@tarquinen/opencode-dcp 1.0.4 → 1.1.0-beta.2

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 (82) hide show
  1. package/README.md +68 -43
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +47 -17
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/config.d.ts +20 -7
  6. package/dist/lib/config.d.ts.map +1 -1
  7. package/dist/lib/config.js +320 -158
  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 +3 -0
  11. package/dist/lib/hooks.js.map +1 -1
  12. package/dist/lib/logger.d.ts +17 -0
  13. package/dist/lib/logger.d.ts.map +1 -1
  14. package/dist/lib/logger.js +90 -7
  15. package/dist/lib/logger.js.map +1 -1
  16. package/dist/lib/messages/prune.d.ts.map +1 -1
  17. package/dist/lib/messages/prune.js +90 -29
  18. package/dist/lib/messages/prune.js.map +1 -1
  19. package/dist/lib/messages/utils.js +7 -7
  20. package/dist/lib/model-selector.d.ts +3 -3
  21. package/dist/lib/model-selector.d.ts.map +1 -1
  22. package/dist/lib/model-selector.js +34 -34
  23. package/dist/lib/model-selector.js.map +1 -1
  24. package/dist/lib/prompt.d.ts.map +1 -1
  25. package/dist/lib/prompt.js +37 -25
  26. package/dist/lib/prompt.js.map +1 -1
  27. package/dist/lib/prompts/discard-tool-spec.txt +56 -0
  28. package/dist/lib/prompts/extract-tool-spec.txt +79 -0
  29. package/dist/lib/prompts/nudge/nudge-both.txt +10 -0
  30. package/dist/lib/prompts/nudge/nudge-discard.txt +9 -0
  31. package/dist/lib/prompts/nudge/nudge-extract.txt +9 -0
  32. package/dist/lib/prompts/{synthetic.txt → system/system-prompt-both.txt} +23 -13
  33. package/dist/lib/prompts/system/system-prompt-discard.txt +49 -0
  34. package/dist/lib/prompts/system/system-prompt-extract.txt +49 -0
  35. package/dist/lib/shared-utils.d.ts.map +1 -1
  36. package/dist/lib/shared-utils.js +1 -1
  37. package/dist/lib/shared-utils.js.map +1 -1
  38. package/dist/lib/state/persistence.d.ts.map +1 -1
  39. package/dist/lib/state/persistence.js +4 -7
  40. package/dist/lib/state/persistence.js.map +1 -1
  41. package/dist/lib/state/state.d.ts +1 -0
  42. package/dist/lib/state/state.d.ts.map +1 -1
  43. package/dist/lib/state/state.js +26 -6
  44. package/dist/lib/state/state.js.map +1 -1
  45. package/dist/lib/state/tool-cache.d.ts.map +1 -1
  46. package/dist/lib/state/tool-cache.js +24 -10
  47. package/dist/lib/state/tool-cache.js.map +1 -1
  48. package/dist/lib/state/types.d.ts +2 -0
  49. package/dist/lib/state/types.d.ts.map +1 -1
  50. package/dist/lib/strategies/deduplication.js +4 -4
  51. package/dist/lib/strategies/deduplication.js.map +1 -1
  52. package/dist/lib/strategies/index.d.ts +1 -1
  53. package/dist/lib/strategies/index.d.ts.map +1 -1
  54. package/dist/lib/strategies/index.js +1 -1
  55. package/dist/lib/strategies/index.js.map +1 -1
  56. package/dist/lib/strategies/on-idle.d.ts.map +1 -1
  57. package/dist/lib/strategies/on-idle.js +25 -24
  58. package/dist/lib/strategies/on-idle.js.map +1 -1
  59. package/dist/lib/strategies/supersede-writes.js +4 -4
  60. package/dist/lib/strategies/supersede-writes.js.map +1 -1
  61. package/dist/lib/strategies/{prune-tool.d.ts → tools.d.ts} +3 -6
  62. package/dist/lib/strategies/tools.d.ts.map +1 -0
  63. package/dist/lib/strategies/tools.js +127 -0
  64. package/dist/lib/strategies/tools.js.map +1 -0
  65. package/dist/lib/strategies/utils.d.ts +0 -1
  66. package/dist/lib/strategies/utils.d.ts.map +1 -1
  67. package/dist/lib/strategies/utils.js +20 -10
  68. package/dist/lib/strategies/utils.js.map +1 -1
  69. package/dist/lib/ui/notification.d.ts +1 -0
  70. package/dist/lib/ui/notification.d.ts.map +1 -1
  71. package/dist/lib/ui/notification.js +44 -20
  72. package/dist/lib/ui/notification.js.map +1 -1
  73. package/dist/lib/ui/utils.d.ts.map +1 -1
  74. package/dist/lib/ui/utils.js +9 -9
  75. package/dist/lib/ui/utils.js.map +1 -1
  76. package/package.json +61 -58
  77. package/dist/lib/prompts/nudge.txt +0 -10
  78. package/dist/lib/prompts/tool.txt +0 -72
  79. package/dist/lib/strategies/prune-tool.d.ts.map +0 -1
  80. package/dist/lib/strategies/prune-tool.js +0 -88
  81. package/dist/lib/strategies/prune-tool.js.map +0 -1
  82. /package/dist/lib/prompts/{pruning.txt → on-idle-analysis.txt} +0 -0
