@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,30 +1,30 @@
1
+ import { readRepositoryFacts, readDispatcherRunFacts } from '../store/reduced-reads'
1
2
  import type { RepositoryEvent } from '../events/repository'
2
3
  import type { BuildStore, RepositoryRecord } from '../store/types'
3
4
  import { formatDispatcherIdentity, projectDispatcherLiveness } from '../kernel/dispatcher-liveness'
4
5
 
5
- /** Bounded first; a later yielding invocation can hide the owner's identity or
6
- * an earlier stop. Only this correlation query falls back to full history. */
6
+ /** Correlate only the latest, stopped and lease-holder runs through persisted values. */
7
7
  export async function readDispatcherLiveness(
8
8
  store: BuildStore,
9
9
  repo: string,
10
10
  now = new Date(),
11
- subset?: RepositoryEvent[],
11
+ _subset?: RepositoryEvent[],
12
12
  ) {
13
13
  const record = await store.getRepo(repo)
14
- let events = record === null ? [] : (subset ?? (await store.getRepoStateEvents(repo)))
15
- const bounded = projectDispatcherLiveness(record, events, now)
16
- if (
17
- record &&
18
- ((record.lease &&
19
- !events.some(
20
- (e) => e.type === 'dispatcher.run-started' && e.payload.run === record.lease!.holder,
21
- )) ||
22
- (bounded.state !== 'held' &&
23
- events.some((e) => e.type === 'dispatcher.run-started') &&
24
- !events.some((e) => e.type === 'dispatcher.run-stopped')))
25
- ) {
26
- events = await store.getRepoEvents(repo)
27
- }
14
+ const facts = record === null ? undefined : (await readRepositoryFacts(store, repo)).value
15
+ const runs = new Set(
16
+ [facts?.latestRun, facts?.latestStoppedRun, record?.lease?.holder].filter(
17
+ (run): run is string => run !== undefined,
18
+ ),
19
+ )
20
+ const correlations = await Promise.all(
21
+ [...runs].map(async (run) => (await readDispatcherRunFacts(store, repo, run)).value),
22
+ )
23
+ const events = correlations.flatMap((run) =>
24
+ [run.start, run.latestStart, run.stop, run.tick].filter(
25
+ (event): event is RepositoryEvent => event !== undefined,
26
+ ),
27
+ )
28
28
  return { record, events, dispatcher: projectDispatcherLiveness(record, events, now) }
29
29
  }
30
30
 
