@defrex/autobuild 0.13.0 → 1.0.0-beta.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 (210) hide show
  1. package/README.md +5 -3
  2. package/SPEC.md +673 -99
  3. package/bin/ab-dispatch-kernel.ts +4 -6
  4. package/docs/architecture.md +322 -75
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/configuration.md +112 -12
  7. package/docs/hosted-service.md +20 -2
  8. package/docs/integration-tree.md +117 -0
  9. package/docs/landing-policy.md +150 -0
  10. package/docs/mcp.md +24 -0
  11. package/docs/migration-1.0.md +68 -0
  12. package/docs/operator-api.md +20 -9
  13. package/docs/remote-store-protocol.md +114 -9
  14. package/docs/remote-ticket-protocol.md +26 -5
  15. package/docs/restacking.md +79 -0
  16. package/docs/setup.md +49 -6
  17. package/docs/ticket-dependencies.md +69 -0
  18. package/docs/ticket-migration.md +8 -0
  19. package/package.json +4 -3
  20. package/packages/core/src/cli/attention.ts +40 -163
  21. package/packages/core/src/cli/build-control.ts +75 -55
  22. package/packages/core/src/cli/bulk-control.ts +3 -2
  23. package/packages/core/src/cli/context.ts +68 -78
  24. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  25. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  26. package/packages/core/src/cli/dashboard/live.ts +5 -0
  27. package/packages/core/src/cli/dashboard/model.ts +178 -40
  28. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  29. package/packages/core/src/cli/dashboard/refresh.ts +176 -0
  30. package/packages/core/src/cli/dashboard/render.ts +78 -28
  31. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  32. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  33. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  34. package/packages/core/src/cli/dispatch-frontend.ts +173 -169
  35. package/packages/core/src/cli/dispatch-process.ts +14 -7
  36. package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
  37. package/packages/core/src/cli/dispatch.ts +397 -214
  38. package/packages/core/src/cli/dispatcher-liveness.ts +41 -21
  39. package/packages/core/src/cli/harvest.ts +71 -39
  40. package/packages/core/src/cli/help.ts +49 -32
  41. package/packages/core/src/cli/historical-build-state.ts +27 -0
  42. package/packages/core/src/cli/init-validation.ts +43 -2
  43. package/packages/core/src/cli/keyboard.ts +6 -0
  44. package/packages/core/src/cli/landings.ts +18 -0
  45. package/packages/core/src/cli/main.ts +52 -18
  46. package/packages/core/src/cli/mcp.ts +9 -0
  47. package/packages/core/src/cli/pr-attachments.ts +10 -13
  48. package/packages/core/src/cli/pr-summary-publication.ts +27 -60
  49. package/packages/core/src/cli/pr-summary.ts +43 -13
  50. package/packages/core/src/cli/publication-settlement.ts +177 -21
  51. package/packages/core/src/cli/repository-status.ts +49 -2
  52. package/packages/core/src/cli/status.ts +133 -36
  53. package/packages/core/src/cli/terminal-restore.ts +54 -0
  54. package/packages/core/src/cli/terminal.ts +16 -2
  55. package/packages/core/src/cli/terminals.ts +121 -219
  56. package/packages/core/src/cli/ticket-editor.ts +10 -3
  57. package/packages/core/src/cli/ticket.ts +115 -20
  58. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  59. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  60. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  61. package/packages/core/src/cli/upgrade.ts +16 -0
  62. package/packages/core/src/cli/wait.ts +194 -91
  63. package/packages/core/src/cli/watch.ts +111 -109
  64. package/packages/core/src/config/landing.ts +22 -0
  65. package/packages/core/src/config/live.ts +1 -0
  66. package/packages/core/src/config/pipeline-source.ts +4 -3
  67. package/packages/core/src/config/schema.ts +3 -0
  68. package/packages/core/src/events/catalog.ts +48 -3
  69. package/packages/core/src/events/payloads.ts +295 -6
  70. package/packages/core/src/events/repository.ts +38 -3
  71. package/packages/core/src/integration/harness.ts +11 -2
  72. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +3330 -119
  73. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  74. package/packages/core/src/kernel/auto-merge.ts +29 -4
  75. package/packages/core/src/kernel/build-identity.ts +94 -0
  76. package/packages/core/src/kernel/change-presence.ts +179 -0
  77. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  78. package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
  79. package/packages/core/src/kernel/engine.ts +89 -2
  80. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  81. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  82. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  83. package/packages/core/src/kernel/generators/repository-journals.ts +25 -3
  84. package/packages/core/src/kernel/harvest.ts +25 -23
  85. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  86. package/packages/core/src/kernel/integration-landing.ts +263 -0
  87. package/packages/core/src/kernel/integration-stack.ts +36 -0
  88. package/packages/core/src/kernel/integration-state.ts +135 -0
  89. package/packages/core/src/kernel/landing-policy.ts +47 -0
  90. package/packages/core/src/kernel/landing-publication.ts +41 -0
  91. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  92. package/packages/core/src/kernel/landing-state.ts +96 -0
  93. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  94. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  95. package/packages/core/src/kernel/log-index-value.ts +38 -0
  96. package/packages/core/src/kernel/log-index.ts +35 -5
  97. package/packages/core/src/kernel/node-landing.ts +439 -0
  98. package/packages/core/src/kernel/node-parent.ts +184 -0
  99. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  100. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  101. package/packages/core/src/kernel/node-restack.ts +274 -0
  102. package/packages/core/src/kernel/read-facts.ts +704 -0
  103. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  104. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  105. package/packages/core/src/kernel/reducer-registry.ts +153 -3
  106. package/packages/core/src/kernel/reducer.ts +121 -6
  107. package/packages/core/src/kernel/repository-attention.ts +179 -0
  108. package/packages/core/src/kernel/service-facts.ts +135 -0
  109. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  110. package/packages/core/src/kernel/terminal-guard.ts +133 -0
  111. package/packages/core/src/ontology.ts +9 -1
  112. package/packages/core/src/operator/annotations.ts +12 -0
  113. package/packages/core/src/operator/control.ts +11 -6
  114. package/packages/core/src/operator/index.ts +6 -0
  115. package/packages/core/src/operator/landings.ts +35 -0
  116. package/packages/core/src/operator/presentation.ts +1 -0
  117. package/packages/core/src/operator/protocol.ts +12 -3
  118. package/packages/core/src/operator/query.ts +40 -21
  119. package/packages/core/src/operator/read-view.ts +4 -13
  120. package/packages/core/src/operator/registry.ts +48 -19
  121. package/packages/core/src/operator/requests.ts +3 -22
  122. package/packages/core/src/operator/sandbox.ts +10 -9
  123. package/packages/core/src/operator/tickets.ts +57 -11
  124. package/packages/core/src/plugin-sdk/index.ts +13 -0
  125. package/packages/core/src/ports/forge/contract.ts +91 -3
  126. package/packages/core/src/ports/forge/fake.ts +142 -4
  127. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  128. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  129. package/packages/core/src/ports/forge/github.ts +631 -35
  130. package/packages/core/src/ports/forge/local-git.ts +119 -5
  131. package/packages/core/src/ports/forge/readiness.ts +99 -0
  132. package/packages/core/src/ports/tickets/contract.ts +41 -0
  133. package/packages/core/src/ports/tickets/create.ts +8 -1
  134. package/packages/core/src/ports/tickets/fake.ts +32 -1
  135. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  136. package/packages/core/src/ports/tickets/file.ts +18 -1
  137. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  138. package/packages/core/src/ports/tickets/linear.ts +124 -4
  139. package/packages/core/src/ports/tickets/migration.ts +25 -1
  140. package/packages/core/src/ports/tickets/operations.ts +7 -2
  141. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  142. package/packages/core/src/ports/tickets/remote.ts +10 -1
  143. package/packages/core/src/ports/tickets/revision.ts +3 -1
  144. package/packages/core/src/ports/tickets/tree.ts +148 -0
  145. package/packages/core/src/ports/tickets/update.ts +15 -2
  146. package/packages/core/src/ports/types.ts +135 -5
  147. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  148. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  149. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  150. package/packages/core/src/processes/build-child.ts +6 -6
  151. package/packages/core/src/processes/build-runner.ts +586 -87
  152. package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
  153. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  154. package/packages/core/src/processes/dispatcher.ts +2239 -357
  155. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  156. package/packages/core/src/processes/harvest-execution-state.ts +15 -9
  157. package/packages/core/src/processes/harvest-runner.ts +34 -70
  158. package/packages/core/src/processes/harvest.ts +38 -15
  159. package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
  160. package/packages/core/src/processes/orchestrator-tick.ts +2 -2
  161. package/packages/core/src/processes/publication-loss.ts +35 -21
  162. package/packages/core/src/processes/publication-state.ts +30 -5
  163. package/packages/core/src/processes/repo-view.ts +244 -1130
  164. package/packages/core/src/processes/tick-publication.ts +110 -0
  165. package/packages/core/src/store/adapter.ts +23 -0
  166. package/packages/core/src/store/build-scope.ts +35 -0
  167. package/packages/core/src/store/contract.ts +909 -0
  168. package/packages/core/src/store/digest.ts +52 -4
  169. package/packages/core/src/store/local/schema.ts +26 -13
  170. package/packages/core/src/store/local/store.ts +296 -55
  171. package/packages/core/src/store/memory.ts +181 -30
  172. package/packages/core/src/store/phase-session.ts +34 -0
  173. package/packages/core/src/store/reduced-reads.ts +240 -0
  174. package/packages/core/src/store/reducer-value-shapes.json +18323 -0
  175. package/packages/core/src/store/reducer-value-validation.ts +96 -0
  176. package/packages/core/src/store/reducer-values.ts +145 -0
  177. package/packages/core/src/store/remote/client.ts +85 -0
  178. package/packages/core/src/store/remote/compatibility.ts +21 -9
  179. package/packages/core/src/store/remote/index.ts +19 -0
  180. package/packages/core/src/store/remote/protocol.ts +27 -0
  181. package/packages/core/src/store/remote/version.ts +3 -1
  182. package/packages/core/src/store/repo-state-events.ts +3 -1
  183. package/packages/core/src/store/repo-tick.ts +72 -0
  184. package/packages/core/src/store/session-handle.ts +34 -0
  185. package/packages/core/src/store/snapshots.ts +10 -0
  186. package/packages/core/src/store/subscribe.ts +1 -1
  187. package/packages/core/src/store/ticket-assets.ts +4 -4
  188. package/packages/core/src/store/types.ts +71 -6
  189. package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
  190. package/packages/core/src/testing/index.ts +10 -0
  191. package/packages/core/src/testing/reduced-read-budget.ts +502 -0
  192. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  193. package/skills/guide/SKILL.md +116 -62
  194. package/skills/guide/references/integration-tree.md +117 -0
  195. package/skills/guide/references/landing-policy.md +150 -0
  196. package/skills/guide/references/migration-1.0.md +68 -0
  197. package/skills/guide/references/operator-api.md +13 -6
  198. package/skills/guide/references/plugin-authoring.md +34 -0
  199. package/skills/guide/references/remote-store-protocol.md +114 -9
  200. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  201. package/skills/guide/references/restacking.md +79 -0
  202. package/skills/guide/references/setup.md +49 -6
  203. package/skills/guide/references/ticket-dependencies.md +69 -0
  204. package/skills/guide/references/ticket-migration.md +8 -0
  205. package/skills/operate/SKILL.md +55 -5
  206. package/skills/reconcile/SKILL.md +55 -48
  207. package/skills/spec/SKILL.md +67 -1
  208. package/skills/tickets/SKILL.md +55 -2
  209. package/templates/autobuild.toml +3 -0
  210. package/templates/hosted-service/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env bun
