tumwater 0.4.3 → 0.4.4

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 (164) hide show
  1. package/README.md +1 -1
  2. package/dist/build-info.json +2 -2
  3. package/dist/src/agent/agent-run.js +2 -1
  4. package/dist/src/agent/claude/claude-account.js +6 -20
  5. package/dist/src/agent/codex/codex-account.js +5 -6
  6. package/dist/src/agent/codex/codex-args.js +5 -5
  7. package/dist/src/agent/codex/codex-rollout.js +1 -1
  8. package/dist/src/agent/opencode/opencode-backend.js +24 -22
  9. package/dist/src/agent/opencode/opencode-catalog.js +35 -9
  10. package/dist/src/agent/session-ledger.js +22 -26
  11. package/dist/src/agent/subscription-account.js +2 -83
  12. package/dist/src/backlog/backlog-archive.js +3 -4
  13. package/dist/src/backlog/backlog-eligibility.js +14 -36
  14. package/dist/src/backlog/backlog-question-answer.js +1 -1
  15. package/dist/src/backlog/backlog.js +2 -1
  16. package/dist/src/baseline/main-guardrails.js +2 -2
  17. package/dist/src/baseline/main-watch.js +84 -50
  18. package/dist/src/brief/brief.js +26 -13
  19. package/dist/src/budget/budget.js +4 -5
  20. package/dist/src/build/build-check-report.js +10 -0
  21. package/dist/src/build/build-check-scoped.js +0 -2
  22. package/dist/src/build/build-stage.js +6 -4
  23. package/dist/src/change/change-data.js +1 -4
  24. package/dist/src/cli/cli-completion-command.js +75 -0
  25. package/dist/src/cli/cli-doctor-command.js +103 -0
  26. package/dist/src/cli/cli-init.js +2 -2
  27. package/dist/src/cli/cli-query-commands.js +1 -1
  28. package/dist/src/cli/cli-role-command.js +2 -41
  29. package/dist/src/cli/cli-start-summary.js +4 -3
  30. package/dist/src/cli/cli-start-supervisor.js +190 -0
  31. package/dist/src/cli/cli-start.js +4 -187
  32. package/dist/src/cli/completion.js +3 -3
  33. package/dist/src/cli/follow-view.js +20 -2
  34. package/dist/src/cli/help.js +2 -7
  35. package/dist/src/cli.js +19 -171
  36. package/dist/src/collections.js +11 -14
  37. package/dist/src/concurrency/lock.js +1 -1
  38. package/dist/src/config/config-keys.js +61 -20
  39. package/dist/src/config/config-request.js +11 -1
  40. package/dist/src/config/config-schema.js +1 -1
  41. package/dist/src/config/config-validation-roles.js +6 -22
  42. package/dist/src/config/config-validation.js +0 -1
  43. package/dist/src/config/config-views.js +17 -16
  44. package/dist/src/config/config-write.js +122 -79
  45. package/dist/src/config/config.js +1 -9
  46. package/dist/src/doctor/doctor-backlog-plans.js +29 -96
  47. package/dist/src/doctor/doctor-backlog.js +10 -10
  48. package/dist/src/doctor/doctor-checks.js +4 -4
  49. package/dist/src/doctor/doctor-claude-checks.js +27 -9
  50. package/dist/src/doctor/doctor-contention-checks.js +13 -5
  51. package/dist/src/doctor/doctor-fallback-checks.js +46 -24
  52. package/dist/src/doctor/doctor-holds.js +2 -2
  53. package/dist/src/doctor/doctor-orphans.js +3 -2
  54. package/dist/src/doctor/doctor-project-checks.js +21 -8
  55. package/dist/src/events/event-format.js +15 -11
  56. package/dist/src/events/event-legacy.js +2 -2
  57. package/dist/src/events/event-notify.js +4 -4
  58. package/dist/src/events/event-window.js +1 -1
  59. package/dist/src/events/events.js +8 -0
  60. package/dist/src/failure/failure-cluster.js +4 -13
  61. package/dist/src/failure/failure-data.js +4 -4
  62. package/dist/src/failure/failure-render.js +2 -2
  63. package/dist/src/failure/failure-state-change.js +50 -86
  64. package/dist/src/gates/gate-polls.js +5 -6
  65. package/dist/src/gates/startup-gates.js +2 -1
  66. package/dist/src/git/git-diff.js +6 -2
  67. package/dist/src/gui/gui-args.js +12 -0
  68. package/dist/src/gui/gui-config-commands.js +2 -64
  69. package/dist/src/gui/gui-endpoint-commands.js +1 -1
  70. package/dist/src/gui/gui-endpoint-common.js +19 -1
  71. package/dist/src/gui/gui-operator-commands.js +21 -25
  72. package/dist/src/gui/gui-prompt-commands.js +2 -2
  73. package/dist/src/gui/gui-server.js +1 -2
  74. package/dist/src/gui/gui-team-commands.js +2 -1
  75. package/dist/src/history/history.js +4 -4
  76. package/dist/src/merge/merge-check-failures.js +12 -9
  77. package/dist/src/merge/merge-core.js +6 -31
  78. package/dist/src/merge/merge-drain.js +3 -2
  79. package/dist/src/merge/merge-post-review-drain.js +1 -1
  80. package/dist/src/merge/merge-queue-render.js +3 -3
  81. package/dist/src/merge/merge-stack.js +17 -18
  82. package/dist/src/merge/merge-to-main.js +13 -58
  83. package/dist/src/merge/merge-verify.js +4 -3
  84. package/dist/src/operator/operator-commands.js +4 -3
  85. package/dist/src/orchestrator/orchestrator-poll.js +18 -38
  86. package/dist/src/orchestrator/orchestrator-scheduling.js +5 -9
  87. package/dist/src/orchestrator/scheduling-scope.js +17 -26
  88. package/dist/src/orchestrator/scheduling-skip.js +9 -13
  89. package/dist/src/paths.js +2 -2
  90. package/dist/src/pi/pi-event-line.js +27 -0
  91. package/dist/src/pi/pi-listed-models.js +13 -0
  92. package/dist/src/pi/pi-stream.js +9 -2
  93. package/dist/src/pi/pi-watchdogs.js +31 -10
  94. package/dist/src/process/process-group.js +2 -21
  95. package/dist/src/process/process.js +12 -4
  96. package/dist/src/process/run-marker.js +2 -2
  97. package/dist/src/prompt/gate-prompts.js +1 -44
  98. package/dist/src/redeploy/redeployer.js +21 -1
  99. package/dist/src/review/diff-rules.js +35 -21
  100. package/dist/src/review/post-merge-review.js +47 -40
  101. package/dist/src/review/review-precheck.js +3 -3
  102. package/dist/src/review/review.js +13 -22
  103. package/dist/src/roles/legacy-role-migration.js +6 -3
  104. package/dist/src/roles/role-render.js +6 -32
  105. package/dist/src/roles/role-view.js +2 -13
  106. package/dist/src/run/ci-parity.js +19 -8
  107. package/dist/src/run/run-apply.js +0 -9
  108. package/dist/src/run/run-stage.js +6 -6
  109. package/dist/src/run/run-verdict.js +13 -4
  110. package/dist/src/run/stage-check.js +17 -24
  111. package/dist/src/runner/runner-leftover.js +9 -26
  112. package/dist/src/runner/runner-outcome.js +1 -1
  113. package/dist/src/runner/runner-pi.js +6 -12
  114. package/dist/src/runner/runner-recovery.js +4 -12
  115. package/dist/src/runner/runner-revision.js +1 -2
  116. package/dist/src/runner/runner-run.js +7 -16
  117. package/dist/src/runner/runner-state-load.js +6 -19
  118. package/dist/src/runner/runner-state.js +0 -14
  119. package/dist/src/scheduling/backoff.js +8 -3
  120. package/dist/src/scheduling/claim-entries.js +2 -1
  121. package/dist/src/status/status-budget.js +4 -43
  122. package/dist/src/status/status-data.js +34 -38
  123. package/dist/src/status/status-roles.js +1 -2
  124. package/dist/src/team/team-hold.js +7 -5
  125. package/dist/src/team/team-orchestrator-info.js +53 -21
  126. package/dist/src/team/team-polls.js +36 -86
  127. package/dist/src/text/datetime.js +16 -7
  128. package/dist/src/text/phrases.js +9 -0
  129. package/dist/src/text/suggest.js +1 -1
  130. package/dist/src/text/text.js +3 -2
  131. package/dist/src/ui/alert-feeds.js +0 -41
  132. package/dist/src/ui/badges.js +14 -75
  133. package/dist/src/ui/gui/gui-client-boot.js +0 -6
  134. package/dist/src/ui/gui/gui-client-drawer-config.js +1 -16
  135. package/dist/src/ui/gui/gui-client-feed.js +1 -1
  136. package/dist/src/ui/gui/gui-client-operator.js +7 -5
  137. package/dist/src/ui/gui/gui-client-team.js +8 -2
  138. package/dist/src/ui/progress-data.js +54 -4
  139. package/dist/src/ui/run-progress-model.js +12 -3
  140. package/dist/src/ui/status-payload.js +10 -25
  141. package/dist/src/ui/status-render.js +10 -17
  142. package/dist/src/ui/team-alert-backlog.js +15 -205
  143. package/dist/src/ui/team-alert-shared.js +6 -29
  144. package/dist/src/ui/team-alerts.js +4 -10
  145. package/dist/src/ui/tui/tui-backlog.js +2 -2
  146. package/dist/src/ui/tui/tui-editors.js +5 -4
  147. package/dist/src/ui/tui/tui-input.js +8 -6
  148. package/dist/src/ui/tui/tui-pane-activity.js +2 -1
  149. package/dist/src/ui/tui/tui-pane-health.js +21 -23
  150. package/dist/src/ui/tui/tui-pane-history.js +7 -5
  151. package/dist/src/ui/tui/tui-pane-pending.js +19 -15
  152. package/dist/src/ui/tui/tui-pane-session.js +4 -3
  153. package/dist/src/ui/tui/tui-panes.js +9 -1
  154. package/dist/src/ui/tui/tui.js +3 -5
  155. package/dist/src/verdict/fix-claim.js +36 -7
  156. package/dist/src/verdict/reply-contract.js +3 -4
  157. package/package.json +2 -2
  158. package/dist/src/review/review-followup.js +0 -87
  159. package/dist/src/review/review-run.js +0 -395
  160. /package/dist/src/cli/{brief-command.js → cli-brief-command.js} +0 -0
  161. /package/dist/src/cli/{config-commands.js → cli-config-commands.js} +0 -0
  162. /package/dist/src/cli/{log-commands.js → cli-log-commands.js} +0 -0
  163. /package/dist/src/cli/{notify-command.js → cli-notify-command.js} +0 -0
  164. /package/dist/src/cli/{question-commands.js → cli-question-commands.js} +0 -0
