@defrex/autobuild 1.6.0 → 1.8.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.
Files changed (165) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +423 -57
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/answering-blocked-builds.md +44 -3
  5. package/docs/architecture.md +124 -29
  6. package/docs/cli.md +1 -0
  7. package/docs/configuration-overview.md +11 -1
  8. package/docs/configuration.md +334 -14
  9. package/docs/dispatcher.md +1 -1
  10. package/docs/forges.md +1 -0
  11. package/docs/integration-overview.md +2 -2
  12. package/docs/integration-tree.md +7 -4
  13. package/docs/merge-policy.md +78 -6
  14. package/docs/migration-1.0.md +4 -2
  15. package/docs/operating.md +3 -2
  16. package/docs/operator-api.md +45 -13
  17. package/docs/operator-surfaces.md +16 -3
  18. package/docs/plugin-authoring.md +45 -7
  19. package/docs/remote-store-protocol.md +28 -7
  20. package/docs/restacking.md +35 -11
  21. package/docs/ticket-dependencies.md +9 -4
  22. package/docs/ticket-sources.md +34 -6
  23. package/docs/tickets.md +7 -1
  24. package/docs/troubleshooting.md +1 -1
  25. package/docs/workspaces.md +1 -1
  26. package/package.json +3 -3
  27. package/packages/core/src/cli/attention.ts +2 -0
  28. package/packages/core/src/cli/binary-direct.ts +1 -0
  29. package/packages/core/src/cli/build-control.ts +65 -7
  30. package/packages/core/src/cli/context.ts +55 -14
  31. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  32. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  33. package/packages/core/src/cli/dashboard/model.ts +61 -8
  34. package/packages/core/src/cli/dashboard/render.ts +28 -3
  35. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  36. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  37. package/packages/core/src/cli/dispatch-preflight.ts +1 -0
  38. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  39. package/packages/core/src/cli/dispatch.ts +9 -3
  40. package/packages/core/src/cli/help.ts +80 -11
  41. package/packages/core/src/cli/init-validation.ts +14 -1
  42. package/packages/core/src/cli/landings.ts +1 -1
  43. package/packages/core/src/cli/main.ts +60 -9
  44. package/packages/core/src/cli/publication-settlement.ts +10 -0
  45. package/packages/core/src/cli/repository-status.ts +37 -2
  46. package/packages/core/src/cli/status.ts +186 -12
  47. package/packages/core/src/cli/terminals.ts +197 -4
  48. package/packages/core/src/cli/ticket.ts +22 -4
  49. package/packages/core/src/cli/wait.ts +1 -0
  50. package/packages/core/src/cli/watch.ts +73 -0
  51. package/packages/core/src/config/landing.ts +12 -0
  52. package/packages/core/src/config/live.ts +4 -0
  53. package/packages/core/src/config/path-selectors.ts +68 -0
  54. package/packages/core/src/config/profiles.ts +96 -0
  55. package/packages/core/src/config/ready-assignee.ts +43 -11
  56. package/packages/core/src/config/roles.ts +33 -10
  57. package/packages/core/src/config/schema.ts +205 -81
  58. package/packages/core/src/events/catalog.ts +17 -3
  59. package/packages/core/src/events/compatibility.ts +4 -1
  60. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  61. package/packages/core/src/events/head-paths-limits.ts +25 -0
  62. package/packages/core/src/events/payloads.ts +323 -20
  63. package/packages/core/src/events/policy.ts +22 -0
  64. package/packages/core/src/events/repository.ts +47 -1
  65. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +320 -130
  66. package/packages/core/src/kernel/build-creation.ts +29 -0
  67. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  68. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  69. package/packages/core/src/kernel/engine.ts +48 -8
  70. package/packages/core/src/kernel/forge-health.ts +47 -0
  71. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  72. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  73. package/packages/core/src/kernel/head-paths.ts +401 -0
  74. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  75. package/packages/core/src/kernel/landing-policy.ts +55 -2
  76. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  77. package/packages/core/src/kernel/landing-state.ts +44 -4
  78. package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
  79. package/packages/core/src/kernel/log-index.ts +27 -1
  80. package/packages/core/src/kernel/node-parent.ts +2 -0
  81. package/packages/core/src/kernel/node-polling.ts +13 -3
  82. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  83. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  84. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  85. package/packages/core/src/kernel/read-facts.ts +37 -2
  86. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  87. package/packages/core/src/kernel/reducer.ts +332 -16
  88. package/packages/core/src/kernel/target-observation.ts +2 -5
  89. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  90. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  91. package/packages/core/src/kernel/ticket-preparation.ts +15 -1
  92. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  93. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  94. package/packages/core/src/ontology.ts +1 -0
  95. package/packages/core/src/operator/annotations.ts +6 -0
  96. package/packages/core/src/operator/index.ts +3 -0
  97. package/packages/core/src/operator/protocol.ts +25 -2
  98. package/packages/core/src/operator/query.ts +1 -1
  99. package/packages/core/src/operator/registry.ts +122 -10
  100. package/packages/core/src/operator/repository-events.ts +67 -0
  101. package/packages/core/src/operator/sandbox-host.ts +3 -0
  102. package/packages/core/src/operator/tickets.ts +15 -3
  103. package/packages/core/src/plugin-sdk/index.ts +4 -0
  104. package/packages/core/src/ports/forge/create.ts +6 -0
  105. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  106. package/packages/core/src/ports/forge/github.ts +12 -1
  107. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  108. package/packages/core/src/ports/forge-failure.ts +31 -2
  109. package/packages/core/src/ports/runner/routing.ts +66 -5
  110. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  111. package/packages/core/src/ports/tickets/contract.ts +164 -4
  112. package/packages/core/src/ports/tickets/create.ts +17 -3
  113. package/packages/core/src/ports/tickets/fake.ts +5 -0
  114. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  115. package/packages/core/src/ports/tickets/github.ts +247 -29
  116. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  117. package/packages/core/src/ports/tickets/operations.ts +6 -1
  118. package/packages/core/src/ports/tickets/tree.ts +12 -2
  119. package/packages/core/src/ports/tickets/update.ts +6 -2
  120. package/packages/core/src/ports/types.ts +36 -5
  121. package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
  122. package/packages/core/src/processes/build-child.ts +28 -7
  123. package/packages/core/src/processes/build-execution-state.ts +34 -2
  124. package/packages/core/src/processes/build-runner.ts +165 -19
  125. package/packages/core/src/processes/dispatcher.ts +837 -115
  126. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  127. package/packages/core/src/processes/harvest-child.ts +4 -0
  128. package/packages/core/src/processes/harvest-runner.ts +5 -0
  129. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  130. package/packages/core/src/processes/publication-state.ts +6 -1
  131. package/packages/core/src/processes/repo-view.ts +2 -0
  132. package/packages/core/src/scenarios/harness.ts +15 -1
  133. package/packages/core/src/store/digest.ts +41 -2
  134. package/packages/core/src/store/reduced-reads.ts +4 -1
  135. package/packages/core/src/store/reducer-value-shapes.json +10310 -8441
  136. package/packages/core/src/store/remote/client.ts +49 -10
  137. package/packages/core/src/store/remote/index.ts +4 -0
  138. package/packages/core/src/store/remote/protocol.ts +18 -1
  139. package/packages/core/src/store/remote/released-clients.json +22 -0
  140. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  141. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  142. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  143. package/packages/core/src/store/repo-state-events.ts +3 -0
  144. package/packages/core/src/store/types.ts +27 -0
  145. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  146. package/packages/core/src/testing/index.ts +2 -0
  147. package/packages/core/src/testing/reduced-read-budget.ts +419 -9
  148. package/skills/code-review/SKILL.md +8 -0
  149. package/skills/finalize/SKILL.md +4 -0
  150. package/skills/guide/SKILL.md +241 -47
  151. package/skills/guide/references/integration-tree.md +7 -4
  152. package/skills/guide/references/merge-policy.md +78 -6
  153. package/skills/guide/references/migration-1.0.md +4 -2
  154. package/skills/guide/references/operator-api.md +45 -13
  155. package/skills/guide/references/plugin-authoring.md +45 -7
  156. package/skills/guide/references/remote-store-protocol.md +28 -7
  157. package/skills/guide/references/restacking.md +35 -11
  158. package/skills/guide/references/ticket-dependencies.md +9 -4
  159. package/skills/implement/SKILL.md +15 -1
  160. package/skills/operate/SKILL.md +133 -16
  161. package/skills/plan/SKILL.md +17 -2
  162. package/skills/plan-review/SKILL.md +8 -0
  163. package/skills/reconcile/SKILL.md +21 -5
  164. package/skills/tickets/SKILL.md +23 -6
  165. package/templates/hosted-service/package.json +2 -2
