@conveno/cli 0.2.0-rc.13 → 0.2.0-rc.14
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 +1 -1
- package/dist/{acp-Bs6XS61j.js → acp-OHqthTVC.js} +3 -3
- package/dist/{agy-relay-BJLRYbFp.js → agy-relay-DLP2H1Rj.js} +2 -2
- package/dist/{args-C4rVCVXx.js → args-DmUsbNu9.js} +12 -6
- package/dist/bin.js +2 -2
- package/dist/daemon.js +109 -10
- package/dist/{daemonError-CjxG2yUl.js → daemonError-CUE_dVn-.js} +1 -1
- package/dist/{dist-DnNuDzEA.js → dist-1k5b8UGF.js} +184 -75
- package/dist/{dist-Ca3P7aN-.js → dist-BYkDv29h.js} +9 -5
- package/dist/{dist-BkhKEexU.js → dist-BiV6HopA.js} +140 -17
- package/dist/{dist-CoRBNycn.js → dist-C4Ey9THP.js} +1 -1
- package/dist/{dist-C9Z1EMlM.js → dist-Cv5et1iE.js} +1 -1
- package/dist/{dist-B14ldKRS.js → dist-D-PhGsuL.js} +1 -1
- package/dist/{dist-D4sb5RQD.js → dist-vefQHFb-.js} +1 -1
- package/dist/{hook-entry-WlJSM5aD.js → hook-entry-Cxh3yIdT.js} +6 -6
- package/dist/hook-entry-De06GWme.js +1 -0
- package/dist/{hook-C60hXJdg.js → hook-mvifUk0K.js} +1 -1
- package/dist/{main-I2RMN7XN.js → main-BY7Kcf9S.js} +36 -59
- package/dist/{pick-Colav8Wm.js → pick-ClIK4l8K.js} +1 -1
- package/dist/{run-BuDbmxx_.js → run-BYmOjvDF.js} +276 -18
- package/dist/{runtime-CPmrhPFJ.js → runtime-PeEPWwix.js} +37 -12
- package/dist/{uninstall-812XZDTG.js → uninstall-CQoGVhp3.js} +80 -8
- package/dist/{watch-DXbOOc20.js → watch-CaC2G2cT.js} +4 -4
- package/package.json +13 -13
- package/dist/hook-entry-jOfjq-0A.js +0 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ Or run `conveno` with no arguments. It opens a full-screen app (Sessions, New, D
|
|
|
39
39
|
| `conveno send <to> <text...> [--urgent]` | Send a message as you to a session name or id, `lead`, or `device:name`. `-` reads the text from standard input. |
|
|
40
40
|
| `conveno rename <session> <new-name>` | Rename an online session. |
|
|
41
41
|
| `conveno lead <session>` | Make a session the lead. `conveno lead --clear` leaves no lead. |
|
|
42
|
-
| `conveno spawn <cli> [--cwd <dir>] [--name <name>] [--task <text> \| --task-file <path>] [--window] [--
|
|
42
|
+
| `conveno spawn <cli> [--cwd <dir>] [--name <name>] [--task <text> \| --task-file <path>] [--window] [--access <read\|edit\|full>] [--yes]` | Start a worker session of `claude`, `codex`, `opencode`, `antigravity` or `grok`, and print its name once it registers. The CLI must be installed. By default the worker runs in the background through the CLI's Agent Client Protocol server, with `conveno acp-host` driving it. It keeps running: each message sent to it becomes its next prompt at once when it is idle, or when its current turn ends. `--window` opens the real CLI in a new terminal instead, so you can watch it and take over: Windows Terminal (`wt -w 0 new-tab`, else a new console window) on Windows, Terminal.app (iTerm2 when it is your terminal) on macOS, and on Linux a new tmux window when you are inside tmux, else the first of `x-terminal-emulator`, `gnome-terminal`, `konsole`, `kitty`, `wezterm`, `alacritty` and `xterm`. The ACP commands are `claude-agent-acp` (install `@agentclientprotocol/claude-agent-acp`), `codex-acp` (install `@agentclientprotocol/codex-acp`), `opencode acp`, `agy acp` and `grok agent stdio`; a missing one is an error that says what to install. For Claude Code and Codex, `conveno init` can allow running the adapter with `npx -y <package>@<pinned version>`, and `CONVENO_ACP_CODEX_CMD` / `CONVENO_ACP_CLAUDE_CMD` replace the command. In the background a tool call the `--access` preset (`read`, `edit` or `full`; default `edit`) does not cover is asked of the session that spawned the worker. The first task is optional. `--name` sets the session name (a taken or reserved one is refused); otherwise the usual `<cli>@<repo>-<n>` name is used. `--cwd` defaults to the current folder, which must be inside your home folder; an explicit `--cwd` can be anywhere. It asks first and `--yes` skips the question; without a terminal it exits 2 unless `--yes` is given. At most 8 spawned sessions run at once (`CONVENO_SPAWN_MAX` changes that), and a spawned session cannot spawn more than 3 levels deep. A task is at most 16000 characters. See `packages/protocol/PROTOCOL.md`. |
|
|
43
43
|
| `conveno stop <worker>` | Stop a background worker. It cancels a running turn, ends its CLI and the processes it started, tells the spawning session why, and goes offline. A worker in a window is yours to close. |
|
|
44
44
|
| `conveno doctor [--cli <list>]` | Check each CLI and the daemon, and say how to fix what is wrong. `--cli claude,codex` checks only those CLIs, so problems in the others do not count. |
|
|
45
45
|
| `conveno devices [pair\|join\|revoke\|rename\|accept\|reset]` | Pro. List your devices, or pair a new machine: `pair` on one device and `join` on the new one at the same time, then type the 8-digit code each screen shows. `revoke` removes a device for good. Needs a Pro login on both. |
|
|
@@ -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 { a as parseFlags, n as COMMANDS } from "./args-
|
|
2
|
+
import { n as runAcpHostFromFile, r as stopRequestPath, t as killProcessTree } from "./dist-BiV6HopA.js";
|
|
3
|
+
import { Kt as readSpawnRecord, an as spawnRecordPath } from "./dist-1k5b8UGF.js";
|
|
4
|
+
import { a as parseFlags, n as COMMANDS } from "./args-DmUsbNu9.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. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import { t as RELAY_SUBCOMMAND } from "./dist-
|
|
3
|
-
import {
|
|
2
|
+
import { t as RELAY_SUBCOMMAND } from "./dist-vefQHFb-.js";
|
|
3
|
+
import { nn as runWaker } from "./dist-1k5b8UGF.js";
|
|
4
4
|
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
5
5
|
// src/agy-relay.ts
|
|
6
6
|
/**
|
|
@@ -33,7 +33,7 @@ const SETUP_FLAGS = {
|
|
|
33
33
|
const COMMANDS = [
|
|
34
34
|
{
|
|
35
35
|
name: "setup",
|
|
36
|
-
usage: "conveno setup [--yes] [--dry-run] [--cli <list>] [--lead <cli>]",
|
|
36
|
+
usage: "conveno setup [--yes] [--dry-run] [--cli <list>] [--lead <cli>] [--worker-access <level>]",
|
|
37
37
|
summary: "Connect Conveno to your AI tools",
|
|
38
38
|
flags: {
|
|
39
39
|
...SETUP_FLAGS,
|
|
@@ -41,6 +41,11 @@ const COMMANDS = [
|
|
|
41
41
|
type: "string",
|
|
42
42
|
value: "<cli>",
|
|
43
43
|
help: "The AI tool that should lead when it starts, such as claude"
|
|
44
|
+
},
|
|
45
|
+
"worker-access": {
|
|
46
|
+
type: "string",
|
|
47
|
+
value: "<read|edit|full>",
|
|
48
|
+
help: "What background workers may do: read, edit (the default) or full"
|
|
44
49
|
}
|
|
45
50
|
},
|
|
46
51
|
notes: [
|
|
@@ -153,10 +158,10 @@ const COMMANDS = [
|
|
|
153
158
|
type: "boolean",
|
|
154
159
|
help: "Open the CLI in a terminal window you can watch, instead of the background"
|
|
155
160
|
},
|
|
156
|
-
|
|
161
|
+
access: {
|
|
157
162
|
type: "string",
|
|
158
|
-
value: "<
|
|
159
|
-
help: "Background:
|
|
163
|
+
value: "<read|edit|full>",
|
|
164
|
+
help: "Background: what the worker may do without asking (default: edit)"
|
|
160
165
|
},
|
|
161
166
|
yes: {
|
|
162
167
|
type: "boolean",
|
|
@@ -165,11 +170,12 @@ const COMMANDS = [
|
|
|
165
170
|
}
|
|
166
171
|
},
|
|
167
172
|
notes: [
|
|
173
|
+
"--access sets what a background worker may do without asking: read (look only), edit (also",
|
|
174
|
+
"change files and fetch pages; the default) or full (everything).",
|
|
168
175
|
"By default the worker runs in the background over ACP and stays alive. Each message sent to",
|
|
169
176
|
"it becomes its next prompt: right away when it is idle, else when its turn ends.",
|
|
170
177
|
"--window opens the real CLI in a new terminal instead, so you can watch it and take over.",
|
|
171
|
-
"In the background, tool calls
|
|
172
|
-
"Example: --allow read,search (also --allow read search, or --allow read --allow search).",
|
|
178
|
+
"In the background, tool calls the preset does not cover are denied.",
|
|
173
179
|
"Conveno's own tools, such as send, are always allowed.",
|
|
174
180
|
"claude and codex need an ACP adapter installed. End a worker with conveno stop.",
|
|
175
181
|
"Waits until the session registers, then prints its name.",
|
package/dist/bin.js
CHANGED
|
@@ -40,9 +40,9 @@ for (const stream of [process.stdout, process.stderr]) stream.on("error", (err)
|
|
|
40
40
|
});
|
|
41
41
|
try {
|
|
42
42
|
let code;
|
|
43
|
-
if (isHook) code = await (await import("./hook-entry-
|
|
43
|
+
if (isHook) code = await (await import("./hook-entry-De06GWme.js")).runHookEntry(argv.slice(1));
|
|
44
44
|
else {
|
|
45
|
-
const [{ main }, { createRuntimeCtx }] = await Promise.all([import("./main-
|
|
45
|
+
const [{ main }, { createRuntimeCtx }] = await Promise.all([import("./main-BY7Kcf9S.js"), import("./runtime-PeEPWwix.js")]);
|
|
46
46
|
code = await main(argv, createRuntimeCtx());
|
|
47
47
|
}
|
|
48
48
|
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 {
|
|
3
|
+
import { t as codexAdapter } from "./dist-Cv5et1iE.js";
|
|
4
|
+
import { $ as formatContinuation, $n as sanitizeLine, $t as resolveRecipient, A as claimOrchestrator, B as dataDir, Bn as defaultSocketPath, Bt as readAccountTokens, Ct as oneWindowPerHost, D as autoLimitsFromEnv, E as autoCandidates, En as EVENT_NAMES, Gn as makeEventNotification, Gt as readSettings, H as decideAutoContinue, In as SESSION_ENDED_TEXT, It as planSpawn, Jn as newMessageId, Kn as makeResult, L as createWmiWalker, M as clearOrchestrator, Mn as PROTOCOL_VERSION, N as clientProof, Nn as RelayPayload, O as baseName, Pn as RpcErrorCode, Qn as safeParse, R as currentAccessToken, Rn as SessionId, Rt as proofsMatch, S as appendHookLog, St as newAuthNonce, Tn as DeviceId, U as defaultProcessIo, Un as isSocketPathTooLong, Ut as readInbox, V as dataPaths, Vn as encodeFrame, Vt as readAncestry, W as detectRepo, Wn as makeError, Xn as parseIpcRequest, Xt as requeueEntries, Y as evaluateLiveness, Yn as newSessionId, Zn as parseRelayFrame, _ as ackEntries, _t as leadLogPath, bt as markDelivered, cn as statusAfterLiveness, dn as takeWithinChars, dt as isOnline, er as socketPathTooLongMessage, et as formatHookContext, fn as tooManyUnreadMessage, ft as jwtClaim, gn as validateRename, gt as leadLogLine, i as ConvenoError, jn as OWNER_SESSION_ID, k as bindAccountDevice, kn as Message, kt as pendingForInjection, l as RESPONSE_BUDGET_BYTES, n as AccountError, nt as generateSessionName, pn as turnHops, q as effectiveHolder, qn as newDeviceId, rt as holderAfterDeparture, un as takeWithinBytes, z as daemonProof, zn as createLineDecoder } from "./dist-1k5b8UGF.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-C4Ey9THP.js";
|
|
10
10
|
import { execFileSync } from "node:child_process";
|
|
11
11
|
import { DatabaseSync } from "node:sqlite";
|
|
12
12
|
// ../daemon/src/lifecycle.ts
|
|
@@ -1970,7 +1970,7 @@ var Store = class {
|
|
|
1970
1970
|
}
|
|
1971
1971
|
};
|
|
1972
1972
|
// ../daemon/src/server.ts
|
|
1973
|
-
const DAEMON_VERSION = "0.2.0-rc.
|
|
1973
|
+
const DAEMON_VERSION = "0.2.0-rc.14";
|
|
1974
1974
|
/** A connection that has not finished the handshake by then is closed. */
|
|
1975
1975
|
const AUTH_TIMEOUT_MS = 5e3;
|
|
1976
1976
|
/** Unread messages one session may hold. */
|
|
@@ -1991,6 +1991,8 @@ const WAKE_RETRY_MS = 15e3;
|
|
|
1991
1991
|
const WOKEN_STALL_MS = 3e4;
|
|
1992
1992
|
const WAKE_RETRY_MAX_MS = 3e5;
|
|
1993
1993
|
/** Sender id on `system` messages made by the daemon itself (no session sent them). */
|
|
1994
|
+
/** Permission requests one worker may have waiting at once. */
|
|
1995
|
+
const MAX_ASKS_PER_WORKER = 5;
|
|
1994
1996
|
const DAEMON_SENDER_ID = SessionId.parse("0".repeat(26));
|
|
1995
1997
|
const CLI_TIER = {
|
|
1996
1998
|
claude: "next_turn",
|
|
@@ -2012,6 +2014,7 @@ var Daemon = class {
|
|
|
2012
2014
|
platform;
|
|
2013
2015
|
wakers;
|
|
2014
2016
|
settingsPath;
|
|
2017
|
+
leadLog;
|
|
2015
2018
|
conns = /* @__PURE__ */ new Set();
|
|
2016
2019
|
/** Reaches the owner's other devices; set by startDaemon unless disabled. */
|
|
2017
2020
|
relay;
|
|
@@ -2042,6 +2045,8 @@ var Daemon = class {
|
|
|
2042
2045
|
wokenAt = /* @__PURE__ */ new Map();
|
|
2043
2046
|
idleSince;
|
|
2044
2047
|
startedMs;
|
|
2048
|
+
/** Permission requests of workers that wait for their spawner, by request id. In memory only. */
|
|
2049
|
+
asks = /* @__PURE__ */ new Map();
|
|
2045
2050
|
/** When each session went offline, for the removal grace. In memory only. */
|
|
2046
2051
|
offlineSince = /* @__PURE__ */ new Map();
|
|
2047
2052
|
/**
|
|
@@ -2057,7 +2062,7 @@ var Daemon = class {
|
|
|
2057
2062
|
* Their heartbeats are refused, so a leftover MCP process cannot bring them back online.
|
|
2058
2063
|
*/
|
|
2059
2064
|
retired = /* @__PURE__ */ new Set();
|
|
2060
|
-
constructor(store, token, now, isAlive, idleExitMs, requestIdleExit, requestShutdown, log, authTimeoutMs = AUTH_TIMEOUT_MS, autoLimits = autoLimitsFromEnv({}), processIo = defaultProcessIo, platform = process.platform, wakers = {}, settingsPath) {
|
|
2065
|
+
constructor(store, token, now, isAlive, idleExitMs, requestIdleExit, requestShutdown, log, authTimeoutMs = AUTH_TIMEOUT_MS, autoLimits = autoLimitsFromEnv({}), processIo = defaultProcessIo, platform = process.platform, wakers = {}, settingsPath, leadLog) {
|
|
2061
2066
|
this.store = store;
|
|
2062
2067
|
this.token = token;
|
|
2063
2068
|
this.now = now;
|
|
@@ -2072,6 +2077,7 @@ var Daemon = class {
|
|
|
2072
2077
|
this.platform = platform;
|
|
2073
2078
|
this.wakers = wakers;
|
|
2074
2079
|
this.settingsPath = settingsPath;
|
|
2080
|
+
this.leadLog = leadLog;
|
|
2075
2081
|
this.deviceId = store.deviceId();
|
|
2076
2082
|
this.startedMs = now().getTime();
|
|
2077
2083
|
this.idleSince = this.startedMs;
|
|
@@ -2167,8 +2173,10 @@ var Daemon = class {
|
|
|
2167
2173
|
case "turn.end": return this.turnEnd(req.params);
|
|
2168
2174
|
case "turn.wake": return this.turnWake(conn, req.params);
|
|
2169
2175
|
case "daemon.shutdown": return { ok: true };
|
|
2170
|
-
case "orchestrator.claim": return this.claim(req.params.sessionId);
|
|
2176
|
+
case "orchestrator.claim": return this.claim(req.params.sessionId, req.params.via ?? "unknown");
|
|
2171
2177
|
case "orchestrator.clear": return this.clearLead(conn);
|
|
2178
|
+
case "permission.ask": return this.permissionAsk(req.params);
|
|
2179
|
+
case "permission.answer": return this.permissionAnswer(req.params);
|
|
2172
2180
|
case "message.send": return this.sendMessage(req.params);
|
|
2173
2181
|
case "owner.send": return this.ownerSend(conn, req.params);
|
|
2174
2182
|
case "message.inbox": return this.inbox(req.params);
|
|
@@ -2351,7 +2359,7 @@ var Daemon = class {
|
|
|
2351
2359
|
if (settings.leadCli !== row.cli) return;
|
|
2352
2360
|
if (settings.tools && !settings.tools.includes(row.cli)) return;
|
|
2353
2361
|
if (this.orchestratorNow() !== null) return;
|
|
2354
|
-
this.claim(row.id);
|
|
2362
|
+
this.claim(row.id, "preferred");
|
|
2355
2363
|
}
|
|
2356
2364
|
async registerAsync(p) {
|
|
2357
2365
|
return this.register(p, await this.detect(p));
|
|
@@ -2379,14 +2387,17 @@ var Daemon = class {
|
|
|
2379
2387
|
depart(sessionId, change) {
|
|
2380
2388
|
const before = this.store.holder();
|
|
2381
2389
|
const after = holderAfterDeparture(before, sessionId);
|
|
2390
|
+
const prevName = this.leadName(before);
|
|
2382
2391
|
this.store.tx(() => {
|
|
2383
2392
|
this.store.updateSession(sessionId, { status: "offline" });
|
|
2384
2393
|
if (after !== before) this.store.setHolder(after);
|
|
2385
2394
|
});
|
|
2395
|
+
this.logLead(prevName, before, after, "departed");
|
|
2386
2396
|
this.listeners.delete(sessionId);
|
|
2387
2397
|
this.woken.delete(sessionId);
|
|
2388
2398
|
this.attached.delete(sessionId);
|
|
2389
2399
|
this.hookAt.delete(sessionId);
|
|
2400
|
+
this.settleAsksOf(sessionId);
|
|
2390
2401
|
this.offlineSince.set(sessionId, this.now().getTime());
|
|
2391
2402
|
this.emitSession(sessionId, change);
|
|
2392
2403
|
if (after !== before) this.emit({
|
|
@@ -2428,10 +2439,12 @@ var Daemon = class {
|
|
|
2428
2439
|
};
|
|
2429
2440
|
const before = this.store.holder();
|
|
2430
2441
|
const after = holderAfterDeparture(before, sessionId);
|
|
2442
|
+
const prevName = this.leadName(before);
|
|
2431
2443
|
this.store.tx(() => {
|
|
2432
2444
|
if (after !== before) this.store.setHolder(after);
|
|
2433
2445
|
this.store.deleteSession(sessionId);
|
|
2434
2446
|
});
|
|
2447
|
+
this.logLead(prevName, before, after, "removed");
|
|
2435
2448
|
this.listeners.delete(sessionId);
|
|
2436
2449
|
this.woken.delete(sessionId);
|
|
2437
2450
|
this.wokenAt.delete(sessionId);
|
|
@@ -2439,6 +2452,7 @@ var Daemon = class {
|
|
|
2439
2452
|
this.offlineSince.delete(sessionId);
|
|
2440
2453
|
this.attached.delete(sessionId);
|
|
2441
2454
|
this.hookAt.delete(sessionId);
|
|
2455
|
+
this.settleAsksOf(sessionId);
|
|
2442
2456
|
this.emit({
|
|
2443
2457
|
event: "session.updated",
|
|
2444
2458
|
data: {
|
|
@@ -2694,13 +2708,16 @@ var Daemon = class {
|
|
|
2694
2708
|
const pids = this.attachedOf(into);
|
|
2695
2709
|
for (const q of this.attachedOf(from)) pids.add(q);
|
|
2696
2710
|
if (pid !== void 0) pids.add(pid);
|
|
2697
|
-
const
|
|
2711
|
+
const before = this.store.holder();
|
|
2712
|
+
const lead = before === from.id;
|
|
2713
|
+
const prevName = this.leadName(before);
|
|
2698
2714
|
this.store.tx(() => {
|
|
2699
2715
|
this.store.moveMailbox(from.id, into.id);
|
|
2700
2716
|
if (lead) this.store.setHolder(into.id);
|
|
2701
2717
|
this.store.updateSession(into.id, { lastSeenAt: this.iso() });
|
|
2702
2718
|
this.store.deleteSession(from.id);
|
|
2703
2719
|
});
|
|
2720
|
+
if (lead) this.logLead(prevName, before, into.id, "merged");
|
|
2704
2721
|
this.listeners.delete(from.id);
|
|
2705
2722
|
this.woken.delete(from.id);
|
|
2706
2723
|
this.attached.delete(from.id);
|
|
@@ -2740,11 +2757,27 @@ var Daemon = class {
|
|
|
2740
2757
|
this.hookAt.delete(r.id);
|
|
2741
2758
|
}
|
|
2742
2759
|
}
|
|
2743
|
-
|
|
2760
|
+
leadName(id) {
|
|
2761
|
+
return id ? this.store.getSession(id)?.name ?? null : null;
|
|
2762
|
+
}
|
|
2763
|
+
/** One line in `<dataDir>/logs/lead.log` when the holder changed. Never throws. */
|
|
2764
|
+
logLead(previous, before, after, via) {
|
|
2765
|
+
if (before === after || !this.leadLog) return;
|
|
2766
|
+
try {
|
|
2767
|
+
appendHookLog(this.leadLog, leadLogLine({
|
|
2768
|
+
at: this.now(),
|
|
2769
|
+
lead: this.leadName(after),
|
|
2770
|
+
previous,
|
|
2771
|
+
via
|
|
2772
|
+
}));
|
|
2773
|
+
} catch {}
|
|
2774
|
+
}
|
|
2775
|
+
claim(sessionId, via) {
|
|
2744
2776
|
this.requireSession(sessionId);
|
|
2745
2777
|
const rows = this.store.allSessions();
|
|
2746
2778
|
const holder = this.store.holder();
|
|
2747
2779
|
const res = claimOrchestrator(holder, sessionId, this.named(rows));
|
|
2780
|
+
const prevName = this.leadName(holder);
|
|
2748
2781
|
const at = this.iso();
|
|
2749
2782
|
const sent = [];
|
|
2750
2783
|
this.store.tx(() => {
|
|
@@ -2766,6 +2799,7 @@ var Daemon = class {
|
|
|
2766
2799
|
sent.push(m);
|
|
2767
2800
|
}
|
|
2768
2801
|
});
|
|
2802
|
+
this.logLead(prevName, holder, res.orchestrator, via);
|
|
2769
2803
|
if (res.notices.length > 0) {
|
|
2770
2804
|
this.emit({
|
|
2771
2805
|
event: "orchestrator.changed",
|
|
@@ -2783,10 +2817,74 @@ var Daemon = class {
|
|
|
2783
2817
|
previous: res.previous
|
|
2784
2818
|
};
|
|
2785
2819
|
}
|
|
2820
|
+
/**
|
|
2821
|
+
* A worker asks its spawner to allow a tool call. Resolves when the spawner answers, when
|
|
2822
|
+
* `timeoutMs` passes, or when the worker goes away. The request lives in memory only.
|
|
2823
|
+
*/
|
|
2824
|
+
permissionAsk(p) {
|
|
2825
|
+
const worker = this.requireOnline(p.sessionId);
|
|
2826
|
+
const spawner = worker.spawnedBy ? this.store.getSession(worker.spawnedBy) : void 0;
|
|
2827
|
+
if (!spawner || spawner.status === "offline") return Promise.resolve({ answer: "no_spawner" });
|
|
2828
|
+
let mine = 0;
|
|
2829
|
+
for (const a of this.asks.values()) if (a.worker === worker.id) mine++;
|
|
2830
|
+
if (mine >= MAX_ASKS_PER_WORKER) throw new ConvenoError(RpcErrorCode.LimitExceeded, `Session "${worker.name}" already has ${mine} permission requests waiting. Wait for an answer.`);
|
|
2831
|
+
let id = randomBytes(4).toString("base64url").slice(0, 6);
|
|
2832
|
+
while (this.asks.has(id)) id = randomBytes(4).toString("base64url").slice(0, 6);
|
|
2833
|
+
const what = `${p.title ?? "a tool call"} (${p.kind ?? "other"})`;
|
|
2834
|
+
const fallback = p.unanswered === "allow" ? "allow" : "deny";
|
|
2835
|
+
const at = this.iso();
|
|
2836
|
+
const m = {
|
|
2837
|
+
id: newMessageId(),
|
|
2838
|
+
from: DAEMON_SENDER_ID,
|
|
2839
|
+
to: spawner.id,
|
|
2840
|
+
kind: "system",
|
|
2841
|
+
body: {
|
|
2842
|
+
event: "permission.asked",
|
|
2843
|
+
detail: `${worker.name} wants to run: ${what}. Answer with the answer_permission tool: request ${id}, answer allow, always or deny. No answer in ${p.timeoutMs >= 6e4 && p.timeoutMs % 6e4 === 0 ? `${p.timeoutMs / 6e4} min` : `${Math.round(p.timeoutMs / 1e3)} s`}: ${fallback}.`
|
|
2844
|
+
},
|
|
2845
|
+
urgent: false,
|
|
2846
|
+
createdAt: at
|
|
2847
|
+
};
|
|
2848
|
+
this.store.insertMessage(m, spawner.id, at);
|
|
2849
|
+
this.emitMessage(m, spawner.id);
|
|
2850
|
+
return new Promise((resolve) => {
|
|
2851
|
+
const timer = setTimeout(() => this.settleAsk(id, { answer: "unanswered" }), p.timeoutMs);
|
|
2852
|
+
timer.unref();
|
|
2853
|
+
this.asks.set(id, {
|
|
2854
|
+
worker: worker.id,
|
|
2855
|
+
spawner: spawner.id,
|
|
2856
|
+
resolve,
|
|
2857
|
+
timer
|
|
2858
|
+
});
|
|
2859
|
+
});
|
|
2860
|
+
}
|
|
2861
|
+
permissionAnswer(p) {
|
|
2862
|
+
this.requireOnline(p.sessionId);
|
|
2863
|
+
const ask = this.asks.get(p.requestId);
|
|
2864
|
+
if (!ask) throw new ConvenoError(RpcErrorCode.NotFound, `No permission request "${p.requestId}". It was already answered, or it expired.`);
|
|
2865
|
+
if (ask.spawner !== p.sessionId) throw new ConvenoError(RpcErrorCode.PermissionRequired, `Only the session that spawned the worker can answer request "${p.requestId}".`);
|
|
2866
|
+
this.settleAsk(p.requestId, {
|
|
2867
|
+
answer: p.answer,
|
|
2868
|
+
by: p.sessionId
|
|
2869
|
+
});
|
|
2870
|
+
return { ok: true };
|
|
2871
|
+
}
|
|
2872
|
+
settleAsk(id, result) {
|
|
2873
|
+
const ask = this.asks.get(id);
|
|
2874
|
+
if (!ask) return;
|
|
2875
|
+
this.asks.delete(id);
|
|
2876
|
+
clearTimeout(ask.timer);
|
|
2877
|
+
ask.resolve(result);
|
|
2878
|
+
}
|
|
2879
|
+
/** The worker left: its waiting requests end as unanswered. */
|
|
2880
|
+
settleAsksOf(worker) {
|
|
2881
|
+
for (const [id, a] of this.asks) if (a.worker === worker) this.settleAsk(id, { answer: "unanswered" });
|
|
2882
|
+
}
|
|
2786
2883
|
clearLead(conn) {
|
|
2787
2884
|
this.requireCli(conn, "clear the lead");
|
|
2788
2885
|
const holder = this.store.holder();
|
|
2789
2886
|
const res = clearOrchestrator(holder, this.named(this.store.allSessions()));
|
|
2887
|
+
const prevName = this.leadName(holder);
|
|
2790
2888
|
const at = this.iso();
|
|
2791
2889
|
const sent = [];
|
|
2792
2890
|
this.store.tx(() => {
|
|
@@ -2808,6 +2906,7 @@ var Daemon = class {
|
|
|
2808
2906
|
sent.push(m);
|
|
2809
2907
|
}
|
|
2810
2908
|
});
|
|
2909
|
+
this.logLead(prevName, holder, null, "clear");
|
|
2811
2910
|
if (holder !== null) {
|
|
2812
2911
|
this.emit({
|
|
2813
2912
|
event: "orchestrator.changed",
|
|
@@ -3379,7 +3478,7 @@ async function startDaemon(opts) {
|
|
|
3379
3478
|
close().then(() => opts.onIdleExit?.());
|
|
3380
3479
|
}, () => {
|
|
3381
3480
|
close().then(() => opts.onShutdown?.());
|
|
3382
|
-
}, daemonLog, opts.authTimeoutMs ?? 5e3, opts.autoLimits ?? autoLimitsFromEnv(process.env), processIo, opts.platform, opts.wakers ?? {}, paths.settings);
|
|
3481
|
+
}, daemonLog, opts.authTimeoutMs ?? 5e3, opts.autoLimits ?? autoLimitsFromEnv(process.env), processIo, opts.platform, opts.wakers ?? {}, paths.settings, leadLogPath(opts.dataDir));
|
|
3383
3482
|
daemon.removeAllOffline();
|
|
3384
3483
|
const srv = createServer((socket) => daemon.attach(socket));
|
|
3385
3484
|
server = srv;
|