@defrex/autobuild 1.11.1 → 1.13.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 (213) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +601 -203
  3. package/bin/ab-build-runner.ts +8 -0
  4. package/docs/answering-blocked-builds.md +32 -2
  5. package/docs/architecture.md +188 -57
  6. package/docs/assets/headline-wide.png +0 -0
  7. package/docs/cli.md +1 -1
  8. package/docs/configuration.md +120 -23
  9. package/docs/dispatcher.md +19 -8
  10. package/docs/integration-overview.md +1 -1
  11. package/docs/integration-tree.md +33 -18
  12. package/docs/merge-policy.md +7 -2
  13. package/docs/operating.md +5 -3
  14. package/docs/operator-api.md +48 -25
  15. package/docs/operator-surfaces.md +39 -3
  16. package/docs/optimization-nodes.md +10 -8
  17. package/docs/plugin-authoring.md +46 -18
  18. package/docs/remote-store-protocol.md +51 -12
  19. package/docs/remote-ticket-protocol.md +85 -38
  20. package/docs/restacking.md +48 -3
  21. package/docs/setup.md +2 -1
  22. package/docs/ticket-migration.md +2 -2
  23. package/docs/ticket-sources.md +23 -8
  24. package/docs/tickets.md +4 -4
  25. package/docs/troubleshooting.md +17 -2
  26. package/docs/verification.md +3 -1
  27. package/package.json +3 -3
  28. package/packages/core/src/cli/ambient-errors.ts +17 -0
  29. package/packages/core/src/cli/bounded-io.ts +174 -0
  30. package/packages/core/src/cli/build-control.ts +72 -6
  31. package/packages/core/src/cli/dashboard/actions.ts +4 -0
  32. package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
  33. package/packages/core/src/cli/dashboard/model.ts +93 -29
  34. package/packages/core/src/cli/dashboard/poll.ts +231 -34
  35. package/packages/core/src/cli/dashboard/queue.ts +21 -10
  36. package/packages/core/src/cli/dashboard/render.ts +14 -37
  37. package/packages/core/src/cli/dashboard/row-text.ts +26 -8
  38. package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
  39. package/packages/core/src/cli/dashboard/vocabulary.ts +165 -20
  40. package/packages/core/src/cli/dispatch-frontend.ts +2 -1
  41. package/packages/core/src/cli/dispatch-handoff.ts +41 -10
  42. package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
  43. package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
  44. package/packages/core/src/cli/dispatch-launcher.ts +9 -10
  45. package/packages/core/src/cli/dispatch-preflight.ts +12 -3
  46. package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
  47. package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
  48. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
  49. package/packages/core/src/cli/dispatch-tickets.ts +33 -12
  50. package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
  51. package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
  52. package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
  53. package/packages/core/src/cli/dispatch.ts +595 -149
  54. package/packages/core/src/cli/env.ts +2 -15
  55. package/packages/core/src/cli/help.ts +43 -28
  56. package/packages/core/src/cli/main.ts +11 -7
  57. package/packages/core/src/cli/production-store.ts +102 -0
  58. package/packages/core/src/cli/publication-settlement.ts +4 -0
  59. package/packages/core/src/cli/remote-poll.ts +22 -5
  60. package/packages/core/src/cli/repo-state.ts +2 -3
  61. package/packages/core/src/cli/repository-status.ts +44 -28
  62. package/packages/core/src/cli/sessionless-store.ts +26 -0
  63. package/packages/core/src/cli/status.ts +188 -47
  64. package/packages/core/src/cli/store-opening.ts +26 -57
  65. package/packages/core/src/cli/store-ref.ts +6 -1
  66. package/packages/core/src/cli/ticket-start.ts +3 -3
  67. package/packages/core/src/cli/ticket.ts +12 -11
  68. package/packages/core/src/cli/wait.ts +8 -28
  69. package/packages/core/src/cli/watch.ts +113 -50
  70. package/packages/core/src/config/reference-metadata.ts +7 -1
  71. package/packages/core/src/config/reference.ts +5 -2
  72. package/packages/core/src/config/schema.ts +51 -16
  73. package/packages/core/src/distribution-packaging.ts +156 -18
  74. package/packages/core/src/events/catalog-identity.ts +28 -0
  75. package/packages/core/src/events/catalog.ts +3 -9
  76. package/packages/core/src/events/compatibility.ts +2 -30
  77. package/packages/core/src/events/payloads.ts +85 -14
  78. package/packages/core/src/events/policy.ts +3 -0
  79. package/packages/core/src/events/repository.ts +15 -4
  80. package/packages/core/src/events/sessions.ts +1 -1
  81. package/packages/core/src/events/validation-error.ts +12 -0
  82. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +36 -0
  83. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
  84. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
  85. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
  86. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
  87. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
  88. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
  89. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
  90. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
  91. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
  92. package/packages/core/src/kernel/auto-merge-default.ts +2 -1
  93. package/packages/core/src/kernel/capacity-build.ts +21 -0
  94. package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
  95. package/packages/core/src/kernel/discard-in-flight.ts +13 -0
  96. package/packages/core/src/kernel/dispatch-capacity.ts +578 -235
  97. package/packages/core/src/kernel/done-escalations.ts +269 -0
  98. package/packages/core/src/kernel/engine.ts +30 -17
  99. package/packages/core/src/kernel/integration-landing.ts +24 -4
  100. package/packages/core/src/kernel/integration-stack.ts +39 -0
  101. package/packages/core/src/kernel/janitor-failure.ts +20 -1
  102. package/packages/core/src/kernel/log-index-value.ts +3 -0
  103. package/packages/core/src/kernel/log-index.ts +41 -2
  104. package/packages/core/src/kernel/measurement.ts +24 -0
  105. package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
  106. package/packages/core/src/kernel/read-facts.ts +8 -370
  107. package/packages/core/src/kernel/reducer-registry.ts +43 -125
  108. package/packages/core/src/kernel/reducer-revisions.ts +18 -0
  109. package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
  110. package/packages/core/src/kernel/reducer-value-index.ts +75 -0
  111. package/packages/core/src/kernel/reducer.ts +84 -16
  112. package/packages/core/src/kernel/reopen-state.ts +10 -0
  113. package/packages/core/src/kernel/repository-attention.ts +14 -5
  114. package/packages/core/src/kernel/repository-read-facts.ts +375 -0
  115. package/packages/core/src/kernel/ticket-starts.ts +15 -4
  116. package/packages/core/src/kernel/verify-stage-state.ts +145 -3
  117. package/packages/core/src/kernel/verify-stages.ts +46 -7
  118. package/packages/core/src/operator/attention.ts +28 -3
  119. package/packages/core/src/operator/done-escalations.ts +38 -0
  120. package/packages/core/src/operator/presentation.ts +14 -1
  121. package/packages/core/src/operator/protocol.ts +8 -5
  122. package/packages/core/src/operator/query.ts +72 -57
  123. package/packages/core/src/operator/registry.ts +19 -15
  124. package/packages/core/src/operator/ticket-start.ts +8 -7
  125. package/packages/core/src/operator/tickets.ts +28 -9
  126. package/packages/core/src/plugin-sdk/index.ts +10 -0
  127. package/packages/core/src/plugins/manifest.ts +14 -1
  128. package/packages/core/src/ports/forge/create.ts +8 -0
  129. package/packages/core/src/ports/forge/github-transport.ts +5 -1
  130. package/packages/core/src/ports/forge/github.ts +3 -0
  131. package/packages/core/src/ports/tickets/contract.ts +147 -76
  132. package/packages/core/src/ports/tickets/create.ts +47 -7
  133. package/packages/core/src/ports/tickets/fake.ts +8 -4
  134. package/packages/core/src/ports/tickets/file-codec.ts +4 -3
  135. package/packages/core/src/ports/tickets/file.ts +7 -3
  136. package/packages/core/src/ports/tickets/github.ts +1 -0
  137. package/packages/core/src/ports/tickets/grants.ts +11 -3
  138. package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
  139. package/packages/core/src/ports/tickets/linear.ts +28 -9
  140. package/packages/core/src/ports/tickets/migration.ts +4 -4
  141. package/packages/core/src/ports/tickets/operations.ts +4 -2
  142. package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
  143. package/packages/core/src/ports/tickets/priority.ts +127 -21
  144. package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
  145. package/packages/core/src/ports/tickets/remote.ts +104 -11
  146. package/packages/core/src/ports/tickets/revision.ts +5 -3
  147. package/packages/core/src/ports/tickets/search.ts +9 -0
  148. package/packages/core/src/ports/tickets/tree.ts +8 -6
  149. package/packages/core/src/ports/types.ts +30 -15
  150. package/packages/core/src/ports/workspace/build-execution.ts +4 -0
  151. package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
  152. package/packages/core/src/ports/workspace/create.ts +16 -3
  153. package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
  154. package/packages/core/src/ports/workspace/fake.ts +15 -3
  155. package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
  156. package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
  157. package/packages/core/src/processes/build-execution-state.ts +4 -0
  158. package/packages/core/src/processes/build-runner.ts +14 -1
  159. package/packages/core/src/processes/dispatcher.ts +777 -288
  160. package/packages/core/src/processes/execution-no-progress.ts +1 -0
  161. package/packages/core/src/processes/execution-settlement.ts +1 -0
  162. package/packages/core/src/processes/harvest-runner.ts +12 -7
  163. package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
  164. package/packages/core/src/processes/invocation-budget.ts +176 -0
  165. package/packages/core/src/processes/publication-loss.ts +38 -3
  166. package/packages/core/src/processes/workspace-preservation.ts +86 -15
  167. package/packages/core/src/store/contract.ts +81 -3
  168. package/packages/core/src/store/event-reads.ts +30 -1
  169. package/packages/core/src/store/local/capabilities.ts +115 -0
  170. package/packages/core/src/store/local/store.ts +86 -56
  171. package/packages/core/src/store/reduced-reads.ts +32 -1
  172. package/packages/core/src/store/reducer-value-read.ts +235 -0
  173. package/packages/core/src/store/reducer-value-shapes.json +6722 -6475
  174. package/packages/core/src/store/reducer-value-validation.ts +181 -33
  175. package/packages/core/src/store/reducer-values.ts +36 -204
  176. package/packages/core/src/store/remote/client.ts +169 -29
  177. package/packages/core/src/store/remote/compatibility.ts +113 -56
  178. package/packages/core/src/store/remote/credentials.ts +4 -1
  179. package/packages/core/src/store/remote/protocol.ts +3 -0
  180. package/packages/core/src/store/remote/released-clients.json +22 -0
  181. package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
  182. package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
  183. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  184. package/packages/core/src/store/remote/released-value-policy.ts +144 -0
  185. package/packages/core/src/store/remote/retry.ts +406 -0
  186. package/packages/core/src/store/rollup-lease.ts +41 -0
  187. package/packages/core/src/store/rollups.ts +7 -38
  188. package/packages/core/src/store/snapshots.ts +1 -1
  189. package/packages/core/src/testing/dispatch-read-budget.ts +409 -14
  190. package/packages/core/src/testing/import-graph.ts +78 -0
  191. package/packages/core/src/testing/index.ts +2 -0
  192. package/packages/core/src/testing/invocation-budget.ts +42 -0
  193. package/packages/core/src/testing/reduced-read-budget.ts +602 -40
  194. package/packages/core/src/testing/released-value-coverage.ts +423 -0
  195. package/packages/core/src/testing/slot-agreement.ts +52 -0
  196. package/packages/core/src/web/assets/app.js +5 -5
  197. package/packages/core/src/web/overview-source.ts +19 -6
  198. package/skills/guide/SKILL.md +245 -103
  199. package/skills/guide/references/integration-tree.md +33 -18
  200. package/skills/guide/references/merge-policy.md +7 -2
  201. package/skills/guide/references/operator-api.md +48 -25
  202. package/skills/guide/references/optimization-nodes.md +10 -8
  203. package/skills/guide/references/plugin-authoring.md +46 -18
  204. package/skills/guide/references/remote-store-protocol.md +51 -12
  205. package/skills/guide/references/remote-ticket-protocol.md +85 -38
  206. package/skills/guide/references/restacking.md +48 -3
  207. package/skills/guide/references/setup.md +2 -1
  208. package/skills/guide/references/ticket-migration.md +2 -2
  209. package/skills/operate/SKILL.md +114 -65
  210. package/skills/plan/SKILL.md +4 -3
  211. package/skills/spec/SKILL.md +9 -5
  212. package/skills/tickets/SKILL.md +25 -17
  213. package/templates/hosted-service/package.json +2 -2
