@tablation/crew 0.133.1 → 0.133.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +44 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -9632,7 +9632,14 @@ function heldByLiveOtherShip(t, a) {
9632
9632
  const holder = ticketHolderShipId(t, a.contract);
9633
9633
  if (!holder || holder === a.myShipId) return false;
9634
9634
  const owner = a.ships.find((s) => s.id === holder);
9635
- return shipIsAlive(owner, a.now ?? Date.now());
9635
+ const now = a.now ?? Date.now();
9636
+ return shipIsAlive(owner, now) || shipEngagedOn(owner, t, now);
9637
+ }
9638
+ var ENGAGED_TRUST_MS = 6 * 60 * 60 * 1e3;
9639
+ function shipEngagedOn(ship, t, now) {
9640
+ if (!ship?.engaged || ship.engaged_ticket_id !== t.id) return false;
9641
+ const since2 = ship.engaged_since ? Date.parse(ship.engaged_since) : NaN;
9642
+ return Number.isFinite(since2) && now - since2 <= ENGAGED_TRUST_MS;
9636
9643
  }
9637
9644
  function shipName(ships, id) {
9638
9645
  if (!id) return "an unknown ship";
@@ -10110,6 +10117,15 @@ async function enforceHandoff(i) {
10110
10117
  return { kind: "failed", why };
10111
10118
  }
10112
10119
  }
10120
+ function lostTicketReason(t, contract, myShipId) {
10121
+ if (closedStatuses(contract).includes(t.status)) return `the ticket is ${t.status}`;
10122
+ const holder = ticketHolderShipId(t, contract);
10123
+ const st = contract.statuses;
10124
+ if (holder && myShipId && holder !== myShipId && [st.building, st.approved].includes(t.status)) {
10125
+ return "another ship holds the ticket now";
10126
+ }
10127
+ return null;
10128
+ }
10113
10129
  async function guardRunHandoff(route2, ship, tracker, role, workingId, log, since2) {
10114
10130
  const replayed = await replayRoutePending(route2, ship, tracker, log, role);
10115
10131
  if (!workingId || role !== "dev" && role !== "design" && role !== "qa") return null;
@@ -10122,6 +10138,11 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
10122
10138
  if (!resolved) return null;
10123
10139
  const { target, cfg } = resolved;
10124
10140
  checkoutDir = target.dir;
10141
+ const lost = lostTicketReason(t, tracker.contract, (await tracker.claimAffinity())?.shipId);
10142
+ if (lost && role !== "qa") {
10143
+ log.warn(`${t.issue_id}: run ended without a push \u2014 ${lost}`, { ticket: t.issue_id, step: "handoff" });
10144
+ return { kind: "unverified", why: lost };
10145
+ }
10125
10146
  if (role === "qa") {
10126
10147
  await retireRunWorktree(tracker, target.dir, cfg, t, role, seatId, ship.name, log);
10127
10148
  return null;
@@ -17915,6 +17936,21 @@ async function resolveOne(tracker, t, seat, approvedStatus, buildingStatus, affi
17915
17936
  throw e;
17916
17937
  }
17917
17938
  }
17939
+ async function claimStillHeld(tracker, t, buildingStatus, affinity) {
17940
+ if (!tracker.ticket) return null;
17941
+ let now;
17942
+ try {
17943
+ now = await tracker.ticket(t.id);
17944
+ } catch {
17945
+ return null;
17946
+ }
17947
+ const holder = affinity ? now[affinity.column] : null;
17948
+ if (affinity && typeof holder === "string" && holder && holder !== affinity.shipId) {
17949
+ return `${t.issue_id} is held by another ship now`;
17950
+ }
17951
+ if (now.status !== buildingStatus) return `${t.issue_id} is at ${now.status}, not ${buildingStatus}`;
17952
+ return null;
17953
+ }
17918
17954
 
17919
17955
  // src/repo-refresh.ts
17920
17956
  import { existsSync as existsSync38, mkdirSync as mkdirSync26, readFileSync as readFileSync36, writeFileSync as writeFileSync29 } from "fs";
@@ -25156,6 +25192,13 @@ async function runRoleAgentLocked(role, decision, ctx, hooks, held) {
25156
25192
  emit.emit(`${role} skipped this cycle \u2014 every candidate was already claimed elsewhere`);
25157
25193
  return;
25158
25194
  }
25195
+ if (role !== "qa") {
25196
+ const lost = await claimStillHeld(tracker, result.ticket, claimStatuses(role, contract).building, await tracker.claimAffinity());
25197
+ if (lost) {
25198
+ emit.warn(`${role} run refused: ${lost}`, { step: "select", role });
25199
+ return;
25200
+ }
25201
+ }
25159
25202
  if (result.claimed) {
25160
25203
  const idx = decision.tickets.findIndex((t) => t.id === result.ticket.id);
25161
25204
  if (idx >= 0) decision.tickets[idx] = result.ticket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.133.1",
3
+ "version": "0.133.2",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",