agent-yes 1.299.1 → 1.300.2

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-BAeTuI-p.js} +3 -3
  4. package/dist/{SUPPORTED_CLIS-YZvIGQvw.js → SUPPORTED_CLIS-BZlaxyEH.js} +2 -2
  5. package/dist/{agentShare-dKQQSOD7.js → agentShare-DGQM24wU.js} +3 -3
  6. package/dist/{callback-BEbbWLKe.js → callback-3RsdcuV0.js} +3 -3
  7. package/dist/{callback-DWxTSlly.js → callback-CQadU_zP.js} +3 -3
  8. package/dist/cli.js +5 -5
  9. package/dist/{cmdPs-D7HWttUU.js → cmdPs-CQxFAs9M.js} +3 -3
  10. package/dist/index.js +2 -2
  11. package/dist/{notifyDaemon-B0aU7koS.js → notifyDaemon-CxkiJvOo.js} +3 -3
  12. package/dist/{parentPingLoop-DSiOXQeU.js → parentPingLoop-vZ8I9k5K.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-CKuufNRn.js → rustBinary-B1buVId2.js} +2 -2
  16. package/dist/{rustBinary-DgRg5H6V.js → rustBinary-etb0Jsga.js} +2 -2
  17. package/dist/{schedule-BStFx0_s.js → schedule-CMBHLSlz.js} +4 -4
  18. package/dist/{serve-Cis4oJM-.js → serve-D5ijYGTv.js} +42 -28
  19. package/dist/{setup-B0sg4AV1.js → setup-DMJYufvD.js} +2 -2
  20. package/dist/{shareCmd-DKIvwe0I.js → shareCmd-CNhCKuOK.js} +3 -3
  21. package/dist/{subcommands-CvL_1Nt9.js → subcommands-BncoxUN6.js} +775 -78
  22. package/dist/subcommands-ZEjbTV_7.js +13 -0
  23. package/dist/{terminal-DqsAuqhw.js → terminal-DzbPI4n0.js} +2 -2
  24. package/dist/{trayApp-Dayj9Frx.js → trayApp-BvtgbxMB.js} +2 -2
  25. package/dist/trayApp-CpPsP3_a.js +5 -0
  26. package/dist/{ts-C2osm4MO.js → ts-Gr1eJOUk.js} +3 -3
  27. package/dist/{versionChecker-BmXwOe40.js → versionChecker-BrjeGNf1.js} +2 -2
  28. package/dist/{widget-D5tsB-oi.js → widget-p4Db_OXd.js} +3 -3
  29. package/dist/{ws-B4jdOeB2.js → ws-D_QClddd.js} +3 -3
  30. package/dist/{ws-mz7VJJwO.js → ws-DnKPi3TS.js} +2 -2
  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 +564 -42
  45. package/ts/subcommands.ts +650 -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
