@defrex/autobuild 0.14.0 → 1.0.0-beta.1

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 (173) hide show
  1. package/README.md +13 -6
  2. package/SPEC.md +657 -100
  3. package/docs/architecture.md +230 -5
  4. package/docs/assets/headline-wide.png +0 -0
  5. package/docs/configuration.md +118 -14
  6. package/docs/hosted-service.md +18 -0
  7. package/docs/integration-tree.md +117 -0
  8. package/docs/landing-policy.md +150 -0
  9. package/docs/mcp.md +24 -0
  10. package/docs/migration-1.0.md +68 -0
  11. package/docs/operator-api.md +19 -8
  12. package/docs/remote-store-protocol.md +30 -7
  13. package/docs/remote-ticket-protocol.md +26 -5
  14. package/docs/restacking.md +79 -0
  15. package/docs/setup.md +53 -6
  16. package/docs/ticket-dependencies.md +69 -0
  17. package/docs/ticket-migration.md +8 -0
  18. package/package.json +3 -3
  19. package/packages/core/src/cli/attention.ts +25 -2
  20. package/packages/core/src/cli/build-control.ts +65 -41
  21. package/packages/core/src/cli/context.ts +54 -2
  22. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  23. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  24. package/packages/core/src/cli/dashboard/live.ts +5 -0
  25. package/packages/core/src/cli/dashboard/model.ts +142 -18
  26. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  27. package/packages/core/src/cli/dashboard/refresh.ts +183 -0
  28. package/packages/core/src/cli/dashboard/render.ts +78 -28
  29. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  30. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  31. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  32. package/packages/core/src/cli/dispatch-frontend.ts +156 -105
  33. package/packages/core/src/cli/dispatch.ts +257 -139
  34. package/packages/core/src/cli/dispatcher-liveness.ts +15 -2
  35. package/packages/core/src/cli/help.ts +52 -33
  36. package/packages/core/src/cli/init-validation.ts +43 -2
  37. package/packages/core/src/cli/keyboard.ts +6 -0
  38. package/packages/core/src/cli/landings.ts +18 -0
  39. package/packages/core/src/cli/main.ts +49 -15
  40. package/packages/core/src/cli/mcp.ts +9 -0
  41. package/packages/core/src/cli/publication-settlement.ts +168 -2
  42. package/packages/core/src/cli/repository-status.ts +11 -0
  43. package/packages/core/src/cli/status.ts +72 -5
  44. package/packages/core/src/cli/terminal-restore.ts +54 -0
  45. package/packages/core/src/cli/terminal.ts +16 -2
  46. package/packages/core/src/cli/terminals.ts +98 -79
  47. package/packages/core/src/cli/ticket-editor.ts +10 -3
  48. package/packages/core/src/cli/ticket.ts +113 -18
  49. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  50. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  51. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  52. package/packages/core/src/cli/upgrade.ts +16 -0
  53. package/packages/core/src/cli/wait.ts +115 -19
  54. package/packages/core/src/cli/watch.ts +51 -12
  55. package/packages/core/src/config/landing.ts +22 -0
  56. package/packages/core/src/config/live.ts +1 -0
  57. package/packages/core/src/config/schema.ts +3 -0
  58. package/packages/core/src/events/catalog.ts +48 -3
  59. package/packages/core/src/events/payloads.ts +295 -6
  60. package/packages/core/src/events/repository.ts +31 -0
  61. package/packages/core/src/integration/harness.ts +10 -0
  62. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +1030 -239
  63. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  64. package/packages/core/src/kernel/auto-merge.ts +12 -3
  65. package/packages/core/src/kernel/build-identity.ts +94 -0
  66. package/packages/core/src/kernel/change-presence.ts +179 -0
  67. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  68. package/packages/core/src/kernel/engine.ts +89 -2
  69. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  70. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  71. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  72. package/packages/core/src/kernel/generators/repository-journals.ts +11 -0
  73. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  74. package/packages/core/src/kernel/integration-landing.ts +263 -0
  75. package/packages/core/src/kernel/integration-stack.ts +36 -0
  76. package/packages/core/src/kernel/integration-state.ts +135 -0
  77. package/packages/core/src/kernel/landing-policy.ts +47 -0
  78. package/packages/core/src/kernel/landing-publication.ts +41 -0
  79. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  80. package/packages/core/src/kernel/landing-state.ts +96 -0
  81. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  82. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  83. package/packages/core/src/kernel/log-index.ts +35 -5
  84. package/packages/core/src/kernel/node-landing.ts +439 -0
  85. package/packages/core/src/kernel/node-parent.ts +184 -0
  86. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  87. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  88. package/packages/core/src/kernel/node-restack.ts +274 -0
  89. package/packages/core/src/kernel/read-facts.ts +70 -3
  90. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  91. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  92. package/packages/core/src/kernel/reducer-registry.ts +16 -0
  93. package/packages/core/src/kernel/reducer.ts +121 -6
  94. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  95. package/packages/core/src/ontology.ts +9 -1
  96. package/packages/core/src/operator/annotations.ts +12 -0
  97. package/packages/core/src/operator/control.ts +6 -0
  98. package/packages/core/src/operator/index.ts +4 -0
  99. package/packages/core/src/operator/landings.ts +35 -0
  100. package/packages/core/src/operator/presentation.ts +1 -0
  101. package/packages/core/src/operator/protocol.ts +12 -3
  102. package/packages/core/src/operator/query.ts +3 -1
  103. package/packages/core/src/operator/registry.ts +48 -19
  104. package/packages/core/src/operator/requests.ts +1 -8
  105. package/packages/core/src/operator/tickets.ts +55 -9
  106. package/packages/core/src/plugins/load.ts +3 -4
  107. package/packages/core/src/ports/forge/contract.ts +91 -3
  108. package/packages/core/src/ports/forge/fake.ts +142 -4
  109. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  110. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  111. package/packages/core/src/ports/forge/github.ts +631 -35
  112. package/packages/core/src/ports/forge/local-git.ts +119 -5
  113. package/packages/core/src/ports/forge/readiness.ts +99 -0
  114. package/packages/core/src/ports/tickets/contract.ts +41 -0
  115. package/packages/core/src/ports/tickets/create.ts +8 -1
  116. package/packages/core/src/ports/tickets/fake.ts +32 -1
  117. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  118. package/packages/core/src/ports/tickets/file.ts +18 -1
  119. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  120. package/packages/core/src/ports/tickets/linear.ts +124 -4
  121. package/packages/core/src/ports/tickets/migration.ts +25 -1
  122. package/packages/core/src/ports/tickets/operations.ts +7 -2
  123. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  124. package/packages/core/src/ports/tickets/remote.ts +10 -1
  125. package/packages/core/src/ports/tickets/revision.ts +3 -1
  126. package/packages/core/src/ports/tickets/tree.ts +148 -0
  127. package/packages/core/src/ports/tickets/update.ts +15 -2
  128. package/packages/core/src/ports/types.ts +135 -5
  129. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  130. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  131. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  132. package/packages/core/src/processes/build-runner.ts +530 -23
  133. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  134. package/packages/core/src/processes/dispatcher.ts +2145 -203
  135. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  136. package/packages/core/src/processes/publication-state.ts +30 -5
  137. package/packages/core/src/processes/repo-view.ts +21 -2
  138. package/packages/core/src/store/build-scope.ts +18 -0
  139. package/packages/core/src/store/contract.ts +658 -0
  140. package/packages/core/src/store/digest.ts +52 -4
  141. package/packages/core/src/store/local/schema.ts +25 -13
  142. package/packages/core/src/store/local/store.ts +117 -1
  143. package/packages/core/src/store/memory.ts +62 -1
  144. package/packages/core/src/store/phase-session.ts +17 -0
  145. package/packages/core/src/store/reduced-reads.ts +2 -1
  146. package/packages/core/src/store/reducer-value-shapes.json +10707 -6440
  147. package/packages/core/src/store/remote/client.ts +45 -0
  148. package/packages/core/src/store/remote/compatibility.ts +25 -9
  149. package/packages/core/src/store/remote/protocol.ts +11 -0
  150. package/packages/core/src/store/repo-state-events.ts +2 -0
  151. package/packages/core/src/store/session-handle.ts +15 -0
  152. package/packages/core/src/store/subscribe.ts +1 -1
  153. package/packages/core/src/store/types.ts +34 -4
  154. package/packages/core/src/testing/index.ts +2 -0
  155. package/packages/core/src/testing/reduced-read-budget.ts +48 -8
  156. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  157. package/skills/guide/SKILL.md +117 -64
  158. package/skills/guide/references/integration-tree.md +117 -0
  159. package/skills/guide/references/landing-policy.md +150 -0
  160. package/skills/guide/references/migration-1.0.md +68 -0
  161. package/skills/guide/references/operator-api.md +12 -5
  162. package/skills/guide/references/plugin-authoring.md +42 -3
  163. package/skills/guide/references/remote-store-protocol.md +30 -7
  164. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  165. package/skills/guide/references/restacking.md +79 -0
  166. package/skills/guide/references/setup.md +53 -6
  167. package/skills/guide/references/ticket-dependencies.md +69 -0
  168. package/skills/guide/references/ticket-migration.md +8 -0
  169. package/skills/operate/SKILL.md +55 -5
  170. package/skills/reconcile/SKILL.md +55 -48
  171. package/skills/spec/SKILL.md +67 -1
  172. package/skills/tickets/SKILL.md +55 -2
  173. package/templates/autobuild.toml +3 -0
