@tablation/crew 0.164.0 → 0.164.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -7275,7 +7275,7 @@ function noProjectsFinding(route2, projectCount) {
7275
7275
 
7276
7276
  // src/passenger-containers.ts
7277
7277
  import { execFileSync as execFileSync10 } from "child_process";
7278
- import { createHash as createHash7 } from "crypto";
7278
+ import { createHash as createHash8 } from "crypto";
7279
7279
 
7280
7280
  // src/sandbox-cache.ts
7281
7281
  import { execFile as execFile2 } from "child_process";
@@ -7357,7 +7357,7 @@ import { readFileSync as readFileSync31, existsSync as existsSync29, statSync as
7357
7357
  import { StringDecoder } from "string_decoder";
7358
7358
  import { finished } from "stream/promises";
7359
7359
  import { join as join34, dirname as dirname17, basename as basename9 } from "path";
7360
- import { createHash as createHash6, randomUUID as randomUUID2 } from "crypto";
7360
+ import { createHash as createHash7, randomUUID as randomUUID2 } from "crypto";
7361
7361
 
7362
7362
  // src/state.ts
7363
7363
  import { readFileSync as readFileSync21, writeFileSync as writeFileSync16, existsSync as existsSync20, mkdirSync as mkdirSync15, rmSync as rmSync11, statSync as statSync7, readdirSync as readdirSync6 } from "fs";
@@ -7567,16 +7567,16 @@ var State = class _State {
7567
7567
  reason: roleMax === 1 ? `${role} is already running (pid ${roleHolders[0]})` : `${role} is already running ${roleMax} agents (its roleConcurrency cap; pid${roleHolders.length > 1 ? "s" : ""} ${[...new Set(roleHolders)].join(", ")})`
7568
7568
  };
7569
7569
  }
7570
- const slot = this.acquireN("crew-slot", max);
7571
- if (!slot.ok) {
7570
+ const slot2 = this.acquireN("crew-slot", max);
7571
+ if (!slot2.ok) {
7572
7572
  roleLock.release();
7573
7573
  return {
7574
7574
  ok: false,
7575
- reason: `at capacity \u2014 ${max} agent(s) already running (pid${slot.heldBy.length > 1 ? "s" : ""} ${slot.heldBy.join(", ")})`
7575
+ reason: `at capacity \u2014 ${max} agent(s) already running (pid${slot2.heldBy.length > 1 ? "s" : ""} ${slot2.heldBy.join(", ")})`
7576
7576
  };
7577
7577
  }
7578
7578
  return { ok: true, release: () => {
7579
- slot.release();
7579
+ slot2.release();
7580
7580
  roleLock.release();
7581
7581
  } };
7582
7582
  }
@@ -9512,6 +9512,7 @@ import { join as join28 } from "path";
9512
9512
  var sleepBackoff = (attempts) => Math.min(6e4 * 2 ** Math.max(0, attempts - 1), 30 * 6e4);
9513
9513
 
9514
9514
  // src/handoff-guard.ts
9515
+ import { createHash as createHash4 } from "crypto";
9515
9516
  import { existsSync as existsSync24, realpathSync as realpathSync2 } from "fs";
9516
9517
  import { dirname as dirname14, join as join27 } from "path";
9517
9518
 
@@ -11503,27 +11504,69 @@ function repairMisnamedBranch(dir, cfg, ticket, role) {
11503
11504
  const base = [`${cfg.branch.remote}/${cfg.branch.base}`, cfg.branch.base].find((b) => gitOk(dir, ["rev-parse", "--verify", "-q", b]) !== null);
11504
11505
  const ahead = base ? Number(gitOk(dir, ["rev-list", "--count", `${base}..${from}`]) ?? "1") : 1;
11505
11506
  if (ahead === 0) return { kind: "none" };
11506
- if (existing) {
11507
+ if (existing) return repairBehindContractBranch(dir, wt.path, from, existing, expected, cfg.branch.remote);
11508
+ try {
11509
+ git(dir, ["branch", "-m", from, expected]);
11510
+ } catch (e) {
11507
11511
  return {
11508
11512
  kind: "refused",
11509
11513
  from,
11510
- to: existing,
11514
+ to: expected,
11511
11515
  local: headSha(wt.path),
11512
- 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}\`)`
11516
+ reason: `the ticket's worktree is on \`${from}\`, not the expected \`${expected}\`, and renaming it failed: ${e.message}`
11517
+ };
11518
+ }
11519
+ return { kind: "renamed", from, to: expected };
11520
+ }
11521
+ function repairBehindContractBranch(dir, wtPath, from, to, expected, remote) {
11522
+ const head = headSha(wtPath);
11523
+ const toTip = gitOk(dir, ["rev-parse", "--verify", "-q", `refs/heads/${to}`]);
11524
+ const elsewhere = worktrees(dir).find((w) => w.branch === to && !w.prunable && !sameDir(w.path, wtPath));
11525
+ const named = to !== expected ? ` (expected name: \`${expected}\`)` : "";
11526
+ if (elsewhere) {
11527
+ return {
11528
+ kind: "refused",
11529
+ from,
11530
+ to,
11531
+ local: head,
11532
+ toTip,
11533
+ worktree: wtPath,
11534
+ reason: `the ticket's worktree is on \`${from}\` (at \`${head}\`), but the contract branch \`${to}\` is checked out in another worktree, \`${elsewhere.path}\`, so the runner cannot move it${named}`,
11535
+ fix: `git -C ${elsewhere.path} switch --detach # or: git worktree remove ${elsewhere.path}`
11536
+ };
11537
+ }
11538
+ if (!head || !toTip || !isAncestor(dir, toTip, head)) {
11539
+ const counts = toTip && head ? gitOk(dir, ["rev-list", "--left-right", "--count", `${to}...${head}`])?.split(/\s+/).map(Number) : void 0;
11540
+ const sides = counts && counts.length === 2 ? `\`${to}\` holds ${counts[0]} commit${counts[0] === 1 ? "" : "s"} the worktree's HEAD lacks, and HEAD holds ${counts[1]} that \`${to}\` lacks` : `the two could not be compared`;
11541
+ return {
11542
+ kind: "refused",
11543
+ from,
11544
+ to,
11545
+ local: head,
11546
+ toTip,
11547
+ worktree: wtPath,
11548
+ reason: `the ticket's worktree is on \`${from}\` at \`${head}\` and the contract branch \`${to}\` is at \`${toTip}\`: ${sides}. Nothing was moved or deleted${named}`,
11549
+ fix: `git -C ${wtPath} merge ${to} # resolve any conflict, commit, run the suite`
11513
11550
  };
11514
11551
  }
11515
11552
  try {
11516
- git(dir, ["branch", "-m", from, expected]);
11553
+ git(dir, ["branch", "-f", to, head]);
11554
+ git(wtPath, ["switch", to]);
11517
11555
  } catch (e) {
11518
11556
  return {
11519
11557
  kind: "refused",
11520
11558
  from,
11521
- to: expected,
11522
- local: headSha(wt.path),
11523
- reason: `the ticket's worktree is on \`${from}\`, not the expected \`${expected}\`, and renaming it failed: ${e.message}`
11559
+ to,
11560
+ local: head,
11561
+ toTip,
11562
+ reason: `the ticket's worktree is on \`${from}\` at \`${head}\`; \`${to}\` is only behind it, but moving the worktree onto it failed: ${e.message}`,
11563
+ fix: `git -C ${wtPath} switch ${to}`,
11564
+ worktree: wtPath
11524
11565
  };
11525
11566
  }
11526
- return { kind: "renamed", from, to: expected };
11567
+ gitOk(wtPath, ["branch", "--set-upstream-to", `${remote}/${to}`, to]);
11568
+ gitOk(dir, ["branch", "-D", from]);
11569
+ return { kind: "renamed", from, to };
11527
11570
  }
11528
11571
  async function announceRename(i, ticketId, r, sha, remote, log) {
11529
11572
  let remoteNote;
@@ -11553,9 +11596,26 @@ function describeHandoffPush(dir, cfg, ticket, role) {
11553
11596
  const v = inspectHandoff(dir, cfg, ticket, role);
11554
11597
  return v.kind === "bounce" && pushableBounce(dir, v) ? `would push ${v.branch} to ${v.remote}` : null;
11555
11598
  }
11556
- function bounceComment(v, shipName2, pushError) {
11557
- return `${HANDOFF_BOUNCED_MARKER}
11599
+ function bounceSignature(...parts) {
11600
+ return createHash4("sha256").update(parts.map((p) => p ?? "").join("\n")).digest("hex").slice(0, 12);
11601
+ }
11602
+ var SIGNATURE_RE = /Bounce signature: `([0-9a-f]{12})`/;
11603
+ var signatureLine = (sig) => `Bounce signature: \`${sig}\``;
11604
+ function repeatParagraph(what, change) {
11605
+ return `**This is the second bounce for exactly the same state.** The run since the last note changed nothing the guard checks: ${what}. Repeating the same hand-off will bounce again, and a third identical bounce parks this ticket for a person. ${change}
11558
11606
 
11607
+ `;
11608
+ }
11609
+ function bounceComment(v, shipName2, pushError, repeat) {
11610
+ const again = repeat?.second ? repeatParagraph(
11611
+ `the local HEAD is still ${v.local ? `\`${v.local}\`` : "(no local branch)"} and \`${v.remote}\` is still ${v.origin ? `\`${v.origin}\`` : "(without the branch)"}`,
11612
+ `Change it: run \`git rev-parse HEAD\` and \`git ls-remote ${v.remote} ${v.branch ?? "<branch>"}\` in the worktree, push the commit that is missing, and if git refuses the push, set \`needs_info\` quoting its error instead of handing off again.`
11613
+ ) : "";
11614
+ return `${HANDOFF_BOUNCED_MARKER}
11615
+ ${repeat ? `
11616
+ ${signatureLine(repeat.sig)}
11617
+ ` : ""}
11618
+ ${again}
11559
11619
  **Hand-off bounced: the branch is not on \`${v.remote}\` at the tip this ticket was built to.**
11560
11620
 
11561
11621
  ${shipName2 ? `Ship: ${shipName2}
@@ -11564,6 +11624,43 @@ ${shipName2 ? `Ship: ${shipName2}
11564
11624
 
11565
11625
  ${v.reason[0].toUpperCase()}${v.reason.slice(1)}. ${pushError ? ` The runner tried a plain push and git refused it: \`${pushError}\`.` : ""} Set back to \`in_progress\`, still held by this ship; push with a plain \`git push --set-upstream ${v.remote} <branch>\` (never \`--force\`) and set \`fixed\` again. Your brief authorizes this push: it is the hand-off, not a release, so do it now rather than asking for permission.`;
11566
11626
  }
11627
+ function refusalComment(r, remote, remoteContractTip, shipName2, repeat) {
11628
+ const remoteLine = remoteContractTip === null ? "(could not be asked)" : remoteContractTip ? `\`${remoteContractTip}\`` : "(no such branch)";
11629
+ const again = repeat.second ? repeatParagraph(
11630
+ `the worktree is still on \`${r.from}\` at ${r.local ? `\`${r.local}\`` : "(unknown)"} and \`${r.to}\` is still at ${r.toTip ? `\`${r.toTip}\`` : "(not local)"}`,
11631
+ `Run the commands below; handing off again without them leaves this exactly as it is.`
11632
+ ) : "";
11633
+ return `${HANDOFF_BOUNCED_MARKER}
11634
+
11635
+ ${signatureLine(repeat.sig)}
11636
+
11637
+ **Hand-off bounced: the ticket's worktree is on \`${r.from}\`, not on the contract branch \`${r.to}\`, and the runner could not rename it safely.**
11638
+
11639
+ ${shipName2 ? `Ship: ${shipName2}
11640
+ ` : ""}Worktree branch \`${r.from}\`: ${r.local ? `\`${r.local}\`` : "(unknown)"}
11641
+ Contract branch \`${r.to}\` (local): ${r.toTip ? `\`${r.toTip}\`` : "(not a local branch)"}
11642
+ \`${remote}/${r.to}\`: ${remoteLine}
11643
+
11644
+ ${again}${r.reason[0].toUpperCase()}${r.reason.slice(1)}.${r.fix ? `
11645
+
11646
+ Resolve it with:
11647
+
11648
+ \`\`\`
11649
+ ${r.fix}
11650
+ \`\`\`
11651
+
11652
+ then set \`fixed\` again: the runner moves \`${r.to}\` to the worktree's HEAD, switches the worktree onto it and pushes it as a plain fast-forward.` : ""} Nothing was forced and no commit was discarded. Set back to \`in_progress\`, still held by this ship.`;
11653
+ }
11654
+ async function identicalBounces(i, ticketRow, sig) {
11655
+ if (!i.writer.events) return 0;
11656
+ const evs = (await i.writer.events("bounced").catch(() => [])).filter((e) => e.record_id === ticketRow).sort((a, b) => (b.occurred_at ?? b.created_at ?? "").localeCompare(a.occurred_at ?? a.created_at ?? ""));
11657
+ let n = 0;
11658
+ for (const e of evs) {
11659
+ if (SIGNATURE_RE.exec(e.message ?? "")?.[1] !== sig) break;
11660
+ n++;
11661
+ }
11662
+ return n;
11663
+ }
11567
11664
  var NOTE_BUDGET = 4800;
