agent-yes 1.303.1 → 1.304.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.
Files changed (184) hide show
  1. package/README.md +54 -0
  2. package/default.config.yaml +5 -5
  3. package/dist/{JsonlStore-BpYZZTap.js → JsonlStore-CB_0sfdT.js} +5 -4
  4. package/dist/{SUPPORTED_CLIS-Dq9Lq9WJ.js → SUPPORTED_CLIS-C_1IiOj3.js} +2 -2
  5. package/dist/SUPPORTED_CLIS-Do3GHAY1.js +12 -0
  6. package/dist/{agentShare-suB6yPgO.js → agentShare-BvpEm-Fr.js} +10 -9
  7. package/dist/{askCli-BU3CNCLU.js → askCli-KmMf-3wA.js} +6 -6
  8. package/dist/{browser-BmxN1Ur9.js → browser-BAFPmEvN.js} +2 -2
  9. package/dist/{callback-Ctj3_Wxp.js → callback-BiSUhjw7.js} +6 -6
  10. package/dist/callback-SqLD2mMX.js +17 -0
  11. package/dist/{callbackCore-DSJWhqAe.js → callbackCore-BZ_10zyc.js} +1 -1
  12. package/dist/{callbackCore-BesbQ6-Z.js → callbackCore-Deve5pv3.js} +1 -1
  13. package/dist/{channels-j5nWuzlQ.js → channels-Y36S0ccW.js} +2 -2
  14. package/dist/cli.js +118 -13
  15. package/dist/{cmdDsh-2LP0grim.js → cmdDsh-DZ8bLsH7.js} +1 -1
  16. package/dist/cmdKill-CzSBfWmx.js +116 -0
  17. package/dist/{cmdPs-wc1j85fi.js → cmdPs-DBt23Qz0.js} +11 -10
  18. package/dist/{cwdConflictWarn-skQSMwEh.js → cwdConflictWarn-y-epQyOj.js} +21 -5
  19. package/dist/{cwdPassthroughHint-BUbWMoz0.js → cwdPassthroughHint-CzWh0hrw.js} +1 -1
  20. package/dist/{expose-Dawq1LxC.js → expose-Bhsn5yUz.js} +2 -2
  21. package/dist/forceKill-BDqxx4uQ.js +44 -0
  22. package/dist/{forkNested-CavHyWzA.js → forkNested-3heLs5XC.js} +45 -5
  23. package/dist/{globalPidIndex-CRB5KtyL.js → globalPidIndex-BsjlId-h.js} +6 -5
  24. package/dist/{globalPidIndex-BftWlg2V.js → globalPidIndex-uoz8Esqz.js} +2 -2
  25. package/dist/{hist-Cs0KFSUW.js → hist-DY16wm7g.js} +1 -1
  26. package/dist/{identity-DA7YI9km.js → identity-C0MxfwI2.js} +1 -1
  27. package/dist/{identity-Bk-aG_xl.js → identity-Ckav3-Up.js} +1 -1
  28. package/dist/index.js +7 -7
  29. package/dist/{initMsg-CcTqFtsp.js → initMsg-BEVDWYnv.js} +1 -1
  30. package/dist/{initMsg-D9KJnfgC.js → initMsg-GPU52N-j.js} +1 -1
  31. package/dist/liagent/box-BSIrRRc_.js +2320 -0
  32. package/dist/liagent/box-DloywR57.d.ts +409 -0
  33. package/dist/liagent/box.d.ts +3 -0
  34. package/dist/liagent/box.js +3 -0
  35. package/dist/liagent/cli.d.ts +1 -0
  36. package/dist/liagent/cli.js +908 -0
  37. package/dist/liagent/client.d.ts +28 -0
  38. package/dist/liagent/client.js +240 -0
  39. package/dist/liagent/echo-BvzPSI0x.js +86 -0
  40. package/dist/liagent/echo-W2RcMEny.d.ts +38 -0
  41. package/dist/liagent/hub.d.ts +405 -0
  42. package/dist/liagent/hub.js +1831 -0
  43. package/dist/liagent/index.d.ts +14 -0
  44. package/dist/liagent/index.js +10 -0
  45. package/dist/liagent/liagent.js +339 -0
  46. package/dist/liagent/mic-audio-C3Shud_F.js +754 -0
  47. package/dist/liagent/mic-audio-DMCWtEI-.d.ts +317 -0
  48. package/dist/liagent/mic-button-CtZHFBSG.js +651 -0
  49. package/dist/liagent/mic-button-Y0ioPetQ.d.ts +248 -0
  50. package/dist/liagent/mic.d.ts +3 -0
  51. package/dist/liagent/mic.js +4 -0
  52. package/dist/liagent/progress-CJs08bXb.js +473 -0
  53. package/dist/liagent/progress-CfE-meHr.d.ts +205 -0
  54. package/dist/liagent/progress.d.ts +2 -0
  55. package/dist/liagent/progress.js +3 -0
  56. package/dist/liagent/protocol.d.ts +324 -0
  57. package/dist/liagent/protocol.js +504 -0
  58. package/dist/liagent/speech-rate-DXeJjRTc.js +42 -0
  59. package/dist/liagent/state-tree-BZCmAknI.js +353 -0
  60. package/dist/liagent/tree-BrR7NwMf.js +710 -0
  61. package/dist/liagent/tree-HB9RhX_H.d.ts +295 -0
  62. package/dist/liagent/tree.d.ts +2 -0
  63. package/dist/liagent/tree.js +4 -0
  64. package/dist/liagent/ui-strings-B03le3fh.d.ts +27 -0
  65. package/dist/liagent/ui-strings-CJIwW5Gf.js +794 -0
  66. package/dist/liagent/ui.d.ts +394 -0
  67. package/dist/liagent/ui.js +5 -0
  68. package/dist/liagent/voice-D7yeS9VM.js +802 -0
  69. package/dist/liagent/voice-Qo7SCgi8.d.ts +308 -0
  70. package/dist/liagent/voice.d.ts +3 -0
  71. package/dist/liagent/voice.js +4 -0
  72. package/dist/{notifyDaemon-C7GlfJ1E.js → notifyDaemon-DkUB7GV2.js} +10 -9
  73. package/dist/{openBrowser-1cIo4dJL.js → openBrowser-CQAOIrD6.js} +1 -1
  74. package/dist/oxmgrService-DlYHmqyI.js +37 -0
  75. package/dist/oxmgrService-o9L3I6FX.js +3 -0
  76. package/dist/{parentLink-DoEWVGld.js → parentLink-BcAYcO9L.js} +2 -2
  77. package/dist/{parentLink-B58V1RVd.js → parentLink-MBUD3oY2.js} +2 -2
  78. package/dist/{parentPingLoop-C73bbmCE.js → parentPingLoop-DDO592Wh.js} +5 -5
  79. package/dist/{pidStore-433kvh9D.js → pidStore-C50VPk3E.js} +3 -3
  80. package/dist/pidStore-COkPjpW8.js +6 -0
  81. package/dist/{procStats-BvmrBrOs.js → procStats-DwTxj3rs.js} +1 -1
  82. package/dist/{remotes-MfdV9M8u.js → remotes-BqLoB5GR.js} +2 -2
  83. package/dist/{remotes-DevcBeLl.js → remotes-BsMGvAay.js} +3 -3
  84. package/dist/{roomReplyAlias-DFqg_6IU.js → roomReplyAlias-B-v76TA8.js} +3 -3
  85. package/dist/roomReplyAlias-BzWUBkQy.js +6 -0
  86. package/dist/{rustBinary-7VK7oLlW.js → rustBinary-BrJ2p8wy.js} +2 -2
  87. package/dist/{rustBinary-BV4LxMMn.js → rustBinary-vpfpWj1q.js} +2 -2
  88. package/dist/{schedule-Dp0qkNO1.js → schedule-Bzjhl6-h.js} +15 -44
  89. package/dist/schedulesCli-CLqieyQZ.js +784 -0
  90. package/dist/senderAncestry-CVHeKk1Y.js +173 -0
  91. package/dist/senderAncestry-KhAUPCQs.js +3 -0
  92. package/dist/{serve-BpOIIOVc.js → serve-XwFYE0cE.js} +67 -69
  93. package/dist/{serveRust-CbBrcUrg.js → serveRust-BfWkeL6T.js} +31 -4
  94. package/dist/{setup-DdIBk6Iv.js → setup-D4-s2VZw.js} +5 -5
  95. package/dist/{share-w5oRbvlj.js → share-CbFetL5H.js} +1 -1
  96. package/dist/{share-DrS3LYqf.js → share-_TPYAGWC.js} +1 -1
  97. package/dist/{shareCmd-DDENkBW2.js → shareCmd-DUBsVI3e.js} +10 -10
  98. package/dist/spawnGate-Dfj9V76w.js +5 -0
  99. package/dist/{spawnGate-lr3tvA6U.js → spawnGate-Dj_WaS29.js} +3 -3
  100. package/dist/{subcommands-DxgvDmZX.js → subcommands-B7YZJL8n.js} +471 -307
  101. package/dist/subcommands-BZPxFgkT.js +15 -0
  102. package/dist/{systemPathLink-SjUzgSiq.js → systemPathLink-Y3iC7bYV.js} +1 -1
  103. package/dist/{terminal-C2h7tpe0.js → terminal-13cGj3h6.js} +2 -2
  104. package/dist/terminal.js +1 -1
  105. package/dist/{todoAutomation-TTp_Qz9G.js → todoAutomation-CKlrxuZv.js} +2 -2
  106. package/dist/{todoCli-BWm5nZE0.js → todoCli-CU9vSJSJ.js} +6 -6
  107. package/dist/{todoIdentity-BvXZKWJI.js → todoIdentity-CzS1e7VL.js} +2 -2
  108. package/dist/{todoStore-C9RTz0Vs.js → todoStore-msRCEUi1.js} +2 -2
  109. package/dist/{tray-BeRSozJz.js → tray-CLktEN3G.js} +1 -1
  110. package/dist/{trayApp-QQjqhDv1.js → trayApp-5_OlvQcz.js} +2 -2
  111. package/dist/trayApp-DkAPo0m6.js +5 -0
  112. package/dist/{ts-6LF7f4fx.js → ts-njuddXQz.js} +126 -57
  113. package/dist/{versionChecker-Bc62HNf6.js → versionChecker-BJycAanp.js} +2 -2
  114. package/dist/{webrtcLink-va_gAR77.js → webrtcLink-DcvacEci.js} +1 -1
  115. package/dist/{webrtcLink-SsInrVHU.js → webrtcLink-WxS1nTIs.js} +1 -1
  116. package/dist/{webrtcRemote-BlGyNZDC.js → webrtcRemote-C3xQyf3u.js} +2 -2
  117. package/dist/{widget-Crb5zeHL.js → widget-DmRwOlco.js} +3 -3
  118. package/dist/widgets.js +1 -1
  119. package/dist/{workspaceConfig-BLWB5Wu9.js → workspaceConfig-DBgsu81B.js} +1 -1
  120. package/dist/{ws-DIbwNz8Z.js → ws-ByO6JO6m.js} +3 -3
  121. package/dist/{ws-BRhPG1Vy.js → ws-D0-Jg88z.js} +9 -8
  122. package/lab/ui/index.html +1 -1
  123. package/lab/ui/lab/posts/2026-08-11-slack-term-safe-writes.md +1 -1
  124. package/package.json +73 -8
  125. package/ts/JsonlStore.ts +10 -3
  126. package/ts/cli-idle.bun.spec.ts +1 -1
  127. package/ts/cli-idle.spec.ts +1 -1
  128. package/ts/cli.ts +35 -0
  129. package/ts/cmdKill.bun.spec.ts +155 -0
  130. package/ts/cmdKill.spec.ts +155 -0
  131. package/ts/cmdKill.ts +183 -0
  132. package/ts/composerGuard.edges.spec.ts +91 -0
  133. package/ts/composerGuard.spec.ts +53 -6
  134. package/ts/composerGuard.ts +42 -13
  135. package/ts/conptyModeFilter.spec.ts +30 -0
  136. package/ts/conptyModeFilter.ts +53 -0
  137. package/ts/copyLiagent.ts +42 -0
  138. package/ts/cwdConflictWarn.io.spec.ts +50 -0
  139. package/ts/cwdConflictWarn.spec.ts +34 -1
  140. package/ts/cwdConflictWarn.ts +43 -5
  141. package/ts/cwdGuard.spec.ts +110 -0
  142. package/ts/cwdGuard.ts +118 -0
  143. package/ts/forceKill.ts +52 -0
  144. package/ts/forkNested.bun.spec.ts +41 -0
  145. package/ts/forkNested.spec.ts +41 -0
  146. package/ts/forkNested.ts +48 -1
  147. package/ts/globalPidIndex.edges.spec.ts +125 -0
  148. package/ts/globalPidIndex.ts +6 -2
  149. package/ts/index.ts +13 -1
  150. package/ts/interruptSend.bun.spec.ts +99 -0
  151. package/ts/interruptSend.spec.ts +99 -0
  152. package/ts/interruptSend.ts +51 -0
  153. package/ts/lockRegistry.spec.ts +49 -0
  154. package/ts/lsRenderCache.spec.ts +58 -0
  155. package/ts/needsInput.edges.spec.ts +23 -0
  156. package/ts/parseCliArgs.ts +7 -0
  157. package/ts/pushGatePlan.spec.ts +147 -0
  158. package/ts/roomReplyAlias.io.spec.ts +81 -0
  159. package/ts/schedule.ts +5 -1
  160. package/ts/schedules.bun.spec.ts +397 -0
  161. package/ts/schedules.spec.ts +397 -0
  162. package/ts/schedules.ts +517 -0
  163. package/ts/schedulesCli.ts +386 -0
  164. package/ts/sendControl.bun.spec.ts +12 -0
  165. package/ts/senderAncestry.ts +1 -3
  166. package/ts/serve.ts +22 -33
  167. package/ts/serveRust.spec.ts +29 -2
  168. package/ts/serveRust.ts +27 -2
  169. package/ts/sizeNego.bun.spec.ts +9 -2
  170. package/ts/sizeNego.spec.ts +9 -2
  171. package/ts/sizeNego.ts +10 -5
  172. package/ts/subcommands.spec.ts +348 -9
  173. package/ts/subcommands.ts +513 -93
  174. package/ts/suggestAgents.spec.ts +33 -0
  175. package/ts/terminal/browser.ts +1 -1
  176. package/ts/todoParse.spec.ts +22 -1
  177. package/ts/todoParse.ts +19 -0
  178. package/dist/SUPPORTED_CLIS-ByO5twge.js +0 -12
  179. package/dist/callback-D7qfh_7p.js +0 -16
  180. package/dist/pidStore-BRlKRHXY.js +0 -6
  181. package/dist/roomReplyAlias-DuEkSSDI.js +0 -6
  182. package/dist/spawnGate-DeQBTX-o.js +0 -5
  183. package/dist/subcommands-DmiswRy4.js +0 -14
  184. package/dist/trayApp-C4TAvRvU.js +0 -5
