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
|
@@ -1,27 +1,56 @@
|
|
|
1
1
|
import { t as invokedCliName } from "./invokedCli-zdFbz1ST.js";
|
|
2
2
|
import { t as agentYesHome } from "./agentYesHome-JmJC28YX.js";
|
|
3
|
-
import { a as readGlobalPids, s as updateGlobalPidStatus } from "./globalPidIndex-
|
|
4
|
-
import { t as PidStore } from "./pidStore-
|
|
3
|
+
import { a as readGlobalPids, s as updateGlobalPidStatus } from "./globalPidIndex-BsjlId-h.js";
|
|
4
|
+
import { t as PidStore } from "./pidStore-C50VPk3E.js";
|
|
5
5
|
import { a as recordOutbox, i as recordMessage, n as readMailbox, o as senderLabel, t as partyMatches } from "./messageLog-Dq_ka-Bt.js";
|
|
6
6
|
import { t as loadSharedCliDefaults } from "./configShared-De4bR5hH.js";
|
|
7
|
-
import { n as localHost, r as localUser, t as formatIdentity } from "./identity-
|
|
8
|
-
import { i as isWebrtcSpec } from "./webrtcLink-
|
|
9
|
-
import { l as readRemotes, u as resolveRemoteSpec } from "./remotes-
|
|
10
|
-
import { n as hostedRoomMember, r as roomAliasPlaceholder } from "./roomReplyAlias-
|
|
7
|
+
import { n as localHost, r as localUser, t as formatIdentity } from "./identity-Ckav3-Up.js";
|
|
8
|
+
import { i as isWebrtcSpec } from "./webrtcLink-DcvacEci.js";
|
|
9
|
+
import { l as readRemotes, u as resolveRemoteSpec } from "./remotes-BsMGvAay.js";
|
|
10
|
+
import { n as hostedRoomMember, r as roomAliasPlaceholder } from "./roomReplyAlias-B-v76TA8.js";
|
|
11
11
|
import { n as isWorkingScreen, r as parseMenu, t as classifyNeedsInput } from "./needsInput-hRiWFjGy.js";
|
|
12
12
|
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-DIfkfKB2.js";
|
|
13
|
-
import {
|
|
13
|
+
import { o as pidOwnershipVerdict, r as findAgentAncestor, s as readAncestryTable, t as ageMatchesRegistration } from "./senderAncestry-CVHeKk1Y.js";
|
|
14
14
|
import ms from "ms";
|
|
15
15
|
import yargs from "yargs";
|
|
16
|
-
import { closeSync, constants, openSync, realpathSync } from "fs";
|
|
16
|
+
import { closeSync, constants, mkdirSync, openSync, readFileSync, realpathSync, renameSync, writeFileSync } from "fs";
|
|
17
17
|
import { appendFile, mkdir, open, readFile, readdir, rename, rm, stat, writeFile } from "fs/promises";
|
|
18
18
|
import { homedir } from "os";
|
|
19
19
|
import path from "path";
|
|
20
20
|
import { lock } from "proper-lockfile";
|
|
21
|
-
import { execFileSync
|
|
21
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
22
22
|
import { createHash, randomBytes } from "crypto";
|
|
23
|
-
import { promisify } from "util";
|
|
24
23
|
|
|
24
|
+
//#region ts/interruptSend.ts
|
|
25
|
+
/** Permission prompts take precedence over lingering busy chrome. */
|
|
26
|
+
function interruptScreenState(cli, lines, cfg) {
|
|
27
|
+
const text = lines.join("\n");
|
|
28
|
+
const matches = (patterns = []) => patterns.some((re) => new RegExp(re.source, re.flags.replace(/[gy]/g, "")).test(text));
|
|
29
|
+
if (matches(cfg.needsInput) || lines.some((line) => /^\s*[│┃]?\s*(?:[❯›>]\s*\d+\.\s|.*\bctrl\+k\s+approve\b|.*\bneeds approval\b)/i.test(line))) return "permission";
|
|
30
|
+
if (matches(cfg.working)) return "busy";
|
|
31
|
+
const prompt = cli === "agy" ? /^\s*>($|\s)/u : /^\s*[❯›]($|\s)/u;
|
|
32
|
+
return lines.some((line) => prompt.test(line)) ? "idle" : "unknown";
|
|
33
|
+
}
|
|
34
|
+
/** Caller holds the input lock through cancellation, idle detection and delivery. */
|
|
35
|
+
async function interruptBeforeSend(cli, deps, timeoutMs = 8e3) {
|
|
36
|
+
if (![
|
|
37
|
+
"claude",
|
|
38
|
+
"codex",
|
|
39
|
+
"agy"
|
|
40
|
+
].includes(cli)) return "unsupported";
|
|
41
|
+
const before = await deps.readState();
|
|
42
|
+
if (before !== "busy") return before;
|
|
43
|
+
await deps.write("\x1B");
|
|
44
|
+
for (let elapsed = 0; elapsed < timeoutMs; elapsed += 100) {
|
|
45
|
+
await deps.sleep(100);
|
|
46
|
+
const state = await deps.readState();
|
|
47
|
+
if (state === "idle") return "interrupted";
|
|
48
|
+
if (state === "permission") return "permission";
|
|
49
|
+
}
|
|
50
|
+
throw new Error("ay send: --interrupt timed out waiting for the idle prompt; message was not sent");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
25
54
|
//#region ts/agentTree.ts
|
|
26
55
|
/**
|
|
27
56
|
* Link records into a forest via parent_pid === wrapper_pid. Records whose
|
|
@@ -127,6 +156,21 @@ function markerOf(line) {
|
|
|
127
156
|
if (PENDING.has(ch)) return "pending";
|
|
128
157
|
return null;
|
|
129
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Whether raw bytes can render to a todo block at all: a block needs the ⎿ anchor and at least two marker
|
|
161
|
+
* cells. Rendering cannot create a glyph that is not in the bytes, but REP (`CSI Ps b`) repeats the previous
|
|
162
|
+
* character, so with a REP in the bytes one literal marker is enough. False → `parseTaskCounts` of any render
|
|
163
|
+
* of them is null, so a caller can skip the (costly) xterm replay. Conservative: never a false negative.
|
|
164
|
+
*/
|
|
165
|
+
function mayHoldTaskBlock(text) {
|
|
166
|
+
if (!text.includes(ANCHOR)) return false;
|
|
167
|
+
const repeats = /\x1b\[[0-9;]*b/.test(text);
|
|
168
|
+
let markers = 0;
|
|
169
|
+
for (const ch of text) if (DONE.has(ch) || IN_PROGRESS.has(ch) || PENDING.has(ch)) {
|
|
170
|
+
if (++markers >= (repeats ? 1 : 2)) return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
130
174
|
function isBareAnchor(line) {
|
|
131
175
|
const s = line.trim();
|
|
132
176
|
return s.startsWith(ANCHOR) && s.slice(1).trim() === "";
|
|
@@ -595,174 +639,6 @@ function shouldFramePaste(opts) {
|
|
|
595
639
|
return opts.supported && Boolean(opts.body) && !opts.isSlashCommand;
|
|
596
640
|
}
|
|
597
641
|
|
|
598
|
-
//#endregion
|
|
599
|
-
//#region ts/senderAncestry.ts
|
|
600
|
-
/**
|
|
601
|
-
* Who is calling `ay send`, established by OBSERVING the caller rather than by
|
|
602
|
-
* asking it.
|
|
603
|
-
*
|
|
604
|
-
* `resolveSender()` reads `AGENT_YES_PID`, which the `ay` wrapper injects. That
|
|
605
|
-
* covers a lane launched through the wrapper and nothing else. A session that
|
|
606
|
-
* shells out to `ay send` WITHOUT that env — an SDK / `claude -p` pass, a
|
|
607
|
-
* cron-driven script, anything re-exec'd through a shell that scrubbed the
|
|
608
|
-
* environment — was recorded with `from: null`, i.e. indistinguishable from an
|
|
609
|
-
* anonymous stranger.
|
|
610
|
-
*
|
|
611
|
-
* That is not a cosmetic mislabel. Receiving lanes refuse messages they cannot
|
|
612
|
-
* attribute, which is correct doctrine; so an honest sender whose env happened
|
|
613
|
-
* to be missing had its traffic dropped as untrustworthy, and two lanes spent
|
|
614
|
-
* hours on an intrusion theory that was false.
|
|
615
|
-
*
|
|
616
|
-
* The env var is a CLAIM the caller passes along. The process tree is a FACT
|
|
617
|
-
* the kernel keeps and the caller cannot forge from inside a message body: a
|
|
618
|
-
* process cannot choose its own ancestors. So when the claim is absent, walk up
|
|
619
|
-
* from our own pid and stop at the first ancestor that is a REGISTERED agent.
|
|
620
|
-
* A lane's `ay send`, however many shells deep, is a descendant of that lane.
|
|
621
|
-
*
|
|
622
|
-
* Two things this deliberately does NOT do:
|
|
623
|
-
*
|
|
624
|
-
* - It never invents a sender. No ancestor registered ⇒ nothing is attributed,
|
|
625
|
-
* and the caller is described by what was measured about it (user, host,
|
|
626
|
-
* cwd, pid) rather than guessed. Filling the field with a plausible name is
|
|
627
|
-
* the failure one level worse than the one this fixes.
|
|
628
|
-
* - It never lets the BODY supply identity. Everything here comes from the
|
|
629
|
-
* kernel and the registry.
|
|
630
|
-
*/
|
|
631
|
-
const execFileAsync = promisify(execFile);
|
|
632
|
-
/**
|
|
633
|
-
* Ancestor pids of `pid`, nearest first, via `ps`.
|
|
634
|
-
*
|
|
635
|
-
* `ps` rather than `/proc` so it works on macOS as well as Linux — this repo's
|
|
636
|
-
* other walker is `/proc`-only and the fleet is mostly macOS. ONE invocation
|
|
637
|
-
* for the whole table: a call per hop would multiply the cost of every send by
|
|
638
|
-
* the depth of the tree. Measured at ~40ms for 887 processes.
|
|
639
|
-
*
|
|
640
|
-
* Best-effort by construction. A failure here means "could not establish",
|
|
641
|
-
* which is a legitimate answer — never an error that blocks a send.
|
|
642
|
-
*/
|
|
643
|
-
async function ancestorPids(pid, opts = {}) {
|
|
644
|
-
const maxHops = opts.maxHops ?? 32;
|
|
645
|
-
let table;
|
|
646
|
-
try {
|
|
647
|
-
table = await (opts.readTable ?? readProcessTable)();
|
|
648
|
-
} catch {
|
|
649
|
-
return [];
|
|
650
|
-
}
|
|
651
|
-
const out = [];
|
|
652
|
-
const seen = new Set([pid]);
|
|
653
|
-
let cur = pid;
|
|
654
|
-
for (let hops = 0; hops < maxHops; hops++) {
|
|
655
|
-
const parent = table.get(cur)?.ppid;
|
|
656
|
-
if (parent === void 0 || parent <= 1 || seen.has(parent)) break;
|
|
657
|
-
out.push(parent);
|
|
658
|
-
seen.add(parent);
|
|
659
|
-
cur = parent;
|
|
660
|
-
}
|
|
661
|
-
return out;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* pid → {ppid, ageSecs} for every visible process, from one `ps`.
|
|
665
|
-
*
|
|
666
|
-
* `etime` (elapsed) rather than `lstart` because it is POSIX and identically
|
|
667
|
-
* available on macOS and Linux, where `etimes` is Linux-only. Windows has no
|
|
668
|
-
* `ps` at all — the caller must not spawn one there; see {@link readProcessTable}.
|
|
669
|
-
*/
|
|
670
|
-
async function readProcessTable() {
|
|
671
|
-
if (process.platform === "win32") throw new Error("no process table reader on win32");
|
|
672
|
-
const { stdout } = await execFileAsync("ps", [
|
|
673
|
-
"-A",
|
|
674
|
-
"-o",
|
|
675
|
-
"pid=,ppid=,etime="
|
|
676
|
-
], {
|
|
677
|
-
timeout: 5e3,
|
|
678
|
-
maxBuffer: 8 * 1024 * 1024
|
|
679
|
-
});
|
|
680
|
-
return parseProcessTable(stdout);
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Seconds from a POSIX `etime` field: `[[DD-]hh:]mm:ss`.
|
|
684
|
-
*
|
|
685
|
-
* Returns null for anything that does not match, so a `ps` variant printing an
|
|
686
|
-
* unexpected shape degrades to "cannot check" rather than to a wrong number —
|
|
687
|
-
* a bogus age would defeat the pid-reuse guard it exists to feed.
|
|
688
|
-
*/
|
|
689
|
-
function parseEtime(etime) {
|
|
690
|
-
const m = /^(?:(?:(\d+)-)?(\d+):)?(\d+):(\d+)$/.exec(etime.trim());
|
|
691
|
-
if (!m) return null;
|
|
692
|
-
const [, dd, hh, mm, ss] = m;
|
|
693
|
-
return Number(dd ?? 0) * 86400 + Number(hh ?? 0) * 3600 + Number(mm) * 60 + Number(ss);
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Parse `ps -A -o pid=,ppid=,etime=` output. Split out from the read so the
|
|
697
|
-
* parsing — the part that can actually be wrong — is testable without a `ps`.
|
|
698
|
-
*/
|
|
699
|
-
function parseProcessTable(stdout) {
|
|
700
|
-
const table = /* @__PURE__ */ new Map();
|
|
701
|
-
for (const line of stdout.split("\n")) {
|
|
702
|
-
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s*$/.exec(line);
|
|
703
|
-
if (!m) continue;
|
|
704
|
-
const ageSecs = parseEtime(m[3]);
|
|
705
|
-
if (ageSecs === null) continue;
|
|
706
|
-
table.set(Number(m[1]), {
|
|
707
|
-
ppid: Number(m[2]),
|
|
708
|
-
ageSecs
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
return table;
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Is the process now at `pid` plausibly the one that registered as this agent?
|
|
715
|
-
*
|
|
716
|
-
* pids are reused. When a registered agent exits and the OS hands its number to
|
|
717
|
-
* something else, matching on the number alone attributes the new process to
|
|
718
|
-
* the dead agent — and, worse, to anything that arranges to be its child. The
|
|
719
|
-
* registry records when the agent started, so compare: a process that began
|
|
720
|
-
* AFTER the registration cannot be the thing that was registered.
|
|
721
|
-
*
|
|
722
|
-
* `toleranceSecs` absorbs the ordinary gap between a process starting and its
|
|
723
|
-
* record being written, plus clock granularity. Unknown age ⇒ null ⇒ the caller
|
|
724
|
-
* declines to attribute, because an unverifiable identity is the case this
|
|
725
|
-
* whole change exists to stop papering over.
|
|
726
|
-
*/
|
|
727
|
-
function ageMatchesRegistration(ageSecs, startedAt, now = Date.now(), toleranceSecs = 60) {
|
|
728
|
-
if (ageSecs === void 0 || startedAt === void 0) return false;
|
|
729
|
-
return ageSecs >= (now - startedAt) / 1e3 - toleranceSecs;
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* The first ancestor of `pid` that `isAgent` recognizes, or null.
|
|
733
|
-
*
|
|
734
|
-
* Nearest-first: with nested agents, the closest enclosing lane is the one that
|
|
735
|
-
* actually made this call, so it is the honest attribution.
|
|
736
|
-
*/
|
|
737
|
-
async function findAgentAncestor(pid, isAgent, opts) {
|
|
738
|
-
for (const ancestor of await ancestorPids(pid, opts)) {
|
|
739
|
-
const hit = isAgent(ancestor);
|
|
740
|
-
if (hit) return hit;
|
|
741
|
-
}
|
|
742
|
-
return null;
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Whether the process holding a pid is still the agent that registered it.
|
|
746
|
-
*
|
|
747
|
-
* Three-way on purpose, and the third value is the point. "Cannot establish"
|
|
748
|
-
* is not "established that it is not ours": win32 has no process table reader
|
|
749
|
-
* here at all, so folding unknown into reused would not guard a destructive
|
|
750
|
-
* action on that platform — it would delete the action from it, permanently,
|
|
751
|
-
* to protect a case that has never occurred. Callers refuse on evidence
|
|
752
|
-
* ("reused") and keep their prior behaviour on "unknown".
|
|
753
|
-
*/
|
|
754
|
-
function pidOwnershipVerdict(ageSecs, startedAt, now = Date.now(), toleranceSecs = 60) {
|
|
755
|
-
if (ageSecs === void 0 || startedAt === void 0) return "unknown";
|
|
756
|
-
return ageMatchesRegistration(ageSecs, startedAt, now, toleranceSecs) ? "ours" : "reused";
|
|
757
|
-
}
|
|
758
|
-
async function readAncestryTable(read = readProcessTable) {
|
|
759
|
-
try {
|
|
760
|
-
return await read();
|
|
761
|
-
} catch {
|
|
762
|
-
return null;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
642
|
//#endregion
|
|
767
643
|
//#region ts/remoteCache.ts
|
|
768
644
|
/** Rows younger than this are served as-is without kicking a refresh. */
|
|
@@ -1199,6 +1075,16 @@ async function resolveWorkDir(r) {
|
|
|
1199
1075
|
* block over the first ghost character must not turn a suggestion into a draft.
|
|
1200
1076
|
*/
|
|
1201
1077
|
const PROMPT_RE = /^\s*[❯›]($|\s)/u;
|
|
1078
|
+
const ASCII_PROMPT_RE = /^\s*[❯›>]($|\s)/u;
|
|
1079
|
+
const ASCII_PROMPT_CLIS = new Set(["agy"]);
|
|
1080
|
+
/** A row with its leading prompt glyph (and the space after it) removed. */
|
|
1081
|
+
function stripPromptGlyph(line, cli) {
|
|
1082
|
+
return line.replace(cli && ASCII_PROMPT_CLIS.has(cli) ? /^\s*[❯›>]\s*/u : /^\s*[❯›]\s*/u, "");
|
|
1083
|
+
}
|
|
1084
|
+
/** The input-row matcher for a CLI (see ASCII_PROMPT_CLIS). */
|
|
1085
|
+
function promptRe(cli) {
|
|
1086
|
+
return cli && ASCII_PROMPT_CLIS.has(cli) ? ASCII_PROMPT_RE : PROMPT_RE;
|
|
1087
|
+
}
|
|
1202
1088
|
const SEPARATOR_RE = /^\s*[─━]{3,}/u;
|
|
1203
1089
|
const FOOTER_RE = /^\s*(?:·\s*)?(?:[←→] .*agents|\? for shortcuts|esc to interrupt|ctrl\+t to|GPT-[^·]*·|gpt-[^·]*·|⏵⏵|⏸|⏎ send|\d+% context left)/iu;
|
|
1204
1090
|
const FOOTER_SEGMENT_RE = /·\s*(?:[←→] .*agents?|↓ |esc to interrupt)|\(shift\+tab to /u;
|
|
@@ -1210,9 +1096,10 @@ const FOOTER_SEGMENT_RE = /·\s*(?:[←→] .*agents?|↓ |esc to interrupt)|\(s
|
|
|
1210
1096
|
* any box (Codex) it is the last prompt-looking row. Shared by the draft check
|
|
1211
1097
|
* and by submission confirmation, so both agree on where history ends.
|
|
1212
1098
|
*/
|
|
1213
|
-
function composerPromptRow(texts) {
|
|
1214
|
-
|
|
1215
|
-
|
|
1099
|
+
function composerPromptRow(texts, cli) {
|
|
1100
|
+
const re = promptRe(cli);
|
|
1101
|
+
for (let i = texts.length - 2; i >= 0; i--) if (SEPARATOR_RE.test(texts[i]) && re.test(texts[i + 1])) return i + 1;
|
|
1102
|
+
return texts.findLastIndex((t) => re.test(t));
|
|
1216
1103
|
}
|
|
1217
1104
|
/**
|
|
1218
1105
|
* Is Claude Code's composer box the bottom of the screen: a rule directly above a
|
|
@@ -1225,15 +1112,16 @@ function composerPromptRow(texts) {
|
|
|
1225
1112
|
* A real draft longer than MAX_DRAFT_ROWS fails too and reads "hidden", which
|
|
1226
1113
|
* parks the send just as a draft does.
|
|
1227
1114
|
*/
|
|
1228
|
-
function composerBoxed(texts) {
|
|
1229
|
-
const prompt = composerPromptRow(texts);
|
|
1230
|
-
if (prompt <
|
|
1115
|
+
function composerBoxed(texts, cli, needRule = true) {
|
|
1116
|
+
const prompt = composerPromptRow(texts, cli);
|
|
1117
|
+
if (prompt < 0) return false;
|
|
1118
|
+
if (needRule && (prompt < 1 || !SEPARATOR_RE.test(texts[prompt - 1]))) return false;
|
|
1231
1119
|
const nonBlank = (rows) => rows.filter((t) => t.trim());
|
|
1232
1120
|
const close = texts.findIndex((t, i) => i > prompt && isComposerChrome(t));
|
|
1233
1121
|
if (close < 0) return false;
|
|
1234
1122
|
const inside = nonBlank(texts.slice(prompt + 1, close));
|
|
1235
1123
|
const below = nonBlank(texts.slice(close + 1));
|
|
1236
|
-
return inside.length <= MAX_DRAFT_ROWS && below.length <= MAX_ROWS_BELOW_BOX && ![...inside, ...below].some((t) =>
|
|
1124
|
+
return inside.length <= MAX_DRAFT_ROWS && below.length <= MAX_ROWS_BELOW_BOX && ![...inside, ...below].some((t) => promptRe(cli).test(t));
|
|
1237
1125
|
}
|
|
1238
1126
|
/** Draft rows under the prompt row, before the box is read as stale (see above). */
|
|
1239
1127
|
const MAX_DRAFT_ROWS = 8;
|
|
@@ -1267,8 +1155,8 @@ function isComposerChrome(text, cells) {
|
|
|
1267
1155
|
* draft is not. A draft whose own line starts with a prompt glyph can still be
|
|
1268
1156
|
* misread there.
|
|
1269
1157
|
*/
|
|
1270
|
-
function classifyComposer(rows) {
|
|
1271
|
-
const prompt = composerPromptRow(rows.map((r) => r.text));
|
|
1158
|
+
function classifyComposer(rows, cli) {
|
|
1159
|
+
const prompt = composerPromptRow(rows.map((r) => r.text), cli);
|
|
1272
1160
|
if (prompt < 0) return {
|
|
1273
1161
|
kind: "unknown",
|
|
1274
1162
|
reason: "no prompt row on screen"
|
|
@@ -1283,7 +1171,8 @@ function classifyComposer(rows) {
|
|
|
1283
1171
|
}
|
|
1284
1172
|
let cells = row.cells;
|
|
1285
1173
|
if (i === prompt) {
|
|
1286
|
-
|
|
1174
|
+
let glyph = cells.findIndex((c) => c.ch.trim() !== "");
|
|
1175
|
+
if (glyph >= 0 && !promptRe(cli).test(cells[glyph].ch)) glyph = -1;
|
|
1287
1176
|
cells = glyph >= 0 ? cells.slice(glyph + 1) : cells;
|
|
1288
1177
|
}
|
|
1289
1178
|
for (const c of cells) {
|
|
@@ -1301,11 +1190,18 @@ function classifyComposer(rows) {
|
|
|
1301
1190
|
ghost
|
|
1302
1191
|
};
|
|
1303
1192
|
}
|
|
1304
|
-
/**
|
|
1305
|
-
|
|
1193
|
+
/**
|
|
1194
|
+
* Read the bottom `n` rows of an xterm buffer as ComposerRows. With
|
|
1195
|
+
* `fromContent`, count them up from the last non-blank row (as `ay tail`
|
|
1196
|
+
* does), so a screen that has not filled the viewport yet keeps its top rows.
|
|
1197
|
+
*/
|
|
1198
|
+
function rowsFromXterm(term, n, fromContent = false) {
|
|
1306
1199
|
const active = term.buffer.active;
|
|
1200
|
+
const blank = (i) => !active.getLine(i)?.translateToString(true).trim();
|
|
1201
|
+
let end = active.length;
|
|
1202
|
+
if (fromContent) while (end > 0 && blank(end - 1)) end--;
|
|
1307
1203
|
const rows = [];
|
|
1308
|
-
for (let i = Math.max(0,
|
|
1204
|
+
for (let i = Math.max(0, end - n); i < end; i++) {
|
|
1309
1205
|
const line = active.getLine(i);
|
|
1310
1206
|
if (!line) {
|
|
1311
1207
|
rows.push({
|
|
@@ -1636,7 +1532,7 @@ function gitCommonDir(dir) {
|
|
|
1636
1532
|
if (hit !== void 0) return hit;
|
|
1637
1533
|
let out = null;
|
|
1638
1534
|
try {
|
|
1639
|
-
out = execFileSync
|
|
1535
|
+
out = execFileSync("git", [
|
|
1640
1536
|
"-C",
|
|
1641
1537
|
dir,
|
|
1642
1538
|
"rev-parse",
|
|
@@ -1915,9 +1811,13 @@ const SUBCOMMANDS = new Set([
|
|
|
1915
1811
|
const MANAGER_SUBCOMMANDS = new Set([
|
|
1916
1812
|
"setup",
|
|
1917
1813
|
"ws",
|
|
1814
|
+
"schedules",
|
|
1815
|
+
"sched",
|
|
1816
|
+
"cron",
|
|
1918
1817
|
"read",
|
|
1919
1818
|
"share",
|
|
1920
|
-
"connect"
|
|
1819
|
+
"connect",
|
|
1820
|
+
"kill"
|
|
1921
1821
|
]);
|
|
1922
1822
|
const IDLE_THRESHOLD_MS = 60 * 1e3;
|
|
1923
1823
|
const STUCK_THRESHOLD_MS = (() => {
|
|
@@ -2145,7 +2045,7 @@ async function runSubcommand(argv) {
|
|
|
2145
2045
|
switch (sub) {
|
|
2146
2046
|
case "ls":
|
|
2147
2047
|
case "list": return await cmdLs(rest);
|
|
2148
|
-
case "ps": return await (await import("./cmdPs-
|
|
2048
|
+
case "ps": return await (await import("./cmdPs-DBt23Qz0.js")).cmdPs(rest);
|
|
2149
2049
|
case "status": return await cmdStatus(rest);
|
|
2150
2050
|
case "whoami": return await cmdWhoami(rest);
|
|
2151
2051
|
case "result": return await cmdResult(rest);
|
|
@@ -2156,7 +2056,7 @@ async function runSubcommand(argv) {
|
|
|
2156
2056
|
case "tail": return await cmdRead(rest, { mode: "tail" });
|
|
2157
2057
|
case "head": return await cmdRead(rest, { mode: "head" });
|
|
2158
2058
|
case "hist":
|
|
2159
|
-
case "history": return await (await import("./hist-
|
|
2059
|
+
case "history": return await (await import("./hist-DY16wm7g.js")).cmdHist(rest);
|
|
2160
2060
|
case "send": return await cmdSend(rest);
|
|
2161
2061
|
case "send-drain": return await cmdSendDrain(rest);
|
|
2162
2062
|
case "ls-refresh": return await cmdLsRefresh(rest);
|
|
@@ -2168,10 +2068,11 @@ async function runSubcommand(argv) {
|
|
|
2168
2068
|
case "stop": return await cmdStop(rest);
|
|
2169
2069
|
case "exit": return await cmdExit(rest);
|
|
2170
2070
|
case "restart": return await cmdRestart(rest);
|
|
2071
|
+
case "kill": return await (await import("./cmdKill-CzSBfWmx.js")).cmdKill(rest);
|
|
2171
2072
|
case "note": return await cmdNote(rest);
|
|
2172
2073
|
case "ask":
|
|
2173
2074
|
case "answer": {
|
|
2174
|
-
const { runAskSubcommand, runAnswerSubcommand } = await import("./askCli-
|
|
2075
|
+
const { runAskSubcommand, runAnswerSubcommand } = await import("./askCli-KmMf-3wA.js");
|
|
2175
2076
|
const deps = {
|
|
2176
2077
|
resolveAgent: (keyword) => resolveOne(keyword, {
|
|
2177
2078
|
all: true,
|
|
@@ -2185,76 +2086,85 @@ async function runSubcommand(argv) {
|
|
|
2185
2086
|
return sub === "ask" ? await runAskSubcommand(rest, deps) : await runAnswerSubcommand(rest, deps);
|
|
2186
2087
|
}
|
|
2187
2088
|
case "todo": {
|
|
2188
|
-
const { runTodoSubcommand } = await import("./todoCli-
|
|
2089
|
+
const { runTodoSubcommand } = await import("./todoCli-CU9vSJSJ.js");
|
|
2189
2090
|
return runTodoSubcommand(rest);
|
|
2190
2091
|
}
|
|
2191
2092
|
case "ch":
|
|
2192
2093
|
case "channels": {
|
|
2193
|
-
const { cmdCh } = await import("./channels-
|
|
2094
|
+
const { cmdCh } = await import("./channels-Y36S0ccW.js");
|
|
2194
2095
|
return cmdCh(rest);
|
|
2195
2096
|
}
|
|
2196
2097
|
case "term": {
|
|
2197
|
-
const { cmdTerm } = await import("./terminal-
|
|
2098
|
+
const { cmdTerm } = await import("./terminal-13cGj3h6.js");
|
|
2198
2099
|
return cmdTerm(rest);
|
|
2199
2100
|
}
|
|
2200
2101
|
case "widget": {
|
|
2201
|
-
const { cmdWidget } = await import("./widget-
|
|
2102
|
+
const { cmdWidget } = await import("./widget-DmRwOlco.js");
|
|
2202
2103
|
return cmdWidget(rest);
|
|
2203
2104
|
}
|
|
2204
2105
|
case "mint": {
|
|
2205
|
-
const { cmdMint } = await import("./widget-
|
|
2106
|
+
const { cmdMint } = await import("./widget-DmRwOlco.js");
|
|
2206
2107
|
return cmdMint(rest);
|
|
2207
2108
|
}
|
|
2208
2109
|
case "serve": {
|
|
2209
|
-
const { cmdServe } = await import("./serve-
|
|
2110
|
+
const { cmdServe } = await import("./serve-XwFYE0cE.js");
|
|
2210
2111
|
return cmdServe(rest);
|
|
2211
2112
|
}
|
|
2212
2113
|
case "tray": {
|
|
2213
|
-
const { cmdTray } = await import("./trayApp-
|
|
2114
|
+
const { cmdTray } = await import("./trayApp-DkAPo0m6.js");
|
|
2214
2115
|
return cmdTray(rest);
|
|
2215
2116
|
}
|
|
2216
2117
|
case "setup": {
|
|
2217
|
-
const { cmdSetup } = await import("./setup-
|
|
2118
|
+
const { cmdSetup } = await import("./setup-D4-s2VZw.js");
|
|
2218
2119
|
return cmdSetup(rest);
|
|
2219
2120
|
}
|
|
2220
2121
|
case "ws": {
|
|
2221
|
-
const { cmdWs } = await import("./ws-
|
|
2122
|
+
const { cmdWs } = await import("./ws-D0-Jg88z.js");
|
|
2222
2123
|
return cmdWs(rest);
|
|
2223
2124
|
}
|
|
2125
|
+
case "schedules":
|
|
2126
|
+
case "sched": {
|
|
2127
|
+
const { cmdSchedules } = await import("./schedulesCli-CLqieyQZ.js");
|
|
2128
|
+
return cmdSchedules(rest);
|
|
2129
|
+
}
|
|
2130
|
+
case "cron": {
|
|
2131
|
+
const { cmdCron } = await import("./schedulesCli-CLqieyQZ.js");
|
|
2132
|
+
return cmdCron(rest);
|
|
2133
|
+
}
|
|
2224
2134
|
case "schedule": {
|
|
2225
|
-
const { cmdSchedule } = await import("./schedule-
|
|
2135
|
+
const { cmdSchedule } = await import("./schedule-Bzjhl6-h.js");
|
|
2226
2136
|
return cmdSchedule(rest);
|
|
2227
2137
|
}
|
|
2228
2138
|
case "remote": {
|
|
2229
|
-
const { cmdRemote } = await import("./remotes-
|
|
2139
|
+
const { cmdRemote } = await import("./remotes-BqLoB5GR.js");
|
|
2230
2140
|
return cmdRemote(rest);
|
|
2231
2141
|
}
|
|
2232
2142
|
case "share": {
|
|
2233
|
-
const { cmdShare } = await import("./shareCmd-
|
|
2143
|
+
const { cmdShare } = await import("./shareCmd-DUBsVI3e.js");
|
|
2234
2144
|
return cmdShare(rest);
|
|
2235
2145
|
}
|
|
2236
2146
|
case "connect": {
|
|
2237
|
-
const { cmdConnect } = await import("./remotes-
|
|
2147
|
+
const { cmdConnect } = await import("./remotes-BqLoB5GR.js");
|
|
2238
2148
|
return cmdConnect(rest);
|
|
2239
2149
|
}
|
|
2240
2150
|
case "expose": {
|
|
2241
|
-
const { cmdExpose } = await import("./expose-
|
|
2151
|
+
const { cmdExpose } = await import("./expose-Bhsn5yUz.js");
|
|
2242
2152
|
return cmdExpose(rest);
|
|
2243
2153
|
}
|
|
2244
2154
|
case "callback": {
|
|
2245
|
-
const { cmdCallback } = await import("./callback-
|
|
2155
|
+
const { cmdCallback } = await import("./callback-SqLD2mMX.js");
|
|
2246
2156
|
return cmdCallback(rest);
|
|
2247
2157
|
}
|
|
2248
2158
|
case "reap":
|
|
2249
2159
|
await (await import("./reaper-DsZhX5FH.js")).sweep();
|
|
2250
2160
|
return 0;
|
|
2251
2161
|
case "dsh-legacy": {
|
|
2252
|
-
const { cmdDsh } = await import("./cmdDsh-
|
|
2162
|
+
const { cmdDsh } = await import("./cmdDsh-DZ8bLsH7.js");
|
|
2253
2163
|
return await cmdDsh(rest);
|
|
2254
2164
|
}
|
|
2255
2165
|
case "gc": {
|
|
2256
|
-
const { gcOldBinaryDirs } = await import("./rustBinary-
|
|
2257
|
-
const { gcLogs } = await import("./globalPidIndex-
|
|
2166
|
+
const { gcOldBinaryDirs } = await import("./rustBinary-vpfpWj1q.js");
|
|
2167
|
+
const { gcLogs } = await import("./globalPidIndex-uoz8Esqz.js");
|
|
2258
2168
|
const bins = gcOldBinaryDirs();
|
|
2259
2169
|
const logs = await gcLogs();
|
|
2260
2170
|
if (bins.removed.length === 0) process.stdout.write("no old agent-yes binary cache dirs to remove\n");
|
|
@@ -2300,7 +2210,11 @@ async function buildAgentContextSection(self) {
|
|
|
2300
2210
|
const dutyLine = parent ? ` You owe it a report: \`ay send ${parent.agent_id || parent.pid} "..."\` when you finish, and\n when you are blocked. It is not watching your terminal.\n` : ``;
|
|
2301
2211
|
return `You are running inside an agent:\n ${whoAmI}\n ${parentLine}\n` + dutyLine + `
|
|
2302
2212
|
As an agent, you can:
|
|
2303
|
-
|
|
2213
|
+
Parallel work: in the SAME cwd use your harness's own subagents (e.g. the Agent
|
|
2214
|
+
tool), NOT a second \`ay\` there (two top-level agents in one checkout is strongly
|
|
2215
|
+
not recommended). For another branch, spawn \`ay\` in a SEPARATE cwd (git worktree)
|
|
2216
|
+
and harvest it by git (merge/PR).
|
|
2217
|
+
Spawn a sub-agent (in its own cwd):
|
|
2304
2218
|
ay <cli> -- "<prompt>" auto-links as your child
|
|
2305
2219
|
ay claude --model sonnet --advisor opus -- "<prompt>" routine task
|
|
2306
2220
|
ay claude --model opus --advisor fable -- "<prompt>" complex task
|
|
@@ -2311,12 +2225,13 @@ As an agent, you can:
|
|
|
2311
2225
|
}
|
|
2312
2226
|
async function cmdHelp(managerCommands = true) {
|
|
2313
2227
|
const setupLine = managerCommands ? ` ay setup guided setup: pick a workspace, share to agent-yes.com\n` : ``;
|
|
2314
|
-
const wsLines = managerCommands ? " ay ws ls [--status] list <owner>/<repo>/tree/<branch> workspaces\n ay ws new <owner>/<repo>[@branch] clone/refresh a workspace (ay ws help for more)\n" : ``;
|
|
2228
|
+
const wsLines = managerCommands ? " ay ws ls [--status] list <owner>/<repo>/tree/<branch> workspaces\n ay ws new <owner>/<repo>[@branch] clone/refresh a workspace (ay ws help for more)\n ay cron \"<cron>\" <target> <msg> recurring reminder sent to an agent (ay cron help)\n ay schedules ls|daemon all schedules on this machine + the scheduler daemon\n" : ``;
|
|
2315
2229
|
const readAliasNote = managerCommands ? `` : ` (\`ay read\` only — \`cy read …\` is a prompt)\n`;
|
|
2316
2230
|
const shareAliasNote = managerCommands ? `` : ` (\`ay\` only — \`cy share\`/\`cy connect\` are prompts)\n`;
|
|
2231
|
+
const killAliasNote = managerCommands ? `` : ` (\`ay kill\` only — \`cy kill …\` is a prompt)\n`;
|
|
2317
2232
|
const self = process.env.AGENT_YES_PID ? await resolveSender() : null;
|
|
2318
2233
|
const agentSection = self ? await buildAgentContextSection(self) : "";
|
|
2319
|
-
process.stdout.write(agentSection + "ay - agent-yes CLI\n\nManagement:\n ay ls [keyword] list running agents (remotes from cache, refreshed\n [--waitFor=all|local|<alias>] in the background; --waitFor blocks for fresh rows)\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");
|
|
2234
|
+
process.stdout.write(agentSection + "ay - agent-yes CLI\n\nManagement:\n ay ls [keyword] list running agents (remotes from cache, refreshed\n [--waitFor=all|local|<alias>] in the background; --waitFor blocks for fresh rows)\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 kill <pid> [--dry-run] SIGKILL an agent + its process group, like the console's\n Kill (exact pid from ay ls; never the calling shell)\n" + killAliasNote + " 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 ay --detach claude -- \"…\" start it in the background and return at once\n (e.g. over ssh); prints its pid + how to drive it\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");
|
|
2320
2235
|
return 0;
|
|
2321
2236
|
}
|
|
2322
2237
|
/** Looks like an agent_id (12 hex, or a longer injected one) rather than a word. */
|
|
@@ -2458,6 +2373,36 @@ async function pickInteractive(matches) {
|
|
|
2458
2373
|
tty.on("data", onData);
|
|
2459
2374
|
});
|
|
2460
2375
|
}
|
|
2376
|
+
/** Edit distance (Levenshtein), small strings only. */
|
|
2377
|
+
function editDistance(a, b) {
|
|
2378
|
+
const d = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
2379
|
+
for (let i = 1; i <= a.length; i++) {
|
|
2380
|
+
let prev = d[0];
|
|
2381
|
+
d[0] = i;
|
|
2382
|
+
for (let j = 1; j <= b.length; j++) {
|
|
2383
|
+
const tmp = d[j];
|
|
2384
|
+
d[j] = Math.min(d[j] + 1, d[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
2385
|
+
prev = tmp;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
return d[b.length];
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* The live agents closest to a keyword that matched nothing, best first (at
|
|
2392
|
+
* most `max`): each agent is scored by its cwd path segments and title words,
|
|
2393
|
+
* so a typo ("lumne" for "lumen") or a stale name still points at the right lane.
|
|
2394
|
+
*/
|
|
2395
|
+
function suggestAgents(records, keyword, max = 3) {
|
|
2396
|
+
const kw = keyword.toLowerCase();
|
|
2397
|
+
if (!kw || /^\d+$/.test(kw)) return [];
|
|
2398
|
+
return records.filter((r) => r.status !== "exited").map((r) => {
|
|
2399
|
+
const tokens = `${r.cwd ?? ""} ${r.title ?? ""}`.toLowerCase().split(/[\s/\\._:@[\]-]+/).filter((t) => t.length >= 2);
|
|
2400
|
+
return {
|
|
2401
|
+
r,
|
|
2402
|
+
best: Math.min(Infinity, ...tokens.map((t) => t.includes(kw) ? 0 : editDistance(kw, t) / Math.max(kw.length, t.length)))
|
|
2403
|
+
};
|
|
2404
|
+
}).filter((x) => x.best < .5).sort((a, b) => a.best - b.best || b.r.started_at - a.r.started_at).slice(0, max).map((x) => x.r);
|
|
2405
|
+
}
|
|
2461
2406
|
async function resolveOne(keyword, opts) {
|
|
2462
2407
|
if (!keyword) throw new Error("keyword required (pid, cwd substring, cli name, or prompt substring)");
|
|
2463
2408
|
const matches = await listRecords(keyword, opts);
|
|
@@ -2469,7 +2414,8 @@ async function resolveOne(keyword, opts) {
|
|
|
2469
2414
|
});
|
|
2470
2415
|
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.`);
|
|
2471
2416
|
}
|
|
2472
|
-
|
|
2417
|
+
const near = suggestAgents(await listRecords(void 0, opts), keyword);
|
|
2418
|
+
throw new Error(`no agent matched "${keyword}"` + (near.length ? ` — closest live agents:\n` + near.map((r) => ` ${r.pid} ${r.agent_id ?? ""} ${shortenPath(r.cwd)}`).join("\n") : ""));
|
|
2473
2419
|
}
|
|
2474
2420
|
if (/^\d+$/.test(keyword)) {
|
|
2475
2421
|
const byPid = matches.filter((r) => r.pid === Number(keyword));
|
|
@@ -2862,7 +2808,7 @@ async function fetchRemoteRecordsRaw(url, token, opts, onReachable) {
|
|
|
2862
2808
|
let base = url;
|
|
2863
2809
|
let bearer = token;
|
|
2864
2810
|
if (isWebrtcSpec(url)) {
|
|
2865
|
-
const { startWebrtcBridge } = await import("./webrtcRemote-
|
|
2811
|
+
const { startWebrtcBridge } = await import("./webrtcRemote-C3xQyf3u.js");
|
|
2866
2812
|
bridge = await startWebrtcBridge(url);
|
|
2867
2813
|
base = bridge.baseUrl;
|
|
2868
2814
|
bearer = bridge.token;
|
|
@@ -2908,7 +2854,7 @@ function spawnDetachedAy(args) {
|
|
|
2908
2854
|
if (!launcher) return null;
|
|
2909
2855
|
const [cmd, ...pre] = launcher;
|
|
2910
2856
|
try {
|
|
2911
|
-
const child = spawn
|
|
2857
|
+
const child = spawn(cmd, [...pre, ...args], {
|
|
2912
2858
|
detached: true,
|
|
2913
2859
|
stdio: "ignore"
|
|
2914
2860
|
});
|
|
@@ -3507,6 +3453,7 @@ async function cmdLs(rest) {
|
|
|
3507
3453
|
process.stdout.write(await y.getHelp() + "\n");
|
|
3508
3454
|
return 0;
|
|
3509
3455
|
}
|
|
3456
|
+
if (!argv.watch) enableRenderDiskCache();
|
|
3510
3457
|
const keyword = argv._[0] !== void 0 ? String(argv._[0]) : void 0;
|
|
3511
3458
|
if (keyword) {
|
|
3512
3459
|
const remote = await resolveRemoteSpec(keyword);
|
|
@@ -4454,35 +4401,8 @@ function resolveReadWindow(opts) {
|
|
|
4454
4401
|
* Reads only the last 32 KB for speed, renders via xterm for clean output.
|
|
4455
4402
|
*/
|
|
4456
4403
|
async function extractActivity(logPath) {
|
|
4457
|
-
const
|
|
4458
|
-
|
|
4459
|
-
try {
|
|
4460
|
-
const fh = await open(logPath, "r");
|
|
4461
|
-
try {
|
|
4462
|
-
const { size } = await fh.stat();
|
|
4463
|
-
if (size === 0) return null;
|
|
4464
|
-
if (size <= TAIL_BYTES) {
|
|
4465
|
-
const data = await fh.readFile();
|
|
4466
|
-
buf = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
4467
|
-
} else {
|
|
4468
|
-
const tmp = Buffer.alloc(TAIL_BYTES);
|
|
4469
|
-
const { bytesRead } = await fh.read(tmp, 0, TAIL_BYTES, size - TAIL_BYTES);
|
|
4470
|
-
buf = new Uint8Array(tmp.buffer, 0, bytesRead);
|
|
4471
|
-
}
|
|
4472
|
-
} finally {
|
|
4473
|
-
await fh.close();
|
|
4474
|
-
}
|
|
4475
|
-
} catch {
|
|
4476
|
-
return null;
|
|
4477
|
-
}
|
|
4478
|
-
try {
|
|
4479
|
-
return extractActivityFromLines((await renderRawLog(buf, {
|
|
4480
|
-
mode: "tail",
|
|
4481
|
-
n: 40
|
|
4482
|
-
})).split("\n"));
|
|
4483
|
-
} catch {
|
|
4484
|
-
return null;
|
|
4485
|
-
}
|
|
4404
|
+
const lines = await renderLogTailLines(logPath, 40);
|
|
4405
|
+
return lines ? extractActivityFromLines(lines) : null;
|
|
4486
4406
|
}
|
|
4487
4407
|
/**
|
|
4488
4408
|
* Extract the agent's current task progress ({done,total}) from its rendered TUI
|
|
@@ -4495,11 +4415,19 @@ async function extractActivity(logPath) {
|
|
|
4495
4415
|
async function extractTaskCounts(logPath) {
|
|
4496
4416
|
const TAIL_BYTES = 256 * 1024;
|
|
4497
4417
|
let buf;
|
|
4418
|
+
let key;
|
|
4498
4419
|
try {
|
|
4499
4420
|
const fh = await open(logPath, "r");
|
|
4500
4421
|
try {
|
|
4501
|
-
const
|
|
4422
|
+
const st = await fh.stat();
|
|
4423
|
+
const { size } = st;
|
|
4502
4424
|
if (size === 0) return null;
|
|
4425
|
+
key = `tasks\0${logPath}\0${size}\0${st.mtimeMs}`;
|
|
4426
|
+
const kept = renderDiskGet(key);
|
|
4427
|
+
if (kept !== void 0 && (kept === "none" || isTaskCounts(kept))) {
|
|
4428
|
+
renderDiskPut(key, kept);
|
|
4429
|
+
return kept === "none" ? null : kept;
|
|
4430
|
+
}
|
|
4503
4431
|
if (size <= TAIL_BYTES) {
|
|
4504
4432
|
const data = await fh.readFile();
|
|
4505
4433
|
buf = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
@@ -4514,15 +4442,25 @@ async function extractTaskCounts(logPath) {
|
|
|
4514
4442
|
} catch {
|
|
4515
4443
|
return null;
|
|
4516
4444
|
}
|
|
4445
|
+
if (!mayHoldTaskBlock(new TextDecoder().decode(buf))) {
|
|
4446
|
+
renderDiskPut(key, "none");
|
|
4447
|
+
return null;
|
|
4448
|
+
}
|
|
4517
4449
|
try {
|
|
4518
|
-
|
|
4450
|
+
const counts = parseTaskCounts((await renderRawLog(buf, {
|
|
4519
4451
|
mode: "cat",
|
|
4520
4452
|
n: 0
|
|
4521
4453
|
})).split("\n"));
|
|
4454
|
+
renderDiskPut(key, counts ?? "none");
|
|
4455
|
+
return counts;
|
|
4522
4456
|
} catch {
|
|
4523
4457
|
return null;
|
|
4524
4458
|
}
|
|
4525
4459
|
}
|
|
4460
|
+
function isTaskCounts(v) {
|
|
4461
|
+
const c = v;
|
|
4462
|
+
return !!c && typeof c === "object" && Number.isInteger(c.done) && Number.isInteger(c.total);
|
|
4463
|
+
}
|
|
4526
4464
|
let _cliDefaults = null;
|
|
4527
4465
|
function cliDefaults() {
|
|
4528
4466
|
return _cliDefaults ??= loadSharedCliDefaults().catch((err) => {
|
|
@@ -4542,6 +4480,74 @@ function cliDefaults() {
|
|
|
4542
4480
|
* stuck classifiers so they don't each re-implement the tail read.
|
|
4543
4481
|
*/
|
|
4544
4482
|
async function renderLogTailLines(logPath, n = 40, geom) {
|
|
4483
|
+
let key;
|
|
4484
|
+
try {
|
|
4485
|
+
const s = await stat(logPath);
|
|
4486
|
+
key = `${logPath}\0${s.size}\0${s.mtimeMs}\0${n}\0${geom?.cols ?? ""}x${geom?.rows ?? ""}`;
|
|
4487
|
+
} catch {
|
|
4488
|
+
return null;
|
|
4489
|
+
}
|
|
4490
|
+
const kept = renderDiskGet(key);
|
|
4491
|
+
if (Array.isArray(kept) && kept.every((l) => typeof l === "string")) {
|
|
4492
|
+
renderDiskPut(key, kept);
|
|
4493
|
+
return kept.slice();
|
|
4494
|
+
}
|
|
4495
|
+
let hit = tailRenderCache.get(key);
|
|
4496
|
+
if (!hit) {
|
|
4497
|
+
const p = renderLogTailLinesUncached(logPath, n, geom);
|
|
4498
|
+
hit = p;
|
|
4499
|
+
if (tailRenderCache.size >= TAIL_RENDER_CACHE_MAX) tailRenderCache.delete(tailRenderCache.keys().next().value);
|
|
4500
|
+
tailRenderCache.set(key, p);
|
|
4501
|
+
p.then((r) => {
|
|
4502
|
+
if (r === null && tailRenderCache.get(key) === p) tailRenderCache.delete(key);
|
|
4503
|
+
});
|
|
4504
|
+
}
|
|
4505
|
+
const lines = await hit;
|
|
4506
|
+
if (lines) renderDiskPut(key, lines);
|
|
4507
|
+
return lines ? lines.slice() : null;
|
|
4508
|
+
}
|
|
4509
|
+
const tailRenderCache = /* @__PURE__ */ new Map();
|
|
4510
|
+
const TAIL_RENDER_CACHE_MAX = 256;
|
|
4511
|
+
let renderDiskEnabled = false;
|
|
4512
|
+
let renderDiskPath = "";
|
|
4513
|
+
let renderDisk = null;
|
|
4514
|
+
const renderDiskUsed = /* @__PURE__ */ new Map();
|
|
4515
|
+
const RENDER_DISK_MAX = 1024;
|
|
4516
|
+
function enableRenderDiskCache() {
|
|
4517
|
+
renderDiskEnabled = true;
|
|
4518
|
+
renderDiskPath = path.join(agentYesHome(), "cache", "ls-render.json");
|
|
4519
|
+
}
|
|
4520
|
+
function renderDiskGet(key) {
|
|
4521
|
+
if (!renderDiskEnabled) return void 0;
|
|
4522
|
+
if (renderDisk === null) try {
|
|
4523
|
+
const v = JSON.parse(readFileSync(renderDiskPath, "utf8"));
|
|
4524
|
+
renderDisk = v && typeof v === "object" ? v : {};
|
|
4525
|
+
} catch {
|
|
4526
|
+
renderDisk = {};
|
|
4527
|
+
}
|
|
4528
|
+
return Object.prototype.hasOwnProperty.call(renderDisk, key) ? renderDisk[key] : void 0;
|
|
4529
|
+
}
|
|
4530
|
+
function renderDiskPut(key, value) {
|
|
4531
|
+
if (!renderDiskEnabled) return;
|
|
4532
|
+
if (renderDiskUsed.size >= RENDER_DISK_MAX && !renderDiskUsed.has(key)) return;
|
|
4533
|
+
if (renderDiskUsed.size === 0) process.once("exit", saveRenderDisk);
|
|
4534
|
+
renderDiskUsed.set(key, value);
|
|
4535
|
+
}
|
|
4536
|
+
/** Write the entries this run used (runs at exit; exported for tests). */
|
|
4537
|
+
function saveRenderDisk() {
|
|
4538
|
+
if (!renderDiskPath) return;
|
|
4539
|
+
try {
|
|
4540
|
+
const file = renderDiskPath;
|
|
4541
|
+
mkdirSync(path.dirname(file), {
|
|
4542
|
+
recursive: true,
|
|
4543
|
+
mode: 448
|
|
4544
|
+
});
|
|
4545
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
4546
|
+
writeFileSync(tmp, JSON.stringify(Object.fromEntries(renderDiskUsed)), { mode: 384 });
|
|
4547
|
+
renameSync(tmp, file);
|
|
4548
|
+
} catch {}
|
|
4549
|
+
}
|
|
4550
|
+
async function renderLogTailLinesUncached(logPath, n, geom) {
|
|
4545
4551
|
const buf = await readLogTailBytes(logPath);
|
|
4546
4552
|
if (!buf) return null;
|
|
4547
4553
|
try {
|
|
@@ -4585,26 +4591,19 @@ function dropComposerTerm(logPath) {
|
|
|
4585
4591
|
composerTerms.delete(logPath);
|
|
4586
4592
|
}
|
|
4587
4593
|
/**
|
|
4588
|
-
*
|
|
4589
|
-
*
|
|
4590
|
-
*
|
|
4591
|
-
*
|
|
4594
|
+
* The bottom 40 rows of a log as the composer check sees them: rendered from
|
|
4595
|
+
* the 32 KB tail and, for Claude, from further back until its composer box is
|
|
4596
|
+
* on screen (see COMPOSER_WINDOWS). Keeps per-cell attributes. Null for an
|
|
4597
|
+
* empty log; throws when the log cannot be read or rendered.
|
|
4592
4598
|
*/
|
|
4593
|
-
async function
|
|
4599
|
+
async function renderComposerRows(record, windows = COMPOSER_WINDOWS, fromContent = false) {
|
|
4594
4600
|
const logPath = record.log_file;
|
|
4595
|
-
if (!logPath) return {
|
|
4596
|
-
kind: "unknown",
|
|
4597
|
-
reason: "no log file recorded"
|
|
4598
|
-
};
|
|
4599
4601
|
const geom = await readAgentPtysize(record) ?? void 0;
|
|
4600
4602
|
const key = `${geom?.cols}x${geom?.rows}:${record.cli}:${windows.join()}`;
|
|
4601
4603
|
const claude = record.cli === "claude";
|
|
4602
4604
|
try {
|
|
4603
4605
|
const { size } = await stat(logPath);
|
|
4604
|
-
if (size === 0) return
|
|
4605
|
-
kind: "unknown",
|
|
4606
|
-
reason: "log unreadable or empty"
|
|
4607
|
-
};
|
|
4606
|
+
if (size === 0) return null;
|
|
4608
4607
|
let ct = composerTerms.get(logPath);
|
|
4609
4608
|
if (ct && (ct.key !== key || size < ct.offset)) {
|
|
4610
4609
|
dropComposerTerm(logPath);
|
|
@@ -4618,9 +4617,9 @@ async function readComposerState(record, windows = COMPOSER_WINDOWS) {
|
|
|
4618
4617
|
await new Promise((resolve) => ct.term.write(delta, resolve));
|
|
4619
4618
|
ct.offset += delta.length;
|
|
4620
4619
|
}
|
|
4621
|
-
rows = rowsFromXterm(ct.term, 40);
|
|
4620
|
+
rows = rowsFromXterm(ct.term, 40, fromContent);
|
|
4622
4621
|
next = ct.whole ? windows.length : ct.window + 1;
|
|
4623
|
-
if (
|
|
4622
|
+
if (composerBoxed(rows.map((r) => r.text), record.cli, claude)) next = windows.length;
|
|
4624
4623
|
}
|
|
4625
4624
|
for (let w = next; w < windows.length; w++) {
|
|
4626
4625
|
const from = Math.max(0, size - windows[w]);
|
|
@@ -4641,23 +4640,93 @@ async function readComposerState(record, windows = COMPOSER_WINDOWS) {
|
|
|
4641
4640
|
whole: from === 0
|
|
4642
4641
|
});
|
|
4643
4642
|
if (composerTerms.size > COMPOSER_TERMS_MAX) dropComposerTerm(composerTerms.keys().next().value);
|
|
4644
|
-
rows = rowsFromXterm(term, 40);
|
|
4645
|
-
if (
|
|
4643
|
+
rows = rowsFromXterm(term, 40, fromContent);
|
|
4644
|
+
if (from === 0 || composerBoxed(rows.map((r) => r.text), record.cli, claude)) break;
|
|
4646
4645
|
}
|
|
4647
|
-
|
|
4648
|
-
|
|
4646
|
+
return rows ?? [];
|
|
4647
|
+
} catch (e) {
|
|
4648
|
+
dropComposerTerm(logPath);
|
|
4649
|
+
throw e;
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
/**
|
|
4653
|
+
* What the target's composer holds right now, read from the same 32 KB tail
|
|
4654
|
+
* `renderLogTailLines` renders (further back when a Claude screen shows no
|
|
4655
|
+
* composer box), keeping per-cell attributes (dim/inverse) so ghost text can be
|
|
4656
|
+
* told from a real draft. See ts/composerGuard.ts.
|
|
4657
|
+
*/
|
|
4658
|
+
async function readComposerState(record, windows = COMPOSER_WINDOWS) {
|
|
4659
|
+
const logPath = record.log_file;
|
|
4660
|
+
if (!logPath) return {
|
|
4661
|
+
kind: "unknown",
|
|
4662
|
+
reason: "no log file recorded"
|
|
4663
|
+
};
|
|
4664
|
+
const claude = record.cli === "claude";
|
|
4665
|
+
try {
|
|
4666
|
+
const rows = await renderComposerRows({
|
|
4667
|
+
...record,
|
|
4668
|
+
log_file: logPath
|
|
4669
|
+
}, windows);
|
|
4670
|
+
if (!rows) return {
|
|
4671
|
+
kind: "unknown",
|
|
4672
|
+
reason: "log unreadable or empty"
|
|
4673
|
+
};
|
|
4674
|
+
const state = classifyComposer(rows, record.cli);
|
|
4675
|
+
if (state.kind === "draft" && !composerBoxed(rows.map((r) => r.text), record.cli, claude)) return {
|
|
4649
4676
|
kind: "hidden",
|
|
4650
4677
|
reason: "its input box is not on screen"
|
|
4651
4678
|
};
|
|
4652
4679
|
return state;
|
|
4653
4680
|
} catch (e) {
|
|
4654
|
-
dropComposerTerm(logPath);
|
|
4655
4681
|
return {
|
|
4656
4682
|
kind: "unknown",
|
|
4657
4683
|
reason: `log unreadable or render failed: ${e?.message ?? e}`
|
|
4658
4684
|
};
|
|
4659
4685
|
}
|
|
4660
4686
|
}
|
|
4687
|
+
/** Waits between re-reads of a draft before it counts as abandoned (~15 s in all). */
|
|
4688
|
+
const DRAFT_STABLE_WAITS_MS = [
|
|
4689
|
+
1e3,
|
|
4690
|
+
2e3,
|
|
4691
|
+
4e3,
|
|
4692
|
+
8e3
|
|
4693
|
+
];
|
|
4694
|
+
/** The bottom of the screen as plain text, to tell "unchanged" from "changed". */
|
|
4695
|
+
async function composerFingerprint(record) {
|
|
4696
|
+
if (!record.log_file) return null;
|
|
4697
|
+
try {
|
|
4698
|
+
const rows = await renderComposerRows({
|
|
4699
|
+
...record,
|
|
4700
|
+
log_file: record.log_file
|
|
4701
|
+
});
|
|
4702
|
+
return rows ? rows.slice(-8).map((r) => r.text).join("\n") : null;
|
|
4703
|
+
} catch {
|
|
4704
|
+
return null;
|
|
4705
|
+
}
|
|
4706
|
+
}
|
|
4707
|
+
/**
|
|
4708
|
+
* The target's input box holds text and has not changed for DRAFT_STABLE_WAITS_MS
|
|
4709
|
+
* (1, 2, 4, 8 s): nobody is typing, so submit it with Enter and report true once
|
|
4710
|
+
* the box reads empty again. Only a draft: a menu or yes/no prompt is a question
|
|
4711
|
+
* agent-yes deliberately does not answer. Any change, or a box that never clears,
|
|
4712
|
+
* returns false and the caller parks the message as before.
|
|
4713
|
+
*/
|
|
4714
|
+
async function submitStableDraft(record, waits = DRAFT_STABLE_WAITS_MS, sleep = (ms) => new Promise((r) => setTimeout(r, ms))) {
|
|
4715
|
+
if ((await readComposerState(record)).kind !== "draft") return false;
|
|
4716
|
+
const base = await composerFingerprint(record);
|
|
4717
|
+
if (base === null) return false;
|
|
4718
|
+
for (const ms of waits) {
|
|
4719
|
+
await sleep(ms);
|
|
4720
|
+
if (await composerFingerprint(record) !== base) return false;
|
|
4721
|
+
}
|
|
4722
|
+
if (!record.fifo_file) return false;
|
|
4723
|
+
await withIpcLock(record.pid, () => writeToIpc(record.fifo_file, "\r"));
|
|
4724
|
+
for (let i = 0; i < 5; i++) {
|
|
4725
|
+
await sleep(500);
|
|
4726
|
+
if ((await readComposerState(record)).kind === "empty") return true;
|
|
4727
|
+
}
|
|
4728
|
+
return false;
|
|
4729
|
+
}
|
|
4661
4730
|
/** Bytes `[from, to)` of a log file. */
|
|
4662
4731
|
async function readLogRange(logPath, from, to) {
|
|
4663
4732
|
const fh = await open(logPath, "r");
|
|
@@ -4919,7 +4988,7 @@ async function backoffWhileTyping(pid, maxWaitMs) {
|
|
|
4919
4988
|
};
|
|
4920
4989
|
}
|
|
4921
4990
|
/** Attribute the evidence to THIS message, never to redraws or another turn. */
|
|
4922
|
-
function inspectSubmission(screen, identity) {
|
|
4991
|
+
function inspectSubmission(screen, identity, cli) {
|
|
4923
4992
|
const unknown = {
|
|
4924
4993
|
submission: "not-submitted",
|
|
4925
4994
|
retry: false,
|
|
@@ -4931,7 +5000,9 @@ function inspectSubmission(screen, identity) {
|
|
|
4931
5000
|
const compact = (text) => text.replace(/\s+/gu, "");
|
|
4932
5001
|
const needle = compact(identity);
|
|
4933
5002
|
const wrapped = identity.startsWith("<ay-msg ");
|
|
4934
|
-
const
|
|
5003
|
+
const closer = wrapped ? compact(`</ay-msg ${identity.slice(8)}>`) : null;
|
|
5004
|
+
const occurrences = (text) => Math.max(text.split(needle).length - 1, closer ? text.split(closer).length - 1 : 0);
|
|
5005
|
+
const prompt = composerPromptRow(screen, cli);
|
|
4935
5006
|
if (prompt < 0) {
|
|
4936
5007
|
if (wrapped) return unknown;
|
|
4937
5008
|
let last = screen.length - 1;
|
|
@@ -4947,9 +5018,9 @@ function inspectSubmission(screen, identity) {
|
|
|
4947
5018
|
}
|
|
4948
5019
|
const transcriptLines = screen.slice(0, prompt);
|
|
4949
5020
|
const transcript = compact(transcriptLines.join("\n"));
|
|
4950
|
-
let transcriptMatches = wrapped ? transcript
|
|
5021
|
+
let transcriptMatches = wrapped ? occurrences(transcript) : 0;
|
|
4951
5022
|
if (!wrapped) {
|
|
4952
|
-
const lines = transcriptLines.map((line) => compact(line
|
|
5023
|
+
const lines = transcriptLines.map((line) => compact(stripPromptGlyph(line, cli)));
|
|
4953
5024
|
for (let start = 0; start < lines.length; start++) {
|
|
4954
5025
|
let candidate = "";
|
|
4955
5026
|
for (let end = start; end < lines.length && candidate.length < needle.length; end++) {
|
|
@@ -4961,13 +5032,13 @@ function inspectSubmission(screen, identity) {
|
|
|
4961
5032
|
}
|
|
4962
5033
|
}
|
|
4963
5034
|
}
|
|
4964
|
-
const input = [screen[prompt]
|
|
5035
|
+
const input = [stripPromptGlyph(screen[prompt], cli)];
|
|
4965
5036
|
for (const line of screen.slice(prompt + 1)) {
|
|
4966
5037
|
if (isComposerChrome(line)) break;
|
|
4967
5038
|
input.push(line);
|
|
4968
5039
|
}
|
|
4969
5040
|
const composer = compact(input.join("\n"));
|
|
4970
|
-
if (wrapped ? composer
|
|
5041
|
+
if (wrapped ? occurrences(composer) > 0 : composer === needle) return {
|
|
4971
5042
|
submission: "not-submitted",
|
|
4972
5043
|
retry: true,
|
|
4973
5044
|
transcriptMatches,
|
|
@@ -4999,14 +5070,32 @@ function ownedCollapsedPaste(cli, beforePaste, afterPaste) {
|
|
|
4999
5070
|
const token = collapsedPasteToken(afterPaste);
|
|
5000
5071
|
return token && !beforePaste.join("\n").includes(token) ? token : null;
|
|
5001
5072
|
}
|
|
5073
|
+
/**
|
|
5074
|
+
* The target's screen as submit-confirm reads it. For Claude this is the
|
|
5075
|
+
* composer check's render, which goes further back than the 32 KB tail when the
|
|
5076
|
+
* tail lacks the composer box: Claude redraws only changed rows, so while it is
|
|
5077
|
+
* busy the tail can hold spinner redraws but neither the box nor a message
|
|
5078
|
+
* queued above it, and nothing on such a screen can be attributed to our send.
|
|
5079
|
+
*/
|
|
5080
|
+
async function renderSendScreen(record, geometry) {
|
|
5081
|
+
if (record.cli === "claude") {
|
|
5082
|
+
const rows = await renderComposerRows(record, COMPOSER_WINDOWS, true).catch(() => void 0);
|
|
5083
|
+
if (rows !== void 0) return (rows ?? []).map((r) => r.text);
|
|
5084
|
+
}
|
|
5085
|
+
return await renderLogTailLines(record.log_file, 40, geometry) ?? [];
|
|
5086
|
+
}
|
|
5002
5087
|
const SEND_EXIT_QUEUED = 4;
|
|
5003
5088
|
/** Retry only Enter, never the body. Three attempts, phi delay capped at 400ms. */
|
|
5004
5089
|
async function submitAndConfirm(record, fifoPath, trailing, identity, beforePaste) {
|
|
5005
5090
|
const logFile = record.log_file;
|
|
5091
|
+
const target = {
|
|
5092
|
+
...record,
|
|
5093
|
+
log_file: logFile
|
|
5094
|
+
};
|
|
5006
5095
|
const geometry = await readAgentPtysize(record) ?? void 0;
|
|
5007
5096
|
const cfg = (await cliDefaults())[record.cli];
|
|
5008
|
-
let screen = await
|
|
5009
|
-
const before = inspectSubmission(screen, identity);
|
|
5097
|
+
let screen = await renderSendScreen(target, geometry);
|
|
5098
|
+
const before = inspectSubmission(screen, identity, record.cli);
|
|
5010
5099
|
const baseline = before.transcriptMatches;
|
|
5011
5100
|
const delivered = (e) => e.submission !== "not-submitted" && e.transcriptMatches > baseline || before.inComposer && e.composerVisible && !e.inComposer;
|
|
5012
5101
|
const outcome = (e, current) => {
|
|
@@ -5018,12 +5107,12 @@ async function submitAndConfirm(record, fifoPath, trailing, identity, beforePast
|
|
|
5018
5107
|
};
|
|
5019
5108
|
};
|
|
5020
5109
|
const ownPaste = ownedCollapsedPaste(record.cli, beforePaste, screen);
|
|
5021
|
-
const canRetry = (evidence, current) => evidence.retry || ownPaste !== null && collapsedPasteToken(current) === ownPaste;
|
|
5110
|
+
const canRetry = (evidence, current) => trailing === "\r" && (evidence.retry || ownPaste !== null && collapsedPasteToken(current) === ownPaste);
|
|
5022
5111
|
for (let attempt = 0; attempt <= SEND_SUBMIT_MAX_RETRIES; attempt++) {
|
|
5023
5112
|
if (attempt) {
|
|
5024
5113
|
await new Promise((r) => setTimeout(r, Math.min(400, 150 * 1.618 ** (attempt - 1))));
|
|
5025
|
-
screen = await
|
|
5026
|
-
const settled = inspectSubmission(screen, identity);
|
|
5114
|
+
screen = await renderSendScreen(target, geometry);
|
|
5115
|
+
const settled = inspectSubmission(screen, identity, record.cli);
|
|
5027
5116
|
if (delivered(settled)) return outcome(settled, screen);
|
|
5028
5117
|
if (!canRetry(settled, screen) || cfg?.needsInput?.length && parseMenu(screen, {
|
|
5029
5118
|
needsInput: cfg.needsInput,
|
|
@@ -5032,8 +5121,8 @@ async function submitAndConfirm(record, fifoPath, trailing, identity, beforePast
|
|
|
5032
5121
|
}
|
|
5033
5122
|
await writeToIpc(fifoPath, trailing);
|
|
5034
5123
|
await waitForLogQuiet(logFile, SEND_CONFIRM_QUIET_MS, SEND_CONFIRM_MAX_MS);
|
|
5035
|
-
screen = await
|
|
5036
|
-
const evidence = inspectSubmission(screen, identity);
|
|
5124
|
+
screen = await renderSendScreen(target, geometry);
|
|
5125
|
+
const evidence = inspectSubmission(screen, identity, record.cli);
|
|
5037
5126
|
if (delivered(evidence)) return outcome(evidence, screen);
|
|
5038
5127
|
if (!canRetry(evidence, screen)) break;
|
|
5039
5128
|
}
|
|
@@ -5060,7 +5149,10 @@ async function waitForNeedsInputClear(record, timeoutMs) {
|
|
|
5060
5149
|
*/
|
|
5061
5150
|
async function deliverBody(record, fifoPath, fullBody, trailing, identity, canConfirm) {
|
|
5062
5151
|
if (fullBody && trailing) {
|
|
5063
|
-
const beforePaste = canConfirm && record.log_file ? await
|
|
5152
|
+
const beforePaste = canConfirm && record.log_file ? await renderSendScreen({
|
|
5153
|
+
...record,
|
|
5154
|
+
log_file: record.log_file
|
|
5155
|
+
}, await readAgentPtysize(record) ?? void 0) : null;
|
|
5064
5156
|
await writeToIpc(fifoPath, fullBody);
|
|
5065
5157
|
if (canConfirm && record.log_file) {
|
|
5066
5158
|
await waitForLogQuiet(record.log_file, SEND_SETTLE_QUIET_MS, SEND_SETTLE_MAX_MS);
|
|
@@ -5075,6 +5167,33 @@ async function deliverBody(record, fifoPath, fullBody, trailing, identity, canCo
|
|
|
5075
5167
|
submission: canConfirm ? "not-submitted" : "unchecked"
|
|
5076
5168
|
};
|
|
5077
5169
|
}
|
|
5170
|
+
/** Called under the same input lock as the subsequent paste and submit. */
|
|
5171
|
+
async function interruptSendTarget(record, fifoPath) {
|
|
5172
|
+
const cfg = (await cliDefaults())[record.cli] ?? {};
|
|
5173
|
+
const result = await interruptBeforeSend(record.cli, {
|
|
5174
|
+
readState: async () => {
|
|
5175
|
+
if (!record.log_file) return "unknown";
|
|
5176
|
+
const screen = await renderSendScreen({
|
|
5177
|
+
...record,
|
|
5178
|
+
log_file: record.log_file
|
|
5179
|
+
});
|
|
5180
|
+
return interruptScreenState(record.cli, screen, cfg);
|
|
5181
|
+
},
|
|
5182
|
+
write: (code) => writeToIpc(fifoPath, code),
|
|
5183
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
5184
|
+
});
|
|
5185
|
+
const notice = result === "permission" ? "ay send: --interrupt skipped: target is at a permission/confirmation prompt; sending as usual" : result === "unknown" || result === "unsupported" ? `ay send: --interrupt skipped: ${result === "unknown" ? "could not verify the target's screen" : `unsupported CLI ${record.cli}`}; sending as usual` : `ay send: ${result === "interrupted" ? "current turn interrupted; idle prompt confirmed" : "target is already idle"}`;
|
|
5186
|
+
process.stderr.write(notice + "\n");
|
|
5187
|
+
return notice;
|
|
5188
|
+
}
|
|
5189
|
+
async function interruptPermissionPrompt(record) {
|
|
5190
|
+
if (!record.log_file) return false;
|
|
5191
|
+
const cfg = (await cliDefaults())[record.cli] ?? {};
|
|
5192
|
+
return interruptScreenState(record.cli, await renderSendScreen({
|
|
5193
|
+
...record,
|
|
5194
|
+
log_file: record.log_file
|
|
5195
|
+
}), cfg) === "permission";
|
|
5196
|
+
}
|
|
5078
5197
|
const DRAIN_POLL_BASE_MS = 500;
|
|
5079
5198
|
const DRAIN_POLL_CAP_MS = 5e3;
|
|
5080
5199
|
function drainerLockPath(pid) {
|
|
@@ -5193,11 +5312,16 @@ async function cmdSendDrain(rest) {
|
|
|
5193
5312
|
}
|
|
5194
5313
|
const record = (await readGlobalPids()).find((r) => r.pid === pid);
|
|
5195
5314
|
let result = null;
|
|
5315
|
+
if (record && !msg.interrupt && !await isUserTyping(pid)) await submitStableDraft(record);
|
|
5196
5316
|
if (record && !await isUserTyping(pid)) await withIpcLock(pid, async () => {
|
|
5197
5317
|
if (await isUserTyping(pid)) return;
|
|
5198
5318
|
if ((await readComposerState(record)).kind !== "empty") return;
|
|
5319
|
+
if (msg.interrupt) {
|
|
5320
|
+
await interruptSendTarget(record, msg.fifoPath);
|
|
5321
|
+
if ((await readComposerState(record)).kind !== "empty") return;
|
|
5322
|
+
}
|
|
5199
5323
|
if (!await claimPending(pid, name)) return;
|
|
5200
|
-
result = await deliverBody(record, msg.fifoPath, msg.fullBody, msg.trailing, msg.identity, msg.trailing
|
|
5324
|
+
result = await deliverBody(record, msg.fifoPath, msg.fullBody, msg.trailing, msg.identity, isSubmitCode(msg.trailing) && Boolean(record.log_file));
|
|
5201
5325
|
});
|
|
5202
5326
|
if (result) {
|
|
5203
5327
|
const d = result;
|
|
@@ -5219,10 +5343,19 @@ async function cmdSendDrain(rest) {
|
|
|
5219
5343
|
}
|
|
5220
5344
|
}
|
|
5221
5345
|
async function cmdSend(rest) {
|
|
5222
|
-
const
|
|
5346
|
+
const y = yargs(rest).help(false).parserConfiguration({ "boolean-negation": false }).usage("Usage: ay send <keyword> <msg|-> [options]\n\nBusy targets receive input without waiting for idle using native Enter input.\nExplicit --code=alt-m requests immediate send and may interrupt work.\nExisting drafts are protected and may defer delivery.\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", {
|
|
5223
5347
|
type: "string",
|
|
5224
5348
|
default: "enter",
|
|
5225
|
-
description: "Trailing control code (enter|esc|ctrl-c|ctrl-y|tab|none)"
|
|
5349
|
+
description: "Trailing control code (enter|alt-m|esc|ctrl-c|ctrl-y|tab|none); alt-m may interrupt work"
|
|
5350
|
+
}).option("interrupt", {
|
|
5351
|
+
alias: "i",
|
|
5352
|
+
type: "boolean",
|
|
5353
|
+
default: false,
|
|
5354
|
+
description: "Stop a local target's current turn, wait for idle, then deliver; never cancel a permission/confirmation prompt"
|
|
5355
|
+
}).option("help", {
|
|
5356
|
+
alias: "h",
|
|
5357
|
+
type: "boolean",
|
|
5358
|
+
description: "Show send options"
|
|
5226
5359
|
}).option("all", {
|
|
5227
5360
|
type: "boolean",
|
|
5228
5361
|
default: false,
|
|
@@ -5248,7 +5381,12 @@ async function cmdSend(rest) {
|
|
|
5248
5381
|
default: false,
|
|
5249
5382
|
alias: "no-wrap",
|
|
5250
5383
|
description: "Send the body verbatim: omit the <ay-msg …> attribution wrapper that agent senders add by default (also: AGENT_YES_SEND_RAW=1)"
|
|
5251
|
-
}).
|
|
5384
|
+
}).version(false).strictOptions().exitProcess(false);
|
|
5385
|
+
const argv = await y.parseAsync();
|
|
5386
|
+
if (argv.help) {
|
|
5387
|
+
process.stdout.write(await y.getHelp() + "\n");
|
|
5388
|
+
return 0;
|
|
5389
|
+
}
|
|
5252
5390
|
const opts = {
|
|
5253
5391
|
all: argv.all,
|
|
5254
5392
|
active: false,
|
|
@@ -5258,11 +5396,12 @@ async function cmdSend(rest) {
|
|
|
5258
5396
|
};
|
|
5259
5397
|
const keyword = argv._[0] !== void 0 ? String(argv._[0]) : void 0;
|
|
5260
5398
|
const rawMessage = argv._.slice(1).map(String).join(" ");
|
|
5261
|
-
if (!keyword) throw new Error("usage: ay send <keyword> <msg|-> [--code=enter|esc|ctrl-c|ctrl-y|tab|none]");
|
|
5399
|
+
if (!keyword) throw new Error("usage: ay send <keyword> <msg|-> [--code=enter|alt-m|esc|ctrl-c|ctrl-y|tab|none]");
|
|
5262
5400
|
if (rawMessage !== "-" && rawMessage.trim() === "") throw new Error("ay send: refusing to send an empty message. Pass the text as a single argument, or use `-` to read the body from stdin (e.g. `ay send <keyword> - < file.txt`).");
|
|
5263
5401
|
const codeName = argv.code.toLowerCase();
|
|
5264
5402
|
{
|
|
5265
5403
|
const remote = await resolveRemoteSpec(keyword);
|
|
5404
|
+
if (remote && argv.interrupt) throw new Error("ay send: --interrupt requires a local target; run ay send --interrupt on the target host");
|
|
5266
5405
|
if (remote) return runRemoteSend(remote, rawMessage, codeName, Boolean(argv.raw) || process.env.AGENT_YES_SEND_RAW === "1");
|
|
5267
5406
|
}
|
|
5268
5407
|
const trailing = controlCodeFromName(codeName);
|
|
@@ -5332,13 +5471,14 @@ async function cmdSend(rest) {
|
|
|
5332
5471
|
}
|
|
5333
5472
|
const fullBody = framePaste$1 ? framePaste(prefix + body + suffix) : prefix + body + suffix;
|
|
5334
5473
|
const noWait = Boolean(argv.noWait) || process.env.AGENT_YES_SEND_NO_WAIT === "1";
|
|
5474
|
+
let interrupt = argv.interrupt;
|
|
5335
5475
|
let parkReason = null;
|
|
5336
5476
|
if (fullBody && !noWait && !force) {
|
|
5337
5477
|
const { clear, waitedMs } = await backoffWhileTyping(record.pid, SEND_TYPING_MAX_WAIT_MS);
|
|
5338
5478
|
if (!clear) parkReason = `user still typing after ${Math.round(waitedMs / 1e3)}s`;
|
|
5339
5479
|
else if (waitedMs > 0) process.stderr.write(`waited ${Math.round(waitedMs / 1e3)}s for the user to pause typing before sending.\n`);
|
|
5340
5480
|
}
|
|
5341
|
-
const canConfirm = trailing
|
|
5481
|
+
const canConfirm = isSubmitCode(trailing) && Boolean(fullBody) && !noWait;
|
|
5342
5482
|
const identity = nonce ? `<ay-msg ${nonce}` : body;
|
|
5343
5483
|
let confirmed = !canConfirm;
|
|
5344
5484
|
const receipt = { submission: canConfirm ? "not-submitted" : "unchecked" };
|
|
@@ -5366,6 +5506,7 @@ async function cmdSend(rest) {
|
|
|
5366
5506
|
code: trailing === "\r" ? void 0 : codeName,
|
|
5367
5507
|
wrapped: Boolean(nonce)
|
|
5368
5508
|
};
|
|
5509
|
+
if (fullBody && !interrupt && !noWait && !parkReason && (await listPending(record.pid)).length === 0) await submitStableDraft(record);
|
|
5369
5510
|
try {
|
|
5370
5511
|
await withIpcLock(record.pid, async () => {
|
|
5371
5512
|
const dedupeKey = force || !body ? null : senderKey(mailBase.from);
|
|
@@ -5373,6 +5514,24 @@ async function cmdSend(rest) {
|
|
|
5373
5514
|
duplicateOf = await findRecentDuplicate(record.pid, dedupeKey, body);
|
|
5374
5515
|
if (duplicateOf) return;
|
|
5375
5516
|
}
|
|
5517
|
+
const park = async () => {
|
|
5518
|
+
if (dedupeKey) await noteRecentSend(record.pid, dedupeKey, body, "queued");
|
|
5519
|
+
await enqueuePending({
|
|
5520
|
+
queuedAt: Date.now(),
|
|
5521
|
+
pid: record.pid,
|
|
5522
|
+
fifoPath,
|
|
5523
|
+
fullBody,
|
|
5524
|
+
trailing,
|
|
5525
|
+
interrupt,
|
|
5526
|
+
identity,
|
|
5527
|
+
record: mailBase
|
|
5528
|
+
});
|
|
5529
|
+
parked = true;
|
|
5530
|
+
};
|
|
5531
|
+
if (interrupt && await interruptPermissionPrompt(record)) {
|
|
5532
|
+
process.stderr.write("ay send: --interrupt skipped: target is at a permission/confirmation prompt; sending as usual\n");
|
|
5533
|
+
interrupt = false;
|
|
5534
|
+
}
|
|
5376
5535
|
if (fullBody) {
|
|
5377
5536
|
if (!parkReason && (await listPending(record.pid)).length) parkReason = "earlier messages to this agent are still queued";
|
|
5378
5537
|
if (!parkReason) {
|
|
@@ -5381,22 +5540,22 @@ async function cmdSend(rest) {
|
|
|
5381
5540
|
else if (composer.kind === "hidden") parkReason = composer.reason;
|
|
5382
5541
|
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`);
|
|
5383
5542
|
}
|
|
5384
|
-
if (dedupeKey) await noteRecentSend(record.pid, dedupeKey, body, parkReason ? "queued" : "sent");
|
|
5385
5543
|
if (parkReason) {
|
|
5386
|
-
await
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5544
|
+
await park();
|
|
5545
|
+
return;
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
if (interrupt) {
|
|
5549
|
+
await interruptSendTarget(record, fifoPath);
|
|
5550
|
+
const composer = await readComposerState(record);
|
|
5551
|
+
if (composer.kind === "draft" || composer.kind === "hidden") {
|
|
5552
|
+
parkReason = "input box was occupied after cancelling the current turn";
|
|
5553
|
+
await park();
|
|
5396
5554
|
return;
|
|
5397
5555
|
}
|
|
5398
5556
|
}
|
|
5399
5557
|
({confirmed, screen: lastScreen, submission: receipt.submission} = await deliverBody(record, fifoPath, fullBody, trailing, identity, canConfirm));
|
|
5558
|
+
if (dedupeKey) await noteRecentSend(record.pid, dedupeKey, body, "sent");
|
|
5400
5559
|
}, (why) => process.stderr.write(`warning: ay send writing pid ${record.pid} without the input lock (${why})\n`));
|
|
5401
5560
|
} catch (e) {
|
|
5402
5561
|
const code = e?.code;
|
|
@@ -5708,11 +5867,16 @@ const GRACEFUL_EXIT_COMMANDS = {
|
|
|
5708
5867
|
cmd: "exit",
|
|
5709
5868
|
powershell: "exit"
|
|
5710
5869
|
};
|
|
5870
|
+
function isSubmitCode(code) {
|
|
5871
|
+
return code === "\r" || code === "\x1Bm";
|
|
5872
|
+
}
|
|
5711
5873
|
function controlCodeFromName(name) {
|
|
5712
5874
|
switch (name) {
|
|
5713
5875
|
case "enter":
|
|
5714
5876
|
case "cr":
|
|
5715
5877
|
case "return": return "\r";
|
|
5878
|
+
case "alt-m":
|
|
5879
|
+
case "alt+m": return "\x1Bm";
|
|
5716
5880
|
case "esc":
|
|
5717
5881
|
case "escape": return "\x1B";
|
|
5718
5882
|
case "ctrl-c":
|
|
@@ -6013,7 +6177,7 @@ async function cmdAttach(rest) {
|
|
|
6013
6177
|
const winsizeDir = path.join(ayHome, "winsize");
|
|
6014
6178
|
await mkdir(winsizeDir, { recursive: true });
|
|
6015
6179
|
const winsizePath = path.join(winsizeDir, String(record.pid));
|
|
6016
|
-
const { resolveDaemonHttpBase, loadTokenReadOnly } = await import("./serve-
|
|
6180
|
+
const { resolveDaemonHttpBase, loadTokenReadOnly } = await import("./serve-XwFYE0cE.js");
|
|
6017
6181
|
const daemonBase = await resolveDaemonHttpBase().catch(() => null);
|
|
6018
6182
|
const daemonToken = daemonBase ? await loadTokenReadOnly().catch(() => null) ?? "" : "";
|
|
6019
6183
|
const capViewer = `attach:${process.pid}`;
|
|
@@ -6762,7 +6926,7 @@ async function cmdNotify(rest) {
|
|
|
6762
6926
|
}
|
|
6763
6927
|
const ensure = async () => {
|
|
6764
6928
|
if (!argv["ensure-daemon"]) return;
|
|
6765
|
-
const { ensureDaemon } = await import("./notifyDaemon-
|
|
6929
|
+
const { ensureDaemon } = await import("./notifyDaemon-DkUB7GV2.js");
|
|
6766
6930
|
await ensureDaemon().catch(() => null);
|
|
6767
6931
|
};
|
|
6768
6932
|
await heartbeatWatcher(parent, selfStartedAt);
|
|
@@ -6836,7 +7000,7 @@ async function cmdNotifyCursor(args) {
|
|
|
6836
7000
|
}
|
|
6837
7001
|
async function cmdNotifyd(rest) {
|
|
6838
7002
|
const sub = rest[0] ?? "status";
|
|
6839
|
-
const daemon = await import("./notifyDaemon-
|
|
7003
|
+
const daemon = await import("./notifyDaemon-DkUB7GV2.js");
|
|
6840
7004
|
switch (sub) {
|
|
6841
7005
|
case "run": return daemon.runDaemon();
|
|
6842
7006
|
case "once": return daemon.runDaemon({ once: true });
|
|
@@ -6862,5 +7026,5 @@ async function cmdNotifyd(rest) {
|
|
|
6862
7026
|
}
|
|
6863
7027
|
|
|
6864
7028
|
//#endregion
|
|
6865
|
-
export {
|
|
6866
|
-
//# sourceMappingURL=subcommands-
|
|
7029
|
+
export { readNotes as $, inspectSubmission as A, isUnknownManagerToken as B, envelopeAttribution as C, framePaste as Ct, extractNeedsInput as D, flattenForest as Dt, extractMenu as E, buildAgentForest as Et, isExitRequest as F, listRecords as G, isUserTyping as H, isPidAlive as I, ownedCollapsedPaste as J, matchKeyword as K, isSlashCommand as L, isAgentIdShaped as M, isAgentStuck as N, extractTaskCounts as O, isBareManagerInvocation as P, readLogForRender as Q, isSubcommand as R, enableRenderDiskCache as S, withIpcLock as St, extractBadges as T, TYPING_BADGE as Tt, lastReadAt as U, isUnreachableWriteErrno as V, lastStdinAt as W, readAgentPtysize as X, probeStdinReachable as Y, readComposerState as Z, cursorAbs as _, submitStableDraft as _t, READ_PAGE_DEFAULT as a, renderRawLogLines as at, deriveLiveStatus as b, writeKeysPaced as bt, SEND_EXIT_QUEUED as c, resolveResumeArgs as ct, backoffWhileTyping as d, saveRenderDisk as dt, readPtysize as et, buildEnvelope as f, sendPayloadCapError as ft, controlCodeFromName as g, submitAndConfirm as gt, confirmStdinUnreachable as h, stopTipForCli as ht, MAX_RENDER_BYTES as i, renderRawLog as it, interruptSendTarget as j, finalizedLines as k, SEND_EXIT_UNREACHABLE as l, restartHintLines as lt, cmdHelp as m, stdinActivityPath as mt, DRAFT_STABLE_WAITS_MS as n, recentReadEdges as nt, READ_WINDOW_MS as o, resolveOne as ot, cliDefaults as p, snapshotStatus as pt, menuSelectKeys as q, GRACEFUL_EXIT_COMMANDS as r, renderLogTailLines as rt, SEND_BODY_MAX_CHARS as s, resolveReadWindow as st, COMPOSER_WINDOWS as t, recentMessageEdges as tt, TYPING_WINDOW_MS as u, runSubcommand as ut, cwdLabel as v, suggestAgents as vt, envelopeCostFor as w, shouldFramePaste as wt, drainerLauncher as x, writeToIpc as xt, deriveLiveState as y, waitForLogQuiet as yt, isSubmitCode as z };
|
|
7030
|
+
//# sourceMappingURL=subcommands-B7YZJL8n.js.map
|