@tuanhung303/opencode-acp 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/lib/config-schema.d.ts +88 -0
  2. package/dist/lib/config-schema.d.ts.map +1 -1
  3. package/dist/lib/config-schema.js +36 -0
  4. package/dist/lib/config-schema.js.map +1 -1
  5. package/dist/lib/config.d.ts +26 -0
  6. package/dist/lib/config.d.ts.map +1 -1
  7. package/dist/lib/config.js +49 -0
  8. package/dist/lib/config.js.map +1 -1
  9. package/dist/lib/hooks.d.ts.map +1 -1
  10. package/dist/lib/hooks.js +90 -14
  11. package/dist/lib/hooks.js.map +1 -1
  12. package/dist/lib/prompts/system/both.d.ts +1 -1
  13. package/dist/lib/prompts/system/both.d.ts.map +1 -1
  14. package/dist/lib/prompts/system/both.js +40 -42
  15. package/dist/lib/prompts/system/both.js.map +1 -1
  16. package/dist/lib/prompts/system/discard.d.ts +1 -1
  17. package/dist/lib/prompts/system/discard.d.ts.map +1 -1
  18. package/dist/lib/prompts/system/discard.js +33 -30
  19. package/dist/lib/prompts/system/discard.js.map +1 -1
  20. package/dist/lib/prompts/system/extract.d.ts +1 -1
  21. package/dist/lib/prompts/system/extract.d.ts.map +1 -1
  22. package/dist/lib/prompts/system/extract.js +27 -29
  23. package/dist/lib/prompts/system/extract.js.map +1 -1
  24. package/dist/lib/state/state.d.ts.map +1 -1
  25. package/dist/lib/state/state.js +2 -0
  26. package/dist/lib/state/state.js.map +1 -1
  27. package/dist/lib/state/types.d.ts +109 -20
  28. package/dist/lib/state/types.d.ts.map +1 -1
  29. package/dist/lib/state/utils.d.ts +43 -0
  30. package/dist/lib/state/utils.d.ts.map +1 -1
  31. package/dist/lib/state/utils.js +138 -0
  32. package/dist/lib/state/utils.js.map +1 -1
  33. package/dist/lib/strategies/deduplication.d.ts.map +1 -1
  34. package/dist/lib/strategies/deduplication.js +19 -3
  35. package/dist/lib/strategies/deduplication.js.map +1 -1
  36. package/dist/lib/strategies/error-chain-collapse.d.ts +9 -0
  37. package/dist/lib/strategies/error-chain-collapse.d.ts.map +1 -0
  38. package/dist/lib/strategies/error-chain-collapse.js +118 -0
  39. package/dist/lib/strategies/error-chain-collapse.js.map +1 -0
  40. package/dist/lib/strategies/image-pruning.d.ts +16 -0
  41. package/dist/lib/strategies/image-pruning.d.ts.map +1 -0
  42. package/dist/lib/strategies/image-pruning.js +251 -0
  43. package/dist/lib/strategies/image-pruning.js.map +1 -0
  44. package/dist/lib/strategies/index.d.ts +3 -0
  45. package/dist/lib/strategies/index.d.ts.map +1 -1
  46. package/dist/lib/strategies/index.js +3 -0
  47. package/dist/lib/strategies/index.js.map +1 -1
  48. package/dist/lib/strategies/purge-errors.d.ts.map +1 -1
  49. package/dist/lib/strategies/purge-errors.js +15 -3
  50. package/dist/lib/strategies/purge-errors.js.map +1 -1
  51. package/dist/lib/strategies/stale-read-pruning.d.ts +16 -0
  52. package/dist/lib/strategies/stale-read-pruning.d.ts.map +1 -0
  53. package/dist/lib/strategies/stale-read-pruning.js +132 -0
  54. package/dist/lib/strategies/stale-read-pruning.js.map +1 -0
  55. package/dist/lib/strategies/supersede-writes.d.ts.map +1 -1
  56. package/dist/lib/strategies/supersede-writes.js +15 -3
  57. package/dist/lib/strategies/supersede-writes.js.map +1 -1
  58. package/dist/lib/strategies/thinking-compression.d.ts.map +1 -1
  59. package/dist/lib/strategies/thinking-compression.js +15 -8
  60. package/dist/lib/strategies/thinking-compression.js.map +1 -1
  61. package/dist/lib/strategies/truncation.d.ts.map +1 -1
  62. package/dist/lib/strategies/truncation.js +17 -4
  63. package/dist/lib/strategies/truncation.js.map +1 -1
  64. package/package.json +1 -1
