@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.
Files changed (3) hide show
  1. package/dist/index.cjs +536 -56
  2. package/dist/index.js +548 -68
  3. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -1,26 +1,7 @@
1
1
  // src/runtime.ts
2
- import path19 from "path";
2
+ import path20 from "path";
3
3
  import { SessionStateStoreImpl as SessionStateStoreImpl2 } from "@codelia/storage";
4
4
 
5
- // src/agent-factory.ts
6
- import { promises as fs15 } from "fs";
7
- import {
8
- Agent,
9
- ANTHROPIC_DEFAULT_MODEL,
10
- ChatAnthropic,
11
- ChatOpenAI,
12
- ChatOpenRouter,
13
- DEFAULT_MODEL_REGISTRY as DEFAULT_MODEL_REGISTRY2,
14
- OPENAI_DEFAULT_MODEL,
15
- resolveProviderModelId as resolveProviderModelId2
16
- } from "@codelia/core";
17
- import { ModelMetadataServiceImpl as ModelMetadataServiceImpl2 } from "@codelia/model-metadata";
18
- import { parseApprovalMode as parseApprovalMode2 } from "@codelia/shared-types";
19
- import {
20
- StoragePathServiceImpl as StoragePathServiceImpl3,
21
- ToolOutputCacheStoreImpl as ToolOutputCacheStoreImpl2
22
- } from "@codelia/storage";
23
-
24
5
  // src/agents/context.ts
