@defrex/autobuild 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +738 -68
- 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 +155 -25
- 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 +63 -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 +101 -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 +178 -76
- package/packages/core/src/cli/dashboard/render.ts +129 -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 +29 -38
- 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 +200 -34
- 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 +97 -43
- 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 +316 -0
- 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/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/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/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +25 -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 +122 -72
- 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 +6987 -5749
- 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 +11 -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/index.ts +18 -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-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 +35 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +366 -52
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
|
|
2
|
-
import { migrationIdentity } from '../kernel/ticket-migrations'
|
|
3
2
|
import type { DispatchUpgradeState } from '../kernel/dispatch-upgrade'
|
|
4
3
|
import { releaseDispatchPresentation } from './dispatch-presentation-ownership'
|
|
4
|
+
import type { DispatchWeb } from './dispatch-web'
|
|
5
5
|
import {
|
|
6
6
|
readDispatchUpgrade,
|
|
7
7
|
readRepositoryFacts,
|
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
} from '../store/reduced-reads'
|
|
10
10
|
import { DISPATCHER } from '../events/envelope'
|
|
11
11
|
import { launchContext } from './dispatch-launch-contract'
|
|
12
|
-
import { dispatchCapacity, startClaimDemand, urgentClaimDemand } from '../kernel/dispatch-capacity'
|
|
13
|
-
import { forgeReadinessWarnings } from '../kernel/dispatch-status'
|
|
14
12
|
import { RepositoryPollCache } from './dashboard/repository-poll'
|
|
15
13
|
import {
|
|
16
14
|
DashboardRefresh,
|
|
@@ -45,7 +43,11 @@ import {
|
|
|
45
43
|
type DashboardSelection,
|
|
46
44
|
type DashboardView,
|
|
47
45
|
} from './dashboard/model'
|
|
48
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
DashboardBuildPollCache,
|
|
48
|
+
repositoryDashboardHeader,
|
|
49
|
+
type DashboardPollSnapshot,
|
|
50
|
+
} from './dashboard/poll'
|
|
49
51
|
import {
|
|
50
52
|
dashboardContentWidth,
|
|
51
53
|
detailScrollLimit,
|
|
@@ -106,6 +108,9 @@ interface ResumePrompt {
|
|
|
106
108
|
export interface DispatchFrontendOptions {
|
|
107
109
|
viewer?: { dispatchedBy?: string }
|
|
108
110
|
plainOutput?: (line: string) => void
|
|
111
|
+
/** `--web`: each frame's repository facts are published to the web UI from
|
|
112
|
+
* the read this frontend already made; the web adds no store read. */
|
|
113
|
+
web?: { dispatch: DispatchWeb }
|
|
109
114
|
/** Repository identity (§12): the normalized origin, or the checkout path
|
|
110
115
|
* when there is no origin. Every Store key uses this. */
|
|
111
116
|
repo: string
|
|
@@ -211,7 +216,9 @@ export class DispatchFrontend {
|
|
|
211
216
|
* operator action. High-frequency dispatcher status is folded from deltas;
|
|
212
217
|
* the feed retains standby identities only, and dashboard facts come from
|
|
213
218
|
* the canonical repository facts. */
|
|
214
|
-
|
|
219
|
+
/** Returns the change position a viewer's facts were read at; a kernel
|
|
220
|
+
* frontend samples none here. */
|
|
221
|
+
private async advanceRepository(sampledPosition?: string): Promise<string | undefined> {
|
|
215
222
|
if (this.opts.viewer) {
|
|
216
223
|
const position = sampledPosition ?? (await this.reader.getRepoChangePosition(this.opts.repo))
|
|
217
224
|
if (
|
|
@@ -223,7 +230,7 @@ export class DispatchFrontend {
|
|
|
223
230
|
this.viewerReadAt = this.clock().getTime()
|
|
224
231
|
}
|
|
225
232
|
this.dispatchStatus = this.viewerFacts!.status ?? reduceDispatchStatus([], this.runId)
|
|
226
|
-
return
|
|
233
|
+
return position
|
|
227
234
|
}
|
|
228
235
|
const refresh = this.eventRefreshTail.then(async () => {
|
|
229
236
|
const delta = await this.repositoryFeed.refresh(false)
|
|
@@ -233,6 +240,7 @@ export class DispatchFrontend {
|
|
|
233
240
|
})
|
|
234
241
|
this.eventRefreshTail = refresh.catch(() => {})
|
|
235
242
|
await refresh
|
|
243
|
+
return undefined
|
|
236
244
|
}
|
|
237
245
|
|
|
238
246
|
private async report(message: string, level: 'info' | 'warning' = 'info'): Promise<void> {
|
|
@@ -433,6 +441,7 @@ export class DispatchFrontend {
|
|
|
433
441
|
this.repositoryFeed.present ? true : undefined,
|
|
434
442
|
)
|
|
435
443
|
).value
|
|
444
|
+
this.opts.web?.dispatch.publishFacts(repositoryFacts, sampledPosition)
|
|
436
445
|
const upgrades = repositoryFacts.upgrades
|
|
437
446
|
const status = this.dispatchStatus
|
|
438
447
|
const ref = status.effectiveConfig
|
|
@@ -491,7 +500,7 @@ export class DispatchFrontend {
|
|
|
491
500
|
const slug = this.abortConfirmation.slug
|
|
492
501
|
if (!validAbortConfirmation(snapshot.states.get(slug))) {
|
|
493
502
|
await this.dismissStaleAbortConfirmation(slug)
|
|
494
|
-
await this.advanceRepository()
|
|
503
|
+
const position = await this.advanceRepository()
|
|
495
504
|
repositoryFacts = (
|
|
496
505
|
await readRepositoryFacts(
|
|
497
506
|
this.reader,
|
|
@@ -499,41 +508,23 @@ export class DispatchFrontend {
|
|
|
499
508
|
this.repositoryFeed.present ? true : undefined,
|
|
500
509
|
)
|
|
501
510
|
).value
|
|
511
|
+
this.opts.web?.dispatch.publishFacts(repositoryFacts, position)
|
|
502
512
|
upgrades = repositoryFacts.upgrades
|
|
503
513
|
status = this.dispatchStatus
|
|
504
514
|
}
|
|
505
515
|
}
|
|
506
516
|
|
|
507
517
|
const previous = this.model === undefined ? [] : dashboardSelections(this.model)
|
|
508
|
-
const warningLines = [
|
|
509
|
-
...status.roleWarnings,
|
|
510
|
-
...forgeReadinessWarnings(status),
|
|
511
|
-
...(status.warningNotice !== undefined ? [status.warningNotice] : []),
|
|
512
|
-
]
|
|
513
518
|
const projected = buildDashboardFromProjected(
|
|
514
519
|
snapshot.builds,
|
|
515
|
-
{
|
|
520
|
+
repositoryDashboardHeader({
|
|
516
521
|
repo: this.opts.repo,
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
)
|
|
522
|
-
|
|
523
|
-
capacityProjection: dispatchCapacity(
|
|
524
|
-
snapshot.capacityBuilds ?? [],
|
|
525
|
-
config.capacity,
|
|
526
|
-
this.clock(),
|
|
527
|
-
migrationIdentity(repositoryFacts.ticketMigrations, config.tickets.source),
|
|
528
|
-
{
|
|
529
|
-
urgentClaims: urgentClaimDemand(repositoryFacts),
|
|
530
|
-
openPrs: {
|
|
531
|
-
policy: config.policy,
|
|
532
|
-
engaged: repositoryFacts.openPrBackpressure !== undefined,
|
|
533
|
-
},
|
|
534
|
-
startRequests: startClaimDemand(repositoryFacts),
|
|
535
|
-
},
|
|
536
|
-
),
|
|
522
|
+
status,
|
|
523
|
+
config,
|
|
524
|
+
repositoryFacts,
|
|
525
|
+
capacityBuilds: snapshot.capacityBuilds ?? [],
|
|
526
|
+
states: snapshot.states.values(),
|
|
527
|
+
now: this.clock(),
|
|
537
528
|
// A viewer shows only its own read; headless ticks publish no count.
|
|
538
529
|
...(this.opts.viewer
|
|
539
530
|
? this.viewerTriage !== undefined
|
|
@@ -542,11 +533,8 @@ export class DispatchFrontend {
|
|
|
542
533
|
: status.triage !== undefined
|
|
543
534
|
? { triage: status.triage }
|
|
544
535
|
: {}),
|
|
545
|
-
...(
|
|
546
|
-
|
|
547
|
-
: {}),
|
|
548
|
-
...(warningLines.length > 0 ? { warningLines } : {}),
|
|
549
|
-
},
|
|
536
|
+
...(standby !== undefined ? { standby } : {}),
|
|
537
|
+
}),
|
|
550
538
|
repositoryFacts,
|
|
551
539
|
upgrades,
|
|
552
540
|
)
|
|
@@ -1122,6 +1110,7 @@ export class DispatchFrontend {
|
|
|
1122
1110
|
// One durable warning per failure streak, not per poll: a poll that
|
|
1123
1111
|
// fails on every tick would otherwise grow the journal it reads.
|
|
1124
1112
|
// Messages carry moving cursors, so they cannot serve as the dedup key.
|
|
1113
|
+
if (this.refresh?.admitted) this.opts.web?.dispatch.hub.fail(error)
|
|
1125
1114
|
if (this.refresh?.admitted && !this.renderFailureReported) {
|
|
1126
1115
|
this.renderFailureReported = true
|
|
1127
1116
|
await this.report(
|
|
@@ -1305,6 +1294,8 @@ export class DispatchFrontend {
|
|
|
1305
1294
|
this.presentationRestored = true
|
|
1306
1295
|
releaseDispatchPresentation()
|
|
1307
1296
|
}
|
|
1297
|
+
// Free the web port before the successor may bind it.
|
|
1298
|
+
await this.opts.web?.dispatch.close()
|
|
1308
1299
|
await this.opts.store.appendRepo(this.opts.repo, {
|
|
1309
1300
|
actor: DISPATCHER,
|
|
1310
1301
|
type: 'dispatcher.terminal-released',
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
BRACKETED_PASTE_MODE,
|
|
5
5
|
ALTERNATE_SCREEN_MODE,
|
|
6
6
|
HIDDEN_CURSOR_MODE,
|
|
7
|
+
DRAINED_QUIT_EXIT,
|
|
7
8
|
} from './terminal-restore'
|
|
8
9
|
import { GENERATION_SIGNALS } from './dispatch-launch-contract'
|
|
9
10
|
|
|
@@ -53,3 +54,20 @@ export function holdDrainedStop(
|
|
|
53
54
|
): void {
|
|
54
55
|
for (const signal of GENERATION_SIGNALS) boundary.on(signal, exit)
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Public outcome after the drain: SIGINT exits 0; SIGQUIT exits 131 rather
|
|
60
|
+
* than dumping core by default disposition; SIGHUP and SIGTERM are re-delivered
|
|
61
|
+
* so the shell sees the signal.
|
|
62
|
+
*/
|
|
63
|
+
export function drainedLauncherExit(
|
|
64
|
+
signal: NodeJS.Signals | undefined,
|
|
65
|
+
publicCode: number,
|
|
66
|
+
boundary: { readonly pid: number; kill(pid: number, signal: NodeJS.Signals): unknown } = process,
|
|
67
|
+
): number {
|
|
68
|
+
if (signal === undefined) return publicCode
|
|
69
|
+
if (signal === 'SIGINT') return 0
|
|
70
|
+
if (signal === 'SIGQUIT') return DRAINED_QUIT_EXIT
|
|
71
|
+
boundary.kill(boundary.pid, signal)
|
|
72
|
+
return publicCode
|
|
73
|
+
}
|
|
@@ -6,8 +6,13 @@ import {
|
|
|
6
6
|
sourceContent,
|
|
7
7
|
type SourceLaunch,
|
|
8
8
|
} from './dispatch-upgrade-source'
|
|
9
|
-
import { parseDispatchArgs } from './dispatch-args'
|
|
10
|
-
import {
|
|
9
|
+
import { parseDispatchArgs, pinWebPort } from './dispatch-args'
|
|
10
|
+
import { DEFAULT_WEB_HOST, reserveWebPort } from '../web/options'
|
|
11
|
+
import {
|
|
12
|
+
drainedLauncherExit,
|
|
13
|
+
operatorStopped,
|
|
14
|
+
restoreLauncherTerminal,
|
|
15
|
+
} from './dispatch-launch-stop'
|
|
11
16
|
import { watchPresentationJob } from './dispatch-presentation-job'
|
|
12
17
|
import { dirname, basename, resolve, join } from 'node:path'
|
|
13
18
|
import { randomUUID } from 'node:crypto'
|
|
@@ -73,9 +78,18 @@ export async function prepareLaunchRuntime(
|
|
|
73
78
|
provenance: await guestArchiveProvenance(originalInstall),
|
|
74
79
|
})
|
|
75
80
|
}
|
|
76
|
-
export async function launchDispatcher(
|
|
77
|
-
// The caller already parsed this argv; only presentation
|
|
78
|
-
const { plain } = parseDispatchArgs(
|
|
81
|
+
export async function launchDispatcher(launchArgv: string[]): Promise<number> {
|
|
82
|
+
// The caller already parsed this argv; only presentation and the web port matter here.
|
|
83
|
+
const { plain, web } = parseDispatchArgs(launchArgv.slice(1), process.env)
|
|
84
|
+
// `--web` without a fixed port: reserve one now and pin it into every
|
|
85
|
+
// generation's argv, so the announced URL survives runtime upgrades.
|
|
86
|
+
const argv =
|
|
87
|
+
web !== undefined && web.port === 0
|
|
88
|
+
? [
|
|
89
|
+
'dispatch',
|
|
90
|
+
...pinWebPort(launchArgv.slice(1), await reserveWebPort(web.host ?? DEFAULT_WEB_HOST)),
|
|
91
|
+
]
|
|
92
|
+
: launchArgv
|
|
79
93
|
const checkout = await resolveMainRepo(process.cwd(), gitExec)
|
|
80
94
|
// Keep the public installation pathname rather than its realpath into Bun's version store.
|
|
81
95
|
const entry = resolve(process.argv[1] ?? '')
|
|
@@ -590,6 +604,5 @@ export async function launchDispatcher(argv: string[]): Promise<number> {
|
|
|
590
604
|
for (const root of protectedRoots) releasePreparedRuntime(root)
|
|
591
605
|
pruneRuntimes(dirname(dirname(runtime.root)))
|
|
592
606
|
}
|
|
593
|
-
|
|
594
|
-
return signal === 'SIGINT' ? 0 : publicCode
|
|
607
|
+
return drainedLauncherExit(signal, publicCode)
|
|
595
608
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { RepositoryReadFacts } from '../store/reduced-reads'
|
|
2
|
+
import type { BuildStore } from '../store/types'
|
|
3
|
+
import { WebAnalyticsSource } from '../web/analytics-source'
|
|
4
|
+
import { readOnlyStore } from '../web/read-only'
|
|
5
|
+
import { WebModelHub } from '../web/hub'
|
|
6
|
+
import { projectRepositoryFrame } from '../web/repository-source'
|
|
7
|
+
import { WebPortInUseError, type StartedWebServer, type WebServerStarter } from '../web/server'
|
|
8
|
+
import type { DispatchWebArgs } from './dispatch-args'
|
|
9
|
+
import { launchContext } from './dispatch-launch-contract'
|
|
10
|
+
import { serveRepositoryWeb } from './web'
|
|
11
|
+
|
|
12
|
+
/** How long a successor generation waits for its predecessor to free the port. */
|
|
13
|
+
export const SUCCESSOR_BIND_RETRY_MS = 100
|
|
14
|
+
export const SUCCESSOR_BIND_ATTEMPTS = 100
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The web UI a dispatcher serves in process (`ab dispatch --web`). Its hub is
|
|
18
|
+
* in push mode and shows the repository facts that a refresh the dispatcher
|
|
19
|
+
* already performs read from the store. Frames from the dashboard frontend
|
|
20
|
+
* carry the change position that refresh sampled, so they add no read. A
|
|
21
|
+
* kernel-only dispatcher's journal refresh samples none, so while a browser
|
|
22
|
+
* is connected each of its frames reads one `getRepoChangePosition`, and
|
|
23
|
+
* nothing while nobody watches. Analytics and timeline requests are explicit
|
|
24
|
+
* reads through the attached store.
|
|
25
|
+
*/
|
|
26
|
+
export interface DispatchWeb {
|
|
27
|
+
hub: WebModelHub
|
|
28
|
+
url: string
|
|
29
|
+
/** Serve the frame for facts a dispatcher refresh just read, stamped with
|
|
30
|
+
* `position` when the refresh sampled one. Without one, and only while a
|
|
31
|
+
* browser is connected and a store is attached, one position read. */
|
|
32
|
+
publishFacts(facts: RepositoryReadFacts, position?: string): void
|
|
33
|
+
/** Serve analytics over `store`, once it is open. Until then the routes
|
|
34
|
+
* answer 503. A later call replaces the store. */
|
|
35
|
+
attachStore(store: BuildStore): void
|
|
36
|
+
/** Stop the server and drop every connection. Idempotent. */
|
|
37
|
+
close(): Promise<void>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface StartDispatchWebOpts {
|
|
41
|
+
options: DispatchWebArgs
|
|
42
|
+
repo: string
|
|
43
|
+
env: Record<string, string | undefined>
|
|
44
|
+
stdout: (line: string) => void
|
|
45
|
+
stderr: (line: string) => void
|
|
46
|
+
start?: WebServerStarter
|
|
47
|
+
sleep?: (ms: number) => Promise<void>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Bind the dispatcher's web server. A first generation fails on a taken port,
|
|
52
|
+
* before it takes the repository lease. A successor generation already holds
|
|
53
|
+
* the lease from preflight, so it waits for its predecessor to free the
|
|
54
|
+
* pinned port and, if it never does, keeps dispatching without the web UI.
|
|
55
|
+
* Only a first generation announces the URL, so it is printed once.
|
|
56
|
+
*/
|
|
57
|
+
export async function startDispatchWeb(
|
|
58
|
+
opts: StartDispatchWebOpts,
|
|
59
|
+
): Promise<DispatchWeb | undefined> {
|
|
60
|
+
const context = launchContext(opts.env)
|
|
61
|
+
const successor =
|
|
62
|
+
context?.predecessor !== undefined ||
|
|
63
|
+
context?.recovery !== undefined ||
|
|
64
|
+
context?.rollback !== undefined
|
|
65
|
+
const hub = new WebModelHub({})
|
|
66
|
+
let analytics: WebAnalyticsSource | undefined
|
|
67
|
+
let attached: BuildStore | undefined
|
|
68
|
+
let store: BuildStore | undefined
|
|
69
|
+
const sleep = opts.sleep ?? ((ms: number) => Bun.sleep(ms))
|
|
70
|
+
let server: StartedWebServer | undefined
|
|
71
|
+
for (let attempt = 1; server === undefined; attempt++) {
|
|
72
|
+
try {
|
|
73
|
+
server = await serveRepositoryWeb({
|
|
74
|
+
hub,
|
|
75
|
+
repo: opts.repo,
|
|
76
|
+
...(opts.options.host !== undefined ? { host: opts.options.host } : {}),
|
|
77
|
+
port: opts.options.port,
|
|
78
|
+
json: opts.options.json,
|
|
79
|
+
command: 'ab dispatch',
|
|
80
|
+
announce: !successor,
|
|
81
|
+
stdout: opts.stdout,
|
|
82
|
+
stderr: opts.stderr,
|
|
83
|
+
analytics: () => analytics,
|
|
84
|
+
...(opts.start !== undefined ? { start: opts.start } : {}),
|
|
85
|
+
})
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (!successor || !(error instanceof WebPortInUseError)) {
|
|
88
|
+
hub.close()
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
if (attempt >= SUCCESSOR_BIND_ATTEMPTS) {
|
|
92
|
+
hub.close()
|
|
93
|
+
opts.stderr(`ab dispatch: web UI unavailable after handoff: ${error.message}`)
|
|
94
|
+
return undefined
|
|
95
|
+
}
|
|
96
|
+
await sleep(SUCCESSOR_BIND_RETRY_MS)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const started = server
|
|
100
|
+
let closing: Promise<void> | undefined
|
|
101
|
+
const publish = (facts: RepositoryReadFacts, position?: string) => {
|
|
102
|
+
const frame = projectRepositoryFrame(opts.repo, facts).frame
|
|
103
|
+
hub.publish(position !== undefined ? { ...frame, position } : frame)
|
|
104
|
+
}
|
|
105
|
+
// The kernel path's position read: single-flight, latest facts win.
|
|
106
|
+
let reading = false
|
|
107
|
+
let pending: RepositoryReadFacts | undefined
|
|
108
|
+
const stampAndPublish = (facts: RepositoryReadFacts) => {
|
|
109
|
+
pending = facts
|
|
110
|
+
if (reading) return
|
|
111
|
+
const reader = store
|
|
112
|
+
if (reader === undefined) return
|
|
113
|
+
reading = true
|
|
114
|
+
void (async () => {
|
|
115
|
+
let position: string | undefined
|
|
116
|
+
try {
|
|
117
|
+
position = await reader.getRepoChangePosition(opts.repo)
|
|
118
|
+
} catch {
|
|
119
|
+
// Presentation only: the frame goes out without its refetch signal.
|
|
120
|
+
}
|
|
121
|
+
reading = false
|
|
122
|
+
const latest = pending!
|
|
123
|
+
pending = undefined
|
|
124
|
+
publish(latest, position)
|
|
125
|
+
})()
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
hub,
|
|
129
|
+
url: started.url,
|
|
130
|
+
publishFacts: (facts, position) => {
|
|
131
|
+
if (position !== undefined || store === undefined || hub.subscribers === 0)
|
|
132
|
+
publish(facts, position)
|
|
133
|
+
else stampAndPublish(facts)
|
|
134
|
+
},
|
|
135
|
+
attachStore: (next) => {
|
|
136
|
+
if (closing !== undefined || next === attached) return
|
|
137
|
+
attached = next
|
|
138
|
+
store = readOnlyStore(next)
|
|
139
|
+
analytics = new WebAnalyticsSource(store, opts.repo)
|
|
140
|
+
},
|
|
141
|
+
close: () => {
|
|
142
|
+
analytics = undefined
|
|
143
|
+
attached = undefined
|
|
144
|
+
store = undefined
|
|
145
|
+
closing ??= (async () => {
|
|
146
|
+
try {
|
|
147
|
+
await started.stop()
|
|
148
|
+
} finally {
|
|
149
|
+
hub.close()
|
|
150
|
+
}
|
|
151
|
+
})()
|
|
152
|
+
return closing
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
}
|