@codelia/runtime 0.1.65 → 0.1.67
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/dist/index.cjs +762 -522
- package/dist/index.js +724 -481
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
var import_node_path20 = __toESM(require("path"), 1);
|
|
27
27
|
var import_storage14 = require("@codelia/storage");
|
|
28
28
|
|
|
29
|
+
// src/agent-factory.ts
|
|
30
|
+
var import_node_fs15 = require("fs");
|
|
31
|
+
var import_core21 = require("@codelia/core");
|
|
32
|
+
var import_model_metadata2 = require("@codelia/model-metadata");
|
|
33
|
+
var import_shared_types2 = require("@codelia/shared-types");
|
|
34
|
+
var import_storage8 = require("@codelia/storage");
|
|
35
|
+
|
|
29
36
|
// src/agents/context.ts
|
|
30
37
|
var createAgentsResolverKey = (resolver) => ({
|
|
31
38
|
id: "agents-resolver",
|
|
@@ -387,13 +394,6 @@ var appendInitialAgentsContext = (systemPrompt, agentsContext) => {
|
|
|
387
394
|
${agentsContext}`;
|
|
388
395
|
};
|
|
389
396
|
|
|
390
|
-
// src/agent-factory.ts
|
|
391
|
-
var import_node_fs15 = require("fs");
|
|
392
|
-
var import_core20 = require("@codelia/core");
|
|
393
|
-
var import_model_metadata2 = require("@codelia/model-metadata");
|
|
394
|
-
var import_shared_types2 = require("@codelia/shared-types");
|
|
395
|
-
var import_storage8 = require("@codelia/storage");
|
|
396
|
-
|
|
397
397
|
// src/auth/oauth-utils.ts
|
|
398
398
|
var import_node_http = require("http");
|
|
399
399
|
var oauth = __toESM(require("oauth4webapi"), 1);
|
|
@@ -808,6 +808,7 @@ var resolveModelConfig = async (workingDir) => {
|
|
|
808
808
|
name: effective.model?.name,
|
|
809
809
|
reasoning: effective.model?.reasoning,
|
|
810
810
|
verbosity: effective.model?.verbosity,
|
|
811
|
+
fast: effective.model?.fast,
|
|
811
812
|
experimental: effective.experimental
|
|
812
813
|
};
|
|
813
814
|
};
|
|
@@ -2361,6 +2362,24 @@ var createMcpOAuthSession = async (params, options = {}) => {
|
|
|
2361
2362
|
};
|
|
2362
2363
|
};
|
|
2363
2364
|
|
|
2365
|
+
// src/model-fast.ts
|
|
2366
|
+
var import_core2 = require("@codelia/core");
|
|
2367
|
+
var resolveFastMode = (params) => {
|
|
2368
|
+
if (params.requested !== true) {
|
|
2369
|
+
return { enabled: false };
|
|
2370
|
+
}
|
|
2371
|
+
if (!(0, import_core2.supportsFastMode)(import_core2.DEFAULT_MODEL_REGISTRY, params.model, params.provider)) {
|
|
2372
|
+
return { enabled: false };
|
|
2373
|
+
}
|
|
2374
|
+
if (params.provider === "openai") {
|
|
2375
|
+
return { enabled: true, provider: "openai", serviceTier: "priority" };
|
|
2376
|
+
}
|
|
2377
|
+
if (params.provider === "anthropic") {
|
|
2378
|
+
return { enabled: true, provider: "anthropic", fastMode: true };
|
|
2379
|
+
}
|
|
2380
|
+
return { enabled: false };
|
|
2381
|
+
};
|
|
2382
|
+
|
|
2364
2383
|
// src/model-reasoning.ts
|
|
2365
2384
|
var REASONING_LEVEL_ORDER = [
|
|
2366
2385
|
"low",
|
|
@@ -2392,6 +2411,15 @@ var ANTHROPIC_BUDGET_PRESET_TOKENS = {
|
|
|
2392
2411
|
};
|
|
2393
2412
|
var ANTHROPIC_MAX_TOKENS_FALLBACK_HEADROOM = 4096;
|
|
2394
2413
|
var ANTHROPIC_REASONING_MODEL_TABLE = {
|
|
2414
|
+
"claude-opus-4-7": {
|
|
2415
|
+
supportedLevels: ["low", "medium", "high", "xhigh"],
|
|
2416
|
+
budgetPresetByLevel: {
|
|
2417
|
+
low: "reasoning_low",
|
|
2418
|
+
medium: "reasoning_medium",
|
|
2419
|
+
high: "reasoning_high",
|
|
2420
|
+
xhigh: "reasoning_xhigh"
|
|
2421
|
+
}
|
|
2422
|
+
},
|
|
2395
2423
|
"claude-opus-4-6": {
|
|
2396
2424
|
supportedLevels: ["low", "medium", "high", "xhigh"],
|
|
2397
2425
|
budgetPresetByLevel: {
|
|
@@ -2463,6 +2491,8 @@ var ANTHROPIC_REASONING_MODEL_TABLE = {
|
|
|
2463
2491
|
}
|
|
2464
2492
|
}
|
|
2465
2493
|
};
|
|
2494
|
+
var ANTHROPIC_ADAPTIVE_THINKING_MODELS = /* @__PURE__ */ new Set(["claude-opus-4-7"]);
|
|
2495
|
+
var toAnthropicOutputEffort = (level) => level === "xhigh" ? "max" : level;
|
|
2466
2496
|
var normalizeRequestedReasoning = (value) => value ?? DEFAULT_REASONING_LEVEL;
|
|
2467
2497
|
var resolveNearestSupportedLevel = (requested, supportedLevels) => {
|
|
2468
2498
|
const supported = new Set(supportedLevels);
|
|
@@ -2543,9 +2573,16 @@ var resolveAnthropicReasoning = ({
|
|
|
2543
2573
|
const budgetTokens = ANTHROPIC_BUDGET_PRESET_TOKENS[preset];
|
|
2544
2574
|
return {
|
|
2545
2575
|
...resolution,
|
|
2546
|
-
|
|
2547
|
-
type: "
|
|
2548
|
-
|
|
2576
|
+
...ANTHROPIC_ADAPTIVE_THINKING_MODELS.has(model) ? {
|
|
2577
|
+
thinking: { type: "adaptive" },
|
|
2578
|
+
outputConfig: {
|
|
2579
|
+
effort: toAnthropicOutputEffort(resolution.applied)
|
|
2580
|
+
}
|
|
2581
|
+
} : {
|
|
2582
|
+
thinking: {
|
|
2583
|
+
type: "enabled",
|
|
2584
|
+
budget_tokens: budgetTokens
|
|
2585
|
+
}
|
|
2549
2586
|
},
|
|
2550
2587
|
budgetPreset: preset,
|
|
2551
2588
|
usedFallbackModelProfile
|
|
@@ -2564,7 +2601,7 @@ var resolveAnthropicMaxTokens = ({
|
|
|
2564
2601
|
};
|
|
2565
2602
|
|
|
2566
2603
|
// src/model-registry.ts
|
|
2567
|
-
var
|
|
2604
|
+
var import_core3 = require("@codelia/core");
|
|
2568
2605
|
var import_model_metadata = require("@codelia/model-metadata");
|
|
2569
2606
|
var import_storage3 = require("@codelia/storage");
|
|
2570
2607
|
var stripProviderPrefix = (provider, model) => {
|
|
@@ -2576,7 +2613,7 @@ var resolveProviderModelEntry = (providerEntries, provider, model) => {
|
|
|
2576
2613
|
return null;
|
|
2577
2614
|
}
|
|
2578
2615
|
const normalized = stripProviderPrefix(provider, model);
|
|
2579
|
-
const providerModelId = (0,
|
|
2616
|
+
const providerModelId = (0, import_core3.resolveProviderModelId)(import_core3.DEFAULT_MODEL_REGISTRY, model, provider) ?? normalized;
|
|
2580
2617
|
const providerModelNormalized = stripProviderPrefix(
|
|
2581
2618
|
provider,
|
|
2582
2619
|
providerModelId
|
|
@@ -2615,13 +2652,13 @@ var resolveDefaultRegistrySpec = (provider, model) => {
|
|
|
2615
2652
|
(value, index, array) => array.indexOf(value) === index
|
|
2616
2653
|
);
|
|
2617
2654
|
for (const candidate of candidates) {
|
|
2618
|
-
const spec = (0,
|
|
2655
|
+
const spec = (0, import_core3.resolveModel)(import_core3.DEFAULT_MODEL_REGISTRY, candidate, provider);
|
|
2619
2656
|
if (spec?.provider === provider) {
|
|
2620
2657
|
return spec;
|
|
2621
2658
|
}
|
|
2622
2659
|
}
|
|
2623
2660
|
const normalizedLower = normalized.toLowerCase();
|
|
2624
|
-
for (const spec of Object.values(
|
|
2661
|
+
for (const spec of Object.values(import_core3.DEFAULT_MODEL_REGISTRY.modelsById)) {
|
|
2625
2662
|
if (spec.provider !== provider) continue;
|
|
2626
2663
|
if (spec.id.toLowerCase() === normalizedLower) {
|
|
2627
2664
|
return spec;
|
|
@@ -2640,7 +2677,7 @@ var withOpenRouterDynamicModel = (registry, llm, entry) => {
|
|
|
2640
2677
|
const contextWindow = toPositiveInteger(entry.limits?.contextWindow) ?? toPositiveInteger(entry.limits?.inputTokens);
|
|
2641
2678
|
const maxInputTokens = toPositiveInteger(entry.limits?.inputTokens) ?? contextWindow;
|
|
2642
2679
|
const maxOutputTokens = toPositiveInteger(entry.limits?.outputTokens);
|
|
2643
|
-
if (!contextWindow && !maxInputTokens
|
|
2680
|
+
if (!contextWindow && !maxInputTokens) {
|
|
2644
2681
|
return registry;
|
|
2645
2682
|
}
|
|
2646
2683
|
const aliases = [llm.model, `${llm.provider}/${normalized}`].filter((value) => value !== normalized).filter((value, index, array) => array.indexOf(value) === index);
|
|
@@ -2653,7 +2690,7 @@ var withOpenRouterDynamicModel = (registry, llm, entry) => {
|
|
|
2653
2690
|
google: { ...registry.aliasesByProvider.google }
|
|
2654
2691
|
}
|
|
2655
2692
|
};
|
|
2656
|
-
(0,
|
|
2693
|
+
(0, import_core3.registerModels)(next, [
|
|
2657
2694
|
{
|
|
2658
2695
|
id: normalized,
|
|
2659
2696
|
provider: llm.provider,
|
|
@@ -2688,13 +2725,13 @@ var buildModelRegistry = async (llm, options = {}) => {
|
|
|
2688
2725
|
}
|
|
2689
2726
|
if (!resolvedEntry) {
|
|
2690
2727
|
const fallbackSpec = resolveDefaultRegistrySpec(llm.provider, llm.model);
|
|
2691
|
-
if (strict && !fallbackSpec) {
|
|
2728
|
+
if (strict && !(0, import_core3.isUsableModelSpec)(fallbackSpec)) {
|
|
2692
2729
|
throw new Error(
|
|
2693
|
-
`
|
|
2730
|
+
`Usable model metadata not found for ${llm.provider}/${llm.model} after refresh; add required limits to the static ModelSpec to use it without metadata`
|
|
2694
2731
|
);
|
|
2695
2732
|
}
|
|
2696
2733
|
}
|
|
2697
|
-
const baseRegistry = (0,
|
|
2734
|
+
const baseRegistry = (0, import_core3.applyModelMetadata)(import_core3.DEFAULT_MODEL_REGISTRY, {
|
|
2698
2735
|
models: entries
|
|
2699
2736
|
});
|
|
2700
2737
|
return resolvedEntry ? withOpenRouterDynamicModel(baseRegistry, llm, resolvedEntry) : baseRegistry;
|
|
@@ -4191,9 +4228,9 @@ ${skillsCatalog}`;
|
|
|
4191
4228
|
};
|
|
4192
4229
|
|
|
4193
4230
|
// src/tools/agents-resolve.ts
|
|
4194
|
-
var
|
|
4231
|
+
var import_core4 = require("@codelia/core");
|
|
4195
4232
|
var import_zod2 = require("zod");
|
|
4196
|
-
var createAgentsResolveTool = (sandboxKey, agentsResolverKey) => (0,
|
|
4233
|
+
var createAgentsResolveTool = (sandboxKey, agentsResolverKey) => (0, import_core4.defineTool)({
|
|
4197
4234
|
name: "agents_resolve",
|
|
4198
4235
|
description: "Resolve AGENTS.md files applicable to a target path (metadata only).",
|
|
4199
4236
|
input: import_zod2.z.object({
|
|
@@ -4232,7 +4269,7 @@ var createAgentsResolveTool = (sandboxKey, agentsResolverKey) => (0, import_core
|
|
|
4232
4269
|
// src/tools/apply-patch.ts
|
|
4233
4270
|
var import_node_fs7 = require("fs");
|
|
4234
4271
|
var import_node_path9 = __toESM(require("path"), 1);
|
|
4235
|
-
var
|
|
4272
|
+
var import_core5 = require("@codelia/core");
|
|
4236
4273
|
var import_zod3 = require("zod");
|
|
4237
4274
|
|
|
4238
4275
|
// src/utils/diff.ts
|
|
@@ -4965,7 +5002,7 @@ var summarizeChanges = (changes, dryRun) => {
|
|
|
4965
5002
|
files: fileSummaries
|
|
4966
5003
|
};
|
|
4967
5004
|
};
|
|
4968
|
-
var createApplyPatchTool = (sandboxKey, outputCacheStore) => (0,
|
|
5005
|
+
var createApplyPatchTool = (sandboxKey, outputCacheStore) => (0, import_core5.defineTool)({
|
|
4969
5006
|
name: "apply_patch",
|
|
4970
5007
|
description: "Apply a codex-style multi-file patch; use dry_run to preview only.",
|
|
4971
5008
|
input: import_zod3.z.object({
|
|
@@ -5001,16 +5038,16 @@ var createApplyPatchTool = (sandboxKey, outputCacheStore) => (0, import_core4.de
|
|
|
5001
5038
|
});
|
|
5002
5039
|
|
|
5003
5040
|
// src/tools/done.ts
|
|
5004
|
-
var
|
|
5041
|
+
var import_core6 = require("@codelia/core");
|
|
5005
5042
|
var import_zod4 = require("zod");
|
|
5006
|
-
var createDoneTool = () => (0,
|
|
5043
|
+
var createDoneTool = () => (0, import_core6.defineTool)({
|
|
5007
5044
|
name: "done",
|
|
5008
5045
|
description: "Mark the task as complete and return a final message.",
|
|
5009
5046
|
input: import_zod4.z.object({
|
|
5010
5047
|
message: import_zod4.z.string().describe("Final user-facing completion message.")
|
|
5011
5048
|
}),
|
|
5012
5049
|
execute: async (input) => {
|
|
5013
|
-
throw new
|
|
5050
|
+
throw new import_core6.TaskComplete(input.message);
|
|
5014
5051
|
}
|
|
5015
5052
|
});
|
|
5016
5053
|
|
|
@@ -5018,7 +5055,7 @@ var createDoneTool = () => (0, import_core5.defineTool)({
|
|
|
5018
5055
|
var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
5019
5056
|
var import_node_fs8 = require("fs");
|
|
5020
5057
|
var import_node_path10 = __toESM(require("path"), 1);
|
|
5021
|
-
var
|
|
5058
|
+
var import_core7 = require("@codelia/core");
|
|
5022
5059
|
var import_zod5 = require("zod");
|
|
5023
5060
|
var trimLine = (line) => line.replace(/\r$/, "").trim();
|
|
5024
5061
|
var lineRangeToIndices = (lines, startLine, lineCount) => {
|
|
@@ -5127,7 +5164,7 @@ var applyReplacements = (content, matches, replacement) => {
|
|
|
5127
5164
|
return next;
|
|
5128
5165
|
};
|
|
5129
5166
|
var hashContent = (content) => import_node_crypto4.default.createHash("sha256").update(content).digest("hex");
|
|
5130
|
-
var createEditTool = (sandboxKey, outputCacheStore) => (0,
|
|
5167
|
+
var createEditTool = (sandboxKey, outputCacheStore) => (0, import_core7.defineTool)({
|
|
5131
5168
|
name: "edit",
|
|
5132
5169
|
description: "Edit a file by replacing matched text with new text; supports guarded match modes and dry-run preview.",
|
|
5133
5170
|
input: import_zod5.z.object({
|
|
@@ -5265,7 +5302,7 @@ var createEditTool = (sandboxKey, outputCacheStore) => (0, import_core6.defineTo
|
|
|
5265
5302
|
});
|
|
5266
5303
|
|
|
5267
5304
|
// src/tools/lane.ts
|
|
5268
|
-
var
|
|
5305
|
+
var import_core8 = require("@codelia/core");
|
|
5269
5306
|
var import_zod6 = require("zod");
|
|
5270
5307
|
|
|
5271
5308
|
// src/lanes/manager.ts
|
|
@@ -5865,7 +5902,7 @@ var buildLaneHints = (lane) => {
|
|
|
5865
5902
|
}
|
|
5866
5903
|
};
|
|
5867
5904
|
};
|
|
5868
|
-
var createLaneCreateTool = (sandboxKey) => (0,
|
|
5905
|
+
var createLaneCreateTool = (sandboxKey) => (0, import_core8.defineTool)({
|
|
5869
5906
|
name: "lane_create",
|
|
5870
5907
|
description: "Create a Task lane (worktree slot) and start autonomous execution in tmux/zellij.",
|
|
5871
5908
|
input: import_zod6.z.object({
|
|
@@ -5900,7 +5937,7 @@ var createLaneCreateTool = (sandboxKey) => (0, import_core7.defineTool)({
|
|
|
5900
5937
|
}
|
|
5901
5938
|
}
|
|
5902
5939
|
});
|
|
5903
|
-
var createLaneListTool = (sandboxKey) => (0,
|
|
5940
|
+
var createLaneListTool = (sandboxKey) => (0, import_core8.defineTool)({
|
|
5904
5941
|
name: "lane_list",
|
|
5905
5942
|
description: "List Task lanes (worktree slots) and current states.",
|
|
5906
5943
|
input: import_zod6.z.object({
|
|
@@ -5924,7 +5961,7 @@ var createLaneListTool = (sandboxKey) => (0, import_core7.defineTool)({
|
|
|
5924
5961
|
}
|
|
5925
5962
|
}
|
|
5926
5963
|
});
|
|
5927
|
-
var createLaneStatusTool = (sandboxKey) => (0,
|
|
5964
|
+
var createLaneStatusTool = (sandboxKey) => (0, import_core8.defineTool)({
|
|
5928
5965
|
name: "lane_status",
|
|
5929
5966
|
description: "Get Task lane status and backend liveness.",
|
|
5930
5967
|
input: import_zod6.z.object({
|
|
@@ -5943,7 +5980,7 @@ var createLaneStatusTool = (sandboxKey) => (0, import_core7.defineTool)({
|
|
|
5943
5980
|
}
|
|
5944
5981
|
}
|
|
5945
5982
|
});
|
|
5946
|
-
var createLaneCloseTool = (sandboxKey) => (0,
|
|
5983
|
+
var createLaneCloseTool = (sandboxKey) => (0, import_core8.defineTool)({
|
|
5947
5984
|
name: "lane_close",
|
|
5948
5985
|
description: "Close a Task lane and optionally remove its worktree.",
|
|
5949
5986
|
input: import_zod6.z.object({
|
|
@@ -5968,7 +6005,7 @@ var createLaneCloseTool = (sandboxKey) => (0, import_core7.defineTool)({
|
|
|
5968
6005
|
}
|
|
5969
6006
|
}
|
|
5970
6007
|
});
|
|
5971
|
-
var createLaneGcTool = (sandboxKey) => (0,
|
|
6008
|
+
var createLaneGcTool = (sandboxKey) => (0, import_core8.defineTool)({
|
|
5972
6009
|
name: "lane_gc",
|
|
5973
6010
|
description: "Close stale finished/error lanes after idle TTL.",
|
|
5974
6011
|
input: import_zod6.z.object({
|
|
@@ -5992,7 +6029,7 @@ var createLaneGcTool = (sandboxKey) => (0, import_core7.defineTool)({
|
|
|
5992
6029
|
|
|
5993
6030
|
// src/tools/read.ts
|
|
5994
6031
|
var import_node_fs11 = require("fs");
|
|
5995
|
-
var
|
|
6032
|
+
var import_core9 = require("@codelia/core");
|
|
5996
6033
|
var import_zod7 = require("zod");
|
|
5997
6034
|
var DEFAULT_READ_LIMIT = 2e3;
|
|
5998
6035
|
var DEFAULT_MAX_LINE_LENGTH = 1e3;
|
|
@@ -6047,7 +6084,7 @@ var buildTruncatedLinesSummary = (lineNumbers) => {
|
|
|
6047
6084
|
}
|
|
6048
6085
|
return `[truncated lines: ${lineNumbers.join(", ")}]`;
|
|
6049
6086
|
};
|
|
6050
|
-
var createReadTool = (sandboxKey) => (0,
|
|
6087
|
+
var createReadTool = (sandboxKey) => (0, import_core9.defineTool)({
|
|
6051
6088
|
name: "read",
|
|
6052
6089
|
description: "Read a bounded text-file preview by 0-based line offset/limit; large output is truncated and long lines should fall back to read_line.",
|
|
6053
6090
|
input: import_zod7.z.object({
|
|
@@ -6154,7 +6191,7 @@ For full long-line content, use read_line({"file_path":${JSON.stringify(input.fi
|
|
|
6154
6191
|
|
|
6155
6192
|
// src/tools/read-line.ts
|
|
6156
6193
|
var import_node_fs12 = require("fs");
|
|
6157
|
-
var
|
|
6194
|
+
var import_core10 = require("@codelia/core");
|
|
6158
6195
|
var import_zod8 = require("zod");
|
|
6159
6196
|
var DEFAULT_CHAR_LIMIT = 1e4;
|
|
6160
6197
|
var MAX_CHAR_LIMIT = 1e5;
|
|
@@ -6162,7 +6199,7 @@ var GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, {
|
|
|
6162
6199
|
granularity: "grapheme"
|
|
6163
6200
|
});
|
|
6164
6201
|
var splitGraphemes = (value) => Array.from(GRAPHEME_SEGMENTER.segment(value), ({ segment }) => segment);
|
|
6165
|
-
var createReadLineTool = (sandboxKey) => (0,
|
|
6202
|
+
var createReadLineTool = (sandboxKey) => (0, import_core10.defineTool)({
|
|
6166
6203
|
name: "read_line",
|
|
6167
6204
|
description: "Read one physical line as paged grapheme-based text by 1-based line number and 0-based char offset.",
|
|
6168
6205
|
input: import_zod8.z.object({
|
|
@@ -6231,7 +6268,7 @@ read_line({"file_path":${JSON.stringify(input.file_path)},"line_number":${input.
|
|
|
6231
6268
|
});
|
|
6232
6269
|
|
|
6233
6270
|
// src/tools/search.ts
|
|
6234
|
-
var
|
|
6271
|
+
var import_core11 = require("@codelia/core");
|
|
6235
6272
|
var import_zod9 = require("zod");
|
|
6236
6273
|
var normalizeDomain = (value) => value.trim().toLowerCase().replace(/\.+$/, "");
|
|
6237
6274
|
var shouldKeepUrl = (url, allowedDomains) => {
|
|
@@ -6348,7 +6385,7 @@ var runBraveSearch = async (query, maxResults, allowedDomains, apiKey) => {
|
|
|
6348
6385
|
const parsed = parseBrave(payload);
|
|
6349
6386
|
return normalizeEntries(parsed, allowedDomains, maxResults);
|
|
6350
6387
|
};
|
|
6351
|
-
var createSearchTool = (options) => (0,
|
|
6388
|
+
var createSearchTool = (options) => (0, import_core11.defineTool)({
|
|
6352
6389
|
name: "search",
|
|
6353
6390
|
description: "Search the web and return concise source candidates.",
|
|
6354
6391
|
input: import_zod9.z.object({
|
|
@@ -6391,7 +6428,7 @@ var createSearchTool = (options) => (0, import_core10.defineTool)({
|
|
|
6391
6428
|
|
|
6392
6429
|
// src/tools/shell.ts
|
|
6393
6430
|
var import_node_crypto7 = __toESM(require("crypto"), 1);
|
|
6394
|
-
var
|
|
6431
|
+
var import_core12 = require("@codelia/core");
|
|
6395
6432
|
var import_storage7 = require("@codelia/storage");
|
|
6396
6433
|
var import_zod10 = require("zod");
|
|
6397
6434
|
|
|
@@ -7351,7 +7388,7 @@ var waitForManagedTaskWindow = async (tasks, taskId, options) => {
|
|
|
7351
7388
|
};
|
|
7352
7389
|
var createShellTool = (sandboxKey, options = {}) => {
|
|
7353
7390
|
const shared = getSharedDeps(options);
|
|
7354
|
-
return (0,
|
|
7391
|
+
return (0, import_core12.defineTool)({
|
|
7355
7392
|
name: "shell",
|
|
7356
7393
|
description: "Run a shell command as a runtime-managed child process in the sandbox. Terminal results use `stdout`/`stderr` stream fields; successful results suppress `stderr` by default unless `include_stderr_on_success=true`, and `shell_logs` is available when you need explicit stream reads. By default wait for completion; with `detached_wait=true`, skip the attached wait and return compact JSON with the task key for follow-up tools.",
|
|
7357
7394
|
input: shellRunSchema,
|
|
@@ -7417,7 +7454,7 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
7417
7454
|
};
|
|
7418
7455
|
var createShellListTool = (options = {}) => {
|
|
7419
7456
|
const shared = getSharedDeps(options);
|
|
7420
|
-
return (0,
|
|
7457
|
+
return (0, import_core12.defineTool)({
|
|
7421
7458
|
name: "shell_list",
|
|
7422
7459
|
description: "List retained shell tasks with compact summaries, defaulting to active tasks.",
|
|
7423
7460
|
input: shellListSchema,
|
|
@@ -7448,7 +7485,7 @@ var createShellListTool = (options = {}) => {
|
|
|
7448
7485
|
};
|
|
7449
7486
|
var createShellStatusTool = (options = {}) => {
|
|
7450
7487
|
const shared = getSharedDeps(options);
|
|
7451
|
-
return (0,
|
|
7488
|
+
return (0, import_core12.defineTool)({
|
|
7452
7489
|
name: "shell_status",
|
|
7453
7490
|
description: "Get the current state for a shell task as compact JSON.",
|
|
7454
7491
|
input: shellTaskKeySchema,
|
|
@@ -7464,7 +7501,7 @@ var createShellStatusTool = (options = {}) => {
|
|
|
7464
7501
|
};
|
|
7465
7502
|
var createShellLogsTool = (options = {}) => {
|
|
7466
7503
|
const shared = getSharedDeps(options);
|
|
7467
|
-
return (0,
|
|
7504
|
+
return (0, import_core12.defineTool)({
|
|
7468
7505
|
name: "shell_logs",
|
|
7469
7506
|
description: "Read recent stdout or stderr for a running or finished shell task. Use this when a compact shell terminal result omitted a stream, such as `stderr` on success.",
|
|
7470
7507
|
input: shellLogsSchema,
|
|
@@ -7486,7 +7523,7 @@ var createShellLogsTool = (options = {}) => {
|
|
|
7486
7523
|
};
|
|
7487
7524
|
var createShellWaitTool = (options = {}) => {
|
|
7488
7525
|
const shared = getSharedDeps(options);
|
|
7489
|
-
return (0,
|
|
7526
|
+
return (0, import_core12.defineTool)({
|
|
7490
7527
|
name: "shell_wait",
|
|
7491
7528
|
description: "Wait for a shell task within a bounded window and return compact JSON describing either the running status or a terminal result with `stdout`/`stderr` stream fields. Successful terminal results suppress `stderr` by default unless `include_stderr_on_success=true`; use `shell_logs` for explicit stream reads.",
|
|
7492
7529
|
input: shellWaitSchema,
|
|
@@ -7521,7 +7558,7 @@ var createShellWaitTool = (options = {}) => {
|
|
|
7521
7558
|
};
|
|
7522
7559
|
var createShellResultTool = (options = {}) => {
|
|
7523
7560
|
const shared = getSharedDeps(options);
|
|
7524
|
-
return (0,
|
|
7561
|
+
return (0, import_core12.defineTool)({
|
|
7525
7562
|
name: "shell_result",
|
|
7526
7563
|
description: "Read the retained terminal result for a shell task as compact JSON with `stdout`/`stderr` stream fields. Successful terminal results suppress `stderr` by default unless `include_stderr_on_success=true`; use `shell_logs` for explicit stream reads.",
|
|
7527
7564
|
input: shellResultSchema,
|
|
@@ -7540,7 +7577,7 @@ var createShellResultTool = (options = {}) => {
|
|
|
7540
7577
|
};
|
|
7541
7578
|
var createShellCancelTool = (options = {}) => {
|
|
7542
7579
|
const shared = getSharedDeps(options);
|
|
7543
|
-
return (0,
|
|
7580
|
+
return (0, import_core12.defineTool)({
|
|
7544
7581
|
name: "shell_cancel",
|
|
7545
7582
|
description: "Cancel a running shell task and return compact JSON for the cancelled state.",
|
|
7546
7583
|
input: shellTaskKeySchema,
|
|
@@ -7559,7 +7596,7 @@ var createShellCancelTool = (options = {}) => {
|
|
|
7559
7596
|
};
|
|
7560
7597
|
|
|
7561
7598
|
// src/tools/skill-load.ts
|
|
7562
|
-
var
|
|
7599
|
+
var import_core13 = require("@codelia/core");
|
|
7563
7600
|
var import_zod11 = require("zod");
|
|
7564
7601
|
var SkillLoadInputSchema = import_zod11.z.object({
|
|
7565
7602
|
name: import_zod11.z.string().min(1).optional().describe("Exact skill name to load."),
|
|
@@ -7568,7 +7605,7 @@ var SkillLoadInputSchema = import_zod11.z.object({
|
|
|
7568
7605
|
message: "name or path is required",
|
|
7569
7606
|
path: ["name"]
|
|
7570
7607
|
});
|
|
7571
|
-
var createSkillLoadTool = (skillsResolverKey) => (0,
|
|
7608
|
+
var createSkillLoadTool = (skillsResolverKey) => (0, import_core13.defineTool)({
|
|
7572
7609
|
name: "skill_load",
|
|
7573
7610
|
description: "Load full SKILL.md content by exact name or path.",
|
|
7574
7611
|
input: SkillLoadInputSchema,
|
|
@@ -7614,9 +7651,9 @@ var createSkillLoadTool = (skillsResolverKey) => (0, import_core12.defineTool)({
|
|
|
7614
7651
|
});
|
|
7615
7652
|
|
|
7616
7653
|
// src/tools/skill-search.ts
|
|
7617
|
-
var
|
|
7654
|
+
var import_core14 = require("@codelia/core");
|
|
7618
7655
|
var import_zod12 = require("zod");
|
|
7619
|
-
var createSkillSearchTool = (skillsResolverKey) => (0,
|
|
7656
|
+
var createSkillSearchTool = (skillsResolverKey) => (0, import_core14.defineTool)({
|
|
7620
7657
|
name: "skill_search",
|
|
7621
7658
|
description: "Search installed local skills by name, description, or path.",
|
|
7622
7659
|
input: import_zod12.z.object({
|
|
@@ -7647,7 +7684,7 @@ var createSkillSearchTool = (skillsResolverKey) => (0, import_core13.defineTool)
|
|
|
7647
7684
|
});
|
|
7648
7685
|
|
|
7649
7686
|
// src/tools/todo-mutate.ts
|
|
7650
|
-
var
|
|
7687
|
+
var import_core15 = require("@codelia/core");
|
|
7651
7688
|
var import_zod13 = require("zod");
|
|
7652
7689
|
|
|
7653
7690
|
// src/tools/todo-store.ts
|
|
@@ -7883,7 +7920,7 @@ var applyTodoMutation = (sessionId, input, outputMode) => {
|
|
|
7883
7920
|
}
|
|
7884
7921
|
return formatSuccess(outputMode, nextTodos);
|
|
7885
7922
|
};
|
|
7886
|
-
var createTodoMutationTool = (name, description, input, executeMutation, sandboxKey, sessionContextKey) => (0,
|
|
7923
|
+
var createTodoMutationTool = (name, description, input, executeMutation, sandboxKey, sessionContextKey) => (0, import_core15.defineTool)({
|
|
7887
7924
|
name,
|
|
7888
7925
|
description,
|
|
7889
7926
|
input,
|
|
@@ -7938,14 +7975,14 @@ var createTodoClearTool = (sandboxKey, sessionContextKey) => createTodoMutationT
|
|
|
7938
7975
|
);
|
|
7939
7976
|
|
|
7940
7977
|
// src/tools/todo-read.ts
|
|
7941
|
-
var
|
|
7978
|
+
var import_core16 = require("@codelia/core");
|
|
7942
7979
|
var import_zod14 = require("zod");
|
|
7943
7980
|
var statusSymbol2 = {
|
|
7944
7981
|
pending: "[ ]",
|
|
7945
7982
|
in_progress: "[>]",
|
|
7946
7983
|
completed: "[x]"
|
|
7947
7984
|
};
|
|
7948
|
-
var createTodoReadTool = (sandboxKey, sessionContextKey) => (0,
|
|
7985
|
+
var createTodoReadTool = (sandboxKey, sessionContextKey) => (0, import_core16.defineTool)({
|
|
7949
7986
|
name: "todo_read",
|
|
7950
7987
|
description: "Read the in-session todo plan with execution order and next step.",
|
|
7951
7988
|
input: import_zod14.z.object({}),
|
|
@@ -7984,9 +8021,9 @@ var createTodoReadTool = (sandboxKey, sessionContextKey) => (0, import_core15.de
|
|
|
7984
8021
|
});
|
|
7985
8022
|
|
|
7986
8023
|
// src/tools/tool-output-cache.ts
|
|
7987
|
-
var
|
|
8024
|
+
var import_core17 = require("@codelia/core");
|
|
7988
8025
|
var import_zod15 = require("zod");
|
|
7989
|
-
var createToolOutputCacheTool = (store) => (0,
|
|
8026
|
+
var createToolOutputCacheTool = (store) => (0, import_core17.defineTool)({
|
|
7990
8027
|
name: "tool_output_cache",
|
|
7991
8028
|
description: "Read cached tool output by ref_id.",
|
|
7992
8029
|
input: import_zod15.z.object({
|
|
@@ -8008,7 +8045,7 @@ var createToolOutputCacheTool = (store) => (0, import_core16.defineTool)({
|
|
|
8008
8045
|
}
|
|
8009
8046
|
}
|
|
8010
8047
|
});
|
|
8011
|
-
var createToolOutputCacheLineTool = (store) => (0,
|
|
8048
|
+
var createToolOutputCacheLineTool = (store) => (0, import_core17.defineTool)({
|
|
8012
8049
|
name: "tool_output_cache_line",
|
|
8013
8050
|
description: "Read a single cached output line segment by line number and char offset.",
|
|
8014
8051
|
input: import_zod15.z.object({
|
|
@@ -8032,7 +8069,7 @@ var createToolOutputCacheLineTool = (store) => (0, import_core16.defineTool)({
|
|
|
8032
8069
|
}
|
|
8033
8070
|
}
|
|
8034
8071
|
});
|
|
8035
|
-
var createToolOutputCacheGrepTool = (store) => (0,
|
|
8072
|
+
var createToolOutputCacheGrepTool = (store) => (0, import_core17.defineTool)({
|
|
8036
8073
|
name: "tool_output_cache_grep",
|
|
8037
8074
|
description: "Search cached tool output by ref_id.",
|
|
8038
8075
|
input: import_zod15.z.object({
|
|
@@ -8064,7 +8101,7 @@ var createToolOutputCacheGrepTool = (store) => (0, import_core16.defineTool)({
|
|
|
8064
8101
|
// src/tools/view-image.ts
|
|
8065
8102
|
var import_node_fs13 = require("fs");
|
|
8066
8103
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
8067
|
-
var
|
|
8104
|
+
var import_core18 = require("@codelia/core");
|
|
8068
8105
|
var import_zod16 = require("zod");
|
|
8069
8106
|
var DEFAULT_MAX_BYTES2 = 5 * 1024 * 1024;
|
|
8070
8107
|
var MAX_MAX_BYTES = 10 * 1024 * 1024;
|
|
@@ -8078,7 +8115,7 @@ var MIME_BY_EXTENSION = {
|
|
|
8078
8115
|
var resolveImageMime = (filePath) => {
|
|
8079
8116
|
return MIME_BY_EXTENSION[import_node_path13.default.extname(filePath).toLowerCase()] ?? null;
|
|
8080
8117
|
};
|
|
8081
|
-
var createViewImageTool = (sandboxKey) => (0,
|
|
8118
|
+
var createViewImageTool = (sandboxKey) => (0, import_core18.defineTool)({
|
|
8082
8119
|
name: "view_image",
|
|
8083
8120
|
description: "Load one local png/jpeg/webp/gif image (default max 5MB) for multimodal inspection.",
|
|
8084
8121
|
input: import_zod16.z.object({
|
|
@@ -8138,7 +8175,7 @@ var createViewImageTool = (sandboxKey) => (0, import_core17.defineTool)({
|
|
|
8138
8175
|
});
|
|
8139
8176
|
|
|
8140
8177
|
// src/tools/webfetch.ts
|
|
8141
|
-
var
|
|
8178
|
+
var import_core19 = require("@codelia/core");
|
|
8142
8179
|
var import_zod17 = require("zod");
|
|
8143
8180
|
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
8144
8181
|
var MAX_TIMEOUT_MS = 3e4;
|
|
@@ -8392,7 +8429,7 @@ var classifyFetchError = (error, timeoutMs) => {
|
|
|
8392
8429
|
})
|
|
8393
8430
|
};
|
|
8394
8431
|
};
|
|
8395
|
-
var createWebfetchTool = () => (0,
|
|
8432
|
+
var createWebfetchTool = () => (0, import_core19.defineTool)({
|
|
8396
8433
|
name: "webfetch",
|
|
8397
8434
|
description: "Fetch an HTTP(S) URL and return bounded normalized markdown/text/html for textual content, not binary downloads.",
|
|
8398
8435
|
input: import_zod17.z.object({
|
|
@@ -8474,9 +8511,9 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
|
|
|
8474
8511
|
// src/tools/write.ts
|
|
8475
8512
|
var import_node_fs14 = require("fs");
|
|
8476
8513
|
var import_node_path14 = __toESM(require("path"), 1);
|
|
8477
|
-
var
|
|
8514
|
+
var import_core20 = require("@codelia/core");
|
|
8478
8515
|
var import_zod18 = require("zod");
|
|
8479
|
-
var createWriteTool = (sandboxKey, outputCacheStore) => (0,
|
|
8516
|
+
var createWriteTool = (sandboxKey, outputCacheStore) => (0, import_core20.defineTool)({
|
|
8480
8517
|
name: "write",
|
|
8481
8518
|
description: "Write full UTF-8 text to a file, replacing any existing contents and creating parent directories if needed.",
|
|
8482
8519
|
input: import_zod18.z.object({
|
|
@@ -8796,13 +8833,28 @@ var resolveModelMaxTokensFromEntry = (entry) => {
|
|
|
8796
8833
|
}
|
|
8797
8834
|
return null;
|
|
8798
8835
|
};
|
|
8836
|
+
var resolveAnthropicStaticModelMaxTokens = (model) => {
|
|
8837
|
+
const spec = (0, import_core21.resolveModel)(import_core21.DEFAULT_MODEL_REGISTRY, model, "anthropic");
|
|
8838
|
+
const candidates = [
|
|
8839
|
+
spec?.maxOutputTokens,
|
|
8840
|
+
spec?.maxInputTokens,
|
|
8841
|
+
spec?.contextWindow
|
|
8842
|
+
];
|
|
8843
|
+
for (const value of candidates) {
|
|
8844
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
8845
|
+
continue;
|
|
8846
|
+
}
|
|
8847
|
+
return Math.trunc(value);
|
|
8848
|
+
}
|
|
8849
|
+
return null;
|
|
8850
|
+
};
|
|
8799
8851
|
var resolveAnthropicModelMaxTokens = async (model) => {
|
|
8800
8852
|
const metadataService = new import_model_metadata2.ModelMetadataServiceImpl({
|
|
8801
8853
|
storagePathService: new import_storage8.StoragePathServiceImpl()
|
|
8802
8854
|
});
|
|
8803
8855
|
const direct = await metadataService.getModelEntry("anthropic", model);
|
|
8804
8856
|
const prefixed = model.startsWith("anthropic/") ? null : await metadataService.getModelEntry("anthropic", `anthropic/${model}`);
|
|
8805
|
-
return resolveModelMaxTokensFromEntry(direct) ?? resolveModelMaxTokensFromEntry(prefixed);
|
|
8857
|
+
return resolveModelMaxTokensFromEntry(direct) ?? resolveModelMaxTokensFromEntry(prefixed) ?? resolveAnthropicStaticModelMaxTokens(model);
|
|
8806
8858
|
};
|
|
8807
8859
|
var sleep2 = (ms) => new Promise((resolve) => {
|
|
8808
8860
|
setTimeout(resolve, ms);
|
|
@@ -9174,12 +9226,13 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9174
9226
|
let llm;
|
|
9175
9227
|
let resolvedModelName = null;
|
|
9176
9228
|
const requestedReasoning = resolveReasoningEffort(modelConfig.reasoning) ?? "medium";
|
|
9229
|
+
const isFastRequested = modelConfig.fast === true;
|
|
9177
9230
|
switch (provider) {
|
|
9178
9231
|
case "openai": {
|
|
9179
|
-
const modelName = modelConfig.name ??
|
|
9232
|
+
const modelName = modelConfig.name ?? import_core21.OPENAI_DEFAULT_MODEL;
|
|
9180
9233
|
resolvedModelName = modelName;
|
|
9181
|
-
const providerModelName = (0,
|
|
9182
|
-
|
|
9234
|
+
const providerModelName = (0, import_core21.resolveProviderModelId)(
|
|
9235
|
+
import_core21.DEFAULT_MODEL_REGISTRY,
|
|
9183
9236
|
modelName,
|
|
9184
9237
|
"openai"
|
|
9185
9238
|
) ?? modelName;
|
|
@@ -9189,7 +9242,12 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9189
9242
|
});
|
|
9190
9243
|
const textVerbosity = resolveTextVerbosity(modelConfig.verbosity);
|
|
9191
9244
|
const websocketMode = modelConfig.experimental?.openai?.websocket_mode;
|
|
9192
|
-
|
|
9245
|
+
const fastMode = resolveFastMode({
|
|
9246
|
+
provider: "openai",
|
|
9247
|
+
model: modelName,
|
|
9248
|
+
requested: isFastRequested
|
|
9249
|
+
});
|
|
9250
|
+
llm = new import_core21.ChatOpenAI({
|
|
9193
9251
|
clientOptions: buildOpenAiClientOptions(authResolver, providerAuth),
|
|
9194
9252
|
model: modelName,
|
|
9195
9253
|
providerModel: providerModelName,
|
|
@@ -9198,19 +9256,20 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9198
9256
|
reasoningLevelApplied: reasoning.applied,
|
|
9199
9257
|
reasoningFallbackApplied: reasoning.fallbackApplied,
|
|
9200
9258
|
...textVerbosity ? { textVerbosity } : {},
|
|
9259
|
+
...fastMode.enabled && fastMode.provider === "openai" ? { serviceTier: fastMode.serviceTier } : {},
|
|
9201
9260
|
...websocketMode ? { websocketMode } : {}
|
|
9202
9261
|
});
|
|
9203
9262
|
break;
|
|
9204
9263
|
}
|
|
9205
9264
|
case "openrouter": {
|
|
9206
|
-
const modelName = modelConfig.name ??
|
|
9265
|
+
const modelName = modelConfig.name ?? import_core21.OPENAI_DEFAULT_MODEL;
|
|
9207
9266
|
resolvedModelName = modelName;
|
|
9208
9267
|
const reasoning = resolveResponsesReasoning({
|
|
9209
9268
|
model: modelName,
|
|
9210
9269
|
requested: requestedReasoning
|
|
9211
9270
|
});
|
|
9212
9271
|
const textVerbosity = resolveTextVerbosity(modelConfig.verbosity);
|
|
9213
|
-
llm = new
|
|
9272
|
+
llm = new import_core21.ChatOpenRouter({
|
|
9214
9273
|
clientOptions: buildOpenRouterClientOptions(providerAuth),
|
|
9215
9274
|
model: modelName,
|
|
9216
9275
|
reasoningEffort: reasoning.effort,
|
|
@@ -9222,7 +9281,7 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9222
9281
|
break;
|
|
9223
9282
|
}
|
|
9224
9283
|
case "anthropic": {
|
|
9225
|
-
const modelName = modelConfig.name ??
|
|
9284
|
+
const modelName = modelConfig.name ?? import_core21.ANTHROPIC_DEFAULT_MODEL;
|
|
9226
9285
|
resolvedModelName = modelName;
|
|
9227
9286
|
const reasoning = resolveAnthropicReasoning({
|
|
9228
9287
|
model: modelName,
|
|
@@ -9235,27 +9294,34 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9235
9294
|
});
|
|
9236
9295
|
const modelMaxTokens = await resolveAnthropicModelMaxTokens(modelName);
|
|
9237
9296
|
const maxTokens = resolveAnthropicMaxTokens({
|
|
9238
|
-
thinkingBudgetTokens: reasoning.thinking.budget_tokens,
|
|
9297
|
+
thinkingBudgetTokens: reasoning.thinking.type === "enabled" ? reasoning.thinking.budget_tokens : 0,
|
|
9239
9298
|
modelLimitMaxTokens: modelMaxTokens
|
|
9240
9299
|
});
|
|
9241
|
-
if (typeof modelMaxTokens === "number" && modelMaxTokens <= reasoning.thinking.budget_tokens) {
|
|
9300
|
+
if (reasoning.thinking.type === "enabled" && typeof modelMaxTokens === "number" && modelMaxTokens <= reasoning.thinking.budget_tokens) {
|
|
9242
9301
|
(0, import_logger.log)(
|
|
9243
9302
|
`anthropic model '${modelName}' max token limit (${modelMaxTokens}) is not above thinking budget (${reasoning.thinking.budget_tokens}); using max_tokens=${maxTokens} to satisfy API constraint`
|
|
9244
9303
|
);
|
|
9245
9304
|
}
|
|
9246
|
-
|
|
9305
|
+
const fastMode = resolveFastMode({
|
|
9306
|
+
provider: "anthropic",
|
|
9307
|
+
model: modelName,
|
|
9308
|
+
requested: isFastRequested
|
|
9309
|
+
});
|
|
9310
|
+
llm = new import_core21.ChatAnthropic({
|
|
9247
9311
|
clientOptions: {
|
|
9248
9312
|
apiKey: requireApiKeyAuth("Anthropic", providerAuth)
|
|
9249
9313
|
},
|
|
9250
9314
|
model: modelName,
|
|
9251
9315
|
maxTokens,
|
|
9252
9316
|
invokeOptions: {
|
|
9253
|
-
thinking: reasoning.thinking
|
|
9317
|
+
thinking: reasoning.thinking,
|
|
9318
|
+
...reasoning.outputConfig ? { output_config: reasoning.outputConfig } : {}
|
|
9254
9319
|
},
|
|
9255
9320
|
reasoningLevelRequested: reasoning.requested,
|
|
9256
9321
|
reasoningLevelApplied: reasoning.applied,
|
|
9257
9322
|
reasoningFallbackApplied: reasoning.fallbackApplied,
|
|
9258
|
-
reasoningBudgetPreset: reasoning.budgetPreset
|
|
9323
|
+
reasoningBudgetPreset: reasoning.budgetPreset,
|
|
9324
|
+
...fastMode.enabled && fastMode.provider === "anthropic" ? { fastMode: true } : {}
|
|
9259
9325
|
});
|
|
9260
9326
|
break;
|
|
9261
9327
|
}
|
|
@@ -9270,17 +9336,23 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9270
9336
|
const totalBudgetTrimEnabled = envTruthy(
|
|
9271
9337
|
process.env.CODELIA_TOOL_OUTPUT_TOTAL_TRIM
|
|
9272
9338
|
);
|
|
9273
|
-
const agent = new
|
|
9339
|
+
const agent = new import_core21.Agent({
|
|
9274
9340
|
llm,
|
|
9275
9341
|
tools,
|
|
9276
9342
|
hostedTools: hostedSearchDefinitions,
|
|
9277
9343
|
systemPrompt,
|
|
9278
|
-
modelRegistry: modelRegistry ??
|
|
9344
|
+
modelRegistry: modelRegistry ?? import_core21.DEFAULT_MODEL_REGISTRY,
|
|
9279
9345
|
toolOutputCache: {
|
|
9280
9346
|
totalBudgetTrim: totalBudgetTrimEnabled
|
|
9281
9347
|
},
|
|
9282
9348
|
services: { toolOutputCacheStore },
|
|
9283
9349
|
canExecuteTool: async (call, rawArgs, toolCtx) => {
|
|
9350
|
+
if (state.autoApprovedClientToolNames.has(call.function.name)) {
|
|
9351
|
+
(0, import_logger.debugLog)(
|
|
9352
|
+
`permission.evaluate tool=${call.function.name} decision=allow reason=client-tool-auto-approved`
|
|
9353
|
+
);
|
|
9354
|
+
return { decision: "allow" };
|
|
9355
|
+
}
|
|
9284
9356
|
const decision = permissionService.evaluate(
|
|
9285
9357
|
call.function.name,
|
|
9286
9358
|
rawArgs
|
|
@@ -11109,7 +11181,7 @@ var createHistoryHandlers = ({
|
|
|
11109
11181
|
};
|
|
11110
11182
|
|
|
11111
11183
|
// src/rpc/model.ts
|
|
11112
|
-
var
|
|
11184
|
+
var import_core22 = require("@codelia/core");
|
|
11113
11185
|
var import_model_metadata3 = require("@codelia/model-metadata");
|
|
11114
11186
|
var import_protocol4 = require("@codelia/protocol");
|
|
11115
11187
|
var isSupportedProvider = (provider) => provider === "openai" || provider === "anthropic" || provider === "openrouter";
|
|
@@ -11117,7 +11189,7 @@ var resolveProviderModelEntry2 = (providerEntries, provider, model) => {
|
|
|
11117
11189
|
if (!providerEntries) {
|
|
11118
11190
|
return null;
|
|
11119
11191
|
}
|
|
11120
|
-
const providerModelId = (0,
|
|
11192
|
+
const providerModelId = (0, import_core22.resolveProviderModelId)(import_core22.DEFAULT_MODEL_REGISTRY, model, provider) ?? model;
|
|
11121
11193
|
const candidates = [
|
|
11122
11194
|
model,
|
|
11123
11195
|
`${provider}/${model}`,
|
|
@@ -11146,7 +11218,7 @@ var normalizeUsdPer1M = (value) => {
|
|
|
11146
11218
|
return value;
|
|
11147
11219
|
};
|
|
11148
11220
|
var buildModelListDetail = (entry, registry, provider, model) => {
|
|
11149
|
-
const spec = (0,
|
|
11221
|
+
const spec = (0, import_core22.resolveModel)(registry, model, provider);
|
|
11150
11222
|
if (!entry && !spec) return null;
|
|
11151
11223
|
const detail = {};
|
|
11152
11224
|
if (entry?.releaseDate?.trim()) {
|
|
@@ -11372,22 +11444,24 @@ var buildProviderModelList = async ({
|
|
|
11372
11444
|
}
|
|
11373
11445
|
}
|
|
11374
11446
|
}
|
|
11447
|
+
const mergedRegistry = (0, import_core22.applyModelMetadata)(import_core22.DEFAULT_MODEL_REGISTRY, {
|
|
11448
|
+
models: {
|
|
11449
|
+
openai: provider === "openai" ? providerEntries ?? {} : {},
|
|
11450
|
+
anthropic: provider === "anthropic" ? providerEntries ?? {} : {},
|
|
11451
|
+
openrouter: {},
|
|
11452
|
+
google: {}
|
|
11453
|
+
}
|
|
11454
|
+
});
|
|
11375
11455
|
const models = sortModelsByReleaseDate(
|
|
11376
|
-
(0,
|
|
11456
|
+
(0, import_core22.listModels)(import_core22.DEFAULT_MODEL_REGISTRY, provider).filter(
|
|
11457
|
+
(model) => (0, import_core22.isUsableModelSpec)((0, import_core22.resolveModel)(mergedRegistry, model.id, provider))
|
|
11458
|
+
).map((model) => model.id),
|
|
11377
11459
|
provider,
|
|
11378
11460
|
providerEntries
|
|
11379
11461
|
);
|
|
11380
11462
|
if (!includeDetails || !providerEntries) {
|
|
11381
11463
|
return { models };
|
|
11382
11464
|
}
|
|
11383
|
-
const mergedRegistry = (0, import_core21.applyModelMetadata)(import_core21.DEFAULT_MODEL_REGISTRY, {
|
|
11384
|
-
models: {
|
|
11385
|
-
openai: provider === "openai" ? providerEntries : {},
|
|
11386
|
-
anthropic: provider === "anthropic" ? providerEntries : {},
|
|
11387
|
-
openrouter: {},
|
|
11388
|
-
google: {}
|
|
11389
|
-
}
|
|
11390
|
-
});
|
|
11391
11465
|
const details = {};
|
|
11392
11466
|
for (const model of models) {
|
|
11393
11467
|
const detail = buildModelListDetail(
|
|
@@ -11419,6 +11493,7 @@ var createModelHandlers = ({
|
|
|
11419
11493
|
let current;
|
|
11420
11494
|
let configuredProvider;
|
|
11421
11495
|
let configuredReasoning;
|
|
11496
|
+
let configuredFast;
|
|
11422
11497
|
try {
|
|
11423
11498
|
const config = await resolveModelConfig();
|
|
11424
11499
|
configuredProvider = config.provider ?? "openai";
|
|
@@ -11426,6 +11501,13 @@ var createModelHandlers = ({
|
|
|
11426
11501
|
if (!requestedProvider || requestedProvider === configuredProvider) {
|
|
11427
11502
|
current = config.name;
|
|
11428
11503
|
}
|
|
11504
|
+
if (config.fast !== void 0 && config.name && isSupportedProvider(configuredProvider)) {
|
|
11505
|
+
configuredFast = resolveFastMode({
|
|
11506
|
+
provider: configuredProvider,
|
|
11507
|
+
model: config.name,
|
|
11508
|
+
requested: config.fast
|
|
11509
|
+
}).enabled;
|
|
11510
|
+
}
|
|
11429
11511
|
} catch (error) {
|
|
11430
11512
|
sendError(id, {
|
|
11431
11513
|
code: import_protocol4.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
@@ -11467,6 +11549,7 @@ var createModelHandlers = ({
|
|
|
11467
11549
|
models,
|
|
11468
11550
|
current,
|
|
11469
11551
|
...configuredReasoning ? { reasoning: configuredReasoning } : {},
|
|
11552
|
+
...configuredFast !== void 0 ? { fast: configuredFast } : {},
|
|
11470
11553
|
...details ? { details } : {}
|
|
11471
11554
|
};
|
|
11472
11555
|
sendResult(id, result);
|
|
@@ -11508,7 +11591,7 @@ var createModelHandlers = ({
|
|
|
11508
11591
|
return;
|
|
11509
11592
|
}
|
|
11510
11593
|
if (provider !== "openrouter") {
|
|
11511
|
-
const spec = (0,
|
|
11594
|
+
const spec = (0, import_core22.resolveModel)(import_core22.DEFAULT_MODEL_REGISTRY, name, provider);
|
|
11512
11595
|
if (!spec) {
|
|
11513
11596
|
sendError(id, {
|
|
11514
11597
|
code: import_protocol4.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
@@ -11522,7 +11605,8 @@ var createModelHandlers = ({
|
|
|
11522
11605
|
const target = await updateModel(workingDir, {
|
|
11523
11606
|
provider,
|
|
11524
11607
|
name,
|
|
11525
|
-
...reasoning ? { reasoning } : {}
|
|
11608
|
+
...reasoning ? { reasoning } : {},
|
|
11609
|
+
...params.fast !== void 0 ? { fast: params.fast } : {}
|
|
11526
11610
|
});
|
|
11527
11611
|
state.currentModelProvider = provider;
|
|
11528
11612
|
state.currentModelName = name;
|
|
@@ -11531,10 +11615,16 @@ var createModelHandlers = ({
|
|
|
11531
11615
|
const effectiveReasoning = resolveReasoningEffort(
|
|
11532
11616
|
updatedConfig.reasoning
|
|
11533
11617
|
);
|
|
11618
|
+
const effectiveFast = resolveFastMode({
|
|
11619
|
+
provider,
|
|
11620
|
+
model: name,
|
|
11621
|
+
requested: updatedConfig.fast
|
|
11622
|
+
}).enabled;
|
|
11534
11623
|
const result = {
|
|
11535
11624
|
provider,
|
|
11536
11625
|
name,
|
|
11537
|
-
...effectiveReasoning ? { reasoning: effectiveReasoning } : {}
|
|
11626
|
+
...effectiveReasoning ? { reasoning: effectiveReasoning } : {},
|
|
11627
|
+
...updatedConfig.fast !== void 0 ? { fast: effectiveFast } : {}
|
|
11538
11628
|
};
|
|
11539
11629
|
sendResult(id, result);
|
|
11540
11630
|
log2(
|
|
@@ -11550,344 +11640,61 @@ var createModelHandlers = ({
|
|
|
11550
11640
|
return { handleModelList, handleModelSet };
|
|
11551
11641
|
};
|
|
11552
11642
|
|
|
11553
|
-
// src/rpc/
|
|
11554
|
-
var
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
var
|
|
11558
|
-
var
|
|
11559
|
-
var
|
|
11560
|
-
var
|
|
11561
|
-
|
|
11562
|
-
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
var DEBUG_ERROR_EXTRAS_MAX_CHARS = 4e3;
|
|
11566
|
-
var DEBUG_PROVIDER_META_STRING_MAX_CHARS = 80;
|
|
11567
|
-
var truncateText2 = (value, maxChars) => {
|
|
11568
|
-
if (value.length <= maxChars) return value;
|
|
11569
|
-
return `${value.slice(0, maxChars)}...[truncated]`;
|
|
11643
|
+
// src/rpc/resume-context.ts
|
|
11644
|
+
var import_node_fs17 = require("fs");
|
|
11645
|
+
var import_node_path16 = __toESM(require("path"), 1);
|
|
11646
|
+
var RESUME_CONTEXT_META_KEY = "codelia_resume_context";
|
|
11647
|
+
var RESUME_CONTEXT_SCHEMA_VERSION = 1;
|
|
11648
|
+
var RESUME_DIFF_TAG = '<system-reminder type="session.resume.diff">';
|
|
11649
|
+
var MAX_RESUME_DETAIL_LINES = 3;
|
|
11650
|
+
var normalizePath2 = (value) => {
|
|
11651
|
+
if (typeof value !== "string") return void 0;
|
|
11652
|
+
const trimmed = value.trim();
|
|
11653
|
+
if (!trimmed) return void 0;
|
|
11654
|
+
return import_node_path16.default.resolve(trimmed);
|
|
11570
11655
|
};
|
|
11571
|
-
var
|
|
11572
|
-
|
|
11573
|
-
return
|
|
11574
|
-
} catch {
|
|
11575
|
-
return String(value);
|
|
11656
|
+
var normalizeMtime3 = (value) => {
|
|
11657
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
11658
|
+
return void 0;
|
|
11576
11659
|
}
|
|
11660
|
+
return Math.trunc(value);
|
|
11577
11661
|
};
|
|
11578
|
-
var
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
includeOtherPayload: true
|
|
11583
|
-
});
|
|
11584
|
-
return truncateText2(text, maxChars);
|
|
11662
|
+
var normalizeText = (value) => {
|
|
11663
|
+
if (typeof value !== "string") return void 0;
|
|
11664
|
+
const trimmed = value.trim();
|
|
11665
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
11585
11666
|
};
|
|
11586
|
-
var
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
role: message.role,
|
|
11592
|
-
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS),
|
|
11593
|
-
tool_calls: (message.tool_calls ?? []).map((call) => ({
|
|
11594
|
-
id: call.id,
|
|
11595
|
-
name: call.function.name
|
|
11596
|
-
}))
|
|
11597
|
-
};
|
|
11598
|
-
}
|
|
11599
|
-
if (message.role === "tool") {
|
|
11600
|
-
return {
|
|
11601
|
-
index,
|
|
11602
|
-
role: message.role,
|
|
11603
|
-
tool_name: message.tool_name,
|
|
11604
|
-
tool_call_id: message.tool_call_id,
|
|
11605
|
-
is_error: message.is_error ?? false,
|
|
11606
|
-
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
11607
|
-
};
|
|
11608
|
-
}
|
|
11609
|
-
if (message.role === "reasoning") {
|
|
11610
|
-
return {
|
|
11611
|
-
index,
|
|
11612
|
-
role: message.role,
|
|
11613
|
-
content: truncateText2(message.content ?? "", DEBUG_MAX_CONTENT_CHARS)
|
|
11614
|
-
};
|
|
11615
|
-
}
|
|
11616
|
-
return {
|
|
11617
|
-
index,
|
|
11618
|
-
role: message.role,
|
|
11619
|
-
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
11620
|
-
};
|
|
11621
|
-
});
|
|
11622
|
-
return truncateText2(stringifyUnknown(payload), DEBUG_MAX_LOG_CHARS);
|
|
11667
|
+
var normalizeApprovalMode = (value) => {
|
|
11668
|
+
if (value === "minimal" || value === "trusted" || value === "full-access") {
|
|
11669
|
+
return value;
|
|
11670
|
+
}
|
|
11671
|
+
return void 0;
|
|
11623
11672
|
};
|
|
11624
|
-
var
|
|
11625
|
-
if (!
|
|
11626
|
-
const
|
|
11627
|
-
const
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11673
|
+
var normalizeTrackedFiles = (value) => {
|
|
11674
|
+
if (!Array.isArray(value)) return [];
|
|
11675
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11676
|
+
const files = [];
|
|
11677
|
+
for (const entry of value) {
|
|
11678
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11679
|
+
const record = entry;
|
|
11680
|
+
const filePath = normalizePath2(record.path);
|
|
11681
|
+
const mtime = normalizeMtime3(record.mtime_ms);
|
|
11682
|
+
if (!filePath || mtime === void 0 || seen.has(filePath)) continue;
|
|
11683
|
+
seen.add(filePath);
|
|
11684
|
+
files.push({ path: filePath, mtime_ms: mtime });
|
|
11685
|
+
}
|
|
11686
|
+
files.sort((left, right) => left.path.localeCompare(right.path));
|
|
11687
|
+
return files;
|
|
11631
11688
|
};
|
|
11632
|
-
var
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
case "tool_call": {
|
|
11636
|
-
const tool = typeof event.tool === "string" ? event.tool : "unknown";
|
|
11637
|
-
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
11638
|
-
const rawArgs = typeof event.raw_args === "string" ? event.raw_args : stringifyUnknown(event.args);
|
|
11639
|
-
const rawArgsSnippet = truncateText2(rawArgs, DEBUG_MAX_EVENT_ARGS_CHARS);
|
|
11640
|
-
return `type=tool_call tool=${tool} tool_call_id=${toolCallId} raw_args=${stringifyUnknown(rawArgsSnippet)}`;
|
|
11641
|
-
}
|
|
11642
|
-
case "tool_result": {
|
|
11643
|
-
const tool = typeof event.tool === "string" ? event.tool : "unknown";
|
|
11644
|
-
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
11645
|
-
const isError = event.is_error === true;
|
|
11646
|
-
const result = typeof event.result === "string" ? truncateText2(event.result, DEBUG_MAX_EVENT_RESULT_CHARS) : truncateText2(
|
|
11647
|
-
stringifyUnknown(event.result),
|
|
11648
|
-
DEBUG_MAX_EVENT_RESULT_CHARS
|
|
11649
|
-
);
|
|
11650
|
-
return `type=tool_result tool=${tool} tool_call_id=${toolCallId} is_error=${String(isError)} result=${stringifyUnknown(result)}`;
|
|
11651
|
-
}
|
|
11652
|
-
case "step_start": {
|
|
11653
|
-
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
11654
|
-
const title = typeof event.title === "string" ? event.title : "unknown";
|
|
11655
|
-
return `type=step_start step_id=${stepId} title=${title}`;
|
|
11656
|
-
}
|
|
11657
|
-
case "step_complete": {
|
|
11658
|
-
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
11659
|
-
const status = typeof event.status === "string" ? event.status : "unknown";
|
|
11660
|
-
const durationMs = typeof event.duration_ms === "number" ? event.duration_ms : -1;
|
|
11661
|
-
return `type=step_complete step_id=${stepId} status=${status} duration_ms=${durationMs}`;
|
|
11662
|
-
}
|
|
11663
|
-
case "final": {
|
|
11664
|
-
const content = typeof event.content === "string" ? event.content : "";
|
|
11665
|
-
return `type=final content_chars=${content.length}`;
|
|
11666
|
-
}
|
|
11667
|
-
default:
|
|
11668
|
-
return `type=${event.type}`;
|
|
11689
|
+
var trimDetails = (lines) => {
|
|
11690
|
+
if (lines.length <= MAX_RESUME_DETAIL_LINES) {
|
|
11691
|
+
return lines;
|
|
11669
11692
|
}
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
var normalizeToolCallHistory = (messages) => {
|
|
11676
|
-
const assistantCallIds = /* @__PURE__ */ new Set();
|
|
11677
|
-
const toolOutputCallIds = /* @__PURE__ */ new Set();
|
|
11678
|
-
for (const message of messages) {
|
|
11679
|
-
if (message.role === "assistant") {
|
|
11680
|
-
for (const call of message.tool_calls ?? []) {
|
|
11681
|
-
assistantCallIds.add(call.id);
|
|
11682
|
-
}
|
|
11683
|
-
continue;
|
|
11684
|
-
}
|
|
11685
|
-
if (message.role === "tool") {
|
|
11686
|
-
toolOutputCallIds.add(message.tool_call_id);
|
|
11687
|
-
}
|
|
11688
|
-
}
|
|
11689
|
-
if (assistantCallIds.size === 0 && toolOutputCallIds.size === 0) {
|
|
11690
|
-
return messages;
|
|
11691
|
-
}
|
|
11692
|
-
const validCallIds = /* @__PURE__ */ new Set();
|
|
11693
|
-
for (const callId of assistantCallIds) {
|
|
11694
|
-
if (toolOutputCallIds.has(callId)) {
|
|
11695
|
-
validCallIds.add(callId);
|
|
11696
|
-
}
|
|
11697
|
-
}
|
|
11698
|
-
if (validCallIds.size === assistantCallIds.size && validCallIds.size === toolOutputCallIds.size) {
|
|
11699
|
-
return messages;
|
|
11700
|
-
}
|
|
11701
|
-
let changed = false;
|
|
11702
|
-
const normalized = [];
|
|
11703
|
-
for (const message of messages) {
|
|
11704
|
-
if (message.role === "assistant") {
|
|
11705
|
-
const calls = message.tool_calls ?? [];
|
|
11706
|
-
if (calls.length > 0) {
|
|
11707
|
-
const filteredCalls = calls.filter((call) => validCallIds.has(call.id));
|
|
11708
|
-
if (filteredCalls.length !== calls.length) {
|
|
11709
|
-
changed = true;
|
|
11710
|
-
if (filteredCalls.length === 0) {
|
|
11711
|
-
const next = { ...message };
|
|
11712
|
-
delete next.tool_calls;
|
|
11713
|
-
normalized.push(next);
|
|
11714
|
-
} else {
|
|
11715
|
-
normalized.push({ ...message, tool_calls: filteredCalls });
|
|
11716
|
-
}
|
|
11717
|
-
continue;
|
|
11718
|
-
}
|
|
11719
|
-
}
|
|
11720
|
-
normalized.push(message);
|
|
11721
|
-
continue;
|
|
11722
|
-
}
|
|
11723
|
-
if (message.role === "tool" && !validCallIds.has(message.tool_call_id)) {
|
|
11724
|
-
changed = true;
|
|
11725
|
-
continue;
|
|
11726
|
-
}
|
|
11727
|
-
normalized.push(message);
|
|
11728
|
-
}
|
|
11729
|
-
return changed ? normalized : messages;
|
|
11730
|
-
};
|
|
11731
|
-
var formatErrorForDebugLog = (error) => {
|
|
11732
|
-
const parts = [];
|
|
11733
|
-
parts.push(`name=${error.name}`);
|
|
11734
|
-
parts.push(
|
|
11735
|
-
`message=${truncateText2(error.message, DEBUG_ERROR_MESSAGE_MAX_CHARS)}`
|
|
11736
|
-
);
|
|
11737
|
-
if (error.stack) {
|
|
11738
|
-
parts.push(
|
|
11739
|
-
`stack=${truncateText2(error.stack, DEBUG_ERROR_STACK_MAX_CHARS)}`
|
|
11740
|
-
);
|
|
11741
|
-
}
|
|
11742
|
-
const causeChain = [];
|
|
11743
|
-
let depth = 0;
|
|
11744
|
-
let current = error.cause;
|
|
11745
|
-
const seen = /* @__PURE__ */ new Set();
|
|
11746
|
-
while (current !== void 0 && current !== null && depth < 4) {
|
|
11747
|
-
if (seen.has(current)) {
|
|
11748
|
-
causeChain.push("[circular]");
|
|
11749
|
-
break;
|
|
11750
|
-
}
|
|
11751
|
-
seen.add(current);
|
|
11752
|
-
if (current instanceof Error) {
|
|
11753
|
-
causeChain.push(`${current.name}: ${current.message}`);
|
|
11754
|
-
current = current.cause;
|
|
11755
|
-
depth += 1;
|
|
11756
|
-
continue;
|
|
11757
|
-
}
|
|
11758
|
-
causeChain.push(stringifyUnknown(current));
|
|
11759
|
-
break;
|
|
11760
|
-
}
|
|
11761
|
-
if (causeChain.length > 0) {
|
|
11762
|
-
parts.push(
|
|
11763
|
-
`cause_chain=${truncateText2(causeChain.join(" <- "), DEBUG_ERROR_CHAIN_MAX_CHARS)}`
|
|
11764
|
-
);
|
|
11765
|
-
}
|
|
11766
|
-
const extras = Object.entries(
|
|
11767
|
-
error
|
|
11768
|
-
).filter(([key]) => key !== "name" && key !== "message" && key !== "stack");
|
|
11769
|
-
if (extras.length > 0) {
|
|
11770
|
-
parts.push(
|
|
11771
|
-
`extras=${truncateText2(
|
|
11772
|
-
stringifyUnknown(Object.fromEntries(extras)),
|
|
11773
|
-
DEBUG_ERROR_EXTRAS_MAX_CHARS
|
|
11774
|
-
)}`
|
|
11775
|
-
);
|
|
11776
|
-
}
|
|
11777
|
-
return parts.join(" ");
|
|
11778
|
-
};
|
|
11779
|
-
var summarizeProviderMeta = (value) => {
|
|
11780
|
-
if (value === null || value === void 0) {
|
|
11781
|
-
return null;
|
|
11782
|
-
}
|
|
11783
|
-
if (typeof value === "string") {
|
|
11784
|
-
return value.length > DEBUG_PROVIDER_META_STRING_MAX_CHARS ? `${value.slice(0, DEBUG_PROVIDER_META_STRING_MAX_CHARS - 3)}...` : value;
|
|
11785
|
-
}
|
|
11786
|
-
if (Array.isArray(value)) {
|
|
11787
|
-
return `array(len=${value.length})`;
|
|
11788
|
-
}
|
|
11789
|
-
if (typeof value === "object") {
|
|
11790
|
-
const obj = value;
|
|
11791
|
-
const details = [];
|
|
11792
|
-
if (typeof obj.transport === "string") {
|
|
11793
|
-
details.push(`transport=${obj.transport}`);
|
|
11794
|
-
}
|
|
11795
|
-
if (typeof obj.websocket_mode === "string") {
|
|
11796
|
-
details.push(`websocket_mode=${obj.websocket_mode}`);
|
|
11797
|
-
}
|
|
11798
|
-
if (typeof obj.response_id === "string") {
|
|
11799
|
-
details.push(`response_id=${obj.response_id}`);
|
|
11800
|
-
}
|
|
11801
|
-
if (typeof obj.chain_reset === "boolean") {
|
|
11802
|
-
details.push(`chain_reset=${obj.chain_reset ? "true" : "false"}`);
|
|
11803
|
-
}
|
|
11804
|
-
if (typeof obj.fallback_used === "boolean") {
|
|
11805
|
-
details.push(`fallback_used=${obj.fallback_used ? "true" : "false"}`);
|
|
11806
|
-
}
|
|
11807
|
-
if (typeof obj.ws_input_mode === "string") {
|
|
11808
|
-
details.push(`ws_input_mode=${obj.ws_input_mode}`);
|
|
11809
|
-
}
|
|
11810
|
-
if (typeof obj.reasoning_requested === "string") {
|
|
11811
|
-
details.push(`reasoning_requested=${obj.reasoning_requested}`);
|
|
11812
|
-
}
|
|
11813
|
-
if (typeof obj.reasoning_applied === "string") {
|
|
11814
|
-
details.push(`reasoning_applied=${obj.reasoning_applied}`);
|
|
11815
|
-
}
|
|
11816
|
-
if (typeof obj.reasoning_fallback === "boolean") {
|
|
11817
|
-
details.push(
|
|
11818
|
-
`reasoning_fallback=${obj.reasoning_fallback ? "true" : "false"}`
|
|
11819
|
-
);
|
|
11820
|
-
}
|
|
11821
|
-
if (typeof obj.reasoning_budget_preset === "string") {
|
|
11822
|
-
details.push(`reasoning_budget_preset=${obj.reasoning_budget_preset}`);
|
|
11823
|
-
}
|
|
11824
|
-
if (details.length > 0) {
|
|
11825
|
-
return details.join(" ");
|
|
11826
|
-
}
|
|
11827
|
-
const keys = Object.keys(obj);
|
|
11828
|
-
if (keys.length === 0) return "object";
|
|
11829
|
-
const shown = keys.slice(0, 4).join(",");
|
|
11830
|
-
return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
|
|
11831
|
-
}
|
|
11832
|
-
return typeof value;
|
|
11833
|
-
};
|
|
11834
|
-
var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
|
|
11835
|
-
|
|
11836
|
-
// src/rpc/resume-context.ts
|
|
11837
|
-
var import_node_fs17 = require("fs");
|
|
11838
|
-
var import_node_path16 = __toESM(require("path"), 1);
|
|
11839
|
-
var RESUME_CONTEXT_META_KEY = "codelia_resume_context";
|
|
11840
|
-
var RESUME_CONTEXT_SCHEMA_VERSION = 1;
|
|
11841
|
-
var RESUME_DIFF_TAG = '<system-reminder type="session.resume.diff">';
|
|
11842
|
-
var MAX_RESUME_DETAIL_LINES = 3;
|
|
11843
|
-
var normalizePath2 = (value) => {
|
|
11844
|
-
if (typeof value !== "string") return void 0;
|
|
11845
|
-
const trimmed = value.trim();
|
|
11846
|
-
if (!trimmed) return void 0;
|
|
11847
|
-
return import_node_path16.default.resolve(trimmed);
|
|
11848
|
-
};
|
|
11849
|
-
var normalizeMtime3 = (value) => {
|
|
11850
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
11851
|
-
return void 0;
|
|
11852
|
-
}
|
|
11853
|
-
return Math.trunc(value);
|
|
11854
|
-
};
|
|
11855
|
-
var normalizeText = (value) => {
|
|
11856
|
-
if (typeof value !== "string") return void 0;
|
|
11857
|
-
const trimmed = value.trim();
|
|
11858
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
11859
|
-
};
|
|
11860
|
-
var normalizeApprovalMode = (value) => {
|
|
11861
|
-
if (value === "minimal" || value === "trusted" || value === "full-access") {
|
|
11862
|
-
return value;
|
|
11863
|
-
}
|
|
11864
|
-
return void 0;
|
|
11865
|
-
};
|
|
11866
|
-
var normalizeTrackedFiles = (value) => {
|
|
11867
|
-
if (!Array.isArray(value)) return [];
|
|
11868
|
-
const seen = /* @__PURE__ */ new Set();
|
|
11869
|
-
const files = [];
|
|
11870
|
-
for (const entry of value) {
|
|
11871
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11872
|
-
const record = entry;
|
|
11873
|
-
const filePath = normalizePath2(record.path);
|
|
11874
|
-
const mtime = normalizeMtime3(record.mtime_ms);
|
|
11875
|
-
if (!filePath || mtime === void 0 || seen.has(filePath)) continue;
|
|
11876
|
-
seen.add(filePath);
|
|
11877
|
-
files.push({ path: filePath, mtime_ms: mtime });
|
|
11878
|
-
}
|
|
11879
|
-
files.sort((left, right) => left.path.localeCompare(right.path));
|
|
11880
|
-
return files;
|
|
11881
|
-
};
|
|
11882
|
-
var trimDetails = (lines) => {
|
|
11883
|
-
if (lines.length <= MAX_RESUME_DETAIL_LINES) {
|
|
11884
|
-
return lines;
|
|
11885
|
-
}
|
|
11886
|
-
const remaining = lines.length - MAX_RESUME_DETAIL_LINES;
|
|
11887
|
-
return [
|
|
11888
|
-
...lines.slice(0, MAX_RESUME_DETAIL_LINES),
|
|
11889
|
-
`... and ${remaining} more change(s)`
|
|
11890
|
-
];
|
|
11693
|
+
const remaining = lines.length - MAX_RESUME_DETAIL_LINES;
|
|
11694
|
+
return [
|
|
11695
|
+
...lines.slice(0, MAX_RESUME_DETAIL_LINES),
|
|
11696
|
+
`... and ${remaining} more change(s)`
|
|
11697
|
+
];
|
|
11891
11698
|
};
|
|
11892
11699
|
var contentToString = (content) => {
|
|
11893
11700
|
if (typeof content === "string") {
|
|
@@ -11963,8 +11770,12 @@ var summarizeTrackedFileDiff = (label, savedFiles, currentFiles) => {
|
|
|
11963
11770
|
if (savedFiles.length === 0 && currentFiles.length === 0) {
|
|
11964
11771
|
return [];
|
|
11965
11772
|
}
|
|
11966
|
-
const savedByPath = new Map(
|
|
11967
|
-
|
|
11773
|
+
const savedByPath = new Map(
|
|
11774
|
+
savedFiles.map((file) => [file.path, file.mtime_ms])
|
|
11775
|
+
);
|
|
11776
|
+
const currentByPath = new Map(
|
|
11777
|
+
currentFiles.map((file) => [file.path, file.mtime_ms])
|
|
11778
|
+
);
|
|
11968
11779
|
const details = [];
|
|
11969
11780
|
for (const [filePath, savedMtime] of savedByPath) {
|
|
11970
11781
|
const currentMtime = currentByPath.get(filePath);
|
|
@@ -11989,7 +11800,9 @@ var summarizeCurrentLoadedSkillDiff = (savedSkills, currentSkills) => (async ()
|
|
|
11989
11800
|
if (savedSkills.length === 0 && currentSkills.length === 0) {
|
|
11990
11801
|
return [];
|
|
11991
11802
|
}
|
|
11992
|
-
const savedByPath = new Map(
|
|
11803
|
+
const savedByPath = new Map(
|
|
11804
|
+
savedSkills.map((file) => [file.path, file.mtime_ms])
|
|
11805
|
+
);
|
|
11993
11806
|
const currentByPath = new Map(
|
|
11994
11807
|
currentSkills.map((file) => [file.path, file.mtime_ms])
|
|
11995
11808
|
);
|
|
@@ -12092,112 +11905,507 @@ var buildResumeDiff = async (meta, state, options = {}) => {
|
|
|
12092
11905
|
if (currentWorkspaceRoot) {
|
|
12093
11906
|
contextLines.push(`Current workspace root: ${currentWorkspaceRoot}`);
|
|
12094
11907
|
}
|
|
12095
|
-
if (currentWorkingDir) {
|
|
12096
|
-
contextLines.push(`Current working directory: ${currentWorkingDir}`);
|
|
11908
|
+
if (currentWorkingDir) {
|
|
11909
|
+
contextLines.push(`Current working directory: ${currentWorkingDir}`);
|
|
11910
|
+
}
|
|
11911
|
+
if (currentSandboxRoot) {
|
|
11912
|
+
contextLines.push(`Current sandbox root: ${currentSandboxRoot}`);
|
|
11913
|
+
}
|
|
11914
|
+
if (currentApprovalMode) {
|
|
11915
|
+
contextLines.push(`Current approval mode: ${currentApprovalMode}`);
|
|
11916
|
+
}
|
|
11917
|
+
if (currentModelProvider || currentModelName) {
|
|
11918
|
+
contextLines.push(
|
|
11919
|
+
`Current model: ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
11920
|
+
);
|
|
11921
|
+
}
|
|
11922
|
+
const detailLines = [];
|
|
11923
|
+
let changed = false;
|
|
11924
|
+
if (!savedContext) {
|
|
11925
|
+
detailLines.push(
|
|
11926
|
+
"Saved session has no structured resume metadata. Treat the current runtime/workspace context as authoritative."
|
|
11927
|
+
);
|
|
11928
|
+
changed = true;
|
|
11929
|
+
} else {
|
|
11930
|
+
const comparePath = (label, savedValue, currentValue) => {
|
|
11931
|
+
if (bestEffortCurrentContext && currentValue === void 0) {
|
|
11932
|
+
return;
|
|
11933
|
+
}
|
|
11934
|
+
if (savedValue === currentValue) return;
|
|
11935
|
+
changed = true;
|
|
11936
|
+
detailLines.push(
|
|
11937
|
+
`${label}: ${savedValue ?? "(unknown)"} -> ${currentValue ?? "(unknown)"}`
|
|
11938
|
+
);
|
|
11939
|
+
};
|
|
11940
|
+
comparePath(
|
|
11941
|
+
"Workspace root changed",
|
|
11942
|
+
savedContext.workspace_root,
|
|
11943
|
+
currentWorkspaceRoot
|
|
11944
|
+
);
|
|
11945
|
+
comparePath(
|
|
11946
|
+
"Working directory changed",
|
|
11947
|
+
savedContext.working_dir,
|
|
11948
|
+
currentWorkingDir
|
|
11949
|
+
);
|
|
11950
|
+
comparePath(
|
|
11951
|
+
"Sandbox root changed",
|
|
11952
|
+
savedContext.sandbox_root,
|
|
11953
|
+
currentSandboxRoot
|
|
11954
|
+
);
|
|
11955
|
+
if (savedContext.approval_mode !== currentApprovalMode && (!bestEffortCurrentContext || currentApprovalMode !== void 0)) {
|
|
11956
|
+
changed = true;
|
|
11957
|
+
detailLines.push(
|
|
11958
|
+
`Approval mode changed: ${savedContext.approval_mode ?? "(unknown)"} -> ${currentApprovalMode ?? "(unknown)"}`
|
|
11959
|
+
);
|
|
11960
|
+
}
|
|
11961
|
+
if ((savedContext.model_provider !== currentModelProvider || savedContext.model_name !== currentModelName) && (!bestEffortCurrentContext || currentModelProvider !== void 0 || currentModelName !== void 0)) {
|
|
11962
|
+
changed = true;
|
|
11963
|
+
detailLines.push(
|
|
11964
|
+
`Model changed: ${savedContext.model_provider ?? "(unknown provider)"}/${savedContext.model_name ?? "(unknown model)"} -> ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
11965
|
+
);
|
|
11966
|
+
}
|
|
11967
|
+
if (!(bestEffortCurrentContext && !currentInitialAgentsKnown)) {
|
|
11968
|
+
const agentDiffs = summarizeTrackedFileDiff(
|
|
11969
|
+
"Initial AGENTS",
|
|
11970
|
+
savedContext.initial_agents ?? [],
|
|
11971
|
+
currentAgents
|
|
11972
|
+
);
|
|
11973
|
+
if (agentDiffs.length > 0) {
|
|
11974
|
+
changed = true;
|
|
11975
|
+
detailLines.push(...agentDiffs);
|
|
11976
|
+
}
|
|
11977
|
+
}
|
|
11978
|
+
const skillDiffs = await summarizeCurrentLoadedSkillDiff(
|
|
11979
|
+
savedContext.loaded_skills ?? [],
|
|
11980
|
+
currentLoadedSkills
|
|
11981
|
+
);
|
|
11982
|
+
if (skillDiffs.length > 0) {
|
|
11983
|
+
changed = true;
|
|
11984
|
+
detailLines.push(...skillDiffs);
|
|
11985
|
+
}
|
|
11986
|
+
if (!changed) {
|
|
11987
|
+
detailLines.push(
|
|
11988
|
+
"No material workspace/AGENTS/skill changes were detected from saved resume metadata."
|
|
11989
|
+
);
|
|
11990
|
+
}
|
|
11991
|
+
}
|
|
11992
|
+
if (contextLines.length === 0 && detailLines.length === 0) {
|
|
11993
|
+
return null;
|
|
11994
|
+
}
|
|
11995
|
+
const summaryLines = [
|
|
11996
|
+
"Resume context:",
|
|
11997
|
+
...contextLines.map((line) => `- ${line}`),
|
|
11998
|
+
...detailLines.map((line) => `- ${line}`)
|
|
11999
|
+
];
|
|
12000
|
+
const systemLines = [
|
|
12001
|
+
'<system-reminder type="session.resume.diff">',
|
|
12002
|
+
"Session resumed in current runtime context:",
|
|
12003
|
+
...contextLines.map((line) => `- ${line}`),
|
|
12004
|
+
...detailLines.map((line) => `- ${line}`),
|
|
12005
|
+
"Use the current runtime/workspace context for subsequent actions.",
|
|
12006
|
+
"</system-reminder>"
|
|
12007
|
+
];
|
|
12008
|
+
return {
|
|
12009
|
+
summary: summaryLines.join("\n"),
|
|
12010
|
+
systemReminder: systemLines.join("\n"),
|
|
12011
|
+
changed
|
|
12012
|
+
};
|
|
12013
|
+
};
|
|
12014
|
+
|
|
12015
|
+
// src/rpc/run.ts
|
|
12016
|
+
var import_protocol5 = require("@codelia/protocol");
|
|
12017
|
+
|
|
12018
|
+
// src/rpc/client-tool-requests.ts
|
|
12019
|
+
var requestClientToolCall = async (state, params, timeoutMs) => {
|
|
12020
|
+
const id = state.nextUiRequestId();
|
|
12021
|
+
const request = {
|
|
12022
|
+
jsonrpc: "2.0",
|
|
12023
|
+
id,
|
|
12024
|
+
method: "client.tool.call",
|
|
12025
|
+
params
|
|
12026
|
+
};
|
|
12027
|
+
send(request);
|
|
12028
|
+
return await state.waitForUiResponse(id, timeoutMs);
|
|
12029
|
+
};
|
|
12030
|
+
|
|
12031
|
+
// src/tools/client.ts
|
|
12032
|
+
var DEFAULT_TIMEOUT_MS4 = 6e4;
|
|
12033
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12034
|
+
var normalizeClientToolResult = (value) => {
|
|
12035
|
+
if (typeof value === "string") {
|
|
12036
|
+
return { type: "text", text: value };
|
|
12037
|
+
}
|
|
12038
|
+
if (isRecord7(value)) {
|
|
12039
|
+
if (value.type === "text" && typeof value.text === "string") {
|
|
12040
|
+
return { type: "text", text: value.text };
|
|
12041
|
+
}
|
|
12042
|
+
if (value.type === "parts" && Array.isArray(value.parts)) {
|
|
12043
|
+
return { type: "parts", parts: value.parts };
|
|
12044
|
+
}
|
|
12045
|
+
if (value.type === "json" && "value" in value) {
|
|
12046
|
+
return { type: "json", value: value.value };
|
|
12047
|
+
}
|
|
12048
|
+
}
|
|
12049
|
+
return { type: "json", value };
|
|
12050
|
+
};
|
|
12051
|
+
var validateClientToolDefinition = (tool, existingNames) => {
|
|
12052
|
+
if (tool.type !== void 0 && tool.type !== "function") {
|
|
12053
|
+
throw new Error(`unsupported client tool type: ${String(tool.type)}`);
|
|
12054
|
+
}
|
|
12055
|
+
if (!tool.name || !/^[a-zA-Z0-9_-]+$/.test(tool.name)) {
|
|
12056
|
+
throw new Error(`invalid client tool name: ${tool.name}`);
|
|
12057
|
+
}
|
|
12058
|
+
if (existingNames.has(tool.name)) {
|
|
12059
|
+
throw new Error(
|
|
12060
|
+
`client tool name conflicts with existing tool: ${tool.name}`
|
|
12061
|
+
);
|
|
12062
|
+
}
|
|
12063
|
+
if (!tool.description.trim()) {
|
|
12064
|
+
throw new Error(`client tool description is required: ${tool.name}`);
|
|
12065
|
+
}
|
|
12066
|
+
if (!isRecord7(tool.parameters)) {
|
|
12067
|
+
throw new Error(
|
|
12068
|
+
`client tool parameters must be a JSON schema: ${tool.name}`
|
|
12069
|
+
);
|
|
12070
|
+
}
|
|
12071
|
+
if (tool.timeout_ms !== void 0 && (!Number.isFinite(tool.timeout_ms) || tool.timeout_ms <= 0)) {
|
|
12072
|
+
throw new Error(`client tool timeout_ms must be positive: ${tool.name}`);
|
|
12073
|
+
}
|
|
12074
|
+
};
|
|
12075
|
+
var createClientToolAdapters = ({
|
|
12076
|
+
runId,
|
|
12077
|
+
tools,
|
|
12078
|
+
state,
|
|
12079
|
+
existingTools
|
|
12080
|
+
}) => {
|
|
12081
|
+
if (!tools?.length) return [];
|
|
12082
|
+
const existingNames = new Set(existingTools.map((tool) => tool.name));
|
|
12083
|
+
const clientNames = /* @__PURE__ */ new Set();
|
|
12084
|
+
return tools.map((clientTool) => {
|
|
12085
|
+
validateClientToolDefinition(clientTool, existingNames);
|
|
12086
|
+
if (clientNames.has(clientTool.name)) {
|
|
12087
|
+
throw new Error(`duplicate client tool name: ${clientTool.name}`);
|
|
12088
|
+
}
|
|
12089
|
+
clientNames.add(clientTool.name);
|
|
12090
|
+
const timeoutMs = clientTool.timeout_ms ?? DEFAULT_TIMEOUT_MS4;
|
|
12091
|
+
const description = `${clientTool.description.trim()} (origin: runtime client)`;
|
|
12092
|
+
return {
|
|
12093
|
+
name: clientTool.name,
|
|
12094
|
+
description,
|
|
12095
|
+
definition: {
|
|
12096
|
+
name: clientTool.name,
|
|
12097
|
+
description,
|
|
12098
|
+
parameters: clientTool.parameters,
|
|
12099
|
+
strict: clientTool.strict ?? false
|
|
12100
|
+
},
|
|
12101
|
+
executeRaw: async (rawArgsJson) => {
|
|
12102
|
+
let args;
|
|
12103
|
+
try {
|
|
12104
|
+
const parsed = JSON.parse(rawArgsJson);
|
|
12105
|
+
args = isRecord7(parsed) ? parsed : { value: parsed };
|
|
12106
|
+
} catch (error) {
|
|
12107
|
+
throw new Error(
|
|
12108
|
+
`Invalid tool arguments JSON for ${clientTool.name}: ${String(error)}`
|
|
12109
|
+
);
|
|
12110
|
+
}
|
|
12111
|
+
const response = await requestClientToolCall(
|
|
12112
|
+
state,
|
|
12113
|
+
{
|
|
12114
|
+
run_id: runId,
|
|
12115
|
+
name: clientTool.name,
|
|
12116
|
+
arguments: args,
|
|
12117
|
+
raw_arguments: rawArgsJson
|
|
12118
|
+
},
|
|
12119
|
+
timeoutMs
|
|
12120
|
+
);
|
|
12121
|
+
if (!response.ok) {
|
|
12122
|
+
throw new Error(response.error);
|
|
12123
|
+
}
|
|
12124
|
+
return normalizeClientToolResult(response.result);
|
|
12125
|
+
}
|
|
12126
|
+
};
|
|
12127
|
+
});
|
|
12128
|
+
};
|
|
12129
|
+
|
|
12130
|
+
// src/rpc/run-debug.ts
|
|
12131
|
+
var import_core23 = require("@codelia/core");
|
|
12132
|
+
var DEBUG_MAX_CONTENT_CHARS = 2e3;
|
|
12133
|
+
var DEBUG_MAX_LOG_CHARS = 2e4;
|
|
12134
|
+
var DEBUG_MAX_EVENT_RESULT_CHARS = 500;
|
|
12135
|
+
var DEBUG_MAX_EVENT_ARGS_CHARS = 2e3;
|
|
12136
|
+
var DEBUG_ERROR_MESSAGE_MAX_CHARS = 2e3;
|
|
12137
|
+
var DEBUG_ERROR_STACK_MAX_CHARS = 8e3;
|
|
12138
|
+
var DEBUG_ERROR_CHAIN_MAX_CHARS = 4e3;
|
|
12139
|
+
var DEBUG_ERROR_EXTRAS_MAX_CHARS = 4e3;
|
|
12140
|
+
var DEBUG_PROVIDER_META_STRING_MAX_CHARS = 80;
|
|
12141
|
+
var truncateText2 = (value, maxChars) => {
|
|
12142
|
+
if (value.length <= maxChars) return value;
|
|
12143
|
+
return `${value.slice(0, maxChars)}...[truncated]`;
|
|
12144
|
+
};
|
|
12145
|
+
var stringifyUnknown = (value) => {
|
|
12146
|
+
try {
|
|
12147
|
+
return JSON.stringify(value);
|
|
12148
|
+
} catch {
|
|
12149
|
+
return String(value);
|
|
12150
|
+
}
|
|
12151
|
+
};
|
|
12152
|
+
var contentToDebugText = (content, maxChars) => {
|
|
12153
|
+
const text = (0, import_core23.stringifyContent)(content, {
|
|
12154
|
+
mode: "log",
|
|
12155
|
+
joiner: "\n",
|
|
12156
|
+
includeOtherPayload: true
|
|
12157
|
+
});
|
|
12158
|
+
return truncateText2(text, maxChars);
|
|
12159
|
+
};
|
|
12160
|
+
var buildCompactionSnapshotLog = (messages) => {
|
|
12161
|
+
const payload = messages.map((message, index) => {
|
|
12162
|
+
if (message.role === "assistant") {
|
|
12163
|
+
return {
|
|
12164
|
+
index,
|
|
12165
|
+
role: message.role,
|
|
12166
|
+
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS),
|
|
12167
|
+
tool_calls: (message.tool_calls ?? []).map((call) => ({
|
|
12168
|
+
id: call.id,
|
|
12169
|
+
name: call.function.name
|
|
12170
|
+
}))
|
|
12171
|
+
};
|
|
12172
|
+
}
|
|
12173
|
+
if (message.role === "tool") {
|
|
12174
|
+
return {
|
|
12175
|
+
index,
|
|
12176
|
+
role: message.role,
|
|
12177
|
+
tool_name: message.tool_name,
|
|
12178
|
+
tool_call_id: message.tool_call_id,
|
|
12179
|
+
is_error: message.is_error ?? false,
|
|
12180
|
+
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
12181
|
+
};
|
|
12182
|
+
}
|
|
12183
|
+
if (message.role === "reasoning") {
|
|
12184
|
+
return {
|
|
12185
|
+
index,
|
|
12186
|
+
role: message.role,
|
|
12187
|
+
content: truncateText2(message.content ?? "", DEBUG_MAX_CONTENT_CHARS)
|
|
12188
|
+
};
|
|
12189
|
+
}
|
|
12190
|
+
return {
|
|
12191
|
+
index,
|
|
12192
|
+
role: message.role,
|
|
12193
|
+
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
12194
|
+
};
|
|
12195
|
+
});
|
|
12196
|
+
return truncateText2(stringifyUnknown(payload), DEBUG_MAX_LOG_CHARS);
|
|
12197
|
+
};
|
|
12198
|
+
var logCompactionSnapshot = (log2, runId, runtimeAgent, compacted) => {
|
|
12199
|
+
if (!(0, import_logger.isDebugEnabled)()) return;
|
|
12200
|
+
const messages = runtimeAgent.getHistoryMessages();
|
|
12201
|
+
const snapshot = buildCompactionSnapshotLog(messages);
|
|
12202
|
+
log2(
|
|
12203
|
+
`compaction context snapshot run_id=${runId} compacted=${String(compacted)} messages=${messages.length} history=${snapshot}`
|
|
12204
|
+
);
|
|
12205
|
+
};
|
|
12206
|
+
var isTrackedRunEvent = (eventType) => eventType === "tool_call" || eventType === "tool_result" || eventType === "step_start" || eventType === "step_complete" || eventType === "final";
|
|
12207
|
+
var summarizeRunEvent = (event) => {
|
|
12208
|
+
switch (event.type) {
|
|
12209
|
+
case "tool_call": {
|
|
12210
|
+
const tool = typeof event.tool === "string" ? event.tool : "unknown";
|
|
12211
|
+
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
12212
|
+
const rawArgs = typeof event.raw_args === "string" ? event.raw_args : stringifyUnknown(event.args);
|
|
12213
|
+
const rawArgsSnippet = truncateText2(rawArgs, DEBUG_MAX_EVENT_ARGS_CHARS);
|
|
12214
|
+
return `type=tool_call tool=${tool} tool_call_id=${toolCallId} raw_args=${stringifyUnknown(rawArgsSnippet)}`;
|
|
12215
|
+
}
|
|
12216
|
+
case "tool_result": {
|
|
12217
|
+
const tool = typeof event.tool === "string" ? event.tool : "unknown";
|
|
12218
|
+
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
12219
|
+
const isError = event.is_error === true;
|
|
12220
|
+
const result = typeof event.result === "string" ? truncateText2(event.result, DEBUG_MAX_EVENT_RESULT_CHARS) : truncateText2(
|
|
12221
|
+
stringifyUnknown(event.result),
|
|
12222
|
+
DEBUG_MAX_EVENT_RESULT_CHARS
|
|
12223
|
+
);
|
|
12224
|
+
return `type=tool_result tool=${tool} tool_call_id=${toolCallId} is_error=${String(isError)} result=${stringifyUnknown(result)}`;
|
|
12225
|
+
}
|
|
12226
|
+
case "step_start": {
|
|
12227
|
+
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
12228
|
+
const title = typeof event.title === "string" ? event.title : "unknown";
|
|
12229
|
+
return `type=step_start step_id=${stepId} title=${title}`;
|
|
12230
|
+
}
|
|
12231
|
+
case "step_complete": {
|
|
12232
|
+
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
12233
|
+
const status = typeof event.status === "string" ? event.status : "unknown";
|
|
12234
|
+
const durationMs = typeof event.duration_ms === "number" ? event.duration_ms : -1;
|
|
12235
|
+
return `type=step_complete step_id=${stepId} status=${status} duration_ms=${durationMs}`;
|
|
12236
|
+
}
|
|
12237
|
+
case "final": {
|
|
12238
|
+
const content = typeof event.content === "string" ? event.content : "";
|
|
12239
|
+
return `type=final content_chars=${content.length}`;
|
|
12240
|
+
}
|
|
12241
|
+
default:
|
|
12242
|
+
return `type=${event.type}`;
|
|
12243
|
+
}
|
|
12244
|
+
};
|
|
12245
|
+
var logRunDebug = (log2, runId, message) => {
|
|
12246
|
+
if (!(0, import_logger.isDebugEnabled)()) return;
|
|
12247
|
+
log2(`run debug run_id=${runId} ${message}`);
|
|
12248
|
+
};
|
|
12249
|
+
var normalizeToolCallHistory = (messages) => {
|
|
12250
|
+
const assistantCallIds = /* @__PURE__ */ new Set();
|
|
12251
|
+
const toolOutputCallIds = /* @__PURE__ */ new Set();
|
|
12252
|
+
for (const message of messages) {
|
|
12253
|
+
if (message.role === "assistant") {
|
|
12254
|
+
for (const call of message.tool_calls ?? []) {
|
|
12255
|
+
assistantCallIds.add(call.id);
|
|
12256
|
+
}
|
|
12257
|
+
continue;
|
|
12258
|
+
}
|
|
12259
|
+
if (message.role === "tool") {
|
|
12260
|
+
toolOutputCallIds.add(message.tool_call_id);
|
|
12261
|
+
}
|
|
12097
12262
|
}
|
|
12098
|
-
if (
|
|
12099
|
-
|
|
12263
|
+
if (assistantCallIds.size === 0 && toolOutputCallIds.size === 0) {
|
|
12264
|
+
return messages;
|
|
12100
12265
|
}
|
|
12101
|
-
|
|
12102
|
-
|
|
12266
|
+
const validCallIds = /* @__PURE__ */ new Set();
|
|
12267
|
+
for (const callId of assistantCallIds) {
|
|
12268
|
+
if (toolOutputCallIds.has(callId)) {
|
|
12269
|
+
validCallIds.add(callId);
|
|
12270
|
+
}
|
|
12103
12271
|
}
|
|
12104
|
-
if (
|
|
12105
|
-
|
|
12106
|
-
`Current model: ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
12107
|
-
);
|
|
12272
|
+
if (validCallIds.size === assistantCallIds.size && validCallIds.size === toolOutputCallIds.size) {
|
|
12273
|
+
return messages;
|
|
12108
12274
|
}
|
|
12109
|
-
const detailLines = [];
|
|
12110
12275
|
let changed = false;
|
|
12111
|
-
|
|
12112
|
-
|
|
12113
|
-
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12276
|
+
const normalized = [];
|
|
12277
|
+
for (const message of messages) {
|
|
12278
|
+
if (message.role === "assistant") {
|
|
12279
|
+
const calls = message.tool_calls ?? [];
|
|
12280
|
+
if (calls.length > 0) {
|
|
12281
|
+
const filteredCalls = calls.filter((call) => validCallIds.has(call.id));
|
|
12282
|
+
if (filteredCalls.length !== calls.length) {
|
|
12283
|
+
changed = true;
|
|
12284
|
+
if (filteredCalls.length === 0) {
|
|
12285
|
+
const next = { ...message };
|
|
12286
|
+
delete next.tool_calls;
|
|
12287
|
+
normalized.push(next);
|
|
12288
|
+
} else {
|
|
12289
|
+
normalized.push({ ...message, tool_calls: filteredCalls });
|
|
12290
|
+
}
|
|
12291
|
+
continue;
|
|
12292
|
+
}
|
|
12120
12293
|
}
|
|
12121
|
-
|
|
12294
|
+
normalized.push(message);
|
|
12295
|
+
continue;
|
|
12296
|
+
}
|
|
12297
|
+
if (message.role === "tool" && !validCallIds.has(message.tool_call_id)) {
|
|
12122
12298
|
changed = true;
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
|
|
12126
|
-
|
|
12127
|
-
|
|
12128
|
-
|
|
12129
|
-
|
|
12130
|
-
|
|
12299
|
+
continue;
|
|
12300
|
+
}
|
|
12301
|
+
normalized.push(message);
|
|
12302
|
+
}
|
|
12303
|
+
return changed ? normalized : messages;
|
|
12304
|
+
};
|
|
12305
|
+
var formatErrorForDebugLog = (error) => {
|
|
12306
|
+
const parts = [];
|
|
12307
|
+
parts.push(`name=${error.name}`);
|
|
12308
|
+
parts.push(
|
|
12309
|
+
`message=${truncateText2(error.message, DEBUG_ERROR_MESSAGE_MAX_CHARS)}`
|
|
12310
|
+
);
|
|
12311
|
+
if (error.stack) {
|
|
12312
|
+
parts.push(
|
|
12313
|
+
`stack=${truncateText2(error.stack, DEBUG_ERROR_STACK_MAX_CHARS)}`
|
|
12131
12314
|
);
|
|
12132
|
-
|
|
12133
|
-
|
|
12134
|
-
|
|
12135
|
-
|
|
12315
|
+
}
|
|
12316
|
+
const causeChain = [];
|
|
12317
|
+
let depth = 0;
|
|
12318
|
+
let current = error.cause;
|
|
12319
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12320
|
+
while (current !== void 0 && current !== null && depth < 4) {
|
|
12321
|
+
if (seen.has(current)) {
|
|
12322
|
+
causeChain.push("[circular]");
|
|
12323
|
+
break;
|
|
12324
|
+
}
|
|
12325
|
+
seen.add(current);
|
|
12326
|
+
if (current instanceof Error) {
|
|
12327
|
+
causeChain.push(`${current.name}: ${current.message}`);
|
|
12328
|
+
current = current.cause;
|
|
12329
|
+
depth += 1;
|
|
12330
|
+
continue;
|
|
12331
|
+
}
|
|
12332
|
+
causeChain.push(stringifyUnknown(current));
|
|
12333
|
+
break;
|
|
12334
|
+
}
|
|
12335
|
+
if (causeChain.length > 0) {
|
|
12336
|
+
parts.push(
|
|
12337
|
+
`cause_chain=${truncateText2(causeChain.join(" <- "), DEBUG_ERROR_CHAIN_MAX_CHARS)}`
|
|
12136
12338
|
);
|
|
12137
|
-
|
|
12138
|
-
|
|
12139
|
-
|
|
12140
|
-
|
|
12339
|
+
}
|
|
12340
|
+
const extras = Object.entries(
|
|
12341
|
+
error
|
|
12342
|
+
).filter(([key]) => key !== "name" && key !== "message" && key !== "stack");
|
|
12343
|
+
if (extras.length > 0) {
|
|
12344
|
+
parts.push(
|
|
12345
|
+
`extras=${truncateText2(
|
|
12346
|
+
stringifyUnknown(Object.fromEntries(extras)),
|
|
12347
|
+
DEBUG_ERROR_EXTRAS_MAX_CHARS
|
|
12348
|
+
)}`
|
|
12141
12349
|
);
|
|
12142
|
-
|
|
12143
|
-
|
|
12144
|
-
|
|
12145
|
-
|
|
12146
|
-
|
|
12350
|
+
}
|
|
12351
|
+
return parts.join(" ");
|
|
12352
|
+
};
|
|
12353
|
+
var summarizeProviderMeta = (value) => {
|
|
12354
|
+
if (value === null || value === void 0) {
|
|
12355
|
+
return null;
|
|
12356
|
+
}
|
|
12357
|
+
if (typeof value === "string") {
|
|
12358
|
+
return value.length > DEBUG_PROVIDER_META_STRING_MAX_CHARS ? `${value.slice(0, DEBUG_PROVIDER_META_STRING_MAX_CHARS - 3)}...` : value;
|
|
12359
|
+
}
|
|
12360
|
+
if (Array.isArray(value)) {
|
|
12361
|
+
return `array(len=${value.length})`;
|
|
12362
|
+
}
|
|
12363
|
+
if (typeof value === "object") {
|
|
12364
|
+
const obj = value;
|
|
12365
|
+
const details = [];
|
|
12366
|
+
if (typeof obj.transport === "string") {
|
|
12367
|
+
details.push(`transport=${obj.transport}`);
|
|
12147
12368
|
}
|
|
12148
|
-
if (
|
|
12149
|
-
|
|
12150
|
-
detailLines.push(
|
|
12151
|
-
`Model changed: ${savedContext.model_provider ?? "(unknown provider)"}/${savedContext.model_name ?? "(unknown model)"} -> ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
12152
|
-
);
|
|
12369
|
+
if (typeof obj.websocket_mode === "string") {
|
|
12370
|
+
details.push(`websocket_mode=${obj.websocket_mode}`);
|
|
12153
12371
|
}
|
|
12154
|
-
if (
|
|
12155
|
-
|
|
12156
|
-
"Initial AGENTS",
|
|
12157
|
-
savedContext.initial_agents ?? [],
|
|
12158
|
-
currentAgents
|
|
12159
|
-
);
|
|
12160
|
-
if (agentDiffs.length > 0) {
|
|
12161
|
-
changed = true;
|
|
12162
|
-
detailLines.push(...agentDiffs);
|
|
12163
|
-
}
|
|
12372
|
+
if (typeof obj.response_id === "string") {
|
|
12373
|
+
details.push(`response_id=${obj.response_id}`);
|
|
12164
12374
|
}
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
currentLoadedSkills
|
|
12168
|
-
);
|
|
12169
|
-
if (skillDiffs.length > 0) {
|
|
12170
|
-
changed = true;
|
|
12171
|
-
detailLines.push(...skillDiffs);
|
|
12375
|
+
if (typeof obj.chain_reset === "boolean") {
|
|
12376
|
+
details.push(`chain_reset=${obj.chain_reset ? "true" : "false"}`);
|
|
12172
12377
|
}
|
|
12173
|
-
if (
|
|
12174
|
-
|
|
12175
|
-
|
|
12378
|
+
if (typeof obj.fallback_used === "boolean") {
|
|
12379
|
+
details.push(`fallback_used=${obj.fallback_used ? "true" : "false"}`);
|
|
12380
|
+
}
|
|
12381
|
+
if (typeof obj.ws_input_mode === "string") {
|
|
12382
|
+
details.push(`ws_input_mode=${obj.ws_input_mode}`);
|
|
12383
|
+
}
|
|
12384
|
+
if (typeof obj.reasoning_requested === "string") {
|
|
12385
|
+
details.push(`reasoning_requested=${obj.reasoning_requested}`);
|
|
12386
|
+
}
|
|
12387
|
+
if (typeof obj.reasoning_applied === "string") {
|
|
12388
|
+
details.push(`reasoning_applied=${obj.reasoning_applied}`);
|
|
12389
|
+
}
|
|
12390
|
+
if (typeof obj.reasoning_fallback === "boolean") {
|
|
12391
|
+
details.push(
|
|
12392
|
+
`reasoning_fallback=${obj.reasoning_fallback ? "true" : "false"}`
|
|
12176
12393
|
);
|
|
12177
12394
|
}
|
|
12395
|
+
if (typeof obj.reasoning_budget_preset === "string") {
|
|
12396
|
+
details.push(`reasoning_budget_preset=${obj.reasoning_budget_preset}`);
|
|
12397
|
+
}
|
|
12398
|
+
if (details.length > 0) {
|
|
12399
|
+
return details.join(" ");
|
|
12400
|
+
}
|
|
12401
|
+
const keys = Object.keys(obj);
|
|
12402
|
+
if (keys.length === 0) return "object";
|
|
12403
|
+
const shown = keys.slice(0, 4).join(",");
|
|
12404
|
+
return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
|
|
12178
12405
|
}
|
|
12179
|
-
|
|
12180
|
-
return null;
|
|
12181
|
-
}
|
|
12182
|
-
const summaryLines = [
|
|
12183
|
-
"Resume context:",
|
|
12184
|
-
...contextLines.map((line) => `- ${line}`),
|
|
12185
|
-
...detailLines.map((line) => `- ${line}`)
|
|
12186
|
-
];
|
|
12187
|
-
const systemLines = [
|
|
12188
|
-
'<system-reminder type="session.resume.diff">',
|
|
12189
|
-
"Session resumed in current runtime context:",
|
|
12190
|
-
...contextLines.map((line) => `- ${line}`),
|
|
12191
|
-
...detailLines.map((line) => `- ${line}`),
|
|
12192
|
-
"Use the current runtime/workspace context for subsequent actions.",
|
|
12193
|
-
"</system-reminder>"
|
|
12194
|
-
];
|
|
12195
|
-
return {
|
|
12196
|
-
summary: summaryLines.join("\n"),
|
|
12197
|
-
systemReminder: systemLines.join("\n"),
|
|
12198
|
-
changed
|
|
12199
|
-
};
|
|
12406
|
+
return typeof value;
|
|
12200
12407
|
};
|
|
12408
|
+
var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
|
|
12201
12409
|
|
|
12202
12410
|
// src/rpc/skill-mentions.ts
|
|
12203
12411
|
var SKILL_MENTION_PATTERN = /\$([a-z0-9]+(?:-[a-z0-9]+)*)/g;
|
|
@@ -12538,6 +12746,24 @@ var createRunHandlers = ({
|
|
|
12538
12746
|
};
|
|
12539
12747
|
}
|
|
12540
12748
|
const runId = state.nextRunId();
|
|
12749
|
+
let clientTools;
|
|
12750
|
+
try {
|
|
12751
|
+
clientTools = createClientToolAdapters({
|
|
12752
|
+
runId,
|
|
12753
|
+
tools: params.tools,
|
|
12754
|
+
state,
|
|
12755
|
+
existingTools: state.tools ?? []
|
|
12756
|
+
});
|
|
12757
|
+
state.autoApprovedClientToolNames = new Set(
|
|
12758
|
+
(params.tools ?? []).filter((tool) => tool.approval === "never").map((tool) => tool.name)
|
|
12759
|
+
);
|
|
12760
|
+
} catch (error) {
|
|
12761
|
+
sendError(id, {
|
|
12762
|
+
code: import_protocol5.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
12763
|
+
message: String(error)
|
|
12764
|
+
});
|
|
12765
|
+
return;
|
|
12766
|
+
}
|
|
12541
12767
|
const startedAt = nowIso5();
|
|
12542
12768
|
state.beginRun(runId, params.ui_context ?? state.lastUiContext);
|
|
12543
12769
|
const runAbortController = new AbortController();
|
|
@@ -12668,10 +12894,17 @@ var createRunHandlers = ({
|
|
|
12668
12894
|
model: modelConfig ? {
|
|
12669
12895
|
provider: modelConfig.provider,
|
|
12670
12896
|
name: modelConfig.name,
|
|
12671
|
-
reasoning: modelConfig.reasoning
|
|
12897
|
+
reasoning: modelConfig.reasoning,
|
|
12898
|
+
...modelConfig.fast !== void 0 ? { fast: modelConfig.fast } : {}
|
|
12672
12899
|
} : void 0,
|
|
12673
12900
|
prompts: state.systemPrompt ? { system: state.systemPrompt } : void 0,
|
|
12674
|
-
tools: state.toolDefinitions ? {
|
|
12901
|
+
tools: state.toolDefinitions ? {
|
|
12902
|
+
definitions: [
|
|
12903
|
+
...state.toolDefinitions,
|
|
12904
|
+
...clientTools.map((tool) => tool.definition)
|
|
12905
|
+
],
|
|
12906
|
+
source: clientTools.length ? "runtime+client" : "runtime"
|
|
12907
|
+
} : void 0,
|
|
12675
12908
|
runtime: {
|
|
12676
12909
|
cwd: state.lastUiContext?.cwd,
|
|
12677
12910
|
os: process.platform,
|
|
@@ -12725,7 +12958,10 @@ var createRunHandlers = ({
|
|
|
12725
12958
|
);
|
|
12726
12959
|
const workspaceRoot = resolveSessionWorkspaceRoot(state);
|
|
12727
12960
|
const sessionMetaWithWorkspace = mergeWorkspaceRootIntoSessionMeta(sessionMeta, workspaceRoot);
|
|
12728
|
-
const sessionMetaWithResumeContext = mergeResumeContextIntoSessionMeta(
|
|
12961
|
+
const sessionMetaWithResumeContext = mergeResumeContextIntoSessionMeta(
|
|
12962
|
+
sessionMetaWithWorkspace,
|
|
12963
|
+
state
|
|
12964
|
+
);
|
|
12729
12965
|
const snapshot = buildSessionState(
|
|
12730
12966
|
sessionId,
|
|
12731
12967
|
runId,
|
|
@@ -12758,7 +12994,9 @@ var createRunHandlers = ({
|
|
|
12758
12994
|
for await (const event of runtimeAgent.runStream(normalizedInput, {
|
|
12759
12995
|
session,
|
|
12760
12996
|
signal: runAbortController.signal,
|
|
12761
|
-
forceCompaction: params.force_compaction
|
|
12997
|
+
forceCompaction: params.force_compaction,
|
|
12998
|
+
tools: clientTools,
|
|
12999
|
+
toolChoice: params.tool_choice
|
|
12762
13000
|
})) {
|
|
12763
13001
|
if (state.cancelRequested) {
|
|
12764
13002
|
break;
|
|
@@ -14450,6 +14688,7 @@ var RuntimeState = class {
|
|
|
14450
14688
|
executionEnvironmentDebugLogged = false;
|
|
14451
14689
|
toolDefinitions = null;
|
|
14452
14690
|
tools = null;
|
|
14691
|
+
autoApprovedClientToolNames = /* @__PURE__ */ new Set();
|
|
14453
14692
|
sessionId = null;
|
|
14454
14693
|
sessionMeta = null;
|
|
14455
14694
|
sessionAppend = null;
|
|
@@ -14485,6 +14724,7 @@ var RuntimeState = class {
|
|
|
14485
14724
|
}
|
|
14486
14725
|
this.cancelRequested = false;
|
|
14487
14726
|
this.lastContextLeftPercent = null;
|
|
14727
|
+
this.autoApprovedClientToolNames.clear();
|
|
14488
14728
|
this.runSeq.delete(runId);
|
|
14489
14729
|
if (this.activeRunId === null) {
|
|
14490
14730
|
this.sessionAppend = null;
|