@cjhyy/code-shell 0.1.0-alpha.3 → 0.1.6
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/CHANGELOG.md +107 -0
- package/dist/anthropic-IBTI4WL2.cjs +10 -0
- package/dist/anthropic-PRZZKHEZ.js +10 -0
- package/dist/arena/index.cjs +7 -6
- package/dist/arena/index.js +6 -5
- package/dist/arena/model-presets.d.ts +10 -1
- package/dist/{arena-ENHBHB2W.js → arena-2LTLIXOL.js} +9 -7
- package/dist/{arena-HHDYYVHJ.cjs → arena-ADB7DRFI.cjs} +25 -23
- package/dist/{chunk-EL2RL5DG.cjs → chunk-2YW4FPFG.cjs} +2 -2
- package/dist/chunk-3OA5G4TM.js +47 -0
- package/dist/{chunk-FPFTIKEJ.js → chunk-3QO25N6E.js} +131 -173
- package/dist/chunk-3SBSUOWZ.js +447 -0
- package/dist/chunk-52LGZKT3.cjs +47 -0
- package/dist/{chunk-KOGV6PDQ.cjs → chunk-55XGPMAP.cjs} +44 -9
- package/dist/{chunk-YD7XTI7T.cjs → chunk-6QVAYW7C.cjs} +116 -28
- package/dist/{chunk-SCDKLTN3.js → chunk-6S4BJ65N.js} +5 -4
- package/dist/{chunk-ZLPJJZUW.js → chunk-76HYEPDM.js} +2 -2
- package/dist/chunk-7BI3V74Y.cjs +447 -0
- package/dist/{chunk-GZBD6QRS.cjs → chunk-7EG3V4JY.cjs} +13 -12
- package/dist/{chunk-LMEKCQX4.js → chunk-7JVTYEEC.js} +6 -6
- package/dist/{chunk-SW3L7HIM.js → chunk-7QIM3BKD.js} +2 -2
- package/dist/{chunk-5C5HIOML.js → chunk-7Y6S3OCX.js} +109 -21
- package/dist/{chunk-REFCCVDM.js → chunk-ABRRONJ7.js} +2 -2
- package/dist/{chunk-F5BS3GUC.js → chunk-BSW22MPA.js} +39 -4
- package/dist/{chunk-ZRVPCXI7.js → chunk-BXCY2FSE.js} +2 -1
- package/dist/{chunk-Y7TSCDF6.js → chunk-BZ5TNE7L.js} +347 -6
- package/dist/{chunk-X2DNIMPC.cjs → chunk-DDB6QOKJ.cjs} +32 -32
- package/dist/{chunk-C7C7ZZY4.cjs → chunk-HEKQCI7B.cjs} +10 -10
- package/dist/{chunk-JHNCK7JP.cjs → chunk-IK4EWJBP.cjs} +4 -3
- package/dist/{chunk-3CAZIWUA.cjs → chunk-ILHE7XLT.cjs} +9 -9
- package/dist/{chunk-M2QI5X3X.cjs → chunk-JMR33QVF.cjs} +2 -2
- package/dist/{chunk-TDXBHD24.js → chunk-KAQHULYN.js} +2 -2
- package/dist/chunk-KE4EQOWA.js +294 -0
- package/dist/{chunk-YAFCN7ZW.cjs → chunk-KOVYSDHZ.cjs} +15 -15
- package/dist/{chunk-IJSHQGMP.cjs → chunk-KS3RYAYL.cjs} +4 -4
- package/dist/{chunk-DI7RDLOS.js → chunk-MD32R22I.js} +7 -4
- package/dist/chunk-MV7YI4WO.cjs +293 -0
- package/dist/chunk-MY5XHADU.cjs +216 -0
- package/dist/{chunk-OP57WUWQ.cjs → chunk-NUNC3VFB.cjs} +6 -6
- package/dist/{chunk-ID6EJUHP.js → chunk-PKGRTCCY.js} +1307 -212
- package/dist/{chunk-OUC2DFA7.js → chunk-QARL3IDQ.js} +3 -3
- package/dist/{chunk-VIPLU4RY.cjs → chunk-S754JHLR.cjs} +4 -4
- package/dist/{chunk-FUOKLKR2.js → chunk-SFXHZSRF.js} +1 -1
- package/dist/{chunk-2EUAE7AY.js → chunk-SIHHIQLO.js} +2 -2
- package/dist/{chunk-SK62UVS6.js → chunk-T6VYG46N.js} +1 -1
- package/dist/{chunk-JHXNOB5G.cjs → chunk-TNLGBJYS.cjs} +6 -6
- package/dist/{chunk-3QR52LL5.cjs → chunk-TUY2T5KP.cjs} +2 -2
- package/dist/{chunk-VWFET3MG.cjs → chunk-UXOCVJJ6.cjs} +1519 -424
- package/dist/{chunk-I57ZD5IQ.js → chunk-VIAGTYYW.js} +1 -1
- package/dist/chunk-WASS5YWB.js +215 -0
- package/dist/{chunk-HOXQLX5R.cjs → chunk-WZJV6DJC.cjs} +444 -103
- package/dist/{chunk-BUJ5KYCI.cjs → chunk-YIQBXAYU.cjs} +13 -13
- package/dist/{chunk-BF4LXLQV.cjs → chunk-YKIAELDZ.cjs} +132 -174
- package/dist/{chunk-M2SVOKC6.js → chunk-ZBPSQCPU.js} +6 -6
- package/dist/cli/commands/builtin/export-md.d.ts +19 -0
- package/dist/cli/commands/builtin/init/detect.d.ts +25 -0
- package/dist/cli/commands/builtin/init/index.d.ts +19 -0
- package/dist/cli/main.cjs +2372 -1453
- package/dist/cli/main.js +2502 -1583
- package/dist/cli/migrate-models.d.ts +45 -0
- package/dist/cli/onboarding.d.ts +110 -5
- package/dist/cli/updater.d.ts +59 -4
- package/dist/client-base-HTF236ZD.cjs +9 -0
- package/dist/client-base-QKRKCOWB.js +9 -0
- package/dist/{compaction-YNWCEF7B.js → compaction-6VU2T643.js} +4 -2
- package/dist/compaction-OKUNTCA7.cjs +33 -0
- package/dist/context/compaction.d.ts +35 -3
- package/dist/context/manager.d.ts +40 -3
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/devtools-T2NIZBJK.cjs +6 -0
- package/dist/{devtools-IRQQPIRY.js → devtools-YXWHOVKR.js} +1 -1
- package/dist/engine/engine.d.ts +47 -0
- package/dist/engine/turn-loop.d.ts +6 -0
- package/dist/export-md-RXDW6F5W.cjs +135 -0
- package/dist/export-md-XXKZANW5.js +135 -0
- package/dist/file-history-KYPE3ECT.cjs +7 -0
- package/dist/file-history-LF4F7X26.js +7 -0
- package/dist/index.cjs +42 -22
- package/dist/index.d.ts +5 -2
- package/dist/index.js +38 -18
- package/dist/llm/client-base.d.ts +1 -1
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-pool.d.ts +13 -0
- package/dist/llm/provider-catalog.d.ts +30 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/types.d.ts +8 -0
- package/dist/logging/session-recorder.d.ts +77 -0
- package/dist/manager-D65VFAPX.js +7 -0
- package/dist/manager-TTF5VHJC.cjs +7 -0
- package/dist/mcp-manager-QMKWPBZ4.js +8 -0
- package/dist/mcp-manager-Z3OKI74O.cjs +8 -0
- package/dist/memory-5LWZ6FI2.cjs +9 -0
- package/dist/{memory-EPFDBPII.js → memory-VIJLBAMQ.js} +2 -2
- package/dist/model-cache-5KIYL5SL.js +13 -0
- package/dist/model-cache-OED3IM4R.cjs +13 -0
- package/dist/model-fetcher-HKGICACL.js +8 -0
- package/dist/model-fetcher-UR6WJOQP.cjs +8 -0
- package/dist/openai-JR2WEKOF.js +10 -0
- package/dist/openai-YBTOET4O.cjs +10 -0
- package/dist/{openrouter-models-2FM3H4SQ.js → openrouter-models-H56GHBHN.js} +2 -2
- package/dist/openrouter-models-TWUFWZ5T.cjs +15 -0
- package/dist/openrouter-sync-5VMGN6C2.cjs +11 -0
- package/dist/{openrouter-sync-SO3AWEAM.js → openrouter-sync-ALEMF5IU.js} +3 -3
- package/dist/product/index.cjs +17 -15
- package/dist/product/index.js +16 -14
- package/dist/protocol/server.d.ts +3 -1
- package/dist/protocol/types.d.ts +36 -2
- package/dist/run/index.cjs +17 -15
- package/dist/run/index.js +16 -14
- package/dist/services/index.d.ts +0 -1
- package/dist/session-manager-Q22BBMD3.js +8 -0
- package/dist/session-manager-XODQVL3C.cjs +8 -0
- package/dist/settings/schema.d.ts +267 -42
- package/dist/{tool-summary-RYNR4DDB.cjs → tool-summary-63DPIS7G.cjs} +4 -4
- package/dist/{tool-summary-2RUFL5QK.js → tool-summary-NP5CDBKG.js} +2 -2
- package/dist/tool-system/builtin/ask-user.d.ts +9 -1
- package/dist/tool-system/context.d.ts +31 -2
- package/dist/tool-system/executor.d.ts +4 -0
- package/dist/tool-system/investigation-guard.d.ts +46 -0
- package/dist/types.d.ts +13 -2
- package/dist/ui/components/AskUserPrompt.d.ts +8 -1
- package/dist/ui/components/DiffLine.d.ts +33 -0
- package/dist/ui/components/ModelManager.d.ts +34 -1
- package/dist/ui/components/OnboardingPrompt.d.ts +10 -1
- package/dist/ui/components/ProviderModelFlow.d.ts +58 -0
- package/dist/ui/components/UpdateBanner.d.ts +1 -0
- package/dist/updater-I7QBW4DP.cjs +17 -0
- package/dist/updater-NVME5S3Z.js +17 -0
- package/dist/utils/semver.d.ts +1 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/package.json +2 -1
- package/skills-builtin/codeshell-help.md +135 -0
- package/dist/anthropic-P5VETAFI.cjs +0 -10
- package/dist/anthropic-W2GU3D76.js +0 -10
- package/dist/chunk-75E4BBFC.js +0 -224
- package/dist/chunk-FV2ARONZ.cjs +0 -224
- package/dist/client-base-TOVE25FA.js +0 -9
- package/dist/client-base-VDDIADAC.cjs +0 -9
- package/dist/compaction-D3KV2NWY.cjs +0 -31
- package/dist/devtools-WTC3NFNE.cjs +0 -6
- package/dist/file-history-HZWO2WQ5.js +0 -7
- package/dist/file-history-UQQILIY7.cjs +0 -7
- package/dist/manager-FWLOVEEK.cjs +0 -7
- package/dist/manager-GEXJLOIS.js +0 -7
- package/dist/mcp-manager-37GQLFGX.js +0 -8
- package/dist/mcp-manager-U77NEXBY.cjs +0 -8
- package/dist/memory-ADGOWADP.cjs +0 -9
- package/dist/openai-RXU5URYI.js +0 -10
- package/dist/openai-SQW4H2K4.cjs +0 -10
- package/dist/openrouter-models-PLCWZZYE.cjs +0 -15
- package/dist/openrouter-sync-K2WK3A2A.cjs +0 -11
- package/dist/services/compact.d.ts +0 -56
- package/dist/session-manager-HRSKENKB.cjs +0 -8
- package/dist/session-manager-NEKFEHF3.js +0 -8
- package/dist/updater-J7L7R6BY.cjs +0 -185
- package/dist/updater-LDBNYCAO.js +0 -185
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk2YW4FPFGcjs = require('./chunk-2YW4FPFG.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkIK4EWJBPcjs = require('./chunk-IK4EWJBP.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
12
12
|
|
|
13
13
|
// src/llm/client-base.ts
|
|
14
|
-
|
|
14
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
15
15
|
var LLMClientBase = (_class = class _LLMClientBase {
|
|
16
16
|
constructor(config) {;_class.prototype.__init.call(this);
|
|
17
17
|
this.config = config;
|
|
@@ -45,13 +45,14 @@ var LLMClientBase = (_class = class _LLMClientBase {
|
|
|
45
45
|
totalTokens: 0,
|
|
46
46
|
requestCount: 0
|
|
47
47
|
}}
|
|
48
|
-
recordUsage(usage) {
|
|
48
|
+
recordUsage(usage, options) {
|
|
49
|
+
if (_optionalChain([options, 'optionalAccess', _ => _.recordUsage]) === false) return;
|
|
49
50
|
this.usage.records.push(usage);
|
|
50
51
|
this.usage.totalPromptTokens += usage.promptTokens;
|
|
51
52
|
this.usage.totalCompletionTokens += usage.completionTokens;
|
|
52
53
|
this.usage.totalTokens += usage.totalTokens;
|
|
53
54
|
this.usage.requestCount++;
|
|
54
|
-
_optionalChain([_LLMClientBase, 'access',
|
|
55
|
+
_optionalChain([_LLMClientBase, 'access', _2 => _2.onUsage, 'optionalCall', _3 => _3(this.model, usage)]);
|
|
55
56
|
}
|
|
56
57
|
getUsage() {
|
|
57
58
|
return { ...this.usage };
|
|
@@ -64,10 +65,10 @@ var LLMClientBase = (_class = class _LLMClientBase {
|
|
|
64
65
|
return await fn();
|
|
65
66
|
} catch (err) {
|
|
66
67
|
lastError = err;
|
|
67
|
-
if (err instanceof
|
|
68
|
-
if (err instanceof
|
|
68
|
+
if (err instanceof _chunk2YW4FPFGcjs.ContextLimitError) throw err;
|
|
69
|
+
if (err instanceof _chunk2YW4FPFGcjs.LLMRateLimitError) {
|
|
69
70
|
const waitMs = (_nullishCoalesce(err.retryAfter, () => ( attempt * 2))) * 1e3;
|
|
70
|
-
|
|
71
|
+
_chunkIK4EWJBPcjs.logger.warn("llm.retry", {
|
|
71
72
|
cat: "llm",
|
|
72
73
|
provider: this.provider,
|
|
73
74
|
model: this.model,
|
|
@@ -80,7 +81,7 @@ var LLMClientBase = (_class = class _LLMClientBase {
|
|
|
80
81
|
continue;
|
|
81
82
|
}
|
|
82
83
|
if (attempt === attempts) {
|
|
83
|
-
|
|
84
|
+
_chunkIK4EWJBPcjs.logger.error("llm.exhausted", {
|
|
84
85
|
cat: "llm",
|
|
85
86
|
provider: this.provider,
|
|
86
87
|
model: this.model,
|
|
@@ -90,7 +91,7 @@ var LLMClientBase = (_class = class _LLMClientBase {
|
|
|
90
91
|
break;
|
|
91
92
|
}
|
|
92
93
|
const backoff = Math.min(1e3 * Math.pow(2, attempt - 1), 3e4);
|
|
93
|
-
|
|
94
|
+
_chunkIK4EWJBPcjs.logger.warn("llm.retry", {
|
|
94
95
|
cat: "llm",
|
|
95
96
|
provider: this.provider,
|
|
96
97
|
model: this.model,
|
|
@@ -103,7 +104,7 @@ var LLMClientBase = (_class = class _LLMClientBase {
|
|
|
103
104
|
await new Promise((r) => setTimeout(r, backoff));
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
|
-
throw _nullishCoalesce(lastError, () => ( new (0,
|
|
107
|
+
throw _nullishCoalesce(lastError, () => ( new (0, _chunk2YW4FPFGcjs.LLMError)("Unknown LLM error")));
|
|
107
108
|
}
|
|
108
109
|
}, _class);
|
|
109
110
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LLMClientBase
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6S4BJ65N.js";
|
|
4
4
|
import {
|
|
5
5
|
ContextLimitError,
|
|
6
6
|
LLMError,
|
|
7
7
|
LLMRateLimitError
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SFXHZSRF.js";
|
|
9
9
|
import {
|
|
10
10
|
logger
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-BXCY2FSE.js";
|
|
12
12
|
import {
|
|
13
13
|
init_esm_shims
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MD32R22I.js";
|
|
15
15
|
|
|
16
16
|
// src/llm/providers/openai.ts
|
|
17
17
|
init_esm_shims();
|
|
@@ -80,7 +80,7 @@ var OpenAIClient = class extends LLMClientBase {
|
|
|
80
80
|
completionTokens: response.usage?.completion_tokens ?? 0,
|
|
81
81
|
totalTokens: response.usage?.total_tokens ?? 0
|
|
82
82
|
};
|
|
83
|
-
this.recordUsage(usage);
|
|
83
|
+
this.recordUsage(usage, options);
|
|
84
84
|
return this.processChoice(choice, usage);
|
|
85
85
|
} catch (err) {
|
|
86
86
|
this.handleApiError(err);
|
|
@@ -176,7 +176,7 @@ var OpenAIClient = class extends LLMClientBase {
|
|
|
176
176
|
completionTokens: streamUsage?.completion_tokens ?? 0,
|
|
177
177
|
totalTokens: streamUsage?.total_tokens ?? 0
|
|
178
178
|
};
|
|
179
|
-
this.recordUsage(usage);
|
|
179
|
+
this.recordUsage(usage, options);
|
|
180
180
|
return {
|
|
181
181
|
text,
|
|
182
182
|
toolCalls,
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__esm,
|
|
3
3
|
__export,
|
|
4
4
|
init_esm_shims
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MD32R22I.js";
|
|
6
6
|
|
|
7
7
|
// src/context/token-counter.ts
|
|
8
8
|
function estimateStringTokens(text) {
|
|
@@ -70,6 +70,7 @@ var init_token_counter = __esm({
|
|
|
70
70
|
// src/context/compaction.ts
|
|
71
71
|
var compaction_exports = {};
|
|
72
72
|
__export(compaction_exports, {
|
|
73
|
+
COMPACTABLE_TOOL_NAMES: () => COMPACTABLE_TOOL_NAMES,
|
|
73
74
|
adjustIndexToPreserveAPIInvariants: () => adjustIndexToPreserveAPIInvariants,
|
|
74
75
|
applySummaryCompaction: () => applySummaryCompaction,
|
|
75
76
|
applyToolResultBudget: () => applyToolResultBudget,
|
|
@@ -143,35 +144,108 @@ function windowCompact(messages, keepLastN) {
|
|
|
143
144
|
if (startIndex <= 1) return messages;
|
|
144
145
|
return [messages[0], ...messages.slice(startIndex)];
|
|
145
146
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
const
|
|
147
|
+
function buildToolUseIdToNameMap(messages) {
|
|
148
|
+
const map = /* @__PURE__ */ new Map();
|
|
149
|
+
for (const msg of messages) {
|
|
150
|
+
if (!Array.isArray(msg.content)) continue;
|
|
151
|
+
for (const block of msg.content) {
|
|
152
|
+
if (block.type === "tool_use" && block.id && block.name) {
|
|
153
|
+
map.set(block.id, block.name);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return map;
|
|
158
|
+
}
|
|
159
|
+
function summarizeToolCallArgs(toolName, input) {
|
|
160
|
+
if (!input || typeof input !== "object") return "";
|
|
161
|
+
const pick = (keys) => {
|
|
162
|
+
const parts = [];
|
|
163
|
+
for (const key of keys) {
|
|
164
|
+
const v = input[key];
|
|
165
|
+
if (typeof v === "string" && v.length > 0) {
|
|
166
|
+
parts.push(`${key}=${v.length > 80 ? v.slice(0, 77) + "..." : v}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return parts.join(" ");
|
|
170
|
+
};
|
|
171
|
+
switch (toolName) {
|
|
172
|
+
case "Read":
|
|
173
|
+
case "Write":
|
|
174
|
+
case "Edit":
|
|
175
|
+
case "NotebookEdit":
|
|
176
|
+
return pick(["file_path", "path", "notebook_path"]);
|
|
177
|
+
case "Glob":
|
|
178
|
+
case "Grep":
|
|
179
|
+
return pick(["pattern", "path", "glob"]);
|
|
180
|
+
case "Bash":
|
|
181
|
+
case "PowerShell":
|
|
182
|
+
case "REPL":
|
|
183
|
+
return pick(["command"]);
|
|
184
|
+
case "WebFetch":
|
|
185
|
+
case "WebSearch":
|
|
186
|
+
return pick(["url", "query"]);
|
|
187
|
+
default: {
|
|
188
|
+
const json = JSON.stringify(input);
|
|
189
|
+
return json.length > 100 ? json.slice(0, 97) + "..." : json;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function microcompact(messages, options = {}) {
|
|
194
|
+
const keepRecentN = options.keepRecentN ?? 5;
|
|
195
|
+
const compactable = options.compactableTools ?? COMPACTABLE_TOOL_NAMES;
|
|
196
|
+
const idToName = buildToolUseIdToNameMap(messages);
|
|
197
|
+
const idToInput = /* @__PURE__ */ new Map();
|
|
198
|
+
for (const msg of messages) {
|
|
199
|
+
if (!Array.isArray(msg.content)) continue;
|
|
200
|
+
for (const block of msg.content) {
|
|
201
|
+
if (block.type === "tool_use" && block.id) {
|
|
202
|
+
idToInput.set(block.id, block.input);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let compactableRoundCount = 0;
|
|
207
|
+
const indicesToTouch = [];
|
|
149
208
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
150
209
|
const msg = messages[i];
|
|
151
|
-
if (Array.isArray(msg.content))
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
210
|
+
if (!Array.isArray(msg.content)) continue;
|
|
211
|
+
const hasEligible = msg.content.some(
|
|
212
|
+
(b) => b.type === "tool_result" && b.tool_use_id != null && compactable.has(idToName.get(b.tool_use_id) ?? "") && typeof b.content === "string" && !b.content.startsWith("[Old tool result cleared")
|
|
213
|
+
);
|
|
214
|
+
if (!hasEligible) continue;
|
|
215
|
+
compactableRoundCount++;
|
|
216
|
+
if (compactableRoundCount > keepRecentN) {
|
|
217
|
+
indicesToTouch.push(i);
|
|
159
218
|
}
|
|
160
219
|
}
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
220
|
+
if (indicesToTouch.length === 0) return messages;
|
|
221
|
+
const touchSet = new Set(indicesToTouch);
|
|
222
|
+
const clearedToolNames = /* @__PURE__ */ new Set();
|
|
223
|
+
let clearedBlocks = 0;
|
|
224
|
+
const result = messages.map((msg, i) => {
|
|
225
|
+
if (!touchSet.has(i) || !Array.isArray(msg.content)) return msg;
|
|
165
226
|
return {
|
|
166
227
|
...msg,
|
|
167
228
|
content: msg.content.map((block) => {
|
|
168
|
-
if (block.type
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return block;
|
|
229
|
+
if (block.type !== "tool_result" || !block.tool_use_id) return block;
|
|
230
|
+
const toolName = idToName.get(block.tool_use_id);
|
|
231
|
+
if (!toolName || !compactable.has(toolName)) return block;
|
|
232
|
+
if (typeof block.content !== "string") return block;
|
|
233
|
+
if (block.content.startsWith("[Old tool result cleared")) return block;
|
|
234
|
+
const argsSummary = summarizeToolCallArgs(toolName, idToInput.get(block.tool_use_id));
|
|
235
|
+
const fingerprint = argsSummary ? `[Old tool result cleared \u2014 ${toolName} ${argsSummary}]` : `[Old tool result cleared \u2014 ${toolName}]`;
|
|
236
|
+
clearedToolNames.add(toolName);
|
|
237
|
+
clearedBlocks++;
|
|
238
|
+
return { ...block, content: fingerprint };
|
|
172
239
|
})
|
|
173
240
|
};
|
|
174
241
|
});
|
|
242
|
+
if (clearedBlocks > 0) {
|
|
243
|
+
options.onClear?.({
|
|
244
|
+
clearedRounds: indicesToTouch.length,
|
|
245
|
+
toolNames: [...clearedToolNames].sort()
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
175
249
|
}
|
|
176
250
|
function applyToolResultBudget(messages, maxTotalChars = 1e5) {
|
|
177
251
|
return messages.map((msg) => {
|
|
@@ -200,9 +274,10 @@ function applyToolResultBudget(messages, maxTotalChars = 1e5) {
|
|
|
200
274
|
const newContent = msg.content.map((block, i) => {
|
|
201
275
|
if (!toTruncate.has(i)) return block;
|
|
202
276
|
const preview = typeof block.content === "string" ? block.content.slice(0, 500) : "";
|
|
277
|
+
const sizeKb = (block.content.length / 1e3).toFixed(0);
|
|
203
278
|
return {
|
|
204
279
|
...block,
|
|
205
|
-
content: `Output too large (${
|
|
280
|
+
content: `Output too large (${sizeKb}KB) \u2014 truncated to fit the per-message budget. Re-run the originating tool if you need the full output.
|
|
206
281
|
|
|
207
282
|
Preview (first 500 chars):
|
|
208
283
|
${preview}`
|
|
@@ -325,10 +400,22 @@ function extractReferencedFilePaths(messages) {
|
|
|
325
400
|
}
|
|
326
401
|
return [...paths];
|
|
327
402
|
}
|
|
403
|
+
var COMPACTABLE_TOOL_NAMES;
|
|
328
404
|
var init_compaction = __esm({
|
|
329
405
|
"src/context/compaction.ts"() {
|
|
330
406
|
init_esm_shims();
|
|
331
407
|
init_token_counter();
|
|
408
|
+
COMPACTABLE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
409
|
+
"Read",
|
|
410
|
+
"Glob",
|
|
411
|
+
"Grep",
|
|
412
|
+
"Bash",
|
|
413
|
+
"PowerShell",
|
|
414
|
+
"NotebookEdit",
|
|
415
|
+
"WebFetch",
|
|
416
|
+
"WebSearch",
|
|
417
|
+
"REPL"
|
|
418
|
+
]);
|
|
332
419
|
}
|
|
333
420
|
});
|
|
334
421
|
|
|
@@ -337,6 +424,7 @@ export {
|
|
|
337
424
|
adjustIndexToPreserveAPIInvariants,
|
|
338
425
|
snipCompact,
|
|
339
426
|
windowCompact,
|
|
427
|
+
COMPACTABLE_TOOL_NAMES,
|
|
340
428
|
microcompact,
|
|
341
429
|
applyToolResultBudget,
|
|
342
430
|
truncateToolResult,
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
NoopEvaluator,
|
|
5
5
|
RunManager,
|
|
6
6
|
registerPreset
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PKGRTCCY.js";
|
|
8
8
|
import {
|
|
9
9
|
init_esm_shims
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-MD32R22I.js";
|
|
11
11
|
|
|
12
12
|
// src/product/index.ts
|
|
13
13
|
init_esm_shims();
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readCache
|
|
3
|
+
} from "./chunk-3OA5G4TM.js";
|
|
1
4
|
import {
|
|
2
5
|
init_esm_shims
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MD32R22I.js";
|
|
4
7
|
|
|
5
8
|
// src/llm/model-pool.ts
|
|
6
9
|
init_esm_shims();
|
|
@@ -18,6 +21,32 @@ function lookupBuiltinContextWindow(model) {
|
|
|
18
21
|
var ModelPool = class {
|
|
19
22
|
models = /* @__PURE__ */ new Map();
|
|
20
23
|
activeKey;
|
|
24
|
+
providerCatalog;
|
|
25
|
+
cacheDir;
|
|
26
|
+
setProviderCatalog(cat) {
|
|
27
|
+
this.providerCatalog = cat;
|
|
28
|
+
}
|
|
29
|
+
setCacheDir(dir) {
|
|
30
|
+
this.cacheDir = dir;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* For each entry in the pool that lacks an explicit maxContextTokens
|
|
34
|
+
* but has a providerKey, look up the contextLength from the cached
|
|
35
|
+
* model list and patch it in.
|
|
36
|
+
*/
|
|
37
|
+
reloadCachedContextWindows() {
|
|
38
|
+
if (!this.cacheDir) return;
|
|
39
|
+
for (const [key, entry] of this.models) {
|
|
40
|
+
if (entry.maxContextTokens != null) continue;
|
|
41
|
+
if (!entry.providerKey) continue;
|
|
42
|
+
const file = readCache(this.cacheDir, entry.providerKey);
|
|
43
|
+
if (!file) continue;
|
|
44
|
+
const match = file.models.find((m) => m.id === entry.model);
|
|
45
|
+
if (match?.contextLength) {
|
|
46
|
+
this.models.set(key, { ...entry, maxContextTokens: match.contextLength });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
21
50
|
/**
|
|
22
51
|
* Build a pool from an array of model entries.
|
|
23
52
|
* The first entry (or the one matching `defaultKey`) becomes active.
|
|
@@ -85,11 +114,17 @@ var ModelPool = class {
|
|
|
85
114
|
* (inherits apiKey, baseUrl, etc. from the base if not set on the entry).
|
|
86
115
|
*/
|
|
87
116
|
toLLMConfig(entry, base) {
|
|
117
|
+
const fromCat = entry.providerKey && this.providerCatalog ? this.providerCatalog.get(entry.providerKey) : void 0;
|
|
118
|
+
const kindToClientProvider = (kind) => {
|
|
119
|
+
if (!kind) return "openai";
|
|
120
|
+
if (kind === "anthropic") return "anthropic";
|
|
121
|
+
return "openai";
|
|
122
|
+
};
|
|
88
123
|
return {
|
|
89
|
-
provider: entry.provider,
|
|
124
|
+
provider: entry.provider || kindToClientProvider(fromCat?.kind) || "openai",
|
|
90
125
|
model: entry.model,
|
|
91
|
-
apiKey: entry.apiKey ?? base?.apiKey,
|
|
92
|
-
baseUrl: entry.baseUrl ?? base?.baseUrl,
|
|
126
|
+
apiKey: entry.apiKey ?? fromCat?.apiKey ?? base?.apiKey,
|
|
127
|
+
baseUrl: entry.baseUrl ?? fromCat?.baseUrl ?? base?.baseUrl,
|
|
93
128
|
temperature: base?.temperature ?? 0.3,
|
|
94
129
|
maxTokens: entry.maxOutputTokens ?? base?.maxTokens ?? 8192,
|
|
95
130
|
enableStreaming: base?.enableStreaming ?? true
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_esm_shims
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MD32R22I.js";
|
|
4
4
|
|
|
5
5
|
// src/logging/logger.ts
|
|
6
6
|
init_esm_shims();
|
|
@@ -197,6 +197,7 @@ function rotateLogs() {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
export {
|
|
200
|
+
getCurrentSid,
|
|
200
201
|
logger,
|
|
201
202
|
rotateLogs
|
|
202
203
|
};
|