@@ -1,44 +1,44 @@
1
1
  export const FALLBACK_MODELS = {
2
- openai: 'gpt-5-mini',
3
- anthropic: 'claude-haiku-4-5', //This model isn't broken in opencode-auth-provider
4
- google: 'gemini-2.5-flash',
5
- deepseek: 'deepseek-chat',
6
- xai: 'grok-4-fast',
7
- alibaba: 'qwen3-coder-flash',
8
- zai: 'glm-4.5-flash',
9
- opencode: 'big-pickle'
2
+ openai: "gpt-5-mini",
3
+ anthropic: "claude-haiku-4-5", //This model isn't broken in opencode-auth-provider
4
+ google: "gemini-2.5-flash",
5
+ deepseek: "deepseek-chat",
6
+ xai: "grok-4-fast",
7
+ alibaba: "qwen3-coder-flash",
8
+ zai: "glm-4.5-flash",
9
+ opencode: "big-pickle",
10
10
  };
11
11
  const PROVIDER_PRIORITY = [
12
- 'openai',
13
- 'anthropic',
14
- 'google',
15
- 'deepseek',
16
- 'xai',
17
- 'alibaba',
18
- 'zai',
19
- 'opencode'
12
+ "openai",
13
+ "anthropic",
14
+ "google",
15
+ "deepseek",
16
+ "xai",
17
+ "alibaba",
18
+ "zai",
19
+ "opencode",
20
20
  ];
21
21
  // TODO: some anthropic provided models aren't supported by the opencode-auth-provider package, so this provides a temporary workaround
22
- const SKIP_PROVIDERS = ['github-copilot', 'anthropic'];
22
+ const SKIP_PROVIDERS = ["github-copilot", "anthropic"];
23
23
  function shouldSkipProvider(providerID) {
24
24
  const normalized = providerID.toLowerCase().trim();
25
- return SKIP_PROVIDERS.some(skip => normalized.includes(skip.toLowerCase()));
25
+ return SKIP_PROVIDERS.some((skip) => normalized.includes(skip.toLowerCase()));
26
26
  }
