@defrex/autobuild 1.16.0 → 1.17.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 (72) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +91 -7
  3. package/docs/answering-blocked-builds.md +34 -1
  4. package/docs/architecture.md +15 -1
  5. package/docs/configuration.md +33 -4
  6. package/docs/operator-api.md +15 -5
  7. package/docs/plugin-authoring.md +1 -0
  8. package/docs/remote-store-protocol.md +13 -3
  9. package/docs/remote-ticket-protocol.md +3 -1
  10. package/docs/restacking.md +41 -1
  11. package/docs/setup.md +15 -6
  12. package/docs/troubleshooting.md +39 -2
  13. package/docs/workspaces.md +2 -0
  14. package/package.json +3 -3
  15. package/packages/core/src/cli/accounts.ts +3 -0
  16. package/packages/core/src/cli/binary-direct.ts +14 -1
  17. package/packages/core/src/cli/binary.ts +10 -7
  18. package/packages/core/src/cli/dispatch.ts +503 -334
  19. package/packages/core/src/cli/secrets.ts +2 -0
  20. package/packages/core/src/config/schema.ts +15 -2
  21. package/packages/core/src/events/payloads.ts +8 -5
  22. package/packages/core/src/kernel/engine.ts +118 -0
  23. package/packages/core/src/kernel/reconcile-restack.ts +72 -9
  24. package/packages/core/src/kernel/tracked-dirt.ts +173 -0
  25. package/packages/core/src/ontology.ts +1 -0
  26. package/packages/core/src/operator/index.ts +10 -0
  27. package/packages/core/src/operator/merged-builds.ts +51 -0
  28. package/packages/core/src/operator/registry.ts +190 -101
  29. package/packages/core/src/operator/repo-argument.ts +43 -0
  30. package/packages/core/src/ports/tickets/grants.ts +2 -0
  31. package/packages/core/src/ports/tickets/remote.ts +2 -0
  32. package/packages/core/src/ports/types.ts +15 -0
  33. package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
  34. package/packages/core/src/ports/workspace/vercel-sandbox.ts +576 -140
  35. package/packages/core/src/processes/build-child.ts +15 -1
  36. package/packages/core/src/processes/build-runner.ts +349 -20
  37. package/packages/core/src/processes/dispatcher.ts +28 -7
  38. package/packages/core/src/processes/harvest-child.ts +21 -1
  39. package/packages/core/src/processes/harvest-runner.ts +82 -35
  40. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  41. package/packages/core/src/processes/provisioning-progress.ts +23 -0
  42. package/packages/core/src/processes/repo-view.ts +25 -4
  43. package/packages/core/src/processes/workspace-preparation.ts +1 -0
  44. package/packages/core/src/store/adapter.ts +34 -5
  45. package/packages/core/src/store/build-feed.ts +148 -22
  46. package/packages/core/src/store/build-scope.ts +12 -3
  47. package/packages/core/src/store/caller-attribution.ts +170 -0
  48. package/packages/core/src/store/contract.ts +1038 -165
  49. package/packages/core/src/store/local/schema.ts +12 -1
  50. package/packages/core/src/store/local/store.ts +260 -25
  51. package/packages/core/src/store/memory.ts +156 -9
  52. package/packages/core/src/store/phase-session.ts +23 -3
  53. package/packages/core/src/store/reducer-value-shapes.json +3184 -3175
  54. package/packages/core/src/store/remote/client.ts +90 -11
  55. package/packages/core/src/store/remote/credentials.ts +2 -0
  56. package/packages/core/src/store/remote/index.ts +31 -5
  57. package/packages/core/src/store/remote/protocol.ts +45 -8
  58. package/packages/core/src/store/remote/released-clients.json +11 -0
  59. package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
  60. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  61. package/packages/core/src/store/session-handle.ts +12 -3
  62. package/packages/core/src/store/types.ts +48 -3
  63. package/packages/core/src/testing/reduced-read-budget.ts +222 -4
  64. package/skills/guide/SKILL.md +46 -8
  65. package/skills/guide/references/operator-api.md +15 -5
  66. package/skills/guide/references/plugin-authoring.md +1 -0
  67. package/skills/guide/references/remote-store-protocol.md +13 -3
  68. package/skills/guide/references/remote-ticket-protocol.md +3 -1
  69. package/skills/guide/references/restacking.md +41 -1
  70. package/skills/guide/references/setup.md +15 -6
  71. package/skills/operate/SKILL.md +24 -3
  72. package/templates/hosted-service/package.json +2 -2