11568
11665
  function boundNote(note, budget = NOTE_BUDGET) {
11569
11666
  if (note.length <= budget) return note;
@@ -11690,7 +11787,10 @@ async function enforceHandoff(i) {
11690
11787
  const repair = i.origin ? { kind: "none" } : repairMisnamedBranch(i.dir, i.cfg, t, i.role);
11691
11788
  const renamed = repair.kind === "renamed" ? repair : null;
11692
11789
  if (renamed) i.log.warn(`${displayKey(t)}: renamed the misnamed branch ${renamed.from} to ${renamed.to}`, log);
11693
- 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);
11790
+ const refusal = repair.kind === "refused" ? repair : null;
11791
+ const refusedTip = refusal && !i.origin ? remoteTip(i.dir, i.cfg.branch.remote, refusal.to) : null;
11792
+ const mismatch = refusal && refusedTip && refusedTip === refusal.local ? refusal : null;
11793
+ const v = mismatch ? { kind: "pushed", branch: mismatch.to, sha: refusedTip, remote: i.cfg.branch.remote } : refusal ? { kind: "bounce", branch: null, remote: i.cfg.branch.remote, local: refusal.local, origin: refusedTip || null, reason: refusal.reason } : i.origin ? inspectRemoteHandoff(i.origin, i.cfg, t, i.role) : inspectHandoff(i.dir, i.cfg, t, i.role);
11694
11794
  if (v.kind === "unverified") {
11695
11795
  i.log.warn(`${displayKey(t)} is at ${t.status} but the push was not checked: ${v.why}`, log);
11696
11796
  return { kind: "unverified", why: v.why };
@@ -11720,6 +11820,7 @@ async function enforceHandoff(i) {
11720
11820
  if (v.kind === "pushed") {
11721
11821
  await postPushed(i, t.id, v.sha, v.remote, v.branch, log);
11722
11822
  if (renamed) await announceRename(i, t.id, renamed, v.sha, v.remote, log);
11823
+ if (mismatch) await i.writer.postEvent(t.id, `The hand-off stands: \`${v.remote}/${mismatch.to}\` is at the worktree's HEAD (${v.sha}). Only the local branch name is off, and the runner left it alone: ${mismatch.reason}.${mismatch.fix ? ` To tidy it: \`${mismatch.fix}\`.` : ""}`, i.seatId, "branch_mismatch").catch((e) => i.log.warn(`the local branch mismatch note failed to post: ${e.message}`, log));
11723
11824
  i.log.emit(`${displayKey(t)} pushed at ${v.sha.slice(0, 7)} \u2014 handed on to QA`, log);
11724
11825
  return { kind: "pushed", sha: v.sha };
11725
11826
  }
@@ -11771,7 +11872,30 @@ async function enforceHandoff(i) {
11771
11872
  } else pushError = done.error;
11772
11873
  if (pushError) i.log.warn(`${displayKey(t)}: the runner's own push failed: ${pushError}`, log);
11773
11874
  }
11774
- if (!await deliverNote(i, t.id, bounceComment(v, i.shipName, pushError), "bounced", log)) {
11875
+ const sig = refusal ? bounceSignature("refused", refusal.from, refusal.to, refusal.local, refusal.toTip, v.origin) : bounceSignature(v.reason, v.branch, v.local, v.origin);
11876
+ const earlier = await identicalBounces(i, t.id, sig);
11877
+ if (earlier >= 2) {
11878
+ const diagnosis = refusal ? `${refusal.reason}. ${refusal.fix ? `The commands that resolve it: \`${refusal.fix}\`.` : ""}` : `${v.reason}. Local HEAD ${v.local ? `\`${v.local}\`` : "(none)"}, \`${v.remote}\` ${v.origin ? `\`${v.origin}\`` : "(without the branch)"}${pushError ? `; the runner's own plain push failed: \`${pushError}\`` : ""}.`;
11879
+ const parked = `${HANDOFF_BOUNCED_MARKER}
11880
+
11881
+ **Parked: the same hand-off bounce happened ${earlier + 1} times in a row with nothing changing.**
11882
+
11883
+ ${diagnosis}
11884
+
11885
+ Needs a person to resolve the branch state above; set the status back to \`in_progress\` when done.`;
11886
+ if (await deliverNote(i, t.id, parked, "bounce_parked", log)) {
11887
+ await i.writer.updateTicket(t.id, {
11888
+ status: i.contract.statuses.needsHuman,
11889
+ assignee_id: i.parkTo ?? null,
11890
+ ...i.hold ? { [i.hold.column]: null } : {}
11891
+ });
11892
+ i.log.warn(`${displayKey(t)} parked for a person: the same hand-off bounce ${earlier + 1} times in a row`, log);
11893
+ return { kind: "bounced" };
11894
+ }
11895
+ }
11896
+ const repeat = { sig, second: earlier === 1 };
11897
+ const note = refusal ? refusalComment(refusal, v.remote, refusedTip, i.shipName, repeat) : bounceComment(v, i.shipName, pushError, repeat);
11898
+ if (!await deliverNote(i, t.id, note, "bounced", log)) {
11775
11899
  i.log.warn(`${displayKey(t)}: ${v.reason}, but the bounce note could not be delivered \u2014 left at ${t.status}, guard outcome unverified`, log);
11776
11900
  return { kind: "unverified", why: "the bounce note could not be posted" };
11777
11901
  }
@@ -11833,6 +11957,7 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
11833
11957
  cfg,
11834
11958
  seatId,
11835
11959
  shipName: ship.name,
11960
+ parkTo: route2.resolved?.operator,
11836
11961
  hold: affinity ? { column: affinity.column, shipId: affinity.shipId } : void 0,
11837
11962
  since: since2,
11838
11963
  log,
@@ -12887,7 +13012,7 @@ function seatNotesSection(notes) {
12887
13012
  }
12888
13013
 
12889
13014
  // src/sandbox-image.ts
12890
- import { createHash as createHash4 } from "crypto";
13015
+ import { createHash as createHash5 } from "crypto";
12891
13016
  import { spawn as spawn4 } from "child_process";
12892
13017
  import { execFileSync as execFileSync8 } from "child_process";
12893
13018
  import { existsSync as existsSync26, mkdirSync as mkdirSync20, readFileSync as readFileSync27, renameSync as renameSync5, writeFileSync as writeFileSync21, rmSync as rmSync16, statSync as statSync8 } from "fs";
@@ -12928,7 +13053,7 @@ echo "password=$CREW_FORGE_TOKEN"
12928
13053
  `;
12929
13054
  var MCP_CONFIG = `${JSON.stringify({ mcpServers: {} }, null, 2)}
12930
13055
  `;
12931
- var hash = (parts) => createHash4("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 12);
13056
+ var hash = (parts) => createHash5("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 12);
12932
13057
  var slug = (s) => s.toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || "repo";
12933
13058
  var run2 = (cmd) => `RUN ["/bin/bash", "-c", ${JSON.stringify(`set -euo pipefail; ${cmd}`)}]`;
12934
13059
  var CREW_ENV = {
@@ -14104,7 +14229,7 @@ function skillMarkerWarnings(promptsDir, personaPrompts) {
14104
14229
  // src/runner.ts
14105
14230
  import { spawn as spawn5, execFile, execFileSync as execFileSync9 } from "child_process";
14106
14231
  import { mkdtempSync, mkdirSync as mkdirSync21, writeFileSync as writeFileSync22, rmSync as rmSync17 } from "fs";
14107
- import { createHash as createHash5 } from "crypto";
14232
+ import { createHash as createHash6 } from "crypto";
14108
14233
  import { tmpdir as tmpdir4 } from "os";
14109
14234
  import { basename as basename8, dirname as dirname16, join as join33 } from "path";
14110
14235
  import { promisify } from "util";
@@ -14200,7 +14325,7 @@ function shQuote2(s) {
14200
14325
  return `'${s.replace(/'/g, `'\\''`)}'`;
