@alan-ai-hq/agent-manager-darwin-arm64 0.1.170 → 0.1.172

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/alan-agent.cjs CHANGED
@@ -1576,8 +1576,8 @@ var init_regexes = __esm({
1576
1576
  _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
1577
1577
  ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
1578
1578
  ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
1579
- mac = (delimiter) => {
1580
- const escapedDelim = escapeRegex(delimiter ?? ":");
1579
+ mac = (delimiter2) => {
1580
+ const escapedDelim = escapeRegex(delimiter2 ?? ":");
1581
1581
  return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
1582
1582
  };
1583
1583
  cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
@@ -20664,7 +20664,7 @@ var init_cloud_repositories = __esm({
20664
20664
  "../shared/dist/constants/cloud-repositories.js"() {
20665
20665
  "use strict";
20666
20666
  MAX_CLOUD_REPOSITORIES = 64;
20667
- CLOUD_REPOSITORY_LIMIT_MESSAGE = `Select at most ${MAX_CLOUD_REPOSITORIES} repositories per cloud session or environment`;
20667
+ CLOUD_REPOSITORY_LIMIT_MESSAGE = `Select at most ${MAX_CLOUD_REPOSITORIES} repositories for one cloud session`;
20668
20668
  }
20669
20669
  });
20670
20670
 
@@ -23453,7 +23453,7 @@ function getAlanModePrompt(mode) {
23453
23453
  function getAlanAgentPrompt(agentId) {
23454
23454
  return getAgentSystemPrompt(agentId);
23455
23455
  }
23456
- var ALAN_CONTEXT_SEARCH_PROMPT, ALAN_PLATFORM_TOOL_ROUTING_PROMPT, ALAN_OPENUI_COMPONENT_SIGNATURES, ALAN_VISUAL_PROMPT, ALAN_VISUAL_REMINDER_PROMPT, ALAN_IDENTITY_PROMPT, ALAN_CODE_CONTEXT_PROMPT, PLAN_MODE_PROMPT, ASK_MODE_PROMPT, REVIEW_MODE_PROMPT;
23456
+ var ALAN_CONTEXT_SEARCH_PROMPT, ALAN_PLATFORM_TOOL_ROUTING_PROMPT, ALAN_OPENUI_COMPONENT_SIGNATURES, ALAN_VISUAL_PROMPT, ALAN_VISUAL_REMINDER_PROMPT, ALAN_SUGGESTING_WORK_PROMPT, ALAN_IDENTITY_PROMPT, ALAN_CODE_CONTEXT_PROMPT, PLAN_MODE_PROMPT, ASK_MODE_PROMPT, REVIEW_MODE_PROMPT;
23457
23457
  var init_system_prompt = __esm({
23458
23458
  "../shared/dist/agent/system-prompt.js"() {
23459
23459
  "use strict";
@@ -23532,6 +23532,12 @@ ${ALAN_OPENUI_COMPONENT_SIGNATURES.map((signature) => ` ${signature}`).join("\n
23532
23532
  ALAN_VISUAL_REMINDER_PROMPT = `## Answer format
23533
23533
 
23534
23534
  Before replying in the Alan chat, consider what the user is trying to do and whether a visual would serve it better than paragraphs: comparisons, trends, statuses, timelines, plans and options go in a \`\`\`chart, \`\`\`mermaid or \`\`\`openui block even when nobody asked for one. Trivial answers stay plain text.`;
23535
+ ALAN_SUGGESTING_WORK_PROMPT = `## Suggesting Work
23536
+
23537
+ When \`suggest_task\` is available, use it to put work in the session's side panel for the user to pick up; it creates nothing by itself.
23538
+ - \`convert_session\`: suggest once when a chat that is not linked to a task has turned into multi-step delivery work (code changes, a PR, several turns). Give the title and description the task should have.
23539
+ - \`follow_up\`: suggest real, separate work you found and did not do, such as a bug, risky debt or a missing test. Never the next step of the current request or work you are about to do. Include \`handoffContext\` with what a fresh session needs: verified findings, files, decisions.
23540
+ - Prefer none. At most three in a turn, never a duplicate (check \`list_task_suggestions\`), and withdraw one that stops applying. Do not mention suggestions in your reply.`;
23535
23541
  ALAN_IDENTITY_PROMPT = `You are Alan, the software factory agent. Alan ships software end to end \u2014 plan, write, review, test, deploy.
23536
23542
 
23537
23543
  ## How Alan is structured
@@ -23574,7 +23580,9 @@ When the user refers to a specific task, document, or epic by human identifier (
23574
23580
 
23575
23581
  ## Task Logging
23576
23582
 
23577
- For non-trivial tasks, log high-signal events as they happen: decisions, changed assumptions, validation results, known-good IDs, blockers, risks, direction changes, and session outcomes. Do not log routine commands or file reads. Before stopping, ensure the Agent Log and current session outcome are enough for a human to understand progress and for another agent to resume. If a prior event or decision is stale, supersede it instead of appending contradictory state.`;
23583
+ For non-trivial tasks, log high-signal events as they happen: decisions, changed assumptions, validation results, known-good IDs, blockers, risks, direction changes, and session outcomes. Do not log routine commands or file reads. Before stopping, ensure the Agent Log and current session outcome are enough for a human to understand progress and for another agent to resume. If a prior event or decision is stale, supersede it instead of appending contradictory state.
23584
+
23585
+ ${ALAN_SUGGESTING_WORK_PROMPT}`;
23578
23586
  ALAN_CODE_CONTEXT_PROMPT = buildAlanCodeContextPrompt();
23579
23587
  PLAN_MODE_PROMPT = [
23580
23588
  "You are in Alan plan mode.",
@@ -23940,6 +23948,17 @@ var init_models = __esm({
23940
23948
  contextWindow: 1048576,
23941
23949
  maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
23942
23950
  },
23951
+ {
23952
+ id: "particle-ai/particle-1",
23953
+ name: "Particle-1",
23954
+ description: "Particle AI's token-efficient coding model via Alan",
23955
+ enabled: true,
23956
+ isDefault: false,
23957
+ sortOrder: 25,
23958
+ upstreamModelId: "particle-ai/particle-1",
23959
+ contextWindow: 1048576,
23960
+ maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
23961
+ },
23943
23962
  {
23944
23963
  id: "z-ai/glm-5.3",
23945
23964
  name: "GLM 5.3",
@@ -27167,7 +27186,7 @@ var init_chunk_WYNUYKKN = __esm({
27167
27186
  }
27168
27187
  });
27169
27188
 
27170
- // ../agent-core/dist/chunk-KVTSAS2T.js
27189
+ // ../agent-core/dist/chunk-A5UQ6YFO.js
27171
27190
  function windowsEnvValue(env, name) {
27172
27191
  const wanted = name.toLowerCase();
27173
27192
  for (const [key, value2] of Object.entries(env).reverse()) {
@@ -27415,28 +27434,123 @@ function invalidChoiceIndicatesSupport(output2, flag2) {
27415
27434
  if (output2.includes(`unknown option '${flag2}'`)) return false;
27416
27435
  return output2.includes(`'${flag2}`) && output2.includes("is invalid");
27417
27436
  }
27418
- function createFlagProbe(capture = captureOutput) {
27419
- const cache2 = /* @__PURE__ */ new Map();
27420
- const remember = (key, answer) => {
27421
- const cached2 = cache2.get(key);
27422
- if (cached2) return cached2;
27423
- const pending = answer();
27424
- cache2.set(key, pending);
27425
- return pending;
27437
+ function createFlagProbe(options = {}) {
27438
+ const { capture = captureOutput, store } = typeof options === "function" ? { capture: options, store: void 0 } : options;
27439
+ const commands = /* @__PURE__ */ new Map();
27440
+ const answersFor = (command, env) => {
27441
+ const known = commands.get(command);
27442
+ if (known) return known;
27443
+ const loading = (store?.read(command, env) ?? Promise.resolve(null)).catch(() => null).then(
27444
+ (stored) => ({
27445
+ record: stored ?? { hiddenChoiceFlags: {} },
27446
+ hidden: /* @__PURE__ */ new Map(),
27447
+ persisting: Promise.resolve()
27448
+ })
27449
+ );
27450
+ commands.set(command, loading);
27451
+ return loading;
27452
+ };
27453
+ const persist = (command, env, answers) => {
27454
+ if (store === void 0) return;
27455
+ answers.persisting = answers.persisting.then(() => store.write(command, env, answers.record)).catch(() => void 0);
27456
+ };
27457
+ const helpOf = async (command, env) => {
27458
+ const answers = await answersFor(command, env);
27459
+ if (answers.record.help !== void 0) return answers.record.help;
27460
+ answers.help ??= capture(command, ["--help"], { env }).then(({ stdout, stderr, exitCode }) => {
27461
+ const help = `${stdout}${stderr}`;
27462
+ if (exitCode !== void 0) {
27463
+ answers.record.help = help;
27464
+ persist(command, env, answers);
27465
+ }
27466
+ return help;
27467
+ });
27468
+ return answers.help;
27426
27469
  };
27427
27470
  return {
27428
- supportsFlag: (command, flag2, env) => remember(`${command}\0${flag2}`, async () => {
27429
- const { stdout, stderr } = await capture(command, ["--help"], { env });
27430
- return helpAdvertisesFlag(`${stdout}${stderr}`, flag2);
27431
- }),
27432
- supportsHiddenChoiceFlag: (command, flag2, env) => remember(`${command}\0hidden\0${flag2}`, async () => {
27433
- const { stdout, stderr } = await capture(
27434
- command,
27435
- [flag2, HIDDEN_FLAG_PROBE_VALUE, "--version"],
27436
- { env }
27471
+ persisted: async () => {
27472
+ const loaded = await Promise.all(commands.values());
27473
+ await Promise.all(loaded.map((answers) => answers.persisting));
27474
+ },
27475
+ supportsFlag: async (command, flag2, env) => helpAdvertisesFlag(await helpOf(command, env), flag2),
27476
+ supportsHiddenChoiceFlag: async (command, flag2, env) => {
27477
+ const answers = await answersFor(command, env);
27478
+ const stored = answers.record.hiddenChoiceFlags[flag2];
27479
+ if (stored !== void 0) return stored;
27480
+ const known = answers.hidden.get(flag2);
27481
+ if (known) return known;
27482
+ const probing = capture(command, [flag2, HIDDEN_FLAG_PROBE_VALUE, "--version"], { env }).then(
27483
+ ({ stdout, stderr, exitCode }) => {
27484
+ const supported = invalidChoiceIndicatesSupport(`${stdout}${stderr}`, flag2);
27485
+ if (exitCode !== void 0) {
27486
+ answers.record.hiddenChoiceFlags[flag2] = supported;
27487
+ persist(command, env, answers);
27488
+ }
27489
+ return supported;
27490
+ }
27437
27491
  );
27438
- return invalidChoiceIndicatesSupport(`${stdout}${stderr}`, flag2);
27439
- })
27492
+ answers.hidden.set(flag2, probing);
27493
+ return probing;
27494
+ }
27495
+ };
27496
+ }
27497
+ async function resolveBinary(command, env) {
27498
+ const candidates2 = command.includes("/") ? [command] : (env.PATH ?? "").split(import_path2.delimiter).filter((dir) => dir.length > 0).map((dir) => (0, import_path2.join)(dir, command));
27499
+ for (const candidate of candidates2) {
27500
+ if (!(0, import_path2.isAbsolute)(candidate)) continue;
27501
+ try {
27502
+ await (0, import_promises19.access)(candidate, import_fs2.constants.X_OK);
27503
+ return candidate;
27504
+ } catch {
27505
+ }
27506
+ }
27507
+ return null;
27508
+ }
27509
+ async function identify(command, env) {
27510
+ const path4 = await resolveBinary(command, env);
27511
+ if (path4 === null) return null;
27512
+ const { mtimeMs, size } = await (0, import_promises19.stat)(path4);
27513
+ return { path: path4, mtimeMs, size };
27514
+ }
27515
+ function isStoredBinary(value2) {
27516
+ if (typeof value2 !== "object" || value2 === null) return false;
27517
+ const entry = value2;
27518
+ return typeof entry.mtimeMs === "number" && typeof entry.size === "number" && typeof entry.record === "object" && entry.record !== null && typeof entry.record.hiddenChoiceFlags === "object";
27519
+ }
27520
+ async function readAll(file2) {
27521
+ try {
27522
+ const parsed = JSON.parse(await (0, import_promises19.readFile)(file2, "utf8"));
27523
+ if (typeof parsed !== "object" || parsed === null) return {};
27524
+ return Object.fromEntries(
27525
+ Object.entries(parsed).filter(
27526
+ (entry) => isStoredBinary(entry[1])
27527
+ )
27528
+ );
27529
+ } catch {
27530
+ return {};
27531
+ }
27532
+ }
27533
+ function createFileFlagProbeStore(file2, platform3 = process.platform) {
27534
+ return {
27535
+ read: async (command, env) => {
27536
+ if (platform3 === "win32") return null;
27537
+ const identity = await identify(command, env);
27538
+ if (identity === null) return null;
27539
+ const stored = (await readAll(file2))[identity.path];
27540
+ if (stored?.mtimeMs !== identity.mtimeMs || stored.size !== identity.size) return null;
27541
+ return stored.record;
27542
+ },
27543
+ write: async (command, env, record2) => {
27544
+ if (platform3 === "win32") return;
27545
+ const identity = await identify(command, env);
27546
+ if (identity === null) return;
27547
+ const all = await readAll(file2);
27548
+ all[identity.path] = { mtimeMs: identity.mtimeMs, size: identity.size, record: record2 };
27549
+ await (0, import_promises19.mkdir)((0, import_path2.dirname)(file2), { recursive: true });
27550
+ const staging = `${file2}.${process.pid}.tmp`;
27551
+ await (0, import_promises19.writeFile)(staging, JSON.stringify(all), { mode: 384 });
27552
+ await (0, import_promises19.rename)(staging, file2);
27553
+ }
27440
27554
  };
27441
27555
  }
27442
27556
  function decode3(bytes, start2, end) {
@@ -27445,8 +27559,8 @@ function decode3(bytes, start2, end) {
27445
27559
  }
27446
27560
  async function linuxStartTicks(pid) {
27447
27561
  try {
27448
- const stat23 = await (0, import_promises19.readFile)(`/proc/${pid}/stat`, "utf8");
27449
- const fields = stat23.slice(stat23.lastIndexOf(")") + 2).split(" ");
27562
+ const stat24 = await (0, import_promises20.readFile)(`/proc/${pid}/stat`, "utf8");
27563
+ const fields = stat24.slice(stat24.lastIndexOf(")") + 2).split(" ");
27450
27564
  return fields[19];
27451
27565
  } catch {
27452
27566
  return void 0;
@@ -27704,15 +27818,15 @@ function helperFile(env) {
27704
27818
  if (override) return override;
27705
27819
  const entry = process.argv[1];
27706
27820
  if (!entry) throw new CoreFault("spawn_failed", "Cannot locate the Windows agent helper");
27707
- return (0, import_path2.join)((0, import_path2.dirname)(entry), "alan-winhelper.exe");
27821
+ return (0, import_path3.join)((0, import_path3.dirname)(entry), "alan-winhelper.exe");
27708
27822
  }
27709
27823
  function spawnInWindowsJob(plan2, options) {
27710
27824
  if (plan2.commandLine === null) {
27711
27825
  throw new CoreFault("internal", `No Windows command line was planned for ${plan2.file}`);
27712
27826
  }
27713
27827
  const file2 = helperFile(options.env);
27714
- const directory = (0, import_fs3.mkdtempSync)((0, import_path2.join)((0, import_os.tmpdir)(), `alan-job-${(0, import_crypto2.randomUUID)()}-`));
27715
- const path4 = (0, import_path2.join)(directory, "started");
27828
+ const directory = (0, import_fs4.mkdtempSync)((0, import_path3.join)((0, import_os.tmpdir)(), `alan-job-${(0, import_crypto2.randomUUID)()}-`));
27829
+ const path4 = (0, import_path3.join)(directory, "started");
27716
27830
  const child = (0, import_child_process6.spawn)(file2, [String(process.pid)], {
27717
27831
  cwd: options.cwd,
27718
27832
  env: {
@@ -27732,13 +27846,14 @@ function spawnInWindowsJob(plan2, options) {
27732
27846
  statuses.set(child, status);
27733
27847
  return child;
27734
27848
  }
27735
- async function waitForWindowsJob(child, command) {
27849
+ async function waitForWindowsJob(child, command, options = {}) {
27736
27850
  const status = statuses.get(child);
27737
27851
  if (!status) throw new CoreFault("internal", "Missing Windows helper startup state");
27738
- const deadline = systemClock2.monotonic() + START_TIMEOUT_MS;
27852
+ const deadline = systemClock2.monotonic() + (options.timeoutMs ?? START_TIMEOUT_MS);
27739
27853
  try {
27740
27854
  while (systemClock2.monotonic() < deadline) {
27741
- const providerPid = await (0, import_promises20.readFile)(status.path, "utf8").catch(() => void 0);
27855
+ options.signal?.throwIfAborted();
27856
+ const providerPid = await (0, import_promises21.readFile)(status.path, "utf8").catch(() => void 0);
27742
27857
  if (providerPid !== void 0) {
27743
27858
  requireStartedProvider(providerPid, command);
27744
27859
  return;
@@ -27755,18 +27870,18 @@ async function waitForWindowsJob(child, command) {
27755
27870
  if (child.exitCode !== null || child.signalCode !== null) {
27756
27871
  throw new CoreFault("spawn_failed", `Could not start ${command} (Windows helper exited)`);
27757
27872
  }
27758
- await systemClock2.sleep(25);
27873
+ await systemClock2.sleep(25, options.signal);
27759
27874
  }
27760
27875
  child.kill("SIGKILL");
27761
27876
  throw new CoreFault("spawn_failed", `Could not start ${command} (Windows helper timed out)`);
27762
27877
  } finally {
27763
27878
  statuses.delete(child);
27764
- await (0, import_promises20.rm)(status.directory, { recursive: true, force: true });
27879
+ await (0, import_promises21.rm)(status.directory, { recursive: true, force: true });
27765
27880
  }
27766
27881
  }
27767
27882
  function preferForOomKill(pid) {
27768
27883
  try {
27769
- (0, import_fs2.writeFileSync)(`/proc/${pid}/oom_score_adj`, String(CLI_OOM_SCORE_ADJ));
27884
+ (0, import_fs3.writeFileSync)(`/proc/${pid}/oom_score_adj`, String(CLI_OOM_SCORE_ADJ));
27770
27885
  } catch {
27771
27886
  }
27772
27887
  }
@@ -27815,7 +27930,7 @@ function waitForSpawn(child, command) {
27815
27930
  }
27816
27931
  function inode(path4) {
27817
27932
  try {
27818
- return (0, import_fs4.statSync)(path4).ino;
27933
+ return (0, import_fs5.statSync)(path4).ino;
27819
27934
  } catch (error62) {
27820
27935
  if (errnoCode2(error62) !== "ENOENT") throw error62;
27821
27936
  return void 0;
@@ -27826,7 +27941,7 @@ async function removeDeadOwner(path4) {
27826
27941
  try {
27827
27942
  let owner;
27828
27943
  try {
27829
- owner = asRecord(JSON.parse((0, import_fs4.readFileSync)(path4, "utf8")));
27944
+ owner = asRecord(JSON.parse((0, import_fs5.readFileSync)(path4, "utf8")));
27830
27945
  } catch (error62) {
27831
27946
  if (!(error62 instanceof SyntaxError)) throw error62;
27832
27947
  }
@@ -27843,24 +27958,24 @@ async function removeDeadOwner(path4) {
27843
27958
  const actualStart = expectedStart ? await readProcessStartTime(pid) : void 0;
27844
27959
  dead ||= actualStart !== void 0 && actualStart !== expectedStart;
27845
27960
  }
27846
- if (dead && observed !== void 0 && inode(path4) === observed) (0, import_fs4.rmSync)(path4, { force: true });
27961
+ if (dead && observed !== void 0 && inode(path4) === observed) (0, import_fs5.rmSync)(path4, { force: true });
27847
27962
  } catch (error62) {
27848
27963
  if (errnoCode2(error62) !== "ENOENT") throw error62;
27849
27964
  }
27850
27965
  }
27851
27966
  async function withStartupLock(path4, clock, work, signal) {
27852
- (0, import_fs4.mkdirSync)((0, import_path3.dirname)(path4), { recursive: true, mode: 448 });
27967
+ (0, import_fs5.mkdirSync)((0, import_path4.dirname)(path4), { recursive: true, mode: 448 });
27853
27968
  const candidate = `${path4}.${(0, import_crypto3.randomUUID)()}`;
27854
27969
  const startedAt = await readProcessStartTime(process.pid);
27855
- (0, import_fs4.writeFileSync)(candidate, JSON.stringify({ pid: process.pid, startedAt }), { mode: 384 });
27856
- const owned = (0, import_fs4.statSync)(candidate).ino;
27970
+ (0, import_fs5.writeFileSync)(candidate, JSON.stringify({ pid: process.pid, startedAt }), { mode: 384 });
27971
+ const owned = (0, import_fs5.statSync)(candidate).ino;
27857
27972
  const deadline = clock.monotonic() + 12e4;
27858
27973
  let acquired = false;
27859
27974
  try {
27860
27975
  for (; ; ) {
27861
27976
  signal?.throwIfAborted();
27862
27977
  try {
27863
- (0, import_fs4.linkSync)(candidate, path4);
27978
+ (0, import_fs5.linkSync)(candidate, path4);
27864
27979
  acquired = true;
27865
27980
  break;
27866
27981
  } catch (error62) {
@@ -27873,33 +27988,36 @@ async function withStartupLock(path4, clock, work, signal) {
27873
27988
  }
27874
27989
  return await work();
27875
27990
  } finally {
27876
- if (acquired && inode(path4) === owned) (0, import_fs4.rmSync)(path4, { force: true });
27877
- (0, import_fs4.rmSync)(candidate, { force: true });
27991
+ if (acquired && inode(path4) === owned) (0, import_fs5.rmSync)(path4, { force: true });
27992
+ (0, import_fs5.rmSync)(candidate, { force: true });
27878
27993
  }
27879
27994
  }
27880
- var import_child_process, import_fs, import_path, import_child_process2, import_promises19, import_child_process3, import_child_process4, import_child_process5, import_fs2, import_child_process6, import_crypto2, import_fs3, import_promises20, import_os, import_path2, import_crypto3, import_fs4, import_path3, SHIM_MAX_BYTES, CMD_MAX_COMMAND_LINE, MAX_COMMAND_LINE, DEFAULT_PATHEXT, LAUNCHABLE_EXTENSIONS, nodeWindowsFiles, NODE_SHIM_ENTRY, SCRIPT_EXTENSION, NATIVE_SHIM_LINES, NATIVE_SHIM_ENTRY, CMD_META, NEVER_STARTED, HIDDEN_FLAG_PROBE_VALUE, NEWLINE, CARRIAGE_RETURN, EMPTY, MAX_LINE_BYTES2, LineSplitter, PS_LINE, POLL_MS, DEFAULT_GRACE_MS, DEFAULT_KILL_WAIT_MS, DEFAULT_TASKKILL_TIMEOUT_MS, statuses, START_TIMEOUT_MS, CLI_OOM_SCORE_ADJ, spawnListeners;
27881
- var init_chunk_KVTSAS2T = __esm({
27882
- "../agent-core/dist/chunk-KVTSAS2T.js"() {
27995
+ var import_child_process, import_fs, import_path, import_fs2, import_promises19, import_path2, import_child_process2, import_promises20, import_child_process3, import_child_process4, import_child_process5, import_fs3, import_child_process6, import_crypto2, import_fs4, import_promises21, import_os, import_path3, import_crypto3, import_fs5, import_path4, SHIM_MAX_BYTES, CMD_MAX_COMMAND_LINE, MAX_COMMAND_LINE, DEFAULT_PATHEXT, LAUNCHABLE_EXTENSIONS, nodeWindowsFiles, NODE_SHIM_ENTRY, SCRIPT_EXTENSION, NATIVE_SHIM_LINES, NATIVE_SHIM_ENTRY, CMD_META, NEVER_STARTED, HIDDEN_FLAG_PROBE_VALUE, NEWLINE, CARRIAGE_RETURN, EMPTY, MAX_LINE_BYTES2, LineSplitter, PS_LINE, POLL_MS, DEFAULT_GRACE_MS, DEFAULT_KILL_WAIT_MS, DEFAULT_TASKKILL_TIMEOUT_MS, statuses, START_TIMEOUT_MS, CLI_OOM_SCORE_ADJ, spawnListeners;
27996
+ var init_chunk_A5UQ6YFO = __esm({
27997
+ "../agent-core/dist/chunk-A5UQ6YFO.js"() {
27883
27998
  "use strict";
27884
27999
  init_chunk_YXWJW7I5();
27885
28000
  import_child_process = require("child_process");
27886
28001
  import_fs = require("fs");
27887
28002
  import_path = require("path");
27888
- import_child_process2 = require("child_process");
28003
+ import_fs2 = require("fs");
27889
28004
  import_promises19 = require("fs/promises");
28005
+ import_path2 = require("path");
28006
+ import_child_process2 = require("child_process");
28007
+ import_promises20 = require("fs/promises");
27890
28008
  import_child_process3 = require("child_process");
27891
28009
  import_child_process4 = require("child_process");
27892
28010
  import_child_process5 = require("child_process");
27893
- import_fs2 = require("fs");
28011
+ import_fs3 = require("fs");
27894
28012
  import_child_process6 = require("child_process");
27895
28013
  import_crypto2 = require("crypto");
27896
- import_fs3 = require("fs");
27897
- import_promises20 = require("fs/promises");
27898
- import_os = require("os");
27899
- import_path2 = require("path");
27900
- import_crypto3 = require("crypto");
27901
28014
  import_fs4 = require("fs");
28015
+ import_promises21 = require("fs/promises");
28016
+ import_os = require("os");
27902
28017
  import_path3 = require("path");
28018
+ import_crypto3 = require("crypto");
28019
+ import_fs5 = require("fs");
28020
+ import_path4 = require("path");
27903
28021
  SHIM_MAX_BYTES = 64 * 1024;
27904
28022
  CMD_MAX_COMMAND_LINE = 8191;
27905
28023
  MAX_COMMAND_LINE = 32766;
@@ -27990,7 +28108,7 @@ var init_chunk_KVTSAS2T = __esm({
27990
28108
  }
27991
28109
  });
27992
28110
 
27993
- // ../agent-core/dist/chunk-U4RQE7JS.js
28111
+ // ../agent-core/dist/chunk-CGBCAZEN.js
27994
28112
  function detectImageMimeType(buffer) {
27995
28113
  if (buffer.length >= 8 && buffer.subarray(0, 8).equals(PNG_SIGNATURE)) return "image/png";
27996
28114
  if (buffer.length >= 3 && buffer[0] === 255 && buffer[1] === 216 && buffer[2] === 255) {
@@ -28055,14 +28173,14 @@ function normalizePath(candidate, cwd) {
28055
28173
  } catch {
28056
28174
  }
28057
28175
  if (path4.startsWith("~/")) return void 0;
28058
- if ((0, import_path4.isAbsolute)(path4)) return path4;
28059
- return cwd ? (0, import_path4.join)(cwd, path4) : void 0;
28176
+ if ((0, import_path5.isAbsolute)(path4)) return path4;
28177
+ return cwd ? (0, import_path5.join)(cwd, path4) : void 0;
28060
28178
  }
28061
28179
  function toolCwd(cwd, toolInput2) {
28062
28180
  if (!isJsonRecord(toolInput2)) return cwd;
28063
28181
  const raw = asString(toolInput2.cwd) || asString(toolInput2.workdir) || asString(toolInput2.workingDirectory);
28064
28182
  if (!raw) return cwd;
28065
- return (0, import_path4.isAbsolute)(raw) || !cwd ? raw : (0, import_path4.join)(cwd, raw);
28183
+ return (0, import_path5.isAbsolute)(raw) || !cwd ? raw : (0, import_path5.join)(cwd, raw);
28066
28184
  }
28067
28185
  function jpegDimensions(buffer) {
28068
28186
  let offset = 2;
@@ -28092,14 +28210,14 @@ function readMediaFiles(query) {
28092
28210
  const files = [];
28093
28211
  for (const candidate of query.candidates) {
28094
28212
  const path4 = normalizePath(candidate, query.cwd);
28095
- if (!path4 || seen.has(path4) || !(0, import_fs5.existsSync)(path4)) continue;
28213
+ if (!path4 || seen.has(path4) || !(0, import_fs6.existsSync)(path4)) continue;
28096
28214
  seen.add(path4);
28097
- const mimeType = query.mimeByExt[(0, import_path4.extname)(path4).toLowerCase()];
28215
+ const mimeType = query.mimeByExt[(0, import_path5.extname)(path4).toLowerCase()];
28098
28216
  if (!mimeType) continue;
28099
- const stat23 = (0, import_fs5.statSync)(path4);
28100
- if (!stat23.isFile() || stat23.size <= 0 || stat23.size > query.maxBytes) continue;
28101
- if (stat23.mtimeMs < query.writtenSince && !query.named.has(path4)) continue;
28102
- files.push({ path: path4, mimeType, buffer: (0, import_fs5.readFileSync)(path4) });
28217
+ const stat24 = (0, import_fs6.statSync)(path4);
28218
+ if (!stat24.isFile() || stat24.size <= 0 || stat24.size > query.maxBytes) continue;
28219
+ if (stat24.mtimeMs < query.writtenSince && !query.named.has(path4)) continue;
28220
+ files.push({ path: path4, mimeType, buffer: (0, import_fs6.readFileSync)(path4) });
28103
28221
  }
28104
28222
  return files;
28105
28223
  }
@@ -28430,17 +28548,17 @@ function silentStartError(name, timeoutMs) {
28430
28548
  message: `${name} printed nothing for ${seconds}s after it started and was stopped. Send your message again.`
28431
28549
  };
28432
28550
  }
28433
- var import_crypto4, import_fs5, import_path4, PNG_SIGNATURE, IMAGE_MIME_BY_EXT, VIDEO_MIME_BY_EXT, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, MAX_IMAGE_BYTES, MAX_VIDEO_BYTES, MAX_TURN_MEDIA_DATA_CHARS, MTIME_SLACK_MS, AGENT_BROWSER_MENTION, AGENT_BROWSER_CAPTURE_COMMAND, LocalMediaReader, SessionOpenRefusal, JsonRpcError, ACP_PROTOCOL_VERSION, ACP_ERROR, STDERR_TAIL_LINES, RESULT_EXIT_GRACE_MS, PerTurnSession;
28434
- var init_chunk_U4RQE7JS = __esm({
28435
- "../agent-core/dist/chunk-U4RQE7JS.js"() {
28551
+ var import_crypto4, import_fs6, import_path5, PNG_SIGNATURE, IMAGE_MIME_BY_EXT, VIDEO_MIME_BY_EXT, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, MAX_IMAGE_BYTES, MAX_VIDEO_BYTES, MAX_TURN_MEDIA_DATA_CHARS, MTIME_SLACK_MS, AGENT_BROWSER_MENTION, AGENT_BROWSER_CAPTURE_COMMAND, LocalMediaReader, SessionOpenRefusal, JsonRpcError, ACP_PROTOCOL_VERSION, ACP_ERROR, STDERR_TAIL_LINES, RESULT_EXIT_GRACE_MS, PerTurnSession;
28552
+ var init_chunk_CGBCAZEN = __esm({
28553
+ "../agent-core/dist/chunk-CGBCAZEN.js"() {
28436
28554
  "use strict";
28437
28555
  init_chunk_AF3IPGDT();
28438
28556
  init_chunk_WYNUYKKN();
28439
- init_chunk_KVTSAS2T();
28557
+ init_chunk_A5UQ6YFO();
28440
28558
  init_chunk_YXWJW7I5();
28441
28559
  import_crypto4 = require("crypto");
28442
- import_fs5 = require("fs");
28443
- import_path4 = require("path");
28560
+ import_fs6 = require("fs");
28561
+ import_path5 = require("path");
28444
28562
  init_agent2();
28445
28563
  init_acp();
28446
28564
  PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
@@ -28553,7 +28671,7 @@ var init_chunk_U4RQE7JS = __esm({
28553
28671
  source,
28554
28672
  kind,
28555
28673
  mimeType: file2.mimeType,
28556
- filename: (0, import_path4.basename)(file2.path),
28674
+ filename: (0, import_path5.basename)(file2.path),
28557
28675
  data: file2.buffer,
28558
28676
  sha256: (0, import_crypto4.createHash)("sha256").update(file2.buffer).digest("hex"),
28559
28677
  ...kind === "image" ? imageDimensions(file2.buffer, file2.mimeType) : {},
@@ -28817,10 +28935,10 @@ var init_chunk_U4RQE7JS = __esm({
28817
28935
  var init_dist = __esm({
28818
28936
  "../agent-core/dist/index.js"() {
28819
28937
  "use strict";
28820
- init_chunk_U4RQE7JS();
28938
+ init_chunk_CGBCAZEN();
28821
28939
  init_chunk_AF3IPGDT();
28822
28940
  init_chunk_WYNUYKKN();
28823
- init_chunk_KVTSAS2T();
28941
+ init_chunk_A5UQ6YFO();
28824
28942
  init_chunk_YXWJW7I5();
28825
28943
  }
28826
28944
  });
@@ -29458,7 +29576,7 @@ function byListingPriority(left, right) {
29458
29576
  return platform3 !== 0 ? platform3 : left.name.localeCompare(right.name);
29459
29577
  }
29460
29578
  function overflowLine(omitted) {
29461
- const folders = [...new Set(omitted.map((skill) => (0, import_path5.dirname)(skill.packageDirectory)))].sort();
29579
+ const folders = [...new Set(omitted.map((skill) => (0, import_path6.dirname)(skill.packageDirectory)))].sort();
29462
29580
  return `${omitted.length} more installed skills are not listed. Each is a folder holding a SKILL.md under ${folders.map((folder) => JSON.stringify(folder)).join(" or ")}; look there before assuming a named skill is unavailable.`;
29463
29581
  }
29464
29582
  function installedSkillLines(skills) {
@@ -29554,13 +29672,13 @@ function buildTurnText(input2) {
29554
29672
  ${body}` : body;
29555
29673
  return spec.mode === "plan" ? planModePrefix(prefixed) : prefixed;
29556
29674
  }
29557
- var import_path5, startCommandStateSchema, repositorySnapshotSchema, environmentSnapshotSchema, agentContextSnapshotSchema, BRANCH_REASONS, SLACK_SURFACE_INSTRUCTIONS, PLAIN_SCALAR, COMMAND_PREVIEW_CHARS, MAX_PARSED_ATTACHMENTS, MAX_PARSED_ATTACHMENT_CHARS, MAX_METADATA_CHARS, UNAVAILABLE, READ_ONLY_MODES, AGENT_MODES, INSTALLED_SKILLS_MAX_CHARS, INSTALLED_SKILL_DESCRIPTION_MAX_CHARS;
29675
+ var import_path6, startCommandStateSchema, repositorySnapshotSchema, environmentSnapshotSchema, agentContextSnapshotSchema, BRANCH_REASONS, SLACK_SURFACE_INSTRUCTIONS, PLAIN_SCALAR, COMMAND_PREVIEW_CHARS, MAX_PARSED_ATTACHMENTS, MAX_PARSED_ATTACHMENT_CHARS, MAX_METADATA_CHARS, UNAVAILABLE, READ_ONLY_MODES, AGENT_MODES, INSTALLED_SKILLS_MAX_CHARS, INSTALLED_SKILL_DESCRIPTION_MAX_CHARS;
29558
29676
  var init_chunk_7FJ7QKFN = __esm({
29559
29677
  "../agent-core/dist/chunk-7FJ7QKFN.js"() {
29560
29678
  "use strict";
29561
29679
  init_runtime_v2();
29562
29680
  init_zod();
29563
- import_path5 = require("path");
29681
+ import_path6 = require("path");
29564
29682
  init_agent2();
29565
29683
  startCommandStateSchema = external_exports.discriminatedUnion("state", [
29566
29684
  external_exports.object({ state: external_exports.literal("not_configured") }),
@@ -29755,20 +29873,20 @@ function canonicalizeManagedMcpToolName(toolName2) {
29755
29873
  return flattened ? `mcp__${MANAGED_MCP_SERVER_NAME}__${flattened[1]}` : toolName2;
29756
29874
  }
29757
29875
  async function writeSecretFile(name, contents) {
29758
- const dir = await (0, import_promises21.mkdtemp)((0, import_path6.join)((0, import_os2.tmpdir)(), "alan-mcp-"));
29759
- const path4 = (0, import_path6.join)(dir, name);
29876
+ const dir = await (0, import_promises22.mkdtemp)((0, import_path7.join)((0, import_os2.tmpdir)(), "alan-mcp-"));
29877
+ const path4 = (0, import_path7.join)(dir, name);
29760
29878
  const remove = async () => {
29761
- await (0, import_promises21.rm)(dir, { recursive: true, force: true });
29879
+ await (0, import_promises22.rm)(dir, { recursive: true, force: true });
29762
29880
  };
29763
29881
  try {
29764
- await (0, import_promises21.writeFile)(path4, contents, { mode: 384, flag: "wx" });
29882
+ await (0, import_promises22.writeFile)(path4, contents, { mode: 384, flag: "wx" });
29765
29883
  } catch (error62) {
29766
29884
  await remove();
29767
29885
  throw error62;
29768
29886
  }
29769
29887
  return { path: path4, remove, [Symbol.asyncDispose]: remove };
29770
29888
  }
29771
- var import_crypto5, import_crypto6, import_promises21, import_os2, import_path6, OPENCODE_CODE_MODE_ENV, OPENCODE_CODE_MODE_TOOL, CODE_MODE_CALLS_META, MANAGED_MCP_SERVER_NAME, RUN_SCOPED_SERVER, NAMESPACED_RUN_TOOL, FLATTENED_RUN_TOOL;
29889
+ var import_crypto5, import_crypto6, import_promises22, import_os2, import_path7, OPENCODE_CODE_MODE_ENV, OPENCODE_CODE_MODE_TOOL, CODE_MODE_CALLS_META, MANAGED_MCP_SERVER_NAME, RUN_SCOPED_SERVER, NAMESPACED_RUN_TOOL, FLATTENED_RUN_TOOL;
29772
29890
  var init_chunk_OSECDZA5 = __esm({
29773
29891
  "../agent-core/dist/chunk-OSECDZA5.js"() {
29774
29892
  "use strict";
@@ -29777,9 +29895,9 @@ var init_chunk_OSECDZA5 = __esm({
29777
29895
  import_crypto6 = require("crypto");
29778
29896
  init_agent2();
29779
29897
  init_runtime_v2();
29780
- import_promises21 = require("fs/promises");
29898
+ import_promises22 = require("fs/promises");
29781
29899
  import_os2 = require("os");
29782
- import_path6 = require("path");
29900
+ import_path7 = require("path");
29783
29901
  OPENCODE_CODE_MODE_ENV = "OPENCODE_EXPERIMENTAL_CODE_MODE";
29784
29902
  OPENCODE_CODE_MODE_TOOL = "execute";
29785
29903
  CODE_MODE_CALLS_META = "alanToolCalls";
@@ -30025,16 +30143,16 @@ function classifyAcpError(error62) {
30025
30143
  return classifyAcpText(acpErrorText(error62));
30026
30144
  }
30027
30145
  function within(root, path4) {
30028
- const rel = (0, import_path7.relative)(root, path4);
30029
- return rel === "" || !rel.startsWith(`..${import_path7.sep}`) && rel !== ".." && !(0, import_path7.isAbsolute)(rel);
30146
+ const rel = (0, import_path8.relative)(root, path4);
30147
+ return rel === "" || !rel.startsWith(`..${import_path8.sep}`) && rel !== ".." && !(0, import_path8.isAbsolute)(rel);
30030
30148
  }
30031
30149
  async function resolveReal(path4) {
30032
30150
  try {
30033
- return await (0, import_promises22.realpath)(path4);
30151
+ return await (0, import_promises23.realpath)(path4);
30034
30152
  } catch {
30035
- const parent = (0, import_path7.dirname)(path4);
30153
+ const parent = (0, import_path8.dirname)(path4);
30036
30154
  if (parent === path4) return path4;
30037
- return (0, import_path7.join)(await resolveReal(parent), (0, import_path7.basename)(path4));
30155
+ return (0, import_path8.join)(await resolveReal(parent), (0, import_path8.basename)(path4));
30038
30156
  }
30039
30157
  }
30040
30158
  function sliceLines(text3, params) {
@@ -30049,7 +30167,7 @@ function createWorkspaceFs(roots, writable) {
30049
30167
  const realRoots = Promise.all(roots.map((root) => resolveReal(root)));
30050
30168
  const confined = async (params) => {
30051
30169
  const path4 = asString(params.path);
30052
- if (!(0, import_path7.isAbsolute)(path4)) throw new FsDenied(`fs path must be absolute: ${path4 || "(empty)"}`);
30170
+ if (!(0, import_path8.isAbsolute)(path4)) throw new FsDenied(`fs path must be absolute: ${path4 || "(empty)"}`);
30053
30171
  const real = await resolveReal(path4);
30054
30172
  if (!(await realRoots).some((root) => within(root, real))) {
30055
30173
  throw new FsDenied(`${path4} is outside the session's workspace`);
@@ -30059,14 +30177,14 @@ function createWorkspaceFs(roots, writable) {
30059
30177
  return {
30060
30178
  read: async (params) => {
30061
30179
  const path4 = await confined(params);
30062
- const bytes = await (0, import_promises22.readFile)(path4);
30180
+ const bytes = await (0, import_promises23.readFile)(path4);
30063
30181
  if (bytes.byteLength > MAX_READ_BYTES) throw new FsDenied(`${path4} is too large to read`);
30064
30182
  return { content: sliceLines(bytes.toString("utf8"), params) };
30065
30183
  },
30066
30184
  write: async (params) => {
30067
30185
  if (!writable) throw new FsDenied("This session is read-only");
30068
30186
  const path4 = await confined(params);
30069
- await (0, import_promises22.writeFile)(path4, asString(params.content));
30187
+ await (0, import_promises23.writeFile)(path4, asString(params.content));
30070
30188
  return {};
30071
30189
  }
30072
30190
  };
@@ -30669,7 +30787,7 @@ async function acpTurnInput(run2, context) {
30669
30787
  const encoded = await Promise.all(
30670
30788
  images.map(async (image) => ({
30671
30789
  mimeType: image.mimeType,
30672
- data: (await (0, import_promises23.readFile)(image.path)).toString("base64")
30790
+ data: (await (0, import_promises24.readFile)(image.path)).toString("base64")
30673
30791
  }))
30674
30792
  );
30675
30793
  return {
@@ -30678,23 +30796,23 @@ async function acpTurnInput(run2, context) {
30678
30796
  ...encoded.length ? { images: encoded, imagePaths: images.map((image) => image.path) } : {}
30679
30797
  };
30680
30798
  }
30681
- var import_promises22, import_path7, import_crypto7, import_promises23, CURSOR_ASK_QUESTION, copilotAcpProfile, cursorAcpProfile, MODEL_REJECTED, MAX_READ_BYTES, FsDenied, ENV_REFERENCE, AcpBackgroundTasks, CURSOR_CREATE_PLAN, STATUSES2, READ_KINDS, ALLOW_KINDS, REJECT_KINDS, CANCELLED_PERMISSION, STOP_REASONS, CHUNKS, ECHOES, AcpTurn, STDERR_TAIL_LINES2, MAX_BETWEEN_UPDATES, AcpSession, DEFAULTS, CLIENT_INFO, TASK_BACKGROUNDED, TASK_COMPLETED, SESSION_NOTIFICATION, KILLED_STATUSES, SUCCESS_STATUSES, SUBAGENT_ID, grokTaskDialect, grokAcpProfile, kimiAcpProfile, ACP_PROFILES, ACP_MODES;
30799
+ var import_promises23, import_path8, import_crypto7, import_promises24, CURSOR_ASK_QUESTION, copilotAcpProfile, cursorAcpProfile, MODEL_REJECTED, MAX_READ_BYTES, FsDenied, ENV_REFERENCE, AcpBackgroundTasks, CURSOR_CREATE_PLAN, STATUSES2, READ_KINDS, ALLOW_KINDS, REJECT_KINDS, CANCELLED_PERMISSION, STOP_REASONS, CHUNKS, ECHOES, AcpTurn, STDERR_TAIL_LINES2, MAX_BETWEEN_UPDATES, AcpSession, DEFAULTS, CLIENT_INFO, TASK_BACKGROUNDED, TASK_COMPLETED, SESSION_NOTIFICATION, KILLED_STATUSES, SUCCESS_STATUSES, SUBAGENT_ID, grokTaskDialect, grokAcpProfile, kimiAcpProfile, ACP_PROFILES, ACP_MODES;
30682
30800
  var init_acp2 = __esm({
30683
30801
  "../agent-core/dist/providers/acp.js"() {
30684
30802
  "use strict";
30685
- init_chunk_U4RQE7JS();
30803
+ init_chunk_CGBCAZEN();
30686
30804
  init_chunk_AF3IPGDT();
30687
30805
  init_chunk_WYNUYKKN();
30688
- init_chunk_KVTSAS2T();
30806
+ init_chunk_A5UQ6YFO();
30689
30807
  init_chunk_7FJ7QKFN();
30690
30808
  init_chunk_OSECDZA5();
30691
30809
  init_chunk_YXWJW7I5();
30692
- import_promises22 = require("fs/promises");
30693
- import_path7 = require("path");
30810
+ import_promises23 = require("fs/promises");
30811
+ import_path8 = require("path");
30694
30812
  init_effort();
30695
30813
  init_acp();
30696
30814
  import_crypto7 = require("crypto");
30697
- import_promises23 = require("fs/promises");
30815
+ import_promises24 = require("fs/promises");
30698
30816
  init_agent2();
30699
30817
  CURSOR_ASK_QUESTION = "cursor/ask_question";
30700
30818
  copilotAcpProfile = {
@@ -32255,14 +32373,14 @@ function getJson(url3, headers, timeout, signal) {
32255
32373
  outgoing.end();
32256
32374
  });
32257
32375
  }
32258
- async function fetchAlanCodeModels(access7, options = {}) {
32376
+ async function fetchAlanCodeModels(access8, options = {}) {
32259
32377
  const clock = options.clock ?? systemClock2;
32260
32378
  const deadline = clock.monotonic() + ACTIVATION_WAIT_MS;
32261
- const url3 = new URL(ALAN_CODE_CATALOG_PATH, access7.apiOrigin);
32379
+ const url3 = new URL(ALAN_CODE_CATALOG_PATH, access8.apiOrigin);
32262
32380
  const headers = {
32263
32381
  Accept: "application/json",
32264
- Authorization: access7.authorization,
32265
- [MANAGED_MCP_CONVERSATION_HEADER]: access7.conversationId
32382
+ Authorization: access8.authorization,
32383
+ [MANAGED_MCP_CONVERSATION_HEADER]: access8.conversationId
32266
32384
  };
32267
32385
  for (; ; ) {
32268
32386
  options.signal?.throwIfAborted();
@@ -32286,13 +32404,13 @@ function alanCodeEngineBinary(platform3) {
32286
32404
  return platform3 === "win32" ? "opencode.exe" : "opencode";
32287
32405
  }
32288
32406
  function packagedAlanCodeEnginePath(bundle, platform3) {
32289
- return (0, import_path8.join)((0, import_path8.dirname)(bundle), "..", "engine", alanCodeEngineBinary(platform3));
32407
+ return (0, import_path9.join)((0, import_path9.dirname)(bundle), "..", "engine", alanCodeEngineBinary(platform3));
32290
32408
  }
32291
32409
  function isRunnableFile(path4, platform3) {
32292
32410
  try {
32293
- if (!(0, import_fs6.statSync)(path4).isFile()) return false;
32411
+ if (!(0, import_fs7.statSync)(path4).isFile()) return false;
32294
32412
  if (platform3 === "win32") return WINDOWS_RUNNABLE_EXTENSION.test(path4);
32295
- (0, import_fs6.accessSync)(path4, import_fs6.constants.X_OK);
32413
+ (0, import_fs7.accessSync)(path4, import_fs7.constants.X_OK);
32296
32414
  return true;
32297
32415
  } catch {
32298
32416
  return false;
@@ -32488,13 +32606,13 @@ export const AlanEnginePlugin = async () => ({
32488
32606
  `;
32489
32607
  }
32490
32608
  function alanCodeEngineRoot(home) {
32491
- return (0, import_path9.join)(home, ".alan", "alan-code", "engine");
32609
+ return (0, import_path10.join)(home, ".alan", "alan-code", "engine");
32492
32610
  }
32493
32611
  function alanCodeEngineDirectories(root) {
32494
32612
  return {
32495
- XDG_DATA_HOME: (0, import_path9.join)(root, "share"),
32496
- XDG_STATE_HOME: (0, import_path9.join)(root, "state"),
32497
- XDG_CACHE_HOME: (0, import_path9.join)(root, "cache")
32613
+ XDG_DATA_HOME: (0, import_path10.join)(root, "share"),
32614
+ XDG_STATE_HOME: (0, import_path10.join)(root, "state"),
32615
+ XDG_CACHE_HOME: (0, import_path10.join)(root, "cache")
32498
32616
  };
32499
32617
  }
32500
32618
  function bearerToken(authorization) {
@@ -32510,8 +32628,8 @@ function alanCodeEngineEnv(input2) {
32510
32628
  };
32511
32629
  }
32512
32630
  function openCodeGlobalConfigDirectory(env, home) {
32513
- const configHome = env.XDG_CONFIG_HOME?.trim() || (0, import_path9.join)(home, ".config");
32514
- return (0, import_path9.join)(configHome, "opencode");
32631
+ const configHome = env.XDG_CONFIG_HOME?.trim() || (0, import_path10.join)(home, ".config");
32632
+ return (0, import_path10.join)(configHome, "opencode");
32515
32633
  }
32516
32634
  function stripJsonc(text3) {
32517
32635
  let out = "";
@@ -32570,7 +32688,7 @@ function parseJsonc(text3) {
32570
32688
  async function inheritedMcpServerNames(configDirectory) {
32571
32689
  const names = /* @__PURE__ */ new Set();
32572
32690
  for (const file2 of ["config.json", "opencode.json", "opencode.jsonc"]) {
32573
- const text3 = await (0, import_promises24.readFile)((0, import_path9.join)(configDirectory, file2), "utf8").catch(() => null);
32691
+ const text3 = await (0, import_promises25.readFile)((0, import_path10.join)(configDirectory, file2), "utf8").catch(() => null);
32574
32692
  if (text3 === null) continue;
32575
32693
  const parsed = parseJsonc(text3);
32576
32694
  const mcp = parsed !== null && typeof parsed === "object" ? parsed.mcp : void 0;
@@ -32582,20 +32700,20 @@ async function inheritedMcpServerNames(configDirectory) {
32582
32700
  }
32583
32701
  async function writePlugin(directory, apiOrigin) {
32584
32702
  const origin = (0, import_crypto8.createHash)("sha256").update(apiOrigin).digest("hex").slice(0, 12);
32585
- const target = (0, import_path9.join)(directory, `engine-plugin-v${ALAN_CODE_ENGINE_PLUGIN_VERSION}-${origin}.mjs`);
32703
+ const target = (0, import_path10.join)(directory, `engine-plugin-v${ALAN_CODE_ENGINE_PLUGIN_VERSION}-${origin}.mjs`);
32586
32704
  const temporary = `${target}.${(0, import_crypto8.randomUUID)()}.tmp`;
32587
- await (0, import_promises24.mkdir)(directory, { recursive: true, mode: 448 });
32588
- await (0, import_promises24.writeFile)(temporary, alanCodeEnginePluginSource(apiOrigin), { mode: 384 });
32589
- await (0, import_promises24.rename)(temporary, target);
32705
+ await (0, import_promises25.mkdir)(directory, { recursive: true, mode: 448 });
32706
+ await (0, import_promises25.writeFile)(temporary, alanCodeEnginePluginSource(apiOrigin), { mode: 384 });
32707
+ await (0, import_promises25.rename)(temporary, target);
32590
32708
  return (0, import_url.pathToFileURL)(target).href;
32591
32709
  }
32592
32710
  async function prepareAlanCodeProfile(input2) {
32593
32711
  const directories = Object.values(alanCodeEngineDirectories(input2.engineRoot));
32594
32712
  await Promise.all(
32595
- directories.map((directory) => (0, import_promises24.mkdir)(directory, { recursive: true, mode: 448 }))
32713
+ directories.map((directory) => (0, import_promises25.mkdir)(directory, { recursive: true, mode: 448 }))
32596
32714
  );
32597
32715
  const [pluginUrl, models, inheritedMcpServers] = await Promise.all([
32598
- writePlugin((0, import_path9.join)(input2.engineRoot, "plugin"), input2.access.apiOrigin),
32716
+ writePlugin((0, import_path10.join)(input2.engineRoot, "plugin"), input2.access.apiOrigin),
32599
32717
  (input2.loadModels ?? fetchAlanCodeModels)(input2.access),
32600
32718
  input2.globalConfigDirectory === void 0 ? Promise.resolve([]) : inheritedMcpServerNames(input2.globalConfigDirectory)
32601
32719
  ]);
@@ -32617,7 +32735,7 @@ function alanCodeSystemPrompt(alanSystemPrompt) {
32617
32735
 
32618
32736
  ${instructions}` : ALAN_CODE_TOOL_NAMING_PROMPT;
32619
32737
  }
32620
- var import_http9, import_https, import_fs6, import_path8, import_crypto8, import_promises24, import_path9, import_url, ALAN_CODE_BASELINE_PROMPT, ALAN_CODE_ENGINE_PROVIDER_ID, DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT_TOKENS, ALAN_CODE_API_KEY_ENV, ALAN_CODE_CONVERSATION_ID_ENV, ALAN_CODE_PROXY_PATH, ALAN_CODE_WEBSEARCH_PATH, ALAN_CODE_CATALOG_PATH, ALAN_CODE_CHUNK_TIMEOUT_MS, CATALOG_TIMEOUT_MS, MAX_CATALOG_BYTES, ACTIVATION_WAIT_MS, ACTIVATION_POLL_MS, CatalogResponseError, ALAN_CODE_ENGINE_PATH_ENV, ALAN_CODE_ENGINE_COMMAND, ALAN_CODE_ENGINE_NAME, WINDOWS_RUNNABLE_EXTENSION, ALAN_CODE_ENGINE_PLUGIN_VERSION, ALAN_CODE_TOOL_NAMING_PROMPT;
32738
+ var import_http9, import_https, import_fs7, import_path9, import_crypto8, import_promises25, import_path10, import_url, ALAN_CODE_BASELINE_PROMPT, ALAN_CODE_ENGINE_PROVIDER_ID, DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT_TOKENS, ALAN_CODE_API_KEY_ENV, ALAN_CODE_CONVERSATION_ID_ENV, ALAN_CODE_PROXY_PATH, ALAN_CODE_WEBSEARCH_PATH, ALAN_CODE_CATALOG_PATH, ALAN_CODE_CHUNK_TIMEOUT_MS, CATALOG_TIMEOUT_MS, MAX_CATALOG_BYTES, ACTIVATION_WAIT_MS, ACTIVATION_POLL_MS, CatalogResponseError, ALAN_CODE_ENGINE_PATH_ENV, ALAN_CODE_ENGINE_COMMAND, ALAN_CODE_ENGINE_NAME, WINDOWS_RUNNABLE_EXTENSION, ALAN_CODE_ENGINE_PLUGIN_VERSION, ALAN_CODE_TOOL_NAMING_PROMPT;
32621
32739
  var init_alan_code = __esm({
32622
32740
  "../agent-core/dist/providers/alan-code.js"() {
32623
32741
  "use strict";
@@ -32628,12 +32746,12 @@ var init_alan_code = __esm({
32628
32746
  init_runtime_v2();
32629
32747
  init_runtime_v2();
32630
32748
  init_models();
32631
- import_fs6 = require("fs");
32632
- import_path8 = require("path");
32749
+ import_fs7 = require("fs");
32750
+ import_path9 = require("path");
32633
32751
  init_runtime_v2();
32634
32752
  import_crypto8 = require("crypto");
32635
- import_promises24 = require("fs/promises");
32636
- import_path9 = require("path");
32753
+ import_promises25 = require("fs/promises");
32754
+ import_path10 = require("path");
32637
32755
  import_url = require("url");
32638
32756
  ALAN_CODE_BASELINE_PROMPT = "You are alan-code, an interactive CLI coding agent that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\nDo not invent URLs. Use verified URLs or ones supplied by the user or project.\n\nIf the user asks for help or wants to give feedback, inform them of the following:\n- `--harness-help` / harness help: learn how to run alan-code\n- For product feedback or bugs, report through the Alan / Supatest issue channels used by this repository\n\nWhen the user directly asks about alan-code capabilities (for example \"can alan-code\u2026\", \"does the harness have\u2026\") or asks in second person about your abilities, answer from the tools and instructions available in this session. If a docs/fetch tool is available and project docs URLs are known, use them; otherwise inspect local README / AGENTS.md rather than inventing product claims.\n\n# Personality\n\nYour default personality and tone is concise, direct, and friendly. You communicate efficiently, always keeping the user clearly informed about ongoing actions without unnecessary detail. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.\n\n# Tone and style\n\nYou should be concise, direct, and to the point. When you run a non-trivial bash command, you should explain what the command does and why you are running it, so the user understands what you are doing (especially important for commands that change their system).\nRemember that your output will be displayed on a command line interface. Your responses can use GitHub-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.\nOutput text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.\nIf you cannot or will not help the user with something, do not lecture about why. Offer helpful alternatives if possible; otherwise keep the response to 1-2 sentences.\nOnly use emojis if the user explicitly requests it. Avoid emojis in all communication unless asked.\nIMPORTANT: Minimize output tokens while staying helpful, correct, and accurate. Only address the specific query or task. Avoid tangential information unless it is critical to completing the request. If you can answer in 1-3 sentences or a short paragraph, do that.\nAnswer the user's question directly. One-word answers are best when they suffice. Avoid text before/after your response such as \"The answer is <answer>.\", \"Here is the content of the file\u2026\", \"Based on the information provided\u2026\", or \"Here is what I will do next\u2026\". Examples of appropriate verbosity:\n<example>\nuser: what is 2+2?\nassistant: 4\n</example>\n\n<example>\nuser: is 11 a prime number?\nassistant: Yes\n</example>\n\n<example>\nuser: what command should I run to list files in the current directory?\nassistant: ls\n</example>\n\n<example>\nuser: what command should I run to watch files in the current directory?\nassistant: [use tools to inspect the project, then answer]\nnpm run dev\n</example>\n\n<example>\nuser: what files are in the directory src/?\nassistant: [lists files and sees foo.c, bar.c, baz.c]\nuser: which file contains the implementation of foo?\nassistant: src/foo.c\n</example>\n\n<example>\nuser: write tests for new feature\nassistant: [searches for similar tests, reads relevant files concurrently, edits/writes tests]\n</example>\n\n# Responsiveness\n\n## Preamble messages\n\nBefore making tool calls, send a brief preamble to the user explaining what you're about to do. When sending preamble messages, follow these principles and examples:\n\n- **Logically group related actions**: if you're about to run several related commands, describe them together in one preamble rather than sending a separate note for each.\n- **Keep it concise**: be no more than 1-2 sentences, focused on immediate, tangible next steps. (8\u201312 words for quick updates).\n- **Build on prior context**: if this is not your first tool call, use the preamble message to connect the dots with what's been done so far and create a sense of momentum and clarity for the user to understand your next actions.\n- **Keep your tone light, friendly and curious**: add small touches of personality in preambles feel collaborative and engaging.\n- **Exception**: Avoid adding a preamble for every trivial read (e.g., `cat` a single file) unless it's part of a larger grouped action.\n\nExamples:\n\n- \"I've explored the repo; now checking the API route definitions.\"\n- \"Next, I'll patch the config and update the related tests.\"\n- \"I'm about to scaffold the CLI commands and helper functions.\"\n- \"Ok cool, so I've wrapped my head around the repo. Now digging into the API routes.\"\n- \"Config's looking tidy. Next up is patching helpers to keep things in sync.\"\n- \"Finished poking at the DB gateway. I will now chase down error handling.\"\n- \"Alright, build pipeline order is interesting. Checking how it reports failures.\"\n- \"Spotted a clever caching util; now hunting where it gets used.\"\n\n# Planning\n\nIf a planning tool is available, use it when it helps track complex work. Keep the plan brief and update it as work progresses.\n\nNote that plans are not for padding out simple work with filler steps or stating the obvious. The content of your plan should not involve doing anything that you aren't capable of doing (i.e. don't try to test things that you can't test). Do not use plans for simple or single-step queries that you can just do or answer immediately.\n\nWhen a planning tool displays the plan, summarize only what changed or what comes next.\n\nKeep any active plan aligned with the work completed and remaining.\n\nUse a plan when:\n\n- The task is non-trivial and will require multiple actions over a long time horizon.\n- There are logical phases or dependencies where sequencing matters.\n- The work has ambiguity that benefits from outlining high-level goals.\n- You want intermediate checkpoints for feedback and validation.\n- When the user asked you to do more than one thing in a single prompt\n- The user has asked you to use the plan tool (aka \"TODOs\")\n- You generate additional steps while working, and plan to do them before yielding to the user\n\n## Examples\n\n**High-quality plans**\n\nExample 1:\n\n1. Add CLI entry with file args\n2. Parse Markdown via CommonMark library\n3. Apply semantic HTML template\n4. Handle code blocks, images, links\n5. Add error handling for invalid files\n\nExample 2:\n\n1. Define CSS variables for colors\n2. Add toggle with localStorage state\n3. Refactor components to use variables\n4. Verify all views for readability\n5. Add smooth theme-change transition\n\nExample 3:\n\n1. Set up Node.js + WebSocket server\n2. Add join/leave broadcast events\n3. Implement messaging with timestamps\n4. Add usernames + mention highlighting\n5. Persist messages in lightweight DB\n6. Add typing indicators + unread count\n\n**Low-quality plans**\n\nExample 1:\n\n1. Create CLI tool\n2. Add Markdown parser\n3. Convert to HTML\n\nExample 2:\n\n1. Add dark mode toggle\n2. Save preference\n3. Make styles look good\n\nExample 3:\n\n1. Create single-file HTML game\n2. Run quick sanity check\n3. Summarize usage instructions\n\nIf you need to write a plan, only write high quality plans, not low quality ones.\n\n## Plan mode and clarification (harness specifics)\n\n- When the session is in plan mode, inspect without making changes and produce a concrete plan. Outside plan mode, proceed with authorized work and ask for approval only when the action requires it.\n- Prefer the durable plan file path over relying on chat memory after compaction.\n- When requirements are ambiguous, ask a targeted question using an available user-input tool instead of guessing.\n- An execution checklist is not a substitute for a durable plan when the task requires one.\n\n# Task execution\n\nYou are a coding agent. Please keep going until the query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. Autonomously resolve the query to the best of your ability, using the tools available to you, before coming back to the user. Do NOT guess or make up an answer.\n\nYou MUST adhere to the following criteria when solving queries:\n\n- Working on the repo(s) in the current environment is allowed, even if they are proprietary.\n- Analyzing code for vulnerabilities is allowed.\n- Showing user code and tool call details is allowed.\n- Use the editing tools available in the current host to modify files. Do not assume a particular tool name.\n\nIf completing the user's task requires writing or modifying files, your code and final answer should follow these coding guidelines, though user instructions (i.e. AGENTS.md) may override these guidelines:\n\n- Fix the problem at the root cause rather than applying surface-level patches, when possible.\n- Avoid unneeded complexity in your solution.\n- Do not attempt to fix unrelated bugs or broken tests. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)\n- Update documentation as necessary.\n- Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.\n- Use `git log` and `git blame` to search the history of the codebase if additional context is required.\n- NEVER add copyright or license headers unless specifically requested.\n- Do not waste tokens by re-reading files after editing them. The tool call will fail if it didn't work. The same goes for making folders, deleting folders, etc.\n- Do not `git commit` your changes or create new git branches unless explicitly requested.\n- Add comments when they explain a non-obvious invariant or reason for a decision.\n- Do not use one-letter variable names unless explicitly requested.\n- NEVER output inline citations like \"\u3010F:README.md\u2020L5-L14\u3011\" in your outputs. The CLI is not able to render these so they will just be broken in the UI. Instead, if you output valid filepaths, users will be able to click on them to open the files in their editor.\n\n# Validating your work\n\nIf the codebase has tests or the ability to build or run, consider using them to verify that your work is complete.\n\nWhen testing, your philosophy should be to start as specific as possible to the code you changed so that you can catch issues efficiently, then make your way to broader tests as you build confidence. If there's no test for the code you changed, and if the adjacent patterns in the codebases show that there's a logical place for you to add a test, you may do so. However, do not add tests to codebases with no tests.\n\nSimilarly, once you're confident in correctness, you can suggest or use formatting commands to ensure that your code is well formatted. If there are issues you can iterate up to 3 times to get formatting right, but if you still can't manage it's better to save the user time and present them a correct solution where you call out the formatting in your final message. If the codebase does not have a formatter configured, do not add one.\n\nFor all of testing, running, building, and formatting, do not attempt to fix unrelated bugs. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)\n\nBe mindful of whether to run validation commands proactively. In the absence of behavioral guidance:\n\n- When running in a non-interactive mode where edits are auto-approved (print/headless, or the `allow edits` permission mode), proactively run tests, lint and do whatever you need to ensure you've completed the task.\n- In plan mode, stay read-only. Otherwise, run focused checks after changes when the host permits them.\n- When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of permission mode. Use your judgement to decide whether this is a test-related task.\n\n# Ambition vs. precision\n\nFor tasks that have no prior context (i.e. the user is starting something brand new), you should feel free to be ambitious and demonstrate creativity with your implementation.\n\nIf you're operating in an existing codebase, you should make sure you do exactly what the user asks with surgical precision. Treat the surrounding codebase with respect, and don't overstep (i.e. changing filenames or variables unnecessarily). You should balance being sufficiently ambitious and proactive when completing tasks of this nature.\n\nYou should use judicious initiative to decide on the right level of detail and complexity to deliver based on the user's needs. This means showing good judgment that you're capable of doing the right extras without gold-plating. This might be demonstrated by high-value, creative touches when scope of the task is vague; while being surgical and targeted when scope is tightly specified.\n\n# Sharing progress updates\n\nFor especially longer tasks that you work on (i.e. requiring many tool calls, or a plan with multiple steps), you should provide progress updates back to the user at reasonable intervals. These updates should be structured as a concise sentence or two (no more than 8-10 words long) recapping progress so far in plain language: this update demonstrates your understanding of what needs to be done, progress so far (i.e. files explores, subtasks complete), and where you're going next.\n\nBefore doing large chunks of work that may incur latency as experienced by the user (i.e. writing a new file), you should send a concise message to the user with an update indicating what you're about to do to ensure they know what you're spending time on. Don't start editing or writing large files before informing the user what you are doing and why.\n\nThe messages you send before tool calls should describe what is immediately about to be done next in very concise language. If there was previous work done, this preamble message should also include a note about the work done so far to bring the user along.\n\n# Presenting your work and final message\n\nYour final message should read naturally, like an update from a concise teammate. For casual conversation, brainstorming tasks, or quick questions from the user, respond in a friendly, conversational tone. You should ask questions, suggest ideas, and adapt to the user's style. If you've finished a large amount of work, when describing what you've done to the user, you should follow the final answer formatting guidelines to communicate substantive changes. You don't need to add structured formatting for one-word answers, greetings, or purely conversational exchanges.\n\nYou can skip heavy formatting for single, simple actions or confirmations. In these cases, respond in plain sentences with any relevant next step or quick option. Reserve multi-section structured responses for results that need grouping or explanation.\n\nThe user is working on the same computer as you, and has access to your work. As such there's no need to show the full contents of large files you have already written unless the user explicitly asks for them. Similarly, if you've created or modified files, there's no need to tell users to \"save the file\" or \"copy the code into a file\"\u2014just reference the file path.\n\nComplete authorized next steps, including relevant tests. Ask before a consequential action that needs approval, and briefly report anything you could not verify.\n\nBrevity is very important as a default. You should be very concise (i.e. no more than 10 lines), but can relax this requirement for tasks where additional detail and comprehensiveness is important for the user's understanding.\n\n## Final answer structure and style guidelines\n\nYou are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.\n\n**Section Headers**\n\n- Use only when they improve clarity \u2014 they are not mandatory for every answer.\n- Choose descriptive names that fit the content\n- Keep headers short (1\u20133 words) and in `**Title Case**`. Always start headers with `**` and end with `**`\n- Use the blank lines required by the renderer for headings and lists.\n- Section headers should only be used where they genuinely improve scanability; avoid fragmenting the answer.\n\n**Bullets**\n\n- Use `-` followed by a space for every bullet.\n- Merge related points when possible; avoid a bullet for every trivial detail.\n- Keep bullets to one line unless breaking for clarity is unavoidable.\n- Group into short lists (4\u20136 bullets) ordered by importance.\n- Use consistent keyword phrasing and formatting across sections.\n\n**Monospace**\n\n- Wrap all commands, file paths, env vars, and code identifiers in backticks (`` `...` ``).\n- Apply to inline examples and to bullet keywords if the keyword itself is a literal file/command.\n- Never mix monospace and bold markers; choose one based on whether it's a keyword (`**`) or inline code/path (`` ` ``).\n\n**File References**\n\nWhen referencing files in your response, make sure to include the relevant start line and always follow the below rules:\n\n- Use inline code to make file paths clickable.\n- Each reference should have a stand alone path. Even if it's the same file.\n- Accepted: absolute, workspace\u2011relative, a/ or b/ diff prefixes, or bare filename/suffix.\n- Line/column (1\u2011based, optional): :line[:column] or #Lline[Ccolumn] (column defaults to 1).\n- Do not use URIs like file://, vscode://, or https://.\n- Do not provide range of lines\n- Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5\n\n**Structure**\n\n- Place related bullets together; don't mix unrelated concepts in the same section.\n- Order sections from general \u2192 specific \u2192 supporting info.\n- For subsections (e.g., \"Binaries\" under \"Rust Workspace\"), introduce with a bolded keyword bullet, then list items under it.\n- Match structure to complexity:\n - Multi-part or detailed results \u2192 use clear headers and grouped bullets.\n - Simple results \u2192 minimal headers, possibly just a short list or paragraph.\n\n**Tone**\n\n- Keep the voice collaborative and natural, like a coding partner handing off work.\n- Be concise and factual \u2014 no filler or conversational commentary and avoid unnecessary repetition\n- Use present tense and active voice (e.g., \"Runs tests\" not \"This will run tests\").\n- Keep descriptions self-contained; don't refer to \"above\" or \"below\".\n- Use parallel structure in lists for consistency.\n\n**Don't**\n\n- Don't use literal words \"bold\" or \"monospace\" in the content.\n- Don't nest bullets or create deep hierarchies.\n- Don't output ANSI escape codes directly \u2014 the CLI renderer applies them.\n- Don't cram unrelated keywords into a single bullet; split for clarity.\n- Don't let keyword lists run long \u2014 wrap or reformat for scanability.\n\nGenerally, ensure your final answers adapt their shape and depth to the request. For example, answers to code explanations should have a precise, structured explanation with code references that answer the question directly. For tasks with a simple implementation, lead with the outcome and supplement only with what's needed for clarity. Larger changes can be presented as a logical walkthrough of your approach, grouping related steps, explaining rationale where it adds value, and highlighting next actions to accelerate the user. Your answers should provide the right level of detail while being easily scannable.\n\nFor casual greetings, acknowledgements, or other one-off conversational messages that are not delivering substantive information or structured results, respond naturally without section headers or bullet formatting.\n\n# Professional objectivity\n\nPrioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving. Be direct and objective without unnecessary praise or emotional validation. Disagree when needed. When uncertain, investigate before confirming the user's assumptions.\n\n# Proactiveness\n\nProactively complete work that follows from the user's request. Avoid unrelated actions that would surprise the user. Strike a balance between:\n\n1. Doing the right thing when asked, including follow-up actions\n2. Not surprising the user with unrequested actions\n For example, if the user asks how to approach something, answer first; do not immediately jump into edits.\n\n# Following conventions\n\nWhen changing files, first understand the file's conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.\n\n- NEVER assume a library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses it (neighboring files, package.json, cargo.toml, go.mod, etc.).\n- When creating a new component, first look at existing components for framework choice, naming, typing, and other conventions.\n- When editing code, first look at surrounding context (especially imports) to understand chosen frameworks/libraries, then make the change idiomatically.\n- Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.\n\n# Doing tasks\n\nThe user will primarily request software engineering tasks: bugs, features, refactors, explanations, and more. Recommended steps:\n\n- Use available search/read tools extensively to understand the codebase and the query (in parallel when independent).\n- Implement the solution with the tools available to you.\n- Prefer editing existing files. Create documentation when the task or project instructions require it.\n- Verify when possible with tests. NEVER assume a specific test framework or script \u2014 check README / AGENTS.md or search the repo.\n- Run lint and typecheck commands (for example npm run lint, npm run typecheck, ruff, pnpm lint) if they were provided to you \u2014 see Validating your work for when to run them proactively vs. when to hold off. If you cannot find the correct command, ask the user, and if they supply it, proactively suggest writing it to AGENTS.md so you know next time.\n\n- Tool results and user messages may include <system-reminder> tags. Those tags contain useful reminders. They are NOT part of the user's provided input or the tool result.\n\n# Tool usage policy\n\n- Prefer specialized file tools over shell for reading, editing, writing, listing, and searching when those tools are available. Use the `grep`, `glob`, and `list` tools instead of bash for search and listing \u2014 they are ripgrep-backed and return structured, length-capped results. Use shell for real system commands (git, package managers, builds, tests, process control).\n- When doing broad codebase exploration, use the available search tools and delegate only when the task benefits from independent work.\n- You can call multiple tools in one response. When multiple independent pieces of information are needed, batch tool calls for performance. When making multiple bash tool calls, send a single message with multiple tool calls so they can run in parallel (for example git status and git diff together).\n- Match edit old-text exactly, including whitespace.\n- If a tool call is denied by policy, adapt: use an allowed approach or ask the user. Do not retry the same blocked call in a loop.\n\n## Shell commands\n\nWhen using the shell, you must adhere to the following guidelines:\n\n- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep` and `find`. (If the `rg` command is not found, then use alternatives.) Reach for the shell only when the `grep`/`glob` tools cannot express the query \u2014 for example counting matches, or piping results into another command.\n- Search narrow first: use `rg -l` or `rg -c` to find which files match, then read only those files. Do not dump full match bodies across a repo into context.\n- Never pipe a large file into your context. Do not `cat` a big file; use the `read` tool with an offset/limit, or `sed -n 'START,ENDp'` for a specific range.\n- Do not use python scripts to attempt to output larger chunks of a file.\n\nIMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames and directory structure.\n\n# AGENTS.md spec\n\n- Repos often contain AGENTS.md files. These files can appear anywhere within the repository.\n- These files are a way for humans to give you (the agent) instructions or tips for working within the container.\n- Some examples might be: coding conventions, info about how code is organized, or instructions for how to run or test code.\n- Instructions in AGENTS.md files:\n - The scope of an AGENTS.md file is the entire directory tree rooted at the folder that contains it.\n - For every file you touch in the final change, you must obey instructions in any AGENTS.md file whose scope includes that file.\n - Instructions about code style, structure, naming, etc. apply only to code within the AGENTS.md file's scope, unless the file states otherwise.\n - More-deeply-nested AGENTS.md files take precedence in the case of conflicting instructions.\n - Direct system/developer/user instructions (as part of a prompt) take precedence over AGENTS.md instructions.\n- The contents of the AGENTS.md file at the root of the repo and the project directory are loaded into your context automatically and don't need to be re-read. AGENTS.md files in subdirectories are NOT loaded automatically: when working in a subdirectory, or a directory outside the CWD, check for any AGENTS.md files that may be applicable.\n\n# Permissions and safety\n\n- Never commit secrets or keys.\n- Never create a git commit unless the user explicitly asks.\n- Do not run destructive commands (mass delete, force-push, hard reset) unless the user clearly requested them.\n";
32639
32757
  ALAN_CODE_ENGINE_PROVIDER_ID = "alan";
@@ -33005,7 +33123,7 @@ function notice(kind, message2) {
33005
33123
  function promptParts2(input2) {
33006
33124
  const files = (input2.imagePaths ?? []).map((path4, index) => ({
33007
33125
  type: "file",
33008
- mime: input2.images?.[index]?.mimeType ?? IMAGE_TYPES[(0, import_path11.extname)(path4).toLowerCase()] ?? "application/octet-stream",
33126
+ mime: input2.images?.[index]?.mimeType ?? IMAGE_TYPES[(0, import_path12.extname)(path4).toLowerCase()] ?? "application/octet-stream",
33009
33127
  filename: path4.split(/[\\/]/).at(-1) ?? path4,
33010
33128
  url: (0, import_url2.pathToFileURL)(path4).href
33011
33129
  }));
@@ -33045,10 +33163,28 @@ function judgeOpenCodeVersion(version2) {
33045
33163
  function unsupportedOpenCodeMessage(version2) {
33046
33164
  return `OpenCode ${version2} is not supported yet: Alan speaks the OpenCode ${OPENCODE_SUPPORTED_MAJOR}.x server API, which OpenCode 2 replaced. Install opencode-ai@${OPENCODE_SUPPORTED_MAJOR}.`;
33047
33165
  }
33048
- async function withDeadline2(work, clock, ms, what) {
33166
+ async function withDeadline2(work, clock, ms, what, code = "protocol_violation") {
33049
33167
  work.catch(() => void 0);
33050
33168
  if (await settlesWithin(work, clock, ms)) return work;
33051
- throw new CoreFault("protocol_violation", `opencode serve did not ${what} within ${ms} ms`);
33169
+ throw new CoreFault(code, `opencode serve did not ${what} within ${ms} ms`);
33170
+ }
33171
+ function exitFault(session) {
33172
+ return new CoreFault(
33173
+ "spawn_failed",
33174
+ `opencode serve exited while opening a session: ${session.outputTail}`
33175
+ );
33176
+ }
33177
+ function whileAlive(session, options, work) {
33178
+ const exited = session.exited.then(() => {
33179
+ throw exitFault(session);
33180
+ });
33181
+ exited.catch(() => void 0);
33182
+ return Promise.race([work, exited]).catch(async (error62) => {
33183
+ if (error62 instanceof CoreFault && error62.code === "spawn_failed") throw error62;
33184
+ if (await settlesWithin(session.exited, options.clock, options.stdoutDrainMs))
33185
+ throw exitFault(session);
33186
+ throw error62;
33187
+ });
33052
33188
  }
33053
33189
  function serverEnv(env, password) {
33054
33190
  const { OPENCODE_SERVER_USERNAME: _user, OPENCODE_SERVER_PASSWORD: _password, ...rest } = env;
@@ -33126,12 +33262,12 @@ async function sameDirectory(left, right) {
33126
33262
  }
33127
33263
  async function canonicalDirectory(directory) {
33128
33264
  try {
33129
- return await (0, import_promises25.realpath)(directory);
33265
+ return await (0, import_promises26.realpath)(directory);
33130
33266
  } catch {
33131
- return (0, import_path10.resolve)(directory);
33267
+ return (0, import_path11.resolve)(directory);
33132
33268
  }
33133
33269
  }
33134
- async function openSession(session, client, spec, log) {
33270
+ async function checkHealth(client, log) {
33135
33271
  const health = await client.health();
33136
33272
  const verdict = judgeOpenCodeVersion(health.version);
33137
33273
  log.info("opencode.healthy", { version: health.version, verdict, healthy: health.healthy });
@@ -33144,7 +33280,34 @@ async function openSession(session, client, spec, log) {
33144
33280
  if (verdict === "too_new") {
33145
33281
  throw new SessionOpenRefusal("unsupported_version", unsupportedOpenCodeMessage(health.version));
33146
33282
  }
33147
- await session.connect(client);
33283
+ }
33284
+ function slowBootstrapNotice(engine, ms) {
33285
+ return noticeUpdate(
33286
+ "info",
33287
+ "engine_bootstrap_slow",
33288
+ `${engine.label} took ${Math.round(ms / 1e3)}s to start`,
33289
+ "A first start installs the engine's dependencies from npm into its config folder; later starts skip this."
33290
+ );
33291
+ }
33292
+ async function connectEvents(session, client, options) {
33293
+ const { clock, log, slowBootstrapMs } = options;
33294
+ const startedAt = clock.monotonic();
33295
+ const done = new AbortController();
33296
+ void clock.sleep(slowBootstrapMs, done.signal).then(
33297
+ () => log.warn("opencode.bootstrap_slow", { pid: session.pid, waitedMs: slowBootstrapMs }),
33298
+ () => void 0
33299
+ );
33300
+ try {
33301
+ await session.connect(client);
33302
+ } finally {
33303
+ done.abort();
33304
+ }
33305
+ const ms = clock.monotonic() - startedAt;
33306
+ if (ms < slowBootstrapMs) return [];
33307
+ log.info("opencode.bootstrap_done", { pid: session.pid, ms: Math.round(ms) });
33308
+ return [slowBootstrapNotice(options.engine, ms)];
33309
+ }
33310
+ async function openSession(client, session, spec, log) {
33148
33311
  const resumeId = spec.resumeSessionId;
33149
33312
  if (resumeId && await canResume(client, resumeId, log)) return { id: resumeId, resumed: true };
33150
33313
  if (resumeId) session.resumeFailed = true;
@@ -33168,8 +33331,22 @@ async function openOnce(spec, password, options) {
33168
33331
  });
33169
33332
  try {
33170
33333
  const client = new OpenCodeClient(url3, password, options.engine.label);
33334
+ const alive = (work) => whileAlive(session, options, work);
33335
+ await withDeadline2(
33336
+ alive(checkHealth(client, options.log)),
33337
+ options.clock,
33338
+ options.openTimeoutMs,
33339
+ "answer a health check"
33340
+ );
33341
+ const notices = await withDeadline2(
33342
+ alive(connectEvents(session, client, options)),
33343
+ options.clock,
33344
+ options.bootstrapTimeoutMs,
33345
+ "open its event stream (a first start installs engine dependencies from npm)",
33346
+ "spawn_failed"
33347
+ );
33171
33348
  const opened = await withDeadline2(
33172
- openSession(session, client, spec, options.log),
33349
+ alive(openSession(client, session, spec, options.log)),
33173
33350
  options.clock,
33174
33351
  options.openTimeoutMs,
33175
33352
  "open a session"
@@ -33177,7 +33354,7 @@ async function openOnce(spec, password, options) {
33177
33354
  session.attach(
33178
33355
  opened.id,
33179
33356
  spec.prompt,
33180
- expiredSignInNotices(spec.env, options.clock.now()),
33357
+ [...expiredSignInNotices(spec.env, options.clock.now()), ...notices],
33181
33358
  opened.resumed
33182
33359
  );
33183
33360
  } catch (error62) {
@@ -33211,6 +33388,8 @@ function createOpenCodeDriver(options = {}) {
33211
33388
  stdoutDrainMs: options.stdoutDrainMs ?? DEFAULTS2.stdoutDrainMs,
33212
33389
  descendantScanMs: options.descendantScanMs ?? DEFAULTS2.descendantScanMs,
33213
33390
  openTimeoutMs: options.openTimeoutMs ?? DEFAULTS2.openTimeoutMs,
33391
+ bootstrapTimeoutMs: options.bootstrapTimeoutMs ?? DEFAULTS2.bootstrapTimeoutMs,
33392
+ slowBootstrapMs: options.slowBootstrapMs ?? DEFAULTS2.slowBootstrapMs,
33214
33393
  openAttempts: options.openAttempts ?? DEFAULTS2.openAttempts,
33215
33394
  startAttempts: options.startAttempts ?? DEFAULTS2.startAttempts,
33216
33395
  reconnectAttempts: options.reconnectAttempts ?? DEFAULTS2.reconnectAttempts,
@@ -33228,9 +33407,9 @@ function createOpenCodeDriver(options = {}) {
33228
33407
  const spec = { ...planned, env: launchEnv(planned, authorization) };
33229
33408
  const password = options.password?.() ?? (0, import_crypto10.randomBytes)(24).toString("base64url");
33230
33409
  try {
33231
- const data = spec.env.XDG_DATA_HOME ?? (0, import_path10.join)(spec.env.HOME ?? spec.env.USERPROFILE ?? spec.cwd, ".local", "share");
33410
+ const data = spec.env.XDG_DATA_HOME ?? (0, import_path11.join)(spec.env.HOME ?? spec.env.USERPROFILE ?? spec.cwd, ".local", "share");
33232
33411
  const session = await withStartupLock(
33233
- (0, import_path10.join)(data, "opencode", ".alan-startup.lock"),
33412
+ (0, import_path11.join)(data, "opencode", ".alan-startup.lock"),
33234
33413
  resolved.clock,
33235
33414
  () => openWithRetries(spec, password, resolved)
33236
33415
  );
@@ -33328,14 +33507,14 @@ function openCodeTurnInput(run2, context) {
33328
33507
  ...context.attachments.length ? { readableFiles: context.attachments.map((attachment) => attachment.path) } : {}
33329
33508
  };
33330
33509
  }
33331
- var import_crypto9, import_http10, import_crypto10, import_promises25, import_path10, import_path11, import_url2, import_path12, import_crypto11, IDLE_SOCKET_MS3, OpenCodeHttpError, BASE62, messageIdClock, OpenCodeClient, OPENCODE_CONFIG_ENV, OPENCODE_ENGINE, TEXT_PARTS, STEP_PARTS, STOPPED_BY_USER, OpenCodeSubagents, NAMED_KINDS, OPENCODE_ABORTED_ERROR, PROVIDER_EVENT_META, TASK_TOOL_NAME, TASK_RESULT_TAG, TASK_ERROR_TAG, PERMISSION_DENIED, FILE_OPERATIONS, NO_USAGE, PartReader, NOTHING, NON_INTERACTIVE_PERMISSIONS, CONTENT_FILTER_FINISHES, TRUNCATED_FINISHES, OUTPUT_PARTS, OpenCodeTurn, LISTENING, OUTPUT_TAIL_LINES, IMAGE_TYPES, OpenCodeSession, OPENCODE_MIN_VERSION, OPENCODE_REQUIREMENT, OPENCODE_TESTED_LINE, OPENCODE_SUPPORTED_MAJOR, DEFAULTS2, STORE_LOCKED, NON_INTERACTIVE_RULES, TITLE_LENGTH, MAX_VARIANT_LENGTH;
33510
+ var import_crypto9, import_http10, import_crypto10, import_promises26, import_path11, import_path12, import_url2, import_path13, import_crypto11, IDLE_SOCKET_MS3, OpenCodeHttpError, BASE62, messageIdClock, OpenCodeClient, OPENCODE_CONFIG_ENV, OPENCODE_ENGINE, TEXT_PARTS, STEP_PARTS, STOPPED_BY_USER, OpenCodeSubagents, NAMED_KINDS, OPENCODE_ABORTED_ERROR, PROVIDER_EVENT_META, TASK_TOOL_NAME, TASK_RESULT_TAG, TASK_ERROR_TAG, PERMISSION_DENIED, FILE_OPERATIONS, NO_USAGE, PartReader, NOTHING, NON_INTERACTIVE_PERMISSIONS, CONTENT_FILTER_FINISHES, TRUNCATED_FINISHES, OUTPUT_PARTS, OpenCodeTurn, LISTENING, OUTPUT_TAIL_LINES, IMAGE_TYPES, OpenCodeSession, OPENCODE_MIN_VERSION, OPENCODE_REQUIREMENT, OPENCODE_TESTED_LINE, OPENCODE_SUPPORTED_MAJOR, DEFAULTS2, STORE_LOCKED, NON_INTERACTIVE_RULES, TITLE_LENGTH, MAX_VARIANT_LENGTH;
33332
33511
  var init_opencode = __esm({
33333
33512
  "../agent-core/dist/providers/opencode.js"() {
33334
33513
  "use strict";
33335
- init_chunk_U4RQE7JS();
33514
+ init_chunk_CGBCAZEN();
33336
33515
  init_chunk_AF3IPGDT();
33337
33516
  init_chunk_WYNUYKKN();
33338
- init_chunk_KVTSAS2T();
33517
+ init_chunk_A5UQ6YFO();
33339
33518
  init_chunk_7FJ7QKFN();
33340
33519
  init_chunk_OSECDZA5();
33341
33520
  init_chunk_YXWJW7I5();
@@ -33343,13 +33522,13 @@ var init_opencode = __esm({
33343
33522
  import_http10 = require("http");
33344
33523
  init_runtime_v2();
33345
33524
  import_crypto10 = require("crypto");
33346
- import_promises25 = require("fs/promises");
33347
- import_path10 = require("path");
33348
- init_agent2();
33525
+ import_promises26 = require("fs/promises");
33349
33526
  import_path11 = require("path");
33527
+ init_agent2();
33528
+ import_path12 = require("path");
33350
33529
  import_url2 = require("url");
33351
33530
  init_acp();
33352
- import_path12 = require("path");
33531
+ import_path13 = require("path");
33353
33532
  init_acp();
33354
33533
  init_constants();
33355
33534
  import_crypto11 = require("crypto");
@@ -33987,7 +34166,7 @@ var init_opencode = __esm({
33987
34166
  this.#readOnly = readOnly;
33988
34167
  this.#memory = memory;
33989
34168
  this.#engine = engine;
33990
- this.#readableFiles = new Set(readableFiles.map((path4) => (0, import_path12.normalize)(path4)));
34169
+ this.#readableFiles = new Set(readableFiles.map((path4) => (0, import_path13.normalize)(path4)));
33991
34170
  }
33992
34171
  get childSessionIds() {
33993
34172
  return [...this.#children.keys()];
@@ -34227,7 +34406,7 @@ var init_opencode = __esm({
34227
34406
  #opensAttachment(kind, properties) {
34228
34407
  if (kind !== "external_directory") return false;
34229
34408
  const filepath = asString(asRecord(properties.metadata)?.filepath);
34230
- return (0, import_path12.isAbsolute)(filepath) && this.#readableFiles.has((0, import_path12.normalize)(filepath));
34409
+ return (0, import_path13.isAbsolute)(filepath) && this.#readableFiles.has((0, import_path13.normalize)(filepath));
34231
34410
  }
34232
34411
  #question(properties) {
34233
34412
  const requestId = asString(properties.id).trim();
@@ -34717,6 +34896,8 @@ var init_opencode = __esm({
34717
34896
  stdoutDrainMs: 2e3,
34718
34897
  descendantScanMs: 5e3,
34719
34898
  openTimeoutMs: 6e4,
34899
+ bootstrapTimeoutMs: 6e5,
34900
+ slowBootstrapMs: 5e3,
34720
34901
  openAttempts: 2,
34721
34902
  startAttempts: 3,
34722
34903
  reconnectAttempts: 3,
@@ -35027,13 +35208,13 @@ function readTranscriptTurns(transcript, chunk, baseOffset, skipped = []) {
35027
35208
  });
35028
35209
  return { turns, consumedBytes: consumedEnd - baseOffset };
35029
35210
  }
35030
- var import_fs7, NEWLINE2, TranscriptCursor, TranscriptLineLookup, CONTENT_UPDATES;
35211
+ var import_fs8, NEWLINE2, TranscriptCursor, TranscriptLineLookup, CONTENT_UPDATES;
35031
35212
  var init_chunk_VUWLTOVK = __esm({
35032
35213
  "../agent-core/dist/chunk-VUWLTOVK.js"() {
35033
35214
  "use strict";
35034
35215
  init_chunk_AF3IPGDT();
35035
35216
  init_chunk_YXWJW7I5();
35036
- import_fs7 = require("fs");
35217
+ import_fs8 = require("fs");
35037
35218
  NEWLINE2 = 10;
35038
35219
  TranscriptCursor = class {
35039
35220
  #path;
@@ -35051,7 +35232,7 @@ var init_chunk_VUWLTOVK = __esm({
35051
35232
  try {
35052
35233
  this.#offset = Math.max(
35053
35234
  this.#offset,
35054
- (0, import_fs7.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0
35235
+ (0, import_fs8.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0
35055
35236
  );
35056
35237
  } catch {
35057
35238
  }
@@ -35073,15 +35254,15 @@ var init_chunk_VUWLTOVK = __esm({
35073
35254
  /** Runs on the CLI's stdout path, so an unreadable file reads as no new lines. */
35074
35255
  #unread() {
35075
35256
  try {
35076
- const size = (0, import_fs7.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0;
35257
+ const size = (0, import_fs8.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0;
35077
35258
  if (size <= this.#offset) return void 0;
35078
35259
  const buffer = Buffer.alloc(size - this.#offset);
35079
- const fd = (0, import_fs7.openSync)(this.#path, "r");
35260
+ const fd = (0, import_fs8.openSync)(this.#path, "r");
35080
35261
  try {
35081
- const read = (0, import_fs7.readSync)(fd, buffer, 0, buffer.length, this.#offset);
35262
+ const read = (0, import_fs8.readSync)(fd, buffer, 0, buffer.length, this.#offset);
35082
35263
  return buffer.subarray(0, read);
35083
35264
  } finally {
35084
- (0, import_fs7.closeSync)(fd);
35265
+ (0, import_fs8.closeSync)(fd);
35085
35266
  }
35086
35267
  } catch {
35087
35268
  return void 0;
@@ -36106,35 +36287,35 @@ function createClaudeDriver(options = {}) {
36106
36287
  };
36107
36288
  }
36108
36289
  function claudeHomeFor(env, homeDir) {
36109
- return env.CLAUDE_CONFIG_DIR || (0, import_path13.join)(env.HOME || homeDir, ".claude");
36290
+ return env.CLAUDE_CONFIG_DIR || (0, import_path14.join)(env.HOME || homeDir, ".claude");
36110
36291
  }
36111
36292
  function encodeProjectDir(cwd) {
36112
36293
  return cwd.replace(/[^a-zA-Z0-9]/g, "-");
36113
36294
  }
36114
36295
  function realCwd(cwd) {
36115
36296
  try {
36116
- return (0, import_fs8.realpathSync)(cwd);
36297
+ return (0, import_fs9.realpathSync)(cwd);
36117
36298
  } catch {
36118
36299
  return cwd;
36119
36300
  }
36120
36301
  }
36121
36302
  function projectDirs(projectsRoot) {
36122
36303
  try {
36123
- return (0, import_fs8.readdirSync)(projectsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
36304
+ return (0, import_fs9.readdirSync)(projectsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
36124
36305
  } catch {
36125
36306
  return [];
36126
36307
  }
36127
36308
  }
36128
36309
  function claudeSessionLogExists(query) {
36129
36310
  if (!query.sessionId || !query.cwd) return false;
36130
- const projectsRoot = (0, import_path13.join)(query.claudeHome, "projects");
36311
+ const projectsRoot = (0, import_path14.join)(query.claudeHome, "projects");
36131
36312
  const fileName = `${query.sessionId}.jsonl`;
36132
36313
  const here = new Set([query.cwd, realCwd(query.cwd)].map(encodeProjectDir));
36133
36314
  for (const dir of here) {
36134
- if ((0, import_fs8.existsSync)((0, import_path13.join)(projectsRoot, dir, fileName))) return true;
36315
+ if ((0, import_fs9.existsSync)((0, import_path14.join)(projectsRoot, dir, fileName))) return true;
36135
36316
  }
36136
36317
  return projectDirs(projectsRoot).some(
36137
- (dir) => !here.has(dir) && (0, import_fs8.existsSync)((0, import_path13.join)(projectsRoot, dir, fileName))
36318
+ (dir) => !here.has(dir) && (0, import_fs9.existsSync)((0, import_path14.join)(projectsRoot, dir, fileName))
36138
36319
  );
36139
36320
  }
36140
36321
  function envDigest3(env) {
@@ -36203,7 +36384,7 @@ async function claudeTurnInput(run2, context) {
36203
36384
  const encoded = await Promise.all(
36204
36385
  images.map(async (image) => ({
36205
36386
  mimeType: image.mimeType,
36206
- data: (await (0, import_promises26.readFile)(image.path)).toString("base64")
36387
+ data: (await (0, import_promises27.readFile)(image.path)).toString("base64")
36207
36388
  }))
36208
36389
  );
36209
36390
  return { turnId: run2.runId, text: text22, ...encoded.length ? { images: encoded } : {} };
@@ -36406,15 +36587,15 @@ function claudeTurnClosingUpdates(records, state) {
36406
36587
  function readClaudeTranscriptTurns(chunk, baseOffset, skipped) {
36407
36588
  return readTranscriptTurns(claudeTranscriptFile, chunk, baseOffset, skipped);
36408
36589
  }
36409
- var import_crypto12, import_fs8, import_path13, import_crypto13, import_promises26, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, CLAUDE_MCP_STATUS, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES3, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS3, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS, CLOUD_SKILL_LISTING_MAX_DESCRIPTION_CHARS, SYNTHETIC_MODEL, INTERRUPT_MARKER, NON_PROMPT_PREFIXES, PRELUDE_TYPES, claudeTranscriptFile;
36590
+ var import_crypto12, import_fs9, import_path14, import_crypto13, import_promises27, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, CLAUDE_MCP_STATUS, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES3, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS3, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS, CLOUD_SKILL_LISTING_MAX_DESCRIPTION_CHARS, SYNTHETIC_MODEL, INTERRUPT_MARKER, NON_PROMPT_PREFIXES, PRELUDE_TYPES, claudeTranscriptFile;
36410
36591
  var init_claude = __esm({
36411
36592
  "../agent-core/dist/providers/claude.js"() {
36412
36593
  "use strict";
36413
36594
  init_chunk_VUWLTOVK();
36414
- init_chunk_U4RQE7JS();
36595
+ init_chunk_CGBCAZEN();
36415
36596
  init_chunk_AF3IPGDT();
36416
36597
  init_chunk_WYNUYKKN();
36417
- init_chunk_KVTSAS2T();
36598
+ init_chunk_A5UQ6YFO();
36418
36599
  init_chunk_7FJ7QKFN();
36419
36600
  init_chunk_OSECDZA5();
36420
36601
  init_chunk_YXWJW7I5();
@@ -36426,10 +36607,10 @@ var init_claude = __esm({
36426
36607
  init_acp();
36427
36608
  init_constants();
36428
36609
  init_agent2();
36429
- import_fs8 = require("fs");
36430
- import_path13 = require("path");
36610
+ import_fs9 = require("fs");
36611
+ import_path14 = require("path");
36431
36612
  import_crypto13 = require("crypto");
36432
- import_promises26 = require("fs/promises");
36613
+ import_promises27 = require("fs/promises");
36433
36614
  init_agent2();
36434
36615
  EDIT_TOOLS = /* @__PURE__ */ new Set([
36435
36616
  "Edit",
@@ -37429,7 +37610,12 @@ __export(claude_exports, {
37429
37610
  });
37430
37611
  function createClaudeHolderDriver(options) {
37431
37612
  const clock = options.clock ?? systemClock2;
37432
- const sessions = options.sessions ?? createClaudeDriver({ ...options.timings, clock, log: options.log });
37613
+ const sessions = options.sessions ?? createClaudeDriver({
37614
+ ...options.timings,
37615
+ clock,
37616
+ log: options.log,
37617
+ ...options.flagProbe === void 0 ? {} : { probe: createClaudeCapabilityProbe(options.flagProbe) }
37618
+ });
37433
37619
  return createPersistentDriver(
37434
37620
  {
37435
37621
  harness: "claude_cli",
@@ -37576,11 +37762,11 @@ function codexExecArgs(input2) {
37576
37762
  ];
37577
37763
  }
37578
37764
  function codexHomeOf(env) {
37579
- return env.CODEX_HOME || (0, import_path14.join)(env.HOME ?? "", ".codex");
37765
+ return env.CODEX_HOME || (0, import_path15.join)(env.HOME ?? "", ".codex");
37580
37766
  }
37581
37767
  function namesNewestFirst(dir, isDir) {
37582
37768
  try {
37583
- return (0, import_fs9.readdirSync)(dir, { withFileTypes: true }).filter((entry) => isDir ? entry.isDirectory() : entry.isFile()).map((entry) => entry.name).sort().reverse();
37769
+ return (0, import_fs10.readdirSync)(dir, { withFileTypes: true }).filter((entry) => isDir ? entry.isDirectory() : entry.isFile()).map((entry) => entry.name).sort().reverse();
37584
37770
  } catch {
37585
37771
  return [];
37586
37772
  }
@@ -37592,15 +37778,15 @@ function findCodexRollout(codexHome, sessionId) {
37592
37778
  const name = namesNewestFirst(dir, false).find(
37593
37779
  (file2) => file2.startsWith("rollout-") && file2.endsWith(suffix)
37594
37780
  );
37595
- return name ? (0, import_path14.join)(dir, name) : void 0;
37781
+ return name ? (0, import_path15.join)(dir, name) : void 0;
37596
37782
  }
37597
37783
  for (const child of namesNewestFirst(dir, true)) {
37598
- const found = walk((0, import_path14.join)(dir, child), depth - 1);
37784
+ const found = walk((0, import_path15.join)(dir, child), depth - 1);
37599
37785
  if (found) return found;
37600
37786
  }
37601
37787
  return void 0;
37602
37788
  };
37603
- return sessionId ? walk((0, import_path14.join)(codexHome, "sessions"), 3) : void 0;
37789
+ return sessionId ? walk((0, import_path15.join)(codexHome, "sessions"), 3) : void 0;
37604
37790
  }
37605
37791
  function codexRolloutExists(codexHome, sessionId) {
37606
37792
  return Promise.resolve(findCodexRollout(codexHome, sessionId) !== void 0);
@@ -39149,9 +39335,9 @@ function tokenCount(payload, state) {
39149
39335
  const totalRecord = asRecord(info?.total_token_usage);
39150
39336
  if (!totalRecord) return [];
39151
39337
  const total = rolloutTokens(totalRecord);
39152
- const lastRecord = asRecord(info?.last_token_usage);
39153
- if (lastRecord)
39154
- state.turnTokens.note(rolloutTokens(lastRecord), total, num(info?.model_context_window));
39338
+ const lastRecord2 = asRecord(info?.last_token_usage);
39339
+ if (lastRecord2)
39340
+ state.turnTokens.note(rolloutTokens(lastRecord2), total, num(info?.model_context_window));
39155
39341
  if (state.turnUsageSeen) return [];
39156
39342
  return reportedUsage(state.turnTokens.spend(total), state);
39157
39343
  }
@@ -39398,20 +39584,20 @@ function codexTurnInput(run2, context) {
39398
39584
  ...images.length ? { imagePaths: images.map((image) => image.path) } : {}
39399
39585
  };
39400
39586
  }
39401
- var import_fs9, import_path14, import_crypto14, import_crypto15, import_crypto16, import_crypto17, TokenRefresher, MCP_STARTUP_TIMEOUT_SEC, FIELD_TYPES, YES_NO, ACCEPT_DECLINE, MAX_INLINE_GENERATED_IMAGE_BYTES, PNG_SIGNATURE2, JPEG_NON_FRAME_MARKERS, IMAGE_GEN_CALL, PROMPT_LITERAL, RELOCATE_EVERY_MS, CodexImageGenerationFold, CodexRolloutImages, CodexRateLimits, USER_INPUT_METHOD, PERMISSIONS_METHOD, ELICITATION_METHOD, COMMAND_OR_FILE, LEGACY, DECISIONS, COORDINATION_TOOLS, SETTLED_AGENT, STATUS, CHANGE_OPERATIONS, SILENT_ON_START, IGNORED_ITEMS, PLAN_STATUS, CodexTurnTokens, CODEX_MCP_STATUS, WORKER_LIFECYCLE, INFO_KINDS, SILENT, CodexTurn, STDERR_TAIL_LINES4, MAX_BETWEEN_UPDATES2, UNSUPPORTED_REQUEST, DECLINED_ELICITATION, IMAGE_CATCH_UP_MS, IMAGE_POLL_MS, CodexSession, CODEX_MIN_VERSION, CODEX_REQUIREMENT, CODEX_TESTED_LINE, DEFAULTS4, CLIENT_INFO2, STATUS2, EXITED_WITHOUT_RESPONSE, CodexExecTurn, DEFAULTS22, CodexExecSession, INJECTED_USER_PREFIXES, SHELL_TOOL_NAMES, ANNOUNCING_ITEM_TYPES, OUTPUT_MARKER, OPEN_PAGE_ACTIONS, FIND_IN_PAGE_ACTIONS, FILE_OPERATIONS2, UNDERSTOOD_ITEM_TYPES, PRELUDE_TYPES2, PRELUDE_EVENTS, codexRolloutFile;
39587
+ var import_fs10, import_path15, import_crypto14, import_crypto15, import_crypto16, import_crypto17, TokenRefresher, MCP_STARTUP_TIMEOUT_SEC, FIELD_TYPES, YES_NO, ACCEPT_DECLINE, MAX_INLINE_GENERATED_IMAGE_BYTES, PNG_SIGNATURE2, JPEG_NON_FRAME_MARKERS, IMAGE_GEN_CALL, PROMPT_LITERAL, RELOCATE_EVERY_MS, CodexImageGenerationFold, CodexRolloutImages, CodexRateLimits, USER_INPUT_METHOD, PERMISSIONS_METHOD, ELICITATION_METHOD, COMMAND_OR_FILE, LEGACY, DECISIONS, COORDINATION_TOOLS, SETTLED_AGENT, STATUS, CHANGE_OPERATIONS, SILENT_ON_START, IGNORED_ITEMS, PLAN_STATUS, CodexTurnTokens, CODEX_MCP_STATUS, WORKER_LIFECYCLE, INFO_KINDS, SILENT, CodexTurn, STDERR_TAIL_LINES4, MAX_BETWEEN_UPDATES2, UNSUPPORTED_REQUEST, DECLINED_ELICITATION, IMAGE_CATCH_UP_MS, IMAGE_POLL_MS, CodexSession, CODEX_MIN_VERSION, CODEX_REQUIREMENT, CODEX_TESTED_LINE, DEFAULTS4, CLIENT_INFO2, STATUS2, EXITED_WITHOUT_RESPONSE, CodexExecTurn, DEFAULTS22, CodexExecSession, INJECTED_USER_PREFIXES, SHELL_TOOL_NAMES, ANNOUNCING_ITEM_TYPES, OUTPUT_MARKER, OPEN_PAGE_ACTIONS, FIND_IN_PAGE_ACTIONS, FILE_OPERATIONS2, UNDERSTOOD_ITEM_TYPES, PRELUDE_TYPES2, PRELUDE_EVENTS, codexRolloutFile;
39402
39588
  var init_codex = __esm({
39403
39589
  "../agent-core/dist/providers/codex.js"() {
39404
39590
  "use strict";
39405
39591
  init_chunk_VUWLTOVK();
39406
- init_chunk_U4RQE7JS();
39592
+ init_chunk_CGBCAZEN();
39407
39593
  init_chunk_AF3IPGDT();
39408
39594
  init_chunk_WYNUYKKN();
39409
- init_chunk_KVTSAS2T();
39595
+ init_chunk_A5UQ6YFO();
39410
39596
  init_chunk_7FJ7QKFN();
39411
39597
  init_chunk_OSECDZA5();
39412
39598
  init_chunk_YXWJW7I5();
39413
- import_fs9 = require("fs");
39414
- import_path14 = require("path");
39599
+ import_fs10 = require("fs");
39600
+ import_path15 = require("path");
39415
39601
  init_effort();
39416
39602
  import_crypto14 = require("crypto");
39417
39603
  import_crypto15 = require("crypto");
@@ -39876,9 +40062,9 @@ var init_codex = __esm({
39876
40062
  }
39877
40063
  #usage(params) {
39878
40064
  const usage = asRecord(params.tokenUsage);
39879
- const lastRecord = asRecord(usage?.last);
39880
- if (!lastRecord) return [];
39881
- const last = appServerTokens(lastRecord);
40065
+ const lastRecord2 = asRecord(usage?.last);
40066
+ if (!lastRecord2) return [];
40067
+ const last = appServerTokens(lastRecord2);
39882
40068
  const totalRecord = asRecord(usage?.total);
39883
40069
  const total = totalRecord ? appServerTokens(totalRecord) : void 0;
39884
40070
  this.#tokens.note(last, total, asFiniteNumber(usage?.modelContextWindow));
@@ -40133,10 +40319,10 @@ var init_codex = __esm({
40133
40319
  images.startAtEnd();
40134
40320
  let finish = () => {
40135
40321
  };
40136
- let identify = () => {
40322
+ let identify2 = () => {
40137
40323
  };
40138
40324
  const identified = new Promise((resolve14) => {
40139
- identify = resolve14;
40325
+ identify2 = resolve14;
40140
40326
  });
40141
40327
  const done = new Promise((resolve14) => {
40142
40328
  finish = (outcome2) => {
@@ -40155,7 +40341,7 @@ var init_codex = __esm({
40155
40341
  done,
40156
40342
  finish,
40157
40343
  identified,
40158
- identify,
40344
+ identify: identify2,
40159
40345
  images,
40160
40346
  cancelRequested: false,
40161
40347
  ending: false
@@ -41140,25 +41326,25 @@ async function droidTurnInput(run2, context) {
41140
41326
  const encoded = await Promise.all(
41141
41327
  images.map(async (image) => ({
41142
41328
  mimeType: image.mimeType,
41143
- data: (await (0, import_promises27.readFile)(image.path)).toString("base64")
41329
+ data: (await (0, import_promises28.readFile)(image.path)).toString("base64")
41144
41330
  }))
41145
41331
  );
41146
41332
  return { turnId: run2.runId, text: text3, ...encoded.length ? { images: encoded } : {} };
41147
41333
  }
41148
- var import_crypto18, import_promises27, FACTORY_API_VERSION, FACTORY_PROTOCOL_VERSION, SUBAGENT_TOOLS, TASK_OUTPUT_TOOLS, TASK_STOP_TOOLS, SILENT2, DroidTurn, STDERR_TAIL_LINES5, UNSUPPORTED_REQUEST2, DroidSession, DEFAULTS5, DROID_REQUIREMENT, DROID_JSONRPC_ARGS;
41334
+ var import_crypto18, import_promises28, FACTORY_API_VERSION, FACTORY_PROTOCOL_VERSION, SUBAGENT_TOOLS, TASK_OUTPUT_TOOLS, TASK_STOP_TOOLS, SILENT2, DroidTurn, STDERR_TAIL_LINES5, UNSUPPORTED_REQUEST2, DroidSession, DEFAULTS5, DROID_REQUIREMENT, DROID_JSONRPC_ARGS;
41149
41335
  var init_droid = __esm({
41150
41336
  "../agent-core/dist/providers/droid.js"() {
41151
41337
  "use strict";
41152
- init_chunk_U4RQE7JS();
41338
+ init_chunk_CGBCAZEN();
41153
41339
  init_chunk_AF3IPGDT();
41154
41340
  init_chunk_WYNUYKKN();
41155
- init_chunk_KVTSAS2T();
41341
+ init_chunk_A5UQ6YFO();
41156
41342
  init_chunk_7FJ7QKFN();
41157
41343
  init_chunk_OSECDZA5();
41158
41344
  init_chunk_YXWJW7I5();
41159
41345
  init_runtime_v2();
41160
41346
  import_crypto18 = require("crypto");
41161
- import_promises27 = require("fs/promises");
41347
+ import_promises28 = require("fs/promises");
41162
41348
  init_agent2();
41163
41349
  FACTORY_API_VERSION = "1.0.0";
41164
41350
  FACTORY_PROTOCOL_VERSION = "1.187.0";
@@ -41640,12 +41826,12 @@ var init_opencode2 = __esm({
41640
41826
  // ../agent-core/dist/providers/antigravity.js
41641
41827
  function settingsPath(env) {
41642
41828
  const home = env.HOME?.trim() || env.USERPROFILE?.trim();
41643
- return home ? (0, import_path15.resolve)(home, ".gemini", "antigravity-cli", "settings.json") : void 0;
41829
+ return home ? (0, import_path16.resolve)(home, ".gemini", "antigravity-cli", "settings.json") : void 0;
41644
41830
  }
41645
41831
  async function readSettings(path4) {
41646
41832
  let raw;
41647
41833
  try {
41648
- raw = (await (0, import_promises28.readFile)(path4, "utf8")).trim();
41834
+ raw = (await (0, import_promises29.readFile)(path4, "utf8")).trim();
41649
41835
  } catch {
41650
41836
  return {};
41651
41837
  }
@@ -41663,8 +41849,8 @@ async function selectAntigravityApiKeyMode(env) {
41663
41849
  const settings2 = await readSettings(path4);
41664
41850
  if (settings2 === "malformed") return "malformed";
41665
41851
  if (settings2.modelProvider === "gemini") return "already_selected";
41666
- await (0, import_promises28.mkdir)((0, import_path15.dirname)(path4), { recursive: true });
41667
- await (0, import_promises28.writeFile)(path4, JSON.stringify({ ...settings2, modelProvider: "gemini" }), { mode: 384 });
41852
+ await (0, import_promises29.mkdir)((0, import_path16.dirname)(path4), { recursive: true });
41853
+ await (0, import_promises29.writeFile)(path4, JSON.stringify({ ...settings2, modelProvider: "gemini" }), { mode: 384 });
41668
41854
  return "selected";
41669
41855
  }
41670
41856
  function readAntigravityCapabilities(version2, help) {
@@ -41707,21 +41893,21 @@ function antigravityArgs(input2, capabilities, prompt) {
41707
41893
  ];
41708
41894
  }
41709
41895
  function workspaceRoot(cwd) {
41710
- for (let current = (0, import_path16.resolve)(cwd); ; current = (0, import_path16.dirname)(current)) {
41711
- if ((0, import_fs10.existsSync)((0, import_path16.join)(current, ".git"))) return current;
41712
- if ((0, import_path16.dirname)(current) === current) return (0, import_path16.resolve)(cwd);
41896
+ for (let current = (0, import_path17.resolve)(cwd); ; current = (0, import_path17.dirname)(current)) {
41897
+ if ((0, import_fs11.existsSync)((0, import_path17.join)(current, ".git"))) return current;
41898
+ if ((0, import_path17.dirname)(current) === current) return (0, import_path17.resolve)(cwd);
41713
41899
  }
41714
41900
  }
41715
41901
  function instructionPaths(cwd) {
41716
41902
  const root = workspaceRoot(cwd);
41717
41903
  const paths = [];
41718
- for (let current = (0, import_path16.resolve)(cwd); ; current = (0, import_path16.dirname)(current)) {
41719
- const path4 = (0, import_path16.join)(current, INSTRUCTIONS_FILE);
41904
+ for (let current = (0, import_path17.resolve)(cwd); ; current = (0, import_path17.dirname)(current)) {
41905
+ const path4 = (0, import_path17.join)(current, INSTRUCTIONS_FILE);
41720
41906
  try {
41721
- if ((0, import_fs10.existsSync)(path4) && (0, import_fs10.statSync)(path4).isFile()) paths.unshift(path4);
41907
+ if ((0, import_fs11.existsSync)(path4) && (0, import_fs11.statSync)(path4).isFile()) paths.unshift(path4);
41722
41908
  } catch {
41723
41909
  }
41724
- if (current === root || (0, import_path16.dirname)(current) === current) return paths;
41910
+ if (current === root || (0, import_path17.dirname)(current) === current) return paths;
41725
41911
  }
41726
41912
  }
41727
41913
  function antigravityWorkspaceInstructions(cwd, maxChars = MAX_INSTRUCTION_CHARS) {
@@ -41732,7 +41918,7 @@ function antigravityWorkspaceInstructions(cwd, maxChars = MAX_INSTRUCTION_CHARS)
41732
41918
  if (remaining <= 0) break;
41733
41919
  let content;
41734
41920
  try {
41735
- content = (0, import_fs10.readFileSync)(path4, "utf8").trim();
41921
+ content = (0, import_fs11.readFileSync)(path4, "utf8").trim();
41736
41922
  } catch {
41737
41923
  continue;
41738
41924
  }
@@ -41975,7 +42161,7 @@ function normalizeAntigravityFrame(event) {
41975
42161
  }
41976
42162
  function antigravityBrainRoot(env) {
41977
42163
  const home = env.HOME?.trim() || env.USERPROFILE?.trim();
41978
- return home ? (0, import_path17.resolve)(home, ".gemini", "antigravity-cli", "brain") : void 0;
42164
+ return home ? (0, import_path18.resolve)(home, ".gemini", "antigravity-cli", "brain") : void 0;
41979
42165
  }
41980
42166
  function parseEntry(text3) {
41981
42167
  try {
@@ -42013,14 +42199,14 @@ function childTranscriptPath(root, frame) {
42013
42199
  try {
42014
42200
  const url3 = new URL(logUri);
42015
42201
  if (url3.protocol !== "file:") return void 0;
42016
- path4 = (0, import_path17.resolve)((0, import_url3.fileURLToPath)(url3));
42202
+ path4 = (0, import_path18.resolve)((0, import_url3.fileURLToPath)(url3));
42017
42203
  } catch {
42018
42204
  return void 0;
42019
42205
  }
42020
- const fromRoot = (0, import_path17.relative)(root, path4);
42021
- if (!fromRoot || (0, import_path17.isAbsolute)(fromRoot) || fromRoot.split(import_path17.sep).includes("..")) return void 0;
42206
+ const fromRoot = (0, import_path18.relative)(root, path4);
42207
+ if (!fromRoot || (0, import_path18.isAbsolute)(fromRoot) || fromRoot.split(import_path18.sep).includes("..")) return void 0;
42022
42208
  const expected = [conversationId, ...LOG_DIRS, TRANSCRIPT_FILE];
42023
- const segments = fromRoot.split(import_path17.sep);
42209
+ const segments = fromRoot.split(import_path18.sep);
42024
42210
  const matches = segments.length === expected.length && segments.every((segment, index) => segment === expected[index]);
42025
42211
  return matches ? path4 : void 0;
42026
42212
  }
@@ -42282,24 +42468,24 @@ function antigravityTurnInput(run2, context) {
42282
42468
  });
42283
42469
  return { turnId: run2.runId, text: appendImagePathReferences(text3, images) };
42284
42470
  }
42285
- var import_promises28, import_path15, import_fs10, import_path16, import_path17, import_url3, import_crypto19, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
42471
+ var import_promises29, import_path16, import_fs11, import_path17, import_path18, import_url3, import_crypto19, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
42286
42472
  var init_antigravity = __esm({
42287
42473
  "../agent-core/dist/providers/antigravity.js"() {
42288
42474
  "use strict";
42289
42475
  init_chunk_VUWLTOVK();
42290
- init_chunk_U4RQE7JS();
42476
+ init_chunk_CGBCAZEN();
42291
42477
  init_chunk_AF3IPGDT();
42292
42478
  init_chunk_WYNUYKKN();
42293
- init_chunk_KVTSAS2T();
42479
+ init_chunk_A5UQ6YFO();
42294
42480
  init_chunk_7FJ7QKFN();
42295
42481
  init_chunk_YXWJW7I5();
42296
- import_promises28 = require("fs/promises");
42297
- import_path15 = require("path");
42298
- init_type_guards();
42299
- import_fs10 = require("fs");
42482
+ import_promises29 = require("fs/promises");
42300
42483
  import_path16 = require("path");
42301
- init_effort();
42484
+ init_type_guards();
42485
+ import_fs11 = require("fs");
42302
42486
  import_path17 = require("path");
42487
+ init_effort();
42488
+ import_path18 = require("path");
42303
42489
  import_url3 = require("url");
42304
42490
  import_crypto19 = require("crypto");
42305
42491
  init_agent2();
@@ -42339,7 +42525,7 @@ var init_antigravity = __esm({
42339
42525
  #full;
42340
42526
  constructor(path4) {
42341
42527
  this.#cursor = new TranscriptCursor(path4);
42342
- this.#fullPath = (0, import_path17.resolve)((0, import_path17.dirname)(path4), FULL_TRANSCRIPT_FILE);
42528
+ this.#fullPath = (0, import_path18.resolve)((0, import_path18.dirname)(path4), FULL_TRANSCRIPT_FILE);
42343
42529
  }
42344
42530
  skipExisting() {
42345
42531
  this.#cursor.read();
@@ -42387,7 +42573,7 @@ var init_antigravity = __esm({
42387
42573
  /** A conversation this turn did not resume was created by it, so it is read whole. */
42388
42574
  trackParent(conversationId) {
42389
42575
  if (this.#parent?.conversationId === conversationId) return;
42390
- const path4 = (0, import_path17.resolve)(this.#root, conversationId, ...LOG_DIRS, TRANSCRIPT_FILE);
42576
+ const path4 = (0, import_path18.resolve)(this.#root, conversationId, ...LOG_DIRS, TRANSCRIPT_FILE);
42391
42577
  this.#parent = { conversationId, transcript: new BrainTranscript(path4) };
42392
42578
  }
42393
42579
  /** A launcher keeps the first valid transcript it names; later frames change nothing. */
@@ -42818,8 +43004,8 @@ function parseConfig(raw) {
42818
43004
  }
42819
43005
  }
42820
43006
  async function writeCommandCodeProjectMcp(cwd, mcp) {
42821
- const path4 = (0, import_path18.join)(cwd, ".mcp.json");
42822
- const original = await (0, import_promises29.readFile)(path4, "utf8").catch(() => null);
43007
+ const path4 = (0, import_path19.join)(cwd, ".mcp.json");
43008
+ const original = await (0, import_promises30.readFile)(path4, "utf8").catch(() => null);
42823
43009
  const config2 = parseConfig(original);
42824
43010
  const next = {
42825
43011
  ...config2,
@@ -42836,12 +43022,12 @@ async function writeCommandCodeProjectMcp(cwd, mcp) {
42836
43022
  }
42837
43023
  }
42838
43024
  };
42839
- await (0, import_promises29.mkdir)(cwd, { recursive: true });
42840
- await (0, import_promises29.writeFile)(path4, `${JSON.stringify(next, null, 2)}
43025
+ await (0, import_promises30.mkdir)(cwd, { recursive: true });
43026
+ await (0, import_promises30.writeFile)(path4, `${JSON.stringify(next, null, 2)}
42841
43027
  `);
42842
43028
  return async () => {
42843
- if (original === null) await (0, import_promises29.rm)(path4, { force: true });
42844
- else await (0, import_promises29.writeFile)(path4, original);
43029
+ if (original === null) await (0, import_promises30.rm)(path4, { force: true });
43030
+ else await (0, import_promises30.writeFile)(path4, original);
42845
43031
  };
42846
43032
  }
42847
43033
  function commandCodeString(value2) {
@@ -43013,19 +43199,19 @@ function commandCodeTurnInput(run2, context) {
43013
43199
  });
43014
43200
  return { turnId: run2.runId, text: appendImagePathReferences(text3, images) };
43015
43201
  }
43016
- var import_promises29, import_path18, import_crypto20, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
43202
+ var import_promises30, import_path19, import_crypto20, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
43017
43203
  var init_command_code = __esm({
43018
43204
  "../agent-core/dist/providers/command-code.js"() {
43019
43205
  "use strict";
43020
- init_chunk_U4RQE7JS();
43206
+ init_chunk_CGBCAZEN();
43021
43207
  init_chunk_AF3IPGDT();
43022
43208
  init_chunk_WYNUYKKN();
43023
- init_chunk_KVTSAS2T();
43209
+ init_chunk_A5UQ6YFO();
43024
43210
  init_chunk_7FJ7QKFN();
43025
43211
  init_chunk_OSECDZA5();
43026
43212
  init_chunk_YXWJW7I5();
43027
- import_promises29 = require("fs/promises");
43028
- import_path18 = require("path");
43213
+ import_promises30 = require("fs/promises");
43214
+ import_path19 = require("path");
43029
43215
  init_agent2();
43030
43216
  init_runtime_v2();
43031
43217
  init_acp();
@@ -53162,7 +53348,7 @@ var require_extract = __commonJS({
53162
53348
  var require_constants = __commonJS({
53163
53349
  "../../node_modules/tar-stream/constants.js"(exports2, module2) {
53164
53350
  "use strict";
53165
- var constants5 = {
53351
+ var constants7 = {
53166
53352
  // just for envs without fs
53167
53353
  S_IFMT: 61440,
53168
53354
  S_IFDIR: 16384,
@@ -53172,9 +53358,9 @@ var require_constants = __commonJS({
53172
53358
  S_IFLNK: 40960
53173
53359
  };
53174
53360
  try {
53175
- module2.exports = require("fs").constants || constants5;
53361
+ module2.exports = require("fs").constants || constants7;
53176
53362
  } catch {
53177
- module2.exports = constants5;
53363
+ module2.exports = constants7;
53178
53364
  }
53179
53365
  }
53180
53366
  });
@@ -53185,7 +53371,7 @@ var require_pack = __commonJS({
53185
53371
  "use strict";
53186
53372
  var { Readable: Readable2, Writable, getStreamError } = require_streamx();
53187
53373
  var b4a = require_b4a();
53188
- var constants5 = require_constants();
53374
+ var constants7 = require_constants();
53189
53375
  var headers = require_headers();
53190
53376
  var DMODE = 493;
53191
53377
  var FMODE = 420;
@@ -53388,16 +53574,16 @@ var require_pack = __commonJS({
53388
53574
  return new Pack(opts);
53389
53575
  };
53390
53576
  function modeToType(mode) {
53391
- switch (mode & constants5.S_IFMT) {
53392
- case constants5.S_IFBLK:
53577
+ switch (mode & constants7.S_IFMT) {
53578
+ case constants7.S_IFBLK:
53393
53579
  return "block-device";
53394
- case constants5.S_IFCHR:
53580
+ case constants7.S_IFCHR:
53395
53581
  return "character-device";
53396
- case constants5.S_IFDIR:
53582
+ case constants7.S_IFDIR:
53397
53583
  return "directory";
53398
- case constants5.S_IFIFO:
53584
+ case constants7.S_IFIFO:
53399
53585
  return "fifo";
53400
- case constants5.S_IFLNK:
53586
+ case constants7.S_IFLNK:
53401
53587
  return "symlink";
53402
53588
  }
53403
53589
  return "file";
@@ -54038,8 +54224,8 @@ var require_common = __commonJS({
54038
54224
  }
54039
54225
  return debug12;
54040
54226
  }
54041
- function extend2(namespace, delimiter) {
54042
- const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
54227
+ function extend2(namespace, delimiter2) {
54228
+ const newDebug = createDebug(this.namespace + (typeof delimiter2 === "undefined" ? ":" : delimiter2) + namespace);
54043
54229
  newDebug.log = this.log;
54044
54230
  return newDebug;
54045
54231
  }
@@ -58209,7 +58395,7 @@ var import_node_worker_threads2 = require("worker_threads");
58209
58395
  // package.json
58210
58396
  var package_default = {
58211
58397
  name: "@alan-ai-hq/agent-manager",
58212
- version: "0.1.170",
58398
+ version: "0.1.172",
58213
58399
  private: true,
58214
58400
  type: "module",
58215
58401
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -59740,9 +59926,9 @@ function isProcessAlive(pid) {
59740
59926
  }
59741
59927
  }
59742
59928
  async function linuxStartTime(pid) {
59743
- const stat23 = await (0, import_promises5.readFile)(`/proc/${pid}/stat`, "utf8").catch(() => null);
59744
- if (stat23 === null) return null;
59745
- const fields = stat23.slice(stat23.lastIndexOf(")") + 2).split(" ");
59929
+ const stat24 = await (0, import_promises5.readFile)(`/proc/${pid}/stat`, "utf8").catch(() => null);
59930
+ if (stat24 === null) return null;
59931
+ const fields = stat24.slice(stat24.lastIndexOf(")") + 2).split(" ");
59746
59932
  return fields[19] ?? null;
59747
59933
  }
59748
59934
  async function linuxCommand(pid) {
@@ -60177,8 +60363,8 @@ function ipcEndpoint(socketsDir, id, platform3 = process.platform) {
60177
60363
  return (0, import_node_path6.join)(dir, `${id}.sock`);
60178
60364
  }
60179
60365
  function assertPrivateDirectory(dir, uid) {
60180
- const stat23 = (0, import_node_fs6.lstatSync)(dir);
60181
- if (!stat23.isDirectory() || stat23.uid !== uid || (stat23.mode & 63) !== 0) {
60366
+ const stat24 = (0, import_node_fs6.lstatSync)(dir);
60367
+ if (!stat24.isDirectory() || stat24.uid !== uid || (stat24.mode & 63) !== 0) {
60182
60368
  throw new RuntimeFault(
60183
60369
  "io_failed",
60184
60370
  `Refusing socket directory ${dir}: it must be a directory owned by uid ${uid} with mode 0700`
@@ -61978,8 +62164,8 @@ async function readVmCounters(platform3 = process.platform) {
61978
62164
  return null;
61979
62165
  }
61980
62166
  }
61981
- function parseProcStat(stat23) {
61982
- const fields = stat23.slice(stat23.lastIndexOf(")") + 2).split(" ");
62167
+ function parseProcStat(stat24) {
62168
+ const fields = stat24.slice(stat24.lastIndexOf(")") + 2).split(" ");
61983
62169
  const ppid = Number(fields[1]);
61984
62170
  const utime = Number(fields[11]);
61985
62171
  const stime = Number(fields[12]);
@@ -61992,8 +62178,8 @@ async function readProcessCpuTable(platform3 = process.platform) {
61992
62178
  const entries = await (0, import_promises16.readdir)("/proc").catch(() => []);
61993
62179
  await Promise.all(
61994
62180
  entries.filter((entry) => /^\d+$/.test(entry)).map(async (entry) => {
61995
- const stat23 = await (0, import_promises16.readFile)(`/proc/${entry}/stat`, "utf8").catch(() => null);
61996
- const row = stat23 === null ? null : parseProcStat(stat23);
62181
+ const stat24 = await (0, import_promises16.readFile)(`/proc/${entry}/stat`, "utf8").catch(() => null);
62182
+ const row = stat24 === null ? null : parseProcStat(stat24);
61997
62183
  if (row !== null) table.set(Number(entry), row);
61998
62184
  })
61999
62185
  );
@@ -62172,7 +62358,7 @@ function startWakeClock(options) {
62172
62358
  }
62173
62359
 
62174
62360
  // src/cli/commands/activity-lease-producer.ts
62175
- var import_promises70 = require("fs/promises");
62361
+ var import_promises71 = require("fs/promises");
62176
62362
  var import_node_path68 = require("path");
62177
62363
  init_runtime_v2();
62178
62364
 
@@ -62349,7 +62535,7 @@ var GitFault = class extends Error {
62349
62535
  };
62350
62536
 
62351
62537
  // src/capabilities/git/remote.ts
62352
- var import_promises30 = require("fs/promises");
62538
+ var import_promises31 = require("fs/promises");
62353
62539
  var import_node_path18 = require("path");
62354
62540
  var import_node_url2 = require("url");
62355
62541
  var SUPPORTED_REMOTE_PROTOCOLS = /* @__PURE__ */ new Set([
@@ -62363,7 +62549,7 @@ async function canonicalPathWithMissingTail(path4) {
62363
62549
  let cursor = (0, import_node_path18.resolve)(path4);
62364
62550
  for (; ; ) {
62365
62551
  try {
62366
- return (0, import_node_path18.join)(await (0, import_promises30.realpath)(cursor), ...missing);
62552
+ return (0, import_node_path18.join)(await (0, import_promises31.realpath)(cursor), ...missing);
62367
62553
  } catch (error62) {
62368
62554
  if (errnoCode(error62) !== "ENOENT" && errnoCode(error62) !== "ENOTDIR") throw error62;
62369
62555
  const parent = (0, import_node_path18.dirname)(cursor);
@@ -62457,11 +62643,11 @@ async function inspectedRemoteUrl(git, repoRoot, remote, signal) {
62457
62643
  }
62458
62644
 
62459
62645
  // src/capabilities/git/repository.ts
62460
- var import_promises31 = require("fs/promises");
62646
+ var import_promises32 = require("fs/promises");
62461
62647
  var import_node_path19 = require("path");
62462
62648
  async function isDirectory2(path4) {
62463
62649
  try {
62464
- return (await (0, import_promises31.stat)(path4)).isDirectory();
62650
+ return (await (0, import_promises32.stat)(path4)).isDirectory();
62465
62651
  } catch {
62466
62652
  return false;
62467
62653
  }
@@ -62482,7 +62668,7 @@ async function resolveRepositoryRoot(git, path4, signal) {
62482
62668
  "The selected folder is not inside a Git repository"
62483
62669
  );
62484
62670
  }
62485
- return (0, import_promises31.realpath)((0, import_node_path19.resolve)(root));
62671
+ return (0, import_promises32.realpath)((0, import_node_path19.resolve)(root));
62486
62672
  }
62487
62673
  async function listWorktrees(git, repoRoot, signal) {
62488
62674
  const output2 = await git.ok(
@@ -62546,12 +62732,12 @@ async function repositoryCommonDir(git, repoRoot, signal) {
62546
62732
  signal,
62547
62733
  "git_operation_failed"
62548
62734
  );
62549
- return (0, import_promises31.realpath)(commonDir);
62735
+ return (0, import_promises32.realpath)(commonDir);
62550
62736
  }
62551
62737
 
62552
62738
  // src/capabilities/git/status.ts
62553
62739
  var import_node_crypto13 = require("crypto");
62554
- var import_promises32 = require("fs/promises");
62740
+ var import_promises33 = require("fs/promises");
62555
62741
  var import_node_path20 = require("path");
62556
62742
  var BRANCH_LABEL_MAX_LENGTH = 256;
62557
62743
  var HASH_OBJECT_BATCH = 128;
@@ -62631,8 +62817,8 @@ async function readWorkspaceStatus(context) {
62631
62817
  };
62632
62818
  }
62633
62819
  async function proposedTreeSha(context, headSha) {
62634
- await (0, import_promises32.mkdir)(context.tmpDir, { recursive: true, mode: 448 });
62635
- const tempDir = await (0, import_promises32.mkdtemp)((0, import_node_path20.join)(context.tmpDir, "index-"));
62820
+ await (0, import_promises33.mkdir)(context.tmpDir, { recursive: true, mode: 448 });
62821
+ const tempDir = await (0, import_promises33.mkdtemp)((0, import_node_path20.join)(context.tmpDir, "index-"));
62636
62822
  const env = { GIT_INDEX_FILE: (0, import_node_path20.join)(tempDir, "index") };
62637
62823
  const run2 = (args) => context.git.ok({ cwd: context.repoRoot, args, env }, context.signal, "git_status_unreadable");
62638
62824
  try {
@@ -62642,7 +62828,7 @@ async function proposedTreeSha(context, headSha) {
62642
62828
  assertCommitSha(tree, "proposedTreeSha");
62643
62829
  return tree;
62644
62830
  } finally {
62645
- await (0, import_promises32.rm)(tempDir, { recursive: true, force: true });
62831
+ await (0, import_promises33.rm)(tempDir, { recursive: true, force: true });
62646
62832
  }
62647
62833
  }
62648
62834
  function updateLengthPrefixed(hash2, value2) {
@@ -62839,14 +63025,14 @@ async function verifyHead(context, request2) {
62839
63025
  }
62840
63026
 
62841
63027
  // src/capabilities/git/checkpoint.ts
62842
- var import_promises33 = require("fs/promises");
63028
+ var import_promises34 = require("fs/promises");
62843
63029
  var import_node_path21 = require("path");
62844
63030
  function sourceChanged(message2) {
62845
63031
  return new GitFault("source_changed_since_approval", message2);
62846
63032
  }
62847
63033
  async function createLockFile(path4) {
62848
63034
  try {
62849
- await (0, import_promises33.writeFile)(path4, "", { flag: "wx" });
63035
+ await (0, import_promises34.writeFile)(path4, "", { flag: "wx" });
62850
63036
  return true;
62851
63037
  } catch {
62852
63038
  return false;
@@ -62860,13 +63046,13 @@ async function acquireHeadLock(locks) {
62860
63046
  }
62861
63047
  async function releaseHeadLock(locks) {
62862
63048
  if (!locks.headLockHeld) return;
62863
- await (0, import_promises33.rm)(locks.headLockPath, { force: true });
63049
+ await (0, import_promises34.rm)(locks.headLockPath, { force: true });
62864
63050
  locks.headLockHeld = false;
62865
63051
  }
62866
63052
  async function releaseLocks(locks) {
62867
63053
  await releaseHeadLock(locks);
62868
63054
  if (locks.indexLockHeld) {
62869
- await (0, import_promises33.rm)(locks.indexLockPath, { force: true });
63055
+ await (0, import_promises34.rm)(locks.indexLockPath, { force: true });
62870
63056
  locks.indexLockHeld = false;
62871
63057
  }
62872
63058
  }
@@ -62910,8 +63096,8 @@ async function assertHead(context, expectedRef, expectedHeadSha) {
62910
63096
  }
62911
63097
  }
62912
63098
  async function createIndexBaseline(context, sha) {
62913
- await (0, import_promises33.mkdir)(context.tmpDir, { recursive: true, mode: 448 });
62914
- const tempDir = await (0, import_promises33.mkdtemp)((0, import_node_path21.join)(context.tmpDir, "checkpoint-index-"));
63099
+ await (0, import_promises34.mkdir)(context.tmpDir, { recursive: true, mode: 448 });
63100
+ const tempDir = await (0, import_promises34.mkdtemp)((0, import_node_path21.join)(context.tmpDir, "checkpoint-index-"));
62915
63101
  const indexPath = (0, import_node_path21.join)(tempDir, "index");
62916
63102
  try {
62917
63103
  await context.git.ok(
@@ -62921,14 +63107,14 @@ async function createIndexBaseline(context, sha) {
62921
63107
  );
62922
63108
  return { indexPath, tempDir };
62923
63109
  } catch (error62) {
62924
- await (0, import_promises33.rm)(tempDir, { recursive: true, force: true });
63110
+ await (0, import_promises34.rm)(tempDir, { recursive: true, force: true });
62925
63111
  throw error62;
62926
63112
  }
62927
63113
  }
62928
63114
  async function installIndexBaseline(locks, baselinePath) {
62929
63115
  try {
62930
- await (0, import_promises33.copyFile)(baselinePath, locks.indexLockPath);
62931
- await (0, import_promises33.rename)(locks.indexLockPath, locks.indexPath);
63116
+ await (0, import_promises34.copyFile)(baselinePath, locks.indexLockPath);
63117
+ await (0, import_promises34.rename)(locks.indexLockPath, locks.indexPath);
62932
63118
  locks.indexLockHeld = false;
62933
63119
  } catch (error62) {
62934
63120
  throw new GitFault(
@@ -62956,7 +63142,7 @@ async function replayCheckpoint(context, expectedRef, headSha) {
62956
63142
  return { repoRoot: context.repoRoot, sha: headSha, replayed: true };
62957
63143
  } finally {
62958
63144
  if (locks) await releaseLocks(locks);
62959
- await (0, import_promises33.rm)(baseline.tempDir, { recursive: true, force: true });
63145
+ await (0, import_promises34.rm)(baseline.tempDir, { recursive: true, force: true });
62960
63146
  }
62961
63147
  }
62962
63148
  async function commitApprovedTree(context, request2) {
@@ -63087,7 +63273,7 @@ async function finalize2(context, expectedRef, previousSha, sha) {
63087
63273
  );
63088
63274
  }
63089
63275
  if (locks) await releaseLocks(locks);
63090
- await (0, import_promises33.rm)(baseline.tempDir, { recursive: true, force: true });
63276
+ await (0, import_promises34.rm)(baseline.tempDir, { recursive: true, force: true });
63091
63277
  }
63092
63278
  }
63093
63279
 
@@ -63182,7 +63368,7 @@ async function push(context, request2) {
63182
63368
  var import_node_child_process9 = require("child_process");
63183
63369
 
63184
63370
  // ../agent-core/dist/process.js
63185
- init_chunk_KVTSAS2T();
63371
+ init_chunk_A5UQ6YFO();
63186
63372
  init_chunk_YXWJW7I5();
63187
63373
 
63188
63374
  // src/capabilities/git/run-git.ts
@@ -63363,7 +63549,7 @@ function createGitRunner(options) {
63363
63549
 
63364
63550
  // src/capabilities/git/checkout-freshness.ts
63365
63551
  var import_node_crypto14 = require("crypto");
63366
- var import_promises34 = require("fs/promises");
63552
+ var import_promises35 = require("fs/promises");
63367
63553
  var import_node_path22 = require("path");
63368
63554
  init_zod();
63369
63555
  var REMOTE = "origin";
@@ -63526,14 +63712,14 @@ async function moveSnapshotTo(git, cwd, snapshot, tip, signal) {
63526
63712
  return moved.exitCode === 0 && back.exitCode === 0;
63527
63713
  }
63528
63714
  async function isCheckout(path4) {
63529
- return (0, import_promises34.stat)((0, import_node_path22.join)(path4, ".git")).then(
63715
+ return (0, import_promises35.stat)((0, import_node_path22.join)(path4, ".git")).then(
63530
63716
  () => true,
63531
63717
  () => false
63532
63718
  );
63533
63719
  }
63534
63720
  async function checkoutsUnder(root) {
63535
63721
  if (await isCheckout(root)) return [root];
63536
- const entries = await (0, import_promises34.readdir)(root, { withFileTypes: true }).catch(() => []);
63722
+ const entries = await (0, import_promises35.readdir)(root, { withFileTypes: true }).catch(() => []);
63537
63723
  const found = await Promise.all(
63538
63724
  entries.filter((entry) => entry.isDirectory()).map(
63539
63725
  async (entry) => await isCheckout((0, import_node_path22.join)(root, entry.name)) ? (0, import_node_path22.join)(root, entry.name) : null
@@ -63697,7 +63883,7 @@ var GIT_CREDENTIAL_QUIT = "quit=1\n";
63697
63883
 
63698
63884
  // src/capabilities/git/credential-server.ts
63699
63885
  var import_node_crypto15 = require("crypto");
63700
- var import_promises35 = require("fs/promises");
63886
+ var import_promises36 = require("fs/promises");
63701
63887
  var import_node_net2 = require("net");
63702
63888
 
63703
63889
  // src/capabilities/git/credential-socket.ts
@@ -63884,7 +64070,7 @@ async function startGitCredentialServer(options) {
63884
64070
  closing.abort();
63885
64071
  await new Promise((resolve14) => server.close(() => resolve14()));
63886
64072
  removeStaleEndpoint(options.endpoint);
63887
- await (0, import_promises35.rm)(options.tokenPath, { force: true });
64073
+ await (0, import_promises36.rm)(options.tokenPath, { force: true });
63888
64074
  }
63889
64075
  };
63890
64076
  }
@@ -63934,7 +64120,7 @@ function createGit(options) {
63934
64120
  // src/capabilities/github-proxy/certificates.ts
63935
64121
  var import_node_child_process10 = require("child_process");
63936
64122
  var import_node_crypto16 = require("crypto");
63937
- var import_promises36 = require("fs/promises");
64123
+ var import_promises37 = require("fs/promises");
63938
64124
  var import_node_path24 = require("path");
63939
64125
  var OPENSSL_TIMEOUT_MS = 1e4;
63940
64126
  var VALIDITY_DAYS = "30";
@@ -63972,13 +64158,13 @@ function openssl(args, cwd) {
63972
64158
  }
63973
64159
  async function createGitHubProxyCertificates(stateDir) {
63974
64160
  const work = (0, import_node_path24.join)(stateDir, "github-proxy");
63975
- await (0, import_promises36.rm)(work, { recursive: true, force: true });
63976
- await (0, import_promises36.mkdir)(work, { recursive: true, mode: 448 });
64161
+ await (0, import_promises37.rm)(work, { recursive: true, force: true });
64162
+ await (0, import_promises37.mkdir)(work, { recursive: true, mode: 448 });
63977
64163
  try {
63978
- await (0, import_promises36.writeFile)((0, import_node_path24.join)(work, "ca.cnf"), opensslConfig("Alan sandbox GitHub proxy CA"), {
64164
+ await (0, import_promises37.writeFile)((0, import_node_path24.join)(work, "ca.cnf"), opensslConfig("Alan sandbox GitHub proxy CA"), {
63979
64165
  mode: 384
63980
64166
  });
63981
- await (0, import_promises36.writeFile)((0, import_node_path24.join)(work, "leaf.cnf"), opensslConfig("github.com"), { mode: 384 });
64167
+ await (0, import_promises37.writeFile)((0, import_node_path24.join)(work, "leaf.cnf"), opensslConfig("github.com"), { mode: 384 });
63982
64168
  const curve = ["ecparam", "-name", "prime256v1", "-genkey", "-noout"];
63983
64169
  await openssl([...curve, "-out", "ca.key"], work);
63984
64170
  await openssl(
@@ -64002,19 +64188,19 @@ async function createGitHubProxyCertificates(stateDir) {
64002
64188
  work
64003
64189
  );
64004
64190
  const caPath = (0, import_node_path24.join)(stateDir, "github-ca.pem");
64005
- await (0, import_promises36.writeFile)(caPath, await (0, import_promises36.readFile)((0, import_node_path24.join)(work, "ca.pem")), { mode: 384 });
64191
+ await (0, import_promises37.writeFile)(caPath, await (0, import_promises37.readFile)((0, import_node_path24.join)(work, "ca.pem")), { mode: 384 });
64006
64192
  return {
64007
64193
  caPath,
64008
- leafKeyPem: await (0, import_promises36.readFile)((0, import_node_path24.join)(work, "leaf.key"), "utf8"),
64009
- leafCertPem: await (0, import_promises36.readFile)((0, import_node_path24.join)(work, "leaf.pem"), "utf8")
64194
+ leafKeyPem: await (0, import_promises37.readFile)((0, import_node_path24.join)(work, "leaf.key"), "utf8"),
64195
+ leafCertPem: await (0, import_promises37.readFile)((0, import_node_path24.join)(work, "leaf.pem"), "utf8")
64010
64196
  };
64011
64197
  } finally {
64012
- await (0, import_promises36.rm)(work, { recursive: true, force: true });
64198
+ await (0, import_promises37.rm)(work, { recursive: true, force: true });
64013
64199
  }
64014
64200
  }
64015
64201
 
64016
64202
  // src/capabilities/github-proxy/config.ts
64017
- var import_promises37 = require("fs/promises");
64203
+ var import_promises38 = require("fs/promises");
64018
64204
  var import_node_path25 = require("path");
64019
64205
  init_runtime_v2();
64020
64206
  var GITHUB_URL = "https://github.com/";
@@ -64031,10 +64217,10 @@ function withGhConfigKey(yaml, key, value2) {
64031
64217
  `;
64032
64218
  }
64033
64219
  async function configureGh(ghConfigDir, socketPath) {
64034
- await (0, import_promises37.mkdir)(ghConfigDir, { recursive: true, mode: 448 });
64220
+ await (0, import_promises38.mkdir)(ghConfigDir, { recursive: true, mode: 448 });
64035
64221
  const path4 = (0, import_node_path25.join)(ghConfigDir, "config.yml");
64036
- const current = await (0, import_promises37.readFile)(path4, "utf8").catch(() => "");
64037
- await (0, import_promises37.writeFile)(path4, withGhConfigKey(current, GH_SOCKET_KEY, socketPath), { mode: 384 });
64222
+ const current = await (0, import_promises38.readFile)(path4, "utf8").catch(() => "");
64223
+ await (0, import_promises38.writeFile)(path4, withGhConfigKey(current, GH_SOCKET_KEY, socketPath), { mode: 384 });
64038
64224
  }
64039
64225
  async function configureGit(input2, git) {
64040
64226
  const run2 = async (args, allowedExitCodes = [0]) => {
@@ -64064,7 +64250,7 @@ async function configureGitHubProxyClients(input2) {
64064
64250
  }
64065
64251
 
64066
64252
  // src/capabilities/github-proxy/server.ts
64067
- var import_promises38 = require("fs/promises");
64253
+ var import_promises39 = require("fs/promises");
64068
64254
  var import_node_http3 = require("http");
64069
64255
  var import_node_tls = require("tls");
64070
64256
  init_runtime_v2();
@@ -64206,7 +64392,7 @@ async function startGitHubProxy(options) {
64206
64392
  });
64207
64393
  removeStaleEndpoint(options.socketPath);
64208
64394
  await listen(gh, options.socketPath);
64209
- await (0, import_promises38.chmod)(options.socketPath, 384);
64395
+ await (0, import_promises39.chmod)(options.socketPath, 384);
64210
64396
  const git = options.certificates === null ? null : await startGitListener(options.certificates, relay);
64211
64397
  options.log.info("github_proxy.listening", {
64212
64398
  socketPath: options.socketPath,
@@ -64225,7 +64411,7 @@ async function startGitHubProxy(options) {
64225
64411
 
64226
64412
  // src/capabilities/mcp-config/mcp-config.ts
64227
64413
  var import_node_crypto17 = require("crypto");
64228
- var import_promises39 = require("fs/promises");
64414
+ var import_promises40 = require("fs/promises");
64229
64415
  var import_node_path26 = require("path");
64230
64416
 
64231
64417
  // ../../node_modules/smol-toml/dist/error.js
@@ -65175,7 +65361,7 @@ function isCredentialFreeAlanEntry(entry, endpoint) {
65175
65361
  }
65176
65362
  async function isInstalled(cli, home) {
65177
65363
  try {
65178
- return (await (0, import_promises39.stat)((0, import_node_path26.join)(home, cli.guardDir))).isDirectory();
65364
+ return (await (0, import_promises40.stat)((0, import_node_path26.join)(home, cli.guardDir))).isDirectory();
65179
65365
  } catch (error62) {
65180
65366
  if (errorCode2(error62) === "ENOENT") return false;
65181
65367
  throw error62;
@@ -65183,7 +65369,7 @@ async function isInstalled(cli, home) {
65183
65369
  }
65184
65370
  async function readText3(path4) {
65185
65371
  try {
65186
- return await (0, import_promises39.readFile)(path4, "utf8");
65372
+ return await (0, import_promises40.readFile)(path4, "utf8");
65187
65373
  } catch (error62) {
65188
65374
  if (errorCode2(error62) === "ENOENT") return null;
65189
65375
  throw error62;
@@ -65210,10 +65396,10 @@ async function readConfig(cli, home) {
65210
65396
  async function writeConfig(path4, text3) {
65211
65397
  const temporary = `${path4}.alan-${(0, import_node_crypto17.randomUUID)()}.tmp`;
65212
65398
  try {
65213
- await (0, import_promises39.writeFile)(temporary, text3, { encoding: "utf8", mode: 384, flag: "wx" });
65214
- await (0, import_promises39.rename)(temporary, path4);
65399
+ await (0, import_promises40.writeFile)(temporary, text3, { encoding: "utf8", mode: 384, flag: "wx" });
65400
+ await (0, import_promises40.rename)(temporary, path4);
65215
65401
  } finally {
65216
- await (0, import_promises39.rm)(temporary, { force: true });
65402
+ await (0, import_promises40.rm)(temporary, { force: true });
65217
65403
  }
65218
65404
  }
65219
65405
  async function editCli(cli, home, endpoint, edit) {
@@ -65291,7 +65477,7 @@ async function inspectAlanMcp(options) {
65291
65477
  }
65292
65478
 
65293
65479
  // src/capabilities/models/opencode-models.ts
65294
- var import_promises40 = require("fs/promises");
65480
+ var import_promises41 = require("fs/promises");
65295
65481
  var import_node_path27 = require("path");
65296
65482
  init_runtime_v2();
65297
65483
  init_zod();
@@ -65607,7 +65793,7 @@ async function readOpenCodeCatalogueCache(env) {
65607
65793
  const home = env.HOME?.trim();
65608
65794
  const cacheHome = env.XDG_CACHE_HOME?.trim() || (home ? (0, import_node_path27.join)(home, ".cache") : "");
65609
65795
  if (cacheHome === "") return null;
65610
- const text3 = await (0, import_promises40.readFile)((0, import_node_path27.join)(cacheHome, ...CATALOGUE_CACHE_SEGMENTS), "utf8").catch(
65796
+ const text3 = await (0, import_promises41.readFile)((0, import_node_path27.join)(cacheHome, ...CATALOGUE_CACHE_SEGMENTS), "utf8").catch(
65611
65797
  () => void 0
65612
65798
  );
65613
65799
  if (text3 === void 0) return null;
@@ -65726,7 +65912,7 @@ async function discoverModels(backendKind, executable, env, capture) {
65726
65912
  }
65727
65913
 
65728
65914
  // src/capabilities/models/opencode-entitlement.ts
65729
- var import_promises41 = require("fs/promises");
65915
+ var import_promises42 = require("fs/promises");
65730
65916
  var import_node_os4 = require("os");
65731
65917
  var import_node_path28 = require("path");
65732
65918
  init_agent2();
@@ -65736,7 +65922,7 @@ async function readOpenCodeZenCredential(env) {
65736
65922
  const injected = env.OPENCODE_AUTH_CONTENT?.trim();
65737
65923
  if (injected) return readZenCredentialFromAuthDocument(injected);
65738
65924
  const dataHome = env.XDG_DATA_HOME?.trim() || (0, import_node_path28.join)(env.HOME?.trim() || (0, import_node_os4.homedir)(), ".local", "share");
65739
- const document2 = await (0, import_promises41.readFile)((0, import_node_path28.join)(dataHome, "opencode", "auth.json"), "utf8").catch(
65925
+ const document2 = await (0, import_promises42.readFile)((0, import_node_path28.join)(dataHome, "opencode", "auth.json"), "utf8").catch(
65740
65926
  () => void 0
65741
65927
  );
65742
65928
  return readZenCredentialFromAuthDocument(document2);
@@ -66179,7 +66365,7 @@ function nextAlanBoundary(entry, inFlightFrom) {
66179
66365
  }
66180
66366
 
66181
66367
  // src/capabilities/native-ingest/pass.ts
66182
- var import_promises43 = require("fs/promises");
66368
+ var import_promises44 = require("fs/promises");
66183
66369
 
66184
66370
  // src/capabilities/native-ingest/ports.ts
66185
66371
  var NativeRequestFailure = class extends Error {
@@ -66317,7 +66503,7 @@ function reconcileTranscriptIdentity(entry, transcriptPath, identity, size) {
66317
66503
 
66318
66504
  // src/capabilities/native-ingest/transcript-window.ts
66319
66505
  var import_node_crypto18 = require("crypto");
66320
- var import_promises42 = require("fs/promises");
66506
+ var import_promises43 = require("fs/promises");
66321
66507
  init_acp3();
66322
66508
  init_claude();
66323
66509
  init_codex();
@@ -66372,7 +66558,7 @@ async function findRecordEnd(handle, from, size) {
66372
66558
  return null;
66373
66559
  }
66374
66560
  async function readTranscriptWindow(path4, offset, limits) {
66375
- const handle = await (0, import_promises42.open)(path4, "r");
66561
+ const handle = await (0, import_promises43.open)(path4, "r");
66376
66562
  try {
66377
66563
  const stats = await handle.stat({ bigint: true });
66378
66564
  const size = Number(stats.size);
@@ -66839,7 +67025,7 @@ async function runPass(ctx, worker) {
66839
67025
  });
66840
67026
  if (signal.ending) ctx.log.info("native_ingest.closed", workerFields(worker));
66841
67027
  }
66842
- const current = await (0, import_promises43.stat)(worker.latest.transcriptPath).catch(() => void 0);
67028
+ const current = await (0, import_promises44.stat)(worker.latest.transcriptPath).catch(() => void 0);
66843
67029
  return { grewDuringPass: current !== void 0 && current.size > state.lastSize };
66844
67030
  }
66845
67031
 
@@ -67196,7 +67382,7 @@ init_alan_code();
67196
67382
 
67197
67383
  // src/capabilities/providers/commands.ts
67198
67384
  var import_node_fs13 = require("fs");
67199
- var import_promises44 = require("fs/promises");
67385
+ var import_promises45 = require("fs/promises");
67200
67386
  var import_node_path34 = require("path");
67201
67387
  var PROVIDER_COMMANDS = [
67202
67388
  // The engine, not a CLI of its own: `resolveProviderExecutable` finds the bundled one first.
@@ -67232,8 +67418,8 @@ function pathDelimiter(platform3) {
67232
67418
  }
67233
67419
  async function isRunnable(path4, platform3) {
67234
67420
  try {
67235
- if (!(await (0, import_promises44.stat)(path4)).isFile()) return false;
67236
- if (platform3 !== "win32") await (0, import_promises44.access)(path4, import_node_fs13.constants.X_OK);
67421
+ if (!(await (0, import_promises45.stat)(path4)).isFile()) return false;
67422
+ if (platform3 !== "win32") await (0, import_promises45.access)(path4, import_node_fs13.constants.X_OK);
67237
67423
  return true;
67238
67424
  } catch {
67239
67425
  return false;
@@ -67298,6 +67484,9 @@ function alanCodeProviderModels() {
67298
67484
  var import_node_child_process11 = require("child_process");
67299
67485
  var DEFAULT_TIMEOUT_MS2 = 5e3;
67300
67486
  var DEFAULT_MAX_BYTES = 1024 * 1024;
67487
+ var STOP_TIMEOUT_MS = 3e4;
67488
+ var ProbeShutdownError = class extends Error {
67489
+ };
67301
67490
  function withWindowsHelper(env) {
67302
67491
  const helper = windowsHelperPath();
67303
67492
  return helper === null ? env : { ...env, ALAN_WINHELPER_PATH: helper };
@@ -67324,16 +67513,19 @@ function directLaunch(command, args, options) {
67324
67513
  }
67325
67514
  }
67326
67515
  function captureProbe(command, args, options) {
67516
+ if (options.signal?.aborted) {
67517
+ return Promise.resolve({ stdout: "", stderr: "", exitCode: void 0, failure: "cancelled" });
67518
+ }
67327
67519
  const platform3 = options.platform ?? process.platform;
67328
67520
  const launch = directLaunch(command, args, options);
67329
67521
  if (launch === void 0) return Promise.resolve({ stdout: "", stderr: "", exitCode: void 0 });
67330
67522
  const env = platform3 === "win32" ? withWindowsHelper(canonicalWindowsEnvironment(options.env)) : options.env;
67331
- return new Promise((resolve14) => {
67523
+ return new Promise((resolve14, reject) => {
67332
67524
  const limit = options.maxBufferBytes ?? DEFAULT_MAX_BYTES;
67333
67525
  const stdout = [];
67334
67526
  const stderr = [];
67335
67527
  let bytes = 0;
67336
- let overflowed = false;
67528
+ let failure7;
67337
67529
  const windowsChild = platform3 === "win32" ? spawnInWindowsJob(planSpawn({ command, args, env, platform: platform3 }), {
67338
67530
  cwd: process.cwd(),
67339
67531
  env
@@ -67358,59 +67550,87 @@ function captureProbe(command, args, options) {
67358
67550
  };
67359
67551
  let settled2 = false;
67360
67552
  const deadlineController = new AbortController();
67553
+ const startupController = new AbortController();
67554
+ const stopController = new AbortController();
67555
+ const dispose = () => {
67556
+ deadlineController.abort();
67557
+ startupController.abort();
67558
+ stopController.abort();
67559
+ options.signal?.removeEventListener("abort", abort);
67560
+ };
67361
67561
  const finish = (exitCode) => {
67362
67562
  if (settled2) return;
67363
67563
  settled2 = true;
67364
- deadlineController.abort();
67365
- options.signal?.removeEventListener("abort", abort);
67564
+ dispose();
67366
67565
  resolve14({
67367
67566
  stdout: Buffer.concat(stdout).toString("utf8"),
67368
67567
  stderr: Buffer.concat(stderr).toString("utf8"),
67369
- exitCode
67568
+ exitCode,
67569
+ ...failure7 === void 0 ? {} : { failure: failure7 }
67370
67570
  });
67371
67571
  };
67372
- void systemClock.sleep(options.timeoutMs ?? DEFAULT_TIMEOUT_MS2, deadlineController.signal).then(
67373
- () => {
67374
- terminate2();
67375
- child.stdout.destroy();
67376
- child.stderr.destroy();
67377
- finish(void 0);
67378
- },
67379
- () => void 0
67380
- );
67381
- const abort = () => {
67572
+ const stop = (reason) => {
67573
+ if (settled2 || failure7 !== void 0) return;
67574
+ failure7 = reason;
67575
+ deadlineController.abort();
67576
+ startupController.abort();
67382
67577
  terminate2();
67383
67578
  child.stdout.destroy();
67384
67579
  child.stderr.destroy();
67385
- finish(void 0);
67580
+ void systemClock.sleep(STOP_TIMEOUT_MS, stopController.signal).then(
67581
+ () => {
67582
+ if (settled2) return;
67583
+ settled2 = true;
67584
+ dispose();
67585
+ reject(
67586
+ new ProbeShutdownError(`${reason}; process did not close within ${STOP_TIMEOUT_MS}ms`)
67587
+ );
67588
+ },
67589
+ () => void 0
67590
+ );
67591
+ };
67592
+ const abort = () => stop("cancelled");
67593
+ const startDeadline = () => {
67594
+ if (settled2 || failure7 !== void 0) return;
67595
+ const timeout = options.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
67596
+ void systemClock.sleep(timeout, deadlineController.signal).then(
67597
+ () => stop(`command timed out after ${timeout}ms`),
67598
+ () => void 0
67599
+ );
67386
67600
  };
67387
- options.signal?.addEventListener("abort", abort, { once: true });
67388
- if (options.signal?.aborted) abort();
67389
67601
  const collect = (into) => (chunk) => {
67602
+ if (failure7 !== void 0) return;
67390
67603
  bytes += chunk.length;
67391
67604
  if (bytes > limit) {
67392
- overflowed = true;
67393
- terminate2();
67394
- finish(void 0);
67605
+ stop(`output exceeded ${limit} bytes`);
67395
67606
  return;
67396
67607
  }
67397
67608
  into.push(chunk);
67398
67609
  };
67399
67610
  child.stdout.on("data", collect(stdout));
67400
67611
  child.stderr.on("data", collect(stderr));
67401
- child.once("error", () => finish(void 0));
67612
+ child.once("error", (error62) => stop(`launch failed: ${error62.message}`));
67402
67613
  child.once(
67403
67614
  "close",
67404
- (code, signal) => finish(overflowed || signal !== null || code === null ? void 0 : code)
67615
+ (code, signal) => finish(failure7 !== void 0 || signal !== null || code === null ? void 0 : code)
67405
67616
  );
67406
67617
  if (windowsChild !== void 0) {
67407
- void waitForWindowsJob(windowsChild, command).catch(() => finish(void 0));
67408
- }
67618
+ void waitForWindowsJob(windowsChild, command, {
67619
+ timeoutMs: options.startupTimeoutMs,
67620
+ signal: startupController.signal
67621
+ }).then(startDeadline, (error62) => {
67622
+ if (!settled2 && failure7 === void 0) {
67623
+ stop(error62 instanceof Error ? error62.message : "Windows startup failed");
67624
+ }
67625
+ });
67626
+ } else startDeadline();
67627
+ options.signal?.addEventListener("abort", abort, { once: true });
67628
+ if (options.signal?.aborted) abort();
67409
67629
  });
67410
67630
  }
67411
67631
 
67412
67632
  // src/capabilities/providers/inventory.ts
67413
- var import_promises45 = require("fs/promises");
67633
+ var import_promises46 = require("fs/promises");
67414
67634
  var import_node_os5 = require("os");
67415
67635
  init_runtime_v2();
67416
67636
 
@@ -67870,8 +68090,8 @@ async function executablesFingerprint(env, platform3) {
67870
68090
  const executable = await resolveProviderExecutable(provider4, env, platform3);
67871
68091
  if (executable === null) return `${provider4.backendKind}:-`;
67872
68092
  try {
67873
- const target = await (0, import_promises45.realpath)(executable);
67874
- const { size, mtimeMs } = await (0, import_promises45.stat)(target);
68093
+ const target = await (0, import_promises46.realpath)(executable);
68094
+ const { size, mtimeMs } = await (0, import_promises46.stat)(target);
67875
68095
  return `${provider4.backendKind}:${target}:${size}:${mtimeMs}`;
67876
68096
  } catch {
67877
68097
  return `${provider4.backendKind}:${executable}:?`;
@@ -68108,15 +68328,15 @@ async function readLoginShellPath(env, capture) {
68108
68328
  });
68109
68329
  return between(login.stdout);
68110
68330
  }
68111
- function appendPathDirectories(first, extra, delimiter) {
68112
- const directories = first.split(delimiter).filter((directory) => directory.length > 0);
68331
+ function appendPathDirectories(first, extra, delimiter2) {
68332
+ const directories = first.split(delimiter2).filter((directory) => directory.length > 0);
68113
68333
  const seen = new Set(directories);
68114
68334
  for (const directory of extra) {
68115
68335
  if (directory.length === 0 || seen.has(directory)) continue;
68116
68336
  seen.add(directory);
68117
68337
  directories.push(directory);
68118
68338
  }
68119
- return directories.join(delimiter);
68339
+ return directories.join(delimiter2);
68120
68340
  }
68121
68341
  async function readLastKnownGood(file2) {
68122
68342
  if (file2 === void 0) return null;
@@ -68145,15 +68365,15 @@ async function resolveCliEnvironmentDetailed(options) {
68145
68365
  if (loginPath !== null) await rememberLastKnownGood(options.lastKnownGoodFile, loginPath);
68146
68366
  const lastKnownGood = loginPath === null ? await readLastKnownGood(options.lastKnownGoodFile) : null;
68147
68367
  const shellPath = loginPath ?? lastKnownGood;
68148
- const delimiter = pathDelimiter(platform3);
68368
+ const delimiter2 = pathDelimiter(platform3);
68149
68369
  const home = envValue(env, "HOME");
68150
68370
  const versionManagers = home.length > 0 ? resolveVersionManagerBinDirs(home, platform3) : [];
68151
68371
  const extra = [
68152
- ...shellPath?.split(delimiter) ?? [],
68372
+ ...shellPath?.split(delimiter2) ?? [],
68153
68373
  ...installerDirectories(home, platform3),
68154
68374
  ...versionManagers
68155
68375
  ];
68156
- const combined = appendPathDirectories(envValue(env, "PATH"), extra, delimiter);
68376
+ const combined = appendPathDirectories(envValue(env, "PATH"), extra, delimiter2);
68157
68377
  const key = Object.keys(env).find((candidate) => candidate.toUpperCase() === "PATH") ?? "PATH";
68158
68378
  return {
68159
68379
  env: { ...env, [key]: promoteUserBinDirs(combined, home, versionManagers) },
@@ -68188,7 +68408,7 @@ async function openCliEnvironment(options) {
68188
68408
 
68189
68409
  // src/capabilities/providers/managed.ts
68190
68410
  var import_node_crypto20 = require("crypto");
68191
- var import_promises46 = require("fs/promises");
68411
+ var import_promises47 = require("fs/promises");
68192
68412
  var import_node_path40 = require("path");
68193
68413
  init_zod();
68194
68414
  var PACKAGES = {
@@ -68203,9 +68423,26 @@ var PACKAGES = {
68203
68423
  };
68204
68424
  var VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?$/;
68205
68425
  var selectedSchema = external_exports.record(external_exports.string(), external_exports.string());
68426
+ var MANAGED_PROBE_TIMEOUT_MS = 6e4;
68427
+ async function cleanFailedInstall(staged, error62) {
68428
+ if (error62 instanceof ProbeShutdownError) {
68429
+ throw new Error(`${error62.message}; retained staging directory: ${staged}`, { cause: error62 });
68430
+ }
68431
+ try {
68432
+ await (0, import_promises47.rm)(staged, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
68433
+ } catch (cleanupError) {
68434
+ const message2 = error62 instanceof Error ? error62.message : String(error62);
68435
+ throw new AggregateError(
68436
+ [error62, cleanupError],
68437
+ `${message2}; staging cleanup also failed: ${staged}`,
68438
+ { cause: error62 }
68439
+ );
68440
+ }
68441
+ throw error62;
68442
+ }
68206
68443
  async function readManagedProviderVersion(file2, backendKind) {
68207
68444
  try {
68208
- const selected = selectedSchema.parse(JSON.parse(await (0, import_promises46.readFile)(file2, "utf8")));
68445
+ const selected = selectedSchema.parse(JSON.parse(await (0, import_promises47.readFile)(file2, "utf8")));
68209
68446
  const version2 = selected[backendKind];
68210
68447
  return version2 !== void 0 && VERSION.test(version2) ? version2 : null;
68211
68448
  } catch {
@@ -68272,7 +68509,7 @@ function selection(root, backendKind, version2) {
68272
68509
  };
68273
68510
  }
68274
68511
  async function runnable(file2) {
68275
- return (0, import_promises46.stat)(file2).then(
68512
+ return (0, import_promises47.stat)(file2).then(
68276
68513
  (value2) => value2.isFile(),
68277
68514
  () => false
68278
68515
  );
@@ -68315,20 +68552,21 @@ function createManagedProviderClis(options) {
68315
68552
  return next;
68316
68553
  };
68317
68554
  const persist = async () => {
68318
- await (0, import_promises46.mkdir)(options.root, { recursive: true, mode: 448 });
68555
+ await (0, import_promises47.mkdir)(options.root, { recursive: true, mode: 448 });
68319
68556
  const staged = `${file2}.${(0, import_node_crypto20.randomUUID)()}`;
68320
68557
  try {
68321
- await (0, import_promises46.writeFile)(staged, JSON.stringify(state), { mode: 384 });
68322
- await (0, import_promises46.rename)(staged, file2);
68558
+ await (0, import_promises47.writeFile)(staged, JSON.stringify(state), { mode: 384 });
68559
+ await (0, import_promises47.rename)(staged, file2);
68323
68560
  } finally {
68324
- await (0, import_promises46.rm)(staged, { force: true });
68561
+ await (0, import_promises47.rm)(staged, { force: true });
68325
68562
  }
68326
68563
  };
68327
- const activate = async (backendKind, version2) => {
68564
+ const activate = async (backendKind, version2, signal) => {
68328
68565
  const next = selection(options.root, backendKind, checkedVersion(version2));
68329
- if (!await runnable(next.executable) || !await options.probe(next.executable, backendKind)) {
68566
+ if (!await runnable(next.executable) || !await options.probe(next.executable, backendKind, signal)) {
68330
68567
  throw new Error(`${backendKind}@${version2} failed its executable probe`);
68331
68568
  }
68569
+ signal?.throwIfAborted();
68332
68570
  const previous = state[backendKind];
68333
68571
  state[backendKind] = version2;
68334
68572
  try {
@@ -68343,7 +68581,7 @@ function createManagedProviderClis(options) {
68343
68581
  return {
68344
68582
  selectionFile: file2,
68345
68583
  load: async () => {
68346
- const raw = await (0, import_promises46.readFile)(file2, "utf8").catch((error62) => {
68584
+ const raw = await (0, import_promises47.readFile)(file2, "utf8").catch((error62) => {
68347
68585
  if (error62 instanceof Error && "code" in error62 && error62.code === "ENOENT") return "{}";
68348
68586
  throw error62;
68349
68587
  });
@@ -68351,7 +68589,7 @@ function createManagedProviderClis(options) {
68351
68589
  try {
68352
68590
  parsed = selectedSchema.parse(JSON.parse(raw));
68353
68591
  } catch {
68354
- await (0, import_promises46.rename)(file2, `${file2}.invalid.${(0, import_node_crypto20.randomUUID)()}`).catch(() => void 0);
68592
+ await (0, import_promises47.rename)(file2, `${file2}.invalid.${(0, import_node_crypto20.randomUUID)()}`).catch(() => void 0);
68355
68593
  return;
68356
68594
  }
68357
68595
  for (const [backendKind, version2] of Object.entries(parsed)) {
@@ -68371,7 +68609,7 @@ function createManagedProviderClis(options) {
68371
68609
  const groups = await Promise.all(
68372
68610
  Object.keys(PACKAGES).map(async (backendKind) => {
68373
68611
  const directory = (0, import_node_path40.join)(options.root, "versions", backendKind);
68374
- const versions = await (0, import_promises46.readdir)(directory).catch((error62) => {
68612
+ const versions = await (0, import_promises47.readdir)(directory).catch((error62) => {
68375
68613
  if (error62 instanceof Error && "code" in error62 && error62.code === "ENOENT") return [];
68376
68614
  throw error62;
68377
68615
  });
@@ -68403,26 +68641,28 @@ function createManagedProviderClis(options) {
68403
68641
  return results;
68404
68642
  },
68405
68643
  install: (backendKind, version2, signal) => serialize(async () => {
68644
+ signal?.throwIfAborted();
68406
68645
  const provider4 = packageFor(backendKind);
68407
68646
  const exact = await installVersion2(backendKind, version2, options, signal);
68408
68647
  const target = (0, import_node_path40.join)(options.root, "versions", backendKind, exact);
68409
68648
  const existing = selection(options.root, backendKind, exact);
68410
- if (!await runnable(existing.executable) || !await options.probe(existing.executable, backendKind)) {
68411
- await (0, import_promises46.mkdir)((0, import_node_path40.dirname)(target), { recursive: true, mode: 448 });
68649
+ if (!await runnable(existing.executable) || !await options.probe(existing.executable, backendKind, signal)) {
68650
+ await (0, import_promises47.mkdir)((0, import_node_path40.dirname)(target), { recursive: true, mode: 448 });
68412
68651
  const staged = `${target}.${(0, import_node_crypto20.randomUUID)()}`;
68413
68652
  try {
68414
68653
  await options.installPackage(provider4.name, exact, staged, provider4.command, signal);
68415
68654
  const built = (0, import_node_path40.join)(staged, "node_modules", ".bin", provider4.command);
68416
- if (!await runnable(built) || !await options.probe(built, backendKind)) {
68655
+ if (!await runnable(built) || !await options.probe(built, backendKind, signal)) {
68417
68656
  throw new Error(`${backendKind}@${exact} failed its executable probe`);
68418
68657
  }
68419
- await (0, import_promises46.rm)(target, { recursive: true, force: true });
68420
- await (0, import_promises46.rename)(staged, target);
68421
- } finally {
68422
- await (0, import_promises46.rm)(staged, { recursive: true, force: true });
68658
+ signal?.throwIfAborted();
68659
+ await (0, import_promises47.rm)(target, { recursive: true, force: true });
68660
+ await (0, import_promises47.rename)(staged, target);
68661
+ } catch (error62) {
68662
+ await cleanFailedInstall(staged, error62);
68423
68663
  }
68424
68664
  }
68425
- return activate(backendKind, exact);
68665
+ return activate(backendKind, exact, signal);
68426
68666
  }),
68427
68667
  select: (backendKind, version2) => serialize(() => activate(backendKind, version2)),
68428
68668
  useExternal: (backendKind) => serialize(async () => {
@@ -68472,7 +68712,7 @@ function createNpmPackageInstaller(options) {
68472
68712
  const output2 = `${result.stdout}
68473
68713
  ${result.stderr}`.trim().slice(-8e3);
68474
68714
  throw new Error(
68475
- `npm install failed (${result.exitCode ?? "timeout, cancellation or launch"}): ${output2}`
68715
+ `npm install failed (${result.failure ?? result.exitCode ?? "timeout, cancellation or launch"}): ${output2}`
68476
68716
  );
68477
68717
  }
68478
68718
  };
@@ -68498,10 +68738,12 @@ function parseNpmVersion(output2, packageName) {
68498
68738
  if (latest === void 0) throw new Error(`No ${packageName} version found`);
68499
68739
  return checkedVersion(latest);
68500
68740
  }
68501
- async function probeManagedProvider(executable, backendKind, env) {
68741
+ async function probeManagedProvider(executable, backendKind, env, signal) {
68502
68742
  const result = await captureProbe(executable, ["--version"], {
68503
68743
  env: { ...env },
68504
- timeoutMs: 5e3
68744
+ signal,
68745
+ startupTimeoutMs: MANAGED_PROBE_TIMEOUT_MS,
68746
+ timeoutMs: MANAGED_PROBE_TIMEOUT_MS
68505
68747
  });
68506
68748
  if (result.exitCode !== 0) return false;
68507
68749
  if (backendKind === "opencode_serve" && !/\b1\.\d+\.\d+\b/.test(result.stdout)) return false;
@@ -68515,30 +68757,32 @@ async function probeManagedProvider(executable, backendKind, env) {
68515
68757
  if (required2 === void 0) return true;
68516
68758
  const help = await captureProbe(executable, required2.args, {
68517
68759
  env: { ...env },
68518
- timeoutMs: 5e3
68760
+ signal,
68761
+ startupTimeoutMs: MANAGED_PROBE_TIMEOUT_MS,
68762
+ timeoutMs: MANAGED_PROBE_TIMEOUT_MS
68519
68763
  });
68520
68764
  return help.exitCode === 0 && required2.pattern.test(`${help.stdout}
68521
68765
  ${help.stderr}`);
68522
68766
  }
68523
68767
 
68524
68768
  // src/capabilities/skills/legacy-cleanup.ts
68525
- var import_promises47 = require("fs/promises");
68769
+ var import_promises48 = require("fs/promises");
68526
68770
  var import_node_path41 = require("path");
68527
68771
  var LEGACY_FOLDER = /--(?:alan-(?:production|staging|local(?:-[0-9a-f]{12})?)|[0-9a-f]{8})$/;
68528
68772
  var MANAGED_MARKER = ".alan-managed.json";
68529
68773
  var COMPATIBILITY_MARKER = ".alan-compatibility.json";
68530
68774
  async function listEntries(directory) {
68531
- return (0, import_promises47.readdir)(directory, { withFileTypes: true }).catch(() => []);
68775
+ return (0, import_promises48.readdir)(directory, { withFileTypes: true }).catch(() => []);
68532
68776
  }
68533
68777
  async function isRegularFile(path4) {
68534
- return (0, import_promises47.lstat)(path4).then(
68778
+ return (0, import_promises48.lstat)(path4).then(
68535
68779
  (stats) => stats.isFile(),
68536
68780
  () => false
68537
68781
  );
68538
68782
  }
68539
68783
  async function isMissing(path4) {
68540
68784
  try {
68541
- await (0, import_promises47.lstat)(path4);
68785
+ await (0, import_promises48.lstat)(path4);
68542
68786
  return false;
68543
68787
  } catch (error62) {
68544
68788
  return errnoCode(error62) === "ENOENT";
@@ -68546,15 +68790,15 @@ async function isMissing(path4) {
68546
68790
  }
68547
68791
  async function removeLink(path4) {
68548
68792
  try {
68549
- await (0, import_promises47.unlink)(path4);
68793
+ await (0, import_promises48.unlink)(path4);
68550
68794
  } catch (error62) {
68551
68795
  const code = errnoCode(error62);
68552
68796
  if (code !== "EPERM" && code !== "EISDIR") throw error62;
68553
- await (0, import_promises47.rmdir)(path4);
68797
+ await (0, import_promises48.rmdir)(path4);
68554
68798
  }
68555
68799
  }
68556
68800
  async function isOrphanedLegacyLink(agentsDir, path4, removed) {
68557
- const target = await (0, import_promises47.readlink)(path4).catch(() => null);
68801
+ const target = await (0, import_promises48.readlink)(path4).catch(() => null);
68558
68802
  if (target === null) return false;
68559
68803
  const absolute = (0, import_node_path41.resolve)((0, import_node_path41.dirname)(path4), target);
68560
68804
  return (0, import_node_path41.dirname)(absolute) === agentsDir && (removed.has(absolute) || LEGACY_FOLDER.test((0, import_node_path41.basename)(absolute))) && await isMissing(absolute);
@@ -68564,7 +68808,7 @@ async function removeLegacyPackages(agentsDir, attempt2) {
68564
68808
  for (const entry of await listEntries(agentsDir)) {
68565
68809
  const path4 = (0, import_node_path41.join)(agentsDir, entry.name);
68566
68810
  if (!entry.isDirectory() || !await isRegularFile((0, import_node_path41.join)(path4, MANAGED_MARKER))) continue;
68567
- if (await attempt2(path4, () => (0, import_promises47.rm)(path4, { recursive: true, force: true }))) removed.push(path4);
68811
+ if (await attempt2(path4, () => (0, import_promises48.rm)(path4, { recursive: true, force: true }))) removed.push(path4);
68568
68812
  }
68569
68813
  return removed;
68570
68814
  }
@@ -68578,7 +68822,7 @@ async function removeLegacyClaudeEntries(claudeDir, agentsDir, removedPackages,
68578
68822
  for (const entry of await listEntries(claudeDir)) {
68579
68823
  const path4 = (0, import_node_path41.join)(claudeDir, entry.name);
68580
68824
  if (!await isLegacyClaudeEntry(agentsDir, path4, entry, removedSet)) continue;
68581
- const remove = entry.isSymbolicLink() ? () => removeLink(path4) : () => (0, import_promises47.rm)(path4, { recursive: true, force: true });
68825
+ const remove = entry.isSymbolicLink() ? () => removeLink(path4) : () => (0, import_promises48.rm)(path4, { recursive: true, force: true });
68582
68826
  if (await attempt2(path4, remove)) removed.push(path4);
68583
68827
  }
68584
68828
  return removed;
@@ -68603,18 +68847,18 @@ async function removeLegacySkillFolders(home) {
68603
68847
  attempt2
68604
68848
  );
68605
68849
  const profiles = (0, import_node_path41.join)(home, ".alan", "skills", "profiles");
68606
- const profilesRemoved = !await isMissing(profiles) && await attempt2(profiles, () => (0, import_promises47.rm)(profiles, { recursive: true, force: true }));
68850
+ const profilesRemoved = !await isMissing(profiles) && await attempt2(profiles, () => (0, import_promises48.rm)(profiles, { recursive: true, force: true }));
68607
68851
  return { packages, links, profilesRemoved, failed };
68608
68852
  }
68609
68853
 
68610
68854
  // src/capabilities/skills/local-preview.ts
68611
- var import_promises52 = require("fs/promises");
68855
+ var import_promises53 = require("fs/promises");
68612
68856
  var import_node_path46 = __toESM(require("path"));
68613
68857
 
68614
68858
  // ../shared/dist/node/skill-package.js
68615
68859
  var import_node_buffer = require("buffer");
68616
68860
  var import_node_crypto21 = require("crypto");
68617
- var import_promises48 = require("fs/promises");
68861
+ var import_promises49 = require("fs/promises");
68618
68862
  var import_node_path42 = require("path");
68619
68863
  var import_yaml = __toESM(require_dist(), 1);
68620
68864
  init_contracts();
@@ -68710,11 +68954,11 @@ async function readSkillPackageFile(packageRoot, path4, expectedSha256) {
68710
68954
  if (!normalizedPath || normalizedPath !== path4 || normalizedPath.includes("\\") || components.some((component) => !component || component === "." || component === "..")) {
68711
68955
  throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${path4}`, path4);
68712
68956
  }
68713
- const absolutePath = await (0, import_promises48.realpath)((0, import_node_path42.resolve)(root, ...components)).catch(() => null);
68957
+ const absolutePath = await (0, import_promises49.realpath)((0, import_node_path42.resolve)(root, ...components)).catch(() => null);
68714
68958
  if (!absolutePath || normalizeRelativePath(root, absolutePath) !== normalizedPath) {
68715
68959
  throw new SkillPackageError("INVALID_PATH", `Skill package file was not found: ${path4}`, path4);
68716
68960
  }
68717
- const entryStat = await (0, import_promises48.lstat)(absolutePath);
68961
+ const entryStat = await (0, import_promises49.lstat)(absolutePath);
68718
68962
  if (!entryStat.isFile()) {
68719
68963
  throw new SkillPackageError("SPECIAL_FILE_BLOCKED", `Only regular files are allowed in Skill packages: ${path4}`, path4);
68720
68964
  }
@@ -68731,11 +68975,11 @@ async function readSkillPackageFile(packageRoot, path4, expectedSha256) {
68731
68975
  return { file: read.manifest, bytes: read.bytes };
68732
68976
  }
68733
68977
  async function requirePackageRoot(packageRoot) {
68734
- const root = await (0, import_promises48.realpath)((0, import_node_path42.resolve)(packageRoot)).catch(() => null);
68978
+ const root = await (0, import_promises49.realpath)((0, import_node_path42.resolve)(packageRoot)).catch(() => null);
68735
68979
  if (!root) {
68736
68980
  throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package directory does not exist");
68737
68981
  }
68738
- const rootStat = await (0, import_promises48.lstat)(root);
68982
+ const rootStat = await (0, import_promises49.lstat)(root);
68739
68983
  if (!rootStat.isDirectory()) {
68740
68984
  throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package root must be a directory");
68741
68985
  }
@@ -68755,13 +68999,13 @@ async function walkPackage(root, ignoredPaths) {
68755
68999
  }
68756
69000
  return files;
68757
69001
  async function walkDirectory(directory) {
68758
- const entries = await (0, import_promises48.readdir)(directory, { withFileTypes: true });
69002
+ const entries = await (0, import_promises49.readdir)(directory, { withFileTypes: true });
68759
69003
  for (const entry of entries) {
68760
69004
  const absolutePath = (0, import_node_path42.resolve)(directory, entry.name);
68761
69005
  const normalizedPath = normalizeRelativePath(root, absolutePath);
68762
69006
  if (isIgnored(normalizedPath, entry.name, entry.isDirectory(), ignored2))
68763
69007
  continue;
68764
- const entryStat = await (0, import_promises48.lstat)(absolutePath);
69008
+ const entryStat = await (0, import_promises49.lstat)(absolutePath);
68765
69009
  if (entryStat.isSymbolicLink()) {
68766
69010
  throw new SkillPackageError("SYMLINK_BLOCKED", `Nested symbolic links are not allowed in Skill packages: ${normalizedPath}`, normalizedPath);
68767
69011
  }
@@ -68870,7 +69114,7 @@ function isSecretPath(path4) {
68870
69114
  return name.endsWith(".private-key.pem") || name.endsWith(".private-key.key");
68871
69115
  }
68872
69116
  async function readPackageFile(file2) {
68873
- const bytes = await (0, import_promises48.readFile)(file2.absolutePath);
69117
+ const bytes = await (0, import_promises49.readFile)(file2.absolutePath);
68874
69118
  return {
68875
69119
  bytes,
68876
69120
  manifest: {
@@ -69042,13 +69286,13 @@ function uint642(value2) {
69042
69286
 
69043
69287
  // src/capabilities/skills/local-sources.ts
69044
69288
  var import_node_crypto23 = require("crypto");
69045
- var import_promises50 = require("fs/promises");
69289
+ var import_promises51 = require("fs/promises");
69046
69290
  var import_node_path44 = __toESM(require("path"));
69047
69291
  init_type_guards();
69048
69292
 
69049
69293
  // src/capabilities/skills/local-scan.ts
69050
69294
  var import_node_crypto22 = require("crypto");
69051
- var import_promises49 = require("fs/promises");
69295
+ var import_promises50 = require("fs/promises");
69052
69296
  var import_node_path43 = __toESM(require("path"));
69053
69297
  var MAX_CANDIDATES = 2e3;
69054
69298
  var MAX_DIAGNOSTICS = 100;
@@ -69169,7 +69413,7 @@ function invalid(resolvedRoot, name, error62) {
69169
69413
  }
69170
69414
  async function scanRootAsPackage(pass, resolvedRoot) {
69171
69415
  if (!await exists3(import_node_path43.default.join(resolvedRoot.directory, "SKILL.md"))) return null;
69172
- const canonical = await (0, import_promises49.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
69416
+ const canonical = await (0, import_promises50.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
69173
69417
  if (isManaged(pass, canonical)) return { candidates: [], diagnostics: [], incomplete: false };
69174
69418
  try {
69175
69419
  const inspected = await inspectCached(pass, canonical, null);
@@ -69199,7 +69443,7 @@ async function scanRoot(pass, resolvedRoot) {
69199
69443
  if (asPackage !== null) return asPackage;
69200
69444
  let entries;
69201
69445
  try {
69202
- entries = await (0, import_promises49.readdir)(resolvedRoot.directory, { withFileTypes: true });
69446
+ entries = await (0, import_promises50.readdir)(resolvedRoot.directory, { withFileTypes: true });
69203
69447
  } catch (error62) {
69204
69448
  const code = errnoCode(error62);
69205
69449
  if (code === "ENOENT" || code === "ENOTDIR") {
@@ -69217,7 +69461,7 @@ async function scanRoot(pass, resolvedRoot) {
69217
69461
  incomplete: true
69218
69462
  };
69219
69463
  }
69220
- const canonicalRoot = await (0, import_promises49.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
69464
+ const canonicalRoot = await (0, import_promises50.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
69221
69465
  const scan = { candidates: [], diagnostics: [], incomplete: false };
69222
69466
  for (const entry of entries) {
69223
69467
  if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
@@ -69229,7 +69473,7 @@ async function scanRoot(pass, resolvedRoot) {
69229
69473
  }
69230
69474
  async function scanEntry(pass, resolvedRoot, canonicalRoot, name) {
69231
69475
  const rootLabel = resolvedRoot.root.label;
69232
- const canonical = await (0, import_promises49.realpath)(import_node_path43.default.join(resolvedRoot.directory, name)).catch(() => null);
69476
+ const canonical = await (0, import_promises50.realpath)(import_node_path43.default.join(resolvedRoot.directory, name)).catch(() => null);
69233
69477
  if (canonical === null) {
69234
69478
  const message2 = `Could not resolve Skill ${name}`;
69235
69479
  return { kind: "diagnostic", diagnostic: { code: "SOURCE_UNREADABLE", message: message2, rootLabel } };
@@ -69314,12 +69558,12 @@ function deduplicateByContent(candidates2) {
69314
69558
  async function fingerprintPackage(root) {
69315
69559
  const hash2 = (0, import_node_crypto22.createHash)("sha256").update("alan-skill-stat-fingerprint-v1\0");
69316
69560
  const visit2 = async (directory, relativeDirectory) => {
69317
- const entries = await (0, import_promises49.readdir)(directory, { withFileTypes: true });
69561
+ const entries = await (0, import_promises50.readdir)(directory, { withFileTypes: true });
69318
69562
  entries.sort((left, right) => Buffer.compare(Buffer.from(left.name), Buffer.from(right.name)));
69319
69563
  for (const entry of entries) {
69320
69564
  const relative6 = relativeDirectory ? `${relativeDirectory}/${entry.name}` : entry.name;
69321
69565
  const absolute = import_node_path43.default.join(directory, entry.name);
69322
- const metadata = await (0, import_promises49.lstat)(absolute);
69566
+ const metadata = await (0, import_promises50.lstat)(absolute);
69323
69567
  const kind = entryKind(entry);
69324
69568
  hash2.update(relative6.normalize("NFC")).update(`\0${kind}\0${metadata.size}\0${metadata.mtimeMs}\0${metadata.mode & 511}\0`);
69325
69569
  if (entry.isDirectory()) await visit2(absolute, relative6);
@@ -69335,7 +69579,7 @@ function entryKind(entry) {
69335
69579
  }
69336
69580
  async function canonicalDirectories(directories) {
69337
69581
  const canonical = await Promise.all(
69338
- directories.map((directory) => (0, import_promises49.realpath)(directory).catch(() => directory))
69582
+ directories.map((directory) => (0, import_promises50.realpath)(directory).catch(() => directory))
69339
69583
  );
69340
69584
  return [...new Set(canonical)];
69341
69585
  }
@@ -69348,7 +69592,7 @@ function isWithinDirectory2(parent, candidate) {
69348
69592
  }
69349
69593
  async function exists3(candidate) {
69350
69594
  try {
69351
- await (0, import_promises49.access)(candidate);
69595
+ await (0, import_promises50.access)(candidate);
69352
69596
  return true;
69353
69597
  } catch {
69354
69598
  return false;
@@ -69356,7 +69600,7 @@ async function exists3(candidate) {
69356
69600
  }
69357
69601
  async function isDirectory3(candidate) {
69358
69602
  try {
69359
- return (await (0, import_promises49.lstat)(candidate)).isDirectory();
69603
+ return (await (0, import_promises50.lstat)(candidate)).isDirectory();
69360
69604
  } catch {
69361
69605
  return false;
69362
69606
  }
@@ -69444,7 +69688,7 @@ async function resolveLocalScanInput(home, context, mode) {
69444
69688
  async function readSkillSourceConfig(home) {
69445
69689
  let content;
69446
69690
  try {
69447
- content = await (0, import_promises50.readFile)(skillSourceConfigPath(home), "utf8");
69691
+ content = await (0, import_promises51.readFile)(skillSourceConfigPath(home), "utf8");
69448
69692
  } catch (error62) {
69449
69693
  if (errnoCode(error62) !== "ENOENT") {
69450
69694
  return { kind: "invalid_config", diagnostic: "~/.alan/config.toml could not be read" };
@@ -69561,7 +69805,7 @@ async function scanLocalSkills(home, context, cache2, mode = "incremental", mana
69561
69805
  }
69562
69806
 
69563
69807
  // src/capabilities/skills/store.ts
69564
- var import_promises51 = require("fs/promises");
69808
+ var import_promises52 = require("fs/promises");
69565
69809
  var import_node_path45 = require("path");
69566
69810
 
69567
69811
  // ../shared/dist/node/alan-skill-identity.js
@@ -69632,7 +69876,7 @@ function writeLocalSkills(layout, file2) {
69632
69876
  async function isLocalSkillCurrent(entry, contentHash, ignoredPaths) {
69633
69877
  if (entry.contentHash !== contentHash) return false;
69634
69878
  try {
69635
- if (await (0, import_promises51.realpath)(entry.path) !== entry.path) return false;
69879
+ if (await (0, import_promises52.realpath)(entry.path) !== entry.path) return false;
69636
69880
  const inspected = await inspectSkillPackage(entry.path, { expectedName: null, ignoredPaths });
69637
69881
  return inspected.contentHash === contentHash;
69638
69882
  } catch {
@@ -69647,7 +69891,7 @@ async function resolveLocalSkill(local, invocation) {
69647
69891
  }
69648
69892
  async function hasSkillFile(directory) {
69649
69893
  try {
69650
- return (await (0, import_promises51.stat)((0, import_node_path45.join)(directory, "SKILL.md"))).isFile();
69894
+ return (await (0, import_promises52.stat)((0, import_node_path45.join)(directory, "SKILL.md"))).isFile();
69651
69895
  } catch {
69652
69896
  return false;
69653
69897
  }
@@ -69704,7 +69948,7 @@ async function resolveSkillInvocations(layout, invocations, baked = "any") {
69704
69948
  async function nativeCandidates(layout) {
69705
69949
  const nativeDir = layout.nativeDir;
69706
69950
  if (nativeDir === null) return [];
69707
- const entries = await (0, import_promises51.readdir)(nativeDir, { withFileTypes: true }).catch(() => []);
69951
+ const entries = await (0, import_promises52.readdir)(nativeDir, { withFileTypes: true }).catch(() => []);
69708
69952
  return entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => ({ directory: (0, import_node_path45.join)(nativeDir, entry.name) }));
69709
69953
  }
69710
69954
  async function availableSkillIndex(layout, sources = { synced: true, native: true }) {
@@ -69802,7 +70046,7 @@ async function readLocalSkillFile(layout, ref) {
69802
70046
  }
69803
70047
  async function isDirectory4(candidate) {
69804
70048
  try {
69805
- return (await (0, import_promises52.stat)(candidate)).isDirectory();
70049
+ return (await (0, import_promises53.stat)(candidate)).isDirectory();
69806
70050
  } catch {
69807
70051
  return false;
69808
70052
  }
@@ -69815,21 +70059,21 @@ async function addSkillSource(home, input2) {
69815
70059
  return { state: "invalid", diagnostic: `${sourcePath} is not a folder` };
69816
70060
  }
69817
70061
  const configPath = skillSourceConfigPath(home);
69818
- await (0, import_promises52.mkdir)(import_node_path46.default.dirname(configPath), { recursive: true, mode: 448 });
69819
- await (0, import_promises52.writeFile)(configPath, DEFAULT_SKILL_CONFIG, { flag: "wx", mode: 384 }).catch(
70062
+ await (0, import_promises53.mkdir)(import_node_path46.default.dirname(configPath), { recursive: true, mode: 448 });
70063
+ await (0, import_promises53.writeFile)(configPath, DEFAULT_SKILL_CONFIG, { flag: "wx", mode: 384 }).catch(
69820
70064
  (error62) => {
69821
70065
  if (errnoCode(error62) !== "EEXIST") throw error62;
69822
70066
  }
69823
70067
  );
69824
70068
  const loaded = await readSkillSourceConfig(home);
69825
70069
  if (loaded.kind === "invalid_config") return { state: "invalid", diagnostic: loaded.diagnostic };
69826
- const canonical = await (0, import_promises52.realpath)(sourcePath).catch(() => sourcePath);
70070
+ const canonical = await (0, import_promises53.realpath)(sourcePath).catch(() => sourcePath);
69827
70071
  for (const source of loaded.config.sources) {
69828
- if (await (0, import_promises52.realpath)(source.path).catch(() => source.path) === canonical) {
70072
+ if (await (0, import_promises53.realpath)(source.path).catch(() => source.path) === canonical) {
69829
70073
  return { state: "already_present", label: source.label };
69830
70074
  }
69831
70075
  }
69832
- const current = await (0, import_promises52.readFile)(configPath, "utf8");
70076
+ const current = await (0, import_promises53.readFile)(configPath, "utf8");
69833
70077
  const block2 = [
69834
70078
  "",
69835
70079
  "[[skills.sources]]",
@@ -69837,7 +70081,7 @@ async function addSkillSource(home, input2) {
69837
70081
  `label = ${JSON.stringify(label)}`,
69838
70082
  ""
69839
70083
  ].join("\n");
69840
- await (0, import_promises52.writeFile)(configPath, `${current.replace(/\n*$/, "\n")}${block2}`, { mode: 384 });
70084
+ await (0, import_promises53.writeFile)(configPath, `${current.replace(/\n*$/, "\n")}${block2}`, { mode: 384 });
69841
70085
  const reloaded = await readSkillSourceConfig(home);
69842
70086
  if (reloaded.kind === "invalid_config") {
69843
70087
  return { state: "invalid", diagnostic: reloaded.diagnostic };
@@ -69846,12 +70090,12 @@ async function addSkillSource(home, input2) {
69846
70090
  }
69847
70091
 
69848
70092
  // src/capabilities/skills/local-upload.ts
69849
- var import_promises54 = require("fs/promises");
70093
+ var import_promises55 = require("fs/promises");
69850
70094
 
69851
70095
  // ../shared/dist/node/skill-bundle.js
69852
70096
  var import_node_buffer2 = require("buffer");
69853
70097
  var import_node_crypto25 = require("crypto");
69854
- var import_promises53 = require("fs/promises");
70098
+ var import_promises54 = require("fs/promises");
69855
70099
  var import_node_path47 = require("path");
69856
70100
  var import_node_stream = require("stream");
69857
70101
  var import_node_zlib = require("zlib");
@@ -69862,7 +70106,7 @@ async function createSkillBundle(packageRoot, options = {}) {
69862
70106
  const archive = (0, import_tar_stream.pack)();
69863
70107
  const tarPromise = collectStream(archive);
69864
70108
  for (const file2 of before.files) {
69865
- const bytes2 = await (0, import_promises53.readFile)((0, import_node_path47.join)(packageRoot, ...file2.path.split("/")));
70109
+ const bytes2 = await (0, import_promises54.readFile)((0, import_node_path47.join)(packageRoot, ...file2.path.split("/")));
69866
70110
  await addArchiveEntry(archive, {
69867
70111
  name: file2.path,
69868
70112
  type: "file",
@@ -69894,7 +70138,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
69894
70138
  throw new Error("Skill archive hash does not match the expected immutable Version");
69895
70139
  }
69896
70140
  const tarBytes = await decompressBounded(archiveBytes);
69897
- await (0, import_promises53.mkdir)(destination, { recursive: false, mode: 448 });
70141
+ await (0, import_promises54.mkdir)(destination, { recursive: false, mode: 448 });
69898
70142
  try {
69899
70143
  await extractTar(tarBytes, destination);
69900
70144
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -69902,7 +70146,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
69902
70146
  throw new Error("Extracted Skill package hash does not match the expected immutable Version");
69903
70147
  }
69904
70148
  } catch (error62) {
69905
- await (0, import_promises53.rm)(destination, { recursive: true, force: true });
70149
+ await (0, import_promises54.rm)(destination, { recursive: true, force: true });
69906
70150
  throw error62;
69907
70151
  }
69908
70152
  }
@@ -69978,8 +70222,8 @@ async function extractEntry(header, stream, destination, limits) {
69978
70222
  throw new Error(`Skill archive file size is invalid: ${path4}`);
69979
70223
  }
69980
70224
  const outputPath = (0, import_node_path47.join)(destination, ...path4.split("/"));
69981
- await (0, import_promises53.mkdir)((0, import_node_path47.dirname)(outputPath), { recursive: true, mode: 448 });
69982
- await (0, import_promises53.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
70225
+ await (0, import_promises54.mkdir)((0, import_node_path47.dirname)(outputPath), { recursive: true, mode: 448 });
70226
+ await (0, import_promises54.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
69983
70227
  }
69984
70228
  function requireSafeArchivePath(value2) {
69985
70229
  const normalized2 = value2.replaceAll("\\", "/").normalize("NFC");
@@ -70005,8 +70249,8 @@ async function publishLocalSkill(options) {
70005
70249
  if (Date.parse(request2.uploadGrant.expiresAt) <= (options.now ?? Date.now())) {
70006
70250
  throw new RuntimeFault("invalid_file", "Skill upload grant expired");
70007
70251
  }
70008
- const folder = await (0, import_promises54.lstat)(entry.path);
70009
- if (!folder.isDirectory() || await (0, import_promises54.realpath)(entry.path) !== entry.path) {
70252
+ const folder = await (0, import_promises55.lstat)(entry.path);
70253
+ if (!folder.isDirectory() || await (0, import_promises55.realpath)(entry.path) !== entry.path) {
70010
70254
  throw new RuntimeFault("invalid_file", "Skill folder moved since the last scan");
70011
70255
  }
70012
70256
  const bundle = await createSkillBundle(entry.path, {
@@ -70035,7 +70279,7 @@ async function publishLocalSkill(options) {
70035
70279
  // src/capabilities/skills/native-index.ts
70036
70280
  var import_node_crypto26 = require("crypto");
70037
70281
  var import_node_fs17 = require("fs");
70038
- var import_promises55 = require("fs/promises");
70282
+ var import_promises56 = require("fs/promises");
70039
70283
  var import_node_path48 = require("path");
70040
70284
  var ALAN_SKILLS_PLUGIN_NAME = "alan";
70041
70285
  var PLUGIN_MANIFEST = `${JSON.stringify(
@@ -70049,32 +70293,32 @@ var PLUGIN_MANIFEST = `${JSON.stringify(
70049
70293
  `;
70050
70294
  async function entryKind2(path4) {
70051
70295
  try {
70052
- return (await (0, import_promises55.lstat)(path4)).isSymbolicLink() ? "link" : "other";
70296
+ return (await (0, import_promises56.lstat)(path4)).isSymbolicLink() ? "link" : "other";
70053
70297
  } catch (error62) {
70054
70298
  if (errnoCode(error62) === "ENOENT") return "missing";
70055
70299
  throw error62;
70056
70300
  }
70057
70301
  }
70058
70302
  async function linkTarget(path4) {
70059
- return (0, import_promises55.readlink)(path4).catch(() => null);
70303
+ return (0, import_promises56.readlink)(path4).catch(() => null);
70060
70304
  }
70061
70305
  async function removeLink2(path4) {
70062
70306
  try {
70063
- await (0, import_promises55.unlink)(path4);
70307
+ await (0, import_promises56.unlink)(path4);
70064
70308
  } catch (error62) {
70065
70309
  const code = errnoCode(error62);
70066
70310
  if (code === "ENOENT") return;
70067
70311
  if (code !== "EPERM" && code !== "EISDIR") throw error62;
70068
- await (0, import_promises55.rmdir)(path4);
70312
+ await (0, import_promises56.rmdir)(path4);
70069
70313
  }
70070
70314
  }
70071
70315
  async function placeLink(plan2, platform3) {
70072
70316
  if (await linkTarget(plan2.path) === plan2.target) return false;
70073
70317
  const staged = (0, import_node_path48.join)((0, import_node_path48.dirname)(plan2.path), `.${(0, import_node_path48.basename)(plan2.path)}.${(0, import_node_crypto26.randomUUID)()}.tmp`);
70074
- await (0, import_promises55.symlink)(plan2.target, staged, platform3 === "win32" ? "junction" : "dir");
70318
+ await (0, import_promises56.symlink)(plan2.target, staged, platform3 === "win32" ? "junction" : "dir");
70075
70319
  try {
70076
70320
  if (platform3 === "win32") await removeLink2(plan2.path);
70077
- await (0, import_promises55.rename)(staged, plan2.path);
70321
+ await (0, import_promises56.rename)(staged, plan2.path);
70078
70322
  } catch (error62) {
70079
70323
  await removeLink2(staged).catch(() => void 0);
70080
70324
  throw error62;
@@ -70087,14 +70331,14 @@ function versionTarget(layout, versionId, platform3) {
70087
70331
  }
70088
70332
  async function writeManifest(layout) {
70089
70333
  const manifest = (0, import_node_path48.join)(layout.pluginDir, ".claude-plugin", "plugin.json");
70090
- if (await (0, import_promises55.readFile)(manifest, "utf8").catch(() => null) === PLUGIN_MANIFEST) return;
70091
- await (0, import_promises55.mkdir)((0, import_node_path48.dirname)(manifest), { recursive: true, mode: 448 });
70334
+ if (await (0, import_promises56.readFile)(manifest, "utf8").catch(() => null) === PLUGIN_MANIFEST) return;
70335
+ await (0, import_promises56.mkdir)((0, import_node_path48.dirname)(manifest), { recursive: true, mode: 448 });
70092
70336
  const staged = `${manifest}.${(0, import_node_crypto26.randomUUID)()}.tmp`;
70093
- await (0, import_promises55.writeFile)(staged, PLUGIN_MANIFEST, { mode: 384 });
70094
- await (0, import_promises55.rename)(staged, manifest);
70337
+ await (0, import_promises56.writeFile)(staged, PLUGIN_MANIFEST, { mode: 384 });
70338
+ await (0, import_promises56.rename)(staged, manifest);
70095
70339
  }
70096
70340
  async function reconcilePluginSkills(layout, installed, platform3) {
70097
- await (0, import_promises55.mkdir)(layout.pluginSkillsDir, { recursive: true, mode: 448 });
70341
+ await (0, import_promises56.mkdir)(layout.pluginSkillsDir, { recursive: true, mode: 448 });
70098
70342
  const wanted = new Map(installed.map((skill) => [skill.slug, skill]));
70099
70343
  let linked = 0;
70100
70344
  for (const skill of installed) {
@@ -70103,16 +70347,16 @@ async function reconcilePluginSkills(layout, installed, platform3) {
70103
70347
  target: versionTarget(layout, skill.versionId, platform3)
70104
70348
  };
70105
70349
  if (await entryKind2(plan2.path) === "other") {
70106
- await (0, import_promises55.rm)(plan2.path, { recursive: true, force: true });
70350
+ await (0, import_promises56.rm)(plan2.path, { recursive: true, force: true });
70107
70351
  }
70108
70352
  if (await placeLink(plan2, platform3)) linked += 1;
70109
70353
  }
70110
70354
  let unlinked = 0;
70111
- for (const name of await (0, import_promises55.readdir)(layout.pluginSkillsDir)) {
70355
+ for (const name of await (0, import_promises56.readdir)(layout.pluginSkillsDir)) {
70112
70356
  if (wanted.has(name)) continue;
70113
70357
  const path4 = (0, import_node_path48.join)(layout.pluginSkillsDir, name);
70114
70358
  if (await entryKind2(path4) === "link") await removeLink2(path4);
70115
- else await (0, import_promises55.rm)(path4, { recursive: true, force: true });
70359
+ else await (0, import_promises56.rm)(path4, { recursive: true, force: true });
70116
70360
  unlinked += 1;
70117
70361
  }
70118
70362
  return { linked, unlinked };
@@ -70124,9 +70368,9 @@ async function isOwnCodexLink(layout, path4) {
70124
70368
  return isWithinDirectory2(layout.pluginSkillsDir, absolute);
70125
70369
  }
70126
70370
  async function isForeignPackage(layout, path4) {
70127
- const resolved = await (0, import_promises55.realpath)(path4).catch(() => null);
70371
+ const resolved = await (0, import_promises56.realpath)(path4).catch(() => null);
70128
70372
  if (resolved === null) return false;
70129
- const root = await (0, import_promises55.realpath)(layout.root).catch(() => layout.root);
70373
+ const root = await (0, import_promises56.realpath)(layout.root).catch(() => layout.root);
70130
70374
  return !isWithinDirectory2(root, resolved);
70131
70375
  }
70132
70376
  async function codexSlot(layout, path4, slug) {
@@ -70143,7 +70387,7 @@ async function codexSlot(layout, path4, slug) {
70143
70387
  }
70144
70388
  async function unlinkStaleCodexEntries(layout, codexSkillsDir2, wanted) {
70145
70389
  let unlinked = 0;
70146
- for (const name of await (0, import_promises55.readdir)(codexSkillsDir2)) {
70390
+ for (const name of await (0, import_promises56.readdir)(codexSkillsDir2)) {
70147
70391
  const path4 = (0, import_node_path48.join)(codexSkillsDir2, name);
70148
70392
  if (wanted.has(name) && !name.endsWith(".tmp")) continue;
70149
70393
  if (await entryKind2(path4) !== "link" || !await isOwnCodexLink(layout, path4)) continue;
@@ -70153,7 +70397,7 @@ async function unlinkStaleCodexEntries(layout, codexSkillsDir2, wanted) {
70153
70397
  return unlinked;
70154
70398
  }
70155
70399
  async function reconcileCodexSkills(layout, installed, codexSkillsDir2, platform3) {
70156
- await (0, import_promises55.mkdir)(codexSkillsDir2, { recursive: true, mode: 448 });
70400
+ await (0, import_promises56.mkdir)(codexSkillsDir2, { recursive: true, mode: 448 });
70157
70401
  const report2 = { linked: 0, unlinked: 0, skipped: [] };
70158
70402
  for (const skill of installed) {
70159
70403
  const path4 = (0, import_node_path48.join)(codexSkillsDir2, skill.slug);
@@ -70190,7 +70434,7 @@ function installedSkillFolders(layout) {
70190
70434
 
70191
70435
  // src/capabilities/skills/sync.ts
70192
70436
  var import_node_crypto27 = require("crypto");
70193
- var import_promises56 = require("fs/promises");
70437
+ var import_promises57 = require("fs/promises");
70194
70438
  var import_node_path49 = require("path");
70195
70439
  init_zod();
70196
70440
  var SKILL_PREPARE_WAIT_MS = 15e3;
@@ -70198,28 +70442,28 @@ var FIRST_INSTALL_WAIT_MS = 5e3;
70198
70442
  var RETIRED_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
70199
70443
  async function makeFilesReadOnly(directory, platform3) {
70200
70444
  if (platform3 === "win32") return;
70201
- for (const entry of await (0, import_promises56.readdir)(directory, { withFileTypes: true })) {
70445
+ for (const entry of await (0, import_promises57.readdir)(directory, { withFileTypes: true })) {
70202
70446
  const path4 = (0, import_node_path49.join)(directory, entry.name);
70203
70447
  if (entry.isDirectory()) await makeFilesReadOnly(path4, platform3);
70204
70448
  else if (entry.isFile()) {
70205
- const executable = ((await (0, import_promises56.lstat)(path4)).mode & 64) !== 0;
70206
- await (0, import_promises56.chmod)(path4, executable ? 365 : 292);
70449
+ const executable = ((await (0, import_promises57.lstat)(path4)).mode & 64) !== 0;
70450
+ await (0, import_promises57.chmod)(path4, executable ? 365 : 292);
70207
70451
  }
70208
70452
  }
70209
70453
  }
70210
70454
  async function install(env, skill, download, signal) {
70211
70455
  const { layout, source, platform: platform3 } = env;
70212
70456
  const bytes = await source.download(download.url, signal);
70213
- await (0, import_promises56.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
70457
+ await (0, import_promises57.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
70214
70458
  const staging = (0, import_node_path49.join)(layout.tmpDir, (0, import_node_crypto27.randomUUID)());
70215
70459
  await extractSkillBundle(Buffer.from(bytes), staging, {
70216
70460
  expectedArchiveHash: download.archiveHash,
70217
70461
  expectedContentHash: skill.contentHash
70218
70462
  });
70219
70463
  const target = packageDirectory(layout, skill.versionId);
70220
- await (0, import_promises56.mkdir)(layout.versionsDir, { recursive: true, mode: 448 });
70221
- await (0, import_promises56.rm)(target, { recursive: true, force: true });
70222
- await (0, import_promises56.rename)(staging, target);
70464
+ await (0, import_promises57.mkdir)(layout.versionsDir, { recursive: true, mode: 448 });
70465
+ await (0, import_promises57.rm)(target, { recursive: true, force: true });
70466
+ await (0, import_promises57.rename)(staging, target);
70223
70467
  await makeFilesReadOnly(target, platform3);
70224
70468
  }
70225
70469
  var retiredFileSchema = external_exports.record(external_exports.string(), external_exports.number());
@@ -70231,14 +70475,14 @@ async function sweep(env, keep) {
70231
70475
  const now = env.now();
70232
70476
  const stillRetired = {};
70233
70477
  const expired = [];
70234
- for (const name of await (0, import_promises56.readdir)(layout.versionsDir).catch(() => [])) {
70478
+ for (const name of await (0, import_promises57.readdir)(layout.versionsDir).catch(() => [])) {
70235
70479
  if (kept.has(name)) continue;
70236
70480
  const since = retired[name] ?? now;
70237
70481
  if (now - since >= RETIRED_VERSION_RETENTION_MS) expired.push(name);
70238
70482
  else stillRetired[name] = since;
70239
70483
  }
70240
70484
  const results = await Promise.allSettled(
70241
- expired.map((name) => (0, import_promises56.rm)((0, import_node_path49.join)(layout.versionsDir, name), { recursive: true, force: true }))
70485
+ expired.map((name) => (0, import_promises57.rm)((0, import_node_path49.join)(layout.versionsDir, name), { recursive: true, force: true }))
70242
70486
  );
70243
70487
  results.forEach((result, index) => {
70244
70488
  const name = expired[index];
@@ -70247,7 +70491,7 @@ async function sweep(env, keep) {
70247
70491
  if (JSON.stringify(stillRetired) !== JSON.stringify(retired)) {
70248
70492
  await writeJsonFileAtomic(layout.retiredFile, stillRetired);
70249
70493
  }
70250
- await (0, import_promises56.rm)(layout.tmpDir, { recursive: true, force: true });
70494
+ await (0, import_promises57.rm)(layout.tmpDir, { recursive: true, force: true });
70251
70495
  return results.filter((result) => result.status === "fulfilled").length;
70252
70496
  }
70253
70497
  var INSTALL_CONCURRENCY = 4;
@@ -70593,7 +70837,7 @@ var import_node_path52 = require("path");
70593
70837
  init_runtime_v2();
70594
70838
 
70595
70839
  // src/capabilities/workspace/approved-paths.ts
70596
- var import_promises57 = require("fs/promises");
70840
+ var import_promises58 = require("fs/promises");
70597
70841
  init_zod();
70598
70842
 
70599
70843
  // src/capabilities/workspace/paths.ts
@@ -70631,7 +70875,7 @@ var storeSchema = external_exports.object({
70631
70875
  });
70632
70876
  async function realpathOrNull(path4) {
70633
70877
  try {
70634
- return await (0, import_promises57.realpath)(path4);
70878
+ return await (0, import_promises58.realpath)(path4);
70635
70879
  } catch (error62) {
70636
70880
  const code = errnoCode(error62);
70637
70881
  if (code === "ENOENT" || code === "ENOTDIR" || code === "EACCES" || code === "EPERM") {
@@ -70691,7 +70935,7 @@ async function openApprovedPaths(options) {
70691
70935
 
70692
70936
  // src/capabilities/workspace/locks.ts
70693
70937
  var import_node_crypto28 = require("crypto");
70694
- var import_promises58 = require("fs/promises");
70938
+ var import_promises59 = require("fs/promises");
70695
70939
  var import_node_path51 = require("path");
70696
70940
  init_zod();
70697
70941
  var LOCK_FORMAT = 1;
@@ -70712,7 +70956,7 @@ function repositoryLockKey(commonDir, platform3) {
70712
70956
  async function readOwner2(path4) {
70713
70957
  let text3;
70714
70958
  try {
70715
- text3 = await (0, import_promises58.readFile)(path4, "utf8");
70959
+ text3 = await (0, import_promises59.readFile)(path4, "utf8");
70716
70960
  } catch (error62) {
70717
70961
  if (errnoCode(error62) === "ENOENT") return { kind: "missing" };
70718
70962
  return { kind: "unreadable" };
@@ -70733,7 +70977,7 @@ async function removeIfSame(path4, expected) {
70733
70977
  if (current.kind !== "owner" || current.owner.since !== expected.since) return;
70734
70978
  if (current.owner.pid !== expected.pid || current.owner.holder !== expected.holder) return;
70735
70979
  }
70736
- await (0, import_promises58.unlink)(path4).catch((error62) => {
70980
+ await (0, import_promises59.unlink)(path4).catch((error62) => {
70737
70981
  if (errnoCode(error62) !== "ENOENT") throw error62;
70738
70982
  });
70739
70983
  }
@@ -70758,7 +71002,7 @@ function openRepositoryLocks(options) {
70758
71002
  await removeIfSame(path4, read.owner);
70759
71003
  return null;
70760
71004
  }
70761
- const age = await (0, import_promises58.stat)(path4).then(
71005
+ const age = await (0, import_promises59.stat)(path4).then(
70762
71006
  (info) => clock.now() - info.mtimeMs,
70763
71007
  () => 0
70764
71008
  );
@@ -70773,12 +71017,12 @@ function openRepositoryLocks(options) {
70773
71017
  const folder = async (commonDir) => {
70774
71018
  const key = repositoryLockKey(commonDir, platform3);
70775
71019
  const dir = (0, import_node_path51.join)(options.dir, key);
70776
- await (0, import_promises58.mkdir)(dir, { recursive: true, mode: 448 });
71020
+ await (0, import_promises59.mkdir)(dir, { recursive: true, mode: 448 });
70777
71021
  return { key, dir };
70778
71022
  };
70779
71023
  const createExclusive = async (path4, owner) => {
70780
71024
  try {
70781
- const handle = await (0, import_promises58.open)(path4, "wx", 384);
71025
+ const handle = await (0, import_promises59.open)(path4, "wx", 384);
70782
71026
  try {
70783
71027
  await handle.writeFile(JSON.stringify(owner));
70784
71028
  } finally {
@@ -70791,7 +71035,7 @@ function openRepositoryLocks(options) {
70791
71035
  }
70792
71036
  };
70793
71037
  const liveRun = async (dir) => {
70794
- const entries = await (0, import_promises58.readdir)(dir);
71038
+ const entries = await (0, import_promises59.readdir)(dir);
70795
71039
  for (const entry of entries) {
70796
71040
  if (!entry.startsWith(RUN_FILE_PREFIX)) continue;
70797
71041
  const holder = await heldBy((0, import_node_path51.join)(dir, entry));
@@ -71315,17 +71559,17 @@ function createConversationMcpAuthorization(options) {
71315
71559
  }
71316
71560
 
71317
71561
  // src/holder/mcp-helper-access.ts
71318
- var import_promises59 = require("fs/promises");
71562
+ var import_promises60 = require("fs/promises");
71319
71563
  function createHelperMcpAccess(options) {
71320
71564
  return {
71321
71565
  [Symbol.asyncDispose]: async () => {
71322
- await (0, import_promises59.rm)(options.credentialPath, { force: true });
71566
+ await (0, import_promises60.rm)(options.credentialPath, { force: true });
71323
71567
  },
71324
71568
  url: options.managedMcp.url,
71325
71569
  authorization: async (signal) => {
71326
71570
  const authorization = await options.managedMcp.authorization(signal);
71327
71571
  if (authorization === void 0 || signal.aborted) {
71328
- await (0, import_promises59.rm)(options.credentialPath, { force: true });
71572
+ await (0, import_promises60.rm)(options.credentialPath, { force: true });
71329
71573
  return void 0;
71330
71574
  }
71331
71575
  const credential = {
@@ -71340,7 +71584,7 @@ function createHelperMcpAccess(options) {
71340
71584
  }
71341
71585
 
71342
71586
  // src/holder/run-inputs.ts
71343
- var import_promises60 = require("fs/promises");
71587
+ var import_promises61 = require("fs/promises");
71344
71588
  var import_node_path55 = require("path");
71345
71589
  init_dist();
71346
71590
  var NO_RUN_INPUTS = {
@@ -71377,7 +71621,7 @@ function runMediaUploader(source, runId) {
71377
71621
  async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71378
71622
  const dir = (0, import_node_path55.join)(tmpDir, "runs", spec.runId);
71379
71623
  const cleanup = async () => {
71380
- await (0, import_promises60.rm)(dir, { recursive: true, force: true });
71624
+ await (0, import_promises61.rm)(dir, { recursive: true, force: true });
71381
71625
  };
71382
71626
  try {
71383
71627
  const credential = await source.fetchProviderCredential(spec.runId, signal);
@@ -71385,8 +71629,8 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71385
71629
  for (const [index, attachment] of (spec.attachments ?? []).entries()) {
71386
71630
  const bytes = await source.downloadAttachment(spec.runId, attachment.id, signal);
71387
71631
  const path4 = attachmentPath(spec, attachment, index, dir);
71388
- await (0, import_promises60.mkdir)((0, import_node_path55.dirname)(path4), { recursive: true, mode: 448 });
71389
- await (0, import_promises60.writeFile)(path4, bytes, { mode: 384 });
71632
+ await (0, import_promises61.mkdir)((0, import_node_path55.dirname)(path4), { recursive: true, mode: 448 });
71633
+ await (0, import_promises61.writeFile)(path4, bytes, { mode: 384 });
71390
71634
  const imageMimeType = attachment.kind === "image" ? detectImageMimeType(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)) : null;
71391
71635
  attachments.push({
71392
71636
  id: attachment.id,
@@ -71424,7 +71668,7 @@ init_runtime_v2();
71424
71668
 
71425
71669
  // src/holder/admission.ts
71426
71670
  var import_node_fs20 = require("fs");
71427
- var import_promises64 = require("fs/promises");
71671
+ var import_promises65 = require("fs/promises");
71428
71672
  var import_node_os9 = require("os");
71429
71673
  var import_node_path61 = require("path");
71430
71674
  init_constants();
@@ -71438,7 +71682,7 @@ function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os8.hom
71438
71682
  }
71439
71683
 
71440
71684
  // src/holder/agent-context.ts
71441
- var import_promises61 = require("fs/promises");
71685
+ var import_promises62 = require("fs/promises");
71442
71686
  var import_node_path57 = require("path");
71443
71687
 
71444
71688
  // ../agent-core/dist/prompt.js
@@ -71446,7 +71690,7 @@ init_chunk_7FJ7QKFN();
71446
71690
 
71447
71691
  // src/holder/agent-context.ts
71448
71692
  async function readText4(path4) {
71449
- return (0, import_promises61.readFile)(path4, "utf8").then(
71693
+ return (0, import_promises62.readFile)(path4, "utf8").then(
71450
71694
  (text3) => text3.trim(),
71451
71695
  () => null
71452
71696
  );
@@ -71492,12 +71736,12 @@ var import_node_path60 = require("path");
71492
71736
 
71493
71737
  // src/holder/claim-once.ts
71494
71738
  var import_node_crypto29 = require("crypto");
71495
- var import_promises62 = require("fs/promises");
71739
+ var import_promises63 = require("fs/promises");
71496
71740
  var import_node_path58 = require("path");
71497
71741
  async function claimOnce(dir, name) {
71498
71742
  try {
71499
- await (0, import_promises62.mkdir)(dir, { recursive: true, mode: 448 });
71500
- await (await (0, import_promises62.open)((0, import_node_path58.join)(dir, name), "wx")).close();
71743
+ await (0, import_promises63.mkdir)(dir, { recursive: true, mode: 448 });
71744
+ await (await (0, import_promises63.open)((0, import_node_path58.join)(dir, name), "wx")).close();
71501
71745
  return true;
71502
71746
  } catch {
71503
71747
  return false;
@@ -71508,7 +71752,7 @@ function claimFirstLease(freshnessDir, path4) {
71508
71752
  }
71509
71753
 
71510
71754
  // src/holder/requested-checkout.ts
71511
- var import_promises63 = require("fs/promises");
71755
+ var import_promises64 = require("fs/promises");
71512
71756
  var import_node_path59 = require("path");
71513
71757
  var REMOTE2 = "origin";
71514
71758
  var REASON_MAX_CHARS = 200;
@@ -71531,7 +71775,7 @@ function notSwitched(checkout, current, reason) {
71531
71775
  }
71532
71776
  async function clone2(checkout, deps, signal) {
71533
71777
  const parent = (0, import_node_path59.dirname)(checkout.path);
71534
- await (0, import_promises63.mkdir)(parent, { recursive: true });
71778
+ await (0, import_promises64.mkdir)(parent, { recursive: true });
71535
71779
  await assertValidBranch(deps.git, parent, checkout.branch, signal);
71536
71780
  const output2 = await deps.git.run(
71537
71781
  {
@@ -71839,7 +72083,7 @@ function volumeRoot(path4) {
71839
72083
  }
71840
72084
  async function exists4(path4) {
71841
72085
  try {
71842
- await (0, import_promises64.stat)(path4);
72086
+ await (0, import_promises65.stat)(path4);
71843
72087
  return true;
71844
72088
  } catch {
71845
72089
  return false;
@@ -71847,10 +72091,10 @@ async function exists4(path4) {
71847
72091
  }
71848
72092
  async function inspectReadiness(path4) {
71849
72093
  try {
71850
- if (!(await (0, import_promises64.stat)(path4)).isDirectory()) {
72094
+ if (!(await (0, import_promises65.stat)(path4)).isDirectory()) {
71851
72095
  return { ready: false, missing: true, message: MESSAGES.missing };
71852
72096
  }
71853
- await (0, import_promises64.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
72097
+ await (0, import_promises65.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71854
72098
  return { ready: true };
71855
72099
  } catch (error62) {
71856
72100
  const code = errnoCode(error62) ?? "";
@@ -71894,8 +72138,8 @@ async function admitDefaultWorkspace(spec, context, skills) {
71894
72138
  const { env } = context;
71895
72139
  const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os9.homedir)());
71896
72140
  try {
71897
- await (0, import_promises64.mkdir)(path4, { recursive: true, mode: 448 });
71898
- await (0, import_promises64.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
72141
+ await (0, import_promises65.mkdir)(path4, { recursive: true, mode: 448 });
72142
+ await (0, import_promises65.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71899
72143
  return { kind: "admitted", spec: { ...spec, projectPath: path4 }, skills };
71900
72144
  } catch (error62) {
71901
72145
  const code = errnoCode(error62);
@@ -72023,7 +72267,7 @@ async function respondToTurn(runningRunId, driver, request2) {
72023
72267
  }
72024
72268
 
72025
72269
  // src/holder/session-facts.ts
72026
- var import_promises65 = require("fs/promises");
72270
+ var import_promises66 = require("fs/promises");
72027
72271
  var CLI_RSS_CACHE_MS = 1e4;
72028
72272
  var LOGIN_PROBLEM_PREFIX = "cli.auth.";
72029
72273
  function isLoginFailure(result) {
@@ -72045,12 +72289,12 @@ function createSessionFacts(options) {
72045
72289
  loginFailed: false,
72046
72290
  rss: null
72047
72291
  };
72048
- const identify = async (command) => {
72292
+ const identify2 = async (command) => {
72049
72293
  const path4 = await resolveCommandOnPath(command, env, platform3);
72050
72294
  if (path4 === null) return null;
72051
72295
  try {
72052
- const real = await (0, import_promises65.realpath)(path4);
72053
- const info = await (0, import_promises65.stat)(real);
72296
+ const real = await (0, import_promises66.realpath)(path4);
72297
+ const info = await (0, import_promises66.stat)(real);
72054
72298
  return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
72055
72299
  } catch {
72056
72300
  return null;
@@ -72064,9 +72308,9 @@ function createSessionFacts(options) {
72064
72308
  const selectionFile = env.ALAN_MANAGED_PROVIDER_SELECTION_FILE;
72065
72309
  state.managedVersion = selectionFile === void 0 ? null : await readManagedProviderVersion(selectionFile, spec.backendKind);
72066
72310
  const command = providerCommandFor(spec.backendKind);
72067
- state.executable = command === void 0 ? null : await identify(command);
72311
+ state.executable = command === void 0 ? null : await identify2(command);
72068
72312
  if (state.executable === null && spec.backendKind === "kimi_cli") {
72069
- state.executable = await identify("kimi-cli");
72313
+ state.executable = await identify2("kimi-cli");
72070
72314
  }
72071
72315
  };
72072
72316
  const liveCliRss = async () => {
@@ -72088,7 +72332,7 @@ function createSessionFacts(options) {
72088
72332
  }
72089
72333
  const spawned = state.executable;
72090
72334
  if (spawned === null) return false;
72091
- const current = await identify(spawned.command);
72335
+ const current = await identify2(spawned.command);
72092
72336
  return current?.key !== spawned.key;
72093
72337
  };
72094
72338
  return {
@@ -72144,12 +72388,12 @@ async function steerTurn(runningRunId, driver, request2) {
72144
72388
  init_acp3();
72145
72389
 
72146
72390
  // src/run-log/archive.ts
72147
- var import_promises66 = require("fs/promises");
72391
+ var import_promises67 = require("fs/promises");
72148
72392
  var import_node_path62 = require("path");
72149
72393
  init_runtime_v2();
72150
72394
  async function openRunArchive(runsDir) {
72151
72395
  const path4 = (0, import_node_path62.join)((0, import_node_path62.dirname)(runsDir), "archived-runs.txt");
72152
- const text3 = await (0, import_promises66.readFile)(path4, "utf8").catch((error62) => {
72396
+ const text3 = await (0, import_promises67.readFile)(path4, "utf8").catch((error62) => {
72153
72397
  if (errnoCode(error62) === "ENOENT") return "";
72154
72398
  throw error62;
72155
72399
  });
@@ -72163,7 +72407,7 @@ async function openRunArchive(runsDir) {
72163
72407
  add: async (runIds) => {
72164
72408
  const added = runIds.filter((runId) => !archived.has(runId));
72165
72409
  if (added.length === 0) return;
72166
- await (0, import_promises66.appendFile)(path4, `
72410
+ await (0, import_promises67.appendFile)(path4, `
72167
72411
  ${added.join("\n")}
72168
72412
  `, { mode: 384 });
72169
72413
  for (const runId of added) archived.add(runId);
@@ -72177,7 +72421,7 @@ var import_node_fs21 = require("fs");
72177
72421
  var import_node_path64 = require("path");
72178
72422
 
72179
72423
  // src/run-log/directory.ts
72180
- var import_promises67 = require("fs/promises");
72424
+ var import_promises68 = require("fs/promises");
72181
72425
  var import_node_path63 = require("path");
72182
72426
  init_runtime_v2();
72183
72427
  init_zod();
@@ -72214,7 +72458,7 @@ function runDirectory(runsDir, runId) {
72214
72458
  }
72215
72459
  async function isRunClaimed(runsDir, runId) {
72216
72460
  try {
72217
- return (await (0, import_promises67.stat)(runDirectory(runsDir, runId).log)).size > 0;
72461
+ return (await (0, import_promises68.stat)(runDirectory(runsDir, runId).log)).size > 0;
72218
72462
  } catch (error62) {
72219
72463
  if (errnoCode(error62) === "ENOENT") return false;
72220
72464
  throw error62;
@@ -72252,7 +72496,7 @@ async function writeCompleteRunLog(runsDir, meta3, records) {
72252
72496
  }
72253
72497
 
72254
72498
  // src/run-log/conversation-index.ts
72255
- var import_promises68 = require("fs/promises");
72499
+ var import_promises69 = require("fs/promises");
72256
72500
  var import_node_path65 = require("path");
72257
72501
  init_runtime_v2();
72258
72502
  init_zod();
@@ -72285,8 +72529,8 @@ async function indexConversationRun(runsDir, conversationId, ordinal, assistantO
72285
72529
  const nextOrdinal = assistantOrdinal + 1;
72286
72530
  if (nextOrdinal <= ordinal) throw new Error("Assistant order must follow the prompt");
72287
72531
  const path4 = shardPath(runsDir, conversationId, ordinal);
72288
- await (0, import_promises68.mkdir)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
72289
- await (0, import_promises68.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
72532
+ await (0, import_promises69.mkdir)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
72533
+ await (0, import_promises69.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
72290
72534
  `, { mode: 384 });
72291
72535
  const coveragePath = (0, import_node_path65.join)((0, import_node_path65.dirname)((0, import_node_path65.dirname)(path4)), "coverage.json");
72292
72536
  const coverage = await readJsonFile(coveragePath, coverageSchema);
@@ -72309,7 +72553,7 @@ async function readConversationIndexCoverage(runsDir, conversationId) {
72309
72553
  }
72310
72554
  async function readConversationRunIndex(runsDir, conversationId, before, limit) {
72311
72555
  const directory = indexDirectory(runsDir, conversationId);
72312
- const names = await (0, import_promises68.readdir)(directory).catch((error62) => {
72556
+ const names = await (0, import_promises69.readdir)(directory).catch((error62) => {
72313
72557
  if (error62.code === "ENOENT") return [];
72314
72558
  throw error62;
72315
72559
  });
@@ -72318,7 +72562,7 @@ async function readConversationRunIndex(runsDir, conversationId, before, limit)
72318
72562
  ).sort((left, right) => right - left);
72319
72563
  const selected = [];
72320
72564
  for (const shard of shards) {
72321
- const text3 = await (0, import_promises68.readFile)((0, import_node_path65.join)(directory, `${shard}.jsonl`), "utf8");
72565
+ const text3 = await (0, import_promises69.readFile)((0, import_node_path65.join)(directory, `${shard}.jsonl`), "utf8");
72322
72566
  const records = text3.split("\n").flatMap((line) => {
72323
72567
  if (!line) return [];
72324
72568
  const parsed = indexRecordSchema.parse(JSON.parse(line));
@@ -72343,7 +72587,7 @@ async function readIndexableRun(runsDir, name) {
72343
72587
  return { conversationId: meta3.conversationId, ordinal, assistantOrdinal, runId: runId.data };
72344
72588
  }
72345
72589
  async function readIndexableRuns(runsDir) {
72346
- const names = await (0, import_promises68.readdir)(runsDir).catch(() => []);
72590
+ const names = await (0, import_promises69.readdir)(runsDir).catch(() => []);
72347
72591
  const byConversation = /* @__PURE__ */ new Map();
72348
72592
  let next = 0;
72349
72593
  const worker = async () => {
@@ -72373,21 +72617,21 @@ async function writeConversationIndex(directory, runs) {
72373
72617
  else lines2.push(line);
72374
72618
  coverage = nextCoverage(coverage, run2.ordinal, nextOrdinal) ?? coverage;
72375
72619
  }
72376
- await (0, import_promises68.mkdir)((0, import_node_path65.join)(directory, "turn-index"), { recursive: true, mode: 448 });
72620
+ await (0, import_promises69.mkdir)((0, import_node_path65.join)(directory, "turn-index"), { recursive: true, mode: 448 });
72377
72621
  for (const [shard, lines2] of shards) {
72378
- await (0, import_promises68.writeFile)((0, import_node_path65.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
72622
+ await (0, import_promises69.writeFile)((0, import_node_path65.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
72379
72623
  `, {
72380
72624
  mode: 384
72381
72625
  });
72382
72626
  }
72383
- await (0, import_promises68.writeFile)((0, import_node_path65.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
72627
+ await (0, import_promises69.writeFile)((0, import_node_path65.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
72384
72628
  `, {
72385
72629
  mode: 384
72386
72630
  });
72387
72631
  }
72388
72632
  async function rebuildConversationIndexes(runsDir) {
72389
72633
  const root = conversationsDirectory(runsDir);
72390
- const exists6 = await (0, import_promises68.stat)(root).then(
72634
+ const exists6 = await (0, import_promises69.stat)(root).then(
72391
72635
  () => true,
72392
72636
  (error62) => {
72393
72637
  if (errnoCode(error62) === "ENOENT") return false;
@@ -72396,18 +72640,18 @@ async function rebuildConversationIndexes(runsDir) {
72396
72640
  );
72397
72641
  if (exists6) return 0;
72398
72642
  const building = `${root}.rebuilding`;
72399
- await (0, import_promises68.rm)(building, { recursive: true, force: true });
72400
- await (0, import_promises68.mkdir)(building, { recursive: true, mode: 448 });
72643
+ await (0, import_promises69.rm)(building, { recursive: true, force: true });
72644
+ await (0, import_promises69.mkdir)(building, { recursive: true, mode: 448 });
72401
72645
  const byConversation = await readIndexableRuns(runsDir);
72402
72646
  for (const [conversationId, runs] of byConversation) {
72403
72647
  await writeConversationIndex((0, import_node_path65.join)(building, conversationId), runs);
72404
72648
  }
72405
- await (0, import_promises68.rename)(building, root);
72649
+ await (0, import_promises69.rename)(building, root);
72406
72650
  return byConversation.size;
72407
72651
  }
72408
72652
 
72409
72653
  // src/run-log/reader.ts
72410
- var import_promises69 = require("fs/promises");
72654
+ var import_promises70 = require("fs/promises");
72411
72655
  init_runtime_v2();
72412
72656
 
72413
72657
  // src/run-log/tail.ts
@@ -72420,9 +72664,24 @@ function tailWindows(size) {
72420
72664
  if (length >= size || length > MAX_RUN_LOG_RECORD_BYTES) return windows;
72421
72665
  }
72422
72666
  }
72423
- function lastLine(text3, wholeFile) {
72424
- const start2 = text3.lastIndexOf("\n") + 1;
72425
- return start2 === 0 && !wholeFile ? void 0 : text3.slice(start2);
72667
+ function parseRecord2(line) {
72668
+ try {
72669
+ const parsed = runLogRecordSchema.safeParse(JSON.parse(Buffer.from(line).toString("utf8")));
72670
+ return parsed.success ? parsed.data : null;
72671
+ } catch {
72672
+ return null;
72673
+ }
72674
+ }
72675
+ function lastRecord(window2, wholeFile) {
72676
+ let end = window2.lastIndexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
72677
+ while (end > 0) {
72678
+ const start2 = end >= 2 ? window2.lastIndexOf(RUN_LOG_RECORD_SEPARATOR, end - 2) + 1 : 0;
72679
+ if (start2 === 0 && !wholeFile) return void 0;
72680
+ const record2 = parseRecord2(window2.subarray(start2, end - 1));
72681
+ if (record2 !== null) return { record: record2, end };
72682
+ end = start2;
72683
+ }
72684
+ return wholeFile ? null : void 0;
72426
72685
  }
72427
72686
 
72428
72687
  // src/run-log/reader.ts
@@ -72430,7 +72689,7 @@ function firstRecordLength(bytes) {
72430
72689
  return bytes.indexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
72431
72690
  }
72432
72691
  async function openRunLogReader(path4) {
72433
- const handle = await (0, import_promises69.open)(path4, "r");
72692
+ const handle = await (0, import_promises70.open)(path4, "r");
72434
72693
  const readAt = async (position, length) => {
72435
72694
  const buffer = Buffer.alloc(length);
72436
72695
  const { bytesRead } = await handle.read(buffer, 0, length, position);
@@ -72464,19 +72723,16 @@ async function openRunLogReader(path4) {
72464
72723
  };
72465
72724
  }
72466
72725
  async function readLastRecord(path4) {
72467
- const handle = await (0, import_promises69.open)(path4, "r").catch(() => null);
72726
+ const handle = await (0, import_promises70.open)(path4, "r").catch(() => null);
72468
72727
  if (handle === null) return null;
72469
72728
  try {
72470
72729
  const { size } = await handle.stat();
72471
72730
  for (const length of tailWindows(size)) {
72472
72731
  const buffer = Buffer.alloc(length);
72473
72732
  await handle.read(buffer, 0, length, size - length);
72474
- const aligned = buffer.subarray(0, alignedLength(buffer)).toString("utf8").trimEnd();
72475
- const last = lastLine(aligned, length === size);
72733
+ const last = lastRecord(buffer, length === size);
72476
72734
  if (last === void 0) continue;
72477
- if (last.length === 0) return null;
72478
- const parsed = runLogRecordSchema.safeParse(JSON.parse(last));
72479
- return parsed.success ? parsed.data : null;
72735
+ return last?.record ?? null;
72480
72736
  }
72481
72737
  return null;
72482
72738
  } finally {
@@ -72500,24 +72756,33 @@ var decoder = new TextDecoder();
72500
72756
  var import_node_fs22 = require("fs");
72501
72757
  var import_node_path66 = require("path");
72502
72758
  init_runtime_v2();
72503
- function lastSeq(fd, size) {
72759
+ function readTail(fd, size) {
72504
72760
  for (const length of tailWindows(size)) {
72505
72761
  const buffer = Buffer.alloc(length);
72506
72762
  (0, import_node_fs22.readSync)(fd, buffer, 0, length, size - length);
72507
- const last = lastLine(buffer.toString("utf8").trimEnd(), length === size);
72763
+ const last = lastRecord(buffer, length === size);
72508
72764
  if (last === void 0) continue;
72509
- if (last.length === 0) return 0;
72510
- const parsed = runLogRecordSchema.safeParse(JSON.parse(last));
72511
- if (!parsed.success) throw new RuntimeFault("invalid_file", "Run log tail is not a record");
72512
- return parsed.data.seq;
72765
+ if (last === null) return { seq: 0, end: 0 };
72766
+ return { seq: last.record.seq, end: size - length + last.end };
72513
72767
  }
72514
72768
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
72515
72769
  }
72770
+ function writeAt(fd, bytes, position) {
72771
+ for (let written = 0; written < bytes.length; ) {
72772
+ written += (0, import_node_fs22.writeSync)(fd, bytes, written, bytes.length - written, position + written);
72773
+ }
72774
+ }
72516
72775
  function openRunLog(path4, clock) {
72517
72776
  (0, import_node_fs22.mkdirSync)((0, import_node_path66.dirname)(path4), { recursive: true, mode: 448 });
72518
- const fd = (0, import_node_fs22.openSync)(path4, "a+", 384);
72519
- let size = (0, import_node_fs22.fstatSync)(fd).size;
72520
- let seq = lastSeq(fd, size);
72777
+ const fd = (0, import_node_fs22.openSync)(path4, import_node_fs22.constants.O_RDWR | import_node_fs22.constants.O_CREAT, 384);
72778
+ const fileSize = (0, import_node_fs22.fstatSync)(fd).size;
72779
+ const tail = readTail(fd, fileSize);
72780
+ let size = tail.end;
72781
+ let seq = tail.seq;
72782
+ if (fileSize > size) {
72783
+ (0, import_node_fs22.ftruncateSync)(fd, size);
72784
+ (0, import_node_fs22.fsyncSync)(fd);
72785
+ }
72521
72786
  let dirty = false;
72522
72787
  const sync = () => {
72523
72788
  (0, import_node_fs22.fsyncSync)(fd);
@@ -72525,16 +72790,21 @@ function openRunLog(path4, clock) {
72525
72790
  };
72526
72791
  return {
72527
72792
  append: (update, sessionId) => {
72528
- seq += 1;
72529
72793
  const record2 = {
72530
- seq,
72794
+ seq: seq + 1,
72531
72795
  at: clock.now(),
72532
72796
  ...sessionId === void 0 ? {} : { sessionId },
72533
72797
  update
72534
72798
  };
72535
72799
  const line = Buffer.from(`${JSON.stringify(record2)}
72536
72800
  `, "utf8");
72537
- (0, import_node_fs22.writeSync)(fd, line);
72801
+ try {
72802
+ writeAt(fd, line, size);
72803
+ } catch (error62) {
72804
+ (0, import_node_fs22.ftruncateSync)(fd, size);
72805
+ throw error62;
72806
+ }
72807
+ seq = record2.seq;
72538
72808
  size += line.length;
72539
72809
  dirty = true;
72540
72810
  if (isRunLifecycleKind(update.sessionUpdate)) sync();
@@ -72680,16 +72950,58 @@ async function claimRun(spec, context) {
72680
72950
  }
72681
72951
  return log;
72682
72952
  }
72953
+ var RUN_END_RETRY_MS = 5e3;
72954
+ var RUN_END_DEADLINE_MS = 10 * 6e4;
72683
72955
  async function runClaimedTurn(spec, claimed, context, signal) {
72684
72956
  var _stack = [];
72685
72957
  try {
72686
72958
  const log = __using(_stack, claimed);
72687
72959
  const reported = { error: false };
72960
+ const writeFailed = new AbortController();
72961
+ let writeError;
72688
72962
  const append = (update, sessionId) => {
72963
+ if (writeError !== void 0) return;
72689
72964
  if (update.sessionUpdate === "notice" && update.severity === "error") reported.error = true;
72690
- const offset = log.append(update, sessionId);
72965
+ let offset;
72966
+ try {
72967
+ offset = log.append(update, sessionId);
72968
+ } catch (error62) {
72969
+ writeError = error62;
72970
+ context.log.error("holder.run_log_write_failed", { runId: spec.runId, error: error62 });
72971
+ writeFailed.abort();
72972
+ return;
72973
+ }
72691
72974
  context.onAppended(spec.runId, offset);
72692
72975
  };
72976
+ const endRun = async (updates2) => {
72977
+ const deadline = context.clock.monotonic() + RUN_END_DEADLINE_MS;
72978
+ for (const update of updates2) {
72979
+ for (; ; ) {
72980
+ let offset;
72981
+ try {
72982
+ offset = log.append(update);
72983
+ } catch (error62) {
72984
+ context.log.warn("holder.run_end_write_failed", { runId: spec.runId, error: error62 });
72985
+ if (context.clock.monotonic() >= deadline) {
72986
+ throw new RuntimeFault("io_failed", `Run ${spec.runId} could not be ended`, {
72987
+ cause: error62
72988
+ });
72989
+ }
72990
+ await context.clock.sleep(RUN_END_RETRY_MS, new AbortController().signal);
72991
+ continue;
72992
+ }
72993
+ context.onAppended(spec.runId, offset);
72994
+ break;
72995
+ }
72996
+ }
72997
+ };
72998
+ const fail = async (message2) => {
72999
+ await endRun([
73000
+ noticeUpdate("error", "run_failed", message2),
73001
+ runEnded({ outcome: "failed", message: message2 })
73002
+ ]);
73003
+ return "failed";
73004
+ };
72693
73005
  let result;
72694
73006
  try {
72695
73007
  result = await admitAndRun(
@@ -72700,20 +73012,22 @@ async function runClaimedTurn(spec, claimed, context, signal) {
72700
73012
  // Base64 media in provider payloads and tool output never reaches the log (main 13590db369).
72701
73013
  onEvent: (event) => append(fitForRunLog(withoutInlineMedia(event.update)), event.sessionId)
72702
73014
  },
72703
- signal
73015
+ AbortSignal.any([signal, writeFailed.signal])
72704
73016
  );
72705
73017
  } catch (error62) {
72706
- const message2 = error62 instanceof Error ? error62.message : String(error62);
72707
73018
  context.log.error("holder.turn_threw", { runId: spec.runId, error: error62 });
72708
- append(noticeUpdate("error", "run_failed", message2));
72709
- append(runEnded({ outcome: "failed", message: message2 }));
72710
- return "failed";
73019
+ return await fail(error62 instanceof Error ? error62.message : String(error62));
73020
+ }
73021
+ if (writeError !== void 0) {
73022
+ const reason = writeError instanceof Error ? writeError.message : String(writeError);
73023
+ return await fail(`This run's log could not be written: ${reason}`);
72711
73024
  }
72712
73025
  const outcome2 = result.outcome === "aborted" && signal.reason === "interrupted" ? "interrupted" : result.outcome;
73026
+ const updates = [];
72713
73027
  if (outcome2 === "failed" && !reported.error && result.message !== void 0) {
72714
- append(noticeUpdate("error", "run_failed", result.message));
73028
+ updates.push(noticeUpdate("error", "run_failed", result.message));
72715
73029
  }
72716
- append(
73030
+ updates.push(
72717
73031
  runEnded({
72718
73032
  outcome: outcome2,
72719
73033
  ...result.providerSessionId === void 0 ? {} : { providerSessionId: result.providerSessionId },
@@ -72723,6 +73037,7 @@ async function runClaimedTurn(spec, claimed, context, signal) {
72723
73037
  ...result.unansweredSteerIds === void 0 ? {} : { unansweredSteerIds: [...result.unansweredSteerIds] }
72724
73038
  })
72725
73039
  );
73040
+ await endRun(updates);
72726
73041
  context.log.info("holder.turn_ended", { runId: spec.runId, outcome: outcome2 });
72727
73042
  return outcome2;
72728
73043
  } catch (_) {
@@ -73016,11 +73331,11 @@ function delta(current, previous) {
73016
73331
  return previous === void 0 ? 0 : Math.max(0, Math.round(current - previous));
73017
73332
  }
73018
73333
  async function lastOutputAtMs(runsDir, run2) {
73019
- const info = await (0, import_promises70.stat)(runDirectory(runsDir, run2.runId).log).catch(() => null);
73334
+ const info = await (0, import_promises71.stat)(runDirectory(runsDir, run2.runId).log).catch(() => null);
73020
73335
  return info === null ? null : Math.floor(info.mtimeMs);
73021
73336
  }
73022
73337
  async function readHolderActivities(sessionsDir) {
73023
- const names = await (0, import_promises70.readdir)(sessionsDir).catch(() => []);
73338
+ const names = await (0, import_promises71.readdir)(sessionsDir).catch(() => []);
73024
73339
  const found = [];
73025
73340
  for (const name of names) {
73026
73341
  const parsed = conversationIdSchema.safeParse(name);
@@ -73303,7 +73618,7 @@ async function runActivityLeaseWorker(rawData, port) {
73303
73618
 
73304
73619
  // src/cli/commands/compat.ts
73305
73620
  var import_node_crypto33 = require("crypto");
73306
- var import_promises74 = require("fs/promises");
73621
+ var import_promises75 = require("fs/promises");
73307
73622
  init_runtime_v2();
73308
73623
  init_zod();
73309
73624
 
@@ -73593,7 +73908,7 @@ var mcpConfigResultSchema = external_exports.object({
73593
73908
  });
73594
73909
 
73595
73910
  // src/client/runtime-client.ts
73596
- var import_promises71 = require("fs/promises");
73911
+ var import_promises72 = require("fs/promises");
73597
73912
  init_acp();
73598
73913
  init_runtime_v2();
73599
73914
 
@@ -73654,7 +73969,7 @@ var DEFAULT_BACKOFF = { initialMs: 250, maxMs: 3e4 };
73654
73969
  async function readDiscovery(path4) {
73655
73970
  let text3;
73656
73971
  try {
73657
- text3 = await (0, import_promises71.readFile)(path4, "utf8");
73972
+ text3 = await (0, import_promises72.readFile)(path4, "utf8");
73658
73973
  } catch (error62) {
73659
73974
  throw new RuntimeClientError("unavailable", "The runtime is not running", { cause: error62 });
73660
73975
  }
@@ -74037,7 +74352,7 @@ async function sendNativeHookSignal(discoveryPath, hookSignal, signal) {
74037
74352
 
74038
74353
  // src/sessions/index.ts
74039
74354
  var import_node_crypto32 = require("crypto");
74040
- var import_promises72 = require("fs/promises");
74355
+ var import_promises73 = require("fs/promises");
74041
74356
  var import_node_path71 = require("path");
74042
74357
  init_runtime_v2();
74043
74358
 
@@ -74084,7 +74399,7 @@ var DEFAULT_MAX_ACTIVE_RUNS = 32;
74084
74399
  var HOLDER_BUSY = "busy";
74085
74400
  async function listIds(dir, schema) {
74086
74401
  const ids = [];
74087
- for (const name of await (0, import_promises72.readdir)(dir).catch(() => [])) {
74402
+ for (const name of await (0, import_promises73.readdir)(dir).catch(() => [])) {
74088
74403
  const parsed = schema.safeParse(name);
74089
74404
  if (parsed.success) ids.push(parsed.data);
74090
74405
  }
@@ -74109,9 +74424,9 @@ async function removeHolderFiles(files) {
74109
74424
  sessionActivityPath(files.dir)
74110
74425
  ];
74111
74426
  for (const path4 of holderWritten) {
74112
- await (0, import_promises72.rm)(path4, { force: true });
74427
+ await (0, import_promises73.rm)(path4, { force: true });
74113
74428
  }
74114
- await (0, import_promises72.rmdir)(files.dir).catch((error62) => {
74429
+ await (0, import_promises73.rmdir)(files.dir).catch((error62) => {
74115
74430
  if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(errnoCode(error62) ?? "")) throw error62;
74116
74431
  });
74117
74432
  }
@@ -74307,7 +74622,7 @@ async function openSessions(deps) {
74307
74622
  const meta3 = await readRunMeta(dir.meta);
74308
74623
  const last = await readLastRecord(dir.log);
74309
74624
  if (meta3 === null || last === null) return null;
74310
- const logged = await (0, import_promises72.stat)(dir.log).catch((error62) => {
74625
+ const logged = await (0, import_promises73.stat)(dir.log).catch((error62) => {
74311
74626
  if (errnoCode(error62) === "ENOENT") return null;
74312
74627
  throw error62;
74313
74628
  });
@@ -74735,7 +75050,7 @@ function takeEnrollmentCodeFromEnv(env = process.env) {
74735
75050
  }
74736
75051
 
74737
75052
  // src/cli/context.ts
74738
- var import_promises73 = require("fs/promises");
75053
+ var import_promises74 = require("fs/promises");
74739
75054
  var import_node_os11 = require("os");
74740
75055
  var import_node_path73 = require("path");
74741
75056
  var DESKTOP_BUNDLE_IDS = {
@@ -74785,7 +75100,7 @@ async function installedServiceSpec(ctx) {
74785
75100
  const spec = serviceSpec(ctx);
74786
75101
  if (ctx.config.host === "app") return spec;
74787
75102
  const layout = installLayout(ctx.config.installDir, ctx.config.profile);
74788
- const installed = await (0, import_promises73.access)(layout.launcher).then(
75103
+ const installed = await (0, import_promises74.access)(layout.launcher).then(
74789
75104
  () => true,
74790
75105
  () => false
74791
75106
  );
@@ -74916,7 +75231,7 @@ var manifestRevisionSchema = external_exports.object({ revision: external_export
74916
75231
  async function manifestRevision(path4) {
74917
75232
  let raw;
74918
75233
  try {
74919
- raw = JSON.parse(await (0, import_promises74.readFile)(path4, "utf8"));
75234
+ raw = JSON.parse(await (0, import_promises75.readFile)(path4, "utf8"));
74920
75235
  } catch (error62) {
74921
75236
  throw new RuntimeFault("invalid_file", `Cannot read the skill manifest at ${path4}`, {
74922
75237
  cause: error62
@@ -74970,7 +75285,7 @@ async function runSkills(argv) {
74970
75285
  }
74971
75286
 
74972
75287
  // src/cli/commands/doctor.ts
74973
- var import_promises77 = require("fs/promises");
75288
+ var import_promises78 = require("fs/promises");
74974
75289
  var import_node_path77 = require("path");
74975
75290
  init_runtime_v2();
74976
75291
 
@@ -75019,14 +75334,14 @@ var storedCredentialSchema = external_exports.object({
75019
75334
  renewalToken: external_exports.string().min(1).optional(),
75020
75335
  issuedAt: external_exports.iso.datetime().optional()
75021
75336
  });
75022
- function credentialStoreFor(paths, kind, access7) {
75337
+ function credentialStoreFor(paths, kind, access8) {
75023
75338
  return openCredentialStore({
75024
75339
  kind,
75025
75340
  filePath: paths.credential,
75026
75341
  stateDir: paths.stateDir,
75027
- exec: access7.exec,
75028
- ...access7.keychainPath === void 0 ? {} : { keychainPath: access7.keychainPath },
75029
- ...access7.platform === void 0 ? {} : { platform: access7.platform }
75342
+ exec: access8.exec,
75343
+ ...access8.keychainPath === void 0 ? {} : { keychainPath: access8.keychainPath },
75344
+ ...access8.platform === void 0 ? {} : { platform: access8.platform }
75030
75345
  });
75031
75346
  }
75032
75347
  function credentialFromGrant(grant, clock) {
@@ -75046,10 +75361,10 @@ async function saveGrant({
75046
75361
  storeKind,
75047
75362
  grant,
75048
75363
  clock,
75049
- access: access7
75364
+ access: access8
75050
75365
  }) {
75051
75366
  const previous = await readMachineFile(paths);
75052
- await credentialStoreFor(paths, storeKind, access7).write(credentialFromGrant(grant, clock));
75367
+ await credentialStoreFor(paths, storeKind, access8).write(credentialFromGrant(grant, clock));
75053
75368
  const machine = {
75054
75369
  machineId: grant.machineId,
75055
75370
  endpoints: grant.endpoints,
@@ -75058,7 +75373,7 @@ async function saveGrant({
75058
75373
  await writeJsonFileAtomic(paths.machine, machine);
75059
75374
  await rememberInstallationMachine(paths, machine.machineId);
75060
75375
  if (previous !== null && previous.credentialStore !== storeKind) {
75061
- await credentialStoreFor(paths, previous.credentialStore, access7).clear();
75376
+ await credentialStoreFor(paths, previous.credentialStore, access8).clear();
75062
75377
  }
75063
75378
  return machine;
75064
75379
  }
@@ -75179,7 +75494,7 @@ async function authorizeDevice(input2) {
75179
75494
  }
75180
75495
 
75181
75496
  // src/identity/enroll.ts
75182
- var import_promises75 = require("fs/promises");
75497
+ var import_promises76 = require("fs/promises");
75183
75498
  init_runtime_v2();
75184
75499
  async function enrollMachine(input2) {
75185
75500
  const machineId = input2.machineId ?? (await readMachineFile(input2.paths))?.machineId ?? (await readInstallation(input2.paths))?.machineId;
@@ -75262,12 +75577,12 @@ async function enrollFromGrantFile(input2) {
75262
75577
  clock: input2.clock,
75263
75578
  access: input2.access
75264
75579
  });
75265
- await (0, import_promises75.rm)(input2.grantPath, { force: true });
75580
+ await (0, import_promises76.rm)(input2.grantPath, { force: true });
75266
75581
  return machine;
75267
75582
  }
75268
75583
 
75269
75584
  // src/identity/migrate-v1.ts
75270
- var import_promises76 = require("fs/promises");
75585
+ var import_promises77 = require("fs/promises");
75271
75586
  var import_node_path75 = require("path");
75272
75587
  init_runtime_v2();
75273
75588
  init_zod();
@@ -75353,12 +75668,12 @@ async function scrubLegacyInstall(install2) {
75353
75668
  const scrubbed = { ...install2.config, migratedToRuntimeV2: true };
75354
75669
  for (const key of SCRUBBED_KEYS) delete scrubbed[key];
75355
75670
  await writeJsonFileAtomic(`${install2.configPath}.migrated-v1`, scrubbed);
75356
- await (0, import_promises76.rm)(install2.configPath, { force: true });
75357
- await (0, import_promises76.rm)(install2.ownerLeasePath, { force: true });
75671
+ await (0, import_promises77.rm)(install2.configPath, { force: true });
75672
+ await (0, import_promises77.rm)(install2.ownerLeasePath, { force: true });
75358
75673
  }
75359
75674
  async function retireLegacyInstall(install2) {
75360
- await (0, import_promises76.rename)(install2.configPath, `${install2.configPath}.retired-v1`);
75361
- await (0, import_promises76.rm)(install2.ownerLeasePath, { force: true });
75675
+ await (0, import_promises77.rename)(install2.configPath, `${install2.configPath}.retired-v1`);
75676
+ await (0, import_promises77.rm)(install2.ownerLeasePath, { force: true });
75362
75677
  }
75363
75678
  async function exchangeCredential(deps) {
75364
75679
  const { config: config2 } = deps.install;
@@ -75423,7 +75738,7 @@ async function migrateFromV1(deps) {
75423
75738
  }
75424
75739
 
75425
75740
  // src/identity/index.ts
75426
- async function readStoredIdentity(paths, access7) {
75741
+ async function readStoredIdentity(paths, access8) {
75427
75742
  const machine = await readJsonFile(paths.machine, machineFileSchema);
75428
75743
  if (machine.kind !== "ok") {
75429
75744
  throw new RuntimeFault(
@@ -75431,7 +75746,7 @@ async function readStoredIdentity(paths, access7) {
75431
75746
  machine.kind === "missing" ? "This computer is not set up yet: run `alan-agent setup`" : `machine.json is invalid: ${machine.reason}`
75432
75747
  );
75433
75748
  }
75434
- const store = credentialStoreFor(paths, machine.value.credentialStore, access7);
75749
+ const store = credentialStoreFor(paths, machine.value.credentialStore, access8);
75435
75750
  const credential = await store.read(storedCredentialSchema);
75436
75751
  if (credential.kind !== "ok") {
75437
75752
  throw new RuntimeFault(
@@ -75441,8 +75756,8 @@ async function readStoredIdentity(paths, access7) {
75441
75756
  }
75442
75757
  return { machine: machine.value, store, credential: credential.value };
75443
75758
  }
75444
- async function loadStoredAccess(paths, access7 = { exec: systemExec }) {
75445
- const { machine, credential } = await readStoredIdentity(paths, access7);
75759
+ async function loadStoredAccess(paths, access8 = { exec: systemExec }) {
75760
+ const { machine, credential } = await readStoredIdentity(paths, access8);
75446
75761
  return { endpoints: machine.endpoints, accessToken: credential.accessToken };
75447
75762
  }
75448
75763
  async function loadIdentity(paths, options = {}) {
@@ -75772,7 +76087,7 @@ async function probeHolder(dir, conversationId) {
75772
76087
  }
75773
76088
  }
75774
76089
  async function holdersCheck(ctx) {
75775
- const names = await (0, import_promises77.readdir)(ctx.paths.sessions).catch(() => []);
76090
+ const names = await (0, import_promises78.readdir)(ctx.paths.sessions).catch(() => []);
75776
76091
  const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path77.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
75777
76092
  const dead = holders.filter((holder) => !holder.alive).length;
75778
76093
  return check2(
@@ -75784,7 +76099,7 @@ async function holdersCheck(ctx) {
75784
76099
  }
75785
76100
  async function freeBytesAt(path4) {
75786
76101
  try {
75787
- const stats = await (0, import_promises77.statfs)(path4);
76102
+ const stats = await (0, import_promises78.statfs)(path4);
75788
76103
  return { path: path4, freeBytes: stats.bavail * stats.bsize };
75789
76104
  } catch (error62) {
75790
76105
  const parent = (0, import_node_path77.dirname)(path4);
@@ -75808,9 +76123,9 @@ var resolveFromLoginShell = (own2) => resolveCliEnvironment({ env: own2, platfor
75808
76123
  async function cliDiscoveryCheck(resolve14) {
75809
76124
  const own2 = readCliEnvironment();
75810
76125
  const env = await resolve14(own2);
75811
- const delimiter = process.platform === "win32" ? ";" : ":";
75812
- const ownDirs = new Set((own2.PATH ?? "").split(delimiter));
75813
- const added = (env.PATH ?? "").split(delimiter).filter((dir) => dir.length > 0 && !ownDirs.has(dir));
76126
+ const delimiter2 = process.platform === "win32" ? ";" : ":";
76127
+ const ownDirs = new Set((own2.PATH ?? "").split(delimiter2));
76128
+ const added = (env.PATH ?? "").split(delimiter2).filter((dir) => dir.length > 0 && !ownDirs.has(dir));
75814
76129
  const commands = await Promise.all(
75815
76130
  PROVIDER_COMMANDS.map(async (provider4) => ({
75816
76131
  backendKind: provider4.backendKind,
@@ -75923,10 +76238,10 @@ async function runDoctor(argv, context = cliContext) {
75923
76238
  }
75924
76239
 
75925
76240
  // src/cli/commands/git-credential.ts
75926
- var import_promises78 = require("fs/promises");
76241
+ var import_promises79 = require("fs/promises");
75927
76242
  var import_node_net4 = require("net");
75928
76243
  var MAX_RESPONSE_BYTES = 64 * 1024;
75929
- async function readAll(stream) {
76244
+ async function readAll2(stream) {
75930
76245
  const chunks = [];
75931
76246
  for await (const chunk of stream) {
75932
76247
  chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
@@ -75935,7 +76250,7 @@ async function readAll(stream) {
75935
76250
  }
75936
76251
  function processIo() {
75937
76252
  return {
75938
- readStdin: () => readAll(process.stdin),
76253
+ readStdin: () => readAll2(process.stdin),
75939
76254
  stdout: (text3) => process.stdout.write(text3),
75940
76255
  stderr: (text3) => process.stderr.write(text3)
75941
76256
  };
@@ -76040,7 +76355,7 @@ async function configure(argv) {
76040
76355
  }
76041
76356
  async function configureGitGateway(config2, gatewayUrl, signal) {
76042
76357
  const { launcher } = installLayout(config2.installDir, config2.profile);
76043
- const installed = await (0, import_promises78.access)(launcher).then(
76358
+ const installed = await (0, import_promises79.access)(launcher).then(
76044
76359
  () => true,
76045
76360
  () => false
76046
76361
  );
@@ -76069,9 +76384,31 @@ async function runGitCredential(argv) {
76069
76384
  }
76070
76385
 
76071
76386
  // src/cli/commands/hold.ts
76072
- var import_node_path78 = require("path");
76387
+ var import_node_path79 = require("path");
76073
76388
  init_agent2();
76074
76389
  init_runtime_v2();
76390
+
76391
+ // src/cli/commands/cli-flag-probes.ts
76392
+ var import_node_path78 = require("path");
76393
+ init_claude();
76394
+ var CLI_FLAG_PROBES_FILE = "cli-flag-probes.json";
76395
+ function openCliFlagProbe(stateDir) {
76396
+ return createFlagProbe({
76397
+ store: createFileFlagProbeStore((0, import_node_path78.join)(stateDir, CLI_FLAG_PROBES_FILE))
76398
+ });
76399
+ }
76400
+ async function prewarmCliFlagProbes(stateDir, env) {
76401
+ if (await resolveCommandOnPath("claude", env, process.platform) === null) return;
76402
+ const flags = openCliFlagProbe(stateDir);
76403
+ await createClaudeCapabilityProbe(flags).detect({
76404
+ command: "claude",
76405
+ env,
76406
+ needsApproveMcps: true
76407
+ });
76408
+ await flags.persisted();
76409
+ }
76410
+
76411
+ // src/cli/commands/hold.ts
76075
76412
  async function machineAccess(paths, log, conversationId, transport) {
76076
76413
  const initial = await loadStoredAccess(paths).catch(
76077
76414
  (error62) => {
@@ -76080,10 +76417,10 @@ async function machineAccess(paths, log, conversationId, transport) {
76080
76417
  }
76081
76418
  );
76082
76419
  const api = async () => {
76083
- const access7 = await loadStoredAccess(paths);
76420
+ const access8 = await loadStoredAccess(paths);
76084
76421
  return createHolderApiClient({
76085
- apiUrl: access7.endpoints.apiUrl,
76086
- accessToken: () => access7.accessToken,
76422
+ apiUrl: access8.endpoints.apiUrl,
76423
+ accessToken: () => access8.accessToken,
76087
76424
  transport
76088
76425
  });
76089
76426
  };
@@ -76128,7 +76465,7 @@ async function runHold(argv) {
76128
76465
  const config2 = loadRuntimeConfig();
76129
76466
  const paths = runtimePaths(config2.stateDir);
76130
76467
  const log = __using(_stack, openFileLog(
76131
- (0, import_node_path78.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
76468
+ (0, import_node_path79.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
76132
76469
  config2.logLevel,
76133
76470
  systemClock
76134
76471
  ));
@@ -76138,19 +76475,19 @@ async function runHold(argv) {
76138
76475
  process.platform
76139
76476
  );
76140
76477
  const transport = __using(_stack, createHttpTransport());
76141
- const access7 = await machineAccess(paths, log, launch.value.conversationId, transport);
76142
- const credentialPath = (0, import_node_path78.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
76143
- const managedMcp = __using(_stack, access7.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
76144
- managedMcp: access7.managedMcp,
76478
+ const access8 = await machineAccess(paths, log, launch.value.conversationId, transport);
76479
+ const credentialPath = (0, import_node_path79.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
76480
+ const managedMcp = __using(_stack, access8.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
76481
+ managedMcp: access8.managedMcp,
76145
76482
  conversationId: launch.value.conversationId,
76146
76483
  credentialPath
76147
76484
  }), true);
76148
- const providerEnvironment2 = access7.managedMcp === void 0 ? cliEnvironment : {
76485
+ const providerEnvironment2 = access8.managedMcp === void 0 ? cliEnvironment : {
76149
76486
  ...cliEnvironment,
76150
- [ALAN_MCP_URL_ENV]: access7.managedMcp.url,
76487
+ [ALAN_MCP_URL_ENV]: access8.managedMcp.url,
76151
76488
  [ALAN_MCP_CREDENTIAL_FILE_ENV]: credentialPath
76152
76489
  };
76153
- const flags = createFlagProbe();
76490
+ const flags = openCliFlagProbe(paths.stateDir);
76154
76491
  await runHolder({
76155
76492
  launch: launch.value,
76156
76493
  driver: createProviderDrivers({
@@ -76159,12 +76496,13 @@ async function runHold(argv) {
76159
76496
  timings: config2.sessionTimings,
76160
76497
  log,
76161
76498
  ...managedMcp === void 0 ? {} : { managedMcp },
76162
- codexCredentials: access7.codexCredentials,
76163
- installedSkills: () => installedSkillFolders(skillsLayout(paths.stateDir))
76499
+ codexCredentials: access8.codexCredentials,
76500
+ installedSkills: () => installedSkillFolders(skillsLayout(paths.stateDir)),
76501
+ flagProbe: flags
76164
76502
  }),
76165
76503
  clock: systemClock,
76166
76504
  log,
76167
- inputs: { source: access7.source, tmpDir: paths.tmp },
76505
+ inputs: { source: access8.source, tmpDir: paths.tmp },
76168
76506
  machine: {
76169
76507
  env: cliEnvironment,
76170
76508
  stateDir: paths.stateDir,
@@ -76185,7 +76523,7 @@ async function runHold(argv) {
76185
76523
  }
76186
76524
 
76187
76525
  // src/cli/commands/hook.ts
76188
- var import_node_path79 = require("path");
76526
+ var import_node_path80 = require("path");
76189
76527
  var RUNTIME_ANSWER_MS = 2e3;
76190
76528
  var DEBUG_VARIABLE = "ALAN_HOOK_DEBUG";
76191
76529
  function flag(argv, name) {
@@ -76217,7 +76555,7 @@ async function forwardHook(argv, io) {
76217
76555
  return "transcript outside provider root";
76218
76556
  }
76219
76557
  const verdict = await io.send(
76220
- (0, import_node_path79.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
76558
+ (0, import_node_path80.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
76221
76559
  hookSignal,
76222
76560
  AbortSignal.timeout(RUNTIME_ANSWER_MS)
76223
76561
  );
@@ -76253,7 +76591,7 @@ async function runHook(argv, overrides = {}) {
76253
76591
  }
76254
76592
 
76255
76593
  // src/cli/commands/ingestion-hooks.ts
76256
- var import_promises79 = require("fs/promises");
76594
+ var import_promises80 = require("fs/promises");
76257
76595
  var CODEX_TRUST_NOTE = "Codex runs new hooks only after you review them: open /hooks in Codex.";
76258
76596
  function isAction(value2) {
76259
76597
  return value2 === "enable" || value2 === "disable" || value2 === "status";
@@ -76276,7 +76614,7 @@ function errorMessage2(error62) {
76276
76614
  return error62 instanceof Error ? error62.message : String(error62);
76277
76615
  }
76278
76616
  async function exists5(path4) {
76279
- return (0, import_promises79.access)(path4).then(
76617
+ return (0, import_promises80.access)(path4).then(
76280
76618
  () => true,
76281
76619
  () => false
76282
76620
  );
@@ -76379,10 +76717,10 @@ async function runIntegrationsCommand(argv) {
76379
76717
  }
76380
76718
 
76381
76719
  // src/cli/commands/legacy.ts
76382
- var import_node_path81 = require("path");
76720
+ var import_node_path82 = require("path");
76383
76721
 
76384
76722
  // src/cli/commands/setup.ts
76385
- var import_node_path80 = require("path");
76723
+ var import_node_path81 = require("path");
76386
76724
  init_zod();
76387
76725
 
76388
76726
  // src/cli/legacy.ts
@@ -76488,7 +76826,7 @@ async function grantFileCredential(argv, grantPath, ctx, deps) {
76488
76826
  return enrollFromGrantFile({
76489
76827
  paths: ctx.paths,
76490
76828
  storeKind: credentialStoreFlag(argv) ?? ctx.config.credentialStore,
76491
- grantPath: (0, import_node_path80.resolve)(grantPath),
76829
+ grantPath: (0, import_node_path81.resolve)(grantPath),
76492
76830
  clock: deps.clock,
76493
76831
  access: ctx.access
76494
76832
  });
@@ -76564,7 +76902,7 @@ async function runSetup(argv, signal) {
76564
76902
  var _stack = [];
76565
76903
  try {
76566
76904
  const ctx = cliContext();
76567
- const log = __using(_stack, openFileLog((0, import_node_path80.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76905
+ const log = __using(_stack, openFileLog((0, import_node_path81.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76568
76906
  const result = await setupMachine(argv, ctx, {
76569
76907
  enrollment: (apiUrl) => createEnrollmentClient({ apiUrl }),
76570
76908
  isProcessAlive,
@@ -76647,7 +76985,7 @@ async function runToken(argv, signal) {
76647
76985
  );
76648
76986
  }
76649
76987
  const ctx = cliContext();
76650
- const log = __using(_stack, openFileLog((0, import_node_path81.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76988
+ const log = __using(_stack, openFileLog((0, import_node_path82.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76651
76989
  const result = await rotateMachineCredential(ctx, { clock: systemClock, log, signal });
76652
76990
  process.stdout.write(`${rotationMessage(result)}
76653
76991
  `);
@@ -76659,8 +76997,8 @@ async function runToken(argv, signal) {
76659
76997
  }
76660
76998
 
76661
76999
  // src/cli/commands/logout.ts
76662
- var import_promises80 = require("fs/promises");
76663
- var import_node_path82 = require("path");
77000
+ var import_promises81 = require("fs/promises");
77001
+ var import_node_path83 = require("path");
76664
77002
  init_runtime_v2();
76665
77003
  var RUNTIME_EXIT_WAIT_MS = 35e3;
76666
77004
  var TURN_END_WAIT_MS = 3e4;
@@ -76719,9 +77057,9 @@ async function stopHolder(launch, deps, outcome2) {
76719
77057
  }
76720
77058
  async function stopHeldRuns(ctx, deps, outcome2 = "aborted") {
76721
77059
  const stopped = [];
76722
- for (const name of await (0, import_promises80.readdir)(ctx.paths.sessions).catch(() => [])) {
77060
+ for (const name of await (0, import_promises81.readdir)(ctx.paths.sessions).catch(() => [])) {
76723
77061
  const launch = await readJsonFile(
76724
- (0, import_node_path82.join)(ctx.paths.sessions, name, "launch.json"),
77062
+ (0, import_node_path83.join)(ctx.paths.sessions, name, "launch.json"),
76725
77063
  holderLaunchSchema
76726
77064
  );
76727
77065
  if (launch.kind !== "ok") continue;
@@ -76758,13 +77096,13 @@ async function forgetMachineLocally(ctx) {
76758
77096
  const machine = await readMachineFile(ctx.paths);
76759
77097
  if (machine === null) return;
76760
77098
  await credentialStoreFor(ctx.paths, machine.credentialStore, ctx.access).clear();
76761
- await (0, import_promises80.rm)(ctx.paths.machine, { force: true });
77099
+ await (0, import_promises81.rm)(ctx.paths.machine, { force: true });
76762
77100
  }
76763
77101
  async function runLogout(argv, signal) {
76764
77102
  var _stack = [];
76765
77103
  try {
76766
77104
  const ctx = cliContext();
76767
- const log = __using(_stack, openFileLog((0, import_node_path82.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
77105
+ const log = __using(_stack, openFileLog((0, import_node_path83.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76768
77106
  const result = await logoutMachine(argv, ctx, {
76769
77107
  api: (apiUrl, accessToken) => createApiClient({ apiUrl, accessToken }),
76770
77108
  stopHeldRuns,
@@ -76782,7 +77120,7 @@ async function runLogout(argv, signal) {
76782
77120
 
76783
77121
  // src/cli/commands/run.ts
76784
77122
  var import_node_fs27 = require("fs");
76785
- var import_node_path87 = require("path");
77123
+ var import_node_path88 = require("path");
76786
77124
 
76787
77125
  // src/local-api/app-attachments.ts
76788
77126
  function createAppAttachments(clock) {
@@ -76859,9 +77197,9 @@ function createRunAppends() {
76859
77197
 
76860
77198
  // src/local-api/server.ts
76861
77199
  var import_node_crypto36 = require("crypto");
76862
- var import_promises81 = require("fs/promises");
77200
+ var import_promises82 = require("fs/promises");
76863
77201
  var import_node_http4 = require("http");
76864
- var import_node_path83 = require("path");
77202
+ var import_node_path84 = require("path");
76865
77203
 
76866
77204
  // src/local-api/guard.ts
76867
77205
  var import_node_crypto35 = require("crypto");
@@ -77917,7 +78255,7 @@ async function serveLocalApi(deps) {
77917
78255
  startedAtMs,
77918
78256
  runtimeVersion: deps.runtimeVersion
77919
78257
  };
77920
- const discoveryPath = (0, import_node_path83.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
78258
+ const discoveryPath = (0, import_node_path84.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
77921
78259
  await writeJsonFileAtomic(discoveryPath, discovery);
77922
78260
  const followers = startMaintenance({
77923
78261
  everyMs: limits.refreshEveryMs,
@@ -77951,7 +78289,7 @@ async function serveLocalApi(deps) {
77951
78289
  await watchedStatus[Symbol.asyncDispose]();
77952
78290
  const current = await readJsonFile(discoveryPath, localApiDiscoverySchema);
77953
78291
  if (current.kind === "ok" && current.value.token === token) {
77954
- await (0, import_promises81.rm)(discoveryPath, { force: true });
78292
+ await (0, import_promises82.rm)(discoveryPath, { force: true });
77955
78293
  }
77956
78294
  await closeServer(server);
77957
78295
  log.info("local_api.closed", {});
@@ -78036,7 +78374,7 @@ function machineFeatureActions(deps) {
78036
78374
  }
78037
78375
 
78038
78376
  // src/cli/commands/machine-plane.ts
78039
- var import_node_path86 = require("path");
78377
+ var import_node_path87 = require("path");
78040
78378
 
78041
78379
  // src/link/index.ts
78042
78380
  init_runtime_v2();
@@ -81704,7 +82042,7 @@ function refusalFailure(refusal2) {
81704
82042
  }
81705
82043
 
81706
82044
  // src/link/probe.ts
81707
- var import_promises82 = require("dns/promises");
82045
+ var import_promises83 = require("dns/promises");
81708
82046
  var import_node_net5 = require("net");
81709
82047
  var import_node_tls2 = require("tls");
81710
82048
  var PROBE_TIMEOUT_MS4 = 5e3;
@@ -81740,7 +82078,7 @@ async function connectOnce(url3, clock) {
81740
82078
  }
81741
82079
  async function probeEndpoint(url3, clock) {
81742
82080
  try {
81743
- await (0, import_promises82.lookup)(url3.hostname);
82081
+ await (0, import_promises83.lookup)(url3.hostname);
81744
82082
  } catch (error62) {
81745
82083
  const reason = classifyTransportFailure(error62);
81746
82084
  return reason === "other" ? "dns" : reason;
@@ -81838,12 +82176,17 @@ var CAPABILITIES_ACK_TIMEOUT_MS = 1e4;
81838
82176
  var REDIAL_BASE_MS = 1e3;
81839
82177
  var REDIAL_MAX_MS = 1e4;
81840
82178
  var MAX_CREDENTIAL_FAILURES = 3;
82179
+ var CREDENTIAL_RETRY_BASE_MS = 3e4;
82180
+ var CREDENTIAL_RETRY_MAX_MS = 5 * 6e4;
81841
82181
  var DISABLED_RETRY_MS = 5 * 6e4;
81842
82182
  var WAKE_PROBE_MS = 5e3;
81843
82183
  var SERVER_DROPS_SILENT_SOCKET_MS = 55e3;
81844
82184
  function redialDelayMs(attempt2) {
81845
82185
  return Math.min(REDIAL_BASE_MS * 2 ** attempt2, REDIAL_MAX_MS) * (0.5 + 0.5 * Math.random());
81846
82186
  }
82187
+ function credentialRetryDelayMs(slowAttempt) {
82188
+ return Math.min(CREDENTIAL_RETRY_BASE_MS * 2 ** slowAttempt, CREDENTIAL_RETRY_MAX_MS);
82189
+ }
81847
82190
  async function answerWorkspaceQuery(raw, options, log) {
81848
82191
  const parsed = workspaceQueryRequestSchema.safeParse(raw);
81849
82192
  if (!parsed.success) {
@@ -81939,6 +82282,12 @@ function connectLink(options) {
81939
82282
  redialAfter(redialDelayMs(retry.attempt++), options.refreshCredential);
81940
82283
  return;
81941
82284
  }
82285
+ stop(failure7);
82286
+ redialAfter(
82287
+ credentialRetryDelayMs(retry.credentialFailures - MAX_CREDENTIAL_FAILURES),
82288
+ options.refreshCredential
82289
+ );
82290
+ return;
81942
82291
  }
81943
82292
  stop(failure7);
81944
82293
  if (refusal2.code === "machine_disabled") redialAfter(DISABLED_RETRY_MS);
@@ -82135,20 +82484,33 @@ function fingerprintOf(desired) {
82135
82484
  var FAILED_READ_RETRY_MS = 3e4;
82136
82485
  function createDesiredSync(deps) {
82137
82486
  const { clock, log } = deps;
82138
- const state = { known: null, dueAt: 0 };
82487
+ const state = {
82488
+ known: null,
82489
+ dueAt: 0,
82490
+ failures: 0
82491
+ };
82139
82492
  const schedule = () => {
82140
82493
  state.dueAt = clock.monotonic() + deps.everyMs * (0.75 + 0.5 * deps.random());
82141
82494
  };
82142
82495
  schedule();
82143
82496
  const read = async (signal) => {
82144
82497
  try {
82145
- return await deps.read(state.known?.etag ?? null, signal);
82498
+ const result = await deps.read(state.known?.etag ?? null, signal);
82499
+ state.failures = 0;
82500
+ return result;
82146
82501
  } catch (error62) {
82147
- state.dueAt = Math.min(state.dueAt, clock.monotonic() + FAILED_READ_RETRY_MS);
82502
+ state.failures = Math.min(state.failures + 1, 3);
82503
+ const retryMs = Math.min(
82504
+ deps.everyMs,
82505
+ 4 * FAILED_READ_RETRY_MS,
82506
+ FAILED_READ_RETRY_MS * 2 ** (state.failures - 1) * (0.75 + 0.5 * deps.random())
82507
+ );
82508
+ state.dueAt = Math.min(state.dueAt, clock.monotonic() + retryMs);
82148
82509
  throw error62;
82149
82510
  }
82150
82511
  };
82151
82512
  const accept = (desired, etag) => {
82513
+ state.failures = 0;
82152
82514
  state.known = { desired, fingerprint: fingerprintOf(desired), etag };
82153
82515
  schedule();
82154
82516
  deps.apply(desired);
@@ -82267,7 +82629,7 @@ function createReconciler(host, lifecycle, log, signal) {
82267
82629
  }
82268
82630
 
82269
82631
  // src/uploader/index.ts
82270
- var import_promises83 = require("fs/promises");
82632
+ var import_promises84 = require("fs/promises");
82271
82633
  init_runtime_v2();
82272
82634
  init_zod();
82273
82635
  var RETRY_DELAYS_MS = [250, 500, 1e3, 2e3, 5e3, 1e4, 3e4];
@@ -82557,13 +82919,13 @@ function startUploader({
82557
82919
  const isDone = (runId) => sealed.has(runId) || archive?.has(runId) === true;
82558
82920
  const unsealedRunIds = async () => {
82559
82921
  const runIds = [];
82560
- for (const name of await (0, import_promises83.readdir)(runsDir).catch(() => [])) {
82922
+ for (const name of await (0, import_promises84.readdir)(runsDir).catch(() => [])) {
82561
82923
  const runId = runIdSchema.safeParse(name);
82562
82924
  if (runId.success && !isDone(runId.data)) runIds.push(runId.data);
82563
82925
  }
82564
82926
  return runIds;
82565
82927
  };
82566
- const hasProgress = async (runId) => await (0, import_promises83.stat)(runDirectory(runsDir, runId).upload).catch(() => null) !== null;
82928
+ const hasProgress = async (runId) => await (0, import_promises84.stat)(runDirectory(runsDir, runId).upload).catch(() => null) !== null;
82567
82929
  const sweep2 = async () => {
82568
82930
  for (const runId of await unsealedRunIds()) {
82569
82931
  if (!await hasProgress(runId)) run2(runId);
@@ -82579,13 +82941,13 @@ function startUploader({
82579
82941
  const dir = runDirectory(runsDir, runId);
82580
82942
  const progress = await readJsonFile(dir.upload, uploadProgressSchema);
82581
82943
  if (progress.kind !== "ok" || !progress.value.sealed) return false;
82582
- const sealedAt = (await (0, import_promises83.stat)(dir.upload)).mtimeMs;
82944
+ const sealedAt = (await (0, import_promises84.stat)(dir.upload)).mtimeMs;
82583
82945
  if (clock.now() - sealedAt < options.sealedForMs) return false;
82584
82946
  return (await readLastRecord(dir.log))?.update.sessionUpdate === "_alan/run.ended";
82585
82947
  };
82586
82948
  const archivable = async (options) => {
82587
82949
  const found = [];
82588
- for (const name of await (0, import_promises83.readdir)(runsDir).catch(() => [])) {
82950
+ for (const name of await (0, import_promises84.readdir)(runsDir).catch(() => [])) {
82589
82951
  const runId = runIdSchema.safeParse(name);
82590
82952
  if (!runId.success || archive?.has(runId.data)) continue;
82591
82953
  try {
@@ -82622,7 +82984,7 @@ function startUploader({
82622
82984
 
82623
82985
  // src/cli/commands/activity-lease.ts
82624
82986
  var import_node_fs26 = require("fs");
82625
- var import_node_path84 = require("path");
82987
+ var import_node_path85 = require("path");
82626
82988
  var import_node_worker_threads = require("worker_threads");
82627
82989
  init_runtime_v2();
82628
82990
  var LEASE_BUNDLE = "alan-lease.cjs";
@@ -82646,7 +83008,7 @@ function spawnThread(script, data) {
82646
83008
  };
82647
83009
  }
82648
83010
  function leaseWorkerScript(bundlePath, exists6 = import_node_fs26.existsSync) {
82649
- const lean = (0, import_node_path84.join)((0, import_node_path84.dirname)(bundlePath), LEASE_BUNDLE);
83011
+ const lean = (0, import_node_path85.join)((0, import_node_path85.dirname)(bundlePath), LEASE_BUNDLE);
82650
83012
  return exists6(lean) ? lean : bundlePath;
82651
83013
  }
82652
83014
  function leasedRuns(held) {
@@ -82666,7 +83028,7 @@ function startActivityLeases(deps) {
82666
83028
  epoch: Math.floor(clock.now()),
82667
83029
  sessionsDir: deps.paths.sessions,
82668
83030
  runsDir: deps.paths.runs,
82669
- logPath: (0, import_node_path84.join)(deps.paths.logs, "runtime.jsonl"),
83031
+ logPath: (0, import_node_path85.join)(deps.paths.logs, "runtime.jsonl"),
82670
83032
  logLevel: deps.logLevel,
82671
83033
  intervalMs: ACTIVITY_LEASE_INTERVAL_MS,
82672
83034
  watchdogMs: deps.watchdogMs,
@@ -82906,12 +83268,12 @@ async function startMachineNativeIngest(deps) {
82906
83268
  }
82907
83269
 
82908
83270
  // src/cli/commands/run-updates.ts
82909
- var import_node_path85 = require("path");
83271
+ var import_node_path86 = require("path");
82910
83272
  init_runtime_v2();
82911
83273
  var UPDATE_CHECK_EVERY_MS = 6 * 60 * 60 * 1e3;
82912
83274
  var DEFERRED_RETRY_MS = 5 * 60 * 1e3;
82913
83275
  function isInstalledBundle(layout, bundlePath) {
82914
- return (0, import_node_path85.resolve)((0, import_node_path85.dirname)((0, import_node_path85.dirname)(bundlePath))) === (0, import_node_path85.resolve)(layout.versions);
83276
+ return (0, import_node_path86.resolve)((0, import_node_path86.dirname)((0, import_node_path86.dirname)(bundlePath))) === (0, import_node_path86.resolve)(layout.versions);
82915
83277
  }
82916
83278
  async function settleUpgradeOnStart({
82917
83279
  layout,
@@ -83018,7 +83380,7 @@ function startRuntimeUpdates(options) {
83018
83380
  layout,
83019
83381
  release: npmRelease,
83020
83382
  tarball: await options.downloader.download(npmRelease.dist.tarball, signal),
83021
- tmpDir: (0, import_node_path85.join)(layout.root, ".downloads")
83383
+ tmpDir: (0, import_node_path86.join)(layout.root, ".downloads")
83022
83384
  });
83023
83385
  await lifecycle.exclusive("upgrade", async () => {
83024
83386
  await recordPendingUpgrade(layout, currentVersion2, version2, clock.now());
@@ -83273,7 +83635,7 @@ async function startMachinePlane(deps) {
83273
83635
  [ALAN_MANAGED_SESSION_ENV]: "1"
83274
83636
  },
83275
83637
  cwd: paths.stateDir,
83276
- outputPath: (0, import_node_path86.join)(paths.logs, "holders.log")
83638
+ outputPath: (0, import_node_path87.join)(paths.logs, "holders.log")
83277
83639
  },
83278
83640
  deps.holderIsolation
83279
83641
  );
@@ -83535,6 +83897,9 @@ async function startMachinePlane(deps) {
83535
83897
  log
83536
83898
  })
83537
83899
  );
83900
+ prewarmCliFlagProbes(paths.stateDir, cliEnvironment).catch(
83901
+ (error62) => log.warn("cli_flag_probes.prewarm_failed", { error: error62 })
83902
+ );
83538
83903
  const workspaceRoot2 = config2.workspaceRoot;
83539
83904
  if (workspaceRoot2 !== null && deps.gitGatewayReady !== void 0) {
83540
83905
  void deps.gitGatewayReady.then(async (ready) => {
@@ -83545,7 +83910,7 @@ async function startMachinePlane(deps) {
83545
83910
  git: createGitRunner({ env: cliEnvironment }),
83546
83911
  clock,
83547
83912
  log,
83548
- dir: (0, import_node_path86.join)(paths.stateDir, "checkout-freshness")
83913
+ dir: (0, import_node_path87.join)(paths.stateDir, "checkout-freshness")
83549
83914
  },
83550
83915
  stopped.signal
83551
83916
  );
@@ -83852,7 +84217,7 @@ function lockWaitMs(argv) {
83852
84217
  }
83853
84218
  async function openManagedProviders(config2, paths) {
83854
84219
  const providerEnv = readCliEnvironment();
83855
- const bundledNpm = (0, import_node_path87.join)((0, import_node_path87.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
84220
+ const bundledNpm = (0, import_node_path88.join)((0, import_node_path88.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
83856
84221
  const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs27.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
83857
84222
  const npmPath = providerToolchain?.node ?? await resolveCommandOnPath("npm", providerEnv, process.platform);
83858
84223
  const npmOptions = npmPath === null || process.platform === "win32" && providerToolchain === null ? null : {
@@ -83860,7 +84225,7 @@ async function openManagedProviders(config2, paths) {
83860
84225
  ...providerToolchain === null ? {} : { argsBeforeNpm: [providerToolchain.npmCli] },
83861
84226
  env: providerEnv
83862
84227
  };
83863
- const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path87.dirname)(providerToolchain.node);
84228
+ const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path88.dirname)(providerToolchain.node);
83864
84229
  const probeEnv = providerNodeDir === void 0 ? providerEnv : {
83865
84230
  ...providerEnv,
83866
84231
  PATH: `${providerNodeDir}${pathDelimiter(process.platform)}${envValue(providerEnv, "PATH")}`
@@ -83870,10 +84235,10 @@ async function openManagedProviders(config2, paths) {
83870
84235
  throw new Error("Provider installer is unavailable on this computer");
83871
84236
  };
83872
84237
  const managed = createManagedProviderClis({
83873
- root: (0, import_node_path87.join)(paths.stateDir, "provider-clis"),
84238
+ root: (0, import_node_path88.join)(paths.stateDir, "provider-clis"),
83874
84239
  resolveVersion: npmOptions === null ? unavailable : createNpmVersionResolver(npmOptions),
83875
84240
  installPackage: npmOptions === null ? unavailable : createNpmPackageInstaller(npmOptions),
83876
- probe: (executable, backendKind) => probeManagedProvider(executable, backendKind, canonicalProbeEnv)
84241
+ probe: (executable, backendKind, signal) => probeManagedProvider(executable, backendKind, canonicalProbeEnv, signal)
83877
84242
  });
83878
84243
  await managed.load();
83879
84244
  return { managed, providerNodeDir };
@@ -83902,7 +84267,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
83902
84267
  waitMs: lockWaitMs(argv),
83903
84268
  signal: stop
83904
84269
  }));
83905
- const log = __using(_stack, openFileLog((0, import_node_path87.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
84270
+ const log = __using(_stack, openFileLog((0, import_node_path88.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
83906
84271
  const lifecycle = createLifecycleQueue({ clock, log });
83907
84272
  const install2 = installLayout(config2.installDir, config2.profile);
83908
84273
  const bundlePath = process.argv[1] ?? "";
@@ -83936,7 +84301,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
83936
84301
  openCliEnvironment({
83937
84302
  env: readCliEnvironment(),
83938
84303
  platform: process.platform,
83939
- lastKnownGoodFile: (0, import_node_path87.join)(paths.stateDir, "login-path.json"),
84304
+ lastKnownGoodFile: (0, import_node_path88.join)(paths.stateDir, "login-path.json"),
83940
84305
  clock,
83941
84306
  decorate: (env) => withPackagedAlanCodeEngine(env, bundlePath, process.platform)
83942
84307
  })
@@ -84113,17 +84478,17 @@ async function runServiceCommand(argv, ctx = cliContext()) {
84113
84478
  }
84114
84479
 
84115
84480
  // src/cli/commands/upgrade.ts
84116
- var import_promises84 = require("fs/promises");
84117
- var import_node_path88 = require("path");
84481
+ var import_promises85 = require("fs/promises");
84482
+ var import_node_path89 = require("path");
84118
84483
  function isNotNewer(version2, installed) {
84119
84484
  return installed !== null && isReleaseVersion(version2) && isReleaseVersion(installed) && compareVersions(version2, installed) <= 0;
84120
84485
  }
84121
84486
  async function installFromSource(source) {
84122
84487
  const { layout, from, ifNewer } = source;
84123
- const isTarball = (await (0, import_promises84.stat)(from)).isFile();
84124
- const downloads = (0, import_node_path88.join)(layout.root, ".downloads");
84125
- if (isTarball) await (0, import_promises84.mkdir)(downloads, { recursive: true, mode: 448 });
84126
- const scratch = isTarball ? await (0, import_promises84.mkdtemp)((0, import_node_path88.join)(downloads, "upgrade-")) : null;
84488
+ const isTarball = (await (0, import_promises85.stat)(from)).isFile();
84489
+ const downloads = (0, import_node_path89.join)(layout.root, ".downloads");
84490
+ if (isTarball) await (0, import_promises85.mkdir)(downloads, { recursive: true, mode: 448 });
84491
+ const scratch = isTarball ? await (0, import_promises85.mkdtemp)((0, import_node_path89.join)(downloads, "upgrade-")) : null;
84127
84492
  try {
84128
84493
  const sourceDir = scratch === null ? from : await extractPackageTarball(from, scratch);
84129
84494
  const version2 = await readPackageVersion(sourceDir);
@@ -84131,7 +84496,7 @@ async function installFromSource(source) {
84131
84496
  if (ifNewer && isNotNewer(version2, installed)) return { kind: "skipped", version: version2, installed };
84132
84497
  return { kind: "installed", ...await installVersion(layout, sourceDir) };
84133
84498
  } finally {
84134
- if (scratch !== null) await (0, import_promises84.rm)(scratch, { recursive: true, force: true });
84499
+ if (scratch !== null) await (0, import_promises85.rm)(scratch, { recursive: true, force: true });
84135
84500
  }
84136
84501
  }
84137
84502
  async function runUpgrade(argv) {
@@ -84143,7 +84508,7 @@ async function runUpgrade(argv) {
84143
84508
  const layout = installLayout(config2.installDir, config2.profile);
84144
84509
  const outcome2 = await installFromSource({
84145
84510
  layout,
84146
- from: (0, import_node_path88.resolve)(from),
84511
+ from: (0, import_node_path89.resolve)(from),
84147
84512
  ifNewer: hasFlag(argv, "--if-newer")
84148
84513
  });
84149
84514
  if (outcome2.kind === "skipped") {