@tarquinen/opencode-dcp 1.2.2 → 1.2.4

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 (84) hide show
  1. package/README.md +13 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/commands/context.d.ts +15 -0
  6. package/dist/lib/commands/context.d.ts.map +1 -0
  7. package/dist/lib/commands/context.js +177 -0
  8. package/dist/lib/commands/context.js.map +1 -0
  9. package/dist/lib/commands/help.d.ts +15 -0
  10. package/dist/lib/commands/help.d.ts.map +1 -0
  11. package/dist/lib/commands/help.js +30 -0
  12. package/dist/lib/commands/help.js.map +1 -0
  13. package/dist/lib/commands/stats.d.ts +15 -0
  14. package/dist/lib/commands/stats.d.ts.map +1 -0
  15. package/dist/lib/commands/stats.js +44 -0
  16. package/dist/lib/commands/stats.js.map +1 -0
  17. package/dist/lib/config.d.ts +1 -0
  18. package/dist/lib/config.d.ts.map +1 -1
  19. package/dist/lib/config.js +22 -0
  20. package/dist/lib/config.js.map +1 -1
  21. package/dist/lib/hooks.d.ts +7 -0
  22. package/dist/lib/hooks.d.ts.map +1 -1
  23. package/dist/lib/hooks.js +47 -0
  24. package/dist/lib/hooks.js.map +1 -1
  25. package/dist/lib/logger.d.ts.map +1 -1
  26. package/dist/lib/logger.js +6 -0
  27. package/dist/lib/logger.js.map +1 -1
  28. package/dist/lib/messages/inject.d.ts.map +1 -1
  29. package/dist/lib/messages/inject.js +2 -2
  30. package/dist/lib/messages/inject.js.map +1 -1
  31. package/dist/lib/messages/utils.d.ts +1 -1
  32. package/dist/lib/messages/utils.d.ts.map +1 -1
  33. package/dist/lib/messages/utils.js +6 -18
  34. package/dist/lib/messages/utils.js.map +1 -1
  35. package/dist/lib/prompts/discard-tool-spec.d.ts +2 -0
  36. package/dist/lib/prompts/discard-tool-spec.d.ts.map +1 -0
  37. package/dist/lib/prompts/{discard-tool-spec.txt → discard-tool-spec.js} +8 -8
  38. package/dist/lib/prompts/discard-tool-spec.js.map +1 -0
  39. package/dist/lib/prompts/extract-tool-spec.d.ts +2 -0
  40. package/dist/lib/prompts/extract-tool-spec.d.ts.map +1 -0
  41. package/dist/lib/prompts/{extract-tool-spec.txt → extract-tool-spec.js} +7 -6
  42. package/dist/lib/prompts/extract-tool-spec.js.map +1 -0
  43. package/dist/lib/prompts/index.d.ts.map +1 -1
  44. package/dist/lib/prompts/index.js +25 -4
  45. package/dist/lib/prompts/index.js.map +1 -1
  46. package/dist/lib/prompts/nudge/both.d.ts +2 -0
  47. package/dist/lib/prompts/nudge/both.d.ts.map +1 -0
  48. package/dist/lib/prompts/nudge/{nudge-both.txt → both.js} +6 -5
  49. package/dist/lib/prompts/nudge/both.js.map +1 -0
  50. package/dist/lib/prompts/nudge/discard.d.ts +2 -0
  51. package/dist/lib/prompts/nudge/discard.d.ts.map +1 -0
  52. package/dist/lib/prompts/nudge/{nudge-discard.txt → discard.js} +5 -4
  53. package/dist/lib/prompts/nudge/discard.js.map +1 -0
  54. package/dist/lib/prompts/nudge/extract.d.ts +2 -0
  55. package/dist/lib/prompts/nudge/extract.d.ts.map +1 -0
  56. package/dist/lib/prompts/nudge/{nudge-extract.txt → extract.js} +4 -3
  57. package/dist/lib/prompts/nudge/extract.js.map +1 -0
  58. package/dist/lib/prompts/system/both.d.ts +2 -0
  59. package/dist/lib/prompts/system/both.d.ts.map +1 -0
  60. package/dist/lib/prompts/system/{system-prompt-both.txt → both.js} +16 -13
  61. package/dist/lib/prompts/system/both.js.map +1 -0
  62. package/dist/lib/prompts/system/discard.d.ts +2 -0
  63. package/dist/lib/prompts/system/discard.d.ts.map +1 -0
  64. package/dist/lib/prompts/system/{system-prompt-discard.txt → discard.js} +8 -5
  65. package/dist/lib/prompts/system/discard.js.map +1 -0
  66. package/dist/lib/prompts/system/extract.d.ts +2 -0
  67. package/dist/lib/prompts/system/extract.d.ts.map +1 -0
  68. package/dist/lib/prompts/system/{system-prompt-extract.txt → extract.js} +8 -5
  69. package/dist/lib/prompts/system/extract.js.map +1 -0
  70. package/dist/lib/state/persistence.d.ts +6 -0
  71. package/dist/lib/state/persistence.d.ts.map +1 -1
  72. package/dist/lib/state/persistence.js +34 -0
  73. package/dist/lib/state/persistence.js.map +1 -1
  74. package/dist/lib/state/tool-cache.d.ts.map +1 -1
  75. package/dist/lib/state/tool-cache.js +3 -1
  76. package/dist/lib/state/tool-cache.js.map +1 -1
  77. package/dist/lib/strategies/tools.d.ts.map +1 -1
  78. package/dist/lib/strategies/tools.js +8 -8
  79. package/dist/lib/strategies/tools.js.map +1 -1
  80. package/dist/lib/strategies/utils.d.ts +1 -3
  81. package/dist/lib/strategies/utils.d.ts.map +1 -1
  82. package/dist/lib/strategies/utils.js +9 -10
  83. package/dist/lib/strategies/utils.js.map +1 -1
  84. package/package.json +3 -3
