@codelia/runtime 0.1.61 → 0.1.63
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 +536 -56
- package/dist/index.js +548 -68
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -23,16 +23,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/runtime.ts
|
|
26
|
-
var
|
|
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_core20 = 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
|
-
|
|
36
29
|
// src/agents/context.ts
|
|
37
30
|
var createAgentsResolverKey = (resolver) => ({
|
|
38
31
|
id: "agents-resolver",
|
|
@@ -394,6 +387,13 @@ var appendInitialAgentsContext = (systemPrompt, agentsContext) => {
|
|
|
394
387
|
${agentsContext}`;
|
|
395
388
|
};
|
|
396
389
|
|
|
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);
|
|
@@ -882,7 +882,9 @@ var normalizeExecutionEnvironmentConfig = (value) => {
|
|
|
882
882
|
...configuredCommands
|
|
883
883
|
];
|
|
884
884
|
const commands = Array.from(
|
|
885
|
-
new Map(
|
|
885
|
+
new Map(
|
|
886
|
+
baseCommands.map((command) => [command.join("\0"), command])
|
|
887
|
+
).values()
|
|
886
888
|
);
|
|
887
889
|
return {
|
|
888
890
|
startupChecks: {
|
|
@@ -2019,7 +2021,7 @@ var describeExecutionEnvironmentHost = () => {
|
|
|
2019
2021
|
};
|
|
2020
2022
|
};
|
|
2021
2023
|
var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOptions = {}) => {
|
|
2022
|
-
if (command.length === 0 || command[0]
|
|
2024
|
+
if (command.length === 0 || command[0]?.trim().length === 0) {
|
|
2023
2025
|
return Promise.resolve("invalid command");
|
|
2024
2026
|
}
|
|
2025
2027
|
return new Promise((resolve) => {
|
|
@@ -2051,7 +2053,9 @@ var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOpt
|
|
|
2051
2053
|
workingDir
|
|
2052
2054
|
);
|
|
2053
2055
|
} catch (error) {
|
|
2054
|
-
finish(
|
|
2056
|
+
finish(
|
|
2057
|
+
`error: ${error instanceof Error ? error.message : String(error)}`
|
|
2058
|
+
);
|
|
2055
2059
|
return;
|
|
2056
2060
|
}
|
|
2057
2061
|
timeoutHandle = setTimeout(() => {
|
|
@@ -2122,9 +2126,7 @@ var formatExecutionEnvironmentContext = (options) => {
|
|
|
2122
2126
|
if (options.startupChecks && options.startupChecks.length > 0) {
|
|
2123
2127
|
lines.push("", "startup checks:");
|
|
2124
2128
|
for (const check of options.startupChecks) {
|
|
2125
|
-
lines.push(
|
|
2126
|
-
`- ${formatCommandLabel(check.command)} => ${check.summary}`
|
|
2127
|
-
);
|
|
2129
|
+
lines.push(`- ${formatCommandLabel(check.command)} => ${check.summary}`);
|
|
2128
2130
|
}
|
|
2129
2131
|
}
|
|
2130
2132
|
lines.push("</execution_environment>");
|
|
@@ -6169,7 +6171,9 @@ var createReadLineTool = (sandboxKey) => (0, import_core9.defineTool)({
|
|
|
6169
6171
|
),
|
|
6170
6172
|
line_number: import_zod8.z.number().int().positive().describe("1-based line number to read."),
|
|
6171
6173
|
char_offset: import_zod8.z.number().int().nonnegative().optional().describe("0-based grapheme offset in the target line. Default 0."),
|
|
6172
|
-
char_limit: import_zod8.z.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
|
|
6174
|
+
char_limit: import_zod8.z.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
|
|
6175
|
+
`Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`
|
|
6176
|
+
)
|
|
6173
6177
|
}),
|
|
6174
6178
|
execute: async (input, ctx) => {
|
|
6175
6179
|
let resolved;
|
|
@@ -7617,7 +7621,9 @@ var createSkillSearchTool = (skillsResolverKey) => (0, import_core13.defineTool)
|
|
|
7617
7621
|
description: "Search installed local skills by name, description, or path.",
|
|
7618
7622
|
input: import_zod12.z.object({
|
|
7619
7623
|
query: import_zod12.z.string().min(1).describe("Search query text."),
|
|
7620
|
-
limit: import_zod12.z.number().int().positive().optional().describe(
|
|
7624
|
+
limit: import_zod12.z.number().int().positive().optional().describe(
|
|
7625
|
+
"Optional max result count. Higher values may be clamped by config."
|
|
7626
|
+
),
|
|
7621
7627
|
scope: import_zod12.z.enum(["repo", "user"]).optional().describe("Optional scope filter.")
|
|
7622
7628
|
}),
|
|
7623
7629
|
execute: async (input, ctx) => {
|
|
@@ -8079,7 +8085,9 @@ var createViewImageTool = (sandboxKey) => (0, import_core17.defineTool)({
|
|
|
8079
8085
|
file_path: import_zod16.z.string().describe(
|
|
8080
8086
|
"Single local png/jpeg/webp/gif image path. Sandbox-bounded unless full-access mode is active."
|
|
8081
8087
|
),
|
|
8082
|
-
detail: import_zod16.z.enum(["auto", "low", "high"]).optional().describe(
|
|
8088
|
+
detail: import_zod16.z.enum(["auto", "low", "high"]).optional().describe(
|
|
8089
|
+
"Model image-detail hint (`auto`/`low`/`high`). Default auto."
|
|
8090
|
+
),
|
|
8083
8091
|
max_bytes: import_zod16.z.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
|
|
8084
8092
|
}),
|
|
8085
8093
|
execute: async (input, ctx) => {
|
|
@@ -8390,8 +8398,12 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
|
|
|
8390
8398
|
input: import_zod17.z.object({
|
|
8391
8399
|
url: import_zod17.z.string().min(1).describe("HTTP(S) URL to fetch."),
|
|
8392
8400
|
output_format: import_zod17.z.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
|
|
8393
|
-
timeout_ms: import_zod17.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
|
|
8394
|
-
|
|
8401
|
+
timeout_ms: import_zod17.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
|
|
8402
|
+
`Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`
|
|
8403
|
+
),
|
|
8404
|
+
max_bytes: import_zod17.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
|
|
8405
|
+
`Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`
|
|
8406
|
+
)
|
|
8395
8407
|
}),
|
|
8396
8408
|
execute: async (input) => {
|
|
8397
8409
|
let url;
|
|
@@ -8406,6 +8418,7 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
|
|
|
8406
8418
|
const timeoutMs = input.timeout_ms ?? DEFAULT_TIMEOUT_MS3;
|
|
8407
8419
|
const maxBytes = input.max_bytes ?? DEFAULT_MAX_BYTES3;
|
|
8408
8420
|
const outputFormat = input.output_format ?? "markdown";
|
|
8421
|
+
const startedAt = Date.now();
|
|
8409
8422
|
const controller = new AbortController();
|
|
8410
8423
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
8411
8424
|
try {
|
|
@@ -8435,6 +8448,7 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
|
|
|
8435
8448
|
} else {
|
|
8436
8449
|
content = normalizeWhitespace(rawText);
|
|
8437
8450
|
}
|
|
8451
|
+
const durationMs = Math.max(0, Date.now() - startedAt);
|
|
8438
8452
|
return {
|
|
8439
8453
|
url: input.url,
|
|
8440
8454
|
final_url: response.url || input.url,
|
|
@@ -8445,7 +8459,8 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
|
|
|
8445
8459
|
title: isHtml ? extractTitle(rawText) ?? null : null,
|
|
8446
8460
|
content,
|
|
8447
8461
|
truncated: body.truncated,
|
|
8448
|
-
byte_size: body.byteSize
|
|
8462
|
+
byte_size: body.byteSize,
|
|
8463
|
+
duration_ms: durationMs
|
|
8449
8464
|
};
|
|
8450
8465
|
} catch (error) {
|
|
8451
8466
|
const classified = classifyFetchError(error, timeoutMs);
|
|
@@ -8601,9 +8616,9 @@ var normalizeLanguage = (value) => {
|
|
|
8601
8616
|
};
|
|
8602
8617
|
var languageFromFilePath = (filePath) => {
|
|
8603
8618
|
if (!filePath) return void 0;
|
|
8604
|
-
const
|
|
8605
|
-
if (!
|
|
8606
|
-
const normalizedPath =
|
|
8619
|
+
const path21 = filePath.trim().replace(/^["']|["']$/g, "");
|
|
8620
|
+
if (!path21 || path21 === "/dev/null") return void 0;
|
|
8621
|
+
const normalizedPath = path21.replace(/^a\//, "").replace(/^b\//, "");
|
|
8607
8622
|
const lastSlash = Math.max(
|
|
8608
8623
|
normalizedPath.lastIndexOf("/"),
|
|
8609
8624
|
normalizedPath.lastIndexOf("\\")
|
|
@@ -9035,6 +9050,7 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9035
9050
|
state.updateSkillsSnapshot(ctx.workingDir, skillsResolver.getSnapshot());
|
|
9036
9051
|
state.runtimeWorkingDir = ctx.workingDir;
|
|
9037
9052
|
state.runtimeSandboxRoot = ctx.rootDir;
|
|
9053
|
+
state.approvalMode = approvalModeResolution.approvalMode;
|
|
9038
9054
|
const sandboxKey = createSandboxKey(ctx);
|
|
9039
9055
|
const todoSessionContextKey = createToolSessionContextKey(
|
|
9040
9056
|
() => state.sessionId
|
|
@@ -9156,10 +9172,12 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9156
9172
|
...hostedSearchDefinitions
|
|
9157
9173
|
];
|
|
9158
9174
|
let llm;
|
|
9175
|
+
let resolvedModelName = null;
|
|
9159
9176
|
const requestedReasoning = resolveReasoningEffort(modelConfig.reasoning) ?? "medium";
|
|
9160
9177
|
switch (provider) {
|
|
9161
9178
|
case "openai": {
|
|
9162
9179
|
const modelName = modelConfig.name ?? import_core20.OPENAI_DEFAULT_MODEL;
|
|
9180
|
+
resolvedModelName = modelName;
|
|
9163
9181
|
const providerModelName = (0, import_core20.resolveProviderModelId)(
|
|
9164
9182
|
import_core20.DEFAULT_MODEL_REGISTRY,
|
|
9165
9183
|
modelName,
|
|
@@ -9186,6 +9204,7 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9186
9204
|
}
|
|
9187
9205
|
case "openrouter": {
|
|
9188
9206
|
const modelName = modelConfig.name ?? import_core20.OPENAI_DEFAULT_MODEL;
|
|
9207
|
+
resolvedModelName = modelName;
|
|
9189
9208
|
const reasoning = resolveResponsesReasoning({
|
|
9190
9209
|
model: modelName,
|
|
9191
9210
|
requested: requestedReasoning
|
|
@@ -9204,6 +9223,7 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9204
9223
|
}
|
|
9205
9224
|
case "anthropic": {
|
|
9206
9225
|
const modelName = modelConfig.name ?? import_core20.ANTHROPIC_DEFAULT_MODEL;
|
|
9226
|
+
resolvedModelName = modelName;
|
|
9207
9227
|
const reasoning = resolveAnthropicReasoning({
|
|
9208
9228
|
model: modelName,
|
|
9209
9229
|
requested: requestedReasoning,
|
|
@@ -9242,6 +9262,8 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9242
9262
|
default:
|
|
9243
9263
|
throw new Error(`Unsupported model.provider: ${provider}`);
|
|
9244
9264
|
}
|
|
9265
|
+
state.currentModelProvider = provider;
|
|
9266
|
+
state.currentModelName = resolvedModelName;
|
|
9245
9267
|
const modelRegistry = await buildModelRegistry(llm, {
|
|
9246
9268
|
strict: provider !== "openrouter"
|
|
9247
9269
|
});
|
|
@@ -9989,8 +10011,8 @@ var parseAuthorizationServerMetadata = (value) => {
|
|
|
9989
10011
|
var buildAuthorizationServerMetadataUrl = (issuer) => {
|
|
9990
10012
|
try {
|
|
9991
10013
|
const parsed = new URL(issuer);
|
|
9992
|
-
const
|
|
9993
|
-
const basePath =
|
|
10014
|
+
const path21 = parsed.pathname === "/" ? "" : parsed.pathname;
|
|
10015
|
+
const basePath = path21.startsWith("/") ? path21 : `/${path21}`;
|
|
9994
10016
|
const metadataPath = `/.well-known/oauth-authorization-server${basePath}`;
|
|
9995
10017
|
return new URL(metadataPath, `${parsed.origin}/`).toString();
|
|
9996
10018
|
} catch {
|
|
@@ -10967,10 +10989,19 @@ var sendHistoryEvent = (runId, seq, event) => {
|
|
|
10967
10989
|
};
|
|
10968
10990
|
var createHistoryHandlers = ({
|
|
10969
10991
|
sessionStateStore,
|
|
10970
|
-
log: log2
|
|
10992
|
+
log: log2,
|
|
10993
|
+
getCurrentWorkspaceRoot,
|
|
10994
|
+
buildResumeDiffSummary
|
|
10971
10995
|
}) => {
|
|
10996
|
+
const normalizeWorkspaceRoot = (value) => {
|
|
10997
|
+
if (typeof value !== "string") return void 0;
|
|
10998
|
+
const trimmed = value.trim();
|
|
10999
|
+
if (!trimmed) return void 0;
|
|
11000
|
+
return import_node_path15.default.resolve(trimmed);
|
|
11001
|
+
};
|
|
10972
11002
|
const handleSessionList = async (id, params) => {
|
|
10973
11003
|
const limit = params?.limit ?? 50;
|
|
11004
|
+
const scope = params?.scope ?? "current_workspace";
|
|
10974
11005
|
let sessions;
|
|
10975
11006
|
try {
|
|
10976
11007
|
sessions = await sessionStateStore.list();
|
|
@@ -10981,11 +11012,20 @@ var createHistoryHandlers = ({
|
|
|
10981
11012
|
});
|
|
10982
11013
|
return;
|
|
10983
11014
|
}
|
|
10984
|
-
const
|
|
11015
|
+
const requestedWorkspaceRoot = scope === "all" ? void 0 : normalizeWorkspaceRoot(
|
|
11016
|
+
params?.workspace_root ?? getCurrentWorkspaceRoot?.()
|
|
11017
|
+
);
|
|
11018
|
+
const workspaceFiltered = requestedWorkspaceRoot === void 0 ? sessions : sessions.filter(
|
|
11019
|
+
(session) => normalizeWorkspaceRoot(session.workspace_root) === requestedWorkspaceRoot
|
|
11020
|
+
);
|
|
11021
|
+
const sorted = workspaceFiltered.sort(
|
|
10985
11022
|
(a, b) => b.updated_at.localeCompare(a.updated_at)
|
|
10986
11023
|
);
|
|
10987
11024
|
const filtered = limit > 0 ? sorted.slice(0, limit) : sorted.slice();
|
|
10988
|
-
const result = {
|
|
11025
|
+
const result = {
|
|
11026
|
+
sessions: filtered,
|
|
11027
|
+
current_workspace_root: requestedWorkspaceRoot
|
|
11028
|
+
};
|
|
10989
11029
|
sendResult(id, result);
|
|
10990
11030
|
};
|
|
10991
11031
|
const handleSessionHistory = async (id, params) => {
|
|
@@ -11046,10 +11086,22 @@ var createHistoryHandlers = ({
|
|
|
11046
11086
|
for (const event of selectedEvents) {
|
|
11047
11087
|
sendHistoryEvent(event.runId, event.seq, event.event);
|
|
11048
11088
|
}
|
|
11089
|
+
let resumeDiff;
|
|
11090
|
+
if (buildResumeDiffSummary) {
|
|
11091
|
+
try {
|
|
11092
|
+
const sessionState = await sessionStateStore.load(sessionId);
|
|
11093
|
+
resumeDiff = sessionState ? await buildResumeDiffSummary(
|
|
11094
|
+
sessionState.meta ?? void 0
|
|
11095
|
+
) : void 0;
|
|
11096
|
+
} catch (error) {
|
|
11097
|
+
log2(`session.history resume diff error: ${String(error)}`);
|
|
11098
|
+
}
|
|
11099
|
+
}
|
|
11049
11100
|
const result = {
|
|
11050
11101
|
runs: runs.length,
|
|
11051
11102
|
events_sent: selectedEvents.length,
|
|
11052
|
-
...truncated ? { truncated: true } : {}
|
|
11103
|
+
...truncated ? { truncated: true } : {},
|
|
11104
|
+
...resumeDiff ? { resume_diff: resumeDiff } : {}
|
|
11053
11105
|
};
|
|
11054
11106
|
sendResult(id, result);
|
|
11055
11107
|
};
|
|
@@ -11472,6 +11524,8 @@ var createModelHandlers = ({
|
|
|
11472
11524
|
name,
|
|
11473
11525
|
...reasoning ? { reasoning } : {}
|
|
11474
11526
|
});
|
|
11527
|
+
state.currentModelProvider = provider;
|
|
11528
|
+
state.currentModelName = name;
|
|
11475
11529
|
state.agent = null;
|
|
11476
11530
|
const updatedConfig = await resolveModelConfig(workingDir);
|
|
11477
11531
|
const effectiveReasoning = resolveReasoningEffort(
|
|
@@ -11779,6 +11833,372 @@ var summarizeProviderMeta = (value) => {
|
|
|
11779
11833
|
};
|
|
11780
11834
|
var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
|
|
11781
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
|
+
];
|
|
11891
|
+
};
|
|
11892
|
+
var contentToString = (content) => {
|
|
11893
|
+
if (typeof content === "string") {
|
|
11894
|
+
return content;
|
|
11895
|
+
}
|
|
11896
|
+
if (!Array.isArray(content)) {
|
|
11897
|
+
return "";
|
|
11898
|
+
}
|
|
11899
|
+
return content.map((part) => {
|
|
11900
|
+
if (!part || typeof part !== "object") return "";
|
|
11901
|
+
if ("type" in part && part.type === "text" && typeof part.text === "string") {
|
|
11902
|
+
return part.text;
|
|
11903
|
+
}
|
|
11904
|
+
return "";
|
|
11905
|
+
}).join("");
|
|
11906
|
+
};
|
|
11907
|
+
var isResumeDiffSystemMessage = (message) => message.role === "system" && contentToString(message.content).includes(RESUME_DIFF_TAG);
|
|
11908
|
+
var resolveWorkspaceRoot = (state) => normalizePath2(
|
|
11909
|
+
state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir
|
|
11910
|
+
);
|
|
11911
|
+
var collectCurrentInitialAgents = (state) => {
|
|
11912
|
+
const snapshot = state.agentsResolver?.getSnapshot();
|
|
11913
|
+
if (!snapshot) return [];
|
|
11914
|
+
return snapshot.initialFiles.map((file) => ({
|
|
11915
|
+
path: normalizePath2(file.path),
|
|
11916
|
+
mtime_ms: normalizeMtime3(file.mtimeMs)
|
|
11917
|
+
})).filter(
|
|
11918
|
+
(entry) => entry.path !== void 0 && entry.mtime_ms !== void 0
|
|
11919
|
+
).sort((left, right) => left.path.localeCompare(right.path));
|
|
11920
|
+
};
|
|
11921
|
+
var collectCurrentLoadedSkills = (state) => {
|
|
11922
|
+
const snapshot = state.skillsResolver?.getSnapshot();
|
|
11923
|
+
if (!snapshot) return [];
|
|
11924
|
+
return snapshot.loaded_versions.map((entry) => ({
|
|
11925
|
+
path: normalizePath2(entry.path),
|
|
11926
|
+
mtime_ms: normalizeMtime3(entry.mtime_ms)
|
|
11927
|
+
})).filter(
|
|
11928
|
+
(entry) => entry.path !== void 0 && entry.mtime_ms !== void 0
|
|
11929
|
+
).sort((left, right) => left.path.localeCompare(right.path));
|
|
11930
|
+
};
|
|
11931
|
+
var parseResumeContextMeta = (meta) => {
|
|
11932
|
+
const raw = meta?.[RESUME_CONTEXT_META_KEY];
|
|
11933
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
11934
|
+
return null;
|
|
11935
|
+
}
|
|
11936
|
+
const record = raw;
|
|
11937
|
+
const schemaVersion = record.schema_version;
|
|
11938
|
+
if (schemaVersion !== RESUME_CONTEXT_SCHEMA_VERSION) {
|
|
11939
|
+
return null;
|
|
11940
|
+
}
|
|
11941
|
+
const workspaceRoot = normalizePath2(record.workspace_root);
|
|
11942
|
+
const workingDir = normalizePath2(record.working_dir);
|
|
11943
|
+
const sandboxRoot = normalizePath2(record.sandbox_root);
|
|
11944
|
+
const approvalMode = normalizeApprovalMode(record.approval_mode);
|
|
11945
|
+
const modelProvider = normalizeText(record.model_provider);
|
|
11946
|
+
const modelName = normalizeText(record.model_name);
|
|
11947
|
+
const initialAgents = normalizeTrackedFiles(record.initial_agents);
|
|
11948
|
+
const loadedSkills = normalizeTrackedFiles(record.loaded_skills);
|
|
11949
|
+
return {
|
|
11950
|
+
schema_version: RESUME_CONTEXT_SCHEMA_VERSION,
|
|
11951
|
+
...workspaceRoot ? { workspace_root: workspaceRoot } : {},
|
|
11952
|
+
...workingDir ? { working_dir: workingDir } : {},
|
|
11953
|
+
...sandboxRoot ? { sandbox_root: sandboxRoot } : {},
|
|
11954
|
+
...approvalMode ? { approval_mode: approvalMode } : {},
|
|
11955
|
+
...modelProvider ? { model_provider: modelProvider } : {},
|
|
11956
|
+
...modelName ? { model_name: modelName } : {},
|
|
11957
|
+
...initialAgents.length > 0 ? { initial_agents: initialAgents } : {},
|
|
11958
|
+
...loadedSkills.length > 0 ? { loaded_skills: loadedSkills } : {}
|
|
11959
|
+
};
|
|
11960
|
+
};
|
|
11961
|
+
var hasStructuredResumeContextMeta = (meta) => parseResumeContextMeta(meta) !== null;
|
|
11962
|
+
var summarizeTrackedFileDiff = (label, savedFiles, currentFiles) => {
|
|
11963
|
+
if (savedFiles.length === 0 && currentFiles.length === 0) {
|
|
11964
|
+
return [];
|
|
11965
|
+
}
|
|
11966
|
+
const savedByPath = new Map(savedFiles.map((file) => [file.path, file.mtime_ms]));
|
|
11967
|
+
const currentByPath = new Map(currentFiles.map((file) => [file.path, file.mtime_ms]));
|
|
11968
|
+
const details = [];
|
|
11969
|
+
for (const [filePath, savedMtime] of savedByPath) {
|
|
11970
|
+
const currentMtime = currentByPath.get(filePath);
|
|
11971
|
+
if (currentMtime === void 0) {
|
|
11972
|
+
details.push(`${label} removed from current context: ${filePath}`);
|
|
11973
|
+
continue;
|
|
11974
|
+
}
|
|
11975
|
+
if (currentMtime !== savedMtime) {
|
|
11976
|
+
details.push(
|
|
11977
|
+
`${label} updated: ${filePath} (mtime ${savedMtime} -> ${currentMtime})`
|
|
11978
|
+
);
|
|
11979
|
+
}
|
|
11980
|
+
}
|
|
11981
|
+
for (const [filePath] of currentByPath) {
|
|
11982
|
+
if (!savedByPath.has(filePath)) {
|
|
11983
|
+
details.push(`${label} added in current context: ${filePath}`);
|
|
11984
|
+
}
|
|
11985
|
+
}
|
|
11986
|
+
return trimDetails(details);
|
|
11987
|
+
};
|
|
11988
|
+
var summarizeCurrentLoadedSkillDiff = (savedSkills, currentSkills) => (async () => {
|
|
11989
|
+
if (savedSkills.length === 0 && currentSkills.length === 0) {
|
|
11990
|
+
return [];
|
|
11991
|
+
}
|
|
11992
|
+
const savedByPath = new Map(savedSkills.map((file) => [file.path, file.mtime_ms]));
|
|
11993
|
+
const currentByPath = new Map(
|
|
11994
|
+
currentSkills.map((file) => [file.path, file.mtime_ms])
|
|
11995
|
+
);
|
|
11996
|
+
const details = [];
|
|
11997
|
+
for (const [filePath, savedMtime] of savedByPath) {
|
|
11998
|
+
const currentLoadedMtime = currentByPath.get(filePath);
|
|
11999
|
+
if (currentLoadedMtime !== void 0) {
|
|
12000
|
+
if (currentLoadedMtime !== savedMtime) {
|
|
12001
|
+
details.push(
|
|
12002
|
+
`Loaded skill updated in current context: ${filePath} (mtime ${savedMtime} -> ${currentLoadedMtime})`
|
|
12003
|
+
);
|
|
12004
|
+
}
|
|
12005
|
+
continue;
|
|
12006
|
+
}
|
|
12007
|
+
try {
|
|
12008
|
+
const stat = await import_node_fs17.promises.stat(filePath);
|
|
12009
|
+
const currentFileMtime = normalizeMtime3(stat.mtimeMs);
|
|
12010
|
+
if (currentFileMtime !== void 0 && currentFileMtime !== savedMtime) {
|
|
12011
|
+
details.push(
|
|
12012
|
+
`Loaded skill file updated since save: ${filePath} (mtime ${savedMtime} -> ${currentFileMtime})`
|
|
12013
|
+
);
|
|
12014
|
+
}
|
|
12015
|
+
} catch {
|
|
12016
|
+
details.push(`Loaded skill file missing since save: ${filePath}`);
|
|
12017
|
+
}
|
|
12018
|
+
}
|
|
12019
|
+
for (const [filePath] of currentByPath) {
|
|
12020
|
+
if (!savedByPath.has(filePath)) {
|
|
12021
|
+
details.push(`Loaded skill added in current context: ${filePath}`);
|
|
12022
|
+
}
|
|
12023
|
+
}
|
|
12024
|
+
return trimDetails(details);
|
|
12025
|
+
})();
|
|
12026
|
+
var stripResumeDiffSystemMessages = (messages) => messages.filter((message) => !isResumeDiffSystemMessage(message));
|
|
12027
|
+
var stripStartupSystemMessages = (messages) => {
|
|
12028
|
+
let firstNonSystem = 0;
|
|
12029
|
+
while (firstNonSystem < messages.length && messages[firstNonSystem]?.role === "system") {
|
|
12030
|
+
firstNonSystem += 1;
|
|
12031
|
+
}
|
|
12032
|
+
return firstNonSystem === 0 ? messages : messages.slice(firstNonSystem);
|
|
12033
|
+
};
|
|
12034
|
+
var prependCurrentStartupSystemMessage = (messages, systemPrompt) => {
|
|
12035
|
+
const prompt = normalizeText(systemPrompt);
|
|
12036
|
+
if (!prompt) {
|
|
12037
|
+
return messages;
|
|
12038
|
+
}
|
|
12039
|
+
return [{ role: "system", content: prompt }, ...messages];
|
|
12040
|
+
};
|
|
12041
|
+
var injectResumeDiffSystemReminder = (messages, systemReminder) => {
|
|
12042
|
+
const stripped = stripResumeDiffSystemMessages(messages);
|
|
12043
|
+
const reminder = {
|
|
12044
|
+
role: "system",
|
|
12045
|
+
content: systemReminder
|
|
12046
|
+
};
|
|
12047
|
+
let insertAt = 0;
|
|
12048
|
+
while (insertAt < stripped.length && stripped[insertAt]?.role === "system") {
|
|
12049
|
+
insertAt += 1;
|
|
12050
|
+
}
|
|
12051
|
+
return [
|
|
12052
|
+
...stripped.slice(0, insertAt),
|
|
12053
|
+
reminder,
|
|
12054
|
+
...stripped.slice(insertAt)
|
|
12055
|
+
];
|
|
12056
|
+
};
|
|
12057
|
+
var mergeResumeContextIntoSessionMeta = (meta, state) => {
|
|
12058
|
+
const nextMeta = meta ? { ...meta } : {};
|
|
12059
|
+
const resumeMeta = {
|
|
12060
|
+
schema_version: RESUME_CONTEXT_SCHEMA_VERSION,
|
|
12061
|
+
...resolveWorkspaceRoot(state) ? { workspace_root: resolveWorkspaceRoot(state) } : {},
|
|
12062
|
+
...normalizePath2(state.runtimeWorkingDir) ? { working_dir: normalizePath2(state.runtimeWorkingDir) } : {},
|
|
12063
|
+
...normalizePath2(state.runtimeSandboxRoot) ? { sandbox_root: normalizePath2(state.runtimeSandboxRoot) } : {},
|
|
12064
|
+
...state.approvalMode ? { approval_mode: state.approvalMode } : {},
|
|
12065
|
+
...normalizeText(state.currentModelProvider) ? { model_provider: normalizeText(state.currentModelProvider) } : {},
|
|
12066
|
+
...normalizeText(state.currentModelName) ? { model_name: normalizeText(state.currentModelName) } : {}
|
|
12067
|
+
};
|
|
12068
|
+
const initialAgents = collectCurrentInitialAgents(state);
|
|
12069
|
+
if (initialAgents.length > 0) {
|
|
12070
|
+
resumeMeta.initial_agents = initialAgents;
|
|
12071
|
+
}
|
|
12072
|
+
const loadedSkills = collectCurrentLoadedSkills(state);
|
|
12073
|
+
if (loadedSkills.length > 0) {
|
|
12074
|
+
resumeMeta.loaded_skills = loadedSkills;
|
|
12075
|
+
}
|
|
12076
|
+
nextMeta[RESUME_CONTEXT_META_KEY] = resumeMeta;
|
|
12077
|
+
return Object.keys(nextMeta).length > 0 ? nextMeta : void 0;
|
|
12078
|
+
};
|
|
12079
|
+
var buildResumeDiff = async (meta, state, options = {}) => {
|
|
12080
|
+
const savedContext = parseResumeContextMeta(meta);
|
|
12081
|
+
const currentWorkspaceRoot = resolveWorkspaceRoot(state);
|
|
12082
|
+
const currentWorkingDir = normalizePath2(state.runtimeWorkingDir);
|
|
12083
|
+
const currentSandboxRoot = normalizePath2(state.runtimeSandboxRoot);
|
|
12084
|
+
const currentApprovalMode = normalizeApprovalMode(state.approvalMode);
|
|
12085
|
+
const currentModelProvider = normalizeText(state.currentModelProvider);
|
|
12086
|
+
const currentModelName = normalizeText(state.currentModelName);
|
|
12087
|
+
const currentAgents = collectCurrentInitialAgents(state);
|
|
12088
|
+
const currentLoadedSkills = collectCurrentLoadedSkills(state);
|
|
12089
|
+
const currentInitialAgentsKnown = state.agentsResolver !== null;
|
|
12090
|
+
const bestEffortCurrentContext = options.bestEffortCurrentContext === true;
|
|
12091
|
+
const contextLines = [];
|
|
12092
|
+
if (currentWorkspaceRoot) {
|
|
12093
|
+
contextLines.push(`Current workspace root: ${currentWorkspaceRoot}`);
|
|
12094
|
+
}
|
|
12095
|
+
if (currentWorkingDir) {
|
|
12096
|
+
contextLines.push(`Current working directory: ${currentWorkingDir}`);
|
|
12097
|
+
}
|
|
12098
|
+
if (currentSandboxRoot) {
|
|
12099
|
+
contextLines.push(`Current sandbox root: ${currentSandboxRoot}`);
|
|
12100
|
+
}
|
|
12101
|
+
if (currentApprovalMode) {
|
|
12102
|
+
contextLines.push(`Current approval mode: ${currentApprovalMode}`);
|
|
12103
|
+
}
|
|
12104
|
+
if (currentModelProvider || currentModelName) {
|
|
12105
|
+
contextLines.push(
|
|
12106
|
+
`Current model: ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
12107
|
+
);
|
|
12108
|
+
}
|
|
12109
|
+
const detailLines = [];
|
|
12110
|
+
let changed = false;
|
|
12111
|
+
if (!savedContext) {
|
|
12112
|
+
detailLines.push(
|
|
12113
|
+
"Saved session has no structured resume metadata. Treat the current runtime/workspace context as authoritative."
|
|
12114
|
+
);
|
|
12115
|
+
changed = true;
|
|
12116
|
+
} else {
|
|
12117
|
+
const comparePath = (label, savedValue, currentValue) => {
|
|
12118
|
+
if (bestEffortCurrentContext && currentValue === void 0) {
|
|
12119
|
+
return;
|
|
12120
|
+
}
|
|
12121
|
+
if (savedValue === currentValue) return;
|
|
12122
|
+
changed = true;
|
|
12123
|
+
detailLines.push(
|
|
12124
|
+
`${label}: ${savedValue ?? "(unknown)"} -> ${currentValue ?? "(unknown)"}`
|
|
12125
|
+
);
|
|
12126
|
+
};
|
|
12127
|
+
comparePath(
|
|
12128
|
+
"Workspace root changed",
|
|
12129
|
+
savedContext.workspace_root,
|
|
12130
|
+
currentWorkspaceRoot
|
|
12131
|
+
);
|
|
12132
|
+
comparePath(
|
|
12133
|
+
"Working directory changed",
|
|
12134
|
+
savedContext.working_dir,
|
|
12135
|
+
currentWorkingDir
|
|
12136
|
+
);
|
|
12137
|
+
comparePath(
|
|
12138
|
+
"Sandbox root changed",
|
|
12139
|
+
savedContext.sandbox_root,
|
|
12140
|
+
currentSandboxRoot
|
|
12141
|
+
);
|
|
12142
|
+
if (savedContext.approval_mode !== currentApprovalMode && (!bestEffortCurrentContext || currentApprovalMode !== void 0)) {
|
|
12143
|
+
changed = true;
|
|
12144
|
+
detailLines.push(
|
|
12145
|
+
`Approval mode changed: ${savedContext.approval_mode ?? "(unknown)"} -> ${currentApprovalMode ?? "(unknown)"}`
|
|
12146
|
+
);
|
|
12147
|
+
}
|
|
12148
|
+
if ((savedContext.model_provider !== currentModelProvider || savedContext.model_name !== currentModelName) && (!bestEffortCurrentContext || currentModelProvider !== void 0 || currentModelName !== void 0)) {
|
|
12149
|
+
changed = true;
|
|
12150
|
+
detailLines.push(
|
|
12151
|
+
`Model changed: ${savedContext.model_provider ?? "(unknown provider)"}/${savedContext.model_name ?? "(unknown model)"} -> ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
12152
|
+
);
|
|
12153
|
+
}
|
|
12154
|
+
if (!(bestEffortCurrentContext && !currentInitialAgentsKnown)) {
|
|
12155
|
+
const agentDiffs = summarizeTrackedFileDiff(
|
|
12156
|
+
"Initial AGENTS",
|
|
12157
|
+
savedContext.initial_agents ?? [],
|
|
12158
|
+
currentAgents
|
|
12159
|
+
);
|
|
12160
|
+
if (agentDiffs.length > 0) {
|
|
12161
|
+
changed = true;
|
|
12162
|
+
detailLines.push(...agentDiffs);
|
|
12163
|
+
}
|
|
12164
|
+
}
|
|
12165
|
+
const skillDiffs = await summarizeCurrentLoadedSkillDiff(
|
|
12166
|
+
savedContext.loaded_skills ?? [],
|
|
12167
|
+
currentLoadedSkills
|
|
12168
|
+
);
|
|
12169
|
+
if (skillDiffs.length > 0) {
|
|
12170
|
+
changed = true;
|
|
12171
|
+
detailLines.push(...skillDiffs);
|
|
12172
|
+
}
|
|
12173
|
+
if (!changed) {
|
|
12174
|
+
detailLines.push(
|
|
12175
|
+
"No material workspace/AGENTS/skill changes were detected from saved resume metadata."
|
|
12176
|
+
);
|
|
12177
|
+
}
|
|
12178
|
+
}
|
|
12179
|
+
if (contextLines.length === 0 && detailLines.length === 0) {
|
|
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
|
+
};
|
|
12200
|
+
};
|
|
12201
|
+
|
|
11782
12202
|
// src/rpc/skill-mentions.ts
|
|
11783
12203
|
var SKILL_MENTION_PATTERN = /\$([a-z0-9]+(?:-[a-z0-9]+)*)/g;
|
|
11784
12204
|
var extractSkillMentions = (value) => {
|
|
@@ -11891,6 +12311,7 @@ var runInputLengthForDebug = (input) => {
|
|
|
11891
12311
|
// src/rpc/run.ts
|
|
11892
12312
|
var nowIso5 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
11893
12313
|
var SESSION_STATE_SAVE_DEBOUNCE_MS = 1500;
|
|
12314
|
+
var SESSION_WORKSPACE_ROOT_META_KEY = "codelia_workspace_root";
|
|
11894
12315
|
var createSessionAppender = (store, onError) => {
|
|
11895
12316
|
let chain = Promise.resolve();
|
|
11896
12317
|
return (record) => {
|
|
@@ -11914,6 +12335,17 @@ var toMetaObject = (value) => {
|
|
|
11914
12335
|
}
|
|
11915
12336
|
return { ...value };
|
|
11916
12337
|
};
|
|
12338
|
+
var mergeWorkspaceRootIntoSessionMeta = (meta, workspaceRoot) => {
|
|
12339
|
+
const nextMeta = meta ? { ...meta } : {};
|
|
12340
|
+
const trimmedWorkspaceRoot = workspaceRoot?.trim();
|
|
12341
|
+
if (trimmedWorkspaceRoot) {
|
|
12342
|
+
nextMeta[SESSION_WORKSPACE_ROOT_META_KEY] = trimmedWorkspaceRoot;
|
|
12343
|
+
} else {
|
|
12344
|
+
delete nextMeta[SESSION_WORKSPACE_ROOT_META_KEY];
|
|
12345
|
+
}
|
|
12346
|
+
return Object.keys(nextMeta).length > 0 ? nextMeta : void 0;
|
|
12347
|
+
};
|
|
12348
|
+
var resolveSessionWorkspaceRoot = (state) => state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? void 0;
|
|
11917
12349
|
var toTimestampMs = (value) => {
|
|
11918
12350
|
const ms = Date.parse(value);
|
|
11919
12351
|
return Number.isFinite(ms) ? ms : null;
|
|
@@ -11952,6 +12384,26 @@ var createRunHandlers = ({
|
|
|
11952
12384
|
}
|
|
11953
12385
|
return normalizedMessages;
|
|
11954
12386
|
};
|
|
12387
|
+
const restoreSessionHistoryIntoAgent = async (options) => {
|
|
12388
|
+
const restoredMessages = Array.isArray(options.resumeState.messages) ? options.resumeState.messages : [];
|
|
12389
|
+
const messages = normalizeRestoredSessionMessages(
|
|
12390
|
+
stripStartupSystemMessages(
|
|
12391
|
+
stripResumeDiffSystemMessages(restoredMessages)
|
|
12392
|
+
),
|
|
12393
|
+
options.sessionId
|
|
12394
|
+
);
|
|
12395
|
+
const resumeDiff = await buildResumeDiff(options.resumeState.meta, state);
|
|
12396
|
+
const restoredWithCurrentStartup = prependCurrentStartupSystemMessage(
|
|
12397
|
+
messages,
|
|
12398
|
+
state.systemPrompt
|
|
12399
|
+
);
|
|
12400
|
+
options.runtimeAgent.replaceHistoryMessages(
|
|
12401
|
+
resumeDiff ? injectResumeDiffSystemReminder(
|
|
12402
|
+
restoredWithCurrentStartup,
|
|
12403
|
+
resumeDiff.systemReminder
|
|
12404
|
+
) : restoredWithCurrentStartup
|
|
12405
|
+
);
|
|
12406
|
+
};
|
|
11955
12407
|
const emitRunStatus = (runId, status, message) => {
|
|
11956
12408
|
sendRunStatus(runId, status, message);
|
|
11957
12409
|
const suffix = message ? ` message=${message}` : "";
|
|
@@ -12036,12 +12488,11 @@ var createRunHandlers = ({
|
|
|
12036
12488
|
});
|
|
12037
12489
|
return;
|
|
12038
12490
|
}
|
|
12039
|
-
|
|
12040
|
-
|
|
12041
|
-
|
|
12042
|
-
requestedSessionId
|
|
12043
|
-
);
|
|
12044
|
-
runtimeAgent.replaceHistoryMessages(messages);
|
|
12491
|
+
await restoreSessionHistoryIntoAgent({
|
|
12492
|
+
runtimeAgent,
|
|
12493
|
+
resumeState,
|
|
12494
|
+
sessionId: requestedSessionId
|
|
12495
|
+
});
|
|
12045
12496
|
sessionId = requestedSessionId;
|
|
12046
12497
|
state.sessionId = sessionId;
|
|
12047
12498
|
loadedSessionState = true;
|
|
@@ -12056,12 +12507,11 @@ var createRunHandlers = ({
|
|
|
12056
12507
|
return;
|
|
12057
12508
|
}
|
|
12058
12509
|
if (resumeState) {
|
|
12059
|
-
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
state.sessionId
|
|
12063
|
-
);
|
|
12064
|
-
runtimeAgent.replaceHistoryMessages(messages);
|
|
12510
|
+
await restoreSessionHistoryIntoAgent({
|
|
12511
|
+
runtimeAgent,
|
|
12512
|
+
resumeState,
|
|
12513
|
+
sessionId: state.sessionId
|
|
12514
|
+
});
|
|
12065
12515
|
loadedSessionState = true;
|
|
12066
12516
|
}
|
|
12067
12517
|
} else if (!state.sessionId) {
|
|
@@ -12257,7 +12707,11 @@ var createRunHandlers = ({
|
|
|
12257
12707
|
sessionSaveChain = sessionSaveChain.then(async () => {
|
|
12258
12708
|
if (!sessionId) return;
|
|
12259
12709
|
const messages = runtimeAgent.getHistoryMessages();
|
|
12260
|
-
const snapshotMessages = normalizeToolCallHistory(
|
|
12710
|
+
const snapshotMessages = normalizeToolCallHistory(
|
|
12711
|
+
stripStartupSystemMessages(
|
|
12712
|
+
stripResumeDiffSystemMessages(messages)
|
|
12713
|
+
)
|
|
12714
|
+
);
|
|
12261
12715
|
if (snapshotMessages !== messages) {
|
|
12262
12716
|
logRunDebug(
|
|
12263
12717
|
log2,
|
|
@@ -12269,15 +12723,18 @@ var createRunHandlers = ({
|
|
|
12269
12723
|
state.sessionMeta ?? void 0,
|
|
12270
12724
|
getTodosForSession(sessionId)
|
|
12271
12725
|
);
|
|
12726
|
+
const workspaceRoot = resolveSessionWorkspaceRoot(state);
|
|
12727
|
+
const sessionMetaWithWorkspace = mergeWorkspaceRootIntoSessionMeta(sessionMeta, workspaceRoot);
|
|
12728
|
+
const sessionMetaWithResumeContext = mergeResumeContextIntoSessionMeta(sessionMetaWithWorkspace, state);
|
|
12272
12729
|
const snapshot = buildSessionState(
|
|
12273
12730
|
sessionId,
|
|
12274
12731
|
runId,
|
|
12275
12732
|
snapshotMessages,
|
|
12276
12733
|
session.invoke_seq,
|
|
12277
|
-
|
|
12734
|
+
sessionMetaWithResumeContext
|
|
12278
12735
|
);
|
|
12279
12736
|
await sessionStateStore.save(snapshot);
|
|
12280
|
-
state.sessionMeta =
|
|
12737
|
+
state.sessionMeta = sessionMetaWithResumeContext ?? null;
|
|
12281
12738
|
logRunDebug(log2, runId, `session.save ${reason}`);
|
|
12282
12739
|
}).catch((error) => {
|
|
12283
12740
|
log2(`Error: session-state save failed: ${String(error)}`);
|
|
@@ -12430,7 +12887,7 @@ var createRunHandlers = ({
|
|
|
12430
12887
|
};
|
|
12431
12888
|
|
|
12432
12889
|
// src/rpc/shell.ts
|
|
12433
|
-
var
|
|
12890
|
+
var import_node_path17 = __toESM(require("path"), 1);
|
|
12434
12891
|
var import_protocol6 = require("@codelia/protocol");
|
|
12435
12892
|
var import_storage11 = require("@codelia/storage");
|
|
12436
12893
|
var COMMAND_PREVIEW_CHARS = 400;
|
|
@@ -12445,14 +12902,14 @@ var truncateCommandPreview = (value) => {
|
|
|
12445
12902
|
return `${trimmed.slice(0, COMMAND_PREVIEW_CHARS)}...[truncated]`;
|
|
12446
12903
|
};
|
|
12447
12904
|
var isWithin2 = (basePath, candidatePath) => {
|
|
12448
|
-
const relative =
|
|
12449
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
12905
|
+
const relative = import_node_path17.default.relative(basePath, candidatePath);
|
|
12906
|
+
return relative === "" || !relative.startsWith("..") && !import_node_path17.default.isAbsolute(relative);
|
|
12450
12907
|
};
|
|
12451
12908
|
var resolveShellCwd = (state, requestedCwd) => {
|
|
12452
12909
|
const workingDir = state.runtimeWorkingDir ?? process.cwd();
|
|
12453
12910
|
const rootDir = state.runtimeSandboxRoot ?? workingDir;
|
|
12454
12911
|
if (!requestedCwd) return workingDir;
|
|
12455
|
-
const resolved =
|
|
12912
|
+
const resolved = import_node_path17.default.resolve(workingDir, requestedCwd);
|
|
12456
12913
|
if (!isWithin2(rootDir, resolved)) {
|
|
12457
12914
|
return null;
|
|
12458
12915
|
}
|
|
@@ -13037,14 +13494,14 @@ var createShellHandlers = ({
|
|
|
13037
13494
|
};
|
|
13038
13495
|
|
|
13039
13496
|
// src/rpc/skills.ts
|
|
13040
|
-
var
|
|
13497
|
+
var import_node_path18 = __toESM(require("path"), 1);
|
|
13041
13498
|
var import_protocol7 = require("@codelia/protocol");
|
|
13042
13499
|
var createSkillsHandlers = ({
|
|
13043
13500
|
state,
|
|
13044
13501
|
log: log2
|
|
13045
13502
|
}) => {
|
|
13046
13503
|
const handleSkillsList = async (id, params) => {
|
|
13047
|
-
const requestedCwd = params?.cwd ?
|
|
13504
|
+
const requestedCwd = params?.cwd ? import_node_path18.default.resolve(params.cwd) : void 0;
|
|
13048
13505
|
const workingDir = requestedCwd ?? state.runtimeWorkingDir ?? state.lastUiContext?.cwd ?? process.cwd();
|
|
13049
13506
|
const forceReload = params?.force_reload ?? false;
|
|
13050
13507
|
if (!forceReload) {
|
|
@@ -13099,7 +13556,7 @@ var createSkillsHandlers = ({
|
|
|
13099
13556
|
};
|
|
13100
13557
|
|
|
13101
13558
|
// src/rpc/task.ts
|
|
13102
|
-
var
|
|
13559
|
+
var import_node_path19 = __toESM(require("path"), 1);
|
|
13103
13560
|
var import_protocol8 = require("@codelia/protocol");
|
|
13104
13561
|
var import_storage12 = require("@codelia/storage");
|
|
13105
13562
|
var DEFAULT_TRUNCATED2 = {
|
|
@@ -13134,14 +13591,14 @@ var getPublicTaskKey = (task) => {
|
|
|
13134
13591
|
return suffix ? `${toShellKeyBase2(task.label)}-${suffix}` : void 0;
|
|
13135
13592
|
};
|
|
13136
13593
|
var isWithin3 = (basePath, candidatePath) => {
|
|
13137
|
-
const relative =
|
|
13138
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
13594
|
+
const relative = import_node_path19.default.relative(basePath, candidatePath);
|
|
13595
|
+
return relative === "" || !relative.startsWith("..") && !import_node_path19.default.isAbsolute(relative);
|
|
13139
13596
|
};
|
|
13140
13597
|
var resolveShellCwd2 = (state, requestedCwd) => {
|
|
13141
13598
|
const workingDir = state.runtimeWorkingDir ?? process.cwd();
|
|
13142
13599
|
const rootDir = state.runtimeSandboxRoot ?? workingDir;
|
|
13143
13600
|
if (!requestedCwd) return workingDir;
|
|
13144
|
-
const resolved =
|
|
13601
|
+
const resolved = import_node_path19.default.resolve(workingDir, requestedCwd);
|
|
13145
13602
|
if (!isWithin3(rootDir, resolved)) {
|
|
13146
13603
|
return null;
|
|
13147
13604
|
}
|
|
@@ -13655,6 +14112,8 @@ var createRuntimeHandlers = ({
|
|
|
13655
14112
|
provider,
|
|
13656
14113
|
name: selectedModel
|
|
13657
14114
|
});
|
|
14115
|
+
state.currentModelProvider = provider;
|
|
14116
|
+
state.currentModelName = selectedModel;
|
|
13658
14117
|
state.agent = null;
|
|
13659
14118
|
log2(
|
|
13660
14119
|
`startup onboarding completed: ${provider}/${selectedModel} scope=${modelTarget.scope} path=${modelTarget.path}`
|
|
@@ -13686,7 +14145,20 @@ var createRuntimeHandlers = ({
|
|
|
13686
14145
|
});
|
|
13687
14146
|
const { handleSessionList, handleSessionHistory } = createHistoryHandlers({
|
|
13688
14147
|
sessionStateStore,
|
|
13689
|
-
log: log2
|
|
14148
|
+
log: log2,
|
|
14149
|
+
getCurrentWorkspaceRoot: () => state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? process.cwd(),
|
|
14150
|
+
buildResumeDiffSummary: async (meta) => {
|
|
14151
|
+
if (!hasStructuredResumeContextMeta(meta)) {
|
|
14152
|
+
return void 0;
|
|
14153
|
+
}
|
|
14154
|
+
const diff = await buildResumeDiff(meta, state, {
|
|
14155
|
+
bestEffortCurrentContext: true
|
|
14156
|
+
});
|
|
14157
|
+
if (!diff?.changed) {
|
|
14158
|
+
return void 0;
|
|
14159
|
+
}
|
|
14160
|
+
return diff.summary;
|
|
14161
|
+
}
|
|
13690
14162
|
});
|
|
13691
14163
|
const { handleModelList, handleModelSet } = createModelHandlers({
|
|
13692
14164
|
state,
|
|
@@ -13988,6 +14460,9 @@ var RuntimeState = class {
|
|
|
13988
14460
|
loadedSkillVersions = /* @__PURE__ */ new Map();
|
|
13989
14461
|
runtimeWorkingDir = null;
|
|
13990
14462
|
runtimeSandboxRoot = null;
|
|
14463
|
+
approvalMode = null;
|
|
14464
|
+
currentModelProvider = null;
|
|
14465
|
+
currentModelName = null;
|
|
13991
14466
|
diagnosticsEnabled = false;
|
|
13992
14467
|
nextRunId() {
|
|
13993
14468
|
return import_node_crypto9.default.randomUUID();
|
|
@@ -14091,9 +14566,14 @@ var startRuntime = () => {
|
|
|
14091
14566
|
void (async () => {
|
|
14092
14567
|
const state = new RuntimeState();
|
|
14093
14568
|
state.diagnosticsEnabled = envTruthy2(process.env.CODELIA_DIAGNOSTICS);
|
|
14094
|
-
const workingDir = process.env.CODELIA_SANDBOX_ROOT ?
|
|
14569
|
+
const workingDir = process.env.CODELIA_SANDBOX_ROOT ? import_node_path20.default.resolve(process.env.CODELIA_SANDBOX_ROOT) : process.cwd();
|
|
14095
14570
|
state.runtimeWorkingDir = workingDir;
|
|
14096
14571
|
state.runtimeSandboxRoot = workingDir;
|
|
14572
|
+
try {
|
|
14573
|
+
state.agentsResolver = await AgentsResolver.create(workingDir);
|
|
14574
|
+
} catch (error) {
|
|
14575
|
+
(0, import_logger.log)(`agents resolver startup init failed: ${String(error)}`);
|
|
14576
|
+
}
|
|
14097
14577
|
const sessionStateStore = new import_storage14.SessionStateStoreImpl({
|
|
14098
14578
|
onError: (error, context) => {
|
|
14099
14579
|
(0, import_logger.log)(
|