@dev4s/opencode-dcp 0.1.0
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 +160 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +58 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +696 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/hooks.d.ts +10 -0
- package/dist/lib/hooks.d.ts.map +1 -0
- package/dist/lib/hooks.js +45 -0
- package/dist/lib/hooks.js.map +1 -0
- package/dist/lib/logger.d.ts +31 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +183 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/messages/index.d.ts +2 -0
- package/dist/lib/messages/index.d.ts.map +1 -0
- package/dist/lib/messages/index.js +2 -0
- package/dist/lib/messages/index.js.map +1 -0
- package/dist/lib/messages/prune.d.ts +6 -0
- package/dist/lib/messages/prune.d.ts.map +1 -0
- package/dist/lib/messages/prune.js +187 -0
- package/dist/lib/messages/prune.js.map +1 -0
- package/dist/lib/messages/utils.d.ts +9 -0
- package/dist/lib/messages/utils.d.ts.map +1 -0
- package/dist/lib/messages/utils.js +124 -0
- package/dist/lib/messages/utils.js.map +1 -0
- package/dist/lib/model-selector.d.ts +17 -0
- package/dist/lib/model-selector.d.ts.map +1 -0
- package/dist/lib/model-selector.js +141 -0
- package/dist/lib/model-selector.js.map +1 -0
- package/dist/lib/prompt.d.ts +3 -0
- package/dist/lib/prompt.d.ts.map +1 -0
- package/dist/lib/prompt.js +128 -0
- package/dist/lib/prompt.js.map +1 -0
- package/dist/lib/prompts/discard-tool-spec.txt +41 -0
- package/dist/lib/prompts/extract-tool-spec.txt +47 -0
- package/dist/lib/prompts/on-idle-analysis.txt +30 -0
- package/dist/lib/prompts/user/nudge/nudge-both.txt +10 -0
- package/dist/lib/prompts/user/nudge/nudge-discard.txt +9 -0
- package/dist/lib/prompts/user/nudge/nudge-extract.txt +9 -0
- package/dist/lib/prompts/user/system/system-prompt-both.txt +58 -0
- package/dist/lib/prompts/user/system/system-prompt-discard.txt +49 -0
- package/dist/lib/prompts/user/system/system-prompt-extract.txt +49 -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 +13 -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 +16 -0
- package/dist/lib/state/persistence.d.ts.map +1 -0
- package/dist/lib/state/persistence.js +73 -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 +112 -0
- package/dist/lib/state/state.js.map +1 -0
- package/dist/lib/state/tool-cache.d.ts +13 -0
- package/dist/lib/state/tool-cache.d.ts.map +1 -0
- package/dist/lib/state/tool-cache.js +74 -0
- package/dist/lib/state/tool-cache.js.map +1 -0
- package/dist/lib/state/types.d.ts +32 -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 +10 -0
- package/dist/lib/strategies/deduplication.d.ts.map +1 -0
- package/dist/lib/strategies/deduplication.js +89 -0
- package/dist/lib/strategies/deduplication.js.map +1 -0
- package/dist/lib/strategies/index.d.ts +6 -0
- package/dist/lib/strategies/index.d.ts.map +1 -0
- package/dist/lib/strategies/index.js +6 -0
- package/dist/lib/strategies/index.js.map +1 -0
- package/dist/lib/strategies/on-idle.d.ts +14 -0
- package/dist/lib/strategies/on-idle.d.ts.map +1 -0
- package/dist/lib/strategies/on-idle.js +220 -0
- package/dist/lib/strategies/on-idle.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 +54 -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 +80 -0
- package/dist/lib/strategies/supersede-writes.js.map +1 -0
- package/dist/lib/strategies/tools.d.ts +14 -0
- package/dist/lib/strategies/tools.d.ts.map +1 -0
- package/dist/lib/strategies/tools.js +137 -0
- package/dist/lib/strategies/tools.js.map +1 -0
- package/dist/lib/strategies/utils.d.ts +12 -0
- package/dist/lib/strategies/utils.d.ts.map +1 -0
- package/dist/lib/strategies/utils.js +82 -0
- package/dist/lib/strategies/utils.js.map +1 -0
- package/dist/lib/tokenizer.d.ts +24 -0
- package/dist/lib/tokenizer.d.ts.map +1 -0
- package/dist/lib/tokenizer.js +45 -0
- package/dist/lib/tokenizer.js.map +1 -0
- package/dist/lib/ui/notification.d.ts +9 -0
- package/dist/lib/ui/notification.d.ts.map +1 -0
- package/dist/lib/ui/notification.js +70 -0
- package/dist/lib/ui/notification.js.map +1 -0
- package/dist/lib/ui/utils.d.ts +15 -0
- package/dist/lib/ui/utils.d.ts.map +1 -0
- package/dist/lib/ui/utils.js +87 -0
- package/dist/lib/ui/utils.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isMessageCompacted } from "../shared-utils";
|
|
2
|
+
const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345";
|
|
3
|
+
const SYNTHETIC_PART_ID = "prt_01234567890123456789012345";
|
|
4
|
+
export const createSyntheticUserMessage = (baseMessage, content) => {
|
|
5
|
+
const userInfo = baseMessage.info;
|
|
6
|
+
return {
|
|
7
|
+
info: {
|
|
8
|
+
id: SYNTHETIC_MESSAGE_ID,
|
|
9
|
+
sessionID: userInfo.sessionID,
|
|
10
|
+
role: "user",
|
|
11
|
+
time: { created: Date.now() },
|
|
12
|
+
agent: userInfo.agent || "code",
|
|
13
|
+
model: {
|
|
14
|
+
providerID: userInfo.model.providerID,
|
|
15
|
+
modelID: userInfo.model.modelID,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
parts: [
|
|
19
|
+
{
|
|
20
|
+
id: SYNTHETIC_PART_ID,
|
|
21
|
+
sessionID: userInfo.sessionID,
|
|
22
|
+
messageID: SYNTHETIC_MESSAGE_ID,
|
|
23
|
+
type: "text",
|
|
24
|
+
text: content,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Extracts a human-readable key from tool metadata for display purposes.
|
|
31
|
+
*/
|
|
32
|
+
export const extractParameterKey = (tool, parameters) => {
|
|
33
|
+
if (!parameters)
|
|
34
|
+
return "";
|
|
35
|
+
if (tool === "read" && parameters.filePath) {
|
|
36
|
+
const offset = parameters.offset;
|
|
37
|
+
const limit = parameters.limit;
|
|
38
|
+
if (offset !== undefined && limit !== undefined) {
|
|
39
|
+
return `${parameters.filePath} (lines ${offset}-${offset + limit})`;
|
|
40
|
+
}
|
|
41
|
+
if (offset !== undefined) {
|
|
42
|
+
return `${parameters.filePath} (lines ${offset}+)`;
|
|
43
|
+
}
|
|
44
|
+
if (limit !== undefined) {
|
|
45
|
+
return `${parameters.filePath} (lines 0-${limit})`;
|
|
46
|
+
}
|
|
47
|
+
return parameters.filePath;
|
|
48
|
+
}
|
|
49
|
+
if (tool === "write" && parameters.filePath) {
|
|
50
|
+
return parameters.filePath;
|
|
51
|
+
}
|
|
52
|
+
if (tool === "edit" && parameters.filePath) {
|
|
53
|
+
return parameters.filePath;
|
|
54
|
+
}
|
|
55
|
+
if (tool === "list") {
|
|
56
|
+
return parameters.path || "(current directory)";
|
|
57
|
+
}
|
|
58
|
+
if (tool === "glob") {
|
|
59
|
+
if (parameters.pattern) {
|
|
60
|
+
const pathInfo = parameters.path ? ` in ${parameters.path}` : "";
|
|
61
|
+
return `"${parameters.pattern}"${pathInfo}`;
|
|
62
|
+
}
|
|
63
|
+
return "(unknown pattern)";
|
|
64
|
+
}
|
|
65
|
+
if (tool === "grep") {
|
|
66
|
+
if (parameters.pattern) {
|
|
67
|
+
const pathInfo = parameters.path ? ` in ${parameters.path}` : "";
|
|
68
|
+
return `"${parameters.pattern}"${pathInfo}`;
|
|
69
|
+
}
|
|
70
|
+
return "(unknown pattern)";
|
|
71
|
+
}
|
|
72
|
+
if (tool === "bash") {
|
|
73
|
+
if (parameters.description)
|
|
74
|
+
return parameters.description;
|
|
75
|
+
if (parameters.command) {
|
|
76
|
+
return parameters.command.length > 50
|
|
77
|
+
? parameters.command.substring(0, 50) + "..."
|
|
78
|
+
: parameters.command;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (tool === "webfetch" && parameters.url) {
|
|
82
|
+
return parameters.url;
|
|
83
|
+
}
|
|
84
|
+
if (tool === "websearch" && parameters.query) {
|
|
85
|
+
return `"${parameters.query}"`;
|
|
86
|
+
}
|
|
87
|
+
if (tool === "codesearch" && parameters.query) {
|
|
88
|
+
return `"${parameters.query}"`;
|
|
89
|
+
}
|
|
90
|
+
if (tool === "todowrite") {
|
|
91
|
+
return `${parameters.todos?.length || 0} todos`;
|
|
92
|
+
}
|
|
93
|
+
if (tool === "todoread") {
|
|
94
|
+
return "read todo list";
|
|
95
|
+
}
|
|
96
|
+
if (tool === "task" && parameters.description) {
|
|
97
|
+
return parameters.description;
|
|
98
|
+
}
|
|
99
|
+
if (tool === "skill" && parameters.name) {
|
|
100
|
+
return parameters.name;
|
|
101
|
+
}
|
|
102
|
+
const paramStr = JSON.stringify(parameters);
|
|
103
|
+
if (paramStr === "{}" || paramStr === "[]" || paramStr === "null") {
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
return paramStr.substring(0, 50);
|
|
107
|
+
};
|
|
108
|
+
export function buildToolIdList(state, messages, logger) {
|
|
109
|
+
const toolIds = [];
|
|
110
|
+
for (const msg of messages) {
|
|
111
|
+
if (isMessageCompacted(state, msg)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (msg.parts) {
|
|
115
|
+
for (const part of msg.parts) {
|
|
116
|
+
if (part.type === "tool" && part.callID && part.tool) {
|
|
117
|
+
toolIds.push(part.callID);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return toolIds;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/messages/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAIpD,MAAM,oBAAoB,GAAG,gCAAgC,CAAA;AAC7D,MAAM,iBAAiB,GAAG,gCAAgC,CAAA;AAE1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,WAAsB,EAAE,OAAe,EAAa,EAAE;IAC7F,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAmB,CAAA;IAChD,OAAO;QACH,IAAI,EAAE;YACF,EAAE,EAAE,oBAAoB;YACxB,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;YAC7B,KAAK,EAAE,QAAQ,CAAC,KAAK,IAAI,MAAM;YAC/B,KAAK,EAAE;gBACH,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;gBACrC,OAAO,EAA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,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBAC3B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACnD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAC7B,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
import type { Logger } from "./logger";
|
|
3
|
+
export interface ModelInfo {
|
|
4
|
+
providerID: string;
|
|
5
|
+
modelID: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const FALLBACK_MODELS: Record<string, string>;
|
|
8
|
+
export interface ModelSelectionResult {
|
|
9
|
+
model: LanguageModel;
|
|
10
|
+
modelInfo: ModelInfo;
|
|
11
|
+
source: "user-model" | "config" | "fallback";
|
|
12
|
+
reason?: string;
|
|
13
|
+
failedModel?: ModelInfo;
|
|
14
|
+
}
|
|
15
|
+
export declare function selectModel(currentModel?: ModelInfo, logger?: Logger, configModel?: string, workspaceDir?: string): Promise<ModelSelectionResult>;
|
|
16
|
+
export declare function extractModelFromSession(sessionState: any, logger?: Logger): ModelInfo | undefined;
|
|
17
|
+
//# sourceMappingURL=model-selector.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export const FALLBACK_MODELS = {
|
|
2
|
+
openai: "gpt-5-mini",
|
|
3
|
+
anthropic: "claude-haiku-4-5", //This model isn't broken in opencode-auth-provider
|
|
4
|
+
google: "gemini-2.5-flash",
|
|
5
|
+
deepseek: "deepseek-chat",
|
|
6
|
+
xai: "grok-4-fast",
|
|
7
|
+
alibaba: "qwen3-coder-flash",
|
|
8
|
+
zai: "glm-4.5-flash",
|
|
9
|
+
opencode: "big-pickle",
|
|
10
|
+
};
|
|
11
|
+
const PROVIDER_PRIORITY = [
|
|
12
|
+
"openai",
|
|
13
|
+
"anthropic",
|
|
14
|
+
"google",
|
|
15
|
+
"deepseek",
|
|
16
|
+
"xai",
|
|
17
|
+
"alibaba",
|
|
18
|
+
"zai",
|
|
19
|
+
"opencode",
|
|
20
|
+
];
|
|
21
|
+
// TODO: some anthropic provided models aren't supported by the opencode-auth-provider package, so this provides a temporary workaround
|
|
22
|
+
const SKIP_PROVIDERS = ["github-copilot", "anthropic"];
|
|
23
|
+
function shouldSkipProvider(providerID) {
|
|
24
|
+
const normalized = providerID.toLowerCase().trim();
|
|
25
|
+
return SKIP_PROVIDERS.some((skip) => normalized.includes(skip.toLowerCase()));
|
|
26
|
+
}
|
|
27
|
+
async function importOpencodeAI(logger, maxRetries = 3, delayMs = 100, workspaceDir) {
|
|
28
|
+
let lastError;
|
|
29
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
30
|
+
try {
|
|
31
|
+
const { OpencodeAI } = await import("@tarquinen/opencode-auth-provider");
|
|
32
|
+
return new OpencodeAI({ workspaceDir });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
lastError = error;
|
|
36
|
+
if (error.message?.includes("before initialization")) {
|
|
37
|
+
logger?.debug(`Import attempt ${attempt}/${maxRetries} failed, will retry`, {
|
|
38
|
+
error: error.message,
|
|
39
|
+
});
|
|
40
|
+
if (attempt < maxRetries) {
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw lastError;
|
|
49
|
+
}
|
|
50
|
+
export async function selectModel(currentModel, logger, configModel, workspaceDir) {
|
|
51
|
+
const opencodeAI = await importOpencodeAI(logger, 3, 100, workspaceDir);
|
|
52
|
+
let failedModelInfo;
|
|
53
|
+
if (configModel) {
|
|
54
|
+
const parts = configModel.split("/");
|
|
55
|
+
if (parts.length !== 2) {
|
|
56
|
+
logger?.warn("Invalid config model format", { configModel });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const [providerID, modelID] = parts;
|
|
60
|
+
try {
|
|
61
|
+
const model = await opencodeAI.getLanguageModel(providerID, modelID);
|
|
62
|
+
return {
|
|
63
|
+
model,
|
|
64
|
+
modelInfo: { providerID, modelID },
|
|
65
|
+
source: "config",
|
|
66
|
+
reason: "Using model specified in dcp.jsonc config",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
logger?.warn(`Config model failed: ${providerID}/${modelID}`, {
|
|
71
|
+
error: error.message,
|
|
72
|
+
});
|
|
73
|
+
failedModelInfo = { providerID, modelID };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (currentModel) {
|
|
78
|
+
if (shouldSkipProvider(currentModel.providerID)) {
|
|
79
|
+
if (!failedModelInfo) {
|
|
80
|
+
failedModelInfo = currentModel;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
try {
|
|
85
|
+
const model = await opencodeAI.getLanguageModel(currentModel.providerID, currentModel.modelID);
|
|
86
|
+
return {
|
|
87
|
+
model,
|
|
88
|
+
modelInfo: currentModel,
|
|
89
|
+
source: "user-model",
|
|
90
|
+
reason: "Using current session model",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (!failedModelInfo) {
|
|
95
|
+
failedModelInfo = currentModel;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const providers = await opencodeAI.listProviders();
|
|
101
|
+
for (const providerID of PROVIDER_PRIORITY) {
|
|
102
|
+
if (!providers[providerID])
|
|
103
|
+
continue;
|
|
104
|
+
const fallbackModelID = FALLBACK_MODELS[providerID];
|
|
105
|
+
if (!fallbackModelID)
|
|
106
|
+
continue;
|
|
107
|
+
try {
|
|
108
|
+
const model = await opencodeAI.getLanguageModel(providerID, fallbackModelID);
|
|
109
|
+
return {
|
|
110
|
+
model,
|
|
111
|
+
modelInfo: { providerID, modelID: fallbackModelID },
|
|
112
|
+
source: "fallback",
|
|
113
|
+
reason: `Using ${providerID}/${fallbackModelID}`,
|
|
114
|
+
failedModel: failedModelInfo,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
throw new Error("No available models for analysis. Please authenticate with at least one provider.");
|
|
122
|
+
}
|
|
123
|
+
export function extractModelFromSession(sessionState, logger) {
|
|
124
|
+
if (sessionState?.model?.providerID && sessionState?.model?.modelID) {
|
|
125
|
+
return {
|
|
126
|
+
providerID: sessionState.model.providerID,
|
|
127
|
+
modelID: sessionState.model.modelID,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (sessionState?.messages && Array.isArray(sessionState.messages)) {
|
|
131
|
+
const lastMessage = sessionState.messages[sessionState.messages.length - 1];
|
|
132
|
+
if (lastMessage?.model?.providerID && lastMessage?.model?.modelID) {
|
|
133
|
+
return {
|
|
134
|
+
providerID: lastMessage.model.providerID,
|
|
135
|
+
modelID: lastMessage.model.modelID,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=model-selector.js.map
|
|
@@ -0,0 +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,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,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I,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjE,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC3E,IAAI,WAAW,EAAE,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAChE,OAAO;gBACH,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,UAAU;gBACxC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO;aACrC,CAAA;QACL,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function loadPrompt(name: string, vars?: Record<string, string>): string;
|
|
2
|
+
export declare function buildAnalysisPrompt(unprunedToolCallIds: string[], messages: any[], alreadyPrunedIds?: string[], protectedToolCallIds?: string[]): string;
|
|
3
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
export function loadPrompt(name, vars) {
|
|
4
|
+
const filePath = join(__dirname, "prompts", `${name}.txt`);
|
|
5
|
+
let content = readFileSync(filePath, "utf8").trim();
|
|
6
|
+
if (vars) {
|
|
7
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
8
|
+
content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return content;
|
|
12
|
+
}
|
|
13
|
+
function minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
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) => {
|
|
22
|
+
const minimized = {
|
|
23
|
+
role: msg.info?.role,
|
|
24
|
+
};
|
|
25
|
+
if (msg.parts) {
|
|
26
|
+
minimized.parts = msg.parts
|
|
27
|
+
.filter((part) => {
|
|
28
|
+
if (part.type === "step-start" || part.type === "step-finish") {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
})
|
|
33
|
+
.map((part) => {
|
|
34
|
+
if (part.type === "text") {
|
|
35
|
+
if (part.ignored) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
type: "text",
|
|
40
|
+
text: part.text,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// TODO: This should use the opencode normalized system instead of per provider settings
|
|
44
|
+
if (part.type === "reasoning") {
|
|
45
|
+
// Calculate encrypted content size if present
|
|
46
|
+
let encryptedContentLength = 0;
|
|
47
|
+
if (part.metadata?.openai?.reasoningEncryptedContent) {
|
|
48
|
+
encryptedContentLength =
|
|
49
|
+
part.metadata.openai.reasoningEncryptedContent.length;
|
|
50
|
+
}
|
|
51
|
+
else if (part.metadata?.anthropic?.signature) {
|
|
52
|
+
encryptedContentLength = part.metadata.anthropic.signature.length;
|
|
53
|
+
}
|
|
54
|
+
else if (part.metadata?.google?.thoughtSignature) {
|
|
55
|
+
encryptedContentLength =
|
|
56
|
+
part.metadata.google.thoughtSignature.length;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
type: "reasoning",
|
|
60
|
+
text: part.text,
|
|
61
|
+
textLength: part.text?.length || 0,
|
|
62
|
+
encryptedContentLength,
|
|
63
|
+
...(part.time && { time: part.time }),
|
|
64
|
+
...(part.metadata && { metadataKeys: Object.keys(part.metadata) }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (part.type === "tool") {
|
|
68
|
+
const callIDLower = part.callID?.toLowerCase();
|
|
69
|
+
const isAlreadyPruned = prunedIdsSet.has(callIDLower);
|
|
70
|
+
const isProtected = protectedIdsSet.has(callIDLower);
|
|
71
|
+
let displayCallID = part.callID;
|
|
72
|
+
if (isAlreadyPruned) {
|
|
73
|
+
displayCallID = "<already-pruned>";
|
|
74
|
+
}
|
|
75
|
+
else if (isProtected) {
|
|
76
|
+
displayCallID = "<protected>";
|
|
77
|
+
}
|
|
78
|
+
const toolPart = {
|
|
79
|
+
type: "tool",
|
|
80
|
+
toolCallID: displayCallID,
|
|
81
|
+
tool: part.tool,
|
|
82
|
+
};
|
|
83
|
+
if (part.state?.output) {
|
|
84
|
+
toolPart.output = part.state.output;
|
|
85
|
+
}
|
|
86
|
+
if (part.state?.input) {
|
|
87
|
+
const input = part.state.input;
|
|
88
|
+
if (input.filePath &&
|
|
89
|
+
(part.tool === "write" ||
|
|
90
|
+
part.tool === "edit" ||
|
|
91
|
+
part.tool === "multiedit" ||
|
|
92
|
+
part.tool === "patch")) {
|
|
93
|
+
toolPart.input = input;
|
|
94
|
+
}
|
|
95
|
+
else if (input.filePath) {
|
|
96
|
+
toolPart.input = { filePath: input.filePath };
|
|
97
|
+
}
|
|
98
|
+
else if (input.tool_calls && Array.isArray(input.tool_calls)) {
|
|
99
|
+
toolPart.input = {
|
|
100
|
+
batch_summary: `${input.tool_calls.length} tool calls`,
|
|
101
|
+
tools: input.tool_calls.map((tc) => tc.tool),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
toolPart.input = input;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return toolPart;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
})
|
|
112
|
+
.filter(Boolean);
|
|
113
|
+
}
|
|
114
|
+
return minimized;
|
|
115
|
+
})
|
|
116
|
+
.filter((msg) => {
|
|
117
|
+
return msg.parts && msg.parts.length > 0;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
export function buildAnalysisPrompt(unprunedToolCallIds, messages, alreadyPrunedIds, protectedToolCallIds) {
|
|
121
|
+
const minimizedMessages = minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds);
|
|
122
|
+
const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, "\n");
|
|
123
|
+
return loadPrompt("on-idle-analysis", {
|
|
124
|
+
available_tool_call_ids: unprunedToolCallIds.join(", "),
|
|
125
|
+
session_history: messagesJson,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +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,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C,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Discards tool outputs from context to manage conversation size and reduce noise.
|
|
2
|
+
|
|
3
|
+
## IMPORTANT: The Prunable List
|
|
4
|
+
A `<prunable-tools>` list is 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
|
+
|
|
6
|
+
## When to Use This Tool
|
|
7
|
+
|
|
8
|
+
Use `discard` for removing tool content that is no longer needed
|
|
9
|
+
|
|
10
|
+
- **Noise:** Irrelevant, unhelpful, or superseded outputs that provide no value.
|
|
11
|
+
- **Task Completion:** Work is complete and there's no valuable information worth preserving.
|
|
12
|
+
|
|
13
|
+
## When NOT to Use This Tool
|
|
14
|
+
|
|
15
|
+
- **If the output contains useful information:** Use `extract` instead to preserve key findings.
|
|
16
|
+
- **If you'll need the output later:** Don't discard files you plan to edit or context you'll need for implementation.
|
|
17
|
+
|
|
18
|
+
## Best Practices
|
|
19
|
+
- **Strategic Batching:** Don't discard single small tool outputs (like short bash commands) unless they are pure noise. Wait until you have several items to perform high-impact discards.
|
|
20
|
+
- **Think ahead:** Before discarding, ask: "Will I need this output for an upcoming task?" If yes, keep it.
|
|
21
|
+
|
|
22
|
+
## Format
|
|
23
|
+
|
|
24
|
+
- `ids`: Array where the first element is the reason, followed by numeric IDs from the `<prunable-tools>` list
|
|
25
|
+
|
|
26
|
+
Reasons: `noise` | `completion`
|
|
27
|
+
|
|
28
|
+
## Example
|
|
29
|
+
|
|
30
|
+
<example_noise>
|
|
31
|
+
Assistant: [Reads 'wrong_file.ts']
|
|
32
|
+
This file isn't relevant to the auth system. I'll remove it to clear the context.
|
|
33
|
+
[Uses discard with ids: ["noise", "5"]]
|
|
34
|
+
</example_noise>
|
|
35
|
+
|
|
36
|
+
<example_completion>
|
|
37
|
+
Assistant: [Runs tests, they pass]
|
|
38
|
+
The tests passed and I don't need to preserve any details. I'll clean up now.
|
|
39
|
+
[Uses discard with ids: ["completion", "20", "21"]]
|
|
40
|
+
</example_completion>
|
|
41
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Extracts key findings from tool outputs into distilled knowledge, then removes the raw outputs from context.
|
|
2
|
+
|
|
3
|
+
## IMPORTANT: The Prunable List
|
|
4
|
+
A `<prunable-tools>` list is 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
|
+
|
|
6
|
+
## When to Use This Tool
|
|
7
|
+
|
|
8
|
+
Use `extract` when you have gathered useful information that you want to **preserve in distilled form** before removing the raw outputs:
|
|
9
|
+
|
|
10
|
+
- **Task Completion:** You completed a unit of work and want to preserve key findings.
|
|
11
|
+
- **Knowledge Preservation:** You have context that contains valuable information, but also a lot of unnecessary detail - you only need to preserve some specifics.
|
|
12
|
+
|
|
13
|
+
## When NOT to Use This Tool
|
|
14
|
+
|
|
15
|
+
- **If you need precise syntax:** If you'll edit a file or grep for exact strings, keep the raw output.
|
|
16
|
+
- **If uncertain:** Prefer keeping over re-fetching.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Best Practices
|
|
20
|
+
- **Strategic Batching:** Wait until you have several items or a few large outputs to extract, rather than doing tiny, frequent extractions. Aim for high-impact extractions that significantly reduce context size.
|
|
21
|
+
- **Think ahead:** Before extracting, ask: "Will I need the raw output for an upcoming task?" If you researched a file you'll later edit, do NOT extract it.
|
|
22
|
+
|
|
23
|
+
## Format
|
|
24
|
+
|
|
25
|
+
- `ids`: Array of numeric IDs as strings from the `<prunable-tools>` list
|
|
26
|
+
- `distillation`: Array of strings, one per ID (positional: distillation[0] is for ids[0], etc.)
|
|
27
|
+
|
|
28
|
+
Each distillation string should capture the essential information you need to preserve - function signatures, logic, constraints, values, etc. Be as detailed as needed for your task.
|
|
29
|
+
|
|
30
|
+
## Example
|
|
31
|
+
|
|
32
|
+
<example_extraction>
|
|
33
|
+
Assistant: [Reads auth service and user types]
|
|
34
|
+
I'll preserve the key details before extracting.
|
|
35
|
+
[Uses extract with:
|
|
36
|
+
ids: ["10", "11"],
|
|
37
|
+
distillation: [
|
|
38
|
+
"auth.ts: validateToken(token: string) -> User|null checks cache first (5min TTL) then OIDC. hashPassword uses bcrypt 12 rounds. Tokens must be 128+ chars.",
|
|
39
|
+
"user.ts: interface User { id: string; email: string; permissions: ('read'|'write'|'admin')[]; status: 'active'|'suspended' }"
|
|
40
|
+
]
|
|
41
|
+
]
|
|
42
|
+
</example_extraction>
|
|
43
|
+
|
|
44
|
+
<example_keep>
|
|
45
|
+
Assistant: [Reads 'auth.ts' to understand the login flow]
|
|
46
|
+
I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than extracting.
|
|
47
|
+
</example_keep>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
You are a conversation analyzer that identifies obsolete tool outputs in a coding session.
|
|
2
|
+
|
|
3
|
+
Your task: Analyze the session history and identify tool call IDs whose outputs are NO LONGER RELEVANT to the current conversation context.
|
|
4
|
+
|
|
5
|
+
Guidelines for identifying obsolete tool calls:
|
|
6
|
+
1. Exploratory reads that didn't lead to actual edits or meaningful discussion AND were not explicitly requested to be retained
|
|
7
|
+
2. Tool outputs from debugging/fixing an error that has now been resolved
|
|
8
|
+
3. Failed or incorrect tool attempts that were immediately corrected (e.g., reading a file from the wrong path, then reading from the correct path)
|
|
9
|
+
|
|
10
|
+
DO NOT prune:
|
|
11
|
+
- Tool calls whose outputs are actively being discussed
|
|
12
|
+
- Tool calls that produced errors still being debugged
|
|
13
|
+
- Tool calls that are the MOST RECENT activity in the conversation (these may be intended for future use)
|
|
14
|
+
|
|
15
|
+
IMPORTANT: Available tool call IDs for analysis: {{available_tool_call_ids}}
|
|
16
|
+
|
|
17
|
+
The session history below may contain tool calls with IDs not in the available list above, these cannot be pruned. These are either:
|
|
18
|
+
1. Protected tools (marked with toolCallID "<protected>")
|
|
19
|
+
2. Already-pruned tools (marked with toolCallID "<already-pruned>")
|
|
20
|
+
|
|
21
|
+
ONLY return IDs from the available list above.
|
|
22
|
+
|
|
23
|
+
Session history (each tool call has a "toolCallID" field):
|
|
24
|
+
{{session_history}}
|
|
25
|
+
|
|
26
|
+
You MUST respond with valid JSON matching this exact schema:
|
|
27
|
+
{
|
|
28
|
+
"pruned_tool_call_ids": ["id1", "id2", ...],
|
|
29
|
+
"reasoning": "explanation of why these IDs were selected"
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<instruction name=context_management_required>
|
|
2
|
+
**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required.
|
|
3
|
+
|
|
4
|
+
**Immediate Actions Required:**
|
|
5
|
+
1. **Task Completion:** If a sub-task is complete, decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping.
|
|
6
|
+
2. **Noise Removal:** If you read files or ran commands that yielded no value, use `discard` to remove them.
|
|
7
|
+
3. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use `extract` to distill the insights and remove the raw entry.
|
|
8
|
+
|
|
9
|
+
**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must perform context management.
|
|
10
|
+
</instruction>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<instruction name=context_management_required>
|
|
2
|
+
**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required.
|
|
3
|
+
|
|
4
|
+
**Immediate Actions Required:**
|
|
5
|
+
1. **Task Completion:** If a sub-task is complete, use the `discard` tool to remove the tools used.
|
|
6
|
+
2. **Noise Removal:** If you read files or ran commands that yielded no value, use the `discard` tool to remove them.
|
|
7
|
+
|
|
8
|
+
**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must discard unneeded tool outputs.
|
|
9
|
+
</instruction>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<instruction name=context_management_required>
|
|
2
|
+
**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required.
|
|
3
|
+
|
|
4
|
+
**Immediate Actions Required:**
|
|
5
|
+
1. **Task Completion:** If you have completed work, extract key findings from the tools used. Scale distillation depth to the value of the content.
|
|
6
|
+
2. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry.
|
|
7
|
+
|
|
8
|
+
**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract valuable findings from tool outputs.
|
|
9
|
+
</instruction>
|