agent-yes 1.129.0 → 1.131.0

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.
@@ -0,0 +1,8 @@
1
+ import "./ts-CFyen5cA.js";
2
+ import "./logger-B9h0djqx.js";
3
+ import "./versionChecker-DF1bftgQ.js";
4
+ import "./pidStore-DWQoGxxA.js";
5
+ import "./globalPidIndex-C7r2m6s7.js";
6
+ import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-QtoszbIC.js";
7
+
8
+ export { SUPPORTED_CLIS };
@@ -1,8 +1,8 @@
1
- import { t as CLIS_CONFIG } from "./ts-D21pYxoi.js";
1
+ import { t as CLIS_CONFIG } from "./ts-CFyen5cA.js";
2
2
 
3
3
  //#region ts/SUPPORTED_CLIS.ts
4
4
  const SUPPORTED_CLIS = Object.keys(CLIS_CONFIG);
5
5
 
6
6
  //#endregion
7
7
  export { SUPPORTED_CLIS as t };
8
- //# sourceMappingURL=SUPPORTED_CLIS-CRiTrZVs.js.map
8
+ //# sourceMappingURL=SUPPORTED_CLIS-QtoszbIC.js.map
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  import { n as logger } from "./logger-B9h0djqx.js";
3
- import { i as versionString, n as displayVersion, r as getInstalledPackage, t as checkAndAutoUpdate } from "./versionChecker-VKD48fzV.js";
3
+ import { i as versionString, n as displayVersion, r as getInstalledPackage, t as checkAndAutoUpdate } from "./versionChecker-DF1bftgQ.js";
4
4
  import { argv } from "process";
5
5
  import { execFileSync, spawn } from "child_process";
6
6
  import ms from "ms";
