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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.cjs +207 -172
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -35445,7 +35445,7 @@ function buildComputerReadiness(input2) {
35445
35445
  }
35446
35446
 
35447
35447
  // src/version.ts
35448
- var AGENT_VERSION = "0.1.126";
35448
+ var AGENT_VERSION = "0.1.127";
35449
35449
 
35450
35450
  // src/daemon/status.ts
35451
35451
  var PENDING_RUN_START_TTL_MS = 10 * 6e4;
@@ -36769,7 +36769,7 @@ async function runHookCommand(args, overrides2 = {}) {
36769
36769
  }
36770
36770
 
36771
36771
  // src/cli/install.ts
36772
- var import_promises16 = require("timers/promises");
36772
+ var import_promises17 = require("timers/promises");
36773
36773
 
36774
36774
  // src/sleep-inhibitor.ts
36775
36775
  var import_node_child_process4 = require("child_process");
@@ -43669,31 +43669,34 @@ function isAlanDefaultWorkspace(value2) {
43669
43669
 
43670
43670
  // ../agent-core/dist/index.js
43671
43671
  var import_crypto7 = require("crypto");
43672
- var import_fs13 = require("fs");
43672
+ var import_promises5 = require("fs/promises");
43673
43673
  var import_os6 = require("os");
43674
43674
  var import_path13 = require("path");
43675
- var import_promises5 = require("timers/promises");
43675
+ var import_fs13 = require("fs");
43676
+ var import_os7 = require("os");
43676
43677
  var import_path14 = require("path");
43677
- var import_fs14 = require("fs");
43678
+ var import_promises6 = require("timers/promises");
43678
43679
  var import_path15 = require("path");
43679
- var import_fs15 = require("fs");
43680
- var import_os7 = require("os");
43680
+ var import_fs14 = require("fs");
43681
43681
  var import_path16 = require("path");
43682
- var import_crypto8 = require("crypto");
43683
- var import_fs16 = require("fs");
43682
+ var import_fs15 = require("fs");
43684
43683
  var import_os8 = require("os");
43685
43684
  var import_path17 = require("path");
43686
- var import_fs17 = require("fs");
43685
+ var import_crypto8 = require("crypto");
43686
+ var import_fs16 = require("fs");
43687
43687
  var import_os9 = require("os");
43688
43688
  var import_path18 = require("path");
43689
- var import_crypto9 = require("crypto");
43690
- var import_fs18 = require("fs");
43689
+ var import_fs17 = require("fs");
43691
43690
  var import_os10 = require("os");
43692
43691
  var import_path19 = require("path");
43693
- var import_child_process8 = require("child_process");
43694
- var import_fs19 = require("fs");
43692
+ var import_crypto9 = require("crypto");
43693
+ var import_fs18 = require("fs");
43695
43694
  var import_os11 = require("os");
43696
43695
  var import_path20 = require("path");
43696
+ var import_child_process8 = require("child_process");
43697
+ var import_fs19 = require("fs");
43698
+ var import_os12 = require("os");
43699
+ var import_path21 = require("path");
43697
43700
  function createGrammarState() {
43698
43701
  return { seenToolCallIds: /* @__PURE__ */ new Set(), counter: 0, scratch: {} };
43699
43702
  }
@@ -45570,7 +45573,9 @@ function spawnWindowsJob(file2, args, options) {
45570
45573
  }
45571
45574
  }
45572
45575
  if (useShell && commandArgs.some((arg) => /[\r\n]/.test(arg))) {
45573
- throw new Error("Multiline provider arguments require a native executable or a Node CLI shim");
45576
+ throw new Error(
45577
+ `Multiline provider arguments require a native executable or a Node CLI shim, but ${commandFile} runs through cmd.exe. Point Alan at the provider's .exe (for Claude Code, set ALAN_CLAUDE_PATH) and restart Alan.`
45578
+ );
45574
45579
  }
