@conveno/cli 0.2.0-rc.12 → 0.2.0-rc.13

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.
@@ -1,7 +1,7 @@
1
1
  import { writeFileSync } from "node:fs";
2
- import { n as runAcpHostFromFile, r as stopRequestPath, t as killProcessTree } from "./dist-4iJnF07i.js";
3
- import { Lt as readSpawnRecord, Xt as spawnRecordPath } from "./dist-CRj_cuHc.js";
4
- import { a as parseFlags, n as COMMANDS } from "./args-C1eX8Ixk.js";
2
+ import { n as runAcpHostFromFile, r as stopRequestPath, t as killProcessTree } from "./dist-BkhKEexU.js";
3
+ import { Ut as readSpawnRecord, nn as spawnRecordPath } from "./dist-DnNuDzEA.js";
4
+ import { a as parseFlags, n as COMMANDS } from "./args-C4rVCVXx.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-Du1hwaux.js";
3
- import { qt as runWaker } from "./dist-CRj_cuHc.js";
2
+ import { t as RELAY_SUBCOMMAND } from "./dist-D4sb5RQD.js";
3
+ import { $t as runWaker } from "./dist-DnNuDzEA.js";
4
4
  import { n as connectOpts } from "./ctx-tYftvhz_.js";
5
5
  // src/agy-relay.ts
6
6
  /**
@@ -156,7 +156,7 @@ const COMMANDS = [
156
156
  allow: {
157
157
  type: "string",
158
158
  value: "<kinds>",
159
- help: "Background: tool calls to approve, such as read,search or execute:npm test*"
159
+ help: "Background: tool calls to approve, such as read,search or execute:npm test*. Comma or space separated; repeat the flag to add more"
160
160
  },
161
161
  yes: {
162
162
  type: "boolean",
@@ -169,6 +169,8 @@ const COMMANDS = [
169
169
  "it becomes its next prompt: right away when it is idle, else when its turn ends.",
170
170
  "--window opens the real CLI in a new terminal instead, so you can watch it and take over.",
171
171
  "In the background, tool calls that need approval are denied unless --allow covers them.",
172
+ "Example: --allow read,search (also --allow read search, or --allow read --allow search).",
173
+ "Conveno's own tools, such as send, are always allowed.",
172
174
  "claude and codex need an ACP adapter installed. End a worker with conveno stop.",
173
175
  "Waits until the session registers, then prints its name.",
174
176
  "Without a terminal of your own it needs --yes, and exits 2 without it.",
package/dist/bin.js CHANGED
@@ -2,6 +2,19 @@
2
2
  import { enableCompileCache } from "node:module";
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
5
+ // src/hook-skip.ts
6
+ /**
7
+ * Whether `conveno <argv>` is a hook that must exit 0 at once, with no output:
8
+ * - an ACP worker's agent (`CONVENO_ACP_WORKER`, set by the ACP host): the host drives its turns
9
+ * and delivery itself, and a hook's process walk could reach the lead's session instead;
10
+ * - Claude hooks run by Grok, which imports `~/.claude/settings.json` and sets `GROK_HOOK_EVENT`
11
+ * on every hook process. Claude Code never sets it. Grok's own hooks (`hook grok ...`) still run.
12
+ */
13
+ function hookSkipped(argv, env) {
14
+ if (argv[0] !== "hook") return false;
15
+ if (env.CONVENO_ACP_WORKER) return true;
16
+ return argv[1] === "claude" && Boolean(env.GROK_HOOK_EVENT);
17
+ }
5
18
  // src/bin.ts
