@conveno/cli 0.2.0-rc.6 → 0.2.0-rc.7
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/dist/{acp-3xehqLdo.js → acp-9pRRszwU.js} +3 -3
- package/dist/agy-relay-C-nqvieJ.js +137 -0
- package/dist/{args-D9T-6TDw.js → args-C7Agak9f.js} +9 -3
- package/dist/bin.js +2 -2
- package/dist/daemon.js +65 -20
- package/dist/{daemonError-CdLataBW.js → daemonError-DNAKEyRT.js} +1 -1
- package/dist/{dist-BTLBO1Rp.js → dist-D2hMvcZu.js} +291 -139
- package/dist/dist-D9Gu-mQm.js +547 -0
- package/dist/dist-DOGlDbRb.js +504 -0
- package/dist/{dist-BAlMjYqQ.js → dist-DOKVrSIw.js} +3 -3
- package/dist/dist-Dd31Fg0h.js +671 -0
- package/dist/{dist-BYVibI3a.js → dist-ftx5RNCp.js} +1 -1
- package/dist/{dist-DIAtMDWW.js → dist-iFaY42Bs.js} +1 -1
- package/dist/{doctor-DjwXJvKw.js → doctor-BYa-MApu.js} +91 -16
- package/dist/{hook-BGJc4PHG.js → hook-CQeSn-w4.js} +5 -1
- package/dist/{hook-entry-BWWJS7n3.js → hook-entry-BXmSN--S.js} +611 -743
- package/dist/hook-entry-CgiSN-Oj.js +1 -0
- package/dist/{main-CRw-fISR.js → main-seh-HPZO.js} +12 -12
- package/dist/{pick-B-18E4Mx.js → pick-DoyocW55.js} +1 -1
- package/dist/{run-Yi48fiJN.js → run-B-WfNtCX.js} +271 -229
- package/dist/{runtime-DyknkzAS.js → runtime-Bnjh9BQ8.js} +18 -9
- package/dist/{dist-CNyzLyZh.js → toml-patch-DGzVRdd1.js} +20 -497
- package/dist/watch-Dr2RdyGo.js +185 -0
- package/package.json +15 -15
- package/dist/dist-LkcRvVjE.js +0 -449
- package/dist/hook-entry-rDISaMgP.js +0 -1
- package/dist/sidecar-CTKxOMie.js +0 -98
- package/dist/watch-CfYanJvt.js +0 -109
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
|
-
import { n as runAcpHostFromFile, r as stopRequestPath, t as killProcessTree } from "./dist-
|
|
3
|
-
import {
|
|
4
|
-
import { i as parseFlags, t as COMMANDS } from "./args-
|
|
2
|
+
import { n as runAcpHostFromFile, r as stopRequestPath, t as killProcessTree } from "./dist-DOKVrSIw.js";
|
|
3
|
+
import { It as spawnRecordPath, St as readSpawnRecord } from "./dist-D2hMvcZu.js";
|
|
4
|
+
import { i as parseFlags, t as COMMANDS } from "./args-C7Agak9f.js";
|
|
5
5
|
import { a as fail, n as cmd } from "./fmt-C2SsP5Y0.js";
|
|
6
6
|
// src/acp.ts
|
|
7
7
|
/** How long `conveno stop` waits for a worker to end by itself before it ends the process tree. */
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { t as RELAY_SUBCOMMAND } from "./dist-D9Gu-mQm.js";
|
|
3
|
+
import { Nt as runWaker } from "./dist-D2hMvcZu.js";
|
|
4
|
+
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
5
|
+
// src/agy-relay.ts
|
|
6
|
+
/**
|
|
7
|
+
* Time limit of one `agentapi send-message`. It normally answers within about a second; the limit
|
|
8
|
+
* only stops a hung run. It is long so a slow send that succeeds is not taken for a failure.
|
|
9
|
+
*/
|
|
10
|
+
const SEND_TIMEOUT_MS = 12e4;
|
|
11
|
+
/** Runs the file directly, never through a shell, so every argument stays one argument. */
|
|
12
|
+
const runSend = (file, args, timeoutMs) => new Promise((resolve) => {
|
|
13
|
+
execFile(file, args, {
|
|
14
|
+
timeout: timeoutMs,
|
|
15
|
+
windowsHide: true,
|
|
16
|
+
encoding: "utf8"
|
|
17
|
+
}, (err) => {
|
|
18
|
+
if (!err) return resolve("sent");
|
|
19
|
+
resolve(err.killed ? "unknown" : "failed");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const UUID = /^[0-9a-fA-F-]{8,64}$/;
|
|
23
|
+
function relayText(text, count) {
|
|
24
|
+
if (text.length <= 16e3) return text;
|
|
25
|
+
return `[conveno] ${count} message${count === 1 ? "" : "s"} arrived through Conveno, too long to show here. Conveno started this turn; the user did not type it. Read them with the inbox tool (unread_only false).`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run `<agy> agentapi send-message <conversation> <text>`. The executable is run directly, never
|
|
29
|
+
* through a shell, so the text stays one argument; on Windows only a real `.exe` is run, because a
|
|
30
|
+
* `.cmd` or `.bat` shim would have cmd.exe parse the text. False only when no turn started: a send
|
|
31
|
+
* killed at the time limit counts as sent, so the waker does not requeue messages agy may already
|
|
32
|
+
* have taken and send them twice (they stay readable with the inbox tool).
|
|
33
|
+
*/
|
|
34
|
+
async function sendToConversation(io, exe, conversationId, text) {
|
|
35
|
+
if (io.platform === "win32" && !/\.exe$/i.test(exe)) return false;
|
|
36
|
+
try {
|
|
37
|
+
return await (io.run ?? runSend)(exe, [
|
|
38
|
+
"agentapi",
|
|
39
|
+
"send-message",
|
|
40
|
+
conversationId,
|
|
41
|
+
text
|
|
42
|
+
], SEND_TIMEOUT_MS) !== "failed";
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const END = {
|
|
48
|
+
superseded: "another relay for this conversation took over. Do not start it again.",
|
|
49
|
+
no_session: "no Conveno session belongs to this conversation (is the conveno MCP server on?). Do not start it again.",
|
|
50
|
+
one_shot: "this agy run is one-shot (agy -p), so nothing can wake it. Do not start it again."
|
|
51
|
+
};
|
|
52
|
+
/** agy's one-shot flags: `-p` and its aliases `--print` and `--prompt` (agy docs cli/headless). */
|
|
53
|
+
const ONE_SHOT = /^(?:-p|--print|--prompt)(?:=|$)/;
|
|
54
|
+
/** True when an ancestor of this process is a one-shot `agy -p` run. */
|
|
55
|
+
async function underOneShotAgy(ctx) {
|
|
56
|
+
return ((await ctx.ancestry(2e3).catch(() => void 0))?.entries ?? []).some((e) => {
|
|
57
|
+
const words = Array.from((e.command ?? "").matchAll(/"([^"]*)"|(\S+)/g)).map((m) => m[1] ?? m[2] ?? "");
|
|
58
|
+
const exe = (words[0] ?? "").split(/[\\/]/).pop()?.toLowerCase();
|
|
59
|
+
return (exe === "agy" || exe === "agy.exe") && words.slice(1).some((w) => ONE_SHOT.test(w));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function runAgyRelay(ctx, argv, deps = {}) {
|
|
63
|
+
const end = (why, code = 0) => {
|
|
64
|
+
ctx.out(`[conveno] ${RELAY_SUBCOMMAND} ended: ${why}\n`);
|
|
65
|
+
return code;
|
|
66
|
+
};
|
|
67
|
+
if (argv.length > 0) return end("it takes no arguments.", 2);
|
|
68
|
+
const conversationId = ctx.env.ANTIGRAVITY_CONVERSATION_ID;
|
|
69
|
+
const exe = ctx.env.ANTIGRAVITY_AGENTAPI_EXE;
|
|
70
|
+
if (!conversationId || !UUID.test(conversationId) || !exe) return end("it only runs inside an Antigravity agent's command. Nothing to do.");
|
|
71
|
+
if (ctx.platform === "win32" && !/\.exe$/i.test(exe)) return end("ANTIGRAVITY_AGENTAPI_EXE is not an .exe. Do not start it again.");
|
|
72
|
+
if (await underOneShotAgy(ctx)) return end(END.one_shot);
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const signal = controller.signal;
|
|
75
|
+
const stop = () => controller.abort();
|
|
76
|
+
deps.signal?.addEventListener("abort", stop, { once: true });
|
|
77
|
+
if (deps.signal?.aborted) stop();
|
|
78
|
+
const signals = deps.signal ? [] : ["SIGINT", "SIGTERM"];
|
|
79
|
+
for (const s of signals) process.once(s, stop);
|
|
80
|
+
const runWaker$1 = deps.runWaker ?? runWaker;
|
|
81
|
+
const pollMs = deps.pollMs ?? 3e3;
|
|
82
|
+
const findMs = deps.findMs ?? 6e5;
|
|
83
|
+
const retryBase = deps.retryMs ?? 2e3;
|
|
84
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
85
|
+
const t = setTimeout(resolve, ms);
|
|
86
|
+
signal.addEventListener("abort", () => {
|
|
87
|
+
clearTimeout(t);
|
|
88
|
+
resolve();
|
|
89
|
+
}, { once: true });
|
|
90
|
+
});
|
|
91
|
+
let client;
|
|
92
|
+
let retry = retryBase;
|
|
93
|
+
let looking = Date.now();
|
|
94
|
+
try {
|
|
95
|
+
while (!signal.aborted) {
|
|
96
|
+
let session;
|
|
97
|
+
let c;
|
|
98
|
+
try {
|
|
99
|
+
c = client ??= await ctx.connect(connectOpts(ctx, false));
|
|
100
|
+
const { sessions } = await c["session.list"]({ cli: "antigravity" });
|
|
101
|
+
session = sessions.find((s) => s.nativeId === conversationId && s.status !== "offline");
|
|
102
|
+
retry = retryBase;
|
|
103
|
+
} catch {
|
|
104
|
+
await client?.close().catch(() => void 0);
|
|
105
|
+
client = void 0;
|
|
106
|
+
await sleep(retry);
|
|
107
|
+
retry = Math.min(retry * 2, 6e4);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (!session) {
|
|
111
|
+
if (Date.now() - looking > findMs) return end(END.no_session);
|
|
112
|
+
await sleep(pollMs);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const hostPid = session.hostPid;
|
|
116
|
+
const reason = await runWaker$1({
|
|
117
|
+
client: c,
|
|
118
|
+
sessionId: session.id,
|
|
119
|
+
signal,
|
|
120
|
+
...hostPid ? { isHostAlive: () => ctx.isAlive(hostPid) } : {},
|
|
121
|
+
inject: (text, messages) => sendToConversation({
|
|
122
|
+
platform: ctx.platform,
|
|
123
|
+
...deps.run ? { run: deps.run } : {}
|
|
124
|
+
}, exe, conversationId, relayText(text, messages.length))
|
|
125
|
+
});
|
|
126
|
+
if (reason === "aborted" || reason === "host_exited") return 0;
|
|
127
|
+
if (reason === "superseded") return end(END.superseded);
|
|
128
|
+
looking = Date.now();
|
|
129
|
+
}
|
|
130
|
+
return 0;
|
|
131
|
+
} finally {
|
|
132
|
+
deps.signal?.removeEventListener("abort", stop);
|
|
133
|
+
for (const s of signals) process.off(s, stop);
|
|
134
|
+
await client?.close().catch(() => void 0);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export { runAgyRelay };
|
|
@@ -18,7 +18,12 @@ const COMMANDS = [
|
|
|
18
18
|
cli: {
|
|
19
19
|
type: "string",
|
|
20
20
|
value: "<list>",
|
|
21
|
-
help: "Only these CLIs,
|
|
21
|
+
help: "Only these CLIs, separated by commas or spaces, such as claude,codex"
|
|
22
|
+
},
|
|
23
|
+
accept: {
|
|
24
|
+
type: "string",
|
|
25
|
+
value: "<ids>",
|
|
26
|
+
help: "Say yes to these optional setups without asking, such as copilot-idle-wake"
|
|
22
27
|
},
|
|
23
28
|
"acp-adapters": {
|
|
24
29
|
type: "boolean",
|
|
@@ -32,6 +37,7 @@ const COMMANDS = [
|
|
|
32
37
|
notes: [
|
|
33
38
|
"init shows every file it will change, with a diff, and asks first.",
|
|
34
39
|
"Without a terminal it needs --yes, and exits 2 without it.",
|
|
40
|
+
"Optional setups, such as Copilot idle wake (it turns on Copilot's experimental mode), are asked as yes/no, default no. --yes answers no; pass --accept <id> to say yes.",
|
|
35
41
|
"When Codex or Claude Code is installed without its ACP adapter, init asks once whether npx may fetch it (third-party npm packages, pinned versions). The answer is kept; the two adapter flags change it."
|
|
36
42
|
]
|
|
37
43
|
},
|
|
@@ -184,7 +190,7 @@ const COMMANDS = [
|
|
|
184
190
|
flags: { cli: {
|
|
185
191
|
type: "string",
|
|
186
192
|
value: "<list>",
|
|
187
|
-
help: "Only these CLIs,
|
|
193
|
+
help: "Only these CLIs, separated by commas or spaces, such as claude,codex"
|
|
188
194
|
} }
|
|
189
195
|
},
|
|
190
196
|
{
|
|
@@ -228,7 +234,7 @@ const COMMANDS = [
|
|
|
228
234
|
flags: { cli: {
|
|
229
235
|
type: "string",
|
|
230
236
|
value: "<cli>",
|
|
231
|
-
help: "
|
|
237
|
+
help: "The CLI that starts it, such as claude"
|
|
232
238
|
} }
|
|
233
239
|
},
|
|
234
240
|
{
|
package/dist/bin.js
CHANGED
|
@@ -26,9 +26,9 @@ for (const stream of [process.stdout, process.stderr]) stream.on("error", (err)
|
|
|
26
26
|
});
|
|
27
27
|
try {
|
|
28
28
|
let code;
|
|
29
|
-
if (isHook) code = await (await import("./hook-entry-
|
|
29
|
+
if (isHook) code = await (await import("./hook-entry-CgiSN-Oj.js")).runHookEntry(argv.slice(1));
|
|
30
30
|
else {
|
|
31
|
-
const [{ main }, { createRuntimeCtx }] = await Promise.all([import("./main-
|
|
31
|
+
const [{ main }, { createRuntimeCtx }] = await Promise.all([import("./main-seh-HPZO.js"), import("./runtime-Bnjh9BQ8.js")]);
|
|
32
32
|
code = await main(argv, createRuntimeCtx());
|
|
33
33
|
}
|
|
34
34
|
if (isHook) process.exit(code);
|
package/dist/daemon.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { homedir, hostname, userInfo } from "node:os";
|
|
3
|
-
import { t as codexAdapter } from "./dist-
|
|
4
|
-
import { $t as
|
|
3
|
+
import { t as codexAdapter } from "./dist-DOGlDbRb.js";
|
|
4
|
+
import { $ as jwtClaim, $t as EVENT_NAMES, A as daemonProof, At as resolveRecipient, B as evaluateLiveness, Cn as safeParse, Et as requeueEntries, F as detectRepo, G as formatHookContext, Ht as takeWithinChars, J as holderAfterDeparture, Kt as validateRename, M as dataPaths, N as decideAutoContinue, O as createWmiWalker, P as defaultProcessIo, Q as isOnline, Qt as DeviceId, R as effectiveHolder, S as claimOrchestrator, Sn as parseRelayFrame, T as clientProof, Tn as socketPathTooLongMessage, Ut as tooManyUnreadMessage, Vt as takeWithinBytes, W as formatContinuation, Wt as turnHops, _n as makeResult, _t as readAccountTokens, an as PROTOCOL_VERSION, b as baseName, bn as newSessionId, bt as readInbox, dn as defaultSocketPath, fn as encodeFrame, gn as makeEventNotification, hn as makeError, ht as proofsMatch, in as OWNER_SESSION_ID, j as dataDir, k as currentAccessToken, l as RESPONSE_BUDGET_BYTES, ln as SessionId, lt as pendingForInjection, mn as isSocketPathTooLong, n as AccountError, nn as Message, nt as markDelivered, on as RelayPayload, p as ackEntries, pt as planSpawn, q as generateSessionName, r as ConvenoError, rt as newAuthNonce, sn as RpcErrorCode, un as createLineDecoder, v as autoCandidates, vn as newDeviceId, vt as readAncestry, w as clearOrchestrator, wn as sanitizeLine, x as bindAccountDevice, xn as parseIpcRequest, y as autoLimitsFromEnv, yn as newMessageId, zt as statusAfterLiveness } from "./dist-D2hMvcZu.js";
|
|
5
5
|
import { randomBytes } from "node:crypto";
|
|
6
6
|
import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { connect, createServer } from "node:net";
|
|
8
8
|
import { dirname, join, posix, win32 } from "node:path";
|
|
9
|
-
import { _ as sasMatches, a as JoinerPairing, b as signRelayHello, c as decodePairMessage, d as forkPoint, f as generateIdentity, g as publicRecord, h as parseIdentity, i as InviterPairing, l as deviceFingerprint, m as openEnvelope, n as ENVELOPE_MAX_AGE_MS, o as appendRevoke, p as headMatches, r as ENVELOPE_MAX_FUTURE_MS, s as chainHead, t as CryptoError, u as encodePairMessage, v as sealEnvelope, x as verifyChain, y as serializeIdentity } from "./dist-
|
|
9
|
+
import { _ as sasMatches, a as JoinerPairing, b as signRelayHello, c as decodePairMessage, d as forkPoint, f as generateIdentity, g as publicRecord, h as parseIdentity, i as InviterPairing, l as deviceFingerprint, m as openEnvelope, n as ENVELOPE_MAX_AGE_MS, o as appendRevoke, p as headMatches, r as ENVELOPE_MAX_FUTURE_MS, s as chainHead, t as CryptoError, u as encodePairMessage, v as sealEnvelope, x as verifyChain, y as serializeIdentity } from "./dist-iFaY42Bs.js";
|
|
10
10
|
import { execFileSync } from "node:child_process";
|
|
11
11
|
import { DatabaseSync } from "node:sqlite";
|
|
12
12
|
// ../daemon/src/lifecycle.ts
|
|
@@ -1944,7 +1944,7 @@ var Store = class {
|
|
|
1944
1944
|
}
|
|
1945
1945
|
};
|
|
1946
1946
|
// ../daemon/src/server.ts
|
|
1947
|
-
const DAEMON_VERSION = "0.2.0-rc.
|
|
1947
|
+
const DAEMON_VERSION = "0.2.0-rc.7";
|
|
1948
1948
|
/** A connection that has not finished the handshake by then is closed. */
|
|
1949
1949
|
const AUTH_TIMEOUT_MS = 5e3;
|
|
1950
1950
|
/** Unread messages one session may hold. */
|
|
@@ -1961,6 +1961,8 @@ const HOST_OF_TIMEOUT_MS = 1500;
|
|
|
1961
1961
|
const DAEMON_WAKE_BYTES = 16e3;
|
|
1962
1962
|
/** First wait before a daemon wake is tried again; doubles up to the max. */
|
|
1963
1963
|
const WAKE_RETRY_MS = 15e3;
|
|
1964
|
+
/** A wake still not a turn after this long counts as unread in status (see `stalledWoken`). */
|
|
1965
|
+
const WOKEN_STALL_MS = 3e4;
|
|
1964
1966
|
const WAKE_RETRY_MAX_MS = 3e5;
|
|
1965
1967
|
/** Sender id on `system` messages made by the daemon itself (no session sent them). */
|
|
1966
1968
|
const DAEMON_SENDER_ID = SessionId.parse("0".repeat(26));
|
|
@@ -2005,8 +2007,14 @@ var Daemon = class {
|
|
|
2005
2007
|
wakeRetry = /* @__PURE__ */ new Map();
|
|
2006
2008
|
/** Set when the daemon shuts down: closing connections must not touch the store any more. */
|
|
2007
2009
|
stopping = false;
|
|
2008
|
-
/**
|
|
2010
|
+
/**
|
|
2011
|
+
* Sessions whose daemon waker answered \`unsupported\` (no \`queue\` in that binary, an ephemeral
|
|
2012
|
+
* thread): not asked again for them while the daemon runs, so a new daemon checks afresh. Other
|
|
2013
|
+
* sessions of the same CLI are still woken.
|
|
2014
|
+
*/
|
|
2009
2015
|
wakersOff = /* @__PURE__ */ new Set();
|
|
2016
|
+
/** When each session's last daemon wake was handed over, to tell a wake that never became a turn. */
|
|
2017
|
+
wokenAt = /* @__PURE__ */ new Map();
|
|
2010
2018
|
idleSince;
|
|
2011
2019
|
startedMs;
|
|
2012
2020
|
/** When each session went offline, for the removal grace. In memory only. */
|
|
@@ -2110,7 +2118,7 @@ var Daemon = class {
|
|
|
2110
2118
|
case "session.rename": return this.rename(req.params);
|
|
2111
2119
|
case "session.setStatus": return this.setStatus(req.params);
|
|
2112
2120
|
case "session.list": return this.list(req.params);
|
|
2113
|
-
case "session.byHost": return this.byHost(req.params
|
|
2121
|
+
case "session.byHost": return this.byHost(req.params);
|
|
2114
2122
|
case "session.hostOf": return this.hostOf(req.params);
|
|
2115
2123
|
case "session.setNative": return this.setNative(req.params);
|
|
2116
2124
|
case "turn.start": return this.turnStart(req.params.sessionId);
|
|
@@ -2180,7 +2188,7 @@ var Daemon = class {
|
|
|
2180
2188
|
return toSession({
|
|
2181
2189
|
...row,
|
|
2182
2190
|
deliveryTier: this.tierFor(row)
|
|
2183
|
-
}, holder?.id === row.id, this.store.unreadCount(row.id));
|
|
2191
|
+
}, holder?.id === row.id, this.store.unreadCount(row.id) + this.stalledWoken(row.id));
|
|
2184
2192
|
}
|
|
2185
2193
|
/** The orchestrator as routing sees it: the holder, if it is online. */
|
|
2186
2194
|
orchestratorNow() {
|
|
@@ -2345,15 +2353,29 @@ var Daemon = class {
|
|
|
2345
2353
|
* on Windows), so several folders on one OpenCode 2.x server stay apart. Two sessions in one
|
|
2346
2354
|
* folder still match nothing.
|
|
2347
2355
|
*/
|
|
2348
|
-
byHost(
|
|
2356
|
+
byHost(p) {
|
|
2357
|
+
const { pid, cwd, nativeId } = p;
|
|
2358
|
+
const rows = this.store.allSessions().filter((r) => p.includeOffline || r.status !== "offline");
|
|
2359
|
+
const live = (list) => {
|
|
2360
|
+
const online = list.filter((r) => r.status !== "offline");
|
|
2361
|
+
return online.length > 0 ? online : list;
|
|
2362
|
+
};
|
|
2349
2363
|
if (nativeId !== void 0) {
|
|
2350
|
-
const own =
|
|
2351
|
-
return { session:
|
|
2352
|
-
|
|
2353
|
-
|
|
2364
|
+
const own = live(rows.filter((r) => r.nativeId === nativeId))[0];
|
|
2365
|
+
if (!own) return { session: null };
|
|
2366
|
+
const pids = [...own.hostPid === void 0 ? [] : [own.hostPid], ...own.hostPids ?? []];
|
|
2367
|
+
if (pids.length === 0 || pids.includes(pid)) return { session: this.view(own) };
|
|
2368
|
+
const mine = this.pidHolders(rows, pid, cwd, live);
|
|
2369
|
+
return { session: this.view(mine.length === 1 ? mine[0] : own) };
|
|
2370
|
+
}
|
|
2371
|
+
const holders = this.pidHolders(rows, pid, cwd, live);
|
|
2354
2372
|
const only = holders.length === 1 ? holders[0] : void 0;
|
|
2355
2373
|
return { session: only ? this.view(only) : null };
|
|
2356
2374
|
}
|
|
2375
|
+
/** Sessions whose host is `pid` (in `cwd`, when given), online ones first. */
|
|
2376
|
+
pidHolders(rows, pid, cwd, live) {
|
|
2377
|
+
return live(rows.filter((r) => r.hostPid === pid && (cwd === void 0 || samePath(r.cwd, cwd, this.platform))));
|
|
2378
|
+
}
|
|
2357
2379
|
/**
|
|
2358
2380
|
* Walk up from a hook's parent pid to its host CLI, for a hook that would otherwise read the
|
|
2359
2381
|
* process table itself. With no online session of the hook's CLI there is nothing the hook could
|
|
@@ -2410,6 +2432,8 @@ var Daemon = class {
|
|
|
2410
2432
|
for (const r of gone) {
|
|
2411
2433
|
this.listeners.delete(r.id);
|
|
2412
2434
|
this.woken.delete(r.id);
|
|
2435
|
+
this.wokenAt.delete(r.id);
|
|
2436
|
+
this.wakersOff.delete(r.id);
|
|
2413
2437
|
this.offlineSince.delete(r.id);
|
|
2414
2438
|
}
|
|
2415
2439
|
}
|
|
@@ -2596,7 +2620,7 @@ var Daemon = class {
|
|
|
2596
2620
|
}
|
|
2597
2621
|
}
|
|
2598
2622
|
daemonWakerFor(row) {
|
|
2599
|
-
if (row.nativeId === void 0 || this.wakersOff.has(row.
|
|
2623
|
+
if (row.nativeId === void 0 || this.wakersOff.has(row.id)) return void 0;
|
|
2600
2624
|
return this.wakers[row.cli];
|
|
2601
2625
|
}
|
|
2602
2626
|
/**
|
|
@@ -2646,7 +2670,7 @@ var Daemon = class {
|
|
|
2646
2670
|
}
|
|
2647
2671
|
if (outcome === "unsupported") {
|
|
2648
2672
|
this.wakeRetry.delete(id);
|
|
2649
|
-
this.wakersOff.add(row.
|
|
2673
|
+
this.wakersOff.add(row.id);
|
|
2650
2674
|
this.relay?.sessionsChanged();
|
|
2651
2675
|
}
|
|
2652
2676
|
if (this.store.getSession(id)?.status === "offline") {
|
|
@@ -2671,6 +2695,17 @@ var Daemon = class {
|
|
|
2671
2695
|
}
|
|
2672
2696
|
markWoken(id, messages) {
|
|
2673
2697
|
this.woken.set(id, new Set(messages.map((m) => m.id)));
|
|
2698
|
+
this.wokenAt.set(id, this.now().getTime());
|
|
2699
|
+
}
|
|
2700
|
+
/**
|
|
2701
|
+
* Messages a wake handed over that no turn took up: the CLI accepted them but the turn never
|
|
2702
|
+
* started (Codex keeps queued input while a turn is interrupted). Counted as unread so status
|
|
2703
|
+
* shows them. A turn start or end clears \`woken\`.
|
|
2704
|
+
*/
|
|
2705
|
+
stalledWoken(id) {
|
|
2706
|
+
const at = this.wokenAt.get(id);
|
|
2707
|
+
if (at === void 0 || this.now().getTime() - at < WOKEN_STALL_MS) return 0;
|
|
2708
|
+
return this.woken.get(id)?.size ?? 0;
|
|
2674
2709
|
}
|
|
2675
2710
|
/**
|
|
2676
2711
|
* Delivered messages go back to queued. When they are from the last wake and that wake made the
|
|
@@ -2722,7 +2757,7 @@ var Daemon = class {
|
|
|
2722
2757
|
* On a hand-over the session is busy and its turn carries the hops. With `endOfTurn`, nothing
|
|
2723
2758
|
* handed over means the session is now idle. One transaction.
|
|
2724
2759
|
*/
|
|
2725
|
-
continueWith(row, allow, endOfTurn, maxBytes = RESPONSE_BUDGET_BYTES) {
|
|
2760
|
+
continueWith(row, allow, endOfTurn, maxBytes = RESPONSE_BUDGET_BYTES, maxChars) {
|
|
2726
2761
|
const nowMs = this.now().getTime();
|
|
2727
2762
|
const at = this.iso();
|
|
2728
2763
|
const orchestrator = this.orchestratorNow();
|
|
@@ -2731,14 +2766,19 @@ var Daemon = class {
|
|
|
2731
2766
|
const candidates = allow ? autoCandidates(queued, row.id) : [];
|
|
2732
2767
|
const decision = decideAutoContinue({ runs: row.autoRuns }, candidates, nowMs, this.autoLimits);
|
|
2733
2768
|
if (decision.continue) {
|
|
2734
|
-
const
|
|
2769
|
+
const fit = takeWithinBytes(candidates.slice(0, 20), maxBytes);
|
|
2770
|
+
const { taken, preview } = maxChars === void 0 ? { taken: fit } : takeWithinChars(fit, maxChars, (ms, cut) => formatContinuation(ms, orchestrator, queued.length - (cut ? 0 : ms.length)));
|
|
2735
2771
|
const updated = markDelivered(taken, taken.map((e) => e.message.id), at);
|
|
2736
2772
|
for (const e of updated) this.store.saveEntry(row.id, e);
|
|
2737
2773
|
this.store.updateSession(row.id, {
|
|
2738
2774
|
status: "busy",
|
|
2739
2775
|
autoRuns: decision.runs,
|
|
2740
|
-
turnHops: turnHops(taken)
|
|
2776
|
+
turnHops: turnHops(preview ? fit.slice(0, 1) : taken)
|
|
2741
2777
|
});
|
|
2778
|
+
if (preview) return {
|
|
2779
|
+
messages: [preview],
|
|
2780
|
+
remaining: queued.length
|
|
2781
|
+
};
|
|
2742
2782
|
return {
|
|
2743
2783
|
messages: updated.map((e) => e.message),
|
|
2744
2784
|
remaining: queued.length - taken.length
|
|
@@ -2763,7 +2803,7 @@ var Daemon = class {
|
|
|
2763
2803
|
const row = this.requireOnline(p.sessionId);
|
|
2764
2804
|
this.woken.delete(p.sessionId);
|
|
2765
2805
|
if (row.status === "waiting_on_question") return this.continueWith(row, false, false);
|
|
2766
|
-
return this.continueWith(row, p.allowContinue, true);
|
|
2806
|
+
return this.continueWith(row, p.allowContinue, true, RESPONSE_BUDGET_BYTES, p.maxChars);
|
|
2767
2807
|
}
|
|
2768
2808
|
/**
|
|
2769
2809
|
* An idle-wake listener asks for work. The newest listener of a session wins: an older one gets
|
|
@@ -2795,7 +2835,7 @@ var Daemon = class {
|
|
|
2795
2835
|
}, row.id);
|
|
2796
2836
|
} else known.conn = conn;
|
|
2797
2837
|
if (!wasConnected) this.relay?.sessionsChanged();
|
|
2798
|
-
const d = this.continueWith(row, row.status === "idle", false);
|
|
2838
|
+
const d = this.continueWith(row, row.status === "idle", false, RESPONSE_BUDGET_BYTES, p.maxChars);
|
|
2799
2839
|
if (d.messages.length > 0) this.markWoken(row.id, d.messages);
|
|
2800
2840
|
return {
|
|
2801
2841
|
...d,
|
|
@@ -2829,9 +2869,14 @@ var Daemon = class {
|
|
|
2829
2869
|
const at = this.iso();
|
|
2830
2870
|
return this.store.tx(() => {
|
|
2831
2871
|
const pending = pendingForInjection(this.store.entries(p.sessionId, { states: ["queued"] }));
|
|
2832
|
-
const
|
|
2872
|
+
const fit = takeWithinBytes(pending.slice(0, p.limit), RESPONSE_BUDGET_BYTES);
|
|
2873
|
+
const { taken, preview } = p.maxChars === void 0 ? { taken: fit } : takeWithinChars(fit, p.maxChars, (ms) => formatHookContext(ms));
|
|
2833
2874
|
const updated = markDelivered(taken, taken.map((e) => e.message.id), at);
|
|
2834
2875
|
for (const e of updated) this.store.saveEntry(p.sessionId, e);
|
|
2876
|
+
if (preview) return {
|
|
2877
|
+
messages: [preview],
|
|
2878
|
+
remaining: pending.length
|
|
2879
|
+
};
|
|
2835
2880
|
return {
|
|
2836
2881
|
messages: updated.map((e) => e.message),
|
|
2837
2882
|
remaining: pending.length - taken.length
|