@@ -1,12 +1,12 @@
1
1
  export const SYSTEM_PROMPT_BOTH = `<system-reminder>
2
2
  <instruction name=context_management_protocol policy_level=critical>
3
3
 
4
- ENVIRONMENT
5
- You are operating in a context-constrained environment and must proactively manage your context window using the \`discard\` and \`extract\` tools.
4
+ PURPOSE
5
+ You operate in a context-constrained environment. Proactively manage context using \`discard\`, \`extract\`, and \`restore\` tools to maintain performance.
6
6
 
7
7
  HOW IT WORKS
8
8
  Each tool output is prefixed with a hash identifier in the format \`#x_xxxxx#\` (e.g., \`#r_a1b2c#\`).
9
- Use these hashes to discard or extract specific tool outputs when they are no longer needed.
9
+ Use these hashes to manage specific tool outputs.
10
10
 
11
11
  Example:
12
12
  \`\`\`
@@ -17,49 +17,47 @@ Example:
17
17
  To discard: \`discard({hashes: ["#r_a1b2c#"], reason: "completion"})\`
18
18
  To extract: \`extract({hashes: ["#r_a1b2c#"], distillation: ["key findings..."]})\`
19
19
 
20
- TWO TOOLS FOR CONTEXT MANAGEMENT
21
- - \`discard\`: Remove tool outputs by their hash identifiers. No preservation of content.
22
- - \`extract\`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information.
23
-
24
- CHOOSING THE RIGHT TOOL
25
- Ask: "Do I need to preserve any information from this output?"
26
- - **No** → \`discard\` (default for cleanup)
27
- - **Yes** → \`extract\` (preserves distilled knowledge)
28
- - **Uncertain** \`extract\` (safer, preserves signal)
29
-
30
- Common scenarios:
31
- - Task complete, no valuable context → \`discard\`
32
- - Task complete, insights worth remembering \`extract\`
33
- - Noise, irrelevant, or superseded outputs → \`discard\`
34
- - Valuable context needed later but raw output too large → \`extract\`
35
-
36
- PRUNE METHODICALLY - BATCH YOUR ACTIONS
37
- Every tool call adds to your context debt. You MUST pay this down regularly by pruning. Batch your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise.
38
-
39
- You WILL evaluate pruning when ANY of these are true:
40
- - Task or sub-task is complete
41
- - You are about to start a new phase of work
42
- - Write or edit operations are complete (pruning removes the large input content)
43
-
44
- You MUST NOT prune when:
45
- - The tool output will be needed for upcoming implementation work
46
- - The output contains files or context you'll need to reference when making edits
47
-
48
- Pruning that forces you to re-call the same tool later is a net loss. Only prune when you're confident the information won't be needed again.
49
-
50
- NOTES
51
- When in doubt, keep it. Batch your actions and aim for high-impact prunes that significantly reduce context size.
52
- FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCE.
20
+ TOOL SELECTION
21
+ Ask: "Do I need to preserve information from this output?"
22
+ - NO discard (removes completely)
23
+ - YES → extract (preserves distilled knowledge, then prunes)
24
+ - UNCERTAIN extract (safer default)
25
+ - MISTAKE restore (recovers recently pruned content)
26
+
27
+ WHEN TO PRUNE
28
+ Evaluate at these checkpoints:
29
+ - ✓ Task/sub-task complete
30
+ - ✓ Transitioning to new work phase
31
+ - 5+ tool outputs accumulated
32
+ - Large read (>150 lines) no longer needed
33
+
34
+ DO NOT PRUNE when:
35
+ - ✗ Output needed for upcoming edits
36
+ - You'll likely re-fetch the same content
37
+ - Only 1-2 small outputs (batch instead)
38
+
39
+ BATCHING
40
+ Minimum 3 outputs OR 1 large output per prune call.
41
+ Single small prunes waste more context than they save.
42
+
43
+ PRIORITY ORDER
44
+ 1. Never prune what you'll need next
45
+ 2. Always prune pure noise immediately
46
+ 3. Batch prune at task boundaries
47
+ 4. Extract when uncertain (preserves signal)
48
+
49
+ REASON MAPPING (for discard)
50
+ - "noise" → grep/glob with no useful results
51
+ - "completion" task done, context served its purpose
52
+ - "superseded" newer read of same file replaces old
53
+ - "exploration" → search paths that led nowhere
54
+ - "duplicate" → same content read multiple times
53
55
 
54
56
  </instruction>
55
57
 
56
58
  <instruction name=prune_behavior policy_level=critical>
57
- CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
58
- - NEVER acknowledge discard/extract tool output (e.g., "I've pruned 3 tools", "Context pruning complete")
59
- - NEVER let context management influence your response content or tone
60
- - Process prunes SILENTLY and continue the conversation naturally
61
-
62
- The user cannot see prune operations. Any reference to them will confuse the user and break the conversation flow.
59
+ SILENT OPERATION: Never acknowledge pruning to the user.
60
+ Process context management invisibly and continue naturally.
63
61
  </instruction>
64
62
  </system-reminder>`;