6
19
  /**
7
20
  * Cache V8's compiled code for Conveno's files and its dependencies, in the user's own data
@@ -20,15 +33,16 @@ function startCompileCache() {
20
33
  startCompileCache();
21
34
  const argv = process.argv.slice(2);
22
35
  const isHook = argv[0] === "hook";
36
+ if (hookSkipped(argv, process.env)) process.exit(0);
23
37
  for (const stream of [process.stdout, process.stderr]) stream.on("error", (err) => {
24
38
  if (err.code === "EPIPE") process.exit(0);
25
39
  throw err;
26
40
  });
27
41
  try {
28
42
  let code;
29
- if (isHook) code = await (await import("./hook-entry-ajdMBSpY.js")).runHookEntry(argv.slice(1));
43
+ if (isHook) code = await (await import("./hook-entry-jOfjq-0A.js")).runHookEntry(argv.slice(1));
30
44
  else {
31
- const [{ main }, { createRuntimeCtx }] = await Promise.all([import("./main-WIfawg60.js"), import("./runtime-BKPod_ZQ.js")]);
45
+ const [{ main }, { createRuntimeCtx }] = await Promise.all([import("./main-I2RMN7XN.js"), import("./runtime-CPmrhPFJ.js")]);
32
46
  code = await main(argv, createRuntimeCtx());
33
47
  }
34
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-BjATai4T.js";
4
- import { $ as generateSessionName, $t as statusAfterLiveness, A as clientProof, An as isSocketPathTooLong, At as proofsMatch, B as defaultProcessIo, Bn as sanitizeLine, C as autoCandidates, D as claimOrchestrator, Dn as defaultSocketPath, E as bindAccountDevice, En as createLineDecoder, F as currentAccessToken, Fn as newMessageId, Ft as readInbox, I as daemonProof, In as newSessionId, It as readSettings, K as evaluateLiveness, L as dataDir, Ln as parseIpcRequest, Mn as makeEventNotification, Mt as readAccountTokens, Nn as makeResult, Nt as readAncestry, On as encodeFrame, Ot as planSpawn, P as createWmiWalker, Pn as newDeviceId, R as dataPaths, Rn as parseRelayFrame, Sn as RpcErrorCode, St as pendingForInjection, T as baseName, Tn as SessionId, V as detectRepo, Vn as socketPathTooLongMessage, Vt as requeueEntries, W as effectiveHolder, Wt as resolveRecipient, X as formatContinuation, Z as formatHookContext, _n as Message, bn as PROTOCOL_VERSION, et as holderAfterDeparture, gt as oneWindowPerHost, ht as newAuthNonce, i as ConvenoError, in as turnHops, jn as makeError, k as clearOrchestrator, m as ackEntries, mn as EVENT_NAMES, n as AccountError, nn as takeWithinChars, ot as isOnline, pn as DeviceId, pt as markDelivered, rn as tooManyUnreadMessage, sn as validateRename, st as jwtClaim, tn as takeWithinBytes, u as RESPONSE_BUDGET_BYTES, w as autoLimitsFromEnv, xn as RelayPayload, yn as OWNER_SESSION_ID, z as decideAutoContinue, zn as safeParse } from "./dist-CRj_cuHc.js";
3
+ import { t as codexAdapter } from "./dist-C9Z1EMlM.js";
4
+ import { A as clearOrchestrator, An as SESSION_ENDED_TEXT, B as decideAutoContinue, Bn as makeResult, Bt as readInbox, Cn as Message, D as bindAccountDevice, Dn as RelayPayload, E as baseName, En as PROTOCOL_VERSION, Et as pendingForInjection, F as createWmiWalker, Fn as encodeFrame, Ft as proofsMatch, G as effectiveHolder, Gn as parseRelayFrame, H as detectRepo, Hn as newMessageId, Ht as readSettings, I as currentAccessToken, Jn as socketPathTooLongMessage, Kn as safeParse, L as daemonProof, Ln as isSocketPathTooLong, Lt as readAccountTokens, Mn as SessionId, Nn as createLineDecoder, Nt as planSpawn, O as claimOrchestrator, On as RpcErrorCode, Pn as defaultSocketPath, Q as formatHookContext, R as dataDir, Rn as makeError, Rt as readAncestry, T as autoLimitsFromEnv, Tn as OWNER_SESSION_ID, Un as newSessionId, V as defaultProcessIo, Vn as newDeviceId, Wn as parseIpcRequest, Xt as resolveRecipient, Z as formatContinuation, _t as markDelivered, a as ConvenoError, an as statusAfterLiveness, bn as EVENT_NAMES, bt as oneWindowPerHost, cn as takeWithinChars, d as RESPONSE_BUDGET_BYTES, dt as jwtClaim, et as generateSessionName, h as ackEntries, j as clientProof, ln as tooManyUnreadMessage, pn as validateRename, q as evaluateLiveness, qn as sanitizeLine, qt as requeueEntries, r as AccountError, sn as takeWithinBytes, tt as holderAfterDeparture, un as turnHops, ut as isOnline, w as autoCandidates, yn as DeviceId, yt as newAuthNonce, z as dataPaths, zn as makeEventNotification } from "./dist-DnNuDzEA.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-DeN0jR3I.js";
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-CoRBNycn.js";
10
10
  import { execFileSync } from "node:child_process";
11
11
  import { DatabaseSync } from "node:sqlite";
12
12
  // ../daemon/src/lifecycle.ts
@@ -1691,6 +1691,10 @@ const MIGRATIONS = [
1691
1691
  ALTER TABLE sessions ADD COLUMN native_id TEXT;
1692
1692
  CREATE INDEX sessions_native_id ON sessions (native_id);
1693
1693
  `
1694
+ },
1695
+ {
1696
+ name: "008_variant",
1697
+ sql: "ALTER TABLE sessions ADD COLUMN variant TEXT;"
1694
1698
  }
1695
1699
  ];
1696
1700
  const str = (v) => typeof v === "string" ? v : void 0;
@@ -1749,6 +1753,7 @@ function toSessionRow(r) {
1749
1753
  if (spawnedBy !== void 0) row.spawnedBy = spawnedBy;
1750
1754
  const nativeId = str(r.native_id);
1751
1755
  if (nativeId !== void 0) row.nativeId = nativeId;
1756
+ if (r.variant === "app") row.variant = "app";
1752
1757
  return row;
1753
1758
  }
1754
1759
  /** Wire-format session for a stored row. */