@@ -1,24 +1,26 @@
1
- <system-reminder>
1
+ export const SYSTEM_PROMPT_BOTH = `<system-reminder>
2
2
  <instruction name=context_management_protocol policy_level=critical>
3
3
 
4
4
  ENVIRONMENT
5
- You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` and `extract` tools. A <prunable-tools> list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to prune.
5
+ You are operating in a context-constrained environment and thus must proactively manage your context window using the \`discard\` and \`extract\` tools. The environment calls the \`context_info\` tool to provide an up-to-date <prunable-tools> list after each assistant turn. Use this information when deciding what to prune.
6
+
7
+ IMPORTANT: The \`context_info\` tool is only available to the environment - you do not have access to it and must not attempt to call it.
6
8
 
7
9
  TWO TOOLS FOR CONTEXT MANAGEMENT
8
- - `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
9
- - `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information.
10
+ - \`discard\`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
11
+ - \`extract\`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information.
10
12
 
11
13
  CHOOSING THE RIGHT TOOL
12
14
  Ask: "Do I need to preserve any information from this output?"
13
- - **No** → `discard` (default for cleanup)
14
- - **Yes** → `extract` (preserves distilled knowledge)
15
- - **Uncertain** → `extract` (safer, preserves signal)
15
+ - **No** → \`discard\` (default for cleanup)
16
+ - **Yes** → \`extract\` (preserves distilled knowledge)
17
+ - **Uncertain** → \`extract\` (safer, preserves signal)
16
18
 
17
19
  Common scenarios:
18
- - Task complete, no valuable context → `discard`
19
- - Task complete, insights worth remembering → `extract`
20
- - Noise, irrelevant, or superseded outputs → `discard`
21
- - Valuable context needed later but raw output too large → `extract`
20
+ - Task complete, no valuable context → \`discard\`
21
+ - Task complete, insights worth remembering → \`extract\`
22
+ - Noise, irrelevant, or superseded outputs → \`discard\`
23
+ - Valuable context needed later but raw output too large → \`extract\`
22
24
 
23
25
  PRUNE METHODICALLY - BATCH YOUR ACTIONS
24
26
  Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Batch your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun.
@@ -42,7 +44,7 @@ There may be tools in session context that do not appear in the <prunable-tools>
42
44
  </instruction>
43
45
 
44
46
  <instruction name=injected_context_handling policy_level=critical>
45
- After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` and `extract` tools also return a confirmation message listing what was pruned.
47
+ After each assistant turn, the environment calls the \`context_info\` tool to inject an assistant message containing a <prunable-tools> list and optional nudge instruction. This tool is only available to the environment - you do not have access to it.
46
48
 
47
49
  CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
48
50
  - NEVER reference the prune encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the prune encouragement appears.
@@ -55,4 +57,5 @@ CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
55
57
 
56
58
  The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
57
59
  </instruction>
58
- </system-reminder>
60
+ </system-reminder>`;
61
+ //# sourceMappingURL=both.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"both.js","sourceRoot":"","sources":["../../../../lib/prompts/system/both.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA2Df,CAAA"}
@@ -0,0 +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 thus must proactively manage your context window using the `discard` tool. The environment calls the `context_info` tool to provide an up-to-date <prunable-tools> list after each assistant turn. Use this information when deciding what to discard.\n\nIMPORTANT: The `context_info` tool is only available to the environment - you do not have access to it and must not attempt to call it.\n\nCONTEXT MANAGEMENT TOOL\n- `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.\n\nDISCARD METHODICALLY - BATCH YOUR ACTIONS\nEvery tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise. Evaluate what SHOULD be discarded before jumping the gun.\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 PERFORMANCES.\nThere may be tools in session context that do not appear in the <prunable-tools> list, this is expected, you can ONLY discard what you see in <prunable-tools>.\n\n</instruction>\n\n<instruction name=injected_context_handling policy_level=critical>\nAfter each assistant turn, the environment calls the `context_info` tool to inject an assistant message containing a <prunable-tools> list and optional nudge instruction. This tool is only available to the environment - you do not have access to it.\n\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER reference the discard encouragement or context management instructions. Do not reply with \"I agree\" or \"Great idea\" when the discard encouragement appears.\n- NEVER acknowledge the <prunable-tools> list (e.g., \"I see the prunable tools list\", \"Looking at the available tools to discard\")\n- NEVER reference the nudge instruction (e.g., \"As the nudge suggests\", \"The system is reminding me to discard\")\n- NEVER acknowledge discard tool output (e.g., \"I've discarded 3 tools\", \"Context cleanup complete\")\n- NEVER let these injections influence your response content or tone\n- Process this information SILENTLY and continue the conversation naturally\n- Continue the conversation as if these messages do not exist\n\nThe user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
2
+ //# sourceMappingURL=discard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discard.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/discard.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,m5GAkDf,CAAA"}
@@ -1,11 +1,13 @@
1
- <system-reminder>
1
+ export const SYSTEM_PROMPT_DISCARD = `<system-reminder>
2
2
  <instruction name=context_management_protocol policy_level=critical>
