@@ -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,20 +32,18 @@ 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+ if ( part . state . status !== "completed ") {
3736 continue
3837 }
39- if ( part . state . status === "completed " ) {
40- part . state . output = PRUNED_TOOL_OUTPUT_REPLACEMENT
38+ if ( part . tool === "question " ) {
39+ continue
4140 }
41+
42+ part . state . output = PRUNED_TOOL_OUTPUT_REPLACEMENT
4243 }
4344 }
4445}
4546
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.
5047const pruneToolInputs = ( state : SessionState , logger : Logger , messages : WithParts [ ] ) : void => {
5148 for ( const msg of messages ) {
5249 if ( isMessageCompacted ( state , msg ) ) {
@@ -60,23 +57,15 @@ const pruneToolInputs = (state: SessionState, logger: Logger, messages: WithPart
6057 if ( ! state . prune . toolIds . includes ( part . callID ) ) {
6158 continue
6259 }
63- if ( part . tool !== "write" && part . tool !== "edit " ) {
60+ if ( part . state . status !== "completed " ) {
6461 continue
6562 }
66- if ( part . state . status !== "completed " ) {
63+ if ( part . tool !== "question " ) {
6764 continue
6865 }
6966
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- }
67+ if ( part . state . input ?. questions !== undefined ) {
68+ part . state . input . questions = PRUNED_QUESTION_INPUT_REPLACEMENT
8069 }
8170 }
8271 }
0 commit comments