14201
14326
  }
14202
14327
  function sandboxName(plan, now = Date.now()) {
14203
- const h = createHash5("sha256").update([plan.route, plan.role, plan.ticket ?? ""].join("\0")).digest();
14328
+ const h = createHash6("sha256").update([plan.route, plan.role, plan.ticket ?? ""].join("\0")).digest();
14204
14329
  const tag = (h.readUInt32BE(0) % 36 ** 6).toString(36).padStart(6, "0");
14205
14330
  return `crew-${tag}${now.toString(36).slice(-8).padStart(8, "0")}`;
14206
14331
  }
@@ -14620,7 +14745,7 @@ function planAgentRun(o) {
14620
14745
  brief: expanded.text,
14621
14746
  digest
14622
14747
  });
14623
- const promptSha = createHash6("sha256").update(expanded.text).digest("hex");
14748
+ const promptSha = createHash7("sha256").update(expanded.text).digest("hex");
14624
14749
  const streamsDir = join34(o.stateDir, "streams");
14625
14750
  const base = `${routeLabel2}-${o.role}-${o.cycle}${o.runId ? `-${o.runId}` : ""}`;
14626
14751
  const seat = resolveSeat(o.ship, o.route, o.role, o.agentPersona ?? (o.agentModel ? { model: o.agentModel } : {}), o.repo);