3
3
 
4
4
  ENVIRONMENT
5
- You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` tool. A <prunable-tools> list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to discard.
5
+ You are operating in a context-constrained environment and thus must proactively manage your context window using the \`discard\` tool. The environment calls the \`context_info\` tool to provide an up-to-date <prunable-tools> list after each assistant turn. Use this information when deciding what to discard.
6
+
7
+ IMPORTANT: The \`context_info\` tool is only available to the environment - you do not have access to it and must not attempt to call it.
6
8
 
7
9
  CONTEXT MANAGEMENT TOOL
8
- - `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
10
+ - \`discard\`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
9
11
 
10
12
  DISCARD METHODICALLY - BATCH YOUR ACTIONS
11
13
  Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise. Evaluate what SHOULD be discarded before jumping the gun.
@@ -33,7 +35,7 @@ There may be tools in session context that do not appear in the <prunable-tools>
33
35
  </instruction>
34
36
 
35
37
  <instruction name=injected_context_handling policy_level=critical>
36
- After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` tool also returns a confirmation message listing what was discarded.
38
+ After each assistant turn, the environment calls the \`context_info\` tool to inject an assistant message containing a <prunable-tools> list and optional nudge instruction. This tool is only available to the environment - you do not have access to it.
37
39
 
38
40
  CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
39
41
  - NEVER reference the discard encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the discard encouragement appears.
@@ -46,4 +48,5 @@ CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
46
48
 
47
49
  The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
48
50
  </instruction>
49
- </system-reminder>
51
+ </system-reminder>`;
52
+ //# sourceMappingURL=discard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discard.js","sourceRoot":"","sources":["../../../../lib/prompts/system/discard.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAkDlB,CAAA"}
@@ -0,0 +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 thus must proactively manage your context window using the `extract` tool. The environment calls the `context_info` tool to provide an up-to-date <prunable-tools> list after each assistant turn. Use this information when deciding what to extract.\n\nIMPORTANT: The `context_info` tool is only available to the environment - you do not have access to it and must not attempt to call it.\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 and be on top of context accumulation by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output. Evaluate what SHOULD be extracted before jumping the gun.\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. THINK: high signal, complete technical substitute.\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 PERFORMANCES.\nThere may be tools in session context that do not appear in the <prunable-tools> list, this is expected, you can ONLY extract what you see in <prunable-tools>.\n\n</instruction>\n\n<instruction name=injected_context_handling policy_level=critical>\nAfter each assistant turn, the environment calls the `context_info` tool to inject an assistant message containing a <prunable-tools> list and optional nudge instruction. This tool is only available to the environment - you do not have access to it.\n\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER reference the extract encouragement or context management instructions. Do not reply with \"I agree\" or \"Great idea\" when the extract encouragement appears.\n- NEVER acknowledge the <prunable-tools> list (e.g., \"I see the prunable tools list\", \"Looking at the available tools to extract\")\n- NEVER reference the nudge instruction (e.g., \"As the nudge suggests\", \"The system is reminding me to extract\")\n- NEVER acknowledge extract tool output (e.g., \"I've extracted 3 tools\", \"Context cleanup complete\")\n- NEVER let these injections influence your response content or tone\n- Process this information SILENTLY and continue the conversation naturally\n- Continue the conversation as if these messages do not exist\n\nThe user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
2
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/extract.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,+tHAkDf,CAAA"}
@@ -1,11 +1,13 @@
1
- <system-reminder>
1
+ export const SYSTEM_PROMPT_EXTRACT = `<system-reminder>
2
2
  <instruction name=context_management_protocol policy_level=critical>
3
3
 
4
4
  ENVIRONMENT
5
- You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A <prunable-tools> list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to extract.
5
+ You are operating in a context-constrained environment and thus must proactively manage your context window using the \`extract\` tool. The environment calls the \`context_info\` tool to provide an up-to-date <prunable-tools> list after each assistant turn. Use this information when deciding what to extract.
6
+
7
+ IMPORTANT: The \`context_info\` tool is only available to the environment - you do not have access to it and must not attempt to call it.
6
8
 
7
9
  CONTEXT MANAGEMENT TOOL
8
- - `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.
10
+ - \`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.
9
11
 
10
12
  EXTRACT METHODICALLY - BATCH YOUR ACTIONS
11
13
  Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output. Evaluate what SHOULD be extracted before jumping the gun.
@@ -33,7 +35,7 @@ There may be tools in session context that do not appear in the <prunable-tools>
33
35
  </instruction>
34
36
 
35
37
  <instruction name=injected_context_handling policy_level=critical>
36
- After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `extract` tool also returns a confirmation message listing what was extracted.
38
+ After each assistant turn, the environment calls the \`context_info\` tool to inject an assistant message containing a <prunable-tools> list and optional nudge instruction. This tool is only available to the environment - you do not have access to it.
37
39
 
38
40
  CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
39
41
  - NEVER reference the extract encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the extract encouragement appears.
@@ -46,4 +48,5 @@ CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
46
48
 
47
49
  The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
48
50
  </instruction>
49
- </system-reminder>
51
+ </system-reminder>`;
52
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../lib/prompts/system/extract.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAkDlB,CAAA"}
@@ -13,4 +13,10 @@ export interface PersistedSessionState {
13
13
  }
