@defrex/autobuild 0.12.0 → 0.14.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 (151) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +138 -16
  3. package/bin/ab-dispatch-kernel.ts +4 -6
  4. package/docs/architecture.md +155 -73
  5. package/docs/configuration.md +41 -9
  6. package/docs/hosted-service.md +31 -5
  7. package/docs/operator-api.md +8 -1
  8. package/docs/remote-store-protocol.md +94 -2
  9. package/docs/remote-ticket-protocol.md +151 -9
  10. package/docs/setup.md +33 -7
  11. package/docs/ticket-migration.md +64 -0
  12. package/package.json +4 -3
  13. package/packages/core/src/cli/attention.ts +18 -164
  14. package/packages/core/src/cli/build-control.ts +23 -16
  15. package/packages/core/src/cli/bulk-control.ts +3 -2
  16. package/packages/core/src/cli/connect.ts +141 -38
  17. package/packages/core/src/cli/context.ts +23 -79
  18. package/packages/core/src/cli/dashboard/model.ts +36 -22
  19. package/packages/core/src/cli/dashboard/poll.ts +1 -1
  20. package/packages/core/src/cli/dispatch-frontend.ts +24 -67
  21. package/packages/core/src/cli/dispatch-process.ts +14 -7
  22. package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
  23. package/packages/core/src/cli/dispatch.ts +304 -82
  24. package/packages/core/src/cli/dispatcher-liveness.ts +26 -19
  25. package/packages/core/src/cli/harvest.ts +84 -42
  26. package/packages/core/src/cli/help.ts +14 -8
  27. package/packages/core/src/cli/historical-build-state.ts +27 -0
  28. package/packages/core/src/cli/installation.ts +67 -13
  29. package/packages/core/src/cli/main.ts +23 -5
  30. package/packages/core/src/cli/mcp.ts +2 -1
  31. package/packages/core/src/cli/pr-attachments.ts +10 -13
  32. package/packages/core/src/cli/pr-summary-publication.ts +27 -60
  33. package/packages/core/src/cli/pr-summary.ts +43 -13
  34. package/packages/core/src/cli/publication-settlement.ts +10 -20
  35. package/packages/core/src/cli/repository-status.ts +38 -2
  36. package/packages/core/src/cli/self-update.ts +5 -1
  37. package/packages/core/src/cli/status.ts +62 -32
  38. package/packages/core/src/cli/terminals.ts +25 -142
  39. package/packages/core/src/cli/ticket-assets.ts +7 -2
  40. package/packages/core/src/cli/ticket-editor.ts +82 -0
  41. package/packages/core/src/cli/ticket.ts +166 -36
  42. package/packages/core/src/cli/wait.ts +91 -84
  43. package/packages/core/src/cli/watch.ts +60 -97
  44. package/packages/core/src/config/pipeline-source.ts +4 -3
  45. package/packages/core/src/config/schema.ts +35 -3
  46. package/packages/core/src/connection.ts +3 -3
  47. package/packages/core/src/events/catalog.ts +3 -2
  48. package/packages/core/src/events/payloads.ts +6 -0
  49. package/packages/core/src/events/repository.ts +7 -3
  50. package/packages/core/src/integration/harness.ts +38 -4
  51. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +2444 -9
  52. package/packages/core/src/kernel/auto-merge.ts +19 -3
  53. package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
  54. package/packages/core/src/kernel/generators/build-log.ts +1 -1
  55. package/packages/core/src/kernel/generators/repository-journals.ts +14 -3
  56. package/packages/core/src/kernel/harvest.ts +25 -23
  57. package/packages/core/src/kernel/incremental-fixtures.ts +13 -2
  58. package/packages/core/src/kernel/log-index-value.ts +38 -0
  59. package/packages/core/src/kernel/read-facts.ts +637 -0
  60. package/packages/core/src/kernel/reducer-registry.ts +139 -3
  61. package/packages/core/src/kernel/repository-attention.ts +179 -0
  62. package/packages/core/src/kernel/service-facts.ts +135 -0
  63. package/packages/core/src/kernel/terminal-guard.ts +133 -0
  64. package/packages/core/src/ontology.ts +1 -0
  65. package/packages/core/src/operator/annotations.ts +12 -0
  66. package/packages/core/src/operator/control.ts +5 -6
  67. package/packages/core/src/operator/index.ts +7 -0
  68. package/packages/core/src/operator/protocol.ts +19 -2
  69. package/packages/core/src/operator/query.ts +37 -20
  70. package/packages/core/src/operator/read-view.ts +4 -13
  71. package/packages/core/src/operator/registry.ts +61 -8
  72. package/packages/core/src/operator/requests.ts +2 -14
  73. package/packages/core/src/operator/sandbox.ts +10 -9
  74. package/packages/core/src/operator/ticket-source-backend.ts +17 -21
  75. package/packages/core/src/operator/tickets.ts +132 -22
  76. package/packages/core/src/plugin-sdk/index.ts +19 -0
  77. package/packages/core/src/plugins/runtimes.ts +5 -1
  78. package/packages/core/src/ports/runner/session-env.ts +2 -0
  79. package/packages/core/src/ports/tickets/contract.ts +66 -1
  80. package/packages/core/src/ports/tickets/create.ts +48 -12
  81. package/packages/core/src/ports/tickets/fake.ts +30 -1
  82. package/packages/core/src/ports/tickets/file-assets.ts +159 -0
  83. package/packages/core/src/ports/tickets/file-codec.ts +90 -0
  84. package/packages/core/src/ports/tickets/file.ts +114 -120
  85. package/packages/core/src/ports/tickets/grants.ts +47 -0
  86. package/packages/core/src/ports/tickets/hosted-index.ts +17 -0
  87. package/packages/core/src/ports/tickets/identity.ts +20 -0
  88. package/packages/core/src/ports/tickets/lifecycle.ts +18 -0
  89. package/packages/core/src/ports/tickets/linear.ts +74 -9
  90. package/packages/core/src/ports/tickets/migration.ts +336 -0
  91. package/packages/core/src/ports/tickets/operations.ts +38 -7
  92. package/packages/core/src/ports/tickets/portable-assets.ts +54 -0
  93. package/packages/core/src/ports/tickets/remote-protocol.ts +95 -0
  94. package/packages/core/src/ports/tickets/remote.ts +60 -3
  95. package/packages/core/src/ports/tickets/requested-id.ts +46 -0
  96. package/packages/core/src/ports/tickets/revision.ts +62 -0
  97. package/packages/core/src/ports/tickets/states.ts +61 -0
  98. package/packages/core/src/ports/types.ts +40 -3
  99. package/packages/core/src/ports/workspace/build-execution.ts +1 -0
  100. package/packages/core/src/ports/workspace/create.ts +5 -1
  101. package/packages/core/src/ports/workspace/operator-sandbox.ts +2 -0
  102. package/packages/core/src/ports/workspace/vercel-sandbox.ts +8 -4
  103. package/packages/core/src/processes/build-child.ts +6 -6
  104. package/packages/core/src/processes/build-runner.ts +62 -70
  105. package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
  106. package/packages/core/src/processes/dispatcher.ts +223 -205
  107. package/packages/core/src/processes/execution-no-progress.ts +176 -0
  108. package/packages/core/src/processes/harvest-child.ts +30 -4
  109. package/packages/core/src/processes/harvest-execution-state.ts +15 -9
  110. package/packages/core/src/processes/harvest-runner.ts +58 -74
  111. package/packages/core/src/processes/harvest.ts +72 -29
  112. package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
  113. package/packages/core/src/processes/orchestrator-tick.ts +2 -2
  114. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  115. package/packages/core/src/processes/publication-loss.ts +35 -21
  116. package/packages/core/src/processes/repo-view.ts +229 -1099
  117. package/packages/core/src/processes/tick-publication.ts +110 -0
  118. package/packages/core/src/store/adapter.ts +23 -0
  119. package/packages/core/src/store/build-scope.ts +17 -0
  120. package/packages/core/src/store/contract.ts +283 -1
  121. package/packages/core/src/store/local/schema.ts +1 -0
  122. package/packages/core/src/store/local/store.ts +180 -55
  123. package/packages/core/src/store/memory.ts +119 -29
  124. package/packages/core/src/store/phase-session.ts +17 -0
  125. package/packages/core/src/store/reduced-reads.ts +239 -0
  126. package/packages/core/src/store/reducer-value-shapes.json +14056 -0
  127. package/packages/core/src/store/reducer-value-validation.ts +96 -0
  128. package/packages/core/src/store/reducer-values.ts +145 -0
  129. package/packages/core/src/store/remote/client.ts +41 -0
  130. package/packages/core/src/store/remote/compatibility.ts +2 -0
  131. package/packages/core/src/store/remote/index.ts +19 -0
  132. package/packages/core/src/store/remote/protocol.ts +16 -0
  133. package/packages/core/src/store/remote/version.ts +3 -1
  134. package/packages/core/src/store/repo-state-events.ts +1 -1
  135. package/packages/core/src/store/repo-tick.ts +72 -0
  136. package/packages/core/src/store/session-handle.ts +19 -0
  137. package/packages/core/src/store/snapshots.ts +10 -0
  138. package/packages/core/src/store/ticket-asset-snapshots.ts +192 -0
  139. package/packages/core/src/store/ticket-assets.ts +86 -8
  140. package/packages/core/src/store/types.ts +40 -3
  141. package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
  142. package/packages/core/src/testing/index.ts +8 -0
  143. package/packages/core/src/testing/reduced-read-budget.ts +462 -0
  144. package/skills/guide/SKILL.md +97 -12
  145. package/skills/guide/references/operator-api.md +8 -1
  146. package/skills/guide/references/remote-store-protocol.md +94 -2
  147. package/skills/guide/references/remote-ticket-protocol.md +151 -9
  148. package/skills/guide/references/setup.md +33 -7
  149. package/skills/guide/references/ticket-migration.md +64 -0
  150. package/skills/tickets/SKILL.md +71 -0
  151. package/templates/hosted-service/package.json +2 -2
