@alan-ai-hq/agent-manager-darwin-arm64 0.1.174 → 0.1.175

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
@@ -20646,6 +20646,11 @@ var init_activity_lease = __esm({
20646
20646
  mainThreadLagMs: external_exports.number().int().nonnegative(),
20647
20647
  runs: external_exports.array(leasedRunSchema),
20648
20648
  holders: external_exports.array(leasedHolderSchema),
20649
+ /**
20650
+ * Desired runs not started because their conversation is still running an earlier turn.
20651
+ * Absent from older runtimes.
20652
+ */
20653
+ busyRunIds: external_exports.array(runIdSchema).max(200).optional(),
20649
20654
  vm: leasedVmPressureSchema.nullable()
20650
20655
  });
20651
20656
  activityLeaseAckSchema = external_exports.object({
@@ -21541,6 +21546,120 @@ var init_contracts = __esm({
21541
21546
  }
21542
21547
  });
21543
21548
 
21549
+ // ../shared/src/constants/branding.ts
21550
+ var ALAN_GIT_BOT_EMAIL;
21551
+ var init_branding = __esm({
21552
+ "../shared/src/constants/branding.ts"() {
21553
+ "use strict";
21554
+ ALAN_GIT_BOT_EMAIL = "agent@tryalan.ai";
21555
+ }
21556
+ });
21557
+
21558
+ // ../shared/src/runtime-v2/commit-attribution.ts
21559
+ function coAuthorTrailer(coAuthor) {
21560
+ return `Co-Authored-By: ${coAuthor.name} <${coAuthor.email}>`;
21561
+ }
21562
+ function trimTrailingBlankLines(lines2) {
21563
+ let end = lines2.length;
21564
+ while (end > 0 && (lines2[end - 1] ?? "").trim() === "") end -= 1;
21565
+ return lines2.slice(0, end);
21566
+ }
21567
+ function appendTrailers(message2, trailers) {
21568
+ const lines2 = trimTrailingBlankLines(message2.split(/\r?\n/));
21569
+ if (trailers.length === 0) return lines2.join("\n");
21570
+ let blank = lines2.length - 1;
21571
+ while (blank >= 0 && (lines2[blank] ?? "").trim() !== "") blank -= 1;
21572
+ const lastParagraph = lines2.slice(blank + 1);
21573
+ const endsInTrailers = blank > 0 && lastParagraph.length > 0 && lastParagraph.every((line) => TRAILER_LINE.test(line));
21574
+ const separator = lines2.length === 0 || endsInTrailers ? [] : [""];
21575
+ return [...lines2, ...separator, ...trailers].join("\n");
21576
+ }
21577
+ function commitAttributionScript() {
21578
+ const pattern = FOREIGN_ATTRIBUTION_PATTERN.replaceAll("[ ]", "[[:blank:]]");
21579
+ return `#!/bin/sh
21580
+ # Managed by Alan; rewritten whenever the runtime starts.
21581
+ name=$(basename "$0")
21582
+ dir=$(cd "$(dirname "$0")" && pwd -P)
21583
+ [ "$name" = ${COMMIT_ATTRIBUTION_SCRIPT} ] || dir=$(dirname "$dir")
21584
+ pattern='${pattern}'
21585
+ coauthor=$(cat "$dir/${COMMIT_ATTRIBUTION_COAUTHOR_FILE}" 2>/dev/null)
21586
+ author_email=$(git var GIT_AUTHOR_IDENT 2>/dev/null | sed -n 's/.*<\\(.*\\)>.*/\\1/p')
21587
+
21588
+ normalize() {
21589
+ if [ -n "$coauthor" ] && [ "$author_email" != '${ALAN_GIT_BOT_EMAIL}' ] &&
21590
+ ! printf '%s' "$coauthor" | grep -qiF "<$author_email>"; then
21591
+ grep -viE "$pattern" | git interpret-trailers --trailer "Co-Authored-By: $coauthor"
21592
+ else
21593
+ grep -viE "$pattern"
21594
+ fi
21595
+ }
21596
+
21597
+ if [ "$name" = ${COMMIT_ATTRIBUTION_SCRIPT} ]; then
21598
+ normalize
21599
+ exit 0
21600
+ fi
21601
+
21602
+ if [ "$name" = prepare-commit-msg ] && [ -f "$1" ]; then
21603
+ case "$2" in
21604
+ merge|squash) ;;
21605
+ *) normalize < "$1" > "$1.alan" && mv "$1.alan" "$1" || rm -f "$1.alan" ;;
21606
+ esac
21607
+ fi
21608
+
21609
+ own=$(git config --local --get core.hooksPath || git config --global --get core.hooksPath || git config --system --get core.hooksPath)
21610
+ if [ -z "$own" ]; then
21611
+ own="$(git rev-parse --git-common-dir)/hooks"
21612
+ else
21613
+ case "$own" in
21614
+ "~/"*) own="$HOME/\${own#\\~/}" ;;
21615
+ /*) ;;
21616
+ *) own="$(git rev-parse --show-toplevel)/$own" ;;
21617
+ esac
21618
+ fi
21619
+ # Skips this script and the per-repo hook older sandboxes installed; both carry the marker.
21620
+ [ -x "$own/$name" ] && ! grep -qs '^# Managed by Alan' "$own/$name" && exec "$own/$name" "$@"
21621
+ exit 0
21622
+ `;
21623
+ }
21624
+ var TRAILER_VALUE, gitCoAuthorSchema, FOREIGN_ATTRIBUTION_PATTERN, FOREIGN_ATTRIBUTION, TRAILER_LINE, COMMIT_ATTRIBUTION_HOOKS, COMMIT_ATTRIBUTION_SCRIPT, COMMIT_ATTRIBUTION_COAUTHOR_FILE;
21625
+ var init_commit_attribution = __esm({
21626
+ "../shared/src/runtime-v2/commit-attribution.ts"() {
21627
+ "use strict";
21628
+ init_zod();
21629
+ init_branding();
21630
+ TRAILER_VALUE = /^[^\r\n<>]+$/;
21631
+ gitCoAuthorSchema = external_exports.object({
21632
+ name: external_exports.string().min(1).max(256).regex(TRAILER_VALUE),
21633
+ email: external_exports.string().min(3).max(320).regex(/^[^\s<>]+@[^\s<>]+$/)
21634
+ });
21635
+ FOREIGN_ATTRIBUTION_PATTERN = "^[ ]*((co-authored-by|assisted-by|generated-by|made-with):|(\u{1F916}[ ]*)?generated (with|by) )";
21636
+ FOREIGN_ATTRIBUTION = new RegExp(FOREIGN_ATTRIBUTION_PATTERN, "iu");
21637
+ TRAILER_LINE = /^[A-Za-z0-9-]+:[ \t]/;
21638
+ COMMIT_ATTRIBUTION_HOOKS = [
21639
+ "applypatch-msg",
21640
+ "pre-applypatch",
21641
+ "post-applypatch",
21642
+ "pre-commit",
21643
+ "pre-merge-commit",
21644
+ "prepare-commit-msg",
21645
+ "commit-msg",
21646
+ "post-commit",
21647
+ "pre-rebase",
21648
+ "post-checkout",
21649
+ "post-merge",
21650
+ "pre-push",
21651
+ "pre-auto-gc",
21652
+ "post-rewrite",
21653
+ "post-index-change",
21654
+ "reference-transaction",
21655
+ "push-to-checkout",
21656
+ "sendemail-validate"
21657
+ ];
21658
+ COMMIT_ATTRIBUTION_SCRIPT = "alan-trailers";
21659
+ COMMIT_ATTRIBUTION_COAUTHOR_FILE = "coauthor";
21660
+ }
21661
+ });
21662
+
21544
21663
  // ../shared/src/runtime-v2/run-context.ts
21545
21664
  function wire() {
21546
21665
  return (schema) => schema;
@@ -21702,6 +21821,7 @@ var init_desired_state = __esm({
21702
21821
  init_cloud_repositories();
21703
21822
  init_contracts();
21704
21823
  init_agent_context();
21824
+ init_commit_attribution();
21705
21825
  init_ids();
21706
21826
  init_run_context();
21707
21827
  init_workspace();
@@ -21756,7 +21876,9 @@ var init_desired_state = __esm({
21756
21876
  contextGraphEnabled: external_exports.boolean().optional(),
21757
21877
  cloudEnvironmentId: external_exports.guid().optional(),
21758
21878
  sandboxId: external_exports.string().min(1).optional(),
21759
- localRepoUrls: external_exports.array(external_exports.string().min(1)).optional()
21879
+ localRepoUrls: external_exports.array(external_exports.string().min(1)).optional(),
21880
+ /** The deployed GitHub App's bot, credited on every commit the turn makes; absent from older servers. */
21881
+ gitCoAuthor: gitCoAuthorSchema.optional()
21760
21882
  // Never here: the provider API key. The holder fetches it per run (RUN_PROVIDER_CREDENTIAL_PATH).
21761
21883
  });
21762
21884
  desiredRunSchema = external_exports.object({
@@ -22901,6 +23023,7 @@ var init_runtime_v2 = __esm({
22901
23023
  init_activity_lease();
22902
23024
  init_agent_context();
22903
23025
  init_capabilities();
23026
+ init_commit_attribution();
22904
23027
  init_desired_state();
22905
23028
  init_files();
22906
23029
  init_git_capability();
@@ -27602,13 +27725,6 @@ var init_agent_package = __esm({
27602
27725
  }
27603
27726
  });
27604
27727
 
27605
- // ../shared/src/constants/branding.ts
27606
- var init_branding = __esm({
27607
- "../shared/src/constants/branding.ts"() {
27608
- "use strict";
27609
- }
27610
- });
27611
-
27612
27728
  // ../shared/src/constants/colors.ts
27613
27729
  var CATEGORICAL_COLORS, CATEGORICAL_COLOR_VALUES, CATEGORICAL_COLOR_VALUE_SET;
27614
27730
  var init_colors = __esm({
@@ -36089,13 +36205,20 @@ function modelArgs(input2) {
36089
36205
  effort: option("--effort", effort)
36090
36206
  };
36091
36207
  }
36092
- function skillListingArgs(input2) {
36093
- const chars = input2.skillListingMaxDescChars;
36208
+ function settingsArgs(input2) {
36094
36209
  const ownSettings = (input2.extraArgs ?? []).some(
36095
36210
  (arg) => arg === "--settings" || arg.startsWith("--settings=")
36096
36211
  );
36097
- if (chars === void 0 || !input2.capabilities.supportsPluginDir || ownSettings) return [];
36098
- return ["--settings", JSON.stringify({ skillListingMaxDescChars: chars })];
36212
+ if (!input2.capabilities.supportsPluginDir || ownSettings) return [];
36213
+ const chars = input2.skillListingMaxDescChars;
36214
+ return [
36215
+ "--settings",
36216
+ JSON.stringify({
36217
+ attribution: { commit: "", pr: "" },
36218
+ includeCoAuthoredBy: false,
36219
+ ...chars === void 0 ? {} : { skillListingMaxDescChars: chars }
36220
+ })
36221
+ ];
36099
36222
  }
36100
36223
  function buildClaudeArgs(input2) {
36101
36224
  const { capabilities } = input2;
@@ -36121,7 +36244,7 @@ function buildClaudeArgs(input2) {
36121
36244
  // Without it the whole answer lands in one frame at turn end.
36122
36245
  ...capabilities.supportsPartialMessages ? ["--include-partial-messages"] : [],
36123
36246
  ...capabilities.supportsPluginDir ? (input2.pluginDirs ?? []).flatMap((dir) => ["--plugin-dir", dir]) : [],
36124
- ...skillListingArgs(input2),
36247
+ ...settingsArgs(input2),
36125
36248
  ...option("--resume", input2.resumeId),
36126
36249
  "--chrome",
36127
36250
  ...input2.extraArgs ?? []
@@ -60110,7 +60233,7 @@ var import_node_worker_threads2 = require("worker_threads");
60110
60233
  // package.json
60111
60234
  var package_default = {
60112
60235
  name: "@alan-ai-hq/agent-manager",
60113
- version: "0.1.174",
60236
+ version: "0.1.175",
60114
60237
  private: true,
60115
60238
  type: "module",
60116
60239
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -64081,8 +64204,8 @@ function startWakeClock(options) {
64081
64204
  }
64082
64205
 
64083
64206
  // src/cli/commands/activity-lease-producer.ts
64084
- var import_promises74 = require("fs/promises");
64085
- var import_node_path89 = require("path");
64207
+ var import_promises75 = require("fs/promises");
64208
+ var import_node_path90 = require("path");
64086
64209
  init_runtime_v2();
64087
64210
 
64088
64211
  // src/holder/activity-file.ts
@@ -64750,6 +64873,7 @@ async function verifyHead(context, request2) {
64750
64873
  // src/capabilities/git/checkpoint.ts
64751
64874
  var import_promises34 = require("fs/promises");
64752
64875
  var import_node_path40 = require("path");
64876
+ init_runtime_v2();
64753
64877
  function sourceChanged(message2) {
64754
64878
  return new GitFault("source_changed_since_approval", message2);
64755
64879
  }
@@ -64869,10 +64993,10 @@ async function replayCheckpoint(context, expectedRef, headSha) {
64869
64993
  }
64870
64994
  }
64871
64995
  async function commitApprovedTree(context, request2) {
64872
- const message2 = `${request2.commitMessage.trim()}
64873
-
64874
- Alan-Switch-Id: ${request2.switchId}
64875
- Alan-Repository-Id: ${request2.repoKey}
64996
+ const message2 = `${appendTrailers(request2.commitMessage, [
64997
+ `Alan-Switch-Id: ${request2.switchId}`,
64998
+ `Alan-Repository-Id: ${request2.repoKey}`
64999
+ ])}
64876
65000
  `;
64877
65001
  const sha = await context.git.ok(
64878
65002
  {
@@ -65481,6 +65605,133 @@ async function readCheckoutFreshness(dir, path4) {
65481
65605
  }
65482
65606
  }
65483
65607
 
65608
+ // src/capabilities/git/commit-attribution.ts
65609
+ var import_node_crypto35 = require("crypto");
65610
+ var import_promises37 = require("fs/promises");
65611
+ var import_node_path43 = require("path");
65612
+ init_runtime_v2();
65613
+
65614
+ // src/capabilities/providers/commands.ts
65615
+ var import_node_fs21 = require("fs");
65616
+ var import_promises36 = require("fs/promises");
65617
+ var import_node_path42 = require("path");
65618
+ var PROVIDER_COMMANDS = [
65619
+ // The engine, not a CLI of its own: `resolveProviderExecutable` finds the bundled one first.
65620
+ { backendKind: "alan_code", command: "opencode", name: "Alan Code" },
65621
+ { backendKind: "claude_cli", command: "claude", name: "Claude" },
65622
+ { backendKind: "codex_app_server", command: "codex", name: "Codex" },
65623
+ { backendKind: "copilot_cli", command: "copilot", name: "Copilot" },
65624
+ { backendKind: "cursor_agent_cli", command: "cursor-agent", name: "Cursor Agent" },
65625
+ { backendKind: "droid_cli", command: "droid", name: "Droid" },
65626
+ { backendKind: "antigravity_cli", command: "agy", name: "Antigravity" },
65627
+ { backendKind: "grok_cli", command: "grok", name: "Grok" },
65628
+ { backendKind: "kimi_cli", command: "kimi", alternateCommands: ["kimi-cli"], name: "Kimi" },
65629
+ { backendKind: "command_code_cli", command: "command-code", name: "Command Code" },
65630
+ { backendKind: "opencode_serve", command: "opencode", name: "OpenCode" }
65631
+ ];
65632
+ var BY_BACKEND = new Map(
65633
+ PROVIDER_COMMANDS.map((provider4) => [provider4.backendKind, provider4])
65634
+ );
65635
+ function providerCommandEntry(backendKind) {
65636
+ return BY_BACKEND.get(backendKind);
65637
+ }
65638
+ function providerCommandFor(backendKind) {
65639
+ return BY_BACKEND.get(backendKind)?.command;
65640
+ }
65641
+ function envValue(env, name) {
65642
+ const key = Object.keys(env).findLast(
65643
+ (candidate) => candidate.toUpperCase() === name.toUpperCase()
65644
+ );
65645
+ return key === void 0 ? "" : env[key] ?? "";
65646
+ }
65647
+ function pathDelimiter(platform3) {
65648
+ return platform3 === "win32" ? ";" : ":";
65649
+ }
65650
+ async function isRunnable(path4, platform3) {
65651
+ try {
65652
+ if (!(await (0, import_promises36.stat)(path4)).isFile()) return false;
65653
+ if (platform3 !== "win32") await (0, import_promises36.access)(path4, import_node_fs21.constants.X_OK);
65654
+ return true;
65655
+ } catch {
65656
+ return false;
65657
+ }
65658
+ }
65659
+ function windowsExtensions(command, env) {
65660
+ const extensions = (envValue(env, "PATHEXT") || ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter((extension) => [".COM", ".EXE", ".BAT", ".CMD"].includes(extension.toUpperCase()));
65661
+ const named = command.toLowerCase();
65662
+ return [".com", ".exe", ...extensions.map((extension) => extension.toLowerCase())].some(
65663
+ (extension) => named.endsWith(extension)
65664
+ ) ? [""] : extensions;
65665
+ }
65666
+ async function resolveCommandOnPath(command, env, platform3) {
65667
+ const directories = envValue(env, "PATH").split(pathDelimiter(platform3)).map(
65668
+ (directory) => platform3 === "win32" ? directory.trim().replace(/^"(.*)"$/, "$1") : directory
65669
+ ).filter(
65670
+ (directory) => platform3 === "win32" ? import_node_path42.win32.isAbsolute(directory) : directory.length > 0
65671
+ );
65672
+ const extensions = platform3 === "win32" ? windowsExtensions(command, env) : [""];
65673
+ for (const directory of directories) {
65674
+ for (const extension of extensions) {
65675
+ const candidate = (0, import_node_path42.join)(directory, `${command}${extension}`);
65676
+ if (await isRunnable(candidate, platform3)) return candidate;
65677
+ }
65678
+ }
65679
+ return null;
65680
+ }
65681
+ async function isCommandOnPath(command, env, platform3) {
65682
+ return await resolveCommandOnPath(command, env, platform3) !== null;
65683
+ }
65684
+
65685
+ // src/capabilities/git/commit-attribution.ts
65686
+ function shellQuote(value2) {
65687
+ return `'${value2.replace(/'/g, "'\\''")}'`;
65688
+ }
65689
+ async function replaceFile(path4, content, mode) {
65690
+ const temp = `${path4}.${(0, import_node_crypto35.randomUUID)()}.tmp`;
65691
+ await (0, import_promises37.writeFile)(temp, content, { mode });
65692
+ await (0, import_promises37.rename)(temp, path4);
65693
+ }
65694
+ async function replaceSymlink(path4, target) {
65695
+ const temp = `${path4}.${(0, import_node_crypto35.randomUUID)()}.tmp`;
65696
+ await (0, import_promises37.symlink)(target, temp);
65697
+ await (0, import_promises37.rename)(temp, path4);
65698
+ }
65699
+ async function installCommitAttribution(input2) {
65700
+ if (input2.platform === "win32") return null;
65701
+ const binDir = (0, import_node_path43.join)(input2.dir, "bin");
65702
+ const hooksDir = (0, import_node_path43.join)(input2.dir, "hooks");
65703
+ const delimiter2 = pathDelimiter(input2.platform);
65704
+ const path4 = envValue(input2.env, "PATH").split(delimiter2).filter((entry) => entry.length > 0 && entry !== binDir).join(delimiter2);
65705
+ const realGit = await resolveCommandOnPath("git", { ...input2.env, PATH: path4 }, input2.platform);
65706
+ if (realGit === null) return null;
65707
+ await (0, import_promises37.mkdir)(binDir, { recursive: true, mode: 493 });
65708
+ await (0, import_promises37.mkdir)(hooksDir, { recursive: true, mode: 493 });
65709
+ await replaceFile((0, import_node_path43.join)(input2.dir, COMMIT_ATTRIBUTION_SCRIPT), commitAttributionScript(), 493);
65710
+ for (const hook of COMMIT_ATTRIBUTION_HOOKS) {
65711
+ await replaceSymlink((0, import_node_path43.join)(hooksDir, hook), (0, import_node_path43.join)("..", COMMIT_ATTRIBUTION_SCRIPT));
65712
+ }
65713
+ await replaceFile(
65714
+ (0, import_node_path43.join)(binDir, "git"),
65715
+ `#!/bin/sh
65716
+ exec ${shellQuote(realGit)} -c core.hooksPath=${shellQuote(hooksDir)} "$@"
65717
+ `,
65718
+ 493
65719
+ );
65720
+ const coAuthorPath = (0, import_node_path43.join)(input2.dir, COMMIT_ATTRIBUTION_COAUTHOR_FILE);
65721
+ return {
65722
+ env: { ...input2.env, PATH: path4 === "" ? binDir : `${binDir}${delimiter2}${path4}` },
65723
+ setCoAuthor: async (coAuthor) => {
65724
+ if (coAuthor === void 0) {
65725
+ await (0, import_promises37.rm)(coAuthorPath, { force: true });
65726
+ return;
65727
+ }
65728
+ const value2 = coAuthorTrailer(coAuthor).replace(/^Co-Authored-By: /, "");
65729
+ await replaceFile(coAuthorPath, `${value2}
65730
+ `, 420);
65731
+ }
65732
+ };
65733
+ }
65734
+
65484
65735
  // ../shared/src/git-hosts.ts
65485
65736
  var EXACT_HOSTS = {
65486
65737
  "github.com": "github",
@@ -65500,15 +65751,15 @@ var GIT_GATEWAY_HTTPS_HOSTS = Object.keys(EXACT_HOSTS).filter(
65500
65751
  // src/capabilities/git/credential-config.ts
65501
65752
  init_runtime_v2();
65502
65753
  var PROACTIVE_AUTH_MIN_VERSION = [2, 46];
65503
- function shellQuote(value2) {
65754
+ function shellQuote2(value2) {
65504
65755
  return `'${value2.replace(/'/g, "'\\''")}'`;
65505
65756
  }
65506
65757
  function gitCredentialHelperValue(input2) {
65507
65758
  const environment = Object.entries(input2.helperEnvironment).map(
65508
- ([key, value2]) => `${key}=${shellQuote(value2)}`
65759
+ ([key, value2]) => `${key}=${shellQuote2(value2)}`
65509
65760
  );
65510
- const command = input2.helperCommand.map(shellQuote);
65511
- return `!${[...environment, ...command, "--state-dir", shellQuote(input2.stateDir), "git-credential"].join(" ")}`;
65761
+ const command = input2.helperCommand.map(shellQuote2);
65762
+ return `!${[...environment, ...command, "--state-dir", shellQuote2(input2.stateDir), "git-credential"].join(" ")}`;
65512
65763
  }
65513
65764
  function parseGitVersion(output2) {
65514
65765
  const match = /git version (\d+)\.(\d+)/.exec(output2);
@@ -65602,12 +65853,12 @@ function formatGitCredentialAnswer(capability, request2) {
65602
65853
  var GIT_CREDENTIAL_QUIT = "quit=1\n";
65603
65854
 
65604
65855
  // src/capabilities/git/credential-server.ts
65605
- var import_node_crypto35 = require("crypto");
65606
- var import_promises36 = require("fs/promises");
65856
+ var import_node_crypto36 = require("crypto");
65857
+ var import_promises38 = require("fs/promises");
65607
65858
  var import_node_net2 = require("net");
65608
65859
 
65609
65860
  // src/capabilities/git/credential-socket.ts
65610
- var import_node_path42 = require("path");
65861
+ var import_node_path44 = require("path");
65611
65862
  init_zod();
65612
65863
  var GIT_CREDENTIAL_SOCKET_ID = "git-credential";
65613
65864
  var GIT_CREDENTIAL_HELPER_BUDGET_MS = 3500;
@@ -65633,7 +65884,7 @@ var gitCredentialTokenSchema = external_exports.object({
65633
65884
  token: external_exports.string().min(1)
65634
65885
  });
65635
65886
  function gitCredentialTokenPath(socketsDir) {
65636
- return (0, import_node_path42.join)(socketsDir, `${GIT_CREDENTIAL_SOCKET_ID}.token`);
65887
+ return (0, import_node_path44.join)(socketsDir, `${GIT_CREDENTIAL_SOCKET_ID}.token`);
65637
65888
  }
65638
65889
 
65639
65890
  // src/capabilities/git/credential-server.ts
@@ -65739,9 +65990,9 @@ function parseRequest(line) {
65739
65990
  }
65740
65991
  }
65741
65992
  function tokenMatches(expected, presented) {
65742
- const a = (0, import_node_crypto35.createHash)("sha256").update(expected).digest();
65743
- const b = (0, import_node_crypto35.createHash)("sha256").update(presented).digest();
65744
- return (0, import_node_crypto35.timingSafeEqual)(a, b);
65993
+ const a = (0, import_node_crypto36.createHash)("sha256").update(expected).digest();
65994
+ const b = (0, import_node_crypto36.createHash)("sha256").update(presented).digest();
65995
+ return (0, import_node_crypto36.timingSafeEqual)(a, b);
65745
65996
  }
65746
65997
  function reply(socket, response) {
65747
65998
  if (!socket.destroyed) socket.end(`${JSON.stringify(response)}
@@ -65750,7 +66001,7 @@ function reply(socket, response) {
65750
66001
  async function startGitCredentialServer(options) {
65751
66002
  const cache2 = createGitCapabilityCache(options);
65752
66003
  const closing = new AbortController();
65753
- const token = (0, import_node_crypto35.randomBytes)(32).toString("base64url");
66004
+ const token = (0, import_node_crypto36.randomBytes)(32).toString("base64url");
65754
66005
  const tokenFile = { token };
65755
66006
  await writeJsonFileAtomic(options.tokenPath, tokenFile);
65756
66007
  const answer = async (request2) => {
@@ -65790,7 +66041,7 @@ async function startGitCredentialServer(options) {
65790
66041
  closing.abort();
65791
66042
  await new Promise((resolve16) => server.close(() => resolve16()));
65792
66043
  removeStaleEndpoint(options.endpoint);
65793
- await (0, import_promises36.rm)(options.tokenPath, { force: true });
66044
+ await (0, import_promises38.rm)(options.tokenPath, { force: true });
65794
66045
  }
65795
66046
  };
65796
66047
  }
@@ -65839,9 +66090,9 @@ function createGit(options) {
65839
66090
 
65840
66091
  // src/capabilities/github-proxy/certificates.ts
65841
66092
  var import_node_child_process16 = require("child_process");
65842
- var import_node_crypto36 = require("crypto");
65843
- var import_promises37 = require("fs/promises");
65844
- var import_node_path43 = require("path");
66093
+ var import_node_crypto37 = require("crypto");
66094
+ var import_promises39 = require("fs/promises");
66095
+ var import_node_path45 = require("path");
65845
66096
  var OPENSSL_TIMEOUT_MS = 1e4;
65846
66097
  var VALIDITY_DAYS = "30";
65847
66098
  function opensslConfig(commonName) {
@@ -65877,14 +66128,14 @@ function openssl(args, cwd) {
65877
66128
  });
65878
66129
  }
65879
66130
  async function createGitHubProxyCertificates(stateDir) {
65880
- const work = (0, import_node_path43.join)(stateDir, "github-proxy");
65881
- await (0, import_promises37.rm)(work, { recursive: true, force: true });
65882
- await (0, import_promises37.mkdir)(work, { recursive: true, mode: 448 });
66131
+ const work = (0, import_node_path45.join)(stateDir, "github-proxy");
66132
+ await (0, import_promises39.rm)(work, { recursive: true, force: true });
66133
+ await (0, import_promises39.mkdir)(work, { recursive: true, mode: 448 });
65883
66134
  try {
65884
- await (0, import_promises37.writeFile)((0, import_node_path43.join)(work, "ca.cnf"), opensslConfig("Alan sandbox GitHub proxy CA"), {
66135
+ await (0, import_promises39.writeFile)((0, import_node_path45.join)(work, "ca.cnf"), opensslConfig("Alan sandbox GitHub proxy CA"), {
65885
66136
  mode: 384
65886
66137
  });
65887
- await (0, import_promises37.writeFile)((0, import_node_path43.join)(work, "leaf.cnf"), opensslConfig("github.com"), { mode: 384 });
66138
+ await (0, import_promises39.writeFile)((0, import_node_path45.join)(work, "leaf.cnf"), opensslConfig("github.com"), { mode: 384 });
65888
66139
  const curve = ["ecparam", "-name", "prime256v1", "-genkey", "-noout"];
65889
66140
  await openssl([...curve, "-out", "ca.key"], work);
65890
66141
  await openssl(
@@ -65904,24 +66155,24 @@ async function createGitHubProxyCertificates(stateDir) {
65904
66155
  work
65905
66156
  );
65906
66157
  await openssl(
65907
- ["x509", "-req", "-in", "leaf.csr", "-CA", "ca.pem", "-CAkey", "ca.key", "-sha256"].concat(["-set_serial", `0x${(0, import_node_crypto36.randomBytes)(16).toString("hex")}`, "-days", VALIDITY_DAYS]).concat(["-extfile", "leaf.cnf", "-extensions", "leaf", "-out", "leaf.pem"]),
66158
+ ["x509", "-req", "-in", "leaf.csr", "-CA", "ca.pem", "-CAkey", "ca.key", "-sha256"].concat(["-set_serial", `0x${(0, import_node_crypto37.randomBytes)(16).toString("hex")}`, "-days", VALIDITY_DAYS]).concat(["-extfile", "leaf.cnf", "-extensions", "leaf", "-out", "leaf.pem"]),
65908
66159
  work
65909
66160
  );
65910
- const caPath = (0, import_node_path43.join)(stateDir, "github-ca.pem");
65911
- await (0, import_promises37.writeFile)(caPath, await (0, import_promises37.readFile)((0, import_node_path43.join)(work, "ca.pem")), { mode: 384 });
66161
+ const caPath = (0, import_node_path45.join)(stateDir, "github-ca.pem");
66162
+ await (0, import_promises39.writeFile)(caPath, await (0, import_promises39.readFile)((0, import_node_path45.join)(work, "ca.pem")), { mode: 384 });
65912
66163
  return {
65913
66164
  caPath,
65914
- leafKeyPem: await (0, import_promises37.readFile)((0, import_node_path43.join)(work, "leaf.key"), "utf8"),
65915
- leafCertPem: await (0, import_promises37.readFile)((0, import_node_path43.join)(work, "leaf.pem"), "utf8")
66165
+ leafKeyPem: await (0, import_promises39.readFile)((0, import_node_path45.join)(work, "leaf.key"), "utf8"),
66166
+ leafCertPem: await (0, import_promises39.readFile)((0, import_node_path45.join)(work, "leaf.pem"), "utf8")
65916
66167
  };
65917
66168
  } finally {
65918
- await (0, import_promises37.rm)(work, { recursive: true, force: true });
66169
+ await (0, import_promises39.rm)(work, { recursive: true, force: true });
65919
66170
  }
65920
66171
  }
65921
66172
 
65922
66173
  // src/capabilities/github-proxy/config.ts
65923
- var import_promises38 = require("fs/promises");
65924
- var import_node_path44 = require("path");
66174
+ var import_promises40 = require("fs/promises");
66175
+ var import_node_path46 = require("path");
65925
66176
  init_runtime_v2();
65926
66177
  var GITHUB_URL = "https://github.com/";
65927
66178
  var GH_SOCKET_KEY = "http_unix_socket";
@@ -65937,10 +66188,10 @@ function withGhConfigKey(yaml, key, value2) {
65937
66188
  `;
65938
66189
  }
65939
66190
  async function configureGh(ghConfigDir, socketPath) {
65940
- await (0, import_promises38.mkdir)(ghConfigDir, { recursive: true, mode: 448 });
65941
- const path4 = (0, import_node_path44.join)(ghConfigDir, "config.yml");
65942
- const current = await (0, import_promises38.readFile)(path4, "utf8").catch(() => "");
65943
- await (0, import_promises38.writeFile)(path4, withGhConfigKey(current, GH_SOCKET_KEY, socketPath), { mode: 384 });
66191
+ await (0, import_promises40.mkdir)(ghConfigDir, { recursive: true, mode: 448 });
66192
+ const path4 = (0, import_node_path46.join)(ghConfigDir, "config.yml");
66193
+ const current = await (0, import_promises40.readFile)(path4, "utf8").catch(() => "");
66194
+ await (0, import_promises40.writeFile)(path4, withGhConfigKey(current, GH_SOCKET_KEY, socketPath), { mode: 384 });
65944
66195
  }
65945
66196
  async function configureGit(input2, git) {
65946
66197
  const run2 = async (args, allowedExitCodes = [0]) => {
@@ -65970,7 +66221,7 @@ async function configureGitHubProxyClients(input2) {
65970
66221
  }
65971
66222
 
65972
66223
  // src/capabilities/github-proxy/server.ts
65973
- var import_promises39 = require("fs/promises");
66224
+ var import_promises41 = require("fs/promises");
65974
66225
  var import_node_http5 = require("http");
65975
66226
  var import_node_tls = require("tls");
65976
66227
  init_runtime_v2();
@@ -66112,7 +66363,7 @@ async function startGitHubProxy(options) {
66112
66363
  });
66113
66364
  removeStaleEndpoint(options.socketPath);
66114
66365
  await listen(gh, options.socketPath);
66115
- await (0, import_promises39.chmod)(options.socketPath, 384);
66366
+ await (0, import_promises41.chmod)(options.socketPath, 384);
66116
66367
  const git = options.certificates === null ? null : await startGitListener(options.certificates, relay);
66117
66368
  options.log.info("github_proxy.listening", {
66118
66369
  socketPath: options.socketPath,
@@ -66130,9 +66381,9 @@ async function startGitHubProxy(options) {
66130
66381
  }
66131
66382
 
66132
66383
  // src/capabilities/mcp-config/mcp-config.ts
66133
- var import_node_crypto37 = require("crypto");
66134
- var import_promises40 = require("fs/promises");
66135
- var import_node_path45 = require("path");
66384
+ var import_node_crypto38 = require("crypto");
66385
+ var import_promises42 = require("fs/promises");
66386
+ var import_node_path47 = require("path");
66136
66387
 
66137
66388
  // ../../node_modules/smol-toml/dist/error.js
66138
66389
  function getLineColFromPtr(string4, ptr) {
@@ -67081,7 +67332,7 @@ function isCredentialFreeAlanEntry(entry, endpoint) {
67081
67332
  }
67082
67333
  async function isInstalled(cli, home) {
67083
67334
  try {
67084
- return (await (0, import_promises40.stat)((0, import_node_path45.join)(home, cli.guardDir))).isDirectory();
67335
+ return (await (0, import_promises42.stat)((0, import_node_path47.join)(home, cli.guardDir))).isDirectory();
67085
67336
  } catch (error62) {
67086
67337
  if (errorCode2(error62) === "ENOENT") return false;
67087
67338
  throw error62;
@@ -67089,7 +67340,7 @@ async function isInstalled(cli, home) {
67089
67340
  }
67090
67341
  async function readText3(path4) {
67091
67342
  try {
67092
- return await (0, import_promises40.readFile)(path4, "utf8");
67343
+ return await (0, import_promises42.readFile)(path4, "utf8");
67093
67344
  } catch (error62) {
67094
67345
  if (errorCode2(error62) === "ENOENT") return null;
67095
67346
  throw error62;
@@ -67102,7 +67353,7 @@ function parseRoot(cli, text3) {
67102
67353
  return value2;
67103
67354
  }
67104
67355
  async function readConfig(cli, home) {
67105
- const path4 = (0, import_node_path45.join)(home, cli.configPath);
67356
+ const path4 = (0, import_node_path47.join)(home, cli.configPath);
67106
67357
  const text3 = await readText3(path4);
67107
67358
  try {
67108
67359
  const root = text3 === null ? {} : parseRoot(cli, text3);
@@ -67114,12 +67365,12 @@ async function readConfig(cli, home) {
67114
67365
  }
67115
67366
  }
67116
67367
  async function writeConfig(path4, text3) {
67117
- const temporary = `${path4}.alan-${(0, import_node_crypto37.randomUUID)()}.tmp`;
67368
+ const temporary = `${path4}.alan-${(0, import_node_crypto38.randomUUID)()}.tmp`;
67118
67369
  try {
67119
- await (0, import_promises40.writeFile)(temporary, text3, { encoding: "utf8", mode: 384, flag: "wx" });
67120
- await (0, import_promises40.rename)(temporary, path4);
67370
+ await (0, import_promises42.writeFile)(temporary, text3, { encoding: "utf8", mode: 384, flag: "wx" });
67371
+ await (0, import_promises42.rename)(temporary, path4);
67121
67372
  } finally {
67122
- await (0, import_promises40.rm)(temporary, { force: true });
67373
+ await (0, import_promises42.rm)(temporary, { force: true });
67123
67374
  }
67124
67375
  }
67125
67376
  async function editCli(cli, home, endpoint, edit) {
@@ -67197,8 +67448,8 @@ async function inspectAlanMcp(options) {
67197
67448
  }
67198
67449
 
67199
67450
  // src/capabilities/models/opencode-models.ts
67200
- var import_promises41 = require("fs/promises");
67201
- var import_node_path46 = require("path");
67451
+ var import_promises43 = require("fs/promises");
67452
+ var import_node_path48 = require("path");
67202
67453
  init_runtime_v2();
67203
67454
  init_zod();
67204
67455
 
@@ -67511,9 +67762,9 @@ function openCodeCatalogueFrom(value2) {
67511
67762
  }
67512
67763
  async function readOpenCodeCatalogueCache(env) {
67513
67764
  const home = env.HOME?.trim();
67514
- const cacheHome = env.XDG_CACHE_HOME?.trim() || (home ? (0, import_node_path46.join)(home, ".cache") : "");
67765
+ const cacheHome = env.XDG_CACHE_HOME?.trim() || (home ? (0, import_node_path48.join)(home, ".cache") : "");
67515
67766
  if (cacheHome === "") return null;
67516
- const text3 = await (0, import_promises41.readFile)((0, import_node_path46.join)(cacheHome, ...CATALOGUE_CACHE_SEGMENTS), "utf8").catch(
67767
+ const text3 = await (0, import_promises43.readFile)((0, import_node_path48.join)(cacheHome, ...CATALOGUE_CACHE_SEGMENTS), "utf8").catch(
67517
67768
  () => void 0
67518
67769
  );
67519
67770
  if (text3 === void 0) return null;
@@ -67632,17 +67883,17 @@ async function discoverModels(backendKind, executable, env, capture) {
67632
67883
  }
67633
67884
 
67634
67885
  // src/capabilities/models/opencode-entitlement.ts
67635
- var import_promises42 = require("fs/promises");
67886
+ var import_promises44 = require("fs/promises");
67636
67887
  var import_node_os6 = require("os");
67637
- var import_node_path47 = require("path");
67888
+ var import_node_path49 = require("path");
67638
67889
  init_agent2();
67639
67890
  async function readOpenCodeZenCredential(env) {
67640
67891
  const direct = env.OPENCODE_API_KEY?.trim();
67641
67892
  if (direct) return direct;
67642
67893
  const injected = env.OPENCODE_AUTH_CONTENT?.trim();
67643
67894
  if (injected) return readZenCredentialFromAuthDocument(injected);
67644
- const dataHome = env.XDG_DATA_HOME?.trim() || (0, import_node_path47.join)(env.HOME?.trim() || (0, import_node_os6.homedir)(), ".local", "share");
67645
- const document2 = await (0, import_promises42.readFile)((0, import_node_path47.join)(dataHome, "opencode", "auth.json"), "utf8").catch(
67895
+ const dataHome = env.XDG_DATA_HOME?.trim() || (0, import_node_path49.join)(env.HOME?.trim() || (0, import_node_os6.homedir)(), ".local", "share");
67896
+ const document2 = await (0, import_promises44.readFile)((0, import_node_path49.join)(dataHome, "opencode", "auth.json"), "utf8").catch(
67646
67897
  () => void 0
67647
67898
  );
67648
67899
  return readZenCredentialFromAuthDocument(document2);
@@ -67691,25 +67942,25 @@ function fingerprintWholeText(fingerprint) {
67691
67942
  }
67692
67943
 
67693
67944
  // src/capabilities/native-ingest/hook-config.ts
67694
- var import_node_fs21 = require("fs");
67695
- var import_node_path49 = require("path");
67945
+ var import_node_fs22 = require("fs");
67946
+ var import_node_path51 = require("path");
67696
67947
 
67697
67948
  // src/capabilities/native-ingest/provider-paths.ts
67698
- var import_node_path48 = require("path");
67949
+ var import_node_path50 = require("path");
67699
67950
  function providerConfigDir(provider4, where) {
67700
67951
  if (provider4 === "claude") {
67701
- return where.env.CLAUDE_CONFIG_DIR?.trim() || (0, import_node_path48.join)(where.home, ".claude");
67952
+ return where.env.CLAUDE_CONFIG_DIR?.trim() || (0, import_node_path50.join)(where.home, ".claude");
67702
67953
  }
67703
- return where.env.CODEX_HOME?.trim() || (0, import_node_path48.join)(where.home, ".codex");
67954
+ return where.env.CODEX_HOME?.trim() || (0, import_node_path50.join)(where.home, ".codex");
67704
67955
  }
67705
67956
  function providerHookSettingsPath(provider4, where) {
67706
- return (0, import_node_path48.join)(
67957
+ return (0, import_node_path50.join)(
67707
67958
  providerConfigDir(provider4, where),
67708
67959
  provider4 === "claude" ? "settings.json" : "hooks.json"
67709
67960
  );
67710
67961
  }
67711
67962
  function providerTranscriptRoot(provider4, where) {
67712
- return (0, import_node_path48.join)(providerConfigDir(provider4, where), provider4 === "claude" ? "projects" : "sessions");
67963
+ return (0, import_node_path50.join)(providerConfigDir(provider4, where), provider4 === "claude" ? "projects" : "sessions");
67713
67964
  }
67714
67965
 
67715
67966
  // src/capabilities/native-ingest/hook-config.ts
@@ -67721,7 +67972,7 @@ var PROVIDER_HOOK_EVENTS = [
67721
67972
  function isRecord9(value2) {
67722
67973
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
67723
67974
  }
67724
- function shellQuote2(value2) {
67975
+ function shellQuote3(value2) {
67725
67976
  return `'${value2.replaceAll("'", `'\\''`)}'`;
67726
67977
  }
67727
67978
  function powershellQuote(value2) {
@@ -67740,8 +67991,8 @@ function hookArgv(launcher, provider4, event) {
67740
67991
  return [launcher.command, ...launcher.args, "hook", "--provider", provider4, "--event", event];
67741
67992
  }
67742
67993
  function posixCommand(argv, environment) {
67743
- const assignments = environment.map(([key, value2]) => `${key}=${shellQuote2(value2)}`);
67744
- return [...assignments, ...argv.map(shellQuote2), INGESTION_HOOK_MARKER].join(" ");
67994
+ const assignments = environment.map(([key, value2]) => `${key}=${shellQuote3(value2)}`);
67995
+ return [...assignments, ...argv.map(shellQuote3), INGESTION_HOOK_MARKER].join(" ");
67745
67996
  }
67746
67997
  function powershellCommand(argv, environment) {
67747
67998
  const assignments = environment.map(([key, value2]) => `$env:${key}=${powershellQuote(value2)}; `).join("");
@@ -67769,9 +68020,9 @@ function hookHandler(provider4, event, options) {
67769
68020
  return { type: "command", command: posixCommand(argv, environment), timeout: 5 };
67770
68021
  }
67771
68022
  function readSettings2(path4, backupWhenMalformed, now) {
67772
- if (!(0, import_node_fs21.existsSync)(path4)) return {};
68023
+ if (!(0, import_node_fs22.existsSync)(path4)) return {};
67773
68024
  try {
67774
- const value2 = JSON.parse((0, import_node_fs21.readFileSync)(path4, "utf8"));
68025
+ const value2 = JSON.parse((0, import_node_fs22.readFileSync)(path4, "utf8"));
67775
68026
  if (!isRecord9(value2)) throw new Error("settings root must be an object");
67776
68027
  if (value2.hooks !== void 0 && !isRecord9(value2.hooks)) {
67777
68028
  throw new Error("settings `hooks` must be an object");
@@ -67781,7 +68032,7 @@ function readSettings2(path4, backupWhenMalformed, now) {
67781
68032
  const reason = error62 instanceof Error ? error62.message : String(error62);
67782
68033
  if (!backupWhenMalformed) throw new Error(`${path4} is malformed: ${reason}`);
67783
68034
  const backup = `${path4}.malformed-${now}.bak`;
67784
- (0, import_node_fs21.copyFileSync)(path4, backup);
68035
+ (0, import_node_fs22.copyFileSync)(path4, backup);
67785
68036
  throw new Error(`${path4} is malformed and was copied to ${backup}: ${reason}`);
67786
68037
  }
67787
68038
  }
@@ -67789,14 +68040,14 @@ function hooksOf(settings2) {
67789
68040
  return isRecord9(settings2.hooks) ? settings2.hooks : {};
67790
68041
  }
67791
68042
  function writeSettings(path4, settings2) {
67792
- (0, import_node_fs21.mkdirSync)((0, import_node_path49.dirname)(path4), { recursive: true, mode: 448 });
68043
+ (0, import_node_fs22.mkdirSync)((0, import_node_path51.dirname)(path4), { recursive: true, mode: 448 });
67793
68044
  const temporary = `${path4}.${process.pid}.tmp`;
67794
68045
  try {
67795
- (0, import_node_fs21.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
68046
+ (0, import_node_fs22.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
67796
68047
  `, { mode: 384 });
67797
- (0, import_node_fs21.renameSync)(temporary, path4);
68048
+ (0, import_node_fs22.renameSync)(temporary, path4);
67798
68049
  } finally {
67799
- (0, import_node_fs21.rmSync)(temporary, { force: true });
68050
+ (0, import_node_fs22.rmSync)(temporary, { force: true });
67800
68051
  }
67801
68052
  }
67802
68053
  function isIngestionHandler(handler) {
@@ -67841,7 +68092,7 @@ function installIngestionHooks(provider4, options, now) {
67841
68092
  }
67842
68093
  function removeIngestionHooks(provider4, where, now) {
67843
68094
  const path4 = providerHookSettingsPath(provider4, where);
67844
- if (!(0, import_node_fs21.existsSync)(path4)) return { provider: provider4, path: path4, changed: false };
68095
+ if (!(0, import_node_fs22.existsSync)(path4)) return { provider: provider4, path: path4, changed: false };
67845
68096
  const settings2 = readSettings2(path4, true, now);
67846
68097
  const hooks = hooksOf(settings2);
67847
68098
  const nextHooks = {};
@@ -67878,8 +68129,8 @@ function ingestionHookStatus(provider4, options) {
67878
68129
  }
67879
68130
 
67880
68131
  // src/capabilities/native-ingest/hook-input.ts
67881
- var import_node_fs22 = require("fs");
67882
- var import_node_path50 = require("path");
68132
+ var import_node_fs23 = require("fs");
68133
+ var import_node_path52 = require("path");
67883
68134
  var ALAN_MANAGED_SESSION_ENV = "ALAN_MANAGED_SESSION";
67884
68135
  var MAX_HOOK_STDIN_BYTES = 256 * 1024 * 1024;
67885
68136
  var OVERFLOW_EDGE_BYTES = 64 * 1024;
@@ -67904,7 +68155,7 @@ function stringField2(payload, ...names) {
67904
68155
  }
67905
68156
  function codexSessionIdFromTranscriptPath(transcriptPath) {
67906
68157
  const match = /^rollout-.*-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i.exec(
67907
- (0, import_node_path50.basename)(transcriptPath)
68158
+ (0, import_node_path52.basename)(transcriptPath)
67908
68159
  );
67909
68160
  return match?.[1] ?? null;
67910
68161
  }
@@ -67978,24 +68229,24 @@ function hookPayload(input2) {
67978
68229
  }
67979
68230
  function realpathOrSelf(path4) {
67980
68231
  try {
67981
- return (0, import_node_fs22.realpathSync)(path4);
68232
+ return (0, import_node_fs23.realpathSync)(path4);
67982
68233
  } catch {
67983
68234
  try {
67984
- return (0, import_node_path50.join)((0, import_node_fs22.realpathSync)((0, import_node_path50.dirname)(path4)), (0, import_node_path50.basename)(path4));
68235
+ return (0, import_node_path52.join)((0, import_node_fs23.realpathSync)((0, import_node_path52.dirname)(path4)), (0, import_node_path52.basename)(path4));
67985
68236
  } catch {
67986
68237
  return path4;
67987
68238
  }
67988
68239
  }
67989
68240
  }
67990
68241
  function isWithinDirectory(path4, directory) {
67991
- const offset = (0, import_node_path50.relative)(realpathOrSelf(directory), realpathOrSelf(path4));
67992
- return offset !== "" && !offset.startsWith("..") && !(0, import_node_path50.isAbsolute)(offset);
68242
+ const offset = (0, import_node_path52.relative)(realpathOrSelf(directory), realpathOrSelf(path4));
68243
+ return offset !== "" && !offset.startsWith("..") && !(0, import_node_path52.isAbsolute)(offset);
67993
68244
  }
67994
68245
  function parseHookSignal(input2) {
67995
68246
  const { payload } = input2;
67996
68247
  const rawTranscriptPath = stringField2(payload, "transcript_path", "transcriptPath");
67997
68248
  if (!rawTranscriptPath) return null;
67998
- const transcriptPath = (0, import_node_path50.resolve)(rawTranscriptPath);
68249
+ const transcriptPath = (0, import_node_path52.resolve)(rawTranscriptPath);
67999
68250
  const externalSessionId = stringField2(payload, "session_id", "sessionId") ?? (input2.provider === "codex" ? codexSessionIdFromTranscriptPath(transcriptPath) : null);
68000
68251
  if (!externalSessionId) return null;
68001
68252
  const cwd = stringField2(payload, "cwd");
@@ -68004,7 +68255,7 @@ function parseHookSignal(input2) {
68004
68255
  event: input2.event,
68005
68256
  externalSessionId,
68006
68257
  transcriptPath,
68007
- cwd: cwd ? (0, import_node_path50.resolve)(cwd) : null,
68258
+ cwd: cwd ? (0, import_node_path52.resolve)(cwd) : null,
68008
68259
  providerTurnId: stringField2(payload, "prompt_id", "turn_id"),
68009
68260
  assistantFingerprint: typeof payload.last_assistant_message === "string" ? assistantFingerprint(payload.last_assistant_message) : null,
68010
68261
  observedAt: input2.observedAt.toISOString()
@@ -68012,7 +68263,7 @@ function parseHookSignal(input2) {
68012
68263
  }
68013
68264
 
68014
68265
  // src/capabilities/native-ingest/ingest.ts
68015
- var import_node_fs23 = require("fs");
68266
+ var import_node_fs24 = require("fs");
68016
68267
 
68017
68268
  // ../shared/src/types/native-agent-session.ts
68018
68269
  var nativeAgentProviderBackendKinds = {
@@ -68085,7 +68336,7 @@ function nextAlanBoundary(entry, inFlightFrom) {
68085
68336
  }
68086
68337
 
68087
68338
  // src/capabilities/native-ingest/pass.ts
68088
- var import_promises44 = require("fs/promises");
68339
+ var import_promises46 = require("fs/promises");
68089
68340
 
68090
68341
  // src/capabilities/native-ingest/ports.ts
68091
68342
  var NativeRequestFailure = class extends Error {
@@ -68144,7 +68395,7 @@ function fitNativeTurnPrompt(message2, maxBytes = NATIVE_TURN_USER_MESSAGE_MAX_B
68144
68395
  }
68145
68396
 
68146
68397
  // src/capabilities/native-ingest/session-store.ts
68147
- var import_node_path51 = require("path");
68398
+ var import_node_path53 = require("path");
68148
68399
  init_zod();
68149
68400
  var MAX_NATIVE_SESSION_ENTRIES = 500;
68150
68401
  var STORE_FILE = "native-sessions.json";
@@ -68175,7 +68426,7 @@ function evictionOrder(a, b) {
68175
68426
  return aFinished - bFinished || a.updatedAt - b.updatedAt;
68176
68427
  }
68177
68428
  async function openNativeSessionStore(stateDir, maxEntries = MAX_NATIVE_SESSION_ENTRIES) {
68178
- const path4 = (0, import_node_path51.join)(stateDir, STORE_FILE);
68429
+ const path4 = (0, import_node_path53.join)(stateDir, STORE_FILE);
68179
68430
  const sessions = /* @__PURE__ */ new Map();
68180
68431
  const stored = await readJsonFile(path4, storedSchema);
68181
68432
  if (stored.kind === "ok") {
@@ -68222,8 +68473,8 @@ function reconcileTranscriptIdentity(entry, transcriptPath, identity, size) {
68222
68473
  }
68223
68474
 
68224
68475
  // src/capabilities/native-ingest/transcript-window.ts
68225
- var import_node_crypto38 = require("crypto");
68226
- var import_promises43 = require("fs/promises");
68476
+ var import_node_crypto39 = require("crypto");
68477
+ var import_promises45 = require("fs/promises");
68227
68478
  init_acp2();
68228
68479
  init_claude();
68229
68480
  init_codex();
@@ -68278,7 +68529,7 @@ async function findRecordEnd(handle, from, size) {
68278
68529
  return null;
68279
68530
  }
68280
68531
  async function readTranscriptWindow(path4, offset, limits) {
68281
- const handle = await (0, import_promises43.open)(path4, "r");
68532
+ const handle = await (0, import_promises45.open)(path4, "r");
68282
68533
  try {
68283
68534
  const stats = await handle.stat({ bigint: true });
68284
68535
  const size = Number(stats.size);
@@ -68372,7 +68623,7 @@ function lastMatchingTurnIndex(turns, target) {
68372
68623
  function signalDigest(target) {
68373
68624
  const fingerprint = target.assistantFingerprint;
68374
68625
  const basis = target.providerTurnId ?? (fingerprint ? `${fingerprint.length}\0${fingerprint.head}\0${fingerprint.tail}` : null);
68375
- return basis ? (0, import_node_crypto38.createHash)("sha256").update(basis).digest("hex") : null;
68626
+ return basis ? (0, import_node_crypto39.createHash)("sha256").update(basis).digest("hex") : null;
68376
68627
  }
68377
68628
  function lastForegroundStop(updates) {
68378
68629
  for (let index = updates.length - 1; index >= 0; index -= 1) {
@@ -68745,19 +68996,19 @@ async function runPass(ctx, worker) {
68745
68996
  });
68746
68997
  if (signal.ending) ctx.log.info("native_ingest.closed", workerFields(worker));
68747
68998
  }
68748
- const current = await (0, import_promises44.stat)(worker.latest.transcriptPath).catch(() => void 0);
68999
+ const current = await (0, import_promises46.stat)(worker.latest.transcriptPath).catch(() => void 0);
68749
69000
  return { grewDuringPass: current !== void 0 && current.size > state.lastSize };
68750
69001
  }
68751
69002
 
68752
69003
  // src/capabilities/native-ingest/settings.ts
68753
- var import_node_path52 = require("path");
69004
+ var import_node_path54 = require("path");
68754
69005
  init_zod();
68755
69006
  var NATIVE_INGEST_SETTINGS_FILE = "native-ingest.json";
68756
69007
  var settingsSchema = external_exports.object({
68757
69008
  providers: external_exports.partialRecord(external_exports.enum(nativeIngestionProviders), external_exports.boolean())
68758
69009
  });
68759
69010
  function nativeIngestSettingsPath(stateDir) {
68760
- return (0, import_node_path52.join)(stateDir, NATIVE_INGEST_SETTINGS_FILE);
69011
+ return (0, import_node_path54.join)(stateDir, NATIVE_INGEST_SETTINGS_FILE);
68761
69012
  }
68762
69013
  async function readNativeIngestSettings(stateDir) {
68763
69014
  const read = await readJsonFile(nativeIngestSettingsPath(stateDir), settingsSchema);
@@ -68782,7 +69033,7 @@ function workerKey(provider4, externalSessionId) {
68782
69033
  return `${provider4}\0${externalSessionId}`;
68783
69034
  }
68784
69035
  function holdFor(entry) {
68785
- const stats = (0, import_node_fs23.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
69036
+ const stats = (0, import_node_fs24.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
68786
69037
  if (!stats) return [];
68787
69038
  return [
68788
69039
  {
@@ -68983,7 +69234,7 @@ async function startNativeIngest(deps) {
68983
69234
  return "accepted";
68984
69235
  };
68985
69236
  const hasUnreadBytes = (entry, now) => {
68986
- const stats = (0, import_node_fs23.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
69237
+ const stats = (0, import_node_fs24.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
68987
69238
  if (!stats || now - Number(stats.mtimeMs) > timing.sweepRecencyMs) return false;
68988
69239
  const replaced = String(stats.dev) !== entry.device || String(stats.ino) !== entry.inode;
68989
69240
  return replaced || Number(stats.size) > entry.cursor.offset;
@@ -69027,7 +69278,7 @@ async function startNativeIngest(deps) {
69027
69278
  const recordAlanRun = async (hold, runId) => {
69028
69279
  const entry = store.get(hold.provider, hold.externalSessionId);
69029
69280
  if (!entry || entry.dead) return;
69030
- const stats = (0, import_node_fs23.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
69281
+ const stats = (0, import_node_fs24.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
69031
69282
  if (!stats) return;
69032
69283
  const identity = { device: String(stats.dev), inode: String(stats.ino) };
69033
69284
  const size = Number(stats.size);
@@ -69099,79 +69350,6 @@ async function startNativeIngest(deps) {
69099
69350
 
69100
69351
  // src/capabilities/providers/alan-code.ts
69101
69352
  init_alan_code();
69102
-
69103
- // src/capabilities/providers/commands.ts
69104
- var import_node_fs24 = require("fs");
69105
- var import_promises45 = require("fs/promises");
69106
- var import_node_path53 = require("path");
69107
- var PROVIDER_COMMANDS = [
69108
- // The engine, not a CLI of its own: `resolveProviderExecutable` finds the bundled one first.
69109
- { backendKind: "alan_code", command: "opencode", name: "Alan Code" },
69110
- { backendKind: "claude_cli", command: "claude", name: "Claude" },
69111
- { backendKind: "codex_app_server", command: "codex", name: "Codex" },
69112
- { backendKind: "copilot_cli", command: "copilot", name: "Copilot" },
69113
- { backendKind: "cursor_agent_cli", command: "cursor-agent", name: "Cursor Agent" },
69114
- { backendKind: "droid_cli", command: "droid", name: "Droid" },
69115
- { backendKind: "antigravity_cli", command: "agy", name: "Antigravity" },
69116
- { backendKind: "grok_cli", command: "grok", name: "Grok" },
69117
- { backendKind: "kimi_cli", command: "kimi", alternateCommands: ["kimi-cli"], name: "Kimi" },
69118
- { backendKind: "command_code_cli", command: "command-code", name: "Command Code" },
69119
- { backendKind: "opencode_serve", command: "opencode", name: "OpenCode" }
69120
- ];
69121
- var BY_BACKEND = new Map(
69122
- PROVIDER_COMMANDS.map((provider4) => [provider4.backendKind, provider4])
69123
- );
69124
- function providerCommandEntry(backendKind) {
69125
- return BY_BACKEND.get(backendKind);
69126
- }
69127
- function providerCommandFor(backendKind) {
69128
- return BY_BACKEND.get(backendKind)?.command;
69129
- }
69130
- function envValue(env, name) {
69131
- const key = Object.keys(env).findLast(
69132
- (candidate) => candidate.toUpperCase() === name.toUpperCase()
69133
- );
69134
- return key === void 0 ? "" : env[key] ?? "";
69135
- }
69136
- function pathDelimiter(platform3) {
69137
- return platform3 === "win32" ? ";" : ":";
69138
- }
69139
- async function isRunnable(path4, platform3) {
69140
- try {
69141
- if (!(await (0, import_promises45.stat)(path4)).isFile()) return false;
69142
- if (platform3 !== "win32") await (0, import_promises45.access)(path4, import_node_fs24.constants.X_OK);
69143
- return true;
69144
- } catch {
69145
- return false;
69146
- }
69147
- }
69148
- function windowsExtensions(command, env) {
69149
- const extensions = (envValue(env, "PATHEXT") || ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter((extension) => [".COM", ".EXE", ".BAT", ".CMD"].includes(extension.toUpperCase()));
69150
- const named = command.toLowerCase();
69151
- return [".com", ".exe", ...extensions.map((extension) => extension.toLowerCase())].some(
69152
- (extension) => named.endsWith(extension)
69153
- ) ? [""] : extensions;
69154
- }
69155
- async function resolveCommandOnPath(command, env, platform3) {
69156
- const directories = envValue(env, "PATH").split(pathDelimiter(platform3)).map(
69157
- (directory) => platform3 === "win32" ? directory.trim().replace(/^"(.*)"$/, "$1") : directory
69158
- ).filter(
69159
- (directory) => platform3 === "win32" ? import_node_path53.win32.isAbsolute(directory) : directory.length > 0
69160
- );
69161
- const extensions = platform3 === "win32" ? windowsExtensions(command, env) : [""];
69162
- for (const directory of directories) {
69163
- for (const extension of extensions) {
69164
- const candidate = (0, import_node_path53.join)(directory, `${command}${extension}`);
69165
- if (await isRunnable(candidate, platform3)) return candidate;
69166
- }
69167
- }
69168
- return null;
69169
- }
69170
- async function isCommandOnPath(command, env, platform3) {
69171
- return await resolveCommandOnPath(command, env, platform3) !== null;
69172
- }
69173
-
69174
- // src/capabilities/providers/alan-code.ts
69175
69353
  var ALAN_CODE_BACKEND = "alan_code";
69176
69354
  function withPackagedAlanCodeEngine(env, bundle, platform3) {
69177
69355
  if (bundle === void 0) return { ...env };
@@ -69351,14 +69529,14 @@ function captureProbe(command, args, options) {
69351
69529
  }
69352
69530
 
69353
69531
  // src/capabilities/providers/inventory.ts
69354
- var import_promises46 = require("fs/promises");
69532
+ var import_promises47 = require("fs/promises");
69355
69533
  var import_node_os7 = require("os");
69356
69534
  init_runtime_v2();
69357
69535
 
69358
69536
  // src/capabilities/providers/account-label.ts
69359
69537
  var import_node_child_process18 = require("child_process");
69360
69538
  var import_node_fs25 = require("fs");
69361
- var import_node_path54 = require("path");
69539
+ var import_node_path55 = require("path");
69362
69540
  var import_node_url6 = require("url");
69363
69541
  init_process();
69364
69542
  var ACCOUNT_TIMEOUT_MS = 2e4;
@@ -69460,7 +69638,7 @@ async function claudeLabel(executable, env) {
69460
69638
  try {
69461
69639
  const childEnv = { ...env };
69462
69640
  delete childEnv.FORCE_CODE_TERMINAL;
69463
- const bundledSdk = typeof __dirname === "string" ? (0, import_node_path54.join)(__dirname, "claude-sdk.mjs") : "";
69641
+ const bundledSdk = typeof __dirname === "string" ? (0, import_node_path55.join)(__dirname, "claude-sdk.mjs") : "";
69464
69642
  const sdkSpecifier = (0, import_node_fs25.existsSync)(bundledSdk) ? (0, import_node_url6.pathToFileURL)(bundledSdk).href : "@anthropic-ai/claude-agent-sdk";
69465
69643
  const { query } = await import(sdkSpecifier);
69466
69644
  const session = query({
@@ -69813,8 +69991,8 @@ async function executablesFingerprint(env, platform3) {
69813
69991
  const executable = await resolveProviderExecutable(provider4, env, platform3);
69814
69992
  if (executable === null) return `${provider4.backendKind}:-`;
69815
69993
  try {
69816
- const target = await (0, import_promises46.realpath)(executable);
69817
- const { size, mtimeMs } = await (0, import_promises46.stat)(target);
69994
+ const target = await (0, import_promises47.realpath)(executable);
69995
+ const { size, mtimeMs } = await (0, import_promises47.stat)(target);
69818
69996
  return `${provider4.backendKind}:${target}:${size}:${mtimeMs}`;
69819
69997
  } catch {
69820
69998
  return `${provider4.backendKind}:${executable}:?`;
@@ -69867,23 +70045,23 @@ function createCapabilityInventory(options) {
69867
70045
  }
69868
70046
 
69869
70047
  // src/capabilities/providers/login-path.ts
69870
- var import_node_path58 = require("path");
70048
+ var import_node_path59 = require("path");
69871
70049
  init_process();
69872
70050
 
69873
70051
  // ../shared/src/node/shell-environment.ts
69874
70052
  var import_node_child_process19 = require("child_process");
69875
- var import_node_crypto39 = require("crypto");
70053
+ var import_node_crypto40 = require("crypto");
69876
70054
  var import_node_fs27 = require("fs");
69877
70055
  var import_node_os9 = require("os");
69878
- var import_node_path57 = require("path");
70056
+ var import_node_path58 = require("path");
69879
70057
 
69880
70058
  // ../shared/src/node/shell-path.ts
69881
70059
  var import_node_os8 = require("os");
69882
- var import_node_path56 = require("path");
70060
+ var import_node_path57 = require("path");
69883
70061
 
69884
70062
  // ../shared/src/node/version-manager-paths.ts
69885
70063
  var import_node_fs26 = require("fs");
69886
- var import_node_path55 = require("path");
70064
+ var import_node_path56 = require("path");
69887
70065
  function compareNodeVersionsDesc(a, b) {
69888
70066
  const parse7 = (value2) => value2.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
69889
70067
  const left = parse7(a);
@@ -69895,11 +70073,11 @@ function compareNodeVersionsDesc(a, b) {
69895
70073
  return 0;
69896
70074
  }
69897
70075
  function resolveNvmDefaultBin(home) {
69898
- const versionsDir = (0, import_node_path55.join)(home, ".nvm", "versions", "node");
70076
+ const versionsDir = (0, import_node_path56.join)(home, ".nvm", "versions", "node");
69899
70077
  if (!(0, import_node_fs26.existsSync)(versionsDir)) return null;
69900
70078
  let alias = null;
69901
70079
  try {
69902
- const aliasFile = (0, import_node_path55.join)(home, ".nvm", "alias", "default");
70080
+ const aliasFile = (0, import_node_path56.join)(home, ".nvm", "alias", "default");
69903
70081
  if ((0, import_node_fs26.existsSync)(aliasFile)) alias = (0, import_node_fs26.readFileSync)(aliasFile, "utf8").trim();
69904
70082
  } catch {
69905
70083
  alias = null;
@@ -69916,18 +70094,18 @@ function resolveNvmDefaultBin(home) {
69916
70094
  ) : [];
69917
70095
  const chosen = (matching.length > 0 ? matching : installed).sort(compareNodeVersionsDesc)[0];
69918
70096
  if (!chosen) return null;
69919
- const bin = (0, import_node_path55.join)(versionsDir, chosen, "bin");
70097
+ const bin = (0, import_node_path56.join)(versionsDir, chosen, "bin");
69920
70098
  return (0, import_node_fs26.existsSync)(bin) ? bin : null;
69921
70099
  }
69922
70100
  function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
69923
70101
  if (platform3 === "win32") return [];
69924
70102
  const candidates2 = [
69925
70103
  resolveNvmDefaultBin(home),
69926
- (0, import_node_path55.join)(home, ".volta", "bin"),
69927
- (0, import_node_path55.join)(home, ".fnm", "aliases", "default", "bin"),
69928
- (0, import_node_path55.join)(home, "Library", "Application Support", "fnm", "aliases", "default", "bin"),
69929
- (0, import_node_path55.join)(home, ".asdf", "shims"),
69930
- (0, import_node_path55.join)(home, ".local", "share", "mise", "shims")
70104
+ (0, import_node_path56.join)(home, ".volta", "bin"),
70105
+ (0, import_node_path56.join)(home, ".fnm", "aliases", "default", "bin"),
70106
+ (0, import_node_path56.join)(home, "Library", "Application Support", "fnm", "aliases", "default", "bin"),
70107
+ (0, import_node_path56.join)(home, ".asdf", "shims"),
70108
+ (0, import_node_path56.join)(home, ".local", "share", "mise", "shims")
69931
70109
  ];
69932
70110
  const seen = /* @__PURE__ */ new Set();
69933
70111
  const resolved = [];
@@ -69959,9 +70137,9 @@ function promoteAheadOfVersionManagers(path4, promoted, versionManagerDirs) {
69959
70137
  }
69960
70138
  function promotedUserBinDirs(home) {
69961
70139
  return /* @__PURE__ */ new Set([
69962
- (0, import_node_path56.join)(home, ".local", "bin"),
69963
- (0, import_node_path56.join)(home, ".bun", "bin"),
69964
- (0, import_node_path56.join)(home, ".cargo", "bin")
70140
+ (0, import_node_path57.join)(home, ".local", "bin"),
70141
+ (0, import_node_path57.join)(home, ".bun", "bin"),
70142
+ (0, import_node_path57.join)(home, ".cargo", "bin")
69965
70143
  ]);
69966
70144
  }
69967
70145
  function promoteUserBinDirs(path4, home, versionManagerDirs) {
@@ -69983,10 +70161,10 @@ function isExecutableFile(path4) {
69983
70161
  function resolveLoginShell(env = process.env) {
69984
70162
  if ((0, import_node_os9.platform)() === "win32") return null;
69985
70163
  const explicit = env.SHELL?.trim();
69986
- if (explicit && (0, import_node_path57.isAbsolute)(explicit) && isExecutableFile(explicit)) return explicit;
70164
+ if (explicit && (0, import_node_path58.isAbsolute)(explicit) && isExecutableFile(explicit)) return explicit;
69987
70165
  try {
69988
70166
  const accountShell = (0, import_node_os9.userInfo)().shell?.trim();
69989
- if (accountShell && (0, import_node_path57.isAbsolute)(accountShell) && isExecutableFile(accountShell)) {
70167
+ if (accountShell && (0, import_node_path58.isAbsolute)(accountShell) && isExecutableFile(accountShell)) {
69990
70168
  return accountShell;
69991
70169
  }
69992
70170
  } catch {
@@ -70003,17 +70181,17 @@ var MARKER = "__ALAN_LOGIN_PATH__";
70003
70181
  var SELF_GUARD_ENV = "ALAN_RESOLVING_ENVIRONMENT";
70004
70182
  var lastKnownGoodSchema = external_exports.object({ path: external_exports.string().min(1) });
70005
70183
  function installerDirectories(home, platform3) {
70006
- const user = home.length > 0 ? [(0, import_node_path58.join)(home, ".local", "bin"), (0, import_node_path58.join)(home, ".bun", "bin")] : [];
70184
+ const user = home.length > 0 ? [(0, import_node_path59.join)(home, ".local", "bin"), (0, import_node_path59.join)(home, ".bun", "bin")] : [];
70007
70185
  const system = platform3 === "darwin" ? ["/opt/homebrew/bin", "/usr/local/bin"] : ["/usr/local/bin"];
70008
70186
  return [...user, ...system];
70009
70187
  }
70010
70188
  function windowsInstallerDirectories(env) {
70011
70189
  const home = envValue(env, "USERPROFILE") || envValue(env, "HOME");
70012
- const hasHome = import_node_path58.win32.isAbsolute(home);
70013
- const appData = envValue(env, "APPDATA") || (hasHome ? import_node_path58.win32.join(home, "AppData", "Roaming") : "");
70190
+ const hasHome = import_node_path59.win32.isAbsolute(home);
70191
+ const appData = envValue(env, "APPDATA") || (hasHome ? import_node_path59.win32.join(home, "AppData", "Roaming") : "");
70014
70192
  return [
70015
- ...hasHome ? [import_node_path58.win32.join(home, ".local", "bin")] : [],
70016
- ...import_node_path58.win32.isAbsolute(appData) ? [import_node_path58.win32.join(appData, "npm")] : []
70193
+ ...hasHome ? [import_node_path59.win32.join(home, ".local", "bin")] : [],
70194
+ ...import_node_path59.win32.isAbsolute(appData) ? [import_node_path59.win32.join(appData, "npm")] : []
70017
70195
  ];
70018
70196
  }
70019
70197
  function printPathCommand() {
@@ -70030,7 +70208,7 @@ async function readLoginShellPath(env, capture) {
70030
70208
  const shell = resolveLoginShell({ ...env });
70031
70209
  if (shell === null) return null;
70032
70210
  const probeEnv = { ...env, [SELF_GUARD_ENV]: "1" };
70033
- const cshFamily = (0, import_node_path58.basename)(shell) === "csh" || (0, import_node_path58.basename)(shell) === "tcsh";
70211
+ const cshFamily = (0, import_node_path59.basename)(shell) === "csh" || (0, import_node_path59.basename)(shell) === "tcsh";
70034
70212
  const interactive = await capture(shell, [cshFamily ? "-ic" : "-ilc", printPathCommand()], {
70035
70213
  env: probeEnv,
70036
70214
  timeoutMs: LOGIN_SHELL_TIMEOUT_MS
@@ -70122,9 +70300,9 @@ async function openCliEnvironment(options) {
70122
70300
  }
70123
70301
 
70124
70302
  // src/capabilities/providers/managed.ts
70125
- var import_node_crypto40 = require("crypto");
70126
- var import_promises47 = require("fs/promises");
70127
- var import_node_path59 = require("path");
70303
+ var import_node_crypto41 = require("crypto");
70304
+ var import_promises48 = require("fs/promises");
70305
+ var import_node_path60 = require("path");
70128
70306
  init_process();
70129
70307
  init_zod();
70130
70308
  var PACKAGES = {
@@ -70145,7 +70323,7 @@ async function cleanFailedInstall(staged, error62) {
70145
70323
  throw new Error(`${error62.message}; retained staging directory: ${staged}`, { cause: error62 });
70146
70324
  }
70147
70325
  try {
70148
- await (0, import_promises47.rm)(staged, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
70326
+ await (0, import_promises48.rm)(staged, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
70149
70327
  } catch (cleanupError) {
70150
70328
  const message2 = error62 instanceof Error ? error62.message : String(error62);
70151
70329
  throw new AggregateError(
@@ -70158,7 +70336,7 @@ async function cleanFailedInstall(staged, error62) {
70158
70336
  }
70159
70337
  async function readManagedProviderVersion(file2, backendKind) {
70160
70338
  try {
70161
- const selected = selectedSchema.parse(JSON.parse(await (0, import_promises47.readFile)(file2, "utf8")));
70339
+ const selected = selectedSchema.parse(JSON.parse(await (0, import_promises48.readFile)(file2, "utf8")));
70162
70340
  const version2 = selected[backendKind];
70163
70341
  return version2 !== void 0 && VERSION.test(version2) ? version2 : null;
70164
70342
  } catch {
@@ -70216,16 +70394,16 @@ async function installVersion2(backendKind, requested, options, signal) {
70216
70394
  );
70217
70395
  }
70218
70396
  function selection(root, backendKind, version2) {
70219
- const binDir = (0, import_node_path59.join)(root, "versions", backendKind, version2, "node_modules", ".bin");
70397
+ const binDir = (0, import_node_path60.join)(root, "versions", backendKind, version2, "node_modules", ".bin");
70220
70398
  return {
70221
70399
  backendKind,
70222
70400
  version: version2,
70223
70401
  binDir,
70224
- executable: (0, import_node_path59.join)(binDir, packageFor(backendKind).command)
70402
+ executable: (0, import_node_path60.join)(binDir, packageFor(backendKind).command)
70225
70403
  };
70226
70404
  }
70227
70405
  async function runnable(file2) {
70228
- return (0, import_promises47.stat)(file2).then(
70406
+ return (0, import_promises48.stat)(file2).then(
70229
70407
  (value2) => value2.isFile(),
70230
70408
  () => false
70231
70409
  );
@@ -70234,7 +70412,7 @@ function createManagedProviderClis(options) {
70234
70412
  const state = {};
70235
70413
  const updateCache = /* @__PURE__ */ new Map();
70236
70414
  let queue = Promise.resolve();
70237
- const file2 = (0, import_node_path59.join)(options.root, "selected.json");
70415
+ const file2 = (0, import_node_path60.join)(options.root, "selected.json");
70238
70416
  const latestVersionFor = async (packageName, signal) => {
70239
70417
  const cached2 = updateCache.get(packageName);
70240
70418
  if (cached2 && cached2.expiresAt > Date.now()) return cached2.latestVersion;
@@ -70268,13 +70446,13 @@ function createManagedProviderClis(options) {
70268
70446
  return next;
70269
70447
  };
70270
70448
  const persist = async () => {
70271
- await (0, import_promises47.mkdir)(options.root, { recursive: true, mode: 448 });
70272
- const staged = `${file2}.${(0, import_node_crypto40.randomUUID)()}`;
70449
+ await (0, import_promises48.mkdir)(options.root, { recursive: true, mode: 448 });
70450
+ const staged = `${file2}.${(0, import_node_crypto41.randomUUID)()}`;
70273
70451
  try {
70274
- await (0, import_promises47.writeFile)(staged, JSON.stringify(state), { mode: 384 });
70275
- await (0, import_promises47.rename)(staged, file2);
70452
+ await (0, import_promises48.writeFile)(staged, JSON.stringify(state), { mode: 384 });
70453
+ await (0, import_promises48.rename)(staged, file2);
70276
70454
  } finally {
70277
- await (0, import_promises47.rm)(staged, { force: true });
70455
+ await (0, import_promises48.rm)(staged, { force: true });
70278
70456
  }
70279
70457
  };
70280
70458
  const activate = async (backendKind, version2, signal) => {
@@ -70297,7 +70475,7 @@ function createManagedProviderClis(options) {
70297
70475
  return {
70298
70476
  selectionFile: file2,
70299
70477
  load: async () => {
70300
- const raw = await (0, import_promises47.readFile)(file2, "utf8").catch((error62) => {
70478
+ const raw = await (0, import_promises48.readFile)(file2, "utf8").catch((error62) => {
70301
70479
  if (error62 instanceof Error && "code" in error62 && error62.code === "ENOENT") return "{}";
70302
70480
  throw error62;
70303
70481
  });
@@ -70305,7 +70483,7 @@ function createManagedProviderClis(options) {
70305
70483
  try {
70306
70484
  parsed = selectedSchema.parse(JSON.parse(raw));
70307
70485
  } catch {
70308
- await (0, import_promises47.rename)(file2, `${file2}.invalid.${(0, import_node_crypto40.randomUUID)()}`).catch(() => void 0);
70486
+ await (0, import_promises48.rename)(file2, `${file2}.invalid.${(0, import_node_crypto41.randomUUID)()}`).catch(() => void 0);
70309
70487
  return;
70310
70488
  }
70311
70489
  for (const [backendKind, version2] of Object.entries(parsed)) {
@@ -70324,8 +70502,8 @@ function createManagedProviderClis(options) {
70324
70502
  available: async () => {
70325
70503
  const groups = await Promise.all(
70326
70504
  Object.keys(PACKAGES).map(async (backendKind) => {
70327
- const directory = (0, import_node_path59.join)(options.root, "versions", backendKind);
70328
- const versions = await (0, import_promises47.readdir)(directory).catch((error62) => {
70505
+ const directory = (0, import_node_path60.join)(options.root, "versions", backendKind);
70506
+ const versions = await (0, import_promises48.readdir)(directory).catch((error62) => {
70329
70507
  if (error62 instanceof Error && "code" in error62 && error62.code === "ENOENT") return [];
70330
70508
  throw error62;
70331
70509
  });
@@ -70360,20 +70538,20 @@ function createManagedProviderClis(options) {
70360
70538
  signal?.throwIfAborted();
70361
70539
  const provider4 = packageFor(backendKind);
70362
70540
  const exact = await installVersion2(backendKind, version2, options, signal);
70363
- const target = (0, import_node_path59.join)(options.root, "versions", backendKind, exact);
70541
+ const target = (0, import_node_path60.join)(options.root, "versions", backendKind, exact);
70364
70542
  const existing = selection(options.root, backendKind, exact);
70365
70543
  if (!await runnable(existing.executable) || !await options.probe(existing.executable, backendKind, signal)) {
70366
- await (0, import_promises47.mkdir)((0, import_node_path59.dirname)(target), { recursive: true, mode: 448 });
70367
- const staged = `${target}.${(0, import_node_crypto40.randomUUID)()}`;
70544
+ await (0, import_promises48.mkdir)((0, import_node_path60.dirname)(target), { recursive: true, mode: 448 });
70545
+ const staged = `${target}.${(0, import_node_crypto41.randomUUID)()}`;
70368
70546
  try {
70369
70547
  await options.installPackage(provider4.name, exact, staged, provider4.command, signal);
70370
- const built = (0, import_node_path59.join)(staged, "node_modules", ".bin", provider4.command);
70548
+ const built = (0, import_node_path60.join)(staged, "node_modules", ".bin", provider4.command);
70371
70549
  if (!await runnable(built) || !await options.probe(built, backendKind, signal)) {
70372
70550
  throw new Error(`${backendKind}@${exact} failed its executable probe`);
70373
70551
  }
70374
70552
  signal?.throwIfAborted();
70375
- await (0, import_promises47.rm)(target, { recursive: true, force: true });
70376
- await (0, import_promises47.rename)(staged, target);
70553
+ await (0, import_promises48.rm)(target, { recursive: true, force: true });
70554
+ await (0, import_promises48.rename)(staged, target);
70377
70555
  } catch (error62) {
70378
70556
  await cleanFailedInstall(staged, error62);
70379
70557
  }
@@ -70398,7 +70576,7 @@ function createManagedProviderClis(options) {
70398
70576
  function withInstallerPath(options) {
70399
70577
  const platform3 = options.platform ?? process.platform;
70400
70578
  const path4 = [
70401
- platform3 === "win32" ? import_node_path59.win32.dirname(options.command) : (0, import_node_path59.dirname)(options.command),
70579
+ platform3 === "win32" ? import_node_path60.win32.dirname(options.command) : (0, import_node_path60.dirname)(options.command),
70402
70580
  envValue(options.env, "PATH")
70403
70581
  ].filter(Boolean).join(pathDelimiter(platform3));
70404
70582
  const env = { ...options.env, PATH: path4 };
@@ -70482,23 +70660,23 @@ ${help.stderr}`);
70482
70660
  }
70483
70661
 
70484
70662
  // src/capabilities/skills/legacy-cleanup.ts
70485
- var import_promises48 = require("fs/promises");
70486
- var import_node_path60 = require("path");
70663
+ var import_promises49 = require("fs/promises");
70664
+ var import_node_path61 = require("path");
70487
70665
  var LEGACY_FOLDER = /--(?:alan-(?:production|staging|local(?:-[0-9a-f]{12})?)|[0-9a-f]{8})$/;
70488
70666
  var MANAGED_MARKER = ".alan-managed.json";
70489
70667
  var COMPATIBILITY_MARKER = ".alan-compatibility.json";
70490
70668
  async function listEntries(directory) {
70491
- return (0, import_promises48.readdir)(directory, { withFileTypes: true }).catch(() => []);
70669
+ return (0, import_promises49.readdir)(directory, { withFileTypes: true }).catch(() => []);
70492
70670
  }
70493
70671
  async function isRegularFile(path4) {
70494
- return (0, import_promises48.lstat)(path4).then(
70672
+ return (0, import_promises49.lstat)(path4).then(
70495
70673
  (stats) => stats.isFile(),
70496
70674
  () => false
70497
70675
  );
70498
70676
  }
70499
70677
  async function isMissing(path4) {
70500
70678
  try {
70501
- await (0, import_promises48.lstat)(path4);
70679
+ await (0, import_promises49.lstat)(path4);
70502
70680
  return false;
70503
70681
  } catch (error62) {
70504
70682
  return errnoCode(error62) === "ENOENT";
@@ -70506,39 +70684,39 @@ async function isMissing(path4) {
70506
70684
  }
70507
70685
  async function removeLink(path4) {
70508
70686
  try {
70509
- await (0, import_promises48.unlink)(path4);
70687
+ await (0, import_promises49.unlink)(path4);
70510
70688
  } catch (error62) {
70511
70689
  const code = errnoCode(error62);
70512
70690
  if (code !== "EPERM" && code !== "EISDIR") throw error62;
70513
- await (0, import_promises48.rmdir)(path4);
70691
+ await (0, import_promises49.rmdir)(path4);
70514
70692
  }
70515
70693
  }
70516
70694
  async function isOrphanedLegacyLink(agentsDir, path4, removed) {
70517
- const target = await (0, import_promises48.readlink)(path4).catch(() => null);
70695
+ const target = await (0, import_promises49.readlink)(path4).catch(() => null);
70518
70696
  if (target === null) return false;
70519
- const absolute = (0, import_node_path60.resolve)((0, import_node_path60.dirname)(path4), target);
70520
- return (0, import_node_path60.dirname)(absolute) === agentsDir && (removed.has(absolute) || LEGACY_FOLDER.test((0, import_node_path60.basename)(absolute))) && await isMissing(absolute);
70697
+ const absolute = (0, import_node_path61.resolve)((0, import_node_path61.dirname)(path4), target);
70698
+ return (0, import_node_path61.dirname)(absolute) === agentsDir && (removed.has(absolute) || LEGACY_FOLDER.test((0, import_node_path61.basename)(absolute))) && await isMissing(absolute);
70521
70699
  }
70522
70700
  async function removeLegacyPackages(agentsDir, attempt2) {
70523
70701
  const removed = [];
70524
70702
  for (const entry of await listEntries(agentsDir)) {
70525
- const path4 = (0, import_node_path60.join)(agentsDir, entry.name);
70526
- if (!entry.isDirectory() || !await isRegularFile((0, import_node_path60.join)(path4, MANAGED_MARKER))) continue;
70527
- if (await attempt2(path4, () => (0, import_promises48.rm)(path4, { recursive: true, force: true }))) removed.push(path4);
70703
+ const path4 = (0, import_node_path61.join)(agentsDir, entry.name);
70704
+ if (!entry.isDirectory() || !await isRegularFile((0, import_node_path61.join)(path4, MANAGED_MARKER))) continue;
70705
+ if (await attempt2(path4, () => (0, import_promises49.rm)(path4, { recursive: true, force: true }))) removed.push(path4);
70528
70706
  }
70529
70707
  return removed;
70530
70708
  }
70531
70709
  async function isLegacyClaudeEntry(agentsDir, path4, entry, removed) {
70532
70710
  if (entry.isSymbolicLink()) return isOrphanedLegacyLink(agentsDir, path4, removed);
70533
- return entry.isDirectory() && isRegularFile((0, import_node_path60.join)(path4, COMPATIBILITY_MARKER));
70711
+ return entry.isDirectory() && isRegularFile((0, import_node_path61.join)(path4, COMPATIBILITY_MARKER));
70534
70712
  }
70535
70713
  async function removeLegacyClaudeEntries(claudeDir, agentsDir, removedPackages, attempt2) {
70536
70714
  const removedSet = new Set(removedPackages);
70537
70715
  const removed = [];
70538
70716
  for (const entry of await listEntries(claudeDir)) {
70539
- const path4 = (0, import_node_path60.join)(claudeDir, entry.name);
70717
+ const path4 = (0, import_node_path61.join)(claudeDir, entry.name);
70540
70718
  if (!await isLegacyClaudeEntry(agentsDir, path4, entry, removedSet)) continue;
70541
- const remove = entry.isSymbolicLink() ? () => removeLink(path4) : () => (0, import_promises48.rm)(path4, { recursive: true, force: true });
70719
+ const remove = entry.isSymbolicLink() ? () => removeLink(path4) : () => (0, import_promises49.rm)(path4, { recursive: true, force: true });
70542
70720
  if (await attempt2(path4, remove)) removed.push(path4);
70543
70721
  }
70544
70722
  return removed;
@@ -70554,28 +70732,28 @@ async function removeLegacySkillFolders(home) {
70554
70732
  return false;
70555
70733
  }
70556
70734
  };
70557
- const agentsDir = (0, import_node_path60.join)(home, ".agents", "skills");
70735
+ const agentsDir = (0, import_node_path61.join)(home, ".agents", "skills");
70558
70736
  const packages = await removeLegacyPackages(agentsDir, attempt2);
70559
70737
  const links = await removeLegacyClaudeEntries(
70560
- (0, import_node_path60.join)(home, ".claude", "skills"),
70738
+ (0, import_node_path61.join)(home, ".claude", "skills"),
70561
70739
  agentsDir,
70562
70740
  packages,
70563
70741
  attempt2
70564
70742
  );
70565
- const profiles = (0, import_node_path60.join)(home, ".alan", "skills", "profiles");
70566
- const profilesRemoved = !await isMissing(profiles) && await attempt2(profiles, () => (0, import_promises48.rm)(profiles, { recursive: true, force: true }));
70743
+ const profiles = (0, import_node_path61.join)(home, ".alan", "skills", "profiles");
70744
+ const profilesRemoved = !await isMissing(profiles) && await attempt2(profiles, () => (0, import_promises49.rm)(profiles, { recursive: true, force: true }));
70567
70745
  return { packages, links, profilesRemoved, failed };
70568
70746
  }
70569
70747
 
70570
70748
  // src/capabilities/skills/local-preview.ts
70571
- var import_promises53 = require("fs/promises");
70572
- var import_node_path65 = __toESM(require("path"));
70749
+ var import_promises54 = require("fs/promises");
70750
+ var import_node_path66 = __toESM(require("path"));
70573
70751
 
70574
70752
  // ../shared/src/node/skill-package.ts
70575
70753
  var import_node_buffer = require("buffer");
70576
- var import_node_crypto41 = require("crypto");
70577
- var import_promises49 = require("fs/promises");
70578
- var import_node_path61 = require("path");
70754
+ var import_node_crypto42 = require("crypto");
70755
+ var import_promises50 = require("fs/promises");
70756
+ var import_node_path62 = require("path");
70579
70757
  var import_yaml = __toESM(require_dist(), 1);
70580
70758
  init_contracts();
70581
70759
  init_domain();
@@ -70652,7 +70830,7 @@ async function inspectSkillPackage(packageRoot, options = {}) {
70652
70830
  inspectedFiles.sort(comparePackageFiles);
70653
70831
  const parsedMetadata = parseSkillMetadata(
70654
70832
  inspectedFiles.find((file2) => file2.manifest.path === "SKILL.md")?.bytes,
70655
- options.expectedName === void 0 ? (0, import_node_path61.basename)(root) : options.expectedName
70833
+ options.expectedName === void 0 ? (0, import_node_path62.basename)(root) : options.expectedName
70656
70834
  );
70657
70835
  const manifestFiles = inspectedFiles.map((file2) => file2.manifest);
70658
70836
  const diagnostics = [
@@ -70681,11 +70859,11 @@ async function readSkillPackageFile(packageRoot, path4, expectedSha256) {
70681
70859
  if (!normalizedPath || normalizedPath !== path4 || normalizedPath.includes("\\") || components.some((component) => !component || component === "." || component === "..")) {
70682
70860
  throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${path4}`, path4);
70683
70861
  }
70684
- const absolutePath = await (0, import_promises49.realpath)((0, import_node_path61.resolve)(root, ...components)).catch(() => null);
70862
+ const absolutePath = await (0, import_promises50.realpath)((0, import_node_path62.resolve)(root, ...components)).catch(() => null);
70685
70863
  if (!absolutePath || normalizeRelativePath(root, absolutePath) !== normalizedPath) {
70686
70864
  throw new SkillPackageError("INVALID_PATH", `Skill package file was not found: ${path4}`, path4);
70687
70865
  }
70688
- const entryStat = await (0, import_promises49.lstat)(absolutePath);
70866
+ const entryStat = await (0, import_promises50.lstat)(absolutePath);
70689
70867
  if (!entryStat.isFile()) {
70690
70868
  throw new SkillPackageError(
70691
70869
  "SPECIAL_FILE_BLOCKED",
@@ -70706,11 +70884,11 @@ async function readSkillPackageFile(packageRoot, path4, expectedSha256) {
70706
70884
  return { file: read.manifest, bytes: read.bytes };
70707
70885
  }
70708
70886
  async function requirePackageRoot(packageRoot) {
70709
- const root = await (0, import_promises49.realpath)((0, import_node_path61.resolve)(packageRoot)).catch(() => null);
70887
+ const root = await (0, import_promises50.realpath)((0, import_node_path62.resolve)(packageRoot)).catch(() => null);
70710
70888
  if (!root) {
70711
70889
  throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package directory does not exist");
70712
70890
  }
70713
- const rootStat = await (0, import_promises49.lstat)(root);
70891
+ const rootStat = await (0, import_promises50.lstat)(root);
70714
70892
  if (!rootStat.isDirectory()) {
70715
70893
  throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package root must be a directory");
70716
70894
  }
@@ -70736,12 +70914,12 @@ async function walkPackage(root, ignoredPaths) {
70736
70914
  }
70737
70915
  return files;
70738
70916
  async function walkDirectory(directory) {
70739
- const entries = await (0, import_promises49.readdir)(directory, { withFileTypes: true });
70917
+ const entries = await (0, import_promises50.readdir)(directory, { withFileTypes: true });
70740
70918
  for (const entry of entries) {
70741
- const absolutePath = (0, import_node_path61.resolve)(directory, entry.name);
70919
+ const absolutePath = (0, import_node_path62.resolve)(directory, entry.name);
70742
70920
  const normalizedPath = normalizeRelativePath(root, absolutePath);
70743
70921
  if (isIgnored(normalizedPath, entry.name, entry.isDirectory(), ignored2)) continue;
70744
- const entryStat = await (0, import_promises49.lstat)(absolutePath);
70922
+ const entryStat = await (0, import_promises50.lstat)(absolutePath);
70745
70923
  if (entryStat.isSymbolicLink()) {
70746
70924
  throw new SkillPackageError(
70747
70925
  "SYMLINK_BLOCKED",
@@ -70810,12 +70988,12 @@ function globToRegExp(pattern) {
70810
70988
  return new RegExp(`${source}(?:/.*)?$`);
70811
70989
  }
70812
70990
  function normalizeRelativePath(root, absolutePath) {
70813
- const nativeRelativePath = (0, import_node_path61.relative)(root, absolutePath);
70814
- if (!nativeRelativePath || nativeRelativePath.startsWith(`..${import_node_path61.sep}`) || nativeRelativePath === "..") {
70991
+ const nativeRelativePath = (0, import_node_path62.relative)(root, absolutePath);
70992
+ if (!nativeRelativePath || nativeRelativePath.startsWith(`..${import_node_path62.sep}`) || nativeRelativePath === "..") {
70815
70993
  throw new SkillPackageError("INVALID_PATH", "Skill package path escapes its root");
70816
70994
  }
70817
- const normalized2 = nativeRelativePath.split(import_node_path61.sep).join("/").normalize("NFC");
70818
- if (normalized2.includes("\0") || normalized2.includes("\uFFFD") || import_node_path61.posix.isAbsolute(normalized2)) {
70995
+ const normalized2 = nativeRelativePath.split(import_node_path62.sep).join("/").normalize("NFC");
70996
+ if (normalized2.includes("\0") || normalized2.includes("\uFFFD") || import_node_path62.posix.isAbsolute(normalized2)) {
70819
70997
  throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${normalized2}`);
70820
70998
  }
70821
70999
  return normalized2;
@@ -70862,12 +71040,12 @@ function requireSafeFile(path4, size, normalizedPaths) {
70862
71040
  }
70863
71041
  }
70864
71042
  function isSecretPath(path4) {
70865
- const name = import_node_path61.posix.basename(path4).toLowerCase();
71043
+ const name = import_node_path62.posix.basename(path4).toLowerCase();
70866
71044
  if (SECRET_BASENAMES.has(name) || name.startsWith(".env.")) return true;
70867
71045
  return name.endsWith(".private-key.pem") || name.endsWith(".private-key.key");
70868
71046
  }
70869
71047
  async function readPackageFile(file2) {
70870
- const bytes = await (0, import_promises49.readFile)(file2.absolutePath);
71048
+ const bytes = await (0, import_promises50.readFile)(file2.absolutePath);
70871
71049
  return {
70872
71050
  bytes,
70873
71051
  manifest: {
@@ -70885,11 +71063,11 @@ function classifyFileKind(path4) {
70885
71063
  if (path4.startsWith("scripts/")) return "script";
70886
71064
  if (path4.startsWith("references/")) return "reference";
70887
71065
  if (path4.startsWith("assets/")) return "asset";
70888
- if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(import_node_path61.posix.basename(path4))) return "license";
71066
+ if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(import_node_path62.posix.basename(path4))) return "license";
70889
71067
  return "other";
70890
71068
  }
70891
71069
  function classifyPreview(path4, bytes) {
70892
- const extension = import_node_path61.posix.extname(path4).toLowerCase();
71070
+ const extension = import_node_path62.posix.extname(path4).toLowerCase();
70893
71071
  if (IMAGE_EXTENSIONS2.has(extension)) return "image";
70894
71072
  if (bytes.includes(0)) return "binary";
70895
71073
  if (MARKDOWN_EXTENSIONS.has(extension)) return "markdown";
@@ -71010,7 +71188,7 @@ function normalizePackageReference(value2) {
71010
71188
  }
71011
71189
  const withoutSuffix = trimmed4.split(/[?#]/, 1)[0];
71012
71190
  if (!withoutSuffix) return null;
71013
- const normalized2 = import_node_path61.posix.normalize(withoutSuffix).replace(/^\.\//, "").normalize("NFC");
71191
+ const normalized2 = import_node_path62.posix.normalize(withoutSuffix).replace(/^\.\//, "").normalize("NFC");
71014
71192
  if (normalized2 === ".." || normalized2.startsWith("../")) return null;
71015
71193
  return normalized2;
71016
71194
  }
@@ -71024,7 +71202,7 @@ function comparePackageFiles(left, right) {
71024
71202
  );
71025
71203
  }
71026
71204
  function hashPackageTree(files) {
71027
- const hash2 = (0, import_node_crypto41.createHash)("sha256");
71205
+ const hash2 = (0, import_node_crypto42.createHash)("sha256");
71028
71206
  hash2.update(TREE_HASH_PREFIX);
71029
71207
  for (const file2 of files) {
71030
71208
  const path4 = import_node_buffer.Buffer.from(file2.path, "utf8");
@@ -71037,7 +71215,7 @@ function hashPackageTree(files) {
71037
71215
  return `sha256:${hash2.digest("hex")}`;
71038
71216
  }
71039
71217
  function sha2562(bytes) {
71040
- return `sha256:${(0, import_node_crypto41.createHash)("sha256").update(bytes).digest("hex")}`;
71218
+ return `sha256:${(0, import_node_crypto42.createHash)("sha256").update(bytes).digest("hex")}`;
71041
71219
  }
71042
71220
  function uint322(value2) {
71043
71221
  const buffer = import_node_buffer.Buffer.allocUnsafe(4);
@@ -71051,22 +71229,22 @@ function uint642(value2) {
71051
71229
  }
71052
71230
 
71053
71231
  // src/capabilities/skills/local-sources.ts
71054
- var import_node_crypto43 = require("crypto");
71055
- var import_promises51 = require("fs/promises");
71056
- var import_node_path63 = __toESM(require("path"));
71232
+ var import_node_crypto44 = require("crypto");
71233
+ var import_promises52 = require("fs/promises");
71234
+ var import_node_path64 = __toESM(require("path"));
71057
71235
  init_type_guards();
71058
71236
 
71059
71237
  // src/capabilities/skills/local-scan.ts
71060
- var import_node_crypto42 = require("crypto");
71061
- var import_promises50 = require("fs/promises");
71062
- var import_node_path62 = __toESM(require("path"));
71238
+ var import_node_crypto43 = require("crypto");
71239
+ var import_promises51 = require("fs/promises");
71240
+ var import_node_path63 = __toESM(require("path"));
71063
71241
  var MAX_CANDIDATES = 2e3;
71064
71242
  var MAX_DIAGNOSTICS = 100;
71065
71243
  function createLocalSkillScanCache() {
71066
71244
  return { inspections: /* @__PURE__ */ new Map(), lastCompleteRevision: null };
71067
71245
  }
71068
71246
  async function scanSkillRoots(input2, cache2, managedRoots = []) {
71069
- const attemptId = (0, import_node_crypto42.randomUUID)();
71247
+ const attemptId = (0, import_node_crypto43.randomUUID)();
71070
71248
  const ignoredPaths = input2.ignoredPaths ?? [];
71071
71249
  const resolvedRoots = resolveScanRoots(input2.roots, input2.enabledProviderKinds ?? []);
71072
71250
  const pass = {
@@ -71132,7 +71310,7 @@ function failedLocalSkillScan(cache2, code, message2) {
71132
71310
  return {
71133
71311
  outcome: {
71134
71312
  status: "failed",
71135
- attemptId: (0, import_node_crypto42.randomUUID)(),
71313
+ attemptId: (0, import_node_crypto43.randomUUID)(),
71136
71314
  retainedInventoryRevision: cache2.lastCompleteRevision,
71137
71315
  diagnostics: [{ code, message: message2.slice(0, 2048) }]
71138
71316
  },
@@ -71178,8 +71356,8 @@ function invalid(resolvedRoot, name, error62) {
71178
71356
  };
71179
71357
  }
71180
71358
  async function scanRootAsPackage(pass, resolvedRoot) {
71181
- if (!await exists3(import_node_path62.default.join(resolvedRoot.directory, "SKILL.md"))) return null;
71182
- const canonical = await (0, import_promises50.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
71359
+ if (!await exists3(import_node_path63.default.join(resolvedRoot.directory, "SKILL.md"))) return null;
71360
+ const canonical = await (0, import_promises51.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
71183
71361
  if (isManaged(pass, canonical)) return { candidates: [], diagnostics: [], incomplete: false };
71184
71362
  try {
71185
71363
  const inspected = await inspectCached(pass, canonical, null);
@@ -71187,7 +71365,7 @@ async function scanRootAsPackage(pass, resolvedRoot) {
71187
71365
  candidates: [
71188
71366
  locate(
71189
71367
  resolvedRoot,
71190
- { key: inspected.metadata.name, order: import_node_path62.default.basename(canonical) },
71368
+ { key: inspected.metadata.name, order: import_node_path63.default.basename(canonical) },
71191
71369
  canonical,
71192
71370
  canonical,
71193
71371
  inspected
@@ -71199,7 +71377,7 @@ async function scanRootAsPackage(pass, resolvedRoot) {
71199
71377
  } catch (error62) {
71200
71378
  return {
71201
71379
  candidates: [],
71202
- diagnostics: [invalid(resolvedRoot, import_node_path62.default.basename(canonical), error62)],
71380
+ diagnostics: [invalid(resolvedRoot, import_node_path63.default.basename(canonical), error62)],
71203
71381
  incomplete: false
71204
71382
  };
71205
71383
  }
@@ -71209,7 +71387,7 @@ async function scanRoot(pass, resolvedRoot) {
71209
71387
  if (asPackage !== null) return asPackage;
71210
71388
  let entries;
71211
71389
  try {
71212
- entries = await (0, import_promises50.readdir)(resolvedRoot.directory, { withFileTypes: true });
71390
+ entries = await (0, import_promises51.readdir)(resolvedRoot.directory, { withFileTypes: true });
71213
71391
  } catch (error62) {
71214
71392
  const code = errnoCode(error62);
71215
71393
  if (code === "ENOENT" || code === "ENOTDIR") {
@@ -71227,7 +71405,7 @@ async function scanRoot(pass, resolvedRoot) {
71227
71405
  incomplete: true
71228
71406
  };
71229
71407
  }
71230
- const canonicalRoot = await (0, import_promises50.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
71408
+ const canonicalRoot = await (0, import_promises51.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
71231
71409
  const scan = { candidates: [], diagnostics: [], incomplete: false };
71232
71410
  for (const entry of entries) {
71233
71411
  if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
@@ -71239,7 +71417,7 @@ async function scanRoot(pass, resolvedRoot) {
71239
71417
  }
71240
71418
  async function scanEntry(pass, resolvedRoot, canonicalRoot, name) {
71241
71419
  const rootLabel = resolvedRoot.root.label;
71242
- const canonical = await (0, import_promises50.realpath)(import_node_path62.default.join(resolvedRoot.directory, name)).catch(() => null);
71420
+ const canonical = await (0, import_promises51.realpath)(import_node_path63.default.join(resolvedRoot.directory, name)).catch(() => null);
71243
71421
  if (canonical === null) {
71244
71422
  const message2 = `Could not resolve Skill ${name}`;
71245
71423
  return { kind: "diagnostic", diagnostic: { code: "SOURCE_UNREADABLE", message: message2, rootLabel } };
@@ -71255,7 +71433,7 @@ async function scanEntry(pass, resolvedRoot, canonicalRoot, name) {
71255
71433
  }
71256
71434
  if (!await isDirectory3(canonical) || pass.visited.has(canonical)) return null;
71257
71435
  pass.visited.add(canonical);
71258
- if (await exists3(import_node_path62.default.join(canonical, ".alan-managed.json"))) return null;
71436
+ if (await exists3(import_node_path63.default.join(canonical, ".alan-managed.json"))) return null;
71259
71437
  try {
71260
71438
  const inspected = await inspectCached(pass, canonical, void 0);
71261
71439
  const names = { key: name, order: name };
@@ -71276,7 +71454,7 @@ function resolveScanRoots(roots, enabledProviderKinds) {
71276
71454
  ).entries()) {
71277
71455
  resolved.push({
71278
71456
  root,
71279
- directory: import_node_path62.default.join(root.path, relative6),
71457
+ directory: import_node_path63.default.join(root.path, relative6),
71280
71458
  order: `1:${root.repositoryId}:${String(index).padStart(2, "0")}`
71281
71459
  });
71282
71460
  }
@@ -71298,11 +71476,11 @@ function candidateOrigin(root) {
71298
71476
  }
71299
71477
  function createLocalKey(root, skillName) {
71300
71478
  const rootIdentity = root.kind === "configured" ? `configured:${root.declarationId}` : root.kind === "repository" ? `repository:${root.repositoryId}` : "drafts";
71301
- const digest = (0, import_node_crypto42.createHash)("sha256").update("alan-local-skill-v1\0").update(rootIdentity).update("\0").update(skillName.normalize("NFC")).digest("hex");
71479
+ const digest = (0, import_node_crypto43.createHash)("sha256").update("alan-local-skill-v1\0").update(rootIdentity).update("\0").update(skillName.normalize("NFC")).digest("hex");
71302
71480
  return `local:${digest}`;
71303
71481
  }
71304
71482
  function hashInventory(candidates2) {
71305
- const hash2 = (0, import_node_crypto42.createHash)("sha256").update("alan-skill-inventory-v1\0");
71483
+ const hash2 = (0, import_node_crypto43.createHash)("sha256").update("alan-skill-inventory-v1\0");
71306
71484
  for (const candidate of candidates2) {
71307
71485
  hash2.update(candidate.localKey).update("\0");
71308
71486
  hash2.update(candidate.contentHash).update("\0");
@@ -71322,14 +71500,14 @@ function deduplicateByContent(candidates2) {
71322
71500
  return candidates2.filter((located) => winners.has(located));
71323
71501
  }
71324
71502
  async function fingerprintPackage(root) {
71325
- const hash2 = (0, import_node_crypto42.createHash)("sha256").update("alan-skill-stat-fingerprint-v1\0");
71503
+ const hash2 = (0, import_node_crypto43.createHash)("sha256").update("alan-skill-stat-fingerprint-v1\0");
71326
71504
  const visit2 = async (directory, relativeDirectory) => {
71327
- const entries = await (0, import_promises50.readdir)(directory, { withFileTypes: true });
71505
+ const entries = await (0, import_promises51.readdir)(directory, { withFileTypes: true });
71328
71506
  entries.sort((left, right) => Buffer.compare(Buffer.from(left.name), Buffer.from(right.name)));
71329
71507
  for (const entry of entries) {
71330
71508
  const relative6 = relativeDirectory ? `${relativeDirectory}/${entry.name}` : entry.name;
71331
- const absolute = import_node_path62.default.join(directory, entry.name);
71332
- const metadata = await (0, import_promises50.lstat)(absolute);
71509
+ const absolute = import_node_path63.default.join(directory, entry.name);
71510
+ const metadata = await (0, import_promises51.lstat)(absolute);
71333
71511
  const kind = entryKind(entry);
71334
71512
  hash2.update(relative6.normalize("NFC")).update(`\0${kind}\0${metadata.size}\0${metadata.mtimeMs}\0${metadata.mode & 511}\0`);
71335
71513
  if (entry.isDirectory()) await visit2(absolute, relative6);
@@ -71345,7 +71523,7 @@ function entryKind(entry) {
71345
71523
  }
71346
71524
  async function canonicalDirectories(directories) {
71347
71525
  const canonical = await Promise.all(
71348
- directories.map((directory) => (0, import_promises50.realpath)(directory).catch(() => directory))
71526
+ directories.map((directory) => (0, import_promises51.realpath)(directory).catch(() => directory))
71349
71527
  );
71350
71528
  return [...new Set(canonical)];
71351
71529
  }
@@ -71353,12 +71531,12 @@ function isManaged(pass, canonical) {
71353
71531
  return pass.managedRoots.some((root) => isWithinDirectory2(root, canonical));
71354
71532
  }
71355
71533
  function isWithinDirectory2(parent, candidate) {
71356
- const relative6 = import_node_path62.default.relative(parent, candidate);
71357
- return relative6 !== ".." && !relative6.startsWith(`..${import_node_path62.default.sep}`) && !import_node_path62.default.isAbsolute(relative6);
71534
+ const relative6 = import_node_path63.default.relative(parent, candidate);
71535
+ return relative6 !== ".." && !relative6.startsWith(`..${import_node_path63.default.sep}`) && !import_node_path63.default.isAbsolute(relative6);
71358
71536
  }
71359
71537
  async function exists3(candidate) {
71360
71538
  try {
71361
- await (0, import_promises50.access)(candidate);
71539
+ await (0, import_promises51.access)(candidate);
71362
71540
  return true;
71363
71541
  } catch {
71364
71542
  return false;
@@ -71366,7 +71544,7 @@ async function exists3(candidate) {
71366
71544
  }
71367
71545
  async function isDirectory3(candidate) {
71368
71546
  try {
71369
- return (await (0, import_promises50.lstat)(candidate)).isDirectory();
71547
+ return (await (0, import_promises51.lstat)(candidate)).isDirectory();
71370
71548
  } catch {
71371
71549
  return false;
71372
71550
  }
@@ -71414,7 +71592,7 @@ label = "OpenCode skills"
71414
71592
  providers = ["opencode_serve"]
71415
71593
  `;
71416
71594
  function skillSourceConfigPath(home) {
71417
- return import_node_path63.default.join(home, ".alan", "config.toml");
71595
+ return import_node_path64.default.join(home, ".alan", "config.toml");
71418
71596
  }
71419
71597
  async function resolveLocalScanInput(home, context, mode) {
71420
71598
  const loaded = await readSkillSourceConfig(home);
@@ -71426,13 +71604,13 @@ async function resolveLocalScanInput(home, context, mode) {
71426
71604
  }
71427
71605
  const enabledProviderKinds = context?.enabledProviderKinds ?? [];
71428
71606
  const enabled = new Set(enabledProviderKinds);
71429
- const drafts = import_node_path63.default.resolve(import_node_path63.default.join(home, ".alan", "skill-sources"));
71607
+ const drafts = import_node_path64.default.resolve(import_node_path64.default.join(home, ".alan", "skill-sources"));
71430
71608
  const roots = [];
71431
71609
  for (const source of config2.sources) {
71432
71610
  const owners = source.providerKinds;
71433
71611
  if (owners !== void 0 && !owners.some((provider4) => enabled.has(provider4))) continue;
71434
71612
  roots.push(
71435
- import_node_path63.default.resolve(source.path) === drafts ? { kind: "drafts", path: source.path, label: "Alan drafts" } : {
71613
+ import_node_path64.default.resolve(source.path) === drafts ? { kind: "drafts", path: source.path, label: "Alan drafts" } : {
71436
71614
  kind: "configured",
71437
71615
  declarationId: source.declarationId,
71438
71616
  path: source.path,
@@ -71454,7 +71632,7 @@ async function resolveLocalScanInput(home, context, mode) {
71454
71632
  async function readSkillSourceConfig(home) {
71455
71633
  let content;
71456
71634
  try {
71457
- content = await (0, import_promises51.readFile)(skillSourceConfigPath(home), "utf8");
71635
+ content = await (0, import_promises52.readFile)(skillSourceConfigPath(home), "utf8");
71458
71636
  } catch (error62) {
71459
71637
  if (errnoCode(error62) !== "ENOENT") {
71460
71638
  return { kind: "invalid_config", diagnostic: "~/.alan/config.toml could not be read" };
@@ -71496,7 +71674,7 @@ function parseSkillSourceConfig(content, home) {
71496
71674
  const label = value2.label.trim();
71497
71675
  if (!label) throw new Error(`skills.sources entry ${index + 1} has an empty label`);
71498
71676
  const declarationId = value2.id === void 0 ? stableSourceDeclarationId(sourcePath) : requiredSourceId(value2.id, `skills.sources[${index}].id`);
71499
- const relativeDirectory = import_node_path63.default.relative(home, sourcePath);
71677
+ const relativeDirectory = import_node_path64.default.relative(home, sourcePath);
71500
71678
  const inferred = providerKindsForUserDirectory(relativeDirectory);
71501
71679
  const declared = value2.providers === void 0 ? inferred : [
71502
71680
  ...new Set(
@@ -71528,7 +71706,7 @@ function staleCodexDeclaration(relativeDirectory, label, providerKinds) {
71528
71706
  return ownedByCursor || label === "Legacy Cursor-compatible skills";
71529
71707
  }
71530
71708
  function stableSourceDeclarationId(sourcePath) {
71531
- const digest = (0, import_node_crypto43.createHash)("sha256").update("alan-skill-source-v1\0").update(sourcePath.normalize("NFC")).digest("hex").slice(0, 24);
71709
+ const digest = (0, import_node_crypto44.createHash)("sha256").update("alan-skill-source-v1\0").update(sourcePath.normalize("NFC")).digest("hex").slice(0, 24);
71532
71710
  return `source-${digest}`;
71533
71711
  }
71534
71712
  function requiredSourceId(value2, field3) {
@@ -71539,12 +71717,12 @@ function requiredSourceId(value2, field3) {
71539
71717
  }
71540
71718
  function resolveSkillSourcePath(sourcePath, home) {
71541
71719
  const trimmed4 = sourcePath.trim();
71542
- if (trimmed4 === "~") return import_node_path63.default.resolve(home);
71720
+ if (trimmed4 === "~") return import_node_path64.default.resolve(home);
71543
71721
  if (trimmed4.startsWith("~/") || trimmed4.startsWith("~\\")) {
71544
71722
  const components = trimmed4.slice(2).split(/[\\/]+/).filter(Boolean);
71545
- return import_node_path63.default.resolve(import_node_path63.default.join(home, ...components));
71723
+ return import_node_path64.default.resolve(import_node_path64.default.join(home, ...components));
71546
71724
  }
71547
- return import_node_path63.default.isAbsolute(trimmed4) ? import_node_path63.default.resolve(trimmed4) : import_node_path63.default.resolve(home, trimmed4);
71725
+ return import_node_path64.default.isAbsolute(trimmed4) ? import_node_path64.default.resolve(trimmed4) : import_node_path64.default.resolve(home, trimmed4);
71548
71726
  }
71549
71727
  function optionalBoolean(value2, fallback, field3) {
71550
71728
  if (value2 === void 0) return fallback;
@@ -71571,14 +71749,14 @@ async function scanLocalSkills(home, context, cache2, mode = "incremental", mana
71571
71749
  }
71572
71750
 
71573
71751
  // src/capabilities/skills/store.ts
71574
- var import_promises52 = require("fs/promises");
71575
- var import_node_path64 = require("path");
71752
+ var import_promises53 = require("fs/promises");
71753
+ var import_node_path65 = require("path");
71576
71754
 
71577
71755
  // ../shared/src/node/alan-skill-identity.ts
71578
- var import_node_crypto44 = require("crypto");
71756
+ var import_node_crypto45 = require("crypto");
71579
71757
  var ALAN_SKILL_NAMESPACE = "ec71d99b-d207-4ca2-a9eb-3a7bed4a73fd";
71580
71758
  function uuidV5(name, namespace) {
71581
- const bytes = (0, import_node_crypto44.createHash)("sha1").update(Buffer.from(namespace.replaceAll("-", ""), "hex")).update(name, "utf8").digest().subarray(0, 16);
71759
+ const bytes = (0, import_node_crypto45.createHash)("sha1").update(Buffer.from(namespace.replaceAll("-", ""), "hex")).update(name, "utf8").digest().subarray(0, 16);
71582
71760
  bytes[6] = bytes[6] & 15 | 80;
71583
71761
  bytes[8] = bytes[8] & 63 | 128;
71584
71762
  const hex3 = bytes.toString("hex");
@@ -71595,21 +71773,21 @@ function alanSkillVersionId(slug, contentHash) {
71595
71773
  init_runtime_v2();
71596
71774
  init_zod();
71597
71775
  function skillsLayout(stateDir, home) {
71598
- const root = (0, import_node_path64.join)(stateDir, "skills");
71776
+ const root = (0, import_node_path65.join)(stateDir, "skills");
71599
71777
  return {
71600
71778
  root,
71601
- installedFile: (0, import_node_path64.join)(root, "installed.json"),
71602
- retiredFile: (0, import_node_path64.join)(root, "retired.json"),
71603
- localFile: (0, import_node_path64.join)(root, "local.json"),
71604
- versionsDir: (0, import_node_path64.join)(root, "versions"),
71605
- tmpDir: (0, import_node_path64.join)(root, "tmp"),
71606
- pluginDir: (0, import_node_path64.join)(root, "alan-plugin"),
71607
- pluginSkillsDir: (0, import_node_path64.join)(root, "alan-plugin", "skills"),
71608
- nativeDir: home === void 0 || home === "" ? null : (0, import_node_path64.join)(home, ".agents", "skills")
71779
+ installedFile: (0, import_node_path65.join)(root, "installed.json"),
71780
+ retiredFile: (0, import_node_path65.join)(root, "retired.json"),
71781
+ localFile: (0, import_node_path65.join)(root, "local.json"),
71782
+ versionsDir: (0, import_node_path65.join)(root, "versions"),
71783
+ tmpDir: (0, import_node_path65.join)(root, "tmp"),
71784
+ pluginDir: (0, import_node_path65.join)(root, "alan-plugin"),
71785
+ pluginSkillsDir: (0, import_node_path65.join)(root, "alan-plugin", "skills"),
71786
+ nativeDir: home === void 0 || home === "" ? null : (0, import_node_path65.join)(home, ".agents", "skills")
71609
71787
  };
71610
71788
  }
71611
71789
  function packageDirectory(layout, versionId) {
71612
- return (0, import_node_path64.join)(layout.versionsDir, versionId);
71790
+ return (0, import_node_path65.join)(layout.versionsDir, versionId);
71613
71791
  }
71614
71792
  var installedFileSchema = external_exports.object({ skills: external_exports.array(desiredMachineSkillSchema) });
71615
71793
  async function readInstalledSkills(layout) {
@@ -71642,7 +71820,7 @@ function writeLocalSkills(layout, file2) {
71642
71820
  async function isLocalSkillCurrent(entry, contentHash, ignoredPaths) {
71643
71821
  if (entry.contentHash !== contentHash) return false;
71644
71822
  try {
71645
- if (await (0, import_promises52.realpath)(entry.path) !== entry.path) return false;
71823
+ if (await (0, import_promises53.realpath)(entry.path) !== entry.path) return false;
71646
71824
  const inspected = await inspectSkillPackage(entry.path, { expectedName: null, ignoredPaths });
71647
71825
  return inspected.contentHash === contentHash;
71648
71826
  } catch {
@@ -71657,7 +71835,7 @@ async function resolveLocalSkill(local, invocation) {
71657
71835
  }
71658
71836
  async function hasSkillFile(directory) {
71659
71837
  try {
71660
- return (await (0, import_promises52.stat)((0, import_node_path64.join)(directory, "SKILL.md"))).isFile();
71838
+ return (await (0, import_promises53.stat)((0, import_node_path65.join)(directory, "SKILL.md"))).isFile();
71661
71839
  } catch {
71662
71840
  return false;
71663
71841
  }
@@ -71675,7 +71853,7 @@ async function isIntact(layout, skill) {
71675
71853
  async function resolveNativeBuiltIn(layout, invocation, baked) {
71676
71854
  const slug = invocation.displayName;
71677
71855
  if (layout.nativeDir === null || invocation.skillId !== alanSkillId(slug)) return null;
71678
- const directory = (0, import_node_path64.join)(layout.nativeDir, slug);
71856
+ const directory = (0, import_node_path65.join)(layout.nativeDir, slug);
71679
71857
  try {
71680
71858
  const inspected = await inspectSkillPackage(directory, { expectedName: slug });
71681
71859
  if (baked === "exact" && alanSkillVersionId(slug, inspected.contentHash) !== invocation.versionId)
@@ -71714,8 +71892,8 @@ async function resolveSkillInvocations(layout, invocations, baked = "any") {
71714
71892
  async function nativeCandidates(layout) {
71715
71893
  const nativeDir = layout.nativeDir;
71716
71894
  if (nativeDir === null) return [];
71717
- const entries = await (0, import_promises52.readdir)(nativeDir, { withFileTypes: true }).catch(() => []);
71718
- return entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => ({ directory: (0, import_node_path64.join)(nativeDir, entry.name) }));
71895
+ const entries = await (0, import_promises53.readdir)(nativeDir, { withFileTypes: true }).catch(() => []);
71896
+ return entries.filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => ({ directory: (0, import_node_path65.join)(nativeDir, entry.name) }));
71719
71897
  }
71720
71898
  async function availableSkillIndex(layout, sources = { synced: true, native: true }) {
71721
71899
  const found = /* @__PURE__ */ new Map();
@@ -71804,7 +71982,7 @@ async function readLocalSkillFile(layout, ref) {
71804
71982
  mediaType: file2.path.toLowerCase().endsWith(".md") ? "text/markdown; charset=utf-8" : "text/plain; charset=utf-8"
71805
71983
  };
71806
71984
  }
71807
- const mediaType = RASTER_MEDIA_TYPES.get(import_node_path65.default.extname(file2.path).toLowerCase());
71985
+ const mediaType = RASTER_MEDIA_TYPES.get(import_node_path66.default.extname(file2.path).toLowerCase());
71808
71986
  if (file2.preview === "image" && mediaType !== void 0) {
71809
71987
  return bytes.byteLength <= MAX_INLINE_IMAGE_BYTES ? { file: file2, encoding: "base64", content: bytes.toString("base64"), mediaType } : { file: file2, encoding: "metadata", mediaType };
71810
71988
  }
@@ -71812,7 +71990,7 @@ async function readLocalSkillFile(layout, ref) {
71812
71990
  }
71813
71991
  async function isDirectory4(candidate) {
71814
71992
  try {
71815
- return (await (0, import_promises53.stat)(candidate)).isDirectory();
71993
+ return (await (0, import_promises54.stat)(candidate)).isDirectory();
71816
71994
  } catch {
71817
71995
  return false;
71818
71996
  }
@@ -71825,21 +72003,21 @@ async function addSkillSource(home, input2) {
71825
72003
  return { state: "invalid", diagnostic: `${sourcePath} is not a folder` };
71826
72004
  }
71827
72005
  const configPath = skillSourceConfigPath(home);
71828
- await (0, import_promises53.mkdir)(import_node_path65.default.dirname(configPath), { recursive: true, mode: 448 });
71829
- await (0, import_promises53.writeFile)(configPath, DEFAULT_SKILL_CONFIG, { flag: "wx", mode: 384 }).catch(
72006
+ await (0, import_promises54.mkdir)(import_node_path66.default.dirname(configPath), { recursive: true, mode: 448 });
72007
+ await (0, import_promises54.writeFile)(configPath, DEFAULT_SKILL_CONFIG, { flag: "wx", mode: 384 }).catch(
71830
72008
  (error62) => {
71831
72009
  if (errnoCode(error62) !== "EEXIST") throw error62;
71832
72010
  }
71833
72011
  );
71834
72012
  const loaded = await readSkillSourceConfig(home);
71835
72013
  if (loaded.kind === "invalid_config") return { state: "invalid", diagnostic: loaded.diagnostic };
71836
- const canonical = await (0, import_promises53.realpath)(sourcePath).catch(() => sourcePath);
72014
+ const canonical = await (0, import_promises54.realpath)(sourcePath).catch(() => sourcePath);
71837
72015
  for (const source of loaded.config.sources) {
71838
- if (await (0, import_promises53.realpath)(source.path).catch(() => source.path) === canonical) {
72016
+ if (await (0, import_promises54.realpath)(source.path).catch(() => source.path) === canonical) {
71839
72017
  return { state: "already_present", label: source.label };
71840
72018
  }
71841
72019
  }
71842
- const current = await (0, import_promises53.readFile)(configPath, "utf8");
72020
+ const current = await (0, import_promises54.readFile)(configPath, "utf8");
71843
72021
  const block2 = [
71844
72022
  "",
71845
72023
  "[[skills.sources]]",
@@ -71847,7 +72025,7 @@ async function addSkillSource(home, input2) {
71847
72025
  `label = ${JSON.stringify(label)}`,
71848
72026
  ""
71849
72027
  ].join("\n");
71850
- await (0, import_promises53.writeFile)(configPath, `${current.replace(/\n*$/, "\n")}${block2}`, { mode: 384 });
72028
+ await (0, import_promises54.writeFile)(configPath, `${current.replace(/\n*$/, "\n")}${block2}`, { mode: 384 });
71851
72029
  const reloaded = await readSkillSourceConfig(home);
71852
72030
  if (reloaded.kind === "invalid_config") {
71853
72031
  return { state: "invalid", diagnostic: reloaded.diagnostic };
@@ -71856,13 +72034,13 @@ async function addSkillSource(home, input2) {
71856
72034
  }
71857
72035
 
71858
72036
  // src/capabilities/skills/local-upload.ts
71859
- var import_promises55 = require("fs/promises");
72037
+ var import_promises56 = require("fs/promises");
71860
72038
 
71861
72039
  // ../shared/src/node/skill-bundle.ts
71862
72040
  var import_node_buffer2 = require("buffer");
71863
- var import_node_crypto45 = require("crypto");
71864
- var import_promises54 = require("fs/promises");
71865
- var import_node_path66 = require("path");
72041
+ var import_node_crypto46 = require("crypto");
72042
+ var import_promises55 = require("fs/promises");
72043
+ var import_node_path67 = require("path");
71866
72044
  var import_node_stream = require("stream");
71867
72045
  var import_node_zlib = require("zlib");
71868
72046
  var import_tar_stream = __toESM(require_tar_stream(), 1);
@@ -71872,7 +72050,7 @@ async function createSkillBundle(packageRoot, options = {}) {
71872
72050
  const archive = (0, import_tar_stream.pack)();
71873
72051
  const tarPromise = collectStream(archive);
71874
72052
  for (const file2 of before.files) {
71875
- const bytes2 = await (0, import_promises54.readFile)((0, import_node_path66.join)(packageRoot, ...file2.path.split("/")));
72053
+ const bytes2 = await (0, import_promises55.readFile)((0, import_node_path67.join)(packageRoot, ...file2.path.split("/")));
71876
72054
  await addArchiveEntry(
71877
72055
  archive,
71878
72056
  {
@@ -71908,7 +72086,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
71908
72086
  throw new Error("Skill archive hash does not match the expected immutable Version");
71909
72087
  }
71910
72088
  const tarBytes = await decompressBounded(archiveBytes);
71911
- await (0, import_promises54.mkdir)(destination, { recursive: false, mode: 448 });
72089
+ await (0, import_promises55.mkdir)(destination, { recursive: false, mode: 448 });
71912
72090
  try {
71913
72091
  await extractTar(tarBytes, destination);
71914
72092
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -71916,7 +72094,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
71916
72094
  throw new Error("Extracted Skill package hash does not match the expected immutable Version");
71917
72095
  }
71918
72096
  } catch (error62) {
71919
- await (0, import_promises54.rm)(destination, { recursive: true, force: true });
72097
+ await (0, import_promises55.rm)(destination, { recursive: true, force: true });
71920
72098
  throw error62;
71921
72099
  }
71922
72100
  }
@@ -71993,19 +72171,19 @@ async function extractEntry(header, stream, destination, limits) {
71993
72171
  if (bytes.byteLength !== declaredSize) {
71994
72172
  throw new Error(`Skill archive file size is invalid: ${path4}`);
71995
72173
  }
71996
- const outputPath = (0, import_node_path66.join)(destination, ...path4.split("/"));
71997
- await (0, import_promises54.mkdir)((0, import_node_path66.dirname)(outputPath), { recursive: true, mode: 448 });
71998
- await (0, import_promises54.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
72174
+ const outputPath = (0, import_node_path67.join)(destination, ...path4.split("/"));
72175
+ await (0, import_promises55.mkdir)((0, import_node_path67.dirname)(outputPath), { recursive: true, mode: 448 });
72176
+ await (0, import_promises55.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
71999
72177
  }
72000
72178
  function requireSafeArchivePath(value2) {
72001
72179
  const normalized2 = value2.replaceAll("\\", "/").normalize("NFC");
72002
- if (!normalized2 || normalized2.startsWith("/") || normalized2.includes("\0") || import_node_path66.posix.normalize(normalized2) !== normalized2 || normalized2 === ".." || normalized2.startsWith("../")) {
72180
+ if (!normalized2 || normalized2.startsWith("/") || normalized2.includes("\0") || import_node_path67.posix.normalize(normalized2) !== normalized2 || normalized2 === ".." || normalized2.startsWith("../")) {
72003
72181
  throw new Error(`Skill archive contains an unsafe path: ${value2}`);
72004
72182
  }
72005
72183
  return normalized2;
72006
72184
  }
72007
72185
  function sha2563(bytes) {
72008
- return `sha256:${(0, import_node_crypto45.createHash)("sha256").update(bytes).digest("hex")}`;
72186
+ return `sha256:${(0, import_node_crypto46.createHash)("sha256").update(bytes).digest("hex")}`;
72009
72187
  }
72010
72188
 
72011
72189
  // src/capabilities/skills/local-upload.ts
@@ -72021,8 +72199,8 @@ async function publishLocalSkill(options) {
72021
72199
  if (Date.parse(request2.uploadGrant.expiresAt) <= (options.now ?? Date.now())) {
72022
72200
  throw new RuntimeFault("invalid_file", "Skill upload grant expired");
72023
72201
  }
72024
- const folder = await (0, import_promises55.lstat)(entry.path);
72025
- if (!folder.isDirectory() || await (0, import_promises55.realpath)(entry.path) !== entry.path) {
72202
+ const folder = await (0, import_promises56.lstat)(entry.path);
72203
+ if (!folder.isDirectory() || await (0, import_promises56.realpath)(entry.path) !== entry.path) {
72026
72204
  throw new RuntimeFault("invalid_file", "Skill folder moved since the last scan");
72027
72205
  }
72028
72206
  const bundle = await createSkillBundle(entry.path, {
@@ -72049,10 +72227,10 @@ async function publishLocalSkill(options) {
72049
72227
  }
72050
72228
 
72051
72229
  // src/capabilities/skills/native-index.ts
72052
- var import_node_crypto46 = require("crypto");
72230
+ var import_node_crypto47 = require("crypto");
72053
72231
  var import_node_fs28 = require("fs");
72054
- var import_promises56 = require("fs/promises");
72055
- var import_node_path67 = require("path");
72232
+ var import_promises57 = require("fs/promises");
72233
+ var import_node_path68 = require("path");
72056
72234
  var ALAN_SKILLS_PLUGIN_NAME = "alan";
72057
72235
  var PLUGIN_MANIFEST = `${JSON.stringify(
72058
72236
  {
@@ -72065,32 +72243,32 @@ var PLUGIN_MANIFEST = `${JSON.stringify(
72065
72243
  `;
72066
72244
  async function entryKind2(path4) {
72067
72245
  try {
72068
- return (await (0, import_promises56.lstat)(path4)).isSymbolicLink() ? "link" : "other";
72246
+ return (await (0, import_promises57.lstat)(path4)).isSymbolicLink() ? "link" : "other";
72069
72247
  } catch (error62) {
72070
72248
  if (errnoCode(error62) === "ENOENT") return "missing";
72071
72249
  throw error62;
72072
72250
  }
72073
72251
  }
72074
72252
  async function linkTarget(path4) {
72075
- return (0, import_promises56.readlink)(path4).catch(() => null);
72253
+ return (0, import_promises57.readlink)(path4).catch(() => null);
72076
72254
  }
72077
72255
  async function removeLink2(path4) {
72078
72256
  try {
72079
- await (0, import_promises56.unlink)(path4);
72257
+ await (0, import_promises57.unlink)(path4);
72080
72258
  } catch (error62) {
72081
72259
  const code = errnoCode(error62);
72082
72260
  if (code === "ENOENT") return;
72083
72261
  if (code !== "EPERM" && code !== "EISDIR") throw error62;
72084
- await (0, import_promises56.rmdir)(path4);
72262
+ await (0, import_promises57.rmdir)(path4);
72085
72263
  }
72086
72264
  }
72087
72265
  async function placeLink(plan2, platform3) {
72088
72266
  if (await linkTarget(plan2.path) === plan2.target) return false;
72089
- const staged = (0, import_node_path67.join)((0, import_node_path67.dirname)(plan2.path), `.${(0, import_node_path67.basename)(plan2.path)}.${(0, import_node_crypto46.randomUUID)()}.tmp`);
72090
- await (0, import_promises56.symlink)(plan2.target, staged, platform3 === "win32" ? "junction" : "dir");
72267
+ const staged = (0, import_node_path68.join)((0, import_node_path68.dirname)(plan2.path), `.${(0, import_node_path68.basename)(plan2.path)}.${(0, import_node_crypto47.randomUUID)()}.tmp`);
72268
+ await (0, import_promises57.symlink)(plan2.target, staged, platform3 === "win32" ? "junction" : "dir");
72091
72269
  try {
72092
72270
  if (platform3 === "win32") await removeLink2(plan2.path);
72093
- await (0, import_promises56.rename)(staged, plan2.path);
72271
+ await (0, import_promises57.rename)(staged, plan2.path);
72094
72272
  } catch (error62) {
72095
72273
  await removeLink2(staged).catch(() => void 0);
72096
72274
  throw error62;
@@ -72098,37 +72276,37 @@ async function placeLink(plan2, platform3) {
72098
72276
  return true;
72099
72277
  }
72100
72278
  function versionTarget(layout, versionId, platform3) {
72101
- const absolute = (0, import_node_path67.join)(layout.versionsDir, versionId);
72102
- return platform3 === "win32" ? absolute : (0, import_node_path67.relative)(layout.pluginSkillsDir, absolute);
72279
+ const absolute = (0, import_node_path68.join)(layout.versionsDir, versionId);
72280
+ return platform3 === "win32" ? absolute : (0, import_node_path68.relative)(layout.pluginSkillsDir, absolute);
72103
72281
  }
72104
72282
  async function writeManifest(layout) {
72105
- const manifest = (0, import_node_path67.join)(layout.pluginDir, ".claude-plugin", "plugin.json");
72106
- if (await (0, import_promises56.readFile)(manifest, "utf8").catch(() => null) === PLUGIN_MANIFEST) return;
72107
- await (0, import_promises56.mkdir)((0, import_node_path67.dirname)(manifest), { recursive: true, mode: 448 });
72108
- const staged = `${manifest}.${(0, import_node_crypto46.randomUUID)()}.tmp`;
72109
- await (0, import_promises56.writeFile)(staged, PLUGIN_MANIFEST, { mode: 384 });
72110
- await (0, import_promises56.rename)(staged, manifest);
72283
+ const manifest = (0, import_node_path68.join)(layout.pluginDir, ".claude-plugin", "plugin.json");
72284
+ if (await (0, import_promises57.readFile)(manifest, "utf8").catch(() => null) === PLUGIN_MANIFEST) return;
72285
+ await (0, import_promises57.mkdir)((0, import_node_path68.dirname)(manifest), { recursive: true, mode: 448 });
72286
+ const staged = `${manifest}.${(0, import_node_crypto47.randomUUID)()}.tmp`;
72287
+ await (0, import_promises57.writeFile)(staged, PLUGIN_MANIFEST, { mode: 384 });
72288
+ await (0, import_promises57.rename)(staged, manifest);
72111
72289
  }
72112
72290
  async function reconcilePluginSkills(layout, installed, platform3) {
72113
- await (0, import_promises56.mkdir)(layout.pluginSkillsDir, { recursive: true, mode: 448 });
72291
+ await (0, import_promises57.mkdir)(layout.pluginSkillsDir, { recursive: true, mode: 448 });
72114
72292
  const wanted = new Map(installed.map((skill) => [skill.slug, skill]));
72115
72293
  let linked = 0;
72116
72294
  for (const skill of installed) {
72117
72295
  const plan2 = {
72118
- path: (0, import_node_path67.join)(layout.pluginSkillsDir, skill.slug),
72296
+ path: (0, import_node_path68.join)(layout.pluginSkillsDir, skill.slug),
72119
72297
  target: versionTarget(layout, skill.versionId, platform3)
72120
72298
  };
72121
72299
  if (await entryKind2(plan2.path) === "other") {
72122
- await (0, import_promises56.rm)(plan2.path, { recursive: true, force: true });
72300
+ await (0, import_promises57.rm)(plan2.path, { recursive: true, force: true });
72123
72301
  }
72124
72302
  if (await placeLink(plan2, platform3)) linked += 1;
72125
72303
  }
72126
72304
  let unlinked = 0;
72127
- for (const name of await (0, import_promises56.readdir)(layout.pluginSkillsDir)) {
72305
+ for (const name of await (0, import_promises57.readdir)(layout.pluginSkillsDir)) {
72128
72306
  if (wanted.has(name)) continue;
72129
- const path4 = (0, import_node_path67.join)(layout.pluginSkillsDir, name);
72307
+ const path4 = (0, import_node_path68.join)(layout.pluginSkillsDir, name);
72130
72308
  if (await entryKind2(path4) === "link") await removeLink2(path4);
72131
- else await (0, import_promises56.rm)(path4, { recursive: true, force: true });
72309
+ else await (0, import_promises57.rm)(path4, { recursive: true, force: true });
72132
72310
  unlinked += 1;
72133
72311
  }
72134
72312
  return { linked, unlinked };
@@ -72136,17 +72314,17 @@ async function reconcilePluginSkills(layout, installed, platform3) {
72136
72314
  async function isOwnCodexLink(layout, path4) {
72137
72315
  const target = await linkTarget(path4);
72138
72316
  if (target === null) return false;
72139
- const absolute = (0, import_node_path67.isAbsolute)(target) ? target : (0, import_node_path67.resolve)((0, import_node_path67.dirname)(path4), target);
72317
+ const absolute = (0, import_node_path68.isAbsolute)(target) ? target : (0, import_node_path68.resolve)((0, import_node_path68.dirname)(path4), target);
72140
72318
  return isWithinDirectory2(layout.pluginSkillsDir, absolute);
72141
72319
  }
72142
72320
  async function isForeignPackage(layout, path4) {
72143
- const resolved = await (0, import_promises56.realpath)(path4).catch(() => null);
72321
+ const resolved = await (0, import_promises57.realpath)(path4).catch(() => null);
72144
72322
  if (resolved === null) return false;
72145
- const root = await (0, import_promises56.realpath)(layout.root).catch(() => layout.root);
72323
+ const root = await (0, import_promises57.realpath)(layout.root).catch(() => layout.root);
72146
72324
  return !isWithinDirectory2(root, resolved);
72147
72325
  }
72148
72326
  async function codexSlot(layout, path4, slug) {
72149
- const baked = layout.nativeDir !== null && await isForeignPackage(layout, (0, import_node_path67.join)(layout.nativeDir, slug));
72327
+ const baked = layout.nativeDir !== null && await isForeignPackage(layout, (0, import_node_path68.join)(layout.nativeDir, slug));
72150
72328
  const kind = await entryKind2(path4);
72151
72329
  if (kind === "other") return "taken";
72152
72330
  const ours = kind === "link" && await isOwnCodexLink(layout, path4);
@@ -72159,8 +72337,8 @@ async function codexSlot(layout, path4, slug) {
72159
72337
  }
72160
72338
  async function unlinkStaleCodexEntries(layout, codexSkillsDir2, wanted) {
72161
72339
  let unlinked = 0;
72162
- for (const name of await (0, import_promises56.readdir)(codexSkillsDir2)) {
72163
- const path4 = (0, import_node_path67.join)(codexSkillsDir2, name);
72340
+ for (const name of await (0, import_promises57.readdir)(codexSkillsDir2)) {
72341
+ const path4 = (0, import_node_path68.join)(codexSkillsDir2, name);
72164
72342
  if (wanted.has(name) && !name.endsWith(".tmp")) continue;
72165
72343
  if (await entryKind2(path4) !== "link" || !await isOwnCodexLink(layout, path4)) continue;
72166
72344
  await removeLink2(path4);
@@ -72169,15 +72347,15 @@ async function unlinkStaleCodexEntries(layout, codexSkillsDir2, wanted) {
72169
72347
  return unlinked;
72170
72348
  }
72171
72349
  async function reconcileCodexSkills(layout, installed, codexSkillsDir2, platform3) {
72172
- await (0, import_promises56.mkdir)(codexSkillsDir2, { recursive: true, mode: 448 });
72350
+ await (0, import_promises57.mkdir)(codexSkillsDir2, { recursive: true, mode: 448 });
72173
72351
  const report2 = { linked: 0, unlinked: 0, skipped: [] };
72174
72352
  for (const skill of installed) {
72175
- const path4 = (0, import_node_path67.join)(codexSkillsDir2, skill.slug);
72353
+ const path4 = (0, import_node_path68.join)(codexSkillsDir2, skill.slug);
72176
72354
  if (await codexSlot(layout, path4, skill.slug) === "taken") {
72177
72355
  report2.skipped.push(skill.slug);
72178
72356
  continue;
72179
72357
  }
72180
- const target = (0, import_node_path67.join)(layout.pluginSkillsDir, skill.slug);
72358
+ const target = (0, import_node_path68.join)(layout.pluginSkillsDir, skill.slug);
72181
72359
  if (await placeLink({ path: path4, target }, platform3)) report2.linked += 1;
72182
72360
  }
72183
72361
  const wanted = new Set(installed.map((skill) => skill.slug));
@@ -72201,41 +72379,41 @@ async function reconcileNativeIndex(layout, installed, options) {
72201
72379
  };
72202
72380
  }
72203
72381
  function installedSkillFolders(layout) {
72204
- return (0, import_node_fs28.existsSync)((0, import_node_path67.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
72382
+ return (0, import_node_fs28.existsSync)((0, import_node_path68.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
72205
72383
  }
72206
72384
 
72207
72385
  // src/capabilities/skills/sync.ts
72208
- var import_node_crypto47 = require("crypto");
72209
- var import_promises57 = require("fs/promises");
72210
- var import_node_path68 = require("path");
72386
+ var import_node_crypto48 = require("crypto");
72387
+ var import_promises58 = require("fs/promises");
72388
+ var import_node_path69 = require("path");
72211
72389
  init_zod();
72212
72390
  var SKILL_PREPARE_WAIT_MS = 15e3;
72213
72391
  var FIRST_INSTALL_WAIT_MS = 5e3;
72214
72392
  var RETIRED_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
72215
72393
  async function makeFilesReadOnly(directory, platform3) {
72216
72394
  if (platform3 === "win32") return;
72217
- for (const entry of await (0, import_promises57.readdir)(directory, { withFileTypes: true })) {
72218
- const path4 = (0, import_node_path68.join)(directory, entry.name);
72395
+ for (const entry of await (0, import_promises58.readdir)(directory, { withFileTypes: true })) {
72396
+ const path4 = (0, import_node_path69.join)(directory, entry.name);
72219
72397
  if (entry.isDirectory()) await makeFilesReadOnly(path4, platform3);
72220
72398
  else if (entry.isFile()) {
72221
- const executable = ((await (0, import_promises57.lstat)(path4)).mode & 64) !== 0;
72222
- await (0, import_promises57.chmod)(path4, executable ? 365 : 292);
72399
+ const executable = ((await (0, import_promises58.lstat)(path4)).mode & 64) !== 0;
72400
+ await (0, import_promises58.chmod)(path4, executable ? 365 : 292);
72223
72401
  }
72224
72402
  }
72225
72403
  }
72226
72404
  async function install(env, skill, download, signal) {
72227
72405
  const { layout, source, platform: platform3 } = env;
72228
72406
  const bytes = await source.download(download.url, signal);
72229
- await (0, import_promises57.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
72230
- const staging = (0, import_node_path68.join)(layout.tmpDir, (0, import_node_crypto47.randomUUID)());
72407
+ await (0, import_promises58.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
72408
+ const staging = (0, import_node_path69.join)(layout.tmpDir, (0, import_node_crypto48.randomUUID)());
72231
72409
  await extractSkillBundle(Buffer.from(bytes), staging, {
72232
72410
  expectedArchiveHash: download.archiveHash,
72233
72411
  expectedContentHash: skill.contentHash
72234
72412
  });
72235
72413
  const target = packageDirectory(layout, skill.versionId);
72236
- await (0, import_promises57.mkdir)(layout.versionsDir, { recursive: true, mode: 448 });
72237
- await (0, import_promises57.rm)(target, { recursive: true, force: true });
72238
- await (0, import_promises57.rename)(staging, target);
72414
+ await (0, import_promises58.mkdir)(layout.versionsDir, { recursive: true, mode: 448 });
72415
+ await (0, import_promises58.rm)(target, { recursive: true, force: true });
72416
+ await (0, import_promises58.rename)(staging, target);
72239
72417
  await makeFilesReadOnly(target, platform3);
72240
72418
  }
72241
72419
  var retiredFileSchema = external_exports.record(external_exports.string(), external_exports.number());
@@ -72247,14 +72425,14 @@ async function sweep(env, keep) {
72247
72425
  const now = env.now();
72248
72426
  const stillRetired = {};
72249
72427
  const expired = [];
72250
- for (const name of await (0, import_promises57.readdir)(layout.versionsDir).catch(() => [])) {
72428
+ for (const name of await (0, import_promises58.readdir)(layout.versionsDir).catch(() => [])) {
72251
72429
  if (kept.has(name)) continue;
72252
72430
  const since = retired[name] ?? now;
72253
72431
  if (now - since >= RETIRED_VERSION_RETENTION_MS) expired.push(name);
72254
72432
  else stillRetired[name] = since;
72255
72433
  }
72256
72434
  const results = await Promise.allSettled(
72257
- expired.map((name) => (0, import_promises57.rm)((0, import_node_path68.join)(layout.versionsDir, name), { recursive: true, force: true }))
72435
+ expired.map((name) => (0, import_promises58.rm)((0, import_node_path69.join)(layout.versionsDir, name), { recursive: true, force: true }))
72258
72436
  );
72259
72437
  results.forEach((result, index) => {
72260
72438
  const name = expired[index];
@@ -72263,7 +72441,7 @@ async function sweep(env, keep) {
72263
72441
  if (JSON.stringify(stillRetired) !== JSON.stringify(retired)) {
72264
72442
  await writeJsonFileAtomic(layout.retiredFile, stillRetired);
72265
72443
  }
72266
- await (0, import_promises57.rm)(layout.tmpDir, { recursive: true, force: true });
72444
+ await (0, import_promises58.rm)(layout.tmpDir, { recursive: true, force: true });
72267
72445
  return results.filter((result) => result.status === "fulfilled").length;
72268
72446
  }
72269
72447
  var INSTALL_CONCURRENCY = 4;
@@ -72605,15 +72783,15 @@ function openMachineSkills(options) {
72605
72783
  }
72606
72784
 
72607
72785
  // src/capabilities/workspace/index.ts
72608
- var import_node_path73 = require("path");
72786
+ var import_node_path74 = require("path");
72609
72787
  init_runtime_v2();
72610
72788
 
72611
72789
  // src/capabilities/workspace/approved-paths.ts
72612
- var import_promises58 = require("fs/promises");
72790
+ var import_promises59 = require("fs/promises");
72613
72791
  init_zod();
72614
72792
 
72615
72793
  // src/capabilities/workspace/paths.ts
72616
- var import_node_path69 = require("path");
72794
+ var import_node_path70 = require("path");
72617
72795
  function stripWin32Namespace(path4) {
72618
72796
  if (/^\\\\\?\\UNC\\/i.test(path4)) return `\\\\${path4.slice(8)}`;
72619
72797
  if (path4.startsWith("\\\\?\\")) return path4.slice(4);
@@ -72621,15 +72799,15 @@ function stripWin32Namespace(path4) {
72621
72799
  }
72622
72800
  function comparablePath(path4, platform3) {
72623
72801
  if (platform3 === "win32") {
72624
- const normalized3 = import_node_path69.win32.normalize(stripWin32Namespace(path4).replaceAll("/", "\\"));
72802
+ const normalized3 = import_node_path70.win32.normalize(stripWin32Namespace(path4).replaceAll("/", "\\"));
72625
72803
  const trimmed4 = normalized3.length > 3 || !/^[a-z]:\\$/i.test(normalized3) ? normalized3.replace(/\\+$/, "") : normalized3;
72626
72804
  return trimmed4.toLowerCase();
72627
72805
  }
72628
- const normalized2 = import_node_path69.posix.normalize(path4);
72806
+ const normalized2 = import_node_path70.posix.normalize(path4);
72629
72807
  return normalized2.length > 1 ? normalized2.replace(/\/+$/, "") : normalized2;
72630
72808
  }
72631
72809
  function isAbsoluteFor(path4, platform3) {
72632
- return platform3 === "win32" ? import_node_path69.win32.isAbsolute(path4) : import_node_path69.posix.isAbsolute(path4);
72810
+ return platform3 === "win32" ? import_node_path70.win32.isAbsolute(path4) : import_node_path70.posix.isAbsolute(path4);
72633
72811
  }
72634
72812
  function isWithin(root, candidate, platform3) {
72635
72813
  const separator = platform3 === "win32" ? "\\" : "/";
@@ -72647,7 +72825,7 @@ var storeSchema = external_exports.object({
72647
72825
  });
72648
72826
  async function realpathOrNull(path4) {
72649
72827
  try {
72650
- return await (0, import_promises58.realpath)(path4);
72828
+ return await (0, import_promises59.realpath)(path4);
72651
72829
  } catch (error62) {
72652
72830
  const code = errnoCode(error62);
72653
72831
  if (code === "ENOENT" || code === "ENOTDIR" || code === "EACCES" || code === "EPERM") {
@@ -72706,12 +72884,12 @@ async function openApprovedPaths(options) {
72706
72884
  }
72707
72885
 
72708
72886
  // src/capabilities/workspace/files/read.ts
72709
- var import_promises59 = require("fs/promises");
72887
+ var import_promises60 = require("fs/promises");
72710
72888
  var BINARY_SNIFF_BYTES = 8e3;
72711
72889
  async function readFileValue(path4, maxBytes) {
72712
72890
  let size;
72713
72891
  try {
72714
- const info = await (0, import_promises59.stat)(path4);
72892
+ const info = await (0, import_promises60.stat)(path4);
72715
72893
  if (!info.isFile()) return { kind: "not_file" };
72716
72894
  size = info.size;
72717
72895
  } catch {
@@ -72720,7 +72898,7 @@ async function readFileValue(path4, maxBytes) {
72720
72898
  if (size > maxBytes) return { kind: "too_large", size };
72721
72899
  let handle;
72722
72900
  try {
72723
- handle = await (0, import_promises59.open)(path4, "r");
72901
+ handle = await (0, import_promises60.open)(path4, "r");
72724
72902
  } catch {
72725
72903
  return { kind: "not_file" };
72726
72904
  }
@@ -72742,8 +72920,8 @@ async function readFileValue(path4, maxBytes) {
72742
72920
  }
72743
72921
 
72744
72922
  // src/capabilities/workspace/files/tree.ts
72745
- var import_promises60 = require("fs/promises");
72746
- var import_node_path70 = require("path");
72923
+ var import_promises61 = require("fs/promises");
72924
+ var import_node_path71 = require("path");
72747
72925
  var MAX_TREE_FILES = 2e5;
72748
72926
  var IGNORED_FOLDER_NAMES = /* @__PURE__ */ new Set([
72749
72927
  ".git",
@@ -72784,7 +72962,7 @@ async function gitListing(git, root, dirs, signal) {
72784
72962
  }
72785
72963
  async function entriesOf(path4) {
72786
72964
  try {
72787
- return await (0, import_promises60.readdir)(path4, { withFileTypes: true });
72965
+ return await (0, import_promises61.readdir)(path4, { withFileTypes: true });
72788
72966
  } catch {
72789
72967
  return [];
72790
72968
  }
@@ -72795,7 +72973,7 @@ async function walkFiles(root, signal, limit = MAX_TREE_FILES) {
72795
72973
  while (pending.length > 0 && files.length <= limit) {
72796
72974
  signal.throwIfAborted();
72797
72975
  const dir = pending.pop() ?? "";
72798
- for (const entry of await entriesOf((0, import_node_path70.join)(root, dir))) {
72976
+ for (const entry of await entriesOf((0, import_node_path71.join)(root, dir))) {
72799
72977
  const relative6 = dir === "" ? entry.name : `${dir}/${entry.name}`;
72800
72978
  if (!entry.isDirectory()) files.push(relative6);
72801
72979
  else if (!IGNORED_FOLDER_NAMES.has(entry.name)) pending.push(relative6);
@@ -72848,8 +73026,8 @@ function foldersOf(files) {
72848
73026
 
72849
73027
  // src/capabilities/workspace/files/watch.ts
72850
73028
  var import_node_fs29 = require("fs");
72851
- var import_promises61 = require("fs/promises");
72852
- var import_node_path71 = require("path");
73029
+ var import_promises62 = require("fs/promises");
73030
+ var import_node_path72 = require("path");
72853
73031
  init_runtime_v2();
72854
73032
  var WATCH_DEBOUNCE_MS = 250;
72855
73033
  var WATCH_MAX_WAIT_MS = 1e3;
@@ -72934,7 +73112,7 @@ var RootWatch = class {
72934
73112
  const { watch } = this.options;
72935
73113
  try {
72936
73114
  const watcher = watch(
72937
- folder === "" ? this.root : (0, import_node_path71.join)(this.root, folder),
73115
+ folder === "" ? this.root : (0, import_node_path72.join)(this.root, folder),
72938
73116
  { persistent: false },
72939
73117
  (type, name) => this.onEvent(folder, type, name === null ? null : String(name))
72940
73118
  );
@@ -72961,7 +73139,7 @@ var RootWatch = class {
72961
73139
  }
72962
73140
  onEvent(folder, type, name) {
72963
73141
  if (this.stopped) return;
72964
- if (name !== null && (0, import_node_path71.isAbsolute)(name)) {
73142
+ if (name !== null && (0, import_node_path72.isAbsolute)(name)) {
72965
73143
  this.dropFolder(folder);
72966
73144
  void this.settleDeadFolder(folder).catch((error62) => {
72967
73145
  this.options.log.warn("workspace.watch_reconcile_failed", { root: this.root, error: error62 });
@@ -73021,7 +73199,7 @@ var RootWatch = class {
73021
73199
  }
73022
73200
  async kindOf(relative6) {
73023
73201
  try {
73024
- return (await (0, import_promises61.lstat)((0, import_node_path71.join)(this.root, relative6))).isDirectory() ? "folder" : "file";
73202
+ return (await (0, import_promises62.lstat)((0, import_node_path72.join)(this.root, relative6))).isDirectory() ? "folder" : "file";
73025
73203
  } catch (error62) {
73026
73204
  const code = errnoCode(error62);
73027
73205
  return code === "ENOENT" || code === "ENOTDIR" ? "gone" : "unreadable";
@@ -73075,7 +73253,7 @@ var RootWatch = class {
73075
73253
  if (!this.watchFolder(folder)) continue;
73076
73254
  let entries;
73077
73255
  try {
73078
- entries = await (0, import_promises61.readdir)((0, import_node_path71.join)(this.root, folder), { withFileTypes: true });
73256
+ entries = await (0, import_promises62.readdir)((0, import_node_path72.join)(this.root, folder), { withFileTypes: true });
73079
73257
  } catch {
73080
73258
  continue;
73081
73259
  }
@@ -73266,9 +73444,9 @@ function openWorkspaceFiles(options) {
73266
73444
  }
73267
73445
 
73268
73446
  // src/capabilities/workspace/locks.ts
73269
- var import_node_crypto48 = require("crypto");
73270
- var import_promises62 = require("fs/promises");
73271
- var import_node_path72 = require("path");
73447
+ var import_node_crypto49 = require("crypto");
73448
+ var import_promises63 = require("fs/promises");
73449
+ var import_node_path73 = require("path");
73272
73450
  init_zod();
73273
73451
  var LOCK_FORMAT = 1;
73274
73452
  var EXCLUSIVE_FILE = "exclusive.json";
@@ -73283,12 +73461,12 @@ var ownerSchema = external_exports.object({
73283
73461
  since: external_exports.number().int().nonnegative()
73284
73462
  });
73285
73463
  function repositoryLockKey(commonDir, platform3) {
73286
- return (0, import_node_crypto48.createHash)("sha256").update(comparablePath(commonDir, platform3)).digest("hex").slice(0, 32);
73464
+ return (0, import_node_crypto49.createHash)("sha256").update(comparablePath(commonDir, platform3)).digest("hex").slice(0, 32);
73287
73465
  }
73288
73466
  async function readOwner2(path4) {
73289
73467
  let text3;
73290
73468
  try {
73291
- text3 = await (0, import_promises62.readFile)(path4, "utf8");
73469
+ text3 = await (0, import_promises63.readFile)(path4, "utf8");
73292
73470
  } catch (error62) {
73293
73471
  if (errnoCode(error62) === "ENOENT") return { kind: "missing" };
73294
73472
  return { kind: "unreadable" };
@@ -73309,7 +73487,7 @@ async function removeIfSame(path4, expected) {
73309
73487
  if (current.kind !== "owner" || current.owner.since !== expected.since) return;
73310
73488
  if (current.owner.pid !== expected.pid || current.owner.holder !== expected.holder) return;
73311
73489
  }
73312
- await (0, import_promises62.unlink)(path4).catch((error62) => {
73490
+ await (0, import_promises63.unlink)(path4).catch((error62) => {
73313
73491
  if (errnoCode(error62) !== "ENOENT") throw error62;
73314
73492
  });
73315
73493
  }
@@ -73334,7 +73512,7 @@ function openRepositoryLocks(options) {
73334
73512
  await removeIfSame(path4, read.owner);
73335
73513
  return null;
73336
73514
  }
73337
- const age = await (0, import_promises62.stat)(path4).then(
73515
+ const age = await (0, import_promises63.stat)(path4).then(
73338
73516
  (info) => clock.now() - info.mtimeMs,
73339
73517
  () => 0
73340
73518
  );
@@ -73348,13 +73526,13 @@ function openRepositoryLocks(options) {
73348
73526
  });
73349
73527
  const folder = async (commonDir) => {
73350
73528
  const key = repositoryLockKey(commonDir, platform3);
73351
- const dir = (0, import_node_path72.join)(options.dir, key);
73352
- await (0, import_promises62.mkdir)(dir, { recursive: true, mode: 448 });
73529
+ const dir = (0, import_node_path73.join)(options.dir, key);
73530
+ await (0, import_promises63.mkdir)(dir, { recursive: true, mode: 448 });
73353
73531
  return { key, dir };
73354
73532
  };
73355
73533
  const createExclusive = async (path4, owner) => {
73356
73534
  try {
73357
- const handle = await (0, import_promises62.open)(path4, "wx", 384);
73535
+ const handle = await (0, import_promises63.open)(path4, "wx", 384);
73358
73536
  try {
73359
73537
  await handle.writeFile(JSON.stringify(owner));
73360
73538
  } finally {
@@ -73367,10 +73545,10 @@ function openRepositoryLocks(options) {
73367
73545
  }
73368
73546
  };
73369
73547
  const liveRun = async (dir) => {
73370
- const entries = await (0, import_promises62.readdir)(dir);
73548
+ const entries = await (0, import_promises63.readdir)(dir);
73371
73549
  for (const entry of entries) {
73372
73550
  if (!entry.startsWith(RUN_FILE_PREFIX)) continue;
73373
- const holder = await heldBy((0, import_node_path72.join)(dir, entry));
73551
+ const holder = await heldBy((0, import_node_path73.join)(dir, entry));
73374
73552
  if (holder !== null) return holder;
73375
73553
  }
73376
73554
  return null;
@@ -73378,7 +73556,7 @@ function openRepositoryLocks(options) {
73378
73556
  return {
73379
73557
  tryExclusive: async (commonDir, operationId) => {
73380
73558
  const { key, dir } = await folder(commonDir);
73381
- const path4 = (0, import_node_path72.join)(dir, EXCLUSIVE_FILE);
73559
+ const path4 = (0, import_node_path73.join)(dir, EXCLUSIVE_FILE);
73382
73560
  const owner = await self(operationId);
73383
73561
  if (!await createExclusive(path4, owner)) {
73384
73562
  const holder = await heldBy(path4);
@@ -73396,11 +73574,11 @@ function openRepositoryLocks(options) {
73396
73574
  },
73397
73575
  tryShared: async (commonDir, runId) => {
73398
73576
  const { key, dir } = await folder(commonDir);
73399
- const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto48.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
73400
- const path4 = (0, import_node_path72.join)(dir, file2);
73577
+ const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto49.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
73578
+ const path4 = (0, import_node_path73.join)(dir, file2);
73401
73579
  const owner = await self(runId);
73402
73580
  await writeJsonFileAtomic(path4, owner);
73403
- const operation = await heldBy((0, import_node_path72.join)(dir, EXCLUSIVE_FILE));
73581
+ const operation = await heldBy((0, import_node_path73.join)(dir, EXCLUSIVE_FILE));
73404
73582
  if (operation !== null) {
73405
73583
  await removeIfSame(path4, owner);
73406
73584
  return { kind: "busy", holder: operation };
@@ -73504,18 +73682,18 @@ async function openWorkspaces(options) {
73504
73682
  const budgetMs = options.budgetMs ?? WORKSPACE_QUERY_BUDGET_MS;
73505
73683
  const lifetime = new AbortController();
73506
73684
  const approved = await openApprovedPaths({
73507
- file: (0, import_node_path73.join)(options.stateDir, "workspaces.json"),
73685
+ file: (0, import_node_path74.join)(options.stateDir, "workspaces.json"),
73508
73686
  log: options.log,
73509
73687
  platform: platform3
73510
73688
  });
73511
73689
  const locks = openRepositoryLocks({
73512
- dir: (0, import_node_path73.join)(options.stateDir, "locks"),
73690
+ dir: (0, import_node_path74.join)(options.stateDir, "locks"),
73513
73691
  clock: options.clock,
73514
73692
  platform: platform3
73515
73693
  });
73516
73694
  const git = createGit({
73517
73695
  env: options.env,
73518
- tmpDir: (0, import_node_path73.join)(options.stateDir, "tmp", "git"),
73696
+ tmpDir: (0, import_node_path74.join)(options.stateDir, "tmp", "git"),
73519
73697
  platform: platform3,
73520
73698
  ...options.gitPath === void 0 ? {} : { gitPath: options.gitPath },
73521
73699
  ...options.localTimeoutMs === void 0 ? {} : { localTimeoutMs: options.localTimeoutMs },
@@ -73802,7 +73980,7 @@ function createProviderDrivers(options) {
73802
73980
  }
73803
73981
 
73804
73982
  // src/holder/engine-records.ts
73805
- var import_node_path74 = require("path");
73983
+ var import_node_path75 = require("path");
73806
73984
  init_process();
73807
73985
  init_zod();
73808
73986
  var ENGINES_FILE = "engines.json";
@@ -73815,7 +73993,7 @@ var engineRecordSchema = external_exports.object({
73815
73993
  });
73816
73994
  var engineRecordsSchema = external_exports.object({ engines: external_exports.array(engineRecordSchema) });
73817
73995
  function engineRecordsPath(sessionDir) {
73818
- return (0, import_node_path74.join)(sessionDir, ENGINES_FILE);
73996
+ return (0, import_node_path75.join)(sessionDir, ENGINES_FILE);
73819
73997
  }
73820
73998
  function recordSpawnedEngines(path4, clock, log) {
73821
73999
  const live = /* @__PURE__ */ new Map();
@@ -73876,11 +74054,11 @@ async function reapLeftoverEngines(path4, options) {
73876
74054
 
73877
74055
  // src/holder/launch-command.ts
73878
74056
  var import_node_fs30 = require("fs");
73879
- var import_node_path75 = require("path");
74057
+ var import_node_path76 = require("path");
73880
74058
  var HOLDER_BUNDLE = "alan-holder.cjs";
73881
74059
  function holderArguments(runtimeArgs, nodeFlags, exists6 = import_node_fs30.existsSync) {
73882
74060
  const bundle = runtimeArgs.at(-1);
73883
- const lean = bundle === void 0 ? void 0 : (0, import_node_path75.join)((0, import_node_path75.dirname)(bundle), HOLDER_BUNDLE);
74061
+ const lean = bundle === void 0 ? void 0 : (0, import_node_path76.join)((0, import_node_path76.dirname)(bundle), HOLDER_BUNDLE);
73884
74062
  const script = lean !== void 0 && exists6(lean) ? [...runtimeArgs.slice(0, -1), lean] : runtimeArgs;
73885
74063
  return [...nodeFlags, ...script, "hold"];
73886
74064
  }
@@ -73915,17 +74093,17 @@ function createConversationMcpAuthorization(options) {
73915
74093
  }
73916
74094
 
73917
74095
  // src/holder/mcp-helper-access.ts
73918
- var import_promises63 = require("fs/promises");
74096
+ var import_promises64 = require("fs/promises");
73919
74097
  function createHelperMcpAccess(options) {
73920
74098
  return {
73921
74099
  [Symbol.asyncDispose]: async () => {
73922
- await (0, import_promises63.rm)(options.credentialPath, { force: true });
74100
+ await (0, import_promises64.rm)(options.credentialPath, { force: true });
73923
74101
  },
73924
74102
  url: options.managedMcp.url,
73925
74103
  authorization: async (signal) => {
73926
74104
  const authorization = await options.managedMcp.authorization(signal);
73927
74105
  if (authorization === void 0 || signal.aborted) {
73928
- await (0, import_promises63.rm)(options.credentialPath, { force: true });
74106
+ await (0, import_promises64.rm)(options.credentialPath, { force: true });
73929
74107
  return void 0;
73930
74108
  }
73931
74109
  const credential = {
@@ -73940,8 +74118,8 @@ function createHelperMcpAccess(options) {
73940
74118
  }
73941
74119
 
73942
74120
  // src/holder/run-inputs.ts
73943
- var import_promises64 = require("fs/promises");
73944
- var import_node_path76 = require("path");
74121
+ var import_promises65 = require("fs/promises");
74122
+ var import_node_path77 = require("path");
73945
74123
  init_src();
73946
74124
  var NO_RUN_INPUTS = {
73947
74125
  attachments: [],
@@ -73955,17 +74133,17 @@ function safeFilename(filename) {
73955
74133
  return safe || "attachment";
73956
74134
  }
73957
74135
  function persistentAttachmentDir(workspaceRoot2) {
73958
- return (0, import_node_path76.join)(workspaceRoot2, ".alan", "attachments");
74136
+ return (0, import_node_path77.join)(workspaceRoot2, ".alan", "attachments");
73959
74137
  }
73960
74138
  function attachmentPath(spec, attachment, index, runDir) {
73961
74139
  const workspaceRoot2 = spec.approvedWorkspacePaths?.[0];
73962
74140
  if (attachment.persist && workspaceRoot2) {
73963
- return (0, import_node_path76.join)(
74141
+ return (0, import_node_path77.join)(
73964
74142
  persistentAttachmentDir(workspaceRoot2),
73965
74143
  `${attachment.id.slice(0, 8)}-${safeFilename(attachment.filename)}`
73966
74144
  );
73967
74145
  }
73968
- return (0, import_node_path76.join)(runDir, `${index}-${safeFilename(attachment.filename)}`);
74146
+ return (0, import_node_path77.join)(runDir, `${index}-${safeFilename(attachment.filename)}`);
73969
74147
  }
73970
74148
  function runMediaUploader(source, runId) {
73971
74149
  const upload = source.uploadMedia?.bind(source);
@@ -73974,10 +74152,11 @@ function runMediaUploader(source, runId) {
73974
74152
  upload: ({ data, ...media }, signal) => upload(runId, { ...media, bytes: data.byteLength }, data, signal)
73975
74153
  };
73976
74154
  }
73977
- async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
73978
- const dir = (0, import_node_path76.join)(tmpDir, "runs", spec.runId);
74155
+ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [], commitAttribution }) {
74156
+ await commitAttribution?.setCoAuthor(spec.gitCoAuthor);
74157
+ const dir = (0, import_node_path77.join)(tmpDir, "runs", spec.runId);
73979
74158
  const cleanup = async () => {
73980
- await (0, import_promises64.rm)(dir, { recursive: true, force: true });
74159
+ await (0, import_promises65.rm)(dir, { recursive: true, force: true });
73981
74160
  };
73982
74161
  try {
73983
74162
  const credential = await source.fetchProviderCredential(spec.runId, signal);
@@ -73985,8 +74164,8 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
73985
74164
  for (const [index, attachment] of (spec.attachments ?? []).entries()) {
73986
74165
  const bytes = await source.downloadAttachment(spec.runId, attachment.id, signal);
73987
74166
  const path4 = attachmentPath(spec, attachment, index, dir);
73988
- await (0, import_promises64.mkdir)((0, import_node_path76.dirname)(path4), { recursive: true, mode: 448 });
73989
- await (0, import_promises64.writeFile)(path4, bytes, { mode: 384 });
74167
+ await (0, import_promises65.mkdir)((0, import_node_path77.dirname)(path4), { recursive: true, mode: 448 });
74168
+ await (0, import_promises65.writeFile)(path4, bytes, { mode: 384 });
73990
74169
  const imageMimeType = attachment.kind === "image" ? detectImageMimeType(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)) : null;
73991
74170
  attachments.push({
73992
74171
  id: attachment.id,
@@ -74016,33 +74195,33 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
74016
74195
  }
74017
74196
 
74018
74197
  // src/holder/serve.ts
74019
- var import_node_crypto51 = require("crypto");
74198
+ var import_node_crypto52 = require("crypto");
74020
74199
  var import_node_fs35 = require("fs");
74021
74200
  var import_node_net3 = require("net");
74022
- var import_node_path88 = require("path");
74201
+ var import_node_path89 = require("path");
74023
74202
  init_runtime_v2();
74024
74203
 
74025
74204
  // src/holder/admission.ts
74026
74205
  var import_node_fs32 = require("fs");
74027
- var import_promises68 = require("fs/promises");
74206
+ var import_promises69 = require("fs/promises");
74028
74207
  var import_node_os11 = require("os");
74029
- var import_node_path82 = require("path");
74208
+ var import_node_path83 = require("path");
74030
74209
  init_constants();
74031
74210
 
74032
74211
  // ../shared/src/node/local-workspace.ts
74033
74212
  var import_node_fs31 = require("fs");
74034
74213
  var import_node_os10 = require("os");
74035
- var import_node_path77 = require("path");
74214
+ var import_node_path78 = require("path");
74036
74215
  function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os10.homedir)()) {
74037
- return (0, import_node_path77.join)(homeDirectory, ".alan", "workspace");
74216
+ return (0, import_node_path78.join)(homeDirectory, ".alan", "workspace");
74038
74217
  }
74039
74218
 
74040
74219
  // src/holder/agent-context.ts
74041
- var import_promises65 = require("fs/promises");
74042
- var import_node_path78 = require("path");
74220
+ var import_promises66 = require("fs/promises");
74221
+ var import_node_path79 = require("path");
74043
74222
  init_prompt();
74044
74223
  async function readText4(path4) {
74045
- return (0, import_promises65.readFile)(path4, "utf8").then(
74224
+ return (0, import_promises66.readFile)(path4, "utf8").then(
74046
74225
  (text3) => text3.trim(),
74047
74226
  () => null
74048
74227
  );
@@ -74057,10 +74236,10 @@ async function startCommandState(statusPath) {
74057
74236
  return code === 0 ? { state: "exited_ok" } : { state: "failed", exitCode: code };
74058
74237
  }
74059
74238
  function createAgentContext(deps) {
74060
- const statusPath = (0, import_node_path78.join)(deps.homeDir, ".alan", "start-commands.status");
74061
- const logPath = (0, import_node_path78.join)(deps.homeDir, ".alan", "start-commands.log");
74239
+ const statusPath = (0, import_node_path79.join)(deps.homeDir, ".alan", "start-commands.status");
74240
+ const logPath = (0, import_node_path79.join)(deps.homeDir, ".alan", "start-commands.log");
74062
74241
  return async (spec, problems) => {
74063
- const file2 = (0, import_node_path78.join)(deps.dir, `${spec.conversationId}.json`);
74242
+ const file2 = (0, import_node_path79.join)(deps.dir, `${spec.conversationId}.json`);
74064
74243
  const saved = await readJsonFile(file2, agentContextSnapshotSchema);
74065
74244
  const known = saved.kind === "ok" ? saved.value : void 0;
74066
74245
  const hasEnvironment = (spec.agentContext ?? known)?.environment !== void 0;
@@ -74084,28 +74263,28 @@ function createAgentContext(deps) {
74084
74263
  }
74085
74264
 
74086
74265
  // src/holder/checkout-refresh.ts
74087
- var import_node_path81 = require("path");
74266
+ var import_node_path82 = require("path");
74088
74267
 
74089
74268
  // src/holder/claim-once.ts
74090
- var import_node_crypto49 = require("crypto");
74091
- var import_promises66 = require("fs/promises");
74092
- var import_node_path79 = require("path");
74269
+ var import_node_crypto50 = require("crypto");
74270
+ var import_promises67 = require("fs/promises");
74271
+ var import_node_path80 = require("path");
74093
74272
  async function claimOnce(dir, name) {
74094
74273
  try {
74095
- await (0, import_promises66.mkdir)(dir, { recursive: true, mode: 448 });
74096
- await (await (0, import_promises66.open)((0, import_node_path79.join)(dir, name), "wx")).close();
74274
+ await (0, import_promises67.mkdir)(dir, { recursive: true, mode: 448 });
74275
+ await (await (0, import_promises67.open)((0, import_node_path80.join)(dir, name), "wx")).close();
74097
74276
  return true;
74098
74277
  } catch {
74099
74278
  return false;
74100
74279
  }
74101
74280
  }
74102
74281
  function claimFirstLease(freshnessDir, path4) {
74103
- return claimOnce((0, import_node_path79.join)(freshnessDir, "leased"), (0, import_node_crypto49.createHash)("sha256").update(path4).digest("hex"));
74282
+ return claimOnce((0, import_node_path80.join)(freshnessDir, "leased"), (0, import_node_crypto50.createHash)("sha256").update(path4).digest("hex"));
74104
74283
  }
74105
74284
 
74106
74285
  // src/holder/requested-checkout.ts
74107
- var import_promises67 = require("fs/promises");
74108
- var import_node_path80 = require("path");
74286
+ var import_promises68 = require("fs/promises");
74287
+ var import_node_path81 = require("path");
74109
74288
  var REMOTE2 = "origin";
74110
74289
  var REASON_MAX_CHARS = 200;
74111
74290
  function firstLine3(text3) {
@@ -74126,8 +74305,8 @@ function notSwitched(checkout, current, reason) {
74126
74305
  );
74127
74306
  }
74128
74307
  async function clone2(checkout, deps, signal) {
74129
- const parent = (0, import_node_path80.dirname)(checkout.path);
74130
- await (0, import_promises67.mkdir)(parent, { recursive: true });
74308
+ const parent = (0, import_node_path81.dirname)(checkout.path);
74309
+ await (0, import_promises68.mkdir)(parent, { recursive: true });
74131
74310
  await assertValidBranch(deps.git, parent, checkout.branch, signal);
74132
74311
  const output2 = await deps.git.run(
74133
74312
  {
@@ -74362,7 +74541,7 @@ async function applyRequestedCheckouts(spec, deps, signal) {
74362
74541
  ms: Date.now() - startedAt
74363
74542
  });
74364
74543
  if (outcome2.kind === "on_branch") continue;
74365
- settled2.add((0, import_node_path81.resolve)(checkout.path));
74544
+ settled2.add((0, import_node_path82.resolve)(checkout.path));
74366
74545
  if (outcome2.kind === "noted") {
74367
74546
  problems.push({ path: checkout.path, problem: outcome2.problem, action: outcome2.action });
74368
74547
  }
@@ -74372,7 +74551,7 @@ async function applyRequestedCheckouts(spec, deps, signal) {
74372
74551
  async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
74373
74552
  const problems = [];
74374
74553
  for (const target of targets) {
74375
- if (settled2.has((0, import_node_path81.resolve)(target))) continue;
74554
+ if (settled2.has((0, import_node_path82.resolve)(target))) continue;
74376
74555
  const freshness = await readCheckoutFreshness(deps.dir, target);
74377
74556
  if (freshness === null) continue;
74378
74557
  const startedAt = Date.now();
@@ -74393,7 +74572,7 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
74393
74572
  function createCheckoutRefresh(deps) {
74394
74573
  return async (spec, signal) => {
74395
74574
  if (spec.providerSessionId !== void 0) return [];
74396
- if (!await claimOnce((0, import_node_path81.join)(deps.dir, "conversations"), spec.conversationId)) return [];
74575
+ if (!await claimOnce((0, import_node_path82.join)(deps.dir, "conversations"), spec.conversationId)) return [];
74397
74576
  const requested = await applyRequestedCheckouts(spec, deps, signal);
74398
74577
  const targets = await checkoutsOf(spec);
74399
74578
  return [
@@ -74435,7 +74614,7 @@ function volumeRoot(path4) {
74435
74614
  }
74436
74615
  async function exists4(path4) {
74437
74616
  try {
74438
- await (0, import_promises68.stat)(path4);
74617
+ await (0, import_promises69.stat)(path4);
74439
74618
  return true;
74440
74619
  } catch {
74441
74620
  return false;
@@ -74443,10 +74622,10 @@ async function exists4(path4) {
74443
74622
  }
74444
74623
  async function inspectReadiness(path4) {
74445
74624
  try {
74446
- if (!(await (0, import_promises68.stat)(path4)).isDirectory()) {
74625
+ if (!(await (0, import_promises69.stat)(path4)).isDirectory()) {
74447
74626
  return { ready: false, missing: true, message: MESSAGES.missing };
74448
74627
  }
74449
- await (0, import_promises68.access)(path4, import_node_fs32.constants.R_OK | import_node_fs32.constants.W_OK | import_node_fs32.constants.X_OK);
74628
+ await (0, import_promises69.access)(path4, import_node_fs32.constants.R_OK | import_node_fs32.constants.W_OK | import_node_fs32.constants.X_OK);
74450
74629
  return { ready: true };
74451
74630
  } catch (error62) {
74452
74631
  const code = errnoCode(error62) ?? "";
@@ -74490,8 +74669,8 @@ async function admitDefaultWorkspace(spec, context, skills) {
74490
74669
  const { env } = context;
74491
74670
  const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os11.homedir)());
74492
74671
  try {
74493
- await (0, import_promises68.mkdir)(path4, { recursive: true, mode: 448 });
74494
- await (0, import_promises68.access)(path4, import_node_fs32.constants.R_OK | import_node_fs32.constants.W_OK | import_node_fs32.constants.X_OK);
74672
+ await (0, import_promises69.mkdir)(path4, { recursive: true, mode: 448 });
74673
+ await (0, import_promises69.access)(path4, import_node_fs32.constants.R_OK | import_node_fs32.constants.W_OK | import_node_fs32.constants.X_OK);
74495
74674
  return { kind: "admitted", spec: { ...spec, projectPath: path4 }, skills };
74496
74675
  } catch (error62) {
74497
74676
  const code = errnoCode(error62);
@@ -74580,7 +74759,7 @@ function createHolderWorkspace(machine, clock, log) {
74580
74759
  ),
74581
74760
  approvedRoots: async () => {
74582
74761
  const approved = await openApprovedPaths({
74583
- file: (0, import_node_path82.join)(machine.stateDir, "workspaces.json"),
74762
+ file: (0, import_node_path83.join)(machine.stateDir, "workspaces.json"),
74584
74763
  log,
74585
74764
  platform: platform3
74586
74765
  });
@@ -74596,12 +74775,12 @@ function createHolderWorkspace(machine, clock, log) {
74596
74775
  localTimeoutMs: CHECKOUT_LOCAL_TIMEOUT_MS,
74597
74776
  networkTimeoutMs: CHECKOUT_NETWORK_TIMEOUT_MS
74598
74777
  }),
74599
- locks: openRepositoryLocks({ dir: (0, import_node_path82.join)(machine.stateDir, "locks"), clock, platform: platform3 }),
74778
+ locks: openRepositoryLocks({ dir: (0, import_node_path83.join)(machine.stateDir, "locks"), clock, platform: platform3 }),
74600
74779
  log,
74601
- dir: (0, import_node_path82.join)(machine.stateDir, "checkout-freshness")
74780
+ dir: (0, import_node_path83.join)(machine.stateDir, "checkout-freshness")
74602
74781
  }),
74603
74782
  prepareAgentContext: createAgentContext({
74604
- dir: (0, import_node_path82.join)(machine.stateDir, "agent-context"),
74783
+ dir: (0, import_node_path83.join)(machine.stateDir, "agent-context"),
74605
74784
  homeDir: machine.env.HOME || (0, import_node_os11.homedir)()
74606
74785
  })
74607
74786
  } : {}
@@ -74619,7 +74798,7 @@ async function respondToTurn(runningRunId, driver, request2) {
74619
74798
  }
74620
74799
 
74621
74800
  // src/holder/session-facts.ts
74622
- var import_promises69 = require("fs/promises");
74801
+ var import_promises70 = require("fs/promises");
74623
74802
  var CLI_RSS_CACHE_MS = 1e4;
74624
74803
  var LOGIN_PROBLEM_PREFIX = "cli.auth.";
74625
74804
  function isLoginFailure(result) {
@@ -74645,8 +74824,8 @@ function createSessionFacts(options) {
74645
74824
  const path4 = await resolveCommandOnPath(command, env, platform3);
74646
74825
  if (path4 === null) return null;
74647
74826
  try {
74648
- const real = await (0, import_promises69.realpath)(path4);
74649
- const info = await (0, import_promises69.stat)(real);
74827
+ const real = await (0, import_promises70.realpath)(path4);
74828
+ const info = await (0, import_promises70.stat)(real);
74650
74829
  return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
74651
74830
  } catch {
74652
74831
  return null;
@@ -74740,12 +74919,12 @@ async function steerTurn(runningRunId, driver, request2) {
74740
74919
  init_acp2();
74741
74920
 
74742
74921
  // src/run-log/archive.ts
74743
- var import_promises70 = require("fs/promises");
74744
- var import_node_path83 = require("path");
74922
+ var import_promises71 = require("fs/promises");
74923
+ var import_node_path84 = require("path");
74745
74924
  init_runtime_v2();
74746
74925
  async function openRunArchive(runsDir) {
74747
- const path4 = (0, import_node_path83.join)((0, import_node_path83.dirname)(runsDir), "archived-runs.txt");
74748
- const text3 = await (0, import_promises70.readFile)(path4, "utf8").catch((error62) => {
74926
+ const path4 = (0, import_node_path84.join)((0, import_node_path84.dirname)(runsDir), "archived-runs.txt");
74927
+ const text3 = await (0, import_promises71.readFile)(path4, "utf8").catch((error62) => {
74749
74928
  if (errnoCode(error62) === "ENOENT") return "";
74750
74929
  throw error62;
74751
74930
  });
@@ -74759,7 +74938,7 @@ async function openRunArchive(runsDir) {
74759
74938
  add: async (runIds) => {
74760
74939
  const added = runIds.filter((runId) => !archived.has(runId));
74761
74940
  if (added.length === 0) return;
74762
- await (0, import_promises70.appendFile)(path4, `
74941
+ await (0, import_promises71.appendFile)(path4, `
74763
74942
  ${added.join("\n")}
74764
74943
  `, { mode: 384 });
74765
74944
  for (const runId of added) archived.add(runId);
@@ -74768,13 +74947,13 @@ ${added.join("\n")}
74768
74947
  }
74769
74948
 
74770
74949
  // src/run-log/complete.ts
74771
- var import_node_crypto50 = require("crypto");
74950
+ var import_node_crypto51 = require("crypto");
74772
74951
  var import_node_fs33 = require("fs");
74773
- var import_node_path85 = require("path");
74952
+ var import_node_path86 = require("path");
74774
74953
 
74775
74954
  // src/run-log/directory.ts
74776
- var import_promises71 = require("fs/promises");
74777
- var import_node_path84 = require("path");
74955
+ var import_promises72 = require("fs/promises");
74956
+ var import_node_path85 = require("path");
74778
74957
  init_runtime_v2();
74779
74958
  init_zod();
74780
74959
  var runMetaSchema = external_exports.object({
@@ -74800,17 +74979,17 @@ async function readRunMeta(path4) {
74800
74979
  return read.kind === "ok" ? read.value : null;
74801
74980
  }
74802
74981
  function runDirectory(runsDir, runId) {
74803
- const dir = (0, import_node_path84.join)(runsDir, runId);
74982
+ const dir = (0, import_node_path85.join)(runsDir, runId);
74804
74983
  return {
74805
74984
  dir,
74806
- log: (0, import_node_path84.join)(dir, "log.jsonl"),
74807
- upload: (0, import_node_path84.join)(dir, "upload.json"),
74808
- meta: (0, import_node_path84.join)(dir, "run.json")
74985
+ log: (0, import_node_path85.join)(dir, "log.jsonl"),
74986
+ upload: (0, import_node_path85.join)(dir, "upload.json"),
74987
+ meta: (0, import_node_path85.join)(dir, "run.json")
74809
74988
  };
74810
74989
  }
74811
74990
  async function isRunClaimed(runsDir, runId) {
74812
74991
  try {
74813
- return (await (0, import_promises71.stat)(runDirectory(runsDir, runId).log)).size > 0;
74992
+ return (await (0, import_promises72.stat)(runDirectory(runsDir, runId).log)).size > 0;
74814
74993
  } catch (error62) {
74815
74994
  if (errnoCode(error62) === "ENOENT") return false;
74816
74995
  throw error62;
@@ -74819,7 +74998,7 @@ async function isRunClaimed(runsDir, runId) {
74819
74998
 
74820
74999
  // src/run-log/complete.ts
74821
75000
  function writeLogFile(path4, dir, text3) {
74822
- const temp = (0, import_node_path85.join)(dir, `.log.${(0, import_node_crypto50.randomUUID)()}.tmp`);
75001
+ const temp = (0, import_node_path86.join)(dir, `.log.${(0, import_node_crypto51.randomUUID)()}.tmp`);
74823
75002
  const fd = (0, import_node_fs33.openSync)(temp, "wx", 384);
74824
75003
  try {
74825
75004
  (0, import_node_fs33.writeSync)(fd, text3);
@@ -74848,8 +75027,8 @@ async function writeCompleteRunLog(runsDir, meta3, records) {
74848
75027
  }
74849
75028
 
74850
75029
  // src/run-log/conversation-index.ts
74851
- var import_promises72 = require("fs/promises");
74852
- var import_node_path86 = require("path");
75030
+ var import_promises73 = require("fs/promises");
75031
+ var import_node_path87 = require("path");
74853
75032
  init_runtime_v2();
74854
75033
  init_zod();
74855
75034
  var ORDINALS_PER_SHARD = 1e3;
@@ -74866,13 +75045,13 @@ var coverageSchema = external_exports.object({
74866
75045
  nextExpectedOrdinal: external_exports.number().int().positive()
74867
75046
  });
74868
75047
  function conversationsDirectory(runsDir) {
74869
- return (0, import_node_path86.join)((0, import_node_path86.dirname)(runsDir), "conversations");
75048
+ return (0, import_node_path87.join)((0, import_node_path87.dirname)(runsDir), "conversations");
74870
75049
  }
74871
75050
  function indexDirectory(runsDir, conversationId) {
74872
- return (0, import_node_path86.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
75051
+ return (0, import_node_path87.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
74873
75052
  }
74874
75053
  function shardPath(runsDir, conversationId, ordinal) {
74875
- return (0, import_node_path86.join)(
75054
+ return (0, import_node_path87.join)(
74876
75055
  indexDirectory(runsDir, conversationId),
74877
75056
  `${Math.floor(ordinal / ORDINALS_PER_SHARD)}.jsonl`
74878
75057
  );
@@ -74881,10 +75060,10 @@ async function indexConversationRun(runsDir, conversationId, ordinal, assistantO
74881
75060
  const nextOrdinal = assistantOrdinal + 1;
74882
75061
  if (nextOrdinal <= ordinal) throw new Error("Assistant order must follow the prompt");
74883
75062
  const path4 = shardPath(runsDir, conversationId, ordinal);
74884
- await (0, import_promises72.mkdir)((0, import_node_path86.dirname)(path4), { recursive: true, mode: 448 });
74885
- await (0, import_promises72.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
75063
+ await (0, import_promises73.mkdir)((0, import_node_path87.dirname)(path4), { recursive: true, mode: 448 });
75064
+ await (0, import_promises73.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
74886
75065
  `, { mode: 384 });
74887
- const coveragePath = (0, import_node_path86.join)((0, import_node_path86.dirname)((0, import_node_path86.dirname)(path4)), "coverage.json");
75066
+ const coveragePath = (0, import_node_path87.join)((0, import_node_path87.dirname)((0, import_node_path87.dirname)(path4)), "coverage.json");
74888
75067
  const coverage = await readJsonFile(coveragePath, coverageSchema);
74889
75068
  const current = coverage.kind === "ok" ? coverage.value : null;
74890
75069
  const next = nextCoverage(current, ordinal, nextOrdinal);
@@ -74899,13 +75078,13 @@ function nextCoverage(current, ordinal, nextOrdinal) {
74899
75078
  return null;
74900
75079
  }
74901
75080
  async function readConversationIndexCoverage(runsDir, conversationId) {
74902
- const path4 = (0, import_node_path86.join)((0, import_node_path86.dirname)(indexDirectory(runsDir, conversationId)), "coverage.json");
75081
+ const path4 = (0, import_node_path87.join)((0, import_node_path87.dirname)(indexDirectory(runsDir, conversationId)), "coverage.json");
74903
75082
  const result = await readJsonFile(path4, coverageSchema);
74904
75083
  return result.kind === "ok" ? result.value : null;
74905
75084
  }
74906
75085
  async function readConversationRunIndex(runsDir, conversationId, before, limit) {
74907
75086
  const directory = indexDirectory(runsDir, conversationId);
74908
- const names = await (0, import_promises72.readdir)(directory).catch((error62) => {
75087
+ const names = await (0, import_promises73.readdir)(directory).catch((error62) => {
74909
75088
  if (error62.code === "ENOENT") return [];
74910
75089
  throw error62;
74911
75090
  });
@@ -74914,7 +75093,7 @@ async function readConversationRunIndex(runsDir, conversationId, before, limit)
74914
75093
  ).sort((left, right) => right - left);
74915
75094
  const selected = [];
74916
75095
  for (const shard of shards) {
74917
- const text3 = await (0, import_promises72.readFile)((0, import_node_path86.join)(directory, `${shard}.jsonl`), "utf8");
75096
+ const text3 = await (0, import_promises73.readFile)((0, import_node_path87.join)(directory, `${shard}.jsonl`), "utf8");
74918
75097
  const records = text3.split("\n").flatMap((line) => {
74919
75098
  if (!line) return [];
74920
75099
  const parsed = indexRecordSchema.parse(JSON.parse(line));
@@ -74939,7 +75118,7 @@ async function readIndexableRun(runsDir, name) {
74939
75118
  return { conversationId: meta3.conversationId, ordinal, assistantOrdinal, runId: runId.data };
74940
75119
  }
74941
75120
  async function readIndexableRuns(runsDir) {
74942
- const names = await (0, import_promises72.readdir)(runsDir).catch(() => []);
75121
+ const names = await (0, import_promises73.readdir)(runsDir).catch(() => []);
74943
75122
  const byConversation = /* @__PURE__ */ new Map();
74944
75123
  let next = 0;
74945
75124
  const worker = async () => {
@@ -74969,21 +75148,21 @@ async function writeConversationIndex(directory, runs) {
74969
75148
  else lines2.push(line);
74970
75149
  coverage = nextCoverage(coverage, run2.ordinal, nextOrdinal) ?? coverage;
74971
75150
  }
74972
- await (0, import_promises72.mkdir)((0, import_node_path86.join)(directory, "turn-index"), { recursive: true, mode: 448 });
75151
+ await (0, import_promises73.mkdir)((0, import_node_path87.join)(directory, "turn-index"), { recursive: true, mode: 448 });
74973
75152
  for (const [shard, lines2] of shards) {
74974
- await (0, import_promises72.writeFile)((0, import_node_path86.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
75153
+ await (0, import_promises73.writeFile)((0, import_node_path87.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
74975
75154
  `, {
74976
75155
  mode: 384
74977
75156
  });
74978
75157
  }
74979
- await (0, import_promises72.writeFile)((0, import_node_path86.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
75158
+ await (0, import_promises73.writeFile)((0, import_node_path87.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
74980
75159
  `, {
74981
75160
  mode: 384
74982
75161
  });
74983
75162
  }
74984
75163
  async function rebuildConversationIndexes(runsDir) {
74985
75164
  const root = conversationsDirectory(runsDir);
74986
- const exists6 = await (0, import_promises72.stat)(root).then(
75165
+ const exists6 = await (0, import_promises73.stat)(root).then(
74987
75166
  () => true,
74988
75167
  (error62) => {
74989
75168
  if (errnoCode(error62) === "ENOENT") return false;
@@ -74992,18 +75171,18 @@ async function rebuildConversationIndexes(runsDir) {
74992
75171
  );
74993
75172
  if (exists6) return 0;
74994
75173
  const building = `${root}.rebuilding`;
74995
- await (0, import_promises72.rm)(building, { recursive: true, force: true });
74996
- await (0, import_promises72.mkdir)(building, { recursive: true, mode: 448 });
75174
+ await (0, import_promises73.rm)(building, { recursive: true, force: true });
75175
+ await (0, import_promises73.mkdir)(building, { recursive: true, mode: 448 });
74997
75176
  const byConversation = await readIndexableRuns(runsDir);
74998
75177
  for (const [conversationId, runs] of byConversation) {
74999
- await writeConversationIndex((0, import_node_path86.join)(building, conversationId), runs);
75178
+ await writeConversationIndex((0, import_node_path87.join)(building, conversationId), runs);
75000
75179
  }
75001
- await (0, import_promises72.rename)(building, root);
75180
+ await (0, import_promises73.rename)(building, root);
75002
75181
  return byConversation.size;
75003
75182
  }
75004
75183
 
75005
75184
  // src/run-log/reader.ts
75006
- var import_promises73 = require("fs/promises");
75185
+ var import_promises74 = require("fs/promises");
75007
75186
  init_runtime_v2();
75008
75187
 
75009
75188
  // src/run-log/tail.ts
@@ -75041,7 +75220,7 @@ function firstRecordLength(bytes) {
75041
75220
  return bytes.indexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
75042
75221
  }
75043
75222
  async function openRunLogReader(path4) {
75044
- const handle = await (0, import_promises73.open)(path4, "r");
75223
+ const handle = await (0, import_promises74.open)(path4, "r");
75045
75224
  const readAt = async (position, length) => {
75046
75225
  const buffer = Buffer.alloc(length);
75047
75226
  const { bytesRead } = await handle.read(buffer, 0, length, position);
@@ -75075,7 +75254,7 @@ async function openRunLogReader(path4) {
75075
75254
  };
75076
75255
  }
75077
75256
  async function readLastRecord(path4) {
75078
- const handle = await (0, import_promises73.open)(path4, "r").catch(() => null);
75257
+ const handle = await (0, import_promises74.open)(path4, "r").catch(() => null);
75079
75258
  if (handle === null) return null;
75080
75259
  try {
75081
75260
  const { size } = await handle.stat();
@@ -75106,7 +75285,7 @@ var decoder = new TextDecoder();
75106
75285
 
75107
75286
  // src/run-log/writer.ts
75108
75287
  var import_node_fs34 = require("fs");
75109
- var import_node_path87 = require("path");
75288
+ var import_node_path88 = require("path");
75110
75289
  init_runtime_v2();
75111
75290
  function readTail(fd, size) {
75112
75291
  for (const length of tailWindows(size)) {
@@ -75125,7 +75304,7 @@ function writeAt(fd, bytes, position) {
75125
75304
  }
75126
75305
  }
75127
75306
  function openRunLog(path4, clock) {
75128
- (0, import_node_fs34.mkdirSync)((0, import_node_path87.dirname)(path4), { recursive: true, mode: 448 });
75307
+ (0, import_node_fs34.mkdirSync)((0, import_node_path88.dirname)(path4), { recursive: true, mode: 448 });
75129
75308
  const fd = (0, import_node_fs34.openSync)(path4, import_node_fs34.constants.O_RDWR | import_node_fs34.constants.O_CREAT, 384);
75130
75309
  const fileSize = (0, import_node_fs34.fstatSync)(fd).size;
75131
75310
  const tail = readTail(fd, fileSize);
@@ -75406,12 +75585,12 @@ var TASK_UNSUPPORTED = {
75406
75585
  message: "This agent cannot stop one background task."
75407
75586
  };
75408
75587
  function sha2564(value2) {
75409
- return (0, import_node_crypto51.createHash)("sha256").update(value2).digest("hex");
75588
+ return (0, import_node_crypto52.createHash)("sha256").update(value2).digest("hex");
75410
75589
  }
75411
75590
  function tokenMatches2(expected, presented) {
75412
75591
  const a = Buffer.from(sha2564(expected), "hex");
75413
75592
  const b = Buffer.from(sha2564(presented), "hex");
75414
- return (0, import_node_crypto51.timingSafeEqual)(a, b);
75593
+ return (0, import_node_crypto52.timingSafeEqual)(a, b);
75415
75594
  }
75416
75595
  async function runHolder({
75417
75596
  launch,
@@ -75425,7 +75604,7 @@ async function runHolder({
75425
75604
  try {
75426
75605
  const identity = await readProcessIdentity(process.pid);
75427
75606
  if (identity === null) throw new RuntimeFault("internal", "Cannot read own process identity");
75428
- const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0, import_node_path88.dirname)(launch.statusPath)), clock, log));
75607
+ const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0, import_node_path89.dirname)(launch.statusPath)), clock, log));
75429
75608
  const holder = {
75430
75609
  state: "idle",
75431
75610
  runId: null,
@@ -75433,7 +75612,7 @@ async function runHolder({
75433
75612
  clients: /* @__PURE__ */ new Set()
75434
75613
  };
75435
75614
  const activity = __using(_stack, startActivityFile({
75436
- path: sessionActivityPath((0, import_node_path88.dirname)(launch.statusPath)),
75615
+ path: sessionActivityPath((0, import_node_path89.dirname)(launch.statusPath)),
75437
75616
  read: () => ({
75438
75617
  runId: holder.runId,
75439
75618
  ...driver.activity?.() ?? IDLE_DRIVER_ACTIVITY
@@ -75676,23 +75855,24 @@ async function runHolder({
75676
75855
  }
75677
75856
 
75678
75857
  // src/cli/commands/activity-lease-producer.ts
75679
- function runsKey(runs) {
75680
- return runs.map((run2) => `${run2.runId}:${run2.state}`).sort().join(",");
75858
+ function snapshotKey(snapshot) {
75859
+ const runs = snapshot.runs.map((run2) => `${run2.runId}:${run2.state}`).sort();
75860
+ return `${runs.join(",")}|${[...snapshot.busyRunIds].sort().join(",")}`;
75681
75861
  }
75682
75862
  function delta(current, previous) {
75683
75863
  return previous === void 0 ? 0 : Math.max(0, Math.round(current - previous));
75684
75864
  }
75685
75865
  async function lastOutputAtMs(runsDir, run2) {
75686
- const info = await (0, import_promises74.stat)(runDirectory(runsDir, run2.runId).log).catch(() => null);
75866
+ const info = await (0, import_promises75.stat)(runDirectory(runsDir, run2.runId).log).catch(() => null);
75687
75867
  return info === null ? null : Math.floor(info.mtimeMs);
75688
75868
  }
75689
75869
  async function readHolderActivities(sessionsDir) {
75690
- const names = await (0, import_promises74.readdir)(sessionsDir).catch(() => []);
75870
+ const names = await (0, import_promises75.readdir)(sessionsDir).catch(() => []);
75691
75871
  const found = [];
75692
75872
  for (const name of names) {
75693
75873
  const parsed = conversationIdSchema.safeParse(name);
75694
75874
  if (!parsed.success) continue;
75695
- const activity = await readSessionActivity(sessionActivityPath((0, import_node_path89.join)(sessionsDir, name)));
75875
+ const activity = await readSessionActivity(sessionActivityPath((0, import_node_path90.join)(sessionsDir, name)));
75696
75876
  if (activity !== null) found.push({ conversationId: parsed.data, activity });
75697
75877
  }
75698
75878
  return found;
@@ -75764,7 +75944,8 @@ function createLeaseProducer(deps) {
75764
75944
  mainThreadLagMs: Math.max(0, Math.round(deps.mainThreadLagMs())),
75765
75945
  runs: await runs(activities),
75766
75946
  holders: await holders(activities),
75767
- vm: await vmPressure()
75947
+ vm: await vmPressure(),
75948
+ busyRunIds: state.snapshot?.busyRunIds ?? []
75768
75949
  };
75769
75950
  state.sequence += 1;
75770
75951
  return lease;
@@ -75777,7 +75958,7 @@ function createLeaseProducer(deps) {
75777
75958
  };
75778
75959
  return {
75779
75960
  update: (snapshot) => {
75780
- const changed2 = state.snapshot === null || runsKey(snapshot.runs) !== runsKey(state.snapshot.runs);
75961
+ const changed2 = state.snapshot === null || snapshotKey(snapshot) !== snapshotKey(state.snapshot);
75781
75962
  state.snapshot = snapshot;
75782
75963
  return changed2;
75783
75964
  },
@@ -75839,7 +76020,8 @@ var snapshotRunSchema = external_exports.object({
75839
76020
  var leaseSnapshotSchema = external_exports.object({
75840
76021
  type: external_exports.literal("snapshot"),
75841
76022
  accessToken: external_exports.string().min(1),
75842
- runs: external_exports.array(snapshotRunSchema)
76023
+ runs: external_exports.array(snapshotRunSchema),
76024
+ busyRunIds: external_exports.array(runIdSchema)
75843
76025
  });
75844
76026
  var leaseWorkerMessageSchema = external_exports.object({
75845
76027
  type: external_exports.literal("unauthorized")
@@ -75969,18 +76151,18 @@ async function runActivityLeaseWorker(rawData, port) {
75969
76151
  }
75970
76152
 
75971
76153
  // src/cli/commands/compat.ts
75972
- var import_node_crypto53 = require("crypto");
75973
- var import_promises78 = require("fs/promises");
76154
+ var import_node_crypto54 = require("crypto");
76155
+ var import_promises79 = require("fs/promises");
75974
76156
  init_runtime_v2();
75975
76157
  init_zod();
75976
76158
 
75977
76159
  // src/cli/config.ts
75978
76160
  var import_node_os12 = require("os");
75979
- var import_node_path93 = require("path");
76161
+ var import_node_path94 = require("path");
75980
76162
  init_zod();
75981
76163
 
75982
76164
  // src/client/contract.ts
75983
- var import_node_path90 = require("path");
76165
+ var import_node_path91 = require("path");
75984
76166
  init_runtime_v2();
75985
76167
  init_zod();
75986
76168
  var LOCAL_API_PROTOCOL = 1;
@@ -76154,7 +76336,7 @@ var nativeHookSignalSchema = external_exports.strictObject({
76154
76336
  provider: external_exports.enum(nativeIngestionProviders),
76155
76337
  event: external_exports.enum(nativeIngestionHookEvents),
76156
76338
  externalSessionId: external_exports.string().trim().min(1).max(200),
76157
- transcriptPath: external_exports.string().min(1).max(4096).refine(import_node_path90.isAbsolute, "transcriptPath must be absolute"),
76339
+ transcriptPath: external_exports.string().min(1).max(4096).refine(import_node_path91.isAbsolute, "transcriptPath must be absolute"),
76158
76340
  cwd: external_exports.string().max(4096).nullable(),
76159
76341
  providerTurnId: external_exports.string().max(200).nullable(),
76160
76342
  assistantFingerprint: assistantFingerprintSchema.nullable(),
@@ -76190,19 +76372,19 @@ var localApiErrorSchema = external_exports.object({
76190
76372
  });
76191
76373
 
76192
76374
  // src/client/locate.ts
76193
- var import_node_path91 = require("path");
76375
+ var import_node_path92 = require("path");
76194
76376
  var RUNTIME_PROFILES = ["production", "staging", "development", "local"];
76195
76377
  function defaultStateDir({ profile, platform: platform3, home, env }) {
76196
76378
  if (platform3 === "win32") {
76197
- return (0, import_node_path91.join)(env.LOCALAPPDATA ?? (0, import_node_path91.join)(home, "AppData", "Local"), "Alan", profile);
76379
+ return (0, import_node_path92.join)(env.LOCALAPPDATA ?? (0, import_node_path92.join)(home, "AppData", "Local"), "Alan", profile);
76198
76380
  }
76199
- return (0, import_node_path91.join)(env.XDG_STATE_HOME ?? (0, import_node_path91.join)(home, ".local", "state"), "alan", profile);
76381
+ return (0, import_node_path92.join)(env.XDG_STATE_HOME ?? (0, import_node_path92.join)(home, ".local", "state"), "alan", profile);
76200
76382
  }
76201
76383
  function defaultInstallDir({ platform: platform3, home, env }) {
76202
76384
  if (platform3 === "win32") {
76203
- return (0, import_node_path91.join)(env.LOCALAPPDATA ?? (0, import_node_path91.join)(home, "AppData", "Local"), "Alan", "runtime");
76385
+ return (0, import_node_path92.join)(env.LOCALAPPDATA ?? (0, import_node_path92.join)(home, "AppData", "Local"), "Alan", "runtime");
76204
76386
  }
76205
- return (0, import_node_path91.join)(env.XDG_DATA_HOME ?? (0, import_node_path91.join)(home, ".local", "share"), "alan", "runtime");
76387
+ return (0, import_node_path92.join)(env.XDG_DATA_HOME ?? (0, import_node_path92.join)(home, ".local", "share"), "alan", "runtime");
76206
76388
  }
76207
76389
 
76208
76390
  // src/client/machine-features-contract.ts
@@ -76261,7 +76443,7 @@ var mcpConfigResultSchema = external_exports.object({
76261
76443
  });
76262
76444
 
76263
76445
  // src/client/runtime-client.ts
76264
- var import_promises75 = require("fs/promises");
76446
+ var import_promises76 = require("fs/promises");
76265
76447
  init_acp();
76266
76448
  init_runtime_v2();
76267
76449
 
@@ -76324,7 +76506,7 @@ var DEFAULT_BACKOFF = { initialMs: 250, maxMs: 3e4 };
76324
76506
  async function readDiscovery(path4) {
76325
76507
  let text3;
76326
76508
  try {
76327
- text3 = await (0, import_promises75.readFile)(path4, "utf8");
76509
+ text3 = await (0, import_promises76.readFile)(path4, "utf8");
76328
76510
  } catch (error62) {
76329
76511
  throw new RuntimeClientError("unavailable", "The runtime is not running", { cause: error62 });
76330
76512
  }
@@ -76732,9 +76914,9 @@ async function sendNativeHookSignal(discoveryPath, hookSignal, signal) {
76732
76914
  }
76733
76915
 
76734
76916
  // src/sessions/index.ts
76735
- var import_node_crypto52 = require("crypto");
76736
- var import_promises76 = require("fs/promises");
76737
- var import_node_path92 = require("path");
76917
+ var import_node_crypto53 = require("crypto");
76918
+ var import_promises77 = require("fs/promises");
76919
+ var import_node_path93 = require("path");
76738
76920
  init_runtime_v2();
76739
76921
 
76740
76922
  // src/sessions/admission.ts
@@ -76780,7 +76962,7 @@ var DEFAULT_MAX_ACTIVE_RUNS = 32;
76780
76962
  var HOLDER_BUSY = "busy";
76781
76963
  async function listIds(dir, schema) {
76782
76964
  const ids = [];
76783
- for (const name of await (0, import_promises76.readdir)(dir).catch(() => [])) {
76965
+ for (const name of await (0, import_promises77.readdir)(dir).catch(() => [])) {
76784
76966
  const parsed = schema.safeParse(name);
76785
76967
  if (parsed.success) ids.push(parsed.data);
76786
76968
  }
@@ -76794,8 +76976,8 @@ function holderIdentity(status) {
76794
76976
  return command === void 0 ? { pid, startedAt } : { pid, startedAt, command };
76795
76977
  }
76796
76978
  function sessionFiles(paths, conversationId) {
76797
- const dir = (0, import_node_path92.join)(paths.sessions, conversationId);
76798
- return { dir, launch: (0, import_node_path92.join)(dir, "launch.json"), status: (0, import_node_path92.join)(dir, "holder.json") };
76979
+ const dir = (0, import_node_path93.join)(paths.sessions, conversationId);
76980
+ return { dir, launch: (0, import_node_path93.join)(dir, "launch.json"), status: (0, import_node_path93.join)(dir, "holder.json") };
76799
76981
  }
76800
76982
  async function removeHolderFiles(files) {
76801
76983
  const holderWritten = [
@@ -76805,9 +76987,9 @@ async function removeHolderFiles(files) {
76805
76987
  sessionActivityPath(files.dir)
76806
76988
  ];
76807
76989
  for (const path4 of holderWritten) {
76808
- await (0, import_promises76.rm)(path4, { force: true });
76990
+ await (0, import_promises77.rm)(path4, { force: true });
76809
76991
  }
76810
- await (0, import_promises76.rmdir)(files.dir).catch((error62) => {
76992
+ await (0, import_promises77.rmdir)(files.dir).catch((error62) => {
76811
76993
  if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(errnoCode(error62) ?? "")) throw error62;
76812
76994
  });
76813
76995
  }
@@ -76976,8 +77158,8 @@ async function openSessions(deps) {
76976
77158
  protocol: HOLDER_PROTOCOL,
76977
77159
  conversationId,
76978
77160
  machineId: deps.machineId,
76979
- endpoint: ipcEndpoint(paths.sockets, (0, import_node_crypto52.randomUUID)().slice(0, 8)),
76980
- token: (0, import_node_crypto52.randomBytes)(32).toString("hex"),
77161
+ endpoint: ipcEndpoint(paths.sockets, (0, import_node_crypto53.randomUUID)().slice(0, 8)),
77162
+ token: (0, import_node_crypto53.randomBytes)(32).toString("hex"),
76981
77163
  runsDir: paths.runs,
76982
77164
  statusPath: files.status
76983
77165
  };
@@ -77003,7 +77185,7 @@ async function openSessions(deps) {
77003
77185
  const meta3 = await readRunMeta(dir.meta);
77004
77186
  const last = await readLastRecord(dir.log);
77005
77187
  if (meta3 === null || last === null) return null;
77006
- const logged = await (0, import_promises76.stat)(dir.log).catch((error62) => {
77188
+ const logged = await (0, import_promises77.stat)(dir.log).catch((error62) => {
77007
77189
  if (errnoCode(error62) === "ENOENT") return null;
77008
77190
  throw error62;
77009
77191
  });
@@ -77295,7 +77477,7 @@ var SECRET_VARIABLES = /* @__PURE__ */ new Set([
77295
77477
  ]);
77296
77478
  var ALAN_CODE_ENGINE_VARIABLE = "ALAN_CODE_ENGINE_PATH";
77297
77479
  function codexSkillsDir(config2) {
77298
- return config2.gitGatewayUrl === null ? null : (0, import_node_path93.join)(config2.codexHome, "skills");
77480
+ return config2.gitGatewayUrl === null ? null : (0, import_node_path94.join)(config2.codexHome, "skills");
77299
77481
  }
77300
77482
  function loadRuntimeConfig(env = process.env) {
77301
77483
  const parsed = envSchema.safeParse(env);
@@ -77356,7 +77538,7 @@ function loadRuntimeConfig(env = process.env) {
77356
77538
  providerProbes: ALAN_RUNTIME_PROVIDER_PROBES === "on",
77357
77539
  providerToolchain: ALAN_RUNTIME_PROVIDER_NODE !== void 0 && ALAN_RUNTIME_PROVIDER_NPM_CLI !== void 0 ? { node: ALAN_RUNTIME_PROVIDER_NODE, npmCli: ALAN_RUNTIME_PROVIDER_NPM_CLI } : null,
77358
77540
  home,
77359
- configHome: XDG_CONFIG_HOME ?? (0, import_node_path93.join)(home, ".config"),
77541
+ configHome: XDG_CONFIG_HOME ?? (0, import_node_path94.join)(home, ".config"),
77360
77542
  codexHome: resolveCodexHome(CODEX_HOME, home),
77361
77543
  ...githubProxyConfig({ ALAN_RUNTIME_GITHUB_PROXY, XDG_CONFIG_HOME, GH_CONFIG_DIR }, home),
77362
77544
  gitGatewayUrl: ALAN_RUNTIME_GIT_GATEWAY_URL ?? null,
@@ -77367,13 +77549,13 @@ function loadRuntimeConfig(env = process.env) {
77367
77549
  };
77368
77550
  }
77369
77551
  function resolveCodexHome(configuredHome, home) {
77370
- return configuredHome ?? (0, import_node_path93.join)(home, ".codex");
77552
+ return configuredHome ?? (0, import_node_path94.join)(home, ".codex");
77371
77553
  }
77372
77554
  function githubProxyConfig(env, home) {
77373
- const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path93.join)(home, ".config");
77555
+ const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path94.join)(home, ".config");
77374
77556
  return {
77375
77557
  githubProxy: env.ALAN_RUNTIME_GITHUB_PROXY === "on",
77376
- ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path93.join)(configHome, "gh")
77558
+ ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path94.join)(configHome, "gh")
77377
77559
  };
77378
77560
  }
77379
77561
  function serviceEnvironment2(env, profile) {
@@ -77431,9 +77613,9 @@ function takeEnrollmentCodeFromEnv(env = process.env) {
77431
77613
  }
77432
77614
 
77433
77615
  // src/cli/context.ts
77434
- var import_promises77 = require("fs/promises");
77616
+ var import_promises78 = require("fs/promises");
77435
77617
  var import_node_os13 = require("os");
77436
- var import_node_path94 = require("path");
77618
+ var import_node_path95 = require("path");
77437
77619
  var DESKTOP_BUNDLE_IDS = {
77438
77620
  production: ["com.alan-ai.desktop"],
77439
77621
  staging: ["com.alan-ai.desktop.staging"],
@@ -77473,7 +77655,7 @@ function serviceSpec({ config: config2, paths, self }) {
77473
77655
  profile: config2.profile,
77474
77656
  program: serviceCommand(config2.host, self, launcher),
77475
77657
  environment: config2.serviceEnvironment,
77476
- logPath: (0, import_node_path94.join)(paths.logs, "service.log"),
77658
+ logPath: (0, import_node_path95.join)(paths.logs, "service.log"),
77477
77659
  associatedBundleIds: DESKTOP_BUNDLE_IDS[config2.profile]
77478
77660
  };
77479
77661
  }
@@ -77481,7 +77663,7 @@ async function installedServiceSpec(ctx) {
77481
77663
  const spec = serviceSpec(ctx);
77482
77664
  if (ctx.config.host === "app") return spec;
77483
77665
  const layout = installLayout(ctx.config.installDir, ctx.config.profile);
77484
- const installed = await (0, import_promises77.access)(layout.launcher).then(
77666
+ const installed = await (0, import_promises78.access)(layout.launcher).then(
77485
77667
  () => true,
77486
77668
  () => false
77487
77669
  );
@@ -77612,7 +77794,7 @@ var manifestRevisionSchema = external_exports.object({ revision: external_export
77612
77794
  async function manifestRevision(path4) {
77613
77795
  let raw;
77614
77796
  try {
77615
- raw = JSON.parse(await (0, import_promises78.readFile)(path4, "utf8"));
77797
+ raw = JSON.parse(await (0, import_promises79.readFile)(path4, "utf8"));
77616
77798
  } catch (error62) {
77617
77799
  throw new RuntimeFault("invalid_file", `Cannot read the skill manifest at ${path4}`, {
77618
77800
  cause: error62
@@ -77630,7 +77812,7 @@ async function runSkills(argv) {
77630
77812
  case "scan":
77631
77813
  writeJson({
77632
77814
  status: "failed",
77633
- attemptId: (0, import_node_crypto53.randomUUID)(),
77815
+ attemptId: (0, import_node_crypto54.randomUUID)(),
77634
77816
  retainedInventoryRevision: null,
77635
77817
  diagnostics: [
77636
77818
  { code: "RUNTIME_SKILL_SCAN_UNSUPPORTED", message: SKILLS_SYNCED_BY_RUNTIME }
@@ -77646,7 +77828,7 @@ async function runSkills(argv) {
77646
77828
  );
77647
77829
  }
77648
77830
  writeJson({
77649
- attemptId: (0, import_node_crypto53.randomUUID)(),
77831
+ attemptId: (0, import_node_crypto54.randomUUID)(),
77650
77832
  desiredRevision: await manifestRevision(manifest),
77651
77833
  skills: []
77652
77834
  });
@@ -77666,8 +77848,8 @@ async function runSkills(argv) {
77666
77848
  }
77667
77849
 
77668
77850
  // src/cli/commands/doctor.ts
77669
- var import_promises81 = require("fs/promises");
77670
- var import_node_path98 = require("path");
77851
+ var import_promises82 = require("fs/promises");
77852
+ var import_node_path99 = require("path");
77671
77853
  init_runtime_v2();
77672
77854
 
77673
77855
  // src/identity/credential.ts
@@ -77675,8 +77857,8 @@ init_runtime_v2();
77675
77857
  init_zod();
77676
77858
 
77677
77859
  // src/identity/installation.ts
77678
- var import_node_crypto54 = require("crypto");
77679
- var import_node_path95 = require("path");
77860
+ var import_node_crypto55 = require("crypto");
77861
+ var import_node_path96 = require("path");
77680
77862
  init_runtime_v2();
77681
77863
  init_zod();
77682
77864
  var installationFileSchema = external_exports.object({
@@ -77684,7 +77866,7 @@ var installationFileSchema = external_exports.object({
77684
77866
  machineId: machineIdSchema.optional()
77685
77867
  });
77686
77868
  function installationPath(paths) {
77687
- return (0, import_node_path95.join)(paths.stateDir, "installation.json");
77869
+ return (0, import_node_path96.join)(paths.stateDir, "installation.json");
77688
77870
  }
77689
77871
  async function readInstallation(paths) {
77690
77872
  const result = await readJsonFile(installationPath(paths), installationFileSchema);
@@ -77693,7 +77875,7 @@ async function readInstallation(paths) {
77693
77875
  async function ensureInstallationId(paths) {
77694
77876
  const existing = await readInstallation(paths);
77695
77877
  if (existing !== null) return existing.installationId;
77696
- const created = { installationId: (0, import_node_crypto54.randomUUID)() };
77878
+ const created = { installationId: (0, import_node_crypto55.randomUUID)() };
77697
77879
  await writeJsonFileAtomic(installationPath(paths), created);
77698
77880
  return created.installationId;
77699
77881
  }
@@ -77875,7 +78057,7 @@ async function authorizeDevice(input2) {
77875
78057
  }
77876
78058
 
77877
78059
  // src/identity/enroll.ts
77878
- var import_promises79 = require("fs/promises");
78060
+ var import_promises80 = require("fs/promises");
77879
78061
  init_runtime_v2();
77880
78062
  async function enrollMachine(input2) {
77881
78063
  const machineId = input2.machineId ?? (await readMachineFile(input2.paths))?.machineId ?? (await readInstallation(input2.paths))?.machineId;
@@ -77958,13 +78140,13 @@ async function enrollFromGrantFile(input2) {
77958
78140
  clock: input2.clock,
77959
78141
  access: input2.access
77960
78142
  });
77961
- await (0, import_promises79.rm)(input2.grantPath, { force: true });
78143
+ await (0, import_promises80.rm)(input2.grantPath, { force: true });
77962
78144
  return machine;
77963
78145
  }
77964
78146
 
77965
78147
  // src/identity/migrate-v1.ts
77966
- var import_promises80 = require("fs/promises");
77967
- var import_node_path96 = require("path");
78148
+ var import_promises81 = require("fs/promises");
78149
+ var import_node_path97 = require("path");
77968
78150
  init_runtime_v2();
77969
78151
  init_zod();
77970
78152
  var EXIT_POLL_MS = 200;
@@ -77987,11 +78169,11 @@ var ownerLeaseSchema = external_exports.looseObject({ pid: external_exports.numb
77987
78169
  function legacyConfigPath(home, profile) {
77988
78170
  switch (profile) {
77989
78171
  case "production":
77990
- return (0, import_node_path96.join)(home, ".alan", "agent", "config.json");
78172
+ return (0, import_node_path97.join)(home, ".alan", "agent", "config.json");
77991
78173
  case "staging":
77992
- return (0, import_node_path96.join)(home, ".alan-staging", "agent", "config.json");
78174
+ return (0, import_node_path97.join)(home, ".alan-staging", "agent", "config.json");
77993
78175
  default:
77994
- return (0, import_node_path96.join)(home, ".alan-dev", "agent", "config.json");
78176
+ return (0, import_node_path97.join)(home, ".alan-dev", "agent", "config.json");
77995
78177
  }
77996
78178
  }
77997
78179
  async function findLegacyInstall(home, profile) {
@@ -78049,12 +78231,12 @@ async function scrubLegacyInstall(install2) {
78049
78231
  const scrubbed = { ...install2.config, migratedToRuntimeV2: true };
78050
78232
  for (const key of SCRUBBED_KEYS) delete scrubbed[key];
78051
78233
  await writeJsonFileAtomic(`${install2.configPath}.migrated-v1`, scrubbed);
78052
- await (0, import_promises80.rm)(install2.configPath, { force: true });
78053
- await (0, import_promises80.rm)(install2.ownerLeasePath, { force: true });
78234
+ await (0, import_promises81.rm)(install2.configPath, { force: true });
78235
+ await (0, import_promises81.rm)(install2.ownerLeasePath, { force: true });
78054
78236
  }
78055
78237
  async function retireLegacyInstall(install2) {
78056
- await (0, import_promises80.rename)(install2.configPath, `${install2.configPath}.retired-v1`);
78057
- await (0, import_promises80.rm)(install2.ownerLeasePath, { force: true });
78238
+ await (0, import_promises81.rename)(install2.configPath, `${install2.configPath}.retired-v1`);
78239
+ await (0, import_promises81.rm)(install2.ownerLeasePath, { force: true });
78058
78240
  }
78059
78241
  async function exchangeCredential(deps) {
78060
78242
  const { config: config2 } = deps.install;
@@ -78168,7 +78350,7 @@ async function loadIdentity(paths, options = {}) {
78168
78350
  }
78169
78351
 
78170
78352
  // src/cli/commands/status.ts
78171
- var import_node_path97 = require("path");
78353
+ var import_node_path98 = require("path");
78172
78354
  async function serviceStatus(ctx) {
78173
78355
  try {
78174
78356
  return await createServiceManager(ctx.host, ctx.config.profile).status();
@@ -78195,7 +78377,7 @@ async function runtimeState(ctx) {
78195
78377
  const running = await readRunningRuntime(ctx.paths.lock);
78196
78378
  if (running === null) return { state: "offline", pid: null, localApi: null };
78197
78379
  const discovery = await readJsonFile(
78198
- (0, import_node_path97.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE),
78380
+ (0, import_node_path98.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE),
78199
78381
  localApiDiscoverySchema
78200
78382
  );
78201
78383
  const localApi = discovery.kind === "ok" && discovery.value.pid === running.pid ? {
@@ -78416,7 +78598,7 @@ async function runtimeCheck(ctx, status) {
78416
78598
  return check2("runtime", "warn", "No runtime is running for this profile");
78417
78599
  }
78418
78600
  const client = createRuntimeClient({
78419
- discoveryPath: (0, import_node_path98.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE)
78601
+ discoveryPath: (0, import_node_path99.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE)
78420
78602
  });
78421
78603
  try {
78422
78604
  const live = await client.status(AbortSignal.timeout(LOCAL_TIMEOUT_MS));
@@ -78443,7 +78625,7 @@ async function runtimeCheck(ctx, status) {
78443
78625
  }
78444
78626
  }
78445
78627
  async function probeHolder(dir, conversationId) {
78446
- const launch = await readJsonFile((0, import_node_path98.join)(dir, "launch.json"), holderLaunchSchema);
78628
+ const launch = await readJsonFile((0, import_node_path99.join)(dir, "launch.json"), holderLaunchSchema);
78447
78629
  if (launch.kind !== "ok") return null;
78448
78630
  try {
78449
78631
  const reply2 = await withTimeout(
@@ -78468,8 +78650,8 @@ async function probeHolder(dir, conversationId) {
78468
78650
  }
78469
78651
  }
78470
78652
  async function holdersCheck(ctx) {
78471
- const names = await (0, import_promises81.readdir)(ctx.paths.sessions).catch(() => []);
78472
- const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path98.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
78653
+ const names = await (0, import_promises82.readdir)(ctx.paths.sessions).catch(() => []);
78654
+ const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path99.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
78473
78655
  const dead = holders.filter((holder) => !holder.alive).length;
78474
78656
  return check2(
78475
78657
  "holders",
@@ -78480,10 +78662,10 @@ async function holdersCheck(ctx) {
78480
78662
  }
78481
78663
  async function freeBytesAt(path4) {
78482
78664
  try {
78483
- const stats = await (0, import_promises81.statfs)(path4);
78665
+ const stats = await (0, import_promises82.statfs)(path4);
78484
78666
  return { path: path4, freeBytes: stats.bavail * stats.bsize };
78485
78667
  } catch (error62) {
78486
- const parent = (0, import_node_path98.dirname)(path4);
78668
+ const parent = (0, import_node_path99.dirname)(path4);
78487
78669
  if (parent === path4) throw error62;
78488
78670
  return freeBytesAt(parent);
78489
78671
  }
@@ -78619,7 +78801,7 @@ async function runDoctor(argv, context = cliContext) {
78619
78801
  }
78620
78802
 
78621
78803
  // src/cli/commands/git-credential.ts
78622
- var import_promises82 = require("fs/promises");
78804
+ var import_promises83 = require("fs/promises");
78623
78805
  var import_node_net4 = require("net");
78624
78806
  var MAX_RESPONSE_BYTES = 64 * 1024;
78625
78807
  async function readAll2(stream) {
@@ -78736,7 +78918,7 @@ async function configure(argv) {
78736
78918
  }
78737
78919
  async function configureGitGateway(config2, gatewayUrl, signal) {
78738
78920
  const { launcher } = installLayout(config2.installDir, config2.profile);
78739
- const installed = await (0, import_promises82.access)(launcher).then(
78921
+ const installed = await (0, import_promises83.access)(launcher).then(
78740
78922
  () => true,
78741
78923
  () => false
78742
78924
  );
@@ -78765,18 +78947,18 @@ async function runGitCredential(argv) {
78765
78947
  }
78766
78948
 
78767
78949
  // src/cli/commands/hold.ts
78768
- var import_node_path100 = require("path");
78950
+ var import_node_path101 = require("path");
78769
78951
  init_agent2();
78770
78952
  init_runtime_v2();
78771
78953
 
78772
78954
  // src/cli/commands/cli-flag-probes.ts
78773
- var import_node_path99 = require("path");
78955
+ var import_node_path100 = require("path");
78774
78956
  init_process();
78775
78957
  init_claude();
78776
78958
  var CLI_FLAG_PROBES_FILE = "cli-flag-probes.json";
78777
78959
  function openCliFlagProbe(stateDir) {
78778
78960
  return createFlagProbe({
78779
- store: createFileFlagProbeStore((0, import_node_path99.join)(stateDir, CLI_FLAG_PROBES_FILE))
78961
+ store: createFileFlagProbeStore((0, import_node_path100.join)(stateDir, CLI_FLAG_PROBES_FILE))
78780
78962
  });
78781
78963
  }
78782
78964
  async function prewarmCliFlagProbes(stateDir, env) {
@@ -78847,7 +79029,7 @@ async function runHold(argv) {
78847
79029
  const config2 = loadRuntimeConfig();
78848
79030
  const paths = runtimePaths(config2.stateDir);
78849
79031
  const log = __using(_stack, openFileLog(
78850
- (0, import_node_path100.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
79032
+ (0, import_node_path101.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
78851
79033
  config2.logLevel,
78852
79034
  systemClock
78853
79035
  ));
@@ -78856,16 +79038,25 @@ async function runHold(argv) {
78856
79038
  process.argv[1],
78857
79039
  process.platform
78858
79040
  );
79041
+ const commitAttribution = await installCommitAttribution({
79042
+ dir: (0, import_node_path101.join)(paths.stateDir, "git-attribution"),
79043
+ env: cliEnvironment,
79044
+ platform: process.platform
79045
+ }).catch((error62) => {
79046
+ log.warn("holder.commit_attribution_unavailable", { error: error62 });
79047
+ return null;
79048
+ });
79049
+ const agentEnvironment = commitAttribution?.env ?? cliEnvironment;
78859
79050
  const transport = __using(_stack, createHttpTransport());
78860
79051
  const access8 = await machineAccess(paths, log, launch.value.conversationId, transport);
78861
- const credentialPath = (0, import_node_path100.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
79052
+ const credentialPath = (0, import_node_path101.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
78862
79053
  const managedMcp = __using(_stack, access8.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
78863
79054
  managedMcp: access8.managedMcp,
78864
79055
  conversationId: launch.value.conversationId,
78865
79056
  credentialPath
78866
79057
  }), true);
78867
- const providerEnvironment2 = access8.managedMcp === void 0 ? cliEnvironment : {
78868
- ...cliEnvironment,
79058
+ const providerEnvironment2 = access8.managedMcp === void 0 ? agentEnvironment : {
79059
+ ...agentEnvironment,
78869
79060
  [ALAN_MCP_URL_ENV]: access8.managedMcp.url,
78870
79061
  [ALAN_MCP_CREDENTIAL_FILE_ENV]: credentialPath
78871
79062
  };
@@ -78884,7 +79075,11 @@ async function runHold(argv) {
78884
79075
  }),
78885
79076
  clock: systemClock,
78886
79077
  log,
78887
- inputs: { source: access8.source, tmpDir: paths.tmp },
79078
+ inputs: {
79079
+ source: access8.source,
79080
+ tmpDir: paths.tmp,
79081
+ ...commitAttribution === null ? {} : { commitAttribution }
79082
+ },
78888
79083
  machine: {
78889
79084
  env: cliEnvironment,
78890
79085
  stateDir: paths.stateDir,
@@ -78905,7 +79100,7 @@ async function runHold(argv) {
78905
79100
  }
78906
79101
 
78907
79102
  // src/cli/commands/hook.ts
78908
- var import_node_path101 = require("path");
79103
+ var import_node_path102 = require("path");
78909
79104
  var RUNTIME_ANSWER_MS = 2e3;
78910
79105
  var DEBUG_VARIABLE = "ALAN_HOOK_DEBUG";
78911
79106
  function flag(argv, name) {
@@ -78937,7 +79132,7 @@ async function forwardHook(argv, io) {
78937
79132
  return "transcript outside provider root";
78938
79133
  }
78939
79134
  const verdict = await io.send(
78940
- (0, import_node_path101.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
79135
+ (0, import_node_path102.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
78941
79136
  hookSignal,
78942
79137
  AbortSignal.timeout(RUNTIME_ANSWER_MS)
78943
79138
  );
@@ -78973,7 +79168,7 @@ async function runHook(argv, overrides = {}) {
78973
79168
  }
78974
79169
 
78975
79170
  // src/cli/commands/ingestion-hooks.ts
78976
- var import_promises83 = require("fs/promises");
79171
+ var import_promises84 = require("fs/promises");
78977
79172
  var CODEX_TRUST_NOTE = "Codex runs new hooks only after you review them: open /hooks in Codex.";
78978
79173
  function isAction(value2) {
78979
79174
  return value2 === "enable" || value2 === "disable" || value2 === "status";
@@ -78996,7 +79191,7 @@ function errorMessage2(error62) {
78996
79191
  return error62 instanceof Error ? error62.message : String(error62);
78997
79192
  }
78998
79193
  async function exists5(path4) {
78999
- return (0, import_promises83.access)(path4).then(
79194
+ return (0, import_promises84.access)(path4).then(
79000
79195
  () => true,
79001
79196
  () => false
79002
79197
  );
@@ -79099,10 +79294,10 @@ async function runIntegrationsCommand(argv) {
79099
79294
  }
79100
79295
 
79101
79296
  // src/cli/commands/legacy.ts
79102
- var import_node_path103 = require("path");
79297
+ var import_node_path104 = require("path");
79103
79298
 
79104
79299
  // src/cli/commands/setup.ts
79105
- var import_node_path102 = require("path");
79300
+ var import_node_path103 = require("path");
79106
79301
  init_zod();
79107
79302
 
79108
79303
  // src/cli/legacy.ts
@@ -79208,7 +79403,7 @@ async function grantFileCredential(argv, grantPath, ctx, deps) {
79208
79403
  return enrollFromGrantFile({
79209
79404
  paths: ctx.paths,
79210
79405
  storeKind: credentialStoreFlag(argv) ?? ctx.config.credentialStore,
79211
- grantPath: (0, import_node_path102.resolve)(grantPath),
79406
+ grantPath: (0, import_node_path103.resolve)(grantPath),
79212
79407
  clock: deps.clock,
79213
79408
  access: ctx.access
79214
79409
  });
@@ -79284,7 +79479,7 @@ async function runSetup(argv, signal) {
79284
79479
  var _stack = [];
79285
79480
  try {
79286
79481
  const ctx = cliContext();
79287
- const log = __using(_stack, openFileLog((0, import_node_path102.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
79482
+ const log = __using(_stack, openFileLog((0, import_node_path103.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
79288
79483
  const result = await setupMachine(argv, ctx, {
79289
79484
  enrollment: (apiUrl) => createEnrollmentClient({ apiUrl }),
79290
79485
  isProcessAlive,
@@ -79367,7 +79562,7 @@ async function runToken(argv, signal) {
79367
79562
  );
79368
79563
  }
79369
79564
  const ctx = cliContext();
79370
- const log = __using(_stack, openFileLog((0, import_node_path103.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
79565
+ const log = __using(_stack, openFileLog((0, import_node_path104.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
79371
79566
  const result = await rotateMachineCredential(ctx, { clock: systemClock, log, signal });
79372
79567
  process.stdout.write(`${rotationMessage(result)}
79373
79568
  `);
@@ -79379,8 +79574,8 @@ async function runToken(argv, signal) {
79379
79574
  }
79380
79575
 
79381
79576
  // src/cli/commands/logout.ts
79382
- var import_promises84 = require("fs/promises");
79383
- var import_node_path104 = require("path");
79577
+ var import_promises85 = require("fs/promises");
79578
+ var import_node_path105 = require("path");
79384
79579
  init_runtime_v2();
79385
79580
  var RUNTIME_EXIT_WAIT_MS = 35e3;
79386
79581
  var TURN_END_WAIT_MS = 3e4;
@@ -79439,9 +79634,9 @@ async function stopHolder(launch, deps, outcome2) {
79439
79634
  }
79440
79635
  async function stopHeldRuns(ctx, deps, outcome2 = "aborted") {
79441
79636
  const stopped = [];
79442
- for (const name of await (0, import_promises84.readdir)(ctx.paths.sessions).catch(() => [])) {
79637
+ for (const name of await (0, import_promises85.readdir)(ctx.paths.sessions).catch(() => [])) {
79443
79638
  const launch = await readJsonFile(
79444
- (0, import_node_path104.join)(ctx.paths.sessions, name, "launch.json"),
79639
+ (0, import_node_path105.join)(ctx.paths.sessions, name, "launch.json"),
79445
79640
  holderLaunchSchema
79446
79641
  );
79447
79642
  if (launch.kind !== "ok") continue;
@@ -79478,13 +79673,13 @@ async function forgetMachineLocally(ctx) {
79478
79673
  const machine = await readMachineFile(ctx.paths);
79479
79674
  if (machine === null) return;
79480
79675
  await credentialStoreFor(ctx.paths, machine.credentialStore, ctx.access).clear();
79481
- await (0, import_promises84.rm)(ctx.paths.machine, { force: true });
79676
+ await (0, import_promises85.rm)(ctx.paths.machine, { force: true });
79482
79677
  }
79483
79678
  async function runLogout(argv, signal) {
79484
79679
  var _stack = [];
79485
79680
  try {
79486
79681
  const ctx = cliContext();
79487
- const log = __using(_stack, openFileLog((0, import_node_path104.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
79682
+ const log = __using(_stack, openFileLog((0, import_node_path105.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
79488
79683
  const result = await logoutMachine(argv, ctx, {
79489
79684
  api: (apiUrl, accessToken) => createApiClient({ apiUrl, accessToken }),
79490
79685
  stopHeldRuns,
@@ -79502,7 +79697,7 @@ async function runLogout(argv, signal) {
79502
79697
 
79503
79698
  // src/cli/commands/run.ts
79504
79699
  var import_node_fs39 = require("fs");
79505
- var import_node_path109 = require("path");
79700
+ var import_node_path110 = require("path");
79506
79701
  init_process();
79507
79702
 
79508
79703
  // src/local-api/app-attachments.ts
@@ -79579,18 +79774,18 @@ function createRunAppends() {
79579
79774
  }
79580
79775
 
79581
79776
  // src/local-api/server.ts
79582
- var import_node_crypto56 = require("crypto");
79583
- var import_promises85 = require("fs/promises");
79777
+ var import_node_crypto57 = require("crypto");
79778
+ var import_promises86 = require("fs/promises");
79584
79779
  var import_node_http6 = require("http");
79585
- var import_node_path105 = require("path");
79780
+ var import_node_path106 = require("path");
79586
79781
 
79587
79782
  // src/local-api/guard.ts
79588
- var import_node_crypto55 = require("crypto");
79783
+ var import_node_crypto56 = require("crypto");
79589
79784
  var ALLOWED = { kind: "allowed" };
79590
79785
  function tokenMatches3(expected, header) {
79591
79786
  if (header === void 0 || !header.startsWith("Bearer ")) return false;
79592
79787
  const presented = Buffer.from(header.slice("Bearer ".length));
79593
- return presented.length === expected.length && (0, import_node_crypto55.timingSafeEqual)(presented, expected);
79788
+ return presented.length === expected.length && (0, import_node_crypto56.timingSafeEqual)(presented, expected);
79594
79789
  }
79595
79790
  function isBrowserReachable(req, allowedHosts) {
79596
79791
  if (req.headers.origin !== void 0 || req.headers.referer !== void 0) return true;
@@ -80605,7 +80800,7 @@ async function serveLocalApi(deps) {
80605
80800
  server.keepAliveTimeout = KEEP_ALIVE_TIMEOUT_MS;
80606
80801
  server.maxConnections = HARD_MAX_CONNECTIONS;
80607
80802
  const port = await listenOnLoopback(server);
80608
- const token = (0, import_node_crypto56.randomBytes)(32).toString("base64url");
80803
+ const token = (0, import_node_crypto57.randomBytes)(32).toString("base64url");
80609
80804
  const guard = createRequestGuard({ token, port, rateLimit: limits.rateLimit, clock });
80610
80805
  const appAttachments = createAppAttachments(clock);
80611
80806
  const routeDeps = {
@@ -80653,7 +80848,7 @@ async function serveLocalApi(deps) {
80653
80848
  startedAtMs,
80654
80849
  runtimeVersion: deps.runtimeVersion
80655
80850
  };
80656
- const discoveryPath = (0, import_node_path105.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
80851
+ const discoveryPath = (0, import_node_path106.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
80657
80852
  await writeJsonFileAtomic(discoveryPath, discovery);
80658
80853
  const followers = startMaintenance({
80659
80854
  everyMs: limits.refreshEveryMs,
@@ -80687,7 +80882,7 @@ async function serveLocalApi(deps) {
80687
80882
  await watchedStatus[Symbol.asyncDispose]();
80688
80883
  const current = await readJsonFile(discoveryPath, localApiDiscoverySchema);
80689
80884
  if (current.kind === "ok" && current.value.token === token) {
80690
- await (0, import_promises85.rm)(discoveryPath, { force: true });
80885
+ await (0, import_promises86.rm)(discoveryPath, { force: true });
80691
80886
  }
80692
80887
  await closeServer(server);
80693
80888
  log.info("local_api.closed", {});
@@ -80772,7 +80967,7 @@ function machineFeatureActions(deps) {
80772
80967
  }
80773
80968
 
80774
80969
  // src/cli/commands/machine-plane.ts
80775
- var import_node_path108 = require("path");
80970
+ var import_node_path109 = require("path");
80776
80971
 
80777
80972
  // src/link/index.ts
80778
80973
  init_runtime_v2();
@@ -84440,7 +84635,7 @@ function refusalFailure(refusal2) {
84440
84635
  }
84441
84636
 
84442
84637
  // src/link/probe.ts
84443
- var import_promises86 = require("dns/promises");
84638
+ var import_promises87 = require("dns/promises");
84444
84639
  var import_node_net5 = require("net");
84445
84640
  var import_node_tls2 = require("tls");
84446
84641
  var PROBE_TIMEOUT_MS4 = 5e3;
@@ -84476,7 +84671,7 @@ async function connectOnce(url3, clock) {
84476
84671
  }
84477
84672
  async function probeEndpoint(url3, clock) {
84478
84673
  try {
84479
- await (0, import_promises86.lookup)(url3.hostname);
84674
+ await (0, import_promises87.lookup)(url3.hostname);
84480
84675
  } catch (error62) {
84481
84676
  const reason = classifyTransportFailure(error62);
84482
84677
  return reason === "other" ? "dns" : reason;
@@ -84886,11 +85081,17 @@ function planReconcile(desired, held, stopRunIds = []) {
84886
85081
  }
84887
85082
  return actions;
84888
85083
  }
85084
+ function orphanedRuns(conversationId, desired, held) {
85085
+ const desiredIds = new Set(desired.map((run2) => run2.runId));
85086
+ return held.filter(
85087
+ (run2) => run2.conversationId === conversationId && run2.state !== "ended" && !desiredIds.has(run2.runId)
85088
+ ).map((run2) => run2.runId);
85089
+ }
84889
85090
 
84890
85091
  // src/reconciler/desired-sync.ts
84891
- var import_node_crypto57 = require("crypto");
85092
+ var import_node_crypto58 = require("crypto");
84892
85093
  function fingerprintOf(desired) {
84893
- return (0, import_node_crypto57.createHash)("sha256").update(JSON.stringify(desired)).digest("hex");
85094
+ return (0, import_node_crypto58.createHash)("sha256").update(JSON.stringify(desired)).digest("hex");
84894
85095
  }
84895
85096
  var FAILED_READ_RETRY_MS = 3e4;
84896
85097
  function createDesiredSync(deps) {
@@ -84961,8 +85162,12 @@ function createDesiredSync(deps) {
84961
85162
  }
84962
85163
 
84963
85164
  // src/reconciler/index.ts
84964
- function createReconciler(host, lifecycle, log, signal) {
85165
+ var BUSY_TAKEOVER_MS = 2 * 6e4;
85166
+ var BUSY_REPORT_AFTER_MS = 15e3;
85167
+ function createReconciler(host, lifecycle, log, signal, clock = systemClock) {
84965
85168
  let latest = null;
85169
+ const busySince = /* @__PURE__ */ new Map();
85170
+ let behindBusy = /* @__PURE__ */ new Map();
84966
85171
  let running = null;
84967
85172
  let waiting = /* @__PURE__ */ new Set();
84968
85173
  const apply = async (action) => {
@@ -85005,13 +85210,40 @@ function createReconciler(host, lifecycle, log, signal) {
85005
85210
  log.error("reconcile.action_failed", { kind: action.kind, error: error62 });
85006
85211
  }
85007
85212
  };
85213
+ const overdueBusy = (busy) => {
85214
+ const nowMs = clock.monotonic();
85215
+ for (const conversationId of [...busySince.keys()]) {
85216
+ if (!busy.has(conversationId)) busySince.delete(conversationId);
85217
+ }
85218
+ const overdue = [];
85219
+ for (const conversationId of busy) {
85220
+ const since = busySince.get(conversationId) ?? nowMs;
85221
+ busySince.set(conversationId, since);
85222
+ if (nowMs - since >= BUSY_TAKEOVER_MS) overdue.push(conversationId);
85223
+ }
85224
+ return overdue;
85225
+ };
85226
+ const takeOverBusyHolders = async (desired, held, holdback) => {
85227
+ for (const conversationId of overdueBusy(holdback.busy)) {
85228
+ for (const runId of orphanedRuns(conversationId, desired, held)) {
85229
+ if (signal.aborted) return;
85230
+ log.warn("reconcile.busy_takeover", { runId, conversationId });
85231
+ await runAction({ kind: "abort", runId }, holdback);
85232
+ }
85233
+ }
85234
+ };
85008
85235
  const reconcileOnce = async ({ desired, stopRunIds }) => {
85009
85236
  const holdback = { waiting: /* @__PURE__ */ new Set(), noFreeSlot: false, busy: /* @__PURE__ */ new Set() };
85010
85237
  const nowWaiting = holdback.waiting;
85011
- for (const action of planReconcile(desired, await host.heldRuns(), stopRunIds)) {
85238
+ const held = await host.heldRuns();
85239
+ for (const action of planReconcile(desired, held, stopRunIds)) {
85012
85240
  if (signal.aborted) return;
85013
85241
  await runAction(action, holdback);
85014
85242
  }
85243
+ await takeOverBusyHolders(desired, held, holdback);
85244
+ behindBusy = new Map(
85245
+ desired.filter((run2) => nowWaiting.has(run2.runId) && holdback.busy.has(run2.conversationId)).map((run2) => [run2.runId, run2.conversationId])
85246
+ );
85015
85247
  const newlyWaiting = [...nowWaiting].filter((runId) => !waiting.has(runId));
85016
85248
  if (newlyWaiting.length > 0) log.info("reconcile.waiting_for_slot", { runIds: newlyWaiting });
85017
85249
  waiting = nowWaiting;
@@ -85035,12 +85267,16 @@ function createReconciler(host, lifecycle, log, signal) {
85035
85267
  latest = { desired, stopRunIds };
85036
85268
  return kick();
85037
85269
  },
85038
- waitingRuns: () => waiting.size
85270
+ waitingRuns: () => waiting.size,
85271
+ busyRunIds: () => {
85272
+ const reportBefore = clock.monotonic() - BUSY_REPORT_AFTER_MS;
85273
+ return [...behindBusy].filter(([, conversationId]) => (busySince.get(conversationId) ?? Infinity) <= reportBefore).map(([runId]) => runId);
85274
+ }
85039
85275
  };
85040
85276
  }
85041
85277
 
85042
85278
  // src/uploader/index.ts
85043
- var import_promises87 = require("fs/promises");
85279
+ var import_promises88 = require("fs/promises");
85044
85280
  init_runtime_v2();
85045
85281
  init_zod();
85046
85282
  var RETRY_DELAYS_MS = [250, 500, 1e3, 2e3, 5e3, 1e4, 3e4];
@@ -85330,13 +85566,13 @@ function startUploader({
85330
85566
  const isDone = (runId) => sealed.has(runId) || archive?.has(runId) === true;
85331
85567
  const unsealedRunIds = async () => {
85332
85568
  const runIds = [];
85333
- for (const name of await (0, import_promises87.readdir)(runsDir).catch(() => [])) {
85569
+ for (const name of await (0, import_promises88.readdir)(runsDir).catch(() => [])) {
85334
85570
  const runId = runIdSchema.safeParse(name);
85335
85571
  if (runId.success && !isDone(runId.data)) runIds.push(runId.data);
85336
85572
  }
85337
85573
  return runIds;
85338
85574
  };
85339
- const hasProgress = async (runId) => await (0, import_promises87.stat)(runDirectory(runsDir, runId).upload).catch(() => null) !== null;
85575
+ const hasProgress = async (runId) => await (0, import_promises88.stat)(runDirectory(runsDir, runId).upload).catch(() => null) !== null;
85340
85576
  const sweep2 = async () => {
85341
85577
  for (const runId of await unsealedRunIds()) {
85342
85578
  if (!await hasProgress(runId)) run2(runId);
@@ -85352,13 +85588,13 @@ function startUploader({
85352
85588
  const dir = runDirectory(runsDir, runId);
85353
85589
  const progress = await readJsonFile(dir.upload, uploadProgressSchema);
85354
85590
  if (progress.kind !== "ok" || !progress.value.sealed) return false;
85355
- const sealedAt = (await (0, import_promises87.stat)(dir.upload)).mtimeMs;
85591
+ const sealedAt = (await (0, import_promises88.stat)(dir.upload)).mtimeMs;
85356
85592
  if (clock.now() - sealedAt < options.sealedForMs) return false;
85357
85593
  return (await readLastRecord(dir.log))?.update.sessionUpdate === "_alan/run.ended";
85358
85594
  };
85359
85595
  const archivable = async (options) => {
85360
85596
  const found = [];
85361
- for (const name of await (0, import_promises87.readdir)(runsDir).catch(() => [])) {
85597
+ for (const name of await (0, import_promises88.readdir)(runsDir).catch(() => [])) {
85362
85598
  const runId = runIdSchema.safeParse(name);
85363
85599
  if (!runId.success || archive?.has(runId.data)) continue;
85364
85600
  try {
@@ -85395,7 +85631,7 @@ function startUploader({
85395
85631
 
85396
85632
  // src/cli/commands/activity-lease.ts
85397
85633
  var import_node_fs38 = require("fs");
85398
- var import_node_path106 = require("path");
85634
+ var import_node_path107 = require("path");
85399
85635
  var import_node_worker_threads = require("worker_threads");
85400
85636
  init_runtime_v2();
85401
85637
  var LEASE_BUNDLE = "alan-lease.cjs";
@@ -85419,7 +85655,7 @@ function spawnThread(script, data) {
85419
85655
  };
85420
85656
  }
85421
85657
  function leaseWorkerScript(bundlePath, exists6 = import_node_fs38.existsSync) {
85422
- const lean = (0, import_node_path106.join)((0, import_node_path106.dirname)(bundlePath), LEASE_BUNDLE);
85658
+ const lean = (0, import_node_path107.join)((0, import_node_path107.dirname)(bundlePath), LEASE_BUNDLE);
85423
85659
  return exists6(lean) ? lean : bundlePath;
85424
85660
  }
85425
85661
  function leasedRuns(held) {
@@ -85439,7 +85675,7 @@ function startActivityLeases(deps) {
85439
85675
  epoch: Math.floor(clock.now()),
85440
85676
  sessionsDir: deps.paths.sessions,
85441
85677
  runsDir: deps.paths.runs,
85442
- logPath: (0, import_node_path106.join)(deps.paths.logs, "runtime.jsonl"),
85678
+ logPath: (0, import_node_path107.join)(deps.paths.logs, "runtime.jsonl"),
85443
85679
  logLevel: deps.logLevel,
85444
85680
  intervalMs: ACTIVITY_LEASE_INTERVAL_MS,
85445
85681
  watchdogMs: deps.watchdogMs,
@@ -85453,7 +85689,12 @@ function startActivityLeases(deps) {
85453
85689
  const sendSnapshot = async () => {
85454
85690
  if (state.disposed) return;
85455
85691
  const runs = leasedRuns(await deps.heldRuns());
85456
- current().postMessage({ type: "snapshot", accessToken: deps.accessToken(), runs });
85692
+ current().postMessage({
85693
+ type: "snapshot",
85694
+ accessToken: deps.accessToken(),
85695
+ runs,
85696
+ busyRunIds: deps.busyRunIds()
85697
+ });
85457
85698
  };
85458
85699
  const sendSoon = () => {
85459
85700
  sendSnapshot().catch((error62) => log.warn("activity_lease.snapshot_failed", { error: error62 }));
@@ -85679,12 +85920,12 @@ async function startMachineNativeIngest(deps) {
85679
85920
  }
85680
85921
 
85681
85922
  // src/cli/commands/run-updates.ts
85682
- var import_node_path107 = require("path");
85923
+ var import_node_path108 = require("path");
85683
85924
  init_runtime_v2();
85684
85925
  var UPDATE_CHECK_EVERY_MS = 6 * 60 * 60 * 1e3;
85685
85926
  var DEFERRED_RETRY_MS = 5 * 60 * 1e3;
85686
85927
  function isInstalledBundle(layout, bundlePath) {
85687
- return (0, import_node_path107.resolve)((0, import_node_path107.dirname)((0, import_node_path107.dirname)(bundlePath))) === (0, import_node_path107.resolve)(layout.versions);
85928
+ return (0, import_node_path108.resolve)((0, import_node_path108.dirname)((0, import_node_path108.dirname)(bundlePath))) === (0, import_node_path108.resolve)(layout.versions);
85688
85929
  }
85689
85930
  async function settleUpgradeOnStart({
85690
85931
  layout,
@@ -85791,7 +86032,7 @@ function startRuntimeUpdates(options) {
85791
86032
  layout,
85792
86033
  release: npmRelease,
85793
86034
  tarball: await options.downloader.download(npmRelease.dist.tarball, signal),
85794
- tmpDir: (0, import_node_path107.join)(layout.root, ".downloads")
86035
+ tmpDir: (0, import_node_path108.join)(layout.root, ".downloads")
85795
86036
  });
85796
86037
  await lifecycle.exclusive("upgrade", async () => {
85797
86038
  await recordPendingUpgrade(layout, currentVersion2, version2, clock.now());
@@ -86047,7 +86288,7 @@ async function startMachinePlane(deps) {
86047
86288
  [ALAN_MANAGED_SESSION_ENV]: "1"
86048
86289
  },
86049
86290
  cwd: paths.stateDir,
86050
- outputPath: (0, import_node_path108.join)(paths.logs, "holders.log")
86291
+ outputPath: (0, import_node_path109.join)(paths.logs, "holders.log")
86051
86292
  },
86052
86293
  deps.holderIsolation
86053
86294
  );
@@ -86080,6 +86321,7 @@ async function startMachinePlane(deps) {
86080
86321
  );
86081
86322
  sessionsOpened.resolve(sessions);
86082
86323
  boot.sessionsMs = elapsedMs();
86324
+ const reconcilerRef = { current: null };
86083
86325
  if (config2.activityLease) {
86084
86326
  const leases = stack.use(
86085
86327
  startActivityLeases({
@@ -86090,6 +86332,7 @@ async function startMachinePlane(deps) {
86090
86332
  watchdogMs: EVENT_LOOP_BLOCKED_AFTER_MS,
86091
86333
  bundlePath: deps.bundlePath,
86092
86334
  heldRuns: () => sessions.heldRuns(),
86335
+ busyRunIds: () => reconcilerRef.current?.busyRunIds() ?? [],
86093
86336
  renewCredential: async () => {
86094
86337
  await renewAfterRejection();
86095
86338
  },
@@ -86157,8 +86400,10 @@ async function startMachinePlane(deps) {
86157
86400
  },
86158
86401
  lifecycle,
86159
86402
  log,
86160
- stopped.signal
86403
+ stopped.signal,
86404
+ clock
86161
86405
  );
86406
+ reconcilerRef.current = reconciler;
86162
86407
  const updates = startRuntimeUpdates({
86163
86408
  enabled: config2.autoUpdate,
86164
86409
  layout: deps.install,
@@ -86325,7 +86570,7 @@ async function startMachinePlane(deps) {
86325
86570
  git: createGitRunner({ env: cliEnvironment }),
86326
86571
  clock,
86327
86572
  log,
86328
- dir: (0, import_node_path108.join)(paths.stateDir, "checkout-freshness")
86573
+ dir: (0, import_node_path109.join)(paths.stateDir, "checkout-freshness")
86329
86574
  },
86330
86575
  stopped.signal
86331
86576
  );
@@ -86632,7 +86877,7 @@ function lockWaitMs(argv) {
86632
86877
  }
86633
86878
  async function openManagedProviders(config2, paths) {
86634
86879
  const providerEnv = readCliEnvironment();
86635
- const bundledNpm = (0, import_node_path109.join)((0, import_node_path109.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
86880
+ const bundledNpm = (0, import_node_path110.join)((0, import_node_path110.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
86636
86881
  const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs39.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
86637
86882
  const npmPath = providerToolchain?.node ?? await resolveCommandOnPath("npm", providerEnv, process.platform);
86638
86883
  const npmOptions = npmPath === null || process.platform === "win32" && providerToolchain === null ? null : {
@@ -86640,7 +86885,7 @@ async function openManagedProviders(config2, paths) {
86640
86885
  ...providerToolchain === null ? {} : { argsBeforeNpm: [providerToolchain.npmCli] },
86641
86886
  env: providerEnv
86642
86887
  };
86643
- const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path109.dirname)(providerToolchain.node);
86888
+ const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path110.dirname)(providerToolchain.node);
86644
86889
  const probeEnv = providerNodeDir === void 0 ? providerEnv : {
86645
86890
  ...providerEnv,
86646
86891
  PATH: `${providerNodeDir}${pathDelimiter(process.platform)}${envValue(providerEnv, "PATH")}`
@@ -86650,7 +86895,7 @@ async function openManagedProviders(config2, paths) {
86650
86895
  throw new Error("Provider installer is unavailable on this computer");
86651
86896
  };
86652
86897
  const managed = createManagedProviderClis({
86653
- root: (0, import_node_path109.join)(paths.stateDir, "provider-clis"),
86898
+ root: (0, import_node_path110.join)(paths.stateDir, "provider-clis"),
86654
86899
  resolveVersion: npmOptions === null ? unavailable : createNpmVersionResolver(npmOptions),
86655
86900
  installPackage: npmOptions === null ? unavailable : createNpmPackageInstaller(npmOptions),
86656
86901
  probe: (executable, backendKind, signal) => probeManagedProvider(executable, backendKind, canonicalProbeEnv, signal)
@@ -86682,7 +86927,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
86682
86927
  waitMs: lockWaitMs(argv),
86683
86928
  signal: stop
86684
86929
  }));
86685
- const log = __using(_stack, openFileLog((0, import_node_path109.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
86930
+ const log = __using(_stack, openFileLog((0, import_node_path110.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
86686
86931
  const lifecycle = createLifecycleQueue({ clock, log });
86687
86932
  const install2 = installLayout(config2.installDir, config2.profile);
86688
86933
  const bundlePath = process.argv[1] ?? "";
@@ -86716,7 +86961,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
86716
86961
  openCliEnvironment({
86717
86962
  env: readCliEnvironment(),
86718
86963
  platform: process.platform,
86719
- lastKnownGoodFile: (0, import_node_path109.join)(paths.stateDir, "login-path.json"),
86964
+ lastKnownGoodFile: (0, import_node_path110.join)(paths.stateDir, "login-path.json"),
86720
86965
  clock,
86721
86966
  decorate: (env) => withPackagedAlanCodeEngine(env, bundlePath, process.platform)
86722
86967
  })
@@ -86893,17 +87138,17 @@ async function runServiceCommand(argv, ctx = cliContext()) {
86893
87138
  }
86894
87139
 
86895
87140
  // src/cli/commands/upgrade.ts
86896
- var import_promises88 = require("fs/promises");
86897
- var import_node_path110 = require("path");
87141
+ var import_promises89 = require("fs/promises");
87142
+ var import_node_path111 = require("path");
86898
87143
  function isNotNewer(version2, installed) {
86899
87144
  return installed !== null && isReleaseVersion(version2) && isReleaseVersion(installed) && compareVersions(version2, installed) <= 0;
86900
87145
  }
86901
87146
  async function installFromSource(source) {
86902
87147
  const { layout, from, ifNewer } = source;
86903
- const isTarball = (await (0, import_promises88.stat)(from)).isFile();
86904
- const downloads = (0, import_node_path110.join)(layout.root, ".downloads");
86905
- if (isTarball) await (0, import_promises88.mkdir)(downloads, { recursive: true, mode: 448 });
86906
- const scratch = isTarball ? await (0, import_promises88.mkdtemp)((0, import_node_path110.join)(downloads, "upgrade-")) : null;
87148
+ const isTarball = (await (0, import_promises89.stat)(from)).isFile();
87149
+ const downloads = (0, import_node_path111.join)(layout.root, ".downloads");
87150
+ if (isTarball) await (0, import_promises89.mkdir)(downloads, { recursive: true, mode: 448 });
87151
+ const scratch = isTarball ? await (0, import_promises89.mkdtemp)((0, import_node_path111.join)(downloads, "upgrade-")) : null;
86907
87152
  try {
86908
87153
  const sourceDir = scratch === null ? from : await extractPackageTarball(from, scratch);
86909
87154
  const version2 = await readPackageVersion(sourceDir);
@@ -86911,7 +87156,7 @@ async function installFromSource(source) {
86911
87156
  if (ifNewer && isNotNewer(version2, installed)) return { kind: "skipped", version: version2, installed };
86912
87157
  return { kind: "installed", ...await installVersion(layout, sourceDir) };
86913
87158
  } finally {
86914
- if (scratch !== null) await (0, import_promises88.rm)(scratch, { recursive: true, force: true });
87159
+ if (scratch !== null) await (0, import_promises89.rm)(scratch, { recursive: true, force: true });
86915
87160
  }
86916
87161
  }
86917
87162
  async function runUpgrade(argv) {
@@ -86923,7 +87168,7 @@ async function runUpgrade(argv) {
86923
87168
  const layout = installLayout(config2.installDir, config2.profile);
86924
87169
  const outcome2 = await installFromSource({
86925
87170
  layout,
86926
- from: (0, import_node_path110.resolve)(from),
87171
+ from: (0, import_node_path111.resolve)(from),
86927
87172
  ifNewer: hasFlag(argv, "--if-newer")
86928
87173
  });
86929
87174
  if (outcome2.kind === "skipped") {