@defrex/autobuild 1.3.0 → 1.4.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 (142) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +302 -26
  3. package/docs/accounts.md +38 -0
  4. package/docs/architecture.md +187 -19
  5. package/docs/build-store.md +18 -0
  6. package/docs/builds.md +5 -1
  7. package/docs/cli.md +1 -1
  8. package/docs/configuration.md +38 -19
  9. package/docs/dispatcher-hosting.md +42 -0
  10. package/docs/dispatcher.md +41 -0
  11. package/docs/forges.md +5 -0
  12. package/docs/integration-tree.md +8 -0
  13. package/docs/operating.md +11 -3
  14. package/docs/operator-api.md +37 -4
  15. package/docs/plugin-authoring.md +45 -1
  16. package/docs/remote-store-protocol.md +258 -42
  17. package/docs/remote-ticket-protocol.md +12 -10
  18. package/docs/restacking.md +60 -3
  19. package/docs/setup.md +37 -8
  20. package/docs/skills.md +1 -1
  21. package/docs/spec-standard.md +37 -3
  22. package/docs/troubleshooting.md +9 -0
  23. package/docs/workspaces.md +1 -1
  24. package/package.json +4 -3
  25. package/packages/core/src/accounts/availability.ts +96 -0
  26. package/packages/core/src/accounts/local-owner.ts +49 -2
  27. package/packages/core/src/cli/attention.ts +2 -0
  28. package/packages/core/src/cli/binary.ts +17 -1
  29. package/packages/core/src/cli/context.ts +62 -0
  30. package/packages/core/src/cli/dashboard/model.ts +12 -3
  31. package/packages/core/src/cli/dashboard/poll.ts +65 -8
  32. package/packages/core/src/cli/dashboard/refresh.ts +2 -0
  33. package/packages/core/src/cli/dashboard/render.ts +46 -5
  34. package/packages/core/src/cli/dispatch-args.ts +27 -3
  35. package/packages/core/src/cli/dispatch-frontend.ts +178 -52
  36. package/packages/core/src/cli/dispatch-mode.ts +94 -0
  37. package/packages/core/src/cli/dispatch-preflight.ts +43 -0
  38. package/packages/core/src/cli/dispatch-repository-feed.ts +45 -9
  39. package/packages/core/src/cli/dispatch.ts +145 -11
  40. package/packages/core/src/cli/harvest.ts +2 -1
  41. package/packages/core/src/cli/help.ts +16 -3
  42. package/packages/core/src/cli/historical-build-state.ts +6 -0
  43. package/packages/core/src/cli/main.ts +15 -2
  44. package/packages/core/src/cli/publication-settlement.ts +17 -0
  45. package/packages/core/src/cli/remote-poll.ts +11 -1
  46. package/packages/core/src/cli/repository-status.ts +11 -0
  47. package/packages/core/src/cli/status.ts +7 -1
  48. package/packages/core/src/cli/wait.ts +9 -2
  49. package/packages/core/src/cli/watch.ts +38 -3
  50. package/packages/core/src/config/roles.ts +16 -1
  51. package/packages/core/src/events/catalog.ts +7 -0
  52. package/packages/core/src/events/payloads.ts +85 -2
  53. package/packages/core/src/events/policy.ts +10 -0
  54. package/packages/core/src/events/repository.ts +35 -0
  55. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +189 -0
  56. package/packages/core/src/kernel/dispatch-placement.ts +30 -0
  57. package/packages/core/src/kernel/engine.ts +19 -12
  58. package/packages/core/src/kernel/generators/leaf-restack-log.ts +17 -1
  59. package/packages/core/src/kernel/leaf-restack-state.ts +24 -2
  60. package/packages/core/src/kernel/log-index.ts +1 -1
  61. package/packages/core/src/kernel/node-landing.ts +27 -10
  62. package/packages/core/src/kernel/node-restack-demand.ts +1 -0
  63. package/packages/core/src/kernel/node-restack-state.ts +16 -1
  64. package/packages/core/src/kernel/node-restack-transaction.ts +14 -0
  65. package/packages/core/src/kernel/read-facts.ts +114 -9
  66. package/packages/core/src/kernel/reconcile-head.ts +34 -11
  67. package/packages/core/src/kernel/reconcile-restack.ts +106 -72
  68. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  69. package/packages/core/src/kernel/reducer.ts +20 -2
  70. package/packages/core/src/kernel/replay-retention.ts +176 -0
  71. package/packages/core/src/kernel/target-lineage.ts +65 -0
  72. package/packages/core/src/kernel/target-observation.ts +117 -0
  73. package/packages/core/src/operator/registry.ts +5 -13
  74. package/packages/core/src/operator/tickets.ts +8 -2
  75. package/packages/core/src/plugin-sdk/index.ts +1 -0
  76. package/packages/core/src/ports/forge/fake.ts +22 -0
  77. package/packages/core/src/ports/forge/git-rewrite.ts +49 -12
  78. package/packages/core/src/ports/forge/github.ts +42 -10
  79. package/packages/core/src/ports/forge/local-git.ts +16 -1
  80. package/packages/core/src/ports/types.ts +58 -4
  81. package/packages/core/src/ports/workspace/account-policy.ts +2 -1
  82. package/packages/core/src/ports/workspace/commit-preservation.ts +175 -0
  83. package/packages/core/src/ports/workspace/create.ts +2 -0
  84. package/packages/core/src/ports/workspace/fake.ts +4 -0
  85. package/packages/core/src/ports/workspace/git-worktree.ts +22 -1
  86. package/packages/core/src/ports/workspace/vercel-sandbox.ts +304 -56
  87. package/packages/core/src/processes/build-runner.ts +240 -111
  88. package/packages/core/src/processes/dispatcher-selectors.ts +3 -2
  89. package/packages/core/src/processes/dispatcher.ts +262 -80
  90. package/packages/core/src/processes/execution-no-progress.ts +7 -0
  91. package/packages/core/src/processes/harvest-runner.ts +6 -7
  92. package/packages/core/src/processes/publication-state.ts +2 -1
  93. package/packages/core/src/processes/repo-view.ts +22 -0
  94. package/packages/core/src/processes/workspace-preservation.ts +164 -0
  95. package/packages/core/src/scenarios/harness.ts +7 -0
  96. package/packages/core/src/store/adapter.ts +9 -0
  97. package/packages/core/src/store/build-scope.ts +28 -0
  98. package/packages/core/src/store/contract.ts +125 -0
  99. package/packages/core/src/store/event-reads.ts +156 -0
  100. package/packages/core/src/store/local/schema.ts +11 -0
  101. package/packages/core/src/store/local/store.ts +117 -2
  102. package/packages/core/src/store/memory.ts +237 -0
  103. package/packages/core/src/store/phase-session.ts +47 -0
  104. package/packages/core/src/store/reduced-reads.ts +8 -0
  105. package/packages/core/src/store/reducer-value-shapes.json +6262 -5227
  106. package/packages/core/src/store/reducer-value-validation.ts +3 -0
  107. package/packages/core/src/store/reducer-values.ts +62 -2
  108. package/packages/core/src/store/remote/client.ts +161 -16
  109. package/packages/core/src/store/remote/compatibility.ts +177 -46
  110. package/packages/core/src/store/remote/errors.ts +16 -0
  111. package/packages/core/src/store/remote/index.ts +11 -0
  112. package/packages/core/src/store/remote/protocol.ts +22 -0
  113. package/packages/core/src/store/remote/released-clients.json +37 -0
  114. package/packages/core/src/store/remote/released-clients.ts +88 -0
  115. package/packages/core/src/store/remote/released-reducer-values/1.3.0.json +25093 -0
  116. package/packages/core/src/store/remote/released-reducer-values/1.4.0.json +26128 -0
  117. package/packages/core/src/store/remote/released-reducer-values/index.ts +13 -0
  118. package/packages/core/src/store/remote/version.ts +5 -2
  119. package/packages/core/src/store/repo-state-events.ts +4 -3
  120. package/packages/core/src/store/scan-cadence.ts +15 -0
  121. package/packages/core/src/store/session-handle.ts +18 -0
  122. package/packages/core/src/store/types.ts +27 -6
  123. package/packages/core/src/testing/dispatch-read-budget.ts +313 -2
  124. package/packages/core/src/testing/index.ts +5 -0
  125. package/packages/core/src/testing/reduced-read-budget.ts +728 -5
  126. package/skills/guide/SKILL.md +177 -16
  127. package/skills/guide/references/accounts.md +38 -0
  128. package/skills/guide/references/integration-tree.md +8 -0
  129. package/skills/guide/references/operator-api.md +37 -4
  130. package/skills/guide/references/plugin-authoring.md +45 -1
  131. package/skills/guide/references/remote-store-protocol.md +258 -42
  132. package/skills/guide/references/remote-ticket-protocol.md +12 -10
  133. package/skills/guide/references/restacking.md +60 -3
  134. package/skills/guide/references/setup.md +37 -8
  135. package/skills/guide/references/spec-standard.md +37 -3
  136. package/skills/implement/SKILL.md +12 -3
  137. package/skills/operate/SKILL.md +64 -7
  138. package/skills/plan/SKILL.md +27 -4
  139. package/skills/plan-review/SKILL.md +22 -2
  140. package/skills/reconcile/SKILL.md +10 -1
  141. package/skills/spec/SKILL.md +7 -4
  142. package/templates/hosted-service/package.json +2 -2
