@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.
- package/README.md +1 -1
- package/SPEC.md +745 -69
- package/bin/ab-dispatch-generation.ts +3 -1
- package/docs/accounts.md +2 -1
- package/docs/answering-blocked-builds.md +20 -0
- package/docs/architecture.md +165 -29
- package/docs/build-store.md +10 -7
- package/docs/cli.md +33 -1
- package/docs/configuration-overview.md +4 -1
- package/docs/configuration.md +381 -29
- package/docs/dispatcher.md +64 -4
- package/docs/forges.md +7 -0
- package/docs/integration-tree.md +2 -2
- package/docs/operating.md +4 -2
- package/docs/operator-api.md +134 -6
- package/docs/operator-surfaces.md +85 -0
- package/docs/optimization-nodes.md +69 -11
- package/docs/plugin-authoring.md +37 -1
- package/docs/remote-store-protocol.md +94 -13
- package/docs/remote-ticket-protocol.md +40 -0
- package/docs/restacking.md +20 -4
- package/docs/setup.md +14 -2
- package/docs/ticket-dependencies.md +10 -3
- package/docs/ticket-sources.md +24 -2
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +8 -0
- package/docs/verification.md +4 -3
- package/docs/workspaces.md +3 -0
- package/package.json +9 -5
- package/packages/core/src/cli/accounts.ts +7 -2
- package/packages/core/src/cli/attention.ts +3 -1
- package/packages/core/src/cli/binary-direct.ts +2 -0
- package/packages/core/src/cli/binary-lifecycle.ts +2 -1
- package/packages/core/src/cli/build-control.ts +79 -1
- package/packages/core/src/cli/context.ts +4 -0
- package/packages/core/src/cli/dashboard/facts.ts +49 -53
- package/packages/core/src/cli/dashboard/header.ts +111 -0
- package/packages/core/src/cli/dashboard/model.ts +31 -39
- package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
- package/packages/core/src/cli/dashboard/poll.ts +179 -76
- package/packages/core/src/cli/dashboard/render.ts +159 -230
- package/packages/core/src/cli/dashboard/row-text.ts +538 -0
- package/packages/core/src/cli/dashboard/timeline.ts +288 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
- package/packages/core/src/cli/dispatch-args.ts +44 -1
- package/packages/core/src/cli/dispatch-frontend.ts +40 -40
- package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
- package/packages/core/src/cli/dispatch-launcher.ts +20 -7
- package/packages/core/src/cli/dispatch-web.ts +155 -0
- package/packages/core/src/cli/dispatch.ts +202 -38
- package/packages/core/src/cli/help.ts +87 -3
- package/packages/core/src/cli/init-validation.ts +3 -3
- package/packages/core/src/cli/main.ts +70 -6
- package/packages/core/src/cli/mcp.ts +35 -3
- package/packages/core/src/cli/objective.ts +1 -1
- package/packages/core/src/cli/operator-preference.ts +57 -0
- package/packages/core/src/cli/repo-lease.ts +2 -0
- package/packages/core/src/cli/repo-state.ts +56 -6
- package/packages/core/src/cli/repository-status.ts +105 -49
- package/packages/core/src/cli/status.ts +82 -1
- package/packages/core/src/cli/terminal-restore.ts +32 -7
- package/packages/core/src/cli/ticket.ts +98 -36
- package/packages/core/src/cli/wait.ts +14 -6
- package/packages/core/src/cli/watch.ts +20 -4
- package/packages/core/src/cli/web.ts +139 -0
- package/packages/core/src/config/live.ts +99 -14
- package/packages/core/src/config/load.ts +61 -20
- package/packages/core/src/config/local.ts +212 -0
- package/packages/core/src/config/pipeline-source.ts +2 -0
- package/packages/core/src/config/reference.ts +18 -0
- package/packages/core/src/config/schema.ts +45 -10
- package/packages/core/src/events/catalog.ts +4 -0
- package/packages/core/src/events/payloads.ts +97 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +46 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +381 -30
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
- package/packages/core/src/kernel/build-roster.ts +230 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
- package/packages/core/src/kernel/dispatch-status.ts +139 -0
- package/packages/core/src/kernel/engine.ts +43 -5
- package/packages/core/src/kernel/execution-intervals.ts +61 -0
- package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
- package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
- package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
- package/packages/core/src/kernel/log-index.ts +19 -0
- package/packages/core/src/kernel/optimization-admission.ts +244 -3
- package/packages/core/src/kernel/optimization.ts +183 -4
- package/packages/core/src/kernel/phase-failures.ts +121 -0
- package/packages/core/src/kernel/published-branch-head.ts +60 -0
- package/packages/core/src/kernel/read-facts.ts +15 -13
- package/packages/core/src/kernel/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +27 -0
- package/packages/core/src/kernel/reducer.ts +63 -4
- package/packages/core/src/kernel/rollup.ts +61 -0
- package/packages/core/src/kernel/setup-streak.ts +38 -0
- package/packages/core/src/kernel/step-durations.ts +257 -0
- package/packages/core/src/kernel/target-observation.ts +6 -1
- package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
- package/packages/core/src/kernel/verify-diff-base.ts +5 -0
- package/packages/core/src/kernel/verify-stages.ts +13 -3
- package/packages/core/src/ontology.ts +5 -0
- package/packages/core/src/operator/agent-context-serve.ts +631 -0
- package/packages/core/src/operator/annotations.ts +75 -5
- package/packages/core/src/operator/attention.ts +470 -0
- package/packages/core/src/operator/canonical-skills.ts +35 -0
- package/packages/core/src/operator/cli-equivalents.ts +270 -0
- package/packages/core/src/operator/context-prompts.ts +61 -0
- package/packages/core/src/operator/index.ts +49 -1
- package/packages/core/src/operator/landings.ts +28 -19
- package/packages/core/src/operator/optimization.ts +7 -0
- package/packages/core/src/operator/protocol.ts +3 -0
- package/packages/core/src/operator/query.ts +129 -74
- package/packages/core/src/operator/read-view.ts +5 -2
- package/packages/core/src/operator/registry.ts +406 -46
- package/packages/core/src/operator/requests.ts +20 -18
- package/packages/core/src/operator/sandbox-host.ts +107 -11
- package/packages/core/src/operator/sandbox-resolver.ts +253 -0
- package/packages/core/src/operator/sandbox.ts +778 -82
- package/packages/core/src/operator/ticket-asset-list.ts +77 -0
- package/packages/core/src/operator/ticket-assets.ts +167 -0
- package/packages/core/src/operator/tickets.ts +33 -2
- package/packages/core/src/plugin-sdk/index.ts +22 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/fake.ts +92 -1
- package/packages/core/src/ports/forge/git-blob.ts +15 -0
- package/packages/core/src/ports/forge/github.ts +82 -0
- package/packages/core/src/ports/forge/local-git.ts +61 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
- package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
- package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
- package/packages/core/src/ports/tickets/contract.ts +71 -0
- package/packages/core/src/ports/tickets/fake.ts +11 -0
- package/packages/core/src/ports/tickets/file.ts +18 -0
- package/packages/core/src/ports/tickets/github-fake.ts +136 -4
- package/packages/core/src/ports/tickets/github.ts +387 -30
- package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
- package/packages/core/src/ports/tickets/linear.ts +130 -0
- package/packages/core/src/ports/tickets/priority.ts +9 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
- package/packages/core/src/ports/tickets/remote.ts +70 -6
- package/packages/core/src/ports/tickets/search.ts +139 -0
- package/packages/core/src/ports/types.ts +104 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
- package/packages/core/src/ports/workspace/create.ts +15 -1
- package/packages/core/src/ports/workspace/fake.ts +340 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
- package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
- package/packages/core/src/ports/workspace/process-group.ts +48 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
- package/packages/core/src/processes/agent-context-assemble.ts +576 -0
- package/packages/core/src/processes/agent-context.ts +469 -0
- package/packages/core/src/processes/build-runner.ts +387 -236
- package/packages/core/src/processes/dispatcher.ts +211 -55
- package/packages/core/src/processes/execution-no-progress.ts +4 -0
- package/packages/core/src/processes/optimization-activity.ts +120 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/repo-view.ts +78 -2
- package/packages/core/src/processes/sandbox-state.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +2 -0
- package/packages/core/src/processes/workspace-preparation.ts +76 -0
- package/packages/core/src/scenarios/harness.ts +0 -5
- package/packages/core/src/store/account-redaction.ts +1 -0
- package/packages/core/src/store/adapter.ts +52 -1
- package/packages/core/src/store/agent-context.ts +432 -0
- package/packages/core/src/store/build-feed.ts +291 -0
- package/packages/core/src/store/build-scope.ts +19 -1
- package/packages/core/src/store/contract.ts +911 -14
- package/packages/core/src/store/digest.ts +19 -6
- package/packages/core/src/store/histogram.ts +113 -0
- package/packages/core/src/store/local/schema.ts +62 -0
- package/packages/core/src/store/local/store.ts +628 -22
- package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
- package/packages/core/src/store/memory.ts +461 -69
- package/packages/core/src/store/open-builds.ts +19 -0
- package/packages/core/src/store/phase-session.ts +32 -4
- package/packages/core/src/store/reduced-reads.ts +14 -4
- package/packages/core/src/store/reducer-value-shapes.json +7027 -5751
- package/packages/core/src/store/reducer-values.ts +6 -1
- package/packages/core/src/store/remote/client.ts +208 -2
- package/packages/core/src/store/remote/compatibility.ts +1 -1
- package/packages/core/src/store/remote/index.ts +33 -0
- package/packages/core/src/store/remote/protocol.ts +69 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/retention.ts +23 -1
- package/packages/core/src/store/rollups.ts +337 -0
- package/packages/core/src/store/session-handle.ts +20 -2
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/types.ts +108 -9
- package/packages/core/src/testing/dispatch-journals.ts +117 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
- package/packages/core/src/testing/git-config-isolation.ts +7 -5
- package/packages/core/src/testing/index.ts +27 -0
- package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
- package/packages/core/src/web/analytics-source.ts +303 -0
- package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
- package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
- package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
- package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
- package/packages/core/src/web/assets/app.css +1 -0
- package/packages/core/src/web/assets/app.js +9 -0
- package/packages/core/src/web/assets/manifest.json +31 -0
- package/packages/core/src/web/assets/theme.js +1 -0
- package/packages/core/src/web/bounded.ts +31 -0
- package/packages/core/src/web/http.ts +315 -0
- package/packages/core/src/web/hub.ts +160 -0
- package/packages/core/src/web/options.ts +38 -0
- package/packages/core/src/web/overview-source.ts +322 -0
- package/packages/core/src/web/page.ts +56 -0
- package/packages/core/src/web/protocol.ts +151 -0
- package/packages/core/src/web/read-only.ts +23 -0
- package/packages/core/src/web/repository-source.ts +39 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +376 -54
- package/skills/guide/references/accounts.md +2 -1
- package/skills/guide/references/integration-tree.md +2 -2
- package/skills/guide/references/operator-api.md +134 -6
- package/skills/guide/references/optimization-nodes.md +69 -11
- package/skills/guide/references/plugin-authoring.md +37 -1
- package/skills/guide/references/remote-store-protocol.md +94 -13
- package/skills/guide/references/remote-ticket-protocol.md +40 -0
- package/skills/guide/references/restacking.md +20 -4
- package/skills/guide/references/setup.md +14 -2
- package/skills/guide/references/ticket-dependencies.md +10 -3
- package/skills/implement/SKILL.md +23 -4
- package/skills/operate/SKILL.md +134 -32
- package/skills/plan/SKILL.md +10 -4
- package/skills/plan-review/SKILL.md +9 -2
- package/skills/spec/SKILL.md +34 -8
- package/skills/tickets/SKILL.md +51 -5
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ab web`'s frame source: the repository header plus the overview page, at a
|
|
3
|
+
* cost bounded by live builds, never by history.
|
|
4
|
+
*
|
|
5
|
+
* Recurring reads, while at least one browser is subscribed (SPEC §14):
|
|
6
|
+
*
|
|
7
|
+
* - Poll, nothing changed: `getRepoChangePosition` only; zero event rows.
|
|
8
|
+
* - Poll, position moved: the saved `repositoryReadFacts` value (with
|
|
9
|
+
* `getRepo`) and one `listBuildsChangedSince` from the saved watermark.
|
|
10
|
+
* - Per changed build: `getBuild` and the saved `buildReadFacts` value, plus
|
|
11
|
+
* `listStreams` and the pinned `getArtifact` while it is still visible.
|
|
12
|
+
* - One `buildRoster` rollup read per poll, only when a changed build entered
|
|
13
|
+
* or left the visible set, became aborted, or is done (including one the
|
|
14
|
+
* source never saw, created and completed between two polls).
|
|
15
|
+
* - One `getRepoArtifact` per new effective-config ref.
|
|
16
|
+
* - Cold start (first read of a process, a repository reset, a config first
|
|
17
|
+
* appearing): the `buildRoster` rollup plus the per-build reads for each
|
|
18
|
+
* live build and each aborted entry among its newest finished builds.
|
|
19
|
+
*
|
|
20
|
+
* It never lists builds or reads events. A remote store that lacks the roster
|
|
21
|
+
* or the feed fails the read with its typed error; there is no fallback.
|
|
22
|
+
*
|
|
23
|
+
* An abort older than the roster's newest finished entries that is still
|
|
24
|
+
* cleaning up at cold start is missed until its next event, which the feed
|
|
25
|
+
* reports.
|
|
26
|
+
*/
|
|
27
|
+
import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
|
|
28
|
+
import { configSchema, type Config } from '../config/schema'
|
|
29
|
+
import { enrichIntegrationRows } from '../cli/dashboard/integration-row'
|
|
30
|
+
import { buildDashboardFromProjected, type DashboardBuild } from '../cli/dashboard/model'
|
|
31
|
+
import {
|
|
32
|
+
capacityBuildFromFacts,
|
|
33
|
+
isDashboardTerminal,
|
|
34
|
+
projectRowWithEnrichment,
|
|
35
|
+
readRowEnrichment,
|
|
36
|
+
repositoryDashboardHeader,
|
|
37
|
+
type RowEnrichment,
|
|
38
|
+
} from '../cli/dashboard/poll'
|
|
39
|
+
import { projectOverview } from '../cli/dashboard/row-text'
|
|
40
|
+
import type { BuildRosterFinished, BuildRosterValue } from '../kernel/build-roster'
|
|
41
|
+
import type { CapacityBuild } from '../kernel/dispatch-capacity'
|
|
42
|
+
import type { BuildState } from '../kernel/reducer'
|
|
43
|
+
import {
|
|
44
|
+
readBuildFacts,
|
|
45
|
+
readRepositoryFacts,
|
|
46
|
+
type CurrentBuildFacts,
|
|
47
|
+
type RepositoryReadFacts,
|
|
48
|
+
} from '../store/reduced-reads'
|
|
49
|
+
import type { BuildRecord, BuildStore } from '../store/types'
|
|
50
|
+
import { mapBounded } from './bounded'
|
|
51
|
+
import { type WebFrame, type WebFrameSource, WebReadFencedError } from './protocol'
|
|
52
|
+
import { projectRepositoryFrame } from './repository-source'
|
|
53
|
+
|
|
54
|
+
/** The only store reads the overview may make. Listing builds and reading
|
|
55
|
+
* events are deliberately absent, so a history scan cannot type-check. */
|
|
56
|
+
export type OverviewFrameReader = Pick<
|
|
57
|
+
BuildStore,
|
|
58
|
+
| 'getRepoChangePosition'
|
|
59
|
+
| 'getRepo'
|
|
60
|
+
| 'getReducerValue'
|
|
61
|
+
| 'getRepoArtifact'
|
|
62
|
+
| 'getBuild'
|
|
63
|
+
| 'listBuildsChangedSince'
|
|
64
|
+
| 'listStreams'
|
|
65
|
+
| 'getArtifact'
|
|
66
|
+
>
|
|
67
|
+
|
|
68
|
+
/** One visible build: everything its row and capacity facts need, so a
|
|
69
|
+
* config change re-projects it without reading. */
|
|
70
|
+
interface LiveBuild {
|
|
71
|
+
record: BuildRecord
|
|
72
|
+
facts: CurrentBuildFacts
|
|
73
|
+
enrichment: RowEnrichment
|
|
74
|
+
capacity: CapacityBuild
|
|
75
|
+
row: DashboardBuild | null
|
|
76
|
+
/** The config key `row` was projected with. */
|
|
77
|
+
projectedWith: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface BuildsState {
|
|
81
|
+
/** The changed-builds watermark. */
|
|
82
|
+
feed: string
|
|
83
|
+
live: Map<string, LiveBuild>
|
|
84
|
+
finished: readonly BuildRosterFinished[]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface LoadedConfig {
|
|
88
|
+
key: string
|
|
89
|
+
config: Config
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type Result = { frame: WebFrame; live: boolean }
|
|
93
|
+
|
|
94
|
+
export interface OverviewFrameSourceOptions {
|
|
95
|
+
/** Capacity projection time; defaults to the wall clock. */
|
|
96
|
+
clock?: () => Date
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The overview source. Its process-local state (gate position, feed
|
|
101
|
+
* watermark, visible builds, finished list, config) is rebuilt from saved
|
|
102
|
+
* values on a cold start, and every poll commits only after all its reads
|
|
103
|
+
* succeeded, so a failed poll retries from the old state.
|
|
104
|
+
*/
|
|
105
|
+
export class OverviewFrameSource implements WebFrameSource {
|
|
106
|
+
private gate: string | undefined
|
|
107
|
+
private cached: Result | undefined
|
|
108
|
+
private builds: BuildsState | undefined
|
|
109
|
+
private config: LoadedConfig | undefined
|
|
110
|
+
private readonly clock: () => Date
|
|
111
|
+
|
|
112
|
+
constructor(
|
|
113
|
+
private readonly reader: OverviewFrameReader,
|
|
114
|
+
private readonly repo: string,
|
|
115
|
+
opts: OverviewFrameSourceOptions = {},
|
|
116
|
+
) {
|
|
117
|
+
this.clock = opts.clock ?? (() => new Date())
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async read(admitted: () => boolean = () => true): Promise<Result> {
|
|
121
|
+
// Every store call checks admission first, so a read whose last
|
|
122
|
+
// subscriber left stops at the next call instead of reading on.
|
|
123
|
+
const reader = fenced(this.reader, admitted)
|
|
124
|
+
const position = await reader.getRepoChangePosition(this.repo)
|
|
125
|
+
if (this.cached !== undefined && position === this.gate) return this.cached
|
|
126
|
+
const facts = (await readRepositoryFacts(reader, this.repo)).value
|
|
127
|
+
const projected = projectRepositoryFrame(this.repo, facts)
|
|
128
|
+
// The position is the browser's refetch signal for explicit reads
|
|
129
|
+
// (analytics, build timelines), so every frame carries the one it was
|
|
130
|
+
// read at, even when nothing else in it changed.
|
|
131
|
+
const repository = { ...projected, frame: { ...projected.frame, position } }
|
|
132
|
+
const ref = facts.status?.effectiveConfig
|
|
133
|
+
if (ref === undefined) {
|
|
134
|
+
// No overview without a recorded config, and so no build reads.
|
|
135
|
+
this.commit(position, repository, undefined, this.config)
|
|
136
|
+
return repository
|
|
137
|
+
}
|
|
138
|
+
const config = await this.loadConfig(reader, `${ref.kind}@${ref.rev}`, ref.kind, ref.rev)
|
|
139
|
+
let builds =
|
|
140
|
+
this.builds === undefined ? undefined : await this.advance(reader, this.builds, config)
|
|
141
|
+
// No state yet, or the feed reports a reset: start from the roster.
|
|
142
|
+
builds ??= await this.coldStart(reader, config)
|
|
143
|
+
const result = {
|
|
144
|
+
frame: { ...repository.frame, overview: this.overview(facts, config, builds) },
|
|
145
|
+
live: repository.live,
|
|
146
|
+
}
|
|
147
|
+
this.commit(position, result, builds, config)
|
|
148
|
+
return result
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private commit(
|
|
152
|
+
position: string,
|
|
153
|
+
result: Result,
|
|
154
|
+
builds: BuildsState | undefined,
|
|
155
|
+
config: LoadedConfig | undefined,
|
|
156
|
+
): void {
|
|
157
|
+
this.gate = position
|
|
158
|
+
this.cached = result
|
|
159
|
+
this.builds = builds
|
|
160
|
+
this.config = config
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private async loadConfig(
|
|
164
|
+
reader: OverviewFrameReader,
|
|
165
|
+
key: string,
|
|
166
|
+
kind: string,
|
|
167
|
+
rev: number,
|
|
168
|
+
): Promise<LoadedConfig> {
|
|
169
|
+
if (this.config?.key === key) return this.config
|
|
170
|
+
const artifact = await reader.getRepoArtifact(this.repo, kind, rev)
|
|
171
|
+
if (artifact === null) throw new Error(`effective config ${key} is not retrievable`)
|
|
172
|
+
const config = configSchema.parse(
|
|
173
|
+
normalizeEffectiveConfigArtifact(JSON.parse(new TextDecoder().decode(artifact.content))),
|
|
174
|
+
)
|
|
175
|
+
return { key, config }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private async coldStart(reader: OverviewFrameReader, config: LoadedConfig): Promise<BuildsState> {
|
|
179
|
+
const roster = await readRoster(reader, this.repo)
|
|
180
|
+
// An acknowledged abort stays visible as cleaning until its final
|
|
181
|
+
// completion, so the roster's newest aborted entries are checked too.
|
|
182
|
+
const slugs = [
|
|
183
|
+
...roster.live.map((entry) => entry.slug),
|
|
184
|
+
...roster.finished.filter((entry) => entry.outcome === 'aborted').map((entry) => entry.slug),
|
|
185
|
+
]
|
|
186
|
+
const live = new Map<string, LiveBuild>()
|
|
187
|
+
for (const read of await mapBounded(slugs, (slug) => this.readBuild(reader, slug, config)))
|
|
188
|
+
if (read.build !== undefined) live.set(read.slug, read.build)
|
|
189
|
+
// The roster's position is the one its answer reflects, so the feed
|
|
190
|
+
// misses nothing between the roster snapshot and its next read.
|
|
191
|
+
return { feed: roster.position, live, finished: roster.finished }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Advance by the changed builds; undefined when the repository was reset. */
|
|
195
|
+
private async advance(
|
|
196
|
+
reader: OverviewFrameReader,
|
|
197
|
+
builds: BuildsState,
|
|
198
|
+
config: LoadedConfig,
|
|
199
|
+
): Promise<BuildsState | undefined> {
|
|
200
|
+
const changed = await reader.listBuildsChangedSince(this.repo, builds.feed)
|
|
201
|
+
if (BigInt(changed.position) < BigInt(builds.feed)) return undefined
|
|
202
|
+
const reads = await mapBounded(
|
|
203
|
+
changed.builds.map((build) => build.slug),
|
|
204
|
+
(slug) => this.readBuild(reader, slug, config),
|
|
205
|
+
)
|
|
206
|
+
const live = new Map(builds.live)
|
|
207
|
+
let rosterMoved = false
|
|
208
|
+
for (const { slug, state, build } of reads) {
|
|
209
|
+
const previous = live.get(slug)
|
|
210
|
+
// The feed reports each build once, at its latest position: a build
|
|
211
|
+
// created and completed between two polls arrives already done, so
|
|
212
|
+
// `done` alone moves the roster, whether or not it was ever visible.
|
|
213
|
+
if (state?.status === 'done') rosterMoved = true
|
|
214
|
+
if (build === undefined) {
|
|
215
|
+
if (previous !== undefined) rosterMoved = true
|
|
216
|
+
live.delete(slug)
|
|
217
|
+
continue
|
|
218
|
+
}
|
|
219
|
+
if (previous === undefined) rosterMoved = true
|
|
220
|
+
else if (state?.status === 'aborted' && previous.facts.state.status !== 'aborted')
|
|
221
|
+
rosterMoved = true
|
|
222
|
+
live.set(slug, build)
|
|
223
|
+
}
|
|
224
|
+
const finished = rosterMoved ? (await readRoster(reader, this.repo)).finished : builds.finished
|
|
225
|
+
return { feed: changed.position, live, finished }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** One build's targeted reads: its record and saved facts, then its row
|
|
229
|
+
* enrichment while it is still visible. */
|
|
230
|
+
private async readBuild(
|
|
231
|
+
reader: OverviewFrameReader,
|
|
232
|
+
slug: string,
|
|
233
|
+
config: LoadedConfig,
|
|
234
|
+
): Promise<{ slug: string; state?: BuildState; build?: LiveBuild }> {
|
|
235
|
+
const [record, { value: facts }] = await Promise.all([
|
|
236
|
+
reader.getBuild(slug),
|
|
237
|
+
readBuildFacts(reader, slug),
|
|
238
|
+
])
|
|
239
|
+
if (record === null || isDashboardTerminal(facts.state)) return { slug, state: facts.state }
|
|
240
|
+
const enrichment = await readRowEnrichment(reader, slug, facts.state.verify.configPin)
|
|
241
|
+
return {
|
|
242
|
+
slug,
|
|
243
|
+
state: facts.state,
|
|
244
|
+
build: {
|
|
245
|
+
record,
|
|
246
|
+
facts,
|
|
247
|
+
enrichment,
|
|
248
|
+
capacity: capacityBuildFromFacts(record, facts),
|
|
249
|
+
row: projectRowWithEnrichment(record, facts.state, [], config.config, enrichment, facts),
|
|
250
|
+
projectedWith: config.key,
|
|
251
|
+
},
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private overview(facts: RepositoryReadFacts, config: LoadedConfig, builds: BuildsState) {
|
|
256
|
+
// A config change re-projects every row from its cached reads.
|
|
257
|
+
for (const [slug, build] of builds.live)
|
|
258
|
+
if (build.projectedWith !== config.key)
|
|
259
|
+
builds.live.set(slug, {
|
|
260
|
+
...build,
|
|
261
|
+
row: projectRowWithEnrichment(
|
|
262
|
+
build.record,
|
|
263
|
+
build.facts.state,
|
|
264
|
+
[],
|
|
265
|
+
config.config,
|
|
266
|
+
build.enrichment,
|
|
267
|
+
build.facts,
|
|
268
|
+
),
|
|
269
|
+
projectedWith: config.key,
|
|
270
|
+
})
|
|
271
|
+
const visible = [...builds.live.values()]
|
|
272
|
+
const rows = visible
|
|
273
|
+
.map((build) => build.row)
|
|
274
|
+
.filter((row): row is DashboardBuild => row !== null)
|
|
275
|
+
.sort((a, b) => a.slug.localeCompare(b.slug))
|
|
276
|
+
const status = facts.status!
|
|
277
|
+
const model = buildDashboardFromProjected(
|
|
278
|
+
enrichIntegrationRows(
|
|
279
|
+
rows,
|
|
280
|
+
visible.map((build) => build.record),
|
|
281
|
+
),
|
|
282
|
+
repositoryDashboardHeader({
|
|
283
|
+
repo: this.repo,
|
|
284
|
+
status,
|
|
285
|
+
config: config.config,
|
|
286
|
+
repositoryFacts: facts,
|
|
287
|
+
capacityBuilds: visible.map((build) => build.capacity),
|
|
288
|
+
states: visible.map((build) => build.facts.state),
|
|
289
|
+
now: this.clock(),
|
|
290
|
+
...(status.triage !== undefined ? { triage: status.triage } : {}),
|
|
291
|
+
}),
|
|
292
|
+
facts,
|
|
293
|
+
facts.upgrades,
|
|
294
|
+
)
|
|
295
|
+
return projectOverview(model, {
|
|
296
|
+
...(status.health !== undefined ? { health: status.health } : {}),
|
|
297
|
+
finished: builds.finished.filter((entry) => !builds.live.has(entry.slug)),
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async function readRoster(reader: OverviewFrameReader, repo: string): Promise<BuildRosterValue> {
|
|
303
|
+
const { value } = await reader.getReducerValue(
|
|
304
|
+
{ kind: 'rollup', repo },
|
|
305
|
+
{ reducer: 'buildRoster' },
|
|
306
|
+
)
|
|
307
|
+
return value as unknown as BuildRosterValue
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Gate every reader call on `admitted`. */
|
|
311
|
+
function fenced<T extends object>(reader: T, admitted: () => boolean): T {
|
|
312
|
+
return new Proxy(reader, {
|
|
313
|
+
get(target, key, receiver) {
|
|
314
|
+
const value = Reflect.get(target, key, receiver)
|
|
315
|
+
if (typeof value !== 'function') return value
|
|
316
|
+
return async (...args: unknown[]) => {
|
|
317
|
+
if (!admitted()) throw new WebReadFencedError()
|
|
318
|
+
return Reflect.apply(value, target, args)
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FRAME_META, REPOSITORY_META, type WebAssetManifest } from './protocol'
|
|
2
|
+
|
|
3
|
+
const ESCAPES: Record<string, string> = {
|
|
4
|
+
'&': '&',
|
|
5
|
+
'<': '<',
|
|
6
|
+
'>': '>',
|
|
7
|
+
'"': '"',
|
|
8
|
+
"'": ''',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function escapeHtml(text: string): string {
|
|
12
|
+
return text.replace(/[&<>"']/g, (c) => ESCAPES[c]!)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The repository as a reader names it: its identity without a URL scheme. */
|
|
16
|
+
export function repositoryLabel(repo: string): string {
|
|
17
|
+
return repo.replace(/^https?:\/\//u, '')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The one HTML page. Every script and stylesheet is a same-origin file, so
|
|
22
|
+
* the page runs under `default-src 'self'` with no inline code; the nonce
|
|
23
|
+
* only lets UI SDK inject its own stylesheet at runtime. `frame`, the hub's
|
|
24
|
+
* serialized frame, rides in a meta tag as the skeleton's layout hint; it is
|
|
25
|
+
* attribute text, never executable.
|
|
26
|
+
*/
|
|
27
|
+
export function renderPage(opts: {
|
|
28
|
+
nonce: string
|
|
29
|
+
repositoryLabel: string
|
|
30
|
+
manifest: WebAssetManifest
|
|
31
|
+
frame?: string
|
|
32
|
+
}): string {
|
|
33
|
+
const label = escapeHtml(opts.repositoryLabel)
|
|
34
|
+
const asset = (path: string) => `/assets/${escapeHtml(path)}`
|
|
35
|
+
const preloads = opts.manifest.fonts
|
|
36
|
+
.map(
|
|
37
|
+
(font) =>
|
|
38
|
+
`<link rel="preload" href="${asset(font)}" as="font" type="font/woff2" crossorigin>`,
|
|
39
|
+
)
|
|
40
|
+
.join('\n')
|
|
41
|
+
return `<!doctype html>
|
|
42
|
+
<html lang="en">
|
|
43
|
+
<head>
|
|
44
|
+
<meta charset="utf-8">
|
|
45
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
46
|
+
<meta property="csp-nonce" nonce="${escapeHtml(opts.nonce)}">
|
|
47
|
+
<meta name="${REPOSITORY_META}" content="${label}">
|
|
48
|
+
${opts.frame !== undefined ? `<meta name="${FRAME_META}" content="${escapeHtml(opts.frame)}">\n` : ''}<title>Autobuild · ${label}</title>
|
|
49
|
+
${preloads}
|
|
50
|
+
<link rel="stylesheet" href="${asset(opts.manifest.stylesheet)}">
|
|
51
|
+
<script src="${asset(opts.manifest.themeScript)}"></script>
|
|
52
|
+
</head>
|
|
53
|
+
<body><div id="root"></div><script src="${asset(opts.manifest.script)}"></script></body>
|
|
54
|
+
</html>
|
|
55
|
+
`
|
|
56
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ab web` wire protocol: what the server pushes and what the page reads.
|
|
3
|
+
* Types, constants and one error class, so the browser client imports it as
|
|
4
|
+
* types without pulling server code into its bundle.
|
|
5
|
+
*/
|
|
6
|
+
import type { DashboardRepositoryHeader } from '../cli/dashboard/header'
|
|
7
|
+
import type {
|
|
8
|
+
AttentionItem,
|
|
9
|
+
DashboardOverview,
|
|
10
|
+
DashboardRowText,
|
|
11
|
+
DispatcherModeText,
|
|
12
|
+
FinishedRowText,
|
|
13
|
+
HarvestRowText,
|
|
14
|
+
} from '../cli/dashboard/row-text'
|
|
15
|
+
import type { TimelineSegment } from '../cli/dashboard/timeline'
|
|
16
|
+
import type { StepDurationStat, StepDurationWindow } from '../kernel/step-durations'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Row and overview terms are aliases of the shared dashboard projection, never
|
|
20
|
+
* restatements, so the web cannot drift into its own wording. Step timing
|
|
21
|
+
* travels raw; the page formats elapsed time with `cli/dashboard/vocabulary`.
|
|
22
|
+
*/
|
|
23
|
+
export type WebBuildRow = DashboardRowText
|
|
24
|
+
export type WebHarvestRow = HarvestRowText
|
|
25
|
+
export type WebFinishedRow = FinishedRowText
|
|
26
|
+
export type WebAttentionItem = AttentionItem
|
|
27
|
+
export type WebDispatcherMode = DispatcherModeText
|
|
28
|
+
export type WebOverview = DashboardOverview
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* One model frame, pushed whole over the `/events` stream as JSON. Later
|
|
32
|
+
* views add optional members; every member must survive a JSON round trip
|
|
33
|
+
* unchanged (no `undefined` values, dates, maps or sets), because the server
|
|
34
|
+
* compares serialized frames to decide whether to push.
|
|
35
|
+
*/
|
|
36
|
+
export interface WebFrame {
|
|
37
|
+
/** The repository-scope dashboard header, the same terms the terminal shows. */
|
|
38
|
+
repository?: DashboardRepositoryHeader
|
|
39
|
+
/** The overview page: dispatcher mode, header terms, attention list, active,
|
|
40
|
+
* queued and finished rows, all from the shared projection the terminal
|
|
41
|
+
* renders. */
|
|
42
|
+
overview?: WebOverview
|
|
43
|
+
/** A one-line notice standing in for content that cannot be shown yet. */
|
|
44
|
+
notice?: string
|
|
45
|
+
/** The repository change position the frame's facts were read at. It moves
|
|
46
|
+
* on every build and repository event, so a change the analytics page or a
|
|
47
|
+
* build timeline could reflect always makes a new frame; the page refetches
|
|
48
|
+
* those explicit reads when it differs from the last one it fetched at. */
|
|
49
|
+
position?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The analytics page's question: a window plus the step-duration rollup's
|
|
53
|
+
* own key arguments, and an opaque listing cursor for the Gantt's page. */
|
|
54
|
+
export interface WebAnalyticsQuery {
|
|
55
|
+
window: StepDurationWindow
|
|
56
|
+
outcome: 'merged' | 'all'
|
|
57
|
+
kind: 'leaf' | 'node' | 'all'
|
|
58
|
+
page?: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One Gantt row: a build's identity and its raw timeline segments, with ISO
|
|
62
|
+
* times, from the build's saved `buildTimeline` value. */
|
|
63
|
+
export interface WebTimelineRow {
|
|
64
|
+
slug: string
|
|
65
|
+
ticketId?: string
|
|
66
|
+
ticketUrl?: string
|
|
67
|
+
title?: string
|
|
68
|
+
kind: 'work' | 'node'
|
|
69
|
+
/** The latest completion outcome; absent while not completed. */
|
|
70
|
+
outcome?: string
|
|
71
|
+
createdAt?: string
|
|
72
|
+
segments: TimelineSegment[]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `GET /api/analytics`: both charts for one query. */
|
|
76
|
+
export interface WebAnalytics {
|
|
77
|
+
/** The normalised query the answer is for. */
|
|
78
|
+
query: WebAnalyticsQuery
|
|
79
|
+
/** The repository change position the answer reflects. */
|
|
80
|
+
position: string
|
|
81
|
+
/** The window's first instant (ISO), shared by both charts. */
|
|
82
|
+
windowStart: string
|
|
83
|
+
/** Per step, in pipeline order with waits last. */
|
|
84
|
+
durations: StepDurationStat[]
|
|
85
|
+
/** One page of builds active in the window, most recently active first. */
|
|
86
|
+
gantt: { rows: WebTimelineRow[]; next: string | null }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** `GET /api/builds/<slug>/timeline`. */
|
|
90
|
+
export interface WebBuildTimeline {
|
|
91
|
+
row: WebTimelineRow
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The read-only JSON routes beside the event stream. */
|
|
95
|
+
export const WEB_API = {
|
|
96
|
+
analytics: '/api/analytics',
|
|
97
|
+
timeline: (slug: string) => `/api/builds/${encodeURIComponent(slug)}/timeline`,
|
|
98
|
+
} as const
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Produces frames for the shared refresh loop. `live` asks for the fast
|
|
102
|
+
* cadence. `admitted` reports whether anyone still wants the frame: a source
|
|
103
|
+
* checks it before each further store read and, once it is false, stops with
|
|
104
|
+
* `WebReadFencedError` instead of reading on for nobody.
|
|
105
|
+
*/
|
|
106
|
+
export interface WebFrameSource {
|
|
107
|
+
read(admitted?: () => boolean): Promise<{ frame: WebFrame; live: boolean } | undefined>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A frame read abandoned because its last subscriber left; not a failure. */
|
|
111
|
+
export class WebReadFencedError extends Error {
|
|
112
|
+
constructor() {
|
|
113
|
+
super('ab web read abandoned: no subscriber')
|
|
114
|
+
this.name = 'WebReadFencedError'
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Server-sent event names on `/events`. */
|
|
119
|
+
export const WEB_EVENTS = { model: 'model' } as const
|
|
120
|
+
|
|
121
|
+
/** `<meta name>` carrying the repository label into the page. */
|
|
122
|
+
export const REPOSITORY_META = 'ab-repository'
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* `<meta name>` carrying the hub's current frame, serialized, into the page.
|
|
126
|
+
* It is a layout hint: the page renders it masked as its loading skeleton so
|
|
127
|
+
* the skeleton has the loaded page's geometry. It is never shown as live data;
|
|
128
|
+
* the facts come from the `/events` stream.
|
|
129
|
+
*/
|
|
130
|
+
export const FRAME_META = 'ab-frame'
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* How long a page request waits for the hub's first frame when it holds none.
|
|
134
|
+
* A safety bound for a hung first read, not an expected wait: the hub delivers
|
|
135
|
+
* a frame, data or a failure notice, for every read that finishes.
|
|
136
|
+
*/
|
|
137
|
+
export const PAGE_FRAME_WAIT_MS = 10_000
|
|
138
|
+
|
|
139
|
+
/** Browser storage key for the theme choice (`light` or `dark`; absent is system). */
|
|
140
|
+
export const THEME_STORAGE_KEY = 'ab-theme'
|
|
141
|
+
|
|
142
|
+
/** `manifest.json` beside the committed client assets. */
|
|
143
|
+
export interface WebAssetManifest {
|
|
144
|
+
/** Every served file, with its content type. */
|
|
145
|
+
files: { path: string; type: string }[]
|
|
146
|
+
script: string
|
|
147
|
+
stylesheet: string
|
|
148
|
+
themeScript: string
|
|
149
|
+
/** Font files the page preloads. */
|
|
150
|
+
fonts: string[]
|
|
151
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const READ = /^(get|list|read|load|count)/u
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrap a store so only reads pass. `ab web` holds the store through this
|
|
5
|
+
* guard, so no endpoint can append an event or change build, ticket or
|
|
6
|
+
* repository state, whatever a later view calls. Calls run with the real
|
|
7
|
+
* store as `this`, so an adapter's internal bookkeeping inside a read (a
|
|
8
|
+
* saved reduced value, for instance) stays internal.
|
|
9
|
+
*/
|
|
10
|
+
export function readOnlyStore<T extends object>(store: T): T {
|
|
11
|
+
return new Proxy(store, {
|
|
12
|
+
get(target, key, receiver) {
|
|
13
|
+
const value = Reflect.get(target, key, receiver)
|
|
14
|
+
if (typeof value !== 'function') return value
|
|
15
|
+
const name = String(key)
|
|
16
|
+
if (READ.test(name) || name === 'close')
|
|
17
|
+
return (...args: unknown[]) => Reflect.apply(value, target, args)
|
|
18
|
+
return () => {
|
|
19
|
+
throw new Error(`ab web is read-only: ${name}`)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NO_DISPATCHER_RUN_LINE } from '../cli/dashboard/configuration'
|
|
2
|
+
import {
|
|
3
|
+
dispatchWarningLines,
|
|
4
|
+
projectRepositoryHeader,
|
|
5
|
+
repositoryQueueDepth,
|
|
6
|
+
} from '../cli/dashboard/header'
|
|
7
|
+
import type { RepositoryReadFacts } from '../store/reduced-reads'
|
|
8
|
+
import type { WebFrame } from './protocol'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The web UI's repository frame for `facts`, the repository value a store
|
|
12
|
+
* read returned: the dashboard header facts that come from repository-scope
|
|
13
|
+
* values only, plus the notice. Pure. `ab dispatch --web` pushes exactly this
|
|
14
|
+
* frame; `ab web` adds the overview to it (`overview-source.ts`). `live` asks
|
|
15
|
+
* for the fast cadence.
|
|
16
|
+
*/
|
|
17
|
+
export function projectRepositoryFrame(
|
|
18
|
+
repo: string,
|
|
19
|
+
facts: RepositoryReadFacts,
|
|
20
|
+
): { frame: WebFrame; live: boolean } {
|
|
21
|
+
const status = facts.status
|
|
22
|
+
const { header } = projectRepositoryHeader(
|
|
23
|
+
{
|
|
24
|
+
repo,
|
|
25
|
+
queued: repositoryQueueDepth(facts),
|
|
26
|
+
...(status?.triage !== undefined ? { triage: status.triage } : {}),
|
|
27
|
+
...(status?.availableUpgrade !== undefined
|
|
28
|
+
? { availableUpgrade: status.availableUpgrade }
|
|
29
|
+
: {}),
|
|
30
|
+
warningLines: status ? dispatchWarningLines(status) : [],
|
|
31
|
+
},
|
|
32
|
+
facts,
|
|
33
|
+
facts.upgrades,
|
|
34
|
+
)
|
|
35
|
+
const notice = facts.config.run === undefined ? NO_DISPATCHER_RUN_LINE : status?.notice
|
|
36
|
+
const frame: WebFrame = { repository: header, ...(notice !== undefined ? { notice } : {}) }
|
|
37
|
+
const live = status?.health === 'starting' || status?.health === 'running'
|
|
38
|
+
return { frame, live }
|
|
39
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { createWebHandler, type WebHandlerOptions } from './http'
|
|
4
|
+
import type { WebAssetManifest } from './protocol'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The committed client bundle's directory, resolved at call time. A literal
|
|
8
|
+
* `new URL('./assets/', import.meta.url)` is a static asset reference to
|
|
9
|
+
* bundlers, and Turbopack fails the hosted service build on a directory one
|
|
10
|
+
* whenever the dispatcher module graph reaches this file.
|
|
11
|
+
*/
|
|
12
|
+
function assetsDir(): string {
|
|
13
|
+
const dir = (import.meta as { dir?: unknown }).dir
|
|
14
|
+
return join(
|
|
15
|
+
typeof dir === 'string' && dir !== '' ? dir : dirname(fileURLToPath(import.meta.url)),
|
|
16
|
+
'assets',
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The committed client bundle's manifest. */
|
|
21
|
+
export async function loadWebManifest(): Promise<WebAssetManifest> {
|
|
22
|
+
return (await Bun.file(join(assetsDir(), 'manifest.json')).json()) as WebAssetManifest
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Serves one manifest-allowlisted asset name. */
|
|
26
|
+
export function readWebAsset(path: string): BodyInit {
|
|
27
|
+
return Bun.file(join(assetsDir(), path))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface StartedWebServer {
|
|
31
|
+
url: string
|
|
32
|
+
port: number
|
|
33
|
+
stop(): Promise<void>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The URL a person opens: wildcard binds print loopback, IPv6 is bracketed. */
|
|
37
|
+
export function webServerUrl(hostname: string, port: number): string {
|
|
38
|
+
const host = hostname === '0.0.0.0' || hostname === '::' ? '127.0.0.1' : hostname
|
|
39
|
+
return `http://${host.includes(':') ? `[${host}]` : host}:${port}/`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class WebPortInUseError extends Error {
|
|
43
|
+
constructor(hostname: string, port: number, command = 'ab web') {
|
|
44
|
+
super(
|
|
45
|
+
`${command}: port ${port} is already in use on ${hostname}; choose another --port, or omit it for a free port`,
|
|
46
|
+
)
|
|
47
|
+
this.name = 'WebPortInUseError'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function startWebServer(
|
|
52
|
+
opts: Omit<WebHandlerOptions, 'manifest' | 'readAsset'> &
|
|
53
|
+
Partial<Pick<WebHandlerOptions, 'manifest' | 'readAsset'>> & {
|
|
54
|
+
hostname: string
|
|
55
|
+
port: number
|
|
56
|
+
/** The command named in errors; default `ab web`. */
|
|
57
|
+
command?: string
|
|
58
|
+
},
|
|
59
|
+
): Promise<StartedWebServer> {
|
|
60
|
+
const command = opts.command ?? 'ab web'
|
|
61
|
+
const handler = createWebHandler({
|
|
62
|
+
...opts,
|
|
63
|
+
manifest: opts.manifest ?? (await loadWebManifest()),
|
|
64
|
+
readAsset: opts.readAsset ?? readWebAsset,
|
|
65
|
+
})
|
|
66
|
+
let server: ReturnType<typeof Bun.serve>
|
|
67
|
+
try {
|
|
68
|
+
server = Bun.serve({
|
|
69
|
+
hostname: opts.hostname,
|
|
70
|
+
port: opts.port,
|
|
71
|
+
development: false,
|
|
72
|
+
// Without this, Bun's production mode shares a taken port instead of
|
|
73
|
+
// failing, and two servers would split one URL's requests.
|
|
74
|
+
reusePort: false,
|
|
75
|
+
fetch: (request, bun) => handler(request, bun),
|
|
76
|
+
error: () =>
|
|
77
|
+
new Response(`${command}: internal error`, {
|
|
78
|
+
status: 500,
|
|
79
|
+
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
80
|
+
}),
|
|
81
|
+
})
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const code = (error as { code?: unknown }).code
|
|
84
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
85
|
+
if (code === 'EADDRINUSE' || /EADDRINUSE|address already in use|in use/i.test(message))
|
|
86
|
+
throw new WebPortInUseError(opts.hostname, opts.port, command)
|
|
87
|
+
throw error
|
|
88
|
+
}
|
|
89
|
+
const port = server.port ?? opts.port
|
|
90
|
+
return {
|
|
91
|
+
url: webServerUrl(opts.hostname, port),
|
|
92
|
+
port,
|
|
93
|
+
stop: () => server.stop(true),
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type WebServerStarter = typeof startWebServer
|