@conveno/cli 0.2.0-rc.15 → 0.2.0-rc.17

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,11 +1,12 @@
1
- import { n as connect } from "./dist-C59LTq60.js";
2
- import { $ as formatContinuation, Pn as RpcErrorCode, Rn as SessionId, g as accessAllows, hn as updateSpawnRecord, i as ConvenoError, ln as takeAcpLaunchFile, wn as CliKind } from "./dist-ZL7d4_97.js";
1
+ import { n as connect } from "./dist-BgAfkqeX.js";
2
+ import { $ as findModelOption, Bt as planProgram, In as CliKind, Mn as writeModelMenu, Tn as updateSpawnRecord, Tt as modelLabel, Zn as SessionId, an as resolveAcpProgram, d as SPAWN_TABLE, et as findOnPath, g as accessAllows, qn as RpcErrorCode, r as ConvenoError, s as NPX_SETUP_TIMEOUT_MS, tt as formatContinuation, wt as menuFromConfigOptions, yn as takeAcpLaunchFile } from "./dist-Dc50_P_f.js";
3
3
  import { randomBytes } from "node:crypto";
4
4
  import { existsSync, rmSync } from "node:fs";
5
5
  import { Readable, Writable } from "node:stream";
6
6
  import { PROTOCOL_VERSION, client, methods, ndJsonStream } from "@agentclientprotocol/sdk";
7
7
  import { spawn, spawnSync } from "node:child_process";
8
8
  // ../acp/dist/index.js
9
+ var version = "0.2.0-rc.17";
9
10
  /**
10
11
  * Pick the option to answer with. Allowing uses `allow_once` only: `allow_always` would change the
11
12
  * CLI's own saved permissions, which is the user's call. Denying uses `reject_once`, and when the
@@ -205,10 +206,14 @@ var ToolTracker = class {
205
206
  return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
206
207
  }
207
208
  };
208
- const HOST_VERSION = "0.2.0-rc.15";
209
+ const HOST_VERSION = version;
210
+ /** How long the agent gets to answer `initialize` and `session/new`. */
211
+ const SETUP_TIMEOUT_MS = 12e4;
212
+ /** How often the host looks for a stop request from `conveno stop`. */
213
+ const STOP_POLL_MS = 500;
209
214
  /** A stop request file: `conveno stop` writes it next to the spawn record. */
210
215
  const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
