@alan-ai-hq/agent-manager-darwin-arm64 0.1.165 → 0.1.166

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
@@ -20658,6 +20658,16 @@ var init_activity_lease = __esm({
20658
20658
  }
20659
20659
  });
20660
20660
 
20661
+ // ../shared/dist/constants/cloud-repositories.js
20662
+ var MAX_CLOUD_REPOSITORIES, CLOUD_REPOSITORY_LIMIT_MESSAGE;
20663
+ var init_cloud_repositories = __esm({
20664
+ "../shared/dist/constants/cloud-repositories.js"() {
20665
+ "use strict";
20666
+ MAX_CLOUD_REPOSITORIES = 64;
20667
+ CLOUD_REPOSITORY_LIMIT_MESSAGE = `Select at most ${MAX_CLOUD_REPOSITORIES} repositories per cloud session or environment`;
20668
+ }
20669
+ });
20670
+
20661
20671
  // ../shared/dist/runtime-v2/workspace.js
20662
20672
  function isMutatingWorkspaceQuery(request2) {
20663
20673
  return request2.method === "git.checkpoint" || request2.method === "git.push" || request2.method === "git.prepare_checkout";
@@ -20861,6 +20871,7 @@ var init_agent_context = __esm({
20861
20871
  "../shared/dist/runtime-v2/agent-context.js"() {
20862
20872
  "use strict";
20863
20873
  init_zod();
20874
+ init_cloud_repositories();
20864
20875
  init_workspace();
20865
20876
  AGENT_CONTEXT_VERSION = 1;
20866
20877
  AGENT_TEAM_INSTRUCTIONS_MAX_CHARS = 2e3;
@@ -20958,7 +20969,7 @@ var init_agent_context = __esm({
20958
20969
  status: external_exports.literal("unresolved"),
20959
20970
  /** A `repo=` value that names no repository in this environment. */
20960
20971
  requested: external_exports.string().min(1).max(200).optional(),
20961
- hints: external_exports.array(agentRepoHintSchema).max(64)
20972
+ hints: external_exports.array(agentRepoHintSchema).max(MAX_CLOUD_REPOSITORIES)
20962
20973
  }),
20963
20974
  external_exports.object({ status: external_exports.literal("none") })
20964
20975
  ]);
@@ -20985,7 +20996,7 @@ var init_agent_context = __esm({
20985
20996
  teamInstructions: external_exports.string().min(1).max(AGENT_TEAM_INSTRUCTIONS_MAX_CHARS).optional(),
20986
20997
  taskWorkingBranch: gitBranchSchema.optional(),
20987
20998
  pullRequest: agentContextPullRequestSchema.optional(),
20988
- repositories: external_exports.array(agentContextRepositorySchema).max(64),
20999
+ repositories: external_exports.array(agentContextRepositorySchema).max(MAX_CLOUD_REPOSITORIES),
20989
21000
  environment: agentContextEnvironmentSchema.optional(),
20990
21001
  surface: agentContextSurfaceSchema.optional()
20991
21002
  });
@@ -21411,7 +21422,8 @@ var init_run_context = __esm({
21411
21422
  content: external_exports.string(),
21412
21423
  turnOrdinal: external_exports.number().int().nullable(),
21413
21424
  createdAt: external_exports.string().min(1),
21414
- clientMessageId: external_exports.string().min(1).optional()
21425
+ clientMessageId: external_exports.string().min(1).optional(),
21426
+ attachmentIds: external_exports.array(external_exports.string().min(1)).optional()
21415
21427
  }));
21416
21428
  canonicalAssistantMessageSchema = wire()(external_exports.object({
21417
21429
  id: external_exports.string().min(1),
@@ -21530,6 +21542,7 @@ var init_desired_state = __esm({
21530
21542
  "../shared/dist/runtime-v2/desired-state.js"() {
21531
21543
  "use strict";
21532
21544
  init_zod();
21545
+ init_cloud_repositories();
21533
21546
  init_contracts();
21534
21547
  init_agent_context();
21535
21548
  init_ids();
@@ -21565,7 +21578,7 @@ var init_desired_state = __esm({
21565
21578
  approvedWorkspacePaths: external_exports.array(external_exports.string().min(1)).optional(),
21566
21579
  repoLocalPaths: external_exports.array(repoLocalPathSchema).optional(),
21567
21580
  /** Applied once, at the conversation's first turn on a cloud sandbox; never moves local work. */
21568
- requestedCheckouts: external_exports.array(requestedCheckoutSchema).max(64).optional(),
21581
+ requestedCheckouts: external_exports.array(requestedCheckoutSchema).max(MAX_CLOUD_REPOSITORIES).optional(),
21569
21582
  agentContext: agentContextSchema.optional(),
21570
21583
  workflowId: external_exports.guid().optional(),
21571
21584
  workflowExecutionId: external_exports.guid().optional(),
@@ -23874,6 +23887,13 @@ var init_colors = __esm({
23874
23887
  }
23875
23888
  });
23876
23889
 
23890
+ // ../shared/dist/constants/comment-reactions.js
23891
+ var init_comment_reactions = __esm({
23892
+ "../shared/dist/constants/comment-reactions.js"() {
23893
+ "use strict";
23894
+ }
23895
+ });
23896
+
23877
23897
  // ../shared/dist/constants/conversations.js
23878
23898
  var init_conversations = __esm({
23879
23899
  "../shared/dist/constants/conversations.js"() {
@@ -24050,7 +24070,7 @@ var init_models = __esm({
24050
24070
  sortOrder: 140,
24051
24071
  upstreamModelId: "minimax/minimax-m3.1-flash",
24052
24072
  contextWindow: 1048576,
24053
- maxOutputTokens: 8192
24073
+ maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
24054
24074
  },
24055
24075
  {
24056
24076
  id: "minimax/minimax-m3",
@@ -24061,7 +24081,7 @@ var init_models = __esm({
24061
24081
  sortOrder: 150,
24062
24082
  upstreamModelId: "minimax/minimax-m3",
24063
24083
  contextWindow: 1048576,
24064
- maxOutputTokens: 16384
24084
+ maxOutputTokens: HARNESS_MAX_OUTPUT_TOKENS
24065
24085
  }
24066
24086
  ];
24067
24087
  DEFAULT_HARNESS_MODEL_ID = HARNESS_MODEL_SEEDS.find((model) => model.isDefault)?.id ?? HARNESS_MODEL_SEEDS[0].id;
@@ -24351,7 +24371,9 @@ var init_constants = __esm({
24351
24371
  init_agent();
24352
24372
  init_agent_package();
24353
24373
  init_branding();
24374
+ init_cloud_repositories();
24354
24375
  init_colors();
24376
+ init_comment_reactions();
24355
24377
  init_conversations();
24356
24378
  init_create_and_start();
24357
24379
  init_labels();
@@ -24927,16 +24949,23 @@ function attachChildren(nodes) {
24927
24949
  }
24928
24950
  }
24929
24951
  const parents = /* @__PURE__ */ new Map();
24952
+ const hidden = /* @__PURE__ */ new Set();
24930
24953
  for (const node2 of nodes) {
24931
24954
  const u = node2.event.update;
24932
24955
  const parentId = isRecord3(u._meta) ? u._meta["alan.dev/parentToolCallId"] : void 0;
24933
24956
  const parent = typeof parentId === "string" ? tools.get(parentId) : typeof u.terminalId === "string" ? terminals.get(u.terminalId) : void 0;
24934
24957
  if (parent)
24935
24958
  parents.set(node2, parent);
24936
- else if (typeof parentId === "string")
24937
- node2.issue = `Waiting for parent tool ${parentId}`;
24959
+ else if (typeof parentId === "string") {
24960
+ if (ORPHAN_VISIBLE_KINDS.has(u.sessionUpdate))
24961
+ node2.issue = `Waiting for parent tool ${parentId}`;
24962
+ else
24963
+ hidden.add(node2);
24964
+ }
24938
24965
  }
24939
24966
  return nodes.filter((node2) => {
24967
+ if (hidden.has(node2))
24968
+ return false;
24940
24969
  let ancestor = parents.get(node2);
24941
24970
  const seen = /* @__PURE__ */ new Set([node2]);
24942
24971
  while (ancestor) {
@@ -25106,7 +25135,7 @@ function retainTurn(turn, previous) {
25106
25135
  function isThought(node2) {
25107
25136
  return ["agent_thought", "agent_thought_chunk"].includes(node2.event.update.sessionUpdate);
25108
25137
  }
25109
- var preparedEntries;
25138
+ var preparedEntries, ORPHAN_VISIBLE_KINDS;
25110
25139
  var init_prepare_conversation_turns = __esm({
25111
25140
  "../shared/dist/agent/acp/presentation/prepare-conversation-turns.js"() {
25112
25141
  "use strict";
@@ -25116,6 +25145,14 @@ var init_prepare_conversation_turns = __esm({
25116
25145
  init_terminal_events();
25117
25146
  init_turn_artifacts();
25118
25147
  preparedEntries = /* @__PURE__ */ new WeakMap();
25148
+ ORPHAN_VISIBLE_KINDS = /* @__PURE__ */ new Set([
25149
+ "user_message",
25150
+ "agent_message",
25151
+ "tool_call_update",
25152
+ "terminal_update",
25153
+ "terminal_output_chunk",
25154
+ "notice"
25155
+ ]);
25119
25156
  }
25120
25157
  });
25121
25158
 
@@ -25441,6 +25478,42 @@ function restatesDispatchFailure(state, update) {
25441
25478
  state.notices[index] = { ...notice2, level: "error" };
25442
25479
  return true;
25443
25480
  }
25481
+ function itemsOf(value2) {
25482
+ return Array.isArray(value2) ? value2 : value2 == null ? [] : [value2];
25483
+ }
25484
+ function hasStringType(value2) {
25485
+ return typeof value2 === "object" && value2 !== null && "type" in value2 ? typeof value2.type === "string" : false;
25486
+ }
25487
+ function isContentBlock(value2) {
25488
+ return hasStringType(value2);
25489
+ }
25490
+ function isToolCallContent(value2) {
25491
+ return hasStringType(value2);
25492
+ }
25493
+ function isToolCallLocation(value2) {
25494
+ return typeof value2 === "object" && value2 !== null && "path" in value2 ? typeof value2.path === "string" : false;
25495
+ }
25496
+ function contentBlocks(value2) {
25497
+ return itemsOf(value2).flatMap((item) => {
25498
+ if (typeof item === "string")
25499
+ return [{ type: "text", text: item }];
25500
+ return isContentBlock(item) ? [item] : [];
25501
+ });
25502
+ }
25503
+ function toolCallContent(value2) {
25504
+ return itemsOf(value2).flatMap((item) => {
25505
+ if (typeof item === "string")
25506
+ return [{ type: "content", content: { type: "text", text: item } }];
25507
+ return isToolCallContent(item) ? [item] : [];
25508
+ });
25509
+ }
25510
+ function toolCallLocations(value2) {
25511
+ return itemsOf(value2).flatMap((item) => {
25512
+ if (typeof item === "string")
25513
+ return [{ path: item }];
25514
+ return isToolCallLocation(item) ? [item] : [];
25515
+ });
25516
+ }
25444
25517
  function applyContent(state, index, update) {
25445
25518
  const role = ROLE_BY_KIND[update.sessionUpdate];
25446
25519
  if (!role)
@@ -25456,14 +25529,11 @@ function applyContent(state, index, update) {
25456
25529
  }
25457
25530
  entry.lastUpdateIndex = state.updateCount;
25458
25531
  if (update.sessionUpdate.endsWith("_chunk")) {
25459
- const block2 = update.content;
25460
- if (block2)
25461
- entry.content.push(block2);
25532
+ entry.content.push(...contentBlocks(update.content));
25462
25533
  } else {
25463
25534
  const content = update.content;
25464
- if (content !== void 0) {
25465
- entry.content = content === null ? [] : Array.isArray(content) ? content : [content];
25466
- }
25535
+ if (content !== void 0)
25536
+ entry.content = contentBlocks(content);
25467
25537
  }
25468
25538
  if (update._meta !== void 0) {
25469
25539
  entry._meta = update._meta === null ? void 0 : { ...entry._meta, ...update._meta };
@@ -25505,9 +25575,7 @@ function applyTool(state, index, update) {
25505
25575
  }
25506
25576
  entry.lastUpdateIndex = state.updateCount;
25507
25577
  if (update.sessionUpdate === "tool_call_content_chunk") {
25508
- const block2 = update.content;
25509
- if (block2)
25510
- entry.content.push(block2);
25578
+ entry.content.push(...toolCallContent(update.content));
25511
25579
  return;
25512
25580
  }
25513
25581
  const u = update;
@@ -25522,9 +25590,9 @@ function applyTool(state, index, update) {
25522
25590
  if (u.status !== void 0 && !isSettled(entry.status))
25523
25591
  entry.status = u.status ?? "pending";
25524
25592
  if (u.content !== void 0)
25525
- entry.content = u.content ?? [];
25593
+ entry.content = toolCallContent(u.content);
25526
25594
  if (u.locations !== void 0)
25527
- entry.locations = u.locations ?? [];
25595
+ entry.locations = toolCallLocations(u.locations);
25528
25596
  if (u.rawInput !== void 0)
25529
25597
  entry.rawInput = u.rawInput;
25530
25598
  if (u.rawOutput !== void 0)
@@ -25534,7 +25602,7 @@ function applyTool(state, index, update) {
25534
25602
  }
25535
25603
  }
25536
25604
  function messageText2(entry) {
25537
- return entry.content.filter((b) => b.type === "text").map((b) => b.text).join("");
25605
+ return entry.content.filter((b) => b?.type === "text" && typeof b.text === "string").map((b) => b.text).join("");
25538
25606
  }
25539
25607
  var ROLE_BY_KIND, entryIndexes, AWAITING_TOOL_CALLS_META, IMPORTED_CONTENT_SUFFIX, SETTLED;
25540
25608
  var init_reduce = __esm({
@@ -25873,7 +25941,7 @@ function prepareConversationTurnRead(state) {
25873
25941
  continue;
25874
25942
  if (entry.status !== "completed" && entry.status !== "failed")
25875
25943
  continue;
25876
- const output2 = typeof entry.rawOutput === "string" ? entry.rawOutput : entry.content.flatMap((item) => item.type === "content" && item.content.type === "text" ? [item.content.text] : []).join("\n");
25944
+ const output2 = typeof entry.rawOutput === "string" ? entry.rawOutput : entry.content.flatMap((item) => item.type === "content" && item.content?.type === "text" ? [item.content.text] : []).join("\n");
25877
25945
  const response = output2.trim().toLowerCase();
25878
25946
  if (response === "accepted" && entry.status === "completed")
25879
25947
  modeChange = "agent";
@@ -56642,7 +56710,7 @@ var require_websocket = __commonJS({
56642
56710
  var http = require("http");
56643
56711
  var net = require("net");
56644
56712
  var tls = require("tls");
56645
- var { randomBytes: randomBytes6, createHash: createHash31 } = require("crypto");
56713
+ var { randomBytes: randomBytes7, createHash: createHash33 } = require("crypto");
56646
56714
  var { Duplex, Readable: Readable2 } = require("stream");
56647
56715
  var { URL: URL2 } = require("url");
56648
56716
  var PerMessageDeflate = require_permessage_deflate();
@@ -57169,7 +57237,7 @@ var require_websocket = __commonJS({
57169
57237
  }
57170
57238
  }
57171
57239
  const defaultPort = isSecure ? 443 : 80;
57172
- const key = randomBytes6(16).toString("base64");
57240
+ const key = randomBytes7(16).toString("base64");
57173
57241
  const request2 = isSecure ? https.request : http.request;
57174
57242
  const protocolSet = /* @__PURE__ */ new Set();
57175
57243
  let perMessageDeflate;
@@ -57299,7 +57367,7 @@ var require_websocket = __commonJS({
57299
57367
  abortHandshake(websocket, socket, "Invalid Upgrade header");
57300
57368
  return;
57301
57369
  }
57302
- const digest = createHash31("sha1").update(key + GUID).digest("base64");
57370
+ const digest = createHash33("sha1").update(key + GUID).digest("base64");
57303
57371
  if (res.headers["sec-websocket-accept"] !== digest) {
57304
57372
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
57305
57373
  return;
@@ -57666,7 +57734,7 @@ var require_websocket_server = __commonJS({
57666
57734
  var EventEmitter = require("events");
57667
57735
  var http = require("http");
57668
57736
  var { Duplex } = require("stream");
57669
- var { createHash: createHash31 } = require("crypto");
57737
+ var { createHash: createHash33 } = require("crypto");
57670
57738
  var extension = require_extension();
57671
57739
  var PerMessageDeflate = require_permessage_deflate();
57672
57740
  var subprotocol = require_subprotocol();
@@ -57963,7 +58031,7 @@ var require_websocket_server = __commonJS({
57963
58031
  );
57964
58032
  }
57965
58033
  if (this._state > RUNNING) return abortHandshake(socket, 503);
57966
- const digest = createHash31("sha1").update(key + GUID).digest("base64");
58034
+ const digest = createHash33("sha1").update(key + GUID).digest("base64");
57967
58035
  const headers = [
57968
58036
  "HTTP/1.1 101 Switching Protocols",
57969
58037
  "Upgrade: websocket",
@@ -58054,7 +58122,7 @@ var import_node_worker_threads2 = require("worker_threads");
58054
58122
  // package.json
58055
58123
  var package_default = {
58056
58124
  name: "@alan-ai-hq/agent-manager",
58057
- version: "0.1.165",
58125
+ version: "0.1.166",
58058
58126
  private: true,
58059
58127
  type: "module",
58060
58128
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -59981,10 +60049,25 @@ function socketsScope(socketsDir) {
59981
60049
  function ipcEndpoint(socketsDir, id, platform3 = process.platform) {
59982
60050
  if (platform3 === "win32") return windowsPipeName(socketsDir, id);
59983
60051
  const preferred = (0, import_node_path6.join)(socketsDir, `${id}.sock`);
59984
- const dir = Buffer.byteLength(preferred) <= MAX_SOCKET_PATH_BYTES ? socketsDir : (0, import_node_path6.join)("/tmp", `alan-${(0, import_node_os.userInfo)().uid}-${socketsScope(socketsDir)}`);
60052
+ if (Buffer.byteLength(preferred) <= MAX_SOCKET_PATH_BYTES) {
60053
+ (0, import_node_fs6.mkdirSync)(socketsDir, { recursive: true, mode: 448 });
60054
+ return preferred;
60055
+ }
60056
+ const { uid } = (0, import_node_os.userInfo)();
60057
+ const dir = (0, import_node_path6.join)("/tmp", `alan-${uid}-${socketsScope(socketsDir)}`);
59985
60058
  (0, import_node_fs6.mkdirSync)(dir, { recursive: true, mode: 448 });
60059
+ assertPrivateDirectory(dir, uid);
59986
60060
  return (0, import_node_path6.join)(dir, `${id}.sock`);
59987
60061
  }
60062
+ function assertPrivateDirectory(dir, uid) {
60063
+ const stat23 = (0, import_node_fs6.lstatSync)(dir);
60064
+ if (!stat23.isDirectory() || stat23.uid !== uid || (stat23.mode & 63) !== 0) {
60065
+ throw new RuntimeFault(
60066
+ "io_failed",
60067
+ `Refusing socket directory ${dir}: it must be a directory owned by uid ${uid} with mode 0700`
60068
+ );
60069
+ }
60070
+ }
59988
60071
  function removeStaleEndpoint(endpoint) {
59989
60072
  if (!endpoint.startsWith("\\\\.\\pipe\\")) (0, import_node_fs6.rmSync)(endpoint, { force: true });
59990
60073
  }
@@ -61972,8 +62055,8 @@ function startWakeClock(options) {
61972
62055
  }
61973
62056
 
61974
62057
  // src/cli/commands/activity-lease-producer.ts
61975
- var import_promises68 = require("fs/promises");
61976
- var import_node_path66 = require("path");
62058
+ var import_promises69 = require("fs/promises");
62059
+ var import_node_path67 = require("path");
61977
62060
  init_runtime_v2();
61978
62061
 
61979
62062
  // src/holder/activity-file.ts
@@ -63496,16 +63579,19 @@ function formatGitCredentialAnswer(capability, request2) {
63496
63579
  var GIT_CREDENTIAL_QUIT = "quit=1\n";
63497
63580
 
63498
63581
  // src/capabilities/git/credential-server.ts
63582
+ var import_node_crypto15 = require("crypto");
63583
+ var import_promises35 = require("fs/promises");
63499
63584
  var import_node_net2 = require("net");
63500
63585
 
63501
63586
  // src/capabilities/git/credential-socket.ts
63587
+ var import_node_path23 = require("path");
63502
63588
  init_zod();
63503
63589
  var GIT_CREDENTIAL_SOCKET_ID = "git-credential";
63504
63590
  var GIT_CREDENTIAL_HELPER_BUDGET_MS = 3500;
63505
63591
  var GIT_CAPABILITY_MINT_BUDGET_MS = 3e3;
63506
63592
  var gitCredentialSocketRequestSchema = external_exports.discriminatedUnion("op", [
63507
- external_exports.object({ op: external_exports.literal("get"), gatewayUrl: external_exports.string().min(1) }),
63508
- external_exports.object({ op: external_exports.literal("erase"), gatewayUrl: external_exports.string().min(1) })
63593
+ external_exports.object({ op: external_exports.literal("get"), gatewayUrl: external_exports.string().min(1), token: external_exports.string().min(1) }),
63594
+ external_exports.object({ op: external_exports.literal("erase"), gatewayUrl: external_exports.string().min(1), token: external_exports.string().min(1) })
63509
63595
  ]);
63510
63596
  var gitCredentialSocketResponseSchema = external_exports.discriminatedUnion("kind", [
63511
63597
  external_exports.object({
@@ -63520,6 +63606,12 @@ var gitCredentialSocketResponseSchema = external_exports.discriminatedUnion("kin
63520
63606
  function gitCredentialEndpoint(socketsDir) {
63521
63607
  return ipcEndpoint(socketsDir, GIT_CREDENTIAL_SOCKET_ID);
63522
63608
  }
63609
+ var gitCredentialTokenSchema = external_exports.object({
63610
+ token: external_exports.string().min(1)
63611
+ });
63612
+ function gitCredentialTokenPath(socketsDir) {
63613
+ return (0, import_node_path23.join)(socketsDir, `${GIT_CREDENTIAL_SOCKET_ID}.token`);
63614
+ }
63523
63615
 
63524
63616
  // src/capabilities/git/credential-server.ts
63525
63617
  function repositoryGatewayUrl(gatewayUrl) {
@@ -63623,6 +63715,11 @@ function parseRequest(line) {
63623
63715
  return null;
63624
63716
  }
63625
63717
  }
63718
+ function tokenMatches(expected, presented) {
63719
+ const a = (0, import_node_crypto15.createHash)("sha256").update(expected).digest();
63720
+ const b = (0, import_node_crypto15.createHash)("sha256").update(presented).digest();
63721
+ return (0, import_node_crypto15.timingSafeEqual)(a, b);
63722
+ }
63626
63723
  function reply(socket, response) {
63627
63724
  if (!socket.destroyed) socket.end(`${JSON.stringify(response)}
63628
63725
  `);
@@ -63630,6 +63727,9 @@ function reply(socket, response) {
63630
63727
  async function startGitCredentialServer(options) {
63631
63728
  const cache2 = createGitCapabilityCache(options);
63632
63729
  const closing = new AbortController();
63730
+ const token = (0, import_node_crypto15.randomBytes)(32).toString("base64url");
63731
+ const tokenFile = { token };
63732
+ await writeJsonFileAtomic(options.tokenPath, tokenFile);
63633
63733
  const answer = async (request2) => {
63634
63734
  if (request2.op === "erase") {
63635
63735
  cache2.forget(request2.gatewayUrl);
@@ -63641,7 +63741,7 @@ async function startGitCredentialServer(options) {
63641
63741
  socket.on("error", () => socket.destroy());
63642
63742
  readRequestLine(socket, (line) => {
63643
63743
  const request2 = parseRequest(line);
63644
- if (request2 === null) {
63744
+ if (request2 === null || !tokenMatches(token, request2.token)) {
63645
63745
  socket.destroy();
63646
63746
  return;
63647
63747
  }
@@ -63662,10 +63762,12 @@ async function startGitCredentialServer(options) {
63662
63762
  options.log.info("git.credential_server_listening", { endpoint: options.endpoint });
63663
63763
  return {
63664
63764
  endpoint: options.endpoint,
63765
+ tokenPath: options.tokenPath,
63665
63766
  [Symbol.asyncDispose]: async () => {
63666
63767
  closing.abort();
63667
63768
  await new Promise((resolve13) => server.close(() => resolve13()));
63668
63769
  removeStaleEndpoint(options.endpoint);
63770
+ await (0, import_promises35.rm)(options.tokenPath, { force: true });
63669
63771
  }
63670
63772
  };
63671
63773
  }
@@ -63714,9 +63816,9 @@ function createGit(options) {
63714
63816
 
63715
63817
  // src/capabilities/github-proxy/certificates.ts
63716
63818
  var import_node_child_process10 = require("child_process");
63717
- var import_node_crypto15 = require("crypto");
63718
- var import_promises35 = require("fs/promises");
63719
- var import_node_path23 = require("path");
63819
+ var import_node_crypto16 = require("crypto");
63820
+ var import_promises36 = require("fs/promises");
63821
+ var import_node_path24 = require("path");
63720
63822
  var OPENSSL_TIMEOUT_MS = 1e4;
63721
63823
  var VALIDITY_DAYS = "30";
63722
63824
  function opensslConfig(commonName) {
@@ -63752,14 +63854,14 @@ function openssl(args, cwd) {
63752
63854
  });
63753
63855
  }
63754
63856
  async function createGitHubProxyCertificates(stateDir) {
63755
- const work = (0, import_node_path23.join)(stateDir, "github-proxy");
63756
- await (0, import_promises35.rm)(work, { recursive: true, force: true });
63757
- await (0, import_promises35.mkdir)(work, { recursive: true, mode: 448 });
63857
+ const work = (0, import_node_path24.join)(stateDir, "github-proxy");
63858
+ await (0, import_promises36.rm)(work, { recursive: true, force: true });
63859
+ await (0, import_promises36.mkdir)(work, { recursive: true, mode: 448 });
63758
63860
  try {
63759
- await (0, import_promises35.writeFile)((0, import_node_path23.join)(work, "ca.cnf"), opensslConfig("Alan sandbox GitHub proxy CA"), {
63861
+ await (0, import_promises36.writeFile)((0, import_node_path24.join)(work, "ca.cnf"), opensslConfig("Alan sandbox GitHub proxy CA"), {
63760
63862
  mode: 384
63761
63863
  });
63762
- await (0, import_promises35.writeFile)((0, import_node_path23.join)(work, "leaf.cnf"), opensslConfig("github.com"), { mode: 384 });
63864
+ await (0, import_promises36.writeFile)((0, import_node_path24.join)(work, "leaf.cnf"), opensslConfig("github.com"), { mode: 384 });
63763
63865
  const curve = ["ecparam", "-name", "prime256v1", "-genkey", "-noout"];
63764
63866
  await openssl([...curve, "-out", "ca.key"], work);
63765
63867
  await openssl(
@@ -63779,24 +63881,24 @@ async function createGitHubProxyCertificates(stateDir) {
63779
63881
  work
63780
63882
  );
63781
63883
  await openssl(
63782
- ["x509", "-req", "-in", "leaf.csr", "-CA", "ca.pem", "-CAkey", "ca.key", "-sha256"].concat(["-set_serial", `0x${(0, import_node_crypto15.randomBytes)(16).toString("hex")}`, "-days", VALIDITY_DAYS]).concat(["-extfile", "leaf.cnf", "-extensions", "leaf", "-out", "leaf.pem"]),
63884
+ ["x509", "-req", "-in", "leaf.csr", "-CA", "ca.pem", "-CAkey", "ca.key", "-sha256"].concat(["-set_serial", `0x${(0, import_node_crypto16.randomBytes)(16).toString("hex")}`, "-days", VALIDITY_DAYS]).concat(["-extfile", "leaf.cnf", "-extensions", "leaf", "-out", "leaf.pem"]),
63783
63885
  work
63784
63886
  );
63785
- const caPath = (0, import_node_path23.join)(stateDir, "github-ca.pem");
63786
- await (0, import_promises35.writeFile)(caPath, await (0, import_promises35.readFile)((0, import_node_path23.join)(work, "ca.pem")), { mode: 384 });
63887
+ const caPath = (0, import_node_path24.join)(stateDir, "github-ca.pem");
63888
+ await (0, import_promises36.writeFile)(caPath, await (0, import_promises36.readFile)((0, import_node_path24.join)(work, "ca.pem")), { mode: 384 });
63787
63889
  return {
63788
63890
  caPath,
63789
- leafKeyPem: await (0, import_promises35.readFile)((0, import_node_path23.join)(work, "leaf.key"), "utf8"),
63790
- leafCertPem: await (0, import_promises35.readFile)((0, import_node_path23.join)(work, "leaf.pem"), "utf8")
63891
+ leafKeyPem: await (0, import_promises36.readFile)((0, import_node_path24.join)(work, "leaf.key"), "utf8"),
63892
+ leafCertPem: await (0, import_promises36.readFile)((0, import_node_path24.join)(work, "leaf.pem"), "utf8")
63791
63893
  };
63792
63894
  } finally {
63793
- await (0, import_promises35.rm)(work, { recursive: true, force: true });
63895
+ await (0, import_promises36.rm)(work, { recursive: true, force: true });
63794
63896
  }
63795
63897
  }
63796
63898
 
63797
63899
  // src/capabilities/github-proxy/config.ts
63798
- var import_promises36 = require("fs/promises");
63799
- var import_node_path24 = require("path");
63900
+ var import_promises37 = require("fs/promises");
63901
+ var import_node_path25 = require("path");
63800
63902
  init_runtime_v2();
63801
63903
  var GITHUB_URL = "https://github.com/";
63802
63904
  var GH_SOCKET_KEY = "http_unix_socket";
@@ -63812,10 +63914,10 @@ function withGhConfigKey(yaml, key, value2) {
63812
63914
  `;
63813
63915
  }
63814
63916
  async function configureGh(ghConfigDir, socketPath) {
63815
- await (0, import_promises36.mkdir)(ghConfigDir, { recursive: true, mode: 448 });
63816
- const path4 = (0, import_node_path24.join)(ghConfigDir, "config.yml");
63817
- const current = await (0, import_promises36.readFile)(path4, "utf8").catch(() => "");
63818
- await (0, import_promises36.writeFile)(path4, withGhConfigKey(current, GH_SOCKET_KEY, socketPath), { mode: 384 });
63917
+ await (0, import_promises37.mkdir)(ghConfigDir, { recursive: true, mode: 448 });
63918
+ const path4 = (0, import_node_path25.join)(ghConfigDir, "config.yml");
63919
+ const current = await (0, import_promises37.readFile)(path4, "utf8").catch(() => "");
63920
+ await (0, import_promises37.writeFile)(path4, withGhConfigKey(current, GH_SOCKET_KEY, socketPath), { mode: 384 });
63819
63921
  }
63820
63922
  async function configureGit(input2, git) {
63821
63923
  const run2 = async (args, allowedExitCodes = [0]) => {
@@ -63845,7 +63947,7 @@ async function configureGitHubProxyClients(input2) {
63845
63947
  }
63846
63948
 
63847
63949
  // src/capabilities/github-proxy/server.ts
63848
- var import_promises37 = require("fs/promises");
63950
+ var import_promises38 = require("fs/promises");
63849
63951
  var import_node_http3 = require("http");
63850
63952
  var import_node_tls = require("tls");
63851
63953
  init_runtime_v2();
@@ -63987,7 +64089,7 @@ async function startGitHubProxy(options) {
63987
64089
  });
63988
64090
  removeStaleEndpoint(options.socketPath);
63989
64091
  await listen(gh, options.socketPath);
63990
- await (0, import_promises37.chmod)(options.socketPath, 384);
64092
+ await (0, import_promises38.chmod)(options.socketPath, 384);
63991
64093
  const git = options.certificates === null ? null : await startGitListener(options.certificates, relay);
63992
64094
  options.log.info("github_proxy.listening", {
63993
64095
  socketPath: options.socketPath,
@@ -64005,9 +64107,9 @@ async function startGitHubProxy(options) {
64005
64107
  }
64006
64108
 
64007
64109
  // src/capabilities/mcp-config/mcp-config.ts
64008
- var import_node_crypto16 = require("crypto");
64009
- var import_promises38 = require("fs/promises");
64010
- var import_node_path25 = require("path");
64110
+ var import_node_crypto17 = require("crypto");
64111
+ var import_promises39 = require("fs/promises");
64112
+ var import_node_path26 = require("path");
64011
64113
 
64012
64114
  // ../../node_modules/smol-toml/dist/error.js
64013
64115
  function getLineColFromPtr(string4, ptr) {
@@ -64956,7 +65058,7 @@ function isCredentialFreeAlanEntry(entry, endpoint) {
64956
65058
  }
64957
65059
  async function isInstalled(cli, home) {
64958
65060
  try {
64959
- return (await (0, import_promises38.stat)((0, import_node_path25.join)(home, cli.guardDir))).isDirectory();
65061
+ return (await (0, import_promises39.stat)((0, import_node_path26.join)(home, cli.guardDir))).isDirectory();
64960
65062
  } catch (error62) {
64961
65063
  if (errorCode2(error62) === "ENOENT") return false;
64962
65064
  throw error62;
@@ -64964,7 +65066,7 @@ async function isInstalled(cli, home) {
64964
65066
  }
64965
65067
  async function readText3(path4) {
64966
65068
  try {
64967
- return await (0, import_promises38.readFile)(path4, "utf8");
65069
+ return await (0, import_promises39.readFile)(path4, "utf8");
64968
65070
  } catch (error62) {
64969
65071
  if (errorCode2(error62) === "ENOENT") return null;
64970
65072
  throw error62;
@@ -64977,7 +65079,7 @@ function parseRoot(cli, text3) {
64977
65079
  return value2;
64978
65080
  }
64979
65081
  async function readConfig(cli, home) {
64980
- const path4 = (0, import_node_path25.join)(home, cli.configPath);
65082
+ const path4 = (0, import_node_path26.join)(home, cli.configPath);
64981
65083
  const text3 = await readText3(path4);
64982
65084
  try {
64983
65085
  const root = text3 === null ? {} : parseRoot(cli, text3);
@@ -64989,12 +65091,12 @@ async function readConfig(cli, home) {
64989
65091
  }
64990
65092
  }
64991
65093
  async function writeConfig(path4, text3) {
64992
- const temporary = `${path4}.alan-${(0, import_node_crypto16.randomUUID)()}.tmp`;
65094
+ const temporary = `${path4}.alan-${(0, import_node_crypto17.randomUUID)()}.tmp`;
64993
65095
  try {
64994
- await (0, import_promises38.writeFile)(temporary, text3, { encoding: "utf8", mode: 384, flag: "wx" });
64995
- await (0, import_promises38.rename)(temporary, path4);
65096
+ await (0, import_promises39.writeFile)(temporary, text3, { encoding: "utf8", mode: 384, flag: "wx" });
65097
+ await (0, import_promises39.rename)(temporary, path4);
64996
65098
  } finally {
64997
- await (0, import_promises38.rm)(temporary, { force: true });
65099
+ await (0, import_promises39.rm)(temporary, { force: true });
64998
65100
  }
64999
65101
  }
65000
65102
  async function editCli(cli, home, endpoint, edit) {
@@ -65072,8 +65174,8 @@ async function inspectAlanMcp(options) {
65072
65174
  }
65073
65175
 
65074
65176
  // src/capabilities/models/opencode-models.ts
65075
- var import_promises39 = require("fs/promises");
65076
- var import_node_path26 = require("path");
65177
+ var import_promises40 = require("fs/promises");
65178
+ var import_node_path27 = require("path");
65077
65179
  init_runtime_v2();
65078
65180
  init_zod();
65079
65181
 
@@ -65386,9 +65488,9 @@ function openCodeCatalogueFrom(value2) {
65386
65488
  }
65387
65489
  async function readOpenCodeCatalogueCache(env) {
65388
65490
  const home = env.HOME?.trim();
65389
- const cacheHome = env.XDG_CACHE_HOME?.trim() || (home ? (0, import_node_path26.join)(home, ".cache") : "");
65491
+ const cacheHome = env.XDG_CACHE_HOME?.trim() || (home ? (0, import_node_path27.join)(home, ".cache") : "");
65390
65492
  if (cacheHome === "") return null;
65391
- const text3 = await (0, import_promises39.readFile)((0, import_node_path26.join)(cacheHome, ...CATALOGUE_CACHE_SEGMENTS), "utf8").catch(
65493
+ const text3 = await (0, import_promises40.readFile)((0, import_node_path27.join)(cacheHome, ...CATALOGUE_CACHE_SEGMENTS), "utf8").catch(
65392
65494
  () => void 0
65393
65495
  );
65394
65496
  if (text3 === void 0) return null;
@@ -65507,17 +65609,17 @@ async function discoverModels(backendKind, executable, env, capture) {
65507
65609
  }
65508
65610
 
65509
65611
  // src/capabilities/models/opencode-entitlement.ts
65510
- var import_promises40 = require("fs/promises");
65612
+ var import_promises41 = require("fs/promises");
65511
65613
  var import_node_os4 = require("os");
65512
- var import_node_path27 = require("path");
65614
+ var import_node_path28 = require("path");
65513
65615
  init_agent2();
65514
65616
  async function readOpenCodeZenCredential(env) {
65515
65617
  const direct = env.OPENCODE_API_KEY?.trim();
65516
65618
  if (direct) return direct;
65517
65619
  const injected = env.OPENCODE_AUTH_CONTENT?.trim();
65518
65620
  if (injected) return readZenCredentialFromAuthDocument(injected);
65519
- const dataHome = env.XDG_DATA_HOME?.trim() || (0, import_node_path27.join)(env.HOME?.trim() || (0, import_node_os4.homedir)(), ".local", "share");
65520
- const document2 = await (0, import_promises40.readFile)((0, import_node_path27.join)(dataHome, "opencode", "auth.json"), "utf8").catch(
65621
+ const dataHome = env.XDG_DATA_HOME?.trim() || (0, import_node_path28.join)(env.HOME?.trim() || (0, import_node_os4.homedir)(), ".local", "share");
65622
+ const document2 = await (0, import_promises41.readFile)((0, import_node_path28.join)(dataHome, "opencode", "auth.json"), "utf8").catch(
65521
65623
  () => void 0
65522
65624
  );
65523
65625
  return readZenCredentialFromAuthDocument(document2);
@@ -65567,24 +65669,24 @@ function fingerprintWholeText(fingerprint) {
65567
65669
 
65568
65670
  // src/capabilities/native-ingest/hook-config.ts
65569
65671
  var import_node_fs10 = require("fs");
65570
- var import_node_path29 = require("path");
65672
+ var import_node_path30 = require("path");
65571
65673
 
65572
65674
  // src/capabilities/native-ingest/provider-paths.ts
65573
- var import_node_path28 = require("path");
65675
+ var import_node_path29 = require("path");
65574
65676
  function providerConfigDir(provider4, where) {
65575
65677
  if (provider4 === "claude") {
65576
- return where.env.CLAUDE_CONFIG_DIR?.trim() || (0, import_node_path28.join)(where.home, ".claude");
65678
+ return where.env.CLAUDE_CONFIG_DIR?.trim() || (0, import_node_path29.join)(where.home, ".claude");
65577
65679
  }
65578
- return where.env.CODEX_HOME?.trim() || (0, import_node_path28.join)(where.home, ".codex");
65680
+ return where.env.CODEX_HOME?.trim() || (0, import_node_path29.join)(where.home, ".codex");
65579
65681
  }
65580
65682
  function providerHookSettingsPath(provider4, where) {
65581
- return (0, import_node_path28.join)(
65683
+ return (0, import_node_path29.join)(
65582
65684
  providerConfigDir(provider4, where),
65583
65685
  provider4 === "claude" ? "settings.json" : "hooks.json"
65584
65686
  );
65585
65687
  }
65586
65688
  function providerTranscriptRoot(provider4, where) {
65587
- return (0, import_node_path28.join)(providerConfigDir(provider4, where), provider4 === "claude" ? "projects" : "sessions");
65689
+ return (0, import_node_path29.join)(providerConfigDir(provider4, where), provider4 === "claude" ? "projects" : "sessions");
65588
65690
  }
65589
65691
 
65590
65692
  // src/capabilities/native-ingest/hook-config.ts
@@ -65664,7 +65766,7 @@ function hooksOf(settings2) {
65664
65766
  return isRecord9(settings2.hooks) ? settings2.hooks : {};
65665
65767
  }
65666
65768
  function writeSettings(path4, settings2) {
65667
- (0, import_node_fs10.mkdirSync)((0, import_node_path29.dirname)(path4), { recursive: true, mode: 448 });
65769
+ (0, import_node_fs10.mkdirSync)((0, import_node_path30.dirname)(path4), { recursive: true, mode: 448 });
65668
65770
  const temporary = `${path4}.${process.pid}.tmp`;
65669
65771
  try {
65670
65772
  (0, import_node_fs10.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
@@ -65754,7 +65856,7 @@ function ingestionHookStatus(provider4, options) {
65754
65856
 
65755
65857
  // src/capabilities/native-ingest/hook-input.ts
65756
65858
  var import_node_fs11 = require("fs");
65757
- var import_node_path30 = require("path");
65859
+ var import_node_path31 = require("path");
65758
65860
  var ALAN_MANAGED_SESSION_ENV = "ALAN_MANAGED_SESSION";
65759
65861
  var MAX_HOOK_STDIN_BYTES = 256 * 1024 * 1024;
65760
65862
  var OVERFLOW_EDGE_BYTES = 64 * 1024;
@@ -65779,7 +65881,7 @@ function stringField2(payload, ...names) {
65779
65881
  }
65780
65882
  function codexSessionIdFromTranscriptPath(transcriptPath) {
65781
65883
  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(
65782
- (0, import_node_path30.basename)(transcriptPath)
65884
+ (0, import_node_path31.basename)(transcriptPath)
65783
65885
  );
65784
65886
  return match?.[1] ?? null;
65785
65887
  }
@@ -65856,21 +65958,21 @@ function realpathOrSelf(path4) {
65856
65958
  return (0, import_node_fs11.realpathSync)(path4);
65857
65959
  } catch {
65858
65960
  try {
65859
- return (0, import_node_path30.join)((0, import_node_fs11.realpathSync)((0, import_node_path30.dirname)(path4)), (0, import_node_path30.basename)(path4));
65961
+ return (0, import_node_path31.join)((0, import_node_fs11.realpathSync)((0, import_node_path31.dirname)(path4)), (0, import_node_path31.basename)(path4));
65860
65962
  } catch {
65861
65963
  return path4;
65862
65964
  }
65863
65965
  }
65864
65966
  }
65865
65967
  function isWithinDirectory(path4, directory) {
65866
- const offset = (0, import_node_path30.relative)(realpathOrSelf(directory), realpathOrSelf(path4));
65867
- return offset !== "" && !offset.startsWith("..") && !(0, import_node_path30.isAbsolute)(offset);
65968
+ const offset = (0, import_node_path31.relative)(realpathOrSelf(directory), realpathOrSelf(path4));
65969
+ return offset !== "" && !offset.startsWith("..") && !(0, import_node_path31.isAbsolute)(offset);
65868
65970
  }
65869
65971
  function parseHookSignal(input2) {
65870
65972
  const { payload } = input2;
65871
65973
  const rawTranscriptPath = stringField2(payload, "transcript_path", "transcriptPath");
65872
65974
  if (!rawTranscriptPath) return null;
65873
- const transcriptPath = (0, import_node_path30.resolve)(rawTranscriptPath);
65975
+ const transcriptPath = (0, import_node_path31.resolve)(rawTranscriptPath);
65874
65976
  const externalSessionId = stringField2(payload, "session_id", "sessionId") ?? (input2.provider === "codex" ? codexSessionIdFromTranscriptPath(transcriptPath) : null);
65875
65977
  if (!externalSessionId) return null;
65876
65978
  const cwd = stringField2(payload, "cwd");
@@ -65879,7 +65981,7 @@ function parseHookSignal(input2) {
65879
65981
  event: input2.event,
65880
65982
  externalSessionId,
65881
65983
  transcriptPath,
65882
- cwd: cwd ? (0, import_node_path30.resolve)(cwd) : null,
65984
+ cwd: cwd ? (0, import_node_path31.resolve)(cwd) : null,
65883
65985
  providerTurnId: stringField2(payload, "prompt_id", "turn_id"),
65884
65986
  assistantFingerprint: typeof payload.last_assistant_message === "string" ? assistantFingerprint(payload.last_assistant_message) : null,
65885
65987
  observedAt: input2.observedAt.toISOString()
@@ -65960,7 +66062,7 @@ function nextAlanBoundary(entry, inFlightFrom) {
65960
66062
  }
65961
66063
 
65962
66064
  // src/capabilities/native-ingest/pass.ts
65963
- var import_promises42 = require("fs/promises");
66065
+ var import_promises43 = require("fs/promises");
65964
66066
 
65965
66067
  // src/capabilities/native-ingest/ports.ts
65966
66068
  var NativeRequestFailure = class extends Error {
@@ -66019,7 +66121,7 @@ function fitNativeTurnPrompt(message2, maxBytes = NATIVE_TURN_USER_MESSAGE_MAX_B
66019
66121
  }
66020
66122
 
66021
66123
  // src/capabilities/native-ingest/session-store.ts
66022
- var import_node_path31 = require("path");
66124
+ var import_node_path32 = require("path");
66023
66125
  init_zod();
66024
66126
  var MAX_NATIVE_SESSION_ENTRIES = 500;
66025
66127
  var STORE_FILE = "native-sessions.json";
@@ -66050,7 +66152,7 @@ function evictionOrder(a, b) {
66050
66152
  return aFinished - bFinished || a.updatedAt - b.updatedAt;
66051
66153
  }
66052
66154
  async function openNativeSessionStore(stateDir, maxEntries = MAX_NATIVE_SESSION_ENTRIES) {
66053
- const path4 = (0, import_node_path31.join)(stateDir, STORE_FILE);
66155
+ const path4 = (0, import_node_path32.join)(stateDir, STORE_FILE);
66054
66156
  const sessions = /* @__PURE__ */ new Map();
66055
66157
  const stored = await readJsonFile(path4, storedSchema);
66056
66158
  if (stored.kind === "ok") {
@@ -66097,8 +66199,8 @@ function reconcileTranscriptIdentity(entry, transcriptPath, identity, size) {
66097
66199
  }
66098
66200
 
66099
66201
  // src/capabilities/native-ingest/transcript-window.ts
66100
- var import_node_crypto17 = require("crypto");
66101
- var import_promises41 = require("fs/promises");
66202
+ var import_node_crypto18 = require("crypto");
66203
+ var import_promises42 = require("fs/promises");
66102
66204
  init_acp3();
66103
66205
  init_claude();
66104
66206
  init_codex();
@@ -66153,7 +66255,7 @@ async function findRecordEnd(handle, from, size) {
66153
66255
  return null;
66154
66256
  }
66155
66257
  async function readTranscriptWindow(path4, offset, limits) {
66156
- const handle = await (0, import_promises41.open)(path4, "r");
66258
+ const handle = await (0, import_promises42.open)(path4, "r");
66157
66259
  try {
66158
66260
  const stats = await handle.stat({ bigint: true });
66159
66261
  const size = Number(stats.size);
@@ -66247,7 +66349,7 @@ function lastMatchingTurnIndex(turns, target) {
66247
66349
  function signalDigest(target) {
66248
66350
  const fingerprint = target.assistantFingerprint;
66249
66351
  const basis = target.providerTurnId ?? (fingerprint ? `${fingerprint.length}\0${fingerprint.head}\0${fingerprint.tail}` : null);
66250
- return basis ? (0, import_node_crypto17.createHash)("sha256").update(basis).digest("hex") : null;
66352
+ return basis ? (0, import_node_crypto18.createHash)("sha256").update(basis).digest("hex") : null;
66251
66353
  }
66252
66354
  function lastForegroundStop(updates) {
66253
66355
  for (let index = updates.length - 1; index >= 0; index -= 1) {
@@ -66620,19 +66722,19 @@ async function runPass(ctx, worker) {
66620
66722
  });
66621
66723
  if (signal.ending) ctx.log.info("native_ingest.closed", workerFields(worker));
66622
66724
  }
66623
- const current = await (0, import_promises42.stat)(worker.latest.transcriptPath).catch(() => void 0);
66725
+ const current = await (0, import_promises43.stat)(worker.latest.transcriptPath).catch(() => void 0);
66624
66726
  return { grewDuringPass: current !== void 0 && current.size > state.lastSize };
66625
66727
  }
66626
66728
 
66627
66729
  // src/capabilities/native-ingest/settings.ts
66628
- var import_node_path32 = require("path");
66730
+ var import_node_path33 = require("path");
66629
66731
  init_zod();
66630
66732
  var NATIVE_INGEST_SETTINGS_FILE = "native-ingest.json";
66631
66733
  var settingsSchema = external_exports.object({
66632
66734
  providers: external_exports.partialRecord(external_exports.enum(nativeIngestionProviders), external_exports.boolean())
66633
66735
  });
66634
66736
  function nativeIngestSettingsPath(stateDir) {
66635
- return (0, import_node_path32.join)(stateDir, NATIVE_INGEST_SETTINGS_FILE);
66737
+ return (0, import_node_path33.join)(stateDir, NATIVE_INGEST_SETTINGS_FILE);
66636
66738
  }
66637
66739
  async function readNativeIngestSettings(stateDir) {
66638
66740
  const read = await readJsonFile(nativeIngestSettingsPath(stateDir), settingsSchema);
@@ -66977,8 +67079,8 @@ init_alan_code();
66977
67079
 
66978
67080
  // src/capabilities/providers/commands.ts
66979
67081
  var import_node_fs13 = require("fs");
66980
- var import_promises43 = require("fs/promises");
66981
- var import_node_path33 = require("path");
67082
+ var import_promises44 = require("fs/promises");
67083
+ var import_node_path34 = require("path");
66982
67084
  var PROVIDER_COMMANDS = [
66983
67085
  // The engine, not a CLI of its own: `resolveProviderExecutable` finds the bundled one first.
66984
67086
  { backendKind: "alan_code", command: "opencode", name: "Alan Code" },
@@ -67013,8 +67115,8 @@ function pathDelimiter(platform3) {
67013
67115
  }
67014
67116
  async function isRunnable(path4, platform3) {
67015
67117
  try {
67016
- if (!(await (0, import_promises43.stat)(path4)).isFile()) return false;
67017
- if (platform3 !== "win32") await (0, import_promises43.access)(path4, import_node_fs13.constants.X_OK);
67118
+ if (!(await (0, import_promises44.stat)(path4)).isFile()) return false;
67119
+ if (platform3 !== "win32") await (0, import_promises44.access)(path4, import_node_fs13.constants.X_OK);
67018
67120
  return true;
67019
67121
  } catch {
67020
67122
  return false;
@@ -67031,12 +67133,12 @@ async function resolveCommandOnPath(command, env, platform3) {
67031
67133
  const directories = envValue(env, "PATH").split(pathDelimiter(platform3)).map(
67032
67134
  (directory) => platform3 === "win32" ? directory.trim().replace(/^"(.*)"$/, "$1") : directory
67033
67135
  ).filter(
67034
- (directory) => platform3 === "win32" ? import_node_path33.win32.isAbsolute(directory) : directory.length > 0
67136
+ (directory) => platform3 === "win32" ? import_node_path34.win32.isAbsolute(directory) : directory.length > 0
67035
67137
  );
67036
67138
  const extensions = platform3 === "win32" ? windowsExtensions(command, env) : [""];
67037
67139
  for (const directory of directories) {
67038
67140
  for (const extension of extensions) {
67039
- const candidate = (0, import_node_path33.join)(directory, `${command}${extension}`);
67141
+ const candidate = (0, import_node_path34.join)(directory, `${command}${extension}`);
67040
67142
  if (await isRunnable(candidate, platform3)) return candidate;
67041
67143
  }
67042
67144
  }
@@ -67191,14 +67293,14 @@ function captureProbe(command, args, options) {
67191
67293
  }
67192
67294
 
67193
67295
  // src/capabilities/providers/inventory.ts
67194
- var import_promises44 = require("fs/promises");
67296
+ var import_promises45 = require("fs/promises");
67195
67297
  var import_node_os5 = require("os");
67196
67298
  init_runtime_v2();
67197
67299
 
67198
67300
  // src/capabilities/providers/account-label.ts
67199
67301
  var import_node_child_process12 = require("child_process");
67200
67302
  var import_node_fs14 = require("fs");
67201
- var import_node_path34 = require("path");
67303
+ var import_node_path35 = require("path");
67202
67304
  var import_node_url3 = require("url");
67203
67305
  var ACCOUNT_TIMEOUT_MS = 2e4;
67204
67306
  var CODEX_OUTPUT_MAX_BYTES = 256 * 1024;
@@ -67299,7 +67401,7 @@ async function claudeLabel(executable, env) {
67299
67401
  try {
67300
67402
  const childEnv = { ...env };
67301
67403
  delete childEnv.FORCE_CODE_TERMINAL;
67302
- const bundledSdk = typeof __dirname === "string" ? (0, import_node_path34.join)(__dirname, "claude-sdk.mjs") : "";
67404
+ const bundledSdk = typeof __dirname === "string" ? (0, import_node_path35.join)(__dirname, "claude-sdk.mjs") : "";
67303
67405
  const sdkSpecifier = (0, import_node_fs14.existsSync)(bundledSdk) ? (0, import_node_url3.pathToFileURL)(bundledSdk).href : "@anthropic-ai/claude-agent-sdk";
67304
67406
  const { query } = await import(sdkSpecifier);
67305
67407
  const session = query({
@@ -67651,8 +67753,8 @@ async function executablesFingerprint(env, platform3) {
67651
67753
  const executable = await resolveProviderExecutable(provider4, env, platform3);
67652
67754
  if (executable === null) return `${provider4.backendKind}:-`;
67653
67755
  try {
67654
- const target = await (0, import_promises44.realpath)(executable);
67655
- const { size, mtimeMs } = await (0, import_promises44.stat)(target);
67756
+ const target = await (0, import_promises45.realpath)(executable);
67757
+ const { size, mtimeMs } = await (0, import_promises45.stat)(target);
67656
67758
  return `${provider4.backendKind}:${target}:${size}:${mtimeMs}`;
67657
67759
  } catch {
67658
67760
  return `${provider4.backendKind}:${executable}:?`;
@@ -67705,22 +67807,22 @@ function createCapabilityInventory(options) {
67705
67807
  }
67706
67808
 
67707
67809
  // src/capabilities/providers/login-path.ts
67708
- var import_node_path38 = require("path");
67810
+ var import_node_path39 = require("path");
67709
67811
 
67710
67812
  // ../shared/dist/node/shell-environment.js
67711
67813
  var import_node_child_process13 = require("child_process");
67712
- var import_node_crypto18 = require("crypto");
67814
+ var import_node_crypto19 = require("crypto");
67713
67815
  var import_node_fs16 = require("fs");
67714
67816
  var import_node_os7 = require("os");
67715
- var import_node_path37 = require("path");
67817
+ var import_node_path38 = require("path");
67716
67818
 
67717
67819
  // ../shared/dist/node/shell-path.js
67718
67820
  var import_node_os6 = require("os");
67719
- var import_node_path36 = require("path");
67821
+ var import_node_path37 = require("path");
67720
67822
 
67721
67823
  // ../shared/dist/node/version-manager-paths.js
67722
67824
  var import_node_fs15 = require("fs");
67723
- var import_node_path35 = require("path");
67825
+ var import_node_path36 = require("path");
67724
67826
  function compareNodeVersionsDesc(a, b) {
67725
67827
  const parse7 = (value2) => value2.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
67726
67828
  const left = parse7(a);
@@ -67733,12 +67835,12 @@ function compareNodeVersionsDesc(a, b) {
67733
67835
  return 0;
67734
67836
  }
67735
67837
  function resolveNvmDefaultBin(home) {
67736
- const versionsDir = (0, import_node_path35.join)(home, ".nvm", "versions", "node");
67838
+ const versionsDir = (0, import_node_path36.join)(home, ".nvm", "versions", "node");
67737
67839
  if (!(0, import_node_fs15.existsSync)(versionsDir))
67738
67840
  return null;
67739
67841
  let alias = null;
67740
67842
  try {
67741
- const aliasFile = (0, import_node_path35.join)(home, ".nvm", "alias", "default");
67843
+ const aliasFile = (0, import_node_path36.join)(home, ".nvm", "alias", "default");
67742
67844
  if ((0, import_node_fs15.existsSync)(aliasFile))
67743
67845
  alias = (0, import_node_fs15.readFileSync)(aliasFile, "utf8").trim();
67744
67846
  } catch {
@@ -67756,7 +67858,7 @@ function resolveNvmDefaultBin(home) {
67756
67858
  const chosen = (matching.length > 0 ? matching : installed).sort(compareNodeVersionsDesc)[0];
67757
67859
  if (!chosen)
67758
67860
  return null;
67759
- const bin = (0, import_node_path35.join)(versionsDir, chosen, "bin");
67861
+ const bin = (0, import_node_path36.join)(versionsDir, chosen, "bin");
67760
67862
  return (0, import_node_fs15.existsSync)(bin) ? bin : null;
67761
67863
  }
67762
67864
  function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
@@ -67764,11 +67866,11 @@ function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
67764
67866
  return [];
67765
67867
  const candidates2 = [
67766
67868
  resolveNvmDefaultBin(home),
67767
- (0, import_node_path35.join)(home, ".volta", "bin"),
67768
- (0, import_node_path35.join)(home, ".fnm", "aliases", "default", "bin"),
67769
- (0, import_node_path35.join)(home, "Library", "Application Support", "fnm", "aliases", "default", "bin"),
67770
- (0, import_node_path35.join)(home, ".asdf", "shims"),
67771
- (0, import_node_path35.join)(home, ".local", "share", "mise", "shims")
67869
+ (0, import_node_path36.join)(home, ".volta", "bin"),
67870
+ (0, import_node_path36.join)(home, ".fnm", "aliases", "default", "bin"),
67871
+ (0, import_node_path36.join)(home, "Library", "Application Support", "fnm", "aliases", "default", "bin"),
67872
+ (0, import_node_path36.join)(home, ".asdf", "shims"),
67873
+ (0, import_node_path36.join)(home, ".local", "share", "mise", "shims")
67772
67874
  ];
67773
67875
  const seen = /* @__PURE__ */ new Set();
67774
67876
  const resolved = [];
@@ -67804,9 +67906,9 @@ function promoteAheadOfVersionManagers(path4, promoted, versionManagerDirs) {
67804
67906
  }
67805
67907
  function promotedUserBinDirs(home) {
67806
67908
  return /* @__PURE__ */ new Set([
67807
- (0, import_node_path36.join)(home, ".local", "bin"),
67808
- (0, import_node_path36.join)(home, ".bun", "bin"),
67809
- (0, import_node_path36.join)(home, ".cargo", "bin")
67909
+ (0, import_node_path37.join)(home, ".local", "bin"),
67910
+ (0, import_node_path37.join)(home, ".bun", "bin"),
67911
+ (0, import_node_path37.join)(home, ".cargo", "bin")
67810
67912
  ]);
67811
67913
  }
67812
67914
  function promoteUserBinDirs(path4, home, versionManagerDirs) {
@@ -67828,11 +67930,11 @@ function resolveLoginShell(env = process.env) {
67828
67930
  if ((0, import_node_os7.platform)() === "win32")
67829
67931
  return null;
67830
67932
  const explicit = env.SHELL?.trim();
67831
- if (explicit && (0, import_node_path37.isAbsolute)(explicit) && isExecutableFile(explicit))
67933
+ if (explicit && (0, import_node_path38.isAbsolute)(explicit) && isExecutableFile(explicit))
67832
67934
  return explicit;
67833
67935
  try {
67834
67936
  const accountShell = (0, import_node_os7.userInfo)().shell?.trim();
67835
- if (accountShell && (0, import_node_path37.isAbsolute)(accountShell) && isExecutableFile(accountShell)) {
67937
+ if (accountShell && (0, import_node_path38.isAbsolute)(accountShell) && isExecutableFile(accountShell)) {
67836
67938
  return accountShell;
67837
67939
  }
67838
67940
  } catch {
@@ -67849,17 +67951,17 @@ var MARKER = "__ALAN_LOGIN_PATH__";
67849
67951
  var SELF_GUARD_ENV = "ALAN_RESOLVING_ENVIRONMENT";
67850
67952
  var lastKnownGoodSchema = external_exports.object({ path: external_exports.string().min(1) });
67851
67953
  function installerDirectories(home, platform3) {
67852
- const user = home.length > 0 ? [(0, import_node_path38.join)(home, ".local", "bin"), (0, import_node_path38.join)(home, ".bun", "bin")] : [];
67954
+ const user = home.length > 0 ? [(0, import_node_path39.join)(home, ".local", "bin"), (0, import_node_path39.join)(home, ".bun", "bin")] : [];
67853
67955
  const system = platform3 === "darwin" ? ["/opt/homebrew/bin", "/usr/local/bin"] : ["/usr/local/bin"];
67854
67956
  return [...user, ...system];
67855
67957
  }
67856
67958
  function windowsInstallerDirectories(env) {
67857
67959
  const home = envValue(env, "USERPROFILE") || envValue(env, "HOME");
67858
- const hasHome = import_node_path38.win32.isAbsolute(home);
67859
- const appData = envValue(env, "APPDATA") || (hasHome ? import_node_path38.win32.join(home, "AppData", "Roaming") : "");
67960
+ const hasHome = import_node_path39.win32.isAbsolute(home);
67961
+ const appData = envValue(env, "APPDATA") || (hasHome ? import_node_path39.win32.join(home, "AppData", "Roaming") : "");
67860
67962
  return [
67861
- ...hasHome ? [import_node_path38.win32.join(home, ".local", "bin")] : [],
67862
- ...import_node_path38.win32.isAbsolute(appData) ? [import_node_path38.win32.join(appData, "npm")] : []
67963
+ ...hasHome ? [import_node_path39.win32.join(home, ".local", "bin")] : [],
67964
+ ...import_node_path39.win32.isAbsolute(appData) ? [import_node_path39.win32.join(appData, "npm")] : []
67863
67965
  ];
67864
67966
  }
67865
67967
  function printPathCommand() {
@@ -67876,7 +67978,7 @@ async function readLoginShellPath(env, capture) {
67876
67978
  const shell = resolveLoginShell({ ...env });
67877
67979
  if (shell === null) return null;
67878
67980
  const probeEnv = { ...env, [SELF_GUARD_ENV]: "1" };
67879
- const cshFamily = (0, import_node_path38.basename)(shell) === "csh" || (0, import_node_path38.basename)(shell) === "tcsh";
67981
+ const cshFamily = (0, import_node_path39.basename)(shell) === "csh" || (0, import_node_path39.basename)(shell) === "tcsh";
67880
67982
  const interactive = await capture(shell, [cshFamily ? "-ic" : "-ilc", printPathCommand()], {
67881
67983
  env: probeEnv,
67882
67984
  timeoutMs: LOGIN_SHELL_TIMEOUT_MS
@@ -67968,9 +68070,9 @@ async function openCliEnvironment(options) {
67968
68070
  }
67969
68071
 
67970
68072
  // src/capabilities/providers/managed.ts
67971
- var import_node_crypto19 = require("crypto");
67972
- var import_promises45 = require("fs/promises");
67973
- var import_node_path39 = require("path");
68073
+ var import_node_crypto20 = require("crypto");
68074
+ var import_promises46 = require("fs/promises");
68075
+ var import_node_path40 = require("path");
67974
68076
  init_zod();
67975
68077
  var PACKAGES = {
67976
68078
  claude_cli: { name: "@anthropic-ai/claude-code", command: "claude" },
@@ -67986,7 +68088,7 @@ var VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?$/;
67986
68088
  var selectedSchema = external_exports.record(external_exports.string(), external_exports.string());
67987
68089
  async function readManagedProviderVersion(file2, backendKind) {
67988
68090
  try {
67989
- const selected = selectedSchema.parse(JSON.parse(await (0, import_promises45.readFile)(file2, "utf8")));
68091
+ const selected = selectedSchema.parse(JSON.parse(await (0, import_promises46.readFile)(file2, "utf8")));
67990
68092
  const version2 = selected[backendKind];
67991
68093
  return version2 !== void 0 && VERSION.test(version2) ? version2 : null;
67992
68094
  } catch {
@@ -68044,16 +68146,16 @@ async function installVersion2(backendKind, requested, options, signal) {
68044
68146
  );
68045
68147
  }
68046
68148
  function selection(root, backendKind, version2) {
68047
- const binDir = (0, import_node_path39.join)(root, "versions", backendKind, version2, "node_modules", ".bin");
68149
+ const binDir = (0, import_node_path40.join)(root, "versions", backendKind, version2, "node_modules", ".bin");
68048
68150
  return {
68049
68151
  backendKind,
68050
68152
  version: version2,
68051
68153
  binDir,
68052
- executable: (0, import_node_path39.join)(binDir, packageFor(backendKind).command)
68154
+ executable: (0, import_node_path40.join)(binDir, packageFor(backendKind).command)
68053
68155
  };
68054
68156
  }
68055
68157
  async function runnable(file2) {
68056
- return (0, import_promises45.stat)(file2).then(
68158
+ return (0, import_promises46.stat)(file2).then(
68057
68159
  (value2) => value2.isFile(),
68058
68160
  () => false
68059
68161
  );
@@ -68062,7 +68164,7 @@ function createManagedProviderClis(options) {
68062
68164
  const state = {};
68063
68165
  const updateCache = /* @__PURE__ */ new Map();
68064
68166
  let queue = Promise.resolve();
68065
- const file2 = (0, import_node_path39.join)(options.root, "selected.json");
68167
+ const file2 = (0, import_node_path40.join)(options.root, "selected.json");
68066
68168
  const latestVersionFor = async (packageName, signal) => {
68067
68169
  const cached2 = updateCache.get(packageName);
68068
68170
  if (cached2 && cached2.expiresAt > Date.now()) return cached2.latestVersion;
@@ -68096,13 +68198,13 @@ function createManagedProviderClis(options) {
68096
68198
  return next;
68097
68199
  };
68098
68200
  const persist = async () => {
68099
- await (0, import_promises45.mkdir)(options.root, { recursive: true, mode: 448 });
68100
- const staged = `${file2}.${(0, import_node_crypto19.randomUUID)()}`;
68201
+ await (0, import_promises46.mkdir)(options.root, { recursive: true, mode: 448 });
68202
+ const staged = `${file2}.${(0, import_node_crypto20.randomUUID)()}`;
68101
68203
  try {
68102
- await (0, import_promises45.writeFile)(staged, JSON.stringify(state), { mode: 384 });
68103
- await (0, import_promises45.rename)(staged, file2);
68204
+ await (0, import_promises46.writeFile)(staged, JSON.stringify(state), { mode: 384 });
68205
+ await (0, import_promises46.rename)(staged, file2);
68104
68206
  } finally {
68105
- await (0, import_promises45.rm)(staged, { force: true });
68207
+ await (0, import_promises46.rm)(staged, { force: true });
68106
68208
  }
68107
68209
  };
68108
68210
  const activate = async (backendKind, version2) => {
@@ -68124,7 +68226,7 @@ function createManagedProviderClis(options) {
68124
68226
  return {
68125
68227
  selectionFile: file2,
68126
68228
  load: async () => {
68127
- const raw = await (0, import_promises45.readFile)(file2, "utf8").catch((error62) => {
68229
+ const raw = await (0, import_promises46.readFile)(file2, "utf8").catch((error62) => {
68128
68230
  if (error62 instanceof Error && "code" in error62 && error62.code === "ENOENT") return "{}";
68129
68231
  throw error62;
68130
68232
  });
@@ -68132,7 +68234,7 @@ function createManagedProviderClis(options) {
68132
68234
  try {
68133
68235
  parsed = selectedSchema.parse(JSON.parse(raw));
68134
68236
  } catch {
68135
- await (0, import_promises45.rename)(file2, `${file2}.invalid.${(0, import_node_crypto19.randomUUID)()}`).catch(() => void 0);
68237
+ await (0, import_promises46.rename)(file2, `${file2}.invalid.${(0, import_node_crypto20.randomUUID)()}`).catch(() => void 0);
68136
68238
  return;
68137
68239
  }
68138
68240
  for (const [backendKind, version2] of Object.entries(parsed)) {
@@ -68151,8 +68253,8 @@ function createManagedProviderClis(options) {
68151
68253
  available: async () => {
68152
68254
  const groups = await Promise.all(
68153
68255
  Object.keys(PACKAGES).map(async (backendKind) => {
68154
- const directory = (0, import_node_path39.join)(options.root, "versions", backendKind);
68155
- const versions = await (0, import_promises45.readdir)(directory).catch((error62) => {
68256
+ const directory = (0, import_node_path40.join)(options.root, "versions", backendKind);
68257
+ const versions = await (0, import_promises46.readdir)(directory).catch((error62) => {
68156
68258
  if (error62 instanceof Error && "code" in error62 && error62.code === "ENOENT") return [];
68157
68259
  throw error62;
68158
68260
  });
@@ -68186,21 +68288,21 @@ function createManagedProviderClis(options) {
68186
68288
  install: (backendKind, version2, signal) => serialize(async () => {
68187
68289
  const provider4 = packageFor(backendKind);
68188
68290
  const exact = await installVersion2(backendKind, version2, options, signal);
68189
- const target = (0, import_node_path39.join)(options.root, "versions", backendKind, exact);
68291
+ const target = (0, import_node_path40.join)(options.root, "versions", backendKind, exact);
68190
68292
  const existing = selection(options.root, backendKind, exact);
68191
68293
  if (!await runnable(existing.executable) || !await options.probe(existing.executable, backendKind)) {
68192
- await (0, import_promises45.mkdir)((0, import_node_path39.dirname)(target), { recursive: true, mode: 448 });
68193
- const staged = `${target}.${(0, import_node_crypto19.randomUUID)()}`;
68294
+ await (0, import_promises46.mkdir)((0, import_node_path40.dirname)(target), { recursive: true, mode: 448 });
68295
+ const staged = `${target}.${(0, import_node_crypto20.randomUUID)()}`;
68194
68296
  try {
68195
68297
  await options.installPackage(provider4.name, exact, staged, provider4.command, signal);
68196
- const built = (0, import_node_path39.join)(staged, "node_modules", ".bin", provider4.command);
68298
+ const built = (0, import_node_path40.join)(staged, "node_modules", ".bin", provider4.command);
68197
68299
  if (!await runnable(built) || !await options.probe(built, backendKind)) {
68198
68300
  throw new Error(`${backendKind}@${exact} failed its executable probe`);
68199
68301
  }
68200
- await (0, import_promises45.rm)(target, { recursive: true, force: true });
68201
- await (0, import_promises45.rename)(staged, target);
68302
+ await (0, import_promises46.rm)(target, { recursive: true, force: true });
68303
+ await (0, import_promises46.rename)(staged, target);
68202
68304
  } finally {
68203
- await (0, import_promises45.rm)(staged, { recursive: true, force: true });
68305
+ await (0, import_promises46.rm)(staged, { recursive: true, force: true });
68204
68306
  }
68205
68307
  }
68206
68308
  return activate(backendKind, exact);
@@ -68223,7 +68325,7 @@ function createManagedProviderClis(options) {
68223
68325
  function withInstallerPath(options) {
68224
68326
  const platform3 = options.platform ?? process.platform;
68225
68327
  const path4 = [
68226
- platform3 === "win32" ? import_node_path39.win32.dirname(options.command) : (0, import_node_path39.dirname)(options.command),
68328
+ platform3 === "win32" ? import_node_path40.win32.dirname(options.command) : (0, import_node_path40.dirname)(options.command),
68227
68329
  envValue(options.env, "PATH")
68228
68330
  ].filter(Boolean).join(pathDelimiter(platform3));
68229
68331
  const env = { ...options.env, PATH: path4 };
@@ -68303,14 +68405,14 @@ ${help.stderr}`);
68303
68405
  }
68304
68406
 
68305
68407
  // src/capabilities/skills/local-preview.ts
68306
- var import_promises50 = require("fs/promises");
68307
- var import_node_path44 = __toESM(require("path"));
68408
+ var import_promises51 = require("fs/promises");
68409
+ var import_node_path45 = __toESM(require("path"));
68308
68410
 
68309
68411
  // ../shared/dist/node/skill-package.js
68310
68412
  var import_node_buffer = require("buffer");
68311
- var import_node_crypto20 = require("crypto");
68312
- var import_promises46 = require("fs/promises");
68313
- var import_node_path40 = require("path");
68413
+ var import_node_crypto21 = require("crypto");
68414
+ var import_promises47 = require("fs/promises");
68415
+ var import_node_path41 = require("path");
68314
68416
  var import_yaml = __toESM(require_dist(), 1);
68315
68417
  init_contracts();
68316
68418
  init_domain();
@@ -68381,7 +68483,7 @@ async function inspectSkillPackage(packageRoot, options = {}) {
68381
68483
  }
68382
68484
  const inspectedFiles = await Promise.all(files.map(readPackageFile));
68383
68485
  inspectedFiles.sort(comparePackageFiles);
68384
- const parsedMetadata = parseSkillMetadata(inspectedFiles.find((file2) => file2.manifest.path === "SKILL.md")?.bytes, options.expectedName === void 0 ? (0, import_node_path40.basename)(root) : options.expectedName);
68486
+ const parsedMetadata = parseSkillMetadata(inspectedFiles.find((file2) => file2.manifest.path === "SKILL.md")?.bytes, options.expectedName === void 0 ? (0, import_node_path41.basename)(root) : options.expectedName);
68385
68487
  const manifestFiles = inspectedFiles.map((file2) => file2.manifest);
68386
68488
  const diagnostics = [
68387
68489
  ...parsedMetadata.conformance,
@@ -68405,11 +68507,11 @@ async function readSkillPackageFile(packageRoot, path4, expectedSha256) {
68405
68507
  if (!normalizedPath || normalizedPath !== path4 || normalizedPath.includes("\\") || components.some((component) => !component || component === "." || component === "..")) {
68406
68508
  throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${path4}`, path4);
68407
68509
  }
68408
- const absolutePath = await (0, import_promises46.realpath)((0, import_node_path40.resolve)(root, ...components)).catch(() => null);
68510
+ const absolutePath = await (0, import_promises47.realpath)((0, import_node_path41.resolve)(root, ...components)).catch(() => null);
68409
68511
  if (!absolutePath || normalizeRelativePath(root, absolutePath) !== normalizedPath) {
68410
68512
  throw new SkillPackageError("INVALID_PATH", `Skill package file was not found: ${path4}`, path4);
68411
68513
  }
68412
- const entryStat = await (0, import_promises46.lstat)(absolutePath);
68514
+ const entryStat = await (0, import_promises47.lstat)(absolutePath);
68413
68515
  if (!entryStat.isFile()) {
68414
68516
  throw new SkillPackageError("SPECIAL_FILE_BLOCKED", `Only regular files are allowed in Skill packages: ${path4}`, path4);
68415
68517
  }
@@ -68426,11 +68528,11 @@ async function readSkillPackageFile(packageRoot, path4, expectedSha256) {
68426
68528
  return { file: read.manifest, bytes: read.bytes };
68427
68529
  }
68428
68530
  async function requirePackageRoot(packageRoot) {
68429
- const root = await (0, import_promises46.realpath)((0, import_node_path40.resolve)(packageRoot)).catch(() => null);
68531
+ const root = await (0, import_promises47.realpath)((0, import_node_path41.resolve)(packageRoot)).catch(() => null);
68430
68532
  if (!root) {
68431
68533
  throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package directory does not exist");
68432
68534
  }
68433
- const rootStat = await (0, import_promises46.lstat)(root);
68535
+ const rootStat = await (0, import_promises47.lstat)(root);
68434
68536
  if (!rootStat.isDirectory()) {
68435
68537
  throw new SkillPackageError("INVALID_PACKAGE_ROOT", "Skill package root must be a directory");
68436
68538
  }
@@ -68450,13 +68552,13 @@ async function walkPackage(root, ignoredPaths) {
68450
68552
  }
68451
68553
  return files;
68452
68554
  async function walkDirectory(directory) {
68453
- const entries = await (0, import_promises46.readdir)(directory, { withFileTypes: true });
68555
+ const entries = await (0, import_promises47.readdir)(directory, { withFileTypes: true });
68454
68556
  for (const entry of entries) {
68455
- const absolutePath = (0, import_node_path40.resolve)(directory, entry.name);
68557
+ const absolutePath = (0, import_node_path41.resolve)(directory, entry.name);
68456
68558
  const normalizedPath = normalizeRelativePath(root, absolutePath);
68457
68559
  if (isIgnored(normalizedPath, entry.name, entry.isDirectory(), ignored2))
68458
68560
  continue;
68459
- const entryStat = await (0, import_promises46.lstat)(absolutePath);
68561
+ const entryStat = await (0, import_promises47.lstat)(absolutePath);
68460
68562
  if (entryStat.isSymbolicLink()) {
68461
68563
  throw new SkillPackageError("SYMLINK_BLOCKED", `Nested symbolic links are not allowed in Skill packages: ${normalizedPath}`, normalizedPath);
68462
68564
  }
@@ -68519,12 +68621,12 @@ function globToRegExp(pattern) {
68519
68621
  return new RegExp(`${source}(?:/.*)?$`);
68520
68622
  }
68521
68623
  function normalizeRelativePath(root, absolutePath) {
68522
- const nativeRelativePath = (0, import_node_path40.relative)(root, absolutePath);
68523
- if (!nativeRelativePath || nativeRelativePath.startsWith(`..${import_node_path40.sep}`) || nativeRelativePath === "..") {
68624
+ const nativeRelativePath = (0, import_node_path41.relative)(root, absolutePath);
68625
+ if (!nativeRelativePath || nativeRelativePath.startsWith(`..${import_node_path41.sep}`) || nativeRelativePath === "..") {
68524
68626
  throw new SkillPackageError("INVALID_PATH", "Skill package path escapes its root");
68525
68627
  }
68526
- const normalized2 = nativeRelativePath.split(import_node_path40.sep).join("/").normalize("NFC");
68527
- if (normalized2.includes("\0") || normalized2.includes("\uFFFD") || import_node_path40.posix.isAbsolute(normalized2)) {
68628
+ const normalized2 = nativeRelativePath.split(import_node_path41.sep).join("/").normalize("NFC");
68629
+ if (normalized2.includes("\0") || normalized2.includes("\uFFFD") || import_node_path41.posix.isAbsolute(normalized2)) {
68528
68630
  throw new SkillPackageError("INVALID_PATH", `Invalid Skill package path: ${normalized2}`);
68529
68631
  }
68530
68632
  return normalized2;
@@ -68559,13 +68661,13 @@ function requireSafeFile(path4, size, normalizedPaths) {
68559
68661
  }
68560
68662
  }
68561
68663
  function isSecretPath(path4) {
68562
- const name = import_node_path40.posix.basename(path4).toLowerCase();
68664
+ const name = import_node_path41.posix.basename(path4).toLowerCase();
68563
68665
  if (SECRET_BASENAMES.has(name) || name.startsWith(".env."))
68564
68666
  return true;
68565
68667
  return name.endsWith(".private-key.pem") || name.endsWith(".private-key.key");
68566
68668
  }
68567
68669
  async function readPackageFile(file2) {
68568
- const bytes = await (0, import_promises46.readFile)(file2.absolutePath);
68670
+ const bytes = await (0, import_promises47.readFile)(file2.absolutePath);
68569
68671
  return {
68570
68672
  bytes,
68571
68673
  manifest: {
@@ -68587,12 +68689,12 @@ function classifyFileKind(path4) {
68587
68689
  return "reference";
68588
68690
  if (path4.startsWith("assets/"))
68589
68691
  return "asset";
68590
- if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(import_node_path40.posix.basename(path4)))
68692
+ if (/^(?:licen[cs]e|copying|notice)(?:\.|$)/i.test(import_node_path41.posix.basename(path4)))
68591
68693
  return "license";
68592
68694
  return "other";
68593
68695
  }
68594
68696
  function classifyPreview(path4, bytes) {
68595
- const extension = import_node_path40.posix.extname(path4).toLowerCase();
68697
+ const extension = import_node_path41.posix.extname(path4).toLowerCase();
68596
68698
  if (IMAGE_EXTENSIONS2.has(extension))
68597
68699
  return "image";
68598
68700
  if (bytes.includes(0))
@@ -68696,7 +68798,7 @@ function normalizePackageReference(value2) {
68696
68798
  const withoutSuffix = trimmed4.split(/[?#]/, 1)[0];
68697
68799
  if (!withoutSuffix)
68698
68800
  return null;
68699
- const normalized2 = import_node_path40.posix.normalize(withoutSuffix).replace(/^\.\//, "").normalize("NFC");
68801
+ const normalized2 = import_node_path41.posix.normalize(withoutSuffix).replace(/^\.\//, "").normalize("NFC");
68700
68802
  if (normalized2 === ".." || normalized2.startsWith("../"))
68701
68803
  return null;
68702
68804
  return normalized2;
@@ -68708,7 +68810,7 @@ function comparePackageFiles(left, right) {
68708
68810
  return import_node_buffer.Buffer.compare(import_node_buffer.Buffer.from(left.manifest.path, "utf8"), import_node_buffer.Buffer.from(right.manifest.path, "utf8"));
68709
68811
  }
68710
68812
  function hashPackageTree(files) {
68711
- const hash2 = (0, import_node_crypto20.createHash)("sha256");
68813
+ const hash2 = (0, import_node_crypto21.createHash)("sha256");
68712
68814
  hash2.update(TREE_HASH_PREFIX);
68713
68815
  for (const file2 of files) {
68714
68816
  const path4 = import_node_buffer.Buffer.from(file2.path, "utf8");
@@ -68721,7 +68823,7 @@ function hashPackageTree(files) {
68721
68823
  return `sha256:${hash2.digest("hex")}`;
68722
68824
  }
68723
68825
  function sha2562(bytes) {
68724
- return `sha256:${(0, import_node_crypto20.createHash)("sha256").update(bytes).digest("hex")}`;
68826
+ return `sha256:${(0, import_node_crypto21.createHash)("sha256").update(bytes).digest("hex")}`;
68725
68827
  }
68726
68828
  function uint322(value2) {
68727
68829
  const buffer = import_node_buffer.Buffer.allocUnsafe(4);
@@ -68735,22 +68837,22 @@ function uint642(value2) {
68735
68837
  }
68736
68838
 
68737
68839
  // src/capabilities/skills/local-sources.ts
68738
- var import_node_crypto22 = require("crypto");
68739
- var import_promises48 = require("fs/promises");
68740
- var import_node_path42 = __toESM(require("path"));
68840
+ var import_node_crypto23 = require("crypto");
68841
+ var import_promises49 = require("fs/promises");
68842
+ var import_node_path43 = __toESM(require("path"));
68741
68843
  init_type_guards();
68742
68844
 
68743
68845
  // src/capabilities/skills/local-scan.ts
68744
- var import_node_crypto21 = require("crypto");
68745
- var import_promises47 = require("fs/promises");
68746
- var import_node_path41 = __toESM(require("path"));
68846
+ var import_node_crypto22 = require("crypto");
68847
+ var import_promises48 = require("fs/promises");
68848
+ var import_node_path42 = __toESM(require("path"));
68747
68849
  var MAX_CANDIDATES = 2e3;
68748
68850
  var MAX_DIAGNOSTICS = 100;
68749
68851
  function createLocalSkillScanCache() {
68750
68852
  return { inspections: /* @__PURE__ */ new Map(), lastCompleteRevision: null };
68751
68853
  }
68752
68854
  async function scanSkillRoots(input2, cache2, managedRoots = []) {
68753
- const attemptId = (0, import_node_crypto21.randomUUID)();
68855
+ const attemptId = (0, import_node_crypto22.randomUUID)();
68754
68856
  const ignoredPaths = input2.ignoredPaths ?? [];
68755
68857
  const resolvedRoots = resolveScanRoots(input2.roots, input2.enabledProviderKinds ?? []);
68756
68858
  const pass = {
@@ -68816,7 +68918,7 @@ function failedLocalSkillScan(cache2, code, message2) {
68816
68918
  return {
68817
68919
  outcome: {
68818
68920
  status: "failed",
68819
- attemptId: (0, import_node_crypto21.randomUUID)(),
68921
+ attemptId: (0, import_node_crypto22.randomUUID)(),
68820
68922
  retainedInventoryRevision: cache2.lastCompleteRevision,
68821
68923
  diagnostics: [{ code, message: message2.slice(0, 2048) }]
68822
68924
  },
@@ -68862,8 +68964,8 @@ function invalid(resolvedRoot, name, error62) {
68862
68964
  };
68863
68965
  }
68864
68966
  async function scanRootAsPackage(pass, resolvedRoot) {
68865
- if (!await exists3(import_node_path41.default.join(resolvedRoot.directory, "SKILL.md"))) return null;
68866
- const canonical = await (0, import_promises47.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
68967
+ if (!await exists3(import_node_path42.default.join(resolvedRoot.directory, "SKILL.md"))) return null;
68968
+ const canonical = await (0, import_promises48.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
68867
68969
  if (isManaged(pass, canonical)) return { candidates: [], diagnostics: [], incomplete: false };
68868
68970
  try {
68869
68971
  const inspected = await inspectCached(pass, canonical, null);
@@ -68871,7 +68973,7 @@ async function scanRootAsPackage(pass, resolvedRoot) {
68871
68973
  candidates: [
68872
68974
  locate(
68873
68975
  resolvedRoot,
68874
- { key: inspected.metadata.name, order: import_node_path41.default.basename(canonical) },
68976
+ { key: inspected.metadata.name, order: import_node_path42.default.basename(canonical) },
68875
68977
  canonical,
68876
68978
  canonical,
68877
68979
  inspected
@@ -68883,7 +68985,7 @@ async function scanRootAsPackage(pass, resolvedRoot) {
68883
68985
  } catch (error62) {
68884
68986
  return {
68885
68987
  candidates: [],
68886
- diagnostics: [invalid(resolvedRoot, import_node_path41.default.basename(canonical), error62)],
68988
+ diagnostics: [invalid(resolvedRoot, import_node_path42.default.basename(canonical), error62)],
68887
68989
  incomplete: false
68888
68990
  };
68889
68991
  }
@@ -68893,7 +68995,7 @@ async function scanRoot(pass, resolvedRoot) {
68893
68995
  if (asPackage !== null) return asPackage;
68894
68996
  let entries;
68895
68997
  try {
68896
- entries = await (0, import_promises47.readdir)(resolvedRoot.directory, { withFileTypes: true });
68998
+ entries = await (0, import_promises48.readdir)(resolvedRoot.directory, { withFileTypes: true });
68897
68999
  } catch (error62) {
68898
69000
  const code = errnoCode(error62);
68899
69001
  if (code === "ENOENT" || code === "ENOTDIR") {
@@ -68911,7 +69013,7 @@ async function scanRoot(pass, resolvedRoot) {
68911
69013
  incomplete: true
68912
69014
  };
68913
69015
  }
68914
- const canonicalRoot = await (0, import_promises47.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
69016
+ const canonicalRoot = await (0, import_promises48.realpath)(resolvedRoot.directory).catch(() => resolvedRoot.directory);
68915
69017
  const scan = { candidates: [], diagnostics: [], incomplete: false };
68916
69018
  for (const entry of entries) {
68917
69019
  if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
@@ -68923,7 +69025,7 @@ async function scanRoot(pass, resolvedRoot) {
68923
69025
  }
68924
69026
  async function scanEntry(pass, resolvedRoot, canonicalRoot, name) {
68925
69027
  const rootLabel = resolvedRoot.root.label;
68926
- const canonical = await (0, import_promises47.realpath)(import_node_path41.default.join(resolvedRoot.directory, name)).catch(() => null);
69028
+ const canonical = await (0, import_promises48.realpath)(import_node_path42.default.join(resolvedRoot.directory, name)).catch(() => null);
68927
69029
  if (canonical === null) {
68928
69030
  const message2 = `Could not resolve Skill ${name}`;
68929
69031
  return { kind: "diagnostic", diagnostic: { code: "SOURCE_UNREADABLE", message: message2, rootLabel } };
@@ -68939,7 +69041,7 @@ async function scanEntry(pass, resolvedRoot, canonicalRoot, name) {
68939
69041
  }
68940
69042
  if (!await isDirectory3(canonical) || pass.visited.has(canonical)) return null;
68941
69043
  pass.visited.add(canonical);
68942
- if (await exists3(import_node_path41.default.join(canonical, ".alan-managed.json"))) return null;
69044
+ if (await exists3(import_node_path42.default.join(canonical, ".alan-managed.json"))) return null;
68943
69045
  try {
68944
69046
  const inspected = await inspectCached(pass, canonical, void 0);
68945
69047
  const names = { key: name, order: name };
@@ -68960,7 +69062,7 @@ function resolveScanRoots(roots, enabledProviderKinds) {
68960
69062
  ).entries()) {
68961
69063
  resolved.push({
68962
69064
  root,
68963
- directory: import_node_path41.default.join(root.path, relative6),
69065
+ directory: import_node_path42.default.join(root.path, relative6),
68964
69066
  order: `1:${root.repositoryId}:${String(index).padStart(2, "0")}`
68965
69067
  });
68966
69068
  }
@@ -68982,11 +69084,11 @@ function candidateOrigin(root) {
68982
69084
  }
68983
69085
  function createLocalKey(root, skillName) {
68984
69086
  const rootIdentity = root.kind === "configured" ? `configured:${root.declarationId}` : root.kind === "repository" ? `repository:${root.repositoryId}` : "drafts";
68985
- const digest = (0, import_node_crypto21.createHash)("sha256").update("alan-local-skill-v1\0").update(rootIdentity).update("\0").update(skillName.normalize("NFC")).digest("hex");
69087
+ const digest = (0, import_node_crypto22.createHash)("sha256").update("alan-local-skill-v1\0").update(rootIdentity).update("\0").update(skillName.normalize("NFC")).digest("hex");
68986
69088
  return `local:${digest}`;
68987
69089
  }
68988
69090
  function hashInventory(candidates2) {
68989
- const hash2 = (0, import_node_crypto21.createHash)("sha256").update("alan-skill-inventory-v1\0");
69091
+ const hash2 = (0, import_node_crypto22.createHash)("sha256").update("alan-skill-inventory-v1\0");
68990
69092
  for (const candidate of candidates2) {
68991
69093
  hash2.update(candidate.localKey).update("\0");
68992
69094
  hash2.update(candidate.contentHash).update("\0");
@@ -69006,14 +69108,14 @@ function deduplicateByContent(candidates2) {
69006
69108
  return candidates2.filter((located) => winners.has(located));
69007
69109
  }
69008
69110
  async function fingerprintPackage(root) {
69009
- const hash2 = (0, import_node_crypto21.createHash)("sha256").update("alan-skill-stat-fingerprint-v1\0");
69111
+ const hash2 = (0, import_node_crypto22.createHash)("sha256").update("alan-skill-stat-fingerprint-v1\0");
69010
69112
  const visit2 = async (directory, relativeDirectory) => {
69011
- const entries = await (0, import_promises47.readdir)(directory, { withFileTypes: true });
69113
+ const entries = await (0, import_promises48.readdir)(directory, { withFileTypes: true });
69012
69114
  entries.sort((left, right) => Buffer.compare(Buffer.from(left.name), Buffer.from(right.name)));
69013
69115
  for (const entry of entries) {
69014
69116
  const relative6 = relativeDirectory ? `${relativeDirectory}/${entry.name}` : entry.name;
69015
- const absolute = import_node_path41.default.join(directory, entry.name);
69016
- const metadata = await (0, import_promises47.lstat)(absolute);
69117
+ const absolute = import_node_path42.default.join(directory, entry.name);
69118
+ const metadata = await (0, import_promises48.lstat)(absolute);
69017
69119
  const kind = entryKind(entry);
69018
69120
  hash2.update(relative6.normalize("NFC")).update(`\0${kind}\0${metadata.size}\0${metadata.mtimeMs}\0${metadata.mode & 511}\0`);
69019
69121
  if (entry.isDirectory()) await visit2(absolute, relative6);
@@ -69029,7 +69131,7 @@ function entryKind(entry) {
69029
69131
  }
69030
69132
  async function canonicalDirectories(directories) {
69031
69133
  const canonical = await Promise.all(
69032
- directories.map((directory) => (0, import_promises47.realpath)(directory).catch(() => directory))
69134
+ directories.map((directory) => (0, import_promises48.realpath)(directory).catch(() => directory))
69033
69135
  );
69034
69136
  return [...new Set(canonical)];
69035
69137
  }
@@ -69037,12 +69139,12 @@ function isManaged(pass, canonical) {
69037
69139
  return pass.managedRoots.some((root) => isWithinDirectory2(root, canonical));
69038
69140
  }
69039
69141
  function isWithinDirectory2(parent, candidate) {
69040
- const relative6 = import_node_path41.default.relative(parent, candidate);
69041
- return relative6 !== ".." && !relative6.startsWith(`..${import_node_path41.default.sep}`) && !import_node_path41.default.isAbsolute(relative6);
69142
+ const relative6 = import_node_path42.default.relative(parent, candidate);
69143
+ return relative6 !== ".." && !relative6.startsWith(`..${import_node_path42.default.sep}`) && !import_node_path42.default.isAbsolute(relative6);
69042
69144
  }
69043
69145
  async function exists3(candidate) {
69044
69146
  try {
69045
- await (0, import_promises47.access)(candidate);
69147
+ await (0, import_promises48.access)(candidate);
69046
69148
  return true;
69047
69149
  } catch {
69048
69150
  return false;
@@ -69050,7 +69152,7 @@ async function exists3(candidate) {
69050
69152
  }
69051
69153
  async function isDirectory3(candidate) {
69052
69154
  try {
69053
- return (await (0, import_promises47.lstat)(candidate)).isDirectory();
69155
+ return (await (0, import_promises48.lstat)(candidate)).isDirectory();
69054
69156
  } catch {
69055
69157
  return false;
69056
69158
  }
@@ -69098,7 +69200,7 @@ label = "OpenCode skills"
69098
69200
  providers = ["opencode_serve"]
69099
69201
  `;
69100
69202
  function skillSourceConfigPath(home) {
69101
- return import_node_path42.default.join(home, ".alan", "config.toml");
69203
+ return import_node_path43.default.join(home, ".alan", "config.toml");
69102
69204
  }
69103
69205
  async function resolveLocalScanInput(home, context, mode) {
69104
69206
  const loaded = await readSkillSourceConfig(home);
@@ -69110,13 +69212,13 @@ async function resolveLocalScanInput(home, context, mode) {
69110
69212
  }
69111
69213
  const enabledProviderKinds = context?.enabledProviderKinds ?? [];
69112
69214
  const enabled = new Set(enabledProviderKinds);
69113
- const drafts = import_node_path42.default.resolve(import_node_path42.default.join(home, ".alan", "skill-sources"));
69215
+ const drafts = import_node_path43.default.resolve(import_node_path43.default.join(home, ".alan", "skill-sources"));
69114
69216
  const roots = [];
69115
69217
  for (const source of config2.sources) {
69116
69218
  const owners = source.providerKinds;
69117
69219
  if (owners !== void 0 && !owners.some((provider4) => enabled.has(provider4))) continue;
69118
69220
  roots.push(
69119
- import_node_path42.default.resolve(source.path) === drafts ? { kind: "drafts", path: source.path, label: "Alan drafts" } : {
69221
+ import_node_path43.default.resolve(source.path) === drafts ? { kind: "drafts", path: source.path, label: "Alan drafts" } : {
69120
69222
  kind: "configured",
69121
69223
  declarationId: source.declarationId,
69122
69224
  path: source.path,
@@ -69138,7 +69240,7 @@ async function resolveLocalScanInput(home, context, mode) {
69138
69240
  async function readSkillSourceConfig(home) {
69139
69241
  let content;
69140
69242
  try {
69141
- content = await (0, import_promises48.readFile)(skillSourceConfigPath(home), "utf8");
69243
+ content = await (0, import_promises49.readFile)(skillSourceConfigPath(home), "utf8");
69142
69244
  } catch (error62) {
69143
69245
  if (errnoCode(error62) !== "ENOENT") {
69144
69246
  return { kind: "invalid_config", diagnostic: "~/.alan/config.toml could not be read" };
@@ -69180,7 +69282,7 @@ function parseSkillSourceConfig(content, home) {
69180
69282
  const label = value2.label.trim();
69181
69283
  if (!label) throw new Error(`skills.sources entry ${index + 1} has an empty label`);
69182
69284
  const declarationId = value2.id === void 0 ? stableSourceDeclarationId(sourcePath) : requiredSourceId(value2.id, `skills.sources[${index}].id`);
69183
- const relativeDirectory = import_node_path42.default.relative(home, sourcePath);
69285
+ const relativeDirectory = import_node_path43.default.relative(home, sourcePath);
69184
69286
  const inferred = providerKindsForUserDirectory(relativeDirectory);
69185
69287
  const declared = value2.providers === void 0 ? inferred : [
69186
69288
  ...new Set(
@@ -69212,7 +69314,7 @@ function staleCodexDeclaration(relativeDirectory, label, providerKinds) {
69212
69314
  return ownedByCursor || label === "Legacy Cursor-compatible skills";
69213
69315
  }
69214
69316
  function stableSourceDeclarationId(sourcePath) {
69215
- const digest = (0, import_node_crypto22.createHash)("sha256").update("alan-skill-source-v1\0").update(sourcePath.normalize("NFC")).digest("hex").slice(0, 24);
69317
+ const digest = (0, import_node_crypto23.createHash)("sha256").update("alan-skill-source-v1\0").update(sourcePath.normalize("NFC")).digest("hex").slice(0, 24);
69216
69318
  return `source-${digest}`;
69217
69319
  }
69218
69320
  function requiredSourceId(value2, field3) {
@@ -69223,12 +69325,12 @@ function requiredSourceId(value2, field3) {
69223
69325
  }
69224
69326
  function resolveSkillSourcePath(sourcePath, home) {
69225
69327
  const trimmed4 = sourcePath.trim();
69226
- if (trimmed4 === "~") return import_node_path42.default.resolve(home);
69328
+ if (trimmed4 === "~") return import_node_path43.default.resolve(home);
69227
69329
  if (trimmed4.startsWith("~/") || trimmed4.startsWith("~\\")) {
69228
69330
  const components = trimmed4.slice(2).split(/[\\/]+/).filter(Boolean);
69229
- return import_node_path42.default.resolve(import_node_path42.default.join(home, ...components));
69331
+ return import_node_path43.default.resolve(import_node_path43.default.join(home, ...components));
69230
69332
  }
69231
- return import_node_path42.default.isAbsolute(trimmed4) ? import_node_path42.default.resolve(trimmed4) : import_node_path42.default.resolve(home, trimmed4);
69333
+ return import_node_path43.default.isAbsolute(trimmed4) ? import_node_path43.default.resolve(trimmed4) : import_node_path43.default.resolve(home, trimmed4);
69232
69334
  }
69233
69335
  function optionalBoolean(value2, fallback, field3) {
69234
69336
  if (value2 === void 0) return fallback;
@@ -69255,14 +69357,14 @@ async function scanLocalSkills(home, context, cache2, mode = "incremental", mana
69255
69357
  }
69256
69358
 
69257
69359
  // src/capabilities/skills/store.ts
69258
- var import_promises49 = require("fs/promises");
69259
- var import_node_path43 = require("path");
69360
+ var import_promises50 = require("fs/promises");
69361
+ var import_node_path44 = require("path");
69260
69362
 
69261
69363
  // ../shared/dist/node/alan-skill-identity.js
69262
- var import_node_crypto23 = require("crypto");
69364
+ var import_node_crypto24 = require("crypto");
69263
69365
  var ALAN_SKILL_NAMESPACE = "ec71d99b-d207-4ca2-a9eb-3a7bed4a73fd";
69264
69366
  function uuidV5(name, namespace) {
69265
- const bytes = (0, import_node_crypto23.createHash)("sha1").update(Buffer.from(namespace.replaceAll("-", ""), "hex")).update(name, "utf8").digest().subarray(0, 16);
69367
+ const bytes = (0, import_node_crypto24.createHash)("sha1").update(Buffer.from(namespace.replaceAll("-", ""), "hex")).update(name, "utf8").digest().subarray(0, 16);
69266
69368
  bytes[6] = bytes[6] & 15 | 80;
69267
69369
  bytes[8] = bytes[8] & 63 | 128;
69268
69370
  const hex3 = bytes.toString("hex");
@@ -69279,21 +69381,21 @@ function alanSkillVersionId(slug, contentHash) {
69279
69381
  init_runtime_v2();
69280
69382
  init_zod();
69281
69383
  function skillsLayout(stateDir, home) {
69282
- const root = (0, import_node_path43.join)(stateDir, "skills");
69384
+ const root = (0, import_node_path44.join)(stateDir, "skills");
69283
69385
  return {
69284
69386
  root,
69285
- installedFile: (0, import_node_path43.join)(root, "installed.json"),
69286
- retiredFile: (0, import_node_path43.join)(root, "retired.json"),
69287
- localFile: (0, import_node_path43.join)(root, "local.json"),
69288
- versionsDir: (0, import_node_path43.join)(root, "versions"),
69289
- tmpDir: (0, import_node_path43.join)(root, "tmp"),
69290
- pluginDir: (0, import_node_path43.join)(root, "alan-plugin"),
69291
- pluginSkillsDir: (0, import_node_path43.join)(root, "alan-plugin", "skills"),
69292
- nativeDir: home === void 0 || home === "" ? null : (0, import_node_path43.join)(home, ".agents", "skills")
69387
+ installedFile: (0, import_node_path44.join)(root, "installed.json"),
69388
+ retiredFile: (0, import_node_path44.join)(root, "retired.json"),
69389
+ localFile: (0, import_node_path44.join)(root, "local.json"),
69390
+ versionsDir: (0, import_node_path44.join)(root, "versions"),
69391
+ tmpDir: (0, import_node_path44.join)(root, "tmp"),
69392
+ pluginDir: (0, import_node_path44.join)(root, "alan-plugin"),
69393
+ pluginSkillsDir: (0, import_node_path44.join)(root, "alan-plugin", "skills"),
69394
+ nativeDir: home === void 0 || home === "" ? null : (0, import_node_path44.join)(home, ".agents", "skills")
69293
69395
  };
69294
69396
  }
69295
69397
  function packageDirectory(layout, versionId) {
69296
- return (0, import_node_path43.join)(layout.versionsDir, versionId);
69398
+ return (0, import_node_path44.join)(layout.versionsDir, versionId);
69297
69399
  }
69298
69400
  var installedFileSchema = external_exports.object({ skills: external_exports.array(desiredMachineSkillSchema) });
69299
69401
  async function readInstalledSkills(layout) {
@@ -69326,7 +69428,7 @@ function writeLocalSkills(layout, file2) {
69326
69428
  async function isLocalSkillCurrent(entry, contentHash, ignoredPaths) {
69327
69429
  if (entry.contentHash !== contentHash) return false;
69328
69430
  try {
69329
- if (await (0, import_promises49.realpath)(entry.path) !== entry.path) return false;
69431
+ if (await (0, import_promises50.realpath)(entry.path) !== entry.path) return false;
69330
69432
  const inspected = await inspectSkillPackage(entry.path, { expectedName: null, ignoredPaths });
69331
69433
  return inspected.contentHash === contentHash;
69332
69434
  } catch {
@@ -69341,7 +69443,7 @@ async function resolveLocalSkill(local, invocation) {
69341
69443
  }
69342
69444
  async function hasSkillFile(directory) {
69343
69445
  try {
69344
- return (await (0, import_promises49.stat)((0, import_node_path43.join)(directory, "SKILL.md"))).isFile();
69446
+ return (await (0, import_promises50.stat)((0, import_node_path44.join)(directory, "SKILL.md"))).isFile();
69345
69447
  } catch {
69346
69448
  return false;
69347
69449
  }
@@ -69359,7 +69461,7 @@ async function isIntact(layout, skill) {
69359
69461
  async function resolveNativeBuiltIn(layout, invocation, baked) {
69360
69462
  const slug = invocation.displayName;
69361
69463
  if (layout.nativeDir === null || invocation.skillId !== alanSkillId(slug)) return null;
69362
- const directory = (0, import_node_path43.join)(layout.nativeDir, slug);
69464
+ const directory = (0, import_node_path44.join)(layout.nativeDir, slug);
69363
69465
  try {
69364
69466
  const inspected = await inspectSkillPackage(directory, { expectedName: slug });
69365
69467
  if (baked === "exact" && alanSkillVersionId(slug, inspected.contentHash) !== invocation.versionId)
@@ -69405,10 +69507,10 @@ async function availableSkillIndex(layout) {
69405
69507
  });
69406
69508
  }
69407
69509
  if (layout.nativeDir !== null) {
69408
- const entries = await (0, import_promises49.readdir)(layout.nativeDir, { withFileTypes: true }).catch(() => []);
69510
+ const entries = await (0, import_promises50.readdir)(layout.nativeDir, { withFileTypes: true }).catch(() => []);
69409
69511
  for (const entry of entries) {
69410
69512
  if (entry.isDirectory() || entry.isSymbolicLink())
69411
- candidates2.push({ directory: (0, import_node_path43.join)(layout.nativeDir, entry.name) });
69513
+ candidates2.push({ directory: (0, import_node_path44.join)(layout.nativeDir, entry.name) });
69412
69514
  }
69413
69515
  }
69414
69516
  const bounded = candidates2.slice(0, 2e3);
@@ -69488,7 +69590,7 @@ async function readLocalSkillFile(layout, ref) {
69488
69590
  mediaType: file2.path.toLowerCase().endsWith(".md") ? "text/markdown; charset=utf-8" : "text/plain; charset=utf-8"
69489
69591
  };
69490
69592
  }
69491
- const mediaType = RASTER_MEDIA_TYPES.get(import_node_path44.default.extname(file2.path).toLowerCase());
69593
+ const mediaType = RASTER_MEDIA_TYPES.get(import_node_path45.default.extname(file2.path).toLowerCase());
69492
69594
  if (file2.preview === "image" && mediaType !== void 0) {
69493
69595
  return bytes.byteLength <= MAX_INLINE_IMAGE_BYTES ? { file: file2, encoding: "base64", content: bytes.toString("base64"), mediaType } : { file: file2, encoding: "metadata", mediaType };
69494
69596
  }
@@ -69496,7 +69598,7 @@ async function readLocalSkillFile(layout, ref) {
69496
69598
  }
69497
69599
  async function isDirectory4(candidate) {
69498
69600
  try {
69499
- return (await (0, import_promises50.stat)(candidate)).isDirectory();
69601
+ return (await (0, import_promises51.stat)(candidate)).isDirectory();
69500
69602
  } catch {
69501
69603
  return false;
69502
69604
  }
@@ -69509,21 +69611,21 @@ async function addSkillSource(home, input2) {
69509
69611
  return { state: "invalid", diagnostic: `${sourcePath} is not a folder` };
69510
69612
  }
69511
69613
  const configPath = skillSourceConfigPath(home);
69512
- await (0, import_promises50.mkdir)(import_node_path44.default.dirname(configPath), { recursive: true, mode: 448 });
69513
- await (0, import_promises50.writeFile)(configPath, DEFAULT_SKILL_CONFIG, { flag: "wx", mode: 384 }).catch(
69614
+ await (0, import_promises51.mkdir)(import_node_path45.default.dirname(configPath), { recursive: true, mode: 448 });
69615
+ await (0, import_promises51.writeFile)(configPath, DEFAULT_SKILL_CONFIG, { flag: "wx", mode: 384 }).catch(
69514
69616
  (error62) => {
69515
69617
  if (errnoCode(error62) !== "EEXIST") throw error62;
69516
69618
  }
69517
69619
  );
69518
69620
  const loaded = await readSkillSourceConfig(home);
69519
69621
  if (loaded.kind === "invalid_config") return { state: "invalid", diagnostic: loaded.diagnostic };
69520
- const canonical = await (0, import_promises50.realpath)(sourcePath).catch(() => sourcePath);
69622
+ const canonical = await (0, import_promises51.realpath)(sourcePath).catch(() => sourcePath);
69521
69623
  for (const source of loaded.config.sources) {
69522
- if (await (0, import_promises50.realpath)(source.path).catch(() => source.path) === canonical) {
69624
+ if (await (0, import_promises51.realpath)(source.path).catch(() => source.path) === canonical) {
69523
69625
  return { state: "already_present", label: source.label };
69524
69626
  }
69525
69627
  }
69526
- const current = await (0, import_promises50.readFile)(configPath, "utf8");
69628
+ const current = await (0, import_promises51.readFile)(configPath, "utf8");
69527
69629
  const block2 = [
69528
69630
  "",
69529
69631
  "[[skills.sources]]",
@@ -69531,7 +69633,7 @@ async function addSkillSource(home, input2) {
69531
69633
  `label = ${JSON.stringify(label)}`,
69532
69634
  ""
69533
69635
  ].join("\n");
69534
- await (0, import_promises50.writeFile)(configPath, `${current.replace(/\n*$/, "\n")}${block2}`, { mode: 384 });
69636
+ await (0, import_promises51.writeFile)(configPath, `${current.replace(/\n*$/, "\n")}${block2}`, { mode: 384 });
69535
69637
  const reloaded = await readSkillSourceConfig(home);
69536
69638
  if (reloaded.kind === "invalid_config") {
69537
69639
  return { state: "invalid", diagnostic: reloaded.diagnostic };
@@ -69540,13 +69642,13 @@ async function addSkillSource(home, input2) {
69540
69642
  }
69541
69643
 
69542
69644
  // src/capabilities/skills/local-upload.ts
69543
- var import_promises52 = require("fs/promises");
69645
+ var import_promises53 = require("fs/promises");
69544
69646
 
69545
69647
  // ../shared/dist/node/skill-bundle.js
69546
69648
  var import_node_buffer2 = require("buffer");
69547
- var import_node_crypto24 = require("crypto");
69548
- var import_promises51 = require("fs/promises");
69549
- var import_node_path45 = require("path");
69649
+ var import_node_crypto25 = require("crypto");
69650
+ var import_promises52 = require("fs/promises");
69651
+ var import_node_path46 = require("path");
69550
69652
  var import_node_stream = require("stream");
69551
69653
  var import_node_zlib = require("zlib");
69552
69654
  var import_tar_stream = __toESM(require_tar_stream(), 1);
@@ -69556,7 +69658,7 @@ async function createSkillBundle(packageRoot, options = {}) {
69556
69658
  const archive = (0, import_tar_stream.pack)();
69557
69659
  const tarPromise = collectStream(archive);
69558
69660
  for (const file2 of before.files) {
69559
- const bytes2 = await (0, import_promises51.readFile)((0, import_node_path45.join)(packageRoot, ...file2.path.split("/")));
69661
+ const bytes2 = await (0, import_promises52.readFile)((0, import_node_path46.join)(packageRoot, ...file2.path.split("/")));
69560
69662
  await addArchiveEntry(archive, {
69561
69663
  name: file2.path,
69562
69664
  type: "file",
@@ -69588,7 +69690,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
69588
69690
  throw new Error("Skill archive hash does not match the expected immutable Version");
69589
69691
  }
69590
69692
  const tarBytes = await decompressBounded(archiveBytes);
69591
- await (0, import_promises51.mkdir)(destination, { recursive: false, mode: 448 });
69693
+ await (0, import_promises52.mkdir)(destination, { recursive: false, mode: 448 });
69592
69694
  try {
69593
69695
  await extractTar(tarBytes, destination);
69594
69696
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -69596,7 +69698,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
69596
69698
  throw new Error("Extracted Skill package hash does not match the expected immutable Version");
69597
69699
  }
69598
69700
  } catch (error62) {
69599
- await (0, import_promises51.rm)(destination, { recursive: true, force: true });
69701
+ await (0, import_promises52.rm)(destination, { recursive: true, force: true });
69600
69702
  throw error62;
69601
69703
  }
69602
69704
  }
@@ -69671,19 +69773,19 @@ async function extractEntry(header, stream, destination, limits) {
69671
69773
  if (bytes.byteLength !== declaredSize) {
69672
69774
  throw new Error(`Skill archive file size is invalid: ${path4}`);
69673
69775
  }
69674
- const outputPath = (0, import_node_path45.join)(destination, ...path4.split("/"));
69675
- await (0, import_promises51.mkdir)((0, import_node_path45.dirname)(outputPath), { recursive: true, mode: 448 });
69676
- await (0, import_promises51.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
69776
+ const outputPath = (0, import_node_path46.join)(destination, ...path4.split("/"));
69777
+ await (0, import_promises52.mkdir)((0, import_node_path46.dirname)(outputPath), { recursive: true, mode: 448 });
69778
+ await (0, import_promises52.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
69677
69779
  }
69678
69780
  function requireSafeArchivePath(value2) {
69679
69781
  const normalized2 = value2.replaceAll("\\", "/").normalize("NFC");
69680
- if (!normalized2 || normalized2.startsWith("/") || normalized2.includes("\0") || import_node_path45.posix.normalize(normalized2) !== normalized2 || normalized2 === ".." || normalized2.startsWith("../")) {
69782
+ if (!normalized2 || normalized2.startsWith("/") || normalized2.includes("\0") || import_node_path46.posix.normalize(normalized2) !== normalized2 || normalized2 === ".." || normalized2.startsWith("../")) {
69681
69783
  throw new Error(`Skill archive contains an unsafe path: ${value2}`);
69682
69784
  }
69683
69785
  return normalized2;
69684
69786
  }
69685
69787
  function sha2563(bytes) {
69686
- return `sha256:${(0, import_node_crypto24.createHash)("sha256").update(bytes).digest("hex")}`;
69788
+ return `sha256:${(0, import_node_crypto25.createHash)("sha256").update(bytes).digest("hex")}`;
69687
69789
  }
69688
69790
 
69689
69791
  // src/capabilities/skills/local-upload.ts
@@ -69699,8 +69801,8 @@ async function publishLocalSkill(options) {
69699
69801
  if (Date.parse(request2.uploadGrant.expiresAt) <= (options.now ?? Date.now())) {
69700
69802
  throw new RuntimeFault("invalid_file", "Skill upload grant expired");
69701
69803
  }
69702
- const folder = await (0, import_promises52.lstat)(entry.path);
69703
- if (!folder.isDirectory() || await (0, import_promises52.realpath)(entry.path) !== entry.path) {
69804
+ const folder = await (0, import_promises53.lstat)(entry.path);
69805
+ if (!folder.isDirectory() || await (0, import_promises53.realpath)(entry.path) !== entry.path) {
69704
69806
  throw new RuntimeFault("invalid_file", "Skill folder moved since the last scan");
69705
69807
  }
69706
69808
  const bundle = await createSkillBundle(entry.path, {
@@ -69727,10 +69829,10 @@ async function publishLocalSkill(options) {
69727
69829
  }
69728
69830
 
69729
69831
  // src/capabilities/skills/native-index.ts
69730
- var import_node_crypto25 = require("crypto");
69832
+ var import_node_crypto26 = require("crypto");
69731
69833
  var import_node_fs17 = require("fs");
69732
- var import_promises53 = require("fs/promises");
69733
- var import_node_path46 = require("path");
69834
+ var import_promises54 = require("fs/promises");
69835
+ var import_node_path47 = require("path");
69734
69836
  var ALAN_SKILLS_PLUGIN_NAME = "alan";
69735
69837
  var PLUGIN_MANIFEST = `${JSON.stringify(
69736
69838
  {
@@ -69743,32 +69845,32 @@ var PLUGIN_MANIFEST = `${JSON.stringify(
69743
69845
  `;
69744
69846
  async function entryKind2(path4) {
69745
69847
  try {
69746
- return (await (0, import_promises53.lstat)(path4)).isSymbolicLink() ? "link" : "other";
69848
+ return (await (0, import_promises54.lstat)(path4)).isSymbolicLink() ? "link" : "other";
69747
69849
  } catch (error62) {
69748
69850
  if (errnoCode(error62) === "ENOENT") return "missing";
69749
69851
  throw error62;
69750
69852
  }
69751
69853
  }
69752
69854
  async function linkTarget(path4) {
69753
- return (0, import_promises53.readlink)(path4).catch(() => null);
69855
+ return (0, import_promises54.readlink)(path4).catch(() => null);
69754
69856
  }
69755
69857
  async function removeLink(path4) {
69756
69858
  try {
69757
- await (0, import_promises53.unlink)(path4);
69859
+ await (0, import_promises54.unlink)(path4);
69758
69860
  } catch (error62) {
69759
69861
  const code = errnoCode(error62);
69760
69862
  if (code === "ENOENT") return;
69761
69863
  if (code !== "EPERM" && code !== "EISDIR") throw error62;
69762
- await (0, import_promises53.rmdir)(path4);
69864
+ await (0, import_promises54.rmdir)(path4);
69763
69865
  }
69764
69866
  }
69765
69867
  async function placeLink(plan2, platform3) {
69766
69868
  if (await linkTarget(plan2.path) === plan2.target) return false;
69767
- const staged = (0, import_node_path46.join)((0, import_node_path46.dirname)(plan2.path), `.${(0, import_node_path46.basename)(plan2.path)}.${(0, import_node_crypto25.randomUUID)()}.tmp`);
69768
- await (0, import_promises53.symlink)(plan2.target, staged, platform3 === "win32" ? "junction" : "dir");
69869
+ const staged = (0, import_node_path47.join)((0, import_node_path47.dirname)(plan2.path), `.${(0, import_node_path47.basename)(plan2.path)}.${(0, import_node_crypto26.randomUUID)()}.tmp`);
69870
+ await (0, import_promises54.symlink)(plan2.target, staged, platform3 === "win32" ? "junction" : "dir");
69769
69871
  try {
69770
69872
  if (platform3 === "win32") await removeLink(plan2.path);
69771
- await (0, import_promises53.rename)(staged, plan2.path);
69873
+ await (0, import_promises54.rename)(staged, plan2.path);
69772
69874
  } catch (error62) {
69773
69875
  await removeLink(staged).catch(() => void 0);
69774
69876
  throw error62;
@@ -69776,37 +69878,37 @@ async function placeLink(plan2, platform3) {
69776
69878
  return true;
69777
69879
  }
69778
69880
  function versionTarget(layout, versionId, platform3) {
69779
- const absolute = (0, import_node_path46.join)(layout.versionsDir, versionId);
69780
- return platform3 === "win32" ? absolute : (0, import_node_path46.relative)(layout.pluginSkillsDir, absolute);
69881
+ const absolute = (0, import_node_path47.join)(layout.versionsDir, versionId);
69882
+ return platform3 === "win32" ? absolute : (0, import_node_path47.relative)(layout.pluginSkillsDir, absolute);
69781
69883
  }
69782
69884
  async function writeManifest(layout) {
69783
- const manifest = (0, import_node_path46.join)(layout.pluginDir, ".claude-plugin", "plugin.json");
69784
- if (await (0, import_promises53.readFile)(manifest, "utf8").catch(() => null) === PLUGIN_MANIFEST) return;
69785
- await (0, import_promises53.mkdir)((0, import_node_path46.dirname)(manifest), { recursive: true, mode: 448 });
69786
- const staged = `${manifest}.${(0, import_node_crypto25.randomUUID)()}.tmp`;
69787
- await (0, import_promises53.writeFile)(staged, PLUGIN_MANIFEST, { mode: 384 });
69788
- await (0, import_promises53.rename)(staged, manifest);
69885
+ const manifest = (0, import_node_path47.join)(layout.pluginDir, ".claude-plugin", "plugin.json");
69886
+ if (await (0, import_promises54.readFile)(manifest, "utf8").catch(() => null) === PLUGIN_MANIFEST) return;
69887
+ await (0, import_promises54.mkdir)((0, import_node_path47.dirname)(manifest), { recursive: true, mode: 448 });
69888
+ const staged = `${manifest}.${(0, import_node_crypto26.randomUUID)()}.tmp`;
69889
+ await (0, import_promises54.writeFile)(staged, PLUGIN_MANIFEST, { mode: 384 });
69890
+ await (0, import_promises54.rename)(staged, manifest);
69789
69891
  }
69790
69892
  async function reconcilePluginSkills(layout, installed, platform3) {
69791
- await (0, import_promises53.mkdir)(layout.pluginSkillsDir, { recursive: true, mode: 448 });
69893
+ await (0, import_promises54.mkdir)(layout.pluginSkillsDir, { recursive: true, mode: 448 });
69792
69894
  const wanted = new Map(installed.map((skill) => [skill.slug, skill]));
69793
69895
  let linked = 0;
69794
69896
  for (const skill of installed) {
69795
69897
  const plan2 = {
69796
- path: (0, import_node_path46.join)(layout.pluginSkillsDir, skill.slug),
69898
+ path: (0, import_node_path47.join)(layout.pluginSkillsDir, skill.slug),
69797
69899
  target: versionTarget(layout, skill.versionId, platform3)
69798
69900
  };
69799
69901
  if (await entryKind2(plan2.path) === "other") {
69800
- await (0, import_promises53.rm)(plan2.path, { recursive: true, force: true });
69902
+ await (0, import_promises54.rm)(plan2.path, { recursive: true, force: true });
69801
69903
  }
69802
69904
  if (await placeLink(plan2, platform3)) linked += 1;
69803
69905
  }
69804
69906
  let unlinked = 0;
69805
- for (const name of await (0, import_promises53.readdir)(layout.pluginSkillsDir)) {
69907
+ for (const name of await (0, import_promises54.readdir)(layout.pluginSkillsDir)) {
69806
69908
  if (wanted.has(name)) continue;
69807
- const path4 = (0, import_node_path46.join)(layout.pluginSkillsDir, name);
69909
+ const path4 = (0, import_node_path47.join)(layout.pluginSkillsDir, name);
69808
69910
  if (await entryKind2(path4) === "link") await removeLink(path4);
69809
- else await (0, import_promises53.rm)(path4, { recursive: true, force: true });
69911
+ else await (0, import_promises54.rm)(path4, { recursive: true, force: true });
69810
69912
  unlinked += 1;
69811
69913
  }
69812
69914
  return { linked, unlinked };
@@ -69814,17 +69916,17 @@ async function reconcilePluginSkills(layout, installed, platform3) {
69814
69916
  async function isOwnCodexLink(layout, path4) {
69815
69917
  const target = await linkTarget(path4);
69816
69918
  if (target === null) return false;
69817
- const absolute = (0, import_node_path46.isAbsolute)(target) ? target : (0, import_node_path46.resolve)((0, import_node_path46.dirname)(path4), target);
69919
+ const absolute = (0, import_node_path47.isAbsolute)(target) ? target : (0, import_node_path47.resolve)((0, import_node_path47.dirname)(path4), target);
69818
69920
  return isWithinDirectory2(layout.pluginSkillsDir, absolute);
69819
69921
  }
69820
69922
  async function isForeignPackage(layout, path4) {
69821
- const resolved = await (0, import_promises53.realpath)(path4).catch(() => null);
69923
+ const resolved = await (0, import_promises54.realpath)(path4).catch(() => null);
69822
69924
  if (resolved === null) return false;
69823
- const root = await (0, import_promises53.realpath)(layout.root).catch(() => layout.root);
69925
+ const root = await (0, import_promises54.realpath)(layout.root).catch(() => layout.root);
69824
69926
  return !isWithinDirectory2(root, resolved);
69825
69927
  }
69826
69928
  async function codexSlot(layout, path4, slug) {
69827
- const baked = layout.nativeDir !== null && await isForeignPackage(layout, (0, import_node_path46.join)(layout.nativeDir, slug));
69929
+ const baked = layout.nativeDir !== null && await isForeignPackage(layout, (0, import_node_path47.join)(layout.nativeDir, slug));
69828
69930
  const kind = await entryKind2(path4);
69829
69931
  if (kind === "other") return "taken";
69830
69932
  const ours = kind === "link" && await isOwnCodexLink(layout, path4);
@@ -69837,8 +69939,8 @@ async function codexSlot(layout, path4, slug) {
69837
69939
  }
69838
69940
  async function unlinkStaleCodexEntries(layout, codexSkillsDir, wanted) {
69839
69941
  let unlinked = 0;
69840
- for (const name of await (0, import_promises53.readdir)(codexSkillsDir)) {
69841
- const path4 = (0, import_node_path46.join)(codexSkillsDir, name);
69942
+ for (const name of await (0, import_promises54.readdir)(codexSkillsDir)) {
69943
+ const path4 = (0, import_node_path47.join)(codexSkillsDir, name);
69842
69944
  if (wanted.has(name) && !name.endsWith(".tmp")) continue;
69843
69945
  if (await entryKind2(path4) !== "link" || !await isOwnCodexLink(layout, path4)) continue;
69844
69946
  await removeLink(path4);
@@ -69847,15 +69949,15 @@ async function unlinkStaleCodexEntries(layout, codexSkillsDir, wanted) {
69847
69949
  return unlinked;
69848
69950
  }
69849
69951
  async function reconcileCodexSkills(layout, installed, codexSkillsDir, platform3) {
69850
- await (0, import_promises53.mkdir)(codexSkillsDir, { recursive: true, mode: 448 });
69952
+ await (0, import_promises54.mkdir)(codexSkillsDir, { recursive: true, mode: 448 });
69851
69953
  const report2 = { linked: 0, unlinked: 0, skipped: [] };
69852
69954
  for (const skill of installed) {
69853
- const path4 = (0, import_node_path46.join)(codexSkillsDir, skill.slug);
69955
+ const path4 = (0, import_node_path47.join)(codexSkillsDir, skill.slug);
69854
69956
  if (await codexSlot(layout, path4, skill.slug) === "taken") {
69855
69957
  report2.skipped.push(skill.slug);
69856
69958
  continue;
69857
69959
  }
69858
- const target = (0, import_node_path46.join)(layout.pluginSkillsDir, skill.slug);
69960
+ const target = (0, import_node_path47.join)(layout.pluginSkillsDir, skill.slug);
69859
69961
  if (await placeLink({ path: path4, target }, platform3)) report2.linked += 1;
69860
69962
  }
69861
69963
  const wanted = new Set(installed.map((skill) => skill.slug));
@@ -69879,41 +69981,41 @@ async function reconcileNativeIndex(layout, installed, options) {
69879
69981
  };
69880
69982
  }
69881
69983
  function installedSkillFolders(layout) {
69882
- return (0, import_node_fs17.existsSync)((0, import_node_path46.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
69984
+ return (0, import_node_fs17.existsSync)((0, import_node_path47.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
69883
69985
  }
69884
69986
 
69885
69987
  // src/capabilities/skills/sync.ts
69886
- var import_node_crypto26 = require("crypto");
69887
- var import_promises54 = require("fs/promises");
69888
- var import_node_path47 = require("path");
69988
+ var import_node_crypto27 = require("crypto");
69989
+ var import_promises55 = require("fs/promises");
69990
+ var import_node_path48 = require("path");
69889
69991
  init_zod();
69890
69992
  var SKILL_PREPARE_WAIT_MS = 15e3;
69891
69993
  var FIRST_INSTALL_WAIT_MS = 5e3;
69892
69994
  var RETIRED_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
69893
69995
  async function makeFilesReadOnly(directory, platform3) {
69894
69996
  if (platform3 === "win32") return;
69895
- for (const entry of await (0, import_promises54.readdir)(directory, { withFileTypes: true })) {
69896
- const path4 = (0, import_node_path47.join)(directory, entry.name);
69997
+ for (const entry of await (0, import_promises55.readdir)(directory, { withFileTypes: true })) {
69998
+ const path4 = (0, import_node_path48.join)(directory, entry.name);
69897
69999
  if (entry.isDirectory()) await makeFilesReadOnly(path4, platform3);
69898
70000
  else if (entry.isFile()) {
69899
- const executable = ((await (0, import_promises54.lstat)(path4)).mode & 64) !== 0;
69900
- await (0, import_promises54.chmod)(path4, executable ? 365 : 292);
70001
+ const executable = ((await (0, import_promises55.lstat)(path4)).mode & 64) !== 0;
70002
+ await (0, import_promises55.chmod)(path4, executable ? 365 : 292);
69901
70003
  }
69902
70004
  }
69903
70005
  }
69904
70006
  async function install(env, skill, download, signal) {
69905
70007
  const { layout, source, platform: platform3 } = env;
69906
70008
  const bytes = await source.download(download.url, signal);
69907
- await (0, import_promises54.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
69908
- const staging = (0, import_node_path47.join)(layout.tmpDir, (0, import_node_crypto26.randomUUID)());
70009
+ await (0, import_promises55.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
70010
+ const staging = (0, import_node_path48.join)(layout.tmpDir, (0, import_node_crypto27.randomUUID)());
69909
70011
  await extractSkillBundle(Buffer.from(bytes), staging, {
69910
70012
  expectedArchiveHash: download.archiveHash,
69911
70013
  expectedContentHash: skill.contentHash
69912
70014
  });
69913
70015
  const target = packageDirectory(layout, skill.versionId);
69914
- await (0, import_promises54.mkdir)(layout.versionsDir, { recursive: true, mode: 448 });
69915
- await (0, import_promises54.rm)(target, { recursive: true, force: true });
69916
- await (0, import_promises54.rename)(staging, target);
70016
+ await (0, import_promises55.mkdir)(layout.versionsDir, { recursive: true, mode: 448 });
70017
+ await (0, import_promises55.rm)(target, { recursive: true, force: true });
70018
+ await (0, import_promises55.rename)(staging, target);
69917
70019
  await makeFilesReadOnly(target, platform3);
69918
70020
  }
69919
70021
  var retiredFileSchema = external_exports.record(external_exports.string(), external_exports.number());
@@ -69925,14 +70027,14 @@ async function sweep(env, keep) {
69925
70027
  const now = env.now();
69926
70028
  const stillRetired = {};
69927
70029
  const expired = [];
69928
- for (const name of await (0, import_promises54.readdir)(layout.versionsDir).catch(() => [])) {
70030
+ for (const name of await (0, import_promises55.readdir)(layout.versionsDir).catch(() => [])) {
69929
70031
  if (kept.has(name)) continue;
69930
70032
  const since = retired[name] ?? now;
69931
70033
  if (now - since >= RETIRED_VERSION_RETENTION_MS) expired.push(name);
69932
70034
  else stillRetired[name] = since;
69933
70035
  }
69934
70036
  const results = await Promise.allSettled(
69935
- expired.map((name) => (0, import_promises54.rm)((0, import_node_path47.join)(layout.versionsDir, name), { recursive: true, force: true }))
70037
+ expired.map((name) => (0, import_promises55.rm)((0, import_node_path48.join)(layout.versionsDir, name), { recursive: true, force: true }))
69936
70038
  );
69937
70039
  results.forEach((result, index) => {
69938
70040
  const name = expired[index];
@@ -69941,7 +70043,7 @@ async function sweep(env, keep) {
69941
70043
  if (JSON.stringify(stillRetired) !== JSON.stringify(retired)) {
69942
70044
  await writeJsonFileAtomic(layout.retiredFile, stillRetired);
69943
70045
  }
69944
- await (0, import_promises54.rm)(layout.tmpDir, { recursive: true, force: true });
70046
+ await (0, import_promises55.rm)(layout.tmpDir, { recursive: true, force: true });
69945
70047
  return results.filter((result) => result.status === "fulfilled").length;
69946
70048
  }
69947
70049
  async function intactSkills(layout) {
@@ -70278,15 +70380,15 @@ function openMachineSkills(options) {
70278
70380
  }
70279
70381
 
70280
70382
  // src/capabilities/workspace/index.ts
70281
- var import_node_path50 = require("path");
70383
+ var import_node_path51 = require("path");
70282
70384
  init_runtime_v2();
70283
70385
 
70284
70386
  // src/capabilities/workspace/approved-paths.ts
70285
- var import_promises55 = require("fs/promises");
70387
+ var import_promises56 = require("fs/promises");
70286
70388
  init_zod();
70287
70389
 
70288
70390
  // src/capabilities/workspace/paths.ts
70289
- var import_node_path48 = require("path");
70391
+ var import_node_path49 = require("path");
70290
70392
  function stripWin32Namespace(path4) {
70291
70393
  if (/^\\\\\?\\UNC\\/i.test(path4)) return `\\\\${path4.slice(8)}`;
70292
70394
  if (path4.startsWith("\\\\?\\")) return path4.slice(4);
@@ -70294,15 +70396,15 @@ function stripWin32Namespace(path4) {
70294
70396
  }
70295
70397
  function comparablePath(path4, platform3) {
70296
70398
  if (platform3 === "win32") {
70297
- const normalized3 = import_node_path48.win32.normalize(stripWin32Namespace(path4).replaceAll("/", "\\"));
70399
+ const normalized3 = import_node_path49.win32.normalize(stripWin32Namespace(path4).replaceAll("/", "\\"));
70298
70400
  const trimmed4 = normalized3.length > 3 || !/^[a-z]:\\$/i.test(normalized3) ? normalized3.replace(/\\+$/, "") : normalized3;
70299
70401
  return trimmed4.toLowerCase();
70300
70402
  }
70301
- const normalized2 = import_node_path48.posix.normalize(path4);
70403
+ const normalized2 = import_node_path49.posix.normalize(path4);
70302
70404
  return normalized2.length > 1 ? normalized2.replace(/\/+$/, "") : normalized2;
70303
70405
  }
70304
70406
  function isAbsoluteFor(path4, platform3) {
70305
- return platform3 === "win32" ? import_node_path48.win32.isAbsolute(path4) : import_node_path48.posix.isAbsolute(path4);
70407
+ return platform3 === "win32" ? import_node_path49.win32.isAbsolute(path4) : import_node_path49.posix.isAbsolute(path4);
70306
70408
  }
70307
70409
  function isWithin(root, candidate, platform3) {
70308
70410
  const separator = platform3 === "win32" ? "\\" : "/";
@@ -70320,7 +70422,7 @@ var storeSchema = external_exports.object({
70320
70422
  });
70321
70423
  async function realpathOrNull(path4) {
70322
70424
  try {
70323
- return await (0, import_promises55.realpath)(path4);
70425
+ return await (0, import_promises56.realpath)(path4);
70324
70426
  } catch (error62) {
70325
70427
  const code = errnoCode(error62);
70326
70428
  if (code === "ENOENT" || code === "ENOTDIR" || code === "EACCES" || code === "EPERM") {
@@ -70379,9 +70481,9 @@ async function openApprovedPaths(options) {
70379
70481
  }
70380
70482
 
70381
70483
  // src/capabilities/workspace/locks.ts
70382
- var import_node_crypto27 = require("crypto");
70383
- var import_promises56 = require("fs/promises");
70384
- var import_node_path49 = require("path");
70484
+ var import_node_crypto28 = require("crypto");
70485
+ var import_promises57 = require("fs/promises");
70486
+ var import_node_path50 = require("path");
70385
70487
  init_zod();
70386
70488
  var LOCK_FORMAT = 1;
70387
70489
  var EXCLUSIVE_FILE = "exclusive.json";
@@ -70396,12 +70498,12 @@ var ownerSchema = external_exports.object({
70396
70498
  since: external_exports.number().int().nonnegative()
70397
70499
  });
70398
70500
  function repositoryLockKey(commonDir, platform3) {
70399
- return (0, import_node_crypto27.createHash)("sha256").update(comparablePath(commonDir, platform3)).digest("hex").slice(0, 32);
70501
+ return (0, import_node_crypto28.createHash)("sha256").update(comparablePath(commonDir, platform3)).digest("hex").slice(0, 32);
70400
70502
  }
70401
70503
  async function readOwner2(path4) {
70402
70504
  let text3;
70403
70505
  try {
70404
- text3 = await (0, import_promises56.readFile)(path4, "utf8");
70506
+ text3 = await (0, import_promises57.readFile)(path4, "utf8");
70405
70507
  } catch (error62) {
70406
70508
  if (errnoCode(error62) === "ENOENT") return { kind: "missing" };
70407
70509
  return { kind: "unreadable" };
@@ -70422,7 +70524,7 @@ async function removeIfSame(path4, expected) {
70422
70524
  if (current.kind !== "owner" || current.owner.since !== expected.since) return;
70423
70525
  if (current.owner.pid !== expected.pid || current.owner.holder !== expected.holder) return;
70424
70526
  }
70425
- await (0, import_promises56.unlink)(path4).catch((error62) => {
70527
+ await (0, import_promises57.unlink)(path4).catch((error62) => {
70426
70528
  if (errnoCode(error62) !== "ENOENT") throw error62;
70427
70529
  });
70428
70530
  }
@@ -70447,7 +70549,7 @@ function openRepositoryLocks(options) {
70447
70549
  await removeIfSame(path4, read.owner);
70448
70550
  return null;
70449
70551
  }
70450
- const age = await (0, import_promises56.stat)(path4).then(
70552
+ const age = await (0, import_promises57.stat)(path4).then(
70451
70553
  (info) => clock.now() - info.mtimeMs,
70452
70554
  () => 0
70453
70555
  );
@@ -70461,13 +70563,13 @@ function openRepositoryLocks(options) {
70461
70563
  });
70462
70564
  const folder = async (commonDir) => {
70463
70565
  const key = repositoryLockKey(commonDir, platform3);
70464
- const dir = (0, import_node_path49.join)(options.dir, key);
70465
- await (0, import_promises56.mkdir)(dir, { recursive: true, mode: 448 });
70566
+ const dir = (0, import_node_path50.join)(options.dir, key);
70567
+ await (0, import_promises57.mkdir)(dir, { recursive: true, mode: 448 });
70466
70568
  return { key, dir };
70467
70569
  };
70468
70570
  const createExclusive = async (path4, owner) => {
70469
70571
  try {
70470
- const handle = await (0, import_promises56.open)(path4, "wx", 384);
70572
+ const handle = await (0, import_promises57.open)(path4, "wx", 384);
70471
70573
  try {
70472
70574
  await handle.writeFile(JSON.stringify(owner));
70473
70575
  } finally {
@@ -70480,10 +70582,10 @@ function openRepositoryLocks(options) {
70480
70582
  }
70481
70583
  };
70482
70584
  const liveRun = async (dir) => {
70483
- const entries = await (0, import_promises56.readdir)(dir);
70585
+ const entries = await (0, import_promises57.readdir)(dir);
70484
70586
  for (const entry of entries) {
70485
70587
  if (!entry.startsWith(RUN_FILE_PREFIX)) continue;
70486
- const holder = await heldBy((0, import_node_path49.join)(dir, entry));
70588
+ const holder = await heldBy((0, import_node_path50.join)(dir, entry));
70487
70589
  if (holder !== null) return holder;
70488
70590
  }
70489
70591
  return null;
@@ -70491,7 +70593,7 @@ function openRepositoryLocks(options) {
70491
70593
  return {
70492
70594
  tryExclusive: async (commonDir, operationId) => {
70493
70595
  const { key, dir } = await folder(commonDir);
70494
- const path4 = (0, import_node_path49.join)(dir, EXCLUSIVE_FILE);
70596
+ const path4 = (0, import_node_path50.join)(dir, EXCLUSIVE_FILE);
70495
70597
  const owner = await self(operationId);
70496
70598
  if (!await createExclusive(path4, owner)) {
70497
70599
  const holder = await heldBy(path4);
@@ -70509,11 +70611,11 @@ function openRepositoryLocks(options) {
70509
70611
  },
70510
70612
  tryShared: async (commonDir, runId) => {
70511
70613
  const { key, dir } = await folder(commonDir);
70512
- const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto27.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
70513
- const path4 = (0, import_node_path49.join)(dir, file2);
70614
+ const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto28.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
70615
+ const path4 = (0, import_node_path50.join)(dir, file2);
70514
70616
  const owner = await self(runId);
70515
70617
  await writeJsonFileAtomic(path4, owner);
70516
- const operation = await heldBy((0, import_node_path49.join)(dir, EXCLUSIVE_FILE));
70618
+ const operation = await heldBy((0, import_node_path50.join)(dir, EXCLUSIVE_FILE));
70517
70619
  if (operation !== null) {
70518
70620
  await removeIfSame(path4, owner);
70519
70621
  return { kind: "busy", holder: operation };
@@ -70613,18 +70715,18 @@ async function openWorkspaces(options) {
70613
70715
  const budgetMs = options.budgetMs ?? WORKSPACE_QUERY_BUDGET_MS;
70614
70716
  const lifetime = new AbortController();
70615
70717
  const approved = await openApprovedPaths({
70616
- file: (0, import_node_path50.join)(options.stateDir, "workspaces.json"),
70718
+ file: (0, import_node_path51.join)(options.stateDir, "workspaces.json"),
70617
70719
  log: options.log,
70618
70720
  platform: platform3
70619
70721
  });
70620
70722
  const locks = openRepositoryLocks({
70621
- dir: (0, import_node_path50.join)(options.stateDir, "locks"),
70723
+ dir: (0, import_node_path51.join)(options.stateDir, "locks"),
70622
70724
  clock: options.clock,
70623
70725
  platform: platform3
70624
70726
  });
70625
70727
  const git = createGit({
70626
70728
  env: options.env,
70627
- tmpDir: (0, import_node_path50.join)(options.stateDir, "tmp", "git"),
70729
+ tmpDir: (0, import_node_path51.join)(options.stateDir, "tmp", "git"),
70628
70730
  platform: platform3,
70629
70731
  ...options.gitPath === void 0 ? {} : { gitPath: options.gitPath },
70630
70732
  ...options.localTimeoutMs === void 0 ? {} : { localTimeoutMs: options.localTimeoutMs },
@@ -70892,7 +70994,7 @@ function createProviderDrivers(options) {
70892
70994
  }
70893
70995
 
70894
70996
  // src/holder/engine-records.ts
70895
- var import_node_path51 = require("path");
70997
+ var import_node_path52 = require("path");
70896
70998
  init_zod();
70897
70999
  var ENGINES_FILE = "engines.json";
70898
71000
  var STOP_GRACE_MS = 2e3;
@@ -70904,7 +71006,7 @@ var engineRecordSchema = external_exports.object({
70904
71006
  });
70905
71007
  var engineRecordsSchema = external_exports.object({ engines: external_exports.array(engineRecordSchema) });
70906
71008
  function engineRecordsPath(sessionDir) {
70907
- return (0, import_node_path51.join)(sessionDir, ENGINES_FILE);
71009
+ return (0, import_node_path52.join)(sessionDir, ENGINES_FILE);
70908
71010
  }
70909
71011
  function recordSpawnedEngines(path4, clock, log) {
70910
71012
  const live = /* @__PURE__ */ new Map();
@@ -70965,11 +71067,11 @@ async function reapLeftoverEngines(path4, options) {
70965
71067
 
70966
71068
  // src/holder/launch-command.ts
70967
71069
  var import_node_fs18 = require("fs");
70968
- var import_node_path52 = require("path");
71070
+ var import_node_path53 = require("path");
70969
71071
  var HOLDER_BUNDLE = "alan-holder.cjs";
70970
71072
  function holderArguments(runtimeArgs, nodeFlags, exists6 = import_node_fs18.existsSync) {
70971
71073
  const bundle = runtimeArgs.at(-1);
70972
- const lean = bundle === void 0 ? void 0 : (0, import_node_path52.join)((0, import_node_path52.dirname)(bundle), HOLDER_BUNDLE);
71074
+ const lean = bundle === void 0 ? void 0 : (0, import_node_path53.join)((0, import_node_path53.dirname)(bundle), HOLDER_BUNDLE);
70973
71075
  const script = lean !== void 0 && exists6(lean) ? [...runtimeArgs.slice(0, -1), lean] : runtimeArgs;
70974
71076
  return [...nodeFlags, ...script, "hold"];
70975
71077
  }
@@ -71004,17 +71106,17 @@ function createConversationMcpAuthorization(options) {
71004
71106
  }
71005
71107
 
71006
71108
  // src/holder/mcp-helper-access.ts
71007
- var import_promises57 = require("fs/promises");
71109
+ var import_promises58 = require("fs/promises");
71008
71110
  function createHelperMcpAccess(options) {
71009
71111
  return {
71010
71112
  [Symbol.asyncDispose]: async () => {
71011
- await (0, import_promises57.rm)(options.credentialPath, { force: true });
71113
+ await (0, import_promises58.rm)(options.credentialPath, { force: true });
71012
71114
  },
71013
71115
  url: options.managedMcp.url,
71014
71116
  authorization: async (signal) => {
71015
71117
  const authorization = await options.managedMcp.authorization(signal);
71016
71118
  if (authorization === void 0 || signal.aborted) {
71017
- await (0, import_promises57.rm)(options.credentialPath, { force: true });
71119
+ await (0, import_promises58.rm)(options.credentialPath, { force: true });
71018
71120
  return void 0;
71019
71121
  }
71020
71122
  const credential = {
@@ -71029,8 +71131,8 @@ function createHelperMcpAccess(options) {
71029
71131
  }
71030
71132
 
71031
71133
  // src/holder/run-inputs.ts
71032
- var import_promises58 = require("fs/promises");
71033
- var import_node_path53 = require("path");
71134
+ var import_promises59 = require("fs/promises");
71135
+ var import_node_path54 = require("path");
71034
71136
  init_dist();
71035
71137
  var NO_RUN_INPUTS = {
71036
71138
  attachments: [],
@@ -71044,17 +71146,17 @@ function safeFilename(filename) {
71044
71146
  return safe || "attachment";
71045
71147
  }
71046
71148
  function persistentAttachmentDir(workspaceRoot2) {
71047
- return (0, import_node_path53.join)(workspaceRoot2, ".alan", "attachments");
71149
+ return (0, import_node_path54.join)(workspaceRoot2, ".alan", "attachments");
71048
71150
  }
71049
71151
  function attachmentPath(spec, attachment, index, runDir) {
71050
71152
  const workspaceRoot2 = spec.approvedWorkspacePaths?.[0];
71051
71153
  if (attachment.persist && workspaceRoot2) {
71052
- return (0, import_node_path53.join)(
71154
+ return (0, import_node_path54.join)(
71053
71155
  persistentAttachmentDir(workspaceRoot2),
71054
71156
  `${attachment.id.slice(0, 8)}-${safeFilename(attachment.filename)}`
71055
71157
  );
71056
71158
  }
71057
- return (0, import_node_path53.join)(runDir, `${index}-${safeFilename(attachment.filename)}`);
71159
+ return (0, import_node_path54.join)(runDir, `${index}-${safeFilename(attachment.filename)}`);
71058
71160
  }
71059
71161
  function runMediaUploader(source, runId) {
71060
71162
  const upload = source.uploadMedia?.bind(source);
@@ -71064,9 +71166,9 @@ function runMediaUploader(source, runId) {
71064
71166
  };
71065
71167
  }
71066
71168
  async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71067
- const dir = (0, import_node_path53.join)(tmpDir, "runs", spec.runId);
71169
+ const dir = (0, import_node_path54.join)(tmpDir, "runs", spec.runId);
71068
71170
  const cleanup = async () => {
71069
- await (0, import_promises58.rm)(dir, { recursive: true, force: true });
71171
+ await (0, import_promises59.rm)(dir, { recursive: true, force: true });
71070
71172
  };
71071
71173
  try {
71072
71174
  const credential = await source.fetchProviderCredential(spec.runId, signal);
@@ -71074,8 +71176,8 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71074
71176
  for (const [index, attachment] of (spec.attachments ?? []).entries()) {
71075
71177
  const bytes = await source.downloadAttachment(spec.runId, attachment.id, signal);
71076
71178
  const path4 = attachmentPath(spec, attachment, index, dir);
71077
- await (0, import_promises58.mkdir)((0, import_node_path53.dirname)(path4), { recursive: true, mode: 448 });
71078
- await (0, import_promises58.writeFile)(path4, bytes, { mode: 384 });
71179
+ await (0, import_promises59.mkdir)((0, import_node_path54.dirname)(path4), { recursive: true, mode: 448 });
71180
+ await (0, import_promises59.writeFile)(path4, bytes, { mode: 384 });
71079
71181
  const imageMimeType = attachment.kind === "image" ? detectImageMimeType(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)) : null;
71080
71182
  attachments.push({
71081
71183
  id: attachment.id,
@@ -71105,37 +71207,37 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71105
71207
  }
71106
71208
 
71107
71209
  // src/holder/serve.ts
71108
- var import_node_crypto30 = require("crypto");
71210
+ var import_node_crypto31 = require("crypto");
71109
71211
  var import_node_fs23 = require("fs");
71110
71212
  var import_node_net3 = require("net");
71111
- var import_node_path65 = require("path");
71213
+ var import_node_path66 = require("path");
71112
71214
  init_runtime_v2();
71113
71215
 
71114
71216
  // src/holder/admission.ts
71115
71217
  var import_node_fs20 = require("fs");
71116
- var import_promises62 = require("fs/promises");
71218
+ var import_promises63 = require("fs/promises");
71117
71219
  var import_node_os9 = require("os");
71118
- var import_node_path59 = require("path");
71220
+ var import_node_path60 = require("path");
71119
71221
  init_constants();
71120
71222
 
71121
71223
  // ../shared/dist/node/local-workspace.js
71122
71224
  var import_node_fs19 = require("fs");
71123
71225
  var import_node_os8 = require("os");
71124
- var import_node_path54 = require("path");
71226
+ var import_node_path55 = require("path");
71125
71227
  function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os8.homedir)()) {
71126
- return (0, import_node_path54.join)(homeDirectory, ".alan", "workspace");
71228
+ return (0, import_node_path55.join)(homeDirectory, ".alan", "workspace");
71127
71229
  }
71128
71230
 
71129
71231
  // src/holder/agent-context.ts
71130
- var import_promises59 = require("fs/promises");
71131
- var import_node_path55 = require("path");
71232
+ var import_promises60 = require("fs/promises");
71233
+ var import_node_path56 = require("path");
71132
71234
 
71133
71235
  // ../agent-core/dist/prompt.js
71134
71236
  init_chunk_DLVRNIY5();
71135
71237
 
71136
71238
  // src/holder/agent-context.ts
71137
71239
  async function readText4(path4) {
71138
- return (0, import_promises59.readFile)(path4, "utf8").then(
71240
+ return (0, import_promises60.readFile)(path4, "utf8").then(
71139
71241
  (text3) => text3.trim(),
71140
71242
  () => null
71141
71243
  );
@@ -71150,10 +71252,10 @@ async function startCommandState(statusPath) {
71150
71252
  return code === 0 ? { state: "exited_ok" } : { state: "failed", exitCode: code };
71151
71253
  }
71152
71254
  function createAgentContext(deps) {
71153
- const statusPath = (0, import_node_path55.join)(deps.homeDir, ".alan", "start-commands.status");
71154
- const logPath = (0, import_node_path55.join)(deps.homeDir, ".alan", "start-commands.log");
71255
+ const statusPath = (0, import_node_path56.join)(deps.homeDir, ".alan", "start-commands.status");
71256
+ const logPath = (0, import_node_path56.join)(deps.homeDir, ".alan", "start-commands.log");
71155
71257
  return async (spec, problems) => {
71156
- const file2 = (0, import_node_path55.join)(deps.dir, `${spec.conversationId}.json`);
71258
+ const file2 = (0, import_node_path56.join)(deps.dir, `${spec.conversationId}.json`);
71157
71259
  const saved = await readJsonFile(file2, agentContextSnapshotSchema);
71158
71260
  const known = saved.kind === "ok" ? saved.value : void 0;
71159
71261
  const hasEnvironment = (spec.agentContext ?? known)?.environment !== void 0;
@@ -71177,28 +71279,28 @@ function createAgentContext(deps) {
71177
71279
  }
71178
71280
 
71179
71281
  // src/holder/checkout-refresh.ts
71180
- var import_node_path58 = require("path");
71282
+ var import_node_path59 = require("path");
71181
71283
 
71182
71284
  // src/holder/claim-once.ts
71183
- var import_node_crypto28 = require("crypto");
71184
- var import_promises60 = require("fs/promises");
71185
- var import_node_path56 = require("path");
71285
+ var import_node_crypto29 = require("crypto");
71286
+ var import_promises61 = require("fs/promises");
71287
+ var import_node_path57 = require("path");
71186
71288
  async function claimOnce(dir, name) {
71187
71289
  try {
71188
- await (0, import_promises60.mkdir)(dir, { recursive: true, mode: 448 });
71189
- await (await (0, import_promises60.open)((0, import_node_path56.join)(dir, name), "wx")).close();
71290
+ await (0, import_promises61.mkdir)(dir, { recursive: true, mode: 448 });
71291
+ await (await (0, import_promises61.open)((0, import_node_path57.join)(dir, name), "wx")).close();
71190
71292
  return true;
71191
71293
  } catch {
71192
71294
  return false;
71193
71295
  }
71194
71296
  }
71195
71297
  function claimFirstLease(freshnessDir, path4) {
71196
- return claimOnce((0, import_node_path56.join)(freshnessDir, "leased"), (0, import_node_crypto28.createHash)("sha256").update(path4).digest("hex"));
71298
+ return claimOnce((0, import_node_path57.join)(freshnessDir, "leased"), (0, import_node_crypto29.createHash)("sha256").update(path4).digest("hex"));
71197
71299
  }
71198
71300
 
71199
71301
  // src/holder/requested-checkout.ts
71200
- var import_promises61 = require("fs/promises");
71201
- var import_node_path57 = require("path");
71302
+ var import_promises62 = require("fs/promises");
71303
+ var import_node_path58 = require("path");
71202
71304
  var REMOTE2 = "origin";
71203
71305
  var REASON_MAX_CHARS = 200;
71204
71306
  function firstLine3(text3) {
@@ -71219,8 +71321,8 @@ function notSwitched(checkout, current, reason) {
71219
71321
  );
71220
71322
  }
71221
71323
  async function clone2(checkout, deps, signal) {
71222
- const parent = (0, import_node_path57.dirname)(checkout.path);
71223
- await (0, import_promises61.mkdir)(parent, { recursive: true });
71324
+ const parent = (0, import_node_path58.dirname)(checkout.path);
71325
+ await (0, import_promises62.mkdir)(parent, { recursive: true });
71224
71326
  await assertValidBranch(deps.git, parent, checkout.branch, signal);
71225
71327
  const output2 = await deps.git.run(
71226
71328
  {
@@ -71455,7 +71557,7 @@ async function applyRequestedCheckouts(spec, deps, signal) {
71455
71557
  ms: Date.now() - startedAt
71456
71558
  });
71457
71559
  if (outcome2.kind === "on_branch") continue;
71458
- settled2.add((0, import_node_path58.resolve)(checkout.path));
71560
+ settled2.add((0, import_node_path59.resolve)(checkout.path));
71459
71561
  if (outcome2.kind === "noted") {
71460
71562
  problems.push({ path: checkout.path, problem: outcome2.problem, action: outcome2.action });
71461
71563
  }
@@ -71465,7 +71567,7 @@ async function applyRequestedCheckouts(spec, deps, signal) {
71465
71567
  async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
71466
71568
  const problems = [];
71467
71569
  for (const target of targets) {
71468
- if (settled2.has((0, import_node_path58.resolve)(target))) continue;
71570
+ if (settled2.has((0, import_node_path59.resolve)(target))) continue;
71469
71571
  const freshness = await readCheckoutFreshness(deps.dir, target);
71470
71572
  if (freshness === null) continue;
71471
71573
  const startedAt = Date.now();
@@ -71486,7 +71588,7 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
71486
71588
  function createCheckoutRefresh(deps) {
71487
71589
  return async (spec, signal) => {
71488
71590
  if (spec.providerSessionId !== void 0) return [];
71489
- if (!await claimOnce((0, import_node_path58.join)(deps.dir, "conversations"), spec.conversationId)) return [];
71591
+ if (!await claimOnce((0, import_node_path59.join)(deps.dir, "conversations"), spec.conversationId)) return [];
71490
71592
  const requested = await applyRequestedCheckouts(spec, deps, signal);
71491
71593
  const targets = await checkoutsOf(spec);
71492
71594
  return [
@@ -71528,7 +71630,7 @@ function volumeRoot(path4) {
71528
71630
  }
71529
71631
  async function exists4(path4) {
71530
71632
  try {
71531
- await (0, import_promises62.stat)(path4);
71633
+ await (0, import_promises63.stat)(path4);
71532
71634
  return true;
71533
71635
  } catch {
71534
71636
  return false;
@@ -71536,10 +71638,10 @@ async function exists4(path4) {
71536
71638
  }
71537
71639
  async function inspectReadiness(path4) {
71538
71640
  try {
71539
- if (!(await (0, import_promises62.stat)(path4)).isDirectory()) {
71641
+ if (!(await (0, import_promises63.stat)(path4)).isDirectory()) {
71540
71642
  return { ready: false, missing: true, message: MESSAGES.missing };
71541
71643
  }
71542
- await (0, import_promises62.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71644
+ await (0, import_promises63.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71543
71645
  return { ready: true };
71544
71646
  } catch (error62) {
71545
71647
  const code = errnoCode(error62) ?? "";
@@ -71583,8 +71685,8 @@ async function admitDefaultWorkspace(spec, context, skills) {
71583
71685
  const { env } = context;
71584
71686
  const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os9.homedir)());
71585
71687
  try {
71586
- await (0, import_promises62.mkdir)(path4, { recursive: true, mode: 448 });
71587
- await (0, import_promises62.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71688
+ await (0, import_promises63.mkdir)(path4, { recursive: true, mode: 448 });
71689
+ await (0, import_promises63.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71588
71690
  return { kind: "admitted", spec: { ...spec, projectPath: path4 }, skills };
71589
71691
  } catch (error62) {
71590
71692
  const code = errnoCode(error62);
@@ -71648,7 +71750,7 @@ function createHolderWorkspace(machine, clock, log) {
71648
71750
  ),
71649
71751
  approvedRoots: async () => {
71650
71752
  const approved = await openApprovedPaths({
71651
- file: (0, import_node_path59.join)(machine.stateDir, "workspaces.json"),
71753
+ file: (0, import_node_path60.join)(machine.stateDir, "workspaces.json"),
71652
71754
  log,
71653
71755
  platform: platform3
71654
71756
  });
@@ -71663,12 +71765,12 @@ function createHolderWorkspace(machine, clock, log) {
71663
71765
  localTimeoutMs: CHECKOUT_LOCAL_TIMEOUT_MS,
71664
71766
  networkTimeoutMs: CHECKOUT_NETWORK_TIMEOUT_MS
71665
71767
  }),
71666
- locks: openRepositoryLocks({ dir: (0, import_node_path59.join)(machine.stateDir, "locks"), clock, platform: platform3 }),
71768
+ locks: openRepositoryLocks({ dir: (0, import_node_path60.join)(machine.stateDir, "locks"), clock, platform: platform3 }),
71667
71769
  log,
71668
- dir: (0, import_node_path59.join)(machine.stateDir, "checkout-freshness")
71770
+ dir: (0, import_node_path60.join)(machine.stateDir, "checkout-freshness")
71669
71771
  }),
71670
71772
  prepareAgentContext: createAgentContext({
71671
- dir: (0, import_node_path59.join)(machine.stateDir, "agent-context"),
71773
+ dir: (0, import_node_path60.join)(machine.stateDir, "agent-context"),
71672
71774
  homeDir: machine.env.HOME || (0, import_node_os9.homedir)()
71673
71775
  })
71674
71776
  } : {}
@@ -71686,7 +71788,7 @@ async function respondToTurn(runningRunId, driver, request2) {
71686
71788
  }
71687
71789
 
71688
71790
  // src/holder/session-facts.ts
71689
- var import_promises63 = require("fs/promises");
71791
+ var import_promises64 = require("fs/promises");
71690
71792
  var CLI_RSS_CACHE_MS = 1e4;
71691
71793
  var LOGIN_PROBLEM_PREFIX = "cli.auth.";
71692
71794
  function isLoginFailure(result) {
@@ -71712,8 +71814,8 @@ function createSessionFacts(options) {
71712
71814
  const path4 = await resolveCommandOnPath(command, env, platform3);
71713
71815
  if (path4 === null) return null;
71714
71816
  try {
71715
- const real = await (0, import_promises63.realpath)(path4);
71716
- const info = await (0, import_promises63.stat)(real);
71817
+ const real = await (0, import_promises64.realpath)(path4);
71818
+ const info = await (0, import_promises64.stat)(real);
71717
71819
  return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
71718
71820
  } catch {
71719
71821
  return null;
@@ -71807,12 +71909,12 @@ async function steerTurn(runningRunId, driver, request2) {
71807
71909
  init_acp3();
71808
71910
 
71809
71911
  // src/run-log/archive.ts
71810
- var import_promises64 = require("fs/promises");
71811
- var import_node_path60 = require("path");
71912
+ var import_promises65 = require("fs/promises");
71913
+ var import_node_path61 = require("path");
71812
71914
  init_runtime_v2();
71813
71915
  async function openRunArchive(runsDir) {
71814
- const path4 = (0, import_node_path60.join)((0, import_node_path60.dirname)(runsDir), "archived-runs.txt");
71815
- const text3 = await (0, import_promises64.readFile)(path4, "utf8").catch((error62) => {
71916
+ const path4 = (0, import_node_path61.join)((0, import_node_path61.dirname)(runsDir), "archived-runs.txt");
71917
+ const text3 = await (0, import_promises65.readFile)(path4, "utf8").catch((error62) => {
71816
71918
  if (errnoCode(error62) === "ENOENT") return "";
71817
71919
  throw error62;
71818
71920
  });
@@ -71826,7 +71928,7 @@ async function openRunArchive(runsDir) {
71826
71928
  add: async (runIds) => {
71827
71929
  const added = runIds.filter((runId) => !archived.has(runId));
71828
71930
  if (added.length === 0) return;
71829
- await (0, import_promises64.appendFile)(path4, `
71931
+ await (0, import_promises65.appendFile)(path4, `
71830
71932
  ${added.join("\n")}
71831
71933
  `, { mode: 384 });
71832
71934
  for (const runId of added) archived.add(runId);
@@ -71835,13 +71937,13 @@ ${added.join("\n")}
71835
71937
  }
71836
71938
 
71837
71939
  // src/run-log/complete.ts
71838
- var import_node_crypto29 = require("crypto");
71940
+ var import_node_crypto30 = require("crypto");
71839
71941
  var import_node_fs21 = require("fs");
71840
- var import_node_path62 = require("path");
71942
+ var import_node_path63 = require("path");
71841
71943
 
71842
71944
  // src/run-log/directory.ts
71843
- var import_promises65 = require("fs/promises");
71844
- var import_node_path61 = require("path");
71945
+ var import_promises66 = require("fs/promises");
71946
+ var import_node_path62 = require("path");
71845
71947
  init_runtime_v2();
71846
71948
  init_zod();
71847
71949
  var runMetaSchema = external_exports.object({
@@ -71867,17 +71969,17 @@ async function readRunMeta(path4) {
71867
71969
  return read.kind === "ok" ? read.value : null;
71868
71970
  }
71869
71971
  function runDirectory(runsDir, runId) {
71870
- const dir = (0, import_node_path61.join)(runsDir, runId);
71972
+ const dir = (0, import_node_path62.join)(runsDir, runId);
71871
71973
  return {
71872
71974
  dir,
71873
- log: (0, import_node_path61.join)(dir, "log.jsonl"),
71874
- upload: (0, import_node_path61.join)(dir, "upload.json"),
71875
- meta: (0, import_node_path61.join)(dir, "run.json")
71975
+ log: (0, import_node_path62.join)(dir, "log.jsonl"),
71976
+ upload: (0, import_node_path62.join)(dir, "upload.json"),
71977
+ meta: (0, import_node_path62.join)(dir, "run.json")
71876
71978
  };
71877
71979
  }
71878
71980
  async function isRunClaimed(runsDir, runId) {
71879
71981
  try {
71880
- return (await (0, import_promises65.stat)(runDirectory(runsDir, runId).log)).size > 0;
71982
+ return (await (0, import_promises66.stat)(runDirectory(runsDir, runId).log)).size > 0;
71881
71983
  } catch (error62) {
71882
71984
  if (errnoCode(error62) === "ENOENT") return false;
71883
71985
  throw error62;
@@ -71886,7 +71988,7 @@ async function isRunClaimed(runsDir, runId) {
71886
71988
 
71887
71989
  // src/run-log/complete.ts
71888
71990
  function writeLogFile(path4, dir, text3) {
71889
- const temp = (0, import_node_path62.join)(dir, `.log.${(0, import_node_crypto29.randomUUID)()}.tmp`);
71991
+ const temp = (0, import_node_path63.join)(dir, `.log.${(0, import_node_crypto30.randomUUID)()}.tmp`);
71890
71992
  const fd = (0, import_node_fs21.openSync)(temp, "wx", 384);
71891
71993
  try {
71892
71994
  (0, import_node_fs21.writeSync)(fd, text3);
@@ -71915,8 +72017,8 @@ async function writeCompleteRunLog(runsDir, meta3, records) {
71915
72017
  }
71916
72018
 
71917
72019
  // src/run-log/conversation-index.ts
71918
- var import_promises66 = require("fs/promises");
71919
- var import_node_path63 = require("path");
72020
+ var import_promises67 = require("fs/promises");
72021
+ var import_node_path64 = require("path");
71920
72022
  init_runtime_v2();
71921
72023
  init_zod();
71922
72024
  var ORDINALS_PER_SHARD = 1e3;
@@ -71933,13 +72035,13 @@ var coverageSchema = external_exports.object({
71933
72035
  nextExpectedOrdinal: external_exports.number().int().positive()
71934
72036
  });
71935
72037
  function conversationsDirectory(runsDir) {
71936
- return (0, import_node_path63.join)((0, import_node_path63.dirname)(runsDir), "conversations");
72038
+ return (0, import_node_path64.join)((0, import_node_path64.dirname)(runsDir), "conversations");
71937
72039
  }
71938
72040
  function indexDirectory(runsDir, conversationId) {
71939
- return (0, import_node_path63.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
72041
+ return (0, import_node_path64.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
71940
72042
  }
71941
72043
  function shardPath(runsDir, conversationId, ordinal) {
71942
- return (0, import_node_path63.join)(
72044
+ return (0, import_node_path64.join)(
71943
72045
  indexDirectory(runsDir, conversationId),
71944
72046
  `${Math.floor(ordinal / ORDINALS_PER_SHARD)}.jsonl`
71945
72047
  );
@@ -71948,10 +72050,10 @@ async function indexConversationRun(runsDir, conversationId, ordinal, assistantO
71948
72050
  const nextOrdinal = assistantOrdinal + 1;
71949
72051
  if (nextOrdinal <= ordinal) throw new Error("Assistant order must follow the prompt");
71950
72052
  const path4 = shardPath(runsDir, conversationId, ordinal);
71951
- await (0, import_promises66.mkdir)((0, import_node_path63.dirname)(path4), { recursive: true, mode: 448 });
71952
- await (0, import_promises66.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
72053
+ await (0, import_promises67.mkdir)((0, import_node_path64.dirname)(path4), { recursive: true, mode: 448 });
72054
+ await (0, import_promises67.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
71953
72055
  `, { mode: 384 });
71954
- const coveragePath = (0, import_node_path63.join)((0, import_node_path63.dirname)((0, import_node_path63.dirname)(path4)), "coverage.json");
72056
+ const coveragePath = (0, import_node_path64.join)((0, import_node_path64.dirname)((0, import_node_path64.dirname)(path4)), "coverage.json");
71955
72057
  const coverage = await readJsonFile(coveragePath, coverageSchema);
71956
72058
  const current = coverage.kind === "ok" ? coverage.value : null;
71957
72059
  const next = nextCoverage(current, ordinal, nextOrdinal);
@@ -71966,13 +72068,13 @@ function nextCoverage(current, ordinal, nextOrdinal) {
71966
72068
  return null;
71967
72069
  }
71968
72070
  async function readConversationIndexCoverage(runsDir, conversationId) {
71969
- const path4 = (0, import_node_path63.join)((0, import_node_path63.dirname)(indexDirectory(runsDir, conversationId)), "coverage.json");
72071
+ const path4 = (0, import_node_path64.join)((0, import_node_path64.dirname)(indexDirectory(runsDir, conversationId)), "coverage.json");
71970
72072
  const result = await readJsonFile(path4, coverageSchema);
71971
72073
  return result.kind === "ok" ? result.value : null;
71972
72074
  }
71973
72075
  async function readConversationRunIndex(runsDir, conversationId, before, limit) {
71974
72076
  const directory = indexDirectory(runsDir, conversationId);
71975
- const names = await (0, import_promises66.readdir)(directory).catch((error62) => {
72077
+ const names = await (0, import_promises67.readdir)(directory).catch((error62) => {
71976
72078
  if (error62.code === "ENOENT") return [];
71977
72079
  throw error62;
71978
72080
  });
@@ -71981,7 +72083,7 @@ async function readConversationRunIndex(runsDir, conversationId, before, limit)
71981
72083
  ).sort((left, right) => right - left);
71982
72084
  const selected = [];
71983
72085
  for (const shard of shards) {
71984
- const text3 = await (0, import_promises66.readFile)((0, import_node_path63.join)(directory, `${shard}.jsonl`), "utf8");
72086
+ const text3 = await (0, import_promises67.readFile)((0, import_node_path64.join)(directory, `${shard}.jsonl`), "utf8");
71985
72087
  const records = text3.split("\n").flatMap((line) => {
71986
72088
  if (!line) return [];
71987
72089
  const parsed = indexRecordSchema.parse(JSON.parse(line));
@@ -72006,7 +72108,7 @@ async function readIndexableRun(runsDir, name) {
72006
72108
  return { conversationId: meta3.conversationId, ordinal, assistantOrdinal, runId: runId.data };
72007
72109
  }
72008
72110
  async function readIndexableRuns(runsDir) {
72009
- const names = await (0, import_promises66.readdir)(runsDir).catch(() => []);
72111
+ const names = await (0, import_promises67.readdir)(runsDir).catch(() => []);
72010
72112
  const byConversation = /* @__PURE__ */ new Map();
72011
72113
  let next = 0;
72012
72114
  const worker = async () => {
@@ -72036,21 +72138,21 @@ async function writeConversationIndex(directory, runs) {
72036
72138
  else lines2.push(line);
72037
72139
  coverage = nextCoverage(coverage, run2.ordinal, nextOrdinal) ?? coverage;
72038
72140
  }
72039
- await (0, import_promises66.mkdir)((0, import_node_path63.join)(directory, "turn-index"), { recursive: true, mode: 448 });
72141
+ await (0, import_promises67.mkdir)((0, import_node_path64.join)(directory, "turn-index"), { recursive: true, mode: 448 });
72040
72142
  for (const [shard, lines2] of shards) {
72041
- await (0, import_promises66.writeFile)((0, import_node_path63.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
72143
+ await (0, import_promises67.writeFile)((0, import_node_path64.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
72042
72144
  `, {
72043
72145
  mode: 384
72044
72146
  });
72045
72147
  }
72046
- await (0, import_promises66.writeFile)((0, import_node_path63.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
72148
+ await (0, import_promises67.writeFile)((0, import_node_path64.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
72047
72149
  `, {
72048
72150
  mode: 384
72049
72151
  });
72050
72152
  }
72051
72153
  async function rebuildConversationIndexes(runsDir) {
72052
72154
  const root = conversationsDirectory(runsDir);
72053
- const exists6 = await (0, import_promises66.stat)(root).then(
72155
+ const exists6 = await (0, import_promises67.stat)(root).then(
72054
72156
  () => true,
72055
72157
  (error62) => {
72056
72158
  if (errnoCode(error62) === "ENOENT") return false;
@@ -72059,18 +72161,18 @@ async function rebuildConversationIndexes(runsDir) {
72059
72161
  );
72060
72162
  if (exists6) return 0;
72061
72163
  const building = `${root}.rebuilding`;
72062
- await (0, import_promises66.rm)(building, { recursive: true, force: true });
72063
- await (0, import_promises66.mkdir)(building, { recursive: true, mode: 448 });
72164
+ await (0, import_promises67.rm)(building, { recursive: true, force: true });
72165
+ await (0, import_promises67.mkdir)(building, { recursive: true, mode: 448 });
72064
72166
  const byConversation = await readIndexableRuns(runsDir);
72065
72167
  for (const [conversationId, runs] of byConversation) {
72066
- await writeConversationIndex((0, import_node_path63.join)(building, conversationId), runs);
72168
+ await writeConversationIndex((0, import_node_path64.join)(building, conversationId), runs);
72067
72169
  }
72068
- await (0, import_promises66.rename)(building, root);
72170
+ await (0, import_promises67.rename)(building, root);
72069
72171
  return byConversation.size;
72070
72172
  }
72071
72173
 
72072
72174
  // src/run-log/reader.ts
72073
- var import_promises67 = require("fs/promises");
72175
+ var import_promises68 = require("fs/promises");
72074
72176
  init_runtime_v2();
72075
72177
 
72076
72178
  // src/run-log/tail.ts
@@ -72093,7 +72195,7 @@ function firstRecordLength(bytes) {
72093
72195
  return bytes.indexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
72094
72196
  }
72095
72197
  async function openRunLogReader(path4) {
72096
- const handle = await (0, import_promises67.open)(path4, "r");
72198
+ const handle = await (0, import_promises68.open)(path4, "r");
72097
72199
  const readAt = async (position, length) => {
72098
72200
  const buffer = Buffer.alloc(length);
72099
72201
  const { bytesRead } = await handle.read(buffer, 0, length, position);
@@ -72127,7 +72229,7 @@ async function openRunLogReader(path4) {
72127
72229
  };
72128
72230
  }
72129
72231
  async function readLastRecord(path4) {
72130
- const handle = await (0, import_promises67.open)(path4, "r").catch(() => null);
72232
+ const handle = await (0, import_promises68.open)(path4, "r").catch(() => null);
72131
72233
  if (handle === null) return null;
72132
72234
  try {
72133
72235
  const { size } = await handle.stat();
@@ -72161,7 +72263,7 @@ var decoder = new TextDecoder();
72161
72263
 
72162
72264
  // src/run-log/writer.ts
72163
72265
  var import_node_fs22 = require("fs");
72164
- var import_node_path64 = require("path");
72266
+ var import_node_path65 = require("path");
72165
72267
  init_runtime_v2();
72166
72268
  function lastSeq(fd, size) {
72167
72269
  for (const length of tailWindows(size)) {
@@ -72177,7 +72279,7 @@ function lastSeq(fd, size) {
72177
72279
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
72178
72280
  }
72179
72281
  function openRunLog(path4, clock) {
72180
- (0, import_node_fs22.mkdirSync)((0, import_node_path64.dirname)(path4), { recursive: true, mode: 448 });
72282
+ (0, import_node_fs22.mkdirSync)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
72181
72283
  const fd = (0, import_node_fs22.openSync)(path4, "a+", 384);
72182
72284
  let size = (0, import_node_fs22.fstatSync)(fd).size;
72183
72285
  let seq = lastSeq(fd, size);
@@ -72402,12 +72504,12 @@ var TASK_UNSUPPORTED = {
72402
72504
  message: "This agent cannot stop one background task."
72403
72505
  };
72404
72506
  function sha2564(value2) {
72405
- return (0, import_node_crypto30.createHash)("sha256").update(value2).digest("hex");
72507
+ return (0, import_node_crypto31.createHash)("sha256").update(value2).digest("hex");
72406
72508
  }
72407
- function tokenMatches(expected, presented) {
72509
+ function tokenMatches2(expected, presented) {
72408
72510
  const a = Buffer.from(sha2564(expected), "hex");
72409
72511
  const b = Buffer.from(sha2564(presented), "hex");
72410
- return (0, import_node_crypto30.timingSafeEqual)(a, b);
72512
+ return (0, import_node_crypto31.timingSafeEqual)(a, b);
72411
72513
  }
72412
72514
  async function runHolder({
72413
72515
  launch,
@@ -72421,7 +72523,7 @@ async function runHolder({
72421
72523
  try {
72422
72524
  const identity = await readProcessIdentity(process.pid);
72423
72525
  if (identity === null) throw new RuntimeFault("internal", "Cannot read own process identity");
72424
- const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0, import_node_path65.dirname)(launch.statusPath)), clock, log));
72526
+ const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0, import_node_path66.dirname)(launch.statusPath)), clock, log));
72425
72527
  const holder = {
72426
72528
  state: "idle",
72427
72529
  runId: null,
@@ -72429,7 +72531,7 @@ async function runHolder({
72429
72531
  clients: /* @__PURE__ */ new Set()
72430
72532
  };
72431
72533
  const activity = __using(_stack, startActivityFile({
72432
- path: sessionActivityPath((0, import_node_path65.dirname)(launch.statusPath)),
72534
+ path: sessionActivityPath((0, import_node_path66.dirname)(launch.statusPath)),
72433
72535
  read: () => ({
72434
72536
  runId: holder.runId,
72435
72537
  ...driver.activity?.() ?? IDLE_DRIVER_ACTIVITY
@@ -72628,7 +72730,7 @@ async function runHolder({
72628
72730
  readMessages(client, holderRequestSchema, {
72629
72731
  onMessage: (request2) => {
72630
72732
  if (!authenticated) {
72631
- if (request2.type !== "auth" || !tokenMatches(launch.token, request2.token)) {
72733
+ if (request2.type !== "auth" || !tokenMatches2(launch.token, request2.token)) {
72632
72734
  client.destroy();
72633
72735
  return;
72634
72736
  }
@@ -72679,16 +72781,16 @@ function delta(current, previous) {
72679
72781
  return previous === void 0 ? 0 : Math.max(0, Math.round(current - previous));
72680
72782
  }
72681
72783
  async function lastOutputAtMs(runsDir, run2) {
72682
- const info = await (0, import_promises68.stat)(runDirectory(runsDir, run2.runId).log).catch(() => null);
72784
+ const info = await (0, import_promises69.stat)(runDirectory(runsDir, run2.runId).log).catch(() => null);
72683
72785
  return info === null ? null : Math.floor(info.mtimeMs);
72684
72786
  }
72685
72787
  async function readHolderActivities(sessionsDir) {
72686
- const names = await (0, import_promises68.readdir)(sessionsDir).catch(() => []);
72788
+ const names = await (0, import_promises69.readdir)(sessionsDir).catch(() => []);
72687
72789
  const found = [];
72688
72790
  for (const name of names) {
72689
72791
  const parsed = conversationIdSchema.safeParse(name);
72690
72792
  if (!parsed.success) continue;
72691
- const activity = await readSessionActivity(sessionActivityPath((0, import_node_path66.join)(sessionsDir, name)));
72793
+ const activity = await readSessionActivity(sessionActivityPath((0, import_node_path67.join)(sessionsDir, name)));
72692
72794
  if (activity !== null) found.push({ conversationId: parsed.data, activity });
72693
72795
  }
72694
72796
  return found;
@@ -72965,18 +73067,18 @@ async function runActivityLeaseWorker(rawData, port) {
72965
73067
  }
72966
73068
 
72967
73069
  // src/cli/commands/compat.ts
72968
- var import_node_crypto32 = require("crypto");
72969
- var import_promises72 = require("fs/promises");
73070
+ var import_node_crypto33 = require("crypto");
73071
+ var import_promises73 = require("fs/promises");
72970
73072
  init_runtime_v2();
72971
73073
  init_zod();
72972
73074
 
72973
73075
  // src/cli/config.ts
72974
73076
  var import_node_os10 = require("os");
72975
- var import_node_path70 = require("path");
73077
+ var import_node_path71 = require("path");
72976
73078
  init_zod();
72977
73079
 
72978
73080
  // src/client/contract.ts
72979
- var import_node_path67 = require("path");
73081
+ var import_node_path68 = require("path");
72980
73082
  init_runtime_v2();
72981
73083
  init_zod();
72982
73084
  var LOCAL_API_PROTOCOL = 1;
@@ -73149,7 +73251,7 @@ var nativeHookSignalSchema = external_exports.strictObject({
73149
73251
  provider: external_exports.enum(nativeIngestionProviders),
73150
73252
  event: external_exports.enum(nativeIngestionHookEvents),
73151
73253
  externalSessionId: external_exports.string().trim().min(1).max(200),
73152
- transcriptPath: external_exports.string().min(1).max(4096).refine(import_node_path67.isAbsolute, "transcriptPath must be absolute"),
73254
+ transcriptPath: external_exports.string().min(1).max(4096).refine(import_node_path68.isAbsolute, "transcriptPath must be absolute"),
73153
73255
  cwd: external_exports.string().max(4096).nullable(),
73154
73256
  providerTurnId: external_exports.string().max(200).nullable(),
73155
73257
  assistantFingerprint: assistantFingerprintSchema.nullable(),
@@ -73185,19 +73287,19 @@ var localApiErrorSchema = external_exports.object({
73185
73287
  });
73186
73288
 
73187
73289
  // src/client/locate.ts
73188
- var import_node_path68 = require("path");
73290
+ var import_node_path69 = require("path");
73189
73291
  var RUNTIME_PROFILES = ["production", "staging", "development", "local"];
73190
73292
  function defaultStateDir({ profile, platform: platform3, home, env }) {
73191
73293
  if (platform3 === "win32") {
73192
- return (0, import_node_path68.join)(env.LOCALAPPDATA ?? (0, import_node_path68.join)(home, "AppData", "Local"), "Alan", profile);
73294
+ return (0, import_node_path69.join)(env.LOCALAPPDATA ?? (0, import_node_path69.join)(home, "AppData", "Local"), "Alan", profile);
73193
73295
  }
73194
- return (0, import_node_path68.join)(env.XDG_STATE_HOME ?? (0, import_node_path68.join)(home, ".local", "state"), "alan", profile);
73296
+ return (0, import_node_path69.join)(env.XDG_STATE_HOME ?? (0, import_node_path69.join)(home, ".local", "state"), "alan", profile);
73195
73297
  }
73196
73298
  function defaultInstallDir({ platform: platform3, home, env }) {
73197
73299
  if (platform3 === "win32") {
73198
- return (0, import_node_path68.join)(env.LOCALAPPDATA ?? (0, import_node_path68.join)(home, "AppData", "Local"), "Alan", "runtime");
73300
+ return (0, import_node_path69.join)(env.LOCALAPPDATA ?? (0, import_node_path69.join)(home, "AppData", "Local"), "Alan", "runtime");
73199
73301
  }
73200
- return (0, import_node_path68.join)(env.XDG_DATA_HOME ?? (0, import_node_path68.join)(home, ".local", "share"), "alan", "runtime");
73302
+ return (0, import_node_path69.join)(env.XDG_DATA_HOME ?? (0, import_node_path69.join)(home, ".local", "share"), "alan", "runtime");
73201
73303
  }
73202
73304
 
73203
73305
  // src/client/machine-features-contract.ts
@@ -73256,7 +73358,7 @@ var mcpConfigResultSchema = external_exports.object({
73256
73358
  });
73257
73359
 
73258
73360
  // src/client/runtime-client.ts
73259
- var import_promises69 = require("fs/promises");
73361
+ var import_promises70 = require("fs/promises");
73260
73362
  init_acp();
73261
73363
  init_runtime_v2();
73262
73364
 
@@ -73317,7 +73419,7 @@ var DEFAULT_BACKOFF = { initialMs: 250, maxMs: 3e4 };
73317
73419
  async function readDiscovery(path4) {
73318
73420
  let text3;
73319
73421
  try {
73320
- text3 = await (0, import_promises69.readFile)(path4, "utf8");
73422
+ text3 = await (0, import_promises70.readFile)(path4, "utf8");
73321
73423
  } catch (error62) {
73322
73424
  throw new RuntimeClientError("unavailable", "The runtime is not running", { cause: error62 });
73323
73425
  }
@@ -73699,9 +73801,9 @@ async function sendNativeHookSignal(discoveryPath, hookSignal, signal) {
73699
73801
  }
73700
73802
 
73701
73803
  // src/sessions/index.ts
73702
- var import_node_crypto31 = require("crypto");
73703
- var import_promises70 = require("fs/promises");
73704
- var import_node_path69 = require("path");
73804
+ var import_node_crypto32 = require("crypto");
73805
+ var import_promises71 = require("fs/promises");
73806
+ var import_node_path70 = require("path");
73705
73807
  init_runtime_v2();
73706
73808
 
73707
73809
  // src/sessions/admission.ts
@@ -73747,7 +73849,7 @@ var DEFAULT_MAX_ACTIVE_RUNS = 32;
73747
73849
  var HOLDER_BUSY = "busy";
73748
73850
  async function listIds(dir, schema) {
73749
73851
  const ids = [];
73750
- for (const name of await (0, import_promises70.readdir)(dir).catch(() => [])) {
73852
+ for (const name of await (0, import_promises71.readdir)(dir).catch(() => [])) {
73751
73853
  const parsed = schema.safeParse(name);
73752
73854
  if (parsed.success) ids.push(parsed.data);
73753
73855
  }
@@ -73761,8 +73863,8 @@ function holderIdentity(status) {
73761
73863
  return command === void 0 ? { pid, startedAt } : { pid, startedAt, command };
73762
73864
  }
73763
73865
  function sessionFiles(paths, conversationId) {
73764
- const dir = (0, import_node_path69.join)(paths.sessions, conversationId);
73765
- return { dir, launch: (0, import_node_path69.join)(dir, "launch.json"), status: (0, import_node_path69.join)(dir, "holder.json") };
73866
+ const dir = (0, import_node_path70.join)(paths.sessions, conversationId);
73867
+ return { dir, launch: (0, import_node_path70.join)(dir, "launch.json"), status: (0, import_node_path70.join)(dir, "holder.json") };
73766
73868
  }
73767
73869
  async function removeHolderFiles(files) {
73768
73870
  const holderWritten = [
@@ -73772,9 +73874,9 @@ async function removeHolderFiles(files) {
73772
73874
  sessionActivityPath(files.dir)
73773
73875
  ];
73774
73876
  for (const path4 of holderWritten) {
73775
- await (0, import_promises70.rm)(path4, { force: true });
73877
+ await (0, import_promises71.rm)(path4, { force: true });
73776
73878
  }
73777
- await (0, import_promises70.rmdir)(files.dir).catch((error62) => {
73879
+ await (0, import_promises71.rmdir)(files.dir).catch((error62) => {
73778
73880
  if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(errnoCode(error62) ?? "")) throw error62;
73779
73881
  });
73780
73882
  }
@@ -73943,8 +74045,8 @@ async function openSessions(deps) {
73943
74045
  protocol: HOLDER_PROTOCOL,
73944
74046
  conversationId,
73945
74047
  machineId: deps.machineId,
73946
- endpoint: ipcEndpoint(paths.sockets, (0, import_node_crypto31.randomUUID)().slice(0, 8)),
73947
- token: (0, import_node_crypto31.randomBytes)(32).toString("hex"),
74048
+ endpoint: ipcEndpoint(paths.sockets, (0, import_node_crypto32.randomUUID)().slice(0, 8)),
74049
+ token: (0, import_node_crypto32.randomBytes)(32).toString("hex"),
73948
74050
  runsDir: paths.runs,
73949
74051
  statusPath: files.status
73950
74052
  };
@@ -73970,7 +74072,7 @@ async function openSessions(deps) {
73970
74072
  const meta3 = await readRunMeta(dir.meta);
73971
74073
  const last = await readLastRecord(dir.log);
73972
74074
  if (meta3 === null || last === null) return null;
73973
- const logged = await (0, import_promises70.stat)(dir.log).catch((error62) => {
74075
+ const logged = await (0, import_promises71.stat)(dir.log).catch((error62) => {
73974
74076
  if (errnoCode(error62) === "ENOENT") return null;
73975
74077
  throw error62;
73976
74078
  });
@@ -74320,7 +74422,7 @@ function loadRuntimeConfig(env = process.env) {
74320
74422
  providerProbes: ALAN_RUNTIME_PROVIDER_PROBES === "on",
74321
74423
  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,
74322
74424
  home,
74323
- configHome: XDG_CONFIG_HOME ?? (0, import_node_path70.join)(home, ".config"),
74425
+ configHome: XDG_CONFIG_HOME ?? (0, import_node_path71.join)(home, ".config"),
74324
74426
  codexHome: resolveCodexHome(CODEX_HOME, home),
74325
74427
  ...githubProxyConfig({ ALAN_RUNTIME_GITHUB_PROXY, XDG_CONFIG_HOME, GH_CONFIG_DIR }, home),
74326
74428
  gitGatewayUrl: ALAN_RUNTIME_GIT_GATEWAY_URL ?? null,
@@ -74331,13 +74433,13 @@ function loadRuntimeConfig(env = process.env) {
74331
74433
  };
74332
74434
  }
74333
74435
  function resolveCodexHome(configuredHome, home) {
74334
- return configuredHome ?? (0, import_node_path70.join)(home, ".codex");
74436
+ return configuredHome ?? (0, import_node_path71.join)(home, ".codex");
74335
74437
  }
74336
74438
  function githubProxyConfig(env, home) {
74337
- const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path70.join)(home, ".config");
74439
+ const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path71.join)(home, ".config");
74338
74440
  return {
74339
74441
  githubProxy: env.ALAN_RUNTIME_GITHUB_PROXY === "on",
74340
- ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path70.join)(configHome, "gh")
74442
+ ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path71.join)(configHome, "gh")
74341
74443
  };
74342
74444
  }
74343
74445
  function serviceEnvironment2(env, profile) {
@@ -74395,9 +74497,9 @@ function takeEnrollmentCodeFromEnv(env = process.env) {
74395
74497
  }
74396
74498
 
74397
74499
  // src/cli/context.ts
74398
- var import_promises71 = require("fs/promises");
74500
+ var import_promises72 = require("fs/promises");
74399
74501
  var import_node_os11 = require("os");
74400
- var import_node_path71 = require("path");
74502
+ var import_node_path72 = require("path");
74401
74503
  var DESKTOP_BUNDLE_IDS = {
74402
74504
  production: ["com.alan-ai.desktop"],
74403
74505
  staging: ["com.alan-ai.desktop.staging"],
@@ -74437,7 +74539,7 @@ function serviceSpec({ config: config2, paths, self }) {
74437
74539
  profile: config2.profile,
74438
74540
  program: serviceCommand(config2.host, self, launcher),
74439
74541
  environment: config2.serviceEnvironment,
74440
- logPath: (0, import_node_path71.join)(paths.logs, "service.log"),
74542
+ logPath: (0, import_node_path72.join)(paths.logs, "service.log"),
74441
74543
  associatedBundleIds: DESKTOP_BUNDLE_IDS[config2.profile]
74442
74544
  };
74443
74545
  }
@@ -74445,7 +74547,7 @@ async function installedServiceSpec(ctx) {
74445
74547
  const spec = serviceSpec(ctx);
74446
74548
  if (ctx.config.host === "app") return spec;
74447
74549
  const layout = installLayout(ctx.config.installDir, ctx.config.profile);
74448
- const installed = await (0, import_promises71.access)(layout.launcher).then(
74550
+ const installed = await (0, import_promises72.access)(layout.launcher).then(
74449
74551
  () => true,
74450
74552
  () => false
74451
74553
  );
@@ -74573,7 +74675,7 @@ var manifestRevisionSchema = external_exports.object({ revision: external_export
74573
74675
  async function manifestRevision(path4) {
74574
74676
  let raw;
74575
74677
  try {
74576
- raw = JSON.parse(await (0, import_promises72.readFile)(path4, "utf8"));
74678
+ raw = JSON.parse(await (0, import_promises73.readFile)(path4, "utf8"));
74577
74679
  } catch (error62) {
74578
74680
  throw new RuntimeFault("invalid_file", `Cannot read the skill manifest at ${path4}`, {
74579
74681
  cause: error62
@@ -74591,7 +74693,7 @@ async function runSkills(argv) {
74591
74693
  case "scan":
74592
74694
  writeJson({
74593
74695
  status: "failed",
74594
- attemptId: (0, import_node_crypto32.randomUUID)(),
74696
+ attemptId: (0, import_node_crypto33.randomUUID)(),
74595
74697
  retainedInventoryRevision: null,
74596
74698
  diagnostics: [
74597
74699
  { code: "RUNTIME_SKILL_SCAN_UNSUPPORTED", message: SKILLS_SYNCED_BY_RUNTIME }
@@ -74607,7 +74709,7 @@ async function runSkills(argv) {
74607
74709
  );
74608
74710
  }
74609
74711
  writeJson({
74610
- attemptId: (0, import_node_crypto32.randomUUID)(),
74712
+ attemptId: (0, import_node_crypto33.randomUUID)(),
74611
74713
  desiredRevision: await manifestRevision(manifest),
74612
74714
  skills: []
74613
74715
  });
@@ -74627,8 +74729,8 @@ async function runSkills(argv) {
74627
74729
  }
74628
74730
 
74629
74731
  // src/cli/commands/doctor.ts
74630
- var import_promises75 = require("fs/promises");
74631
- var import_node_path75 = require("path");
74732
+ var import_promises76 = require("fs/promises");
74733
+ var import_node_path76 = require("path");
74632
74734
  init_runtime_v2();
74633
74735
 
74634
74736
  // src/identity/credential.ts
@@ -74636,8 +74738,8 @@ init_runtime_v2();
74636
74738
  init_zod();
74637
74739
 
74638
74740
  // src/identity/installation.ts
74639
- var import_node_crypto33 = require("crypto");
74640
- var import_node_path72 = require("path");
74741
+ var import_node_crypto34 = require("crypto");
74742
+ var import_node_path73 = require("path");
74641
74743
  init_runtime_v2();
74642
74744
  init_zod();
74643
74745
  var installationFileSchema = external_exports.object({
@@ -74645,7 +74747,7 @@ var installationFileSchema = external_exports.object({
74645
74747
  machineId: machineIdSchema.optional()
74646
74748
  });
74647
74749
  function installationPath(paths) {
74648
- return (0, import_node_path72.join)(paths.stateDir, "installation.json");
74750
+ return (0, import_node_path73.join)(paths.stateDir, "installation.json");
74649
74751
  }
74650
74752
  async function readInstallation(paths) {
74651
74753
  const result = await readJsonFile(installationPath(paths), installationFileSchema);
@@ -74654,7 +74756,7 @@ async function readInstallation(paths) {
74654
74756
  async function ensureInstallationId(paths) {
74655
74757
  const existing = await readInstallation(paths);
74656
74758
  if (existing !== null) return existing.installationId;
74657
- const created = { installationId: (0, import_node_crypto33.randomUUID)() };
74759
+ const created = { installationId: (0, import_node_crypto34.randomUUID)() };
74658
74760
  await writeJsonFileAtomic(installationPath(paths), created);
74659
74761
  return created.installationId;
74660
74762
  }
@@ -74836,7 +74938,7 @@ async function authorizeDevice(input2) {
74836
74938
  }
74837
74939
 
74838
74940
  // src/identity/enroll.ts
74839
- var import_promises73 = require("fs/promises");
74941
+ var import_promises74 = require("fs/promises");
74840
74942
  init_runtime_v2();
74841
74943
  async function enrollMachine(input2) {
74842
74944
  const machineId = input2.machineId ?? (await readMachineFile(input2.paths))?.machineId ?? (await readInstallation(input2.paths))?.machineId;
@@ -74919,13 +75021,13 @@ async function enrollFromGrantFile(input2) {
74919
75021
  clock: input2.clock,
74920
75022
  access: input2.access
74921
75023
  });
74922
- await (0, import_promises73.rm)(input2.grantPath, { force: true });
75024
+ await (0, import_promises74.rm)(input2.grantPath, { force: true });
74923
75025
  return machine;
74924
75026
  }
74925
75027
 
74926
75028
  // src/identity/migrate-v1.ts
74927
- var import_promises74 = require("fs/promises");
74928
- var import_node_path73 = require("path");
75029
+ var import_promises75 = require("fs/promises");
75030
+ var import_node_path74 = require("path");
74929
75031
  init_runtime_v2();
74930
75032
  init_zod();
74931
75033
  var EXIT_POLL_MS = 200;
@@ -74948,11 +75050,11 @@ var ownerLeaseSchema = external_exports.looseObject({ pid: external_exports.numb
74948
75050
  function legacyConfigPath(home, profile) {
74949
75051
  switch (profile) {
74950
75052
  case "production":
74951
- return (0, import_node_path73.join)(home, ".alan", "agent", "config.json");
75053
+ return (0, import_node_path74.join)(home, ".alan", "agent", "config.json");
74952
75054
  case "staging":
74953
- return (0, import_node_path73.join)(home, ".alan-staging", "agent", "config.json");
75055
+ return (0, import_node_path74.join)(home, ".alan-staging", "agent", "config.json");
74954
75056
  default:
74955
- return (0, import_node_path73.join)(home, ".alan-dev", "agent", "config.json");
75057
+ return (0, import_node_path74.join)(home, ".alan-dev", "agent", "config.json");
74956
75058
  }
74957
75059
  }
74958
75060
  async function findLegacyInstall(home, profile) {
@@ -75010,8 +75112,8 @@ async function scrubLegacyInstall(install2) {
75010
75112
  const scrubbed = { ...install2.config, migratedToRuntimeV2: true };
75011
75113
  for (const key of SCRUBBED_KEYS) delete scrubbed[key];
75012
75114
  await writeJsonFileAtomic(`${install2.configPath}.migrated-v1`, scrubbed);
75013
- await (0, import_promises74.rm)(install2.configPath, { force: true });
75014
- await (0, import_promises74.rm)(install2.ownerLeasePath, { force: true });
75115
+ await (0, import_promises75.rm)(install2.configPath, { force: true });
75116
+ await (0, import_promises75.rm)(install2.ownerLeasePath, { force: true });
75015
75117
  }
75016
75118
  async function exchangeCredential(deps) {
75017
75119
  const { config: config2 } = deps.install;
@@ -75125,7 +75227,7 @@ async function loadIdentity(paths, options = {}) {
75125
75227
  }
75126
75228
 
75127
75229
  // src/cli/commands/status.ts
75128
- var import_node_path74 = require("path");
75230
+ var import_node_path75 = require("path");
75129
75231
  async function serviceStatus(ctx) {
75130
75232
  try {
75131
75233
  return await createServiceManager(ctx.host, ctx.config.profile).status();
@@ -75152,7 +75254,7 @@ async function runtimeState(ctx) {
75152
75254
  const running = await readRunningRuntime(ctx.paths.lock);
75153
75255
  if (running === null) return { state: "offline", pid: null, localApi: null };
75154
75256
  const discovery = await readJsonFile(
75155
- (0, import_node_path74.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE),
75257
+ (0, import_node_path75.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE),
75156
75258
  localApiDiscoverySchema
75157
75259
  );
75158
75260
  const localApi = discovery.kind === "ok" && discovery.value.pid === running.pid ? {
@@ -75373,7 +75475,7 @@ async function runtimeCheck(ctx, status) {
75373
75475
  return check2("runtime", "warn", "No runtime is running for this profile");
75374
75476
  }
75375
75477
  const client = createRuntimeClient({
75376
- discoveryPath: (0, import_node_path75.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE)
75478
+ discoveryPath: (0, import_node_path76.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE)
75377
75479
  });
75378
75480
  try {
75379
75481
  const live = await client.status(AbortSignal.timeout(LOCAL_TIMEOUT_MS));
@@ -75400,7 +75502,7 @@ async function runtimeCheck(ctx, status) {
75400
75502
  }
75401
75503
  }
75402
75504
  async function probeHolder(dir, conversationId) {
75403
- const launch = await readJsonFile((0, import_node_path75.join)(dir, "launch.json"), holderLaunchSchema);
75505
+ const launch = await readJsonFile((0, import_node_path76.join)(dir, "launch.json"), holderLaunchSchema);
75404
75506
  if (launch.kind !== "ok") return null;
75405
75507
  try {
75406
75508
  const reply2 = await withTimeout(
@@ -75425,8 +75527,8 @@ async function probeHolder(dir, conversationId) {
75425
75527
  }
75426
75528
  }
75427
75529
  async function holdersCheck(ctx) {
75428
- const names = await (0, import_promises75.readdir)(ctx.paths.sessions).catch(() => []);
75429
- const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path75.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
75530
+ const names = await (0, import_promises76.readdir)(ctx.paths.sessions).catch(() => []);
75531
+ const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path76.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
75430
75532
  const dead = holders.filter((holder) => !holder.alive).length;
75431
75533
  return check2(
75432
75534
  "holders",
@@ -75437,10 +75539,10 @@ async function holdersCheck(ctx) {
75437
75539
  }
75438
75540
  async function freeBytesAt(path4) {
75439
75541
  try {
75440
- const stats = await (0, import_promises75.statfs)(path4);
75542
+ const stats = await (0, import_promises76.statfs)(path4);
75441
75543
  return { path: path4, freeBytes: stats.bavail * stats.bsize };
75442
75544
  } catch (error62) {
75443
- const parent = (0, import_node_path75.dirname)(path4);
75545
+ const parent = (0, import_node_path76.dirname)(path4);
75444
75546
  if (parent === path4) throw error62;
75445
75547
  return freeBytesAt(parent);
75446
75548
  }
@@ -75576,7 +75678,7 @@ async function runDoctor(argv, context = cliContext) {
75576
75678
  }
75577
75679
 
75578
75680
  // src/cli/commands/git-credential.ts
75579
- var import_promises76 = require("fs/promises");
75681
+ var import_promises77 = require("fs/promises");
75580
75682
  var import_node_net4 = require("net");
75581
75683
  var MAX_RESPONSE_BYTES = 64 * 1024;
75582
75684
  async function readAll(stream) {
@@ -75633,23 +75735,30 @@ function askGitCredentialSocket(endpoint, request2, signal) {
75633
75735
  function describe8(error62) {
75634
75736
  return error62 instanceof Error ? error62.message : String(error62);
75635
75737
  }
75738
+ async function readRuntimeToken(path4) {
75739
+ const read = await readJsonFile(path4, gitCredentialTokenSchema);
75740
+ if (read.kind === "ok") return read.value.token;
75741
+ throw new RuntimeFault(
75742
+ "io_failed",
75743
+ read.kind === "missing" ? "the Alan runtime is not running" : "the Alan runtime's git credential token is unreadable"
75744
+ );
75745
+ }
75636
75746
  async function answerGitCredential(action, deps) {
75637
75747
  if (action !== "get" && action !== "erase") return 0;
75638
75748
  const request2 = parseGitCredentialRequest(await deps.io.readStdin());
75639
75749
  const gatewayUrl = gitCredentialUrl(request2);
75640
75750
  if (gatewayUrl === null) return 0;
75641
75751
  const signal = AbortSignal.timeout(deps.budgetMs);
75752
+ const ask = async (op) => askGitCredentialSocket(
75753
+ deps.endpoint,
75754
+ { op, gatewayUrl, token: await readRuntimeToken(deps.tokenPath) },
75755
+ signal
75756
+ );
75642
75757
  if (action === "erase") {
75643
- await askGitCredentialSocket(deps.endpoint, { op: "erase", gatewayUrl }, signal).catch(
75644
- () => void 0
75645
- );
75758
+ await ask("erase").catch(() => void 0);
75646
75759
  return 0;
75647
75760
  }
75648
- const response = await askGitCredentialSocket(
75649
- deps.endpoint,
75650
- { op: "get", gatewayUrl },
75651
- signal
75652
- ).catch(
75761
+ const response = await ask("get").catch(
75653
75762
  (error62) => ({
75654
75763
  kind: "unavailable",
75655
75764
  message: describe8(error62)
@@ -75686,7 +75795,7 @@ async function configure(argv) {
75686
75795
  }
75687
75796
  async function configureGitGateway(config2, gatewayUrl, signal) {
75688
75797
  const { launcher } = installLayout(config2.installDir, config2.profile);
75689
- const installed = await (0, import_promises76.access)(launcher).then(
75798
+ const installed = await (0, import_promises77.access)(launcher).then(
75690
75799
  () => true,
75691
75800
  () => false
75692
75801
  );
@@ -75705,15 +75814,17 @@ async function runGitCredential(argv) {
75705
75814
  const [action, ...rest] = argv;
75706
75815
  if (action === "configure") return configure(rest);
75707
75816
  const config2 = loadRuntimeConfig();
75817
+ const { sockets } = runtimePaths(config2.stateDir);
75708
75818
  return answerGitCredential(action, {
75709
75819
  io: processIo(),
75710
- endpoint: gitCredentialEndpoint(runtimePaths(config2.stateDir).sockets),
75820
+ endpoint: gitCredentialEndpoint(sockets),
75821
+ tokenPath: gitCredentialTokenPath(sockets),
75711
75822
  budgetMs: GIT_CREDENTIAL_HELPER_BUDGET_MS
75712
75823
  });
75713
75824
  }
75714
75825
 
75715
75826
  // src/cli/commands/hold.ts
75716
- var import_node_path76 = require("path");
75827
+ var import_node_path77 = require("path");
75717
75828
  init_agent2();
75718
75829
  init_runtime_v2();
75719
75830
  async function machineAccess(paths, log, conversationId, transport) {
@@ -75772,7 +75883,7 @@ async function runHold(argv) {
75772
75883
  const config2 = loadRuntimeConfig();
75773
75884
  const paths = runtimePaths(config2.stateDir);
75774
75885
  const log = __using(_stack, openFileLog(
75775
- (0, import_node_path76.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
75886
+ (0, import_node_path77.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
75776
75887
  config2.logLevel,
75777
75888
  systemClock
75778
75889
  ));
@@ -75783,7 +75894,7 @@ async function runHold(argv) {
75783
75894
  );
75784
75895
  const transport = __using(_stack, createHttpTransport());
75785
75896
  const access7 = await machineAccess(paths, log, launch.value.conversationId, transport);
75786
- const credentialPath = (0, import_node_path76.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
75897
+ const credentialPath = (0, import_node_path77.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
75787
75898
  const managedMcp = __using(_stack, access7.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
75788
75899
  managedMcp: access7.managedMcp,
75789
75900
  conversationId: launch.value.conversationId,
@@ -75824,7 +75935,7 @@ async function runHold(argv) {
75824
75935
  }
75825
75936
 
75826
75937
  // src/cli/commands/hook.ts
75827
- var import_node_path77 = require("path");
75938
+ var import_node_path78 = require("path");
75828
75939
  var RUNTIME_ANSWER_MS = 2e3;
75829
75940
  var DEBUG_VARIABLE = "ALAN_HOOK_DEBUG";
75830
75941
  function flag(argv, name) {
@@ -75856,7 +75967,7 @@ async function forwardHook(argv, io) {
75856
75967
  return "transcript outside provider root";
75857
75968
  }
75858
75969
  const verdict = await io.send(
75859
- (0, import_node_path77.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
75970
+ (0, import_node_path78.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
75860
75971
  hookSignal,
75861
75972
  AbortSignal.timeout(RUNTIME_ANSWER_MS)
75862
75973
  );
@@ -75892,7 +76003,7 @@ async function runHook(argv, overrides = {}) {
75892
76003
  }
75893
76004
 
75894
76005
  // src/cli/commands/ingestion-hooks.ts
75895
- var import_promises77 = require("fs/promises");
76006
+ var import_promises78 = require("fs/promises");
75896
76007
  var CODEX_TRUST_NOTE = "Codex runs new hooks only after you review them: open /hooks in Codex.";
75897
76008
  function isAction(value2) {
75898
76009
  return value2 === "enable" || value2 === "disable" || value2 === "status";
@@ -75915,7 +76026,7 @@ function errorMessage2(error62) {
75915
76026
  return error62 instanceof Error ? error62.message : String(error62);
75916
76027
  }
75917
76028
  async function exists5(path4) {
75918
- return (0, import_promises77.access)(path4).then(
76029
+ return (0, import_promises78.access)(path4).then(
75919
76030
  () => true,
75920
76031
  () => false
75921
76032
  );
@@ -76018,10 +76129,10 @@ async function runIntegrationsCommand(argv) {
76018
76129
  }
76019
76130
 
76020
76131
  // src/cli/commands/legacy.ts
76021
- var import_node_path79 = require("path");
76132
+ var import_node_path80 = require("path");
76022
76133
 
76023
76134
  // src/cli/commands/setup.ts
76024
- var import_node_path78 = require("path");
76135
+ var import_node_path79 = require("path");
76025
76136
  init_zod();
76026
76137
 
76027
76138
  // src/cli/legacy.ts
@@ -76105,7 +76216,7 @@ async function grantFileCredential(argv, grantPath, ctx, deps) {
76105
76216
  return enrollFromGrantFile({
76106
76217
  paths: ctx.paths,
76107
76218
  storeKind: credentialStoreFlag(argv) ?? ctx.config.credentialStore,
76108
- grantPath: (0, import_node_path78.resolve)(grantPath),
76219
+ grantPath: (0, import_node_path79.resolve)(grantPath),
76109
76220
  clock: deps.clock,
76110
76221
  access: ctx.access
76111
76222
  });
@@ -76181,7 +76292,7 @@ async function runSetup(argv, signal) {
76181
76292
  var _stack = [];
76182
76293
  try {
76183
76294
  const ctx = cliContext();
76184
- const log = __using(_stack, openFileLog((0, import_node_path78.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76295
+ const log = __using(_stack, openFileLog((0, import_node_path79.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76185
76296
  const result = await setupMachine(argv, ctx, {
76186
76297
  enrollment: (apiUrl) => createEnrollmentClient({ apiUrl }),
76187
76298
  isProcessAlive,
@@ -76264,7 +76375,7 @@ async function runToken(argv, signal) {
76264
76375
  );
76265
76376
  }
76266
76377
  const ctx = cliContext();
76267
- const log = __using(_stack, openFileLog((0, import_node_path79.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76378
+ const log = __using(_stack, openFileLog((0, import_node_path80.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76268
76379
  const result = await rotateMachineCredential(ctx, { clock: systemClock, log, signal });
76269
76380
  process.stdout.write(`${rotationMessage(result)}
76270
76381
  `);
@@ -76276,8 +76387,8 @@ async function runToken(argv, signal) {
76276
76387
  }
76277
76388
 
76278
76389
  // src/cli/commands/logout.ts
76279
- var import_promises78 = require("fs/promises");
76280
- var import_node_path80 = require("path");
76390
+ var import_promises79 = require("fs/promises");
76391
+ var import_node_path81 = require("path");
76281
76392
  init_runtime_v2();
76282
76393
  var RUNTIME_EXIT_WAIT_MS = 35e3;
76283
76394
  var TURN_END_WAIT_MS = 3e4;
@@ -76336,9 +76447,9 @@ async function stopHolder(launch, deps, outcome2) {
76336
76447
  }
76337
76448
  async function stopHeldRuns(ctx, deps, outcome2 = "aborted") {
76338
76449
  const stopped = [];
76339
- for (const name of await (0, import_promises78.readdir)(ctx.paths.sessions).catch(() => [])) {
76450
+ for (const name of await (0, import_promises79.readdir)(ctx.paths.sessions).catch(() => [])) {
76340
76451
  const launch = await readJsonFile(
76341
- (0, import_node_path80.join)(ctx.paths.sessions, name, "launch.json"),
76452
+ (0, import_node_path81.join)(ctx.paths.sessions, name, "launch.json"),
76342
76453
  holderLaunchSchema
76343
76454
  );
76344
76455
  if (launch.kind !== "ok") continue;
@@ -76375,13 +76486,13 @@ async function forgetMachineLocally(ctx) {
76375
76486
  const machine = await readMachineFile(ctx.paths);
76376
76487
  if (machine === null) return;
76377
76488
  await credentialStoreFor(ctx.paths, machine.credentialStore, ctx.access).clear();
76378
- await (0, import_promises78.rm)(ctx.paths.machine, { force: true });
76489
+ await (0, import_promises79.rm)(ctx.paths.machine, { force: true });
76379
76490
  }
76380
76491
  async function runLogout(argv, signal) {
76381
76492
  var _stack = [];
76382
76493
  try {
76383
76494
  const ctx = cliContext();
76384
- const log = __using(_stack, openFileLog((0, import_node_path80.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76495
+ const log = __using(_stack, openFileLog((0, import_node_path81.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
76385
76496
  const result = await logoutMachine(argv, ctx, {
76386
76497
  api: (apiUrl, accessToken) => createApiClient({ apiUrl, accessToken }),
76387
76498
  stopHeldRuns,
@@ -76399,7 +76510,7 @@ async function runLogout(argv, signal) {
76399
76510
 
76400
76511
  // src/cli/commands/run.ts
76401
76512
  var import_node_fs27 = require("fs");
76402
- var import_node_path85 = require("path");
76513
+ var import_node_path86 = require("path");
76403
76514
 
76404
76515
  // src/local-api/app-attachments.ts
76405
76516
  function createAppAttachments(clock) {
@@ -76475,18 +76586,18 @@ function createRunAppends() {
76475
76586
  }
76476
76587
 
76477
76588
  // src/local-api/server.ts
76478
- var import_node_crypto35 = require("crypto");
76479
- var import_promises79 = require("fs/promises");
76589
+ var import_node_crypto36 = require("crypto");
76590
+ var import_promises80 = require("fs/promises");
76480
76591
  var import_node_http4 = require("http");
76481
- var import_node_path81 = require("path");
76592
+ var import_node_path82 = require("path");
76482
76593
 
76483
76594
  // src/local-api/guard.ts
76484
- var import_node_crypto34 = require("crypto");
76595
+ var import_node_crypto35 = require("crypto");
76485
76596
  var ALLOWED = { kind: "allowed" };
76486
- function tokenMatches2(expected, header) {
76597
+ function tokenMatches3(expected, header) {
76487
76598
  if (header === void 0 || !header.startsWith("Bearer ")) return false;
76488
76599
  const presented = Buffer.from(header.slice("Bearer ".length));
76489
- return presented.length === expected.length && (0, import_node_crypto34.timingSafeEqual)(presented, expected);
76600
+ return presented.length === expected.length && (0, import_node_crypto35.timingSafeEqual)(presented, expected);
76490
76601
  }
76491
76602
  function isBrowserReachable(req, allowedHosts) {
76492
76603
  if (req.headers.origin !== void 0 || req.headers.referer !== void 0) return true;
@@ -76513,7 +76624,7 @@ function createRequestGuard(options) {
76513
76624
  if (isBrowserReachable(req, allowedHosts)) {
76514
76625
  return { kind: "refused", status: 403, code: "forbidden", message: "Forbidden" };
76515
76626
  }
76516
- if (!tokenMatches2(expected, req.headers.authorization)) {
76627
+ if (!tokenMatches3(expected, req.headers.authorization)) {
76517
76628
  return { kind: "refused", status: 401, code: "unauthorized", message: "Unauthorized" };
76518
76629
  }
76519
76630
  return ALLOWED;
@@ -77474,7 +77585,7 @@ async function serveLocalApi(deps) {
77474
77585
  server.keepAliveTimeout = KEEP_ALIVE_TIMEOUT_MS;
77475
77586
  server.maxConnections = HARD_MAX_CONNECTIONS;
77476
77587
  const port = await listenOnLoopback(server);
77477
- const token = (0, import_node_crypto35.randomBytes)(32).toString("base64url");
77588
+ const token = (0, import_node_crypto36.randomBytes)(32).toString("base64url");
77478
77589
  const guard = createRequestGuard({ token, port, rateLimit: limits.rateLimit, clock });
77479
77590
  const appAttachments = createAppAttachments(clock);
77480
77591
  const routeDeps = {
@@ -77521,7 +77632,7 @@ async function serveLocalApi(deps) {
77521
77632
  startedAtMs,
77522
77633
  runtimeVersion: deps.runtimeVersion
77523
77634
  };
77524
- const discoveryPath = (0, import_node_path81.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
77635
+ const discoveryPath = (0, import_node_path82.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
77525
77636
  await writeJsonFileAtomic(discoveryPath, discovery);
77526
77637
  const followers = startMaintenance({
77527
77638
  everyMs: limits.refreshEveryMs,
@@ -77555,7 +77666,7 @@ async function serveLocalApi(deps) {
77555
77666
  await watchedStatus[Symbol.asyncDispose]();
77556
77667
  const current = await readJsonFile(discoveryPath, localApiDiscoverySchema);
77557
77668
  if (current.kind === "ok" && current.value.token === token) {
77558
- await (0, import_promises79.rm)(discoveryPath, { force: true });
77669
+ await (0, import_promises80.rm)(discoveryPath, { force: true });
77559
77670
  }
77560
77671
  await closeServer(server);
77561
77672
  log.info("local_api.closed", {});
@@ -77640,7 +77751,7 @@ function machineFeatureActions(deps) {
77640
77751
  }
77641
77752
 
77642
77753
  // src/cli/commands/machine-plane.ts
77643
- var import_node_path84 = require("path");
77754
+ var import_node_path85 = require("path");
77644
77755
 
77645
77756
  // src/link/index.ts
77646
77757
  init_runtime_v2();
@@ -81308,7 +81419,7 @@ function refusalFailure(refusal2) {
81308
81419
  }
81309
81420
 
81310
81421
  // src/link/probe.ts
81311
- var import_promises80 = require("dns/promises");
81422
+ var import_promises81 = require("dns/promises");
81312
81423
  var import_node_net5 = require("net");
81313
81424
  var import_node_tls2 = require("tls");
81314
81425
  var PROBE_TIMEOUT_MS3 = 5e3;
@@ -81344,7 +81455,7 @@ async function connectOnce(url3, clock) {
81344
81455
  }
81345
81456
  async function probeEndpoint(url3, clock) {
81346
81457
  try {
81347
- await (0, import_promises80.lookup)(url3.hostname);
81458
+ await (0, import_promises81.lookup)(url3.hostname);
81348
81459
  } catch (error62) {
81349
81460
  const reason = classifyTransportFailure(error62);
81350
81461
  return reason === "other" ? "dns" : reason;
@@ -81732,9 +81843,9 @@ function planReconcile(desired, held) {
81732
81843
  }
81733
81844
 
81734
81845
  // src/reconciler/desired-sync.ts
81735
- var import_node_crypto36 = require("crypto");
81846
+ var import_node_crypto37 = require("crypto");
81736
81847
  function fingerprintOf(desired) {
81737
- return (0, import_node_crypto36.createHash)("sha256").update(JSON.stringify(desired)).digest("hex");
81848
+ return (0, import_node_crypto37.createHash)("sha256").update(JSON.stringify(desired)).digest("hex");
81738
81849
  }
81739
81850
  var FAILED_READ_RETRY_MS = 3e4;
81740
81851
  function createDesiredSync(deps) {
@@ -81871,7 +81982,7 @@ function createReconciler(host, lifecycle, log, signal) {
81871
81982
  }
81872
81983
 
81873
81984
  // src/uploader/index.ts
81874
- var import_promises81 = require("fs/promises");
81985
+ var import_promises82 = require("fs/promises");
81875
81986
  init_runtime_v2();
81876
81987
  init_zod();
81877
81988
  var RETRY_DELAYS_MS = [250, 500, 1e3, 2e3, 5e3, 1e4, 3e4];
@@ -82161,13 +82272,13 @@ function startUploader({
82161
82272
  const isDone = (runId) => sealed.has(runId) || archive?.has(runId) === true;
82162
82273
  const unsealedRunIds = async () => {
82163
82274
  const runIds = [];
82164
- for (const name of await (0, import_promises81.readdir)(runsDir).catch(() => [])) {
82275
+ for (const name of await (0, import_promises82.readdir)(runsDir).catch(() => [])) {
82165
82276
  const runId = runIdSchema.safeParse(name);
82166
82277
  if (runId.success && !isDone(runId.data)) runIds.push(runId.data);
82167
82278
  }
82168
82279
  return runIds;
82169
82280
  };
82170
- const hasProgress = async (runId) => await (0, import_promises81.stat)(runDirectory(runsDir, runId).upload).catch(() => null) !== null;
82281
+ const hasProgress = async (runId) => await (0, import_promises82.stat)(runDirectory(runsDir, runId).upload).catch(() => null) !== null;
82171
82282
  const sweep2 = async () => {
82172
82283
  for (const runId of await unsealedRunIds()) {
82173
82284
  if (!await hasProgress(runId)) run2(runId);
@@ -82183,13 +82294,13 @@ function startUploader({
82183
82294
  const dir = runDirectory(runsDir, runId);
82184
82295
  const progress = await readJsonFile(dir.upload, uploadProgressSchema);
82185
82296
  if (progress.kind !== "ok" || !progress.value.sealed) return false;
82186
- const sealedAt = (await (0, import_promises81.stat)(dir.upload)).mtimeMs;
82297
+ const sealedAt = (await (0, import_promises82.stat)(dir.upload)).mtimeMs;
82187
82298
  if (clock.now() - sealedAt < options.sealedForMs) return false;
82188
82299
  return (await readLastRecord(dir.log))?.update.sessionUpdate === "_alan/run.ended";
82189
82300
  };
82190
82301
  const archivable = async (options) => {
82191
82302
  const found = [];
82192
- for (const name of await (0, import_promises81.readdir)(runsDir).catch(() => [])) {
82303
+ for (const name of await (0, import_promises82.readdir)(runsDir).catch(() => [])) {
82193
82304
  const runId = runIdSchema.safeParse(name);
82194
82305
  if (!runId.success || archive?.has(runId.data)) continue;
82195
82306
  try {
@@ -82226,7 +82337,7 @@ function startUploader({
82226
82337
 
82227
82338
  // src/cli/commands/activity-lease.ts
82228
82339
  var import_node_fs26 = require("fs");
82229
- var import_node_path82 = require("path");
82340
+ var import_node_path83 = require("path");
82230
82341
  var import_node_worker_threads = require("worker_threads");
82231
82342
  init_runtime_v2();
82232
82343
  var LEASE_BUNDLE = "alan-lease.cjs";
@@ -82250,7 +82361,7 @@ function spawnThread(script, data) {
82250
82361
  };
82251
82362
  }
82252
82363
  function leaseWorkerScript(bundlePath, exists6 = import_node_fs26.existsSync) {
82253
- const lean = (0, import_node_path82.join)((0, import_node_path82.dirname)(bundlePath), LEASE_BUNDLE);
82364
+ const lean = (0, import_node_path83.join)((0, import_node_path83.dirname)(bundlePath), LEASE_BUNDLE);
82254
82365
  return exists6(lean) ? lean : bundlePath;
82255
82366
  }
82256
82367
  function leasedRuns(held) {
@@ -82270,7 +82381,7 @@ function startActivityLeases(deps) {
82270
82381
  epoch: Math.floor(clock.now()),
82271
82382
  sessionsDir: deps.paths.sessions,
82272
82383
  runsDir: deps.paths.runs,
82273
- logPath: (0, import_node_path82.join)(deps.paths.logs, "runtime.jsonl"),
82384
+ logPath: (0, import_node_path83.join)(deps.paths.logs, "runtime.jsonl"),
82274
82385
  logLevel: deps.logLevel,
82275
82386
  intervalMs: ACTIVITY_LEASE_INTERVAL_MS,
82276
82387
  watchdogMs: deps.watchdogMs,
@@ -82510,12 +82621,12 @@ async function startMachineNativeIngest(deps) {
82510
82621
  }
82511
82622
 
82512
82623
  // src/cli/commands/run-updates.ts
82513
- var import_node_path83 = require("path");
82624
+ var import_node_path84 = require("path");
82514
82625
  init_runtime_v2();
82515
82626
  var UPDATE_CHECK_EVERY_MS = 6 * 60 * 60 * 1e3;
82516
82627
  var DEFERRED_RETRY_MS = 5 * 60 * 1e3;
82517
82628
  function isInstalledBundle(layout, bundlePath) {
82518
- return (0, import_node_path83.resolve)((0, import_node_path83.dirname)((0, import_node_path83.dirname)(bundlePath))) === (0, import_node_path83.resolve)(layout.versions);
82629
+ return (0, import_node_path84.resolve)((0, import_node_path84.dirname)((0, import_node_path84.dirname)(bundlePath))) === (0, import_node_path84.resolve)(layout.versions);
82519
82630
  }
82520
82631
  async function settleUpgradeOnStart({
82521
82632
  layout,
@@ -82622,7 +82733,7 @@ function startRuntimeUpdates(options) {
82622
82733
  layout,
82623
82734
  release: npmRelease,
82624
82735
  tarball: await options.downloader.download(npmRelease.dist.tarball, signal),
82625
- tmpDir: (0, import_node_path83.join)(layout.root, ".downloads")
82736
+ tmpDir: (0, import_node_path84.join)(layout.root, ".downloads")
82626
82737
  });
82627
82738
  await lifecycle.exclusive("upgrade", async () => {
82628
82739
  await recordPendingUpgrade(layout, currentVersion2, version2, clock.now());
@@ -82877,7 +82988,7 @@ async function startMachinePlane(deps) {
82877
82988
  [ALAN_MANAGED_SESSION_ENV]: "1"
82878
82989
  },
82879
82990
  cwd: paths.stateDir,
82880
- outputPath: (0, import_node_path84.join)(paths.logs, "holders.log")
82991
+ outputPath: (0, import_node_path85.join)(paths.logs, "holders.log")
82881
82992
  },
82882
82993
  deps.holderIsolation
82883
82994
  );
@@ -82939,7 +83050,7 @@ async function startMachinePlane(deps) {
82939
83050
  }),
82940
83051
  local: { home: config2.home, machineId: identity.machineId },
82941
83052
  // Only a cloud sandbox's runtime has a git gateway; a person's own ~/.codex is theirs.
82942
- ...config2.gitGatewayUrl === null ? {} : { codexSkillsDir: (0, import_node_path84.join)(config2.codexHome, "skills") },
83053
+ ...config2.gitGatewayUrl === null ? {} : { codexSkillsDir: (0, import_node_path85.join)(config2.codexHome, "skills") },
82943
83054
  log
82944
83055
  })
82945
83056
  );
@@ -83123,6 +83234,7 @@ async function startMachinePlane(deps) {
83123
83234
  stack.use(
83124
83235
  await startGitCredentialServer({
83125
83236
  endpoint: gitCredentialEndpoint(paths.sockets),
83237
+ tokenPath: gitCredentialTokenPath(paths.sockets),
83126
83238
  mint: (gatewayUrl, signal) => api.mintGitCapability(gatewayUrl, signal),
83127
83239
  renewCredential: async (signal) => {
83128
83240
  const renewal = await lifecycle.exclusive("renew", () => identity.rotate(signal));
@@ -83142,7 +83254,7 @@ async function startMachinePlane(deps) {
83142
83254
  git: createGitRunner({ env: cliEnvironment }),
83143
83255
  clock,
83144
83256
  log,
83145
- dir: (0, import_node_path84.join)(paths.stateDir, "checkout-freshness")
83257
+ dir: (0, import_node_path85.join)(paths.stateDir, "checkout-freshness")
83146
83258
  },
83147
83259
  stopped.signal
83148
83260
  );
@@ -83452,7 +83564,7 @@ function lockWaitMs(argv) {
83452
83564
  }
83453
83565
  async function openManagedProviders(config2, paths) {
83454
83566
  const providerEnv = readCliEnvironment();
83455
- const bundledNpm = (0, import_node_path85.join)((0, import_node_path85.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
83567
+ const bundledNpm = (0, import_node_path86.join)((0, import_node_path86.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
83456
83568
  const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs27.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
83457
83569
  const npmPath = providerToolchain?.node ?? await resolveCommandOnPath("npm", providerEnv, process.platform);
83458
83570
  const npmOptions = npmPath === null || process.platform === "win32" && providerToolchain === null ? null : {
@@ -83460,7 +83572,7 @@ async function openManagedProviders(config2, paths) {
83460
83572
  ...providerToolchain === null ? {} : { argsBeforeNpm: [providerToolchain.npmCli] },
83461
83573
  env: providerEnv
83462
83574
  };
83463
- const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path85.dirname)(providerToolchain.node);
83575
+ const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path86.dirname)(providerToolchain.node);
83464
83576
  const probeEnv = providerNodeDir === void 0 ? providerEnv : {
83465
83577
  ...providerEnv,
83466
83578
  PATH: `${providerNodeDir}${pathDelimiter(process.platform)}${envValue(providerEnv, "PATH")}`
@@ -83470,7 +83582,7 @@ async function openManagedProviders(config2, paths) {
83470
83582
  throw new Error("Provider installer is unavailable on this computer");
83471
83583
  };
83472
83584
  const managed = createManagedProviderClis({
83473
- root: (0, import_node_path85.join)(paths.stateDir, "provider-clis"),
83585
+ root: (0, import_node_path86.join)(paths.stateDir, "provider-clis"),
83474
83586
  resolveVersion: npmOptions === null ? unavailable : createNpmVersionResolver(npmOptions),
83475
83587
  installPackage: npmOptions === null ? unavailable : createNpmPackageInstaller(npmOptions),
83476
83588
  probe: (executable, backendKind) => probeManagedProvider(executable, backendKind, canonicalProbeEnv)
@@ -83502,7 +83614,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
83502
83614
  waitMs: lockWaitMs(argv),
83503
83615
  signal: stop
83504
83616
  }));
83505
- const log = __using(_stack, openFileLog((0, import_node_path85.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
83617
+ const log = __using(_stack, openFileLog((0, import_node_path86.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
83506
83618
  const lifecycle = createLifecycleQueue({ clock, log });
83507
83619
  const install2 = installLayout(config2.installDir, config2.profile);
83508
83620
  const bundlePath = process.argv[1] ?? "";
@@ -83536,7 +83648,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
83536
83648
  openCliEnvironment({
83537
83649
  env: readCliEnvironment(),
83538
83650
  platform: process.platform,
83539
- lastKnownGoodFile: (0, import_node_path85.join)(paths.stateDir, "login-path.json"),
83651
+ lastKnownGoodFile: (0, import_node_path86.join)(paths.stateDir, "login-path.json"),
83540
83652
  clock,
83541
83653
  decorate: (env) => withPackagedAlanCodeEngine(env, bundlePath, process.platform)
83542
83654
  })
@@ -83713,17 +83825,17 @@ async function runServiceCommand(argv, ctx = cliContext()) {
83713
83825
  }
83714
83826
 
83715
83827
  // src/cli/commands/upgrade.ts
83716
- var import_promises82 = require("fs/promises");
83717
- var import_node_path86 = require("path");
83828
+ var import_promises83 = require("fs/promises");
83829
+ var import_node_path87 = require("path");
83718
83830
  function isNotNewer(version2, installed) {
83719
83831
  return installed !== null && isReleaseVersion(version2) && isReleaseVersion(installed) && compareVersions(version2, installed) <= 0;
83720
83832
  }
83721
83833
  async function installFromSource(source) {
83722
83834
  const { layout, from, ifNewer } = source;
83723
- const isTarball = (await (0, import_promises82.stat)(from)).isFile();
83724
- const downloads = (0, import_node_path86.join)(layout.root, ".downloads");
83725
- if (isTarball) await (0, import_promises82.mkdir)(downloads, { recursive: true, mode: 448 });
83726
- const scratch = isTarball ? await (0, import_promises82.mkdtemp)((0, import_node_path86.join)(downloads, "upgrade-")) : null;
83835
+ const isTarball = (await (0, import_promises83.stat)(from)).isFile();
83836
+ const downloads = (0, import_node_path87.join)(layout.root, ".downloads");
83837
+ if (isTarball) await (0, import_promises83.mkdir)(downloads, { recursive: true, mode: 448 });
83838
+ const scratch = isTarball ? await (0, import_promises83.mkdtemp)((0, import_node_path87.join)(downloads, "upgrade-")) : null;
83727
83839
  try {
83728
83840
  const sourceDir = scratch === null ? from : await extractPackageTarball(from, scratch);
83729
83841
  const version2 = await readPackageVersion(sourceDir);
@@ -83731,7 +83843,7 @@ async function installFromSource(source) {
83731
83843
  if (ifNewer && isNotNewer(version2, installed)) return { kind: "skipped", version: version2, installed };
83732
83844
  return { kind: "installed", ...await installVersion(layout, sourceDir) };
83733
83845
  } finally {
83734
- if (scratch !== null) await (0, import_promises82.rm)(scratch, { recursive: true, force: true });
83846
+ if (scratch !== null) await (0, import_promises83.rm)(scratch, { recursive: true, force: true });
83735
83847
  }
83736
83848
  }
83737
83849
  async function runUpgrade(argv) {
@@ -83743,7 +83855,7 @@ async function runUpgrade(argv) {
83743
83855
  const layout = installLayout(config2.installDir, config2.profile);
83744
83856
  const outcome2 = await installFromSource({
83745
83857
  layout,
83746
- from: (0, import_node_path86.resolve)(from),
83858
+ from: (0, import_node_path87.resolve)(from),
83747
83859
  ifNewer: hasFlag(argv, "--if-newer")
83748
83860
  });
83749
83861
  if (outcome2.kind === "skipped") {