25
6
  var createAgentsResolverKey = (resolver) => ({
26
7
  id: "agents-resolver",
@@ -382,6 +363,25 @@ var appendInitialAgentsContext = (systemPrompt, agentsContext) => {
382
363
  ${agentsContext}`;
383
364
  };
384
365
 
366
+ // src/agent-factory.ts
367
+ import { promises as fs15 } from "fs";
368
+ import {
369
+ Agent,
370
+ ANTHROPIC_DEFAULT_MODEL,
371
+ ChatAnthropic,
372
+ ChatOpenAI,
373
+ ChatOpenRouter,
374
+ DEFAULT_MODEL_REGISTRY as DEFAULT_MODEL_REGISTRY2,
375
+ OPENAI_DEFAULT_MODEL,
376
+ resolveProviderModelId as resolveProviderModelId2
377
+ } from "@codelia/core";
378
+ import { ModelMetadataServiceImpl as ModelMetadataServiceImpl2 } from "@codelia/model-metadata";
379
+ import { parseApprovalMode as parseApprovalMode2 } from "@codelia/shared-types";
380
+ import {
381
+ StoragePathServiceImpl as StoragePathServiceImpl3,
382
+ ToolOutputCacheStoreImpl as ToolOutputCacheStoreImpl2
383
+ } from "@codelia/storage";
384
+
385
385
  // src/auth/oauth-utils.ts
386
386
  import { createServer } from "http";
387
387
  import * as oauth from "oauth4webapi";
@@ -878,7 +878,9 @@ var normalizeExecutionEnvironmentConfig = (value) => {
878
878
  ...configuredCommands
879
879
  ];
880
880
  const commands = Array.from(
881
- new Map(baseCommands.map((command) => [command.join("\0"), command])).values()
881
+ new Map(
882
+ baseCommands.map((command) => [command.join("\0"), command])
883
+ ).values()
882
884
  );
883
885
  return {
884
886
  startupChecks: {
@@ -2015,7 +2017,7 @@ var describeExecutionEnvironmentHost = () => {
2015
2017
  };
2016
2018
  };
2017
2019
  var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOptions = {}) => {
2018
- if (command.length === 0 || command[0].trim().length === 0) {
2020
+ if (command.length === 0 || command[0]?.trim().length === 0) {
2019
2021
  return Promise.resolve("invalid command");
2020
2022
  }
2021
2023
  return new Promise((resolve) => {
@@ -2047,7 +2049,9 @@ var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOpt
2047
2049
  workingDir
2048
2050
  );
2049
2051
  } catch (error) {
2050
- finish(`error: ${error instanceof Error ? error.message : String(error)}`);
2052
+ finish(
2053
+ `error: ${error instanceof Error ? error.message : String(error)}`
2054
+ );
2051
2055
  return;
2052
2056
  }
2053
2057
  timeoutHandle = setTimeout(() => {
@@ -2118,9 +2122,7 @@ var formatExecutionEnvironmentContext = (options) => {
2118
2122
  if (options.startupChecks && options.startupChecks.length > 0) {
2119
2123
  lines.push("", "startup checks:");
2120
2124
  for (const check of options.startupChecks) {
2121
- lines.push(
2122
- `- ${formatCommandLabel(check.command)} => ${check.summary}`
2123
- );
2125
+ lines.push(`- ${formatCommandLabel(check.command)} => ${check.summary}`);
2124
2126
  }
2125
2127
  }
2126
2128
  lines.push("</execution_environment>");
@@ -6171,7 +6173,9 @@ var createReadLineTool = (sandboxKey) => defineTool7({
6171
6173
  ),
6172
6174
  line_number: z8.number().int().positive().describe("1-based line number to read."),
6173
6175
  char_offset: z8.number().int().nonnegative().optional().describe("0-based grapheme offset in the target line. Default 0."),
6174
- char_limit: z8.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(`Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`)
6176
+ char_limit: z8.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
6177
+ `Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`
6178
+ )
6175
6179
  }),
6176
6180
  execute: async (input, ctx) => {
6177
6181
  let resolved;
@@ -7621,7 +7625,9 @@ var createSkillSearchTool = (skillsResolverKey) => defineTool11({
7621
7625
  description: "Search installed local skills by name, description, or path.",
7622
7626
  input: z12.object({
7623
7627
  query: z12.string().min(1).describe("Search query text."),
7624
- limit: z12.number().int().positive().optional().describe("Optional max result count. Higher values may be clamped by config."),
7628
+ limit: z12.number().int().positive().optional().describe(
7629
+ "Optional max result count. Higher values may be clamped by config."
7630
+ ),
7625
7631
  scope: z12.enum(["repo", "user"]).optional().describe("Optional scope filter.")
7626
7632
  }),
7627
7633
  execute: async (input, ctx) => {
@@ -8083,7 +8089,9 @@ var createViewImageTool = (sandboxKey) => defineTool15({
8083
8089
  file_path: z16.string().describe(
8084
8090
  "Single local png/jpeg/webp/gif image path. Sandbox-bounded unless full-access mode is active."
8085
8091
  ),
8086
- detail: z16.enum(["auto", "low", "high"]).optional().describe("Model image-detail hint (`auto`/`low`/`high`). Default auto."),
8092
+ detail: z16.enum(["auto", "low", "high"]).optional().describe(
8093
+ "Model image-detail hint (`auto`/`low`/`high`). Default auto."
8094
+ ),
8087
8095
  max_bytes: z16.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
8088
8096
  }),
8089
8097
  execute: async (input, ctx) => {
@@ -8394,8 +8402,12 @@ var createWebfetchTool = () => defineTool16({
8394
8402
  input: z17.object({
8395
8403
  url: z17.string().min(1).describe("HTTP(S) URL to fetch."),
8396
8404
  output_format: z17.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
8397
- timeout_ms: z17.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(`Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`),
8398
- max_bytes: z17.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(`Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`)
8405
+ timeout_ms: z17.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
8406
+ `Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`
8407
+ ),
8408
+ max_bytes: z17.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
8409
+ `Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`
8410
+ )
8399
8411
  }),
8400
8412
  execute: async (input) => {
8401
8413
  let url;
@@ -8410,6 +8422,7 @@ var createWebfetchTool = () => defineTool16({
8410
8422
  const timeoutMs = input.timeout_ms ?? DEFAULT_TIMEOUT_MS3;
8411
8423
  const maxBytes = input.max_bytes ?? DEFAULT_MAX_BYTES3;
8412
8424
  const outputFormat = input.output_format ?? "markdown";
8425
+ const startedAt = Date.now();
8413
8426
  const controller = new AbortController();
8414
8427
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
8415
8428
  try {
@@ -8439,6 +8452,7 @@ var createWebfetchTool = () => defineTool16({
8439
8452
  } else {
8440
8453
  content = normalizeWhitespace(rawText);
8441
8454
  }
8455
+ const durationMs = Math.max(0, Date.now() - startedAt);
8442
8456
  return {
8443
8457
  url: input.url,
8444
8458
  final_url: response.url || input.url,
@@ -8449,7 +8463,8 @@ var createWebfetchTool = () => defineTool16({
8449
8463
  title: isHtml ? extractTitle(rawText) ?? null : null,
8450
8464
  content,
8451
8465
  truncated: body.truncated,
8452
- byte_size: body.byteSize
8466
+ byte_size: body.byteSize,
8467
+ duration_ms: durationMs
8453
8468
  };
8454
8469
  } catch (error) {
8455
8470
  const classified = classifyFetchError(error, timeoutMs);
@@ -8605,9 +8620,9 @@ var normalizeLanguage = (value) => {
8605
8620
  };
8606
8621
  var languageFromFilePath = (filePath) => {
8607
8622
  if (!filePath) return void 0;
8608
- const path20 = filePath.trim().replace(/^["']|["']$/g, "");
8609
- if (!path20 || path20 === "/dev/null") return void 0;
8610
- const normalizedPath = path20.replace(/^a\//, "").replace(/^b\//, "");
8623
+ const path21 = filePath.trim().replace(/^["']|["']$/g, "");
8624
+ if (!path21 || path21 === "/dev/null") return void 0;
8625
+ const normalizedPath = path21.replace(/^a\//, "").replace(/^b\//, "");
8611
8626
  const lastSlash = Math.max(
8612
8627
  normalizedPath.lastIndexOf("/"),
8613
8628
  normalizedPath.lastIndexOf("\\")
@@ -9039,6 +9054,7 @@ var createAgentFactory = (state, options = {}) => {
9039
9054
  state.updateSkillsSnapshot(ctx.workingDir, skillsResolver.getSnapshot());
9040
9055
  state.runtimeWorkingDir = ctx.workingDir;
9041
9056
  state.runtimeSandboxRoot = ctx.rootDir;
9057
+ state.approvalMode = approvalModeResolution.approvalMode;
9042
9058
  const sandboxKey = createSandboxKey(ctx);
9043
9059
  const todoSessionContextKey = createToolSessionContextKey(
9044
9060
  () => state.sessionId
@@ -9160,10 +9176,12 @@ var createAgentFactory = (state, options = {}) => {
9160
9176
  ...hostedSearchDefinitions
9161
9177
  ];
9162
9178
  let llm;
9179
+ let resolvedModelName = null;
9163
9180
  const requestedReasoning = resolveReasoningEffort(modelConfig.reasoning) ?? "medium";
9164
9181
  switch (provider) {
9165
9182
  case "openai": {
9166
9183
  const modelName = modelConfig.name ?? OPENAI_DEFAULT_MODEL;
9184
+ resolvedModelName = modelName;
9167
9185
  const providerModelName = resolveProviderModelId2(
9168
9186
  DEFAULT_MODEL_REGISTRY2,
9169
9187
  modelName,
@@ -9190,6 +9208,7 @@ var createAgentFactory = (state, options = {}) => {
9190
9208
  }
9191
9209
  case "openrouter": {
9192
9210
  const modelName = modelConfig.name ?? OPENAI_DEFAULT_MODEL;
9211
+ resolvedModelName = modelName;
9193
9212
  const reasoning = resolveResponsesReasoning({
9194
9213
  model: modelName,
9195
9214
  requested: requestedReasoning
@@ -9208,6 +9227,7 @@ var createAgentFactory = (state, options = {}) => {
9208
9227
  }
9209
9228
  case "anthropic": {
9210
9229
  const modelName = modelConfig.name ?? ANTHROPIC_DEFAULT_MODEL;
9230
+ resolvedModelName = modelName;
9211
9231
  const reasoning = resolveAnthropicReasoning({
9212
9232
  model: modelName,
9213
9233
  requested: requestedReasoning,
@@ -9246,6 +9266,8 @@ var createAgentFactory = (state, options = {}) => {
9246
9266
  default:
9247
9267
  throw new Error(`Unsupported model.provider: ${provider}`);
9248
9268
  }
9269
+ state.currentModelProvider = provider;
9270
+ state.currentModelName = resolvedModelName;
9249
9271
  const modelRegistry = await buildModelRegistry(llm, {
9250
9272
  strict: provider !== "openrouter"
9251
9273
  });
@@ -10002,8 +10024,8 @@ var parseAuthorizationServerMetadata = (value) => {
10002
10024
  var buildAuthorizationServerMetadataUrl = (issuer) => {
10003
10025
  try {
10004
10026
  const parsed = new URL(issuer);
10005
- const path20 = parsed.pathname === "/" ? "" : parsed.pathname;
10006
- const basePath = path20.startsWith("/") ? path20 : `/${path20}`;
10027
+ const path21 = parsed.pathname === "/" ? "" : parsed.pathname;
10028
+ const basePath = path21.startsWith("/") ? path21 : `/${path21}`;
10007
10029
  const metadataPath = `/.well-known/oauth-authorization-server${basePath}`;
10008
10030
  return new URL(metadataPath, `${parsed.origin}/`).toString();
10009
10031
  } catch {
@@ -10989,10 +11011,19 @@ var sendHistoryEvent = (runId, seq, event) => {
10989
11011
  };
10990
11012
  var createHistoryHandlers = ({
10991
11013
  sessionStateStore,
10992
- log: log2
11014
+ log: log2,
11015
+ getCurrentWorkspaceRoot,
11016
+ buildResumeDiffSummary
10993
11017
  }) => {
11018
+ const normalizeWorkspaceRoot = (value) => {
11019
+ if (typeof value !== "string") return void 0;
11020
+ const trimmed = value.trim();
11021
+ if (!trimmed) return void 0;
11022
+ return path15.resolve(trimmed);
11023
+ };
10994
11024
  const handleSessionList = async (id, params) => {
10995
11025
  const limit = params?.limit ?? 50;
11026
+ const scope = params?.scope ?? "current_workspace";
10996
11027
  let sessions;
10997
11028
  try {
10998
11029
  sessions = await sessionStateStore.list();
@@ -11003,11 +11034,20 @@ var createHistoryHandlers = ({
11003
11034
  });
11004
11035
  return;
11005
11036
  }
11006
- const sorted = sessions.sort(
11037
+ const requestedWorkspaceRoot = scope === "all" ? void 0 : normalizeWorkspaceRoot(
11038
+ params?.workspace_root ?? getCurrentWorkspaceRoot?.()
11039
+ );
11040
+ const workspaceFiltered = requestedWorkspaceRoot === void 0 ? sessions : sessions.filter(
11041
+ (session) => normalizeWorkspaceRoot(session.workspace_root) === requestedWorkspaceRoot
11042
+ );
11043
+ const sorted = workspaceFiltered.sort(
11007
11044
  (a, b) => b.updated_at.localeCompare(a.updated_at)
11008
11045
  );
11009
11046
  const filtered = limit > 0 ? sorted.slice(0, limit) : sorted.slice();
11010
- const result = { sessions: filtered };
11047
+ const result = {
11048
+ sessions: filtered,
11049
+ current_workspace_root: requestedWorkspaceRoot
11050
+ };
11011
11051
  sendResult(id, result);
11012
11052
  };
11013
11053
  const handleSessionHistory = async (id, params) => {
@@ -11068,10 +11108,22 @@ var createHistoryHandlers = ({
11068
11108
  for (const event of selectedEvents) {
11069
11109
  sendHistoryEvent(event.runId, event.seq, event.event);
11070
11110
  }
11111
+ let resumeDiff;
11112
+ if (buildResumeDiffSummary) {
11113
+ try {
11114
+ const sessionState = await sessionStateStore.load(sessionId);
11115
+ resumeDiff = sessionState ? await buildResumeDiffSummary(
11116
+ sessionState.meta ?? void 0
11117
+ ) : void 0;
11118
+ } catch (error) {
11119
+ log2(`session.history resume diff error: ${String(error)}`);
11120
+ }
11121
+ }
11071
11122
  const result = {
11072
11123
  runs: runs.length,
11073
11124
  events_sent: selectedEvents.length,
11074
- ...truncated ? { truncated: true } : {}
11125
+ ...truncated ? { truncated: true } : {},
11126
+ ...resumeDiff ? { resume_diff: resumeDiff } : {}
11075
11127
  };
11076
11128
  sendResult(id, result);
11077
11129
  };
@@ -11502,6 +11554,8 @@ var createModelHandlers = ({
11502
11554
  name,
11503
11555
  ...reasoning ? { reasoning } : {}
11504
11556
  });
11557
+ state.currentModelProvider = provider;
11558
+ state.currentModelName = name;
11505
11559
  state.agent = null;
11506
11560
  const updatedConfig = await resolveModelConfig(workingDir);
11507
11561
  const effectiveReasoning = resolveReasoningEffort(
@@ -11811,6 +11865,372 @@ var summarizeProviderMeta = (value) => {
11811
11865
  };
11812
11866
  var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
11813
11867
 
11868
+ // src/rpc/resume-context.ts
11869
+ import { promises as fs17 } from "fs";
11870
+ import path16 from "path";
11871
+ var RESUME_CONTEXT_META_KEY = "codelia_resume_context";
11872
+ var RESUME_CONTEXT_SCHEMA_VERSION = 1;
11873
+ var RESUME_DIFF_TAG = '<system-reminder type="session.resume.diff">';
11874
+ var MAX_RESUME_DETAIL_LINES = 3;
11875
+ var normalizePath2 = (value) => {
11876
+ if (typeof value !== "string") return void 0;
11877
+ const trimmed = value.trim();
11878
+ if (!trimmed) return void 0;
11879
+ return path16.resolve(trimmed);
11880
+ };
11881
+ var normalizeMtime3 = (value) => {
11882
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
11883
+ return void 0;
11884
+ }
11885
+ return Math.trunc(value);
11886
+ };
11887
+ var normalizeText = (value) => {
11888
+ if (typeof value !== "string") return void 0;
11889
+ const trimmed = value.trim();
11890
+ return trimmed.length > 0 ? trimmed : void 0;
11891
+ };
11892
+ var normalizeApprovalMode = (value) => {
11893
+ if (value === "minimal" || value === "trusted" || value === "full-access") {
11894
+ return value;
11895
+ }
11896
+ return void 0;
11897
+ };
11898
+ var normalizeTrackedFiles = (value) => {
11899
+ if (!Array.isArray(value)) return [];
11900
+ const seen = /* @__PURE__ */ new Set();
11901
+ const files = [];
11902
+ for (const entry of value) {
11903
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
11904
+ const record = entry;
11905
+ const filePath = normalizePath2(record.path);
11906
+ const mtime = normalizeMtime3(record.mtime_ms);
11907
+ if (!filePath || mtime === void 0 || seen.has(filePath)) continue;
11908
+ seen.add(filePath);
11909
+ files.push({ path: filePath, mtime_ms: mtime });
11910
+ }
11911
+ files.sort((left, right) => left.path.localeCompare(right.path));
11912
+ return files;
11913
+ };
11914
+ var trimDetails = (lines) => {
11915
+ if (lines.length <= MAX_RESUME_DETAIL_LINES) {
11916
+ return lines;
11917
+ }
11918
+ const remaining = lines.length - MAX_RESUME_DETAIL_LINES;
11919
+ return [
11920
+ ...lines.slice(0, MAX_RESUME_DETAIL_LINES),
11921
+ `... and ${remaining} more change(s)`
11922
+ ];
11923
+ };
11924
+ var contentToString = (content) => {
11925
+ if (typeof content === "string") {
11926
+ return content;
11927
+ }
11928
+ if (!Array.isArray(content)) {
11929
+ return "";
11930
+ }
11931
+ return content.map((part) => {
11932
+ if (!part || typeof part !== "object") return "";
11933
+ if ("type" in part && part.type === "text" && typeof part.text === "string") {
11934
+ return part.text;
11935
+ }
11936
+ return "";
11937
+ }).join("");
11938
+ };
11939
+ var isResumeDiffSystemMessage = (message) => message.role === "system" && contentToString(message.content).includes(RESUME_DIFF_TAG);
11940
+ var resolveWorkspaceRoot = (state) => normalizePath2(
11941
+ state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir
11942
+ );
11943
+ var collectCurrentInitialAgents = (state) => {
11944
+ const snapshot = state.agentsResolver?.getSnapshot();
11945
+ if (!snapshot) return [];
11946
+ return snapshot.initialFiles.map((file) => ({
11947
+ path: normalizePath2(file.path),
11948
+ mtime_ms: normalizeMtime3(file.mtimeMs)
11949
+ })).filter(
11950
+ (entry) => entry.path !== void 0 && entry.mtime_ms !== void 0
11951
+ ).sort((left, right) => left.path.localeCompare(right.path));
11952
+ };
11953
+ var collectCurrentLoadedSkills = (state) => {
11954
+ const snapshot = state.skillsResolver?.getSnapshot();
11955
+ if (!snapshot) return [];
11956
+ return snapshot.loaded_versions.map((entry) => ({
11957
+ path: normalizePath2(entry.path),
11958
+ mtime_ms: normalizeMtime3(entry.mtime_ms)
11959
+ })).filter(
11960
+ (entry) => entry.path !== void 0 && entry.mtime_ms !== void 0
11961
+ ).sort((left, right) => left.path.localeCompare(right.path));
11962
+ };
11963
+ var parseResumeContextMeta = (meta) => {
11964
+ const raw = meta?.[RESUME_CONTEXT_META_KEY];
11965
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
11966
+ return null;
11967
+ }
11968
+ const record = raw;
11969
+ const schemaVersion = record.schema_version;
11970
+ if (schemaVersion !== RESUME_CONTEXT_SCHEMA_VERSION) {
11971
+ return null;
11972
+ }
11973
+ const workspaceRoot = normalizePath2(record.workspace_root);
11974
+ const workingDir = normalizePath2(record.working_dir);
11975
+ const sandboxRoot = normalizePath2(record.sandbox_root);
11976
+ const approvalMode = normalizeApprovalMode(record.approval_mode);
11977
+ const modelProvider = normalizeText(record.model_provider);
11978
+ const modelName = normalizeText(record.model_name);
11979
+ const initialAgents = normalizeTrackedFiles(record.initial_agents);
11980
+ const loadedSkills = normalizeTrackedFiles(record.loaded_skills);
11981
+ return {
11982
+ schema_version: RESUME_CONTEXT_SCHEMA_VERSION,
11983
+ ...workspaceRoot ? { workspace_root: workspaceRoot } : {},
11984
+ ...workingDir ? { working_dir: workingDir } : {},
11985
+ ...sandboxRoot ? { sandbox_root: sandboxRoot } : {},
11986
+ ...approvalMode ? { approval_mode: approvalMode } : {},
11987
+ ...modelProvider ? { model_provider: modelProvider } : {},
11988
+ ...modelName ? { model_name: modelName } : {},
11989
+ ...initialAgents.length > 0 ? { initial_agents: initialAgents } : {},
11990
+ ...loadedSkills.length > 0 ? { loaded_skills: loadedSkills } : {}
11991
+ };
11992
+ };
11993
+ var hasStructuredResumeContextMeta = (meta) => parseResumeContextMeta(meta) !== null;
11994
+ var summarizeTrackedFileDiff = (label, savedFiles, currentFiles) => {
11995
+ if (savedFiles.length === 0 && currentFiles.length === 0) {
11996
+ return [];
11997
+ }
11998
+ const savedByPath = new Map(savedFiles.map((file) => [file.path, file.mtime_ms]));
11999
+ const currentByPath = new Map(currentFiles.map((file) => [file.path, file.mtime_ms]));
12000
+ const details = [];
12001
+ for (const [filePath, savedMtime] of savedByPath) {
12002
+ const currentMtime = currentByPath.get(filePath);
12003
+ if (currentMtime === void 0) {
12004
+ details.push(`${label} removed from current context: ${filePath}`);
12005
+ continue;
12006
+ }
12007
+ if (currentMtime !== savedMtime) {
12008
+ details.push(
12009
+ `${label} updated: ${filePath} (mtime ${savedMtime} -> ${currentMtime})`
12010
+ );
12011
+ }
12012
+ }
12013
+ for (const [filePath] of currentByPath) {
12014
+ if (!savedByPath.has(filePath)) {
12015
+ details.push(`${label} added in current context: ${filePath}`);
12016
+ }
12017
+ }
12018
+ return trimDetails(details);
12019
+ };
12020
+ var summarizeCurrentLoadedSkillDiff = (savedSkills, currentSkills) => (async () => {
12021
+ if (savedSkills.length === 0 && currentSkills.length === 0) {
12022
+ return [];
12023
+ }
12024
+ const savedByPath = new Map(savedSkills.map((file) => [file.path, file.mtime_ms]));
12025
+ const currentByPath = new Map(
12026
+ currentSkills.map((file) => [file.path, file.mtime_ms])
12027
+ );
12028
+ const details = [];
12029
+ for (const [filePath, savedMtime] of savedByPath) {
12030
+ const currentLoadedMtime = currentByPath.get(filePath);
12031
+ if (currentLoadedMtime !== void 0) {
12032
+ if (currentLoadedMtime !== savedMtime) {
12033
+ details.push(
12034
+ `Loaded skill updated in current context: ${filePath} (mtime ${savedMtime} -> ${currentLoadedMtime})`
12035
+ );
12036
+ }
12037
+ continue;
12038
+ }
12039
+ try {
12040
+ const stat = await fs17.stat(filePath);
12041
+ const currentFileMtime = normalizeMtime3(stat.mtimeMs);
12042
+ if (currentFileMtime !== void 0 && currentFileMtime !== savedMtime) {
12043
+ details.push(
12044
+ `Loaded skill file updated since save: ${filePath} (mtime ${savedMtime} -> ${currentFileMtime})`
12045
+ );
12046
+ }
12047
+ } catch {
12048
+ details.push(`Loaded skill file missing since save: ${filePath}`);
12049
+ }
12050
+ }
12051
+ for (const [filePath] of currentByPath) {
12052
+ if (!savedByPath.has(filePath)) {
12053
+ details.push(`Loaded skill added in current context: ${filePath}`);
12054
+ }
12055
+ }
12056
+ return trimDetails(details);
12057
+ })();
12058
+ var stripResumeDiffSystemMessages = (messages) => messages.filter((message) => !isResumeDiffSystemMessage(message));
12059
+ var stripStartupSystemMessages = (messages) => {
12060
+ let firstNonSystem = 0;
12061
+ while (firstNonSystem < messages.length && messages[firstNonSystem]?.role === "system") {
12062
+ firstNonSystem += 1;
12063
+ }
12064
+ return firstNonSystem === 0 ? messages : messages.slice(firstNonSystem);
12065
+ };
12066
+ var prependCurrentStartupSystemMessage = (messages, systemPrompt) => {
12067
+ const prompt = normalizeText(systemPrompt);
12068
+ if (!prompt) {
12069
+ return messages;
12070
+ }
12071
+ return [{ role: "system", content: prompt }, ...messages];
12072
+ };
12073
+ var injectResumeDiffSystemReminder = (messages, systemReminder) => {
12074
+ const stripped = stripResumeDiffSystemMessages(messages);
12075
+ const reminder = {
12076
+ role: "system",
12077
+ content: systemReminder
12078
+ };
12079
+ let insertAt = 0;
12080
+ while (insertAt < stripped.length && stripped[insertAt]?.role === "system") {
12081
+ insertAt += 1;
12082
+ }
12083
+ return [
12084
+ ...stripped.slice(0, insertAt),
12085
+ reminder,
12086
+ ...stripped.slice(insertAt)
12087
+ ];
12088
+ };
12089
+ var mergeResumeContextIntoSessionMeta = (meta, state) => {
12090
+ const nextMeta = meta ? { ...meta } : {};
12091
+ const resumeMeta = {
12092
+ schema_version: RESUME_CONTEXT_SCHEMA_VERSION,
12093
+ ...resolveWorkspaceRoot(state) ? { workspace_root: resolveWorkspaceRoot(state) } : {},
12094
+ ...normalizePath2(state.runtimeWorkingDir) ? { working_dir: normalizePath2(state.runtimeWorkingDir) } : {},
12095
+ ...normalizePath2(state.runtimeSandboxRoot) ? { sandbox_root: normalizePath2(state.runtimeSandboxRoot) } : {},
12096
+ ...state.approvalMode ? { approval_mode: state.approvalMode } : {},
12097
+ ...normalizeText(state.currentModelProvider) ? { model_provider: normalizeText(state.currentModelProvider) } : {},
12098
+ ...normalizeText(state.currentModelName) ? { model_name: normalizeText(state.currentModelName) } : {}
12099
+ };
12100
+ const initialAgents = collectCurrentInitialAgents(state);
12101
+ if (initialAgents.length > 0) {
12102
+ resumeMeta.initial_agents = initialAgents;
12103
+ }
12104
+ const loadedSkills = collectCurrentLoadedSkills(state);
12105
+ if (loadedSkills.length > 0) {
12106
+ resumeMeta.loaded_skills = loadedSkills;
12107
+ }
12108
+ nextMeta[RESUME_CONTEXT_META_KEY] = resumeMeta;
12109
+ return Object.keys(nextMeta).length > 0 ? nextMeta : void 0;
12110
+ };
12111
+ var buildResumeDiff = async (meta, state, options = {}) => {
12112
+ const savedContext = parseResumeContextMeta(meta);
12113
+ const currentWorkspaceRoot = resolveWorkspaceRoot(state);
12114
+ const currentWorkingDir = normalizePath2(state.runtimeWorkingDir);
12115
+ const currentSandboxRoot = normalizePath2(state.runtimeSandboxRoot);
12116
+ const currentApprovalMode = normalizeApprovalMode(state.approvalMode);
12117
+ const currentModelProvider = normalizeText(state.currentModelProvider);
12118
+ const currentModelName = normalizeText(state.currentModelName);
12119
+ const currentAgents = collectCurrentInitialAgents(state);
12120
+ const currentLoadedSkills = collectCurrentLoadedSkills(state);
12121
+ const currentInitialAgentsKnown = state.agentsResolver !== null;
12122
+ const bestEffortCurrentContext = options.bestEffortCurrentContext === true;
12123
+ const contextLines = [];
12124
+ if (currentWorkspaceRoot) {
12125
+ contextLines.push(`Current workspace root: ${currentWorkspaceRoot}`);
12126
+ }
12127
+ if (currentWorkingDir) {
12128
+ contextLines.push(`Current working directory: ${currentWorkingDir}`);
12129
+ }
12130
+ if (currentSandboxRoot) {
12131
+ contextLines.push(`Current sandbox root: ${currentSandboxRoot}`);
12132
+ }
12133
+ if (currentApprovalMode) {
12134
+ contextLines.push(`Current approval mode: ${currentApprovalMode}`);
12135
+ }
12136
+ if (currentModelProvider || currentModelName) {
12137
+ contextLines.push(
12138
+ `Current model: ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
12139
+ );
12140
+ }
12141
+ const detailLines = [];
12142
+ let changed = false;
12143
+ if (!savedContext) {
12144
+ detailLines.push(
12145
+ "Saved session has no structured resume metadata. Treat the current runtime/workspace context as authoritative."
12146
+ );
12147
+ changed = true;
12148
+ } else {
12149
+ const comparePath = (label, savedValue, currentValue) => {
12150
+ if (bestEffortCurrentContext && currentValue === void 0) {
12151
+ return;
12152
+ }
12153
+ if (savedValue === currentValue) return;
12154
+ changed = true;
12155
+ detailLines.push(
12156
+ `${label}: ${savedValue ?? "(unknown)"} -> ${currentValue ?? "(unknown)"}`
12157
+ );
12158
+ };
12159
+ comparePath(
12160
+ "Workspace root changed",
12161
+ savedContext.workspace_root,
12162
+ currentWorkspaceRoot
12163
+ );
12164
+ comparePath(
12165
+ "Working directory changed",
12166
+ savedContext.working_dir,
12167
+ currentWorkingDir
12168
+ );
12169
+ comparePath(
12170
+ "Sandbox root changed",
12171
+ savedContext.sandbox_root,
12172
+ currentSandboxRoot
12173
+ );
12174
+ if (savedContext.approval_mode !== currentApprovalMode && (!bestEffortCurrentContext || currentApprovalMode !== void 0)) {
12175
+ changed = true;
12176
+ detailLines.push(
12177
+ `Approval mode changed: ${savedContext.approval_mode ?? "(unknown)"} -> ${currentApprovalMode ?? "(unknown)"}`
12178
+ );
12179
+ }
12180
+ if ((savedContext.model_provider !== currentModelProvider || savedContext.model_name !== currentModelName) && (!bestEffortCurrentContext || currentModelProvider !== void 0 || currentModelName !== void 0)) {
12181
+ changed = true;
12182
+ detailLines.push(
12183
+ `Model changed: ${savedContext.model_provider ?? "(unknown provider)"}/${savedContext.model_name ?? "(unknown model)"} -> ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
12184
+ );
12185
+ }
12186
+ if (!(bestEffortCurrentContext && !currentInitialAgentsKnown)) {
12187
+ const agentDiffs = summarizeTrackedFileDiff(
12188
+ "Initial AGENTS",
12189
+ savedContext.initial_agents ?? [],
12190
+ currentAgents
12191
+ );
12192
+ if (agentDiffs.length > 0) {
12193
+ changed = true;
12194
+ detailLines.push(...agentDiffs);
12195
+ }
12196
+ }
12197
+ const skillDiffs = await summarizeCurrentLoadedSkillDiff(
12198
+ savedContext.loaded_skills ?? [],
12199
+ currentLoadedSkills
12200
+ );
12201
+ if (skillDiffs.length > 0) {
12202
+ changed = true;
12203
+ detailLines.push(...skillDiffs);
12204
+ }
12205
+ if (!changed) {
12206
+ detailLines.push(
12207
+ "No material workspace/AGENTS/skill changes were detected from saved resume metadata."
12208
+ );
12209
+ }
12210
+ }
12211
+ if (contextLines.length === 0 && detailLines.length === 0) {
12212
+ return null;
12213
+ }
12214
+ const summaryLines = [
12215
+ "Resume context:",
12216
+ ...contextLines.map((line) => `- ${line}`),
12217
+ ...detailLines.map((line) => `- ${line}`)
12218
+ ];
12219
+ const systemLines = [
12220
+ '<system-reminder type="session.resume.diff">',
12221
+ "Session resumed in current runtime context:",
12222
+ ...contextLines.map((line) => `- ${line}`),
12223
+ ...detailLines.map((line) => `- ${line}`),
12224
+ "Use the current runtime/workspace context for subsequent actions.",
12225
+ "</system-reminder>"
12226
+ ];
12227
+ return {
12228
+ summary: summaryLines.join("\n"),
12229
+ systemReminder: systemLines.join("\n"),
12230
+ changed
12231
+ };
12232
+ };
12233
+
11814
12234
  // src/rpc/skill-mentions.ts
11815
12235
  var SKILL_MENTION_PATTERN = /\$([a-z0-9]+(?:-[a-z0-9]+)*)/g;
11816
12236
  var extractSkillMentions = (value) => {
@@ -11923,6 +12343,7 @@ var runInputLengthForDebug = (input) => {
11923
12343
  // src/rpc/run.ts
11924
12344
  var nowIso5 = () => (/* @__PURE__ */ new Date()).toISOString();
11925
12345
  var SESSION_STATE_SAVE_DEBOUNCE_MS = 1500;
12346
+ var SESSION_WORKSPACE_ROOT_META_KEY = "codelia_workspace_root";
11926
12347
  var createSessionAppender = (store, onError) => {
11927
12348
  let chain = Promise.resolve();
11928
12349
  return (record) => {
@@ -11946,6 +12367,17 @@ var toMetaObject = (value) => {
11946
12367
  }
11947
12368
  return { ...value };
11948
12369
  };
12370
+ var mergeWorkspaceRootIntoSessionMeta = (meta, workspaceRoot) => {
12371
+ const nextMeta = meta ? { ...meta } : {};
12372
+ const trimmedWorkspaceRoot = workspaceRoot?.trim();
12373
+ if (trimmedWorkspaceRoot) {
12374
+ nextMeta[SESSION_WORKSPACE_ROOT_META_KEY] = trimmedWorkspaceRoot;
12375
+ } else {
12376
+ delete nextMeta[SESSION_WORKSPACE_ROOT_META_KEY];
12377
+ }
12378
+ return Object.keys(nextMeta).length > 0 ? nextMeta : void 0;
12379
+ };
12380
+ var resolveSessionWorkspaceRoot = (state) => state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? void 0;
11949
12381
  var toTimestampMs = (value) => {
11950
12382
  const ms = Date.parse(value);
11951
12383
  return Number.isFinite(ms) ? ms : null;
@@ -11984,6 +12416,26 @@ var createRunHandlers = ({
11984
12416
  }
11985
12417
  return normalizedMessages;
11986
12418
  };
12419
+ const restoreSessionHistoryIntoAgent = async (options) => {
12420
+ const restoredMessages = Array.isArray(options.resumeState.messages) ? options.resumeState.messages : [];
12421
+ const messages = normalizeRestoredSessionMessages(
12422
+ stripStartupSystemMessages(
12423
+ stripResumeDiffSystemMessages(restoredMessages)
12424
+ ),
12425
+ options.sessionId
12426
+ );
12427
+ const resumeDiff = await buildResumeDiff(options.resumeState.meta, state);
12428
+ const restoredWithCurrentStartup = prependCurrentStartupSystemMessage(
12429
+ messages,
12430
+ state.systemPrompt
12431
+ );
12432
+ options.runtimeAgent.replaceHistoryMessages(
12433
+ resumeDiff ? injectResumeDiffSystemReminder(
12434
+ restoredWithCurrentStartup,
12435
+ resumeDiff.systemReminder
12436
+ ) : restoredWithCurrentStartup
12437
+ );
12438
+ };
11987
12439
  const emitRunStatus = (runId, status, message) => {
11988
12440
  sendRunStatus(runId, status, message);
11989
12441
  const suffix = message ? ` message=${message}` : "";
@@ -12068,12 +12520,11 @@ var createRunHandlers = ({
12068
12520
  });
12069
12521
  return;
12070
12522
  }
12071
- const restoredMessages = Array.isArray(resumeState.messages) ? resumeState.messages : [];
12072
- const messages = normalizeRestoredSessionMessages(
12073
- restoredMessages,
12074
- requestedSessionId
12075
- );
12076
- runtimeAgent.replaceHistoryMessages(messages);
12523
+ await restoreSessionHistoryIntoAgent({
12524
+ runtimeAgent,
12525
+ resumeState,
12526
+ sessionId: requestedSessionId
12527
+ });
12077
12528
  sessionId = requestedSessionId;
12078
12529
  state.sessionId = sessionId;
12079
12530
  loadedSessionState = true;
@@ -12088,12 +12539,11 @@ var createRunHandlers = ({
12088
12539
  return;
12089
12540
  }
12090
12541
  if (resumeState) {
12091
- const restoredMessages = Array.isArray(resumeState.messages) ? resumeState.messages : [];
12092
- const messages = normalizeRestoredSessionMessages(
12093
- restoredMessages,
12094
- state.sessionId
12095
- );
12096
- runtimeAgent.replaceHistoryMessages(messages);
12542
+ await restoreSessionHistoryIntoAgent({
12543
+ runtimeAgent,
12544
+ resumeState,
12545
+ sessionId: state.sessionId
12546
+ });
12097
12547
  loadedSessionState = true;
12098
12548
  }
12099
12549
  } else if (!state.sessionId) {
@@ -12289,7 +12739,11 @@ var createRunHandlers = ({
12289
12739
  sessionSaveChain = sessionSaveChain.then(async () => {
12290
12740
  if (!sessionId) return;
12291
12741
  const messages = runtimeAgent.getHistoryMessages();
12292
- const snapshotMessages = normalizeToolCallHistory(messages);
12742
+ const snapshotMessages = normalizeToolCallHistory(
12743
+ stripStartupSystemMessages(
12744
+ stripResumeDiffSystemMessages(messages)
12745
+ )
12746
+ );
12293
12747
  if (snapshotMessages !== messages) {
12294
12748
  logRunDebug(
12295
12749
  log2,
@@ -12301,15 +12755,18 @@ var createRunHandlers = ({
12301
12755
  state.sessionMeta ?? void 0,
12302
12756
  getTodosForSession(sessionId)
12303
12757
  );
12758
+ const workspaceRoot = resolveSessionWorkspaceRoot(state);
12759
+ const sessionMetaWithWorkspace = mergeWorkspaceRootIntoSessionMeta(sessionMeta, workspaceRoot);
12760
+ const sessionMetaWithResumeContext = mergeResumeContextIntoSessionMeta(sessionMetaWithWorkspace, state);
12304
12761
  const snapshot = buildSessionState(
12305
12762
  sessionId,
12306
12763
  runId,
12307
12764
  snapshotMessages,
12308
12765
  session.invoke_seq,
12309
- sessionMeta
12766
+ sessionMetaWithResumeContext
12310
12767
  );
12311
12768
  await sessionStateStore.save(snapshot);
12312
- state.sessionMeta = sessionMeta ?? null;
12769
+ state.sessionMeta = sessionMetaWithResumeContext ?? null;
12313
12770
  logRunDebug(log2, runId, `session.save ${reason}`);
12314
12771
  }).catch((error) => {
12315
12772
  log2(`Error: session-state save failed: ${String(error)}`);
@@ -12462,7 +12919,7 @@ var createRunHandlers = ({
12462
12919
  };
12463
12920
 
12464
12921
  // src/rpc/shell.ts
12465
- import path16 from "path";
12922
+ import path17 from "path";
12466
12923
  import {
12467
12924
  RPC_ERROR_CODE as RPC_ERROR_CODE5
12468
12925
  } from "@codelia/protocol";
@@ -12481,14 +12938,14 @@ var truncateCommandPreview = (value) => {
12481
12938
  return `${trimmed.slice(0, COMMAND_PREVIEW_CHARS)}...[truncated]`;
12482
12939
  };
12483
12940
  var isWithin2 = (basePath, candidatePath) => {
12484
- const relative = path16.relative(basePath, candidatePath);
12485
- return relative === "" || !relative.startsWith("..") && !path16.isAbsolute(relative);
12941
+ const relative = path17.relative(basePath, candidatePath);
12942
+ return relative === "" || !relative.startsWith("..") && !path17.isAbsolute(relative);
12486
12943
  };
12487
12944
  var resolveShellCwd = (state, requestedCwd) => {
12488
12945
  const workingDir = state.runtimeWorkingDir ?? process.cwd();
12489
12946
  const rootDir = state.runtimeSandboxRoot ?? workingDir;
12490
12947
  if (!requestedCwd) return workingDir;
12491
- const resolved = path16.resolve(workingDir, requestedCwd);
12948
+ const resolved = path17.resolve(workingDir, requestedCwd);
12492
12949
  if (!isWithin2(rootDir, resolved)) {
12493
12950
  return null;
12494
12951
  }
@@ -13073,7 +13530,7 @@ var createShellHandlers = ({
13073
13530
  };
13074
13531
 
13075
13532
  // src/rpc/skills.ts
13076
- import path17 from "path";
13533
+ import path18 from "path";
13077
13534
  import {
13078
13535
  RPC_ERROR_CODE as RPC_ERROR_CODE6
13079
13536
  } from "@codelia/protocol";
@@ -13082,7 +13539,7 @@ var createSkillsHandlers = ({
13082
13539
  log: log2
13083
13540
  }) => {
13084
13541
  const handleSkillsList = async (id, params) => {
13085
- const requestedCwd = params?.cwd ? path17.resolve(params.cwd) : void 0;
13542
+ const requestedCwd = params?.cwd ? path18.resolve(params.cwd) : void 0;
13086
13543
  const workingDir = requestedCwd ?? state.runtimeWorkingDir ?? state.lastUiContext?.cwd ?? process.cwd();
13087
13544
  const forceReload = params?.force_reload ?? false;
13088
13545
  if (!forceReload) {
@@ -13137,7 +13594,7 @@ var createSkillsHandlers = ({
13137
13594
  };
13138
13595
 
13139
13596
  // src/rpc/task.ts
13140
- import path18 from "path";
13597
+ import path19 from "path";
13141
13598
  import {
13142
13599
  RPC_ERROR_CODE as RPC_ERROR_CODE7
13143
13600
  } from "@codelia/protocol";
@@ -13174,14 +13631,14 @@ var getPublicTaskKey = (task) => {
13174
13631
  return suffix ? `${toShellKeyBase2(task.label)}-${suffix}` : void 0;
13175
13632
  };
13176
13633
  var isWithin3 = (basePath, candidatePath) => {
13177
- const relative = path18.relative(basePath, candidatePath);
13178
- return relative === "" || !relative.startsWith("..") && !path18.isAbsolute(relative);
13634
+ const relative = path19.relative(basePath, candidatePath);
13635
+ return relative === "" || !relative.startsWith("..") && !path19.isAbsolute(relative);
13179
13636
  };
13180
13637
  var resolveShellCwd2 = (state, requestedCwd) => {
13181
13638
  const workingDir = state.runtimeWorkingDir ?? process.cwd();
13182
13639
  const rootDir = state.runtimeSandboxRoot ?? workingDir;
13183
13640
  if (!requestedCwd) return workingDir;
13184
- const resolved = path18.resolve(workingDir, requestedCwd);
13641
+ const resolved = path19.resolve(workingDir, requestedCwd);
13185
13642
  if (!isWithin3(rootDir, resolved)) {
13186
13643
  return null;
13187
13644
  }
@@ -13697,6 +14154,8 @@ var createRuntimeHandlers = ({
13697
14154
  provider,
13698
14155
  name: selectedModel
13699
14156
  });
14157
+ state.currentModelProvider = provider;
14158
+ state.currentModelName = selectedModel;
13700
14159
  state.agent = null;
13701
14160
  log2(
13702
14161
  `startup onboarding completed: ${provider}/${selectedModel} scope=${modelTarget.scope} path=${modelTarget.path}`
@@ -13728,7 +14187,20 @@ var createRuntimeHandlers = ({
13728
14187
  });
13729
14188
  const { handleSessionList, handleSessionHistory } = createHistoryHandlers({
13730
14189
  sessionStateStore,
13731
- log: log2
14190
+ log: log2,
14191
+ getCurrentWorkspaceRoot: () => state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? process.cwd(),
14192
+ buildResumeDiffSummary: async (meta) => {
14193
+ if (!hasStructuredResumeContextMeta(meta)) {
14194
+ return void 0;
14195
+ }
14196
+ const diff = await buildResumeDiff(meta, state, {
14197
+ bestEffortCurrentContext: true
14198
+ });
14199
+ if (!diff?.changed) {
14200
+ return void 0;
14201
+ }
14202
+ return diff.summary;
14203
+ }
13732
14204
  });
13733
14205
  const { handleModelList, handleModelSet } = createModelHandlers({
13734
14206
  state,
@@ -14030,6 +14502,9 @@ var RuntimeState = class {
14030
14502
  loadedSkillVersions = /* @__PURE__ */ new Map();
14031
14503
  runtimeWorkingDir = null;
14032
14504
  runtimeSandboxRoot = null;
14505
+ approvalMode = null;
14506
+ currentModelProvider = null;
14507
+ currentModelName = null;
14033
14508
  diagnosticsEnabled = false;
14034
14509
  nextRunId() {
14035
14510
  return crypto9.randomUUID();
@@ -14133,9 +14608,14 @@ var startRuntime = () => {
14133
14608
  void (async () => {
14134
14609
  const state = new RuntimeState();
14135
14610
  state.diagnosticsEnabled = envTruthy2(process.env.CODELIA_DIAGNOSTICS);
14136
- const workingDir = process.env.CODELIA_SANDBOX_ROOT ? path19.resolve(process.env.CODELIA_SANDBOX_ROOT) : process.cwd();
14611
+ const workingDir = process.env.CODELIA_SANDBOX_ROOT ? path20.resolve(process.env.CODELIA_SANDBOX_ROOT) : process.cwd();
14137
14612
  state.runtimeWorkingDir = workingDir;
14138
14613
  state.runtimeSandboxRoot = workingDir;
14614
+ try {
14615
+ state.agentsResolver = await AgentsResolver.create(workingDir);
14616
+ } catch (error) {
14617
+ log(`agents resolver startup init failed: ${String(error)}`);
14618
+ }
14139
14619
  const sessionStateStore = new SessionStateStoreImpl2({
14140
14620
  onError: (error, context) => {
14141
14621
  log(