@@ -482,7 +482,7 @@ function buildRustArgs(argv, cliFromScript, supportedClis) {
482
482
  {
483
483
  const rawArg = process.argv[2];
484
484
  const isHelpFlag = rawArg === "-h" || rawArg === "--help";
485
- const { isSubcommand, runSubcommand, cmdHelp } = await import("./subcommands-BLUX23IJ.js");
485
+ const { isSubcommand, runSubcommand, cmdHelp } = await import("./subcommands-BgZ46FBg.js");
486
486
  if (isHelpFlag && process.argv.length === 3) {
487
487
  cmdHelp();
488
488
  process.exit(0);
@@ -515,7 +515,7 @@ if (config.useRust) {
515
515
  }
516
516
  }
517
517
  if (rustBinary) {
518
- const { SUPPORTED_CLIS } = await import("./SUPPORTED_CLIS-BEGaVwg2.js");
518
+ const { SUPPORTED_CLIS } = await import("./SUPPORTED_CLIS-BeiCQyhf.js");
519
519
  const rustArgs = buildRustArgs(process.argv, config.cli, SUPPORTED_CLIS);
520
520
  if (config.verbose) {
521
521
  console.log(`[rust] Using binary: ${rustBinary}`);
@@ -545,7 +545,7 @@ if (config.showVersion) {
545
545
  process.exit(0);
546
546
  }
547
547
  if (config.appendPrompt) {
548
- const { PidStore } = await import("./pidStore-C4c2O15q.js");
548
+ const { PidStore } = await import("./pidStore-BweOirbR.js");
549
549
  const ipcPath = await PidStore.findActiveFifo(process.cwd());
550
550
  if (!ipcPath) {
551
551
  console.error("No active agent with IPC found in current directory.");
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { a as removeControlCharacters, i as AgentContext, n as agentYes, r as config, t as CLIS_CONFIG } from "./ts-D21pYxoi.js";
1
+ import { a as removeControlCharacters, i as AgentContext, n as agentYes, r as config, t as CLIS_CONFIG } from "./ts-CFyen5cA.js";
2
2
  import "./logger-B9h0djqx.js";
3
- import "./versionChecker-VKD48fzV.js";
4
- import "./pidStore-CGKIhaJO.js";
3
+ import "./versionChecker-DF1bftgQ.js";
4
+ import "./pidStore-DWQoGxxA.js";
5
5
  import "./globalPidIndex-C7r2m6s7.js";
6
6
 
7
7
  export { AgentContext, CLIS_CONFIG, config, agentYes as default, removeControlCharacters };
@@ -0,0 +1,5 @@
1
+ import "./logger-B9h0djqx.js";
2
+ import { t as PidStore } from "./pidStore-DWQoGxxA.js";
3
+ import "./globalPidIndex-C7r2m6s7.js";
4
+
5
+ export { PidStore };
@@ -4,6 +4,7 @@ import { a as updateGlobalPidStatus, n as maybeCompactGlobalPids, r as pruneOldL
4
4
  import { closeSync, existsSync, fsyncSync, openSync } from "fs";
5
5
  import { appendFile, mkdir, readFile, rename, writeFile } from "fs/promises";
6
6
  import path from "path";
7
+ import { randomBytes } from "node:crypto";
7
8
  import { lock } from "proper-lockfile";
8
9
 
9
10
  //#region ts/JsonlStore.ts
@@ -208,6 +209,8 @@ var PidStore = class PidStore {
208
209
  const argsJson = JSON.stringify(args);
209
210
  const logFile = this.getRawLogPath(pid);
210
211
  const fifoFile = this.getFifoPath(pid);
212
+ const existing = this.store.findOne((doc) => doc.pid === pid);
213
+ const agentId = existing?.agentId ?? randomBytes(6).toString("hex");
211
214
  const record = {
212
215
  pid,
213
216
  cli,
@@ -218,9 +221,9 @@ var PidStore = class PidStore {
218
221
  fifoFile,
219
222
  status: "active",
220
223
  exitReason: "",
221
- startedAt: now
224
+ startedAt: now,
225
+ agentId
222
226
  };
223
- const existing = this.store.findOne((doc) => doc.pid === pid);
224
227
  if (existing) await this.store.updateById(existing._id, record);
225
228
  else await this.store.append(record);
226
229
  const result = this.store.findOne((doc) => doc.pid === pid);
@@ -242,7 +245,8 @@ var PidStore = class PidStore {
242
245
  exit_reason: null,
243
246
  started_at: now,
244
247
  wrapper_pid: wrapperPid ?? null,
245
- parent_pid: parentPid ?? null
248
+ parent_pid: parentPid ?? null,
249
+ agent_id: agentId
246
250
  }).then(() => maybeCompactGlobalPids()).catch(() => null);
247
251
  return result;
248
252
  }
@@ -363,4 +367,4 @@ pid-db/
363
367
 
364
368
  //#endregion
365
369
  export { PidStore as t };
366
- //# sourceMappingURL=pidStore-CGKIhaJO.js.map
370
+ //# sourceMappingURL=pidStore-DWQoGxxA.js.map
@@ -1,9 +1,9 @@
1
- import "./ts-D21pYxoi.js";
1
+ import "./ts-CFyen5cA.js";
2
2
  import "./logger-B9h0djqx.js";
3
- import "./versionChecker-VKD48fzV.js";
4
- import "./pidStore-CGKIhaJO.js";
3
+ import "./versionChecker-DF1bftgQ.js";
4
+ import "./pidStore-DWQoGxxA.js";
5
5
  import "./globalPidIndex-C7r2m6s7.js";
6
- import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-CRiTrZVs.js";
6
+ import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-QtoszbIC.js";
7
7
  import { n as resolveSpawnCwd } from "./workspaceConfig-BJO4fzEn.js";
8
8
  import { createHash } from "node:crypto";
9
9
 
@@ -141,4 +141,4 @@ async function cmdSchedule(rest) {
141
141
 
142
142
  //#endregion
143
143
  export { cmdSchedule };
144
- //# sourceMappingURL=schedule-QakndFJf.js.map
144
+ //# sourceMappingURL=schedule-BGsUo_2s.js.map
@@ -1,13 +1,13 @@
1
- import "./ts-D21pYxoi.js";
1
+ import "./ts-CFyen5cA.js";
2
2
  import "./logger-B9h0djqx.js";
3
- import { r as getInstalledPackage } from "./versionChecker-VKD48fzV.js";
4
- import "./pidStore-CGKIhaJO.js";
3
+ import { r as getInstalledPackage } from "./versionChecker-DF1bftgQ.js";
4
+ import "./pidStore-DWQoGxxA.js";
5
5
  import { a as updateGlobalPidStatus } from "./globalPidIndex-C7r2m6s7.js";
6
6
  import { t as pgidForWrapper } from "./reaper-BkjPN7mw.js";
7
7
  import "./configShared-C5QaNPnz.js";
8
- import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-CRiTrZVs.js";
8
+ import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-QtoszbIC.js";
9
9
  import "./remotes-D8GvSbhf.js";
10
- import { d as listRecords, g as resolveOne, i as controlCodeFromName, m as renderRawLog, p as readNotes, s as extractTaskCounts, x as writeToIpc, y as snapshotStatus } from "./subcommands-D1floyWA.js";
10
+ import { d as listRecords, g as resolveOne, i as controlCodeFromName, m as renderRawLog, p as readNotes, s as extractTaskCounts, x as writeToIpc, y as snapshotStatus } from "./subcommands-DP2XsJNo.js";
11
11
  import yargs from "yargs";
12
12
  import { mkdir, open, readFile, stat, writeFile } from "fs/promises";
13
13
  import { homedir, hostname, userInfo } from "os";
@@ -308,6 +308,8 @@ async function cmdServeDaemon(sub, args) {
308
308
  DAEMON_NAME,
309
309
  "--interpreter",
310
310
  "none",
311
+ "--exp-backoff-restart-delay",
312
+ "200",
311
313
  "--",
312
314
  ...serveArgv.slice(1)
313
315
  ];
@@ -1052,11 +1054,17 @@ Options:
1052
1054
  };
1053
1055
  let server = null;
1054
1056
  if (wantHttp) {
1055
- try {
1057
+ for (let attempt = 0;; attempt++) try {
1056
1058
  server = Bun.serve(serverOpts);
1059
+ break;
1057
1060
  } catch (e) {
1058
- if (e.code === "EADDRINUSE") {
1059
- process.stderr.write(`ay serve: port ${port} is already in use — pick another with --port N,\nor run a port-free WebRTC-only share with: ay serve --webrtc\n`);
1061
+ const inUse = e.code === "EADDRINUSE";
1062
+ if (inUse && attempt < 5) {
1063
+ await Bun.sleep(Math.min(2e3, 250 * 2 ** attempt));
1064
+ continue;
1065
+ }
1066
+ if (inUse) {
1067
+ process.stderr.write(`ay serve: port ${port} is still in use after retries — pick another with --port N,\nor run a port-free WebRTC-only share with: ay serve --webrtc\n`);
1060
1068
  return 1;
1061
1069
  }
1062
1070
  throw e;
@@ -1134,4 +1142,4 @@ Options:
1134
1142
 
1135
1143
  //#endregion
1136
1144
  export { cmdServe };
1137
- //# sourceMappingURL=serve-DpBmExxp.js.map
1145
+ //# sourceMappingURL=serve-C9o_RRVC.js.map
@@ -32,7 +32,7 @@ async function cmdSetup(rest) {
32
32
  if (!existsSync(abs)) process.stderr.write(` note: that directory doesn't exist yet — create it, or agents spawned there will fail\n`);
33
33
  if (noShare) return 0;
34
34
  process.stdout.write(`\nsharing this machine to agent-yes.com…\n`);
35
- const { cmdServe } = await import("./serve-DpBmExxp.js");
35
+ const { cmdServe } = await import("./serve-C9o_RRVC.js");
36
36
  return cmdServe([
37
37
  "install",
38
38
  "--share",
@@ -42,4 +42,4 @@ async function cmdSetup(rest) {
42
42
 
43
43
  //#endregion
44
44
  export { cmdSetup };
45
- //# sourceMappingURL=setup-DCisWuHB.js.map
45
+ //# sourceMappingURL=setup-C1UKmIoW.js.map
@@ -2,6 +2,6 @@ import "./logger-B9h0djqx.js";
2
2
  import "./globalPidIndex-C7r2m6s7.js";
3
3
  import "./configShared-C5QaNPnz.js";
4
4
  import "./remotes-D8GvSbhf.js";
5
- import { _ as resolveReadWindow, a as cursorAbs, b as stopTipForCli, c as finalizedLines, d as listRecords, f as matchKeyword, g as resolveOne, h as renderRawLogLines, i as controlCodeFromName, l as isPidAlive, m as renderRawLog, n as READ_PAGE_DEFAULT, o as extractNeedsInput, p as readNotes, r as cmdHelp, s as extractTaskCounts, t as GRACEFUL_EXIT_COMMANDS, u as isSubcommand, v as runSubcommand, x as writeToIpc, y as snapshotStatus } from "./subcommands-D1floyWA.js";
5
+ import { _ as resolveReadWindow, a as cursorAbs, b as stopTipForCli, c as finalizedLines, d as listRecords, f as matchKeyword, g as resolveOne, h as renderRawLogLines, i as controlCodeFromName, l as isPidAlive, m as renderRawLog, n as READ_PAGE_DEFAULT, o as extractNeedsInput, p as readNotes, r as cmdHelp, s as extractTaskCounts, t as GRACEFUL_EXIT_COMMANDS, u as isSubcommand, v as runSubcommand, x as writeToIpc, y as snapshotStatus } from "./subcommands-DP2XsJNo.js";
6
6
 
7
7
  export { cmdHelp, isSubcommand, runSubcommand };
@@ -524,15 +524,15 @@ async function runSubcommand(argv) {
524
524
  case "restart": return await cmdRestart(rest);
525
525
  case "note": return await cmdNote(rest);
526
526
  case "serve": {
527
- const { cmdServe } = await import("./serve-DpBmExxp.js");
527
+ const { cmdServe } = await import("./serve-C9o_RRVC.js");
528
528
  return cmdServe(rest);
529
529
  }
530
530
  case "setup": {
531
- const { cmdSetup } = await import("./setup-DCisWuHB.js");
531
+ const { cmdSetup } = await import("./setup-C1UKmIoW.js");
532
532
  return cmdSetup(rest);
533
533
  }
534
534
  case "schedule": {
535
- const { cmdSchedule } = await import("./schedule-QakndFJf.js");
535
+ const { cmdSchedule } = await import("./schedule-BGsUo_2s.js");
536
536
  return cmdSchedule(rest);
537
537
  }
538
538
  case "remote": {
@@ -562,6 +562,7 @@ function matchKeyword(record, keyword) {
562
562
  if (record.cwd.toLowerCase().includes(kw)) return true;
563
563
  if (record.cli.toLowerCase() === kw) return true;
564
564
  if (record.prompt && record.prompt.toLowerCase().includes(kw)) return true;
565
+ if (record.agent_id && record.agent_id.toLowerCase().startsWith(kw)) return true;
565
566
  return false;
566
567
  }
567
568
  async function listRecords(keyword, opts) {
@@ -2407,4 +2408,4 @@ async function cmdResultSet(rest) {
2407
2408
 
2408
2409
  //#endregion
2409
2410
  export { resolveReadWindow as _, cursorAbs as a, stopTipForCli as b, finalizedLines as c, listRecords as d, matchKeyword as f, resolveOne as g, renderRawLogLines as h, controlCodeFromName as i, isPidAlive as l, renderRawLog as m, READ_PAGE_DEFAULT as n, extractNeedsInput as o, readNotes as p, cmdHelp as r, extractTaskCounts as s, GRACEFUL_EXIT_COMMANDS as t, isSubcommand as u, runSubcommand as v, writeToIpc as x, snapshotStatus as y };
2410
- //# sourceMappingURL=subcommands-D1floyWA.js.map
2411
+ //# sourceMappingURL=subcommands-DP2XsJNo.js.map
@@ -1,8 +1,8 @@
1
1
  import { n as logger, t as addTransport } from "./logger-B9h0djqx.js";
2
- import { r as getInstalledPackage } from "./versionChecker-VKD48fzV.js";
2
+ import { r as getInstalledPackage } from "./versionChecker-DF1bftgQ.js";
3
3
  import { t as agentYesHome } from "./agentYesHome-BvaUOzCV.js";
4
4
  import { i as shouldUseLock, r as releaseLock, t as acquireLock } from "./runningLock-CJxsoGdb.js";
5
- import { t as PidStore } from "./pidStore-CGKIhaJO.js";
5
+ import { t as PidStore } from "./pidStore-DWQoGxxA.js";
6
6
  import { i as readGlobalPids } from "./globalPidIndex-C7r2m6s7.js";
7
7
  import { n as register, r as sweep } from "./reaper-BkjPN7mw.js";
8
8
  import { arch, platform } from "process";
@@ -1787,4 +1787,4 @@ function sleep(ms) {
1787
1787
 
1788
1788
  //#endregion
1789
1789
  export { removeControlCharacters as a, AgentContext as i, agentYes as n, config as r, CLIS_CONFIG as t };
1790
- //# sourceMappingURL=ts-D21pYxoi.js.map
1790
+ //# sourceMappingURL=ts-CFyen5cA.js.map
@@ -7,7 +7,7 @@ import { fileURLToPath } from "url";
7
7
 
8
8
  //#region package.json
9
9
  var name = "agent-yes";
10
- var version = "1.129.0";
10
+ var version = "1.131.0";
11
11
 
12
12
  //#endregion
13
13
  //#region ts/versionChecker.ts
@@ -215,4 +215,4 @@ async function displayVersion() {
215
215
 
216
216
  //#endregion
217
217
  export { versionString as i, displayVersion as n, getInstalledPackage as r, checkAndAutoUpdate as t };
218
- //# sourceMappingURL=versionChecker-VKD48fzV.js.map
218
+ //# sourceMappingURL=versionChecker-DF1bftgQ.js.map
package/lab/ui/index.html CHANGED
@@ -2958,38 +2958,46 @@
2958
2958
  // and re-assert our size to the agent so the stream always reflows to OUR
2959
2959
  // viewport (see the visibilitychange hook in startPolling). Push-if-different
2960
2960
  // inside fitAndSync keeps an already-matching agent from a redundant SIGWINCH.
2961
+ // Returns the in-flight sync promise so the initial open can await it
2962
+ // before starting the tail (below); tab-reactivation callers ignore it.
2961
2963
  resyncTerm = () => {
2962
2964
  if (sel !== selKey || !term) return;
2963
- tx.fetchJSON("/api/size/" + encodeURIComponent(pid))
2965
+ return tx
2966
+ .fetchJSON("/api/size/" + encodeURIComponent(pid))
2964
2967
  .then(fitAndSync)
2965
2968
  .catch(() => fitAndSync(null));
2966
2969
  };
2967
- resyncTerm();
2968
-
2969
- // True live tail via ay serve's SSE stream. First event is an xterm-rendered
2970
- // tail snapshot; later events are incremental deltas. We normalise terminal
2971
- // carriage returns so the stream reads cleanly as HTML, autoscroll while the
2972
- // viewer is pinned to the bottom, and cap the buffer so it can't grow forever.
2973
- $("livedot").className = "dot idle";
2974
- $("livetxt").textContent = "connecting…";
2975
- const close = tx.subscribe(
2976
- "/api/tail/" + encodeURIComponent(pid) + "?raw=1",
2977
- (raw) => {
2978
- if (term) {
2979
- term.write(raw);
2980
- perfNote("out", raw?.length ?? 0);
2981
- }
2982
- },
2983
- () => {
2984
- $("livedot").className = "dot active";
2985
- $("livetxt").textContent = "live";
2986
- },
2987
- () => {
2988
- $("livedot").className = "dot stopped";
2989
- $("livetxt").textContent = "disconnected";
2990
- },
2991
- );
2992
- es = { close };
2970
+
2971
+ // Start the raw replay only AFTER the initial size sync (fit + resize
2972
+ // push) settles. /api/tail?raw=1 is absolute-cursor-positioned for the
2973
+ // agent's grid; writing it into xterm before fit.fit()/resize would land
2974
+ // the initial snapshot on a wrong-size grid that no later resize can
2975
+ // repair (garbled, overlapping, dim-bleed output). First event is an
2976
+ // xterm-rendered tail snapshot; later events are incremental deltas.
2977
+ const startTail = () => {
2978
+ if (sel !== selKey || !term) return; // switched away during size sync
2979
+ $("livedot").className = "dot idle";
2980
+ $("livetxt").textContent = "connecting…";
2981
+ const close = tx.subscribe(
2982
+ "/api/tail/" + encodeURIComponent(pid) + "?raw=1",
2983
+ (raw) => {
2984
+ if (term) {
2985
+ term.write(raw);
2986
+ perfNote("out", raw?.length ?? 0);
2987
+ }
2988
+ },
2989
+ () => {
2990
+ $("livedot").className = "dot active";
2991
+ $("livetxt").textContent = "live";
2992
+ },
2993
+ () => {
2994
+ $("livedot").className = "dot stopped";
2995
+ $("livetxt").textContent = "disconnected";
2996
+ },
2997
+ );
2998
+ es = { close };
2999
+ };
3000
+ Promise.resolve(resyncTerm()).finally(startTail);
2993
3001
  }
2994
3002
 
2995
3003
  $("list").addEventListener("click", (ev) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-yes",
3
- "version": "1.129.0",
3
+ "version": "1.131.0",
4
4
  "description": "A wrapper tool that automates interactions with various AI CLI tools by automatically handling common prompts and responses.",
5
5
  "keywords": [
6
6
  "ai",
@@ -81,7 +81,7 @@
81
81
  "build": "tsdown",
82
82
  "check:e2e": "bun scripts/check-e2e.ts",
83
83
  "cf": "bun scripts/cf.ts",
84
- "build:rs": "cargo install --path rs --features swarm",
84
+ "build:rs": "bun ./scripts/build-rs.ts",
85
85
  "postbuild": "bun ./ts/postbuild.ts",
86
86
  "demo": "bun run build && bun link && claude-yes -- demo",
87
87
  "dev": "bun ts/index.ts",
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env bun
2
+ // Build + install the Rust binary.
3
+ //
4
+ // On Windows a running `agent-yes.exe` holds its own image file locked, so
5
+ // `cargo install` fails with "Access is denied" when it tries to remove/
6
+ // overwrite the old binary. Windows DOES permit *renaming* a running .exe
7
+ // (the live process keeps using the renamed image), so we move any locked
8
+ // binary aside as `agent-yes.old-<ts>.exe` before building and let cargo write
9
+ // a fresh one. This makes rebuilds lock-free without killing live sessions.
10
+ //
11
+ // On macOS/Linux a running binary can be replaced directly, so this is a no-op
12
+ // there and we just run cargo.
13
+ import { spawnSync } from "child_process";
14
+ import { existsSync, readdirSync, renameSync, rmSync } from "fs";
15
+ import os from "os";
16
+ import path from "path";
17
+
18
+ const repoRoot = path.resolve(import.meta.dirname, "..");
19
+ const cargoHome = process.env.CARGO_HOME || path.join(os.homedir(), ".cargo");
20
+
21
+ // Both binaries cargo touches: the build output and the installed copy.
22
+ const targets = [
23
+ path.join(repoRoot, "rs", "target", "release", "agent-yes.exe"),
24
+ path.join(cargoHome, "bin", "agent-yes.exe"),
25
+ ];
26
+
27
+ function moveLockedBinariesAside(): Array<{ original: string; aside: string }> {
28
+ const moved: Array<{ original: string; aside: string }> = [];
29
+ for (const exe of targets) {
30
+ const dir = path.dirname(exe);
31
+ if (!existsSync(dir)) continue;
32
+ const base = path.basename(exe, ".exe");
33
+
34
+ // Sweep stale .old- files from earlier rebuilds. Any still locked by a
35
+ // live process will fail to delete — that's fine, skip and move on.
36
+ for (const f of readdirSync(dir)) {
37
+ if (f.startsWith(`${base}.old-`) && f.endsWith(".exe")) {
38
+ try {
39
+ rmSync(path.join(dir, f));
40
+ } catch {
41
+ /* still running — leave it */
42
+ }
43
+ }
44
+ }
45
+
46
+ // Move the current (possibly locked) binary aside so cargo can write fresh.
47
+ if (existsSync(exe)) {
48
+ const aside = path.join(dir, `${base}.old-${Date.now()}.exe`);
49
+ try {
50
+ renameSync(exe, aside);
51
+ moved.push({ original: exe, aside });
52
+ console.log(`[build-rs] moved locked binary aside: ${path.basename(aside)}`);
53
+ } catch {
54
+ // Not locked (or rename unsupported) — try a plain delete instead.
55
+ try {
56
+ rmSync(exe);
57
+ } catch (e) {
58
+ console.warn(`[build-rs] WARNING: could not free ${exe}: ${e}`);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ return moved;
64
+ }
65
+
66
+ const moved = process.platform === "win32" ? moveLockedBinariesAside() : [];
67
+
68
+ const args = ["install", "--path", "rs", "--features", "swarm", ...process.argv.slice(2)];
69
+ console.log(`[build-rs] cargo ${args.join(" ")}`);
70
+ const result = spawnSync("cargo", args, { cwd: repoRoot, stdio: "inherit" });
71
+
72
+ // On failure cargo never wrote the fresh originals, so restore anything we
73
+ // moved aside — otherwise a build error would leave agent-yes.exe missing
74
+ // from PATH until the next successful build.
75
+ if (result.status !== 0) {
76
+ for (const { original, aside } of moved) {
77
+ if (!existsSync(original) && existsSync(aside)) {
78
+ try {
79
+ renameSync(aside, original);
80
+ console.warn(`[build-rs] build failed — restored ${path.basename(original)}`);
81
+ } catch {
82
+ /* best effort */
83
+ }
84
+ }
85
+ }
86
+ }
87
+
88
+ process.exit(result.status ?? 1);
@@ -55,6 +55,29 @@ describe("globalPidIndex", () => {
55
55
  });
56
56
  });
57
57
 
58
+ it("round-trips agent_id and preserves it through a status update", async () => {
59
+ const mod = await loadModule();
60
+ await mod.appendGlobalPid({
61
+ pid: 31313,
62
+ cli: "claude",
63
+ prompt: null,
64
+ cwd: "/a",
65
+ log_file: null,
66
+ status: "active",
67
+ exit_code: null,
68
+ exit_reason: null,
69
+ started_at: 1,
70
+ agent_id: "deadbeef0001",
71
+ });
72
+ // updateStatus appends a merged record by pid; agent_id must survive since
73
+ // the patch doesn't include it (last-line-wins merge spreads the prior doc).
74
+ await mod.updateGlobalPidStatus(31313, { status: "idle" });
75
+
76
+ const records = await mod.readGlobalPids();
77
+ expect(records).toHaveLength(1);
78
+ expect(records[0]).toMatchObject({ pid: 31313, status: "idle", agent_id: "deadbeef0001" });
79
+ });
80
+
58
81
  it("merges multiple appends for the same pid (last write wins)", async () => {
59
82
  const mod = await loadModule();
60
83
  await mod.appendGlobalPid({
@@ -47,6 +47,11 @@ export interface GlobalPidRecord {
47
47
  // started from a human shell. Builds the agent>subagent tree: a child links to
48
48
  // its parent via child.parent_pid === parent.wrapper_pid. See buildAgentForest.
49
49
  parent_pid?: number | null;
50
+ // Stable id minted once at registration so a share grant or `ay <cmd> <id>`
51
+ // can reference this agent without its ephemeral pid. Mirrors Rust's `agent_id`
52
+ // (snake_case). Currently per-process; cross-restart re-binding is a follow-up
53
+ // (see docs/agent-sharing.md). Preserved verbatim through merges/compaction.
54
+ agent_id?: string | null;
50
55
  }
51
56
 
52
57
  /**
package/ts/pidStore.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { mkdir, writeFile } from "fs/promises";
2
+ import { randomBytes } from "node:crypto";
2
3
  import path from "path";
3
4
  import { logger } from "./logger.ts";
4
5
  import { JsonlStore } from "./JsonlStore.ts";
@@ -23,6 +24,8 @@ export interface PidRecord {
23
24
  exitReason: string;
24
25
  exitCode?: number;
25
26
  startedAt: number;
27
+ // Stable id minted at registration; mirrored to the global index as `agent_id`.
28
+ agentId?: string;
26
29
  }
27
30
 
28
31
  export class PidStore {
@@ -73,6 +76,11 @@ export class PidStore {
73
76
  const logFile = this.getRawLogPath(pid);
74
77
  const fifoFile = this.getFifoPath(pid);
75
78
 
79
+ // Upsert by pid. Reuse an existing record's agent id so re-registration
80
+ // (e.g. status churn) keeps the id stable; mint a fresh 12-hex id otherwise.
81
+ const existing = this.store.findOne((doc) => doc.pid === pid);
82
+ const agentId = existing?.agentId ?? randomBytes(6).toString("hex");
83
+
76
84
  const record: Omit<PidRecord, "_id"> = {
77
85
  pid,
78
86
  cli,
@@ -84,10 +92,9 @@ export class PidStore {
84
92
  status: "active",
85
93
  exitReason: "",
86
94
  startedAt: now,
95
+ agentId,
87
96
  };
88
97
 
89
- // Upsert by pid
90
- const existing = this.store.findOne((doc) => doc.pid === pid);
91
98
  if (existing) {
92
99
  await this.store.updateById(existing._id!, record);
93
100
  } else {
@@ -119,6 +126,7 @@ export class PidStore {
119
126
  started_at: now,
120
127
  wrapper_pid: wrapperPid ?? null,
121
128
  parent_pid: parentPid ?? null,
129
+ agent_id: agentId,
122
130
  })
123
131
  .then(() => maybeCompactGlobalPids())
124
132
  .catch(() => null);
package/ts/serve.ts CHANGED
@@ -447,6 +447,13 @@ async function cmdServeDaemon(sub: string, args: string[]): Promise<number> {
447
447
  DAEMON_NAME,
448
448
  "--interpreter",
449
449
  "none",
450
+ // Exponential restart backoff: a persistent crash (e.g. a port held
451
+ // by a stale instance) must NOT hammer-restart. pm2's default is an
452
+ // instant respawn, which storms — hundreds of restarts/min, each
453
+ // briefly grabbing window focus. exp-backoff grows the delay on
454
+ // repeated quick crashes and resets once the process stays up.
455
+ "--exp-backoff-restart-delay",
456
+ "200",
450
457
  "--",
451
458
  ...serveArgv.slice(1),
452
459
  ];
@@ -1453,17 +1460,30 @@ export async function cmdServe(rest: string[]): Promise<number> {
1453
1460
 
1454
1461
  let server: ReturnType<typeof Bun.serve> | null = null;
1455
1462
  if (wantHttp) {
1456
- try {
1457
- server = Bun.serve(serverOpts);
1458
- } catch (e) {
1459
- if ((e as { code?: string }).code === "EADDRINUSE") {
1460
- process.stderr.write(
1461
- `ay serve: port ${port} is already in use — pick another with --port N,\n` +
1462
- `or run a port-free WebRTC-only share with: ay serve --webrtc\n`,
1463
- );
1464
- return 1;
1463
+ // A daemon restart can race the previous instance's port release (TIME_WAIT
1464
+ // / slow shutdown), so a single Bun.serve would EADDRINUSE and the daemon
1465
+ // would exit 1 straight into another restart. Retry with backoff first so a
1466
+ // restart self-heals; only give up (and let the manager back off) if the
1467
+ // port stays held — e.g. by an unrelated/stale process.
1468
+ for (let attempt = 0; ; attempt++) {
1469
+ try {
1470
+ server = Bun.serve(serverOpts);
1471
+ break;
1472
+ } catch (e) {
1473
+ const inUse = (e as { code?: string }).code === "EADDRINUSE";
1474
+ if (inUse && attempt < 5) {
1475
+ await Bun.sleep(Math.min(2000, 250 * 2 ** attempt));
1476
+ continue;
1477
+ }
1478
+ if (inUse) {
1479
+ process.stderr.write(
1480
+ `ay serve: port ${port} is still in use after retries — pick another with --port N,\n` +
1481
+ `or run a port-free WebRTC-only share with: ay serve --webrtc\n`,
1482
+ );
1483
+ return 1;
1484
+ }
1485
+ throw e;
1465
1486
  }
1466
- throw e;
1467
1487
  }
1468
1488
 
1469
1489
  const uiHost = host === "0.0.0.0" || host === "::" ? "127.0.0.1" : host;
@@ -140,6 +140,16 @@ describe("subcommands.matchKeyword", () => {
140
140
  const r = { ...baseRecord, prompt: null };
141
141
  expect(matchKeyword(r, "parser")).toBe(false);
142
142
  });
143
+
144
+ it("matches by agent_id prefix", async () => {
145
+ const { matchKeyword } = await loadModule();
146
+ const r = { ...baseRecord, agent_id: "a1b2c3d4e5f6" };
147
+ expect(matchKeyword(r, "a1b2c3d4e5f6")).toBe(true); // full id
148
+ expect(matchKeyword(r, "a1b2c3")).toBe(true); // prefix
149
+ expect(matchKeyword(r, "A1B2C3")).toBe(true); // case-insensitive
150
+ expect(matchKeyword(r, "b2c3")).toBe(false); // not a prefix (mid-string)
151
+ expect(matchKeyword({ ...baseRecord, agent_id: null }, "a1b2")).toBe(false);
152
+ });
143
153
  });
144
154
 
145
155
  describe("subcommands.runSubcommand routing", () => {
package/ts/subcommands.ts CHANGED
Binary file
@@ -1,8 +0,0 @@
1
- import "./ts-D21pYxoi.js";
2
- import "./logger-B9h0djqx.js";
3
- import "./versionChecker-VKD48fzV.js";
4
- import "./pidStore-CGKIhaJO.js";
5
- import "./globalPidIndex-C7r2m6s7.js";
6
- import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-CRiTrZVs.js";
7
-
8
- export { SUPPORTED_CLIS };
@@ -1,5 +0,0 @@
1
- import "./logger-B9h0djqx.js";
2
- import { t as PidStore } from "./pidStore-CGKIhaJO.js";
3
- import "./globalPidIndex-C7r2m6s7.js";
4
-
5
- export { PidStore };