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.
- package/README.md +54 -0
- package/default.config.yaml +5 -5
- package/dist/{JsonlStore-BpYZZTap.js → JsonlStore-CB_0sfdT.js} +5 -4
- package/dist/{SUPPORTED_CLIS-Dq9Lq9WJ.js → SUPPORTED_CLIS-C_1IiOj3.js} +2 -2
- package/dist/SUPPORTED_CLIS-Do3GHAY1.js +12 -0
- package/dist/{agentShare-suB6yPgO.js → agentShare-BvpEm-Fr.js} +10 -9
- package/dist/{askCli-BU3CNCLU.js → askCli-KmMf-3wA.js} +6 -6
- package/dist/{browser-BmxN1Ur9.js → browser-BAFPmEvN.js} +2 -2
- package/dist/{callback-Ctj3_Wxp.js → callback-BiSUhjw7.js} +6 -6
- package/dist/callback-SqLD2mMX.js +17 -0
- package/dist/{callbackCore-DSJWhqAe.js → callbackCore-BZ_10zyc.js} +1 -1
- package/dist/{callbackCore-BesbQ6-Z.js → callbackCore-Deve5pv3.js} +1 -1
- package/dist/{channels-j5nWuzlQ.js → channels-Y36S0ccW.js} +2 -2
- package/dist/cli.js +118 -13
- package/dist/{cmdDsh-2LP0grim.js → cmdDsh-DZ8bLsH7.js} +1 -1
- package/dist/cmdKill-CzSBfWmx.js +116 -0
- package/dist/{cmdPs-wc1j85fi.js → cmdPs-DBt23Qz0.js} +11 -10
- package/dist/{cwdConflictWarn-skQSMwEh.js → cwdConflictWarn-y-epQyOj.js} +21 -5
- package/dist/{cwdPassthroughHint-BUbWMoz0.js → cwdPassthroughHint-CzWh0hrw.js} +1 -1
- package/dist/{expose-Dawq1LxC.js → expose-Bhsn5yUz.js} +2 -2
- package/dist/forceKill-BDqxx4uQ.js +44 -0
- package/dist/{forkNested-CavHyWzA.js → forkNested-3heLs5XC.js} +45 -5
- package/dist/{globalPidIndex-CRB5KtyL.js → globalPidIndex-BsjlId-h.js} +6 -5
- package/dist/{globalPidIndex-BftWlg2V.js → globalPidIndex-uoz8Esqz.js} +2 -2
- package/dist/{hist-Cs0KFSUW.js → hist-DY16wm7g.js} +1 -1
- package/dist/{identity-DA7YI9km.js → identity-C0MxfwI2.js} +1 -1
- package/dist/{identity-Bk-aG_xl.js → identity-Ckav3-Up.js} +1 -1
- package/dist/index.js +7 -7
- package/dist/{initMsg-CcTqFtsp.js → initMsg-BEVDWYnv.js} +1 -1
- package/dist/{initMsg-D9KJnfgC.js → initMsg-GPU52N-j.js} +1 -1
- package/dist/liagent/box-BSIrRRc_.js +2320 -0
- package/dist/liagent/box-DloywR57.d.ts +409 -0
- package/dist/liagent/box.d.ts +3 -0
- package/dist/liagent/box.js +3 -0
- package/dist/liagent/cli.d.ts +1 -0
- package/dist/liagent/cli.js +908 -0
- package/dist/liagent/client.d.ts +28 -0
- package/dist/liagent/client.js +240 -0
- package/dist/liagent/echo-BvzPSI0x.js +86 -0
- package/dist/liagent/echo-W2RcMEny.d.ts +38 -0
- package/dist/liagent/hub.d.ts +405 -0
- package/dist/liagent/hub.js +1831 -0
- package/dist/liagent/index.d.ts +14 -0
- package/dist/liagent/index.js +10 -0
- package/dist/liagent/liagent.js +339 -0
- package/dist/liagent/mic-audio-C3Shud_F.js +754 -0
- package/dist/liagent/mic-audio-DMCWtEI-.d.ts +317 -0
- package/dist/liagent/mic-button-CtZHFBSG.js +651 -0
- package/dist/liagent/mic-button-Y0ioPetQ.d.ts +248 -0
- package/dist/liagent/mic.d.ts +3 -0
- package/dist/liagent/mic.js +4 -0
- package/dist/liagent/progress-CJs08bXb.js +473 -0
- package/dist/liagent/progress-CfE-meHr.d.ts +205 -0
- package/dist/liagent/progress.d.ts +2 -0
- package/dist/liagent/progress.js +3 -0
- package/dist/liagent/protocol.d.ts +324 -0
- package/dist/liagent/protocol.js +504 -0
- package/dist/liagent/speech-rate-DXeJjRTc.js +42 -0
- package/dist/liagent/state-tree-BZCmAknI.js +353 -0
- package/dist/liagent/tree-BrR7NwMf.js +710 -0
- package/dist/liagent/tree-HB9RhX_H.d.ts +295 -0
- package/dist/liagent/tree.d.ts +2 -0
- package/dist/liagent/tree.js +4 -0
- package/dist/liagent/ui-strings-B03le3fh.d.ts +27 -0
- package/dist/liagent/ui-strings-CJIwW5Gf.js +794 -0
- package/dist/liagent/ui.d.ts +394 -0
- package/dist/liagent/ui.js +5 -0
- package/dist/liagent/voice-D7yeS9VM.js +802 -0
- package/dist/liagent/voice-Qo7SCgi8.d.ts +308 -0
- package/dist/liagent/voice.d.ts +3 -0
- package/dist/liagent/voice.js +4 -0
- package/dist/{notifyDaemon-C7GlfJ1E.js → notifyDaemon-DkUB7GV2.js} +10 -9
- package/dist/{openBrowser-1cIo4dJL.js → openBrowser-CQAOIrD6.js} +1 -1
- package/dist/oxmgrService-DlYHmqyI.js +37 -0
- package/dist/oxmgrService-o9L3I6FX.js +3 -0
- package/dist/{parentLink-DoEWVGld.js → parentLink-BcAYcO9L.js} +2 -2
- package/dist/{parentLink-B58V1RVd.js → parentLink-MBUD3oY2.js} +2 -2
- package/dist/{parentPingLoop-C73bbmCE.js → parentPingLoop-DDO592Wh.js} +5 -5
- package/dist/{pidStore-433kvh9D.js → pidStore-C50VPk3E.js} +3 -3
- package/dist/pidStore-COkPjpW8.js +6 -0
- package/dist/{procStats-BvmrBrOs.js → procStats-DwTxj3rs.js} +1 -1
- package/dist/{remotes-MfdV9M8u.js → remotes-BqLoB5GR.js} +2 -2
- package/dist/{remotes-DevcBeLl.js → remotes-BsMGvAay.js} +3 -3
- package/dist/{roomReplyAlias-DFqg_6IU.js → roomReplyAlias-B-v76TA8.js} +3 -3
- package/dist/roomReplyAlias-BzWUBkQy.js +6 -0
- package/dist/{rustBinary-7VK7oLlW.js → rustBinary-BrJ2p8wy.js} +2 -2
- package/dist/{rustBinary-BV4LxMMn.js → rustBinary-vpfpWj1q.js} +2 -2
- package/dist/{schedule-Dp0qkNO1.js → schedule-Bzjhl6-h.js} +15 -44
- package/dist/schedulesCli-CLqieyQZ.js +784 -0
- package/dist/senderAncestry-CVHeKk1Y.js +173 -0
- package/dist/senderAncestry-KhAUPCQs.js +3 -0
- package/dist/{serve-BpOIIOVc.js → serve-XwFYE0cE.js} +67 -69
- package/dist/{serveRust-CbBrcUrg.js → serveRust-BfWkeL6T.js} +31 -4
- package/dist/{setup-DdIBk6Iv.js → setup-D4-s2VZw.js} +5 -5
- package/dist/{share-w5oRbvlj.js → share-CbFetL5H.js} +1 -1
- package/dist/{share-DrS3LYqf.js → share-_TPYAGWC.js} +1 -1
- package/dist/{shareCmd-DDENkBW2.js → shareCmd-DUBsVI3e.js} +10 -10
- package/dist/spawnGate-Dfj9V76w.js +5 -0
- package/dist/{spawnGate-lr3tvA6U.js → spawnGate-Dj_WaS29.js} +3 -3
- package/dist/{subcommands-DxgvDmZX.js → subcommands-B7YZJL8n.js} +471 -307
- package/dist/subcommands-BZPxFgkT.js +15 -0
- package/dist/{systemPathLink-SjUzgSiq.js → systemPathLink-Y3iC7bYV.js} +1 -1
- package/dist/{terminal-C2h7tpe0.js → terminal-13cGj3h6.js} +2 -2
- package/dist/terminal.js +1 -1
- package/dist/{todoAutomation-TTp_Qz9G.js → todoAutomation-CKlrxuZv.js} +2 -2
- package/dist/{todoCli-BWm5nZE0.js → todoCli-CU9vSJSJ.js} +6 -6
- package/dist/{todoIdentity-BvXZKWJI.js → todoIdentity-CzS1e7VL.js} +2 -2
- package/dist/{todoStore-C9RTz0Vs.js → todoStore-msRCEUi1.js} +2 -2
- package/dist/{tray-BeRSozJz.js → tray-CLktEN3G.js} +1 -1
- package/dist/{trayApp-QQjqhDv1.js → trayApp-5_OlvQcz.js} +2 -2
- package/dist/trayApp-DkAPo0m6.js +5 -0
- package/dist/{ts-6LF7f4fx.js → ts-njuddXQz.js} +126 -57
- package/dist/{versionChecker-Bc62HNf6.js → versionChecker-BJycAanp.js} +2 -2
- package/dist/{webrtcLink-va_gAR77.js → webrtcLink-DcvacEci.js} +1 -1
- package/dist/{webrtcLink-SsInrVHU.js → webrtcLink-WxS1nTIs.js} +1 -1
- package/dist/{webrtcRemote-BlGyNZDC.js → webrtcRemote-C3xQyf3u.js} +2 -2
- package/dist/{widget-Crb5zeHL.js → widget-DmRwOlco.js} +3 -3
- package/dist/widgets.js +1 -1
- package/dist/{workspaceConfig-BLWB5Wu9.js → workspaceConfig-DBgsu81B.js} +1 -1
- package/dist/{ws-DIbwNz8Z.js → ws-ByO6JO6m.js} +3 -3
- package/dist/{ws-BRhPG1Vy.js → ws-D0-Jg88z.js} +9 -8
- package/lab/ui/index.html +1 -1
- package/lab/ui/lab/posts/2026-08-11-slack-term-safe-writes.md +1 -1
- package/package.json +73 -8
- package/ts/JsonlStore.ts +10 -3
- package/ts/cli-idle.bun.spec.ts +1 -1
- package/ts/cli-idle.spec.ts +1 -1
- package/ts/cli.ts +35 -0
- package/ts/cmdKill.bun.spec.ts +155 -0
- package/ts/cmdKill.spec.ts +155 -0
- package/ts/cmdKill.ts +183 -0
- package/ts/composerGuard.edges.spec.ts +91 -0
- package/ts/composerGuard.spec.ts +53 -6
- package/ts/composerGuard.ts +42 -13
- package/ts/conptyModeFilter.spec.ts +30 -0
- package/ts/conptyModeFilter.ts +53 -0
- package/ts/copyLiagent.ts +42 -0
- package/ts/cwdConflictWarn.io.spec.ts +50 -0
- package/ts/cwdConflictWarn.spec.ts +34 -1
- package/ts/cwdConflictWarn.ts +43 -5
- package/ts/cwdGuard.spec.ts +110 -0
- package/ts/cwdGuard.ts +118 -0
- package/ts/forceKill.ts +52 -0
- package/ts/forkNested.bun.spec.ts +41 -0
- package/ts/forkNested.spec.ts +41 -0
- package/ts/forkNested.ts +48 -1
- package/ts/globalPidIndex.edges.spec.ts +125 -0
- package/ts/globalPidIndex.ts +6 -2
- package/ts/index.ts +13 -1
- package/ts/interruptSend.bun.spec.ts +99 -0
- package/ts/interruptSend.spec.ts +99 -0
- package/ts/interruptSend.ts +51 -0
- package/ts/lockRegistry.spec.ts +49 -0
- package/ts/lsRenderCache.spec.ts +58 -0
- package/ts/needsInput.edges.spec.ts +23 -0
- package/ts/parseCliArgs.ts +7 -0
- package/ts/pushGatePlan.spec.ts +147 -0
- package/ts/roomReplyAlias.io.spec.ts +81 -0
- package/ts/schedule.ts +5 -1
- package/ts/schedules.bun.spec.ts +397 -0
- package/ts/schedules.spec.ts +397 -0
- package/ts/schedules.ts +517 -0
- package/ts/schedulesCli.ts +386 -0
- package/ts/sendControl.bun.spec.ts +12 -0
- package/ts/senderAncestry.ts +1 -3
- package/ts/serve.ts +22 -33
- package/ts/serveRust.spec.ts +29 -2
- package/ts/serveRust.ts +27 -2
- package/ts/sizeNego.bun.spec.ts +9 -2
- package/ts/sizeNego.spec.ts +9 -2
- package/ts/sizeNego.ts +10 -5
- package/ts/subcommands.spec.ts +348 -9
- package/ts/subcommands.ts +513 -93
- package/ts/suggestAgents.spec.ts +33 -0
- package/ts/terminal/browser.ts +1 -1
- package/ts/todoParse.spec.ts +22 -1
- package/ts/todoParse.ts +19 -0
- package/dist/SUPPORTED_CLIS-ByO5twge.js +0 -12
- package/dist/callback-D7qfh_7p.js +0 -16
- package/dist/pidStore-BRlKRHXY.js +0 -6
- package/dist/roomReplyAlias-DuEkSSDI.js +0 -6
- package/dist/spawnGate-DeQBTX-o.js +0 -5
- package/dist/subcommands-DmiswRy4.js +0 -14
- package/dist/trayApp-C4TAvRvU.js +0 -5
package/ts/cmdKill.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// `ay kill <pid>` — force-kill one agent, by the exact pid `ay ls` prints.
|
|
2
|
+
//
|
|
3
|
+
// The CLI counterpart of the console's POST /api/kill, using the same kill path
|
|
4
|
+
// (ts/forceKill.ts: SIGKILL the recorded process group, then pid + wrapper).
|
|
5
|
+
// It exists so nobody reaches for `pkill -f <pattern>`: that pattern usually
|
|
6
|
+
// also matches the caller's own shell (its argv contains it), so the caller
|
|
7
|
+
// kills itself. Deliberately narrow: local only, exact pid only, no keyword
|
|
8
|
+
// matching, and it refuses when the kill would reach the caller.
|
|
9
|
+
|
|
10
|
+
import yargs from "yargs";
|
|
11
|
+
import type { GlobalPidRecord } from "./globalPidIndex.ts";
|
|
12
|
+
import { pidOwnershipVerdict } from "./senderAncestry.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Why a kill of `record` must not go ahead, or null. Pure, so each refusal is
|
|
16
|
+
* unit-tested. `selfChain` is the caller and its ancestors; `selfPgid` the
|
|
17
|
+
* caller's process group (null when unknown).
|
|
18
|
+
*/
|
|
19
|
+
export function killRefusal(
|
|
20
|
+
record: Pick<GlobalPidRecord, "pid" | "wrapper_pid">,
|
|
21
|
+
targets: { pgid: number | null },
|
|
22
|
+
selfChain: number[],
|
|
23
|
+
selfPgid: number | null,
|
|
24
|
+
): string | null {
|
|
25
|
+
for (const [pid, what] of [
|
|
26
|
+
[record.pid, "pid"],
|
|
27
|
+
[record.wrapper_pid, "wrapper pid"],
|
|
28
|
+
] as const) {
|
|
29
|
+
if (pid && selfChain.includes(pid)) {
|
|
30
|
+
return (
|
|
31
|
+
`${what} ${pid} is this shell or one of its ancestors — killing it would kill the ` +
|
|
32
|
+
`caller too. To end your own agent, use: ay exit ${record.pid}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (targets.pgid && selfPgid && targets.pgid === selfPgid) {
|
|
37
|
+
return `process group ${targets.pgid} is the caller's own group — refusing to kill it`;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The record's wrapper pid if it now belongs to a process younger than the
|
|
43
|
+
* registration (reused), else null. Same age test as `ay restart`. */
|
|
44
|
+
export function reusedWrapperPid(
|
|
45
|
+
record: Pick<GlobalPidRecord, "pid" | "wrapper_pid" | "started_at">,
|
|
46
|
+
table: Map<number, { ageSecs: number }>,
|
|
47
|
+
now = Date.now(),
|
|
48
|
+
): number | null {
|
|
49
|
+
const w = record.wrapper_pid;
|
|
50
|
+
if (!w || w === record.pid) return null;
|
|
51
|
+
return pidOwnershipVerdict(table.get(w)?.ageSecs, record.started_at, now) === "reused" ? w : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function ownPgid(): Promise<number | null> {
|
|
55
|
+
try {
|
|
56
|
+
const { execFileSync } = await import("node:child_process");
|
|
57
|
+
const out = execFileSync("ps", ["-o", "pgid=", "-p", String(process.pid)], {
|
|
58
|
+
encoding: "utf8",
|
|
59
|
+
timeout: 5000,
|
|
60
|
+
});
|
|
61
|
+
const n = Number(out.trim());
|
|
62
|
+
return Number.isInteger(n) && n > 1 ? n : null;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function cmdKill(rest: string[]): Promise<number> {
|
|
69
|
+
const usage = "usage: ay kill <pid> [--dry-run] (the exact pid shown by ay ls)";
|
|
70
|
+
const argv = await yargs(rest)
|
|
71
|
+
.usage(usage)
|
|
72
|
+
.option("dry-run", {
|
|
73
|
+
alias: "n",
|
|
74
|
+
type: "boolean",
|
|
75
|
+
default: false,
|
|
76
|
+
description: "Print what would be killed, send nothing",
|
|
77
|
+
})
|
|
78
|
+
.strictOptions()
|
|
79
|
+
// Keep the selector a string (`12e3` must not become 12000).
|
|
80
|
+
.parserConfiguration({ "parse-positional-numbers": false })
|
|
81
|
+
.help(false)
|
|
82
|
+
.version(false)
|
|
83
|
+
.exitProcess(false)
|
|
84
|
+
.parseAsync();
|
|
85
|
+
const sel = argv._.length === 1 ? String(argv._[0]) : "";
|
|
86
|
+
if (!/^[1-9]\d*$/.test(sel)) {
|
|
87
|
+
process.stderr.write(
|
|
88
|
+
`ay kill: expected exactly one pid as printed by \`ay ls\`${sel ? ` (got '${sel}')` : ""}.\n` +
|
|
89
|
+
` No keyword, agent-id or remote matching — for a graceful stop use: ay stop <keyword>\n`,
|
|
90
|
+
);
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
if (process.platform === "win32") {
|
|
94
|
+
process.stderr.write(`ay kill: not supported on Windows (as with the console's Kill)\n`);
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
const pid = Number(sel);
|
|
98
|
+
|
|
99
|
+
const { readGlobalPids, updateGlobalPidStatus } = await import("./globalPidIndex.ts");
|
|
100
|
+
const matches = (await readGlobalPids()).filter((r) => r.pid === pid);
|
|
101
|
+
if (matches.length !== 1) {
|
|
102
|
+
process.stderr.write(
|
|
103
|
+
matches.length === 0
|
|
104
|
+
? `ay kill: no registered agent has pid ${pid} (see: ay ls --all)\n`
|
|
105
|
+
: `ay kill: ${matches.length} registry rows claim pid ${pid} — refusing an ambiguous kill\n`,
|
|
106
|
+
);
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
109
|
+
const record = matches[0]!;
|
|
110
|
+
if (record.status === "exited") {
|
|
111
|
+
process.stderr.write(
|
|
112
|
+
`ay kill: pid ${pid} is registered as exited — refusing: the number may belong to ` +
|
|
113
|
+
`another process by now\n`,
|
|
114
|
+
);
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Everything below needs the process table; without it we can neither protect
|
|
119
|
+
// the caller nor detect a reused pid, so refuse rather than guess.
|
|
120
|
+
const { ancestorPids, pidOwnershipVerdict, readAncestryTable } =
|
|
121
|
+
await import("./senderAncestry.ts");
|
|
122
|
+
const table = await readAncestryTable();
|
|
123
|
+
const selfPgid = await ownPgid();
|
|
124
|
+
if (!table || !selfPgid) {
|
|
125
|
+
process.stderr.write(
|
|
126
|
+
`ay kill: could not read the process table (ps) — refusing, since it is unknown ` +
|
|
127
|
+
`whether pid ${pid} is still this agent or an ancestor of this shell\n`,
|
|
128
|
+
);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
// Same pid-reuse guard as \`ay restart\`'s force-kill: a process younger than
|
|
132
|
+
// its registration cannot be the agent that registered.
|
|
133
|
+
if (pidOwnershipVerdict(table.get(pid)?.ageSecs, record.started_at) === "reused") {
|
|
134
|
+
process.stderr.write(
|
|
135
|
+
`ay kill: pid ${pid} is alive but is NOT the agent that registered it (the number ` +
|
|
136
|
+
`was reused) — refusing. Retire the stale row with: ay stop ${pid}\n`,
|
|
137
|
+
);
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const { forceKill, forceKillTargets } = await import("./forceKill.ts");
|
|
142
|
+
const targets = await forceKillTargets(record);
|
|
143
|
+
// The wrapper pid gets the same reuse guard; a reused one is left alone.
|
|
144
|
+
const reusedWrapper = reusedWrapperPid(record, table);
|
|
145
|
+
if (reusedWrapper) {
|
|
146
|
+
targets.pids = targets.pids.filter((p) => p !== reusedWrapper);
|
|
147
|
+
process.stderr.write(
|
|
148
|
+
`ay kill: warning: wrapper pid ${reusedWrapper} was reused — not signalling it\n`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const selfChain = [
|
|
152
|
+
process.pid,
|
|
153
|
+
process.ppid,
|
|
154
|
+
...(await ancestorPids(process.pid, { readTable: async () => table })),
|
|
155
|
+
];
|
|
156
|
+
const refusal = killRefusal(record, targets, selfChain, selfPgid);
|
|
157
|
+
if (refusal) {
|
|
158
|
+
process.stderr.write(`ay kill: ${refusal}\n`);
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const what = `pid ${pid} (${record.cli}, ${record.cwd})`;
|
|
163
|
+
if (argv["dry-run"]) {
|
|
164
|
+
const list = [...(targets.pgid ? [`group ${targets.pgid}`] : []), ...targets.pids];
|
|
165
|
+
process.stdout.write(`would SIGKILL ${list.join(", ")} — ${what}\n`);
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
const { killed, failed } = forceKill(targets);
|
|
169
|
+
if (failed.length) {
|
|
170
|
+
process.stderr.write(
|
|
171
|
+
`ay kill: could not signal ${failed.join(", ")} — ${what} not marked exited\n`,
|
|
172
|
+
);
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
await updateGlobalPidStatus(pid, {
|
|
176
|
+
status: "exited",
|
|
177
|
+
exit_reason: "force-killed via ay kill",
|
|
178
|
+
}).catch(() => {});
|
|
179
|
+
process.stdout.write(
|
|
180
|
+
`killed ${what}: ${killed.join(", ") || "nothing left to signal (already gone)"}\n`,
|
|
181
|
+
);
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { mkdir, mkdtemp, rm, writeFile } from "fs/promises";
|
|
3
|
+
import { tmpdir } from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import {
|
|
6
|
+
classifyComposer,
|
|
7
|
+
findRecentDuplicate,
|
|
8
|
+
noteRecentSend,
|
|
9
|
+
pendingDir,
|
|
10
|
+
promptRe,
|
|
11
|
+
readPending,
|
|
12
|
+
recentSendsPath,
|
|
13
|
+
rowsFromXterm,
|
|
14
|
+
stripPromptGlyph,
|
|
15
|
+
} from "./composerGuard.ts";
|
|
16
|
+
|
|
17
|
+
describe("composer and pending-input recovery edges", () => {
|
|
18
|
+
let root: string;
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
root = await mkdtemp(path.join(tmpdir(), "ay-composer-edges-"));
|
|
21
|
+
vi.stubEnv("AGENT_YES_HOME", root);
|
|
22
|
+
});
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
vi.unstubAllEnvs();
|
|
25
|
+
await rm(root, { recursive: true, force: true });
|
|
26
|
+
});
|
|
27
|
+
it("recognizes ASCII prompts only for agy while preserving quoted transcript text", () => {
|
|
28
|
+
expect(stripPromptGlyph(" > hello", "agy")).toBe("hello");
|
|
29
|
+
expect(stripPromptGlyph(" > quote", "claude")).toBe(" > quote");
|
|
30
|
+
expect(stripPromptGlyph(" ❯ hello")).toBe("hello");
|
|
31
|
+
expect(promptRe("agy").test("> hi")).toBe(true);
|
|
32
|
+
expect(promptRe("claude").test("> quote")).toBe(false);
|
|
33
|
+
expect(promptRe().test("› hi")).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it("tolerates absent or mismatched terminal cells without losing a real draft", () => {
|
|
36
|
+
const cell = { ch: "x", dim: false, inverse: false, colored: false };
|
|
37
|
+
expect(
|
|
38
|
+
classifyComposer([
|
|
39
|
+
{ text: "❯", cells: [] },
|
|
40
|
+
{ text: "", cells: [] },
|
|
41
|
+
]),
|
|
42
|
+
).toEqual({ kind: "empty", ghost: false });
|
|
43
|
+
expect(classifyComposer([{ text: "❯", cells: [cell] }])).toEqual({ kind: "draft", chars: 1 });
|
|
44
|
+
});
|
|
45
|
+
it("handles sparse terminal rows, missing cells and wide-character continuation cells", () => {
|
|
46
|
+
const char = (value: string, width = 1) => ({
|
|
47
|
+
getWidth: () => width,
|
|
48
|
+
getChars: () => value,
|
|
49
|
+
isDim: () => 0,
|
|
50
|
+
isInverse: () => 0,
|
|
51
|
+
isFgDefault: () => true,
|
|
52
|
+
});
|
|
53
|
+
const line = {
|
|
54
|
+
length: 4,
|
|
55
|
+
translateToString: () => "x",
|
|
56
|
+
getCell: (x: number) => [char("x"), undefined, char("", 0), char("")][x],
|
|
57
|
+
};
|
|
58
|
+
const term = {
|
|
59
|
+
buffer: { active: { length: 3, getLine: (i: number) => (i === 1 ? line : undefined) } },
|
|
60
|
+
};
|
|
61
|
+
const rows = rowsFromXterm(term as never, 3);
|
|
62
|
+
expect(rows).toHaveLength(2);
|
|
63
|
+
expect(rows[0]).toEqual({ text: "", cells: [] });
|
|
64
|
+
expect(rows[1]?.cells.map((c) => c.ch)).toEqual(["x", " "]);
|
|
65
|
+
expect(rowsFromXterm(term as never, 3, true)).toEqual(rows);
|
|
66
|
+
expect(
|
|
67
|
+
rowsFromXterm(
|
|
68
|
+
{ buffer: { active: { length: 1, getLine: () => undefined } } } as never,
|
|
69
|
+
3,
|
|
70
|
+
true,
|
|
71
|
+
),
|
|
72
|
+
).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
it("returns no pending message for missing or torn queue files", async () => {
|
|
75
|
+
expect(await readPending(1111, "missing.json")).toBeNull();
|
|
76
|
+
await mkdir(pendingDir(1111), { recursive: true });
|
|
77
|
+
await writeFile(path.join(pendingDir(1111), "torn.json"), "{");
|
|
78
|
+
expect(await readPending(1111, "torn.json")).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
it("ignores corrupt dedupe ledger lines and prunes entries older than the resend window", async () => {
|
|
81
|
+
const file = recentSendsPath(1111);
|
|
82
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
83
|
+
await writeFile(file, '{torn\n\n{"at":0,"sender":"old","hash":"x","outcome":"sent"}\n');
|
|
84
|
+
expect(await findRecentDuplicate(1111, "new", "hello", 100000)).toBeNull();
|
|
85
|
+
await noteRecentSend(1111, "new", "hello", "sent", 100000);
|
|
86
|
+
expect(await findRecentDuplicate(1111, "new", "hello", 100001)).toMatchObject({
|
|
87
|
+
sender: "new",
|
|
88
|
+
outcome: "sent",
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
package/ts/composerGuard.spec.ts
CHANGED
|
@@ -23,14 +23,32 @@ import {
|
|
|
23
23
|
const RULE = "─".repeat(40);
|
|
24
24
|
const FOOTER = "\x1b[38;2;153;153;153m ⏵⏵ auto mode on (shift+tab to cycle)\x1b[39m";
|
|
25
25
|
|
|
26
|
-
async function classify(frame: string, cols = 60) {
|
|
26
|
+
async function classify(frame: string, cols = 60, cli?: string) {
|
|
27
27
|
const term = new Terminal({ cols, rows: 12, allowProposedApi: true });
|
|
28
28
|
await new Promise<void>((r) => term.write(frame, r));
|
|
29
|
-
return classifyComposer(rowsFromXterm(term as never, 40));
|
|
29
|
+
return classifyComposer(rowsFromXterm(term as never, 40), cli);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const box = (inner: string) => `history\r\n${RULE}\r\n❯ ${inner}\x1b[0m\r\n${RULE}\r\n${FOOTER}`;
|
|
33
33
|
|
|
34
|
+
describe("composerBoxed without a rule (Codex)", () => {
|
|
35
|
+
const live = ["› hello", "", " gpt-x default · ~/repo", " ? for shortcuts"];
|
|
36
|
+
it("accepts a prompt row followed by Codex's footer", () => {
|
|
37
|
+
expect(composerBoxed(live, "codex", false)).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
it("rejects an echoed › message with only transcript under it", () => {
|
|
40
|
+
const stale = [
|
|
41
|
+
"› start the app",
|
|
42
|
+
"",
|
|
43
|
+
"• queued a request",
|
|
44
|
+
" Worked for 18s",
|
|
45
|
+
" ↳ Recap: done",
|
|
46
|
+
];
|
|
47
|
+
expect(composerBoxed(stale, "codex", false)).toBe(false);
|
|
48
|
+
expect(composerBoxed(stale)).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
34
52
|
describe("classifyComposer", () => {
|
|
35
53
|
it("reads an empty prompt as empty", async () => {
|
|
36
54
|
expect(await classify(box(""))).toEqual({ kind: "empty", ghost: false });
|
|
@@ -170,6 +188,27 @@ describe("classifyComposer", () => {
|
|
|
170
188
|
});
|
|
171
189
|
});
|
|
172
190
|
|
|
191
|
+
// agy (Antigravity CLI 1.5.6) draws a claude-shaped box with a plain `>` prompt,
|
|
192
|
+
// as read off a live lane's PTY log.
|
|
193
|
+
const agyBox = (inner: string) =>
|
|
194
|
+
`history\r\n${RULE}\r\n>${inner}\r\n${RULE}\r\n? for shortcuts Gemini 3.8 Flash · low`;
|
|
195
|
+
|
|
196
|
+
describe("agy's ASCII `>` prompt", () => {
|
|
197
|
+
it("reads agy's empty box as empty, not as a one-char draft", async () => {
|
|
198
|
+
expect(await classify(agyBox(""), 60, "agy")).toEqual({ kind: "empty", ghost: false });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("reads typed text in agy's box as a draft", async () => {
|
|
202
|
+
expect(await classify(agyBox(" hi"), 60, "agy")).toEqual({ kind: "draft", chars: 2 });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("keeps `>` a markdown quote, not a prompt, for other CLIs", async () => {
|
|
206
|
+
expect((await classify(agyBox(""), 60)).kind).toBe("unknown");
|
|
207
|
+
expect(composerBoxed(["history", RULE, "> quoted", RULE, "? for shortcuts"])).toBe(false);
|
|
208
|
+
expect(composerBoxed(["history", RULE, ">", RULE, "? for shortcuts"], "agy")).toBe(true);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
173
212
|
describe("pending queue", () => {
|
|
174
213
|
let home: string;
|
|
175
214
|
const prev = process.env.AGENT_YES_HOME;
|
|
@@ -295,19 +334,27 @@ describe("composerBoxed", () => {
|
|
|
295
334
|
expect(composerBoxed(["● done", "❯ please summarise", " answer"])).toBe(false);
|
|
296
335
|
});
|
|
297
336
|
it("rejects a stale box that history has been drawn under", () => {
|
|
298
|
-
expect(
|
|
337
|
+
expect(
|
|
338
|
+
composerBoxed([RULE, "❯ old draft", RULE, "● done", "❯ please summarise", " answer"]),
|
|
339
|
+
).toBe(false);
|
|
299
340
|
expect(composerBoxed([RULE, "❯ ", RULE, " a", " b", " c", " d", " e"])).toBe(false);
|
|
300
341
|
// Left open by a partial redraw, with history drawn under it.
|
|
301
342
|
expect(composerBoxed([RULE, "❯ ", "● done", "❯ please summarise", " answer"])).toBe(false);
|
|
302
|
-
expect(
|
|
343
|
+
expect(
|
|
344
|
+
composerBoxed([RULE, "❯ ", " a", " b", " c", " d", " e", " f", " g", " h", " i"]),
|
|
345
|
+
).toBe(false);
|
|
303
346
|
// Transcript drawn under a stale prompt, with chrome further down.
|
|
304
|
-
expect(composerBoxed([RULE, "❯ ", "● done", "❯ please summarise", " answer", RULE])).toBe(
|
|
347
|
+
expect(composerBoxed([RULE, "❯ ", "● done", "❯ please summarise", " answer", RULE])).toBe(
|
|
348
|
+
false,
|
|
349
|
+
);
|
|
305
350
|
expect(
|
|
306
351
|
composerBoxed([RULE, "❯ ", ...Array.from({ length: 9 }, (_, i) => ` row ${i}`), FOOTER]),
|
|
307
352
|
).toBe(false);
|
|
308
353
|
});
|
|
309
354
|
|
|
310
355
|
it("accepts a short multi-line draft inside the box", () => {
|
|
311
|
-
expect(composerBoxed([RULE, "❯ first line", " second line", " third", RULE, FOOTER])).toBe(
|
|
356
|
+
expect(composerBoxed([RULE, "❯ first line", " second line", " third", RULE, FOOTER])).toBe(
|
|
357
|
+
true,
|
|
358
|
+
);
|
|
312
359
|
});
|
|
313
360
|
});
|
package/ts/composerGuard.ts
CHANGED
|
@@ -58,6 +58,18 @@ export type ComposerState =
|
|
|
58
58
|
| { kind: "hidden"; reason: string };
|
|
59
59
|
|
|
60
60
|
const PROMPT_RE = /^\s*[❯›]($|\s)/u;
|
|
61
|
+
// agy (Antigravity CLI) draws its input row with a plain ASCII `>`. Only for the
|
|
62
|
+
// CLIs listed here: in Claude/Codex transcripts a `> ` row is a markdown quote.
|
|
63
|
+
const ASCII_PROMPT_RE = /^\s*[❯›>]($|\s)/u;
|
|
64
|
+
const ASCII_PROMPT_CLIS = new Set(["agy"]);
|
|
65
|
+
/** A row with its leading prompt glyph (and the space after it) removed. */
|
|
66
|
+
export function stripPromptGlyph(line: string, cli?: string): string {
|
|
67
|
+
return line.replace(cli && ASCII_PROMPT_CLIS.has(cli) ? /^\s*[❯›>]\s*/u : /^\s*[❯›]\s*/u, "");
|
|
68
|
+
}
|
|
69
|
+
/** The input-row matcher for a CLI (see ASCII_PROMPT_CLIS). */
|
|
70
|
+
export function promptRe(cli?: string): RegExp {
|
|
71
|
+
return cli && ASCII_PROMPT_CLIS.has(cli) ? ASCII_PROMPT_RE : PROMPT_RE;
|
|
72
|
+
}
|
|
61
73
|
// Same chrome inspectSubmission stops at: the separator rule under the box and
|
|
62
74
|
// the Claude/Codex footer rows.
|
|
63
75
|
const SEPARATOR_RE = /^\s*[─━]{3,}/u;
|
|
@@ -83,11 +95,12 @@ const FOOTER_SEGMENT_RE = /·\s*(?:[←→] .*agents?|↓ |esc to interrupt)|\(s
|
|
|
83
95
|
* any box (Codex) it is the last prompt-looking row. Shared by the draft check
|
|
84
96
|
* and by submission confirmation, so both agree on where history ends.
|
|
85
97
|
*/
|
|
86
|
-
export function composerPromptRow(texts: string[]): number {
|
|
98
|
+
export function composerPromptRow(texts: string[], cli?: string): number {
|
|
99
|
+
const re = promptRe(cli);
|
|
87
100
|
for (let i = texts.length - 2; i >= 0; i--) {
|
|
88
|
-
if (SEPARATOR_RE.test(texts[i]!) &&
|
|
101
|
+
if (SEPARATOR_RE.test(texts[i]!) && re.test(texts[i + 1]!)) return i + 1;
|
|
89
102
|
}
|
|
90
|
-
return texts.findLastIndex((t) =>
|
|
103
|
+
return texts.findLastIndex((t) => re.test(t));
|
|
91
104
|
}
|
|
92
105
|
|
|
93
106
|
/**
|
|
@@ -101,9 +114,12 @@ export function composerPromptRow(texts: string[]): number {
|
|
|
101
114
|
* A real draft longer than MAX_DRAFT_ROWS fails too and reads "hidden", which
|
|
102
115
|
* parks the send just as a draft does.
|
|
103
116
|
*/
|
|
104
|
-
export function composerBoxed(texts: string[]): boolean {
|
|
105
|
-
const prompt = composerPromptRow(texts);
|
|
106
|
-
if (prompt <
|
|
117
|
+
export function composerBoxed(texts: string[], cli?: string, needRule = true): boolean {
|
|
118
|
+
const prompt = composerPromptRow(texts, cli);
|
|
119
|
+
if (prompt < 0) return false;
|
|
120
|
+
// Codex draws no rule above its composer; its footer under the prompt row is
|
|
121
|
+
// what shows the live composer rather than an echoed `›` message in history.
|
|
122
|
+
if (needRule && (prompt < 1 || !SEPARATOR_RE.test(texts[prompt - 1]!))) return false;
|
|
107
123
|
const nonBlank = (rows: string[]) => rows.filter((t) => t.trim());
|
|
108
124
|
const close = texts.findIndex((t, i) => i > prompt && isComposerChrome(t));
|
|
109
125
|
if (close < 0) return false;
|
|
@@ -112,7 +128,7 @@ export function composerBoxed(texts: string[]): boolean {
|
|
|
112
128
|
return (
|
|
113
129
|
inside.length <= MAX_DRAFT_ROWS &&
|
|
114
130
|
below.length <= MAX_ROWS_BELOW_BOX &&
|
|
115
|
-
![...inside, ...below].some((t) =>
|
|
131
|
+
![...inside, ...below].some((t) => promptRe(cli).test(t))
|
|
116
132
|
);
|
|
117
133
|
}
|
|
118
134
|
|
|
@@ -150,8 +166,11 @@ export function isComposerChrome(text: string, cells?: ComposerCell[]): boolean
|
|
|
150
166
|
* draft is not. A draft whose own line starts with a prompt glyph can still be
|
|
151
167
|
* misread there.
|
|
152
168
|
*/
|
|
153
|
-
export function classifyComposer(rows: ComposerRow[]): ComposerState {
|
|
154
|
-
const prompt = composerPromptRow(
|
|
169
|
+
export function classifyComposer(rows: ComposerRow[], cli?: string): ComposerState {
|
|
170
|
+
const prompt = composerPromptRow(
|
|
171
|
+
rows.map((r) => r.text),
|
|
172
|
+
cli,
|
|
173
|
+
);
|
|
155
174
|
if (prompt < 0) return { kind: "unknown", reason: "no prompt row on screen" };
|
|
156
175
|
let real = 0;
|
|
157
176
|
let ghost = false;
|
|
@@ -164,7 +183,8 @@ export function classifyComposer(rows: ComposerRow[]): ComposerState {
|
|
|
164
183
|
let cells = row.cells;
|
|
165
184
|
if (i === prompt) {
|
|
166
185
|
// Skip the indentation and the prompt glyph itself.
|
|
167
|
-
|
|
186
|
+
let glyph = cells.findIndex((c) => c.ch.trim() !== "");
|
|
187
|
+
if (glyph >= 0 && !promptRe(cli).test(cells[glyph]!.ch)) glyph = -1;
|
|
168
188
|
cells = glyph >= 0 ? cells.slice(glyph + 1) : cells;
|
|
169
189
|
}
|
|
170
190
|
for (const c of cells) {
|
|
@@ -200,11 +220,18 @@ type XtermLike = {
|
|
|
200
220
|
};
|
|
201
221
|
};
|
|
202
222
|
|
|
203
|
-
/**
|
|
204
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Read the bottom `n` rows of an xterm buffer as ComposerRows. With
|
|
225
|
+
* `fromContent`, count them up from the last non-blank row (as `ay tail`
|
|
226
|
+
* does), so a screen that has not filled the viewport yet keeps its top rows.
|
|
227
|
+
*/
|
|
228
|
+
export function rowsFromXterm(term: XtermLike, n: number, fromContent = false): ComposerRow[] {
|
|
205
229
|
const active = term.buffer.active;
|
|
230
|
+
const blank = (i: number) => !active.getLine(i)?.translateToString(true).trim();
|
|
231
|
+
let end = active.length;
|
|
232
|
+
if (fromContent) while (end > 0 && blank(end - 1)) end--;
|
|
206
233
|
const rows: ComposerRow[] = [];
|
|
207
|
-
for (let i = Math.max(0,
|
|
234
|
+
for (let i = Math.max(0, end - n); i < end; i++) {
|
|
208
235
|
const line = active.getLine(i);
|
|
209
236
|
if (!line) {
|
|
210
237
|
rows.push({ text: "", cells: [] });
|
|
@@ -241,6 +268,8 @@ export interface PendingSend {
|
|
|
241
268
|
/** Exactly what cmdSend would have written (envelope + paste framing). */
|
|
242
269
|
fullBody: string;
|
|
243
270
|
trailing: string;
|
|
271
|
+
/** Explicitly cancel a running turn before delivery once the draft is clear. */
|
|
272
|
+
interrupt?: boolean;
|
|
244
273
|
/** Submit-confirm identity (`<ay-msg nonce` or the raw body). */
|
|
245
274
|
identity: string;
|
|
246
275
|
/** The mailbox record to append once the outcome is known. */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { ConptyModeFilter } from "./conptyModeFilter";
|
|
3
|
+
test("only consumes inner ConPTY keyboard negotiation across every split", () => {
|
|
4
|
+
const input =
|
|
5
|
+
"hello?\x1b[?9001h\x1b[?1004;9001;2004h\x1b[?1003;1006h\x1b[A\x1b[200~paste\x1b[201~\x1b[?9001l\x1b[6n\x1b]7;cwd\x07";
|
|
6
|
+
const expected =
|
|
7
|
+
"hello?\x1b[?1004;2004h\x1b[?1003;1006h\x1b[A\x1b[200~paste\x1b[201~\x1b[6n\x1b]7;cwd\x07";
|
|
8
|
+
for (let split = 0; split <= input.length; split++) {
|
|
9
|
+
const filter = new ConptyModeFilter();
|
|
10
|
+
expect(
|
|
11
|
+
filter.feed(input.slice(0, split)) + filter.feed(input.slice(split)) + filter.finish(),
|
|
12
|
+
).toBe(expected);
|
|
13
|
+
}
|
|
14
|
+
const filter = new ConptyModeFilter();
|
|
15
|
+
expect([...input].map((c) => filter.feed(c)).join("") + filter.finish()).toBe(expected);
|
|
16
|
+
});
|
|
17
|
+
test("preserves incomplete, long and unrelated sequences", () => {
|
|
18
|
+
for (const input of [
|
|
19
|
+
"\x1b",
|
|
20
|
+
"\x1b[?",
|
|
21
|
+
"\x1b[?9001",
|
|
22
|
+
"\x1b[?90010h",
|
|
23
|
+
"\x1b[?9001$p",
|
|
24
|
+
"\x1b[?9001?",
|
|
25
|
+
"\x1b[?" + "1".repeat(300),
|
|
26
|
+
]) {
|
|
27
|
+
const filter = new ConptyModeFilter();
|
|
28
|
+
expect(filter.feed(input) + filter.finish()).toBe(input);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Keep ConPTY's private keyboard protocol local to its PTY boundary.
|
|
2
|
+
* Forwarding DECSET 9001 to an outer Windows console turns VT input bytes
|
|
3
|
+
* into literal-character INPUT_RECORDs, breaking arrows, paste and mouse.
|
|
4
|
+
* This is output negotiation, not an input sanitizer. All app modes survive.
|
|
5
|
+
*/
|
|
6
|
+
export class ConptyModeFilter {
|
|
7
|
+
private pending = "";
|
|
8
|
+
feed(chunk: string): string {
|
|
9
|
+
const text = this.pending + chunk;
|
|
10
|
+
this.pending = "";
|
|
11
|
+
let out = "",
|
|
12
|
+
i = 0;
|
|
13
|
+
while (i < text.length) {
|
|
14
|
+
const start = text.indexOf("\x1b", i);
|
|
15
|
+
if (start < 0) {
|
|
16
|
+
out += text.slice(i);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
out += text.slice(i, start);
|
|
20
|
+
const rest = text.slice(start);
|
|
21
|
+
if ("\x1b[?".startsWith(rest)) {
|
|
22
|
+
this.pending = rest;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
if (!rest.startsWith("\x1b[?")) {
|
|
26
|
+
out += "\x1b";
|
|
27
|
+
i = start + 1;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
let end = start + 3;
|
|
31
|
+
while (end < text.length && /[0-9;]/.test(text[end])) end++;
|
|
32
|
+
if (end === text.length && end - start < 256) {
|
|
33
|
+
this.pending = rest;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
const params = text.slice(start + 3, end).split(";");
|
|
37
|
+
if ((text[end] === "h" || text[end] === "l") && params.includes("9001")) {
|
|
38
|
+
const kept = params.filter((p) => p !== "9001");
|
|
39
|
+
if (kept.length) out += "\x1b[?" + kept.join(";") + text[end];
|
|
40
|
+
i = end + 1;
|
|
41
|
+
} else {
|
|
42
|
+
out += text.slice(start, end);
|
|
43
|
+
i = end;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
finish(): string {
|
|
49
|
+
const tail = this.pending;
|
|
50
|
+
this.pending = "";
|
|
51
|
+
return tail;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#! /usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Build step: ship liagent (https://github.com/snolab/liagent) inside
|
|
4
|
+
* agent-yes as `agent-yes/liagent`. liagent is a devDependency pinned to a
|
|
5
|
+
* release tag ("github:snolab/liagent#vX.Y.Z"), whose tag commit holds its
|
|
6
|
+
* built dist/. This copies the .js and .d.ts files (no source maps) into
|
|
7
|
+
* dist/liagent/, which the ./liagent* exports and the `liagent` bin point at.
|
|
8
|
+
* To move to a new liagent release, bump that one pin in package.json.
|
|
9
|
+
*/
|
|
10
|
+
import { chmod, copyFile, mkdir, readdir } from "fs/promises";
|
|
11
|
+
import path from "path";
|
|
12
|
+
|
|
13
|
+
const from = path.join(import.meta.dir, "..", "node_modules", "liagent", "dist");
|
|
14
|
+
const to = path.join(import.meta.dir, "..", "dist", "liagent");
|
|
15
|
+
// What the exports and the bin need; the build fails without any of them.
|
|
16
|
+
const required = [
|
|
17
|
+
"index",
|
|
18
|
+
"box",
|
|
19
|
+
"ui",
|
|
20
|
+
"tree",
|
|
21
|
+
"mic",
|
|
22
|
+
"voice",
|
|
23
|
+
"client",
|
|
24
|
+
"protocol",
|
|
25
|
+
"progress",
|
|
26
|
+
"hub",
|
|
27
|
+
"cli",
|
|
28
|
+
].flatMap((n) => [`${n}.js`, `${n}.d.ts`]);
|
|
29
|
+
|
|
30
|
+
const files = await readdir(from).catch(() => {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`liagent's dist is missing at ${from}: run \`bun install\` (devDependency "liagent").`,
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
const missing = required.filter((f) => !files.includes(f));
|
|
36
|
+
if (missing.length) throw new Error(`liagent's dist lacks ${missing.join(", ")} (${from})`);
|
|
37
|
+
|
|
38
|
+
await mkdir(to, { recursive: true });
|
|
39
|
+
const shipped = files.filter((f) => /\.(js|d\.ts)$/.test(f));
|
|
40
|
+
for (const f of shipped) await copyFile(path.join(from, f), path.join(to, f));
|
|
41
|
+
await chmod(path.join(to, "cli.js"), 0o755);
|
|
42
|
+
console.log(`dist/liagent: ${shipped.length} files from liagent`);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
const io = vi.hoisted(() => ({ read: vi.fn() }));
|
|
3
|
+
vi.mock("./globalPidIndex.ts", () => ({ readGlobalPids: io.read }));
|
|
4
|
+
import { launchingCli, warnIfCwdOccupied } from "./cwdConflictWarn.ts";
|
|
5
|
+
|
|
6
|
+
describe("launch conflict warning IO", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.stubEnv("AGENT_YES_NO_CWD_WARN", "0");
|
|
9
|
+
io.read.mockReset().mockResolvedValue([]);
|
|
10
|
+
vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.restoreAllMocks();
|
|
14
|
+
vi.unstubAllEnvs();
|
|
15
|
+
vi.useRealTimers();
|
|
16
|
+
});
|
|
17
|
+
it("handles missing argv, opt-out, empty discovery and discovery errors", async () => {
|
|
18
|
+
expect(launchingCli([])).toBeNull();
|
|
19
|
+
vi.stubEnv("AGENT_YES_NO_CWD_WARN", "1");
|
|
20
|
+
await warnIfCwdOccupied([]);
|
|
21
|
+
expect(io.read).not.toHaveBeenCalled();
|
|
22
|
+
vi.stubEnv("AGENT_YES_NO_CWD_WARN", "0");
|
|
23
|
+
await warnIfCwdOccupied([]);
|
|
24
|
+
expect(process.stderr.write).not.toHaveBeenCalled();
|
|
25
|
+
io.read.mockRejectedValue(new Error("registry unavailable"));
|
|
26
|
+
await expect(warnIfCwdOccupied([])).resolves.toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
it.each([false, true])(
|
|
29
|
+
"warns only for matching cwd and pauses only on a TTY (%s)",
|
|
30
|
+
async (tty) => {
|
|
31
|
+
vi.useFakeTimers();
|
|
32
|
+
const old = Object.getOwnPropertyDescriptor(process.stdout, "isTTY");
|
|
33
|
+
Object.defineProperty(process.stdout, "isTTY", { configurable: true, value: tty });
|
|
34
|
+
io.read.mockResolvedValue([
|
|
35
|
+
{ pid: 1111, cli: "claude", cwd: process.cwd() },
|
|
36
|
+
{ pid: 2222, cli: "codex", cwd: "/unrelated/repo" },
|
|
37
|
+
]);
|
|
38
|
+
try {
|
|
39
|
+
const pending = warnIfCwdOccupied(["bun", "agent-yes.js", "claude", "two words"]);
|
|
40
|
+
await vi.runAllTimersAsync();
|
|
41
|
+
await pending;
|
|
42
|
+
expect(process.stderr.write).toHaveBeenCalledWith(expect.stringContaining("1111 claude"));
|
|
43
|
+
expect(process.stderr.write).toHaveBeenCalledWith(expect.stringContaining("'two words'"));
|
|
44
|
+
} finally {
|
|
45
|
+
if (old) Object.defineProperty(process.stdout, "isTTY", old);
|
|
46
|
+
else Reflect.deleteProperty(process.stdout, "isTTY");
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
});
|