2
+ import { readDispatcherRunFacts } from '../packages/core/src/store/reduced-reads'
2
3
  /** Private, shipped child for the interactive `ab dispatch` kernel. It owns no
3
4
  * terminal handles; the public command launches it with immutable options. */
4
5
  import { abDispatch } from '../packages/core/src/cli/dispatch'
@@ -61,12 +62,9 @@ try {
61
62
  const opened = openStoreForRepoState(state, { env: process.env })
62
63
  try {
63
64
  await opened.store.ensureRepo(state.repo)
64
- const events = await opened.store.getRepoEvents(state.repo)
65
- if (
66
- !events.some(
67
- (event) => event.type === 'dispatcher.run-stopped' && event.payload.run === options.run,
68
- )
69
- ) {
65
+ const facts = (await readDispatcherRunFacts(opened.store, state.repo, options.run, false))
66
+ .value
67
+ if (!facts.stop) {
70
68
  await opened.store.appendRepo(state.repo, {
71
69
  actor: DISPATCHER,
72
70
  type: 'dispatcher.run-stopped',
@@ -145,9 +145,9 @@ by a later advance. Each reducer publishes a `version`; bump it whenever the
145
145
  accumulator shape or the fold semantics change, because a cached accumulator is
146
146
  only valid for the version that wrote it. `kernel/reducer-registry.ts` lists
147
147
  every reducer with its version, and its snapshot test fails when an accumulator
148
- shape changes without a bump. Most callers still read whole logs (the terminal
149
- dashboard poll advances a carried build accumulator by per-build deltas; the
150
- dispatcher view below restores from stored accumulators).
148
+ shape changes without a bump. Current-state consumers use the typed persisted
149
+ read helpers in `store/reduced-reads.ts`; whole-array reducers remain pure
150
+ reference projections for tests and explicit historical output.
151
151
 
152
152
  **Reducer snapshots.** The `BuildStore` port can keep, per scope (one build log
153
153
  or the repository journal) and registered reducer, that reducer's accumulator as
@@ -173,72 +173,91 @@ reads every snapshot as missing and replays (SQLSTATE `42P01` is never an
173
173
  error), and an older client never asks. Run `bun run postgres:migrate` once to
174
174
  gain the table; until then the dispatcher and every other reader replay in full.
175
175
 
176
- **Dispatcher repository view.** A dispatcher process builds its view of the
177
- repository once and refreshes it by deltas
178
- (`packages/core/src/processes/repo-view.ts`). `RepoViewStore` decorates the
179
- `BuildStore` port: the first `refresh()` reads the journal's high-water mark
180
- (`getRepoHighWater`), the bounded journal subset, the build listing and digests,
181
- and the full log of every build that still has work (the same predicate the tick
182
- loops use); every later `refresh()` reads only events newer than its cursors —
183
- one journal delta, one delta per held build, plus the listing and digest reads
184
- that discover new builds. Every tick stage reads and writes through the view, so
185
- an event a stage appends is folded in at once and later stages in the same tick
186
- see it with no re-read; a foreign append interleaved with ours leaves a seq gap
187
- that marks the log dirty, a lost compare-and-set does the same, and any delta
188
- that is not contiguous from its cursor discards the log and re-reads it in full,
189
- so no event is skipped. Every state transition of one source (a build, the
190
- journal) runs on that source's single promise chain — snapshot and delta reads,
191
- window opening and widening, the fold after an own append, a lost
192
- compare-and-set's invalidation — and readers queue on it too, so overlapping
193
- readers join the repair in flight instead of observing half-applied state.
194
- Decisions that deliberately re-read at the last moment
195
- (`refreshBuild`) take an explicit delta. Cursor-bearing readers such as the
196
- orchestrator wake pass get per-source windows that hold only events above the
197
- lowest session cursor. A `--once` invocation builds the view cold and reads each
198
- log once; a long-running dispatcher pays that replay at its first tick and not
199
- again.
200
-
201
- The view restores from reducer snapshots on cold start. The journal comes from
202
- the `journalView` reducer (the journal pruned on arrival: durable types plus the
203
- tail from the latest `dispatcher.run-started`); each work build comes from one
204
- `work` snapshot row — the `build`, `logIndex`, `openExecution`,
205
- `openBuildWorkspace`, `publicationState`, `lastExecutionOutcome`, `buildDigest`,
206
- `dashboardFacts` and `currentDeferralObservation` accumulators at a single
207
- cursor. One row is one atomic write on every adapter, so a reader in another
208
- process sees the old bundle or the new, never a mix; the bundle version is
209
- derived from the component reducer versions, so a stale bundle misses and the
210
- build is replayed once. The view
211
- reads only the events newer than that cursor and holds, for a snapshot-backed
212
- build, just that delta plus the reduced state of everything before it, so a tick
213
- with no new events reads zero event rows (apart from the discovery listing and
214
- digests) and one with M new events reads exactly M. Tick stages that run for every
215
- build each tick take `buildFacts(slug)` (state, log index, open execution, open
216
- workspace, publication view) instead of the event array, and read raw history
217
- only on the branches that act on it. `persistSnapshots()` writes the advanced
218
- state back at the end of each tick and on shutdown — best effort, throttled in a
219
- resident dispatcher, always run by a cold single-tick process — and never writes
220
- a cursor that was not read from the log.
221
-
222
- **Operator reads.** The web dashboard, the repository and Harvest status
223
- routes, the operator build listings, and the `ab watch`/`ab wait` discovery
224
- passes derive from that same view instead of replaying the log
225
- (`packages/core/src/operator/read-view.ts`). A dashboard row renders from the
226
- `BuildState` plus the `dashboardFacts` reducer
227
- (`packages/core/src/cli/dashboard/facts.ts`: queued-row dispatch text, session
228
- brackets, phase intervals, pause time, and the per-round loop-output seqs) and
229
- the auto-merge deferral ledger; `projectBuild(…, events)` is the same projection
230
- over the whole-array reduction, so the snapshot and replay paths cannot differ.
231
- Within one serving process, passes are single-flight per repository: requests
232
- arriving while a pass runs join the one trailing pass, which restores from the
233
- snapshot the previous pass persisted. A poll at idle therefore reads no event
234
- rows beyond snapshot lookups and build discovery, and a poll after M new events
235
- reads those M rows once, however many tabs or watchers the process serves.
236
- Serving processes do not coordinate: with P of them, each may read the same M
237
- rows once, so duplicate reads are bounded by P and never by history, tabs, or
238
- watchers. A settled build listed under `--all` is restored from the snapshot the
239
- dispatcher left at settlement, or read once and then persisted. The first
240
- operator poll after upgrading replays each work build once, because the stored
241
- bundle layout changed.
176
+ **Named reducer values.** `BuildStore.getReducerValue(scope, {reducer, args?})`
177
+ returns `{version, cursor, value}` for each eligible entry in the executable
178
+ reducer registry. Eligible reducers consume build or repository events and finish
179
+ as plain JSON; raw journal-event lists, operator-session reducers, collections,
180
+ selector functions, and top-level optional results are explicitly excluded with
181
+ reasons. Factory arguments are validated and participate in a bounded digest
182
+ cache key. The persisted envelope also records the canonical scope, arguments,
183
+ name and version, and nested accumulator shapes are validated before restore.
184
+ The `value.*` namespace is reserved: public snapshot reads and writes reject it,
185
+ and the engine persists through private adapter hooks. Versioned cache keys
186
+ exclude checkpoints produced while the old namespace was publicly writable.
187
+ `tools/reducer-value-shapes.ts` regenerates those structural validators from the
188
+ declared accumulator types.
189
+
190
+ Memory, SQLite and Postgres use the same algorithm: capture the authoritative
191
+ high-water, load persisted state on every call, fold the indexed contiguous delta
192
+ through that boundary, persist, and return an independent JSON value. There is
193
+ no process-local accumulator cache. A foreign checkpoint newer than the initial
194
+ boundary causes a fresh high-water check. Normal writes are monotone; corrupt,
195
+ wrong-version or ahead-of-log rows are repaired only by comparing the exact row
196
+ observed, atomically with the log boundary. A losing writer still returns its
197
+ correct prefix. Missing or unreadable cache state replays; log failures propagate.
198
+
199
+ The remote adapter makes one value request; only the finished answer crosses the
200
+ wire. The service uses named effective-configuration references for hosted ticket
201
+ operations (including policy publication) and semantic build/harvest lifecycle
202
+ facts for delegated authentication and issuance. Lifecycle snapshots keep session,
203
+ execution and terminal evidence, including historical endings, without dispatcher
204
+ tick tails. Anchor membership follows the contiguous log prefix. The legacy
205
+ state-events route remains a deprecated compatibility endpoint. Public generic
206
+ snapshot routes remain compatible, but current consumer reads do not restore the
207
+ former dispatcher work bundles.
208
+
209
+ **Dispatcher repository view.** `RepoViewStore`
210
+ (`packages/core/src/processes/repo-view.ts`) coordinates repository metadata and
211
+ source promise chains. Its build and journal facts come from persisted reduced
212
+ values. Reads after an append or lost conditional append consult that boundary
213
+ again, so no process-local memo suppresses a required delta. The adapter owns
214
+ cache persistence and recovery; the view neither writes work bundles nor hydrates
215
+ whole logs for decisions. Discovery uses persisted build digests, including for
216
+ settled builds. Raw methods forward actual cursor event output.
217
+
218
+ JSON-safe companion projections preserve collection and optional-value contracts.
219
+ The build facts projection returns one prefix for engine routing; its log-index
220
+ rounds and finalize steps reconstruct Maps and Sets explicitly, while publication
221
+ selectors reconstruct from a JSON ledger. Repository facts retain configuration,
222
+ control, Harvest, and dispatcher run correlations. Lease metadata and clocks stay
223
+ outside event reducers: liveness combines durable run facts with the current
224
+ repository record and observation time, including an older lease holder hidden
225
+ by a newer run. The shared repository value keeps a bounded recent-run window, including the
226
+ latest started and stopped runs. Fresh invocations use those shared facts for
227
+ first-tick publication, liveness and supervision without creating a cold
228
+ parameterized cache. Older holder correlations can use `dispatcherRunFacts` for
229
+ the requested historical run. A never-started fresh invocation does not request
230
+ historical correlation. Stopped dispatcher history is not copied into every
231
+ current read.
232
+
233
+ Hosted project build listings use the optional backing-store
234
+ `listBuildsForRepo` capability with the authenticated repository. Postgres filters
235
+ build rows in SQL before hosted ticket readable-id projection. Admin listings
236
+ remain global; adapters without the capability retain application filtering.
237
+
238
+ **Operator and CLI reads.** Build listings and details, repository and Harvest
239
+ status, dispatcher decisions, operator API queries, MCP delegation and web
240
+ dashboard refreshes use the same typed persisted read helpers. Shared projection
241
+ functions render those facts; whole-array overloads remain reference oracles.
242
+ Operator passes are single-flight per repository, with requests arriving during a
243
+ pass queued for one trailing pass. Fresh readers use persisted cache rows too;
244
+ steady-state event-row cost depends on newly appended events at fixed build/run
245
+ cardinality, not on log length. Reduced collections may legitimately grow in JSON
246
+ size. Cache loss or corruption can replay history once to recover the same answer.
247
+
248
+ Watch and wait register from a compound persisted `buildStreamSeed` at cursor C.
249
+ Its build accumulator, deferral ledger and insertion-ordered historical PR
250
+ eligibility describe that same prefix. Ordinary polling, including the first
251
+ batch on an old build, reads only events after the cursor and advances that seed
252
+ event by event, preserving state at event N in each emitted record. Watch uses
253
+ historical eligibility for baseline suppression; wait retains its separate
254
+ current-attention registration policy. Only an explicit `--since` older than C
255
+ reconstructs a historical prefix once in `cli/historical-build-state.ts`.
256
+ Actual event listings, transcripts and cursor streams remain raw reads. The
257
+ interactive terminal frontend retains its independently established incremental
258
+ feed. `tools/persisted-reduced-reads.test.ts` scans production TypeScript calls
259
+ and maintains precise, reason-bearing exceptions for these boundaries and pure
260
+ reference projections; stale exceptions fail the check.
242
261
 
243
262
  **Session Store authority.** `packages/core/src/cli/binary.ts` validates a complete build or
244
263
  Harvest ambient tuple before opening its phase Store through
@@ -351,7 +370,7 @@ selection (applied at the planner's `ab done` in `packages/core/src/cli/terminal
351
370
  snapshotted by the engine at approval), and
352
371
  `packages/core/src/kernel/verify-applicability.ts` matches changed paths against a step's
353
372
  selectors, resolved by the build runner via `git diff` against the initial
354
- branch-cut base (or the refreshed base promoted by a completed reconcile).
373
+ branch-cut base (or the effective base promoted by successful restack/reconcile publication).
355
374
  This verify-only base is deliberately independent from implementation's
356
375
  focused review range. All narrowing mechanisms produce the ordinary
357
376
  queryable skipped outcome; Git failure is infrastructure and fails closed,
@@ -387,7 +406,19 @@ SIGTERM restore terminal modes immediately and begin one supervised drain;
387
406
  persistent frontend and child handlers keep repeated signals graceful until the
388
407
  kernel child is reaped, after which a non-SIGINT terminating signal is replayed
389
408
  in the frontend. A parent-liveness watch remains the detached-kernel fallback.
390
- Timeout escalation is held while a durable `tick-started` fact remains open,
409
+ The repository record carries constant-size, lease-holder-fenced tick telemetry:
410
+ `beginRepoTick` opens the unsafe boundary, and `finishRepoTick` atomically closes
411
+ it and appends selected tick facts. Successful unchanged ticks append nothing;
412
+ queue transitions, counters, diagnostics, attention resets/retries, and failures
413
+ retain their journal evidence. Buffered starts preserve actual `startedAt` for
414
+ attention cooldowns; old starts use their envelope time. Liveness reads refresh
415
+ the repository record even with an unchanged event cursor, merging matching-run
416
+ completion samples with journal ticks. Heartbeat renewal cannot invent progress.
417
+ The memory, SQLite, Postgres and remote adapters share this contract, including
418
+ no mutation after lease expiry and no partial publication on validation failure.
419
+
420
+ Timeout escalation is held while the matching repository tick observation is open
421
+ (with historical `tick-started` journal fallback when no observation exists),
391
422
  because force-killing the ticket claim before build creation would not be
392
423
  recoverable. After a build child claims a takeover lease, it reduces one
393
424
  captured event prefix and appends transcriptless reclaimed `session.ended`
@@ -511,6 +542,17 @@ receive-pack-free network policy, so even a failed publication-policy restore
511
542
  fails closed before setup or plugin code runs. Normal VM sessions never receive
512
543
  Forge credentials.
513
544
 
545
+ **Forge readiness.** `ports/forge/readiness.ts` owns the portable check inventory,
546
+ classification, plugin fallback, and formatting; `github-readiness.ts` performs
547
+ read-only settings/policy inspection, keeping incomplete evidence unknown. Host
548
+ init validation invokes the configured registry forge outside guest probes.
549
+ Dispatch inspects after acquiring its repository lease and writes validated
550
+ `dispatcher.forge-readiness-failed` facts once per run/check for known hard
551
+ failures. `kernel/dispatch-status.ts` retains their typed collection across ticks
552
+ and reloads; the independent frontend and operator query project the same warnings.
553
+ `ab watch` follows these repository attention events for external orchestrators.
554
+ See [setup](setup.md#forge-readiness) for requirements and access guidance.
555
+
514
556
  **Forge credentials.** `packages/core/src/ports/forge/github-transport.ts` owns the
515
557
  REST transport seam and credential resolution for the builtin GitHub forge:
516
558
  `GITHUB_TOKEN`, then `GH_TOKEN`, then the gh CLI's stored login read through
@@ -524,6 +566,35 @@ dispatcher — requires an exported token before any side effect and never consu
524
566
  a checkout-less host has neither gh nor a keyring, and `vercel-sandbox` publication
525
567
  injects that same token.
526
568
 
569
+ **Stable build identity.** The forge landing seam accepts optional build identity at operation time. Both
570
+ built-in adapters preserve their squash message and normalize a final
571
+ `Autobuild-Build: <slug>` trailer through `packages/core/src/kernel/build-identity.ts`. The GitHub
572
+ adapter reads the viewer's squash headline/body and head in one GraphQL query;
573
+ it never reconstructs server defaults from repository settings. The janitor
574
+ maintains native request message freshness after acknowledgement. A matching
575
+ request costs one GraphQL freshness query and no extra consent or pipeline read;
576
+ full gate inspection and refreshed durable consent/engine eligibility precede
577
+ any repair. Body comparison tolerates provider trimming of trailing whitespace
578
+ while preserving the complete headline, body content, and squash method.
579
+
580
+ Optional `Forge.readCommitMessage` and `Forge.containsBuild` capabilities expose
581
+ actual landed messages and exact trailer presence in reachable branch history.
582
+ The janitor records optional `pr.merged.buildTrailerPresent` for normal and abort
583
+ cleanup observations. Unsupported or failed inspection leaves evidence unknown;
584
+ a read failure also records an observation without preventing completion. Old
585
+ logs need no migration and keep the same status and presentation.
586
+
587
+ GitHub merge queues ignore squash-message overrides. The message query also
588
+ reads `repository.mergeQueue(branch:)`, covering classic protection and rulesets.
589
+ Its branch hint is checked against the PR's actual base, with a bounded re-query
590
+ after a retarget rather than assuming the repository default is the base.
591
+ Kernel auto-merge therefore
592
+ returns an actionable `unproven-gate-state` deferral for queue-protected bases;
593
+ it never bypasses the queue. Human queue landings still settle normally with
594
+ inspected trailer evidence when available. Expected-head guards and recurring
595
+ polls bound native message freshness, but cannot prevent a push and automatic
596
+ landing from both completing between polls.
597
+
527
598
  **Agent runtimes.** `packages/core/src/ports/runner/`: `runtime.ts` (capability-carrying
528
599
  registry plus boundary validation), `routing.ts` (eager role resolver),
529
600
  `production.ts` (shipped Claude/Codex/Pi registrations), `codex.ts` (direct
@@ -671,13 +742,37 @@ queue. The supervised kernel child owns every slow
671
742
  adapter operation, so slug naming, provisioning, runners, and Harvest cannot
672
743
  block input.
673
744
 
745
+ `packages/core/src/cli/dashboard/refresh.ts` owns the shared presentation read
746
+ scheduler for both terminal paths: focused by default, paused on focus-out,
747
+ immediate on focus-in or keys, 500 ms with retained builds or during a 30-second
748
+ interaction hold, and 5 seconds when idle. Presentation store facades check
749
+ admission at every asynchronous read stage; the kernel uses its original store
750
+ and independent tick timers. Cached clock paints perform no reads. The mode
751
+ ledger owns focus reporting through teardown and catchable faults; job-control
752
+ suspension restores modes and input before stopping and reactivates with assumed
753
+ focus on resume. Plain, non-TTY, and once runs never enable focus reporting.
754
+
674
755
  `packages/core/src/cli/build-progress.ts` projects the exact last-event, heartbeat, and lease
675
756
  inputs shared by the diagnostic `ab builds` and `ab build status` surfaces. Its
676
757
  one-hour `diverged` predicate is presentation-only: reducer status, engine
677
758
  routing, and lease health remain independent. `packages/core/src/cli/dashboard/model.ts` is
678
759
  the event-derived build-row projection; `poll.ts` reprojects rows for event or
679
- effective-config changes and reuses them across heartbeat/lease-only renewals
680
- while retaining the cached log and reduction.
760
+ effective-config changes and bounded enrichment refreshes while retaining the
761
+ cached log and reduction. `repository-poll.ts` serializes the complete presentation
762
+ snapshot in both terminal paths. It samples `getRepoChangePosition` before reads,
763
+ acknowledges it only after complete admitted reads, and reuses unchanged snapshots
764
+ for up to ten seconds. Scoped discovery uses `listBuildsForRepo`; unchanged focused
765
+ frames make one counter request. Session feeds remain independent.
766
+
767
+ The memory adapter maintains independent bigint counters; SQLite and PostgreSQL
768
+ increment `repo_change_positions` transactionally through triggers on build,
769
+ build-event, repository-event insertion and null-safe repository lease holder
770
+ changes. Reads return decimal text (unknown repos: `"0"`) without journal creation.
771
+ The hosted counter route returns only that position; scoped build discovery has
772
+ its own repository-authorized route before the journal-existence gate. PostgreSQL
773
+ counter DDL is additive, outside the guarded core schema/checksum, and must be
774
+ explicitly migrated before the service rollout. Existing writers use the same
775
+ triggers; rerunning migration preserves positions without replaying old events.
681
776
  `detail.ts` projects chronological session history from the same retained log,
682
777
  including a distinct transcriptless `reclaimed` ending, and `transcript.ts`
683
778
  heuristically presents ordinary opaque transcript artifacts with a raw
@@ -962,13 +1057,13 @@ revisions rather than ignoring them.
962
1057
 
963
1058
  `ab ticket edit <id>` opens `$VISUAL`, falling back to `$EDITOR`, using TOML
964
1059
  frontmatter and a Markdown body. Only title, body and labels are editable;
965
- id, blockers, creation key and reference comments are read-only. It saves only
1060
+ kind, target, id, blockers, creation key and reference comments are read-only. It saves only
966
1061
  changed fields with the opening revision. Unchanged or formatting-only edits
967
1062
  write nothing. On conflict, invalid input or editor failure, the error names an
968
1063
  absolute file path containing the edited text. Read the current ticket and
969
1064
  reapply the intended changes before retrying; conflicts are never merged.
970
1065
 
971
- File and Linear revisions fingerprint title, body, canonical label/blocker sets
1066
+ File and Linear revisions fingerprint kind, target, title, body, canonical label/blocker sets
972
1067
  and state; reverting identical content restores its fingerprint. File checks
973
1068
  re-read immediately before writing, with the existing no-lock race window.
974
1069
  Direct file edits and state-directory moves change revisions. File comments
@@ -994,3 +1089,155 @@ Hosted ticket detail reads expose complete, oldest-first structured comments in
994
1089
  HTTP clients opt in with `x-autobuild-ticket-comments: 1` so historical strict
995
1090
  decoders retain compatible responses. File comments remain embedded in the body;
996
1091
  Linear comment reads are unchanged.
1092
+
1093
+ Ticket integration metadata lives in `ports/tickets/tree.ts`: source compatibility
1094
+ normalization, capability refusal, graph validation and the pure tree projection.
1095
+ File/fake/Linear adapters validate metadata at write boundaries; `operations.ts`
1096
+ and CLI/operator source opening wrap injected or plugin sources with the same
1097
+ compatibility facade. Metadata is excluded from hosted persistence/protocols.
1098
+
1099
+
1100
+ ### Integration node dispatch
1101
+
1102
+ The product dispatcher owns the workspace-free node lifecycle:
1103
+ spec → node.opening → node.opened → collecting → complete → verify:* → consent → land.
1104
+ The ordinary work pipeline is unchanged. `build.created` freezes kind, target
1105
+ ticket/build identity and resolved parent in `baseBranch`. Integration facts
1106
+ are projected by the shared reducer and digests, including collecting/empty
1107
+ state. Admission resolves same-source targets through repository read facts;
1108
+ integration identities remain active for deduplication but consume no work slot.
1109
+
1110
+ Optional Forge node branch creation and comparison capabilities let GitHub
1111
+ operate without a checkout and local-git operate directly on its shared refs.
1112
+ Opening intent retains the sampled SHA across retries; adoption requires that
1113
+ commit in the existing branch's history. Comparison uses reachability, so an
1114
+ advanced parent never makes an empty node nonempty. The janitor opens PRs lazily
1115
+ and reuses terminal cleanup without leaf reconcile or auto-merge.
1116
+
1117
+ ### Leaf and reconcile restacking
1118
+
1119
+ The kernel prepares a detached replay of one net build change on the base frozen
1120
+ by `reconcile.started`. The contribution baseline is the initial branch-cut base
1121
+ or latest successfully published restack/reconcile base. The resolver continues that one replay;
1122
+ completion requires one parent at the frozen base and the build identity trailer.
1123
+ Historical merge completions retain their original shape and semantics.
1124
+
1125
+ The optional grouped Forge rewrite capability owns authoritative head snapshots,
1126
+ immutable `refs/autobuild/archive/<slug>/<sha>` publication and expected-head CAS.
1127
+ GitHub uses explicit Git transport leases; local-git uses shared-database
1128
+ `update-ref` CAS without network calls. Trusted remote publication archives before
1129
+ replacement after guest teardown; it never uses ordinary append-only publication
1130
+ for restacks. Prepared, replayed, intended and rewritten facts support recovery.
1131
+ A contended rewrite preserves the observed work and retries on the same base.
1132
+
1133
+ `kernel/leaf-restack-state.ts` projects target observations, frozen transactions
1134
+ and cycle gates into the log index and persisted build facts. The engine selects
1135
+ automatic kernel work before any verify action and after finalize post-steps when
1136
+ the target moves. `reconcile-restack.ts` shares collapse, detached replay,
1137
+ archive-before-replacement and expected-head publication mechanics. Automatic
1138
+ transactions emit `restack.*`; clean completion never starts a reconcile cycle.
1139
+ Pre-PR conflicts adopt the prepared replay through ordinary reconcile. Initial
1140
+ verification remains mandatory; waiting conflicts use post-reconcile policy.
1141
+
1142
+ The dispatcher observes targets without changing workspaces; execution ownership
1143
+ and session settlement fence mutation. Transaction targets stay frozen while
1144
+ later moves coalesce. `publication.requested` carries automatic transaction
1145
+ identity through trusted remote teardown and publication. The runner settles
1146
+ local resolver intent only after its session ends. Verification facts
1147
+ cite the cycle's base/head, and clean waiting rewrites preserve those results.
1148
+ Object packs retain newly introduced replay trees/blobs as well as commit bytes.
1149
+
1150
+ GitHub archive push/fresh-fetch and rewrite contracts are manual opt-in cases in
1151
+ `ports/forge/github.live.test.ts`, using `AB_RUN_LIVE_PORT_CONTRACTS=1` and an
1152
+ explicit disposable `AB_GITHUB_CONTRACT_REPO`. Offline transport tests are not
1153
+ live provider evidence.
1154
+
1155
+ ### Descendant node restacking
1156
+
1157
+ `kernel/node-restack.ts` inventories the contribution above the durable previous
1158
+ base, proves foreign merge safety against the sampled parent's full identity set,
1159
+ and replays individual changes. `kernel/node-restack-state.ts` reduces writer
1160
+ reservations, ordered receipts, conflicts, publication intent, confirmed effects,
1161
+ and inventory. `kernel/node-restack-transaction.ts` retains replay objects and
1162
+ archives before expected-head publication. The dispatcher polls all open nodes,
1163
+ including empty nodes, and advances clean cascades without agent calls. Only the
1164
+ active conflicted item attaches a reconcile runner, using source-build artifacts
1165
+ materialized by the dispatcher into the integration owner's store scope.
1166
+
1167
+ `kernel/node-parent.ts` coordinates lifecycle-aware target mutations for CLI
1168
+ and operator requests. It canonicalizes source aliases, checks the latest build
1169
+ generation and proposed/effective/pending ancestry, and reserves a durable
1170
+ `node.parent-requested` before provider mutation. Claimed work targets stay frozen;
1171
+ a changed target requires abort and re-dispatch before any mixed patch is written.
1172
+ The dispatcher reads node tickets independently of readiness and activates a
1173
+ confirmed, revalidated request with `node.parent-accepted`. Provider edits use
1174
+ the same validation; refusals are deduplicated by revision, target and reason.
1175
+ Uncertain writes recover by source readback rather than replaying a caller patch.
1176
+ Tracker observation errors are contained within that observation, preserving
1177
+ ordinary cascade and PR handling against durable ancestry. Already accepted moves
1178
+ complete their PR effects without another tracker read. Rejection comparisons use
1179
+ revision, target and reason fields so JSONB key ordering cannot defeat deduplication;
1180
+ `node.parent-rejection-cleared` removes a current refusal after correction while
1181
+ preserving its history.
1182
+
1183
+ Accepted parent facts update node target/base projections while creation facts
1184
+ remain provenance. Pending requests and moves fence verification, child landing
1185
+ and source landing, and count against both parents' completeness. Existing writer
1186
+ reservations settle before activation. The existing replay transaction freezes the
1187
+ new destination and retains the old contribution boundary until completion, even
1188
+ for distinct parents at the same SHA. Afterwards the dispatcher retargets the same
1189
+ PR through the optional `Forge.retargetPr` capability, inspects its acknowledged
1190
+ base/head, records a receipt and completes the parent operation. GitHub uses the
1191
+ [documented PR update endpoint](https://docs.github.com/en/rest/pulls/pulls#update-a-pull-request)
1192
+ with a branch-name `base`. Publication and PR acknowledgement retry separately;
1193
+ terminal human PR changes keep their ordinary handling. Children retain the moved
1194
+ node's identity and branch, so the usual target observations cascade the move.
1195
+
1196
+ In origin mode, node plumbing uses the forge's trusted `kernelExec` transport.
1197
+ The GitHub adapter supplies its token through subprocess-only Git configuration,
1198
+ scoped to the repository's HTTPS URL; credentials are absent from argv, saved
1199
+ remote URLs, repository configuration and agent environments. Parent snapshots,
1200
+ archives and expected-head writes use this same transport. The dispatcher checks
1201
+ parent and node heads through the forge API before acquiring a repository: an
1202
+ unchanged inventory needs no clone or Git commands. A required temporary clone
1203
+ completes before the node writer lease is acquired, so download time cannot
1204
+ expire writer authority. Build sandbox publication retains its separate trusted
1205
+ receive-pack path.
1206
+
1207
+ `kernel/node-landing.ts` shares the node writer lease and reservation with
1208
+ restacking. It cancels native auto-merge, refreshes actual PR refs, proves the
1209
+ exact destination ungated and fast-forwards the canonical child commit under
1210
+ CAS. The destination write proves landing; provider PR reconciliation is
1211
+ best-effort and never decides or retries that write. Root landing retains squash
1212
+ semantics. Store adapters expose node writer claim, renewal and holder-checked
1213
+ release separately from execution leases; Postgres schema version 15 adds their
1214
+ columns. Reservations live in the event stream and survive lease expiry.
1215
+
1216
+ The contribution boundary advances only on completed restacks. Reachable build
1217
+ identities include inherited parent changes; foreign counts include only the
1218
+ node's own contribution, preventing a parent rewrite from inflating descendants'
1219
+ foreign inventory. Status text and JSON expose both inventory and active items.
1220
+
1221
+
1222
+ Integration completion is sampled by `kernel/integration-completeness.ts` from
1223
+ exhaustive source listings, frozen claims and retained contribution identities.
1224
+ `integration.*` events retain observations, immutable cycle inputs, landing
1225
+ intents, provenance and tree audits. The build reducer projects these facts and
1226
+ `engine.ts` routes nodes directly through verification, without producer phases.
1227
+ Failed cycles park for repair children. The dispatcher temporarily provisions
1228
+ verification resources and rechecks head, parent, controls and completeness
1229
+ before publication. `integration-landing.ts` owns source-reserved root landing
1230
+ and immutable result audits; nested nodes use the destination writer transaction
1231
+ in `node-landing.ts`. GitHub uses guarded PR rebase; local-git uses an ancestry
1232
+ proof and exact-parent fast-forward. Shared status vocabulary exposes provenance
1233
+ and mismatch attention in both frontends. Human forge merges remain observable
1234
+ escape hatches independent of completeness and verification.
1235
+
1236
+ ### Landing authorization
1237
+
1238
+ The pure evaluator in `kernel/landing-policy.ts` chooses the first matching
1239
+ `[[landing]]` rule. `kernel/landing-state.ts` reduces immutable candidate
1240
+ decisions and persistent hold/land commands. The dispatcher owns readiness,
1241
+ ticket label sampling and native-state convergence. `kernel/landing-publication.ts`
1242
+ confirms native cancellation at local and trusted remote head-publication seams.
1243
+ Node landings retain the existing writer serialization and gate proof.
Binary file