14
14
  export declare function saveSessionState(sessionState: SessionState, logger: Logger, sessionName?: string): Promise<void>;
15
15
  export declare function loadSessionState(sessionId: string, logger: Logger): Promise<PersistedSessionState | null>;
16
+ export interface AggregatedStats {
17
+ totalTokens: number;
18
+ totalTools: number;
19
+ sessionCount: number;
20
+ }
21
+ export declare function loadAllSessionStats(logger: Logger): Promise<AggregatedStats>;
16
22
  //# sourceMappingURL=persistence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../lib/state/persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK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CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;CACvB;AAED,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAqClF"}
@@ -70,4 +70,38 @@ export async function loadSessionState(sessionId, logger) {
70
70
  return null;
71
71
  }
72
72
  }
73
+ export async function loadAllSessionStats(logger) {
74
+ const result = {
75
+ totalTokens: 0,
76
+ totalTools: 0,
77
+ sessionCount: 0,
78
+ };
79
+ try {
80
+ if (!existsSync(STORAGE_DIR)) {
81
+ return result;
82
+ }
83
+ const files = await fs.readdir(STORAGE_DIR);
84
+ const jsonFiles = files.filter((f) => f.endsWith(".json"));
85
+ for (const file of jsonFiles) {
86
+ try {
87
+ const filePath = join(STORAGE_DIR, file);
88
+ const content = await fs.readFile(filePath, "utf-8");
89
+ const state = JSON.parse(content);
90
+ if (state?.stats?.totalPruneTokens && state?.prune?.toolIds) {
91
+ result.totalTokens += state.stats.totalPruneTokens;
92
+ result.totalTools += state.prune.toolIds.length;
93
+ result.sessionCount++;
94
+ }
95
+ }
96
+ catch {
97
+ // Skip invalid files
98
+ }
99
+ }
100
+ logger.debug("Loaded all-time stats", result);
101
+ }
102
+ catch (error) {
103
+ logger.warn("Failed to load all-time stats", { error: error?.message });
104
+ }
105
+ return result;
106
+ }
73
107
  //# sourceMappingURL=persistence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../../lib/state/persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAW3B,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OA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AAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAA;IACjD,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,MAAM,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;IAC3E,CAAC;IAED,OAAO,MAAM,CAAA;AACjB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tool-cache.d.ts","sourceRoot":"","sources":["../../../lib/state/tool-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAKxC;;GAEG;AACH,wBAAsB,aAAa,CAC/B,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CAmEf;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAajE"}