45575
45580
  const meta22 = /([()\][%!^"`<>&|;, *?])/g;
45576
45581
  const escapeCmd = (value2) => value2.replace(meta22, "^$1");
@@ -51047,8 +51052,8 @@ var disallowedTools = (input2) => {
51047
51052
  const tools = getClaudeDisallowedTools(config22(input2));
51048
51053
  return tools.length > 0 ? tools.join(",") : void 0;
51049
51054
  };
51050
- var freshSystemPrompt = (input2) => input2.resume.resumeId ? void 0 : trimmedOrUndefined(config22(input2).systemPrompt);
51051
- var appendedSystemPrompt = (input2) => input2.resume.resumeId ? trimmedOrUndefined(config22(input2).systemPromptAppend) : void 0;
51055
+ var systemPromptFile = (input2) => input2.promptFiles.system;
51056
+ var appendSystemPromptFile = (input2) => input2.promptFiles.append;
51052
51057
  var hasMcpGrant = (input2) => Boolean(config22(input2).alanMcp);
51053
51058
  var baseModel = (input2) => collapseModelIdToBase(trimmedOrUndefined(config22(input2).selectedModel) ?? "");
51054
51059
  var modelArg = (input2) => {
@@ -51074,8 +51079,8 @@ var CLAUDE_FLAGS = [
51074
51079
  { build: option("--permission-mode", permissionMode) },
51075
51080
  { build: spreadArgs(managedMcpArgs) },
51076
51081
  { build: option("--disallowedTools", disallowedTools) },
51077
- { build: option("--system-prompt", freshSystemPrompt) },
51078
- { build: option("--append-system-prompt", appendedSystemPrompt) },
51082
+ { build: option("--system-prompt-file", systemPromptFile) },
51083
+ { build: option("--append-system-prompt-file", appendSystemPromptFile) },
51079
51084
  { requires: "supportsApproveMcps", build: flag("--approve-mcps", hasMcpGrant) },
51080
51085
  { build: option("--model", modelArg) },
51081
51086
  { build: option("--effort", effort) },
@@ -51615,6 +51620,30 @@ function latchApiError(event, state) {
51615
51620
  function numberOf(value2) {
51616
51621
  return typeof value2 === "number" && Number.isFinite(value2) ? value2 : 0;
51617
51622
  }
51623
+ var NO_PROMPT_FILES = { paths: {}, dispose: async () => {
51624
+ } };
51625
+ async function writeClaudePromptFiles(context, resume) {
51626
+ const system = resume.resumeId ? void 0 : trimmedOrUndefined(context.config.systemPrompt);
51627
+ const append = resume.resumeId ? trimmedOrUndefined(context.config.systemPromptAppend) : void 0;
51628
+ if (!system && !append) return NO_PROMPT_FILES;
51629
+ const directory = await (0, import_promises5.mkdtemp)((0, import_path13.join)((0, import_os6.tmpdir)(), "alan-claude-prompt-"));
51630
+ const dispose = () => (0, import_promises5.rm)(directory, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
51631
+ try {
51632
+ const paths = {};
51633
+ if (system) {
51634
+ paths.system = (0, import_path13.join)(directory, "system-prompt.md");
51635
+ await (0, import_promises5.writeFile)(paths.system, system, "utf8");
51636
+ }
51637
+ if (append) {
51638
+ paths.append = (0, import_path13.join)(directory, "append-system-prompt.md");
51639
+ await (0, import_promises5.writeFile)(paths.append, append, "utf8");
51640
+ }
51641
+ return { paths, dispose };
51642
+ } catch (error61) {
51643
+ await dispose();
51644
+ throw error61;
51645
+ }
51646
+ }
51618
51647
  function planClaudeResume(context) {
51619
51648
  const requestedResumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
51620
51649
  if (!requestedResumeId) return {};
@@ -51669,29 +51698,35 @@ function createClaudeCliBackend(command = "claude", defaultArgs = []) {
51669
51698
  needsApproveMcps: Boolean(context.config.alanMcp)
51670
51699
  });
51671
51700
  const resume = planClaudeResume(context);
51672
- const args = buildClaudeCliArgs(
51673
- {
51674
- context,
51675
- capabilities,
51676
- resume,
51677
- managedRegistration,
51678
- externalServers: externalMcp?.servers
51679
- },
51680
- defaultArgs
51681
- );
51682
- return createCliBackend({
51683
- kind: "claude_cli",
51684
- supportTier: "structured",
51685
- command,
51686
- args,
51687
- parseStructuredLine: grammarAsStructuredLineParser(claudeGrammar, claudeEffects),
51688
- stdinWriter: (stdin, ctx) => {
51689
- stdin.write(`${buildClaudeUserMessage(ctx, resume)}
51701
+ const promptFiles = await writeClaudePromptFiles(context, resume);
51702
+ try {
51703
+ const args = buildClaudeCliArgs(
51704
+ {
51705
+ context,
51706
+ capabilities,
51707
+ resume,
51708
+ managedRegistration,
51709
+ externalServers: externalMcp?.servers,
51710
+ promptFiles: promptFiles.paths
51711
+ },
51712
+ defaultArgs
51713
+ );
51714
+ return await createCliBackend({
51715
+ kind: "claude_cli",
51716
+ supportTier: "structured",
51717
+ command,
51718
+ args,
51719
+ parseStructuredLine: grammarAsStructuredLineParser(claudeGrammar, claudeEffects),
51720
+ stdinWriter: (stdin, ctx) => {
51721
+ stdin.write(`${buildClaudeUserMessage(ctx, resume)}
51690
51722
  `);
51691
- },
51692
- keepStdinOpen: true,
51693
- stopBackgroundTask: (task, ctx, state) => requestClaudeTaskStop(task, ctx, state)
51694
- }).run(runContext);
51723
+ },
51724
+ keepStdinOpen: true,
51725
+ stopBackgroundTask: (task, ctx, state) => requestClaudeTaskStop(task, ctx, state)
51726
+ }).run(runContext);
51727
+ } finally {
51728
+ await promptFiles.dispose();
51729
+ }
51695
51730
  }
51696
51731
  };
51697
51732
  }
@@ -51799,7 +51834,7 @@ function foldImageGenerationLine(entryType, payload, fold) {
51799
51834
  id: item.id,
51800
51835
  call_id: toolCallId,
51801
51836
  result: item.result,
51802
- filename: savedPath && (0, import_path14.basename)(savedPath)
51837
+ filename: savedPath && (0, import_path15.basename)(savedPath)
51803
51838
  },
51804
51839
  { dataFields: ["result"], toolIdFields: ["call_id"], idFields: ["id"] }
51805
51840
  ) : null;
@@ -51825,18 +51860,18 @@ function takeImageGenerationUpdates(fold) {
51825
51860
  var DAY_MS = 24 * 60 * 60 * 1e3;
51826
51861
  var MAX_HEADER_BYTES = 1024 * 1024;
51827
51862
  function workerDirectories(rootLog) {
51828
- const directory = (0, import_path15.dirname)(rootLog);
51829
- const monthDirectory = (0, import_path15.dirname)(directory);
51830
- const yearDirectory = (0, import_path15.dirname)(monthDirectory);
51831
- const date5 = `${(0, import_path15.basename)(yearDirectory)}-${(0, import_path15.basename)(monthDirectory)}-${(0, import_path15.basename)(directory)}`;
51863
+ const directory = (0, import_path16.dirname)(rootLog);
51864
+ const monthDirectory = (0, import_path16.dirname)(directory);
51865
+ const yearDirectory = (0, import_path16.dirname)(monthDirectory);
51866
+ const date5 = `${(0, import_path16.basename)(yearDirectory)}-${(0, import_path16.basename)(monthDirectory)}-${(0, import_path16.basename)(directory)}`;
51832
51867
  if (!/^\d{4}-\d{2}-\d{2}$/.test(date5)) return [directory];
51833
51868
  const timestamp = Date.parse(`${date5}T00:00:00Z`);
51834
51869
  if (!Number.isFinite(timestamp) || new Date(timestamp).toISOString().slice(0, 10) !== date5)
51835
51870
  return [directory];
51836
- const sessionsDirectory2 = (0, import_path15.dirname)(yearDirectory);
51871
+ const sessionsDirectory2 = (0, import_path16.dirname)(yearDirectory);
51837
51872
  return [0, 1, -1].map((offset2) => {
51838
51873
  const day = new Date(timestamp + offset2 * DAY_MS).toISOString().slice(0, 10);
51839
- return (0, import_path15.join)(sessionsDirectory2, ...day.split("-"));
51874
+ return (0, import_path16.join)(sessionsDirectory2, ...day.split("-"));
51840
51875
  });
51841
51876
  }
51842
51877
  function firstLine(path2) {
@@ -51873,7 +51908,7 @@ function findCodexWorkerLogs(rootLog, parentThreadId) {
51873
51908
  }
51874
51909
  for (const entry of entries) {
51875
51910
  if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
51876
- const path2 = (0, import_path15.join)(directory, entry.name);
51911
+ const path2 = (0, import_path16.join)(directory, entry.name);
51877
51912
  if (path2 === rootLog) continue;
51878
51913
  try {
51879
51914
  const line = firstLine(path2);
@@ -51901,7 +51936,7 @@ function findCodexWorkerLogs(rootLog, parentThreadId) {
51901
51936
  return workers;
51902
51937
  }
51903
51938
  function resolveCodexHome(env) {
51904
- return env.CODEX_HOME || process.env.CODEX_HOME || (0, import_path13.join)((0, import_os6.homedir)(), ".codex");
51939
+ return env.CODEX_HOME || process.env.CODEX_HOME || (0, import_path14.join)((0, import_os7.homedir)(), ".codex");
51905
51940
  }
51906
51941
  function mtimeOf(path2) {
51907
51942
  try {
@@ -51915,11 +51950,11 @@ function newestMatchIn(dir, entries, sessionId) {
51915
51950
  (entry) => entry.isFile() && entry.name.endsWith(".jsonl") && entry.name.includes(sessionId)
51916
51951
  );
51917
51952
  if (matches.length === 0) return null;
51918
- if (matches.length === 1) return (0, import_path13.join)(dir, matches[0].name);
51953
+ if (matches.length === 1) return (0, import_path14.join)(dir, matches[0].name);
51919
51954
  let best = "";
51920
51955
  let bestMtime = -1;
51921
51956
  for (const entry of matches) {
51922
- const path2 = (0, import_path13.join)(dir, entry.name);
51957
+ const path2 = (0, import_path14.join)(dir, entry.name);
51923
51958
  const mtime = mtimeOf(path2);
51924
51959
  if (mtime > bestMtime) {
51925
51960
  best = path2;
@@ -51930,7 +51965,7 @@ function newestMatchIn(dir, entries, sessionId) {
51930
51965
  }
51931
51966
  function findCodexSessionLog(runtimeSessionId, codexHome) {
51932
51967
  if (!runtimeSessionId) return null;
51933
- const stack = [(0, import_path13.join)(codexHome, "sessions")];
51968
+ const stack = [(0, import_path14.join)(codexHome, "sessions")];
51934
51969
  while (stack.length > 0) {
51935
51970
  const dir = stack.pop();
51936
51971
  let entries;
@@ -51943,7 +51978,7 @@ function findCodexSessionLog(runtimeSessionId, codexHome) {
51943
51978
  if (match) return match;
51944
51979
  const subdirs = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
51945
51980
  subdirs.sort();
51946
- for (const name of subdirs) stack.push((0, import_path13.join)(dir, name));
51981
+ for (const name of subdirs) stack.push((0, import_path14.join)(dir, name));
51947
51982
  }
51948
51983
  return null;
51949
51984
  }
@@ -52379,7 +52414,7 @@ async function flushCodexImageGenerationOnExit(context, state) {
52379
52414
  const updates = takeImageGenerationUpdates(fold);
52380
52415
  if (updates.length === 0) break;
52381
52416
  for (const update of updates) emitSessionUpdate(update, context, state);
52382
- if (fold.updates.length > 0) await (0, import_promises5.setTimeout)(EXIT_IMAGE_SPACING_MS);
52417
+ if (fold.updates.length > 0) await (0, import_promises6.setTimeout)(EXIT_IMAGE_SPACING_MS);
52383
52418
  }
52384
52419
  for (const update of settlePendingImageGenerations(fold))
52385
52420
  emitSessionUpdate(update, context, state);
@@ -54669,8 +54704,8 @@ function activeTaskIdNamedIn(state, content) {
54669
54704
  }
54670
54705
  function writeCopilotMcpConfig(registration) {
54671
54706
  if (!registration) return null;
54672
- const dir = (0, import_fs15.mkdtempSync)((0, import_path16.join)((0, import_os7.tmpdir)(), "alan-copilot-mcp-"));
54673
- const path2 = (0, import_path16.join)(dir, "mcp-config.json");
54707
+ const dir = (0, import_fs15.mkdtempSync)((0, import_path17.join)((0, import_os8.tmpdir)(), "alan-copilot-mcp-"));
54708
+ const path2 = (0, import_path17.join)(dir, "mcp-config.json");
54674
54709
  (0, import_fs15.writeFileSync)(
54675
54710
  path2,
54676
54711
  JSON.stringify({
@@ -54688,12 +54723,12 @@ function writeCopilotMcpConfig(registration) {
54688
54723
  return { path: path2, cleanup: () => (0, import_fs15.rmSync)(dir, { recursive: true, force: true }) };
54689
54724
  }
54690
54725
  function resolveCopilotHome(env) {
54691
- return env.COPILOT_HOME || (0, import_path17.join)(env.HOME || (0, import_os8.homedir)(), ".copilot");
54726
+ return env.COPILOT_HOME || (0, import_path18.join)(env.HOME || (0, import_os9.homedir)(), ".copilot");
54692
54727
  }
54693
54728
  function copilotSessionPresence(sessionId, home) {
54694
- const stateRoot = (0, import_path17.join)(home, "session-state");
54729
+ const stateRoot = (0, import_path18.join)(home, "session-state");
54695
54730
  if (!(0, import_fs16.existsSync)(stateRoot)) return "unknown";
54696
- return (0, import_fs16.existsSync)((0, import_path17.join)(stateRoot, sessionId, "events.jsonl")) ? "present" : "missing";
54731
+ return (0, import_fs16.existsSync)((0, import_path18.join)(stateRoot, sessionId, "events.jsonl")) ? "present" : "missing";
54697
54732
  }
54698
54733
  function freshSession(contextPrefix) {
54699
54734
  const sessionId = (0, import_crypto8.randomUUID)();
@@ -55359,11 +55394,11 @@ function cursorConversationStepText(steps) {
55359
55394
  }
55360
55395
  function cursorTranscriptsRoot(context) {
55361
55396
  const projectKey = context.cwd.replace(/^[/\\]+/, "").replace(/[/\\]+/g, "-");
55362
- const home = context.env.HOME || process.env.HOME || (0, import_os9.homedir)();
55363
- return (0, import_path18.join)(home, ".cursor", "projects", projectKey, "agent-transcripts");
55397
+ const home = context.env.HOME || process.env.HOME || (0, import_os10.homedir)();
55398
+ return (0, import_path19.join)(home, ".cursor", "projects", projectKey, "agent-transcripts");
55364
55399
  }
55365
55400
  function cursorTranscriptPathForAgent(context, agentId) {
55366
- return (0, import_path18.join)(cursorTranscriptsRoot(context), agentId, `${agentId}.jsonl`);
55401
+ return (0, import_path19.join)(cursorTranscriptsRoot(context), agentId, `${agentId}.jsonl`);
55367
55402
  }
55368
55403
  function resolveCursorSubagentTranscriptPath(success2, context) {
55369
55404
  const explicit = success2?.transcriptPath ?? success2?.transcript_path;
@@ -55733,10 +55768,10 @@ function workspaceKeys(cwd) {
55733
55768
  );
55734
55769
  }
55735
55770
  function cursorChatPresence(query) {
55736
- const chatsRoot = (0, import_path19.join)(query.home, ".cursor", "chats");
55771
+ const chatsRoot = (0, import_path20.join)(query.home, ".cursor", "chats");
55737
55772
  if (!(0, import_fs18.existsSync)(chatsRoot)) return "unknown";
55738
55773
  const found = workspaceKeys(query.cwd).some(
55739
- (key) => (0, import_fs18.existsSync)((0, import_path19.join)(chatsRoot, key, query.chatId, "store.db"))
55774
+ (key) => (0, import_fs18.existsSync)((0, import_path20.join)(chatsRoot, key, query.chatId, "store.db"))
55740
55775
  );
55741
55776
  return found ? "present" : "missing";
55742
55777
  }
@@ -55746,7 +55781,7 @@ function planCursorResume(context) {
55746
55781
  const presence = cursorChatPresence({
55747
55782
  chatId: requestedResumeId,
55748
55783
  cwd: context.cwd,
55749
- home: context.env.HOME || (0, import_os10.homedir)()
55784
+ home: context.env.HOME || (0, import_os11.homedir)()
55750
55785
  });
55751
55786
  if (presence !== "missing") return { resumeId: requestedResumeId };
55752
55787
  const contextPrefix = context.config.resumeFallbackContext?.trim() || void 0;
@@ -57749,8 +57784,8 @@ function createKimiCliBackend(command = "kimi", defaultArgs = []) {
57749
57784
  async run(context) {
57750
57785
  const dialect = await detectKimiCliDialect(command, context);
57751
57786
  const registration = dialect === "kimi-cli" ? context.config.alanMcp : void 0;
57752
- const mcpDirectory = registration ? (0, import_fs19.mkdtempSync)((0, import_path20.join)((0, import_os11.tmpdir)(), "alan-kimi-mcp-")) : null;
57753
- const mcpConfigPath = mcpDirectory ? (0, import_path20.join)(mcpDirectory, "mcp.json") : null;
57787
+ const mcpDirectory = registration ? (0, import_fs19.mkdtempSync)((0, import_path21.join)((0, import_os12.tmpdir)(), "alan-kimi-mcp-")) : null;
57788
+ const mcpConfigPath = mcpDirectory ? (0, import_path21.join)(mcpDirectory, "mcp.json") : null;
57754
57789
  if (registration && mcpConfigPath) {
57755
57790
  (0, import_fs19.writeFileSync)(
57756
57791
  mcpConfigPath,
@@ -63952,11 +63987,11 @@ function removeNativeHooks(homeDir = (0, import_node_os14.homedir)()) {
63952
63987
  }
63953
63988
 
63954
63989
  // src/events/runtime-command-reply.ts
63955
- var import_promises6 = require("timers/promises");
63990
+ var import_promises7 = require("timers/promises");
63956
63991
  async function publishRuntimeCommandReply(path2, reply, credentials) {
63957
63992
  const body = JSON.stringify(reply);
63958
63993
  for (let attempt = 0; attempt < 2; attempt += 1) {
63959
- if (attempt > 0) await (0, import_promises6.setTimeout)(250, void 0, { signal: credentials.signal });
63994
+ if (attempt > 0) await (0, import_promises7.setTimeout)(250, void 0, { signal: credentials.signal });
63960
63995
  credentials.signal.throwIfAborted();
63961
63996
  let response;
63962
63997
  try {
@@ -63993,7 +64028,7 @@ var import_node_fs19 = require("fs");
63993
64028
  // src/events/live.ts
63994
64029
  var import_node_crypto9 = require("crypto");
63995
64030
  var import_node_fs17 = require("fs");
63996
- var import_promises9 = require("fs/promises");
64031
+ var import_promises10 = require("fs/promises");
63997
64032
 
63998
64033
  // src/events/http-retry.ts
63999
64034
  var TranscriptRequestError = class extends Error {
@@ -64054,7 +64089,7 @@ function requestDeadline(timeoutMs, parent) {
64054
64089
  // src/events/push.ts
64055
64090
  var import_node_crypto8 = require("crypto");
64056
64091
  var import_node_fs16 = require("fs");
64057
- var import_promises8 = require("fs/promises");
64092
+ var import_promises9 = require("fs/promises");
64058
64093
 
64059
64094
  // src/events/session.ts
64060
64095
  var import_node_fs15 = require("fs");
@@ -64263,7 +64298,7 @@ function writeRunTranscriptState(configPath, conversationId, runId, state) {
64263
64298
  }
64264
64299
 
64265
64300
  // src/events/transcript-buffer.ts
64266
- var import_promises7 = require("fs/promises");
64301
+ var import_promises8 = require("fs/promises");
64267
64302
  var RETAINED_BYTES = 256 * 1024;
64268
64303
  var MAX_PENDING_TRANSCRIPT_BYTES = 8 * 1024 * 1024;
64269
64304
  var TranscriptBuffer = class {
@@ -64323,7 +64358,7 @@ function closeTranscriptBuffer(path2, buffer) {
64323
64358
  async function retryTranscriptWrites(path2, runId) {
64324
64359
  const buffer = active.get(path2);
64325
64360
  if (!buffer || buffer.runId !== runId) return void 0;
64326
- const file2 = await (0, import_promises7.open)(path2, "r+");
64361
+ const file2 = await (0, import_promises8.open)(path2, "r+");
64327
64362
  try {
64328
64363
  const stat4 = await file2.stat();
64329
64364
  if (`${stat4.dev}.${stat4.ino}.${stat4.birthtimeMs}` !== buffer.generation)
@@ -64723,7 +64758,7 @@ function startTranscriptPush(target, onProblem) {
64723
64758
  const current = state();
64724
64759
  if (!current) throw new Error("Transcript run range disappeared");
64725
64760
  const end = Math.min(boundary, admitted + adaptivePushBytes);
64726
- const file2 = await (0, import_promises8.open)(path2, "r");
64761
+ const file2 = await (0, import_promises9.open)(path2, "r");
64727
64762
  let bytes;
64728
64763
  try {
64729
64764
  bytes = Buffer.alloc(end - admitted);
@@ -64966,7 +65001,7 @@ function startTranscriptLive(target, onProblem) {
64966
65001
  if (active2 && from < active2.retainedFrom)
64967
65002
  length = Math.min(length, active2.retainedFrom - from);
64968
65003
  bytes = Buffer.alloc(length);
64969
- const file2 = await (0, import_promises9.open)(path2, "r");
65004
+ const file2 = await (0, import_promises10.open)(path2, "r");
64970
65005
  try {
64971
65006
  const read = await file2.read(bytes, 0, length, from);
64972
65007
  if (read.bytesRead !== length) throw new Error("Live transcript changed during read");
@@ -65514,7 +65549,7 @@ function createTranscriptWatchRegistry() {
65514
65549
 
65515
65550
  // src/native/ingest.ts
65516
65551
  var import_node_fs21 = require("fs");
65517
- var import_promises11 = require("fs/promises");
65552
+ var import_promises12 = require("fs/promises");
65518
65553
 
65519
65554
  // src/native/alan-runs.ts
65520
65555
  function nativeProviderForBackend(backendKind) {
@@ -65853,7 +65888,7 @@ function reconcileTranscriptIdentity(entry, transcriptPath2, identity, size) {
65853
65888
 
65854
65889
  // src/native/turns.ts
65855
65890
  var import_node_crypto11 = require("crypto");
65856
- var import_promises10 = require("fs/promises");
65891
+ var import_promises11 = require("fs/promises");
65857
65892
  var SCAN_BYTES = 1024 * 1024;
65858
65893
  var MIN_READ_BYTES = 64 * 1024;
65859
65894
  var SKIPPED_RECORD_LINE = Buffer.from("\n");
@@ -65900,7 +65935,7 @@ async function findRecordEnd(handle, from, size) {
65900
65935
  return null;
65901
65936
  }
65902
65937
  async function readTranscriptWindow(path2, offset2, limits) {
65903
- const handle = await (0, import_promises10.open)(path2, "r");
65938
+ const handle = await (0, import_promises11.open)(path2, "r");
65904
65939
  try {
65905
65940
  const stats = await handle.stat({ bigint: true });
65906
65941
  const size = Number(stats.size);
@@ -66427,7 +66462,7 @@ function createNativeIngestionSink(deps) {
66427
66462
  store.put(entry);
66428
66463
  if (ending) log3("native-ingest-turn", worker, "closed");
66429
66464
  }
66430
- const current = await (0, import_promises11.stat)(path2).catch(() => void 0);
66465
+ const current = await (0, import_promises12.stat)(path2).catch(() => void 0);
66431
66466
  return { grewDuringPass: current !== void 0 && current.size > lastSize };
66432
66467
  };
66433
66468
  const handleFailure = (worker, error61) => {
@@ -66914,12 +66949,12 @@ var RuntimeSkillCoordinator = class {
66914
66949
  // src/skills/runtime-skill-manager.ts
66915
66950
  var import_node_buffer5 = require("buffer");
66916
66951
  var import_node_crypto14 = require("crypto");
66917
- var import_promises14 = require("fs/promises");
66952
+ var import_promises15 = require("fs/promises");
66918
66953
  var import_node_path24 = require("path");
66919
66954
 
66920
66955
  // src/skills/managed-skill-store.ts
66921
66956
  var import_node_crypto12 = require("crypto");
66922
- var import_promises12 = require("fs/promises");
66957
+ var import_promises13 = require("fs/promises");
66923
66958
  var import_node_path22 = require("path");
66924
66959
  var EMPTY_STATE = {
66925
66960
  version: 1,
@@ -66935,9 +66970,9 @@ var ManagedSkillStore = class _ManagedSkillStore {
66935
66970
  state;
66936
66971
  integrity;
66937
66972
  static async open(baseDirectory) {
66938
- await (0, import_promises12.mkdir)(baseDirectory, { recursive: true, mode: 448 });
66973
+ await (0, import_promises13.mkdir)(baseDirectory, { recursive: true, mode: 448 });
66939
66974
  try {
66940
- const parsed = JSON.parse(await (0, import_promises12.readFile)((0, import_node_path22.join)(baseDirectory, "state.json"), "utf8"));
66975
+ const parsed = JSON.parse(await (0, import_promises13.readFile)((0, import_node_path22.join)(baseDirectory, "state.json"), "utf8"));
66941
66976
  return new _ManagedSkillStore(baseDirectory, parseState(parsed), "verified");
66942
66977
  } catch (error61) {
66943
66978
  if (isMissingPath(error61)) {
@@ -67001,15 +67036,15 @@ var ManagedSkillStore = class _ManagedSkillStore {
67001
67036
  `.state.json.pending-${process.pid}-${(0, import_node_crypto12.randomBytes)(6).toString("hex")}`
67002
67037
  );
67003
67038
  try {
67004
- await (0, import_promises12.writeFile)(pendingPath, `${JSON.stringify(this.state, null, 2)}
67039
+ await (0, import_promises13.writeFile)(pendingPath, `${JSON.stringify(this.state, null, 2)}
67005
67040
  `, {
67006
67041
  encoding: "utf8",
67007
67042
  flag: "wx",
67008
67043
  mode: 384
67009
67044
  });
67010
- await (0, import_promises12.rename)(pendingPath, statePath);
67045
+ await (0, import_promises13.rename)(pendingPath, statePath);
67011
67046
  } finally {
67012
- await (0, import_promises12.rm)(pendingPath, { force: true });
67047
+ await (0, import_promises13.rm)(pendingPath, { force: true });
67013
67048
  }
67014
67049
  }
67015
67050
  };
@@ -67064,7 +67099,7 @@ function isMissingPath(error61) {
67064
67099
  // ../shared/dist/node/skill-bundle.js
67065
67100
  var import_node_buffer3 = require("buffer");
67066
67101
  var import_node_crypto13 = require("crypto");
67067
- var import_promises13 = require("fs/promises");
67102
+ var import_promises14 = require("fs/promises");
67068
67103
  var import_node_path23 = require("path");
67069
67104
  var import_node_stream = require("stream");
67070
67105
  var import_node_zlib = require("zlib");
@@ -67074,7 +67109,7 @@ async function createSkillBundle(packageRoot, options = {}) {
67074
67109
  const archive = (0, import_tar_stream.pack)();
67075
67110
  const tarPromise = collectStream(archive);
67076
67111
  for (const file2 of before.files) {
67077
- const bytes2 = await (0, import_promises13.readFile)((0, import_node_path23.join)(packageRoot, ...file2.path.split("/")));
67112
+ const bytes2 = await (0, import_promises14.readFile)((0, import_node_path23.join)(packageRoot, ...file2.path.split("/")));
67078
67113
  await addArchiveEntry(archive, {
67079
67114
  name: file2.path,
67080
67115
  type: "file",
@@ -67106,7 +67141,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
67106
67141
  throw new Error("Skill archive hash does not match the expected immutable Version");
67107
67142
  }
67108
67143
  const tarBytes = await decompressBounded(archiveBytes);
67109
- await (0, import_promises13.mkdir)(destination, { recursive: false, mode: 448 });
67144
+ await (0, import_promises14.mkdir)(destination, { recursive: false, mode: 448 });
67110
67145
  try {
67111
67146
  await extractTar(tarBytes, destination);
67112
67147
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -67114,7 +67149,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
67114
67149
  throw new Error("Extracted Skill package hash does not match the expected immutable Version");
67115
67150
  }
67116
67151
  } catch (error61) {
67117
- await (0, import_promises13.rm)(destination, { recursive: true, force: true });
67152
+ await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67118
67153
  throw error61;
67119
67154
  }
67120
67155
  }
@@ -67190,8 +67225,8 @@ async function extractEntry(header, stream, destination, limits) {
67190
67225
  throw new Error(`Skill archive file size is invalid: ${path2}`);
67191
67226
  }
67192
67227
  const outputPath = (0, import_node_path23.join)(destination, ...path2.split("/"));
67193
- await (0, import_promises13.mkdir)((0, import_node_path23.dirname)(outputPath), { recursive: true, mode: 448 });
67194
- await (0, import_promises13.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
67228
+ await (0, import_promises14.mkdir)((0, import_node_path23.dirname)(outputPath), { recursive: true, mode: 448 });
67229
+ await (0, import_promises14.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
67195
67230
  }
67196
67231
  function requireSafeArchivePath(value2) {
67197
67232
  const normalized2 = value2.replaceAll("\\", "/").normalize("NFC");
@@ -67451,12 +67486,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67451
67486
  }
67452
67487
  async reconcileUnlocked(manifest) {
67453
67488
  const desired = desiredSkillManifestSchema.parse(manifest);
67454
- await (0, import_promises14.mkdir)(this.managedSkillsDirectory, { recursive: true, mode: 448 });
67455
- await (0, import_promises14.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "cache", "sha256"), {
67489
+ await (0, import_promises15.mkdir)(this.managedSkillsDirectory, { recursive: true, mode: 448 });
67490
+ await (0, import_promises15.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "cache", "sha256"), {
67456
67491
  recursive: true,
67457
67492
  mode: 448
67458
67493
  });
67459
- await (0, import_promises14.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "tmp"), { recursive: true, mode: 448 });
67494
+ await (0, import_promises15.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "tmp"), { recursive: true, mode: 448 });
67460
67495
  const results = [];
67461
67496
  const nextProjections = {};
67462
67497
  for (const entry of desired.skills) {
@@ -67579,52 +67614,52 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67579
67614
  let sourceMoved = false;
67580
67615
  let destinationInstalled = false;
67581
67616
  try {
67582
- await (0, import_promises14.rename)(source2, backup);
67617
+ await (0, import_promises15.rename)(source2, backup);
67583
67618
  sourceMoved = true;
67584
- await (0, import_promises14.cp)(backup, pending, { recursive: true, errorOnExist: true, force: false });
67619
+ await (0, import_promises15.cp)(backup, pending, { recursive: true, errorOnExist: true, force: false });
67585
67620
  const skillMarkdown = (0, import_node_path24.join)(pending, "SKILL.md");
67586
- await (0, import_promises14.writeFile)(
67621
+ await (0, import_promises15.writeFile)(
67587
67622
  skillMarkdown,
67588
- rewriteSkillMarkdownName(await (0, import_promises14.readFile)(skillMarkdown, "utf8"), name),
67623
+ rewriteSkillMarkdownName(await (0, import_promises15.readFile)(skillMarkdown, "utf8"), name),
67589
67624
  {
67590
67625
  encoding: "utf8",
67591
67626
  mode: 420
67592
67627
  }
67593
67628
  );
67594
67629
  await inspectSkillPackage(pending, { expectedName: name });
67595
- await (0, import_promises14.rename)(pending, destination);
67630
+ await (0, import_promises15.rename)(pending, destination);
67596
67631
  destinationInstalled = true;
67597
- await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67632
+ await (0, import_promises15.rm)(backup, { recursive: true, force: true });
67598
67633
  } catch (error61) {
67599
- if (destinationInstalled) await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67634
+ if (destinationInstalled) await (0, import_promises15.rm)(destination, { recursive: true, force: true });
67600
67635
  if (sourceMoved && await pathExists2(backup) && !await pathExists2(source2)) {
67601
- await (0, import_promises14.rename)(backup, source2);
67636
+ await (0, import_promises15.rename)(backup, source2);
67602
67637
  }
67603
67638
  throw error61;
67604
67639
  } finally {
67605
- await (0, import_promises14.rm)(pending, { recursive: true, force: true });
67640
+ await (0, import_promises15.rm)(pending, { recursive: true, force: true });
67606
67641
  if (!sourceMoved || destinationInstalled) {
67607
- await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67642
+ await (0, import_promises15.rm)(backup, { recursive: true, force: true });
67608
67643
  }
67609
67644
  }
67610
67645
  }
67611
67646
  async overwriteLocalConflict(input2, entry, conflict, manifest) {
67612
67647
  const source2 = this.conflictDirectory(entry.runtimeDirectory, conflict.kind);
67613
67648
  const backup = `${source2}.overwrite-backup-${process.pid}-${(0, import_node_crypto14.randomBytes)(8).toString("hex")}`;
67614
- await (0, import_promises14.rename)(source2, backup);
67649
+ await (0, import_promises15.rename)(source2, backup);
67615
67650
  try {
67616
67651
  const reconciled = await this.reconcileUnlocked(manifest);
67617
67652
  const result = resolutionFromReconcile(input2, reconciled);
67618
67653
  if (result.state !== "applied") {
67619
67654
  await this.removeResolvedProjection(entry, conflict.kind);
67620
- await (0, import_promises14.rename)(backup, source2);
67655
+ await (0, import_promises15.rename)(backup, source2);
67621
67656
  return result;
67622
67657
  }
67623
- await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67658
+ await (0, import_promises15.rm)(backup, { recursive: true, force: true });
67624
67659
  return result;
67625
67660
  } catch (error61) {
67626
67661
  await this.removeResolvedProjection(entry, conflict.kind).catch(() => void 0);
67627
- if (!await pathExists2(source2) && await pathExists2(backup)) await (0, import_promises14.rename)(backup, source2);
67662
+ if (!await pathExists2(source2) && await pathExists2(backup)) await (0, import_promises15.rename)(backup, source2);
67628
67663
  throw error61;
67629
67664
  }
67630
67665
  }
@@ -67634,7 +67669,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67634
67669
  if (conflictKind === "managed_destination") {
67635
67670
  const marker = await readMarker(destination);
67636
67671
  if (marker?.skillId === entry.skillId && marker.versionId === entry.versionId && marker.contentHash === entry.contentHash) {
67637
- await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67672
+ await (0, import_promises15.rm)(destination, { recursive: true, force: true });
67638
67673
  }
67639
67674
  return;
67640
67675
  }
@@ -67666,16 +67701,16 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67666
67701
  if (!await legacyFileMatches(source2, legacy.hash) || !await packageMatches(source2, entry.contentHash)) {
67667
67702
  return;
67668
67703
  }
67669
- await (0, import_promises14.rename)(source2, destination);
67704
+ await (0, import_promises15.rename)(source2, destination);
67670
67705
  try {
67671
- await (0, import_promises14.writeFile)(
67706
+ await (0, import_promises15.writeFile)(
67672
67707
  (0, import_node_path24.join)(destination, ".alan-managed.json"),
67673
67708
  `${JSON.stringify(markerFor(entry), null, 2)}
67674
67709
  `,
67675
67710
  { encoding: "utf8", flag: "wx", mode: 384 }
67676
67711
  );
67677
67712
  } catch (error61) {
67678
- await (0, import_promises14.rename)(destination, source2).catch(() => void 0);
67713
+ await (0, import_promises15.rename)(destination, source2).catch(() => void 0);
67679
67714
  throw error61;
67680
67715
  }
67681
67716
  await removeExactLegacySkill((0, import_node_path24.join)(this.compatibilitySkillsDirectory, entry.slug), legacy.hash);
@@ -67688,7 +67723,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67688
67723
  await removeExactLegacySkill((0, import_node_path24.join)(this.managedSkillsDirectory, command), entry.hash);
67689
67724
  await removeExactLegacySkill((0, import_node_path24.join)(this.compatibilitySkillsDirectory, command), entry.hash);
67690
67725
  }
67691
- await (0, import_promises14.rm)(this.legacyManifestPath, { force: true });
67726
+ await (0, import_promises15.rm)(this.legacyManifestPath, { force: true });
67692
67727
  }
67693
67728
  async ensureCached(entry) {
67694
67729
  const cacheDirectory = (0, import_node_path24.join)(
@@ -67698,7 +67733,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67698
67733
  entry.contentHash.slice("sha256:".length)
67699
67734
  );
67700
67735
  if (await packageMatches(cacheDirectory, entry.contentHash)) return cacheDirectory;
67701
- await (0, import_promises14.rm)(cacheDirectory, { recursive: true, force: true });
67736
+ await (0, import_promises15.rm)(cacheDirectory, { recursive: true, force: true });
67702
67737
  const bytes = await this.downloadBundle(entry);
67703
67738
  if (bytes.byteLength !== entry.compressedBytes) {
67704
67739
  throw new Error(
@@ -67716,12 +67751,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67716
67751
  expectedContentHash: entry.contentHash
67717
67752
  });
67718
67753
  try {
67719
- await (0, import_promises14.rename)(pendingDirectory, cacheDirectory);
67754
+ await (0, import_promises15.rename)(pendingDirectory, cacheDirectory);
67720
67755
  } catch (error61) {
67721
67756
  if (!await packageMatches(cacheDirectory, entry.contentHash)) throw error61;
67722
67757
  }
67723
67758
  } finally {
67724
- await (0, import_promises14.rm)(pendingDirectory, { recursive: true, force: true });
67759
+ await (0, import_promises15.rm)(pendingDirectory, { recursive: true, force: true });
67725
67760
  }
67726
67761
  return cacheDirectory;
67727
67762
  }
@@ -67739,8 +67774,8 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67739
67774
  let installedPending = false;
67740
67775
  let completed = false;
67741
67776
  try {
67742
- await (0, import_promises14.cp)(cacheDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67743
- await (0, import_promises14.writeFile)(
67777
+ await (0, import_promises15.cp)(cacheDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67778
+ await (0, import_promises15.writeFile)(
67744
67779
  (0, import_node_path24.join)(pending, ".alan-managed.json"),
67745
67780
  `${JSON.stringify(markerFor(entry), null, 2)}
67746
67781
  `,
@@ -67750,14 +67785,14 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67750
67785
  throw new Error("Pending managed Skill projection failed content verification");
67751
67786
  }
67752
67787
  if (await pathExists2(destination)) {
67753
- await (0, import_promises14.rename)(destination, backup);
67788
+ await (0, import_promises15.rename)(destination, backup);
67754
67789
  movedExisting = true;
67755
67790
  }
67756
67791
  try {
67757
- await (0, import_promises14.rename)(pending, destination);
67792
+ await (0, import_promises15.rename)(pending, destination);
67758
67793
  installedPending = true;
67759
67794
  } catch (error61) {
67760
- if (movedExisting) await (0, import_promises14.rename)(backup, destination);
67795
+ if (movedExisting) await (0, import_promises15.rename)(backup, destination);
67761
67796
  throw error61;
67762
67797
  }
67763
67798
  const inspected = await inspectSkillPackage(destination, { expectedName: null });
@@ -67766,18 +67801,18 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67766
67801
  }
67767
67802
  await this.ensureCompatibilityProjection(entry, destination);
67768
67803
  completed = true;
67769
- await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67804
+ await (0, import_promises15.rm)(backup, { recursive: true, force: true });
67770
67805
  return inspected.contentHash;
67771
67806
  } catch (error61) {
67772
67807
  if (!completed && installedPending) {
67773
- await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67774
- if (movedExisting && await pathExists2(backup)) await (0, import_promises14.rename)(backup, destination);
67808
+ await (0, import_promises15.rm)(destination, { recursive: true, force: true });
67809
+ if (movedExisting && await pathExists2(backup)) await (0, import_promises15.rename)(backup, destination);
67775
67810
  }
67776
67811
  throw error61;
67777
67812
  } finally {
67778
- await (0, import_promises14.rm)(pending, { recursive: true, force: true });
67813
+ await (0, import_promises15.rm)(pending, { recursive: true, force: true });
67779
67814
  if (completed || !movedExisting) {
67780
- await (0, import_promises14.rm)(backup, { recursive: true, force: true });
67815
+ await (0, import_promises15.rm)(backup, { recursive: true, force: true });
67781
67816
  }
67782
67817
  }
67783
67818
  }
@@ -67805,7 +67840,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67805
67840
  const failures = [];
67806
67841
  let entries;
67807
67842
  try {
67808
- entries = await (0, import_promises14.readdir)(this.managedSkillsDirectory);
67843
+ entries = await (0, import_promises15.readdir)(this.managedSkillsDirectory);
67809
67844
  } catch (error61) {
67810
67845
  if (isMissingPath2(error61)) return failures;
67811
67846
  throw error61;
@@ -67842,12 +67877,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67842
67877
  });
67843
67878
  continue;
67844
67879
  }
67845
- await (0, import_promises14.rm)(destination, { recursive: true, force: true });
67880
+ await (0, import_promises15.rm)(destination, { recursive: true, force: true });
67846
67881
  }
67847
67882
  return failures;
67848
67883
  }
67849
67884
  async ensureCompatibilityProjection(entry, canonicalDirectory) {
67850
- await (0, import_promises14.mkdir)(this.compatibilitySkillsDirectory, { recursive: true, mode: 448 });
67885
+ await (0, import_promises15.mkdir)(this.compatibilitySkillsDirectory, { recursive: true, mode: 448 });
67851
67886
  const destination = (0, import_node_path24.join)(
67852
67887
  this.compatibilitySkillsDirectory,
67853
67888
  this.projectionDirectoryName(entry.runtimeDirectory)
@@ -67857,23 +67892,23 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67857
67892
  throw unmanagedCompatibilityConflict(entry.runtimeDirectory);
67858
67893
  }
67859
67894
  try {
67860
- await (0, import_promises14.symlink)(canonicalDirectory, destination, "dir");
67895
+ await (0, import_promises15.symlink)(canonicalDirectory, destination, "dir");
67861
67896
  return;
67862
67897
  } catch (error61) {
67863
67898
  if (!isSymlinkUnsupported(error61)) throw error61;
67864
67899
  }
67865
67900
  const pending = `${destination}.pending-${process.pid}-${(0, import_node_crypto14.randomBytes)(6).toString("hex")}`;
67866
67901
  try {
67867
- await (0, import_promises14.cp)(canonicalDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67868
- await (0, import_promises14.writeFile)(
67902
+ await (0, import_promises15.cp)(canonicalDirectory, pending, { recursive: true, errorOnExist: true, force: false });
67903
+ await (0, import_promises15.writeFile)(
67869
67904
  (0, import_node_path24.join)(pending, ".alan-compatibility.json"),
67870
67905
  `${JSON.stringify({ ...markerFor(entry), canonicalDirectory }, null, 2)}
67871
67906
  `,
67872
67907
  { encoding: "utf8", flag: "wx", mode: 384 }
67873
67908
  );
67874
- await (0, import_promises14.rename)(pending, destination);
67909
+ await (0, import_promises15.rename)(pending, destination);
67875
67910
  } finally {
67876
- await (0, import_promises14.rm)(pending, { recursive: true, force: true });
67911
+ await (0, import_promises15.rm)(pending, { recursive: true, force: true });
67877
67912
  }
67878
67913
  }
67879
67914
  async runExclusively(work) {
@@ -67897,29 +67932,29 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67897
67932
  return this.storageNamespace ? `${runtimeDirectory}--alan-${this.storageNamespace}` : runtimeDirectory;
67898
67933
  }
67899
67934
  async withMachineLock(work) {
67900
- await (0, import_promises14.mkdir)(this.skillsStateDirectory, { recursive: true, mode: 448 });
67935
+ await (0, import_promises15.mkdir)(this.skillsStateDirectory, { recursive: true, mode: 448 });
67901
67936
  const lockDirectory = (0, import_node_path24.join)(this.skillsStateDirectory, "manager.lock");
67902
67937
  const deadline = Date.now() + 3e4;
67903
67938
  while (true) {
67904
67939
  try {
67905
- await (0, import_promises14.mkdir)(lockDirectory, { mode: 448 });
67940
+ await (0, import_promises15.mkdir)(lockDirectory, { mode: 448 });
67906
67941
  try {
67907
- await (0, import_promises14.writeFile)(
67942
+ await (0, import_promises15.writeFile)(
67908
67943
  (0, import_node_path24.join)(lockDirectory, "owner.json"),
67909
67944
  `${JSON.stringify({ pid: process.pid, acquiredAt: (/* @__PURE__ */ new Date()).toISOString() })}
67910
67945
  `,
67911
67946
  { encoding: "utf8", flag: "wx", mode: 384 }
67912
67947
  );
67913
67948
  } catch (error61) {
67914
- await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
67949
+ await (0, import_promises15.rm)(lockDirectory, { recursive: true, force: true });
67915
67950
  throw error61;
67916
67951
  }
67917
67952
  break;
67918
67953
  } catch (error61) {
67919
67954
  if (!isAlreadyPresent2(error61)) throw error61;
67920
- const ageMs = await (0, import_promises14.stat)(lockDirectory).then((metadata) => Date.now() - metadata.mtimeMs).catch(() => 0);
67955
+ const ageMs = await (0, import_promises15.stat)(lockDirectory).then((metadata) => Date.now() - metadata.mtimeMs).catch(() => 0);
67921
67956
  if (ageMs > 15 * 6e4) {
67922
- await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
67957
+ await (0, import_promises15.rm)(lockDirectory, { recursive: true, force: true });
67923
67958
  continue;
67924
67959
  }
67925
67960
  if (Date.now() >= deadline) {
@@ -67933,7 +67968,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
67933
67968
  try {
67934
67969
  return await work();
67935
67970
  } finally {
67936
- await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
67971
+ await (0, import_promises15.rm)(lockDirectory, { recursive: true, force: true });
67937
67972
  }
67938
67973
  }
67939
67974
  };
@@ -67955,7 +67990,7 @@ async function packageMatches(directory, expectedHash) {
67955
67990
  async function readMarker(directory) {
67956
67991
  try {
67957
67992
  const value2 = JSON.parse(
67958
- await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, ".alan-managed.json"), "utf8")
67993
+ await (0, import_promises15.readFile)((0, import_node_path24.join)(directory, ".alan-managed.json"), "utf8")
67959
67994
  );
67960
67995
  if (typeof value2 !== "object" || value2 === null || !("protocolVersion" in value2) || value2.protocolVersion !== SKILLS_PROTOCOL_VERSION || !("skillId" in value2) || typeof value2.skillId !== "string" || !("versionId" in value2) || typeof value2.versionId !== "string" || !("contentHash" in value2) || typeof value2.contentHash !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value2.contentHash)) {
67961
67996
  return null;
@@ -67966,9 +68001,9 @@ async function readMarker(directory) {
67966
68001
  }
67967
68002
  }
67968
68003
  async function compatibilityProjectionMatches(destination, canonicalDirectory, entry) {
67969
- const metadata = await (0, import_promises14.lstat)(destination);
68004
+ const metadata = await (0, import_promises15.lstat)(destination);
67970
68005
  if (metadata.isSymbolicLink()) {
67971
- const target = await (0, import_promises14.readlink)(destination);
68006
+ const target = await (0, import_promises15.readlink)(destination);
67972
68007
  return (0, import_node_path24.resolve)((0, import_node_path24.dirname)(destination), target) === (0, import_node_path24.resolve)(canonicalDirectory);
67973
68008
  }
67974
68009
  if (!metadata.isDirectory()) return false;
@@ -67977,22 +68012,22 @@ async function compatibilityProjectionMatches(destination, canonicalDirectory, e
67977
68012
  }
67978
68013
  async function removeCompatibilityProjection(destination, canonicalDirectory, projection) {
67979
68014
  if (!await pathExists2(destination)) return true;
67980
- const metadata = await (0, import_promises14.lstat)(destination);
68015
+ const metadata = await (0, import_promises15.lstat)(destination);
67981
68016
  if (metadata.isSymbolicLink()) {
67982
- const target = await (0, import_promises14.readlink)(destination);
68017
+ const target = await (0, import_promises15.readlink)(destination);
67983
68018
  if ((0, import_node_path24.resolve)((0, import_node_path24.dirname)(destination), target) !== (0, import_node_path24.resolve)(canonicalDirectory)) return false;
67984
- await (0, import_promises14.rm)(destination, { force: true });
68019
+ await (0, import_promises15.rm)(destination, { force: true });
67985
68020
  return true;
67986
68021
  }
67987
68022
  const marker = await readCompatibilityMarker(destination);
67988
68023
  if (!marker || !markerMatchesProjection(marker, projection)) return false;
67989
- await (0, import_promises14.rm)(destination, { recursive: true, force: true });
68024
+ await (0, import_promises15.rm)(destination, { recursive: true, force: true });
67990
68025
  return true;
67991
68026
  }
67992
68027
  async function readCompatibilityMarker(directory) {
67993
68028
  try {
67994
68029
  const value2 = JSON.parse(
67995
- await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, ".alan-compatibility.json"), "utf8")
68030
+ await (0, import_promises15.readFile)((0, import_node_path24.join)(directory, ".alan-compatibility.json"), "utf8")
67996
68031
  );
67997
68032
  if (value2.protocolVersion !== SKILLS_PROTOCOL_VERSION || typeof value2.skillId !== "string" || typeof value2.versionId !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value2.contentHash) || typeof value2.canonicalDirectory !== "string") {
67998
68033
  return null;
@@ -68012,7 +68047,7 @@ function markerFor(entry) {
68012
68047
  }
68013
68048
  async function readLegacyManifest(path2) {
68014
68049
  try {
68015
- const value2 = JSON.parse(await (0, import_promises14.readFile)(path2, "utf8"));
68050
+ const value2 = JSON.parse(await (0, import_promises15.readFile)(path2, "utf8"));
68016
68051
  if (!value2 || typeof value2 !== "object" || !("skills" in value2)) return null;
68017
68052
  const skillsValue = value2.skills;
68018
68053
  if (!skillsValue || typeof skillsValue !== "object" || Array.isArray(skillsValue)) return null;
@@ -68030,9 +68065,9 @@ async function readLegacyManifest(path2) {
68030
68065
  }
68031
68066
  async function legacyFileMatches(directory, expectedHash) {
68032
68067
  try {
68033
- const metadata = await (0, import_promises14.lstat)(directory);
68068
+ const metadata = await (0, import_promises15.lstat)(directory);
68034
68069
  if (!metadata.isDirectory() || metadata.isSymbolicLink()) return false;
68035
- const content = await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, "SKILL.md"));
68070
+ const content = await (0, import_promises15.readFile)((0, import_node_path24.join)(directory, "SKILL.md"));
68036
68071
  return (0, import_node_crypto14.createHash)("sha256").update(content).digest("hex").slice(0, 16) === expectedHash;
68037
68072
  } catch {
68038
68073
  return false;
@@ -68040,9 +68075,9 @@ async function legacyFileMatches(directory, expectedHash) {
68040
68075
  }
68041
68076
  async function removeExactLegacySkill(directory, expectedHash) {
68042
68077
  if (!await legacyFileMatches(directory, expectedHash)) return;
68043
- await (0, import_promises14.rm)((0, import_node_path24.join)(directory, "SKILL.md"), { force: true });
68044
- const remaining = await (0, import_promises14.readdir)(directory);
68045
- if (remaining.length === 0) await (0, import_promises14.rm)(directory, { recursive: true, force: true });
68078
+ await (0, import_promises15.rm)((0, import_node_path24.join)(directory, "SKILL.md"), { force: true });
68079
+ const remaining = await (0, import_promises15.readdir)(directory);
68080
+ if (remaining.length === 0) await (0, import_promises15.rm)(directory, { recursive: true, force: true });
68046
68081
  }
68047
68082
  function markerMatchesProjection(marker, projection) {
68048
68083
  return marker.skillId === projection.skillId && marker.versionId === projection.versionId && marker.contentHash === projection.contentHash;
@@ -68144,7 +68179,7 @@ function localTextMediaType(path2) {
68144
68179
  }
68145
68180
  async function pathExists2(path2) {
68146
68181
  try {
68147
- await (0, import_promises14.lstat)(path2);
68182
+ await (0, import_promises15.lstat)(path2);
68148
68183
  return true;
68149
68184
  } catch (error61) {
68150
68185
  if (isMissingPath2(error61)) return false;
@@ -68630,19 +68665,19 @@ ${input2.userRequest}
68630
68665
  }
68631
68666
 
68632
68667
  // src/workspace-run-lease.ts
68633
- var import_promises15 = require("fs/promises");
68668
+ var import_promises16 = require("fs/promises");
68634
68669
  var import_node_path25 = require("path");
68635
68670
  var WORKSPACE_LEASE_CHECK_INTERVAL_MS = 1e3;
68636
68671
  async function hasGitWorkspaceMarker(workspacePath) {
68637
68672
  let directory;
68638
68673
  try {
68639
- directory = await (0, import_promises15.realpath)((0, import_node_path25.resolve)(workspacePath));
68674
+ directory = await (0, import_promises16.realpath)((0, import_node_path25.resolve)(workspacePath));
68640
68675
  } catch {
68641
68676
  return true;
68642
68677
  }
68643
68678
  while (true) {
68644
68679
  try {
68645
- await (0, import_promises15.stat)((0, import_node_path25.join)(directory, ".git"));
68680
+ await (0, import_promises16.stat)((0, import_node_path25.join)(directory, ".git"));
68646
68681
  return true;
68647
68682
  } catch (error61) {
68648
68683
  const code = error61.code;
@@ -68654,8 +68689,8 @@ async function hasGitWorkspaceMarker(workspacePath) {
68654
68689
  }
68655
68690
  }
68656
68691
  async function filesystemIdentity(path2) {
68657
- const canonicalPath = await (0, import_promises15.realpath)(path2);
68658
- const metadata = await (0, import_promises15.stat)(canonicalPath);
68692
+ const canonicalPath = await (0, import_promises16.realpath)(path2);
68693
+ const metadata = await (0, import_promises16.stat)(canonicalPath);
68659
68694
  return `${canonicalPath}:${metadata.dev}:${metadata.ino}`;
68660
68695
  }
68661
68696
  function resolveGitPath(workspacePath, value2) {
@@ -68667,7 +68702,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
68667
68702
  const marker = (0, import_node_path25.join)(directory, ".git");
68668
68703
  let markerStats;
68669
68704
  try {
68670
- markerStats = await (0, import_promises15.stat)(marker);
68705
+ markerStats = await (0, import_promises16.stat)(marker);
68671
68706
  } catch (error61) {
68672
68707
  const code = error61.code;
68673
68708
  if (code !== "ENOENT" && code !== "ENOTDIR") return null;
@@ -68681,7 +68716,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
68681
68716
  }
68682
68717
  let pointer;
68683
68718
  try {
68684
- pointer = await (0, import_promises15.readFile)(marker, "utf8");
68719
+ pointer = await (0, import_promises16.readFile)(marker, "utf8");
68685
68720
  } catch {
68686
68721
  return null;
68687
68722
  }
@@ -68690,7 +68725,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
68690
68725
  const gitDirectory = resolveGitPath(directory, gitDirMatch[1].trim());
68691
68726
  let commonDirectory = gitDirectory;
68692
68727
  try {
68693
- const commonRaw = (await (0, import_promises15.readFile)((0, import_node_path25.join)(gitDirectory, "commondir"), "utf8")).trim();
68728
+ const commonRaw = (await (0, import_promises16.readFile)((0, import_node_path25.join)(gitDirectory, "commondir"), "utf8")).trim();
68694
68729
  if (commonRaw) commonDirectory = (0, import_node_path25.resolve)(gitDirectory, commonRaw);
68695
68730
  } catch (error61) {
68696
68731
  const code = error61.code;
@@ -68736,7 +68771,7 @@ var DEFAULT_PROBE = {
68736
68771
  snapshot: createWorkspaceRunLeaseSnapshotProbe(snapshotWorkspace),
68737
68772
  pathExists: async (workspacePath) => {
68738
68773
  try {
68739
- await (0, import_promises15.access)((0, import_node_path25.resolve)(workspacePath));
68774
+ await (0, import_promises16.access)((0, import_node_path25.resolve)(workspacePath));
68740
68775
  return true;
68741
68776
  } catch (error61) {
68742
68777
  return error61.code !== "ENOENT";
@@ -68745,7 +68780,7 @@ var DEFAULT_PROBE = {
68745
68780
  };
68746
68781
  async function snapshotWorkspace(workspacePath) {
68747
68782
  try {
68748
- const canonicalWorkspacePath = await (0, import_promises15.realpath)((0, import_node_path25.resolve)(workspacePath));
68783
+ const canonicalWorkspacePath = await (0, import_promises16.realpath)((0, import_node_path25.resolve)(workspacePath));
68749
68784
  const gitPaths = await resolveGitIdentityPaths(canonicalWorkspacePath);
68750
68785
  if (!gitPaths) return null;
68751
68786
  return {
@@ -75383,7 +75418,7 @@ async function setupWindowsRuntime(commandArgs) {
75383
75418
  throw new Error("Windows runtime setup completed without a local readiness endpoint");
75384
75419
  }
75385
75420
  const probe = () => probeLocalDaemon(localApiPort, localApiToken, Math.min(250, remainingMs()));
75386
- const poll = () => (0, import_promises16.setTimeout)(Math.min(100, remainingMs()), void 0, { signal: controller.signal });
75421
+ const poll = () => (0, import_promises17.setTimeout)(Math.min(100, remainingMs()), void 0, { signal: controller.signal });
75387
75422
  if (runtimeIdentityChanged) {
75388
75423
  while (true) {
75389
75424
  const status2 = await probe();
@@ -77344,7 +77379,7 @@ async function runSandbox(config4) {
77344
77379
  }
77345
77380
 
77346
77381
  // src/skills/skill-cli.ts
77347
- var import_promises17 = require("fs/promises");
77382
+ var import_promises18 = require("fs/promises");
77348
77383
  var import_node_os22 = require("os");
77349
77384
  var import_node_path40 = require("path");
77350
77385
  async function runSkillsCommand(args) {
@@ -77391,7 +77426,7 @@ async function defaultScanInput(homeDirectory2) {
77391
77426
  }
77392
77427
  async function readProtectedJson(path2) {
77393
77428
  const absolutePath = (0, import_node_path40.resolve)(path2);
77394
- const stat4 = await (0, import_promises17.lstat)(absolutePath);
77429
+ const stat4 = await (0, import_promises18.lstat)(absolutePath);
77395
77430
  if (!stat4.isFile()) throw new Error(`Skill input is not a regular file: ${absolutePath}`);
77396
77431
  if (process.platform !== "win32" && (stat4.mode & 63) !== 0) {
77397
77432
  throw new Error(`Skill input must not be accessible by group or other users: ${absolutePath}`);
@@ -77400,7 +77435,7 @@ async function readProtectedJson(path2) {
77400
77435
  throw new Error(`Skill input must be owned by the current user: ${absolutePath}`);
77401
77436
  }
77402
77437
  if (stat4.size > 2 * 1024 * 1024) throw new Error("Skill input exceeds 2 MiB");
77403
- return JSON.parse(await (0, import_promises17.readFile)(absolutePath, "utf8"));
77438
+ return JSON.parse(await (0, import_promises18.readFile)(absolutePath, "utf8"));
77404
77439
  }
77405
77440
  function option2(args, name) {
77406
77441
  const index = args.indexOf(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alan-ai-hq/agent-manager",
3
- "version": "0.1.126",
3
+ "version": "0.1.127",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "description": "Alan agent runtime — cloud sandbox and local daemon (alan-agent CLI)",