@tablation/crew 0.137.4 → 0.137.5

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 (2) hide show
  1. package/dist/cli.js +361 -172
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -15118,7 +15118,7 @@ function doctorSelftestLines(stored, toolchains) {
15118
15118
  }
15119
15119
 
15120
15120
  // src/cli.ts
15121
- import { resolve as resolve7, dirname as dirname35, join as join57, basename as basename16 } from "path";
15121
+ import { resolve as resolve7, dirname as dirname36, join as join58, basename as basename16 } from "path";
15122
15122
  import { fileURLToPath as fileURLToPath2 } from "url";
15123
15123
  import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
15124
15124
  import { spawnSync as spawnSync13 } from "child_process";
@@ -22906,6 +22906,76 @@ function readDaemonStamp(stateDir) {
22906
22906
  }
22907
22907
  }
22908
22908
 
22909
+ // src/daemon-start-failure.ts
22910
+ import { existsSync as existsSync48, mkdirSync as mkdirSync35, readFileSync as readFileSync45, unlinkSync as unlinkSync4, writeFileSync as writeFileSync36 } from "fs";
22911
+ import { dirname as dirname28, join as join49 } from "path";
22912
+ var DAEMON_START_FAILED_KEY = "daemon_start_failed";
22913
+ var START_FAILURE_BACKOFF_MS = 6e4;
22914
+ var BACKOFF_AFTER_FAILURES = 2;
22915
+ var fileFor3 = (stateDir) => join49(stateDir, ".daemon-start-failure.json");
22916
+ function readStartFailure(stateDir) {
22917
+ try {
22918
+ const parsed = JSON.parse(readFileSync45(fileFor3(stateDir), "utf8"));
22919
+ return typeof parsed.reason === "string" && typeof parsed.count === "number" ? { reason: parsed.reason, count: parsed.count, firstAt: String(parsed.firstAt), lastAt: String(parsed.lastAt) } : null;
22920
+ } catch {
22921
+ return null;
22922
+ }
22923
+ }
22924
+ function noteStartFailure(stateDir, reason, nowMs = Date.now()) {
22925
+ const previous = readStartFailure(stateDir);
22926
+ const nowIso = new Date(nowMs).toISOString();
22927
+ const same = previous?.reason === reason;
22928
+ const record = {
22929
+ reason,
22930
+ count: same ? previous.count + 1 : 1,
22931
+ firstAt: same ? previous.firstAt : nowIso,
22932
+ lastAt: nowIso
22933
+ };
22934
+ mkdirSync35(stateDir, { recursive: true });
22935
+ writeFileSync36(fileFor3(stateDir), JSON.stringify(record));
22936
+ return record;
22937
+ }
22938
+ function startFailureDelayMs(count) {
22939
+ return count >= BACKOFF_AFTER_FAILURES ? START_FAILURE_BACKOFF_MS : 0;
22940
+ }
22941
+ function startFailureItem(record, o = {}) {
22942
+ const parts = [`The daemon cannot start: ${record.reason}`];
22943
+ if (o.fix) parts.push(o.fix);
22944
+ if (o.logPath) parts.push(`Unit log: ${o.logPath}`);
22945
+ parts.push("Resumes automatically once a daemon completes a pass.");
22946
+ return { kind: "daemon_start_failed", key: DAEMON_START_FAILED_KEY, message: parts.join(". ").replace(/\.\./g, "."), since: record.firstAt };
22947
+ }
22948
+ function clearStartFailure(state, stateDir) {
22949
+ if (existsSync48(fileFor3(stateDir))) {
22950
+ try {
22951
+ unlinkSync4(fileFor3(stateDir));
22952
+ } catch {
22953
+ }
22954
+ }
22955
+ clearShipAttention(state, DAEMON_START_FAILED_KEY);
22956
+ }
22957
+ async function reportStartFailure(o) {
22958
+ const record = noteStartFailure(o.stateDir, o.reason, o.nowMs);
22959
+ const item = startFailureItem(record, { fix: o.fix, logPath: o.logPath });
22960
+ if (record.count === 1) o.emit.error(item.message, { step: "poll" });
22961
+ try {
22962
+ await raiseShipAttention({ state: o.state, emit: o.emit, route: o.route, ship: o.ship }, item);
22963
+ } catch {
22964
+ }
22965
+ if (o.publish) {
22966
+ try {
22967
+ await o.publish(item);
22968
+ } catch {
22969
+ }
22970
+ }
22971
+ const delay = startFailureDelayMs(record.count);
22972
+ if (delay > 0) await (o.sleep ?? ((ms3) => new Promise((r) => setTimeout(r, ms3))))(delay);
22973
+ return delay;
22974
+ }
22975
+ function fallbackStateDir(configFile) {
22976
+ return join49(dirname28(configFile), "state");
22977
+ }
22978
+
22909
22979
  // src/projects-cmd.ts
