agent-yes 1.299.1 → 1.300.1

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 (51) hide show
  1. package/README.md +9 -0
  2. package/default.config.yaml +12 -0
  3. package/dist/{SUPPORTED_CLIS-MftynU62.js → SUPPORTED_CLIS-BUn4zN_B.js} +3 -3
  4. package/dist/{SUPPORTED_CLIS-YZvIGQvw.js → SUPPORTED_CLIS-DWZDaH9f.js} +2 -2
  5. package/dist/{agentShare-dKQQSOD7.js → agentShare-DpJmCvJ2.js} +3 -3
  6. package/dist/{callback-BEbbWLKe.js → callback-BW73zdcS.js} +3 -3
  7. package/dist/{callback-DWxTSlly.js → callback-DQrYImyf.js} +3 -3
  8. package/dist/cli.js +5 -5
  9. package/dist/{cmdPs-D7HWttUU.js → cmdPs-DBt-LD-H.js} +3 -3
  10. package/dist/index.js +2 -2
  11. package/dist/{notifyDaemon-B0aU7koS.js → notifyDaemon-BkuOBb_g.js} +3 -3
  12. package/dist/{parentPingLoop-DSiOXQeU.js → parentPingLoop-d0GZjqY9.js} +2 -2
  13. package/dist/{remotes-DrYe_nfw.js → remotes-B4v0Nowo.js} +64 -7
  14. package/dist/remotes-DnMQWaqQ.js +5 -0
  15. package/dist/{rustBinary-DgRg5H6V.js → rustBinary-CVjRaDmT.js} +2 -2
  16. package/dist/{rustBinary-CKuufNRn.js → rustBinary-DdWIf051.js} +2 -2
  17. package/dist/{schedule-BStFx0_s.js → schedule-C0HWIN7Z.js} +4 -4
  18. package/dist/{serve-Cis4oJM-.js → serve-DTQomE4j.js} +42 -28
  19. package/dist/{setup-B0sg4AV1.js → setup-BwZ3UlCM.js} +2 -2
  20. package/dist/{shareCmd-DKIvwe0I.js → shareCmd-Cx2kxthJ.js} +3 -3
  21. package/dist/subcommands-R1eJF51D.js +13 -0
  22. package/dist/{subcommands-CvL_1Nt9.js → subcommands-sr1CIEeP.js} +760 -77
  23. package/dist/{terminal-DqsAuqhw.js → terminal-CHPcyJuv.js} +2 -2
  24. package/dist/{trayApp-Dayj9Frx.js → trayApp-CjUWDytD.js} +2 -2
  25. package/dist/trayApp-K6-U3syh.js +5 -0
  26. package/dist/{ts-C2osm4MO.js → ts-tta7Z887.js} +3 -3
  27. package/dist/{versionChecker-BmXwOe40.js → versionChecker-qFzGUoUo.js} +2 -2
  28. package/dist/{widget-D5tsB-oi.js → widget-BOUSiXVj.js} +3 -3
  29. package/dist/{ws-mz7VJJwO.js → ws-BV2o8Zce.js} +2 -2
  30. package/dist/{ws-B4jdOeB2.js → ws-xxrH3pXD.js} +3 -3
  31. package/package.json +1 -1
  32. package/ts/composerGuard.spec.ts +279 -0
  33. package/ts/composerGuard.ts +366 -0
  34. package/ts/globalPidIndex.ts +7 -0
  35. package/ts/messageLog.ts +2 -0
  36. package/ts/needsInput.bun.spec.ts +36 -0
  37. package/ts/needsInput.spec.ts +36 -0
  38. package/ts/remotes.bun.spec.ts +125 -0
  39. package/ts/remotes.spec.ts +125 -0
  40. package/ts/remotes.ts +95 -5
  41. package/ts/serve.bun.spec.ts +50 -0
  42. package/ts/serve.spec.ts +57 -1
  43. package/ts/serve.ts +50 -9
  44. package/ts/subcommands.spec.ts +512 -42
  45. package/ts/subcommands.ts +629 -79
  46. package/ts/workDir.bun.spec.ts +90 -0
  47. package/ts/workDir.spec.ts +90 -0
  48. package/ts/workDir.ts +75 -0
  49. package/dist/remotes-BDMnvGI6.js +0 -5
  50. package/dist/subcommands-DioyG80q.js +0 -13
  51. package/dist/trayApp-C6C7-TSh.js +0 -5
@@ -541,6 +541,18 @@ describe("subcommands.matchKeyword", () => {
541
541
  expect(matchKeyword(baseRecord, "different-project")).toBe(false);
542
542
  });
543
543
 
