@defrex/autobuild 1.0.1 → 1.1.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 (186) hide show
  1. package/README.md +6 -6
  2. package/SPEC.md +360 -229
  3. package/docs/answering-blocked-builds.md +2 -2
  4. package/docs/architecture.md +155 -45
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/builds.md +4 -4
  7. package/docs/cli.md +4 -4
  8. package/docs/configuration-overview.md +4 -4
  9. package/docs/configuration.md +245 -210
  10. package/docs/dispatcher-hosting.md +2 -2
  11. package/docs/dispatcher.md +1 -1
  12. package/docs/forges.md +5 -5
  13. package/docs/getting-started.md +2 -2
  14. package/docs/glossary.md +6 -6
  15. package/docs/hosted-dispatcher.md +6 -3
  16. package/docs/hosted-service.md +16 -5
  17. package/docs/integration-overview.md +15 -15
  18. package/docs/integration-tree.md +45 -38
  19. package/docs/integration.md +6 -6
  20. package/docs/mcp.md +16 -15
  21. package/docs/{landing-policy.md → merge-policy.md} +42 -24
  22. package/docs/migration-1.0.md +17 -13
  23. package/docs/operating.md +41 -18
  24. package/docs/operator-api.md +91 -15
  25. package/docs/operator-surfaces.md +8 -4
  26. package/docs/overview.md +3 -3
  27. package/docs/remote-store-protocol.md +76 -11
  28. package/docs/remote-ticket-protocol.md +1 -1
  29. package/docs/restacking.md +54 -15
  30. package/docs/setup.md +41 -6
  31. package/docs/skills.md +1 -1
  32. package/docs/spec-standard.md +6 -6
  33. package/docs/ticket-dependencies.md +7 -7
  34. package/docs/tickets.md +8 -2
  35. package/docs/troubleshooting.md +2 -2
  36. package/docs/upgrading.md +8 -3
  37. package/docs/verification.md +60 -14
  38. package/package.json +7 -5
  39. package/packages/core/src/cli/binary-direct.ts +13 -1
  40. package/packages/core/src/cli/binary-lifecycle.ts +65 -2
  41. package/packages/core/src/cli/build-control.ts +83 -28
  42. package/packages/core/src/cli/context.ts +81 -38
  43. package/packages/core/src/cli/dashboard/facts.ts +2 -1
  44. package/packages/core/src/cli/dashboard/integration-detail.ts +8 -8
  45. package/packages/core/src/cli/dashboard/integration-row.ts +40 -13
  46. package/packages/core/src/cli/dashboard/landing-display.ts +25 -0
  47. package/packages/core/src/cli/dashboard/model.ts +56 -33
  48. package/packages/core/src/cli/dashboard/poll.ts +9 -3
  49. package/packages/core/src/cli/dashboard/render.ts +59 -37
  50. package/packages/core/src/cli/dashboard/target-distance.ts +14 -0
  51. package/packages/core/src/cli/dashboard/tree.ts +3 -2
  52. package/packages/core/src/cli/dispatch-args.ts +1 -1
  53. package/packages/core/src/cli/dispatch-frontend.ts +6 -3
  54. package/packages/core/src/cli/dispatch.ts +35 -9
  55. package/packages/core/src/cli/env.ts +4 -0
  56. package/packages/core/src/cli/help.ts +30 -23
  57. package/packages/core/src/cli/main.ts +24 -8
  58. package/packages/core/src/cli/node-verification-provenance.ts +1 -97
  59. package/packages/core/src/cli/publication-settlement.ts +43 -20
  60. package/packages/core/src/cli/repository-status.ts +20 -9
  61. package/packages/core/src/cli/status.ts +42 -5
  62. package/packages/core/src/cli/store-opening.ts +6 -1
  63. package/packages/core/src/cli/terminal.ts +22 -1
  64. package/packages/core/src/cli/terminals.ts +14 -10
  65. package/packages/core/src/cli/upgrade-landing.ts +70 -30
  66. package/packages/core/src/cli/upgrade.ts +3 -1
  67. package/packages/core/src/cli/wait.ts +15 -7
  68. package/packages/core/src/cli/watch-lifetime.ts +111 -0
  69. package/packages/core/src/cli/watch.ts +634 -511
  70. package/packages/core/src/config/effective-artifact.fixture.ts +27 -0
  71. package/packages/core/src/config/effective-artifact.ts +13 -0
  72. package/packages/core/src/config/landing.ts +1 -1
  73. package/packages/core/src/config/load.ts +21 -1
  74. package/packages/core/src/config/pipeline-source.ts +28 -0
  75. package/packages/core/src/config/reference-metadata.ts +2 -0
  76. package/packages/core/src/config/reference.ts +22 -7
  77. package/packages/core/src/config/schema.ts +86 -162
  78. package/packages/core/src/context-directory.ts +26 -0
  79. package/packages/core/src/distribution-packaging.ts +26 -5
  80. package/packages/core/src/events/catalog.ts +10 -2
  81. package/packages/core/src/events/globs.ts +1 -1
  82. package/packages/core/src/events/payloads.ts +70 -1
  83. package/packages/core/src/events/policy.ts +7 -0
  84. package/packages/core/src/events/repository.ts +2 -4
  85. package/packages/core/src/events/sessions.ts +6 -6
  86. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +571 -0
  87. package/packages/core/src/kernel/auto-merge.ts +2 -2
  88. package/packages/core/src/kernel/engine.ts +255 -26
  89. package/packages/core/src/kernel/generators/leaf-restack-log.ts +10 -0
  90. package/packages/core/src/kernel/integration-landing.ts +3 -3
  91. package/packages/core/src/kernel/integration-state.ts +27 -4
  92. package/packages/core/src/kernel/leaf-restack-state.ts +28 -3
  93. package/packages/core/src/kernel/log-index.ts +13 -1
  94. package/packages/core/src/kernel/node-landing.ts +8 -8
  95. package/packages/core/src/kernel/node-parent.ts +2 -2
  96. package/packages/core/src/kernel/node-restack-transaction.ts +1 -1
  97. package/packages/core/src/kernel/node-verification-context.ts +216 -0
  98. package/packages/core/src/kernel/phases.ts +1 -1
  99. package/packages/core/src/kernel/plan-verify-selection.ts +16 -0
  100. package/packages/core/src/kernel/publication-retry.ts +168 -0
  101. package/packages/core/src/kernel/reconcile-restack.ts +29 -1
  102. package/packages/core/src/kernel/reducer.ts +82 -5
  103. package/packages/core/src/kernel/target-distance.ts +45 -0
  104. package/packages/core/src/kernel/terminal-guard.ts +10 -1
  105. package/packages/core/src/kernel/verify-stage-state.ts +123 -0
  106. package/packages/core/src/kernel/verify-stages.ts +39 -0
  107. package/packages/core/src/ontology.ts +1 -0
  108. package/packages/core/src/operator/annotations.ts +6 -0
  109. package/packages/core/src/operator/control.ts +1 -1
  110. package/packages/core/src/operator/index.ts +1 -7
  111. package/packages/core/src/operator/landings.ts +5 -1
  112. package/packages/core/src/operator/presentation.ts +6 -1
  113. package/packages/core/src/operator/query.ts +14 -18
  114. package/packages/core/src/operator/registry.ts +17 -6
  115. package/packages/core/src/operator/sandbox-host.ts +64 -40
  116. package/packages/core/src/operator/sandbox.ts +3 -0
  117. package/packages/core/src/operator/ticket-source-backend.ts +3 -12
  118. package/packages/core/src/ports/forge/contract.ts +2 -2
  119. package/packages/core/src/ports/forge/git-rewrite.ts +25 -2
  120. package/packages/core/src/ports/forge/github-readiness.ts +2 -2
  121. package/packages/core/src/ports/forge/github.ts +26 -7
  122. package/packages/core/src/ports/forge/local-git.ts +4 -4
  123. package/packages/core/src/ports/forge/readiness.ts +1 -1
  124. package/packages/core/src/ports/forge-failure.ts +24 -0
  125. package/packages/core/src/ports/workspace/build-execution.ts +3 -1
  126. package/packages/core/src/ports/workspace/phase-scratch.ts +4 -3
  127. package/packages/core/src/ports/workspace/vercel-sandbox.ts +59 -39
  128. package/packages/core/src/processes/build-child.ts +6 -8
  129. package/packages/core/src/processes/build-execution-state.ts +8 -5
  130. package/packages/core/src/processes/build-runner.ts +522 -98
  131. package/packages/core/src/processes/dispatcher.ts +186 -101
  132. package/packages/core/src/processes/execution-no-progress.ts +8 -1
  133. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  134. package/packages/core/src/processes/publication-loss.ts +8 -2
  135. package/packages/core/src/processes/publication-state.ts +42 -4
  136. package/packages/core/src/processes/repo-view.ts +14 -0
  137. package/packages/core/src/processes/verify-cycle-config.ts +96 -0
  138. package/packages/core/src/{integration → scenarios}/harness.ts +330 -317
  139. package/packages/core/src/store/adapter.ts +1 -0
  140. package/packages/core/src/store/build-scope.ts +9 -0
  141. package/packages/core/src/store/contract.ts +113 -1
  142. package/packages/core/src/store/local/schema.ts +13 -0
  143. package/packages/core/src/store/local/store.ts +42 -0
  144. package/packages/core/src/store/memory.ts +47 -0
  145. package/packages/core/src/store/operator-presence.ts +21 -0
  146. package/packages/core/src/store/phase-session.ts +10 -0
  147. package/packages/core/src/store/reducer-value-shapes.json +5081 -4160
  148. package/packages/core/src/store/remote/client.ts +47 -1
  149. package/packages/core/src/store/remote/compatibility.ts +2 -0
  150. package/packages/core/src/store/remote/protocol.ts +4 -0
  151. package/packages/core/src/store/remote/version.ts +3 -1
  152. package/packages/core/src/store/retention.ts +2 -3
  153. package/packages/core/src/store/session-handle.ts +9 -0
  154. package/packages/core/src/store/streams/session-writer.ts +1 -1
  155. package/packages/core/src/store/types.ts +12 -2
  156. package/packages/core/src/testing/index.ts +11 -1
  157. package/packages/core/src/testing/temp-directories.ts +58 -0
  158. package/skills/code-review/SKILL.md +23 -9
  159. package/skills/finalize/SKILL.md +15 -7
  160. package/skills/guide/SKILL.md +253 -118
  161. package/skills/guide/references/integration-tree.md +45 -38
  162. package/skills/guide/references/{landing-policy.md → merge-policy.md} +42 -24
  163. package/skills/guide/references/migration-1.0.md +17 -13
  164. package/skills/guide/references/operator-api.md +91 -15
  165. package/skills/guide/references/remote-store-protocol.md +76 -11
  166. package/skills/guide/references/remote-ticket-protocol.md +1 -1
  167. package/skills/guide/references/restacking.md +54 -15
  168. package/skills/guide/references/setup.md +41 -6
  169. package/skills/guide/references/spec-standard.md +6 -6
  170. package/skills/guide/references/ticket-dependencies.md +7 -7
  171. package/skills/implement/SKILL.md +43 -17
  172. package/skills/operate/SKILL.md +117 -116
  173. package/skills/plan/SKILL.md +39 -13
  174. package/skills/plan-review/SKILL.md +15 -10
  175. package/skills/reconcile/SKILL.md +22 -3
  176. package/skills/spec/SKILL.md +19 -19
  177. package/skills/tickets/SKILL.md +9 -7
  178. package/templates/autobuild.toml +1 -1
  179. package/templates/hosted-service/package.json +2 -2
  180. package/packages/core/src/orchestrator/approvals.ts +0 -115
  181. package/packages/core/src/orchestrator/conversation.ts +0 -167
  182. package/packages/core/src/orchestrator/model.ts +0 -86
  183. package/packages/core/src/orchestrator/prompt.ts +0 -63
  184. package/packages/core/src/orchestrator/tools.ts +0 -117
  185. package/packages/core/src/orchestrator/turn-runner.ts +0 -457
  186. package/packages/core/src/processes/orchestrator-tick.ts +0 -360
