11import type { PluginState , ToolStatus } from "./index"
22import type { Logger } from "../logger"
3+ import type { ToolTracker } from "../fetch-wrapper/tool-tracker"
34
45/** Maximum number of entries to keep in the tool parameters cache */
56const MAX_TOOL_CACHE_SIZE = 500
@@ -8,11 +9,16 @@ const MAX_TOOL_CACHE_SIZE = 500
89 * Sync tool parameters from OpenCode's session.messages() API.
910 * This is the single source of truth for tool parameters, replacing
1011 * format-specific parsing from LLM API requests.
12+ *
13+ * Also tracks new tool results for nudge injection, consolidating
14+ * what was previously done via format-specific trackNewToolResults().
1115 */
1216export async function syncToolParametersFromOpenCode (
1317 client : any ,
1418 sessionId : string ,
1519 state : PluginState ,
20+ tracker ?: ToolTracker ,
21+ protectedTools ?: Set < string > ,
1622 logger ?: Logger
1723) : Promise < void > {
1824 try {
@@ -36,9 +42,21 @@ export async function syncToolParametersFromOpenCode(
3642
3743 const id = part . callID . toLowerCase ( )
3844
39- // Skip if already cached (optimization)
45+ // Track tool results for nudge injection (replaces format-specific trackNewToolResults)
46+ if ( tracker && ! tracker . seenToolResultIds . has ( id ) ) {
47+ tracker . seenToolResultIds . add ( id )
48+ // Only count non-protected tools toward nudge threshold
49+ if ( ! part . tool || ! protectedTools ?. has ( part . tool ) ) {
50+ tracker . toolResultCount ++
51+ }
52+ }
53+
54+ // Skip if already cached (optimization for parameter caching only)
4055 if ( state . toolParameters . has ( id ) ) continue
4156
57+ // Skip protected tools - they shouldn't be in the cache at all
58+ if ( part . tool && protectedTools ?. has ( part . tool ) ) continue
59+
4260 const status = part . state ?. status as ToolStatus | undefined
4361 state . toolParameters . set ( id , {
4462 tool : part . tool ,
@@ -55,8 +73,7 @@ export async function syncToolParametersFromOpenCode(
5573 if ( logger && synced > 0 ) {
5674 logger . debug ( "tool-cache" , "Synced tool parameters from OpenCode" , {
5775 sessionId : sessionId . slice ( 0 , 8 ) ,
58- synced,
59- totalCached : state . toolParameters . size
76+ synced
6077 } )
6178 }
6279 } catch ( error ) {
0 commit comments