@tablation/crew 0.154.0 → 0.154.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -7214,14 +7214,14 @@ function envForRepository(entries, repo) {
7214
7214
 
7215
7215
  // src/interrupted.ts
7216
7216
  import { existsSync as existsSync30, readdirSync as readdirSync10, readFileSync as readFileSync32 } from "fs";
7217
- import { join as join34 } from "path";
7217
+ import { join as join35 } from "path";
7218
7218
 
7219
7219
  // src/agent.ts
7220
7220
  import { spawnSync as spawnSync6 } from "child_process";
7221
7221
  import { readFileSync as readFileSync31, existsSync as existsSync29, statSync as statSync9, mkdirSync as mkdirSync22, writeFileSync as writeFileSync23, createWriteStream, openSync as openSync4, closeSync as closeSync4, readSync } from "fs";
7222
7222
  import { StringDecoder } from "string_decoder";
7223
7223
  import { finished } from "stream/promises";
7224
- import { join as join33, dirname as dirname16, basename as basename9 } from "path";
7224
+ import { join as join34, dirname as dirname17, basename as basename9 } from "path";
7225
7225
  import { createHash as createHash6, randomUUID as randomUUID2 } from "crypto";
7226
7226
 
7227
7227
  // src/state.ts
@@ -9180,13 +9180,14 @@ var runInputFor = (run4) => live.get(run4);
9180
9180
 
9181
9181
  // src/agent-log.ts
9182
9182
  import { existsSync as existsSync25, mkdirSync as mkdirSync18, readdirSync as readdirSync8, readFileSync as readFileSync25, rmSync as rmSync14, writeFileSync as writeFileSync19 } from "fs";
9183
- import { join as join27 } from "path";
9183
+ import { join as join28 } from "path";
9184
9184
 
9185
9185
  // src/pending-backoff.ts
9186
9186
  var sleepBackoff = (attempts) => Math.min(6e4 * 2 ** Math.max(0, attempts - 1), 30 * 6e4);
9187
9187
 
9188
9188
  // src/handoff-guard.ts
9189
- import { existsSync as existsSync24 } from "fs";
9189
+ import { existsSync as existsSync24, realpathSync as realpathSync2 } from "fs";
9190
+ import { dirname as dirname14, join as join27 } from "path";
9190
9191
 
9191
9192
  // src/ticket-branch.ts
9192
9193
  import { basename as basename7 } from "path";
@@ -10823,6 +10824,67 @@ function inspectHandoff(dir, cfg, ticket, role) {
10823
10824
  }
10824
10825
  return { kind: "pushed", branch, sha: origin, remote };
10825
10826
  }
10827
+ var sameDir = (a, b) => {
10828
+ try {
10829
+ return realpathSync2(a) === realpathSync2(b);
10830
+ } catch {
10831
+ return a === b;
10832
+ }
10833
+ };
10834
+ function repairMisnamedBranch(dir, cfg, ticket, role) {
10835
+ const expected = branchCandidatesForTicket(cfg, ticket, role).find((c) => !c.endsWith("*"));
10836
+ if (!expected) return { kind: "none" };
10837
+ const wtPath = join27(dirname14(dir), worktreeForTicket(dir, cfg, ticket, role));
10838
+ const wt = worktrees(dir).find((w) => !w.prunable && sameDir(w.path, wtPath));
10839
+ const from = wt?.branch;
10840
+ if (!wt || !from || from === cfg.branch.base) return { kind: "none" };
10841
+ const existing = existingBranchForTicket(dir, cfg, ticket, role);
10842
+ if (existing === from) return { kind: "none" };
10843
+ const base = [`${cfg.branch.remote}/${cfg.branch.base}`, cfg.branch.base].find((b) => gitOk(dir, ["rev-parse", "--verify", "-q", b]) !== null);
10844
+ const ahead = base ? Number(gitOk(dir, ["rev-list", "--count", `${base}..${from}`]) ?? "1") : 1;
10845
+ if (ahead === 0) return { kind: "none" };
10846
+ if (existing) {
10847
+ return {
10848
+ kind: "refused",
10849
+ from,
10850
+ to: existing,
10851
+ local: headSha(wt.path),
10852
+ reason: `the ticket's worktree is on \`${from}\`, but the contract branch \`${existing}\` already exists and the runner will not overwrite it, so \`${from}\` was left as it is (expected name: \`${expected}\`)`
10853
+ };
10854
+ }
10855
+ try {
10856
+ git(dir, ["branch", "-m", from, expected]);
10857
+ } catch (e) {
10858
+ return {
10859
+ kind: "refused",
10860
+ from,
10861
+ to: expected,
10862
+ local: headSha(wt.path),
10863
+ reason: `the ticket's worktree is on \`${from}\`, not the expected \`${expected}\`, and renaming it failed: ${e.message}`
10864
+ };
10865
+ }
10866
+ return { kind: "renamed", from, to: expected };
10867
+ }
10868
+ async function announceRename(i, ticketId, r, sha, remote, log) {
10869
+ let remoteNote;
10870
+ const tip = remoteTip(i.dir, remote, r.from);
10871
+ if (tip === null) remoteNote = `Could not ask \`${remote}\` about \`${r.from}\`, so any copy of it there was left in place.`;
10872
+ else if (!tip) remoteNote = `\`${r.from}\` was never on \`${remote}\`.`;
10873
+ else if (tip === sha) {
10874
+ try {
10875
+ git(i.dir, ["push", remote, "--delete", r.from]);
10876
+ remoteNote = `The misnamed \`${remote}/${r.from}\` was at the same tip and has been deleted.`;
10877
+ } catch (e) {
10878
+ remoteNote = `\`${remote}/${r.from}\` is at the same tip but could not be deleted: ${e.message}`;
10879
+ }
10880
+ } else remoteNote = `\`${remote}/${r.from}\` is at \`${tip}\`, a different tip than the renamed branch, and was left in place.`;
10881
+ await i.writer.postEvent(
10882
+ ticketId,
10883
+ `The runner renamed the local branch \`${r.from}\` to \`${r.to}\` (the contract name) and pushed it to \`${remote}\` at ${sha}: the ${i.role} run built this ticket on a branch with another name, which QA and the release phase cannot find. ${remoteNote}`,
10884
+ i.seatId,
10885
+ "renamed_by_runner"
10886
+ ).catch((e) => i.log.warn(`renamed, but the note failed to post: ${e.message}`, log));
10887
+ }
10826
10888
  function pushableBounce(dir, v) {
10827
10889
  if (!v.branch || !v.local) return false;
10828
10890
  return !v.origin || isAncestor(dir, v.origin, v.local);
@@ -10944,6 +11006,17 @@ ${acceptanceChecklistBlock(shown(all))}
10944
11006
  }
10945
11007
  return boundNote(build(most));
10946
11008
  }
