@tablation/crew 0.142.5 → 0.142.6

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 +69 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -6684,17 +6684,33 @@ function recheckBaseStops(state, route2) {
6684
6684
  }
6685
6685
  var heldWorktreeKey = (repo, path) => `worktree_held:${repo}:${path}`;
6686
6686
  var HELD_WORKTREE_REMINDER_MS = 24 * 60 * 60 * 1e3;
6687
+ var HELD_WORKTREE_MIN_SWEEPS = 2;
6688
+ var HELD_WORKTREE_MIN_AGE_MS = 10 * 60 * 1e3;
6687
6689
  function noteHeldWorktree(state, h, nowMs = Date.now()) {
6688
6690
  const store = state.shipAttention();
6689
6691
  const previous = store.previous();
6690
6692
  const key = heldWorktreeKey(h.repo, h.path);
6691
6693
  const existing = previous.find((i) => i.key === key)?.held;
6692
6694
  const nowIso = new Date(nowMs).toISOString();
6695
+ let firstSeenAt = existing?.firstSeenAt;
6696
+ if (!existing) {
6697
+ const pending = state.pendingHeldWorktrees();
6698
+ const all = pending.previous();
6699
+ const p = all[key]?.reason === h.reason ? all[key] : void 0;
6700
+ const sweeps = (p?.sweeps ?? 0) + 1;
6701
+ firstSeenAt = p?.firstSeenAt ?? nowIso;
6702
+ if (sweeps < HELD_WORKTREE_MIN_SWEEPS && nowMs - Date.parse(firstSeenAt) < HELD_WORKTREE_MIN_AGE_MS) {
6703
+ pending.persist({ ...all, [key]: { reason: h.reason, firstSeenAt, sweeps } });
6704
+ return null;
6705
+ }
6706
+ const { [key]: _promoted, ...rest } = all;
6707
+ if (key in all) pending.persist(rest);
6708
+ }
6693
6709
  const lastWarned = existing ? Date.parse(existing.lastWarnedAt) : NaN;
6694
6710
  const warn = !existing ? "first" : existing.reason !== h.reason ? "changed" : !(nowMs - lastWarned < HELD_WORKTREE_REMINDER_MS) ? "reminder" : null;
6695
6711
  const held = {
6696
6712
  ...h,
6697
- firstSeenAt: existing?.firstSeenAt ?? nowIso,
6713
+ firstSeenAt,
6698
6714
  lastWarnedAt: warn ? nowIso : existing.lastWarnedAt
6699
6715
  };
6700
6716
  const n = h.ticket.replace(/^\D+/, "");
@@ -6709,6 +6725,15 @@ function noteHeldWorktree(state, h, nowMs = Date.now()) {
6709
6725
  return warn;
6710
6726
  }
6711
6727
  function reconcileHeldWorktrees(state, repo, log, stillRefused) {
6728
+ const pending = state.pendingHeldWorktrees();
6729
+ const waiting = pending.previous();
6730
+ const keep = Object.fromEntries(Object.entries(waiting).filter(([key]) => {
6731
+ const [, r, ...rest] = key.split(":");
6732
+ const path = rest.join(":");
6733
+ if (r !== repo) return true;
6734
+ return existsSync18(path) && !(stillRefused && !stillRefused.has(path));
6735
+ }));
6736
+ if (Object.keys(keep).length !== Object.keys(waiting).length) pending.persist(keep);
6712
6737
  for (const i of state.shipAttention().previous()) {
6713
6738
  if (i.kind !== "worktree_held" || !i.held || i.held.repo !== repo) continue;
6714
6739
  const gone = !existsSync18(i.held.path);
@@ -7448,6 +7473,28 @@ var State = class _State {
7448
7473
  }
7449
7474
  };
7450
7475
  }
7476
+ /**
7477
+ * Worktree refusals not yet old enough to publish as `worktree_held` items
7478
+ * (CREW-3204), keyed by the item key. Kept apart from `shipAttention()` so no
7479
+ * client sees a refusal that may clear on its own. A corrupt or missing file
7480
+ * reads as empty.
7481
+ */
7482
+ pendingHeldWorktrees() {
7483
+ const file = ".worktree-held-pending.json";
7484
+ return {
7485
+ previous: () => {
7486
+ try {
7487
+ const parsed = JSON.parse(readFileSync21(this.path(file), "utf8"));
7488
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
7489
+ } catch {
7490
+ return {};
7491
+ }
7492
+ },
7493
+ persist: (next) => {
7494
+ writeFileSync16(this.path(file), JSON.stringify(next));
7495
+ }
7496
+ };
7497
+ }
7451
7498
  /**
7452
7499
  * When the release phase last ran a cycle (CREW-1373), as the mtime of a
7453
7500
  * marker file. `touch()` is called at the start and the end of every cycle
@@ -25801,23 +25848,42 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
25801
25848
  );
25802
25849
  }
25803
25850
  }
25851
+ const n = Number(a.ticket.issue_id.replace(/^\D+/, ""));
25852
+ const pids = pidsInWorktree(a.path, n);
25853
+ const liveRun = !!held && liveRuns(held.state.dir).some((r) => (r.ticket ?? "").replace(/^\D+/, "") === String(n));
25854
+ const defer = () => {
25855
+ log.emit(
25856
+ `leaving ${a.path} for the next cycle: ${liveRun ? `${a.ticket.issue_id} has a run in progress on this ship` : `processes are still inside it (${pids.join(" ")})`}`,
25857
+ { ticket: a.ticket.issue_id, step: "worktree" }
25858
+ );
25859
+ };
25860
+ if (!dryRun && liveRun && existsSync53(a.path)) {
25861
+ defer();
25862
+ continue;
25863
+ }
25804
25864
  if (!dryRun && existsSync53(a.path)) {
25805
25865
  let dirty = false;
25806
25866
  try {
25807
25867
  dirty = status(a.path).length > 0;
25808
25868
  } catch {
25809
25869
  }
25870
+ if (dirty && pids.length) {
25871
+ defer();
25872
+ continue;
25873
+ }
25810
25874
  if (dirty) {
25811
25875
  refuse2(a, "uncommitted changes", "it has uncommitted changes");
25812
25876
  continue;
25813
25877
  }
25814
25878
  }
25815
25879
  if (!dryRun && a.requirePushed && a.branch && existsSync53(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
25880
+ if (pids.length) {
25881
+ defer();
25882
+ continue;
25883
+ }
25816
25884
  refuse2(a, "unpushed commits", `${a.branch} has commits that are not on ${remote}`);
25817
25885
  continue;
25818
25886
  }
25819
- const n = Number(a.ticket.issue_id.replace(/^\D+/, ""));
25820
- const pids = pidsInWorktree(a.path, n);
25821
25887
  if (pids.length) {
25822
25888
  log.emit(
25823
25889
  `${dryRun ? "would kill" : "killing"} processes still inside ${a.path}: ${pids.join(" ")}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.142.5",
3
+ "version": "0.142.6",
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",