@alan-ai-hq/agent-manager-linux-x64 0.1.162 → 0.1.164

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 (3) hide show
  1. package/alan-agent.cjs +234 -257
  2. package/alan-holder.cjs +170 -174
  3. package/package.json +1 -1
package/alan-agent.cjs CHANGED
@@ -23748,7 +23748,7 @@ var init_chunk_YXWJW7I5 = __esm({
23748
23748
  }
23749
23749
  });
23750
23750
 
23751
- // ../agent-core/dist/chunk-6VWVDJ2A.js
23751
+ // ../agent-core/dist/chunk-KVTSAS2T.js
23752
23752
  function windowsEnvValue(env, name) {
23753
23753
  const wanted = name.toLowerCase();
23754
23754
  for (const [key, value2] of Object.entries(env).reverse()) {
@@ -24292,7 +24292,7 @@ function spawnInWindowsJob(plan2, options) {
24292
24292
  throw new CoreFault("internal", `No Windows command line was planned for ${plan2.file}`);
24293
24293
  }
24294
24294
  const file2 = helperFile(options.env);
24295
- const directory = (0, import_fs2.mkdtempSync)((0, import_path2.join)((0, import_os.tmpdir)(), `alan-job-${(0, import_crypto.randomUUID)()}-`));
24295
+ const directory = (0, import_fs3.mkdtempSync)((0, import_path2.join)((0, import_os.tmpdir)(), `alan-job-${(0, import_crypto.randomUUID)()}-`));
24296
24296
  const path4 = (0, import_path2.join)(directory, "started");
24297
24297
  const child = (0, import_child_process6.spawn)(file2, [String(process.pid)], {
24298
24298
  cwd: options.cwd,
@@ -24345,6 +24345,12 @@ async function waitForWindowsJob(child, command) {
24345
24345
  await (0, import_promises10.rm)(status.directory, { recursive: true, force: true });
24346
24346
  }
24347
24347
  }
24348
+ function preferForOomKill(pid) {
24349
+ try {
24350
+ (0, import_fs2.writeFileSync)(`/proc/${pid}/oom_score_adj`, String(CLI_OOM_SCORE_ADJ));
24351
+ } catch {
24352
+ }
24353
+ }
24348
24354
  function onCliSpawned(listener) {
24349
24355
  spawnListeners.add(listener);
24350
24356
  return {
@@ -24365,6 +24371,7 @@ function spawnCli(options) {
24365
24371
  shell: false,
24366
24372
  detached: true
24367
24373
  });
24374
+ if (platform3 === "linux" && child.pid !== void 0) preferForOomKill(child.pid);
24368
24375
  for (const listener of spawnListeners) listener(child);
24369
24376
  return child;
24370
24377
  }
@@ -24389,7 +24396,7 @@ function waitForSpawn(child, command) {
24389
24396
  }
24390
24397
  function inode(path4) {
24391
24398
  try {
24392
- return (0, import_fs3.statSync)(path4).ino;
24399
+ return (0, import_fs4.statSync)(path4).ino;
24393
24400
  } catch (error62) {
24394
24401
  if (errnoCode2(error62) !== "ENOENT") throw error62;
24395
24402
  return void 0;
@@ -24400,7 +24407,7 @@ async function removeDeadOwner(path4) {
24400
24407
  try {
24401
24408
  let owner;
24402
24409
  try {
24403
- owner = asRecord(JSON.parse((0, import_fs3.readFileSync)(path4, "utf8")));
24410
+ owner = asRecord(JSON.parse((0, import_fs4.readFileSync)(path4, "utf8")));
24404
24411
  } catch (error62) {
24405
24412
  if (!(error62 instanceof SyntaxError)) throw error62;
24406
24413
  }
@@ -24417,24 +24424,24 @@ async function removeDeadOwner(path4) {
24417
24424
  const actualStart = expectedStart ? await readProcessStartTime(pid) : void 0;
24418
24425
  dead ||= actualStart !== void 0 && actualStart !== expectedStart;
24419
24426
  }
24420
- if (dead && observed !== void 0 && inode(path4) === observed) (0, import_fs3.rmSync)(path4, { force: true });
24427
+ if (dead && observed !== void 0 && inode(path4) === observed) (0, import_fs4.rmSync)(path4, { force: true });
24421
24428
  } catch (error62) {
24422
24429
  if (errnoCode2(error62) !== "ENOENT") throw error62;
24423
24430
  }
24424
24431
  }
24425
24432
  async function withStartupLock(path4, clock, work, signal) {
24426
- (0, import_fs3.mkdirSync)((0, import_path3.dirname)(path4), { recursive: true, mode: 448 });
24433
+ (0, import_fs4.mkdirSync)((0, import_path3.dirname)(path4), { recursive: true, mode: 448 });
24427
24434
  const candidate = `${path4}.${(0, import_crypto2.randomUUID)()}`;
24428
24435
  const startedAt = await readProcessStartTime(process.pid);
24429
- (0, import_fs3.writeFileSync)(candidate, JSON.stringify({ pid: process.pid, startedAt }), { mode: 384 });
24430
- const owned = (0, import_fs3.statSync)(candidate).ino;
24436
+ (0, import_fs4.writeFileSync)(candidate, JSON.stringify({ pid: process.pid, startedAt }), { mode: 384 });
24437
+ const owned = (0, import_fs4.statSync)(candidate).ino;
24431
24438
  const deadline = clock.monotonic() + 12e4;
24432
24439
  let acquired = false;
24433
24440
  try {
24434
24441
  for (; ; ) {
24435
24442
  signal?.throwIfAborted();
24436
24443
  try {
24437
- (0, import_fs3.linkSync)(candidate, path4);
24444
+ (0, import_fs4.linkSync)(candidate, path4);
24438
24445
  acquired = true;
24439
24446
  break;
24440
24447
  } catch (error62) {
@@ -24447,13 +24454,13 @@ async function withStartupLock(path4, clock, work, signal) {
24447
24454
  }
24448
24455
  return await work();
24449
24456
  } finally {
24450
- if (acquired && inode(path4) === owned) (0, import_fs3.rmSync)(path4, { force: true });
24451
- (0, import_fs3.rmSync)(candidate, { force: true });
24457
+ if (acquired && inode(path4) === owned) (0, import_fs4.rmSync)(path4, { force: true });
24458
+ (0, import_fs4.rmSync)(candidate, { force: true });
24452
24459
  }
24453
24460
  }
24454
- var import_child_process, import_fs, import_path, import_child_process2, import_promises9, import_child_process3, import_child_process4, import_child_process5, import_child_process6, import_crypto, import_fs2, import_promises10, import_os, import_path2, import_crypto2, import_fs3, import_path3, SHIM_MAX_BYTES, CMD_MAX_COMMAND_LINE, MAX_COMMAND_LINE, DEFAULT_PATHEXT, LAUNCHABLE_EXTENSIONS, nodeWindowsFiles, NODE_SHIM_ENTRY, SCRIPT_EXTENSION, NATIVE_SHIM_LINES, NATIVE_SHIM_ENTRY, CMD_META, NEVER_STARTED, HIDDEN_FLAG_PROBE_VALUE, NEWLINE, CARRIAGE_RETURN, EMPTY, MAX_LINE_BYTES, LineSplitter, PS_LINE, POLL_MS, DEFAULT_GRACE_MS, DEFAULT_KILL_WAIT_MS, DEFAULT_TASKKILL_TIMEOUT_MS, statuses, START_TIMEOUT_MS, spawnListeners;
24455
- var init_chunk_6VWVDJ2A = __esm({
24456
- "../agent-core/dist/chunk-6VWVDJ2A.js"() {
24461
+ var import_child_process, import_fs, import_path, import_child_process2, import_promises9, import_child_process3, import_child_process4, import_child_process5, import_fs2, import_child_process6, import_crypto, import_fs3, import_promises10, import_os, import_path2, import_crypto2, import_fs4, import_path3, SHIM_MAX_BYTES, CMD_MAX_COMMAND_LINE, MAX_COMMAND_LINE, DEFAULT_PATHEXT, LAUNCHABLE_EXTENSIONS, nodeWindowsFiles, NODE_SHIM_ENTRY, SCRIPT_EXTENSION, NATIVE_SHIM_LINES, NATIVE_SHIM_ENTRY, CMD_META, NEVER_STARTED, HIDDEN_FLAG_PROBE_VALUE, NEWLINE, CARRIAGE_RETURN, EMPTY, MAX_LINE_BYTES, LineSplitter, PS_LINE, POLL_MS, DEFAULT_GRACE_MS, DEFAULT_KILL_WAIT_MS, DEFAULT_TASKKILL_TIMEOUT_MS, statuses, START_TIMEOUT_MS, CLI_OOM_SCORE_ADJ, spawnListeners;
24462
+ var init_chunk_KVTSAS2T = __esm({
24463
+ "../agent-core/dist/chunk-KVTSAS2T.js"() {
24457
24464
  "use strict";
24458
24465
  init_chunk_YXWJW7I5();
24459
24466
  import_child_process = require("child_process");
@@ -24464,14 +24471,15 @@ var init_chunk_6VWVDJ2A = __esm({
24464
24471
  import_child_process3 = require("child_process");
24465
24472
  import_child_process4 = require("child_process");
24466
24473
  import_child_process5 = require("child_process");
24474
+ import_fs2 = require("fs");
24467
24475
  import_child_process6 = require("child_process");
24468
24476
  import_crypto = require("crypto");
24469
- import_fs2 = require("fs");
24477
+ import_fs3 = require("fs");
24470
24478
  import_promises10 = require("fs/promises");
24471
24479
  import_os = require("os");
24472
24480
  import_path2 = require("path");
24473
24481
  import_crypto2 = require("crypto");
24474
- import_fs3 = require("fs");
24482
+ import_fs4 = require("fs");
24475
24483
  import_path3 = require("path");
24476
24484
  SHIM_MAX_BYTES = 64 * 1024;
24477
24485
  CMD_MAX_COMMAND_LINE = 8191;
@@ -24558,6 +24566,7 @@ var init_chunk_6VWVDJ2A = __esm({
24558
24566
  DEFAULT_TASKKILL_TIMEOUT_MS = 5e3;
24559
24567
  statuses = /* @__PURE__ */ new WeakMap();
24560
24568
  START_TIMEOUT_MS = 1e4;
24569
+ CLI_OOM_SCORE_ADJ = 500;
24561
24570
  spawnListeners = /* @__PURE__ */ new Set();
24562
24571
  }
24563
24572
  });
@@ -26791,7 +26800,9 @@ var init_conversation_messages = __esm({
26791
26800
  "pattern",
26792
26801
  "search_query",
26793
26802
  "subagent_type",
26794
- "run_in_background"
26803
+ "run_in_background",
26804
+ "skill",
26805
+ "skill_name"
26795
26806
  ]);
26796
26807
  COMMAND_INPUT_FIELDS = /* @__PURE__ */ new Set(["command", "cmd", "code"]);
26797
26808
  STEP_INPUT_TEXT_LIMIT = 1024;
@@ -27545,13 +27556,13 @@ function readTranscriptTurns(transcript, chunk, baseOffset, skipped = []) {
27545
27556
  });
27546
27557
  return { turns, consumedBytes: consumedEnd - baseOffset };
27547
27558
  }
27548
- var import_fs4, NEWLINE2, TranscriptCursor, TranscriptLineLookup, CONTENT_UPDATES;
27559
+ var import_fs5, NEWLINE2, TranscriptCursor, TranscriptLineLookup, CONTENT_UPDATES;
27549
27560
  var init_chunk_TFIO37PI = __esm({
27550
27561
  "../agent-core/dist/chunk-TFIO37PI.js"() {
27551
27562
  "use strict";
27552
27563
  init_chunk_RBQC7XZH();
27553
27564
  init_chunk_YXWJW7I5();
27554
- import_fs4 = require("fs");
27565
+ import_fs5 = require("fs");
27555
27566
  NEWLINE2 = 10;
27556
27567
  TranscriptCursor = class {
27557
27568
  #path;
@@ -27569,7 +27580,7 @@ var init_chunk_TFIO37PI = __esm({
27569
27580
  try {
27570
27581
  this.#offset = Math.max(
27571
27582
  this.#offset,
27572
- (0, import_fs4.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0
27583
+ (0, import_fs5.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0
27573
27584
  );
27574
27585
  } catch {
27575
27586
  }
@@ -27591,15 +27602,15 @@ var init_chunk_TFIO37PI = __esm({
27591
27602
  /** Runs on the CLI's stdout path, so an unreadable file reads as no new lines. */
27592
27603
  #unread() {
27593
27604
  try {
27594
- const size = (0, import_fs4.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0;
27605
+ const size = (0, import_fs5.statSync)(this.#path, { throwIfNoEntry: false })?.size ?? 0;
27595
27606
  if (size <= this.#offset) return void 0;
27596
27607
  const buffer = Buffer.alloc(size - this.#offset);
27597
- const fd = (0, import_fs4.openSync)(this.#path, "r");
27608
+ const fd = (0, import_fs5.openSync)(this.#path, "r");
27598
27609
  try {
27599
- const read = (0, import_fs4.readSync)(fd, buffer, 0, buffer.length, this.#offset);
27610
+ const read = (0, import_fs5.readSync)(fd, buffer, 0, buffer.length, this.#offset);
27600
27611
  return buffer.subarray(0, read);
27601
27612
  } finally {
27602
- (0, import_fs4.closeSync)(fd);
27613
+ (0, import_fs5.closeSync)(fd);
27603
27614
  }
27604
27615
  } catch {
27605
27616
  return void 0;
@@ -28106,7 +28117,7 @@ var init_chunk_ZCTKXKYY = __esm({
28106
28117
  }
28107
28118
  });
28108
28119
 
28109
- // ../agent-core/dist/chunk-N2M5D7RS.js
28120
+ // ../agent-core/dist/chunk-LDVOKUAU.js
28110
28121
  function detectImageMimeType(buffer) {
28111
28122
  if (buffer.length >= 8 && buffer.subarray(0, 8).equals(PNG_SIGNATURE)) return "image/png";
28112
28123
  if (buffer.length >= 3 && buffer[0] === 255 && buffer[1] === 216 && buffer[2] === 255) {
@@ -28208,14 +28219,14 @@ function readMediaFiles(query) {
28208
28219
  const files = [];
28209
28220
  for (const candidate of query.candidates) {
28210
28221
  const path4 = normalizePath(candidate, query.cwd);
28211
- if (!path4 || seen.has(path4) || !(0, import_fs5.existsSync)(path4)) continue;
28222
+ if (!path4 || seen.has(path4) || !(0, import_fs6.existsSync)(path4)) continue;
28212
28223
  seen.add(path4);
28213
28224
  const mimeType = query.mimeByExt[(0, import_path4.extname)(path4).toLowerCase()];
28214
28225
  if (!mimeType) continue;
28215
- const stat22 = (0, import_fs5.statSync)(path4);
28226
+ const stat22 = (0, import_fs6.statSync)(path4);
28216
28227
  if (!stat22.isFile() || stat22.size <= 0 || stat22.size > query.maxBytes) continue;
28217
28228
  if (stat22.mtimeMs < query.writtenSince && !query.named.has(path4)) continue;
28218
- files.push({ path: path4, mimeType, buffer: (0, import_fs5.readFileSync)(path4) });
28229
+ files.push({ path: path4, mimeType, buffer: (0, import_fs6.readFileSync)(path4) });
28219
28230
  }
28220
28231
  return files;
28221
28232
  }
@@ -28546,16 +28557,16 @@ function silentStartError(name, timeoutMs) {
28546
28557
  message: `${name} printed nothing for ${seconds}s after it started and was stopped. Send your message again.`
28547
28558
  };
28548
28559
  }
28549
- var import_crypto4, import_fs5, import_path4, PNG_SIGNATURE, IMAGE_MIME_BY_EXT, VIDEO_MIME_BY_EXT, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, MAX_IMAGE_BYTES, MAX_VIDEO_BYTES, MAX_TURN_MEDIA_DATA_CHARS, MTIME_SLACK_MS, AGENT_BROWSER_MENTION, AGENT_BROWSER_CAPTURE_COMMAND, LocalMediaReader, SessionOpenRefusal, JsonRpcError, ACP_PROTOCOL_VERSION, ACP_ERROR, STDERR_TAIL_LINES, RESULT_EXIT_GRACE_MS, PerTurnSession;
28550
- var init_chunk_N2M5D7RS = __esm({
28551
- "../agent-core/dist/chunk-N2M5D7RS.js"() {
28560
+ var import_crypto4, import_fs6, import_path4, PNG_SIGNATURE, IMAGE_MIME_BY_EXT, VIDEO_MIME_BY_EXT, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, MAX_IMAGE_BYTES, MAX_VIDEO_BYTES, MAX_TURN_MEDIA_DATA_CHARS, MTIME_SLACK_MS, AGENT_BROWSER_MENTION, AGENT_BROWSER_CAPTURE_COMMAND, LocalMediaReader, SessionOpenRefusal, JsonRpcError, ACP_PROTOCOL_VERSION, ACP_ERROR, STDERR_TAIL_LINES, RESULT_EXIT_GRACE_MS, PerTurnSession;
28561
+ var init_chunk_LDVOKUAU = __esm({
28562
+ "../agent-core/dist/chunk-LDVOKUAU.js"() {
28552
28563
  "use strict";
28553
28564
  init_chunk_RBQC7XZH();
28554
28565
  init_chunk_ZCTKXKYY();
28555
- init_chunk_6VWVDJ2A();
28566
+ init_chunk_KVTSAS2T();
28556
28567
  init_chunk_YXWJW7I5();
28557
28568
  import_crypto4 = require("crypto");
28558
- import_fs5 = require("fs");
28569
+ import_fs6 = require("fs");
28559
28570
  import_path4 = require("path");
28560
28571
  init_agent2();
28561
28572
  init_acp();
@@ -30852,14 +30863,14 @@ function encodeProjectDir(cwd) {
30852
30863
  }
30853
30864
  function realCwd(cwd) {
30854
30865
  try {
30855
- return (0, import_fs6.realpathSync)(cwd);
30866
+ return (0, import_fs7.realpathSync)(cwd);
30856
30867
  } catch {
30857
30868
  return cwd;
30858
30869
  }
30859
30870
  }
30860
30871
  function projectDirs(projectsRoot) {
30861
30872
  try {
30862
- return (0, import_fs6.readdirSync)(projectsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
30873
+ return (0, import_fs7.readdirSync)(projectsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
30863
30874
  } catch {
30864
30875
  return [];
30865
30876
  }
@@ -30870,10 +30881,10 @@ function claudeSessionLogExists(query) {
30870
30881
  const fileName = `${query.sessionId}.jsonl`;
30871
30882
  const here = new Set([query.cwd, realCwd(query.cwd)].map(encodeProjectDir));
30872
30883
  for (const dir of here) {
30873
- if ((0, import_fs6.existsSync)((0, import_path6.join)(projectsRoot, dir, fileName))) return true;
30884
+ if ((0, import_fs7.existsSync)((0, import_path6.join)(projectsRoot, dir, fileName))) return true;
30874
30885
  }
30875
30886
  return projectDirs(projectsRoot).some(
30876
- (dir) => !here.has(dir) && (0, import_fs6.existsSync)((0, import_path6.join)(projectsRoot, dir, fileName))
30887
+ (dir) => !here.has(dir) && (0, import_fs7.existsSync)((0, import_path6.join)(projectsRoot, dir, fileName))
30877
30888
  );
30878
30889
  }
30879
30890
  function envDigest(env) {
@@ -31144,15 +31155,15 @@ function claudeTurnClosingUpdates(records, state) {
31144
31155
  function readClaudeTranscriptTurns(chunk, baseOffset, skipped) {
31145
31156
  return readTranscriptTurns(claudeTranscriptFile, chunk, baseOffset, skipped);
31146
31157
  }
31147
- var import_crypto7, import_fs6, import_path6, import_crypto8, import_promises31, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, CLAUDE_MCP_STATUS, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES2, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS, SYNTHETIC_MODEL, INTERRUPT_MARKER, NON_PROMPT_PREFIXES, PRELUDE_TYPES, claudeTranscriptFile;
31158
+ var import_crypto7, import_fs7, import_path6, import_crypto8, import_promises31, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, CLAUDE_MCP_STATUS, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES2, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS, SYNTHETIC_MODEL, INTERRUPT_MARKER, NON_PROMPT_PREFIXES, PRELUDE_TYPES, claudeTranscriptFile;
31148
31159
  var init_claude = __esm({
31149
31160
  "../agent-core/dist/providers/claude.js"() {
31150
31161
  "use strict";
31151
31162
  init_chunk_TFIO37PI();
31152
- init_chunk_N2M5D7RS();
31163
+ init_chunk_LDVOKUAU();
31153
31164
  init_chunk_RBQC7XZH();
31154
31165
  init_chunk_ZCTKXKYY();
31155
- init_chunk_6VWVDJ2A();
31166
+ init_chunk_KVTSAS2T();
31156
31167
  init_chunk_DLVRNIY5();
31157
31168
  init_chunk_OSECDZA5();
31158
31169
  init_chunk_YXWJW7I5();
@@ -31164,7 +31175,7 @@ var init_claude = __esm({
31164
31175
  init_acp();
31165
31176
  init_constants();
31166
31177
  init_agent2();
31167
- import_fs6 = require("fs");
31178
+ import_fs7 = require("fs");
31168
31179
  import_path6 = require("path");
31169
31180
  import_crypto8 = require("crypto");
31170
31181
  import_promises31 = require("fs/promises");
@@ -32257,7 +32268,7 @@ function codexHomeOf(env) {
32257
32268
  }
32258
32269
  function namesNewestFirst(dir, isDir) {
32259
32270
  try {
32260
- return (0, import_fs7.readdirSync)(dir, { withFileTypes: true }).filter((entry) => isDir ? entry.isDirectory() : entry.isFile()).map((entry) => entry.name).sort().reverse();
32271
+ return (0, import_fs8.readdirSync)(dir, { withFileTypes: true }).filter((entry) => isDir ? entry.isDirectory() : entry.isFile()).map((entry) => entry.name).sort().reverse();
32261
32272
  } catch {
32262
32273
  return [];
32263
32274
  }
@@ -34074,19 +34085,19 @@ function codexTurnInput(run2, context) {
34074
34085
  ...images.length ? { imagePaths: images.map((image) => image.path) } : {}
34075
34086
  };
34076
34087
  }
34077
- var import_fs7, import_path7, import_crypto9, import_crypto10, import_crypto11, import_crypto12, TokenRefresher, MCP_STARTUP_TIMEOUT_SEC, FIELD_TYPES, YES_NO, ACCEPT_DECLINE, MAX_INLINE_GENERATED_IMAGE_BYTES, PNG_SIGNATURE2, JPEG_NON_FRAME_MARKERS, IMAGE_GEN_CALL, PROMPT_LITERAL, RELOCATE_EVERY_MS, CodexImageGenerationFold, CodexRolloutImages, CodexRateLimits, USER_INPUT_METHOD, PERMISSIONS_METHOD, ELICITATION_METHOD, COMMAND_OR_FILE, LEGACY, DECISIONS, COORDINATION_TOOLS, SETTLED_AGENT, STATUS, CHANGE_OPERATIONS, SILENT_ON_START, IGNORED_ITEMS, PLAN_STATUS, CodexTurnTokens, CODEX_MCP_STATUS, WORKER_LIFECYCLE, INFO_KINDS, SILENT, CodexTurn, STDERR_TAIL_LINES3, MAX_BETWEEN_UPDATES, UNSUPPORTED_REQUEST, DECLINED_ELICITATION, IMAGE_CATCH_UP_MS, IMAGE_POLL_MS, CodexSession, CODEX_MIN_VERSION, CODEX_REQUIREMENT, CODEX_TESTED_LINE, DEFAULTS2, CLIENT_INFO, STATUS2, EXITED_WITHOUT_RESPONSE, CodexExecTurn, DEFAULTS22, CodexExecSession, INJECTED_USER_PREFIXES, SHELL_TOOL_NAMES, ANNOUNCING_ITEM_TYPES, OUTPUT_MARKER, OPEN_PAGE_ACTIONS, FIND_IN_PAGE_ACTIONS, FILE_OPERATIONS, UNDERSTOOD_ITEM_TYPES, PRELUDE_TYPES2, PRELUDE_EVENTS, codexRolloutFile;
34088
+ var import_fs8, import_path7, import_crypto9, import_crypto10, import_crypto11, import_crypto12, TokenRefresher, MCP_STARTUP_TIMEOUT_SEC, FIELD_TYPES, YES_NO, ACCEPT_DECLINE, MAX_INLINE_GENERATED_IMAGE_BYTES, PNG_SIGNATURE2, JPEG_NON_FRAME_MARKERS, IMAGE_GEN_CALL, PROMPT_LITERAL, RELOCATE_EVERY_MS, CodexImageGenerationFold, CodexRolloutImages, CodexRateLimits, USER_INPUT_METHOD, PERMISSIONS_METHOD, ELICITATION_METHOD, COMMAND_OR_FILE, LEGACY, DECISIONS, COORDINATION_TOOLS, SETTLED_AGENT, STATUS, CHANGE_OPERATIONS, SILENT_ON_START, IGNORED_ITEMS, PLAN_STATUS, CodexTurnTokens, CODEX_MCP_STATUS, WORKER_LIFECYCLE, INFO_KINDS, SILENT, CodexTurn, STDERR_TAIL_LINES3, MAX_BETWEEN_UPDATES, UNSUPPORTED_REQUEST, DECLINED_ELICITATION, IMAGE_CATCH_UP_MS, IMAGE_POLL_MS, CodexSession, CODEX_MIN_VERSION, CODEX_REQUIREMENT, CODEX_TESTED_LINE, DEFAULTS2, CLIENT_INFO, STATUS2, EXITED_WITHOUT_RESPONSE, CodexExecTurn, DEFAULTS22, CodexExecSession, INJECTED_USER_PREFIXES, SHELL_TOOL_NAMES, ANNOUNCING_ITEM_TYPES, OUTPUT_MARKER, OPEN_PAGE_ACTIONS, FIND_IN_PAGE_ACTIONS, FILE_OPERATIONS, UNDERSTOOD_ITEM_TYPES, PRELUDE_TYPES2, PRELUDE_EVENTS, codexRolloutFile;
34078
34089
  var init_codex = __esm({
34079
34090
  "../agent-core/dist/providers/codex.js"() {
34080
34091
  "use strict";
34081
34092
  init_chunk_TFIO37PI();
34082
- init_chunk_N2M5D7RS();
34093
+ init_chunk_LDVOKUAU();
34083
34094
  init_chunk_RBQC7XZH();
34084
34095
  init_chunk_ZCTKXKYY();
34085
- init_chunk_6VWVDJ2A();
34096
+ init_chunk_KVTSAS2T();
34086
34097
  init_chunk_DLVRNIY5();
34087
34098
  init_chunk_OSECDZA5();
34088
34099
  init_chunk_YXWJW7I5();
34089
- import_fs7 = require("fs");
34100
+ import_fs8 = require("fs");
34090
34101
  import_path7 = require("path");
34091
34102
  init_effort();
34092
34103
  import_crypto9 = require("crypto");
@@ -35478,9 +35489,9 @@ function packagedAlanCodeEnginePath(bundle, platform3) {
35478
35489
  }
35479
35490
  function isRunnableFile(path4, platform3) {
35480
35491
  try {
35481
- if (!(0, import_fs8.statSync)(path4).isFile()) return false;
35492
+ if (!(0, import_fs9.statSync)(path4).isFile()) return false;
35482
35493
  if (platform3 === "win32") return WINDOWS_RUNNABLE_EXTENSION.test(path4);
35483
- (0, import_fs8.accessSync)(path4, import_fs8.constants.X_OK);
35494
+ (0, import_fs9.accessSync)(path4, import_fs9.constants.X_OK);
35484
35495
  return true;
35485
35496
  } catch {
35486
35497
  return false;
@@ -35805,7 +35816,7 @@ function alanCodeSystemPrompt(alanSystemPrompt) {
35805
35816
 
35806
35817
  ${instructions}` : ALAN_CODE_TOOL_NAMING_PROMPT;
35807
35818
  }
35808
- var import_http9, import_https, import_fs8, import_path8, import_crypto13, import_promises34, import_path9, import_url, ALAN_CODE_BASELINE_PROMPT, ALAN_CODE_ENGINE_PROVIDER_ID, DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT_TOKENS, ALAN_CODE_API_KEY_ENV, ALAN_CODE_CONVERSATION_ID_ENV, ALAN_CODE_PROXY_PATH, ALAN_CODE_WEBSEARCH_PATH, ALAN_CODE_CATALOG_PATH, ALAN_CODE_CHUNK_TIMEOUT_MS, CATALOG_TIMEOUT_MS, MAX_CATALOG_BYTES, ACTIVATION_WAIT_MS, ACTIVATION_POLL_MS, CatalogResponseError, ALAN_CODE_ENGINE_PATH_ENV, ALAN_CODE_ENGINE_COMMAND, ALAN_CODE_ENGINE_NAME, WINDOWS_RUNNABLE_EXTENSION, ALAN_CODE_ENGINE_PLUGIN_VERSION, ALAN_CODE_TOOL_NAMING_PROMPT;
35819
+ var import_http9, import_https, import_fs9, import_path8, import_crypto13, import_promises34, import_path9, import_url, ALAN_CODE_BASELINE_PROMPT, ALAN_CODE_ENGINE_PROVIDER_ID, DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT_TOKENS, ALAN_CODE_API_KEY_ENV, ALAN_CODE_CONVERSATION_ID_ENV, ALAN_CODE_PROXY_PATH, ALAN_CODE_WEBSEARCH_PATH, ALAN_CODE_CATALOG_PATH, ALAN_CODE_CHUNK_TIMEOUT_MS, CATALOG_TIMEOUT_MS, MAX_CATALOG_BYTES, ACTIVATION_WAIT_MS, ACTIVATION_POLL_MS, CatalogResponseError, ALAN_CODE_ENGINE_PATH_ENV, ALAN_CODE_ENGINE_COMMAND, ALAN_CODE_ENGINE_NAME, WINDOWS_RUNNABLE_EXTENSION, ALAN_CODE_ENGINE_PLUGIN_VERSION, ALAN_CODE_TOOL_NAMING_PROMPT;
35809
35820
  var init_alan_code = __esm({
35810
35821
  "../agent-core/dist/providers/alan-code.js"() {
35811
35822
  "use strict";
@@ -35816,7 +35827,7 @@ var init_alan_code = __esm({
35816
35827
  init_runtime_v2();
35817
35828
  init_runtime_v2();
35818
35829
  init_models();
35819
- import_fs8 = require("fs");
35830
+ import_fs9 = require("fs");
35820
35831
  import_path8 = require("path");
35821
35832
  init_runtime_v2();
35822
35833
  import_crypto13 = require("crypto");
@@ -45631,10 +45642,10 @@ var require_tar_stream = __commonJS({
45631
45642
  var init_dist = __esm({
45632
45643
  "../agent-core/dist/index.js"() {
45633
45644
  "use strict";
45634
- init_chunk_N2M5D7RS();
45645
+ init_chunk_LDVOKUAU();
45635
45646
  init_chunk_RBQC7XZH();
45636
45647
  init_chunk_ZCTKXKYY();
45637
- init_chunk_6VWVDJ2A();
45648
+ init_chunk_KVTSAS2T();
45638
45649
  init_chunk_YXWJW7I5();
45639
45650
  }
45640
45651
  });
@@ -46384,10 +46395,10 @@ var import_promises50, import_path10, import_crypto14, import_promises51, CURSOR
46384
46395
  var init_acp3 = __esm({
46385
46396
  "../agent-core/dist/providers/acp.js"() {
46386
46397
  "use strict";
46387
- init_chunk_N2M5D7RS();
46398
+ init_chunk_LDVOKUAU();
46388
46399
  init_chunk_RBQC7XZH();
46389
46400
  init_chunk_ZCTKXKYY();
46390
- init_chunk_6VWVDJ2A();
46401
+ init_chunk_KVTSAS2T();
46391
46402
  init_chunk_DLVRNIY5();
46392
46403
  init_chunk_OSECDZA5();
46393
46404
  init_chunk_YXWJW7I5();
@@ -48427,17 +48438,18 @@ function openCodeTurnInput(run2, context) {
48427
48438
  return {
48428
48439
  turnId: run2.runId,
48429
48440
  text: text3,
48430
- ...images.length ? { imagePaths: images.map((image) => image.path) } : {}
48441
+ ...images.length ? { imagePaths: images.map((image) => image.path) } : {},
48442
+ ...context.attachments.length ? { readableFiles: context.attachments.map((attachment) => attachment.path) } : {}
48431
48443
  };
48432
48444
  }
48433
- var import_crypto15, import_http10, import_crypto16, import_promises52, import_path11, import_path12, import_url2, import_crypto17, IDLE_SOCKET_MS3, OpenCodeHttpError, BASE62, messageIdClock, OpenCodeClient, OPENCODE_CONFIG_ENV, OPENCODE_ENGINE, TEXT_PARTS, STEP_PARTS, STOPPED_BY_USER, OpenCodeSubagents, NAMED_KINDS, OPENCODE_ABORTED_ERROR, PROVIDER_EVENT_META, TASK_TOOL_NAME, TASK_RESULT_TAG, TASK_ERROR_TAG, PERMISSION_DENIED, FILE_OPERATIONS2, NO_USAGE, PartReader, NOTHING, NON_INTERACTIVE_PERMISSIONS, CONTENT_FILTER_FINISHES, TRUNCATED_FINISHES, OUTPUT_PARTS, OpenCodeTurn, LISTENING, OUTPUT_TAIL_LINES, IMAGE_TYPES, OpenCodeSession, OPENCODE_MIN_VERSION, OPENCODE_REQUIREMENT, OPENCODE_TESTED_LINE, OPENCODE_SUPPORTED_MAJOR, DEFAULTS4, STORE_LOCKED, NON_INTERACTIVE_RULES, TITLE_LENGTH, MAX_VARIANT_LENGTH;
48445
+ var import_crypto15, import_http10, import_crypto16, import_promises52, import_path11, import_path12, import_url2, import_path13, import_crypto17, IDLE_SOCKET_MS3, OpenCodeHttpError, BASE62, messageIdClock, OpenCodeClient, OPENCODE_CONFIG_ENV, OPENCODE_ENGINE, TEXT_PARTS, STEP_PARTS, STOPPED_BY_USER, OpenCodeSubagents, NAMED_KINDS, OPENCODE_ABORTED_ERROR, PROVIDER_EVENT_META, TASK_TOOL_NAME, TASK_RESULT_TAG, TASK_ERROR_TAG, PERMISSION_DENIED, FILE_OPERATIONS2, NO_USAGE, PartReader, NOTHING, NON_INTERACTIVE_PERMISSIONS, CONTENT_FILTER_FINISHES, TRUNCATED_FINISHES, OUTPUT_PARTS, OpenCodeTurn, LISTENING, OUTPUT_TAIL_LINES, IMAGE_TYPES, OpenCodeSession, OPENCODE_MIN_VERSION, OPENCODE_REQUIREMENT, OPENCODE_TESTED_LINE, OPENCODE_SUPPORTED_MAJOR, DEFAULTS4, STORE_LOCKED, NON_INTERACTIVE_RULES, TITLE_LENGTH, MAX_VARIANT_LENGTH;
48434
48446
  var init_opencode = __esm({
48435
48447
  "../agent-core/dist/providers/opencode.js"() {
48436
48448
  "use strict";
48437
- init_chunk_N2M5D7RS();
48449
+ init_chunk_LDVOKUAU();
48438
48450
  init_chunk_RBQC7XZH();
48439
48451
  init_chunk_ZCTKXKYY();
48440
- init_chunk_6VWVDJ2A();
48452
+ init_chunk_KVTSAS2T();
48441
48453
  init_chunk_DLVRNIY5();
48442
48454
  init_chunk_OSECDZA5();
48443
48455
  init_chunk_YXWJW7I5();
@@ -48451,6 +48463,7 @@ var init_opencode = __esm({
48451
48463
  import_path12 = require("path");
48452
48464
  import_url2 = require("url");
48453
48465
  init_acp();
48466
+ import_path13 = require("path");
48454
48467
  init_acp();
48455
48468
  init_constants();
48456
48469
  import_crypto17 = require("crypto");
@@ -49062,6 +49075,8 @@ var init_opencode = __esm({
49062
49075
  #readOnly;
49063
49076
  #memory;
49064
49077
  #engine;
49078
+ /** The turn's attachments: downloaded outside the workspace, still readable when read-only. */
49079
+ #readableFiles;
49065
49080
  #parts = new PartReader();
49066
49081
  /** Child session id \u2192 the `task` call that launched it; `undefined` when unlinked. */
49067
49082
  #children = /* @__PURE__ */ new Map();
@@ -49077,11 +49092,12 @@ var init_opencode = __esm({
49077
49092
  #finish;
49078
49093
  #error;
49079
49094
  #end;
49080
- constructor(rootSessionId, readOnly, memory, engine = OPENCODE_ENGINE) {
49095
+ constructor(rootSessionId, readOnly, memory, engine = OPENCODE_ENGINE, readableFiles = []) {
49081
49096
  this.#root = rootSessionId;
49082
49097
  this.#readOnly = readOnly;
49083
49098
  this.#memory = memory;
49084
49099
  this.#engine = engine;
49100
+ this.#readableFiles = new Set(readableFiles.map((path4) => (0, import_path13.normalize)(path4)));
49085
49101
  }
49086
49102
  get childSessionIds() {
49087
49103
  return [...this.#children.keys()];
@@ -49309,13 +49325,20 @@ var init_opencode = __esm({
49309
49325
  if (!requestId) return NOTHING;
49310
49326
  const kind = asString(properties.permission).trim() || "an action";
49311
49327
  const nonInteractive = NON_INTERACTIVE_PERMISSIONS.has(kind);
49312
- const reply2 = nonInteractive || this.#readOnly ? "reject" : "once";
49313
- const message2 = nonInteractive ? `${subject} tried to ${kind.replace(/_/g, " ")} \u2014 denied (Alan does not yet support interactive requests for ${this.#engine.label}).` : this.#readOnly ? `${subject} requested permission to ${kind} \u2014 automatically denied (read-only session).` : `${subject} requested permission to ${kind} \u2014 automatically approved (autonomous mode).`;
49328
+ const attachment = this.#readOnly && this.#opensAttachment(kind, properties);
49329
+ const reply2 = nonInteractive || this.#readOnly && !attachment ? "reject" : "once";
49330
+ const message2 = nonInteractive ? `${subject} tried to ${kind.replace(/_/g, " ")} \u2014 denied (Alan does not yet support interactive requests for ${this.#engine.label}).` : attachment ? `${subject} opened an attached file outside the workspace \u2014 approved (read-only session).` : this.#readOnly ? `${subject} requested permission to ${kind} \u2014 automatically denied (read-only session).` : `${subject} requested permission to ${kind} \u2014 automatically approved (autonomous mode).`;
49314
49331
  return {
49315
49332
  updates: [notice("permission_decision", message2)],
49316
49333
  actions: [{ kind: "permission", requestId, reply: reply2 }]
49317
49334
  };
49318
49335
  }
49336
+ /** OpenCode asks `external_directory` with the exact target path in `metadata.filepath`. */
49337
+ #opensAttachment(kind, properties) {
49338
+ if (kind !== "external_directory") return false;
49339
+ const filepath = asString(asRecord(properties.metadata)?.filepath);
49340
+ return (0, import_path13.isAbsolute)(filepath) && this.#readableFiles.has((0, import_path13.normalize)(filepath));
49341
+ }
49319
49342
  #question(properties) {
49320
49343
  const requestId = asString(properties.id).trim();
49321
49344
  if (!requestId) return NOTHING;
@@ -49474,7 +49497,7 @@ var init_opencode = __esm({
49474
49497
  const client = this.#client;
49475
49498
  const sessionId = this.#sessionId;
49476
49499
  if (!client || !sessionId) throw new CoreFault("internal", `The ${engine} session is not open`);
49477
- const active = this.#startTurn(input2.turnId, sessionId);
49500
+ const active = this.#startTurn(input2.turnId, sessionId, input2.readableFiles);
49478
49501
  void this.#send(active, client, sessionId, {
49479
49502
  ...this.#promptBody(input2),
49480
49503
  messageID: active.initialMessageId
@@ -49596,14 +49619,15 @@ var init_opencode = __esm({
49596
49619
  #emit(event) {
49597
49620
  this.#listeners.emit(event);
49598
49621
  }
49599
- #startTurn(id, sessionId) {
49622
+ #startTurn(id, sessionId, readableFiles) {
49600
49623
  this.#turnCount += 1;
49601
49624
  this.#subagents.prune();
49602
49625
  const turn = new OpenCodeTurn(
49603
49626
  sessionId,
49604
49627
  this.#prompt.readOnly,
49605
49628
  this.#memory,
49606
- this.#options.engine
49629
+ this.#options.engine,
49630
+ readableFiles
49607
49631
  );
49608
49632
  let finish = () => {
49609
49633
  };
@@ -50530,10 +50554,10 @@ var import_crypto18, import_promises53, FACTORY_API_VERSION, FACTORY_PROTOCOL_VE
50530
50554
  var init_droid = __esm({
50531
50555
  "../agent-core/dist/providers/droid.js"() {
50532
50556
  "use strict";
50533
- init_chunk_N2M5D7RS();
50557
+ init_chunk_LDVOKUAU();
50534
50558
  init_chunk_RBQC7XZH();
50535
50559
  init_chunk_ZCTKXKYY();
50536
- init_chunk_6VWVDJ2A();
50560
+ init_chunk_KVTSAS2T();
50537
50561
  init_chunk_DLVRNIY5();
50538
50562
  init_chunk_OSECDZA5();
50539
50563
  init_chunk_YXWJW7I5();
@@ -51024,7 +51048,7 @@ var init_opencode2 = __esm({
51024
51048
  // ../agent-core/dist/providers/antigravity.js
51025
51049
  function settingsPath(env) {
51026
51050
  const home = env.HOME?.trim() || env.USERPROFILE?.trim();
51027
- return home ? (0, import_path13.resolve)(home, ".gemini", "antigravity-cli", "settings.json") : void 0;
51051
+ return home ? (0, import_path14.resolve)(home, ".gemini", "antigravity-cli", "settings.json") : void 0;
51028
51052
  }
51029
51053
  async function readSettings2(path4) {
51030
51054
  let raw;
@@ -51047,7 +51071,7 @@ async function selectAntigravityApiKeyMode(env) {
51047
51071
  const settings2 = await readSettings2(path4);
51048
51072
  if (settings2 === "malformed") return "malformed";
51049
51073
  if (settings2.modelProvider === "gemini") return "already_selected";
51050
- await (0, import_promises54.mkdir)((0, import_path13.dirname)(path4), { recursive: true });
51074
+ await (0, import_promises54.mkdir)((0, import_path14.dirname)(path4), { recursive: true });
51051
51075
  await (0, import_promises54.writeFile)(path4, JSON.stringify({ ...settings2, modelProvider: "gemini" }), { mode: 384 });
51052
51076
  return "selected";
51053
51077
  }
@@ -51091,21 +51115,21 @@ function antigravityArgs(input2, capabilities, prompt) {
51091
51115
  ];
51092
51116
  }
51093
51117
  function workspaceRoot(cwd) {
51094
- for (let current = (0, import_path14.resolve)(cwd); ; current = (0, import_path14.dirname)(current)) {
51095
- if ((0, import_fs9.existsSync)((0, import_path14.join)(current, ".git"))) return current;
51096
- if ((0, import_path14.dirname)(current) === current) return (0, import_path14.resolve)(cwd);
51118
+ for (let current = (0, import_path15.resolve)(cwd); ; current = (0, import_path15.dirname)(current)) {
51119
+ if ((0, import_fs10.existsSync)((0, import_path15.join)(current, ".git"))) return current;
51120
+ if ((0, import_path15.dirname)(current) === current) return (0, import_path15.resolve)(cwd);
51097
51121
  }
51098
51122
  }
51099
51123
  function instructionPaths(cwd) {
51100
51124
  const root = workspaceRoot(cwd);
51101
51125
  const paths = [];
51102
- for (let current = (0, import_path14.resolve)(cwd); ; current = (0, import_path14.dirname)(current)) {
51103
- const path4 = (0, import_path14.join)(current, INSTRUCTIONS_FILE);
51126
+ for (let current = (0, import_path15.resolve)(cwd); ; current = (0, import_path15.dirname)(current)) {
51127
+ const path4 = (0, import_path15.join)(current, INSTRUCTIONS_FILE);
51104
51128
  try {
51105
- if ((0, import_fs9.existsSync)(path4) && (0, import_fs9.statSync)(path4).isFile()) paths.unshift(path4);
51129
+ if ((0, import_fs10.existsSync)(path4) && (0, import_fs10.statSync)(path4).isFile()) paths.unshift(path4);
51106
51130
  } catch {
51107
51131
  }
51108
- if (current === root || (0, import_path14.dirname)(current) === current) return paths;
51132
+ if (current === root || (0, import_path15.dirname)(current) === current) return paths;
51109
51133
  }
51110
51134
  }
51111
51135
  function antigravityWorkspaceInstructions(cwd, maxChars = MAX_INSTRUCTION_CHARS) {
@@ -51116,7 +51140,7 @@ function antigravityWorkspaceInstructions(cwd, maxChars = MAX_INSTRUCTION_CHARS)
51116
51140
  if (remaining <= 0) break;
51117
51141
  let content;
51118
51142
  try {
51119
- content = (0, import_fs9.readFileSync)(path4, "utf8").trim();
51143
+ content = (0, import_fs10.readFileSync)(path4, "utf8").trim();
51120
51144
  } catch {
51121
51145
  continue;
51122
51146
  }
@@ -51359,7 +51383,7 @@ function normalizeAntigravityFrame(event) {
51359
51383
  }
51360
51384
  function antigravityBrainRoot(env) {
51361
51385
  const home = env.HOME?.trim() || env.USERPROFILE?.trim();
51362
- return home ? (0, import_path15.resolve)(home, ".gemini", "antigravity-cli", "brain") : void 0;
51386
+ return home ? (0, import_path16.resolve)(home, ".gemini", "antigravity-cli", "brain") : void 0;
51363
51387
  }
51364
51388
  function parseEntry(text3) {
51365
51389
  try {
@@ -51397,14 +51421,14 @@ function childTranscriptPath(root, frame) {
51397
51421
  try {
51398
51422
  const url3 = new URL(logUri);
51399
51423
  if (url3.protocol !== "file:") return void 0;
51400
- path4 = (0, import_path15.resolve)((0, import_url3.fileURLToPath)(url3));
51424
+ path4 = (0, import_path16.resolve)((0, import_url3.fileURLToPath)(url3));
51401
51425
  } catch {
51402
51426
  return void 0;
51403
51427
  }
51404
- const fromRoot = (0, import_path15.relative)(root, path4);
51405
- if (!fromRoot || (0, import_path15.isAbsolute)(fromRoot) || fromRoot.split(import_path15.sep).includes("..")) return void 0;
51428
+ const fromRoot = (0, import_path16.relative)(root, path4);
51429
+ if (!fromRoot || (0, import_path16.isAbsolute)(fromRoot) || fromRoot.split(import_path16.sep).includes("..")) return void 0;
51406
51430
  const expected = [conversationId, ...LOG_DIRS, TRANSCRIPT_FILE];
51407
- const segments = fromRoot.split(import_path15.sep);
51431
+ const segments = fromRoot.split(import_path16.sep);
51408
51432
  const matches = segments.length === expected.length && segments.every((segment, index) => segment === expected[index]);
51409
51433
  return matches ? path4 : void 0;
51410
51434
  }
@@ -51664,24 +51688,24 @@ function antigravityTurnInput(run2, context) {
51664
51688
  });
51665
51689
  return { turnId: run2.runId, text: appendImagePathReferences(text3, images) };
51666
51690
  }
51667
- var import_promises54, import_path13, import_fs9, import_path14, import_path15, import_url3, import_crypto19, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
51691
+ var import_promises54, import_path14, import_fs10, import_path15, import_path16, import_url3, import_crypto19, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
51668
51692
  var init_antigravity = __esm({
51669
51693
  "../agent-core/dist/providers/antigravity.js"() {
51670
51694
  "use strict";
51671
51695
  init_chunk_TFIO37PI();
51672
- init_chunk_N2M5D7RS();
51696
+ init_chunk_LDVOKUAU();
51673
51697
  init_chunk_RBQC7XZH();
51674
51698
  init_chunk_ZCTKXKYY();
51675
- init_chunk_6VWVDJ2A();
51699
+ init_chunk_KVTSAS2T();
51676
51700
  init_chunk_DLVRNIY5();
51677
51701
  init_chunk_YXWJW7I5();
51678
51702
  import_promises54 = require("fs/promises");
51679
- import_path13 = require("path");
51680
- init_type_guards();
51681
- import_fs9 = require("fs");
51682
51703
  import_path14 = require("path");
51683
- init_effort();
51704
+ init_type_guards();
51705
+ import_fs10 = require("fs");
51684
51706
  import_path15 = require("path");
51707
+ init_effort();
51708
+ import_path16 = require("path");
51685
51709
  import_url3 = require("url");
51686
51710
  import_crypto19 = require("crypto");
51687
51711
  init_agent2();
@@ -51721,7 +51745,7 @@ var init_antigravity = __esm({
51721
51745
  #full;
51722
51746
  constructor(path4) {
51723
51747
  this.#cursor = new TranscriptCursor(path4);
51724
- this.#fullPath = (0, import_path15.resolve)((0, import_path15.dirname)(path4), FULL_TRANSCRIPT_FILE);
51748
+ this.#fullPath = (0, import_path16.resolve)((0, import_path16.dirname)(path4), FULL_TRANSCRIPT_FILE);
51725
51749
  }
51726
51750
  skipExisting() {
51727
51751
  this.#cursor.read();
@@ -51769,7 +51793,7 @@ var init_antigravity = __esm({
51769
51793
  /** A conversation this turn did not resume was created by it, so it is read whole. */
51770
51794
  trackParent(conversationId) {
51771
51795
  if (this.#parent?.conversationId === conversationId) return;
51772
- const path4 = (0, import_path15.resolve)(this.#root, conversationId, ...LOG_DIRS, TRANSCRIPT_FILE);
51796
+ const path4 = (0, import_path16.resolve)(this.#root, conversationId, ...LOG_DIRS, TRANSCRIPT_FILE);
51773
51797
  this.#parent = { conversationId, transcript: new BrainTranscript(path4) };
51774
51798
  }
51775
51799
  /** A launcher keeps the first valid transcript it names; later frames change nothing. */
@@ -52204,7 +52228,7 @@ function parseConfig(raw) {
52204
52228
  }
52205
52229
  }
52206
52230
  async function writeCommandCodeProjectMcp(cwd, mcp) {
52207
- const path4 = (0, import_path16.join)(cwd, ".mcp.json");
52231
+ const path4 = (0, import_path17.join)(cwd, ".mcp.json");
52208
52232
  const original = await (0, import_promises55.readFile)(path4, "utf8").catch(() => null);
52209
52233
  const config2 = parseConfig(original);
52210
52234
  const next = {
@@ -52399,19 +52423,19 @@ function commandCodeTurnInput(run2, context) {
52399
52423
  });
52400
52424
  return { turnId: run2.runId, text: appendImagePathReferences(text3, images) };
52401
52425
  }
52402
- var import_promises55, import_path16, import_crypto20, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
52426
+ var import_promises55, import_path17, import_crypto20, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
52403
52427
  var init_command_code = __esm({
52404
52428
  "../agent-core/dist/providers/command-code.js"() {
52405
52429
  "use strict";
52406
- init_chunk_N2M5D7RS();
52430
+ init_chunk_LDVOKUAU();
52407
52431
  init_chunk_RBQC7XZH();
52408
52432
  init_chunk_ZCTKXKYY();
52409
- init_chunk_6VWVDJ2A();
52433
+ init_chunk_KVTSAS2T();
52410
52434
  init_chunk_DLVRNIY5();
52411
52435
  init_chunk_OSECDZA5();
52412
52436
  init_chunk_YXWJW7I5();
52413
52437
  import_promises55 = require("fs/promises");
52414
- import_path16 = require("path");
52438
+ import_path17 = require("path");
52415
52439
  init_agent2();
52416
52440
  init_runtime_v2();
52417
52441
  init_acp();
@@ -57830,7 +57854,7 @@ var require_websocket_server = __commonJS({
57830
57854
  // package.json
57831
57855
  var package_default = {
57832
57856
  name: "@alan-ai-hq/agent-manager",
57833
- version: "0.1.162",
57857
+ version: "0.1.164",
57834
57858
  private: true,
57835
57859
  type: "module",
57836
57860
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -59962,7 +59986,7 @@ async function push(context, request2) {
59962
59986
  var import_node_child_process = require("child_process");
59963
59987
 
59964
59988
  // ../agent-core/dist/process.js
59965
- init_chunk_6VWVDJ2A();
59989
+ init_chunk_KVTSAS2T();
59966
59990
  init_chunk_YXWJW7I5();
59967
59991
 
59968
59992
  // src/capabilities/git/run-git.ts
@@ -60291,6 +60315,20 @@ async function checkOne(path4, deps, signal) {
60291
60315
  );
60292
60316
  return fetched.exitCode === 0 ? write({ state: "behind", path: path4, snapshot, tip, fetched: true }) : write({ state: "failed", path: path4, snapshot, reason: gitError(fetched, "fetch") });
60293
60317
  }
60318
+ async function currentBranch(git, cwd, signal) {
60319
+ const output2 = await git.run(
60320
+ { cwd, args: ["symbolic-ref", "--quiet", "--short", "HEAD"], readOnly: true },
60321
+ signal
60322
+ );
60323
+ return output2.exitCode === 0 ? output2.stdout.trim() || null : null;
60324
+ }
60325
+ async function moveSnapshotTo(git, cwd, snapshot, tip, signal) {
60326
+ const run2 = (args) => git.run({ cwd, args }, signal);
60327
+ if ((await run2(["switch", "--quiet", "--detach", tip])).exitCode !== 0) return false;
60328
+ const moved = await run2(["update-ref", `refs/heads/${snapshot.branch}`, tip, snapshot.head]);
60329
+ const back = await run2(["switch", "--quiet", snapshot.branch]);
60330
+ return moved.exitCode === 0 && back.exitCode === 0;
60331
+ }
60294
60332
  async function isCheckout(path4) {
60295
60333
  return (0, import_promises11.stat)((0, import_node_path7.join)(path4, ".git")).then(
60296
60334
  () => true,
@@ -61310,7 +61348,6 @@ function runtimePaths(stateDir) {
61310
61348
 
61311
61349
  // src/platform/process-memory.ts
61312
61350
  var import_node_child_process4 = require("child_process");
61313
- var import_node_fs7 = require("fs");
61314
61351
  var import_promises16 = require("fs/promises");
61315
61352
  var import_node_os2 = require("os");
61316
61353
  var import_node_util3 = require("util");
@@ -61378,52 +61415,9 @@ function readMemoryPressure() {
61378
61415
  if (process.platform === "linux") return linuxPressure();
61379
61416
  return Promise.resolve("normal");
61380
61417
  }
61381
- function parseDarwinVmStat(output2) {
61382
- const pageSize = Number(/page size of (\d+) bytes/.exec(output2)?.[1]);
61383
- if (!Number.isFinite(pageSize) || pageSize <= 0) return null;
61384
- const pages = (name) => {
61385
- const match = new RegExp(`^Pages ${name}:\\s+(\\d+)\\.?$`, "m").exec(output2);
61386
- return match ? Number(match[1]) : null;
61387
- };
61388
- const free = pages("free");
61389
- if (free === null) return null;
61390
- return (free + (pages("inactive") ?? 0) + (pages("speculative") ?? 0)) * pageSize;
61391
- }
61392
- function parseLinuxMemInfo(output2) {
61393
- const kilobytes = /^MemAvailable:\s+(\d+)\s+kB$/m.exec(output2)?.[1];
61394
- return kilobytes === void 0 ? null : Number(kilobytes) * 1024;
61395
- }
61396
- var CAPACITY_PROBE_TTL_MS = 2e3;
61397
- var AvailableMemoryProbe = class {
61398
- cached = null;
61399
- read(now) {
61400
- if (this.cached !== null && now - this.cached.at < CAPACITY_PROBE_TTL_MS) {
61401
- return this.cached.bytes;
61402
- }
61403
- let bytes = null;
61404
- try {
61405
- if (process.platform === "darwin") {
61406
- bytes = parseDarwinVmStat(
61407
- (0, import_node_child_process4.execFileSync)("vm_stat", { encoding: "utf8", timeout: PROBE_TIMEOUT_MS })
61408
- );
61409
- } else if (process.platform === "linux") {
61410
- bytes = parseLinuxMemInfo((0, import_node_fs7.readFileSync)("/proc/meminfo", "utf8"));
61411
- }
61412
- } catch {
61413
- bytes = null;
61414
- }
61415
- this.cached = { at: now, bytes };
61416
- return bytes;
61417
- }
61418
- };
61419
- var availableMemoryProbe = new AvailableMemoryProbe();
61420
- function readMemoryCapacity() {
61418
+ function readTotalMemoryBytes() {
61421
61419
  const constrained = process.constrainedMemory();
61422
- const totalBytes = constrained > 0 ? Math.min((0, import_node_os2.totalmem)(), constrained) : (0, import_node_os2.totalmem)();
61423
- const reported = typeof process.availableMemory === "function" ? process.availableMemory() : (0, import_node_os2.freemem)();
61424
- const probed = constrained > 0 && process.platform === "linux" ? null : availableMemoryProbe.read(Date.now());
61425
- const availableBytes = Math.min(totalBytes, Math.max(reported, probed ?? reported));
61426
- return { totalBytes, availableBytes };
61420
+ return constrained > 0 ? Math.min((0, import_node_os2.totalmem)(), constrained) : (0, import_node_os2.totalmem)();
61427
61421
  }
61428
61422
  async function processMemoryRows() {
61429
61423
  if (process.platform === "win32") {
@@ -61903,7 +61897,7 @@ var import_promises20 = require("fs/promises");
61903
61897
  var import_node_path17 = require("path");
61904
61898
 
61905
61899
  // src/platform/service/windows-service.ts
61906
- var import_node_fs8 = require("fs");
61900
+ var import_node_fs7 = require("fs");
61907
61901
  var import_promises19 = require("fs/promises");
61908
61902
  var import_node_path16 = require("path");
61909
61903
 
@@ -62133,7 +62127,7 @@ function windowsManager(host, profile) {
62133
62127
  name: files.runValue,
62134
62128
  definitionPath: files.config,
62135
62129
  install: async (spec, { restart }) => {
62136
- if (process.platform === "win32" && !(0, import_node_fs8.existsSync)(files.helper)) {
62130
+ if (process.platform === "win32" && !(0, import_node_fs7.existsSync)(files.helper)) {
62137
62131
  throw new RuntimeFault("io_failed", `Windows helper is missing: ${files.helper}`);
62138
62132
  }
62139
62133
  await (0, import_promises19.mkdir)((0, import_node_path16.dirname)(spec.logPath), { recursive: true });
@@ -62828,7 +62822,7 @@ function systemAssertionSpawner(log) {
62828
62822
  // src/platform/spawn-detached.ts
62829
62823
  var import_node_child_process8 = require("child_process");
62830
62824
  var import_node_crypto12 = require("crypto");
62831
- var import_node_fs9 = require("fs");
62825
+ var import_node_fs8 = require("fs");
62832
62826
  var import_node_path21 = require("path");
62833
62827
  var WINDOWS_UNSAFE_ENV = "NODE_PENDING_PIPE_INSTANCES";
62834
62828
  var SYSTEMD_RUN = "systemd-run";
@@ -62883,8 +62877,8 @@ function isolatedCommand(request2, isolation) {
62883
62877
  };
62884
62878
  }
62885
62879
  function spawnDetached(request2, isolation) {
62886
- (0, import_node_fs9.mkdirSync)((0, import_node_path21.dirname)(request2.outputPath), { recursive: true, mode: 448 });
62887
- const output2 = (0, import_node_fs9.openSync)(request2.outputPath, "a", 384);
62880
+ (0, import_node_fs8.mkdirSync)((0, import_node_path21.dirname)(request2.outputPath), { recursive: true, mode: 448 });
62881
+ const output2 = (0, import_node_fs8.openSync)(request2.outputPath, "a", 384);
62888
62882
  const { command, args } = isolatedCommand(request2, isolation);
62889
62883
  try {
62890
62884
  const child = (0, import_node_child_process8.spawn)(command, args, {
@@ -62900,7 +62894,7 @@ function spawnDetached(request2, isolation) {
62900
62894
  child.unref();
62901
62895
  return { pid: child.pid };
62902
62896
  } finally {
62903
- (0, import_node_fs9.closeSync)(output2);
62897
+ (0, import_node_fs8.closeSync)(output2);
62904
62898
  }
62905
62899
  }
62906
62900
 
@@ -62940,7 +62934,7 @@ function createUpdateGate(deps) {
62940
62934
 
62941
62935
  // src/platform/wake-clock.ts
62942
62936
  var import_node_child_process9 = require("child_process");
62943
- var import_node_fs10 = require("fs");
62937
+ var import_node_fs9 = require("fs");
62944
62938
  var import_node_readline = require("readline");
62945
62939
  var PTP_DEVICE = "/dev/ptp0";
62946
62940
  var RESPAWN_BASE_MS = 1e3;
@@ -63024,7 +63018,7 @@ function systemWakeClockSpawner(log) {
63024
63018
  function startWakeClock(options) {
63025
63019
  const { clock, log } = options;
63026
63020
  const platform3 = options.platform ?? process.platform;
63027
- const hasPtpDevice = options.hasPtpDevice ?? (() => (0, import_node_fs10.existsSync)(PTP_DEVICE));
63021
+ const hasPtpDevice = options.hasPtpDevice ?? (() => (0, import_node_fs9.existsSync)(PTP_DEVICE));
63028
63022
  if (platform3 !== "linux" || !hasPtpDevice()) return { [Symbol.dispose]: () => {
63029
63023
  } };
63030
63024
  const spawner = options.spawner ?? systemWakeClockSpawner(log);
@@ -65158,7 +65152,7 @@ function fingerprintWholeText(fingerprint) {
65158
65152
  }
65159
65153
 
65160
65154
  // src/capabilities/native-ingest/hook-config.ts
65161
- var import_node_fs11 = require("fs");
65155
+ var import_node_fs10 = require("fs");
65162
65156
  var import_node_path28 = require("path");
65163
65157
 
65164
65158
  // src/capabilities/native-ingest/provider-paths.ts
@@ -65236,9 +65230,9 @@ function hookHandler(provider4, event, options) {
65236
65230
  return { type: "command", command: posixCommand(argv, environment), timeout: 5 };
65237
65231
  }
65238
65232
  function readSettings(path4, backupWhenMalformed, now) {
65239
- if (!(0, import_node_fs11.existsSync)(path4)) return {};
65233
+ if (!(0, import_node_fs10.existsSync)(path4)) return {};
65240
65234
  try {
65241
- const value2 = JSON.parse((0, import_node_fs11.readFileSync)(path4, "utf8"));
65235
+ const value2 = JSON.parse((0, import_node_fs10.readFileSync)(path4, "utf8"));
65242
65236
  if (!isRecord4(value2)) throw new Error("settings root must be an object");
65243
65237
  if (value2.hooks !== void 0 && !isRecord4(value2.hooks)) {
65244
65238
  throw new Error("settings `hooks` must be an object");
@@ -65248,7 +65242,7 @@ function readSettings(path4, backupWhenMalformed, now) {
65248
65242
  const reason = error62 instanceof Error ? error62.message : String(error62);
65249
65243
  if (!backupWhenMalformed) throw new Error(`${path4} is malformed: ${reason}`);
65250
65244
  const backup = `${path4}.malformed-${now}.bak`;
65251
- (0, import_node_fs11.copyFileSync)(path4, backup);
65245
+ (0, import_node_fs10.copyFileSync)(path4, backup);
65252
65246
  throw new Error(`${path4} is malformed and was copied to ${backup}: ${reason}`);
65253
65247
  }
65254
65248
  }
@@ -65256,14 +65250,14 @@ function hooksOf(settings2) {
65256
65250
  return isRecord4(settings2.hooks) ? settings2.hooks : {};
65257
65251
  }
65258
65252
  function writeSettings(path4, settings2) {
65259
- (0, import_node_fs11.mkdirSync)((0, import_node_path28.dirname)(path4), { recursive: true, mode: 448 });
65253
+ (0, import_node_fs10.mkdirSync)((0, import_node_path28.dirname)(path4), { recursive: true, mode: 448 });
65260
65254
  const temporary = `${path4}.${process.pid}.tmp`;
65261
65255
  try {
65262
- (0, import_node_fs11.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
65256
+ (0, import_node_fs10.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
65263
65257
  `, { mode: 384 });
65264
- (0, import_node_fs11.renameSync)(temporary, path4);
65258
+ (0, import_node_fs10.renameSync)(temporary, path4);
65265
65259
  } finally {
65266
- (0, import_node_fs11.rmSync)(temporary, { force: true });
65260
+ (0, import_node_fs10.rmSync)(temporary, { force: true });
65267
65261
  }
65268
65262
  }
65269
65263
  function isIngestionHandler(handler) {
@@ -65308,7 +65302,7 @@ function installIngestionHooks(provider4, options, now) {
65308
65302
  }
65309
65303
  function removeIngestionHooks(provider4, where, now) {
65310
65304
  const path4 = providerHookSettingsPath(provider4, where);
65311
- if (!(0, import_node_fs11.existsSync)(path4)) return { provider: provider4, path: path4, changed: false };
65305
+ if (!(0, import_node_fs10.existsSync)(path4)) return { provider: provider4, path: path4, changed: false };
65312
65306
  const settings2 = readSettings(path4, true, now);
65313
65307
  const hooks = hooksOf(settings2);
65314
65308
  const nextHooks = {};
@@ -65345,7 +65339,7 @@ function ingestionHookStatus(provider4, options) {
65345
65339
  }
65346
65340
 
65347
65341
  // src/capabilities/native-ingest/hook-input.ts
65348
- var import_node_fs12 = require("fs");
65342
+ var import_node_fs11 = require("fs");
65349
65343
  var import_node_path29 = require("path");
65350
65344
  var ALAN_MANAGED_SESSION_ENV = "ALAN_MANAGED_SESSION";
65351
65345
  var MAX_HOOK_STDIN_BYTES = 256 * 1024 * 1024;
@@ -65445,10 +65439,10 @@ function hookPayload(input2) {
65445
65439
  }
65446
65440
  function realpathOrSelf(path4) {
65447
65441
  try {
65448
- return (0, import_node_fs12.realpathSync)(path4);
65442
+ return (0, import_node_fs11.realpathSync)(path4);
65449
65443
  } catch {
65450
65444
  try {
65451
- return (0, import_node_path29.join)((0, import_node_fs12.realpathSync)((0, import_node_path29.dirname)(path4)), (0, import_node_path29.basename)(path4));
65445
+ return (0, import_node_path29.join)((0, import_node_fs11.realpathSync)((0, import_node_path29.dirname)(path4)), (0, import_node_path29.basename)(path4));
65452
65446
  } catch {
65453
65447
  return path4;
65454
65448
  }
@@ -65479,7 +65473,7 @@ function parseHookSignal(input2) {
65479
65473
  }
65480
65474
 
65481
65475
  // src/capabilities/native-ingest/ingest.ts
65482
- var import_node_fs13 = require("fs");
65476
+ var import_node_fs12 = require("fs");
65483
65477
 
65484
65478
  // ../shared/dist/types/native-agent-session.js
65485
65479
  var nativeAgentProviderBackendKinds = {
@@ -66249,7 +66243,7 @@ function workerKey(provider4, externalSessionId) {
66249
66243
  return `${provider4}\0${externalSessionId}`;
66250
66244
  }
66251
66245
  function holdFor(entry) {
66252
- const stats = (0, import_node_fs13.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66246
+ const stats = (0, import_node_fs12.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66253
66247
  if (!stats) return [];
66254
66248
  return [
66255
66249
  {
@@ -66450,7 +66444,7 @@ async function startNativeIngest(deps) {
66450
66444
  return "accepted";
66451
66445
  };
66452
66446
  const hasUnreadBytes = (entry, now) => {
66453
- const stats = (0, import_node_fs13.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66447
+ const stats = (0, import_node_fs12.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66454
66448
  if (!stats || now - Number(stats.mtimeMs) > timing.sweepRecencyMs) return false;
66455
66449
  const replaced = String(stats.dev) !== entry.device || String(stats.ino) !== entry.inode;
66456
66450
  return replaced || Number(stats.size) > entry.cursor.offset;
@@ -66494,7 +66488,7 @@ async function startNativeIngest(deps) {
66494
66488
  const recordAlanRun = async (hold, runId) => {
66495
66489
  const entry = store.get(hold.provider, hold.externalSessionId);
66496
66490
  if (!entry || entry.dead) return;
66497
- const stats = (0, import_node_fs13.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66491
+ const stats = (0, import_node_fs12.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66498
66492
  if (!stats) return;
66499
66493
  const identity = { device: String(stats.dev), inode: String(stats.ino) };
66500
66494
  const size = Number(stats.size);
@@ -66568,7 +66562,7 @@ async function startNativeIngest(deps) {
66568
66562
  init_alan_code();
66569
66563
 
66570
66564
  // src/capabilities/providers/commands.ts
66571
- var import_node_fs14 = require("fs");
66565
+ var import_node_fs13 = require("fs");
66572
66566
  var import_promises35 = require("fs/promises");
66573
66567
  var import_node_path32 = require("path");
66574
66568
  var PROVIDER_COMMANDS = [
@@ -66606,7 +66600,7 @@ function pathDelimiter(platform3) {
66606
66600
  async function isRunnable(path4, platform3) {
66607
66601
  try {
66608
66602
  if (!(await (0, import_promises35.stat)(path4)).isFile()) return false;
66609
- if (platform3 !== "win32") await (0, import_promises35.access)(path4, import_node_fs14.constants.X_OK);
66603
+ if (platform3 !== "win32") await (0, import_promises35.access)(path4, import_node_fs13.constants.X_OK);
66610
66604
  return true;
66611
66605
  } catch {
66612
66606
  return false;
@@ -66789,7 +66783,7 @@ init_runtime_v2();
66789
66783
 
66790
66784
  // src/capabilities/providers/account-label.ts
66791
66785
  var import_node_child_process12 = require("child_process");
66792
- var import_node_fs15 = require("fs");
66786
+ var import_node_fs14 = require("fs");
66793
66787
  var import_node_path33 = require("path");
66794
66788
  var import_node_url3 = require("url");
66795
66789
  var ACCOUNT_TIMEOUT_MS = 2e4;
@@ -66892,7 +66886,7 @@ async function claudeLabel(executable, env) {
66892
66886
  const childEnv = { ...env };
66893
66887
  delete childEnv.FORCE_CODE_TERMINAL;
66894
66888
  const bundledSdk = typeof __dirname === "string" ? (0, import_node_path33.join)(__dirname, "claude-sdk.mjs") : "";
66895
- const sdkSpecifier = (0, import_node_fs15.existsSync)(bundledSdk) ? (0, import_node_url3.pathToFileURL)(bundledSdk).href : "@anthropic-ai/claude-agent-sdk";
66889
+ const sdkSpecifier = (0, import_node_fs14.existsSync)(bundledSdk) ? (0, import_node_url3.pathToFileURL)(bundledSdk).href : "@anthropic-ai/claude-agent-sdk";
66896
66890
  const { query } = await import(sdkSpecifier);
66897
66891
  const session = query({
66898
66892
  prompt: idlePrompt(abort.signal),
@@ -67302,7 +67296,7 @@ var import_node_path37 = require("path");
67302
67296
  // ../shared/dist/node/shell-environment.js
67303
67297
  var import_node_child_process13 = require("child_process");
67304
67298
  var import_node_crypto16 = require("crypto");
67305
- var import_node_fs17 = require("fs");
67299
+ var import_node_fs16 = require("fs");
67306
67300
  var import_node_os6 = require("os");
67307
67301
  var import_node_path36 = require("path");
67308
67302
 
@@ -67311,7 +67305,7 @@ var import_node_os5 = require("os");
67311
67305
  var import_node_path35 = require("path");
67312
67306
 
67313
67307
  // ../shared/dist/node/version-manager-paths.js
67314
- var import_node_fs16 = require("fs");
67308
+ var import_node_fs15 = require("fs");
67315
67309
  var import_node_path34 = require("path");
67316
67310
  function compareNodeVersionsDesc(a, b) {
67317
67311
  const parse7 = (value2) => value2.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
@@ -67326,19 +67320,19 @@ function compareNodeVersionsDesc(a, b) {
67326
67320
  }
67327
67321
  function resolveNvmDefaultBin(home) {
67328
67322
  const versionsDir = (0, import_node_path34.join)(home, ".nvm", "versions", "node");
67329
- if (!(0, import_node_fs16.existsSync)(versionsDir))
67323
+ if (!(0, import_node_fs15.existsSync)(versionsDir))
67330
67324
  return null;
67331
67325
  let alias = null;
67332
67326
  try {
67333
67327
  const aliasFile = (0, import_node_path34.join)(home, ".nvm", "alias", "default");
67334
- if ((0, import_node_fs16.existsSync)(aliasFile))
67335
- alias = (0, import_node_fs16.readFileSync)(aliasFile, "utf8").trim();
67328
+ if ((0, import_node_fs15.existsSync)(aliasFile))
67329
+ alias = (0, import_node_fs15.readFileSync)(aliasFile, "utf8").trim();
67336
67330
  } catch {
67337
67331
  alias = null;
67338
67332
  }
67339
67333
  let installed;
67340
67334
  try {
67341
- installed = (0, import_node_fs16.readdirSync)(versionsDir).filter((entry) => entry.startsWith("v"));
67335
+ installed = (0, import_node_fs15.readdirSync)(versionsDir).filter((entry) => entry.startsWith("v"));
67342
67336
  } catch {
67343
67337
  return null;
67344
67338
  }
@@ -67349,7 +67343,7 @@ function resolveNvmDefaultBin(home) {
67349
67343
  if (!chosen)
67350
67344
  return null;
67351
67345
  const bin = (0, import_node_path34.join)(versionsDir, chosen, "bin");
67352
- return (0, import_node_fs16.existsSync)(bin) ? bin : null;
67346
+ return (0, import_node_fs15.existsSync)(bin) ? bin : null;
67353
67347
  }
67354
67348
  function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
67355
67349
  if (platform3 === "win32")
@@ -67368,7 +67362,7 @@ function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
67368
67362
  if (!dir || seen.has(dir))
67369
67363
  continue;
67370
67364
  seen.add(dir);
67371
- if ((0, import_node_fs16.existsSync)(dir))
67365
+ if ((0, import_node_fs15.existsSync)(dir))
67372
67366
  resolved.push(dir);
67373
67367
  }
67374
67368
  return resolved;
@@ -67410,7 +67404,7 @@ function promoteUserBinDirs(path4, home, versionManagerDirs) {
67410
67404
  // ../shared/dist/node/shell-environment.js
67411
67405
  function isExecutableFile(path4) {
67412
67406
  try {
67413
- (0, import_node_fs17.accessSync)(path4, import_node_fs17.constants.X_OK);
67407
+ (0, import_node_fs16.accessSync)(path4, import_node_fs16.constants.X_OK);
67414
67408
  return true;
67415
67409
  } catch {
67416
67410
  return false;
@@ -69320,7 +69314,7 @@ async function publishLocalSkill(options) {
69320
69314
 
69321
69315
  // src/capabilities/skills/native-index.ts
69322
69316
  var import_node_crypto23 = require("crypto");
69323
- var import_node_fs18 = require("fs");
69317
+ var import_node_fs17 = require("fs");
69324
69318
  var import_promises45 = require("fs/promises");
69325
69319
  var import_node_path45 = require("path");
69326
69320
  var ALAN_SKILLS_PLUGIN_NAME = "alan";
@@ -69471,7 +69465,7 @@ async function reconcileNativeIndex(layout, installed, options) {
69471
69465
  };
69472
69466
  }
69473
69467
  function installedSkillFolders(layout) {
69474
- return (0, import_node_fs18.existsSync)((0, import_node_path45.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
69468
+ return (0, import_node_fs17.existsSync)((0, import_node_path45.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
69475
69469
  }
69476
69470
 
69477
69471
  // src/capabilities/skills/sync.ts
@@ -71360,10 +71354,10 @@ async function reapLeftoverEngines(path4, options) {
71360
71354
  }
71361
71355
 
71362
71356
  // src/holder/launch-command.ts
71363
- var import_node_fs19 = require("fs");
71357
+ var import_node_fs18 = require("fs");
71364
71358
  var import_node_path53 = require("path");
71365
71359
  var HOLDER_BUNDLE = "alan-holder.cjs";
71366
- function holderArguments(runtimeArgs, nodeFlags, exists6 = import_node_fs19.existsSync) {
71360
+ function holderArguments(runtimeArgs, nodeFlags, exists6 = import_node_fs18.existsSync) {
71367
71361
  const bundle = runtimeArgs.at(-1);
71368
71362
  const lean = bundle === void 0 ? void 0 : (0, import_node_path53.join)((0, import_node_path53.dirname)(bundle), HOLDER_BUNDLE);
71369
71363
  const script = lean !== void 0 && exists6(lean) ? [...runtimeArgs.slice(0, -1), lean] : runtimeArgs;
@@ -71502,20 +71496,20 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71502
71496
 
71503
71497
  // src/holder/serve.ts
71504
71498
  var import_node_crypto30 = require("crypto");
71505
- var import_node_fs24 = require("fs");
71499
+ var import_node_fs23 = require("fs");
71506
71500
  var import_node_net3 = require("net");
71507
71501
  var import_node_path66 = require("path");
71508
71502
  init_runtime_v2();
71509
71503
 
71510
71504
  // src/holder/admission.ts
71511
- var import_node_fs21 = require("fs");
71505
+ var import_node_fs20 = require("fs");
71512
71506
  var import_promises61 = require("fs/promises");
71513
71507
  var import_node_os10 = require("os");
71514
71508
  var import_node_path60 = require("path");
71515
71509
  init_constants();
71516
71510
 
71517
71511
  // ../shared/dist/node/local-workspace.js
71518
- var import_node_fs20 = require("fs");
71512
+ var import_node_fs19 = require("fs");
71519
71513
  var import_node_os9 = require("os");
71520
71514
  var import_node_path55 = require("path");
71521
71515
  function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os9.homedir)()) {
@@ -71743,18 +71737,16 @@ async function switchTo(checkout, current, operationId, deps, signal) {
71743
71737
  async function applyRequestedCheckout(checkout, spec, deps, signal) {
71744
71738
  try {
71745
71739
  if (!await isCheckout(checkout.path)) return await clone2(checkout, deps, signal);
71746
- const status = await readCheckoutStatus(deps.git, checkout.path, signal);
71747
- if (status === null) return notSwitched(checkout, null, "git status failed");
71748
- if (status.branch === checkout.branch) return { kind: "on_branch" };
71749
- if (status.dirty) return notSwitched(checkout, status.branch, "it has uncommitted changes");
71740
+ const branch = await currentBranch(deps.git, checkout.path, signal);
71741
+ if (branch === checkout.branch) return { kind: "on_branch" };
71750
71742
  if (!await claimFirstLease(deps.dir, checkout.path)) {
71751
71743
  return notSwitched(
71752
71744
  checkout,
71753
- status.branch,
71745
+ branch,
71754
71746
  "an earlier conversation on this machine already uses it"
71755
71747
  );
71756
71748
  }
71757
- return await switchTo(checkout, status.branch, `checkout-${spec.runId}`, deps, signal);
71749
+ return await switchTo(checkout, branch, `checkout-${spec.runId}`, deps, signal);
71758
71750
  } catch (error62) {
71759
71751
  return noted(
71760
71752
  `could not be put on ${checkout.branch}, the branch picked for this chat`,
@@ -71785,15 +71777,13 @@ async function fastForward(freshness, operationId, deps, signal) {
71785
71777
  const attempt2 = await deps.locks.tryExclusive(snapshot.commonDir, operationId);
71786
71778
  if (attempt2.kind === "busy") return false;
71787
71779
  const _lock = __using(_stack, attempt2.lock, true);
71788
- const now = await readCheckoutStatus(deps.git, cwd, signal);
71789
- if (now === null || now.dirty || now.head !== snapshot.head || now.branch !== snapshot.branch) {
71790
- return false;
71791
- }
71792
- const git = (args) => deps.git.run({ cwd, args }, signal);
71793
- if ((await git(["switch", "--quiet", "--detach", tip])).exitCode !== 0) return false;
71794
- const moved = await git(["update-ref", `refs/heads/${snapshot.branch}`, tip, snapshot.head]);
71795
- const back = await git(["switch", "--quiet", snapshot.branch]);
71796
- return moved.exitCode === 0 && back.exitCode === 0;
71780
+ const head = await deps.git.run(
71781
+ { cwd, args: ["rev-parse", "--verify", "HEAD"], readOnly: true },
71782
+ signal
71783
+ );
71784
+ if (head.exitCode !== 0 || head.stdout.trim() !== snapshot.head) return false;
71785
+ if (await currentBranch(deps.git, cwd, signal) !== snapshot.branch) return false;
71786
+ return moveSnapshotTo(deps.git, cwd, snapshot, tip, signal);
71797
71787
  } catch (_) {
71798
71788
  var _error = _, _hasError = true;
71799
71789
  } finally {
@@ -71844,13 +71834,15 @@ async function applyRequestedCheckouts(spec, deps, signal) {
71844
71834
  const settled2 = /* @__PURE__ */ new Set();
71845
71835
  const problems = [];
71846
71836
  for (const checkout of requestedCheckoutsOf(spec, deps.log)) {
71837
+ const startedAt = Date.now();
71847
71838
  const outcome2 = await applyRequestedCheckout(checkout, spec, deps, signal);
71848
71839
  deps.log.info("workspace.requested_checkout", {
71849
71840
  runId: spec.runId,
71850
71841
  path: checkout.path,
71851
71842
  branch: checkout.branch,
71852
71843
  outcome: outcome2.kind,
71853
- ...outcome2.kind === "moved" ? { how: outcome2.how } : {}
71844
+ ...outcome2.kind === "moved" ? { how: outcome2.how } : {},
71845
+ ms: Date.now() - startedAt
71854
71846
  });
71855
71847
  if (outcome2.kind === "on_branch") continue;
71856
71848
  settled2.add((0, import_node_path59.resolve)(checkout.path));
@@ -71866,6 +71858,7 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
71866
71858
  if (settled2.has((0, import_node_path59.resolve)(target))) continue;
71867
71859
  const freshness = await readCheckoutFreshness(deps.dir, target);
71868
71860
  if (freshness === null) continue;
71861
+ const startedAt = Date.now();
71869
71862
  const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
71870
71863
  () => "noted"
71871
71864
  );
@@ -71874,7 +71867,8 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
71874
71867
  runId: spec.runId,
71875
71868
  path: freshness.path,
71876
71869
  state: freshness.state,
71877
- outcome: outcome2
71870
+ outcome: outcome2,
71871
+ ms: Date.now() - startedAt
71878
71872
  });
71879
71873
  }
71880
71874
  return problems;
@@ -71901,10 +71895,10 @@ var VOLUME_ERRORS = /* @__PURE__ */ new Set([
71901
71895
  "ESTALE"
71902
71896
  ]);
71903
71897
  var MESSAGES = {
71904
- missing: "This project folder was moved or removed. Locate it before starting the run.",
71905
- permission: "Alan needs permission to access this project folder.",
71906
- volume: "The drive containing this project is unavailable. Connect it and try again.",
71907
- pinnedMissing: "This run must use exactly this project folder, and it was moved or removed. Restore it or choose another folder.",
71898
+ missing: "This folder was moved or removed. Locate it before starting the run.",
71899
+ permission: "Alan needs permission to access this folder.",
71900
+ volume: "The drive containing this folder is unavailable. Connect it and try again.",
71901
+ pinnedMissing: "This run must use exactly this folder, and it was moved or removed. Restore it or choose another folder.",
71908
71902
  notApproved: "This folder is not one of the workspaces approved on this computer."
71909
71903
  };
71910
71904
  function rejected(rejection2, message2) {
@@ -71935,7 +71929,7 @@ async function inspectReadiness(path4) {
71935
71929
  if (!(await (0, import_promises61.stat)(path4)).isDirectory()) {
71936
71930
  return { ready: false, missing: true, message: MESSAGES.missing };
71937
71931
  }
71938
- await (0, import_promises61.access)(path4, import_node_fs21.constants.R_OK | import_node_fs21.constants.W_OK | import_node_fs21.constants.X_OK);
71932
+ await (0, import_promises61.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71939
71933
  return { ready: true };
71940
71934
  } catch (error62) {
71941
71935
  const code = errnoCode(error62) ?? "";
@@ -71980,7 +71974,7 @@ async function admitDefaultWorkspace(spec, context, skills) {
71980
71974
  const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os10.homedir)());
71981
71975
  try {
71982
71976
  await (0, import_promises61.mkdir)(path4, { recursive: true, mode: 448 });
71983
- await (0, import_promises61.access)(path4, import_node_fs21.constants.R_OK | import_node_fs21.constants.W_OK | import_node_fs21.constants.X_OK);
71977
+ await (0, import_promises61.access)(path4, import_node_fs20.constants.R_OK | import_node_fs20.constants.W_OK | import_node_fs20.constants.X_OK);
71984
71978
  return { kind: "admitted", spec: { ...spec, projectPath: path4 }, skills };
71985
71979
  } catch (error62) {
71986
71980
  const code = errnoCode(error62);
@@ -72229,7 +72223,7 @@ ${added.join("\n")}
72229
72223
 
72230
72224
  // src/run-log/complete.ts
72231
72225
  var import_node_crypto29 = require("crypto");
72232
- var import_node_fs22 = require("fs");
72226
+ var import_node_fs21 = require("fs");
72233
72227
  var import_node_path63 = require("path");
72234
72228
 
72235
72229
  // src/run-log/directory.ts
@@ -72280,23 +72274,23 @@ async function isRunClaimed(runsDir, runId) {
72280
72274
  // src/run-log/complete.ts
72281
72275
  function writeLogFile(path4, dir, text3) {
72282
72276
  const temp = (0, import_node_path63.join)(dir, `.log.${(0, import_node_crypto29.randomUUID)()}.tmp`);
72283
- const fd = (0, import_node_fs22.openSync)(temp, "wx", 384);
72277
+ const fd = (0, import_node_fs21.openSync)(temp, "wx", 384);
72284
72278
  try {
72285
- (0, import_node_fs22.writeSync)(fd, text3);
72286
- (0, import_node_fs22.fsyncSync)(fd);
72279
+ (0, import_node_fs21.writeSync)(fd, text3);
72280
+ (0, import_node_fs21.fsyncSync)(fd);
72287
72281
  } finally {
72288
- (0, import_node_fs22.closeSync)(fd);
72282
+ (0, import_node_fs21.closeSync)(fd);
72289
72283
  }
72290
72284
  try {
72291
- (0, import_node_fs22.renameSync)(temp, path4);
72285
+ (0, import_node_fs21.renameSync)(temp, path4);
72292
72286
  } finally {
72293
- (0, import_node_fs22.rmSync)(temp, { force: true });
72287
+ (0, import_node_fs21.rmSync)(temp, { force: true });
72294
72288
  }
72295
72289
  }
72296
72290
  async function writeCompleteRunLog(runsDir, meta3, records) {
72297
72291
  const paths = runDirectory(runsDir, meta3.runId);
72298
72292
  if (!await isRunClaimed(runsDir, meta3.runId)) {
72299
- (0, import_node_fs22.mkdirSync)(paths.dir, { recursive: true, mode: 448 });
72293
+ (0, import_node_fs21.mkdirSync)(paths.dir, { recursive: true, mode: 448 });
72300
72294
  const text3 = records.map((record2, index) => {
72301
72295
  const line = { seq: index + 1, at: record2.at, update: record2.update };
72302
72296
  return `${JSON.stringify(line)}
@@ -72553,13 +72547,13 @@ function runEnded(input2) {
72553
72547
  var decoder = new TextDecoder();
72554
72548
 
72555
72549
  // src/run-log/writer.ts
72556
- var import_node_fs23 = require("fs");
72550
+ var import_node_fs22 = require("fs");
72557
72551
  var import_node_path65 = require("path");
72558
72552
  init_runtime_v2();
72559
72553
  function lastSeq(fd, size) {
72560
72554
  for (const length of tailWindows(size)) {
72561
72555
  const buffer = Buffer.alloc(length);
72562
- (0, import_node_fs23.readSync)(fd, buffer, 0, length, size - length);
72556
+ (0, import_node_fs22.readSync)(fd, buffer, 0, length, size - length);
72563
72557
  const last = lastLine(buffer.toString("utf8").trimEnd(), length === size);
72564
72558
  if (last === void 0) continue;
72565
72559
  if (last.length === 0) return 0;
@@ -72570,13 +72564,13 @@ function lastSeq(fd, size) {
72570
72564
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
72571
72565
  }
72572
72566
  function openRunLog(path4, clock) {
72573
- (0, import_node_fs23.mkdirSync)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
72574
- const fd = (0, import_node_fs23.openSync)(path4, "a+", 384);
72575
- let size = (0, import_node_fs23.fstatSync)(fd).size;
72567
+ (0, import_node_fs22.mkdirSync)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
72568
+ const fd = (0, import_node_fs22.openSync)(path4, "a+", 384);
72569
+ let size = (0, import_node_fs22.fstatSync)(fd).size;
72576
72570
  let seq = lastSeq(fd, size);
72577
72571
  let dirty = false;
72578
72572
  const sync = () => {
72579
- (0, import_node_fs23.fsyncSync)(fd);
72573
+ (0, import_node_fs22.fsyncSync)(fd);
72580
72574
  dirty = false;
72581
72575
  };
72582
72576
  return {
@@ -72590,7 +72584,7 @@ function openRunLog(path4, clock) {
72590
72584
  };
72591
72585
  const line = Buffer.from(`${JSON.stringify(record2)}
72592
72586
  `, "utf8");
72593
- (0, import_node_fs23.writeSync)(fd, line);
72587
+ (0, import_node_fs22.writeSync)(fd, line);
72594
72588
  size += line.length;
72595
72589
  dirty = true;
72596
72590
  if (isRunLifecycleKind(update.sessionUpdate)) sync();
@@ -72602,7 +72596,7 @@ function openRunLog(path4, clock) {
72602
72596
  },
72603
72597
  [Symbol.dispose]: () => {
72604
72598
  if (dirty) sync();
72605
- (0, import_node_fs23.closeSync)(fd);
72599
+ (0, import_node_fs22.closeSync)(fd);
72606
72600
  }
72607
72601
  };
72608
72602
  }
@@ -73043,7 +73037,7 @@ async function runHolder({
73043
73037
  for (const client of holder.clients) client.end();
73044
73038
  await new Promise((resolve13) => server.close(() => resolve13()));
73045
73039
  await statusWrites;
73046
- (0, import_node_fs24.rmSync)(launch.statusPath, { force: true });
73040
+ (0, import_node_fs23.rmSync)(launch.statusPath, { force: true });
73047
73041
  log.info("holder.suspended", { conversationId: launch.conversationId });
73048
73042
  } catch (_) {
73049
73043
  var _error = _, _hasError = true;
@@ -73053,14 +73047,6 @@ async function runHolder({
73053
73047
  }
73054
73048
 
73055
73049
  // src/sessions/admission.ts
73056
- var GIB = 1024 ** 3;
73057
- var MIN_RUN_BYTES = 1.25 * GIB;
73058
- function memoryAllowsStart(capacity, activeRuns, pendingStarts = 0) {
73059
- if (activeRuns + pendingStarts === 0) return true;
73060
- const headroom = Math.max(512 * 1024 ** 2, capacity.totalBytes * 0.2);
73061
- const slots = Math.max(1, Math.floor((capacity.totalBytes - headroom) / MIN_RUN_BYTES));
73062
- return activeRuns + pendingStarts < slots && capacity.availableBytes >= MIN_RUN_BYTES * (pendingStarts + 1);
73063
- }
73064
73050
  function runOccupancy(held, reserved, exclude = null) {
73065
73051
  const active = new Set(
73066
73052
  held.filter((run2) => run2.state === "running" && run2.runId !== exclude).map((run2) => run2.runId)
@@ -73073,11 +73059,11 @@ function runOccupancy(held, reserved, exclude = null) {
73073
73059
  }
73074
73060
 
73075
73061
  // src/sessions/suspend-policy.ts
73076
- var GIB2 = 1024 ** 3;
73077
- var SESSION_MEMORY_CEILING_BYTES = 2.5 * GIB2;
73062
+ var GIB = 1024 ** 3;
73063
+ var SESSION_MEMORY_CEILING_BYTES = 2.5 * GIB;
73078
73064
  var MEMORY_BUDGET_SHARE = 0.15;
73079
- var MEMORY_BUDGET_MIN_BYTES = GIB2;
73080
- var MEMORY_BUDGET_MAX_BYTES = 4 * GIB2;
73065
+ var MEMORY_BUDGET_MIN_BYTES = GIB;
73066
+ var MEMORY_BUDGET_MAX_BYTES = 4 * GIB;
73081
73067
  function memoryBudgetFor(totalMemoryBytes) {
73082
73068
  const share = Math.round(totalMemoryBytes * MEMORY_BUDGET_SHARE);
73083
73069
  return Math.min(MEMORY_BUDGET_MAX_BYTES, Math.max(MEMORY_BUDGET_MIN_BYTES, share));
@@ -73190,8 +73176,8 @@ async function openSessions(deps) {
73190
73176
  const retiring = /* @__PURE__ */ new Map();
73191
73177
  const legacy = /* @__PURE__ */ new Map();
73192
73178
  const maxActiveRuns = deps.maxActiveRuns ?? DEFAULT_MAX_ACTIVE_RUNS;
73193
- const memoryCapacity = deps.memoryCapacity ?? readMemoryCapacity;
73194
- const suspendPolicy = deps.suspendPolicy ?? defaultSuspendPolicy(memoryCapacity().totalBytes);
73179
+ const totalMemoryBytes = deps.totalMemoryBytes ?? readTotalMemoryBytes;
73180
+ const suspendPolicy = deps.suspendPolicy ?? defaultSuspendPolicy(totalMemoryBytes());
73195
73181
  const admitted = /* @__PURE__ */ new Set();
73196
73182
  let admitting = Promise.resolve();
73197
73183
  const memoryPressure = deps.memoryPressure ?? readMemoryPressure;
@@ -73473,8 +73459,7 @@ async function openSessions(deps) {
73473
73459
  const claim2 = admitting.then(async () => {
73474
73460
  const held = await heldRuns();
73475
73461
  const { active, pending } = runOccupancy(held, [...admitted, ...launched.keys()], runId);
73476
- if (active + pending >= maxActiveRuns || !memoryAllowsStart(memoryCapacity(), active, pending))
73477
- return false;
73462
+ if (active + pending >= maxActiveRuns) return false;
73478
73463
  admitted.add(runId);
73479
73464
  return true;
73480
73465
  });
@@ -73499,20 +73484,12 @@ async function openSessions(deps) {
73499
73484
  return "started";
73500
73485
  }
73501
73486
  if (!await claimCapacity(run2.runId)) {
73502
- const capacity = memoryCapacity();
73503
73487
  const { active, pending } = runOccupancy(
73504
73488
  await heldRuns(),
73505
73489
  [...admitted, ...launched.keys()],
73506
73490
  run2.runId
73507
73491
  );
73508
- log.info("sessions.resource_wait", {
73509
- runId: run2.runId,
73510
- active,
73511
- pending,
73512
- maxActiveRuns,
73513
- totalMiB: Math.round(capacity.totalBytes / 2 ** 20),
73514
- availableMiB: Math.round(capacity.availableBytes / 2 ** 20)
73515
- });
73492
+ log.info("sessions.resource_wait", { runId: run2.runId, active, pending, maxActiveRuns });
73516
73493
  return "waiting";
73517
73494
  }
73518
73495
  try {
@@ -73545,7 +73522,7 @@ async function openSessions(deps) {
73545
73522
  heldRuns,
73546
73523
  hasFreeSlot: async () => {
73547
73524
  const { active, pending } = runOccupancy(await heldRuns(), [...admitted, ...launched.keys()]);
73548
- return active + pending < maxActiveRuns && memoryAllowsStart(memoryCapacity(), active, pending);
73525
+ return active + pending < maxActiveRuns;
73549
73526
  },
73550
73527
  applySuspendPolicy,
73551
73528
  start: (run2) => {
@@ -75813,7 +75790,7 @@ async function runLogout(argv, signal) {
75813
75790
  }
75814
75791
 
75815
75792
  // src/cli/commands/run.ts
75816
- var import_node_fs26 = require("fs");
75793
+ var import_node_fs25 = require("fs");
75817
75794
  var import_node_path82 = require("path");
75818
75795
 
75819
75796
  // src/local-api/app-attachments.ts
@@ -76368,7 +76345,7 @@ var machineFeatureRoutes = [
76368
76345
  ];
76369
76346
 
76370
76347
  // src/local-api/run-log-routes.ts
76371
- var import_node_fs25 = require("fs");
76348
+ var import_node_fs24 = require("fs");
76372
76349
  init_runtime_v2();
76373
76350
  var RUN_ENDED = "_alan/run.ended";
76374
76351
  var decoder2 = new TextDecoder();
@@ -76385,7 +76362,7 @@ async function openWhenWritten(deps, runId, res, signal) {
76385
76362
  const path4 = runDirectory(deps.runsDir, runId).log;
76386
76363
  while (!signal.aborted) {
76387
76364
  const appended = deps.appends.nextAppend(runId, signal);
76388
- if ((0, import_node_fs25.existsSync)(path4) || !await deps.isHeld(runId, signal)) return openReader(res, path4);
76365
+ if ((0, import_node_fs24.existsSync)(path4) || !await deps.isHeld(runId, signal)) return openReader(res, path4);
76389
76366
  await appended;
76390
76367
  }
76391
76368
  return null;
@@ -82733,7 +82710,7 @@ function lockWaitMs(argv) {
82733
82710
  async function openManagedProviders(config2, paths) {
82734
82711
  const providerEnv = readCliEnvironment();
82735
82712
  const bundledNpm = (0, import_node_path82.join)((0, import_node_path82.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
82736
- const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs26.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
82713
+ const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs25.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
82737
82714
  const npmPath = providerToolchain?.node ?? await resolveCommandOnPath("npm", providerEnv, process.platform);
82738
82715
  const npmOptions = npmPath === null || process.platform === "win32" && providerToolchain === null ? null : {
82739
82716
  command: npmPath,