@@ -4,7 +4,7 @@ import type { PluginConfig } from "./config"
44import { syncToolCache } from "./state/tool-cache"
55import { deduplicate , supersedeWrites , purgeErrors } from "./strategies"
66import { prune , insertCompressToolContext } from "./messages"
7- import { buildToolIdList , isIgnoredUserMessage } from "./messages/utils"
7+ import { buildToolIdList , isIgnoredUserMessage , annotateContext } from "./messages/utils"
88import { checkSession } from "./state"
99import { renderSystemPrompt } from "./prompts"
1010import { handleStatsCommand } from "./commands/stats"
@@ -13,49 +13,14 @@ import { handleHelpCommand } from "./commands/help"
1313import { handleSweepCommand } from "./commands/sweep"
1414import { handleManualToggleCommand , handleManualTriggerCommand } from "./commands/manual"
1515import { ensureSessionInitialized } from "./state/state"
16- import { getCurrentParams , countToolTokens } from "./strategies/utils"
16+ import { getCurrentParams } from "./strategies/utils"
1717
1818const INTERNAL_AGENT_SIGNATURES = [
1919 "You are a title generator" ,
2020 "You are a helpful AI assistant tasked with summarizing conversations" ,
2121 "Summarize what was done in this conversation" ,
2222]
2323
24- function formatTokenCount ( n : number ) : string {
25- if ( n >= 1000 ) return `${ ( n / 1000 ) . toFixed ( 1 ) } k tokens`
26- return `${ n } tokens`
27- }
28-
29- function annotateContext ( messages : WithParts [ ] ) : void {
30- let uid = 0
31- let muid = 0
32- for ( const msg of messages ) {
33- const parts = Array . isArray ( msg . parts ) ? msg . parts : [ ]
34-
35- if ( msg . info . role === "user" && ! isIgnoredUserMessage ( msg ) ) {
36- muid ++
37- const text = parts . find (
38- ( p ) => p . type === "text" && ! ( p as any ) . ignored && ! ( p as any ) . synthetic ,
39- )
40- if ( text && text . type === "text" ) {
41- text . text = `[muid_${ muid } ]\n${ text . text } `
42- }
43- }
44-
45- for ( const part of parts ) {
46- if ( part . type !== "tool" ) continue
47- uid ++
48- const tokens = countToolTokens ( part )
49- const tag = tokens > 0 ? `[uid_${ uid } , ${ formatTokenCount ( tokens ) } ]` : `[uid_${ uid } ]`
50- if ( part . state ?. status === "completed" && typeof part . state . output === "string" ) {
51- part . state . output = `${ tag } \n${ part . state . output } `
52- } else if ( part . state ?. status === "error" && typeof part . state . error === "string" ) {
53- part . state . error = `${ tag } \n${ part . state . error } `
54- }
55- }
56- }
57- }
58-
5924function applyPendingManualTriggerPrompt (
6025 state : SessionState ,
6126 messages : WithParts [ ] ,
0 commit comments