@tablation/crew 0.169.6 → 0.171.0

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 +388 -191
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -17891,7 +17891,7 @@ async function runSelfLaunchCheck(own, spawnFn = spawnChild, launch = selfLaunch
17891
17891
  }
17892
17892
 
17893
17893
  // src/cli.ts
17894
- import { resolve as resolve8, dirname as dirname38, join as join67, basename as basename17 } from "path";
17894
+ import { resolve as resolve8, dirname as dirname39, join as join68, basename as basename18 } from "path";
17895
17895
  import { fileURLToPath as fileURLToPath2 } from "url";
17896
17896
  import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
17897
17897
  import { spawnSync as spawnSync15 } from "child_process";
@@ -26861,6 +26861,98 @@ function fallbackStateDir(configFile) {
26861
26861
  return join55(dirname30(configFile), "state");
26862
26862
  }
26863
26863
 
26864
+ // src/routes-available.ts
26865
+ var lower = (s) => s.trim().toLowerCase();
26866
+ async function buildRoutesAvailable(routes, deps) {
26867
+ const doFetch = deps.fetch ?? fetch;
26868
+ const hosts = /* @__PURE__ */ new Map();
26869
+ for (const r of routes) {
26870
+ const h = deps.hostOf(r.baseUrl);
26871
+ hosts.set(h, [...hosts.get(h) ?? [], r]);
26872
+ }
26873
+ const existing = new Set(routes.map((r) => {
26874
+ const [ws, proj] = splitRoute(r.route);
26875
+ return `${deps.hostOf(r.baseUrl)}|${lower(ws)}|${lower(proj)}`;
26876
+ }));
26877
+ const get2 = (r, key, path) => doFetch(`${r.baseUrl.replace(/\/+$/, "")}/api${path}`, {
26878
+ headers: { Authorization: `Bearer ${key}`, "User-Agent": deps.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" }
26879
+ });
26880
+ return Promise.all([...hosts].map(async ([host, hostRoutes]) => {
26881
+ let keyed = 0;
26882
+ for (const r of hostRoutes) {
26883
+ let key;
26884
+ try {
26885
+ key = resolveApiKey(r);
26886
+ } catch {
26887
+ continue;
26888
+ }
26889
+ keyed++;
26890
+ let res;
26891
+ try {
26892
+ res = await get2(r, key, "/auth/my-tracker-apps");
26893
+ } catch (e) {
26894
+ return { host, error: e.message, reason: "failed" };
26895
+ }
26896
+ if (res.status === 401 || res.status === 403) continue;
26897
+ if (res.status === 404) return { host, error: "this Tablation host does not offer the tracker app list yet", reason: "unsupported" };
26898
+ if (!res.ok) return { host, error: `/auth/my-tracker-apps answered HTTP ${res.status}`, reason: "failed" };
26899
+ const apps = await res.json();
26900
+ const list = Array.isArray(apps) ? apps : apps.apps ?? [];
26901
+ let email = null;
26902
+ try {
26903
+ const me = await get2(r, key, "/auth/me");
26904
+ if (me.ok) email = (await me.json()).email ?? null;
26905
+ } catch {
26906
+ }
26907
+ const signIn = /* @__PURE__ */ new Map();
26908
+ const out = [];
26909
+ for (const a of list) {
26910
+ const address = a.workspace.path || a.workspace.slug;
26911
+ if (existing.has(`${host}|${lower(address)}|${lower(a.project.slug)}`)) continue;
26912
+ if (!signIn.has(address)) {
26913
+ const sibling = siblingRouteKey(hostRoutes, host, (w) => lower(w) === lower(address), deps.hostOf);
26914
+ signIn.set(address, !sibling && !await deps.holdsCredential(host, address).catch(() => false));
26915
+ }
26916
+ out.push({
26917
+ route: `${address}/${a.project.slug}`,
26918
+ workspace: { address, name: a.workspace.name, role: a.workspace.role },
26919
+ project: { slug: a.project.slug, name: a.project.name },
26920
+ accepted: a.interfaceVersion === null || versionAccepted(a.interfaceVersion),
26921
+ needsSignIn: signIn.get(address)
26922
+ });
26923
+ }
26924
+ return { host, identity: { email }, routes: out };
26925
+ }
26926
+ return keyed === 0 ? { host, error: "no route on this host has a usable key", reason: "no_key" } : { host, error: "every key on this host was rejected", reason: "rejected" };
26927
+ }));
26928
+ }
26929
+ function formatRoutesAvailable(report, hadRoutes) {
26930
+ if (!hadRoutes) return "No routes are configured, so there is nothing to list from. `crew connect` is the first-run path.\n";
26931
+ const lines2 = [];
26932
+ let any = false;
26933
+ for (const h of report) {
26934
+ if ("error" in h) {
26935
+ lines2.push(`${h.host}: ${h.error}`);
26936
+ continue;
26937
+ }
26938
+ if (report.length > 1) lines2.push(`${h.host}${h.identity.email ? ` (${h.identity.email})` : ""}`);
26939
+ const byWs = /* @__PURE__ */ new Map();
26940
+ for (const r of h.routes) byWs.set(r.workspace.address, [...byWs.get(r.workspace.address) ?? [], r]);
26941
+ for (const [, rs] of [...byWs].sort((a, b) => a[1][0].workspace.name.localeCompare(b[1][0].workspace.name))) {
26942
+ any = true;
26943
+ lines2.push(rs[0].workspace.name);
26944
+ for (const r of rs.sort((a, b) => a.project.name.localeCompare(b.project.name))) {
26945
+ const marks = [!r.accepted ? `needs a newer crew (accepts ${acceptedLabel()})` : "", r.needsSignIn ? "sign-in needed" : ""].filter(Boolean);
26946
+ lines2.push(` ${r.project.name} ${r.route}${marks.length ? ` [${marks.join("; ")}]` : ""}`);
26947
+ }
26948
+ }
26949
+ }
26950
+ if (!any && report.some((h) => !("error" in h))) lines2.push("Every tracker app you can reach is already routed on this machine.");
26951
+ if (any) lines2.push("", "Add one with `crew connect <route>`.");
26952
+ return `${lines2.join("\n")}
26953
+ `;
26954
+ }
26955
+
26864
26956
  // src/projects-cmd.ts
26865
26957
  async function buildProjectsReport(routes, open2) {
26866
26958
  return Promise.all(routes.map(async (r) => {
@@ -29276,6 +29368,73 @@ function planSampleTicket(i) {
29276
29368
  };
29277
29369
  }
29278
29370
 
29371
+ // src/connect-append.ts
29372
+ import { chmodSync as chmodSync4, existsSync as existsSync54, readFileSync as readFileSync55, renameSync as renameSync10, statSync as statSync16, unlinkSync as unlinkSync5, writeFileSync as writeFileSync43 } from "fs";
29373
+ import { basename as basename14, dirname as dirname34, join as join59 } from "path";
29374
+ import { isMap as isMap4, isSeq as isSeq2, parseDocument as parseDocument7 } from "yaml";
29375
+ function appendRouteBlock(config, block) {
29376
+ const doc = parseDocument7(config);
29377
+ if (doc.errors.length > 0) return { ok: false, reason: "crew.yaml is not valid YAML" };
29378
+ if (!isMap4(doc.contents)) return { ok: false, reason: "crew.yaml has no routes: list" };
29379
+ const routes = doc.contents.get("routes", true);
29380
+ if (!isSeq2(routes) || !routes.range) return { ok: false, reason: "crew.yaml has no routes: list to extend" };
29381
+ const body = block.replace(/\n+$/, "");
29382
+ if (routes.items.length === 0) {
29383
+ if (!routes.flow) return { ok: false, reason: "routes: is written in a form that cannot be extended" };
29384
+ let start = routes.range[0];
29385
+ while (start > 0 && (config[start - 1] === " " || config[start - 1] === " ")) start--;
29386
+ return { ok: true, text: `${config.slice(0, start)}
29387
+ ${body}${config.slice(routes.range[1])}` };
29388
+ }
29389
+ if (routes.flow) return { ok: false, reason: "routes: is written as an inline list that cannot be extended" };
29390
+ const first = routes.items[0];
29391
+ if (!isMap4(first) || !first.range) return { ok: false, reason: "routes: holds an entry that is not a mapping" };
29392
+ const lineStart = config.lastIndexOf("\n", first.range[0] - 1) + 1;
29393
+ const dashCol = config.slice(lineStart, first.range[0]).indexOf("-");
29394
+ if (dashCol < 0) return { ok: false, reason: "routes: is written in a form that cannot be extended" };
29395
+ const shift = dashCol - 2;
29396
+ const lines2 = body.split("\n").map((l) => shift >= 0 ? " ".repeat(shift) + l : l.slice(Math.min(-shift, l.length - l.trimStart().length)));
29397
+ const indented = lines2.join("\n");
29398
+ const lastEnd = routes.range[1];
29399
+ let eol = config.indexOf("\n", Math.max(0, lastEnd - 1));
29400
+ if (eol < 0) return { ok: true, text: `${config}
29401
+ ${indented}
29402
+ ` };
29403
+ eol += 1;
29404
+ return { ok: true, text: `${config.slice(0, eol)}${indented}
29405
+ ${config.slice(eol)}` };
29406
+ }
29407
+ function replaceFileKeepingMode(path, text2) {
29408
+ const mode = statSync16(path).mode & 4095;
29409
+ const tmp = join59(dirname34(path), `.${basename14(path)}.${process.pid}.tmp`);
29410
+ try {
29411
+ writeFileSync43(tmp, text2, { mode });
29412
+ chmodSync4(tmp, mode);
29413
+ renameSync10(tmp, path);
29414
+ } catch (e) {
29415
+ if (existsSync54(tmp)) unlinkSync5(tmp);
29416
+ throw e;
29417
+ }
29418
+ }
29419
+ function planAppendToConfig(crewHome, configFile, route2, block, keyPersisted) {
29420
+ if (!keyPersisted) return { ok: false, reason: "no stored key to name" };
29421
+ let current;
29422
+ try {
29423
+ current = readFileSync55(configFile, "utf8");
29424
+ } catch (e) {
29425
+ return { ok: false, reason: `could not read the file: ${e.message}` };
29426
+ }
29427
+ const r = appendRouteBlock(current, block);
29428
+ if (!r.ok) return r;
29429
+ try {
29430
+ const loaded = loadConfig(crewHome, configFile, { text: r.text });
29431
+ if (!loaded.routes.some((x) => x.route === route2)) return { ok: false, reason: "the config loader dropped the new route" };
29432
+ } catch (e) {
29433
+ return { ok: false, reason: `the config loader rejected the result: ${e.message.split("\n")[0]}` };
29434
+ }
29435
+ return r;
29436
+ }
29437
+
29279
29438
  // src/snapshot-staleness.ts
29280
29439
  var SNAPSHOT_TABLES = [
29281
29440
  { key: "periscopesModelId", name: "Periscopes" },
@@ -29501,8 +29660,8 @@ function fixPhaseNothingToOffer(o) {
29501
29660
  }
29502
29661
 
29503
29662
  // src/worktree-sweep.ts
29504
- import { existsSync as existsSync54, readFileSync as readFileSync55, readdirSync as readdirSync16 } from "fs";
29505
- import { basename as basename14, dirname as dirname34, join as join59, resolve as resolve6 } from "path";
29663
+ import { existsSync as existsSync55, readFileSync as readFileSync56, readdirSync as readdirSync16 } from "fs";
29664
+ import { basename as basename15, dirname as dirname35, join as join60, resolve as resolve6 } from "path";
29506
29665
  function planWorktreeSweep(target, tickets, contract) {
29507
29666
  const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
29508
29667
  const verified = contract.statuses.verified;
@@ -29543,7 +29702,7 @@ function ticketForWorktree(w, byNumber, contract) {
29543
29702
  const t = num2 ? byNumber.get(num2) : void 0;
29544
29703
  if (t && ticketStems(t).has(stem)) return t;
29545
29704
  }
29546
- const dir = basename14(w.path);
29705
+ const dir = basename15(w.path);
29547
29706
  const m = DIR_NUMBER.exec(dir);
29548
29707
  if (m && byNumber.has(m[1])) return byNumber.get(m[1]);
29549
29708
  if (!w.branch) {
@@ -29559,15 +29718,15 @@ function worktreeTicketNumbers(target) {
29559
29718
  const n = /-(\d+)$/.exec(BRANCH_STEM.exec(w.branch)?.[1] ?? "")?.[1];
29560
29719
  if (n) nums.add(n);
29561
29720
  }
29562
- const m = DIR_NUMBER_SUFFIXED.exec(basename14(w.path));
29721
+ const m = DIR_NUMBER_SUFFIXED.exec(basename15(w.path));
29563
29722
  if (m) nums.add(m[1]);
29564
29723
  }
29565
29724
  for (const d of siblingWorktreeDirs(target)) nums.add(d.number);
29566
29725
  return [...nums];
29567
29726
  }
29568
29727
  function siblingWorktreeDirs(target) {
29569
- const parent = dirname34(target.dir.replace(/[/\\]+$/, ""));
29570
- const stem = `${basename14(target.dir.replace(/[/\\]+$/, ""))}-`;
29728
+ const parent = dirname35(target.dir.replace(/[/\\]+$/, ""));
29729
+ const stem = `${basename15(target.dir.replace(/[/\\]+$/, ""))}-`;
29571
29730
  const registered = new Set(worktrees(target.dir).map((w) => resolve6(w.path)));
29572
29731
  let names;
29573
29732
  try {
@@ -29579,7 +29738,7 @@ function siblingWorktreeDirs(target) {
29579
29738
  for (const name of names) {
29580
29739
  if (!name.startsWith(stem)) continue;
29581
29740
  const m = DIR_NUMBER_SUFFIXED.exec(name);
29582
- const path = join59(parent, name);
29741
+ const path = join60(parent, name);
29583
29742
  if (m && !registered.has(resolve6(path))) out.push({ path, number: m[1] });
29584
29743
  }
29585
29744
  return out;
@@ -29592,7 +29751,7 @@ function orphanedWorktreeDirs(target, tickets, contract) {
29592
29751
  }
29593
29752
  function warnOrphanedWorktreeDirs(paths, log, held) {
29594
29753
  for (const p of paths) {
29595
- const number = DIR_NUMBER_SUFFIXED.exec(basename14(p))?.[1];
29754
+ const number = DIR_NUMBER_SUFFIXED.exec(basename15(p))?.[1];
29596
29755
  const when = held && number ? noteHeldWorktree(held.state, { repo: held.repo, path: p, ticket: number, status: "deployed", reason: "orphaned directory" }) : "first";
29597
29756
  if (when) {
29598
29757
  log.warn(`orphaned directory ${p}: its ticket is deployed but it is not a registered worktree; the sweep will not delete it \u2014 remove it by hand`, { step: "worktree" });
@@ -29614,7 +29773,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
29614
29773
  let removed = 0;
29615
29774
  let keptBranches = 0;
29616
29775
  for (const a of actions) {
29617
- if (!dryRun && base && !a.keepBranch && existsSync54(a.path) && isHandBackMerge(a.path, base)) {
29776
+ if (!dryRun && base && !a.keepBranch && existsSync55(a.path) && isHandBackMerge(a.path, base)) {
29618
29777
  if (gitOk(a.path, ["merge", "--abort"]) !== null) {
29619
29778
  log.emit(
29620
29779
  `abandoned the hand-back merge of ${base} in ${a.path}: ${displayKey(a.ticket)} deployed without it`,
@@ -29631,11 +29790,11 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
29631
29790
  { ticket: a.ticket.issue_id, step: "worktree" }
29632
29791
  );
29633
29792
  };
29634
- if (!dryRun && liveRun && existsSync54(a.path)) {
29793
+ if (!dryRun && liveRun && existsSync55(a.path)) {
29635
29794
  defer();
29636
29795
  continue;
29637
29796
  }
29638
- if (!dryRun && existsSync54(a.path)) {
29797
+ if (!dryRun && existsSync55(a.path)) {
29639
29798
  let dirty = false;
29640
29799
  try {
29641
29800
  dirty = status(a.path).length > 0;
@@ -29650,7 +29809,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
29650
29809
  continue;
29651
29810
  }
29652
29811
  }
29653
- if (!dryRun && a.requirePushed && a.branch && existsSync54(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
29812
+ if (!dryRun && a.requirePushed && a.branch && existsSync55(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
29654
29813
  if (pids.length) {
29655
29814
  defer();
29656
29815
  continue;
@@ -29706,7 +29865,7 @@ function isHandBackMerge(path, base) {
29706
29865
  if (!msgPath) return false;
29707
29866
  let first;
29708
29867
  try {
29709
- first = readFileSync55(resolve6(path, msgPath), "utf8").split("\n")[0] ?? "";
29868
+ first = readFileSync56(resolve6(path, msgPath), "utf8").split("\n")[0] ?? "";
29710
29869
  } catch {
29711
29870
  return false;
29712
29871
  }
@@ -29760,7 +29919,7 @@ function isTicketBranch(name, base, stems) {
29760
29919
  }
29761
29920
  function sweepCandidatesExist(cwd, base) {
29762
29921
  const linked = worktrees(cwd).slice(1);
29763
- if (linked.some((w) => DIR_NUMBER_SUFFIXED.test(basename14(w.path)) || w.branch && BRANCH_STEM.test(w.branch))) return true;
29922
+ if (linked.some((w) => DIR_NUMBER_SUFFIXED.test(basename15(w.path)) || w.branch && BRANCH_STEM.test(w.branch))) return true;
29764
29923
  if (siblingWorktreeDirs({ name: "", dir: cwd }).length) return true;
29765
29924
  return localBranches(cwd).some((b) => b !== base && /-\d+(?:-.*)?$/.test(b));
29766
29925
  }
@@ -29811,16 +29970,16 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
29811
29970
  }
29812
29971
 
29813
29972
  // src/stream-sweep.ts
29814
- import { existsSync as existsSync55, readdirSync as readdirSync17, rmSync as rmSync24, statSync as statSync16 } from "fs";
29815
- import { join as join60 } from "path";
29973
+ import { existsSync as existsSync56, readdirSync as readdirSync17, rmSync as rmSync24, statSync as statSync17 } from "fs";
29974
+ import { join as join61 } from "path";
29816
29975
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
29817
29976
  function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
29818
- const dir = join60(stateDir, "streams");
29819
- if (!existsSync55(dir)) return [];
29977
+ const dir = join61(stateDir, "streams");
29978
+ if (!existsSync56(dir)) return [];
29820
29979
  const cutoff = now - retentionDays * DAY_MS2;
29821
- return readdirSync17(dir).map((name) => join60(dir, name)).filter((path) => {
29980
+ return readdirSync17(dir).map((name) => join61(dir, name)).filter((path) => {
29822
29981
  try {
29823
- return statSync16(path).mtimeMs < cutoff;
29982
+ return statSync17(path).mtimeMs < cutoff;
29824
29983
  } catch {
29825
29984
  return false;
29826
29985
  }
@@ -29844,11 +30003,11 @@ function applyStreamSweep(paths, dryRun, log) {
29844
30003
  return removed;
29845
30004
  }
29846
30005
  function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
29847
- if (!existsSync55(stateDir)) return [];
30006
+ if (!existsSync56(stateDir)) return [];
29848
30007
  const cutoff = now - retentionDays * DAY_MS2;
29849
- return readdirSync17(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join60(stateDir, name)).filter((path) => {
30008
+ return readdirSync17(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join61(stateDir, name)).filter((path) => {
29850
30009
  try {
29851
- return statSync16(path).mtimeMs < cutoff;
30010
+ return statSync17(path).mtimeMs < cutoff;
29852
30011
  } catch {
29853
30012
  return false;
29854
30013
  }
@@ -29857,18 +30016,18 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
29857
30016
  function planSizeCapSweep(stateDir, maxBytes, now = Date.now()) {
29858
30017
  const files = [];
29859
30018
  const add = (dir, keep) => {
29860
- if (!existsSync55(dir)) return;
30019
+ if (!existsSync56(dir)) return;
29861
30020
  for (const name of readdirSync17(dir)) {
29862
30021
  if (!keep(name)) continue;
29863
- const path = join60(dir, name);
30022
+ const path = join61(dir, name);
29864
30023
  try {
29865
- const st = statSync16(path);
30024
+ const st = statSync17(path);
29866
30025
  if (st.isFile()) files.push({ path, mtime: st.mtimeMs, size: st.size });
29867
30026
  } catch {
29868
30027
  }
29869
30028
  }
29870
30029
  };
29871
- add(join60(stateDir, "streams"), () => true);
30030
+ add(join61(stateDir, "streams"), () => true);
29872
30031
  add(stateDir, (name) => ROTATED_EVENTS_RE.test(name));
29873
30032
  let total = files.reduce((n, f2) => n + f2.size, 0);
29874
30033
  const out = [];
@@ -29888,7 +30047,7 @@ function planStateSweep(stateDir, retentionDays, maxBytes, now = Date.now()) {
29888
30047
  }
29889
30048
 
29890
30049
  // src/cli.ts
29891
- import { realpathSync as realpathSync4, readFileSync as readFileSync58, existsSync as existsSync60, mkdirSync as mkdirSync44, writeFileSync as writeFileSync45, rmSync as rmSync27, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync10, statSync as statSync19, readdirSync as readdirSync22 } from "fs";
30050
+ import { realpathSync as realpathSync4, readFileSync as readFileSync59, existsSync as existsSync61, mkdirSync as mkdirSync44, writeFileSync as writeFileSync46, rmSync as rmSync27, unlinkSync as unlinkSync7, copyFileSync as copyFileSync2, renameSync as renameSync11, statSync as statSync20, readdirSync as readdirSync22 } from "fs";
29892
30051
  import { createInterface } from "readline/promises";
29893
30052
 
29894
30053
  // src/periscope-resume.ts
@@ -29964,33 +30123,33 @@ ${tail2(preview.output)}`);
29964
30123
  import { dirname as dirOf2, resolve as resolvePath } from "path";
29965
30124
 
29966
30125
  // src/bundle-staleness.ts
29967
- import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
29968
- import { join as join61 } from "path";
30126
+ import { existsSync as existsSync57, readdirSync as readdirSync18, statSync as statSync18 } from "fs";
30127
+ import { join as join62 } from "path";
29969
30128
  function builtVersion() {
29970
- return true ? "0.169.6" : null;
30129
+ return true ? "0.171.0" : null;
29971
30130
  }
29972
30131
  var REBUILD_HINT = "rebuild with npm run build";
29973
30132
  function newestMtime(path) {
29974
30133
  let stat2;
29975
30134
  try {
29976
- stat2 = statSync17(path);
30135
+ stat2 = statSync18(path);
29977
30136
  } catch {
29978
30137
  return 0;
29979
30138
  }
29980
30139
  if (stat2.isFile()) return stat2.mtimeMs;
29981
30140
  if (!stat2.isDirectory()) return 0;
29982
30141
  let latest = stat2.mtimeMs;
29983
- for (const e of readdirSync18(path, { withFileTypes: true })) latest = Math.max(latest, newestMtime(join61(path, e.name)));
30142
+ for (const e of readdirSync18(path, { withFileTypes: true })) latest = Math.max(latest, newestMtime(join62(path, e.name)));
29984
30143
  return latest;
29985
30144
  }
29986
30145
  function bundleStaleness(i) {
29987
30146
  if (i.built === null || i.compiled) return null;
29988
- const src = join61(i.home, "src");
29989
- if (!existsSync56(src)) return null;
30147
+ const src = join62(i.home, "src");
30148
+ if (!existsSync57(src)) return null;
29990
30149
  if (i.built !== i.current) {
29991
30150
  return { kind: "version", builtVersion: i.built, message: `running a bundle built from ${i.built} (package.json names ${i.current}); ${REBUILD_HINT}` };
29992
30151
  }
29993
- const bundle = statSafe(join61(i.home, "dist", "cli.js"));
30152
+ const bundle = statSafe(join62(i.home, "dist", "cli.js"));
29994
30153
  if (bundle === null) return null;
29995
30154
  if (newestMtime(src) > bundle) {
29996
30155
  return { kind: "source", builtVersion: i.built, message: `running a bundle older than the source in src/ (both ${i.current}); ${REBUILD_HINT}` };
@@ -29999,7 +30158,7 @@ function bundleStaleness(i) {
29999
30158
  }
30000
30159
  function statSafe(p) {
30001
30160
  try {
30002
- return statSync17(p).mtimeMs;
30161
+ return statSync18(p).mtimeMs;
30003
30162
  } catch {
30004
30163
  return null;
30005
30164
  }
@@ -30208,8 +30367,8 @@ async function unregisterEndpoint(workspaceId, info, d) {
30208
30367
  import { createServer as createHttpServer } from "http";
30209
30368
  import { spawn as spawn10 } from "child_process";
30210
30369
  import { randomBytes as randomBytes2 } from "crypto";
30211
- import { existsSync as existsSync57, mkdirSync as mkdirSync41, readFileSync as readFileSync56, writeFileSync as writeFileSync43, unlinkSync as unlinkSync5, readdirSync as readdirSync19 } from "fs";
30212
- import { join as join62 } from "path";
30370
+ import { existsSync as existsSync58, mkdirSync as mkdirSync41, readFileSync as readFileSync57, writeFileSync as writeFileSync44, unlinkSync as unlinkSync6, readdirSync as readdirSync19 } from "fs";
30371
+ import { join as join63 } from "path";
30213
30372
 
30214
30373
  // src/secret-compare.ts
30215
30374
  import { timingSafeEqual } from "crypto";
@@ -30302,27 +30461,27 @@ var defaultSpawn2 = (cmd, args, env) => {
30302
30461
  return child;
30303
30462
  };
30304
30463
  function syncDaemonStatePath(stateDir, workspaceId) {
30305
- return join62(stateDir, "passengers", `${workspaceId}-sync.json`);
30464
+ return join63(stateDir, "passengers", `${workspaceId}-sync.json`);
30306
30465
  }
30307
30466
  function readPersistedSyncDaemon(stateDir, workspaceId) {
30308
30467
  const path = syncDaemonStatePath(stateDir, workspaceId);
30309
- if (!existsSync57(path)) return void 0;
30468
+ if (!existsSync58(path)) return void 0;
30310
30469
  try {
30311
- return JSON.parse(readFileSync56(path, "utf8"));
30470
+ return JSON.parse(readFileSync57(path, "utf8"));
30312
30471
  } catch {
30313
30472
  return void 0;
30314
30473
  }
30315
30474
  }
30316
30475
  function writePersistedSyncDaemon(stateDir, state) {
30317
30476
  const path = syncDaemonStatePath(stateDir, state.workspaceId);
30318
- mkdirSync41(join62(stateDir, "passengers"), { recursive: true });
30319
- writeFileSync43(path, `${JSON.stringify(state, null, 2)}
30477
+ mkdirSync41(join63(stateDir, "passengers"), { recursive: true });
30478
+ writeFileSync44(path, `${JSON.stringify(state, null, 2)}
30320
30479
  `);
30321
30480
  }
30322
30481
  function removePersistedSyncDaemon(stateDir, workspaceId) {
30323
30482
  const path = syncDaemonStatePath(stateDir, workspaceId);
30324
30483
  try {
30325
- unlinkSync5(path);
30484
+ unlinkSync6(path);
30326
30485
  } catch {
30327
30486
  }
30328
30487
  }
@@ -30333,8 +30492,8 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
30333
30492
  }
30334
30493
  }
30335
30494
  function readAllPersistedSyncWorkspaceIds(stateDir) {
30336
- const dir = join62(stateDir, "passengers");
30337
- if (!existsSync57(dir)) return [];
30495
+ const dir = join63(stateDir, "passengers");
30496
+ if (!existsSync58(dir)) return [];
30338
30497
  const suffix = "-sync.json";
30339
30498
  return readdirSync19(dir).filter((f2) => f2.endsWith(suffix)).map((f2) => f2.slice(0, -suffix.length));
30340
30499
  }
@@ -30398,7 +30557,7 @@ import { createServer, request as httpRequest } from "http";
30398
30557
  import { request as httpsRequest } from "https";
30399
30558
  import { connect as netConnect } from "net";
30400
30559
  import { connect as tlsConnect } from "tls";
30401
- import { dirname as dirname35, isAbsolute as isAbsolute4 } from "path";
30560
+ import { dirname as dirname36, isAbsolute as isAbsolute4 } from "path";
30402
30561
  import { brotliDecompressSync, gunzipSync, inflateSync } from "zlib";
30403
30562
 
30404
30563
  // src/periscope-inspector.ts
@@ -30512,7 +30671,7 @@ function parsePointedBody(raw) {
30512
30671
  return entry;
30513
30672
  }
30514
30673
  function appendPointed(file, entry, now = /* @__PURE__ */ new Date()) {
30515
- mkdirSync42(dirname35(file), { recursive: true });
30674
+ mkdirSync42(dirname36(file), { recursive: true });
30516
30675
  appendFileSync4(file, `${JSON.stringify({ ...entry, at: now.toISOString() })}
30517
30676
  `);
30518
30677
  }
@@ -30801,7 +30960,7 @@ async function startWorktreeIntel(d) {
30801
30960
  }
30802
30961
 
30803
30962
  // src/contract-refusal.ts
30804
- import { join as join63 } from "path";
30963
+ import { join as join64 } from "path";
30805
30964
  function contractFixers(dir, baseRef, tickets, locate) {
30806
30965
  const out = [];
30807
30966
  for (const t of tickets) {
@@ -30813,7 +30972,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
30813
30972
  const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
30814
30973
  if (text2 === null) continue;
30815
30974
  try {
30816
- parseRepoConfig(text2, join63(dir, file));
30975
+ parseRepoConfig(text2, join64(dir, file));
30817
30976
  } catch (e) {
30818
30977
  if (e instanceof RepoConfigError) continue;
30819
30978
  throw e;
@@ -30826,20 +30985,20 @@ function contractFixers(dir, baseRef, tickets, locate) {
30826
30985
  // src/control-api.ts
30827
30986
  import { createHash as createHash12 } from "crypto";
30828
30987
  import {
30829
- chmodSync as chmodSync4,
30988
+ chmodSync as chmodSync5,
30830
30989
  closeSync as closeSync7,
30831
- existsSync as existsSync58,
30990
+ existsSync as existsSync59,
30832
30991
  fstatSync as fstatSync2,
30833
30992
  openSync as openSync7,
30834
30993
  readSync as readSync4,
30835
30994
  readdirSync as readdirSync20,
30836
30995
  rmSync as rmSync25,
30837
- statSync as statSync18,
30996
+ statSync as statSync19,
30838
30997
  watch
30839
30998
  } from "fs";
30840
30999
  import { createConnection } from "net";
30841
31000
  import { createServer as createServer2 } from "http";
30842
- import { basename as basename15, dirname as dirname36, join as join64 } from "path";
31001
+ import { basename as basename16, dirname as dirname37, join as join65 } from "path";
30843
31002
  import { execFile as execFile6, spawn as spawn13 } from "child_process";
30844
31003
 
30845
31004
  // src/periscope-control.ts
@@ -31077,7 +31236,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
31077
31236
  // src/control-api.ts
31078
31237
  var PAUSABLE = ["dev", "design", "qa"];
31079
31238
  var CONTROL_SOCKET_NAME = "control.sock";
31080
- var controlSocketFor = (stateDir) => join64(stateDir, CONTROL_SOCKET_NAME);
31239
+ var controlSocketFor = (stateDir) => join65(stateDir, CONTROL_SOCKET_NAME);
31081
31240
  var MAX_SOCKET_PATH = 100;
31082
31241
  var MAX_TAIL_BYTES = 1024 * 1024;
31083
31242
  var MAX_WAIT_SECONDS = 30;
@@ -31164,7 +31323,7 @@ function candidates(live2, rotated) {
31164
31323
  const out = [live2];
31165
31324
  if (!rotated) return out;
31166
31325
  try {
31167
- for (const n of readdirSync20(dirname36(live2))) if (ROTATED_EVENTS_RE.test(n)) out.push(join64(dirname36(live2), n));
31326
+ for (const n of readdirSync20(dirname37(live2))) if (ROTATED_EVENTS_RE.test(n)) out.push(join65(dirname37(live2), n));
31168
31327
  } catch {
31169
31328
  }
31170
31329
  return out;
@@ -31187,7 +31346,7 @@ function readRange(path, from, max) {
31187
31346
  }
31188
31347
  }
31189
31348
  function lastLines2(path, n) {
31190
- const st = statSync18(path);
31349
+ const st = statSync19(path);
31191
31350
  const cursorAt = (off) => encodeCursor({ dev: st.dev, ino: st.ino, off });
31192
31351
  if (n <= 0 || st.size === 0) return { lines: [], cursor: cursorAt(st.size), reset: false };
31193
31352
  let start = st.size;
@@ -31208,7 +31367,7 @@ function lastLines2(path, n) {
31208
31367
  }
31209
31368
  function readTail(live2, opts) {
31210
31369
  const max = opts.maxBytes ?? MAX_TAIL_BYTES;
31211
- if (!existsSync58(live2)) {
31370
+ if (!existsSync59(live2)) {
31212
31371
  return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
31213
31372
  }
31214
31373
  const cur = opts.after ? decodeCursor(opts.after) : null;
@@ -31221,7 +31380,7 @@ function readTail(live2, opts) {
31221
31380
  } else {
31222
31381
  const found = candidates(live2, opts.rotated ?? false).find((p) => {
31223
31382
  try {
31224
- const s = statSync18(p);
31383
+ const s = statSync19(p);
31225
31384
  return s.ino === cur.ino && s.dev === cur.dev;
31226
31385
  } catch {
31227
31386
  return false;
@@ -31232,7 +31391,7 @@ function readTail(live2, opts) {
31232
31391
  off = cur.off;
31233
31392
  } else reset = true;
31234
31393
  }
31235
- let size = statSync18(path).size;
31394
+ let size = statSync19(path).size;
31236
31395
  if (off > size) {
31237
31396
  off = 0;
31238
31397
  reset = true;
@@ -31240,12 +31399,12 @@ function readTail(live2, opts) {
31240
31399
  if (off >= size && path !== live2) {
31241
31400
  path = live2;
31242
31401
  off = 0;
31243
- size = statSync18(path).size;
31402
+ size = statSync19(path).size;
31244
31403
  }
31245
31404
  const { text: text2 } = readRange(path, off, max);
31246
31405
  const cut = text2.lastIndexOf("\n");
31247
31406
  const whole = cut < 0 ? "" : text2.slice(0, cut + 1);
31248
- const st = statSync18(path);
31407
+ const st = statSync19(path);
31249
31408
  return {
31250
31409
  lines: whole.split("\n").filter((l) => l.length),
31251
31410
  cursor: encodeCursor({ dev: st.dev, ino: st.ino, off: off + Buffer.byteLength(whole) }),
@@ -31295,7 +31454,7 @@ function pauseDoc(state) {
31295
31454
  }
31296
31455
  function describeStream(r) {
31297
31456
  return {
31298
- run: basename15(r.streamPath).replace(/\.jsonl$/, ""),
31457
+ run: basename16(r.streamPath).replace(/\.jsonl$/, ""),
31299
31458
  pid: r.pid,
31300
31459
  ticket: r.ticket,
31301
31460
  role: r.role,
@@ -31332,7 +31491,7 @@ async function tailReply(path, q2, rotated, abort) {
31332
31491
  const deadline = Date.now() + Math.min(wait, MAX_WAIT_SECONDS) * 1e3;
31333
31492
  let r = readTail(path, { after, tail: tail3, rotated });
31334
31493
  while (after && !r.lines.length && !r.reset && Date.now() < deadline && !abort.aborted) {
31335
- await waitForChange(dirname36(path), deadline - Date.now(), abort);
31494
+ await waitForChange(dirname37(path), deadline - Date.now(), abort);
31336
31495
  r = readTail(path, { after: r.cursor, rotated });
31337
31496
  }
31338
31497
  return reply2(200, r);
@@ -31341,14 +31500,14 @@ var NOTE_MAX_CHARS = 4e3;
31341
31500
  var SEAT_ROLES = ["dev", "design", "qa", "triage", "pair"];
31342
31501
  async function postRunMessage(deps, run4, body) {
31343
31502
  if (!RUN_NAME_RE.test(run4) || run4.includes("..")) return err2(400, "not a run name");
31344
- const live2 = liveRuns(deps.stateDir).find((r) => basename15(r.streamPath, ".jsonl") === run4.replace(/\.jsonl$/, ""));
31503
+ const live2 = liveRuns(deps.stateDir).find((r) => basename16(r.streamPath, ".jsonl") === run4.replace(/\.jsonl$/, ""));
31345
31504
  const carry = "A note for the work item posted from the platform is carried forward into its next run's brief.";
31346
31505
  if (!live2) return err2(404, `no live run ${run4}: it is unknown or has finished. ${carry}`);
31347
31506
  if (!body) return err2(400, "body must be a small JSON object");
31348
31507
  const text2 = typeof body.text === "string" ? body.text.trim() : "";
31349
31508
  if (!text2 || text2.length > NOTE_MAX_CHARS) return err2(400, `text must be a string of 1 to ${NOTE_MAX_CHARS} characters`);
31350
31509
  if (body.author !== void 0 && typeof body.author !== "string") return err2(400, "author must be a string");
31351
- const input = runInputFor(basename15(live2.streamPath, ".jsonl"));
31510
+ const input = runInputFor(basename16(live2.streamPath, ".jsonl"));
31352
31511
  const rowId = input?.agentLogRowId();
31353
31512
  if (!input?.target || !rowId) return err2(409, `run ${run4} is live but this daemon cannot record a note on it (it did not start the run, or the run has no Agent Log row). ${carry}`);
31354
31513
  try {
@@ -31423,8 +31582,8 @@ async function route(deps, method, url, req, abort) {
31423
31582
  if (p.startsWith("/streams/") && get2) {
31424
31583
  const run4 = decodeURIComponent(p.slice("/streams/".length));
31425
31584
  if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
31426
- const file = join64(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
31427
- if (!existsSync58(file)) return err2(404, "no such run");
31585
+ const file = join65(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
31586
+ if (!existsSync59(file)) return err2(404, "no such run");
31428
31587
  return tailReply(file, url.searchParams, false, abort);
31429
31588
  }
31430
31589
  const note = /^\/streams\/([^/]+)\/messages$/.exec(p);
@@ -31473,7 +31632,7 @@ function send2(res, r) {
31473
31632
  res.end(body);
31474
31633
  }
31475
31634
  async function socketIsStale(path) {
31476
- if (!existsSync58(path)) return false;
31635
+ if (!existsSync59(path)) return false;
31477
31636
  return new Promise((resolve9) => {
31478
31637
  const c = createConnection(path);
31479
31638
  c.once("connect", () => {
@@ -31492,7 +31651,7 @@ async function startControlServer(deps) {
31492
31651
  return null;
31493
31652
  }
31494
31653
  if (await socketIsStale(path)) rmSync25(path, { force: true });
31495
- else if (existsSync58(path)) {
31654
+ else if (existsSync59(path)) {
31496
31655
  log(`control API not started: ${path} is in use by another process`);
31497
31656
  return null;
31498
31657
  }
@@ -31529,7 +31688,7 @@ async function startControlServer(deps) {
31529
31688
  });
31530
31689
  server.listen(path, () => {
31531
31690
  try {
31532
- chmodSync4(path, 384);
31691
+ chmodSync5(path, 384);
31533
31692
  } catch {
31534
31693
  }
31535
31694
  server.on("error", (e) => log(`control API error: ${e.message}`));
@@ -31591,31 +31750,31 @@ function crewJson(args, timeoutMs = CREW_JSON_TIMEOUT_MS) {
31591
31750
 
31592
31751
  // src/periscope-mcp.ts
31593
31752
  import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
31594
- import { basename as basename16, dirname as dirname37, isAbsolute as isAbsolute5, join as join66, relative as relative2, resolve as resolve7, sep } from "path";
31753
+ import { basename as basename17, dirname as dirname38, isAbsolute as isAbsolute5, join as join67, relative as relative2, resolve as resolve7, sep } from "path";
31595
31754
  import { z } from "zod";
31596
31755
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
31597
31756
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
31598
31757
 
31599
31758
  // src/periscope-endpoints.ts
31600
31759
  import { randomBytes as randomBytes3 } from "crypto";
31601
- import { chmodSync as chmodSync5, existsSync as existsSync59, mkdirSync as mkdirSync43, readdirSync as readdirSync21, readFileSync as readFileSync57, rmSync as rmSync26, writeFileSync as writeFileSync44 } from "fs";
31602
- import { join as join65 } from "path";
31603
- var secretDir = (stateDir) => join65(stateDir, "periscope-mcp");
31604
- var secretFile = (stateDir, id) => join65(secretDir(stateDir), `${id}.json`);
31605
- var endpointDir = (stateDir) => join65(stateDir, "periscope-endpoints");
31606
- var endpointFile = (stateDir, id) => join65(endpointDir(stateDir), `${id}.json`);
31760
+ import { chmodSync as chmodSync6, existsSync as existsSync60, mkdirSync as mkdirSync43, readdirSync as readdirSync21, readFileSync as readFileSync58, rmSync as rmSync26, writeFileSync as writeFileSync45 } from "fs";
31761
+ import { join as join66 } from "path";
31762
+ var secretDir = (stateDir) => join66(stateDir, "periscope-mcp");
31763
+ var secretFile = (stateDir, id) => join66(secretDir(stateDir), `${id}.json`);
31764
+ var endpointDir = (stateDir) => join66(stateDir, "periscope-endpoints");
31765
+ var endpointFile = (stateDir, id) => join66(endpointDir(stateDir), `${id}.json`);
31607
31766
  function mintPeriscopeSecret(stateDir, ticketRecordId) {
31608
31767
  mkdirSync43(secretDir(stateDir), { recursive: true, mode: 448 });
31609
31768
  const secret = randomBytes3(32).toString("base64url");
31610
31769
  const file = secretFile(stateDir, ticketRecordId);
31611
- writeFileSync44(file, `${JSON.stringify({ secret })}
31770
+ writeFileSync45(file, `${JSON.stringify({ secret })}
31612
31771
  `, { mode: 384 });
31613
- chmodSync5(file, 384);
31772
+ chmodSync6(file, 384);
31614
31773
  return secret;
31615
31774
  }
31616
31775
  function readPeriscopeSecret(stateDir, ticketRecordId) {
31617
31776
  try {
31618
- const v = JSON.parse(readFileSync57(secretFile(stateDir, ticketRecordId), "utf8"));
31777
+ const v = JSON.parse(readFileSync58(secretFile(stateDir, ticketRecordId), "utf8"));
31619
31778
  return typeof v.secret === "string" && v.secret ? v.secret : void 0;
31620
31779
  } catch {
31621
31780
  return void 0;
@@ -31626,14 +31785,14 @@ function removePeriscopeSecret(stateDir, ticketRecordId) {
31626
31785
  }
31627
31786
  function readPeriscopeEndpoint(stateDir, ticketRecordId) {
31628
31787
  try {
31629
- return JSON.parse(readFileSync57(endpointFile(stateDir, ticketRecordId), "utf8"));
31788
+ return JSON.parse(readFileSync58(endpointFile(stateDir, ticketRecordId), "utf8"));
31630
31789
  } catch {
31631
31790
  return void 0;
31632
31791
  }
31633
31792
  }
31634
31793
  function writePeriscopeEndpoint(stateDir, rec) {
31635
31794
  mkdirSync43(endpointDir(stateDir), { recursive: true });
31636
- writeFileSync44(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
31795
+ writeFileSync45(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
31637
31796
  `);
31638
31797
  }
31639
31798
  function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
@@ -31641,7 +31800,7 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
31641
31800
  }
31642
31801
  function listPeriscopeEndpoints(stateDir) {
31643
31802
  const dir = endpointDir(stateDir);
31644
- if (!existsSync59(dir)) return [];
31803
+ if (!existsSync60(dir)) return [];
31645
31804
  const out = [];
31646
31805
  for (const name of readdirSync21(dir)) {
31647
31806
  if (!name.endsWith(".json")) continue;
@@ -31729,12 +31888,12 @@ async function realAncestor(p) {
31729
31888
  }
31730
31889
  if (isLink) {
31731
31890
  if (++hops > 40) throw new PathRefusal(`too many symbolic links resolving ${p}`);
31732
- cur = resolve7(dirname37(cur), await readlink(cur));
31891
+ cur = resolve7(dirname38(cur), await readlink(cur));
31733
31892
  continue;
31734
31893
  }
31735
- const parent = dirname37(cur);
31894
+ const parent = dirname38(cur);
31736
31895
  if (parent === cur) throw new PathRefusal(`cannot resolve ${p}`);
31737
- tail3.push(basename16(cur));
31896
+ tail3.push(basename17(cur));
31738
31897
  cur = parent;
31739
31898
  }
31740
31899
  }
@@ -31744,13 +31903,13 @@ async function resolveInWorktree(root, requested) {
31744
31903
  let abs;
31745
31904
  if (isAbsolute5(requested)) {
31746
31905
  abs = resolve7(requested);
31747
- if (isInside(root, abs)) abs = join66(realRoot, relative2(root, abs));
31906
+ if (isInside(root, abs)) abs = join67(realRoot, relative2(root, abs));
31748
31907
  } else {
31749
31908
  abs = resolve7(realRoot, requested);
31750
31909
  }
31751
31910
  if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
31752
31911
  const { real, rest } = await realAncestor(abs);
31753
- const final = rest ? join66(real, rest) : real;
31912
+ const final = rest ? join67(real, rest) : real;
31754
31913
  if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
31755
31914
  if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
31756
31915
  return final;
@@ -31818,7 +31977,7 @@ function createPeriscopeMcpServer(d, sc) {
31818
31977
  const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
31819
31978
  const lines2 = await Promise.all(entries.map(async (e) => {
31820
31979
  if (e.isDirectory()) return `[DIR] ${e.name}`;
31821
- const size = (await lstat(join66(abs, e.name))).size;
31980
+ const size = (await lstat(join67(abs, e.name))).size;
31822
31981
  return `[FILE] ${e.name} (${size} bytes)`;
31823
31982
  }));
31824
31983
  return text(lines2.join("\n") || "(empty)");
@@ -31843,7 +32002,7 @@ function createPeriscopeMcpServer(d, sc) {
31843
32002
  if (Buffer.byteLength(content) > MAX_WRITE_BYTES) return text(`content exceeds ${MAX_WRITE_BYTES} bytes`, true);
31844
32003
  const abs = await inTree(path);
31845
32004
  if (abs === await realpath(root)) return text("path must name a file", true);
31846
- await mkdir(dirname37(abs), { recursive: true });
32005
+ await mkdir(dirname38(abs), { recursive: true });
31847
32006
  await inTree(path);
31848
32007
  await writeFile(abs, content);
31849
32008
  return text(`Wrote ${Buffer.byteLength(content)} bytes to ${await rel(abs)}`);
@@ -31883,9 +32042,9 @@ function createPeriscopeMcpServer(d, sc) {
31883
32042
  inputSchema: { path: z.string() },
31884
32043
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
31885
32044
  }, async ({ path }) => {
31886
- const parent = await inTree(dirname37(path) === "" ? "." : dirname37(path));
31887
- const abs = join66(parent, basename16(path));
31888
- if (basename16(path) === ".git" || abs === parent) return text("path must name a file", true);
32045
+ const parent = await inTree(dirname38(path) === "" ? "." : dirname38(path));
32046
+ const abs = join67(parent, basename17(path));
32047
+ if (basename17(path) === ".git" || abs === parent) return text("path must name a file", true);
31889
32048
  const st = await lstat(abs).catch(() => void 0);
31890
32049
  if (!st) return text(`${path} does not exist`, true);
31891
32050
  if (st.isDirectory()) return text(`${path} is a directory; only files are deleted`, true);
@@ -32005,7 +32164,7 @@ function findPeriscope(sidecars, segment) {
32005
32164
  }
32006
32165
 
32007
32166
  // src/cli.ts
32008
- var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname38(process.execPath) : resolve8(dirname38(fileURLToPath2(import.meta.url)), "..");
32167
+ var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname39(process.execPath) : resolve8(dirname39(fileURLToPath2(import.meta.url)), "..");
32009
32168
  {
32010
32169
  const v = crewVersion(CREW_HOME);
32011
32170
  if (v !== "0.0.0") setRunningCrewVersion(v);
@@ -32168,6 +32327,7 @@ function usage(problem, requested = false) {
32168
32327
  crew --version [--json] print the crew version on one line (also: crew version); --json adds home and compiled
32169
32328
  crew status [route] [--json] [--verbose] what is running and what needs a person; --verbose adds configuration and full lists; --json for a machine reader
32170
32329
  crew projects [--route R] [--json] the Projects rows each route can read (id, name, prefix, work mode)
32330
+ crew routes available [--json] the tracker apps you can reach that this machine has no route for (read-only; starts no sign-in)
32171
32331
  crew projects add [route] NAME --prefix P [--work-mode automatic|hybrid|manual] [--json] [--dry-run] create a Projects row
32172
32332
  crew provision --key K --route WS[/PROJECT] [--forge-host H] [--ship-name N] [--json] one non-interactive run: connect, forge tokens,
32173
32333
  enable routes, install units with lingering, start the daemon; safe to re-run (CREW_CONNECT_KEY,
@@ -32322,6 +32482,7 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
32322
32482
  "projects",
32323
32483
  "reap",
32324
32484
  "release",
32485
+ "routes",
32325
32486
  "reload",
32326
32487
  "repos",
32327
32488
  "resume",
@@ -32417,7 +32578,7 @@ if (command === "provision") {
32417
32578
  process.exit(outcome.code);
32418
32579
  }
32419
32580
  if (command === "pool-member") {
32420
- const pool = poolConfigFrom(argv, process.env, () => readFileSync58(0, "utf8"));
32581
+ const pool = poolConfigFrom(argv, process.env, () => readFileSync59(0, "utf8"));
32421
32582
  if (typeof pool === "string") {
32422
32583
  process.stderr.write(`crew pool-member: ${pool}
32423
32584
  `);
@@ -32760,9 +32921,9 @@ if (command === "passenger-sync-daemon") {
32760
32921
  firstRun = { answers, configPath };
32761
32922
  cfg = loadConfig(CREW_HOME, configPath, { text: renderShipBlock(answers), allowNoRoutes: true });
32762
32923
  } else {
32763
- const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
32764
- const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
32765
- if (configless && !existsSync60(findConfigFile(CREW_HOME))) {
32924
+ const toleratesNoRoutes = command === "routes" || command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
32925
+ const configless = command === "routes" || command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
32926
+ if (configless && !existsSync61(findConfigFile(CREW_HOME))) {
32766
32927
  cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
32767
32928
  } else {
32768
32929
  cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
@@ -32785,7 +32946,7 @@ if (command === "passenger-sync-daemon") {
32785
32946
  throw e;
32786
32947
  }
32787
32948
  if (command === "credential") {
32788
- const r = runCredential(positional[1], readFileSync58(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
32949
+ const r = runCredential(positional[1], readFileSync59(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
32789
32950
  process.stdout.write(r.out);
32790
32951
  process.stderr.write(r.err);
32791
32952
  process.exit(r.code);
@@ -32797,9 +32958,9 @@ if (command === "passenger-sync-daemon") {
32797
32958
  forges: cfg.ship.forges,
32798
32959
  stateDir: cfg.ship.stateDir,
32799
32960
  configFile: cfg.configFile,
32800
- readFile: (p) => readFileSync58(p, "utf8"),
32801
- writeFile: (p, t) => writeFileSync45(p, t),
32802
- stdin: () => readFileSync58(0, "utf8"),
32961
+ readFile: (p) => readFileSync59(p, "utf8"),
32962
+ writeFile: (p, t) => writeFileSync46(p, t),
32963
+ stdin: () => readFileSync59(0, "utf8"),
32803
32964
  env: process.env
32804
32965
  }
32805
32966
  );
@@ -32819,7 +32980,7 @@ if (command === "passenger-sync-daemon") {
32819
32980
  const DAEMON_SUBCOMMANDS = /* @__PURE__ */ new Set(["start", "stop", "status", "restart"]);
32820
32981
  const worktreeArgs = command === "worktree" ? splitWorktreeArgs(positional, cfg.routes.map((r) => r.route)) : void 0;
32821
32982
  const named = worktreeArgs ? worktreeArgs.route : command === "daemon" && DAEMON_SUBCOMMANDS.has(positional[1] ?? "") ? positional[2] : positional[1];
32822
- const fleetWide = command === "inbox" || command === "connect" || command === "disconnect" || command === "deprovision" || command === "agents" || command === "skills" || command === "logbook" || command === "repos" || command === "ship" || command === "projects" || command === "periscope" || command === "whoami" || command === "sandbox" || releaseFleetWide || // CREW-3875: the scheduler units are per ship and name no route, so a route given is ignored.
32983
+ const fleetWide = command === "inbox" || command === "connect" || command === "disconnect" || command === "deprovision" || command === "agents" || command === "skills" || command === "logbook" || command === "repos" || command === "ship" || command === "projects" || command === "routes" || command === "periscope" || command === "whoami" || command === "sandbox" || releaseFleetWide || // CREW-3875: the scheduler units are per ship and name no route, so a route given is ignored.
32823
32984
  command === "install" || command === "uninstall" || command === "pause" || command === "resume" || command === "reload" || FLEET_CAPABLE.has(command) && !named && cfg.routes.length > 1 || worktreeArgs !== void 0 && !named && cfg.routes.length > 1;
32824
32985
  let route2;
32825
32986
  try {
@@ -33159,15 +33320,15 @@ if (command === "passenger-sync-daemon") {
33159
33320
  for (const l of summarizeJobs(results, { dryRun, verbose: flag("verbose"), host })) emit.emit(l);
33160
33321
  if (host === "linux" && hasSystemd) {
33161
33322
  const label = labelFor(CREW_HOME, "run");
33162
- const staleTimer = join67(homedir11(), ".config", "systemd", "user", `${label}.timer`);
33163
- if (existsSync60(staleTimer)) {
33323
+ const staleTimer = join68(homedir11(), ".config", "systemd", "user", `${label}.timer`);
33324
+ if (existsSync61(staleTimer)) {
33164
33325
  emit.emit(
33165
33326
  `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run, not applied)" : ""}`
33166
33327
  );
33167
33328
  if (!dryRun) {
33168
33329
  spawnSync15("systemctl", ["--user", "disable", "--now", `${label}.timer`], { cwd: CREW_HOME, env: withUserBusEnv() });
33169
33330
  try {
33170
- unlinkSync6(staleTimer);
33331
+ unlinkSync7(staleTimer);
33171
33332
  } catch {
33172
33333
  }
33173
33334
  }
@@ -33209,7 +33370,7 @@ if (command === "passenger-sync-daemon") {
33209
33370
  const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
33210
33371
  for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
33211
33372
  for (const r of doctorRepos) {
33212
- if (!existsSync60(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
33373
+ if (!existsSync61(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
33213
33374
  if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
33214
33375
  readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
33215
33376
  }
@@ -33249,7 +33410,7 @@ if (command === "passenger-sync-daemon") {
33249
33410
  }
33250
33411
  async function doctorFix(o) {
33251
33412
  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))));
33252
- const unitExists = (p) => existsSync60(p);
33413
+ const unitExists = (p) => existsSync61(p);
33253
33414
  const crontab = o.host === "linux" ? spawnSync15("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
33254
33415
  const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
33255
33416
  const plan = planFix({ routes, schedulerAbsent, host: o.host });
@@ -33279,7 +33440,7 @@ if (command === "passenger-sync-daemon") {
33279
33440
  changed2.push(`refreshed the connect snapshot for ${a.route} (\`crew connect\`)${rel.status === 0 ? " and reloaded the daemon" : "; `crew reload` failed \u2014 run it by hand"}`);
33280
33441
  } else if (a.kind === "enable") {
33281
33442
  if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
33282
- writeFileSync45(cfg.configFile, planEnable(readFileSync58(cfg.configFile, "utf8"), a.route));
33443
+ writeFileSync46(cfg.configFile, planEnable(readFileSync59(cfg.configFile, "utf8"), a.route));
33283
33444
  enabledSound.add(a.route);
33284
33445
  changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
33285
33446
  } else {
@@ -33532,7 +33693,7 @@ ${changed2.map((c) => ` - ${c}
33532
33693
  harnessBin: "claude",
33533
33694
  ...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
33534
33695
  },
33535
- policyFile: join67(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
33696
+ policyFile: join68(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
33536
33697
  repo: mirror,
33537
33698
  origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
33538
33699
  base: effective.branch.base,
@@ -34955,7 +35116,7 @@ ${f2.tail.trimEnd()}
34955
35116
  logFile: cfg.ship.logFile
34956
35117
  });
34957
35118
  }
34958
- const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join67(CREW_HOME, "src"), join67(CREW_HOME, "dist"), join67(CREW_HOME, "bin")];
35119
+ const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join68(CREW_HOME, "src"), join68(CREW_HOME, "dist"), join68(CREW_HOME, "bin")];
34959
35120
  const configPaths = daemonConfigPaths(cfg);
34960
35121
  watchPaths.push(...configPaths);
34961
35122
  noteDaemonStarted(cfg.ship.stateDir);
@@ -35264,10 +35425,10 @@ ${f2.tail.trimEnd()}
35264
35425
  for (const w of result.warnings) emit.warn(w);
35265
35426
  if (!dryRun) {
35266
35427
  const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
35267
- const raw = existsSync60(resolvedPath) ? JSON.parse(readFileSync58(resolvedPath, "utf8")) : {};
35428
+ const raw = existsSync61(resolvedPath) ? JSON.parse(readFileSync59(resolvedPath, "utf8")) : {};
35268
35429
  raw.agentSkills = result.agentSkills;
35269
35430
  mkdirSync44(dirOf2(resolvedPath), { recursive: true });
35270
- writeFileSync45(resolvedPath, `${JSON.stringify(raw, null, 2)}
35431
+ writeFileSync46(resolvedPath, `${JSON.stringify(raw, null, 2)}
35271
35432
  `);
35272
35433
  }
35273
35434
  if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
@@ -35288,7 +35449,7 @@ ${f2.tail.trimEnd()}
35288
35449
  throw e;
35289
35450
  }
35290
35451
  const oldName = cfg.ship.name;
35291
- writeFileSync45(cfg.configFile, setShipNameInYaml(readFileSync58(cfg.configFile, "utf8"), newName));
35452
+ writeFileSync46(cfg.configFile, setShipNameInYaml(readFileSync59(cfg.configFile, "utf8"), newName));
35292
35453
  cfg.ship.name = newName;
35293
35454
  let renameMachineId;
35294
35455
  try {
@@ -35335,14 +35496,14 @@ ${f2.tail.trimEnd()}
35335
35496
  process.exit(2);
35336
35497
  };
35337
35498
  if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
35338
- const configText = readFileSync58(cfg.configFile, "utf8");
35499
+ const configText = readFileSync59(cfg.configFile, "utf8");
35339
35500
  if (sub === "check") {
35340
35501
  try {
35341
35502
  const routeArg = value("route") ?? positional[2];
35342
35503
  const found = cfg.routes.find((r) => r.route === routeArg);
35343
35504
  if (!found) throw new ReposError(`no route "${routeArg}" in the config (have: ${cfg.routes.map((r) => r.route).join(", ") || "none"})`);
35344
35505
  const named2 = value("route") ? void 0 : positional[3];
35345
- const dir = named2 ? repoDirOf(configText, dirname38(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
35506
+ const dir = named2 ? repoDirOf(configText, dirname39(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
35346
35507
  const target = reposOf(found).find((t) => resolvePath(t.dir) === dir || t.name === named2);
35347
35508
  const o = target ? found.repoOverrides[target.name] : void 0;
35348
35509
  runReposCheck(dir, {
@@ -35364,9 +35525,9 @@ ${f2.tail.trimEnd()}
35364
35525
  if (sub === "hooks") {
35365
35526
  try {
35366
35527
  const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
35367
- const dir = repoDirOf(configText, dirname38(cfg.configFile), a.route, a.name);
35368
- if (!existsSync60(dir)) throw new ReposError(`${dir} does not exist on disk`);
35369
- const files = { exists: (r) => existsSync60(resolvePath(dir, r)), list: (r) => {
35528
+ const dir = repoDirOf(configText, dirname39(cfg.configFile), a.route, a.name);
35529
+ if (!existsSync61(dir)) throw new ReposError(`${dir} does not exist on disk`);
35530
+ const files = { exists: (r) => existsSync61(resolvePath(dir, r)), list: (r) => {
35370
35531
  try {
35371
35532
  return readdirSync22(resolvePath(dir, r));
35372
35533
  } catch {
@@ -35374,7 +35535,7 @@ ${f2.tail.trimEnd()}
35374
35535
  }
35375
35536
  }, read: (r) => {
35376
35537
  try {
35377
- return readFileSync58(resolvePath(dir, r), "utf8");
35538
+ return readFileSync59(resolvePath(dir, r), "utf8");
35378
35539
  } catch {
35379
35540
  return void 0;
35380
35541
  }
@@ -35416,19 +35577,19 @@ ${f2.tail.trimEnd()}
35416
35577
  let cleared;
35417
35578
  if (clear2) {
35418
35579
  const plan = clearRouteHooks(configText, a.route, a.name);
35419
- if (plan.removed.length > 0) writeFileSync45(cfg.configFile, plan.text);
35580
+ if (plan.removed.length > 0) writeFileSync46(cfg.configFile, plan.text);
35420
35581
  cleared = { file: cfg.configFile, removed: plan.removed };
35421
35582
  }
35422
35583
  if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
35423
35584
  if (write === "route") {
35424
35585
  const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
35425
- writeFileSync45(cfg.configFile, plan.text);
35586
+ writeFileSync46(cfg.configFile, plan.text);
35426
35587
  written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
35427
35588
  } else if (write === "repo") {
35428
35589
  const have = existingRepoConfig(files);
35429
35590
  if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
35430
35591
  const file = resolvePath(dir, ".crew.yaml");
35431
- writeFileSync45(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
35592
+ writeFileSync46(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
35432
35593
  written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
35433
35594
  }
35434
35595
  if (flag("json")) {
@@ -35481,7 +35642,7 @@ ${f2.tail.trimEnd()}
35481
35642
  if (sub === "list" && !routeName) usage2();
35482
35643
  if (sub === "add") {
35483
35644
  try {
35484
- const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync60(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
35645
+ const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync61(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
35485
35646
  routeName = a.route;
35486
35647
  addPath = a.path;
35487
35648
  addName = a.name;
@@ -35507,7 +35668,7 @@ ${f2.tail.trimEnd()}
35507
35668
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
35508
35669
  if (sub === "list" || sub === "add") {
35509
35670
  const liveRoute = cfg.routes.find((r) => r.route === routeName);
35510
- if (liveRoute?.resolved?.reposModelId && existsSync60(resolvedFile) && !dryRun) {
35671
+ if (liveRoute?.resolved?.reposModelId && existsSync61(resolvedFile) && !dryRun) {
35511
35672
  try {
35512
35673
  await hydrateApiKeys([liveRoute]);
35513
35674
  persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
@@ -35516,16 +35677,16 @@ ${f2.tail.trimEnd()}
35516
35677
  }
35517
35678
  }
35518
35679
  let resolvedRemotes;
35519
- if (existsSync60(resolvedFile)) {
35680
+ if (existsSync61(resolvedFile)) {
35520
35681
  try {
35521
- resolvedRemotes = JSON.parse(readFileSync58(resolvedFile, "utf8"));
35682
+ resolvedRemotes = JSON.parse(readFileSync59(resolvedFile, "utf8"));
35522
35683
  } catch {
35523
35684
  }
35524
35685
  }
35525
35686
  const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
35526
35687
  const text2 = configText;
35527
- const base = dirname38(cfg.configFile);
35528
- const isCheckout = (d) => existsSync60(`${d}/.git`);
35688
+ const base = dirname39(cfg.configFile);
35689
+ const isCheckout = (d) => existsSync61(`${d}/.git`);
35529
35690
  try {
35530
35691
  if (sub === "list") {
35531
35692
  if (flag("json")) {
@@ -35535,12 +35696,12 @@ ${f2.tail.trimEnd()}
35535
35696
  base,
35536
35697
  resolved: resolvedRemotes,
35537
35698
  originOf,
35538
- exists: (d) => existsSync60(d),
35699
+ exists: (d) => existsSync61(d),
35539
35700
  isCheckout,
35540
35701
  repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f2) => {
35541
35702
  try {
35542
35703
  const path = resolvePath(d, f2);
35543
- return Object.keys(parseRepoConfig(readFileSync58(path, "utf8"), path).hooks).length > 0;
35704
+ return Object.keys(parseRepoConfig(readFileSync59(path, "utf8"), path).hooks).length > 0;
35544
35705
  } catch {
35545
35706
  return false;
35546
35707
  }
@@ -35557,7 +35718,7 @@ ${f2.tail.trimEnd()}
35557
35718
  for (const r of repos) {
35558
35719
  const origin2 = originOf(r.dir);
35559
35720
  const row = matchRepoName(origin2, resolvedRemotes);
35560
- const note = !existsSync60(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote2(origin2) ?? "this checkout (no origin remote)"}`;
35721
+ const note = !existsSync61(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote2(origin2) ?? "this checkout (no origin remote)"}`;
35561
35722
  process.stdout.write(`${r.name} ${r.dir} ${note}
35562
35723
  `);
35563
35724
  }
@@ -35569,9 +35730,9 @@ ${f2.tail.trimEnd()}
35569
35730
  ` : `${human}
35570
35731
  `);
35571
35732
  const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
35572
- if (existsSync60(plan2.target) && (existsSync60(`${plan2.target}/.git`) || readdirSync22(plan2.target).length > 0)) {
35733
+ if (existsSync61(plan2.target) && (existsSync61(`${plan2.target}/.git`) || readdirSync22(plan2.target).length > 0)) {
35573
35734
  throw new ReposError(
35574
- existsSync60(`${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`
35735
+ existsSync61(`${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`
35575
35736
  );
35576
35737
  }
35577
35738
  if (dryRun) {
@@ -35589,13 +35750,13 @@ ${f2.tail.trimEnd()}
35589
35750
  throw new ReposError(`${e.message}${authHint}
35590
35751
  crew.yaml was not changed`);
35591
35752
  }
35592
- writeFileSync45(cfg.configFile, plan2.text);
35753
+ writeFileSync46(cfg.configFile, plan2.text);
35593
35754
  if (plan2.droppedDir) emit.warn(`crew repos: dropped dir: ${plan2.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:`);
35594
35755
  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}`);
35595
35756
  break;
35596
35757
  }
35597
35758
  const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
35598
- if (!existsSync60(target)) throw new ReposError(`${target} does not exist`);
35759
+ if (!existsSync61(target)) throw new ReposError(`${target} does not exist`);
35599
35760
  let top;
35600
35761
  try {
35601
35762
  top = git(target, ["rev-parse", "--show-toplevel"]);
@@ -35679,15 +35840,15 @@ would need a project first: the tracker has none (\`crew projects add NAME --pre
35679
35840
  const created = await rowTracker.createRepoRow(rowPayload);
35680
35841
  process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
35681
35842
  `);
35682
- if (existsSync60(resolvedFile)) {
35683
- const raw = JSON.parse(readFileSync58(resolvedFile, "utf8"));
35843
+ if (existsSync61(resolvedFile)) {
35844
+ const raw = JSON.parse(readFileSync59(resolvedFile, "utf8"));
35684
35845
  raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
35685
35846
  raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
35686
- writeFileSync45(resolvedFile, `${JSON.stringify(raw, null, 2)}
35847
+ writeFileSync46(resolvedFile, `${JSON.stringify(raw, null, 2)}
35687
35848
  `);
35688
35849
  }
35689
35850
  }
35690
- writeFileSync45(cfg.configFile, plan.text);
35851
+ writeFileSync46(cfg.configFile, plan.text);
35691
35852
  process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
35692
35853
  `);
35693
35854
  } catch (e) {
@@ -36053,7 +36214,7 @@ Waiting for approval`
36053
36214
  ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, then run `crew connect` again");
36054
36215
  }
36055
36216
  if (found.shipNameAdopted && !dryRun) {
36056
- writeFileSync45(cfg.configFile, setShipNameInYaml(readFileSync58(cfg.configFile, "utf8"), found.shipNameAdopted));
36217
+ writeFileSync46(cfg.configFile, setShipNameInYaml(readFileSync59(cfg.configFile, "utf8"), found.shipNameAdopted));
36057
36218
  cfg.ship.name = found.shipNameAdopted;
36058
36219
  }
36059
36220
  if (found.shipRow) {
@@ -36094,10 +36255,10 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36094
36255
  }
36095
36256
  }
36096
36257
  let previous;
36097
- const hadPreviousFile = existsSync60(resolvedPath);
36258
+ const hadPreviousFile = existsSync61(resolvedPath);
36098
36259
  if (hadPreviousFile) {
36099
36260
  try {
36100
- previous = JSON.parse(readFileSync58(resolvedPath, "utf8"));
36261
+ previous = JSON.parse(readFileSync59(resolvedPath, "utf8"));
36101
36262
  } catch {
36102
36263
  }
36103
36264
  }
@@ -36243,12 +36404,12 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36243
36404
  process.stderr.write(`(dry run) would write resolved ids to ${resolvedPath}
36244
36405
  `);
36245
36406
  } else {
36246
- mkdirSync44(dirname38(resolvedPath), { recursive: true });
36407
+ mkdirSync44(dirname39(resolvedPath), { recursive: true });
36247
36408
  if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
36248
36409
  const tmpPath = `${resolvedPath}.tmp${process.pid}`;
36249
- writeFileSync45(tmpPath, `${JSON.stringify(resolved, null, 2)}
36410
+ writeFileSync46(tmpPath, `${JSON.stringify(resolved, null, 2)}
36250
36411
  `);
36251
- renameSync10(tmpPath, resolvedPath);
36412
+ renameSync11(tmpPath, resolvedPath);
36252
36413
  emit.note(`Resolved ids written to ${resolvedPath}`);
36253
36414
  }
36254
36415
  let mintOutcomes = [];
@@ -36315,8 +36476,8 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36315
36476
  process.stderr.write(`(dry run) would write the API key to ${apiKeyFile}
36316
36477
  `);
36317
36478
  } else {
36318
- mkdirSync44(dirname38(apiKeyFile), { recursive: true });
36319
- writeFileSync45(apiKeyFile, `${apiKeyVar}=${apiKey}
36479
+ mkdirSync44(dirname39(apiKeyFile), { recursive: true });
36480
+ writeFileSync46(apiKeyFile, `${apiKeyVar}=${apiKey}
36320
36481
  `, { mode: 384 });
36321
36482
  routineLine(`API key written to ${apiKeyFile}`);
36322
36483
  }
@@ -36340,6 +36501,17 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36340
36501
  }
36341
36502
  );
36342
36503
  let wroteConfig = false;
36504
+ const routeAlreadyInConfig = cfg.routes.some((r) => r.route === route3);
36505
+ let appendReason;
36506
+ let appendedToExisting = false;
36507
+ if (!wizard && !routeAlreadyInConfig) {
36508
+ const appended = planAppendToConfig(CREW_HOME, cfg.configFile, route3, routeBlock, keyPersisted);
36509
+ if (!appended.ok) appendReason = appended.reason;
36510
+ else if (!dryRun) {
36511
+ replaceFileKeepingMode(cfg.configFile, appended.text);
36512
+ appendedToExisting = true;
36513
+ } else appendReason = "dry-run";
36514
+ }
36343
36515
  if (writeFirstRun) {
36344
36516
  wroteConfig = writeNewConfig(wizard.configPath, renderFullConfig(wizard.answers, routeBlock));
36345
36517
  if (!wroteConfig) emit.warn(`${wizard.configPath} appeared while connecting \u2014 leaving it alone`);
@@ -36351,8 +36523,10 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36351
36523
  connectEvents.emit("config", `${wizard.configPath} appeared while connecting; left alone`, { written: false, path: wizard.configPath, reason: "appeared while connecting" });
36352
36524
  } else if (wizard) {
36353
36525
  connectEvents.emit("config", `no key file or keychain entry to name; ${wizard.configPath} not written`, { written: false, path: wizard.configPath, reason: "no-key" });
36526
+ } else if (appendedToExisting) {
36527
+ connectEvents.emit("config", `added the route ${route3} to ${cfg.configFile}, disabled`, { written: true, path: cfg.configFile, appended: true });
36354
36528
  } else {
36355
- connectEvents.emit("config", `${cfg.configFile} already exists; left alone`, { written: false, path: cfg.configFile, reason: "exists" });
36529
+ connectEvents.emit("config", `${cfg.configFile} already exists; left alone`, { written: false, path: cfg.configFile, reason: appendReason ? `exists: ${appendReason}` : "exists" });
36356
36530
  }
36357
36531
  }
36358
36532
  const routeInConfig = cfg.routes.some((r) => r.route === route3);
@@ -36365,7 +36539,13 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
36365
36539
  keys: mintOutcomes.map((m) => ({ role: m.role, action: m.action }))
36366
36540
  }) : "";
36367
36541
  if (routeInConfig) (connectEvents.json ? process.stderr : process.stdout).write(existingReport);
36368
- else if (!wroteConfig) (connectEvents.json ? process.stderr : process.stdout).write(routeBlock);
36542
+ else if (appendedToExisting) {
36543
+ (connectEvents.json ? process.stderr : process.stdout).write(`Added the route ${route3} to ${cfg.configFile}, disabled. Set \`enabled: true\` on it once \`crew doctor ${route3}\` is green.
36544
+ `);
36545
+ } else if (dryRun && appendReason === "dry-run") {
36546
+ (connectEvents.json ? process.stderr : process.stdout).write(`(dry run) would add the route ${route3} to ${cfg.configFile}, disabled.
36547
+ `);
36548
+ } else if (!wroteConfig) (connectEvents.json ? process.stderr : process.stdout).write(routeBlock);
36369
36549
  if (!flag("no-mcp") && apiKey) {
36370
36550
  const replace = value("mcp") === "replace";
36371
36551
  const seen = /* @__PURE__ */ new Set();
@@ -36415,6 +36595,8 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
36415
36595
  }));
36416
36596
  if (!operator) process.stderr.write(` Also set operator in ${resolvedPath} before arming it.
36417
36597
  `);
36598
+ } else if (appendedToExisting) {
36599
+ if (!operator) emit.warn(`no operator resolved: set it in ${resolvedPath} before arming this route`);
36418
36600
  } else if (routeInConfig) {
36419
36601
  if (!operator) emit.warn(`no operator resolved: set it in ${resolvedPath} before arming this route`);
36420
36602
  } else if (operator) {
@@ -36968,10 +37150,10 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
36968
37150
  startupSeconds: cfg.ship.intelStartupSeconds,
36969
37151
  prepare: async (path) => {
36970
37152
  for (const f2 of repoWt.config.worktrees.copy) {
36971
- const src = join67(repoWt.dir, f2);
36972
- if (!existsSync60(src) || existsSync60(join67(path, f2))) continue;
36973
- mkdirSync44(dirOf2(join67(path, f2)), { recursive: true });
36974
- copyFileSync2(src, join67(path, f2));
37153
+ const src = join68(repoWt.dir, f2);
37154
+ if (!existsSync61(src) || existsSync61(join68(path, f2))) continue;
37155
+ mkdirSync44(dirOf2(join68(path, f2)), { recursive: true });
37156
+ copyFileSync2(src, join68(path, f2));
36975
37157
  }
36976
37158
  const setup = repoWt.config.hooks.setup;
36977
37159
  return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
@@ -37195,7 +37377,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
37195
37377
  const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
37196
37378
  const resumed = await runPeriscopeResume({
37197
37379
  find: async () => hit && { row: hit.row, tag: hit.tag },
37198
- worktreeExists: (p) => existsSync60(p),
37380
+ worktreeExists: (p) => existsSync61(p),
37199
37381
  prepareDropFile,
37200
37382
  startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
37201
37383
  relay: hit && previewRelayFor(hit.route) && {
@@ -37298,10 +37480,10 @@ ${where.join("\n")}`);
37298
37480
  },
37299
37481
  prepare: async (path) => {
37300
37482
  for (const f2 of repoP.config.worktrees.copy) {
37301
- const src = join67(repoP.dir, f2);
37302
- if (!existsSync60(src)) continue;
37303
- mkdirSync44(dirOf2(join67(path, f2)), { recursive: true });
37304
- copyFileSync2(src, join67(path, f2));
37483
+ const src = join68(repoP.dir, f2);
37484
+ if (!existsSync61(src)) continue;
37485
+ mkdirSync44(dirOf2(join68(path, f2)), { recursive: true });
37486
+ copyFileSync2(src, join68(path, f2));
37305
37487
  }
37306
37488
  const setup = repoP.config.hooks.setup;
37307
37489
  return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
@@ -37706,7 +37888,7 @@ ${where.join("\n")}`);
37706
37888
  };
37707
37889
  const droppedRoutes = [];
37708
37890
  try {
37709
- const rawCfg = parseYaml3(readFileSync58(cfg.configFile, "utf8"));
37891
+ const rawCfg = parseYaml3(readFileSync59(cfg.configFile, "utf8"));
37710
37892
  for (const r of rawCfg?.routes ?? []) {
37711
37893
  if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
37712
37894
  try {
@@ -37770,7 +37952,7 @@ ${where.join("\n")}`);
37770
37952
  break;
37771
37953
  }
37772
37954
  mkdirSync44(cfg.ship.stateDir, { recursive: true });
37773
- writeFileSync45(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
37955
+ writeFileSync46(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
37774
37956
  `);
37775
37957
  process.stdout.write(
37776
37958
  "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"
@@ -37832,7 +38014,7 @@ ${where.join("\n")}`);
37832
38014
  }
37833
38015
  case "log": {
37834
38016
  try {
37835
- const text2 = readFileSync58(cfg.ship.logFile, "utf8").split("\n");
38017
+ const text2 = readFileSync59(cfg.ship.logFile, "utf8").split("\n");
37836
38018
  process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
37837
38019
  `);
37838
38020
  } catch {
@@ -37856,8 +38038,8 @@ ${where.join("\n")}`);
37856
38038
  };
37857
38039
  if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
37858
38040
  const tracker = new Tracker(route2, cfg.ship);
37859
- const configText = readFileSync58(cfg.configFile, "utf8");
37860
- const cfgBase = dirname38(cfg.configFile);
38041
+ const configText = readFileSync59(cfg.configFile, "utf8");
38042
+ const cfgBase = dirname39(cfg.configFile);
37861
38043
  const configured2 = configuredRepos(configText, route2.route, cfgBase);
37862
38044
  const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
37863
38045
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, route2.route);
@@ -37885,7 +38067,7 @@ ${where.join("\n")}`);
37885
38067
  }
37886
38068
  if (configured2.some((r) => r.dir === dir)) {
37887
38069
  try {
37888
- writeFileSync45(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
38070
+ writeFileSync46(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
37889
38071
  } catch (e) {
37890
38072
  if (e instanceof ReposError) fail2(e.message);
37891
38073
  throw e;
@@ -37893,29 +38075,29 @@ ${where.join("\n")}`);
37893
38075
  }
37894
38076
  if (row) {
37895
38077
  await tracker.deleteRepoRow(row.id);
37896
- if (existsSync60(resolvedFile)) {
37897
- const raw = JSON.parse(readFileSync58(resolvedFile, "utf8"));
38078
+ if (existsSync61(resolvedFile)) {
38079
+ const raw = JSON.parse(readFileSync59(resolvedFile, "utf8"));
37898
38080
  if (raw.repoNames) delete raw.repoNames[row.id];
37899
38081
  if (raw.repoRemotes) delete raw.repoRemotes[row.id];
37900
- writeFileSync45(resolvedFile, `${JSON.stringify(raw, null, 2)}
38082
+ writeFileSync46(resolvedFile, `${JSON.stringify(raw, null, 2)}
37901
38083
  `);
37902
38084
  }
37903
38085
  }
37904
- if (existsSync60(join67(dir, ".git")) && basename17(dir) === SAMPLE_REPO) rmSync27(dir, { recursive: true, force: true });
38086
+ if (existsSync61(join68(dir, ".git")) && basename18(dir) === SAMPLE_REPO) rmSync27(dir, { recursive: true, force: true });
37905
38087
  say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
37906
38088
  break;
37907
38089
  }
37908
38090
  const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
37909
- const fresh = !existsSync60(join67(dir, ".git"));
37910
- if (existsSync60(dir) && fresh && readdirSync22(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
38091
+ const fresh = !existsSync61(join68(dir, ".git"));
38092
+ if (existsSync61(dir) && fresh && readdirSync22(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
37911
38093
  if (dryRun) {
37912
38094
  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`);
37913
38095
  break;
37914
38096
  }
37915
38097
  if (fresh) {
37916
38098
  mkdirSync44(dir, { recursive: true });
37917
- writeFileSync45(join67(dir, "README.md"), SAMPLE_README);
37918
- writeFileSync45(join67(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
38099
+ writeFileSync46(join68(dir, "README.md"), SAMPLE_README);
38100
+ writeFileSync46(join68(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
37919
38101
  const g = (...a) => {
37920
38102
  const r = spawnSync15("git", a, { cwd: dir, encoding: "utf8" });
37921
38103
  if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
@@ -37933,17 +38115,17 @@ ${where.join("\n")}`);
37933
38115
  spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
37934
38116
  });
37935
38117
  repoId = (await tracker.createRepoRow(payload)).id;
37936
- if (existsSync60(resolvedFile)) {
37937
- const raw = JSON.parse(readFileSync58(resolvedFile, "utf8"));
38118
+ if (existsSync61(resolvedFile)) {
38119
+ const raw = JSON.parse(readFileSync59(resolvedFile, "utf8"));
37938
38120
  raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
37939
38121
  raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
37940
- writeFileSync45(resolvedFile, `${JSON.stringify(raw, null, 2)}
38122
+ writeFileSync46(resolvedFile, `${JSON.stringify(raw, null, 2)}
37941
38123
  `);
37942
38124
  }
37943
38125
  }
37944
38126
  if (!configured2.some((r) => r.dir === dir)) {
37945
38127
  try {
37946
- writeFileSync45(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
38128
+ writeFileSync46(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
37947
38129
  } catch (e) {
37948
38130
  if (e instanceof ReposError) fail2(e.message);
37949
38131
  throw e;
@@ -38030,6 +38212,21 @@ ${where.join("\n")}`);
38030
38212
  if (report.some((r) => !r.ok)) process.exitCode = 1;
38031
38213
  break;
38032
38214
  }
38215
+ case "routes": {
38216
+ if (positional[1] !== "available") die("crew routes", "unknown subcommand", "`crew routes available [--json]`", 2);
38217
+ const report = await buildRoutesAvailable(cfg.routes, {
38218
+ userAgent: cfg.ship.userAgent,
38219
+ hostOf: hostFromUrl4,
38220
+ holdsCredential: async (host, address) => {
38221
+ const s = getSessionStore();
38222
+ return !!(await s.get(host, address))?.apiKey;
38223
+ }
38224
+ });
38225
+ process.stdout.write(flag("json") ? `${JSON.stringify({ hosts: report }, null, 2)}
38226
+ ` : formatRoutesAvailable(report, cfg.routes.length > 0));
38227
+ if (report.length > 0 && report.every((h) => "error" in h)) process.exitCode = 1;
38228
+ break;
38229
+ }
38033
38230
  case "projects": {
38034
38231
  if (positional[1] === "add") {
38035
38232
  const rest = positional.slice(2);
@@ -38260,7 +38457,7 @@ ${where.join("\n")}`);
38260
38457
  // `synthesis-tabl-123`. `worktreePrefix` above is kept for
38261
38458
  // config-provenance display; this is the field that actually
38262
38459
  // describes where a worktree lands by default.
38263
- worktreeDirPattern: r.config.worktrees.name ?? (r.config.provenance["worktrees.prefix"] !== "default" ? `${r.config.worktrees.prefix}<number>` : `${basename17(r.dir.replace(/[/\\]+$/, ""))}-<branch>`),
38460
+ worktreeDirPattern: r.config.worktrees.name ?? (r.config.provenance["worktrees.prefix"] !== "default" ? `${r.config.worktrees.prefix}<number>` : `${basename18(r.dir.replace(/[/\\]+$/, ""))}-<branch>`),
38264
38461
  worktreeParent: resolvePath(r.dir, "..")
38265
38462
  })),
38266
38463
  waiting: waiting ? { ticket: waiting.ticket, since: waiting.since, streak: fairness.streak() } : null
@@ -38363,7 +38560,7 @@ ${where.join("\n")}`);
38363
38560
  plan,
38364
38561
  label,
38365
38562
  uid: process.getuid?.() ?? 0,
38366
- system: plan.mechanism === "systemd" && existsSync60(systemUnitPathFor(label)),
38563
+ system: plan.mechanism === "systemd" && existsSync61(systemUnitPathFor(label)),
38367
38564
  stamp: readDaemonStamp(cfg.ship.stateDir)
38368
38565
  });
38369
38566
  })();
@@ -38379,7 +38576,7 @@ ${where.join("\n")}`);
38379
38576
  }
38380
38577
  for (const r of repos) {
38381
38578
  const remote = r.config.branch.remote;
38382
- if (existsSync60(r.dir)) {
38579
+ if (existsSync61(r.dir)) {
38383
38580
  pushAuth.push({
38384
38581
  route: c.route,
38385
38582
  repo: r.name,
@@ -38468,7 +38665,7 @@ ${where.join("\n")}`);
38468
38665
  else passed++;
38469
38666
  }
38470
38667
  if (staleBundle) problems.push({ severity: "blocker", kind: "stale_bundle", message: staleBundle.message, remedy: "npm run build" });
38471
- const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync60, userInfo2().username);
38668
+ const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync61, userInfo2().username);
38472
38669
  if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
38473
38670
  if (!flag("offline")) {
38474
38671
  const shipKind = await doctorShipKind(route2, cfg.ship);
@@ -38565,7 +38762,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
38565
38762
  }
38566
38763
  try {
38567
38764
  const evFile = eventFileFor(cfg.ship.stateDir);
38568
- const evSize = existsSync60(evFile) ? statSync19(evFile).size : 0;
38765
+ const evSize = existsSync61(evFile) ? statSync20(evFile).size : 0;
38569
38766
  R.line(
38570
38767
  evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
38571
38768
  ` : "events log: ok\n"
@@ -38576,7 +38773,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
38576
38773
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
38577
38774
  const abandons = unitAbandonsAgents(unitPlan, (p) => {
38578
38775
  try {
38579
- return readFileSync58(p, "utf8");
38776
+ return readFileSync59(p, "utf8");
38580
38777
  } catch {
38581
38778
  return null;
38582
38779
  }
@@ -38591,7 +38788,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
38591
38788
  const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
38592
38789
  const keeps = unitAbandonsAgents(pPlan, (p) => {
38593
38790
  try {
38594
- return readFileSync58(p, "utf8");
38791
+ return readFileSync59(p, "utf8");
38595
38792
  } catch {
38596
38793
  return null;
38597
38794
  }
@@ -38605,7 +38802,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
38605
38802
  if (host === "linux" && detectSystemd()) {
38606
38803
  const ctl = planDaemonControl(CREW_HOME, host, true);
38607
38804
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
38608
- if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync60(p))) {
38805
+ if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync61(p))) {
38609
38806
  const st = spawnSync15(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
38610
38807
  if (!st.error && st.status !== 0) {
38611
38808
  R.line("daemon unit: WARN installed but not running \u2014 no work is picked up; run `crew reload` (or `crew daemon start`), and `crew install` if the unit still says Restart=on-failure\n");
@@ -38630,8 +38827,8 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
38630
38827
  const changed2 = configChangedAfter(daemonConfigPaths(cfg), daemonStartedAt);
38631
38828
  if (changed2) {
38632
38829
  R.line(
38633
- daemonDead ? `daemon config: WARN ${changed2} changed at ${new Date(statSync19(changed2).mtimeMs).toISOString()} \u2014 no daemon is running; the new config applies when it starts
38634
- ` : `daemon config: WARN ${changed2} changed at ${new Date(statSync19(changed2).mtimeMs).toISOString()} but the daemon started at ${new Date(daemonStartedAt).toISOString()} \u2014 run \`crew reload\`
38830
+ daemonDead ? `daemon config: WARN ${changed2} changed at ${new Date(statSync20(changed2).mtimeMs).toISOString()} \u2014 no daemon is running; the new config applies when it starts
38831
+ ` : `daemon config: WARN ${changed2} changed at ${new Date(statSync20(changed2).mtimeMs).toISOString()} but the daemon started at ${new Date(daemonStartedAt).toISOString()} \u2014 run \`crew reload\`
38635
38832
  `
38636
38833
  );
38637
38834
  }
@@ -38664,7 +38861,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
38664
38861
  for (const r of await resolvedRepos(route2)) {
38665
38862
  const { config } = r;
38666
38863
  R.repo = r.name;
38667
- const worktreePattern = config.worktrees.name ?? (config.provenance["worktrees.prefix"] !== "default" ? `${config.worktrees.prefix}<number>` : `${basename17(r.dir.replace(/[/\\]+$/, ""))}-${effectiveBranchTemplate(config, void 0)}`);
38864
+ const worktreePattern = config.worktrees.name ?? (config.provenance["worktrees.prefix"] !== "default" ? `${config.worktrees.prefix}<number>` : `${basename18(r.dir.replace(/[/\\]+$/, ""))}-${effectiveBranchTemplate(config, void 0)}`);
38668
38865
  R.line(
38669
38866
  `${`repo ${r.name}:`.padEnd(19)}${r.dir}
38670
38867
  worktrees at ../${worktreePattern} (${config.provenance["worktrees.name"] ?? config.provenance["worktrees.prefix"] ?? "default"}), branch ${config.branch.name}