544
+ it("matches the effective work dir too (lane spawned in one dir, working in another)", async () => {
545
+ const { matchKeyword } = await loadModule();
546
+ const r = {
547
+ ...baseRecord,
548
+ workdir: "/repo/alpha/tree/feat-x",
549
+ workdir_source: "observed" as const,
550
+ };
551
+ expect(matchKeyword(r, "feat-x")).toBe(true);
552
+ expect(matchKeyword(r, "agent-yes")).toBe(true); // spawn dir still matches
553
+ expect(matchKeyword(baseRecord, "feat-x")).toBe(false);
554
+ });
555
+
544
556
  it("matches by exact cli name", async () => {
545
557
  const { matchKeyword } = await loadModule();
546
558
  expect(matchKeyword(baseRecord, "claude")).toBe(true);
@@ -1108,8 +1120,8 @@ describe("subcommands.cmdSend writes bytes to FIFO", () => {
1108
1120
  "hello-fifo",
1109
1121
  "--force",
1110
1122
  ]);
1111
- expect(code).toBe(0);
1112
- expect(stdout.join("")).toMatch(/sent to pid/);
1123
+ expect(code).toBe(1); // Bytes written, but no destination log proves submission.
1124
+ expect(stdout.join("")).toMatch(/NOT SUBMITTED/);
1113
1125
  } finally {
1114
1126
  process.stdout.write = orig;
1115
1127
  if (savedAyPid !== undefined) process.env.AGENT_YES_PID = savedAyPid;
@@ -1419,10 +1431,15 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1419
1431
  // has actually landed — a genuine idle→busy transition, and one that
1420
1432
  // provably happens AFTER submitAndConfirm's pre-write snapshot.
1421
1433
  const reacted = onKeystroke().then((got) => {
1422
- if (got) appendFileSync(log, BUSY);
1434
+ if (got) appendFileSync(log, "some leftover unsent text\r\n" + BUSY + "❯ \r\n");
1423
1435
  return got;
1424
1436
  });
1425
- const { confirmed, screen } = await submitAndConfirm(rec({ log_file: log }), fifo, "\r");
1437
+ const { confirmed, screen } = await submitAndConfirm(
1438
+ rec({ log_file: log }),
1439
+ fifo,
1440
+ "\r",
1441
+ "some leftover unsent text",
1442
+ );
1426
1443
  expect(await reacted).toBe(true); // the fifo really carried the Enter
1427
1444
  expect(confirmed).toBe(true);
1428
1445
  expect(screen.join("\n")).toContain("esc to interrupt");
@@ -1446,7 +1463,86 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1446
1463
  await writeFile(log, BUSY);
1447
1464
  const { submitAndConfirm } = await loadModule();
1448
1465
  await withFifo(async (fifo) => {
1449
- const { confirmed } = await submitAndConfirm(rec({ log_file: log }), fifo, "\r");
1466
+ const { confirmed } = await submitAndConfirm(
1467
+ rec({ log_file: log }),
1468
+ fifo,
1469
+ "\r",
1470
+ "some leftover unsent text",
1471
+ );
1472
+ expect(confirmed).toBe(false);
1473
+ });
1474
+ } finally {
1475
+ await rm(dir, { recursive: true, force: true }).catch(() => null);
1476
+ }
1477
+ },
1478
+ 10_000,
1479
+ );
1480
+
1481
+ // Codex review (2ecc427): counting copies in a 40-row window cannot confirm a
1482
+ // repeated raw message: the old "continue" scrolls out as the new one lands,
1483
+ // and the count stays 1. Leaving the visible composer is the evidence.
1484
+ it.skipIf(!itUnix)(
1485
+ "confirms a repeated raw message whose earlier copy scrolls out of the window",
1486
+ async () => {
1487
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-confirm-log-"));
1488
+ try {
1489
+ const log = path.join(dir, "a.log");
1490
+ const RULE = "─".repeat(20);
1491
+ await writeFile(log, `❯ continue\r\nok\r\n${RULE}\r\n❯ continue\r\n${RULE}\r\n`);
1492
+ const { submitAndConfirm } = await loadModule();
1493
+ await withFifo(async (fifo, onKeystroke) => {
1494
+ const reacted = onKeystroke().then((got) => {
1495
+ if (got) {
1496
+ const output = Array.from({ length: 50 }, (_, i) => `output line ${i}`).join("\r\n");
1497
+ appendFileSync(
1498
+ log,
1499
+ `\x1b[2J\x1b[H❯ continue\r\n${output}\r\n${RULE}\r\n❯ \r\n${RULE}\r\n`,
1500
+ );
1501
+ }
1502
+ return got;
1503
+ });
1504
+ const { confirmed, submission } = await submitAndConfirm(
1505
+ rec({ log_file: log }),
1506
+ fifo,
1507
+ "\r",
1508
+ "continue",
1509
+ );
1510
+ expect(await reacted).toBe(true);
1511
+ expect(submission).toBe("submitted");
1512
+ expect(confirmed).toBe(true);
1513
+ });
1514
+ } finally {
1515
+ await rm(dir, { recursive: true, force: true }).catch(() => null);
1516
+ }
1517
+ },
1518
+ 10_000,
1519
+ );
1520
+
1521
+ it.skipIf(!itUnix)(
1522
+ "does not take a vanished composer (a menu took the screen) for delivery",
1523
+ async () => {
1524
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-confirm-log-"));
1525
+ try {
1526
+ const log = path.join(dir, "a.log");
1527
+ const RULE = "─".repeat(20);
1528
+ await writeFile(log, `${RULE}\r\n❯ continue\r\n${RULE}\r\n`);
1529
+ const { submitAndConfirm } = await loadModule();
1530
+ await withFifo(async (fifo, onKeystroke) => {
1531
+ const reacted = onKeystroke().then((got) => {
1532
+ if (got)
1533
+ appendFileSync(
1534
+ log,
1535
+ `\x1b[2J\x1b[HDo you trust this folder?\r\n 1. Yes\r\n 2. No\r\n`,
1536
+ );
1537
+ return got;
1538
+ });
1539
+ const { confirmed } = await submitAndConfirm(
1540
+ rec({ log_file: log }),
1541
+ fifo,
1542
+ "\r",
1543
+ "continue",
1544
+ );
1545
+ expect(await reacted).toBe(true);
1450
1546
  expect(confirmed).toBe(false);
1451
1547
  });
1452
1548
  } finally {
@@ -1456,25 +1552,296 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1456
1552
  10_000,
1457
1553
  );
1458
1554
 
1459
- it.skipIf(!itUnix)("confirms via log growth even without a recognized busy marker", async () => {
1460
- const dir = await mkdtemp(path.join(tmpdir(), "ay-confirm-log-"));
1555
+ it.skipIf(!itUnix)(
1556
+ "confirms a cleared composer after a response without a busy marker",
1557
+ async () => {
1558
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-confirm-log-"));
1559
+ try {
1560
+ const log = path.join(dir, "a.log");
1561
+ await writeFile(log, "❯ \r\n");
1562
+ const { submitAndConfirm } = await loadModule();
1563
+ await withFifo(async (fifo, onKeystroke) => {
1564
+ // The CLI starts responding once the Enter lands. Keyed off the actual
1565
+ // keystroke so the growth cannot be folded into `sizeBefore`.
1566
+ const reacted = onKeystroke().then((got) => {
1567
+ if (got)
1568
+ appendFileSync(
1569
+ log,
1570
+ "some leftover unsent text\r\nsome real response text appears here\r\n❯ \r\n",
1571
+ );
1572
+ return got;
1573
+ });
1574
+ const { confirmed } = await submitAndConfirm(
1575
+ rec({ log_file: log }),
1576
+ fifo,
1577
+ "\r",
1578
+ "some leftover unsent text",
1579
+ );
1580
+ expect(await reacted).toBe(true);
1581
+ expect(confirmed).toBe(true);
1582
+ });
1583
+ } finally {
1584
+ await rm(dir, { recursive: true, force: true }).catch(() => null);
1585
+ }
1586
+ },
1587
+ );
1588
+
1589
+ it.skipIf(!itUnix)(
1590
+ "rejects growing logs while the message remains in the composer",
1591
+ async () => {
1592
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-redraw-"));
1593
+ try {
1594
+ const log = path.join(dir, "a.log");
1595
+ await writeFile(log, IDLE);
1596
+ const { submitAndConfirm } = await loadModule();
1597
+ await withFifo(async (fifo, onKeystroke) => {
1598
+ const reaction = onKeystroke().then((got) => {
1599
+ if (got) appendFileSync(log, BUSY + IDLE);
1600
+ return got;
1601
+ });
1602
+ const result = await submitAndConfirm(
1603
+ rec({ log_file: log }),
1604
+ fifo,
1605
+ "\r",
1606
+ "some leftover unsent text",
1607
+ );
1608
+ expect(await reaction).toBe(true);
1609
+ expect(result.confirmed).toBe(false);
1610
+ expect(result.submission).toBe("not-submitted");
1611
+ });
1612
+ } finally {
1613
+ await rm(dir, { recursive: true, force: true });
1614
+ }
1615
+ },
1616
+ 10_000,
1617
+ );
1618
+
1619
+ it.skipIf(!itUnix)("distinguishes a queued receipt from submission", async () => {
1620
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-queued-"));
1461
1621
  try {
1462
1622
  const log = path.join(dir, "a.log");
1463
- await writeFile(log, "❯ \r\n");
1623
+ await writeFile(log, IDLE);
1464
1624
  const { submitAndConfirm } = await loadModule();
1465
1625
  await withFifo(async (fifo, onKeystroke) => {
1466
- // The CLI starts responding once the Enter lands. Keyed off the actual
1467
- // keystroke so the growth cannot be folded into `sizeBefore`.
1468
- const reacted = onKeystroke().then((got) => {
1469
- if (got) appendFileSync(log, "some real response text appears here\r\n");
1626
+ const reaction = onKeystroke().then((got) => {
1627
+ if (got) appendFileSync(log, "❯ Press up to edit queued messages\r\n");
1470
1628
  return got;
1471
1629
  });
1472
- const { confirmed } = await submitAndConfirm(rec({ log_file: log }), fifo, "\r");
1473
- expect(await reacted).toBe(true);
1474
- expect(confirmed).toBe(true);
1630
+ const result = await submitAndConfirm(
1631
+ rec({ log_file: log }),
1632
+ fifo,
1633
+ "\r",
1634
+ "some leftover unsent text",
1635
+ );
1636
+ expect(await reaction).toBe(true);
1637
+ expect(result.confirmed).toBe(false);
1638
+ expect(result.submission).toBe("queued");
1475
1639
  });
1476
1640
  } finally {
1477
- await rm(dir, { recursive: true, force: true }).catch(() => null);
1641
+ await rm(dir, { recursive: true, force: true });
1642
+ }
1643
+ });
1644
+
1645
+ it("requires our identity to move out of the composer into the transcript", async () => {
1646
+ const { submissionState, inspectSubmission } = await loadModule();
1647
+ const marker = "<ay-msg abc12345";
1648
+ expect(submissionState([`❯ ${marker}`, "────────"], marker)).toBe("not-submitted");
1649
+ expect(inspectSubmission(["❯", ` ${marker}`, "────────"], marker).retry).toBe(true);
1650
+ expect(submissionState([marker, "❯", "────────"], marker)).toBe("submitted");
1651
+ expect(
1652
+ submissionState([marker, "❯ Press up to edit queued messages", "────────"], marker),
1653
+ ).toBe("queued");
1654
+ expect(submissionState(["❯", "────────"], marker)).toBe("not-submitted");
1655
+ expect(submissionState([], marker)).toBe("not-submitted");
1656
+ expect(inspectSubmission(["❯ unrelated draft"], marker).retry).toBe(false);
1657
+ expect(inspectSubmission(["Codex", "› Ask Codex to do anything"], "x")).toMatchObject({
1658
+ submission: "not-submitted",
1659
+ retry: false,
1660
+ });
1661
+ });
1662
+
1663
+ // Codex review (2ecc427): the last prompt-looking row was taken for the prompt,
1664
+ // so a quoted `› line` inside our unsent message put its nonce in "transcript".
1665
+ it("does not take a quoted prompt glyph inside our unsent message for the prompt", async () => {
1666
+ const { inspectSubmission } = await loadModule();
1667
+ const marker = "<ay-msg abc12345";
1668
+ const screen = ["older history", "────────", `❯ ${marker}`, " › quoted line", "────────"];
1669
+ expect(inspectSubmission(screen, marker)).toMatchObject({
1670
+ transcriptMatches: 0,
1671
+ retry: true,
1672
+ inComposer: true,
1673
+ composerVisible: true,
1674
+ });
1675
+ });
1676
+
1677
+ it("recognizes captured Codex idle/working and Claude suggestion layouts only with our transcript identity", async () => {
1678
+ const { submissionState, inspectSubmission } = await loadModule();
1679
+ const marker = "<ay-msg abc12345";
1680
+ // Layouts from the reviewer's captured fleet screens, with synthetic message identity.
1681
+ const screens = [
1682
+ [
1683
+ "• Ran tests",
1684
+ "",
1685
+ "› Ask Codex to do anything",
1686
+ " GPT-6-Astra low · ~/ws/x · Read brief",
1687
+ " ? for shortcuts ⚠ 2 warnings · f2 to view",
1688
+ ],
1689
+ [
1690
+ "• Working (10m 54s • esc to interrupt)",
1691
+ " └ Tip: Start a fresh idea with /new",
1692
+ "› Ask Codex to do anything",
1693
+ " GPT-6-Astra low · ~/ws/x · Read brief",
1694
+ " ? for shortcuts",
1695
+ ],
1696
+ [
1697
+ "✻ Churned for 15s",
1698
+ "────────────",
1699
+ "❯ push it and open the PR",
1700
+ "────────────",
1701
+ " ⏵⏵ auto mode on",
1702
+ ],
1703
+ ];
1704
+ for (const screen of screens) {
1705
+ expect(submissionState([marker, ...screen], marker)).toBe("submitted");
1706
+ expect(submissionState(screen, marker)).toBe("not-submitted");
1707
+ expect(inspectSubmission(screen, marker).retry).toBe(false);
1708
+ }
1709
+ });
1710
+
1711
+ it.skipIf(!itUnix)(
1712
+ "sends zero extra Enters for unrelated composer text, placeholders and dialogs",
1713
+ async () => {
1714
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-no-retry-"));
1715
+ try {
1716
+ const log = path.join(dir, "a.log");
1717
+ const { submitAndConfirm } = await loadModule();
1718
+ for (const screen of [
1719
+ "❯ push it and open the PR",
1720
+ "› Ask Codex to do anything",
1721
+ "Allow this command?\r\n❯ 1. Yes",
1722
+ ]) {
1723
+ await writeFile(log, screen + "\r\n");
1724
+ await withFifo(async (fifo) => {
1725
+ const result = await submitAndConfirm(
1726
+ rec({ log_file: log }),
1727
+ fifo,
1728
+ "\r",
1729
+ "<ay-msg abc12345",
1730
+ );
1731
+ expect(result.confirmed).toBe(false);
1732
+ const fs = await import("fs");
1733
+ const fd = fs.openSync(fifo, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
1734
+ try {
1735
+ const bytes = Buffer.alloc(16);
1736
+ const count = fs.readSync(fd, bytes, 0, bytes.length, null);
1737
+ expect(bytes.subarray(0, count).toString()).toBe("\r");
1738
+ } finally {
1739
+ fs.closeSync(fd);
1740
+ }
1741
+ });
1742
+ }
1743
+ } finally {
1744
+ await rm(dir, { recursive: true, force: true });
1745
+ }
1746
+ },
1747
+ );
1748
+
1749
+ it.skipIf(!itUnix)(
1750
+ "retries a swallowed Enter only for our composer and confirms its transcript",
1751
+ async () => {
1752
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-own-retry-"));
1753
+ try {
1754
+ const log = path.join(dir, "a.log");
1755
+ const marker = "<ay-msg abc12345";
1756
+ await writeFile(log, `❯ ${marker} hello\r\n`);
1757
+ const { submitAndConfirm } = await loadModule();
1758
+ await withFifo(async (fifo, onKeystroke) => {
1759
+ const reaction = (async () => {
1760
+ expect(await onKeystroke()).toBe(true); // first Enter is swallowed
1761
+ expect(await onKeystroke()).toBe(true); // only our message gets retried
1762
+ appendFileSync(
1763
+ log,
1764
+ `\r\n${marker} hello\r\n❯ push it and open the PR\r\n────────────\r\n`,
1765
+ );
1766
+ })();
1767
+ const result = await submitAndConfirm(rec({ log_file: log }), fifo, "\r", marker);
1768
+ await reaction;
1769
+ expect(result.confirmed).toBe(true);
1770
+ expect(result.submission).toBe("submitted");
1771
+ });
1772
+ } finally {
1773
+ await rm(dir, { recursive: true, force: true });
1774
+ }
1775
+ },
1776
+ 10_000,
1777
+ );
1778
+
1779
+ it("owns only a newly appeared Claude collapsed paste, never an existing or unreadable baseline", async () => {
1780
+ const { ownedCollapsedPaste } = await loadModule();
1781
+ const token = "[Pasted text #2 +12 lines]";
1782
+ const after = [`❯ ${token}`];
1783
+ expect(ownedCollapsedPaste("claude", ["❯"], after)).toBe(token);
1784
+ expect(ownedCollapsedPaste("claude", after, after)).toBeNull();
1785
+ expect(ownedCollapsedPaste("claude", [token, "❯"], after)).toBeNull();
1786
+ expect(ownedCollapsedPaste("claude", null, after)).toBeNull();
1787
+ expect(ownedCollapsedPaste("codex", ["❯"], after)).toBeNull();
1788
+ expect(ownedCollapsedPaste("claude", ["❯"], ["❯ unrelated draft"])).toBeNull();
1789
+ });
1790
+
1791
+ it.skipIf(!itUnix)(
1792
+ "retries our newly collapsed paste until its nonce appears in the transcript",
1793
+ async () => {
1794
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-collapsed-"));
1795
+ try {
1796
+ const log = path.join(dir, "a.log");
1797
+ const marker = "<ay-msg abc12345";
1798
+ await writeFile(log, "❯ [Pasted text #2 +12 lines]\r\n");
1799
+ const { submitAndConfirm } = await loadModule();
1800
+ await withFifo(async (fifo, onKeystroke) => {
1801
+ const reaction = (async () => {
1802
+ expect(await onKeystroke()).toBe(true);
1803
+ expect(await onKeystroke()).toBe(true);
1804
+ appendFileSync(log, `\r\n${marker} hello\r\n❯\r\n────────────\r\n`);
1805
+ })();
1806
+ const result = await submitAndConfirm(rec({ log_file: log }), fifo, "\r", marker, ["❯"]);
1807
+ await reaction;
1808
+ expect(result.confirmed).toBe(true);
1809
+ });
1810
+ } finally {
1811
+ await rm(dir, { recursive: true, force: true });
1812
+ }
1813
+ },
1814
+ 10_000,
1815
+ );
1816
+
1817
+ it.skipIf(!itUnix)("does not retry a collapsed paste that existed before our write", async () => {
1818
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-existing-paste-"));
1819
+ try {
1820
+ const log = path.join(dir, "a.log");
1821
+ const screen = ["❯ [Pasted text #2 +12 lines]"];
1822
+ await writeFile(log, screen.join("\r\n"));
1823
+ const { submitAndConfirm } = await loadModule();
1824
+ await withFifo(async (fifo) => {
1825
+ const result = await submitAndConfirm(
1826
+ rec({ log_file: log }),
1827
+ fifo,
1828
+ "\r",
1829
+ "<ay-msg abc12345",
1830
+ screen,
1831
+ );
1832
+ expect(result.confirmed).toBe(false);
1833
+ const fs = await import("fs");
1834
+ const fd = fs.openSync(fifo, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
1835
+ try {
1836
+ const bytes = Buffer.alloc(16);
1837
+ const count = fs.readSync(fd, bytes, 0, bytes.length, null);
1838
+ expect(bytes.subarray(0, count).toString()).toBe("\r");
1839
+ } finally {
1840
+ fs.closeSync(fd);
1841
+ }
1842
+ });
1843
+ } finally {
1844
+ await rm(dir, { recursive: true, force: true });
1478
1845
  }
1479
1846
  });
1480
1847
 
@@ -1487,7 +1854,12 @@ describe("subcommands.submitAndConfirm (ay send swallowed-Enter fix)", () => {
1487
1854
  await writeFile(log, IDLE); // never touched again — nothing to confirm
1488
1855
  const { submitAndConfirm } = await loadModule();
1489
1856
  await withFifo(async (fifo) => {
1490
- const { confirmed, screen } = await submitAndConfirm(rec({ log_file: log }), fifo, "\r");
1857
+ const { confirmed, screen } = await submitAndConfirm(
1858
+ rec({ log_file: log }),
1859
+ fifo,
1860
+ "\r",
1861
+ "some leftover unsent text",
1862
+ );
1491
1863
  expect(confirmed).toBe(false);
1492
1864
  expect(screen.join("\n")).toContain("leftover unsent text");
1493
1865
  });
@@ -1505,7 +1877,10 @@ describe("subcommands.cmdSend end-to-end submit-confirm wiring", () => {
1505
1877
 
1506
1878
  // A background drain so cmdSend's writes to the FIFO never block, mirroring
1507
1879
  // the "delivers a message to a real FIFO" setup above.
1508
- async function withDrainedFifo(fn: (fifo: string) => Promise<void>) {
1880
+ async function withDrainedFifo(
1881
+ fn: (fifo: string) => Promise<void>,
1882
+ onBytes?: (bytes: string) => void,
1883
+ ) {
1509
1884
  const { spawnSync } = await import("child_process");
1510
1885
  const dir = await mkdtemp(path.join(tmpdir(), "ay-send-e2e-"));
1511
1886
  const fifo = path.join(dir, "test.fifo");
@@ -1523,7 +1898,9 @@ describe("subcommands.cmdSend end-to-end submit-confirm wiring", () => {
1523
1898
  const rdwrFd = fs.openSync(fifo, fs.constants.O_RDWR | fs.constants.O_NONBLOCK);
1524
1899
  const drain = setInterval(() => {
1525
1900
  try {
1526
- fs.readSync(rdwrFd, Buffer.alloc(4096), 0, 4096, null);
1901
+ const bytes = Buffer.alloc(4096);
1902
+ const count = fs.readSync(rdwrFd, bytes, 0, bytes.length, null);
1903
+ if (count) onBytes?.(bytes.subarray(0, count).toString());
1527
1904
  } catch {
1528
1905
  /* EAGAIN or similar — nothing pending, ignore */
1529
1906
  }
@@ -1587,34 +1964,90 @@ describe("subcommands.cmdSend end-to-end submit-confirm wiring", () => {
1587
1964
  "exits 0 and reports 'sent' when a working marker appears after the Enter (genuine confirm)",
1588
1965
  async () => {
1589
1966
  const dir = await mkdtemp(path.join(tmpdir(), "ay-send-e2e-log-"));
1590
- // A STATIC pre-existing busy marker cannot confirm — that's the #157
1591
- // wasAlreadyWorking guard (see the "already on screen before sending" test).
1592
- // Confirmation needs a real idle→working transition (or >=8 bytes of growth)
1593
- // AFTER the submit. Model that: the log is idle until we send, then a steady
1594
- // trickle of the working marker lands within submitAndConfirm's window, so it
1595
- // confirms deterministically without fragile single-shot timing.
1596
1967
  const log = path.join(dir, "a.log");
1597
- await writeFile(log, "❯ \r\n"); // idle until the submitted Enter lands
1598
- let working = false;
1599
- const respond = setInterval(() => {
1600
- if (working) appendFileSync(log, BUSY);
1601
- }, 40);
1602
- respond.unref();
1968
+ await writeFile(log, "❯ hello\r\n");
1603
1969
  try {
1604
- await withDrainedFifo(async (fifo) => {
1605
- working = true; // the submitted Enter kicks the agent into working
1606
- const { code, stdout } = await send(fifo, log, "hello");
1607
- expect(code).toBe(0);
1608
- expect(stdout).toMatch(/^sent to pid/);
1609
- expect(stdout).not.toMatch(/NOT confirmed/);
1610
- });
1970
+ await withDrainedFifo(
1971
+ async (fifo) => {
1972
+ const { code, stdout } = await send(fifo, log, "hello");
1973
+ expect(code).toBe(0);
1974
+ expect(stdout).toMatch(/^sent to pid/);
1975
+ expect(stdout).not.toMatch(/NOT confirmed/);
1976
+ },
1977
+ (bytes) => {
1978
+ if (bytes.includes("\r")) appendFileSync(log, "\r\nhello\r\n" + BUSY + "❯ \r\n");
1979
+ },
1980
+ );
1611
1981
  } finally {
1612
- clearInterval(respond);
1613
1982
  await rm(dir, { recursive: true, force: true }).catch(() => null);
1614
1983
  }
1615
1984
  },
1616
1985
  );
1617
1986
 
1987
+ it.skipIf(!itUnix)("captures collapsed-paste ownership before writing the body", async () => {
1988
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-collapse-wiring-"));
1989
+ const log = path.join(dir, "a.log");
1990
+ await writeFile(log, "❯\r\n");
1991
+ let enters = 0;
1992
+ try {
1993
+ await withDrainedFifo(
1994
+ async (fifo) => {
1995
+ const { code } = await send(fifo, log, "collapsed-message");
1996
+ expect(code).toBe(0);
1997
+ expect(enters).toBe(2);
1998
+ },
1999
+ (bytes) => {
2000
+ if (bytes.includes("collapsed-message"))
2001
+ appendFileSync(log, "\x1b[2J\x1b[H❯ [Pasted text #3 +20 lines]\r\n");
2002
+ if (bytes.includes("\r") && ++enters === 2)
2003
+ appendFileSync(log, "collapsed-message\r\n❯\r\n");
2004
+ },
2005
+ );
2006
+ } finally {
2007
+ await rm(dir, { recursive: true, force: true });
2008
+ }
2009
+ });
2010
+
2011
+ it.skipIf(!itUnix)("reports QUEUED with its distinct exit 4", async () => {
2012
+ const dir = await mkdtemp(path.join(tmpdir(), "ay-queue-e2e-"));
2013
+ const log = path.join(dir, "a.log");
2014
+ await writeFile(log, "❯ waiting\r\n");
2015
+ try {
2016
+ await withDrainedFifo(
2017
+ async (fifo) => {
2018
+ const errs: string[] = [];
2019
+ const origErr = process.stderr.write.bind(process.stderr);
2020
+ process.stderr.write = ((c: string | Uint8Array) => (
2021
+ errs.push(String(c)), true
2022
+ )) as typeof process.stderr.write;
2023
+ let res: { code: number | null; stdout: string };
2024
+ try {
2025
+ res = await send(fifo, log, "queued-receipt-test");
2026
+ } finally {
2027
+ process.stderr.write = origErr;
2028
+ }
2029
+ const { code, stdout } = res;
2030
+ expect(code).toBe(4);
2031
+ expect(stdout).toMatch(/^QUEUED to pid/);
2032
+ // The receipt says so, so a lane does not read rc=4 as a failure and resend.
2033
+ expect(errs.join("")).toContain("Queued, do not resend.");
2034
+ const { readMailbox } = await import("./messageLog.ts");
2035
+ const receipt = (await readMailbox(process.cwd(), "outbox")).findLast(
2036
+ (r) => r.body === "queued-receipt-test",
2037
+ );
2038
+ expect(receipt?.confirmed).toBe(false);
2039
+ expect(receipt?.submission).toBe("queued");
2040
+ },
2041
+ (bytes) => {
2042
+ if (bytes.includes("\r"))
2043
+ appendFileSync(log, "queued-receipt-test\r\n❯ Press up to edit queued messages\r\n");
2044
+ },
2045
+ );
2046
+ } finally {
2047
+ await rm(dir, { recursive: true, force: true });
2048
+ }
2049
+ });
2050
+
1618
2051
  it.skipIf(!itUnix)(
1619
2052
  "exits non-zero and reports the leftover screen when submission can't be confirmed",
1620
2053
  async () => {
@@ -3246,7 +3679,7 @@ describe("subcommands.cmdSend double-envelope warning", () => {
3246
3679
  '<ay-msg deadbeef from claude #900001 @ /repo/beta — reply: ay send 900001 "...">hi</ay-msg deadbeef>',
3247
3680
  "--force",
3248
3681
  ]);
3249
- expect(code).toBe(0);
3682
+ expect(code).toBe(1); // This FIFO fixture has no destination log.
3250
3683
  expect(stderr.join("")).toMatch(/DOUBLE wrapper/);
3251
3684
  } finally {
3252
3685
  process.stderr.write = origErr;
@@ -3329,7 +3762,7 @@ describe("subcommands.cmdSend double-envelope warning", () => {
3329
3762
  "plain body, quoting <ay-msg deadbeef …> mid-text is fine",
3330
3763
  "--force",
3331
3764
  ]);
3332
- expect(code).toBe(0);
3765
+ expect(code).toBe(1); // This FIFO fixture has no destination log.
3333
3766
  expect(stderr.join("")).not.toMatch(/DOUBLE wrapper/);
3334
3767
  } finally {
3335
3768
  process.stderr.write = origErr;
@@ -3403,7 +3836,7 @@ describe("subcommands.cmdSend double-envelope warning", () => {
3403
3836
  "hello from crm",
3404
3837
  "--force",
3405
3838
  ]);
3406
- expect(code).toBe(0);
3839
+ expect(code).toBe(1); // This FIFO fixture has no destination log.
3407
3840
  } finally {
3408
3841
  process.stdout.write = origOut;
3409
3842
  if (savedAyPid === undefined) delete process.env.AGENT_YES_PID;
@@ -4182,3 +4615,40 @@ describe("subcommands.cmdSend unreachable exit status", () => {
4182
4615
  },
4183
4616
  );
4184
4617
  });
4618
+
4619
+ // The drainer is spawned detached from `ay send`; a launcher that cannot start
4620
+ // is silent (spawn's ENOENT is swallowed), so the parked message simply never
4621
+ // moves. Pin the argv shape per runtime so the Windows regression (spawning the
4622
+ // .js script bare) cannot come back.
4623
+ describe("drainerLauncher", () => {
4624
+ it("re-runs the current script under bun, on every platform", async () => {
4625
+ const { drainerLauncher } = await loadModule();
4626
+ expect(
4627
+ drainerLauncher("/usr/local/bin/bun", "/repo/alpha/dist/cli.js", "/usr/local/bin/ay"),
4628
+ ).toEqual(["/usr/local/bin/bun", "/repo/alpha/dist/cli.js"]);
4629
+ expect(
4630
+ drainerLauncher(
4631
+ "C:\\Users\\alice\\.bun\\bin\\bun.exe",
4632
+ "C:\\repo\\alpha\\dist\\cli.js",
4633
+ null,
4634
+ ),
4635
+ ).toEqual(["C:\\Users\\alice\\.bun\\bin\\bun.exe", "C:\\repo\\alpha\\dist\\cli.js"]);
4636
+ });
4637
+
4638
+ it("falls back to the ay on PATH only when there is no script, and to nothing when there is neither", async () => {
4639
+ const { drainerLauncher } = await loadModule();
4640
+ expect(drainerLauncher("/usr/local/bin/bun", undefined, "/usr/local/bin/ay")).toEqual([
4641
+ "/usr/local/bin/bun",
4642
+ "/usr/local/bin/ay",
4643
+ ]);
4644
+ expect(drainerLauncher("/usr/local/bin/bun", undefined, null)).toBeNull();
4645
+ });
4646
+
4647
+ it("re-runs a compiled single-file binary as itself", async () => {
4648
+ const { drainerLauncher } = await loadModule();
4649
+ expect(drainerLauncher("/opt/ay/ay", "/$bunfs/root/cli", "/usr/local/bin/ay")).toEqual([
4650
+ "/opt/ay/ay",
4651
+ ]);
4652
+ expect(drainerLauncher("C:\\tools\\ay.exe", undefined, null)).toEqual(["C:\\tools\\ay.exe"]);
4653
+ });
4654
+ });