@tablation/crew 0.165.1 → 0.166.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3592,6 +3592,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
3592
3592
  "verify",
3593
3593
  "isolateFailures",
3594
3594
  "rightOfWayMinutes",
3595
+ "rebuildPrimary",
3595
3596
  "versioning",
3596
3597
  "versionFiles",
3597
3598
  "changelog",
@@ -3604,6 +3605,11 @@ var VERIFY_KEYS = /* @__PURE__ */ new Set(["match", "timeoutSeconds", "intervalS
3604
3605
  var ISOLATE_KEYS = /* @__PURE__ */ new Set(["maxCandidates"]);
3605
3606
  var DEFAULT_ISOLATE_MAX_CANDIDATES = 4;
3606
3607
  var DEFAULT_RIGHT_OF_WAY_MINUTES = 60;
3608
+ function parseRebuildPrimary(raw, fail2) {
3609
+ if (raw === void 0 || raw === null) return void 0;
3610
+ if (typeof raw !== "boolean") throw fail2(`release.rebuildPrimary must be true or false (got "${raw}")`);
3611
+ return raw;
3612
+ }
3607
3613
  function parseRightOfWayMinutes(raw, fail2) {
3608
3614
  if (raw === void 0 || raw === null) return void 0;
3609
3615
  const n = Number(raw);
@@ -3835,6 +3841,7 @@ function parseRepoConfig(text2, file) {
3835
3841
  (m) => new RepoConfigError(`${file}: ${m}`)
3836
3842
  );
3837
3843
  const rightOfWay = parseRightOfWayMinutes(raw.release?.rightOfWayMinutes, (m) => new RepoConfigError(`${file}: ${m}`));
3844
+ const rebuildPrimary = parseRebuildPrimary(raw.release?.rebuildPrimary, (m) => new RepoConfigError(`${file}: ${m}`));
3838
3845
  const versioning = String(raw.release?.versioning ?? "auto");
3839
3846
  if (!VERSIONINGS.includes(versioning)) {
3840
3847
  throw new RepoConfigError(`${file}: release.versioning must be auto|none (got "${versioning}")`);
@@ -3913,6 +3920,7 @@ function parseRepoConfig(text2, file) {
3913
3920
  verify,
3914
3921
  isolateFailures: isolateMax === void 0 ? void 0 : { maxCandidates: isolateMax },
3915
3922
  rightOfWayMinutes: rightOfWay,
3923
+ rebuildPrimary,
3916
3924
  versioning,
3917
3925
  versionFiles,
3918
3926
  tag,
@@ -4124,6 +4132,7 @@ function resolveRepoConfig(repo, ship, dir) {
4124
4132
  )
4125
4133
  },
4126
4134
  rightOfWayMinutes: repo?.release.rightOfWayMinutes ?? ship?.release?.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES,
4135
+ rebuildPrimary: repo?.release.rebuildPrimary ?? false,
4127
4136
  versioning: pick(
4128
4137
  "release.versioning",
4129
4138
  repo?.release.versioning === "auto" ? void 0 : repo?.release.versioning,
@@ -9568,8 +9577,9 @@ import { StaleWriteError } from "@tablation/client";
9568
9577
  function releaseLockScope(route2, repo) {
9569
9578
  return `${route2}/${repo}`;
9570
9579
  }
9571
- async function acquireBoardLock(client2, modelId, scope, holderLabel, ttlMs, log = {}) {
9580
+ async function acquireBoardLock(client2, modelId, scope, holderLabel, ttlMs, log = {}, renewEveryMs = DEFAULT_RENEW_EVERY_MS) {
9572
9581
  if (!modelId) return { ok: true, release: async () => {
9582
+ }, stillHeld: async () => true, renew: async () => {
9573
9583
  }, exclusion: "off" };
9574
9584
  const filters = JSON.stringify([{ columnName: "scope", operator: "EQ", value: scope }]);
9575
9585
  const rows = await client2.list(modelId, { filters, limit: 1 });
@@ -9587,13 +9597,58 @@ async function acquireBoardLock(client2, modelId, scope, holderLabel, ttlMs, log
9587
9597
  if (e instanceof StaleWriteError) return { ok: false, reason: "contended" };
9588
9598
  throw e;
9589
9599
  }
9600
+ let current = claimed.updated_at;
9601
+ let lost = false;
9602
+ let stopped = false;
9603
+ let renewing = false;
9604
+ const renew = async () => {
9605
+ if (stopped || lost || renewing) return;
9606
+ renewing = true;
9607
+ try {
9608
+ try {
9609
+ current = (await client2.update(modelId, row.id, { holder: holderLabel }, current)).updated_at;
9610
+ } catch (e) {
9611
+ if (!(e instanceof StaleWriteError)) throw e;
9612
+ const [now] = await client2.list(modelId, { filters: scopeFilter(scope), limit: 1 });
9613
+ if (now?.holder !== holderLabel) {
9614
+ lost = true;
9615
+ log.warn?.(`board lock ${scope} was taken by ${now?.holder || "another ship"} while this release was running`);
9616
+ return;
9617
+ }
9618
+ current = (await client2.update(modelId, row.id, { holder: holderLabel }, now.updated_at)).updated_at;
9619
+ }
9620
+ } catch (e) {
9621
+ log.warn?.(`lock renewal failed for ${scope}: ${e.message}; will retry`);
9622
+ } finally {
9623
+ renewing = false;
9624
+ }
9625
+ };
9626
+ const timer = setInterval(() => {
9627
+ void renew();
9628
+ }, renewEveryMs);
9629
+ timer.unref();
9590
9630
  return {
9591
9631
  ok: true,
9592
9632
  exclusion: "taken",
9633
+ renew,
9634
+ stillHeld: async () => {
9635
+ if (lost) return false;
9636
+ try {
9637
+ const [now] = await client2.list(modelId, { filters: scopeFilter(scope), limit: 1 });
9638
+ if (now?.holder === holderLabel) return true;
9639
+ lost = true;
9640
+ return false;
9641
+ } catch (e) {
9642
+ log.warn?.(`could not confirm board lock ${scope} is still held: ${e.message}`);
9643
+ return true;
9644
+ }
9645
+ },
9593
9646
  release: async () => {
9647
+ stopped = true;
9648
+ clearInterval(timer);
9594
9649
  try {
9595
9650
  try {
9596
- await client2.update(modelId, row.id, { holder: "" }, claimed.updated_at);
9651
+ await client2.update(modelId, row.id, { holder: "" }, current);
9597
9652
  } catch (e) {
9598
9653
  if (!(e instanceof StaleWriteError)) throw e;
9599
9654
  const [now] = await client2.list(modelId, { filters: scopeFilter(scope), limit: 1 });
@@ -9606,6 +9661,7 @@ async function acquireBoardLock(client2, modelId, scope, holderLabel, ttlMs, log
9606
9661
  }
9607
9662
  };
9608
9663
  }
9664
+ var DEFAULT_RENEW_EVERY_MS = 3 * 60 * 1e3;
9609
9665
  function isDeadOwnClaim(holder, mine) {
9610
9666
  const split = (l) => {
9611
9667
  const i = l.lastIndexOf(":");
@@ -10331,8 +10387,8 @@ var Tracker = class _Tracker {
10331
10387
  * Locks table with no row for `scope` is `{ ok: false, reason: 'missing' }`
10332
10388
  * (CREW-1384): `crew connect` provisions the row.
10333
10389
  */
10334
- acquireBoardLock(scope, holderLabel, ttlMs, log) {
10335
- return acquireBoardLock(this.client.records, this.route.resolved?.locksModelId, scope, holderLabel, ttlMs, log);
10390
+ acquireBoardLock(scope, holderLabel, ttlMs, log, renewEveryMs) {
10391
+ return acquireBoardLock(this.client.records, this.route.resolved?.locksModelId, scope, holderLabel, ttlMs, log, renewEveryMs);
10336
10392
  }
10337
10393
  /** The Locks row for `scope` — present? held by whom? Undefined when this workspace has no Locks table. */
10338
10394
  async lockState(scope) {
@@ -22022,9 +22078,29 @@ async function applyMergeStamp(tracker, merged, tickets, emit, dryRun, cwd) {
22022
22078
  }
22023
22079
  return stamped;
22024
22080
  }
22025
- async function applyStamp(tracker, plan, version, contract, emit, dryRun, cwd) {
22081
+ var RELEASE_CLAIMED_EVENT = "release_claimed";
22082
+ async function priorAssignees(tracker, plan, seat, contract, emit) {
22083
+ const out = /* @__PURE__ */ new Map();
22084
+ if (!plan.length) return out;
22085
+ try {
22086
+ const fresh = await tracker.ticketsByIds(plan.map((p) => p.ticket.id));
22087
+ const held = fresh.filter((t) => t[contract.columns.assignee] === seat);
22088
+ if (!held.length) return out;
22089
+ const events = await tracker.events(RELEASE_CLAIMED_EVENT);
22090
+ for (const t of held) {
22091
+ const e = events.find((x) => x.record_id === t.id);
22092
+ const prior = e?.metadata?.prior_assignee;
22093
+ out.set(t.id, typeof prior === "string" && prior !== seat ? prior : null);
22094
+ }
22095
+ } catch (e) {
22096
+ emit.warn(`could not read who held the tickets before the release: ${e.message}`);
22097
+ }
22098
+ return out;
22099
+ }
22100
+ async function applyStamp(tracker, plan, version, contract, emit, dryRun, cwd, seat) {
22026
22101
  let stamped = 0;
22027
22102
  const at = (/* @__PURE__ */ new Date()).toISOString();
22103
+ const priorAssignee = !dryRun && seat ? await priorAssignees(tracker, plan, seat, contract, emit) : /* @__PURE__ */ new Map();
22028
22104
  for (const { ticket, sha } of plan) {
22029
22105
  const shaNote = sha ? `, commit_sha ${sha.slice(0, 8)}` : "";
22030
22106
  if (dryRun) {
@@ -22038,6 +22114,7 @@ async function applyStamp(tracker, plan, version, contract, emit, dryRun, cwd) {
22038
22114
  try {
22039
22115
  await tracker.updateTicket(ticket.id, {
22040
22116
  status: contract.statuses.deployed,
22117
+ ...priorAssignee.has(ticket.id) ? { [contract.columns.assignee]: priorAssignee.get(ticket.id) ?? null } : {},
22041
22118
  // `released_at` is always a real release moment here; only the version is optional (versioning: none).
22042
22119
  released_at: at,
22043
22120
  ...version ? { released_version: version } : {},
@@ -22457,7 +22534,12 @@ function looksLikeTransientResolveFailure(output) {
22457
22534
  const realBuildError = /(TS\d{4}:|SyntaxError|error TS|Cannot find module '\.)/;
22458
22535
  return resolveFailure.test(output) && !realBuildError.test(output);
22459
22536
  }
22537
+ var HOOK_NO_RETRY_EXIT_CODE = 86;
22460
22538
  async function rerunOnce(o, name, first) {
22539
+ if (first.code === HOOK_NO_RETRY_EXIT_CODE) {
22540
+ o.emit.warn(`${name} gate reported a failure that a rerun cannot fix (exit ${HOOK_NO_RETRY_EXIT_CODE}) \u2014 not rerunning`);
22541
+ return first;
22542
+ }
22461
22543
  o.emit.warn(`${name} gate failed \u2014 rerunning once on the same composition before blaming a branch`);
22462
22544
  const again = await hook(o, name);
22463
22545
  if (!again || again.code !== 0) return again ?? first;
@@ -23099,18 +23181,23 @@ async function runReleaseCycle(o, movedPast2, localRefSkips, rightOfWay) {
23099
23181
  o.emit.error(scoped(`could not cut a release checkout from ${remote}/${base} \u2014 ${e.message}`));
23100
23182
  return { merged: [], deployed: false, stopped: "release checkout failed", decision };
23101
23183
  }
23184
+ let outcome;
23185
+ let rebuild;
23102
23186
  try {
23103
- return await mergeAndRelease({ ...o, cwd: checkout.dir }, decision, fresh, checkout.branch);
23187
+ outcome = await mergeAndRelease({ ...o, cwd: checkout.dir }, decision, fresh, checkout.branch);
23104
23188
  } finally {
23105
23189
  checkout.close();
23106
23190
  const refreshed = refreshBaseBranch(o.cwd, remote, base);
23107
- if (refreshed.action === "fast-forwarded" && o.repo.hooks.build) {
23108
- const r = await hook(o, "build");
23109
- if (r && r.code !== 0) {
23110
- o.emit.warn(scoped(`rebuilding the primary checkout after the release failed (exit ${r.code}) \u2014 its dist/ is stale until \`${o.repo.hooks.build}\` is run there`));
23111
- }
23191
+ if (refreshed.action === "fast-forwarded" && o.repo.hooks.build && o.repo.release.rebuildPrimary) {
23192
+ rebuild = async () => {
23193
+ const r = await hook(o, "build");
23194
+ if (r && r.code !== 0) {
23195
+ o.emit.warn(scoped(`rebuilding the primary checkout after the release failed (exit ${r.code}) \u2014 its dist/ is stale until \`${o.repo.hooks.build}\` is run there`));
23196
+ }
23197
+ };
23112
23198
  }
23113
23199
  }
23200
+ return rebuild ? { ...outcome, primaryRebuild: rebuild } : outcome;
23114
23201
  }
23115
23202
  var MAX_ISOLATE_PAIRS = 10;
23116
23203
  function pairOrder(n, max = MAX_ISOLATE_PAIRS) {
@@ -23308,7 +23395,21 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23308
23395
  }
23309
23396
  continue;
23310
23397
  }
23398
+ if (o.onClaim && !o.dryRun) {
23399
+ try {
23400
+ await o.onClaim(c.ticket);
23401
+ } catch (e) {
23402
+ o.emit.warn(`could not assign the ticket to the release seat: ${e.message}`, { ticket: c.ticket.issue_id });
23403
+ }
23404
+ }
23311
23405
  const r = mergeOne(o, c);
23406
+ if (o.onUnclaim && !o.dryRun && typeof r === "object" && ("conflict" in r || "error" in r)) {
23407
+ try {
23408
+ await o.onUnclaim(c.ticket);
23409
+ } catch (e) {
23410
+ o.emit.warn(`could not hand the ticket back from the release seat: ${e.message}`, { ticket: c.ticket.issue_id });
23411
+ }
23412
+ }
23312
23413
  if (typeof r === "object" && "conflict" in r) {
23313
23414
  conflicts.push(r.conflict);
23314
23415
  continue;
@@ -23499,6 +23600,10 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23499
23600
  }
23500
23601
  }
23501
23602
  }
23603
+ if (!o.dryRun && o.stillHoldsLock && !await o.stillHoldsLock()) {
23604
+ o.emit.error("the board lock is no longer held by this release \u2014 not pushing or deploying; the tickets stay verified");
23605
+ return { merged, conflicts, unbuildable, version, deployed: false, decision, stopped: "release lock lost" };
23606
+ }
23502
23607
  if (remoteConfigured(o.cwd, o.repo.branch.remote)) {
23503
23608
  if (o.dryRun) {
23504
23609
  o.emit.emit(`would push ${o.repo.branch.base} to ${o.repo.branch.remote}`);
@@ -23537,7 +23642,10 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23537
23642
  integrated = true;
23538
23643
  } else if (o.repo.release.mode === "local" && o.repo.hooks.deploy) {
23539
23644
  if (o.dryRun) o.emit.emit(`would run: ${hookLabel(o.repo, "deploy")}`);
23540
- else {
23645
+ else if (o.stillHoldsLock && !await o.stillHoldsLock()) {
23646
+ o.emit.error("the board lock is no longer held by this release \u2014 not deploying; run `crew deploy` once the other release has finished");
23647
+ return { merged, conflicts, unbuildable, version, deployed: false, decision, stopped: "release lock lost" };
23648
+ } else {
23541
23649
  let r = await hook(o, "deploy");
23542
23650
  if (r && r.code !== 0 && looksLikeTransientResolveFailure(r.output)) {
23543
23651
  o.emit.warn("deploy failed with what looks like a transient dependency-resolution glitch, not a real failure \u2014 retrying once");
@@ -23596,6 +23704,33 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23596
23704
  );
23597
23705
  return { merged, conflicts, unbuildable, version, tag, deployed, integrated, confirmed, decision, ...ciOutcome(o, watch2, confirmed) };
23598
23706
  }
23707
+ var MAX_CONSECUTIVE_RELEASE_PASSES = 5;
23708
+ var RELEASED_OUTCOMES = /* @__PURE__ */ new Set(["deployed", "merged", "integrated"]);
23709
+ async function runFleetPasses(deps) {
23710
+ const cap = deps.cap ?? MAX_CONSECUTIVE_RELEASE_PASSES;
23711
+ let passes = 0;
23712
+ let only;
23713
+ for (; ; ) {
23714
+ const results = await deps.pass(only);
23715
+ passes++;
23716
+ const released = results.filter((r) => RELEASED_OUTCOMES.has(r.summary.outcome));
23717
+ if (released.length === 0 || deps.refused()) return passes;
23718
+ const next = [];
23719
+ for (const r of released) {
23720
+ const count = await deps.waiting(r.key);
23721
+ if (count > 0) next.push({ key: r.key, count });
23722
+ }
23723
+ if (next.length === 0) return passes;
23724
+ if (passes >= cap) {
23725
+ deps.emit(`release: ${cap} consecutive passes run with verified tickets still waiting \u2014 leaving the rest to the timer`);
23726
+ return passes;
23727
+ }
23728
+ for (const n of next) {
23729
+ deps.emit(`release: repeating ${deps.describe(n.key)} \u2014 ${n.count} verified ticket${n.count === 1 ? "" : "s"} waiting`);
23730
+ }
23731
+ only = next.map((n) => n.key);
23732
+ }
23733
+ }
23599
23734
 
23600
23735
  // src/failure-alert.ts
23601
23736
  var FAILURE_ALERT_MARKER = calloutHeader("CAUTION", "Failure Alert");
@@ -28023,8 +28158,9 @@ import { existsSync as existsSync52, readFileSync as readFileSync50 } from "fs";
28023
28158
  import { join as join56 } from "path";
28024
28159
  var IMAGE_TYPES = { png: "image/png", svg: "image/svg+xml" };
28025
28160
  function personaAvatarFile(promptsDir, role) {
28161
+ const stem = role === "release" ? "release-agent" : `lane-${role}`;
28026
28162
  for (const ext of ["png", "svg"]) {
28027
- const name = `lane-${role}.${ext}`;
28163
+ const name = `${stem}.${ext}`;
28028
28164
  const path = join56(promptsDir, "personas", name);
28029
28165
  if (existsSync52(path)) return { path, mimeType: IMAGE_TYPES[ext], name };
28030
28166
  }
@@ -28034,9 +28170,12 @@ async function syncPersonaAvatars(route2, agentPersonas, opts) {
28034
28170
  if (!route2.resolved) return [];
28035
28171
  const base = `${route2.baseUrl.replace(/\/+$/, "")}/api/workspaces/${route2.resolved.workspaceId}/agents/personas`;
28036
28172
  const outcomes = [];
28037
- for (const role of ROLE_NAMES) {
28173
+ const targets = [
28174
+ ...ROLE_NAMES.map((role) => ({ role, agentId: agentPersonas[role]?.agentId })),
28175
+ { role: "release", agentId: opts.releaseAgentId }
28176
+ ];
28177
+ for (const { role, agentId } of targets) {
28038
28178
  const file = personaAvatarFile(route2.promptsDir, role);
28039
- const agentId = agentPersonas[role]?.agentId;
28040
28179
  if (!file || !agentId) continue;
28041
28180
  try {
28042
28181
  const form = new FormData();
@@ -28124,8 +28263,8 @@ async function runAgentsSync(target, o) {
28124
28263
  for (const w of skillResult?.warnings ?? []) o.warn(`warning: ${w}`);
28125
28264
  const avatarFailures2 = {};
28126
28265
  if (!readOnly2 && !dryRun) {
28127
- for (const a of await syncPersonaAvatars(target, personaResult.agentPersonas, { userAgent: o.userAgent })) {
28128
- const line = describeAvatarOutcome(a, PERSONA_NAME[a.role]);
28266
+ for (const a of await syncPersonaAvatars(target, personaResult.agentPersonas, { userAgent: o.userAgent, releaseAgentId: personaResult.releaseAgentId })) {
28267
+ const line = describeAvatarOutcome(a, a.role === "release" ? RELEASE_AGENT_NAME : PERSONA_NAME[a.role]);
28129
28268
  if (a.status === "failed") {
28130
28269
  o.warn(`warning: ${line}`);
28131
28270
  avatarFailures2[a.role] = a.detail ?? "unknown error";
@@ -29548,7 +29687,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
29548
29687
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
29549
29688
  import { join as join61 } from "path";
29550
29689
  function builtVersion() {
29551
- return true ? "0.165.1" : null;
29690
+ return true ? "0.166.0" : null;
29552
29691
  }
29553
29692
  var REBUILD_HINT = "rebuild with npm run build";
29554
29693
  function newestMtime(path) {
@@ -32607,16 +32746,43 @@ if (command === "passenger-sync-daemon") {
32607
32746
  }
32608
32747
  async function releaseFleet(opts = {}) {
32609
32748
  sweepStateDir();
32610
- if (releaseRefused()) return;
32611
- precheckTickets.clear();
32612
- const summaries = [];
32613
- if (!dryRun) state.releaseHeartbeat().touch();
32614
- for (const c of cfg.routes) {
32615
- if (!dryRun && !c.enabled) continue;
32616
- for (const r of reposOf(c)) summaries.push({ ...await releasePhase(c, r, opts), route: c.route });
32617
- }
32618
- emitReleaseSummary(emit, summaries);
32619
- if (!dryRun) state.releaseHeartbeat().touch();
32749
+ const keyOf = (k) => `${k.c.route}\0${k.r.name}`;
32750
+ await runFleetPasses({
32751
+ pass: async (only) => {
32752
+ if (!only && releaseRefused()) return [];
32753
+ precheckTickets.clear();
32754
+ const wanted = only ? new Set(only.map(keyOf)) : void 0;
32755
+ const summaries = [];
32756
+ const results = [];
32757
+ if (!dryRun) state.releaseHeartbeat().touch();
32758
+ for (const c of cfg.routes) {
32759
+ if (!dryRun && !c.enabled) continue;
32760
+ for (const r of reposOf(c)) {
32761
+ if (wanted && !wanted.has(keyOf({ c, r }))) continue;
32762
+ const summary = await releasePhase(c, r, opts);
32763
+ summaries.push({ ...summary, route: c.route });
32764
+ results.push({ key: { c, r }, summary });
32765
+ }
32766
+ }
32767
+ emitReleaseSummary(emit, summaries);
32768
+ if (!dryRun) state.releaseHeartbeat().touch();
32769
+ return results;
32770
+ },
32771
+ waiting: async ({ c, r }) => {
32772
+ try {
32773
+ const identity = await resolveReleaseKey(c);
32774
+ const tracker = new Tracker(c, cfg.ship, { apiKey: identity.apiKey });
32775
+ const { byRepo } = ticketsByRepo(c, await tracker.openTickets());
32776
+ const modes = { modes: await tracker.projectWorkModes(), agentAssignees: /* @__PURE__ */ new Set() };
32777
+ return withoutManualVerified(byRepo.get(r.name) ?? [], tracker.contract.statuses.verified, modes).filter((t) => t.status === tracker.contract.statuses.verified).length;
32778
+ } catch {
32779
+ return 0;
32780
+ }
32781
+ },
32782
+ refused: () => !dryRun && releaseRefused(),
32783
+ describe: ({ c, r }) => releaseLockScope(c.route, r.name),
32784
+ emit: (line) => emit.emit(line, { step: "release" })
32785
+ });
32620
32786
  }
32621
32787
  async function releaseTargets(opts = {}) {
32622
32788
  if (releaseRefused()) return;
@@ -33123,6 +33289,7 @@ ${changed2.map((c) => ` - ${c}
33123
33289
  return { scope, tests: "skipped", outcome: "skipped", detail: "a previous release is still running" };
33124
33290
  }
33125
33291
  let boardLock;
33292
+ let primaryRebuild;
33126
33293
  try {
33127
33294
  let contractRefusal = null;
33128
33295
  const repoFile = loadRepoConfigTolerant(target.dir, (e) => {
@@ -33327,6 +33494,7 @@ ${changed2.map((c) => ` - ${c}
33327
33494
  remit.warn(`could not read hand-back events; not deferring any branch: ${e.message}`);
33328
33495
  }
33329
33496
  }
33497
+ const claimed = /* @__PURE__ */ new Map();
33330
33498
  const outcome = await runRelease({
33331
33499
  cwd: target.dir,
33332
33500
  repo,
@@ -33368,6 +33536,20 @@ ${changed2.map((c) => ` - ${c}
33368
33536
  mergeOnly: command === "merge",
33369
33537
  // ci_* modes: record the merge on the board when it lands on base,
33370
33538
  // not only once CI confirms the release live (CREW-2820).
33539
+ // CREW-3811: the release seat holds a ticket while it merges and ships it.
33540
+ onClaim: async (ticket) => {
33541
+ const seat = releaseSeat(c);
33542
+ if (!seat || ticket.assignee_id === seat) return;
33543
+ const prior = ticket.assignee_id ?? null;
33544
+ await tracker.postEvent(ticket.id, "release took the ticket while it merges and ships it", seat, RELEASE_CLAIMED_EVENT, { prior_assignee: prior });
33545
+ claimed.set(ticket.id, prior);
33546
+ await tracker.updateTicket(ticket.id, { [tracker.contract.columns.assignee]: seat });
33547
+ },
33548
+ onUnclaim: async (ticket) => {
33549
+ if (!claimed.has(ticket.id)) return;
33550
+ await tracker.updateTicket(ticket.id, { [tracker.contract.columns.assignee]: claimed.get(ticket.id) ?? null });
33551
+ claimed.delete(ticket.id);
33552
+ },
33371
33553
  onBasePushed: async (merged) => {
33372
33554
  remit.enter("reconcile");
33373
33555
  await applyMergeStamp(
@@ -33384,12 +33566,14 @@ ${changed2.map((c) => ` - ${c}
33384
33566
  // genuinely unreleased.
33385
33567
  force: command === "deploy" || flag("force"),
33386
33568
  isDeployCommand: opts.isDeployCommand,
33569
+ stillHoldsLock: boardLock?.ok ? boardLock.stillHeld : void 0,
33387
33570
  attention: {
33388
33571
  raise: (item) => raiseShipAttention({ state, emit: remit, route: c, ship: cfg.ship }, item),
33389
33572
  clear: (key) => clearShipAttention(state, key),
33390
33573
  clearKind: (kind, keyPrefix) => clearShipAttentionKind(state, kind, keyPrefix)
33391
33574
  }
33392
33575
  });
33576
+ primaryRebuild = outcome.primaryRebuild;
33393
33577
  const summary = summarizeOutcome(outcome, scope, !!repo.hooks.test && !flag("skip-tests"));
33394
33578
  if (outcome.deployed || outcome.confirmed || outcome.alreadyLive || outcome.integrated) {
33395
33579
  remit.enter("reconcile");
@@ -33406,7 +33590,7 @@ ${changed2.map((c) => ` - ${c}
33406
33590
  ...outcome.merged.map((m) => [m.ticket.issue_id, m.sha])
33407
33591
  ])
33408
33592
  );
33409
- if (plan.length) await applyStamp(tracker, plan, outcome.version, tracker.contract, remit, dryRun, target.dir);
33593
+ if (plan.length) await applyStamp(tracker, plan, outcome.version, tracker.contract, remit, dryRun, target.dir, releaseSeat(c));
33410
33594
  } else if (outcome.stopped) {
33411
33595
  remit.emit(`nothing stamped \u2014 ${outcome.stopped}`);
33412
33596
  }
@@ -33422,7 +33606,8 @@ ${changed2.map((c) => ` - ${c}
33422
33606
  tracker.contract,
33423
33607
  remit,
33424
33608
  dryRun,
33425
- target.dir
33609
+ target.dir,
33610
+ releaseSeat(c)
33426
33611
  );
33427
33612
  }
33428
33613
  for (const r of planReleasedBranches(
@@ -33441,7 +33626,8 @@ ${changed2.map((c) => ` - ${c}
33441
33626
  tracker.contract,
33442
33627
  remit,
33443
33628
  dryRun,
33444
- target.dir
33629
+ target.dir,
33630
+ releaseSeat(c)
33445
33631
  );
33446
33632
  }
33447
33633
  if (outcome.gateRed && !dryRun) {
@@ -33726,6 +33912,13 @@ ${f2.tail.trimEnd()}
33726
33912
  } finally {
33727
33913
  if (boardLock && boardLock.ok) await boardLock.release();
33728
33914
  if (relLock && relLock.ok) relLock.release();
33915
+ if (primaryRebuild) {
33916
+ try {
33917
+ await primaryRebuild();
33918
+ } catch (e) {
33919
+ remit.warn(`rebuilding the primary checkout failed: ${e.message}`, { step: "release" });
33920
+ }
33921
+ }
33729
33922
  }
33730
33923
  }
33731
33924
  let lock;
@@ -24800,6 +24800,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
24800
24800
  "verify",
24801
24801
  "isolateFailures",
24802
24802
  "rightOfWayMinutes",
24803
+ "rebuildPrimary",
24803
24804
  "versioning",
24804
24805
  "versionFiles",
24805
24806
  "changelog",
@@ -24810,6 +24811,11 @@ var VERSIONINGS = ["auto", "none"];
24810
24811
  var CI_KEYS = /* @__PURE__ */ new Set(["provider", "ref"]);
24811
24812
  var VERIFY_KEYS = /* @__PURE__ */ new Set(["match", "timeoutSeconds", "intervalSeconds"]);
24812
24813
  var ISOLATE_KEYS = /* @__PURE__ */ new Set(["maxCandidates"]);
24814
+ function parseRebuildPrimary(raw, fail2) {
24815
+ if (raw === void 0 || raw === null) return void 0;
24816
+ if (typeof raw !== "boolean") throw fail2(`release.rebuildPrimary must be true or false (got "${raw}")`);
24817
+ return raw;
24818
+ }
24813
24819
  function parseRightOfWayMinutes(raw, fail2) {
24814
24820
  if (raw === void 0 || raw === null) return void 0;
24815
24821
  const n = Number(raw);
@@ -25041,6 +25047,7 @@ function parseRepoConfig(text, file) {
25041
25047
  (m) => new RepoConfigError(`${file}: ${m}`)
25042
25048
  );
25043
25049
  const rightOfWay = parseRightOfWayMinutes(raw.release?.rightOfWayMinutes, (m) => new RepoConfigError(`${file}: ${m}`));
25050
+ const rebuildPrimary = parseRebuildPrimary(raw.release?.rebuildPrimary, (m) => new RepoConfigError(`${file}: ${m}`));
25044
25051
  const versioning = String(raw.release?.versioning ?? "auto");
25045
25052
  if (!VERSIONINGS.includes(versioning)) {
25046
25053
  throw new RepoConfigError(`${file}: release.versioning must be auto|none (got "${versioning}")`);
@@ -25119,6 +25126,7 @@ function parseRepoConfig(text, file) {
25119
25126
  verify,
25120
25127
  isolateFailures: isolateMax === void 0 ? void 0 : { maxCandidates: isolateMax },
25121
25128
  rightOfWayMinutes: rightOfWay,
25129
+ rebuildPrimary,
25122
25130
  versioning,
25123
25131
  versionFiles,
25124
25132
  tag,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.165.1",
3
+ "version": "0.166.0",
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",