@@ -34,9 +34,9 @@ describe("negotiateSize", () => {
34
34
  });
35
35
  it("phone + desktop: elementwise min (the tmux rule)", () => {
36
36
  // phone is narrow but tall, desktop is wide but short → min of each axis
37
- const phone = { cols: 51, rows: 60 };
37
+ const phone = { cols: 91, rows: 60 };
38
38
  const desktop = { cols: 200, rows: 50 };
39
- expect(negotiateSize([phone, desktop])).toEqual({ cols: 51, rows: 50 });
39
+ expect(negotiateSize([phone, desktop])).toEqual({ cols: 91, rows: 50 });
40
40
  });
41
41
  it("clamps to the floor so a tiny viewer can't wedge the agent", () => {
42
42
  expect(negotiateSize([{ cols: 20, rows: 5 }])).toEqual({
@@ -44,6 +44,13 @@ describe("negotiateSize", () => {
44
44
  rows: NEGO_FLOOR_ROWS,
45
45
  });
46
46
  });
47
+ it("a narrow viewer letterboxes at 80 cols instead of hard-wrapping the agent", () => {
48
+ expect(negotiateSize([{ cols: 63, rows: 40 }])).toEqual({ cols: 80, rows: 40 });
49
+ });
50
+ it("a narrower operator terminal lowers the floor (never outgrow a real tty)", () => {
51
+ const local = { cols: 70, rows: 50 };
52
+ expect(negotiateSize([{ cols: 63, rows: 40 }, local], local)).toEqual({ cols: 70, rows: 40 });
53
+ });
47
54
  it("three viewers: min wins per axis", () => {
48
55
  expect(
49
56
  negotiateSize([
@@ -34,9 +34,9 @@ describe("negotiateSize", () => {
34
34
  });
35
35
  it("phone + desktop: elementwise min (the tmux rule)", () => {
36
36
  // phone is narrow but tall, desktop is wide but short → min of each axis
37
- const phone = { cols: 51, rows: 60 };
37
+ const phone = { cols: 91, rows: 60 };
38
38
  const desktop = { cols: 200, rows: 50 };
39
- expect(negotiateSize([phone, desktop])).toEqual({ cols: 51, rows: 50 });
39
+ expect(negotiateSize([phone, desktop])).toEqual({ cols: 91, rows: 50 });
40
40
  });
41
41
  it("clamps to the floor so a tiny viewer can't wedge the agent", () => {
42
42
  expect(negotiateSize([{ cols: 20, rows: 5 }])).toEqual({
@@ -44,6 +44,13 @@ describe("negotiateSize", () => {
44
44
  rows: NEGO_FLOOR_ROWS,
45
45
  });
46
46
  });
47
+ it("a narrow viewer letterboxes at 80 cols instead of hard-wrapping the agent", () => {
48
+ expect(negotiateSize([{ cols: 63, rows: 40 }])).toEqual({ cols: 80, rows: 40 });
49
+ });
50
+ it("a narrower operator terminal lowers the floor (never outgrow a real tty)", () => {
51
+ const local = { cols: 70, rows: 50 };
52
+ expect(negotiateSize([{ cols: 63, rows: 40 }, local], local)).toEqual({ cols: 70, rows: 40 });
53
+ });
47
54
  it("three viewers: min wins per axis", () => {
48
55
  expect(
49
56
  negotiateSize([
package/ts/sizeNego.ts CHANGED
@@ -24,9 +24,11 @@ const CAP_MIN_ROWS = 5;
24
24
  const CAP_MAX_COLS = 500;
25
25
  const CAP_MAX_ROWS = 200;
26
26
 
27
- /** Never negotiate below this — TUIs (claude, codex) break down when the grid
28
- * gets absurdly narrow, so a tiny watch-sized viewer can't wedge the agent. */
29
- export const NEGO_FLOOR_COLS = 40;
27
+ /** Never negotiate below this. A narrower viewer letterboxes instead: below 80
28
+ * cols TUIs hard-wrap, and the wrapped text is what `ay read` / other agents get
29
+ * from the log, long after that viewer has gone. Lowered to the operator's own
30
+ * terminal width when that is narrower (never grow the PTY past a real tty). */
31
+ export const NEGO_FLOOR_COLS = 80;
30
32
  export const NEGO_FLOOR_ROWS = 10;
31
33
 
32
34
  /** Parse a presence-reported cap into a sane SizeCap, or null if unusable. */
@@ -44,7 +46,10 @@ export function sanitizeCap(cap: unknown): SizeCap | null {
44
46
  * Returns null when no viewer reports a capacity — meaning "withdraw the
45
47
  * negotiated size, let the real tty size rule again".
46
48
  */
47
- export function negotiateSize(caps: ReadonlyArray<SizeCap>): SizeCap | null {
49
+ export function negotiateSize(
50
+ caps: ReadonlyArray<SizeCap>,
51
+ local: SizeCap | null = null,
52
+ ): SizeCap | null {
48
53
  let cols = Infinity;
49
54
  let rows = Infinity;
50
55
  for (const cap of caps) {
@@ -53,7 +58,7 @@ export function negotiateSize(caps: ReadonlyArray<SizeCap>): SizeCap | null {
53
58
  }
54
59
  if (!Number.isFinite(cols) || !Number.isFinite(rows)) return null;
55
60
  return {
56
- cols: Math.max(NEGO_FLOOR_COLS, cols),
61
+ cols: Math.max(Math.min(NEGO_FLOOR_COLS, local?.cols ?? Infinity), cols),
57
62
  rows: Math.max(NEGO_FLOOR_ROWS, rows),
58
63
  };
59
64
  }
@@ -117,10 +117,17 @@ describe("subcommands.readLogForRender", () => {
117
117
  });
118
118
 
119
119
  describe("subcommands.controlCodeFromName", () => {
120
+ it("confirms submit codes while excluding cancellation and navigation", async () => {
121
+ const { isSubmitCode } = await loadModule();
122
+ for (const code of ["\r", "\x1bm"]) expect(isSubmitCode(code)).toBe(true);
123
+ for (const code of ["\x1b", "\x03", "\t", ""]) expect(isSubmitCode(code)).toBe(false);
124
+ });
120
125
  it("maps named codes to the right control bytes", async () => {
121
126
  const { controlCodeFromName } = await loadModule();
122
127
  expect(controlCodeFromName("enter")).toBe("\r");
123
128
  expect(controlCodeFromName("cr")).toBe("\r");
129
+ expect(controlCodeFromName("alt-m")).toBe("\x1bm");
130
+ expect(controlCodeFromName("alt+m")).toBe("\x1bm");
124
131
  expect(controlCodeFromName("esc")).toBe("\x1b");
125
132
  expect(controlCodeFromName("ctrl-c")).toBe("\x03");
126
133
  expect(controlCodeFromName("ctrl-y")).toBe("\x19");
@@ -205,7 +212,10 @@ describe("subcommands.isSubcommand", () => {
205
212
  // `read` / `share` / `connect` are ordinary English verbs: `cy read ts/cli.ts
206
213
  // and explain it` and `cy connect the frontend to the API` must reach claude.
207
214
  // The commands live on the manager entry (`ay read`, `ay share`, `ay connect`).
208
- for (const sub of ["read", "share", "connect"]) {
215
+ // `kill` likewise: `cy kill the stale dev server on :3000` is a prompt.
216
+ // `cron` / `schedules` / `sched` manage the host (`ay cron …`), so
217
+ // `cy cron job is broken, fix it` must also stay a prompt.
218
+ for (const sub of ["read", "share", "connect", "kill", "cron", "schedules", "sched"]) {
209
219
  expect(isSubcommand(sub, true)).toBe(true);
210
220
  expect(isSubcommand(sub, false)).toBe(false);
211
221
  }
@@ -887,7 +897,9 @@ describe("subcommands.cmdLs human table", () => {
887
897
  pid: process.pid,
888
898
  cli: "claude",
889
899
  prompt: "table format test",
890
- cwd: process.cwd(),
900
+ // A non-repo cwd: in a repo the NOTE column leads with the branch, and a
901
+ // long branch name truncates the prompt this test looks for.
902
+ cwd: testHome,
891
903
  log_file: null,
892
904
  status: "active",
893
905
  exit_code: null,
@@ -897,7 +909,7 @@ describe("subcommands.cmdLs human table", () => {
897
909
 
898
910
  const cap = captureStdout();
899
911
  try {
900
- const code = await runSubcommand(["bun", "cli.js", "ls"]);
912
+ const code = await runSubcommand(["bun", "cli.js", "ls", "--cwd", testHome]);
901
913
  expect(code).toBe(0);
902
914
  } finally {
903
915
  cap.restore();
@@ -1432,7 +1444,10 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1432
1444
  * false-positive guard below deliberately treats as NOT confirmed).
1433
1445
  */
1434
1446
  async function withFifo(
1435
- fn: (fifo: string, onKeystroke: () => Promise<boolean>) => Promise<void>,
1447
+ fn: (
1448
+ fifo: string,
1449
+ onKeystroke: (timeoutMs?: number, observe?: (bytes: string) => void) => Promise<boolean>,
1450
+ ) => Promise<void>,
1436
1451
  ) {
1437
1452
  const { spawnSync } = await import("child_process");
1438
1453
  const dir = await mkdtemp(path.join(tmpdir(), "ay-confirm-"));
@@ -1446,12 +1461,19 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1446
1461
  // keystroke is still here to be observed. O_NONBLOCK is load-bearing —
1447
1462
  // a blocking readSync on an empty fifo wedges the whole vitest worker.
1448
1463
  const readFd = fs.openSync(fifo, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
1449
- const onKeystroke = async (timeoutMs = 5_000): Promise<boolean> => {
1464
+ const onKeystroke = async (
1465
+ timeoutMs = 5_000,
1466
+ observe?: (bytes: string) => void,
1467
+ ): Promise<boolean> => {
1450
1468
  const buf = Buffer.alloc(64);
1451
1469
  const deadline = Date.now() + timeoutMs;
1452
1470
  while (Date.now() < deadline) {
1453
1471
  try {
1454
- if (fs.readSync(readFd, buf, 0, buf.length, null) > 0) return true;
1472
+ const count = fs.readSync(readFd, buf, 0, buf.length, null);
1473
+ if (count > 0) {
1474
+ observe?.(buf.subarray(0, count).toString());
1475
+ return true;
1476
+ }
1455
1477
  } catch (err: any) {
1456
1478
  if (err?.code !== "EAGAIN") throw err; // EAGAIN = nothing yet
1457
1479
  }
@@ -1470,6 +1492,66 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1470
1492
  }
1471
1493
  }
1472
1494
 
1495
+ it.skipIf(!itUnix).each([
1496
+ ["agy", "\r"],
1497
+ ["claude", "\r"],
1498
+ ["codex", "\r"],
1499
+ ["agy", "\x1bm"],
1500
+ ])("delivers %s submit %j without substituting a cancellation key", async (cli, code) => {
1501
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-immediate-"));
1502
+ try {
1503
+ const log = path.join(dir, "agent.log");
1504
+ const marker = "<ay-msg abc12345";
1505
+ const prompt = cli === "agy" ? ">" : "❯";
1506
+ const busy = cli === "agy" ? "Running command..." : "Working (esc to interrupt)";
1507
+ await writeFile(log, `${busy}\r\n${prompt} ${marker}\r\nAlt+M to send immediately\r\n`);
1508
+ const { submitAndConfirm } = await loadModule();
1509
+ await withFifo(async (fifo, onKeystroke) => {
1510
+ let bytes = "";
1511
+ const reaction = onKeystroke(5000, (value) => {
1512
+ bytes = value;
1513
+ }).then(async (got) => {
1514
+ if (got) await writeFile(log, `${prompt} ${marker}\r\nAccepted\r\n${prompt}\r\n`);
1515
+ return got;
1516
+ });
1517
+ const result = await submitAndConfirm(rec({ cli, log_file: log }), fifo, code, marker);
1518
+ expect(await reaction).toBe(true);
1519
+ expect(bytes).toBe(code);
1520
+ expect(result.submission).toBe("submitted");
1521
+ expect(result.confirmed).toBe(true);
1522
+ });
1523
+ } finally {
1524
+ await rm(dir, { recursive: true, force: true });
1525
+ }
1526
+ });
1527
+
1528
+ it.skipIf(!itUnix)(
1529
+ "never retries an explicit immediate shortcut even when input stays in the composer",
1530
+ async () => {
1531
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-immediate-once-"));
1532
+ try {
1533
+ const log = path.join(dir, "agent.log");
1534
+ const marker = "<ay-msg abc12345";
1535
+ await writeFile(log, `> ${marker}\r\nAlt+M to send immediately\r\n`);
1536
+ const { submitAndConfirm } = await loadModule();
1537
+ await withFifo(async (fifo, onKeystroke) => {
1538
+ const received = onKeystroke();
1539
+ const result = await submitAndConfirm(
1540
+ rec({ cli: "agy", log_file: log }),
1541
+ fifo,
1542
+ "\x1bm",
1543
+ marker,
1544
+ );
1545
+ expect(await received).toBe(true);
1546
+ expect(result.confirmed).toBe(false);
1547
+ expect(await onKeystroke(100)).toBe(false);
1548
+ });
1549
+ } finally {
1550
+ await rm(dir, { recursive: true, force: true });
1551
+ }
1552
+ },
1553
+ );
1554
+
1473
1555
  it.skipIf(!itUnix)(
1474
1556
  "confirms on the first attempt when the busy marker newly appears after sending",
1475
1557
  async () => {
@@ -1694,6 +1776,17 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1694
1776
  }
1695
1777
  });
1696
1778
 
1779
+ it("confirms a send to agy, whose prompt row is a plain `>`", async () => {
1780
+ // Regression: agy received every message, but with no `❯` row on screen
1781
+ // `ay send` reported NOT SUBMITTED (rc 1) each time.
1782
+ const { submissionState } = await loadModule();
1783
+ const marker = "<ay-msg abc12345";
1784
+ const rule = "─".repeat(40);
1785
+ const sent = [rule, `> ${marker} from claude`, " …", "", " Done.", rule, ">", rule];
1786
+ expect(submissionState([...sent, "? for shortcuts"], marker, "agy")).toBe("submitted");
1787
+ expect(submissionState([rule, `> ${marker}`, rule], marker, "agy")).toBe("not-submitted");
1788
+ });
1789
+
1697
1790
  it("requires our identity to move out of the composer into the transcript", async () => {
1698
1791
  const { submissionState, inspectSubmission } = await loadModule();
1699
1792
  const marker = "<ay-msg abc12345";
@@ -1712,6 +1805,127 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1712
1805
  });
1713
1806
  });
1714
1807
 
1808
+ // A long message queued behind a busy Claude is echoed in full above the
1809
+ // composer; its `<ay-msg NONCE` header scrolls out of the rendered window and
1810
+ // only the closing `</ay-msg NONCE>` tag is left to attribute it.
1811
+ it("counts the closing tag as our identity when the header has scrolled away", async () => {
1812
+ const { submissionState, inspectSubmission } = await loadModule();
1813
+ const marker = "<ay-msg abc12345";
1814
+ const queued = [
1815
+ " line 18: body",
1816
+ " </ay-msg abc12345>",
1817
+ " ctrl+x ctrl+s to send now",
1818
+ "✻ Working… (20s)",
1819
+ "────────",
1820
+ "❯ Press up to edit queued messages",
1821
+ "────────",
1822
+ " paste again to expand",
1823
+ ];
1824
+ expect(submissionState(queued, marker)).toBe("queued");
1825
+ expect(
1826
+ submissionState([" </ay-msg abc12345>", "❯", "────────", " ? for shortcuts"], marker),
1827
+ ).toBe("submitted");
1828
+ // Still in the composer: the closing tag below the prompt row is not evidence.
1829
+ expect(
1830
+ inspectSubmission(
1831
+ ["────────", "❯ line 18: body", " </ay-msg abc12345>", "────────"],
1832
+ marker,
1833
+ ),
1834
+ ).toMatchObject({ submission: "not-submitted", inComposer: true, transcriptMatches: 0 });
1835
+ // Another message's closing tag is not ours.
1836
+ expect(submissionState([" </ay-msg ffff0000>", "❯", "────────"], marker)).toBe(
1837
+ "not-submitted",
1838
+ );
1839
+ });
1840
+
1841
+ it.skipIf(!itUnix)(
1842
+ "reports a long collapsed paste queued behind a busy Claude as queued, not unsubmitted",
1843
+ async () => {
1844
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-queued-long-"));
1845
+ try {
1846
+ const log = path.join(dir, "a.log");
1847
+ const marker = "<ay-msg abc12345";
1848
+ const paste = "[Pasted text #1 +60 lines]";
1849
+ await writeFile(log, `✻ Working… (5s)\r\n────────\r\n❯ ${paste}\r\n────────\r\n`);
1850
+ const { submitAndConfirm } = await loadModule();
1851
+ await withFifo(async (fifo, onKeystroke) => {
1852
+ const reaction = onKeystroke().then((got) => {
1853
+ if (got) {
1854
+ const body = Array.from({ length: 60 }, (_, i) => ` line ${i}: body`);
1855
+ appendFileSync(
1856
+ log,
1857
+ "\x1b[2J\x1b[H" +
1858
+ [
1859
+ ` ${marker} from alice>`,
1860
+ ...body,
1861
+ " </ay-msg abc12345>",
1862
+ " ctrl+x ctrl+s to send now",
1863
+ "✻ Working… (6s)",
1864
+ "────────",
1865
+ "❯ Press up to edit queued messages",
1866
+ "────────",
1867
+ " paste again to expand",
1868
+ ].join("\r\n") +
1869
+ "\r\n",
1870
+ );
1871
+ }
1872
+ return got;
1873
+ });
1874
+ const result = await submitAndConfirm(rec({ log_file: log }), fifo, "\r", marker, [
1875
+ "✻ Working… (5s)",
1876
+ "────────",
1877
+ "❯",
1878
+ "────────",
1879
+ ]);
1880
+ expect(await reaction).toBe(true);
1881
+ expect(result.submission).toBe("queued");
1882
+ });
1883
+ } finally {
1884
+ await rm(dir, { recursive: true, force: true });
1885
+ }
1886
+ },
1887
+ 10_000,
1888
+ );
1889
+
1890
+ // While Claude is busy it redraws only the spinner row, so the last 32 KB of
1891
+ // the log can hold neither the composer box nor the message queued above it;
1892
+ // a tail render then shows "Press up to edit queued messages" with no prompt
1893
+ // row, which cannot be attributed. The confirm must render from further back.
1894
+ it.skipIf(!itUnix)(
1895
+ "renders past spinner-only redraws to see the box when confirming a queued send",
1896
+ async () => {
1897
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-queued-redraw-"));
1898
+ try {
1899
+ const log = path.join(dir, "a.log");
1900
+ const marker = "<ay-msg abc12345";
1901
+ // history / spinner / rule / prompt / rule / footer, cursor parked below.
1902
+ let raw = "history\r\n✻ Working… 0\r\n────────\r\n❯ \r\n────────\r\n ? for shortcuts\r\n";
1903
+ for (let i = 1; raw.length < 64 * 1024; i++)
1904
+ raw += `\x1b[5A\r\x1b[2K✻ Working… ${i}\x1b[5B\r`;
1905
+ await writeFile(log, raw);
1906
+ const { submitAndConfirm } = await loadModule();
1907
+ await withFifo(async (fifo, onKeystroke) => {
1908
+ const reaction = onKeystroke().then((got) => {
1909
+ // Only the changed cells: the echoed message's last row over the
1910
+ // spinner, and the hint after the (unchanged) `❯ ` of the prompt row.
1911
+ if (got)
1912
+ appendFileSync(
1913
+ log,
1914
+ "\x1b[5A\r\x1b[2K </ay-msg abc12345>\x1b[2B\r\x1b[2CPress up to edit queued messages\x1b[3B\r",
1915
+ );
1916
+ return got;
1917
+ });
1918
+ const result = await submitAndConfirm(rec({ log_file: log }), fifo, "\r", marker);
1919
+ expect(await reaction).toBe(true);
1920
+ expect(result.submission).toBe("queued");
1921
+ });
1922
+ } finally {
1923
+ await rm(dir, { recursive: true, force: true });
1924
+ }
1925
+ },
1926
+ 10_000,
1927
+ );
1928
+
1715
1929
  // Codex review (2ecc427): the last prompt-looking row was taken for the prompt,
1716
1930
  // so a quoted `› line` inside our unsent message put its nonce in "transcript".
1717
1931
  it("does not take a quoted prompt glyph inside our unsent message for the prompt", async () => {
@@ -2012,6 +2226,83 @@ describe("subcommands.cmdSend end-to-end submit-confirm wiring", () => {
2012
2226
  }
2013
2227
  }
2014
2228
 
2229
+ it.skipIf(!itUnix).each(["--interrupt", "-i"])(
2230
+ "%s cancels before pasting and waits for idle even with --no-wait",
2231
+ async (flag) => {
2232
+ const log = path.join(testHome, "interrupt.log");
2233
+ const box = "────────\r\n❯ \r\n────────\r\n";
2234
+ await writeFile(log, BUSY + box);
2235
+ const chunks: string[] = [];
2236
+ let idleDrawn = false;
2237
+ let pastedBeforeIdle = false;
2238
+ let transition: ReturnType<typeof setTimeout> | undefined;
2239
+ try {
2240
+ await withDrainedFifo(
2241
+ async (fifo) => {
2242
+ const result = await send(fifo, log, "replacement-task", [flag, "--no-wait"]);
2243
+ await new Promise((resolve) => setTimeout(resolve, 40));
2244
+ expect(result.code).toBe(0);
2245
+ },
2246
+ (bytes) => {
2247
+ chunks.push(bytes);
2248
+ if (bytes === "\x1b")
2249
+ transition = setTimeout(() => {
2250
+ appendFileSync(log, "\x1b[2J\x1b[H" + box);
2251
+ idleDrawn = true;
2252
+ }, 150);
2253
+ if (bytes.includes("replacement-task") && !idleDrawn) pastedBeforeIdle = true;
2254
+ },
2255
+ );
2256
+ expect(chunks[0]).toBe("\x1b");
2257
+ expect(chunks.join("")).toContain("replacement-task");
2258
+ expect(chunks.join("").endsWith("\r")).toBe(true);
2259
+ expect(pastedBeforeIdle).toBe(false);
2260
+ expect(idleDrawn).toBe(true);
2261
+ } finally {
2262
+ if (transition) clearTimeout(transition);
2263
+ }
2264
+ },
2265
+ );
2266
+
2267
+ it("send --help documents interrupt and its short alias without needing a target", async () => {
2268
+ const { runSubcommand } = await loadModule();
2269
+ const out = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2270
+ try {
2271
+ expect(await runSubcommand(["bun", "cli.js", "send", "--help"])).toBe(0);
2272
+ const help = out.mock.calls.map(([value]) => String(value)).join("");
2273
+ expect(help).toContain("--interrupt");
2274
+ expect(help).toContain("-i");
2275
+ expect(help).toContain("permission/confirmation");
2276
+ } finally {
2277
+ out.mockRestore();
2278
+ }
2279
+ });
2280
+
2281
+ it("reports a permission prompt without writing a cancellation key", async () => {
2282
+ const log = path.join(testHome, "permission.log");
2283
+ await writeFile(
2284
+ log,
2285
+ BUSY + "Do you want to allow this command?\r\n❯ 1. Allow\r\n 2. Deny\r\n",
2286
+ );
2287
+ const { interruptSendTarget } = await loadModule();
2288
+ const notice = await interruptSendTarget(
2289
+ {
2290
+ pid: 1111,
2291
+ cli: "claude",
2292
+ cwd: "/repo/alpha",
2293
+ prompt: null,
2294
+ log_file: log,
2295
+ status: "active",
2296
+ exit_code: null,
2297
+ exit_reason: null,
2298
+ started_at: 0,
2299
+ },
2300
+ path.join(testHome, "nonexistent.fifo"),
2301
+ );
2302
+ expect(notice).toContain("permission/confirmation prompt");
2303
+ expect(notice).toContain("sending as usual");
2304
+ });
2305
+
2015
2306
  it.skipIf(!itUnix)(
2016
2307
  "exits 0 and reports 'sent' when a working marker appears after the Enter (genuine confirm)",
2017
2308
  async () => {
@@ -2070,7 +2361,8 @@ describe("subcommands.cmdSend end-to-end submit-confirm wiring", () => {
2070
2361
  const errs: string[] = [];
2071
2362
  const origErr = process.stderr.write.bind(process.stderr);
2072
2363
  process.stderr.write = ((c: string | Uint8Array) => (
2073
- errs.push(String(c)), true
2364
+ errs.push(String(c)),
2365
+ true
2074
2366
  )) as typeof process.stderr.write;
2075
2367
  let res: { code: number | null; stdout: string };
2076
2368
  try {
@@ -4744,6 +5036,53 @@ describe("readComposerState on a lane idle for hours", { timeout: 60_000 }, () =
4744
5036
  return readComposerState({ pid: 1111, cli, log_file: file } as never, windows);
4745
5037
  }
4746
5038
 
5039
+ describe("submitStableDraft", () => {
5040
+ async function setup(draft: string) {
5041
+ const { submitStableDraft } = await loadModule();
5042
+ const n = 2000 + logs++;
5043
+ const log_file = path.join(testHome, `${n}.raw.log`);
5044
+ const fifo_file = path.join(testHome, `${n}.fifo`);
5045
+ await writeFile(log_file, idleLog(draft));
5046
+ await writeFile(fifo_file, "");
5047
+ const record = { pid: n, cli: "claude", log_file, fifo_file } as never;
5048
+ return { submitStableDraft, record, log_file, fifo_file };
5049
+ }
5050
+
5051
+ // writeToIpc connects to a named pipe on Windows; this fake FIFO is a plain file.
5052
+ it.skipIf(process.platform === "win32")(
5053
+ "submits a draft that is unchanged at every check, then sees the box clear",
5054
+ async () => {
5055
+ const { submitStableDraft, record, log_file, fifo_file } = await setup("btw how");
5056
+ const waits: number[] = [];
5057
+ const sent = await submitStableDraft(record, [1, 2, 4, 8], async (ms) => {
5058
+ waits.push(ms);
5059
+ // Once Enter has been written, the CLI redraws an empty box.
5060
+ if ((await readFile(fifo_file, "utf-8")).includes("\r"))
5061
+ await writeFile(log_file, idleLog(""));
5062
+ });
5063
+ expect(sent).toBe(true);
5064
+ expect(waits.slice(0, 4)).toEqual([1, 2, 4, 8]);
5065
+ expect(await readFile(fifo_file, "utf-8")).toBe("\r");
5066
+ },
5067
+ );
5068
+
5069
+ it("leaves a draft alone when it changes between checks (someone is typing)", async () => {
5070
+ const { submitStableDraft, record, log_file, fifo_file } = await setup("btw how");
5071
+ let n = 0;
5072
+ const sent = await submitStableDraft(record, [1, 2, 4, 8], async () => {
5073
+ if (++n === 2) await writeFile(log_file, idleLog("btw how are you"));
5074
+ });
5075
+ expect(sent).toBe(false);
5076
+ expect(await readFile(fifo_file, "utf-8")).toBe("");
5077
+ });
5078
+
5079
+ it("does nothing for an empty box", async () => {
5080
+ const { submitStableDraft, record, fifo_file } = await setup("");
5081
+ expect(await submitStableDraft(record, [1], async () => {})).toBe(false);
5082
+ expect(await readFile(fifo_file, "utf-8")).toBe("");
5083
+ });
5084
+ });
5085
+
4747
5086
  it("reads the empty composer drawn before the last 32 KB, not the transcript", async () => {
4748
5087
  // The 32 KB tail alone renders the old turn as the prompt and its answer as a draft.
4749
5088
  expect(await stateOf(idleLog(""))).toEqual({ kind: "empty", ghost: false });
@@ -4776,8 +5115,8 @@ describe("readComposerState on a lane idle for hours", { timeout: 60_000 }, () =
4776
5115
  kind: "hidden",
4777
5116
  reason: "its input box is not on screen",
4778
5117
  });
4779
- // CLIs without a box keep reading the last prompt row in the 32 KB tail.
4780
- expect((await stateOf(turn.repeat(3000), "codex")).kind).toBe("draft");
5118
+ // Codex has no rule, but a prompt row with no footer under it is history too.
5119
+ expect((await stateOf(turn.repeat(3000), "codex")).kind).toBe("hidden");
4781
5120
  });
4782
5121
 
4783
5122
  it("follows what is appended after the first reading, and a truncated log", async () => {