@@ -0,0 +1,13 @@
1
+ import "./logger-CDIsZ-Pp.js";
2
+ import "./JsonlStore-BqF7AQ6E.js";
3
+ import "./globalPidIndex-CRH9L9tn.js";
4
+ import "./pidStore-DXWqzTSz.js";
5
+ import "./messageLog-Brx3w6zT.js";
6
+ import "./e2e-z1xpwSAg.js";
7
+ import "./configShared-DKTgiz7K.js";
8
+ import { $ as renderRawLog, A as isBareManagerInvocation, B as listRecords, C as extractMenu, D as inspectSubmission, E as finalizedLines, F as isUnknownManagerToken, G as readAgentPtysize, H as menuSelectKeys, I as isUnreachableWriteErrno, J as readNotes, K as readComposerState, L as isUserTyping, M as isPidAlive, N as isSlashCommand, O as isAgentIdShaped, P as isSubcommand, Q as renderLogTailLines, R as lastReadAt, S as extractBadges, T as extractTaskCounts, U as ownedCollapsedPaste, V as matchKeyword, W as probeStdinReachable, X as recentMessageEdges, Y as readPtysize, Z as recentReadEdges, _ as deriveLiveState, a as SEND_BODY_MAX_CHARS, at as runSubcommand, b as envelopeAttribution, c as TYPING_WINDOW_MS, ct as stdinActivityPath, d as cliDefaults, dt as waitForLogQuiet, et as renderRawLogLines, f as cmdHelp, ft as writeKeysPaced, g as cwdLabel, h as cursorAbs, i as READ_WINDOW_MS, it as restartHintLines, j as isExitRequest, k as isAgentStuck, l as backoffWhileTyping, lt as stopTipForCli, m as controlCodeFromName, n as MAX_RENDER_BYTES, nt as resolveReadWindow, o as SEND_EXIT_QUEUED, ot as sendPayloadCapError, p as confirmStdinUnreachable, pt as writeToIpc, q as readLogForRender, r as READ_PAGE_DEFAULT, rt as resolveResumeArgs, s as SEND_EXIT_UNREACHABLE, st as snapshotStatus, t as GRACEFUL_EXIT_COMMANDS, tt as resolveOne, u as buildEnvelope, ut as submitAndConfirm, v as deriveLiveStatus, w as extractNeedsInput, x as envelopeCostFor, y as drainerLauncher, z as lastStdinAt } from "./subcommands-BncoxUN6.js";
9
+ import "./notifyStore-2SWKGwZI.js";
10
+ import "./webrtcLink-DFRyWNMs.js";
11
+ import "./remotes-B4v0Nowo.js";
12
+
13
+ export { READ_WINDOW_MS, cmdHelp, isBareManagerInvocation, isSubcommand, isUnknownManagerToken, lastReadAt, runSubcommand };
@@ -98,7 +98,7 @@ async function cmdTermMint(args) {
98
98
  if (flags.ro && flags.interactive) throw new Error("--ro and --interactive are mutually exclusive");
99
99
  const ttlSec = parseTtlSec(typeof flags.ttl === "string" ? flags.ttl : "15m");
100
100
  const canSend = flags.interactive === true;
101
- const { mintScopedTermToken } = await import("./serve-Cis4oJM-.js");
101
+ const { mintScopedTermToken } = await import("./serve-D5ijYGTv.js");
102
102
  const r = await mintScopedTermToken(pid, {
103
103
  ttlSec,
104
104
  canSend
@@ -135,4 +135,4 @@ async function cmdTerm(args) {
135
135
 
136
136
  //#endregion
137
137
  export { cmdTerm };
138
- //# sourceMappingURL=terminal-DqsAuqhw.js.map
138
+ //# sourceMappingURL=terminal-DzbPI4n0.js.map
@@ -1,4 +1,4 @@
1
- import { o as findTrayLauncher } from "./rustBinary-CKuufNRn.js";
1
+ import { o as findTrayLauncher } from "./rustBinary-B1buVId2.js";
2
2
  import { t as agentYesHome } from "./agentYesHome-BNtn19J4.js";
3
3
  import { existsSync } from "node:fs";
4
4
  import path from "node:path";
@@ -97,4 +97,4 @@ async function cmdTray(args) {
97
97
 
98
98
  //#endregion
99
99
  export { trayHiddenMarker as a, launchTray as i, hasDesktop as n, isTrayHidden as r, cmdTray as t };
100
- //# sourceMappingURL=trayApp-Dayj9Frx.js.map
100
+ //# sourceMappingURL=trayApp-BvtgbxMB.js.map
@@ -0,0 +1,5 @@
1
+ import "./versionChecker-BrjeGNf1.js";
2
+ import "./rustBinary-B1buVId2.js";
3
+ import { a as trayHiddenMarker, i as launchTray, n as hasDesktop, r as isTrayHidden, t as cmdTray } from "./trayApp-BvtgbxMB.js";
4
+
5
+ export { cmdTray };
@@ -1,6 +1,6 @@
1
1
  import { n as __esmMin, r as __exportAll } from "./chunk-cZBX9HZv.js";
2
2
  import { n as logger, t as addTransport } from "./logger-CDIsZ-Pp.js";
3
- import { i as getInstalledPackage } from "./versionChecker-BmXwOe40.js";
3
+ import { i as getInstalledPackage } from "./versionChecker-BrjeGNf1.js";
4
4
  import { t as agentYesHome } from "./agentYesHome-BNtn19J4.js";
5
5
  import { u as removeControlCharacters } from "./todoAutomation-CbVVS4re.js";
6
6
  import { i as shouldUseLock, r as releaseLock, t as acquireLock } from "./runningLock-BOIPD_Vs.js";
@@ -2086,7 +2086,7 @@ async function agentYes({ cli, cliArgs = [], skipPermissions = false, prompt, ro
2086
2086
  }, 100);
2087
2087
  const cleanupHeartbeat = () => clearInterval(heartbeatInterval);
2088
2088
  shell.onExit(cleanupHeartbeat);
2089
- const { startParentPingLoop } = await import("./parentPingLoop-DSiOXQeU.js");
2089
+ const { startParentPingLoop } = await import("./parentPingLoop-vZ8I9k5K.js");
2090
2090
  const parentPingLoop = startParentPingLoop({
2091
2091
  parentPid,
2092
2092
  selfWrapperPid: process.pid,
@@ -2349,4 +2349,4 @@ function sleep(ms) {
2349
2349
 
2350
2350
  //#endregion
2351
2351
  export { hasTodoStore as a, permissionBadge as c, answerAsk as i, AgentContext as l, agentYes as n, listAsks as o, config as r, listAsksForProject as s, CLIS_CONFIG as t, CLAUDE_SESSION_PIN_ENV as u };
2352
- //# sourceMappingURL=ts-C2osm4MO.js.map
2352
+ //# sourceMappingURL=ts-Gr1eJOUk.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.299.1";
10
+ var version = "1.300.2";
11
11
 
12
12
  //#endregion
13
13
  //#region ts/versionChecker.ts
@@ -285,4 +285,4 @@ async function displayVersion() {
285
285
 
286
286
  //#endregion
287
287
  export { versionString as a, getInstalledPackage as i, compareVersions as n, displayVersion as r, checkAndAutoUpdate as t };
288
- //# sourceMappingURL=versionChecker-BmXwOe40.js.map
288
+ //# sourceMappingURL=versionChecker-BrjeGNf1.js.map
@@ -28,7 +28,7 @@ function parseFlags(args, known) {
28
28
  }
29
29
  /** Resolve the local daemon base URL + token (flags override discovery). */
30
30
  async function daemonTarget(flags) {
31
- const { resolveDaemonHttpBase, loadTokenReadOnly } = await import("./serve-Cis4oJM-.js");
31
+ const { resolveDaemonHttpBase, loadTokenReadOnly } = await import("./serve-D5ijYGTv.js");
32
32
  const base = typeof flags.base === "string" ? flags.base : await resolveDaemonHttpBase();
33
33
  if (!base) throw new Error("no running ay serve daemon found — start `ay serve` or pass --base <url> (e.g. http://127.0.0.1:PORT)");
34
34
  const token = typeof flags.token === "string" ? flags.token : await loadTokenReadOnly() ?? "";
@@ -186,7 +186,7 @@ async function cmdMint(args) {
186
186
  const bad = caps.filter((c) => !KNOWN_CAPS.has(c));
187
187
  if (bad.length) throw new Error(`unknown cap(s): ${bad.join(", ")} (valid: ${[...KNOWN_CAPS].join(", ")})`);
188
188
  const ttlSec = parseTtlSec(typeof flags.ttl === "string" ? flags.ttl : "15m");
189
- const { mintScopedTermToken } = await import("./serve-Cis4oJM-.js");
189
+ const { mintScopedTermToken } = await import("./serve-D5ijYGTv.js");
190
190
  const r = await mintScopedTermToken(target, {
191
191
  ttlSec,
192
192
  caps
@@ -202,4 +202,4 @@ async function cmdMint(args) {
202
202
 
203
203
  //#endregion
204
204
  export { cmdMint, cmdWidget };
205
- //# sourceMappingURL=widget-D5tsB-oi.js.map
205
+ //# sourceMappingURL=widget-p4Db_OXd.js.map
@@ -5,10 +5,10 @@ import "./pidStore-DXWqzTSz.js";
5
5
  import "./messageLog-Brx3w6zT.js";
6
6
  import "./e2e-z1xpwSAg.js";
7
7
  import "./configShared-DKTgiz7K.js";
8
- import "./subcommands-CvL_1Nt9.js";
8
+ import "./subcommands-BncoxUN6.js";
9
9
  import "./notifyStore-2SWKGwZI.js";
10
10
  import "./webrtcLink-DFRyWNMs.js";
11
- import "./remotes-DrYe_nfw.js";
12
- import { a as isPathInside, c as walkWorkspaces, i as importProvisionModule, l as workspaceStatus, n as cmdWs, o as loadProvision, r as collectWorkspaces, s as resolveOperand, t as WS_JSON_SCHEMA } from "./ws-mz7VJJwO.js";
11
+ import "./remotes-B4v0Nowo.js";
12
+ import { a as isPathInside, c as walkWorkspaces, i as importProvisionModule, l as workspaceStatus, n as cmdWs, o as loadProvision, r as collectWorkspaces, s as resolveOperand, t as WS_JSON_SCHEMA } from "./ws-DnKPi3TS.js";
13
13
 
14
14
  export { WS_JSON_SCHEMA, cmdWs, collectWorkspaces, isPathInside, loadProvision, walkWorkspaces, workspaceStatus };
@@ -1,4 +1,4 @@
1
- import { F as listRecords } from "./subcommands-CvL_1Nt9.js";
1
+ import { B as listRecords } from "./subcommands-BncoxUN6.js";
2
2
  import { a as getProvisionRoot } from "./workspaceConfig-DTvPtr5j.js";
3
3
  import { existsSync } from "fs";
4
4
  import { lstat, opendir } from "fs/promises";
@@ -424,4 +424,4 @@ async function cmdWs(args) {
424
424
 
425
425
  //#endregion
426
426
  export { isPathInside as a, walkWorkspaces as c, importProvisionModule as i, workspaceStatus as l, cmdWs as n, loadProvision as o, collectWorkspaces as r, resolveOperand as s, WS_JSON_SCHEMA as t };
427
- //# sourceMappingURL=ws-mz7VJJwO.js.map
427
+ //# sourceMappingURL=ws-DnKPi3TS.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-yes",
3
- "version": "1.299.1",
3
+ "version": "1.300.2",
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",
@@ -0,0 +1,279 @@
1
+ import { mkdtemp, readdir, rm } from "fs/promises";
2
+ import { tmpdir } from "os";
3
+ import path from "path";
4
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
+ import { Terminal } from "@xterm/headless";
6
+ import {
7
+ claimPending,
8
+ classifyComposer,
9
+ DUPLICATE_WINDOW_MS,
10
+ enqueuePending,
11
+ findRecentDuplicate,
12
+ listPending,
13
+ noteRecentSend,
14
+ queuedReceipt,
15
+ readPending,
16
+ recentSendsPath,
17
+ retirePending,
18
+ rowsFromXterm,
19
+ senderKey,
20
+ } from "./composerGuard.ts";
21
+
22
+ const RULE = "─".repeat(40);
23
+ const FOOTER = "\x1b[38;2;153;153;153m ⏵⏵ auto mode on (shift+tab to cycle)\x1b[39m";
24
+
25
+ async function classify(frame: string, cols = 60) {
26
+ const term = new Terminal({ cols, rows: 12, allowProposedApi: true });
27
+ await new Promise<void>((r) => term.write(frame, r));
28
+ return classifyComposer(rowsFromXterm(term as never, 40));
29
+ }
30
+
31
+ const box = (inner: string) => `history\r\n${RULE}\r\n❯ ${inner}\x1b[0m\r\n${RULE}\r\n${FOOTER}`;
32
+
33
+ describe("classifyComposer", () => {
34
+ it("reads an empty prompt as empty", async () => {
35
+ expect(await classify(box(""))).toEqual({ kind: "empty", ghost: false });
36
+ });
37
+
38
+ it("reads typed text as a draft (the 2026-10-08 'btw how' case)", async () => {
39
+ expect(await classify(box("btw how"))).toEqual({ kind: "draft", chars: 6 });
40
+ });
41
+
42
+ it("reads Claude Code's dim prompt suggestion as ghost, not a draft", async () => {
43
+ // Byte-for-byte the suggestion frame from a live lane's PTY log.
44
+ expect(await classify(box("\x1b[2mwater the plants\x1b[22m"))).toEqual({
45
+ kind: "empty",
46
+ ghost: true,
47
+ });
48
+ });
49
+
50
+ it("reads the dim queued-messages hint as ghost", async () => {
51
+ expect(await classify(box("\x1b[2mPress up to edit queued messages\x1b[22m"))).toEqual({
52
+ kind: "empty",
53
+ ghost: true,
54
+ });
55
+ });
56
+
57
+ it("ignores an inverse fake cursor painted over the ghost", async () => {
58
+ expect(await classify(box("\x1b[7mw\x1b[27m\x1b[2mater the plants\x1b[22m"))).toEqual({
59
+ kind: "empty",
60
+ ghost: true,
61
+ });
62
+ });
63
+
64
+ it("still sees a draft when the user's text sits before a ghost tail", async () => {
65
+ expect((await classify(box("hi\x1b[2m there\x1b[22m"))).kind).toBe("draft");
66
+ });
67
+
68
+ it("counts a wrapped second line of the draft", async () => {
69
+ const frame = `${RULE}\r\n❯\u00a0first\r\n second line typed\r\n${RULE}\r\n${FOOTER}`;
70
+ expect(await classify(frame)).toEqual({ kind: "draft", chars: 20 });
71
+ });
72
+
73
+ it("reads a collapsed paste placeholder as a draft", async () => {
74
+ expect((await classify(box("[Pasted text #1 +4 lines]"))).kind).toBe("draft");
75
+ });
76
+
77
+ it("does not count history above the prompt or the footer below it", async () => {
78
+ const frame = `❯ old submitted turn\r\nreply text\r\n${RULE}\r\n❯ \r\n${RULE}\r\n${FOOTER}`;
79
+ expect(await classify(frame)).toEqual({ kind: "empty", ghost: false });
80
+ });
81
+
82
+ it("does not count a footer when the bottom rule is missing (2026-10-08 replay)", async () => {
83
+ const frame = `${RULE}\r\n❯\u00a0\r\n\r\n\x1b[38;2;153;153;153m · ← for agents\x1b[39m`;
84
+ expect(await classify(frame)).toEqual({ kind: "empty", ghost: false });
85
+ });
86
+
87
+ it("keeps a blank line inside a multi-line draft in the box (codex review)", async () => {
88
+ const frame = `${RULE}\r\n❯\u00a0\r\n \r\n human draft\r\n${RULE}\r\n${FOOTER}`;
89
+ expect(await classify(frame)).toEqual({ kind: "draft", chars: 10 });
90
+ });
91
+
92
+ it("keeps a draft line that starts with a prompt glyph in the box (codex review)", async () => {
93
+ const frame = `${RULE}\r\n❯\u00a0human draft\r\n › \r\n${RULE}\r\n${FOOTER}`;
94
+ expect(await classify(frame)).toEqual({ kind: "draft", chars: 11 });
95
+ });
96
+
97
+ it("is unknown when no composer is on screen", async () => {
98
+ expect((await classify("Do you trust this folder?\r\n 1. Yes\r\n 2. No")).kind).toBe(
99
+ "unknown",
100
+ );
101
+ });
102
+
103
+ // Codex review (2ecc427): without a top rule the scan stopped at the first
104
+ // blank row, so a multi-line Codex draft read as empty and was typed into.
105
+ it("keeps a blank line inside an unboxed (Codex) multi-line draft", async () => {
106
+ expect(await classify(`history\r\n› \r\n\r\n human draft\r\n`)).toEqual({
107
+ kind: "draft",
108
+ chars: 10,
109
+ });
110
+ });
111
+ it("still ends an unboxed composer at Codex's footer, past blank rows", async () => {
112
+ expect(
113
+ await classify(
114
+ `› \x1b[2mAsk Codex to do anything\x1b[22m\r\n\r\n ⏎ send ⌃J newline ⌃T transcript\r\n 100% context left\r\n`,
115
+ ),
116
+ ).toEqual({
117
+ kind: "empty",
118
+ ghost: true,
119
+ });
120
+ });
121
+
122
+ it("reads Codex's › prompt the same way", async () => {
123
+ expect((await classify(`› fix the bug\r\n`)).kind).toBe("draft");
124
+ expect(await classify(`› \x1b[2mAsk Codex to do anything\x1b[22m\r\n`)).toEqual({
125
+ kind: "empty",
126
+ ghost: true,
127
+ });
128
+ });
129
+
130
+ // 2026-10-09: idle Claude lanes rendered without the composer's rules in the
131
+ // 32 KB tail, and their status footer led with other segments, so the footer
132
+ // row was counted as a 26-43 char "draft" and every send was parked (rc=4).
133
+ describe("Claude's status footer with leading segments", () => {
134
+ const GRAY = (s: string) => `\x1b[38;2;153;153;153m${s}\x1b[39m`;
135
+ const footers = [
136
+ " · 1 shell · ← for agents · ↓ to manage",
137
+ " shell · ← for agents · ↓ to manage",
138
+ " 1 shell · esc to interrupt · ← 2 agents · ↓ to manage",
139
+ " shell, 1 monitor · esc to interrupt · ← for agents · ↓ …",
140
+ " PR #1234 · 2 shells · ← 2 agents · ↓ to manage",
141
+ // ink partial redraws leave the row garbled in the replayed tail
142
+ " 1 · esc to interrupt · ← 2 agents · ↓ t…",
143
+ " (shift+tab to cy le)",
144
+ ];
145
+ it.each(footers)("does not count a dim suggestion over %j", async (footer) => {
146
+ const frame = `reply\r\n\r\n❯ \x1b[2mbump the dependency pin\x1b[22m\r\n\r\n${GRAY(footer)}`;
147
+ expect(await classify(frame, 80)).toEqual({ kind: "empty", ghost: true });
148
+ });
149
+ it.each(footers)("does not count an empty composer over %j", async (footer) => {
150
+ const frame = `reply\r\n\r\n❯ \r\n\r\n${GRAY(footer)}`;
151
+ expect(await classify(frame, 80)).toEqual({ kind: "empty", ghost: false });
152
+ });
153
+ it.each(footers)("still counts real typed text over %j", async (footer) => {
154
+ const frame = `reply\r\n\r\n❯ btw how\r\n\r\n${GRAY(footer)}`;
155
+ expect(await classify(frame, 80)).toEqual({ kind: "draft", chars: 6 });
156
+ });
157
+ it("ignores the update banner above the composer's top rule", async () => {
158
+ const frame = `${GRAY(" ✔ Update installed · Restart to update")}\r\n${RULE}\r\n❯ \r\n${RULE}\r\n${GRAY(footers[0]!)}`;
159
+ expect(await classify(frame, 80)).toEqual({ kind: "empty", ghost: false });
160
+ });
161
+ it("still counts a typed draft line that reads like a footer segment (luna review)", async () => {
162
+ const frame = `❯\u00a0notes\r\n then · esc to interrupt · ↓ to manage\r\n\r\n${GRAY(footers[0]!)}`;
163
+ expect(await classify(frame, 80)).toEqual({ kind: "draft", chars: 34 });
164
+ });
165
+ it("still counts a draft line that merely contains a middle dot", async () => {
166
+ const frame = `❯ first\r\n a · b\r\n\r\n${GRAY(footers[0]!)}`;
167
+ expect(await classify(frame, 80)).toEqual({ kind: "draft", chars: 8 });
168
+ });
169
+ });
170
+ });
171
+
172
+ describe("pending queue", () => {
173
+ let home: string;
174
+ const prev = process.env.AGENT_YES_HOME;
175
+ beforeEach(async () => {
176
+ home = await mkdtemp(path.join(tmpdir(), "ay-pending-"));
177
+ process.env.AGENT_YES_HOME = home;
178
+ });
179
+ afterEach(async () => {
180
+ if (prev === undefined) delete process.env.AGENT_YES_HOME;
181
+ else process.env.AGENT_YES_HOME = prev;
182
+ await rm(home, { recursive: true, force: true });
183
+ });
184
+
185
+ const msg = (queuedAt: number, fullBody: string) => ({
186
+ queuedAt,
187
+ pid: 4242,
188
+ fifoPath: "/nonexistent",
189
+ fullBody,
190
+ trailing: "\r",
191
+ identity: fullBody,
192
+ record: { body: fullBody },
193
+ });
194
+
195
+ it("lists parked messages in send order", async () => {
196
+ await enqueuePending(msg(2000, "second"));
197
+ await enqueuePending(msg(1000, "first"));
198
+ const names = await listPending(4242);
199
+ expect(names).toHaveLength(2);
200
+ expect((await readPending(4242, names[0]!))?.fullBody).toBe("first");
201
+ });
202
+
203
+ it("claims a message exactly once", async () => {
204
+ await enqueuePending(msg(1, "only"));
205
+ const [name] = await listPending(4242);
206
+ expect(await claimPending(4242, name!)).toBe(true);
207
+ expect(await claimPending(4242, name!)).toBe(false);
208
+ expect(await listPending(4242)).toEqual([]);
209
+ });
210
+
211
+ it("retires a message out of the queue but keeps it on disk", async () => {
212
+ await enqueuePending(msg(1, "stale"));
213
+ const [name] = await listPending(4242);
214
+ await retirePending(4242, name!, "expired");
215
+ expect(await listPending(4242)).toEqual([]);
216
+ const kept = await readdir(path.join(home, "pending", "4242", "undelivered"));
217
+ expect(kept.sort()).toEqual([name!, `${name!}.why`].sort());
218
+ });
219
+ });
220
+
221
+ // Observed live: a lane sent the same report twice, 6 s apart, after
222
+ // reading rc=4 QUEUED as a failure. The sink drops the resend.
223
+ describe("duplicate suppression at the sink", () => {
224
+ let home: string;
225
+ const prev = process.env.AGENT_YES_HOME;
226
+ beforeEach(async () => {
227
+ home = await mkdtemp(path.join(tmpdir(), "ay-dedupe-"));
228
+ process.env.AGENT_YES_HOME = home;
229
+ });
230
+ afterEach(async () => {
231
+ if (prev === undefined) delete process.env.AGENT_YES_HOME;
232
+ else process.env.AGENT_YES_HOME = prev;
233
+ await rm(home, { recursive: true, force: true });
234
+ });
235
+
236
+ const lane = senderKey({ agent_id: "alice-1", pid: 1111 })!;
237
+ const other = senderKey({ agent_id: "bob-1", pid: 2222 })!;
238
+ const T = 1_800_000_000_000;
239
+
240
+ it("an identical body from the same agent within 60 s is a duplicate, and keeps the first outcome", async () => {
241
+ await noteRecentSend(4242, lane, "[alice] report", "queued", T);
242
+ expect(await findRecentDuplicate(4242, lane, "[alice] report", T + 6_000)).toMatchObject({
243
+ outcome: "queued",
244
+ at: T,
245
+ });
246
+ });
247
+
248
+ it("is NOT a duplicate: another sender, another body, another target, or past the window", async () => {
249
+ await noteRecentSend(4242, lane, "report", "sent", T);
250
+ expect(await findRecentDuplicate(4242, other, "report", T + 1_000)).toBeNull();
251
+ expect(await findRecentDuplicate(4242, lane, "report v2", T + 1_000)).toBeNull();
252
+ expect(await findRecentDuplicate(4343, lane, "report", T + 1_000)).toBeNull();
253
+ expect(await findRecentDuplicate(4242, lane, "report", T + DUPLICATE_WINDOW_MS + 1)).toBeNull();
254
+ });
255
+
256
+ it("a person at a shell (no agent) is never deduped", () => {
257
+ expect(senderKey(null)).toBeNull();
258
+ expect(senderKey({ pid: null })).toBeNull();
259
+ expect(senderKey({ pid: 7 })).toBe("p:7");
260
+ });
261
+
262
+ it("the ledger keeps hashes, not bodies, and forgets entries past the window", async () => {
263
+ await noteRecentSend(4242, lane, "secret customer detail", "sent", T);
264
+ await noteRecentSend(4242, lane, "later", "sent", T + DUPLICATE_WINDOW_MS + 10);
265
+ const { readFile } = await import("fs/promises");
266
+ const raw = await readFile(recentSendsPath(4242), "utf-8");
267
+ expect(raw).not.toContain("secret customer detail");
268
+ expect(raw.trim().split("\n")).toHaveLength(1);
269
+ });
270
+
271
+ it("every rc=4 receipt tells the caller not to resend", () => {
272
+ for (const kind of ["parked", "cli-queued", "duplicate"] as const) {
273
+ expect(queuedReceipt(kind, "x")).toMatch(/do not resend/i);
274
+ }
275
+ expect(queuedReceipt("parked", "its input box holds a draft (3 chars)")).toContain(
276
+ "Queued, do not resend.",
277
+ );
278
+ });
279
+ });