@tablation/crew 0.131.1 → 0.132.2

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 +557 -236
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3731,6 +3731,7 @@ var SHIP_KEYS = /* @__PURE__ */ new Set([
3731
3731
  "periscopeIdleMinutes",
3732
3732
  "intelStartupSeconds",
3733
3733
  "mapTokenBudget",
3734
+ "noopRunRepeats",
3734
3735
  "secretStore",
3735
3736
  "env",
3736
3737
  "runner",
@@ -4087,6 +4088,10 @@ Create the first of those:
4087
4088
  if (!Number.isInteger(mapTokenBudget) || mapTokenBudget < 1) {
4088
4089
  missing.add(`ship.mapTokenBudget must be a positive integer (got "${shipRaw.mapTokenBudget}")`);
4089
4090
  }
4091
+ const noopRunRepeats = shipRaw.noopRunRepeats === void 0 ? void 0 : Number(shipRaw.noopRunRepeats);
4092
+ if (noopRunRepeats !== void 0 && (!Number.isInteger(noopRunRepeats) || noopRunRepeats < 1)) {
4093
+ missing.add(`ship.noopRunRepeats must be a positive integer (got "${shipRaw.noopRunRepeats}")`);
4094
+ }
4090
4095
  const secretStoreRaw = shipRaw.secretStore === void 0 ? "auto" : shipRaw.secretStore;
4091
4096
  if (!isSecretStoreMode(secretStoreRaw)) {
4092
4097
  missing.add(`ship.secretStore must be one of ${SECRET_STORE_MODES.join(" | ")} (got "${String(shipRaw.secretStore)}")`);
@@ -4172,6 +4177,7 @@ Create the first of those:
4172
4177
  periscopeIdleMinutes,
4173
4178
  intelStartupSeconds,
4174
4179
  mapTokenBudget,
4180
+ ...noopRunRepeats !== void 0 ? { noopRunRepeats } : {},
4175
4181
  secretStore,
4176
4182
  env: parseShipEnv(shipRaw.env)
4177
4183
  },
@@ -5457,6 +5463,7 @@ import {
5457
5463
  readdirSync as readdirSync4,
5458
5464
  rmSync as rmSync9
5459
5465
  } from "fs";
5466
+ import { tmpdir as tmpdir2 } from "os";
5460
5467
  import { dirname as dirname10, basename as basename5, join as join19 } from "path";
5461
5468
  var GitError = class extends Error {
5462
5469
  };
@@ -5640,6 +5647,16 @@ function fetchRemote(cwd, remote = "origin") {
5640
5647
  gitOk(cwd, ["fetch", "--quiet", remote, "refs/tags/*:refs/tags/*"]);
5641
5648
  return true;
5642
5649
  }
5650
+ function lsRemoteHeads(url) {
5651
+ const out = gitOk(tmpdir2(), ["ls-remote", "--heads", url]);
5652
+ if (out === null) return null;
5653
+ const heads = /* @__PURE__ */ new Map();
5654
+ for (const line of out.split("\n")) {
5655
+ const [sha, ref] = line.split(" ");
5656
+ if (sha && ref?.startsWith("refs/heads/")) heads.set(ref.slice("refs/heads/".length), sha);
5657
+ }
5658
+ return heads;
5659
+ }
5643
5660
  function remoteConfigured(cwd, remote = "origin") {
5644
5661
  return gitOk(cwd, ["remote", "get-url", remote]) !== null;
5645
5662
  }
@@ -6486,15 +6503,15 @@ import { promisify as promisify2 } from "util";
6486
6503
 
6487
6504
  // src/deprovision-host.ts
6488
6505
  import { spawnSync as spawnSync7 } from "child_process";
6489
- import { existsSync as existsSync29, readdirSync as readdirSync11 } from "fs";
6506
+ import { existsSync as existsSync30, readdirSync as readdirSync11 } from "fs";
6490
6507
 
6491
6508
  // src/interrupted.ts
6492
- import { existsSync as existsSync27, readdirSync as readdirSync9, readFileSync as readFileSync28 } from "fs";
6509
+ import { existsSync as existsSync28, readdirSync as readdirSync9, readFileSync as readFileSync28 } from "fs";
6493
6510
  import { join as join31 } from "path";
6494
6511
 
6495
6512
  // src/agent.ts
6496
6513
  import { spawnSync as spawnSync6 } from "child_process";
6497
- import { readFileSync as readFileSync27, existsSync as existsSync26, statSync as statSync8, mkdirSync as mkdirSync19, writeFileSync as writeFileSync20, createWriteStream, openSync as openSync4, closeSync as closeSync4, readSync } from "fs";
6514
+ import { readFileSync as readFileSync27, existsSync as existsSync27, statSync as statSync8, mkdirSync as mkdirSync19, writeFileSync as writeFileSync20, createWriteStream, openSync as openSync4, closeSync as closeSync4, readSync } from "fs";
6498
6515
  import { StringDecoder } from "string_decoder";
6499
6516
  import { finished } from "stream/promises";
6500
6517
  import { join as join30, dirname as dirname15, basename as basename9 } from "path";
@@ -8417,12 +8434,15 @@ var BeforeFirstEditTracker = class {
8417
8434
  };
8418
8435
 
8419
8436
  // src/agent-log.ts
8420
- import { existsSync as existsSync22, mkdirSync as mkdirSync16, readdirSync as readdirSync7, readFileSync as readFileSync23, rmSync as rmSync13, writeFileSync as writeFileSync17 } from "fs";
8437
+ import { existsSync as existsSync23, mkdirSync as mkdirSync16, readdirSync as readdirSync7, readFileSync as readFileSync23, rmSync as rmSync13, writeFileSync as writeFileSync17 } from "fs";
8421
8438
  import { join as join25 } from "path";
8422
8439
 
8423
8440
  // src/pending-backoff.ts
8424
8441
  var sleepBackoff = (attempts) => Math.min(6e4 * 2 ** Math.max(0, attempts - 1), 30 * 6e4);
8425
8442
 
8443
+ // src/handoff-guard.ts
8444
+ import { existsSync as existsSync22 } from "fs";
8445
+
8426
8446
  // src/ticket-branch.ts
8427
8447
  import { basename as basename7 } from "path";
8428
8448
 
@@ -9459,6 +9479,9 @@ function branchTemplates(cfg, t) {
9459
9479
  function pushedBranchForTicket(cfg, t, role) {
9460
9480
  return branchRenderer(t, role, cfg.branch.lowercase)(branchTemplates(cfg, t).push);
9461
9481
  }
9482
+ function branchCandidatesForTicket(cfg, t, role) {
9483
+ return branchCandidates(t.issue_id, branchTemplates(cfg, t), branchRenderer(t, role, cfg.branch.lowercase));
9484
+ }
9462
9485
  function existingBranchForTicket(dir, cfg, t, role) {
9463
9486
  return branchForIssue(dir, t.issue_id, branchTemplates(cfg, t), branchRenderer(t, role, cfg.branch.lowercase));
9464
9487
  }
@@ -9847,6 +9870,28 @@ function remoteTip(dir, remote, branch) {
9847
9870
  if (out === null) return null;
9848
9871
  return out.split("\n").find((l) => l.endsWith(` refs/heads/${branch}`))?.split(" ")[0] ?? "";
9849
9872
  }
9873
+ function inspectRemoteHandoff(origin, cfg, ticket, role) {
9874
+ const remote = cfg.branch.remote;
9875
+ const heads = lsRemoteHeads(origin);
9876
+ if (!heads) return { kind: "unverified", why: `could not reach \`${remote}\` (${origin}) to check the pushed branch` };
9877
+ for (const c of branchCandidatesForTicket(cfg, ticket, role)) {
9878
+ const hit = c.endsWith("*") ? [...heads.keys()].find((b) => b.startsWith(c.slice(0, -1))) : heads.has(c) ? c : void 0;
9879
+ if (hit) return { kind: "pushed", branch: hit, sha: heads.get(hit), remote };
9880
+ }
9881
+ return {
9882
+ kind: "bounce",
9883
+ branch: null,
9884
+ remote,
9885
+ local: null,
9886
+ origin: null,
9887
+ reason: `no branch for this ticket is on \`${remote}\`; the run's clone was deleted with its sandbox, so nothing it did not push can be recovered`
9888
+ };
9889
+ }
9890
+ function describeGuardError(e, dir) {
9891
+ const msg = e.message;
9892
+ if (!/ENOENT/.test(msg)) return msg;
9893
+ return dir && !existsSync22(dir) ? `the run's clone at ${dir} is gone` : "git is not installed on this machine";
9894
+ }
9850
9895
  function inspectHandoff(dir, cfg, ticket, role) {
9851
9896
  const remote = cfg.branch.remote;
9852
9897
  if (!remoteConfigured(dir, remote)) return { kind: "unverified", why: `no remote \`${remote}\` configured` };
@@ -9964,7 +10009,7 @@ async function enforceHandoff(i) {
9964
10009
  i.log.emit(`${t.issue_id} is at ${t.status}, not handed off \u2014 nothing to check`, log);
9965
10010
  return { kind: "not-handed-off" };
9966
10011
  }
9967
- const v = inspectHandoff(i.dir, i.cfg, t, i.role);
10012
+ const v = i.origin ? inspectRemoteHandoff(i.origin, i.cfg, t, i.role) : inspectHandoff(i.dir, i.cfg, t, i.role);
9968
10013
  if (v.kind === "unverified") {
9969
10014
  i.log.warn(`${t.issue_id} is at ${t.status} but the push was not checked: ${v.why}`, log);
9970
10015
  return { kind: "unverified", why: v.why };
@@ -10008,7 +10053,7 @@ async function enforceHandoff(i) {
10008
10053
  i.log.warn(`${t.issue_id} was taken over by another ship during this run \u2014 left alone`, log);
10009
10054
  return { kind: "unverified", why: "ticket was taken over during this run" };
10010
10055
  }
10011
- if (!v.local) {
10056
+ if (!v.local && !i.origin) {
10012
10057
  i.log.warn(`${t.issue_id} has no local branch on this ship, so it is not this ship's hand-off to bounce: ${v.reason}`, log);
10013
10058
  return { kind: "unverified", why: "no local branch on this ship" };
10014
10059
  }
@@ -10046,8 +10091,9 @@ async function enforceHandoff(i) {
10046
10091
  i.log.warn(`${t.issue_id} bounced back to ${i.contract.statuses.building}: ${v.reason}`, log);
10047
10092
  return { kind: "bounced" };
10048
10093
  } catch (e) {
10049
- i.log.warn(`could not check the hand-off: ${e.message}`, { step: "handoff" });
10050
- return { kind: "failed", why: e.message };
10094
+ const why = describeGuardError(e, i.dir);
10095
+ i.log.warn(`could not check the hand-off: ${why}`, { step: "handoff" });
10096
+ return { kind: "failed", why };
10051
10097
  }
10052
10098
  }
10053
10099
  async function guardRunHandoff(route2, ship, tracker, role, workingId, log, since2) {
@@ -10055,16 +10101,23 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
10055
10101
  if (!workingId || role !== "dev" && role !== "design" && role !== "qa") return null;
10056
10102
  const seatId = route2.resolved?.seats[role];
10057
10103
  if (!seatId) return null;
10104
+ let checkoutDir;
10058
10105
  try {
10059
10106
  const t = await tracker.ticket(workingId);
10060
10107
  const resolved = repoConfigFor(route2, t);
10061
10108
  if (!resolved) return null;
10062
10109
  const { target, cfg } = resolved;
10110
+ checkoutDir = target.dir;
10063
10111
  if (role === "qa") {
10064
10112
  await retireRunWorktree(tracker, target.dir, cfg, t, role, seatId, ship.name, log);
10065
10113
  return null;
10066
10114
  }
10067
10115
  const affinity = await tracker.claimAffinity();
10116
+ const origin = ship.runner === "sandbox" ? sandboxOriginFor(route2, target.name) : void 0;
10117
+ if (ship.runner === "sandbox" && !origin) {
10118
+ log.warn(`${t.issue_id}: the push was not checked: this ship cannot place the remote of ${target.name}`, { ticket: t.issue_id, step: "handoff" });
10119
+ return null;
10120
+ }
10068
10121
  const outcome = replayed.includes(workingId) ? { kind: "pushed", sha: "" } : await enforceHandoff({
10069
10122
  writer: tracker,
10070
10123
  contract: tracker.contract,
@@ -10076,19 +10129,21 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
10076
10129
  shipName: ship.name,
10077
10130
  hold: affinity ? { column: affinity.column, shipId: affinity.shipId } : void 0,
10078
10131
  since: since2,
10079
- log
10132
+ log,
10133
+ ...origin ? { origin } : {}
10080
10134
  });
10081
- if (outcome.kind === "pushed") await retireRunWorktree(tracker, target.dir, cfg, t, role, seatId, ship.name, log);
10135
+ if (origin) {
10136
+ } else if (outcome.kind === "pushed") await retireRunWorktree(tracker, target.dir, cfg, t, role, seatId, ship.name, log);
10082
10137
  else {
10083
10138
  const branch = existingBranchForTicket(target.dir, cfg, t, role);
10084
10139
  if (branch && dropEmptyRunBranch(target.dir, cfg, branch)) {
10085
10140
  log.emit(`${t.issue_id}: dropped ${branch} \u2014 the run made no commits beyond ${cfg.branch.base}`, { ticket: t.issue_id, step: "handoff" });
10086
10141
  }
10087
10142
  }
10088
- if (since2) await guardRunStrays(route2, ship, tracker, role, workingId, since2, log);
10143
+ if (since2 && !origin) await guardRunStrays(route2, ship, tracker, role, workingId, since2, log);
10089
10144
  return outcome;
10090
10145
  } catch (e) {
10091
- log.warn(`could not check the hand-off: ${e.message}`, { step: "handoff" });
10146
+ log.warn(`could not check the hand-off: ${describeGuardError(e, checkoutDir)}`, { step: "handoff" });
10092
10147
  return null;
10093
10148
  }
10094
10149
  }
@@ -10502,7 +10557,7 @@ function queueAgentRun(stateDir, name, q2) {
10502
10557
  }
10503
10558
  async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
10504
10559
  const dir = queueDir(stateDir);
10505
- if (!existsSync22(dir)) return 0;
10560
+ if (!existsSync23(dir)) return 0;
10506
10561
  let sent = 0;
10507
10562
  for (const f of readdirSync7(dir).filter((n) => n.endsWith(".json")).sort()) {
10508
10563
  const path = join25(dir, f);
@@ -10555,7 +10610,7 @@ function queueTicketCounters(stateDir, name, q2) {
10555
10610
  }
10556
10611
  async function replayQueuedTicketCounters(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
10557
10612
  const dir = countersDir(stateDir);
10558
- if (!existsSync22(dir)) return 0;
10613
+ if (!existsSync23(dir)) return 0;
10559
10614
  let sent = 0;
10560
10615
  for (const f of readdirSync7(dir).filter((n) => n.endsWith(".json")).sort()) {
10561
10616
  const path = join25(dir, f);
@@ -10823,10 +10878,10 @@ var HandoffTranscriptTracker = class {
10823
10878
  import { createHash as createHash4 } from "crypto";
10824
10879
  import { spawn as spawn3 } from "child_process";
10825
10880
  import { execFileSync as execFileSync7 } from "child_process";
10826
- import { existsSync as existsSync23, mkdirSync as mkdirSync17, readFileSync as readFileSync24, renameSync as renameSync3, writeFileSync as writeFileSync18, rmSync as rmSync14 } from "fs";
10881
+ import { existsSync as existsSync24, mkdirSync as mkdirSync17, readFileSync as readFileSync24, renameSync as renameSync3, writeFileSync as writeFileSync18, rmSync as rmSync14 } from "fs";
10827
10882
  import { dirname as dirname13, join as join26 } from "path";
10828
10883
  import { fileURLToPath } from "url";
10829
- import { tmpdir as tmpdir2 } from "os";
10884
+ import { tmpdir as tmpdir3 } from "os";
10830
10885
  var SANDBOX_BASE_IMAGE = "nvcr.io/nvidia/base/ubuntu:24.04";
10831
10886
  var SANDBOX_OPENSHELL_VERSION = "0.1.6";
10832
10887
  var SANDBOX_CLAUDE_VERSION = "2.1.309";
@@ -10841,7 +10896,7 @@ var SANDBOX_BRIDGE_PATH = `${CREW_PREFIX}/bin/intel-bridge`;
10841
10896
  function readBridgeBundle() {
10842
10897
  const here = dirname13(fileURLToPath(import.meta.url));
10843
10898
  for (const p of [join26(here, "sandbox-intel-bridge.cjs"), join26(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
10844
- if (existsSync23(p)) return readFileSync24(p, "utf8");
10899
+ if (existsSync24(p)) return readFileSync24(p, "utf8");
10845
10900
  }
10846
10901
  return void 0;
10847
10902
  }
@@ -11038,6 +11093,17 @@ function sandboxImageFor(state, repo) {
11038
11093
  function sandboxImageForRun(state, repo, declares) {
11039
11094
  return (declares && repo ? sandboxImageFor(state, repo) : null) ?? sandboxImageFor(state, SHIP_SANDBOX_KEY);
11040
11095
  }
11096
+ function sandboxImageMissing(state, repo, declares) {
11097
+ return declares && Boolean(repo) && sandboxImageFor(state, repo) === null;
11098
+ }
11099
+ function sandboxMissingItem(repo, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
11100
+ return {
11101
+ kind: "sandbox_build_failed",
11102
+ key: sandboxFailedKey(repo),
11103
+ since: nowIso,
11104
+ message: `${repo}: its sandbox image has not been built on this ship, so its tickets are skipped until it is (the build runs between passes; \`crew sandbox build\` forces it)`
11105
+ };
11106
+ }
11041
11107
  function sandboxImageStatus(state, plan) {
11042
11108
  const s = state[plan.repo];
11043
11109
  const current = s?.tags[0];
@@ -11090,7 +11156,7 @@ async function buildSandboxImage(plan, deps) {
11090
11156
  const builtLayers = [];
11091
11157
  for (const layer of plan.layers) {
11092
11158
  if (deps.hasImage(layer.tag)) continue;
11093
- const ctx = join26(tmpdir2(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
11159
+ const ctx = join26(tmpdir3(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
11094
11160
  mkdirSync17(ctx, { recursive: true });
11095
11161
  try {
11096
11162
  writeFileSync18(join26(ctx, "Dockerfile"), layer.dockerfile);
@@ -11115,7 +11181,7 @@ async function buildSandboxImage(plan, deps) {
11115
11181
  state[plan.repo] = { tags: tags.slice(0, KEEP_TAGS) };
11116
11182
  writeSandboxState(deps.stateDir, state);
11117
11183
  for (const t of dropped) deps.removeImage(t.tag);
11118
- return { kind: "built", tag: plan.tag, builtLayers };
11184
+ return builtLayers.length === 0 ? { kind: "adopted", tag: plan.tag } : { kind: "built", tag: plan.tag, builtLayers };
11119
11185
  }
11120
11186
  var sandboxFailedKey = (repo) => `sandbox_build_failed:${repo}`;
11121
11187
  function sandboxFailedItem(repo, tag, layer, logPath, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
@@ -11136,15 +11202,16 @@ async function sandboxBuildTick(repos, deps, force = false) {
11136
11202
  deps.clear(sandboxFailedKey(r.name));
11137
11203
  continue;
11138
11204
  }
11139
- if (!force && state?.failure?.tag === plan.tag && nowMs - Date.parse(state.failure.at) < SANDBOX_RETRY_AFTER_MS) continue;
11140
- deps.log(`sandbox image for ${r.name}: building ${plan.tag}`);
11205
+ const present = !upToDate && deps.hasImage(plan.tag);
11206
+ if (!force && !present && state?.failure?.tag === plan.tag && nowMs - Date.parse(state.failure.at) < SANDBOX_RETRY_AFTER_MS) continue;
11207
+ deps.log(`sandbox image for ${r.name}: ${present ? `found ${plan.tag} in the engine, recording it` : `building ${plan.tag}`}`);
11141
11208
  const out = await buildSandboxImage(plan, deps);
11142
11209
  if (out.kind === "failed") {
11143
11210
  deps.raise(sandboxFailedItem(r.name, out.tag, out.layer, out.logPath));
11144
11211
  deps.log(`sandbox image for ${r.name}: build failed at the ${out.layer} layer, log ${out.logPath}`);
11145
11212
  } else {
11146
11213
  deps.clear(sandboxFailedKey(r.name));
11147
- deps.log(`sandbox image for ${r.name}: ${out.kind === "built" ? `built ${out.tag}` : `${out.tag} already built`}`);
11214
+ deps.log(`sandbox image for ${r.name}: ${out.kind === "built" ? `built ${out.tag}` : out.kind === "adopted" ? `recorded ${out.tag}` : `${out.tag} already built`}`);
11148
11215
  }
11149
11216
  return r.name;
11150
11217
  }
@@ -11196,7 +11263,7 @@ function expandSkillMarkers(text2, lookup2, opts = {}) {
11196
11263
  }
11197
11264
 
11198
11265
  // src/skills.ts
11199
- import { readFileSync as readFileSync26, readdirSync as readdirSync8, existsSync as existsSync25 } from "fs";
11266
+ import { readFileSync as readFileSync26, readdirSync as readdirSync8, existsSync as existsSync26 } from "fs";
11200
11267
  import { join as join28 } from "path";
11201
11268
  import { parse as parseYaml } from "yaml";
11202
11269
  import { TablationClient as TablationClient3, StaleWriteError as StaleWriteError3, TablationApiError as TablationApiError2 } from "@tablation/client";
@@ -11213,7 +11280,7 @@ ${additions}`;
11213
11280
  }
11214
11281
 
11215
11282
  // src/agents.ts
11216
- import { readFileSync as readFileSync25, existsSync as existsSync24 } from "fs";
11283
+ import { readFileSync as readFileSync25, existsSync as existsSync25 } from "fs";
11217
11284
  import { join as join27 } from "path";
11218
11285
  import { TablationClient as TablationClient2, StaleWriteError as StaleWriteError2, TablationApiError } from "@tablation/client";
11219
11286
  var PERSONA_NAME = {
@@ -11229,10 +11296,10 @@ var AgentsSyncError = class extends Error {
11229
11296
  };
11230
11297
  function personaDefaultPrompt(promptsDir, role) {
11231
11298
  const briefPath = join27(promptsDir, "personas", `lane-${role}.md`);
11232
- if (!existsSync24(briefPath)) throw new AgentsSyncError(`no brief at ${briefPath}`);
11299
+ if (!existsSync25(briefPath)) throw new AgentsSyncError(`no brief at ${briefPath}`);
11233
11300
  if (SELF_CONTAINED_ROLES.has(role)) return readFileSync25(briefPath, "utf8");
11234
11301
  const commonPath = join27(promptsDir, "personas", "common.md");
11235
- if (!existsSync24(commonPath)) return readFileSync25(briefPath, "utf8");
11302
+ if (!existsSync25(commonPath)) return readFileSync25(briefPath, "utf8");
11236
11303
  return `${readFileSync25(commonPath, "utf8")}${readFileSync25(briefPath, "utf8")}`;
11237
11304
  }
11238
11305
  async function resolveAgentId(route2, role, opts) {
@@ -11694,7 +11761,7 @@ function parseSkillFile(path) {
11694
11761
  }
11695
11762
  function listLocalSkills(promptsDir) {
11696
11763
  const dir = join28(promptsDir, "skills");
11697
- if (!existsSync25(dir)) return [];
11764
+ if (!existsSync26(dir)) return [];
11698
11765
  return readdirSync8(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(join28(dir, f)));
11699
11766
  }
11700
11767
  async function syncSkills(route2, opts) {
@@ -11882,7 +11949,7 @@ function skillMarkerWarnings(promptsDir, personaPrompts) {
11882
11949
  import { spawn as spawn4, execFile, execFileSync as execFileSync8 } from "child_process";
11883
11950
  import { mkdtempSync, mkdirSync as mkdirSync18, writeFileSync as writeFileSync19, rmSync as rmSync15 } from "fs";
11884
11951
  import { createHash as createHash5 } from "crypto";
11885
- import { tmpdir as tmpdir3 } from "os";
11952
+ import { tmpdir as tmpdir4 } from "os";
11886
11953
  import { basename as basename8, dirname as dirname14, join as join29 } from "path";
11887
11954
  import { promisify } from "util";
11888
11955
 
@@ -12040,7 +12107,8 @@ var SandboxRunner = class {
12040
12107
  await this.deleteQuietly(name);
12041
12108
  throw new Error(`openshell could not create the sandbox: ${describeExecError(e)}`);
12042
12109
  }
12043
- o.emit.emit(`sandbox_created: ${name}`, { role: plan.role, data: { event: "sandbox_created", sandbox: name, ms: Date.now() - t0 } });
12110
+ const imageNote = plan.sandboxImageReason ? ` (image ${image ?? "default"}: ${plan.sandboxImageReason})` : "";
12111
+ o.emit.emit(`sandbox_created: ${name}${imageNote}`, { role: plan.role, data: { event: "sandbox_created", sandbox: name, ms: Date.now() - t0, ...plan.sandboxImageReason ? { image: image ?? null, imageReason: plan.sandboxImageReason } : {} } });
12044
12112
  const handle = { runner: "sandbox", sandbox: name, sandboxBin: cfg.bin };
12045
12113
  if (generated) {
12046
12114
  const hosts = generated.groups.flatMap((g) => g.endpoints.map((e) => `${e.host}:${e.port}`));
@@ -12066,7 +12134,7 @@ var SandboxRunner = class {
12066
12134
  const harness = cfg.agentBin ?? basename8(plan.bin);
12067
12135
  const viaUpload = Buffer.byteLength(plan.prompt) > SANDBOX_STDIN_LIMIT;
12068
12136
  if (viaUpload) {
12069
- const tmp = mkdtempSync(join29(tmpdir3(), "crew-prompt-"));
12137
+ const tmp = mkdtempSync(join29(tmpdir4(), "crew-prompt-"));
12070
12138
  try {
12071
12139
  const file = join29(tmp, "prompt.txt");
12072
12140
  writeFileSync19(file, plan.prompt, { mode: 384 });
@@ -12207,8 +12275,8 @@ function sandboxPolicyInputFor(route2, toolchain, o) {
12207
12275
  const repos = reposOf(route2);
12208
12276
  const forgeHosts = [...new Set(repos.map((r) => r.forgeHost ?? "github.com"))];
12209
12277
  const dir = repos.find((r) => r.name === o.repo)?.dir ?? route2.dir;
12210
- let declared = null;
12211
- try {
12278
+ let declared = o.contract ?? null;
12279
+ if (o.contract === void 0) try {
12212
12280
  declared = loadRepoConfig(dir);
12213
12281
  } catch {
12214
12282
  }
@@ -12241,14 +12309,21 @@ function sandboxLspPluginFor(route2, repo) {
12241
12309
  return void 0;
12242
12310
  }
12243
12311
  }
12244
- function sandboxImageOf(route2, repo, stateDir) {
12312
+ function sandboxImageOf(route2, repo, stateDir, contract) {
12245
12313
  let declares = false;
12246
- try {
12247
- const dir = reposOf(route2).find((r) => r.name === repo)?.dir ?? route2.dir;
12248
- declares = Boolean(loadRepoConfig(dir)?.sandbox);
12249
- } catch {
12314
+ if (contract !== void 0) declares = Boolean(contract?.sandbox);
12315
+ else {
12316
+ try {
12317
+ const dir = reposOf(route2).find((r) => r.name === repo)?.dir ?? route2.dir;
12318
+ declares = Boolean(loadRepoConfig(dir)?.sandbox);
12319
+ } catch {
12320
+ }
12250
12321
  }
12251
- return sandboxImageForRun(readSandboxState(stateDir), repo, declares) ?? void 0;
12322
+ const state = readSandboxState(stateDir);
12323
+ if (sandboxImageMissing(state, repo, declares)) return { reason: "refused: image missing" };
12324
+ const image = sandboxImageForRun(state, repo, declares) ?? void 0;
12325
+ const reason = !declares ? "ship layer: repository declares no sandbox" : "repository image";
12326
+ return { image, reason };
12252
12327
  }
12253
12328
  var AgentSpawnError = class extends AgentError {
12254
12329
  };
@@ -12333,18 +12408,18 @@ function codeBridgeFor(o, harness) {
12333
12408
  }
12334
12409
  function planAgentRun(o) {
12335
12410
  const briefPath = join30(o.route.promptsDir, "personas", `lane-${o.role}.md`);
12336
- if (!existsSync26(briefPath)) {
12411
+ if (!existsSync27(briefPath)) {
12337
12412
  throw new AgentError(`no brief at ${briefPath} \u2014 refusing to run an unscoped session`);
12338
12413
  }
12339
12414
  const commonPath = join30(o.route.promptsDir, "personas", "common.md");
12340
- const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) && existsSync26(commonPath);
12415
+ const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) && existsSync27(commonPath);
12341
12416
  const now = o.now ?? (() => Date.now());
12342
12417
  const routeLabel = routeSlug(o.route.route);
12343
12418
  const ownDigest = o.runId ? digestPathFor(o.stateDir, routeLabel, o.role, o.runId) : void 0;
12344
- const digestPath2 = ownDigest && existsSync26(ownDigest) ? ownDigest : digestPathFor(o.stateDir, routeLabel, o.role);
12419
+ const digestPath2 = ownDigest && existsSync27(ownDigest) ? ownDigest : digestPathFor(o.stateDir, routeLabel, o.role);
12345
12420
  let digest;
12346
12421
  let ageSeconds;
12347
- if (existsSync26(digestPath2)) {
12422
+ if (existsSync27(digestPath2)) {
12348
12423
  ageSeconds = Math.floor((now() - statSync8(digestPath2).mtimeMs) / 1e3);
12349
12424
  if (ageSeconds <= DIGEST_MAX_AGE_SECONDS) digest = readFileSync27(digestPath2, "utf8");
12350
12425
  }
@@ -12392,7 +12467,8 @@ function planAgentRun(o) {
12392
12467
  const code = codeBridgeFor(o, adapter.harness);
12393
12468
  const sandboxLsp = o.ship.runner === "sandbox" && adapter.harness === "claude" ? sandboxLspPluginFor(o.route, o.repo) : void 0;
12394
12469
  const sandboxOrigin = o.ship.runner === "sandbox" ? sandboxOriginFor(o.route, o.repo) : void 0;
12395
- const sandboxImage = o.ship.runner === "sandbox" ? sandboxImageOf(o.route, o.repo, o.stateDir) : void 0;
12470
+ const sandboxChoice = o.ship.runner === "sandbox" ? sandboxImageOf(o.route, o.repo, o.stateDir, o.repoContract) : void 0;
12471
+ const sandboxImage = sandboxChoice?.image;
12396
12472
  const sandboxFiles = [...code?.files ?? [], ...sandboxLsp?.files ?? []];
12397
12473
  const invocation = adapter.invocation(toolchain, {
12398
12474
  code,
@@ -12448,7 +12524,8 @@ function planAgentRun(o) {
12448
12524
  ...o.ship.sandbox ? { sandboxConfig: o.ship.sandbox } : {},
12449
12525
  ...sandboxOrigin ? { sandboxOrigin } : {},
12450
12526
  ...sandboxImage ? { sandboxImage } : {},
12451
- sandboxPolicy: sandboxPolicyInputFor(o.route, toolchain, { harnessBin: invocation.bin, repo: o.repo, sandbox: o.ship.sandbox }),
12527
+ ...sandboxChoice ? { sandboxImageReason: sandboxChoice.reason } : {},
12528
+ sandboxPolicy: sandboxPolicyInputFor(o.route, toolchain, { harnessBin: invocation.bin, repo: o.repo, sandbox: o.ship.sandbox, contract: o.repoContract }),
12452
12529
  ...sandboxFiles.length ? { sandboxFiles } : {}
12453
12530
  } : {},
12454
12531
  resolution: { toolchain: seat.toolchainWhy, model: seat.modelWhy },
@@ -13106,7 +13183,7 @@ var pidAlive = (pid) => {
13106
13183
  };
13107
13184
  function runFinished(streamPath) {
13108
13185
  const path = `${streamPath}.meta.json`;
13109
- if (!existsSync27(path)) return false;
13186
+ if (!existsSync28(path)) return false;
13110
13187
  try {
13111
13188
  return JSON.parse(readFileSync28(path, "utf8")).running !== true;
13112
13189
  } catch {
@@ -13115,7 +13192,7 @@ function runFinished(streamPath) {
13115
13192
  }
13116
13193
  function orphanedStreams(o) {
13117
13194
  const dir = join31(o.stateDir, "streams");
13118
- if (!existsSync27(dir)) return [];
13195
+ if (!existsSync28(dir)) return [];
13119
13196
  const ownerAlive = o.isOwnerAlive ?? pidAlive;
13120
13197
  const out = [];
13121
13198
  for (const name of readdirSync9(dir)) {
@@ -13173,11 +13250,11 @@ async function reconcileRuns(o) {
13173
13250
  }
13174
13251
 
13175
13252
  // src/live-runs.ts
13176
- import { existsSync as existsSync28, readdirSync as readdirSync10, statSync as statSync9 } from "fs";
13253
+ import { existsSync as existsSync29, readdirSync as readdirSync10, statSync as statSync9 } from "fs";
13177
13254
  import { join as join32 } from "path";
13178
13255
  function liveRuns(stateDir, isAlive = runIsAlive) {
13179
13256
  const dir = join32(stateDir, "streams");
13180
- if (!existsSync28(dir)) return [];
13257
+ if (!existsSync29(dir)) return [];
13181
13258
  const out = [];
13182
13259
  for (const name of readdirSync10(dir)) {
13183
13260
  if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
@@ -13193,7 +13270,7 @@ function runActivity(stateDir, isAlive = runIsAlive) {
13193
13270
  const activeRuns = liveRuns(stateDir, isAlive).length;
13194
13271
  const dir = join32(stateDir, "streams");
13195
13272
  let newest = 0;
13196
- if (existsSync28(dir)) {
13273
+ if (existsSync29(dir)) {
13197
13274
  for (const name of readdirSync10(dir)) {
13198
13275
  if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
13199
13276
  const streamPath = join32(dir, name);
@@ -13291,7 +13368,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
13291
13368
  if (host === "windows") return [];
13292
13369
  const ctx = installContext();
13293
13370
  const systemd = detectSystemd();
13294
- return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) => existsSync29(p));
13371
+ return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) => existsSync30(p));
13295
13372
  };
13296
13373
  return {
13297
13374
  liveRuns: () => liveRuns(stateDir).map((r) => ({ role: r.role, route: r.route, pid: r.pid, ticketRecordId: r.ticketRecordId ?? void 0, streamPath: r.streamPath })),
@@ -13352,7 +13429,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
13352
13429
  },
13353
13430
  remaining() {
13354
13431
  const left = [];
13355
- if (existsSync29(cfg.configFile)) left.push(`config ${cfg.configFile}`);
13432
+ if (existsSync30(cfg.configFile)) left.push(`config ${cfg.configFile}`);
13356
13433
  for (const h of forgeHosts()) if (hasForgeToken(cfg.ship.forges, h, stateDir)) left.push(`forge token for ${h}`);
13357
13434
  try {
13358
13435
  for (const k of readdirSync11(keysDir(stateDir))) left.push(`seat key ${k}`);
@@ -13377,6 +13454,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
13377
13454
  var execFileP2 = promisify2(execFile2);
13378
13455
  var realExec2 = (bin, args, o) => execFileP2(bin, args, { env: o?.env ?? process.env, maxBuffer: 16 * 1024 * 1024 });
13379
13456
  var OPENSHELL_ATTACHABLE_LABEL = "openshell.ai/sandbox-attachable=true";
13457
+ var OPENSHELL_ATTACHABLE_KEY = "openshell.ai/sandbox-attachable";
13380
13458
  var OPENSHELL_WORKSPACE_LABEL = "openshell.ai/sandbox-attachable-workspace";
13381
13459
  var VOLUME_ROOT = "/cache";
13382
13460
  var SANDBOX_WORKSPACE = "default";
@@ -13526,12 +13604,20 @@ var SandboxCache = class {
13526
13604
  engine(args, env) {
13527
13605
  return this.exec(this.s.engine, args, { env });
13528
13606
  }
13529
- /** Creates the volume with the labels OpenShell and `crew deprovision` look for, if it is not there. */
13607
+ /**
13608
+ * Makes sure the volume exists WITH the labels OpenShell and `crew deprovision` look for (CREW-3013).
13609
+ * Every mount of the volume by name goes through here first (`helper`): docker creates a named volume
13610
+ * unlabeled on first `-v` use, and the gateway then refuses to attach it to any sandbox for the life
13611
+ * of the host. A volume that exists without the required labels cannot be relabeled in place, so it is
13612
+ * recreated when it holds nothing, and otherwise refused with the reset remedy (never silently wiped).
13613
+ * Returns true when it created the volume.
13614
+ */
13530
13615
  async ensureVolume() {
13531
- try {
13532
- await this.engine(["volume", "inspect", this.s.volume]);
13533
- return false;
13534
- } catch {
13616
+ const labels = await this.volumeLabels();
13617
+ if (labels) {
13618
+ if (this.labelsOk(labels)) return false;
13619
+ if (!await this.volumeEmpty()) throw new Error(`${this.labelProblem(labels)}; run \`crew sandbox cache --reset\` to recreate it`);
13620
+ await this.engine(["volume", "rm", "--force", this.s.volume]);
13535
13621
  }
13536
13622
  await this.engine([
13537
13623
  "volume",
@@ -13548,6 +13634,31 @@ var SandboxCache = class {
13548
13634
  ]);
13549
13635
  return true;
13550
13636
  }
13637
+ /** Both OpenShell labels as the existing volume carries them (null when unset), or null when the volume is absent. */
13638
+ async volumeLabels() {
13639
+ let stdout;
13640
+ try {
13641
+ ({ stdout } = await this.engine(["volume", "inspect", "--format", `{{index .Labels "${OPENSHELL_ATTACHABLE_KEY}"}}|{{index .Labels "${OPENSHELL_WORKSPACE_LABEL}"}}`, this.s.volume]));
13642
+ } catch {
13643
+ return null;
13644
+ }
13645
+ const [a, w] = stdout.trim().split("|");
13646
+ const val = (v) => v && v !== "<no value>" ? v : null;
13647
+ return { attachable: val(a), workspace: val(w) };
13648
+ }
13649
+ /** True when the labels are what the gateway needs: attachable, and for the workspace sandboxes are created in. */
13650
+ labelsOk(l) {
13651
+ return l.attachable === "true" && l.workspace === this.s.workspace;
13652
+ }
13653
+ /** Why the gateway would refuse this volume (CREW-3013). */
13654
+ labelProblem(l) {
13655
+ const what = l.attachable === null && l.workspace === null ? "carries no OpenShell labels" : l.attachable !== "true" ? "is not labeled sandbox-attachable" : `is labeled for OpenShell workspace "${l.workspace}" but sandboxes are created in "${this.s.workspace}"`;
13656
+ return `the cache volume ${this.s.volume} ${what}, so the gateway refuses to mount it`;
13657
+ }
13658
+ async volumeEmpty() {
13659
+ const { stdout } = await this.engine(["run", "--rm", "--label", DOCKER_LABEL_OWNER, "-v", `${this.s.volume}:${VOLUME_ROOT}`, "--entrypoint", "sh", this.s.helperImage, "-c", `ls -A ${VOLUME_ROOT} | head -n 1`]);
13660
+ return stdout.trim() === "";
13661
+ }
13551
13662
  /** The workspace label the existing volume carries, or null when the volume is absent or unlabeled. A volume's labels cannot be changed in place. */
13552
13663
  async volumeWorkspace() {
13553
13664
  try {
@@ -13558,7 +13669,8 @@ var SandboxCache = class {
13558
13669
  return null;
13559
13670
  }
13560
13671
  }
13561
- helper(image, script, args, env = {}, extra = []) {
13672
+ async helper(image, script, args, env = {}, extra = []) {
13673
+ await this.ensureVolume();
13562
13674
  const flags = Object.keys(env).flatMap((k) => ["-e", k]);
13563
13675
  return this.engine(["run", "--rm", "--label", DOCKER_LABEL_OWNER, "-v", `${this.s.volume}:${VOLUME_ROOT}`, ...extra, ...flags, "--entrypoint", "sh", image, "-c", script, "sh", ...args], { ...process.env, ...env });
13564
13676
  }
@@ -14129,8 +14241,8 @@ function managedGitIdentityWarnings(kind, identity) {
14129
14241
 
14130
14242
  // src/selftest.ts
14131
14243
  import { spawn as spawn6 } from "child_process";
14132
- import { existsSync as existsSync30, mkdirSync as mkdirSync20, mkdtempSync as mkdtempSync2, readFileSync as readFileSync29, rmSync as rmSync16, writeFileSync as writeFileSync21 } from "fs";
14133
- import { tmpdir as tmpdir4 } from "os";
14244
+ import { existsSync as existsSync31, mkdirSync as mkdirSync20, mkdtempSync as mkdtempSync2, readFileSync as readFileSync29, rmSync as rmSync16, writeFileSync as writeFileSync21 } from "fs";
14245
+ import { tmpdir as tmpdir5 } from "os";
14134
14246
  import { join as join33 } from "path";
14135
14247
  var SELFTEST_TIMEOUT_MS = 12e4;
14136
14248
  var KEY_VAR = "CREW_API_KEY";
@@ -14297,7 +14409,7 @@ async function runSelftest(i, deps = realDeps) {
14297
14409
  ...adapter.runEnv(spec),
14298
14410
  [KEY_VAR]: i.apiKey
14299
14411
  };
14300
- const cwd = mkdtempSync2(join33(tmpdir4(), "crew-selftest-"));
14412
+ const cwd = mkdtempSync2(join33(tmpdir5(), "crew-selftest-"));
14301
14413
  try {
14302
14414
  const run3 = await deps.run({
14303
14415
  bin: invocation.bin,
@@ -14334,7 +14446,7 @@ var fileFor2 = (stateDir) => join33(stateDir, "selftest.json");
14334
14446
  function readSelftest(stateDir) {
14335
14447
  try {
14336
14448
  const p = fileFor2(stateDir);
14337
- return existsSync30(p) ? JSON.parse(readFileSync29(p, "utf8")) : {};
14449
+ return existsSync31(p) ? JSON.parse(readFileSync29(p, "utf8")) : {};
14338
14450
  } catch {
14339
14451
  return {};
14340
14452
  }
@@ -14355,7 +14467,7 @@ function doctorSelftestLines(stored, toolchains) {
14355
14467
  }
14356
14468
 
14357
14469
  // src/cli.ts
14358
- import { resolve as resolve7, dirname as dirname35, join as join56, basename as basename16 } from "path";
14470
+ import { resolve as resolve7, dirname as dirname35, join as join57, basename as basename16 } from "path";
14359
14471
  import { fileURLToPath as fileURLToPath2 } from "url";
14360
14472
  import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
14361
14473
  import { spawnSync as spawnSync12 } from "child_process";
@@ -14661,7 +14773,7 @@ async function signOutSessions(o) {
14661
14773
  }
14662
14774
 
14663
14775
  // src/reset.ts
14664
- import { existsSync as existsSync31, mkdirSync as mkdirSync22, readFileSync as readFileSync31, readdirSync as readdirSync12, rmSync as rmSync18, statSync as statSync10, writeFileSync as writeFileSync23 } from "fs";
14776
+ import { existsSync as existsSync32, mkdirSync as mkdirSync22, readFileSync as readFileSync31, readdirSync as readdirSync12, rmSync as rmSync18, statSync as statSync10, writeFileSync as writeFileSync23 } from "fs";
14665
14777
  import { dirname as dirname17, join as join35 } from "path";
14666
14778
  import { hostFromUrl as hostFromUrl3 } from "@tablation/client";
14667
14779
  function clonedCheckoutsFile(stateDir) {
@@ -14734,7 +14846,7 @@ async function runReset(o, fx) {
14734
14846
  }
14735
14847
  if (o.beforeState) steps.push(...await o.beforeState());
14736
14848
  steps.push(...o.wipeState ? wipeStateDir(o.stateDir, o.dryRun) : removeState(o.stateDir, o.dryRun));
14737
- if (existsSync31(o.configFile)) {
14849
+ if (existsSync32(o.configFile)) {
14738
14850
  if (!o.dryRun) rmSync18(o.configFile, { force: true });
14739
14851
  steps.push({ step: "config", target: o.configFile, action: mark(o.dryRun) });
14740
14852
  } else {
@@ -14743,7 +14855,7 @@ async function runReset(o, fx) {
14743
14855
  return steps;
14744
14856
  }
14745
14857
  function removeCheckout(dir, dryRun, fx) {
14746
- if (!existsSync31(dir)) return { step: "checkout", target: dir, action: "absent", detail: "already gone" };
14858
+ if (!existsSync32(dir)) return { step: "checkout", target: dir, action: "absent", detail: "already gone" };
14747
14859
  const { dirty, linkedWorktrees } = fx.inspectCheckout(dir);
14748
14860
  if (dirty.length) {
14749
14861
  return { step: "checkout", target: dir, action: "kept", detail: `has uncommitted changes (${dirty.length} path${dirty.length === 1 ? "" : "s"}: ${dirty.slice(0, 5).join(", ")}${dirty.length > 5 ? ", \u2026" : ""})` };
@@ -14764,7 +14876,7 @@ function removeState(stateDir, dryRun) {
14764
14876
  } catch {
14765
14877
  }
14766
14878
  for (const t of targets) {
14767
- if (!existsSync31(t)) continue;
14879
+ if (!existsSync32(t)) continue;
14768
14880
  if (!dryRun) rmSync18(t, { recursive: true, force: true });
14769
14881
  out.push({ step: "state", target: t, action: mark(dryRun) });
14770
14882
  }
@@ -15160,13 +15272,13 @@ function hostArchitecture(arch = process.arch) {
15160
15272
 
15161
15273
  // src/pool-member-host.ts
15162
15274
  import "child_process";
15163
- import { existsSync as existsSync35 } from "fs";
15275
+ import { existsSync as existsSync36 } from "fs";
15164
15276
  import { hostname as hostname3 } from "os";
15165
15277
 
15166
15278
  // src/machine-id.ts
15167
15279
  import { execFileSync as execFileSync11 } from "child_process";
15168
15280
  import { createHash as createHash8 } from "crypto";
15169
- import { existsSync as existsSync32, mkdirSync as mkdirSync24, readFileSync as readFileSync33, writeFileSync as writeFileSync25 } from "fs";
15281
+ import { existsSync as existsSync33, mkdirSync as mkdirSync24, readFileSync as readFileSync33, writeFileSync as writeFileSync25 } from "fs";
15170
15282
  import { dirname as dirname19, join as join37 } from "path";
15171
15283
  function machineIdPathFor(stateDir) {
15172
15284
  return join37(stateDir, "machine-id");
@@ -15182,7 +15294,7 @@ function readRawMachineId(platform2 = process.platform) {
15182
15294
  return /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(out)?.[1];
15183
15295
  }
15184
15296
  for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
15185
- if (existsSync32(p)) {
15297
+ if (existsSync33(p)) {
15186
15298
  const id = readFileSync33(p, "utf8").trim();
15187
15299
  if (id) return id;
15188
15300
  }
@@ -15194,7 +15306,7 @@ function readRawMachineId(platform2 = process.platform) {
15194
15306
  function ensureMachineId(stateDir, opts = {}) {
15195
15307
  if (opts.override?.trim()) return sha256(opts.override.trim());
15196
15308
  const path = machineIdPathFor(stateDir);
15197
- if (existsSync32(path)) {
15309
+ if (existsSync33(path)) {
15198
15310
  const cached = readFileSync33(path, "utf8").trim();
15199
15311
  if (/^[0-9a-f]{64}$/.test(cached)) return cached;
15200
15312
  }
@@ -15215,7 +15327,7 @@ function matchShipRows(ships, shipName2, machineId) {
15215
15327
 
15216
15328
  // src/provision.ts
15217
15329
  import { spawnSync as spawnSync9 } from "child_process";
15218
- import { existsSync as existsSync33, readFileSync as readFileSync34, writeFileSync as writeFileSync26 } from "fs";
15330
+ import { existsSync as existsSync34, readFileSync as readFileSync34, writeFileSync as writeFileSync26 } from "fs";
15219
15331
  import { hostname as hostname2 } from "os";
15220
15332
  import { parseDocument as parseDocument3, isMap as isMap2, isScalar } from "yaml";
15221
15333
 
@@ -15833,7 +15945,7 @@ function realProvisionDeps(crewHome) {
15833
15945
  };
15834
15946
  const configFile = () => {
15835
15947
  const f = findConfigFile(crewHome);
15836
- return existsSync33(f) ? f : null;
15948
+ return existsSync34(f) ? f : null;
15837
15949
  };
15838
15950
  return {
15839
15951
  crew: spawnCrew,
@@ -15867,14 +15979,14 @@ function realProvisionDeps(crewHome) {
15867
15979
  continue;
15868
15980
  }
15869
15981
  for (const p of plan.unitPaths) {
15870
- if (!existsSync33(p) || readFileSync34(p, "utf8") !== plan.unitContent[p]) unitsStale = true;
15982
+ if (!existsSync34(p) || readFileSync34(p, "utf8") !== plan.unitContent[p]) unitsStale = true;
15871
15983
  }
15872
15984
  }
15873
15985
  const label = labelFor(crewHome, "run");
15874
15986
  let running = false;
15875
15987
  let lingering = true;
15876
15988
  if (mechanism === "systemd") {
15877
- const system = ctx.root || existsSync33(systemUnitPathFor(label));
15989
+ const system = ctx.root || existsSync34(systemUnitPathFor(label));
15878
15990
  const ctl = system ? ["systemctl"] : ["systemctl", "--user"];
15879
15991
  running = spawnSync9(ctl[0], [...ctl.slice(1), "is-active", "--quiet", `${label}.service`], { env: withUserBusEnv() }).status === 0;
15880
15992
  if (!system) {
@@ -15930,7 +16042,7 @@ host=${host}
15930
16042
 
15931
16043
  // src/tunnel.ts
15932
16044
  import { spawn as spawn7 } from "child_process";
15933
- import { existsSync as existsSync34, mkdirSync as mkdirSync25, readFileSync as readFileSync35, writeFileSync as writeFileSync27, unlinkSync as unlinkSync3, readdirSync as readdirSync13 } from "fs";
16045
+ import { existsSync as existsSync35, mkdirSync as mkdirSync25, readFileSync as readFileSync35, writeFileSync as writeFileSync27, unlinkSync as unlinkSync3, readdirSync as readdirSync13 } from "fs";
15934
16046
  import { randomInt } from "crypto";
15935
16047
  import { join as join39 } from "path";
15936
16048
  var DEFAULT_SPAWN_OPTIONS = { stdio: "ignore", detached: true };
@@ -16014,7 +16126,7 @@ function tunnelStatePath(stateDir, workspaceId) {
16014
16126
  }
16015
16127
  function readPersistedTunnel(stateDir, workspaceId) {
16016
16128
  const path = tunnelStatePath(stateDir, workspaceId);
16017
- if (!existsSync34(path)) return void 0;
16129
+ if (!existsSync35(path)) return void 0;
16018
16130
  try {
16019
16131
  return JSON.parse(readFileSync35(path, "utf8"));
16020
16132
  } catch {
@@ -16154,7 +16266,7 @@ function syncPassengerTunnels(plans, relayHost, relayPort, privateKeyPath, state
16154
16266
  }
16155
16267
  function readAllPersistedWorkspaceIds(stateDir) {
16156
16268
  const dir = join39(stateDir, "passengers");
16157
- if (!existsSync34(dir)) return [];
16269
+ if (!existsSync35(dir)) return [];
16158
16270
  return readdirSync13(dir).filter((f) => f.endsWith(".json") && !f.endsWith("-sync.json")).map((f) => f.slice(0, -".json".length));
16159
16271
  }
16160
16272
  var TUNNEL_REJECTED_KEY = "tunnel_rejected";
@@ -16194,7 +16306,7 @@ function realPoolMemberDeps(o) {
16194
16306
  crewVersion: crewVersion(o.crewHome),
16195
16307
  hostname: hostname3()
16196
16308
  },
16197
- hasShipConfig: () => existsSync35(findConfigFile(o.crewHome)),
16309
+ hasShipConfig: () => existsSync36(findConfigFile(o.crewHome)),
16198
16310
  async provision(lease, instanceClass, shipKind) {
16199
16311
  const hosts = lease.forges.map((f) => f.host.toLowerCase());
16200
16312
  const lines2 = [];
@@ -17571,7 +17683,7 @@ async function resolveOne(tracker, t, seat, approvedStatus, buildingStatus, affi
17571
17683
  }
17572
17684
 
17573
17685
  // src/repo-refresh.ts
17574
- import { existsSync as existsSync36, mkdirSync as mkdirSync26, readFileSync as readFileSync36, writeFileSync as writeFileSync29 } from "fs";
17686
+ import { existsSync as existsSync37, mkdirSync as mkdirSync26, readFileSync as readFileSync36, writeFileSync as writeFileSync29 } from "fs";
17575
17687
  import { dirname as dirname21 } from "path";
17576
17688
  var REFRESH_COOLDOWN_MS = 2 * 6e4;
17577
17689
  var UNSERVABLE_PASSES_BEFORE_ATTENTION = 3;
@@ -17601,7 +17713,7 @@ function applyRepoRows(resolved, rows) {
17601
17713
  }
17602
17714
  function persistRepoRows(stateDir, routeName, rows) {
17603
17715
  const path = resolvedPathFor(stateDir, routeName);
17604
- if (!existsSync36(path)) return;
17716
+ if (!existsSync37(path)) return;
17605
17717
  const raw = JSON.parse(readFileSync36(path, "utf8"));
17606
17718
  applyRepoRows(raw, rows);
17607
17719
  mkdirSync26(dirname21(path), { recursive: true });
@@ -18056,12 +18168,12 @@ var localRefSkipReported = (ticket, problem, events) => events.some((e) => e.rec
18056
18168
 
18057
18169
  // src/connect-wizard.ts
18058
18170
  import { delimiter, dirname as dirname22, join as join41 } from "path";
18059
- import { accessSync as accessSync3, constants as constants3, existsSync as existsSync37, mkdirSync as mkdirSync27, writeFileSync as writeFileSync30 } from "fs";
18171
+ import { accessSync as accessSync3, constants as constants3, existsSync as existsSync38, mkdirSync as mkdirSync27, writeFileSync as writeFileSync30 } from "fs";
18060
18172
  import { stringify as stringify3 } from "yaml";
18061
18173
  var HOST_PASSENGERS_DOCS_URL = "https://crew.tablation.dev/host-passengers";
18062
18174
  function shouldRunWizard(opts) {
18063
18175
  if (!opts.isTTY) return false;
18064
- const exists = opts.configExists ?? existsSync37;
18176
+ const exists = opts.configExists ?? existsSync38;
18065
18177
  return !configSearchPath(opts.crewHome).some((p) => exists(p));
18066
18178
  }
18067
18179
  function firstRunConfigPath() {
@@ -18340,9 +18452,9 @@ async function collectDiagnostics(d) {
18340
18452
  }
18341
18453
 
18342
18454
  // src/release-run.ts
18343
- import { readFileSync as readFileSync37, writeFileSync as writeFileSync31, existsSync as existsSync38, copyFileSync, mkdirSync as mkdirSync28, mkdtempSync as mkdtempSync3, rmSync as rmSync19 } from "fs";
18455
+ import { readFileSync as readFileSync37, writeFileSync as writeFileSync31, existsSync as existsSync39, copyFileSync, mkdirSync as mkdirSync28, mkdtempSync as mkdtempSync3, rmSync as rmSync19 } from "fs";
18344
18456
  import { dirname as dirname24, join as join43 } from "path";
18345
- import { tmpdir as tmpdir5, hostname as hostname4 } from "os";
18457
+ import { tmpdir as tmpdir6, hostname as hostname4 } from "os";
18346
18458
 
18347
18459
  // src/release.ts
18348
18460
  function describeUnplaceable(unplaceable, verifiedStatus) {
@@ -19125,7 +19237,7 @@ async function bump(o, size) {
19125
19237
  }
19126
19238
  const files = o.repo.release.versionFiles.map((f) => join43(o.cwd, f));
19127
19239
  const first = files[0];
19128
- if (!existsAt(first, existsSync38)) {
19240
+ if (!existsAt(first, existsSync39)) {
19129
19241
  o.emit.error(`no ${o.repo.release.versionFiles[0]} to read a version from`);
19130
19242
  return null;
19131
19243
  }
@@ -19167,7 +19279,7 @@ function writeChangelog(o, version, entries) {
19167
19279
  o.emit.emit(`would prepend ${entries.length} entr(ies) to ${file}`);
19168
19280
  return;
19169
19281
  }
19170
- const existing = existsAt(path, existsSync38) ? readTextAt(path, (p) => readFileSync37(p, "utf8")) : "# Changelog\n";
19282
+ const existing = existsAt(path, existsSync39) ? readTextAt(path, (p) => readFileSync37(p, "utf8")) : "# Changelog\n";
19171
19283
  writeTextAt(path, insertChangelogSection(existing, section), writeFileSync31);
19172
19284
  }
19173
19285
  async function confirm(o, expected) {
@@ -19261,7 +19373,7 @@ function closeReleaseCheckout(cwd, root, dir, branch, run3 = gitOk) {
19261
19373
  function openReleaseCheckout(o) {
19262
19374
  const { remote, base } = o.repo.branch;
19263
19375
  const branch = `crew/release-${Date.now()}`;
19264
- const root = mkdtempSync3(join43(tmpdir5(), "crew-release-"));
19376
+ const root = mkdtempSync3(join43(tmpdir6(), "crew-release-"));
19265
19377
  const dir = join43(root, "checkout");
19266
19378
  o.emit.emit(`release checkout: ${dir}`, { step: "release" });
19267
19379
  const close = () => closeReleaseCheckout(o.cwd, root, dir, branch);
@@ -19273,7 +19385,7 @@ function openReleaseCheckout(o) {
19273
19385
  }
19274
19386
  for (const f of o.repo.worktrees.copy) {
19275
19387
  const src = join43(o.cwd, f);
19276
- if (!existsSync38(src)) continue;
19388
+ if (!existsSync39(src)) continue;
19277
19389
  mkdirSync28(dirname24(join43(dir, f)), { recursive: true });
19278
19390
  copyFileSync(src, join43(dir, f));
19279
19391
  }
@@ -19426,7 +19538,7 @@ async function runReleaseCycle(o, movedPast2, localRefSkips) {
19426
19538
  let checkout;
19427
19539
  const stranded = recoverStrandedReleaseCheckouts(o.cwd);
19428
19540
  if (stranded.length > 0) o.emit.warn(scoped(`dropped release checkout(s) stranded by a crash: ${stranded.join(", ")}`));
19429
- const swept = sweepStaleReleaseRoots(tmpdir5());
19541
+ const swept = sweepStaleReleaseRoots(tmpdir6());
19430
19542
  if (swept.length > 0) o.emit.emit(scoped(`removed ${swept.length} stale crew-release-* temp dir(s)`), { step: "release" });
19431
19543
  try {
19432
19544
  checkout = openReleaseCheckout(o);
@@ -20110,7 +20222,7 @@ function runForge(a, io) {
20110
20222
  }
20111
20223
 
20112
20224
  // src/mirror-contract.ts
20113
- import { existsSync as existsSync39 } from "fs";
20225
+ import { existsSync as existsSync40 } from "fs";
20114
20226
 
20115
20227
  // src/passenger-mirror.ts
20116
20228
  import { mkdirSync as mkdirSync29 } from "fs";
@@ -20151,7 +20263,7 @@ function mirrorOutcome(m) {
20151
20263
 
20152
20264
  // src/mirror-contract.ts
20153
20265
  function lacksCheckout(ship, dir) {
20154
- return ship.runner === "sandbox" && !existsSync39(dir) && !remoteOf(dir);
20266
+ return ship.runner === "sandbox" && !existsSync40(dir) && !remoteOf(dir);
20155
20267
  }
20156
20268
  function skipsHostCheckout(ship) {
20157
20269
  return ship.runner === "sandbox";
@@ -20170,6 +20282,24 @@ async function readMirrorContract(cache, repo, base) {
20170
20282
  }
20171
20283
  return null;
20172
20284
  }
20285
+ async function repoContractFor(ship, route2, t) {
20286
+ if (ship.runner === "sandbox") {
20287
+ const settings = cacheSettingsOf(ship.sandbox);
20288
+ const mirror = mirrorRepoOfTarget(t);
20289
+ if (settings && mirror) {
20290
+ try {
20291
+ return await readMirrorContract(new SandboxCache(settings), mirror, route2.branch?.base ?? "main");
20292
+ } catch {
20293
+ return null;
20294
+ }
20295
+ }
20296
+ }
20297
+ try {
20298
+ return loadRepoConfigTolerant(t.dir);
20299
+ } catch {
20300
+ return null;
20301
+ }
20302
+ }
20173
20303
  async function readMirrorWarmFiles(cache, repo, base, patterns) {
20174
20304
  if (patterns.length === 0) return {};
20175
20305
  const res = patterns.map(globToRegExp);
@@ -20427,7 +20557,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
20427
20557
  }
20428
20558
 
20429
20559
  // src/watch.ts
20430
- import { watch as watchFile, existsSync as existsSync40, statSync as statSync11, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
20560
+ import { watch as watchFile, existsSync as existsSync41, statSync as statSync11, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
20431
20561
  var E = "\x1B[";
20432
20562
  var dim = (s) => `${E}2m${s}${E}0m`;
20433
20563
  var bold = (s) => `${E}1m${s}${E}0m`;
@@ -20528,7 +20658,7 @@ function renderHeaders(states, now = Date.now()) {
20528
20658
  return states.map((s) => renderHeader(s, now)).join("");
20529
20659
  }
20530
20660
  function readFrom(file, from) {
20531
- if (!existsSync40(file)) return { events: [], offset: from };
20661
+ if (!existsSync41(file)) return { events: [], offset: from };
20532
20662
  const size = statSync11(file).size;
20533
20663
  if (size < from) return readFrom(file, 0);
20534
20664
  if (size === from) return { events: [], offset: from };
@@ -20771,7 +20901,7 @@ function nextRoles(decision, ran) {
20771
20901
  }
20772
20902
 
20773
20903
  // src/ship-name.ts
20774
- import { existsSync as existsSync41, mkdirSync as mkdirSync31, readFileSync as readFileSync38, renameSync as renameSync5, writeFileSync as writeFileSync33 } from "fs";
20904
+ import { existsSync as existsSync42, mkdirSync as mkdirSync31, readFileSync as readFileSync38, renameSync as renameSync5, writeFileSync as writeFileSync33 } from "fs";
20775
20905
  import { dirname as dirname27 } from "path";
20776
20906
  import { parseDocument as parseDocument5 } from "yaml";
20777
20907
  var ShipNameError = class extends Error {
@@ -20833,7 +20963,7 @@ async function syncRouteName(i) {
20833
20963
  return { status: "ok", ...base, action, name: i.local };
20834
20964
  }
20835
20965
  function readSyncedName(resolvedFile) {
20836
- if (!existsSync41(resolvedFile)) return void 0;
20966
+ if (!existsSync42(resolvedFile)) return void 0;
20837
20967
  try {
20838
20968
  const v = JSON.parse(readFileSync38(resolvedFile, "utf8")).shipName;
20839
20969
  return typeof v === "string" ? v : void 0;
@@ -20842,7 +20972,7 @@ function readSyncedName(resolvedFile) {
20842
20972
  }
20843
20973
  }
20844
20974
  function writeSyncedName(resolvedFile, name) {
20845
- if (!existsSync41(resolvedFile)) return;
20975
+ if (!existsSync42(resolvedFile)) return;
20846
20976
  let raw;
20847
20977
  try {
20848
20978
  raw = JSON.parse(readFileSync38(resolvedFile, "utf8"));
@@ -21544,7 +21674,7 @@ function describeCapability(i) {
21544
21674
  }
21545
21675
 
21546
21676
  // src/agents-sync-run.ts
21547
- import { existsSync as existsSync42, mkdirSync as mkdirSync32, readFileSync as readFileSync39, writeFileSync as writeFileSync34 } from "fs";
21677
+ import { existsSync as existsSync43, mkdirSync as mkdirSync32, readFileSync as readFileSync39, writeFileSync as writeFileSync34 } from "fs";
21548
21678
  import { dirname as dirname28 } from "path";
21549
21679
  async function runAgentsSync(target, o) {
21550
21680
  const dryRun = o.dryRun ?? false;
@@ -21578,7 +21708,7 @@ async function runAgentsSync(target, o) {
21578
21708
  for (const s of skillResult?.outcomes ?? []) o.say(describeSkillSyncOutcome(s));
21579
21709
  if (!dryRun) {
21580
21710
  const resolvedPath = resolvedPathFor(o.stateDir, target.route);
21581
- const raw = existsSync42(resolvedPath) ? JSON.parse(readFileSync39(resolvedPath, "utf8")) : {};
21711
+ const raw = existsSync43(resolvedPath) ? JSON.parse(readFileSync39(resolvedPath, "utf8")) : {};
21582
21712
  raw.agentPersonas = personaResult.agentPersonas;
21583
21713
  if (skillResult) raw.agentSkills = skillResult.agentSkills;
21584
21714
  if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
@@ -22293,7 +22423,7 @@ function planSampleTicket(i) {
22293
22423
  }
22294
22424
 
22295
22425
  // src/worktree-sweep.ts
22296
- import { existsSync as existsSync43, readFileSync as readFileSync41, readdirSync as readdirSync14 } from "fs";
22426
+ import { existsSync as existsSync44, readFileSync as readFileSync41, readdirSync as readdirSync14 } from "fs";
22297
22427
  import { basename as basename13, dirname as dirname30, join as join45, resolve as resolve5 } from "path";
22298
22428
  function planWorktreeSweep(target, tickets, contract) {
22299
22429
  const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
@@ -22406,7 +22536,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
22406
22536
  let removed = 0;
22407
22537
  let keptBranches = 0;
22408
22538
  for (const a of actions) {
22409
- if (!dryRun && base && !a.keepBranch && existsSync43(a.path) && isHandBackMerge(a.path, base)) {
22539
+ if (!dryRun && base && !a.keepBranch && existsSync44(a.path) && isHandBackMerge(a.path, base)) {
22410
22540
  if (gitOk(a.path, ["merge", "--abort"]) !== null) {
22411
22541
  log.emit(
22412
22542
  `abandoned the hand-back merge of ${base} in ${a.path}: ${a.ticket.issue_id} deployed without it`,
@@ -22414,7 +22544,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
22414
22544
  );
22415
22545
  }
22416
22546
  }
22417
- if (!dryRun && existsSync43(a.path)) {
22547
+ if (!dryRun && existsSync44(a.path)) {
22418
22548
  let dirty = false;
22419
22549
  try {
22420
22550
  dirty = status(a.path).length > 0;
@@ -22425,7 +22555,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
22425
22555
  continue;
22426
22556
  }
22427
22557
  }
22428
- if (!dryRun && a.requirePushed && a.branch && existsSync43(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
22558
+ if (!dryRun && a.requirePushed && a.branch && existsSync44(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
22429
22559
  refuse2(a, "unpushed commits", `${a.branch} has commits that are not on ${remote}`);
22430
22560
  continue;
22431
22561
  }
@@ -22579,12 +22709,12 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
22579
22709
  }
22580
22710
 
22581
22711
  // src/stream-sweep.ts
22582
- import { existsSync as existsSync44, readdirSync as readdirSync15, rmSync as rmSync20, statSync as statSync12 } from "fs";
22712
+ import { existsSync as existsSync45, readdirSync as readdirSync15, rmSync as rmSync20, statSync as statSync12 } from "fs";
22583
22713
  import { join as join46 } from "path";
22584
22714
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
22585
22715
  function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
22586
22716
  const dir = join46(stateDir, "streams");
22587
- if (!existsSync44(dir)) return [];
22717
+ if (!existsSync45(dir)) return [];
22588
22718
  const cutoff = now - retentionDays * DAY_MS2;
22589
22719
  return readdirSync15(dir).map((name) => join46(dir, name)).filter((path) => {
22590
22720
  try {
@@ -22612,7 +22742,7 @@ function applyStreamSweep(paths, dryRun, log) {
22612
22742
  return removed;
22613
22743
  }
22614
22744
  function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
22615
- if (!existsSync44(stateDir)) return [];
22745
+ if (!existsSync45(stateDir)) return [];
22616
22746
  const cutoff = now - retentionDays * DAY_MS2;
22617
22747
  return readdirSync15(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join46(stateDir, name)).filter((path) => {
22618
22748
  try {
@@ -22624,11 +22754,11 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
22624
22754
  }
22625
22755
 
22626
22756
  // src/cli.ts
22627
- import { realpathSync as realpathSync3, readFileSync as readFileSync47, existsSync as existsSync51, mkdirSync as mkdirSync39, writeFileSync as writeFileSync39, rmSync as rmSync25, unlinkSync as unlinkSync5, copyFileSync as copyFileSync2, renameSync as renameSync6, statSync as statSync16, readdirSync as readdirSync20 } from "fs";
22757
+ import { realpathSync as realpathSync3, readFileSync as readFileSync48, existsSync as existsSync53, mkdirSync as mkdirSync40, writeFileSync as writeFileSync40, rmSync as rmSync25, unlinkSync as unlinkSync5, copyFileSync as copyFileSync2, renameSync as renameSync7, statSync as statSync16, readdirSync as readdirSync20 } from "fs";
22628
22758
  import { createInterface } from "readline/promises";
22629
22759
 
22630
22760
  // src/periscope-cmd.ts
22631
- import { existsSync as existsSync45, mkdirSync as mkdirSync33, readFileSync as readFileSync42, rmSync as rmSync21, writeFileSync as writeFileSync35 } from "fs";
22761
+ import { existsSync as existsSync46, mkdirSync as mkdirSync33, readFileSync as readFileSync42, rmSync as rmSync21, writeFileSync as writeFileSync35 } from "fs";
22632
22762
  import { join as join47 } from "path";
22633
22763
  var PeriscopeError = class extends Error {
22634
22764
  };
@@ -22654,7 +22784,7 @@ function writePeriscopePrior(stateDir, ticketRecordId, prior) {
22654
22784
  function readPeriscopePrior(stateDir, ticketRecordId) {
22655
22785
  try {
22656
22786
  const p = priorPath(stateDir, ticketRecordId);
22657
- return existsSync45(p) ? JSON.parse(readFileSync42(p, "utf8")) : void 0;
22787
+ return existsSync46(p) ? JSON.parse(readFileSync42(p, "utf8")) : void 0;
22658
22788
  } catch {
22659
22789
  return void 0;
22660
22790
  }
@@ -23210,7 +23340,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
23210
23340
 
23211
23341
  // src/ssh-keys.ts
23212
23342
  import { execFileSync as execFileSync14 } from "child_process";
23213
- import { existsSync as existsSync46, mkdirSync as mkdirSync34, readFileSync as readFileSync43, chmodSync as chmodSync3 } from "fs";
23343
+ import { existsSync as existsSync47, mkdirSync as mkdirSync34, readFileSync as readFileSync43, chmodSync as chmodSync3 } from "fs";
23214
23344
  import { dirname as dirname31, join as join49 } from "path";
23215
23345
  var SshKeyError = class extends Error {
23216
23346
  };
@@ -23220,7 +23350,7 @@ function shipSshKeyPathFor(stateDir) {
23220
23350
  function ensureShipSshKeypair(stateDir) {
23221
23351
  const privateKeyPath = shipSshKeyPathFor(stateDir);
23222
23352
  const publicKeyPath = `${privateKeyPath}.pub`;
23223
- if (!existsSync46(privateKeyPath)) {
23353
+ if (!existsSync47(privateKeyPath)) {
23224
23354
  mkdirSync34(dirname31(privateKeyPath), { recursive: true });
23225
23355
  try {
23226
23356
  execFileSync14("ssh-keygen", [
@@ -23241,7 +23371,7 @@ function ensureShipSshKeypair(stateDir) {
23241
23371
  }
23242
23372
  chmodSync3(privateKeyPath, 384);
23243
23373
  }
23244
- if (!existsSync46(publicKeyPath)) {
23374
+ if (!existsSync47(publicKeyPath)) {
23245
23375
  throw new SshKeyError(`${privateKeyPath} exists but ${publicKeyPath} does not \u2014 regenerate or restore it`);
23246
23376
  }
23247
23377
  const publicKey = readFileSync43(publicKeyPath, "utf8").trim();
@@ -23408,7 +23538,7 @@ async function unregisterEndpoint(workspaceId, info, d) {
23408
23538
  import { createServer as createHttpServer } from "http";
23409
23539
  import { spawn as spawn9 } from "child_process";
23410
23540
  import { randomBytes } from "crypto";
23411
- import { existsSync as existsSync47, mkdirSync as mkdirSync35, readFileSync as readFileSync44, writeFileSync as writeFileSync36, unlinkSync as unlinkSync4, readdirSync as readdirSync16 } from "fs";
23541
+ import { existsSync as existsSync48, mkdirSync as mkdirSync35, readFileSync as readFileSync44, writeFileSync as writeFileSync36, unlinkSync as unlinkSync4, readdirSync as readdirSync16 } from "fs";
23412
23542
  import { join as join50 } from "path";
23413
23543
 
23414
23544
  // src/secret-compare.ts
@@ -23506,7 +23636,7 @@ function syncDaemonStatePath(stateDir, workspaceId) {
23506
23636
  }
23507
23637
  function readPersistedSyncDaemon(stateDir, workspaceId) {
23508
23638
  const path = syncDaemonStatePath(stateDir, workspaceId);
23509
- if (!existsSync47(path)) return void 0;
23639
+ if (!existsSync48(path)) return void 0;
23510
23640
  try {
23511
23641
  return JSON.parse(readFileSync44(path, "utf8"));
23512
23642
  } catch {
@@ -23537,7 +23667,7 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
23537
23667
  }
23538
23668
  function readAllPersistedSyncWorkspaceIds(stateDir) {
23539
23669
  const dir = join50(stateDir, "passengers");
23540
- if (!existsSync47(dir)) return [];
23670
+ if (!existsSync48(dir)) return [];
23541
23671
  const suffix = "-sync.json";
23542
23672
  return readdirSync16(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
23543
23673
  }
@@ -24057,9 +24187,103 @@ function contractFixers(dir, baseRef, tickets, locate) {
24057
24187
  }
24058
24188
 
24059
24189
  // src/daemon.ts
24060
- import { existsSync as existsSync48, mkdirSync as mkdirSync37, readFileSync as readFileSync45, readdirSync as readdirSync17, rmSync as rmSync22, statSync as statSync14, writeFileSync as writeFileSync37 } from "fs";
24061
- import { join as join52 } from "path";
24190
+ import { existsSync as existsSync50, mkdirSync as mkdirSync38, readFileSync as readFileSync46, readdirSync as readdirSync17, rmSync as rmSync22, statSync as statSync14, writeFileSync as writeFileSync38 } from "fs";
24191
+ import { join as join53 } from "path";
24062
24192
  import { randomBytes as randomBytes2 } from "crypto";
24193
+
24194
+ // src/noop-runs.ts
24195
+ import { existsSync as existsSync49, mkdirSync as mkdirSync37, readFileSync as readFileSync45, renameSync as renameSync6, writeFileSync as writeFileSync37 } from "fs";
24196
+ import { join as join52 } from "path";
24197
+ var NOOP_DELAYS_MS = [5, 15, 60].map((m) => m * 6e4);
24198
+ var DEFAULT_NOOP_REPEATS = 3;
24199
+ var NOOP_BOUNCED_MARKER = calloutHeader("WARNING", "Runs Changed Nothing");
24200
+ var noopRunsPath = (stateDir) => join52(stateDir, "noop-runs.json");
24201
+ var noopRunsKey = (issueId) => `noop_runs:${issueId}`;
24202
+ function readNoopRuns(stateDir) {
24203
+ try {
24204
+ const v = JSON.parse(readFileSync45(noopRunsPath(stateDir), "utf8"));
24205
+ return v && typeof v === "object" && !Array.isArray(v) ? v : {};
24206
+ } catch {
24207
+ return {};
24208
+ }
24209
+ }
24210
+ function writeNoopRuns(stateDir, state) {
24211
+ mkdirSync37(stateDir, { recursive: true });
24212
+ const file = noopRunsPath(stateDir);
24213
+ writeFileSync37(`${file}.tmp`, `${JSON.stringify(state, null, 2)}
24214
+ `);
24215
+ renameSync6(`${file}.tmp`, file);
24216
+ }
24217
+ function noopBackedOff(stateDir, recordId, now = Date.now()) {
24218
+ const e = readNoopRuns(stateDir)[recordId];
24219
+ return e !== void 0 && now < e.nextAt;
24220
+ }
24221
+ function recordNoopRun(stateDir, recordId, repeats, now = Date.now()) {
24222
+ const state = readNoopRuns(stateDir);
24223
+ const count = (state[recordId]?.count ?? 0) + 1;
24224
+ const nextAt = now + NOOP_DELAYS_MS[Math.min(count, NOOP_DELAYS_MS.length) - 1];
24225
+ state[recordId] = { count, lastAt: now, nextAt };
24226
+ writeNoopRuns(stateDir, state);
24227
+ return { count, nextAt, bounce: count >= repeats };
24228
+ }
24229
+ function clearNoopRuns(stateDir, recordId) {
24230
+ if (!existsSync49(noopRunsPath(stateDir))) return;
24231
+ const state = readNoopRuns(stateDir);
24232
+ if (!(recordId in state)) return;
24233
+ delete state[recordId];
24234
+ writeNoopRuns(stateDir, state);
24235
+ }
24236
+ function noopAttentionMessage(tag, role, count, nextAt, lastComment2) {
24237
+ const mins = Math.max(1, Math.round((nextAt - Date.now()) / 6e4));
24238
+ return `${tag}: ${role} run ended ${count} time${count === 1 ? "" : "s"} in a row with nothing pushed and no hand-off; next attempt in about ${mins} minutes` + (lastComment2 ? `. Its last comment: ${lastComment2.slice(0, 300)}` : "");
24239
+ }
24240
+ function noopBounceComment(count, lastComment2) {
24241
+ return `${NOOP_BOUNCED_MARKER}
24242
+
24243
+ ${count} consecutive runs of this ticket ended with nothing pushed and no hand-off, so the crew stopped retrying and released its hold. ` + (lastComment2 ? `The agent's last comment:
24244
+
24245
+ ${lastComment2}
24246
+
24247
+ ` : "") + "Needs a person to read this, fix what stopped the run, and set the status back to `accepted` or `in_progress`.";
24248
+ }
24249
+ async function settleNoopRun(o) {
24250
+ const tag = o.before.issue_tag ?? o.before.issue_id;
24251
+ const after = await o.tracker.ticket(o.ticketId);
24252
+ const noop = o.before[o.columns.status] === o.statuses.building && after[o.columns.status] === o.before[o.columns.status] && after[o.columns.assignee] === o.before[o.columns.assignee] && o.tipBefore === o.tipAfter;
24253
+ if (!noop) {
24254
+ clearNoopRuns(o.stateDir, o.ticketId);
24255
+ o.clear(noopRunsKey(o.before.issue_id));
24256
+ return "progress";
24257
+ }
24258
+ const verdict = recordNoopRun(o.stateDir, o.ticketId, o.repeats, o.now);
24259
+ let last = null;
24260
+ try {
24261
+ const mine = (await o.tracker.comments()).filter((c) => c.ticket_id === o.ticketId && c.team_member_id === o.memberId && c.created_at >= o.runStart && c.body).sort((a, b) => a.created_at.localeCompare(b.created_at));
24262
+ last = mine.at(-1)?.body ?? null;
24263
+ } catch {
24264
+ }
24265
+ if (!verdict.bounce) {
24266
+ await o.raise({
24267
+ kind: "noop_runs",
24268
+ key: noopRunsKey(o.before.issue_id),
24269
+ since: (/* @__PURE__ */ new Date()).toISOString(),
24270
+ message: noopAttentionMessage(tag, o.role, verdict.count, verdict.nextAt, last)
24271
+ });
24272
+ return "backoff";
24273
+ }
24274
+ const affinity = await o.tracker.claimAffinity();
24275
+ await o.tracker.updateTicket(o.ticketId, {
24276
+ [o.columns.status]: o.statuses.needsHuman,
24277
+ ...o.operatorId ? { [o.columns.assignee]: o.operatorId } : {},
24278
+ ...affinity ? { [affinity.column]: null } : {}
24279
+ }, after.updated_at);
24280
+ if (o.memberId) await o.tracker.postEvent(o.ticketId, noopBounceComment(verdict.count, last), o.memberId, "noop_bounced").catch(() => void 0);
24281
+ clearNoopRuns(o.stateDir, o.ticketId);
24282
+ o.clear(noopRunsKey(o.before.issue_id));
24283
+ return "bounced";
24284
+ }
24285
+
24286
+ // src/daemon.ts
24063
24287
  var DEFAULT_FLOOR_MS = 5e3;
24064
24288
  var DEFAULT_CEILING_MS = INTERVAL_SECONDS * 1e3;
24065
24289
  var ALLOWANCE_PAUSE_MS = 5 * 60 * 1e3;
@@ -24146,7 +24370,7 @@ function latestMtime(path) {
24146
24370
  if (!stat2.isDirectory()) return 0;
24147
24371
  let latest = stat2.mtimeMs;
24148
24372
  for (const entry of readdirSync17(path, { withFileTypes: true })) {
24149
- latest = Math.max(latest, latestMtime(join52(path, entry.name)));
24373
+ latest = Math.max(latest, latestMtime(join53(path, entry.name)));
24150
24374
  }
24151
24375
  return latest;
24152
24376
  }
@@ -24155,10 +24379,10 @@ function computeTreeSignature(paths) {
24155
24379
  }
24156
24380
  function makeStaleChecker(paths, opts = {}) {
24157
24381
  const initial = computeTreeSignature(paths);
24158
- return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync48(opts.reloadSentinel);
24382
+ return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync50(opts.reloadSentinel);
24159
24383
  }
24160
24384
  function reloadSentinelFor(stateDir) {
24161
- return join52(stateDir, "reload-requested");
24385
+ return join53(stateDir, "reload-requested");
24162
24386
  }
24163
24387
  function readReloadRequestedAt(stateDir) {
24164
24388
  try {
@@ -24168,17 +24392,17 @@ function readReloadRequestedAt(stateDir) {
24168
24392
  }
24169
24393
  }
24170
24394
  function daemonStampFor(stateDir) {
24171
- return join52(stateDir, "daemon.started");
24395
+ return join53(stateDir, "daemon.started");
24172
24396
  }
24173
24397
  function noteDaemonStarted(stateDir, now = Date.now()) {
24174
- mkdirSync37(stateDir, { recursive: true });
24398
+ mkdirSync38(stateDir, { recursive: true });
24175
24399
  rmSync22(reloadSentinelFor(stateDir), { force: true });
24176
- writeFileSync37(daemonStampFor(stateDir), `${JSON.stringify({ pid: process.pid, startedAt: now })}
24400
+ writeFileSync38(daemonStampFor(stateDir), `${JSON.stringify({ pid: process.pid, startedAt: now })}
24177
24401
  `);
24178
24402
  }
24179
24403
  function readDaemonStarted(stateDir) {
24180
24404
  try {
24181
- const v = JSON.parse(readFileSync45(daemonStampFor(stateDir), "utf8")).startedAt;
24405
+ const v = JSON.parse(readFileSync46(daemonStampFor(stateDir), "utf8")).startedAt;
24182
24406
  return typeof v === "number" ? v : null;
24183
24407
  } catch {
24184
24408
  return null;
@@ -24541,6 +24765,59 @@ async function postRunKilled(route2, tracker, ticketId, memberId, limitMinutes,
24541
24765
  emit.warn(`could not post the wall-clock limit comment: ${e.message}`, { step: "agent" });
24542
24766
  }
24543
24767
  }
24768
+ async function skipUnrunnable(candidates2, ctx) {
24769
+ const { route: route2, ship, emit } = ctx;
24770
+ const backedOff = [];
24771
+ const noImage = /* @__PURE__ */ new Set();
24772
+ const imageSkipped = [];
24773
+ const state = ship.runner === "sandbox" ? readSandboxState(ship.stateDir) : null;
24774
+ const declares = /* @__PURE__ */ new Map();
24775
+ const out = [];
24776
+ for (const t of candidates2) {
24777
+ if (noopBackedOff(ship.stateDir, t.id)) {
24778
+ backedOff.push(t.issue_id);
24779
+ continue;
24780
+ }
24781
+ const target = repoTargetFor(route2, t.repo_id);
24782
+ if (state && target) {
24783
+ if (!declares.has(target.name)) declares.set(target.name, Boolean((await repoContractFor(ship, route2, target))?.sandbox));
24784
+ if (sandboxImageMissing(state, target.name, declares.get(target.name))) {
24785
+ noImage.add(target.name);
24786
+ imageSkipped.push(t.issue_id);
24787
+ continue;
24788
+ }
24789
+ }
24790
+ out.push(t);
24791
+ }
24792
+ if (backedOff.length) emit.emit(`skipped ${backedOff.join(", ")} \u2014 recent runs changed nothing, backing off`, { step: "select" });
24793
+ if (imageSkipped.length) emit.emit(`skipped ${imageSkipped.join(", ")} \u2014 the sandbox image for their repo is not built yet`, { step: "select" });
24794
+ for (const repo of noImage) {
24795
+ if (openShipAttention(ctx.state).some((i) => i.key === sandboxFailedKey(repo))) continue;
24796
+ try {
24797
+ await raiseShipAttention({ state: ctx.state, emit, route: route2, ship }, sandboxMissingItem(repo));
24798
+ } catch {
24799
+ }
24800
+ }
24801
+ return out;
24802
+ }
24803
+ function branchProgress(route2, t) {
24804
+ try {
24805
+ const target = repoTargetFor(route2, t.repo_id);
24806
+ if (!target) return "";
24807
+ const num2 = String(t.issue_id).replace(/^\D+/, "");
24808
+ const origin = originBranchSha(target.dir, t, resolve3) ?? "";
24809
+ const wt = worktreeForNumber(target.dir, num2);
24810
+ let local = "";
24811
+ if (wt) {
24812
+ const o = route2.repoOverrides[target.name];
24813
+ const base = resolveRepoConfig(loadRepoConfigTolerant(target.dir), { hooks: {}, labels: {}, branch: { ...route2.branch, ...o?.branch }, worktrees: {} }, target.dir).branch.base;
24814
+ if (countCommits(wt.path, `origin/${base}..HEAD`) > 0) local = (resolve3(wt.path, "HEAD") ?? "").slice(0, 7);
24815
+ }
24816
+ return `${origin}|${local}`;
24817
+ } catch {
24818
+ return "";
24819
+ }
24820
+ }
24544
24821
  async function runRoleAgent(role, decision, ctx, hooks) {
24545
24822
  const held = {};
24546
24823
  try {
@@ -24586,9 +24863,10 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
24586
24863
  const candidates2 = rankedCandidates(role, decision.selectionInput);
24587
24864
  const contract = decision.selectionInput.contract ?? DEFAULT_CONTRACT;
24588
24865
  await refreshUnknownRepos({ route: route2, stateDir: ship.stateDir, fetchRows: () => tracker.repoRowsForMap(), tickets: candidates2 });
24866
+ const runnable = await skipUnrunnable(candidates2, ctx);
24589
24867
  const result = await resolveTopCandidate(
24590
24868
  tracker,
24591
- candidates2,
24869
+ runnable,
24592
24870
  seat,
24593
24871
  claimStatuses(role, contract).approved,
24594
24872
  claimStatuses(role, contract).building,
@@ -24664,7 +24942,9 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
24664
24942
  hooks?.ready(true);
24665
24943
  }
24666
24944
  }
24945
+ const ticketTarget = ship.runner === "sandbox" ? reposOf(route2).find((r) => r.name === ticketRepo) : void 0;
24667
24946
  const plan = planAgentRun({
24947
+ repoContract: ticketTarget ? await repoContractFor(ship, route2, ticketTarget) : void 0,
24668
24948
  role,
24669
24949
  route: route2,
24670
24950
  ship,
@@ -24714,10 +24994,33 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
24714
24994
  try {
24715
24995
  const runStart = (/* @__PURE__ */ new Date()).toISOString();
24716
24996
  let hintMoved;
24997
+ let settleNoop;
24717
24998
  if (workingId) {
24718
24999
  try {
24719
25000
  const before = await tracker.ticket(workingId);
24720
25001
  const col = tracker.contract.columns;
25002
+ const tipBefore = branchProgress(route2, before);
25003
+ if (role === "dev" || role === "design") {
25004
+ settleNoop = async () => {
25005
+ await settleNoopRun({
25006
+ tracker,
25007
+ stateDir: ship.stateDir,
25008
+ role,
25009
+ ticketId: workingId,
25010
+ before,
25011
+ tipBefore,
25012
+ tipAfter: branchProgress(route2, before),
25013
+ runStart,
25014
+ memberId,
25015
+ operatorId: route2.resolved?.operator,
25016
+ columns: { status: col.status, assignee: col.assignee },
25017
+ statuses: { building: tracker.contract.statuses.building, needsHuman: tracker.contract.statuses.needsHuman },
25018
+ repeats: ship.noopRunRepeats ?? DEFAULT_NOOP_REPEATS,
25019
+ raise: (item) => raiseShipAttention({ state: ctx.state, emit, route: route2, ship }, item),
25020
+ clear: (key) => clearShipAttention(ctx.state, key)
25021
+ });
25022
+ };
25023
+ }
24721
25024
  hintMoved = async () => {
24722
25025
  const after = await tracker.ticket(workingId);
24723
25026
  return after[col.status] !== before[col.status] || after[col.assignee] !== before[col.assignee];
@@ -24734,6 +25037,13 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
24734
25037
  throw new WorkspaceAllowanceExhausted("the inference endpoint refused the run: the workspace is past its AI allowance");
24735
25038
  }
24736
25039
  await settleSignOut(plan, tracker, ctx.state, workingId, emit);
25040
+ if (settleNoop) {
25041
+ try {
25042
+ await settleNoop();
25043
+ } catch (e) {
25044
+ emit.warn(`could not settle a no-op run: ${e.message}`, { step: "agent" });
25045
+ }
25046
+ }
24737
25047
  }
24738
25048
  } finally {
24739
25049
  await settleRunEnd({
@@ -24796,7 +25106,7 @@ import { createHash as createHash11 } from "crypto";
24796
25106
  import {
24797
25107
  chmodSync as chmodSync4,
24798
25108
  closeSync as closeSync6,
24799
- existsSync as existsSync49,
25109
+ existsSync as existsSync51,
24800
25110
  fstatSync,
24801
25111
  openSync as openSync6,
24802
25112
  readSync as readSync3,
@@ -24807,7 +25117,7 @@ import {
24807
25117
  } from "fs";
24808
25118
  import { createConnection } from "net";
24809
25119
  import { createServer as createServer2 } from "http";
24810
- import { basename as basename14, dirname as dirname33, join as join53 } from "path";
25120
+ import { basename as basename14, dirname as dirname33, join as join54 } from "path";
24811
25121
  import { execFile as execFile5, spawn as spawn12 } from "child_process";
24812
25122
 
24813
25123
  // src/periscope-control.ts
@@ -25036,7 +25346,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
25036
25346
  // src/control-api.ts
25037
25347
  var PAUSABLE = ["dev", "design", "qa"];
25038
25348
  var CONTROL_SOCKET_NAME = "control.sock";
25039
- var controlSocketFor = (stateDir) => join53(stateDir, CONTROL_SOCKET_NAME);
25349
+ var controlSocketFor = (stateDir) => join54(stateDir, CONTROL_SOCKET_NAME);
25040
25350
  var MAX_SOCKET_PATH = 100;
25041
25351
  var MAX_TAIL_BYTES = 1024 * 1024;
25042
25352
  var MAX_WAIT_SECONDS = 30;
@@ -25123,7 +25433,7 @@ function candidates(live, rotated) {
25123
25433
  const out = [live];
25124
25434
  if (!rotated) return out;
25125
25435
  try {
25126
- for (const n of readdirSync18(dirname33(live))) if (ROTATED_EVENTS_RE.test(n)) out.push(join53(dirname33(live), n));
25436
+ for (const n of readdirSync18(dirname33(live))) if (ROTATED_EVENTS_RE.test(n)) out.push(join54(dirname33(live), n));
25127
25437
  } catch {
25128
25438
  }
25129
25439
  return out;
@@ -25167,7 +25477,7 @@ function lastLines2(path, n) {
25167
25477
  }
25168
25478
  function readTail(live, opts) {
25169
25479
  const max = opts.maxBytes ?? MAX_TAIL_BYTES;
25170
- if (!existsSync49(live)) {
25480
+ if (!existsSync51(live)) {
25171
25481
  return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
25172
25482
  }
25173
25483
  const cur = opts.after ? decodeCursor(opts.after) : null;
@@ -25323,8 +25633,8 @@ async function route(deps, method, url, req, abort) {
25323
25633
  if (p.startsWith("/streams/") && get2) {
25324
25634
  const run3 = decodeURIComponent(p.slice("/streams/".length));
25325
25635
  if (!RUN_NAME_RE.test(run3) || run3.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run3)) return err2(400, "not a run name");
25326
- const file = join53(deps.stateDir, "streams", run3.endsWith(".jsonl") ? run3 : `${run3}.jsonl`);
25327
- if (!existsSync49(file)) return err2(404, "no such run");
25636
+ const file = join54(deps.stateDir, "streams", run3.endsWith(".jsonl") ? run3 : `${run3}.jsonl`);
25637
+ if (!existsSync51(file)) return err2(404, "no such run");
25328
25638
  return tailReply(file, url.searchParams, false, abort);
25329
25639
  }
25330
25640
  if ((p === "/pause" || p === "/resume") && post3) {
@@ -25369,7 +25679,7 @@ function send(res, r) {
25369
25679
  res.end(body);
25370
25680
  }
25371
25681
  async function socketIsStale(path) {
25372
- if (!existsSync49(path)) return false;
25682
+ if (!existsSync51(path)) return false;
25373
25683
  return new Promise((resolve8) => {
25374
25684
  const c = createConnection(path);
25375
25685
  c.once("connect", () => {
@@ -25388,7 +25698,7 @@ async function startControlServer(deps) {
25388
25698
  return null;
25389
25699
  }
25390
25700
  if (await socketIsStale(path)) rmSync23(path, { force: true });
25391
- else if (existsSync49(path)) {
25701
+ else if (existsSync51(path)) {
25392
25702
  log(`control API not started: ${path} is in use by another process`);
25393
25703
  return null;
25394
25704
  }
@@ -25474,31 +25784,31 @@ function crewJson(args, timeoutMs = 6e4) {
25474
25784
 
25475
25785
  // src/periscope-mcp.ts
25476
25786
  import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
25477
- import { basename as basename15, dirname as dirname34, isAbsolute as isAbsolute5, join as join55, relative as relative2, resolve as resolve6, sep } from "path";
25787
+ import { basename as basename15, dirname as dirname34, isAbsolute as isAbsolute5, join as join56, relative as relative2, resolve as resolve6, sep } from "path";
25478
25788
  import { z } from "zod";
25479
25789
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
25480
25790
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
25481
25791
 
25482
25792
  // src/periscope-endpoints.ts
25483
25793
  import { randomBytes as randomBytes3 } from "crypto";
25484
- import { chmodSync as chmodSync5, existsSync as existsSync50, mkdirSync as mkdirSync38, readdirSync as readdirSync19, readFileSync as readFileSync46, rmSync as rmSync24, writeFileSync as writeFileSync38 } from "fs";
25485
- import { join as join54 } from "path";
25486
- var secretDir = (stateDir) => join54(stateDir, "periscope-mcp");
25487
- var secretFile = (stateDir, id) => join54(secretDir(stateDir), `${id}.json`);
25488
- var endpointDir = (stateDir) => join54(stateDir, "periscope-endpoints");
25489
- var endpointFile = (stateDir, id) => join54(endpointDir(stateDir), `${id}.json`);
25794
+ import { chmodSync as chmodSync5, existsSync as existsSync52, mkdirSync as mkdirSync39, readdirSync as readdirSync19, readFileSync as readFileSync47, rmSync as rmSync24, writeFileSync as writeFileSync39 } from "fs";
25795
+ import { join as join55 } from "path";
25796
+ var secretDir = (stateDir) => join55(stateDir, "periscope-mcp");
25797
+ var secretFile = (stateDir, id) => join55(secretDir(stateDir), `${id}.json`);
25798
+ var endpointDir = (stateDir) => join55(stateDir, "periscope-endpoints");
25799
+ var endpointFile = (stateDir, id) => join55(endpointDir(stateDir), `${id}.json`);
25490
25800
  function mintPeriscopeSecret(stateDir, ticketRecordId) {
25491
- mkdirSync38(secretDir(stateDir), { recursive: true, mode: 448 });
25801
+ mkdirSync39(secretDir(stateDir), { recursive: true, mode: 448 });
25492
25802
  const secret = randomBytes3(32).toString("base64url");
25493
25803
  const file = secretFile(stateDir, ticketRecordId);
25494
- writeFileSync38(file, `${JSON.stringify({ secret })}
25804
+ writeFileSync39(file, `${JSON.stringify({ secret })}
25495
25805
  `, { mode: 384 });
25496
25806
  chmodSync5(file, 384);
25497
25807
  return secret;
25498
25808
  }
25499
25809
  function readPeriscopeSecret(stateDir, ticketRecordId) {
25500
25810
  try {
25501
- const v = JSON.parse(readFileSync46(secretFile(stateDir, ticketRecordId), "utf8"));
25811
+ const v = JSON.parse(readFileSync47(secretFile(stateDir, ticketRecordId), "utf8"));
25502
25812
  return typeof v.secret === "string" && v.secret ? v.secret : void 0;
25503
25813
  } catch {
25504
25814
  return void 0;
@@ -25509,14 +25819,14 @@ function removePeriscopeSecret(stateDir, ticketRecordId) {
25509
25819
  }
25510
25820
  function readPeriscopeEndpoint(stateDir, ticketRecordId) {
25511
25821
  try {
25512
- return JSON.parse(readFileSync46(endpointFile(stateDir, ticketRecordId), "utf8"));
25822
+ return JSON.parse(readFileSync47(endpointFile(stateDir, ticketRecordId), "utf8"));
25513
25823
  } catch {
25514
25824
  return void 0;
25515
25825
  }
25516
25826
  }
25517
25827
  function writePeriscopeEndpoint(stateDir, rec) {
25518
- mkdirSync38(endpointDir(stateDir), { recursive: true });
25519
- writeFileSync38(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
25828
+ mkdirSync39(endpointDir(stateDir), { recursive: true });
25829
+ writeFileSync39(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
25520
25830
  `);
25521
25831
  }
25522
25832
  function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
@@ -25524,7 +25834,7 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
25524
25834
  }
25525
25835
  function listPeriscopeEndpoints(stateDir) {
25526
25836
  const dir = endpointDir(stateDir);
25527
- if (!existsSync50(dir)) return [];
25837
+ if (!existsSync52(dir)) return [];
25528
25838
  const out = [];
25529
25839
  for (const name of readdirSync19(dir)) {
25530
25840
  if (!name.endsWith(".json")) continue;
@@ -25627,13 +25937,13 @@ async function resolveInWorktree(root, requested) {
25627
25937
  let abs;
25628
25938
  if (isAbsolute5(requested)) {
25629
25939
  abs = resolve6(requested);
25630
- if (isInside(root, abs)) abs = join55(realRoot, relative2(root, abs));
25940
+ if (isInside(root, abs)) abs = join56(realRoot, relative2(root, abs));
25631
25941
  } else {
25632
25942
  abs = resolve6(realRoot, requested);
25633
25943
  }
25634
25944
  if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
25635
25945
  const { real, rest } = await realAncestor(abs);
25636
- const final = rest ? join55(real, rest) : real;
25946
+ const final = rest ? join56(real, rest) : real;
25637
25947
  if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
25638
25948
  if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
25639
25949
  return final;
@@ -25701,7 +26011,7 @@ function createPeriscopeMcpServer(d, sc) {
25701
26011
  const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
25702
26012
  const lines2 = await Promise.all(entries.map(async (e) => {
25703
26013
  if (e.isDirectory()) return `[DIR] ${e.name}`;
25704
- const size = (await lstat(join55(abs, e.name))).size;
26014
+ const size = (await lstat(join56(abs, e.name))).size;
25705
26015
  return `[FILE] ${e.name} (${size} bytes)`;
25706
26016
  }));
25707
26017
  return text(lines2.join("\n") || "(empty)");
@@ -25767,7 +26077,7 @@ function createPeriscopeMcpServer(d, sc) {
25767
26077
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
25768
26078
  }, async ({ path }) => {
25769
26079
  const parent = await inTree(dirname34(path) === "" ? "." : dirname34(path));
25770
- const abs = join55(parent, basename15(path));
26080
+ const abs = join56(parent, basename15(path));
25771
26081
  if (basename15(path) === ".git" || abs === parent) return text("path must name a file", true);
25772
26082
  const st = await lstat(abs).catch(() => void 0);
25773
26083
  if (!st) return text(`${path} does not exist`, true);
@@ -26258,7 +26568,7 @@ if (command === "provision") {
26258
26568
  process.exit(outcome.code);
26259
26569
  }
26260
26570
  if (command === "pool-member") {
26261
- const pool = poolConfigFrom(argv, process.env, () => readFileSync47(0, "utf8"));
26571
+ const pool = poolConfigFrom(argv, process.env, () => readFileSync48(0, "utf8"));
26262
26572
  if (typeof pool === "string") {
26263
26573
  process.stderr.write(`crew pool-member: ${pool}
26264
26574
  `);
@@ -26507,7 +26817,7 @@ if (command === "passenger-sync-daemon") {
26507
26817
  } else {
26508
26818
  const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
26509
26819
  const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
26510
- if (configless && !existsSync51(findConfigFile(CREW_HOME))) {
26820
+ if (configless && !existsSync53(findConfigFile(CREW_HOME))) {
26511
26821
  cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
26512
26822
  } else {
26513
26823
  cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
@@ -26522,7 +26832,7 @@ if (command === "passenger-sync-daemon") {
26522
26832
  throw e;
26523
26833
  }
26524
26834
  if (command === "credential") {
26525
- const r = runCredential(positional[1], readFileSync47(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
26835
+ const r = runCredential(positional[1], readFileSync48(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
26526
26836
  process.stdout.write(r.out);
26527
26837
  process.stderr.write(r.err);
26528
26838
  process.exit(r.code);
@@ -26534,9 +26844,9 @@ if (command === "passenger-sync-daemon") {
26534
26844
  forges: cfg.ship.forges,
26535
26845
  stateDir: cfg.ship.stateDir,
26536
26846
  configFile: cfg.configFile,
26537
- readFile: (p) => readFileSync47(p, "utf8"),
26538
- writeFile: (p, t) => writeFileSync39(p, t),
26539
- stdin: () => readFileSync47(0, "utf8"),
26847
+ readFile: (p) => readFileSync48(p, "utf8"),
26848
+ writeFile: (p, t) => writeFileSync40(p, t),
26849
+ stdin: () => readFileSync48(0, "utf8"),
26540
26850
  env: process.env
26541
26851
  }
26542
26852
  );
@@ -26859,8 +27169,8 @@ if (command === "passenger-sync-daemon") {
26859
27169
  }
26860
27170
  if (host === "linux" && hasSystemd) {
26861
27171
  const label = labelFor(CREW_HOME, "run");
26862
- const staleTimer = join56(homedir11(), ".config", "systemd", "user", `${label}.timer`);
26863
- if (existsSync51(staleTimer)) {
27172
+ const staleTimer = join57(homedir11(), ".config", "systemd", "user", `${label}.timer`);
27173
+ if (existsSync53(staleTimer)) {
26864
27174
  process.stdout.write(
26865
27175
  `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
26866
27176
  `
@@ -26889,7 +27199,7 @@ if (command === "passenger-sync-daemon") {
26889
27199
  const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
26890
27200
  for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
26891
27201
  for (const r of doctorRepos) {
26892
- if (!existsSync51(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
27202
+ if (!existsSync53(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
26893
27203
  if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
26894
27204
  readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
26895
27205
  }
@@ -26916,7 +27226,7 @@ if (command === "passenger-sync-daemon") {
26916
27226
  }
26917
27227
  async function doctorFix(o) {
26918
27228
  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))));
26919
- const unitExists = (p) => existsSync51(p);
27229
+ const unitExists = (p) => existsSync53(p);
26920
27230
  const crontab = o.host === "linux" ? spawnSync12("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
26921
27231
  const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
26922
27232
  const plan = planFix({ routes, schedulerAbsent, host: o.host });
@@ -26933,7 +27243,7 @@ if (command === "passenger-sync-daemon") {
26933
27243
  for (const a of plan.actions) {
26934
27244
  if (a.kind === "enable") {
26935
27245
  if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
26936
- writeFileSync39(cfg.configFile, planEnable(readFileSync47(cfg.configFile, "utf8"), a.route));
27246
+ writeFileSync40(cfg.configFile, planEnable(readFileSync48(cfg.configFile, "utf8"), a.route));
26937
27247
  enabledSound.add(a.route);
26938
27248
  changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
26939
27249
  } else {
@@ -27001,6 +27311,10 @@ ${changed2.map((c) => ` - ${c}
27001
27311
  if (!settings || !mirror) return null;
27002
27312
  return readMirrorContract(new SandboxCache(settings), mirror, c.branch?.base ?? "main");
27003
27313
  }
27314
+ async function planContractOf(c, repo) {
27315
+ const t = repo ? reposOf(c).find((r) => r.name === repo) : void 0;
27316
+ return t && cfg.ship.runner === "sandbox" ? repoContractFor(cfg.ship, c, t) : void 0;
27317
+ }
27004
27318
  async function resolveOneRepo(c, t) {
27005
27319
  {
27006
27320
  const id = repoIdForName(c, t.name);
@@ -27158,7 +27472,7 @@ ${changed2.map((c) => ` - ${c}
27158
27472
  harnessBin: "claude",
27159
27473
  ...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
27160
27474
  },
27161
- policyFile: join56(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
27475
+ policyFile: join57(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
27162
27476
  repo: mirror,
27163
27477
  origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
27164
27478
  base: effective.branch.base,
@@ -27767,6 +28081,7 @@ ${cu.tail.trimEnd()}
27767
28081
  }
27768
28082
  if (dryRun) {
27769
28083
  const fleetPlan2 = planAgentRun({
28084
+ repoContract: await planContractOf(w.route, repoTargetFor(w.route, w.decision.actionable.top?.repo_id)?.name),
27770
28085
  role: w.role,
27771
28086
  route: w.route,
27772
28087
  ship: cfg.ship,
@@ -27877,6 +28192,7 @@ ${cu.tail.trimEnd()}
27877
28192
  }
27878
28193
  }
27879
28194
  const fleetPlan = planAgentRun({
28195
+ repoContract: await planContractOf(w.route, fleetTicketRepo),
27880
28196
  role: w.role,
27881
28197
  route: w.route,
27882
28198
  ship: cfg.ship,
@@ -28101,6 +28417,7 @@ ${cu.tail.trimEnd()}
28101
28417
  }
28102
28418
  }
28103
28419
  const plan = planAgentRun({
28420
+ repoContract: await planContractOf(route2, ticketRepo),
28104
28421
  role: current,
28105
28422
  route: route2,
28106
28423
  ship: cfg.ship,
@@ -28255,7 +28572,7 @@ ${cu.tail.trimEnd()}
28255
28572
  );
28256
28573
  process.exit(1);
28257
28574
  }
28258
- const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join56(CREW_HOME, "src"), join56(CREW_HOME, "dist"), join56(CREW_HOME, "bin")];
28575
+ const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join57(CREW_HOME, "src"), join57(CREW_HOME, "dist"), join57(CREW_HOME, "bin")];
28259
28576
  const configPaths = daemonConfigPaths(cfg);
28260
28577
  watchPaths.push(...configPaths);
28261
28578
  noteDaemonStarted(cfg.ship.stateDir);
@@ -28567,10 +28884,10 @@ ${cu.tail.trimEnd()}
28567
28884
  `);
28568
28885
  if (!dryRun) {
28569
28886
  const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
28570
- const raw = existsSync51(resolvedPath) ? JSON.parse(readFileSync47(resolvedPath, "utf8")) : {};
28887
+ const raw = existsSync53(resolvedPath) ? JSON.parse(readFileSync48(resolvedPath, "utf8")) : {};
28571
28888
  raw.agentSkills = result.agentSkills;
28572
- mkdirSync39(dirOf2(resolvedPath), { recursive: true });
28573
- writeFileSync39(resolvedPath, `${JSON.stringify(raw, null, 2)}
28889
+ mkdirSync40(dirOf2(resolvedPath), { recursive: true });
28890
+ writeFileSync40(resolvedPath, `${JSON.stringify(raw, null, 2)}
28574
28891
  `);
28575
28892
  }
28576
28893
  if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
@@ -28593,7 +28910,7 @@ ${cu.tail.trimEnd()}
28593
28910
  throw e;
28594
28911
  }
28595
28912
  const oldName = cfg.ship.name;
28596
- writeFileSync39(cfg.configFile, setShipNameInYaml(readFileSync47(cfg.configFile, "utf8"), newName));
28913
+ writeFileSync40(cfg.configFile, setShipNameInYaml(readFileSync48(cfg.configFile, "utf8"), newName));
28597
28914
  cfg.ship.name = newName;
28598
28915
  let renameMachineId;
28599
28916
  try {
@@ -28640,7 +28957,7 @@ ${cu.tail.trimEnd()}
28640
28957
  process.exit(2);
28641
28958
  };
28642
28959
  if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
28643
- const configText = readFileSync47(cfg.configFile, "utf8");
28960
+ const configText = readFileSync48(cfg.configFile, "utf8");
28644
28961
  if (sub === "check") {
28645
28962
  try {
28646
28963
  const routeArg = value("route") ?? positional[2];
@@ -28672,8 +28989,8 @@ ${cu.tail.trimEnd()}
28672
28989
  try {
28673
28990
  const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
28674
28991
  const dir = repoDirOf(configText, dirname35(cfg.configFile), a.route, a.name);
28675
- if (!existsSync51(dir)) throw new ReposError(`${dir} does not exist on disk`);
28676
- const files = { exists: (r) => existsSync51(resolvePath(dir, r)), list: (r) => {
28992
+ if (!existsSync53(dir)) throw new ReposError(`${dir} does not exist on disk`);
28993
+ const files = { exists: (r) => existsSync53(resolvePath(dir, r)), list: (r) => {
28677
28994
  try {
28678
28995
  return readdirSync20(resolvePath(dir, r));
28679
28996
  } catch {
@@ -28681,7 +28998,7 @@ ${cu.tail.trimEnd()}
28681
28998
  }
28682
28999
  }, read: (r) => {
28683
29000
  try {
28684
- return readFileSync47(resolvePath(dir, r), "utf8");
29001
+ return readFileSync48(resolvePath(dir, r), "utf8");
28685
29002
  } catch {
28686
29003
  return void 0;
28687
29004
  }
@@ -28723,19 +29040,19 @@ ${cu.tail.trimEnd()}
28723
29040
  let cleared;
28724
29041
  if (clear2) {
28725
29042
  const plan = clearRouteHooks(configText, a.route, a.name);
28726
- if (plan.removed.length > 0) writeFileSync39(cfg.configFile, plan.text);
29043
+ if (plan.removed.length > 0) writeFileSync40(cfg.configFile, plan.text);
28727
29044
  cleared = { file: cfg.configFile, removed: plan.removed };
28728
29045
  }
28729
29046
  if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
28730
29047
  if (write === "route") {
28731
29048
  const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
28732
- writeFileSync39(cfg.configFile, plan.text);
29049
+ writeFileSync40(cfg.configFile, plan.text);
28733
29050
  written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
28734
29051
  } else if (write === "repo") {
28735
29052
  const have = existingRepoConfig(files);
28736
29053
  if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
28737
29054
  const file = resolvePath(dir, ".crew.yaml");
28738
- writeFileSync39(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
29055
+ writeFileSync40(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
28739
29056
  written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
28740
29057
  }
28741
29058
  if (flag("json")) {
@@ -28791,7 +29108,7 @@ ${cu.tail.trimEnd()}
28791
29108
  if (sub === "list" && !routeName) usage2();
28792
29109
  if (sub === "add") {
28793
29110
  try {
28794
- const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync51(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
29111
+ const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync53(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
28795
29112
  routeName = a.route;
28796
29113
  addPath = a.path;
28797
29114
  addName = a.name;
@@ -28821,7 +29138,7 @@ ${cu.tail.trimEnd()}
28821
29138
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
28822
29139
  if (sub === "list" || sub === "add") {
28823
29140
  const liveRoute = cfg.routes.find((r) => r.route === routeName);
28824
- if (liveRoute?.resolved?.reposModelId && existsSync51(resolvedFile) && !dryRun) {
29141
+ if (liveRoute?.resolved?.reposModelId && existsSync53(resolvedFile) && !dryRun) {
28825
29142
  try {
28826
29143
  await hydrateApiKeys([liveRoute]);
28827
29144
  persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
@@ -28830,16 +29147,16 @@ ${cu.tail.trimEnd()}
28830
29147
  }
28831
29148
  }
28832
29149
  let resolvedRemotes;
28833
- if (existsSync51(resolvedFile)) {
29150
+ if (existsSync53(resolvedFile)) {
28834
29151
  try {
28835
- resolvedRemotes = JSON.parse(readFileSync47(resolvedFile, "utf8"));
29152
+ resolvedRemotes = JSON.parse(readFileSync48(resolvedFile, "utf8"));
28836
29153
  } catch {
28837
29154
  }
28838
29155
  }
28839
29156
  const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
28840
29157
  const text2 = configText;
28841
29158
  const base = dirname35(cfg.configFile);
28842
- const isCheckout = (d) => existsSync51(`${d}/.git`);
29159
+ const isCheckout = (d) => existsSync53(`${d}/.git`);
28843
29160
  try {
28844
29161
  if (sub === "list") {
28845
29162
  if (flag("json")) {
@@ -28849,12 +29166,12 @@ ${cu.tail.trimEnd()}
28849
29166
  base,
28850
29167
  resolved: resolvedRemotes,
28851
29168
  originOf,
28852
- exists: (d) => existsSync51(d),
29169
+ exists: (d) => existsSync53(d),
28853
29170
  isCheckout,
28854
29171
  repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f) => {
28855
29172
  try {
28856
29173
  const path = resolvePath(d, f);
28857
- return Object.keys(parseRepoConfig(readFileSync47(path, "utf8"), path).hooks).length > 0;
29174
+ return Object.keys(parseRepoConfig(readFileSync48(path, "utf8"), path).hooks).length > 0;
28858
29175
  } catch {
28859
29176
  return false;
28860
29177
  }
@@ -28871,7 +29188,7 @@ ${cu.tail.trimEnd()}
28871
29188
  for (const r of repos) {
28872
29189
  const origin2 = originOf(r.dir);
28873
29190
  const row = matchRepoName(origin2, resolvedRemotes);
28874
- const note = !existsSync51(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote(origin2) ?? "this checkout (no origin remote)"}`;
29191
+ const note = !existsSync53(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote(origin2) ?? "this checkout (no origin remote)"}`;
28875
29192
  process.stdout.write(`${r.name} ${r.dir} ${note}
28876
29193
  `);
28877
29194
  }
@@ -28883,9 +29200,9 @@ ${cu.tail.trimEnd()}
28883
29200
  ` : `${human}
28884
29201
  `);
28885
29202
  const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
28886
- if (existsSync51(plan2.target) && (existsSync51(`${plan2.target}/.git`) || readdirSync20(plan2.target).length > 0)) {
29203
+ if (existsSync53(plan2.target) && (existsSync53(`${plan2.target}/.git`) || readdirSync20(plan2.target).length > 0)) {
28887
29204
  throw new ReposError(
28888
- existsSync51(`${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`
29205
+ existsSync53(`${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`
28889
29206
  );
28890
29207
  }
28891
29208
  if (dryRun) {
@@ -28903,14 +29220,14 @@ ${cu.tail.trimEnd()}
28903
29220
  throw new ReposError(`${e.message}${authHint}
28904
29221
  crew.yaml was not changed`);
28905
29222
  }
28906
- writeFileSync39(cfg.configFile, plan2.text);
29223
+ writeFileSync40(cfg.configFile, plan2.text);
28907
29224
  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:
28908
29225
  `);
28909
29226
  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}`);
28910
29227
  break;
28911
29228
  }
28912
29229
  const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
28913
- const top = existsSync51(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
29230
+ const top = existsSync53(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
28914
29231
  if (!top) throw new ReposError(`${target} is not a git checkout`);
28915
29232
  const origin = originOf(top);
28916
29233
  const plan = planRepoAdd({
@@ -28962,15 +29279,15 @@ ${cu.tail.trimEnd()}
28962
29279
  const created = await rowTracker.createRepoRow(rowPayload);
28963
29280
  process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
28964
29281
  `);
28965
- if (existsSync51(resolvedFile)) {
28966
- const raw = JSON.parse(readFileSync47(resolvedFile, "utf8"));
29282
+ if (existsSync53(resolvedFile)) {
29283
+ const raw = JSON.parse(readFileSync48(resolvedFile, "utf8"));
28967
29284
  raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
28968
29285
  raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
28969
- writeFileSync39(resolvedFile, `${JSON.stringify(raw, null, 2)}
29286
+ writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
28970
29287
  `);
28971
29288
  }
28972
29289
  }
28973
- writeFileSync39(cfg.configFile, plan.text);
29290
+ writeFileSync40(cfg.configFile, plan.text);
28974
29291
  process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
28975
29292
  `);
28976
29293
  } catch (e) {
@@ -29345,7 +29662,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
29345
29662
  process.exit(2);
29346
29663
  }
29347
29664
  if (found.shipNameAdopted && !dryRun) {
29348
- writeFileSync39(cfg.configFile, setShipNameInYaml(readFileSync47(cfg.configFile, "utf8"), found.shipNameAdopted));
29665
+ writeFileSync40(cfg.configFile, setShipNameInYaml(readFileSync48(cfg.configFile, "utf8"), found.shipNameAdopted));
29349
29666
  cfg.ship.name = found.shipNameAdopted;
29350
29667
  }
29351
29668
  if (found.shipRow) {
@@ -29388,10 +29705,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
29388
29705
  }
29389
29706
  }
29390
29707
  let previous;
29391
- const hadPreviousFile = existsSync51(resolvedPath);
29708
+ const hadPreviousFile = existsSync53(resolvedPath);
29392
29709
  if (hadPreviousFile) {
29393
29710
  try {
29394
- previous = JSON.parse(readFileSync47(resolvedPath, "utf8"));
29711
+ previous = JSON.parse(readFileSync48(resolvedPath, "utf8"));
29395
29712
  } catch {
29396
29713
  }
29397
29714
  }
@@ -29521,12 +29838,12 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
29521
29838
  process.stderr.write(`(dry run) would write resolved ids to ${resolvedPath}
29522
29839
  `);
29523
29840
  } else {
29524
- mkdirSync39(dirname35(resolvedPath), { recursive: true });
29841
+ mkdirSync40(dirname35(resolvedPath), { recursive: true });
29525
29842
  if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
29526
29843
  const tmpPath = `${resolvedPath}.tmp${process.pid}`;
29527
- writeFileSync39(tmpPath, `${JSON.stringify(resolved, null, 2)}
29844
+ writeFileSync40(tmpPath, `${JSON.stringify(resolved, null, 2)}
29528
29845
  `);
29529
- renameSync6(tmpPath, resolvedPath);
29846
+ renameSync7(tmpPath, resolvedPath);
29530
29847
  process.stderr.write(`Resolved ids written to ${resolvedPath}
29531
29848
  `);
29532
29849
  }
@@ -29570,8 +29887,8 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
29570
29887
  process.stderr.write(`(dry run) would write the minted API key to ${apiKeyFile}
29571
29888
  `);
29572
29889
  } else {
29573
- mkdirSync39(dirname35(apiKeyFile), { recursive: true });
29574
- writeFileSync39(apiKeyFile, `${apiKeyVar}=${apiKey}
29890
+ mkdirSync40(dirname35(apiKeyFile), { recursive: true });
29891
+ writeFileSync40(apiKeyFile, `${apiKeyVar}=${apiKey}
29575
29892
  `, { mode: 384 });
29576
29893
  process.stderr.write(`API key written to ${apiKeyFile}
29577
29894
  `);
@@ -29889,7 +30206,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
29889
30206
  const r = wanted[0];
29890
30207
  const repoName = value("repo");
29891
30208
  const seat = resolveSeat(cfg.ship, r, role, {}, repoName);
29892
- const input = sandboxPolicyInputFor(r, seat.toolchain, { harnessBin: seat.toolchain.bin, repo: repoName, sandbox: cfg.ship.sandbox });
30209
+ const input = sandboxPolicyInputFor(r, seat.toolchain, { harnessBin: seat.toolchain.bin, repo: repoName, sandbox: cfg.ship.sandbox, contract: await planContractOf(r, repoName) });
29893
30210
  try {
29894
30211
  const policy = generateSandboxPolicy({ mirrorDir: cfg.ship.sandbox?.mirrorDir, workDir: cfg.ship.sandbox?.workDir, ...input });
29895
30212
  process.stdout.write(flag("json") ? `${JSON.stringify({ route: r.route, role, input, groups: policy.groups, yaml: policy.yaml }, null, 2)}
@@ -30286,10 +30603,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30286
30603
  startupSeconds: cfg.ship.intelStartupSeconds,
30287
30604
  prepare: async (path) => {
30288
30605
  for (const f of repoWt.config.worktrees.copy) {
30289
- const src = join56(repoWt.dir, f);
30290
- if (!existsSync51(src) || existsSync51(join56(path, f))) continue;
30291
- mkdirSync39(dirOf2(join56(path, f)), { recursive: true });
30292
- copyFileSync2(src, join56(path, f));
30606
+ const src = join57(repoWt.dir, f);
30607
+ if (!existsSync53(src) || existsSync53(join57(path, f))) continue;
30608
+ mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
30609
+ copyFileSync2(src, join57(path, f));
30293
30610
  }
30294
30611
  const setup = repoWt.config.hooks.setup;
30295
30612
  return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
@@ -30510,7 +30827,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
30510
30827
  const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
30511
30828
  const resumed = await runPeriscopeResume({
30512
30829
  find: async () => hit && { row: hit.row, tag: hit.tag },
30513
- worktreeExists: (p) => existsSync51(p),
30830
+ worktreeExists: (p) => existsSync53(p),
30514
30831
  prepareDropFile,
30515
30832
  startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
30516
30833
  caps: periscopeCaps(cfg.ship),
@@ -30606,10 +30923,10 @@ ${where.join("\n")}`);
30606
30923
  },
30607
30924
  prepare: async (path) => {
30608
30925
  for (const f of repoP.config.worktrees.copy) {
30609
- const src = join56(repoP.dir, f);
30610
- if (!existsSync51(src)) continue;
30611
- mkdirSync39(dirOf2(join56(path, f)), { recursive: true });
30612
- copyFileSync2(src, join56(path, f));
30926
+ const src = join57(repoP.dir, f);
30927
+ if (!existsSync53(src)) continue;
30928
+ mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
30929
+ copyFileSync2(src, join57(path, f));
30613
30930
  }
30614
30931
  const setup = repoP.config.hooks.setup;
30615
30932
  return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
@@ -30920,7 +31237,7 @@ ${where.join("\n")}`);
30920
31237
  };
30921
31238
  const droppedRoutes = [];
30922
31239
  try {
30923
- const rawCfg = parseYaml2(readFileSync47(cfg.configFile, "utf8"));
31240
+ const rawCfg = parseYaml2(readFileSync48(cfg.configFile, "utf8"));
30924
31241
  for (const r of rawCfg?.routes ?? []) {
30925
31242
  if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
30926
31243
  try {
@@ -30984,8 +31301,8 @@ ${where.join("\n")}`);
30984
31301
  process.stdout.write("crew reload: no daemon unit is running \u2014 nothing to reload (the next run reads crew.yaml fresh)\n");
30985
31302
  break;
30986
31303
  }
30987
- mkdirSync39(cfg.ship.stateDir, { recursive: true });
30988
- writeFileSync39(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
31304
+ mkdirSync40(cfg.ship.stateDir, { recursive: true });
31305
+ writeFileSync40(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
30989
31306
  `);
30990
31307
  process.stdout.write(
30991
31308
  "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"
@@ -31050,7 +31367,7 @@ ${where.join("\n")}`);
31050
31367
  }
31051
31368
  case "log": {
31052
31369
  try {
31053
- const text2 = readFileSync47(cfg.ship.logFile, "utf8").split("\n");
31370
+ const text2 = readFileSync48(cfg.ship.logFile, "utf8").split("\n");
31054
31371
  process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
31055
31372
  `);
31056
31373
  } catch {
@@ -31073,7 +31390,7 @@ ${where.join("\n")}`);
31073
31390
  };
31074
31391
  if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
31075
31392
  const tracker = new Tracker(route2, cfg.ship);
31076
- const configText = readFileSync47(cfg.configFile, "utf8");
31393
+ const configText = readFileSync48(cfg.configFile, "utf8");
31077
31394
  const cfgBase = dirname35(cfg.configFile);
31078
31395
  const configured2 = configuredRepos(configText, route2.route, cfgBase);
31079
31396
  const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
@@ -31102,7 +31419,7 @@ ${where.join("\n")}`);
31102
31419
  }
31103
31420
  if (configured2.some((r) => r.dir === dir)) {
31104
31421
  try {
31105
- writeFileSync39(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
31422
+ writeFileSync40(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
31106
31423
  } catch (e) {
31107
31424
  if (e instanceof ReposError) fail2(e.message);
31108
31425
  throw e;
@@ -31110,29 +31427,29 @@ ${where.join("\n")}`);
31110
31427
  }
31111
31428
  if (row) {
31112
31429
  await tracker.deleteRepoRow(row.id);
31113
- if (existsSync51(resolvedFile)) {
31114
- const raw = JSON.parse(readFileSync47(resolvedFile, "utf8"));
31430
+ if (existsSync53(resolvedFile)) {
31431
+ const raw = JSON.parse(readFileSync48(resolvedFile, "utf8"));
31115
31432
  if (raw.repoNames) delete raw.repoNames[row.id];
31116
31433
  if (raw.repoRemotes) delete raw.repoRemotes[row.id];
31117
- writeFileSync39(resolvedFile, `${JSON.stringify(raw, null, 2)}
31434
+ writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
31118
31435
  `);
31119
31436
  }
31120
31437
  }
31121
- if (existsSync51(join56(dir, ".git")) && basename16(dir) === SAMPLE_REPO) rmSync25(dir, { recursive: true, force: true });
31438
+ if (existsSync53(join57(dir, ".git")) && basename16(dir) === SAMPLE_REPO) rmSync25(dir, { recursive: true, force: true });
31122
31439
  say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
31123
31440
  break;
31124
31441
  }
31125
31442
  const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
31126
- const fresh = !existsSync51(join56(dir, ".git"));
31127
- if (existsSync51(dir) && fresh && readdirSync20(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
31443
+ const fresh = !existsSync53(join57(dir, ".git"));
31444
+ if (existsSync53(dir) && fresh && readdirSync20(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
31128
31445
  if (dryRun) {
31129
31446
  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`);
31130
31447
  break;
31131
31448
  }
31132
31449
  if (fresh) {
31133
- mkdirSync39(dir, { recursive: true });
31134
- writeFileSync39(join56(dir, "README.md"), SAMPLE_README);
31135
- writeFileSync39(join56(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
31450
+ mkdirSync40(dir, { recursive: true });
31451
+ writeFileSync40(join57(dir, "README.md"), SAMPLE_README);
31452
+ writeFileSync40(join57(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
31136
31453
  const g = (...a) => {
31137
31454
  const r = spawnSync12("git", a, { cwd: dir, encoding: "utf8" });
31138
31455
  if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
@@ -31150,17 +31467,17 @@ ${where.join("\n")}`);
31150
31467
  spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
31151
31468
  });
31152
31469
  repoId = (await tracker.createRepoRow(payload)).id;
31153
- if (existsSync51(resolvedFile)) {
31154
- const raw = JSON.parse(readFileSync47(resolvedFile, "utf8"));
31470
+ if (existsSync53(resolvedFile)) {
31471
+ const raw = JSON.parse(readFileSync48(resolvedFile, "utf8"));
31155
31472
  raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
31156
31473
  raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
31157
- writeFileSync39(resolvedFile, `${JSON.stringify(raw, null, 2)}
31474
+ writeFileSync40(resolvedFile, `${JSON.stringify(raw, null, 2)}
31158
31475
  `);
31159
31476
  }
31160
31477
  }
31161
31478
  if (!configured2.some((r) => r.dir === dir)) {
31162
31479
  try {
31163
- writeFileSync39(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
31480
+ writeFileSync40(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
31164
31481
  } catch (e) {
31165
31482
  if (e instanceof ReposError) fail2(e.message);
31166
31483
  throw e;
@@ -31506,7 +31823,7 @@ watermark: ${state.watermark()}
31506
31823
  }
31507
31824
  for (const r of repos) {
31508
31825
  const remote = r.config.branch.remote;
31509
- if (existsSync51(r.dir)) {
31826
+ if (existsSync53(r.dir)) {
31510
31827
  pushAuth.push({
31511
31828
  route: c.route,
31512
31829
  repo: r.name,
@@ -31579,7 +31896,7 @@ watermark: ${state.watermark()}
31579
31896
  }
31580
31897
  }
31581
31898
  for (const message of roleCapWarnings(cfg.ship)) problems.push({ severity: "note", kind: "role_cap_above_ship_cap", message });
31582
- const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync51, userInfo2().username);
31899
+ const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync53, userInfo2().username);
31583
31900
  if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
31584
31901
  if (!flag("offline")) {
31585
31902
  const shipKind = await doctorShipKind(route2, cfg.ship);
@@ -31591,8 +31908,12 @@ watermark: ${state.watermark()}
31591
31908
  try {
31592
31909
  const missing = unmirroredRepos(sandboxCacheRepos(route2, cfg.ship), await new SandboxCache(cacheSettings).list());
31593
31910
  for (const r of missing) problems.push({ severity: "attention", kind: "sandbox_cache_unmirrored", route: route2.route, message: `${r} has no mirror in the cache volume ${cacheSettings.volume}, so sandboxed runs cannot clone it`, remedy: "see `crew sandbox cache` for the last refresh failure" });
31594
- const labeled = await new SandboxCache(cacheSettings).volumeWorkspace();
31595
- if (labeled !== null && labeled !== cacheSettings.workspace) problems.push({ severity: "blocker", kind: "sandbox_cache_workspace_mismatch", route: route2.route, message: `the cache volume ${cacheSettings.volume} is labeled for OpenShell workspace "${labeled}" but sandboxes are created in "${cacheSettings.workspace}", so the gateway refuses to mount it`, remedy: "run `crew sandbox cache --reset` to recreate the volume with the right label" });
31911
+ const cache = new SandboxCache(cacheSettings);
31912
+ const labels = await cache.volumeLabels();
31913
+ if (labels && !cache.labelsOk(labels)) {
31914
+ const kind = labels.attachable === "true" && labels.workspace !== null ? "sandbox_cache_workspace_mismatch" : "sandbox_cache_unlabeled";
31915
+ problems.push({ severity: "blocker", kind, route: route2.route, message: cache.labelProblem(labels), remedy: "run `crew sandbox cache --reset` to recreate the volume with the right labels" });
31916
+ }
31596
31917
  } catch {
31597
31918
  }
31598
31919
  }
@@ -31640,7 +31961,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
31640
31961
  }
31641
31962
  try {
31642
31963
  const evFile = eventFileFor(cfg.ship.stateDir);
31643
- const evSize = existsSync51(evFile) ? statSync16(evFile).size : 0;
31964
+ const evSize = existsSync53(evFile) ? statSync16(evFile).size : 0;
31644
31965
  process.stdout.write(
31645
31966
  evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
31646
31967
  ` : "events log: ok\n"
@@ -31651,7 +31972,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
31651
31972
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
31652
31973
  const abandons = unitAbandonsAgents(unitPlan, (p) => {
31653
31974
  try {
31654
- return readFileSync47(p, "utf8");
31975
+ return readFileSync48(p, "utf8");
31655
31976
  } catch {
31656
31977
  return null;
31657
31978
  }
@@ -31666,7 +31987,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
31666
31987
  const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
31667
31988
  const keeps = unitAbandonsAgents(pPlan, (p) => {
31668
31989
  try {
31669
- return readFileSync47(p, "utf8");
31990
+ return readFileSync48(p, "utf8");
31670
31991
  } catch {
31671
31992
  return null;
31672
31993
  }
@@ -31680,7 +32001,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
31680
32001
  if (host === "linux" && detectSystemd()) {
31681
32002
  const ctl = planDaemonControl(CREW_HOME, host, true);
31682
32003
  const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
31683
- if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync51(p))) {
32004
+ if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync53(p))) {
31684
32005
  const st = spawnSync12(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
31685
32006
  if (!st.error && st.status !== 0) {
31686
32007
  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");