package/docs/operating.md CHANGED
@@ -59,16 +59,24 @@ without withdrawal support fall back silently. SIGKILL still relies on TTL expir
59
59
 
60
60
  Re-arm with `bun ab watch --operator --json --since <watch-cursor>` using only
61
61
  the standing watch's own cursor. This preserves one ID and original start time
62
- across a re-arm gap of up to five minutes. After termination withdraws presence,
62
+ across a presence re-arm gap of up to five minutes. This presence TTL is separate
63
+ from hosted event-window eligibility. After termination withdraws presence,
63
64
  the same cursor re-registers the same ID and start time. Reconcile current and
64
65
  newly dispatched builds after arming and on timeout. Keep operating after the initial work ends,
65
66
  until you end or hand off the role. `wait` does not heartbeat or carry registration
66
67
  identity: a separate unflagged diagnostic wait/watch must never replace the
67
68
  standing monitor or supply its resume cursor. MCP presence is deferred.
68
69
 
70
+ Keep `--since` for normal re-arms. Hosted resume accepts cursors at or above
71
+ `max(0, head - 1000)` in each monitored stream: the inclusive window is 1,000
72
+ sequence positions behind its head. If a cursor is too old, re-arm without
73
+ `--since` and reconcile repository and build status. That fresh attachment cannot
74
+ recover the unavailable historical gap; status reconciliation does not restore
75
+ one-off events from that gap.
76
+
69
77
  - **Default filter:** actionable attention only, such as escalations and ready merges awaiting consent. Add `--event` globs for routine lifecycle events.