@@ -32,6 +32,8 @@ export async function readDispatcherLiveness(
32
32
  * always come from the current lease record and clock. Failed correlations are
33
33
  * negatively cached so a standby cannot repeatedly replay a large journal. */
34
34
  export class StandbyIdentityResolver {
35
+ private failed = false
36
+ private record: RepositoryRecord | null = null
35
37
  private readonly starts = new Map<string, RepositoryEvent>()
36
38
  private readonly attempted = new Set<string>()
37
39
  private readonly pending = new Map<string, Promise<void>>()
@@ -39,6 +41,10 @@ export class StandbyIdentityResolver {
39
41
  constructor(
40
42
  private readonly store: BuildStore,
41
43
  private readonly repo: string,
44
+ private readonly history?: {
45
+ allowLookup: () => boolean
46
+ remember: (events: RepositoryEvent[], complete: boolean) => void
47
+ },
42
48
  ) {}
43
49
 
44
50
  ingest(events: readonly RepositoryEvent[]): void {
@@ -51,11 +57,14 @@ export class StandbyIdentityResolver {
51
57
  const pending = this.pending.get(holder)
52
58
  if (pending !== undefined) return pending
53
59
  if (this.starts.has(holder) || this.attempted.has(holder)) return
60
+ if (this.history && !this.history.allowLookup()) return
54
61
  this.attempted.add(holder)
55
62
  const lookup = (async () => {
56
63
  try {
57
- this.ingest(await this.store.getRepoStateEvents(this.repo))
58
- if (!this.starts.has(holder)) this.ingest(await this.store.getRepoEvents(this.repo, 0))
64
+ const facts = (await readDispatcherRunFacts(this.store, this.repo, holder)).value
65
+ this.ingest(facts.start ? [facts.start] : [])
66
+ const complete = false // This lookup correlates one holder, not the complete journal.
67
+ this.history?.remember([...this.starts.values()], complete)
59
68
  } catch {
60
69
  // Identity is best effort; the sampled holder id remains sufficient.
61
70
  }
@@ -77,12 +86,23 @@ export class StandbyIdentityResolver {
77
86
  try {
78
87
  record = await this.store.getRepo(this.repo)
79
88
  } catch {
89
+ this.failed = true
80
90
  return yieldedHolder
81
91
  }
92
+ this.failed = false
93
+ this.record = record
94
+ const holder = record?.lease?.holder
95
+ if (holder !== undefined && holder !== run) await this.correlate(holder)
96
+ return this.current(run, yieldedHolder, now)
97
+ }
98
+
99
+ /** Reformat sampled liveness against the paint clock without store I/O. */
100
+ current(run: string, _yieldedHolder: string | undefined, now: Date): string | undefined {
101
+ if (this.failed) return _yieldedHolder
102
+ const record = this.record
82
103
  const holder = record?.lease?.holder
83
104
  if (holder === run) return undefined
84
- if (holder === undefined) return yieldedHolder
85
- await this.correlate(holder)
105
+ if (holder === undefined) return undefined
86
106
  if (!this.starts.has(holder)) return holder
87
107
  const projection = projectDispatcherLiveness(record, [...this.starts.values()], now)
88
108
  const identity = projection.holder ?? projection.expiredHolder
@@ -1,3 +1,4 @@
1
+ import { readRepositoryFacts, type RepositoryReadFacts } from '../store/reduced-reads'
1
2
  /** Typed agent/operator surface for repository-scoped harvest workflows. Agent
2
3
  * stdout is never interpreted: proposal sets and review verdicts land through
3
4
  * this module as validated repository events and versioned artifacts. */
@@ -67,8 +68,8 @@ async function writeJson(path: string, value: unknown): Promise<void> {
67
68
  await writeFile(path, `${JSON.stringify(value, null, 2)}\n`)
68
69
  }
69
70
 
70
- function runForEnv(events: RepositoryEvent[], env: HarvestCliEnv): HarvestRunState {
71
- const run = reduceHarvest(events).runs.find((candidate) => candidate.run === env.run)
71
+ function runForEnv(events: RepositoryReadFacts, env: HarvestCliEnv): HarvestRunState {
72
+ const run = events.harvest.runs.find((candidate) => candidate.run === env.run)
72
73
  if (!run) throw new Error(`unknown harvest run "${env.run}" in repo "${env.repo}"`)
73
74
  if (run.status !== 'running') {
74
75
  throw new Error(
@@ -78,34 +79,44 @@ function runForEnv(events: RepositoryEvent[], env: HarvestCliEnv): HarvestRunSta
78
79
  return run
79
80
  }
80
81
 
81
- function assertNoSessionTerminal(events: RepositoryEvent[], env: HarvestCliEnv): void {
82
- for (const event of events) {
83
- if (
84
- event.type === 'harvest.proposals.submitted' &&
85
- env.phase === 'synthesize' &&
86
- event.payload.run === env.run &&
87
- event.payload.round === env.round
88
- ) {
89
- throw new Error(
90
- `second harvest terminal rejected: proposals for ${env.run} synthesize@${env.round} already landed at repo seq ${event.seq}`,
91
- )
92
- }
93
- if (
94
- event.type === 'harvest.review.verdict' &&
95
- env.phase === 'review' &&
96
- event.payload.run === env.run &&
97
- event.payload.round === env.round
98
- ) {
99
- throw new Error(
100
- `second harvest terminal rejected: verdict for ${env.run} review@${env.round} already landed at repo seq ${event.seq}`,
101
- )
102
- }
103
- if (event.type === 'harvest.session.ended' && event.payload.session === env.session) {
104
- throw new Error(
105
- `harvest terminal rejected: session "${env.session}" already ended at repo seq ${event.seq}`,
106
- )
107
- }
108
- }
82
+ function assertNoSessionTerminal(events: RepositoryReadFacts, env: HarvestCliEnv): void {
83
+ const run = events.harvest.runs.find((run) => run.run === env.run)
84
+ const proposal =
85
+ env.phase === 'synthesize'
86
+ ? run?.proposals.find((proposal) => proposal.round === env.round)
87
+ : undefined
88
+ const review =
89
+ env.phase === 'review'
90
+ ? events.harvestVerdicts[JSON.stringify([env.run, env.round])]?.first
91
+ : undefined
92
+ const ended = events.harvestSessionEndings[JSON.stringify(env.session)]
93
+ const errors = [
94
+ ...(proposal
95
+ ? [
96
+ {
97
+ seq: proposal.seq,
98
+ message: `second harvest terminal rejected: proposals for ${env.run} synthesize@${env.round} already landed at repo seq ${proposal.seq}`,
99
+ },
100
+ ]
101
+ : []),
102
+ ...(review
103
+ ? [
104
+ {
105
+ seq: review.seq,
106
+ message: `second harvest terminal rejected: verdict for ${env.run} review@${env.round} already landed at repo seq ${review.seq}`,
107
+ },
108
+ ]
109
+ : []),
110
+ ...(ended
111
+ ? [
112
+ {
113
+ seq: ended,
114
+ message: `harvest terminal rejected: session "${env.session}" already ended at repo seq ${ended}`,
115
+ },
116
+ ]
117
+ : []),
118
+ ].sort((a, b) => a.seq - b.seq)
119
+ if (errors[0]) throw new Error(errors[0].message)
109
120
  }
110
121
 
111
122
  async function readArtifactJson(
@@ -122,7 +133,7 @@ async function readArtifactJson(
122
133
  export async function buildHarvestContext(deps: HarvestCliDeps): Promise<HarvestContextManifest> {
123
134
  const { store, env, workspacePath } = deps
124
135
  // Bounded read (AUT-489): runForEnv reduces harvest facts only.
125
- const events = await store.getRepoStateEvents(env.repo)
136
+ const events = (await readRepositoryFacts(store, env.repo)).value
126
137
  const run = runForEnv(events, env)
127
138
  const packet = await loadScanPacket(store, env.repo, run.scan)
128
139
  const abDir = join(workspacePath, '.ab')
@@ -230,7 +241,7 @@ export async function submitHarvestProposals(
230
241
  }
231
242
  // Bounded read (AUT-489): runForEnv and assertNoSessionTerminal consume
232
243
  // harvest facts only.
233
- const events = await store.getRepoStateEvents(env.repo)
244
+ const events = (await readRepositoryFacts(store, env.repo)).value
234
245
  const run = runForEnv(events, env)
235
246
  assertNoSessionTerminal(events, env)
236
247
 
@@ -322,7 +333,7 @@ export async function submitHarvestVerdict(
322
333
  }
323
334
  // Bounded read (AUT-489): runForEnv and assertNoSessionTerminal consume
324
335
  // harvest facts only.
325
- const events = await store.getRepoStateEvents(env.repo)
336
+ const events = (await readRepositoryFacts(store, env.repo)).value
326
337
  const run = runForEnv(events, env)
327
338
  assertNoSessionTerminal(events, env)
328
339
  if (proposalArtifactForRound(run, env.round) === undefined) {
@@ -602,19 +613,35 @@ function projectHarvestRunStatus(run: HarvestRunState): Omit<HarvestRunStatusVie
602
613
 
603
614
  export function projectHarvestStatus(
604
615
  repo: string,
605
- events: RepositoryEvent[],
616
+ events: RepositoryEvent[] | RepositoryReadFacts,
606
617
  newestEvents?: number,
607
618
  streams?: readonly StreamRecord[],
608
619
  ): HarvestStatusView {
609
- const state = reduceHarvest(events)
620
+ const state = Array.isArray(events) ? reduceHarvest(events) : events.harvest
610
621
  const history =
611
- newestEvents === undefined ? undefined : events.filter(isHarvestEvent).slice(-newestEvents)
622
+ newestEvents === undefined || !Array.isArray(events)
623
+ ? undefined
624
+ : events.filter(isHarvestEvent).slice(-newestEvents)
612
625
  const unresolved = [...parkedHarvestRuns(state), ...unresolvedHarvestAttentionRuns(state)]
613
626
  const open = openHarvestRuns(state)
614
627
  const included = new Set(
615
628
  [...unresolved, ...open, ...(state.latest ? [state.latest] : [])].map((run) => run.run),
616
629
  )
617
- const sessionsByRun = projectHarvestSessions(events, streams)
630
+ const sessionsByRun = Array.isArray(events)
631
+ ? projectHarvestSessions(events, streams)
632
+ : new Map<string, HarvestSessionStatusView[]>()
633
+ if (!Array.isArray(events))
634
+ for (const { run, ...session } of events.harvestSessions) {
635
+ const record = streams?.find(
636
+ (record) => record.scope.kind === 'repo' && record.label === `session:${session.session}`,
637
+ )
638
+ const list = sessionsByRun.get(run) ?? []
639
+ list.push({
640
+ ...session,
641
+ ...(record ? { stream: record.id, streamStatus: record.status } : {}),
642
+ })
643
+ sessionsByRun.set(run, list)
644
+ }
618
645
  const runs = state.runs
619
646
  .filter((run) => included.has(run.run))
620
647
  .map((run) => ({
@@ -802,7 +829,7 @@ export async function abHarvestStatus(opts: HarvestStatusOpts): Promise<void> {
802
829
  async ({ store, repo }) => {
803
830
  const record = await store.getRepo(repo)
804
831
  // Bounded read (AUT-489): projectHarvestStatus reduces harvest facts only.
805
- const events = record === null ? [] : await store.getRepoStateEvents(repo)
832
+ const events = (await readRepositoryFacts(store, repo)).value
806
833
  // Best-effort stream enrichment for the session rows, mirroring the
807
834
  // degrade-gracefully pattern of 'ab build status': a store that cannot
808
835
  // list streams keeps the payload-derived projection instead of failing.
@@ -814,7 +841,12 @@ export async function abHarvestStatus(opts: HarvestStatusOpts): Promise<void> {
814
841
  streams = undefined
815
842
  }
816
843
  }
817
- const view = projectHarvestStatus(repo, events, opts.events, streams)
844
+ const view = projectHarvestStatus(repo, events, undefined, streams)
845
+ if (opts.events !== undefined)
846
+ view.events =
847
+ record === null
848
+ ? []
849
+ : (await store.getRepoEvents(repo)).filter(isHarvestEvent).slice(-opts.events)
818
850
  if (opts.json === true) opts.stdout(JSON.stringify(view, null, 2))
819
851
  else for (const line of renderHarvestStatus(view)) opts.stdout(line)
820
852
  },
@@ -125,7 +125,7 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
125
125
  summary: 'Run the repository build dispatcher and dashboard.',
126
126
  detail: page([
127
127
  'Usage:',
128
- ' ab dispatch [--once] [--interval <s>] [--store <ref>] [--plain] [--intake | --no-intake] [--auto-merge | --no-auto-merge]',
128
+ ' ab dispatch [--once] [--interval <s>] [--store <ref>] [--plain] [--intake | --no-intake]',
129
129
  '',
130
130
  'Run the outer loop for this repository: resume current builds, run the',
131
131
  'janitor and lease sweep, and dispatch ready work (§3.3, §12). This command',
@@ -138,19 +138,16 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
138
138
  ' --plain Force line-oriented output.',
139
139
  ' --intake Durably turn new ticket intake on.',
140
140
  ' --no-intake Durably turn new ticket intake off.',
141
- ' --auto-merge Durably enable auto-merge intent for newly claimed builds.',
142
- ' --no-auto-merge Durably disable that claim-time default.',
141
+ 'With omission, intake reuses stored state (fresh repository: on).',
143
142
  '',
144
- 'The intake and auto-merge flags durably set repository defaults; omission reuses stored state (fresh repo: intake on, auto-merge off).',
145
- '--auto-merge seeds durable intent on newly claimed builds only. Opposite forms of the same setting cannot be combined.',
146
143
  '',
147
144
  'An interactive terminal gets a fixed global/harvest/build dashboard.',
148
145
  'TTY controls:',
149
146
  ' Up/Down Select the global, Harvest, or a build row.',
150
147
  ' h Toggle harvesting when the global row is selected.',
151
148
  ' i Toggle intake when the global row is selected.',
152
- ' m Toggle the claim-time default on the global row, or durable',
153
- ' auto-merge intent on a build.',
149
+ ' l Land the selected ready build.',
150
+ ' o Hold the selected landing.',
154
151
  ' p On the global row, pause every pausable build and turn intake',
155
152
  ' off. On a build, pause or cancel a pending pause; on Harvest,',
156
153
  ' resume or acknowledge the run.',
@@ -172,11 +169,12 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
172
169
  summary: 'Create, groom, inspect, and move source-agnostic tickets.',
173
170
  detail: page([
174
171
  'Usage:',
175
- ' ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--json]',
172
+ ' ab ticket tree [--json]',
173
+ ' ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--kind work|node] [--target <id> | --no-target] [--json]',
176
174
  ' ab ticket edit <id>',
177
175
  ' ab ticket export <dir> [--store <ref>]',
178
176
  ' ab ticket import <dir> [--store <ref>]',
179
- ' ab ticket update <id> [--title <title>] [--body <file>] [--labels a,b] [--expected-revision <opaque>] [--json]',
177
+ ' ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--expected-revision <opaque>] [--json]',
180
178
  ' ab ticket block <id> <blocker-id[,blocker-id...]> [--expected-revision <opaque>] [--json]',
181
179
  ' ab ticket unblock <id> <blocker-id[,blocker-id...]> [--expected-revision <opaque>] [--json]',
182
180
  ' ab ticket list [--state <state>] [--labels a,b] [--json]',
@@ -192,7 +190,13 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
192
190
  'Every JSON ticket read includes an opaque revision. update, move, block and',
193
191
  'unblock accept --expected-revision to refuse stale writes. Linear refuses checks.',
194
192
  'edit opens VISUAL or EDITOR, checks the opening revision, and preserves failed buffers.',
195
- 'create files a ticket and may establish initial blockers.',
193
+ `create files a ticket and may establish initial blockers.
194
+ --kind work|node declares a ticket's kind; work is the default. --target <id>
195
+ names a same-source node; --no-target clears it to the baseBranch root.
196
+ Targets cannot form cycles, and nodes with targeting tickets cannot become work.
197
+ tree shows all tickets nested by target, including completed work and empty nodes;
198
+ --json returns {root, children} with recursive {ticket, children} entries.
199
+ These fields describe intent; dispatch and landing behavior are unchanged.`,
196
200
  '--state overrides [tickets].createState (or the provider default) for that',
197
201
  'create only; it is passed through unchanged and validated by the source.',
198
202
  'update partially replaces editable fields: omitted fields survive, --labels',
@@ -202,7 +206,7 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
202
206
  '',
203
207
  'With no list filters, list uses the same ready criteria as dispatch. show one ticket, including its body/spec.',
204
208
  'Human output is the default. --json emits exactly one bare value: Ticket[]',
205
- 'for list and the complete resulting Ticket for every other subcommand; show',
209
+ 'for list, the hierarchy for tree, and the resulting Ticket for ticket mutations; show',
206
210
  'adds an assets array (kind, name, revision, size, layout, fileCount).',
207
211
  '',
208
212
  'Ticket assets are files or folders (a design export, a reference screenshot, a',
@@ -241,16 +245,27 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
241
245
  'Usage:',
242
246
  ' ab repository status [--json] [--store <ref>]',
243
247
  '',
244
- 'Report the durable ticket-intake setting, repository-wide pause, and',
245
- 'claim-time auto-merge default from the same journal projection used by',
246
- 'dispatch and the dashboard. A repository with no setting events reports',
247
- 'the defaults: intake on, repository pause off, and auto-merge default off.',
248
+ 'Report the durable ticket-intake setting and repository-wide pause from',
249
+ 'the same journal projection used by dispatch and the dashboard.',
250
+ 'The defaults are intake on and repository pause off. Landing policy is',
251
+ 'configured with [[landing]] rules in autobuild.toml.',
248
252
  '',
249
253
  '--json emits one bare object for scripts. --store overrides AB_STORE, which',
250
254
  'overrides the repository-local .autobuild store. This sessionless command',
251
255
  'writes no state and starts no dispatcher, runner, ticket claim, or other work.',
252
256
  ]),
253
257
  },
258
+ {
259
+ name: 'landings',
260
+ audience: 'human',
261
+ summary: 'List ready landings awaiting consent.',
262
+ detail: page([
263
+ 'Usage: ab landings [--json] [--store <ref>]',
264
+ 'Shows ready consent and held landings with effective target, branch, verification and node children.',
265
+ 'Use ab land <slug> to consent or ab hold <slug> to withdraw consent. Land rechecks readiness.',
266
+ 'Source ancestry is available separately through ab ticket tree or MCP tickets.tree.',
267
+ ]),
268
+ },
254
269
  {
255
270
  name: 'builds',
256
271
  audience: 'human',
@@ -331,10 +346,12 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
331
346
  ' flushed as soon as it is written.',
332
347
  ' --store <ref> Override the BuildStore path or URL.',
333
348
  '',
334
- 'Default filter — actionable attention only. Builds: escalation.raised and',
335
- 'build.merge-decision (finalized open PR, auto-merge off or currently deferred).',
336
- 'Armed consent awaiting application is silent; one merge decision per build/PR.',
337
- 'Repository: harvest.escalated, harvest.recovery-exhausted, dispatcher.config-rejected,',
349
+ 'Default filter — actionable attention only. Builds: escalation.raised, integration.landed,',
350
+ 'node.item-conflicted, conflicted restack.replayed, derived build.consent-ready and',
351
+ 'build.merge-decision (a current actionable merge-gate deferral or unsafe forge outcome).',
352
+ 'Consent and held ready landings use only build.consent-ready, once per readiness episode.',
353
+ 'Unready or stale consent candidates stay silent; one merge gate decision per build/PR.',
354
+ 'Repository: harvest.escalated, harvest.recovery-exhausted, dispatcher.config-rejected, dispatcher.forge-readiness-failed,',
338
355
  'dispatcher.config-reloaded with restartRequired, abnormal dispatcher.run-stopped,',
339
356
  'and dispatcher.lost. dispatcher.ticket-source-persistent reports degradation past',
340
357
  'resetAt after a tick started at or after reset completes or fails while still degraded,',
@@ -393,10 +410,11 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
393
410
  'error before waiting begins.',
394
411
  '',
395
412
  'Conditions (--for, repeatable): blocked, paused, running, done, aborted, terminal (done',
396
- 'or aborted), pr=open, pr=merged, pr=closed, pr=conflicted, phase=<phase> (a core phase —',
413
+ 'or aborted), pr=open, pr=merged, pr=closed, consent, node-landed, restack-conflicted, pr=conflicted, phase=<phase> (a core phase —',
397
414
  'plan, plan-review, implement, code-review, finalize, reconcile — or verify:<step>), and',
398
- 'attention (an open escalation or a build waiting for a merge decision). Merge attention',
399
- 'requires a finalized open PR with auto-merge off or a current actionable gate deferral;',
415
+ 'attention (an open escalation, consent readiness, a node landing or restack conflict,',
416
+ 'or a build waiting for a merge decision). Merge attention',
417
+ 'requires a current actionable gate deferral or an unsafe forge outcome;',
400
418
  'armed pending consent, routine outcomes and self-healing failures stay silent.',
401
419
  'An unknown condition value is rejected before',
402
420
  'any store access. Repeatable --event globs follow the ab watch rules. Multiple --for',
@@ -582,19 +600,18 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
582
600
  'may not control its own build.',
583
601
  ]),
584
602
  },
585
- {
586
- name: 'auto-merge',
587
- audience: 'human',
588
- summary: 'Enable or cancel native auto-merge for one build.',
603
+ ...(['hold', 'land'] as const).map((name) => ({
604
+ name,
605
+ audience: 'human' as const,
606
+ summary:
607
+ name === 'hold' ? 'Hold a landing and withdraw consent.' : 'Consent to a ready landing.',
589
608
  detail: page([
590
- 'Usage:',
591
- ' ab auto-merge <slug> <on|off> [--store <ref>]',
609
+ `Usage: ab ${name} <slug> [--store <ref>]`,
592
610
  '',
593
- 'Request or cancel native squash auto-merge for an active build. --store',
594
- 'overrides the BuildStore path or URL. This command is sessionless; a phase',
595
- 'may not control its own build.',
611
+ 'Landing consent survives restacks and verification; hold persists until land.',
612
+ 'These sessionless controls never bypass merge gates.',
596
613
  ]),
597
- },
614
+ })),
598
615
  {
599
616
  name: 'models',
600
617
  audience: 'human',
@@ -0,0 +1,27 @@
1
+ import type { BuildStore } from '../store/types'
2
+ import { buildStreamSeedReducer, type BuildStreamSeed } from '../kernel/read-facts'
3
+
4
+ /** Only explicit old --since cursors need historical reconstruction. Ordinary
5
+ * registration and the first event batch must use the persisted seed. */
6
+ export async function historicalBuildState(
7
+ store: BuildStore,
8
+ slug: string,
9
+ requested: number,
10
+ current: { cursor: number; value: BuildStreamSeed },
11
+ ) {
12
+ if (requested >= current.cursor) return current.value
13
+ const events = await store.getEvents(slug)
14
+ return buildStreamSeedReducer.reduce(events.filter((event) => event.seq <= requested))
15
+ }
16
+
17
+ import { repositoryAttentionReducer } from '../kernel/repository-attention'
18
+ export async function historicalRepositoryAttention(
19
+ store: BuildStore,
20
+ repo: string,
21
+ requested: number,
22
+ current: { cursor: number; value: ReturnType<typeof repositoryAttentionReducer.finish> },
23
+ ) {
24
+ if (requested >= current.cursor) return current.value
25
+ const events = await store.getRepoEvents(repo)
26
+ return repositoryAttentionReducer.reduce(events.filter((event) => event.seq <= requested))
27
+ }
@@ -1,3 +1,10 @@
1
+ import { createForge } from '../ports/forge/create'
2
+ import {
3
+ inspectForgeReadiness,
4
+ readinessChecks,
5
+ formatReadinessFailure,
6
+ type ForgeReadinessCheck,
7
+ } from '../ports/forge/readiness'
1
8
  import { projectToken } from './project-credentials'
2
9
  import { resolveRepoOrigin } from './repo-state'
3
10
  import { mkdtemp, readFile, rm } from 'node:fs/promises'
@@ -384,6 +391,7 @@ export async function validateInitReadiness(opts: {
384
391
  runtimes?: RuntimeRegistry
385
392
  vercelFacade?: VercelSandboxFacade
386
393
  packageArchive?: () => Promise<Uint8Array>
394
+ createForge?: typeof createForge
387
395
  signal?: AbortSignal
388
396
  }): Promise<InitValidationReport> {
389
397
  const exec = opts.exec ?? spawnExec
@@ -430,10 +438,25 @@ export async function validateInitReadiness(opts: {
430
438
  )
431
439
  let caps: WorkspaceProviderCapabilities | undefined
432
440
  let assigneeLine: string | undefined
441
+ let forgeChecks: ForgeReadinessCheck[] = readinessChecks(
442
+ 'unknown',
443
+ 'Host forge construction unavailable; check adapter configuration and access.',
444
+ )
433
445
  try {
434
446
  // Ticket acquisition is a host responsibility for both workspace providers.
435
447
  // Exercise its read surface before allocating disposable infrastructure.
436
448
  const hostPlugins = await loadPlugins(config.plugins, repo, { packageRoot: repo })
449
+ try {
450
+ const forge = await (opts.createForge ?? createForge)({
451
+ name: config.forge,
452
+ registry: hostPlugins,
453
+ env: opts.env,
454
+ repoRoot: repo,
455
+ })
456
+ forgeChecks = await inspectForgeReadiness(forge, { rootBranch: config.baseBranch })
457
+ } catch {
458
+ /* Keep useful workspace readiness even if the forge is unavailable. */
459
+ }
437
460
  caps =
438
461
  hostPlugins.workspaceProviders.get(config.workspace.provider)?.capabilities ?? builtinCaps
439
462
  // Registry-aware declaration checks. The pre-registry preflight above could
@@ -624,6 +647,20 @@ export async function validateInitReadiness(opts: {
624
647
  }
625
648
 
626
649
  if (report === undefined) throw new Error('readiness validation produced no report')
650
+ report.checks.push(
651
+ ...forgeChecks.map(
652
+ (check): ReadinessCheck => ({
653
+ name: `forge-${check.check}`,
654
+ status:
655
+ check.status === 'fail' && check.requirement === 'recommendation'
656
+ ? 'warning'
657
+ : check.status,
658
+ detail: formatReadinessFailure(check),
659
+ }),
660
+ ),
661
+ )
662
+ if (forgeChecks.some((check) => check.requirement === 'hard' && check.status === 'fail'))
663
+ report.exitCode = 1
627
664
  const stdout = opts.stdout ?? (() => {})
628
665
  stdout(`Readiness: ${report.context} (${report.provider})`)
629
666
  stdout(`Store: ${state.storeRef}`)
@@ -642,11 +679,15 @@ export async function validateInitReadiness(opts: {
642
679
  `Disposable environment: ${report.workspace} (released${report.snapshotsDeleted === undefined ? '' : `; ${report.snapshotsDeleted} snapshot(s) deleted`})`,
643
680
  )
644
681
  for (const check of report.checks) {
645
- const label = check.status === 'pass' ? 'PASS' : check.status === 'absent' ? 'ABSENT' : 'FAIL'
682
+ const label = check.status === 'warning' ? 'WARN' : check.status.toUpperCase()
646
683
  stdout(` ${label} ${check.name}: ${redact(check.detail)}`)
647
684
  }
648
685
  return {
649
686
  ...report,
650
- checks: report.checks.map((check) => ({ ...check, detail: redact(check.detail) })),
687
+ checks: report.checks.map((check) => ({
688
+ ...check,
689
+ name: redact(check.name),
690
+ detail: redact(check.detail),
691
+ })),
651
692
  }
652
693
  }
@@ -89,6 +89,8 @@ export type CsiReport =
89
89
  | { kind: 'input'; event: TerminalInputEvent }
90
90
  | { kind: 'keyboard-flags'; flags: number }
91
91
  | { kind: 'device-attributes' }
92
+ | { kind: 'focus'; focused: boolean }
93
+ | { kind: 'suspend' }
92
94
  | { kind: 'ignored' }
93
95
 
94
96
  const ignored = (): CsiReport => ({ kind: 'ignored' })
@@ -105,6 +107,9 @@ export function decodeCsi(sequence: string): CsiReport {
105
107
  }
106
108
  if (final === 'c' && body.startsWith('?')) return { kind: 'device-attributes' }
107
109
 
110
+ if (body === '' && (final === 'I' || final === 'O'))
111
+ return { kind: 'focus', focused: final === 'I' }
112
+
108
113
  const params = body.split(';')
109
114
  if (final === 'u') {
110
115
  const [primaryRaw, shiftedRaw, baseRaw] = (params[0] ?? '').split(':')
@@ -127,6 +132,7 @@ export function decodeCsi(sequence: string): CsiReport {
127
132
  // The Dvorak physical-QWERTY-C collision contains both 106 and 99. The
128
133
  // produced `j` wins: a newline is recoverable while an interrupt is not.
129
134
  if (chordKeys.includes(106)) return input({ type: 'newline' })
135
+ if (chordKeys.includes(122)) return { kind: 'suspend' }
130
136
  if (chordKeys.includes(99)) return input({ type: 'interrupt' })
131
137
  }
132
138
 
@@ -0,0 +1,18 @@
1
+ import { treeVocabulary } from './dashboard/tree'
2
+ import { listOperatorLandings } from '../operator/landings'
3
+ import type { StatusOpts } from './status'
4
+ import { withAmbientReadStore } from './store-opening'
5
+
6
+ export async function abLandings(opts: StatusOpts): Promise<void> {
7
+ await withAmbientReadStore(opts, async ({ store, repo }) => {
8
+ const entries = await listOperatorLandings({ store, repo })
9
+ if (opts.json) opts.stdout(JSON.stringify(entries, null, 2))
10
+ else if (!entries.length)
11
+ opts.stdout(`No ${treeVocabulary.landing}s awaiting ${treeVocabulary.consent}.`)
12
+ else
13
+ for (const entry of entries)
14
+ opts.stdout(
15
+ `${entry.slug} → ${entry.target.ticket?.id ?? entry.target.branch ?? treeVocabulary.root} · ${entry.branch ?? 'unknown branch'} · ${entry.reason} · ${treeVocabulary.verify} ${entry.verification.results.map((r) => `${r.step}:${r.outcome}`).join(', ') || 'no steps'}${entry.kind === 'node' ? ` · ${treeVocabulary.children} ${entry.children?.length ?? 'unknown'} (${entry.completeness})` : ''}`,
16
+ )
17
+ })
18
+ }