@@ -3,11 +3,10 @@ import type { Logger } from "../logger"
33import type { PluginConfig } from "../config"
44import { isMessageCompacted } from "../shared-utils"
55
6- const PRUNED_TOOL_INPUT_REPLACEMENT =
7- "[content removed to save context, this is not what was written to the file, but a placeholder]"
86const PRUNED_TOOL_OUTPUT_REPLACEMENT =
97 "[Output removed to save context - information superseded or no longer needed]"
108const PRUNED_TOOL_ERROR_INPUT_REPLACEMENT = "[input removed due to failed tool call]"
9+ const PRUNED_QUESTION_INPUT_REPLACEMENT = "[questions removed - see output for user's answers]"
1110
1211export const prune = (
1312 state : SessionState ,
@@ -33,7 +32,8 @@ const pruneToolOutputs = (state: SessionState, logger: Logger, messages: WithPar
3332 if ( ! state . prune . toolIds . includes ( part . callID ) ) {
3433 continue
3534 }
36- if ( part . tool === "write" || part . tool === "edit" ) {
35+ // Skip write/edit (protected) and question (output contains answers we want to keep)
36+ if ( part . tool === "write" || part . tool === "edit" || part . tool === "question" ) {
3737 continue
3838 }
3939 if ( part . state . status === "completed" ) {
@@ -43,10 +43,6 @@ const pruneToolOutputs = (state: SessionState, logger: Logger, messages: WithPar
4343 }
4444}
4545
46- // NOTE: This function is currently unused because "write" and "edit" are protected by default.
47- // Some models incorrectly use PRUNED_TOOL_INPUT_REPLACEMENT in their output when they see it in context.
48- // See: https://github.com/Opencode-DCP/opencode-dynamic-context-pruning/issues/215
49- // Keeping this function in case the bug is resolved in the future.
5046const pruneToolInputs = ( state : SessionState , logger : Logger , messages : WithParts [ ] ) : void => {
5147 for ( const msg of messages ) {
5248 if ( isMessageCompacted ( state , msg ) ) {
@@ -60,23 +56,12 @@ const pruneToolInputs = (state: SessionState, logger: Logger, messages: WithPart
6056 if ( ! state . prune . toolIds . includes ( part . callID ) ) {
6157 continue
6258 }
63- if ( part . tool !== "write" && part . tool !== "edit" ) {
64- continue
65- }
6659 if ( part . state . status !== "completed" ) {
6760 continue
6861 }
6962
70- if ( part . tool === "write" && part . state . input ?. content !== undefined ) {
71- part . state . input . content = PRUNED_TOOL_INPUT_REPLACEMENT
72- }
73- if ( part . tool === "edit" ) {
74- if ( part . state . input ?. oldString !== undefined ) {
75- part . state . input . oldString = PRUNED_TOOL_INPUT_REPLACEMENT
76- }
77- if ( part . state . input ?. newString !== undefined ) {
78- part . state . input . newString = PRUNED_TOOL_INPUT_REPLACEMENT
79- }
63+ if ( part . tool === "question" && part . state . input ?. questions !== undefined ) {
64+ part . state . input . questions = PRUNED_QUESTION_INPUT_REPLACEMENT
8065 }
8166 }
8267 }
0 commit comments