@tablation/crew 0.154.1 → 0.155.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
@@ -3500,6 +3500,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
3500
3500
  "ci",
3501
3501
  "verify",
3502
3502
  "isolateFailures",
3503
+ "rightOfWayMinutes",
3503
3504
  "versioning",
3504
3505
  "versionFiles",
3505
3506
  "changelog",
@@ -3511,6 +3512,13 @@ var CI_KEYS = /* @__PURE__ */ new Set(["provider", "ref"]);
3511
3512
  var VERIFY_KEYS = /* @__PURE__ */ new Set(["match", "timeoutSeconds", "intervalSeconds"]);
3512
3513
  var ISOLATE_KEYS = /* @__PURE__ */ new Set(["maxCandidates"]);
3513
3514
  var DEFAULT_ISOLATE_MAX_CANDIDATES = 4;
3515
+ var DEFAULT_RIGHT_OF_WAY_MINUTES = 60;
3516
+ function parseRightOfWayMinutes(raw, fail2) {
3517
+ if (raw === void 0 || raw === null) return void 0;
3518
+ const n = Number(raw);
3519
+ if (!Number.isInteger(n) || n < 0) throw fail2(`release.rightOfWayMinutes must be a non-negative integer (got "${raw}")`);
3520
+ return n;
3521
+ }
3514
3522
  function parseIsolateMax(raw, where, fail2) {
3515
3523
  if (raw === void 0 || raw === null) return void 0;
3516
3524
  const n = Number(raw);
@@ -3735,6 +3743,7 @@ function parseRepoConfig(text2, file) {
3735
3743
  "release.isolateFailures",
3736
3744
  (m) => new RepoConfigError(`${file}: ${m}`)
3737
3745
  );
3746
+ const rightOfWay = parseRightOfWayMinutes(raw.release?.rightOfWayMinutes, (m) => new RepoConfigError(`${file}: ${m}`));
3738
3747
  const versioning = String(raw.release?.versioning ?? "auto");
3739
3748
  if (!VERSIONINGS.includes(versioning)) {
3740
3749
  throw new RepoConfigError(`${file}: release.versioning must be auto|none (got "${versioning}")`);
@@ -3812,6 +3821,7 @@ function parseRepoConfig(text2, file) {
3812
3821
  ci: { provider, ref: raw.release?.ci?.ref ? String(raw.release.ci.ref) : void 0 },
3813
3822
  verify,
3814
3823
  isolateFailures: isolateMax === void 0 ? void 0 : { maxCandidates: isolateMax },
3824
+ rightOfWayMinutes: rightOfWay,
3815
3825
  versioning,
3816
3826
  versionFiles,
3817
3827
  tag,
@@ -4022,6 +4032,7 @@ function resolveRepoConfig(repo, ship, dir) {
4022
4032
  DEFAULT_ISOLATE_MAX_CANDIDATES
4023
4033
  )
4024
4034
  },
4035
+ rightOfWayMinutes: repo?.release.rightOfWayMinutes ?? ship?.release?.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES,
4025
4036
  versioning: pick(
4026
4037
  "release.versioning",
4027
4038
  repo?.release.versioning === "auto" ? void 0 : repo?.release.versioning,
@@ -19881,7 +19892,7 @@ async function applyConflictBounce(writer, b, contract, memberId, log, dryRun) {
19881
19892
  handBackComment(b, merged),
19882
19893
  memberId,
19883
19894
  "conflict_handed_back",
19884
- b.baseSha ? { base_sha: b.baseSha } : void 0
19895
+ { ...b.baseSha ? { base_sha: b.baseSha } : {}, ...b.paths.length ? { paths: b.paths } : {} }
19885
19896
  ).catch((e) => {
19886
19897
  log.warn(`handed back, but the note failed to post: ${e.message}`, t);
19887
19898
  });
@@ -20146,6 +20157,80 @@ async function applyStrandedVerified(writer, s, contract, operatorId, memberId,
20146
20157
  }
20147
20158
  }
20148
20159
 
20160
+ // src/right-of-way.ts
20161
+ var RIGHT_OF_WAY_MARKER = calloutHeader("NOTE", "Waiting For A Conflict Fix");
20162
+ var DEFERRED_EVENT = "right_of_way_deferred";
20163
+ var stampMs = (e) => Date.parse(e.occurred_at ?? e.created_at ?? "") || 0;
20164
+ var pathsOf = (e) => {
20165
+ const p = e.metadata?.paths;
20166
+ return Array.isArray(p) ? p.filter((x) => typeof x === "string" && x !== "") : [];
20167
+ };
20168
+ function handBacks(tickets, events, contract, now, ttlMinutes) {
20169
+ const none = { open: [], lapsed: [] };
20170
+ if (ttlMinutes <= 0) return none;
20171
+ const s = contract.statuses;
20172
+ const live2 = /* @__PURE__ */ new Set([s.building, s.handoff, s.verifying, s.verified]);
20173
+ const byId = new Map(tickets.map((t) => [t.id, t]));
20174
+ const newest = /* @__PURE__ */ new Map();
20175
+ for (const e of events) {
20176
+ if (e.event_type !== "conflict_handed_back" || !pathsOf(e).length) continue;
20177
+ const prev = newest.get(e.record_id);
20178
+ if (!prev || stampMs(e) > stampMs(prev)) newest.set(e.record_id, e);
20179
+ }
20180
+ const out = { open: [], lapsed: [] };
20181
+ for (const [id, e] of newest) {
20182
+ const ticket = byId.get(id);
20183
+ if (!ticket || !live2.has(ticket.status)) continue;
20184
+ const at = stampMs(e);
20185
+ if (events.some((x) => x.record_id === id && x.event_type === "conflict_escalated" && stampMs(x) > at)) continue;
20186
+ const hb = { ticket, at, paths: pathsOf(e), expiresAt: at + ttlMinutes * 6e4 };
20187
+ (now >= hb.expiresAt ? out.lapsed : out.open).push(hb);
20188
+ }
20189
+ const order = (a, b) => a.at - b.at || a.ticket.issue_id.localeCompare(b.ticket.issue_id);
20190
+ out.open.sort(order);
20191
+ out.lapsed.sort(order);
20192
+ return out;
20193
+ }
20194
+ var overlap = (a, b) => {
20195
+ const set = new Set(b);
20196
+ return a.filter((p) => set.has(p));
20197
+ };
20198
+ function planRightOfWay(candidates2, tickets, events, contract, now, ttlMinutes) {
20199
+ const { open, lapsed } = handBacks(tickets, events, contract, now, ttlMinutes);
20200
+ const own = new Map(open.map((h) => [h.ticket.id, h]));
20201
+ const deferrals = [];
20202
+ for (const c of candidates2) {
20203
+ const mine = own.get(c.ticket.id);
20204
+ const first = open.find((h) => h.ticket.id !== c.ticket.id && (!mine || mine.at > h.at || mine.at === h.at && mine.ticket.issue_id > h.ticket.issue_id) && overlap(c.paths, h.paths).length > 0);
20205
+ if (first) deferrals.push({ ticket: c.ticket, waitingFor: first.ticket, paths: overlap(c.paths, first.paths), since: first.at });
20206
+ }
20207
+ const lapsedUsed = lapsed.filter((h) => candidates2.some((c) => c.ticket.id !== h.ticket.id && overlap(c.paths, h.paths).length > 0));
20208
+ return { deferrals, lapsed: lapsedUsed };
20209
+ }
20210
+ function branchPaths(cwd, base, branch) {
20211
+ return (gitOk(cwd, ["diff", "--name-only", `${base}...${branch}`]) ?? "").split("\n").filter(Boolean);
20212
+ }
20213
+ var deferralReported = (d, events) => events.some((e) => e.record_id === d.ticket.id && e.event_type === DEFERRED_EVENT && e.metadata?.waiting_for === d.waitingFor.id && stampMs(e) >= d.since);
20214
+ function deferralComment(d, base, ttlMinutes) {
20215
+ const list = d.paths.map((p) => `\`${p}\``).join(", ");
20216
+ return `${RIGHT_OF_WAY_MARKER}
20217
+
20218
+ **Verified, and waiting its turn \u2014 not handed back.**
20219
+
20220
+ ${displayKey(d.waitingFor)} was handed back for a merge conflict in ${list}, which this branch also changes. Releasing this branch first would move \`${base}\` under it again, so the release leaves this ticket at \`verified\` and retries it each cycle until ${displayKey(d.waitingFor)} is verified and released, or until its right of way lapses (${ttlMinutes} minutes after the hand-back). Nothing is needed from anyone.`;
20221
+ }
20222
+ function deferredFromLog(tickets, events, contract, now, ttlMinutes) {
20223
+ const { open } = handBacks(tickets, events, contract, now, ttlMinutes);
20224
+ const out = [];
20225
+ for (const t of tickets) {
20226
+ if (t.status !== contract.statuses.verified) continue;
20227
+ const last = events.filter((e) => e.record_id === t.id && e.event_type === DEFERRED_EVENT).sort((a, b) => stampMs(b) - stampMs(a))[0];
20228
+ const hb = last && open.find((h) => h.ticket.id === last.metadata?.waiting_for && h.at <= stampMs(last));
20229
+ if (hb) out.push({ ticket: t, waitingFor: hb.ticket });
20230
+ }
20231
+ return out;
20232
+ }
20233
+
20149
20234
  // src/local-ref-skip.ts
20150
20235
  var LOCAL_REF_SKIP_MARKER = calloutHeader("WARNING", "Release Skipped");
20151
20236
  function localRefSkipComment(shipName2, problem) {
@@ -21619,14 +21704,16 @@ function reportHeld(o, held) {
21619
21704
  async function runRelease(o) {
21620
21705
  const movedPast2 = [];
21621
21706
  const localRefSkips = [];
21622
- const out = await runReleaseCycle(o, movedPast2, localRefSkips);
21707
+ const rightOfWay = { deferrals: [], lapsed: [] };
21708
+ const out = await runReleaseCycle(o, movedPast2, localRefSkips, rightOfWay);
21623
21709
  return {
21624
21710
  ...out,
21625
21711
  ...movedPast2.length ? { movedPast: movedPast2 } : {},
21626
- ...localRefSkips.length ? { localRefSkips } : {}
21712
+ ...localRefSkips.length ? { localRefSkips } : {},
21713
+ ...rightOfWay.deferrals.length || rightOfWay.lapsed.length ? { rightOfWay } : {}
21627
21714
  };
21628
21715
  }
21629
- async function runReleaseCycle(o, movedPast2, localRefSkips) {
21716
+ async function runReleaseCycle(o, movedPast2, localRefSkips, rightOfWay) {
21630
21717
  const scoped = (msg) => o.scope ? `${o.scope}: ${msg}` : msg;
21631
21718
  const tagPattern = o.repo.release.tagPattern ?? "v*";
21632
21719
  o.emit.enter("release");
@@ -21673,6 +21760,41 @@ async function runReleaseCycle(o, movedPast2, localRefSkips) {
21673
21760
  }
21674
21761
  if (drop.size) releasable = releasable.filter((t) => !drop.has(t.id));
21675
21762
  }
21763
+ if (o.rightOfWayEvents?.length && (o.repo.release.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES) > 0) {
21764
+ const baseRef = remoteBranchExists(o.cwd, o.repo.branch.remote, o.repo.branch.base) ? `${o.repo.branch.remote}/${o.repo.branch.base}` : o.repo.branch.base;
21765
+ const candidates2 = [];
21766
+ for (const t of releasable) {
21767
+ if (t.status !== o.contract.statuses.verified) continue;
21768
+ const branch = locateBranchForTicket(o.cwd, o.repo, t)?.branch;
21769
+ if (branch) candidates2.push({ ticket: t, paths: branchPaths(o.cwd, baseRef, branch) });
21770
+ }
21771
+ const plan = planRightOfWay(
21772
+ candidates2,
21773
+ o.tickets,
21774
+ o.rightOfWayEvents,
21775
+ o.contract,
21776
+ (o.now ?? Date.now)(),
21777
+ o.repo.release.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES
21778
+ );
21779
+ rightOfWay.deferrals.push(...plan.deferrals);
21780
+ rightOfWay.lapsed.push(...plan.lapsed);
21781
+ for (const h of plan.lapsed) {
21782
+ o.emit.warn(
21783
+ `${displayKey(h.ticket)}'s right of way over ${h.paths.join(", ")} lapsed after ${o.repo.release.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES} minutes without it coming back verified \u2014 not deferring other branches for it`,
21784
+ { ticket: h.ticket.issue_id, step: "release" }
21785
+ );
21786
+ }
21787
+ for (const d of plan.deferrals) {
21788
+ o.emit.emit(
21789
+ `not releasing ${displayKey(d.ticket)} this cycle: waiting for ${displayKey(d.waitingFor)}, handed back for a conflict in ${d.paths.join(", ")}`,
21790
+ { ticket: d.ticket.issue_id, step: "release" }
21791
+ );
21792
+ }
21793
+ if (plan.deferrals.length) {
21794
+ const waiting = new Set(plan.deferrals.map((d) => d.ticket.id));
21795
+ releasable = releasable.filter((t) => !waiting.has(t.id));
21796
+ }
21797
+ }
21676
21798
  const { remote, base } = o.repo.branch;
21677
21799
  const inPlace = o.dryRun || !!o.mergeOnly || !remoteBranchExists(o.cwd, remote, base);
21678
21800
  const remoteRef = `${remote}/${base}`;
@@ -25471,11 +25593,13 @@ function renderStatus(v, opts) {
25471
25593
  const own = byRecent(v.attention, (a) => a.since);
25472
25594
  const others = v.ships.filter((s) => s.name !== v.ship.name && s.attention.length);
25473
25595
  const unsafe = v.repos.filter((r) => r.unsafeDetail);
25474
- if (own.length || others.length || unsafe.length || v.heldReleases.length || v.starved) {
25596
+ const deferred = v.deferredReleases ?? [];
25597
+ if (own.length || others.length || unsafe.length || v.heldReleases.length || deferred.length || v.starved) {
25475
25598
  out.push("needs attention:");
25476
25599
  for (const i of own) out.push(` ${i.kind} \u2014 ${i.message}`);
25477
25600
  for (const r of unsafe) out.push(` base ${r.name} \u2014 UNSAFE, no worktree cuts or releases: ${r.unsafeDetail}`);
25478
25601
  for (const l of v.heldReleases) out.push(` release: ${l}`);
25602
+ for (const l of deferred) out.push(` deferred: ${l}`);
25479
25603
  if (v.starved) {
25480
25604
  out.push(` waiting: ${v.starved.ticket} for ${since(v.starved.since, now)} (passed over ${plural(v.starved.streak, "cycle")} running)`);
25481
25605
  }
@@ -27710,7 +27834,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
27710
27834
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
27711
27835
  import { join as join60 } from "path";
27712
27836
  function builtVersion() {
27713
- return true ? "0.154.1" : null;
27837
+ return true ? "0.155.0" : null;
27714
27838
  }
27715
27839
  var REBUILD_HINT = "rebuild with npm run build";
27716
27840
  function newestMtime(path) {
@@ -31469,9 +31593,18 @@ ${changed2.map((c) => ` - ${c}
31469
31593
  if (sha) verifiedShas.set(t.id, sha);
31470
31594
  }
31471
31595
  }
31596
+ let rightOfWayEvents;
31597
+ if (verifiedTickets.length >= 1 && repo.release.mode !== "external") {
31598
+ try {
31599
+ rightOfWayEvents = [...await tracker.events("conflict_handed_back"), ...await tracker.events("conflict_escalated")];
31600
+ } catch (e) {
31601
+ remit.warn(`could not read hand-back events; not deferring any branch: ${e.message}`);
31602
+ }
31603
+ }
31472
31604
  const outcome = await runRelease({
31473
31605
  cwd: target.dir,
31474
31606
  repo,
31607
+ rightOfWayEvents,
31475
31608
  reloadRepo: (dir) => resolveRepoConfig(loadRepoConfig(dir), {
31476
31609
  hooks: { ...c.hooks, ...o?.hooks },
31477
31610
  labels: { ...c.labels, ...o?.labels },
@@ -31597,6 +31730,25 @@ ${changed2.map((c) => ` - ${c}
31597
31730
  remit.warn(`could not note the skipped release on the board: ${e.message}`, { step: "merge" });
31598
31731
  }
31599
31732
  }
31733
+ if (outcome.rightOfWay?.deferrals.length && !dryRun) {
31734
+ try {
31735
+ const reported2 = await tracker.events(DEFERRED_EVENT);
31736
+ const seat = releaseSeat(c);
31737
+ const minutes = repo.release.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES;
31738
+ for (const d of outcome.rightOfWay.deferrals) {
31739
+ if (deferralReported(d, reported2)) continue;
31740
+ await tracker.postEvent(
31741
+ d.ticket.id,
31742
+ deferralComment(d, repo.branch.base, minutes),
31743
+ seat,
31744
+ DEFERRED_EVENT,
31745
+ { waiting_for: d.waitingFor.id, paths: d.paths }
31746
+ );
31747
+ }
31748
+ } catch (e) {
31749
+ remit.warn(`could not note the deferred release on the board: ${e.message}`, { step: "release" });
31750
+ }
31751
+ }
31600
31752
  if (outcome.externalClosures?.length) {
31601
31753
  await applyExternalClosures(tracker, outcome.externalClosures, tracker.contract, remit, dryRun, target.dir);
31602
31754
  }
@@ -35635,6 +35787,7 @@ ${where.join("\n")}`);
35635
35787
  }
35636
35788
  const shipAttention = openShipAttention(state);
35637
35789
  let heldReleases = [];
35790
+ let deferredReleases = [];
35638
35791
  try {
35639
35792
  const open = await statusTracker.openTickets();
35640
35793
  heldReleases = describeHeld(heldByBlockers(
@@ -35642,6 +35795,16 @@ ${where.join("\n")}`);
35642
35795
  statusTracker.contract.statuses.verified,
35643
35796
  blockerInfoMap(open, await statusTracker.ticketsByIds(missingBlockerIds(open)))
35644
35797
  ));
35798
+ const minutes = Math.min(...(await resolvedRepos(route2)).map((r) => r.config.release.rightOfWayMinutes ?? DEFAULT_RIGHT_OF_WAY_MINUTES), DEFAULT_RIGHT_OF_WAY_MINUTES);
35799
+ if (open.some((t) => t.status === statusTracker.contract.statuses.verified)) {
35800
+ deferredReleases = deferredFromLog(
35801
+ open,
35802
+ [...await statusTracker.events(DEFERRED_EVENT), ...await statusTracker.events("conflict_handed_back"), ...await statusTracker.events("conflict_escalated")],
35803
+ statusTracker.contract,
35804
+ Date.now(),
35805
+ minutes
35806
+ ).map((d) => `${displayKey(d.ticket)} waits for ${displayKey(d.waitingFor)}, handed back for a merge conflict`);
35807
+ }
35645
35808
  } catch {
35646
35809
  }
35647
35810
  const repoViews = [];
@@ -35682,6 +35845,7 @@ ${where.join("\n")}`);
35682
35845
  })),
35683
35846
  repos: repoViews,
35684
35847
  heldReleases,
35848
+ deferredReleases,
35685
35849
  starved: waiting ? { ticket: waiting.ticket, since: waiting.since, streak: fairness.streak() } : void 0,
35686
35850
  ships: shipRows.map((s) => ({
35687
35851
  name: s.name ?? "(unnamed)",
@@ -24799,6 +24799,7 @@ var RELEASE_KEYS = /* @__PURE__ */ new Set([
24799
24799
  "ci",
24800
24800
  "verify",
24801
24801
  "isolateFailures",
24802
+ "rightOfWayMinutes",
24802
24803
  "versioning",
24803
24804
  "versionFiles",
24804
24805
  "changelog",
@@ -24809,6 +24810,12 @@ var VERSIONINGS = ["auto", "none"];
24809
24810
  var CI_KEYS = /* @__PURE__ */ new Set(["provider", "ref"]);
24810
24811
  var VERIFY_KEYS = /* @__PURE__ */ new Set(["match", "timeoutSeconds", "intervalSeconds"]);
24811
24812
  var ISOLATE_KEYS = /* @__PURE__ */ new Set(["maxCandidates"]);
24813
+ function parseRightOfWayMinutes(raw, fail2) {
24814
+ if (raw === void 0 || raw === null) return void 0;
24815
+ const n = Number(raw);
24816
+ if (!Number.isInteger(n) || n < 0) throw fail2(`release.rightOfWayMinutes must be a non-negative integer (got "${raw}")`);
24817
+ return n;
24818
+ }
24812
24819
  function parseIsolateMax(raw, where, fail2) {
24813
24820
  if (raw === void 0 || raw === null) return void 0;
24814
24821
  const n = Number(raw);
@@ -25033,6 +25040,7 @@ function parseRepoConfig(text, file) {
25033
25040
  "release.isolateFailures",
25034
25041
  (m) => new RepoConfigError(`${file}: ${m}`)
25035
25042
  );
25043
+ const rightOfWay = parseRightOfWayMinutes(raw.release?.rightOfWayMinutes, (m) => new RepoConfigError(`${file}: ${m}`));
25036
25044
  const versioning = String(raw.release?.versioning ?? "auto");
25037
25045
  if (!VERSIONINGS.includes(versioning)) {
25038
25046
  throw new RepoConfigError(`${file}: release.versioning must be auto|none (got "${versioning}")`);
@@ -25110,6 +25118,7 @@ function parseRepoConfig(text, file) {
25110
25118
  ci: { provider, ref: raw.release?.ci?.ref ? String(raw.release.ci.ref) : void 0 },
25111
25119
  verify,
25112
25120
  isolateFailures: isolateMax === void 0 ? void 0 : { maxCandidates: isolateMax },
25121
+ rightOfWayMinutes: rightOfWay,
25113
25122
  versioning,
25114
25123
  versionFiles,
25115
25124
  tag,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.154.1",
3
+ "version": "0.155.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",