@tuanhung303/opencode-acp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +166 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/commands/budget.d.ts +15 -0
- package/dist/lib/commands/budget.d.ts.map +1 -0
- package/dist/lib/commands/budget.js +120 -0
- package/dist/lib/commands/budget.js.map +1 -0
- package/dist/lib/commands/context.d.ts +49 -0
- package/dist/lib/commands/context.d.ts.map +1 -0
- package/dist/lib/commands/context.js +191 -0
- package/dist/lib/commands/context.js.map +1 -0
- package/dist/lib/commands/help.d.ts +15 -0
- package/dist/lib/commands/help.d.ts.map +1 -0
- package/dist/lib/commands/help.js +28 -0
- package/dist/lib/commands/help.js.map +1 -0
- package/dist/lib/commands/protected.d.ts +17 -0
- package/dist/lib/commands/protected.d.ts.map +1 -0
- package/dist/lib/commands/protected.js +50 -0
- package/dist/lib/commands/protected.js.map +1 -0
- package/dist/lib/commands/stats.d.ts +15 -0
- package/dist/lib/commands/stats.d.ts.map +1 -0
- package/dist/lib/commands/stats.js +64 -0
- package/dist/lib/commands/stats.js.map +1 -0
- package/dist/lib/commands/sweep.d.ts +23 -0
- package/dist/lib/commands/sweep.d.ts.map +1 -0
- package/dist/lib/commands/sweep.js +194 -0
- package/dist/lib/commands/sweep.js.map +1 -0
- package/dist/lib/config-schema.d.ts +119 -0
- package/dist/lib/config-schema.d.ts.map +1 -0
- package/dist/lib/config-schema.js +97 -0
- package/dist/lib/config-schema.js.map +1 -0
- package/dist/lib/config.d.ts +59 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +426 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/hooks.d.ts +31 -0
- package/dist/lib/hooks.d.ts.map +1 -0
- package/dist/lib/hooks.js +230 -0
- package/dist/lib/hooks.js.map +1 -0
- package/dist/lib/logger.d.ts +55 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +230 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/messages/index.d.ts +3 -0
- package/dist/lib/messages/index.d.ts.map +1 -0
- package/dist/lib/messages/index.js +3 -0
- package/dist/lib/messages/index.js.map +1 -0
- package/dist/lib/messages/inject.d.ts +10 -0
- package/dist/lib/messages/inject.d.ts.map +1 -0
- package/dist/lib/messages/inject.js +10 -0
- package/dist/lib/messages/inject.js.map +1 -0
- package/dist/lib/messages/prune.d.ts +13 -0
- package/dist/lib/messages/prune.d.ts.map +1 -0
- package/dist/lib/messages/prune.js +173 -0
- package/dist/lib/messages/prune.js.map +1 -0
- package/dist/lib/messages/utils.d.ts +43 -0
- package/dist/lib/messages/utils.d.ts.map +1 -0
- package/dist/lib/messages/utils.js +262 -0
- package/dist/lib/messages/utils.js.map +1 -0
- 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 +54 -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/extract-tool-spec.js +56 -0
- package/dist/lib/prompts/extract-tool-spec.js.map +1 -0
- package/dist/lib/prompts/index.d.ts +2 -0
- package/dist/lib/prompts/index.d.ts.map +1 -0
- package/dist/lib/prompts/index.js +29 -0
- package/dist/lib/prompts/index.js.map +1 -0
- package/dist/lib/prompts/restore-tool-spec.d.ts +2 -0
- package/dist/lib/prompts/restore-tool-spec.d.ts.map +1 -0
- package/dist/lib/prompts/restore-tool-spec.js +37 -0
- package/dist/lib/prompts/restore-tool-spec.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 +65 -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 +55 -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 +55 -0
- package/dist/lib/prompts/system/extract.js.map +1 -0
- package/dist/lib/protected-file-patterns.d.ts +12 -0
- package/dist/lib/protected-file-patterns.d.ts.map +1 -0
- package/dist/lib/protected-file-patterns.js +69 -0
- package/dist/lib/protected-file-patterns.js.map +1 -0
- package/dist/lib/safe-execute.d.ts +20 -0
- package/dist/lib/safe-execute.d.ts.map +1 -0
- package/dist/lib/safe-execute.js +38 -0
- package/dist/lib/safe-execute.js.map +1 -0
- package/dist/lib/shared-utils.d.ts +4 -0
- package/dist/lib/shared-utils.d.ts.map +1 -0
- package/dist/lib/shared-utils.js +14 -0
- package/dist/lib/shared-utils.js.map +1 -0
- package/dist/lib/state/index.d.ts +4 -0
- package/dist/lib/state/index.d.ts.map +1 -0
- package/dist/lib/state/index.js +4 -0
- package/dist/lib/state/index.js.map +1 -0
- package/dist/lib/state/persistence.d.ts +27 -0
- package/dist/lib/state/persistence.d.ts.map +1 -0
- package/dist/lib/state/persistence.js +165 -0
- package/dist/lib/state/persistence.js.map +1 -0
- package/dist/lib/state/state.d.ts +8 -0
- package/dist/lib/state/state.d.ts.map +1 -0
- package/dist/lib/state/state.js +166 -0
- package/dist/lib/state/state.js.map +1 -0
- package/dist/lib/state/tool-cache.d.ts +15 -0
- package/dist/lib/state/tool-cache.d.ts.map +1 -0
- package/dist/lib/state/tool-cache.js +99 -0
- package/dist/lib/state/tool-cache.js.map +1 -0
- package/dist/lib/state/types.d.ts +83 -0
- package/dist/lib/state/types.d.ts.map +1 -0
- package/dist/lib/state/types.js +2 -0
- package/dist/lib/state/types.js.map +1 -0
- package/dist/lib/state/utils.d.ts +2 -0
- package/dist/lib/state/utils.d.ts.map +1 -0
- package/dist/lib/state/utils.js +10 -0
- package/dist/lib/state/utils.js.map +1 -0
- package/dist/lib/strategies/deduplication.d.ts +11 -0
- package/dist/lib/strategies/deduplication.d.ts.map +1 -0
- package/dist/lib/strategies/deduplication.js +178 -0
- package/dist/lib/strategies/deduplication.js.map +1 -0
- package/dist/lib/strategies/index.d.ts +5 -0
- package/dist/lib/strategies/index.d.ts.map +1 -0
- package/dist/lib/strategies/index.js +5 -0
- package/dist/lib/strategies/index.js.map +1 -0
- package/dist/lib/strategies/purge-errors.d.ts +13 -0
- package/dist/lib/strategies/purge-errors.d.ts.map +1 -0
- package/dist/lib/strategies/purge-errors.js +62 -0
- package/dist/lib/strategies/purge-errors.js.map +1 -0
- package/dist/lib/strategies/supersede-writes.d.ts +13 -0
- package/dist/lib/strategies/supersede-writes.d.ts.map +1 -0
- package/dist/lib/strategies/supersede-writes.js +90 -0
- package/dist/lib/strategies/supersede-writes.js.map +1 -0
- package/dist/lib/strategies/tools.d.ts +15 -0
- package/dist/lib/strategies/tools.d.ts.map +1 -0
- package/dist/lib/strategies/tools.js +288 -0
- package/dist/lib/strategies/tools.js.map +1 -0
- package/dist/lib/strategies/utils.d.ts +11 -0
- package/dist/lib/strategies/utils.d.ts.map +1 -0
- package/dist/lib/strategies/utils.js +75 -0
- package/dist/lib/strategies/utils.js.map +1 -0
- package/dist/lib/ui/notification.d.ts +12 -0
- package/dist/lib/ui/notification.d.ts.map +1 -0
- package/dist/lib/ui/notification.js +81 -0
- package/dist/lib/ui/notification.js.map +1 -0
- package/dist/lib/ui/utils.d.ts +10 -0
- package/dist/lib/ui/utils.d.ts.map +1 -0
- package/dist/lib/ui/utils.js +113 -0
- package/dist/lib/ui/utils.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Tool specs
|
|
2
|
+
import { DISCARD_TOOL_SPEC } from "./discard-tool-spec";
|
|
3
|
+
import { EXTRACT_TOOL_SPEC } from "./extract-tool-spec";
|
|
4
|
+
import { RESTORE_TOOL_SPEC } from "./restore-tool-spec";
|
|
5
|
+
// System prompts
|
|
6
|
+
import { SYSTEM_PROMPT_BOTH } from "./system/both";
|
|
7
|
+
import { SYSTEM_PROMPT_DISCARD } from "./system/discard";
|
|
8
|
+
import { SYSTEM_PROMPT_EXTRACT } from "./system/extract";
|
|
9
|
+
const PROMPTS = {
|
|
10
|
+
"discard-tool-spec": DISCARD_TOOL_SPEC,
|
|
11
|
+
"extract-tool-spec": EXTRACT_TOOL_SPEC,
|
|
12
|
+
"restore-tool-spec": RESTORE_TOOL_SPEC,
|
|
13
|
+
"system/system-prompt-both": SYSTEM_PROMPT_BOTH,
|
|
14
|
+
"system/system-prompt-discard": SYSTEM_PROMPT_DISCARD,
|
|
15
|
+
"system/system-prompt-extract": SYSTEM_PROMPT_EXTRACT,
|
|
16
|
+
};
|
|
17
|
+
export function loadPrompt(name, vars) {
|
|
18
|
+
let content = PROMPTS[name];
|
|
19
|
+
if (!content) {
|
|
20
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
21
|
+
}
|
|
22
|
+
if (vars) {
|
|
23
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
24
|
+
content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/prompts/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,iBAAiB;AACjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,MAAM,OAAO,GAA2B;IACpC,mBAAmB,EAAE,iBAAiB;IACtC,mBAAmB,EAAE,iBAAiB;IACtC,mBAAmB,EAAE,iBAAiB;IACtC,2BAA2B,EAAE,kBAAkB;IAC/C,8BAA8B,EAAE,qBAAqB;IACrD,8BAA8B,EAAE,qBAAqB;CACxD,CAAA;AAED,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAA6B;IAClE,IAAI,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAA;IAChD,CAAC;IACD,IAAI,IAAI,EAAE,CAAC;QACP,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;QAC3E,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const RESTORE_TOOL_SPEC = "Restores previously pruned tool outputs to the conversation context.\n\n## How It Works\n\nWhen tools are discarded or extracted, their original outputs are stored in a soft-prune cache for a limited time. The restore tool allows you to bring back pruned content if you need it again.\n\n## When to Use This Tool\n\nUse `restore` when:\n- You accidentally discarded content you still need\n- You need to reference the full output of a previously pruned tool\n- You want to undo a recent discard operation\n\n## When NOT to Use This Tool\n\n- Content older than the cache window (typically 20 turns) cannot be restored\n- Content that was pruned before the current session started cannot be restored\n\n## Parameters\n\n- `hashes` (required): Array of hash strings from tool outputs (e.g., [\"#r_a1b2c#\", \"#g_d4e5f#\"])\n\n## Example\n\n<example_restore>\nYou previously discarded:\ndiscard({hashes: [\"#r_a1b2c#\"], reason: \"completion\"})\n\nNow you need that content back:\nrestore({hashes: [\"#r_a1b2c#\"]})\n</example_restore>\n\n<example_batch_restore>\nRestore multiple tools at once:\nrestore({hashes: [\"#r_a1b2c#\", \"#g_d4e5f#\", \"#b_12345#\"]})\n</example_batch_restore>";
|
|
2
|
+
//# sourceMappingURL=restore-tool-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore-tool-spec.d.ts","sourceRoot":"","sources":["../../../lib/prompts/restore-tool-spec.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,sqCAmCL,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const RESTORE_TOOL_SPEC = `Restores previously pruned tool outputs to the conversation context.
|
|
2
|
+
|
|
3
|
+
## How It Works
|
|
4
|
+
|
|
5
|
+
When tools are discarded or extracted, their original outputs are stored in a soft-prune cache for a limited time. The restore tool allows you to bring back pruned content if you need it again.
|
|
6
|
+
|
|
7
|
+
## When to Use This Tool
|
|
8
|
+
|
|
9
|
+
Use \`restore\` when:
|
|
10
|
+
- You accidentally discarded content you still need
|
|
11
|
+
- You need to reference the full output of a previously pruned tool
|
|
12
|
+
- You want to undo a recent discard operation
|
|
13
|
+
|
|
14
|
+
## When NOT to Use This Tool
|
|
15
|
+
|
|
16
|
+
- Content older than the cache window (typically 20 turns) cannot be restored
|
|
17
|
+
- Content that was pruned before the current session started cannot be restored
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
- \`hashes\` (required): Array of hash strings from tool outputs (e.g., ["#r_a1b2c#", "#g_d4e5f#"])
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
<example_restore>
|
|
26
|
+
You previously discarded:
|
|
27
|
+
discard({hashes: ["#r_a1b2c#"], reason: "completion"})
|
|
28
|
+
|
|
29
|
+
Now you need that content back:
|
|
30
|
+
restore({hashes: ["#r_a1b2c#"]})
|
|
31
|
+
</example_restore>
|
|
32
|
+
|
|
33
|
+
<example_batch_restore>
|
|
34
|
+
Restore multiple tools at once:
|
|
35
|
+
restore({hashes: ["#r_a1b2c#", "#g_d4e5f#", "#b_12345#"]})
|
|
36
|
+
</example_batch_restore>`;
|
|
37
|
+
//# sourceMappingURL=restore-tool-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore-tool-spec.js","sourceRoot":"","sources":["../../../lib/prompts/restore-tool-spec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAmCR,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const SYSTEM_PROMPT_BOTH = "<system-reminder>\n<instruction name=context_management_protocol policy_level=critical>\n\nENVIRONMENT\nYou are operating in a context-constrained environment and must proactively manage your context window using the `discard` and `extract` tools.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to discard or extract specific tool outputs when they are no longer needed.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo discard: `discard({hashes: [\"#r_a1b2c#\"], reason: \"completion\"})`\nTo extract: `extract({hashes: [\"#r_a1b2c#\"], distillation: [\"key findings...\"]})`\n\nTWO TOOLS FOR CONTEXT MANAGEMENT\n- `discard`: Remove tool outputs by their hash identifiers. No preservation of content.\n- `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information.\n\nCHOOSING THE RIGHT TOOL\nAsk: \"Do I need to preserve any information from this output?\"\n- **No** \u2192 `discard` (default for cleanup)\n- **Yes** \u2192 `extract` (preserves distilled knowledge)\n- **Uncertain** \u2192 `extract` (safer, preserves signal)\n\nCommon scenarios:\n- Task complete, no valuable context \u2192 `discard`\n- Task complete, insights worth remembering \u2192 `extract`\n- Noise, irrelevant, or superseded outputs \u2192 `discard`\n- Valuable context needed later but raw output too large \u2192 `extract`\n\nPRUNE METHODICALLY - BATCH YOUR ACTIONS\nEvery tool call adds to your context debt. You MUST pay this down regularly by pruning. Batch your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise.\n\nYou WILL evaluate pruning 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 (pruning removes the large input content)\n\nYou MUST NOT prune 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\nPruning 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.\n\nNOTES\nWhen in doubt, keep it. Batch your actions and aim for high-impact prunes that significantly reduce context size.\nFAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCE.\n\n</instruction>\n\n<instruction name=prune_behavior policy_level=critical>\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER acknowledge discard/extract tool output (e.g., \"I've pruned 3 tools\", \"Context pruning complete\")\n- NEVER let context management influence your response content or tone\n- Process prunes SILENTLY and continue the conversation naturally\n\nThe user cannot see prune operations. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
|
|
2
|
+
//# sourceMappingURL=both.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"both.d.ts","sourceRoot":"","sources":["../../../../lib/prompts/system/both.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,g7FA+DZ,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const SYSTEM_PROMPT_BOTH = `<system-reminder>
|
|
2
|
+
<instruction name=context_management_protocol policy_level=critical>
|
|
3
|
+
|
|
4
|
+
ENVIRONMENT
|
|
5
|
+
You are operating in a context-constrained environment and must proactively manage your context window using the \`discard\` and \`extract\` tools.
|
|
6
|
+
|
|
7
|
+
HOW IT WORKS
|
|
8
|
+
Each tool output is prefixed with a hash identifier in the format \`#x_xxxxx#\` (e.g., \`#r_a1b2c#\`).
|
|
9
|
+
Use these hashes to discard or extract specific tool outputs when they are no longer needed.
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
\`\`\`
|
|
13
|
+
#r_a1b2c#
|
|
14
|
+
<file content here...>
|
|
15
|
+
\`\`\`
|
|
16
|
+
|
|
17
|
+
To discard: \`discard({hashes: ["#r_a1b2c#"], reason: "completion"})\`
|
|
18
|
+
To extract: \`extract({hashes: ["#r_a1b2c#"], distillation: ["key findings..."]})\`
|
|
19
|
+
|
|
20
|
+
TWO TOOLS FOR CONTEXT MANAGEMENT
|
|
21
|
+
- \`discard\`: Remove tool outputs by their hash identifiers. No preservation of content.
|
|
22
|
+
- \`extract\`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information.
|
|
23
|
+
|
|
24
|
+
CHOOSING THE RIGHT TOOL
|
|
25
|
+
Ask: "Do I need to preserve any information from this output?"
|
|
26
|
+
- **No** → \`discard\` (default for cleanup)
|
|
27
|
+
- **Yes** → \`extract\` (preserves distilled knowledge)
|
|
28
|
+
- **Uncertain** → \`extract\` (safer, preserves signal)
|
|
29
|
+
|
|
30
|
+
Common scenarios:
|
|
31
|
+
- Task complete, no valuable context → \`discard\`
|
|
32
|
+
- Task complete, insights worth remembering → \`extract\`
|
|
33
|
+
- Noise, irrelevant, or superseded outputs → \`discard\`
|
|
34
|
+
- Valuable context needed later but raw output too large → \`extract\`
|
|
35
|
+
|
|
36
|
+
PRUNE METHODICALLY - BATCH YOUR ACTIONS
|
|
37
|
+
Every tool call adds to your context debt. You MUST pay this down regularly by pruning. Batch your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise.
|
|
38
|
+
|
|
39
|
+
You WILL evaluate pruning when ANY of these are true:
|
|
40
|
+
- Task or sub-task is complete
|
|
41
|
+
- You are about to start a new phase of work
|
|
42
|
+
- Write or edit operations are complete (pruning removes the large input content)
|
|
43
|
+
|
|
44
|
+
You MUST NOT prune when:
|
|
45
|
+
- The tool output will be needed for upcoming implementation work
|
|
46
|
+
- The output contains files or context you'll need to reference when making edits
|
|
47
|
+
|
|
48
|
+
Pruning that forces you to re-call the same tool later is a net loss. Only prune when you're confident the information won't be needed again.
|
|
49
|
+
|
|
50
|
+
NOTES
|
|
51
|
+
When in doubt, keep it. Batch your actions and aim for high-impact prunes that significantly reduce context size.
|
|
52
|
+
FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCE.
|
|
53
|
+
|
|
54
|
+
</instruction>
|
|
55
|
+
|
|
56
|
+
<instruction name=prune_behavior policy_level=critical>
|
|
57
|
+
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
|
|
58
|
+
- NEVER acknowledge discard/extract tool output (e.g., "I've pruned 3 tools", "Context pruning complete")
|
|
59
|
+
- NEVER let context management influence your response content or tone
|
|
60
|
+
- Process prunes SILENTLY and continue the conversation naturally
|
|
61
|
+
|
|
62
|
+
The user cannot see prune operations. Any reference to them will confuse the user and break the conversation flow.
|
|
63
|
+
</instruction>
|
|
64
|
+
</system-reminder>`;
|
|
65
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA+Df,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 must proactively manage your context window using the `discard` tool.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to discard specific tool outputs when they are no longer needed.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo discard: `discard({hashes: [\"#r_a1b2c#\"], reason: \"completion\"})`\n\nCONTEXT MANAGEMENT TOOL\n- `discard`: Remove tool outputs by their hash identifiers. Provide hashes and a reason.\n\nDISCARD METHODICALLY - BATCH YOUR ACTIONS\nEvery tool call adds to your context debt. You MUST pay this down regularly by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise.\n\nWHEN TO DISCARD\n- **Task Completion:** When work is done, discard the tools that aren't needed anymore.\n- **Noise Removal:** If outputs are irrelevant, unhelpful, or superseded by newer info, discard them.\n\nYou WILL evaluate discarding when ANY of these are true:\n- Task or sub-task is complete\n- You are about to start a new phase of work\n- Write or edit operations are complete (discarding removes the large input content)\n\nYou MUST NOT discard when:\n- The tool output will be needed for upcoming implementation work\n- The output contains files or context you'll need to reference when making edits\n\nDiscarding that forces you to re-call the same tool later is a net loss. Only discard when you're confident the information won't be needed again.\n\nNOTES\nWhen in doubt, keep it. Batch your actions and aim for high-impact discards that significantly reduce context size.\nFAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCE.\n\n</instruction>\n\n<instruction name=discard_behavior policy_level=critical>\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER acknowledge discard tool output (e.g., \"I've discarded 3 tools\", \"Context cleanup complete\")\n- NEVER let context management influence your response content or tone\n- Process discards SILENTLY and continue the conversation naturally\n\nThe user cannot see discard operations. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
|
|
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,04EAqDf,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export const SYSTEM_PROMPT_DISCARD = `<system-reminder>
|
|
2
|
+
<instruction name=context_management_protocol policy_level=critical>
|
|
3
|
+
|
|
4
|
+
ENVIRONMENT
|
|
5
|
+
You are operating in a context-constrained environment and must proactively manage your context window using the \`discard\` tool.
|
|
6
|
+
|
|
7
|
+
HOW IT WORKS
|
|
8
|
+
Each tool output is prefixed with a hash identifier in the format \`#x_xxxxx#\` (e.g., \`#r_a1b2c#\`).
|
|
9
|
+
Use these hashes to discard specific tool outputs when they are no longer needed.
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
\`\`\`
|
|
13
|
+
#r_a1b2c#
|
|
14
|
+
<file content here...>
|
|
15
|
+
\`\`\`
|
|
16
|
+
|
|
17
|
+
To discard: \`discard({hashes: ["#r_a1b2c#"], reason: "completion"})\`
|
|
18
|
+
|
|
19
|
+
CONTEXT MANAGEMENT TOOL
|
|
20
|
+
- \`discard\`: Remove tool outputs by their hash identifiers. Provide hashes and a reason.
|
|
21
|
+
|
|
22
|
+
DISCARD METHODICALLY - BATCH YOUR ACTIONS
|
|
23
|
+
Every tool call adds to your context debt. You MUST pay this down regularly by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise.
|
|
24
|
+
|
|
25
|
+
WHEN TO DISCARD
|
|
26
|
+
- **Task Completion:** When work is done, discard the tools that aren't needed anymore.
|
|
27
|
+
- **Noise Removal:** If outputs are irrelevant, unhelpful, or superseded by newer info, discard them.
|
|
28
|
+
|
|
29
|
+
You WILL evaluate discarding when ANY of these are true:
|
|
30
|
+
- Task or sub-task is complete
|
|
31
|
+
- You are about to start a new phase of work
|
|
32
|
+
- Write or edit operations are complete (discarding removes the large input content)
|
|
33
|
+
|
|
34
|
+
You MUST NOT discard when:
|
|
35
|
+
- The tool output will be needed for upcoming implementation work
|
|
36
|
+
- The output contains files or context you'll need to reference when making edits
|
|
37
|
+
|
|
38
|
+
Discarding that forces you to re-call the same tool later is a net loss. Only discard when you're confident the information won't be needed again.
|
|
39
|
+
|
|
40
|
+
NOTES
|
|
41
|
+
When in doubt, keep it. Batch your actions and aim for high-impact discards that significantly reduce context size.
|
|
42
|
+
FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCE.
|
|
43
|
+
|
|
44
|
+
</instruction>
|
|
45
|
+
|
|
46
|
+
<instruction name=discard_behavior policy_level=critical>
|
|
47
|
+
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
|
|
48
|
+
- NEVER acknowledge discard tool output (e.g., "I've discarded 3 tools", "Context cleanup complete")
|
|
49
|
+
- NEVER let context management influence your response content or tone
|
|
50
|
+
- Process discards SILENTLY and continue the conversation naturally
|
|
51
|
+
|
|
52
|
+
The user cannot see discard operations. Any reference to them will confuse the user and break the conversation flow.
|
|
53
|
+
</instruction>
|
|
54
|
+
</system-reminder>`;
|
|
55
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAqDlB,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 must proactively manage your context window using the `extract` tool.\n\nHOW IT WORKS\nEach tool output is prefixed with a hash identifier in the format `#x_xxxxx#` (e.g., `#r_a1b2c#`).\nUse these hashes to extract and distill specific tool outputs.\n\nExample:\n```\n#r_a1b2c#\n<file content here...>\n```\n\nTo extract: `extract({hashes: [\"#r_a1b2c#\"], distillation: [\"key findings...\"]})`\n\nCONTEXT MANAGEMENT TOOL\n- `extract`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size.\n\nEXTRACT METHODICALLY - BATCH YOUR ACTIONS\nEvery tool call adds to your context debt. You MUST pay this down regularly by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output.\n\nWHEN TO EXTRACT\n- **Task Completion:** When work is done, extract key findings from the tools used. Scale distillation depth to the value of the content.\n- **Knowledge Preservation:** When you have valuable context you want to preserve but need to reduce size, use high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed.\n\nYou WILL evaluate extracting when ANY of these are true:\n- Task or sub-task is complete\n- You are about to start a new phase of work\n- Write or edit operations are complete (extracting removes the large input content)\n\nYou MUST NOT extract when:\n- The tool output will be needed for upcoming implementation work\n- The output contains files or context you'll need to reference when making edits\n\nExtracting that forces you to re-call the same tool later is a net loss. Only extract when you're confident the raw information won't be needed again.\n\nNOTES\nWhen in doubt, keep it. Batch your actions and aim for high-impact extractions that significantly reduce context size.\nFAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCE.\n\n</instruction>\n\n<instruction name=extract_behavior policy_level=critical>\nCRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:\n- NEVER acknowledge extract tool output (e.g., \"I've extracted 3 tools\", \"Context cleanup complete\")\n- NEVER let context management influence your response content or tone\n- Process extractions SILENTLY and continue the conversation naturally\n\nThe user cannot see extract operations. Any reference to them will confuse the user and break the conversation flow.\n</instruction>\n</system-reminder>";
|
|
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,usFAqDf,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export const SYSTEM_PROMPT_EXTRACT = `<system-reminder>
|
|
2
|
+
<instruction name=context_management_protocol policy_level=critical>
|
|
3
|
+
|
|
4
|
+
ENVIRONMENT
|
|
5
|
+
You are operating in a context-constrained environment and must proactively manage your context window using the \`extract\` tool.
|
|
6
|
+
|
|
7
|
+
HOW IT WORKS
|
|
8
|
+
Each tool output is prefixed with a hash identifier in the format \`#x_xxxxx#\` (e.g., \`#r_a1b2c#\`).
|
|
9
|
+
Use these hashes to extract and distill specific tool outputs.
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
\`\`\`
|
|
13
|
+
#r_a1b2c#
|
|
14
|
+
<file content here...>
|
|
15
|
+
\`\`\`
|
|
16
|
+
|
|
17
|
+
To extract: \`extract({hashes: ["#r_a1b2c#"], distillation: ["key findings..."]})\`
|
|
18
|
+
|
|
19
|
+
CONTEXT MANAGEMENT TOOL
|
|
20
|
+
- \`extract\`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size.
|
|
21
|
+
|
|
22
|
+
EXTRACT METHODICALLY - BATCH YOUR ACTIONS
|
|
23
|
+
Every tool call adds to your context debt. You MUST pay this down regularly by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output.
|
|
24
|
+
|
|
25
|
+
WHEN TO EXTRACT
|
|
26
|
+
- **Task Completion:** When work is done, extract key findings from the tools used. Scale distillation depth to the value of the content.
|
|
27
|
+
- **Knowledge Preservation:** When you have valuable context you want to preserve but need to reduce size, use high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed.
|
|
28
|
+
|
|
29
|
+
You WILL evaluate extracting when ANY of these are true:
|
|
30
|
+
- Task or sub-task is complete
|
|
31
|
+
- You are about to start a new phase of work
|
|
32
|
+
- Write or edit operations are complete (extracting removes the large input content)
|
|
33
|
+
|
|
34
|
+
You MUST NOT extract when:
|
|
35
|
+
- The tool output will be needed for upcoming implementation work
|
|
36
|
+
- The output contains files or context you'll need to reference when making edits
|
|
37
|
+
|
|
38
|
+
Extracting that forces you to re-call the same tool later is a net loss. Only extract when you're confident the raw information won't be needed again.
|
|
39
|
+
|
|
40
|
+
NOTES
|
|
41
|
+
When in doubt, keep it. Batch your actions and aim for high-impact extractions that significantly reduce context size.
|
|
42
|
+
FAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCE.
|
|
43
|
+
|
|
44
|
+
</instruction>
|
|
45
|
+
|
|
46
|
+
<instruction name=extract_behavior policy_level=critical>
|
|
47
|
+
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
|
|
48
|
+
- NEVER acknowledge extract tool output (e.g., "I've extracted 3 tools", "Context cleanup complete")
|
|
49
|
+
- NEVER let context management influence your response content or tone
|
|
50
|
+
- Process extractions SILENTLY and continue the conversation naturally
|
|
51
|
+
|
|
52
|
+
The user cannot see extract operations. Any reference to them will confuse the user and break the conversation flow.
|
|
53
|
+
</instruction>
|
|
54
|
+
</system-reminder>`;
|
|
55
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAqDlB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic glob matching with support for `**`, `*`, and `?`.
|
|
3
|
+
*
|
|
4
|
+
* Notes:
|
|
5
|
+
* - Matching is performed against the full (normalized) string.
|
|
6
|
+
* - `*` and `?` do not match `/`.
|
|
7
|
+
* - `**` matches across `/`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchesGlob(inputPath: string, pattern: string): boolean;
|
|
10
|
+
export declare function getFilePathFromParameters(parameters: unknown): string | undefined;
|
|
11
|
+
export declare function isProtectedFilePath(filePath: string | undefined, patterns: string[]): boolean;
|
|
12
|
+
//# sourceMappingURL=protected-file-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-file-patterns.d.ts","sourceRoot":"","sources":["../../lib/protected-file-patterns.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAiDvE;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOjF;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAK7F"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function normalizePath(input) {
|
|
2
|
+
return input.replaceAll("\\\\", "/");
|
|
3
|
+
}
|
|
4
|
+
function escapeRegExpChar(ch) {
|
|
5
|
+
return /[\\.^$+{}()|\[\]]/.test(ch) ? `\\${ch}` : ch;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Basic glob matching with support for `**`, `*`, and `?`.
|
|
9
|
+
*
|
|
10
|
+
* Notes:
|
|
11
|
+
* - Matching is performed against the full (normalized) string.
|
|
12
|
+
* - `*` and `?` do not match `/`.
|
|
13
|
+
* - `**` matches across `/`.
|
|
14
|
+
*/
|
|
15
|
+
export function matchesGlob(inputPath, pattern) {
|
|
16
|
+
if (!pattern)
|
|
17
|
+
return false;
|
|
18
|
+
const input = normalizePath(inputPath);
|
|
19
|
+
const pat = normalizePath(pattern);
|
|
20
|
+
let regex = "^";
|
|
21
|
+
for (let i = 0; i < pat.length; i++) {
|
|
22
|
+
const ch = pat[i];
|
|
23
|
+
if (ch === "*") {
|
|
24
|
+
const next = pat[i + 1];
|
|
25
|
+
if (next === "*") {
|
|
26
|
+
const after = pat[i + 2];
|
|
27
|
+
if (after === "/") {
|
|
28
|
+
// **/ (zero or more directories)
|
|
29
|
+
regex += "(?:.*/)?";
|
|
30
|
+
i += 2;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
// **
|
|
34
|
+
regex += ".*";
|
|
35
|
+
i++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
// *
|
|
39
|
+
regex += "[^/]*";
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (ch === "?") {
|
|
43
|
+
regex += "[^/]";
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (ch === "/") {
|
|
47
|
+
regex += "/";
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
regex += escapeRegExpChar(ch ?? "");
|
|
51
|
+
}
|
|
52
|
+
regex += "$";
|
|
53
|
+
return new RegExp(regex).test(input);
|
|
54
|
+
}
|
|
55
|
+
export function getFilePathFromParameters(parameters) {
|
|
56
|
+
if (typeof parameters !== "object" || parameters === null) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const filePath = parameters.filePath;
|
|
60
|
+
return typeof filePath === "string" && filePath.length > 0 ? filePath : undefined;
|
|
61
|
+
}
|
|
62
|
+
export function isProtectedFilePath(filePath, patterns) {
|
|
63
|
+
if (!filePath)
|
|
64
|
+
return false;
|
|
65
|
+
if (!patterns || patterns.length === 0)
|
|
66
|
+
return false;
|
|
67
|
+
return patterns.some((pattern) => matchesGlob(filePath, pattern));
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=protected-file-patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-file-patterns.js","sourceRoot":"","sources":["../../lib/protected-file-patterns.ts"],"names":[],"mappings":"AAAA,SAAS,aAAa,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CAAC,EAAU;IAChC,OAAO,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,OAAe;IAC1D,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAE1B,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;IACtC,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IAElC,IAAI,KAAK,GAAG,GAAG,CAAA;IAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAEjB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;YACvB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACf,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;gBACxB,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;oBAChB,kCAAkC;oBAClC,KAAK,IAAI,UAAU,CAAA;oBACnB,CAAC,IAAI,CAAC,CAAA;oBACN,SAAQ;gBACZ,CAAC;gBAED,KAAK;gBACL,KAAK,IAAI,IAAI,CAAA;gBACb,CAAC,EAAE,CAAA;gBACH,SAAQ;YACZ,CAAC;YAED,IAAI;YACJ,KAAK,IAAI,OAAO,CAAA;YAChB,SAAQ;QACZ,CAAC;QAED,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,KAAK,IAAI,MAAM,CAAA;YACf,SAAQ;QACZ,CAAC;QAED,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,KAAK,IAAI,GAAG,CAAA;YACZ,SAAQ;QACZ,CAAC;QAED,KAAK,IAAI,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACvC,CAAC;IAED,KAAK,IAAI,GAAG,CAAA;IAEZ,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,UAAmB;IACzD,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxD,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,MAAM,QAAQ,GAAI,UAAsC,CAAC,QAAQ,CAAA;IACjE,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAA;AACrF,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAA4B,EAAE,QAAkB;IAChF,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3B,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Logger } from "./logger";
|
|
2
|
+
/**
|
|
3
|
+
* Safely execute a function with error boundary.
|
|
4
|
+
* If the function throws, logs the error and returns without crashing.
|
|
5
|
+
*
|
|
6
|
+
* @param fn - The function to execute
|
|
7
|
+
* @param logger - Logger instance for error reporting
|
|
8
|
+
* @param context - Description of what's being executed (for error messages)
|
|
9
|
+
*/
|
|
10
|
+
export declare function safeExecute(fn: () => void, logger: Logger, context: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Safely execute an async function with error boundary.
|
|
13
|
+
* If the function throws, logs the error and returns without crashing.
|
|
14
|
+
*
|
|
15
|
+
* @param fn - The async function to execute
|
|
16
|
+
* @param logger - Logger instance for error reporting
|
|
17
|
+
* @param context - Description of what's being executed (for error messages)
|
|
18
|
+
*/
|
|
19
|
+
export declare function safeExecuteAsync<T>(fn: () => Promise<T>, logger: Logger, context: string): Promise<T | undefined>;
|
|
20
|
+
//# sourceMappingURL=safe-execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-execute.d.ts","sourceRoot":"","sources":["../../lib/safe-execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAQjF;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACpC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CASxB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely execute a function with error boundary.
|
|
3
|
+
* If the function throws, logs the error and returns without crashing.
|
|
4
|
+
*
|
|
5
|
+
* @param fn - The function to execute
|
|
6
|
+
* @param logger - Logger instance for error reporting
|
|
7
|
+
* @param context - Description of what's being executed (for error messages)
|
|
8
|
+
*/
|
|
9
|
+
export function safeExecute(fn, logger, context) {
|
|
10
|
+
try {
|
|
11
|
+
fn();
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
15
|
+
const stack = error instanceof Error ? error.stack : undefined;
|
|
16
|
+
logger.warn(`Strategy error in ${context}: ${message}`, { stack });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Safely execute an async function with error boundary.
|
|
21
|
+
* If the function throws, logs the error and returns without crashing.
|
|
22
|
+
*
|
|
23
|
+
* @param fn - The async function to execute
|
|
24
|
+
* @param logger - Logger instance for error reporting
|
|
25
|
+
* @param context - Description of what's being executed (for error messages)
|
|
26
|
+
*/
|
|
27
|
+
export async function safeExecuteAsync(fn, logger, context) {
|
|
28
|
+
try {
|
|
29
|
+
return await fn();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
33
|
+
const stack = error instanceof Error ? error.stack : undefined;
|
|
34
|
+
logger.warn(`Strategy error in ${context}: ${message}`, { stack });
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=safe-execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-execute.js","sourceRoot":"","sources":["../../lib/safe-execute.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,EAAc,EAAE,MAAc,EAAE,OAAe;IACvE,IAAI,CAAC;QACD,EAAE,EAAE,CAAA;IACR,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACtE,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAC9D,MAAM,CAAC,IAAI,CAAC,qBAAqB,OAAO,KAAK,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACtE,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAClC,EAAoB,EACpB,MAAc,EACd,OAAe;IAEf,IAAI,CAAC;QACD,OAAO,MAAM,EAAE,EAAE,CAAA;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACtE,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAC9D,MAAM,CAAC,IAAI,CAAC,qBAAqB,OAAO,KAAK,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAClE,OAAO,SAAS,CAAA;IACpB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SessionState, WithParts } from "./state";
|
|
2
|
+
export declare const isMessageCompacted: (state: SessionState, msg: WithParts) => boolean;
|
|
3
|
+
export declare const getLastUserMessage: (messages: WithParts[]) => WithParts | null;
|
|
4
|
+
//# sourceMappingURL=shared-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-utils.d.ts","sourceRoot":"","sources":["../../lib/shared-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGjD,eAAO,MAAM,kBAAkB,GAAI,OAAO,YAAY,EAAE,KAAK,SAAS,KAAG,OAExE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,UAAU,SAAS,EAAE,KAAG,SAAS,GAAG,IAQtE,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isIgnoredUserMessage } from "./messages/utils";
|
|
2
|
+
export const isMessageCompacted = (state, msg) => {
|
|
3
|
+
return msg.info.time.created < state.lastCompaction;
|
|
4
|
+
};
|
|
5
|
+
export const getLastUserMessage = (messages) => {
|
|
6
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
7
|
+
const msg = messages[i];
|
|
8
|
+
if (msg && msg.info.role === "user" && !isIgnoredUserMessage(msg)) {
|
|
9
|
+
return msg;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=shared-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-utils.js","sourceRoot":"","sources":["../../lib/shared-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAEvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAmB,EAAE,GAAc,EAAW,EAAE;IAC/E,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,cAAc,CAAA;AACvD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAqB,EAAoB,EAAE;IAC1E,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QACvB,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC;YAChE,OAAO,GAAG,CAAA;QACd,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State persistence module for ACP plugin.
|
|
3
|
+
* Persists pruned tool IDs across sessions so they survive OpenCode restarts.
|
|
4
|
+
* Storage location: ~/.local/share/opencode/storage/plugin/acp/{sessionId}.json
|
|
5
|
+
*
|
|
6
|
+
* Uses atomic writes (temp file + rename) to prevent data corruption.
|
|
7
|
+
*/
|
|
8
|
+
import type { SessionState, SessionStats, Prune, DiscardStats } from "./types";
|
|
9
|
+
import type { Logger } from "../logger";
|
|
10
|
+
export interface PersistedSessionState {
|
|
11
|
+
sessionName?: string;
|
|
12
|
+
prune: Prune;
|
|
13
|
+
stats: SessionStats;
|
|
14
|
+
lastUpdated: string;
|
|
15
|
+
hashToCallId?: Record<string, string>;
|
|
16
|
+
callIdToHash?: Record<string, string>;
|
|
17
|
+
discardHistory?: DiscardStats[];
|
|
18
|
+
}
|
|
19
|
+
export declare function saveSessionState(sessionState: SessionState, logger: Logger, sessionName?: string): Promise<void>;
|
|
20
|
+
export declare function loadSessionState(sessionId: string, logger: Logger): Promise<PersistedSessionState | null>;
|
|
21
|
+
export interface AggregatedStats {
|
|
22
|
+
totalTokens: number;
|
|
23
|
+
totalTools: number;
|
|
24
|
+
sessionCount: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function loadAllSessionStats(logger: Logger): Promise<AggregatedStats>;
|
|
27
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../lib/state/persistence.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,WAAW,qBAAqB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,YAAY,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IAEnB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,cAAc,CAAC,EAAE,YAAY,EAAE,CAAA;CAClC;AAmED,wBAAsB,gBAAgB,CAClC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CAqCf;AAED,wBAAsB,gBAAgB,CAClC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CA8BvC;AAED,MAAM,WAAW,eAAe;IAC5B,WAAW,EAAE,MAAM,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"}
|