@tablation/crew 0.165.2 → 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) {
@@ -22478,7 +22534,12 @@ function looksLikeTransientResolveFailure(output) {
22478
22534
  const realBuildError = /(TS\d{4}:|SyntaxError|error TS|Cannot find module '\.)/;
22479
22535
  return resolveFailure.test(output) && !realBuildError.test(output);
22480
22536
  }
22537
+ var HOOK_NO_RETRY_EXIT_CODE = 86;
22481
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
+ }
22482
22543
  o.emit.warn(`${name} gate failed \u2014 rerunning once on the same composition before blaming a branch`);
22483
22544
  const again = await hook(o, name);
22484
22545
  if (!again || again.code !== 0) return again ?? first;
@@ -23120,18 +23181,23 @@ async function runReleaseCycle(o, movedPast2, localRefSkips, rightOfWay) {
23120
23181
  o.emit.error(scoped(`could not cut a release checkout from ${remote}/${base} \u2014 ${e.message}`));
23121
23182
  return { merged: [], deployed: false, stopped: "release checkout failed", decision };
23122
23183
  }
23184
+ let outcome;
23185
+ let rebuild;
23123
23186
  try {
23124
- return await mergeAndRelease({ ...o, cwd: checkout.dir }, decision, fresh, checkout.branch);
23187
+ outcome = await mergeAndRelease({ ...o, cwd: checkout.dir }, decision, fresh, checkout.branch);
23125
23188
  } finally {
23126
23189
  checkout.close();
23127
23190
  const refreshed = refreshBaseBranch(o.cwd, remote, base);
23128
- if (refreshed.action === "fast-forwarded" && o.repo.hooks.build) {
23129
- const r = await hook(o, "build");
23130
- if (r && r.code !== 0) {
23131
- 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`));
23132
- }
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
+ };
23133
23198
  }
23134
23199
  }
23200
+ return rebuild ? { ...outcome, primaryRebuild: rebuild } : outcome;
23135
23201
  }
23136
23202
  var MAX_ISOLATE_PAIRS = 10;
23137
23203
  function pairOrder(n, max = MAX_ISOLATE_PAIRS) {
@@ -23534,6 +23600,10 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23534
23600
  }
23535
23601
  }
23536
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
+ }
23537
23607
  if (remoteConfigured(o.cwd, o.repo.branch.remote)) {
23538
23608
  if (o.dryRun) {
23539
23609
  o.emit.emit(`would push ${o.repo.branch.base} to ${o.repo.branch.remote}`);
@@ -23572,7 +23642,10 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23572
23642
  integrated = true;
23573
23643
  } else if (o.repo.release.mode === "local" && o.repo.hooks.deploy) {
23574
23644
  if (o.dryRun) o.emit.emit(`would run: ${hookLabel(o.repo, "deploy")}`);
23575
- 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 {
23576
23649
  let r = await hook(o, "deploy");
23577
23650
  if (r && r.code !== 0 && looksLikeTransientResolveFailure(r.output)) {
23578
23651
  o.emit.warn("deploy failed with what looks like a transient dependency-resolution glitch, not a real failure \u2014 retrying once");
@@ -23631,6 +23704,33 @@ async function mergeAndReleaseBody(o, decision, fresh, releaseBranch, isolated =
23631
23704
  );
23632
23705
  return { merged, conflicts, unbuildable, version, tag, deployed, integrated, confirmed, decision, ...ciOutcome(o, watch2, confirmed) };
23633
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
+ }
23634
23734
 
23635
23735
  // src/failure-alert.ts
23636
23736
  var FAILURE_ALERT_MARKER = calloutHeader("CAUTION", "Failure Alert");
@@ -29587,7 +29687,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
29587
29687
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
29588
29688
  import { join as join61 } from "path";
29589
29689
  function builtVersion() {
29590
- return true ? "0.165.2" : null;
29690
+ return true ? "0.166.0" : null;
29591
29691
  }
29592
29692
  var REBUILD_HINT = "rebuild with npm run build";
29593
29693
  function newestMtime(path) {
@@ -32646,16 +32746,43 @@ if (command === "passenger-sync-daemon") {
32646
32746
  }
32647
32747
  async function releaseFleet(opts = {}) {
32648
32748
  sweepStateDir();
32649
- if (releaseRefused()) return;
32650
- precheckTickets.clear();
32651
- const summaries = [];
32652
- if (!dryRun) state.releaseHeartbeat().touch();
32653
- for (const c of cfg.routes) {
32654
- if (!dryRun && !c.enabled) continue;
32655
- for (const r of reposOf(c)) summaries.push({ ...await releasePhase(c, r, opts), route: c.route });
32656
- }
32657
- emitReleaseSummary(emit, summaries);
32658
- 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
+ });
32659
32786
  }
32660
32787
  async function releaseTargets(opts = {}) {
32661
32788
  if (releaseRefused()) return;
@@ -33162,6 +33289,7 @@ ${changed2.map((c) => ` - ${c}
33162
33289
  return { scope, tests: "skipped", outcome: "skipped", detail: "a previous release is still running" };
33163
33290
  }
33164
33291
  let boardLock;
33292
+ let primaryRebuild;
33165
33293
  try {
33166
33294
  let contractRefusal = null;
33167
33295
  const repoFile = loadRepoConfigTolerant(target.dir, (e) => {
@@ -33438,12 +33566,14 @@ ${changed2.map((c) => ` - ${c}
33438
33566
  // genuinely unreleased.
33439
33567
  force: command === "deploy" || flag("force"),
33440
33568
  isDeployCommand: opts.isDeployCommand,
33569
+ stillHoldsLock: boardLock?.ok ? boardLock.stillHeld : void 0,
33441
33570
  attention: {
33442
33571
  raise: (item) => raiseShipAttention({ state, emit: remit, route: c, ship: cfg.ship }, item),
33443
33572
  clear: (key) => clearShipAttention(state, key),
33444
33573
  clearKind: (kind, keyPrefix) => clearShipAttentionKind(state, kind, keyPrefix)
33445
33574
  }
33446
33575
  });
33576
+ primaryRebuild = outcome.primaryRebuild;
33447
33577
  const summary = summarizeOutcome(outcome, scope, !!repo.hooks.test && !flag("skip-tests"));
33448
33578
  if (outcome.deployed || outcome.confirmed || outcome.alreadyLive || outcome.integrated) {
33449
33579
  remit.enter("reconcile");
@@ -33782,6 +33912,13 @@ ${f2.tail.trimEnd()}
33782
33912
  } finally {
33783
33913
  if (boardLock && boardLock.ok) await boardLock.release();
33784
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
+ }
33785
33922
  }
33786
33923
  }
33787
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.2",
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",