@@ -1,3 +1,13 @@
1
+ import { projectTree, treeVocabulary, type TreeProjection } from './tree'
2
+ export { treeVocabulary, consentQueue } from './tree'
3
+ import { landingAuthorized } from '../../kernel/landing-state'
4
+ import {
5
+ integrationComplete,
6
+ integrationFailed,
7
+ integrationCurrent,
8
+ integrationCycleVerified,
9
+ integrationNeedsRunner,
10
+ } from '../../kernel/integration-state'
1
11
  import type { RepositoryReadFacts } from '../../store/reduced-reads'
2
12
  /**
3
13
  * The dashboard's pure projection: `BuildState` → what the operator sees.
@@ -77,6 +87,7 @@ import {
77
87
  export type EffectiveStatus =
78
88
  | 'queued'
79
89
  | 'running'
90
+ | 'collecting'
80
91
  | 'pausing'
81
92
  | 'paused'
82
93
  | 'resuming'
@@ -146,6 +157,22 @@ export interface DashboardHarvest {
146
157
  }
147
158
 
148
159
  export interface DashboardBuild {
160
+ tree?: TreeProjection
161
+ kind?: 'integration' | 'work'
162
+ target?: string
163
+ integration?:
164
+ | 'reparenting'
165
+ | 'opening'
166
+ | 'empty'
167
+ | 'collecting'
168
+ | 'verifying'
169
+ | 'verification failed'
170
+ | 'awaiting consent'
171
+ | 'ready to land'
172
+ | 'human landing'
173
+ | 'fenced landing'
174
+ | 'unfenced landing'
175
+ | 'unverified landing'
149
176
  slug: string
150
177
  status: EffectiveStatus
151
178
  /** True when the build is BOTH paused and blocked: blocked wins the status
@@ -168,6 +195,7 @@ export interface DashboardBuild {
168
195
  /** Current-spec per-loop review budget overrides. */