@@ -114,6 +114,15 @@ Placement is informational and does not change `ab dispatch` behavior.
114
114
  body parsing, or resource lookup, the server validates the release-line window and known protocol identity.
115
115
  Unsupported or missing values receive `409 {"kind":"conflict","error":"…"}`;
116
116
  the diagnostic names the client and server package and protocol versions.
117
+ - Clients may send `X-Autobuild-Caller`, a diagnostic attribution of who made
118
+ the request: `key=value` pairs joined by `;`, at most 512 characters. Keys
119
+ are `kind` (`dispatcher`, `runner` or `operator`), `client`, `runner`,
120
+ `invocation`, `run`, `stage`, `build`, `harvest`, `execution`, `session`,
121
+ `phase` and `command`; each value is at most 96 characters of
122
+ `[A-Za-z0-9._:@+/-]`. The shipped client sends it on store, ticket, grant
123
+ and credential requests. A server must accept requests without it, must
124
+ treat it as untrusted (bound, sanitize, ignore unknown keys), and must never
125
+ use it for authorization or routing.
117
126
  - Clients send `Content-Type: application/json` for requests with bodies. Every
118
127
  response, including errors and `null` artifact results, has
119
128
  `Content-Type: application/json`.
@@ -763,7 +772,7 @@ artifacts, and leases. `{repo}` is one percent-encoded repository id; encode
763
772
  embedded `/` characters. All resource routes authorize and require the
764
773
  repository to exist. An unknown repository returns `404 not-found` — except
765
774
  for the build-record reads of this section (`change-position`, `builds`,
766
- `changed-builds`, `build-page`, `build-digests`, `open-builds` and `rollup-values`), which are keyed
775
+ `changed-builds`, `build-page`, `merged-build-page`, `build-digests`, `open-builds` and `rollup-values`), which are keyed
767
776
  to build records, not the repository journal record, so they authorize the
768
777
  project credential but answer `200` (possibly empty) even for an unknown
769
778
  repository, a repository without a journal record, or a repository without
@@ -787,6 +796,7 @@ builds.
787
796
  | `listBuildsForRepo` | `GET /repos/{repo}/builds` | none | `200` + `BuildRecord[]` ordered by creation time, then slug |
788
797
  | `listBuildsChangedSince` | `GET /repos/{repo}/changed-builds?since={p}` | required `since`, a canonical unsigned decimal no greater than 9223372036854775807; anything else is `400 validation` | `200 {"position": string, "builds": [{"slug": string, "position": string}]}`: the builds whose latest change position is greater than `since`, ascending by position and each once, with the repository head read in the same snapshot. Reads no event rows. An unknown repository answers `{"position": "0", "builds": []}` |