@@ -1779,6 +1784,7 @@ function toSession(row, isOrchestrator, unreadCount) {
1779
1784
  if (row.statusText !== void 0) s.statusText = row.statusText;
1780
1785
  if (row.spawnedBy !== void 0) s.spawnedBy = row.spawnedBy;
1781
1786
  if (row.nativeId !== void 0) s.nativeId = row.nativeId;
1787
+ if (row.variant !== void 0) s.variant = row.variant;
1782
1788
  return s;
1783
1789
  }
1784
1790
  function toEntry(r) {
@@ -1852,8 +1858,8 @@ var Store = class {
1852
1858
  insertSession(s) {
1853
1859
  this.run(`INSERT INTO sessions (id, name, cli, cli_version, device_id, cwd, repo_root, repo_remote_hash,
1854
1860
  pid, host_pid, host_pids, status, status_text, delivery_tier, spawned_by, spawned, spawn_depth,
1855
- auto_runs, turn_hops, started_at, last_seen_at)
1856
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, s.id, s.name, s.cli, s.cliVersion ?? null, s.deviceId, s.cwd, s.repoRoot ?? null, s.repoRemoteUrlHash ?? null, s.pid ?? null, s.hostPid ?? null, s.hostPids ? JSON.stringify(s.hostPids) : null, s.status, s.statusText ?? null, s.deliveryTier, s.spawnedBy ?? null, s.spawned ? 1 : 0, s.spawnDepth, JSON.stringify(s.autoRuns), s.turnHops, s.startedAt, s.lastSeenAt);
1861
+ auto_runs, turn_hops, started_at, last_seen_at, variant)
1862
+ VALUES (?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, s.id, s.name, s.cli, s.cliVersion ?? null, s.deviceId, s.cwd, s.repoRoot ?? null, s.repoRemoteUrlHash ?? null, s.pid ?? null, s.hostPid ?? null, s.hostPids ? JSON.stringify(s.hostPids) : null, s.status, s.statusText ?? null, s.deliveryTier, s.spawnedBy ?? null, s.spawned ? 1 : 0, s.spawnDepth, JSON.stringify(s.autoRuns), s.turnHops, s.startedAt, s.lastSeenAt, s.variant ?? null);
1857
1863
  }
1858
1864
  getSession(id) {
1859
1865
  const r = this.all("SELECT * FROM sessions WHERE id = ?", id)[0];
@@ -1866,6 +1872,18 @@ var Store = class {
1866
1872
  updateSession(id, fields) {
1867
1873
  const sets = [];
1868
1874
  const vals = [];
1875
+ if (fields.cwd !== void 0) {
1876
+ sets.push("cwd = ?");
1877
+ vals.push(fields.cwd);
1878
+ }
1879
+ if (fields.repoRoot !== void 0) {
1880
+ sets.push("repo_root = ?", "repo_remote_hash = NULL");
1881
+ vals.push(fields.repoRoot);
1882
+ }
1883
+ if (fields.variant !== void 0) {
1884
+ sets.push("variant = ?");
1885
+ vals.push(fields.variant);
1886
+ }
1869
1887
  if (fields.pid !== void 0) {
1870
1888
  sets.push("pid = ?");
1871
1889
  vals.push(fields.pid);
@@ -1952,7 +1970,7 @@ var Store = class {
1952
1970
  }
1953
1971
  };
1954
1972
  // ../daemon/src/server.ts
1955
- const DAEMON_VERSION = "0.2.0-rc.12";
1973
+ const DAEMON_VERSION = "0.2.0-rc.13";
1956
1974
  /** A connection that has not finished the handshake by then is closed. */
1957
1975
  const AUTH_TIMEOUT_MS = 5e3;
1958
1976
  /** Unread messages one session may hold. */
@@ -2034,6 +2052,11 @@ var Daemon = class {
2034
2052
  attached = /* @__PURE__ */ new Map();
2035
2053
  /** When a hook last touched each session (a turn start or end, a delivery, a bind). In memory only. */
2036
2054
  hookAt = /* @__PURE__ */ new Map();
2055
+ /**
2056
+ * Sessions retired by an unregister without a pid (a Codex SessionEnd hook, an ACP host exiting).
2057
+ * Their heartbeats are refused, so a leftover MCP process cannot bring them back online.
2058
+ */
2059
+ retired = /* @__PURE__ */ new Set();
2037
2060
  constructor(store, token, now, isAlive, idleExitMs, requestIdleExit, requestShutdown, log, authTimeoutMs = AUTH_TIMEOUT_MS, autoLimits = autoLimitsFromEnv({}), processIo = defaultProcessIo, platform = process.platform, wakers = {}, settingsPath) {
2038
2061
  this.store = store;
2039
2062
  this.token = token;
@@ -2131,6 +2154,7 @@ var Daemon = class {
2131
2154
  case "session.register": return this.registerAsync(req.params);
2132
2155
  case "session.heartbeat": return this.heartbeat(req.params.sessionId, req.params.pid);
2133
2156
  case "session.unregister": return this.unregister(req.params.sessionId, req.params.pid);
2157
+ case "session.remove": return this.remove(req.params.sessionId);
2134
2158
  case "session.rename": return this.rename(req.params);
2135
2159
  case "session.setStatus": return this.setStatus(req.params);
2136
2160
  case "session.list": return this.list(req.params);
@@ -2138,6 +2162,7 @@ var Daemon = class {
2138
2162
  case "session.hostOf": return this.hostOf(req.params);
2139
2163
  case "session.setNative": return this.setNative(req.params);
2140
2164
  case "session.bind": return this.bind(req.params);
2165
+ case "session.setCwd": return this.setCwd(req.params);
2141
2166
  case "turn.start": return this.turnStart(req.params.sessionId);
2142
2167
  case "turn.end": return this.turnEnd(req.params);
2143
2168
  case "turn.wake": return this.turnWake(conn, req.params);
@@ -2299,6 +2324,7 @@ var Daemon = class {
2299
2324
  lastSeenAt: at
2300
2325
  };
2301
2326
  if (p.cliVersion !== void 0) r.cliVersion = p.cliVersion;
2327
+ if (p.variant !== void 0) r.variant = p.variant;
2302
2328
  if (repo) {
2303
2329
  r.repoRoot = repo.root;
2304
2330
  if (repo.remoteUrlHash !== void 0) r.repoRemoteUrlHash = repo.remoteUrlHash;
@@ -2332,6 +2358,7 @@ var Daemon = class {
2332
2358
  }
2333
2359
  heartbeat(sessionId, pid) {
2334
2360
  const row = this.requireSession(sessionId);
2361
+ if (this.retired.has(sessionId)) throw new ConvenoError(RpcErrorCode.NotFound, `Session "${row.name}" ${SESSION_ENDED_TEXT}.`);
2335
2362
  const at = this.iso();
2336
2363
  if (row.status !== "offline") {
2337
2364
  if (pid !== void 0) this.attachedOf(row).add(pid);
@@ -2385,9 +2412,50 @@ var Daemon = class {
2385
2412
  return { ok: true };
2386
2413
  }
2387
2414
  }
2415
+ if (pid === void 0) this.retired.add(sessionId);
2388
2416
  this.depart(sessionId, "unregistered");
2389
2417
  return { ok: true };
2390
2418
  }
2419
+ /**
2420
+ * Delete a session and its mail (the app's "Remove this session"). The lead role goes with it.
2421
+ * A window that is still open registers again on its next heartbeat or tool call.
2422
+ */
2423
+ remove(sessionId) {
2424
+ const row = this.requireSession(sessionId);
2425
+ const shown = {
2426
+ ...this.view(row),
2427
+ status: "offline"
2428
+ };
2429
+ const before = this.store.holder();
2430
+ const after = holderAfterDeparture(before, sessionId);
2431
+ this.store.tx(() => {
2432
+ if (after !== before) this.store.setHolder(after);
2433
+ this.store.deleteSession(sessionId);
2434
+ });
2435
+ this.listeners.delete(sessionId);
2436
+ this.woken.delete(sessionId);
2437
+ this.wokenAt.delete(sessionId);
2438
+ this.wakersOff.delete(sessionId);
2439
+ this.offlineSince.delete(sessionId);
2440
+ this.attached.delete(sessionId);
2441
+ this.hookAt.delete(sessionId);
2442
+ this.emit({
2443
+ event: "session.updated",
2444
+ data: {
2445
+ session: shown,
2446
+ change: "unregistered"
2447
+ }
2448
+ });
2449
+ this.relay?.sessionsChanged();
2450
+ if (after !== before) this.emit({
2451
+ event: "orchestrator.changed",
2452
+ data: {
2453
+ orchestrator: after,
2454
+ previous: before
2455
+ }
2456
+ });
2457
+ return { ok: true };
2458
+ }
2391
2459
  rename(p) {
2392
2460
  const row = this.requireSession(p.sessionId);
2393
2461
  const name = validateRename(p.sessionId, p.name, this.named(this.store.allSessions()));
@@ -2499,6 +2567,36 @@ var Daemon = class {
2499
2567
  return { session: this.view(this.requireSession(row.id)) };
2500
2568
  }
2501
2569
  /**
2570
+ * A desktop app session learns its workspace from a hook: the app starts Conveno in its install
2571
+ * folder, so the row moves to the folder the user has open. A name made from the old folder
2572
+ * follows it; a name the user chose stays. Only an app session moves (`variant` on the call may
2573
+ * mark one); a CLI row keeps the folder it registered with.
2574
+ */
2575
+ async setCwd(p) {
2576
+ const row = this.requireOnline(p.sessionId);
2577
+ if (!(row.variant === "app" || p.variant === "app")) return { session: this.view(row) };
2578
+ const found = samePath(row.cwd, p.cwd, this.platform) ? void 0 : await detectRepo(p.cwd, { exists: (path) => existsSync(path) });
2579
+ const cur = this.requireOnline(p.sessionId);
2580
+ const fields = {};
2581
+ if (cur.variant !== "app") fields.variant = "app";
2582
+ if (found && !samePath(cur.cwd, p.cwd, this.platform)) {
2583
+ const oldBase = baseName(cur.repoRoot ?? cur.cwd);
2584
+ const prefix = generateSessionName(cur.cli, oldBase, []).replace(/1$/, "");
2585
+ const auto = cur.name.startsWith(prefix) && /^\d+$/.test(cur.name.slice(prefix.length));
2586
+ fields.cwd = p.cwd;
2587
+ fields.repoRoot = found.root ?? null;
2588
+ if (auto) {
2589
+ const others = this.named(this.store.allSessions().filter((r) => r.id !== cur.id));
2590
+ fields.name = generateSessionName(cur.cli, baseName(found.root ?? p.cwd), others);
2591
+ }
2592
+ }
2593
+ if (Object.keys(fields).length > 0) {
2594
+ this.store.updateSession(cur.id, fields);
2595
+ this.emitSession(cur.id, "updated");
2596
+ }
2597
+ return { session: this.view(this.requireSession(cur.id)) };
2598
+ }
2599
+ /**
2502
2600
  * The session of the window a hook runs in, among the online sessions of its CLI: the one under
2503
2601
  * its host process (and in its folder, when the hook says which). Codex shares one host process
2504
2602
  * between windows, so there it prefers a session that has no conversation yet, and takes a bound
@@ -2514,6 +2612,31 @@ var Daemon = class {
2514
2612
  return cands.length === 1 ? cands[0] : void 0;
2515
2613
  }
2516
2614
  /**
2615
+ * `session.bind` from a hook that has only its parent pid. Answers without the hook walking the
2616
+ * process tree when the conversation settles it: exactly one online session of the CLI holds the
2617
+ * id, and the hook's parent is that session's host, or the hook starts no turn (a Stop or an
2618
+ * idle never moves a window), or that session is already busy. A conversation no window could
2619
+ * take (no session online, or a hook that is no turn start and every session has a
2620
+ * conversation) answers none. Anything else needs the host pid: `needsHost`. So only the turn
2621
+ * start of an idle conversation walks.
2622
+ */
2623
+ bindWithoutHost(rows, p) {
2624
+ if (rows.length === 0) return { session: null };
2625
+ const holders = rows.filter((r) => r.nativeId === p.nativeId);
2626
+ const [holder] = holders;
2627
+ if (holders.length === 1 && holder) {
2628
+ const pids = [...holder.hostPid === void 0 ? [] : [holder.hostPid], ...holder.hostPids ?? []];
2629
+ if (p.ppid !== void 0 && pids.includes(p.ppid) || !p.turnStart || holder.status === "busy") {
2630
+ this.touchHook(holder.id);
2631
+ return { session: this.view(holder) };
2632
+ }
2633
+ } else if (holders.length === 0 && !p.turnStart && rows.every((r) => r.nativeId !== void 0)) return { session: null };
2634
+ return {
2635
+ session: null,
2636
+ needsHost: true
2637
+ };
2638
+ }
2639
+ /**
2517
2640
  * Bind a conversation to the window's session (see `session.bind` in the protocol). The session
2518
2641
  * that holds the id wins; a caller with a session of its own is merged into it. Otherwise only a
2519
2642
  * turn start moves the window to the conversation, and a conversation that is not the window's
@@ -2523,6 +2646,7 @@ var Daemon = class {
2523
2646
  const caller = p.sessionId === void 0 ? void 0 : this.requireOnline(p.sessionId);
2524
2647
  if (caller && caller.cli !== p.cli) return { session: null };
2525
2648
  const rows = this.store.allSessions().filter((r) => r.status !== "offline" && r.cli === p.cli);
2649
+ if (!caller && p.hostPid === void 0) return this.bindWithoutHost(rows, p);
2526
2650
  let holder = rows.find((r) => r.nativeId === p.nativeId);
2527
2651
  if (holder && !caller && p.hostPid !== void 0) {
2528
2652
  const pids = [...holder.hostPid === void 0 ? [] : [holder.hostPid], ...holder.hostPids ?? []];
@@ -1,4 +1,4 @@
1
- import { t as ClientError } from "./dist-B3YYLzKS.js";
1
+ import { t as ClientError } from "./dist-Ca3P7aN-.js";
2
2
  import { n as cmd, s as plainError } from "./fmt-C2SsP5Y0.js";
3
3
  // src/daemonError.ts
4
4
  /**
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
- import { B as defaultProcessIo, Ct as pendingHookContext, Et as planLauncher, G as endTurnContinuation, H as dropFromList, Jt as sameJson, Pt as readCommandLine, U as editJson, _t as ownSession, an as uninstallLauncher, at as isObject, b as askedKey, c as NOT_FROM_USER_NOTICE, ct as late, dt as loadJson, jt as putInList, l as ORCHESTRATOR_TASK_NOTICE, mt as needsQuoting, o as FROM_USER_NOTICE, q as existedBefore, v as agentCommand, x as askedMarker, yt as parseCliVersion } from "./dist-CRj_cuHc.js";
3
+ import { Ct as parseCliVersion, Dt as pendingHookContext, It as putInList, J as existedBefore, K as endTurnContinuation, S as askedMarker, U as dropFromList, V as defaultProcessIo, W as editJson, at as hostPidOf, dn as uninstallLauncher, en as sameJson, ft as late, ht as loadJson, jt as planLauncher, l as NOT_FROM_USER_NOTICE, lt as isObject, s as FROM_USER_NOTICE, u as ORCHESTRATOR_TASK_NOTICE, vt as needsQuoting, x as askedKey, xt as ownSession, y as agentCommand, zt as readCommandLine } from "./dist-DnNuDzEA.js";
4
4
  import { n as cs, t as Za } from "./toml-patch-DGzVRdd1.js";
5
5
  // ../adapters/grok/dist/index.js
6
6
  const SERVER_NAME = "conveno";
@@ -619,7 +619,8 @@ async function stopHook(input, ctx) {
619
619
  const session = await ownSession(ctx);
620
620
  const key = session && askedKey(session.id, ctx.nativeId);
621
621
  if (session !== null && key && session.deliveryTier !== "live" && !await wasAsked(key)) {
622
- const command = await readCommandLine(ctx.hostPid, defaultProcessIo, ASK_READ_TIMEOUT_MS);
622
+ const hostPid = await hostPidOf(ctx);
623
+ const command = hostPid === void 0 ? null : await readCommandLine(hostPid, defaultProcessIo, ASK_READ_TIMEOUT_MS);
623
624
  if (command !== null && !isOneShotGrok(command)) askFor = key;
624
625
  }
625
626
  } catch {
@@ -1,5 +1,5 @@
1
- import { n as connect } from "./dist-B3YYLzKS.js";
2
- import { Sn as RpcErrorCode, Tn as SessionId, X as formatContinuation, a as DEFAULT_ALLOW_RULES, en as takeAcpLaunchFile, fn as CliKind, i as ConvenoError, on as updateSpawnRecord, rt as isAllowed, vt as parseAllowPatterns } from "./dist-CRj_cuHc.js";
1
+ import { n as connect } from "./dist-Ca3P7aN-.js";
2
+ import { Mn as SessionId, On as RpcErrorCode, St as parseAllowPatterns, Z as formatContinuation, a as ConvenoError, fn as updateSpawnRecord, o as DEFAULT_ALLOW_RULES, on as takeAcpLaunchFile, ot as isAllowed, vn as CliKind } from "./dist-DnNuDzEA.js";
3
3
  import { randomBytes } from "node:crypto";
4
4
  import { existsSync, rmSync } from "node:fs";
5
5
  import { Readable, Writable } from "node:stream";
@@ -19,6 +19,36 @@ function answer(ask, allow) {
19
19
  optionId: option.optionId
20
20
  } : { outcome: "cancelled" };
21
21
  }
22
+ const CONVENO_TOOL_TITLE = new RegExp(`^(?:tool\\s*[:\\-]\\s*)?(?:mcp[_\\-.:/ ]{1,3})?conveno[_\\-.:/ ]{1,3}(${[
23
+ "whoami",
24
+ "list_sessions",
25
+ "send",
26
+ "inbox",
27
+ "ack",
28
+ "rename",
29
+ "set_status",
30
+ "become_lead",
31
+ "orchestrate",
32
+ "handoff",
33
+ "spawn_session"
34
+ ].join("|")})$`, "i");
35
+ /** Kinds whose title is a command line or a path, so a title that looks like a tool name is not one. */
36
+ const COMMAND_OR_FILE_KINDS = /* @__PURE__ */ new Set([
37
+ "execute",
38
+ "edit",
39
+ "delete",
40
+ "move"
41
+ ]);
42
+ /**
43
+ * The Conveno tool a tool call is, or undefined. Only a call that names the whole tool counts, and
44
+ * never one the agent reports as a command it runs or a file it changes: the title of such a call
45
+ * is the command line or the path.
46
+ */
47
+ function convenoToolOf(call) {
48
+ if (call.kind && COMMAND_OR_FILE_KINDS.has(call.kind)) return void 0;
49
+ const m = CONVENO_TOOL_TITLE.exec((call.title ?? "").trim());
50
+ return m ? m[1]?.toLowerCase() : void 0;
51
+ }
22
52
  var AllowListPolicy = class {
23
53
  rules;
24
54
  constructor(rules) {
@@ -26,7 +56,8 @@ var AllowListPolicy = class {
26
56
  }
27
57
  async decide(ask, _signal) {
28
58
  const what = `${ask.title ?? "a tool call"} (${ask.kind ?? "other"})`;
29
- if (isAllowed(this.rules, {
59
+ const own = convenoToolOf(ask) !== void 0;
60
+ if (own || isAllowed(this.rules, {
30
61
  kind: ask.kind,
31
62
  title: ask.title
32
63
  })) {
@@ -34,7 +65,7 @@ var AllowListPolicy = class {
34
65
  if (outcome.outcome === "selected") return {
35
66
  allowed: true,
36
67
  outcome,
37
- reason: `allowed ${what} by the allow list`
68
+ reason: `allowed ${what} ${own ? "(a Conveno tool)" : "by the allow list"}`
38
69
  };
39
70
  return {
40
71
  allowed: false,
@@ -71,7 +102,7 @@ var ToolTracker = class {
71
102
  return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
72
103
  }
73
104
  };
74
- const HOST_VERSION = "0.2.0-rc.12";
105
+ const HOST_VERSION = "0.2.0-rc.13";
75
106
  /** A stop request file: `conveno stop` writes it next to the spawn record. */
76
107
  const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
77
108
  function withTimeout(p, ms, what) {
@@ -126,6 +157,8 @@ var AcpHost = class {
126
157
  /** The status line after a failed prompt, kept until the next prompt starts. */
127
158
  failedText;
128
159
  denials = [];
160
+ /** The worker called Conveno's `send` (or `handoff`) in the turn that is running. */
161
+ sentThisTurn = false;
129
162
  lastStatus;
130
163
  timers = [];
131
164
  constructor(spec, deps) {
@@ -245,6 +278,10 @@ var AcpHost = class {
245
278
  ...agentVersion ? { cliVersion: agentVersion } : {}
246
279
  });
247
280
  this.sessionId = session.id;
281
+ await this.client["session.setNative"]({
282
+ sessionId: session.id,
283
+ nativeId: created.sessionId.slice(0, 256)
284
+ }).catch((e) => this.log(`could not record the ACP session id: ${errText(e)}`));
248
285
  updateSpawnRecord(spec.record, {
249
286
  pid: process.pid,
250
287
  sessionId: session.id,
@@ -257,9 +294,9 @@ var AcpHost = class {
257
294
  let next = this.spec.task ?? null;
258
295
  if (next === null) await this.status("idle", null);
259
296
  while (!this.stopping) if (next !== null) {
260
- await this.prompt(next);
297
+ const finished = await this.prompt(next);
261
298
  if (this.stopping) break;
262
- await this.reportDenials();
299
+ await this.reportTurnEnd(finished);
263
300
  next = await this.endTurn();
264
301
  } else next = await this.waitForWork();
265
302
  }
@@ -286,14 +323,18 @@ var AcpHost = class {
286
323
  return null;
287
324
  }
288
325
  }
289
- /** One prompt turn. Resolves when the agent answers `session/prompt` or the host stops. */
326
+ /**
327
+ * One prompt turn. Resolves when the agent answers `session/prompt` or the host stops. True when
328
+ * the turn ran to its end; false when the prompt failed (the spawner was told) or the host stopped.
329
+ */
290
330
  async prompt(text) {
291
331
  const conn = this.conn;
292
332
  const sid = this.acpSessionId;
293
- if (!conn || !sid) return;
333
+ if (!conn || !sid) return false;
294
334
  this.turnCtl = new AbortController();
295
335
  this.failedText = void 0;
296
336
  this.denials = [];
337
+ this.sentThisTurn = false;
297
338
  await this.status("busy", null);
298
339
  const turn = conn.agent.request(methods.agent.session.prompt, {
299
340
  sessionId: sid,
@@ -309,12 +350,14 @@ var AcpHost = class {
309
350
  const reason = requestReason(e);
310
351
  this.log(`session/prompt failed: ${reason}`);
311
352
  await this.promptFailed(reason);
312
- return;
353
+ return false;
313
354
  }
314
355
  await conn.agent.notify(methods.agent.session.cancel, { sessionId: sid }).catch(() => void 0);
315
356
  const grace = this.deps.stopGraceMs ?? 5e3;
316
357
  await Promise.race([turn.then(() => void 0, () => void 0), new Promise((r) => setTimeout(r, grace).unref())]);
358
+ return false;
317
359
  }
360
+ return true;
318
361
  }
319
362
  /**
320
363
  * Idle: wait until the daemon hands this session messages through `turn.wake`, then return the
@@ -382,6 +425,8 @@ var AcpHost = class {
382
425
  onUpdate(n) {
383
426
  if (n.sessionId !== this.acpSessionId) return;
384
427
  const doing = this.tools.update(n.update);
428
+ const id = n.update.toolCallId;
429
+ if (id !== void 0) this.noteConvenoCall(this.tools.tools.get(id));
385
430
  if (doing !== void 0 && doing !== this.lastStatus) {
386
431
  this.lastStatus = doing;
387
432
  this.status(void 0, doing);
@@ -392,6 +437,10 @@ var AcpHost = class {
392
437
  const known = this.tools.tools.get(p.toolCall.toolCallId) ?? {};
393
438
  const title = p.toolCall.title ?? known.title;
394
439
  const kind = p.toolCall.kind ?? known.kind;
440
+ this.noteConvenoCall({
441
+ title,
442
+ kind
443
+ });
395
444
  const ask = {
396
445
  toolCallId: p.toolCall.toolCallId,
397
446
  ...title ? { title } : {},
@@ -451,17 +500,32 @@ var AcpHost = class {
451
500
  this.lastPromptFailure = reason;
452
501
  await this.tell(`[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP) could not run a prompt: ${reason}. It keeps running and takes the next message.`);
453
502
  }
454
- /** Tell the spawner which tool calls were denied in the turn that just ended. */
455
- async reportDenials() {
456
- if (this.denials.length === 0 || !this.spec.spawnedBy) return;
457
- const list = this.denials.slice(0, 5).map((d) => `- ${d}`);
458
- if (this.denials.length > 5) list.push(`- and ${this.denials.length - 5} more`);
503
+ /** Remember that the worker sent something this turn. Only Conveno's own send tools count. */
504
+ noteConvenoCall(call) {
505
+ if (!call) return;
506
+ const tool = convenoToolOf(call);
507
+ if (tool === "send" || tool === "handoff") this.sentThisTurn = true;
508
+ }
509
+ /**
510
+ * One note to the spawner about the turn that just ended: the worker finished without sending
511
+ * anything, and/or which tool calls were denied. Nothing when there is no spawner (a spawn from
512
+ * a terminal), when the worker did reply and nothing was denied, or when the prompt failed.
513
+ */
514
+ async reportTurnEnd(finished) {
515
+ const denials = this.denials;
459
516
  this.denials = [];
460
- await this.tell([
461
- `[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP) was denied these tool calls in its last turn, because its spawn limited it to an allow list:`,
462
- ...list,
463
- "The allow list it was spawned with does not cover them. Spawn it again with a wider allow list, or none for full access."
464
- ].join("\n"));
517
+ if (!this.spec.spawnedBy) return;
518
+ const silent = finished && !this.sentThisTurn;
519
+ if (denials.length === 0 && !silent) return;
520
+ const who = `[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP)`;
521
+ const lines = [];
522
+ if (silent) lines.push(`${who} finished its turn without replying.`);
523
+ if (denials.length > 0) {
524
+ const list = denials.slice(0, 5).map((d) => `- ${d}`);
525
+ if (denials.length > 5) list.push(`- and ${denials.length - 5} more`);
526
+ lines.push(silent ? "It was denied these tool calls in its last turn, because its spawn limited it to an allow list:" : `${who} was denied these tool calls in its last turn, because its spawn limited it to an allow list:`, ...list, "The allow list it was spawned with does not cover them. Spawn it again with a wider allow list, or none for full access.");
527
+ }
528
+ await this.tell(lines.join("\n"));
465
529
  }
466
530
  /** Send a text message from this session to its spawner. Never throws. */
467
531
  async tell(text) {
@@ -522,6 +586,8 @@ var AcpHost = class {
522
586
  this.log(`stopped: ${describeStop(reason)}`);
523
587
  }
524
588
  };
589
+ /** Set on every agent the ACP host starts. `conveno hook` exits at once when it is set. */
590
+ const ACP_WORKER_ENV = "CONVENO_ACP_WORKER";
525
591
  /**
526
592
  * End `pid` and its descendants. POSIX: the agent leads its own process group (it was started
527
593
  * detached), so the whole group gets SIGKILL. Windows has no process groups; `taskkill /T` ends the
@@ -566,7 +632,10 @@ function startAgentProcess(opts) {
566
632
  ],
567
633
  detached: platform !== "win32",
568
634
  windowsHide: true,
569
- env: opts.env ?? process.env,
635
+ env: {
636
+ ...opts.env ?? process.env,
637
+ [ACP_WORKER_ENV]: "1"
638
+ },
570
639
  ...opts.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
571
640
  });
572
641
  const exited = new Promise((r) => {