@tablation/crew 0.137.3 → 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 +366 -173
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -14561,6 +14561,10 @@ function stopContainer(name, exec = realExec) {
14561
14561
  } catch {
14562
14562
  }
14563
14563
  }
14564
+ function bindMountSpec(hostPath, containerPath) {
14565
+ const q2 = (v) => /[",]/.test(v) ? `"${v.replace(/"/g, '""')}"` : v;
14566
+ return `type=bind,source=${q2(hostPath)},target=${q2(containerPath)},readonly`;
14567
+ }
14564
14568
  function startContainer(plan, tablationApiBaseUrl, sync, exec = realExec) {
14565
14569
  const args = [
14566
14570
  "run",
@@ -14590,7 +14594,7 @@ function startContainer(plan, tablationApiBaseUrl, sync, exec = realExec) {
14590
14594
  `PASSENGER_MCP_SECRET=${sync.secret}`
14591
14595
  );
14592
14596
  }
14593
- for (const m of plan.mounts) args.push("-v", `${m.hostPath}:${m.containerPath}:ro`);
14597
+ for (const m of plan.mounts) args.push("--mount", bindMountSpec(m.hostPath, m.containerPath));
14594
14598
  args.push(plan.image);
14595
14599
  exec("docker", args);
14596
14600
  }
@@ -15114,7 +15118,7 @@ function doctorSelftestLines(stored, toolchains) {
15114
15118
  }
15115
15119
 
15116
15120
  // src/cli.ts
15117
- 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";
15118
15122
  import { fileURLToPath as fileURLToPath2 } from "url";
15119
15123
  import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
15120
15124
  import { spawnSync as spawnSync13 } from "child_process";
@@ -22902,6 +22906,76 @@ function readDaemonStamp(stateDir) {
22902
22906
  }
22903
22907
  }
22904
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
+
22905
22979
  // src/projects-cmd.ts
22906
22980
  async function buildProjectsReport(routes, open) {
22907
22981
  return Promise.all(routes.map(async (r) => {
@@ -23013,8 +23087,8 @@ function runForge(a, io) {
23013
23087
 
23014
23088
  // src/release-sandbox.ts
23015
23089
  import { execFile as execFile5 } from "child_process";
23016
- import { mkdirSync as mkdirSync35, writeFileSync as writeFileSync36 } from "fs";
23017
- import { dirname as dirname28 } from "path";
23090
+ import { mkdirSync as mkdirSync36, writeFileSync as writeFileSync37 } from "fs";
23091
+ import { dirname as dirname29 } from "path";
23018
23092
  import { promisify as promisify4 } from "util";
23019
23093
  var execFileP4 = promisify4(execFile5);
23020
23094
  var RELEASE_CLONE_DEPTH = 50;
@@ -23060,8 +23134,8 @@ async function openReleaseSandbox(o) {
23060
23134
  if (!policyFile) {
23061
23135
  generated = generateSandboxPolicy({ mirrorDir: cfg.mirrorDir, workDir: cfg.workDir, ...o.policy });
23062
23136
  policyFile = o.policyFile;
23063
- mkdirSync35(dirname28(policyFile), { recursive: true });
23064
- writeFileSync36(policyFile, generated.yaml, { mode: 384 });
23137
+ mkdirSync36(dirname29(policyFile), { recursive: true });
23138
+ writeFileSync37(policyFile, generated.yaml, { mode: 384 });
23065
23139
  }
23066
23140
  const secrets = { ...process.env };
23067
23141
  const secretKeys = [];
@@ -23227,7 +23301,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
23227
23301
  }
23228
23302
 
23229
23303
  // src/watch.ts
23230
- 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";
23231
23305
  var E = "\x1B[";
23232
23306
  var dim = (s) => `${E}2m${s}${E}0m`;
23233
23307
  var bold = (s) => `${E}1m${s}${E}0m`;
@@ -23328,7 +23402,7 @@ function renderHeaders(states, now = Date.now()) {
23328
23402
  return states.map((s) => renderHeader(s, now)).join("");
23329
23403
  }
23330
23404
  function readFrom(file, from) {
23331
- if (!existsSync48(file)) return { events: [], offset: from };
23405
+ if (!existsSync49(file)) return { events: [], offset: from };
23332
23406
  const size = statSync14(file).size;
23333
23407
  if (size < from) return readFrom(file, 0);
23334
23408
  if (size === from) return { events: [], offset: from };
@@ -24099,8 +24173,8 @@ function describeCapability(i) {
24099
24173
  }
24100
24174
 
24101
24175
  // src/agents-sync-run.ts
24102
- import { existsSync as existsSync49, mkdirSync as mkdirSync36, readFileSync as readFileSync45, writeFileSync as writeFileSync37 } from "fs";
24103
- 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";
24104
24178
  async function runAgentsSync(target, o) {
24105
24179
  const dryRun = o.dryRun ?? false;
24106
24180
  const force = o.force ?? false;
@@ -24135,12 +24209,12 @@ async function runAgentsSync(target, o) {
24135
24209
  for (const w of skillResult?.warnings ?? []) o.warn(`warning: ${w}`);
24136
24210
  if (!dryRun) {
24137
24211
  const resolvedPath = resolvedPathFor(o.stateDir, target.route);
24138
- const raw = existsSync49(resolvedPath) ? JSON.parse(readFileSync45(resolvedPath, "utf8")) : {};
24212
+ const raw = existsSync50(resolvedPath) ? JSON.parse(readFileSync46(resolvedPath, "utf8")) : {};
24139
24213
  raw.agentPersonas = personaResult.agentPersonas;
24140
24214
  if (skillResult) raw.agentSkills = skillResult.agentSkills;
24141
24215
  if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
24142
- mkdirSync36(dirname29(resolvedPath), { recursive: true });
24143
- writeFileSync37(resolvedPath, `${JSON.stringify(raw, null, 2)}
24216
+ mkdirSync37(dirname30(resolvedPath), { recursive: true });
24217
+ writeFileSync38(resolvedPath, `${JSON.stringify(raw, null, 2)}
24144
24218
  `);
24145
24219
  if (target.resolved) {
24146
24220
  target.resolved.agentPersonas = personaResult.agentPersonas;
@@ -24277,7 +24351,7 @@ async function showLogEntry(route2, entryId, opts = {}) {
24277
24351
 
24278
24352
  // src/repos-check.ts
24279
24353
  import { spawnSync as spawnSync12 } from "child_process";
24280
- import { readFileSync as readFileSync46 } from "fs";
24354
+ import { readFileSync as readFileSync47 } from "fs";
24281
24355
  import { basename as basename11 } from "path";
24282
24356
  var POSIX_SHELL = /^(?:ba|z|da|k|a|mk)?sh$|^fish$/;
24283
24357
  function checkHookSyntax(script, shell) {
@@ -24318,7 +24392,7 @@ function checkRepoSpec(dir, opts = {}) {
24318
24392
  }
24319
24393
  let parsed;
24320
24394
  try {
24321
- parsed = parseRepoConfig(readFileSync46(file, "utf8"), file);
24395
+ parsed = parseRepoConfig(readFileSync47(file, "utf8"), file);
24322
24396
  } catch (e) {
24323
24397
  if (!(e instanceof RepoConfigError)) throw e;
24324
24398
  return { ...empty, file, error: e.message, exitCode: 1 };
@@ -24782,7 +24856,7 @@ ${run4.err}` });
24782
24856
  }
24783
24857
 
24784
24858
  // src/sample-ticket.ts
24785
- 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";
24786
24860
  var SAMPLE_REPO = "crew-sample";
24787
24861
  var SAMPLE_REMOTE = `local/${SAMPLE_REPO}`;
24788
24862
  var SAMPLE_MARKER = "sample: true";
@@ -24805,8 +24879,8 @@ has something safe to work on: its test and build hooks always pass, it has no
24805
24879
  remote, and \`crew sample-ticket --remove\` deletes it.
24806
24880
  `;
24807
24881
  function sampleDir(existing, reposBase, workspace) {
24808
- if (existing.length > 0) return join49(dirname30(existing[0]), SAMPLE_REPO);
24809
- 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);
24810
24884
  }
24811
24885
  var SAMPLE_TITLE = "Sample: add a documented `greet` function with a test";
24812
24886
  function sampleDescription() {
@@ -24850,8 +24924,8 @@ function planSampleTicket(i) {
24850
24924
  }
24851
24925
 
24852
24926
  // src/worktree-sweep.ts
24853
- import { existsSync as existsSync50, readFileSync as readFileSync47, readdirSync as readdirSync15 } from "fs";
24854
- 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";
24855
24929
  function planWorktreeSweep(target, tickets, contract) {
24856
24930
  const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
24857
24931
  const verified = contract.statuses.verified;
@@ -24915,7 +24989,7 @@ function worktreeTicketNumbers(target) {
24915
24989
  return [...nums];
24916
24990
  }
24917
24991
  function siblingWorktreeDirs(target) {
24918
- const parent = dirname31(target.dir.replace(/[/\\]+$/, ""));
24992
+ const parent = dirname32(target.dir.replace(/[/\\]+$/, ""));
24919
24993
  const stem = `${basename13(target.dir.replace(/[/\\]+$/, ""))}-`;
24920
24994
  const registered = new Set(worktrees(target.dir).map((w) => resolve5(w.path)));
24921
24995
  let names;
@@ -24928,7 +25002,7 @@ function siblingWorktreeDirs(target) {
24928
25002
  for (const name of names) {
24929
25003
  if (!name.startsWith(stem)) continue;
24930
25004
  const m = DIR_NUMBER_SUFFIXED.exec(name);
24931
- const path = join50(parent, name);
25005
+ const path = join51(parent, name);
24932
25006
  if (m && !registered.has(resolve5(path))) out.push({ path, number: m[1] });
24933
25007
  }
24934
25008
  return out;
@@ -24963,7 +25037,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
24963
25037
  let removed = 0;
24964
25038
  let keptBranches = 0;
24965
25039
  for (const a of actions) {
24966
- 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)) {
24967
25041
  if (gitOk(a.path, ["merge", "--abort"]) !== null) {
24968
25042
  log.emit(
24969
25043
  `abandoned the hand-back merge of ${base} in ${a.path}: ${a.ticket.issue_id} deployed without it`,
@@ -24971,7 +25045,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
24971
25045
  );
24972
25046
  }
24973
25047
  }
24974
- if (!dryRun && existsSync50(a.path)) {
25048
+ if (!dryRun && existsSync51(a.path)) {
24975
25049
  let dirty = false;
24976
25050
  try {
24977
25051
  dirty = status(a.path).length > 0;
@@ -24982,7 +25056,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
24982
25056
  continue;
24983
25057
  }
24984
25058
  }
24985
- 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)) {
24986
25060
  refuse2(a, "unpushed commits", `${a.branch} has commits that are not on ${remote}`);
24987
25061
  continue;
24988
25062
  }
@@ -25031,7 +25105,7 @@ function isHandBackMerge(path, base) {
25031
25105
  if (!msgPath) return false;
25032
25106
  let first;
25033
25107
  try {
25034
- first = readFileSync47(resolve5(path, msgPath), "utf8").split("\n")[0] ?? "";
25108
+ first = readFileSync48(resolve5(path, msgPath), "utf8").split("\n")[0] ?? "";
25035
25109
  } catch {
25036
25110
  return false;
25037
25111
  }
@@ -25136,14 +25210,14 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
25136
25210
  }
25137
25211
 
25138
25212
  // src/stream-sweep.ts
25139
- import { existsSync as existsSync51, readdirSync as readdirSync16, rmSync as rmSync22, statSync as statSync15 } from "fs";
25140
- 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";
25141
25215
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
25142
25216
  function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
25143
- const dir = join51(stateDir, "streams");
25144
- if (!existsSync51(dir)) return [];
25217
+ const dir = join52(stateDir, "streams");
25218
+ if (!existsSync52(dir)) return [];
25145
25219
  const cutoff = now - retentionDays * DAY_MS2;
25146
- return readdirSync16(dir).map((name) => join51(dir, name)).filter((path) => {
25220
+ return readdirSync16(dir).map((name) => join52(dir, name)).filter((path) => {
25147
25221
  try {
25148
25222
  return statSync15(path).mtimeMs < cutoff;
25149
25223
  } catch {
@@ -25169,9 +25243,9 @@ function applyStreamSweep(paths, dryRun, log) {
25169
25243
  return removed;
25170
25244
  }
25171
25245
  function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
25172
- if (!existsSync51(stateDir)) return [];
25246
+ if (!existsSync52(stateDir)) return [];
25173
25247
  const cutoff = now - retentionDays * DAY_MS2;
25174
- 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) => {
25175
25249
  try {
25176
25250
  return statSync15(path).mtimeMs < cutoff;
25177
25251
  } catch {
@@ -25181,7 +25255,7 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
25181
25255
  }
25182
25256
 
25183
25257
  // src/cli.ts
25184
- 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";
25185
25259
  import { createInterface } from "readline/promises";
25186
25260
 
25187
25261
  // src/periscope-resume.ts
@@ -25408,8 +25482,8 @@ async function unregisterEndpoint(workspaceId, info, d) {
25408
25482
  import { createServer as createHttpServer } from "http";
25409
25483
  import { spawn as spawn9 } from "child_process";
25410
25484
  import { randomBytes as randomBytes2 } from "crypto";
25411
- import { existsSync as existsSync52, mkdirSync as mkdirSync37, readFileSync as readFileSync48, writeFileSync as writeFileSync38, unlinkSync as unlinkSync4, readdirSync as readdirSync17 } from "fs";
25412
- 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";
25413
25487
 
25414
25488
  // src/secret-compare.ts
25415
25489
  import { timingSafeEqual } from "crypto";
@@ -25502,27 +25576,27 @@ var defaultSpawn2 = (cmd, args, env) => {
25502
25576
  return child;
25503
25577
  };
25504
25578
  function syncDaemonStatePath(stateDir, workspaceId) {
25505
- return join52(stateDir, "passengers", `${workspaceId}-sync.json`);
25579
+ return join53(stateDir, "passengers", `${workspaceId}-sync.json`);
25506
25580
  }
25507
25581
  function readPersistedSyncDaemon(stateDir, workspaceId) {
25508
25582
  const path = syncDaemonStatePath(stateDir, workspaceId);
25509
- if (!existsSync52(path)) return void 0;
25583
+ if (!existsSync53(path)) return void 0;
25510
25584
  try {
25511
- return JSON.parse(readFileSync48(path, "utf8"));
25585
+ return JSON.parse(readFileSync49(path, "utf8"));
25512
25586
  } catch {
25513
25587
  return void 0;
25514
25588
  }
25515
25589
  }
25516
25590
  function writePersistedSyncDaemon(stateDir, state) {
25517
25591
  const path = syncDaemonStatePath(stateDir, state.workspaceId);
25518
- mkdirSync37(join52(stateDir, "passengers"), { recursive: true });
25519
- writeFileSync38(path, `${JSON.stringify(state, null, 2)}
25592
+ mkdirSync38(join53(stateDir, "passengers"), { recursive: true });
25593
+ writeFileSync39(path, `${JSON.stringify(state, null, 2)}
25520
25594
  `);
25521
25595
  }
25522
25596
  function removePersistedSyncDaemon(stateDir, workspaceId) {
25523
25597
  const path = syncDaemonStatePath(stateDir, workspaceId);
25524
25598
  try {
25525
- unlinkSync4(path);
25599
+ unlinkSync5(path);
25526
25600
  } catch {
25527
25601
  }
25528
25602
  }
@@ -25536,8 +25610,8 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
25536
25610
  }
25537
25611
  }
25538
25612
  function readAllPersistedSyncWorkspaceIds(stateDir) {
25539
- const dir = join52(stateDir, "passengers");
25540
- if (!existsSync52(dir)) return [];
25613
+ const dir = join53(stateDir, "passengers");
25614
+ if (!existsSync53(dir)) return [];
25541
25615
  const suffix = "-sync.json";
25542
25616
  return readdirSync17(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
25543
25617
  }
@@ -25595,12 +25669,12 @@ function syncPassengerSyncDaemons(plans, cfg, stateDir, deps = {}) {
25595
25669
 
25596
25670
  // src/periscope-proxy.ts
25597
25671
  import { spawn as spawn10 } from "child_process";
25598
- import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync38 } from "fs";
25672
+ import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync39 } from "fs";
25599
25673
  import { createServer, request as httpRequest } from "http";
25600
25674
  import { request as httpsRequest } from "https";
25601
25675
  import { connect as netConnect } from "net";
25602
25676
  import { connect as tlsConnect } from "tls";
25603
- import { dirname as dirname32, isAbsolute as isAbsolute4 } from "path";
25677
+ import { dirname as dirname33, isAbsolute as isAbsolute4 } from "path";
25604
25678
  import { brotliDecompressSync, gunzipSync, inflateSync } from "zlib";
25605
25679
 
25606
25680
  // src/periscope-inspector.ts
@@ -25714,7 +25788,7 @@ function parsePointedBody(raw) {
25714
25788
  return entry;
25715
25789
  }
25716
25790
  function appendPointed(file, entry, now = /* @__PURE__ */ new Date()) {
25717
- mkdirSync38(dirname32(file), { recursive: true });
25791
+ mkdirSync39(dirname33(file), { recursive: true });
25718
25792
  appendFileSync3(file, `${JSON.stringify({ ...entry, at: now.toISOString() })}
25719
25793
  `);
25720
25794
  }
@@ -26003,7 +26077,7 @@ async function startWorktreeIntel(d) {
26003
26077
  }
26004
26078
 
26005
26079
  // src/contract-refusal.ts
26006
- import { join as join53 } from "path";
26080
+ import { join as join54 } from "path";
26007
26081
  function contractFixers(dir, baseRef, tickets, locate) {
26008
26082
  const out = [];
26009
26083
  for (const t of tickets) {
@@ -26015,7 +26089,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
26015
26089
  const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
26016
26090
  if (text2 === null) continue;
26017
26091
  try {
26018
- parseRepoConfig(text2, join53(dir, file));
26092
+ parseRepoConfig(text2, join54(dir, file));
26019
26093
  } catch (e) {
26020
26094
  if (e instanceof RepoConfigError) continue;
26021
26095
  throw e;
@@ -26030,7 +26104,7 @@ import { createHash as createHash11 } from "crypto";
26030
26104
  import {
26031
26105
  chmodSync as chmodSync4,
26032
26106
  closeSync as closeSync6,
26033
- existsSync as existsSync53,
26107
+ existsSync as existsSync54,
26034
26108
  fstatSync,
26035
26109
  openSync as openSync6,
26036
26110
  readSync as readSync3,
@@ -26041,7 +26115,7 @@ import {
26041
26115
  } from "fs";
26042
26116
  import { createConnection } from "net";
26043
26117
  import { createServer as createServer2 } from "http";
26044
- 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";
26045
26119
  import { execFile as execFile6, spawn as spawn12 } from "child_process";
26046
26120
 
26047
26121
  // src/periscope-control.ts
@@ -26278,7 +26352,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
26278
26352
  // src/control-api.ts
26279
26353
  var PAUSABLE = ["dev", "design", "qa"];
26280
26354
  var CONTROL_SOCKET_NAME = "control.sock";
26281
- var controlSocketFor = (stateDir) => join54(stateDir, CONTROL_SOCKET_NAME);
26355
+ var controlSocketFor = (stateDir) => join55(stateDir, CONTROL_SOCKET_NAME);
26282
26356
  var MAX_SOCKET_PATH = 100;
26283
26357
  var MAX_TAIL_BYTES = 1024 * 1024;
26284
26358
  var MAX_WAIT_SECONDS = 30;
@@ -26365,7 +26439,7 @@ function candidates(live, rotated) {
26365
26439
  const out = [live];
26366
26440
  if (!rotated) return out;
26367
26441
  try {
26368
- 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));
26369
26443
  } catch {
26370
26444
  }
26371
26445
  return out;
@@ -26409,7 +26483,7 @@ function lastLines2(path, n) {
26409
26483
  }
26410
26484
  function readTail(live, opts) {
26411
26485
  const max = opts.maxBytes ?? MAX_TAIL_BYTES;
26412
- if (!existsSync53(live)) {
26486
+ if (!existsSync54(live)) {
26413
26487
  return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
26414
26488
  }
26415
26489
  const cur = opts.after ? decodeCursor(opts.after) : null;
@@ -26525,7 +26599,7 @@ async function tailReply(path, q2, rotated, abort) {
26525
26599
  const deadline = Date.now() + Math.min(wait, MAX_WAIT_SECONDS) * 1e3;
26526
26600
  let r = readTail(path, { after, tail: tail3, rotated });
26527
26601
  while (after && !r.lines.length && !r.reset && Date.now() < deadline && !abort.aborted) {
26528
- await waitForChange(dirname33(path), deadline - Date.now(), abort);
26602
+ await waitForChange(dirname34(path), deadline - Date.now(), abort);
26529
26603
  r = readTail(path, { after: r.cursor, rotated });
26530
26604
  }
26531
26605
  return reply2(200, r);
@@ -26565,8 +26639,8 @@ async function route(deps, method, url, req, abort) {
26565
26639
  if (p.startsWith("/streams/") && get2) {
26566
26640
  const run4 = decodeURIComponent(p.slice("/streams/".length));
26567
26641
  if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
26568
- const file = join54(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
26569
- 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");
26570
26644
  return tailReply(file, url.searchParams, false, abort);
26571
26645
  }
26572
26646
  if ((p === "/pause" || p === "/resume") && post3) {
@@ -26611,7 +26685,7 @@ function send(res, r) {
26611
26685
  res.end(body);
26612
26686
  }
26613
26687
  async function socketIsStale(path) {
26614
- if (!existsSync53(path)) return false;
26688
+ if (!existsSync54(path)) return false;
26615
26689
  return new Promise((resolve8) => {
26616
26690
  const c = createConnection(path);
26617
26691
  c.once("connect", () => {
@@ -26630,7 +26704,7 @@ async function startControlServer(deps) {
26630
26704
  return null;
26631
26705
  }
26632
26706
  if (await socketIsStale(path)) rmSync23(path, { force: true });
26633
- else if (existsSync53(path)) {
26707
+ else if (existsSync54(path)) {
26634
26708
  log(`control API not started: ${path} is in use by another process`);
26635
26709
  return null;
26636
26710
  }
@@ -26716,31 +26790,31 @@ function crewJson(args, timeoutMs = 6e4) {
26716
26790
 
26717
26791
  // src/periscope-mcp.ts
26718
26792
  import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
26719
- 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";
26720
26794
  import { z } from "zod";
26721
26795
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
26722
26796
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
26723
26797
 
26724
26798
  // src/periscope-endpoints.ts
26725
26799
  import { randomBytes as randomBytes3 } from "crypto";
26726
- import { chmodSync as chmodSync5, existsSync as existsSync54, mkdirSync as mkdirSync39, readdirSync as readdirSync19, readFileSync as readFileSync49, rmSync as rmSync24, writeFileSync as writeFileSync39 } from "fs";
26727
- import { join as join55 } from "path";
26728
- var secretDir = (stateDir) => join55(stateDir, "periscope-mcp");
26729
- var secretFile = (stateDir, id) => join55(secretDir(stateDir), `${id}.json`);
26730
- var endpointDir = (stateDir) => join55(stateDir, "periscope-endpoints");
26731
- 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`);
26732
26806
  function mintPeriscopeSecret(stateDir, ticketRecordId) {
26733
- mkdirSync39(secretDir(stateDir), { recursive: true, mode: 448 });
26807
+ mkdirSync40(secretDir(stateDir), { recursive: true, mode: 448 });
26734
26808
  const secret = randomBytes3(32).toString("base64url");
26735
26809
  const file = secretFile(stateDir, ticketRecordId);
26736
- writeFileSync39(file, `${JSON.stringify({ secret })}
26810
+ writeFileSync40(file, `${JSON.stringify({ secret })}
26737
26811
  `, { mode: 384 });
26738
26812
  chmodSync5(file, 384);
26739
26813
  return secret;
26740
26814
  }
26741
26815
  function readPeriscopeSecret(stateDir, ticketRecordId) {
26742
26816
  try {
26743
- const v = JSON.parse(readFileSync49(secretFile(stateDir, ticketRecordId), "utf8"));
26817
+ const v = JSON.parse(readFileSync50(secretFile(stateDir, ticketRecordId), "utf8"));
26744
26818
  return typeof v.secret === "string" && v.secret ? v.secret : void 0;
26745
26819
  } catch {
26746
26820
  return void 0;
@@ -26751,14 +26825,14 @@ function removePeriscopeSecret(stateDir, ticketRecordId) {
26751
26825
  }
26752
26826
  function readPeriscopeEndpoint(stateDir, ticketRecordId) {
26753
26827
  try {
26754
- return JSON.parse(readFileSync49(endpointFile(stateDir, ticketRecordId), "utf8"));
26828
+ return JSON.parse(readFileSync50(endpointFile(stateDir, ticketRecordId), "utf8"));
26755
26829
  } catch {
26756
26830
  return void 0;
26757
26831
  }
26758
26832
  }
26759
26833
  function writePeriscopeEndpoint(stateDir, rec) {
26760
- mkdirSync39(endpointDir(stateDir), { recursive: true });
26761
- 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)}
26762
26836
  `);
26763
26837
  }
26764
26838
  function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
@@ -26766,7 +26840,7 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
26766
26840
  }
26767
26841
  function listPeriscopeEndpoints(stateDir) {
26768
26842
  const dir = endpointDir(stateDir);
26769
- if (!existsSync54(dir)) return [];
26843
+ if (!existsSync55(dir)) return [];
26770
26844
  const out = [];
26771
26845
  for (const name of readdirSync19(dir)) {
26772
26846
  if (!name.endsWith(".json")) continue;
@@ -26854,10 +26928,10 @@ async function realAncestor(p) {
26854
26928
  }
26855
26929
  if (isLink) {
26856
26930
  if (++hops > 40) throw new PathRefusal(`too many symbolic links resolving ${p}`);
26857
- cur = resolve6(dirname34(cur), await readlink(cur));
26931
+ cur = resolve6(dirname35(cur), await readlink(cur));
26858
26932
  continue;
26859
26933
  }
26860
- const parent = dirname34(cur);
26934
+ const parent = dirname35(cur);
26861
26935
  if (parent === cur) throw new PathRefusal(`cannot resolve ${p}`);
26862
26936
  tail3.push(basename15(cur));
26863
26937
  cur = parent;
@@ -26869,13 +26943,13 @@ async function resolveInWorktree(root, requested) {
26869
26943
  let abs;
26870
26944
  if (isAbsolute5(requested)) {
26871
26945
  abs = resolve6(requested);
26872
- if (isInside(root, abs)) abs = join56(realRoot, relative2(root, abs));
26946
+ if (isInside(root, abs)) abs = join57(realRoot, relative2(root, abs));
26873
26947
  } else {
26874
26948
  abs = resolve6(realRoot, requested);
26875
26949
  }
26876
26950
  if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
26877
26951
  const { real, rest } = await realAncestor(abs);
26878
- const final = rest ? join56(real, rest) : real;
26952
+ const final = rest ? join57(real, rest) : real;
26879
26953
  if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
26880
26954
  if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
26881
26955
  return final;
@@ -26943,7 +27017,7 @@ function createPeriscopeMcpServer(d, sc) {
26943
27017
  const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
26944
27018
  const lines2 = await Promise.all(entries.map(async (e) => {
26945
27019
  if (e.isDirectory()) return `[DIR] ${e.name}`;
26946
- const size = (await lstat(join56(abs, e.name))).size;
27020
+ const size = (await lstat(join57(abs, e.name))).size;
26947
27021
  return `[FILE] ${e.name} (${size} bytes)`;
26948
27022
  }));
26949
27023
  return text(lines2.join("\n") || "(empty)");
@@ -26968,7 +27042,7 @@ function createPeriscopeMcpServer(d, sc) {
26968
27042
  if (Buffer.byteLength(content) > MAX_WRITE_BYTES) return text(`content exceeds ${MAX_WRITE_BYTES} bytes`, true);
26969
27043
  const abs = await inTree(path);
26970
27044
  if (abs === await realpath(root)) return text("path must name a file", true);
26971
- await mkdir(dirname34(abs), { recursive: true });
27045
+ await mkdir(dirname35(abs), { recursive: true });
26972
27046
  await inTree(path);
26973
27047
  await writeFile(abs, content);
26974
27048
  return text(`Wrote ${Buffer.byteLength(content)} bytes to ${await rel(abs)}`);
@@ -27008,8 +27082,8 @@ function createPeriscopeMcpServer(d, sc) {
27008
27082
  inputSchema: { path: z.string() },
27009
27083
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
27010
27084
  }, async ({ path }) => {
27011
- const parent = await inTree(dirname34(path) === "" ? "." : dirname34(path));
27012
- const abs = join56(parent, basename15(path));
27085
+ const parent = await inTree(dirname35(path) === "" ? "." : dirname35(path));
27086
+ const abs = join57(parent, basename15(path));
27013
27087
  if (basename15(path) === ".git" || abs === parent) return text("path must name a file", true);
27014
27088
  const st = await lstat(abs).catch(() => void 0);
27015
27089
  if (!st) return text(`${path} does not exist`, true);
@@ -27130,7 +27204,7 @@ function findPeriscope(sidecars, segment) {
27130
27204
  }
27131
27205
 
27132
27206
  // src/cli.ts
27133
- 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)), "..");
27134
27208
  var RELEASE_LOCK_TTL_MS = 20 * 60 * 1e3;
27135
27209
  var CYCLE_SECONDS2 = 120;
27136
27210
  var STALE_CYCLES = 3;
@@ -27500,7 +27574,7 @@ if (command === "provision") {
27500
27574
  process.exit(outcome.code);
27501
27575
  }
27502
27576
  if (command === "pool-member") {
27503
- const pool = poolConfigFrom(argv, process.env, () => readFileSync50(0, "utf8"));
27577
+ const pool = poolConfigFrom(argv, process.env, () => readFileSync51(0, "utf8"));
27504
27578
  if (typeof pool === "string") {
27505
27579
  process.stderr.write(`crew pool-member: ${pool}
27506
27580
  `);
@@ -27738,6 +27812,34 @@ if (command === "passenger-sync-daemon") {
27738
27812
  };
27739
27813
  };
27740
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
+ }
27741
27843
  let cfg;
27742
27844
  let firstRun;
27743
27845
  let firstRunFromFlags = false;
@@ -27793,7 +27895,7 @@ if (command === "passenger-sync-daemon") {
27793
27895
  } else {
27794
27896
  const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
27795
27897
  const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
27796
- if (configless && !existsSync55(findConfigFile(CREW_HOME))) {
27898
+ if (configless && !existsSync56(findConfigFile(CREW_HOME))) {
27797
27899
  cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
27798
27900
  } else {
27799
27901
  cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
@@ -27803,12 +27905,20 @@ if (command === "passenger-sync-daemon") {
27803
27905
  if (e instanceof ConfigError) {
27804
27906
  process.stderr.write(`crew: ${e.message}
27805
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
+ }
27806
27916
  process.exit(2);
27807
27917
  }
27808
27918
  throw e;
27809
27919
  }
27810
27920
  if (command === "credential") {
27811
- 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"));
27812
27922
  process.stdout.write(r.out);
27813
27923
  process.stderr.write(r.err);
27814
27924
  process.exit(r.code);
@@ -27820,9 +27930,9 @@ if (command === "passenger-sync-daemon") {
27820
27930
  forges: cfg.ship.forges,
27821
27931
  stateDir: cfg.ship.stateDir,
27822
27932
  configFile: cfg.configFile,
27823
- readFile: (p) => readFileSync50(p, "utf8"),
27824
- writeFile: (p, t) => writeFileSync40(p, t),
27825
- stdin: () => readFileSync50(0, "utf8"),
27933
+ readFile: (p) => readFileSync51(p, "utf8"),
27934
+ writeFile: (p, t) => writeFileSync41(p, t),
27935
+ stdin: () => readFileSync51(0, "utf8"),
27826
27936
  env: process.env
27827
27937
  }
27828
27938
  );
@@ -27850,6 +27960,17 @@ if (command === "passenger-sync-daemon") {
27850
27960
  if (e instanceof ConfigError) {
27851
27961
  process.stderr.write(`crew: ${e.message}
27852
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
+ }
27853
27974
  process.exit(2);
27854
27975
  }
27855
27976
  throw e;
@@ -28145,8 +28266,8 @@ if (command === "passenger-sync-daemon") {
28145
28266
  }
28146
28267
  if (host === "linux" && hasSystemd) {
28147
28268
  const label = labelFor(CREW_HOME, "run");
28148
- const staleTimer = join57(homedir11(), ".config", "systemd", "user", `${label}.timer`);
28149
- if (existsSync55(staleTimer)) {
28269
+ const staleTimer = join58(homedir11(), ".config", "systemd", "user", `${label}.timer`);
28270
+ if (existsSync56(staleTimer)) {
28150
28271
  process.stdout.write(
28151
28272
  `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
28152
28273
  `
@@ -28154,7 +28275,7 @@ if (command === "passenger-sync-daemon") {
28154
28275
  if (!dryRun) {
28155
28276
  spawnSync13("systemctl", ["--user", "disable", "--now", `${label}.timer`], { cwd: CREW_HOME, env: withUserBusEnv() });
28156
28277
  try {
28157
- unlinkSync5(staleTimer);
28278
+ unlinkSync6(staleTimer);
28158
28279
  } catch {
28159
28280
  }
28160
28281
  }
@@ -28175,7 +28296,7 @@ if (command === "passenger-sync-daemon") {
28175
28296
  const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
28176
28297
  for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
28177
28298
  for (const r of doctorRepos) {
28178
- 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`);
28179
28300
  if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
28180
28301
  readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
28181
28302
  }
@@ -28202,7 +28323,7 @@ if (command === "passenger-sync-daemon") {
28202
28323
  }
28203
28324
  async function doctorFix(o) {
28204
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))));
28205
- const unitExists = (p) => existsSync55(p);
28326
+ const unitExists = (p) => existsSync56(p);
28206
28327
  const crontab = o.host === "linux" ? spawnSync13("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
28207
28328
  const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
28208
28329
  const plan = planFix({ routes, schedulerAbsent, host: o.host });
@@ -28219,7 +28340,7 @@ if (command === "passenger-sync-daemon") {
28219
28340
  for (const a of plan.actions) {
28220
28341
  if (a.kind === "enable") {
28221
28342
  if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
28222
- writeFileSync40(cfg.configFile, planEnable(readFileSync50(cfg.configFile, "utf8"), a.route));
28343
+ writeFileSync41(cfg.configFile, planEnable(readFileSync51(cfg.configFile, "utf8"), a.route));
28223
28344
  enabledSound.add(a.route);
28224
28345
  changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
28225
28346
  } else {
@@ -28448,7 +28569,7 @@ ${changed2.map((c) => ` - ${c}
28448
28569
  harnessBin: "claude",
28449
28570
  ...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
28450
28571
  },
28451
- policyFile: join57(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
28572
+ policyFile: join58(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
28452
28573
  repo: mirror,
28453
28574
  origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
28454
28575
  base: effective.branch.base,
@@ -29536,11 +29657,20 @@ ${cu.tail.trimEnd()}
29536
29657
  const daemonRoutes = fleetWide ? cfg.routes.filter((r) => r.enabled) : [route2];
29537
29658
  if (!daemonRoutes.length) {
29538
29659
  emit.error("no enabled routes \u2014 nothing for the daemon to serve");
29539
- 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
+ });
29540
29669
  }
29541
29670
  const primary = daemonRoutes[0];
29542
29671
  const sandboxCachePasses = /* @__PURE__ */ new Map();
29543
29672
  const servable = [];
29673
+ const unservable = [];
29544
29674
  for (const r of daemonRoutes) {
29545
29675
  const pass = cfg.ship.runner === "sandbox" ? buildSandboxCachePass(r, cfg.ship, state, emit.forRoute(r.route)) : void 0;
29546
29676
  if (pass) sandboxCachePasses.set(r.route, pass);
@@ -29553,10 +29683,49 @@ ${cu.tail.trimEnd()}
29553
29683
  }
29554
29684
  }
29555
29685
  if (await anyRepoServable(r, true)) servable.push(r);
29556
- 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
+ });
29557
29702
  }
29558
- if (!servable.length) process.exit(1);
29559
- const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join57(CREW_HOME, "src"), join57(CREW_HOME, "dist"), join57(CREW_HOME, "bin")];
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
+ });
29727
+ }
29728
+ const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join58(CREW_HOME, "src"), join58(CREW_HOME, "dist"), join58(CREW_HOME, "bin")];
29560
29729
  const configPaths = daemonConfigPaths(cfg);
29561
29730
  watchPaths.push(...configPaths);
29562
29731
  noteDaemonStarted(cfg.ship.stateDir);
@@ -29680,6 +29849,7 @@ ${cu.tail.trimEnd()}
29680
29849
  ),
29681
29850
  checkStale: makeStaleChecker(watchPaths, { reloadSentinel: reloadSentinelFor(cfg.ship.stateDir) }),
29682
29851
  onPass: (result) => {
29852
+ clearStartFailure(state, cfg.ship.stateDir);
29683
29853
  if (!sandboxBuilding && !diskFullStop(state)) {
29684
29854
  sandboxBuilding = true;
29685
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(() => {
@@ -29873,10 +30043,10 @@ ${cu.tail.trimEnd()}
29873
30043
  `);
29874
30044
  if (!dryRun) {
29875
30045
  const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
29876
- const raw = existsSync55(resolvedPath) ? JSON.parse(readFileSync50(resolvedPath, "utf8")) : {};
30046
+ const raw = existsSync56(resolvedPath) ? JSON.parse(readFileSync51(resolvedPath, "utf8")) : {};
29877
30047
  raw.agentSkills = result.agentSkills;
29878
- mkdirSync40(dirOf2(resolvedPath), { recursive: true });
29879
- writeFileSync40(resolvedPath, `${JSON.stringify(raw, null, 2)}
30048
+ mkdirSync41(dirOf2(resolvedPath), { recursive: true });
30049
+ writeFileSync41(resolvedPath, `${JSON.stringify(raw, null, 2)}
29880
30050
  `);
29881
30051
  }
29882
30052
  if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
@@ -29899,7 +30069,7 @@ ${cu.tail.trimEnd()}
29899
30069
  throw e;
29900
30070
  }
29901
30071
  const oldName = cfg.ship.name;
29902
- writeFileSync40(cfg.configFile, setShipNameInYaml(readFileSync50(cfg.configFile, "utf8"), newName));
30072
+ writeFileSync41(cfg.configFile, setShipNameInYaml(readFileSync51(cfg.configFile, "utf8"), newName));
29903
30073
  cfg.ship.name = newName;
29904
30074
  let renameMachineId;
29905
30075
  try {
@@ -29946,14 +30116,14 @@ ${cu.tail.trimEnd()}
29946
30116
  process.exit(2);
29947
30117
  };
29948
30118
  if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
29949
- const configText = readFileSync50(cfg.configFile, "utf8");
30119
+ const configText = readFileSync51(cfg.configFile, "utf8");
29950
30120
  if (sub === "check") {
29951
30121
  try {
29952
30122
  const routeArg = value("route") ?? positional[2];
29953
30123
  const found = cfg.routes.find((r) => r.route === routeArg);
29954
30124
  if (!found) throw new ReposError(`no route "${routeArg}" in the config (have: ${cfg.routes.map((r) => r.route).join(", ") || "none"})`);
29955
30125
  const named2 = value("route") ? void 0 : positional[3];
29956
- 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] ?? ".");
29957
30127
  const target = reposOf(found).find((t) => resolvePath(t.dir) === dir || t.name === named2);
29958
30128
  const o = target ? found.repoOverrides[target.name] : void 0;
29959
30129
  runReposCheck(dir, {
@@ -29977,9 +30147,9 @@ ${cu.tail.trimEnd()}
29977
30147
  if (sub === "hooks") {
29978
30148
  try {
29979
30149
  const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
29980
- const dir = repoDirOf(configText, dirname35(cfg.configFile), a.route, a.name);
29981
- if (!existsSync55(dir)) throw new ReposError(`${dir} does not exist on disk`);
29982
- 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) => {
29983
30153
  try {
29984
30154
  return readdirSync20(resolvePath(dir, r));
29985
30155
  } catch {
@@ -29987,7 +30157,7 @@ ${cu.tail.trimEnd()}
29987
30157
  }
29988
30158
  }, read: (r) => {
29989
30159
  try {
29990
- return readFileSync50(resolvePath(dir, r), "utf8");
30160
+ return readFileSync51(resolvePath(dir, r), "utf8");
29991
30161
  } catch {
29992
30162
  return void 0;
29993
30163
  }
@@ -30029,19 +30199,19 @@ ${cu.tail.trimEnd()}
30029
30199
  let cleared;
30030
30200
  if (clear2) {
30031
30201
  const plan = clearRouteHooks(configText, a.route, a.name);
30032
- if (plan.removed.length > 0) writeFileSync40(cfg.configFile, plan.text);
30202
+ if (plan.removed.length > 0) writeFileSync41(cfg.configFile, plan.text);
30033
30203
  cleared = { file: cfg.configFile, removed: plan.removed };
30034
30204
  }
30035
30205
  if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
30036
30206
  if (write === "route") {
30037
30207
  const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
30038
- writeFileSync40(cfg.configFile, plan.text);
30208
+ writeFileSync41(cfg.configFile, plan.text);
30039
30209
  written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
30040
30210
  } else if (write === "repo") {
30041
30211
  const have = existingRepoConfig(files);
30042
30212
  if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
30043
30213
  const file = resolvePath(dir, ".crew.yaml");
30044
- writeFileSync40(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
30214
+ writeFileSync41(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
30045
30215
  written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
30046
30216
  }
30047
30217
  if (flag("json")) {
@@ -30097,7 +30267,7 @@ ${cu.tail.trimEnd()}
30097
30267
  if (sub === "list" && !routeName) usage2();
30098
30268
  if (sub === "add") {
30099
30269
  try {
30100
- 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()))));
30101
30271
  routeName = a.route;
30102
30272
  addPath = a.path;
30103
30273
  addName = a.name;
@@ -30127,7 +30297,7 @@ ${cu.tail.trimEnd()}
30127
30297
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
30128
30298
  if (sub === "list" || sub === "add") {
30129
30299
  const liveRoute = cfg.routes.find((r) => r.route === routeName);
30130
- if (liveRoute?.resolved?.reposModelId && existsSync55(resolvedFile) && !dryRun) {
30300
+ if (liveRoute?.resolved?.reposModelId && existsSync56(resolvedFile) && !dryRun) {
30131
30301
  try {
30132
30302
  await hydrateApiKeys([liveRoute]);
30133
30303
  persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
@@ -30136,16 +30306,16 @@ ${cu.tail.trimEnd()}
30136
30306
  }
30137
30307
  }
30138
30308
  let resolvedRemotes;
30139
- if (existsSync55(resolvedFile)) {
30309
+ if (existsSync56(resolvedFile)) {
30140
30310
  try {
30141
- resolvedRemotes = JSON.parse(readFileSync50(resolvedFile, "utf8"));
30311
+ resolvedRemotes = JSON.parse(readFileSync51(resolvedFile, "utf8"));
30142
30312
  } catch {
30143
30313
  }
30144
30314
  }
30145
30315
  const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
30146
30316
  const text2 = configText;
30147
- const base = dirname35(cfg.configFile);
30148
- const isCheckout = (d) => existsSync55(`${d}/.git`);
30317
+ const base = dirname36(cfg.configFile);
30318
+ const isCheckout = (d) => existsSync56(`${d}/.git`);
30149
30319
  try {
30150
30320
  if (sub === "list") {
30151
30321
  if (flag("json")) {
@@ -30155,12 +30325,12 @@ ${cu.tail.trimEnd()}
30155
30325
  base,
30156
30326
  resolved: resolvedRemotes,
30157
30327
  originOf,
30158
- exists: (d) => existsSync55(d),
30328
+ exists: (d) => existsSync56(d),
30159
30329
  isCheckout,
30160
30330
  repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f) => {
30161
30331
  try {
30162
30332
  const path = resolvePath(d, f);
30163
- return Object.keys(parseRepoConfig(readFileSync50(path, "utf8"), path).hooks).length > 0;
30333
+ return Object.keys(parseRepoConfig(readFileSync51(path, "utf8"), path).hooks).length > 0;
30164
30334
  } catch {
30165
30335
  return false;
30166
30336
  }
@@ -30177,7 +30347,7 @@ ${cu.tail.trimEnd()}
30177
30347
  for (const r of repos) {
30178
30348
  const origin2 = originOf(r.dir);
30179
30349
  const row = matchRepoName(origin2, resolvedRemotes);
30180
- 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)"}`;
30181
30351
  process.stdout.write(`${r.name} ${r.dir} ${note}
30182
30352
  `);
30183
30353
  }
@@ -30189,9 +30359,9 @@ ${cu.tail.trimEnd()}
30189
30359
  ` : `${human}
30190
30360
  `);
30191
30361
  const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
30192
- 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)) {
30193
30363
  throw new ReposError(
30194
- 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`
30195
30365
  );
30196
30366
  }
30197
30367
  if (dryRun) {
@@ -30209,14 +30379,14 @@ ${cu.tail.trimEnd()}
30209
30379
  throw new ReposError(`${e.message}${authHint}
30210
30380
  crew.yaml was not changed`);
30211
30381
  }
30212
- writeFileSync40(cfg.configFile, plan2.text);
30382
+ writeFileSync41(cfg.configFile, plan2.text);
30213
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:
30214
30384
  `);
30215
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}`);
30216
30386
  break;
30217
30387
  }
30218
30388
  const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
30219
- const top = existsSync55(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
30389
+ const top = existsSync56(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
30220
30390
  if (!top) throw new ReposError(`${target} is not a git checkout`);
30221
30391
  const origin = originOf(top);
30222
30392
  const plan = planRepoAdd({
@@ -30268,15 +30438,15 @@ ${cu.tail.trimEnd()}
30268
30438
  const created = await rowTracker.createRepoRow(rowPayload);
30269
30439
  process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
30270
30440
  `);
30271
- if (existsSync55(resolvedFile)) {
30272
- const raw = JSON.parse(readFileSync50(resolvedFile, "utf8"));
30441
+ if (existsSync56(resolvedFile)) {
30442
+ const raw = JSON.parse(readFileSync51(resolvedFile, "utf8"));
30273
30443
  raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
30274
30444
  raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
30275
- writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
30445
+ writeFileSync41(resolvedFile, `${JSON.stringify(raw, null, 2)}
30276
30446
  `);
30277
30447
  }
30278
30448
  }
30279
- writeFileSync40(cfg.configFile, plan.text);
30449
+ writeFileSync41(cfg.configFile, plan.text);
30280
30450
  process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
30281
30451
  `);
30282
30452
  } catch (e) {
@@ -30651,7 +30821,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30651
30821
  process.exit(2);
30652
30822
  }
30653
30823
  if (found.shipNameAdopted && !dryRun) {
30654
- writeFileSync40(cfg.configFile, setShipNameInYaml(readFileSync50(cfg.configFile, "utf8"), found.shipNameAdopted));
30824
+ writeFileSync41(cfg.configFile, setShipNameInYaml(readFileSync51(cfg.configFile, "utf8"), found.shipNameAdopted));
30655
30825
  cfg.ship.name = found.shipNameAdopted;
30656
30826
  }
30657
30827
  if (found.shipRow) {
@@ -30694,10 +30864,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30694
30864
  }
30695
30865
  }
30696
30866
  let previous;
30697
- const hadPreviousFile = existsSync55(resolvedPath);
30867
+ const hadPreviousFile = existsSync56(resolvedPath);
30698
30868
  if (hadPreviousFile) {
30699
30869
  try {
30700
- previous = JSON.parse(readFileSync50(resolvedPath, "utf8"));
30870
+ previous = JSON.parse(readFileSync51(resolvedPath, "utf8"));
30701
30871
  } catch {
30702
30872
  }
30703
30873
  }
@@ -30827,10 +30997,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30827
30997
  process.stderr.write(`(dry run) would write resolved ids to ${resolvedPath}
30828
30998
  `);
30829
30999
  } else {
30830
- mkdirSync40(dirname35(resolvedPath), { recursive: true });
31000
+ mkdirSync41(dirname36(resolvedPath), { recursive: true });
30831
31001
  if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
30832
31002
  const tmpPath = `${resolvedPath}.tmp${process.pid}`;
30833
- writeFileSync40(tmpPath, `${JSON.stringify(resolved, null, 2)}
31003
+ writeFileSync41(tmpPath, `${JSON.stringify(resolved, null, 2)}
30834
31004
  `);
30835
31005
  renameSync7(tmpPath, resolvedPath);
30836
31006
  process.stderr.write(`Resolved ids written to ${resolvedPath}
@@ -30876,8 +31046,8 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30876
31046
  process.stderr.write(`(dry run) would write the minted API key to ${apiKeyFile}
30877
31047
  `);
30878
31048
  } else {
30879
- mkdirSync40(dirname35(apiKeyFile), { recursive: true });
30880
- writeFileSync40(apiKeyFile, `${apiKeyVar}=${apiKey}
31049
+ mkdirSync41(dirname36(apiKeyFile), { recursive: true });
31050
+ writeFileSync41(apiKeyFile, `${apiKeyVar}=${apiKey}
30881
31051
  `, { mode: 384 });
30882
31052
  process.stderr.write(`API key written to ${apiKeyFile}
30883
31053
  `);
@@ -31592,10 +31762,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
31592
31762
  startupSeconds: cfg.ship.intelStartupSeconds,
31593
31763
  prepare: async (path) => {
31594
31764
  for (const f of repoWt.config.worktrees.copy) {
31595
- const src = join57(repoWt.dir, f);
31596
- if (!existsSync55(src) || existsSync55(join57(path, f))) continue;
31597
- mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
31598
- 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));
31599
31769
  }
31600
31770
  const setup = repoWt.config.hooks.setup;
31601
31771
  return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
@@ -31821,7 +31991,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
31821
31991
  const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
31822
31992
  const resumed = await runPeriscopeResume({
31823
31993
  find: async () => hit && { row: hit.row, tag: hit.tag },
31824
- worktreeExists: (p) => existsSync55(p),
31994
+ worktreeExists: (p) => existsSync56(p),
31825
31995
  prepareDropFile,
31826
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" }),
31827
31997
  relay: hit && previewRelayFor(hit.route) && {
@@ -31924,10 +32094,10 @@ ${where.join("\n")}`);
31924
32094
  },
31925
32095
  prepare: async (path) => {
31926
32096
  for (const f of repoP.config.worktrees.copy) {
31927
- const src = join57(repoP.dir, f);
31928
- if (!existsSync55(src)) continue;
31929
- mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
31930
- 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));
31931
32101
  }
31932
32102
  const setup = repoP.config.hooks.setup;
31933
32103
  return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
@@ -32239,7 +32409,7 @@ ${where.join("\n")}`);
32239
32409
  };
32240
32410
  const droppedRoutes = [];
32241
32411
  try {
32242
- const rawCfg = parseYaml3(readFileSync50(cfg.configFile, "utf8"));
32412
+ const rawCfg = parseYaml3(readFileSync51(cfg.configFile, "utf8"));
32243
32413
  for (const r of rawCfg?.routes ?? []) {
32244
32414
  if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
32245
32415
  try {
@@ -32303,8 +32473,8 @@ ${where.join("\n")}`);
32303
32473
  process.stdout.write("crew reload: no daemon unit is running \u2014 nothing to reload (the next run reads crew.yaml fresh)\n");
32304
32474
  break;
32305
32475
  }
32306
- mkdirSync40(cfg.ship.stateDir, { recursive: true });
32307
- writeFileSync40(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
32476
+ mkdirSync41(cfg.ship.stateDir, { recursive: true });
32477
+ writeFileSync41(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
32308
32478
  `);
32309
32479
  process.stdout.write(
32310
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"
@@ -32369,7 +32539,7 @@ ${where.join("\n")}`);
32369
32539
  }
32370
32540
  case "log": {
32371
32541
  try {
32372
- const text2 = readFileSync50(cfg.ship.logFile, "utf8").split("\n");
32542
+ const text2 = readFileSync51(cfg.ship.logFile, "utf8").split("\n");
32373
32543
  process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
32374
32544
  `);
32375
32545
  } catch {
@@ -32392,8 +32562,8 @@ ${where.join("\n")}`);
32392
32562
  };
32393
32563
  if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
32394
32564
  const tracker = new Tracker(route2, cfg.ship);
32395
- const configText = readFileSync50(cfg.configFile, "utf8");
32396
- const cfgBase = dirname35(cfg.configFile);
32565
+ const configText = readFileSync51(cfg.configFile, "utf8");
32566
+ const cfgBase = dirname36(cfg.configFile);
32397
32567
  const configured2 = configuredRepos(configText, route2.route, cfgBase);
32398
32568
  const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
32399
32569
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, route2.route);
@@ -32421,7 +32591,7 @@ ${where.join("\n")}`);
32421
32591
  }
32422
32592
  if (configured2.some((r) => r.dir === dir)) {
32423
32593
  try {
32424
- writeFileSync40(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
32594
+ writeFileSync41(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
32425
32595
  } catch (e) {
32426
32596
  if (e instanceof ReposError) fail2(e.message);
32427
32597
  throw e;
@@ -32429,29 +32599,29 @@ ${where.join("\n")}`);
32429
32599
  }
32430
32600
  if (row) {
32431
32601
  await tracker.deleteRepoRow(row.id);
32432
- if (existsSync55(resolvedFile)) {
32433
- const raw = JSON.parse(readFileSync50(resolvedFile, "utf8"));
32602
+ if (existsSync56(resolvedFile)) {
32603
+ const raw = JSON.parse(readFileSync51(resolvedFile, "utf8"));
32434
32604
  if (raw.repoNames) delete raw.repoNames[row.id];
32435
32605
  if (raw.repoRemotes) delete raw.repoRemotes[row.id];
32436
- writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
32606
+ writeFileSync41(resolvedFile, `${JSON.stringify(raw, null, 2)}
32437
32607
  `);
32438
32608
  }
32439
32609
  }
32440
- 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 });
32441
32611
  say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
32442
32612
  break;
32443
32613
  }
32444
32614
  const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
32445
- const fresh = !existsSync55(join57(dir, ".git"));
32446
- 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`);
32447
32617
  if (dryRun) {
32448
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`);
32449
32619
  break;
32450
32620
  }
32451
32621
  if (fresh) {
32452
- mkdirSync40(dir, { recursive: true });
32453
- writeFileSync40(join57(dir, "README.md"), SAMPLE_README);
32454
- 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);
32455
32625
  const g = (...a) => {
32456
32626
  const r = spawnSync13("git", a, { cwd: dir, encoding: "utf8" });
32457
32627
  if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
@@ -32469,17 +32639,17 @@ ${where.join("\n")}`);
32469
32639
  spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
32470
32640
  });
32471
32641
  repoId = (await tracker.createRepoRow(payload)).id;
32472
- if (existsSync55(resolvedFile)) {
32473
- const raw = JSON.parse(readFileSync50(resolvedFile, "utf8"));
32642
+ if (existsSync56(resolvedFile)) {
32643
+ const raw = JSON.parse(readFileSync51(resolvedFile, "utf8"));
32474
32644
  raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
32475
32645
  raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
32476
- writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
32646
+ writeFileSync41(resolvedFile, `${JSON.stringify(raw, null, 2)}
32477
32647
  `);
32478
32648
  }
32479
32649
  }
32480
32650
  if (!configured2.some((r) => r.dir === dir)) {
32481
32651
  try {
32482
- 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);
32483
32653
  } catch (e) {
32484
32654
  if (e instanceof ReposError) fail2(e.message);
32485
32655
  throw e;
@@ -32592,7 +32762,30 @@ ${where.join("\n")}`);
32592
32762
  case "status": {
32593
32763
  const fairness = state.fairness(route2.route);
32594
32764
  const waiting = fairness.waiting();
32595
- 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
+ }
32596
32789
  const shipRows = await statusTracker.shipRows();
32597
32790
  const engagedTicketIds = shipRows.map((s) => s.engaged_ticket_id).filter((id) => !!id);
32598
32791
  const engagedTickets = engagedTicketIds.length ? await statusTracker.ticketsByIds(engagedTicketIds) : [];
@@ -32823,7 +33016,7 @@ watermark: ${state.watermark()}
32823
33016
  plan,
32824
33017
  label,
32825
33018
  uid: process.getuid?.() ?? 0,
32826
- system: plan.mechanism === "systemd" && existsSync55(systemUnitPathFor(label)),
33019
+ system: plan.mechanism === "systemd" && existsSync56(systemUnitPathFor(label)),
32827
33020
  stamp: readDaemonStamp(cfg.ship.stateDir)
32828
33021
  });
32829
33022
  })();
@@ -32839,7 +33032,7 @@ watermark: ${state.watermark()}
32839
33032
  }
32840
33033
  for (const r of repos) {
32841
33034
  const remote = r.config.branch.remote;
32842
- if (existsSync55(r.dir)) {
33035
+ if (existsSync56(r.dir)) {
32843
33036
  pushAuth.push({
32844
33037
  route: c.route,
32845
33038
  repo: r.name,
@@ -32921,7 +33114,7 @@ watermark: ${state.watermark()}
32921
33114
  if (dp) problems.push(dp);
32922
33115
  else passed++;
32923
33116
  }
32924
- const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync55, userInfo2().username);
33117
+ const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync56, userInfo2().username);
32925
33118
  if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
32926
33119
  if (!flag("offline")) {
32927
33120
  const shipKind = await doctorShipKind(route2, cfg.ship);
@@ -32986,7 +33179,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
32986
33179
  }
32987
33180
  try {
32988
33181
  const evFile = eventFileFor(cfg.ship.stateDir);
32989
- const evSize = existsSync55(evFile) ? statSync17(evFile).size : 0;
33182
+ const evSize = existsSync56(evFile) ? statSync17(evFile).size : 0;
32990
33183
  process.stdout.write(
32991
33184
  evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
32992
33185
  ` : "events log: ok\n"
@@ -32997,7 +33190,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
32997
33190
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
32998
33191
  const abandons = unitAbandonsAgents(unitPlan, (p) => {
32999
33192
  try {
33000
- return readFileSync50(p, "utf8");
33193
+ return readFileSync51(p, "utf8");
33001
33194
  } catch {
33002
33195
  return null;
33003
33196
  }
@@ -33012,7 +33205,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
33012
33205
  const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
33013
33206
  const keeps = unitAbandonsAgents(pPlan, (p) => {
33014
33207
  try {
33015
- return readFileSync50(p, "utf8");
33208
+ return readFileSync51(p, "utf8");
33016
33209
  } catch {
33017
33210
  return null;
33018
33211
  }
@@ -33026,7 +33219,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
33026
33219
  if (host === "linux" && detectSystemd()) {
33027
33220
  const ctl = planDaemonControl(CREW_HOME, host, true);
33028
33221
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
33029
- if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync55(p))) {
33222
+ if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync56(p))) {
33030
33223
  const st = spawnSync13(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
33031
33224
  if (!st.error && st.status !== 0) {
33032
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");