package/docs/tickets.md CHANGED
@@ -55,6 +55,12 @@ When a ticket must go next, such as a fix for a stuck build, mark it urgent inst
55
55
  bun ab ticket update AUT-12 --priority urgent
56
56
  ```
57
57
 
58
+ On the `github` source a ticket has assignees. `--assignees alice,me` on `ab ticket create` or `ab ticket update` sets them, where `me` is the owner of the GitHub credential. On update it replaces the whole set, `--assignees ''` clears it, and omitting the option leaves it alone. Set `[tickets].createAssignee` to assign every ticket Autobuild creates, including harvest proposals; explicit `--assignees` replace that default. `ab ticket show` prints the assignees, and JSON ticket reads carry an `assignees` array of usernames. Sources that can't store assignees refuse the option and name the source. See [Ticket sources](ticket-sources.md#shipped-adapters).
59
+
60
+ ```sh
61
+ bun ab ticket update 412 --assignees octocat
62
+ ```
63
+
58
64
 
59
65
  ## Backlog and rejected
60
66
 
@@ -76,7 +82,7 @@ Moving a ticket back to triage, backlog or ready restores ordinary behavior. "Bu
76
82
  The dispatcher claims only tickets in the ready state with the required labels and any source-specific filter. A ready ticket still waits on:
77
83
 
78
84
  - **Blockers.** Unresolved prerequisite tickets keep it queued; they don't create a blocked build. With nodes, prerequisites with builds must be present at the sampled destination; see [integration and blocker presence](integration-overview.md).
79
- - **Destination and capacity.** Its target must accept new work, and a capacity slot must be free and not reserved for an integration node awaiting verification or a finished build waiting to re-verify or reconcile.
85
+ - **Destination and capacity.** Its target must accept new work, and a capacity slot must be free and not reserved for an integration node awaiting verification, a finished build waiting to re-verify or reconcile, or a build resuming after its ticket wait ends; each of those is admitted before new claims.
80
86
 
81
87
  When a slot is free, the dispatcher takes urgent ready tickets first, then normal ones, each in the source's order. Priority changes only that order: a blocked urgent ticket waits like any other while normal work proceeds, and an urgent ticket never stops or pauses a running build. The web dashboard's Queue tab lists tickets in the same order and marks urgent ones `URGENT`; the mark shows priority, not that the ticket will dispatch next.
82
88
 
@@ -57,7 +57,7 @@ bun ab harvest status
57
57
  - **Ready state:** ticket in the exact ready state with every required label.
58
58
  - **Blockers and destination:** blockers done, target node open, required changes in the destination. A target node built by another dispatcher's store never opens here; see [several dispatchers](build-store.md#several-dispatchers-on-one-repository). `ab repository status` lists the queue diagnostics.
59
59
  - **Claims:** claimed tickets aren't reclaimed.
60
- - **Capacity:** paused or blocked unfinished work keeps its slot; builds waiting for a merge decision and idle collecting nodes take none. A finished build that must re-verify or reconcile reserves a slot ahead of new claims. Node verification and reconciliation account specially for descendants' slots.
60
+ - **Capacity:** paused unfinished work, and work blocked on a question, keeps its slot; builds waiting for a merge decision, builds waiting on other tickets, and idle collecting nodes take none. A finished build that must re-verify or reconcile, or a build whose ticket wait ended, reserves a slot ahead of new claims. Node verification and reconciliation account specially for descendants' slots.
61
61
  - **Harvest:** check the acknowledged harvest gate and unclaimed observations. Harvest triggers at `policy.harvestThreshold` observations, or `policy.harvestMaxDrift` other merged builds since the oldest observation (zero disables drift), and uses no build slot.
62
62
 
63
63
  ## Authentication failures
@@ -126,7 +126,7 @@ export AB_GIT_READ_TOKEN='<read-only repository token>'
126
126
 
127
127
  - Use a repository-scoped read token, separate from the push identity. For a public clone, remove `gitUsernameEnv` and `gitPasswordEnv`.
128
128
  - Autobuild passes these as the authenticated Git source for [Vercel private-repository cloning](https://vercel.com/kb/guide/sandbox-private-github-repositories); don't embed credentials in the origin URL.
129
- - `environmentVariables` forwards legacy runtime API credentials; declared account credentials become placeholders even when listed here. Never forward `AB_TOKEN`, `GITHUB_TOKEN`, `GH_TOKEN`, Vercel tokens or the clone token; Autobuild supplies scoped Store authority, keeps clone secrets out of guest commands, and publishes from the host.
129
+ - `environmentVariables` forwards legacy runtime API credentials; declared account credentials become placeholders even when listed here. Never forward `AB_TOKEN`, `GITHUB_TOKEN`, `GH_TOKEN`, Vercel tokens or the clone token; Autobuild supplies scoped Store authority, keeps clone secrets out of guest commands, and publishes from the host. Guest runners always run with `AB_GITHUB_REQUIRE_CREDENTIAL=1`, which a forwarded value cannot override, so a GitHub API request from the guest without a credential fails with a typed error naming `GITHUB_TOKEN or GH_TOKEN` instead of using the sandbox address's shared anonymous quota.
130
130
 
131
131
  ## Writing your own
132
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defrex/autobuild",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Agent-driven software delivery from groomed ticket to merged PR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -157,8 +157,8 @@
157
157
  },
158
158
  "devDependencies": {
159
159
  "@biomejs/biome": "2.5.5",
160
- "@defrex/autobuild-postgres-store": "1.6.0",
161
- "@defrex/autobuild-vercel-sandbox": "1.6.0",
160
+ "@defrex/autobuild-postgres-store": "1.8.0",
161
+ "@defrex/autobuild-vercel-sandbox": "1.8.0",
162
162
  "@resvg/resvg-js": "2.6.2",
163
163
  "@types/bun": "^1.3.14",
164
164
  "@types/node": "^24.0.0",
@@ -62,6 +62,8 @@ export function repositoryNeedsAttention(event: RepositoryEvent): boolean {
62
62
  case 'dispatcher.runtime-rolled-back':
63
63
  case 'dispatcher.upgrade-failed':
64
64
  case 'dispatcher.kernel-git-unavailable':
65
+ case 'forge.credential-limited':
66
+ case 'ticket.handed-back':
65
67
  return true
66
68
  case 'dispatcher.config-reloaded':
67
69
  return event.payload.restartRequired.length > 0
@@ -187,6 +187,7 @@ export async function runDirectBinary(
187
187
  repo: record.repo,
188
188
  name: forge.name,
189
189
  wait: true,
190
+ scope: { process: `phase session ${cliEnv.session} (build ${cliEnv.build})` },
190
191
  })
191
192
  return await runCli(argv, {
192
193
  ...unscopedDeps,
@@ -1,5 +1,9 @@
1
1
  import { integrationFailed } from '../kernel/integration-state'
2
- import { landRefusalReason } from '../kernel/landing-readiness'
2
+ import {
3
+ candidateHeadMatches,
4
+ currentCandidateHead,
5
+ landRefusalReason,
6
+ } from '../kernel/landing-readiness'
3
7
  import { observeIntegration } from '../kernel/integration-completeness'
4
8
  import type { TicketSource } from '../ports/types'
5
9
  import { readBuildFacts } from '../store/reduced-reads'
@@ -12,7 +16,7 @@ import { readBuildFacts } from '../store/reduced-reads'
12
16
  * normal runner and dispatcher consume them.
13
17
  */
14
18
  import type { AbEvent } from '../events/catalog'
15
- import type { PinnedAsset } from '../events/payloads'
19
+ import type { AbortDestination, PinnedAsset } from '../events/payloads'
16
20
  import { humanActor, KERNEL, type Via } from '../events/envelope'
17
21
  import { discardInFlight, type BuildState, type OpenEscalation } from '../kernel/reducer'
18
22
  import type { ArtifactRef, BuildOutcome, BuildStatus, TicketRef } from '../ontology'
@@ -22,6 +26,9 @@ import { samplePinnedAssets } from '../store/ticket-assets'
22
26
  import type { BuildStore } from '../store/types'
23
27
  import { withSessionlessStore, type StoreOpener } from './store-opening'
24
28
 
29
+ /** Matches the hand-back report's reason bound. */
30
+ export const ABORT_REASON_LIMIT = 2000
31
+
25
32
  const ACTIVE_STATUSES: readonly BuildStatus[] = ['running', 'collecting', 'paused', 'blocked']
26
33
 
27
34
  /** Retry carries no phase guidance, but the event schema still requires a
@@ -43,10 +50,16 @@ export type AnswerResolutionRequest =
43
50
 
44
51
  export type BuildControlAction =
45
52
  | { kind: 'hold' }
46
- | { kind: 'land' }
53
+ | { kind: 'land'; head?: string }
47
54
  | { kind: 'pause' }
48
55
  | { kind: 'resume' }
49
- | { kind: 'abort' }
56
+ | {
57
+ kind: 'abort'
58
+ /** Where cleanup hands the ticket back; omitted means triage. */
59
+ to?: AbortDestination
60
+ /** Recorded on the request and quoted in the hand-back comment. */
61
+ reason?: string
62
+ }
50
63
  | { kind: 'discard' }
51
64
  | { kind: 'auto-merge-on' }
52
65
  | { kind: 'auto-merge-off' }
@@ -124,6 +137,16 @@ export type BuildControlErrorCode =
124
137
  | 'incompatible-answer-options'
125
138
  | 'merge-not-ready'
126
139
  | 'node-incomplete'
140
+ | 'head-mismatch'
141
+ | 'invalid-argument'
142
+
143
+ /** Normalize an operator-given consent head (`ab merge --head`, the operator
144
+ * `head` field): trimmed and lowercased. Undefined when blank or containing
145
+ * whitespace, which every caller reports as a usage or validation error. */
146
+ export function parseConsentHead(raw: string): string | undefined {
147
+ const head = raw.trim().toLowerCase()
148
+ return /^\S+$/.test(head) ? head : undefined
149
+ }
127
150
 
128
151
  /** Typed codes let the dashboard turn stale selections/prompts into warnings
129
152
  * while the CLI can surface the same underlying conflict as a command error. */
@@ -161,6 +184,7 @@ async function appendCommand(
161
184
  user: string,
162
185
  command: BuildControlCommand,
163
186
  via?: Via,
187
+ abort: { to?: AbortDestination; reason?: string } = {},
164
188
  ): Promise<BuildControlResult> {
165
189
  const actor = humanActor(user, via)
166
190
  let event: AbEvent
@@ -186,7 +210,10 @@ async function appendCommand(
186
210
  event = await store.append(slug, {
187
211
  actor,
188
212
  type: 'build.abort-requested',
189
- payload: {},
213
+ payload: {
214
+ ...(abort.reason !== undefined ? { reason: abort.reason } : {}),
215
+ ...(abort.to !== undefined ? { to: abort.to } : {}),
216
+ },
190
217
  })
191
218
  break
192
219
  case 'discard':
@@ -295,7 +322,7 @@ function abortPending(slug: string): BuildControlError {
295
322
  return new BuildControlError(
296
323
  'abort-pending',
297
324
  `build "${slug}" is aborting; nothing was recorded. Abort is not revocable — ` +
298
- 'after cleanup returns the ticket to Triage, dispatch it as a fresh build',
325
+ 'after cleanup hands the ticket back, dispatch it as a fresh build',
299
326
  )
300
327
  }
301
328
 
@@ -521,12 +548,33 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
521
548
  }
522
549
 
523
550
  if (opts.action.kind === 'abort') {
551
+ const reason = opts.action.reason?.trim()
552
+ if (opts.action.reason !== undefined && (!reason || reason.length > ABORT_REASON_LIMIT))
553
+ throw new BuildControlError(
554
+ 'invalid-argument',
555
+ `abort reason must be 1–${ABORT_REASON_LIMIT} characters after trimming; nothing was recorded`,
556
+ )
557
+ const to = opts.action.to
524
558
  if (state.status !== 'queued') activeState(opts.slug, state)
525
559
  const existing = events.latestAbort
526
560
  if (existing !== undefined) {
561
+ // An identical repeat is the same request; a different destination or
562
+ // reason would be silently ignored by cleanup, so it is refused.
563
+ const recordedTo = existing.payload.to ?? 'triage'
564
+ const recordedReason = existing.payload.reason?.trim() || undefined
565
+ if (recordedTo !== (to ?? 'triage') || recordedReason !== reason)
566
+ throw new BuildControlError(
567
+ 'abort-pending',
568
+ `build "${opts.slug}" already has an abort request returning its ticket to ` +
569
+ `${recordedTo}${recordedReason ? ` (reason: ${recordedReason})` : ''}; nothing was recorded. ` +
570
+ 'An abort request is not revocable or editable.',
571
+ )
527
572
  return { kind: 'command', slug: opts.slug, command: 'abort', event: existing }
528
573
  }
529
- return appendCommand(opts.store, opts.slug, user, 'abort', opts.via)
574
+ return appendCommand(opts.store, opts.slug, user, 'abort', opts.via, {
575
+ ...(to !== undefined ? { to } : {}),
576
+ ...(reason !== undefined ? { reason } : {}),
577
+ })
530
578
  }
531
579
 
532
580
  activeState(opts.slug, state)
@@ -542,6 +590,16 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
542
590
  const current = facts.state
543
591
  activeState(opts.slug, current)
544
592
  if (opts.action.kind === 'land' && discardInFlight(current)) throw discardPending(opts.slug)
593
+ if (opts.action.kind === 'land' && opts.action.head !== undefined) {
594
+ const given = parseConsentHead(opts.action.head)
595
+ if (given === undefined) throw new Error('Merge consent head must be a nonblank SHA')
596
+ const live = currentCandidateHead(current)
597
+ if (!candidateHeadMatches(given, live))
598
+ throw new BuildControlError(
599
+ 'head-mismatch',
600
+ `Merge consent was not recorded: head ${given} is not the current candidate head of build "${opts.slug}"; the current head is ${live ?? 'not yet recorded'}. Review that head and retry.`,
601
+ )
602
+ }
545
603
  const decision = current.landing?.decision
546
604
  if (opts.action.kind === 'land') {
547
605
  const reason = landRefusalReason(current, facts.log.restack)
@@ -30,6 +30,7 @@ import {
30
30
  type TerminalCommand,
31
31
  } from '../kernel/phases'
32
32
  import type { BuildState } from '../kernel/reducer'
33
+ import { waitBlock, waitGuidance, waitSummary } from '../kernel/ticket-wait'
33
34
  import {
34
35
  isVerifyPhase,
35
36
  verifyReportKind,
@@ -503,6 +504,37 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
503
504
  }
504
505
  }
505
506
 
507
+ // A ticket wait refused or ended for this phase occurrence (SPEC §11
508
+ // "Ticket waits"): every guidance.json naming its escalation or request id
509
+ // carries a `wait` block saying what the session waited on, including the
510
+ // answer to the dispatcher's unresolvable raise that ended the wait.
511
+ const wait = waitBlock(state, phase, round)
512
+ const waitIds = new Set([
513
+ wait?.id,
514
+ wait && state.wait?.escalation,
515
+ ...(wait?.outcome === 'ended'
516
+ ? state.answeredEscalations
517
+ .filter((escalation) => escalation.wait?.id === wait.id)
518
+ .map((escalation) => escalation.id)
519
+ : []),
520
+ ])
521
+ // seq of the refusal or end the wait block reports, and of the answer
522
+ // behind the guidance.json written so far: only a strictly newer answer
523
+ // may stand in for the wait's own guidance.
524
+ const waitSeq =
525
+ wait?.outcome === 'refused' ? state.waitRequest?.outcome?.seq : state.wait?.ended?.seq
526
+ let guidanceWritten: string | undefined
527
+ let guidanceSeq: number | undefined
528
+ const answeredSeq = (id: string) =>
529
+ [...state.answeredEscalations, ...waitGuidance(state)].find((item) => item.id === id)
530
+ ?.answeredSeq
531
+ const writeGuidance = async (guidance: { escalation: string; answer: string }) => {
532
+ guidanceWritten = guidance.escalation
533
+ guidanceSeq = answeredSeq(guidance.escalation)
534
+ const document = waitIds.has(guidance.escalation) ? { ...guidance, wait } : guidance
535
+ await writeDerived('guidance.json', `${JSON.stringify(document, null, 2)}\n`)
536
+ }
537
+
506
538
  if (inputs.findings === 'current' || inputs.currentFeedback === true) {
507
539
  if (phase === 'implement') {
508
540
  const receiptSeq = state.verifyStage.implementations[String(round)]
@@ -550,7 +582,7 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
550
582
  )
551
583
  } else if ('guidance' in feedback) {
552
584
  // A human escalation answer fed in as authoritative feedback (§15.6-B).
553
- await writeDerived('guidance.json', `${JSON.stringify(feedback.guidance, null, 2)}\n`)
585
+ await writeGuidance(feedback.guidance)
554
586
  }
555
587
  }
556
588
  }
@@ -581,21 +613,16 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
581
613
  (escalation) => escalation.resolution === 'guidance' && escalation.phase === phase,
582
614
  )
583
615
  const latest = answered.at(-1) // answeredEscalations is in answer order
584
- if (latest !== undefined) {
585
- await writeDerived(
586
- 'guidance.json',
587
- `${JSON.stringify({ escalation: latest.id, answer: latest.answer }, null, 2)}\n`,
588
- )
589
- }
616
+ if (latest !== undefined) await writeGuidance({ escalation: latest.id, answer: latest.answer })
590
617
  }
591
618
 
592
- // Read-deferral guidance repairs access for this same execution occurrence,
593
- // including reviewers, which have no producer-feedback carrier.
619
+ // Read-deferral and ticket-wait guidance resumes this same review occurrence,
620
+ // which has no producer-feedback carrier.
594
621
  if (manifest.feedback === undefined && (phase === 'plan-review' || phase === 'code-review')) {
595
622
  const latest = state.answeredEscalations
596
623
  .filter(
597
624
  (item) =>
598
- item.deferral === 'own-build-read' &&
625
+ (item.deferral === 'own-build-read' || item.wait !== undefined) &&
599
626
  item.resolution === 'guidance' &&
600
627
  item.phase === phase &&
601
628
  item.round === round,
@@ -603,11 +630,25 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
603
630
  .at(-1)
604
631
  if (latest) {
605
632
  manifest.feedback = { guidance: { escalation: latest.id, answer: latest.answer } }
606
- await writeDerived(
607
- 'guidance.json',
608
- `${JSON.stringify(manifest.feedback.guidance, null, 2)}\n`,
609
- )
633
+ await writeGuidance(manifest.feedback.guidance)
634
+ }
635
+ }
636
+
637
+ // A refused wait, or a wait ended without guidance text (a bare retry or an
638
+ // automatic end), still tells the session what it waited on. Only guidance
639
+ // answered after the refusal or end keeps precedence; an older answer the
640
+ // blocks above found never hides the wait.
641
+ const waitSuperseded =
642
+ guidanceWritten !== undefined &&
643
+ (guidanceSeq === undefined || waitSeq === undefined || guidanceSeq >= waitSeq)
644
+ if (wait !== undefined && !waitSuperseded) {
645
+ const guidance = {
646
+ escalation: wait.outcome === 'refused' ? wait.id : (state.wait?.escalation ?? wait.id),
647
+ answer: waitSummary(wait),
610
648
  }
649
+ if (manifest.feedback === undefined || 'guidance' in manifest.feedback)
650
+ manifest.feedback = { guidance }
651
+ await writeGuidance(guidance)
611
652
  }
612
653
 
613
654
  if (inputs.commitRange === true && state.kind === 'node' && state.integration?.cycle) {
@@ -14,6 +14,7 @@ export function dashboardBuildControl(status: EffectiveStatus): DashboardBuildCo
14
14
  return { key: 'p', action: 'cancel-pause', label: 'cancel pause' }
15
15
  case 'paused':
16
16
  case 'blocked':
17
+ case 'waiting':
17
18
  return { key: 'r', action: 'resume', label: 'resume' }
18
19
  case 'collecting':
19
20
  case 'queued':
@@ -37,12 +38,20 @@ export function buildActionAvailability(build: DashboardBuild): DashboardActionA
37
38
  ...(dashboardBuildControl(build.status)
38
39
  ? { primary: dashboardBuildControl(build.status)!.action }
39
40
  : {}),
40
- abort: ['queued', 'running', 'collecting', 'pausing', 'paused', 'resuming', 'blocked'].includes(
41
- build.status,
42
- ),
41
+ abort: [
42
+ 'queued',
43
+ 'running',
44
+ 'collecting',
45
+ 'pausing',
46
+ 'paused',
47
+ 'resuming',
48
+ 'blocked',
49
+ 'waiting',
50
+ ].includes(build.status),
43
51
  discard: build.kind !== 'integration' && build.status === 'queued',
44
52
  autoMerge: !['aborting', 'cleaning'].includes(build.status),
45
- answer: build.blockers.length > 0,
53
+ // Answering an open ticket wait ends it early.
54
+ answer: build.blockers.length > 0 || build.wait !== undefined,
46
55
  }
47
56
  }
48
57
 
@@ -1,6 +1,19 @@
1
- import { evaluateLandingPolicy } from '../../kernel/landing-policy'
1
+ import { candidateHeadPaths } from '../../kernel/head-paths-state'
2
+ import { evaluateLandingPolicy, type LandingPaths } from '../../kernel/landing-policy'
2
3
  import type { BuildState } from '../../kernel/reducer'
3
4
 
5
+ /** The candidate's already-reduced changed paths; never an artifact read. */
6
+ function candidatePaths(state: BuildState): LandingPaths {
7
+ const answer = candidateHeadPaths(state)
8
+ return answer.recorded
9
+ ? {
10
+ recorded: true,
11
+ complete: answer.record.total === answer.record.preview.length,
12
+ paths: answer.record.preview,
13
+ }
14
+ : { recorded: false }
15
+ }
16
+
4
17
  export function landingPolicyDisplay(landing: BuildState['landing']): string {
5
18
  if (landing?.command?.kind === 'hold') return 'held'
6
19
  return landing?.decision?.mode ?? 'policy pending'
@@ -18,6 +31,11 @@ export function nodeLandingPolicyDisplay(
18
31
  ? { kind: 'node' as const, ticket: state.target.ticket.id }
19
32
  : { kind: 'root' as const }
20
33
  const input = { from: 'node' as const, into, labels: [] as string[] }
34
+ const paths = candidatePaths(state)
35
+ const mode = (labels: string[]) => {
36
+ const result = evaluateLandingPolicy(rules, { ...input, labels }, paths)
37
+ return 'deferred' in result ? 'policy pending' : result.mode
38
+ }
21
39
  const excluded = new Set<string>()
22
40
  const modes = new Set<string>()
23
41
  for (const rule of rules) {
@@ -31,15 +49,19 @@ export function nodeLandingPolicyDisplay(
31
49
  continue
32
50
  if (rule.label) {
33
51
  if (excluded.has(rule.label)) continue
34
- modes.add(evaluateLandingPolicy(rules, { ...input, labels: [rule.label] }).mode)
52
+ modes.add(mode([rule.label]))
35
53
  excluded.add(rule.label)
36
54
  } else {
37
- modes.add(evaluateLandingPolicy(rules, input).mode)
38
- return modes.size === 1 ? ([...modes][0] as 'auto' | 'consent') : 'policy pending'
55
+ modes.add(mode([]))
56
+ return modes.size === 1
57
+ ? ([...modes][0] as 'auto' | 'consent' | 'policy pending')
58
+ : 'policy pending'
39
59
  }
40
60
  }
41
- modes.add(evaluateLandingPolicy(rules, input).mode)
42
- return modes.size === 1 ? ([...modes][0] as 'auto' | 'consent') : 'policy pending'
61
+ modes.add(mode([]))
62
+ return modes.size === 1
63
+ ? ([...modes][0] as 'auto' | 'consent' | 'policy pending')
64
+ : 'policy pending'
43
65
  }
44
66
 
45
67
  /** Explain the durable rule when available; unknown labels must not invent a match. */
@@ -55,12 +77,14 @@ export function nodeLandingRuleDisplay(
55
77
  const into = state.target
56
78
  ? { kind: 'node' as const, ticket: state.target.ticket.id }
57
79
  : { kind: 'root' as const }
80
+ const paths = candidatePaths(state)
58
81
  const candidates = [
59
- evaluateLandingPolicy(rules, { from: 'node', into, labels: [] }),
82
+ evaluateLandingPolicy(rules, { from: 'node', into, labels: [] }, paths),
60
83
  ...rules
61
84
  .filter((r) => r.label)
62
- .map((r) => evaluateLandingPolicy(rules, { from: 'node', into, labels: [r.label!] })),
85
+ .map((r) => evaluateLandingPolicy(rules, { from: 'node', into, labels: [r.label!] }, paths)),
63
86
  ]
87
+ if (candidates.some((c) => 'deferred' in c)) return 'rule pending changed paths'
64
88
  const unique = new Map(candidates.map((c) => [JSON.stringify(c.rule), c.rule]))
65
89
  if (unique.size !== 1) return 'rule pending ticket labels'
66
90
  const rule = [...unique.values()][0]!
@@ -1,5 +1,6 @@
1
1
  import { repositoryReadFactsReducer } from '../../kernel/read-facts'
2
2
  import { workTargetDistance } from './target-distance'
3
+ import { openTicketWait, waitingOnLine } from '../../kernel/ticket-wait'
3
4
  import { migrationIdentity, ticketMigrationsReducer } from '../../kernel/ticket-migrations'
4
5
  import { projectRollback, type DashboardRollback } from './rollback'
5
6
  import { dispatchUpgradeReducer, type DispatchUpgradeState } from '../../kernel/dispatch-upgrade'
@@ -101,7 +102,9 @@ import {
101
102
 
102
103
  /** Every capacity-bearing build plus acknowledged abort cleanup is listed.
103
104
  * `aborting` and `cleaning` are display-only projections over durable abort
104
- * facts; neither extends the reducer's lifecycle vocabulary. */
105
+ * facts; neither extends the reducer's lifecycle vocabulary. `waiting` is
106
+ * likewise display-only: a build whose only open escalation is its open
107
+ * ticket wait. The reducer still calls it `blocked` (SPEC §11). */
105
108
  export type EffectiveStatus =
106
109
  | 'queued'
107
110
  | 'running'
@@ -110,6 +113,7 @@ export type EffectiveStatus =
110
113
  | 'paused'
111
114
  | 'resuming'
112
115
  | 'blocked'
116
+ | 'waiting'
113
117
  | 'aborting'
114
118
  | 'cleaning'
115
119
 
@@ -183,6 +187,37 @@ export interface DashboardHarvest {
183
187
  action?: HarvestRunAction
184
188
  }
185
189
 
190
+ /** An open ticket wait as every dashboard renders it. `text` is the shared
191
+ * wording; `question` is the wait escalation's, which answering ends early. */
192
+ export interface DashboardWait {
193
+ tickets: string[]
194
+ reason: string
195
+ since: string
196
+ escalation: string
197
+ question: string
198
+ text: string
199
+ }
200
+
201
+ /** The one builder of a row's wait, so captures and projections share text. */
202
+ export function dashboardWaitFrom(wait: Omit<DashboardWait, 'text'>): DashboardWait {
203
+ return { ...wait, text: waitingOnLine(wait.tickets, wait.reason) }
204
+ }
205
+
206
+ /** The build's open ticket wait, or undefined when none is open. */
207
+ export function dashboardWait(state: BuildState): DashboardWait | undefined {
208
+ const wait = openTicketWait(state)
209
+ if (wait === undefined) return undefined
210
+ const question =
211
+ state.openEscalations.find((escalation) => escalation.id === wait.escalation)?.question ?? ''
212
+ return dashboardWaitFrom({
213
+ tickets: wait.tickets.map((ticket) => ticket.id),
214
+ reason: wait.reason,
215
+ since: wait.enteredAt,
216
+ escalation: wait.escalation,
217
+ question,
218
+ })
219
+ }
220
+
186
221
  export interface DashboardBuild {
187
222
  draining?: boolean
188
223
  /** A work row's standing alert, such as a parked build waiting for a slot. */
@@ -220,10 +255,13 @@ export interface DashboardBuild {
220
255
  | 'unverified merge'
221
256
  slug: string
222
257
  status: EffectiveStatus
223
- /** True when the build is BOTH paused and blocked: blocked wins the status
224
- * (the spec's visual override), and this keeps the pause visible so no
225
- * information is lost. */
258
+ /** True when the build is BOTH paused and blocked or waiting: those win the
259
+ * status (the spec's visual override), and this keeps the pause visible so
260
+ * no information is lost. */
226
261
  alsoPaused: boolean
262
+ /** The open ticket wait, present even when another escalation makes the
263
+ * row `blocked`. Its question is never among `blockers`. */
264
+ wait?: DashboardWait
227
265
  ticketId?: string
228
266
  steps: PipelineStep[]
229
267
  /** Queued-only explanation of the dispatcher boundary currently pending. */
@@ -235,7 +273,8 @@ export interface DashboardBuild {
235
273
  * a later successful attachment proves recovery. */
236
274
  setupError?: string
237
275
  /** Every unresolved blocker's question. Resolved ones drop out by
238
- * construction — the reducer moves them to answeredEscalations. */
276
+ * construction — the reducer moves them to answeredEscalations. An open
277
+ * ticket wait's question is excluded; it is `wait.question`. */
239
278
  blockers: string[]
240
279
  /** Current-spec per-loop review budget overrides. */
241
280
  reviewRoundCeilings?: { plan?: number; code?: number }
@@ -390,6 +429,14 @@ export function effectiveStatus(state: BuildState): EffectiveStatus | BuildState
390
429
  if (state.status === 'aborted') return 'cleaning'
391
430
  if (state.pendingCommands.some((command) => command.command === 'abort')) return 'aborting'
392
431
  if (state.kind === 'node' && integrationFailed(state)) return 'blocked'
432
+ // A ticket wait whose escalation is the only one open reads as waiting; any
433
+ // other open question outranks it and the build reads blocked.
434
+ const wait = openTicketWait(state)
435
+ if (
436
+ wait !== undefined &&
437
+ state.openEscalations.every((escalation) => escalation.id === wait.escalation)
438
+ )
439
+ return 'waiting'
393
440
  if (
394
441
  (state.status === 'paused' || state.status === 'blocked') &&
395
442
  state.openEscalations.length > 0
@@ -418,6 +465,7 @@ function isVisible(status: EffectiveStatus | BuildState['status']): status is Ef
418
465
  status === 'paused' ||
419
466
  status === 'resuming' ||
420
467
  status === 'blocked' ||
468
+ status === 'waiting' ||
421
469
  status === 'aborting' ||
422
470
  status === 'cleaning'
423
471
  )
@@ -588,6 +636,7 @@ export function projectBuildFromFacts(
588
636
  const dashboard = facts.dashboard
589
637
  const status = effectiveStatus(state)
590
638
  if (!isVisible(status)) return null
639
+ const wait = dashboardWait(state)
591
640
  const abortProgress =
592
641
  status === 'aborting'
593
642
  ? state.status === 'queued'
@@ -713,7 +762,10 @@ export function projectBuildFromFacts(
713
762
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
714
763
  steps: [],
715
764
  abortProgress,
716
- blockers: state.openEscalations.map((escalation) => escalation.question),
765
+ ...(wait !== undefined ? { wait } : {}),
766
+ blockers: state.openEscalations
767
+ .filter((escalation) => escalation.id !== wait?.escalation)
768
+ .map((escalation) => escalation.question),
717
769
  ...(state.reviewRoundCeilings.plan !== undefined ||
718
770
  state.reviewRoundCeilings.code !== undefined
719
771
  ? { reviewRoundCeilings: { ...state.reviewRoundCeilings } }
@@ -1052,7 +1104,7 @@ export function projectBuildFromFacts(
1052
1104
  createdAt: record.createdAt,
1053
1105
  },
1054
1106
  status,
1055
- alsoPaused: state.status === 'paused' && status === 'blocked',
1107
+ alsoPaused: state.status === 'paused' && (status === 'blocked' || status === 'waiting'),
1056
1108
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
1057
1109
  steps:
1058
1110
  state.kind === 'node'
@@ -1075,8 +1127,9 @@ export function projectBuildFromFacts(
1075
1127
  ]
1076
1128
  : steps,
1077
1129
  ...(setupError !== undefined ? { setupError } : {}),
1130
+ ...(wait !== undefined ? { wait } : {}),
1078
1131
  blockers: [
1079
- ...state.openEscalations.map((e) => e.question),
1132
+ ...state.openEscalations.filter((e) => e.id !== wait?.escalation).map((e) => e.question),
1080
1133
  ...(state.kind === 'node' && integrationFailed(state)
1081
1134
  ? ['verification failed: file a repair child targeting this node']
1082
1135
  : []),