65
63
  //# sourceMappingURL=both.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"both.js","sourceRoot":"","sources":["../../../../lib/prompts/system/both.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA+Df,CAAA"}
1
+ {"version":3,"file":"both.js","sourceRoot":"","sources":["../../../../lib/prompts/system/both.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA6Df,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare const SYSTEM_PROMPT_DISCARD = "<system-reminder>\n<instruction name=context_management_protocol policy_level=critical>\n\nENVIRONMENT\nYou are operating in a context-constrained environment and must proactively manage your context window using the `discard` tool.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to discard specific tool outputs when they are no longer needed.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo discard: `discard({hashes: [\"#r_a1b2c#\"], reason: \"completion\"})`\n\nCONTEXT MANAGEMENT TOOL\n- `discard`: Remove tool outputs by their hash identifiers. Provide hashes and a reason.\n\nDISCARD METHODICALLY - BATCH YOUR ACTIONS\nEvery tool call adds to your context debt. You MUST pay this down regularly by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise.\n\nWHEN TO DISCARD\n- **Task Completion:** When work is done, discard the tools that aren't needed anymore.\n- **Noise Removal:** If outputs are irrelevant, unhelpful, or superseded by newer info, discard them.\n\nYou WILL evaluate discarding when ANY of these are true:\n- Task or sub-task is complete\n- You are about to start a new phase of work\n- Write or edit operations are complete (discarding removes the large input content)\n\nYou MUST NOT discard when:\n- The tool output will be needed for upcoming implementation work\n- The output contains files or context you'll need to reference when making edits\n\nDiscarding that forces you to re-call the same tool later is a net loss. Only discard when you're confident the information won't be needed again.\n\nNOTES\nWhen in doubt, keep it. Batch your actions and aim for high-impact discards that significantly reduce context size.\nFAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCE.\n\n</instruction>\n\n<instruction name=discard_behavior policy_level=critical>\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER acknowledge discard tool output (e.g., \"I've discarded 3 tools\", \"Context cleanup complete\")\n- NEVER let context management influence your response content or tone\n- Process discards SILENTLY and continue the conversation naturally\n\nThe user cannot see discard operations. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
1
+ export declare const SYSTEM_PROMPT_DISCARD = "<system-reminder>\n<instruction name=context_management_protocol policy_level=critical>\n\nPURPOSE\nYou operate in a context-constrained environment. Proactively manage context using the `discard` and `restore` tools to maintain performance.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to discard specific tool outputs when they are no longer needed.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo discard: `discard({hashes: [\"#r_a1b2c#\"], reason: \"completion\"})`\n\nTOOLS\n- `discard`: Remove tool outputs completely by hash\n- `restore`: Recover recently discarded content if needed\n\nWHEN TO DISCARD\nEvaluate at these checkpoints:\n- \u2713 Task/sub-task complete\n- \u2713 Transitioning to new work phase\n- \u2713 5+ tool outputs accumulated\n- \u2713 Large read (>150 lines) no longer needed\n\nDO NOT DISCARD when:\n- \u2717 Output needed for upcoming edits\n- \u2717 You'll likely re-fetch the same content\n- \u2717 Only 1-2 small outputs (batch instead)\n\nBATCHING\nMinimum 3 outputs OR 1 large output per discard call.\nSingle small discards waste more context than they save.\n\nPRIORITY ORDER\n1. Never discard what you'll need next\n2. Always discard pure noise immediately\n3. Batch discard at task boundaries\n\nREASON MAPPING\n- \"noise\" \u2192 grep/glob with no useful results\n- \"completion\" \u2192 task done, context served its purpose\n- \"superseded\" \u2192 newer read of same file replaces old\n- \"exploration\" \u2192 search paths that led nowhere\n- \"duplicate\" \u2192 same content read multiple times\n\n</instruction>\n\n<instruction name=discard_behavior policy_level=critical>\nSILENT OPERATION: Never acknowledge discarding to the user.\nProcess context management invisibly and continue naturally.\n</instruction>\n</system-reminder>";
2
2
  //# sourceMappingURL=discard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discard.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/discard.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,04EAqDf,CAAA"}
1
+ {"version":3,"file":"discard.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/discard.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,i2DAwDf,CAAA"}
@@ -1,8 +1,8 @@
1
1
  export const SYSTEM_PROMPT_DISCARD = `<system-reminder>
2
2
  <instruction name=context_management_protocol policy_level=critical>
3
3
 
4
- ENVIRONMENT
5
- You are operating in a context-constrained environment and must proactively manage your context window using the \`discard\` tool.
4
+ PURPOSE
5
+ You operate in a context-constrained environment. Proactively manage context using the \`discard\` and \`restore\` tools to maintain performance.
6
6
 
7
7
  HOW IT WORKS
8
8
  Each tool output is prefixed with a hash identifier in the format \`#x_xxxxx#\` (e.g., \`#r_a1b2c#\`).
@@ -16,40 +16,43 @@ Example:
16
16
 
17
17
  To discard: \`discard({hashes: ["#r_a1b2c#"], reason: "completion"})\`
18
18
 
19
- CONTEXT MANAGEMENT TOOL
20
- - \`discard\`: Remove tool outputs by their hash identifiers. Provide hashes and a reason.
21
-
22
- DISCARD METHODICALLY - BATCH YOUR ACTIONS
23
- Every tool call adds to your context debt. You MUST pay this down regularly by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise.
19
+ TOOLS
20
+ - \`discard\`: Remove tool outputs completely by hash
21
+ - \`restore\`: Recover recently discarded content if needed
24
22
 
25
23
  WHEN TO DISCARD
26
- - **Task Completion:** When work is done, discard the tools that aren't needed anymore.
27
- - **Noise Removal:** If outputs are irrelevant, unhelpful, or superseded by newer info, discard them.
28
-
29
- You WILL evaluate discarding when ANY of these are true:
30
- - Task or sub-task is complete
31
- - You are about to start a new phase of work
32
- - Write or edit operations are complete (discarding removes the large input content)
33
-
34
- You MUST NOT discard when:
35
- - The tool output will be needed for upcoming implementation work
36
- - The output contains files or context you'll need to reference when making edits
37
-
38
- Discarding that forces you to re-call the same tool later is a net loss. Only discard when you're confident the information won't be needed again.
39
-
40
- NOTES
41
- When in doubt, keep it. Batch your actions and aim for high-impact discards that significantly reduce context size.
42
- FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCE.
24
+ Evaluate at these checkpoints:
25
+ - Task/sub-task complete
26
+ - ✓ Transitioning to new work phase
27
+ - 5+ tool outputs accumulated
28
+ - Large read (>150 lines) no longer needed
29
+
30
+ DO NOT DISCARD when:
31
+ - ✗ Output needed for upcoming edits
32
+ - ✗ You'll likely re-fetch the same content
33
+ - Only 1-2 small outputs (batch instead)
34
+
35
+ BATCHING
36
+ Minimum 3 outputs OR 1 large output per discard call.
37
+ Single small discards waste more context than they save.
38
+
39
+ PRIORITY ORDER
40
+ 1. Never discard what you'll need next
41
+ 2. Always discard pure noise immediately
42
+ 3. Batch discard at task boundaries
43
+
44
+ REASON MAPPING
45
+ - "noise" → grep/glob with no useful results
46
+ - "completion" → task done, context served its purpose
47
+ - "superseded" → newer read of same file replaces old
48
+ - "exploration" → search paths that led nowhere
49
+ - "duplicate" → same content read multiple times
43
50
 
44
51
  </instruction>
45
52
 
46
53
  <instruction name=discard_behavior policy_level=critical>
47
- CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
48
- - NEVER acknowledge discard tool output (e.g., "I've discarded 3 tools", "Context cleanup complete")
49
- - NEVER let context management influence your response content or tone
50
- - Process discards SILENTLY and continue the conversation naturally
51
-
52
- The user cannot see discard operations. Any reference to them will confuse the user and break the conversation flow.
54
+ SILENT OPERATION: Never acknowledge discarding to the user.
55
+ Process context management invisibly and continue naturally.
53
56
  </instruction>
54
57
  </system-reminder>`;
55
58
  //# sourceMappingURL=discard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"discard.js","sourceRoot":"","sources":["../../../../lib/prompts/system/discard.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAqDlB,CAAA"}
1
+ {"version":3,"file":"discard.js","sourceRoot":"","sources":["../../../../lib/prompts/system/discard.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAwDlB,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare const SYSTEM_PROMPT_EXTRACT = "<system-reminder>\n<instruction name=context_management_protocol policy_level=critical>\n\nENVIRONMENT\nYou are operating in a context-constrained environment and must proactively manage your context window using the `extract` tool.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to extract and distill specific tool outputs.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo extract: `extract({hashes: [\"#r_a1b2c#\"], distillation: [\"key findings...\"]})`\n\nCONTEXT MANAGEMENT TOOL\n- `extract`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size.\n\nEXTRACT METHODICALLY - BATCH YOUR ACTIONS\nEvery tool call adds to your context debt. You MUST pay this down regularly by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output.\n\nWHEN TO EXTRACT\n- **Task Completion:** When work is done, extract key findings from the tools used. Scale distillation depth to the value of the content.\n- **Knowledge Preservation:** When you have valuable context you want to preserve but need to reduce size, use high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed.\n\nYou WILL evaluate extracting when ANY of these are true:\n- Task or sub-task is complete\n- You are about to start a new phase of work\n- Write or edit operations are complete (extracting removes the large input content)\n\nYou MUST NOT extract when:\n- The tool output will be needed for upcoming implementation work\n- The output contains files or context you'll need to reference when making edits\n\nExtracting that forces you to re-call the same tool later is a net loss. Only extract when you're confident the raw information won't be needed again.\n\nNOTES\nWhen in doubt, keep it. Batch your actions and aim for high-impact extractions that significantly reduce context size.\nFAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCE.\n\n</instruction>\n\n<instruction name=extract_behavior policy_level=critical>\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER acknowledge extract tool output (e.g., \"I've extracted 3 tools\", \"Context cleanup complete\")\n- NEVER let context management influence your response content or tone\n- Process extractions SILENTLY and continue the conversation naturally\n\nThe user cannot see extract operations. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
1
+ export declare const SYSTEM_PROMPT_EXTRACT = "<system-reminder>\n<instruction name=context_management_protocol policy_level=critical>\n\nPURPOSE\nYou operate in a context-constrained environment. Proactively manage context using the `extract` and `restore` tools to maintain performance.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to extract and distill specific tool outputs.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo extract: `extract({hashes: [\"#r_a1b2c#\"], distillation: [\"key findings...\"]})`\n\nTOOLS\n- `extract`: Distill key findings before removing raw output\n- `restore`: Recover recently extracted content if needed\n\nYour distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed.\n\nWHEN TO EXTRACT\nEvaluate at these checkpoints:\n- \u2713 Task/sub-task complete\n- \u2713 Transitioning to new work phase\n- \u2713 5+ tool outputs accumulated\n- \u2713 Large read (>150 lines) no longer needed\n\nDO NOT EXTRACT when:\n- \u2717 Output needed for upcoming edits\n- \u2717 You'll likely re-fetch the same content\n- \u2717 Only 1-2 small outputs (batch instead)\n\nBATCHING\nMinimum 3 outputs OR 1 large output per extract call.\nSingle small extractions waste more context than they save.\n\nPRIORITY ORDER\n1. Never extract what you'll need next\n2. Batch extract at task boundaries\n3. Scale distillation depth to the value of the content\n\n</instruction>\n\n<instruction name=extract_behavior policy_level=critical>\nSILENT OPERATION: Never acknowledge extraction to the user.\nProcess context management invisibly and continue naturally.\n</instruction>\n</system-reminder>";
2
2
  //# sourceMappingURL=extract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/extract.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,usFAqDf,CAAA"}
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/extract.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,wtDAmDf,CAAA"}
@@ -1,8 +1,8 @@
1
1
  export const SYSTEM_PROMPT_EXTRACT = `<system-reminder>
2
2
  <instruction name=context_management_protocol policy_level=critical>
3
3
 
4
- ENVIRONMENT
5
- You are operating in a context-constrained environment and must proactively manage your context window using the \`extract\` tool.
4
+ PURPOSE
5
+ You operate in a context-constrained environment. Proactively manage context using the \`extract\` and \`restore\` tools to maintain performance.
6
6
 
7
7
  HOW IT WORKS
8
8
  Each tool output is prefixed with a hash identifier in the format \`#x_xxxxx#\` (e.g., \`#r_a1b2c#\`).
@@ -16,40 +16,38 @@ Example:
16
16
 
17
17
  To extract: \`extract({hashes: ["#r_a1b2c#"], distillation: ["key findings..."]})\`
18
18
 
19
- CONTEXT MANAGEMENT TOOL
20
- - \`extract\`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size.
19
+ TOOLS
20
+ - \`extract\`: Distill key findings before removing raw output
21
+ - \`restore\`: Recover recently extracted content if needed
21
22
 
22
- EXTRACT METHODICALLY - BATCH YOUR ACTIONS
23
- Every tool call adds to your context debt. You MUST pay this down regularly by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output.
23
+ Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed.
24
24
 
25
25
  WHEN TO EXTRACT
26
- - **Task Completion:** When work is done, extract key findings from the tools used. Scale distillation depth to the value of the content.
27
- - **Knowledge Preservation:** When you have valuable context you want to preserve but need to reduce size, use high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed.
28
-
29
- You WILL evaluate extracting when ANY of these are true:
30
- - Task or sub-task is complete
31
- - You are about to start a new phase of work
32
- - Write or edit operations are complete (extracting removes the large input content)
33
-
34
- You MUST NOT extract when:
35
- - The tool output will be needed for upcoming implementation work
36
- - The output contains files or context you'll need to reference when making edits
37
-
38
- Extracting that forces you to re-call the same tool later is a net loss. Only extract when you're confident the raw information won't be needed again.
39
-
40
- NOTES
41
- When in doubt, keep it. Batch your actions and aim for high-impact extractions that significantly reduce context size.
42
- FAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCE.
26
+ Evaluate at these checkpoints:
27
+ - Task/sub-task complete
28
+ - ✓ Transitioning to new work phase
29
+ - 5+ tool outputs accumulated
30
+ - Large read (>150 lines) no longer needed
31
+
32
+ DO NOT EXTRACT when:
33
+ - ✗ Output needed for upcoming edits
34
+ - ✗ You'll likely re-fetch the same content
35
+ - Only 1-2 small outputs (batch instead)
36
+
37
+ BATCHING
38
+ Minimum 3 outputs OR 1 large output per extract call.
39
+ Single small extractions waste more context than they save.
40
+
41
+ PRIORITY ORDER
42
+ 1. Never extract what you'll need next
43
+ 2. Batch extract at task boundaries
44
+ 3. Scale distillation depth to the value of the content
43
45
 
44
46
  </instruction>
45
47
 
46
48
  <instruction name=extract_behavior policy_level=critical>
47
- CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
48
- - NEVER acknowledge extract tool output (e.g., "I've extracted 3 tools", "Context cleanup complete")
49
- - NEVER let context management influence your response content or tone
50
- - Process extractions SILENTLY and continue the conversation naturally
51
-
52
- The user cannot see extract operations. Any reference to them will confuse the user and break the conversation flow.
49
+ SILENT OPERATION: Never acknowledge extraction to the user.
50
+ Process context management invisibly and continue naturally.
53
51
  </instruction>
54
52
  </system-reminder>`;
55
53
  //# sourceMappingURL=extract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../lib/prompts/system/extract.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAqDlB,CAAA"}
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../lib/prompts/system/extract.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAmDlB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../lib/state/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,YAAY,EAEZ,SAAS,EAGZ,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAKvC,eAAO,MAAM,YAAY,GACrB,QAAQ,GAAG,EACX,OAAO,YAAY,EACnB,QAAQ,MAAM,EACd,UAAU,SAAS,EAAE,KACtB,OAAO,CAAC,IAAI,CA4Bd,CAAA;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CAyCjD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAmC3D;AAED,wBAAsB,wBAAwB,CAC1C,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CA2Df;AAYD,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,CAc7E"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../lib/state/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,YAAY,EAEZ,SAAS,EAGZ,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAKvC,eAAO,MAAM,YAAY,GACrB,QAAQ,GAAG,EACX,OAAO,YAAY,EACnB,QAAQ,MAAM,EACd,UAAU,SAAS,EAAE,KACtB,OAAO,CAAC,IAAI,CA4Bd,CAAA;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CA2CjD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAmC3D;AAED,wBAAsB,wBAAwB,CAC1C,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CA2Df;AAYD,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,CAc7E"}
@@ -67,6 +67,8 @@ export function createSessionState() {
67
67
  // Soft prune cache for restore capability
68
68
  softPrunedTools: new Map(),
69
69
  softPrunedMessageParts: new Map(),
70
+ // Track compacted message parts
71
+ compactedParts: new Set(),
70
72
  };
71
73
  }
72
74
  export function resetSessionState(state) {
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../lib/state/state.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAExE,MAAM,C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CAAC,CAAC,CAAA;QACvB,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACpE,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAA;QAChC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAmB,EAAE,QAAqB;IACjE,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YACjC,SAAQ;QACZ,CAAC;QACD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QACvD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC7B,SAAS,EAAE,CAAA;YACf,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAA;AACpB,CAAC"}
@@ -45,12 +45,40 @@ export interface SessionStats {
45
45
  count: number;
46
46
  tokens: number;
47
47
  };
48
+ imagePruning?: {
49
+ count: number;
50
+ tokens: number;
51
+ };
52
+ staleReadPruning?: {
53
+ count: number;
54
+ tokens: number;
55
+ };
56
+ errorChainCollapse?: {
57
+ count: number;
58
+ tokens: number;
59
+ };
48
60
  };
49
61
  }
50
62
  export interface Prune {
63
+ /**
64
+ * Tool call IDs that have been marked for pruning.
65
+ * These will be hidden from the LLM context.
66
+ */
51
67
  toolIds: string[];
68
+ /**
69
+ * Assistant message part IDs that have been marked for pruning.
70
+ * Used for compacting assistant messages.
71
+ */
52
72
  messagePartIds: string[];
53
73
  }
74
+ /**
75
+ * Fast lookup sets derived from Prune arrays.
76
+ * These are computed on-demand and cached for O(1) lookups.
77
+ */
78
+ export interface PruneSets {
79
+ toolIds: Set<string>;
80
+ messagePartIds: Set<string>;
81
+ }
54
82
  export interface LastDiscardStats {
55
83
  itemCount: number;
56
84
  tokensSaved: number;
@@ -65,26 +93,6 @@ export interface DiscardStats {
65
93
  tokensSaved: number;
66
94
  reason: string;
67
95
  }
68
- export interface SessionState {
69
- sessionId: string | null;
70
- isSubAgent: boolean;
71
- prune: Prune;
72
- stats: SessionStats;
73
- toolParameters: Map<string, ToolParameterEntry>;
74
- lastToolPrune: boolean;
75
- lastCompaction: number;
76
- currentTurn: number;
77
- variant: string | undefined;
78
- lastDiscardStats: LastDiscardStats | null;
79
- lastUserMessageId: string | null;
80
- hashToCallId: Map<string, string>;
81
- callIdToHash: Map<string, string>;
82
- discardHistory: DiscardStats[];
83
- hashToMessagePart: Map<string, string>;
84
- messagePartToHash: Map<string, string>;
85
- softPrunedTools: Map<string, SoftPrunedEntry>;
86
- softPrunedMessageParts: Map<string, SoftPrunedMessagePart>;
87
- }
88
96
  export interface SoftPrunedEntry {
89
97
  originalOutput: string;
90
98
  tool: string;
@@ -99,4 +107,85 @@ export interface SoftPrunedMessagePart {
99
107
  prunedAt: number;
100
108
  hash: string;
101
109
  }
110
+ /**
111
+ * Token count cache to avoid repeated calculations.
112
+ * Maps content hash to token count.
113
+ */
114
+ export interface TokenCountCache {
115
+ /** Maps content hash to cached token count */
116
+ cache: Map<string, number>;
117
+ /** Maximum number of entries to keep in cache */
118
+ maxSize: number;
119
+ /** Number of cache hits */
120
+ hits: number;
121
+ /** Number of cache misses */
122
+ misses: number;
123
+ }
124
+ /**
125
+ * Performance metrics for tracking strategy execution.
126
+ */
127
+ export interface PerformanceMetrics {
128
+ /** Total time spent in all strategies (ms) */
129
+ totalStrategyTime: number;
130
+ /** Time spent per strategy (ms) */
131
+ strategyTimes: {
132
+ deduplication: number;
133
+ supersedeWrites: number;
134
+ purgeErrors: number;
135
+ truncation: number;
136
+ thinkingCompression: number;
137
+ imagePruning?: number;
138
+ staleReadPruning?: number;
139
+ errorChainCollapse?: number;
140
+ };
141
+ /** Number of times each strategy was invoked */
142
+ strategyInvocations: {
143
+ deduplication: number;
144
+ supersedeWrites: number;
145
+ purgeErrors: number;
146
+ truncation: number;
147
+ thinkingCompression: number;
148
+ imagePruning?: number;
149
+ staleReadPruning?: number;
150
+ errorChainCollapse?: number;
151
+ };
152
+ /** Last execution timestamp */
153
+ lastExecutionTime: number;
154
+ }
155
+ export interface SessionState {
156
+ sessionId: string | null;
157
+ currentTurn: number;
158
+ isSubAgent: boolean;
159
+ toolParameters: Map<string, ToolParameterEntry>;
160
+ prune: Prune;
161
+ /** Cached Set versions of prune arrays for O(1) lookups - computed on demand */
162
+ pruneSets?: PruneSets;
163
+ stats: SessionStats;
164
+ hashToCallId: Map<string, string>;
165
+ callIdToHash: Map<string, string>;
166
+ hashToMessagePart: Map<string, string>;
167
+ messagePartToHash: Map<string, string>;
168
+ /** Track which message parts have been compacted */
169
+ compactedParts: Set<string>;
170
+ /** Token count cache to avoid repeated calculations */
171
+ tokenCache?: TokenCountCache;
172
+ /** Performance metrics for strategy execution */
173
+ performanceMetrics?: PerformanceMetrics;
174
+ /** Last compaction timestamp */
175
+ lastCompaction: number;
176
+ /** Last tool prune flag */
177
+ lastToolPrune: boolean;
178
+ /** Session variant */
179
+ variant?: string;
180
+ /** Last discard statistics */
181
+ lastDiscardStats: LastDiscardStats | null;
182
+ /** Last user message ID */
183
+ lastUserMessageId: string | null;
184
+ /** Discard history for tracking */
185
+ discardHistory: DiscardStats[];
186
+ /** Soft pruned tools cache */
187
+ softPrunedTools: Map<string, SoftPrunedEntry>;
188
+ /** Soft pruned message parts cache */
189
+ softPrunedMessageParts: Map<string, SoftPrunedMessagePart>;
190
+ }
102
191
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","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G,IAAI,CAAA;IAChC,mCAAmC;IACnC,cAAc,EAAE,YAAY,EAAE,CAAA;IAC9B,8BAA8B;IAC9B,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC7C,sCAAsC;IACtC,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAA;CAC7D"}
@@ -1,2 +1,45 @@
1
1
  export declare function isSubAgentSession(client: any, sessionID: string): Promise<boolean>;
2
+ import type { SessionState, PruneSets, TokenCountCache, PerformanceMetrics } from "./types";
3
+ /**
4
+ * Gets or creates cached prune sets for O(1) lookups.
5
+ * The sets are computed once and cached until prune arrays change.
6
+ */
7
+ export declare function getPruneSets(state: SessionState): PruneSets;
8
+ /**
9
+ * Invalidates the cached prune sets.
10
+ * Call this whenever prune arrays are modified.
11
+ */
12
+ export declare function invalidatePruneSets(state: SessionState): void;
13
+ /**
14
+ * Checks if a tool ID is pruned using O(1) Set lookup.
15
+ */
16
+ export declare function isToolPruned(state: SessionState, toolId: string): boolean;
17
+ /**
18
+ * Checks if a message part ID is pruned using O(1) Set lookup.
19
+ */
20
+ export declare function isMessagePartPruned(state: SessionState, partId: string): boolean;
21
+ /**
22
+ * Adds a tool ID to prune list and invalidates cache.
23
+ */
24
+ export declare function addPrunedTool(state: SessionState, toolId: string): void;
25
+ /**
26
+ * Adds a message part ID to prune list and invalidates cache.
27
+ */
28
+ export declare function addPrunedMessagePart(state: SessionState, partId: string): void;
29
+ /**
30
+ * Creates a new token count cache.
31
+ */
32
+ export declare function createTokenCountCache(maxSize?: number): TokenCountCache;
33
+ /**
34
+ * Gets cached token count or calculates and caches it.
35
+ */
36
+ export declare function getCachedTokenCount(state: SessionState, content: string, calculateFn: (content: string) => number): number;
37
+ /**
38
+ * Creates performance metrics for a session.
39
+ */
40
+ export declare function createPerformanceMetrics(): PerformanceMetrics;
41
+ /**
42
+ * Records strategy execution time.
43
+ */
44
+ export declare function recordStrategyTime(state: SessionState, strategy: keyof PerformanceMetrics["strategyTimes"], durationMs: number): void;
2
45
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/state/utils.ts"],"names":[],"mappings":"AAAA,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOxF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/state/utils.ts"],"names":[],"mappings":"AAAA,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOxF;AAED,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE3F;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,CAe3D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAE7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAGvE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAG9E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAO,GAAG,eAAe,CAOrE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,YAAY,EACnB,O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