@@ -16344,12 +16469,12 @@ function containerNameFor(workspaceId) {
16344
16469
  return `crew-passenger-${workspaceId}`;
16345
16470
  }
16346
16471
  function portFor(workspaceId, base = 28765, span = 1e3) {
16347
- const digest = createHash7("sha256").update(workspaceId).digest();
16472
+ const digest = createHash8("sha256").update(workspaceId).digest();
16348
16473
  return base + digest.readUInt32BE(0) % span;
16349
16474
  }
16350
16475
  function mountsDigest(mounts, image) {
16351
16476
  const sorted2 = [...mounts].sort((a, b) => a.containerPath.localeCompare(b.containerPath));
16352
- return createHash7("sha256").update(JSON.stringify({ mounts: sorted2, image })).digest("hex").slice(0, 16);
16477
+ return createHash8("sha256").update(JSON.stringify({ mounts: sorted2, image })).digest("hex").slice(0, 16);
16353
16478
  }
16354
16479
  function planContainers(cfg) {
16355
16480
  const byWorkspace = /* @__PURE__ */ new Map();
@@ -17850,13 +17975,13 @@ import { hostname as hostname3 } from "os";
17850
17975
 
17851
17976
  // src/machine-id.ts
17852
17977
  import { execFileSync as execFileSync12 } from "child_process";
17853
- import { createHash as createHash8 } from "crypto";
17978
+ import { createHash as createHash9 } from "crypto";
17854
17979
  import { existsSync as existsSync36, mkdirSync as mkdirSync27, readFileSync as readFileSync38, writeFileSync as writeFileSync29 } from "fs";
17855
17980
  import { dirname as dirname21, join as join42 } from "path";
17856
17981
  function machineIdPathFor(stateDir) {
17857
17982
  return join42(stateDir, "machine-id");
17858
17983
  }
17859
- var sha256 = (s) => createHash8("sha256").update(s).digest("hex");
17984
+ var sha256 = (s) => createHash9("sha256").update(s).digest("hex");
17860
17985
  function readRawMachineId(platform2 = process.platform) {
17861
17986
  try {
17862
17987
  if (platform2 === "darwin") {
@@ -18893,12 +19018,12 @@ function sweepDiagnostics(tickets, info) {
18893
19018
  return { dangling, selfBlocked: [...new Set(selfBlocked)] };
18894
19019
  }
18895
19020
  var describeBlockers = (t, info) => (t.blocked_by ?? []).map((id) => `${info[id]?.issue_tag ?? info[id]?.issue_id ?? "?"} (${info[id]?.status ?? "unknown"})`).join(", ");
18896
- function planSweep(tickets, info, blocked, wm, footprintWaits) {
19021
+ function planSweep(tickets, info, blocked, wm, footprintWaits, resolved) {
18897
19022
  const steps = [];
18898
19023
  for (const t of withinWorkMode(tickets, wm)) {
18899
19024
  if (t.status === "accepted" && blocked.has(t.id)) {
18900
19025
  const fw = footprintWaits?.get(t.id);
18901
- const byFiles = fw && unresolvedBlockers(t, info).length === 0;
19026
+ const byFiles = fw && unresolvedBlockers(t, info, { resolved }).length === 0;
18902
19027
  steps.push({
18903
19028
  action: "park",
18904
19029
  ticket: t,
@@ -20090,7 +20215,8 @@ async function decideCycle(o) {
20090
20215
  const extra = await tracker.ticketsByIds(missingBlockerIds(tickets));
20091
20216
  const info = blockerInfoMap(tickets, extra);
20092
20217
  await reportTruncated(tracker, route2.route, state, emit);
20093
- const blocked = computeBlockedIds(tickets, info, { resolved: new Set(tracker.contract.statuses.resolved) });
20218
+ const resolvedStatuses = new Set(tracker.contract.statuses.resolved);
20219
+ const blocked = computeBlockedIds(tickets, info, { resolved: resolvedStatuses });
20094
20220
  const footprintEvents = await optional("footprint events", readFootprintEvents(tracker), { declared: /* @__PURE__ */ new Map(), pushed: /* @__PURE__ */ new Map() });
20095
20221
  const footprintPlan = planFootprintsFor(route2, tickets, footprintEvents, new Set(blocked));
20096
20222
  for (const id of footprintPlan.waits.keys()) blocked.add(id);
@@ -20103,7 +20229,7 @@ async function decideCycle(o) {
20103
20229
  if (diag.selfBlocked.length) {
20104
20230
  emit.warn(`ticket(s) blocking themselves, parked permanently: ${diag.selfBlocked.join(", ")}`);
20105
20231
  }
20106
- const sweep = planSweep(tickets, info, blocked, workModes, footprintPlan.waits);
20232
+ const sweep = planSweep(tickets, info, blocked, workModes, footprintPlan.waits, resolvedStatuses);
20107
20233
  const holdReleases = planHoldReleases(tickets, tracker.contract);
20108
20234
  const stalled = planStalled(tickets, comments, ships, tracker.contract, holds2, Date.now(), workModes, stalledEvents);
20109
20235
  const skipped = await skippedCounts(tracker, tickets, projectModes);
@@ -20126,7 +20252,7 @@ async function decideCycle(o) {
20126
20252
  reportTypeColumn: tracker.contract.columns.reportType,
20127
20253
  coordinatingValue: tracker.contract.coordinatingValue
20128
20254
  };
20129
- for (const r of rollUpParents(tickets, void 0, coordinating)) {
20255
+ for (const r of rollUpParents(tickets, resolvedStatuses, coordinating)) {
20130
20256
  if (r.complete) {
20131
20257
  emit.note(`every child is done \u2014 this coordinating ticket is too`, { ticket: r.parent.issue_id });
20132
20258
  }
@@ -23398,6 +23524,30 @@ Passed: ${passed}.${willClose ? " Closing this alert." : ""}`,
23398
23524
  return out;
23399
23525
  }
23400
23526
 
23527
+ // src/run-tags.ts
23528
+ var slot = (route2, key) => `${route2}\0${key}`;
23529
+ async function resolveRunTags(refs, sourceFor) {
23530
+ const byRoute2 = /* @__PURE__ */ new Map();
23531
+ for (const r of refs) {
23532
+ if (!r.route) continue;
23533
+ const want = byRoute2.get(r.route) ?? { ids: /* @__PURE__ */ new Set(), keys: /* @__PURE__ */ new Set() };
23534
+ if (r.ticketRecordId) want.ids.add(r.ticketRecordId);
23535
+ if (r.ticket) want.keys.add(r.ticket);
23536
+ byRoute2.set(r.route, want);
23537
+ }
23538
+ const tags = /* @__PURE__ */ new Map();
23539
+ await Promise.all([...byRoute2].map(async ([route2, want]) => {
23540
+ const source = sourceFor(route2);
23541
+ if (!source) return;
23542
+ const found = [
23543
+ ...want.ids.size ? await source.ticketsByIds([...want.ids]).catch(() => []) : [],
23544
+ ...want.keys.size ? await source.ticketsByKeys([...want.keys]).catch(() => []) : []
23545
+ ];
23546
+ for (const t of found) tags.set(slot(route2, t.issue_id), displayKey(t));
23547
+ }));
23548
+ return (route2, key) => key ? (route2 ? tags.get(slot(route2, key)) : void 0) ?? key : null;
23549
+ }
23550
+
23401
23551
  // src/comment-delivery.ts
23402
23552
  import { basename as basename11 } from "path";
23403
23553
  var MESSAGE_MAX_CHARS = 4e3;
@@ -27787,7 +27937,7 @@ async function runAgentsSync(target, o) {
27787
27937
  }
27788
27938
 
27789
27939
  // src/logbook.ts
27790
- import { createHash as createHash9 } from "crypto";
27940
+ import { createHash as createHash10 } from "crypto";
27791
27941
  import { TablationClient as TablationClient4 } from "@tablation/client";
27792
27942
  var LogbookError = class extends Error {
27793
27943
  };
@@ -27892,7 +28042,7 @@ async function showLogEntry(route2, entryId, opts = {}) {
27892
28042
  };
27893
28043
  }
27894
28044
  const prompt = appendAdditions(match.prompt ?? "", match.prompt_additions);
27895
- const actualSha = createHash9("sha256").update(prompt).digest("hex");
28045
+ const actualSha = createHash10("sha256").update(prompt).digest("hex");
27896
28046
  const exact = !!entry.prompt_sha && actualSha === entry.prompt_sha;
27897
28047
  return {
27898
28048
  entry,
@@ -29180,7 +29330,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
29180
29330
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
29181
29331
  import { join as join60 } from "path";
29182
29332
  function builtVersion() {
29183
- return true ? "0.164.0" : null;
29333
+ return true ? "0.164.2" : null;
29184
29334
  }
29185
29335
  var REBUILD_HINT = "rebuild with npm run build";
29186
29336
  function newestMtime(path) {
@@ -29300,7 +29450,7 @@ function shipIdentityJson(s) {
29300
29450
  }
29301
29451
 
29302
29452
  // src/mcp-endpoint-registry.ts
29303
- import { createHash as createHash10 } from "crypto";
29453
+ import { createHash as createHash11 } from "crypto";
29304
29454
  function endpointsUrl(api, workspaceId, id) {
29305
29455
  const base = `${api.baseUrl.replace(/\/+$/, "")}/api/workspaces/${workspaceId}/mcp-endpoints`;
29306
29456
  return id ? `${base}/${id}` : base;
@@ -29370,7 +29520,7 @@ async function probeEndpointAccess(api, workspaceId) {
29370
29520
  }
29371
29521
  var REGISTER_MCP_ENDPOINTS_HINT = "give this key's role the REGISTER_MCP_ENDPOINTS capability, e.g. via the group that holds the Crew project role";
29372
29522
  function registrationKey(url, mcpSecret, controlUrl) {
29373
- return createHash10("sha256").update(`${url}
29523
+ return createHash11("sha256").update(`${url}
29374
29524
  ${mcpSecret ?? ""}
29375
29525
  ${controlUrl ?? ""}`).digest("hex").slice(0, 16);
29376
29526
  }
@@ -30040,7 +30190,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
30040
30190
  }
30041
30191
 
30042
30192
  // src/control-api.ts
30043
- import { createHash as createHash11 } from "crypto";
30193
+ import { createHash as createHash12 } from "crypto";
30044
30194
  import {
30045
30195
  chmodSync as chmodSync4,
30046
30196
  closeSync as closeSync7,
@@ -30309,7 +30459,7 @@ var ControlAuth = class {
30309
30459
  if (!token) return "unauthorized";
30310
30460
  for (const k of this.o.shipKeys()) if (k && secretsMatch(token, k)) return "ok";
30311
30461
  const now = (this.o.now ?? Date.now)();
30312
- const id = createHash11("sha256").update(token).digest("hex");
30462
+ const id = createHash12("sha256").update(token).digest("hex");
30313
30463
  const hit = this.cache.get(id);
30314
30464
  if (hit && now - hit.at < (this.o.cacheMs ?? 6e4)) return hit.verdict;
30315
30465
  const verdict = await this.ask(token);
@@ -30330,7 +30480,7 @@ var ControlAuth = class {
30330
30480
  for (const k of this.o.shipKeys()) if (k && secretsMatch(token, k)) return "ok";
30331
30481
  for (const k of this.o.workspaceSecrets?.(workspaceId) ?? []) if (k && secretsMatch(token, k)) return "ok";
30332
30482
  const now = (this.o.now ?? Date.now)();
30333
- const id = `${workspaceId}:${createHash11("sha256").update(token).digest("hex")}`;
30483
+ const id = `${workspaceId}:${createHash12("sha256").update(token).digest("hex")}`;
30334
30484
  const hit = this.cache.get(id);
30335
30485
  if (hit && now - hit.at < (this.o.cacheMs ?? 6e4)) return hit.verdict;
30336
30486
  const verdict = await this.ask(token, [workspaceId]);
@@ -37207,13 +37357,24 @@ ${where.join("\n")}`);
37207
37357
  (await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => [])).map((t) => [t.id, t.title ?? null])
37208
37358
  );
37209
37359
  const lastRuns = lastRunsBySeat(cfg.ship.stateDir);
37210
- const wantedKeys = [...new Set([...runs.map((x) => x.ticket), ...[...lastRuns.values()].map((l) => l.ticket)].filter((k) => !!k))];
37211
- const tagByKey = /* @__PURE__ */ new Map();
37212
- for (const t of [
37213
- ...await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => []),
37214
- ...await statusTracker.ticketsByKeys(wantedKeys).catch(() => [])
37215
- ]) tagByKey.set(t.issue_id, displayKey(t));
37216
- const tagOf = (k) => k ? tagByKey.get(k) ?? k : null;
37360
+ const thisSlug = routeSlug(route2.route);
37361
+ const otherSources = /* @__PURE__ */ new Map();
37362
+ const sourceFor = (slug2) => {
37363
+ if (slug2 === thisSlug) return statusTracker;
37364
+ if (!otherSources.has(slug2)) {
37365
+ const rt = cfg.routes.find((x) => routeSlug(x.route) === slug2);
37366
+ let t;
37367
+ try {
37368
+ t = rt ? new Tracker(rt, cfg.ship) : void 0;
37369
+ } catch (e) {
37370
+ if (!(e instanceof ConfigError)) throw e;
37371
+ }
37372
+ otherSources.set(slug2, t);
37373
+ }
37374
+ return otherSources.get(slug2);
37375
+ };
37376
+ const resolvedTag = await resolveRunTags([...runs, ...lastRuns.values()], sourceFor);
37377
+ const tagOf = (route3, k) => resolvedTag(route3, k);
37217
37378
  const periscopes = await periscopesForStatus(cfg.ship.stateDir);
37218
37379
  const runPreviews = new Map(periscopes.filter((p) => p.serving).map((p) => [p.ticketRecordId, p.url]));
37219
37380
  if (flag("json")) {
@@ -37241,7 +37402,7 @@ ${where.join("\n")}`);
37241
37402
  // Additive (CREW-2822): how many runs this seat has live right now.
37242
37403
  running: runs.filter((x) => x.role === r && x.route === routeSlug(route2.route)).length,
37243
37404
  // Additive (CREW-3247): this seat's newest finished run on this ship, or null.
37244
- lastRun: ((l) => l ? { ticket: tagOf(l.ticket), startedAt: l.startedAt, finishedAt: l.finishedAt, outcome: l.outcome, exitCode: l.exitCode } : null)(lastRuns.get(`${routeSlug(route2.route)}/${r}`))
37405
+ lastRun: ((l) => l ? { ticket: tagOf(l.route, l.ticket), startedAt: l.startedAt, finishedAt: l.finishedAt, outcome: l.outcome, exitCode: l.exitCode } : null)(lastRuns.get(`${routeSlug(route2.route)}/${r}`))
37245
37406
  };
37246
37407
  });
37247
37408
  process.stdout.write(`${JSON.stringify({
@@ -37291,7 +37452,7 @@ ${where.join("\n")}`);
37291
37452
  seats: seats2
37292
37453
  },
37293
37454
  // Additive (CREW-2822): every live run on this ship. `version` stays 1.
37294
- runs: runs.map((x) => describeRun(x, route2, seatIds, void 0, { titles: runTitles, previews: runPreviews, tags: tagByKey })),
37455
+ runs: runs.map((x) => describeRun(x, route2, seatIds, void 0, { titles: runTitles, previews: runPreviews, tags: new Map(x.ticket ? [[x.ticket, tagOf(x.route, x.ticket) ?? x.ticket]] : []) })),
37295
37456
  // Additive (CREW-2857): every live periscope on this ship, from its local record. `version` stays 1.
37296
37457
  periscopes,
37297
37458
  watermark: state.watermark(routeSlug(route2.route)),
@@ -37388,7 +37549,7 @@ ${where.join("\n")}`);
37388
37549
  });
37389
37550
  }
37390
37551
  const reloadWaitingAt = readReloadRequestedAt(cfg.ship.stateDir);
37391
- const lastRunView = [...lastRuns.values()].filter((l) => l.route === routeSlug(route2.route)).map((l) => ({ role: l.role, ticket: tagOf(l.ticket), finishedAt: l.finishedAt, outcome: l.outcome }));
37552
+ const lastRunView = [...lastRuns.values()].filter((l) => l.route === routeSlug(route2.route)).map((l) => ({ role: l.role, ticket: tagOf(l.route, l.ticket), finishedAt: l.finishedAt, outcome: l.outcome }));
37392
37553
  for (const line of renderStatus({
37393
37554
  ship: { name: cfg.ship.name, platform: cfg.ship.platform },
37394
37555
  route: { name: route2.route, dir: route2.dir, enabled: route2.enabled },
@@ -37403,7 +37564,7 @@ ${where.join("\n")}`);
37403
37564
  watermark: String(state.watermark(routeSlug(route2.route))),
37404
37565
  projects: projects.map((p) => p.label),
37405
37566
  reloadRequestedSecondsAgo: reloadWaitingAt === null ? null : Math.max(0, Math.round((Date.now() - reloadWaitingAt) / 1e3)),
37406
- runs: runs.map((x) => ({ role: x.role, ticket: tagOf(x.ticket), repo: x.repo, pid: x.pid, spawnedAt: x.spawnedAt, deadline: x.deadline })),
37567
+ runs: runs.map((x) => ({ role: x.role, ticket: tagOf(x.route, x.ticket), repo: x.repo, pid: x.pid, spawnedAt: x.spawnedAt, deadline: x.deadline })),
37407
37568
  lastRuns: lastRunView,
37408
37569
  attention: shipAttention.map((i) => ({ kind: i.kind, message: i.message, since: i.since })),
37409
37570
  waiting: todo.map((i) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.164.0",
3
+ "version": "0.164.2",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,6 +45,11 @@ person says so. **A missing worktree is never a reason to stop.**
45
45
  3. Otherwise `git worktree add <dir> -b <branch> <remote>/<base>` from the
46
46
  primary checkout, or `git worktree add <dir> <branch>` when
47
47
  `<remote>/<branch>` already exists (git creates the tracking branch).
48
+ When the branch already exists **locally** with no worktree (a QA run's
49
+ leftover, or an earlier run's), add the worktree on that branch and
50
+ fast-forward it to `<remote>/<branch>`; never create a branch under another
51
+ name for a ticket, because QA and the release phase find work by the
52
+ contract name only.
48
53
  The `-b <branch>` argument is required: omit it and git names the branch
49
54
  after the directory, which QA and the release phase cannot find. Before
50
55
  the first commit, check `git branch --show-current` against the digest's
@@ -45,6 +45,11 @@ person says so. **A missing worktree is never a reason to stop.**
45
45
  3. Otherwise `git worktree add <dir> -b <branch> <remote>/<base>` from the
46
46
  primary checkout, or `git worktree add <dir> <branch>` when
47
47
  `<remote>/<branch>` already exists (git creates the tracking branch).
48
+ When the branch already exists **locally** with no worktree (a QA run's
49
+ leftover, or an earlier run's), add the worktree on that branch and
50
+ fast-forward it to `<remote>/<branch>`; never create a branch under another
51
+ name for a ticket, because QA and the release phase find work by the
52
+ contract name only.
48
53
  The `-b <branch>` argument is required: omit it and git names the branch
49
54
  after the directory, which QA and the release phase cannot find. Before
50
55
  the first commit, check `git branch --show-current` against the digest's