@alan-ai-hq/agent-manager-linux-arm64 0.1.162 → 0.1.163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/alan-agent.cjs CHANGED
@@ -57830,7 +57830,7 @@ var require_websocket_server = __commonJS({
57830
57830
  // package.json
57831
57831
  var package_default = {
57832
57832
  name: "@alan-ai-hq/agent-manager",
57833
- version: "0.1.162",
57833
+ version: "0.1.163",
57834
57834
  private: true,
57835
57835
  type: "module",
57836
57836
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -60291,6 +60291,20 @@ async function checkOne(path4, deps, signal) {
60291
60291
  );
60292
60292
  return fetched.exitCode === 0 ? write({ state: "behind", path: path4, snapshot, tip, fetched: true }) : write({ state: "failed", path: path4, snapshot, reason: gitError(fetched, "fetch") });
60293
60293
  }
60294
+ async function currentBranch(git, cwd, signal) {
60295
+ const output2 = await git.run(
60296
+ { cwd, args: ["symbolic-ref", "--quiet", "--short", "HEAD"], readOnly: true },
60297
+ signal
60298
+ );
60299
+ return output2.exitCode === 0 ? output2.stdout.trim() || null : null;
60300
+ }
60301
+ async function moveSnapshotTo(git, cwd, snapshot, tip, signal) {
60302
+ const run2 = (args) => git.run({ cwd, args }, signal);
60303
+ if ((await run2(["switch", "--quiet", "--detach", tip])).exitCode !== 0) return false;
60304
+ const moved = await run2(["update-ref", `refs/heads/${snapshot.branch}`, tip, snapshot.head]);
60305
+ const back = await run2(["switch", "--quiet", snapshot.branch]);
60306
+ return moved.exitCode === 0 && back.exitCode === 0;
60307
+ }
60294
60308
  async function isCheckout(path4) {
60295
60309
  return (0, import_promises11.stat)((0, import_node_path7.join)(path4, ".git")).then(
60296
60310
  () => true,
@@ -61310,7 +61324,6 @@ function runtimePaths(stateDir) {
61310
61324
 
61311
61325
  // src/platform/process-memory.ts
61312
61326
  var import_node_child_process4 = require("child_process");
61313
- var import_node_fs7 = require("fs");
61314
61327
  var import_promises16 = require("fs/promises");
61315
61328
  var import_node_os2 = require("os");
61316
61329
  var import_node_util3 = require("util");
@@ -61378,52 +61391,9 @@ function readMemoryPressure() {
61378
61391
  if (process.platform === "linux") return linuxPressure();
61379
61392
  return Promise.resolve("normal");
61380
61393
  }
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() {
61394
+ function readTotalMemoryBytes() {
61421
61395
  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 };
61396
+ return constrained > 0 ? Math.min((0, import_node_os2.totalmem)(), constrained) : (0, import_node_os2.totalmem)();
61427
61397
  }
61428
61398
  async function processMemoryRows() {
61429
61399
  if (process.platform === "win32") {
@@ -61903,7 +61873,7 @@ var import_promises20 = require("fs/promises");
61903
61873
  var import_node_path17 = require("path");
61904
61874
 
61905
61875
  // src/platform/service/windows-service.ts
61906
- var import_node_fs8 = require("fs");
61876
+ var import_node_fs7 = require("fs");
61907
61877
  var import_promises19 = require("fs/promises");
61908
61878
  var import_node_path16 = require("path");
61909
61879
 
@@ -62133,7 +62103,7 @@ function windowsManager(host, profile) {
62133
62103
  name: files.runValue,
62134
62104
  definitionPath: files.config,
62135
62105
  install: async (spec, { restart }) => {
62136
- if (process.platform === "win32" && !(0, import_node_fs8.existsSync)(files.helper)) {
62106
+ if (process.platform === "win32" && !(0, import_node_fs7.existsSync)(files.helper)) {
62137
62107
  throw new RuntimeFault("io_failed", `Windows helper is missing: ${files.helper}`);
62138
62108
  }
62139
62109
  await (0, import_promises19.mkdir)((0, import_node_path16.dirname)(spec.logPath), { recursive: true });
@@ -62828,7 +62798,7 @@ function systemAssertionSpawner(log) {
62828
62798
  // src/platform/spawn-detached.ts
62829
62799
  var import_node_child_process8 = require("child_process");
62830
62800
  var import_node_crypto12 = require("crypto");
62831
- var import_node_fs9 = require("fs");
62801
+ var import_node_fs8 = require("fs");
62832
62802
  var import_node_path21 = require("path");
62833
62803
  var WINDOWS_UNSAFE_ENV = "NODE_PENDING_PIPE_INSTANCES";
62834
62804
  var SYSTEMD_RUN = "systemd-run";
@@ -62883,8 +62853,8 @@ function isolatedCommand(request2, isolation) {
62883
62853
  };
62884
62854
  }
62885
62855
  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);
62856
+ (0, import_node_fs8.mkdirSync)((0, import_node_path21.dirname)(request2.outputPath), { recursive: true, mode: 448 });
62857
+ const output2 = (0, import_node_fs8.openSync)(request2.outputPath, "a", 384);
62888
62858
  const { command, args } = isolatedCommand(request2, isolation);
62889
62859
  try {
62890
62860
  const child = (0, import_node_child_process8.spawn)(command, args, {
@@ -62900,7 +62870,7 @@ function spawnDetached(request2, isolation) {
62900
62870
  child.unref();
62901
62871
  return { pid: child.pid };
62902
62872
  } finally {
62903
- (0, import_node_fs9.closeSync)(output2);
62873
+ (0, import_node_fs8.closeSync)(output2);
62904
62874
  }
62905
62875
  }
62906
62876
 
@@ -62940,7 +62910,7 @@ function createUpdateGate(deps) {
62940
62910
 
62941
62911
  // src/platform/wake-clock.ts
62942
62912
  var import_node_child_process9 = require("child_process");
62943
- var import_node_fs10 = require("fs");
62913
+ var import_node_fs9 = require("fs");
62944
62914
  var import_node_readline = require("readline");
62945
62915
  var PTP_DEVICE = "/dev/ptp0";
62946
62916
  var RESPAWN_BASE_MS = 1e3;
@@ -63024,7 +62994,7 @@ function systemWakeClockSpawner(log) {
63024
62994
  function startWakeClock(options) {
63025
62995
  const { clock, log } = options;
63026
62996
  const platform3 = options.platform ?? process.platform;
63027
- const hasPtpDevice = options.hasPtpDevice ?? (() => (0, import_node_fs10.existsSync)(PTP_DEVICE));
62997
+ const hasPtpDevice = options.hasPtpDevice ?? (() => (0, import_node_fs9.existsSync)(PTP_DEVICE));
63028
62998
  if (platform3 !== "linux" || !hasPtpDevice()) return { [Symbol.dispose]: () => {
63029
62999
  } };
63030
63000
  const spawner = options.spawner ?? systemWakeClockSpawner(log);
@@ -65158,7 +65128,7 @@ function fingerprintWholeText(fingerprint) {
65158
65128
  }
65159
65129
 
65160
65130
  // src/capabilities/native-ingest/hook-config.ts
65161
- var import_node_fs11 = require("fs");
65131
+ var import_node_fs10 = require("fs");
65162
65132
  var import_node_path28 = require("path");
65163
65133
 
65164
65134
  // src/capabilities/native-ingest/provider-paths.ts
@@ -65236,9 +65206,9 @@ function hookHandler(provider4, event, options) {
65236
65206
  return { type: "command", command: posixCommand(argv, environment), timeout: 5 };
65237
65207
  }
65238
65208
  function readSettings(path4, backupWhenMalformed, now) {
65239
- if (!(0, import_node_fs11.existsSync)(path4)) return {};
65209
+ if (!(0, import_node_fs10.existsSync)(path4)) return {};
65240
65210
  try {
65241
- const value2 = JSON.parse((0, import_node_fs11.readFileSync)(path4, "utf8"));
65211
+ const value2 = JSON.parse((0, import_node_fs10.readFileSync)(path4, "utf8"));
65242
65212
  if (!isRecord4(value2)) throw new Error("settings root must be an object");
65243
65213
  if (value2.hooks !== void 0 && !isRecord4(value2.hooks)) {
65244
65214
  throw new Error("settings `hooks` must be an object");
@@ -65248,7 +65218,7 @@ function readSettings(path4, backupWhenMalformed, now) {
65248
65218
  const reason = error62 instanceof Error ? error62.message : String(error62);
65249
65219
  if (!backupWhenMalformed) throw new Error(`${path4} is malformed: ${reason}`);
65250
65220
  const backup = `${path4}.malformed-${now}.bak`;
65251
- (0, import_node_fs11.copyFileSync)(path4, backup);
65221
+ (0, import_node_fs10.copyFileSync)(path4, backup);
65252
65222
  throw new Error(`${path4} is malformed and was copied to ${backup}: ${reason}`);
65253
65223
  }
65254
65224
  }
@@ -65256,14 +65226,14 @@ function hooksOf(settings2) {
65256
65226
  return isRecord4(settings2.hooks) ? settings2.hooks : {};
65257
65227
  }
65258
65228
  function writeSettings(path4, settings2) {
65259
- (0, import_node_fs11.mkdirSync)((0, import_node_path28.dirname)(path4), { recursive: true, mode: 448 });
65229
+ (0, import_node_fs10.mkdirSync)((0, import_node_path28.dirname)(path4), { recursive: true, mode: 448 });
65260
65230
  const temporary = `${path4}.${process.pid}.tmp`;
65261
65231
  try {
65262
- (0, import_node_fs11.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
65232
+ (0, import_node_fs10.writeFileSync)(temporary, `${JSON.stringify(settings2, null, 2)}
65263
65233
  `, { mode: 384 });
65264
- (0, import_node_fs11.renameSync)(temporary, path4);
65234
+ (0, import_node_fs10.renameSync)(temporary, path4);
65265
65235
  } finally {
65266
- (0, import_node_fs11.rmSync)(temporary, { force: true });
65236
+ (0, import_node_fs10.rmSync)(temporary, { force: true });
65267
65237
  }
65268
65238
  }
65269
65239
  function isIngestionHandler(handler) {
@@ -65308,7 +65278,7 @@ function installIngestionHooks(provider4, options, now) {
65308
65278
  }
65309
65279
  function removeIngestionHooks(provider4, where, now) {
65310
65280
  const path4 = providerHookSettingsPath(provider4, where);
65311
- if (!(0, import_node_fs11.existsSync)(path4)) return { provider: provider4, path: path4, changed: false };
65281
+ if (!(0, import_node_fs10.existsSync)(path4)) return { provider: provider4, path: path4, changed: false };
65312
65282
  const settings2 = readSettings(path4, true, now);
65313
65283
  const hooks = hooksOf(settings2);
65314
65284
  const nextHooks = {};
@@ -65345,7 +65315,7 @@ function ingestionHookStatus(provider4, options) {
65345
65315
  }
65346
65316
 
65347
65317
  // src/capabilities/native-ingest/hook-input.ts
65348
- var import_node_fs12 = require("fs");
65318
+ var import_node_fs11 = require("fs");
65349
65319
  var import_node_path29 = require("path");
65350
65320
  var ALAN_MANAGED_SESSION_ENV = "ALAN_MANAGED_SESSION";
65351
65321
  var MAX_HOOK_STDIN_BYTES = 256 * 1024 * 1024;
@@ -65445,10 +65415,10 @@ function hookPayload(input2) {
65445
65415
  }
65446
65416
  function realpathOrSelf(path4) {
65447
65417
  try {
65448
- return (0, import_node_fs12.realpathSync)(path4);
65418
+ return (0, import_node_fs11.realpathSync)(path4);
65449
65419
  } catch {
65450
65420
  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));
65421
+ return (0, import_node_path29.join)((0, import_node_fs11.realpathSync)((0, import_node_path29.dirname)(path4)), (0, import_node_path29.basename)(path4));
65452
65422
  } catch {
65453
65423
  return path4;
65454
65424
  }
@@ -65479,7 +65449,7 @@ function parseHookSignal(input2) {
65479
65449
  }
65480
65450
 
65481
65451
  // src/capabilities/native-ingest/ingest.ts
65482
- var import_node_fs13 = require("fs");
65452
+ var import_node_fs12 = require("fs");
65483
65453
 
65484
65454
  // ../shared/dist/types/native-agent-session.js
65485
65455
  var nativeAgentProviderBackendKinds = {
@@ -66249,7 +66219,7 @@ function workerKey(provider4, externalSessionId) {
66249
66219
  return `${provider4}\0${externalSessionId}`;
66250
66220
  }
66251
66221
  function holdFor(entry) {
66252
- const stats = (0, import_node_fs13.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66222
+ const stats = (0, import_node_fs12.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66253
66223
  if (!stats) return [];
66254
66224
  return [
66255
66225
  {
@@ -66450,7 +66420,7 @@ async function startNativeIngest(deps) {
66450
66420
  return "accepted";
66451
66421
  };
66452
66422
  const hasUnreadBytes = (entry, now) => {
66453
- const stats = (0, import_node_fs13.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66423
+ const stats = (0, import_node_fs12.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66454
66424
  if (!stats || now - Number(stats.mtimeMs) > timing.sweepRecencyMs) return false;
66455
66425
  const replaced = String(stats.dev) !== entry.device || String(stats.ino) !== entry.inode;
66456
66426
  return replaced || Number(stats.size) > entry.cursor.offset;
@@ -66494,7 +66464,7 @@ async function startNativeIngest(deps) {
66494
66464
  const recordAlanRun = async (hold, runId) => {
66495
66465
  const entry = store.get(hold.provider, hold.externalSessionId);
66496
66466
  if (!entry || entry.dead) return;
66497
- const stats = (0, import_node_fs13.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66467
+ const stats = (0, import_node_fs12.statSync)(entry.transcriptPath, { bigint: true, throwIfNoEntry: false });
66498
66468
  if (!stats) return;
66499
66469
  const identity = { device: String(stats.dev), inode: String(stats.ino) };
66500
66470
  const size = Number(stats.size);
@@ -66568,7 +66538,7 @@ async function startNativeIngest(deps) {
66568
66538
  init_alan_code();
66569
66539
 
66570
66540
  // src/capabilities/providers/commands.ts
66571
- var import_node_fs14 = require("fs");
66541
+ var import_node_fs13 = require("fs");
66572
66542
  var import_promises35 = require("fs/promises");
66573
66543
  var import_node_path32 = require("path");
66574
66544
  var PROVIDER_COMMANDS = [
@@ -66606,7 +66576,7 @@ function pathDelimiter(platform3) {
66606
66576
  async function isRunnable(path4, platform3) {
66607
66577
  try {
66608
66578
  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);
66579
+ if (platform3 !== "win32") await (0, import_promises35.access)(path4, import_node_fs13.constants.X_OK);
66610
66580
  return true;
66611
66581
  } catch {
66612
66582
  return false;
@@ -66789,7 +66759,7 @@ init_runtime_v2();
66789
66759
 
66790
66760
  // src/capabilities/providers/account-label.ts
66791
66761
  var import_node_child_process12 = require("child_process");
66792
- var import_node_fs15 = require("fs");
66762
+ var import_node_fs14 = require("fs");
66793
66763
  var import_node_path33 = require("path");
66794
66764
  var import_node_url3 = require("url");
66795
66765
  var ACCOUNT_TIMEOUT_MS = 2e4;
@@ -66892,7 +66862,7 @@ async function claudeLabel(executable, env) {
66892
66862
  const childEnv = { ...env };
66893
66863
  delete childEnv.FORCE_CODE_TERMINAL;
66894
66864
  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";
66865
+ const sdkSpecifier = (0, import_node_fs14.existsSync)(bundledSdk) ? (0, import_node_url3.pathToFileURL)(bundledSdk).href : "@anthropic-ai/claude-agent-sdk";
66896
66866
  const { query } = await import(sdkSpecifier);
66897
66867
  const session = query({
66898
66868
  prompt: idlePrompt(abort.signal),
@@ -67302,7 +67272,7 @@ var import_node_path37 = require("path");
67302
67272
  // ../shared/dist/node/shell-environment.js
67303
67273
  var import_node_child_process13 = require("child_process");
67304
67274
  var import_node_crypto16 = require("crypto");
67305
- var import_node_fs17 = require("fs");
67275
+ var import_node_fs16 = require("fs");
67306
67276
  var import_node_os6 = require("os");
67307
67277
  var import_node_path36 = require("path");
67308
67278
 
@@ -67311,7 +67281,7 @@ var import_node_os5 = require("os");
67311
67281
  var import_node_path35 = require("path");
67312
67282
 
67313
67283
  // ../shared/dist/node/version-manager-paths.js
67314
- var import_node_fs16 = require("fs");
67284
+ var import_node_fs15 = require("fs");
67315
67285
  var import_node_path34 = require("path");
67316
67286
  function compareNodeVersionsDesc(a, b) {
67317
67287
  const parse7 = (value2) => value2.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
@@ -67326,19 +67296,19 @@ function compareNodeVersionsDesc(a, b) {
67326
67296
  }
67327
67297
  function resolveNvmDefaultBin(home) {
67328
67298
  const versionsDir = (0, import_node_path34.join)(home, ".nvm", "versions", "node");
67329
- if (!(0, import_node_fs16.existsSync)(versionsDir))
67299
+ if (!(0, import_node_fs15.existsSync)(versionsDir))
67330
67300
  return null;
67331
67301
  let alias = null;
67332
67302
  try {
67333
67303
  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();
67304
+ if ((0, import_node_fs15.existsSync)(aliasFile))
67305
+ alias = (0, import_node_fs15.readFileSync)(aliasFile, "utf8").trim();
67336
67306
  } catch {
67337
67307
  alias = null;
67338
67308
  }
67339
67309
  let installed;
67340
67310
  try {
67341
- installed = (0, import_node_fs16.readdirSync)(versionsDir).filter((entry) => entry.startsWith("v"));
67311
+ installed = (0, import_node_fs15.readdirSync)(versionsDir).filter((entry) => entry.startsWith("v"));
67342
67312
  } catch {
67343
67313
  return null;
67344
67314
  }
@@ -67349,7 +67319,7 @@ function resolveNvmDefaultBin(home) {
67349
67319
  if (!chosen)
67350
67320
  return null;
67351
67321
  const bin = (0, import_node_path34.join)(versionsDir, chosen, "bin");
67352
- return (0, import_node_fs16.existsSync)(bin) ? bin : null;
67322
+ return (0, import_node_fs15.existsSync)(bin) ? bin : null;
67353
67323
  }
67354
67324
  function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
67355
67325
  if (platform3 === "win32")
@@ -67368,7 +67338,7 @@ function resolveVersionManagerBinDirs(home, platform3 = process.platform) {
67368
67338
  if (!dir || seen.has(dir))
67369
67339
  continue;
67370
67340
  seen.add(dir);
67371
- if ((0, import_node_fs16.existsSync)(dir))
67341
+ if ((0, import_node_fs15.existsSync)(dir))
67372
67342
  resolved.push(dir);
67373
67343
  }
67374
67344
  return resolved;
@@ -67410,7 +67380,7 @@ function promoteUserBinDirs(path4, home, versionManagerDirs) {
67410
67380
  // ../shared/dist/node/shell-environment.js
67411
67381
  function isExecutableFile(path4) {
67412
67382
  try {
67413
- (0, import_node_fs17.accessSync)(path4, import_node_fs17.constants.X_OK);
67383
+ (0, import_node_fs16.accessSync)(path4, import_node_fs16.constants.X_OK);
67414
67384
  return true;
67415
67385
  } catch {
67416
67386
  return false;
@@ -69320,7 +69290,7 @@ async function publishLocalSkill(options) {
69320
69290
 
69321
69291
  // src/capabilities/skills/native-index.ts
69322
69292
  var import_node_crypto23 = require("crypto");
69323
- var import_node_fs18 = require("fs");
69293
+ var import_node_fs17 = require("fs");
69324
69294
  var import_promises45 = require("fs/promises");
69325
69295
  var import_node_path45 = require("path");
69326
69296
  var ALAN_SKILLS_PLUGIN_NAME = "alan";
@@ -69471,7 +69441,7 @@ async function reconcileNativeIndex(layout, installed, options) {
69471
69441
  };
69472
69442
  }
69473
69443
  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;
69444
+ 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
69445
  }
69476
69446
 
69477
69447
  // src/capabilities/skills/sync.ts
@@ -71360,10 +71330,10 @@ async function reapLeftoverEngines(path4, options) {
71360
71330
  }
71361
71331
 
71362
71332
  // src/holder/launch-command.ts
71363
- var import_node_fs19 = require("fs");
71333
+ var import_node_fs18 = require("fs");
71364
71334
  var import_node_path53 = require("path");
71365
71335
  var HOLDER_BUNDLE = "alan-holder.cjs";
71366
- function holderArguments(runtimeArgs, nodeFlags, exists6 = import_node_fs19.existsSync) {
71336
+ function holderArguments(runtimeArgs, nodeFlags, exists6 = import_node_fs18.existsSync) {
71367
71337
  const bundle = runtimeArgs.at(-1);
71368
71338
  const lean = bundle === void 0 ? void 0 : (0, import_node_path53.join)((0, import_node_path53.dirname)(bundle), HOLDER_BUNDLE);
71369
71339
  const script = lean !== void 0 && exists6(lean) ? [...runtimeArgs.slice(0, -1), lean] : runtimeArgs;
@@ -71502,20 +71472,20 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
71502
71472
 
71503
71473
  // src/holder/serve.ts
71504
71474
  var import_node_crypto30 = require("crypto");
71505
- var import_node_fs24 = require("fs");
71475
+ var import_node_fs23 = require("fs");
71506
71476
  var import_node_net3 = require("net");
71507
71477
  var import_node_path66 = require("path");
71508
71478
  init_runtime_v2();
71509
71479
 
71510
71480
  // src/holder/admission.ts
71511
- var import_node_fs21 = require("fs");
71481
+ var import_node_fs20 = require("fs");
71512
71482
  var import_promises61 = require("fs/promises");
71513
71483
  var import_node_os10 = require("os");
71514
71484
  var import_node_path60 = require("path");
71515
71485
  init_constants();
71516
71486
 
71517
71487
  // ../shared/dist/node/local-workspace.js
71518
- var import_node_fs20 = require("fs");
71488
+ var import_node_fs19 = require("fs");
71519
71489
  var import_node_os9 = require("os");
71520
71490
  var import_node_path55 = require("path");
71521
71491
  function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os9.homedir)()) {
@@ -71743,18 +71713,16 @@ async function switchTo(checkout, current, operationId, deps, signal) {
71743
71713
  async function applyRequestedCheckout(checkout, spec, deps, signal) {
71744
71714
  try {
71745
71715
  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");
71716
+ const branch = await currentBranch(deps.git, checkout.path, signal);
71717
+ if (branch === checkout.branch) return { kind: "on_branch" };
71750
71718
  if (!await claimFirstLease(deps.dir, checkout.path)) {
71751
71719
  return notSwitched(
71752
71720
  checkout,
71753
- status.branch,
71721
+ branch,
71754
71722
  "an earlier conversation on this machine already uses it"
71755
71723
  );
71756
71724
  }
71757
- return await switchTo(checkout, status.branch, `checkout-${spec.runId}`, deps, signal);
71725
+ return await switchTo(checkout, branch, `checkout-${spec.runId}`, deps, signal);
71758
71726
  } catch (error62) {
71759
71727
  return noted(
71760
71728
  `could not be put on ${checkout.branch}, the branch picked for this chat`,
@@ -71785,15 +71753,13 @@ async function fastForward(freshness, operationId, deps, signal) {
71785
71753
  const attempt2 = await deps.locks.tryExclusive(snapshot.commonDir, operationId);
71786
71754
  if (attempt2.kind === "busy") return false;
71787
71755
  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;
71756
+ const head = await deps.git.run(
71757
+ { cwd, args: ["rev-parse", "--verify", "HEAD"], readOnly: true },
71758
+ signal
71759
+ );
71760
+ if (head.exitCode !== 0 || head.stdout.trim() !== snapshot.head) return false;
71761
+ if (await currentBranch(deps.git, cwd, signal) !== snapshot.branch) return false;
71762
+ return moveSnapshotTo(deps.git, cwd, snapshot, tip, signal);
71797
71763
  } catch (_) {
71798
71764
  var _error = _, _hasError = true;
71799
71765
  } finally {
@@ -71844,13 +71810,15 @@ async function applyRequestedCheckouts(spec, deps, signal) {
71844
71810
  const settled2 = /* @__PURE__ */ new Set();
71845
71811
  const problems = [];
71846
71812
  for (const checkout of requestedCheckoutsOf(spec, deps.log)) {
71813
+ const startedAt = Date.now();
71847
71814
  const outcome2 = await applyRequestedCheckout(checkout, spec, deps, signal);
71848
71815
  deps.log.info("workspace.requested_checkout", {
71849
71816
  runId: spec.runId,
71850
71817
  path: checkout.path,
71851
71818
  branch: checkout.branch,
71852
71819
  outcome: outcome2.kind,
71853
- ...outcome2.kind === "moved" ? { how: outcome2.how } : {}
71820
+ ...outcome2.kind === "moved" ? { how: outcome2.how } : {},
71821
+ ms: Date.now() - startedAt
71854
71822
  });
71855
71823
  if (outcome2.kind === "on_branch") continue;
71856
71824
  settled2.add((0, import_node_path59.resolve)(checkout.path));
@@ -71866,6 +71834,7 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
71866
71834
  if (settled2.has((0, import_node_path59.resolve)(target))) continue;
71867
71835
  const freshness = await readCheckoutFreshness(deps.dir, target);
71868
71836
  if (freshness === null) continue;
71837
+ const startedAt = Date.now();
71869
71838
  const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
71870
71839
  () => "noted"
71871
71840
  );
@@ -71874,7 +71843,8 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
71874
71843
  runId: spec.runId,
71875
71844
  path: freshness.path,
71876
71845
  state: freshness.state,
71877
- outcome: outcome2
71846
+ outcome: outcome2,
71847
+ ms: Date.now() - startedAt
71878
71848
  });
71879
71849
  }
71880
71850
  return problems;
@@ -71935,7 +71905,7 @@ async function inspectReadiness(path4) {
71935
71905
  if (!(await (0, import_promises61.stat)(path4)).isDirectory()) {
71936
71906
  return { ready: false, missing: true, message: MESSAGES.missing };
71937
71907
  }
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);
71908
+ 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
71909
  return { ready: true };
71940
71910
  } catch (error62) {
71941
71911
  const code = errnoCode(error62) ?? "";
@@ -71980,7 +71950,7 @@ async function admitDefaultWorkspace(spec, context, skills) {
71980
71950
  const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os10.homedir)());
71981
71951
  try {
71982
71952
  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);
71953
+ 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
71954
  return { kind: "admitted", spec: { ...spec, projectPath: path4 }, skills };
71985
71955
  } catch (error62) {
71986
71956
  const code = errnoCode(error62);
@@ -72229,7 +72199,7 @@ ${added.join("\n")}
72229
72199
 
72230
72200
  // src/run-log/complete.ts
72231
72201
  var import_node_crypto29 = require("crypto");
72232
- var import_node_fs22 = require("fs");
72202
+ var import_node_fs21 = require("fs");
72233
72203
  var import_node_path63 = require("path");
72234
72204
 
72235
72205
  // src/run-log/directory.ts
@@ -72280,23 +72250,23 @@ async function isRunClaimed(runsDir, runId) {
72280
72250
  // src/run-log/complete.ts
72281
72251
  function writeLogFile(path4, dir, text3) {
72282
72252
  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);
72253
+ const fd = (0, import_node_fs21.openSync)(temp, "wx", 384);
72284
72254
  try {
72285
- (0, import_node_fs22.writeSync)(fd, text3);
72286
- (0, import_node_fs22.fsyncSync)(fd);
72255
+ (0, import_node_fs21.writeSync)(fd, text3);
72256
+ (0, import_node_fs21.fsyncSync)(fd);
72287
72257
  } finally {
72288
- (0, import_node_fs22.closeSync)(fd);
72258
+ (0, import_node_fs21.closeSync)(fd);
72289
72259
  }
72290
72260
  try {
72291
- (0, import_node_fs22.renameSync)(temp, path4);
72261
+ (0, import_node_fs21.renameSync)(temp, path4);
72292
72262
  } finally {
72293
- (0, import_node_fs22.rmSync)(temp, { force: true });
72263
+ (0, import_node_fs21.rmSync)(temp, { force: true });
72294
72264
  }
72295
72265
  }
72296
72266
  async function writeCompleteRunLog(runsDir, meta3, records) {
72297
72267
  const paths = runDirectory(runsDir, meta3.runId);
72298
72268
  if (!await isRunClaimed(runsDir, meta3.runId)) {
72299
- (0, import_node_fs22.mkdirSync)(paths.dir, { recursive: true, mode: 448 });
72269
+ (0, import_node_fs21.mkdirSync)(paths.dir, { recursive: true, mode: 448 });
72300
72270
  const text3 = records.map((record2, index) => {
72301
72271
  const line = { seq: index + 1, at: record2.at, update: record2.update };
72302
72272
  return `${JSON.stringify(line)}
@@ -72553,13 +72523,13 @@ function runEnded(input2) {
72553
72523
  var decoder = new TextDecoder();
72554
72524
 
72555
72525
  // src/run-log/writer.ts
72556
- var import_node_fs23 = require("fs");
72526
+ var import_node_fs22 = require("fs");
72557
72527
  var import_node_path65 = require("path");
72558
72528
  init_runtime_v2();
72559
72529
  function lastSeq(fd, size) {
72560
72530
  for (const length of tailWindows(size)) {
72561
72531
  const buffer = Buffer.alloc(length);
72562
- (0, import_node_fs23.readSync)(fd, buffer, 0, length, size - length);
72532
+ (0, import_node_fs22.readSync)(fd, buffer, 0, length, size - length);
72563
72533
  const last = lastLine(buffer.toString("utf8").trimEnd(), length === size);
72564
72534
  if (last === void 0) continue;
72565
72535
  if (last.length === 0) return 0;
@@ -72570,13 +72540,13 @@ function lastSeq(fd, size) {
72570
72540
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
72571
72541
  }
72572
72542
  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;
72543
+ (0, import_node_fs22.mkdirSync)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
72544
+ const fd = (0, import_node_fs22.openSync)(path4, "a+", 384);
72545
+ let size = (0, import_node_fs22.fstatSync)(fd).size;
72576
72546
  let seq = lastSeq(fd, size);
72577
72547
  let dirty = false;
72578
72548
  const sync = () => {
72579
- (0, import_node_fs23.fsyncSync)(fd);
72549
+ (0, import_node_fs22.fsyncSync)(fd);
72580
72550
  dirty = false;
72581
72551
  };
72582
72552
  return {
@@ -72590,7 +72560,7 @@ function openRunLog(path4, clock) {
72590
72560
  };
72591
72561
  const line = Buffer.from(`${JSON.stringify(record2)}
72592
72562
  `, "utf8");
72593
- (0, import_node_fs23.writeSync)(fd, line);
72563
+ (0, import_node_fs22.writeSync)(fd, line);
72594
72564
  size += line.length;
72595
72565
  dirty = true;
72596
72566
  if (isRunLifecycleKind(update.sessionUpdate)) sync();
@@ -72602,7 +72572,7 @@ function openRunLog(path4, clock) {
72602
72572
  },
72603
72573
  [Symbol.dispose]: () => {
72604
72574
  if (dirty) sync();
72605
- (0, import_node_fs23.closeSync)(fd);
72575
+ (0, import_node_fs22.closeSync)(fd);
72606
72576
  }
72607
72577
  };
72608
72578
  }
@@ -73043,7 +73013,7 @@ async function runHolder({
73043
73013
  for (const client of holder.clients) client.end();
73044
73014
  await new Promise((resolve13) => server.close(() => resolve13()));
73045
73015
  await statusWrites;
73046
- (0, import_node_fs24.rmSync)(launch.statusPath, { force: true });
73016
+ (0, import_node_fs23.rmSync)(launch.statusPath, { force: true });
73047
73017
  log.info("holder.suspended", { conversationId: launch.conversationId });
73048
73018
  } catch (_) {
73049
73019
  var _error = _, _hasError = true;
@@ -73053,14 +73023,6 @@ async function runHolder({
73053
73023
  }
73054
73024
 
73055
73025
  // 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
73026
  function runOccupancy(held, reserved, exclude = null) {
73065
73027
  const active = new Set(
73066
73028
  held.filter((run2) => run2.state === "running" && run2.runId !== exclude).map((run2) => run2.runId)
@@ -73073,11 +73035,11 @@ function runOccupancy(held, reserved, exclude = null) {
73073
73035
  }
73074
73036
 
73075
73037
  // src/sessions/suspend-policy.ts
73076
- var GIB2 = 1024 ** 3;
73077
- var SESSION_MEMORY_CEILING_BYTES = 2.5 * GIB2;
73038
+ var GIB = 1024 ** 3;
73039
+ var SESSION_MEMORY_CEILING_BYTES = 2.5 * GIB;
73078
73040
  var MEMORY_BUDGET_SHARE = 0.15;
73079
- var MEMORY_BUDGET_MIN_BYTES = GIB2;
73080
- var MEMORY_BUDGET_MAX_BYTES = 4 * GIB2;
73041
+ var MEMORY_BUDGET_MIN_BYTES = GIB;
73042
+ var MEMORY_BUDGET_MAX_BYTES = 4 * GIB;
73081
73043
  function memoryBudgetFor(totalMemoryBytes) {
73082
73044
  const share = Math.round(totalMemoryBytes * MEMORY_BUDGET_SHARE);
73083
73045
  return Math.min(MEMORY_BUDGET_MAX_BYTES, Math.max(MEMORY_BUDGET_MIN_BYTES, share));
@@ -73190,8 +73152,8 @@ async function openSessions(deps) {
73190
73152
  const retiring = /* @__PURE__ */ new Map();
73191
73153
  const legacy = /* @__PURE__ */ new Map();
73192
73154
  const maxActiveRuns = deps.maxActiveRuns ?? DEFAULT_MAX_ACTIVE_RUNS;
73193
- const memoryCapacity = deps.memoryCapacity ?? readMemoryCapacity;
73194
- const suspendPolicy = deps.suspendPolicy ?? defaultSuspendPolicy(memoryCapacity().totalBytes);
73155
+ const totalMemoryBytes = deps.totalMemoryBytes ?? readTotalMemoryBytes;
73156
+ const suspendPolicy = deps.suspendPolicy ?? defaultSuspendPolicy(totalMemoryBytes());
73195
73157
  const admitted = /* @__PURE__ */ new Set();
73196
73158
  let admitting = Promise.resolve();
73197
73159
  const memoryPressure = deps.memoryPressure ?? readMemoryPressure;
@@ -73473,8 +73435,7 @@ async function openSessions(deps) {
73473
73435
  const claim2 = admitting.then(async () => {
73474
73436
  const held = await heldRuns();
73475
73437
  const { active, pending } = runOccupancy(held, [...admitted, ...launched.keys()], runId);
73476
- if (active + pending >= maxActiveRuns || !memoryAllowsStart(memoryCapacity(), active, pending))
73477
- return false;
73438
+ if (active + pending >= maxActiveRuns) return false;
73478
73439
  admitted.add(runId);
73479
73440
  return true;
73480
73441
  });
@@ -73499,20 +73460,12 @@ async function openSessions(deps) {
73499
73460
  return "started";
73500
73461
  }
73501
73462
  if (!await claimCapacity(run2.runId)) {
73502
- const capacity = memoryCapacity();
73503
73463
  const { active, pending } = runOccupancy(
73504
73464
  await heldRuns(),
73505
73465
  [...admitted, ...launched.keys()],
73506
73466
  run2.runId
73507
73467
  );
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
- });
73468
+ log.info("sessions.resource_wait", { runId: run2.runId, active, pending, maxActiveRuns });
73516
73469
  return "waiting";
73517
73470
  }
73518
73471
  try {
@@ -73545,7 +73498,7 @@ async function openSessions(deps) {
73545
73498
  heldRuns,
73546
73499
  hasFreeSlot: async () => {
73547
73500
  const { active, pending } = runOccupancy(await heldRuns(), [...admitted, ...launched.keys()]);
73548
- return active + pending < maxActiveRuns && memoryAllowsStart(memoryCapacity(), active, pending);
73501
+ return active + pending < maxActiveRuns;
73549
73502
  },
73550
73503
  applySuspendPolicy,
73551
73504
  start: (run2) => {
@@ -75813,7 +75766,7 @@ async function runLogout(argv, signal) {
75813
75766
  }
75814
75767
 
75815
75768
  // src/cli/commands/run.ts
75816
- var import_node_fs26 = require("fs");
75769
+ var import_node_fs25 = require("fs");
75817
75770
  var import_node_path82 = require("path");
75818
75771
 
75819
75772
  // src/local-api/app-attachments.ts
@@ -76368,7 +76321,7 @@ var machineFeatureRoutes = [
76368
76321
  ];
76369
76322
 
76370
76323
  // src/local-api/run-log-routes.ts
76371
- var import_node_fs25 = require("fs");
76324
+ var import_node_fs24 = require("fs");
76372
76325
  init_runtime_v2();
76373
76326
  var RUN_ENDED = "_alan/run.ended";
76374
76327
  var decoder2 = new TextDecoder();
@@ -76385,7 +76338,7 @@ async function openWhenWritten(deps, runId, res, signal) {
76385
76338
  const path4 = runDirectory(deps.runsDir, runId).log;
76386
76339
  while (!signal.aborted) {
76387
76340
  const appended = deps.appends.nextAppend(runId, signal);
76388
- if ((0, import_node_fs25.existsSync)(path4) || !await deps.isHeld(runId, signal)) return openReader(res, path4);
76341
+ if ((0, import_node_fs24.existsSync)(path4) || !await deps.isHeld(runId, signal)) return openReader(res, path4);
76389
76342
  await appended;
76390
76343
  }
76391
76344
  return null;
@@ -82733,7 +82686,7 @@ function lockWaitMs(argv) {
82733
82686
  async function openManagedProviders(config2, paths) {
82734
82687
  const providerEnv = readCliEnvironment();
82735
82688
  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);
82689
+ const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs25.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
82737
82690
  const npmPath = providerToolchain?.node ?? await resolveCommandOnPath("npm", providerEnv, process.platform);
82738
82691
  const npmOptions = npmPath === null || process.platform === "win32" && providerToolchain === null ? null : {
82739
82692
  command: npmPath,
package/alan-holder.cjs CHANGED
@@ -48506,6 +48506,20 @@ async function readCheckoutStatus(git, cwd, signal) {
48506
48506
  );
48507
48507
  return output2.exitCode === 0 ? parseStatus(output2.stdout) : null;
48508
48508
  }
48509
+ async function currentBranch(git, cwd, signal) {
48510
+ const output2 = await git.run(
48511
+ { cwd, args: ["symbolic-ref", "--quiet", "--short", "HEAD"], readOnly: true },
48512
+ signal
48513
+ );
48514
+ return output2.exitCode === 0 ? output2.stdout.trim() || null : null;
48515
+ }
48516
+ async function moveSnapshotTo(git, cwd, snapshot, tip, signal) {
48517
+ const run = (args) => git.run({ cwd, args }, signal);
48518
+ if ((await run(["switch", "--quiet", "--detach", tip])).exitCode !== 0) return false;
48519
+ const moved = await run(["update-ref", `refs/heads/${snapshot.branch}`, tip, snapshot.head]);
48520
+ const back = await run(["switch", "--quiet", snapshot.branch]);
48521
+ return moved.exitCode === 0 && back.exitCode === 0;
48522
+ }
48509
48523
  async function isCheckout(path) {
48510
48524
  return (0, import_promises8.stat)((0, import_node_path4.join)(path, ".git")).then(
48511
48525
  () => true,
@@ -48885,7 +48899,6 @@ function runtimePaths(stateDir) {
48885
48899
 
48886
48900
  // src/platform/process-memory.ts
48887
48901
  var import_node_child_process4 = require("child_process");
48888
- var import_node_fs6 = require("fs");
48889
48902
  var import_promises12 = require("fs/promises");
48890
48903
  var import_node_os2 = require("os");
48891
48904
  var import_node_util3 = require("util");
@@ -48925,45 +48938,6 @@ async function readProcessRss(pid) {
48925
48938
  return null;
48926
48939
  }
48927
48940
  }
48928
- function parseDarwinVmStat(output2) {
48929
- const pageSize = Number(/page size of (\d+) bytes/.exec(output2)?.[1]);
48930
- if (!Number.isFinite(pageSize) || pageSize <= 0) return null;
48931
- const pages = (name) => {
48932
- const match = new RegExp(`^Pages ${name}:\\s+(\\d+)\\.?$`, "m").exec(output2);
48933
- return match ? Number(match[1]) : null;
48934
- };
48935
- const free = pages("free");
48936
- if (free === null) return null;
48937
- return (free + (pages("inactive") ?? 0) + (pages("speculative") ?? 0)) * pageSize;
48938
- }
48939
- function parseLinuxMemInfo(output2) {
48940
- const kilobytes = /^MemAvailable:\s+(\d+)\s+kB$/m.exec(output2)?.[1];
48941
- return kilobytes === void 0 ? null : Number(kilobytes) * 1024;
48942
- }
48943
- var CAPACITY_PROBE_TTL_MS = 2e3;
48944
- var AvailableMemoryProbe = class {
48945
- cached = null;
48946
- read(now) {
48947
- if (this.cached !== null && now - this.cached.at < CAPACITY_PROBE_TTL_MS) {
48948
- return this.cached.bytes;
48949
- }
48950
- let bytes = null;
48951
- try {
48952
- if (process.platform === "darwin") {
48953
- bytes = parseDarwinVmStat(
48954
- (0, import_node_child_process4.execFileSync)("vm_stat", { encoding: "utf8", timeout: PROBE_TIMEOUT_MS })
48955
- );
48956
- } else if (process.platform === "linux") {
48957
- bytes = parseLinuxMemInfo((0, import_node_fs6.readFileSync)("/proc/meminfo", "utf8"));
48958
- }
48959
- } catch {
48960
- bytes = null;
48961
- }
48962
- this.cached = { at: now, bytes };
48963
- return bytes;
48964
- }
48965
- };
48966
- var availableMemoryProbe = new AvailableMemoryProbe();
48967
48941
  async function processMemoryRows() {
48968
48942
  if (process.platform === "win32") {
48969
48943
  const { stdout: stdout2 } = await execFileAsync3(
@@ -49064,7 +49038,7 @@ var systemExec = (request2) => new Promise((resolve8) => {
49064
49038
  init_alan_code();
49065
49039
 
49066
49040
  // src/capabilities/providers/commands.ts
49067
- var import_node_fs7 = require("fs");
49041
+ var import_node_fs6 = require("fs");
49068
49042
  var import_promises17 = require("fs/promises");
49069
49043
  var import_node_path9 = require("path");
49070
49044
  var PROVIDER_COMMANDS = [
@@ -49102,7 +49076,7 @@ function pathDelimiter(platform) {
49102
49076
  async function isRunnable(path, platform) {
49103
49077
  try {
49104
49078
  if (!(await (0, import_promises17.stat)(path)).isFile()) return false;
49105
- if (platform !== "win32") await (0, import_promises17.access)(path, import_node_fs7.constants.X_OK);
49079
+ if (platform !== "win32") await (0, import_promises17.access)(path, import_node_fs6.constants.X_OK);
49106
49080
  return true;
49107
49081
  } catch {
49108
49082
  return false;
@@ -49752,7 +49726,7 @@ async function inspectIndexedSkill(directory, contentHash) {
49752
49726
 
49753
49727
  // src/capabilities/skills/native-index.ts
49754
49728
  var import_node_crypto10 = require("crypto");
49755
- var import_node_fs8 = require("fs");
49729
+ var import_node_fs7 = require("fs");
49756
49730
  var import_promises21 = require("fs/promises");
49757
49731
  var import_node_path13 = require("path");
49758
49732
  var ALAN_SKILLS_PLUGIN_NAME = "alan";
@@ -49766,7 +49740,7 @@ var PLUGIN_MANIFEST = `${JSON.stringify(
49766
49740
  )}
49767
49741
  `;
49768
49742
  function installedSkillFolders(layout) {
49769
- return (0, import_node_fs8.existsSync)((0, import_node_path13.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
49743
+ return (0, import_node_fs7.existsSync)((0, import_node_path13.join)(layout.pluginDir, ".claude-plugin", "plugin.json")) ? { pluginDir: layout.pluginDir, skillsDir: layout.pluginSkillsDir } : null;
49770
49744
  }
49771
49745
 
49772
49746
  // src/capabilities/workspace/index.ts
@@ -50383,20 +50357,20 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
50383
50357
 
50384
50358
  // src/holder/serve.ts
50385
50359
  var import_node_crypto15 = require("crypto");
50386
- var import_node_fs12 = require("fs");
50360
+ var import_node_fs11 = require("fs");
50387
50361
  var import_node_net2 = require("net");
50388
50362
  var import_node_path29 = require("path");
50389
50363
  init_runtime_v2();
50390
50364
 
50391
50365
  // src/holder/admission.ts
50392
- var import_node_fs10 = require("fs");
50366
+ var import_node_fs9 = require("fs");
50393
50367
  var import_promises35 = require("fs/promises");
50394
50368
  var import_node_os6 = require("os");
50395
50369
  var import_node_path25 = require("path");
50396
50370
  init_constants();
50397
50371
 
50398
50372
  // ../shared/dist/node/local-workspace.js
50399
- var import_node_fs9 = require("fs");
50373
+ var import_node_fs8 = require("fs");
50400
50374
  var import_node_os5 = require("os");
50401
50375
  var import_node_path20 = require("path");
50402
50376
  function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os5.homedir)()) {
@@ -50624,18 +50598,16 @@ async function switchTo(checkout, current, operationId, deps, signal) {
50624
50598
  async function applyRequestedCheckout(checkout, spec, deps, signal) {
50625
50599
  try {
50626
50600
  if (!await isCheckout(checkout.path)) return await clone2(checkout, deps, signal);
50627
- const status = await readCheckoutStatus(deps.git, checkout.path, signal);
50628
- if (status === null) return notSwitched(checkout, null, "git status failed");
50629
- if (status.branch === checkout.branch) return { kind: "on_branch" };
50630
- if (status.dirty) return notSwitched(checkout, status.branch, "it has uncommitted changes");
50601
+ const branch = await currentBranch(deps.git, checkout.path, signal);
50602
+ if (branch === checkout.branch) return { kind: "on_branch" };
50631
50603
  if (!await claimFirstLease(deps.dir, checkout.path)) {
50632
50604
  return notSwitched(
50633
50605
  checkout,
50634
- status.branch,
50606
+ branch,
50635
50607
  "an earlier conversation on this machine already uses it"
50636
50608
  );
50637
50609
  }
50638
- return await switchTo(checkout, status.branch, `checkout-${spec.runId}`, deps, signal);
50610
+ return await switchTo(checkout, branch, `checkout-${spec.runId}`, deps, signal);
50639
50611
  } catch (error62) {
50640
50612
  return noted(
50641
50613
  `could not be put on ${checkout.branch}, the branch picked for this chat`,
@@ -50666,15 +50638,13 @@ async function fastForward(freshness, operationId, deps, signal) {
50666
50638
  const attempt = await deps.locks.tryExclusive(snapshot.commonDir, operationId);
50667
50639
  if (attempt.kind === "busy") return false;
50668
50640
  const _lock = __using(_stack, attempt.lock, true);
50669
- const now = await readCheckoutStatus(deps.git, cwd, signal);
50670
- if (now === null || now.dirty || now.head !== snapshot.head || now.branch !== snapshot.branch) {
50671
- return false;
50672
- }
50673
- const git = (args) => deps.git.run({ cwd, args }, signal);
50674
- if ((await git(["switch", "--quiet", "--detach", tip])).exitCode !== 0) return false;
50675
- const moved = await git(["update-ref", `refs/heads/${snapshot.branch}`, tip, snapshot.head]);
50676
- const back = await git(["switch", "--quiet", snapshot.branch]);
50677
- return moved.exitCode === 0 && back.exitCode === 0;
50641
+ const head = await deps.git.run(
50642
+ { cwd, args: ["rev-parse", "--verify", "HEAD"], readOnly: true },
50643
+ signal
50644
+ );
50645
+ if (head.exitCode !== 0 || head.stdout.trim() !== snapshot.head) return false;
50646
+ if (await currentBranch(deps.git, cwd, signal) !== snapshot.branch) return false;
50647
+ return moveSnapshotTo(deps.git, cwd, snapshot, tip, signal);
50678
50648
  } catch (_) {
50679
50649
  var _error = _, _hasError = true;
50680
50650
  } finally {
@@ -50725,13 +50695,15 @@ async function applyRequestedCheckouts(spec, deps, signal) {
50725
50695
  const settled2 = /* @__PURE__ */ new Set();
50726
50696
  const problems = [];
50727
50697
  for (const checkout of requestedCheckoutsOf(spec, deps.log)) {
50698
+ const startedAt = Date.now();
50728
50699
  const outcome2 = await applyRequestedCheckout(checkout, spec, deps, signal);
50729
50700
  deps.log.info("workspace.requested_checkout", {
50730
50701
  runId: spec.runId,
50731
50702
  path: checkout.path,
50732
50703
  branch: checkout.branch,
50733
50704
  outcome: outcome2.kind,
50734
- ...outcome2.kind === "moved" ? { how: outcome2.how } : {}
50705
+ ...outcome2.kind === "moved" ? { how: outcome2.how } : {},
50706
+ ms: Date.now() - startedAt
50735
50707
  });
50736
50708
  if (outcome2.kind === "on_branch") continue;
50737
50709
  settled2.add((0, import_node_path24.resolve)(checkout.path));
@@ -50747,6 +50719,7 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
50747
50719
  if (settled2.has((0, import_node_path24.resolve)(target))) continue;
50748
50720
  const freshness = await readCheckoutFreshness(deps.dir, target);
50749
50721
  if (freshness === null) continue;
50722
+ const startedAt = Date.now();
50750
50723
  const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
50751
50724
  () => "noted"
50752
50725
  );
@@ -50755,7 +50728,8 @@ async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
50755
50728
  runId: spec.runId,
50756
50729
  path: freshness.path,
50757
50730
  state: freshness.state,
50758
- outcome: outcome2
50731
+ outcome: outcome2,
50732
+ ms: Date.now() - startedAt
50759
50733
  });
50760
50734
  }
50761
50735
  return problems;
@@ -50816,7 +50790,7 @@ async function inspectReadiness(path) {
50816
50790
  if (!(await (0, import_promises35.stat)(path)).isDirectory()) {
50817
50791
  return { ready: false, missing: true, message: MESSAGES.missing };
50818
50792
  }
50819
- await (0, import_promises35.access)(path, import_node_fs10.constants.R_OK | import_node_fs10.constants.W_OK | import_node_fs10.constants.X_OK);
50793
+ await (0, import_promises35.access)(path, import_node_fs9.constants.R_OK | import_node_fs9.constants.W_OK | import_node_fs9.constants.X_OK);
50820
50794
  return { ready: true };
50821
50795
  } catch (error62) {
50822
50796
  const code = errnoCode(error62) ?? "";
@@ -50861,7 +50835,7 @@ async function admitDefaultWorkspace(spec, context, skills) {
50861
50835
  const path = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os6.homedir)());
50862
50836
  try {
50863
50837
  await (0, import_promises35.mkdir)(path, { recursive: true, mode: 448 });
50864
- await (0, import_promises35.access)(path, import_node_fs10.constants.R_OK | import_node_fs10.constants.W_OK | import_node_fs10.constants.X_OK);
50838
+ await (0, import_promises35.access)(path, import_node_fs9.constants.R_OK | import_node_fs9.constants.W_OK | import_node_fs9.constants.X_OK);
50865
50839
  return { kind: "admitted", spec: { ...spec, projectPath: path }, skills };
50866
50840
  } catch (error62) {
50867
50841
  const code = errnoCode(error62);
@@ -51200,13 +51174,13 @@ function runEnded(input2) {
51200
51174
  var decoder = new TextDecoder();
51201
51175
 
51202
51176
  // src/run-log/writer.ts
51203
- var import_node_fs11 = require("fs");
51177
+ var import_node_fs10 = require("fs");
51204
51178
  var import_node_path28 = require("path");
51205
51179
  init_runtime_v2();
51206
51180
  function lastSeq(fd, size) {
51207
51181
  for (const length of tailWindows(size)) {
51208
51182
  const buffer = Buffer.alloc(length);
51209
- (0, import_node_fs11.readSync)(fd, buffer, 0, length, size - length);
51183
+ (0, import_node_fs10.readSync)(fd, buffer, 0, length, size - length);
51210
51184
  const last = lastLine(buffer.toString("utf8").trimEnd(), length === size);
51211
51185
  if (last === void 0) continue;
51212
51186
  if (last.length === 0) return 0;
@@ -51217,13 +51191,13 @@ function lastSeq(fd, size) {
51217
51191
  throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
51218
51192
  }
51219
51193
  function openRunLog(path, clock) {
51220
- (0, import_node_fs11.mkdirSync)((0, import_node_path28.dirname)(path), { recursive: true, mode: 448 });
51221
- const fd = (0, import_node_fs11.openSync)(path, "a+", 384);
51222
- let size = (0, import_node_fs11.fstatSync)(fd).size;
51194
+ (0, import_node_fs10.mkdirSync)((0, import_node_path28.dirname)(path), { recursive: true, mode: 448 });
51195
+ const fd = (0, import_node_fs10.openSync)(path, "a+", 384);
51196
+ let size = (0, import_node_fs10.fstatSync)(fd).size;
51223
51197
  let seq = lastSeq(fd, size);
51224
51198
  let dirty = false;
51225
51199
  const sync = () => {
51226
- (0, import_node_fs11.fsyncSync)(fd);
51200
+ (0, import_node_fs10.fsyncSync)(fd);
51227
51201
  dirty = false;
51228
51202
  };
51229
51203
  return {
@@ -51237,7 +51211,7 @@ function openRunLog(path, clock) {
51237
51211
  };
51238
51212
  const line = Buffer.from(`${JSON.stringify(record2)}
51239
51213
  `, "utf8");
51240
- (0, import_node_fs11.writeSync)(fd, line);
51214
+ (0, import_node_fs10.writeSync)(fd, line);
51241
51215
  size += line.length;
51242
51216
  dirty = true;
51243
51217
  if (isRunLifecycleKind(update.sessionUpdate)) sync();
@@ -51249,7 +51223,7 @@ function openRunLog(path, clock) {
51249
51223
  },
51250
51224
  [Symbol.dispose]: () => {
51251
51225
  if (dirty) sync();
51252
- (0, import_node_fs11.closeSync)(fd);
51226
+ (0, import_node_fs10.closeSync)(fd);
51253
51227
  }
51254
51228
  };
51255
51229
  }
@@ -51690,7 +51664,7 @@ async function runHolder({
51690
51664
  for (const client of holder.clients) client.end();
51691
51665
  await new Promise((resolve8) => server.close(() => resolve8()));
51692
51666
  await statusWrites;
51693
- (0, import_node_fs12.rmSync)(launch.statusPath, { force: true });
51667
+ (0, import_node_fs11.rmSync)(launch.statusPath, { force: true });
51694
51668
  log.info("holder.suspended", { conversationId: launch.conversationId });
51695
51669
  } catch (_) {
51696
51670
  var _error = _, _hasError = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alan-ai-hq/agent-manager-linux-arm64",
3
- "version": "0.1.162",
3
+ "version": "0.1.163",
4
4
  "description": "Alan machine runtime (alan-agent) for one platform: the official Node.js binary, the runtime bundle and its launcher. Installed by @alan-ai-hq/agent-manager.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://tryalan.ai",