@tablation/crew 0.149.6 → 0.150.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 +494 -224
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -5680,13 +5680,17 @@ function runAll(commands, cwd, log) {
5680
5680
  }
5681
5681
  async function applyInstall(plan, crewHome, dryRun, log) {
5682
5682
  let changed2 = plan.crontabLine !== null;
5683
+ let replaced = false;
5683
5684
  for (const path of plan.unitPaths) {
5684
5685
  if (dryRun) {
5685
5686
  log.emit(`would write ${path}`);
5686
5687
  continue;
5687
5688
  }
5688
5689
  const before = existsSync16(path) ? readFileSync17(path, "utf8") : null;
5689
- if (before !== plan.unitContent[path]) changed2 = true;
5690
+ if (before !== plan.unitContent[path]) {
5691
+ changed2 = true;
5692
+ if (before !== null) replaced = true;
5693
+ }
5690
5694
  mkdirSync12(dirname9(path), { recursive: true });
5691
5695
  writeFileSync13(path, plan.unitContent[path]);
5692
5696
  log.emit(`wrote ${path}`);
@@ -5703,7 +5707,7 @@ async function applyInstall(plan, crewHome, dryRun, log) {
5703
5707
  if (dryRun) {
5704
5708
  for (const c of plan.preLoadCommands) log.emit(`would run: ${c.join(" ")}`);
5705
5709
  } else {
5706
- const ok = runAll(plan.preLoadCommands, crewHome, log);
5710
+ const ok = runAll(plan.preLoadCommands, crewHome, { emit: log.emit.bind(log), warn: (m) => log.emit(m) });
5707
5711
  if (!ok) log.emit("unload before reload failed \u2014 likely not loaded yet, continuing");
5708
5712
  }
5709
5713
  }
@@ -5727,19 +5731,20 @@ async function applyInstall(plan, crewHome, dryRun, log) {
5727
5731
  }
5728
5732
  log.emit(`crew's own log: ${plan.crewLog}`);
5729
5733
  log.emit(`scheduler log (only what escapes the crew, e.g. a crash before it starts): ${plan.schedulerLog}`);
5730
- return { changed: changed2 };
5734
+ return { changed: changed2, action: !changed2 ? "unchanged" : replaced ? "replaced" : "installed" };
5731
5735
  }
5732
5736
  async function applyUninstall(plan, crewHome, dryRun, log) {
5737
+ let changed2 = false;
5733
5738
  if (plan.mechanism === "none") {
5734
5739
  log.emit("nothing to uninstall on this platform");
5735
- return;
5740
+ return { changed: changed2 };
5736
5741
  }
5737
5742
  if (plan.unloadCommands.length) {
5738
5743
  if (dryRun) {
5739
5744
  for (const c of plan.unloadCommands) log.emit(`would run: ${c.join(" ")}`);
5740
5745
  } else {
5741
- const ok = runAll(plan.unloadCommands, crewHome, log);
5742
- if (!ok) log.warn("unload command failed \u2014 it may not have been loaded; continuing to remove files");
5746
+ const ok = runAll(plan.unloadCommands, crewHome, { emit: log.emit.bind(log), warn: (m) => log.emit(m) });
5747
+ if (!ok) log.emit("unload command failed \u2014 it may not have been loaded; continuing to remove files");
5743
5748
  }
5744
5749
  }
5745
5750
  if (plan.removeLabel) {
@@ -5747,6 +5752,7 @@ async function applyUninstall(plan, crewHome, dryRun, log) {
5747
5752
  log.emit(`would run: launchctl remove ${plan.removeLabel}`);
5748
5753
  } else {
5749
5754
  if (spawnSync5("launchctl", ["remove", plan.removeLabel], { encoding: "utf8" }).status === 0) {
5755
+ changed2 = true;
5750
5756
  log.emit(`removed loaded job ${plan.removeLabel}`);
5751
5757
  }
5752
5758
  }
@@ -5758,6 +5764,7 @@ async function applyUninstall(plan, crewHome, dryRun, log) {
5758
5764
  continue;
5759
5765
  }
5760
5766
  unlinkSync2(path);
5767
+ changed2 = true;
5761
5768
  log.emit(`removed ${path}`);
5762
5769
  }
5763
5770
  if (plan.crontabLine) {
@@ -5765,9 +5772,11 @@ async function applyUninstall(plan, crewHome, dryRun, log) {
5765
5772
  log.emit("would remove crontab entry");
5766
5773
  } else {
5767
5774
  removeCrontabLine(plan.crontabLine);
5775
+ changed2 = true;
5768
5776
  log.emit("removed crontab entry");
5769
5777
  }
5770
5778
  }
5779
+ return { changed: changed2 };
5771
5780
  }
5772
5781
  var CREW_LAUNCHD_PREFIX = "com.tablation.crew";
5773
5782
  function launchAgentsDir() {
@@ -5835,8 +5844,8 @@ function clearForeignLaunchdUnits(crewHome, replace, dryRun, log, dir, loaded) {
5835
5844
  }
5836
5845
  for (const unit of foreign) {
5837
5846
  const why = unit.orphan ? "removing a loaded job whose plist is gone" : unit.program === null ? "replacing a unit with no readable ProgramArguments" : unit.programExists ? "replacing a live other install" : "removing a stale unit whose program is gone";
5838
- log.emit(`${why}: ${unit.label}`);
5839
- removeLaunchdUnit(unit, dryRun, log);
5847
+ log.emit(`${why}: ${unit.label}${dryRun ? " (dry run, not applied)" : ""}`);
5848
+ removeLaunchdUnit(unit, dryRun, { emit: () => void 0, warn: log.warn.bind(log) });
5840
5849
  }
5841
5850
  return true;
5842
5851
  }
@@ -24965,6 +24974,90 @@ function renderInbox(items, byConnection = false, subject) {
24965
24974
  return out.join("\n");
24966
24975
  }
24967
24976
 
24977
+ // src/status-render.ts
24978
+ var WAITING_SHOWN = 5;
24979
+ var plural = (n, w, many = `${w}s`) => `${n} ${n === 1 ? w : many}`;
24980
+ function stateWord(v) {
24981
+ const bits = [];
24982
+ if (v.crewPaused) bits.push("crew paused");
24983
+ else if (v.releasePaused) bits.push("release paused");
24984
+ for (const r of v.pausedRoles) bits.push(`${r} paused`);
24985
+ if (!v.route.enabled) bits.push("route disabled");
24986
+ return bits.length ? bits.join(", ") : "active";
24987
+ }
24988
+ var byRecent = (items, at) => [...items].sort((a, b) => Date.parse(at(b) ?? "") - Date.parse(at(a) ?? "") || 0);
24989
+ function waitingReasonCounts(w) {
24990
+ const counts = /* @__PURE__ */ new Map();
24991
+ for (const t of w) for (const r of t.reasons) counts.set(r, (counts.get(r) ?? 0) + 1);
24992
+ return [...counts].map(([r, n]) => `${r} ${n}`).join(", ");
24993
+ }
24994
+ var waitingLine = (t) => `${t.key} \u2014 ${t.reasons.join(", ")}${t.title ? ` \u2014 ${t.title}` : ""}`;
24995
+ function renderStatus(v, opts) {
24996
+ const now = opts.now ?? Date.now();
24997
+ const out = [];
24998
+ const verbose = opts.verbose;
24999
+ out.push(`${v.ship.name} \xB7 ${v.route.name} \xB7 ${stateWord(v)}`);
25000
+ if (v.runs.length) {
25001
+ for (const x of v.runs) {
25002
+ out.push(`running: ${x.role} \u2014 ${x.ticket ?? "(no ticket)"}${x.repo ? ` in ${x.repo}` : ""} for ${since(x.spawnedAt, now)}` + (verbose ? ` (pid ${x.pid}, since ${x.spawnedAt}${x.deadline ? `, deadline ${x.deadline}` : ""})` : ""));
25003
+ }
25004
+ } else {
25005
+ const last = byRecent(v.lastRuns, (l) => l.finishedAt)[0];
25006
+ out.push(last ? `running: nothing (last run ${since(last.finishedAt, now)} ago)` : "running: nothing");
25007
+ }
25008
+ if (v.reloadRequestedSecondsAgo !== null) {
25009
+ out.push(`reload: requested ${v.reloadRequestedSecondsAgo}s ago, not yet honored \u2014 \`crew reload --now\` forces it`);
25010
+ }
25011
+ const own = byRecent(v.attention, (a) => a.since);
25012
+ const others = v.ships.filter((s) => s.name !== v.ship.name && s.attention.length);
25013
+ const unsafe = v.repos.filter((r) => r.unsafeDetail);
25014
+ if (own.length || others.length || unsafe.length || v.heldReleases.length || v.starved) {
25015
+ out.push("needs attention:");
25016
+ for (const i of own) out.push(` ${i.kind} \u2014 ${i.message}`);
25017
+ for (const r of unsafe) out.push(` base ${r.name} \u2014 UNSAFE, no worktree cuts or releases: ${r.unsafeDetail}`);
25018
+ for (const l of v.heldReleases) out.push(` release: ${l}`);
25019
+ if (v.starved) {
25020
+ out.push(` waiting: ${v.starved.ticket} for ${since(v.starved.since, now)} (passed over ${plural(v.starved.streak, "cycle")} running)`);
25021
+ }
25022
+ for (const s of others) {
25023
+ if (verbose) for (const i of s.attention) out.push(` ship ${s.name}: ${i.kind} \u2014 ${i.message}`);
25024
+ else out.push(` ship ${s.name}: ${plural(s.attention.length, "item")} (\`crew status --verbose\` lists them)`);
25025
+ }
25026
+ }
25027
+ if (v.waiting.length) {
25028
+ const sorted2 = byRecent(v.waiting, (t) => t.updatedAt);
25029
+ out.push(`waiting on you: ${v.waiting.length} (${waitingReasonCounts(v.waiting)})`);
25030
+ const shown = verbose ? sorted2 : sorted2.slice(0, WAITING_SHOWN);
25031
+ for (const t of shown) out.push(` ${waitingLine(t)}`);
25032
+ if (shown.length < sorted2.length) out.push(` \u2026 ${sorted2.length - shown.length} more (\`crew status --verbose\` lists all)`);
25033
+ }
25034
+ const notable = v.repos.filter((r) => verbose || r.notable);
25035
+ for (const r of notable) out.push(`releaser: ${r.name} \u2014 ${r.releaser}`);
25036
+ const rest = v.repos.length - notable.length;
25037
+ if (rest > 0) out.push(`releases: ${plural(rest, "repository", "repositories")} idle, no lock held`);
25038
+ for (const s of v.ships.filter((x) => x.name !== v.ship.name)) out.push(`other ship: ${s.line}`);
25039
+ if (verbose) {
25040
+ out.push("");
25041
+ out.push(`ship: ${v.ship.name} (${v.ship.platform})`);
25042
+ out.push(`route: ${v.route.name} -> ${v.route.dir}`);
25043
+ out.push(`enabled: ${v.route.enabled}`);
25044
+ out.push(`crew: ${v.crewPaused ? "paused" : "active"}`);
25045
+ out.push(`release: ${v.releasePaused ? "paused" : "active"}`);
25046
+ for (const r of v.pausedRoles) out.push(`role ${r}: paused`);
25047
+ out.push(`periscopes: ${v.periscopes.summary}`);
25048
+ if (v.periscopes.relayUrl) out.push(`relay: ${v.periscopes.relayUrl}`);
25049
+ for (const p of v.periscopes.live) out.push(`periscope: ${p}`);
25050
+ out.push(`watermark: ${v.watermark}`);
25051
+ if (v.projects.length) out.push(`projects: ${v.projects.join(", ")}`);
25052
+ for (const l of byRecent(v.lastRuns, (x) => x.finishedAt)) {
25053
+ out.push(`last run: ${l.role} \u2014 ${l.ticket ?? "(no ticket)"} ${l.outcome}, ${since(l.finishedAt, now)} ago`);
25054
+ }
25055
+ const self = v.ships.find((s) => s.name === v.ship.name);
25056
+ if (self) out.push(`ship row: ${self.line}`);
25057
+ }
25058
+ return out;
25059
+ }
25060
+
24968
25061
  // src/connect.ts
24969
25062
  var ConnectHttpError = class extends Error {
24970
25063
  status;
@@ -25709,6 +25802,23 @@ function summarizeOutcomes(outcomes, describe2, isRoutine, noun, verbose) {
25709
25802
  function withFix(message, fix) {
25710
25803
  return `${message.replace(/[.\s]+$/, "")} \u2014 try: ${fix}`;
25711
25804
  }
25805
+ function summarizeJobs(results, o) {
25806
+ const state = o.uninstall ? "not installed" : "installed";
25807
+ const mark3 = o.dryRun ? " (dry run, not applied)" : "";
25808
+ const line = (r) => {
25809
+ if (o.dryRun) return `would ${o.uninstall ? "remove" : "install"} ${r.job} via ${r.mechanism} for ${o.host}${mark3}`;
25810
+ if (r.action === "unchanged") return `${r.job} already ${state} (${r.mechanism})`;
25811
+ return `${r.action} ${r.job} via ${r.mechanism} for ${o.host}`;
25812
+ };
25813
+ if (o.dryRun || o.verbose) return results.map(line);
25814
+ const lines2 = results.filter((r) => r.action !== "unchanged").map(line);
25815
+ const same = results.filter((r) => r.action === "unchanged");
25816
+ if (same.length > 0) {
25817
+ const names = same.map((r) => r.job).join(", ");
25818
+ lines2.push(same.length === results.length ? `all ${same.length} jobs already ${state} (${names})` : `${same.length} job${same.length === 1 ? "" : "s"} already ${state} (${names})`);
25819
+ }
25820
+ return lines2;
25821
+ }
25712
25822
 
25713
25823
  // src/agents-sync-run.ts
25714
25824
  async function runAgentsSync(target, o) {
@@ -26470,6 +26580,176 @@ function planSampleTicket(i) {
26470
26580
  };
26471
26581
  }
26472
26582
 
26583
+ // src/doctor-report.ts
26584
+ var DOCTOR_SECTIONS = [
26585
+ { id: "ship", title: "Ship" },
26586
+ { id: "tracker", title: "Tracker" },
26587
+ { id: "repositories", title: "Repositories" },
26588
+ { id: "seats", title: "Seats" },
26589
+ { id: "tools", title: "Tools" },
26590
+ { id: "passengers", title: "Periscopes, passengers and sandbox" }
26591
+ ];
26592
+ var RANK = { ok: 0, info: 1, note: 2, warning: 3, blocker: 4 };
26593
+ var worse = (a, b) => RANK[b] > RANK[a] ? b : a;
26594
+ function classifySeverity(label, text2) {
26595
+ const s = `${label} ${text2}`;
26596
+ if (/\b(BLOCKER|ERROR)\b/.test(s)) return "blocker";
26597
+ if (/^attention$/i.test(label)) return "warning";
26598
+ if (/\b(WARN|WARNING|ATTENTION|DEAD|NOT FOUND|NOT READY|NOT AVAILABLE|NOT installed|NO row|MISMATCH|STALE|FAILED)\b|\(missing\)|\bMISSING\b|\bnot registered\b|\b\d{3} —/.test(s)) return "warning";
26599
+ if (/\bNOTE\b|cannot enforce|\bnot run\b|release readiness|\babsent\b|\bmissing\b|^none\b|\bnot minted\b|could not (be )?check|\bunknown\b|no operator|\bwithout\b|discovery unavailable/.test(s)) return "note";
26600
+ return "ok";
26601
+ }
26602
+ var SECTION_BY_LABEL = [
26603
+ ["seats", /^(seat |operator identity|api key role|can mint|capability)/],
26604
+ ["passengers", /^(periscopes?\b|periscope mcp|host passengers|docker|ssh-keygen|image|relay (host|control|tunnel)|sandbox|attention|foreign launchd)/],
26605
+ ["tracker", /^(contract|authorship|runtime columns|link columns|public replies|crew assisted|release seat|ship (record|row|holds)|crew manifest|branch\/pull|pull request|branch links)/],
26606
+ ["tools", /^(agent binary|toolchain|git\b|mcp|pair\b|auth\b|credential helper|hook |repo toolchain|push auth|gh\b|node\b|docker\b)/],
26607
+ ["ship", /^(ship|routes?|bundle|role concurrency|persona avatar|key store|events log|scheduler unit|passengers unit|daemon|reload request|crew version)/]
26608
+ ];
26609
+ function sectionOf(label) {
26610
+ for (const [id, re] of SECTION_BY_LABEL) if (re.test(label)) return id;
26611
+ return void 0;
26612
+ }
26613
+ var LABEL_RE = /^([A-Za-z][\w.\-/ ]{0,38}?):\s+(\S.*)$/;
26614
+ var MARKER_RE = /^(WARNING|WARN|ERROR|BLOCKER|ATTENTION|NOTE|MISSING|NOT)\b/;
26615
+ var DoctorReport = class {
26616
+ findings = [];
26617
+ /** Set while a repository's block is being written; lines are filed under it and grouped across repositories. */
26618
+ repo;
26619
+ /** Repository names of the route; a line outside a repo block that names exactly one is grouped with the same line for the others. */
26620
+ repoNames = [];
26621
+ last;
26622
+ mentionedRepo(text2) {
26623
+ const hits = this.repoNames.filter((n) => text2.split("\n").some((l) => l.includes(`${n}:`) && new RegExp(`(?:^|[\\s/])${n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:`).test(l)));
26624
+ return hits.length === 1 ? hits[0] : void 0;
26625
+ }
26626
+ /** Take one check's output (one or more lines, as it would have been printed). */
26627
+ line(raw, ctx = {}) {
26628
+ const repo = ctx.repo ?? this.repo;
26629
+ for (const physical of raw.split("\n")) {
26630
+ if (physical.trim() === "") continue;
26631
+ const continuation = /^\s{2,}/.test(physical);
26632
+ const body = physical.trim().replace(/^-\s+/, "");
26633
+ const m = MARKER_RE.test(body) ? null : /^(repo \S+?):(\/\S.*)$/.exec(body) ?? LABEL_RE.exec(body);
26634
+ if (continuation && this.last && !m && !MARKER_RE.test(body)) {
26635
+ this.last.text += `
26636
+ ${body}`;
26637
+ this.last.severity = worse(this.last.severity, classifySeverity("", body));
26638
+ continue;
26639
+ }
26640
+ const label = m ? m[1].trim() : "";
26641
+ const text2 = m ? m[2].trim() : body;
26642
+ const parent = continuation ? this.last : void 0;
26643
+ const section = repo ? "repositories" : sectionOf(label) ?? parent?.section ?? this.last?.section ?? "ship";
26644
+ const f = { severity: classifySeverity(label, text2), section, label, text: text2, ...repo ? { repo } : {} };
26645
+ if (!repo) {
26646
+ const mentions = this.mentionedRepo(text2);
26647
+ if (mentions) f.mentions = mentions;
26648
+ }
26649
+ this.findings.push(f);
26650
+ this.last = f;
26651
+ }
26652
+ }
26653
+ counts() {
26654
+ const merged = groupFindings(this.findings.filter((f) => RANK[f.severity] >= RANK.note));
26655
+ const c = { blocker: 0, warning: 0, note: 0, passed: 0 };
26656
+ for (const g of merged) c[g.severity]++;
26657
+ c.passed = this.findings.filter((f) => RANK[f.severity] < RANK.note).length;
26658
+ return c;
26659
+ }
26660
+ };
26661
+ function groupFindings(findings) {
26662
+ const out = [];
26663
+ const byKey = /* @__PURE__ */ new Map();
26664
+ for (const f of findings) {
26665
+ const repo = f.repo ?? f.mentions;
26666
+ if (!repo) {
26667
+ out.push({ ...f, repos: [] });
26668
+ continue;
26669
+ }
26670
+ const norm = (s) => s.split(repo).join("<repo>");
26671
+ const key = [f.severity, f.section, norm(f.label), norm(f.text)].join("\0");
26672
+ const hit = byKey.get(key);
26673
+ if (hit) {
26674
+ if (!hit.repos.includes(repo)) hit.repos.push(repo);
26675
+ continue;
26676
+ }
26677
+ const g = { ...f, repos: [repo] };
26678
+ byKey.set(key, g);
26679
+ out.push(g);
26680
+ }
26681
+ return out;
26682
+ }
26683
+ var plural2 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
26684
+ function reposPhrase(repos) {
26685
+ return repos.length <= 5 ? `repositories ${repos.join(", ")}` : `${repos.length} repositories (${repos.slice(0, 3).join(", ")}, \u2026)`;
26686
+ }
26687
+ var SEVERITY_WORD = { blocker: "BLOCKER", warning: "WARNING", note: "NOTE " };
26688
+ function verdictLine(c) {
26689
+ const parts = [];
26690
+ if (c.blocker) parts.push(plural2(c.blocker, "blocker"));
26691
+ if (c.warning) parts.push(plural2(c.warning, "warning"));
26692
+ if (c.note) parts.push(plural2(c.note, "note"));
26693
+ if (parts.length === 0) return `verdict: all clear \u2014 ${plural2(c.passed, "check")} passed`;
26694
+ const lead = c.blocker ? "needs action" : c.warning ? "usable, with warnings" : "ok, with notes";
26695
+ return `verdict: ${lead} \u2014 ${parts.join(", ")}; ${plural2(c.passed, "check")} passed`;
26696
+ }
26697
+ function indentContinuation(text2, pad) {
26698
+ return text2.split("\n").map((l, i) => i === 0 ? l : `${" ".repeat(pad)}${l}`).join("\n");
26699
+ }
26700
+ function renderDoctor(report, header, verbose) {
26701
+ const c = report.counts();
26702
+ const out = [...header];
26703
+ if (!verbose) {
26704
+ const shown = groupFindings(report.findings.filter((f) => RANK[f.severity] >= RANK.note)).sort((a, b) => RANK[b.severity] - RANK[a.severity]);
26705
+ for (const g of shown) {
26706
+ const sev = SEVERITY_WORD[g.severity];
26707
+ const where = g.repos.length ? ` [${reposPhrase(g.repos)}]` : "";
26708
+ const head = `${sev} ${g.label ? `${g.label}: ` : ""}`;
26709
+ let text2 = g.text.replace(/^(WARNING|WARN|NOTE|BLOCKER|ERROR|ATTENTION)\s+/, "");
26710
+ if (g.repos.length > 1) for (const r of g.repos) text2 = text2.split(r).join("<repo>");
26711
+ out.push(`${head}${indentContinuation(text2, 4)}${where}`);
26712
+ }
26713
+ if (shown.length) out.push("");
26714
+ if (c.passed) out.push(`${plural2(c.passed, "check")} passed (\`crew doctor --verbose\` lists them)`);
26715
+ out.push(verdictLine(c));
26716
+ return `${out.join("\n")}
26717
+ `;
26718
+ }
26719
+ for (const s of DOCTOR_SECTIONS) {
26720
+ const inSection = report.findings.filter((f) => f.section === s.id);
26721
+ if (inSection.length === 0) continue;
26722
+ out.push("", s.title, "-".repeat(s.title.length));
26723
+ const block = (items, indent, strip) => {
26724
+ const labelOf2 = (f) => strip && f.label === `repo ${strip}` ? "path" : f.label;
26725
+ const width = Math.min(26, Math.max(...items.map((f) => labelOf2(f) ? labelOf2(f).length + 1 : 0))) + 1;
26726
+ for (const f of items) {
26727
+ const l = labelOf2(f);
26728
+ const lab = l ? `${l}:` : "";
26729
+ const col = lab.length >= width ? `${lab} ` : lab.padEnd(width);
26730
+ out.push(`${" ".repeat(indent)}${col}${indentContinuation(f.text, indent + col.length)}`);
26731
+ }
26732
+ };
26733
+ if (s.id === "repositories") {
26734
+ const names = [...new Set(inSection.map((f) => f.repo ?? ""))];
26735
+ for (const n of names) {
26736
+ out.push(n ? ` ${n}` : "");
26737
+ block(inSection.filter((f) => (f.repo ?? "") === n), 4, n);
26738
+ }
26739
+ } else block(inSection, 0);
26740
+ }
26741
+ out.push("", verdictLine(c));
26742
+ return `${out.join("\n")}
26743
+ `;
26744
+ }
26745
+ function fixPhaseNothingToOffer(o) {
26746
+ const lines2 = o.notes.map((n) => `fix: ${n}`);
26747
+ if (!o.fixFlag) return lines2;
26748
+ const outstanding = o.blockers + o.warnings;
26749
+ lines2.push(outstanding ? `fix: no automatic fix applies; the ${plural2(outstanding, "finding")} above ${outstanding === 1 ? "needs" : "need"} action` : "fix: no automatic fix applies, and nothing needs one");
26750
+ return lines2;
26751
+ }
26752
+
26473
26753
  // src/worktree-sweep.ts
26474
26754
  import { existsSync as existsSync54, readFileSync as readFileSync53, readdirSync as readdirSync16 } from "fs";
26475
26755
  import { basename as basename14, dirname as dirname33, join as join56, resolve as resolve5 } from "path";
@@ -26905,7 +27185,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
26905
27185
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
26906
27186
  import { join as join58 } from "path";
26907
27187
  function builtVersion() {
26908
- return true ? "0.149.6" : null;
27188
+ return true ? "0.150.1" : null;
26909
27189
  }
26910
27190
  var REBUILD_HINT = "rebuild with npm run build";
26911
27191
  function newestMtime(path) {
@@ -29103,7 +29383,7 @@ function usage(problem, requested = false) {
29103
29383
  crew deploy [route] release now, even with nothing new to merge
29104
29384
  crew watch [route] live view of what the crew is doing
29105
29385
  crew --version [--json] print the crew version on one line (also: crew version); --json adds home and compiled
29106
- crew status [route] [--json] paused/running state; --json for a machine reader
29386
+ crew status [route] [--json] [--verbose] what is running and what needs a person; --verbose adds configuration and full lists; --json for a machine reader
29107
29387
  crew projects [--route R] [--json] the Projects rows each route can read (id, name, prefix, work mode)
29108
29388
  crew provision --key K --route WS[/PROJECT] [--forge-host H] [--ship-name N] [--json] one non-interactive run: connect, forge tokens,
29109
29389
  enable routes, install units with lingering, start the daemon; safe to re-run (CREW_CONNECT_KEY,
@@ -29116,7 +29396,7 @@ function usage(problem, requested = false) {
29116
29396
  crew credential get|store|erase git credential helper answering from ship.forges (git runs it; not for hand use)
29117
29397
  crew whoami [route] [--json] the signed-in identity, key role, operator Crew row and credential source per route
29118
29398
  crew reload make the running daemon re-read crew.yaml (--now: restart it immediately)
29119
- crew doctor [route] [--fix] [--offline] [--json] preflight; --fix enables clean routes and offers crew install;
29399
+ crew doctor [route] [--fix] [--offline] [--verbose] [--json] preflight: findings first, then a verdict; --verbose lists every check; --fix enables clean routes and offers crew install;
29120
29400
  --offline skips push probes; --json prints push-auth and tool checks only
29121
29401
  crew selftest [route] [--toolchain NAME] [--json] launch each toolchain as a run would and prove it reaches the tracker
29122
29402
  crew sample-ticket [route] [--remove] [--dry-run] [--json] file one ticket on a throwaway repo that walks the dev, QA and release loop
@@ -29998,33 +30278,33 @@ if (command === "passenger-sync-daemon") {
29998
30278
  async function installScheduler(opts = {}) {
29999
30279
  const host = hostPlatform();
30000
30280
  if (host === "windows") {
30001
- process.stderr.write("crew install: no scheduler support yet for Windows (Task Scheduler is planned, not built)\n");
30002
- process.exit(2);
30281
+ die("crew install", "no scheduler support yet for Windows (Task Scheduler is planned, not built)", "run `crew daemon` in a terminal instead");
30003
30282
  }
30283
+ const installLog = {
30284
+ emit: (m) => emit.note(m),
30285
+ warn: (m) => emit.warn(withFix(`crew install: ${m}`, "`crew doctor`"))
30286
+ };
30004
30287
  if (host === "macos") {
30005
30288
  const ok = clearForeignLaunchdUnits(CREW_HOME, !!opts.replace, dryRun, {
30006
- emit: (m) => process.stdout.write(`${m}
30007
- `),
30008
- warn: (m) => process.stderr.write(`crew install: ${m}
30009
- `)
30289
+ // A removed foreign unit is a real change, so it is shown by default.
30290
+ emit: (m) => emit.emit(m),
30291
+ warn: (m) => emit.warn(withFix(`crew install: ${m}`, "`crew install --replace`"))
30010
30292
  }, void 0, loadedCrewLabels());
30011
30293
  if (!ok) return false;
30012
30294
  }
30013
30295
  const installPathProblem = cfg.routes.some((r) => r.enabled && r.hostPassengers) ? dockerPathProblem(cfg.ship) : void 0;
30014
30296
  if (installPathProblem) {
30015
- process.stderr.write(`crew install: Host Passengers is on but ${installPathProblem}
30016
- `);
30297
+ emit.error(withFix(`crew install: Host Passengers is on but ${installPathProblem}`, "`crew doctor`"));
30017
30298
  process.exitCode = 1;
30018
30299
  } else if (!dryRun && cfg.routes.some((r) => r.enabled && r.hostPassengers) && dockerAvailable()) {
30019
30300
  const image = passengerImageRef(cfg);
30020
30301
  if (imagePresent(image)) {
30021
- process.stdout.write(`Host Passengers image ${image} is already present
30022
- `);
30302
+ emit.note(`Host Passengers image ${image} is already present`);
30023
30303
  } else {
30024
- process.stdout.write(`pulling Host Passengers image ${image}
30025
- `);
30304
+ emit.note(`pulling Host Passengers image ${image}`);
30026
30305
  try {
30027
30306
  ensureImage(image);
30307
+ emit.emit(`pulled Host Passengers image ${image}`);
30028
30308
  } catch (e) {
30029
30309
  emit.warn(withFix(`crew install: could not pull Host Passengers image ${image}: ${e.message}`, "`crew doctor`"));
30030
30310
  process.exitCode = 1;
@@ -30032,24 +30312,24 @@ if (command === "passenger-sync-daemon") {
30032
30312
  }
30033
30313
  }
30034
30314
  const hasSystemd = detectSystemd();
30315
+ const results = [];
30035
30316
  for (const job of ["run", "release", "passengers"]) {
30036
30317
  const plan = planInstall(cfg.ship, CREW_HOME, host, hasSystemd, job, installContext());
30037
- process.stdout.write(`installing ${job} via ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}
30038
- `);
30039
- await applyInstall(plan, CREW_HOME, dryRun, {
30040
- emit: (m) => process.stdout.write(`${m}
30041
- `),
30042
- warn: (m) => process.stderr.write(`crew install: ${m}
30043
- `)
30044
- });
30318
+ emit.note(`installing ${job} via ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}`);
30319
+ try {
30320
+ const { action } = await applyInstall(plan, CREW_HOME, dryRun, installLog);
30321
+ results.push({ job, mechanism: plan.mechanism, action });
30322
+ } catch (e) {
30323
+ return die("crew install", e.message.replace(/^crew install:\s*/, ""), "`crew doctor`", 1);
30324
+ }
30045
30325
  }
30326
+ for (const l of summarizeJobs(results, { dryRun, verbose: flag("verbose"), host })) emit.emit(l);
30046
30327
  if (host === "linux" && hasSystemd) {
30047
30328
  const label = labelFor(CREW_HOME, "run");
30048
30329
  const staleTimer = join64(homedir11(), ".config", "systemd", "user", `${label}.timer`);
30049
30330
  if (existsSync60(staleTimer)) {
30050
- process.stdout.write(
30051
- `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
30052
- `
30331
+ emit.emit(
30332
+ `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run, not applied)" : ""}`
30053
30333
  );
30054
30334
  if (!dryRun) {
30055
30335
  spawnSync14("systemctl", ["--user", "disable", "--now", `${label}.timer`], { cwd: CREW_HOME, env: withUserBusEnv() });
@@ -30115,12 +30395,13 @@ if (command === "passenger-sync-daemon") {
30115
30395
  const crontab = o.host === "linux" ? spawnSync14("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
30116
30396
  const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
30117
30397
  const plan = planFix({ routes, schedulerAbsent, host: o.host });
30118
- for (const n of plan.notes) process.stdout.write(`fix: ${n}
30119
- `);
30120
30398
  if (plan.actions.length === 0) {
30121
- process.stdout.write("fix: nothing to change\n");
30399
+ for (const l of fixPhaseNothingToOffer({ notes: plan.notes, fixFlag: o.fixFlag, blockers: o.blockers, warnings: o.warnings })) process.stdout.write(`${l}
30400
+ `);
30122
30401
  return;
30123
30402
  }
30403
+ for (const n of plan.notes) process.stdout.write(`fix: ${n}
30404
+ `);
30124
30405
  const prompter = o.prompt ? terminalPrompter() : void 0;
30125
30406
  const changed2 = [];
30126
30407
  const enabledSound = new Set(routes.filter((r) => r.enabled && r.hasRepos && r.problems.length === 0).map((r) => r.route));
@@ -30294,13 +30575,14 @@ ${changed2.map((c) => ` - ${c}
30294
30575
  async function releaserLine(tracker, routeName, repo, release) {
30295
30576
  const who2 = release.ship ? `released by ${release.ship}` : "any ship may release";
30296
30577
  let lock2;
30578
+ let lockHeld = false;
30297
30579
  try {
30298
30580
  const st = await tracker.lockState(releaseLockScope(routeName, repo));
30299
- lock2 = st === void 0 ? "no Locks table" : !st.exists ? "lock row MISSING (run crew connect)" : st.holder ? `lock held by ${st.holder}` : "lock row free";
30581
+ lock2 = st === void 0 ? "no Locks table" : !st.exists ? "lock row MISSING (run crew connect)" : st.holder ? (lockHeld = true, `lock held by ${st.holder}`) : "lock row free";
30300
30582
  } catch (e) {
30301
30583
  lock2 = `lock unreadable (${e.message})`;
30302
30584
  }
30303
- return `${who2}; ${lock2}`;
30585
+ return { line: `${who2}; ${lock2}`, lockHeld };
30304
30586
  }
30305
30587
  async function sweepClosedTickets(c, target, branch, tracker, dryRun2, remit, idle = false) {
30306
30588
  if (remoteOf(target.dir)) return;
@@ -34361,28 +34643,26 @@ ${where.join("\n")}`);
34361
34643
  case "uninstall": {
34362
34644
  const host = hostPlatform();
34363
34645
  if (host === "windows") {
34364
- process.stdout.write("nothing installed on Windows\n");
34646
+ emit.emit("nothing installed on Windows");
34365
34647
  break;
34366
34648
  }
34649
+ const uninstallLog = {
34650
+ emit: (m) => emit.note(m),
34651
+ warn: (m) => emit.warn(withFix(`crew uninstall: ${m}`, "`crew doctor`"))
34652
+ };
34653
+ const results = [];
34367
34654
  for (const job of ["run", "release", "passengers"]) {
34368
34655
  const plan = planUninstall(cfg.ship, CREW_HOME, host, detectSystemd(), job);
34369
- process.stdout.write(`uninstalling ${job} ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}
34370
- `);
34371
- await applyUninstall(plan, CREW_HOME, dryRun, {
34372
- emit: (m) => process.stdout.write(`${m}
34373
- `),
34374
- warn: (m) => process.stderr.write(`crew uninstall: ${m}
34375
- `)
34376
- });
34656
+ emit.note(`uninstalling ${job} ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}`);
34657
+ const { changed: changed2 } = await applyUninstall(plan, CREW_HOME, dryRun, uninstallLog);
34658
+ results.push({ job, mechanism: plan.mechanism, action: changed2 ? "removed" : "unchanged" });
34377
34659
  }
34660
+ for (const l of summarizeJobs(results, { uninstall: true, dryRun, verbose: flag("verbose"), host })) emit.emit(l);
34378
34661
  if (flag("all") && host === "macos") {
34379
- process.stdout.write(`uninstalling every crew launchd unit${dryRun ? " (dry run)" : ""}
34380
- `);
34662
+ emit.note(`uninstalling every crew launchd unit${dryRun ? " (dry run)" : ""}`);
34381
34663
  removeAllLaunchdUnits(dryRun, {
34382
- emit: (m) => process.stdout.write(`${m}
34383
- `),
34384
- warn: (m) => process.stderr.write(`crew uninstall: ${m}
34385
- `)
34664
+ emit: (m) => emit.emit(m),
34665
+ warn: uninstallLog.warn
34386
34666
  }, void 0, loadedCrewLabels());
34387
34667
  }
34388
34668
  break;
@@ -34796,81 +35076,63 @@ ${where.join("\n")}`);
34796
35076
  `);
34797
35077
  break;
34798
35078
  }
34799
- const owed = [
34800
- ...todo.map((i) => `${displayKey(i.ticket)} \u2014 ${i.reasons.join(", ")}${i.ticket.title ? ` \u2014 ${i.ticket.title}` : ""}`),
34801
- ...openShipAttention(state).map((i) => `ship ${cfg.ship.name}: ${i.kind} \u2014 ${i.message}`),
34802
- ...shipRows.filter((s) => s.name !== cfg.ship.name).flatMap((s) => (s.attention ?? []).map((i) => `ship ${s.name}: ${i.kind} \u2014 ${i.message}`))
34803
- ];
34804
- if (owed.length) process.stdout.write(`to do (${owed.length}):
34805
- ${owed.map((l) => ` ${l}
34806
- `).join("")}
34807
- `);
34808
- process.stdout.write(
34809
- `ship: ${cfg.ship.name} (${cfg.ship.platform})
34810
- route: ${route2.route} -> ${route2.dir}
34811
- enabled: ${route2.enabled}
34812
- periscopes: ${periscopeSummary(cfg)}
34813
- ` + (routeRelayUrl(route2) ? `relay: ${routeRelayUrl(route2)}
34814
- ` : "") + periscopes.map((p) => `periscope: ${p.ticket} ${p.repo} ${p.url} ${p.state}${p.serving ? "" : " (not serving)"} expires ${p.expiresAt}
34815
- `).join("") + `crew: ${state.isPaused() ? "paused" : "active"}
34816
- release: ${state.releaseSkipReason() ? "paused" : "active"}
34817
- watermark: ${state.watermark(routeSlug(route2.route))}
34818
- `
34819
- );
34820
- for (const r of ["dev", "design", "qa"]) {
34821
- if (state.isRolePaused(r)) process.stdout.write(`role ${r}: paused
34822
- `);
34823
- }
34824
- const reloadWaitingAt = readReloadRequestedAt(cfg.ship.stateDir);
34825
- if (reloadWaitingAt !== null) {
34826
- process.stdout.write(`reload: requested ${Math.max(0, Math.round((Date.now() - reloadWaitingAt) / 1e3))}s ago, not yet honored \u2014 \`crew reload --now\` forces it
34827
- `);
34828
- }
34829
- if (projects.length) process.stdout.write(`projects: ${projects.map((p) => p.label).join(", ")}
34830
- `);
34831
- for (const i of openShipAttention(state)) {
34832
- process.stdout.write(`attention: ${i.kind} \u2014 ${i.message}
34833
- `);
34834
- }
34835
- for (const r of await resolvedRepos(route2)) {
34836
- const bh = baseHealth(r);
34837
- if (bh.unsafe) process.stdout.write(`base: ${r.name} \u2014 UNSAFE, no worktree cuts or releases: ${bh.detail}
34838
- `);
34839
- process.stdout.write(`releaser: ${r.name} \u2014 ${await releaserLine(statusTracker, route2.route, r.name, r.config.release)}
34840
- `);
34841
- }
35079
+ const shipAttention = openShipAttention(state);
35080
+ let heldReleases = [];
34842
35081
  try {
34843
35082
  const open = await statusTracker.openTickets();
34844
- const held = heldByBlockers(
35083
+ heldReleases = describeHeld(heldByBlockers(
34845
35084
  open,
34846
35085
  statusTracker.contract.statuses.verified,
34847
35086
  blockerInfoMap(open, await statusTracker.ticketsByIds(missingBlockerIds(open)))
34848
- );
34849
- for (const line of describeHeld(held)) process.stdout.write(`release: ${line}
34850
- `);
35087
+ ));
34851
35088
  } catch {
34852
35089
  }
34853
- if (waiting) {
34854
- process.stdout.write(
34855
- `waiting: ${waiting.ticket} for ${since(waiting.since)} (passed over ${fairness.streak()} cycle${fairness.streak() === 1 ? "" : "s"} running)
34856
- `
34857
- );
34858
- }
34859
- for (const x of runs) {
34860
- process.stdout.write(`running: ${x.role} \u2014 ${x.ticket ?? "(no ticket)"}${x.repo ? ` in ${x.repo}` : ""} (pid ${x.pid}, since ${x.spawnedAt}${x.deadline ? `, deadline ${x.deadline}` : ""})
34861
- `);
35090
+ const repoViews = [];
35091
+ for (const r of await resolvedRepos(route2)) {
35092
+ const bh = baseHealth(r);
35093
+ const rel = await releaserLine(statusTracker, route2.route, r.name, r.config.release);
35094
+ repoViews.push({
35095
+ name: r.name,
35096
+ unsafeDetail: bh.unsafe ? bh.detail : void 0,
35097
+ releaser: rel.line,
35098
+ notable: rel.lockHeld || !!r.config.release.ship && r.config.release.ship !== cfg.ship.name
35099
+ });
34862
35100
  }
34863
- if (shipRows.length) {
34864
- process.stdout.write("ships:\n");
34865
- for (const s of shipRows) {
34866
- process.stdout.write(` ${renderShipLine(s, issueLabelById)}
34867
- `);
34868
- if (s.name !== cfg.ship.name) {
34869
- for (const i of s.attention ?? []) process.stdout.write(` attention: ${i.kind} \u2014 ${i.message}
35101
+ const reloadWaitingAt = readReloadRequestedAt(cfg.ship.stateDir);
35102
+ const lastRunView = [...lastRuns.values()].filter((l) => l.route === routeSlug(route2.route)).map((l) => ({ role: l.role, ticket: l.ticket, finishedAt: l.finishedAt, outcome: l.outcome }));
35103
+ for (const line of renderStatus({
35104
+ ship: { name: cfg.ship.name, platform: cfg.ship.platform },
35105
+ route: { name: route2.route, dir: route2.dir, enabled: route2.enabled },
35106
+ crewPaused: state.isPaused(),
35107
+ releasePaused: state.releaseSkipReason() !== null,
35108
+ pausedRoles: ["dev", "design", "qa"].filter((r) => state.isRolePaused(r)),
35109
+ periscopes: {
35110
+ summary: periscopeSummary(cfg),
35111
+ relayUrl: routeRelayUrl(route2) || void 0,
35112
+ live: periscopes.map((p) => `${p.ticket} ${p.repo} ${p.url} ${p.state}${p.serving ? "" : " (not serving)"} expires ${p.expiresAt}`)
35113
+ },
35114
+ watermark: String(state.watermark(routeSlug(route2.route))),
35115
+ projects: projects.map((p) => p.label),
35116
+ reloadRequestedSecondsAgo: reloadWaitingAt === null ? null : Math.max(0, Math.round((Date.now() - reloadWaitingAt) / 1e3)),
35117
+ runs: runs.map((x) => ({ role: x.role, ticket: x.ticket, repo: x.repo, pid: x.pid, spawnedAt: x.spawnedAt, deadline: x.deadline })),
35118
+ lastRuns: lastRunView,
35119
+ attention: shipAttention.map((i) => ({ kind: i.kind, message: i.message, since: i.since })),
35120
+ waiting: todo.map((i) => ({
35121
+ key: displayKey(i.ticket),
35122
+ title: i.ticket.title,
35123
+ reasons: i.reasons,
35124
+ updatedAt: i.ticket.updated_at
35125
+ })),
35126
+ repos: repoViews,
35127
+ heldReleases,
35128
+ starved: waiting ? { ticket: waiting.ticket, since: waiting.since, streak: fairness.streak() } : void 0,
35129
+ ships: shipRows.map((s) => ({
35130
+ name: s.name ?? "(unnamed)",
35131
+ line: renderShipLine(s, issueLabelById),
35132
+ attention: (s.attention ?? []).map((i) => ({ kind: i.kind, message: i.message }))
35133
+ }))
35134
+ }, { verbose: flag("verbose") })) process.stdout.write(`${line}
34870
35135
  `);
34871
- }
34872
- }
34873
- }
34874
35136
  break;
34875
35137
  }
34876
35138
  case "doctor": {
@@ -35030,50 +35292,51 @@ watermark: ${state.watermark(routeSlug(route2.route))}
35030
35292
  `);
35031
35293
  break;
35032
35294
  }
35033
- process.stdout.write(
35295
+ const R = new DoctorReport();
35296
+ R.line(
35034
35297
  `ship: ${cfg.ship.name} (${host})
35035
35298
  routes: ${cfg.routes.map((c) => c.route).join(", ")}
35036
35299
  `
35037
35300
  );
35038
35301
  if (staleBundle) {
35039
- process.stdout.write(`bundle: BLOCKER ${staleBundle.message}
35302
+ R.line(`bundle: BLOCKER ${staleBundle.message}
35040
35303
  `);
35041
35304
  process.exitCode = 1;
35042
35305
  }
35043
35306
  const dockerFinding = dockerDaemonFinding({ needed: await shipNeedsDocker(), up: dockerAvailable() });
35044
35307
  const dockerNote = dockerFinding ? " (consequence of the Docker finding above)" : "";
35045
35308
  if (dockerFinding) {
35046
- process.stdout.write(`docker: BLOCKER ${dockerFinding.message} \u2014 ${dockerFinding.remedy}
35309
+ R.line(`docker: BLOCKER ${dockerFinding.message} \u2014 ${dockerFinding.remedy}
35047
35310
  `);
35048
35311
  process.exitCode = 1;
35049
35312
  }
35050
35313
  for (const f of deadTunnelFindings(deadTunnels(cfg.ship.stateDir), Boolean(dockerFinding))) {
35051
- process.stdout.write(`tunnel: DEAD ${f.message} \u2014 ${f.remedy}
35314
+ R.line(`tunnel: DEAD ${f.message} \u2014 ${f.remedy}
35052
35315
  `);
35053
35316
  }
35054
- for (const w of roleCapWarnings(cfg.ship)) process.stdout.write(`role concurrency: WARN ${w}
35317
+ for (const w of roleCapWarnings(cfg.ship)) R.line(`role concurrency: WARN ${w}
35055
35318
  `);
35056
- for (const r of cfg.routes) for (const f of routeAvatarFailures(cfg.ship.stateDir, r.route)) process.stdout.write(`persona avatar: WARN ${r.route}: ${f.role} avatar failed to upload (${f.detail}); run \`crew agents sync\` again
35319
+ for (const r of cfg.routes) for (const f of routeAvatarFailures(cfg.ship.stateDir, r.route)) R.line(`persona avatar: WARN ${r.route}: ${f.role} avatar failed to upload (${f.detail}); run \`crew agents sync\` again
35057
35320
  `);
35058
- for (const t of rejectedTunnels(cfg.ship.stateDir)) process.stdout.write(`relay tunnel: ATTENTION ${tunnelRejectedMessage(t.workspaceId, t.quickExits)}
35321
+ for (const t of rejectedTunnels(cfg.ship.stateDir)) R.line(`relay tunnel: ATTENTION ${tunnelRejectedMessage(t.workspaceId, t.quickExits)}
35059
35322
  `);
35060
- for (const workspaceId of controlRefusedTunnels(cfg.ship.stateDir)) process.stdout.write(`relay tunnel: ATTENTION ${relayControlUnsupportedMessage(workspaceId)}
35323
+ for (const workspaceId of controlRefusedTunnels(cfg.ship.stateDir)) R.line(`relay tunnel: ATTENTION ${relayControlUnsupportedMessage(workspaceId)}
35061
35324
  `);
35062
- process.stdout.write(`periscopes: ${periscopeSummary(cfg)}
35325
+ R.line(`periscopes: ${periscopeSummary(cfg)}
35063
35326
  `);
35064
- process.stdout.write(`key store: ${describeKeyStore(cfg.ship)}
35327
+ R.line(`key store: ${describeKeyStore(cfg.ship)}
35065
35328
  `);
35066
35329
  const previewProblem = await previewHostProblem(cfg);
35067
35330
  if (previewProblem) {
35068
35331
  const blocks = previewHostFinding(previewProblem).severity === "blocker";
35069
- process.stdout.write(` ${blocks ? "BLOCKER" : "ATTENTION"} ${previewProblem}
35332
+ R.line(` ${blocks ? "BLOCKER" : "ATTENTION"} ${previewProblem}
35070
35333
  `);
35071
35334
  if (blocks) process.exitCode = 1;
35072
35335
  }
35073
35336
  try {
35074
35337
  const evFile = eventFileFor(cfg.ship.stateDir);
35075
35338
  const evSize = existsSync60(evFile) ? statSync19(evFile).size : 0;
35076
- process.stdout.write(
35339
+ R.line(
35077
35340
  evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
35078
35341
  ` : "events log: ok\n"
35079
35342
  );
@@ -35089,7 +35352,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35089
35352
  }
35090
35353
  });
35091
35354
  if (abandons === false) {
35092
- process.stdout.write(
35355
+ R.line(
35093
35356
  "scheduler unit: WARN the installed unit does not leave agent runs alone when the daemon restarts (no AbandonProcessGroup / KillMode=process) \u2014 a daemon crash or relaunch kills the run in flight; run `crew install`\n"
35094
35357
  );
35095
35358
  }
@@ -35104,7 +35367,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35104
35367
  }
35105
35368
  });
35106
35369
  if (keeps === false) {
35107
- process.stdout.write(
35370
+ R.line(
35108
35371
  "passengers unit: WARN the installed unit lacks KillMode=process, so systemd kills the relay tunnel each time the sync exits (tunnel never reaches connected); run `crew install`\n"
35109
35372
  );
35110
35373
  }
@@ -35115,19 +35378,19 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35115
35378
  if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync60(p))) {
35116
35379
  const st = spawnSync14(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
35117
35380
  if (!st.error && st.status !== 0) {
35118
- process.stdout.write("daemon unit: WARN installed but not running \u2014 no work is picked up; run `crew reload` (or `crew daemon start`), and `crew install` if the unit still says Restart=on-failure\n");
35381
+ R.line("daemon unit: WARN installed but not running \u2014 no work is picked up; run `crew reload` (or `crew daemon start`), and `crew install` if the unit still says Restart=on-failure\n");
35119
35382
  }
35120
35383
  }
35121
35384
  }
35122
35385
  if (daemonLiveness) {
35123
- process.stdout.write(`daemon: ${daemonLineText(daemonLiveness)}
35386
+ R.line(`daemon: ${daemonLineText(daemonLiveness)}
35124
35387
  `);
35125
35388
  if (daemonLiveness.state === "exited") process.exitCode = 1;
35126
35389
  }
35127
35390
  const daemonDead = daemonKnownDead(daemonLiveness);
35128
35391
  const reloadAt = readReloadRequestedAt(cfg.ship.stateDir);
35129
35392
  if (reloadAt !== null) {
35130
- process.stdout.write(
35393
+ R.line(
35131
35394
  `reload request: ${reloadRequestText(Math.max(0, Math.round((Date.now() - reloadAt) / 1e3)), daemonLiveness, liveRuns(cfg.ship.stateDir).length)}
35132
35395
  `
35133
35396
  );
@@ -35136,7 +35399,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35136
35399
  if (daemonStartedAt !== null) {
35137
35400
  const changed2 = configChangedAfter(daemonConfigPaths(cfg), daemonStartedAt);
35138
35401
  if (changed2) {
35139
- process.stdout.write(
35402
+ R.line(
35140
35403
  daemonDead ? `daemon config: WARN ${changed2} changed at ${new Date(statSync19(changed2).mtimeMs).toISOString()} \u2014 no daemon is running; the new config applies when it starts
35141
35404
  ` : `daemon config: WARN ${changed2} changed at ${new Date(statSync19(changed2).mtimeMs).toISOString()} but the daemon started at ${new Date(daemonStartedAt).toISOString()} \u2014 run \`crew reload\`
35142
35405
  `
@@ -35148,82 +35411,85 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35148
35411
  const have = sentVersion(cfg.ship);
35149
35412
  const floor = await readCrewFloor(route2, cfg.ship);
35150
35413
  if (have && floor) {
35151
- process.stdout.write(
35414
+ R.line(
35152
35415
  `crew version: ${belowFloor(have, floor) ? "WARN " : ""}${have} (workspace requires ${floor})${belowFloor(have, floor) ? " \u2014 update crew (the Crew app, or `npm install -g @tablation/crew`)" : ""}
35153
35416
  `
35154
35417
  );
35155
35418
  } else if (have) {
35156
- process.stdout.write(`crew version: ${have}${floor === null ? " (workspace sets no minimum)" : ""}
35419
+ R.line(`crew version: ${have}${floor === null ? " (workspace sets no minimum)" : ""}
35157
35420
  `);
35158
35421
  }
35159
35422
  }
35160
35423
  const contractProblems = validateContract(tracker.contract);
35161
- process.stdout.write(
35424
+ R.line(
35162
35425
  contractProblems.length ? `contract: ${contractProblems.length} problem(s)
35163
35426
  ` + contractProblems.map((p) => ` - ${p}
35164
35427
  `).join("") : "contract: consistent\n"
35165
35428
  );
35429
+ R.repoNames = reposOf(route2).map((t) => t.name);
35166
35430
  for (const r of await resolvedRepos(route2)) {
35167
35431
  const { config } = r;
35432
+ R.repo = r.name;
35168
35433
  const worktreePattern = config.worktrees.name ?? (config.provenance["worktrees.prefix"] !== "default" ? `${config.worktrees.prefix}<number>` : `${basename17(r.dir.replace(/[/\\]+$/, ""))}-${effectiveBranchTemplate(config, void 0)}`);
35169
- process.stdout.write(
35434
+ R.line(
35170
35435
  `${`repo ${r.name}:`.padEnd(19)}${r.dir}
35171
35436
  worktrees at ../${worktreePattern} (${config.provenance["worktrees.name"] ?? config.provenance["worktrees.prefix"] ?? "default"}), branch ${config.branch.name}
35172
35437
  requires ${config.platform} \u2014 ${satisfies(host, config.platform) ? "OK" : "MISMATCH"}
35173
35438
  `
35174
35439
  );
35175
35440
  if (config.shadowed.length) {
35176
- process.stdout.write(
35441
+ R.line(
35177
35442
  ` this ship declares ${config.shadowed.join(", ")}, and ${r.name} overrides it \u2014 the repo wins
35178
35443
  `
35179
35444
  );
35180
35445
  }
35181
35446
  for (const p2 of validateEffective(config)) {
35182
- process.stdout.write(` - release readiness: ${p2}
35447
+ R.line(` - release readiness: ${p2}
35183
35448
  `);
35184
35449
  }
35185
- process.stdout.write(` release self-repair: ${selfRepairLine(config.release.isolateFailures?.maxCandidates)}
35450
+ R.line(` release self-repair: ${selfRepairLine(config.release.isolateFailures?.maxCandidates)}
35186
35451
  `);
35187
35452
  const dh = doctorBaseReport(r, config.branch.base, baseHealth);
35188
- process.stdout.write(dh.text);
35453
+ R.line(dh.text);
35189
35454
  if (dh.failed) process.exitCode = 1;
35190
35455
  if (dh.skipRest) continue;
35191
35456
  if (config.release.ship) {
35192
- process.stdout.write(` release.ship ${config.release.ship}${config.release.ship === cfg.ship.name ? " (this ship)" : ""}
35457
+ R.line(` release.ship ${config.release.ship}${config.release.ship === cfg.ship.name ? " (this ship)" : ""}
35193
35458
  `);
35194
35459
  } else {
35195
35460
  const warn = missingReleaserWarning(r.name, config.release, await tracker.shipRows().catch(() => []));
35196
- if (warn) process.stdout.write(` WARNING ${warn}
35461
+ if (warn) R.line(` WARNING ${warn}
35197
35462
  `);
35198
35463
  }
35199
35464
  const scope = releaseLockScope(route2.route, r.name);
35200
35465
  const lock2 = await tracker.lockState(scope).catch(() => void 0);
35201
35466
  if (lock2?.holder && staleOwnLockClaim(lock2.holder, cfg.ship.name)) {
35202
- process.stdout.write(` ${formatStaleOwnLock(scope, lock2.holder)}`);
35467
+ R.line(` ${formatStaleOwnLock(scope, lock2.holder)}`);
35203
35468
  }
35204
35469
  }
35470
+ R.repo = void 0;
35205
35471
  const missingAuthorship = await tracker.missingAuthorshipColumns();
35206
- process.stdout.write(
35472
+ R.line(
35207
35473
  missingAuthorship.length === 0 ? "authorship: filed_by_id, ship_id present\n" : `authorship: missing ${missingAuthorship.join(", ")} \u2014 update the Issues template
35208
35474
  `
35209
35475
  );
35210
35476
  const missingRuntime = await tracker.missingRuntimeColumns();
35211
- process.stdout.write(
35477
+ R.line(
35212
35478
  missingRuntime.length === 0 ? "runtime columns: forge_host, kind, instance_class, relay_url present\n" : `runtime columns: missing ${missingRuntime.join(", ")} \u2014 read as their defaults; update the Issues template
35213
35479
  `
35214
35480
  );
35215
35481
  {
35216
35482
  const have = await tracker.linkColumns();
35217
35483
  const lines2 = linkDoctorLines(have, reposOf(route2).map((t) => ({ name: t.name, host: t.forgeHost })), cfg.ship.forges, cfg.ship.stateDir);
35218
- process.stdout.write(`${lines2.join("\n")}
35484
+ R.line(`${lines2.join("\n")}
35219
35485
  `);
35220
35486
  }
35221
- process.stdout.write(
35487
+ R.line(
35222
35488
  await tracker.hasPublicReplyColumn() ? `public replies: Comments.${tracker.contract.comments.publicReply} present \u2014 public reporters are labelled in the digest
35223
35489
  ` : `public replies: Comments.${tracker.contract.comments.publicReply} absent \u2014 no public intake form, nothing to guard
35224
35490
  `
35225
35491
  );
35226
- process.stdout.write(
35492
+ R.line(
35227
35493
  await tracker.hasCrewAssistedColumn() ? `crew assisted: Issues.${tracker.contract.columns.crewAssisted} present \u2014 Dev/QA runs mark the ticket
35228
35494
  ` : `crew assisted: Issues.${tracker.contract.columns.crewAssisted} absent \u2014 tickets are not marked; update the Issues template to adopt it
35229
35495
  `
@@ -35237,44 +35503,44 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35237
35503
  tablePresent: periscopes.present,
35238
35504
  repos: settled.map((r) => ({ name: r.name, hasPreviewHook: !!r.config.hooks.preview }))
35239
35505
  })) {
35240
- process.stdout.write(`periscopes: ${f.severity.toUpperCase()} ${f.message}
35506
+ R.line(`periscopes: ${f.severity.toUpperCase()} ${f.message}
35241
35507
  `);
35242
35508
  }
35243
35509
  if (!flag("offline")) {
35244
35510
  for (const f of await duplicateLivePeriscopeProblems(route2, cfg.ship)) {
35245
- process.stdout.write(`periscopes: ${f.severity.toUpperCase()} ${f.message}
35511
+ R.line(`periscopes: ${f.severity.toUpperCase()} ${f.message}
35246
35512
  `);
35247
35513
  }
35248
35514
  }
35249
35515
  }
35250
- process.stdout.write(
35516
+ R.line(
35251
35517
  !periscopes.present ? "periscopes: Periscopes table absent \u2014 this workspace cannot host periscopes\n" : periscopes.missing.length === 0 ? `periscopes: Periscopes table present (${periscopes.modelId})
35252
35518
  ` : `periscopes: Periscopes table present (${periscopes.modelId}) but missing ${periscopes.missing.join(", ")} \u2014 update the Issues template
35253
35519
  `
35254
35520
  );
35255
- process.stdout.write(
35521
+ R.line(
35256
35522
  route2.resolved?.releaseSeat ? "release seat: this ship has its own Release Crew row\n" : "release seat: none \u2014 release comments are credited to the dev seat; run `crew connect` once the Crew table has this ship's row\n"
35257
35523
  );
35258
35524
  const keyRole = route2.resolved?.role ?? await fetchKeyRole(route2, cfg.ship.userAgent);
35259
35525
  const roleRoute = route2.resolved && keyRole ? { ...route2, resolved: { ...route2.resolved, role: keyRole } } : route2;
35260
- process.stdout.write(`api key role: ${keyRole ?? "unknown"}
35526
+ R.line(`api key role: ${keyRole ?? "unknown"}
35261
35527
  `);
35262
- for (const m of route2.resolved?.capabilityMisses ?? []) process.stdout.write(`capability: MISSING ${m} (re-run \`crew connect\` once granted)
35528
+ for (const m of route2.resolved?.capabilityMisses ?? []) R.line(`capability: MISSING ${m} (re-run \`crew connect\` once granted)
35263
35529
  `);
35264
35530
  const canMint = await canMintAgentKeys(roleRoute, { userAgent: cfg.ship.userAgent });
35265
- process.stdout.write(`can mint agent keys: ${canMint === void 0 ? "unknown" : canMint ? "yes" : "no"}
35531
+ R.line(`can mint agent keys: ${canMint === void 0 ? "unknown" : canMint ? "yes" : "no"}
35266
35532
  `);
35267
35533
  for (const role of SEAT_KEY_ROLES) {
35268
35534
  if (!route2.resolved?.seats[role]) continue;
35269
35535
  const id = await resolveSeatKey(roleRoute, role);
35270
- process.stdout.write(
35536
+ R.line(
35271
35537
  `seat identity: ${role} writes as ${id.kind === "agent" ? `its own agent (${id.agentId})` : `the ship (${id.reason})`}
35272
35538
  `
35273
35539
  );
35274
35540
  }
35275
35541
  if (route2.resolved?.releaseSeat) {
35276
35542
  const id = await resolveReleaseKey(roleRoute);
35277
- process.stdout.write(
35543
+ R.line(
35278
35544
  `seat identity: release writes as ${id.kind === "agent" ? `its own agent (${id.agentId})` : `the ship (${id.reason})`}
35279
35545
  `
35280
35546
  );
@@ -35282,54 +35548,54 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35282
35548
  if (!flag("offline")) {
35283
35549
  for (const p of await probeSeatReads(roleRoute, { userAgent: cfg.ship.userAgent })) {
35284
35550
  if (p.state === "forbidden") {
35285
- process.stdout.write(`${describeSeatForbidden(p.role, p.tables)}
35551
+ R.line(`${describeSeatForbidden(p.role, p.tables)}
35286
35552
  `);
35287
35553
  process.exitCode = 1;
35288
35554
  } else {
35289
- process.stdout.write(p.state === "ok" ? `${describeSeatTables(p.role, p.tables)}
35555
+ R.line(p.state === "ok" ? `${describeSeatTables(p.role, p.tables)}
35290
35556
  ` : `seat read: ${p.role} could not be checked (${p.detail})
35291
35557
  `);
35292
35558
  }
35293
35559
  }
35294
35560
  for (const w of await probeSeatWrites(roleRoute, { userAgent: cfg.ship.userAgent })) {
35295
35561
  if (w.state === "forbidden") {
35296
- process.stdout.write(`seat write: ERROR ${seatCannotWriteMessage(w.role, w.tables)} (READ only) \u2014 ${SEAT_NO_WRITE_REMEDY}
35562
+ R.line(`seat write: ERROR ${seatCannotWriteMessage(w.role, w.tables)} (READ only) \u2014 ${SEAT_NO_WRITE_REMEDY}
35297
35563
  `);
35298
35564
  process.exitCode = 1;
35299
- } else if (w.state === "ok") process.stdout.write(`seat write: ${w.role}: ok
35565
+ } else if (w.state === "ok") R.line(`seat write: ${w.role}: ok
35300
35566
  `);
35301
35567
  }
35302
35568
  }
35303
35569
  const [ships, crewRows] = await Promise.all([tracker.shipRows(), tracker.crewRows()]);
35304
35570
  if (ships.length === 0) {
35305
- process.stdout.write("ship record: this workspace has no Ships table (fine)\n");
35571
+ R.line("ship record: this workspace has no Ships table (fine)\n");
35306
35572
  } else {
35307
35573
  const matched = matchShipRows(ships, cfg.ship.name, doctorMachineId(cfg.ship.stateDir));
35308
35574
  const mine = matched.rows;
35309
- process.stdout.write(
35575
+ R.line(
35310
35576
  matched.hasColumn ? `ship row: ${mine.length === 1 ? `matched by ${matched.by === "machine_id" ? "machine id" : "name"}` : "not matched"}
35311
35577
  ` : "ship row: matched by name only \u2014 the Ships table has no machine_id column (update the Issues template)\n"
35312
35578
  );
35313
35579
  if (mine.length === 0) {
35314
- process.stdout.write(
35580
+ R.line(
35315
35581
  `ship record: NO row named "${cfg.ship.name}" \u2014 have: ${ships.map((s2) => s2.name).join(", ")}
35316
35582
  `
35317
35583
  );
35318
35584
  } else if (mine.length > 1) {
35319
- process.stdout.write(`ship record: ${mine.length} rows named "${cfg.ship.name}" \u2014 ambiguous
35585
+ R.line(`ship record: ${mine.length} rows named "${cfg.ship.name}" \u2014 ambiguous
35320
35586
  `);
35321
35587
  } else {
35322
35588
  const row = mine[0];
35323
35589
  const seats2 = crewRows.filter((c) => c.ship_id === row.id);
35324
35590
  const declared = row.platform;
35325
- process.stdout.write(
35591
+ R.line(
35326
35592
  `ship record: ${row.name} (${declared ?? "no platform"})${declared && declared !== host ? ` \u2014 MISMATCH, this host is ${host}` : ""}
35327
35593
  crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "none"}
35328
35594
  `
35329
35595
  );
35330
- for (const w of managedRuntimeWarnings(row.kind, cfg.ship)) process.stdout.write(`managed runtime: WARN ${w}
35596
+ for (const w of managedRuntimeWarnings(row.kind, cfg.ship)) R.line(`managed runtime: WARN ${w}
35331
35597
  `);
35332
- for (const w of managedGitIdentityWarnings(row.kind, readGlobalGitIdentity())) process.stdout.write(`managed git: WARN ${w}
35598
+ for (const w of managedGitIdentityWarnings(row.kind, readGlobalGitIdentity())) R.line(`managed git: WARN ${w}
35333
35599
  `);
35334
35600
  }
35335
35601
  }
@@ -35337,20 +35603,20 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35337
35603
  const op = route2.resolved?.operator;
35338
35604
  const row = op ? crewRows.find((c) => c.id === op) : void 0;
35339
35605
  if (!op) {
35340
- process.stdout.write("operator identity: no operator on this route \u2014 run `crew connect`\n");
35606
+ R.line("operator identity: no operator on this route \u2014 run `crew connect`\n");
35341
35607
  } else if (!row) {
35342
- process.stdout.write(`operator identity: ERROR operator ${op} is not a row of the Crew table
35608
+ R.line(`operator identity: ERROR operator ${op} is not a row of the Crew table
35343
35609
  `);
35344
35610
  process.exitCode = 1;
35345
35611
  } else if (!row.user_id) {
35346
- process.stdout.write(
35612
+ R.line(
35347
35613
  `operator identity: ERROR Crew row "${row.name ?? op}" has no user_id \u2014 their UI comments will read "(no identity)"; re-run \`crew connect\` to link it
35348
35614
  `
35349
35615
  );
35350
35616
  process.exitCode = 1;
35351
35617
  } else {
35352
35618
  const resolves = memberByIdentity(buildRoster(configuredMembers(route2), crewRows), row.user_id);
35353
- process.stdout.write(
35619
+ R.line(
35354
35620
  resolves ? `operator identity: comments from ${row.name ?? op} resolve to ${crewLabel(resolves)}
35355
35621
  ` : `operator identity: ERROR user_id ${row.user_id} does not resolve through the roster
35356
35622
  `
@@ -35362,12 +35628,12 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35362
35628
  try {
35363
35629
  const humanHolds = new Set(holdIds(buildRoster(configuredMembers(route2), crewRows)));
35364
35630
  const warnings = holdWarnings(await tracker.openTickets(), ships, tracker.contract, humanHolds);
35365
- process.stdout.write(
35631
+ R.line(
35366
35632
  warnings.length === 0 ? "ship holds: every in-flight ticket is held by a live ship\n" : warnings.map((w) => `ship holds: WARNING ${w}
35367
35633
  `).join("")
35368
35634
  );
35369
35635
  } catch (e) {
35370
- process.stdout.write(`ship holds: could not check \u2014 ${e.message}
35636
+ R.line(`ship holds: could not check \u2014 ${e.message}
35371
35637
  `);
35372
35638
  }
35373
35639
  }
@@ -35381,16 +35647,16 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35381
35647
  const binPath = findOnPath(runBin, schedulerPath);
35382
35648
  if (!binPath) allBinsFound = false;
35383
35649
  const label = tc.name === defaultToolchain ? "agent binary: " : `toolchain ${tc.name}:`.padEnd(18);
35384
- process.stdout.write(
35650
+ R.line(
35385
35651
  `${label} ${runBin} \u2014 ${binPath ? `OK (${binPath})` : "NOT FOUND on the scheduler PATH"}${tc.name === defaultToolchain ? "" : ` [${adapter.displayName}]`}
35386
35652
  `
35387
35653
  );
35388
- for (const limit of adapter.limitations) process.stdout.write(` cannot enforce: ${limit}
35654
+ for (const limit of adapter.limitations) R.line(` cannot enforce: ${limit}
35389
35655
  `);
35390
35656
  if (isOmlxLauncher(tc)) {
35391
35657
  const s = readOmlxSettings();
35392
35658
  if (!s) {
35393
- process.stdout.write(` omlx: ~/.omlx/settings.json not found or has no server.port \u2014 cannot check the server
35659
+ R.line(` omlx: ~/.omlx/settings.json not found or has no server.port \u2014 cannot check the server
35394
35660
  `);
35395
35661
  } else {
35396
35662
  let status2;
@@ -35400,32 +35666,32 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35400
35666
  status2 = void 0;
35401
35667
  }
35402
35668
  const probe = interpretOmlxProbe(status2);
35403
- process.stdout.write(` omlx server: ${s.host}:${s.port} \u2014 ${probe.detail}${probe.up ? "" : " (start oMLX)"}
35669
+ R.line(` omlx server: ${s.host}:${s.port} \u2014 ${probe.detail}${probe.up ? "" : " (start oMLX)"}
35404
35670
  `);
35405
- process.stdout.write(
35671
+ R.line(
35406
35672
  ` omlx model: ${tc.model} \u2014 ${omlxModelPresent(tc.model, s.modelDirs) ? "present" : `NOT FOUND in ${s.modelDirs.join(", ") || "any model dir"}`}
35407
35673
  `
35408
35674
  );
35409
35675
  }
35410
- process.stdout.write(` local model: tool-call reliability and prefill speed vary by model
35676
+ R.line(` local model: tool-call reliability and prefill speed vary by model
35411
35677
  `);
35412
35678
  }
35413
35679
  if (isOriLauncher(tc)) {
35414
- process.stdout.write(` ori: headless auth under the scheduler is unverified \u2014 run \`ori login\` as the scheduler user, then confirm a run records provider openrouter (see docs/toolchains.md)
35680
+ R.line(` ori: headless auth under the scheduler is unverified \u2014 run \`ori login\` as the scheduler user, then confirm a run records provider openrouter (see docs/toolchains.md)
35415
35681
  `);
35416
35682
  }
35417
35683
  }
35418
35684
  for (const [repoName, ov] of Object.entries(route2.repoOverrides)) {
35419
- if (ov.toolchain) process.stdout.write(`repo toolchain: ${repoName} \u2192 ${ov.toolchain} (binary and MCP checked above, as for every ship toolchain)
35685
+ if (ov.toolchain) R.line(`repo toolchain: ${repoName} \u2192 ${ov.toolchain} (binary and MCP checked above, as for every ship toolchain)
35420
35686
  `);
35421
35687
  }
35422
- if (cfg.ship.forges) process.stdout.write(formatPushAuth("credential helper", probeCredentialHelper(crewCommandLine())).replace("push auth credential helper:", "credential helper:".padEnd(19)));
35423
- for (const p of pushAuth) process.stdout.write(formatPushAuth(`${p.repo}`, p.result));
35424
- for (const t of toolRows) process.stdout.write(formatToolCheck(t));
35425
- process.stdout.write(`git: ${gitPath ? `OK (${gitPath})` : "NOT FOUND on the scheduler PATH"}
35688
+ if (cfg.ship.forges) R.line(formatPushAuth("credential helper", probeCredentialHelper(crewCommandLine())).replace("push auth credential helper:", "credential helper:".padEnd(19)));
35689
+ for (const p of pushAuth) R.line(formatPushAuth(`${p.repo}`, p.result), { repo: p.repo });
35690
+ for (const t of toolRows) R.line(formatToolCheck(t));
35691
+ R.line(`git: ${gitPath ? `OK (${gitPath})` : "NOT FOUND on the scheduler PATH"}
35426
35692
  `);
35427
35693
  if (!allBinsFound || !gitPath) {
35428
- process.stdout.write(
35694
+ R.line(
35429
35695
  ` scheduler PATH is ${schedulerPath} \u2014 add the directory holding the missing binary to ship.extraPath in crew.yaml, then re-run \`crew doctor\`.
35430
35696
  `
35431
35697
  );
@@ -35439,7 +35705,7 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35439
35705
  seenMcp.add(id);
35440
35706
  const adapter = adapterFor(tc.harness);
35441
35707
  const m = adapter.inspectMcp({ bin: tc.bin, url: mcpUrl, key: route2.apiKey });
35442
- process.stdout.write(
35708
+ R.line(
35443
35709
  m.state === "registered" ? `mcp: tablation registered (user scope) \u2192 ${m.url}
35444
35710
  ` : m.state === "no-binary" ? `mcp: ${tc.bin} not found \u2014 ${adapter.displayName} was not checked
35445
35711
  ` : m.state === "different" ? `mcp: tablation registered but not for this route \u2014 ${m.detail}
@@ -35451,11 +35717,11 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35451
35717
  for (const h of shipPair(cfg.ship).filter((x) => x !== "claude")) {
35452
35718
  const inst = pairInstallerFor(h);
35453
35719
  const v = inst.verifyPair({ url: mcpUrlFor(route2.baseUrl) });
35454
- process.stdout.write(`pair ${h}:`.padEnd(19) + (v.ok ? ` installed (${v.detail})
35720
+ R.line(`pair ${h}:`.padEnd(19) + (v.ok ? ` installed (${v.detail})
35455
35721
  ` : ` NOT installed \u2014 ${v.detail}; run crew connect
35456
35722
  `));
35457
35723
  const envWarn = inst.envWarning?.({ url: mcpUrlFor(route2.baseUrl) });
35458
- if (envWarn) process.stdout.write(`pair ${h} env:`.padEnd(19) + ` WARN \u2014 ${envWarn}
35724
+ if (envWarn) R.line(`pair ${h} env:`.padEnd(19) + ` WARN \u2014 ${envWarn}
35459
35725
  `);
35460
35726
  }
35461
35727
  const shipVendors = new Set(shipToolchains(cfg.ship).map(toolchainVendor));
@@ -35465,11 +35731,11 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35465
35731
  const persona = await fetchSeatPersona(route2, role, { userAgent: cfg.ship.userAgent });
35466
35732
  if (persona?.vendor && !shipVendors.has(persona.vendor)) {
35467
35733
  flagged++;
35468
- process.stdout.write(`seat vendor: ${role} persona wants "${persona.vendor}" \u2014 no toolchain on this ship serves it (have: ${[...shipVendors].join(", ")}); it will run ${resolveSeat(cfg.ship, route2, role).toolchain.name} with a warning
35734
+ R.line(`seat vendor: ${role} persona wants "${persona.vendor}" \u2014 no toolchain on this ship serves it (have: ${[...shipVendors].join(", ")}); it will run ${resolveSeat(cfg.ship, route2, role).toolchain.name} with a warning
35469
35735
  `);
35470
35736
  }
35471
35737
  }
35472
- if (flagged === 0) process.stdout.write("seat vendor: OK (every persona vendor has a toolchain on this ship)\n");
35738
+ if (flagged === 0) R.line("seat vendor: OK (every persona vendor has a toolchain on this ship)\n");
35473
35739
  }
35474
35740
  for (const c of cfg.routes.filter((r) => r.enabled)) {
35475
35741
  let repos;
@@ -35498,8 +35764,8 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35498
35764
  clearShipAttention(state, key);
35499
35765
  continue;
35500
35766
  }
35501
- process.stdout.write(`hook ${c.route}/${r.name} ${name}: \`${cmd}\` NOT FOUND in the sandbox image
35502
- `);
35767
+ R.line(`hook ${c.route}/${r.name} ${name}: \`${cmd}\` NOT FOUND in the sandbox image
35768
+ `, { repo: r.name });
35503
35769
  await raiseShipAttention({ state, emit, route: c, ship: cfg.ship }, { kind: "hook_missing", key, message: gap.message, since: (/* @__PURE__ */ new Date()).toISOString() });
35504
35770
  continue;
35505
35771
  }
@@ -35507,8 +35773,8 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35507
35773
  clearShipAttention(state, key);
35508
35774
  continue;
35509
35775
  }
35510
- process.stdout.write(`hook ${c.route}/${r.name} ${name}: \`${cmd}\` NOT FOUND on the scheduler PATH
35511
- `);
35776
+ R.line(`hook ${c.route}/${r.name} ${name}: \`${cmd}\` NOT FOUND on the scheduler PATH
35777
+ `, { repo: r.name });
35512
35778
  await raiseShipAttention({ state, emit, route: c, ship: cfg.ship }, {
35513
35779
  kind: "hook_missing",
35514
35780
  key,
@@ -35519,33 +35785,33 @@ crew manifest: ${seats2.length ? seats2.map((c) => c.name).join(", ") : "non
35519
35785
  }
35520
35786
  }
35521
35787
  for (const i of visibleAttention(openShipAttention(state), Boolean(dockerFinding))) {
35522
- process.stdout.write(`attention: ${i.kind} \u2014 ${i.message} (since ${i.since})
35788
+ R.line(`attention: ${i.kind} \u2014 ${i.message} (since ${i.since})
35523
35789
  `);
35524
35790
  }
35525
35791
  if (host === "macos") {
35526
35792
  const foreign = describeForeignLaunchdUnits(CREW_HOME);
35527
35793
  if (foreign.length > 0) {
35528
- process.stdout.write(`foreign launchd units (not this checkout's \u2014 \`crew install\` or \`crew uninstall --all\` clears them):
35529
- ${foreign.join("\n")}
35794
+ R.line(`foreign launchd units: not this checkout's \u2014 \`crew install\` or \`crew uninstall --all\` clears them
35795
+ ${foreign.map((f) => ` ${f.trim()}`).join("\n")}
35530
35796
  `);
35531
35797
  }
35532
35798
  }
35533
35799
  if (cfg.ship.runner === "sandbox") {
35534
35800
  const sb = checkSandboxRunner(cfg.ship.sandbox);
35535
- process.stdout.write(`sandbox runner: ${sb.ok ? `OK (${sb.detail})` : `NOT READY \u2014 ${sb.detail}`}
35801
+ R.line(`sandbox runner: ${sb.ok ? `OK (${sb.detail})` : `NOT READY \u2014 ${sb.detail}`}
35536
35802
  `);
35537
35803
  } else {
35538
- process.stdout.write("sandbox runner: off (ship.runner is host)\n");
35804
+ R.line("sandbox runner: off (ship.runner is host)\n");
35539
35805
  }
35540
35806
  const passengerRoutes = cfg.routes.filter((r) => r.enabled && r.hostPassengers);
35541
35807
  if (passengerRoutes.length === 0) {
35542
- process.stdout.write("host passengers: off (no enabled route sets hostPassengers: true)\n");
35808
+ R.line("host passengers: off (no enabled route sets hostPassengers: true)\n");
35543
35809
  } else {
35544
35810
  const dockerOk = dockerAvailable();
35545
35811
  const dockerPathIssue = dockerPathProblem(cfg.ship);
35546
35812
  const dockerKey = "docker_missing";
35547
35813
  if (dockerPathIssue) {
35548
- process.stdout.write(`docker on scheduler PATH: NOT FOUND \u2014 ${dockerPathIssue}
35814
+ R.line(`docker on scheduler PATH: NOT FOUND \u2014 ${dockerPathIssue}
35549
35815
  `);
35550
35816
  await raiseShipAttention({ state, emit, route: passengerRoutes[0], ship: cfg.ship }, {
35551
35817
  kind: "docker_missing",
@@ -35559,7 +35825,7 @@ ${foreign.join("\n")}
35559
35825
  const keygenOk = sshKeygenAvailable();
35560
35826
  const image = passengerImageRef(cfg);
35561
35827
  const imageOk = dockerOk && imagePresent(image);
35562
- process.stdout.write(
35828
+ R.line(
35563
35829
  `host passengers: ON for ${passengerRoutes.map((r) => r.route).join(", ")}
35564
35830
  docker: ${dockerOk ? "OK" : `NOT AVAILABLE${dockerNote}`}
35565
35831
  ssh-keygen: ${keygenOk ? "OK" : "NOT AVAILABLE"}
@@ -35568,12 +35834,12 @@ ${foreign.join("\n")}
35568
35834
  `
35569
35835
  );
35570
35836
  if (!dockerOk) {
35571
- process.stdout.write(
35837
+ R.line(
35572
35838
  " Docker Desktop (or another Docker daemon) is required for Host Passengers \u2014 install/start it, then re-run `crew doctor`. The toggle stays armed in crew.yaml but nothing will start until Docker answers `docker info`.\n"
35573
35839
  );
35574
35840
  }
35575
35841
  if (!keygenOk) {
35576
- process.stdout.write(
35842
+ R.line(
35577
35843
  " `ssh-keygen` is required to mint this ship's tunnel identity \u2014 install OpenSSH, then re-run `crew connect` to sync a key onto this workspace's Ships row.\n"
35578
35844
  );
35579
35845
  }
@@ -35582,24 +35848,24 @@ ${foreign.join("\n")}
35582
35848
  const ws = r.resolved?.workspaceId;
35583
35849
  const slug2 = ws ? readPersistedTunnel(cfg.ship.stateDir, ws)?.slug : void 0;
35584
35850
  if (!ws) continue;
35585
- process.stdout.write(
35851
+ R.line(
35586
35852
  ` ${r.route} url: ${slug2 ? publicUrlFor(slug2, cfg.ship.relayHost, cfg.ship.relayHttpPort, cfg.ship.relayPublicDomain) : "not minted yet (first tunnel cycle creates it)"}
35587
35853
  `
35588
35854
  );
35589
35855
  const controlUrl = slug2 && readPersistedTunnel(cfg.ship.stateDir, ws)?.controlSocket ? `${relayBaseUrlFor(slug2, cfg.ship.relayHost, cfg.ship.relayHttpPort, cfg.ship.relayPublicDomain)}/control` : void 0;
35590
- process.stdout.write(` ${r.route} control url: ${controlUrl ?? "none (the tunnel carries passengers only)"}
35856
+ R.line(` ${r.route} control url: ${controlUrl ?? "none (the tunnel carries passengers only)"}
35591
35857
  `);
35592
35858
  const api = endpointApiFor([r])(ws);
35593
35859
  if (!api) continue;
35594
35860
  const probe = await probeEndpointAccess(api, ws);
35595
- process.stdout.write(
35861
+ R.line(
35596
35862
  ` ${r.route} mcp endpoints: ` + (probe === "ok" ? "OK (key may register its endpoint)" : probe === "forbidden" ? `403 \u2014 ${REGISTER_MCP_ENDPOINTS_HINT}` : `could not check (${probe.error})`) + "\n"
35597
35863
  );
35598
35864
  }
35599
35865
  }
35600
35866
  for (const r of passengerRoutes) {
35601
35867
  const included = passengerRepoTargets(r);
35602
- process.stdout.write(
35868
+ R.line(
35603
35869
  ` ${r.route}: ${included.length ? included.map((t) => t.name).join(", ") : "(no repos included)"}
35604
35870
  `
35605
35871
  );
@@ -35610,19 +35876,19 @@ ${foreign.join("\n")}
35610
35876
  const stateS = readSandboxState(cfg.ship.stateDir);
35611
35877
  for (const r of declaredS) {
35612
35878
  const st = sandboxImageStatus(stateS, planSandbox(r.name, r.decl, r.warm, r.bridge));
35613
- process.stdout.write(`sandbox image: ${r.name}: ${st.status.toUpperCase()} \u2014 ${st.detail}${st.status === "ok" ? "" : dockerNote}
35879
+ R.line(`sandbox image: ${r.name}: ${st.status.toUpperCase()} \u2014 ${st.detail}${st.status === "ok" ? "" : dockerNote}
35614
35880
  `);
35615
35881
  }
35616
35882
  }
35617
35883
  for (const e of listPeriscopeEndpoints(cfg.ship.stateDir)) {
35618
35884
  const secret = readPeriscopeSecret(cfg.ship.stateDir, e.ticketRecordId) ? "live" : "ended, awaiting removal";
35619
- process.stdout.write(`periscope mcp: ${e.ticket} ${e.route} ${e.url} (${secret}, attached only)
35885
+ R.line(`periscope mcp: ${e.ticket} ${e.route} ${e.url} (${secret}, attached only)
35620
35886
  `);
35621
35887
  }
35622
35888
  if (cfg.ship.relayHost && !flag("offline")) {
35623
35889
  const relayUrl = routeRelayUrl(route2);
35624
35890
  if (!relayUrl) {
35625
- process.stdout.write("relay control: no tunnel URL yet (the first `crew passengers` cycle opens it)\n");
35891
+ R.line("relay control: no tunnel URL yet (the first `crew passengers` cycle opens it)\n");
35626
35892
  } else {
35627
35893
  let key;
35628
35894
  try {
@@ -35631,29 +35897,33 @@ ${foreign.join("\n")}
35631
35897
  key = void 0;
35632
35898
  }
35633
35899
  const relayLine = key ? describeRelayProbe(relayUrl, await probeRelayControl(relayUrl, key, cfg.ship.userAgent)) : "relay control: could not check (no API key for this route)";
35634
- process.stdout.write(`${relayLine}${/FAILED/.test(relayLine) ? dockerNote : ""}
35900
+ R.line(`${relayLine}${/FAILED/.test(relayLine) ? dockerNote : ""}
35635
35901
  `);
35636
35902
  }
35637
35903
  }
35638
35904
  for (const l of doctorSelftestLines(readSelftest(cfg.ship.stateDir), shipToolchains(cfg.ship).map((t) => t.name))) {
35639
- process.stdout.write(`${l}
35905
+ R.line(`${l}
35640
35906
  `);
35641
35907
  }
35642
35908
  for (const t of shipToolchains(cfg.ship).filter((t2) => t2.harness === "claude")) {
35643
35909
  if (t.auth === "workspace") {
35644
35910
  for (const r of cfg.routes.filter((r2) => r2.enabled)) {
35645
35911
  const inference = r.resolved ? { baseUrl: inferenceBaseUrl(r.baseUrl, r.resolved.workspaceId), token: "" } : void 0;
35646
- process.stdout.write(`auth: ${t.name}: ${r.route}: ${describeClaudeAuth({ ...t, inference })}
35912
+ R.line(`auth: ${t.name}: ${r.route}: ${describeClaudeAuth({ ...t, inference })}
35647
35913
  `);
35648
35914
  }
35649
35915
  continue;
35650
35916
  }
35651
- process.stdout.write(`auth: ${t.name}: ${describeClaudeAuth(t)}
35917
+ R.line(`auth: ${t.name}: ${describeClaudeAuth(t)}
35652
35918
  `);
35653
35919
  }
35654
35920
  const interactive = !!(process.stdin.isTTY && process.stdout.isTTY);
35921
+ const counts = R.counts();
35922
+ process.stdout.write(renderDoctor(R, [
35923
+ `ship ${cfg.ship.name} (${host}) \xB7 route ${route2.route} \xB7 crew ${sentVersion(cfg.ship) ?? "unknown version"}${daemonLiveness ? ` \xB7 daemon ${daemonLineText(daemonLiveness)}` : ""}`
35924
+ ], flag("verbose")));
35655
35925
  if (flag("fix") || interactive) {
35656
- await doctorFix({ prompt: !flag("fix") || interactive, host });
35926
+ await doctorFix({ prompt: !flag("fix") || interactive, host, fixFlag: flag("fix"), blockers: counts.blocker, warnings: counts.warning });
35657
35927
  }
35658
35928
  break;
35659
35929
  }