11009
+ function pushForSeat(i, t, v) {
11010
+ const wt = worktrees(i.dir).find((w) => w.branch === v.branch);
11011
+ try {
11012
+ pushBranchUpstream(wt?.path ?? i.dir, v.remote, v.branch);
11013
+ const again = inspectHandoff(i.dir, i.cfg, t, i.role);
11014
+ if (again.kind === "pushed") return { again };
11015
+ return { error: `the push succeeded but ${again.kind === "bounce" ? again.reason : again.why}` };
11016
+ } catch (e) {
11017
+ return { error: e.message };
11018
+ }
11019
+ }
10947
11020
  async function enforceHandoff(i) {
10948
11021
  try {
10949
11022
  const t = await i.writer.ticket(i.ticketId);
@@ -10954,7 +11027,10 @@ async function enforceHandoff(i) {
10954
11027
  i.log.emit(`${displayKey(t)} is at ${t.status}, not handed off \u2014 nothing to check`, log);
10955
11028
  return { kind: "not-handed-off" };
10956
11029
  }
10957
- const v = i.origin ? inspectRemoteHandoff(i.origin, i.cfg, t, i.role) : inspectHandoff(i.dir, i.cfg, t, i.role);
11030
+ const repair = i.origin ? { kind: "none" } : repairMisnamedBranch(i.dir, i.cfg, t, i.role);
11031
+ const renamed = repair.kind === "renamed" ? repair : null;
11032
+ if (renamed) i.log.warn(`${displayKey(t)}: renamed the misnamed branch ${renamed.from} to ${renamed.to}`, log);
11033
+ const v = repair.kind === "refused" ? { kind: "bounce", branch: null, remote: i.cfg.branch.remote, local: repair.local, origin: null, reason: repair.reason } : i.origin ? inspectRemoteHandoff(i.origin, i.cfg, t, i.role) : inspectHandoff(i.dir, i.cfg, t, i.role);
10958
11034
  if (v.kind === "unverified") {
10959
11035
  i.log.warn(`${displayKey(t)} is at ${t.status} but the push was not checked: ${v.why}`, log);
10960
11036
  return { kind: "unverified", why: v.why };
@@ -10983,10 +11059,21 @@ async function enforceHandoff(i) {
10983
11059
  }
10984
11060
  if (v.kind === "pushed") {
10985
11061
  await postPushed(i, t.id, v.sha, v.remote, v.branch, log);
11062
+ if (renamed) await announceRename(i, t.id, renamed, v.sha, v.remote, log);
10986
11063
  i.log.emit(`${displayKey(t)} pushed at ${v.sha.slice(0, 7)} \u2014 handed on to QA`, log);
10987
11064
  return { kind: "pushed", sha: v.sha };
10988
11065
  }
10989
11066
  if (claimed) {
11067
+ if (renamed && pushableBounce(i.dir, v)) {
11068
+ const done = pushForSeat(i, t, v);
11069
+ if (done.again) {
11070
+ await postPushed(i, t.id, done.again.sha, done.again.remote, done.again.branch, log);
11071
+ await announceRename(i, t.id, renamed, done.again.sha, done.again.remote, log);
11072
+ return { kind: "pushed", sha: done.again.sha };
11073
+ }
11074
+ i.log.warn(`${displayKey(t)} is at ${t.status} and its renamed branch could not be pushed: ${done.error}`, log);
11075
+ return { kind: "failed", why: done.error ?? v.reason };
11076
+ }
10990
11077
  i.log.warn(`${displayKey(t)} is at ${t.status} but its branch is not on the remote at HEAD: ${v.reason}`, log);
10991
11078
  return { kind: "failed", why: v.reason };
10992
11079
  }
@@ -11005,26 +11092,24 @@ async function enforceHandoff(i) {
11005
11092
  }
11006
11093
  let pushError;
11007
11094
  if (pushableBounce(i.dir, v)) {
11008
- const wt = worktrees(i.dir).find((w) => w.branch === v.branch);
11009
- try {
11010
- pushBranchUpstream(wt?.path ?? i.dir, v.remote, v.branch);
11011
- const again = inspectHandoff(i.dir, i.cfg, t, i.role);
11012
- if (again.kind === "pushed") {
11013
- await postPushed(i, t.id, again.sha, again.remote, again.branch, log);
11095
+ const done = pushForSeat(i, t, v);
11096
+ if (done.again) {
11097
+ const again = done.again;
11098
+ const posted = await postPushed(i, t.id, again.sha, again.remote, again.branch, log).then(() => null, (e) => e.message);
11099
+ if (posted !== null) pushError = posted;
11100
+ else {
11014
11101
  await i.writer.postEvent(
11015
11102
  t.id,
11016
11103
  `The runner pushed \`${again.branch}\` to \`${again.remote}\` on ${i.shipName ? `${i.shipName}'s` : "this ship's"} behalf: the ${i.role} seat set \`${i.contract.statuses.handoff}\` without pushing. Plain fast-forward push.${i.cfg.hooks.ci_status ? " The repo's `ci_status` hook was NOT run by the hand-off guard, so CI was not checked by the builder." : ""}`,
11017
11104
  i.seatId,
11018
11105
  "pushed_by_runner"
11019
11106
  ).catch((e) => i.log.warn(`pushed, but the note failed to post: ${e.message}`, log));
11107
+ if (renamed) await announceRename(i, t.id, renamed, again.sha, again.remote, log);
11020
11108
  i.log.emit(`${displayKey(t)}: pushed ${again.branch} to ${again.remote} on the seat's behalf at ${again.sha.slice(0, 7)} \u2014 handed on to QA`, log);
11021
11109
  return { kind: "pushed", sha: again.sha };
11022
11110
  }
11023
- pushError = `the push succeeded but ${again.kind === "bounce" ? again.reason : again.why}`;
11024
- } catch (e) {
11025
- pushError = e.message;
11026
- }
11027
- i.log.warn(`${displayKey(t)}: the runner's own push failed: ${pushError}`, log);
11111
+ } else pushError = done.error;
11112
+ if (pushError) i.log.warn(`${displayKey(t)}: the runner's own push failed: ${pushError}`, log);
11028
11113
  }
11029
11114
  if (!await deliverNote(i, t.id, bounceComment(v, i.shipName, pushError), "bounced", log)) {
11030
11115
  i.log.warn(`${displayKey(t)}: ${v.reason}, but the bounce note could not be delivered \u2014 left at ${t.status}, guard outcome unverified`, log);
@@ -11758,17 +11843,17 @@ async function addRunToTicket(target, t, recordId, run4) {
11758
11843
  };
11759
11844
  }
11760
11845
  }
11761
- var queueDir = (stateDir) => join27(stateDir, "pending-agent-logs");
11846
+ var queueDir = (stateDir) => join28(stateDir, "pending-agent-logs");
11762
11847
  function queueAgentRun(stateDir, name, q2) {
11763
11848
  mkdirSync18(queueDir(stateDir), { recursive: true });
11764
- writeFileSync19(join27(queueDir(stateDir), `${name}.json`), JSON.stringify(q2));
11849
+ writeFileSync19(join28(queueDir(stateDir), `${name}.json`), JSON.stringify(q2));
11765
11850
  }
11766
11851
  async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
11767
11852
  const dir = queueDir(stateDir);
11768
11853
  if (!existsSync25(dir)) return 0;
11769
11854
  let sent = 0;
11770
11855
  for (const f of readdirSync8(dir).filter((n) => n.endsWith(".json")).sort()) {
11771
- const path = join27(dir, f);
11856
+ const path = join28(dir, f);
11772
11857
  let q2;
11773
11858
  try {
11774
11859
  q2 = JSON.parse(readFileSync25(path, "utf8"));
@@ -11811,17 +11896,17 @@ async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__
11811
11896
  }
11812
11897
  return sent;
11813
11898
  }
11814
- var countersDir = (stateDir) => join27(stateDir, "pending-ticket-counters");
11899
+ var countersDir = (stateDir) => join28(stateDir, "pending-ticket-counters");
11815
11900
  function queueTicketCounters(stateDir, name, q2) {
11816
11901
  mkdirSync18(countersDir(stateDir), { recursive: true });
11817
- writeFileSync19(join27(countersDir(stateDir), `${name}.json`), JSON.stringify(q2));
11902
+ writeFileSync19(join28(countersDir(stateDir), `${name}.json`), JSON.stringify(q2));
11818
11903
  }
11819
11904
  async function replayQueuedTicketCounters(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
11820
11905
  const dir = countersDir(stateDir);
11821
11906
  if (!existsSync25(dir)) return 0;
11822
11907
  let sent = 0;
11823
11908
  for (const f of readdirSync8(dir).filter((n) => n.endsWith(".json")).sort()) {
11824
- const path = join27(dir, f);
11909
+ const path = join28(dir, f);
11825
11910
  let q2;
11826
11911
  try {
11827
11912
  q2 = JSON.parse(readFileSync25(path, "utf8"));
@@ -12085,8 +12170,8 @@ var HandoffTranscriptTracker = class {
12085
12170
  // src/seat-notes.ts
12086
12171
  import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync19, readFileSync as readFileSync26, renameSync as renameSync4, rmSync as rmSync15, writeFileSync as writeFileSync20 } from "fs";
12087
12172
  import { randomUUID } from "crypto";
12088
- import { join as join28 } from "path";
12089
- var fileFor2 = (stateDir, role) => join28(stateDir, "seat-notes", `${role}.jsonl`);
12173
+ import { join as join29 } from "path";
12174
+ var fileFor2 = (stateDir, role) => join29(stateDir, "seat-notes", `${role}.jsonl`);
12090
12175
  var sameTicket = (a, b) => a.trim().toLowerCase() === b.trim().toLowerCase();
12091
12176
  function readAll(stateDir, role) {
12092
12177
  let raw;
@@ -12107,7 +12192,7 @@ function readAll(stateDir, role) {
12107
12192
  }
12108
12193
  function addSeatNote(stateDir, note, now = /* @__PURE__ */ new Date()) {
12109
12194
  const full = { id: randomUUID(), createdAt: now.toISOString(), ...note };
12110
- mkdirSync19(join28(stateDir, "seat-notes"), { recursive: true });
12195
+ mkdirSync19(join29(stateDir, "seat-notes"), { recursive: true });
12111
12196
  appendFileSync3(fileFor2(stateDir, note.role), `${JSON.stringify(full)}
12112
12197
  `);
12113
12198
  return full;
@@ -12146,7 +12231,7 @@ import { createHash as createHash4 } from "crypto";
12146
12231
  import { spawn as spawn4 } from "child_process";
12147
12232
  import { execFileSync as execFileSync8 } from "child_process";
12148
12233
  import { existsSync as existsSync26, mkdirSync as mkdirSync20, readFileSync as readFileSync27, renameSync as renameSync5, writeFileSync as writeFileSync21, rmSync as rmSync16, statSync as statSync8 } from "fs";
12149
- import { dirname as dirname14, join as join29 } from "path";
12234
+ import { dirname as dirname15, join as join30 } from "path";
12150
12235
  import { fileURLToPath } from "url";
12151
12236
  import { tmpdir as tmpdir3 } from "os";
12152
12237
  var SANDBOX_BASE_IMAGE = "nvcr.io/nvidia/base/ubuntu:24.04";
@@ -12161,8 +12246,8 @@ var SANDBOX_UID = 1e3;
12161
12246
  var CREW_PREFIX = "/opt/crew";
12162
12247
  var SANDBOX_BRIDGE_PATH = `${CREW_PREFIX}/bin/intel-bridge`;
12163
12248
  function readBridgeBundle() {
12164
- const here = dirname14(fileURLToPath(import.meta.url));
12165
- for (const p of [join29(here, "sandbox-intel-bridge.cjs"), join29(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
12249
+ const here = dirname15(fileURLToPath(import.meta.url));
12250
+ for (const p of [join30(here, "sandbox-intel-bridge.cjs"), join30(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
12166
12251
  if (existsSync26(p)) return readFileSync27(p, "utf8");
12167
12252
  }
12168
12253
  return void 0;
@@ -12338,7 +12423,7 @@ function planSandbox(repo, decl, warm = {}, bridge) {
12338
12423
  }
12339
12424
  var SHIP_SANDBOX_KEY = "@ship";
12340
12425
  var shipSandboxRef = () => ({ name: SHIP_SANDBOX_KEY, decl: { packages: [], setup: [] } });
12341
- var sandboxStatePath = (stateDir) => join29(stateDir, "sandbox-images.json");
12426
+ var sandboxStatePath = (stateDir) => join30(stateDir, "sandbox-images.json");
12342
12427
  function readSandboxState(stateDir) {
12343
12428
  try {
12344
12429
  const v = JSON.parse(readFileSync27(sandboxStatePath(stateDir), "utf8"));
@@ -12410,7 +12495,7 @@ var engineRemoveImage = (engine = "docker", exec = realExec) => (tag) => {
12410
12495
  } catch {
12411
12496
  }
12412
12497
  };
12413
- var sandboxLogDir = (stateDir) => join29(stateDir, "sandbox-logs");
12498
+ var sandboxLogDir = (stateDir) => join30(stateDir, "sandbox-logs");
12414
12499
  async function buildSandboxImage(plan, deps) {
12415
12500
  const now = deps.now ?? (() => /* @__PURE__ */ new Date());
12416
12501
  const state = readSandboxState(deps.stateDir);
@@ -12420,20 +12505,20 @@ async function buildSandboxImage(plan, deps) {
12420
12505
  }
12421
12506
  const logDir = sandboxLogDir(deps.stateDir);
12422
12507
  mkdirSync20(logDir, { recursive: true });
12423
- const logPath = join29(logDir, `${slug(plan.repo)}-${now().toISOString().replace(/[:.]/g, "-")}.log`);
12508
+ const logPath = join30(logDir, `${slug(plan.repo)}-${now().toISOString().replace(/[:.]/g, "-")}.log`);
12424
12509
  const builtLayers = [];
12425
12510
  for (const layer of plan.layers) {
12426
12511
  if (deps.hasImage(layer.tag)) continue;
12427
- const ctx = join29(tmpdir3(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
12512
+ const ctx = join30(tmpdir3(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
12428
12513
  mkdirSync20(ctx, { recursive: true });
12429
12514
  try {
12430
- writeFileSync21(join29(ctx, "Dockerfile"), layer.dockerfile);
12515
+ writeFileSync21(join30(ctx, "Dockerfile"), layer.dockerfile);
12431
12516
  for (const [name, content] of Object.entries(layer.files)) {
12432
- mkdirSync20(dirname14(join29(ctx, name)), { recursive: true });
12433
- writeFileSync21(join29(ctx, name), content);
12517
+ mkdirSync20(dirname15(join30(ctx, name)), { recursive: true });
12518
+ writeFileSync21(join30(ctx, name), content);
12434
12519
  }
12435
- if (layer.caBundleFile) writeFileSync21(join29(ctx, layer.caBundleFile), (deps.caBundle ?? readHostCaBundle)());
12436
- const code = await deps.run(["build", "--tag", layer.tag, "--file", join29(ctx, "Dockerfile"), ctx], logPath);
12520
+ if (layer.caBundleFile) writeFileSync21(join30(ctx, layer.caBundleFile), (deps.caBundle ?? readHostCaBundle)());
12521
+ const code = await deps.run(["build", "--tag", layer.tag, "--file", join30(ctx, "Dockerfile"), ctx], logPath);
12437
12522
  if (code === BUILD_INTERRUPTED) return { kind: "interrupted", tag: plan.tag };
12438
12523
  if (code !== 0) {
12439
12524
  state[plan.repo] = { ...entry, failure: { tag: plan.tag, at: now().toISOString(), logPath } };
@@ -12552,7 +12637,7 @@ function expandSkillMarkers(text2, lookup2, opts = {}) {
12552
12637
 
12553
12638
  // src/skills.ts
12554
12639
  import { readFileSync as readFileSync30, readdirSync as readdirSync9, existsSync as existsSync28 } from "fs";
12555
- import { join as join31 } from "path";
12640
+ import { join as join32 } from "path";
12556
12641
  import { parse as parseYaml2 } from "yaml";
12557
12642
  import { TablationClient as TablationClient3, StaleWriteError as StaleWriteError3, TablationApiError as TablationApiError2 } from "@tablation/client";
12558
12643
 
@@ -12585,7 +12670,7 @@ function readPersonaFile(path) {
12585
12670
 
12586
12671
  // src/agents.ts
12587
12672
  import { readFileSync as readFileSync29, existsSync as existsSync27 } from "fs";
12588
- import { join as join30 } from "path";
12673
+ import { join as join31 } from "path";
12589
12674
  import { TablationClient as TablationClient2, StaleWriteError as StaleWriteError2, TablationApiError } from "@tablation/client";
12590
12675
  var PERSONA_NAME = {
12591
12676
  dev: "Developer",
@@ -12599,16 +12684,16 @@ var CREW_AGENT_COLUMN = "agent_id";
12599
12684
  var AgentsSyncError = class extends Error {
12600
12685
  };
12601
12686
  function personaDefaultPrompt(promptsDir, role) {
12602
- const briefPath = join30(promptsDir, "personas", `lane-${role}.md`);
12687
+ const briefPath = join31(promptsDir, "personas", `lane-${role}.md`);
12603
12688
  if (!existsSync27(briefPath)) throw new AgentsSyncError(`no brief at ${briefPath}`);
12604
12689
  const brief = readPersonaFile(briefPath).body;
12605
12690
  if (SELF_CONTAINED_ROLES.has(role)) return brief;
12606
- const commonPath = join30(promptsDir, "personas", "common.md");
12691
+ const commonPath = join31(promptsDir, "personas", "common.md");
12607
12692
  if (!existsSync27(commonPath)) return brief;
12608
12693
  return `${readFileSync29(commonPath, "utf8")}${brief}`;
12609
12694
  }
12610
12695
  function personaChatEnabled(promptsDir, role) {
12611
- const briefPath = join30(promptsDir, "personas", `lane-${role}.md`);
12696
+ const briefPath = join31(promptsDir, "personas", `lane-${role}.md`);
12612
12697
  return existsSync27(briefPath) ? readPersonaFile(briefPath).chatEnabled : void 0;
12613
12698
  }
12614
12699
  async function resolveAgentId(route2, role, opts) {
@@ -13106,9 +13191,9 @@ function parseSkillFile(path) {
13106
13191
  };
13107
13192
  }
13108
13193
  function listLocalSkills(promptsDir) {
13109
- const dir = join31(promptsDir, "skills");
13194
+ const dir = join32(promptsDir, "skills");
13110
13195
  if (!existsSync28(dir)) return [];
13111
- return readdirSync9(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(join31(dir, f)));
13196
+ return readdirSync9(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(join32(dir, f)));
13112
13197
  }
13113
13198
  function personaColumn(model) {
13114
13199
  for (const c of ["persona_id", "persona"]) if (model.fields?.some((f) => f.columnName === c)) return c;
@@ -13345,7 +13430,7 @@ import { spawn as spawn5, execFile, execFileSync as execFileSync9 } from "child_
13345
13430
  import { mkdtempSync, mkdirSync as mkdirSync21, writeFileSync as writeFileSync22, rmSync as rmSync17 } from "fs";
13346
13431
  import { createHash as createHash5 } from "crypto";
13347
13432
  import { tmpdir as tmpdir4 } from "os";
13348
- import { basename as basename8, dirname as dirname15, join as join32 } from "path";
13433
+ import { basename as basename8, dirname as dirname16, join as join33 } from "path";
13349
13434
  import { promisify } from "util";
13350
13435
 
13351
13436
  // src/run-limit.ts
@@ -13496,7 +13581,7 @@ var SandboxRunner = class {
13496
13581
  throw new Error(`cannot generate the sandbox policy: ${e.message}`);
13497
13582
  }
13498
13583
  policyFile = policyPathFor(plan.streamPath);
13499
- mkdirSync21(dirname15(policyFile), { recursive: true });
13584
+ mkdirSync21(dirname16(policyFile), { recursive: true });
13500
13585
  writeFileSync22(policyFile, generated.yaml, { mode: 384 });
13501
13586
  }
13502
13587
  const create2 = ["sandbox", "create", "--name", name, "--detach"];
@@ -13546,9 +13631,9 @@ var SandboxRunner = class {
13546
13631
  const harness = cfg.agentBin ?? basename8(plan.bin);
13547
13632
  const viaUpload = Buffer.byteLength(plan.prompt) > SANDBOX_STDIN_LIMIT;
13548
13633
  if (viaUpload) {
13549
- const tmp = mkdtempSync(join32(tmpdir4(), "crew-prompt-"));
13634
+ const tmp = mkdtempSync(join33(tmpdir4(), "crew-prompt-"));
13550
13635
  try {
13551
- const file = join32(tmp, "prompt.txt");
13636
+ const file = join33(tmp, "prompt.txt");
13552
13637
  writeFileSync22(file, plan.prompt, { mode: 384 });
13553
13638
  await this.os(["sandbox", "upload", name, file, SANDBOX_PROMPT_PATH]);
13554
13639
  } finally {
@@ -13770,7 +13855,7 @@ function streamShowsAllowanceRefusal(streamPath) {
13770
13855
  }
13771
13856
  return false;
13772
13857
  }
13773
- var digestPathFor = (stateDir, routeLabel, role, runId) => join33(stateDir, `digest-${routeLabel}-${role}${runId ? `-${runId}` : ""}.md`);
13858
+ var digestPathFor = (stateDir, routeLabel, role, runId) => join34(stateDir, `digest-${routeLabel}-${role}${runId ? `-${runId}` : ""}.md`);
13774
13859
  function codeBridgeFor(o, harness) {
13775
13860
  if (!o.ticket) return void 0;
13776
13861
  const number = /(\d+)$/.exec(o.ticket)?.[1];
@@ -13798,7 +13883,7 @@ function codeBridgeFor(o, harness) {
13798
13883
  "--clone",
13799
13884
  o.ship.sandbox?.workDir ?? DEFAULT_SANDBOX_WORKDIR,
13800
13885
  "--state-dir",
13801
- dirname16(SANDBOX_INTEL_DIR),
13886
+ dirname17(SANDBOX_INTEL_DIR),
13802
13887
  "--ticket",
13803
13888
  number,
13804
13889
  ...seed ? ["--seed-cache", seed] : []
@@ -13811,8 +13896,8 @@ function codeBridgeFor(o, harness) {
13811
13896
  bridge.settingsFile = `${SANDBOX_INTEL_DIR}/gemini-settings.json`;
13812
13897
  bridge.files = [{ path: bridge.settingsFile, content: text2 }];
13813
13898
  } else {
13814
- const file = join33(intelDir(o.stateDir, o.route.route, number), "gemini-settings.json");
13815
- mkdirSync22(dirname16(file), { recursive: true });
13899
+ const file = join34(intelDir(o.stateDir, o.route.route, number), "gemini-settings.json");
13900
+ mkdirSync22(dirname17(file), { recursive: true });
13816
13901
  writeFileSync23(file, text2);
13817
13902
  bridge.settingsFile = file;
13818
13903
  }
@@ -13820,11 +13905,11 @@ function codeBridgeFor(o, harness) {
13820
13905
  return bridge;
13821
13906
  }
13822
13907
  function planAgentRun(o) {
13823
- const briefPath = join33(o.route.promptsDir, "personas", `lane-${o.role}.md`);
13908
+ const briefPath = join34(o.route.promptsDir, "personas", `lane-${o.role}.md`);
13824
13909
  if (!existsSync29(briefPath)) {
13825
13910
  throw new AgentError(`no brief at ${briefPath} \u2014 refusing to run an unscoped session`);
13826
13911
  }
13827
- const commonPath = join33(o.route.promptsDir, "personas", "common.md");
13912
+ const commonPath = join34(o.route.promptsDir, "personas", "common.md");
13828
13913
  const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) && existsSync29(commonPath);
13829
13914
  const now = o.now ?? (() => Date.now());
13830
13915
  const routeLabel = routeSlug(o.route.route);
@@ -13860,7 +13945,7 @@ function planAgentRun(o) {
13860
13945
  digest
13861
13946
  });
13862
13947
  const promptSha = createHash6("sha256").update(expanded.text).digest("hex");
13863
- const streamsDir = join33(o.stateDir, "streams");
13948
+ const streamsDir = join34(o.stateDir, "streams");
13864
13949
  const base = `${routeLabel}-${o.role}-${o.cycle}${o.runId ? `-${o.runId}` : ""}`;
13865
13950
  const seat = resolveSeat(o.ship, o.route, o.role, o.agentPersona ?? (o.agentModel ? { model: o.agentModel } : {}), o.repo);
13866
13951
  const { model } = seat;
@@ -13971,8 +14056,8 @@ function planAgentRun(o) {
13971
14056
  digestAttached: digest !== void 0,
13972
14057
  digestAgeSeconds: ageSeconds,
13973
14058
  model,
13974
- streamPath: join33(streamsDir, `${base}.jsonl`),
13975
- eventsPath: join33(streamsDir, `${base}.events.jsonl`),
14059
+ streamPath: join34(streamsDir, `${base}.jsonl`),
14060
+ eventsPath: join34(streamsDir, `${base}.events.jsonl`),
13976
14061
  ticket: o.ticket,
13977
14062
  ticketRecordId: o.ticketRecordId ?? null,
13978
14063
  repo: o.repo ?? null,
@@ -14060,7 +14145,7 @@ async function killForDeadline(kill, pid, emit, role, ticket, spawnedAt, limitMi
14060
14145
  var withoutKey = ({ apiKey: _apiKey, ...rest }) => rest;
14061
14146
  function openSink(path) {
14062
14147
  try {
14063
- mkdirSync22(dirname16(path), { recursive: true });
14148
+ mkdirSync22(dirname17(path), { recursive: true });
14064
14149
  return createWriteStream(path, { flags: "a" });
14065
14150
  } catch {
14066
14151
  return void 0;
@@ -14499,7 +14584,7 @@ function spawnPlanned(plan, emit, hintMoved) {
14499
14584
  const id = identityOf(plan, adapter.harness);
14500
14585
  let streamFd;
14501
14586
  try {
14502
- mkdirSync22(dirname16(plan.streamPath), { recursive: true });
14587
+ mkdirSync22(dirname17(plan.streamPath), { recursive: true });
14503
14588
  streamFd = openSync4(plan.streamPath, "a");
14504
14589
  } catch (e) {
14505
14590
  void endSink(eventsSink);
@@ -14764,13 +14849,13 @@ function runFinished(streamPath) {
14764
14849
  }
14765
14850
  }
14766
14851
  function orphanedStreams(o) {
14767
- const dir = join34(o.stateDir, "streams");
14852
+ const dir = join35(o.stateDir, "streams");
14768
14853
  if (!existsSync30(dir)) return [];
14769
14854
  const ownerAlive = o.isOwnerAlive ?? pidAlive;
14770
14855
  const out = [];
14771
14856
  for (const name of readdirSync10(dir)) {
14772
14857
  if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
14773
- const streamPath = join34(dir, name);
14858
+ const streamPath = join35(dir, name);
14774
14859
  if (runFinished(streamPath)) continue;
14775
14860
  const sidecar = readRunSidecar(streamPath);
14776
14861
  if (!sidecar || sidecar.route !== o.routeLabel) continue;
@@ -14824,11 +14909,11 @@ async function reconcileRuns(o) {
14824
14909
 
14825
14910
  // src/live-runs.ts
14826
14911
  import { existsSync as existsSync32, readdirSync as readdirSync12, statSync as statSync11 } from "fs";
14827
- import { join as join36 } from "path";
14912
+ import { join as join37 } from "path";
14828
14913
 
14829
14914
  // src/run-snapshot.ts
14830
14915
  import { closeSync as closeSync5, existsSync as existsSync31, fstatSync, openSync as openSync5, readSync as readSync2, readdirSync as readdirSync11, statSync as statSync10, readFileSync as readFileSync33, writeFileSync as writeFileSync24, renameSync as renameSync6 } from "fs";
14831
- import { join as join35 } from "path";
14916
+ import { join as join36 } from "path";
14832
14917
  var TAIL_BYTES = 256 * 1024;
14833
14918
  var EXCERPT_CHARS = 280;
14834
14919
  function endsWithQuestion(text2) {
@@ -14882,12 +14967,12 @@ function outcomeOf(m) {
14882
14967
  return m.exitCode === void 0 || m.exitCode === null || m.exitCode === 0 ? "ok" : "failed";
14883
14968
  }
14884
14969
  function lastRunsBySeat(stateDir) {
14885
- const dir = join35(stateDir, "streams");
14970
+ const dir = join36(stateDir, "streams");
14886
14971
  const out = /* @__PURE__ */ new Map();
14887
14972
  if (!existsSync31(dir)) return out;
14888
14973
  for (const name of readdirSync11(dir)) {
14889
14974
  if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
14890
- const streamPath = join35(dir, name);
14975
+ const streamPath = join36(dir, name);
14891
14976
  if (!runFinished(streamPath)) continue;
14892
14977
  const metaPath = `${streamPath}.meta.json`;
14893
14978
  let meta;
@@ -14936,12 +15021,12 @@ function appendRunNote(streamPath, note) {
14936
15021
 
14937
15022
  // src/live-runs.ts
14938
15023
  function liveRuns(stateDir, isAlive = runIsAlive) {
14939
- const dir = join36(stateDir, "streams");
15024
+ const dir = join37(stateDir, "streams");
14940
15025
  if (!existsSync32(dir)) return [];
14941
15026
  const out = [];
14942
15027
  for (const name of readdirSync12(dir)) {
14943
15028
  if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
14944
- const streamPath = join36(dir, name);
15029
+ const streamPath = join37(dir, name);
14945
15030
  if (runFinished(streamPath)) continue;
14946
15031
  const sidecar = readRunSidecar(streamPath);
14947
15032
  if (!sidecar || !isAlive(sidecar)) continue;
@@ -14951,12 +15036,12 @@ function liveRuns(stateDir, isAlive = runIsAlive) {
14951
15036
  }
14952
15037
  function runActivity(stateDir, isAlive = runIsAlive) {
14953
15038
  const activeRuns = liveRuns(stateDir, isAlive).length;
14954
- const dir = join36(stateDir, "streams");
15039
+ const dir = join37(stateDir, "streams");
14955
15040
  let newest = 0;
14956
15041
  if (existsSync32(dir)) {
14957
15042
  for (const name of readdirSync12(dir)) {
14958
15043
  if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
14959
- const streamPath = join36(dir, name);
15044
+ const streamPath = join37(dir, name);
14960
15045
  if (!runFinished(streamPath)) continue;
14961
15046
  try {
14962
15047
  newest = Math.max(newest, statSync11(`${streamPath}.meta.json`).mtimeMs);
@@ -15969,7 +16054,7 @@ function managedGitIdentityWarnings(kind, identity) {
15969
16054
  import { spawn as spawn7 } from "child_process";
15970
16055
  import { existsSync as existsSync34, mkdirSync as mkdirSync23, mkdtempSync as mkdtempSync2, readFileSync as readFileSync34, rmSync as rmSync18, writeFileSync as writeFileSync25 } from "fs";
15971
16056
  import { tmpdir as tmpdir5 } from "os";
15972
- import { join as join37 } from "path";
16057
+ import { join as join38 } from "path";
15973
16058
  var SELFTEST_TIMEOUT_MS = 12e4;
15974
16059
  var KEY_VAR = "CREW_API_KEY";
15975
16060
  var SELFTEST_PROMPT = "This is a read-only connectivity check. Use the tracker MCP tool to read this workspace (the workspaces find-one tool, using the workspace id below) and reply with the workspace's name alone, on one line. Do not write anything, do not create files, and do not use any other tool.\n\nWorkspace id: ";
@@ -16135,7 +16220,7 @@ async function runSelftest(i, deps = realDeps) {
16135
16220
  ...adapter.runEnv(spec),
16136
16221
  [KEY_VAR]: i.apiKey
16137
16222
  };
16138
- const cwd = mkdtempSync2(join37(tmpdir5(), "crew-selftest-"));
16223
+ const cwd = mkdtempSync2(join38(tmpdir5(), "crew-selftest-"));
16139
16224
  try {
16140
16225
  const run4 = await deps.run({
16141
16226
  bin: invocation.bin,
@@ -16168,7 +16253,7 @@ function formatResult(r) {
16168
16253
  const secs = `${(r.ms / 1e3).toFixed(1)}s`;
16169
16254
  return r.ok ? `${r.toolchain}: PASS ${r.detail} (${secs}${tok})` : `${r.toolchain}: FAIL ${r.failure} \u2014 ${r.detail} (${secs})`;
16170
16255
  }
16171
- var fileFor3 = (stateDir) => join37(stateDir, "selftest.json");
16256
+ var fileFor3 = (stateDir) => join38(stateDir, "selftest.json");
16172
16257
  function readSelftest(stateDir) {
16173
16258
  try {
16174
16259
  const p = fileFor3(stateDir);
@@ -16243,7 +16328,7 @@ async function runSelfLaunchCheck(own, spawnFn = spawnChild, launch = selfLaunch
16243
16328
  }
16244
16329
 
16245
16330
  // src/cli.ts
16246
- import { resolve as resolve7, dirname as dirname37, join as join65, basename as basename17 } from "path";
16331
+ import { resolve as resolve7, dirname as dirname38, join as join66, basename as basename17 } from "path";
16247
16332
  import { fileURLToPath as fileURLToPath2 } from "url";
16248
16333
  import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
16249
16334
  import { spawnSync as spawnSync14 } from "child_process";
@@ -16455,9 +16540,9 @@ function rosterMarkdown(roster, meId) {
16455
16540
 
16456
16541
  // src/connect-resume.ts
16457
16542
  import { mkdirSync as mkdirSync24, readFileSync as readFileSync35, rmSync as rmSync19, writeFileSync as writeFileSync26 } from "fs";
16458
- import { dirname as dirname17, join as join38 } from "path";
16543
+ import { dirname as dirname18, join as join39 } from "path";
16459
16544
  function lastSessionFile(stateDir) {
16460
- return join38(stateDir, "connect-session.json");
16545
+ return join39(stateDir, "connect-session.json");
16461
16546
  }
16462
16547
  function readPointers(stateDir) {
16463
16548
  try {
@@ -16475,7 +16560,7 @@ function readPointers(stateDir) {
16475
16560
  }
16476
16561
  function writePointers(stateDir, pointers) {
16477
16562
  const file = lastSessionFile(stateDir);
16478
- mkdirSync24(dirname17(file), { recursive: true });
16563
+ mkdirSync24(dirname18(file), { recursive: true });
16479
16564
  writeFileSync26(file, `${JSON.stringify(pointers, null, 2)}
16480
16565
  `, { mode: 384 });
16481
16566
  }
@@ -16562,10 +16647,10 @@ async function signOutSessions(o) {
16562
16647
 
16563
16648
  // src/reset.ts
16564
16649
  import { existsSync as existsSync35, mkdirSync as mkdirSync25, readFileSync as readFileSync36, readdirSync as readdirSync14, rmSync as rmSync20, statSync as statSync12, writeFileSync as writeFileSync27 } from "fs";
16565
- import { dirname as dirname18, join as join39 } from "path";
16650
+ import { dirname as dirname19, join as join40 } from "path";
16566
16651
  import { hostFromUrl as hostFromUrl3 } from "@tablation/client";
16567
16652
  function clonedCheckoutsFile(stateDir) {
16568
- return join39(stateDir, "cloned-checkouts.json");
16653
+ return join40(stateDir, "cloned-checkouts.json");
16569
16654
  }
16570
16655
  function readClonedCheckouts(stateDir) {
16571
16656
  try {
@@ -16579,7 +16664,7 @@ function recordClonedCheckout(stateDir, dir) {
16579
16664
  const known = readClonedCheckouts(stateDir);
16580
16665
  if (known.includes(dir)) return;
16581
16666
  const file = clonedCheckoutsFile(stateDir);
16582
- mkdirSync25(dirname18(file), { recursive: true });
16667
+ mkdirSync25(dirname19(file), { recursive: true });
16583
16668
  writeFileSync27(file, `${JSON.stringify([...known, dir], null, 2)}
16584
16669
  `);
16585
16670
  }
@@ -16656,10 +16741,10 @@ function removeCheckout(dir, dryRun, fx) {
16656
16741
  }
16657
16742
  function removeState(stateDir, dryRun) {
16658
16743
  const out = [];
16659
- const targets = [join39(stateDir, "resolved"), join39(stateDir, "keys"), clonedCheckoutsFile(stateDir), join39(stateDir, "connect-session.json"), join39(stateDir, "reload-requested"), join39(stateDir, "daemon.started")];
16744
+ const targets = [join40(stateDir, "resolved"), join40(stateDir, "keys"), clonedCheckoutsFile(stateDir), join40(stateDir, "connect-session.json"), join40(stateDir, "reload-requested"), join40(stateDir, "daemon.started")];
16660
16745
  try {
16661
16746
  for (const name of readdirSync14(stateDir)) {
16662
- if (name.startsWith(".") && statSync12(join39(stateDir, name)).isFile()) targets.push(join39(stateDir, name));
16747
+ if (name.startsWith(".") && statSync12(join40(stateDir, name)).isFile()) targets.push(join40(stateDir, name));
16663
16748
  }
16664
16749
  } catch {
16665
16750
  }
@@ -16679,7 +16764,7 @@ function wipeStateDir(stateDir, dryRun) {
16679
16764
  return [{ step: "state", target: stateDir, action: "absent", detail: "no state directory" }];
16680
16765
  }
16681
16766
  if (!names.length) return [{ step: "state", target: stateDir, action: "absent", detail: "already empty" }];
16682
- if (!dryRun) for (const n of names) rmSync20(join39(stateDir, n), { recursive: true, force: true });
16767
+ if (!dryRun) for (const n of names) rmSync20(join40(stateDir, n), { recursive: true, force: true });
16683
16768
  return [{ step: "state", target: stateDir, action: mark(dryRun), detail: `${names.length} entr${names.length === 1 ? "y" : "ies"}` }];
16684
16769
  }
16685
16770
  function describeResetStep(s) {
@@ -16763,7 +16848,7 @@ async function runDeprovision(o, fx, deps) {
16763
16848
  // src/pool-member.ts
16764
16849
  import { mkdirSync as mkdirSync26, readFileSync as readFileSync37, renameSync as renameSync7, writeFileSync as writeFileSync28 } from "fs";
16765
16850
  import { homedir as homedir8 } from "os";
16766
- import { dirname as dirname19, join as join40 } from "path";
16851
+ import { dirname as dirname20, join as join41 } from "path";
16767
16852
  var POOL_EXIT = { ok: 0, failed: 1, credential: 2 };
16768
16853
  function backoffMs(attempt) {
16769
16854
  return Math.min(6e4, 5e3 * 2 ** Math.max(0, attempt));
@@ -17005,10 +17090,10 @@ async function runPoolMember(deps) {
17005
17090
  }
17006
17091
  }
17007
17092
  function defaultMemberDir(env = process.env) {
17008
- return env.CREW_POOL_DIR ?? join40(env.XDG_STATE_HOME ?? join40(homedir8(), ".local", "state"), "crew-pool-member");
17093
+ return env.CREW_POOL_DIR ?? join41(env.XDG_STATE_HOME ?? join41(homedir8(), ".local", "state"), "crew-pool-member");
17009
17094
  }
17010
17095
  function fileMemberStore(dir) {
17011
- const file = join40(dir, "member.json");
17096
+ const file = join41(dir, "member.json");
17012
17097
  return {
17013
17098
  read() {
17014
17099
  try {
@@ -17018,7 +17103,7 @@ function fileMemberStore(dir) {
17018
17103
  }
17019
17104
  },
17020
17105
  write(f) {
17021
- mkdirSync26(dirname19(file), { recursive: true, mode: 448 });
17106
+ mkdirSync26(dirname20(file), { recursive: true, mode: 448 });
17022
17107
  const tmp = `${file}.tmp`;
17023
17108
  writeFileSync28(tmp, `${JSON.stringify(f)}
17024
17109
  `, { mode: 384 });
@@ -17079,9 +17164,9 @@ import { hostname as hostname3 } from "os";
17079
17164
  import { execFileSync as execFileSync12 } from "child_process";
17080
17165
  import { createHash as createHash8 } from "crypto";
17081
17166
  import { existsSync as existsSync36, mkdirSync as mkdirSync27, readFileSync as readFileSync38, writeFileSync as writeFileSync29 } from "fs";
17082
- import { dirname as dirname20, join as join41 } from "path";
17167
+ import { dirname as dirname21, join as join42 } from "path";
17083
17168
  function machineIdPathFor(stateDir) {
17084
- return join41(stateDir, "machine-id");
17169
+ return join42(stateDir, "machine-id");
17085
17170
  }
17086
17171
  var sha256 = (s) => createHash8("sha256").update(s).digest("hex");
17087
17172
  function readRawMachineId(platform2 = process.platform) {
@@ -17113,7 +17198,7 @@ function ensureMachineId(stateDir, opts = {}) {
17113
17198
  const raw = (opts.read ?? readRawMachineId)();
17114
17199
  if (!raw) return void 0;
17115
17200
  const hashed = sha256(raw);
17116
- mkdirSync27(dirname20(path), { recursive: true });
17201
+ mkdirSync27(dirname21(path), { recursive: true });
17117
17202
  writeFileSync29(path, `${hashed}
17118
17203
  `, { mode: 384 });
17119
17204
  return hashed;
@@ -17136,7 +17221,7 @@ import { parseDocument as parseDocument2 } from "yaml";
17136
17221
 
17137
17222
  // src/repos-cmd.ts
17138
17223
  import { homedir as homedir9 } from "os";
17139
- import { basename as basename10, join as join42, resolve as resolve4 } from "path";
17224
+ import { basename as basename10, join as join43, resolve as resolve4 } from "path";
17140
17225
  import { isMap, isSeq, parseDocument, stringify as stringify2 } from "yaml";
17141
17226
  var ReposError = class extends Error {
17142
17227
  /** A stable reason for a `--json` reader, when the failure has one (CREW-3359). */
@@ -17427,7 +17512,7 @@ function planRepoClone(i) {
17427
17512
  }
17428
17513
  const ship = doc.get("ship", true);
17429
17514
  const basePath = String(m.get("reposBasePath") ?? (isMap(ship) ? ship.get("reposBasePath") : void 0) ?? "~/Crew");
17430
- const target = i.dir ? expandDir(i.dir, i.base) : join42(expandDir(basePath, i.base), i.route.split("/")[0], name);
17515
+ const target = i.dir ? expandDir(i.dir, i.base) : join43(expandDir(basePath, i.base), i.route.split("/")[0], name);
17431
17516
  const add = planRepoAdd({ text: i.text, base: i.base, route: i.route, path: target, origin: remote, resolved: i.resolved, name, isCheckout: i.isCheckout });
17432
17517
  const forgeHost = i.resolved?.repoForgeHosts?.[id];
17433
17518
  return { ...add, remote, target, ...forgeHost ? { forgeHost } : {} };
@@ -18993,7 +19078,7 @@ function diskFullStop(state) {
18993
19078
 
18994
19079
  // src/poll.ts
18995
19080
  import { writeFileSync as writeFileSync31 } from "fs";
18996
- import { join as join43 } from "path";
19081
+ import { join as join44 } from "path";
18997
19082
 
18998
19083
  // src/stalled.ts
18999
19084
  var STALLED_AFTER_CYCLES = 30;
@@ -19310,7 +19395,7 @@ async function decideCycle(o) {
19310
19395
  }
19311
19396
  return decision;
19312
19397
  }
19313
- var digestPath = (stateDir, route2, role, runId) => join43(stateDir, `digest-${route2}-${role}${runId ? `-${runId}` : ""}.md`);
19398
+ var digestPath = (stateDir, route2, role, runId) => join44(stateDir, `digest-${route2}-${role}${runId ? `-${runId}` : ""}.md`);
19314
19399
  function otherRunsRemoved(tickets, own) {
19315
19400
  if (!own) return tickets;
19316
19401
  return tickets.filter((t) => t.id === own.ticket.id || !own.inFlight(t.id));
@@ -19541,7 +19626,7 @@ async function markCrewAssistedAtLaunch(tracker, route2, role, ticketId, ticket,
19541
19626
 
19542
19627
  // src/repo-refresh.ts
19543
19628
  import { existsSync as existsSync40, mkdirSync as mkdirSync28, readFileSync as readFileSync40, writeFileSync as writeFileSync32 } from "fs";
19544
- import { dirname as dirname22 } from "path";
19629
+ import { dirname as dirname23 } from "path";
19545
19630
  var REFRESH_COOLDOWN_MS = 2 * 6e4;
19546
19631
  var UNSERVABLE_PASSES_BEFORE_ATTENTION = 3;
19547
19632
  var lastAsked = /* @__PURE__ */ new Map();
@@ -19573,7 +19658,7 @@ function persistRepoRows(stateDir, routeName, rows) {
19573
19658
  if (!existsSync40(path)) return;
19574
19659
  const raw = JSON.parse(readFileSync40(path, "utf8"));
19575
19660
  applyRepoRows(raw, rows);
19576
- mkdirSync28(dirname22(path), { recursive: true });
19661
+ mkdirSync28(dirname23(path), { recursive: true });
19577
19662
  writeFileSync32(path, `${JSON.stringify(raw, null, 2)}
19578
19663
  `);
19579
19664
  }
@@ -19964,14 +20049,39 @@ async function applyBuildFailureBounce(writer, b, contract, memberId, log, dryRu
19964
20049
 
19965
20050
  // src/stranded-verified.ts
19966
20051
  var STRANDED_MARKER = calloutHeader("WARNING", "Stranded Verified");
20052
+ function findNearMissBranches(dir, cfg, ticket) {
20053
+ const number = ticket.issue_id.replace(/^\D+/, "");
20054
+ if (!number) return [];
20055
+ const remote = cfg.branch.remote;
20056
+ const prefix = `refs/remotes/${remote}/`;
20057
+ const refs = (gitOk(dir, ["for-each-ref", "--format=%(refname)", prefix]) ?? "").split("\n").filter((r) => r.startsWith(prefix) && r !== `${prefix}HEAD`).map((r) => r.slice(prefix.length)).filter((b) => b !== cfg.branch.base && new RegExp(`(^|\\D)${number}(\\D|$)`).test(b));
20058
+ const keys = [...new Set([ticket.issue_id, ticket.issue_tag].filter((k) => !!k))];
20059
+ const keyRe = keys.map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
20060
+ const out = [];
20061
+ for (const b of refs) {
20062
+ const log = gitOk(dir, ["log", "--format=%H", "-E", "-i", `--grep=(^|[^0-9A-Za-z])(${keyRe})([^0-9]|$)`, `${remote}/${cfg.branch.base}..${prefix}${b}`]);
20063
+ const commits = log ? log.split("\n").filter(Boolean).length : 0;
20064
+ if (commits > 0) out.push({ branch: b, commits });
20065
+ }
20066
+ return out;
20067
+ }
20068
+ function nearMissText(s) {
20069
+ if (!s.nearMisses?.length) return "";
20070
+ const list = s.nearMisses.map((n) => `\`${s.remote}/${n.branch}\` (${n.commits} commit${n.commits === 1 ? "" : "s"} naming the key)`).join(", ");
20071
+ return `
20072
+
20073
+ **A branch under another name looks like this ticket's work:** ${list}. The crew expected \`${s.expectedBranch ?? "the contract branch name"}\`. It was most likely built on a misnamed branch; pushing it under the expected name, or renaming it, lets the release merge it.`;
20074
+ }
19967
20075
  var STRANDED_ESCALATE_AFTER_MS = 30 * 60 * 1e3;
19968
20076
  var priorStrandedFlags = (ticket, events) => events.filter((e) => e.record_id === ticket.id && e.event_type === "stranded_flagged").length;
19969
- function planStrandedVerified(candidate, base, remote, events) {
20077
+ function planStrandedVerified(candidate, base, remote, events, look) {
19970
20078
  const stamps = events.filter((e) => e.record_id === candidate.ticket.id && e.event_type === "stranded_flagged").map((e) => Date.parse(e.occurred_at ?? e.created_at ?? "")).filter((n) => !Number.isNaN(n));
20079
+ const nearMisses = look ? findNearMissBranches(look.dir, look.cfg, candidate.ticket) : [];
19971
20080
  return {
19972
20081
  candidate,
19973
20082
  base,
19974
20083
  remote,
20084
+ ...nearMisses.length && look ? { nearMisses, expectedBranch: branchCandidatesForTicket(look.cfg, candidate.ticket).find((c) => !c.endsWith("*")) } : {},
19975
20085
  priorFlags: priorStrandedFlags(candidate.ticket, events),
19976
20086
  lastFlaggedAt: stamps.length ? Math.max(...stamps) : void 0
19977
20087
  };
@@ -19984,7 +20094,7 @@ function flagComment(s) {
19984
20094
 
19985
20095
  \`${key}\` is \`verified\` with no branch on this ship, and its key names no commit anywhere in this ship's \`${s.base}\` history (searched all of it, local commits included, for a bounded \`${key}\` in a commit subject or body). One of three things is true: it landed under a commit that never named the key, the branch was deleted before it merged, or it was verified in error \u2014 the crew cannot tell these apart and will not guess.
19986
20096
 
19987
- If it is still unplaceable next cycle, this ticket is escalated to a person. If the work already landed, closing this ticket by hand now avoids that.`;
20097
+ If it is still unplaceable next cycle, this ticket is escalated to a person. If the work already landed, closing this ticket by hand now avoids that.${nearMissText(s)}`;
19988
20098
  }
19989
20099
  function escalateComment2(s) {
19990
20100
  const key = s.candidate.ticket.issue_id;
@@ -19994,7 +20104,7 @@ function escalateComment2(s) {
19994
20104
 
19995
20105
  \`${key}\` was flagged as stranded at \`verified\` on an earlier cycle and still has no branch on this ship or on \`${s.remote}\` and no commit in this ship's \`${s.base}\` history naming its key (searched all of it, local commits included). This needs a person: either the work landed under a commit that doesn't name the key and this ticket can simply close, or the branch is gone and the work needs redoing.
19996
20106
 
19997
- The crew will not close this on its own.`;
20107
+ The crew will not close this on its own.${nearMissText(s)}`;
19998
20108
  }
19999
20109
  async function applyStrandedVerified(writer, s, contract, operatorId, memberId, log, dryRun, now = Date.now()) {
20000
20110
  const t = { ticket: s.candidate.ticket.issue_id, step: "merge" };
@@ -20050,7 +20160,7 @@ Ship ${shipName2} found: ${problem}. The release refuses to squash a ref nobody
20050
20160
  var localRefSkipReported = (ticket, problem, events) => events.some((e) => e.record_id === ticket.id && e.event_type === "local_ref_skip" && (e.message ?? "").includes(problem));
20051
20161
 
20052
20162
  // src/platform-gate.ts
20053
- import { join as join44 } from "path";
20163
+ import { join as join45 } from "path";
20054
20164
  function platformAdmitters(dir, baseRef, ship, tickets, locate) {
20055
20165
  const out = [];
20056
20166
  for (const t of tickets) {
@@ -20062,7 +20172,7 @@ function platformAdmitters(dir, baseRef, ship, tickets, locate) {
20062
20172
  const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
20063
20173
  if (text2 === null) continue;
20064
20174
  try {
20065
- const { platform: platform2 } = parseRepoConfig(text2, join44(dir, file));
20175
+ const { platform: platform2 } = parseRepoConfig(text2, join45(dir, file));
20066
20176
  if (satisfies(ship, platform2)) out.push({ issueId: t.issue_id, branch, platform: platform2 });
20067
20177
  } catch (e) {
20068
20178
  if (e instanceof RepoConfigError) continue;
@@ -20078,7 +20188,7 @@ function platformStuckNote(repo, required, ship, issueIds) {
20078
20188
  }
20079
20189
 
20080
20190
  // src/connect-wizard.ts
20081
- import { delimiter, dirname as dirname23, join as join45 } from "path";
20191
+ import { delimiter, dirname as dirname24, join as join46 } from "path";
20082
20192
  import { accessSync as accessSync3, constants as constants3, existsSync as existsSync41, mkdirSync as mkdirSync29, writeFileSync as writeFileSync33 } from "fs";
20083
20193
  import { stringify as stringify3 } from "yaml";
20084
20194
  var HOST_PASSENGERS_DOCS_URL = "https://crew.tablation.dev/host-passengers";
@@ -20101,7 +20211,7 @@ function defaultIsExecutable(p) {
20101
20211
  function findOnPath2(name, pathEnv, isExecutable = defaultIsExecutable) {
20102
20212
  for (const dir of pathEnv.split(delimiter)) {
20103
20213
  if (!dir) continue;
20104
- const candidate = join45(dir, name);
20214
+ const candidate = join46(dir, name);
20105
20215
  if (isExecutable(candidate)) return candidate;
20106
20216
  }
20107
20217
  return void 0;
@@ -20127,9 +20237,9 @@ async function runWizard(p, env) {
20127
20237
  if (entered && isExec(entered)) agentBin = entered;
20128
20238
  else p.say(entered ? `${entered} is not an executable file.` : "A path is required.");
20129
20239
  }
20130
- const nodeDir = dirname23(env.nodePath);
20240
+ const nodeDir = dirname24(env.nodePath);
20131
20241
  const pnpmPath = findOnPath2("pnpm", env.pathEnv, isExec);
20132
- const baseDirs = [nodeDir, pnpmPath ? dirname23(pnpmPath) : void 0];
20242
+ const baseDirs = [nodeDir, pnpmPath ? dirname24(pnpmPath) : void 0];
20133
20243
  p.say(
20134
20244
  `
20135
20245
  Host Passengers lets this machine run the agent sessions that other people's
@@ -20140,7 +20250,7 @@ Tablation workspaces ask for, in a container. More: ${HOST_PASSENGERS_DOCS_URL}`
20140
20250
  p.say("Docker is not available here, so nothing will be hosted until it is. Your answer is recorded anyway.");
20141
20251
  }
20142
20252
  const dockerPath = hostPassengers ? findOnPath2("docker", env.pathEnv, isExec) : void 0;
20143
- const extraPath = deriveExtraPath([...baseDirs, dockerPath ? dirname23(dockerPath) : void 0]);
20253
+ const extraPath = deriveExtraPath([...baseDirs, dockerPath ? dirname24(dockerPath) : void 0]);
20144
20254
  if (extraPath) {
20145
20255
  p.say(`Hooks will get ${extraPath} on their PATH (where node, pnpm${dockerPath ? " and docker" : ""} live).`);
20146
20256
  }
@@ -20162,7 +20272,7 @@ routes:
20162
20272
  ${routeBlock}`;
20163
20273
  }
20164
20274
  function writeNewConfig(path, text2) {
20165
- mkdirSync29(dirname23(path), { recursive: true });
20275
+ mkdirSync29(dirname24(path), { recursive: true });
20166
20276
  try {
20167
20277
  writeFileSync33(path, text2, { mode: 384, flag: "wx" });
20168
20278
  return true;
@@ -20198,7 +20308,7 @@ Wrote ${o.configPath}.
20198
20308
  // src/connect-json.ts
20199
20309
  import { accessSync as accessSync4, constants as constants4 } from "fs";
20200
20310
  import { homedir as homedir10 } from "os";
20201
- import { dirname as dirname24, join as join46 } from "path";
20311
+ import { dirname as dirname25, join as join47 } from "path";
20202
20312
  import { delimiter as delimiter2 } from "path";
20203
20313
  var CHOICE_EXIT_CODE = 3;
20204
20314
  function createEmitter(json2, write) {
@@ -20237,12 +20347,12 @@ function agentBinSearchDirs(home, pathEnv, extraPath) {
20237
20347
  const dirs = [
20238
20348
  ...pathEnv.split(delimiter2),
20239
20349
  ...(extraPath ?? "").split(delimiter2),
20240
- join46(home, ".local/bin"),
20241
- join46(home, ".claude/local"),
20350
+ join47(home, ".local/bin"),
20351
+ join47(home, ".claude/local"),
20242
20352
  "/opt/homebrew/bin",
20243
20353
  "/usr/local/bin",
20244
- join46(home, ".npm-global/bin"),
20245
- join46(home, ".volta/bin")
20354
+ join47(home, ".npm-global/bin"),
20355
+ join47(home, ".volta/bin")
20246
20356
  ];
20247
20357
  return [...new Set(dirs.filter(Boolean))];
20248
20358
  }
@@ -20264,7 +20374,7 @@ function flagWizardAnswers(f, env) {
20264
20374
  const agentBin = f.agentBin ?? found?.bin;
20265
20375
  const pnpmPath = findOnPath2("pnpm", env.pathEnv, isExec);
20266
20376
  const dockerPath = f.hostPassengers ? findOnPath2("docker", env.pathEnv, isExec) : void 0;
20267
- const extraPath = f.extraPath ?? deriveExtraPath([dirname24(env.nodePath), pnpmPath ? dirname24(pnpmPath) : void 0, dockerPath ? dirname24(dockerPath) : void 0]);
20377
+ const extraPath = f.extraPath ?? deriveExtraPath([dirname25(env.nodePath), pnpmPath ? dirname25(pnpmPath) : void 0, dockerPath ? dirname25(dockerPath) : void 0]);
20268
20378
  return {
20269
20379
  answers: {
20270
20380
  name: f.shipName?.trim() || env.hostname,
@@ -20364,7 +20474,7 @@ async function collectDiagnostics(d) {
20364
20474
 
20365
20475
  // src/release-run.ts
20366
20476
  import { readFileSync as readFileSync41, writeFileSync as writeFileSync34, existsSync as existsSync42, copyFileSync, mkdirSync as mkdirSync30, mkdtempSync as mkdtempSync3, rmSync as rmSync21 } from "fs";
20367
- import { dirname as dirname25, join as join47 } from "path";
20477
+ import { dirname as dirname26, join as join48 } from "path";
20368
20478
  import { tmpdir as tmpdir6, hostname as hostname4 } from "os";
20369
20479
 
20370
20480
  // src/release.ts
@@ -21339,7 +21449,7 @@ async function bump(o, size) {
21339
21449
  }
21340
21450
  return printed;
21341
21451
  }
21342
- const files = o.repo.release.versionFiles.map((f) => join47(o.cwd, f));
21452
+ const files = o.repo.release.versionFiles.map((f) => join48(o.cwd, f));
21343
21453
  const first = files[0];
21344
21454
  if (!existsAt(first, existsSync42)) {
21345
21455
  o.emit.error(`no ${o.repo.release.versionFiles[0]} to read a version from`);
@@ -21377,7 +21487,7 @@ async function bump(o, size) {
21377
21487
  function writeChangelog(o, version, entries) {
21378
21488
  const file = o.repo.release.changelog;
21379
21489
  if (!file || entries.length === 0) return;
21380
- const path = join47(o.cwd, file);
21490
+ const path = join48(o.cwd, file);
21381
21491
  const section = renderChangelogSection(version, (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), entries);
21382
21492
  if (o.dryRun) {
21383
21493
  o.emit.emit(`would prepend ${entries.length} entr(ies) to ${file}`);
@@ -21477,8 +21587,8 @@ function closeReleaseCheckout(cwd, root, dir, branch, run4 = gitOk) {
21477
21587
  function openReleaseCheckout(o) {
21478
21588
  const { remote, base } = o.repo.branch;
21479
21589
  const branch = `crew/release-${Date.now()}`;
21480
- const root = mkdtempSync3(join47(tmpdir6(), "crew-release-"));
21481
- const dir = join47(root, "checkout");
21590
+ const root = mkdtempSync3(join48(tmpdir6(), "crew-release-"));
21591
+ const dir = join48(root, "checkout");
21482
21592
  o.emit.note(`release checkout: ${dir}`, { step: "release" });
21483
21593
  const close = () => closeReleaseCheckout(o.cwd, root, dir, branch);
21484
21594
  try {
@@ -21488,10 +21598,10 @@ function openReleaseCheckout(o) {
21488
21598
  throw e;
21489
21599
  }
21490
21600
  for (const f of o.repo.worktrees.copy) {
21491
- const src = join47(o.cwd, f);
21601
+ const src = join48(o.cwd, f);
21492
21602
  if (!existsSync42(src)) continue;
21493
- mkdirSync30(dirname25(join47(dir, f)), { recursive: true });
21494
- copyFileSync(src, join47(dir, f));
21603
+ mkdirSync30(dirname26(join48(dir, f)), { recursive: true });
21604
+ copyFileSync(src, join48(dir, f));
21495
21605
  }
21496
21606
  return { dir, branch, close };
21497
21607
  }
@@ -22318,7 +22428,7 @@ import { existsSync as existsSync49, readFileSync as readFileSync47 } from "fs";
22318
22428
 
22319
22429
  // src/daemon.ts
22320
22430
  import { existsSync as existsSync48, mkdirSync as mkdirSync36, readFileSync as readFileSync46, readdirSync as readdirSync15, rmSync as rmSync23, statSync as statSync14, writeFileSync as writeFileSync38 } from "fs";
22321
- import { join as join52 } from "path";
22431
+ import { join as join53 } from "path";
22322
22432
  import { randomBytes } from "crypto";
22323
22433
 
22324
22434
  // src/outage.ts
@@ -22442,11 +22552,11 @@ function nextRoles(decision, ran) {
22442
22552
 
22443
22553
  // src/noop-runs.ts
22444
22554
  import { existsSync as existsSync43, mkdirSync as mkdirSync31, readFileSync as readFileSync42, renameSync as renameSync8, writeFileSync as writeFileSync35 } from "fs";
22445
- import { join as join48 } from "path";
22555
+ import { join as join49 } from "path";
22446
22556
  var NOOP_DELAYS_MS = [5, 15, 60].map((m) => m * 6e4);
22447
22557
  var DEFAULT_NOOP_REPEATS = 3;
22448
22558
  var NOOP_BOUNCED_MARKER = calloutHeader("WARNING", "Runs Changed Nothing");
22449
- var noopRunsPath = (stateDir) => join48(stateDir, "noop-runs.json");
22559
+ var noopRunsPath = (stateDir) => join49(stateDir, "noop-runs.json");
22450
22560
  var noopRunsKey = (issueId) => `noop_runs:${issueId}`;
22451
22561
  function readNoopRuns(stateDir) {
22452
22562
  try {
@@ -22537,7 +22647,7 @@ async function settleNoopRun(o) {
22537
22647
 
22538
22648
  // src/ship-name.ts
22539
22649
  import { existsSync as existsSync44, mkdirSync as mkdirSync32, readFileSync as readFileSync43, renameSync as renameSync9, writeFileSync as writeFileSync36 } from "fs";
22540
- import { dirname as dirname26 } from "path";
22650
+ import { dirname as dirname27 } from "path";
22541
22651
  import { parseDocument as parseDocument4 } from "yaml";
22542
22652
  var ShipNameError = class extends Error {
22543
22653
  };
@@ -22616,7 +22726,7 @@ function writeSyncedName(resolvedFile, name) {
22616
22726
  }
22617
22727
  if (raw.shipName === name) return;
22618
22728
  raw.shipName = name;
22619
- mkdirSync32(dirname26(resolvedFile), { recursive: true });
22729
+ mkdirSync32(dirname27(resolvedFile), { recursive: true });
22620
22730
  const tmp = `${resolvedFile}.tmp${process.pid}`;
22621
22731
  writeFileSync36(tmp, `${JSON.stringify(raw, null, 2)}
22622
22732
  `);
@@ -22699,7 +22809,7 @@ import { existsSync as existsSync45 } from "fs";
22699
22809
 
22700
22810
  // src/passenger-mirror.ts
22701
22811
  import { mkdirSync as mkdirSync33 } from "fs";
22702
- import { dirname as dirname27 } from "path";
22812
+ import { dirname as dirname28 } from "path";
22703
22813
  function mirrorRepoOf(spec) {
22704
22814
  const fromOrigin = spec.originUrl ? parseRemote(spec.originUrl) : null;
22705
22815
  if (fromOrigin) return fromOrigin;
@@ -22717,7 +22827,7 @@ async function materializeMirrorCheckouts(specs, cacheFor = (s) => new SandboxCa
22717
22827
  continue;
22718
22828
  }
22719
22829
  try {
22720
- const parent = dirname27(spec.dir);
22830
+ const parent = dirname28(spec.dir);
22721
22831
  mkdirSync33(parent, { recursive: true });
22722
22832
  mkdirSync33(spec.dir, { recursive: true });
22723
22833
  const r = await cacheFor(spec).materialize(repo, spec.base, parent, spec.name);
@@ -22818,17 +22928,17 @@ function explainRefusal(readable, unreadable) {
22818
22928
  // src/ssh-keys.ts
22819
22929
  import { execFileSync as execFileSync13 } from "child_process";
22820
22930
  import { existsSync as existsSync46, mkdirSync as mkdirSync34, readFileSync as readFileSync44, chmodSync as chmodSync3 } from "fs";
22821
- import { dirname as dirname28, join as join49 } from "path";
22931
+ import { dirname as dirname29, join as join50 } from "path";
22822
22932
  var SshKeyError = class extends Error {
22823
22933
  };
22824
22934
  function shipSshKeyPathFor(stateDir) {
22825
- return join49(stateDir, "ssh", "id_ed25519");
22935
+ return join50(stateDir, "ssh", "id_ed25519");
22826
22936
  }
22827
22937
  function ensureShipSshKeypair(stateDir) {
22828
22938
  const privateKeyPath = shipSshKeyPathFor(stateDir);
22829
22939
  const publicKeyPath = `${privateKeyPath}.pub`;
22830
22940
  if (!existsSync46(privateKeyPath)) {
22831
- mkdirSync34(dirname28(privateKeyPath), { recursive: true });
22941
+ mkdirSync34(dirname29(privateKeyPath), { recursive: true });
22832
22942
  try {
22833
22943
  execFileSync13("ssh-keygen", [
22834
22944
  "-t",
@@ -22866,7 +22976,7 @@ function sshKeygenAvailable() {
22866
22976
  // src/periscope-idle.ts
22867
22977
  import { execFileSync as execFileSync14 } from "child_process";
22868
22978
  import { statSync as statSync13 } from "fs";
22869
- import { join as join50 } from "path";
22979
+ import { join as join51 } from "path";
22870
22980
  var MAX_SCANNED_FILES = 2e4;
22871
22981
  function newestWorktreeMtime(root) {
22872
22982
  const a = newestTrackedMtime(root);
@@ -22891,7 +23001,7 @@ function newestTrackedMtime(root) {
22891
23001
  if (!rel) continue;
22892
23002
  if (++scanned > MAX_SCANNED_FILES) break;
22893
23003
  try {
22894
- const m = statSync13(join50(root, rel)).mtimeMs;
23004
+ const m = statSync13(join51(root, rel)).mtimeMs;
22895
23005
  if (newest === null || m > newest) newest = m;
22896
23006
  } catch {
22897
23007
  }
@@ -22966,7 +23076,7 @@ async function runPeriscopeIdlePass(d) {
22966
23076
 
22967
23077
  // src/periscope-cmd.ts
22968
23078
  import { existsSync as existsSync47, mkdirSync as mkdirSync35, readFileSync as readFileSync45, rmSync as rmSync22, writeFileSync as writeFileSync37 } from "fs";
22969
- import { join as join51 } from "path";
23079
+ import { join as join52 } from "path";
22970
23080
  var PeriscopeError = class extends Error {
22971
23081
  };
22972
23082
  var LivePeriscopeError = class extends PeriscopeError {
@@ -22976,8 +23086,8 @@ var LivePeriscopeError = class extends PeriscopeError {
22976
23086
  this.data = { refused: "live_periscope_exists", ...live2 };
22977
23087
  }
22978
23088
  };
22979
- var priorDir = (stateDir) => join51(stateDir, "periscope-priors");
22980
- var priorPath = (stateDir, ticketRecordId) => join51(priorDir(stateDir), `${ticketRecordId}.json`);
23089
+ var priorDir = (stateDir) => join52(stateDir, "periscope-priors");
23090
+ var priorPath = (stateDir, ticketRecordId) => join52(priorDir(stateDir), `${ticketRecordId}.json`);
22981
23091
  function removePeriscopePrior(stateDir, ticketRecordId) {
22982
23092
  rmSync22(priorPath(stateDir, ticketRecordId), { force: true });
22983
23093
  }
@@ -23530,7 +23640,7 @@ function latestMtime(path) {
23530
23640
  if (!stat2.isDirectory()) return 0;
23531
23641
  let latest = stat2.mtimeMs;
23532
23642
  for (const entry of readdirSync15(path, { withFileTypes: true })) {
23533
- latest = Math.max(latest, latestMtime(join52(path, entry.name)));
23643
+ latest = Math.max(latest, latestMtime(join53(path, entry.name)));
23534
23644
  }
23535
23645
  return latest;
23536
23646
  }
@@ -23542,7 +23652,7 @@ function makeStaleChecker(paths, opts = {}) {
23542
23652
  return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync48(opts.reloadSentinel);
23543
23653
  }
23544
23654
  function reloadSentinelFor(stateDir) {
23545
- return join52(stateDir, "reload-requested");
23655
+ return join53(stateDir, "reload-requested");
23546
23656
  }
23547
23657
  function readReloadRequestedAt(stateDir) {
23548
23658
  try {
@@ -23552,7 +23662,7 @@ function readReloadRequestedAt(stateDir) {
23552
23662
  }
23553
23663
  }
23554
23664
  function daemonStampFor(stateDir) {
23555
- return join52(stateDir, "daemon.started");
23665
+ return join53(stateDir, "daemon.started");
23556
23666
  }
23557
23667
  function noteDaemonStarted(stateDir, now = Date.now()) {
23558
23668
  mkdirSync36(stateDir, { recursive: true });
@@ -24595,11 +24705,11 @@ function startLaunchdDaemon(o) {
24595
24705
 
24596
24706
  // src/daemon-start-failure.ts
24597
24707
  import { existsSync as existsSync50, mkdirSync as mkdirSync37, readFileSync as readFileSync49, unlinkSync as unlinkSync4, writeFileSync as writeFileSync39 } from "fs";
24598
- import { dirname as dirname29, join as join53 } from "path";
24708
+ import { dirname as dirname30, join as join54 } from "path";
24599
24709
  var DAEMON_START_FAILED_KEY = "daemon_start_failed";
24600
24710
  var START_FAILURE_BACKOFF_MS = 6e4;
24601
24711
  var BACKOFF_AFTER_FAILURES = 2;
24602
- var fileFor4 = (stateDir) => join53(stateDir, ".daemon-start-failure.json");
24712
+ var fileFor4 = (stateDir) => join54(stateDir, ".daemon-start-failure.json");
24603
24713
  function readStartFailure(stateDir) {
24604
24714
  try {
24605
24715
  const parsed = JSON.parse(readFileSync49(fileFor4(stateDir), "utf8"));
@@ -24660,7 +24770,7 @@ async function reportStartFailure(o) {
24660
24770
  return delay;
24661
24771
  }
24662
24772
  function fallbackStateDir(configFile) {
24663
- return join53(dirname29(configFile), "state");
24773
+ return join54(dirname30(configFile), "state");
24664
24774
  }
24665
24775
 
24666
24776
  // src/projects-cmd.ts
@@ -24854,7 +24964,7 @@ function runForge(a, io) {
24854
24964
  // src/release-sandbox.ts
24855
24965
  import { execFile as execFile5 } from "child_process";
24856
24966
  import { mkdirSync as mkdirSync38, writeFileSync as writeFileSync40 } from "fs";
24857
- import { dirname as dirname30 } from "path";
24967
+ import { dirname as dirname31 } from "path";
24858
24968
  import { promisify as promisify4 } from "util";
24859
24969
  var execFileP4 = promisify4(execFile5);
24860
24970
  var RELEASE_CLONE_DEPTH = 50;
@@ -24900,7 +25010,7 @@ async function openReleaseSandbox(o) {
24900
25010
  if (!policyFile) {
24901
25011
  generated = generateSandboxPolicy({ mirrorDir: cfg.mirrorDir, workDir: cfg.workDir, ...o.policy });
24902
25012
  policyFile = o.policyFile;
24903
- mkdirSync38(dirname30(policyFile), { recursive: true });
25013
+ mkdirSync38(dirname31(policyFile), { recursive: true });
24904
25014
  writeFileSync40(policyFile, generated.yaml, { mode: 384 });
24905
25015
  }
24906
25016
  const secrets = { ...process.env };
@@ -26073,12 +26183,12 @@ function describeCapability(i) {
26073
26183
 
26074
26184
  // src/persona-avatars.ts
26075
26185
  import { existsSync as existsSync52, readFileSync as readFileSync50 } from "fs";
26076
- import { join as join54 } from "path";
26186
+ import { join as join55 } from "path";
26077
26187
  var IMAGE_TYPES = { png: "image/png", svg: "image/svg+xml" };
26078
26188
  function personaAvatarFile(promptsDir, role) {
26079
26189
  for (const ext of ["png", "svg"]) {
26080
26190
  const name = `lane-${role}.${ext}`;
26081
- const path = join54(promptsDir, "personas", name);
26191
+ const path = join55(promptsDir, "personas", name);
26082
26192
  if (existsSync52(path)) return { path, mimeType: IMAGE_TYPES[ext], name };
26083
26193
  }
26084
26194
  return void 0;
@@ -26142,7 +26252,7 @@ function routeAvatarFailures(stateDir, route2) {
26142
26252
 
26143
26253
  // src/agents-sync-run.ts
26144
26254
  import { existsSync as existsSync53, mkdirSync as mkdirSync39, readFileSync as readFileSync51, writeFileSync as writeFileSync41 } from "fs";
26145
- import { dirname as dirname31 } from "path";
26255
+ import { dirname as dirname32 } from "path";
26146
26256
  async function runAgentsSync(target, o) {
26147
26257
  const dryRun = o.dryRun ?? false;
26148
26258
  const force = o.force ?? false;
@@ -26192,7 +26302,7 @@ async function runAgentsSync(target, o) {
26192
26302
  if (skillResult) raw.agentSkills = skillResult.agentSkills;
26193
26303
  if (!readOnly) raw.avatarSyncFailures = avatarFailures2;
26194
26304
  if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
26195
- mkdirSync39(dirname31(resolvedPath), { recursive: true });
26305
+ mkdirSync39(dirname32(resolvedPath), { recursive: true });
26196
26306
  writeFileSync41(resolvedPath, `${JSON.stringify(raw, null, 2)}
26197
26307
  `);
26198
26308
  if (target.resolved) {
@@ -26330,10 +26440,10 @@ async function showLogEntry(route2, entryId, opts = {}) {
26330
26440
 
26331
26441
  // src/repo-setup-prompt.ts
26332
26442
  import { readFileSync as readFileSync52 } from "fs";
26333
- import { join as join55 } from "path";
26334
- var REPO_SETUP_PROMPT_PATH = join55("docs", "repo-setup-prompt.md");
26443
+ import { join as join56 } from "path";
26444
+ var REPO_SETUP_PROMPT_PATH = join56("docs", "repo-setup-prompt.md");
26335
26445
  function readRepoSetupPrompt(crewHome) {
26336
- return readFileSync52(join55(crewHome, REPO_SETUP_PROMPT_PATH), "utf8");
26446
+ return readFileSync52(join56(crewHome, REPO_SETUP_PROMPT_PATH), "utf8");
26337
26447
  }
26338
26448
 
26339
26449
  // src/repos-check.ts
@@ -26672,7 +26782,7 @@ function existingRepoConfig(f) {
26672
26782
 
26673
26783
  // src/repos-hooks-agent.ts
26674
26784
  import { spawn as spawn9, execFileSync as execFileSync15 } from "child_process";
26675
- import { realpathSync as realpathSync2 } from "fs";
26785
+ import { realpathSync as realpathSync3 } from "fs";
26676
26786
  import { isAbsolute as isAbsolute3, relative } from "path";
26677
26787
  var AgentSuggestError = class extends Error {
26678
26788
  reason;
@@ -26728,7 +26838,7 @@ function parseAgentStream(out, dir) {
26728
26838
  const files = /* @__PURE__ */ new Set();
26729
26839
  let base = dir;
26730
26840
  try {
26731
- base = realpathSync2(dir);
26841
+ base = realpathSync3(dir);
26732
26842
  } catch {
26733
26843
  }
26734
26844
  for (const line of out.split("\n")) {
@@ -26843,7 +26953,7 @@ ${run4.err}` });
26843
26953
  }
26844
26954
 
26845
26955
  // src/sample-ticket.ts
26846
- import { basename as basename13, dirname as dirname32, join as join56 } from "path";
26956
+ import { basename as basename13, dirname as dirname33, join as join57 } from "path";
26847
26957
  var SAMPLE_REPO = "crew-sample";
26848
26958
  var SAMPLE_REMOTE = `local/${SAMPLE_REPO}`;
26849
26959
  var SAMPLE_MARKER = "sample: true";
@@ -26866,8 +26976,8 @@ has something safe to work on: its test and build hooks always pass, it has no
26866
26976
  remote, and \`crew sample-ticket --remove\` deletes it.
26867
26977
  `;
26868
26978
  function sampleDir(existing, reposBase, workspace) {
26869
- if (existing.length > 0) return join56(dirname32(existing[0]), SAMPLE_REPO);
26870
- return join56(reposBase, workspace, SAMPLE_REPO);
26979
+ if (existing.length > 0) return join57(dirname33(existing[0]), SAMPLE_REPO);
26980
+ return join57(reposBase, workspace, SAMPLE_REPO);
26871
26981
  }
26872
26982
  var SAMPLE_TITLE = "Sample: add a documented `greet` function with a test";
26873
26983
  function sampleDescription() {
@@ -27135,7 +27245,7 @@ function fixPhaseNothingToOffer(o) {
27135
27245
 
27136
27246
  // src/worktree-sweep.ts
27137
27247
  import { existsSync as existsSync54, readFileSync as readFileSync54, readdirSync as readdirSync16 } from "fs";
27138
- import { basename as basename14, dirname as dirname33, join as join57, resolve as resolve5 } from "path";
27248
+ import { basename as basename14, dirname as dirname34, join as join58, resolve as resolve5 } from "path";
27139
27249
  function planWorktreeSweep(target, tickets, contract) {
27140
27250
  const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
27141
27251
  const verified = contract.statuses.verified;
@@ -27199,7 +27309,7 @@ function worktreeTicketNumbers(target) {
27199
27309
  return [...nums];
27200
27310
  }
27201
27311
  function siblingWorktreeDirs(target) {
27202
- const parent = dirname33(target.dir.replace(/[/\\]+$/, ""));
27312
+ const parent = dirname34(target.dir.replace(/[/\\]+$/, ""));
27203
27313
  const stem = `${basename14(target.dir.replace(/[/\\]+$/, ""))}-`;
27204
27314
  const registered = new Set(worktrees(target.dir).map((w) => resolve5(w.path)));
27205
27315
  let names;
@@ -27212,7 +27322,7 @@ function siblingWorktreeDirs(target) {
27212
27322
  for (const name of names) {
27213
27323
  if (!name.startsWith(stem)) continue;
27214
27324
  const m = DIR_NUMBER_SUFFIXED.exec(name);
27215
- const path = join57(parent, name);
27325
+ const path = join58(parent, name);
27216
27326
  if (m && !registered.has(resolve5(path))) out.push({ path, number: m[1] });
27217
27327
  }
27218
27328
  return out;
@@ -27445,13 +27555,13 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
27445
27555
 
27446
27556
  // src/stream-sweep.ts
27447
27557
  import { existsSync as existsSync55, readdirSync as readdirSync17, rmSync as rmSync24, statSync as statSync16 } from "fs";
27448
- import { join as join58 } from "path";
27558
+ import { join as join59 } from "path";
27449
27559
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
27450
27560
  function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
27451
- const dir = join58(stateDir, "streams");
27561
+ const dir = join59(stateDir, "streams");
27452
27562
  if (!existsSync55(dir)) return [];
27453
27563
  const cutoff = now - retentionDays * DAY_MS2;
27454
- return readdirSync17(dir).map((name) => join58(dir, name)).filter((path) => {
27564
+ return readdirSync17(dir).map((name) => join59(dir, name)).filter((path) => {
27455
27565
  try {
27456
27566
  return statSync16(path).mtimeMs < cutoff;
27457
27567
  } catch {
@@ -27479,7 +27589,7 @@ function applyStreamSweep(paths, dryRun, log) {
27479
27589
  function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
27480
27590
  if (!existsSync55(stateDir)) return [];
27481
27591
  const cutoff = now - retentionDays * DAY_MS2;
27482
- return readdirSync17(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join58(stateDir, name)).filter((path) => {
27592
+ return readdirSync17(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join59(stateDir, name)).filter((path) => {
27483
27593
  try {
27484
27594
  return statSync16(path).mtimeMs < cutoff;
27485
27595
  } catch {
@@ -27493,7 +27603,7 @@ function planSizeCapSweep(stateDir, maxBytes, now = Date.now()) {
27493
27603
  if (!existsSync55(dir)) return;
27494
27604
  for (const name of readdirSync17(dir)) {
27495
27605
  if (!keep(name)) continue;
27496
- const path = join58(dir, name);
27606
+ const path = join59(dir, name);
27497
27607
  try {
27498
27608
  const st = statSync16(path);
27499
27609
  if (st.isFile()) files.push({ path, mtime: st.mtimeMs, size: st.size });
@@ -27501,7 +27611,7 @@ function planSizeCapSweep(stateDir, maxBytes, now = Date.now()) {
27501
27611
  }
27502
27612
  }
27503
27613
  };
27504
- add(join58(stateDir, "streams"), () => true);
27614
+ add(join59(stateDir, "streams"), () => true);
27505
27615
  add(stateDir, (name) => ROTATED_EVENTS_RE.test(name));
27506
27616
  let total = files.reduce((n, f) => n + f.size, 0);
27507
27617
  const out = [];
@@ -27521,7 +27631,7 @@ function planStateSweep(stateDir, retentionDays, maxBytes, now = Date.now()) {
27521
27631
  }
27522
27632
 
27523
27633
  // src/cli.ts
27524
- import { realpathSync as realpathSync3, readFileSync as readFileSync57, existsSync as existsSync60, mkdirSync as mkdirSync43, writeFileSync as writeFileSync44, rmSync as rmSync27, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync10, statSync as statSync19, readdirSync as readdirSync22 } from "fs";
27634
+ import { realpathSync as realpathSync4, readFileSync as readFileSync57, existsSync as existsSync60, mkdirSync as mkdirSync43, writeFileSync as writeFileSync44, rmSync as rmSync27, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync10, statSync as statSync19, readdirSync as readdirSync22 } from "fs";
27525
27635
  import { createInterface } from "readline/promises";
27526
27636
 
27527
27637
  // src/periscope-resume.ts
@@ -27598,9 +27708,9 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
27598
27708
 
27599
27709
  // src/bundle-staleness.ts
27600
27710
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
27601
- import { join as join59 } from "path";
27711
+ import { join as join60 } from "path";
27602
27712
  function builtVersion() {
27603
- return true ? "0.154.0" : null;
27713
+ return true ? "0.154.1" : null;
27604
27714
  }
27605
27715
  var REBUILD_HINT = "rebuild with npm run build";
27606
27716
  function newestMtime(path) {
@@ -27613,17 +27723,17 @@ function newestMtime(path) {
27613
27723
  if (stat2.isFile()) return stat2.mtimeMs;
27614
27724
  if (!stat2.isDirectory()) return 0;
27615
27725
  let latest = stat2.mtimeMs;
27616
- for (const e of readdirSync18(path, { withFileTypes: true })) latest = Math.max(latest, newestMtime(join59(path, e.name)));
27726
+ for (const e of readdirSync18(path, { withFileTypes: true })) latest = Math.max(latest, newestMtime(join60(path, e.name)));
27617
27727
  return latest;
27618
27728
  }
27619
27729
  function bundleStaleness(i) {
27620
27730
  if (i.built === null || i.compiled) return null;
27621
- const src = join59(i.home, "src");
27731
+ const src = join60(i.home, "src");
27622
27732
  if (!existsSync56(src)) return null;
27623
27733
  if (i.built !== i.current) {
27624
27734
  return { kind: "version", builtVersion: i.built, message: `running a bundle built from ${i.built} (package.json names ${i.current}); ${REBUILD_HINT}` };
27625
27735
  }
27626
- const bundle = statSafe(join59(i.home, "dist", "cli.js"));
27736
+ const bundle = statSafe(join60(i.home, "dist", "cli.js"));
27627
27737
  if (bundle === null) return null;
27628
27738
  if (newestMtime(src) > bundle) {
27629
27739
  return { kind: "source", builtVersion: i.built, message: `running a bundle older than the source in src/ (both ${i.current}); ${REBUILD_HINT}` };
@@ -27842,7 +27952,7 @@ import { createServer as createHttpServer } from "http";
27842
27952
  import { spawn as spawn10 } from "child_process";
27843
27953
  import { randomBytes as randomBytes2 } from "crypto";
27844
27954
  import { existsSync as existsSync57, mkdirSync as mkdirSync40, readFileSync as readFileSync55, writeFileSync as writeFileSync42, unlinkSync as unlinkSync5, readdirSync as readdirSync19 } from "fs";
27845
- import { join as join60 } from "path";
27955
+ import { join as join61 } from "path";
27846
27956
 
27847
27957
  // src/secret-compare.ts
27848
27958
  import { timingSafeEqual } from "crypto";
@@ -27935,7 +28045,7 @@ var defaultSpawn2 = (cmd, args, env) => {
27935
28045
  return child;
27936
28046
  };
27937
28047
  function syncDaemonStatePath(stateDir, workspaceId) {
27938
- return join60(stateDir, "passengers", `${workspaceId}-sync.json`);
28048
+ return join61(stateDir, "passengers", `${workspaceId}-sync.json`);
27939
28049
  }
27940
28050
  function readPersistedSyncDaemon(stateDir, workspaceId) {
27941
28051
  const path = syncDaemonStatePath(stateDir, workspaceId);
@@ -27948,7 +28058,7 @@ function readPersistedSyncDaemon(stateDir, workspaceId) {
27948
28058
  }
27949
28059
  function writePersistedSyncDaemon(stateDir, state) {
27950
28060
  const path = syncDaemonStatePath(stateDir, state.workspaceId);
27951
- mkdirSync40(join60(stateDir, "passengers"), { recursive: true });
28061
+ mkdirSync40(join61(stateDir, "passengers"), { recursive: true });
27952
28062
  writeFileSync42(path, `${JSON.stringify(state, null, 2)}
27953
28063
  `);
27954
28064
  }
@@ -27969,7 +28079,7 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
27969
28079
  }
27970
28080
  }
27971
28081
  function readAllPersistedSyncWorkspaceIds(stateDir) {
27972
- const dir = join60(stateDir, "passengers");
28082
+ const dir = join61(stateDir, "passengers");
27973
28083
  if (!existsSync57(dir)) return [];
27974
28084
  const suffix = "-sync.json";
27975
28085
  return readdirSync19(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
@@ -28034,7 +28144,7 @@ import { createServer, request as httpRequest } from "http";
28034
28144
  import { request as httpsRequest } from "https";
28035
28145
  import { connect as netConnect } from "net";
28036
28146
  import { connect as tlsConnect } from "tls";
28037
- import { dirname as dirname34, isAbsolute as isAbsolute4 } from "path";
28147
+ import { dirname as dirname35, isAbsolute as isAbsolute4 } from "path";
28038
28148
  import { brotliDecompressSync, gunzipSync, inflateSync } from "zlib";
28039
28149
 
28040
28150
  // src/periscope-inspector.ts
@@ -28148,7 +28258,7 @@ function parsePointedBody(raw) {
28148
28258
  return entry;
28149
28259
  }
28150
28260
  function appendPointed(file, entry, now = /* @__PURE__ */ new Date()) {
28151
- mkdirSync41(dirname34(file), { recursive: true });
28261
+ mkdirSync41(dirname35(file), { recursive: true });
28152
28262
  appendFileSync4(file, `${JSON.stringify({ ...entry, at: now.toISOString() })}
28153
28263
  `);
28154
28264
  }
@@ -28437,7 +28547,7 @@ async function startWorktreeIntel(d) {
28437
28547
  }
28438
28548
 
28439
28549
  // src/contract-refusal.ts
28440
- import { join as join61 } from "path";
28550
+ import { join as join62 } from "path";
28441
28551
  function contractFixers(dir, baseRef, tickets, locate) {
28442
28552
  const out = [];
28443
28553
  for (const t of tickets) {
@@ -28449,7 +28559,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
28449
28559
  const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
28450
28560
  if (text2 === null) continue;
28451
28561
  try {
28452
- parseRepoConfig(text2, join61(dir, file));
28562
+ parseRepoConfig(text2, join62(dir, file));
28453
28563
  } catch (e) {
28454
28564
  if (e instanceof RepoConfigError) continue;
28455
28565
  throw e;
@@ -28475,7 +28585,7 @@ import {
28475
28585
  } from "fs";
28476
28586
  import { createConnection } from "net";
28477
28587
  import { createServer as createServer2 } from "http";
28478
- import { basename as basename15, dirname as dirname35, join as join62 } from "path";
28588
+ import { basename as basename15, dirname as dirname36, join as join63 } from "path";
28479
28589
  import { execFile as execFile6, spawn as spawn13 } from "child_process";
28480
28590
 
28481
28591
  // src/periscope-control.ts
@@ -28713,7 +28823,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
28713
28823
  // src/control-api.ts
28714
28824
  var PAUSABLE = ["dev", "design", "qa"];
28715
28825
  var CONTROL_SOCKET_NAME = "control.sock";
28716
- var controlSocketFor = (stateDir) => join62(stateDir, CONTROL_SOCKET_NAME);
28826
+ var controlSocketFor = (stateDir) => join63(stateDir, CONTROL_SOCKET_NAME);
28717
28827
  var MAX_SOCKET_PATH = 100;
28718
28828
  var MAX_TAIL_BYTES = 1024 * 1024;
28719
28829
  var MAX_WAIT_SECONDS = 30;
@@ -28800,7 +28910,7 @@ function candidates(live2, rotated) {
28800
28910
  const out = [live2];
28801
28911
  if (!rotated) return out;
28802
28912
  try {
28803
- for (const n of readdirSync20(dirname35(live2))) if (ROTATED_EVENTS_RE.test(n)) out.push(join62(dirname35(live2), n));
28913
+ for (const n of readdirSync20(dirname36(live2))) if (ROTATED_EVENTS_RE.test(n)) out.push(join63(dirname36(live2), n));
28804
28914
  } catch {
28805
28915
  }
28806
28916
  return out;
@@ -28968,7 +29078,7 @@ async function tailReply(path, q2, rotated, abort) {
28968
29078
  const deadline = Date.now() + Math.min(wait, MAX_WAIT_SECONDS) * 1e3;
28969
29079
  let r = readTail(path, { after, tail: tail3, rotated });
28970
29080
  while (after && !r.lines.length && !r.reset && Date.now() < deadline && !abort.aborted) {
28971
- await waitForChange(dirname35(path), deadline - Date.now(), abort);
29081
+ await waitForChange(dirname36(path), deadline - Date.now(), abort);
28972
29082
  r = readTail(path, { after: r.cursor, rotated });
28973
29083
  }
28974
29084
  return reply2(200, r);
@@ -29059,7 +29169,7 @@ async function route(deps, method, url, req, abort) {
29059
29169
  if (p.startsWith("/streams/") && get2) {
29060
29170
  const run4 = decodeURIComponent(p.slice("/streams/".length));
29061
29171
  if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
29062
- const file = join62(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
29172
+ const file = join63(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
29063
29173
  if (!existsSync58(file)) return err2(404, "no such run");
29064
29174
  return tailReply(file, url.searchParams, false, abort);
29065
29175
  }
@@ -29227,7 +29337,7 @@ function crewJson(args, timeoutMs = CREW_JSON_TIMEOUT_MS) {
29227
29337
 
29228
29338
  // src/periscope-mcp.ts
29229
29339
  import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
29230
- import { basename as basename16, dirname as dirname36, isAbsolute as isAbsolute5, join as join64, relative as relative2, resolve as resolve6, sep } from "path";
29340
+ import { basename as basename16, dirname as dirname37, isAbsolute as isAbsolute5, join as join65, relative as relative2, resolve as resolve6, sep } from "path";
29231
29341
  import { z } from "zod";
29232
29342
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
29233
29343
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
@@ -29235,11 +29345,11 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
29235
29345
  // src/periscope-endpoints.ts
29236
29346
  import { randomBytes as randomBytes3 } from "crypto";
29237
29347
  import { chmodSync as chmodSync5, existsSync as existsSync59, mkdirSync as mkdirSync42, readdirSync as readdirSync21, readFileSync as readFileSync56, rmSync as rmSync26, writeFileSync as writeFileSync43 } from "fs";
29238
- import { join as join63 } from "path";
29239
- var secretDir = (stateDir) => join63(stateDir, "periscope-mcp");
29240
- var secretFile = (stateDir, id) => join63(secretDir(stateDir), `${id}.json`);
29241
- var endpointDir = (stateDir) => join63(stateDir, "periscope-endpoints");
29242
- var endpointFile = (stateDir, id) => join63(endpointDir(stateDir), `${id}.json`);
29348
+ import { join as join64 } from "path";
29349
+ var secretDir = (stateDir) => join64(stateDir, "periscope-mcp");
29350
+ var secretFile = (stateDir, id) => join64(secretDir(stateDir), `${id}.json`);
29351
+ var endpointDir = (stateDir) => join64(stateDir, "periscope-endpoints");
29352
+ var endpointFile = (stateDir, id) => join64(endpointDir(stateDir), `${id}.json`);
29243
29353
  function mintPeriscopeSecret(stateDir, ticketRecordId) {
29244
29354
  mkdirSync42(secretDir(stateDir), { recursive: true, mode: 448 });
29245
29355
  const secret = randomBytes3(32).toString("base64url");
@@ -29365,10 +29475,10 @@ async function realAncestor(p) {
29365
29475
  }
29366
29476
  if (isLink) {
29367
29477
  if (++hops > 40) throw new PathRefusal(`too many symbolic links resolving ${p}`);
29368
- cur = resolve6(dirname36(cur), await readlink(cur));
29478
+ cur = resolve6(dirname37(cur), await readlink(cur));
29369
29479
  continue;
29370
29480
  }
29371
- const parent = dirname36(cur);
29481
+ const parent = dirname37(cur);
29372
29482
  if (parent === cur) throw new PathRefusal(`cannot resolve ${p}`);
29373
29483
  tail3.push(basename16(cur));
29374
29484
  cur = parent;
@@ -29380,13 +29490,13 @@ async function resolveInWorktree(root, requested) {
29380
29490
  let abs;
29381
29491
  if (isAbsolute5(requested)) {
29382
29492
  abs = resolve6(requested);
29383
- if (isInside(root, abs)) abs = join64(realRoot, relative2(root, abs));
29493
+ if (isInside(root, abs)) abs = join65(realRoot, relative2(root, abs));
29384
29494
  } else {
29385
29495
  abs = resolve6(realRoot, requested);
29386
29496
  }
29387
29497
  if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
29388
29498
  const { real, rest } = await realAncestor(abs);
29389
- const final = rest ? join64(real, rest) : real;
29499
+ const final = rest ? join65(real, rest) : real;
29390
29500
  if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
29391
29501
  if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
29392
29502
  return final;
@@ -29454,7 +29564,7 @@ function createPeriscopeMcpServer(d, sc) {
29454
29564
  const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
29455
29565
  const lines2 = await Promise.all(entries.map(async (e) => {
29456
29566
  if (e.isDirectory()) return `[DIR] ${e.name}`;
29457
- const size = (await lstat(join64(abs, e.name))).size;
29567
+ const size = (await lstat(join65(abs, e.name))).size;
29458
29568
  return `[FILE] ${e.name} (${size} bytes)`;
29459
29569
  }));
29460
29570
  return text(lines2.join("\n") || "(empty)");
@@ -29479,7 +29589,7 @@ function createPeriscopeMcpServer(d, sc) {
29479
29589
  if (Buffer.byteLength(content) > MAX_WRITE_BYTES) return text(`content exceeds ${MAX_WRITE_BYTES} bytes`, true);
29480
29590
  const abs = await inTree(path);
29481
29591
  if (abs === await realpath(root)) return text("path must name a file", true);
29482
- await mkdir(dirname36(abs), { recursive: true });
29592
+ await mkdir(dirname37(abs), { recursive: true });
29483
29593
  await inTree(path);
29484
29594
  await writeFile(abs, content);
29485
29595
  return text(`Wrote ${Buffer.byteLength(content)} bytes to ${await rel(abs)}`);
@@ -29519,8 +29629,8 @@ function createPeriscopeMcpServer(d, sc) {
29519
29629
  inputSchema: { path: z.string() },
29520
29630
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
29521
29631
  }, async ({ path }) => {
29522
- const parent = await inTree(dirname36(path) === "" ? "." : dirname36(path));
29523
- const abs = join64(parent, basename16(path));
29632
+ const parent = await inTree(dirname37(path) === "" ? "." : dirname37(path));
29633
+ const abs = join65(parent, basename16(path));
29524
29634
  if (basename16(path) === ".git" || abs === parent) return text("path must name a file", true);
29525
29635
  const st = await lstat(abs).catch(() => void 0);
29526
29636
  if (!st) return text(`${path} does not exist`, true);
@@ -29641,7 +29751,7 @@ function findPeriscope(sidecars, segment) {
29641
29751
  }
29642
29752
 
29643
29753
  // src/cli.ts
29644
- var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname37(process.execPath) : resolve7(dirname37(fileURLToPath2(import.meta.url)), "..");
29754
+ var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname38(process.execPath) : resolve7(dirname38(fileURLToPath2(import.meta.url)), "..");
29645
29755
  var RELEASE_LOCK_TTL_MS = 20 * 60 * 1e3;
29646
29756
  var CYCLE_SECONDS2 = 120;
29647
29757
  var STALE_CYCLES = 3;
@@ -30748,7 +30858,7 @@ if (command === "passenger-sync-daemon") {
30748
30858
  for (const l of summarizeJobs(results, { dryRun, verbose: flag("verbose"), host })) emit.emit(l);
30749
30859
  if (host === "linux" && hasSystemd) {
30750
30860
  const label = labelFor(CREW_HOME, "run");
30751
- const staleTimer = join65(homedir11(), ".config", "systemd", "user", `${label}.timer`);
30861
+ const staleTimer = join66(homedir11(), ".config", "systemd", "user", `${label}.timer`);
30752
30862
  if (existsSync60(staleTimer)) {
30753
30863
  emit.emit(
30754
30864
  `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run, not applied)" : ""}`
@@ -31110,7 +31220,7 @@ ${changed2.map((c) => ` - ${c}
31110
31220
  harnessBin: "claude",
31111
31221
  ...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
31112
31222
  },
31113
- policyFile: join65(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
31223
+ policyFile: join66(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
31114
31224
  repo: mirror,
31115
31225
  origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
31116
31226
  base: effective.branch.base,
@@ -31636,7 +31746,7 @@ ${f.tail.trimEnd()}
31636
31746
  }
31637
31747
  for (const cand of outcome.unbuildable ?? []) {
31638
31748
  try {
31639
- const stranded = planStrandedVerified(cand, repo.branch.base, repo.branch.remote, flagged);
31749
+ const stranded = planStrandedVerified(cand, repo.branch.base, repo.branch.remote, flagged, { dir: target.dir, cfg: repo });
31640
31750
  const r = await applyStrandedVerified(
31641
31751
  tracker,
31642
31752
  stranded,
@@ -32379,7 +32489,7 @@ ${f.tail.trimEnd()}
32379
32489
  logFile: cfg.ship.logFile
32380
32490
  });
32381
32491
  }
32382
- const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join65(CREW_HOME, "src"), join65(CREW_HOME, "dist"), join65(CREW_HOME, "bin")];
32492
+ const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join66(CREW_HOME, "src"), join66(CREW_HOME, "dist"), join66(CREW_HOME, "bin")];
32383
32493
  const configPaths = daemonConfigPaths(cfg);
32384
32494
  watchPaths.push(...configPaths);
32385
32495
  noteDaemonStarted(cfg.ship.stateDir);
@@ -32766,7 +32876,7 @@ ${f.tail.trimEnd()}
32766
32876
  const found = cfg.routes.find((r) => r.route === routeArg);
32767
32877
  if (!found) throw new ReposError(`no route "${routeArg}" in the config (have: ${cfg.routes.map((r) => r.route).join(", ") || "none"})`);
32768
32878
  const named2 = value("route") ? void 0 : positional[3];
32769
- const dir = named2 ? repoDirOf(configText, dirname37(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
32879
+ const dir = named2 ? repoDirOf(configText, dirname38(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
32770
32880
  const target = reposOf(found).find((t) => resolvePath(t.dir) === dir || t.name === named2);
32771
32881
  const o = target ? found.repoOverrides[target.name] : void 0;
32772
32882
  runReposCheck(dir, {
@@ -32788,7 +32898,7 @@ ${f.tail.trimEnd()}
32788
32898
  if (sub === "hooks") {
32789
32899
  try {
32790
32900
  const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
32791
- const dir = repoDirOf(configText, dirname37(cfg.configFile), a.route, a.name);
32901
+ const dir = repoDirOf(configText, dirname38(cfg.configFile), a.route, a.name);
32792
32902
  if (!existsSync60(dir)) throw new ReposError(`${dir} does not exist on disk`);
32793
32903
  const files = { exists: (r) => existsSync60(resolvePath(dir, r)), list: (r) => {
32794
32904
  try {
@@ -32948,7 +33058,7 @@ ${f.tail.trimEnd()}
32948
33058
  }
32949
33059
  const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
32950
33060
  const text2 = configText;
32951
- const base = dirname37(cfg.configFile);
33061
+ const base = dirname38(cfg.configFile);
32952
33062
  const isCheckout = (d) => existsSync60(`${d}/.git`);
32953
33063
  try {
32954
33064
  if (sub === "list") {
@@ -33635,7 +33745,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
33635
33745
  process.stderr.write(`(dry run) would write resolved ids to ${resolvedPath}
33636
33746
  `);
33637
33747
  } else {
33638
- mkdirSync43(dirname37(resolvedPath), { recursive: true });
33748
+ mkdirSync43(dirname38(resolvedPath), { recursive: true });
33639
33749
  if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
33640
33750
  const tmpPath = `${resolvedPath}.tmp${process.pid}`;
33641
33751
  writeFileSync44(tmpPath, `${JSON.stringify(resolved, null, 2)}
@@ -33679,7 +33789,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`, "fix the problems above, t
33679
33789
  process.stderr.write(`(dry run) would write the minted API key to ${apiKeyFile}
33680
33790
  `);
33681
33791
  } else {
33682
- mkdirSync43(dirname37(apiKeyFile), { recursive: true });
33792
+ mkdirSync43(dirname38(apiKeyFile), { recursive: true });
33683
33793
  writeFileSync44(apiKeyFile, `${apiKeyVar}=${apiKey}
33684
33794
  `, { mode: 384 });
33685
33795
  routineLine(`API key written to ${apiKeyFile}`);
@@ -34317,10 +34427,10 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
34317
34427
  startupSeconds: cfg.ship.intelStartupSeconds,
34318
34428
  prepare: async (path) => {
34319
34429
  for (const f of repoWt.config.worktrees.copy) {
34320
- const src = join65(repoWt.dir, f);
34321
- if (!existsSync60(src) || existsSync60(join65(path, f))) continue;
34322
- mkdirSync43(dirOf2(join65(path, f)), { recursive: true });
34323
- copyFileSync2(src, join65(path, f));
34430
+ const src = join66(repoWt.dir, f);
34431
+ if (!existsSync60(src) || existsSync60(join66(path, f))) continue;
34432
+ mkdirSync43(dirOf2(join66(path, f)), { recursive: true });
34433
+ copyFileSync2(src, join66(path, f));
34324
34434
  }
34325
34435
  const setup = repoWt.config.hooks.setup;
34326
34436
  return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
@@ -34399,7 +34509,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
34399
34509
  }
34400
34510
  const real = (p) => {
34401
34511
  try {
34402
- return realpathSync3(p);
34512
+ return realpathSync4(p);
34403
34513
  } catch {
34404
34514
  return p;
34405
34515
  }
@@ -34647,10 +34757,10 @@ ${where.join("\n")}`);
34647
34757
  },
34648
34758
  prepare: async (path) => {
34649
34759
  for (const f of repoP.config.worktrees.copy) {
34650
- const src = join65(repoP.dir, f);
34760
+ const src = join66(repoP.dir, f);
34651
34761
  if (!existsSync60(src)) continue;
34652
- mkdirSync43(dirOf2(join65(path, f)), { recursive: true });
34653
- copyFileSync2(src, join65(path, f));
34762
+ mkdirSync43(dirOf2(join66(path, f)), { recursive: true });
34763
+ copyFileSync2(src, join66(path, f));
34654
34764
  }
34655
34765
  const setup = repoP.config.hooks.setup;
34656
34766
  return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
@@ -34959,7 +35069,7 @@ ${where.join("\n")}`);
34959
35069
  },
34960
35070
  inspectCheckout(dir) {
34961
35071
  const dirty = status(dir).map((c) => c.path);
34962
- const linkedWorktrees = worktrees(dir).map((w) => w.path).filter((p) => realpathSync3(p) !== realpathSync3(dir));
35072
+ const linkedWorktrees = worktrees(dir).map((w) => w.path).filter((p) => realpathSync4(p) !== realpathSync4(dir));
34963
35073
  return { dirty, linkedWorktrees };
34964
35074
  }
34965
35075
  };
@@ -35116,7 +35226,7 @@ ${where.join("\n")}`);
35116
35226
  if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
35117
35227
  const tracker = new Tracker(route2, cfg.ship);
35118
35228
  const configText = readFileSync57(cfg.configFile, "utf8");
35119
- const cfgBase = dirname37(cfg.configFile);
35229
+ const cfgBase = dirname38(cfg.configFile);
35120
35230
  const configured2 = configuredRepos(configText, route2.route, cfgBase);
35121
35231
  const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
35122
35232
  const resolvedFile = resolvedPathFor(cfg.ship.stateDir, route2.route);
@@ -35160,12 +35270,12 @@ ${where.join("\n")}`);
35160
35270
  `);
35161
35271
  }
35162
35272
  }
35163
- if (existsSync60(join65(dir, ".git")) && basename17(dir) === SAMPLE_REPO) rmSync27(dir, { recursive: true, force: true });
35273
+ if (existsSync60(join66(dir, ".git")) && basename17(dir) === SAMPLE_REPO) rmSync27(dir, { recursive: true, force: true });
35164
35274
  say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
35165
35275
  break;
35166
35276
  }
35167
35277
  const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
35168
- const fresh = !existsSync60(join65(dir, ".git"));
35278
+ const fresh = !existsSync60(join66(dir, ".git"));
35169
35279
  if (existsSync60(dir) && fresh && readdirSync22(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
35170
35280
  if (dryRun) {
35171
35281
  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`);
@@ -35173,8 +35283,8 @@ ${where.join("\n")}`);
35173
35283
  }
35174
35284
  if (fresh) {
35175
35285
  mkdirSync43(dir, { recursive: true });
35176
- writeFileSync44(join65(dir, "README.md"), SAMPLE_README);
35177
- writeFileSync44(join65(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
35286
+ writeFileSync44(join66(dir, "README.md"), SAMPLE_README);
35287
+ writeFileSync44(join66(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
35178
35288
  const g = (...a) => {
35179
35289
  const r = spawnSync14("git", a, { cwd: dir, encoding: "utf8" });
35180
35290
  if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);