@defrex/autobuild 1.3.0 → 1.4.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.
- package/README.md +1 -1
- package/SPEC.md +307 -27
- package/docs/accounts.md +38 -0
- package/docs/architecture.md +198 -25
- package/docs/build-store.md +18 -0
- package/docs/builds.md +5 -1
- package/docs/cli.md +1 -1
- package/docs/configuration.md +38 -19
- package/docs/dispatcher-hosting.md +42 -0
- package/docs/dispatcher.md +41 -0
- package/docs/forges.md +5 -0
- package/docs/integration-tree.md +8 -0
- package/docs/operating.md +11 -3
- package/docs/operator-api.md +37 -4
- package/docs/plugin-authoring.md +45 -1
- package/docs/remote-store-protocol.md +262 -42
- package/docs/remote-ticket-protocol.md +12 -10
- package/docs/restacking.md +60 -3
- package/docs/setup.md +37 -8
- package/docs/skills.md +1 -1
- package/docs/spec-standard.md +37 -3
- package/docs/troubleshooting.md +9 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -3
- package/packages/core/src/accounts/availability.ts +96 -0
- package/packages/core/src/accounts/local-owner.ts +49 -2
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +62 -0
- package/packages/core/src/cli/dashboard/model.ts +12 -3
- package/packages/core/src/cli/dashboard/poll.ts +65 -8
- package/packages/core/src/cli/dashboard/refresh.ts +2 -0
- package/packages/core/src/cli/dashboard/render.ts +46 -5
- package/packages/core/src/cli/dispatch-args.ts +27 -3
- package/packages/core/src/cli/dispatch-frontend.ts +187 -53
- package/packages/core/src/cli/dispatch-mode.ts +94 -0
- package/packages/core/src/cli/dispatch-preflight.ts +43 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +45 -9
- package/packages/core/src/cli/dispatch.ts +145 -11
- package/packages/core/src/cli/harvest.ts +2 -1
- package/packages/core/src/cli/help.ts +16 -3
- package/packages/core/src/cli/historical-build-state.ts +6 -0
- package/packages/core/src/cli/main.ts +15 -2
- package/packages/core/src/cli/publication-settlement.ts +17 -0
- package/packages/core/src/cli/remote-poll.ts +11 -1
- package/packages/core/src/cli/repository-status.ts +11 -0
- package/packages/core/src/cli/status.ts +7 -1
- package/packages/core/src/cli/wait.ts +9 -2
- package/packages/core/src/cli/watch.ts +38 -3
- package/packages/core/src/config/roles.ts +16 -1
- package/packages/core/src/events/catalog.ts +7 -0
- package/packages/core/src/events/payloads.ts +85 -2
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +35 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +189 -0
- package/packages/core/src/kernel/dispatch-placement.ts +30 -0
- package/packages/core/src/kernel/engine.ts +19 -12
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +17 -1
- package/packages/core/src/kernel/leaf-restack-state.ts +24 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +27 -10
- package/packages/core/src/kernel/node-restack-demand.ts +1 -0
- package/packages/core/src/kernel/node-restack-state.ts +16 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +14 -0
- package/packages/core/src/kernel/read-facts.ts +114 -9
- package/packages/core/src/kernel/reconcile-head.ts +34 -11
- package/packages/core/src/kernel/reconcile-restack.ts +106 -72
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer.ts +20 -2
- package/packages/core/src/kernel/replay-retention.ts +176 -0
- package/packages/core/src/kernel/target-lineage.ts +65 -0
- package/packages/core/src/kernel/target-observation.ts +117 -0
- package/packages/core/src/operator/registry.ts +5 -13
- package/packages/core/src/operator/tickets.ts +8 -2
- package/packages/core/src/plugin-sdk/index.ts +1 -0
- package/packages/core/src/ports/forge/fake.ts +22 -0
- package/packages/core/src/ports/forge/git-rewrite.ts +49 -12
- package/packages/core/src/ports/forge/github.ts +42 -10
- package/packages/core/src/ports/forge/local-git.ts +16 -1
- package/packages/core/src/ports/types.ts +58 -4
- package/packages/core/src/ports/workspace/account-policy.ts +2 -1
- package/packages/core/src/ports/workspace/commit-preservation.ts +175 -0
- package/packages/core/src/ports/workspace/create.ts +2 -0
- package/packages/core/src/ports/workspace/distribution-archive.ts +14 -4
- package/packages/core/src/ports/workspace/fake.ts +4 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +22 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +304 -56
- package/packages/core/src/processes/build-runner.ts +240 -111
- package/packages/core/src/processes/dispatcher-selectors.ts +3 -2
- package/packages/core/src/processes/dispatcher.ts +262 -80
- package/packages/core/src/processes/execution-no-progress.ts +7 -0
- package/packages/core/src/processes/harvest-runner.ts +6 -7
- package/packages/core/src/processes/publication-state.ts +2 -1
- package/packages/core/src/processes/repo-view.ts +22 -0
- package/packages/core/src/processes/tick-publication.ts +35 -47
- package/packages/core/src/processes/workspace-preservation.ts +164 -0
- package/packages/core/src/scenarios/harness.ts +7 -0
- package/packages/core/src/store/adapter.ts +9 -0
- package/packages/core/src/store/build-scope.ts +28 -0
- package/packages/core/src/store/contract.ts +125 -0
- package/packages/core/src/store/event-reads.ts +156 -0
- package/packages/core/src/store/local/schema.ts +11 -0
- package/packages/core/src/store/local/store.ts +117 -2
- package/packages/core/src/store/memory.ts +237 -0
- package/packages/core/src/store/phase-session.ts +47 -0
- package/packages/core/src/store/reduced-reads.ts +8 -0
- package/packages/core/src/store/reducer-value-shapes.json +6262 -5227
- package/packages/core/src/store/reducer-value-validation.ts +3 -0
- package/packages/core/src/store/reducer-values.ts +62 -2
- package/packages/core/src/store/remote/client.ts +161 -16
- package/packages/core/src/store/remote/compatibility.ts +177 -46
- package/packages/core/src/store/remote/errors.ts +16 -0
- package/packages/core/src/store/remote/index.ts +11 -0
- package/packages/core/src/store/remote/protocol.ts +22 -0
- package/packages/core/src/store/remote/released-clients.json +48 -0
- package/packages/core/src/store/remote/released-clients.ts +88 -0
- package/packages/core/src/store/remote/released-reducer-values/1.3.0.json +25093 -0
- package/packages/core/src/store/remote/released-reducer-values/1.4.0.json +26128 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +13 -0
- package/packages/core/src/store/remote/version.ts +5 -2
- package/packages/core/src/store/repo-state-events.ts +4 -3
- package/packages/core/src/store/scan-cadence.ts +15 -0
- package/packages/core/src/store/session-handle.ts +18 -0
- package/packages/core/src/store/types.ts +27 -6
- package/packages/core/src/testing/dispatch-read-budget.ts +313 -2
- package/packages/core/src/testing/index.ts +5 -0
- package/packages/core/src/testing/reduced-read-budget.ts +728 -5
- package/skills/guide/SKILL.md +201 -18
- package/skills/guide/references/accounts.md +38 -0
- package/skills/guide/references/integration-tree.md +8 -0
- package/skills/guide/references/operator-api.md +37 -4
- package/skills/guide/references/plugin-authoring.md +45 -1
- package/skills/guide/references/remote-store-protocol.md +262 -42
- package/skills/guide/references/remote-ticket-protocol.md +12 -10
- package/skills/guide/references/restacking.md +60 -3
- package/skills/guide/references/setup.md +37 -8
- package/skills/guide/references/spec-standard.md +37 -3
- package/skills/implement/SKILL.md +12 -3
- package/skills/operate/SKILL.md +87 -15
- package/skills/plan/SKILL.md +27 -4
- package/skills/plan-review/SKILL.md +22 -2
- package/skills/reconcile/SKILL.md +10 -1
- package/skills/spec/SKILL.md +7 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -40,6 +40,7 @@ export class DashboardRefresh {
|
|
|
40
40
|
private readonly refresh: () => Promise<void>,
|
|
41
41
|
private readonly time: RefreshScheduler = scheduler,
|
|
42
42
|
private readonly networkReads = false,
|
|
43
|
+
private readonly cadenceMs?: number,
|
|
43
44
|
) {}
|
|
44
45
|
|
|
45
46
|
get painting(): boolean {
|
|
@@ -141,6 +142,7 @@ export class DashboardRefresh {
|
|
|
141
142
|
|
|
142
143
|
/** Current admission cadence, also used to bound presentation staleness. */
|
|
143
144
|
get intervalMs(): number {
|
|
145
|
+
if (this.cadenceMs !== undefined) return this.cadenceMs
|
|
144
146
|
if (this.networkReads && !this.focused) return 5000
|
|
145
147
|
return this.live || this.time.now() < this.deadline ? 500 : 5000
|
|
146
148
|
}
|
|
@@ -557,6 +557,15 @@ export const DASHBOARD_SESSION_LIVE_LEGEND =
|
|
|
557
557
|
export const DASHBOARD_SESSION_PAUSED_LEGEND =
|
|
558
558
|
'Keys: Up/Down scroll (paused) Esc back Ctrl-C quit'
|
|
559
559
|
|
|
560
|
+
function modeLegend(model: DashboardModel, legend: string): string {
|
|
561
|
+
return model.viewer
|
|
562
|
+
? legend
|
|
563
|
+
.replace('Up/Down select', 'Up/Down')
|
|
564
|
+
.replace('Ctrl-C quit', 'Ctrl-C close viewer')
|
|
565
|
+
.replace(/ {2}/g, ' ')
|
|
566
|
+
: legend
|
|
567
|
+
}
|
|
568
|
+
|
|
560
569
|
function buildLegend(build: DashboardBuild, detail: boolean): string {
|
|
561
570
|
if (build.status === 'aborting' || build.status === 'cleaning') {
|
|
562
571
|
return detail
|
|
@@ -1026,7 +1035,7 @@ function renderDetail(model: DashboardModel, opts: RenderOpts): string[] {
|
|
|
1026
1035
|
const controls =
|
|
1027
1036
|
model.resumeInput !== undefined || model.abortConfirmation !== undefined
|
|
1028
1037
|
? dashboardControls(model, color, width, controlsCapacity(height, top.length))
|
|
1029
|
-
: [truncate(paint(buildLegend(build, true), 'dim', color), width)]
|
|
1038
|
+
: [truncate(paint(modeLegend(model, buildLegend(build, true)), 'dim', color), width)]
|
|
1030
1039
|
if (height !== undefined && height <= 0) return []
|
|
1031
1040
|
if (height !== undefined && height <= top.length) return top.slice(0, height)
|
|
1032
1041
|
if (height !== undefined && height === top.length + 1) return [...top, ...controls]
|
|
@@ -1134,7 +1143,7 @@ function renderTranscript(model: DashboardModel, opts: RenderOpts): string[] {
|
|
|
1134
1143
|
]
|
|
1135
1144
|
const content = transcriptContent(view.transcript, width).map((line) => truncate(line, width))
|
|
1136
1145
|
const controls = truncate(
|
|
1137
|
-
paint('Keys: Up/Down scroll Esc back Ctrl-C quit', 'dim', color),
|
|
1146
|
+
paint(modeLegend(model, 'Keys: Up/Down scroll Esc back Ctrl-C quit'), 'dim', color),
|
|
1138
1147
|
width,
|
|
1139
1148
|
)
|
|
1140
1149
|
if (height !== undefined && height <= 0) return []
|
|
@@ -1212,7 +1221,10 @@ function renderSessionView(model: DashboardModel, opts: RenderOpts): string[] {
|
|
|
1212
1221
|
const content = sessionContentLines(view, width).map((line) => truncate(line, width))
|
|
1213
1222
|
const controls = truncate(
|
|
1214
1223
|
paint(
|
|
1215
|
-
|
|
1224
|
+
modeLegend(
|
|
1225
|
+
model,
|
|
1226
|
+
view.follow ? DASHBOARD_SESSION_LIVE_LEGEND : DASHBOARD_SESSION_PAUSED_LEGEND,
|
|
1227
|
+
),
|
|
1216
1228
|
'dim',
|
|
1217
1229
|
color,
|
|
1218
1230
|
),
|
|
@@ -1562,7 +1574,7 @@ function dashboardControls(
|
|
|
1562
1574
|
? DASHBOARD_HARVEST_ACKNOWLEDGE_LEGEND
|
|
1563
1575
|
: DASHBOARD_HARVEST_LEGEND
|
|
1564
1576
|
: DASHBOARD_GLOBAL_LEGEND
|
|
1565
|
-
return [truncate(paint(legend, 'dim', color), width)]
|
|
1577
|
+
return [truncate(paint(modeLegend(model, legend), 'dim', color), width)]
|
|
1566
1578
|
}
|
|
1567
1579
|
return resumePanel(model, color, width, capacity)
|
|
1568
1580
|
}
|
|
@@ -1812,10 +1824,39 @@ function renderDashboardContent(model: DashboardModel, opts: RenderOpts): string
|
|
|
1812
1824
|
* truncation, and right-pinning share one geometry. Prefixing only after the
|
|
1813
1825
|
* frame is composed preserves its logical line count (including truly blank
|
|
1814
1826
|
* separators) and therefore leaves vertical budgeting unchanged. */
|
|
1827
|
+
export function renderViewerNotice(
|
|
1828
|
+
viewer: { dispatchedBy?: string },
|
|
1829
|
+
message: string,
|
|
1830
|
+
width: number,
|
|
1831
|
+
height: number,
|
|
1832
|
+
): string[] {
|
|
1833
|
+
const contentWidth = dashboardContentWidth(width)
|
|
1834
|
+
return [viewerIndicator(viewer, contentWidth), truncate(displayText(message), contentWidth)]
|
|
1835
|
+
.slice(0, Math.max(0, height))
|
|
1836
|
+
.map((line) => (width > 0 ? ` ${line}` : line))
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
export function viewerIndicator(viewer: { dispatchedBy?: string }, width: number): string {
|
|
1840
|
+
const label =
|
|
1841
|
+
viewer.dispatchedBy === undefined
|
|
1842
|
+
? 'viewer'
|
|
1843
|
+
: `viewer · dispatched by ${displayText(viewer.dispatchedBy)}`
|
|
1844
|
+
return width >= 6 && width < 9 ? 'viewer' : truncate(label, width)
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1815
1847
|
export function renderDashboard(model: DashboardModel, opts: RenderOpts): string[] {
|
|
1816
1848
|
const terminalWidth = Math.max(0, opts.width)
|
|
1817
1849
|
const contentWidth = dashboardContentWidth(terminalWidth)
|
|
1818
|
-
const
|
|
1850
|
+
const viewerRows = model.viewer ? 1 : 0
|
|
1851
|
+
const height = opts.height === undefined ? undefined : Math.max(0, opts.height - viewerRows)
|
|
1852
|
+
const lines = renderDashboardContent(model, {
|
|
1853
|
+
...opts,
|
|
1854
|
+
width: contentWidth,
|
|
1855
|
+
...(height !== undefined ? { height } : {}),
|
|
1856
|
+
})
|
|
1857
|
+
if (model.viewer && (opts.height === undefined || opts.height > 0)) {
|
|
1858
|
+
lines.unshift(viewerIndicator(model.viewer, contentWidth))
|
|
1859
|
+
}
|
|
1819
1860
|
const leftGutter = terminalWidth > 0 ? ' ' : ''
|
|
1820
1861
|
|
|
1821
1862
|
return lines.map((line) => (line === '' ? '' : `${leftGutter}${line}`))
|
|
@@ -4,10 +4,13 @@ export function parseDispatchArgs(
|
|
|
4
4
|
env: Record<string, string | undefined>,
|
|
5
5
|
) {
|
|
6
6
|
const usage =
|
|
7
|
-
'usage: ab dispatch [--once] [--interval <seconds>] [--store <ref>] [--repository <origin>] [--plain] [--intake | --no-intake] [--auto-merge | --no-auto-merge] (§3.3)'
|
|
7
|
+
'usage: ab dispatch [--viewer [--dispatched-by <label>] | --takeover] [--once] [--interval <seconds>] [--store <ref>] [--repository <origin>] [--plain] [--intake | --no-intake] [--auto-merge | --no-auto-merge] (§3.3)'
|
|
8
8
|
const parsed = parseArgs(
|
|
9
9
|
rest,
|
|
10
10
|
{
|
|
11
|
+
viewer: 'boolean',
|
|
12
|
+
takeover: 'boolean',
|
|
13
|
+
'dispatched-by': 'value',
|
|
11
14
|
once: 'boolean',
|
|
12
15
|
interval: 'value',
|
|
13
16
|
store: 'value',
|
|
@@ -22,6 +25,16 @@ export function parseDispatchArgs(
|
|
|
22
25
|
)
|
|
23
26
|
if (parsed.positionals.length > 0) throw new Error(usage)
|
|
24
27
|
|
|
28
|
+
const takeover = parsed.flags.has('takeover')
|
|
29
|
+
const viewer = parsed.flags.has('viewer')
|
|
30
|
+
if (viewer && takeover) throw new Error('--viewer and --takeover cannot be combined')
|
|
31
|
+
const dispatchedBy = stringFlag(parsed, 'dispatched-by')?.trim()
|
|
32
|
+
if (dispatchedBy !== undefined && (!viewer || dispatchedBy === ''))
|
|
33
|
+
throw new Error('--dispatched-by requires --viewer and a nonblank label')
|
|
34
|
+
if (viewer && parsed.flags.has('repository'))
|
|
35
|
+
throw new Error('--viewer requires a local checkout; omit --repository')
|
|
36
|
+
if (viewer && (parsed.flags.has('intake') || parsed.flags.has('no-intake')))
|
|
37
|
+
throw new Error('--viewer cannot set startup intake; use the interactive intake control')
|
|
25
38
|
const once = parsed.flags.has('once')
|
|
26
39
|
const plain = parsed.flags.has('plain')
|
|
27
40
|
const sawIntake = parsed.flags.has('intake')
|
|
@@ -45,9 +58,20 @@ export function parseDispatchArgs(
|
|
|
45
58
|
intervalMs = Math.round(seconds * 1000)
|
|
46
59
|
}
|
|
47
60
|
const storeRef = stringFlag(parsed, 'store')
|
|
48
|
-
const repository = stringFlag(parsed, 'repository') ?? env.AB_REPOSITORY
|
|
61
|
+
const repository = stringFlag(parsed, 'repository') ?? (viewer ? undefined : env.AB_REPOSITORY)
|
|
49
62
|
const intake = sawIntake ? true : sawNoIntake ? false : undefined
|
|
50
63
|
const defaultAutoMerge = sawAutoMerge ? true : sawNoAutoMerge ? false : undefined
|
|
51
64
|
|
|
52
|
-
return {
|
|
65
|
+
return {
|
|
66
|
+
viewer,
|
|
67
|
+
takeover,
|
|
68
|
+
dispatchedBy,
|
|
69
|
+
once,
|
|
70
|
+
plain,
|
|
71
|
+
intake,
|
|
72
|
+
defaultAutoMerge,
|
|
73
|
+
intervalMs,
|
|
74
|
+
storeRef,
|
|
75
|
+
repository,
|
|
76
|
+
}
|
|
53
77
|
}
|
|
@@ -2,7 +2,11 @@ import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
|
|
|
2
2
|
import { migrationIdentity, ticketMigrationsReducer } from '../kernel/ticket-migrations'
|
|
3
3
|
import type { DispatchUpgradeState } from '../kernel/dispatch-upgrade'
|
|
4
4
|
import { releaseDispatchPresentation } from './dispatch-presentation-ownership'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
readDispatchUpgrade,
|
|
7
|
+
readRepositoryFacts,
|
|
8
|
+
type RepositoryReadFacts,
|
|
9
|
+
} from '../store/reduced-reads'
|
|
6
10
|
import { DISPATCHER } from '../events/envelope'
|
|
7
11
|
import { launchContext } from './dispatch-launch-contract'
|
|
8
12
|
import { dispatchCapacity } from '../kernel/dispatch-capacity'
|
|
@@ -49,6 +53,8 @@ import {
|
|
|
49
53
|
moveDetailScroll,
|
|
50
54
|
moveTranscriptScroll,
|
|
51
55
|
renderDashboard,
|
|
56
|
+
viewerIndicator,
|
|
57
|
+
renderViewerNotice,
|
|
52
58
|
revealDetailFocus,
|
|
53
59
|
type DashboardRendererResolver,
|
|
54
60
|
} from './dashboard/render'
|
|
@@ -95,6 +101,8 @@ interface ResumePrompt {
|
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
export interface DispatchFrontendOptions {
|
|
104
|
+
viewer?: { dispatchedBy?: string }
|
|
105
|
+
plainOutput?: (line: string) => void
|
|
98
106
|
/** Repository identity (§12): the normalized origin, or the checkout path
|
|
99
107
|
* when there is no origin. Every Store key uses this. */
|
|
100
108
|
repo: string
|
|
@@ -155,17 +163,27 @@ export class DispatchFrontend {
|
|
|
155
163
|
private accepting = false
|
|
156
164
|
private cleanupInput: (() => void) | undefined
|
|
157
165
|
private refresh: DashboardRefresh | undefined
|
|
166
|
+
/** Set once a failure streak is journaled; cleared by the next good frame. */
|
|
167
|
+
private renderFailureReported = false
|
|
158
168
|
private suspension: ReturnType<typeof installPresentationSuspension> | undefined
|
|
159
169
|
private readonly reader: BuildStore
|
|
160
170
|
private paintTimer: ReturnType<typeof setInterval> | undefined
|
|
161
171
|
private actionTail: Promise<void> = Promise.resolve()
|
|
162
172
|
private presentationRestored = false
|
|
163
173
|
private operatorStopRequested = false
|
|
174
|
+
private viewerStopped: (() => void) | undefined
|
|
175
|
+
private viewerFacts: RepositoryReadFacts | undefined
|
|
176
|
+
private viewerPosition: string | undefined
|
|
177
|
+
private viewerReadAt = -Infinity
|
|
178
|
+
private lastPlainFrame: string | undefined
|
|
164
179
|
|
|
165
180
|
constructor(private readonly opts: DispatchFrontendOptions) {
|
|
166
181
|
this.runId = launchContext(opts.env)?.run ?? crypto.randomUUID()
|
|
167
182
|
this.dispatchStatus = reduceDispatchStatus([], this.runId)
|
|
168
|
-
this.reader = presentationReader(
|
|
183
|
+
this.reader = presentationReader(
|
|
184
|
+
opts.store,
|
|
185
|
+
() => !this.presentationRestored && (this.refresh?.admitted ?? true),
|
|
186
|
+
)
|
|
169
187
|
this.clock = opts.clock ?? systemClock
|
|
170
188
|
this.repositoryFeed = new DispatchRepositoryFeed(this.reader, opts.repo, this.clock)
|
|
171
189
|
this.standbyResolver = new StandbyIdentityResolver(this.reader, opts.repo, {
|
|
@@ -184,7 +202,20 @@ export class DispatchFrontend {
|
|
|
184
202
|
* operator action. High-frequency dispatcher status is folded from deltas;
|
|
185
203
|
* only the low-volume settings/Harvest facts needed by the dashboard model
|
|
186
204
|
* are retained for their existing replay reducers. */
|
|
187
|
-
private async events(): Promise<RepositoryEvent[]> {
|
|
205
|
+
private async events(sampledPosition?: string): Promise<RepositoryEvent[]> {
|
|
206
|
+
if (this.opts.viewer) {
|
|
207
|
+
const position = sampledPosition ?? (await this.reader.getRepoChangePosition(this.opts.repo))
|
|
208
|
+
if (
|
|
209
|
+
position !== this.viewerPosition ||
|
|
210
|
+
this.clock().getTime() - this.viewerReadAt >= 10_000
|
|
211
|
+
) {
|
|
212
|
+
this.viewerFacts = (await readRepositoryFacts(this.reader, this.opts.repo)).value
|
|
213
|
+
this.viewerPosition = position
|
|
214
|
+
this.viewerReadAt = this.clock().getTime()
|
|
215
|
+
}
|
|
216
|
+
this.dispatchStatus = this.viewerFacts!.status ?? reduceDispatchStatus([], this.runId)
|
|
217
|
+
return []
|
|
218
|
+
}
|
|
188
219
|
const refresh = this.eventRefreshTail.then(async () => {
|
|
189
220
|
const delta = await this.repositoryFeed.refresh(false)
|
|
190
221
|
this.standbyResolver.ingest(this.repositoryFeed.identities)
|
|
@@ -269,7 +300,7 @@ export class DispatchFrontend {
|
|
|
269
300
|
detailScrollLimit(
|
|
270
301
|
next,
|
|
271
302
|
dashboardContentWidth(this.opts.terminal.columns),
|
|
272
|
-
|
|
303
|
+
this.contentHeight(),
|
|
273
304
|
),
|
|
274
305
|
),
|
|
275
306
|
),
|
|
@@ -284,14 +315,26 @@ export class DispatchFrontend {
|
|
|
284
315
|
if (this.refresh !== undefined && !this.refresh.painting) return
|
|
285
316
|
if (this.model === undefined) return
|
|
286
317
|
const renderer = this.opts.resolveDashboardRenderer?.() ?? renderDashboard
|
|
287
|
-
this.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
318
|
+
const lines = renderer(this.model, {
|
|
319
|
+
color: this.opts.plainOutput === undefined,
|
|
320
|
+
width: this.opts.terminal.columns,
|
|
321
|
+
height: paintableRows(this.opts.terminal.rows),
|
|
322
|
+
now: this.clock().getTime(),
|
|
323
|
+
})
|
|
324
|
+
this.outputFrame(lines)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private outputFrame(lines: string[]): void {
|
|
328
|
+
if (this.presentationRestored) return
|
|
329
|
+
if (this.opts.plainOutput) {
|
|
330
|
+
const frame = lines.join('\n')
|
|
331
|
+
if (frame !== this.lastPlainFrame) this.opts.plainOutput(frame)
|
|
332
|
+
this.lastPlainFrame = frame
|
|
333
|
+
} else this.region.update(lines)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private contentHeight(): number {
|
|
337
|
+
return Math.max(0, paintableRows(this.opts.terminal.rows) - (this.opts.viewer ? 1 : 0))
|
|
295
338
|
}
|
|
296
339
|
|
|
297
340
|
private async loadConfig(kind: string, rev: number): Promise<Config> {
|
|
@@ -316,6 +359,7 @@ export class DispatchFrontend {
|
|
|
316
359
|
private readonly repositoryPoll = new RepositoryPollCache<{
|
|
317
360
|
repositoryEvents: RepositoryEvent[]
|
|
318
361
|
upgrades: DispatchUpgradeState
|
|
362
|
+
repositoryFacts: RepositoryReadFacts
|
|
319
363
|
status: DispatchStatus
|
|
320
364
|
config: Config
|
|
321
365
|
observationCount: number
|
|
@@ -324,8 +368,12 @@ export class DispatchFrontend {
|
|
|
324
368
|
|
|
325
369
|
private async readFrame(): Promise<void> {
|
|
326
370
|
if (this.refresh !== undefined && !this.refresh.admitted) return
|
|
371
|
+
let sampledPosition: string | undefined
|
|
327
372
|
const frame = await this.repositoryPoll.refresh({
|
|
328
|
-
position: () =>
|
|
373
|
+
position: async () => {
|
|
374
|
+
sampledPosition = await this.reader.getRepoChangePosition(this.opts.repo)
|
|
375
|
+
return sampledPosition
|
|
376
|
+
},
|
|
329
377
|
now: () => this.clock().getTime(),
|
|
330
378
|
revision: 0,
|
|
331
379
|
enabled: !this.opts.once,
|
|
@@ -333,14 +381,33 @@ export class DispatchFrontend {
|
|
|
333
381
|
admitted: () => this.refresh === undefined || this.refresh.admitted,
|
|
334
382
|
nextPollMs: this.refresh?.intervalMs ?? 0,
|
|
335
383
|
read: async ({ fullEnrichment }) => {
|
|
336
|
-
const repositoryEvents = await this.events()
|
|
384
|
+
const repositoryEvents = await this.events(sampledPosition)
|
|
337
385
|
// Authority and rollback holds need the full durable reduction, not the
|
|
338
386
|
// low-volume replay feed (which deliberately discards per-tick facts).
|
|
339
|
-
const
|
|
387
|
+
const repositoryFacts =
|
|
388
|
+
this.viewerFacts ??
|
|
389
|
+
(
|
|
390
|
+
await readRepositoryFacts(
|
|
391
|
+
this.reader,
|
|
392
|
+
this.opts.repo,
|
|
393
|
+
repositoryEvents.length || this.repositoryFeed.identities.length ? true : undefined,
|
|
394
|
+
)
|
|
395
|
+
).value
|
|
396
|
+
const upgrades = repositoryFacts.upgrades
|
|
340
397
|
const status = this.dispatchStatus
|
|
341
398
|
const ref = status.effectiveConfig
|
|
342
399
|
if (ref === undefined) {
|
|
343
|
-
if (
|
|
400
|
+
if (this.opts.viewer) {
|
|
401
|
+
this.model = undefined
|
|
402
|
+
this.outputFrame(
|
|
403
|
+
renderViewerNotice(
|
|
404
|
+
this.opts.viewer,
|
|
405
|
+
status.warningNotice ?? 'Waiting for dispatcher configuration',
|
|
406
|
+
this.opts.terminal.columns,
|
|
407
|
+
paintableRows(this.opts.terminal.rows),
|
|
408
|
+
),
|
|
409
|
+
)
|
|
410
|
+
} else if (status.health === 'failed' && status.warningNotice !== undefined)
|
|
344
411
|
this.region.update([status.warningNotice])
|
|
345
412
|
// Startup is incomplete: retry at the same position.
|
|
346
413
|
return undefined
|
|
@@ -350,7 +417,7 @@ export class DispatchFrontend {
|
|
|
350
417
|
try {
|
|
351
418
|
observationCount = unclaimedObservationCount({
|
|
352
419
|
digests: await this.reader.getRepoBuildDigests(this.opts.repo),
|
|
353
|
-
harvestEvents: repositoryEvents,
|
|
420
|
+
harvestEvents: this.opts.viewer ? repositoryFacts.harvest : repositoryEvents,
|
|
354
421
|
})
|
|
355
422
|
} catch {
|
|
356
423
|
// Incomplete snapshots never acknowledge the sampled position.
|
|
@@ -360,19 +427,28 @@ export class DispatchFrontend {
|
|
|
360
427
|
}
|
|
361
428
|
this.cache ??= new DashboardBuildPollCache(this.reader, this.opts.repo, config)
|
|
362
429
|
const snapshot = await this.cache.refresh(config, this.configRevision, fullEnrichment)
|
|
363
|
-
if (!this.opts.once)
|
|
430
|
+
if (!this.opts.once && !this.opts.viewer)
|
|
364
431
|
await this.standbyResolver.refresh(this.runId, status.yieldedHolder, this.clock())
|
|
365
|
-
await this.repositoryFeed.save()
|
|
432
|
+
if (!this.opts.viewer) await this.repositoryFeed.save()
|
|
366
433
|
if (!this.cache.isCurrent(snapshot)) return undefined
|
|
367
|
-
return {
|
|
434
|
+
return {
|
|
435
|
+
repositoryEvents,
|
|
436
|
+
repositoryFacts,
|
|
437
|
+
upgrades,
|
|
438
|
+
status,
|
|
439
|
+
config,
|
|
440
|
+
observationCount,
|
|
441
|
+
snapshot,
|
|
442
|
+
}
|
|
368
443
|
},
|
|
369
444
|
})
|
|
370
445
|
if (frame === undefined) return
|
|
371
|
-
let { repositoryEvents, upgrades, status } = frame
|
|
446
|
+
let { repositoryEvents, repositoryFacts, upgrades, status } = frame
|
|
372
447
|
const { config, snapshot } = frame
|
|
373
|
-
const standby =
|
|
374
|
-
|
|
375
|
-
|
|
448
|
+
const standby =
|
|
449
|
+
this.opts.once || this.opts.viewer
|
|
450
|
+
? undefined
|
|
451
|
+
: this.standbyResolver.current(this.runId, status.yieldedHolder, this.clock())
|
|
376
452
|
this.observationCount = frame.observationCount
|
|
377
453
|
this.refresh?.activity(snapshot.states.size > 0)
|
|
378
454
|
|
|
@@ -388,7 +464,14 @@ export class DispatchFrontend {
|
|
|
388
464
|
if (!validAbortConfirmation(snapshot.states.get(slug))) {
|
|
389
465
|
await this.dismissStaleAbortConfirmation(slug)
|
|
390
466
|
repositoryEvents = await this.events()
|
|
391
|
-
|
|
467
|
+
repositoryFacts = (
|
|
468
|
+
await readRepositoryFacts(
|
|
469
|
+
this.reader,
|
|
470
|
+
this.opts.repo,
|
|
471
|
+
repositoryEvents.length || this.repositoryFeed.identities.length ? true : undefined,
|
|
472
|
+
)
|
|
473
|
+
).value
|
|
474
|
+
upgrades = repositoryFacts.upgrades
|
|
392
475
|
status = this.dispatchStatus
|
|
393
476
|
}
|
|
394
477
|
}
|
|
@@ -414,7 +497,9 @@ export class DispatchFrontend {
|
|
|
414
497
|
config.capacity,
|
|
415
498
|
this.clock(),
|
|
416
499
|
migrationIdentity(
|
|
417
|
-
|
|
500
|
+
this.opts.viewer
|
|
501
|
+
? repositoryFacts.ticketMigrations
|
|
502
|
+
: ticketMigrationsReducer.reduce(repositoryEvents),
|
|
418
503
|
config.tickets.source,
|
|
419
504
|
),
|
|
420
505
|
),
|
|
@@ -425,7 +510,7 @@ export class DispatchFrontend {
|
|
|
425
510
|
: {}),
|
|
426
511
|
...(warningLines.length > 0 ? { warningLines } : {}),
|
|
427
512
|
},
|
|
428
|
-
|
|
513
|
+
repositoryFacts,
|
|
429
514
|
upgrades,
|
|
430
515
|
)
|
|
431
516
|
this.selection = reconcileSelection(previous, dashboardSelections(projected), this.selection)
|
|
@@ -435,7 +520,7 @@ export class DispatchFrontend {
|
|
|
435
520
|
) {
|
|
436
521
|
this.view = undefined
|
|
437
522
|
}
|
|
438
|
-
this.model = projected
|
|
523
|
+
this.model = { ...projected, ...(this.opts.viewer ? { viewer: this.opts.viewer } : {}) }
|
|
439
524
|
this.syncControls()
|
|
440
525
|
this.paint()
|
|
441
526
|
// The session view's live-read cycle rides the poll tick: one immediate
|
|
@@ -450,7 +535,7 @@ export class DispatchFrontend {
|
|
|
450
535
|
const limit = sessionScrollLimit(
|
|
451
536
|
view,
|
|
452
537
|
this.opts.terminal.columns,
|
|
453
|
-
|
|
538
|
+
this.contentHeight(),
|
|
454
539
|
upgrade,
|
|
455
540
|
this.model?.standby !== undefined,
|
|
456
541
|
)
|
|
@@ -458,7 +543,7 @@ export class DispatchFrontend {
|
|
|
458
543
|
const scroll = moveSessionScroll(
|
|
459
544
|
view,
|
|
460
545
|
this.opts.terminal.columns,
|
|
461
|
-
|
|
546
|
+
this.contentHeight(),
|
|
462
547
|
current,
|
|
463
548
|
delta,
|
|
464
549
|
upgrade,
|
|
@@ -478,7 +563,7 @@ export class DispatchFrontend {
|
|
|
478
563
|
scroll: moveTranscriptScroll(
|
|
479
564
|
this.view.transcript,
|
|
480
565
|
this.opts.terminal.columns,
|
|
481
|
-
|
|
566
|
+
this.contentHeight(),
|
|
482
567
|
this.view.scroll,
|
|
483
568
|
delta,
|
|
484
569
|
this.model?.availableUpgrade !== undefined,
|
|
@@ -491,7 +576,7 @@ export class DispatchFrontend {
|
|
|
491
576
|
scroll: moveDetailScroll(
|
|
492
577
|
this.model,
|
|
493
578
|
dashboardContentWidth(this.opts.terminal.columns),
|
|
494
|
-
|
|
579
|
+
this.contentHeight(),
|
|
495
580
|
this.view.scroll,
|
|
496
581
|
delta,
|
|
497
582
|
),
|
|
@@ -519,7 +604,7 @@ export class DispatchFrontend {
|
|
|
519
604
|
scroll: revealDetailFocus(
|
|
520
605
|
{ ...this.model!, view: candidate },
|
|
521
606
|
dashboardContentWidth(this.opts.terminal.columns),
|
|
522
|
-
|
|
607
|
+
this.contentHeight(),
|
|
523
608
|
'session',
|
|
524
609
|
candidate.scroll,
|
|
525
610
|
),
|
|
@@ -579,7 +664,7 @@ export class DispatchFrontend {
|
|
|
579
664
|
scroll: revealDetailFocus(
|
|
580
665
|
{ ...this.model!, view: candidate },
|
|
581
666
|
dashboardContentWidth(this.opts.terminal.columns),
|
|
582
|
-
|
|
667
|
+
this.contentHeight(),
|
|
583
668
|
'message',
|
|
584
669
|
candidate.scroll,
|
|
585
670
|
),
|
|
@@ -643,7 +728,7 @@ export class DispatchFrontend {
|
|
|
643
728
|
const limit = sessionScrollLimit(
|
|
644
729
|
next,
|
|
645
730
|
terminal.columns,
|
|
646
|
-
|
|
731
|
+
this.contentHeight(),
|
|
647
732
|
this.model?.availableUpgrade !== undefined,
|
|
648
733
|
this.model?.standby !== undefined,
|
|
649
734
|
)
|
|
@@ -995,40 +1080,49 @@ export class DispatchFrontend {
|
|
|
995
1080
|
async () => {
|
|
996
1081
|
try {
|
|
997
1082
|
await this.readFrame()
|
|
1083
|
+
this.renderFailureReported = false
|
|
998
1084
|
} catch (error) {
|
|
999
|
-
|
|
1085
|
+
// One durable warning per failure streak, not per poll: a poll that
|
|
1086
|
+
// fails on every tick would otherwise grow the journal it reads.
|
|
1087
|
+
// Messages carry moving cursors, so they cannot serve as the dedup key.
|
|
1088
|
+
if (this.refresh?.admitted && !this.renderFailureReported) {
|
|
1089
|
+
this.renderFailureReported = true
|
|
1000
1090
|
await this.report(
|
|
1001
1091
|
`dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1002
1092
|
'warning',
|
|
1003
1093
|
)
|
|
1094
|
+
}
|
|
1004
1095
|
throw error
|
|
1005
1096
|
}
|
|
1006
1097
|
},
|
|
1007
1098
|
this.opts.refreshScheduler,
|
|
1008
1099
|
this.opts.store.networkReads,
|
|
1100
|
+
this.opts.viewer ? this.opts.intervalMs : undefined,
|
|
1009
1101
|
)
|
|
1010
|
-
this.listen()
|
|
1011
|
-
this.opts.terminal.modes.enter(FOCUS_REPORTING_MODE)
|
|
1012
|
-
this.
|
|
1013
|
-
this.
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
this.paintTimer.
|
|
1102
|
+
if (!this.opts.plainOutput) this.listen()
|
|
1103
|
+
if (!this.opts.plainOutput) this.opts.terminal.modes.enter(FOCUS_REPORTING_MODE)
|
|
1104
|
+
if (!this.opts.plainOutput)
|
|
1105
|
+
this.suspension = installPresentationSuspension(
|
|
1106
|
+
this.opts.terminal.modes,
|
|
1107
|
+
() => {
|
|
1108
|
+
this.refresh?.suspend()
|
|
1109
|
+
this.cleanupInput?.()
|
|
1110
|
+
this.cleanupInput = undefined
|
|
1111
|
+
},
|
|
1112
|
+
() => {
|
|
1113
|
+
this.listen()
|
|
1114
|
+
this.region.invalidate()
|
|
1115
|
+
this.refresh?.resume()
|
|
1116
|
+
},
|
|
1117
|
+
)
|
|
1118
|
+
if (!this.opts.plainOutput) this.paintTimer = setInterval(() => this.paint(), PAINT_MS)
|
|
1119
|
+
this.paintTimer?.unref?.()
|
|
1027
1120
|
void this.refresh.request()
|
|
1028
1121
|
}
|
|
1029
1122
|
|
|
1030
1123
|
private requestOperatorStop(): void {
|
|
1031
1124
|
this.operatorStopRequested = true
|
|
1125
|
+
this.viewerStopped?.()
|
|
1032
1126
|
this.restorePresentationForStop()
|
|
1033
1127
|
void this.child?.stop(
|
|
1034
1128
|
typeof this.opts.signal?.reason === 'string' ? this.opts.signal.reason : undefined,
|
|
@@ -1082,7 +1176,47 @@ export class DispatchFrontend {
|
|
|
1082
1176
|
}
|
|
1083
1177
|
}
|
|
1084
1178
|
|
|
1179
|
+
private async runViewer(): Promise<void> {
|
|
1180
|
+
// Viewing has no repository creation, lease, child, or dispatcher lifecycle writes.
|
|
1181
|
+
if (this.opts.plainOutput) this.opts.plainOutput(viewerIndicator(this.opts.viewer!, 1000))
|
|
1182
|
+
if (this.opts.signal?.aborted) return
|
|
1183
|
+
const stopped = new Promise<void>((resolve) => {
|
|
1184
|
+
this.viewerStopped = resolve
|
|
1185
|
+
})
|
|
1186
|
+
const stop = () => this.requestOperatorStop()
|
|
1187
|
+
// A pending Promise and the adaptive scheduler's unref timers do not keep
|
|
1188
|
+
// a plain viewer alive. This timer owns only the presentation lifetime.
|
|
1189
|
+
const lifetime = setInterval(() => {}, 60_000)
|
|
1190
|
+
this.opts.signal?.addEventListener('abort', stop, { once: true })
|
|
1191
|
+
try {
|
|
1192
|
+
await this.readFrame()
|
|
1193
|
+
if (!this.opts.once && !this.operatorStopRequested) {
|
|
1194
|
+
this.startPresentation()
|
|
1195
|
+
await stopped
|
|
1196
|
+
}
|
|
1197
|
+
} catch (error) {
|
|
1198
|
+
if (this.operatorStopRequested) return
|
|
1199
|
+
this.outputFrame(
|
|
1200
|
+
renderViewerNotice(
|
|
1201
|
+
this.opts.viewer!,
|
|
1202
|
+
`Viewer unavailable: ${error instanceof Error ? error.message : String(error)}`,
|
|
1203
|
+
this.opts.terminal.columns,
|
|
1204
|
+
paintableRows(this.opts.terminal.rows),
|
|
1205
|
+
),
|
|
1206
|
+
)
|
|
1207
|
+
throw error
|
|
1208
|
+
} finally {
|
|
1209
|
+
clearInterval(lifetime)
|
|
1210
|
+
this.opts.signal?.removeEventListener('abort', stop)
|
|
1211
|
+
this.restorePresentationForStop()
|
|
1212
|
+
await this.refresh?.join()
|
|
1213
|
+
await this.actionTail
|
|
1214
|
+
this.viewerStopped = undefined
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1085
1218
|
async run(): Promise<void> {
|
|
1219
|
+
if (this.opts.viewer) return this.runViewer()
|
|
1086
1220
|
await this.opts.store.ensureRepo(this.opts.repo)
|
|
1087
1221
|
const actor = humanActor(buildControlUser(this.opts.env))
|
|
1088
1222
|
if (this.opts.intake !== undefined) {
|