@@ -37,7 +37,7 @@ headers, or available backend.
37
37
  `[store] url` (in that precedence order, before the local default); the shipped client appends the routes below.
38
38
  - Every `/builds`, `/repos`, and `/sessions` request sends
39
39
  `X-Autobuild-Version` with the exact client package version and
40
- `X-Autobuild-Protocol-Version` with the remote protocol version (`3` in this
40
+ `X-Autobuild-Protocol-Version` with the remote protocol version (`4` in this
41
41
  distribution). Before authentication,
42
42
  body parsing, or resource lookup, the server validates the release-line window and known protocol identity.
43
43
  Unsupported or missing values receive `409 {"kind":"conflict","error":"…"}`;
@@ -355,6 +355,74 @@ part of this protocol. Retention is enforced server-side inside the store at
355
355
  deposit time (bounded pruning of dispatcher run/config artifact revisions),
356
356
  not through any endpoint.
357
357
 
358
+ ### Named reducer values
359
+
360
+ `POST /builds/{slug}/reducer-values` and
361
+ `POST /repos/{repo}/reducer-values` accept at most 4 KiB of JSON:
362
+
363
+ ```json
364
+ {"reducer":"dispatchStatus","args":{"run":"run-a"}}
365
+ ```
366
+
367
+ The response is `200 {"version":2,"cursor":123,"value":{...}}`. Only the
368
+ finished JSON answer is returned, with no accumulator or raw-log bundle. `cursor`
369
+ is the authoritative prefix included in the answer, not a guarantee to include
370
+ appends concurrent with the request. Every call checks durable progress and
371
+ persisted state; parallel instances may safely advance the same checkpoint.
372
+ Snapshots are disposable caches: deletion, corruption, wrong versions and
373
+ unreadable cache storage cause replay. Log read failures remain errors.
374
+
375
+ The executable catalog is `kernel/reducer-registry.ts`. All requests reject
376
+ unknown names, excluded reducers, wrong scopes and invalid/extra arguments with
377
+ `400 validation`. A missing resource is `404`, project and delegated authority
378
+ checks are the same as other reads, and unsupported methods remain unavailable.
379
+ The operation is read-only authority even though its HTTP verb is POST and its
380
+ internal cache may advance. It does not accept caller-supplied state. This is an
381
+ additive protocol route: historical snapshot and event handlers and the supported
382
+ client version window are unchanged.
383
+
384
+ | Scope | Reducers with no arguments |
385
+ | --- | --- |
386
+ | Build | `executionNoProgress`, `summaryRequests`, `build`, `buildDigest`, `currentPrAttachments`, `pendingPrAttachmentReclaims`, `openExecution`, `lastExecutionOutcome`, `infrastructureFailureReset`, `openWorkspace`, `setupStreak`, `openBuildWorkspace`, `currentDeferralObservation`, `dashboardFacts`, `pinnedAssets`, `buildDelegation` |
387
+ | Repository | `harvest`, `dispatchSettings`, `sandboxStates`, `openHarvestExecutions`, `autoMergeDefault`, `effectiveConfig`, `harvestDelegation` |
388
+
389
+ | Reducer | Scope | Required arguments |
390
+ | --- | --- | --- |
391
+ | `dispatchStatus`, `openTick` | Repository | `run`: nonempty string |
392
+ | `dispatchFailureBudget` | Build | `infrastructureOwnsWorkspace`: boolean |
393
+ | `phaseFailures` | Build | `phase`: valid phase name; `round`: nonnegative integer |
394
+
395
+ Arguments are canonicalized into the cache identity; variants never reuse one
396
+ another's accumulator. `effectiveConfig` returns an object with optional `run`
397
+ and `reference: {kind, rev}`. Absence is distinct from an unreadable referenced
398
+ artifact. Delegation values contain semantic lifecycle facts indexed by prefixed
399
+ identifiers, not authorization decisions; request time and grace expiry are
400
+ always evaluated against those facts on the service.
401
+
402
+ Each remaining registered reducer is explicitly excluded:
403
+
404
+ | Reducers | Reason |
405
+ | --- | --- |
406
+ | `journalView`, `repositoryStateEvents`, `dispatchFrontend` | Raw repository event lists |
407
+ | `session` | Operator-session log scope |
408
+ | `publicationState` | Selector functions in finished value |
409
+ | `logIndex` | Maps and Sets in finished value |
410
+ | `hostedPrAttachments` | Map as finished value |
411
+ | `summaryBoundary`, `ticketSourceHealth`, `frozenPrImageHost`, `publishedBranchHead`, `verifyDiffBase`, `recordedBaseSha`, `baseBranch`, `provisionMarker`, `recoveryCheckpoint` | Existing finished contract can return top-level `undefined`, which is not JSON |
412
+
413
+ `GET /repos/{repo}/state-events` is **deprecated**. Its response remains unchanged
414
+ for supported clients, including the current dispatcher run's event tail. It is
415
+ the compatibility exception to flat event-row reads; new callers should request
416
+ named values. The current product no longer loads or writes raw-tail snapshots.
417
+
418
+ The `value.*` snapshot namespace is reserved for the adapter's private value
419
+ checkpoint hooks. Public snapshot GET and PUT requests for this prefix return
420
+ `400 validation`, including requests made with delegated or administrator
421
+ credentials. Adapter snapshot APIs reject the same names. Ordinary snapshot
422
+ names retain their existing behavior. The value cache key format is versioned;
423
+ checkpoints from the former publicly writable format are ignored and rebuilt
424
+ from the log after upgrading.
425
+
358
426
  ### Reducer snapshots
359
427
 
360
428
  A reducer snapshot is one registered reducer's serialized state as of a log
@@ -485,6 +553,16 @@ does not apply. `{repo}` and `{id}` are percent-encoded path segments. Token
485
553
  authorization requires a credential for that registered project, or owner admin.
486
554
  The family is additive, so `REMOTE_STORE_PROTOCOL_VERSION` did not change.
487
555
 
556
+ Hosted ticket attachments use the ticket service's existing repository-keyed
557
+ asset routes with the ticket connection's URL and credential, independently
558
+ of the build store. Names, revisions, tombstones and service limits are
559
+ unchanged. Existing service attachments need no migration; old local
560
+ attachments are not moved or used as a fallback. A claim or ticket spec re-pin
561
+ copies exact revisions into immutable chunked repository artifacts in the
562
+ destination build store. Build pins reference explicit snapshot manifests;
563
+ build-scoped asset reads need no ticket credentials. Old pins without snapshot
564
+ references keep their existing ticket-row lookup.
565
+
488
566
  A build also reads the assets it froze at its claim through its own build-scoped
489
567
  routes, authorized against the build's actual project. The
490
568
  server reduces the build's events to find the pinned revision, then returns that
@@ -1126,7 +1204,7 @@ Four shipped behaviors do not add `BuildStore` routes:
1126
1204
  store lifecycle; there is no close endpoint.
1127
1205
  - `GET /health` is outside the `BuildStore` interface. It is always open and
1128
1206
  returns exactly `200 {"ok":true,"autobuildVersion":"<package>",
1129
- "protocolVersion":"3", "supportedClientRange":{"minVersion":"0.9.0",
1207
+ "protocolVersion":"4", "supportedClientRange":{"minVersion":"0.9.0",
1130
1208
  "maxVersionExclusive":"0.12.0"}}`. It reports HTTP-process availability and identity,
1131
1209
  not a deeper backing-store transaction or migration check.
1132
1210
 
@@ -1203,3 +1281,17 @@ require a project credential and operate only on its own identity; admin and
1203
1281
  internal operator credentials cannot impersonate self-service. All protocol
1204
1282
  responses are no-store/no-referrer. Connection commands are unavailable in
1205
1283
  build/harvest sessions.
1284
+
1285
+ ### Repository tick telemetry (protocol 4)
1286
+
1287
+ `POST /repos/:repo/tick/begin` accepts `{holder}` and returns the actual start
1288
+ timestamp, or null when the unexpired repository lease does not match.
1289
+ `POST /repos/:repo/tick/finish` accepts `{holder, completion, events}`. Completion
1290
+ is `{outcome:"completed", counters}` or `{outcome:"failed", error}`; events is
1291
+ empty for a quiet success or a matching dispatcher start/terminal pair for that
1292
+ holder. The validated batch and finished telemetry commit atomically. The reply
1293
+ is `{observation, events}` with assigned envelopes, or null on fencing failure.
1294
+ These operations never renew the lease. Repository records optionally expose
1295
+ `tick: {run, open?: {startedAt}, finished?: {run, startedAt, completedAt, ...completion}}`.
1296
+ They retain the previous completion while a new tick is open and after lease
1297
+ release. Build and session credentials cannot mutate repository ticks.
@@ -67,6 +67,16 @@ must match the credential's project; mismatches are 403. Owner admin requests
67
67
  require this selector and registration is checked before configuration is read.
68
68
  Internal operator credentials remain forbidden on machine ticket routes.
69
69
 
70
+ Hosted ticket attachments use the ticket service's existing repository-keyed
71
+ asset routes with the ticket connection's URL and credential, independently
72
+ of the build store. Names, revisions, tombstones and service limits are
73
+ unchanged. Existing service attachments need no migration; old local
74
+ attachments are not moved or used as a fallback. A claim or ticket spec re-pin
75
+ copies exact revisions into immutable chunked repository artifacts in the
76
+ destination build store. Build pins reference explicit snapshot manifests;
77
+ build-scoped asset reads need no ticket credentials. Old pins without snapshot
78
+ references keep their existing ticket-row lookup.
79
+
70
80
  The strict request envelope is:
71
81
 
72
82
  ```json
@@ -82,16 +92,37 @@ The strict request envelope is:
82
92
 
83
93
  `teamKey` remains required for older client compatibility. It and the optional
84
94
  `claimedState` / `createState` fields are ignored as policy inputs. The service
85
- loads the project's latest effective configuration from its repository journal
86
- and artifact bytes for every operation. Missing or invalid configuration returns
87
- an actionable 409; run the project's dispatcher to publish its configuration.
88
- There is no deployment-wide lifecycle fallback.
95
+ loads the project's durable independent ticket policy. Project authority publishes
96
+ version 1 policy through `POST /tickets/policy`, using the usual context/input
97
+ envelope. The input contains only `version` and `tickets`: source, teamKey,
98
+ readyState, triageState, claimedState, doneState, createState, proposalState and
99
+ optional readyLabels. URL, secrets, and pipeline configuration are rejected.
100
+ Only project or owner authority can publish. This does not append BuildStore
101
+ history. Registration removal invalidates policy and grants from that registration.
102
+
103
+ For compatibility, projects without independent policy use their latest uploaded
104
+ dispatcher configuration with the old `Backlog`, `Doing`, `Done` defaults.
105
+ New policy defaults are `triage`, `ready`, `doing`, `done`; create/proposal follow
106
+ triage. States are persistent project data, including empty states and optional
107
+ one-line purposes. Configured role names always exist; removed roles remain as
108
+ custom states and keep their tickets. Explicit settings preserve state spelling.
109
+ State lookup prefers an exact match, then a unique case-insensitive match;
110
+ unknown or ambiguous names are refused. Lists order configured triage, ready,
111
+ doing, done first (deduplicated), then other names alphabetically.
112
+
113
+ `[tickets] url` selects the ticket service independently of the build store;
114
+ otherwise the selected remote build store is used. A local build store requires
115
+ an explicit ticket URL. Credentials are resolved for that selected service.
116
+ `ab connect --tickets URL` registers and publishes policy before any dispatcher run.
89
117
 
90
- Hosted lifecycle defaults are triage `Backlog`, claimed `Doing`, done `Done`,
91
- and create/proposal equal to triage. `readyState` is required. The allowed states
92
- are the distinct union of these configured roles, including custom create and
93
- proposal states; roles may overlap. Historical states remain readable unchanged.
94
- `tickets.doneState` controls completion and the dispatcher's merged transition.
118
+ `POST /tickets/grants` issues, renews or revokes short-lived, digest-stored ticket
119
+ grants. Project authority issues runner grants scoped to project and execution;
120
+ runners may issue only read-only phase children bound to themselves. Runner grants
121
+ allow read and create; phase grants allow read only. Policy, claim, moves, comments,
122
+ updates, blocker changes, BuildStore, and credential administration are denied.
123
+ AB_TICKET_URL and AB_TICKET_TOKEN carry this authority separately from AB_STORE and
124
+ AB_TOKEN. Revocation, expiry, parent revocation and registration changes invalidate
125
+ grants. Existing combined-service BuildStore delegation remains supported.
95
126
 
96
127
  The service never contacts Linear or relays external trackers. If the project's
97
128
  source is Linear, file or another non-hosted source, machine HTTP, operator and
@@ -111,6 +142,8 @@ The operation names and `input` values are:
111
142
 
112
143
  | Operation | Input | Successful response |
113
144
  |---|---|---|
145
+ | `states` | `{}` | `{name, tickets, about?}[]`, including empty states |
146
+ | `add-state` | `{name, about?: string}` | `{state: {name,tickets,about?}, created: boolean}` |
114
147
  | `list-ready` | `{labels?: string[], state?: string}` | `TicketListing` |
115
148
  | `get` | `{id}` | `Ticket \| null` |
116
149
  | `claim` | `{id}` | `{claimed: boolean}` |
@@ -132,6 +165,35 @@ Ticket body strings are opaque. Clients, JSON handling, the service, and the
132
165
  database backend must not trim or normalize bytes, newlines, Unicode, blank
133
166
  lines, or trailing whitespace.
134
167
 
168
+ ## Readable ticket identity
169
+
170
+ New hosted tickets use `<teamKey>-<n>`, for example `ENG-1`. The effective
171
+ project configuration supplies the literal prefix; the request's `teamKey`
172
+ does not choose it. Numbers start at 1 in each project, increase atomically
173
+ across concurrent creates, and are never reused after deletion. Projects sharing
174
+ a team key have independent counters. Changing `teamKey` affects only future
175
+ ids and continues the same numbering; existing ids retain their captured prefix.
176
+
177
+ Every ticket operation, CLI command, MCP tool and blocker input accepts readable
178
+ ids in any letter case. Legacy storage ids (such as `ticket-<uuid>`) remain
179
+ aliases, including references in existing builds, harvest records and assets.
180
+ Current ticket and blocker output uses the canonical readable id. The exception
181
+ is `dependency-states`: each result's `id` echoes the requested id for correlation,
182
+ while its `blockedBy` edges are canonical. Raw historical events and artifacts
183
+ remain unchanged. These rules apply only to hosted tickets, not file or Linear ids.
184
+
185
+ Upgrade the service with its environment-aware migration command before serving
186
+ requests. The transactional migration preserves storage keys and assigns existing
187
+ tickets numbers in `(created_at, id)` order within each project. It first resolves
188
+ legacy team ownership, then reads each populated project's current independent
189
+ ticket policy. Projects without that policy use their selected effective
190
+ configuration through the configured blob backend. Independent-policy projects
191
+ need no uploaded config or blob access. Missing or invalid fallback config,
192
+ missing `teamKey`, or inaccessible required blobs abort the entire migration
193
+ unchanged with a project diagnostic. Restore that config/blob access and rerun;
194
+ an ownership assignment alone cannot supply a readable prefix. Empty projects
195
+ need no config lookup. Re-running a completed migration does not renumber tickets.
196
+
135
197
  ## Errors and conformance
136
198
 
137
199
  Errors are JSON `{ "error": string, "kind": "validation" | "not-found" |
@@ -170,3 +232,83 @@ project removal are also checked before parsing or source construction.
170
232
 
171
233
  Ticket admission and assets use the authenticated project, including for
172
234
  delegated harvest grants.
235
+
236
+ Custom state creation uses `/^[a-z][a-z0-9-]{0,39}$/`; an optional purpose must
237
+ be one nonblank line. A duplicate in any letter case is refused without
238
+ changing purpose. `add-state` requires project or owner machine authority;
239
+ ticket grants and harvest delegations can read states but cannot create them.
240
+ Request context cannot supply lifecycle policy or insert another project's
241
+ states. These operations use the existing wire version and strict envelopes.
242
+
243
+ ## Revision-checked ticket writes
244
+
245
+ Every ticket read includes an opaque `revision`. Pass it as `expectedRevision`
246
+ (on MCP/operator requests) or `--expected-revision <opaque>` on `ab ticket update`,
247
+ `move`, `block` and `unblock`. A stale write fails without changing anything and
248
+ reports the current revision. Omission preserves unguarded behavior. Blocker
249
+ checks cover the entire batch. Dispatcher moves remain unguarded and change the
250
+ revision. Sources without guarded writes, including Linear, refuse supplied
251
+ revisions rather than ignoring them.
252
+
253
+ `ab ticket edit <id>` opens `$VISUAL`, falling back to `$EDITOR`, using TOML
254
+ frontmatter and a Markdown body. Only title, body and labels are editable;
255
+ id, blockers, creation key and reference comments are read-only. It saves only
256
+ changed fields with the opening revision. Unchanged or formatting-only edits
257
+ write nothing. On conflict, invalid input or editor failure, the error names an
258
+ absolute file path containing the edited text. Read the current ticket and
259
+ reapply the intended changes before retrying; conflicts are never merged.
260
+
261
+ File and Linear revisions fingerprint title, body, canonical label/blocker sets
262
+ and state; reverting identical content restores its fingerprint. File checks
263
+ re-read immediately before writing, with the existing no-lock race window.
264
+ Direct file edits and state-directory moves change revisions. File revisions also
265
+ cover structured comments and portable attachments. Legacy file comments change
266
+ the body; structured comments preserve it. Separate hosted comments do not change
267
+ ticket revisions. Hosted revisions
268
+ are monotonic decimal bigint strings, and checks run under the same row lock
269
+ and transaction as all requested changes. Hosted reads return a coherent
270
+ snapshot of fields, blockers and revision.
271
+
272
+ ### Guarded mutation transport
273
+
274
+ `POST /tickets/mutate-if-revision` accepts the usual authenticated context and
275
+ `input: { id, expectedRevision, mutation }`. Mutation is one of
276
+ `{ kind: "update", patch: { title?, body?, labels? } }`,
277
+ `{ kind: "transition", state }`, or
278
+ `{ kind: "blockers", operation: "block" | "unblock", ids: string[] }`.
279
+ Unknown keys and empty patches are refused. Success returns `{ ok: true }`.
280
+ A revision conflict returns HTTP 409 with `kind: "conflict"`, `error`, `id`,
281
+ `expectedRevision` and `currentRevision`. Delegated credentials retain existing
282
+ permissions: none of the guarded mutation variants grants additional access.
283
+ Ticket responses include `revision` only when the request advertises
284
+ `x-autobuild-ticket-revisions: 1`. The current hosted client sends this header
285
+ on every request and requires revision-bearing responses. Released clients
286
+ through 0.12.x omit the header and retain their strict decoder's original
287
+ response shape on get, list-ready and create. This explicit capability also
288
+ supports new source checkouts that still report version 0.12.0; version alone
289
+ cannot distinguish them from released clients. Unknown capability values do
290
+ not opt in. Clients before 0.11 also omit the existing resolution projections.
291
+ The capability does not change authentication, authorization or the remote
292
+ BuildStore protocol version.
293
+
294
+ ## Requested ids for migration
295
+
296
+ Create options accept optional `requestedId: string` alongside `state` and
297
+ `idempotencyKey`. Older clients omit it and responses are unchanged. Unsupported
298
+ sources reject supplied ids; Linear is not an import target. File sources keep
299
+ filesystem-safe ids exactly and never overwrite an occupied id.
300
+
301
+ Hosted sources preserve only literal own-team `<teamKey>-<n>` ids, where `n` is a
302
+ positive canonical decimal within PostgreSQL bigint bounds. For example,
303
+ `AUT-706` in team `AUT` keeps 706; `OTHER-706`, `AUT-01` and `AUT-0` use ordinary
304
+ allocation. Overflow canonical numbers are rejected. A matching creation key is
305
+ adopted before occupancy checks. A kept number belonging to a different ticket
306
+ fails without replacing it. Creation and counter advancement share the existing
307
+ project transaction and counter lock. Later automatic numbers exceed both the
308
+ counter and highest occupied number; importing a lower number never lowers the
309
+ counter. Requested ids require project or owner authority. Ticket grants and
310
+ delegated credentials receive 403 for create options containing `requestedId`,
311
+ before source construction. Their ordinary create grants remain unchanged.
312
+
313
+ See the [migration procedure](ticket-migration.md) for preflight, state mapping,
314
+ resumption and portable file records.
@@ -398,13 +398,13 @@ the verifier does not fix it.
398
398
  ### Project-scoped hosted tickets
399
399
 
400
400
  Hosted ticket queues belong to the credential's registered repository, even
401
- when projects share a team key. The latest uploaded effective `[tickets]`
402
- configuration owns lifecycle: hosted defaults are Backlog / Doing / Done,
403
- `readyState` is required, `doneState` customizes completion, and create/proposal
404
- default to triage. The union of configured roles is allowed; roles may overlap.
405
- Owner admin requests require an explicit registered `context.repo`; project
406
- credentials cannot select another project. Missing effective configuration is
407
- an actionable refusal: run the project's dispatcher to publish it.
401
+ when projects share a team key. Independent project ticket policy owns lifecycle:
402
+ new defaults are triage / ready / doing / done, with create/proposal following
403
+ triage. Explicit names retain their spelling; doneState customizes completion.
404
+ `ab connect --tickets URL` publishes policy before dispatch. Older clients without
405
+ independent policy retain their uploaded dispatcher configuration and legacy defaults.
406
+ Owner admin requests require an explicit registered context.repo; project credentials
407
+ cannot select another project. See [local builds with hosted tickets](#local-builds-with-hosted-tickets).
408
408
 
409
409
  The service never contacts Linear. Projects with external sources (including
410
410
  file and Linear) keep using those sources directly through their dispatcher;
@@ -447,3 +447,29 @@ require the running service's blob backend, access mode, credentials and prefix
447
447
  (`AB_BLOB_PREFIX`), not just PostgreSQL access. `deploy:build` inherits this
448
448
  environment and migration failure stops Next build. Fresh databases, empty v1
449
449
  queues and v2 reruns stay SQL-only and do not initialize blob storage.
450
+
451
+ ## Local builds with hosted tickets
452
+
453
+ Hosted tickets do not require hosted builds. Set `[tickets] source = "hosted"`
454
+ and `teamKey = "ENG"`, then run `ab connect --tickets https://your-service.example`.
455
+ Approve the project in the browser. This saves a service-scoped credential and
456
+ `[tickets] url` while leaving `[store]` unchanged. Ticket commands work immediately,
457
+ before any dispatcher runs. `ab connect` reports every service and whether it serves
458
+ builds, tickets, or both. Use `ab disconnect --tickets` to revoke ticket access;
459
+ when services differ use `--builds` to select build access. Shared uses share one
460
+ credential, so disconnecting either shared use affects both.
461
+
462
+ Ticket URL selection is `[tickets] url`, then the selected build service (including
463
+ AB_STORE or a supported --store override). With local builds, `[tickets] url` is
464
+ required. Builds, events, artifacts, and harvest journals remain in the local store.
465
+ The service stores ticket records, project ticket policy, and restricted ticket
466
+ grants. Normal project clients synchronize current `[tickets]` policy before use;
467
+ failed synchronization fails the operation. Harvest grants can read and create;
468
+ phase grants can only read. Neither can change policy or access BuildStore routes.
469
+
470
+ New hosted policy defaults to `triage`, `ready`, `doing`, `done`, with creation and
471
+ harvest proposals in `triage`. Explicit state names preserve their spelling.
472
+ To retain earlier names configure `triageState = "Backlog"`,
473
+ `claimedState = "Doing"`, `doneState = "Done"`, and the desired `readyState`.
474
+ Existing ticket rows are never renamed. Older combined-service clients continue
475
+ using the uploaded dispatcher configuration until independent policy is published.
@@ -0,0 +1,64 @@
1
+ # Moving a project between ticket sources
2
+
3
+ Export and import use the ordinary file ticket layout. They operate on tickets
4
+ and current attachments through the ticket source; neither command contacts the
5
+ forge. File and hosted sources support import. Linear supports export only.
6
+
7
+ 1. Pause intake and stop other ticket writers for the cutover. Import preflight
8
+ does not reserve numbers against concurrent writers.
9
+ 2. With the old `[tickets]` configuration, run `ab ticket export /path/to/export`.
10
+ The destination must be absent or empty. Export reads every state, including
11
+ archived Linear tickets and empty discoverable states, and publishes the
12
+ directory only after all reads succeed. Back up the target tracker too.
13
+ 3. Configure the new `[tickets]` source, or use `ab connect --tickets URL` for a
14
+ hosted ticket service. Keep the export directory intact.
15
+ 4. Run `ab ticket import /path/to/export`. Inspect its printed ticket and state
16
+ mappings and `/path/to/export/.ab-import-map.json`.
17
+ 5. Inspect ticket bodies, labels, blockers, comments and attachments in the new
18
+ source. Confirm lifecycle configuration and the ready gate, then resume intake.
19
+
20
+ Both commands also accept
21
+ `--store <ref>` to reach legacy BuildStore attachments. Keep the old store available
22
+ through export when file or Linear tickets have attachments there.
23
+
24
+ State directory names use lowercase letters, digits and hyphens, start with a
25
+ letter and contain at most forty characters. Export maps `In Progress` to
26
+ `in-progress`, `Backlog` to `backlog`, and `Done` to `done`. It retains each ticket's
27
+ state rather than assigning lifecycle roles. Distinct names that collapse to the
28
+ same directory fail before publication. The hidden `.ab-migration.json` records
29
+ original display names and the state map. Import also accepts ordinary legacy
30
+ file layouts: it reuses exact or unique case-insensitive target states before
31
+ normalizing new names. A seeded `done` satisfies `Done`; absent `In Progress`
32
+ creates `in-progress`. Ambiguous matches and colliding state maps fail preflight.
33
+
34
+ File targets retain source ids. Hosted targets keep canonical own-team ids:
35
+ `AUT-706` imported into team `AUT` stays `AUT-706`. Other ids receive numbers above
36
+ all existing and preserved incoming numbers. Known clashes with unrelated tickets
37
+ are reported together before any target state, ticket, comment or asset write.
38
+ Content similarity and stale mapping files never establish identity.
39
+
40
+ Creation keys establish identity. Exports retain existing keys and assign keys to
41
+ legacy tickets. Importing an ordinary file layout first saves a hidden migration
42
+ identity and keys in that input directory. Preserve this file and the input across
43
+ retries. After interruption, rerun the same command: committed creates are adopted
44
+ by key even if their mapping write failed. Adopted bodies and other fields are not
45
+ overwritten. Missing blockers and comments are replayed, and unchanged attachments
46
+ do not create another revision. Comments are deduplicated by exact body, so two
47
+ identical source comment bodies produce one target comment. Original authors and
48
+ timestamps remain in the export; imported comments use the target's metadata.
49
+
50
+ Portable records use TOML frontmatter between `+++` fences and an unchanged
51
+ Markdown body. Alongside `id`, `title`, `labels`, `blockedBy` and `idempotencyKey`,
52
+ optional `comments` contain `body`, `createdAt` and optional `author`. Optional
53
+ `attachments` contain `kind`, `name`, `layout` (`file` or `tree`) and `entries`:
54
+ `{ type = "dir", path = "empty" }` or
55
+ `{ type = "file", path = "image.png", base64 = "…" }`. Common asset limits and
56
+ path validators apply. Only current attachment contents travel, including binary
57
+ files and empty directories; historical revisions do not. The exported directory
58
+ works directly as a file source, without its migration manifest or original store.
59
+ File source revision history stays in its hidden `.ab-assets` directory.
60
+
61
+ Legacy records without `comments` retain their Markdown comment append behavior;
62
+ export never interprets Markdown headings as structured history. New file tickets
63
+ use structured comments and preserve their body when a comment is added. There is
64
+ no continuous sync, assignee migration, state history or build-history migration.
@@ -9,6 +9,16 @@ The local ticket tracker is a directory of markdown files. `ls` and `mv` are
9
9
  the state/backlog UI; source-agnostic `ab ticket` commands create and edit
10
10
  content and blocker relationships. The default file source needs no secret.
11
11
 
12
+ ## Hosted ticket ids
13
+
14
+ When `[tickets].source = "hosted"`, use readable ids such as `ENG-12` with
15
+ `ab ticket show`, `update`, `move`, `block`, and `unblock`. Inputs accept any
16
+ letter case and old UUID ids remain aliases. Output shows canonical readable
17
+ ids; blocker references use the same identity. Numbering belongs to each project
18
+ and never resets or reuses deleted numbers. A `teamKey` change affects future
19
+ prefixes only. File and Linear id rules are unchanged. See the
20
+ [hosted ticket protocol](../ab-guide/references/remote-ticket-protocol.md).
21
+
12
22
  ## Where it lives
13
23
 
14
24
  `.autobuild/tickets/` by default (if `autobuild.toml` has a `[tickets] dir`,
@@ -189,3 +199,64 @@ the state directories) are file-tracker-only. If this repo's
189
199
  guidance: state and labels live in Linear. The source-agnostic `ab ticket block`
190
200
  and `ab ticket unblock` commands still edit blocker relationships through the
191
201
  configured source.
202
+
203
+ ## Hosted ticket states
204
+
205
+ For `[tickets].source = "hosted"`, states are project-owned service data.
206
+ Run `ab ticket states` before creating a state, and reuse an existing purpose
207
+ when it fits. `ab ticket state create icebox --about "Deferred work"` creates
208
+ an empty state with an optional one-line, nonblank purpose. Custom names use
209
+ one to forty lowercase letters, digits, or hyphens, starting with a letter.
210
+ Hosted creation refuses an existing name in any letter case and never replaces
211
+ its purpose; file creation remains idempotent and can update the purpose.
212
+
213
+ Use `ab ticket create --state <name>`, `ab ticket move <id> <name>`, and
214
+ `ab ticket list --state <name>` with any existing state. Unknown states are
215
+ refused with the available names. Configured states are added automatically;
216
+ former configuration roles remain custom states with their tickets intact.
217
+ Listing puts the configured triage, ready, doing, and done roles first, then
218
+ other states alphabetically, including empty states and purposes. Configured
219
+ names keep their spelling; lookup prefers an exact match, then a unique
220
+ case-insensitive match. States belong to one project.
221
+
222
+ The directory `ls` and `mv` instructions above apply only to the file source.
223
+ For MCP, use `tickets.states` and `tickets.state.create`; the latter requires
224
+ an attributed operator identity and normal project authorization.
225
+
226
+ ## Revision-checked ticket writes
227
+
228
+ Every ticket read includes an opaque `revision`. Pass it as `expectedRevision`
229
+ (on MCP/operator requests) or `--expected-revision <opaque>` on `ab ticket update`,
230
+ `move`, `block` and `unblock`. A stale write fails without changing anything and
231
+ reports the current revision. Omission preserves unguarded behavior. Blocker
232
+ checks cover the entire batch. Dispatcher moves remain unguarded and change the
233
+ revision. Sources without guarded writes, including Linear, refuse supplied
234
+ revisions rather than ignoring them.
235
+
236
+ `ab ticket edit <id>` opens `$VISUAL`, falling back to `$EDITOR`, using TOML
237
+ frontmatter and a Markdown body. Only title, body and labels are editable;
238
+ id, blockers, creation key and reference comments are read-only. It saves only
239
+ changed fields with the opening revision. Unchanged or formatting-only edits
240
+ write nothing. On conflict, invalid input or editor failure, the error names an
241
+ absolute file path containing the edited text. Read the current ticket and
242
+ reapply the intended changes before retrying; conflicts are never merged.
243
+
244
+ File and Linear revisions fingerprint title, body, canonical label/blocker sets
245
+ and state; reverting identical content restores its fingerprint. File checks
246
+ re-read immediately before writing, with the existing no-lock race window.
247
+ Direct file edits and state-directory moves change revisions. File comments
248
+ change the body and revision; separate hosted comments do not. Hosted revisions
249
+ are monotonic decimal bigint strings, and checks run under the same row lock
250
+ and transaction as all requested changes. Hosted reads return a coherent
251
+ snapshot of fields, blockers and revision.
252
+
253
+ Read before writing, and copy the opaque revision verbatim:
254
+
255
+ ```sh
256
+ ab ticket show AUT-8 --json
257
+ ab ticket update AUT-8 --title 'Revised title' --expected-revision '<revision from show>'
258
+ ab ticket edit AUT-8
259
+ ```
260
+
261
+ Use `expectedRevision` on MCP `tickets.update`, `tickets.move`, `tickets.block`
262
+ and `tickets.unblock` with the revision from `tickets.get` or `tickets.list`.
@@ -4,8 +4,8 @@
4
4
  "build": "ab-hosted-service-build"
5
5
  },
6
6
  "dependencies": {
7
- "@defrex/autobuild-hosted-store-service": "0.12.0",
8
- "@defrex/autobuild": "0.12.0",
7
+ "@defrex/autobuild-hosted-store-service": "0.14.0",
8
+ "@defrex/autobuild": "0.14.0",
9
9
  "next": "16.1.6",
10
10
  "react": "19.2.4",
11
11
  "react-dom": "19.2.4"