@tarquinen/opencode-dcp 1.1.0-beta.1 → 1.1.0-beta.3
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 +64 -64
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +17 -23
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +316 -274
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +3 -0
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/logger.d.ts +17 -0
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +90 -7
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/messages/prune.d.ts.map +1 -1
- package/dist/lib/messages/prune.js +85 -41
- package/dist/lib/messages/prune.js.map +1 -1
- package/dist/lib/messages/utils.js +7 -7
- package/dist/lib/model-selector.d.ts +3 -3
- package/dist/lib/model-selector.d.ts.map +1 -1
- package/dist/lib/model-selector.js +34 -34
- package/dist/lib/model-selector.js.map +1 -1
- package/dist/lib/prompt.d.ts.map +1 -1
- package/dist/lib/prompt.js +36 -24
- package/dist/lib/prompt.js.map +1 -1
- package/dist/lib/prompts/discard-tool-spec.txt +1 -1
- package/dist/lib/prompts/extract-tool-spec.txt +1 -1
- package/dist/lib/prompts/nudge/nudge-both.txt +5 -5
- package/dist/lib/prompts/nudge/nudge-discard.txt +4 -4
- package/dist/lib/prompts/nudge/nudge-extract.txt +4 -4
- package/dist/lib/prompts/system/system-prompt-both.txt +1 -16
- package/dist/lib/prompts/system/system-prompt-discard.txt +1 -16
- package/dist/lib/prompts/system/system-prompt-extract.txt +1 -16
- package/dist/lib/shared-utils.d.ts +1 -0
- package/dist/lib/shared-utils.d.ts.map +1 -1
- package/dist/lib/shared-utils.js +10 -1
- package/dist/lib/shared-utils.js.map +1 -1
- package/dist/lib/state/persistence.d.ts.map +1 -1
- package/dist/lib/state/persistence.js +4 -7
- package/dist/lib/state/persistence.js.map +1 -1
- package/dist/lib/state/state.d.ts.map +1 -1
- package/dist/lib/state/state.js +9 -5
- 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 +7 -13
- package/dist/lib/state/tool-cache.js.map +1 -1
- package/dist/lib/state/types.d.ts +1 -0
- package/dist/lib/state/types.d.ts.map +1 -1
- package/dist/lib/strategies/deduplication.js +3 -3
- package/dist/lib/strategies/deduplication.js.map +1 -1
- package/dist/lib/strategies/on-idle.d.ts.map +1 -1
- package/dist/lib/strategies/on-idle.js +24 -24
- package/dist/lib/strategies/on-idle.js.map +1 -1
- package/dist/lib/strategies/supersede-writes.js +4 -4
- package/dist/lib/strategies/supersede-writes.js.map +1 -1
- package/dist/lib/strategies/tools.d.ts.map +1 -1
- package/dist/lib/strategies/tools.js +23 -17
- package/dist/lib/strategies/tools.js.map +1 -1
- package/dist/lib/strategies/utils.d.ts.map +1 -1
- package/dist/lib/strategies/utils.js +20 -9
- package/dist/lib/strategies/utils.js.map +1 -1
- package/dist/lib/ui/notification.d.ts.map +1 -1
- package/dist/lib/ui/notification.js +26 -23
- package/dist/lib/ui/notification.js.map +1 -1
- package/dist/lib/ui/utils.d.ts.map +1 -1
- package/dist/lib/ui/utils.js +9 -9
- package/dist/lib/ui/utils.js.map +1 -1
- package/package.json +61 -58
|
@@ -4,7 +4,7 @@ import { isMessageCompacted } from "../shared-utils";
|
|
|
4
4
|
*/
|
|
5
5
|
export const extractParameterKey = (tool, parameters) => {
|
|
6
6
|
if (!parameters)
|
|
7
|
-
return
|
|
7
|
+
return "";
|
|
8
8
|
if (tool === "read" && parameters.filePath) {
|
|
9
9
|
return parameters.filePath;
|
|
10
10
|
}
|
|
@@ -15,21 +15,21 @@ export const extractParameterKey = (tool, parameters) => {
|
|
|
15
15
|
return parameters.filePath;
|
|
16
16
|
}
|
|
17
17
|
if (tool === "list") {
|
|
18
|
-
return parameters.path ||
|
|
18
|
+
return parameters.path || "(current directory)";
|
|
19
19
|
}
|
|
20
20
|
if (tool === "glob") {
|
|
21
21
|
if (parameters.pattern) {
|
|
22
22
|
const pathInfo = parameters.path ? ` in ${parameters.path}` : "";
|
|
23
23
|
return `"${parameters.pattern}"${pathInfo}`;
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return "(unknown pattern)";
|
|
26
26
|
}
|
|
27
27
|
if (tool === "grep") {
|
|
28
28
|
if (parameters.pattern) {
|
|
29
29
|
const pathInfo = parameters.path ? ` in ${parameters.path}` : "";
|
|
30
30
|
return `"${parameters.pattern}"${pathInfo}`;
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return "(unknown pattern)";
|
|
33
33
|
}
|
|
34
34
|
if (tool === "bash") {
|
|
35
35
|
if (parameters.description)
|
|
@@ -59,8 +59,8 @@ export const extractParameterKey = (tool, parameters) => {
|
|
|
59
59
|
return parameters.description;
|
|
60
60
|
}
|
|
61
61
|
const paramStr = JSON.stringify(parameters);
|
|
62
|
-
if (paramStr ===
|
|
63
|
-
return
|
|
62
|
+
if (paramStr === "{}" || paramStr === "[]" || paramStr === "null") {
|
|
63
|
+
return "";
|
|
64
64
|
}
|
|
65
65
|
return paramStr.substring(0, 50);
|
|
66
66
|
};
|
|
@@ -72,7 +72,7 @@ export function buildToolIdList(state, messages, logger) {
|
|
|
72
72
|
}
|
|
73
73
|
if (msg.parts) {
|
|
74
74
|
for (const part of msg.parts) {
|
|
75
|
-
if (part.type ===
|
|
75
|
+
if (part.type === "tool" && part.callID && part.tool) {
|
|
76
76
|
toolIds.push(part.callID);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LanguageModel } from
|
|
2
|
-
import type { Logger } from
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
import type { Logger } from "./logger";
|
|
3
3
|
export interface ModelInfo {
|
|
4
4
|
providerID: string;
|
|
5
5
|
modelID: string;
|
|
@@ -8,7 +8,7 @@ export declare const FALLBACK_MODELS: Record<string, string>;
|
|
|
8
8
|
export interface ModelSelectionResult {
|
|
9
9
|
model: LanguageModel;
|
|
10
10
|
modelInfo: ModelInfo;
|
|
11
|
-
source:
|
|
11
|
+
source: "user-model" | "config" | "fallback";
|
|
12
12
|
reason?: string;
|
|
13
13
|
failedModel?: ModelInfo;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-selector.d.ts","sourceRoot":"","sources":["../../lib/model-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"model-selector.d.ts","sourceRoot":"","sources":["../../lib/model-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC,MAAM,WAAW,SAAS;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CASlD,CAAA;AAgBD,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,aAAa,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,SAAS,CAAA;CAC1B;AAwCD,wBAAsB,WAAW,CAC7B,YAAY,CAAC,EAAE,SAAS,EACxB,MAAM,CAAC,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,CAAC,CA+E/B;AAED,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAmBjG"}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
export const FALLBACK_MODELS = {
|
|
2
|
-
openai:
|
|
3
|
-
anthropic:
|
|
4
|
-
google:
|
|
5
|
-
deepseek:
|
|
6
|
-
xai:
|
|
7
|
-
alibaba:
|
|
8
|
-
zai:
|
|
9
|
-
opencode:
|
|
2
|
+
openai: "gpt-5-mini",
|
|
3
|
+
anthropic: "claude-haiku-4-5", //This model isn't broken in opencode-auth-provider
|
|
4
|
+
google: "gemini-2.5-flash",
|
|
5
|
+
deepseek: "deepseek-chat",
|
|
6
|
+
xai: "grok-4-fast",
|
|
7
|
+
alibaba: "qwen3-coder-flash",
|
|
8
|
+
zai: "glm-4.5-flash",
|
|
9
|
+
opencode: "big-pickle",
|
|
10
10
|
};
|
|
11
11
|
const PROVIDER_PRIORITY = [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
"openai",
|
|
13
|
+
"anthropic",
|
|
14
|
+
"google",
|
|
15
|
+
"deepseek",
|
|
16
|
+
"xai",
|
|
17
|
+
"alibaba",
|
|
18
|
+
"zai",
|
|
19
|
+
"opencode",
|
|
20
20
|
];
|
|
21
21
|
// TODO: some anthropic provided models aren't supported by the opencode-auth-provider package, so this provides a temporary workaround
|
|
22
|
-
const SKIP_PROVIDERS = [
|
|
22
|
+
const SKIP_PROVIDERS = ["github-copilot", "anthropic"];
|
|
23
23
|
function shouldSkipProvider(providerID) {
|
|
24
24
|
const normalized = providerID.toLowerCase().trim();
|
|
25
|
-
return SKIP_PROVIDERS.some(skip => normalized.includes(skip.toLowerCase()));
|
|
25
|
+
return SKIP_PROVIDERS.some((skip) => normalized.includes(skip.toLowerCase()));
|
|
26
26
|
}
|
|
27
27
|
async function importOpencodeAI(logger, maxRetries = 3, delayMs = 100, workspaceDir) {
|
|
28
28
|
let lastError;
|
|
29
29
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
30
30
|
try {
|
|
31
|
-
const { OpencodeAI } = await import(
|
|
31
|
+
const { OpencodeAI } = await import("@tarquinen/opencode-auth-provider");
|
|
32
32
|
return new OpencodeAI({ workspaceDir });
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
35
|
lastError = error;
|
|
36
|
-
if (error.message?.includes(
|
|
36
|
+
if (error.message?.includes("before initialization")) {
|
|
37
37
|
logger?.debug(`Import attempt ${attempt}/${maxRetries} failed, will retry`, {
|
|
38
|
-
error: error.message
|
|
38
|
+
error: error.message,
|
|
39
39
|
});
|
|
40
40
|
if (attempt < maxRetries) {
|
|
41
|
-
await new Promise(resolve => setTimeout(resolve, delayMs * attempt));
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -51,9 +51,9 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
|
|
|
51
51
|
const opencodeAI = await importOpencodeAI(logger, 3, 100, workspaceDir);
|
|
52
52
|
let failedModelInfo;
|
|
53
53
|
if (configModel) {
|
|
54
|
-
const parts = configModel.split(
|
|
54
|
+
const parts = configModel.split("/");
|
|
55
55
|
if (parts.length !== 2) {
|
|
56
|
-
logger?.warn(
|
|
56
|
+
logger?.warn("Invalid config model format", { configModel });
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
59
|
const [providerID, modelID] = parts;
|
|
@@ -62,13 +62,13 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
|
|
|
62
62
|
return {
|
|
63
63
|
model,
|
|
64
64
|
modelInfo: { providerID, modelID },
|
|
65
|
-
source:
|
|
66
|
-
reason:
|
|
65
|
+
source: "config",
|
|
66
|
+
reason: "Using model specified in dcp.jsonc config",
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
70
70
|
logger?.warn(`Config model failed: ${providerID}/${modelID}`, {
|
|
71
|
-
error: error.message
|
|
71
|
+
error: error.message,
|
|
72
72
|
});
|
|
73
73
|
failedModelInfo = { providerID, modelID };
|
|
74
74
|
}
|
|
@@ -86,8 +86,8 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
|
|
|
86
86
|
return {
|
|
87
87
|
model,
|
|
88
88
|
modelInfo: currentModel,
|
|
89
|
-
source:
|
|
90
|
-
reason:
|
|
89
|
+
source: "user-model",
|
|
90
|
+
reason: "Using current session model",
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
@@ -109,22 +109,22 @@ export async function selectModel(currentModel, logger, configModel, workspaceDi
|
|
|
109
109
|
return {
|
|
110
110
|
model,
|
|
111
111
|
modelInfo: { providerID, modelID: fallbackModelID },
|
|
112
|
-
source:
|
|
112
|
+
source: "fallback",
|
|
113
113
|
reason: `Using ${providerID}/${fallbackModelID}`,
|
|
114
|
-
failedModel: failedModelInfo
|
|
114
|
+
failedModel: failedModelInfo,
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
catch (error) {
|
|
118
118
|
continue;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
throw new Error(
|
|
121
|
+
throw new Error("No available models for analysis. Please authenticate with at least one provider.");
|
|
122
122
|
}
|
|
123
123
|
export function extractModelFromSession(sessionState, logger) {
|
|
124
124
|
if (sessionState?.model?.providerID && sessionState?.model?.modelID) {
|
|
125
125
|
return {
|
|
126
126
|
providerID: sessionState.model.providerID,
|
|
127
|
-
modelID: sessionState.model.modelID
|
|
127
|
+
modelID: sessionState.model.modelID,
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
if (sessionState?.messages && Array.isArray(sessionState.messages)) {
|
|
@@ -132,7 +132,7 @@ export function extractModelFromSession(sessionState, logger) {
|
|
|
132
132
|
if (lastMessage?.model?.providerID && lastMessage?.model?.modelID) {
|
|
133
133
|
return {
|
|
134
134
|
providerID: lastMessage.model.providerID,
|
|
135
|
-
modelID: lastMessage.model.modelID
|
|
135
|
+
modelID: lastMessage.model.modelID,
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-selector.js","sourceRoot":"","sources":["../../lib/model-selector.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,eAAe,GAA2B;IACnD,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,kBAAkB,EAAE,mDAAmD;IAClF,MAAM,EAAE,kBAAkB;IAC1B,QAAQ,EAAE,eAAe;IACzB,GAAG,EAAE,aAAa;IAClB,OAAO,EAAE,mBAAmB;IAC5B,GAAG,EAAE,eAAe;IACpB,QAAQ,EAAE,YAAY;CACzB,
|
|
1
|
+
{"version":3,"file":"model-selector.js","sourceRoot":"","sources":["../../lib/model-selector.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,eAAe,GAA2B;IACnD,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,kBAAkB,EAAE,mDAAmD;IAClF,MAAM,EAAE,kBAAkB;IAC1B,QAAQ,EAAE,eAAe;IACzB,GAAG,EAAE,aAAa;IAClB,OAAO,EAAE,mBAAmB;IAC5B,GAAG,EAAE,eAAe;IACpB,QAAQ,EAAE,YAAY;CACzB,CAAA;AAED,MAAM,iBAAiB,GAAG;IACtB,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,UAAU;IACV,KAAK;IACL,SAAS;IACT,KAAK;IACL,UAAU;CACb,CAAA;AAED,uIAAuI;AACvI,MAAM,cAAc,GAAG,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAA;AAUtD,SAAS,kBAAkB,CAAC,UAAkB;IAC1C,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;IAClD,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU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AAG,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC3E,IAAI,WAAW,EAAE,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAChE,OAAO;gBACH,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,UAAU;gBACxC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO;aACrC,CAAA;QACL,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC"}
|
package/dist/lib/prompt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAS9E;
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAS9E;AA2HD,wBAAgB,mBAAmB,CAC/B,mBAAmB,EAAE,MAAM,EAAE,EAC7B,QAAQ,EAAE,GAAG,EAAE,EACf,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,GAChC,MAAM,CAQR"}
|
package/dist/lib/prompt.js
CHANGED
|
@@ -5,80 +5,91 @@ export function loadPrompt(name, vars) {
|
|
|
5
5
|
let content = readFileSync(filePath, "utf8").trim();
|
|
6
6
|
if (vars) {
|
|
7
7
|
for (const [key, value] of Object.entries(vars)) {
|
|
8
|
-
content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`,
|
|
8
|
+
content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
return content;
|
|
12
12
|
}
|
|
13
13
|
function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
14
|
-
const prunedIdsSet = alreadyPrunedIds
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const prunedIdsSet = alreadyPrunedIds
|
|
15
|
+
? new Set(alreadyPrunedIds.map((id) => id.toLowerCase()))
|
|
16
|
+
: new Set();
|
|
17
|
+
const protectedIdsSet = protectedToolCallIds
|
|
18
|
+
? new Set(protectedToolCallIds.map((id) => id.toLowerCase()))
|
|
19
|
+
: new Set();
|
|
20
|
+
return messages
|
|
21
|
+
.map((msg) => {
|
|
17
22
|
const minimized = {
|
|
18
|
-
role: msg.info?.role
|
|
23
|
+
role: msg.info?.role,
|
|
19
24
|
};
|
|
20
25
|
if (msg.parts) {
|
|
21
26
|
minimized.parts = msg.parts
|
|
22
27
|
.filter((part) => {
|
|
23
|
-
if (part.type ===
|
|
28
|
+
if (part.type === "step-start" || part.type === "step-finish") {
|
|
24
29
|
return false;
|
|
25
30
|
}
|
|
26
31
|
return true;
|
|
27
32
|
})
|
|
28
33
|
.map((part) => {
|
|
29
|
-
if (part.type ===
|
|
34
|
+
if (part.type === "text") {
|
|
30
35
|
if (part.ignored) {
|
|
31
36
|
return null;
|
|
32
37
|
}
|
|
33
38
|
return {
|
|
34
|
-
type:
|
|
35
|
-
text: part.text
|
|
39
|
+
type: "text",
|
|
40
|
+
text: part.text,
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
// TODO: This should use the opencode normalized system instead of per provider settings
|
|
39
|
-
if (part.type ===
|
|
44
|
+
if (part.type === "reasoning") {
|
|
40
45
|
// Calculate encrypted content size if present
|
|
41
46
|
let encryptedContentLength = 0;
|
|
42
47
|
if (part.metadata?.openai?.reasoningEncryptedContent) {
|
|
43
|
-
encryptedContentLength =
|
|
48
|
+
encryptedContentLength =
|
|
49
|
+
part.metadata.openai.reasoningEncryptedContent.length;
|
|
44
50
|
}
|
|
45
51
|
else if (part.metadata?.anthropic?.signature) {
|
|
46
52
|
encryptedContentLength = part.metadata.anthropic.signature.length;
|
|
47
53
|
}
|
|
48
54
|
else if (part.metadata?.google?.thoughtSignature) {
|
|
49
|
-
encryptedContentLength =
|
|
55
|
+
encryptedContentLength =
|
|
56
|
+
part.metadata.google.thoughtSignature.length;
|
|
50
57
|
}
|
|
51
58
|
return {
|
|
52
|
-
type:
|
|
59
|
+
type: "reasoning",
|
|
53
60
|
text: part.text,
|
|
54
61
|
textLength: part.text?.length || 0,
|
|
55
62
|
encryptedContentLength,
|
|
56
63
|
...(part.time && { time: part.time }),
|
|
57
|
-
...(part.metadata && { metadataKeys: Object.keys(part.metadata) })
|
|
64
|
+
...(part.metadata && { metadataKeys: Object.keys(part.metadata) }),
|
|
58
65
|
};
|
|
59
66
|
}
|
|
60
|
-
if (part.type ===
|
|
67
|
+
if (part.type === "tool") {
|
|
61
68
|
const callIDLower = part.callID?.toLowerCase();
|
|
62
69
|
const isAlreadyPruned = prunedIdsSet.has(callIDLower);
|
|
63
70
|
const isProtected = protectedIdsSet.has(callIDLower);
|
|
64
71
|
let displayCallID = part.callID;
|
|
65
72
|
if (isAlreadyPruned) {
|
|
66
|
-
displayCallID =
|
|
73
|
+
displayCallID = "<already-pruned>";
|
|
67
74
|
}
|
|
68
75
|
else if (isProtected) {
|
|
69
|
-
displayCallID =
|
|
76
|
+
displayCallID = "<protected>";
|
|
70
77
|
}
|
|
71
78
|
const toolPart = {
|
|
72
|
-
type:
|
|
79
|
+
type: "tool",
|
|
73
80
|
toolCallID: displayCallID,
|
|
74
|
-
tool: part.tool
|
|
81
|
+
tool: part.tool,
|
|
75
82
|
};
|
|
76
83
|
if (part.state?.output) {
|
|
77
84
|
toolPart.output = part.state.output;
|
|
78
85
|
}
|
|
79
86
|
if (part.state?.input) {
|
|
80
87
|
const input = part.state.input;
|
|
81
|
-
if (input.filePath &&
|
|
88
|
+
if (input.filePath &&
|
|
89
|
+
(part.tool === "write" ||
|
|
90
|
+
part.tool === "edit" ||
|
|
91
|
+
part.tool === "multiedit" ||
|
|
92
|
+
part.tool === "patch")) {
|
|
82
93
|
toolPart.input = input;
|
|
83
94
|
}
|
|
84
95
|
else if (input.filePath) {
|
|
@@ -87,7 +98,7 @@ function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
|
87
98
|
else if (input.tool_calls && Array.isArray(input.tool_calls)) {
|
|
88
99
|
toolPart.input = {
|
|
89
100
|
batch_summary: `${input.tool_calls.length} tool calls`,
|
|
90
|
-
tools: input.tool_calls.map((tc) => tc.tool)
|
|
101
|
+
tools: input.tool_calls.map((tc) => tc.tool),
|
|
91
102
|
};
|
|
92
103
|
}
|
|
93
104
|
else {
|
|
@@ -101,16 +112,17 @@ function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
|
101
112
|
.filter(Boolean);
|
|
102
113
|
}
|
|
103
114
|
return minimized;
|
|
104
|
-
})
|
|
115
|
+
})
|
|
116
|
+
.filter((msg) => {
|
|
105
117
|
return msg.parts && msg.parts.length > 0;
|
|
106
118
|
});
|
|
107
119
|
}
|
|
108
120
|
export function buildAnalysisPrompt(unprunedToolCallIds, messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
109
121
|
const minimizedMessages = minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds);
|
|
110
|
-
const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g,
|
|
122
|
+
const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, "\n");
|
|
111
123
|
return loadPrompt("on-idle-analysis", {
|
|
112
124
|
available_tool_call_ids: unprunedToolCallIds.join(", "),
|
|
113
|
-
session_history: messagesJson
|
|
125
|
+
session_history: messagesJson,
|
|
114
126
|
});
|
|
115
127
|
}
|
|
116
128
|
//# sourceMappingURL=prompt.js.map
|
package/dist/lib/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAA6B;IAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI,MAAM,CAAC,CAAA;IAC1D,IAAI,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IACnD,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;AAED,SAAS,gBAAgB,
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../lib/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAA6B;IAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI,MAAM,CAAC,CAAA;IAC1D,IAAI,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IACnD,IAAI,IAAI,EAAE,CAAC;QACP,KAAK,MAAM,CAAC,GAAG,EAA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,7 +1,7 @@
|
|
|
1
1
|
Discards tool outputs from context to manage conversation size and reduce noise.
|
|
2
2
|
|
|
3
3
|
## IMPORTANT: The Prunable List
|
|
4
|
-
A `<prunable-tools>` list is
|
|
4
|
+
A `<prunable-tools>` list is provided to you showing available tool outputs you can discard when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to discard.
|
|
5
5
|
|
|
6
6
|
**Note:** For `write` and `edit` tools, discarding removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context.
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Extracts key findings from tool outputs into distilled knowledge, then removes the raw outputs from context.
|
|
2
2
|
|
|
3
3
|
## IMPORTANT: The Prunable List
|
|
4
|
-
A `<prunable-tools>` list is
|
|
4
|
+
A `<prunable-tools>` list is provided to you showing available tool outputs you can extract from when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to extract.
|
|
5
5
|
|
|
6
6
|
## When to Use This Tool
|
|
7
7
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<instruction name=context_management_required>
|
|
2
|
-
**CRITICAL CONTEXT WARNING:**
|
|
2
|
+
**CRITICAL CONTEXT WARNING:** My context window is filling with tool outputs. I must adhere strictly to context hygiene.
|
|
3
3
|
|
|
4
4
|
**Immediate Actions Required:**
|
|
5
|
-
1. **Task Completion:** If a sub-task is complete, decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping.
|
|
6
|
-
2. **Noise Removal:** If
|
|
7
|
-
3. **Knowledge Preservation:** If
|
|
5
|
+
1. **Task Completion:** If a sub-task is complete, I will decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping.
|
|
6
|
+
2. **Noise Removal:** If I read files or ran commands that yielded no value, I will use `discard` to remove them.
|
|
7
|
+
3. **Knowledge Preservation:** If I am holding valuable raw data I'll need to reference later, I will use `extract` to distill the insights and remove the raw entry.
|
|
8
8
|
|
|
9
|
-
**Protocol:**
|
|
9
|
+
**Protocol:** I should prioritize this cleanup, but I will not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, I must perform context management.
|
|
10
10
|
</instruction>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<instruction name=context_management_required>
|
|
2
|
-
**CRITICAL CONTEXT WARNING:**
|
|
2
|
+
**CRITICAL CONTEXT WARNING:** My context window is filling with tool outputs. I must adhere strictly to context hygiene.
|
|
3
3
|
|
|
4
4
|
**Immediate Actions Required:**
|
|
5
|
-
1. **Task Completion:** If a sub-task is complete, use the `discard` tool to remove the tools used.
|
|
6
|
-
2. **Noise Removal:** If
|
|
5
|
+
1. **Task Completion:** If a sub-task is complete, I will use the `discard` tool to remove the tools used.
|
|
6
|
+
2. **Noise Removal:** If I read files or ran commands that yielded no value, I will use the `discard` tool to remove them.
|
|
7
7
|
|
|
8
|
-
**Protocol:**
|
|
8
|
+
**Protocol:** I should prioritize this cleanup, but I will not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, I must discard unneeded tool outputs.
|
|
9
9
|
</instruction>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<instruction name=context_management_required>
|
|
2
|
-
**CRITICAL CONTEXT WARNING:**
|
|
2
|
+
**CRITICAL CONTEXT WARNING:** My context window is filling with tool outputs. I must adhere strictly to context hygiene.
|
|
3
3
|
|
|
4
4
|
**Immediate Actions Required:**
|
|
5
|
-
1. **Task Completion:** If
|
|
6
|
-
2. **Knowledge Preservation:** If
|
|
5
|
+
1. **Task Completion:** If I have completed work, I will extract key findings from the tools used. I will scale distillation depth to the value of the content.
|
|
6
|
+
2. **Knowledge Preservation:** If I am holding valuable raw data I'll need to reference later, I will use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry.
|
|
7
7
|
|
|
8
|
-
**Protocol:**
|
|
8
|
+
**Protocol:** I should prioritize this cleanup, but I will not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, I must extract valuable findings from tool outputs.
|
|
9
9
|
</instruction>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<instruction name=context_management_protocol policy_level=critical>
|
|
3
3
|
|
|
4
4
|
ENVIRONMENT
|
|
5
|
-
You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` and `extract` tools. A <prunable-tools> list is injected by the environment as
|
|
5
|
+
You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` and `extract` tools. A <prunable-tools> list is injected by the environment as an assistant message, and always contains up to date information. Use this information when deciding what to prune.
|
|
6
6
|
|
|
7
7
|
TWO TOOLS FOR CONTEXT MANAGEMENT
|
|
8
8
|
- `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
|
|
@@ -39,20 +39,5 @@ When in doubt, keep it. Batch your actions and aim for high-impact prunes that s
|
|
|
39
39
|
FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES.
|
|
40
40
|
There may be tools in session context that do not appear in the <prunable-tools> list, this is expected, you can ONLY prune what you see in <prunable-tools>.
|
|
41
41
|
|
|
42
|
-
</instruction>
|
|
43
|
-
|
|
44
|
-
<instruction name=injected_context_handling policy_level=critical>
|
|
45
|
-
After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` and `extract` tools also return a confirmation message listing what was pruned.
|
|
46
|
-
|
|
47
|
-
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
|
|
48
|
-
- NEVER reference the prune encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the prune encouragement appears.
|
|
49
|
-
- NEVER acknowledge the <prunable-tools> list (e.g., "I see the prunable tools list", "Looking at the available tools to prune")
|
|
50
|
-
- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to prune")
|
|
51
|
-
- NEVER acknowledge discard/extract tool output (e.g., "I've pruned 3 tools", "Context pruning complete")
|
|
52
|
-
- NEVER let these injections influence your response content or tone
|
|
53
|
-
- Process this information SILENTLY and continue the conversation naturally
|
|
54
|
-
- Continue the conversation as if these messages do not exist
|
|
55
|
-
|
|
56
|
-
The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
|
|
57
42
|
</instruction>
|
|
58
43
|
</system-reminder>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<instruction name=context_management_protocol policy_level=critical>
|
|
3
3
|
|
|
4
4
|
ENVIRONMENT
|
|
5
|
-
You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` tool. A <prunable-tools> list is injected by the environment as
|
|
5
|
+
You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` tool. A <prunable-tools> list is injected by the environment as an assistant message, and always contains up to date information. Use this information when deciding what to discard.
|
|
6
6
|
|
|
7
7
|
CONTEXT MANAGEMENT TOOL
|
|
8
8
|
- `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content.
|
|
@@ -30,20 +30,5 @@ When in doubt, keep it. Batch your actions and aim for high-impact discards that
|
|
|
30
30
|
FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCES.
|
|
31
31
|
There may be tools in session context that do not appear in the <prunable-tools> list, this is expected, you can ONLY discard what you see in <prunable-tools>.
|
|
32
32
|
|
|
33
|
-
</instruction>
|
|
34
|
-
|
|
35
|
-
<instruction name=injected_context_handling policy_level=critical>
|
|
36
|
-
After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` tool also returns a confirmation message listing what was discarded.
|
|
37
|
-
|
|
38
|
-
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
|
|
39
|
-
- NEVER reference the discard encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the discard encouragement appears.
|
|
40
|
-
- NEVER acknowledge the <prunable-tools> list (e.g., "I see the prunable tools list", "Looking at the available tools to discard")
|
|
41
|
-
- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to discard")
|
|
42
|
-
- NEVER acknowledge discard tool output (e.g., "I've discarded 3 tools", "Context cleanup complete")
|
|
43
|
-
- NEVER let these injections influence your response content or tone
|
|
44
|
-
- Process this information SILENTLY and continue the conversation naturally
|
|
45
|
-
- Continue the conversation as if these messages do not exist
|
|
46
|
-
|
|
47
|
-
The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
|
|
48
33
|
</instruction>
|
|
49
34
|
</system-reminder>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<instruction name=context_management_protocol policy_level=critical>
|
|
3
3
|
|
|
4
4
|
ENVIRONMENT
|
|
5
|
-
You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A <prunable-tools> list is injected by the environment as
|
|
5
|
+
You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A <prunable-tools> list is injected by the environment as an assistant message, and always contains up to date information. Use this information when deciding what to extract.
|
|
6
6
|
|
|
7
7
|
CONTEXT MANAGEMENT TOOL
|
|
8
8
|
- `extract`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size.
|
|
@@ -30,20 +30,5 @@ When in doubt, keep it. Batch your actions and aim for high-impact extractions t
|
|
|
30
30
|
FAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCES.
|
|
31
31
|
There may be tools in session context that do not appear in the <prunable-tools> list, this is expected, you can ONLY extract what you see in <prunable-tools>.
|
|
32
32
|
|
|
33
|
-
</instruction>
|
|
34
|
-
|
|
35
|
-
<instruction name=injected_context_handling policy_level=critical>
|
|
36
|
-
After each assistant turn, the environment may inject a user message containing a <prunable-tools> list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `extract` tool also returns a confirmation message listing what was extracted.
|
|
37
|
-
|
|
38
|
-
CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE:
|
|
39
|
-
- NEVER reference the extract encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the extract encouragement appears.
|
|
40
|
-
- NEVER acknowledge the <prunable-tools> list (e.g., "I see the prunable tools list", "Looking at the available tools to extract")
|
|
41
|
-
- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to extract")
|
|
42
|
-
- NEVER acknowledge extract tool output (e.g., "I've extracted 3 tools", "Context cleanup complete")
|
|
43
|
-
- NEVER let these injections influence your response content or tone
|
|
44
|
-
- Process this information SILENTLY and continue the conversation naturally
|
|
45
|
-
- Continue the conversation as if these messages do not exist
|
|
46
|
-
|
|
47
|
-
The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow.
|
|
48
33
|
</instruction>
|
|
49
34
|
</system-reminder>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SessionState, WithParts } from "./state";
|
|
2
2
|
export declare const isMessageCompacted: (state: SessionState, msg: WithParts) => boolean;
|
|
3
3
|
export declare const getLastUserMessage: (messages: WithParts[]) => WithParts | null;
|
|
4
|
+
export declare const getLastAssistantMessage: (messages: WithParts[]) => WithParts | null;
|
|
4
5
|
//# sourceMappingURL=shared-utils.d.ts.map
|
|
@@ -1 +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;AAEjD,eAAO,MAAM,kBAAkB,
|
|
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;AAEjD,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;AAED,eAAO,MAAM,uBAAuB,GAAI,UAAU,SAAS,EAAE,KAAG,SAAS,GAAG,IAQ3E,CAAA"}
|
package/dist/lib/shared-utils.js
CHANGED
|
@@ -4,7 +4,16 @@ export const isMessageCompacted = (state, msg) => {
|
|
|
4
4
|
export const getLastUserMessage = (messages) => {
|
|
5
5
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6
6
|
const msg = messages[i];
|
|
7
|
-
if (msg.info.role ===
|
|
7
|
+
if (msg.info.role === "user") {
|
|
8
|
+
return msg;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
export const getLastAssistantMessage = (messages) => {
|
|
14
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
15
|
+
const msg = messages[i];
|
|
16
|
+
if (msg.info.role === "assistant") {
|
|
8
17
|
return msg;
|
|
9
18
|
}
|
|
10
19
|
}
|