@@ -6,11 +6,11 @@
6
6
  * scope. */
7
7
  import { increment } from "../collections.js";
8
8
  import { DIRECTOR_ROLE, commitTier } from "../roles/roles.js";
9
+ import { HOUR_MS } from "../text/datetime.js";
9
10
  import { baseRoleOf, runnerEnabled, runnerPaused } from "../roles/runner-ids.js";
10
11
  import { hasOutstandingWork, saveRunnerStateBestEffort } from "../runner/runner-state.js";
11
12
  import { queuedMergeRoles } from "../merge/merge-queue.js";
12
13
  import { readMergeMarker, mergeChanges } from "../merge/merge-slot.js";
13
- import { isAfterMergeRole } from "../review/post-merge-review.js";
14
14
  import { aheadOfMainBranch, branchExists } from "../git/git.js";
15
15
  import { branchName } from "../paths.js";
16
16
  import { hasUnmergedPin } from "../runner/runner-leftover.js";
@@ -31,7 +31,7 @@ export function noteSkip(root, runner, reason) {
31
31
  * hasUnmergedPin director pin, the per-base claim-group build (with its claim-release loop,
32
32
  * which mutates runner state, persists and logs), and the writing count. */
33
33
  export async function buildSchedulingScope(ctx) {
34
- const { root, runners, mainBranch, merges, once, now, mainHead, userPaused, quietNow, pausedRoles, capPaused, maintenanceQuota, bootstrapHeld, budgetPausedRoles, probeRoles, reviewStrongPaused, afterMergeRoles, roleQuietHeld, heldProviders, windowHeldProviders, reviewHeld, roleProviders, openBugsNow, workBacklogOpen, planBacklogFull, holdForRestart, diskHeld, deferredDue, workMergedSince, } = ctx;
34
+ const { root, runners, mainBranch, merges, once, now, mainHead, userPaused, quietNow, pausedRoles, capPaused, maintenanceQuota, bootstrapHeld, budgetPausedRoles, probeRoles, roleQuietHeld, heldProviders, windowHeldProviders, roleProviders, openBugsNow, workBacklogOpen, planBacklogFull, holdForRestart, diskHeld, deferredDue, workMergedSince, } = ctx;
35
35
  // Merge-queue interlock data, listed ONCE per poll (was once per runner per poll — each
36
36
  // queuedMergeFiles() re-lists the merge-queue directory and re-stats every queued entry): the
37
37
  // check below only asks whether the runner's role has a queued entry. The queue changes
@@ -43,23 +43,22 @@ export async function buildSchedulingScope(ctx) {
43
43
  // clock, since its only other run is an operator prompt. A queued or in-flight pin is the
44
44
  // merge-queue interlock's to hold, so the leftover reason is not offered then.
45
45
  const pinnedDirector = !queuedRoles.has(DIRECTOR_ROLE) && (await hasUnmergedPin(root, DIRECTOR_ROLE));
46
- // Merge-queue interlock relief (parts 1-3/4): for a post-merge-review role — one whose own
47
- // config `review.afterMerge` names it — the queued/in-flight interlock is scoped to the stages
48
- // that actually race the author's branch. `interlockedHold` holds exactly the QUEUED post-merge
49
- // roles in a non-admissible stage: pre-approval (`verifying`, or queued but not yet picked up —
50
- // absent from the pipeline's approved/merge sets), conflict resolution (`resolve-wait`/
51
- // `resolving`, read from the live marker), or a branch already ahead of main (a prior relief
52
- // run's held commit). An approved-and-waiting or in-flight-merge queued change no longer parks
53
- // the author. Pre-merge-review roles keep the full interlock (their rejection must reach the
54
- // runner before it authors again), so they are never added here; scheduling-skip.ts skips a
55
- // queued role unless it is BOTH post-merge AND absent from interlockedHold.
46
+ // Merge-queue interlock relief (parts 1-3/4): the queued/in-flight interlock is scoped to
47
+ // the stages that actually race the author's branch. `interlockedHold` holds exactly the
48
+ // QUEUED roles in a non-admissible stage: pre-approval (`verifying`, or queued but not yet
49
+ // picked up — absent from the pipeline's approved/merge sets), conflict resolution
50
+ // (`resolve-wait`/`resolving`, read from the live marker), or a branch already ahead of main
51
+ // (a prior relief run's held commit). An approved-and-waiting or in-flight-merge queued
52
+ // change no longer parks the author. The relief applies team-wide — no role waits on a
53
+ // reviewer — so every queued role is held only while it is in interlockedHold;
54
+ // scheduling-skip.ts skips a queued role unless it is absent from that set.
56
55
  const interlockedHold = new Set();
57
56
  if (queuedRoles.size > 0) {
58
57
  const marker = readMergeMarker(root);
59
58
  const markerChanges = marker ? mergeChanges(marker) : [];
60
59
  for (const runner of runners) {
61
60
  const role = runner.role;
62
- if (!queuedRoles.has(role) || !isAfterMergeRole(runner.config, role))
61
+ if (!queuedRoles.has(role))
63
62
  continue;
64
63
  const inApproved = merges.approved.has(role);
65
64
  const inMerge = (merges.merge?.roles ?? []).includes(role);
@@ -133,7 +132,7 @@ export async function buildSchedulingScope(ctx) {
133
132
  const reason = released;
134
133
  logEventBestEffort(root, { source: r.role, type: "claim", action: "released", title, reason });
135
134
  if (reason === "stale") {
136
- warnEventBestEffort(root, r.role, `released "${title}", which a stopped instance was working on (idle ${Math.round(CLAIM_IDLE_MAX_MS / 3_600_000)}h)`);
135
+ warnEventBestEffort(root, r.role, `released "${title}", which a stopped instance was working on (idle ${Math.round(CLAIM_IDLE_MAX_MS / HOUR_MS)}h)`);
137
136
  }
138
137
  }
139
138
  claimGroups.set(base, {
@@ -151,15 +150,10 @@ export async function buildSchedulingScope(ctx) {
151
150
  // The per-role windows (quietHoursPerRole) fold in beside the team one as a fourth
152
151
  // disjunct — a role held by either window (or both, held once) starts no new runs;
153
152
  // the director stays exempt by the same role check that covers the other disjuncts.
154
- // The budget hold, per role (part 5c/8): a tier that resolved to pause holds its own roles,
155
- // and — with review on — an unresolvable strong tier holds every role a pre-merge review
156
- // gates (nothing could merge) — except a role on `review.afterMerge`, whose review runs
157
- // after merging, so it keeps authoring. The probe of a demoted pair pierces the hold for
158
- // EXACTLY the probed pair's tier's roles: the earlier draft's pair-blind pierce lifted the
159
- // pause team-wide on any due probe.
160
- const budgetHolds = (role) => (budgetPausedRoles.has(role) ||
161
- (reviewStrongPaused && !afterMergeRoles.has(baseRoleOf(role)))) &&
162
- !probeRoles.has(role);
153
+ // The budget hold, per role (part 5c/8): a tier that resolved to pause holds its own
154
+ // roles. The probe of a demoted pair pierces the hold for EXACTLY the probed pair's tier's
155
+ // roles: the earlier draft's pair-blind pierce lifted the pause team-wide on any due probe.
156
+ const budgetHolds = (role) => budgetPausedRoles.has(role) && !probeRoles.has(role);
163
157
  const operatorPauseBlocks = (role) => (userPaused || quietNow || roleQuietHeld.has(role) || budgetHolds(role)) &&
164
158
  role !== DIRECTOR_ROLE;
165
159
  // Fresh operator demand: a queued prompt or a wake newer than the role's last run end. The
@@ -213,12 +207,9 @@ export async function buildSchedulingScope(ctx) {
213
207
  bootstrapHeld,
214
208
  budgetPausedRoles,
215
209
  probeRoles,
216
- reviewStrongPaused,
217
- afterMergeRoles,
218
210
  roleQuietHeld,
219
211
  heldProviders,
220
212
  windowHeldProviders,
221
- reviewHeld,
222
213
  roleProviders,
223
214
  openBugsNow,
224
215
  workBacklogOpen,
@@ -1,7 +1,6 @@
1
1
  import { logEventBestEffort } from "../events/events.js";
2
2
  import { baseRoleOf, configuredInstances, runnerPaused } from "../roles/runner-ids.js";
3
3
  import { BUGFIX_ROLE, DIRECTOR_ROLE, commitTier } from "../roles/roles.js";
4
- import { isAfterMergeRole } from "../review/post-merge-review.js";
5
4
  import { deferRunReason, isEligible } from "../scheduling/scheduling.js";
6
5
  import { inboxSize } from "../inbox/inbox.js";
7
6
  import { freshlyWoken } from "../runner/runner-state.js";
@@ -14,7 +13,7 @@ import { noteSkip } from "./scheduling-scope.js";
14
13
  * deferredDue, quotaAdmitted, once-mode settlement — and writes skip reasons as its only
15
14
  * side effects. */
16
15
  export async function skipRunner(scope, runner) {
17
- const { root, once, now, mainHead, pausedRoles, capPaused, holdForRestart, diskHeld, windowHeldProviders, roleProviders, reviewHeld, afterMergeRoles, heldProviders, openBugsNow, workBacklogOpen, planBacklogFull, deferredDue, workMergedSince, queuedRoles, interlockedHold, pinnedDirector, claimGroups, writing, maintenanceQuota, maintenanceQuotaOverLine, bootstrapHeldNow, operatorPauseBlocks, } = scope;
16
+ const { root, once, now, mainHead, pausedRoles, capPaused, holdForRestart, diskHeld, windowHeldProviders, roleProviders, heldProviders, openBugsNow, workBacklogOpen, planBacklogFull, deferredDue, workMergedSince, queuedRoles, interlockedHold, pinnedDirector, claimGroups, writing, maintenanceQuota, maintenanceQuotaOverLine, bootstrapHeldNow, operatorPauseBlocks, } = scope;
18
17
  // The role's inbox size and operator demand, computed once per runner per poll: every
19
18
  // consumer below (the holds, isEligible's inbox count, the maintenance admission) shares
20
19
  // this one directory listing + per-file stat read instead of each re-scanning the queue.
@@ -73,10 +72,8 @@ export async function skipRunner(scope, runner) {
73
72
  // re-queue every poll until the repeated-failure pause stops it.
74
73
  if (runner.role === DIRECTOR_ROLE && windowHeldProviders.has(roleProviders.get(runner.role)))
75
74
  return { skip: true };
76
- if (runner.role !== DIRECTOR_ROLE &&
77
- (heldProviders.has(roleProviders.get(runner.role)) ||
78
- (reviewHeld && !afterMergeRoles.has(baseRoleOf(runner.role)))))
79
- return { skip: true }; // nor while ITS provider's failure storm holds — or the reviewer's, which a pre-merge review gates (a review.afterMerge role is exempt)
75
+ if (runner.role !== DIRECTOR_ROLE && heldProviders.has(roleProviders.get(runner.role)))
76
+ return { skip: true }; // nor while ITS provider's failure storm holds — the reviewer's hold parks only the post-merge review queue, never a role start
80
77
  // The role's OWN queue decides inbox due-ness: the director counts its historical
81
78
  // inbox, every other role its per-role queue (tumwater prompt --role <id>) — so a
82
79
  // queued prompt makes its role due by itself, no wake marker needed (isEligible).
@@ -113,14 +110,13 @@ export async function skipRunner(scope, runner) {
113
110
  // results — but the merge's outcome replaces it before the interlock lets the role back into
114
111
  // this pass), and skipping here saves that branch's workMergedSince git-range query for the
115
112
  // skipped role.
116
- // Interlock relief (parts 1-3/4): a post-merge-review role (its own config `review.afterMerge`
117
- // names it) with a queued change is held only while it is in a non-admissible stage — the
118
- // pre-approval/conflict/branch-ahead holds buildSchedulingScope put in `interlockedHold` — and
119
- // otherwise falls through to author (the merge no longer parks it). A pre-merge-review role,
120
- // and a post-merge role still in a held stage, keep the full interlock: their rejection must
121
- // reach the runner before it authors again.
113
+ // Interlock relief (parts 1-3/4): a queued role is held only while it is in a non-admissible
114
+ // stage — the pre-approval/conflict/branch-ahead holds buildSchedulingScope put in
115
+ // `interlockedHold` — and otherwise falls through to author (the merge no longer parks it).
116
+ // A role still in a held stage keeps the full interlock: its rejection must reach the runner
117
+ // before it authors again. The relief now applies team-wide: no role waits on a reviewer.
122
118
  if (queuedRoles.has(runner.role)) {
123
- if (!isAfterMergeRole(runner.config, runner.role) || interlockedHold.has(runner.role)) {
119
+ if (interlockedHold.has(runner.role)) {
124
120
  noteSkip(root, runner, undefined);
125
121
  return { skip: true };
126
122
  }
package/dist/src/paths.js CHANGED
@@ -164,8 +164,8 @@ export function roleNotesPath(root, role) {
164
164
  export function mergeStatePath(root) {
165
165
  return path.join(tumwaterDir(root), "state", "merging.json");
166
166
  }
167
- /** Merged commits awaiting their review after merging (src/review/post-merge-review.ts), for roles
168
- * listed in `review.afterMerge`: `{ pending: PostReview[] }`. Runtime state, never committed. */
167
+ /** Merged commits awaiting their review after merging (src/review/post-merge-review.ts):
168
+ * `{ pending: PostReview[] }`. Runtime state, never committed. */
169
169
  export function postReviewPath(root) {
170
170
  return path.join(tumwaterDir(root), "state", "post-review.json");
171
171
  }
@@ -76,6 +76,33 @@ export function messageUpdateHasContent(event) {
76
76
  return false;
77
77
  return isNonBlankString(update.delta);
78
78
  }
79
+ /** Fold one pi event into the pending-reply state and return the new state — the single
80
+ * definition both observers apply (see PendingReply). An assistant `message_start` opens a
81
+ * stretch stamped `now`, or counts one more attempt of an open one. A `message_update` whose
82
+ * delta carries content (`hasContent`: each observer decides for itself whether a delta is worth
83
+ * parsing) or an assistant `message_end` that did not fail closes it: the model answered. A failed
84
+ * or aborted end keeps it open, because pi's retry that follows is the same unanswered request. */
85
+ export function foldPendingReply(pending, event, { hasContent = false, now = Date.now() } = {}) {
86
+ const msg = event.message;
87
+ switch (event.type) {
88
+ case "message_start": {
89
+ if (msg?.role !== "assistant")
90
+ return pending;
91
+ if (pending)
92
+ return { ...pending, attempts: pending.attempts + 1 };
93
+ const target = [msg.provider, msg.model].filter(isNonBlankString).join("/");
94
+ return { since: now, target, attempts: 1 };
95
+ }
96
+ case "message_update":
97
+ return hasContent ? undefined : pending;
98
+ case "message_end":
99
+ if (msg?.role !== "assistant")
100
+ return pending;
101
+ return msg.stopReason === "error" || msg.stopReason === "aborted" ? pending : undefined;
102
+ default:
103
+ return pending;
104
+ }
105
+ }
79
106
  /** The call's full raw command text from a tool-execution event's args (bash-like tools name
80
107
  * it `command`, some `cmd`; other tools yield ""). The two open-call trackers
81
108
  * (src/pi/pi-watchdogs.ts's stall warning, src/ui/progress-data.ts's dashboard flag) store this
@@ -1,4 +1,5 @@
1
1
  import { readJsonFile, writeJsonAtomic } from "../files/json-files.js";
2
+ import { cachedByStat } from "../files/stat-cache.js";
2
3
  import { piListedModelsPath } from "../paths.js";
3
4
  /** The whitespace-split rows of the table `pi --list-models` prints, header first. Null unless
4
5
  * the first non-blank line is the `provider model …` header, so other text (a "No models
@@ -33,8 +34,20 @@ export function parsePiModelImages(stdout) {
33
34
  }
34
35
  return images;
35
36
  }
37
+ /** Per-poll cache of the parsed listing, keyed by file path: the status snapshot reads it once
38
+ * per poll through collectRoleRows (src/status/status-roles.ts) while the file changes only when
39
+ * doctor runs `pi --list-models` and rewrites it, so an unchanged file costs one stat per poll
40
+ * instead of a re-read plus JSON.parse. Any write invalidates via dev/ino/mtime/size
41
+ * (stat-cache.cachedByStat, same freshness check as the other polled files); a missing or
42
+ * malformed file yields null and is not cached, so a mid-edit broken file recovers on the next
43
+ * poll exactly like before. */
44
+ const listedCache = new Map();
36
45
  /** The saved listing, or null when the file is missing, torn, or has no `images` object. */
37
46
  export function readPiListedModels(root) {
47
+ return cachedByStat(listedCache, piListedModelsPath(root), // Keyed by path so distinct roots and test files never collide.
48
+ piListedModelsPath(root), () => readPiListedModelsUncached(root), (listed) => ({ ...listed, images: { ...listed.images } }));
49
+ }
50
+ function readPiListedModelsUncached(root) {
38
51
  const saved = readJsonFile(piListedModelsPath(root));
39
52
  const images = saved?.images;
40
53
  if (typeof images !== "object" || images === null || Array.isArray(images))
@@ -1,5 +1,5 @@
1
1
  import { extractRefusal, hasVerdictLine, isNegatedRefusal, isNothingToDo } from "../verdict/reply-contract.js";
2
- import { applyToolExecutionEvent, messageUpdateHasContent, piEventType, toolCallCommand, toolUpdateHasContent, } from "./pi-event-line.js";
2
+ import { applyToolExecutionEvent, foldPendingReply, messageUpdateHasContent, piEventType, toolCallCommand, toolUpdateHasContent, } from "./pi-event-line.js";
3
3
  import { describeToolCall } from "../text/phrases.js";
4
4
  import { objectOrEmpty, nonNegativeNumber, parseJsonObject, isJsonObject } from "../files/json-object.js";
5
5
  import { backendKind, isBackendFailureKind, isPermanentConfigError, TRANSIENT_BACKEND } from "./pi-failure.js";
@@ -204,6 +204,10 @@ export class PiStreamParser {
204
204
  * empty-content update right after start, and a content-free keepalive must not mask a hang.
205
205
  * Feeds runPi's stall warning; entries clear at tool_execution_end. */
206
206
  openToolCalls = [];
207
+ /** The model request pi has sent and the provider has not yet answered (see PendingReply), or
208
+ * undefined. Feeds runPi's unanswered-request warning; stamped with this parser's clock, since
209
+ * it observes the request live. */
210
+ pendingReply = undefined;
207
211
  /** Read tool calls started but not yet ended, keyed by pi's toolCallId so concurrent reads
208
212
  * attribute their end to the right start (pi runs one message's tool calls concurrently, so
209
213
  * several can be open at once and end in completion order — the same rule
@@ -369,6 +373,7 @@ export class PiStreamParser {
369
373
  if (event.type === "billing" && (event.billing === "subscription" || event.billing === "api"))
370
374
  this.billing = event.billing;
371
375
  this.countProgress(event);
376
+ this.pendingReply = foldPendingReply(this.pendingReply, event);
372
377
  this.applyToolExecution(event);
373
378
  if (event.type !== "message_end" || event.message?.role !== "assistant")
374
379
  return;
@@ -383,8 +388,10 @@ export class PiStreamParser {
383
388
  // Nothing else in this parser acts on the type, so the line is done either way.
384
389
  applyMessageUpdate(line) {
385
390
  if (piEventType(line) === "message_update") {
386
- if (messageUpdateHasContent(parseJsonObject(line)))
391
+ const hasContent = messageUpdateHasContent(parseJsonObject(line));
392
+ if (hasContent)
387
393
  this.progressCount += 1;
394
+ this.pendingReply = foldPendingReply(this.pendingReply, { type: "message_update" }, { hasContent });
388
395
  return true;
389
396
  }
390
397
  return false;
@@ -1,5 +1,6 @@
1
1
  /** The run's watchdog clocks, split out of pi.ts's runPi (2026-10-04, organize): the run
2
- * deadline and the quiet watchdog (quiet-kill plus the stalled-tool-call warning) — the
2
+ * deadline and the quiet watchdog (quiet-kill plus the stalled-tool-call and
3
+ * unanswered-model-request warnings) — the
3
4
  * timing policy of one pi run, which changes for different reasons than the spawn, stream,
4
5
  * and result-distillation wiring that drives it (src/agent/agent-run.ts keeps those). The
5
6
  * factory owns all the mutable state the two timers kept in runPi's closure (the progress
@@ -85,9 +86,13 @@ function startDeadlineWatch(state, deps) {
85
86
  };
86
87
  state.timeout = setTimeout(fireDeadline, deps.runTimeoutMs);
87
88
  }
89
+ /** Whole minutes read cleaner in the feed; sub-minute thresholds stay in seconds. */
90
+ function silenceLabel(ms) {
91
+ return ms < 60_000 ? `${Math.round(ms / 1000)}s` : `${Math.round(ms / 60_000)}m`;
92
+ }
88
93
  /** The quiet/stall clock: quiet-kills a run that stopped making progress and warns on
89
- * stalled tool calls, on one interval against the wall clock (BUGS.md 2026-09-23,
90
- * 2026-09-28, 2026-09-29, 2026-10-06). */
94
+ * stalled tool calls and unanswered model requests, on one interval against the wall clock
95
+ * (BUGS.md 2026-09-23, 2026-09-28, 2026-09-29, 2026-10-06, 2026-10-29). */
91
96
  function startQuietWatch(state, deps) {
92
97
  // Quiet watchdog: a healthy run makes PROGRESS continuously even when slow — messages
93
98
  // start and end, turns and tool calls complete. Prolonged lack of progress means a hung
@@ -154,21 +159,35 @@ function startQuietWatch(state, deps) {
154
159
  const bufferedStallMs = bufferedCommandStallMs(deps.stallMs);
155
160
  if (openMs >= bufferedStallMs) {
156
161
  warnedStalledCalls.add(call.id);
157
- deps.onToolCallStalled?.(`tool call stalled: ${call.label} — no exit for ${Math.round(openMs / 60_000)}m`);
162
+ deps.onStallWarning?.(`tool call stalled: ${call.label} — no exit for ${silenceLabel(openMs)}`);
158
163
  }
159
164
  continue;
160
165
  }
161
166
  const silentMs = Date.now() - call.lastActivityAt;
162
167
  if (silentMs >= deps.stallMs) {
163
168
  warnedStalledCalls.add(call.id);
164
- // Whole minutes read cleaner in the feed; sub-minute thresholds stay in seconds.
165
- const silent = silentMs < 60_000
166
- ? `${Math.round(silentMs / 1000)}s`
167
- : `${Math.round(silentMs / 60_000)}m`;
168
- deps.onToolCallStalled?.(`tool call stalled: ${call.label} — no output for ${silent}`);
169
+ deps.onStallWarning?.(`tool call stalled: ${call.label} — no output for ${silenceLabel(silentMs)}`);
169
170
  }
170
171
  }
171
172
  };
173
+ // The unanswered-request warning, the model-side twin of the stall warning: a provider can
174
+ // accept a request and never answer it (BUGS.md 2026-10-29: deepinfra's DeepSeek-V4.1-Flash
175
+ // sent plan only SSE keepalives, which pi never surfaces). pi then waits out its own idle
176
+ // timeout and retries, and each retry is progress to the quiet watchdog, so nothing else
177
+ // names the hang for hours. Like the stall warning it only warns: a slow local prefill can
178
+ // legitimately run this long, and pi's own timeout still owns each attempt. One warning per
179
+ // unanswered stretch, keyed by its start, not one per retry.
180
+ let warnedReplySince;
181
+ const warnUnansweredReply = () => {
182
+ const pending = deps.pendingReply?.();
183
+ if (!pending || pending.since === warnedReplySince)
184
+ return;
185
+ const waitedMs = Date.now() - pending.since;
186
+ if (waitedMs < deps.stallMs)
187
+ return;
188
+ warnedReplySince = pending.since;
189
+ deps.onStallWarning?.(`model request unanswered: ${pending.target || "model"} — no reply for ${silenceLabel(waitedMs)}`);
190
+ };
172
191
  const checkEveryMs = deps.quietMs > 0 ? deps.quietMs : deps.stallMs;
173
192
  state.quietCheck =
174
193
  checkEveryMs > 0
@@ -181,8 +200,10 @@ function startQuietWatch(state, deps) {
181
200
  state.quietKilled = true;
182
201
  deps.kill();
183
202
  }
184
- if (deps.stallMs > 0)
203
+ if (deps.stallMs > 0) {
185
204
  warnStalledToolCalls();
205
+ warnUnansweredReply();
206
+ }
186
207
  }, Math.min(Math.max(checkEveryMs / 2, 250), 30_000))
187
208
  : undefined;
188
209
  }
@@ -1,26 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
- import { captureCappedOutput, releaseChildHandles, signalTree, withoutLaunchServicesCheckIn } from "./process.js";
2
+ import { captureCappedOutput, KILL_GRACE_MS, releaseChildHandles, signalTree, withoutLaunchServicesCheckIn, } from "./process.js";
3
+ export { KILL_GRACE_MS };
3
4
  import { errCode } from "../errno.js";
4
- /** The detached process-group runner: runScriptGroup starts a command in its own process
5
- * group — exactly like pi — and settles exactly once, bounding a timed-out tree at its
6
- * deadline plus the SIGTERM → SIGKILL escalation grace. Split out of process.ts, whose other
7
- * residents (the exec helper, the liveness and process-table probes, the LaunchServices
8
- * preload) are generic child-process plumbing shared across the harness: this runner's two
9
- * runtime consumers both sit in the build boundary — the build check (build/build-check.ts)
10
- * and the lockfile install (build/dep-install.ts) — and its result carries the build check's
11
- * run record, so it lives beside that boundary instead of inside the shared module. The
12
- * signals it escalates with come from process.ts's signalTree; the children it starts carry
13
- * withoutLaunchServicesCheckIn's preload, so its npm trees check in with launchservicesd
14
- * neither on macOS nor anywhere else. */
15
- /** SIGTERM → SIGKILL escalation window once a run's timeout has FIRED: the whole process
16
- * group gets SIGTERM, and anything still alive this much later (a SIGTERM-trapping runner, a
17
- * wedged worker) is SIGKILLed — and the run settles then, whether or not the tree ever closed
18
- * its pipes, so a timed-out run is bounded at its deadline plus this grace. The default of
19
- * runBuildCheck's killGraceMs parameter (build/build-check.ts), which tests shrink — pinning that
20
- * the escalation is armed on timeout (never at spawn: a healthy run that merely outlasts the
21
- * grace period must run to completion), that a surviving grandchild is taken down before the
22
- * run settles, and that a tree the SIGTERM already took down does not wait out the grace. */
23
- export const KILL_GRACE_MS = 10_000;
24
5
  /** True while any process in the group led by `pid` still exists: a signal-0 probe of the
25
6
  * group, where EPERM still means a member exists. armGroupDeadline probes with it for both
26
7
  * detached-process-group runners (runScriptGroup and git-run's execGitBounded), whose
@@ -88,10 +88,18 @@ export async function identityAlive(id) {
88
88
  const now = await pidIdentity(id.pid);
89
89
  return now !== null && now.start === id.start;
90
90
  }
91
+ /** SIGTERM → SIGKILL escalation window: how long a SIGTERM is given to take a process tree
92
+ * down before whatever survived is SIGKILLed. The one value behind every harness escalation
93
+ * — terminateChild's group kill here, the run-marker sweep's orphan kill, and the detached
94
+ * process-group runner (whose own `KILL_GRACE_MS` re-exports it, process-group.ts) — so a
95
+ * team-wide teardown, an end-of-run sweep, and a timed-out build check all grant the same
96
+ * grace and the literal cannot drift between them. 10 s is enough for a well-behaved tree to
97
+ * exit on SIGTERM; a SIGTERM-trapping straggler is SIGKILLed after it. */
98
+ export const KILL_GRACE_MS = 10_000;
91
99
  /** Terminate a detached child and everything it started: SIGTERM to the process group now,
92
- * escalating to SIGKILL after 10 s if any of it is still alive. The child is spawned detached
93
- * (its own process group leader — runPi does this for pi), so a negative PID reaches every
94
- * tool-call grandchild — which a single-PID kill leaves orphaned to launchd — while the
100
+ * escalating to SIGKILL after KILL_GRACE_MS if any of it is still alive. The child is spawned
101
+ * detached (its own process group leader — runPi does this for pi), so a negative PID reaches
102
+ * every tool-call grandchild — which a single-PID kill leaves orphaned to launchd — while the
95
103
  * harness's own group is never in the blast radius. Shared by the run-timeout,
96
104
  * quiet-watchdog, and harness-shutdown kills, and by the sweep every run gets once pi exits
97
105
  * (runPi's 'exit' handler), when the group holds only what pi's tool calls backgrounded.
@@ -106,7 +114,7 @@ export async function identityAlive(id) {
106
114
  * by it. */
107
115
  export function terminateChild(child) {
108
116
  if (signalTree(child, "SIGTERM"))
109
- setTimeout(() => signalTree(child, "SIGKILL"), 10_000).unref();
117
+ setTimeout(() => signalTree(child, "SIGKILL"), KILL_GRACE_MS).unref();
110
118
  }
111
119
  /** Signal the child's whole process group, falling back to the child alone when the group is
112
120
  * already gone or the platform has no negative-PID kill (Windows). Returns whether the signal
@@ -11,7 +11,7 @@ import crypto from "node:crypto";
11
11
  import fs from "node:fs";
12
12
  import path from "node:path";
13
13
  import { agree, plural } from "../text/phrases.js";
14
- import { execFileAsync, withoutLaunchServicesCheckIn } from "./process.js";
14
+ import { execFileAsync, KILL_GRACE_MS, withoutLaunchServicesCheckIn } from "./process.js";
15
15
  /** Every lookup normally finishes in well under a second; a wedged one must not hang
16
16
  * its caller — the same ceiling process-table.ts's probe lookups carry. */
17
17
  const PS_ENVIRON_TIMEOUT_MS = 10_000;
@@ -244,7 +244,7 @@ export async function sweepRunMarker(marker) {
244
244
  // Already gone.
245
245
  }
246
246
  }
247
- }, 10_000).unref();
247
+ }, KILL_GRACE_MS).unref();
248
248
  }
249
249
  return signaled;
250
250
  }
@@ -156,7 +156,7 @@ ${TEST_RUNNER_RULE}${noCheckRunRule}
156
156
  * revision of a previously rejected change (plans/revise-rejected.md part 2/2): it names the round
157
157
  * and shows the prior objections plus the interdiff so the re-review checks each one first.
158
158
  * Omitted, the prompt is unchanged from a fresh change's. `postMerge` marks the post-merge review
159
- * of a commit already on main (review.afterMerge): a finding the reviewer can repair is the work —
159
+ * of a commit already on main: a finding the reviewer can repair is the work —
160
160
  * it makes the minimal fix in the worktree, leaves the edit, and ends with the verdict line plus a
161
161
  * `FIX:` line — so the instruction and the repair rule render only for that caller, and every other
162
162
  * (pre-merge) caller's prompt is byte-identical. */
@@ -286,49 +286,6 @@ ${TEST_RUNNER_RULE}
286
286
  FIX: <files you changed>` : ""}`);
287
287
  return parts.join("\n\n");
288
288
  }
289
- /** The prompt for the next attempt at a review whose previous run hit its time budget while
290
- * still making progress (RunnerState.reviewResume): that run continues the timed-out reviewer's
291
- * own session (`--continue`), so the diff and everything the reviewer already read are in
292
- * context. This prompt carries no diff — re-sending it would defeat the resume — and names the
293
- * frozen comparison base and the unchanged patch-id so the reviewer knows the change it was
294
- * judging has not moved. `baseRev` is changeBaseRev's frozen revision (see buildReviewPrompt);
295
- * `patchId` is git/git.ts's patchId for the change. It closes with the same VERDICT_ENDING
296
- * contract as the full review prompt, so the accepted forms cannot drift. */
297
- export function buildReviewResumePrompt(baseRev, patchId) {
298
- return `${dateLine()}
299
-
300
- You are resuming an adversarial review of a tumwater change: the previous attempt hit its time budget while still making progress, and this run continues that same reviewer session. Everything you already read — the diff and the files you checked — is in your context; do not re-read it.
301
-
302
- The change is unchanged since that attempt (patch-id ${patchId}) and is still measured against ${shortSha(baseRev)}. Other roles merge on main while you review, so compare against ${shortSha(baseRev)}, never against \`main\`.
303
-
304
- Finish the checks you had not completed, then end your reply with exactly one line in this form:
305
- ${VERDICT_ENDING.replace(/\n/g, "\n ")}`;
306
- }
307
- /** The one-turn follow-up sent into the REVIEWER's own session (--continue) when its run
308
- * completed but the reply carried no parseable VERDICT line — the review-gate sibling of
309
- * prompt-followup.ts's buildSummaryRequestPrompt. The session already holds the full review, so one
310
- * short reply recovers the verdict the gate needs without paying a second full review run;
311
- * the caller bounds the run tightly and counts the strike against the HEAD only when this
312
- * too yields nothing (BUGS.md 2026-09-29). It shares the review prompt's closing rule
313
- * (reply-contract.ts's VERDICT_ENDING), so the accepted forms cannot drift between the prompts. */
314
- export function buildVerdictRequestPrompt() {
315
- return `Your review reply above did not include the verdict line tumwater parses, so
316
- your judgment was lost. Reply now with ONLY the closing block — no tool calls, no other text:
317
- one line in this form:
318
- ${VERDICT_ENDING}`;
319
- }
320
- /** The no-re-run nudge (BUGS.md 2026-10-02): the reviewer broke the prompt's no-re-run rule
321
- * despite a green pre-check, so this turn on its own session names the exact tool call and
322
- * asks it to finish the review from what it already read. The reviewer's only output channel
323
- * is the verdict, so the closing rule names both accepted forms like the review prompt does. */
324
- export function buildNoRerunPrompt(rerun) {
325
- return `You started a tool call tumwater's pre-check already covered, so it must not run:
326
- ${rerun}
327
- The full check passed at this exact tree before your review began. Do not re-run it — not in
328
- this worktree, not in a scratch copy. Finish the review now from what you have already read:
329
- reply with ONLY the closing block — no tool calls, no other text — one line in this form:
330
- ${VERDICT_ENDING}`;
331
- }
332
289
  /** The one-turn follow-up sent into a run's OWN session (--continue) when the harness's
333
290
  * pre-queue self-check found problems likely to get the change rejected. Only some findings are
334
291
  * the merge gate's own deterministic checks; the rest (path drift, plan dependencies) are
@@ -1,6 +1,7 @@
1
1
  import { TUMWATER_SOURCE } from "../events/events.js";
2
2
  import { errorMessage, stripTerminalControls } from "../text/text.js";
3
3
  import { shortSha } from "../text/format.js";
4
+ import { HOUR_MS } from "../text/datetime.js";
4
5
  import { mainRedPhrase } from "../text/phrases.js";
5
6
  import { RESTART_COOLDOWN_HOURS, RESTART_COOLDOWN_MS, RESTART_DRAIN_MAX_MS, RESTART_URGENT_COOLDOWN_MIN, RESTART_URGENT_COOLDOWN_MS, STALE_ESCALATE_AFTER_MS, STALE_ESCALATE_EVERY_MS, } from "./redeploy-policy.js";
6
7
  import { PrewarmProbes, track } from "./redeploy-probes.js";
@@ -39,6 +40,10 @@ export class Redeployer {
39
40
  restartRecord;
40
41
  lastHead = null;
41
42
  staleness = null;
43
+ /** Main's tip as noteTip last saw it, and the build's staleness against it. Differs from
44
+ * lastHead only while redeploy's target is an older passing commit (redeployTarget). */
45
+ lastTip = null;
46
+ tipStaleness = null;
42
47
  /** The head a restart is pending for. */
43
48
  pendingHead = null;
44
49
  /** When the team's current unbroken hold began — 0 when it is not being held. The drain
@@ -192,9 +197,24 @@ export class Redeployer {
192
197
  else if (this.refusedReason !== null)
193
198
  s.restartBlocked = `the update could not start: ${this.refusedReason}`;
194
199
  }
200
+ // A tip whose code no passing commit carries yet: nothing above can say so, since the
201
+ // target is the newest passing commit and the build is current against it.
202
+ if (!s.stale && this.lastTip !== null && this.lastTip !== this.lastHead && this.tipStaleness?.stale)
203
+ s.waitingForCheck = { head: this.lastTip, aheadCommits: this.tipStaleness.aheadCommits };
195
204
  }
196
205
  return s;
197
206
  }
207
+ /** Record main's tip beside the redeploy target poll is given. When the main watch verifies
208
+ * main, the target is the newest commit that passed main's check, so a tip whose check keeps
209
+ * timing out or failing leaves the target — and with it `stale` — behind; status() then
210
+ * publishes the tip as waitingForCheck. Computes the tip's staleness once per moved tip, and
211
+ * not at all on a project that is not the harness itself. */
212
+ async noteTip(tip) {
213
+ if (!this.selfHosted || tip === this.lastTip)
214
+ return;
215
+ this.lastTip = tip;
216
+ this.tipStaleness = tip === "" ? null : await this.deps.staleness(tip);
217
+ }
198
218
  /** When the current post-restart cooldown expires (epoch ms), or 0 when none is running. */
199
219
  cooldownUntil() {
200
220
  return this.lastAutoRestartAt !== null ? this.lastAutoRestartAt + RESTART_COOLDOWN_MS : 0;
@@ -617,7 +637,7 @@ export class Redeployer {
617
637
  if (this.lastEscalationAt !== null && now - this.lastEscalationAt < STALE_ESCALATE_EVERY_MS)
618
638
  return;
619
639
  this.lastEscalationAt = now;
620
- const hours = Math.max(1, Math.round((now - since) / 3_600_000));
640
+ const hours = Math.max(1, Math.round((now - since) / HOUR_MS));
621
641
  this.warn(`an update has waited ~${hours} h to install (running ${shortSha(this.build.sha)}, ${this.staleness?.aheadCommits ?? 0} commits behind main) while update attempts keep failing — the stuck version itself is the problem, not any one commit`);
622
642
  }
623
643
  /** Log one warning event for the harness loop — the shape the class's warn sites share. */
@@ -1,17 +1,23 @@
1
- /** The review gate's five deterministic diff rules, in the gate's own order and scope — the one
2
- * call site both the gate (review.ts) and the main watch (main-watch.ts) use, so a finding reads
3
- * the same on a changed tree and on main's tip. `baseRev` is a commit or branch name the async
1
+ /** The deterministic diff rules the review gate and the main watch share, each run in its own
2
+ * `scope` and order — the one call site both the gate (review.ts) and the main watch
3
+ * (main-watch.ts) use, so a finding reads the same on a changed tree and on main's tip.
4
+ * `baseRev` is a commit or branch name the async
4
5
  * rules resolve with changeBaseRev (merge-base of HEAD and it), so the watch passes a commit
5
- * while the gate passes the main branch. Runs conflictMarkerReason, then protectedEditReason,
6
- * then secretLeakReason, then — only for an exempt (md-only) diff — falseFixReason, then
7
- * backlogStructureReason for every diff, short-circuiting on the first finding exactly as the
8
- * original gate did: a later rule never runs once an earlier one already rejects. Returns a
9
- * one-reason array when a rule fires (the reason the gate rejects on and the watch reports) and
10
- * `[]` when nothing is wrong. An empty `role` (the watch cannot name the tip's merging role) is
11
- * no basis for calling a PRINCIPLES.md edit unauthorized, so the role-dependent half of the
12
- * protected-edit rule is skipped — but its role-independent half, the brief-block rule
13
- * (briefEditReason), still runs, so a brief edit on an unattributed head is still reported; the
14
- * gate always passes a known role, so its rejections are unchanged.
6
+ * while the gate passes the main branch. The final `scope` argument picks which set runs and in
7
+ * what order: `"watch"` runs all five — conflictMarkerReason, then protectedEditReason, then
8
+ * secretLeakReason, then — only for an exempt (md-only) diff — falseFixReason, then
9
+ * backlogStructureReason for every diff — while `"gate"` (the pre-merge gate) runs only the
10
+ * three a later commit cannot repair: briefEditReason, protectedEditReason, then
11
+ * secretLeakReason. A conflict marker, a false fix claim and a broken backlog structure can all
12
+ * be repaired by a later commit, so they stop refusing a diff pre-merge and the main watch
13
+ * reports them on main's tip instead. Both scopes short-circuit on their first finding exactly
14
+ * as the original gate did: a later rule never runs once an earlier one already rejects.
15
+ * Returns a one-reason array when a rule fires (the reason the gate rejects on and the watch
16
+ * reports) and `[]` when nothing is wrong. An empty `role` (the watch cannot name the tip's
17
+ * merging role) is no basis for calling a PRINCIPLES.md edit unauthorized, so the
18
+ * role-dependent half of the protected-edit rule is skipped — but its role-independent half,
19
+ * the brief-block rule (briefEditReason), still runs, so a brief edit on an unattributed head
20
+ * is still reported; the gate always passes a known role, so its rejections are unchanged.
15
21
  *
16
22
  * This module lives apart from review-precheck.ts so the main watch can share the rules without a
17
23
  * runtime import cycle: review-precheck.ts imports src/baseline/main-watch.ts
@@ -25,10 +31,16 @@ import { briefEditReason, protectedEditReason } from "./protected-edits.js";
25
31
  import { secretLeakReason } from "./secret-leaks.js";
26
32
  import { falseFixReason } from "../verdict/fix-claim.js";
27
33
  import { backlogStructureReason } from "../backlog/backlog-structure.js";
28
- export async function diffRuleReasons(wt, baseRev, files, role, exempt) {
29
- const marker = conflictMarkerReason(wt, files);
30
- if (marker !== undefined)
31
- return [marker];
34
+ export async function diffRuleReasons(wt, baseRev, files, role, exempt, scope) {
35
+ // The gate scope rejects only the three findings a later commit cannot repair (a brief-block
36
+ // edit, a protected edit, a leaked credential); the watch scope runs the full set, because a
37
+ // conflict marker, a false fix claim and a broken backlog structure are all repairable and so
38
+ // bare waiting for the main watch to report them on main's tip.
39
+ if (scope === "watch") {
40
+ const marker = conflictMarkerReason(wt, files);
41
+ if (marker !== undefined)
42
+ return [marker];
43
+ }
32
44
  // The brief-block rule is role-independent — its edit is forbidden for every role alike — so it
33
45
  // runs even when the watch cannot name the tip's merging role (role === ""). Only the
34
46
  // PRINCIPLES.md half of protectedEditReason needs a known role to condemn an edit.
@@ -41,13 +53,15 @@ export async function diffRuleReasons(wt, baseRev, files, role, exempt) {
41
53
  const secretReason = await secretLeakReason(wt, baseRev, files);
42
54
  if (secretReason !== undefined)
43
55
  return [secretReason];
44
- if (exempt) {
56
+ if (scope === "watch" && exempt) {
45
57
  const falseFix = await falseFixReason(wt, baseRev, files);
46
58
  if (falseFix)
47
59
  return [falseFix];
48
60
  }
49
- const structure = await backlogStructureReason(wt, baseRev, files);
50
- if (structure)
51
- return [structure];
61
+ if (scope === "watch") {
62
+ const structure = await backlogStructureReason(wt, baseRev, files);
63
+ if (structure)
64
+ return [structure];
65
+ }
52
66
  return [];
53
67
  }