@alan-ai-hq/agent-manager 0.1.124 → 0.1.126

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 (2) hide show
  1. package/dist/index.cjs +454 -232
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -34118,11 +34118,11 @@ function runOneShotCli(command, args, env, timeoutMs) {
34118
34118
  return new Promise((resolve16) => {
34119
34119
  const child = (0, import_node_child_process.spawn)(command, args, { env, stdio: ["ignore", "pipe", "ignore"] });
34120
34120
  let stdout = "";
34121
- let settled = false;
34121
+ let settled2 = false;
34122
34122
  const settle = (value2) => {
34123
- if (settled)
34123
+ if (settled2)
34124
34124
  return;
34125
- settled = true;
34125
+ settled2 = true;
34126
34126
  clearTimeout(timer);
34127
34127
  resolve16(value2);
34128
34128
  };
@@ -34381,6 +34381,8 @@ function parseNpmRuntimeVerifiedVersion(stdout, packageName) {
34381
34381
  var SANDBOX_AGENT_BROWSER_PACKAGE = "agent-browser";
34382
34382
  var SANDBOX_AGENT_BROWSER_VERSION_POLICY = "0.37.1";
34383
34383
  var SANDBOX_AGENT_BROWSER_NPM_SPEC = `${SANDBOX_AGENT_BROWSER_PACKAGE}@${SANDBOX_AGENT_BROWSER_VERSION_POLICY}`;
34384
+ var OPENCODE_ENGINE_PACKAGE = "opencode-ai";
34385
+ var OPENCODE_ENGINE_VERSION = "1.18.32";
34384
34386
  var SANDBOX_DESKTOP_BROWSER_ENV = Object.freeze({
34385
34387
  DISPLAY: ":0",
34386
34388
  AGENT_BROWSER_HEADED: "true",
@@ -34562,8 +34564,8 @@ var definitions = [
34562
34564
  envVars: ["ALAN_OPENCODE_PATH"],
34563
34565
  installer: {
34564
34566
  kind: "npm",
34565
- packageName: "opencode-ai",
34566
- versionPolicy: "latest"
34567
+ packageName: OPENCODE_ENGINE_PACKAGE,
34568
+ versionPolicy: OPENCODE_ENGINE_VERSION
34567
34569
  },
34568
34570
  bakeInto: ["e2b", "daytona", "freestyle"],
34569
34571
  runtimeRepair: { kind: "all-hosts", timeoutMs: 12e4 },
@@ -35443,7 +35445,7 @@ function buildComputerReadiness(input2) {
35443
35445
  }
35444
35446
 
35445
35447
  // src/version.ts
35446
- var AGENT_VERSION = "0.1.124";
35448
+ var AGENT_VERSION = "0.1.126";
35447
35449
 
35448
35450
  // src/daemon/status.ts
35449
35451
  var PENDING_RUN_START_TTL_MS = 10 * 6e4;
@@ -36767,7 +36769,7 @@ async function runHookCommand(args, overrides2 = {}) {
36767
36769
  }
36768
36770
 
36769
36771
  // src/cli/install.ts
36770
- var import_promises15 = require("timers/promises");
36772
+ var import_promises16 = require("timers/promises");
36771
36773
 
36772
36774
  // src/sleep-inhibitor.ts
36773
36775
  var import_node_child_process4 = require("child_process");
@@ -38152,6 +38154,7 @@ Team
38152
38154
  \`\`\`
38153
38155
  \`type\` is one of \`bar\`, \`line\`, \`area\`, \`pie\`, \`scatter\`. \`data\` is a non-empty array of flat objects \u2014 category field defaults to \`name\` (override with \`categoryKey\`), other numeric fields become series (or list explicitly via \`series: [...]\`). Pie needs a name+value field; scatter needs \`x\`/\`y\` (override via \`xKey\`/\`yKey\`). No JSX, no JS, no \`const\`/\`function\`, no unquoted keys or single-quoted strings, no code at all \u2014 it is rendered by a fixed component, not executed.
38154
38156
  - This only covers plain chart data. There is currently no safe inline path for custom/bespoke visuals (node graphs, gauges, click-to-inspect panels, mini-apps) \u2014 an earlier version ran agent-authored JSX directly in the chat page with no sandbox, which is a real security risk (full page privileges: cookies, session storage, same-origin requests), so it was removed. If a request needs something \`\`\`chart's JSON shape can't express, say so plainly and offer the closest data-chart alternative, a Mermaid diagram, or a written summary \u2014 do not force custom visuals into the JSON shape, and do not silently fall back to scaffolding a project file with Write/Edit as a substitute for "inline."
38157
+ - Images you generate or edit appear in the chat automatically, the way ChatGPT shows them. Do not link, embed, or print the generated file's path afterwards, and do not announce "Generated:" or "Edited image:" \u2014 at most one short sentence about the result. Mention a path only when the user asked for the file to be saved into the project.
38155
38158
 
38156
38159
  ${ALAN_PLATFORM_TOOL_ROUTING_PROMPT}
38157
38160
 
@@ -40988,7 +40991,7 @@ function daemonExternalStopExitCode(reason) {
40988
40991
 
40989
40992
  // src/cli/recover.ts
40990
40993
  async function runLocalDaemonRecoveryLadder(input2) {
40991
- const settled = (status3) => status3.connected === true && !status3.recovering && !status3.restartRecommended || input2.stopWaiting?.(status3) === true;
40994
+ const settled2 = (status3) => status3.connected === true && !status3.recovering && !status3.restartRecommended || input2.stopWaiting?.(status3) === true;
40992
40995
  const blocked = (status3) => input2.blockingRunCount(status3) > 0;
40993
40996
  const busy = (status3) => {
40994
40997
  const count2 = input2.blockingRunCount(status3);
@@ -41009,17 +41012,17 @@ async function runLocalDaemonRecoveryLadder(input2) {
41009
41012
  const pollMs = input2.options?.pollMs ?? 500;
41010
41013
  let status3 = await input2.getStatus();
41011
41014
  while (Date.now() < deadline) {
41012
- if (settled(status3)) return status3;
41015
+ if (settled2(status3)) return status3;
41013
41016
  await sleep(pollMs);
41014
41017
  status3 = await input2.getStatus();
41015
41018
  }
41016
41019
  return status3;
41017
41020
  };
41018
41021
  let status2 = input2.initialStatus;
41019
- if (settled(status2)) return status2;
41022
+ if (settled2(status2)) return status2;
41020
41023
  if (await input2.redial().catch(() => false)) {
41021
41024
  status2 = await waitForRecovery();
41022
- if (settled(status2)) return status2;
41025
+ if (settled2(status2)) return status2;
41023
41026
  if (status2.configured && status2.running !== false && !status2.restartRecommended) {
41024
41027
  return { ...status2, recovering: true, recoveryCode: "connect_timeout" };
41025
41028
  }
@@ -41033,10 +41036,10 @@ async function runLocalDaemonRecoveryLadder(input2) {
41033
41036
  error61 instanceof Error ? error61.message : "Local daemon restart failed"
41034
41037
  );
41035
41038
  }
41036
- if (settled(status2)) return status2;
41039
+ if (settled2(status2)) return status2;
41037
41040
  if (blocked(status2)) return busy(status2);
41038
41041
  status2 = await waitForRecovery();
41039
- if (settled(status2)) return status2;
41042
+ if (settled2(status2)) return status2;
41040
41043
  if (blocked(status2)) return busy(status2);
41041
41044
  return exhausted(
41042
41045
  status2,
@@ -43640,13 +43643,15 @@ var import_path8 = require("path");
43640
43643
  var import_promises4 = require("fs/promises");
43641
43644
  var import_path9 = require("path");
43642
43645
  var import_crypto4 = require("crypto");
43646
+ var import_child_process6 = require("child_process");
43647
+ var import_util14 = require("util");
43643
43648
  var import_crypto5 = require("crypto");
43644
43649
  var import_fs9 = require("fs");
43645
43650
  var import_os4 = require("os");
43646
43651
  var import_path10 = require("path");
43647
43652
  var import_url2 = require("url");
43648
- var import_child_process6 = require("child_process");
43649
- var import_util14 = require("util");
43653
+ var import_child_process7 = require("child_process");
43654
+ var import_util15 = require("util");
43650
43655
  var import_os5 = require("os");
43651
43656
  var import_path11 = require("path");
43652
43657
  var import_url3 = require("url");
@@ -43667,30 +43672,33 @@ var import_crypto7 = require("crypto");
43667
43672
  var import_fs13 = require("fs");
43668
43673
  var import_os6 = require("os");
43669
43674
  var import_path13 = require("path");
43670
- var import_fs14 = require("fs");
43675
+ var import_promises5 = require("timers/promises");
43671
43676
  var import_path14 = require("path");
43677
+ var import_fs14 = require("fs");
43678
+ var import_path15 = require("path");
43672
43679
  var import_fs15 = require("fs");
43673
43680
  var import_os7 = require("os");
43674
- var import_path15 = require("path");
43681
+ var import_path16 = require("path");
43675
43682
  var import_crypto8 = require("crypto");
43676
43683
  var import_fs16 = require("fs");
43677
43684
  var import_os8 = require("os");
43678
- var import_path16 = require("path");
43685
+ var import_path17 = require("path");
43679
43686
  var import_fs17 = require("fs");
43680
43687
  var import_os9 = require("os");
43681
- var import_path17 = require("path");
43688
+ var import_path18 = require("path");
43682
43689
  var import_crypto9 = require("crypto");
43683
43690
  var import_fs18 = require("fs");
43684
43691
  var import_os10 = require("os");
43685
- var import_path18 = require("path");
43686
- var import_child_process7 = require("child_process");
43692
+ var import_path19 = require("path");
43693
+ var import_child_process8 = require("child_process");
43687
43694
  var import_fs19 = require("fs");
43688
43695
  var import_os11 = require("os");
43689
- var import_path19 = require("path");
43696
+ var import_path20 = require("path");
43690
43697
  function createGrammarState() {
43691
43698
  return { seenToolCallIds: /* @__PURE__ */ new Set(), counter: 0, scratch: {} };
43692
43699
  }
43693
43700
  var PROVIDER_PAYLOAD_META = "alan.dev/providerPayload";
43701
+ var PROVIDER_WIRE_META = "alan.dev/providerWire";
43694
43702
  var TOOL_RESULT_ONLY_META = "alan.dev/toolResultOnly";
43695
43703
  var PARENT_TOOL_CALL_META = "alan.dev/parentToolCallId";
43696
43704
  var SUBAGENT_LAUNCHER_META = "alan.dev/subagentLauncher";
@@ -44689,8 +44697,8 @@ function withBackgroundTaskMeta(update, state) {
44689
44697
  if (!record4) return update;
44690
44698
  const label = record4.meta.label ?? toolLabels.get(state)?.get(update.toolCallId);
44691
44699
  if (!record4.meta.label && label) record4.meta = { ...record4.meta, label };
44692
- const settled = update.status === "completed" || update.status === "failed" || update.status === "cancelled";
44693
- if (settled && record4.meta.kind === "agent" && isRunningBackgroundTask(record4)) {
44700
+ const settled2 = update.status === "completed" || update.status === "failed" || update.status === "cancelled";
44701
+ if (settled2 && record4.meta.kind === "agent" && isRunningBackgroundTask(record4)) {
44694
44702
  setBackgroundTaskStatus(
44695
44703
  record4,
44696
44704
  terminalBackgroundTaskStatus(
@@ -45618,11 +45626,11 @@ async function killProcessTree(pid, options = {}) {
45618
45626
  }
45619
45627
  if (process.platform === "win32") {
45620
45628
  return new Promise((resolve52) => {
45621
- let settled = false;
45629
+ let settled2 = false;
45622
45630
  let timer;
45623
45631
  const finish = (error61) => {
45624
- if (settled) return;
45625
- settled = true;
45632
+ if (settled2) return;
45633
+ settled2 = true;
45626
45634
  clearTimeout(timer);
45627
45635
  if (error61) onError?.("taskkill", error61);
45628
45636
  resolve52(!error61);
@@ -46370,8 +46378,8 @@ function mediaUpdatesFor(update, context) {
46370
46378
  hints2.add(path2);
46371
46379
  }
46372
46380
  }
46373
- const settled = update.status === "completed" || update.status === "failed";
46374
- if (!settled || update.status === "failed") return [];
46381
+ const settled2 = update.status === "completed" || update.status === "failed";
46382
+ if (!settled2 || update.status === "failed") return [];
46375
46383
  const call = tools.get(toolCallId);
46376
46384
  if (!call) return [];
46377
46385
  const hints = hintsFor(context);
@@ -46453,8 +46461,8 @@ function applyToolCall(update, context, state, effects, projection) {
46453
46461
  if (taskId) registerBackgroundTaskRecord(state, { task_id: taskId, tool_use_id: id });
46454
46462
  }
46455
46463
  }
46456
- const settled = update.status === "completed" || update.status === "failed" || update.status === "cancelled";
46457
- if (settled && isLauncher) clearBackgroundTaskIds(state, [id]);
46464
+ const settled2 = update.status === "completed" || update.status === "failed" || update.status === "cancelled";
46465
+ if (settled2 && isLauncher) clearBackgroundTaskIds(state, [id]);
46458
46466
  }
46459
46467
  function breakdownOf(update) {
46460
46468
  const raw = metaOf(update)?.[USAGE_META];
@@ -47065,6 +47073,45 @@ async function connectOpenCodeSse(url3, signal) {
47065
47073
  }
47066
47074
  };
47067
47075
  }
47076
+ var execFileAsync2 = (0, import_util14.promisify)(import_child_process6.execFile);
47077
+ var VERSION_PROBE_TIMEOUT_MS = 5e3;
47078
+ var SUPPORTED_OPENCODE_MAJOR = 1;
47079
+ var versionProbes = /* @__PURE__ */ new Map();
47080
+ function parseOpenCodeVersion(output2) {
47081
+ return /\bv?(\d+\.\d+\.\d+(?:-[\w.-]+)?)/.exec(output2)?.[1] ?? null;
47082
+ }
47083
+ function unsupportedOpenCodeVersionMessage(version2, command) {
47084
+ const major = Number.parseInt(version2, 10);
47085
+ if (!Number.isFinite(major) || major <= SUPPORTED_OPENCODE_MAJOR) return null;
47086
+ return `OpenCode ${version2} (${command}) is not supported yet. Alan runs the OpenCode ${SUPPORTED_OPENCODE_MAJOR}.x server API, which OpenCode 2 replaced. Install opencode-ai@${SUPPORTED_OPENCODE_MAJOR} or point ALAN_OPENCODE_PATH at an OpenCode ${SUPPORTED_OPENCODE_MAJOR}.x binary.`;
47087
+ }
47088
+ async function probeOpenCodeVersion(command, context) {
47089
+ try {
47090
+ const { stdout, stderr } = await execFileAsync2(command, ["--version"], {
47091
+ cwd: context.cwd,
47092
+ env: { ...process.env, ...context.env },
47093
+ encoding: "utf8",
47094
+ timeout: VERSION_PROBE_TIMEOUT_MS,
47095
+ maxBuffer: 64 * 1024,
47096
+ windowsHide: true
47097
+ });
47098
+ return parseOpenCodeVersion(`${stdout}
47099
+ ${stderr}`);
47100
+ } catch {
47101
+ return null;
47102
+ }
47103
+ }
47104
+ async function assertSupportedOpenCodeEngine(command, context) {
47105
+ const cacheKey = `${command}\0${context.env.PATH ?? process.env.PATH ?? ""}`;
47106
+ let probe = versionProbes.get(cacheKey);
47107
+ if (!probe) {
47108
+ probe = probeOpenCodeVersion(command, context);
47109
+ versionProbes.set(cacheKey, probe);
47110
+ }
47111
+ const version2 = await probe;
47112
+ const message = version2 ? unsupportedOpenCodeVersionMessage(version2, command) : null;
47113
+ if (message) throw new Error(message);
47114
+ }
47068
47115
  var HUNK_FIELDS = ["oldStart", "oldLines", "newStart", "newLines"];
47069
47116
  function readPatchHunk(value2) {
47070
47117
  const record4 = asRecord(value2);
@@ -47184,6 +47231,7 @@ function opencodeFileChangeContent(metadata, name = "", input2) {
47184
47231
  ];
47185
47232
  }
47186
47233
  var OPENCODE_GRAMMAR_NAME = "opencode";
47234
+ var OPENCODE_WIRE = "opencode-v1";
47187
47235
  var SCRATCH = OPENCODE_GRAMMAR_NAME;
47188
47236
  var TASK_TOOL_NAME = "task";
47189
47237
  var TASK_RESULT_TAG = /<task_result>\n?([\s\S]*?)\n?<\/task_result>/;
@@ -47284,7 +47332,7 @@ function parseEvent(event, state) {
47284
47332
  {
47285
47333
  sessionUpdate: "_alan/unhandled",
47286
47334
  kind: `opencode.part.${type || "unknown"}`,
47287
- _meta: { [PROVIDER_PAYLOAD_META]: event }
47335
+ _meta: { [PROVIDER_PAYLOAD_META]: event, [PROVIDER_WIRE_META]: OPENCODE_WIRE }
47288
47336
  }
47289
47337
  ];
47290
47338
  }
@@ -47363,6 +47411,7 @@ function parseTool(part) {
47363
47411
  // `task` spawns a subagent the runtime gates run completion on.
47364
47412
  _meta: {
47365
47413
  "alan.dev/providerEvent": part,
47414
+ [PROVIDER_WIRE_META]: OPENCODE_WIRE,
47366
47415
  ...isTask ? { [SUBAGENT_LAUNCHER_META]: true } : {},
47367
47416
  ...childSessionId ? { [SUBAGENT_TASK_ID_META]: childSessionId } : {},
47368
47417
  ...toolState?.metadata !== void 0 ? { [PROVIDER_PAYLOAD_META]: toolState.metadata } : {}
@@ -47851,10 +47900,10 @@ function startOpenCodeServer(command, context) {
47851
47900
  env: withoutOpenCodeServerAuth(context.env)
47852
47901
  });
47853
47902
  const ready = new Promise((resolve52, reject2) => {
47854
- let settled = false;
47903
+ let settled2 = false;
47855
47904
  const timeout = setTimeout(() => {
47856
- if (settled) return;
47857
- settled = true;
47905
+ if (settled2) return;
47906
+ settled2 = true;
47858
47907
  reject2(
47859
47908
  new Error(`opencode serve did not report a listening URL within ${STARTUP_TIMEOUT_MS}ms`)
47860
47909
  );
@@ -47862,10 +47911,10 @@ function startOpenCodeServer(command, context) {
47862
47911
  let stdoutTail = "";
47863
47912
  let stderrTail = "";
47864
47913
  const checkLine = (line) => {
47865
- if (settled) return;
47914
+ if (settled2) return;
47866
47915
  const match = line.match(SERVER_LISTENING_PATTERN);
47867
47916
  if (!match) return;
47868
- settled = true;
47917
+ settled2 = true;
47869
47918
  clearTimeout(timeout);
47870
47919
  child.stdout.off("data", onStdout);
47871
47920
  child.stderr.off("data", onStderr);
@@ -47886,14 +47935,14 @@ function startOpenCodeServer(command, context) {
47886
47935
  child.stdout.on("data", onStdout);
47887
47936
  child.stderr.on("data", onStderr);
47888
47937
  child.once("error", (error61) => {
47889
- if (settled) return;
47890
- settled = true;
47938
+ if (settled2) return;
47939
+ settled2 = true;
47891
47940
  clearTimeout(timeout);
47892
47941
  reject2(error61);
47893
47942
  });
47894
47943
  child.once("exit", (code) => {
47895
- if (settled) return;
47896
- settled = true;
47944
+ if (settled2) return;
47945
+ settled2 = true;
47897
47946
  clearTimeout(timeout);
47898
47947
  reject2(
47899
47948
  new Error(
@@ -48314,6 +48363,7 @@ function createOpencodeServeBackend(command = "opencode", options = PLAIN_OPENCO
48314
48363
  let context;
48315
48364
  try {
48316
48365
  context = await options.prepareContext(rawContext);
48366
+ await assertSupportedOpenCodeEngine(command, context);
48317
48367
  } catch (error61) {
48318
48368
  const message = error61 instanceof Error ? error61.message : String(error61);
48319
48369
  const state2 = {
@@ -48766,6 +48816,12 @@ function alanCodeEngineDirectories(root) {
48766
48816
  function defaultEngineRoot(env) {
48767
48817
  return (0, import_path10.join)(env.HOME?.trim() || (0, import_os4.homedir)(), ".alan", "alan-code", "engine");
48768
48818
  }
48819
+ var ALAN_CODE_TOOL_NAMING_PROMPT = `## Alan tool names
48820
+
48821
+ This engine exposes Alan MCP tools with an \`alan_\` prefix. Where these instructions name an Alan tool, call its prefixed form: \`search_context\` is \`alan_search_context\`, \`search_code_context\` is \`alan_search_code_context\`, and \`find_records\` is \`alan_find_records\`.`;
48822
+ function buildAlanCodeSystemPrompt(alanSystemPrompt) {
48823
+ return [ALAN_CODE_BASELINE_PROMPT, ALAN_CODE_TOOL_NAMING_PROMPT, alanSystemPrompt?.trim()].filter((part) => Boolean(part)).join("\n\n");
48824
+ }
48769
48825
  async function withAlanCodeEngine(context, dependencies = {}) {
48770
48826
  const registration = context.config.alanMcp;
48771
48827
  if (!registration) {
@@ -48776,10 +48832,11 @@ async function withAlanCodeEngine(context, dependencies = {}) {
48776
48832
  const apiOrigin = new URL(registration.url).origin;
48777
48833
  const models = await loadAlanCodeModels(apiOrigin, registration, dependencies.fetchCatalog);
48778
48834
  const modelId = resolveAlanCodeModelId(context.config.selectedModel, models);
48835
+ const { systemPrompt, systemPromptAppend: _append, ...config4 } = context.config;
48779
48836
  return {
48780
48837
  ...context,
48781
48838
  config: {
48782
- ...context.config,
48839
+ ...config4,
48783
48840
  selectedModel: `${ALAN_CODE_ENGINE_PROVIDER_ID}/${modelId}`
48784
48841
  },
48785
48842
  env: {
@@ -48791,7 +48848,8 @@ async function withAlanCodeEngine(context, dependencies = {}) {
48791
48848
  baseURL: `${apiOrigin}${ALAN_CODE_PROXY_PATH}`,
48792
48849
  modelId,
48793
48850
  models,
48794
- pluginUrl: materializeEnginePlugin(dependencies.pluginDirectory, apiOrigin)
48851
+ pluginUrl: materializeEnginePlugin(dependencies.pluginDirectory, apiOrigin),
48852
+ prompt: buildAlanCodeSystemPrompt(systemPrompt)
48795
48853
  })
48796
48854
  }
48797
48855
  };
@@ -50043,7 +50101,7 @@ function handleSubagentResult(event, context, state) {
50043
50101
  state.iterations = Math.max(state.iterations, 1);
50044
50102
  const updates = [];
50045
50103
  const launcherId = antigravityExplicitToolId(event);
50046
- const settled = settleBackgroundTerminalNotification(
50104
+ const settled2 = settleBackgroundTerminalNotification(
50047
50105
  KIND,
50048
50106
  context,
50049
50107
  state,
@@ -50056,9 +50114,9 @@ function handleSubagentResult(event, context, state) {
50056
50114
  }
50057
50115
  }
50058
50116
  );
50059
- if (settled) {
50060
- state.antigravitySubagentTranscripts?.get(settled)?.cursor?.close();
50061
- state.antigravitySubagentTranscripts?.delete(settled);
50117
+ if (settled2) {
50118
+ state.antigravitySubagentTranscripts?.get(settled2)?.cursor?.close();
50119
+ state.antigravitySubagentTranscripts?.delete(settled2);
50062
50120
  }
50063
50121
  return updates;
50064
50122
  }
@@ -50185,14 +50243,14 @@ var parseAntigravityStructuredLine = grammarAsStructuredLineParser(
50185
50243
  antigravityEffects
50186
50244
  );
50187
50245
  var parseAntigravityTextLine = grammarAsStructuredLineParser(antigravityTextGrammar);
50188
- var execFileAsync2 = (0, import_util14.promisify)(import_child_process6.execFile);
50246
+ var execFileAsync3 = (0, import_util15.promisify)(import_child_process7.execFile);
50189
50247
  var capabilityCache = /* @__PURE__ */ new Map();
50190
50248
  function normalizeProbeOutput(output2) {
50191
50249
  return output2.toLowerCase().replace(/\s+/g, " ");
50192
50250
  }
50193
50251
  async function readCliOutput(command, args, context) {
50194
50252
  try {
50195
- const { stdout, stderr } = await execFileAsync2(command, args, {
50253
+ const { stdout, stderr } = await execFileAsync3(command, args, {
50196
50254
  cwd: context.cwd,
50197
50255
  env: { ...process.env, ...context.env },
50198
50256
  encoding: "utf8",
@@ -51245,14 +51303,14 @@ function backgroundTaskProgress(event, state) {
51245
51303
  return [
51246
51304
  { sessionUpdate: "tool_call_update", toolCallId, _meta: { [PROVIDER_PAYLOAD_META]: event } }
51247
51305
  ];
51248
- const settled = Boolean(
51306
+ const settled2 = Boolean(
51249
51307
  progress.status && TERMINAL_BACKGROUND_STATUSES.has(progress.status.toLowerCase())
51250
51308
  );
51251
51309
  return [
51252
51310
  {
51253
51311
  sessionUpdate: "tool_call_update",
51254
51312
  toolCallId,
51255
- ...settled ? {} : { status: "in_progress" },
51313
+ ...settled2 ? {} : { status: "in_progress" },
51256
51314
  _meta: { "alan.dev/taskProgress": progress, [PROVIDER_PAYLOAD_META]: event }
51257
51315
  }
51258
51316
  ];
@@ -51394,11 +51452,11 @@ function handleSystem(event, context, state) {
51394
51452
  }
51395
51453
  clearBackgroundTaskIds(state, keys);
51396
51454
  if (toolUseId && wasActive) {
51397
- const settled = settledSubagentResult(toolUseId, resultText2, failed, outputMeta(notification));
51455
+ const settled2 = settledSubagentResult(toolUseId, resultText2, failed, outputMeta(notification));
51398
51456
  updates.push({
51399
- ...settled,
51457
+ ...settled2,
51400
51458
  _meta: {
51401
- ...asRecord(settled._meta),
51459
+ ...asRecord(settled2._meta),
51402
51460
  [PROVIDER_PAYLOAD_META]: event,
51403
51461
  ...notification.summary ? {
51404
51462
  "alan.dev/taskProgress": {
@@ -51676,21 +51734,109 @@ function recoverCodexFileChange(state, item) {
51676
51734
  _meta: { ...asRecord(update._meta), [PROVIDER_PAYLOAD_META]: item }
51677
51735
  }));
51678
51736
  }
51737
+ var IMAGE_GEN_CALL = /\bimage_gen\w*\s*\(/;
51738
+ var PROMPT_LITERAL = /\bprompt\s*:\s*("(?:[^"\\]|\\.)*")/;
51739
+ function emptyImageGenerationFold() {
51740
+ return { pending: [], updates: [] };
51741
+ }
51742
+ function mentionsImageGeneration(line) {
51743
+ return line.includes("image_gen");
51744
+ }
51745
+ function promptOf(script) {
51746
+ const literal2 = PROMPT_LITERAL.exec(script)?.[1];
51747
+ if (!literal2) return void 0;
51748
+ try {
51749
+ const prompt = JSON.parse(literal2);
51750
+ return typeof prompt === "string" ? prompt : void 0;
51751
+ } catch {
51752
+ return void 0;
51753
+ }
51754
+ }
51755
+ function startedCall(payload) {
51756
+ const callId = typeof payload.call_id === "string" ? payload.call_id : "";
51757
+ if (!callId) return null;
51758
+ if (payload.type === "custom_tool_call" && payload.name === "exec") {
51759
+ const script = typeof payload.input === "string" ? payload.input : "";
51760
+ return IMAGE_GEN_CALL.test(script) ? { callId, prompt: promptOf(script) } : null;
51761
+ }
51762
+ if (payload.type === "function_call" && payload.name === "image_gen" && !payload.namespace) {
51763
+ return { callId };
51764
+ }
51765
+ return null;
51766
+ }
51767
+ function settled(toolCallId, status2) {
51768
+ return { sessionUpdate: "tool_call_update", toolCallId, status: status2 };
51769
+ }
51770
+ function foldImageGenerationLine(entryType, payload, fold) {
51771
+ if (entryType === "response_item") {
51772
+ const call = startedCall(payload);
51773
+ if (!call) return;
51774
+ fold.pending.push(call.callId);
51775
+ fold.updates.push({
51776
+ sessionUpdate: "tool_call_update",
51777
+ toolCallId: call.callId,
51778
+ name: "image_gen",
51779
+ title: "Generate image",
51780
+ kind: "other",
51781
+ status: "in_progress",
51782
+ rawInput: call.prompt ? { prompt: call.prompt } : {}
51783
+ });
51784
+ return;
51785
+ }
51786
+ if (entryType !== "event_msg") return;
51787
+ if (payload.type === "image_generation_end") {
51788
+ const toolCallId2 = fold.pending.shift();
51789
+ if (toolCallId2) fold.updates.push(settled(toolCallId2, "completed"));
51790
+ return;
51791
+ }
51792
+ const item = asRecord(payload.item);
51793
+ if (payload.type !== "item_completed") return;
51794
+ if (item?.type !== "Extension" || item.kind !== "image_gen.generation") return;
51795
+ const toolCallId = fold.pending.shift();
51796
+ const savedPath = typeof item.savedPath === "string" ? item.savedPath : void 0;
51797
+ const image = item.status === "completed" ? buildGeneratedImageFromInlinePayload(
51798
+ {
51799
+ id: item.id,
51800
+ call_id: toolCallId,
51801
+ result: item.result,
51802
+ filename: savedPath && (0, import_path14.basename)(savedPath)
51803
+ },
51804
+ { dataFields: ["result"], toolIdFields: ["call_id"], idFields: ["id"] }
51805
+ ) : null;
51806
+ if (image) {
51807
+ fold.updates.push({
51808
+ sessionUpdate: "_alan/generated_image",
51809
+ image: savedPath ? { ...image, sourcePath: savedPath } : image
51810
+ });
51811
+ }
51812
+ if (toolCallId) fold.updates.push(settled(toolCallId, image ? "completed" : "failed"));
51813
+ }
51814
+ function settlePendingImageGenerations(fold) {
51815
+ const updates = fold.pending.map((toolCallId) => settled(toolCallId, "failed"));
51816
+ fold.pending = [];
51817
+ return updates;
51818
+ }
51819
+ function takeImageGenerationUpdates(fold) {
51820
+ const isImage = (update) => update.sessionUpdate === "_alan/generated_image";
51821
+ const first = fold.updates.findIndex(isImage);
51822
+ const second = first === -1 ? -1 : fold.updates.findIndex((u, i) => i > first && isImage(u));
51823
+ return fold.updates.splice(0, second === -1 ? fold.updates.length : second);
51824
+ }
51679
51825
  var DAY_MS = 24 * 60 * 60 * 1e3;
51680
51826
  var MAX_HEADER_BYTES = 1024 * 1024;
51681
51827
  function workerDirectories(rootLog) {
51682
- const directory = (0, import_path14.dirname)(rootLog);
51683
- const monthDirectory = (0, import_path14.dirname)(directory);
51684
- const yearDirectory = (0, import_path14.dirname)(monthDirectory);
51685
- const date5 = `${(0, import_path14.basename)(yearDirectory)}-${(0, import_path14.basename)(monthDirectory)}-${(0, import_path14.basename)(directory)}`;
51828
+ const directory = (0, import_path15.dirname)(rootLog);
51829
+ const monthDirectory = (0, import_path15.dirname)(directory);
51830
+ const yearDirectory = (0, import_path15.dirname)(monthDirectory);
51831
+ const date5 = `${(0, import_path15.basename)(yearDirectory)}-${(0, import_path15.basename)(monthDirectory)}-${(0, import_path15.basename)(directory)}`;
51686
51832
  if (!/^\d{4}-\d{2}-\d{2}$/.test(date5)) return [directory];
51687
51833
  const timestamp = Date.parse(`${date5}T00:00:00Z`);
51688
51834
  if (!Number.isFinite(timestamp) || new Date(timestamp).toISOString().slice(0, 10) !== date5)
51689
51835
  return [directory];
51690
- const sessionsDirectory2 = (0, import_path14.dirname)(yearDirectory);
51836
+ const sessionsDirectory2 = (0, import_path15.dirname)(yearDirectory);
51691
51837
  return [0, 1, -1].map((offset2) => {
51692
51838
  const day = new Date(timestamp + offset2 * DAY_MS).toISOString().slice(0, 10);
51693
- return (0, import_path14.join)(sessionsDirectory2, ...day.split("-"));
51839
+ return (0, import_path15.join)(sessionsDirectory2, ...day.split("-"));
51694
51840
  });
51695
51841
  }
51696
51842
  function firstLine(path2) {
@@ -51727,7 +51873,7 @@ function findCodexWorkerLogs(rootLog, parentThreadId) {
51727
51873
  }
51728
51874
  for (const entry of entries) {
51729
51875
  if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
51730
- const path2 = (0, import_path14.join)(directory, entry.name);
51876
+ const path2 = (0, import_path15.join)(directory, entry.name);
51731
51877
  if (path2 === rootLog) continue;
51732
51878
  try {
51733
51879
  const line = firstLine(path2);
@@ -51899,13 +52045,14 @@ function rolloutScanFor(state, path2) {
51899
52045
  path: path2,
51900
52046
  cursor: new TranscriptCursor(path2, promptOffset),
51901
52047
  spawnByCallId: /* @__PURE__ */ new Map(),
51902
- workersByThreadId: /* @__PURE__ */ new Map()
52048
+ workersByThreadId: /* @__PURE__ */ new Map(),
52049
+ imageGeneration: emptyImageGenerationFold()
51903
52050
  };
51904
52051
  rolloutScans.set(state, scan);
51905
52052
  return scan;
51906
52053
  }
51907
52054
  function couldMatter(line, scan) {
51908
- return line.includes('"role":"user"') || line.includes('"spawn_agent"') || line.includes('"sub_agent_activity"') || scan.spawnByCallId.size > 0 && line.includes('"function_call_output"');
52055
+ return line.includes('"role":"user"') || mentionsImageGeneration(line) || line.includes('"spawn_agent"') || line.includes('"sub_agent_activity"') || scan.spawnByCallId.size > 0 && line.includes('"function_call_output"');
51909
52056
  }
51910
52057
  function foldSpawnCall(payload, scan, timestamp) {
51911
52058
  const namespace = typeof payload.namespace === "string" ? payload.namespace : "";
@@ -51962,6 +52109,7 @@ function foldRolloutLine(line, scan) {
51962
52109
  scan.workersByThreadId.clear();
51963
52110
  return;
51964
52111
  }
52112
+ foldImageGenerationLine(entry.type, payload, scan.imageGeneration);
51965
52113
  if (entry.type === "response_item" && payload.type === "function_call") {
51966
52114
  if (payload.name === "spawn_agent") foldSpawnCall(payload, scan, entry.timestamp);
51967
52115
  return;
@@ -51974,11 +52122,16 @@ function foldRolloutLine(line, scan) {
51974
52122
  foldWorkerStarted(payload, scan);
51975
52123
  }
51976
52124
  }
51977
- function collectCodexWorkerReplays(logPath, state) {
52125
+ function advanceRolloutScan(state, logPath) {
51978
52126
  const scan = rolloutScanFor(state, logPath);
51979
- if (!scan) return [];
52127
+ if (!scan) return null;
51980
52128
  for (const line of scan.cursor.read()) foldRolloutLine(line.text, scan);
51981
52129
  scan.cursor.close();
52130
+ return scan;
52131
+ }
52132
+ function collectCodexWorkerReplays(logPath, state) {
52133
+ const scan = advanceRolloutScan(state, logPath);
52134
+ if (!scan) return [];
51982
52135
  const unresolved = [...scan.spawnByCallId.values()].filter(
51983
52136
  (spawn42) => spawn42.agentPath && ![...scan.workersByThreadId.values()].some((worker) => worker.launcherId === spawn42.launcherId)
51984
52137
  );
@@ -52207,6 +52360,30 @@ function replayCodexWorkerTranscript(context, worker, codexHome, state) {
52207
52360
  rememberWorkerReplay(state, worker.threadId, lines.length, finalText);
52208
52361
  return finalText;
52209
52362
  }
52363
+ function imageGenerationFold(state) {
52364
+ const logPath = state.codexSessionLogPath;
52365
+ const scan = logPath ? advanceRolloutScan(state, logPath) : null;
52366
+ return scan?.imageGeneration ?? null;
52367
+ }
52368
+ function syncCodexImageGenerationFromSessionLog(context, state) {
52369
+ const fold = imageGenerationFold(state);
52370
+ const updates = fold ? takeImageGenerationUpdates(fold) : [];
52371
+ for (const update of updates) emitSessionUpdate(update, context, state);
52372
+ return updates.length;
52373
+ }
52374
+ var EXIT_IMAGE_SPACING_MS = 100;
52375
+ async function flushCodexImageGenerationOnExit(context, state) {
52376
+ const fold = imageGenerationFold(state);
52377
+ if (!fold) return;
52378
+ for (; ; ) {
52379
+ const updates = takeImageGenerationUpdates(fold);
52380
+ if (updates.length === 0) break;
52381
+ for (const update of updates) emitSessionUpdate(update, context, state);
52382
+ if (fold.updates.length > 0) await (0, import_promises5.setTimeout)(EXIT_IMAGE_SPACING_MS);
52383
+ }
52384
+ for (const update of settlePendingImageGenerations(fold))
52385
+ emitSessionUpdate(update, context, state);
52386
+ }
52210
52387
  function syncCodexWorkerEventsFromSessionLog(context, state) {
52211
52388
  const runtimeSessionId = state.runtimeSessionId;
52212
52389
  if (!runtimeSessionId) return [];
@@ -52260,6 +52437,13 @@ function syncCodexWorkerEventsFromSessionLog(context, state) {
52260
52437
  return workers;
52261
52438
  }
52262
52439
  async function replayCodexMcpToolEventsFromSessionLog(context, state) {
52440
+ try {
52441
+ replayRolloutAfterExit(context, state);
52442
+ } finally {
52443
+ await flushCodexImageGenerationOnExit(context, state);
52444
+ }
52445
+ }
52446
+ function replayRolloutAfterExit(context, state) {
52263
52447
  const runtimeSessionId = state.runtimeSessionId;
52264
52448
  if (!runtimeSessionId) return;
52265
52449
  if (!state.iterations || state.iterations <= 0) return;
@@ -53007,7 +53191,8 @@ function ensureCodexWorkerEventPolling(context, state) {
53007
53191
  drain: () => {
53008
53192
  const before = replayProgress(state);
53009
53193
  syncCodexWorkerEventsFromSessionLog(context, state);
53010
- if (replayProgress(state) > before) state.onNewOutput?.();
53194
+ const images2 = syncCodexImageGenerationFromSessionLog(context, state);
53195
+ if (replayProgress(state) > before || images2 > 0) state.onNewOutput?.();
53011
53196
  }
53012
53197
  });
53013
53198
  state.providerTranscriptTail = tail;
@@ -54466,8 +54651,8 @@ function handleToolComplete(event, context, state) {
54466
54651
  {
54467
54652
  resultText: text2,
54468
54653
  isError: success2 ? void 0 : true,
54469
- emitToolResult: (launcherId, settled, isError) => {
54470
- updates.push(settlementUpdate(launcherId, settled, isError));
54654
+ emitToolResult: (launcherId, settled2, isError) => {
54655
+ updates.push(settlementUpdate(launcherId, settled2, isError));
54471
54656
  }
54472
54657
  }
54473
54658
  );
@@ -54484,8 +54669,8 @@ function activeTaskIdNamedIn(state, content) {
54484
54669
  }
54485
54670
  function writeCopilotMcpConfig(registration) {
54486
54671
  if (!registration) return null;
54487
- const dir = (0, import_fs15.mkdtempSync)((0, import_path15.join)((0, import_os7.tmpdir)(), "alan-copilot-mcp-"));
54488
- const path2 = (0, import_path15.join)(dir, "mcp-config.json");
54672
+ const dir = (0, import_fs15.mkdtempSync)((0, import_path16.join)((0, import_os7.tmpdir)(), "alan-copilot-mcp-"));
54673
+ const path2 = (0, import_path16.join)(dir, "mcp-config.json");
54489
54674
  (0, import_fs15.writeFileSync)(
54490
54675
  path2,
54491
54676
  JSON.stringify({
@@ -54503,12 +54688,12 @@ function writeCopilotMcpConfig(registration) {
54503
54688
  return { path: path2, cleanup: () => (0, import_fs15.rmSync)(dir, { recursive: true, force: true }) };
54504
54689
  }
54505
54690
  function resolveCopilotHome(env) {
54506
- return env.COPILOT_HOME || (0, import_path16.join)(env.HOME || (0, import_os8.homedir)(), ".copilot");
54691
+ return env.COPILOT_HOME || (0, import_path17.join)(env.HOME || (0, import_os8.homedir)(), ".copilot");
54507
54692
  }
54508
54693
  function copilotSessionPresence(sessionId, home) {
54509
- const stateRoot = (0, import_path16.join)(home, "session-state");
54694
+ const stateRoot = (0, import_path17.join)(home, "session-state");
54510
54695
  if (!(0, import_fs16.existsSync)(stateRoot)) return "unknown";
54511
- return (0, import_fs16.existsSync)((0, import_path16.join)(stateRoot, sessionId, "events.jsonl")) ? "present" : "missing";
54696
+ return (0, import_fs16.existsSync)((0, import_path17.join)(stateRoot, sessionId, "events.jsonl")) ? "present" : "missing";
54512
54697
  }
54513
54698
  function freshSession(contextPrefix) {
54514
54699
  const sessionId = (0, import_crypto8.randomUUID)();
@@ -55128,9 +55313,9 @@ function cursorSubagentConversationStepUpdates(steps, parentToolUseId2) {
55128
55313
  if (!entry) return;
55129
55314
  const args = cursorToolArgs(entry);
55130
55315
  const toolCallId = asString(args.toolCallId) || asString(args.tool_call_id) || messageId;
55131
- const settled = entry.payload.result !== void 0;
55132
- const failed = settled && cursorResultVariant(entry.payload.result, "error") !== null;
55133
- const text2 = settled ? buildCursorToolResultText(entry.payload.result) : "";
55316
+ const settled2 = entry.payload.result !== void 0;
55317
+ const failed = settled2 && cursorResultVariant(entry.payload.result, "error") !== null;
55318
+ const text2 = settled2 ? buildCursorToolResultText(entry.payload.result) : "";
55134
55319
  const name = formatCursorToolName(entry.rawName, entry.payload);
55135
55320
  updates.push({
55136
55321
  sessionUpdate: "tool_call_update",
@@ -55138,11 +55323,11 @@ function cursorSubagentConversationStepUpdates(steps, parentToolUseId2) {
55138
55323
  name,
55139
55324
  title: name,
55140
55325
  kind: toolKindFor(name),
55141
- status: settled ? failed ? "failed" : "completed" : "in_progress",
55326
+ status: settled2 ? failed ? "failed" : "completed" : "in_progress",
55142
55327
  rawInput: args,
55143
55328
  // `rawOutput` is what the provider said, `content` is what a reader renders;
55144
55329
  // writing only the first left a replayed child tool showing no output.
55145
- ...settled ? {
55330
+ ...settled2 ? {
55146
55331
  rawOutput: text2,
55147
55332
  content: [
55148
55333
  ...failed ? [] : cursorFileChangeContent(entry.rawName, args, entry.payload.result),
@@ -55151,7 +55336,7 @@ function cursorSubagentConversationStepUpdates(steps, parentToolUseId2) {
55151
55336
  } : {},
55152
55337
  _meta: {
55153
55338
  ...childMeta(parentToolUseId2),
55154
- ...settled ? { [PROVIDER_PAYLOAD_META]: entry.payload.result } : {}
55339
+ ...settled2 ? { [PROVIDER_PAYLOAD_META]: entry.payload.result } : {}
55155
55340
  }
55156
55341
  });
55157
55342
  });
@@ -55175,10 +55360,10 @@ function cursorConversationStepText(steps) {
55175
55360
  function cursorTranscriptsRoot(context) {
55176
55361
  const projectKey = context.cwd.replace(/^[/\\]+/, "").replace(/[/\\]+/g, "-");
55177
55362
  const home = context.env.HOME || process.env.HOME || (0, import_os9.homedir)();
55178
- return (0, import_path17.join)(home, ".cursor", "projects", projectKey, "agent-transcripts");
55363
+ return (0, import_path18.join)(home, ".cursor", "projects", projectKey, "agent-transcripts");
55179
55364
  }
55180
55365
  function cursorTranscriptPathForAgent(context, agentId) {
55181
- return (0, import_path17.join)(cursorTranscriptsRoot(context), agentId, `${agentId}.jsonl`);
55366
+ return (0, import_path18.join)(cursorTranscriptsRoot(context), agentId, `${agentId}.jsonl`);
55182
55367
  }
55183
55368
  function resolveCursorSubagentTranscriptPath(success2, context) {
55184
55369
  const explicit = success2?.transcriptPath ?? success2?.transcript_path;
@@ -55548,10 +55733,10 @@ function workspaceKeys(cwd) {
55548
55733
  );
55549
55734
  }
55550
55735
  function cursorChatPresence(query) {
55551
- const chatsRoot = (0, import_path18.join)(query.home, ".cursor", "chats");
55736
+ const chatsRoot = (0, import_path19.join)(query.home, ".cursor", "chats");
55552
55737
  if (!(0, import_fs18.existsSync)(chatsRoot)) return "unknown";
55553
55738
  const found = workspaceKeys(query.cwd).some(
55554
- (key) => (0, import_fs18.existsSync)((0, import_path18.join)(chatsRoot, key, query.chatId, "store.db"))
55739
+ (key) => (0, import_fs18.existsSync)((0, import_path19.join)(chatsRoot, key, query.chatId, "store.db"))
55555
55740
  );
55556
55741
  return found ? "present" : "missing";
55557
55742
  }
@@ -56009,8 +56194,8 @@ function handleToolResult(event, context, state) {
56009
56194
  const text2 = droidToolResultText(event.value);
56010
56195
  const isError = event.isError === true;
56011
56196
  const updates = [];
56012
- const emitToolResult = (launcherId, settled, failed) => {
56013
- updates.push(settlementUpdate2(launcherId, settled, failed));
56197
+ const emitToolResult = (launcherId, settled2, failed) => {
56198
+ updates.push(settlementUpdate2(launcherId, settled2, failed));
56014
56199
  };
56015
56200
  const polledTaskId = polledTaskIdByToolId.get(state)?.get(toolCallId);
56016
56201
  if (polledTaskId) {
@@ -57520,7 +57705,7 @@ function kimiCliDialectFromHelp(help) {
57520
57705
  }
57521
57706
  function readHelp(command, context) {
57522
57707
  return new Promise((resolve52) => {
57523
- (0, import_child_process7.execFile)(
57708
+ (0, import_child_process8.execFile)(
57524
57709
  command,
57525
57710
  ["--help"],
57526
57711
  {
@@ -57564,8 +57749,8 @@ function createKimiCliBackend(command = "kimi", defaultArgs = []) {
57564
57749
  async run(context) {
57565
57750
  const dialect = await detectKimiCliDialect(command, context);
57566
57751
  const registration = dialect === "kimi-cli" ? context.config.alanMcp : void 0;
57567
- const mcpDirectory = registration ? (0, import_fs19.mkdtempSync)((0, import_path19.join)((0, import_os11.tmpdir)(), "alan-kimi-mcp-")) : null;
57568
- const mcpConfigPath = mcpDirectory ? (0, import_path19.join)(mcpDirectory, "mcp.json") : null;
57752
+ const mcpDirectory = registration ? (0, import_fs19.mkdtempSync)((0, import_path20.join)((0, import_os11.tmpdir)(), "alan-kimi-mcp-")) : null;
57753
+ const mcpConfigPath = mcpDirectory ? (0, import_path20.join)(mcpDirectory, "mcp.json") : null;
57569
57754
  if (registration && mcpConfigPath) {
57570
57755
  (0, import_fs19.writeFileSync)(
57571
57756
  mcpConfigPath,
@@ -57877,6 +58062,23 @@ var AgentRunner = class {
57877
58062
  content: [{ type: "text", text: text2 }]
57878
58063
  });
57879
58064
  }
58065
+ /**
58066
+ * Memory the API retrieved before the provider started, recorded as the
58067
+ * `search_context` call it stands in for so the transcript shows what the agent was given.
58068
+ */
58069
+ recordRelevantContext(recall) {
58070
+ if (!recall) return;
58071
+ this.emit({
58072
+ sessionUpdate: "tool_call_update",
58073
+ toolCallId: `relevant-context-${(0, import_crypto.randomUUID)()}`,
58074
+ name: "search_context",
58075
+ kind: "search",
58076
+ status: "completed",
58077
+ rawInput: { query: recall.query },
58078
+ rawOutput: JSON.stringify(recall.envelope),
58079
+ _meta: { "alan.dev/contextRecall": "prefetch" }
58080
+ });
58081
+ }
57880
58082
  log(message) {
57881
58083
  this.emit({ sessionUpdate: "_alan/log", source: "agent", message });
57882
58084
  }
@@ -58176,6 +58378,7 @@ ${runtimeConfig.task}` } : {}
58176
58378
  };
58177
58379
  this.host.onStart?.(initialConfig);
58178
58380
  this.recordUserMessage(config4.task);
58381
+ this.recordRelevantContext(config4.relevantContext);
58179
58382
  this.emit({ sessionUpdate: "state_update", state: "running" });
58180
58383
  let safeProjectPath = initialConfig.teamPath;
58181
58384
  if (initialConfig.teamPath) {
@@ -59236,8 +59439,8 @@ function readNativeTranscriptTurns(provider, chunk, baseOffset, skipped = []) {
59236
59439
  const records = draftLines.map((line) => line.record).filter(isRecordValue);
59237
59440
  const closing = transcript.closingUpdates(records, state);
59238
59441
  const error61 = turnError(draftLines, transcript);
59239
- const settled = index < drafts.length - 1 || error61 !== null || endsIdle([...updates.map((entry) => entry.update), ...closing]);
59240
- if (!hasContent && !settled) {
59442
+ const settled2 = index < drafts.length - 1 || error61 !== null || endsIdle([...updates.map((entry) => entry.update), ...closing]);
59443
+ if (!hasContent && !settled2) {
59241
59444
  if (index === drafts.length - 1) consumedEnd = draftLines[0].offset;
59242
59445
  return;
59243
59446
  }
@@ -59684,10 +59887,10 @@ var RuntimeRunHost = class extends BaseRunHost {
59684
59887
  completion = Promise.reject(error61);
59685
59888
  }
59686
59889
  }
59687
- const settled = completion.catch(() => void 0);
59688
- this.orderedDeliveryTail = settled;
59689
- void settled.then(() => {
59690
- if (this.orderedDeliveryTail === settled) {
59890
+ const settled2 = completion.catch(() => void 0);
59891
+ this.orderedDeliveryTail = settled2;
59892
+ void settled2.then(() => {
59893
+ if (this.orderedDeliveryTail === settled2) {
59691
59894
  this.orderedDeliveryTail = void 0;
59692
59895
  this.orderedDeliveryLeaseGate = void 0;
59693
59896
  }
@@ -61518,11 +61721,11 @@ var SocketWithoutUpgrade = class _SocketWithoutUpgrade extends Emitter {
61518
61721
  */
61519
61722
  _resetPingTimeout() {
61520
61723
  this.clearTimeoutFn(this._pingTimeoutTimer);
61521
- const delay4 = this._pingInterval + this._pingTimeout;
61522
- this._pingTimeoutTime = Date.now() + delay4;
61724
+ const delay5 = this._pingInterval + this._pingTimeout;
61725
+ this._pingTimeoutTime = Date.now() + delay5;
61523
61726
  this._pingTimeoutTimer = this.setTimeoutFn(() => {
61524
61727
  this._onClose("ping timeout");
61525
- }, delay4);
61728
+ }, delay5);
61526
61729
  if (this.opts.autoUnref) {
61527
61730
  this._pingTimeoutTimer.unref();
61528
61731
  }
@@ -61989,7 +62192,7 @@ function deconstructPacket(packet) {
61989
62192
  pack2.attachments = buffers.length;
61990
62193
  return { packet: pack2, buffers };
61991
62194
  }
61992
- function _deconstructPacket(data, buffers) {
62195
+ function _deconstructPacket(data, buffers, toJSON) {
61993
62196
  if (!data)
61994
62197
  return data;
61995
62198
  if (isBinary(data)) {
@@ -62003,6 +62206,9 @@ function _deconstructPacket(data, buffers) {
62003
62206
  }
62004
62207
  return newData;
62005
62208
  } else if (typeof data === "object" && !(data instanceof Date)) {
62209
+ if (data.toJSON && typeof data.toJSON === "function" && !toJSON) {
62210
+ return _deconstructPacket(data.toJSON(), buffers, true);
62211
+ }
62006
62212
  const newData = {};
62007
62213
  for (const key in data) {
62008
62214
  if (Object.prototype.hasOwnProperty.call(data, key)) {
@@ -62159,9 +62365,6 @@ var Decoder = class _Decoder extends Emitter {
62159
62365
  if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
62160
62366
  packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
62161
62367
  this.reconstructor = new BinaryReconstructor(packet);
62162
- if (packet.attachments === 0) {
62163
- super.emitReserved("decoded", packet);
62164
- }
62165
62368
  } else {
62166
62369
  super.emitReserved("decoded", packet);
62167
62370
  }
@@ -62202,7 +62405,7 @@ var Decoder = class _Decoder extends Emitter {
62202
62405
  throw new Error("Illegal attachments");
62203
62406
  }
62204
62407
  const n = Number(buf);
62205
- if (!isInteger(n) || n < 0) {
62408
+ if (!isInteger(n) || n < 1) {
62206
62409
  throw new Error("Illegal attachments");
62207
62410
  } else if (n > this.opts.maxAttachments) {
62208
62411
  throw new Error("too many attachments");
@@ -63503,8 +63706,8 @@ var Manager = class extends Emitter {
63503
63706
  this.emitReserved("reconnect_failed");
63504
63707
  this._reconnecting = false;
63505
63708
  } else {
63506
- const delay4 = this.backoff.duration();
63507
- debug10("will wait %dms before reconnect attempt", delay4);
63709
+ const delay5 = this.backoff.duration();
63710
+ debug10("will wait %dms before reconnect attempt", delay5);
63508
63711
  this._reconnecting = true;
63509
63712
  const timer = this.setTimeoutFn(() => {
63510
63713
  if (self.skipReconnect)
@@ -63524,7 +63727,7 @@ var Manager = class extends Emitter {
63524
63727
  self.onreconnect();
63525
63728
  }
63526
63729
  });
63527
- }, delay4);
63730
+ }, delay5);
63528
63731
  if (this.opts.autoUnref) {
63529
63732
  timer.unref();
63530
63733
  }
@@ -63749,11 +63952,11 @@ function removeNativeHooks(homeDir = (0, import_node_os14.homedir)()) {
63749
63952
  }
63750
63953
 
63751
63954
  // src/events/runtime-command-reply.ts
63752
- var import_promises5 = require("timers/promises");
63955
+ var import_promises6 = require("timers/promises");
63753
63956
  async function publishRuntimeCommandReply(path2, reply, credentials) {
63754
63957
  const body = JSON.stringify(reply);
63755
63958
  for (let attempt = 0; attempt < 2; attempt += 1) {
63756
- if (attempt > 0) await (0, import_promises5.setTimeout)(250, void 0, { signal: credentials.signal });
63959
+ if (attempt > 0) await (0, import_promises6.setTimeout)(250, void 0, { signal: credentials.signal });
63757
63960
  credentials.signal.throwIfAborted();
63758
63961
  let response;
63759
63962
  try {
@@ -63790,7 +63993,7 @@ var import_node_fs19 = require("fs");
63790
63993
  // src/events/live.ts
63791
63994
  var import_node_crypto9 = require("crypto");
63792
63995
  var import_node_fs17 = require("fs");
63793
- var import_promises8 = require("fs/promises");
63996
+ var import_promises9 = require("fs/promises");
63794
63997
 
63795
63998
  // src/events/http-retry.ts
63796
63999
  var TranscriptRequestError = class extends Error {
@@ -63851,7 +64054,7 @@ function requestDeadline(timeoutMs, parent) {
63851
64054
  // src/events/push.ts
63852
64055
  var import_node_crypto8 = require("crypto");
63853
64056
  var import_node_fs16 = require("fs");
63854
- var import_promises7 = require("fs/promises");
64057
+ var import_promises8 = require("fs/promises");
63855
64058
 
63856
64059
  // src/events/session.ts
63857
64060
  var import_node_fs15 = require("fs");
@@ -64060,7 +64263,7 @@ function writeRunTranscriptState(configPath, conversationId, runId, state) {
64060
64263
  }
64061
64264
 
64062
64265
  // src/events/transcript-buffer.ts
64063
- var import_promises6 = require("fs/promises");
64266
+ var import_promises7 = require("fs/promises");
64064
64267
  var RETAINED_BYTES = 256 * 1024;
64065
64268
  var MAX_PENDING_TRANSCRIPT_BYTES = 8 * 1024 * 1024;
64066
64269
  var TranscriptBuffer = class {
@@ -64120,7 +64323,7 @@ function closeTranscriptBuffer(path2, buffer) {
64120
64323
  async function retryTranscriptWrites(path2, runId) {
64121
64324
  const buffer = active.get(path2);
64122
64325
  if (!buffer || buffer.runId !== runId) return void 0;
64123
- const file2 = await (0, import_promises6.open)(path2, "r+");
64326
+ const file2 = await (0, import_promises7.open)(path2, "r+");
64124
64327
  try {
64125
64328
  const stat4 = await file2.stat();
64126
64329
  if (`${stat4.dev}.${stat4.ino}.${stat4.birthtimeMs}` !== buffer.generation)
@@ -64520,7 +64723,7 @@ function startTranscriptPush(target, onProblem) {
64520
64723
  const current = state();
64521
64724
  if (!current) throw new Error("Transcript run range disappeared");
64522
64725
  const end = Math.min(boundary, admitted + adaptivePushBytes);
64523
- const file2 = await (0, import_promises7.open)(path2, "r");
64726
+ const file2 = await (0, import_promises8.open)(path2, "r");
64524
64727
  let bytes;
64525
64728
  try {
64526
64729
  bytes = Buffer.alloc(end - admitted);
@@ -64597,9 +64800,9 @@ function startTranscriptPush(target, onProblem) {
64597
64800
  });
64598
64801
  return running;
64599
64802
  };
64600
- const schedule = (delay4) => {
64803
+ const schedule = (delay5) => {
64601
64804
  if (stopped || target.signal?.aborted) return;
64602
- const at = Math.max(Date.now() + delay4, retryNotBefore);
64805
+ const at = Math.max(Date.now() + delay5, retryNotBefore);
64603
64806
  if (timer && scheduledAt <= at) return;
64604
64807
  clearTimeout(timer);
64605
64808
  scheduledAt = at;
@@ -64619,7 +64822,7 @@ function startTranscriptPush(target, onProblem) {
64619
64822
  schedule(0);
64620
64823
  return;
64621
64824
  }
64622
- let delay4 = cached2 && (cached2.committedOffset < cached2.admittedOffset || cached2.finalOffset !== null && !cached2.finalized) ? Math.max(0, pollAt - Date.now()) : Number.POSITIVE_INFINITY;
64825
+ let delay5 = cached2 && (cached2.committedOffset < cached2.admittedOffset || cached2.finalOffset !== null && !cached2.finalized) ? Math.max(0, pollAt - Date.now()) : Number.POSITIVE_INFINITY;
64623
64826
  try {
64624
64827
  if (state()?.finalRequested && cached2?.finalOffset == null) {
64625
64828
  schedule(0);
@@ -64627,13 +64830,13 @@ function startTranscriptPush(target, onProblem) {
64627
64830
  }
64628
64831
  const remaining = size() - (cached2?.admittedOffset ?? 0);
64629
64832
  if (remaining > 0)
64630
- delay4 = Math.min(
64631
- delay4,
64833
+ delay5 = Math.min(
64834
+ delay5,
64632
64835
  remaining >= MAX_PUSH_BYTES ? 0 : Math.max(0, checkpointAt - Date.now())
64633
64836
  );
64634
64837
  } catch {
64635
64838
  }
64636
- if (Number.isFinite(delay4)) schedule(delay4);
64839
+ if (Number.isFinite(delay5)) schedule(delay5);
64637
64840
  };
64638
64841
  return {
64639
64842
  notify() {
@@ -64763,7 +64966,7 @@ function startTranscriptLive(target, onProblem) {
64763
64966
  if (active2 && from < active2.retainedFrom)
64764
64967
  length = Math.min(length, active2.retainedFrom - from);
64765
64968
  bytes = Buffer.alloc(length);
64766
- const file2 = await (0, import_promises8.open)(path2, "r");
64969
+ const file2 = await (0, import_promises9.open)(path2, "r");
64767
64970
  try {
64768
64971
  const read = await file2.read(bytes, 0, length, from);
64769
64972
  if (read.bytesRead !== length) throw new Error("Live transcript changed during read");
@@ -64779,9 +64982,9 @@ function startTranscriptLive(target, onProblem) {
64779
64982
  received = receipt.receivedOffset;
64780
64983
  }
64781
64984
  };
64782
- const schedule = (delay4) => {
64985
+ const schedule = (delay5) => {
64783
64986
  if (stopped || signal.aborted) return;
64784
- const at = Math.max(Date.now() + delay4, retryNotBefore);
64987
+ const at = Math.max(Date.now() + delay5, retryNotBefore);
64785
64988
  if (timer && scheduledAt <= at) return;
64786
64989
  clearTimeout(timer);
64787
64990
  scheduledAt = at;
@@ -65311,7 +65514,7 @@ function createTranscriptWatchRegistry() {
65311
65514
 
65312
65515
  // src/native/ingest.ts
65313
65516
  var import_node_fs21 = require("fs");
65314
- var import_promises10 = require("fs/promises");
65517
+ var import_promises11 = require("fs/promises");
65315
65518
 
65316
65519
  // src/native/alan-runs.ts
65317
65520
  function nativeProviderForBackend(backendKind) {
@@ -65650,7 +65853,7 @@ function reconcileTranscriptIdentity(entry, transcriptPath2, identity, size) {
65650
65853
 
65651
65854
  // src/native/turns.ts
65652
65855
  var import_node_crypto11 = require("crypto");
65653
- var import_promises9 = require("fs/promises");
65856
+ var import_promises10 = require("fs/promises");
65654
65857
  var SCAN_BYTES = 1024 * 1024;
65655
65858
  var MIN_READ_BYTES = 64 * 1024;
65656
65859
  var SKIPPED_RECORD_LINE = Buffer.from("\n");
@@ -65697,7 +65900,7 @@ async function findRecordEnd(handle, from, size) {
65697
65900
  return null;
65698
65901
  }
65699
65902
  async function readTranscriptWindow(path2, offset2, limits) {
65700
- const handle = await (0, import_promises9.open)(path2, "r");
65903
+ const handle = await (0, import_promises10.open)(path2, "r");
65701
65904
  try {
65702
65905
  const stats = await handle.stat({ bigint: true });
65703
65906
  const size = Number(stats.size);
@@ -66145,9 +66348,9 @@ function createNativeIngestionSink(deps) {
66145
66348
  eligible = [];
66146
66349
  } else {
66147
66350
  const index = lastMatchingTurnIndex(turns, target);
66148
- const delay4 = lagDelays.shift();
66149
- if (index < 0 && delay4 !== void 0) {
66150
- await sleep2(delay4, shutdown.signal);
66351
+ const delay5 = lagDelays.shift();
66352
+ if (index < 0 && delay5 !== void 0) {
66353
+ await sleep2(delay5, shutdown.signal);
66151
66354
  continue;
66152
66355
  }
66153
66356
  if (index < 0 && turns.length > 0)
@@ -66224,7 +66427,7 @@ function createNativeIngestionSink(deps) {
66224
66427
  store.put(entry);
66225
66428
  if (ending) log3("native-ingest-turn", worker, "closed");
66226
66429
  }
66227
- const current = await (0, import_promises10.stat)(path2).catch(() => void 0);
66430
+ const current = await (0, import_promises11.stat)(path2).catch(() => void 0);
66228
66431
  return { grewDuringPass: current !== void 0 && current.size > lastSize };
66229
66432
  };
66230
66433
  const handleFailure = (worker, error61) => {
@@ -66711,12 +66914,12 @@ var RuntimeSkillCoordinator = class {
66711
66914
  // src/skills/runtime-skill-manager.ts
66712
66915
  var import_node_buffer5 = require("buffer");
66713
66916
  var import_node_crypto14 = require("crypto");
66714
- var import_promises13 = require("fs/promises");
66917
+ var import_promises14 = require("fs/promises");
66715
66918
  var import_node_path24 = require("path");
66716
66919
 
66717
66920
  // src/skills/managed-skill-store.ts
66718
66921
  var import_node_crypto12 = require("crypto");
66719
- var import_promises11 = require("fs/promises");
66922
+ var import_promises12 = require("fs/promises");
66720
66923
  var import_node_path22 = require("path");
66721
66924
  var EMPTY_STATE = {
66722
66925
  version: 1,
@@ -66732,9 +66935,9 @@ var ManagedSkillStore = class _ManagedSkillStore {
66732
66935
  state;
66733
66936
  integrity;
66734
66937
  static async open(baseDirectory) {
66735
- await (0, import_promises11.mkdir)(baseDirectory, { recursive: true, mode: 448 });
66938
+ await (0, import_promises12.mkdir)(baseDirectory, { recursive: true, mode: 448 });
66736
66939
  try {
66737
- const parsed = JSON.parse(await (0, import_promises11.readFile)((0, import_node_path22.join)(baseDirectory, "state.json"), "utf8"));
66940
+ const parsed = JSON.parse(await (0, import_promises12.readFile)((0, import_node_path22.join)(baseDirectory, "state.json"), "utf8"));
66738
66941
  return new _ManagedSkillStore(baseDirectory, parseState(parsed), "verified");
66739
66942
  } catch (error61) {
66740
66943
  if (isMissingPath(error61)) {
@@ -66798,15 +67001,15 @@ var ManagedSkillStore = class _ManagedSkillStore {
66798
67001
  `.state.json.pending-${process.pid}-${(0, import_node_crypto12.randomBytes)(6).toString("hex")}`
66799
67002
  );
66800
67003
  try {
66801
- await (0, import_promises11.writeFile)(pendingPath, `${JSON.stringify(this.state, null, 2)}
67004
+ await (0, import_promises12.writeFile)(pendingPath, `${JSON.stringify(this.state, null, 2)}
66802
67005
  `, {
66803
67006
  encoding: "utf8",
66804
67007
  flag: "wx",
66805
67008
  mode: 384
66806
67009
  });
66807
- await (0, import_promises11.rename)(pendingPath, statePath);
67010
+ await (0, import_promises12.rename)(pendingPath, statePath);
66808
67011
  } finally {
66809
- await (0, import_promises11.rm)(pendingPath, { force: true });
67012
+ await (0, import_promises12.rm)(pendingPath, { force: true });
66810
67013
  }
66811
67014
  }
66812
67015
  };
@@ -66861,7 +67064,7 @@ function isMissingPath(error61) {
66861
67064
  // ../shared/dist/node/skill-bundle.js
66862
67065
  var import_node_buffer3 = require("buffer");
66863
67066
  var import_node_crypto13 = require("crypto");
66864
- var import_promises12 = require("fs/promises");
67067
+ var import_promises13 = require("fs/promises");
66865
67068
  var import_node_path23 = require("path");
66866
67069
  var import_node_stream = require("stream");
66867
67070
  var import_node_zlib = require("zlib");
@@ -66871,7 +67074,7 @@ async function createSkillBundle(packageRoot, options = {}) {
66871
67074
  const archive = (0, import_tar_stream.pack)();
66872
67075
  const tarPromise = collectStream(archive);
66873
67076
  for (const file2 of before.files) {
66874
- const bytes2 = await (0, import_promises12.readFile)((0, import_node_path23.join)(packageRoot, ...file2.path.split("/")));
67077
+ const bytes2 = await (0, import_promises13.readFile)((0, import_node_path23.join)(packageRoot, ...file2.path.split("/")));
66875
67078
  await addArchiveEntry(archive, {
66876
67079
  name: file2.path,
66877
67080
  type: "file",
@@ -66903,7 +67106,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
66903
67106
  throw new Error("Skill archive hash does not match the expected immutable Version");
66904
67107
  }
66905
67108
  const tarBytes = await decompressBounded(archiveBytes);
66906
- await (0, import_promises12.mkdir)(destination, { recursive: false, mode: 448 });
67109
+ await (0, import_promises13.mkdir)(destination, { recursive: false, mode: 448 });
66907
67110
  try {
66908
67111
  await extractTar(tarBytes, destination);
66909
67112
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -66911,7 +67114,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
66911
67114
  throw new Error("Extracted Skill package hash does not match the expected immutable Version");
66912
67115
  }
66913
67116
  } catch (error61) {
66914
- await (0, import_promises12.rm)(destination, { recursive: true, force: true });
67117
+ await (0, import_promises13.rm)(destination, { recursive: true, force: true });
66915
67118
  throw error61;
66916
67119
  }
66917
67120
  }
@@ -66987,8 +67190,8 @@ async function extractEntry(header, stream, destination, limits) {
66987
67190
  throw new Error(`Skill archive file size is invalid: ${path2}`);
66988
67191
  }
66989
67192
  const outputPath = (0, import_node_path23.join)(destination, ...path2.split("/"));
66990
- await (0, import_promises12.mkdir)((0, import_node_path23.dirname)(outputPath), { recursive: true, mode: 448 });
66991
- await (0, import_promises12.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
67193
+ await (0, import_promises13.mkdir)((0, import_node_path23.dirname)(outputPath), { recursive: true, mode: 448 });
67194
+ await (0, import_promises13.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
66992
67195
  }
66993
67196
  function requireSafeArchivePath(value2) {
66994
67197
  const normalized2 = value2.replaceAll("\\", "/").normalize("NFC");
@@ -67248,12 +67451,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67248
67451
  }
67249
67452
  async reconcileUnlocked(manifest) {
67250
67453
  const desired = desiredSkillManifestSchema.parse(manifest);
67251
- await (0, import_promises13.mkdir)(this.managedSkillsDirectory, { recursive: true, mode: 448 });
67252
- await (0, import_promises13.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "cache", "sha256"), {
67454
+ await (0, import_promises14.mkdir)(this.managedSkillsDirectory, { recursive: true, mode: 448 });
67455
+ await (0, import_promises14.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "cache", "sha256"), {
67253
67456
  recursive: true,
67254
67457
  mode: 448
67255
67458
  });
67256
- await (0, import_promises13.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "tmp"), { recursive: true, mode: 448 });
67459
+ await (0, import_promises14.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "tmp"), { recursive: true, mode: 448 });
67257
67460
  const results = [];
67258
67461
  const nextProjections = {};
67259
67462
  for (const entry of desired.skills) {
@@ -67376,52 +67579,52 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67376
67579
  let sourceMoved = false;
67377
67580
  let destinationInstalled = false;
67378
67581
  try {
67379
- await (0, import_promises13.rename)(source2, backup);
67582
+ await (0, import_promises14.rename)(source2, backup);
67380
67583
  sourceMoved = true;
67381
- await (0, import_promises13.cp)(backup, pending, { recursive: true, errorOnExist: true, force: false });
67584
+ await (0, import_promises14.cp)(backup, pending, { recursive: true, errorOnExist: true, force: false });
67382
67585
  const skillMarkdown = (0, import_node_path24.join)(pending, "SKILL.md");
67383
- await (0, import_promises13.writeFile)(
67586
+ await (0, import_promises14.writeFile)(
67384
67587
  skillMarkdown,
67385
- rewriteSkillMarkdownName(await (0, import_promises13.readFile)(skillMarkdown, "utf8"), name),
67588
+ rewriteSkillMarkdownName(await (0, import_promises14.readFile)(skillMarkdown, "utf8"), name),
67386
67589
  {
67387
67590
  encoding: "utf8",
67388
67591
  mode: 420
67389
67592
  }
67390
67593
  );
67391
67594
  await inspectSkillPackage(pending, { expectedName: name });
67392
- await (0, import_promises13.rename)(pending, destination);
67595
+ await (0, import_promises14.rename)(pending, destination);
67393
67596
  destinationInstalled = true;
67394
- await (0, import_promises13.rm)(backup, { recursive: true, force: true });
67597
+ await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67395
67598
  } catch (error61) {
67396
- if (destinationInstalled) await (0, import_promises13.rm)(destination, { recursive: true, force: true });
67599
+ if (destinationInstalled) await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67397
67600
  if (sourceMoved && await pathExists2(backup) && !await pathExists2(source2)) {
67398
- await (0, import_promises13.rename)(backup, source2);
67601
+ await (0, import_promises14.rename)(backup, source2);
67399
67602
  }
67400
67603
  throw error61;
67401
67604
  } finally {
67402
- await (0, import_promises13.rm)(pending, { recursive: true, force: true });
67605
+ await (0, import_promises14.rm)(pending, { recursive: true, force: true });
67403
67606
  if (!sourceMoved || destinationInstalled) {
67404
- await (0, import_promises13.rm)(backup, { recursive: true, force: true });
67607
+ await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67405
67608
  }
67406
67609
  }
67407
67610
  }
67408
67611
  async overwriteLocalConflict(input2, entry, conflict, manifest) {
67409
67612
  const source2 = this.conflictDirectory(entry.runtimeDirectory, conflict.kind);
67410
67613
  const backup = `${source2}.overwrite-backup-${process.pid}-${(0, import_node_crypto14.randomBytes)(8).toString("hex")}`;
67411
- await (0, import_promises13.rename)(source2, backup);
67614
+ await (0, import_promises14.rename)(source2, backup);
67412
67615
  try {
67413
67616
  const reconciled = await this.reconcileUnlocked(manifest);
67414
67617
  const result = resolutionFromReconcile(input2, reconciled);
67415
67618
  if (result.state !== "applied") {
67416
67619
  await this.removeResolvedProjection(entry, conflict.kind);
67417
- await (0, import_promises13.rename)(backup, source2);
67620
+ await (0, import_promises14.rename)(backup, source2);
67418
67621
  return result;
67419
67622
  }
67420
- await (0, import_promises13.rm)(backup, { recursive: true, force: true });
67623
+ await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67421
67624
  return result;
67422
67625
  } catch (error61) {
67423
67626
  await this.removeResolvedProjection(entry, conflict.kind).catch(() => void 0);
67424
- if (!await pathExists2(source2) && await pathExists2(backup)) await (0, import_promises13.rename)(backup, source2);
67627
+ if (!await pathExists2(source2) && await pathExists2(backup)) await (0, import_promises14.rename)(backup, source2);
67425
67628
  throw error61;
67426
67629
  }
67427
67630
  }
@@ -67431,7 +67634,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67431
67634
  if (conflictKind === "managed_destination") {
67432
67635
  const marker = await readMarker(destination);
67433
67636
  if (marker?.skillId === entry.skillId && marker.versionId === entry.versionId && marker.contentHash === entry.contentHash) {
67434
- await (0, import_promises13.rm)(destination, { recursive: true, force: true });
67637
+ await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67435
67638
  }
67436
67639
  return;
67437
67640
  }
@@ -67463,16 +67666,16 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67463
67666
  if (!await legacyFileMatches(source2, legacy.hash) || !await packageMatches(source2, entry.contentHash)) {
67464
67667
  return;
67465
67668
  }
67466
- await (0, import_promises13.rename)(source2, destination);
67669
+ await (0, import_promises14.rename)(source2, destination);
67467
67670
  try {
67468
- await (0, import_promises13.writeFile)(
67671
+ await (0, import_promises14.writeFile)(
67469
67672
  (0, import_node_path24.join)(destination, ".alan-managed.json"),
67470
67673
  `${JSON.stringify(markerFor(entry), null, 2)}
67471
67674
  `,
67472
67675
  { encoding: "utf8", flag: "wx", mode: 384 }
67473
67676
  );
67474
67677
  } catch (error61) {
67475
- await (0, import_promises13.rename)(destination, source2).catch(() => void 0);
67678
+ await (0, import_promises14.rename)(destination, source2).catch(() => void 0);
67476
67679
  throw error61;
67477
67680
  }
67478
67681
  await removeExactLegacySkill((0, import_node_path24.join)(this.compatibilitySkillsDirectory, entry.slug), legacy.hash);
@@ -67485,7 +67688,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67485
67688
  await removeExactLegacySkill((0, import_node_path24.join)(this.managedSkillsDirectory, command), entry.hash);
67486
67689
  await removeExactLegacySkill((0, import_node_path24.join)(this.compatibilitySkillsDirectory, command), entry.hash);
67487
67690
  }
67488
- await (0, import_promises13.rm)(this.legacyManifestPath, { force: true });
67691
+ await (0, import_promises14.rm)(this.legacyManifestPath, { force: true });
67489
67692
  }
67490
67693
  async ensureCached(entry) {
67491
67694
  const cacheDirectory = (0, import_node_path24.join)(
@@ -67495,7 +67698,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67495
67698
  entry.contentHash.slice("sha256:".length)
67496
67699
  );
67497
67700
  if (await packageMatches(cacheDirectory, entry.contentHash)) return cacheDirectory;
67498
- await (0, import_promises13.rm)(cacheDirectory, { recursive: true, force: true });
67701
+ await (0, import_promises14.rm)(cacheDirectory, { recursive: true, force: true });
67499
67702
  const bytes = await this.downloadBundle(entry);
67500
67703
  if (bytes.byteLength !== entry.compressedBytes) {
67501
67704
  throw new Error(
@@ -67513,12 +67716,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67513
67716
  expectedContentHash: entry.contentHash
67514
67717
  });
67515
67718
  try {
67516
- await (0, import_promises13.rename)(pendingDirectory, cacheDirectory);
67719
+ await (0, import_promises14.rename)(pendingDirectory, cacheDirectory);
67517
67720
  } catch (error61) {
67518
67721
  if (!await packageMatches(cacheDirectory, entry.contentHash)) throw error61;
67519
67722
  }
67520
67723
  } finally {
67521
- await (0, import_promises13.rm)(pendingDirectory, { recursive: true, force: true });
67724
+ await (0, import_promises14.rm)(pendingDirectory, { recursive: true, force: true });
67522
67725
  }
67523
67726
  return cacheDirectory;
67524
67727
  }
@@ -67536,8 +67739,8 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67536
67739
  let installedPending = false;
67537
67740
  let completed = false;
67538
67741
  try {
67539
- await (0, import_promises13.cp)(cacheDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67540
- await (0, import_promises13.writeFile)(
67742
+ await (0, import_promises14.cp)(cacheDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67743
+ await (0, import_promises14.writeFile)(
67541
67744
  (0, import_node_path24.join)(pending, ".alan-managed.json"),
67542
67745
  `${JSON.stringify(markerFor(entry), null, 2)}
67543
67746
  `,
@@ -67547,14 +67750,14 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67547
67750
  throw new Error("Pending managed Skill projection failed content verification");
67548
67751
  }
67549
67752
  if (await pathExists2(destination)) {
67550
- await (0, import_promises13.rename)(destination, backup);
67753
+ await (0, import_promises14.rename)(destination, backup);
67551
67754
  movedExisting = true;
67552
67755
  }
67553
67756
  try {
67554
- await (0, import_promises13.rename)(pending, destination);
67757
+ await (0, import_promises14.rename)(pending, destination);
67555
67758
  installedPending = true;
67556
67759
  } catch (error61) {
67557
- if (movedExisting) await (0, import_promises13.rename)(backup, destination);
67760
+ if (movedExisting) await (0, import_promises14.rename)(backup, destination);
67558
67761
  throw error61;
67559
67762
  }
67560
67763
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -67563,18 +67766,18 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67563
67766
  }
67564
67767
  await this.ensureCompatibilityProjection(entry, destination);
67565
67768
  completed = true;
67566
- await (0, import_promises13.rm)(backup, { recursive: true, force: true });
67769
+ await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67567
67770
  return inspected.contentHash;
67568
67771
  } catch (error61) {
67569
67772
  if (!completed && installedPending) {
67570
- await (0, import_promises13.rm)(destination, { recursive: true, force: true });
67571
- if (movedExisting && await pathExists2(backup)) await (0, import_promises13.rename)(backup, destination);
67773
+ await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67774
+ if (movedExisting && await pathExists2(backup)) await (0, import_promises14.rename)(backup, destination);
67572
67775
  }
67573
67776
  throw error61;
67574
67777
  } finally {
67575
- await (0, import_promises13.rm)(pending, { recursive: true, force: true });
67778
+ await (0, import_promises14.rm)(pending, { recursive: true, force: true });
67576
67779
  if (completed || !movedExisting) {
67577
- await (0, import_promises13.rm)(backup, { recursive: true, force: true });
67780
+ await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67578
67781
  }
67579
67782
  }
67580
67783
  }
@@ -67602,7 +67805,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67602
67805
  const failures = [];
67603
67806
  let entries;
67604
67807
  try {
67605
- entries = await (0, import_promises13.readdir)(this.managedSkillsDirectory);
67808
+ entries = await (0, import_promises14.readdir)(this.managedSkillsDirectory);
67606
67809
  } catch (error61) {
67607
67810
  if (isMissingPath2(error61)) return failures;
67608
67811
  throw error61;
@@ -67639,12 +67842,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67639
67842
  });
67640
67843
  continue;
67641
67844
  }
67642
- await (0, import_promises13.rm)(destination, { recursive: true, force: true });
67845
+ await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67643
67846
  }
67644
67847
  return failures;
67645
67848
  }
67646
67849
  async ensureCompatibilityProjection(entry, canonicalDirectory) {
67647
- await (0, import_promises13.mkdir)(this.compatibilitySkillsDirectory, { recursive: true, mode: 448 });
67850
+ await (0, import_promises14.mkdir)(this.compatibilitySkillsDirectory, { recursive: true, mode: 448 });
67648
67851
  const destination = (0, import_node_path24.join)(
67649
67852
  this.compatibilitySkillsDirectory,
67650
67853
  this.projectionDirectoryName(entry.runtimeDirectory)
@@ -67654,23 +67857,23 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67654
67857
  throw unmanagedCompatibilityConflict(entry.runtimeDirectory);
67655
67858
  }
67656
67859
  try {
67657
- await (0, import_promises13.symlink)(canonicalDirectory, destination, "dir");
67860
+ await (0, import_promises14.symlink)(canonicalDirectory, destination, "dir");
67658
67861
  return;
67659
67862
  } catch (error61) {
67660
67863
  if (!isSymlinkUnsupported(error61)) throw error61;
67661
67864
  }
67662
67865
  const pending = `${destination}.pending-${process.pid}-${(0, import_node_crypto14.randomBytes)(6).toString("hex")}`;
67663
67866
  try {
67664
- await (0, import_promises13.cp)(canonicalDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67665
- await (0, import_promises13.writeFile)(
67867
+ await (0, import_promises14.cp)(canonicalDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67868
+ await (0, import_promises14.writeFile)(
67666
67869
  (0, import_node_path24.join)(pending, ".alan-compatibility.json"),
67667
67870
  `${JSON.stringify({ ...markerFor(entry), canonicalDirectory }, null, 2)}
67668
67871
  `,
67669
67872
  { encoding: "utf8", flag: "wx", mode: 384 }
67670
67873
  );
67671
- await (0, import_promises13.rename)(pending, destination);
67874
+ await (0, import_promises14.rename)(pending, destination);
67672
67875
  } finally {
67673
- await (0, import_promises13.rm)(pending, { recursive: true, force: true });
67876
+ await (0, import_promises14.rm)(pending, { recursive: true, force: true });
67674
67877
  }
67675
67878
  }
67676
67879
  async runExclusively(work) {
@@ -67694,29 +67897,29 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67694
67897
  return this.storageNamespace ? `${runtimeDirectory}--alan-${this.storageNamespace}` : runtimeDirectory;
67695
67898
  }
67696
67899
  async withMachineLock(work) {
67697
- await (0, import_promises13.mkdir)(this.skillsStateDirectory, { recursive: true, mode: 448 });
67900
+ await (0, import_promises14.mkdir)(this.skillsStateDirectory, { recursive: true, mode: 448 });
67698
67901
  const lockDirectory = (0, import_node_path24.join)(this.skillsStateDirectory, "manager.lock");
67699
67902
  const deadline = Date.now() + 3e4;
67700
67903
  while (true) {
67701
67904
  try {
67702
- await (0, import_promises13.mkdir)(lockDirectory, { mode: 448 });
67905
+ await (0, import_promises14.mkdir)(lockDirectory, { mode: 448 });
67703
67906
  try {
67704
- await (0, import_promises13.writeFile)(
67907
+ await (0, import_promises14.writeFile)(
67705
67908
  (0, import_node_path24.join)(lockDirectory, "owner.json"),
67706
67909
  `${JSON.stringify({ pid: process.pid, acquiredAt: (/* @__PURE__ */ new Date()).toISOString() })}
67707
67910
  `,
67708
67911
  { encoding: "utf8", flag: "wx", mode: 384 }
67709
67912
  );
67710
67913
  } catch (error61) {
67711
- await (0, import_promises13.rm)(lockDirectory, { recursive: true, force: true });
67914
+ await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
67712
67915
  throw error61;
67713
67916
  }
67714
67917
  break;
67715
67918
  } catch (error61) {
67716
67919
  if (!isAlreadyPresent2(error61)) throw error61;
67717
- const ageMs = await (0, import_promises13.stat)(lockDirectory).then((metadata) => Date.now() - metadata.mtimeMs).catch(() => 0);
67920
+ const ageMs = await (0, import_promises14.stat)(lockDirectory).then((metadata) => Date.now() - metadata.mtimeMs).catch(() => 0);
67718
67921
  if (ageMs > 15 * 6e4) {
67719
- await (0, import_promises13.rm)(lockDirectory, { recursive: true, force: true });
67922
+ await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
67720
67923
  continue;
67721
67924
  }
67722
67925
  if (Date.now() >= deadline) {
@@ -67730,7 +67933,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67730
67933
  try {
67731
67934
  return await work();
67732
67935
  } finally {
67733
- await (0, import_promises13.rm)(lockDirectory, { recursive: true, force: true });
67936
+ await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
67734
67937
  }
67735
67938
  }
67736
67939
  };
@@ -67752,7 +67955,7 @@ async function packageMatches(directory, expectedHash) {
67752
67955
  async function readMarker(directory) {
67753
67956
  try {
67754
67957
  const value2 = JSON.parse(
67755
- await (0, import_promises13.readFile)((0, import_node_path24.join)(directory, ".alan-managed.json"), "utf8")
67958
+ await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, ".alan-managed.json"), "utf8")
67756
67959
  );
67757
67960
  if (typeof value2 !== "object" || value2 === null || !("protocolVersion" in value2) || value2.protocolVersion !== SKILLS_PROTOCOL_VERSION || !("skillId" in value2) || typeof value2.skillId !== "string" || !("versionId" in value2) || typeof value2.versionId !== "string" || !("contentHash" in value2) || typeof value2.contentHash !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value2.contentHash)) {
67758
67961
  return null;
@@ -67763,9 +67966,9 @@ async function readMarker(directory) {
67763
67966
  }
67764
67967
  }
67765
67968
  async function compatibilityProjectionMatches(destination, canonicalDirectory, entry) {
67766
- const metadata = await (0, import_promises13.lstat)(destination);
67969
+ const metadata = await (0, import_promises14.lstat)(destination);
67767
67970
  if (metadata.isSymbolicLink()) {
67768
- const target = await (0, import_promises13.readlink)(destination);
67971
+ const target = await (0, import_promises14.readlink)(destination);
67769
67972
  return (0, import_node_path24.resolve)((0, import_node_path24.dirname)(destination), target) === (0, import_node_path24.resolve)(canonicalDirectory);
67770
67973
  }
67771
67974
  if (!metadata.isDirectory()) return false;
@@ -67774,22 +67977,22 @@ async function compatibilityProjectionMatches(destination, canonicalDirectory, e
67774
67977
  }
67775
67978
  async function removeCompatibilityProjection(destination, canonicalDirectory, projection) {
67776
67979
  if (!await pathExists2(destination)) return true;
67777
- const metadata = await (0, import_promises13.lstat)(destination);
67980
+ const metadata = await (0, import_promises14.lstat)(destination);
67778
67981
  if (metadata.isSymbolicLink()) {
67779
- const target = await (0, import_promises13.readlink)(destination);
67982
+ const target = await (0, import_promises14.readlink)(destination);
67780
67983
  if ((0, import_node_path24.resolve)((0, import_node_path24.dirname)(destination), target) !== (0, import_node_path24.resolve)(canonicalDirectory)) return false;
67781
- await (0, import_promises13.rm)(destination, { force: true });
67984
+ await (0, import_promises14.rm)(destination, { force: true });
67782
67985
  return true;
67783
67986
  }
67784
67987
  const marker = await readCompatibilityMarker(destination);
67785
67988
  if (!marker || !markerMatchesProjection(marker, projection)) return false;
67786
- await (0, import_promises13.rm)(destination, { recursive: true, force: true });
67989
+ await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67787
67990
  return true;
67788
67991
  }
67789
67992
  async function readCompatibilityMarker(directory) {
67790
67993
  try {
67791
67994
  const value2 = JSON.parse(
67792
- await (0, import_promises13.readFile)((0, import_node_path24.join)(directory, ".alan-compatibility.json"), "utf8")
67995
+ await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, ".alan-compatibility.json"), "utf8")
67793
67996
  );
67794
67997
  if (value2.protocolVersion !== SKILLS_PROTOCOL_VERSION || typeof value2.skillId !== "string" || typeof value2.versionId !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value2.contentHash) || typeof value2.canonicalDirectory !== "string") {
67795
67998
  return null;
@@ -67809,7 +68012,7 @@ function markerFor(entry) {
67809
68012
  }
67810
68013
  async function readLegacyManifest(path2) {
67811
68014
  try {
67812
- const value2 = JSON.parse(await (0, import_promises13.readFile)(path2, "utf8"));
68015
+ const value2 = JSON.parse(await (0, import_promises14.readFile)(path2, "utf8"));
67813
68016
  if (!value2 || typeof value2 !== "object" || !("skills" in value2)) return null;
67814
68017
  const skillsValue = value2.skills;
67815
68018
  if (!skillsValue || typeof skillsValue !== "object" || Array.isArray(skillsValue)) return null;
@@ -67827,9 +68030,9 @@ async function readLegacyManifest(path2) {
67827
68030
  }
67828
68031
  async function legacyFileMatches(directory, expectedHash) {
67829
68032
  try {
67830
- const metadata = await (0, import_promises13.lstat)(directory);
68033
+ const metadata = await (0, import_promises14.lstat)(directory);
67831
68034
  if (!metadata.isDirectory() || metadata.isSymbolicLink()) return false;
67832
- const content = await (0, import_promises13.readFile)((0, import_node_path24.join)(directory, "SKILL.md"));
68035
+ const content = await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, "SKILL.md"));
67833
68036
  return (0, import_node_crypto14.createHash)("sha256").update(content).digest("hex").slice(0, 16) === expectedHash;
67834
68037
  } catch {
67835
68038
  return false;
@@ -67837,9 +68040,9 @@ async function legacyFileMatches(directory, expectedHash) {
67837
68040
  }
67838
68041
  async function removeExactLegacySkill(directory, expectedHash) {
67839
68042
  if (!await legacyFileMatches(directory, expectedHash)) return;
67840
- await (0, import_promises13.rm)((0, import_node_path24.join)(directory, "SKILL.md"), { force: true });
67841
- const remaining = await (0, import_promises13.readdir)(directory);
67842
- if (remaining.length === 0) await (0, import_promises13.rm)(directory, { recursive: true, force: true });
68043
+ await (0, import_promises14.rm)((0, import_node_path24.join)(directory, "SKILL.md"), { force: true });
68044
+ const remaining = await (0, import_promises14.readdir)(directory);
68045
+ if (remaining.length === 0) await (0, import_promises14.rm)(directory, { recursive: true, force: true });
67843
68046
  }
67844
68047
  function markerMatchesProjection(marker, projection) {
67845
68048
  return marker.skillId === projection.skillId && marker.versionId === projection.versionId && marker.contentHash === projection.contentHash;
@@ -67941,7 +68144,7 @@ function localTextMediaType(path2) {
67941
68144
  }
67942
68145
  async function pathExists2(path2) {
67943
68146
  try {
67944
- await (0, import_promises13.lstat)(path2);
68147
+ await (0, import_promises14.lstat)(path2);
67945
68148
  return true;
67946
68149
  } catch (error61) {
67947
68150
  if (isMissingPath2(error61)) return false;
@@ -68383,6 +68586,9 @@ function buildAgentRunConfig(input2) {
68383
68586
  teamId: input2.teamId,
68384
68587
  currentUser: input2.currentUser,
68385
68588
  sessionVisibility: input2.sessionVisibility,
68589
+ codeIndexEnabled: input2.codeIndexEnabled,
68590
+ contextGraphEnabled: input2.contextGraphEnabled,
68591
+ relevantContext: input2.relevantContext,
68386
68592
  workflowTools: input2.workflowTools,
68387
68593
  workflowId: input2.workflowId,
68388
68594
  workflowExecutionId: input2.workflowExecutionId,
@@ -68424,19 +68630,19 @@ ${input2.userRequest}
68424
68630
  }
68425
68631
 
68426
68632
  // src/workspace-run-lease.ts
68427
- var import_promises14 = require("fs/promises");
68633
+ var import_promises15 = require("fs/promises");
68428
68634
  var import_node_path25 = require("path");
68429
68635
  var WORKSPACE_LEASE_CHECK_INTERVAL_MS = 1e3;
68430
68636
  async function hasGitWorkspaceMarker(workspacePath) {
68431
68637
  let directory;
68432
68638
  try {
68433
- directory = await (0, import_promises14.realpath)((0, import_node_path25.resolve)(workspacePath));
68639
+ directory = await (0, import_promises15.realpath)((0, import_node_path25.resolve)(workspacePath));
68434
68640
  } catch {
68435
68641
  return true;
68436
68642
  }
68437
68643
  while (true) {
68438
68644
  try {
68439
- await (0, import_promises14.stat)((0, import_node_path25.join)(directory, ".git"));
68645
+ await (0, import_promises15.stat)((0, import_node_path25.join)(directory, ".git"));
68440
68646
  return true;
68441
68647
  } catch (error61) {
68442
68648
  const code = error61.code;
@@ -68448,8 +68654,8 @@ async function hasGitWorkspaceMarker(workspacePath) {
68448
68654
  }
68449
68655
  }
68450
68656
  async function filesystemIdentity(path2) {
68451
- const canonicalPath = await (0, import_promises14.realpath)(path2);
68452
- const metadata = await (0, import_promises14.stat)(canonicalPath);
68657
+ const canonicalPath = await (0, import_promises15.realpath)(path2);
68658
+ const metadata = await (0, import_promises15.stat)(canonicalPath);
68453
68659
  return `${canonicalPath}:${metadata.dev}:${metadata.ino}`;
68454
68660
  }
68455
68661
  function resolveGitPath(workspacePath, value2) {
@@ -68461,7 +68667,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
68461
68667
  const marker = (0, import_node_path25.join)(directory, ".git");
68462
68668
  let markerStats;
68463
68669
  try {
68464
- markerStats = await (0, import_promises14.stat)(marker);
68670
+ markerStats = await (0, import_promises15.stat)(marker);
68465
68671
  } catch (error61) {
68466
68672
  const code = error61.code;
68467
68673
  if (code !== "ENOENT" && code !== "ENOTDIR") return null;
@@ -68475,7 +68681,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
68475
68681
  }
68476
68682
  let pointer;
68477
68683
  try {
68478
- pointer = await (0, import_promises14.readFile)(marker, "utf8");
68684
+ pointer = await (0, import_promises15.readFile)(marker, "utf8");
68479
68685
  } catch {
68480
68686
  return null;
68481
68687
  }
@@ -68484,7 +68690,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
68484
68690
  const gitDirectory = resolveGitPath(directory, gitDirMatch[1].trim());
68485
68691
  let commonDirectory = gitDirectory;
68486
68692
  try {
68487
- const commonRaw = (await (0, import_promises14.readFile)((0, import_node_path25.join)(gitDirectory, "commondir"), "utf8")).trim();
68693
+ const commonRaw = (await (0, import_promises15.readFile)((0, import_node_path25.join)(gitDirectory, "commondir"), "utf8")).trim();
68488
68694
  if (commonRaw) commonDirectory = (0, import_node_path25.resolve)(gitDirectory, commonRaw);
68489
68695
  } catch (error61) {
68490
68696
  const code = error61.code;
@@ -68530,7 +68736,7 @@ var DEFAULT_PROBE = {
68530
68736
  snapshot: createWorkspaceRunLeaseSnapshotProbe(snapshotWorkspace),
68531
68737
  pathExists: async (workspacePath) => {
68532
68738
  try {
68533
- await (0, import_promises14.access)((0, import_node_path25.resolve)(workspacePath));
68739
+ await (0, import_promises15.access)((0, import_node_path25.resolve)(workspacePath));
68534
68740
  return true;
68535
68741
  } catch (error61) {
68536
68742
  return error61.code !== "ENOENT";
@@ -68539,7 +68745,7 @@ var DEFAULT_PROBE = {
68539
68745
  };
68540
68746
  async function snapshotWorkspace(workspacePath) {
68541
68747
  try {
68542
- const canonicalWorkspacePath = await (0, import_promises14.realpath)((0, import_node_path25.resolve)(workspacePath));
68748
+ const canonicalWorkspacePath = await (0, import_promises15.realpath)((0, import_node_path25.resolve)(workspacePath));
68543
68749
  const gitPaths = await resolveGitIdentityPaths(canonicalWorkspacePath);
68544
68750
  if (!gitPaths) return null;
68545
68751
  return {
@@ -69097,7 +69303,7 @@ function admitWithToken(ctx, payload, tokenReady, heartbeatSeq, disconnectedSinc
69097
69303
  const runtimeToken = ctx.getRuntimeToken();
69098
69304
  const provider = resolveProvider(ctx, payload);
69099
69305
  return provider instanceof Promise ? provider.then(
69100
- (settled) => settleAdmission(ctx, payload, runtimeToken, settled, heartbeatSeq, disconnectedSinceMs)
69306
+ (settled2) => settleAdmission(ctx, payload, runtimeToken, settled2, heartbeatSeq, disconnectedSinceMs)
69101
69307
  ) : settleAdmission(ctx, payload, runtimeToken, provider, heartbeatSeq, disconnectedSinceMs);
69102
69308
  }
69103
69309
  function settleAdmission(ctx, payload, runtimeToken, provider, heartbeatSeq, disconnectedSinceMs) {
@@ -69456,6 +69662,9 @@ async function launchRun(ctx, payload, plan) {
69456
69662
  teamId: payload.teamId,
69457
69663
  currentUser: payload.currentUser,
69458
69664
  sessionVisibility: payload.sessionVisibility,
69665
+ codeIndexEnabled: payload.codeIndexEnabled,
69666
+ contextGraphEnabled: payload.contextGraphEnabled,
69667
+ relevantContext: payload.relevantContext,
69459
69668
  workflowTools: payload.workflowTools,
69460
69669
  workflowId: payload.workflowId,
69461
69670
  workflowExecutionId: payload.workflowExecutionId,
@@ -70892,7 +71101,7 @@ async function runNetworkGit(cwd, args, code) {
70892
71101
  let stderr = "";
70893
71102
  let outputExceeded = false;
70894
71103
  let timedOut = false;
70895
- let settled = false;
71104
+ let settled2 = false;
70896
71105
  const killTree = () => {
70897
71106
  if (child.pid && process.platform !== "win32") {
70898
71107
  try {
@@ -70923,14 +71132,14 @@ async function runNetworkGit(cwd, args, code) {
70923
71132
  stderr = append(stderr, chunk);
70924
71133
  });
70925
71134
  child.once("error", (error61) => {
70926
- if (settled) return;
70927
- settled = true;
71135
+ if (settled2) return;
71136
+ settled2 = true;
70928
71137
  clearTimeout(timer);
70929
71138
  rejectPromise(new BindingSwitchGitError(code, error61.message));
70930
71139
  });
70931
71140
  child.once("close", (exitCode) => {
70932
- if (settled) return;
70933
- settled = true;
71141
+ if (settled2) return;
71142
+ settled2 = true;
70934
71143
  clearTimeout(timer);
70935
71144
  if (timedOut) {
70936
71145
  rejectPromise(
@@ -75174,7 +75383,7 @@ async function setupWindowsRuntime(commandArgs) {
75174
75383
  throw new Error("Windows runtime setup completed without a local readiness endpoint");
75175
75384
  }
75176
75385
  const probe = () => probeLocalDaemon(localApiPort, localApiToken, Math.min(250, remainingMs()));
75177
- const poll = () => (0, import_promises15.setTimeout)(Math.min(100, remainingMs()), void 0, { signal: controller.signal });
75386
+ const poll = () => (0, import_promises16.setTimeout)(Math.min(100, remainingMs()), void 0, { signal: controller.signal });
75178
75387
  if (runtimeIdentityChanged) {
75179
75388
  while (true) {
75180
75389
  const status2 = await probe();
@@ -75491,14 +75700,14 @@ var AgentResourceSampler = class {
75491
75700
  if (this.inFlight) return;
75492
75701
  this.inFlight = true;
75493
75702
  const generation = this.generation;
75494
- const delay4 = this.delay.count > 0 ? {
75703
+ const delay5 = this.delay.count > 0 ? {
75495
75704
  eventLoopDelayMaxMs: this.delay.max / 1e6,
75496
75705
  eventLoopDelayP99Ms: this.delay.percentile(99) / 1e6
75497
75706
  } : {};
75498
75707
  this.delay.reset();
75499
75708
  try {
75500
75709
  const sample = await this.collect();
75501
- if (generation === this.generation) this.sample = { ...sample, ...delay4 };
75710
+ if (generation === this.generation) this.sample = { ...sample, ...delay5 };
75502
75711
  } catch {
75503
75712
  if (generation === this.generation) this.sample = void 0;
75504
75713
  } finally {
@@ -75815,6 +76024,9 @@ var WSClient = class {
75815
76024
  teamId: data.teamId,
75816
76025
  currentUser: data.currentUser,
75817
76026
  sessionVisibility: data.sessionVisibility,
76027
+ codeIndexEnabled: data.codeIndexEnabled,
76028
+ contextGraphEnabled: data.contextGraphEnabled,
76029
+ relevantContext: data.relevantContext,
75818
76030
  terminalContextRefs: data.terminalContextRefs,
75819
76031
  terminalSnapshots: data.terminalSnapshots,
75820
76032
  externalMcpServers: data.externalMcpServers
@@ -76309,7 +76521,7 @@ var ExecutionLeaseClient = class {
76309
76521
  const remaining = deadline - Date.now();
76310
76522
  if (remaining <= 0) throw new Error("Sandbox provider protection timed out");
76311
76523
  if (!this.inFlight) this.requestRenewal();
76312
- await delay3(Math.min(remaining, EXECUTION_PROTECTION_POLL_MS));
76524
+ await delay4(Math.min(remaining, EXECUTION_PROTECTION_POLL_MS));
76313
76525
  }
76314
76526
  throw new Error("Execution authority was lost before provider protection");
76315
76527
  }
@@ -76323,7 +76535,7 @@ var ExecutionLeaseClient = class {
76323
76535
  const remaining = deadline - Date.now();
76324
76536
  if (remaining <= 0) throw new Error("Execution protection capability timed out");
76325
76537
  if (!this.inFlight) this.requestRenewal();
76326
- await delay3(Math.min(remaining, EXECUTION_PROTECTION_POLL_MS));
76538
+ await delay4(Math.min(remaining, EXECUTION_PROTECTION_POLL_MS));
76327
76539
  }
76328
76540
  throw new Error("Execution authority was lost before protection capability resolved");
76329
76541
  }
@@ -76550,7 +76762,7 @@ var ExecutionLeaseClient = class {
76550
76762
  return;
76551
76763
  }
76552
76764
  }
76553
- await delay3(this.retryDelaysMs[attempt] ?? 0);
76765
+ await delay4(this.retryDelaysMs[attempt] ?? 0);
76554
76766
  }
76555
76767
  }
76556
76768
  };
@@ -76588,7 +76800,7 @@ async function readErrorBody(response) {
76588
76800
  return {};
76589
76801
  }
76590
76802
  }
76591
- function delay3(ms) {
76803
+ function delay4(ms) {
76592
76804
  return new Promise((resolve16) => setTimeout(resolve16, ms));
76593
76805
  }
76594
76806
 
@@ -76627,6 +76839,9 @@ function initialTurn(seed) {
76627
76839
  teamId: seed.teamId,
76628
76840
  currentUser: seed.currentUser,
76629
76841
  sessionVisibility: seed.sessionVisibility,
76842
+ codeIndexEnabled: void 0,
76843
+ contextGraphEnabled: void 0,
76844
+ relevantContext: void 0,
76630
76845
  terminalContextRefs: void 0,
76631
76846
  terminalSnapshots: void 0
76632
76847
  };
@@ -76649,6 +76864,10 @@ function applyUserMessage(turn, patch) {
76649
76864
  canonicalUserMessage: patch.canonicalUserMessage,
76650
76865
  canonicalAssistantMessage: patch.canonicalAssistantMessage,
76651
76866
  cloudEnvironmentId: patch.cloudEnvironmentId,
76867
+ // Entitlements and recall are decided per message, so an omission never inherits.
76868
+ codeIndexEnabled: patch.codeIndexEnabled,
76869
+ contextGraphEnabled: patch.contextGraphEnabled,
76870
+ relevantContext: patch.relevantContext,
76652
76871
  // A resume hint only travels with the session it belongs to.
76653
76872
  ...patch.providerSessionId ? {
76654
76873
  providerSessionId: patch.providerSessionId,
@@ -77024,6 +77243,9 @@ async function runSandbox(config4) {
77024
77243
  teamId: turn.teamId,
77025
77244
  currentUser: turn.currentUser,
77026
77245
  sessionVisibility: turn.sessionVisibility,
77246
+ codeIndexEnabled: turn.codeIndexEnabled,
77247
+ contextGraphEnabled: turn.contextGraphEnabled,
77248
+ relevantContext: turn.relevantContext,
77027
77249
  workflowTools: turn.workflowTools,
77028
77250
  workflowId,
77029
77251
  workflowExecutionId,
@@ -77122,7 +77344,7 @@ async function runSandbox(config4) {
77122
77344
  }
77123
77345
 
77124
77346
  // src/skills/skill-cli.ts
77125
- var import_promises16 = require("fs/promises");
77347
+ var import_promises17 = require("fs/promises");
77126
77348
  var import_node_os22 = require("os");
77127
77349
  var import_node_path40 = require("path");
77128
77350
  async function runSkillsCommand(args) {
@@ -77169,7 +77391,7 @@ async function defaultScanInput(homeDirectory2) {
77169
77391
  }
77170
77392
  async function readProtectedJson(path2) {
77171
77393
  const absolutePath = (0, import_node_path40.resolve)(path2);
77172
- const stat4 = await (0, import_promises16.lstat)(absolutePath);
77394
+ const stat4 = await (0, import_promises17.lstat)(absolutePath);
77173
77395
  if (!stat4.isFile()) throw new Error(`Skill input is not a regular file: ${absolutePath}`);
77174
77396
  if (process.platform !== "win32" && (stat4.mode & 63) !== 0) {
77175
77397
  throw new Error(`Skill input must not be accessible by group or other users: ${absolutePath}`);
@@ -77178,7 +77400,7 @@ async function readProtectedJson(path2) {
77178
77400
  throw new Error(`Skill input must be owned by the current user: ${absolutePath}`);
77179
77401
  }
77180
77402
  if (stat4.size > 2 * 1024 * 1024) throw new Error("Skill input exceeds 2 MiB");
77181
- return JSON.parse(await (0, import_promises16.readFile)(absolutePath, "utf8"));
77403
+ return JSON.parse(await (0, import_promises17.readFile)(absolutePath, "utf8"));
77182
77404
  }
77183
77405
  function option2(args, name) {
77184
77406
  const index = args.indexOf(name);