@defrex/autobuild 1.10.0 → 1.11.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 (255) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +745 -69
  3. package/bin/ab-dispatch-generation.ts +3 -1
  4. package/docs/accounts.md +2 -1
  5. package/docs/answering-blocked-builds.md +20 -0
  6. package/docs/architecture.md +165 -29
  7. package/docs/build-store.md +10 -7
  8. package/docs/cli.md +33 -1
  9. package/docs/configuration-overview.md +4 -1
  10. package/docs/configuration.md +381 -29
  11. package/docs/dispatcher.md +64 -4
  12. package/docs/forges.md +7 -0
  13. package/docs/integration-tree.md +2 -2
  14. package/docs/operating.md +4 -2
  15. package/docs/operator-api.md +134 -6
  16. package/docs/operator-surfaces.md +85 -0
  17. package/docs/optimization-nodes.md +69 -11
  18. package/docs/plugin-authoring.md +37 -1
  19. package/docs/remote-store-protocol.md +94 -13
  20. package/docs/remote-ticket-protocol.md +40 -0
  21. package/docs/restacking.md +20 -4
  22. package/docs/setup.md +14 -2
  23. package/docs/ticket-dependencies.md +10 -3
  24. package/docs/ticket-sources.md +24 -2
  25. package/docs/tickets.md +7 -1
  26. package/docs/troubleshooting.md +8 -0
  27. package/docs/verification.md +4 -3
  28. package/docs/workspaces.md +3 -0
  29. package/package.json +9 -5
  30. package/packages/core/src/cli/accounts.ts +7 -2
  31. package/packages/core/src/cli/attention.ts +3 -1
  32. package/packages/core/src/cli/binary-direct.ts +2 -0
  33. package/packages/core/src/cli/binary-lifecycle.ts +2 -1
  34. package/packages/core/src/cli/build-control.ts +79 -1
  35. package/packages/core/src/cli/context.ts +4 -0
  36. package/packages/core/src/cli/dashboard/facts.ts +49 -53
  37. package/packages/core/src/cli/dashboard/header.ts +111 -0
  38. package/packages/core/src/cli/dashboard/model.ts +31 -39
  39. package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
  40. package/packages/core/src/cli/dashboard/poll.ts +179 -76
  41. package/packages/core/src/cli/dashboard/render.ts +159 -230
  42. package/packages/core/src/cli/dashboard/row-text.ts +538 -0
  43. package/packages/core/src/cli/dashboard/timeline.ts +288 -0
  44. package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
  45. package/packages/core/src/cli/dispatch-args.ts +44 -1
  46. package/packages/core/src/cli/dispatch-frontend.ts +40 -40
  47. package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
  48. package/packages/core/src/cli/dispatch-launcher.ts +20 -7
  49. package/packages/core/src/cli/dispatch-web.ts +155 -0
  50. package/packages/core/src/cli/dispatch.ts +202 -38
  51. package/packages/core/src/cli/help.ts +87 -3
  52. package/packages/core/src/cli/init-validation.ts +3 -3
  53. package/packages/core/src/cli/main.ts +70 -6
  54. package/packages/core/src/cli/mcp.ts +35 -3
  55. package/packages/core/src/cli/objective.ts +1 -1
  56. package/packages/core/src/cli/operator-preference.ts +57 -0
  57. package/packages/core/src/cli/repo-lease.ts +2 -0
  58. package/packages/core/src/cli/repo-state.ts +56 -6
  59. package/packages/core/src/cli/repository-status.ts +105 -49
  60. package/packages/core/src/cli/status.ts +82 -1
  61. package/packages/core/src/cli/terminal-restore.ts +32 -7
  62. package/packages/core/src/cli/ticket.ts +98 -36
  63. package/packages/core/src/cli/wait.ts +14 -6
  64. package/packages/core/src/cli/watch.ts +20 -4
  65. package/packages/core/src/cli/web.ts +139 -0
  66. package/packages/core/src/config/live.ts +99 -14
  67. package/packages/core/src/config/load.ts +61 -20
  68. package/packages/core/src/config/local.ts +212 -0
  69. package/packages/core/src/config/pipeline-source.ts +2 -0
  70. package/packages/core/src/config/reference.ts +18 -0
  71. package/packages/core/src/config/schema.ts +45 -10
  72. package/packages/core/src/events/catalog.ts +4 -0
  73. package/packages/core/src/events/payloads.ts +97 -0
  74. package/packages/core/src/events/policy.ts +10 -0
  75. package/packages/core/src/events/repository.ts +46 -3
  76. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +381 -30
  77. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
  78. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
  79. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
  80. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
  81. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
  82. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
  83. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
  84. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
  85. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
  86. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
  87. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
  88. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
  89. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
  90. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
  91. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
  92. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
  93. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
  94. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
  95. package/packages/core/src/kernel/build-roster.ts +230 -0
  96. package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
  97. package/packages/core/src/kernel/dispatch-status.ts +139 -0
  98. package/packages/core/src/kernel/engine.ts +43 -5
  99. package/packages/core/src/kernel/execution-intervals.ts +61 -0
  100. package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
  101. package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
  102. package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
  103. package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
  104. package/packages/core/src/kernel/log-index.ts +19 -0
  105. package/packages/core/src/kernel/optimization-admission.ts +244 -3
  106. package/packages/core/src/kernel/optimization.ts +183 -4
  107. package/packages/core/src/kernel/phase-failures.ts +121 -0
  108. package/packages/core/src/kernel/published-branch-head.ts +60 -0
  109. package/packages/core/src/kernel/read-facts.ts +15 -13
  110. package/packages/core/src/kernel/reducer-registry.ts +27 -8
  111. package/packages/core/src/kernel/reducer-revisions.ts +27 -0
  112. package/packages/core/src/kernel/reducer.ts +63 -4
  113. package/packages/core/src/kernel/rollup.ts +61 -0
  114. package/packages/core/src/kernel/setup-streak.ts +38 -0
  115. package/packages/core/src/kernel/step-durations.ts +257 -0
  116. package/packages/core/src/kernel/target-observation.ts +6 -1
  117. package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
  118. package/packages/core/src/kernel/verify-diff-base.ts +5 -0
  119. package/packages/core/src/kernel/verify-stages.ts +13 -3
  120. package/packages/core/src/ontology.ts +5 -0
  121. package/packages/core/src/operator/agent-context-serve.ts +631 -0
  122. package/packages/core/src/operator/annotations.ts +75 -5
  123. package/packages/core/src/operator/attention.ts +470 -0
  124. package/packages/core/src/operator/canonical-skills.ts +35 -0
  125. package/packages/core/src/operator/cli-equivalents.ts +270 -0
  126. package/packages/core/src/operator/context-prompts.ts +61 -0
  127. package/packages/core/src/operator/index.ts +49 -1
  128. package/packages/core/src/operator/landings.ts +28 -19
  129. package/packages/core/src/operator/optimization.ts +7 -0
  130. package/packages/core/src/operator/protocol.ts +3 -0
  131. package/packages/core/src/operator/query.ts +129 -74
  132. package/packages/core/src/operator/read-view.ts +5 -2
  133. package/packages/core/src/operator/registry.ts +406 -46
  134. package/packages/core/src/operator/requests.ts +20 -18
  135. package/packages/core/src/operator/sandbox-host.ts +107 -11
  136. package/packages/core/src/operator/sandbox-resolver.ts +253 -0
  137. package/packages/core/src/operator/sandbox.ts +778 -82
  138. package/packages/core/src/operator/ticket-asset-list.ts +77 -0
  139. package/packages/core/src/operator/ticket-assets.ts +167 -0
  140. package/packages/core/src/operator/tickets.ts +33 -2
  141. package/packages/core/src/plugin-sdk/index.ts +22 -0
  142. package/packages/core/src/plugins/manifest.ts +1 -1
  143. package/packages/core/src/ports/forge/fake.ts +92 -1
  144. package/packages/core/src/ports/forge/git-blob.ts +15 -0
  145. package/packages/core/src/ports/forge/github.ts +82 -0
  146. package/packages/core/src/ports/forge/local-git.ts +61 -1
  147. package/packages/core/src/ports/forge-failure.ts +24 -0
  148. package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
  149. package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
  150. package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
  151. package/packages/core/src/ports/tickets/contract.ts +71 -0
  152. package/packages/core/src/ports/tickets/fake.ts +11 -0
  153. package/packages/core/src/ports/tickets/file.ts +18 -0
  154. package/packages/core/src/ports/tickets/github-fake.ts +136 -4
  155. package/packages/core/src/ports/tickets/github.ts +387 -30
  156. package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
  157. package/packages/core/src/ports/tickets/linear.ts +130 -0
  158. package/packages/core/src/ports/tickets/priority.ts +9 -0
  159. package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
  160. package/packages/core/src/ports/tickets/remote.ts +70 -6
  161. package/packages/core/src/ports/tickets/search.ts +139 -0
  162. package/packages/core/src/ports/types.ts +104 -2
  163. package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
  164. package/packages/core/src/ports/workspace/create.ts +15 -1
  165. package/packages/core/src/ports/workspace/fake.ts +340 -12
  166. package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
  167. package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
  168. package/packages/core/src/ports/workspace/process-group.ts +48 -0
  169. package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
  170. package/packages/core/src/processes/agent-context-assemble.ts +576 -0
  171. package/packages/core/src/processes/agent-context.ts +469 -0
  172. package/packages/core/src/processes/build-runner.ts +387 -236
  173. package/packages/core/src/processes/dispatcher.ts +211 -55
  174. package/packages/core/src/processes/execution-no-progress.ts +4 -0
  175. package/packages/core/src/processes/optimization-activity.ts +120 -0
  176. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  177. package/packages/core/src/processes/repo-view.ts +78 -2
  178. package/packages/core/src/processes/sandbox-state.ts +53 -6
  179. package/packages/core/src/processes/tick-publication.ts +2 -0
  180. package/packages/core/src/processes/workspace-preparation.ts +76 -0
  181. package/packages/core/src/scenarios/harness.ts +0 -5
  182. package/packages/core/src/store/account-redaction.ts +1 -0
  183. package/packages/core/src/store/adapter.ts +52 -1
  184. package/packages/core/src/store/agent-context.ts +432 -0
  185. package/packages/core/src/store/build-feed.ts +291 -0
  186. package/packages/core/src/store/build-scope.ts +19 -1
  187. package/packages/core/src/store/contract.ts +911 -14
  188. package/packages/core/src/store/digest.ts +19 -6
  189. package/packages/core/src/store/histogram.ts +113 -0
  190. package/packages/core/src/store/local/schema.ts +62 -0
  191. package/packages/core/src/store/local/store.ts +628 -22
  192. package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
  193. package/packages/core/src/store/memory.ts +461 -69
  194. package/packages/core/src/store/open-builds.ts +19 -0
  195. package/packages/core/src/store/phase-session.ts +32 -4
  196. package/packages/core/src/store/reduced-reads.ts +14 -4
  197. package/packages/core/src/store/reducer-value-shapes.json +7027 -5751
  198. package/packages/core/src/store/reducer-values.ts +6 -1
  199. package/packages/core/src/store/remote/client.ts +208 -2
  200. package/packages/core/src/store/remote/compatibility.ts +1 -1
  201. package/packages/core/src/store/remote/index.ts +33 -0
  202. package/packages/core/src/store/remote/protocol.ts +69 -0
  203. package/packages/core/src/store/remote/released-clients.json +22 -0
  204. package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
  205. package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
  206. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  207. package/packages/core/src/store/retention.ts +23 -1
  208. package/packages/core/src/store/rollups.ts +337 -0
  209. package/packages/core/src/store/session-handle.ts +20 -2
  210. package/packages/core/src/store/snapshots.ts +10 -0
  211. package/packages/core/src/store/types.ts +108 -9
  212. package/packages/core/src/testing/dispatch-journals.ts +117 -0
  213. package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
  214. package/packages/core/src/testing/git-config-isolation.ts +7 -5
  215. package/packages/core/src/testing/index.ts +27 -0
  216. package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
  217. package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
  218. package/packages/core/src/web/analytics-source.ts +303 -0
  219. package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
  220. package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
  221. package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
  222. package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
  223. package/packages/core/src/web/assets/app.css +1 -0
  224. package/packages/core/src/web/assets/app.js +9 -0
  225. package/packages/core/src/web/assets/manifest.json +31 -0
  226. package/packages/core/src/web/assets/theme.js +1 -0
  227. package/packages/core/src/web/bounded.ts +31 -0
  228. package/packages/core/src/web/http.ts +315 -0
  229. package/packages/core/src/web/hub.ts +160 -0
  230. package/packages/core/src/web/options.ts +38 -0
  231. package/packages/core/src/web/overview-source.ts +322 -0
  232. package/packages/core/src/web/page.ts +56 -0
  233. package/packages/core/src/web/protocol.ts +151 -0
  234. package/packages/core/src/web/read-only.ts +23 -0
  235. package/packages/core/src/web/repository-source.ts +39 -0
  236. package/packages/core/src/web/server.ts +97 -0
  237. package/skills/code-review/SKILL.md +10 -2
  238. package/skills/guide/SKILL.md +376 -54
  239. package/skills/guide/references/accounts.md +2 -1
  240. package/skills/guide/references/integration-tree.md +2 -2
  241. package/skills/guide/references/operator-api.md +134 -6
  242. package/skills/guide/references/optimization-nodes.md +69 -11
  243. package/skills/guide/references/plugin-authoring.md +37 -1
  244. package/skills/guide/references/remote-store-protocol.md +94 -13
  245. package/skills/guide/references/remote-ticket-protocol.md +40 -0
  246. package/skills/guide/references/restacking.md +20 -4
  247. package/skills/guide/references/setup.md +14 -2
  248. package/skills/guide/references/ticket-dependencies.md +10 -3
  249. package/skills/implement/SKILL.md +23 -4
  250. package/skills/operate/SKILL.md +134 -32
  251. package/skills/plan/SKILL.md +10 -4
  252. package/skills/plan-review/SKILL.md +9 -2
  253. package/skills/spec/SKILL.md +34 -8
  254. package/skills/tickets/SKILL.md +51 -5
  255. package/templates/hosted-service/package.json +2 -2