70
78
  - **Starts now:** a fresh watch ignores history, so check current status too.
71
- - **Resumable:** pass the opaque cursor from the JSON output back with `--since` to receive events recorded while away. The final JSON line always carries one.
79
+ - **Resumable:** pass the opaque cursor from the JSON output back with `--since` to receive events recorded while away within the hosted window described above. The final JSON line always carries one.
72
80
  - **Duration:** 30 minutes by default; `--timeout 0` keeps it open.
73
81
 
74
82
  ```
@@ -83,7 +91,7 @@ bun ab wait my-build --for attention --json --timeout 5m
83
91
  | 2 | Every named build ended without matching |
84
92
  | 3 | Timed out |
85
93
 
86
- Existing attention returns immediately, even with a cursor, so looping `wait` doesn't consume events. Use `watch --since` for that.
94
+ Existing attention returns immediately, even with a cursor, so looping `wait` doesn't consume events. Use `watch --since` for that. Hosted `wait --since` uses the same inclusive 1,000-position resume window and too-old recovery described above: re-arm without `--since`, reconcile repository and build status, and account for the unavailable historical gap.
87
95
 
88
96
  ## Answer and pause
89
97
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  A conforming hosted instance implements this normative polling-oriented operator
4
4
  contract at
5
- `/operator/v1/repos/{repo}`. It is versioned with remote store protocol **6**.
5
+ `/operator/v1/repos/{repo}`. It is versioned with remote store protocol **7**.
6
6
  Every request must send `X-Autobuild-Version`,
7
- `X-Autobuild-Protocol-Version: 6`, and `Authorization: Bearer …`. Identity is
7
+ `X-Autobuild-Protocol-Version: 7`, and `Authorization: Bearer …`. Identity is
8
8
  checked before authentication or resource lookup.
9
9
 
10
10
  Project credentials are opaque `abp_1_<id>_<secret>` bearer values bound to one
@@ -271,7 +271,7 @@ The default watch reports actionable conditions only:
271
271
  - `build.janitor-failing`: a build has reached the configured consecutive-failure threshold; a successful janitor attempt clears it.
272
272
  - `dispatcher.forge-persistent`: forge degradation remains after a completed post-reset retry opportunity; successful recovery clears it.
273
273
 
274
- - Build `escalation.raised`, `integration.landed`, `node.item-conflicted`, or
274
+ - Build `escalation.raised`, `integration.landed`, `node.item-conflicted`, `target.rewritten`, or
275
275
  conflicted `restack.replayed` events. `build.consent-ready` is the single
276
276
  signal for a ready consent or held merge, including first repository-wide
277
277
  discovery. Its target has the queue entry shape `{kind, branch, ticket?, build?}`.
@@ -311,7 +311,7 @@ have `repo` and null build/state. Source observations also report
311
311
 
312
312
  Every record carries a cursor, including timer-only records. Resuming suppresses
313
313
  delivered merge decisions and persistence episodes even when stream positions
314
- did not advance. Old v1 cursors remain valid: historical eligible merge
314
+ did not advance. Old v1 cursors remain valid inside the hosted 1,000-position resume window: historical eligible merge
315
315
  decisions are treated as consumed; active overdue repository episodes may
316
316
  report because old watches had no persistence notification. Fresh attachment
317
317
  silently baselines historical direct events and merge decisions, but retains
@@ -328,11 +328,32 @@ self-healing failures. A merge match uses the watch observation with
328
328
  `condition: "attention"`. Explicit `--event` globs remain event-only.
329
329
  Watch and wait preserve each other's cursor notification metadata.
330
330
 
331
+ Normal re-arms retain `--since`. Hosted watch/wait resume is gap-proportional
332
+ inside a 1,000-sequence-position window, inclusive at `head - 1000`. Expired
333
+ cursors fail with typed `cursor-too-old` and the oldest servable cursor; re-arm
334
+ without `--since` and reconcile repository/build status, acknowledging the lost
335
+ historical gap. An ordinary reducer upgrade preserves valid cursors. A retired
336
+ seed generation instead requires an upgrade/restart before fresh attachment;
337
+ checkpoint integrity errors are terminal and never trigger replay from zero.
338
+
339
+ The MCP `builds.events` tool returns `{events, cursor, hasMore}`, at most 256
340
+ events per call. Follow `cursor` while `hasMore` is true to traverse a build's
341
+ complete history without omission. Waiting remains bounded and applies only
342
+ when no events are available. Repository event reads have a 1,000-position
343
+ window; build history itself remains available through explicit pages.
344
+
345
+
331
346
  Hosted ticket tools resolve independent project ticket policy before legacy uploaded
332
347
  configuration. Queue, detail, state discovery and mutations work before any build
333
348
  or dispatcher run; detail reports a null matching build. Ticket policy publication
334
349
  never creates synthetic build or repository history.
335
350
 
351
+ Ticket detail and mutation results prefer exact normalized ticket ids when associating
352
+ a build. If no exact match exists, only legacy hosted `ticket-<uuid>` storage
353
+ references require optional alias resolution, once per distinct reference. Readable
354
+ historical ids require no ticket lookup. Failed optional alias resolution does not
355
+ fail ticket detail or a completed mutation; matches already resolved remain eligible.
356
+
336
357
  Ticket results include kind (default work) and optional same-source node target.
337
358
  Metadata-only patches are accepted. Target validation and demotion guards apply
338
359
  to CLI, HTTP and MCP alike; unsupported sources refuse even explicit defaults
@@ -451,6 +472,18 @@ projects return the same unknown-repository result as absent projects. Machine c
451
472
 
452
473
  ### Permanent project deletion
453
474
 
475
+ The browser requires the exact full repository identity in a transient dialog field;
476
+ confirm stays disabled for empty or mismatched input and focus starts in the field.
477
+ The handler independently binds that identity to the selected repository and its
478
+ fresh validated preview. Only JSON `{deleted:true}` acknowledges completion.
479
+ After any failed or unrecognized deletion response, the browser shows
480
+ “Deletion outcome unknown; reload to check” and holds the row in its original slot
481
+ without actions, even after dismissal. Only a complete successful discovery begun
482
+ by Reload after the attempt settles it: absence removes the row, presence restores
483
+ its authorized actions, and pending cleanup restores Finish deletion with a fresh
484
+ preview and exact typing. An earlier or unsuccessful read cannot settle the outcome.
485
+ The server's `{repo}` body and generation-bound If-Match contract are unchanged.
486
+
454
487
  Super users and the owner of a project's organization can delete it from the
455
488
  Projects page. Owners see only projects in organizations they own; Move and
456
489
  Assign remain super-user operations. The shared confirmation dialog names the project,
@@ -61,7 +61,12 @@ Declare served model prefixes and a default. Optional tool-free `oneShot` sits b
61
61
  Reconcile requires the optional grouped `Forge.rewrite` capability:
62
62
 
63
63
  1. Snapshot the actual build branch into a build-private ref.
64
- 2. Publish immutable exact-SHA refs under `refs/autobuild/archive/<slug>/<sha>`.
64
+ 2. Publish immutable exact-SHA refs under `refs/autobuild/archive/<slug>/<sha>`. Remote
65
+ archives also publish commits present only on the remote: GitHub uses create-only
66
+ Git-reference REST creation when the workspace lacks the commit, retaining guarded
67
+ Git pushes for local objects. Exact remote readback confirms publication, then a
68
+ depth-one fetch by the archive ref (without tags or configured refmap expansion)
69
+ restores missing commits and verifies them locally before returning.
65
70
  3. Replace the explicit branch, leased on an explicit expected remote head.
66
71
 
67
72
  - Return `lease-mismatch` separately from transport, auth and policy failures.
@@ -71,6 +76,45 @@ Reconcile requires the optional grouped `Forge.rewrite` capability:
71
76
  - Older forge plugins still load; reconcile refuses them actionably.
72
77
  - Remote workspace providers also need trusted `WorkspacePublication.rewrite` after guest teardown; ordinary `publish` can't publish a restack.
73
78
 
79
+ ### Destination observation and ancestry
80
+
81
+ `remoteBranchSha(branch)` must read the authoritative forge branch. Its absence
82
+ or failure defers observation; there is no host-checkout fallback. The optional
83
+ `isCommitAncestor(ancestor, descendant)` compares immutable full OIDs: return
84
+ false only for a proven non-descendant, and throw for missing objects, transport,
85
+ authentication, malformed responses or rate limits. Missing capability withholds
86
+ new replay requiring proof. GitHub uses exact-SHA comparison; local-git requires
87
+ an explicit served `repoRoot`. Unknown ancestry never authorizes replay.
88
+
89
+ Stores may expose `getNodeRewrite(node, previousHead, beforePrevious)` as a bounded point
90
+ lookup of a durable `node.rewritten` receipt. Built-in adapters index these
91
+ validated publication facts atomically with append, including transactional
92
+ deposits. The dispatcher uses at most 64 hops per baseline to prove kernel node
93
+ restacks and records `target.moved.lineage` for scoped runners. There is no
94
+ history-download fallback when the capability or a receipt is absent.
95
+ With `beforePrevious`, return the publication immediately preceding the latest
96
+ receipt keyed by that previous head, using indexed cursor and result lookups.
97
+ This lets lineage proofs cross forward sibling landings between restacks; every
98
+ intervening forward gap still requires immutable ancestry proof.
99
+
100
+
101
+ ### Workspace preservation
102
+
103
+ Remote providers expose trusted `WorkspacePublication.preserve` and
104
+ `recoverCandidate`; local providers may supply `WorkspaceProvider.preservation`
105
+ without changing the remote-publication discriminator. Missing capabilities fail
106
+ safely at destructive boundaries. `WorkspaceRecovery.fence(handle)` reports
107
+ confirmed, absent, or unknown without deleting an environment or its snapshots.
108
+ Only dispatcher-authorized reap follows the durable fence and preservation/loss
109
+ receipt. `provision` accepts exact `restoration` heads; branch ancestry must be
110
+ verified, and detached producer objects must never overwrite the named branch.
111
+ Provision/start failures signal `WorkspaceCleanupRequired` rather than deleting
112
+ or implicitly recreating an existing checkout. A confirmed `snapshot_not_found`
113
+ lookup establishes filesystem absence, while retaining the stale name for
114
+ dispatcher-authorized deletion. Other provider failures remain unknown and must
115
+ never be converted into loss evidence. Credentials stay in trusted transport policy,
116
+ never guest environment or agent commands.
117
+
74
118
  ### Publication readback
75
119
 
76
120
  Publication succeeds only when an authoritative branch-head readback equals the frozen intended SHA, including recovery after a failed push. Unconfirmed candidate ancestry never proves publication.