1
+ {"version":3,"file":"tool-cache.d.ts","sourceRoot":"","sources":["../../../lib/state/tool-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAKxC;;GAEG;AACH,wBAAsB,aAAa,CAC/B,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CAqEf;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAajE"}
@@ -25,7 +25,9 @@ export async function syncToolCache(state, config, logger, messages) {
25
25
  const isProtectedByTurn = turnProtectionEnabled &&
26
26
  turnProtectionTurns > 0 &&
27
27
  state.currentTurn - turnCounter < turnProtectionTurns;
28
- state.lastToolPrune = part.tool === "discard" || part.tool === "extract";
28
+ state.lastToolPrune =
29
+ (part.tool === "discard" || part.tool === "extract") &&
30
+ part.state.status === "completed";
29
31
  const allProtectedTools = config.tools.settings.protectedTools;
30
32
  if (part.tool === "discard" || part.tool === "extract") {
31
33
  state.nudgeCounter = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-cache.js","sourceRoot":"","sources":["../../../lib/state/tool-cache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAEhC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAC/B,KAAmB,EACnB,MAAoB,EACpB,MAAc,EACd,QAAqB;IAErB,IAAI,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;QAE7D,KAAK,CAAC,YAAY,GAAG,CAAC,CAAA;QACtB,IAAI,WAAW,GAAG,CAAC,CAAA;QAEnB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YACzB,IAAI,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;gBACjC,SAAQ;YACZ,CAAC;YAED,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBAC3B,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAC7B,WAAW,EAAE,CAAA;oBACb,SAAQ;gBACZ,CAAC;gBAED,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;oBACvC,SAAQ;gBACZ,CAAC;gBAED,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ourceRoot":"","sources":["../../../lib/strategies/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAiC,MAAM,UAAU,CAAA;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAM7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAQvC,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,YAAY,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,YAAY,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;CAC3B;AAoID,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CA0BhF;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAqChF"}
@@ -17,14 +17,14 @@ async function executePruneOperation(ctx, toolCtx, ids, reason, toolName, distil
17
17
  logger.info(JSON.stringify(reason ? { ids, reason } : { ids }));
18
18
  if (!ids || ids.length === 0) {
19
19
  logger.debug(`${toolName} tool called but ids is empty or undefined`);
20
- return `No IDs provided. Check the <prunable-tools> list for available IDs to ${toolName.toLowerCase()}.`;
20
+ throw new Error(`No IDs provided. Check the <prunable-tools> list for available IDs to ${toolName.toLowerCase()}.`);
21
21
  }
22
22
  const numericToolIds = ids
23
23
  .map((id) => parseInt(id, 10))
24
24
  .filter((n) => !isNaN(n));
25
25
  if (numericToolIds.length === 0) {
26
26
  logger.debug(`No numeric tool IDs provided for ${toolName}: ` + JSON.stringify(ids));
27
- return "No numeric IDs provided. Format: ids: [id1, id2, ...]";
27
+ throw new Error("No numeric IDs provided. Format: ids: [id1, id2, ...]");
28
28
  }
29
29
  // Fetch messages to calculate tokens and find current agent
30
30
  const messagesResponse = await client.session.messages({
@@ -37,7 +37,7 @@ async function executePruneOperation(ctx, toolCtx, ids, reason, toolName, distil
37
37
  // Validate that all numeric IDs are within bounds
38
38
  if (numericToolIds.some((id) => id < 0 || id >= toolIdList.length)) {
39
39
  logger.debug("Invalid tool IDs provided: " + numericToolIds.join(", "));
40
- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.";
40
+ throw new Error("Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.");
41
41
  }
42
42
  // Validate that all IDs exist in cache and aren't protected
43
43
  // (rejects hallucinated IDs and turn-protected tools not shown in <prunable-tools>)
@@ -46,7 +46,7 @@ async function executePruneOperation(ctx, toolCtx, ids, reason, toolName, distil
46
46
  const metadata = state.toolParameters.get(id);
47
47
  if (!metadata) {
48
48
  logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id });
49
- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.";
49
+ throw new Error("Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.");
50
50
  }
51
51
  const allProtectedTools = config.tools.settings.protectedTools;
52
52
  if (allProtectedTools.includes(metadata.tool)) {
@@ -55,7 +55,7 @@ async function executePruneOperation(ctx, toolCtx, ids, reason, toolName, distil
55
55
  id,
56
56
  tool: metadata.tool,
57
57
  });
58
- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.";
58
+ throw new Error("Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.");
59
59
  }
60
60
  const filePath = getFilePathFromParameters(metadata.parameters);
61
61
  if (isProtectedFilePath(filePath, config.protectedFilePatterns)) {
@@ -65,7 +65,7 @@ async function executePruneOperation(ctx, toolCtx, ids, reason, toolName, distil
65
65
  tool: metadata.tool,
66
66
  filePath,
67
67
  });
68
- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.";
68
+ throw new Error("Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list.");
69
69
  }
70
70
  }
71
71
  const pruneToolIds = numericToolIds.map((index) => toolIdList[index]);
@@ -102,7 +102,7 @@ export function createDiscardTool(ctx) {
102
102
  const validReasons = ["completion", "noise"];
103
103
  if (typeof reason !== "string" || !validReasons.includes(reason)) {
104
104
  ctx.logger.debug("Invalid discard reason provided: " + reason);
105
- return "No valid reason found. Use 'completion' or 'noise' as the first element.";
105
+ throw new Error("No valid reason found. Use 'completion' or 'noise' as the first element.");
106
106
  }
107
107
  const numericIds = args.ids.slice(1);
108
108
  return executePruneOperation(ctx, toolCtx, numericIds, reason, "Discard");
@@ -123,7 +123,7 @@ export function createExtractTool(ctx) {
123
123
  async execute(args, toolCtx) {
124
124
  if (!args.distillation || args.distillation.length === 0) {
125
125
  ctx.logger.debug("Extract tool called without distillation: " + JSON.stringify(args));
126
- return "Missing distillation. You must provide a distillation string for each ID.";
126
+ throw new Error("Missing distillation. You must provide a distillation string for each ID.");
127
127
  }
128
128
  // Log the distillation for debugging/analysis
129
129
  ctx.logger.info("Distillation data received:");
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../lib/strategies/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAG1C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAe,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAE3F,MAAM,wBAAwB,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;AA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AAQ,CAAC,kEAAkE,CAAC;YACjF,YAAY,EAAE,IAAI,CAAC,MAAM;iBACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;iBAC3B,QAAQ,CACL,0FAA0F,CAC7F;SACR;QACD,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO;YACvB,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvD,GAAG,CAAC,MAAM,CAAC,KAAK,CACZ,4CAA4C,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACtE,CAAA;gBACD,MAAM,IAAI,KAAK,CACX,2EAA2E,CAC9E,CAAA;YACL,CAAC;YAED,8CAA8C;YAC9C,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;YAC9C,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YAE3D,OAAO,qBAAqB,CACxB,GAAG,EACH,OAAO,EACP,IAAI,CAAC,GAAG,EACR,YAA2B,EAC3B,SAAS,EACT,IAAI,CAAC,YAAY,CACpB,CAAA;QACL,CAAC;KACJ,CAAC,CAAA;AACN,CAAC"}
@@ -6,8 +6,6 @@ export declare function getCurrentParams(state: SessionState, messages: WithPart
6
6
  agent: string | undefined;
7
7
  variant: string | undefined;
8
8
  };
9
- /**
10
- * Calculates approximate tokens saved by pruning the given tool call IDs.
11
- */
9
+ export declare function countTokens(text: string): number;
12
10
  export declare const calculateTokensSaved: (state: SessionState, messages: WithParts[], pruneToolIds: string[]) => number;
13
11
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/strategies/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,SAAS,EAAE,EACrB,MAAM,EAAE,MAAM,GACf;IACC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,CAkBA;AAaD;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC7B,OAAO,YAAY,EACnB,UAAU,SAAS,EAAE,EACrB,cAAc,MAAM,EAAE,KACvB,MAwCF,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/strategies/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,SAAS,EAAE,EACrB,MAAM,EAAE,MAAM,GACf;IACC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,CAkBA;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOhD;AAMD,eAAO,MAAM,oBAAoB,GAC7B,OAAO,YAAY,EACnB,UAAU,SAAS,EAAE,EACrB,cAAc,MAAM,EAAE,KACvB,MAwCF,CAAA"}
@@ -1,4 +1,4 @@
1
- import { encode } from "gpt-tokenizer";
1
+ import { countTokens as anthropicCountTokens } from "@anthropic-ai/tokenizer";
2
2
  import { getLastUserMessage, isMessageCompacted } from "../shared-utils";
3
3
  export function getCurrentParams(state, messages, logger) {
4
4
  const userMsg = getLastUserMessage(messages);
@@ -18,20 +18,19 @@ export function getCurrentParams(state, messages, logger) {
18
18
  const variant = state.variant ?? userInfo.variant;
19
19
  return { providerId, modelId, agent, variant };
20
20
  }
21
- /**
22
- * Estimates token counts for a batch of texts using gpt-tokenizer.
23
- */
24
- function estimateTokensBatch(texts) {
21
+ export function countTokens(text) {
22
+ if (!text)
23
+ return 0;
25
24
  try {
26
- return texts.map((text) => encode(text).length);
25
+ return anthropicCountTokens(text);
27
26
  }
28
27
  catch {
29
- return texts.map((text) => Math.round(text.length / 4));
28
+ return Math.round(text.length / 4);
30
29
  }
31
30
  }
32
- /**
33
- * Calculates approximate tokens saved by pruning the given tool call IDs.
34
- */
31
+ function estimateTokensBatch(texts) {
32
+ return texts.map(countTokens);
33
+ }
35
34
  export const calculateTokensSaved = (state, messages, pruneToolIds) => {
36
35
  try {
37
36
  const contents = [];
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/strategies/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAExE,MAAM,UAAU,gBAAgB,CAC5B,KAAmB,EACnB,QAAqB,EACrB,MAAc;IAOd,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAA;QACrE,OAAO;YACH,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,SAAS;YAClB,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;SACzB,CAAA;IACL,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAA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K,QAAQ;wBACjC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;wBACnB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;oBAC3C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBAC1B,CAAC;qBAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;oBACvC,MAAM,OAAO,GACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ;wBAChC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;wBAClB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBAC1C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBAC1B,CAAC;YACL,CAAC;QACL,CAAC;QACD,MAAM,WAAW,GAAa,mBAAmB,CAAC,QAAQ,CAAC,CAAA;QAC3D,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,CAAA;IACZ,CAAC;AACL,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@tarquinen/opencode-dcp",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "type": "module",
6
6
  "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "scripts": {
10
10
  "clean": "rm -rf dist",
11
- "build": "npm run clean && tsc && cp -r lib/prompts/*.txt lib/prompts/system lib/prompts/nudge dist/lib/prompts/",
11
+ "build": "npm run clean && tsc",
12
12
  "postbuild": "rm -rf dist/logs",
13
13
  "prepublishOnly": "npm run build",
14
14
  "dev": "opencode plugin dev",
@@ -40,8 +40,8 @@
40
40
  "@opencode-ai/plugin": ">=0.13.7"
41
41
  },
42
42
  "dependencies": {
43
+ "@anthropic-ai/tokenizer": "^0.0.4",
43
44
  "@opencode-ai/sdk": "^1.1.3",
44
- "gpt-tokenizer": "^3.4.0",
45
45
  "jsonc-parser": "^3.3.1",
46
46
  "zod": "^4.1.13"
47
47
  },