@@ -0,0 +1,538 @@
1
+ /**
2
+ * The dashboard's shared row, header and overview text: what each row says,
3
+ * as plain data. The terminal renderer paints these values, and the web
4
+ * protocol carries the same ones, so a term changes here or nowhere.
5
+ *
6
+ * Pure projections over the existing `DashboardModel`: no IO, no clock, and no
7
+ * terminal escapes. Every value survives a JSON round trip unchanged (no
8
+ * `undefined` members), because web frames are compared serialized. Elapsed
9
+ * time travels as step `timing` and is formatted against the viewer's clock by
10
+ * `./vocabulary`, so a frame does not change every second.
11
+ *
12
+ * Layout (padding, truncation, wrapping, separators) stays with each frontend.
13
+ */
14
+ import { capacityExplanation } from '../../kernel/dispatch-capacity'
15
+ import type { BuildRosterFinished } from '../../kernel/build-roster'
16
+ import type { DispatchHealth } from '../../kernel/dispatch-status'
17
+ import { NO_DISPATCHER_RUN_LINE, activeCounterText } from './configuration'
18
+ import type { DashboardHandoff } from './handoff'
19
+ import type { IntegrationRow } from './integration-row'
20
+ import { mergeSummary, mergeVocabulary, mergedChildren } from './landing-display'
21
+ import type { DashboardBuild, DashboardHarvest, DashboardModel, PipelineStep } from './model'
22
+ import type { ObjectiveRow } from './objective-row'
23
+ import { treeVocabulary } from './tree'
24
+ import {
25
+ dispatchedByText,
26
+ dispatcherModeWord,
27
+ finishedOutcomeText,
28
+ statusText,
29
+ stepMark,
30
+ stepTone,
31
+ type DashboardTone,
32
+ type DispatcherMode,
33
+ type StatusText,
34
+ } from './vocabulary'
35
+
36
+ export interface ToneText {
37
+ text: string
38
+ tone: DashboardTone
39
+ }
40
+
41
+ /** A pipeline step with its glyph and tone. Timing stays raw for the clock. */
42
+ export type StepText = PipelineStep & { mark: string; tone: DashboardTone }
43
+
44
+ export type RowFlag = 'held' | 'draining' | 'paused'
45
+
46
+ export type RowAttentionKind = 'alert' | 'wait' | 'setup-error' | 'escalation'
47
+
48
+ export interface RowAttention extends ToneText {
49
+ kind: RowAttentionKind
50
+ }
51
+
52
+ export interface RowProgress {
53
+ /** Raw child counts for a progress bar. */
54
+ children: IntegrationRow['children']
55
+ /** Ordered count terms; the first is never preceded by a separator. */
56
+ counts: ToneText[]
57
+ verified: boolean
58
+ }
59
+
60
+ export interface DashboardRowText {
61
+ slug: string
62
+ ticketId?: string
63
+ /** The ticket's title. Ticket identity: the terminal row does not show it,
64
+ * and the web titles the row with it (Title First), falling back to the slug. */
65
+ title?: string
66
+ /** The ticket's address in its tracker. Ticket identity, as `title` is. */
67
+ ticketUrl?: string
68
+ kind: 'work' | 'integration'
69
+ status: StatusText
70
+ /** The label of the step currently running. */
71
+ phase?: string
72
+ /** Ordered parenthesised annotations beside the status. */
73
+ flags: { term: RowFlag; tone: DashboardTone }[]
74
+ /** Merge intent; absent for integration builds. */
75
+ merge?: ToneText
76
+ pr?: { text: string; url: string }
77
+ /** Destination and its distance suffix, raw text. */
78
+ target?: { destination: string; distance: string }
79
+ progress?: RowProgress
80
+ objective?: ObjectiveRow
81
+ tree?: string[]
82
+ ceiling?: string
83
+ steps: StepText[]
84
+ /** Shown in place of the steps while present. */
85
+ notice?: ToneText
86
+ attention: RowAttention[]
87
+ }
88
+
89
+ export interface HarvestRowText {
90
+ title: string
91
+ status: StatusText
92
+ observations: string
93
+ steps: StepText[]
94
+ detail?: ToneText
95
+ }
96
+
97
+ export interface HeaderCount {
98
+ label: 'triage' | 'queue' | 'active'
99
+ value: string
100
+ }
101
+
102
+ export interface HeaderGate {
103
+ label: 'intake' | 'harvest' | 'repository'
104
+ word: string
105
+ tone: DashboardTone
106
+ }
107
+
108
+ export interface DashboardHeaderText {
109
+ counts: HeaderCount[]
110
+ /** Why the active limit differs from the configured one. */
111
+ capacityNote?: string
112
+ gates: HeaderGate[]
113
+ }
114
+
115
+ export interface DispatcherModeText {
116
+ mode: DispatcherMode
117
+ word: string
118
+ tone: DashboardTone
119
+ detail?: string
120
+ }
121
+
122
+ export type AttentionKind =
123
+ | 'escalation'
124
+ | 'setup-error'
125
+ | 'failure'
126
+ | 'consent'
127
+ | 'wait'
128
+ | 'harvest'
129
+
130
+ export interface AttentionItem extends ToneText {
131
+ kind: AttentionKind
132
+ slug?: string
133
+ ticketId?: string
134
+ }
135
+
136
+ export interface FinishedRowText {
137
+ slug: string
138
+ kind: 'work' | 'integration'
139
+ outcome: BuildRosterFinished['outcome']
140
+ word: string
141
+ tone: DashboardTone
142
+ completedAt: string
143
+ }
144
+
145
+ export interface DashboardOverview {
146
+ dispatcher: DispatcherModeText
147
+ header: DashboardHeaderText
148
+ attention: AttentionItem[]
149
+ active: DashboardRowText[]
150
+ queued: DashboardRowText[]
151
+ finished: FinishedRowText[]
152
+ harvest?: HarvestRowText
153
+ }
154
+
155
+ export const HARVEST_TITLE = 'Harvest'
156
+
157
+ const alertTone = (tone: 'red' | 'yellow'): DashboardTone => (tone === 'red' ? 'alert' : 'held')
158
+
159
+ function stepText(step: PipelineStep): StepText {
160
+ return {
161
+ label: step.label,
162
+ state: step.state,
163
+ ...(step.qualifier !== undefined ? { qualifier: step.qualifier } : {}),
164
+ ...(step.count !== undefined ? { count: step.count } : {}),
165
+ ...(step.timing !== undefined
166
+ ? {
167
+ timing: {
168
+ accumulatedMs: step.timing.accumulatedMs,
169
+ ...(step.timing.runningSince !== undefined
170
+ ? { runningSince: step.timing.runningSince }
171
+ : {}),
172
+ },
173
+ }
174
+ : {}),
175
+ ...(step.reason !== undefined ? { reason: step.reason } : {}),
176
+ mark: stepMark(step.state),
177
+ tone: stepTone(step.state),
178
+ }
179
+ }
180
+
181
+ function mergeTone(autoMerge: DashboardBuild['autoMerge']): DashboardTone {
182
+ if (autoMerge === 'enabled') return 'ok'
183
+ if (autoMerge === 'requested' || autoMerge === 'polling') return 'live'
184
+ if (autoMerge === 'cancelling' || autoMerge === 'human-merge') return 'held'
185
+ return 'pending'
186
+ }
187
+
188
+ export function reviewRoundCeilingText(build: DashboardBuild): string | undefined {
189
+ if (build.reviewRoundCeilings === undefined) return undefined
190
+ const values = [
191
+ ...(build.reviewRoundCeilings.plan !== undefined
192
+ ? [`plan ${build.reviewRoundCeilings.plan}`]
193
+ : []),
194
+ ...(build.reviewRoundCeilings.code !== undefined
195
+ ? [`code ${build.reviewRoundCeilings.code}`]
196
+ : []),
197
+ ]
198
+ return values.length === 0 ? undefined : `review round ceiling: ${values.join(', ')}`
199
+ }
200
+
201
+ /** An integration row's progress terms: child counts and verification. */
202
+ export function projectProgress(row: IntegrationRow): RowProgress {
203
+ const children = row.children
204
+ let counts: ToneText[] = [{ text: 'children unknown', tone: 'pending' }]
205
+ if (children.known) {
206
+ counts = children.total
207
+ ? [
208
+ { text: mergedChildren(children.landed, children.total), tone: 'ok' },
209
+ ...(children.building
210
+ ? [{ text: `${children.building} building`, tone: 'live' as const }]
211
+ : []),
212
+ ...(children.queued
213
+ ? [{ text: `${children.queued} queued`, tone: 'pending' as const }]
214
+ : []),
215
+ ]
216
+ : [{ text: 'no children yet', tone: 'pending' }]
217
+ }
218
+ return { children: { ...children }, counts, verified: row.verified }
219
+ }
220
+
221
+ function treeLines(build: DashboardBuild): string[] | undefined {
222
+ const tree = build.tree
223
+ if (!tree || (build.kind !== 'integration' && !tree.consent)) return undefined
224
+ return [
225
+ `${tree.branch ?? 'unknown branch'} · ${treeVocabulary.restack} ${tree.restack} · ${treeVocabulary.verify} ${tree.verification.current ? treeVocabulary.current : treeVocabulary.pending} · ${tree.reason ?? (tree.ready ? treeVocabulary.readyToLand : treeVocabulary.notReady)}`,
226
+ ...(tree.kind === 'node'
227
+ ? [
228
+ `${treeVocabulary.children} ${tree.children?.length ?? 'unknown'} · ${tree.completeness}${tree.diagnostics?.length ? ` · ${tree.diagnostics.join('; ')}` : ''}`,
229
+ ]
230
+ : []),
231
+ ]
232
+ }
233
+
234
+ /**
235
+ * Everything one build row says. Integration rows (an `integrationRow` is
236
+ * present) show their own steps, progress and alert, and hide the tree,
237
+ * ceiling, notice and blockers, as the terminal row does.
238
+ */
239
+ export function projectRowText(
240
+ build: DashboardBuild,
241
+ options: { repositoryPaused: boolean },
242
+ ): DashboardRowText {
243
+ const status = statusText(build.status)
244
+ const row = build.integrationRow
245
+ const steps = (row?.steps ?? build.steps).map(stepText)
246
+ const phase = steps.find((step) => step.state === 'current')?.label
247
+ const flags: DashboardRowText['flags'] = [
248
+ // A repository hold changes no build lifecycle state: QUEUED stays literal
249
+ // and only the rows the hold prevents from launching are annotated.
250
+ ...(options.repositoryPaused && build.status === 'queued'
251
+ ? [{ term: 'held' as const, tone: 'held' as const }]
252
+ : []),
253
+ ...(build.draining ? [{ term: 'draining' as const, tone: 'held' as const }] : []),
254
+ // Blocked overrides paused visually; the pause still rides along.
255
+ ...(build.alsoPaused ? [{ term: 'paused' as const, tone: 'held' as const }] : []),
256
+ ]
257
+ const destination = row?.destination ?? build.target
258
+ const distance = row?.parentDistance ?? build.targetDistance ?? '+?'
259
+ const ceiling = row ? undefined : reviewRoundCeilingText(build)
260
+ const tree = row ? undefined : treeLines(build)
261
+ const noticeText = row ? undefined : (build.abortProgress ?? build.dispatch)
262
+ const attention: RowAttention[] = row
263
+ ? row.alert
264
+ ? [
265
+ {
266
+ kind: 'alert',
267
+ tone: alertTone(row.alert.tone),
268
+ text: row.alert.text,
269
+ },
270
+ ]
271
+ : []
272
+ : [
273
+ ...(build.alert
274
+ ? [
275
+ {
276
+ kind: 'alert' as const,
277
+ tone: alertTone(build.alert.tone),
278
+ text: build.alert.text,
279
+ },
280
+ ]
281
+ : []),
282
+ // A ticket wait is held work, not a blocker.
283
+ ...(build.wait
284
+ ? [
285
+ {
286
+ kind: 'wait' as const,
287
+ tone: 'held' as const,
288
+ text: build.wait.text,
289
+ },
290
+ ]
291
+ : []),
292
+ ...(build.setupError !== undefined
293
+ ? [
294
+ {
295
+ kind: 'setup-error' as const,
296
+ tone: 'alert' as const,
297
+ text: build.setupError,
298
+ },
299
+ ]
300
+ : []),
301
+ ...build.blockers.map((text) => ({
302
+ kind: 'escalation' as const,
303
+ tone: 'alert' as const,
304
+ text,
305
+ })),
306
+ ]
307
+ return {
308
+ slug: build.slug,
309
+ ...(build.ticketId !== undefined ? { ticketId: build.ticketId } : {}),
310
+ ...(build.collectionIdentity?.title !== undefined
311
+ ? { title: build.collectionIdentity.title }
312
+ : {}),
313
+ ...(build.collectionIdentity?.url !== undefined
314
+ ? { ticketUrl: build.collectionIdentity.url }
315
+ : {}),
316
+ kind: build.kind === 'integration' ? 'integration' : 'work',
317
+ status,
318
+ ...(phase !== undefined ? { phase } : {}),
319
+ flags,
320
+ ...(build.kind !== 'integration'
321
+ ? {
322
+ merge: {
323
+ text: mergeSummary(build),
324
+ tone: mergeTone(build.autoMerge),
325
+ },
326
+ }
327
+ : {}),
328
+ ...(build.pr !== undefined ? { pr: { text: `PR ${build.pr.state}`, url: build.pr.url } } : {}),
329
+ ...(destination ? { target: { destination, distance } } : {}),
330
+ ...(row ? { progress: projectProgress(row) } : {}),
331
+ ...(row && build.objectiveRow ? { objective: build.objectiveRow } : {}),
332
+ ...(tree !== undefined ? { tree } : {}),
333
+ ...(ceiling !== undefined ? { ceiling } : {}),
334
+ steps,
335
+ ...(noticeText !== undefined ? { notice: { text: noticeText, tone: status.tone } } : {}),
336
+ attention,
337
+ }
338
+ }
339
+
340
+ export function projectHarvestRowText(harvest: DashboardHarvest): HarvestRowText {
341
+ const status = statusText(harvest.status)
342
+ return {
343
+ title: HARVEST_TITLE,
344
+ status,
345
+ observations: `${harvest.observations} observations`,
346
+ steps: harvest.steps.map(stepText),
347
+ ...(harvest.detail !== undefined
348
+ ? { detail: { text: harvest.detail, tone: status.tone } }
349
+ : {}),
350
+ }
351
+ }
352
+
353
+ const gateTone = (off: boolean): DashboardTone => (off ? 'held' : 'ok')
354
+
355
+ /** The header's counters, capacity note and repository gates. */
356
+ export function projectHeaderText(
357
+ model: Pick<
358
+ DashboardModel,
359
+ | 'triage'
360
+ | 'queued'
361
+ | 'active'
362
+ | 'configuration'
363
+ | 'capacity'
364
+ | 'drained'
365
+ | 'harvestPaused'
366
+ | 'repositoryPaused'
367
+ >,
368
+ ): DashboardHeaderText {
369
+ const capacityNote =
370
+ model.configuration === 'no-dispatcher-run'
371
+ ? ''
372
+ : capacityExplanation(model.capacity).trimStart()
373
+ return {
374
+ counts: [
375
+ {
376
+ label: 'triage',
377
+ value: model.triage === undefined ? '–' : String(model.triage),
378
+ },
379
+ { label: 'queue', value: String(model.queued) },
380
+ { label: 'active', value: activeCounterText(model) },
381
+ ],
382
+ ...(capacityNote !== '' ? { capacityNote } : {}),
383
+ gates: [
384
+ {
385
+ label: 'intake',
386
+ word: model.drained ? 'OFF' : 'ON',
387
+ tone: gateTone(model.drained),
388
+ },
389
+ {
390
+ label: 'harvest',
391
+ word: model.harvestPaused ? 'OFF' : 'ON',
392
+ tone: gateTone(model.harvestPaused),
393
+ },
394
+ ...(model.repositoryPaused
395
+ ? [
396
+ {
397
+ label: 'repository' as const,
398
+ word: 'PAUSED',
399
+ tone: 'held' as const,
400
+ },
401
+ ]
402
+ : []),
403
+ ],
404
+ }
405
+ }
406
+
407
+ /**
408
+ * The dispatcher's mode. An upgrade handoff outranks everything; then a
409
+ * dispatcher that is not up reads stopped, even for a viewer, because the mode
410
+ * describes the dispatcher rather than this process.
411
+ */
412
+ export function projectDispatcherMode(input: {
413
+ health?: DispatchHealth
414
+ viewer?: { dispatchedBy?: string }
415
+ handoffs?: readonly DashboardHandoff[]
416
+ configuration?: DashboardModel['configuration']
417
+ }): DispatcherModeText {
418
+ const mode = (m: DispatcherMode, detail?: string): DispatcherModeText => ({
419
+ mode: m,
420
+ ...dispatcherModeWord(m),
421
+ ...(detail !== undefined ? { detail } : {}),
422
+ })
423
+ if ((input.handoffs?.length ?? 0) > 0) return mode('handoff')
424
+ if (input.health === undefined || input.health === 'stopped' || input.health === 'failed') {
425
+ return mode(
426
+ 'stopped',
427
+ input.health === undefined || input.configuration === 'no-dispatcher-run'
428
+ ? NO_DISPATCHER_RUN_LINE
429
+ : undefined,
430
+ )
431
+ }
432
+ if (input.viewer !== undefined) {
433
+ return mode(
434
+ 'viewer',
435
+ input.viewer.dispatchedBy !== undefined
436
+ ? dispatchedByText(input.viewer.dispatchedBy)
437
+ : undefined,
438
+ )
439
+ }
440
+ return mode('running')
441
+ }
442
+
443
+ /**
444
+ * Everything waiting on an operator, red before yellow. Built from the builds
445
+ * themselves, so an integration row's hidden blockers are still listed. Within
446
+ * a tone, harvest comes first and builds keep model order.
447
+ */
448
+ export function projectAttention(
449
+ builds: readonly DashboardBuild[],
450
+ harvest?: DashboardHarvest,
451
+ ): AttentionItem[] {
452
+ const items: AttentionItem[] = []
453
+ if (harvest !== undefined && (harvest.status === 'escalated' || harvest.status === 'failed')) {
454
+ const status = statusText(harvest.status)
455
+ items.push({
456
+ kind: 'harvest',
457
+ tone: status.tone,
458
+ text: harvest.detail ?? status.word,
459
+ })
460
+ }
461
+ for (const build of builds) {
462
+ const identity = {
463
+ slug: build.slug,
464
+ ...(build.ticketId !== undefined ? { ticketId: build.ticketId } : {}),
465
+ }
466
+ for (const text of build.blockers)
467
+ items.push({ kind: 'escalation', tone: 'alert', text, ...identity })
468
+ if (build.setupError !== undefined)
469
+ items.push({
470
+ kind: 'setup-error',
471
+ tone: 'alert',
472
+ text: build.setupError,
473
+ ...identity,
474
+ })
475
+ const alert = build.alert ?? build.integrationRow?.alert
476
+ if (alert?.tone === 'red')
477
+ items.push({
478
+ kind: 'failure',
479
+ tone: 'alert',
480
+ text: alert.text,
481
+ ...identity,
482
+ })
483
+ if (build.tree?.consent)
484
+ items.push({
485
+ kind: 'consent',
486
+ tone: 'held',
487
+ text: mergeVocabulary.consent,
488
+ ...identity,
489
+ })
490
+ if (build.wait)
491
+ items.push({
492
+ kind: 'wait',
493
+ tone: 'held',
494
+ text: build.wait.text,
495
+ ...identity,
496
+ })
497
+ }
498
+ return [
499
+ ...items.filter((item) => item.tone === 'alert'),
500
+ ...items.filter((item) => item.tone !== 'alert'),
501
+ ]
502
+ }
503
+
504
+ /** One finished build. A roster `node` is the dashboard's integration kind. */
505
+ export function projectFinishedRow(entry: BuildRosterFinished): FinishedRowText {
506
+ const outcome = finishedOutcomeText(entry.outcome)
507
+ return {
508
+ slug: entry.slug,
509
+ kind: entry.kind === 'node' ? 'integration' : 'work',
510
+ outcome: entry.outcome,
511
+ word: outcome.word,
512
+ tone: outcome.tone,
513
+ completedAt: entry.completedAt,
514
+ }
515
+ }
516
+
517
+ /** The whole overview page as data. Pure: it performs no reads. */
518
+ export function projectOverview(
519
+ model: DashboardModel,
520
+ input: { health?: DispatchHealth; finished: readonly BuildRosterFinished[] },
521
+ ): DashboardOverview {
522
+ const row = (build: DashboardBuild) =>
523
+ projectRowText(build, { repositoryPaused: model.repositoryPaused })
524
+ return {
525
+ dispatcher: projectDispatcherMode({
526
+ ...(input.health !== undefined ? { health: input.health } : {}),
527
+ ...(model.viewer !== undefined ? { viewer: model.viewer } : {}),
528
+ ...(model.handoffs !== undefined ? { handoffs: model.handoffs } : {}),
529
+ ...(model.configuration !== undefined ? { configuration: model.configuration } : {}),
530
+ }),
531
+ header: projectHeaderText(model),
532
+ attention: projectAttention(model.builds, model.harvest),
533
+ active: model.builds.filter((build) => build.status !== 'queued').map(row),
534
+ queued: model.builds.filter((build) => build.status === 'queued').map(row),
535
+ finished: input.finished.map(projectFinishedRow),
536
+ ...(model.harvest !== undefined ? { harvest: projectHarvestRowText(model.harvest) } : {}),
537
+ }
538
+ }