@tablation/crew 0.164.1 → 0.164.3

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";
@@ -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
 
@@ -10344,13 +10345,15 @@ var Tracker = class _Tracker {
10344
10345
  *
10345
10346
  * `ticketRecordId` is the ticket's own row id (`Ticket.id`), not its
10346
10347
  * `issue_id` label — the field it fills is a Reference, not text.
10347
- * Omitted (as on the idle transition) leaves the column alone, so it
10348
- * keeps reading as "current/last issue" rather than clearing to blank
10349
- * the moment a run ends.
10348
+ * An idle seat has no current issue (CREW-3689): the idle write clears
10349
+ * the column in the same patch, so a stale pointer never reads as a stuck
10350
+ * seat. The last ticket a seat worked stays in the agent log. A working
10351
+ * write with no id leaves the column alone.
10350
10352
  */
10351
10353
  async setCrewStatus(memberId, status2, ticketRecordId) {
10352
10354
  const patch2 = { status: status2, status_updated_at: (/* @__PURE__ */ new Date()).toISOString() };
10353
- if (ticketRecordId !== void 0) patch2.current_issue_id = ticketRecordId;
10355
+ if (status2 === "idle") patch2.current_issue_id = null;
10356
+ else if (ticketRecordId !== void 0) patch2.current_issue_id = ticketRecordId;
10354
10357
  await this.client.records.update(this.models.crew, memberId, patch2);
10355
10358
  }
10356
10359
  /**
@@ -11503,27 +11506,69 @@ function repairMisnamedBranch(dir, cfg, ticket, role) {
11503
11506
  const base = [`${cfg.branch.remote}/${cfg.branch.base}`, cfg.branch.base].find((b) => gitOk(dir, ["rev-parse", "--verify", "-q", b]) !== null);
11504
11507
  const ahead = base ? Number(gitOk(dir, ["rev-list", "--count", `${base}..${from}`]) ?? "1") : 1;
11505
11508
  if (ahead === 0) return { kind: "none" };
11506
- if (existing) {
11509
+ if (existing) return repairBehindContractBranch(dir, wt.path, from, existing, expected, cfg.branch.remote);
11510
+ try {
11511
+ git(dir, ["branch", "-m", from, expected]);
11512
+ } catch (e) {
11507
11513
  return {
11508
11514
  kind: "refused",
11509
11515
  from,
11510
- to: existing,
11516
+ to: expected,
11511
11517
  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}\`)`
11518
+ reason: `the ticket's worktree is on \`${from}\`, not the expected \`${expected}\`, and renaming it failed: ${e.message}`
11519
+ };
11520
+ }
11521
+ return { kind: "renamed", from, to: expected };
11522
+ }
11523
+ function repairBehindContractBranch(dir, wtPath, from, to, expected, remote) {
11524
+ const head = headSha(wtPath);
11525
+ const toTip = gitOk(dir, ["rev-parse", "--verify", "-q", `refs/heads/${to}`]);
11526
+ const elsewhere = worktrees(dir).find((w) => w.branch === to && !w.prunable && !sameDir(w.path, wtPath));
11527
+ const named = to !== expected ? ` (expected name: \`${expected}\`)` : "";
11528
+ if (elsewhere) {
11529
+ return {
11530
+ kind: "refused",
11531
+ from,
11532
+ to,
11533
+ local: head,
11534
+ toTip,
11535
+ worktree: wtPath,
11536
+ 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}`,
11537
+ fix: `git -C ${elsewhere.path} switch --detach # or: git worktree remove ${elsewhere.path}`
11538
+ };
11539
+ }
11540
+ if (!head || !toTip || !isAncestor(dir, toTip, head)) {
11541
+ const counts = toTip && head ? gitOk(dir, ["rev-list", "--left-right", "--count", `${to}...${head}`])?.split(/\s+/).map(Number) : void 0;
11542
+ 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`;
11543
+ return {
11544
+ kind: "refused",
11545
+ from,
11546
+ to,
11547
+ local: head,
11548
+ toTip,
11549
+ worktree: wtPath,
11550
+ 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}`,
11551
+ fix: `git -C ${wtPath} merge ${to} # resolve any conflict, commit, run the suite`
11513
11552
  };
11514
11553
  }
11515
11554
  try {
11516
- git(dir, ["branch", "-m", from, expected]);
11555
+ git(dir, ["branch", "-f", to, head]);
11556
+ git(wtPath, ["switch", to]);
11517
11557
  } catch (e) {
11518
11558
  return {
11519
11559
  kind: "refused",
11520
11560
  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}`
11561
+ to,
11562
+ local: head,
11563
+ toTip,
11564
+ reason: `the ticket's worktree is on \`${from}\` at \`${head}\`; \`${to}\` is only behind it, but moving the worktree onto it failed: ${e.message}`,
11565
+ fix: `git -C ${wtPath} switch ${to}`,
11566
+ worktree: wtPath
11524
11567
  };
11525
11568
  }
11526
- return { kind: "renamed", from, to: expected };
11569
+ gitOk(wtPath, ["branch", "--set-upstream-to", `${remote}/${to}`, to]);
11570
+ gitOk(dir, ["branch", "-D", from]);
11571
+ return { kind: "renamed", from, to };
11527
11572
  }
11528
11573
  async function announceRename(i, ticketId, r, sha, remote, log) {
11529
11574
  let remoteNote;
@@ -11553,9 +11598,26 @@ function describeHandoffPush(dir, cfg, ticket, role) {
11553
11598
  const v = inspectHandoff(dir, cfg, ticket, role);
11554
11599
  return v.kind === "bounce" && pushableBounce(dir, v) ? `would push ${v.branch} to ${v.remote}` : null;
11555
11600
  }
11556
- function bounceComment(v, shipName2, pushError) {
11557
- return `${HANDOFF_BOUNCED_MARKER}
11601
+ function bounceSignature(...parts) {
11602
+ return createHash4("sha256").update(parts.map((p) => p ?? "").join("\n")).digest("hex").slice(0, 12);
11603
+ }
11604
+ var SIGNATURE_RE = /Bounce signature: `([0-9a-f]{12})`/;
11605
+ var signatureLine = (sig) => `Bounce signature: \`${sig}\``;
11606
+ function repeatParagraph(what, change) {
11607
+ 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
11608
 
11609
+ `;
11610
+ }
11611
+ function bounceComment(v, shipName2, pushError, repeat) {
11612
+ const again = repeat?.second ? repeatParagraph(
11613
+ `the local HEAD is still ${v.local ? `\`${v.local}\`` : "(no local branch)"} and \`${v.remote}\` is still ${v.origin ? `\`${v.origin}\`` : "(without the branch)"}`,
11614
+ `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.`
11615
+ ) : "";
11616
+ return `${HANDOFF_BOUNCED_MARKER}
11617
+ ${repeat ? `
11618
+ ${signatureLine(repeat.sig)}
11619
+ ` : ""}
11620
+ ${again}
11559
11621
  **Hand-off bounced: the branch is not on \`${v.remote}\` at the tip this ticket was built to.**
11560
11622
 
11561
11623
  ${shipName2 ? `Ship: ${shipName2}
@@ -11564,6 +11626,43 @@ ${shipName2 ? `Ship: ${shipName2}
11564
11626
 
11565
11627
  ${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
11628
  }
11629
+ function refusalComment(r, remote, remoteContractTip, shipName2, repeat) {
11630
+ const remoteLine = remoteContractTip === null ? "(could not be asked)" : remoteContractTip ? `\`${remoteContractTip}\`` : "(no such branch)";
11631
+ const again = repeat.second ? repeatParagraph(
11632
+ `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)"}`,
11633
+ `Run the commands below; handing off again without them leaves this exactly as it is.`
11634
+ ) : "";
11635
+ return `${HANDOFF_BOUNCED_MARKER}
11636
+
11637
+ ${signatureLine(repeat.sig)}
11638
+
11639
+ **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.**
11640
+
11641
+ ${shipName2 ? `Ship: ${shipName2}
11642
+ ` : ""}Worktree branch \`${r.from}\`: ${r.local ? `\`${r.local}\`` : "(unknown)"}
11643
+ Contract branch \`${r.to}\` (local): ${r.toTip ? `\`${r.toTip}\`` : "(not a local branch)"}
11644
+ \`${remote}/${r.to}\`: ${remoteLine}
11645
+
11646
+ ${again}${r.reason[0].toUpperCase()}${r.reason.slice(1)}.${r.fix ? `
11647
+
11648
+ Resolve it with:
11649
+
11650
+ \`\`\`
11651
+ ${r.fix}
11652
+ \`\`\`
11653
+
11654
+ 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.`;
11655
+ }
11656
+ async function identicalBounces(i, ticketRow, sig) {
11657
+ if (!i.writer.events) return 0;
11658
+ 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 ?? ""));
11659
+ let n = 0;
11660
+ for (const e of evs) {
11661
+ if (SIGNATURE_RE.exec(e.message ?? "")?.[1] !== sig) break;
11662
+ n++;
11663
+ }
11664
+ return n;
11665
+ }
11567
11666
  var NOTE_BUDGET = 4800;
11568
11667
  function boundNote(note, budget = NOTE_BUDGET) {
11569
11668
  if (note.length <= budget) return note;
@@ -11690,7 +11789,10 @@ async function enforceHandoff(i) {
11690
11789
  const repair = i.origin ? { kind: "none" } : repairMisnamedBranch(i.dir, i.cfg, t, i.role);
11691
11790
  const renamed = repair.kind === "renamed" ? repair : null;
11692
11791
  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);
11792
+ const refusal = repair.kind === "refused" ? repair : null;
11793
+ const refusedTip = refusal && !i.origin ? remoteTip(i.dir, i.cfg.branch.remote, refusal.to) : null;
11794
+ const mismatch = refusal && refusedTip && refusedTip === refusal.local ? refusal : null;
11795
+ 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
11796
  if (v.kind === "unverified") {
11695
11797
  i.log.warn(`${displayKey(t)} is at ${t.status} but the push was not checked: ${v.why}`, log);
11696
11798
  return { kind: "unverified", why: v.why };
@@ -11720,6 +11822,7 @@ async function enforceHandoff(i) {
11720
11822
  if (v.kind === "pushed") {
11721
11823
  await postPushed(i, t.id, v.sha, v.remote, v.branch, log);
11722
11824
  if (renamed) await announceRename(i, t.id, renamed, v.sha, v.remote, log);
11825
+ 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
11826
  i.log.emit(`${displayKey(t)} pushed at ${v.sha.slice(0, 7)} \u2014 handed on to QA`, log);
11724
11827
  return { kind: "pushed", sha: v.sha };
11725
11828
  }
@@ -11771,7 +11874,30 @@ async function enforceHandoff(i) {
11771
11874
  } else pushError = done.error;
11772
11875
  if (pushError) i.log.warn(`${displayKey(t)}: the runner's own push failed: ${pushError}`, log);
11773
11876
  }
11774
- if (!await deliverNote(i, t.id, bounceComment(v, i.shipName, pushError), "bounced", log)) {
11877
+ const sig = refusal ? bounceSignature("refused", refusal.from, refusal.to, refusal.local, refusal.toTip, v.origin) : bounceSignature(v.reason, v.branch, v.local, v.origin);
11878
+ const earlier = await identicalBounces(i, t.id, sig);
11879
+ if (earlier >= 2) {
11880
+ 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}\`` : ""}.`;
11881
+ const parked = `${HANDOFF_BOUNCED_MARKER}
11882
+
11883
+ **Parked: the same hand-off bounce happened ${earlier + 1} times in a row with nothing changing.**
11884
+
11885
+ ${diagnosis}
11886
+
11887
+ Needs a person to resolve the branch state above; set the status back to \`in_progress\` when done.`;
11888
+ if (await deliverNote(i, t.id, parked, "bounce_parked", log)) {
11889
+ await i.writer.updateTicket(t.id, {
11890
+ status: i.contract.statuses.needsHuman,
11891
+ assignee_id: i.parkTo ?? null,
11892
+ ...i.hold ? { [i.hold.column]: null } : {}
11893
+ });
11894
+ i.log.warn(`${displayKey(t)} parked for a person: the same hand-off bounce ${earlier + 1} times in a row`, log);
11895
+ return { kind: "bounced" };
11896
+ }
11897
+ }
11898
+ const repeat = { sig, second: earlier === 1 };
11899
+ const note = refusal ? refusalComment(refusal, v.remote, refusedTip, i.shipName, repeat) : bounceComment(v, i.shipName, pushError, repeat);
11900
+ if (!await deliverNote(i, t.id, note, "bounced", log)) {
11775
11901
  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
11902
  return { kind: "unverified", why: "the bounce note could not be posted" };
11777
11903
  }
@@ -11833,6 +11959,7 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
11833
11959
  cfg,
11834
11960
  seatId,
11835
11961
  shipName: ship.name,
11962
+ parkTo: route2.resolved?.operator,
11836
11963
  hold: affinity ? { column: affinity.column, shipId: affinity.shipId } : void 0,
11837
11964
  since: since2,
11838
11965
  log,
@@ -12887,7 +13014,7 @@ function seatNotesSection(notes) {
12887
13014
  }
12888
13015
 
12889
13016
  // src/sandbox-image.ts
12890
- import { createHash as createHash4 } from "crypto";
13017
+ import { createHash as createHash5 } from "crypto";
12891
13018
  import { spawn as spawn4 } from "child_process";
12892
13019
  import { execFileSync as execFileSync8 } from "child_process";
12893
13020
  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 +13055,7 @@ echo "password=$CREW_FORGE_TOKEN"
12928
13055
  `;
12929
13056
  var MCP_CONFIG = `${JSON.stringify({ mcpServers: {} }, null, 2)}
12930
13057
  `;
12931
- var hash = (parts) => createHash4("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 12);
13058
+ var hash = (parts) => createHash5("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 12);
12932
13059
  var slug = (s) => s.toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || "repo";
12933
13060
  var run2 = (cmd) => `RUN ["/bin/bash", "-c", ${JSON.stringify(`set -euo pipefail; ${cmd}`)}]`;
12934
13061
  var CREW_ENV = {
@@ -14104,7 +14231,7 @@ function skillMarkerWarnings(promptsDir, personaPrompts) {
14104
14231
  // src/runner.ts
14105
14232
  import { spawn as spawn5, execFile, execFileSync as execFileSync9 } from "child_process";
14106
14233
  import { mkdtempSync, mkdirSync as mkdirSync21, writeFileSync as writeFileSync22, rmSync as rmSync17 } from "fs";
14107
- import { createHash as createHash5 } from "crypto";
14234
+ import { createHash as createHash6 } from "crypto";
14108
14235
  import { tmpdir as tmpdir4 } from "os";
14109
14236
  import { basename as basename8, dirname as dirname16, join as join33 } from "path";
14110
14237
  import { promisify } from "util";
@@ -14200,7 +14327,7 @@ function shQuote2(s) {
14200
14327
  return `'${s.replace(/'/g, `'\\''`)}'`;
14201
14328
  }
14202
14329
  function sandboxName(plan, now = Date.now()) {
14203
- const h = createHash5("sha256").update([plan.route, plan.role, plan.ticket ?? ""].join("\0")).digest();
14330
+ const h = createHash6("sha256").update([plan.route, plan.role, plan.ticket ?? ""].join("\0")).digest();
14204
14331
  const tag = (h.readUInt32BE(0) % 36 ** 6).toString(36).padStart(6, "0");
14205
14332
  return `crew-${tag}${now.toString(36).slice(-8).padStart(8, "0")}`;
14206
14333
  }
@@ -14620,7 +14747,7 @@ function planAgentRun(o) {
14620
14747
  brief: expanded.text,
14621
14748
  digest
14622
14749
  });
14623
- const promptSha = createHash6("sha256").update(expanded.text).digest("hex");
14750
+ const promptSha = createHash7("sha256").update(expanded.text).digest("hex");
14624
14751
  const streamsDir = join34(o.stateDir, "streams");
14625
14752
  const base = `${routeLabel2}-${o.role}-${o.cycle}${o.runId ? `-${o.runId}` : ""}`;
14626
14753
  const seat = resolveSeat(o.ship, o.route, o.role, o.agentPersona ?? (o.agentModel ? { model: o.agentModel } : {}), o.repo);
@@ -15756,6 +15883,27 @@ async function settleRunEnd(o) {
15756
15883
  emit.warn(`could not beat ship idle: ${e.message}`, { step: "agent" });
15757
15884
  }
15758
15885
  }
15886
+ function staleIdleSeats(route2, crewRows, runs) {
15887
+ const slug2 = routeSlug(route2.route);
15888
+ const out = [];
15889
+ for (const [role, memberId] of Object.entries(route2.resolved?.seats ?? {})) {
15890
+ if (!memberId) continue;
15891
+ const row = crewRows.find((r) => r.id === memberId);
15892
+ if (!row?.current_issue_id || row.status === "working") continue;
15893
+ if (runs.some((r) => r.role === role && r.route === slug2)) continue;
15894
+ out.push({ role, memberId });
15895
+ }
15896
+ return out;
15897
+ }
15898
+ async function clearStaleIdleSeats(tracker, route2, crewRows, runs, emit) {
15899
+ for (const s of staleIdleSeats(route2, crewRows, runs)) {
15900
+ try {
15901
+ await tracker.setCrewStatus(s.memberId, "idle");
15902
+ } catch (e) {
15903
+ emit.warn(`could not clear ${s.role} seat's current issue: ${e.message}`, { step: "poll" });
15904
+ }
15905
+ }
15906
+ }
15759
15907
  function pidAlive2(pid) {
15760
15908
  try {
15761
15909
  process.kill(pid, 0);
@@ -16344,12 +16492,12 @@ function containerNameFor(workspaceId) {
16344
16492
  return `crew-passenger-${workspaceId}`;
16345
16493
  }
16346
16494
  function portFor(workspaceId, base = 28765, span = 1e3) {
16347
- const digest = createHash7("sha256").update(workspaceId).digest();
16495
+ const digest = createHash8("sha256").update(workspaceId).digest();
16348
16496
  return base + digest.readUInt32BE(0) % span;
16349
16497
  }
16350
16498
  function mountsDigest(mounts, image) {
16351
16499
  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);
16500
+ return createHash8("sha256").update(JSON.stringify({ mounts: sorted2, image })).digest("hex").slice(0, 16);
16353
16501
  }
16354
16502
  function planContainers(cfg) {
16355
16503
  const byWorkspace = /* @__PURE__ */ new Map();
@@ -17850,13 +17998,13 @@ import { hostname as hostname3 } from "os";
17850
17998
 
17851
17999
  // src/machine-id.ts
17852
18000
  import { execFileSync as execFileSync12 } from "child_process";
17853
- import { createHash as createHash8 } from "crypto";
18001
+ import { createHash as createHash9 } from "crypto";
17854
18002
  import { existsSync as existsSync36, mkdirSync as mkdirSync27, readFileSync as readFileSync38, writeFileSync as writeFileSync29 } from "fs";
17855
18003
  import { dirname as dirname21, join as join42 } from "path";
17856
18004
  function machineIdPathFor(stateDir) {
17857
18005
  return join42(stateDir, "machine-id");
17858
18006
  }
17859
- var sha256 = (s) => createHash8("sha256").update(s).digest("hex");
18007
+ var sha256 = (s) => createHash9("sha256").update(s).digest("hex");
17860
18008
  function readRawMachineId(platform2 = process.platform) {
17861
18009
  try {
17862
18010
  if (platform2 === "darwin") {
@@ -20044,6 +20192,7 @@ async function decideCycle(o) {
20044
20192
  tracker.crewRows(),
20045
20193
  optional("project work modes", tracker.projectWorkModes(), /* @__PURE__ */ new Map())
20046
20194
  ]);
20195
+ await clearStaleIdleSeats(tracker, route2, crewRows, liveRuns(state.dir), emit);
20047
20196
  const scopeHolds = new Set(holdIds(buildRoster(configuredMembers(route2), crewRows)));
20048
20197
  const scope = {
20049
20198
  modes: projectModes,
@@ -27812,7 +27961,7 @@ async function runAgentsSync(target, o) {
27812
27961
  }
27813
27962
 
27814
27963
  // src/logbook.ts
27815
- import { createHash as createHash9 } from "crypto";
27964
+ import { createHash as createHash10 } from "crypto";
27816
27965
  import { TablationClient as TablationClient4 } from "@tablation/client";
27817
27966
  var LogbookError = class extends Error {
27818
27967
  };
@@ -27917,7 +28066,7 @@ async function showLogEntry(route2, entryId, opts = {}) {
27917
28066
  };
27918
28067
  }
27919
28068
  const prompt = appendAdditions(match.prompt ?? "", match.prompt_additions);
27920
- const actualSha = createHash9("sha256").update(prompt).digest("hex");
28069
+ const actualSha = createHash10("sha256").update(prompt).digest("hex");
27921
28070
  const exact = !!entry.prompt_sha && actualSha === entry.prompt_sha;
27922
28071
  return {
27923
28072
  entry,
@@ -29205,7 +29354,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
29205
29354
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
29206
29355
  import { join as join60 } from "path";
29207
29356
  function builtVersion() {
29208
- return true ? "0.164.1" : null;
29357
+ return true ? "0.164.3" : null;
29209
29358
  }
29210
29359
  var REBUILD_HINT = "rebuild with npm run build";
29211
29360
  function newestMtime(path) {
@@ -29325,7 +29474,7 @@ function shipIdentityJson(s) {
29325
29474
  }
29326
29475
 
29327
29476
  // src/mcp-endpoint-registry.ts
29328
- import { createHash as createHash10 } from "crypto";
29477
+ import { createHash as createHash11 } from "crypto";
29329
29478
  function endpointsUrl(api, workspaceId, id) {
29330
29479
  const base = `${api.baseUrl.replace(/\/+$/, "")}/api/workspaces/${workspaceId}/mcp-endpoints`;
29331
29480
  return id ? `${base}/${id}` : base;
@@ -29395,7 +29544,7 @@ async function probeEndpointAccess(api, workspaceId) {
29395
29544
  }
29396
29545
  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";
29397
29546
  function registrationKey(url, mcpSecret, controlUrl) {
29398
- return createHash10("sha256").update(`${url}
29547
+ return createHash11("sha256").update(`${url}
29399
29548
  ${mcpSecret ?? ""}
29400
29549
  ${controlUrl ?? ""}`).digest("hex").slice(0, 16);
29401
29550
  }
@@ -30065,7 +30214,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
30065
30214
  }
30066
30215
 
30067
30216
  // src/control-api.ts
30068
- import { createHash as createHash11 } from "crypto";
30217
+ import { createHash as createHash12 } from "crypto";
30069
30218
  import {
30070
30219
  chmodSync as chmodSync4,
30071
30220
  closeSync as closeSync7,
@@ -30334,7 +30483,7 @@ var ControlAuth = class {
30334
30483
  if (!token) return "unauthorized";
30335
30484
  for (const k of this.o.shipKeys()) if (k && secretsMatch(token, k)) return "ok";
30336
30485
  const now = (this.o.now ?? Date.now)();
30337
- const id = createHash11("sha256").update(token).digest("hex");
30486
+ const id = createHash12("sha256").update(token).digest("hex");
30338
30487
  const hit = this.cache.get(id);
30339
30488
  if (hit && now - hit.at < (this.o.cacheMs ?? 6e4)) return hit.verdict;
30340
30489
  const verdict = await this.ask(token);
@@ -30355,7 +30504,7 @@ var ControlAuth = class {
30355
30504
  for (const k of this.o.shipKeys()) if (k && secretsMatch(token, k)) return "ok";
30356
30505
  for (const k of this.o.workspaceSecrets?.(workspaceId) ?? []) if (k && secretsMatch(token, k)) return "ok";
30357
30506
  const now = (this.o.now ?? Date.now)();
30358
- const id = `${workspaceId}:${createHash11("sha256").update(token).digest("hex")}`;
30507
+ const id = `${workspaceId}:${createHash12("sha256").update(token).digest("hex")}`;
30359
30508
  const hit = this.cache.get(id);
30360
30509
  if (hit && now - hit.at < (this.o.cacheMs ?? 6e4)) return hit.verdict;
30361
30510
  const verdict = await this.ask(token, [workspaceId]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.164.1",
3
+ "version": "0.164.3",
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