27
27
  async function importOpencodeAI(logger, maxRetries = 3, delayMs = 100, workspaceDir) {
28
28
  let lastError;
29
29
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
30
30
  try {
31
- const { OpencodeAI } = await import('@tarquinen/opencode-auth-provider');
31
+ const { OpencodeAI } = await import("@tarquinen/opencode-auth-provider");
32
32
  return new OpencodeAI({ workspaceDir });
33
33
  }
34
34
  catch (error) {
35
35
  lastError = error;
36
- if (error.message?.includes('before initialization')) {
36
+ if (error.message?.includes("before initialization")) {
37
37
  logger?.debug(`Import attempt ${attempt}/${maxRetries} failed, will retry`, {
38
- error: error.message
38
+ error: error.message,
39
39
  });
40
40
  if (attempt < maxRetries) {
41
- await new Promise(resolve => setTimeout(resolve, delayMs * attempt));
41
+ await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
42
42
  continue;
43
43
  }
44
44
  }
@@ -51,9 +51,9 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
51
51
  const opencodeAI = await importOpencodeAI(logger, 3, 100, workspaceDir);
52
52
  let failedModelInfo;
53
53
  if (configModel) {
54
- const parts = configModel.split('/');
54
+ const parts = configModel.split("/");
55
55
  if (parts.length !== 2) {
56
- logger?.warn('Invalid config model format', { configModel });
56
+ logger?.warn("Invalid config model format", { configModel });
57
57
  }
58
58
  else {
59
59
  const [providerID, modelID] = parts;
@@ -62,13 +62,13 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
62
62
  return {
63
63
  model,
64
64
  modelInfo: { providerID, modelID },
65
- source: 'config',
66
- reason: 'Using model specified in dcp.jsonc config'
65
+ source: "config",
66
+ reason: "Using model specified in dcp.jsonc config",
67
67
  };
68
68
  }
69
69
  catch (error) {
70
70
  logger?.warn(`Config model failed: ${providerID}/${modelID}`, {
71
- error: error.message
71
+ error: error.message,
72
72
  });
73
73
  failedModelInfo = { providerID, modelID };
74
74
  }
@@ -86,8 +86,8 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
86
86
  return {
87
87
  model,
88
88
  modelInfo: currentModel,
89
- source: 'user-model',
90
- reason: 'Using current session model'
89
+ source: "user-model",
90
+ reason: "Using current session model",
91
91
  };
92
92
  }
93
93
  catch (error) {
@@ -109,22 +109,22 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
109
109
  return {
110
110
  model,
111
111
  modelInfo: { providerID, modelID: fallbackModelID },
112
- source: 'fallback',
112
+ source: "fallback",
113
113
  reason: `Using ${providerID}/${fallbackModelID}`,
114
- failedModel: failedModelInfo
114
+ failedModel: failedModelInfo,
115
115
  };
116
116
  }
117
117
  catch (error) {
118
118
  continue;
119
119
  }
120
120
  }
121
- throw new Error('No available models for analysis. Please authenticate with at least one provider.');
121
+ throw new Error("No available models for analysis. Please authenticate with at least one provider.");
122
122
  }
123
123
  export function extractModelFromSession(sessionState, logger) {
124
124
  if (sessionState?.model?.providerID && sessionState?.model?.modelID) {
125
125
  return {
126
126
  providerID: sessionState.model.providerID,
127
- modelID: sessionState.model.modelID
127
+ modelID: sessionState.model.modelID,
128
128
  };
129
129
  }
130
130
  if (sessionState?.messages && Array.isArray(sessionState.messages)) {
@@ -132,7 +132,7 @@ export function extractModelFromSession(sessionState, logger) {
132
132
  if (lastMessage?.model?.providerID && lastMessage?.model?.modelID) {
133
133
  return {
134
134
  providerID: lastMessage.model.providerID,
135
- modelID: lastMessage.model.modelID
135
+ modelID: lastMessage.model.modelID,
136
136
  };
137
137
  }
138
138
  }
@@ -1 +1 @@
1
- {"version":3,"file":"model-selector.js","sourceRoot":"","sources":["../../lib/model-selector.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,eAAe,GAA2B;IACnD,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,kBAAkB,EAAE,mDAAmD;IAClF,MAAM,EAAE,kBAAkB;IAC1B,QAAQ,EAAE,eAAe;IACzB,GAAG,EAAE,aAAa;IAClB,O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IAAI,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAClE,OAAO;YACH,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,UAAU;YACzC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO;SACtC,CAAA;IACL,CAAC;IAED,IAAI,YAAY,EAAE,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjE,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC3E,IAAI,WAAW,EAAE,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAChE,OAAO;gBACH,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,UAAU;gBACxC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO;aACrC,CAAA;QACL,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAS9E;AA4GD,wBAAgB,mBAAmB,CAC/B,mBAAmB,EAAE,MAAM,EAAE,EAC7B,QAAQ,EAAE,GAAG,EAAE,EACf,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,GAChC,MAAM,CAQR"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAS9E;AA2HD,wBAAgB,mBAAmB,CAC/B,mBAAmB,EAAE,MAAM,EAAE,EAC7B,QAAQ,EAAE,GAAG,EAAE,EACf,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,GAChC,MAAM,CAQR"}
@@ -5,80 +5,91 @@ export function loadPrompt(name, vars) {
5
5
  let content = readFileSync(filePath, "utf8").trim();
6
6
  if (vars) {
7
7
  for (const [key, value] of Object.entries(vars)) {
8
- content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, 'g'), value);
8
+ content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
9
9
  }
10
10
  }
11
11
  return content;
12
12
  }
13
13
  function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
14
- const prunedIdsSet = alreadyPrunedIds ? new Set(alreadyPrunedIds.map(id => id.toLowerCase())) : new Set();
15
- const protectedIdsSet = protectedToolCallIds ? new Set(protectedToolCallIds.map(id => id.toLowerCase())) : new Set();
16
- return messages.map(msg => {
14
+ const prunedIdsSet = alreadyPrunedIds
15
+ ? new Set(alreadyPrunedIds.map((id) => id.toLowerCase()))
16
+ : new Set();
17
+ const protectedIdsSet = protectedToolCallIds
18
+ ? new Set(protectedToolCallIds.map((id) => id.toLowerCase()))
19
+ : new Set();
20
+ return messages
21
+ .map((msg) => {
17
22
  const minimized = {
18
- role: msg.info?.role
23
+ role: msg.info?.role,
19
24
  };
20
25
  if (msg.parts) {
21
26
  minimized.parts = msg.parts
22
27
  .filter((part) => {
23
- if (part.type === 'step-start' || part.type === 'step-finish') {
28
+ if (part.type === "step-start" || part.type === "step-finish") {
24
29
  return false;
25
30
  }
26
31
  return true;
27
32
  })
28
33
  .map((part) => {
29
- if (part.type === 'text') {
34
+ if (part.type === "text") {
30
35
  if (part.ignored) {
31
36
  return null;
32
37
  }
33
38
  return {
34
- type: 'text',
35
- text: part.text
39
+ type: "text",
40
+ text: part.text,
36
41
  };
37
42
  }
38
43
  // TODO: This should use the opencode normalized system instead of per provider settings
39
- if (part.type === 'reasoning') {
44
+ if (part.type === "reasoning") {
40
45
  // Calculate encrypted content size if present
41
46
  let encryptedContentLength = 0;
42
47
  if (part.metadata?.openai?.reasoningEncryptedContent) {
43
- encryptedContentLength = part.metadata.openai.reasoningEncryptedContent.length;
48
+ encryptedContentLength =
49
+ part.metadata.openai.reasoningEncryptedContent.length;
44
50
  }
45
51
  else if (part.metadata?.anthropic?.signature) {
46
52
  encryptedContentLength = part.metadata.anthropic.signature.length;
47
53
  }
48
54
  else if (part.metadata?.google?.thoughtSignature) {
49
- encryptedContentLength = part.metadata.google.thoughtSignature.length;
55
+ encryptedContentLength =
56
+ part.metadata.google.thoughtSignature.length;
50
57
  }
51
58
  return {
52
- type: 'reasoning',
59
+ type: "reasoning",
53
60
  text: part.text,
54
61
  textLength: part.text?.length || 0,
55
62
  encryptedContentLength,
56
63
  ...(part.time && { time: part.time }),
57
- ...(part.metadata && { metadataKeys: Object.keys(part.metadata) })
64
+ ...(part.metadata && { metadataKeys: Object.keys(part.metadata) }),
58
65
  };
59
66
  }
60
- if (part.type === 'tool') {
67
+ if (part.type === "tool") {
61
68
  const callIDLower = part.callID?.toLowerCase();
62
69
  const isAlreadyPruned = prunedIdsSet.has(callIDLower);
63
70
  const isProtected = protectedIdsSet.has(callIDLower);
64
71
  let displayCallID = part.callID;
65
72
  if (isAlreadyPruned) {
66
- displayCallID = '<already-pruned>';
73
+ displayCallID = "<already-pruned>";
67
74
  }
68
75
  else if (isProtected) {
69
- displayCallID = '<protected>';
76
+ displayCallID = "<protected>";
70
77
  }
71
78
  const toolPart = {
72
- type: 'tool',
79
+ type: "tool",
73
80
  toolCallID: displayCallID,
74
- tool: part.tool
81
+ tool: part.tool,
75
82
  };
76
83
  if (part.state?.output) {
77
84
  toolPart.output = part.state.output;
78
85
  }
79
86
  if (part.state?.input) {
80
87
  const input = part.state.input;
81
- if (input.filePath && (part.tool === 'write' || part.tool === 'edit' || part.tool === 'multiedit' || part.tool === 'patch')) {
88
+ if (input.filePath &&
89
+ (part.tool === "write" ||
90
+ part.tool === "edit" ||
91
+ part.tool === "multiedit" ||
92
+ part.tool === "patch")) {
82
93
  toolPart.input = input;
83
94
  }
84
95
  else if (input.filePath) {
@@ -87,7 +98,7 @@ function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
87
98
  else if (input.tool_calls && Array.isArray(input.tool_calls)) {
88
99
  toolPart.input = {
89
100
  batch_summary: `${input.tool_calls.length} tool calls`,
90
- tools: input.tool_calls.map((tc) => tc.tool)
101
+ tools: input.tool_calls.map((tc) => tc.tool),
91
102
  };
92
103
  }
93
104
  else {
@@ -101,16 +112,17 @@ function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
101
112
  .filter(Boolean);
102
113
  }
103
114
  return minimized;
104
- }).filter(msg => {
115
+ })
116
+ .filter((msg) => {
105
117
  return msg.parts && msg.parts.length > 0;
106
118
  });
107
119
  }
108
120
  export function buildAnalysisPrompt(unprunedToolCallIds, messages, alreadyPrunedIds, protectedToolCallIds) {
109
121
  const minimizedMessages = minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds);
110
- const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, '\n');
111
- return loadPrompt("pruning", {
122
+ const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, "\n");
123
+ return loadPrompt("on-idle-analysis", {
112
124
  available_tool_call_ids: unprunedToolCallIds.join(", "),
113
- session_history: messagesJson
125
+ session_history: messagesJson,
114
126
  });
115
127
  }
116
128
  //# sourceMappingURL=prompt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,MAAM,UAAU,UAAU,CAAC,IAAY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AO,SAAS,CAAA;IACpB,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QACZ,OAAO,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,mBAA6B,EAC7B,QAAe,EACf,gBAA2B,EAC3B,oBAA+B;IAE/B,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,oBAAoB,CAAC,CAAA;IAC5F,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAErF,OAAO,UAAU,CAAC,kBAAkB,EAAE;QAClC,uBAAuB,EAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;QACvD,eAAe,EAAE,YAAY;KAChC,CAAC,CAAA;AACN,CAAC"}
@@ -0,0 +1,56 @@
1
+ Discards tool outputs from context to manage conversation size and reduce noise.
2
+
3
+ ## IMPORTANT: The Prunable List
4
+ A `<prunable-tools>` list is injected into user messages showing available tool outputs you can discard when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to discard.
5
+
6
+ **Note:** For `write` and `edit` tools, discarding removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context.
7
+
8
+ ## When to Use This Tool
9
+
10
+ Use `discard` for removing tool outputs that are no longer needed **without preserving their content**:
11
+
12
+ ### 1. Task Completion (Clean Up)
13
+ **When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question).
14
+ **Action:** Discard the tools used for that task with reason `completion`.
15
+
16
+ ### 2. Removing Noise (Garbage Collection)
17
+ **When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information).
18
+ **Action:** Discard these specific tool outputs immediately with reason `noise`.
19
+
20
+ ## When NOT to Use This Tool
21
+
22
+ - **If you need to preserve information:** Keep the raw output in context rather than discarding it.
23
+ - **If you'll need the output later:** Don't discard files you plan to edit, or context you'll need for implementation.
24
+
25
+ ## Best Practices
26
+ - **Strategic Batching:** Don't discard single small tool outputs (like short bash commands) unless they are pure noise. Wait until you have several items to perform high-impact discards.
27
+ - **Think ahead:** Before discarding, ask: "Will I need this output for an upcoming task?" If yes, keep it.
28
+
29
+ ## Format
30
+ The `ids` parameter is an array where the first element is the reason, followed by numeric IDs:
31
+ `ids: ["reason", "id1", "id2", ...]`
32
+
33
+ ## Examples
34
+
35
+ <example_noise>
36
+ Assistant: [Reads 'wrong_file.ts']
37
+ This file isn't relevant to the auth system. I'll remove it to clear the context.
38
+ [Uses discard with ids: ["noise", "5"]]
39
+ </example_noise>
40
+
41
+ <example_completion>
42
+ Assistant: [Runs tests, they pass]
43
+ The tests passed. I'll clean up now.
44
+ [Uses discard with ids: ["completion", "20", "21"]]
45
+ </example_completion>
46
+
47
+ <example_keep>
48
+ Assistant: [Reads 'auth.ts' to understand the login flow]
49
+ I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than discarding.
50
+ </example_keep>
51
+
52
+ <example_edit_completion>
53
+ Assistant: [Edits 'auth.ts' to add validation]
54
+ The edit was successful. I no longer need the raw edit content in context.
55
+ [Uses discard with ids: ["completion", "15"]]
56
+ </example_edit_completion>
@@ -0,0 +1,79 @@
1
+ Extracts key findings from tool outputs into distilled knowledge, then removes the raw outputs from context.
2
+
3
+ ## IMPORTANT: The Prunable List
4
+ A `<prunable-tools>` list is injected into user messages showing available tool outputs you can extract from when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to extract.
5
+
6
+ ## When to Use This Tool
7
+
8
+ Use `extract` when you have gathered useful information that you want to **preserve in distilled form** before removing the raw outputs:
9
+
10
+ ### 1. Task Completion
11
+ **When:** You have completed a unit of work and want to preserve key findings.
12
+ **Action:** Extract with distillation scaled to the value of the content. High-value insights require comprehensive capture; routine completions can use lighter distillation.
13
+
14
+ ### 2. Knowledge Preservation
15
+ **When:** You have read files, run commands, or gathered context that contains valuable information you'll need to reference later, but the full raw output is too large to keep.
16
+ **Action:** Convert raw data into distilled knowledge. This allows you to remove large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant).
17
+
18
+ ## CRITICAL: Distillation Requirements
19
+
20
+ You MUST provide distilled findings in the `distillation` parameter. This is not optional.
21
+
22
+ - **Comprehensive Capture:** Distillation is not just a summary. It must be a high-fidelity representation of the technical details. If you read a file, the distillation should include function signatures, specific logic flows, constant values, and any constraints or edge cases discovered.
23
+ - **Task-Relevant Verbosity:** Be as verbose as necessary to ensure that the "distilled" version is a complete substitute for the raw output for the task at hand. If you will need to reference a specific algorithm or interface later, include it in its entirety within the distillation.
24
+ - **Extract Per-ID:** When extracting from multiple tools, your `distillation` object MUST contain a corresponding entry for EVERY ID being extracted. You must capture high-fidelity findings for each tool individually to ensure no signal is lost.
25
+ - **Structure:** Map EVERY `ID` from the `ids` array to its specific distilled findings.
26
+ Example: `{ "20": { ... }, "21": { ... } }`
27
+ - Capture all relevant details (function names, logic, constraints) to ensure no signal is lost.
28
+ - Prioritize information that is essential for the immediate next steps of your plan.
29
+
30
+ ## When NOT to Use This Tool
31
+
32
+ - **If you need precise syntax:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original.
33
+ - **If uncertain:** Prefer keeping over re-fetching. The cost of retaining context is lower than the cost of redundant tool calls.
34
+
35
+ ## Best Practices
36
+ - **Technical Fidelity:** Ensure that types, parameters, and return values are preserved if they are relevant to upcoming implementation steps.
37
+ - **Strategic Batching:** Wait until you have several items or a few large outputs to extract, rather than doing tiny, frequent extractions. Aim for high-impact extractions that significantly reduce context size.
38
+ - **Think ahead:** Before extracting, ask: "Will I need the raw output for an upcoming task?" If you researched a file you'll later edit, do NOT extract it.
39
+
40
+ ## Format
41
+ The `ids` parameter is an array of numeric IDs as strings:
42
+ `ids: ["id1", "id2", ...]`
43
+
44
+ The `distillation` parameter is an object mapping each ID to its distilled findings:
45
+ `distillation: { "id1": { ...findings... }, "id2": { ...findings... } }`
46
+
47
+ ## Example
48
+
49
+ <example_extraction>
50
+ Assistant: [Reads service implementation, types, and config]
51
+ I'll preserve the full technical specification and implementation logic before extracting.
52
+ [Uses extract with ids: ["10", "11", "12"], distillation: {
53
+ "10": {
54
+ "file": "src/services/auth.ts",
55
+ "signatures": [
56
+ "async function validateToken(token: string): Promise<User | null>",
57
+ "function hashPassword(password: string): string"
58
+ ],
59
+ "logic": "The validateToken function first checks the local cache before calling the external OIDC provider. It uses a 5-minute TTL for cached tokens.",
60
+ "dependencies": ["import { cache } from '../utils/cache'", "import { oidc } from '../config'"],
61
+ "constraints": "Tokens must be at least 128 chars long. hashPassword uses bcrypt with 12 rounds."
62
+ },
63
+ "11": {
64
+ "file": "src/types/user.ts",
65
+ "interface": "interface User { id: string; email: string; permissions: ('read' | 'write' | 'admin')[]; status: 'active' | 'suspended'; }",
66
+ "context": "The permissions array is strictly typed and used by the RBAC middleware."
67
+ },
68
+ "12": {
69
+ "file": "config/default.json",
70
+ "values": { "PORT": 3000, "RETRY_STRATEGY": "exponential", "MAX_ATTEMPTS": 5 },
71
+ "impact": "The retry strategy affects all outgoing HTTP clients in the core module."
72
+ }
73
+ }]
74
+ </example_extraction>
75
+
76
+ <example_keep>
77
+ Assistant: [Reads 'auth.ts' to understand the login flow]
78
+ I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than extracting.
79
+ </example_keep>
@@ -0,0 +1,10 @@
1
+ <instruction name=context_management_required>
2
+ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required.
3
+
4
+ **Immediate Actions Required:**
5
+ 1. **Task Completion:** If a sub-task is complete, decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping.
6
+ 2. **Noise Removal:** If you read files or ran commands that yielded no value, use `discard` to remove them.
7
+ 3. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use `extract` to distill the insights and remove the raw entry.
8
+
9
+ **Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must perform context management.
10
+ </instruction>
@@ -0,0 +1,9 @@
1
+ <instruction name=context_management_required>
2
+ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required.
3
+
4
+ **Immediate Actions Required:**
5
+ 1. **Task Completion:** If a sub-task is complete, use the `discard` tool to remove the tools used.
6
+ 2. **Noise Removal:** If you read files or ran commands that yielded no value, use the `discard` tool to remove them.
7
+
8
+ **Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must discard unneeded tool outputs.
9
+ </instruction>
@@ -0,0 +1,9 @@
1
+ <instruction name=context_management_required>
2
+ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required.
3
+
4
+ **Immediate Actions Required:**
5
+ 1. **Task Completion:** If you have completed work, extract key findings from the tools used. Scale distillation depth to the value of the content.
6
+ 2. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry.
7
+
8
+ **Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract valuable findings from tool outputs.
9
+ </instruction>
@@ -2,21 +2,30 @@
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 `prune` 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 prune.
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.
6
6
 
7
- PRUNE EARLY, PRUNE OFTEN - BUT PRUNE METHODICALLY
8
- Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Evaluate what SHOULD be pruned before jumping the gun.
7
+ 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.
9
10
 
10
- WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER
11
- 1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore
12
- 2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune IMMEDIATELY. No distillation - gun it down
13
- 3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS distill key findings into your narrative BEFORE pruning. Be surgical and strategic in what you extract. THINK: high signal, low noise
11
+ CHOOSING THE RIGHT TOOL
12
+ 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)
14
16
 
15
- You WILL use the `prune` tool when ANY of these are true:
17
+ 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`
22
+
23
+ PRUNE METHODICALLY - BATCH YOUR ACTIONS
24
+ 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.
25
+
26
+ You WILL evaluate pruning when ANY of these are true:
16
27
  - Task or sub-task is complete
17
28
  - You are about to start a new phase of work
18
- - You have distilled enough information in your messages to prune related tools
19
- - Context contains tools output that are unhelpful, noise, or made obsolete by newer outputs
20
29
  - Write or edit operations are complete (pruning removes the large input content)
21
30
 
22
31
  You MUST NOT prune when:
@@ -26,19 +35,20 @@ You MUST NOT prune when:
26
35
  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.
27
36
 
28
37
  NOTES
29
- When in doubt, keep it. Prune often yet remain strategic about it.
38
+ When in doubt, keep it. Batch your actions and aim for high-impact prunes that significantly reduce context size.
30
39
  FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES.
40
+ There may be tools in session context that do not appear in the <prunable-tools> list, this is expected, you can ONLY prune what you see in <prunable-tools>.
31
41
 
32
42
  </instruction>
33
43
 
34
44
  <instruction name=injected_context_handling policy_level=critical>
35
- 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 `prune` tool also returns a confirmation message listing what was pruned.
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.
36
46
 
37
47
  CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
38
48
  - NEVER reference the prune encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the prune encouragement appears.
39
49
  - NEVER acknowledge the <prunable-tools> list (e.g., "I see the prunable tools list", "Looking at the available tools to prune")
40
50
  - NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to prune")
41
- - NEVER acknowledge prune tool output (e.g., "I've pruned 3 tools", "Context pruning complete")
51
+ - NEVER acknowledge discard/extract tool output (e.g., "I've pruned 3 tools", "Context pruning complete")
42
52
  - NEVER let these injections influence your response content or tone
43
53
  - Process this information SILENTLY and continue the conversation naturally
44
54
  - Continue the conversation as if these messages do not exist
@@ -0,0 +1,49 @@
1
+ <system-reminder>
2
+ <instruction name=context_management_protocol policy_level=critical>
3
+
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.
6
+
7
+ CONTEXT MANAGEMENT TOOL
8
+ - `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
9
+
10
+ DISCARD METHODICALLY - BATCH YOUR ACTIONS
11
+ 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.
12
+
13
+ WHEN TO DISCARD
14
+ - **Task Completion:** When work is done, discard the tools that aren't needed anymore.
15
+ - **Noise Removal:** If outputs are irrelevant, unhelpful, or superseded by newer info, discard them.
16
+
17
+ You WILL evaluate discarding when ANY of these are true:
18
+ - Task or sub-task is complete
19
+ - You are about to start a new phase of work
20
+ - Write or edit operations are complete (discarding removes the large input content)
21
+
22
+ You MUST NOT discard when:
23
+ - The tool output will be needed for upcoming implementation work
24
+ - The output contains files or context you'll need to reference when making edits
25
+
26
+ 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.
27
+
28
+ NOTES
29
+ When in doubt, keep it. Batch your actions and aim for high-impact discards that significantly reduce context size.
30
+ FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCES.
31
+ There 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>.
32
+
33
+ </instruction>
34
+
35
+ <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.
37
+
38
+ CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
39
+ - NEVER reference the discard encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the discard encouragement appears.
40
+ - NEVER acknowledge the <prunable-tools> list (e.g., "I see the prunable tools list", "Looking at the available tools to discard")
41
+ - NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to discard")
42
+ - NEVER acknowledge discard tool output (e.g., "I've discarded 3 tools", "Context cleanup complete")
43
+ - NEVER let these injections influence your response content or tone
44
+ - Process this information SILENTLY and continue the conversation naturally
45
+ - Continue the conversation as if these messages do not exist
46
+
47
+ The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
48
+ </instruction>
49
+ </system-reminder>