@defrex/autobuild 0.14.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 (172) hide show
  1. package/README.md +4 -2
  2. package/SPEC.md +654 -98
  3. package/docs/architecture.md +226 -5
  4. package/docs/assets/headline-wide.png +0 -0
  5. package/docs/configuration.md +112 -12
  6. package/docs/hosted-service.md +18 -0
  7. package/docs/integration-tree.md +117 -0
  8. package/docs/landing-policy.md +150 -0
  9. package/docs/mcp.md +24 -0
  10. package/docs/migration-1.0.md +68 -0
  11. package/docs/operator-api.md +19 -8
  12. package/docs/remote-store-protocol.md +30 -7
  13. package/docs/remote-ticket-protocol.md +26 -5
  14. package/docs/restacking.md +79 -0
  15. package/docs/setup.md +49 -6
  16. package/docs/ticket-dependencies.md +69 -0
  17. package/docs/ticket-migration.md +8 -0
  18. package/package.json +3 -3
  19. package/packages/core/src/cli/attention.ts +25 -2
  20. package/packages/core/src/cli/build-control.ts +65 -41
  21. package/packages/core/src/cli/context.ts +54 -2
  22. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  23. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  24. package/packages/core/src/cli/dashboard/live.ts +5 -0
  25. package/packages/core/src/cli/dashboard/model.ts +142 -18
  26. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  27. package/packages/core/src/cli/dashboard/refresh.ts +176 -0
  28. package/packages/core/src/cli/dashboard/render.ts +78 -28
  29. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  30. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  31. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  32. package/packages/core/src/cli/dispatch-frontend.ts +156 -109
  33. package/packages/core/src/cli/dispatch.ts +250 -136
  34. package/packages/core/src/cli/dispatcher-liveness.ts +15 -2
  35. package/packages/core/src/cli/help.ts +49 -32
  36. package/packages/core/src/cli/init-validation.ts +43 -2
  37. package/packages/core/src/cli/keyboard.ts +6 -0
  38. package/packages/core/src/cli/landings.ts +18 -0
  39. package/packages/core/src/cli/main.ts +49 -15
  40. package/packages/core/src/cli/mcp.ts +9 -0
  41. package/packages/core/src/cli/publication-settlement.ts +168 -2
  42. package/packages/core/src/cli/repository-status.ts +11 -0
  43. package/packages/core/src/cli/status.ts +72 -5
  44. package/packages/core/src/cli/terminal-restore.ts +54 -0
  45. package/packages/core/src/cli/terminal.ts +16 -2
  46. package/packages/core/src/cli/terminals.ts +98 -79
  47. package/packages/core/src/cli/ticket-editor.ts +10 -3
  48. package/packages/core/src/cli/ticket.ts +113 -18
  49. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  50. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  51. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  52. package/packages/core/src/cli/upgrade.ts +16 -0
  53. package/packages/core/src/cli/wait.ts +115 -19
  54. package/packages/core/src/cli/watch.ts +51 -12
  55. package/packages/core/src/config/landing.ts +22 -0
  56. package/packages/core/src/config/live.ts +1 -0
  57. package/packages/core/src/config/schema.ts +3 -0
  58. package/packages/core/src/events/catalog.ts +48 -3
  59. package/packages/core/src/events/payloads.ts +295 -6
  60. package/packages/core/src/events/repository.ts +31 -0
  61. package/packages/core/src/integration/harness.ts +10 -0
  62. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +1030 -239
  63. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  64. package/packages/core/src/kernel/auto-merge.ts +12 -3
  65. package/packages/core/src/kernel/build-identity.ts +94 -0
  66. package/packages/core/src/kernel/change-presence.ts +179 -0
  67. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  68. package/packages/core/src/kernel/engine.ts +89 -2
  69. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  70. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  71. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  72. package/packages/core/src/kernel/generators/repository-journals.ts +11 -0
  73. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  74. package/packages/core/src/kernel/integration-landing.ts +263 -0
  75. package/packages/core/src/kernel/integration-stack.ts +36 -0
  76. package/packages/core/src/kernel/integration-state.ts +135 -0
  77. package/packages/core/src/kernel/landing-policy.ts +47 -0
  78. package/packages/core/src/kernel/landing-publication.ts +41 -0
  79. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  80. package/packages/core/src/kernel/landing-state.ts +96 -0
  81. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  82. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  83. package/packages/core/src/kernel/log-index.ts +35 -5
  84. package/packages/core/src/kernel/node-landing.ts +439 -0
  85. package/packages/core/src/kernel/node-parent.ts +184 -0
  86. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  87. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  88. package/packages/core/src/kernel/node-restack.ts +274 -0
  89. package/packages/core/src/kernel/read-facts.ts +70 -3
  90. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  91. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  92. package/packages/core/src/kernel/reducer-registry.ts +16 -0
  93. package/packages/core/src/kernel/reducer.ts +121 -6
  94. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  95. package/packages/core/src/ontology.ts +9 -1
  96. package/packages/core/src/operator/annotations.ts +12 -0
  97. package/packages/core/src/operator/control.ts +6 -0
  98. package/packages/core/src/operator/index.ts +4 -0
  99. package/packages/core/src/operator/landings.ts +35 -0
  100. package/packages/core/src/operator/presentation.ts +1 -0
  101. package/packages/core/src/operator/protocol.ts +12 -3
  102. package/packages/core/src/operator/query.ts +3 -1
  103. package/packages/core/src/operator/registry.ts +48 -19
  104. package/packages/core/src/operator/requests.ts +1 -8
  105. package/packages/core/src/operator/tickets.ts +55 -9
  106. package/packages/core/src/ports/forge/contract.ts +91 -3
  107. package/packages/core/src/ports/forge/fake.ts +142 -4
  108. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  109. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  110. package/packages/core/src/ports/forge/github.ts +631 -35
  111. package/packages/core/src/ports/forge/local-git.ts +119 -5
  112. package/packages/core/src/ports/forge/readiness.ts +99 -0
  113. package/packages/core/src/ports/tickets/contract.ts +41 -0
  114. package/packages/core/src/ports/tickets/create.ts +8 -1
  115. package/packages/core/src/ports/tickets/fake.ts +32 -1
  116. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  117. package/packages/core/src/ports/tickets/file.ts +18 -1
  118. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  119. package/packages/core/src/ports/tickets/linear.ts +124 -4
  120. package/packages/core/src/ports/tickets/migration.ts +25 -1
  121. package/packages/core/src/ports/tickets/operations.ts +7 -2
  122. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  123. package/packages/core/src/ports/tickets/remote.ts +10 -1
  124. package/packages/core/src/ports/tickets/revision.ts +3 -1
  125. package/packages/core/src/ports/tickets/tree.ts +148 -0
  126. package/packages/core/src/ports/tickets/update.ts +15 -2
  127. package/packages/core/src/ports/types.ts +135 -5
  128. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  129. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  130. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  131. package/packages/core/src/processes/build-runner.ts +530 -23
  132. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  133. package/packages/core/src/processes/dispatcher.ts +2145 -203
  134. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  135. package/packages/core/src/processes/publication-state.ts +30 -5
  136. package/packages/core/src/processes/repo-view.ts +21 -2
  137. package/packages/core/src/store/build-scope.ts +18 -0
  138. package/packages/core/src/store/contract.ts +658 -0
  139. package/packages/core/src/store/digest.ts +52 -4
  140. package/packages/core/src/store/local/schema.ts +25 -13
  141. package/packages/core/src/store/local/store.ts +117 -1
  142. package/packages/core/src/store/memory.ts +62 -1
  143. package/packages/core/src/store/phase-session.ts +17 -0
  144. package/packages/core/src/store/reduced-reads.ts +2 -1
  145. package/packages/core/src/store/reducer-value-shapes.json +10707 -6440
  146. package/packages/core/src/store/remote/client.ts +44 -0
  147. package/packages/core/src/store/remote/compatibility.ts +19 -9
  148. package/packages/core/src/store/remote/protocol.ts +11 -0
  149. package/packages/core/src/store/repo-state-events.ts +2 -0
  150. package/packages/core/src/store/session-handle.ts +15 -0
  151. package/packages/core/src/store/subscribe.ts +1 -1
  152. package/packages/core/src/store/types.ts +32 -4
  153. package/packages/core/src/testing/index.ts +2 -0
  154. package/packages/core/src/testing/reduced-read-budget.ts +48 -8
  155. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  156. package/skills/guide/SKILL.md +110 -61
  157. package/skills/guide/references/integration-tree.md +117 -0
  158. package/skills/guide/references/landing-policy.md +150 -0
  159. package/skills/guide/references/migration-1.0.md +68 -0
  160. package/skills/guide/references/operator-api.md +12 -5
  161. package/skills/guide/references/plugin-authoring.md +34 -0
  162. package/skills/guide/references/remote-store-protocol.md +30 -7
  163. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  164. package/skills/guide/references/restacking.md +79 -0
  165. package/skills/guide/references/setup.md +49 -6
  166. package/skills/guide/references/ticket-dependencies.md +69 -0
  167. package/skills/guide/references/ticket-migration.md +8 -0
  168. package/skills/operate/SKILL.md +55 -5
  169. package/skills/reconcile/SKILL.md +55 -48
  170. package/skills/spec/SKILL.md +67 -1
  171. package/skills/tickets/SKILL.md +55 -2
  172. package/templates/autobuild.toml +3 -0