211
- function withTimeout(p, ms, what) {
216
+ function withTimeout$1(p, ms, what) {
212
217
  return new Promise((resolve, reject) => {
213
218
  const t = setTimeout(() => reject(/* @__PURE__ */ new Error(`${what} did not answer within ${Math.round(ms / 1e3)} s.`)), ms);
214
219
  p.then((v) => {
@@ -220,11 +225,11 @@ function withTimeout(p, ms, what) {
220
225
  });
221
226
  });
222
227
  }
223
- const errText = (e) => e instanceof Error ? e.message : String(e);
228
+ const errText$1 = (e) => e instanceof Error ? e.message : String(e);
224
229
  /** A JSON-RPC error's own words: an agent that throws gets "Internal error" with the text in `data.details`. */
225
230
  const requestReason = (e) => {
226
231
  const details = e?.data?.details;
227
- return typeof details === "string" && details.trim() !== "" ? details.trim() : errText(e);
232
+ return typeof details === "string" && details.trim() !== "" ? details.trim() : errText$1(e);
228
233
  };
229
234
  const describeStop = (r) => {
230
235
  switch (r.kind) {
@@ -249,6 +254,8 @@ var AcpHost = class {
249
254
  policy;
250
255
  tools = new ToolTracker();
251
256
  sessionId;
257
+ /** The model label, sent again with each heartbeat so a restarted daemon still shows it. */
258
+ modelLabel;
252
259
  acpSessionId;
253
260
  conn;
254
261
  agent;
@@ -260,12 +267,16 @@ var AcpHost = class {
260
267
  /** The status line after a failed prompt, kept until the next prompt starts. */
261
268
  failedText;
262
269
  denials = [];
263
- /** A denied call of a worker nobody spawned, shown until the next turn starts. */
270
+ /** The last denied call, shown on the row until the next turn starts. */
264
271
  deniedText;
265
272
  /** The worker called Conveno's `send` (or `handoff`) in the turn that is running. */
266
273
  sentThisTurn = false;
267
274
  /** The daemon's `lastSentAt` of this session when the turn began. */
268
275
  sentAtTurnStart;
276
+ /** The messages the next turn's prompt hands over; undefined for the first task. */
277
+ answering;
278
+ /** When the newest message from a session that the running turn hands over was sent. */
279
+ askedAt;
269
280
  /** Status updates go out one after another, so a late one cannot overwrite a newer one. */
270
281
  statusChain = Promise.resolve();
271
282
  lastStatus;
@@ -311,7 +322,7 @@ var AcpHost = class {
311
322
  } catch (e) {
312
323
  if (!this.stopping) this.stop({
313
324
  kind: "failed",
314
- detail: errText(e)
325
+ detail: errText$1(e)
315
326
  });
316
327
  } finally {
317
328
  process.off("SIGTERM", onSignal);
@@ -322,7 +333,7 @@ var AcpHost = class {
322
333
  }
323
334
  async setup() {
324
335
  const { spec } = this;
325
- const timeout = spec.setupTimeoutMs ?? this.deps.setupTimeoutMs ?? 12e4;
336
+ const timeout = spec.setupTimeoutMs ?? this.deps.setupTimeoutMs ?? SETUP_TIMEOUT_MS;
326
337
  this.agent = await this.deps.startAgent(spec);
327
338
  const agent = this.agent;
328
339
  this.log(`started ${spec.file} (pid ${agent.pid}) for ${spec.name}`);
@@ -337,7 +348,7 @@ var AcpHost = class {
337
348
  pid: process.pid,
338
349
  agentPid: agent.pid
339
350
  });
340
- this.every(this.deps.stopPollMs ?? 500, () => {
351
+ this.every(this.deps.stopPollMs ?? STOP_POLL_MS, () => {
341
352
  const path = stopRequestPath(spec.record);
342
353
  if (existsSync(path)) {
343
354
  rmSync(path, { force: true });
@@ -350,7 +361,7 @@ var AcpHost = class {
350
361
  const app = client({ name: "conveno" }).onNotification(methods.client.session.update, ({ params }) => this.onUpdate(params)).onRequest(methods.client.session.requestPermission, ({ params }) => this.onPermission(params));
351
362
  this.conn = app.connect(ndJsonStream(Writable.toWeb(agent.stdin), Readable.toWeb(agent.stdout)));
352
363
  const conn = this.conn;
353
- const init = await this.untilStopped(withTimeout(conn.agent.request(methods.agent.initialize, {
364
+ const init = await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.initialize, {
354
365
  protocolVersion: PROTOCOL_VERSION,
355
366
  clientCapabilities: {
356
367
  fs: {
@@ -366,7 +377,7 @@ var AcpHost = class {
366
377
  }), timeout, "initialize"));
367
378
  const agentVersion = init.agentInfo?.version?.trim().slice(0, 64);
368
379
  this.log(`initialize: protocol ${init.protocolVersion}, agent ${init.agentInfo?.name ?? "unknown"} ${agentVersion ?? ""}`);
369
- const created = await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.new, {
380
+ const created = await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.new, {
370
381
  cwd: spec.cwd,
371
382
  mcpServers: spec.mcp ? [{
372
383
  name: "conveno",
@@ -378,18 +389,19 @@ var AcpHost = class {
378
389
  this.acpSessionId = created.sessionId;
379
390
  this.log(`session/new: ${created.sessionId}`);
380
391
  const mode = spec.mode;
381
- if (mode && created.modes?.availableModes.some((m) => m.id === mode)) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setMode, {
392
+ if (mode && created.modes?.availableModes.some((m) => m.id === mode)) await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.setMode, {
382
393
  sessionId: created.sessionId,
383
394
  modeId: mode
384
- }), timeout, "session/set_mode")).then(() => this.log(`mode: ${mode}`), (e) => this.log(`could not set mode ${mode}: ${errText(e)}`));
395
+ }), timeout, "session/set_mode")).then(() => this.log(`mode: ${mode}`), (e) => this.log(`could not set mode ${mode}: ${errText$1(e)}`));
385
396
  else if (mode) {
386
397
  const configId = modeConfigId(created.configOptions, mode);
387
- if (configId) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setConfigOption, {
398
+ if (configId) await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.setConfigOption, {
388
399
  sessionId: created.sessionId,
389
400
  configId,
390
401
  value: mode
391
- }), timeout, "session/set_config_option")).then(() => this.log(`mode: ${mode} (config option ${configId})`), (e) => this.log(`could not set mode ${mode}: ${errText(e)}`));
402
+ }), timeout, "session/set_config_option")).then(() => this.log(`mode: ${mode} (config option ${configId})`), (e) => this.log(`could not set mode ${mode}: ${errText$1(e)}`));
392
403
  }
404
+ const modelState = await this.applyModel(conn, created.sessionId, created.configOptions, timeout);
393
405
  const spawnedBy = SessionId.safeParse(spec.spawnedBy);
394
406
  const { session } = await this.client["session.register"]({
395
407
  name: spec.name,
@@ -400,21 +412,75 @@ var AcpHost = class {
400
412
  spawned: true,
401
413
  acp: true,
402
414
  ...spawnedBy.success ? { spawnedBy: spawnedBy.data } : {},
403
- ...agentVersion ? { cliVersion: agentVersion } : {}
415
+ ...agentVersion ? { cliVersion: agentVersion } : {},
416
+ ...modelState.label ? { model: modelState.label.slice(0, 200) } : {}
404
417
  });
405
418
  this.sessionId = session.id;
419
+ this.modelLabel = modelState.label?.slice(0, 200);
406
420
  await this.client["session.setNative"]({
407
421
  sessionId: session.id,
408
422
  nativeId: created.sessionId.slice(0, 256)
409
- }).catch((e) => this.log(`could not record the ACP session id: ${errText(e)}`));
423
+ }).catch((e) => this.log(`could not record the ACP session id: ${errText$1(e)}`));
410
424
  updateSpawnRecord(spec.record, {
411
425
  pid: process.pid,
412
426
  sessionId: session.id,
413
427
  agentPid: agent.pid
414
428
  });
415
429
  this.log(`registered as ${session.name} (${session.id})`);
430
+ for (const note of modelState.notes) await this.tell(`[conveno] Worker ${spec.name}: ${note}`);
416
431
  this.every(this.deps.heartbeatMs ?? 15e3, () => this.heartbeat());
417
432
  }
433
+ /**
434
+ * Set the worker's model, then its effort (the effort list can change with the model), through
435
+ * the CLI's session config options. Never fails the worker: a name the CLI does not offer or an
436
+ * error keeps the CLI's default and leaves a note for the spawner.
437
+ */
438
+ async applyModel(conn, sessionId, initial, timeout) {
439
+ const { spec } = this;
440
+ let options = initial;
441
+ const notes = [];
442
+ const set = async (kind, want) => {
443
+ if (!want) return;
444
+ const opt = findModelOption(options, kind);
445
+ if (!opt) {
446
+ this.log(`${kind}: '${want}' not offered; ${spec.cli} has no ${kind} choice here`);
447
+ notes.push(`${kind} '${want}' is not offered by ${spec.cli}: it has no ${kind} choice here.`);
448
+ return;
449
+ }
450
+ if (!opt.values.some((v) => v.value === want)) {
451
+ const names = opt.values.map((v) => v.value);
452
+ const offered = names.slice(0, 20).join(", ") + (names.length > 20 ? ` and ${names.length - 20} more` : "");
453
+ this.log(`${kind}: '${want}' not offered${opt.current ? `; using ${opt.current}` : ""}. Offered: ${offered}`);
454
+ notes.push(`${kind} '${want}' is not offered by ${spec.cli}${opt.current ? `; it uses ${opt.current}` : ""}. Offered: ${offered}.`);
455
+ return;
456
+ }
457
+ try {
458
+ const r = await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.setConfigOption, {
459
+ sessionId,
460
+ configId: opt.id,
461
+ value: want
462
+ }), timeout, "session/set_config_option"));
463
+ if (Array.isArray(r?.configOptions) && r.configOptions.length > 0) options = r.configOptions;
464
+ } catch (e) {
465
+ this.log(`could not set ${kind} ${want}: ${errText$1(e)}`);
466
+ notes.push(`${kind} '${want}' could not be set on ${spec.cli}; it keeps its default.`);
467
+ }
468
+ };
469
+ await set("model", spec.model);
470
+ await set("effort", spec.effort);
471
+ const m = findModelOption(options, "model");
472
+ const e = findModelOption(options, "effort");
473
+ const label = modelLabel({
474
+ ...m?.current ? { model: m.current } : {},
475
+ ...e?.current ? { effort: e.current } : {}
476
+ });
477
+ if (label) this.log(`model: ${label}`);
478
+ if (spec.modelMenuPath && m) writeModelMenu(spec.modelMenuPath, CliKind.parse(spec.cli), menuFromConfigOptions(options, (/* @__PURE__ */ new Date()).toISOString()));
479
+ return {
480
+ label,
481
+ notes
482
+ };
483
+ }
418
484
  async loop() {
419
485
  let next = this.spec.task ?? null;
420
486
  if (next === null) await this.status("idle", null);
@@ -432,6 +498,7 @@ var AcpHost = class {
432
498
  sessionId: this.me,
433
499
  allowContinue: true
434
500
  });
501
+ this.answering = r.messages;
435
502
  const next = formatContinuation(r.messages, r.orchestrator, r.remaining) || null;
436
503
  if (next === null) await this.status(void 0, this.failedText ?? this.deniedText ?? null);
437
504
  return next;
@@ -439,11 +506,11 @@ var AcpHost = class {
439
506
  if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) {
440
507
  this.stop({
441
508
  kind: "session-gone",
442
- detail: errText(e)
509
+ detail: errText$1(e)
443
510
  });
444
511
  return null;
445
512
  }
446
- this.log(`turn.end failed: ${errText(e)}`);
513
+ this.log(`turn.end failed: ${errText$1(e)}`);
447
514
  await this.status("idle", this.failedText ?? this.deniedText ?? null);
448
515
  return null;
449
516
  }
@@ -461,6 +528,8 @@ var AcpHost = class {
461
528
  this.denials = [];
462
529
  this.deniedText = void 0;
463
530
  this.sentThisTurn = false;
531
+ this.askedAt = (this.answering ?? []).filter((m) => m.kind !== "system").map((m) => m.createdAt).sort().at(-1);
532
+ this.answering = void 0;
464
533
  this.sentAtTurnStart = await this.lastSentAt();
465
534
  await this.status("busy", null);
466
535
  const turn = conn.agent.request(methods.agent.session.prompt, {
@@ -514,7 +583,10 @@ var AcpHost = class {
514
583
  sessionId: id,
515
584
  listenerId
516
585
  });
517
- if (r.messages.length > 0) return formatContinuation(r.messages, r.orchestrator, r.remaining);
586
+ if (r.messages.length > 0) {
587
+ this.answering = r.messages;
588
+ return formatContinuation(r.messages, r.orchestrator, r.remaining);
589
+ }
518
590
  if (r.superseded) {
519
591
  this.log("turn.wake: superseded; listening again");
520
592
  return null;
@@ -538,11 +610,11 @@ var AcpHost = class {
538
610
  if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) {
539
611
  this.stop({
540
612
  kind: "session-gone",
541
- detail: errText(e)
613
+ detail: errText$1(e)
542
614
  });
543
615
  return null;
544
616
  }
545
- this.log(`waiting for work failed: ${errText(e)}`);
617
+ this.log(`waiting for work failed: ${errText$1(e)}`);
546
618
  await new Promise((r) => setTimeout(r, Math.min(pollMs, 5e3)).unref());
547
619
  return null;
548
620
  } finally {
@@ -581,10 +653,8 @@ var AcpHost = class {
581
653
  if (!decision.allowed) {
582
654
  const what = `${title ?? "a tool call"} (${kind ?? "other"})`;
583
655
  this.denials.push(`${what}: ${decision.why ?? "it was not allowed"}`);
584
- if (!this.spec.spawnedBy) {
585
- this.deniedText = `denied: ${title ?? what}`;
586
- this.status(void 0, this.deniedText);
587
- }
656
+ this.deniedText = `denied: ${title ?? what}`;
657
+ this.status(void 0, this.deniedText);
588
658
  }
589
659
  return { outcome: decision.outcome };
590
660
  }
@@ -606,16 +676,24 @@ var AcpHost = class {
606
676
  this.statusChain = done;
607
677
  await done;
608
678
  }
609
- /** When the daemon last saw this session send a message; undefined if never, or unknown. */
610
- async lastSentAt() {
679
+ /** This session as the daemon has it now; undefined when unknown. */
680
+ async self() {
611
681
  if (!this.sessionId) return void 0;
612
682
  try {
613
683
  const { sessions } = await this.client["session.list"]({ includeOffline: true });
614
- return sessions.find((x) => x.id === this.sessionId)?.lastSentAt;
684
+ return sessions.find((x) => x.id === this.sessionId);
615
685
  } catch {
616
686
  return;
617
687
  }
618
688
  }
689
+ /** When the daemon last saw this session send a message; undefined if never, or unknown. */
690
+ async lastSentAt() {
691
+ return (await this.self())?.lastSentAt;
692
+ }
693
+ /** How a notice names this worker: by its name now, which a rename may have changed. */
694
+ async who() {
695
+ return `[conveno] Worker ${(await this.self())?.name ?? this.spec.name} (${this.spec.cli}, over ACP)`;
696
+ }
619
697
  /** Show that the worker waits for its spawner's answer; null puts the usual status back. */
620
698
  async waitingFor(title) {
621
699
  await this.status(void 0, title === null ? this.deniedText ?? this.lastStatus ?? null : `waiting for permission: ${title}`);
@@ -623,11 +701,14 @@ var AcpHost = class {
623
701
  async heartbeat() {
624
702
  if (!this.sessionId) return;
625
703
  try {
626
- await this.client["session.heartbeat"]({ sessionId: this.sessionId });
704
+ await this.client["session.heartbeat"]({
705
+ sessionId: this.sessionId,
706
+ ...this.modelLabel ? { model: this.modelLabel } : {}
707
+ });
627
708
  } catch (e) {
628
709
  if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) this.stop({
629
710
  kind: "session-gone",
630
- detail: errText(e)
711
+ detail: errText$1(e)
631
712
  });
632
713
  }
633
714
  }
@@ -650,7 +731,7 @@ var AcpHost = class {
650
731
  await this.status("idle", this.failedText);
651
732
  if (reason === this.lastPromptFailure) return;
652
733
  this.lastPromptFailure = reason;
653
- 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.`);
734
+ await this.tell(`${await this.who()} could not run a prompt: ${reason}. It keeps running and takes the next message.`);
654
735
  }
655
736
  /** Remember that the worker sent something this turn. Only Conveno's own send tools count. */
656
737
  noteConvenoCall(call) {
@@ -668,9 +749,14 @@ var AcpHost = class {
668
749
  this.denials = [];
669
750
  if (!this.spec.spawnedBy) return;
670
751
  let silent = finished && !this.sentThisTurn;
671
- if (silent && await this.lastSentAt() !== this.sentAtTurnStart) silent = false;
752
+ if (silent) {
753
+ const sent = await this.lastSentAt();
754
+ const askedAt = this.askedAt;
755
+ if (sent !== this.sentAtTurnStart) silent = false;
756
+ else if (sent !== void 0 && askedAt !== void 0 && sent >= askedAt) silent = false;
757
+ }
672
758
  if (denials.length === 0 && !silent) return;
673
- const who = `[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP)`;
759
+ const who = await this.who();
674
760
  const lines = [];
675
761
  if (silent) lines.push(`${who} finished its turn without replying.`);
676
762
  if (denials.length > 0) {
@@ -690,7 +776,7 @@ var AcpHost = class {
690
776
  kind: "text",
691
777
  body: { text }
692
778
  }).catch((e) => {
693
- this.log(`could not message the spawner: ${errText(e)}`);
779
+ this.log(`could not message the spawner: ${errText$1(e)}`);
694
780
  });
695
781
  }
696
782
  every(ms, fn) {
@@ -731,7 +817,7 @@ var AcpHost = class {
731
817
  }
732
818
  if (this.sessionId) {
733
819
  const why = describeStop(reason);
734
- if (reason.kind !== "session-gone") await this.tell(`[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP) stopped: ${why}. Its session is now offline.`);
820
+ if (reason.kind !== "session-gone") await this.tell(`${await this.who()} stopped: ${why}. Its session is now offline.`);
735
821
  await this.client["session.unregister"]({ sessionId: this.sessionId }).catch(() => void 0);
736
822
  }
737
823
  rmSync(this.spec.record, { force: true });
@@ -831,6 +917,124 @@ function startAgentProcess(opts) {
831
917
  });
832
918
  });
833
919
  }
920
+ /** An agent that throws gets "Internal error" from the SDK, with its own words in `data.details`. */
921
+ const errText = (e) => {
922
+ const details = e?.data?.details;
923
+ if (typeof details === "string" && details.trim() !== "") return details.trim();
924
+ return e instanceof Error ? e.message : String(e);
925
+ };
926
+ function withTimeout(p, ms, what) {
927
+ let timer;
928
+ const late = new Promise((_, reject) => {
929
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`${what} timed out after ${ms / 1e3}s.`)), ms);
930
+ });
931
+ return Promise.race([p, late]).finally(() => clearTimeout(timer));
932
+ }
933
+ /**
934
+ * Start `cli`'s ACP server, read the models and efforts it offers, and stop it (with everything it
935
+ * started). Never throws: a failure comes back as a message fit to show.
936
+ */
937
+ async function probeModelMenu(opts) {
938
+ const platform = opts.platform;
939
+ const spec = SPAWN_TABLE[opts.cli]?.acp;
940
+ let launch;
941
+ let timeout = opts.timeoutMs ?? 6e4;
942
+ if (opts.command) launch = {
943
+ file: opts.command.file,
944
+ args: opts.command.args
945
+ };
946
+ else {
947
+ if (!spec) return {
948
+ ok: false,
949
+ message: `${opts.cli} cannot run in the background.`
950
+ };
951
+ const res = resolveAcpProgram(opts.cli, spec, {
952
+ env: opts.env,
953
+ which: opts.which ?? ((name) => findOnPath(name, opts.env, platform)),
954
+ npxConsent: opts.npxConsent
955
+ });
956
+ if (!res.ok) return {
957
+ ok: false,
958
+ message: res.reason === "no-npx" ? `${opts.cli} needs npx to start, and npx was not found. Install Node.js.` : `${opts.cli} is not installed for background workers. Run conveno init to set it up.`
959
+ };
960
+ if (res.run.source.startsWith("npx:") && opts.timeoutMs === void 0) timeout = NPX_SETUP_TIMEOUT_MS;
961
+ launch = planProgram(res.run.program, [...res.run.args, ...spec.args], {
962
+ platform,
963
+ env: opts.env
964
+ });
965
+ }
966
+ const CANCELLED = "Cancelled.";
967
+ if (opts.signal?.aborted) return {
968
+ ok: false,
969
+ message: CANCELLED
970
+ };
971
+ let agent;
972
+ let onAbort;
973
+ const cancelled = new Promise((_, reject) => {
974
+ onAbort = () => {
975
+ agent?.killTree();
976
+ reject(/* @__PURE__ */ new Error(CANCELLED));
977
+ };
978
+ opts.signal?.addEventListener("abort", onAbort, { once: true });
979
+ });
980
+ cancelled.catch(() => void 0);
981
+ try {
982
+ agent = await startAgentProcess({
983
+ file: launch.file,
984
+ args: launch.args,
985
+ cwd: opts.home,
986
+ env: opts.env,
987
+ platform,
988
+ stderr: new Writable({ write: (_c, _e, done) => done() }),
989
+ ...launch.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
990
+ });
991
+ if (opts.signal?.aborted) return {
992
+ ok: false,
993
+ message: CANCELLED
994
+ };
995
+ const gone = agent.exited.then(({ code, signal }) => {
996
+ throw new Error(`${opts.cli} stopped before it answered (${signal ?? `exit ${code}`}).`);
997
+ });
998
+ gone.catch(() => void 0);
999
+ const conn = client({ name: "conveno" }).connect(ndJsonStream(Writable.toWeb(agent.stdin), Readable.toWeb(agent.stdout)));
1000
+ const step = (p, what) => Promise.race([
1001
+ withTimeout(p, timeout, what),
1002
+ gone,
1003
+ cancelled
1004
+ ]);
1005
+ await step(conn.agent.request(methods.agent.initialize, {
1006
+ protocolVersion: PROTOCOL_VERSION,
1007
+ clientCapabilities: {
1008
+ fs: {
1009
+ readTextFile: false,
1010
+ writeTextFile: false
1011
+ },
1012
+ terminal: false
1013
+ },
1014
+ clientInfo: {
1015
+ name: "conveno",
1016
+ version: "probe"
1017
+ }
1018
+ }), "initialize");
1019
+ const created = await step(conn.agent.request(methods.agent.session.new, {
1020
+ cwd: opts.home,
1021
+ mcpServers: []
1022
+ }), "session/new");
1023
+ const at = (opts.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
1024
+ return {
1025
+ ok: true,
1026
+ menu: menuFromConfigOptions(created.configOptions, at)
1027
+ };
1028
+ } catch (e) {
1029
+ return {
1030
+ ok: false,
1031
+ message: opts.signal?.aborted ? CANCELLED : errText(e)
1032
+ };
1033
+ } finally {
1034
+ if (onAbort) opts.signal?.removeEventListener("abort", onAbort);
1035
+ agent?.killTree();
1036
+ }
1037
+ }
834
1038
  /**
835
1039
  * `conveno acp-host <launch file>`: read and delete the launch file, connect to the daemon and
836
1040
  * drive the worker until it stops. Returns the exit code.
@@ -858,4 +1062,4 @@ async function runAcpHostFromFile(path, opts = {}) {
858
1062
  await client.close().catch(() => void 0);
859
1063
  }
860
1064
  }
861
- export { runAcpHostFromFile as n, stopRequestPath as r, killProcessTree as t };
1065
+ export { stopRequestPath as i, probeModelMenu as n, runAcpHostFromFile as r, killProcessTree as t };
@@ -1,5 +1,5 @@
1
1
  import { appendFileSync } from "node:fs";
2
- import { S as appendHookLog, it as hookLogLine } from "./dist-ZL7d4_97.js";
2
+ import { S as appendHookLog, ot as hookLogLine } from "./dist-Dc50_P_f.js";
3
3
  import { n as connectOpts } from "./ctx-tYftvhz_.js";
4
4
  // src/hook.ts
5
5
  /**
@@ -140,7 +140,7 @@ async function runHook(ctx, argv) {
140
140
  hostPid ??= (async () => {
141
141
  const t = Date.now();
142
142
  try {
143
- const pid = await findHostPid(ctx, connected, adapter.cli, () => early ?? ctx.ancestry(1200));
143
+ const pid = await findHostPid(ctx, connected, adapter.cli, () => early ?? ctx.ancestry(HOOK_ANCESTRY_TIMEOUT_MS));
144
144
  if (pid === void 0) hostMissing = true;
145
145
  return pid;
146
146
  } finally {
@@ -0,0 +1 @@
1
+ export { i as runHookEntry } from "./hook-entry-DYXjVztc.js";
@@ -1,13 +1,13 @@
1
1
  import { homedir } from "node:os";
2
- import { n as antigravityAdapter } from "./dist-Bv1bmmme.js";
2
+ import { n as antigravityAdapter } from "./dist-CTw3arJP.js";
3
3
  import { isAbsolute, join } from "node:path";
4
- import { At as pendingHookContext, B as dataDir, Gt as readSettings, J as endTurnContinuation, Tt as parseCliVersion, V as dataPaths, Vt as readAncestry, Zt as requeueMessages, _n as waitForWork, at as hookLogPath, jt as pendingTurn, ot as hostAlive, r as CLAUDE_PENDING_TURN_FOLDER, sn as startTurnContext, vn as waitForWorkBatch, wt as ownSession } from "./dist-ZL7d4_97.js";
4
+ import { At as parseCliVersion, Dn as waitForWork, Ft as pendingHookContext, H as dataPaths, It as pendingTurn, Kt as readAncestry, On as waitForWorkBatch, V as dataDir, Y as endTurnContinuation, Zt as readSettings, _n as startTurnContext, ct as hostAlive, in as requeueMessages, kt as ownSession, n as CLAUDE_PENDING_TURN_FOLDER, st as hookLogPath } from "./dist-Dc50_P_f.js";
5
5
  import { readFile } from "node:fs/promises";
6
6
  import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
7
- import { t as codexAdapter } from "./dist-DDzIkwf9.js";
8
- import { t as grokAdapter } from "./dist-C4KljaIP.js";
9
- import { n as connect } from "./dist-C59LTq60.js";
10
- import { t as runHook } from "./hook-BFZTvd7M.js";
7
+ import { t as codexAdapter } from "./dist-CvKAege3.js";
8
+ import { t as grokAdapter } from "./dist-Bb2opAjB.js";
9
+ import { n as connect } from "./dist-BgAfkqeX.js";
10
+ import { t as runHook } from "./hook-BLSrNkFF.js";
11
11
  // ../adapters/claude/dist/index.js
12
12
  const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
13
13
  /** Read a JSON object file. Missing or blank files give `{}`; anything else that is not a JSON object throws. */
@@ -176,7 +176,7 @@ function hookProgram(env, event) {
176
176
  /** One hook handler as written to settings.json. The listener runs in the background (`asyncRewake`). */
177
177
  function handlerFor(env, arg) {
178
178
  const { command, args } = hookProgram(env, arg);
179
- return arg === "Listen" ? {
179
+ return arg === LISTEN_EVENT ? {
180
180
  type: "command",
181
181
  command,
182
182
  args,
@@ -229,7 +229,7 @@ function hasExactHook(hooks, event, handler) {
229
229
  /** Every handler Conveno wants on `event` is there, exactly. */
230
230
  const eventComplete = (env, hooks, event) => HANDLERS[event].every((arg) => hasExactHook(hooks, event, handlerFor(env, arg)));
231
231
  /** The name `conveno doctor --verbose` shows for one event. Start and Stop also arm the listener. */
232
- const hookPartName = (e) => HANDLERS[e].includes("Listen") ? `${e} hook and listener` : `${e} hook`;
232
+ const hookPartName = (e) => HANDLERS[e].includes(LISTEN_EVENT) ? `${e} hook and listener` : `${e} hook`;
233
233
  const hasOurHandler = (g) => isObject(g) && Array.isArray(g.hooks) && g.hooks.some(isOurHook);
234
234
  /** Drop our hook handlers (and groups left empty by that). */
235
235
  function stripOurHooks(groups) {
@@ -1,13 +1,13 @@
1
- import { Cn as CLI_KINDS, Ot as parseWorkerAccess, V as dataPaths, d as SPAWN_TABLE, f as SpawnError, on as spawnSession, p as WORKER_ACCESS, qt as realSpawnDeps, tn as runLaunchFile, u as SPAWN_CLIS } from "./dist-ZL7d4_97.js";
2
- import { A as runRelay, I as runAccount, L as runLogin, M as runDaemon, P as VERSION, R as runLogout, b as workerAccessLine, i as runDoctor, k as runDevices, m as runSetup, p as runInit, t as runUninstall } from "./uninstall-DK25hyWX.js";
3
- import { a as parseFlags, i as commandHelp, n as COMMANDS, r as COMMAND_NAMES, t as ALL_COMMAND_NAMES } from "./args-CpAvszNY.js";
4
- import { t as daemonProblem } from "./daemonError-Bj22X-4V.js";
1
+ import { $t as realSpawnDeps, Fn as CLI_KINDS, H as dataPaths, M as cleanModelName, Nt as parseWorkerAccess, d as SPAWN_TABLE, f as SpawnError, gn as spawnSession, ln as runLaunchFile, p as WORKER_ACCESS, u as SPAWN_CLIS } from "./dist-Dc50_P_f.js";
2
+ import { A as runRelay, I as runAccount, L as runLogin, M as runDaemon, P as VERSION, R as runLogout, b as workerAccessLine, i as runDoctor, k as runDevices, m as runSetup, p as runInit, t as runUninstall } from "./uninstall-B-deU_wY.js";
3
+ import { a as parseFlags, i as commandHelp, n as COMMANDS, r as COMMAND_NAMES, t as ALL_COMMAND_NAMES } from "./args-CtyKPZuN.js";
4
+ import { t as daemonProblem } from "./daemonError-BwdtKOCy.js";
5
5
  import { chmod, mkdir, writeFile } from "node:fs/promises";
6
6
  import { join, resolve } from "node:path";
7
7
  import { a as fail, c as plural, d as warnBlock, n as cmd, r as columns, s as plainError, t as closest, u as tilde } from "./fmt-C2SsP5Y0.js";
8
- import { t as runHook } from "./hook-BFZTvd7M.js";
8
+ import { t as runHook } from "./hook-BLSrNkFF.js";
9
9
  import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
10
- import { t as findSession } from "./pick-DaCRjuyz.js";
10
+ import { t as findSession } from "./pick-iuG24FX9.js";
11
11
  import { readFileSync } from "node:fs";
12
12
  // src/errorLog.ts
13
13
  /** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
@@ -297,6 +297,23 @@ async function runSpawn(ctx, argv) {
297
297
  exit: 2,
298
298
  ref: "e_usage"
299
299
  });
300
+ const model = cleanModelName(str("model"));
301
+ const effort = cleanModelName(str("effort"));
302
+ for (const [flag, given, clean] of [[
303
+ "model",
304
+ str("model"),
305
+ model
306
+ ], [
307
+ "effort",
308
+ str("effort"),
309
+ effort
310
+ ]]) if (given !== void 0 && clean === void 0) return fail(ctx, {
311
+ what: `--${flag} is empty, too long or has a line break`,
312
+ detail: ["Give the CLI's own name, up to 200 characters."],
313
+ fix: help,
314
+ exit: 2,
315
+ ref: "e_usage"
316
+ });
300
317
  const window = parsed.values.window === true;
301
318
  const yes = parsed.values.yes === true;
302
319
  const adapter = ctx.adapters.find((a) => a.cli === cli);
@@ -352,6 +369,8 @@ async function runSpawn(ctx, argv) {
352
369
  task,
353
370
  window,
354
371
  access,
372
+ model,
373
+ effort,
355
374
  confineToHome: false,
356
375
  onProgress: (line) => ctx.err(`${t.paint("quiet", line)}\n`)
357
376
  });
@@ -443,7 +462,7 @@ function renderSessions(ctx, sessions) {
443
462
  const tags = [...s.isOrchestrator ? [t.paint("entry", "lead")] : [], ...s.spawned || s.spawnedBy ? [q("spawned")] : []];
444
463
  return [
445
464
  `${st.glyph} ${t.bold(s.name)}${tags.length > 0 ? ` ${tags.join(" ")}` : ""}`,
446
- s.variant === "app" ? "Antigravity app" : toolName(s.cli),
465
+ (s.variant === "app" ? "Antigravity app" : toolName(s.cli)) + (s.model ? q(` · ${s.model.length > 30 ? `${s.model.slice(0, 29)}…` : s.model}`) : ""),
447
466
  st.word,
448
467
  ...waiting ? [s.unreadCount ? String(s.unreadCount) : q("none")] : [],
449
468
  ...doing ? [s.statusText ?? ""] : []
@@ -471,6 +490,7 @@ function relaySummary(r) {
471
490
  case "connecting": return "connecting";
472
491
  case "disconnected": return "not connected, trying again";
473
492
  case "revoked": return "off, this device was removed";
493
+ case "upgrade_required": return "off, Conveno needs an update";
474
494
  case "unpaired": return "off, no paired devices";
475
495
  default: return "off";
476
496
  }
@@ -501,6 +521,10 @@ async function runStatus(ctx, argv = []) {
501
521
  "connecting",
502
522
  "disconnected"
503
523
  ].includes(relay.state)) ctx.out(` Your other devices: ${relaySummary(relay)}\n`);
524
+ else if (relay?.state === "upgrade_required") {
525
+ ctx.out(` Your other devices: ${relaySummary(relay)}\n`);
526
+ if (relay.detail) ctx.out(` ${relay.detail}\n`);
527
+ }
504
528
  if (sessions.length === 0) {
505
529
  ctx.out(`\nNo sessions yet. Open an AI tool you have connected with ${cmd(t, "conveno setup")} and it appears here.\n`);
506
530
  return 0;
@@ -585,11 +609,11 @@ async function dispatch(name, rest, ctx) {
585
609
  case "rename": return runRename(ctx, rest);
586
610
  case "lead": return runLead(ctx, rest);
587
611
  case "spawn": return runSpawn(ctx, rest);
588
- case "acp-host": return (await import("./acp-DZf0zyNC.js")).runAcpHostCmd(ctx, rest);
589
- case "stop": return (await import("./acp-DZf0zyNC.js")).runStop(ctx, rest);
612
+ case "acp-host": return (await import("./acp-C-o3rtAB.js")).runAcpHostCmd(ctx, rest);
613
+ case "stop": return (await import("./acp-C-o3rtAB.js")).runStop(ctx, rest);
590
614
  case "spawn-run": return runSpawnRun(ctx, rest);
591
- case "agy-relay": return (await import("./agy-relay-DSRJtMz3.js")).runAgyRelay(ctx, rest);
592
- case "watch": return (await import("./watch-De3wbdQL.js")).runWatch(ctx, rest);
615
+ case "agy-relay": return (await import("./agy-relay-D17zTd_Z.js")).runAgyRelay(ctx, rest);
616
+ case "watch": return (await import("./watch-CPZ2X-yt.js")).runWatch(ctx, rest);
593
617
  case "devices": return runDevices(ctx, rest);
594
618
  case "relay": return runRelay(ctx, rest);
595
619
  case "doctor": return runDoctor(ctx, rest);
@@ -628,7 +652,7 @@ function opensApp(env, tty = {
628
652
  async function main(argv, ctx) {
629
653
  const [command, ...rest] = argv;
630
654
  if (command === void 0 && opensApp(ctx.env)) try {
631
- return await (await import("./run-CKiYjNqx.js")).runTui(ctx);
655
+ return await (await import("./run-B01nDeos.js")).runTui(ctx);
632
656
  } catch (e) {
633
657
  ctx.err(`The app could not start (${rawMessage(e)}). Showing the help instead.\n`);
634
658
  ctx.out(helpText(ctx));