@tablation/crew 0.150.2 → 0.151.1

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +201 -241
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -243,7 +243,7 @@ now on disk. `crew daemon restart` forces this immediately, for a manual
243
243
  ## Commands
244
244
 
245
245
  ```
246
- crew poll [route] decide a cycle and report it; writes nothing
246
+ crew poll [route] [--verbose] decide a cycle and report it; writes nothing; --verbose adds counts and timestamps
247
247
  crew run [route] [--role R] run the winning role's session, then release
248
248
  crew daemon [route] run the persistent supervisor loop in the foreground (every enabled route when none is named)
249
249
  crew daemon start|stop|status control the installed `run` service directly
package/dist/cli.js CHANGED
@@ -1285,7 +1285,7 @@ var Emitter = class _Emitter {
1285
1285
  `);
1286
1286
  } catch {
1287
1287
  }
1288
- if (!e.routine || this.opts.verbose) {
1288
+ if (!e.routine || this.opts.verbose || !this.opts.plain) {
1289
1289
  try {
1290
1290
  (this.opts.console ?? ((l) => process.stderr.write(`${l}
1291
1291
  `)))(this.opts.plain ? renderPlain(e) : line);
@@ -1294,6 +1294,28 @@ var Emitter = class _Emitter {
1294
1294
  }
1295
1295
  return e;
1296
1296
  }
1297
+ /**
1298
+ * A line for a person at the terminal that is not an event (CREW-3285): the
1299
+ * closing count of a roll-up. Console only, never the event stream or log,
1300
+ * and hidden from a non-terminal console, which has the events it summarizes.
1301
+ */
1302
+ echo(message) {
1303
+ if (!this.opts.plain) return;
1304
+ try {
1305
+ (this.opts.console ?? ((l) => process.stderr.write(`${l}
1306
+ `)))(message);
1307
+ } catch {
1308
+ }
1309
+ }
1310
+ /**
1311
+ * Show lines already emitted as routine that a failure now makes relevant
1312
+ * (CREW-3285: a failed hook's output). Console only; nothing when the
1313
+ * console already showed them (`--verbose`) or is not a terminal.
1314
+ */
1315
+ replay(lines2) {
1316
+ if (!this.opts.plain || this.opts.verbose) return;
1317
+ for (const l of lines2) this.echo(l);
1318
+ }
1297
1319
  /** Routine progress: logged, but shown on the console only under `--verbose`. */
1298
1320
  note(message, extra = {}) {
1299
1321
  return this.emit(message, { ...extra, routine: true });
@@ -14150,7 +14172,7 @@ async function finishRun(id, obs, emit, startedAt, end, agentLogKey, hintMoved)
14150
14172
  } catch {
14151
14173
  }
14152
14174
  const ms3 = Date.now() - Date.parse(startedAt);
14153
- emit.emit(end.interrupted ? "agent run interrupted" : `agent run finished (${pending ? "hand-off pending" : `exit ${end.code ?? "unknown"}`})`, {
14175
+ emit.note(end.interrupted ? "agent run interrupted" : `agent run finished (${pending ? "hand-off pending" : `exit ${end.code ?? "unknown"}`})`, {
14154
14176
  data: {
14155
14177
  ms: ms3,
14156
14178
  code: end.code,
@@ -18917,7 +18939,7 @@ async function decideCycle(o) {
18917
18939
  ]);
18918
18940
  const directionEvents = (await Promise.all([...DIRECTION_EVENT_TYPES, ...STATUS_EVENT_TYPES, "pushed"].map((t) => tracker.events(t)))).flat();
18919
18941
  const statusChanges = await tracker.statusChanges();
18920
- emit.emit(`${tickets.length} open ticket(s), ${comments.length} comment(s)`, {
18942
+ emit.note(`${tickets.length} open ticket(s), ${comments.length} comment(s)`, {
18921
18943
  data: { tickets: tickets.length, comments: comments.length }
18922
18944
  });
18923
18945
  const epicColumn = tracker.contract.columns.epic;
@@ -18962,14 +18984,14 @@ async function decideCycle(o) {
18962
18984
  const stalled = planStalled(tickets, comments, ships, tracker.contract, holds2, Date.now(), workModes, stalledEvents);
18963
18985
  const skipped = skippedByMode(tickets, workModes);
18964
18986
  if (skipped.manual || skipped.hybrid) {
18965
- emit.emit(`sweeps skipped ${skipped.manual} manual/project-less and ${skipped.hybrid} unassigned hybrid ticket(s)`, {
18987
+ emit.note(`sweeps skipped ${skipped.manual} manual/project-less and ${skipped.hybrid} unassigned hybrid ticket(s)`, {
18966
18988
  data: { sweepSkipped: skipped }
18967
18989
  });
18968
18990
  }
18969
18991
  const blockedIssues = tickets.filter((t) => blocked.has(t.id)).map((t) => t.issue_id);
18970
- emit.emit(`${blockedIssues.length} ticket(s) parked as blocked`, { data: { blocked: blockedIssues } });
18992
+ emit.note(`${blockedIssues.length} ticket(s) parked as blocked`, { data: { blocked: blockedIssues } });
18971
18993
  const qaHeld = tickets.filter((t) => t.status === tracker.contract.statuses.verifying).map((t) => t.issue_id);
18972
- emit.emit(`${qaHeld.length} ticket(s) held in QA`, { data: { qaHeld } });
18994
+ emit.note(`${qaHeld.length} ticket(s) held in QA`, { data: { qaHeld } });
18973
18995
  const stranded = strandedNeedsInfo(tickets, blocked, holds2);
18974
18996
  for (const t of stranded) {
18975
18997
  emit.emit("needs_info with all blockers resolved \u2014 the operator's call, not the crew's", {
@@ -18982,7 +19004,7 @@ async function decideCycle(o) {
18982
19004
  };
18983
19005
  for (const r of rollUpParents(tickets, void 0, coordinating)) {
18984
19006
  if (r.complete) {
18985
- emit.emit(`every child is done \u2014 this coordinating ticket is too`, { ticket: r.parent.issue_id });
19007
+ emit.note(`every child is done \u2014 this coordinating ticket is too`, { ticket: r.parent.issue_id });
18986
19008
  }
18987
19009
  }
18988
19010
  const unroutableTickets = filingErrors(tickets, {
@@ -19002,9 +19024,10 @@ async function decideCycle(o) {
19002
19024
  { ticket: t.issue_id }
19003
19025
  );
19004
19026
  }
19005
- for (const t of gained) emit.emit("now has a repository \u2014 no longer unroutable", { ticket: t.issue_id });
19027
+ for (const t of gained) emit.note("now has a repository \u2014 no longer unroutable", { ticket: t.issue_id });
19006
19028
  if (unroutableTickets.length) {
19007
- emit.emit(
19029
+ (added.length ? emit.emit : emit.note).call(
19030
+ emit,
19008
19031
  `${unroutableTickets.length} open ticket(s) have no repository and are not routable (${added.length} new since last cycle)`,
19009
19032
  { step: "sweep", data: { unroutable: unroutableTickets.map((t) => t.issue_id), newUnroutable: added.map((a) => a.ticket.issue_id) } }
19010
19033
  );
@@ -19088,7 +19111,7 @@ async function decideCycle(o) {
19088
19111
  };
19089
19112
  const advanced = state.advanceWatermark([...comments, ...tickets], routeSlug(route2.route));
19090
19113
  if (advanced !== watermark) {
19091
- emit.emit(`watermark ${watermark.slice(0, 19)} -> ${advanced.slice(0, 19)}`, {
19114
+ emit.note(`watermark ${watermark.slice(0, 19)} -> ${advanced.slice(0, 19)}`, {
19092
19115
  step: "poll",
19093
19116
  data: { from: watermark, to: advanced }
19094
19117
  });
@@ -19192,7 +19215,7 @@ function writeDigest(o, d, role, stateDir, runId, own) {
19192
19215
  ${body}` : body;
19193
19216
  const path = digestPath(stateDir, routeSlug(o.route.route), role, runId);
19194
19217
  writeFileSync31(path, text2);
19195
- o.emit.emit(`queue digest written for ${role} (${Buffer.byteLength(text2)} bytes)`, {
19218
+ o.emit.note(`queue digest written for ${role} (${Buffer.byteLength(text2)} bytes)`, {
19196
19219
  data: { role, bytes: Buffer.byteLength(text2) }
19197
19220
  });
19198
19221
  return true;
@@ -20792,6 +20815,56 @@ ${h.prFailure.tail}
20792
20815
  }
20793
20816
  }
20794
20817
 
20818
+ // src/cli-output.ts
20819
+ function summarizeOutcomes(outcomes, describe2, isRoutine, noun, verbose) {
20820
+ if (verbose) return outcomes.map(describe2);
20821
+ const lines2 = outcomes.filter((o) => !isRoutine(o)).map(describe2);
20822
+ const routine = outcomes.length - lines2.length;
20823
+ if (routine > 0) lines2.push(`${routine} ${noun}${routine === 1 ? "" : "s"} already in sync`);
20824
+ return lines2;
20825
+ }
20826
+ function withFix(message, fix) {
20827
+ return `${message.replace(/[.\s]+$/, "")} \u2014 try: ${fix}`;
20828
+ }
20829
+ function summarizeJobs(results, o) {
20830
+ const state = o.uninstall ? "not installed" : "installed";
20831
+ const mark3 = o.dryRun ? " (dry run, not applied)" : "";
20832
+ const line = (r) => {
20833
+ if (o.dryRun) return `would ${o.uninstall ? "remove" : "install"} ${r.job} via ${r.mechanism} for ${o.host}${mark3}`;
20834
+ if (r.action === "unchanged") return `${r.job} already ${state} (${r.mechanism})`;
20835
+ return `${r.action} ${r.job} via ${r.mechanism} for ${o.host}`;
20836
+ };
20837
+ if (o.dryRun || o.verbose) return results.map(line);
20838
+ const lines2 = results.filter((r) => r.action !== "unchanged").map(line);
20839
+ const same2 = results.filter((r) => r.action === "unchanged");
20840
+ if (same2.length > 0) {
20841
+ const names = same2.map((r) => r.job).join(", ");
20842
+ lines2.push(same2.length === results.length ? `all ${same2.length} jobs already ${state} (${names})` : `${same2.length} job${same2.length === 1 ? "" : "s"} already ${state} (${names})`);
20843
+ }
20844
+ return lines2;
20845
+ }
20846
+ function describeRunOutcome(o) {
20847
+ const who2 = `${o.role}${o.ticket ? ` on ${o.ticket}` : ""}`;
20848
+ const status2 = `crew status ${o.route}`;
20849
+ if (o.run.killed) return withFix(`${who2}: run stopped at its ${o.run.killed.limitMinutes} min limit`, `\`${status2}\``);
20850
+ if (o.run.code !== 0) return withFix(`${who2}: run failed (exit ${o.run.code})`, `\`${status2}\` and the run's stream under the state directory`);
20851
+ if (o.run.handoffPending) return `${who2}: finished; the hand-off write is pending and replays next cycle`;
20852
+ const h = o.handoff;
20853
+ if (!h) return `${who2}: finished`;
20854
+ switch (h.kind) {
20855
+ case "pushed":
20856
+ return `${who2}: handed off`;
20857
+ case "bounced":
20858
+ return `${who2}: hand-off bounced, set back to in_progress`;
20859
+ case "unverified":
20860
+ return `${who2}: parked, ${h.why ?? "hand-off not verified"}`;
20861
+ case "failed":
20862
+ return withFix(`${who2}: hand-off failed, ${h.why ?? "unknown reason"}`, `\`${status2}\``);
20863
+ default:
20864
+ return `${who2}: finished without a hand-off`;
20865
+ }
20866
+ }
20867
+
20795
20868
  // src/release-run.ts
20796
20869
  function emitReleaseSummary(emit, summaries) {
20797
20870
  if (summaries.length <= 1) return;
@@ -20800,13 +20873,16 @@ function emitReleaseSummary(emit, summaries) {
20800
20873
  const rows = summaries.filter((s) => s.route === route2);
20801
20874
  const remit = emit.forRoute(route2);
20802
20875
  remit.enter("release");
20803
- remit.emit(`release summary \u2014 ${rows.length} repo(s):`);
20876
+ remit.note(`release summary \u2014 ${rows.length} repo(s):`);
20804
20877
  for (const s of rows) {
20805
20878
  const testLabel = s.tests === "pass" ? "tests passed" : s.tests === "fail" ? "tests FAILED" : "tests skipped";
20806
- remit.emit(` ${s.scope}: ${testLabel}, ${s.outcome} \u2014 ${s.detail}`, {
20807
- level: s.outcome === "error" || s.tests === "fail" ? "warn" : "info"
20808
- });
20879
+ const failed = s.outcome === "error" || s.tests === "fail";
20880
+ const line = ` ${s.scope}: ${testLabel}, ${s.outcome} \u2014 ${s.detail}`;
20881
+ if (s.outcome === "nothing" && !failed) remit.note(line);
20882
+ else remit.emit(line, { level: failed ? "warn" : "info" });
20809
20883
  }
20884
+ const idle = rows.filter((s) => s.outcome === "nothing" && s.tests !== "fail").length;
20885
+ if (idle > 0) remit.echo(`${idle} of ${rows.length} repo(s) had nothing to release`);
20810
20886
  }
20811
20887
  }
20812
20888
  function summarizeOutcome(o, scope, hadTestHook) {
@@ -20863,14 +20939,19 @@ async function rerunOnce(o, name, first) {
20863
20939
  var hook = async (o, name, env = {}) => {
20864
20940
  const script = o.repo.hooks[name];
20865
20941
  if (!script) return null;
20942
+ const lines2 = [];
20866
20943
  const result = await runScript(script, {
20867
20944
  cwd: o.cwd,
20868
20945
  env,
20869
20946
  shell: resolveShell(o.repo.shell ?? o.shell),
20870
20947
  onLine: (l) => {
20871
- if (l.trim()) o.emit.emit(l.trim(), { data: { hook: name } });
20948
+ if (l.trim()) {
20949
+ lines2.push(l.trim());
20950
+ o.emit.note(l.trim(), { data: { hook: name } });
20951
+ }
20872
20952
  }
20873
20953
  });
20954
+ if (result.code !== 0) o.emit.replay(lastLines(lines2.join("\n"), HOOK_FAILURE_TAIL_LINES).split("\n"));
20874
20955
  if (o.attention && !o.dryRun) {
20875
20956
  const key = `hook_missing:${o.scope ?? "release"}/${name}`;
20876
20957
  if (result.code === 127) {
@@ -20893,7 +20974,7 @@ async function detectExternalClosures(o, candidates2) {
20893
20974
  env,
20894
20975
  shell: resolveShell(o.repo.shell ?? o.shell),
20895
20976
  onLine: (l) => {
20896
- if (l.trim()) o.emit.emit(l.trim(), { data: { hook: "merged" } });
20977
+ if (l.trim()) o.emit.note(l.trim(), { data: { hook: "merged" } });
20897
20978
  }
20898
20979
  })).code : void 0;
20899
20980
  const out = [];
@@ -21035,7 +21116,7 @@ ${BRANCH_TIP_TRAILER}: ${tip}` : "";
21035
21116
 
21036
21117
  Closes ${c.ticket.issue_id}.${trailer}`]);
21037
21118
  const sha = headSha(o.cwd);
21038
- o.emit.emit(`merged ${c.branch}`, { ticket: c.ticket.issue_id });
21119
+ o.emit.note(`merged ${c.branch}`, { ticket: c.ticket.issue_id });
21039
21120
  clearFailure();
21040
21121
  return { applied: true, sha };
21041
21122
  } catch (e) {
@@ -21216,7 +21297,7 @@ function openReleaseCheckout(o) {
21216
21297
  const branch = `crew/release-${Date.now()}`;
21217
21298
  const root = mkdtempSync3(join47(tmpdir6(), "crew-release-"));
21218
21299
  const dir = join47(root, "checkout");
21219
- o.emit.emit(`release checkout: ${dir}`, { step: "release" });
21300
+ o.emit.note(`release checkout: ${dir}`, { step: "release" });
21220
21301
  const close = () => closeReleaseCheckout(o.cwd, root, dir, branch);
21221
21302
  try {
21222
21303
  git(o.cwd, ["worktree", "add", "-q", "--no-track", "-b", branch, dir, `${remote}/${base}`]);
@@ -21369,7 +21450,7 @@ async function runReleaseCycle(o, movedPast2, localRefSkips) {
21369
21450
  if (remoteOf(o.cwd)) {
21370
21451
  const releaseBranch = `crew/release-${Date.now()}`;
21371
21452
  git(o.cwd, ["checkout", "-q", "--no-track", "-b", releaseBranch, remoteRef]);
21372
- o.emit.emit("release checkout: the release sandbox clone", { step: "release" });
21453
+ o.emit.note("release checkout: the release sandbox clone", { step: "release" });
21373
21454
  return mergeAndRelease(o, decision, fresh, releaseBranch);
21374
21455
  }
21375
21456
  const primary = checkGuards(o.cwd, base);
@@ -21611,7 +21692,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21611
21692
  decision
21612
21693
  };
21613
21694
  }
21614
- o.emit.emit("nothing to release");
21695
+ o.emit.note("nothing to release");
21615
21696
  return { merged, conflicts, unbuildable, deployed: false, stopped: "nothing to release", decision };
21616
21697
  }
21617
21698
  const waiting = decision.merges.some((c) => c.skipReason === "already-merged" && c.mergedSha);
@@ -21657,7 +21738,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21657
21738
  else {
21658
21739
  const r = await hook(o, "setup");
21659
21740
  if (r && r.code !== 0) {
21660
- o.emit.error(`setup FAILED (exit ${r.code}) \u2014 not testing or deploying; the target stays on the previous release`);
21741
+ o.emit.error(withFix(`setup FAILED (exit ${r.code}) \u2014 not testing or deploying; the target stays on the previous release`, "`crew doctor`"));
21661
21742
  return { merged, conflicts, unbuildable, deployed: false, stopped: "setup failed", decision, hookFailure: hookFailure(o, "setup", r.output) };
21662
21743
  }
21663
21744
  }
@@ -21673,7 +21754,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21673
21754
  else if (out) return out;
21674
21755
  }
21675
21756
  if (r && r.code !== 0) {
21676
- o.emit.error(`test gate FAILED \u2014 not deploying; the target stays on the previous release`);
21757
+ o.emit.error(withFix("test gate FAILED \u2014 not deploying; the target stays on the previous release", "`crew doctor`, then fix the failing tests on the branch"));
21677
21758
  const sha = headSha(o.cwd);
21678
21759
  const count = o.state?.noteTestGateFailed?.(sha) ?? 1;
21679
21760
  const gateRed = count >= GATE_RED_AFTER && !o.state?.testGateReported?.(sha) ? { sha, count, hook: hookLabel(o.repo, "test"), tail: lastLines(r.output, 15) } : void 0;
@@ -21731,7 +21812,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21731
21812
  else if (out) return out;
21732
21813
  }
21733
21814
  if (r && r.code !== 0) {
21734
- o.emit.error("build failed \u2014 not deploying");
21815
+ o.emit.error(withFix("build failed \u2014 not deploying", "`crew doctor`, then run the repo's build hook in the release checkout"));
21735
21816
  if (version && !o.dryRun && headSha(o.cwd) !== preBump) {
21736
21817
  git(o.cwd, ["reset", "--hard", preBump]);
21737
21818
  o.emit.warn(`dropped the unreleased version commit for ${version} (reset ${o.repo.branch.base} to ${preBump.slice(0, 8)}) so a retry starts clean`);
@@ -21756,7 +21837,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21756
21837
  } else {
21757
21838
  try {
21758
21839
  pushBranch(o.cwd, o.repo.branch.remote, releaseBranch ?? o.repo.branch.base, o.repo.branch.base);
21759
- o.emit.emit(`pushed ${o.repo.branch.base} to ${o.repo.branch.remote}`);
21840
+ o.emit.note(`pushed ${o.repo.branch.base} to ${o.repo.branch.remote}`);
21760
21841
  } catch (e) {
21761
21842
  o.emit.error(
21762
21843
  `failed to push ${o.repo.branch.base} to ${o.repo.branch.remote} \u2014 ${e.message}; not deploying`
@@ -21817,7 +21898,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21817
21898
  else if (tagExists(o.cwd, tag)) o.emit.warn(`tag ${tag} already exists \u2014 not retagging`);
21818
21899
  else {
21819
21900
  createReleaseTag(o.cwd, tag, at, `Release ${tag}`);
21820
- o.emit.emit(`tagged ${tag}`);
21901
+ o.emit.note(`tagged ${tag}`);
21821
21902
  }
21822
21903
  }
21823
21904
  const tagIsCiTrigger = o.repo.release.mode === "ci_manual" || o.repo.release.mode === "ci_auto";
@@ -21827,7 +21908,7 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
21827
21908
  } else {
21828
21909
  try {
21829
21910
  pushTag(o.cwd, o.repo.branch.remote, tag);
21830
- o.emit.emit(`pushed tag ${tag} to ${o.repo.branch.remote}`);
21911
+ o.emit.note(`pushed tag ${tag} to ${o.repo.branch.remote}`);
21831
21912
  } catch (e) {
21832
21913
  const msg = `failed to push tag ${tag} to ${o.repo.branch.remote} \u2014 ${e.message}`;
21833
21914
  if (tagIsCiTrigger) {
@@ -25798,37 +25879,6 @@ function routeAvatarFailures(stateDir, route2) {
25798
25879
  // src/agents-sync-run.ts
25799
25880
  import { existsSync as existsSync53, mkdirSync as mkdirSync39, readFileSync as readFileSync51, writeFileSync as writeFileSync41 } from "fs";
25800
25881
  import { dirname as dirname31 } from "path";
25801
-
25802
- // src/cli-output.ts
25803
- function summarizeOutcomes(outcomes, describe2, isRoutine, noun, verbose) {
25804
- if (verbose) return outcomes.map(describe2);
25805
- const lines2 = outcomes.filter((o) => !isRoutine(o)).map(describe2);
25806
- const routine = outcomes.length - lines2.length;
25807
- if (routine > 0) lines2.push(`${routine} ${noun}${routine === 1 ? "" : "s"} already in sync`);
25808
- return lines2;
25809
- }
25810
- function withFix(message, fix) {
25811
- return `${message.replace(/[.\s]+$/, "")} \u2014 try: ${fix}`;
25812
- }
25813
- function summarizeJobs(results, o) {
25814
- const state = o.uninstall ? "not installed" : "installed";
25815
- const mark3 = o.dryRun ? " (dry run, not applied)" : "";
25816
- const line = (r) => {
25817
- if (o.dryRun) return `would ${o.uninstall ? "remove" : "install"} ${r.job} via ${r.mechanism} for ${o.host}${mark3}`;
25818
- if (r.action === "unchanged") return `${r.job} already ${state} (${r.mechanism})`;
25819
- return `${r.action} ${r.job} via ${r.mechanism} for ${o.host}`;
25820
- };
25821
- if (o.dryRun || o.verbose) return results.map(line);
25822
- const lines2 = results.filter((r) => r.action !== "unchanged").map(line);
25823
- const same2 = results.filter((r) => r.action === "unchanged");
25824
- if (same2.length > 0) {
25825
- const names = same2.map((r) => r.job).join(", ");
25826
- lines2.push(same2.length === results.length ? `all ${same2.length} jobs already ${state} (${names})` : `${same2.length} job${same2.length === 1 ? "" : "s"} already ${state} (${names})`);
25827
- }
25828
- return lines2;
25829
- }
25830
-
25831
- // src/agents-sync-run.ts
25832
25882
  async function runAgentsSync(target, o) {
25833
25883
  const dryRun = o.dryRun ?? false;
25834
25884
  const force = o.force ?? false;
@@ -27246,7 +27296,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
27246
27296
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
27247
27297
  import { join as join58 } from "path";
27248
27298
  function builtVersion() {
27249
- return true ? "0.150.2" : null;
27299
+ return true ? "0.151.1" : null;
27250
27300
  }
27251
27301
  var REBUILD_HINT = "rebuild with npm run build";
27252
27302
  function newestMtime(path) {
@@ -29437,7 +29487,7 @@ No project here has what a route needs. Install the "${template.name}" library t
29437
29487
  function usage(problem, requested = false) {
29438
29488
  const text2 = `crew \u2014 a standing team of headless agents
29439
29489
 
29440
- crew poll [route] decide a cycle and report it; writes nothing
29490
+ crew poll [route] [--verbose] decide a cycle and report it; writes nothing; --verbose adds counts and timestamps
29441
29491
  crew run [route] [--role R] run the winning role's session
29442
29492
  crew release [route] merge what QA verified, version it, ship it
29443
29493
  crew merge [route] merge verified branches and stop
@@ -29726,11 +29776,10 @@ if (command === "passenger-sync-daemon") {
29726
29776
  return process.exit(code);
29727
29777
  }, requireArmed = function(what) {
29728
29778
  if (dryRun || route2.enabled) return;
29729
- process.stderr.write(
29730
- `crew: route "${route2.route}" is not enabled in ${cfg.configFile} \u2014 refusing to ${what}.
29731
- Add --dry-run to see what it would do.
29732
- `
29733
- );
29779
+ emit.warn(withFix(
29780
+ `crew: route "${route2.route}" is not enabled in ${cfg.configFile} \u2014 refusing to ${what}`,
29781
+ "add --dry-run to see what it would do, or set `enabled: true` on the route"
29782
+ ));
29734
29783
  process.exit(0);
29735
29784
  }, parseTicketNumber = function(input) {
29736
29785
  const m = /^(?:[A-Za-z]+-)?(\d+)$/.exec(input.trim());
@@ -31482,7 +31531,7 @@ ${f.tail.trimEnd()}
31482
31531
  } };
31483
31532
  }
31484
31533
  if (result.contended.length) {
31485
- wemit.emit(`claim contended for ${result.contended.join(", ")} \u2014 moved to the next candidate`, {
31534
+ wemit.note(`claim contended for ${result.contended.join(", ")} \u2014 moved to the next candidate`, {
31486
31535
  step: "select",
31487
31536
  role: w.role
31488
31537
  });
@@ -31524,7 +31573,7 @@ ${f.tail.trimEnd()}
31524
31573
  fleetTicketRepo = target?.name;
31525
31574
  try {
31526
31575
  if (target && !skipsHostCheckout(cfg.ship) && ensureRepoCheckout(target.dir, target.remote, { scheme: cfg.ship.cloneScheme, host: target.forgeHost })) {
31527
- wemit.emit(`cloned ${target.name} into ${target.dir}`, { step: "select", role: w.role });
31576
+ wemit.note(`cloned ${target.name} into ${target.dir}`, { step: "select", role: w.role });
31528
31577
  }
31529
31578
  } catch (e) {
31530
31579
  wemit.error(`could not check out ${target?.name ?? "(unknown repo)"} for ${result.ticket.issue_id}: ${e.message}`);
@@ -31551,7 +31600,7 @@ ${f.tail.trimEnd()}
31551
31600
  resolvedAgentId: await resolveAgentId(w.route, w.role, { userAgent: cfg.ship.userAgent })
31552
31601
  });
31553
31602
  wemit.enter("agent", w.role);
31554
- wemit.emit(`starting agent run for ${w.route.route}`);
31603
+ wemit.note(`starting agent run for ${w.route.route}`);
31555
31604
  const fleetMemberId = w.route.resolved?.seats[w.role];
31556
31605
  if (fleetMemberId) {
31557
31606
  try {
@@ -31568,8 +31617,9 @@ ${f.tail.trimEnd()}
31568
31617
  try {
31569
31618
  const runStart = (/* @__PURE__ */ new Date()).toISOString();
31570
31619
  await markCrewAssistedAtLaunch(fleetTracker, w.route, w.role, fleetWorkingId ?? null, void 0, (m) => wemit.warn(m, { step: "agent" }));
31571
- await spawnAgent(fleetPlan, wemit);
31572
- await guardRunHandoff(w.route, cfg.ship, fleetTracker, w.role, fleetWorkingId, wemit, runStart);
31620
+ const fleetRun = await spawnAgent(fleetPlan, wemit);
31621
+ const fleetHandoff = await guardRunHandoff(w.route, cfg.ship, fleetTracker, w.role, fleetWorkingId, wemit, runStart);
31622
+ wemit.echo(describeRunOutcome({ role: w.role, route: w.route.route, ticket: fleetTicketHint, run: fleetRun, handoff: fleetHandoff }));
31573
31623
  } finally {
31574
31624
  dropLock();
31575
31625
  await settleRunEnd({
@@ -31612,7 +31662,7 @@ ${f.tail.trimEnd()}
31612
31662
  } else {
31613
31663
  const seat = route2.resolved?.seats.qa ?? route2.resolved?.seats.dev;
31614
31664
  const r = await applySweep(new Tracker(route2, cfg.ship), decision.sweep, seat ?? "", emit);
31615
- emit.emit(
31665
+ emit.note(
31616
31666
  `swept ${r.parked} parked, ${r.restored} restored${r.failed ? `, ${r.failed} failed` : ""}${r.contended ? `, ${r.contended} contended` : ""}`,
31617
31667
  { step: "sweep", data: r }
31618
31668
  );
@@ -31697,7 +31747,7 @@ ${f.tail.trimEnd()}
31697
31747
  } };
31698
31748
  }
31699
31749
  if (result.contended.length) {
31700
- emit.emit(`claim contended for ${result.contended.join(", ")} \u2014 moved to the next candidate`, {
31750
+ emit.note(`claim contended for ${result.contended.join(", ")} \u2014 moved to the next candidate`, {
31701
31751
  step: "select",
31702
31752
  role: current
31703
31753
  });
@@ -31745,7 +31795,7 @@ ${f.tail.trimEnd()}
31745
31795
  ticketRepo = target?.name;
31746
31796
  try {
31747
31797
  if (target && !skipsHostCheckout(cfg.ship) && ensureRepoCheckout(target.dir, target.remote, { scheme: cfg.ship.cloneScheme, host: target.forgeHost })) {
31748
- emit.emit(`cloned ${target.name} into ${target.dir}`, { step: "select", role: current });
31798
+ emit.note(`cloned ${target.name} into ${target.dir}`, { step: "select", role: current });
31749
31799
  }
31750
31800
  } catch (e) {
31751
31801
  emit.error(`could not check out ${target?.name ?? "(unknown repo)"} for ${result.ticket.issue_id}: ${e.message}`);
@@ -31794,7 +31844,7 @@ ${f.tail.trimEnd()}
31794
31844
  }
31795
31845
  const before = snapshot(await tracker2.openTickets());
31796
31846
  emit.enter("agent", current);
31797
- emit.emit("starting agent run");
31847
+ emit.note("starting agent run");
31798
31848
  const memberId = route2.resolved?.seats[current];
31799
31849
  if (memberId) {
31800
31850
  try {
@@ -31811,8 +31861,9 @@ ${f.tail.trimEnd()}
31811
31861
  try {
31812
31862
  const runStart = (/* @__PURE__ */ new Date()).toISOString();
31813
31863
  await markCrewAssistedAtLaunch(tracker2, route2, current, workingId ?? null, void 0, (m) => emit.warn(m, { step: "agent" }));
31814
- await spawnAgent(plan, emit);
31815
- await guardRunHandoff(route2, cfg.ship, tracker2, current, workingId, emit, runStart);
31864
+ const agentRun = await spawnAgent(plan, emit);
31865
+ const handoff = await guardRunHandoff(route2, cfg.ship, tracker2, current, workingId, emit, runStart);
31866
+ emit.echo(describeRunOutcome({ role: current, route: route2.route, ticket: ticketHint, run: agentRun, handoff }));
31816
31867
  } finally {
31817
31868
  dropLock();
31818
31869
  await settleRunEnd({
@@ -31846,8 +31897,7 @@ ${f.tail.trimEnd()}
31846
31897
  if (daemonSub === "start" || daemonSub === "stop" || daemonSub === "status" || daemonSub === "restart") {
31847
31898
  const host = hostPlatform();
31848
31899
  if (host === "windows") {
31849
- process.stderr.write("crew daemon: no scheduler support yet for Windows (Task Scheduler is planned, not built)\n");
31850
- process.exit(2);
31900
+ die("crew daemon", "no scheduler support yet for Windows (Task Scheduler is planned, not built)", "`crew run <route>` from your own scheduler");
31851
31901
  }
31852
31902
  const control = planDaemonControl(CREW_HOME, host, detectSystemd());
31853
31903
  if (!control.startCommand && !control.stopCommand && !control.statusCommand) {
@@ -31906,8 +31956,7 @@ ${f.tail.trimEnd()}
31906
31956
  if (res2.stdout) process.stdout.write(res2.stdout);
31907
31957
  if (res2.stderr) process.stderr.write(res2.stderr);
31908
31958
  if (cmd2 === control.startCommand && (res2.error || res2.status !== 0)) {
31909
- process.stderr.write(`crew daemon restart: ${cmd2.join(" ")} exited ${res2.status ?? "error"}
31910
- `);
31959
+ emit.error(withFix(`crew daemon restart: ${cmd2.join(" ")} exited ${res2.status ?? "error"}`, "`crew doctor`"));
31911
31960
  failed = true;
31912
31961
  }
31913
31962
  }
@@ -31924,8 +31973,7 @@ ${f.tail.trimEnd()}
31924
31973
  if (res.stdout) process.stdout.write(res.stdout);
31925
31974
  if (res.stderr) process.stderr.write(res.stderr);
31926
31975
  if (daemonSub !== "status" && (res.error || res.status !== 0)) {
31927
- process.stderr.write(`crew daemon ${daemonSub}: ${cmd.join(" ")} exited ${res.status ?? "error"}
31928
- `);
31976
+ emit.error(withFix(`crew daemon ${daemonSub}: ${cmd.join(" ")} exited ${res.status ?? "error"}`, "`crew doctor`"));
31929
31977
  process.exitCode = 1;
31930
31978
  } else {
31931
31979
  process.exitCode = res.status ?? 0;
@@ -31933,13 +31981,11 @@ ${f.tail.trimEnd()}
31933
31981
  break;
31934
31982
  }
31935
31983
  if (dryRun) {
31936
- process.stderr.write("crew: daemon does not support --dry-run \u2014 it only ever performs real cycles.\n");
31937
- process.exit(2);
31984
+ die("crew", "daemon does not support --dry-run \u2014 it only ever performs real cycles", "run `crew daemon` without --dry-run, or `crew poll --dry-run` to preview a cycle");
31938
31985
  }
31939
31986
  if (!fleetWide && !route2.enabled) {
31940
31987
  const reason = `route "${route2.route}" is not enabled in ${cfg.configFile} \u2014 refusing to run the daemon loop`;
31941
- process.stderr.write(`crew: ${reason}.
31942
- `);
31988
+ emit.error(withFix(`crew: ${reason}`, `set \`enabled: true\` on route "${route2.route}" in crew.yaml`));
31943
31989
  await failDaemonStart({
31944
31990
  stateDir: cfg.ship.stateDir,
31945
31991
  reason,
@@ -32231,17 +32277,11 @@ ${f.tail.trimEnd()}
32231
32277
  try {
32232
32278
  promptTarget = positional[3] ? findRoute(cfg, positional[3]) : routeForDir(cfg, process.cwd()) ?? findRoute(cfg, void 0);
32233
32279
  } catch (e) {
32234
- if (e instanceof ConfigError) {
32235
- process.stderr.write(`crew: ${e.message}
32236
- `);
32237
- process.exit(2);
32238
- }
32280
+ if (e instanceof ConfigError) die("crew", e.message, "`crew doctor`");
32239
32281
  throw e;
32240
32282
  }
32241
32283
  if (!promptTarget.resolved) {
32242
- process.stderr.write(`crew agents prompt: route "${promptTarget.route}" has no resolved ids \u2014 run \`crew connect\` first
32243
- `);
32244
- process.exit(2);
32284
+ die("crew agents prompt", `route "${promptTarget.route}" has no resolved ids`, "`crew connect`");
32245
32285
  }
32246
32286
  try {
32247
32287
  const prompt = await currentPersonaPrompt(promptTarget, role, { userAgent: cfg.ship.userAgent });
@@ -32523,8 +32563,7 @@ ${f.tail.trimEnd()}
32523
32563
  for (const n of agent.notes) process.stdout.write(`note: ${n}
32524
32564
  `);
32525
32565
  }
32526
- if (agentError) process.stderr.write(`crew repos: --agent failed (${agentError.reason}): ${agentError.message}
32527
- `);
32566
+ if (agentError) emit.warn(withFix(`crew repos: --agent failed (${agentError.reason}): ${agentError.message}`, "`crew repos hooks --suggest` for the deterministic suggestion"));
32528
32567
  if (cleared) process.stdout.write(cleared.removed.length ? `removed route hooks ${cleared.removed.join(", ")} from ${cleared.file}
32529
32568
  ` : "no route hooks to remove\n");
32530
32569
  if (written) {
@@ -32663,8 +32702,7 @@ ${f.tail.trimEnd()}
32663
32702
  crew.yaml was not changed`);
32664
32703
  }
32665
32704
  writeFileSync44(cfg.configFile, plan2.text);
32666
- if (plan2.droppedDir) process.stderr.write(`crew repos: dropped dir: ${plan2.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:
32667
- `);
32705
+ if (plan2.droppedDir) emit.warn(`crew repos: dropped dir: ${plan2.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:`);
32668
32706
  say("attached", { route: routeName, name: plan2.name, dir: plan2.target, mode: plan2.mode }, `cloned and attached ${plan2.target} to ${routeName} as ${plan2.mode === "dir" ? "dir" : `repos.${plan2.name}`} in ${cfg.configFile}`);
32669
32707
  break;
32670
32708
  }
@@ -32683,8 +32721,7 @@ ${f.tail.trimEnd()}
32683
32721
  nameForExisting: (d) => matchRepoName(originOf(d), resolvedRemotes),
32684
32722
  isCheckout
32685
32723
  });
32686
- if (plan.droppedDir) process.stderr.write(`crew repos: dropped dir: ${plan.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:
32687
- `);
32724
+ if (plan.droppedDir) emit.warn(`crew repos: dropped dir: ${plan.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:`);
32688
32725
  let rowTracker;
32689
32726
  let rowPayload;
32690
32727
  if (plan.unmatched && origin && !flag("no-create")) {
@@ -32707,8 +32744,7 @@ ${f.tail.trimEnd()}
32707
32744
  }
32708
32745
  rowPayload = planRepoRow({ name: plan.name, origin, spec, projectId });
32709
32746
  } else if (plan.warning) {
32710
- process.stderr.write(`crew repos: warning \u2014 ${plan.warning}
32711
- `);
32747
+ emit.warn(`crew repos: warning \u2014 ${plan.warning}`);
32712
32748
  }
32713
32749
  if (dryRun) {
32714
32750
  process.stdout.write(`${plan.block}
@@ -32758,11 +32794,7 @@ ${f.tail.trimEnd()}
32758
32794
  try {
32759
32795
  target = findRoute(cfg, routeArg);
32760
32796
  } catch (e) {
32761
- if (e instanceof ConfigError) {
32762
- process.stderr.write(`crew: ${e.message}
32763
- `);
32764
- process.exit(2);
32765
- }
32797
+ if (e instanceof ConfigError) die("crew", e.message, "`crew doctor`");
32766
32798
  throw e;
32767
32799
  }
32768
32800
  try {
@@ -32853,10 +32885,7 @@ ${reconstruction.prompt}
32853
32885
  const canAsk = !!(process.stdin.isTTY && process.stdout.isTTY) && !connectEvents.json;
32854
32886
  const stopForChoice = (key, message, options) => {
32855
32887
  connectEvents.emit("choice", message, choiceData(key, options));
32856
- process.stderr.write(`crew connect: ${message}
32857
- Re-run with --choose ${key}=<${options.map((o) => o.value).join("|")}>
32858
- `);
32859
- return process.exit(CHOICE_EXIT_CODE);
32888
+ return die("crew connect", message, `re-run with --choose ${key}=<${options.map((o) => o.value).join("|")}>`, CHOICE_EXIT_CODE);
32860
32889
  };
32861
32890
  const stopWithProblem = (message, stage) => {
32862
32891
  connectEvents.emit("problem", message, { stage });
@@ -32965,16 +32994,11 @@ Waiting for approval`
32965
32994
  } catch (e) {
32966
32995
  process.stderr.write("\n");
32967
32996
  const why = e instanceof DeviceLoginError ? e.message : `device authorization failed \u2014 ${e.message}`;
32968
- process.stderr.write(`crew connect: ${why}
32969
- `);
32970
32997
  connectEvents.emit("problem", why, { stage: "device_login" });
32971
- process.exit(2);
32998
+ die("crew connect", why, "`crew connect` again, or pass --key");
32972
32999
  }
32973
- process.stderr.write(
32974
- `
32975
- Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${result.workspace.name}".
32976
- `
32977
- );
33000
+ process.stderr.write("\n");
33001
+ emit.note(`Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${result.workspace.name}".`);
32978
33002
  apiKey = result.apiKey.key;
32979
33003
  mintedFromDevice = true;
32980
33004
  const deviceWorkspace = "path" in result.workspace && typeof result.workspace.path === "string" ? result.workspace.path : result.workspace.slug;
@@ -32990,18 +33014,15 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
32990
33014
  keychainBacked = true;
32991
33015
  sessionAddress = deviceWorkspace;
32992
33016
  rememberSession(cfg.ship.stateDir, hostFromUrl4(baseUrl), deviceWorkspace);
32993
- process.stderr.write(
32994
- `API key stored in the OS keychain for ${hostFromUrl4(baseUrl)}/${deviceWorkspace}.
32995
- `
32996
- );
33017
+ emit.note(`API key stored in the OS keychain for ${hostFromUrl4(baseUrl)}/${deviceWorkspace}.`);
32997
33018
  } catch (e) {
32998
- process.stderr.write(
32999
- `(could not store the key in the OS keychain \u2014 ${e.message} \u2014 falling back to a key file)
33000
- `
33001
- );
33019
+ emit.warn(withFix(
33020
+ `could not store the key in the OS keychain \u2014 ${e.message} \u2014 falling back to a key file`,
33021
+ "`crew doctor`"
33022
+ ));
33002
33023
  }
33003
33024
  } else {
33004
- process.stderr.write("(no OS keychain support on this platform \u2014 falling back to a key file)\n");
33025
+ emit.warn("no OS keychain support on this platform \u2014 falling back to a key file");
33005
33026
  }
33006
33027
  }
33007
33028
  const authOpts = { baseUrl, apiKey, userAgent: cfg.ship.userAgent };
@@ -33011,16 +33032,14 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33011
33032
  try {
33012
33033
  sshPublicKey = ensureShipSshKeypair(cfg.ship.stateDir).publicKey;
33013
33034
  } catch (e) {
33014
- process.stderr.write(`(no SSH keypair synced \u2014 ${e.message})
33015
- `);
33035
+ emit.warn(`no SSH keypair synced \u2014 ${e.message}`);
33016
33036
  }
33017
33037
  }
33018
33038
  let machineId;
33019
33039
  try {
33020
33040
  machineId = ensureMachineId(cfg.ship.stateDir, { override: value("machine-id") });
33021
33041
  } catch (e) {
33022
- process.stderr.write(`(no machine id \u2014 ${e.message})
33023
- `);
33042
+ emit.warn(`no machine id \u2014 ${e.message}`);
33024
33043
  }
33025
33044
  const ship = {
33026
33045
  name: cfg.ship.name,
@@ -33088,14 +33107,9 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33088
33107
  }
33089
33108
  }
33090
33109
  if (!found.projectId) {
33091
- process.stderr.write(`crew connect ${ws}: unresolved \u2014
33092
- `);
33093
- for (const p of found.problems) {
33094
- process.stderr.write(` - ${p}
33095
- `);
33096
- connectEvents.emit("problem", p, { stage: "discover" });
33097
- }
33098
- process.exit(2);
33110
+ for (const p of found.problems) connectEvents.emit("problem", p, { stage: "discover" });
33111
+ die(`crew connect ${ws}`, `unresolved \u2014
33112
+ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, then run `crew connect` again");
33099
33113
  }
33100
33114
  if (found.shipNameAdopted && !dryRun) {
33101
33115
  writeFileSync44(cfg.configFile, setShipNameInYaml(readFileSync56(cfg.configFile, "utf8"), found.shipNameAdopted));
@@ -33121,11 +33135,9 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33121
33135
  const repoNames = [...Object.values(found.repoNames ?? {}), ...configured2 ? reposOf(configured2).map((t) => t.name) : []].filter((n) => !!n);
33122
33136
  try {
33123
33137
  const made = await provisionReleaseLocks(authOpts, found.locksModelId, route3, repoNames);
33124
- for (const sc of made) process.stderr.write(`created release lock row ${sc}
33125
- `);
33138
+ for (const sc of made) emit.note(`created release lock row ${sc}`);
33126
33139
  } catch (e) {
33127
- process.stderr.write(`(could not provision release lock rows \u2014 ${e.message})
33128
- `);
33140
+ emit.warn(withFix(`could not provision release lock rows \u2014 ${e.message}`, "`crew doctor`"));
33129
33141
  }
33130
33142
  }
33131
33143
  let operator = found.operator;
@@ -33172,8 +33184,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33172
33184
  }
33173
33185
  }
33174
33186
  if (!operator && found.operatorCompared && found.operatorAction !== "would-create") {
33175
- process.stderr.write(`crew connect: no Crew row matched you \u2014 ${found.operatorCompared}
33176
- `);
33187
+ emit.warn(`crew connect: no Crew row matched you \u2014 ${found.operatorCompared}`);
33177
33188
  connectEvents.emit("operator_row", "no Crew row matched you", { action: "unmatched", compared: found.operatorCompared });
33178
33189
  }
33179
33190
  if (operator) {
@@ -33195,12 +33206,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33195
33206
  });
33196
33207
  }
33197
33208
  if (!operator && !hadPreviousFile && !operatorWouldBeCreated) {
33198
- process.stderr.write(
33199
- `crew connect ${route3}: cannot determine the operator \u2014 ${found.candidates.length} Crew row(s) could be it, none matching this key's own email, and there's no terminal to ask.
33200
- Re-run from a real terminal to pick one, or pass --key for a key whose own
33201
- identity email matches exactly one Crew row.
33202
- `
33203
- );
33209
+ emit.error(withFix(
33210
+ `crew connect ${route3}: cannot determine the operator \u2014 ${found.candidates.length} Crew row(s) could be it, none matching this key's own email, and there's no terminal to ask`,
33211
+ "run `crew connect` from a real terminal to pick one, or pass --key for a key whose own identity email matches exactly one Crew row"
33212
+ ));
33204
33213
  stopWithProblem(`cannot determine the operator \u2014 ${found.candidates.length} Crew row(s) could be it`, "operator");
33205
33214
  }
33206
33215
  const alreadyReviewed = new Set(previous?.reviewedStatuses ?? []);
@@ -33281,22 +33290,18 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33281
33290
  writeFileSync44(tmpPath, `${JSON.stringify(resolved, null, 2)}
33282
33291
  `);
33283
33292
  renameSync10(tmpPath, resolvedPath);
33284
- process.stderr.write(`Resolved ids written to ${resolvedPath}
33285
- `);
33293
+ emit.note(`Resolved ids written to ${resolvedPath}`);
33286
33294
  }
33287
33295
  let mintOutcomes = [];
33288
33296
  if (!dryRun && previous?.agentPersonas && existingRoute?.resolved) {
33289
33297
  try {
33290
33298
  mintOutcomes = await mintMissingSeatKeys(withFoundSeats(existingRoute, found, previous.releaseAgentId), { userAgent: cfg.ship.userAgent, shipName: cfg.ship.name });
33291
- for (const o of mintOutcomes) process.stderr.write(`${describeMintOutcome(o)}
33292
- `);
33299
+ for (const o of mintOutcomes) emit.note(describeMintOutcome(o));
33293
33300
  for (const p of await probeSeatReads({ ...existingRoute, resolved: { ...existingRoute.resolved, seats: found.seats } }, { userAgent: cfg.ship.userAgent })) {
33294
- if (p.state === "forbidden") process.stderr.write(`${describeSeatForbidden(p.role, p.tables)}
33295
- `);
33301
+ if (p.state === "forbidden") emit.warn(describeSeatForbidden(p.role, p.tables));
33296
33302
  }
33297
33303
  } catch (e) {
33298
- process.stderr.write(`seat keys: skipped (${e.message})
33299
- `);
33304
+ emit.warn(withFix(`seat keys: skipped (${e.message})`, "`crew agents sync`"));
33300
33305
  }
33301
33306
  }
33302
33307
  for (const sr of found.seatRows ?? []) {
@@ -33314,8 +33319,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33314
33319
  const apiKeyVar = "CREW_API_KEY";
33315
33320
  if (firstRunFromFlags && agentBinSearched && !dryRun && !isManagedShipKind(value("ship-kind"))) {
33316
33321
  const msg = `no agent binary: "claude" was not found on PATH or in ${agentBinSearched.join(", ")} \u2014 pass --agent-bin /absolute/path`;
33317
- process.stderr.write(`crew connect: ${msg}
33318
- `);
33322
+ emit.error(`crew connect: ${msg}`);
33319
33323
  stopWithProblem(msg, "wizard");
33320
33324
  }
33321
33325
  if ((mintedFromDevice || firstRunFromFlags) && !keychainBacked) {
@@ -33349,8 +33353,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33349
33353
  let wroteConfig = false;
33350
33354
  if (writeFirstRun) {
33351
33355
  wroteConfig = writeNewConfig(wizard.configPath, renderFullConfig(wizard.answers, routeBlock));
33352
- if (!wroteConfig) process.stderr.write(`(${wizard.configPath} appeared while connecting \u2014 leaving it alone)
33353
- `);
33356
+ if (!wroteConfig) emit.warn(`${wizard.configPath} appeared while connecting \u2014 leaving it alone`);
33354
33357
  }
33355
33358
  if (!dryRun) {
33356
33359
  if (wroteConfig) {
@@ -33385,33 +33388,22 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33385
33388
  }
33386
33389
  }
33387
33390
  if (found.holds.length) {
33388
- process.stderr.write(
33389
- `
33390
- Holds resolved (${found.holds.length}): ${found.holds.map((h) => `${h.name || h.id}${h.id === operator ? " [operator]" : ""}`).join(", ")}
33391
- `
33391
+ emit.note(
33392
+ `Holds resolved (${found.holds.length}): ${found.holds.map((h) => `${h.name || h.id}${h.id === operator ? " [operator]" : ""}`).join(", ")}`
33392
33393
  );
33393
33394
  }
33394
33395
  if (found.provisioning.length) {
33395
- process.stderr.write(`
33396
- Provisioned for this machine (${ship.name}):
33397
- `);
33398
- for (const p of found.provisioning) process.stderr.write(` - ${p}
33399
- `);
33396
+ emit.note(`Provisioned for this machine (${ship.name}):`);
33397
+ for (const p of found.provisioning) emit.note(` - ${p}`);
33400
33398
  }
33401
33399
  if (found.problems.length) {
33402
- process.stderr.write("\n Unresolved \u2014 fix these before arming it:\n");
33403
- for (const p of found.problems) {
33404
- process.stderr.write(` - ${p}
33405
- `);
33406
- connectEvents.emit("problem", p, { stage: "discover" });
33407
- }
33400
+ emit.warn(`Unresolved \u2014 fix these before arming it:
33401
+ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
33402
+ for (const p of found.problems) connectEvents.emit("problem", p, { stage: "discover" });
33408
33403
  }
33409
33404
  if (!canPrompt && !jsonClassified && stillUnrecognized.length > 0) {
33410
- process.stderr.write(
33411
- `
33412
- ${stillUnrecognized.length} status value(s) this workspace has that the default contract
33413
- doesn't know the meaning of (${stillUnrecognized.map((s) => s.value).join(", ")}) \u2014 re-run from a terminal to classify them, or edit ${resolvedPath} by hand.
33414
- `
33405
+ emit.warn(
33406
+ `${stillUnrecognized.length} status value(s) this workspace has that the default contract doesn't know the meaning of (${stillUnrecognized.map((s) => s.value).join(", ")}) \u2014 re-run from a terminal to classify them, or edit ${resolvedPath} by hand.`
33415
33407
  );
33416
33408
  }
33417
33409
  if (wroteConfig) {
@@ -33439,9 +33431,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33439
33431
  }
33440
33432
  if (!dryRun && !flag("no-agents-sync")) {
33441
33433
  const skip = (why) => {
33442
- process.stderr.write(`
33443
- agents sync: skipped (${why})
33444
- `);
33434
+ emit.warn(`agents sync: skipped (${why})`);
33445
33435
  connectEvents.emit("agents_synced", `agents sync skipped: ${why}`, { route: route3, skipped: why });
33446
33436
  };
33447
33437
  let syncRoute;
@@ -33454,25 +33444,21 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33454
33444
  }
33455
33445
  if (syncRoute?.resolved) {
33456
33446
  try {
33457
- process.stderr.write("\n");
33458
33447
  const run4 = await runAgentsSync(syncRoute, {
33459
33448
  userAgent: cfg.ship.userAgent,
33460
33449
  stateDir: cfg.ship.stateDir,
33461
- say: (l) => process.stderr.write(` ${l}
33462
- `),
33463
- warn: (l) => process.stderr.write(` agents sync: ${l}
33464
- `)
33450
+ say: (l) => emit.note(l),
33451
+ warn: (l) => emit.warn(`agents sync: ${l}`)
33465
33452
  });
33466
33453
  const minted = await mintMissingSeatKeys(syncRoute, { userAgent: cfg.ship.userAgent, shipName: cfg.ship.name });
33467
- for (const m of minted) process.stderr.write(` ${describeMintOutcome(m)}
33468
- `);
33454
+ for (const m of minted) emit.note(describeMintOutcome(m));
33469
33455
  for (const p of await probeSeatReads(syncRoute, { userAgent: cfg.ship.userAgent })) {
33470
- if (p.state === "forbidden") process.stderr.write(` ${describeSeatForbidden(p.role, p.tables)}
33471
- `);
33456
+ if (p.state === "forbidden") emit.warn(describeSeatForbidden(p.role, p.tables));
33472
33457
  }
33473
33458
  if (run4.readOnly) {
33474
33459
  const missing = run4.personaResult.outcomes.some((p) => p.action === "missing");
33475
- process.stderr.write(missing ? " A workspace admin has to open the Crew app or run `crew agents sync` once before this ship's seats can run.\n" : " Seats are linked to the workspace's existing personas.\n");
33460
+ if (missing) emit.warn("A workspace admin has to open the Crew app or run `crew agents sync` once before this ship's seats can run.");
33461
+ else emit.note("Seats are linked to the workspace's existing personas.");
33476
33462
  }
33477
33463
  connectEvents.emit("agents_synced", run4.readOnly ? "agents linked (read-only key)" : "agents synced", {
33478
33464
  route: route3,
@@ -33543,12 +33529,8 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33543
33529
  workspaces.map((w) => ({ value: w.slug, label: `${w.name} (${w.role})` }))
33544
33530
  );
33545
33531
  }
33546
- process.stderr.write(
33547
- `${workspaces.length} workspaces reachable by this key \u2014 name one:
33548
- ` + workspaces.map((w) => ` ${w.slug.padEnd(24)} ${w.name} (${w.role})
33549
- `).join("")
33550
- );
33551
- process.exit(2);
33532
+ die("crew connect", `${workspaces.length} workspaces reachable by this key \u2014 name one:
33533
+ ` + workspaces.map((w) => ` ${w.slug.padEnd(24)} ${w.name} (${w.role})`).join("\n"), "run `crew connect <workspace>` with one of the slugs above");
33552
33534
  }
33553
33535
  } else {
33554
33536
  await runConnect(workspace, project);
@@ -33584,20 +33566,16 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33584
33566
  );
33585
33567
  }
33586
33568
  if (ambiguous) {
33587
- process.stderr.write(
33588
- `
33589
- WARNING: "${who2}" resolved to different people on different workspaces.
33590
- A name is a per-workspace label, not an identity \u2014 this queue is a mixture.
33591
- Use an email address to match exactly.
33592
- `
33593
- );
33569
+ emit.warn(withFix(
33570
+ `"${who2}" resolved to different people on different workspaces. A name is a per-workspace label, not an identity \u2014 this queue is a mixture`,
33571
+ "pass an email address to --member to match exactly"
33572
+ ));
33594
33573
  }
33595
33574
  process.stdout.write("\n");
33596
33575
  }
33597
33576
  const subject = who2 ? [...new Set(resolved.flatMap((r) => r.names))].join(", ") || `"${who2}"` : void 0;
33598
33577
  process.stdout.write(renderInbox(items, flag("by-route"), subject));
33599
- for (const e of errors) process.stderr.write(` (${e.route} unreachable: ${e.error})
33600
- `);
33578
+ for (const e of errors) emit.warn(withFix(`${e.route} unreachable: ${e.error}`, `\`crew doctor ${e.route}\``));
33601
33579
  break;
33602
33580
  }
33603
33581
  case "ports": {
@@ -33649,11 +33627,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33649
33627
  try {
33650
33628
  routesS = value("route") ? [findRoute(cfg, value("route"))] : cfg.routes.filter((r) => r.enabled);
33651
33629
  } catch (e) {
33652
- if (e instanceof ConfigError) {
33653
- process.stderr.write(`crew: ${e.message}
33654
- `);
33655
- process.exit(2);
33656
- }
33630
+ if (e instanceof ConfigError) die("crew", e.message, "`crew doctor`");
33657
33631
  throw e;
33658
33632
  }
33659
33633
  const declared = withShipSandbox(await sandboxReposOf(routesS));
@@ -33683,9 +33657,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33683
33657
  const only = positional[2];
33684
33658
  const targets = only ? declared.filter((r) => r.name === only) : declared;
33685
33659
  if (targets.length === 0) {
33686
- process.stderr.write(only ? `crew: no repository "${only}" declares a sandbox: section (${SHIP_SANDBOX_KEY} is the ship's crew layer, built only on a ship.runner: sandbox ship)
33687
- ` : "crew: this ship is not a sandbox ship and no repository declares a sandbox: section in its .crew.yaml\n");
33688
- process.exit(2);
33660
+ die("crew", only ? `no repository "${only}" declares a sandbox: section (${SHIP_SANDBOX_KEY} is the ship's crew layer, built only on a ship.runner: sandbox ship)` : "this ship is not a sandbox ship and no repository declares a sandbox: section in its .crew.yaml", "add a sandbox: section to the repository's .crew.yaml, or run `crew sandbox images` to list what is declared");
33689
33661
  }
33690
33662
  const emitS = new Emitter({ route: routesS[0].route, eventFile: eventFileFor(cfg.ship.stateDir), rotateBytes: cfg.ship.eventsRotateBytes, logFile: cfg.ship.logFile, console: (l) => process.stderr.write(`${l}
33691
33663
  `) });
@@ -33704,10 +33676,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33704
33676
  }
33705
33677
  case "cache": {
33706
33678
  const settings = cacheSettingsOf(cfg.ship.sandbox);
33707
- if (!settings) {
33708
- process.stderr.write("crew sandbox cache: ship.sandbox.cacheVolume is not set, so there is no cache volume\n");
33709
- process.exit(2);
33710
- }
33679
+ if (!settings) die("crew sandbox cache", "ship.sandbox.cacheVolume is not set, so there is no cache volume", "set ship.sandbox.cacheVolume in crew.yaml");
33711
33680
  const cache = new SandboxCache(settings);
33712
33681
  const served = cfg.routes.flatMap((r) => sandboxCacheRepos(r, cfg.ship));
33713
33682
  try {
@@ -33752,8 +33721,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33752
33721
  }
33753
33722
  if (refreshFailed) process.exitCode = 1;
33754
33723
  } catch (e) {
33755
- process.stderr.write(`crew sandbox cache: ${e instanceof Error ? e.message : String(e)}
33756
- `);
33724
+ emit.error(withFix(`crew sandbox cache: ${e instanceof Error ? e.message : String(e)}`, "`crew doctor`"));
33757
33725
  process.exitCode = 1;
33758
33726
  }
33759
33727
  break;
@@ -34446,14 +34414,12 @@ ${where.join("\n")}`);
34446
34414
  const opener = openerFor(process.platform);
34447
34415
  if (opener && shouldOpen({ open: flag("open"), noOpen: flag("no-open"), json: jsonP, terminal })) {
34448
34416
  const r = spawnSync14(opener, [res.url], { stdio: "ignore" });
34449
- if (r.error || r.status !== 0) process.stderr.write(`crew periscope: could not open ${res.url} with ${opener}
34450
- `);
34417
+ if (r.error || r.status !== 0) emit.warn(withFix(`crew periscope: could not open ${res.url} with ${opener}`, `open ${res.url} yourself`));
34451
34418
  }
34452
34419
  }
34453
34420
  } catch (e) {
34454
34421
  if (e instanceof PeriscopeError || e instanceof ConfigError) {
34455
- process.stderr.write(`crew periscope: ${e.message}
34456
- `);
34422
+ emit.error(withFix(`crew periscope: ${e.message}`, "`crew periscope list`"));
34457
34423
  if (e instanceof LivePeriscopeError && jsonP) process.stdout.write(`${JSON.stringify(e.data)}
34458
34424
  `);
34459
34425
  process.exit(1);
@@ -34591,14 +34557,12 @@ ${where.join("\n")}`);
34591
34557
  if (!dryRun) {
34592
34558
  for (const r of cfg.routes.filter((x) => x.resolved?.shipsModelId)) {
34593
34559
  await new Tracker(r, cfg.ship).updateRelayUrl(cfg.ship.name, null).catch((e) => {
34594
- process.stderr.write(`could not clear relay_url for ${r.route}: ${e.message}
34595
- `);
34560
+ emit.warn(withFix(`could not clear relay_url for ${r.route}: ${e.message}`, "`crew doctor`"));
34596
34561
  });
34597
34562
  }
34598
34563
  }
34599
34564
  if (!flag("reset") && !deprovisioning) {
34600
- for (const line of removePairEntries(url, dryRun)) process.stderr.write(`${line}
34601
- `);
34565
+ for (const line of removePairEntries(url, dryRun)) emit.note(line);
34602
34566
  break;
34603
34567
  }
34604
34568
  const host = hostPlatform();
@@ -34705,8 +34669,7 @@ ${where.join("\n")}`);
34705
34669
  if (!unitRunning && control?.mechanism === "systemd" && control.startCommand) {
34706
34670
  const res = spawnSync14(control.startCommand[0], control.startCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
34707
34671
  if (res.error || res.status !== 0) {
34708
- process.stderr.write(`crew reload: ${control.startCommand.join(" ")} exited ${res.status ?? "error"}
34709
- `);
34672
+ emit.error(withFix(`crew reload: ${control.startCommand.join(" ")} exited ${res.status ?? "error"}`, "`crew doctor`"));
34710
34673
  process.exitCode = 1;
34711
34674
  } else {
34712
34675
  process.stdout.write("crew reload: the daemon unit was not running \u2014 started it, so it reads crew.yaml fresh\n");
@@ -34727,8 +34690,7 @@ ${where.join("\n")}`);
34727
34690
  for (const cmd of [control.stopCommand, control.startCommand]) {
34728
34691
  const res = spawnSync14(cmd[0], cmd.slice(1), { cwd: CREW_HOME, encoding: "utf8", env: withUserBusEnv() });
34729
34692
  if (cmd === control.startCommand && (res.error || res.status !== 0)) {
34730
- process.stderr.write(`crew reload: ${cmd.join(" ")} exited ${res.status ?? "error"}
34731
- `);
34693
+ emit.error(withFix(`crew reload: ${cmd.join(" ")} exited ${res.status ?? "error"}`, "`crew doctor`"));
34732
34694
  process.exitCode = 1;
34733
34695
  }
34734
34696
  }
@@ -34911,9 +34873,7 @@ ${where.join("\n")}`);
34911
34873
  const all = shipToolchains(cfg.ship);
34912
34874
  const chosen = wanted ? all.filter((t) => t.name === wanted) : all;
34913
34875
  if (chosen.length === 0) {
34914
- process.stderr.write(`crew selftest: no toolchain "${wanted}" (have: ${all.map((t) => t.name).join(", ")})
34915
- `);
34916
- process.exit(2);
34876
+ die("crew selftest", `no toolchain "${wanted}" (have: ${all.map((t) => t.name).join(", ")})`, "name one of those, or omit it to test them all");
34917
34877
  }
34918
34878
  if (!route2.resolved) {
34919
34879
  die("crew selftest", `route ${route2.route} is not connected`, "`crew connect`");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.150.2",
3
+ "version": "0.151.1",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",