@@ -55,21 +55,8 @@ export interface JudgeCliEnv {
55
55
  export type AmbientReadSession = CliEnv | HarvestCliEnv
56
56
 
57
57
  const PHASE_FORMAT = "'<phase>[@<round>]' (e.g. 'implement@2', 'verify:acceptance@1')"
58
- const BUILD_AMBIENT_TUPLE = 'AB_STORE/AB_BUILD/AB_PHASE/AB_SESSION'
59
- const HARVEST_AMBIENT_TUPLE = 'AB_STORE/AB_REPO/AB_HARVEST/AB_PHASE/AB_SESSION'
60
-
61
- /** Optional ambient identity is present but cannot safely select one scope. */
62
- export class InvalidAmbientContextError extends Error {
63
- override readonly name = 'InvalidAmbientContextError'
64
-
65
- constructor(detail: string) {
66
- super(
67
- `invalid ambient context: ${detail}. Expected no agent identity markers, ` +
68
- `a complete build tuple (${BUILD_AMBIENT_TUPLE}), or a complete Harvest tuple ` +
69
- `(${HARVEST_AMBIENT_TUPLE})`,
70
- )
71
- }
72
- }
58
+ export { InvalidAmbientContextError } from './ambient-errors'
59
+ import { InvalidAmbientContextError } from './ambient-errors'
73
60
 
74
61
  /** A required runner-provided session value is absent or empty. Callers that
75
62
  * resolve ambient auth directly still receive the variable-specific message;
@@ -231,12 +231,12 @@ export const HELP_CATALOG: readonly HelpEntry[] = [
231
231
  detail: page([
232
232
  'Usage:',
233
233
  ' ab ticket tree [--json]',
234
- ' ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--issues N[:refs],...] [--priority urgent|normal] [--assignees a,b] [--kind work|node] [--target <id> | --no-target] [--json]',
234
+ ' ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--issues N[:refs],...] [--priority urgent|high|normal|low] [--assignees a,b] [--kind work|node] [--target <id> | --no-target] [--json]',
235
235
  ' ab ticket edit <id>',
236
236
  ' ab ticket export <dir> [--store <ref>]',
237
237
  ' ab ticket import <dir> [--states <state,...>] [--store <ref>]',
238
238
  ' ab ticket migration record <dir> [--store <ref>]',
239
- ' ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--issues N[:refs],...] [--priority urgent|normal] [--assignees a,b] [--expected-revision <opaque>] [--json]',
239
+ ' ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--issues N[:refs],...] [--priority urgent|high|normal|low] [--assignees a,b] [--expected-revision <opaque>] [--json]',
240
240
  ' ab ticket block <id> <blocker-id[,blocker-id...]> [--expected-revision <opaque>] [--json]',
241
241
  ' ab ticket unblock <id> <blocker-id[,blocker-id...]> [--expected-revision <opaque>] [--json]',
242
242
  ' ab ticket list [--state <state>] [--labels a,b] [--json]',
@@ -272,10 +272,12 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
272
272
  'or N:refs for partial work, comma-separated. On update it replaces the set',
273
273
  'and --issues "" clears it. Sources that cannot store issue links refuse the',
274
274
  'write, name the source, and write nothing.',
275
- '--priority urgent dispatches the ticket before normal ready work, each class',
276
- 'in source order; it never preempts a running build. normal (the default)',
277
- 'removes urgency. Sources that cannot store priority refuse urgent, name the',
278
- 'source, and write nothing; normal is a no-op there.',
275
+ '--priority sets the level: urgent, high, normal (the default) or low. Ready',
276
+ 'tickets are claimed by level, urgent first and low last, each level in source',
277
+ 'order; a running build is never preempted. On update, normal clears the level. A',
278
+ 'source without native priority stores the level as exactly one label,',
279
+ 'priority:urgent, priority:high or priority:low; those labels report as the',
280
+ 'priority, never in labels, and --labels may not name them.',
279
281
  '--assignees entries are usernames or me (the owner of the source credential).',
280
282
  'On create they replace the [tickets].createAssignee default and --assignees ""',
281
283
  'creates an unassigned ticket; on update they replace the set and "" clears it.',
@@ -283,7 +285,7 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
283
285
  'write nothing.',
284
286
  '',
285
287
  'With no list filters, list uses the same ready criteria as dispatch. show one ticket, including its body/spec.',
286
- 'Human output is the default and marks urgent tickets. --json emits exactly',
288
+ 'Human output is the default and marks every level but normal. --json emits exactly',
287
289
  'one bare value, and every JSON ticket names its priority: Ticket[]',
288
290
  'for list, the hierarchy for tree, and the resulting Ticket for ticket mutations; show',
289
291
  'adds an assets array (kind, name, revision, size, layout, fileCount). Sources',
@@ -452,12 +454,13 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
452
454
  '',
453
455
  'Default filter — actionable attention only. Builds: escalation.raised, phase.deferral-escalated, integration.landed,',
454
456
  'integration.verification-failed (failed node verification), build.janitor-failing, build.janitor-escalated,',
455
- 'build.compatibility-deferred, node.item-conflicted, target.rewritten (a node, once per rejected baseline),',
456
- 'conflicted restack.replayed,',
457
+ 'build.compatibility-deferred, target.rewritten (a node, once per rejected baseline),',
457
458
  'landing.consent-revoked (protected merge consent revoked by a reconcile),',
458
459
  "pr.checks-failed (failing forge CI on a finished leaf's live PR head),",
459
460
  "optimization.noise-exceeded (an optimization node's ε is below its measured noise), derived build.consent-ready and",
460
461
  'build.merge-decision (a current actionable merge-gate deferral, a landing awaiting a human merge, or an unsafe forge outcome).',
462
+ 'Restack conflicts (conflicted restack.replayed, node.item-conflicted) are routine: reconcile resolves them.',
463
+ 'Follow them with --event; an unresolvable conflict arrives as escalation.raised or landing.consent-revoked.',
461
464
  'Consent and held ready merges use only build.consent-ready, once per readiness episode.',
462
465
  'Unready or stale consent candidates stay silent; one merge gate decision per build/PR.',
463
466
  'Repository: harvest.escalated, harvest.recovery-exhausted, dispatcher.config-rejected, dispatcher.forge-readiness-failed,',
@@ -578,8 +581,9 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
578
581
  'Conditions (--for, repeatable): blocked, paused, running, done, aborted, terminal (done',
579
582
  'or aborted), pr=open, pr=merged, pr=closed, consent, node-merged, restack-conflicted, pr=conflicted, phase=<phase> (a core phase —',
580
583
  'plan, plan-review, implement, code-review, finalize, reconcile, propose — or verify:<step>), and',
581
- "attention (an open escalation other than a ticket wait's own, failed node verification, consent readiness, a node merge or restack conflict,",
582
- 'failing forge CI on a finished leaf, or a build waiting for a merge decision). Merge attention',
584
+ "attention (an open escalation other than a ticket wait's own, failed node verification, consent readiness, a node merge,",
585
+ 'failing forge CI on a finished leaf, or a build waiting for a merge decision). Routine restack conflicts are',
586
+ 'not attention: reconcile resolves them, and --for restack-conflicted waits for them. Merge attention',
583
587
  'requires a current actionable gate deferral or an unsafe forge outcome;',
584
588
  'armed pending consent, routine outcomes and self-healing failures stay silent.',
585
589
  'An unknown condition value is rejected before',
@@ -707,10 +711,11 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
707
711
  'dashboard’s global-row r: it durably releases the queued-build hold, then',
708
712
  'turns ticket intake back on, then requests a resume on every cleanly paused',
709
713
  'build that does not already have one. A released queued build becomes',
710
- 'launchable on the next ordinary tick with no further action. Running, resuming,',
711
- 'blocked, and finished builds are skipped without error, and a build still',
712
- 'holding an open escalation is left to ab answer. Output names every build that',
713
- 'received a request, the hold, and the intake value written; --json emits that',
714
+ 'launchable on the next ordinary tick with no further action. Running builds,',
715
+ 'builds with a resume already pending, and blocked and finished builds are',
716
+ 'skipped without error, and a build still holding an open escalation is',
717
+ 'left to ab answer. Output names every build that received a request, the',
718
+ 'hold, and the intake value written; --json emits that',
714
719
  'summary as JSON. Re-running it changes nothing further. A phase session may not',
715
720
  'use --all. A failure exits nonzero and reports which of the two repository',
716
721
  'facts landed and which builds were requested.',
@@ -757,6 +762,10 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
757
762
  "the build's own commits onto the current target before any further verification.",
758
763
  'Other answer forms skip that escalation; ab abort is the other way out.',
759
764
  '',
765
+ 'On a completed build, guidance or a bare answer only acknowledges open escalations,',
766
+ 'such as a post-landing integration audit; the build stays done and every other',
767
+ 'form is refused.',
768
+ '',
760
769
  'If paused and every blocker clears, resume is requested last. --store overrides the',
761
770
  'BuildStore path or URL. This command is sessionless; a phase may not answer its',
762
771
  'own build.',
@@ -768,7 +777,7 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
768
777
  summary: 'Ask the running dispatcher to start one ticket, even while intake is off.',
769
778
  detail: page([
770
779
  'Usage:',
771
- ' ab start <ticket-id> [--priority manual|urgent|normal] [--cancel] [--json] [--store <ref>]',
780
+ ' ab start <ticket-id> [--priority manual|urgent|high|normal|low] [--cancel] [--json] [--store <ref>]',
772
781
  '',
773
782
  'Record a durable start request for one ticket. The running dispatcher, local or',
774
783
  "hosted, claims it on its next tick with a free slot in the request's priority",
@@ -782,11 +791,15 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
782
791
  'Priority tiers (free slots go to them in this order, among parked work and claims):',
783
792
  ' manual (default) Ahead of every waiting build and ticket claim, urgent ones included.',
784
793
  ' urgent After urgent parked work; ahead of urgent ready tickets and all',
785
- ' normal work.',
786
- ' normal After normal parked work and urgent claims; ahead of normal ready',
794
+ ' high, normal and low work.',
795
+ ' high After high parked work and urgent claims; ahead of high ready',
796
+ ' tickets and all normal and low work.',
797
+ ' normal After normal parked work and high claims; ahead of normal ready',
798
+ ' tickets and all low work.',
799
+ ' low After low parked work and normal claims; ahead of low ready',
787
800
  ' tickets.',
788
- 'manual is admission-only: the claimed build is urgent when the request was urgent,',
789
- "and otherwise keeps its ticket's priority.",
801
+ "manual is admission-only: the claimed build takes its ticket's level. Any other",
802
+ "tier sets the claimed build's level to the request's.",
790
803
  '',
791
804
  'Every ordinary gate still applies: the ticket must be in the configured ready',
792
805
  'state, conform to the spec standard (a nonconforming one is bounced to triage),',
@@ -797,7 +810,8 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
797
810
  'blocked, invalid, missing, not-ready, terminal or claim-refused. Pending and',
798
811
  'recently settled requests appear, with their priority, in ab repository status.',
799
812
  '',
800
- ' --priority <tier> manual (default), urgent or normal; not allowed with --cancel.',
813
+ ' --priority <tier> manual (default), urgent, high, normal or low; not allowed with',
814
+ ' --cancel.',
801
815
  ' --cancel Cancel the pending request instead; a no-op when none is pending.',
802
816
  ' --json Print the result object.',
803
817
  ' --store <ref> Override the BuildStore path or URL.',
@@ -960,13 +974,14 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
960
974
  audience: 'human',
961
975
  summary: "Set an active build's slot-admission priority.",
962
976
  detail: page([
963
- 'Usage: ab priority <slug> urgent|normal [--store <ref>]',
964
- '',
965
- 'Records build.priority-set. A build starts with its ticket priority at claim;',
966
- 'this changes only the build, never the ticket. Free slots go, in order, to urgent',
967
- 'parked work (re-verification, reconcile, resume, propose), urgent ticket claims,',
968
- 'normal parked work, then normal ticket claims. Running work is never preempted.',
969
- 'Use it to expedite a waiting build that became a blocker, or return it to normal.',
977
+ 'Usage: ab priority <slug> urgent|high|normal|low [--store <ref>]',
978
+ '',
979
+ "Records build.priority-set. A build starts at its ticket's level; this changes",
980
+ 'only the build, never the ticket. Free slots go, in order, to manual start',
981
+ "requests, then for each level, urgent, high, normal and low: that level's parked",
982
+ 'work (re-verification, reconcile, resume, reopen, propose), then its ticket',
983
+ 'claims. Running work is never preempted. Use it to expedite a waiting build',
984
+ 'that became a blocker, defer one with low, or return it to normal.',
970
985
  'Requires a running, paused or blocked build. This command is sessionless; a phase',
971
986
  'may not control its own build.',
972
987
  ]),
@@ -243,11 +243,13 @@ export function buildControlConfirmation(result: BuildControlResult): string {
243
243
  if (result.event.type === 'build.hold-requested' && result.event.payload.reason !== undefined)
244
244
  return `build ${result.slug}: merge hold requested (reason: ${result.event.payload.reason})`
245
245
  if (result.event.type === 'build.priority-set')
246
- return `build ${result.slug}: priority set to ${result.event.payload.priority}`
246
+ return `build ${result.slug}: priority set to ${result.event.payload.level ?? result.event.payload.priority}`
247
247
  return `build ${result.slug}: ${outcome[result.command]}`
248
248
  }
249
249
  case 'answered': {
250
250
  const plural = result.count === 1 ? '' : 's'
251
+ if (result.acknowledged)
252
+ return `build ${result.slug}: acknowledged ${result.count} escalation${plural} on the completed build; status stays done`
251
253
  const terminal = result.terminalSignal
252
254
  if (terminal !== undefined) {
253
255
  const ending =
@@ -1000,7 +1002,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1000
1002
  }
1001
1003
 
1002
1004
  case 'builds': {
1003
- const { abBuilds } = await import('./status')
1005
+ const { abBuilds, statusColor } = await import('./status')
1004
1006
  const usage = 'usage: ab builds [--queued] [--all] [--json] [--store <ref>] (§8.2)'
1005
1007
  const parsed = parseArgs(
1006
1008
  rest,
@@ -1020,6 +1022,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1020
1022
  queued: parsed.flags.has('queued'),
1021
1023
  all: parsed.flags.has('all'),
1022
1024
  json: parsed.flags.has('json'),
1025
+ color: statusColor(deps.terminal, parsed.flags.has('json')),
1023
1026
  ...(storeRef !== undefined ? { storeRef } : {}),
1024
1027
  ...(deps.openStore !== undefined ? { openStore: deps.openStore } : {}),
1025
1028
  ...(deps.clock !== undefined ? { now: deps.clock } : {}),
@@ -1050,7 +1053,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1050
1053
  }
1051
1054
 
1052
1055
  case 'build': {
1053
- const { abBuildAssetGet, abBuildStatus } = await import('./status')
1056
+ const { abBuildAssetGet, abBuildStatus, statusColor } = await import('./status')
1054
1057
  const usage =
1055
1058
  'usage: ab build status <slug> [--events <n>] [--json] [--store <ref>] (§8.2)\n' +
1056
1059
  ' ab build asset get <slug> <kind> <name> <dest> [--rev <n>] [--json] [--store <ref>] (§8.8)'
@@ -1117,6 +1120,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1117
1120
  stdout,
1118
1121
  slug,
1119
1122
  json: parsed.flags.has('json'),
1123
+ color: statusColor(deps.terminal, parsed.flags.has('json')),
1120
1124
  ...(events !== undefined ? { events } : {}),
1121
1125
  ...(storeRef !== undefined ? { storeRef } : {}),
1122
1126
  ...(deps.openStore !== undefined ? { openStore: deps.openStore } : {}),
@@ -1377,7 +1381,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1377
1381
  const { abTicketStart } = await import('./ticket-start')
1378
1382
  const { parseStartPriorityFlag } = await import('../ports/tickets/priority')
1379
1383
  const usage =
1380
- 'usage: ab start <ticket-id> [--priority manual|urgent|normal] [--cancel] [--json] [--store <ref>]'
1384
+ 'usage: ab start <ticket-id> [--priority manual|urgent|high|normal|low] [--cancel] [--json] [--store <ref>]'
1381
1385
  const parsed = parseArgs(
1382
1386
  rest,
1383
1387
  { cancel: 'boolean', json: 'boolean', priority: 'value', store: 'value' },
@@ -1446,11 +1450,11 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1446
1450
  }
1447
1451
 
1448
1452
  case 'priority': {
1449
- const { parsePriorityFlag } = await import('../ports/tickets/priority')
1450
- const usage = 'usage: ab priority <slug> urgent|normal [--store <ref>]'
1453
+ const { parseBuildPriorityFlag } = await import('../ports/tickets/priority')
1454
+ const usage = 'usage: ab priority <slug> urgent|high|normal|low [--store <ref>]'
1451
1455
  const parsed = parseArgs(rest, { store: 'value' }, usage)
1452
1456
  if (parsed.positionals.length !== 2) throw new Error(usage)
1453
- const priority = parsePriorityFlag(parsed.positionals[1]!, 'priority')
1457
+ const priority = parseBuildPriorityFlag(parsed.positionals[1]!, 'priority')
1454
1458
  await runBuildControl(
1455
1459
  deps,
1456
1460
  parsed.positionals[0]!,
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The adapter-free half of production store composition. A local reference
3
+ * never evaluates the remote HTTP adapter or repository configuration: the
4
+ * remote client loads only when `openProductionStoreAsync` opens an http(s)
5
+ * reference, and repository-state resolution lives in `store-opening.ts` and
6
+ * `sessionless-store.ts`. `store-opening.ts` re-exposes all of this with its
7
+ * eager remote factory, so its exports and behavior are unchanged.
8
+ */
9
+ import { AccountRedactor, redactAccountStore } from '../store/account-redaction'
10
+ import type { BuildStore } from '../store/types'
11
+ import { InvalidAmbientContextError } from './ambient-errors'
12
+ import { projectToken } from './project-credentials'
13
+ import type { RepoStatePaths } from './repo-state'
14
+ import { isRemoteStoreRef, resolveStore, type ResolveStoreOpts } from './store-ref'
15
+
16
+ /** Shared injection seam used by every command that opens a BuildStore. */
17
+ export type StoreOpener = (ref: string, token?: string) => BuildStore
18
+
19
+ export function optionalToken(value: string | undefined): string | undefined {
20
+ // Bearer credentials are opaque. Only absence and the exact empty value mean
21
+ // "no token"; nonempty values are forwarded byte-for-byte.
22
+ return value !== undefined && value !== '' ? value : undefined
23
+ }
24
+
25
+ /** Production local/remote composition over a supplied remote factory. */
26
+ export function composeProductionStore(
27
+ ref: string,
28
+ token: string | undefined,
29
+ remoteFactory?: ResolveStoreOpts['remoteFactory'],
30
+ ): BuildStore {
31
+ const forwardedToken = optionalToken(token)
32
+ const store = resolveStore(ref, {
33
+ ...(remoteFactory ? { remoteFactory } : {}),
34
+ ...(forwardedToken !== undefined ? { token: forwardedToken } : {}),
35
+ })
36
+ const raw = process.env.AB_ACCOUNT_CREDENTIAL_ENVS
37
+ if (!raw) return store
38
+ const names: unknown = JSON.parse(raw)
39
+ if (!Array.isArray(names) || !names.every((name) => typeof name === 'string'))
40
+ throw new Error('Invalid account credential variable inventory')
41
+ return redactAccountStore(
42
+ store,
43
+ new AccountRedactor(() => names.map((name) => process.env[name])),
44
+ )
45
+ }
46
+
47
+ /** The production remote factory, loaded with the remote adapter. */
48
+ export async function loadRemoteFactory(): Promise<NonNullable<ResolveStoreOpts['remoteFactory']>> {
49
+ const { RemoteBuildStore } = await import('../store/remote/client')
50
+ return (url, remoteToken) => new RemoteBuildStore({ url, token: remoteToken })
51
+ }
52
+
53
+ /** The production opener for `ref`: the remote adapter loads only for an
54
+ * http(s) reference. */
55
+ export async function productionOpenerFor(ref: string): Promise<StoreOpener> {
56
+ const remoteFactory = isRemoteStoreRef(ref) ? await loadRemoteFactory() : undefined
57
+ return (selected, token) => composeProductionStore(selected, token, remoteFactory)
58
+ }
59
+
60
+ /** `openProductionStore` without loading the remote adapter for a local ref. */
61
+ export async function openProductionStoreAsync(ref: string, token?: string): Promise<BuildStore> {
62
+ return (await productionOpenerFor(ref))(ref, token)
63
+ }
64
+
65
+ export interface OpenStoreForRepoStateOpts {
66
+ env: Record<string, string | undefined>
67
+ openStore?: StoreOpener
68
+ useProjectCredential?: boolean
69
+ }
70
+
71
+ export interface OpenedStoreContext extends RepoStatePaths {
72
+ store: BuildStore
73
+ token?: string
74
+ /** The validated ambient phase/Harvest identity this invocation carries, if
75
+ * any — the same value that scoped `store`. Exposed for commands whose
76
+ * repository selection also depends on ambient own-build authority. */
77
+ ambient?: import('./env').AmbientReadSession
78
+ }
79
+
80
+ /** Open from an already canonicalized state selection with `opener`. */
81
+ export function openStoreForRepoStateWith(
82
+ state: RepoStatePaths,
83
+ opts: OpenStoreForRepoStateOpts,
84
+ opener: StoreOpener,
85
+ ): OpenedStoreContext {
86
+ // A judge session's only store authority is its one preference.
87
+ if (opts.env.AB_JUDGE !== undefined)
88
+ throw new InvalidAmbientContextError('a judge session has no read authority')
89
+ const token =
90
+ opts.useProjectCredential !== false && isRemoteStoreRef(state.storeRef)
91
+ ? projectToken(state.storeRef, state.repo, opts.env)
92
+ : optionalToken(opts.env.AB_TOKEN)
93
+ if (!token && isRemoteStoreRef(state.storeRef) && state.configStore === state.storeRef) {
94
+ throw new Error('No project credential for this service; run ab connect')
95
+ }
96
+ const store = opener(state.storeRef, token)
97
+ return {
98
+ ...state,
99
+ store,
100
+ ...(token !== undefined ? { token } : {}),
101
+ }
102
+ }
@@ -1,6 +1,7 @@
1
1
  import { recoverLostCandidate } from '../kernel/reconcile-restack'
2
2
  import { publicationRetryGate, retryPublicationEffect } from '../kernel/publication-retry'
3
3
  import { ForgeRequestDeferred } from '../ports/forge-request-context'
4
+ import { isRecoveryDeferred } from '../ports/workspace/recovery-step'
4
5
  import { stat } from 'node:fs/promises'
5
6
  import { deferMixedVersion, MixedVersionDeferral } from '../kernel/mixed-version'
6
7
  import { suspendNativeLanding } from '../kernel/landing-publication'
@@ -427,6 +428,9 @@ export async function settlePendingPublication(
427
428
  }
428
429
  } catch (error) {
429
430
  if (error instanceof ForgeRequestDeferred) throw error
431
+ // The invocation deadline cut recovery short: the request stays pending
432
+ // and a later invocation settles it. Never a failed finalize step.
433
+ if (isRecoveryDeferred(error)) throw error
430
434
  if (error instanceof MixedVersionDeferral) return
431
435
  if (request.payload.operation !== 'finalize-step') throw error
432
436
  const detail = error instanceof Error ? error.message : String(error)
@@ -21,6 +21,13 @@ import { isTerminalEventReadError } from '../store/event-reads'
21
21
  */
22
22
  import { REMOTE_EVENT_WAIT_SECONDS } from '../store/remote/client'
23
23
 
24
+ /**
25
+ * A stream poll resolves this when its stream has left tracking: the task
26
+ * ends quietly — no `requestStop`, no `endCheck` — and its siblings keep
27
+ * polling. Only `ab watch` returns it (a settled build retiring).
28
+ */
29
+ export const STREAM_RETIRED: unique symbol = Symbol('stream-retired')
30
+
24
31
  /** The read options one held long-poll request carries. */
25
32
  export interface RemotePollReadOpts {
26
33
  waitSeconds?: number
@@ -116,8 +123,10 @@ export interface RemotePollRunner {
116
123
  readonly stopped: boolean
117
124
  /** Abort every in-flight held read, wake the gap sleeps, mark stopped. */
118
125
  requestStop(): void
119
- /** Launch one per-stream long-poll task; idempotent per key. `endCheck`
120
- * runs after each successful poll; true ⇒ requestStop + return. */
126
+ /** Launch one per-stream long-poll task; idempotent per key while the task
127
+ * runs. `endCheck` runs after each successful poll; true ⇒ requestStop +
128
+ * return. A poll resolving `STREAM_RETIRED` ends only its own task and
129
+ * frees the key. */
121
130
  launch(
122
131
  key: string,
123
132
  poll: (readOpts: RemotePollReadOpts) => Promise<unknown>,
@@ -185,7 +194,9 @@ export function createRemotePollRunner(opts: RemotePollRunnerOpts): RemotePollRu
185
194
  )
186
195
  }
187
196
 
197
+ const launched = new Set<string>()
188
198
  const runStreamTask = async (
199
+ key: string,
189
200
  poll: (readOpts: RemotePollReadOpts) => Promise<unknown>,
190
201
  endCheck?: () => boolean,
191
202
  ): Promise<void> => {
@@ -195,8 +206,15 @@ export function createRemotePollRunner(opts: RemotePollRunnerOpts): RemotePollRu
195
206
  const controller = new AbortController()
196
207
  inFlightReads.add(controller)
197
208
  try {
198
- await poll({ waitSeconds: readWaitSeconds(started), signal: controller.signal })
209
+ const result = await poll({
210
+ waitSeconds: readWaitSeconds(started),
211
+ signal: controller.signal,
212
+ })
199
213
  streak.onSuccess()
214
+ if (result === STREAM_RETIRED) {
215
+ launched.delete(key)
216
+ return
217
+ }
200
218
  if (endCheck?.()) {
201
219
  requestStop()
202
220
  return
@@ -219,7 +237,6 @@ export function createRemotePollRunner(opts: RemotePollRunnerOpts): RemotePollRu
219
237
  }
220
238
  }
221
239
 
222
- const launched = new Set<string>()
223
240
  const launch = (
224
241
  key: string,
225
242
  poll: (readOpts: RemotePollReadOpts) => Promise<unknown>,
@@ -227,7 +244,7 @@ export function createRemotePollRunner(opts: RemotePollRunnerOpts): RemotePollRu
227
244
  ): void => {
228
245
  if (launched.has(key)) return
229
246
  launched.add(key)
230
- track(runStreamTask(poll, endCheck))
247
+ track(runStreamTask(key, poll, endCheck))
231
248
  }
232
249
 
233
250
  const runDiscovery = (discovery: {
@@ -32,9 +32,8 @@ export { normalizeGitRemoteUrl } from '../kernel/origin'
32
32
 
33
33
  export const LOCAL_STATE_DIR = '.autobuild'
34
34
 
35
- export function isRemoteStoreRef(ref: string): boolean {
36
- return /^https?:\/\//i.test(ref)
37
- }
35
+ export { isRemoteStoreRef } from './store-ref'
36
+ import { isRemoteStoreRef } from './store-ref'
38
37
 
39
38
  export { resolveMainRepo } from './main-checkout'
40
39
  import { resolveMainRepo } from './main-checkout'
@@ -1,4 +1,4 @@
1
- import type { TicketStartPriority } from '../events/repository'
1
+ import { startTierOf, type StartTier } from '../ports/tickets/priority'
2
2
  import { repositoryReadFactsReducer } from '../kernel/read-facts'
3
3
  import {
4
4
  ticketStartsReducer,
@@ -7,7 +7,6 @@ import {
7
7
  } from '../kernel/ticket-starts'
8
8
  import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
9
9
  import { OPERATOR_PRESENCE_TTL_MS, type OperatorPresence } from '../store/operator-presence'
10
- import { migrationIdentity } from '../kernel/ticket-migrations'
11
10
  import {
12
11
  dispatchUpgradeReducer,
13
12
  upgradeRunRecency,
@@ -15,14 +14,15 @@ import {
15
14
  type UpgradeRun,
16
15
  } from '../kernel/dispatch-upgrade'
17
16
  import { formatRuntimeIdentity } from '../events/runtime'
18
- import { landingRestackDue } from '../kernel/engine'
17
+ import { capacityBuildFromFacts } from '../kernel/capacity-build'
19
18
  import {
20
19
  dispatchCapacity,
21
20
  startClaimDemand,
22
- urgentClaimDemand,
21
+ claimDemand,
23
22
  waitingExplanation,
24
23
  type DispatchCapacity,
25
24
  type CapacityBuild,
25
+ type SlotState,
26
26
  } from '../kernel/dispatch-capacity'
27
27
  import { backpressureStatusLine } from '../kernel/open-pr-backpressure'
28
28
  import {
@@ -266,11 +266,13 @@ export interface RepositoryTicketStarts {
266
266
  pending: Array<{
267
267
  ticket: { source: string; id: string }
268
268
  request: number
269
- priority: TicketStartPriority
269
+ /** The request's admission tier (`startTierOf`). */
270
+ priority: StartTier
270
271
  requestedAt: string
271
272
  by?: string
272
273
  }>
273
- recent: SettledTicketStart[]
274
+ /** Settled or cancelled requests, newest last, each naming its tier. */
275
+ recent: Array<Omit<SettledTicketStart, 'priority' | 'level'> & { priority: StartTier }>
274
276
  }
275
277
 
276
278
  function projectTicketStarts(starts: TicketStarts): { ticketStarts?: RepositoryTicketStarts } {
@@ -279,12 +281,20 @@ function projectTicketStarts(starts: TicketStarts): { ticketStarts?: RepositoryT
279
281
  .map((entry) => ({
280
282
  ticket: entry.ticket,
281
283
  request: entry.seq,
282
- priority: entry.priority,
284
+ priority: startTierOf(entry),
283
285
  requestedAt: entry.ts,
284
286
  ...(entry.by !== undefined ? { by: entry.by } : {}),
285
287
  }))
286
288
  return pending.length || starts.recent.length
287
- ? { ticketStarts: { pending, recent: [...starts.recent] } }
289
+ ? {
290
+ ticketStarts: {
291
+ pending,
292
+ recent: starts.recent.map(({ level: _level, ...entry }) => ({
293
+ ...entry,
294
+ priority: startTierOf({ priority: entry.priority, level: _level }),
295
+ })),
296
+ },
297
+ }
288
298
  : {}
289
299
  }
290
300
 
@@ -574,9 +584,10 @@ export function renderRepositoryStatus(status: RepositoryStatus): string[] {
574
584
  `repository: ${status.repo}`,
575
585
  ...(status.capacity
576
586
  ? [
577
- `capacity: ${status.capacity.occupied}/${status.capacity.effective} effective; ${status.capacity.configured} configured; ${status.capacity.borrowingNodes.length} node${status.capacity.borrowingNodes.length === 1 ? '' : 's'} using descendant-held slots${status.capacity.borrowingNodes.length ? `: ${status.capacity.borrowingNodes.join(', ')}` : ''}${status.capacity.waitingNodes?.length || status.capacity.waitingBuilds?.length || status.capacity.urgentClaims || status.capacity.startRequests ? `; ${waitingExplanation(status.capacity, { requests: true })}` : ''}`,
587
+ `capacity: ${status.capacity.occupied}/${status.capacity.configured}${status.capacity.waitingNodes?.length || status.capacity.waitingBuilds?.length || status.capacity.urgentClaims || status.capacity.highClaims || status.capacity.normalClaims || status.capacity.startRequests ? `; ${waitingExplanation(status.capacity, { requests: true })}` : ''}`,
578
588
  ]
579
589
  : []),
590
+ ...(status.capacity?.slots ? [slotsStatusLine(status.capacity.slots)] : []),
580
591
  ...(status.capacity?.backpressure
581
592
  ? [backpressureStatusLine(status.capacity.backpressure)]
582
593
  : []),
@@ -723,6 +734,24 @@ export function localOverridesFromArtifact(
723
734
 
724
735
  /** Capacity is optional when no held dispatcher has a retrievable configuration
725
736
  * (`artifact` comes from `readHeldEffectiveConfig`). */
737
+ /** Every reported build's slot state, grouped held, requested and none,
738
+ * each group sorted by slug; `none` when no build is reported. Builds whose
739
+ * state is unknown are not listed. */
740
+ function slotsStatusLine(slots: Record<string, SlotState>): string {
741
+ const entries = Object.entries(slots).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
742
+ const label = (slug: string, slot: SlotState) =>
743
+ slot.state === 'requested'
744
+ ? `${slug} (${slot.request}${slot.priority !== undefined ? `, ${slot.priority}` : ''})`
745
+ : slug
746
+ const clauses = (['held', 'requested', 'none'] as const).flatMap((state) => {
747
+ const members = entries.filter(([, slot]) => slot.state === state)
748
+ return members.length
749
+ ? [`${state} ${members.map(([slug, slot]) => label(slug, slot)).join(', ')}`]
750
+ : []
751
+ })
752
+ return `slots: ${clauses.length ? clauses.join('; ') : 'none'}`
753
+ }
754
+
726
755
  export async function readRepositoryCapacity(
727
756
  store: BuildStore,
728
757
  repo: string,
@@ -739,26 +768,13 @@ export async function readRepositoryCapacity(
739
768
  // settled build, so this read stays flat as history accumulates.
740
769
  for (const { record, digest } of await store.listOpenBuilds(repo)) {
741
770
  if (digest.terminal) continue
742
- const build = (await readBuildFacts(store, record.slug)).value
743
- builds.push({
744
- record,
745
- state: build.state,
746
- workspace: build.workspace !== null,
747
- provisioning: build.provisionMarker !== undefined,
748
- restackDue: landingRestackDue(build.state, build.log),
749
- })
771
+ builds.push(capacityBuildFromFacts(record, (await readBuildFacts(store, record.slug)).value))
750
772
  }
751
- return dispatchCapacity(
752
- builds,
753
- config.capacity,
754
- now,
755
- migrationIdentity(facts.ticketMigrations, config.tickets.source),
756
- {
757
- urgentClaims: urgentClaimDemand(facts),
758
- startRequests: startClaimDemand(facts),
759
- openPrs: { policy: config.policy, engaged: facts.openPrBackpressure !== undefined },
760
- },
761
- )
773
+ return dispatchCapacity(builds, config.capacity, now, {
774
+ claims: claimDemand(facts),
775
+ startRequests: startClaimDemand(facts),
776
+ openPrs: { policy: config.policy, engaged: facts.openPrBackpressure !== undefined },
777
+ })
762
778
  }
763
779
 
764
780
  /**
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `openSessionlessStore` for callers that must not evaluate the remote adapter
3
+ * for a local reference. This is the only light-path module that resolves
4
+ * repository state (and with it configuration), so readers that already know
5
+ * their journal never load it.
6
+ */
7
+ import { resolveRepoState } from './repo-state'
8
+ import {
9
+ openStoreForRepoStateWith,
10
+ productionOpenerFor,
11
+ type OpenedStoreContext,
12
+ } from './production-store'
13
+ import type { SessionlessStoreOpts } from './store-opening'
14
+
15
+ export async function openSessionlessStoreLazily(
16
+ opts: SessionlessStoreOpts,
17
+ ): Promise<OpenedStoreContext> {
18
+ const state = await resolveRepoState({
19
+ targetRepo: opts.targetRepo,
20
+ exec: opts.exec,
21
+ ...(opts.storeRef !== undefined ? { storeRef: opts.storeRef } : {}),
22
+ ...(opts.env.AB_STORE !== undefined ? { envStore: opts.env.AB_STORE } : {}),
23
+ })
24
+ const opener = opts.openStore ?? (await productionOpenerFor(state.storeRef))
25
+ return openStoreForRepoStateWith(state, opts, opener)
26
+ }