22910
22980
  async function buildProjectsReport(routes, open) {
22911
22981
  return Promise.all(routes.map(async (r) => {
@@ -23017,8 +23087,8 @@ function runForge(a, io) {
23017
23087
 
23018
23088
  // src/release-sandbox.ts
23019
23089
  import { execFile as execFile5 } from "child_process";
23020
- import { mkdirSync as mkdirSync35, writeFileSync as writeFileSync36 } from "fs";
23021
- import { dirname as dirname28 } from "path";
23090
+ import { mkdirSync as mkdirSync36, writeFileSync as writeFileSync37 } from "fs";
23091
+ import { dirname as dirname29 } from "path";
23022
23092
  import { promisify as promisify4 } from "util";
23023
23093
  var execFileP4 = promisify4(execFile5);
23024
23094
  var RELEASE_CLONE_DEPTH = 50;
@@ -23064,8 +23134,8 @@ async function openReleaseSandbox(o) {
23064
23134
  if (!policyFile) {
23065
23135
  generated = generateSandboxPolicy({ mirrorDir: cfg.mirrorDir, workDir: cfg.workDir, ...o.policy });
23066
23136
  policyFile = o.policyFile;
23067
- mkdirSync35(dirname28(policyFile), { recursive: true });
23068
- writeFileSync36(policyFile, generated.yaml, { mode: 384 });
23137
+ mkdirSync36(dirname29(policyFile), { recursive: true });
23138
+ writeFileSync37(policyFile, generated.yaml, { mode: 384 });
23069
23139
  }
23070
23140
  const secrets = { ...process.env };
23071
23141
  const secretKeys = [];
@@ -23231,7 +23301,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
23231
23301
  }
23232
23302
 
23233
23303
  // src/watch.ts
23234
- import { watch as watchFile, existsSync as existsSync48, statSync as statSync14, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
23304
+ import { watch as watchFile, existsSync as existsSync49, statSync as statSync14, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
23235
23305
  var E = "\x1B[";
23236
23306
  var dim = (s) => `${E}2m${s}${E}0m`;
23237
23307
  var bold = (s) => `${E}1m${s}${E}0m`;
@@ -23332,7 +23402,7 @@ function renderHeaders(states, now = Date.now()) {
23332
23402
  return states.map((s) => renderHeader(s, now)).join("");
23333
23403
  }
23334
23404
  function readFrom(file, from) {
23335
- if (!existsSync48(file)) return { events: [], offset: from };
23405
+ if (!existsSync49(file)) return { events: [], offset: from };
23336
23406
  const size = statSync14(file).size;
23337
23407
  if (size < from) return readFrom(file, 0);
23338
23408
  if (size === from) return { events: [], offset: from };
@@ -24103,8 +24173,8 @@ function describeCapability(i) {
24103
24173
  }
24104
24174
 
24105
24175
  // src/agents-sync-run.ts
24106
- import { existsSync as existsSync49, mkdirSync as mkdirSync36, readFileSync as readFileSync45, writeFileSync as writeFileSync37 } from "fs";
24107
- import { dirname as dirname29 } from "path";
24176
+ import { existsSync as existsSync50, mkdirSync as mkdirSync37, readFileSync as readFileSync46, writeFileSync as writeFileSync38 } from "fs";
24177
+ import { dirname as dirname30 } from "path";
24108
24178
  async function runAgentsSync(target, o) {
24109
24179
  const dryRun = o.dryRun ?? false;
24110
24180
  const force = o.force ?? false;
@@ -24139,12 +24209,12 @@ async function runAgentsSync(target, o) {
24139
24209
  for (const w of skillResult?.warnings ?? []) o.warn(`warning: ${w}`);
24140
24210
  if (!dryRun) {
24141
24211
  const resolvedPath = resolvedPathFor(o.stateDir, target.route);
24142
- const raw = existsSync49(resolvedPath) ? JSON.parse(readFileSync45(resolvedPath, "utf8")) : {};
24212
+ const raw = existsSync50(resolvedPath) ? JSON.parse(readFileSync46(resolvedPath, "utf8")) : {};
24143
24213
  raw.agentPersonas = personaResult.agentPersonas;
24144
24214
  if (skillResult) raw.agentSkills = skillResult.agentSkills;
24145
24215
  if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
24146
- mkdirSync36(dirname29(resolvedPath), { recursive: true });
24147
- writeFileSync37(resolvedPath, `${JSON.stringify(raw, null, 2)}
24216
+ mkdirSync37(dirname30(resolvedPath), { recursive: true });
24217
+ writeFileSync38(resolvedPath, `${JSON.stringify(raw, null, 2)}
24148
24218
  `);
24149
24219
  if (target.resolved) {
24150
24220
  target.resolved.agentPersonas = personaResult.agentPersonas;
@@ -24281,7 +24351,7 @@ async function showLogEntry(route2, entryId, opts = {}) {
24281
24351
 
24282
24352
  // src/repos-check.ts
24283
24353
  import { spawnSync as spawnSync12 } from "child_process";
24284
- import { readFileSync as readFileSync46 } from "fs";
24354
+ import { readFileSync as readFileSync47 } from "fs";
24285
24355
  import { basename as basename11 } from "path";
24286
24356
  var POSIX_SHELL = /^(?:ba|z|da|k|a|mk)?sh$|^fish$/;
24287
24357
  function checkHookSyntax(script, shell) {
@@ -24322,7 +24392,7 @@ function checkRepoSpec(dir, opts = {}) {
24322
24392
  }
24323
24393
  let parsed;
24324
24394
  try {
24325
- parsed = parseRepoConfig(readFileSync46(file, "utf8"), file);
24395
+ parsed = parseRepoConfig(readFileSync47(file, "utf8"), file);
24326
24396
  } catch (e) {
24327
24397
  if (!(e instanceof RepoConfigError)) throw e;
24328
24398
  return { ...empty, file, error: e.message, exitCode: 1 };
@@ -24786,7 +24856,7 @@ ${run4.err}` });
24786
24856
  }
24787
24857
 
24788
24858
  // src/sample-ticket.ts
24789
- import { basename as basename12, dirname as dirname30, join as join49 } from "path";
24859
+ import { basename as basename12, dirname as dirname31, join as join50 } from "path";
24790
24860
  var SAMPLE_REPO = "crew-sample";
24791
24861
  var SAMPLE_REMOTE = `local/${SAMPLE_REPO}`;
24792
24862
  var SAMPLE_MARKER = "sample: true";
@@ -24809,8 +24879,8 @@ has something safe to work on: its test and build hooks always pass, it has no
24809
24879
  remote, and \`crew sample-ticket --remove\` deletes it.
24810
24880
  `;
24811
24881
  function sampleDir(existing, reposBase, workspace) {
24812
- if (existing.length > 0) return join49(dirname30(existing[0]), SAMPLE_REPO);
24813
- return join49(reposBase, workspace, SAMPLE_REPO);
24882
+ if (existing.length > 0) return join50(dirname31(existing[0]), SAMPLE_REPO);
24883
+ return join50(reposBase, workspace, SAMPLE_REPO);
24814
24884
  }
24815
24885
  var SAMPLE_TITLE = "Sample: add a documented `greet` function with a test";
24816
24886
  function sampleDescription() {
@@ -24854,8 +24924,8 @@ function planSampleTicket(i) {
24854
24924
  }
24855
24925
 
24856
24926
  // src/worktree-sweep.ts
24857
- import { existsSync as existsSync50, readFileSync as readFileSync47, readdirSync as readdirSync15 } from "fs";
24858
- import { basename as basename13, dirname as dirname31, join as join50, resolve as resolve5 } from "path";
24927
+ import { existsSync as existsSync51, readFileSync as readFileSync48, readdirSync as readdirSync15 } from "fs";
24928
+ import { basename as basename13, dirname as dirname32, join as join51, resolve as resolve5 } from "path";
24859
24929
  function planWorktreeSweep(target, tickets, contract) {
24860
24930
  const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
24861
24931
  const verified = contract.statuses.verified;
@@ -24919,7 +24989,7 @@ function worktreeTicketNumbers(target) {
24919
24989
  return [...nums];
24920
24990
  }
24921
24991
  function siblingWorktreeDirs(target) {
24922
- const parent = dirname31(target.dir.replace(/[/\\]+$/, ""));
24992
+ const parent = dirname32(target.dir.replace(/[/\\]+$/, ""));
24923
24993
  const stem = `${basename13(target.dir.replace(/[/\\]+$/, ""))}-`;
24924
24994
  const registered = new Set(worktrees(target.dir).map((w) => resolve5(w.path)));
24925
24995
  let names;
@@ -24932,7 +25002,7 @@ function siblingWorktreeDirs(target) {
24932
25002
  for (const name of names) {
24933
25003
  if (!name.startsWith(stem)) continue;
24934
25004
  const m = DIR_NUMBER_SUFFIXED.exec(name);
24935
- const path = join50(parent, name);
25005
+ const path = join51(parent, name);
24936
25006
  if (m && !registered.has(resolve5(path))) out.push({ path, number: m[1] });
24937
25007
  }
24938
25008
  return out;
@@ -24967,7 +25037,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
24967
25037
  let removed = 0;
24968
25038
  let keptBranches = 0;
24969
25039
  for (const a of actions) {
24970
- if (!dryRun && base && !a.keepBranch && existsSync50(a.path) && isHandBackMerge(a.path, base)) {
25040
+ if (!dryRun && base && !a.keepBranch && existsSync51(a.path) && isHandBackMerge(a.path, base)) {
24971
25041
  if (gitOk(a.path, ["merge", "--abort"]) !== null) {
24972
25042
  log.emit(
24973
25043
  `abandoned the hand-back merge of ${base} in ${a.path}: ${a.ticket.issue_id} deployed without it`,
@@ -24975,7 +25045,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
24975
25045
  );
24976
25046
  }
24977
25047
  }
24978
- if (!dryRun && existsSync50(a.path)) {
25048
+ if (!dryRun && existsSync51(a.path)) {
24979
25049
  let dirty = false;
24980
25050
  try {
24981
25051
  dirty = status(a.path).length > 0;
@@ -24986,7 +25056,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
24986
25056
  continue;
24987
25057
  }
24988
25058
  }
24989
- if (!dryRun && a.requirePushed && a.branch && existsSync50(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
25059
+ if (!dryRun && a.requirePushed && a.branch && existsSync51(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
24990
25060
  refuse2(a, "unpushed commits", `${a.branch} has commits that are not on ${remote}`);
24991
25061
  continue;
24992
25062
  }
@@ -25035,7 +25105,7 @@ function isHandBackMerge(path, base) {
25035
25105
  if (!msgPath) return false;
25036
25106
  let first;
25037
25107
  try {
25038
- first = readFileSync47(resolve5(path, msgPath), "utf8").split("\n")[0] ?? "";
25108
+ first = readFileSync48(resolve5(path, msgPath), "utf8").split("\n")[0] ?? "";
25039
25109
  } catch {
25040
25110
  return false;
25041
25111
  }
@@ -25140,14 +25210,14 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
25140
25210
  }
25141
25211
 
25142
25212
  // src/stream-sweep.ts
25143
- import { existsSync as existsSync51, readdirSync as readdirSync16, rmSync as rmSync22, statSync as statSync15 } from "fs";
25144
- import { join as join51 } from "path";
25213
+ import { existsSync as existsSync52, readdirSync as readdirSync16, rmSync as rmSync22, statSync as statSync15 } from "fs";
25214
+ import { join as join52 } from "path";
25145
25215
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
25146
25216
  function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
25147
- const dir = join51(stateDir, "streams");
25148
- if (!existsSync51(dir)) return [];
25217
+ const dir = join52(stateDir, "streams");
25218
+ if (!existsSync52(dir)) return [];
25149
25219
  const cutoff = now - retentionDays * DAY_MS2;
25150
- return readdirSync16(dir).map((name) => join51(dir, name)).filter((path) => {
25220
+ return readdirSync16(dir).map((name) => join52(dir, name)).filter((path) => {
25151
25221
  try {
25152
25222
  return statSync15(path).mtimeMs < cutoff;
25153
25223
  } catch {
@@ -25173,9 +25243,9 @@ function applyStreamSweep(paths, dryRun, log) {
25173
25243
  return removed;
25174
25244
  }
25175
25245
  function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
25176
- if (!existsSync51(stateDir)) return [];
25246
+ if (!existsSync52(stateDir)) return [];
25177
25247
  const cutoff = now - retentionDays * DAY_MS2;
25178
- return readdirSync16(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join51(stateDir, name)).filter((path) => {
25248
+ return readdirSync16(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join52(stateDir, name)).filter((path) => {
25179
25249
  try {
25180
25250
  return statSync15(path).mtimeMs < cutoff;
25181
25251
  } catch {
@@ -25185,7 +25255,7 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
25185
25255
  }
25186
25256
 
25187
25257
  // src/cli.ts
25188
- import { realpathSync as realpathSync3, readFileSync as readFileSync50, existsSync as existsSync55, mkdirSync as mkdirSync40, writeFileSync as writeFileSync40, rmSync as rmSync25, unlinkSync as unlinkSync5, copyFileSync as copyFileSync2, renameSync as renameSync7, statSync as statSync17, readdirSync as readdirSync20 } from "fs";
25258
+ import { realpathSync as realpathSync3, readFileSync as readFileSync51, existsSync as existsSync56, mkdirSync as mkdirSync41, writeFileSync as writeFileSync41, rmSync as rmSync25, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync7, statSync as statSync17, readdirSync as readdirSync20 } from "fs";
25189
25259
  import { createInterface } from "readline/promises";
25190
25260
 
25191
25261
  // src/periscope-resume.ts
@@ -25412,8 +25482,8 @@ async function unregisterEndpoint(workspaceId, info, d) {
25412
25482
  import { createServer as createHttpServer } from "http";
25413
25483
  import { spawn as spawn9 } from "child_process";
25414
25484
  import { randomBytes as randomBytes2 } from "crypto";
25415
- import { existsSync as existsSync52, mkdirSync as mkdirSync37, readFileSync as readFileSync48, writeFileSync as writeFileSync38, unlinkSync as unlinkSync4, readdirSync as readdirSync17 } from "fs";
25416
- import { join as join52 } from "path";
25485
+ import { existsSync as existsSync53, mkdirSync as mkdirSync38, readFileSync as readFileSync49, writeFileSync as writeFileSync39, unlinkSync as unlinkSync5, readdirSync as readdirSync17 } from "fs";
25486
+ import { join as join53 } from "path";
25417
25487
 
25418
25488
  // src/secret-compare.ts
25419
25489
  import { timingSafeEqual } from "crypto";
@@ -25506,27 +25576,27 @@ var defaultSpawn2 = (cmd, args, env) => {
25506
25576
  return child;
25507
25577
  };
25508
25578
  function syncDaemonStatePath(stateDir, workspaceId) {
25509
- return join52(stateDir, "passengers", `${workspaceId}-sync.json`);
25579
+ return join53(stateDir, "passengers", `${workspaceId}-sync.json`);
25510
25580
  }
25511
25581
  function readPersistedSyncDaemon(stateDir, workspaceId) {
25512
25582
  const path = syncDaemonStatePath(stateDir, workspaceId);
25513
- if (!existsSync52(path)) return void 0;
25583
+ if (!existsSync53(path)) return void 0;
25514
25584
  try {
25515
- return JSON.parse(readFileSync48(path, "utf8"));
25585
+ return JSON.parse(readFileSync49(path, "utf8"));
25516
25586
  } catch {
25517
25587
  return void 0;
25518
25588
  }
25519
25589
  }
25520
25590
  function writePersistedSyncDaemon(stateDir, state) {
25521
25591
  const path = syncDaemonStatePath(stateDir, state.workspaceId);
25522
- mkdirSync37(join52(stateDir, "passengers"), { recursive: true });
25523
- writeFileSync38(path, `${JSON.stringify(state, null, 2)}
25592
+ mkdirSync38(join53(stateDir, "passengers"), { recursive: true });
25593
+ writeFileSync39(path, `${JSON.stringify(state, null, 2)}
25524
25594
  `);
25525
25595
  }
25526
25596
  function removePersistedSyncDaemon(stateDir, workspaceId) {
25527
25597
  const path = syncDaemonStatePath(stateDir, workspaceId);
25528
25598
  try {
25529
- unlinkSync4(path);
25599
+ unlinkSync5(path);
25530
25600
  } catch {
25531
25601
  }
25532
25602
  }
@@ -25540,8 +25610,8 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
25540
25610
  }
25541
25611
  }
25542
25612
  function readAllPersistedSyncWorkspaceIds(stateDir) {
25543
- const dir = join52(stateDir, "passengers");
25544
- if (!existsSync52(dir)) return [];
25613
+ const dir = join53(stateDir, "passengers");
25614
+ if (!existsSync53(dir)) return [];
25545
25615
  const suffix = "-sync.json";
25546
25616
  return readdirSync17(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
25547
25617
  }
@@ -25599,12 +25669,12 @@ function syncPassengerSyncDaemons(plans, cfg, stateDir, deps = {}) {
25599
25669
 
25600
25670
  // src/periscope-proxy.ts
25601
25671
  import { spawn as spawn10 } from "child_process";
25602
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync38 } from "fs";
25672
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync39 } from "fs";
25603
25673
  import { createServer, request as httpRequest } from "http";
25604
25674
  import { request as httpsRequest } from "https";
25605
25675
  import { connect as netConnect } from "net";
25606
25676
  import { connect as tlsConnect } from "tls";
25607
- import { dirname as dirname32, isAbsolute as isAbsolute4 } from "path";
25677
+ import { dirname as dirname33, isAbsolute as isAbsolute4 } from "path";
25608
25678
  import { brotliDecompressSync, gunzipSync, inflateSync } from "zlib";
25609
25679
 
25610
25680
  // src/periscope-inspector.ts
@@ -25718,7 +25788,7 @@ function parsePointedBody(raw) {
25718
25788
  return entry;
25719
25789
  }
25720
25790
  function appendPointed(file, entry, now = /* @__PURE__ */ new Date()) {
25721
- mkdirSync38(dirname32(file), { recursive: true });
25791
+ mkdirSync39(dirname33(file), { recursive: true });
25722
25792
  appendFileSync3(file, `${JSON.stringify({ ...entry, at: now.toISOString() })}
25723
25793
  `);
25724
25794
  }
@@ -26007,7 +26077,7 @@ async function startWorktreeIntel(d) {
26007
26077
  }
26008
26078
 
26009
26079
  // src/contract-refusal.ts
26010
- import { join as join53 } from "path";
26080
+ import { join as join54 } from "path";
26011
26081
  function contractFixers(dir, baseRef, tickets, locate) {
26012
26082
  const out = [];
26013
26083
  for (const t of tickets) {
@@ -26019,7 +26089,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
26019
26089
  const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
26020
26090
  if (text2 === null) continue;
26021
26091
  try {
26022
- parseRepoConfig(text2, join53(dir, file));
26092
+ parseRepoConfig(text2, join54(dir, file));
26023
26093
  } catch (e) {
26024
26094
  if (e instanceof RepoConfigError) continue;
26025
26095
  throw e;
@@ -26034,7 +26104,7 @@ import { createHash as createHash11 } from "crypto";
26034
26104
  import {
26035
26105
  chmodSync as chmodSync4,
26036
26106
  closeSync as closeSync6,
26037
- existsSync as existsSync53,
26107
+ existsSync as existsSync54,
26038
26108
  fstatSync,
26039
26109
  openSync as openSync6,
26040
26110
  readSync as readSync3,
@@ -26045,7 +26115,7 @@ import {
26045
26115
  } from "fs";
26046
26116
  import { createConnection } from "net";
26047
26117
  import { createServer as createServer2 } from "http";
26048
- import { basename as basename14, dirname as dirname33, join as join54 } from "path";
26118
+ import { basename as basename14, dirname as dirname34, join as join55 } from "path";
26049
26119
  import { execFile as execFile6, spawn as spawn12 } from "child_process";
26050
26120
 
26051
26121
  // src/periscope-control.ts
@@ -26282,7 +26352,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
26282
26352
  // src/control-api.ts
26283
26353
  var PAUSABLE = ["dev", "design", "qa"];
26284
26354
  var CONTROL_SOCKET_NAME = "control.sock";
26285
- var controlSocketFor = (stateDir) => join54(stateDir, CONTROL_SOCKET_NAME);
26355
+ var controlSocketFor = (stateDir) => join55(stateDir, CONTROL_SOCKET_NAME);
26286
26356
  var MAX_SOCKET_PATH = 100;
26287
26357
  var MAX_TAIL_BYTES = 1024 * 1024;
26288
26358
  var MAX_WAIT_SECONDS = 30;
@@ -26369,7 +26439,7 @@ function candidates(live, rotated) {
26369
26439
  const out = [live];
26370
26440
  if (!rotated) return out;
26371
26441
  try {
26372
- for (const n of readdirSync18(dirname33(live))) if (ROTATED_EVENTS_RE.test(n)) out.push(join54(dirname33(live), n));
26442
+ for (const n of readdirSync18(dirname34(live))) if (ROTATED_EVENTS_RE.test(n)) out.push(join55(dirname34(live), n));
26373
26443
  } catch {
26374
26444
  }
26375
26445
  return out;
@@ -26413,7 +26483,7 @@ function lastLines2(path, n) {
26413
26483
  }
26414
26484
  function readTail(live, opts) {
26415
26485
  const max = opts.maxBytes ?? MAX_TAIL_BYTES;
26416
- if (!existsSync53(live)) {
26486
+ if (!existsSync54(live)) {
26417
26487
  return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
26418
26488
  }
26419
26489
  const cur = opts.after ? decodeCursor(opts.after) : null;
@@ -26529,7 +26599,7 @@ async function tailReply(path, q2, rotated, abort) {
26529
26599
  const deadline = Date.now() + Math.min(wait, MAX_WAIT_SECONDS) * 1e3;
26530
26600
  let r = readTail(path, { after, tail: tail3, rotated });
26531
26601
  while (after && !r.lines.length && !r.reset && Date.now() < deadline && !abort.aborted) {
26532
- await waitForChange(dirname33(path), deadline - Date.now(), abort);
26602
+ await waitForChange(dirname34(path), deadline - Date.now(), abort);
26533
26603
  r = readTail(path, { after: r.cursor, rotated });
26534
26604
  }
26535
26605
  return reply2(200, r);
@@ -26569,8 +26639,8 @@ async function route(deps, method, url, req, abort) {
26569
26639
  if (p.startsWith("/streams/") && get2) {
26570
26640
  const run4 = decodeURIComponent(p.slice("/streams/".length));
26571
26641
  if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
26572
- const file = join54(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
26573
- if (!existsSync53(file)) return err2(404, "no such run");
26642
+ const file = join55(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
26643
+ if (!existsSync54(file)) return err2(404, "no such run");
26574
26644
  return tailReply(file, url.searchParams, false, abort);
26575
26645
  }
26576
26646
  if ((p === "/pause" || p === "/resume") && post3) {
@@ -26615,7 +26685,7 @@ function send(res, r) {
26615
26685
  res.end(body);
26616
26686
  }
26617
26687
  async function socketIsStale(path) {
26618
- if (!existsSync53(path)) return false;
26688
+ if (!existsSync54(path)) return false;
26619
26689
  return new Promise((resolve8) => {
26620
26690
  const c = createConnection(path);
26621
26691
  c.once("connect", () => {
@@ -26634,7 +26704,7 @@ async function startControlServer(deps) {
26634
26704
  return null;
26635
26705
  }
26636
26706
  if (await socketIsStale(path)) rmSync23(path, { force: true });
26637
- else if (existsSync53(path)) {
26707
+ else if (existsSync54(path)) {
26638
26708
  log(`control API not started: ${path} is in use by another process`);
26639
26709
  return null;
26640
26710
  }
@@ -26720,31 +26790,31 @@ function crewJson(args, timeoutMs = 6e4) {
26720
26790
 
26721
26791
  // src/periscope-mcp.ts
26722
26792
  import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
26723
- import { basename as basename15, dirname as dirname34, isAbsolute as isAbsolute5, join as join56, relative as relative2, resolve as resolve6, sep } from "path";
26793
+ import { basename as basename15, dirname as dirname35, isAbsolute as isAbsolute5, join as join57, relative as relative2, resolve as resolve6, sep } from "path";
26724
26794
  import { z } from "zod";
26725
26795
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
26726
26796
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
26727
26797
 
26728
26798
  // src/periscope-endpoints.ts
26729
26799
  import { randomBytes as randomBytes3 } from "crypto";
26730
- import { chmodSync as chmodSync5, existsSync as existsSync54, mkdirSync as mkdirSync39, readdirSync as readdirSync19, readFileSync as readFileSync49, rmSync as rmSync24, writeFileSync as writeFileSync39 } from "fs";
26731
- import { join as join55 } from "path";
26732
- var secretDir = (stateDir) => join55(stateDir, "periscope-mcp");
26733
- var secretFile = (stateDir, id) => join55(secretDir(stateDir), `${id}.json`);
26734
- var endpointDir = (stateDir) => join55(stateDir, "periscope-endpoints");
26735
- var endpointFile = (stateDir, id) => join55(endpointDir(stateDir), `${id}.json`);
26800
+ import { chmodSync as chmodSync5, existsSync as existsSync55, mkdirSync as mkdirSync40, readdirSync as readdirSync19, readFileSync as readFileSync50, rmSync as rmSync24, writeFileSync as writeFileSync40 } from "fs";
26801
+ import { join as join56 } from "path";
26802
+ var secretDir = (stateDir) => join56(stateDir, "periscope-mcp");
26803
+ var secretFile = (stateDir, id) => join56(secretDir(stateDir), `${id}.json`);
26804
+ var endpointDir = (stateDir) => join56(stateDir, "periscope-endpoints");
26805
+ var endpointFile = (stateDir, id) => join56(endpointDir(stateDir), `${id}.json`);
26736
26806
  function mintPeriscopeSecret(stateDir, ticketRecordId) {
26737
- mkdirSync39(secretDir(stateDir), { recursive: true, mode: 448 });
26807
+ mkdirSync40(secretDir(stateDir), { recursive: true, mode: 448 });
26738
26808
  const secret = randomBytes3(32).toString("base64url");
26739
26809
  const file = secretFile(stateDir, ticketRecordId);
26740
- writeFileSync39(file, `${JSON.stringify({ secret })}
26810
+ writeFileSync40(file, `${JSON.stringify({ secret })}
26741
26811
  `, { mode: 384 });
26742
26812
  chmodSync5(file, 384);
26743
26813
  return secret;
26744
26814
  }
26745
26815
  function readPeriscopeSecret(stateDir, ticketRecordId) {
26746
26816
  try {
26747
- const v = JSON.parse(readFileSync49(secretFile(stateDir, ticketRecordId), "utf8"));
26817
+ const v = JSON.parse(readFileSync50(secretFile(stateDir, ticketRecordId), "utf8"));
26748
26818
  return typeof v.secret === "string" && v.secret ? v.secret : void 0;
26749
26819
  } catch {
26750
26820
  return void 0;
@@ -26755,14 +26825,14 @@ function removePeriscopeSecret(stateDir, ticketRecordId) {
26755
26825
  }
26756
26826
  function readPeriscopeEndpoint(stateDir, ticketRecordId) {
26757
26827
  try {
26758
- return JSON.parse(readFileSync49(endpointFile(stateDir, ticketRecordId), "utf8"));
26828
+ return JSON.parse(readFileSync50(endpointFile(stateDir, ticketRecordId), "utf8"));
26759
26829
  } catch {
26760
26830
  return void 0;
26761
26831
  }
26762
26832
  }
26763
26833
  function writePeriscopeEndpoint(stateDir, rec) {
26764
- mkdirSync39(endpointDir(stateDir), { recursive: true });
26765
- writeFileSync39(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
26834
+ mkdirSync40(endpointDir(stateDir), { recursive: true });
26835
+ writeFileSync40(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
26766
26836
  `);
26767
26837
  }
26768
26838
  function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
@@ -26770,7 +26840,7 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
26770
26840
  }
26771
26841
  function listPeriscopeEndpoints(stateDir) {
26772
26842
  const dir = endpointDir(stateDir);
26773
- if (!existsSync54(dir)) return [];
26843
+ if (!existsSync55(dir)) return [];
26774
26844
  const out = [];
26775
26845
  for (const name of readdirSync19(dir)) {
26776
26846
  if (!name.endsWith(".json")) continue;
@@ -26858,10 +26928,10 @@ async function realAncestor(p) {
26858
26928
  }
26859
26929
  if (isLink) {
26860
26930
  if (++hops > 40) throw new PathRefusal(`too many symbolic links resolving ${p}`);
26861
- cur = resolve6(dirname34(cur), await readlink(cur));
26931
+ cur = resolve6(dirname35(cur), await readlink(cur));
26862
26932
  continue;
26863
26933
  }
26864
- const parent = dirname34(cur);
26934
+ const parent = dirname35(cur);
26865
26935
  if (parent === cur) throw new PathRefusal(`cannot resolve ${p}`);
26866
26936
  tail3.push(basename15(cur));
26867
26937
  cur = parent;
@@ -26873,13 +26943,13 @@ async function resolveInWorktree(root, requested) {
26873
26943
  let abs;
26874
26944
  if (isAbsolute5(requested)) {
26875
26945
  abs = resolve6(requested);
26876
- if (isInside(root, abs)) abs = join56(realRoot, relative2(root, abs));
26946
+ if (isInside(root, abs)) abs = join57(realRoot, relative2(root, abs));
26877
26947
  } else {
26878
26948
  abs = resolve6(realRoot, requested);
26879
26949
  }
26880
26950
  if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
26881
26951
  const { real, rest } = await realAncestor(abs);
26882
- const final = rest ? join56(real, rest) : real;
26952
+ const final = rest ? join57(real, rest) : real;
26883
26953
  if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
26884
26954
  if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
26885
26955
  return final;
@@ -26947,7 +27017,7 @@ function createPeriscopeMcpServer(d, sc) {
26947
27017
  const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
26948
27018
  const lines2 = await Promise.all(entries.map(async (e) => {
26949
27019
  if (e.isDirectory()) return `[DIR] ${e.name}`;
26950
- const size = (await lstat(join56(abs, e.name))).size;
27020
+ const size = (await lstat(join57(abs, e.name))).size;
26951
27021
  return `[FILE] ${e.name} (${size} bytes)`;
26952
27022
  }));
26953
27023
  return text(lines2.join("\n") || "(empty)");
@@ -26972,7 +27042,7 @@ function createPeriscopeMcpServer(d, sc) {
26972
27042
  if (Buffer.byteLength(content) > MAX_WRITE_BYTES) return text(`content exceeds ${MAX_WRITE_BYTES} bytes`, true);
26973
27043
  const abs = await inTree(path);
26974
27044
  if (abs === await realpath(root)) return text("path must name a file", true);
26975
- await mkdir(dirname34(abs), { recursive: true });
27045
+ await mkdir(dirname35(abs), { recursive: true });
26976
27046
  await inTree(path);
26977
27047
  await writeFile(abs, content);
26978
27048
  return text(`Wrote ${Buffer.byteLength(content)} bytes to ${await rel(abs)}`);
@@ -27012,8 +27082,8 @@ function createPeriscopeMcpServer(d, sc) {
27012
27082
  inputSchema: { path: z.string() },
27013
27083
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
27014
27084
  }, async ({ path }) => {
27015
- const parent = await inTree(dirname34(path) === "" ? "." : dirname34(path));
27016
- const abs = join56(parent, basename15(path));
27085
+ const parent = await inTree(dirname35(path) === "" ? "." : dirname35(path));
27086
+ const abs = join57(parent, basename15(path));
27017
27087
  if (basename15(path) === ".git" || abs === parent) return text("path must name a file", true);
27018
27088
  const st = await lstat(abs).catch(() => void 0);
27019
27089
  if (!st) return text(`${path} does not exist`, true);
@@ -27134,7 +27204,7 @@ function findPeriscope(sidecars, segment) {
27134
27204
  }
27135
27205
 
27136
27206
  // src/cli.ts
27137
- var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname35(process.execPath) : resolve7(dirname35(fileURLToPath2(import.meta.url)), "..");
27207
+ var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname36(process.execPath) : resolve7(dirname36(fileURLToPath2(import.meta.url)), "..");
27138
27208
  var RELEASE_LOCK_TTL_MS = 20 * 60 * 1e3;
27139
27209
  var CYCLE_SECONDS2 = 120;
27140
27210
  var STALE_CYCLES = 3;
@@ -27504,7 +27574,7 @@ if (command === "provision") {
27504
27574
  process.exit(outcome.code);
27505
27575
  }
27506
27576
  if (command === "pool-member") {
27507
- const pool = poolConfigFrom(argv, process.env, () => readFileSync50(0, "utf8"));
27577
+ const pool = poolConfigFrom(argv, process.env, () => readFileSync51(0, "utf8"));
27508
27578
  if (typeof pool === "string") {
27509
27579
  process.stderr.write(`crew pool-member: ${pool}
27510
27580
  `);
@@ -27742,6 +27812,34 @@ if (command === "passenger-sync-daemon") {
27742
27812
  };
27743
27813
  };
27744
27814
  requireArmed2 = requireArmed, parseTicketNumber2 = parseTicketNumber, routeRelayUrl2 = routeRelayUrl, previewRelayFor2 = previewRelayFor, passengerApiKeys2 = passengerApiKeys, endpointApiFor2 = endpointApiFor, periscopeEndpointDeps2 = periscopeEndpointDeps, periscopeMcpDeps2 = periscopeMcpDeps, endpointReconcileDeps2 = endpointReconcileDeps, releaseRefused2 = releaseRefused, doctorMachineId2 = doctorMachineId, baseHealth2 = baseHealth, sandboxCacheRepos2 = sandboxCacheRepos, buildSandboxCachePass2 = buildSandboxCachePass, sandboxTickDeps2 = sandboxTickDeps;
27815
+ async function failDaemonStart(o) {
27816
+ const failEmit = new Emitter({
27817
+ route: "",
27818
+ eventFile: eventFileFor(o.stateDir),
27819
+ logFile: o.logFile,
27820
+ console: () => {
27821
+ }
27822
+ });
27823
+ const failState = new State(o.stateDir);
27824
+ const ship = o.ship;
27825
+ await reportStartFailure({
27826
+ state: failState,
27827
+ stateDir: o.stateDir,
27828
+ emit: failEmit,
27829
+ reason: o.reason,
27830
+ fix: o.fix,
27831
+ logPath: o.logFile ? schedulerLogFor(o.logFile, "run") : void 0,
27832
+ publish: ship ? async () => {
27833
+ await Promise.all((o.routes ?? []).filter((r) => r.enabled).map(async (r) => {
27834
+ try {
27835
+ await new Tracker(r, ship).publishShipAttention(ship.name);
27836
+ } catch {
27837
+ }
27838
+ }));
27839
+ } : void 0
27840
+ });
27841
+ process.exit(o.code);
27842
+ }
27745
27843
  let cfg;
27746
27844
  let firstRun;
27747
27845
  let firstRunFromFlags = false;
@@ -27797,7 +27895,7 @@ if (command === "passenger-sync-daemon") {
27797
27895
  } else {
27798
27896
  const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
27799
27897
  const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
27800
- if (configless && !existsSync55(findConfigFile(CREW_HOME))) {
27898
+ if (configless && !existsSync56(findConfigFile(CREW_HOME))) {
27801
27899
  cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
27802
27900
  } else {
27803
27901
  cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
@@ -27807,12 +27905,20 @@ if (command === "passenger-sync-daemon") {
27807
27905
  if (e instanceof ConfigError) {
27808
27906
  process.stderr.write(`crew: ${e.message}
27809
27907
  `);
27908
+ if (command === "daemon" && !["start", "stop", "status", "restart"].includes(positional[1] ?? "")) {
27909
+ await failDaemonStart({
27910
+ stateDir: fallbackStateDir(findConfigFile(CREW_HOME)),
27911
+ reason: e.message,
27912
+ fix: "Fix crew.yaml (`crew doctor` names what is wrong)",
27913
+ code: 2
27914
+ });
27915
+ }
27810
27916
  process.exit(2);
27811
27917
  }
27812
27918
  throw e;
27813
27919
  }
27814
27920
  if (command === "credential") {
27815
- const r = runCredential(positional[1], readFileSync50(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
27921
+ const r = runCredential(positional[1], readFileSync51(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
27816
27922
  process.stdout.write(r.out);
27817
27923
  process.stderr.write(r.err);
27818
27924
  process.exit(r.code);
@@ -27824,9 +27930,9 @@ if (command === "passenger-sync-daemon") {
27824
27930
  forges: cfg.ship.forges,
27825
27931
  stateDir: cfg.ship.stateDir,
27826
27932
  configFile: cfg.configFile,
27827
- readFile: (p) => readFileSync50(p, "utf8"),
27828
- writeFile: (p, t) => writeFileSync40(p, t),
27829
- stdin: () => readFileSync50(0, "utf8"),
27933
+ readFile: (p) => readFileSync51(p, "utf8"),
27934
+ writeFile: (p, t) => writeFileSync41(p, t),
27935
+ stdin: () => readFileSync51(0, "utf8"),
27830
27936
  env: process.env
27831
27937
  }
27832
27938
  );
@@ -27854,6 +27960,17 @@ if (command === "passenger-sync-daemon") {
27854
27960
  if (e instanceof ConfigError) {
27855
27961
  process.stderr.write(`crew: ${e.message}
27856
27962
  `);
27963
+ if (command === "daemon" && !DAEMON_SUBCOMMANDS.has(positional[1] ?? "")) {
27964
+ await failDaemonStart({
27965
+ stateDir: cfg.ship.stateDir,
27966
+ reason: e.message,
27967
+ fix: "Name a route in the unit (`crew install`) or correct crew.yaml",
27968
+ code: 2,
27969
+ routes: cfg.routes,
27970
+ ship: cfg.ship,
27971
+ logFile: cfg.ship.logFile
27972
+ });
27973
+ }
27857
27974
  process.exit(2);
27858
27975
  }
27859
27976
  throw e;
@@ -28149,8 +28266,8 @@ if (command === "passenger-sync-daemon") {
28149
28266
  }
28150
28267
  if (host === "linux" && hasSystemd) {
28151
28268
  const label = labelFor(CREW_HOME, "run");
28152
- const staleTimer = join57(homedir11(), ".config", "systemd", "user", `${label}.timer`);
28153
- if (existsSync55(staleTimer)) {
28269
+ const staleTimer = join58(homedir11(), ".config", "systemd", "user", `${label}.timer`);
28270
+ if (existsSync56(staleTimer)) {
28154
28271
  process.stdout.write(
28155
28272
  `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
28156
28273
  `
@@ -28158,7 +28275,7 @@ if (command === "passenger-sync-daemon") {
28158
28275
  if (!dryRun) {
28159
28276
  spawnSync13("systemctl", ["--user", "disable", "--now", `${label}.timer`], { cwd: CREW_HOME, env: withUserBusEnv() });
28160
28277
  try {
28161
- unlinkSync5(staleTimer);
28278
+ unlinkSync6(staleTimer);
28162
28279
  } catch {
28163
28280
  }
28164
28281
  }
@@ -28179,7 +28296,7 @@ if (command === "passenger-sync-daemon") {
28179
28296
  const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
28180
28297
  for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
28181
28298
  for (const r of doctorRepos) {
28182
- if (!existsSync55(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
28299
+ if (!existsSync56(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
28183
28300
  if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
28184
28301
  readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
28185
28302
  }
@@ -28206,7 +28323,7 @@ if (command === "passenger-sync-daemon") {
28206
28323
  }
28207
28324
  async function doctorFix(o) {
28208
28325
  const routes = await Promise.all(routesInScope(cfg.routes, named).map((c) => gatherHealth({ route: c.route, enabled: c.enabled, hasRepos: reposOf(c).length > 0 }, () => routeProblems(c))));
28209
- const unitExists = (p) => existsSync55(p);
28326
+ const unitExists = (p) => existsSync56(p);
28210
28327
  const crontab = o.host === "linux" ? spawnSync13("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
28211
28328
  const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
28212
28329
  const plan = planFix({ routes, schedulerAbsent, host: o.host });
@@ -28223,7 +28340,7 @@ if (command === "passenger-sync-daemon") {
28223
28340
  for (const a of plan.actions) {
28224
28341
  if (a.kind === "enable") {
28225
28342
  if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
28226
- writeFileSync40(cfg.configFile, planEnable(readFileSync50(cfg.configFile, "utf8"), a.route));
28343
+ writeFileSync41(cfg.configFile, planEnable(readFileSync51(cfg.configFile, "utf8"), a.route));
28227
28344
  enabledSound.add(a.route);
28228
28345
  changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
28229
28346
  } else {
@@ -28452,7 +28569,7 @@ ${changed2.map((c) => ` - ${c}
28452
28569
  harnessBin: "claude",
28453
28570
  ...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
28454
28571
  },
28455
- policyFile: join57(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
28572
+ policyFile: join58(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
28456
28573
  repo: mirror,
28457
28574
  origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
28458
28575
  base: effective.branch.base,
@@ -29540,11 +29657,20 @@ ${cu.tail.trimEnd()}
29540
29657
  const daemonRoutes = fleetWide ? cfg.routes.filter((r) => r.enabled) : [route2];
29541
29658
  if (!daemonRoutes.length) {
29542
29659
  emit.error("no enabled routes \u2014 nothing for the daemon to serve");
29543
- process.exit(1);
29660
+ await failDaemonStart({
29661
+ stateDir: cfg.ship.stateDir,
29662
+ reason: "no enabled routes \u2014 nothing for the daemon to serve",
29663
+ fix: "Set `enabled: true` on a route in crew.yaml, or run `crew connect`",
29664
+ code: 1,
29665
+ routes: cfg.routes,
29666
+ ship: cfg.ship,
29667
+ logFile: cfg.ship.logFile
29668
+ });
29544
29669
  }
29545
29670
  const primary = daemonRoutes[0];
29546
29671
  const sandboxCachePasses = /* @__PURE__ */ new Map();
29547
29672
  const servable = [];
29673
+ const unservable = [];
29548
29674
  for (const r of daemonRoutes) {
29549
29675
  const pass = cfg.ship.runner === "sandbox" ? buildSandboxCachePass(r, cfg.ship, state, emit.forRoute(r.route)) : void 0;
29550
29676
  if (pass) sandboxCachePasses.set(r.route, pass);
@@ -29557,10 +29683,49 @@ ${cu.tail.trimEnd()}
29557
29683
  }
29558
29684
  }
29559
29685
  if (await anyRepoServable(r, true)) servable.push(r);
29560
- else emit.forRoute(r.route).error(`refusing route ${r.route} \u2014 this ship is ${cfg.ship.platform}, but ${await explainUnservable(r)}`);
29686
+ else {
29687
+ const why = await explainUnservable(r);
29688
+ unservable.push(`route ${r.route}: this ship is ${cfg.ship.platform}, but ${why}`);
29689
+ emit.forRoute(r.route).error(`refusing route ${r.route} \u2014 this ship is ${cfg.ship.platform}, but ${why}`);
29690
+ }
29691
+ }
29692
+ if (!servable.length) {
29693
+ await failDaemonStart({
29694
+ stateDir: cfg.ship.stateDir,
29695
+ reason: `no route can be served on this machine (${unservable.join("; ")})`,
29696
+ fix: "Run `crew doctor` to see what each route needs",
29697
+ code: 1,
29698
+ routes: daemonRoutes,
29699
+ ship: cfg.ship,
29700
+ logFile: cfg.ship.logFile
29701
+ });
29702
+ }
29703
+ const unready = [];
29704
+ const ready = servable.filter((r) => {
29705
+ if (!r.resolved) {
29706
+ unready.push(`route ${r.route} has no resolved ids`);
29707
+ return false;
29708
+ }
29709
+ try {
29710
+ resolveApiKey(r);
29711
+ } catch (e) {
29712
+ unready.push(`route ${r.route}: ${e instanceof Error ? e.message : String(e)}`);
29713
+ return false;
29714
+ }
29715
+ return true;
29716
+ });
29717
+ if (!ready.length) {
29718
+ await failDaemonStart({
29719
+ stateDir: cfg.ship.stateDir,
29720
+ reason: `no route can run a pass (${unready.join("; ")})`,
29721
+ fix: "Run `crew connect` for a route without ids, or restore its API key file or `apiKeyVar`",
29722
+ code: 1,
29723
+ routes: daemonRoutes,
29724
+ ship: cfg.ship,
29725
+ logFile: cfg.ship.logFile
29726
+ });
29561
29727
  }
29562
- if (!servable.length) process.exit(1);
29563
- const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join57(CREW_HOME, "src"), join57(CREW_HOME, "dist"), join57(CREW_HOME, "bin")];
29728
+ const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join58(CREW_HOME, "src"), join58(CREW_HOME, "dist"), join58(CREW_HOME, "bin")];
29564
29729
  const configPaths = daemonConfigPaths(cfg);
29565
29730
  watchPaths.push(...configPaths);
29566
29731
  noteDaemonStarted(cfg.ship.stateDir);
@@ -29684,6 +29849,7 @@ ${cu.tail.trimEnd()}
29684
29849
  ),
29685
29850
  checkStale: makeStaleChecker(watchPaths, { reloadSentinel: reloadSentinelFor(cfg.ship.stateDir) }),
29686
29851
  onPass: (result) => {
29852
+ clearStartFailure(state, cfg.ship.stateDir);
29687
29853
  if (!sandboxBuilding && !diskFullStop(state)) {
29688
29854
  sandboxBuilding = true;
29689
29855
  void sandboxReposOf(cfg.routes.filter((r) => r.enabled)).then(withShipSandbox).then((repos) => repos.length ? sandboxBuildTick(repos, sandboxTickDeps(emit, primary)) : null).catch((err3) => emit.warn(`sandbox image build tick failed: ${err3 instanceof Error ? err3.message : String(err3)}`)).finally(() => {
@@ -29877,10 +30043,10 @@ ${cu.tail.trimEnd()}
29877
30043
  `);
29878
30044
  if (!dryRun) {
29879
30045
  const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
29880
- const raw = existsSync55(resolvedPath) ? JSON.parse(readFileSync50(resolvedPath, "utf8")) : {};
30046
+ const raw = existsSync56(resolvedPath) ? JSON.parse(readFileSync51(resolvedPath, "utf8")) : {};
29881
30047
  raw.agentSkills = result.agentSkills;
29882
- mkdirSync40(dirOf2(resolvedPath), { recursive: true });
29883
- writeFileSync40(resolvedPath, `${JSON.stringify(raw, null, 2)}
30048
+ mkdirSync41(dirOf2(resolvedPath), { recursive: true });
30049
+ writeFileSync41(resolvedPath, `${JSON.stringify(raw, null, 2)}
29884
30050
  `);
29885
30051
  }
29886
30052
  if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
@@ -29903,7 +30069,7 @@ ${cu.tail.trimEnd()}
29903
30069
  throw e;
29904
30070
  }
29905
30071
  const oldName = cfg.ship.name;
29906
- writeFileSync40(cfg.configFile, setShipNameInYaml(readFileSync50(cfg.configFile, "utf8"), newName));
30072
+ writeFileSync41(cfg.configFile, setShipNameInYaml(readFileSync51(cfg.configFile, "utf8"), newName));
29907
30073
  cfg.ship.name = newName;
29908
30074
  let renameMachineId;
29909
30075
  try {
@@ -29950,14 +30116,14 @@ ${cu.tail.trimEnd()}
29950
30116
  process.exit(2);
29951
30117
  };
29952
30118
  if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
29953
- const configText = readFileSync50(cfg.configFile, "utf8");
30119
+ const configText = readFileSync51(cfg.configFile, "utf8");
29954
30120
  if (sub === "check") {
29955
30121
  try {
29956
30122
  const routeArg = value("route") ?? positional[2];
29957
30123
  const found = cfg.routes.find((r) => r.route === routeArg);
29958
30124
  if (!found) throw new ReposError(`no route "${routeArg}" in the config (have: ${cfg.routes.map((r) => r.route).join(", ") || "none"})`);
29959
30125
  const named2 = value("route") ? void 0 : positional[3];
29960
- const dir = named2 ? repoDirOf(configText, dirname35(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
30126
+ const dir = named2 ? repoDirOf(configText, dirname36(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
29961
30127
  const target = reposOf(found).find((t) => resolvePath(t.dir) === dir || t.name === named2);
29962
30128
  const o = target ? found.repoOverrides[target.name] : void 0;
29963
30129
  runReposCheck(dir, {
@@ -29981,9 +30147,9 @@ ${cu.tail.trimEnd()}
29981
30147
  if (sub === "hooks") {
29982
30148
  try {
29983
30149
  const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
29984
- const dir = repoDirOf(configText, dirname35(cfg.configFile), a.route, a.name);
29985
- if (!existsSync55(dir)) throw new ReposError(`${dir} does not exist on disk`);
29986
- const files = { exists: (r) => existsSync55(resolvePath(dir, r)), list: (r) => {
30150
+ const dir = repoDirOf(configText, dirname36(cfg.configFile), a.route, a.name);
30151
+ if (!existsSync56(dir)) throw new ReposError(`${dir} does not exist on disk`);
30152
+ const files = { exists: (r) => existsSync56(resolvePath(dir, r)), list: (r) => {
29987
30153
  try {
29988
30154
  return readdirSync20(resolvePath(dir, r));
29989
30155
  } catch {
@@ -29991,7 +30157,7 @@ ${cu.tail.trimEnd()}
29991
30157
  }
29992
30158
  }, read: (r) => {
29993
30159
  try {
29994
- return readFileSync50(resolvePath(dir, r), "utf8");
30160
+ return readFileSync51(resolvePath(dir, r), "utf8");
29995
30161
  } catch {
29996
30162
  return void 0;
29997
30163
  }
@@ -30033,19 +30199,19 @@ ${cu.tail.trimEnd()}
30033
30199
  let cleared;
30034
30200
  if (clear2) {
30035
30201
  const plan = clearRouteHooks(configText, a.route, a.name);
30036
- if (plan.removed.length > 0) writeFileSync40(cfg.configFile, plan.text);
30202
+ if (plan.removed.length > 0) writeFileSync41(cfg.configFile, plan.text);
30037
30203
  cleared = { file: cfg.configFile, removed: plan.removed };
30038
30204
  }
30039
30205
  if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
30040
30206
  if (write === "route") {
30041
30207
  const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
30042
- writeFileSync40(cfg.configFile, plan.text);
30208
+ writeFileSync41(cfg.configFile, plan.text);
30043
30209
  written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
30044
30210
  } else if (write === "repo") {
30045
30211
  const have = existingRepoConfig(files);
30046
30212
  if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
30047
30213
  const file = resolvePath(dir, ".crew.yaml");
30048
- writeFileSync40(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
30214
+ writeFileSync41(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
30049
30215
  written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
30050
30216
  }
30051
30217
  if (flag("json")) {
@@ -30101,7 +30267,7 @@ ${cu.tail.trimEnd()}
30101
30267
  if (sub === "list" && !routeName) usage2();
30102
30268
  if (sub === "add") {
30103
30269
  try {
30104
- const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync55(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
30270
+ const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync56(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
30105
30271
  routeName = a.route;
30106
30272
  addPath = a.path;
30107
30273
  addName = a.name;
@@ -30131,7 +30297,7 @@ ${cu.tail.trimEnd()}
30131
30297
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
30132
30298
  if (sub === "list" || sub === "add") {
30133
30299
  const liveRoute = cfg.routes.find((r) => r.route === routeName);
30134
- if (liveRoute?.resolved?.reposModelId && existsSync55(resolvedFile) && !dryRun) {
30300
+ if (liveRoute?.resolved?.reposModelId && existsSync56(resolvedFile) && !dryRun) {
30135
30301
  try {
30136
30302
  await hydrateApiKeys([liveRoute]);
30137
30303
  persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
@@ -30140,16 +30306,16 @@ ${cu.tail.trimEnd()}
30140
30306
  }
30141
30307
  }
30142
30308
  let resolvedRemotes;
30143
- if (existsSync55(resolvedFile)) {
30309
+ if (existsSync56(resolvedFile)) {
30144
30310
  try {
30145
- resolvedRemotes = JSON.parse(readFileSync50(resolvedFile, "utf8"));
30311
+ resolvedRemotes = JSON.parse(readFileSync51(resolvedFile, "utf8"));
30146
30312
  } catch {
30147
30313
  }
30148
30314
  }
30149
30315
  const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
30150
30316
  const text2 = configText;
30151
- const base = dirname35(cfg.configFile);
30152
- const isCheckout = (d) => existsSync55(`${d}/.git`);
30317
+ const base = dirname36(cfg.configFile);
30318
+ const isCheckout = (d) => existsSync56(`${d}/.git`);
30153
30319
  try {
30154
30320
  if (sub === "list") {
30155
30321
  if (flag("json")) {
@@ -30159,12 +30325,12 @@ ${cu.tail.trimEnd()}
30159
30325
  base,
30160
30326
  resolved: resolvedRemotes,
30161
30327
  originOf,
30162
- exists: (d) => existsSync55(d),
30328
+ exists: (d) => existsSync56(d),
30163
30329
  isCheckout,
30164
30330
  repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f) => {
30165
30331
  try {
30166
30332
  const path = resolvePath(d, f);
30167
- return Object.keys(parseRepoConfig(readFileSync50(path, "utf8"), path).hooks).length > 0;
30333
+ return Object.keys(parseRepoConfig(readFileSync51(path, "utf8"), path).hooks).length > 0;
30168
30334
  } catch {
30169
30335
  return false;
30170
30336
  }
@@ -30181,7 +30347,7 @@ ${cu.tail.trimEnd()}
30181
30347
  for (const r of repos) {
30182
30348
  const origin2 = originOf(r.dir);
30183
30349
  const row = matchRepoName(origin2, resolvedRemotes);
30184
- const note = !existsSync55(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote(origin2) ?? "this checkout (no origin remote)"}`;
30350
+ const note = !existsSync56(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote(origin2) ?? "this checkout (no origin remote)"}`;
30185
30351
  process.stdout.write(`${r.name} ${r.dir} ${note}
30186
30352
  `);
30187
30353
  }
@@ -30193,9 +30359,9 @@ ${cu.tail.trimEnd()}
30193
30359
  ` : `${human}
30194
30360
  `);
30195
30361
  const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
30196
- if (existsSync55(plan2.target) && (existsSync55(`${plan2.target}/.git`) || readdirSync20(plan2.target).length > 0)) {
30362
+ if (existsSync56(plan2.target) && (existsSync56(`${plan2.target}/.git`) || readdirSync20(plan2.target).length > 0)) {
30197
30363
  throw new ReposError(
30198
- existsSync55(`${plan2.target}/.git`) ? `${plan2.target} is already a checkout \u2014 attach it with \`crew repos add ${routeName} ${plan2.name} ${plan2.target}\`` : `${plan2.target} exists and is not empty \u2014 pass --dir to clone somewhere else`
30364
+ existsSync56(`${plan2.target}/.git`) ? `${plan2.target} is already a checkout \u2014 attach it with \`crew repos add ${routeName} ${plan2.name} ${plan2.target}\`` : `${plan2.target} exists and is not empty \u2014 pass --dir to clone somewhere else`
30199
30365
  );
30200
30366
  }
30201
30367
  if (dryRun) {
@@ -30213,14 +30379,14 @@ ${cu.tail.trimEnd()}
30213
30379
  throw new ReposError(`${e.message}${authHint}
30214
30380
  crew.yaml was not changed`);
30215
30381
  }
30216
- writeFileSync40(cfg.configFile, plan2.text);
30382
+ writeFileSync41(cfg.configFile, plan2.text);
30217
30383
  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:
30218
30384
  `);
30219
30385
  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}`);
30220
30386
  break;
30221
30387
  }
30222
30388
  const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
30223
- const top = existsSync55(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
30389
+ const top = existsSync56(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
30224
30390
  if (!top) throw new ReposError(`${target} is not a git checkout`);
30225
30391
  const origin = originOf(top);
30226
30392
  const plan = planRepoAdd({
@@ -30272,15 +30438,15 @@ ${cu.tail.trimEnd()}
30272
30438
  const created = await rowTracker.createRepoRow(rowPayload);
30273
30439
  process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
30274
30440
  `);
30275
- if (existsSync55(resolvedFile)) {
30276
- const raw = JSON.parse(readFileSync50(resolvedFile, "utf8"));
30441
+ if (existsSync56(resolvedFile)) {
30442
+ const raw = JSON.parse(readFileSync51(resolvedFile, "utf8"));
30277
30443
  raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
30278
30444
  raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
30279
- writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
30445
+ writeFileSync41(resolvedFile, `${JSON.stringify(raw, null, 2)}
30280
30446
  `);
30281
30447
  }
30282
30448
  }
30283
- writeFileSync40(cfg.configFile, plan.text);
30449
+ writeFileSync41(cfg.configFile, plan.text);
30284
30450
  process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
30285
30451
  `);
30286
30452
  } catch (e) {
@@ -30655,7 +30821,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30655
30821
  process.exit(2);
30656
30822
  }
30657
30823
  if (found.shipNameAdopted && !dryRun) {
30658
- writeFileSync40(cfg.configFile, setShipNameInYaml(readFileSync50(cfg.configFile, "utf8"), found.shipNameAdopted));
30824
+ writeFileSync41(cfg.configFile, setShipNameInYaml(readFileSync51(cfg.configFile, "utf8"), found.shipNameAdopted));
30659
30825
  cfg.ship.name = found.shipNameAdopted;
30660
30826
  }
30661
30827
  if (found.shipRow) {
@@ -30698,10 +30864,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30698
30864
  }
30699
30865
  }
30700
30866
  let previous;
30701
- const hadPreviousFile = existsSync55(resolvedPath);
30867
+ const hadPreviousFile = existsSync56(resolvedPath);
30702
30868
  if (hadPreviousFile) {
30703
30869
  try {
30704
- previous = JSON.parse(readFileSync50(resolvedPath, "utf8"));
30870
+ previous = JSON.parse(readFileSync51(resolvedPath, "utf8"));
30705
30871
  } catch {
30706
30872
  }
30707
30873
  }
@@ -30831,10 +30997,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30831
30997
  process.stderr.write(`(dry run) would write resolved ids to ${resolvedPath}
30832
30998
  `);
30833
30999
  } else {
30834
- mkdirSync40(dirname35(resolvedPath), { recursive: true });
31000
+ mkdirSync41(dirname36(resolvedPath), { recursive: true });
30835
31001
  if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
30836
31002
  const tmpPath = `${resolvedPath}.tmp${process.pid}`;
30837
- writeFileSync40(tmpPath, `${JSON.stringify(resolved, null, 2)}
31003
+ writeFileSync41(tmpPath, `${JSON.stringify(resolved, null, 2)}
30838
31004
  `);
30839
31005
  renameSync7(tmpPath, resolvedPath);
30840
31006
  process.stderr.write(`Resolved ids written to ${resolvedPath}
@@ -30880,8 +31046,8 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30880
31046
  process.stderr.write(`(dry run) would write the minted API key to ${apiKeyFile}
30881
31047
  `);
30882
31048
  } else {
30883
- mkdirSync40(dirname35(apiKeyFile), { recursive: true });
30884
- writeFileSync40(apiKeyFile, `${apiKeyVar}=${apiKey}
31049
+ mkdirSync41(dirname36(apiKeyFile), { recursive: true });
31050
+ writeFileSync41(apiKeyFile, `${apiKeyVar}=${apiKey}
30885
31051
  `, { mode: 384 });
30886
31052
  process.stderr.write(`API key written to ${apiKeyFile}
30887
31053
  `);
@@ -31596,10 +31762,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
31596
31762
  startupSeconds: cfg.ship.intelStartupSeconds,
31597
31763
  prepare: async (path) => {
31598
31764
  for (const f of repoWt.config.worktrees.copy) {
31599
- const src = join57(repoWt.dir, f);
31600
- if (!existsSync55(src) || existsSync55(join57(path, f))) continue;
31601
- mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
31602
- copyFileSync2(src, join57(path, f));
31765
+ const src = join58(repoWt.dir, f);
31766
+ if (!existsSync56(src) || existsSync56(join58(path, f))) continue;
31767
+ mkdirSync41(dirOf2(join58(path, f)), { recursive: true });
31768
+ copyFileSync2(src, join58(path, f));
31603
31769
  }
31604
31770
  const setup = repoWt.config.hooks.setup;
31605
31771
  return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
@@ -31825,7 +31991,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
31825
31991
  const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
31826
31992
  const resumed = await runPeriscopeResume({
31827
31993
  find: async () => hit && { row: hit.row, tag: hit.tag },
31828
- worktreeExists: (p) => existsSync55(p),
31994
+ worktreeExists: (p) => existsSync56(p),
31829
31995
  prepareDropFile,
31830
31996
  startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
31831
31997
  relay: hit && previewRelayFor(hit.route) && {
@@ -31928,10 +32094,10 @@ ${where.join("\n")}`);
31928
32094
  },
31929
32095
  prepare: async (path) => {
31930
32096
  for (const f of repoP.config.worktrees.copy) {
31931
- const src = join57(repoP.dir, f);
31932
- if (!existsSync55(src)) continue;
31933
- mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
31934
- copyFileSync2(src, join57(path, f));
32097
+ const src = join58(repoP.dir, f);
32098
+ if (!existsSync56(src)) continue;
32099
+ mkdirSync41(dirOf2(join58(path, f)), { recursive: true });
32100
+ copyFileSync2(src, join58(path, f));
31935
32101
  }
31936
32102
  const setup = repoP.config.hooks.setup;
31937
32103
  return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
@@ -32243,7 +32409,7 @@ ${where.join("\n")}`);
32243
32409
  };
32244
32410
  const droppedRoutes = [];
32245
32411
  try {
32246
- const rawCfg = parseYaml3(readFileSync50(cfg.configFile, "utf8"));
32412
+ const rawCfg = parseYaml3(readFileSync51(cfg.configFile, "utf8"));
32247
32413
  for (const r of rawCfg?.routes ?? []) {
32248
32414
  if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
32249
32415
  try {
@@ -32307,8 +32473,8 @@ ${where.join("\n")}`);
32307
32473
  process.stdout.write("crew reload: no daemon unit is running \u2014 nothing to reload (the next run reads crew.yaml fresh)\n");
32308
32474
  break;
32309
32475
  }
32310
- mkdirSync40(cfg.ship.stateDir, { recursive: true });
32311
- writeFileSync40(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
32476
+ mkdirSync41(cfg.ship.stateDir, { recursive: true });
32477
+ writeFileSync41(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
32312
32478
  `);
32313
32479
  process.stdout.write(
32314
32480
  "crew reload: requested \u2014 the daemon relaunches with the new config once its running agents end (it starts no new work meanwhile); if it is busy, `crew reload --now` forces the relaunch and interrupts them\n"
@@ -32373,7 +32539,7 @@ ${where.join("\n")}`);
32373
32539
  }
32374
32540
  case "log": {
32375
32541
  try {
32376
- const text2 = readFileSync50(cfg.ship.logFile, "utf8").split("\n");
32542
+ const text2 = readFileSync51(cfg.ship.logFile, "utf8").split("\n");
32377
32543
  process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
32378
32544
  `);
32379
32545
  } catch {
@@ -32396,8 +32562,8 @@ ${where.join("\n")}`);
32396
32562
  };
32397
32563
  if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
32398
32564
  const tracker = new Tracker(route2, cfg.ship);
32399
- const configText = readFileSync50(cfg.configFile, "utf8");
32400
- const cfgBase = dirname35(cfg.configFile);
32565
+ const configText = readFileSync51(cfg.configFile, "utf8");
32566
+ const cfgBase = dirname36(cfg.configFile);
32401
32567
  const configured2 = configuredRepos(configText, route2.route, cfgBase);
32402
32568
  const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
32403
32569
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, route2.route);
@@ -32425,7 +32591,7 @@ ${where.join("\n")}`);
32425
32591
  }
32426
32592
  if (configured2.some((r) => r.dir === dir)) {
32427
32593
  try {
32428
- writeFileSync40(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
32594
+ writeFileSync41(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
32429
32595
  } catch (e) {
32430
32596
  if (e instanceof ReposError) fail2(e.message);
32431
32597
  throw e;
@@ -32433,29 +32599,29 @@ ${where.join("\n")}`);
32433
32599
  }
32434
32600
  if (row) {
32435
32601
  await tracker.deleteRepoRow(row.id);
32436
- if (existsSync55(resolvedFile)) {
32437
- const raw = JSON.parse(readFileSync50(resolvedFile, "utf8"));
32602
+ if (existsSync56(resolvedFile)) {
32603
+ const raw = JSON.parse(readFileSync51(resolvedFile, "utf8"));
32438
32604
  if (raw.repoNames) delete raw.repoNames[row.id];
32439
32605
  if (raw.repoRemotes) delete raw.repoRemotes[row.id];
32440
- writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
32606
+ writeFileSync41(resolvedFile, `${JSON.stringify(raw, null, 2)}
32441
32607
  `);
32442
32608
  }
32443
32609
  }
32444
- if (existsSync55(join57(dir, ".git")) && basename16(dir) === SAMPLE_REPO) rmSync25(dir, { recursive: true, force: true });
32610
+ if (existsSync56(join58(dir, ".git")) && basename16(dir) === SAMPLE_REPO) rmSync25(dir, { recursive: true, force: true });
32445
32611
  say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
32446
32612
  break;
32447
32613
  }
32448
32614
  const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
32449
- const fresh = !existsSync55(join57(dir, ".git"));
32450
- if (existsSync55(dir) && fresh && readdirSync20(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
32615
+ const fresh = !existsSync56(join58(dir, ".git"));
32616
+ if (existsSync56(dir) && fresh && readdirSync20(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
32451
32617
  if (dryRun) {
32452
32618
  say("dry-run", { dir, newCheckout: fresh, repoRow: row?.id ?? null }, `would ${fresh ? "create" : "reuse"} ${dir}${row ? "" : ", create the Repos row"}, and file one ${tracker.contract.statuses.approved} ticket`);
32453
32619
  break;
32454
32620
  }
32455
32621
  if (fresh) {
32456
- mkdirSync40(dir, { recursive: true });
32457
- writeFileSync40(join57(dir, "README.md"), SAMPLE_README);
32458
- writeFileSync40(join57(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
32622
+ mkdirSync41(dir, { recursive: true });
32623
+ writeFileSync41(join58(dir, "README.md"), SAMPLE_README);
32624
+ writeFileSync41(join58(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
32459
32625
  const g = (...a) => {
32460
32626
  const r = spawnSync13("git", a, { cwd: dir, encoding: "utf8" });
32461
32627
  if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
@@ -32473,17 +32639,17 @@ ${where.join("\n")}`);
32473
32639
  spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
32474
32640
  });
32475
32641
  repoId = (await tracker.createRepoRow(payload)).id;
32476
- if (existsSync55(resolvedFile)) {
32477
- const raw = JSON.parse(readFileSync50(resolvedFile, "utf8"));
32642
+ if (existsSync56(resolvedFile)) {
32643
+ const raw = JSON.parse(readFileSync51(resolvedFile, "utf8"));
32478
32644
  raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
32479
32645
  raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
32480
- writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
32646
+ writeFileSync41(resolvedFile, `${JSON.stringify(raw, null, 2)}
32481
32647
  `);
32482
32648
  }
32483
32649
  }
32484
32650
  if (!configured2.some((r) => r.dir === dir)) {
32485
32651
  try {
32486
- writeFileSync40(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
32652
+ writeFileSync41(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
32487
32653
  } catch (e) {
32488
32654
  if (e instanceof ReposError) fail2(e.message);
32489
32655
  throw e;
@@ -32596,7 +32762,30 @@ ${where.join("\n")}`);
32596
32762
  case "status": {
32597
32763
  const fairness = state.fairness(route2.route);
32598
32764
  const waiting = fairness.waiting();
32599
- const statusTracker = new Tracker(route2, cfg.ship);
32765
+ let statusTracker;
32766
+ try {
32767
+ statusTracker = new Tracker(route2, cfg.ship);
32768
+ } catch (e) {
32769
+ if (!(e instanceof ConfigError)) throw e;
32770
+ const attention = openShipAttention(state);
32771
+ if (flag("json")) {
32772
+ process.stdout.write(`${JSON.stringify({
32773
+ version: 1,
32774
+ configFile: cfg.configFile,
32775
+ ship: { name: cfg.ship.name, platform: cfg.ship.platform },
32776
+ route: route2.route,
32777
+ attention,
32778
+ error: e.message
32779
+ }, null, 2)}
32780
+ `);
32781
+ } else {
32782
+ process.stdout.write(`crew: ${e.message}
32783
+ `);
32784
+ for (const i of attention) process.stdout.write(`attention: ${i.kind} \u2014 ${i.message}
32785
+ `);
32786
+ }
32787
+ process.exit(1);
32788
+ }
32600
32789
  const shipRows = await statusTracker.shipRows();
32601
32790
  const engagedTicketIds = shipRows.map((s) => s.engaged_ticket_id).filter((id) => !!id);
32602
32791
  const engagedTickets = engagedTicketIds.length ? await statusTracker.ticketsByIds(engagedTicketIds) : [];
@@ -32827,7 +33016,7 @@ watermark: ${state.watermark()}
32827
33016
  plan,
32828
33017
  label,
32829
33018
  uid: process.getuid?.() ?? 0,
32830
- system: plan.mechanism === "systemd" && existsSync55(systemUnitPathFor(label)),
33019
+ system: plan.mechanism === "systemd" && existsSync56(systemUnitPathFor(label)),
32831
33020
  stamp: readDaemonStamp(cfg.ship.stateDir)
32832
33021
  });
32833
33022
  })();
@@ -32843,7 +33032,7 @@ watermark: ${state.watermark()}
32843
33032
  }
32844
33033
  for (const r of repos) {
32845
33034
  const remote = r.config.branch.remote;
32846
- if (existsSync55(r.dir)) {
33035
+ if (existsSync56(r.dir)) {
32847
33036
  pushAuth.push({
32848
33037
  route: c.route,
32849
33038
  repo: r.name,
@@ -32925,7 +33114,7 @@ watermark: ${state.watermark()}
32925
33114
  if (dp) problems.push(dp);
32926
33115
  else passed++;
32927
33116
  }
32928
- const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync55, userInfo2().username);
33117
+ const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync56, userInfo2().username);
32929
33118
  if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
32930
33119
  if (!flag("offline")) {
32931
33120
  const shipKind = await doctorShipKind(route2, cfg.ship);
@@ -32990,7 +33179,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
32990
33179
  }
32991
33180
  try {
32992
33181
  const evFile = eventFileFor(cfg.ship.stateDir);
32993
- const evSize = existsSync55(evFile) ? statSync17(evFile).size : 0;
33182
+ const evSize = existsSync56(evFile) ? statSync17(evFile).size : 0;
32994
33183
  process.stdout.write(
32995
33184
  evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
32996
33185
  ` : "events log: ok\n"
@@ -33001,7 +33190,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
33001
33190
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
33002
33191
  const abandons = unitAbandonsAgents(unitPlan, (p) => {
33003
33192
  try {
33004
- return readFileSync50(p, "utf8");
33193
+ return readFileSync51(p, "utf8");
33005
33194
  } catch {
33006
33195
  return null;
33007
33196
  }
@@ -33016,7 +33205,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
33016
33205
  const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
33017
33206
  const keeps = unitAbandonsAgents(pPlan, (p) => {
33018
33207
  try {
33019
- return readFileSync50(p, "utf8");
33208
+ return readFileSync51(p, "utf8");
33020
33209
  } catch {
33021
33210
  return null;
33022
33211
  }
@@ -33030,7 +33219,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
33030
33219
  if (host === "linux" && detectSystemd()) {
33031
33220
  const ctl = planDaemonControl(CREW_HOME, host, true);
33032
33221
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
33033
- if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync55(p))) {
33222
+ if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync56(p))) {
33034
33223
  const st = spawnSync13(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
33035
33224
  if (!st.error && st.status !== 0) {
33036
33225
  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");