789
798
  | `listBuildsPage` | `GET /repos/{repo}/build-page?limit={n}&cursor={c}&kind={k}&outcome=merged&activeSince={t}` | optional `limit`, a decimal integer from 1 to 100 (default 25); optional `cursor`, a `next` value this server issued for the same filters; optional `kind`, `leaf` or `node`; optional `outcome`, only `merged`; optional `activeSince`, an ISO instant with a zone. A bad limit, a malformed cursor, a cursor of the other order, or an empty or invalid filter is `400 validation` | `200 {"builds": BuildRecord[], "next": string \| null, "filters"?: {"kind"?, "outcome"?, "activeSince"?}}`: one page newest first by creation time, slug descending to break ties, with records as `builds` returns them; `next` is `null` on the last page. `kind` and `outcome` keep that order. `activeSince` keeps builds whose `updatedAt` is at or after it, ordered by `updatedAt` then slug, both descending, a superset of builds active in the window; a build written between two requests can appear twice or be skipped once, so dedupe by slug. A filtered answer echoes the normalized filters it applied as `filters`. Every page, filtered or not, costs at most `limit + 1` index entries and no event rows |
799
+ | `listMergedBuildsPage` | `GET /repos/{repo}/merged-build-page?limit={n}&cursor={c}&since={t}&until={t}` | optional `limit`, as for `build-page`; optional `cursor`, a `next` value this server issued for the same window; optional `since` (inclusive) and `until` (exclusive), ISO instants with a zone. A bad limit, a malformed cursor, a cursor of another order, an empty or invalid instant, or `since` after `until` is `400 validation` | `200 {"builds": [{"record": BuildRecord, "mergedAt": string, "kind": "leaf" \| "node", "pr"?: {"number", "url"}, "target"?: {"build", "ticket"}}], "next": string \| null}`: merged builds, most recently merged first (merge time, then slug, both descending). `mergedAt` is the merging `build.completed`'s `ts`; `pr` comes from the latest `pr.opened` or `finalize.completed`; `target` from `build.created`, replaced on a node by `node.parent-accepted`. Every page costs at most `limit + 1` index entries, no event rows and no reduced values |
790
800
  | `getReducerValue` (rollup scope) | `POST /repos/{repo}/rollup-values` | a named-value request with optional `read`; see [Rollup values](#rollup-values) | `200 {"version", "cursor": 0, "value"}`: the canonical rollup; an unknown repository answers the empty value |
791
801
  | `getRepoBuildDigests` | `GET /repos/{repo}/build-digests` | none | `200` + `BuildDigest[]`, one entry per build record of the repository (possibly empty), ordered by slug; handled before the repository-existence gate, so an unknown or journal-less repository answers `200 []` |
792
802
  | `listOpenBuilds` | `GET /repos/{repo}/open-builds` | none | `200` + `[{"record", "digest"}]`, a build record and its `BuildDigest` for every open build of the repository (possibly empty), ordered by `createdAt` and then slug; handled before the repository-existence gate, so an unknown or journal-less repository answers `200 []` |
@@ -794,8 +804,8 @@ builds.
794
804
  | `heartbeatRepo` | `POST /repos/{repo}/lease/heartbeat` | holder request | `200 {"ok": boolean}` |
795
805
  | `releaseRepoLease` | `POST /repos/{repo}/lease/release` | holder request | `200 {"ok": true}`; a wrong holder is a successful no-op |
796
806
 
797
- The `changed-builds` and `build-page` routes are additive and keep the
798
- protocol version. A server on the same release line that lacks them answers
807
+ The `changed-builds`, `build-page` and `merged-build-page` routes are additive
808
+ and keep the protocol version. A server on the same release line that lacks them answers
799
809
  `501 unsupported-operation` or `404 not-found`; the shipped client reports
800
810
  that as a typed `BuildFeedUnsupportedError` and never falls back to listing
801
811
  builds or reading events. The `build-page` filters are additive too. A server
@@ -35,7 +35,9 @@ Every request is `POST /tickets/<operation>`, has `Content-Type: application/jso
35
35
  and requires `Authorization: Bearer <project credential>`. Authentication and
36
36
  registration checks precede body parsing and source construction. Owner admin
37
37
  is the explicit cross-project exception; internal operator signatures have no
38
- ticket authority.
38
+ ticket authority. Clients may also send the optional, diagnostic
39
+ `X-Autobuild-Caller` attribution header described in the remote store
40
+ protocol's transport conventions; the service never authorizes on it.
39
41
 
40
42
  Project credentials are opaque `abp_1_<id>_<secret>` bearer values bound to one
41
43
  registered normalized repository. The service stores only a SHA-256 digest of
@@ -159,7 +159,8 @@ applies to nodes: a stale node cannot verify or merge; inventory and child merge
159
159
  continue while it collects.
160
160
 
161
161
  Restack and reconcile publication reject tracked modifications with the existing
162
- clean-worktree error. Nonignored untracked files do not block publication and
162
+ clean-worktree error. Before a replay, preparation handles them as described in
163
+ [Tracked dirt before preparation](#tracked-dirt-before-preparation). Nonignored untracked files do not block publication and
163
164
  remain unpublished and untouched; each publication that encounters them records
164
165
  a path-bearing `observation.recorded` followup, deduplicated by operation,
165
166
  transaction, candidate SHA and exact path list on recovery. The phase-terminal
@@ -342,6 +343,45 @@ and `· N regenerated` or `· regeneration failed` to a node's restack lines.
342
343
  `ab watch --event 'restack.*'` or `--event 'node.item-*'` shows each outcome.
343
344
  Repositories that declare nothing restack exactly as before.
344
345
 
346
+ ## Tracked dirt before preparation
347
+
348
+ Uncommitted changes to tracked files, typically left by `[commands].setup` on
349
+ a relaunch, never strand a restack or reconcile preparation:
350
+
351
+ | Dirt | Outcome |
352
+ |---|---|
353
+ | Only declared `[[generated]]` paths | Restored to `HEAD`, one `followup` observation recorded, replay proceeds |
354
+ | Any undeclared path | Preparation refuses, touches nothing, raises `policy/dirty-worktree` naming the undeclared paths |
355
+
356
+ The same classification runs again just before a completed automatic replay
357
+ or an intended candidate publishes, so a relaunch or crash at any point of the
358
+ replay cannot reach publication with dirt. A fresh automatic restack and a
359
+ fresh epilogue reconcile check before
360
+ `restack.prepared` or `reconcile.started`, so a refusal freezes nothing and
361
+ spends no phase-failure budget. Answering the escalation with guidance or a
362
+ bare retry returns the build to `implement`:
363
+
364
+ - **Nothing frozen.** `implement` runs with the question, its paths and the
365
+ answer as feedback.
366
+ - **Frozen, no publish intent.** The kernel records `reconcile.superseded
367
+ {cause: dirty-worktree}`, returns a workspace the replay left detached to
368
+ the build branch with the changes intact, then runs `implement`. If the
369
+ target also changed a dirty file, so Git cannot carry it, the changes are
370
+ first set aside as artifact `dirty-worktree-<escalation>`, as below. The
371
+ abandoned restack is decided again from the new head.
372
+ - **Frozen, publish intent recorded.** The candidate settles first: the
373
+ undeclared changes are stored as artifact `dirty-worktree-<escalation>` (a
374
+ byte-exact binary patch, captured without textconv or external diff
375
+ drivers) with observation `dirty-worktree:<escalation>:set-aside`,
376
+ restored, and the frozen candidate publishes as recorded. The `implement`
377
+ feedback names the artifact and how to re-apply it. If the set-aside runs
378
+ again before the restore (after a stop, or when relaunch setup rewrote a
379
+ path), a changed tree is stored as a new artifact revision first; it keeps
380
+ every file an earlier revision held, so the latest revision is complete.
381
+
382
+ Autobuild never commits or discards undeclared changes on its own, and the
383
+ escalation never needs an abort.
384
+
345
385
  ## Foreign merges
346
386
 
347
387
  Before any replay or publication, inspect every merge's non-first-parent history,
@@ -101,10 +101,12 @@ Use the supported `vercel/sandbox/universal` image. Other managed images and
101
101
  custom VCR images are rejected. Autobuild remains stack-neutral. For Vercel,
102
102
  put repository-specific operating-system packages and machine-level tooling in
103
103
  the ordered `[workspace.config].provisioning` list. Each strict `{ name,
104
- command }` entry runs from the checkout through `sh -c` with provider root
105
- authority after pinned Bun is verified and before dependency bootstrap,
106
- `[commands].setup`, or an agent. It runs once per fresh environment and repeats
107
- on every replacement. Commands are declarative TOML string data, not evaluated
104
+ command, timeoutSeconds? }` entry runs from the checkout through `sh -c` with
105
+ provider root authority after pinned Bun is verified and before dependency
106
+ bootstrap, `[commands].setup`, or an agent. It runs once per fresh environment
107
+ and repeats on every replacement. A step runs under `timeoutSeconds` (default
108
+ 600, at most 840); one that fails reports its name, redacted command and
109
+ output tails, and one that overruns also reports its elapsed time. Commands are declarative TOML string data, not evaluated
108
110
  configuration logic. Local git worktrees never run this list; ensure their host
109
111
  already has required system tooling.
110
112
 
@@ -121,7 +123,14 @@ allowlist entry; their real credentials remain on the dispatcher host.
121
123
 
122
124
  Keep package-level and checkout-level bootstrap in an idempotent
123
125
  `[commands].setup`. It runs after system provisioning and must remain safe to
124
- rerun on attachment and after every restack onto a new base. Do not repeatedly install OS packages there. Expose only
126
+ rerun on attachment and after every restack onto a new base. It must not modify
127
+ tracked files: tracked paths it newly changes outside `[[generated]]` block the
128
+ build with `policy/dirty-worktree` before the next phase runs, naming the paths.
129
+ The check is skipped when that phase is a `reconcile`, whose resolver works on
130
+ its own in-progress replay, and while an answered dirty-worktree recovery is
131
+ pending. A restack or reconcile preparation still classifies any tracked dirt
132
+ before it replays. Declare tracked codegen outputs it rewrites in
133
+ `[[generated]]`; those are tolerated and discarded before any replay. Do not repeatedly install OS packages there. Expose only
125
134
  required runtime credentials through
126
135
  `[workspace.config].environmentVariables`, keep generated caches disposable,
127
136
  and lock dependencies in the repository. A browser-capable repository should
@@ -162,7 +171,7 @@ For Vercel it identifies and permanently deletes a fresh unnamed sandbox, even
162
171
  when system or runtime provisioning, setup, or a probe fails; cleanup failures
163
172
  name the environment for manual deletion. Its `system provisioning` check lists
164
173
  completed step names (or says none were declared) before guest setup checks. A
165
- failed step reports its name, command, status, labeled stdout/stderr, and
174
+ failed step reports its name, command, status or timeout, stderr/stdout tails, and
166
175
  remediation without marking the environment ready. It provisions/preflights
167
176
  every effective primary and alternate runtime, then runs `commands.setup`, loads
168
177
  repository plugins, and checks every
@@ -334,6 +334,10 @@ Read events with a cursor or a small `--events` count; logs are long.
334
334
  target was force-pushed while it had work of its own. It restacks the build's
335
335
  own commits onto the current target; abort is the alternative. A leaf with no
336
336
  work recovers from a rewritten target by itself and raises nothing.
337
+ A `dirty-worktree` escalation names tracked files changed outside
338
+ `[[generated]]`, usually by `[commands].setup`; answer with guidance or a bare
339
+ retry, never abort: the build returns to implement to commit, revert or
340
+ regenerate them.
337
341
  Idle collecting or verification-failed nodes need no escalation and recollect
338
342
  for verification on the same head; children and contributions remain intact.
339
343
  Active work, pause, pending controls and merge intent refuse revision. Leaves
@@ -510,11 +514,14 @@ operator tools. Which repository you act on depends on the connector:
510
514
 
511
515
  - **Per-repository connector** (a URL such as `<origin>/mcp/github.com/acme/widgets`,
512
516
  copied from the project's Settings tab): it serves that one repository. Its
513
- tools have no `repo` argument; do not add one, because a `repo` naming
514
- another repository is refused.
517
+ tools have no `repo` argument; do not add one, because any `repo`, even
518
+ naming that repository, is refused with code `repo-argument`.
515
519
  - **Deployment-wide connector** (`<origin>/mcp`): every tool requires `repo`.
516
520
  Call `repositories.list` to find the identities you can reach.
517
521
 
522
+ The argument is `repo`, never `repository`; a `repository` argument is
523
+ refused on both connectors.
524
+
518
525
  Either way, follow each advertised tool schema exactly.
519
526
 
520
527
  ### Load context first
@@ -587,7 +594,12 @@ Your tools are the operator registry. The read-only ones are always safe:
587
594
  - `repository.attention` — the attention digest: everything waiting on the
588
595
  operator, each item naming its resolving tool call. The first call of each
589
596
  round.
590
- - `builds.list` — active, queued, or all builds, with effective status.
597
+ - `builds.list` — active, queued, or all builds, with effective status. Scope
598
+ `merged` answers "what shipped": merged builds, most recently merged first,
599
+ each with `mergedAt`, `kind`, `ticket`, `pr` and the node `target` of a child
600
+ build. Narrow it with `since` (inclusive) and `until` (exclusive) instants
601
+ and page with `limit` and the returned `next` as `cursor`. Use `active` and
602
+ `queued` for what lands next.
591
603
  - `builds.get` — one build's detail.
592
604
  - `builds.events` — one build's event log from a cursor (use a cursor; logs
593
605
  are long).
@@ -885,6 +897,10 @@ waits, end the message with one line saying so, such as
885
897
  logical credentials, or records a reasoned `harvest.session.resume-fallback`
886
898
  and starts fresh. Orderly suspension spends no recovery attempt; real
887
899
  crashes retain recovery accounting.
900
+ A hosted harvest launch that is still preparing stops at its next boundary,
901
+ and teardown joins it before releasing the lease. A harvest that a
902
+ dispatcher launches never claims, renews or releases the repository lease
903
+ on its own behalf.
888
904
  - Human checkout dispatch defaults to viewer for hosted placement. Humans can use
889
905
  `--takeover` to dispatch locally with a displacement warning; unreadable placement
890
906
  fails closed and names `--viewer` and `--takeover` as explicit recovery choices.
@@ -1147,6 +1163,11 @@ started; priority-ordered admission and intake loops keep their order.
1147
1163
  deadline stopped. The same stage or part stopping at the deadline on
1148
1164
  invocation after invocation means one visit there outlasts the window: report
1149
1165
  it with those lines.
1166
+ The hosted store service logs one `autobuild.store-request` line per request
1167
+ naming its caller: dispatcher invocation, run and stage, build or harvest
1168
+ runner, or operator client (`cli`, `mcp`, `web`). For a store traffic burst or
1169
+ database pressure, report the callers and stages that dominate those lines;
1170
+ `caller: null` is an older client.
1150
1171
 
1151
1172
  Leaf restack and reconcile publication retry classified transient forge or transport
1152
1173
  failures six times after the initial attempt, waiting 30, 60, 120, 240, 300 and
@@ -4,8 +4,8 @@
4
4
  "build": "ab-hosted-service-build"
5
5
  },
6
6
  "dependencies": {
7
- "@defrex/autobuild-hosted-store-service": "1.16.0",
8
- "@defrex/autobuild": "1.16.0",
7
+ "@defrex/autobuild-hosted-store-service": "1.17.0",
8
+ "@defrex/autobuild": "1.17.0",
9
9
  "next": "16.1.6",
10
10
  "react": "19.2.4",
11
11
  "react-dom": "19.2.4"