169
196
  reviewRoundCeilings?: { plan?: number; code?: number }
170
197
  /** Native auto-merge desired/applied state. */
198
+ landing?: BuildState['landing']
171
199
  autoMerge: AutoMergeDisplay
172
200
  pr?: { url: string; state: PrLifecycle }
173
201
  /** Chronological session history projected from the retained raw log. */
@@ -330,6 +358,7 @@ function isVisible(status: EffectiveStatus | BuildState['status']): status is Ef
330
358
  return (
331
359
  status === 'queued' ||
332
360
  status === 'running' ||
361
+ status === 'collecting' ||
333
362
  status === 'pausing' ||
334
363
  status === 'paused' ||
335
364
  status === 'resuming' ||
@@ -340,6 +369,18 @@ function isVisible(status: EffectiveStatus | BuildState['status']): status is Ef
340
369
  }
341
370
 
342
371
  export function autoMergeDisplay(state: BuildState): AutoMergeDisplay {
372
+ if (state.landing?.decision || state.landing?.command) {
373
+ if (state.landing.command?.kind === 'hold' && !state.pr && !state.landing.native?.enabled)
374
+ return 'off'
375
+ if (state.landing.command?.kind === 'hold')
376
+ return state.landing.acknowledgedSeq === state.landing.command.seq ? 'off' : 'cancelling'
377
+ if (landingAuthorized(state.landing))
378
+ return state.landing.native?.enabled &&
379
+ state.landing.native.decisionSeq === state.landing.decision?.seq
380
+ ? 'enabled'
381
+ : 'requested'
382
+ return 'off'
383
+ }
343
384
  const { requested, commandSeq, applied } = state.autoMerge
344
385
  if (requested) {
345
386
  return applied?.enabled === true && applied.commandSeq === commandSeq ? 'enabled' : 'requested'
@@ -357,12 +398,7 @@ export function autoMergeDisplay(state: BuildState): AutoMergeDisplay {
357
398
  * so the terminal row/detail and the web row/detail say the same words, and
358
399
  * so it names the per-build control that unblocks the parked build. */
359
400
  export function autoMergeConsentReason(slug: string): string {
360
- return (
361
- `no auto-merge consent has been requested — request it with m on the build row or ` +
362
- '`ab auto-merge ' +
363
- slug +
364
- ' on`'
365
- )
401
+ return `Landing awaits consent — use ab land ${slug}; use ab hold ${slug} to withdraw consent`
366
402
  }
367
403
 
368
404
  /**
@@ -497,7 +533,7 @@ export function projectBuildFromFacts(
497
533
  ? 'running work stopped; abort cleanup pending or in progress'
498
534
  : undefined
499
535
 
500
- if (status === 'queued') {
536
+ if (status === 'queued' && state.kind !== 'node') {
501
537
  const created = dashboard.created
502
538
  const workspace = dashboard.workspaceProvisioned
503
539
  const released = dashboard.workspaceReleased
@@ -530,12 +566,15 @@ export function projectBuildFromFacts(
530
566
  : 'runner attachment pending'
531
567
  return {
532
568
  slug: record.slug,
569
+ ...buildVocabulary(state),
570
+ tree: projectTree(record, state, facts.log.restack, pipeline.verify.steps),
533
571
  status,
534
572
  alsoPaused: false,
535
573
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
536
574
  steps: [],
537
575
  dispatch,
538
576
  blockers: [],
577
+ landing: state.landing,
539
578
  autoMerge: autoMergeDisplay(state),
540
579
  sessions: projectSessions(dashboard.sessionEvents, streams),
541
580
  }
@@ -544,6 +583,8 @@ export function projectBuildFromFacts(
544
583
  if (abortProgress !== undefined) {
545
584
  return {
546
585
  slug: record.slug,
586
+ ...buildVocabulary(state),
587
+ tree: projectTree(record, state, facts.log.restack, pipeline.verify.steps),
547
588
  status,
548
589
  alsoPaused: false,
549
590
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
@@ -554,6 +595,7 @@ export function projectBuildFromFacts(
554
595
  state.reviewRoundCeilings.code !== undefined
555
596
  ? { reviewRoundCeilings: { ...state.reviewRoundCeilings } }
556
597
  : {}),
598
+ landing: state.landing,
557
599
  autoMerge: autoMergeDisplay(state),
558
600
  ...(state.pr !== undefined && state.prState !== undefined
559
601
  ? { pr: { url: state.pr.url, state: state.prState } }
@@ -816,15 +858,16 @@ export function projectBuildFromFacts(
816
858
  : { accumulatedMs: 0, runningSince: lastMs }
817
859
  steps.push(step('merge', false, mergeCurrent, { qualifier: 'waiting', timing: mergeTiming }))
818
860
  const autoMerge = autoMergeDisplay(state)
819
- // The parked no-consent reason: a merge-current build whose effective
820
- // auto-merge state is off will never merge without operator action, and the
821
- // step must say so (and name the control) wherever the pipeline renders.
822
- // Display-only; the deferral `mergeWaitReason` stays in `blockers`.
823
- if (mergeCurrent && autoMerge === 'off') {
824
- steps[steps.length - 1] = {
825
- ...steps[steps.length - 1]!,
826
- reason: autoMergeConsentReason(record.slug),
827
- }
861
+ // Only a recorded consent decision can ask the operator to land. A
862
+ // finalized PR may still be awaiting the dispatcher's readiness decision.
863
+ if (mergeCurrent && !landingAuthorized(state.landing)) {
864
+ const reason =
865
+ state.landing?.command?.kind === 'hold'
866
+ ? `Landing held — use ab land ${record.slug} when ready to release the hold`
867
+ : state.landing?.decision?.mode === 'consent'
868
+ ? autoMergeConsentReason(record.slug)
869
+ : 'Landing policy decision pending'
870
+ steps[steps.length - 1] = { ...steps[steps.length - 1]!, reason }
828
871
  }
829
872
 
830
873
  const setupError =
@@ -850,10 +893,31 @@ export function projectBuildFromFacts(
850
893
 
851
894
  return {
852
895
  slug: record.slug,
896
+ ...buildVocabulary(state),
897
+ tree: projectTree(record, state, facts.log.restack, pipeline.verify.steps),
853
898
  status,
854
899
  alsoPaused: state.status === 'paused' && status === 'blocked',
855
900
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
856
- steps,
901
+ steps:
902
+ state.kind === 'node'
903
+ ? [
904
+ step('spec', state.specRev !== undefined, false),
905
+ step('open', state.nodeOpened !== undefined, state.nodeOpened === undefined),
906
+ step(buildVocabulary(state).integration!, false, state.nodeOpened !== undefined),
907
+ step('merge', false, state.pr !== undefined, {
908
+ qualifier: 'waiting',
909
+ reason: !integrationComplete(state)
910
+ ? `integration incomplete${state.integration?.observation?.openChildren.length ? `: ${state.integration.observation.openChildren.join(', ')}` : ''}`
911
+ : integrationFailed(state)
912
+ ? 'verification failed; file a repair child targeting this node'
913
+ : !state.integration?.cycle || !integrationCycleVerified(state)
914
+ ? 'integration awaits verification'
915
+ : !landingAuthorized(state.landing)
916
+ ? 'integration awaits explicit per-build consent'
917
+ : 'integration awaits guarded landing',
918
+ }),
919
+ ]
920
+ : steps,
857
921
  ...(setupError !== undefined ? { setupError } : {}),
858
922
  blockers: [
859
923
  ...state.openEscalations.map((e) => e.question),
@@ -862,6 +926,7 @@ export function projectBuildFromFacts(
862
926
  ...(state.reviewRoundCeilings.plan !== undefined || state.reviewRoundCeilings.code !== undefined
863
927
  ? { reviewRoundCeilings: { ...state.reviewRoundCeilings } }
864
928
  : {}),
929
+ landing: state.landing,
865
930
  autoMerge,
866
931
  ...(state.pr !== undefined && state.prState !== undefined
867
932
  ? { pr: { url: state.pr.url, state: state.prState } }
@@ -1163,7 +1228,11 @@ export function buildDashboard(
1163
1228
  .map(({ record, state, events }) => projectBuild(record, state, config, events))
1164
1229
  .filter((build): build is DashboardBuild => build !== null)
1165
1230
  const activeCount = entries.filter(
1166
- ({ state }) => state.status !== 'done' && state.status !== 'aborted',
1231
+ ({ state }) =>
1232
+ (state.kind !== 'node' ||
1233
+ (integrationNeedsRunner(state) && state.phase?.startsWith('verify:'))) &&
1234
+ state.status !== 'done' &&
1235
+ state.status !== 'aborted',
1167
1236
  ).length
1168
1237
  return buildDashboardFromProjected(
1169
1238
  builds,
@@ -1176,3 +1245,58 @@ export function buildDashboard(
1176
1245
  repositoryEvents,
1177
1246
  )
1178
1247
  }
1248
+
1249
+ /** One vocabulary for CLI, terminal, web and operator reads. */
1250
+ export function buildVocabulary(state: BuildState): {
1251
+ kind?: 'integration' | 'work'
1252
+ target?: string
1253
+ integration?:
1254
+ | 'reparenting'
1255
+ | 'opening'
1256
+ | 'empty'
1257
+ | 'collecting'
1258
+ | 'verifying'
1259
+ | 'verification failed'
1260
+ | 'awaiting consent'
1261
+ | 'ready to land'
1262
+ | 'human landing'
1263
+ | 'fenced landing'
1264
+ | 'unfenced landing'
1265
+ | 'unverified landing'
1266
+ } {
1267
+ return {
1268
+ kind: state.kind === 'node' ? treeVocabulary.integrationKind : treeVocabulary.work,
1269
+ ...(state.target?.ticket.id || state.baseBranch
1270
+ ? { target: state.target?.ticket.id ?? state.baseBranch }
1271
+ : {}),
1272
+ ...(state.kind === 'node'
1273
+ ? {
1274
+ integration:
1275
+ state.integration?.audit &&
1276
+ state.integration.audit.verifiedTree !== state.integration.audit.landedTree
1277
+ ? 'unverified landing'
1278
+ : state.integration?.landing?.provenance === 'human'
1279
+ ? 'human landing'
1280
+ : state.integration?.landing
1281
+ ? state.integration.landing.fenced
1282
+ ? 'fenced landing'
1283
+ : 'unfenced landing'
1284
+ : state.nodeRestack?.parentRequest || state.nodeRestack?.parentChange
1285
+ ? 'reparenting'
1286
+ : integrationFailed(state)
1287
+ ? 'verification failed'
1288
+ : integrationCurrent(state) && integrationComplete(state)
1289
+ ? !integrationCycleVerified(state)
1290
+ ? 'verifying'
1291
+ : landingAuthorized(state.landing)
1292
+ ? treeVocabulary.readyToLand
1293
+ : `awaiting ${treeVocabulary.consent}`
1294
+ : !state.nodeOpened
1295
+ ? 'opening'
1296
+ : !state.pr && (state.nodeComparison?.ahead ?? 0) === 0
1297
+ ? 'empty'
1298
+ : 'collecting',
1299
+ }
1300
+ : {}),
1301
+ }
1302
+ }
@@ -18,7 +18,7 @@ import { projectBuild, type DashboardBuild } from './model'
18
18
  * metadata decorates each row with its pinned pipeline source and revision
19
19
  * (SPEC §16.1). */
20
20
  export interface DashboardBuildReader {
21
- listBuilds(): Promise<BuildRecord[]>
21
+ listBuildsForRepo(repo: string): Promise<BuildRecord[]>
22
22
  getEvents(slug: string, sinceSeq?: number): Promise<AbEvent[]>
23
23
  listStreams?(scope: StreamScope): Promise<StreamRecord[]>
24
24
  getArtifact?(slug: string, kind: string): Promise<Artifact | null>
@@ -81,7 +81,7 @@ function validateDelta(slug: string, sinceSeq: number, events: AbEvent[]): void
81
81
  /**
82
82
  * Process-local, display-only acceleration for the interactive dispatch frame.
83
83
  *
84
- * Every refresh still discovers records with `listBuilds()`. A first-seen
84
+ * Every refresh still discovers records with `listBuildsForRepo(repo)`. A first-seen
85
85
  * stream is hydrated from seq 0; a cached dashboard-visible stream is read only
86
86
  * after its reduced `lastSeq`. Empty deltas preserve the exact reduction and
87
87
  * projected row, so phase timing is not recomputed. Only fully completed
@@ -180,8 +180,11 @@ export class DashboardBuildPollCache {
180
180
  refresh(
181
181
  config: Config = this.config,
182
182
  configRevision = this.configRevision,
183
+ fullEnrichment = false,
183
184
  ): Promise<DashboardPollSnapshot> {
184
- const result = this.refreshTail.then(() => this.refreshNow(config, configRevision))
185
+ const result = this.refreshTail.then(() =>
186
+ this.refreshNow(config, configRevision, fullEnrichment),
187
+ )
185
188
  this.refreshTail = result.then(
186
189
  () => undefined,
187
190
  () => undefined,
@@ -189,9 +192,13 @@ export class DashboardBuildPollCache {
189
192
  return result
190
193
  }
191
194
 
192
- private async refreshNow(config: Config, configRevision: number): Promise<DashboardPollSnapshot> {
195
+ private async refreshNow(
196
+ config: Config,
197
+ configRevision: number,
198
+ fullEnrichment: boolean,
199
+ ): Promise<DashboardPollSnapshot> {
193
200
  const configChanged = configRevision !== this.configRevision || config !== this.config
194
- const records = (await this.reader.listBuilds()).filter((record) => record.repo === this.repo)
201
+ const records = await this.reader.listBuildsForRepo(this.repo)
195
202
  const next = new Map<string, PollEntry>()
196
203
 
197
204
  for (const record of records) {
@@ -206,12 +213,11 @@ export class DashboardBuildPollCache {
206
213
  validateDelta(record.slug, sinceSeq, delta)
207
214
 
208
215
  if (current !== undefined && delta.length === 0) {
209
- // Dashboard rows derive from event streams and effective config only.
210
- // Heartbeat and lease renewals are mutable record facts, so they leave
211
- // both the cached reduction and projected row untouched.
216
+ // Preserve the reduction on empty deltas. Bounded full refreshes also
217
+ // reload mutable record, stream and artifact enrichment.
212
218
  next.set(
213
219
  record.slug,
214
- configChanged || current.build?.ticketId !== record.ticket?.id
220
+ fullEnrichment || configChanged || current.build?.ticketId !== record.ticket?.id
215
221
  ? {
216
222
  ...current,
217
223
  build: await this.projectRow(record, current.state, current.events, config),
@@ -0,0 +1,183 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks'
2
+
3
+ const readIntent = new AsyncLocalStorage<boolean>()
4
+
5
+ /** Reads needed by an explicitly requested action may finish while unfocused. */
6
+ export function interactionRead<T>(operation: () => T): T {
7
+ return readIntent.run(true, operation)
8
+ }
9
+
10
+ /** Presentation-only read scheduling. Kernel timers never use this controller. */
11
+ export interface RefreshScheduler {
12
+ now(): number
13
+ set(callback: () => void, delay: number): unknown
14
+ clear(handle: unknown): void
15
+ }
16
+ const scheduler: RefreshScheduler = {
17
+ now: Date.now,
18
+ set: (callback, delay) => {
19
+ const timer = setTimeout(callback, delay)
20
+ timer.unref?.()
21
+ return timer
22
+ },
23
+ clear: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),
24
+ }
25
+
26
+ export class DashboardRefresh {
27
+ private focused = true
28
+ private active = true
29
+ private suspended = false
30
+ private live = true // Unknown startup activity retries quickly.
31
+ private deadline = -Infinity
32
+ private started = -Infinity
33
+ private timer: unknown
34
+ private flight: Promise<void> | undefined
35
+ private generation = 0
36
+ private permit: number | undefined
37
+ private wake = false
38
+
39
+ constructor(
40
+ private readonly refresh: () => Promise<void>,
41
+ private readonly time: RefreshScheduler = scheduler,
42
+ private readonly networkReads = false,
43
+ ) {}
44
+
45
+ get painting(): boolean {
46
+ return !this.suspended
47
+ }
48
+
49
+ get isFocused(): boolean {
50
+ return this.focused && !this.suspended
51
+ }
52
+
53
+ get admitted(): boolean {
54
+ return this.active && !this.suspended
55
+ }
56
+
57
+ activity(live: boolean): void {
58
+ this.live = live
59
+ }
60
+
61
+ focus(focused: boolean): void {
62
+ if (this.focused === focused) return
63
+ this.focused = focused
64
+ if (focused) void this.request()
65
+ else if (this.networkReads) {
66
+ this.cancel()
67
+ if (this.flight === undefined) this.schedule()
68
+ }
69
+ }
70
+
71
+ interaction(): void {
72
+ this.deadline = this.time.now() + 30_000
73
+ void this.request(true)
74
+ }
75
+
76
+ suspend(): void {
77
+ this.suspended = true
78
+ this.generation += 1
79
+ this.cancel()
80
+ }
81
+
82
+ resume(): void {
83
+ this.suspended = false
84
+ this.focused = true
85
+ void this.request()
86
+ }
87
+
88
+ stop(): void {
89
+ this.active = false
90
+ this.generation += 1
91
+ this.cancel()
92
+ }
93
+
94
+ async join(): Promise<void> {
95
+ await this.flight
96
+ }
97
+
98
+ /** One final focused snapshot, after input and scheduled polling are closed. */
99
+ async finalRefresh(): Promise<void> {
100
+ await this.join()
101
+ if (!this.focused || this.suspended) return
102
+ this.active = true
103
+ try {
104
+ await this.request()
105
+ } finally {
106
+ this.stop()
107
+ }
108
+ }
109
+
110
+ request(interaction = false): Promise<void> {
111
+ if (!this.active || this.suspended) return Promise.resolve()
112
+ if (this.flight !== undefined) {
113
+ // Retain an explicit wakeup that arrives during outstanding I/O.
114
+ if (interaction || this.permit !== this.generation) this.wake = true
115
+ return this.flight
116
+ }
117
+ this.cancel()
118
+ this.wake = false
119
+ this.started = this.time.now()
120
+ this.permit = this.generation
121
+ const current = Promise.resolve()
122
+ .then(() => readIntent.run(false, this.refresh))
123
+ .catch(() => {})
124
+ .finally(() => {
125
+ if (this.flight !== current) return
126
+ this.flight = undefined
127
+ this.permit = undefined
128
+ if (this.wake && this.active && !this.suspended) {
129
+ this.wake = false
130
+ void this.request()
131
+ } else this.schedule()
132
+ })
133
+ this.flight = current
134
+ return current
135
+ }
136
+
137
+ private cancel(): void {
138
+ if (this.timer !== undefined) this.time.clear(this.timer)
139
+ this.timer = undefined
140
+ }
141
+
142
+ /** Current admission cadence, also used to bound presentation staleness. */
143
+ get intervalMs(): number {
144
+ if (this.networkReads && !this.focused) return 5000
145
+ return this.live || this.time.now() < this.deadline ? 500 : 5000
146
+ }
147
+
148
+ private schedule(): void {
149
+ if (!this.active || this.suspended) return
150
+ const interval = this.intervalMs
151
+ // Slow/failing requests do not spin when their start deadline is overdue.
152
+ const remaining = Number.isFinite(this.started)
153
+ ? this.started + interval - this.time.now()
154
+ : interval
155
+ const delay = remaining > 0 ? remaining : this.networkReads && !this.focused ? interval : 50
156
+ this.timer = this.time.set(() => {
157
+ this.timer = undefined
158
+ void this.request()
159
+ }, delay)
160
+ }
161
+ }
162
+
163
+ /** Guard each asynchronous read stage, including reads inside shared caches.
164
+ * Operator mutations keep their original store; only presentation readers use
165
+ * this facade. Suspension and stop fence subsequent read stages. */
166
+ export function presentationReader<T extends object>(store: T, admitted: () => boolean): T {
167
+ return new Proxy(store, {
168
+ get(target, key, receiver) {
169
+ const value = Reflect.get(target, key, receiver)
170
+ if (typeof value !== 'function') return value
171
+ return (...args: unknown[]) => {
172
+ if (
173
+ /^(get|list|read|load)/u.test(String(key)) &&
174
+ !admitted() &&
175
+ readIntent.getStore() !== true
176
+ ) {
177
+ return Promise.reject(new Error('dashboard presentation read paused'))
178
+ }
179
+ return Reflect.apply(value, target, args)
180
+ }
181
+ },
182
+ })
183
+ }