@tarquinen/opencode-dcp 1.3.1-beta.0 → 1.3.1-beta1
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.
- package/README.md +8 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -25
- package/dist/index.js.map +1 -1
- package/dist/lib/commands/context.d.ts.map +1 -1
- package/dist/lib/commands/context.js +23 -36
- package/dist/lib/commands/context.js.map +1 -1
- package/dist/lib/config.d.ts +4 -9
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +28 -59
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +16 -8
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/messages/inject.d.ts +0 -7
- package/dist/lib/messages/inject.d.ts.map +1 -1
- package/dist/lib/messages/inject.js +51 -90
- package/dist/lib/messages/inject.js.map +1 -1
- package/dist/lib/messages/prune.d.ts.map +1 -1
- package/dist/lib/messages/prune.js +1 -42
- package/dist/lib/messages/prune.js.map +1 -1
- package/dist/lib/messages/utils.d.ts +0 -2
- package/dist/lib/messages/utils.d.ts.map +1 -1
- package/dist/lib/messages/utils.js +12 -21
- package/dist/lib/messages/utils.js.map +1 -1
- package/dist/lib/prompts/discard-tool-spec.d.ts +2 -0
- package/dist/lib/prompts/discard-tool-spec.d.ts.map +1 -0
- package/dist/lib/prompts/discard-tool-spec.js +41 -0
- package/dist/lib/prompts/discard-tool-spec.js.map +1 -0
- package/dist/lib/prompts/extract-tool-spec.d.ts +2 -0
- package/dist/lib/prompts/extract-tool-spec.d.ts.map +1 -0
- package/dist/lib/prompts/{distill-tool-spec.js → extract-tool-spec.js} +14 -14
- package/dist/lib/prompts/extract-tool-spec.js.map +1 -0
- package/dist/lib/prompts/index.d.ts +0 -7
- package/dist/lib/prompts/index.d.ts.map +1 -1
- package/dist/lib/prompts/index.js +18 -28
- package/dist/lib/prompts/index.js.map +1 -1
- package/dist/lib/prompts/nudge/both.d.ts +2 -0
- package/dist/lib/prompts/nudge/both.d.ts.map +1 -0
- package/dist/lib/prompts/nudge/both.js +11 -0
- package/dist/lib/prompts/nudge/both.js.map +1 -0
- package/dist/lib/prompts/nudge/discard.d.ts +2 -0
- package/dist/lib/prompts/nudge/discard.d.ts.map +1 -0
- package/dist/lib/prompts/nudge/discard.js +10 -0
- package/dist/lib/prompts/nudge/discard.js.map +1 -0
- package/dist/lib/prompts/nudge/extract.d.ts +2 -0
- package/dist/lib/prompts/nudge/extract.d.ts.map +1 -0
- package/dist/lib/prompts/nudge/extract.js +10 -0
- package/dist/lib/prompts/nudge/extract.js.map +1 -0
- package/dist/lib/prompts/system/both.d.ts +2 -0
- package/dist/lib/prompts/system/both.d.ts.map +1 -0
- package/dist/lib/prompts/system/both.js +61 -0
- package/dist/lib/prompts/system/both.js.map +1 -0
- package/dist/lib/prompts/system/discard.d.ts +2 -0
- package/dist/lib/prompts/system/discard.d.ts.map +1 -0
- package/dist/lib/prompts/system/discard.js +52 -0
- package/dist/lib/prompts/system/discard.js.map +1 -0
- package/dist/lib/prompts/system/extract.d.ts +2 -0
- package/dist/lib/prompts/system/extract.d.ts.map +1 -0
- package/dist/lib/prompts/system/extract.js +52 -0
- package/dist/lib/prompts/system/extract.js.map +1 -0
- package/dist/lib/shared-utils.d.ts +1 -1
- package/dist/lib/shared-utils.d.ts.map +1 -1
- package/dist/lib/shared-utils.js +3 -10
- package/dist/lib/shared-utils.js.map +1 -1
- package/dist/lib/state/persistence.d.ts +1 -2
- package/dist/lib/state/persistence.d.ts.map +1 -1
- package/dist/lib/state/persistence.js +0 -1
- package/dist/lib/state/persistence.js.map +1 -1
- package/dist/lib/state/state.d.ts +1 -0
- package/dist/lib/state/state.d.ts.map +1 -1
- package/dist/lib/state/state.js +29 -10
- package/dist/lib/state/state.js.map +1 -1
- package/dist/lib/state/tool-cache.d.ts.map +1 -1
- package/dist/lib/state/tool-cache.js +3 -2
- package/dist/lib/state/tool-cache.js.map +1 -1
- package/dist/lib/state/types.d.ts +0 -6
- package/dist/lib/state/types.d.ts.map +1 -1
- package/dist/lib/state/utils.d.ts +0 -4
- package/dist/lib/state/utils.d.ts.map +1 -1
- package/dist/lib/state/utils.js +0 -33
- package/dist/lib/state/utils.js.map +1 -1
- package/dist/lib/strategies/index.d.ts +1 -1
- package/dist/lib/strategies/index.d.ts.map +1 -1
- package/dist/lib/strategies/index.js +1 -1
- package/dist/lib/strategies/index.js.map +1 -1
- package/dist/lib/{tools/types.d.ts → strategies/tools.d.ts} +4 -1
- package/dist/lib/strategies/tools.d.ts.map +1 -0
- package/dist/lib/strategies/tools.js +135 -0
- package/dist/lib/strategies/tools.js.map +1 -0
- package/dist/lib/strategies/utils.d.ts +0 -1
- package/dist/lib/strategies/utils.d.ts.map +1 -1
- package/dist/lib/strategies/utils.js +4 -5
- package/dist/lib/strategies/utils.js.map +1 -1
- package/dist/lib/ui/notification.d.ts +0 -1
- package/dist/lib/ui/notification.d.ts.map +1 -1
- package/dist/lib/ui/notification.js +4 -32
- package/dist/lib/ui/notification.js.map +1 -1
- package/dist/lib/ui/utils.d.ts +0 -1
- package/dist/lib/ui/utils.d.ts.map +1 -1
- package/dist/lib/ui/utils.js +0 -16
- package/dist/lib/ui/utils.js.map +1 -1
- package/package.json +4 -7
- package/dist/lib/auth.d.ts +0 -4
- package/dist/lib/auth.d.ts.map +0 -1
- package/dist/lib/auth.js +0 -32
- package/dist/lib/auth.js.map +0 -1
- package/dist/lib/prompts/compress-tool-spec.d.ts +0 -2
- package/dist/lib/prompts/compress-tool-spec.d.ts.map +0 -1
- package/dist/lib/prompts/compress-tool-spec.js +0 -58
- package/dist/lib/prompts/compress-tool-spec.js.map +0 -1
- package/dist/lib/prompts/distill-tool-spec.d.ts +0 -2
- package/dist/lib/prompts/distill-tool-spec.d.ts.map +0 -1
- package/dist/lib/prompts/distill-tool-spec.js.map +0 -1
- package/dist/lib/prompts/prune-tool-spec.d.ts +0 -2
- package/dist/lib/prompts/prune-tool-spec.d.ts.map +0 -1
- package/dist/lib/prompts/prune-tool-spec.js +0 -40
- package/dist/lib/prompts/prune-tool-spec.js.map +0 -1
- package/dist/lib/tools/compress.d.ts +0 -4
- package/dist/lib/tools/compress.d.ts.map +0 -1
- package/dist/lib/tools/compress.js +0 -81
- package/dist/lib/tools/compress.js.map +0 -1
- package/dist/lib/tools/distill.d.ts +0 -4
- package/dist/lib/tools/distill.d.ts.map +0 -1
- package/dist/lib/tools/distill.js +0 -35
- package/dist/lib/tools/distill.js.map +0 -1
- package/dist/lib/tools/index.d.ts +0 -5
- package/dist/lib/tools/index.d.ts.map +0 -1
- package/dist/lib/tools/index.js +0 -4
- package/dist/lib/tools/index.js.map +0 -1
- package/dist/lib/tools/prune-shared.d.ts +0 -6
- package/dist/lib/tools/prune-shared.d.ts.map +0 -1
- package/dist/lib/tools/prune-shared.js +0 -107
- package/dist/lib/tools/prune-shared.js.map +0 -1
- package/dist/lib/tools/prune.d.ts +0 -4
- package/dist/lib/tools/prune.d.ts.map +0 -1
- package/dist/lib/tools/prune.js +0 -21
- package/dist/lib/tools/prune.js.map +0 -1
- package/dist/lib/tools/types.d.ts.map +0 -1
- package/dist/lib/tools/types.js +0 -2
- package/dist/lib/tools/types.js.map +0 -1
- package/dist/lib/tools/utils.d.ts +0 -26
- package/dist/lib/tools/utils.d.ts.map +0 -1
- package/dist/lib/tools/utils.js +0 -121
- package/dist/lib/tools/utils.js.map +0 -1
package/dist/lib/ui/utils.js
CHANGED
|
@@ -30,22 +30,6 @@ export function truncate(str, maxLen = 60) {
|
|
|
30
30
|
return str;
|
|
31
31
|
return str.slice(0, maxLen - 3) + "...";
|
|
32
32
|
}
|
|
33
|
-
export function formatProgressBar(total, start, end, width = 20) {
|
|
34
|
-
if (total <= 0)
|
|
35
|
-
return `│${" ".repeat(width)}│`;
|
|
36
|
-
const startIdx = Math.floor((start / total) * width);
|
|
37
|
-
const endIdx = Math.min(width - 1, Math.floor((end / total) * width));
|
|
38
|
-
let bar = "";
|
|
39
|
-
for (let i = 0; i < width; i++) {
|
|
40
|
-
if (i >= startIdx && i <= endIdx) {
|
|
41
|
-
bar += "░";
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
bar += "█";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return `│${bar}│`;
|
|
48
|
-
}
|
|
49
33
|
export function shortenPath(input, workingDirectory) {
|
|
50
34
|
const inPathMatch = input.match(/^(.+) in (.+)$/);
|
|
51
35
|
if (inPathMatch) {
|
package/dist/lib/ui/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/ui/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,MAAM,UAAU,uBAAuB,CAAC,YAAuB;IAC3D,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IACxD,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAC/C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,YAAuB;IACnD,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,EAAE,CAAA;IACb,CAAC;IACD,IAAI,MAAM,GAAG,iBAAiB,CAAA;IAC9B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;QACjC,MAAM,IAAI,UAAU,OAAO,EAAE,CAAA;IACjC,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,gBAAwB,EAAE,iBAAyB;IACjF,MAAM,mBAAmB,GAAG,IAAI,gBAAgB,CAAC,gBAAgB,GAAG,iBAAiB,CAAC,EAAE,C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AAY,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAA;IAC3E,MAAM,YAAY,GAAG,YAAY,CAAC,MAAM,GAAG,UAAU,CAAA;IAErD,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC,MAAM,YAAY,QAAQ,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAA;IAC9F,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC;AAED,MAAM,UAAU,0BAA0B,CACtC,SAAmB,EACnB,YAA6C,EAC7C,gBAAyB;IAEzB,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,CAAC,IAAI,CAAC,oCAAoC,SAAS,CAAC,MAAM,gBAAgB,CAAC,CAAA;IAChF,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEd,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CAAC,wBAAwB,SAAS,CAAC,MAAM,IAAI,CAAC,CAAA;QACxD,KAAK,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC,SAAS,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAA;IACnF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAA;AAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@tarquinen/opencode-dcp",
|
|
4
|
-
"version": "1.3.1-
|
|
4
|
+
"version": "1.3.1-beta1",
|
|
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
|
-
"generate:prompts": "tsx scripts/generate-prompts.ts",
|
|
12
|
-
"prebuild": "npm run generate:prompts",
|
|
13
11
|
"build": "npm run clean && tsc",
|
|
12
|
+
"postbuild": "rm -rf dist/logs",
|
|
14
13
|
"prepublishOnly": "npm run build",
|
|
15
14
|
"dev": "opencode plugin dev",
|
|
16
|
-
"typecheck": "
|
|
15
|
+
"typecheck": "tsc --noEmit",
|
|
17
16
|
"test": "node --import tsx --test tests/*.test.ts",
|
|
18
17
|
"format": "prettier --write .",
|
|
19
|
-
"format:check": "prettier --check ."
|
|
20
|
-
"dcp": "tsx scripts/print.ts"
|
|
18
|
+
"format:check": "prettier --check ."
|
|
21
19
|
},
|
|
22
20
|
"keywords": [
|
|
23
21
|
"opencode",
|
|
@@ -45,7 +43,6 @@
|
|
|
45
43
|
"@anthropic-ai/tokenizer": "^0.0.4",
|
|
46
44
|
"@opencode-ai/sdk": "^1.1.3",
|
|
47
45
|
"jsonc-parser": "^3.3.1",
|
|
48
|
-
"ulid": "^3.0.2",
|
|
49
46
|
"zod": "^4.1.13"
|
|
50
47
|
},
|
|
51
48
|
"devDependencies": {
|
package/dist/lib/auth.d.ts
DELETED
package/dist/lib/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../lib/auth.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,SAAS,CAQ3D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAsBpD"}
|
package/dist/lib/auth.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export function isSecureMode() {
|
|
2
|
-
return !!process.env.OPENCODE_SERVER_PASSWORD;
|
|
3
|
-
}
|
|
4
|
-
export function getAuthorizationHeader() {
|
|
5
|
-
const password = process.env.OPENCODE_SERVER_PASSWORD;
|
|
6
|
-
if (!password)
|
|
7
|
-
return undefined;
|
|
8
|
-
const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode";
|
|
9
|
-
// Use Buffer for Node.js base64 encoding (btoa may not be available in all Node versions)
|
|
10
|
-
const credentials = Buffer.from(`${username}:${password}`).toString("base64");
|
|
11
|
-
return `Basic ${credentials}`;
|
|
12
|
-
}
|
|
13
|
-
export function configureClientAuth(client) {
|
|
14
|
-
const authHeader = getAuthorizationHeader();
|
|
15
|
-
if (!authHeader) {
|
|
16
|
-
return client;
|
|
17
|
-
}
|
|
18
|
-
// The SDK client has an internal client with request interceptors
|
|
19
|
-
// Access the underlying client to add the interceptor
|
|
20
|
-
const innerClient = client._client || client.client;
|
|
21
|
-
if (innerClient?.interceptors?.request) {
|
|
22
|
-
innerClient.interceptors.request.use((request) => {
|
|
23
|
-
// Only add auth header if not already present
|
|
24
|
-
if (!request.headers.has("Authorization")) {
|
|
25
|
-
request.headers.set("Authorization", authHeader);
|
|
26
|
-
}
|
|
27
|
-
return request;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return client;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=auth.js.map
|
package/dist/lib/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../lib/auth.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY;IACxB,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,sBAAsB;IAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAA;IACrD,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAA;IAE/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,UAAU,CAAA;IACnE,0FAA0F;IAC1F,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC7E,OAAO,SAAS,WAAW,EAAE,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAW;IAC3C,MAAM,UAAU,GAAG,sBAAsB,EAAE,CAAA;IAE3C,IAAI,CAAC,UAAU,EAAE,CAAC;QACd,OAAO,MAAM,CAAA;IACjB,CAAC;IAED,kEAAkE;IAClE,sDAAsD;IACtD,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAA;IAEnD,IAAI,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;QACrC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAgB,EAAE,EAAE;YACtD,8CAA8C;YAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;gBACxC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;YACpD,CAAC;YACD,OAAO,OAAO,CAAA;QAClB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,OAAO,MAAM,CAAA;AACjB,CAAC"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const COMPRESS_TOOL_SPEC = "Collapses a contiguous range of conversation into a single summary.\n\n## When to Use This Tool\n\nUse `compress` when you want to condense an entire sequence of work into a brief summary:\n\n- **Phase Completion:** You completed a phase (research, tool calls, implementation) and want to collapse the entire sequence into a summary.\n- **Exploration Done:** You explored multiple files or ran multiple commands and only need a summary of what you learned.\n- **Failed Attempts:** You tried several unsuccessful approaches and want to condense them into a brief note.\n- **Verbose Output:** A section of conversation has grown large but can be summarized without losing critical details.\n\n## When NOT to Use This Tool\n\n- **If you need specific details:** If you'll need exact code, file contents, or error messages from the range, keep them.\n- **For individual tool outputs:** Use `prune` or `distill` for single tool outputs. Compress targets conversation ranges.\n- **If it's recent content:** You may still need recent work for the current phase.\n\n## How It Works\n\n1. `startString` \u2014 A unique text string that marks the start of the range to compress\n2. `endString` \u2014 A unique text string that marks the end of the range to compress\n3. `topic` \u2014 A short label (3-5 words) describing the compressed content\n4. `summary` \u2014 The replacement text that will be inserted\n\nEverything between startString and endString (inclusive) is removed and replaced with your summary.\n\n**Important:** The compress will FAIL if `startString` or `endString` is not found in the conversation. The compress will also FAIL if either string is found multiple times. Provide a larger string with more surrounding context to uniquely identify the intended match.\n\n## Best Practices\n- **Choose unique strings:** Pick text that appears only once in the conversation.\n- **Write concise topics:** Examples: \"Auth System Exploration\", \"Token Logic Refactor\"\n- **Write comprehensive summaries:** Include key information like file names, function signatures, and important findings.\n- **Timing:** Best used after finishing a work phase, not during active exploration.\n\n## Format\n\n- `input`: Array with four elements: [startString, endString, topic, summary]\n\n## Example\n\n<example_compress>\nConversation: [Asked about auth] -> [Read 5 files] -> [Analyzed patterns] -> [Found \"JWT tokens with 24h expiry\"]\n\n[Uses compress with:\n input: [\n \"Asked about authentication\",\n \"JWT tokens with 24h expiry\",\n \"Auth System Exploration\",\n \"Auth: JWT 24h expiry, bcrypt passwords, refresh rotation. Files: auth.ts, tokens.ts, middleware/auth.ts\"\n ]\n]\n</example_compress>\n\n<example_keep>\nAssistant: [Just finished reading auth.ts]\nI've read the auth file and now need to make edits based on it. I'm keeping this in context rather than compressing.\n</example_keep>";
|
|
2
|
-
//# sourceMappingURL=compress-tool-spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress-tool-spec.d.ts","sourceRoot":"","sources":["../../../lib/prompts/compress-tool-spec.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,o2FAwDf,CAAA"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export const COMPRESS_TOOL_SPEC = `Collapses a contiguous range of conversation into a single summary.
|
|
2
|
-
|
|
3
|
-
## When to Use This Tool
|
|
4
|
-
|
|
5
|
-
Use \`compress\` when you want to condense an entire sequence of work into a brief summary:
|
|
6
|
-
|
|
7
|
-
- **Phase Completion:** You completed a phase (research, tool calls, implementation) and want to collapse the entire sequence into a summary.
|
|
8
|
-
- **Exploration Done:** You explored multiple files or ran multiple commands and only need a summary of what you learned.
|
|
9
|
-
- **Failed Attempts:** You tried several unsuccessful approaches and want to condense them into a brief note.
|
|
10
|
-
- **Verbose Output:** A section of conversation has grown large but can be summarized without losing critical details.
|
|
11
|
-
|
|
12
|
-
## When NOT to Use This Tool
|
|
13
|
-
|
|
14
|
-
- **If you need specific details:** If you'll need exact code, file contents, or error messages from the range, keep them.
|
|
15
|
-
- **For individual tool outputs:** Use \`prune\` or \`distill\` for single tool outputs. Compress targets conversation ranges.
|
|
16
|
-
- **If it's recent content:** You may still need recent work for the current phase.
|
|
17
|
-
|
|
18
|
-
## How It Works
|
|
19
|
-
|
|
20
|
-
1. \`startString\` — A unique text string that marks the start of the range to compress
|
|
21
|
-
2. \`endString\` — A unique text string that marks the end of the range to compress
|
|
22
|
-
3. \`topic\` — A short label (3-5 words) describing the compressed content
|
|
23
|
-
4. \`summary\` — The replacement text that will be inserted
|
|
24
|
-
|
|
25
|
-
Everything between startString and endString (inclusive) is removed and replaced with your summary.
|
|
26
|
-
|
|
27
|
-
**Important:** The compress will FAIL if \`startString\` or \`endString\` is not found in the conversation. The compress will also FAIL if either string is found multiple times. Provide a larger string with more surrounding context to uniquely identify the intended match.
|
|
28
|
-
|
|
29
|
-
## Best Practices
|
|
30
|
-
- **Choose unique strings:** Pick text that appears only once in the conversation.
|
|
31
|
-
- **Write concise topics:** Examples: "Auth System Exploration", "Token Logic Refactor"
|
|
32
|
-
- **Write comprehensive summaries:** Include key information like file names, function signatures, and important findings.
|
|
33
|
-
- **Timing:** Best used after finishing a work phase, not during active exploration.
|
|
34
|
-
|
|
35
|
-
## Format
|
|
36
|
-
|
|
37
|
-
- \`input\`: Array with four elements: [startString, endString, topic, summary]
|
|
38
|
-
|
|
39
|
-
## Example
|
|
40
|
-
|
|
41
|
-
<example_compress>
|
|
42
|
-
Conversation: [Asked about auth] -> [Read 5 files] -> [Analyzed patterns] -> [Found "JWT tokens with 24h expiry"]
|
|
43
|
-
|
|
44
|
-
[Uses compress with:
|
|
45
|
-
input: [
|
|
46
|
-
"Asked about authentication",
|
|
47
|
-
"JWT tokens with 24h expiry",
|
|
48
|
-
"Auth System Exploration",
|
|
49
|
-
"Auth: JWT 24h expiry, bcrypt passwords, refresh rotation. Files: auth.ts, tokens.ts, middleware/auth.ts"
|
|
50
|
-
]
|
|
51
|
-
]
|
|
52
|
-
</example_compress>
|
|
53
|
-
|
|
54
|
-
<example_keep>
|
|
55
|
-
Assistant: [Just finished reading auth.ts]
|
|
56
|
-
I've read the auth file and now need to make edits based on it. I'm keeping this in context rather than compressing.
|
|
57
|
-
</example_keep>`;
|
|
58
|
-
//# sourceMappingURL=compress-tool-spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress-tool-spec.js","sourceRoot":"","sources":["../../../lib/prompts/compress-tool-spec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAwDlB,CAAA"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const DISTILL_TOOL_SPEC = "Distills key findings from tool outputs into preserved knowledge, then removes the raw outputs from context.\n\n## IMPORTANT: The Prunable List\nA `<prunable-tools>` list is provided to you showing available tool outputs you can distill 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 distill.\n\n## When to Use This Tool\n\nUse `distill` when you have individual tool outputs with valuable information you want to **preserve in distilled form** before removing the raw content:\n\n- **Large Outputs:** The raw output is too large but contains valuable technical details worth keeping.\n- **Knowledge Preservation:** You have context that contains valuable information (signatures, logic, constraints) but also a lot of unnecessary detail.\n\n## When NOT to Use This Tool\n\n- **If you need precise syntax:** If you'll edit a file or grep for exact strings, keep the raw output.\n- **If uncertain:** Prefer keeping over re-fetching.\n\n\n## Best Practices\n- **Strategic Batching:** Wait until you have several items or a few large outputs to distill, rather than doing tiny, frequent distillations. Aim for high-impact distillations that significantly reduce context size.\n- **Think ahead:** Before distilling, ask: \"Will I need the raw output for upcoming work?\" If you researched a file you'll later edit, do NOT distill it.\n\n## Format\n\n- `ids`: Array of numeric IDs as strings from the `<prunable-tools>` list\n- `distillation`: Array of strings, one per ID (positional: distillation[0] is for ids[0], etc.)\n\nEach distillation string should capture the essential information you need to preserve - function signatures, logic, constraints, values, etc. Be as detailed as needed.\n\n## Example\n\n<example_distillation>\nAssistant: [Reads auth service and user types]\nI'll preserve the key details before distilling.\n[Uses distill with:\n ids: [\"10\", \"11\"],\n distillation: [\n \"auth.ts: validateToken(token: string) -> User|null checks cache first (5min TTL) then OIDC. hashPassword uses bcrypt 12 rounds. Tokens must be 128+ chars.\",\n \"user.ts: interface User { id: string; email: string; permissions: ('read'|'write'|'admin')[]; status: 'active'|'suspended' }\"\n ]\n]\n</example_distillation>\n\n<example_keep>\nAssistant: [Reads 'auth.ts' to understand the login flow]\nI'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 distilling.\n</example_keep>";
|
|
2
|
-
//# sourceMappingURL=distill-tool-spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"distill-tool-spec.d.ts","sourceRoot":"","sources":["../../../lib/prompts/distill-tool-spec.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,glFA8Cd,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"distill-tool-spec.js","sourceRoot":"","sources":["../../../lib/prompts/distill-tool-spec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA8CjB,CAAA"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const PRUNE_TOOL_SPEC = "Prunes tool outputs from context to manage conversation size and reduce noise.\n\n## IMPORTANT: The Prunable List\nA `<prunable-tools>` list is provided to you showing available tool outputs you can prune 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 prune.\n\n## When to Use This Tool\n\nUse `prune` for removing individual tool outputs that are no longer needed:\n\n- **Noise:** Irrelevant, unhelpful, or superseded outputs that provide no value.\n- **Wrong Files:** You read or accessed something that turned out to be irrelevant.\n- **Outdated Info:** Outputs that have been superseded by newer information.\n\n## When NOT to Use This Tool\n\n- **If the output contains useful information:** Keep it in context rather than pruning.\n- **If you'll need the output later:** Don't prune files you plan to edit or context you'll need for implementation.\n\n## Best Practices\n- **Strategic Batching:** Don't prune single small tool outputs (like short bash commands) unless they are pure noise. Wait until you have several items to perform high-impact prunes.\n- **Think ahead:** Before pruning, ask: \"Will I need this output for upcoming work?\" If yes, keep it.\n\n## Format\n\n- `ids`: Array of numeric IDs as strings from the `<prunable-tools>` list\n\n## Example\n\n<example_noise>\nAssistant: [Reads 'wrong_file.ts']\nThis file isn't relevant to the auth system. I'll remove it to clear the context.\n[Uses prune with ids: [\"5\"]]\n</example_noise>\n\n<example_superseded>\nAssistant: [Reads config.ts, then reads updated config.ts after changes]\nThe first read is now outdated. I'll prune it and keep the updated version.\n[Uses prune with ids: [\"20\"]]\n</example_superseded>";
|
|
2
|
-
//# sourceMappingURL=prune-tool-spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prune-tool-spec.d.ts","sourceRoot":"","sources":["../../../lib/prompts/prune-tool-spec.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,+zDAsCN,CAAA"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export const PRUNE_TOOL_SPEC = `Prunes tool outputs from context to manage conversation size and reduce noise.
|
|
2
|
-
|
|
3
|
-
## IMPORTANT: The Prunable List
|
|
4
|
-
A \`<prunable-tools>\` list is provided to you showing available tool outputs you can prune 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 prune.
|
|
5
|
-
|
|
6
|
-
## When to Use This Tool
|
|
7
|
-
|
|
8
|
-
Use \`prune\` for removing individual tool outputs that are no longer needed:
|
|
9
|
-
|
|
10
|
-
- **Noise:** Irrelevant, unhelpful, or superseded outputs that provide no value.
|
|
11
|
-
- **Wrong Files:** You read or accessed something that turned out to be irrelevant.
|
|
12
|
-
- **Outdated Info:** Outputs that have been superseded by newer information.
|
|
13
|
-
|
|
14
|
-
## When NOT to Use This Tool
|
|
15
|
-
|
|
16
|
-
- **If the output contains useful information:** Keep it in context rather than pruning.
|
|
17
|
-
- **If you'll need the output later:** Don't prune files you plan to edit or context you'll need for implementation.
|
|
18
|
-
|
|
19
|
-
## Best Practices
|
|
20
|
-
- **Strategic Batching:** Don't prune single small tool outputs (like short bash commands) unless they are pure noise. Wait until you have several items to perform high-impact prunes.
|
|
21
|
-
- **Think ahead:** Before pruning, ask: "Will I need this output for upcoming work?" If yes, keep it.
|
|
22
|
-
|
|
23
|
-
## Format
|
|
24
|
-
|
|
25
|
-
- \`ids\`: Array of numeric IDs as strings from the \`<prunable-tools>\` list
|
|
26
|
-
|
|
27
|
-
## Example
|
|
28
|
-
|
|
29
|
-
<example_noise>
|
|
30
|
-
Assistant: [Reads 'wrong_file.ts']
|
|
31
|
-
This file isn't relevant to the auth system. I'll remove it to clear the context.
|
|
32
|
-
[Uses prune with ids: ["5"]]
|
|
33
|
-
</example_noise>
|
|
34
|
-
|
|
35
|
-
<example_superseded>
|
|
36
|
-
Assistant: [Reads config.ts, then reads updated config.ts after changes]
|
|
37
|
-
The first read is now outdated. I'll prune it and keep the updated version.
|
|
38
|
-
[Uses prune with ids: ["20"]]
|
|
39
|
-
</example_superseded>`;
|
|
40
|
-
//# sourceMappingURL=prune-tool-spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prune-tool-spec.js","sourceRoot":"","sources":["../../../lib/prompts/prune-tool-spec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAsCT,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../../../lib/tools/compress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAe/C,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,gBAAgB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAyIjF"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { tool } from "@opencode-ai/plugin";
|
|
2
|
-
import { ensureSessionInitialized } from "../state";
|
|
3
|
-
import { saveSessionState } from "../state/persistence";
|
|
4
|
-
import { loadPrompt } from "../prompts";
|
|
5
|
-
import { estimateTokensBatch, getCurrentParams } from "../strategies/utils";
|
|
6
|
-
import { collectContentInRange, findStringInMessages, collectToolIdsInRange, collectMessageIdsInRange, } from "./utils";
|
|
7
|
-
import { sendCompressNotification } from "../ui/notification";
|
|
8
|
-
const COMPRESS_TOOL_DESCRIPTION = loadPrompt("compress-tool-spec");
|
|
9
|
-
export function createCompressTool(ctx) {
|
|
10
|
-
return tool({
|
|
11
|
-
description: COMPRESS_TOOL_DESCRIPTION,
|
|
12
|
-
args: {
|
|
13
|
-
input: tool.schema
|
|
14
|
-
.array(tool.schema.string())
|
|
15
|
-
.length(4)
|
|
16
|
-
.describe("[startString, endString, topic, summary] - 4 required strings: (1) startString: unique text from conversation marking range start, (2) endString: unique text marking range end, (3) topic: short 3-5 word label for UI, (4) summary: comprehensive text replacing all compressed content"),
|
|
17
|
-
},
|
|
18
|
-
async execute(args, toolCtx) {
|
|
19
|
-
const { client, state, logger } = ctx;
|
|
20
|
-
const sessionId = toolCtx.sessionID;
|
|
21
|
-
const [startString, endString, topic, summary] = args.input;
|
|
22
|
-
logger.info("Compress tool invoked");
|
|
23
|
-
// logger.info(
|
|
24
|
-
// JSON.stringify({
|
|
25
|
-
// startString: startString?.substring(0, 50) + "...",
|
|
26
|
-
// endString: endString?.substring(0, 50) + "...",
|
|
27
|
-
// topic: topic,
|
|
28
|
-
// summaryLength: summary?.length,
|
|
29
|
-
// }),
|
|
30
|
-
// )
|
|
31
|
-
const messagesResponse = await client.session.messages({
|
|
32
|
-
path: { id: sessionId },
|
|
33
|
-
});
|
|
34
|
-
const messages = messagesResponse.data || messagesResponse;
|
|
35
|
-
await ensureSessionInitialized(client, state, sessionId, logger, messages);
|
|
36
|
-
const startResult = findStringInMessages(messages, startString, logger, state.compressSummaries, "startString");
|
|
37
|
-
const endResult = findStringInMessages(messages, endString, logger, state.compressSummaries, "endString");
|
|
38
|
-
if (startResult.messageIndex > endResult.messageIndex) {
|
|
39
|
-
throw new Error(`startString appears after endString in the conversation. Start must come before end.`);
|
|
40
|
-
}
|
|
41
|
-
const containedToolIds = collectToolIdsInRange(messages, startResult.messageIndex, endResult.messageIndex);
|
|
42
|
-
const containedMessageIds = collectMessageIdsInRange(messages, startResult.messageIndex, endResult.messageIndex);
|
|
43
|
-
state.prune.toolIds.push(...containedToolIds);
|
|
44
|
-
state.prune.messageIds.push(...containedMessageIds);
|
|
45
|
-
// Remove any existing summaries whose anchors are now inside this range
|
|
46
|
-
// This prevents duplicate injections when a larger compress subsumes a smaller one
|
|
47
|
-
const removedSummaries = state.compressSummaries.filter((s) => containedMessageIds.includes(s.anchorMessageId));
|
|
48
|
-
if (removedSummaries.length > 0) {
|
|
49
|
-
// logger.info("Removing subsumed compress summaries", {
|
|
50
|
-
// count: removedSummaries.length,
|
|
51
|
-
// anchorIds: removedSummaries.map((s) => s.anchorMessageId),
|
|
52
|
-
// })
|
|
53
|
-
state.compressSummaries = state.compressSummaries.filter((s) => !containedMessageIds.includes(s.anchorMessageId));
|
|
54
|
-
}
|
|
55
|
-
const compressSummary = {
|
|
56
|
-
anchorMessageId: startResult.messageId,
|
|
57
|
-
summary: summary,
|
|
58
|
-
};
|
|
59
|
-
state.compressSummaries.push(compressSummary);
|
|
60
|
-
const contentsToTokenize = collectContentInRange(messages, startResult.messageIndex, endResult.messageIndex);
|
|
61
|
-
const estimatedCompressedTokens = estimateTokensBatch(contentsToTokenize);
|
|
62
|
-
state.stats.pruneTokenCounter += estimatedCompressedTokens;
|
|
63
|
-
const currentParams = getCurrentParams(state, messages, logger);
|
|
64
|
-
await sendCompressNotification(client, logger, ctx.config, state, sessionId, containedToolIds, containedMessageIds, topic, summary, startResult, endResult, messages.length, currentParams);
|
|
65
|
-
state.stats.totalPruneTokens += state.stats.pruneTokenCounter;
|
|
66
|
-
state.stats.pruneTokenCounter = 0;
|
|
67
|
-
state.nudgeCounter = 0;
|
|
68
|
-
// logger.info("Compress range created", {
|
|
69
|
-
// startMessageId: startResult.messageId,
|
|
70
|
-
// endMessageId: endResult.messageId,
|
|
71
|
-
// toolIdsRemoved: containedToolIds.length,
|
|
72
|
-
// messagesInRange: containedMessageIds.length,
|
|
73
|
-
// estimatedTokens: estimatedCompressedTokens,
|
|
74
|
-
// })
|
|
75
|
-
saveSessionState(state, logger).catch((err) => logger.error("Failed to persist state", { error: err.message }));
|
|
76
|
-
const messagesCompressed = endResult.messageIndex - startResult.messageIndex + 1;
|
|
77
|
-
return `Compressed ${messagesCompressed} messages (${containedToolIds.length} tool calls) into summary. The content will be replaced with your summary.`;
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=compress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../../../lib/tools/compress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAG1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EACH,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,GAC3B,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,MAAM,yBAAyB,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAA;AAElE,MAAM,UAAU,kBAAkB,CAAC,GAAqB;IACpD,OAAO,IAAI,CAAC;QACR,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE;YACF,KAAK,EAAE,IAAI,CAAC,MAAM;iBACb,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;iBAC3B,MAAM,CAAC,CAAC,CAAC;iBACT,QAAQ,CACL,2RAA2R,CAC9R;SACR;QACD,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO;YACvB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;YACrC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;YAEnC,MAAM,CAAC,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;YAE3D,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,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C,KAAK,CAAC,YAAY,GAAG,CAAC,CAAA;YAEtB,0CAA0C;YAC1C,6CAA6C;YAC7C,yCAAyC;YACzC,+CAA+C;YAC/C,mDAAmD;YACnD,kDAAkD;YAClD,KAAK;YAEL,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAC1C,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAClE,CAAA;YAED,MAAM,kBAAkB,GAAG,SAAS,CAAC,YAAY,GAAG,WAAW,CAAC,YAAY,GAAG,CAAC,CAAA;YAChF,OAAO,cAAc,kBAAkB,cAAc,gBAAgB,CAAC,MAAM,4EAA4E,CAAA;QAC5J,CAAC;KACJ,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"distill.d.ts","sourceRoot":"","sources":["../../../lib/tools/distill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAiDhF"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { tool } from "@opencode-ai/plugin";
|
|
2
|
-
import { executePruneOperation } from "./prune-shared";
|
|
3
|
-
import { loadPrompt } from "../prompts";
|
|
4
|
-
const DISTILL_TOOL_DESCRIPTION = loadPrompt("distill-tool-spec");
|
|
5
|
-
export function createDistillTool(ctx) {
|
|
6
|
-
return tool({
|
|
7
|
-
description: DISTILL_TOOL_DESCRIPTION,
|
|
8
|
-
args: {
|
|
9
|
-
ids: tool.schema
|
|
10
|
-
.array(tool.schema.string())
|
|
11
|
-
.min(1)
|
|
12
|
-
.describe("Numeric IDs as strings to distill from the <prunable-tools> list"),
|
|
13
|
-
distillation: tool.schema
|
|
14
|
-
.array(tool.schema.string())
|
|
15
|
-
.min(1)
|
|
16
|
-
.describe("Required array of distillation strings, one per ID (positional: distillation[0] for ids[0], etc.)"),
|
|
17
|
-
},
|
|
18
|
-
async execute(args, toolCtx) {
|
|
19
|
-
if (!args.distillation || args.distillation.length === 0) {
|
|
20
|
-
ctx.logger.debug("Distill tool called without distillation: " + JSON.stringify(args));
|
|
21
|
-
throw new Error("Missing distillation. You must provide a distillation string for each ID.");
|
|
22
|
-
}
|
|
23
|
-
if (!Array.isArray(args.distillation)) {
|
|
24
|
-
ctx.logger.debug("Distill tool called with non-array distillation: " + JSON.stringify(args));
|
|
25
|
-
throw new Error(`Invalid distillation format: expected an array of strings, got ${typeof args.distillation}. ` +
|
|
26
|
-
`Example: distillation: ["summary for id 0", "summary for id 1"]`);
|
|
27
|
-
}
|
|
28
|
-
// Log the distillation for debugging/analysis
|
|
29
|
-
ctx.logger.info("Distillation data received:");
|
|
30
|
-
ctx.logger.info(JSON.stringify(args.distillation, null, 2));
|
|
31
|
-
return executePruneOperation(ctx, toolCtx, args.ids, "extraction", "Distill", args.distillation);
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=distill.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"distill.js","sourceRoot":"","sources":["../../../lib/tools/distill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,wBAAwB,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAEhE,MAAM,UAAU,iBAAiB,CAAC,GAAqB;IACnD,OAAO,IAAI,CAAC;QACR,WAAW,EAAE,wBAAwB;QACrC,IAAI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S,EACT,IAAI,CAAC,YAAY,CACpB,CAAA;QACL,CAAC;KACJ,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/lib/tools/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { PruneToolContext } from "./types";
|
|
2
|
-
import { PruneReason } from "../ui/notification";
|
|
3
|
-
export declare function executePruneOperation(ctx: PruneToolContext, toolCtx: {
|
|
4
|
-
sessionID: string;
|
|
5
|
-
}, ids: string[], reason: PruneReason, toolName: string, distillation?: string[]): Promise<string>;
|
|
6
|
-
//# sourceMappingURL=prune-shared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prune-shared.d.ts","sourceRoot":"","sources":["../../../lib/tools/prune-shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG/C,OAAO,EAAE,WAAW,EAA2B,MAAM,oBAAoB,CAAA;AAQzE,wBAAsB,qBAAqB,CACvC,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAC9B,GAAG,EAAE,MAAM,EAAE,EACb,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,MAAM,CAAC,CAyIjB"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { buildToolIdList } from "../messages/utils";
|
|
2
|
-
import { syncToolCache } from "../state/tool-cache";
|
|
3
|
-
import { sendUnifiedNotification } from "../ui/notification";
|
|
4
|
-
import { formatPruningResultForTool } from "../ui/utils";
|
|
5
|
-
import { ensureSessionInitialized } from "../state";
|
|
6
|
-
import { saveSessionState } from "../state/persistence";
|
|
7
|
-
import { calculateTokensSaved, getCurrentParams } from "../strategies/utils";
|
|
8
|
-
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns";
|
|
9
|
-
// Shared logic for executing prune operations.
|
|
10
|
-
export async function executePruneOperation(ctx, toolCtx, ids, reason, toolName, distillation) {
|
|
11
|
-
const { client, state, logger, config, workingDirectory } = ctx;
|
|
12
|
-
const sessionId = toolCtx.sessionID;
|
|
13
|
-
logger.info(`${toolName} tool invoked`);
|
|
14
|
-
logger.info(JSON.stringify(reason ? { ids, reason } : { ids }));
|
|
15
|
-
if (!ids || ids.length === 0) {
|
|
16
|
-
logger.debug(`${toolName} tool called but ids is empty or undefined`);
|
|
17
|
-
throw new Error(`No IDs provided. Check the <prunable-tools> list for available IDs to ${toolName.toLowerCase()}.`);
|
|
18
|
-
}
|
|
19
|
-
const numericToolIds = ids
|
|
20
|
-
.map((id) => parseInt(id, 10))
|
|
21
|
-
.filter((n) => !isNaN(n));
|
|
22
|
-
if (numericToolIds.length === 0) {
|
|
23
|
-
logger.debug(`No numeric tool IDs provided for ${toolName}: ` + JSON.stringify(ids));
|
|
24
|
-
throw new Error("No numeric IDs provided. Format: ids: [id1, id2, ...]");
|
|
25
|
-
}
|
|
26
|
-
// Fetch messages to calculate tokens and find current agent
|
|
27
|
-
const messagesResponse = await client.session.messages({
|
|
28
|
-
path: { id: sessionId },
|
|
29
|
-
});
|
|
30
|
-
const messages = messagesResponse.data || messagesResponse;
|
|
31
|
-
await ensureSessionInitialized(ctx.client, state, sessionId, logger, messages);
|
|
32
|
-
await syncToolCache(state, config, logger, messages);
|
|
33
|
-
const currentParams = getCurrentParams(state, messages, logger);
|
|
34
|
-
const toolIdList = buildToolIdList(state, messages, logger);
|
|
35
|
-
const validNumericIds = [];
|
|
36
|
-
const skippedIds = [];
|
|
37
|
-
// Validate and filter IDs
|
|
38
|
-
for (const index of numericToolIds) {
|
|
39
|
-
// Validate that all numeric IDs are within bounds
|
|
40
|
-
if (index < 0 || index >= toolIdList.length) {
|
|
41
|
-
logger.debug(`Rejecting prune request - index out of bounds: ${index}`);
|
|
42
|
-
skippedIds.push(index.toString());
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const id = toolIdList[index];
|
|
46
|
-
const metadata = state.toolParameters.get(id);
|
|
47
|
-
// Validate that all IDs exist in cache and aren't protected
|
|
48
|
-
// (rejects hallucinated IDs and turn-protected tools not shown in <prunable-tools>)
|
|
49
|
-
if (!metadata) {
|
|
50
|
-
logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id });
|
|
51
|
-
skippedIds.push(index.toString());
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const allProtectedTools = config.tools.settings.protectedTools;
|
|
55
|
-
if (allProtectedTools.includes(metadata.tool)) {
|
|
56
|
-
logger.debug("Rejecting prune request - protected tool", {
|
|
57
|
-
index,
|
|
58
|
-
id,
|
|
59
|
-
tool: metadata.tool,
|
|
60
|
-
});
|
|
61
|
-
skippedIds.push(index.toString());
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const filePath = getFilePathFromParameters(metadata.parameters);
|
|
65
|
-
if (isProtectedFilePath(filePath, config.protectedFilePatterns)) {
|
|
66
|
-
logger.debug("Rejecting prune request - protected file path", {
|
|
67
|
-
index,
|
|
68
|
-
id,
|
|
69
|
-
tool: metadata.tool,
|
|
70
|
-
filePath,
|
|
71
|
-
});
|
|
72
|
-
skippedIds.push(index.toString());
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
validNumericIds.push(index);
|
|
76
|
-
}
|
|
77
|
-
if (validNumericIds.length === 0) {
|
|
78
|
-
const errorMsg = skippedIds.length > 0
|
|
79
|
-
? `Invalid IDs provided: [${skippedIds.join(", ")}]. Only use numeric IDs from the <prunable-tools> list.`
|
|
80
|
-
: `No valid IDs provided to ${toolName.toLowerCase()}.`;
|
|
81
|
-
throw new Error(errorMsg);
|
|
82
|
-
}
|
|
83
|
-
const pruneToolIds = validNumericIds.map((index) => toolIdList[index]);
|
|
84
|
-
state.prune.toolIds.push(...pruneToolIds);
|
|
85
|
-
const toolMetadata = new Map();
|
|
86
|
-
for (const id of pruneToolIds) {
|
|
87
|
-
const toolParameters = state.toolParameters.get(id);
|
|
88
|
-
if (toolParameters) {
|
|
89
|
-
toolMetadata.set(id, toolParameters);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
logger.debug("No metadata found for ID", { id });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
state.stats.pruneTokenCounter += calculateTokensSaved(state, messages, pruneToolIds);
|
|
96
|
-
await sendUnifiedNotification(client, logger, config, state, sessionId, pruneToolIds, toolMetadata, reason, currentParams, workingDirectory, distillation);
|
|
97
|
-
state.stats.totalPruneTokens += state.stats.pruneTokenCounter;
|
|
98
|
-
state.stats.pruneTokenCounter = 0;
|
|
99
|
-
state.nudgeCounter = 0;
|
|
100
|
-
saveSessionState(state, logger).catch((err) => logger.error("Failed to persist state", { error: err.message }));
|
|
101
|
-
let result = formatPruningResultForTool(pruneToolIds, toolMetadata, workingDirectory);
|
|
102
|
-
if (skippedIds.length > 0) {
|
|
103
|
-
result += `\n\nNote: ${skippedIds.length} IDs were skipped (invalid, protected, or missing metadata): ${skippedIds.join(", ")}`;
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=prune-shared.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prune-shared.js","sourceRoot":"","sources":["../../../lib/tools/prune-shared.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,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;AACvD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAE3F,+CAA+C;AAC/C,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACvC,GAAqB,EACrB,OAA8B,EAC9B,GAAa,EACb,MAAmB,EACnB,QAAgB,EAChB,YAAuB;IAEvB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAA;IAC/D,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IAEnC,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,eAAe,CAAC,CAAA;IACvC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;IAE/D,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAA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Q,EAAE,YAAY,CAAC,CAAA;IAEpF,MAAM,uBAAuB,CACzB,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,aAAa,EACb,gBAAgB,EAChB,YAAY,CACf,CAAA;IAED,KAAK,CAAC,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAA;IAC7D,KAAK,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAA;IACjC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAA;IAEtB,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAC1C,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAClE,CAAA;IAED,IAAI,MAAM,GAAG,0BAA0B,CAAC,YAAY,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAA;IACrF,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,aAAa,UAAU,CAAC,MAAM,gEAAgE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IACnI,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../../lib/tools/prune.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,wBAAgB,eAAe,CAAC,GAAG,EAAE,gBAAgB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAgB9E"}
|
package/dist/lib/tools/prune.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { tool } from "@opencode-ai/plugin";
|
|
2
|
-
import { executePruneOperation } from "./prune-shared";
|
|
3
|
-
import { loadPrompt } from "../prompts";
|
|
4
|
-
const PRUNE_TOOL_DESCRIPTION = loadPrompt("prune-tool-spec");
|
|
5
|
-
export function createPruneTool(ctx) {
|
|
6
|
-
return tool({
|
|
7
|
-
description: PRUNE_TOOL_DESCRIPTION,
|
|
8
|
-
args: {
|
|
9
|
-
ids: tool.schema
|
|
10
|
-
.array(tool.schema.string())
|
|
11
|
-
.min(1)
|
|
12
|
-
.describe("Numeric IDs as strings from the <prunable-tools> list to prune"),
|
|
13
|
-
},
|
|
14
|
-
async execute(args, toolCtx) {
|
|
15
|
-
const numericIds = args.ids;
|
|
16
|
-
const reason = "noise";
|
|
17
|
-
return executePruneOperation(ctx, toolCtx, numericIds, reason, "Prune");
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=prune.js.map
|