@@ -6,6 +6,7 @@ import {
6
6
  integrationCurrent,
7
7
  integrationCycleVerified,
8
8
  } from '../../kernel/integration-state'
9
+ import { mergeVocabulary } from './landing-display'
9
10
  import { awaitsConsent, landingReady } from '../../kernel/landing-readiness'
10
11
 
11
12
  export const treeVocabulary = {
@@ -13,7 +14,7 @@ export const treeVocabulary = {
13
14
  node: 'node',
14
15
  target: 'target',
15
16
  integration: 'integration build',
16
- landing: 'landing',
17
+ landing: mergeVocabulary.label,
17
18
  restack: 'restack',
18
19
  consent: 'consent',
19
20
  queue: 'queue',
@@ -25,7 +26,7 @@ export const treeVocabulary = {
25
26
  verification: 'verification',
26
27
  current: 'current',
27
28
  pending: 'pending',
28
- readyToLand: 'ready to land',
29
+ readyToLand: 'ready to merge',
29
30
  notReady: 'not ready',
30
31
  } as const
31
32
 
@@ -32,7 +32,7 @@ export function parseDispatchArgs(
32
32
  throw new Error(`--intake and --no-intake cannot be combined — ${usage}`)
33
33
  }
34
34
  if (sawAutoMerge || sawNoAutoMerge) {
35
- throw new Error(`Auto-merge flags are retired; configure [[landing]] policy — ${usage}`)
35
+ throw new Error(`Auto-merge flags are retired; configure [[merge]] policy — ${usage}`)
36
36
  }
37
37
 
38
38
  const interval = stringFlag(parsed, 'interval')
@@ -1,3 +1,4 @@
1
+ import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
1
2
  import { migrationIdentity, ticketMigrationsReducer } from '../kernel/ticket-migrations'
2
3
  import type { DispatchUpgradeState } from '../kernel/dispatch-upgrade'
3
4
  import { releaseDispatchPresentation } from './dispatch-presentation-ownership'
@@ -297,7 +298,9 @@ export class DispatchFrontend {
297
298
  if (this.config !== undefined && this.configRef === key) return this.config
298
299
  const artifact = await this.reader.getRepoArtifact(this.opts.repo, kind, rev)
299
300
  if (artifact === null) throw new Error(`effective config ${key} is not retrievable`)
300
- const parsed = configSchema.parse(JSON.parse(new TextDecoder().decode(artifact.content)))
301
+ const parsed = configSchema.parse(
302
+ normalizeEffectiveConfigArtifact(JSON.parse(new TextDecoder().decode(artifact.content))),
303
+ )
301
304
  this.config = parsed
302
305
  this.configRef = key
303
306
  this.configRevision += 1
@@ -749,8 +752,8 @@ export class DispatchFrontend {
749
752
  : result.command === 'abort'
750
753
  ? `build ${slug}: abort requested`
751
754
  : result.command === 'land'
752
- ? `build ${slug}: landing consent requested`
753
- : `build ${slug}: landing hold requested`
755
+ ? `build ${slug}: merge consent requested`
756
+ : `build ${slug}: merge hold requested`
754
757
  await this.report(message)
755
758
  await this.renderOnce()
756
759
  }
@@ -1,3 +1,5 @@
1
+ import { capturedBuildConfig } from '../processes/verify-cycle-config'
2
+ import { ForgeRequestDeferred } from '../ports/forge-request-context'
1
3
  import { migrationIdentity } from '../kernel/ticket-migrations'
2
4
  import { recordRuntimeRollback } from './dispatch-handoff'
3
5
  import { syncRollbackRetention } from './dispatch-runtime-use'
@@ -924,6 +926,12 @@ class DispatchLoop {
924
926
  * naming the failed attempts; the documented fallbacks (an unpublished
925
927
  * branch, an unreadable legacy base) stay quiet. */
926
928
  private async publishBuildConfig(slug: string, snapshot = this.currentConfig()): Promise<void> {
929
+ const state = (await readBuildFacts(this.wiring.store, slug)).value.state
930
+ if (state.verify.configPin) {
931
+ const config = await capturedBuildConfig(this.wiring.store, slug, state, snapshot.config)
932
+ await this.depositBuildConfig(slug, snapshot, config, state.verify.configPin.source)
933
+ return
934
+ }
927
935
  const { source, failures, observations } = await this.resolveBuildPipeline(slug)
928
936
  if (source !== undefined) {
929
937
  await this.depositBuildConfig(
@@ -1026,8 +1034,8 @@ class DispatchLoop {
1026
1034
  /** Re-deposit deployment-owned sections to active builds on a reload. The
1027
1035
  * build-owned sections are reused verbatim from the build's last deposit, so
1028
1036
  * a base-branch reload can never retarget an in-flight build's pipeline; a
1029
- * build picks up pipeline changes only from its own branch at its next
1030
- * launch (SPEC §16.1). */
1037
+ * runner refreshes the execution checkout at settled verification boundaries.
1038
+ * A cycle capture's exact revision outranks latest-artifact races (SPEC §16.1). */
1031
1039
  private async publishActiveBuildConfigs(snapshot: ConfigSnapshot): Promise<void> {
1032
1040
  await Promise.all(
1033
1041
  [...this.activeBuildRuns.keys()].map(async (slug) => {
@@ -1046,11 +1054,17 @@ class DispatchLoop {
1046
1054
  return
1047
1055
  }
1048
1056
  const meta = parseBuildConfigMetadata(artifact)
1057
+ const state = (await readBuildFacts(this.wiring.store, slug)).value.state
1049
1058
  await this.depositBuildConfig(
1050
1059
  slug,
1051
1060
  snapshot,
1052
- composeBuildConfig(existing, snapshot.config),
1053
- meta.pipelineSource,
1061
+ await capturedBuildConfig(
1062
+ this.wiring.store,
1063
+ slug,
1064
+ state,
1065
+ composeBuildConfig(existing, snapshot.config),
1066
+ ),
1067
+ state.verify.configPin?.source ?? meta.pipelineSource,
1054
1068
  )
1055
1069
  }),
1056
1070
  )
@@ -1764,9 +1778,7 @@ class DispatchLoop {
1764
1778
  throw new Error('build-control returned an invalid auto-merge toggle result')
1765
1779
  }
1766
1780
  this.say(
1767
- `build ${slug}: landing ${
1768
- result.command === 'hold' ? 'hold requested' : 'consent requested'
1769
- }`,
1781
+ `build ${slug}: merge ${result.command === 'hold' ? 'hold requested' : 'consent requested'}`,
1770
1782
  )
1771
1783
  await this.renderOnce()
1772
1784
  }
@@ -3087,6 +3099,15 @@ class DispatchLoop {
3087
3099
  })
3088
3100
  }
3089
3101
 
3102
+ /** A parked publication is durable work for a later tick, not a failed guest. */
3103
+ private async settleEndedPublication(slug: string): Promise<void> {
3104
+ try {
3105
+ await this.settlePendingPublication(slug)
3106
+ } catch (error) {
3107
+ if (!(error instanceof ForgeRequestDeferred)) throw error
3108
+ }
3109
+ }
3110
+
3090
3111
  private async recordInfrastructureFailure(input: {
3091
3112
  slug: string
3092
3113
  instance: string
@@ -3263,7 +3284,7 @@ class DispatchLoop {
3263
3284
  this.warn(`build ${slug} runner failed: ${detail}`)
3264
3285
  } finally {
3265
3286
  await this.repoView.releaseLease(slug, instance)
3266
- if (!this.retirement) await this.settlePendingPublication(slug)
3287
+ if (!this.retirement) await this.settleEndedPublication(slug)
3267
3288
  }
3268
3289
  },
3269
3290
  async (error) => {
@@ -3300,6 +3321,11 @@ class DispatchLoop {
3300
3321
  if (this.activeBuildRuns.get(slug)?.reservation === reservation) {
3301
3322
  this.activeBuildRuns.delete(slug)
3302
3323
  }
3324
+ if (error instanceof ForgeRequestDeferred) {
3325
+ if (leaseClaimed) await this.repoView.releaseLease(slug, instance)
3326
+ await this.repoView.refreshBuild(slug)
3327
+ return 'already-active'
3328
+ }
3303
3329
  if (leaseClaimed) {
3304
3330
  // The runner appended through its own handle: take the delta.
3305
3331
  await this.repoView.refreshBuild(slug)
@@ -4843,7 +4869,7 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
4843
4869
  storeRef: opened.storeRef,
4844
4870
  stdout: resolvedOpts.stdout,
4845
4871
  },
4846
- 'ab land',
4872
+ 'ab merge',
4847
4873
  )
4848
4874
  ).source,
4849
4875
  env: resolvedOpts.env,
@@ -1,3 +1,4 @@
1
+ import { resolveContextDirectory } from '../context-directory'
1
2
  /**
2
3
  * Ambient auth resolution (SPEC §8.1, D8): the runner launches every session
3
4
  * with `AB_STORE`, `AB_BUILD`, `AB_PHASE`, `AB_SESSION` (and `AB_TOKEN` for a
@@ -21,6 +22,8 @@ export interface HarvestCliEnv {
21
22
  }
22
23
 
23
24
  export interface CliEnv {
25
+ /** Workspace-relative session scratch directory (`AB_CONTEXT_DIR`); phase-derived when omitted. */
26
+ contextDir?: string
24
27
  /** Store URL or local path (`AB_STORE`). */
25
28
  store: string
26
29
  /** Build slug (`AB_BUILD`). */
@@ -162,6 +165,7 @@ export function resolveCliEnv(env: Record<string, string | undefined>): CliEnv {
162
165
  return {
163
166
  store,
164
167
  build,
168
+ contextDir: resolveContextDirectory(phase, env.AB_CONTEXT_DIR),
165
169
  phase,
166
170
  round,
167
171
  session,
@@ -148,8 +148,8 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
148
148
  ' Up/Down Select the global, Harvest, or a build row.',
149
149
  ' h Toggle harvesting when the global row is selected.',
150
150
  ' i Toggle intake when the global row is selected.',
151
- ' l Land the selected ready build.',
152
- ' o Hold the selected landing.',
151
+ ' l Merge the selected ready build.',
152
+ ' o Hold the selected merge.',
153
153
  ' p On the global row, pause every pausable build and turn intake',
154
154
  ' off. On a build, pause or cancel a pending pause; on Harvest,',
155
155
  ' resume or acknowledge the run.',
@@ -199,7 +199,7 @@ names a same-source node; --no-target clears it to the baseBranch root.
199
199
  Targets cannot form cycles, and nodes with targeting tickets cannot become work.
200
200
  tree shows all tickets nested by target, including completed work and empty nodes;
201
201
  --json returns {root, children} with recursive {ticket, children} entries.
202
- These fields describe intent; dispatch and landing behavior are unchanged.`,
202
+ These fields describe intent; dispatch and merge behavior are unchanged.`,
203
203
  '--state overrides [tickets].createState (or the provider default) for that',
204
204
  'create only; it is passed through unchanged and validated by the source.',
205
205
  'update partially replaces editable fields: omitted fields survive, --labels',
@@ -250,8 +250,8 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
250
250
  '',
251
251
  'Report the durable ticket-intake setting and repository-wide pause from',
252
252
  'the same journal projection used by dispatch and the dashboard.',
253
- 'The defaults are intake on and repository pause off. Landing policy is',
254
- 'configured with [[landing]] rules in autobuild.toml.',
253
+ 'The defaults are intake on and repository pause off. Merge policy is',
254
+ 'configured with [[merge]] rules in autobuild.toml.',
255
255
  '',
256
256
  '--json emits one bare object for scripts. --store overrides AB_STORE, which',
257
257
  'overrides the repository-local .autobuild store. This sessionless command',
@@ -259,13 +259,13 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
259
259
  ]),
260
260
  },
261
261
  {
262
- name: 'landings',
262
+ name: 'merges',
263
263
  audience: 'human',
264
- summary: 'List ready landings awaiting consent.',
264
+ summary: 'List ready merges awaiting consent.',
265
265
  detail: page([
266
- 'Usage: ab landings [--json] [--store <ref>]',
267
- 'Shows ready consent and held landings with effective target, branch, verification and node children.',
268
- 'Use ab land <slug> to consent or ab hold <slug> to withdraw consent. Land rechecks readiness.',
266
+ 'Usage: ab merges [--json] [--store <ref>]',
267
+ 'Shows ready consent and held merges with effective target, branch, verification and node children.',
268
+ 'Use ab merge <slug> to consent or ab hold <slug> to withdraw consent. Merge rechecks readiness.',
269
269
  'Source ancestry is available separately through ab ticket tree or MCP tickets.tree.',
270
270
  ]),
271
271
  },
@@ -317,7 +317,7 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
317
317
  summary: 'Stream build and repository events as they land, with a resumable cursor.',
318
318
  detail: page([
319
319
  'Usage:',
320
- ' ab watch [<slug>...] [--repository] [--event <glob>]... [--since <cursor>] [--timeout <duration>] [--interval <duration>] [--count <n>] [--json] [--store <ref>]',
320
+ ' ab watch [<slug>...] [--repository] [--operator] [--event <glob>]... [--since <cursor>] [--timeout <duration>] [--interval <duration>] [--count <n>] [--json] [--store <ref>]',
321
321
  '',
322
322
  'Follow the event logs of one, several, or all active builds in this repository —',
323
323
  'the repository journal by default with no slugs — and emit one record per matching event as it',
@@ -353,7 +353,7 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
353
353
  'integration.verification-failed (failed node verification), build.janitor-failing, build.compatibility-deferred,',
354
354
  'node.item-conflicted, conflicted restack.replayed, derived build.consent-ready and',
355
355
  'build.merge-decision (a current actionable merge-gate deferral or unsafe forge outcome).',
356
- 'Consent and held ready landings use only build.consent-ready, once per readiness episode.',
356
+ 'Consent and held ready merges use only build.consent-ready, once per readiness episode.',
357
357
  'Unready or stale consent candidates stay silent; one merge gate decision per build/PR.',
358
358
  'Repository: harvest.escalated, harvest.recovery-exhausted, dispatcher.config-rejected, dispatcher.forge-readiness-failed,',
359
359
  'dispatcher.config-reloaded with restartRequired, abnormal dispatcher.run-stopped,',
@@ -390,8 +390,15 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
390
390
  'streak — and retried at the next interval without ending the watch or duplicating or',
391
391
  'skipping any event.',
392
392
  '',
393
- 'This command is read-only: it appends no event, takes no lease, and creates no build or',
394
- 'repository record, and requires no session identity for operator use. Inside a phase, a',
393
+ '--operator registers advisory presence for a repository-wide watch with no named slugs.',
394
+ 'It is rejected inside a build or scoped session. Multiple registrations may coexist;',
395
+ 'presence grants no authority or exclusive lock. Only flagged watches write liveness',
396
+ 'state, renewed every 30 seconds and live for 5 minutes after the last heartbeat.',
397
+ 'Re-arm with --operator --since using this standing watch’s own cursor to retain its',
398
+ 'registration. ab wait does not renew presence or carry registration identity.',
399
+ 'Without --operator this command is read-only. Either form appends no event, takes no',
400
+ 'lease, and creates no build or repository record. It requires no session identity.',
401
+ 'For an unflagged watch inside a phase, a',
395
402
  'complete ambient tuple permits only the ambient build: the no-slug form, a foreign slug,',
396
403
  'and --repository are rejected, as are malformed or partial identity.',
397
404
  ]),
@@ -414,9 +421,9 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
414
421
  'error before waiting begins.',
415
422
  '',
416
423
  'Conditions (--for, repeatable): blocked, paused, running, done, aborted, terminal (done',
417
- 'or aborted), pr=open, pr=merged, pr=closed, consent, node-landed, restack-conflicted, pr=conflicted, phase=<phase> (a core phase —',
424
+ 'or aborted), pr=open, pr=merged, pr=closed, consent, node-merged, restack-conflicted, pr=conflicted, phase=<phase> (a core phase —',
418
425
  'plan, plan-review, implement, code-review, finalize, reconcile — or verify:<step>), and',
419
- 'attention (an open escalation, failed node verification, consent readiness, a node landing or restack conflict,',
426
+ 'attention (an open escalation, failed node verification, consent readiness, a node merge or restack conflict,',
420
427
  'or a build waiting for a merge decision). Merge attention',
421
428
  'requires a current actionable gate deferral or an unsafe forge outcome;',
422
429
  'armed pending consent, routine outcomes and self-healing failures stay silent.',
@@ -584,7 +591,7 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
584
591
  'the next spec revision. Leaves require an open escalation and restart from plan.',
585
592
  'Idle collecting or verification-failed nodes need no escalation: they recollect',
586
593
  'and verify again, even on the same head. Active work, pause, pending controls and',
587
- 'landing intent refuse node revision. Non-conforming bodies are refused before anything is',
594
+ 'merge intent refuse node revision. Non-conforming bodies are refused before anything is',
588
595
  'recorded. Retrying an interrupted revision completes the exact body authorized by',
589
596
  'the earlier recorded answer, not a newly supplied body.',
590
597
  '',
@@ -621,15 +628,14 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
621
628
  'and nodes without an open branch are refused. This command is sessionless.',
622
629
  ]),
623
630
  },
624
- ...(['hold', 'land'] as const).map((name) => ({
631
+ ...(['hold', 'merge'] as const).map((name) => ({
625
632
  name,
626
633
  audience: 'human' as const,
627
- summary:
628
- name === 'hold' ? 'Hold a landing and withdraw consent.' : 'Consent to a ready landing.',
634
+ summary: name === 'hold' ? 'Hold a merge and withdraw consent.' : 'Consent to a ready merge.',
629
635
  detail: page([
630
636
  `Usage: ab ${name} <slug> [--store <ref>]`,
631
637
  '',
632
- 'Landing consent survives restacks and verification; hold persists until land.',
638
+ 'Merge consent survives restacks and verification; hold persists until merge.',
633
639
  'These sessionless controls never bypass merge gates.',
634
640
  ]),
635
641
  })),
@@ -673,7 +679,7 @@ These fields describe intent; dispatch and landing behavior are unchanged.`,
673
679
  'Usage:',
674
680
  ' ab context [--json]',
675
681
  '',
676
- "Hydrate .ab/ with the current phase's inputs and print the context manifest.",
682
+ "Hydrate $AB_CONTEXT_DIR/ with the current phase's inputs and print the context manifest.",
677
683
  '--json prints the manifest as JSON instead of the human summary. This command',
678
684
  'runs inside a build session and uses the runner-provided AB_* phase context.',
679
685
  ]),
@@ -836,7 +842,8 @@ export function renderTopLevelHelp(): string {
836
842
  }
837
843
 
838
844
  export function renderCommandHelp(command: string): string {
839
- const entry = ENTRY_BY_NAME.get(command === 'update' ? 'upgrade' : command)
845
+ const canonical = command === 'land' ? 'merge' : command === 'landings' ? 'merges' : command
846
+ const entry = ENTRY_BY_NAME.get(canonical === 'update' ? 'upgrade' : canonical)
840
847
  if (entry === undefined) {
841
848
  throw new Error(`unknown help command "${command}"`)
842
849
  }
@@ -112,6 +112,8 @@ export const SESSIONLESS_COMMANDS = new Set([
112
112
  'dispatch',
113
113
  'builds',
114
114
  'landings',
115
+ 'merges',
116
+ 'merge',
115
117
  'build',
116
118
  'watch',
117
119
  'wait',
@@ -173,6 +175,8 @@ export interface SessionlessCliDeps {
173
175
  /** For init/upgrade this is just the cwd — the default target repo. */
174
176
  workspacePath: string
175
177
  stdout: (line: string) => void
178
+ /** Drain watch output while termination cleanup still owns the store. */
179
+ flushStdout?: () => Promise<void>
176
180
  stderr: (line: string) => void
177
181
  /** Raw process environment for sessionless store selection, operator
178
182
  * provenance/self-control checks, and adapter secrets; distinct from `env`,
@@ -248,7 +252,7 @@ function requireSession(command: string, deps: SessionlessCliDeps): CliDeps {
248
252
  ) {
249
253
  throw new Error(
250
254
  `'ab ${command}' runs inside a build session — the runner sets AB_STORE, ` +
251
- 'AB_BUILD, AB_PHASE, AB_SESSION for every session (SPEC §8.1, D8). ' +
255
+ 'AB_BUILD, AB_PHASE, AB_SESSION, AB_CONTEXT_DIR for every session (SPEC §8.1, D8). ' +
252
256
  'Use `ab help` for commands that run sessionless.',
253
257
  )
254
258
  }
@@ -263,8 +267,8 @@ export function buildControlConfirmation(result: BuildControlResult): string {
263
267
  resume: 'resume requested',
264
268
  abort: 'abort requested',
265
269
  discard: 'discard requested',
266
- hold: 'landing hold requested',
267
- land: 'landing consent requested',
270
+ hold: 'merge hold requested',
271
+ land: 'merge consent requested',
268
272
  'auto-merge-on': 'auto-merge requested',
269
273
  'auto-merge-off': 'auto-merge cancelled',
270
274
  }
@@ -408,6 +412,7 @@ function renderManifest(manifest: ContextManifest): string[] {
408
412
  `context materialized for ${manifest.build} — ${manifest.phase}@${manifest.round}`,
409
413
  `required deposits: ${manifest.required.join(', ') || '(none)'}`,
410
414
  `allowed terminals: ${manifest.allowedTerminals.join(', ')}`,
415
+ `directory: ${manifest.contextDir}`,
411
416
  `manifest: ${manifest.manifestPath}`,
412
417
  ]
413
418
  if (manifest.notesPath !== undefined) lines.push(`notes path: ${manifest.notesPath}`)
@@ -420,7 +425,7 @@ function renderManifest(manifest: ContextManifest): string[] {
420
425
  if (manifest.step !== undefined) {
421
426
  lines.push(`verify step: ${manifest.step.name} (kind ${manifest.step.config.kind})`)
422
427
  }
423
- lines.push('.ab/ files:')
428
+ lines.push(`${manifest.contextDir}/ files:`)
424
429
  const entries = Object.entries(manifest.materialized)
425
430
  if (entries.length === 0) {
426
431
  lines.push(' (none)')
@@ -455,6 +460,10 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
455
460
  return 0
456
461
  }
457
462
  if (helpRequest?.kind === 'command') {
463
+ if (helpRequest.command === 'land' || helpRequest.command === 'landings')
464
+ stderr(
465
+ `ab ${helpRequest.command} is deprecated; use ab ${helpRequest.command === 'land' ? 'merge' : 'merges'}`,
466
+ )
458
467
  stdout(renderCommandHelp(helpRequest.command))
459
468
  return 0
460
469
  }
@@ -780,11 +789,13 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
780
789
  return 0
781
790
  }
782
791
 
792
+ case 'merges':
783
793
  case 'landings': {
784
- const usage = 'usage: ab landings [--json] [--store <ref>]'
794
+ if (command === 'landings') stderr('ab landings is deprecated; use ab merges')
795
+ const usage = 'usage: ab merges [--json] [--store <ref>]'
785
796
  const parsed = parseArgs(rest, { json: 'boolean', store: 'value' }, usage)
786
797
  if (parsed.positionals.length) throw new Error(usage)
787
- if (!deps.exec) throw new Error('ab landings needs an exec seam')
798
+ if (!deps.exec) throw new Error('ab merges needs an exec seam')
788
799
  await abLandings({
789
800
  targetRepo: deps.workspacePath,
790
801
  env: deps.processEnv ?? {},
@@ -928,6 +939,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
928
939
  rest,
929
940
  {
930
941
  repository: 'boolean',
942
+ operator: 'boolean',
931
943
  event: 'multi',
932
944
  since: 'value',
933
945
  timeout: 'value',
@@ -958,9 +970,11 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
958
970
  env: deps.processEnv ?? {},
959
971
  exec: deps.exec,
960
972
  stdout,
973
+ ...(deps.flushStdout ? { flushStdout: deps.flushStdout } : {}),
961
974
  stderr,
962
975
  slugs: parsed.positionals,
963
976
  repository: parsed.flags.has('repository'),
977
+ operator: parsed.flags.has('operator'),
964
978
  events: multiFlag(parsed, 'event'),
965
979
  since: stringFlag(parsed, 'since'),
966
980
  timeout: stringFlag(parsed, 'timeout'),
@@ -1090,20 +1104,22 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1090
1104
  }
1091
1105
 
1092
1106
  case 'hold':
1107
+ case 'merge':
1093
1108
  case 'land': {
1109
+ if (command === 'land') stderr('ab land is deprecated; use ab merge')
1094
1110
  const usage = `usage: ab ${command} <slug> [--store <ref>]`
1095
1111
  const parsed = parseArgs(rest, { store: 'value' }, usage)
1096
1112
  if (parsed.positionals.length !== 1) throw new Error(usage)
1097
1113
  await runBuildControl(
1098
1114
  deps,
1099
1115
  parsed.positionals[0]!,
1100
- { kind: command },
1116
+ { kind: command === 'merge' ? 'land' : command },
1101
1117
  stringFlag(parsed, 'store'),
1102
1118
  )
1103
1119
  return 0
1104
1120
  }
1105
1121
  case 'auto-merge':
1106
- throw new Error('ab auto-merge is retired; use ab hold, ab land, and [[landing]] policy')
1122
+ throw new Error('ab auto-merge is retired; use ab hold, ab merge, and [[merge]] policy')
1107
1123
 
1108
1124
  case 'answer': {
1109
1125
  const usage =
@@ -1,97 +1 @@
1
- import { buildTrailers, validateBuildSlug } from '../kernel/build-identity'
2
- import { originalForeign } from '../kernel/change-presence'
3
- import { history, nodeInventory, type NodeGit } from '../kernel/node-restack'
4
- import type { CommitRange, TicketRef } from '../ontology'
5
- import { readBuildFacts } from '../store/reduced-reads'
6
- import type { BuildStore } from '../store/types'
7
-
8
- export interface NodeContribution {
9
- build: string
10
- ticket: TicketRef
11
- spec: { kind: 'spec'; rev: number }
12
- specPath: string
13
- commits: string[]
14
- }
15
- export interface NodeVerificationIndex {
16
- range: CommitRange
17
- handPushedCommits: { sha: string; originalSha: string; message: string }[]
18
- contributions: NodeContribution[]
19
- unattributedCommits: string[]
20
- commits: { sha: string; build?: string }[]
21
- }
22
-
23
- /** Reachability, rather than the current child inventory, establishes membership. */
24
- export async function collectNodeVerificationProvenance(
25
- store: BuildStore,
26
- repo: string,
27
- range: CommitRange,
28
- git: NodeGit,
29
- ownership: { contributionBase: string; foreignAliases?: Record<string, string> },
30
- ): Promise<{ index: NodeVerificationIndex; specs: Map<string, string> }> {
31
- const index: NodeVerificationIndex = {
32
- range,
33
- handPushedCommits: [],
34
- contributions: [],
35
- unattributedCommits: [],
36
- commits: [],
37
- }
38
- const owned = new Set((await nodeInventory(git, range.head, ownership.contributionBase)).foreign)
39
- const aliases = new Map(Object.entries(ownership.foreignAliases ?? {}))
40
- const specs = new Map<string, string>()
41
- const byBuild = new Map<string, NodeContribution>()
42
- for (const commit of await history(
43
- git,
44
- [`${range.base}..${range.head}`],
45
- ['--reverse', '--topo-order'],
46
- )) {
47
- if (owned.has(commit.sha))
48
- index.handPushedCommits.push({
49
- sha: commit.sha,
50
- originalSha: originalForeign(commit.sha, aliases),
51
- message: commit.message,
52
- })
53
- const trailers = buildTrailers(commit.message)
54
- if (trailers.length > 1) throw new Error(`ambiguous build identity on ${commit.sha}`)
55
- const build = trailers[0]
56
- if (build === undefined) {
57
- index.commits.push({ sha: commit.sha })
58
- index.unattributedCommits.push(commit.sha)
59
- continue
60
- }
61
- try {
62
- validateBuildSlug(build)
63
- } catch {
64
- throw new Error(`invalid build identity on ${commit.sha}: ${JSON.stringify(build)}`)
65
- }
66
- let contribution = byBuild.get(build)
67
- if (contribution === undefined) {
68
- try {
69
- const record = await store.getBuild(build)
70
- if (!record) throw new Error('unknown build')
71
- if (record.repo !== repo) throw new Error('build belongs to a different repository')
72
- if (!record.ticket) throw new Error('missing ticket identity')
73
- const { state } = (await readBuildFacts(store, build)).value
74
- if (state.specRev === undefined) throw new Error('missing authoritative spec revision')
75
- const artifact = await store.getArtifact(build, 'spec', state.specRev)
76
- if (!artifact) throw new Error(`missing spec@${state.specRev}`)
77
- contribution = {
78
- build,
79
- ticket: record.ticket,
80
- spec: { kind: 'spec', rev: state.specRev },
81
- specPath: '',
82
- commits: [],
83
- }
84
- byBuild.set(build, contribution)
85
- index.contributions.push(contribution)
86
- specs.set(build, new TextDecoder().decode(artifact.content))
87
- } catch (error) {
88
- throw new Error(
89
- `node verification contribution ${build} at ${commit.sha}: ${error instanceof Error ? error.message : String(error)}`,
90
- )
91
- }
92
- }
93
- contribution.commits.push(commit.sha)
94
- index.commits.push({ sha: commit.sha, build })
95
- }
96
- return { index, specs }
97
- }
1
+ export * from '../kernel/node-verification-context'
@@ -1,3 +1,4 @@
1
+ import { publicationRetryGate, retryPublicationEffect } from '../kernel/publication-retry'
1
2
  import { ForgeRequestDeferred } from '../ports/forge-request-context'
2
3
  import { stat } from 'node:fs/promises'
3
4
  import { deferMixedVersion, MixedVersionDeferral } from '../kernel/mixed-version'
@@ -93,21 +94,35 @@ export async function settlePendingPublication(
93
94
  intended.branch !== request.payload.branch
94
95
  )
95
96
  throw new Error('restack publication request does not match its durable intent')
97
+ const retryDeps = { ...deps, slug, clock: deps.clock ?? systemClock, actor: DISPATCHER }
98
+ await publicationRetryGate(retryDeps, 'restack', transaction.id)
96
99
  const archives = [...new Set([...events.gitTips, request.payload.sha])].map((sha) => ({
97
100
  ref: `refs/autobuild/archive/${slug}/${sha}`,
98
101
  sha,
99
102
  }))
100
- await suspendNativeLanding({ ...deps, slug }, `publication:${request.seq}`)
101
- const result = await publication.rewrite({
102
- ref,
103
- sha: request.payload.sha,
104
- branch: transaction.branch,
105
- expected: transaction.oldHead,
106
- localExpected: transaction.localBranchHead,
107
- archives,
108
- })
103
+ const external = <T>(effect: () => Promise<T>) =>
104
+ retryPublicationEffect(
105
+ retryDeps,
106
+ 'restack',
107
+ transaction.id,
108
+ events.state.reconcileAttempts + 1,
109
+ effect,
110
+ )
111
+ await external(() => suspendNativeLanding({ ...deps, slug }, `publication:${request.seq}`))
112
+ const result = await external(() =>
113
+ publication.rewrite!({
114
+ ref,
115
+ sha: request.payload.sha,
116
+ branch: transaction.branch,
117
+ expected: transaction.oldHead,
118
+ localExpected: transaction.localBranchHead,
119
+ archives,
120
+ }),
121
+ )
109
122
  if (result.kind === 'published')
110
- await confirmDispatcherCache(deps, request.payload.branch, request.payload.sha)
123
+ await external(() =>
124
+ confirmDispatcherCache(deps, request.payload.branch, request.payload.sha),
125
+ )
111
126
  const latest = (await readBuildFacts(deps.store, slug)).value
112
127
  if (
113
128
  (result.kind === 'published' || result.rewritten === true) &&
@@ -170,19 +185,27 @@ export async function settlePendingPublication(
170
185
  throw new Error('reconcile request does not match its durable resolved intent')
171
186
  if (events.reconcileBases[String(transaction.attempt)] !== transaction.targetBase)
172
187
  throw new Error('reconcile publication target differs from the recorded start')
188
+ const retryDeps = { ...deps, slug, clock: deps.clock ?? systemClock, actor: DISPATCHER }
189
+ await publicationRetryGate(retryDeps, 'reconcile', transaction.id)
173
190
  const tips = new Set([...events.gitTips, request.payload.sha])
174
191
  const archives = [...tips].map((sha) => ({ ref: `refs/autobuild/archive/${slug}/${sha}`, sha }))
175
- await suspendNativeLanding({ ...deps, slug }, `publication:${request.seq}`)
176
- const result = await publication.rewrite({
177
- ref,
178
- sha: request.payload.sha,
179
- branch: request.payload.branch,
180
- expected: transaction.oldHead,
181
- localExpected: transaction.localBranchHead,
182
- archives,
183
- })
192
+ const external = <T>(effect: () => Promise<T>) =>
193
+ retryPublicationEffect(retryDeps, 'reconcile', transaction.id, transaction.attempt, effect)
194
+ await external(() => suspendNativeLanding({ ...deps, slug }, `publication:${request.seq}`))
195
+ const result = await external(() =>
196
+ publication.rewrite!({
197
+ ref,
198
+ sha: request.payload.sha,
199
+ branch: request.payload.branch,
200
+ expected: transaction.oldHead,
201
+ localExpected: transaction.localBranchHead,
202
+ archives,
203
+ }),
204
+ )
184
205
  if (result.kind === 'published')
185
- await confirmDispatcherCache(deps, request.payload.branch, request.payload.sha)
206
+ await external(() =>
207
+ confirmDispatcherCache(deps, request.payload.branch, request.payload.sha),
208
+ )
186
209
  const history = (await readBuildFacts(deps.store, slug)).value.reconcileHistory
187
210
  if (
188
211
  (result.kind === 'published' || result.rewritten === true) &&