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.
- package/README.md +9 -0
- package/default.config.yaml +12 -0
- package/dist/{SUPPORTED_CLIS-MftynU62.js → SUPPORTED_CLIS-BAeTuI-p.js} +3 -3
- package/dist/{SUPPORTED_CLIS-YZvIGQvw.js → SUPPORTED_CLIS-BZlaxyEH.js} +2 -2
- package/dist/{agentShare-dKQQSOD7.js → agentShare-DGQM24wU.js} +3 -3
- package/dist/{callback-BEbbWLKe.js → callback-3RsdcuV0.js} +3 -3
- package/dist/{callback-DWxTSlly.js → callback-CQadU_zP.js} +3 -3
- package/dist/cli.js +5 -5
- package/dist/{cmdPs-D7HWttUU.js → cmdPs-CQxFAs9M.js} +3 -3
- package/dist/index.js +2 -2
- package/dist/{notifyDaemon-B0aU7koS.js → notifyDaemon-CxkiJvOo.js} +3 -3
- package/dist/{parentPingLoop-DSiOXQeU.js → parentPingLoop-vZ8I9k5K.js} +2 -2
- package/dist/{remotes-DrYe_nfw.js → remotes-B4v0Nowo.js} +64 -7
- package/dist/remotes-DnMQWaqQ.js +5 -0
- package/dist/{rustBinary-CKuufNRn.js → rustBinary-B1buVId2.js} +2 -2
- package/dist/{rustBinary-DgRg5H6V.js → rustBinary-etb0Jsga.js} +2 -2
- package/dist/{schedule-BStFx0_s.js → schedule-CMBHLSlz.js} +4 -4
- package/dist/{serve-Cis4oJM-.js → serve-D5ijYGTv.js} +42 -28
- package/dist/{setup-B0sg4AV1.js → setup-DMJYufvD.js} +2 -2
- package/dist/{shareCmd-DKIvwe0I.js → shareCmd-CNhCKuOK.js} +3 -3
- package/dist/{subcommands-CvL_1Nt9.js → subcommands-BncoxUN6.js} +775 -78
- package/dist/subcommands-ZEjbTV_7.js +13 -0
- package/dist/{terminal-DqsAuqhw.js → terminal-DzbPI4n0.js} +2 -2
- package/dist/{trayApp-Dayj9Frx.js → trayApp-BvtgbxMB.js} +2 -2
- package/dist/trayApp-CpPsP3_a.js +5 -0
- package/dist/{ts-C2osm4MO.js → ts-Gr1eJOUk.js} +3 -3
- package/dist/{versionChecker-BmXwOe40.js → versionChecker-BrjeGNf1.js} +2 -2
- package/dist/{widget-D5tsB-oi.js → widget-p4Db_OXd.js} +3 -3
- package/dist/{ws-B4jdOeB2.js → ws-D_QClddd.js} +3 -3
- package/dist/{ws-mz7VJJwO.js → ws-DnKPi3TS.js} +2 -2
- package/package.json +1 -1
- package/ts/composerGuard.spec.ts +279 -0
- package/ts/composerGuard.ts +366 -0
- package/ts/globalPidIndex.ts +7 -0
- package/ts/messageLog.ts +2 -0
- package/ts/needsInput.bun.spec.ts +36 -0
- package/ts/needsInput.spec.ts +36 -0
- package/ts/remotes.bun.spec.ts +125 -0
- package/ts/remotes.spec.ts +125 -0
- package/ts/remotes.ts +95 -5
- package/ts/serve.bun.spec.ts +50 -0
- package/ts/serve.spec.ts +57 -1
- package/ts/serve.ts +50 -9
- package/ts/subcommands.spec.ts +564 -42
- package/ts/subcommands.ts +650 -79
- package/ts/workDir.bun.spec.ts +90 -0
- package/ts/workDir.spec.ts +90 -0
- package/ts/workDir.ts +75 -0
- package/dist/remotes-BDMnvGI6.js +0 -5
- package/dist/subcommands-DioyG80q.js +0 -13
- package/dist/trayApp-C6C7-TSh.js +0 -5
|
@@ -8,17 +8,17 @@ import { n as localHost, r as localUser, t as formatIdentity } from "./identity-
|
|
|
8
8
|
import { n as isWorkingScreen, r as parseMenu, t as classifyNeedsInput } from "./needsInput-BHopZGM8.js";
|
|
9
9
|
import { S as postmortemStartedAt, _ as filterSinceSeq, a as getCursor, b as maxSeq, f as readInbox, o as heartbeatWatcher, p as setCursor, r as clearWatcher, s as hostId, v as filterSinceTs, y as filterUnread } from "./notifyStore-2SWKGwZI.js";
|
|
10
10
|
import { n as isWebrtcSpec } from "./webrtcLink-DFRyWNMs.js";
|
|
11
|
-
import {
|
|
11
|
+
import { l as readRemotes, u as resolveRemoteSpec } from "./remotes-B4v0Nowo.js";
|
|
12
12
|
import { execFile } from "child_process";
|
|
13
13
|
import ms from "ms";
|
|
14
14
|
import yargs from "yargs";
|
|
15
15
|
import { closeSync, constants, openSync, realpathSync } from "fs";
|
|
16
|
-
import { appendFile, mkdir, open, readFile, rename, stat, writeFile } from "fs/promises";
|
|
16
|
+
import { appendFile, mkdir, open, readFile, readdir, rename, rm, stat, writeFile } from "fs/promises";
|
|
17
17
|
import { homedir } from "os";
|
|
18
18
|
import path from "path";
|
|
19
19
|
import { lock } from "proper-lockfile";
|
|
20
20
|
import { execFileSync as execFileSync$1 } from "node:child_process";
|
|
21
|
-
import { randomBytes } from "crypto";
|
|
21
|
+
import { createHash, randomBytes } from "crypto";
|
|
22
22
|
import { promisify } from "util";
|
|
23
23
|
|
|
24
24
|
//#region ts/agentTree.ts
|
|
@@ -991,6 +991,306 @@ async function withIpcLock(pid, fn, onFallback) {
|
|
|
991
991
|
}
|
|
992
992
|
}
|
|
993
993
|
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region ts/workDir.ts
|
|
996
|
+
function isWithin(child, parent) {
|
|
997
|
+
const rel = path.relative(parent, child);
|
|
998
|
+
return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
999
|
+
}
|
|
1000
|
+
function workdirSamplePath(pid) {
|
|
1001
|
+
return path.join(agentYesHome(), "workdir", `${pid}.json`);
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* The wrapper's latest sample for this agent, or null. A sample whose
|
|
1005
|
+
* `agent_id` doesn't match belongs to an earlier agent that had the same pid.
|
|
1006
|
+
*/
|
|
1007
|
+
async function readWorkdirSample(r) {
|
|
1008
|
+
try {
|
|
1009
|
+
const j = JSON.parse(await readFile(workdirSamplePath(r.pid), "utf-8"));
|
|
1010
|
+
if (typeof j?.workdir !== "string" || typeof j?.at !== "number") return null;
|
|
1011
|
+
if (!r.agent_id || j.agent_id !== r.agent_id) return null;
|
|
1012
|
+
return {
|
|
1013
|
+
workdir: j.workdir,
|
|
1014
|
+
at: j.at
|
|
1015
|
+
};
|
|
1016
|
+
} catch {
|
|
1017
|
+
return null;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* The effective work dir for a record. The sampled repo wins unless it merely
|
|
1022
|
+
* contains the spawn dir (a lane working in the repo it was spawned in — the
|
|
1023
|
+
* spawn cwd is the more precise answer) or it no longer exists.
|
|
1024
|
+
*/
|
|
1025
|
+
async function resolveWorkDir(r) {
|
|
1026
|
+
const spawn = {
|
|
1027
|
+
workdir: r.cwd,
|
|
1028
|
+
workdir_source: "spawn",
|
|
1029
|
+
workdir_at: null
|
|
1030
|
+
};
|
|
1031
|
+
const sample = await readWorkdirSample(r);
|
|
1032
|
+
const w = sample?.workdir;
|
|
1033
|
+
if (!w || isWithin(r.cwd, w)) return spawn;
|
|
1034
|
+
if (!await stat(w).then((s) => s.isDirectory(), () => false)) return spawn;
|
|
1035
|
+
return {
|
|
1036
|
+
workdir: w,
|
|
1037
|
+
workdir_source: "observed",
|
|
1038
|
+
workdir_at: sample.at
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
//#endregion
|
|
1043
|
+
//#region ts/composerGuard.ts
|
|
1044
|
+
/**
|
|
1045
|
+
* Composer guard for `ay send`: never type into, append to, or submit a draft
|
|
1046
|
+
* someone else left in the target's input box.
|
|
1047
|
+
*
|
|
1048
|
+
* Why: a terminal shared by a human and by other agents' `ay send` has ONE
|
|
1049
|
+
* composer. Observed 2026-10-08: a human had typed "btw how" and paused; a lane's
|
|
1050
|
+
* report was pasted after it and Enter submitted both as one turn, so the human's
|
|
1051
|
+
* half-written message went out early, fused with the report, and the rest of it
|
|
1052
|
+
* was lost. The stdin-activity backoff (isUserTyping) cannot see this: it only
|
|
1053
|
+
* knows when the last key was pressed, not whether text is still sitting there.
|
|
1054
|
+
*
|
|
1055
|
+
* So the send path reads the composer off the rendered screen first. When it
|
|
1056
|
+
* holds real input, the message is parked in a per-target file queue and a
|
|
1057
|
+
* single detached drainer delivers it once the composer is empty again.
|
|
1058
|
+
*
|
|
1059
|
+
* Telling a draft from ghost text: Claude Code renders its prompt suggestion
|
|
1060
|
+
* (and the "Press up to edit queued messages" hint) with SGR 2 (dim/faint) in the
|
|
1061
|
+
* default colour; typed or pasted input is drawn without SGR 2. Measured on the
|
|
1062
|
+
* raw PTY log of a live lane: the suggestion frame is `ESC[2mwater the plants
|
|
1063
|
+
* ESC[22m` on the prompt row, while typed text on the same row is plain. Colour
|
|
1064
|
+
* is not used: typed input is drawn in the default colour, exactly like the
|
|
1065
|
+
* ghost, and the user's theme changes the palette but not the SGR 2 attribute.
|
|
1066
|
+
* Inverse cells are ignored too: a TUI that paints its own cursor as an inverse
|
|
1067
|
+
* block over the first ghost character must not turn a suggestion into a draft.
|
|
1068
|
+
*/
|
|
1069
|
+
const PROMPT_RE = /^\s*[❯›]($|\s)/u;
|
|
1070
|
+
const SEPARATOR_RE = /^\s*[─━]{3,}/u;
|
|
1071
|
+
const FOOTER_RE = /^\s*(?:·\s*)?(?:[←→] .*agents|\? for shortcuts|esc to interrupt|ctrl\+t to|GPT-[^·]*·|gpt-[^·]*·|⏵⏵|⏸|⏎ send|\d+% context left)/iu;
|
|
1072
|
+
const FOOTER_SEGMENT_RE = /·\s*(?:[←→] .*agents?|↓ |esc to interrupt)|\(shift\+tab to /u;
|
|
1073
|
+
/**
|
|
1074
|
+
* The composer's prompt row among plain-text rows (oldest first), or -1.
|
|
1075
|
+
* Claude Code boxes its composer, so the prompt is the row directly under the
|
|
1076
|
+
* LAST rule that has a prompt row under it — a `›`/`❯` that merely starts a
|
|
1077
|
+
* line of a multi-line draft is inside the box, not a second prompt. Without
|
|
1078
|
+
* any box (Codex) it is the last prompt-looking row. Shared by the draft check
|
|
1079
|
+
* and by submission confirmation, so both agree on where history ends.
|
|
1080
|
+
*/
|
|
1081
|
+
function composerPromptRow(texts) {
|
|
1082
|
+
for (let i = texts.length - 2; i >= 0; i--) if (SEPARATOR_RE.test(texts[i]) && PROMPT_RE.test(texts[i + 1])) return i + 1;
|
|
1083
|
+
return texts.findLastIndex((t) => PROMPT_RE.test(t));
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Is this row composer chrome (a rule or a Claude/Codex footer) — the end of the
|
|
1087
|
+
* input? Pass the row's `cells` when known: the loose footer match then also
|
|
1088
|
+
* requires every visible cell to be coloured, so a typed line is never cut off.
|
|
1089
|
+
*/
|
|
1090
|
+
function isComposerChrome(text, cells) {
|
|
1091
|
+
if (SEPARATOR_RE.test(text) || FOOTER_RE.test(text)) return true;
|
|
1092
|
+
if (!FOOTER_SEGMENT_RE.test(text)) return false;
|
|
1093
|
+
return !cells || cells.every((c) => !c.ch.trim() || c.ch === "\xA0" || c.colored);
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Classify the composer from rendered rows (oldest first, screen bottom last).
|
|
1097
|
+
*
|
|
1098
|
+
* Claude Code draws the composer as a box: a rule, the prompt row, any further
|
|
1099
|
+
* draft rows, a rule. The box is found by its TOP rule (the last rule directly
|
|
1100
|
+
* followed by a prompt row) and runs to the next rule, so a draft line that
|
|
1101
|
+
* itself starts with `›`/`❯`, or a blank line inside a multi-line draft, stays
|
|
1102
|
+
* inside it. When the bottom rule is not on screen (a partial redraw in the
|
|
1103
|
+
* replayed tail) the box ends at the footer instead.
|
|
1104
|
+
*
|
|
1105
|
+
* Without a top rule (Codex) the composer is the last prompt row plus every row
|
|
1106
|
+
* under it up to a rule or the footer (Codex's `⏎ send` hints / `% context
|
|
1107
|
+
* left` row) — blank rows included, so a multi-line draft with a blank line in
|
|
1108
|
+
* it is not cut short and read as empty (codex review). Any other non-dim text
|
|
1109
|
+
* down there counts as a draft: parking a message is recoverable, typing into a
|
|
1110
|
+
* draft is not. A draft whose own line starts with a prompt glyph can still be
|
|
1111
|
+
* misread there.
|
|
1112
|
+
*/
|
|
1113
|
+
function classifyComposer(rows) {
|
|
1114
|
+
const prompt = composerPromptRow(rows.map((r) => r.text));
|
|
1115
|
+
if (prompt < 0) return {
|
|
1116
|
+
kind: "unknown",
|
|
1117
|
+
reason: "no prompt row on screen"
|
|
1118
|
+
};
|
|
1119
|
+
let real = 0;
|
|
1120
|
+
let ghost = false;
|
|
1121
|
+
for (let i = prompt; i < rows.length; i++) {
|
|
1122
|
+
const row = rows[i];
|
|
1123
|
+
if (i > prompt) {
|
|
1124
|
+
if (isComposerChrome(row.text, row.cells)) break;
|
|
1125
|
+
if (!row.text.trim()) continue;
|
|
1126
|
+
}
|
|
1127
|
+
let cells = row.cells;
|
|
1128
|
+
if (i === prompt) {
|
|
1129
|
+
const glyph = cells.findIndex((c) => c.ch === "❯" || c.ch === "›");
|
|
1130
|
+
cells = glyph >= 0 ? cells.slice(glyph + 1) : cells;
|
|
1131
|
+
}
|
|
1132
|
+
for (const c of cells) {
|
|
1133
|
+
if (!c.ch.trim() || c.ch === "\xA0") continue;
|
|
1134
|
+
if (c.inverse) continue;
|
|
1135
|
+
if (c.dim) ghost = true;
|
|
1136
|
+
else real++;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return real > 0 ? {
|
|
1140
|
+
kind: "draft",
|
|
1141
|
+
chars: real
|
|
1142
|
+
} : {
|
|
1143
|
+
kind: "empty",
|
|
1144
|
+
ghost
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
/** Read the bottom `n` rows of an xterm buffer as ComposerRows. */
|
|
1148
|
+
function rowsFromXterm(term, n) {
|
|
1149
|
+
const active = term.buffer.active;
|
|
1150
|
+
const rows = [];
|
|
1151
|
+
for (let i = Math.max(0, active.length - n); i < active.length; i++) {
|
|
1152
|
+
const line = active.getLine(i);
|
|
1153
|
+
if (!line) {
|
|
1154
|
+
rows.push({
|
|
1155
|
+
text: "",
|
|
1156
|
+
cells: []
|
|
1157
|
+
});
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1160
|
+
const cells = [];
|
|
1161
|
+
for (let x = 0; x < line.length; x++) {
|
|
1162
|
+
const c = line.getCell(x);
|
|
1163
|
+
if (!c || c.getWidth() === 0) continue;
|
|
1164
|
+
cells.push({
|
|
1165
|
+
ch: c.getChars() || " ",
|
|
1166
|
+
dim: c.isDim() !== 0,
|
|
1167
|
+
inverse: c.isInverse() !== 0,
|
|
1168
|
+
colored: !c.isFgDefault()
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
rows.push({
|
|
1172
|
+
text: line.translateToString(true),
|
|
1173
|
+
cells
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
while (rows.length && rows[rows.length - 1].text.trim() === "") rows.pop();
|
|
1177
|
+
return rows;
|
|
1178
|
+
}
|
|
1179
|
+
/** How long a parked message waits for the composer before it is given up. */
|
|
1180
|
+
const PENDING_MAX_AGE_MS = 1440 * 60 * 1e3;
|
|
1181
|
+
function pendingDir(pid) {
|
|
1182
|
+
return path.join(agentYesHome(), "pending", String(pid));
|
|
1183
|
+
}
|
|
1184
|
+
async function listPending(pid) {
|
|
1185
|
+
return (await readdir(pendingDir(pid)).catch(() => [])).filter((n) => n.endsWith(".json")).sort();
|
|
1186
|
+
}
|
|
1187
|
+
async function enqueuePending(p) {
|
|
1188
|
+
const dir = pendingDir(p.pid);
|
|
1189
|
+
await mkdir(dir, {
|
|
1190
|
+
recursive: true,
|
|
1191
|
+
mode: 448
|
|
1192
|
+
});
|
|
1193
|
+
const id = `${String(p.queuedAt).padStart(15, "0")}-${randomBytes(4).toString("hex")}`;
|
|
1194
|
+
const full = {
|
|
1195
|
+
...p,
|
|
1196
|
+
id
|
|
1197
|
+
};
|
|
1198
|
+
const tmp = path.join(dir, `.${id}.tmp`);
|
|
1199
|
+
await writeFile(tmp, JSON.stringify(full), { mode: 384 });
|
|
1200
|
+
await rename(tmp, path.join(dir, `${id}.json`));
|
|
1201
|
+
return full;
|
|
1202
|
+
}
|
|
1203
|
+
async function readPending(pid, name) {
|
|
1204
|
+
const raw = await readFile(path.join(pendingDir(pid), name), "utf-8").catch(() => null);
|
|
1205
|
+
if (raw === null) return null;
|
|
1206
|
+
try {
|
|
1207
|
+
return JSON.parse(raw);
|
|
1208
|
+
} catch {
|
|
1209
|
+
return null;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Take a parked message off the queue BEFORE writing it. Delivery is therefore
|
|
1214
|
+
* at most once: a drainer that dies mid-write loses the message (it is still in
|
|
1215
|
+
* the sender's outbox as queued) rather than pasting it a second time into
|
|
1216
|
+
* whatever the composer holds next. Returns false when another process took it.
|
|
1217
|
+
*/
|
|
1218
|
+
async function claimPending(pid, name) {
|
|
1219
|
+
try {
|
|
1220
|
+
await rm(path.join(pendingDir(pid), name));
|
|
1221
|
+
return true;
|
|
1222
|
+
} catch {
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
/** Move a message the drainer gave up on out of the queue, keeping it on disk. */
|
|
1227
|
+
async function retirePending(pid, name, why) {
|
|
1228
|
+
const dir = path.join(pendingDir(pid), "undelivered");
|
|
1229
|
+
await mkdir(dir, {
|
|
1230
|
+
recursive: true,
|
|
1231
|
+
mode: 448
|
|
1232
|
+
}).catch(() => {});
|
|
1233
|
+
await rename(path.join(pendingDir(pid), name), path.join(dir, name)).catch(() => {});
|
|
1234
|
+
await writeFile(path.join(dir, `${name}.why`), `${why}\n`, { mode: 384 }).catch(() => {});
|
|
1235
|
+
}
|
|
1236
|
+
/** An identical body from the same sender within this window is a resend. */
|
|
1237
|
+
const DUPLICATE_WINDOW_MS = 6e4;
|
|
1238
|
+
function recentSendsPath(pid) {
|
|
1239
|
+
return path.join(agentYesHome(), "pending", `${pid}.recent.jsonl`);
|
|
1240
|
+
}
|
|
1241
|
+
/** Who sent it, for dedupe purposes: an agent's stable id (or pid). A person at
|
|
1242
|
+
* a shell (no agent) is never deduped — typing "continue" twice is deliberate. */
|
|
1243
|
+
function senderKey(from) {
|
|
1244
|
+
if (!from) return null;
|
|
1245
|
+
if (from.agent_id) return `a:${from.agent_id}`;
|
|
1246
|
+
return typeof from.pid === "number" ? `p:${from.pid}` : null;
|
|
1247
|
+
}
|
|
1248
|
+
function bodyHash(body) {
|
|
1249
|
+
return createHash("sha256").update(body).digest("hex");
|
|
1250
|
+
}
|
|
1251
|
+
async function readRecent(pid) {
|
|
1252
|
+
const raw = await readFile(recentSendsPath(pid), "utf-8").catch(() => "");
|
|
1253
|
+
const out = [];
|
|
1254
|
+
for (const line of raw.split("\n")) {
|
|
1255
|
+
if (!line.trim()) continue;
|
|
1256
|
+
try {
|
|
1257
|
+
out.push(JSON.parse(line));
|
|
1258
|
+
} catch {}
|
|
1259
|
+
}
|
|
1260
|
+
return out;
|
|
1261
|
+
}
|
|
1262
|
+
/** The earlier identical send this one repeats, or null. Call under the input lock. */
|
|
1263
|
+
async function findRecentDuplicate(pid, sender, body, now = Date.now()) {
|
|
1264
|
+
const hash = bodyHash(body);
|
|
1265
|
+
return (await readRecent(pid)).filter((r) => r.sender === sender && r.hash === hash && now - r.at >= 0 && now - r.at <= DUPLICATE_WINDOW_MS).at(-1) ?? null;
|
|
1266
|
+
}
|
|
1267
|
+
/** Note a send (before it is typed or parked) and drop entries past the window. */
|
|
1268
|
+
async function noteRecentSend(pid, sender, body, outcome, now = Date.now()) {
|
|
1269
|
+
const kept = (await readRecent(pid)).filter((r) => now - r.at <= DUPLICATE_WINDOW_MS);
|
|
1270
|
+
kept.push({
|
|
1271
|
+
at: now,
|
|
1272
|
+
sender,
|
|
1273
|
+
hash: bodyHash(body),
|
|
1274
|
+
outcome
|
|
1275
|
+
});
|
|
1276
|
+
const file = recentSendsPath(pid);
|
|
1277
|
+
await mkdir(path.dirname(file), {
|
|
1278
|
+
recursive: true,
|
|
1279
|
+
mode: 448
|
|
1280
|
+
});
|
|
1281
|
+
const tmp = `${file}.${randomBytes(4).toString("hex")}.tmp`;
|
|
1282
|
+
await writeFile(tmp, kept.map((r) => JSON.stringify(r)).join("\n") + "\n", { mode: 384 });
|
|
1283
|
+
await rename(tmp, file);
|
|
1284
|
+
}
|
|
1285
|
+
/** What `ay send` prints when a send exits 4, so no caller reads it as a failure. */
|
|
1286
|
+
function queuedReceipt(kind, detail) {
|
|
1287
|
+
switch (kind) {
|
|
1288
|
+
case "parked": return `ay send: nothing was typed — ${detail}. The message is parked and will be delivered once the input box is empty and nobody is typing. Queued, do not resend.`;
|
|
1289
|
+
case "cli-queued": return `ay send: the target accepted it into its own queue (${detail}); it runs after the current turn. Queued, do not resend.`;
|
|
1290
|
+
case "duplicate": return `ay send: not resent — ${detail}. Do not resend.`;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
|
|
994
1294
|
//#endregion
|
|
995
1295
|
//#region ts/subcommands.ts
|
|
996
1296
|
/**
|
|
@@ -1425,6 +1725,7 @@ const SUBCOMMANDS = new Set([
|
|
|
1425
1725
|
"hist",
|
|
1426
1726
|
"history",
|
|
1427
1727
|
"send",
|
|
1728
|
+
"send-drain",
|
|
1428
1729
|
"msgs",
|
|
1429
1730
|
"key",
|
|
1430
1731
|
"select",
|
|
@@ -1469,7 +1770,6 @@ const SEND_SETTLE_QUIET_MS = 150;
|
|
|
1469
1770
|
const SEND_SETTLE_MAX_MS = 1500;
|
|
1470
1771
|
const SEND_CONFIRM_QUIET_MS = 400;
|
|
1471
1772
|
const SEND_CONFIRM_MAX_MS = 1200;
|
|
1472
|
-
const SEND_CONFIRM_MIN_GROWTH_BYTES = 8;
|
|
1473
1773
|
const SEND_SUBMIT_MAX_RETRIES = 2;
|
|
1474
1774
|
const SEND_TYPING_POLL_MS = 200;
|
|
1475
1775
|
const SEND_TYPING_MAX_WAIT_MS = 1e4;
|
|
@@ -1686,7 +1986,7 @@ async function runSubcommand(argv) {
|
|
|
1686
1986
|
switch (sub) {
|
|
1687
1987
|
case "ls":
|
|
1688
1988
|
case "list": return await cmdLs(rest);
|
|
1689
|
-
case "ps": return await (await import("./cmdPs-
|
|
1989
|
+
case "ps": return await (await import("./cmdPs-CQxFAs9M.js")).cmdPs(rest);
|
|
1690
1990
|
case "status": return await cmdStatus(rest);
|
|
1691
1991
|
case "whoami": return await cmdWhoami(rest);
|
|
1692
1992
|
case "result": return await cmdResult(rest);
|
|
@@ -1699,6 +1999,7 @@ async function runSubcommand(argv) {
|
|
|
1699
1999
|
case "hist":
|
|
1700
2000
|
case "history": return await (await import("./hist-DZxq7NMA.js")).cmdHist(rest);
|
|
1701
2001
|
case "send": return await cmdSend(rest);
|
|
2002
|
+
case "send-drain": return await cmdSendDrain(rest);
|
|
1702
2003
|
case "msgs": return await cmdMsgs(rest);
|
|
1703
2004
|
case "key": return await cmdKey(rest);
|
|
1704
2005
|
case "select": return await cmdSelect(rest);
|
|
@@ -1733,47 +2034,47 @@ async function runSubcommand(argv) {
|
|
|
1733
2034
|
return cmdCh(rest);
|
|
1734
2035
|
}
|
|
1735
2036
|
case "term": {
|
|
1736
|
-
const { cmdTerm } = await import("./terminal-
|
|
2037
|
+
const { cmdTerm } = await import("./terminal-DzbPI4n0.js");
|
|
1737
2038
|
return cmdTerm(rest);
|
|
1738
2039
|
}
|
|
1739
2040
|
case "widget": {
|
|
1740
|
-
const { cmdWidget } = await import("./widget-
|
|
2041
|
+
const { cmdWidget } = await import("./widget-p4Db_OXd.js");
|
|
1741
2042
|
return cmdWidget(rest);
|
|
1742
2043
|
}
|
|
1743
2044
|
case "mint": {
|
|
1744
|
-
const { cmdMint } = await import("./widget-
|
|
2045
|
+
const { cmdMint } = await import("./widget-p4Db_OXd.js");
|
|
1745
2046
|
return cmdMint(rest);
|
|
1746
2047
|
}
|
|
1747
2048
|
case "serve": {
|
|
1748
|
-
const { cmdServe } = await import("./serve-
|
|
2049
|
+
const { cmdServe } = await import("./serve-D5ijYGTv.js");
|
|
1749
2050
|
return cmdServe(rest);
|
|
1750
2051
|
}
|
|
1751
2052
|
case "tray": {
|
|
1752
|
-
const { cmdTray } = await import("./trayApp-
|
|
2053
|
+
const { cmdTray } = await import("./trayApp-CpPsP3_a.js");
|
|
1753
2054
|
return cmdTray(rest);
|
|
1754
2055
|
}
|
|
1755
2056
|
case "setup": {
|
|
1756
|
-
const { cmdSetup } = await import("./setup-
|
|
2057
|
+
const { cmdSetup } = await import("./setup-DMJYufvD.js");
|
|
1757
2058
|
return cmdSetup(rest);
|
|
1758
2059
|
}
|
|
1759
2060
|
case "ws": {
|
|
1760
|
-
const { cmdWs } = await import("./ws-
|
|
2061
|
+
const { cmdWs } = await import("./ws-D_QClddd.js");
|
|
1761
2062
|
return cmdWs(rest);
|
|
1762
2063
|
}
|
|
1763
2064
|
case "schedule": {
|
|
1764
|
-
const { cmdSchedule } = await import("./schedule-
|
|
2065
|
+
const { cmdSchedule } = await import("./schedule-CMBHLSlz.js");
|
|
1765
2066
|
return cmdSchedule(rest);
|
|
1766
2067
|
}
|
|
1767
2068
|
case "remote": {
|
|
1768
|
-
const { cmdRemote } = await import("./remotes-
|
|
2069
|
+
const { cmdRemote } = await import("./remotes-DnMQWaqQ.js");
|
|
1769
2070
|
return cmdRemote(rest);
|
|
1770
2071
|
}
|
|
1771
2072
|
case "share": {
|
|
1772
|
-
const { cmdShare } = await import("./shareCmd-
|
|
2073
|
+
const { cmdShare } = await import("./shareCmd-CNhCKuOK.js");
|
|
1773
2074
|
return cmdShare(rest);
|
|
1774
2075
|
}
|
|
1775
2076
|
case "connect": {
|
|
1776
|
-
const { cmdConnect } = await import("./remotes-
|
|
2077
|
+
const { cmdConnect } = await import("./remotes-DnMQWaqQ.js");
|
|
1777
2078
|
return cmdConnect(rest);
|
|
1778
2079
|
}
|
|
1779
2080
|
case "expose": {
|
|
@@ -1781,7 +2082,7 @@ async function runSubcommand(argv) {
|
|
|
1781
2082
|
return cmdExpose(rest);
|
|
1782
2083
|
}
|
|
1783
2084
|
case "callback": {
|
|
1784
|
-
const { cmdCallback } = await import("./callback-
|
|
2085
|
+
const { cmdCallback } = await import("./callback-3RsdcuV0.js");
|
|
1785
2086
|
return cmdCallback(rest);
|
|
1786
2087
|
}
|
|
1787
2088
|
case "reap":
|
|
@@ -1792,7 +2093,7 @@ async function runSubcommand(argv) {
|
|
|
1792
2093
|
return await cmdDsh(rest);
|
|
1793
2094
|
}
|
|
1794
2095
|
case "gc": {
|
|
1795
|
-
const { gcOldBinaryDirs } = await import("./rustBinary-
|
|
2096
|
+
const { gcOldBinaryDirs } = await import("./rustBinary-etb0Jsga.js");
|
|
1796
2097
|
const { gcLogs } = await import("./globalPidIndex-DC93JhHQ.js");
|
|
1797
2098
|
const bins = gcOldBinaryDirs();
|
|
1798
2099
|
const logs = await gcLogs();
|
|
@@ -1858,6 +2159,10 @@ async function cmdHelp(managerCommands = true) {
|
|
|
1858
2159
|
process.stdout.write(agentSection + "ay - agent-yes CLI\n\nManagement:\n ay ls [keyword] list running agents\n ay ps [keyword] per-agent CPU/RSS, rolled up over each\n agent's whole process tree, + box vitals\n ay tail [-f] [-n N] <keyword> last N lines (96), -f to follow\n ay tail <keyword> --until TEXT block until TEXT is printed, then exit 0\n [--timeout 10m] [-q] [--regex] (1 = agent exited without it, 2 = no match,\n [--fail-on TEXT] [--count N] 3 = --fail-on hit first)\n ay read <keyword> [page opts] paginate: --last/--head N, --range A:B,\n --before-line L [--limit N]\n" + readAliasNote + " ay cat <keyword> full log\n ay head <keyword> first N lines\n ay hist [-n 6] [--all] [--json] past agent conversations (claude/codex\n transcripts, incl. exited sessions);\n this cwd unless --all\n ay send <keyword> <msg> send a message (keyword '.' = agent in this cwd)\n ay msgs [keyword] [--in|--out] inter-agent message log (sent + received)\n ay ch mk|join|send|read|tail <topic> local-first E2E channels: AI ↔ humans on a topic (ay ch help)\n ay term embed <pid> <script> to embed a live read-only agent terminal in a page (ay term help)\n ay widget ls | read selection|dom read an opted-in page widget's context (selection/DOM) (ay widget help)\n ay mint <target> --caps ... mint a scoped, short-TTL capability token (embeddable in a page)\n ay key <keyword> <key...> send raw keystrokes (down/up/enter/esc/…) — drives menus\n ay select <keyword> <N> pick option N of a needs_input selection menu\n ay attach <keyword> interactive attach (detach: Ctrl-\\)\n ay stop <keyword> graceful shutdown (/exit for claude/codex)\n ay exit <keyword> [reason] graceful shutdown, recording who/why (= 'ay send <kw> exit')\n ay restart <keyword> [--fresh] stop (if live) + relaunch resuming the session; --fresh replays the prompt\n ay status <keyword> agent status snapshot\n ay notify watch --unread get notified when sub-agents finish/stuck/crash (writes to inbox)\n ay whoami [--json] (inside an agent) your own registry identity + reply address\n ay result <keyword> [--wait] pull an agent's structured result envelope\n ay result set '<json>' (inside an agent) deposit your result envelope\n ay reap kill process groups leaked by dead agents\n ay gc reclaim old-version binary cache dirs + stale session logs\n ay dsh-legacy [args...] launch the DeepSeek Harness terminal client (dsh-tui)\n" + wsLines + "\nRemote:\n" + setupLine + " ay share [local|lan|tailscale|webrtc] share this machine: one URL for web console + CLI\n ay connect <share-url> [alias] save another machine's share URL as a remote\n" + shareAliasNote + " ay schedule <when> <cli> -- <msg> run an agent on a schedule (HH:MM or cron)\n ay serve [--port N] start HTTP API server (prints token)\n ay serve status show serve daemon/server status\n ay remote add <alias> http://<token>@<host>:<port>\n ay remote ls / rm <alias> manage saved remotes\n ay expose <port> share localhost:<port> at https://<id>.agent-yes.com (private link)\n ay callback --expires 7d mint an embeddable message-me widget for one agent\n ay ls <token>@<host>:<port> connect inline (no alias needed)\n ay send <token>@<host>:<port>:<kw> <msg>\n\nRun an agent (naming a CLI is what launches one — bare 'ay' shows this help):\n ay <claude|codex|...> [options] -- [prompt]\n ay claude -- \"fix the bug in auth.ts\"\n cy [options] -- [prompt] shortcut for 'ay claude' (bare 'cy' starts claude)\n ay claude --help full agent-runner options\n\nLabs (examples at https://github.com/snomiao/agent-yes/tree/main/lab):\n local-role-play/ designer + builder on one machine\n http-remote/ ay serve remote access demo\n p2p-pairing/ libp2p P2P (needs: cargo build --features swarm)\n");
|
|
1859
2160
|
return 0;
|
|
1860
2161
|
}
|
|
2162
|
+
/** Looks like an agent_id (12 hex, or a longer injected one) rather than a word. */
|
|
2163
|
+
function isAgentIdShaped(keyword) {
|
|
2164
|
+
return /^[0-9a-f]{12,32}$/i.test(keyword);
|
|
2165
|
+
}
|
|
1861
2166
|
function matchKeyword(record, keyword) {
|
|
1862
2167
|
if (!keyword) return true;
|
|
1863
2168
|
const kw = keyword.toLowerCase();
|
|
@@ -1865,8 +2170,13 @@ function matchKeyword(record, keyword) {
|
|
|
1865
2170
|
if (record.pid === Number(keyword)) return true;
|
|
1866
2171
|
return !!(record.agent_id && record.agent_id.toLowerCase().startsWith(kw));
|
|
1867
2172
|
}
|
|
1868
|
-
if (
|
|
2173
|
+
if (isAgentIdShaped(keyword)) return !!(record.agent_id && record.agent_id.toLowerCase().startsWith(kw));
|
|
2174
|
+
if (kw === "." || kw === "./") {
|
|
2175
|
+
const here = path.resolve(process.cwd());
|
|
2176
|
+
return path.resolve(record.cwd) === here || !!record.workdir && path.resolve(record.workdir) === here;
|
|
2177
|
+
}
|
|
1869
2178
|
if (record.cwd.toLowerCase().includes(kw)) return true;
|
|
2179
|
+
if (record.workdir && record.workdir.toLowerCase().includes(kw)) return true;
|
|
1870
2180
|
if (record.cli.toLowerCase() === kw) return true;
|
|
1871
2181
|
if (record.prompt && record.prompt.toLowerCase().includes(kw)) return true;
|
|
1872
2182
|
if (record.agent_id && record.agent_id.toLowerCase().startsWith(kw)) return true;
|
|
@@ -1876,14 +2186,39 @@ async function listRecords(keyword, opts) {
|
|
|
1876
2186
|
let records = mergeRecords(await readLocalTsPids(process.cwd()), opts.cwdScope ? await readLocalTsPids(opts.cwdScope) : [], await readGlobalPids());
|
|
1877
2187
|
if (!opts.all) records = records.filter((r) => r.status !== "exited");
|
|
1878
2188
|
if (opts.active) records = records.filter((r) => isPidAlive(r.pid));
|
|
2189
|
+
records = await withWorkDirs(records);
|
|
1879
2190
|
if (opts.cwdScope) {
|
|
1880
2191
|
const scope = opts.cwdScope;
|
|
1881
|
-
records = records.filter((r) => r.cwd
|
|
2192
|
+
records = records.filter((r) => isWithin(r.cwd, scope) || !!r.workdir && isWithin(r.workdir, scope));
|
|
1882
2193
|
}
|
|
1883
2194
|
if (keyword) records = records.filter((r) => matchKeyword(r, keyword));
|
|
1884
2195
|
records.sort((a, b) => b.started_at - a.started_at);
|
|
1885
2196
|
return records;
|
|
1886
2197
|
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Stamp each live record with its effective work dir (ts/workDir.ts). Exited
|
|
2200
|
+
* agents keep their spawn cwd: their transcript is history, not a location.
|
|
2201
|
+
*/
|
|
2202
|
+
async function withWorkDirs(records) {
|
|
2203
|
+
return Promise.all(records.map(async (r) => r.status === "exited" ? {
|
|
2204
|
+
...r,
|
|
2205
|
+
workdir: r.cwd,
|
|
2206
|
+
workdir_source: "spawn",
|
|
2207
|
+
workdir_at: null
|
|
2208
|
+
} : {
|
|
2209
|
+
...r,
|
|
2210
|
+
...await resolveWorkDir(r)
|
|
2211
|
+
}));
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* The CWD column: the effective work dir, with a leading `↪` when it is not the
|
|
2215
|
+
* spawn dir (sampled from its shells) so a reader knows the registry's `cwd`
|
|
2216
|
+
* says otherwise. `ay ls --json` carries both (`cwd` + `workdir`).
|
|
2217
|
+
*/
|
|
2218
|
+
function cwdLabel(r) {
|
|
2219
|
+
if (r.workdir && r.workdir_source && r.workdir_source !== "spawn") return `↪ ${shortenPath(r.workdir)}`;
|
|
2220
|
+
return shortenPath(r.cwd);
|
|
2221
|
+
}
|
|
1887
2222
|
function isPidAlive(pid) {
|
|
1888
2223
|
try {
|
|
1889
2224
|
process.kill(pid, 0);
|
|
@@ -1966,7 +2301,16 @@ async function pickInteractive(matches) {
|
|
|
1966
2301
|
async function resolveOne(keyword, opts) {
|
|
1967
2302
|
if (!keyword) throw new Error("keyword required (pid, cwd substring, cli name, or prompt substring)");
|
|
1968
2303
|
const matches = await listRecords(keyword, opts);
|
|
1969
|
-
if (matches.length === 0)
|
|
2304
|
+
if (matches.length === 0) {
|
|
2305
|
+
if (isAgentIdShaped(keyword)) {
|
|
2306
|
+
const gone = opts.all ? [] : await listRecords(keyword, {
|
|
2307
|
+
...opts,
|
|
2308
|
+
all: true
|
|
2309
|
+
});
|
|
2310
|
+
throw new Error(`no live agent has id "${keyword}"${gone.length ? ` (pid ${gone[0].pid} exited)` : ""} — it is unknown or stale: an agent whose wrapper restarted gets a new id. Find the current one with \`ay ls\`; nothing was sent.`);
|
|
2311
|
+
}
|
|
2312
|
+
throw new Error(`no agent matched "${keyword}"`);
|
|
2313
|
+
}
|
|
1970
2314
|
if (/^\d+$/.test(keyword)) {
|
|
1971
2315
|
const byPid = matches.filter((r) => r.pid === Number(keyword));
|
|
1972
2316
|
if (byPid.length === 1) return byPid[0];
|
|
@@ -2411,7 +2755,7 @@ async function runAllRemotesLs(opts) {
|
|
|
2411
2755
|
const [tasks, badges, git, typing] = state !== "stopped" ? await Promise.all([
|
|
2412
2756
|
r.log_file ? extractTaskCounts(r.log_file) : Promise.resolve(null),
|
|
2413
2757
|
r.log_file ? extractBadges(r.log_file) : Promise.resolve([]),
|
|
2414
|
-
gitStatusOnce(r.cwd, gitRootCache, gitInfoCache),
|
|
2758
|
+
gitStatusOnce(r.workdir ?? r.cwd, gitRootCache, gitInfoCache),
|
|
2415
2759
|
isUserTyping(r.pid)
|
|
2416
2760
|
]) : [
|
|
2417
2761
|
null,
|
|
@@ -2463,7 +2807,7 @@ async function runAllRemotesLs(opts) {
|
|
|
2463
2807
|
const cliW = Math.max(3, ...rows.map((r) => String(r.rec.cli).length));
|
|
2464
2808
|
const statusW = Math.max(6, ...rows.map((r) => String(r.rec.status).length));
|
|
2465
2809
|
const ageW = Math.max(3, ...rows.map((r) => ageOf(r.rec).length));
|
|
2466
|
-
const cwdW = Math.max(3, ...rows.map((r) =>
|
|
2810
|
+
const cwdW = Math.max(3, ...rows.map((r) => cwdLabel(r.rec).length));
|
|
2467
2811
|
const promptBudget = Math.max(20, termWidth - hostW - pidW - cliW - statusW - ageW - cwdW - 12 - 1);
|
|
2468
2812
|
process.stdout.write([
|
|
2469
2813
|
"HOST".padEnd(hostW),
|
|
@@ -2487,7 +2831,7 @@ async function runAllRemotesLs(opts) {
|
|
|
2487
2831
|
String(rec.cli).padEnd(cliW),
|
|
2488
2832
|
String(rec.status).padEnd(statusW),
|
|
2489
2833
|
ageOf(rec).padEnd(ageW),
|
|
2490
|
-
|
|
2834
|
+
cwdLabel(rec).padEnd(cwdW),
|
|
2491
2835
|
label
|
|
2492
2836
|
].join(" ") + "\n");
|
|
2493
2837
|
}
|
|
@@ -2910,7 +3254,7 @@ async function cmdLs(rest) {
|
|
|
2910
3254
|
const now = Date.now();
|
|
2911
3255
|
const lastActive = new Map(await Promise.all(records.map(async (r) => [r.pid, await deriveLastActiveAt(r)])));
|
|
2912
3256
|
const ageOf = (r) => humanizeAge(now - (lastActive.get(r.pid) ?? r.started_at));
|
|
2913
|
-
const rawCwds = records.map((r) =>
|
|
3257
|
+
const rawCwds = records.map((r) => cwdLabel(r));
|
|
2914
3258
|
const widths = {
|
|
2915
3259
|
pid: Math.max(3, ...records.map((r) => String(r.pid).length)),
|
|
2916
3260
|
cli: Math.max(3, ...records.map((r) => r.cli.length)),
|
|
@@ -2931,7 +3275,7 @@ async function cmdLs(rest) {
|
|
|
2931
3275
|
const [tasks, flags, git, typing] = alive ? await Promise.all([
|
|
2932
3276
|
r.log_file ? extractTaskCounts(r.log_file) : Promise.resolve(null),
|
|
2933
3277
|
r.log_file ? extractBadges(r.log_file) : Promise.resolve([]),
|
|
2934
|
-
gitStatusOnce(r.cwd, gitRootCache, gitInfoCache),
|
|
3278
|
+
gitStatusOnce(r.workdir ?? r.cwd, gitRootCache, gitInfoCache),
|
|
2935
3279
|
isUserTyping(r.pid)
|
|
2936
3280
|
]) : [
|
|
2937
3281
|
null,
|
|
@@ -2958,7 +3302,7 @@ async function cmdLs(rest) {
|
|
|
2958
3302
|
cli: r.cli,
|
|
2959
3303
|
status: displayStatus,
|
|
2960
3304
|
age: ageOf(r),
|
|
2961
|
-
cwd:
|
|
3305
|
+
cwd: cwdLabel(r),
|
|
2962
3306
|
label,
|
|
2963
3307
|
hasNote,
|
|
2964
3308
|
_alive: displayStatus !== "stopped"
|
|
@@ -3871,6 +4215,52 @@ function cliDefaults() {
|
|
|
3871
4215
|
* stuck classifiers so they don't each re-implement the tail read.
|
|
3872
4216
|
*/
|
|
3873
4217
|
async function renderLogTailLines(logPath, n = 40, geom) {
|
|
4218
|
+
const buf = await readLogTailBytes(logPath);
|
|
4219
|
+
if (!buf) return null;
|
|
4220
|
+
try {
|
|
4221
|
+
return (await renderRawLog(buf, {
|
|
4222
|
+
mode: "tail",
|
|
4223
|
+
n,
|
|
4224
|
+
cols: geom?.cols,
|
|
4225
|
+
rows: geom?.rows
|
|
4226
|
+
})).split("\n");
|
|
4227
|
+
} catch {
|
|
4228
|
+
return null;
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
/**
|
|
4232
|
+
* What the target's composer holds right now, read from the same 32 KB tail
|
|
4233
|
+
* `renderLogTailLines` renders, but keeping per-cell attributes (dim/inverse) so
|
|
4234
|
+
* ghost text can be told from a real draft. See ts/composerGuard.ts.
|
|
4235
|
+
*/
|
|
4236
|
+
async function readComposerState(record) {
|
|
4237
|
+
if (!record.log_file) return {
|
|
4238
|
+
kind: "unknown",
|
|
4239
|
+
reason: "no log file recorded"
|
|
4240
|
+
};
|
|
4241
|
+
const buf = await readLogTailBytes(record.log_file);
|
|
4242
|
+
if (!buf) return {
|
|
4243
|
+
kind: "unknown",
|
|
4244
|
+
reason: "log unreadable or empty"
|
|
4245
|
+
};
|
|
4246
|
+
const geom = await readAgentPtysize(record) ?? void 0;
|
|
4247
|
+
try {
|
|
4248
|
+
const term = new (await (loadXtermTerminal()))({
|
|
4249
|
+
cols: geom?.cols && geom.cols > 0 ? geom.cols : 200,
|
|
4250
|
+
rows: geom?.rows && geom.rows > 0 ? geom.rows : 50,
|
|
4251
|
+
scrollback: 5e3,
|
|
4252
|
+
allowProposedApi: true
|
|
4253
|
+
});
|
|
4254
|
+
await new Promise((resolve) => term.write(buf, resolve));
|
|
4255
|
+
return classifyComposer(rowsFromXterm(term, 40));
|
|
4256
|
+
} catch (e) {
|
|
4257
|
+
return {
|
|
4258
|
+
kind: "unknown",
|
|
4259
|
+
reason: `render failed: ${e?.message ?? e}`
|
|
4260
|
+
};
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
async function readLogTailBytes(logPath) {
|
|
3874
4264
|
const TAIL_BYTES = 32 * 1024;
|
|
3875
4265
|
let buf;
|
|
3876
4266
|
try {
|
|
@@ -3892,16 +4282,7 @@ async function renderLogTailLines(logPath, n = 40, geom) {
|
|
|
3892
4282
|
} catch {
|
|
3893
4283
|
return null;
|
|
3894
4284
|
}
|
|
3895
|
-
|
|
3896
|
-
return (await renderRawLog(buf, {
|
|
3897
|
-
mode: "tail",
|
|
3898
|
-
n,
|
|
3899
|
-
cols: geom?.cols,
|
|
3900
|
-
rows: geom?.rows
|
|
3901
|
-
})).split("\n");
|
|
3902
|
-
} catch {
|
|
3903
|
-
return null;
|
|
3904
|
-
}
|
|
4285
|
+
return buf;
|
|
3905
4286
|
}
|
|
3906
4287
|
async function extractNeedsInput(logPath, cli) {
|
|
3907
4288
|
const cfg = (await cliDefaults())[cli];
|
|
@@ -4128,33 +4509,116 @@ async function backoffWhileTyping(pid, maxWaitMs) {
|
|
|
4128
4509
|
waitedMs: Date.now() - start
|
|
4129
4510
|
};
|
|
4130
4511
|
}
|
|
4131
|
-
/**
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4512
|
+
/** Attribute the evidence to THIS message, never to redraws or another turn. */
|
|
4513
|
+
function inspectSubmission(screen, identity) {
|
|
4514
|
+
const unknown = {
|
|
4515
|
+
submission: "not-submitted",
|
|
4516
|
+
retry: false,
|
|
4517
|
+
transcriptMatches: 0,
|
|
4518
|
+
composerVisible: false,
|
|
4519
|
+
inComposer: false
|
|
4520
|
+
};
|
|
4521
|
+
const prompt = composerPromptRow(screen);
|
|
4522
|
+
if (prompt < 0 || !identity.trim()) return unknown;
|
|
4523
|
+
const compact = (text) => text.replace(/\s+/gu, "");
|
|
4524
|
+
const needle = compact(identity);
|
|
4525
|
+
const wrapped = identity.startsWith("<ay-msg ");
|
|
4526
|
+
const transcriptLines = screen.slice(0, prompt);
|
|
4527
|
+
const transcript = compact(transcriptLines.join("\n"));
|
|
4528
|
+
let transcriptMatches = wrapped ? transcript.split(needle).length - 1 : 0;
|
|
4529
|
+
if (!wrapped) {
|
|
4530
|
+
const lines = transcriptLines.map((line) => compact(line.replace(/^\s*[❯›]\s*/u, "")));
|
|
4531
|
+
for (let start = 0; start < lines.length; start++) {
|
|
4532
|
+
let candidate = "";
|
|
4533
|
+
for (let end = start; end < lines.length && candidate.length < needle.length; end++) {
|
|
4534
|
+
candidate += lines[end];
|
|
4535
|
+
if (candidate === needle) {
|
|
4536
|
+
transcriptMatches++;
|
|
4537
|
+
break;
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4542
|
+
const input = [screen[prompt].replace(/^\s*[❯›]\s*/u, "")];
|
|
4543
|
+
for (const line of screen.slice(prompt + 1)) {
|
|
4544
|
+
if (isComposerChrome(line)) break;
|
|
4545
|
+
input.push(line);
|
|
4546
|
+
}
|
|
4547
|
+
const composer = compact(input.join("\n"));
|
|
4548
|
+
if (wrapped ? composer.includes(needle) : composer === needle) return {
|
|
4549
|
+
submission: "not-submitted",
|
|
4550
|
+
retry: true,
|
|
4551
|
+
transcriptMatches,
|
|
4552
|
+
composerVisible: true,
|
|
4553
|
+
inComposer: true
|
|
4554
|
+
};
|
|
4555
|
+
const queued = screen.some((line) => /^\s*(?:[❯›]\s*)?Press up to edit queued messages\s*$/iu.test(line));
|
|
4556
|
+
if (transcriptMatches) return {
|
|
4557
|
+
submission: queued ? "queued" : "submitted",
|
|
4558
|
+
retry: false,
|
|
4559
|
+
transcriptMatches,
|
|
4560
|
+
composerVisible: true,
|
|
4561
|
+
inComposer: false
|
|
4562
|
+
};
|
|
4563
|
+
return {
|
|
4564
|
+
...unknown,
|
|
4565
|
+
composerVisible: true
|
|
4566
|
+
};
|
|
4567
|
+
}
|
|
4568
|
+
/** A collapsed paste is not delivery evidence; it can only authorize a retry. */
|
|
4569
|
+
function collapsedPasteToken(screen) {
|
|
4570
|
+
const prompt = screen.findLastIndex((line) => /^\s*❯($|\s)/u.test(line));
|
|
4571
|
+
if (prompt < 0) return null;
|
|
4572
|
+
const input = screen[prompt].replace(/^\s*❯\s*/u, "").trim();
|
|
4573
|
+
return /^\[Pasted text #\d+ \+\d+ lines\]$/.test(input) ? input : null;
|
|
4574
|
+
}
|
|
4575
|
+
function ownedCollapsedPaste(cli, beforePaste, afterPaste) {
|
|
4576
|
+
if (cli !== "claude" || !beforePaste) return null;
|
|
4577
|
+
const token = collapsedPasteToken(afterPaste);
|
|
4578
|
+
return token && !beforePaste.join("\n").includes(token) ? token : null;
|
|
4579
|
+
}
|
|
4580
|
+
const SEND_EXIT_QUEUED = 4;
|
|
4581
|
+
/** Retry only Enter, never the body. Three attempts, phi delay capped at 400ms. */
|
|
4582
|
+
async function submitAndConfirm(record, fifoPath, trailing, identity, beforePaste) {
|
|
4140
4583
|
const logFile = record.log_file;
|
|
4584
|
+
const geometry = await readAgentPtysize(record) ?? void 0;
|
|
4141
4585
|
const cfg = (await cliDefaults())[record.cli];
|
|
4142
|
-
let screen = [];
|
|
4586
|
+
let screen = await renderLogTailLines(logFile, 40, geometry) ?? [];
|
|
4587
|
+
const before = inspectSubmission(screen, identity);
|
|
4588
|
+
const baseline = before.transcriptMatches;
|
|
4589
|
+
const delivered = (e) => e.submission !== "not-submitted" && e.transcriptMatches > baseline || before.inComposer && e.composerVisible && !e.inComposer;
|
|
4590
|
+
const outcome = (e, current) => {
|
|
4591
|
+
const queued = e.submission === "queued" || current.some((line) => /^\s*(?:[❯›]\s*)?Press up to edit queued messages\s*$/iu.test(line));
|
|
4592
|
+
return {
|
|
4593
|
+
confirmed: !queued,
|
|
4594
|
+
screen: current,
|
|
4595
|
+
submission: queued ? "queued" : "submitted"
|
|
4596
|
+
};
|
|
4597
|
+
};
|
|
4598
|
+
const ownPaste = ownedCollapsedPaste(record.cli, beforePaste, screen);
|
|
4599
|
+
const canRetry = (evidence, current) => evidence.retry || ownPaste !== null && collapsedPasteToken(current) === ownPaste;
|
|
4143
4600
|
for (let attempt = 0; attempt <= SEND_SUBMIT_MAX_RETRIES; attempt++) {
|
|
4144
|
-
|
|
4145
|
-
|
|
4601
|
+
if (attempt) {
|
|
4602
|
+
await new Promise((r) => setTimeout(r, Math.min(400, 150 * 1.618 ** (attempt - 1))));
|
|
4603
|
+
screen = await renderLogTailLines(logFile, 40, geometry) ?? [];
|
|
4604
|
+
const settled = inspectSubmission(screen, identity);
|
|
4605
|
+
if (delivered(settled)) return outcome(settled, screen);
|
|
4606
|
+
if (!canRetry(settled, screen) || cfg?.needsInput?.length && parseMenu(screen, {
|
|
4607
|
+
needsInput: cfg.needsInput,
|
|
4608
|
+
working: cfg.working
|
|
4609
|
+
})) break;
|
|
4610
|
+
}
|
|
4146
4611
|
await writeToIpc(fifoPath, trailing);
|
|
4147
|
-
|
|
4148
|
-
screen = await renderLogTailLines(logFile, 40) ?? [];
|
|
4149
|
-
const
|
|
4150
|
-
if (
|
|
4151
|
-
|
|
4152
|
-
screen
|
|
4153
|
-
};
|
|
4612
|
+
await waitForLogQuiet(logFile, SEND_CONFIRM_QUIET_MS, SEND_CONFIRM_MAX_MS);
|
|
4613
|
+
screen = await renderLogTailLines(logFile, 40, geometry) ?? [];
|
|
4614
|
+
const evidence = inspectSubmission(screen, identity);
|
|
4615
|
+
if (delivered(evidence)) return outcome(evidence, screen);
|
|
4616
|
+
if (!canRetry(evidence, screen)) break;
|
|
4154
4617
|
}
|
|
4155
4618
|
return {
|
|
4156
4619
|
confirmed: false,
|
|
4157
|
-
screen
|
|
4620
|
+
screen,
|
|
4621
|
+
submission: "not-submitted"
|
|
4158
4622
|
};
|
|
4159
4623
|
}
|
|
4160
4624
|
/** Poll until the agent is no longer parked on a menu (selection accepted → it
|
|
@@ -4167,8 +4631,173 @@ async function waitForNeedsInputClear(record, timeoutMs) {
|
|
|
4167
4631
|
}
|
|
4168
4632
|
return false;
|
|
4169
4633
|
}
|
|
4634
|
+
/**
|
|
4635
|
+
* Write one message and its trailing code to the target, then (when `canConfirm`)
|
|
4636
|
+
* confirm the submit. The caller holds the input lock. The body is written
|
|
4637
|
+
* exactly once; only Enter is ever retried (see submitAndConfirm).
|
|
4638
|
+
*/
|
|
4639
|
+
async function deliverBody(record, fifoPath, fullBody, trailing, identity, canConfirm) {
|
|
4640
|
+
if (fullBody && trailing) {
|
|
4641
|
+
const beforePaste = canConfirm && record.log_file ? await renderLogTailLines(record.log_file, 40, await readAgentPtysize(record) ?? void 0) : null;
|
|
4642
|
+
await writeToIpc(fifoPath, fullBody);
|
|
4643
|
+
if (canConfirm && record.log_file) {
|
|
4644
|
+
await waitForLogQuiet(record.log_file, SEND_SETTLE_QUIET_MS, SEND_SETTLE_MAX_MS);
|
|
4645
|
+
return submitAndConfirm(record, fifoPath, trailing, identity, beforePaste);
|
|
4646
|
+
}
|
|
4647
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
4648
|
+
await writeToIpc(fifoPath, trailing);
|
|
4649
|
+
} else await writeToIpc(fifoPath, fullBody + trailing);
|
|
4650
|
+
return {
|
|
4651
|
+
confirmed: !canConfirm,
|
|
4652
|
+
screen: [],
|
|
4653
|
+
submission: canConfirm ? "not-submitted" : "unchecked"
|
|
4654
|
+
};
|
|
4655
|
+
}
|
|
4656
|
+
const DRAIN_POLL_BASE_MS = 500;
|
|
4657
|
+
const DRAIN_POLL_CAP_MS = 5e3;
|
|
4658
|
+
function drainerLockPath(pid) {
|
|
4659
|
+
return path.join(agentYesHome(), "pending", `${pid}.drainer`);
|
|
4660
|
+
}
|
|
4661
|
+
/** The pid of a live drainer for `pid`'s queue, or null. */
|
|
4662
|
+
async function liveDrainer(pid) {
|
|
4663
|
+
const raw = await readFile(drainerLockPath(pid), "utf-8").catch(() => null);
|
|
4664
|
+
const owner = Number(raw?.trim());
|
|
4665
|
+
if (!Number.isInteger(owner) || owner <= 0) return null;
|
|
4666
|
+
try {
|
|
4667
|
+
process.kill(owner, 0);
|
|
4668
|
+
return owner;
|
|
4669
|
+
} catch {
|
|
4670
|
+
return null;
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
/**
|
|
4674
|
+
* The argv that re-launches THIS build as the drainer. The drainer must be the
|
|
4675
|
+
* same build that parked the message (an older `ay` on PATH has no
|
|
4676
|
+
* send-drain), so prefer the running script over PATH lookup. Under the bun
|
|
4677
|
+
* runtime that is `bun <script>` on every platform: argv[1] is a .js/.ts file,
|
|
4678
|
+
* never an executable, so spawning it bare (as the first cut did on win32)
|
|
4679
|
+
* ENOENTs and the parked message waits for a manual `ay send-drain`. A
|
|
4680
|
+
* compiled single-file binary has no script to hand over: re-run the binary.
|
|
4681
|
+
*/
|
|
4682
|
+
function drainerLauncher(execPath, script, onPath) {
|
|
4683
|
+
if (!/(^|[\\/])bun(\.exe)?$/i.test(execPath)) return [execPath];
|
|
4684
|
+
if (script) return [execPath, script];
|
|
4685
|
+
return onPath ? [execPath, onPath] : null;
|
|
4686
|
+
}
|
|
4687
|
+
/** Start the per-target drainer unless one is already running. */
|
|
4688
|
+
async function ensureSendDrainer(pid) {
|
|
4689
|
+
const existing = await liveDrainer(pid);
|
|
4690
|
+
if (existing) return existing;
|
|
4691
|
+
const { spawn } = await import("node:child_process");
|
|
4692
|
+
const launcher = drainerLauncher(process.execPath, process.argv[1], Bun.which("ay"));
|
|
4693
|
+
if (!launcher) return null;
|
|
4694
|
+
const [cmd, ...pre] = launcher;
|
|
4695
|
+
const child = spawn(cmd, [
|
|
4696
|
+
...pre,
|
|
4697
|
+
"send-drain",
|
|
4698
|
+
String(pid)
|
|
4699
|
+
], {
|
|
4700
|
+
detached: true,
|
|
4701
|
+
stdio: "ignore"
|
|
4702
|
+
});
|
|
4703
|
+
child.on("error", () => {});
|
|
4704
|
+
child.unref();
|
|
4705
|
+
return child.pid ?? null;
|
|
4706
|
+
}
|
|
4707
|
+
function pidAlive(pid) {
|
|
4708
|
+
try {
|
|
4709
|
+
process.kill(pid, 0);
|
|
4710
|
+
return true;
|
|
4711
|
+
} catch (e) {
|
|
4712
|
+
return e?.code === "EPERM";
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
/**
|
|
4716
|
+
* `ay send-drain <pid>` — deliver the messages `ay send` parked for <pid>
|
|
4717
|
+
* because its composer held a draft. Runs until the queue is empty, the target
|
|
4718
|
+
* exits, or every message expired. One drainer per target (a pid file under
|
|
4719
|
+
* pending/); a second one exits at once. Normally started by `ay send` itself.
|
|
4720
|
+
*/
|
|
4721
|
+
async function cmdSendDrain(rest) {
|
|
4722
|
+
const pid = Number(rest[0]);
|
|
4723
|
+
if (!Number.isInteger(pid) || pid <= 0) throw new Error("usage: ay send-drain <pid>");
|
|
4724
|
+
const lockFile = drainerLockPath(pid);
|
|
4725
|
+
await mkdir(path.dirname(lockFile), { recursive: true });
|
|
4726
|
+
const other = await liveDrainer(pid);
|
|
4727
|
+
if (other && other !== process.pid) return 0;
|
|
4728
|
+
await writeFile(lockFile, `${process.pid}\n`);
|
|
4729
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
4730
|
+
if (await liveDrainer(pid) !== process.pid) return 0;
|
|
4731
|
+
try {
|
|
4732
|
+
let attempt = 0;
|
|
4733
|
+
const delivered = /* @__PURE__ */ new Map();
|
|
4734
|
+
for (;;) {
|
|
4735
|
+
const names = await listPending(pid);
|
|
4736
|
+
if (!names.length) {
|
|
4737
|
+
if (await withIpcLock(pid, async () => {
|
|
4738
|
+
if ((await listPending(pid)).length) return false;
|
|
4739
|
+
await rm(lockFile, { force: true });
|
|
4740
|
+
return true;
|
|
4741
|
+
})) return 0;
|
|
4742
|
+
continue;
|
|
4743
|
+
}
|
|
4744
|
+
const name = names[0];
|
|
4745
|
+
const msg = await readPending(pid, name);
|
|
4746
|
+
if (!msg) {
|
|
4747
|
+
await retirePending(pid, name, "unparseable pending file");
|
|
4748
|
+
continue;
|
|
4749
|
+
}
|
|
4750
|
+
const gone = !pidAlive(pid);
|
|
4751
|
+
const expired = Date.now() - msg.queuedAt > PENDING_MAX_AGE_MS;
|
|
4752
|
+
if (gone || expired) {
|
|
4753
|
+
const why = gone ? "target exited before its input box was free" : "expired after 24h";
|
|
4754
|
+
for (const n of gone ? names : [name]) await retirePending(pid, n, why);
|
|
4755
|
+
await recordMessage({
|
|
4756
|
+
at: Date.now(),
|
|
4757
|
+
...msg.record,
|
|
4758
|
+
confirmed: false,
|
|
4759
|
+
submission: "not-submitted"
|
|
4760
|
+
});
|
|
4761
|
+
if (gone) return 1;
|
|
4762
|
+
continue;
|
|
4763
|
+
}
|
|
4764
|
+
const from = senderKey(msg.record.from);
|
|
4765
|
+
const msgBody = msg.record.body ?? "";
|
|
4766
|
+
const dupKey = from && msgBody ? `${from}|${bodyHash(msgBody)}` : null;
|
|
4767
|
+
const prev = dupKey ? delivered.get(dupKey) : void 0;
|
|
4768
|
+
if (prev !== void 0 && msg.queuedAt - prev <= DUPLICATE_WINDOW_MS) {
|
|
4769
|
+
await retirePending(pid, name, `duplicate of the same sender's identical message delivered ${Math.round((Date.now() - prev) / 1e3)}s ago`);
|
|
4770
|
+
continue;
|
|
4771
|
+
}
|
|
4772
|
+
const record = (await readGlobalPids()).find((r) => r.pid === pid);
|
|
4773
|
+
let result = null;
|
|
4774
|
+
if (record && !await isUserTyping(pid)) await withIpcLock(pid, async () => {
|
|
4775
|
+
if (await isUserTyping(pid)) return;
|
|
4776
|
+
if ((await readComposerState(record)).kind !== "empty") return;
|
|
4777
|
+
if (!await claimPending(pid, name)) return;
|
|
4778
|
+
result = await deliverBody(record, msg.fifoPath, msg.fullBody, msg.trailing, msg.identity, msg.trailing === "\r" && Boolean(record.log_file));
|
|
4779
|
+
});
|
|
4780
|
+
if (result) {
|
|
4781
|
+
const d = result;
|
|
4782
|
+
if (dupKey) delivered.set(dupKey, Date.now());
|
|
4783
|
+
await recordMessage({
|
|
4784
|
+
at: Date.now(),
|
|
4785
|
+
...msg.record,
|
|
4786
|
+
confirmed: d.confirmed,
|
|
4787
|
+
submission: d.submission
|
|
4788
|
+
});
|
|
4789
|
+
attempt = 0;
|
|
4790
|
+
continue;
|
|
4791
|
+
}
|
|
4792
|
+
attempt++;
|
|
4793
|
+
await new Promise((r) => setTimeout(r, Math.min(DRAIN_POLL_CAP_MS, DRAIN_POLL_BASE_MS * 1.618 ** (attempt - 1))));
|
|
4794
|
+
}
|
|
4795
|
+
} finally {
|
|
4796
|
+
if (await liveDrainer(pid) === process.pid) await rm(lockFile, { force: true });
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4170
4799
|
async function cmdSend(rest) {
|
|
4171
|
-
const argv = await yargs(rest).parserConfiguration({ "boolean-negation": false }).usage("Usage: ay send <keyword> <msg|-> [options]\n\nExit: 0 sent, 3 target unreachable (nothing sent; ay ls shows it as\n'unreachable' — ay restart <pid> revives it),
|
|
4800
|
+
const argv = await yargs(rest).parserConfiguration({ "boolean-negation": false }).usage("Usage: ay send <keyword> <msg|-> [options]\n\nExit: 0 sent, 3 target unreachable (nothing sent; ay ls shows it as\n'unreachable' — ay restart <pid> revives it), 4 QUEUED (accepted, not yet\nsubmitted: either the CLI queued it, or its input box held someone's draft and\nthe message was parked for delivery once the box is empty — do not resend;\nan identical resend from the same agent within 60s is dropped as a DUPLICATE),\n1 everything else.").option("code", {
|
|
4172
4801
|
type: "string",
|
|
4173
4802
|
default: "enter",
|
|
4174
4803
|
description: "Trailing control code (enter|esc|ctrl-c|ctrl-y|tab|none)"
|
|
@@ -4281,26 +4910,70 @@ async function cmdSend(rest) {
|
|
|
4281
4910
|
}
|
|
4282
4911
|
const fullBody = framePaste$1 ? framePaste(prefix + body + suffix) : prefix + body + suffix;
|
|
4283
4912
|
const noWait = Boolean(argv.noWait) || process.env.AGENT_YES_SEND_NO_WAIT === "1";
|
|
4913
|
+
let parkReason = null;
|
|
4284
4914
|
if (fullBody && !noWait && !force) {
|
|
4285
4915
|
const { clear, waitedMs } = await backoffWhileTyping(record.pid, SEND_TYPING_MAX_WAIT_MS);
|
|
4286
|
-
if (!clear)
|
|
4916
|
+
if (!clear) parkReason = `user still typing after ${Math.round(waitedMs / 1e3)}s`;
|
|
4287
4917
|
else if (waitedMs > 0) process.stderr.write(`waited ${Math.round(waitedMs / 1e3)}s for the user to pause typing before sending.\n`);
|
|
4288
4918
|
}
|
|
4289
4919
|
const canConfirm = trailing === "\r" && Boolean(fullBody) && !noWait;
|
|
4290
|
-
|
|
4920
|
+
const identity = nonce ? `<ay-msg ${nonce}` : body;
|
|
4921
|
+
let confirmed = !canConfirm;
|
|
4922
|
+
const receipt = { submission: canConfirm ? "not-submitted" : "unchecked" };
|
|
4291
4923
|
let lastScreen = [];
|
|
4924
|
+
let parked = false;
|
|
4925
|
+
let duplicateOf = null;
|
|
4926
|
+
const mailBase = {
|
|
4927
|
+
nonce,
|
|
4928
|
+
origin: sender.agent ? void 0 : "shell",
|
|
4929
|
+
from_via: sender.via,
|
|
4930
|
+
sender_observed: observedSender(),
|
|
4931
|
+
from: sender.agent ? {
|
|
4932
|
+
pid: sender.agent.pid,
|
|
4933
|
+
cli: sender.agent.cli,
|
|
4934
|
+
cwd: sender.agent.cwd,
|
|
4935
|
+
agent_id: sender.agent.agent_id
|
|
4936
|
+
} : null,
|
|
4937
|
+
to: {
|
|
4938
|
+
pid: record.pid,
|
|
4939
|
+
cli: record.cli,
|
|
4940
|
+
cwd: record.cwd,
|
|
4941
|
+
agent_id: record.agent_id
|
|
4942
|
+
},
|
|
4943
|
+
body,
|
|
4944
|
+
code: trailing === "\r" ? void 0 : codeName,
|
|
4945
|
+
wrapped: Boolean(nonce)
|
|
4946
|
+
};
|
|
4292
4947
|
try {
|
|
4293
4948
|
await withIpcLock(record.pid, async () => {
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4949
|
+
const dedupeKey = force || !body ? null : senderKey(mailBase.from);
|
|
4950
|
+
if (dedupeKey) {
|
|
4951
|
+
duplicateOf = await findRecentDuplicate(record.pid, dedupeKey, body);
|
|
4952
|
+
if (duplicateOf) return;
|
|
4953
|
+
}
|
|
4954
|
+
if (fullBody) {
|
|
4955
|
+
if (!parkReason && (await listPending(record.pid)).length) parkReason = "earlier messages to this agent are still queued";
|
|
4956
|
+
if (!parkReason) {
|
|
4957
|
+
const composer = await readComposerState(record);
|
|
4958
|
+
if (composer.kind === "draft") parkReason = `its input box holds a draft (${composer.chars} chars)`;
|
|
4959
|
+
else if (composer.kind === "unknown") process.stderr.write(`warning: ay send could not see pid ${record.pid}'s input box (${composer.reason}) — sending without the draft check.\n`);
|
|
4960
|
+
}
|
|
4961
|
+
if (dedupeKey) await noteRecentSend(record.pid, dedupeKey, body, parkReason ? "queued" : "sent");
|
|
4962
|
+
if (parkReason) {
|
|
4963
|
+
await enqueuePending({
|
|
4964
|
+
queuedAt: Date.now(),
|
|
4965
|
+
pid: record.pid,
|
|
4966
|
+
fifoPath,
|
|
4967
|
+
fullBody,
|
|
4968
|
+
trailing,
|
|
4969
|
+
identity,
|
|
4970
|
+
record: mailBase
|
|
4971
|
+
});
|
|
4972
|
+
parked = true;
|
|
4973
|
+
return;
|
|
4302
4974
|
}
|
|
4303
|
-
}
|
|
4975
|
+
}
|
|
4976
|
+
({confirmed, screen: lastScreen, submission: receipt.submission} = await deliverBody(record, fifoPath, fullBody, trailing, identity, canConfirm));
|
|
4304
4977
|
}, (why) => process.stderr.write(`warning: ay send writing pid ${record.pid} without the input lock (${why})\n`));
|
|
4305
4978
|
} catch (e) {
|
|
4306
4979
|
const code = e?.code;
|
|
@@ -4308,9 +4981,30 @@ async function cmdSend(rest) {
|
|
|
4308
4981
|
process.stderr.write(`ay send: pid ${record.pid} (${record.cli}) became UNREACHABLE mid-send — its stdin FIFO ${fifoPath} stopped taking a writer (${code}). The message may be partly delivered. Retire the row with: ay stop ${record.pid} (registry only, sends no signal); ay restart writes to this same FIFO and would fail the same way.\n`);
|
|
4309
4982
|
return SEND_EXIT_UNREACHABLE;
|
|
4310
4983
|
}
|
|
4984
|
+
if (duplicateOf) {
|
|
4985
|
+
const dup = duplicateOf;
|
|
4986
|
+
const ago = Math.max(0, Math.round((Date.now() - dup.at) / 1e3));
|
|
4987
|
+
process.stdout.write(`DUPLICATE (not resent) to pid ${record.pid} (${record.cli}): ${truncate(body + trailing, 80)}\n`);
|
|
4988
|
+
process.stderr.write(queuedReceipt("duplicate", `you sent this exact message to pid ${record.pid} ${ago}s ago and it was ${dup.outcome}`) + "\n");
|
|
4989
|
+
return dup.outcome === "queued" ? SEND_EXIT_QUEUED : 0;
|
|
4990
|
+
}
|
|
4991
|
+
if (parked) {
|
|
4992
|
+
const drainer = await ensureSendDrainer(record.pid);
|
|
4993
|
+
process.stdout.write(`QUEUED to pid ${record.pid} (${record.cli}): ${truncate(body + trailing, 80)}\n`);
|
|
4994
|
+
process.stderr.write(queuedReceipt("parked", parkReason) + (drainer ? ` (drainer pid ${drainer})\n` : `\nay send: the drainer did not start; run: ay send-drain ${record.pid}\n`));
|
|
4995
|
+
if (body) await recordMessage({
|
|
4996
|
+
at: Date.now(),
|
|
4997
|
+
...mailBase,
|
|
4998
|
+
confirmed: false,
|
|
4999
|
+
submission: "queued"
|
|
5000
|
+
});
|
|
5001
|
+
return SEND_EXIT_QUEUED;
|
|
5002
|
+
}
|
|
5003
|
+
const { submission } = receipt;
|
|
4311
5004
|
const payload = body + trailing;
|
|
4312
|
-
const status = confirmed ? "sent" : "
|
|
5005
|
+
const status = submission === "queued" ? "QUEUED" : confirmed ? "sent" : "NOT SUBMITTED (NOT confirmed: our message remains in input or destination evidence is unavailable)";
|
|
4313
5006
|
process.stdout.write(`${status} to pid ${record.pid} (${record.cli}): ${truncate(payload, 80)}\n`);
|
|
5007
|
+
if (submission === "queued") process.stderr.write(queuedReceipt("cli-queued", `${record.cli} is busy`) + "\n");
|
|
4314
5008
|
if (body) await recordMessage({
|
|
4315
5009
|
at: Date.now(),
|
|
4316
5010
|
nonce,
|
|
@@ -4332,9 +5026,10 @@ async function cmdSend(rest) {
|
|
|
4332
5026
|
body,
|
|
4333
5027
|
code: trailing === "\r" ? void 0 : codeName,
|
|
4334
5028
|
confirmed,
|
|
5029
|
+
submission,
|
|
4335
5030
|
wrapped: Boolean(nonce)
|
|
4336
5031
|
});
|
|
4337
|
-
if (!confirmed) process.stderr.write(
|
|
5032
|
+
if (!confirmed && submission !== "queued") process.stderr.write("\nwarning: couldn't confirm the CLI acted on this message — it may still be sitting unsubmitted in the prompt. Last screen:\n" + lastScreen.slice(-8).map((l) => ` ${l}`).join("\n") + "\n");
|
|
4338
5033
|
if (record.log_file) {
|
|
4339
5034
|
const geom = await readAgentPtysize(record) ?? void 0;
|
|
4340
5035
|
const tail = await renderLogTailLines(record.log_file, 10, geom) ?? [];
|
|
@@ -4349,7 +5044,7 @@ async function cmdSend(rest) {
|
|
|
4349
5044
|
const tip = stopTipForCli(record.cli, record.pid);
|
|
4350
5045
|
if (tip) process.stderr.write(tip);
|
|
4351
5046
|
}
|
|
4352
|
-
return confirmed ? 0 : 1;
|
|
5047
|
+
return submission === "queued" ? SEND_EXIT_QUEUED : confirmed ? 0 : 1;
|
|
4353
5048
|
}
|
|
4354
5049
|
/**
|
|
4355
5050
|
* `ay msgs [keyword]` — show the inter-agent messages an agent sent and
|
|
@@ -4442,7 +5137,7 @@ async function cmdMsgs(rest) {
|
|
|
4442
5137
|
const fromLabel = senderLabel(rec);
|
|
4443
5138
|
const peer = dir === "out" ? `→ ${rec.to.cli} #${rec.to.pid}` : `← ${fromLabel}`;
|
|
4444
5139
|
const via = rec.remote ? ` (via ${rec.remote})` : "";
|
|
4445
|
-
const flag = rec.confirmed === false ? " (unconfirmed)" : "";
|
|
5140
|
+
const flag = rec.submission === "queued" ? " (QUEUED)" : rec.confirmed === false ? " (unconfirmed)" : "";
|
|
4446
5141
|
const line = (rec.kind ? `[${rec.kind}] ` : "") + truncate(rec.body.replace(/\s+/g, " "), 100);
|
|
4447
5142
|
process.stdout.write(`${when} ${peer.padEnd(20)}${via}${flag} ${line}\n`);
|
|
4448
5143
|
}
|
|
@@ -4895,7 +5590,7 @@ async function cmdAttach(rest) {
|
|
|
4895
5590
|
const winsizeDir = path.join(ayHome, "winsize");
|
|
4896
5591
|
await mkdir(winsizeDir, { recursive: true });
|
|
4897
5592
|
const winsizePath = path.join(winsizeDir, String(record.pid));
|
|
4898
|
-
const { resolveDaemonHttpBase, loadTokenReadOnly } = await import("./serve-
|
|
5593
|
+
const { resolveDaemonHttpBase, loadTokenReadOnly } = await import("./serve-D5ijYGTv.js");
|
|
4899
5594
|
const daemonBase = await resolveDaemonHttpBase().catch(() => null);
|
|
4900
5595
|
const daemonToken = daemonBase ? await loadTokenReadOnly().catch(() => null) ?? "" : "";
|
|
4901
5596
|
const capViewer = `attach:${process.pid}`;
|
|
@@ -5251,6 +5946,8 @@ async function snapshotStatus(record) {
|
|
|
5251
5946
|
pid: record.pid,
|
|
5252
5947
|
cli: record.cli,
|
|
5253
5948
|
cwd: record.cwd,
|
|
5949
|
+
workdir: record.workdir ?? record.cwd,
|
|
5950
|
+
workdir_source: record.workdir_source ?? "spawn",
|
|
5254
5951
|
state,
|
|
5255
5952
|
activity,
|
|
5256
5953
|
question,
|
|
@@ -5622,7 +6319,7 @@ async function cmdNotify(rest) {
|
|
|
5622
6319
|
}
|
|
5623
6320
|
const ensure = async () => {
|
|
5624
6321
|
if (!argv["ensure-daemon"]) return;
|
|
5625
|
-
const { ensureDaemon } = await import("./notifyDaemon-
|
|
6322
|
+
const { ensureDaemon } = await import("./notifyDaemon-CxkiJvOo.js");
|
|
5626
6323
|
await ensureDaemon().catch(() => null);
|
|
5627
6324
|
};
|
|
5628
6325
|
await heartbeatWatcher(parent, selfStartedAt);
|
|
@@ -5696,7 +6393,7 @@ async function cmdNotifyCursor(args) {
|
|
|
5696
6393
|
}
|
|
5697
6394
|
async function cmdNotifyd(rest) {
|
|
5698
6395
|
const sub = rest[0] ?? "status";
|
|
5699
|
-
const daemon = await import("./notifyDaemon-
|
|
6396
|
+
const daemon = await import("./notifyDaemon-CxkiJvOo.js");
|
|
5700
6397
|
switch (sub) {
|
|
5701
6398
|
case "run": return daemon.runDaemon();
|
|
5702
6399
|
case "once": return daemon.runDaemon({ once: true });
|
|
@@ -5722,5 +6419,5 @@ async function cmdNotifyd(rest) {
|
|
|
5722
6419
|
}
|
|
5723
6420
|
|
|
5724
6421
|
//#endregion
|
|
5725
|
-
export {
|
|
5726
|
-
//# sourceMappingURL=subcommands-
|
|
6422
|
+
export { renderRawLog as $, isBareManagerInvocation as A, listRecords as B, extractMenu as C, inspectSubmission as D, finalizedLines as E, isUnknownManagerToken as F, readAgentPtysize as G, menuSelectKeys as H, isUnreachableWriteErrno as I, readNotes as J, readComposerState as K, isUserTyping as L, isPidAlive as M, isSlashCommand as N, isAgentIdShaped as O, isSubcommand as P, renderLogTailLines as Q, lastReadAt as R, extractBadges as S, extractTaskCounts as T, ownedCollapsedPaste as U, matchKeyword as V, probeStdinReachable as W, recentMessageEdges as X, readPtysize as Y, recentReadEdges as Z, deriveLiveState as _, TYPING_BADGE as _t, SEND_BODY_MAX_CHARS as a, runSubcommand as at, envelopeAttribution as b, TYPING_WINDOW_MS as c, stdinActivityPath as ct, cliDefaults as d, waitForLogQuiet as dt, renderRawLogLines as et, cmdHelp as f, writeKeysPaced as ft, cwdLabel as g, shouldFramePaste as gt, cursorAbs as h, framePaste as ht, READ_WINDOW_MS as i, restartHintLines as it, isExitRequest as j, isAgentStuck as k, backoffWhileTyping as l, stopTipForCli as lt, controlCodeFromName as m, withIpcLock as mt, MAX_RENDER_BYTES as n, resolveReadWindow as nt, SEND_EXIT_QUEUED as o, sendPayloadCapError as ot, confirmStdinUnreachable as p, writeToIpc as pt, readLogForRender as q, READ_PAGE_DEFAULT as r, resolveResumeArgs as rt, SEND_EXIT_UNREACHABLE as s, snapshotStatus as st, GRACEFUL_EXIT_COMMANDS as t, resolveOne as tt, buildEnvelope as u, submitAndConfirm as ut, deriveLiveStatus as v, buildAgentForest as vt, extractNeedsInput as w, envelopeCostFor as x, drainerLauncher as y, flattenForest as yt, lastStdinAt as z };
|
|
6423
|
+
//# sourceMappingURL=subcommands-BncoxUN6.js.map
|