@@ -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>>()
@@ -84,12 +86,23 @@ export class StandbyIdentityResolver {
84
86
  try {
85
87
  record = await this.store.getRepo(this.repo)
86
88
  } catch {
89
+ this.failed = true
87
90
  return yieldedHolder
88
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
89
103
  const holder = record?.lease?.holder
90
104
  if (holder === run) return undefined
91
- if (holder === undefined) return yieldedHolder
92
- await this.correlate(holder)
105
+ if (holder === undefined) return undefined
93
106
  if (!this.starts.has(holder)) return holder
94
107
  const projection = projectDispatcherLiveness(record, [...this.starts.values()], now)
95
108
  const identity = projection.holder ?? projection.expiredHolder
@@ -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',
@@ -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
+ }
@@ -1,3 +1,4 @@
1
+ import { abLandings } from './landings'
1
2
  import { readBuildFacts } from '../store/reduced-reads'
2
3
  import { preparePinnedAssets } from '../store/ticket-assets'
3
4
  import type { PinnedAsset } from '../events/payloads'
@@ -105,6 +106,7 @@ export const SESSIONLESS_COMMANDS = new Set([
105
106
  'ticket',
106
107
  'dispatch',
107
108
  'builds',
109
+ 'landings',
108
110
  'build',
109
111
  'watch',
110
112
  'wait',
@@ -112,6 +114,8 @@ export const SESSIONLESS_COMMANDS = new Set([
112
114
  'repository',
113
115
  'pause',
114
116
  'resume',
117
+ 'hold',
118
+ 'land',
115
119
  'auto-merge',
116
120
  'answer',
117
121
  'abort',
@@ -253,6 +257,8 @@ export function buildControlConfirmation(result: BuildControlResult): string {
253
257
  resume: 'resume requested',
254
258
  abort: 'abort requested',
255
259
  discard: 'discard requested',
260
+ hold: 'landing hold requested',
261
+ land: 'landing consent requested',
256
262
  'auto-merge-on': 'auto-merge requested',
257
263
  'auto-merge-off': 'auto-merge cancelled',
258
264
  }
@@ -318,6 +324,19 @@ async function runBuildControl(
318
324
  )
319
325
  }
320
326
  const result = await abBuildControl({
327
+ ticketSource: async () =>
328
+ (
329
+ await openTicketSource(
330
+ {
331
+ targetRepo: deps.workspacePath,
332
+ env: deps.processEnv ?? {},
333
+ exec: deps.exec!,
334
+ stdout: deps.stdout,
335
+ ...(storeRef !== undefined ? { storeRef } : {}),
336
+ },
337
+ `ab ${action.kind}`,
338
+ )
339
+ ).source,
321
340
  targetRepo: deps.workspacePath,
322
341
  env: deps.processEnv ?? {},
323
342
  exec: deps.exec,
@@ -625,6 +644,8 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
625
644
  })
626
645
  const report = await abUpgrade({
627
646
  targetRepo,
647
+ env: deps.processEnv,
648
+ openStore: deps.openStore,
628
649
  stdout,
629
650
  ...(deps.distributionRoot !== undefined ? { distRoot: deps.distributionRoot } : {}),
630
651
  ...(deps.exec !== undefined ? { exec: deps.exec } : {}),
@@ -687,8 +708,8 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
687
708
  if (sawIntake && sawNoIntake) {
688
709
  throw new Error(`--intake and --no-intake cannot be combined — ${usage}`)
689
710
  }
690
- if (sawAutoMerge && sawNoAutoMerge) {
691
- throw new Error(`--auto-merge and --no-auto-merge cannot be combined — ${usage}`)
711
+ if (sawAutoMerge || sawNoAutoMerge) {
712
+ throw new Error(`Auto-merge flags are retired; configure [[landing]] policy — ${usage}`)
692
713
  }
693
714
 
694
715
  const interval = stringFlag(parsed, 'interval')
@@ -784,6 +805,23 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
784
805
  return 0
785
806
  }
786
807
 
808
+ case 'landings': {
809
+ const usage = 'usage: ab landings [--json] [--store <ref>]'
810
+ const parsed = parseArgs(rest, { json: 'boolean', store: 'value' }, usage)
811
+ if (parsed.positionals.length) throw new Error(usage)
812
+ if (!deps.exec) throw new Error('ab landings needs an exec seam')
813
+ await abLandings({
814
+ targetRepo: deps.workspacePath,
815
+ env: deps.processEnv ?? {},
816
+ exec: deps.exec,
817
+ stdout,
818
+ json: parsed.flags.has('json'),
819
+ storeRef: stringFlag(parsed, 'store'),
820
+ openStore: deps.openStore,
821
+ })
822
+ return 0
823
+ }
824
+
787
825
  case 'builds': {
788
826
  const usage = 'usage: ab builds [--queued] [--all] [--json] [--store <ref>] (§8.2)'
789
827
  const parsed = parseArgs(
@@ -1042,25 +1080,21 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1042
1080
  return 0
1043
1081
  }
1044
1082
 
1045
- case 'auto-merge': {
1046
- const usage = 'usage: ab auto-merge <slug> <on|off> [--store <ref>]'
1083
+ case 'hold':
1084
+ case 'land': {
1085
+ const usage = `usage: ab ${command} <slug> [--store <ref>]`
1047
1086
  const parsed = parseArgs(rest, { store: 'value' }, usage)
1048
- const [slug, setting] = parsed.positionals
1049
- if (
1050
- parsed.positionals.length !== 2 ||
1051
- slug === undefined ||
1052
- (setting !== 'on' && setting !== 'off')
1053
- ) {
1054
- throw new Error(usage)
1055
- }
1087
+ if (parsed.positionals.length !== 1) throw new Error(usage)
1056
1088
  await runBuildControl(
1057
1089
  deps,
1058
- slug,
1059
- { kind: setting === 'on' ? 'auto-merge-on' : 'auto-merge-off' },
1090
+ parsed.positionals[0]!,
1091
+ { kind: command },
1060
1092
  stringFlag(parsed, 'store'),
1061
1093
  )
1062
1094
  return 0
1063
1095
  }
1096
+ case 'auto-merge':
1097
+ throw new Error('ab auto-merge is retired; use ab hold, ab land, and [[landing]] policy')
1064
1098
 
1065
1099
  case 'answer': {
1066
1100
  const usage =
@@ -1437,7 +1471,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1437
1471
  const event = await done(session, notes !== undefined ? { notes } : {})
1438
1472
  stdout(
1439
1473
  event.type === 'publication.requested'
1440
- ? `${event.type} recorded (seq ${event.seq}); remote publication is pending — do not run ab done again`
1474
+ ? `${event.type} recorded (seq ${event.seq}); publication is pending — do not run ab done again`
1441
1475
  : `${event.type} recorded (seq ${event.seq})`,
1442
1476
  )
1443
1477
  return 0
@@ -112,6 +112,15 @@ export async function buildMcpTicketBackend(
112
112
  ),
113
113
  ]
114
114
  return {
115
+ supportsNodeRetarget: async () => {
116
+ const forge = await createForge({
117
+ name: config.forge,
118
+ registry: plugins,
119
+ env: opts.env,
120
+ repoRoot: opts.checkout,
121
+ })
122
+ return !!forge.retargetPr && !!forge.inspectLandingPr
123
+ },
115
124
  sourceFor: async (context) => {
116
125
  if ((config.tickets.teamKey ?? '') !== context.teamKey) {
117
126
  throw new Error(