@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,25 +1,27 @@
|
|
|
1
1
|
// Generated release catalog registry. Historical catalogs are immutable evidence.
|
|
2
2
|
import release0 from './1.10.0.json'
|
|
3
|
-
import release1 from './1.
|
|
4
|
-
import release2 from './1.
|
|
5
|
-
import release3 from './1.
|
|
6
|
-
import release4 from './1.
|
|
7
|
-
import release5 from './1.
|
|
8
|
-
import release6 from './1.
|
|
9
|
-
import release7 from './1.
|
|
10
|
-
import release8 from './1.
|
|
3
|
+
import release1 from './1.11.0.json'
|
|
4
|
+
import release2 from './1.2.0.json'
|
|
5
|
+
import release3 from './1.3.0.json'
|
|
6
|
+
import release4 from './1.4.0.json'
|
|
7
|
+
import release5 from './1.5.0.json'
|
|
8
|
+
import release6 from './1.6.0.json'
|
|
9
|
+
import release7 from './1.7.0.json'
|
|
10
|
+
import release8 from './1.8.0.json'
|
|
11
|
+
import release9 from './1.9.0.json'
|
|
11
12
|
import type { ReducerValueCatalog } from '../../reducer-value-validation'
|
|
12
13
|
export interface ReleasedReducerValues extends ReducerValueCatalog {
|
|
13
14
|
versions: Record<string, number>
|
|
14
15
|
}
|
|
15
16
|
export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerValues>> = {
|
|
16
17
|
'1.10.0.json': release0,
|
|
17
|
-
'1.
|
|
18
|
-
'1.
|
|
19
|
-
'1.
|
|
20
|
-
'1.
|
|
21
|
-
'1.
|
|
22
|
-
'1.
|
|
23
|
-
'1.
|
|
24
|
-
'1.
|
|
18
|
+
'1.11.0.json': release1,
|
|
19
|
+
'1.2.0.json': release2,
|
|
20
|
+
'1.3.0.json': release3,
|
|
21
|
+
'1.4.0.json': release4,
|
|
22
|
+
'1.5.0.json': release5,
|
|
23
|
+
'1.6.0.json': release6,
|
|
24
|
+
'1.7.0.json': release7,
|
|
25
|
+
'1.8.0.json': release8,
|
|
26
|
+
'1.9.0.json': release9,
|
|
25
27
|
}
|
|
@@ -78,6 +78,26 @@ export function hookProgressKind(name: string): string {
|
|
|
78
78
|
return `${HOOK_PROGRESS_KIND_PREFIX}${name}`
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Repository agent context (`store/agent-context.ts`): the dispatcher's
|
|
83
|
+
* record of the base branch's installed skills and agent instructions, its
|
|
84
|
+
* small head pointer, and the continuation slots an interrupted capture
|
|
85
|
+
* resumes from. Every kind is read only at its latest revision, so ordinary
|
|
86
|
+
* count-based retention never removes live data. Restated here (no runtime
|
|
87
|
+
* imports) because this module is bundled into the browser.
|
|
88
|
+
*/
|
|
89
|
+
export const AGENT_CONTEXT_ARTIFACT = 'agent-context'
|
|
90
|
+
export const AGENT_CONTEXT_HEAD_ARTIFACT = 'agent-context-head'
|
|
91
|
+
export const AGENT_CONTEXT_CACHE_KIND_PREFIX = 'agent-context-cache.'
|
|
92
|
+
export const AGENT_CONTEXT_RETENTION_REPO_KINDS = [
|
|
93
|
+
AGENT_CONTEXT_ARTIFACT,
|
|
94
|
+
AGENT_CONTEXT_HEAD_ARTIFACT,
|
|
95
|
+
] as const
|
|
96
|
+
|
|
97
|
+
export function agentContextCacheKind(slot: number): string {
|
|
98
|
+
return `${AGENT_CONTEXT_CACHE_KIND_PREFIX}${slot}`
|
|
99
|
+
}
|
|
100
|
+
|
|
81
101
|
/** Default bound: the newest 200 revisions of each retention-managed kind survive. */
|
|
82
102
|
export const DEFAULT_ARTIFACT_RETENTION_MAX_REVISIONS = 200
|
|
83
103
|
|
|
@@ -87,7 +107,9 @@ export function isRetentionManagedKind(kind: string): boolean {
|
|
|
87
107
|
(DISPATCHER_RETENTION_REPO_KINDS as readonly string[]).includes(kind) ||
|
|
88
108
|
(OPERATOR_RETENTION_REPO_KINDS as readonly string[]).includes(kind) ||
|
|
89
109
|
(DISPATCHER_RETENTION_BUILD_KINDS as readonly string[]).includes(kind) ||
|
|
90
|
-
|
|
110
|
+
(AGENT_CONTEXT_RETENTION_REPO_KINDS as readonly string[]).includes(kind) ||
|
|
111
|
+
kind.startsWith(HOOK_PROGRESS_KIND_PREFIX) ||
|
|
112
|
+
kind.startsWith(AGENT_CONTEXT_CACHE_KIND_PREFIX)
|
|
91
113
|
)
|
|
92
114
|
}
|
|
93
115
|
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The derived-reducer engine (RFC 0007 §8.3, SPEC §7.7): answers a
|
|
3
|
+
* `{kind: 'rollup', repo}` scope in every local adapter against a narrow
|
|
4
|
+
* storage port, the way `readReducerValue` answers named values.
|
|
5
|
+
*
|
|
6
|
+
* A rollup row holds the accumulator and the repository change position it
|
|
7
|
+
* reflects. A read whose saved position equals the repository head, and whose
|
|
8
|
+
* accumulator holds nothing retention drops, is two constant reads: no event
|
|
9
|
+
* rows and no feed query. Otherwise, under a per-key serialization that spans
|
|
10
|
+
* every process sharing the store, the engine asks the changed-builds feed for
|
|
11
|
+
* builds changed since the saved position, reads each changed build's saved
|
|
12
|
+
* build-reducer value (a delta read), subtracts the contribution it absorbed
|
|
13
|
+
* from that build last time, adds the new one (contributed with the build's
|
|
14
|
+
* slug), and commits the accumulator,
|
|
15
|
+
* the feed's snapshot head and every changed absorbed contribution together,
|
|
16
|
+
* conditional on the row it read. A first computation (no valid row) starts
|
|
17
|
+
* from the empty accumulator at position 0, so the feed lists every build once.
|
|
18
|
+
*
|
|
19
|
+
* Rows live in the private `value.` namespace of `reducer_snapshots`: the
|
|
20
|
+
* rollup row at `('rollup', repo, value.rollup.v1.<digest>)` and each absorbed
|
|
21
|
+
* contribution at `('build', slug, value.absorbed.v1.<digest>)`. The public
|
|
22
|
+
* snapshot API refuses both names.
|
|
23
|
+
*
|
|
24
|
+
* Browser-safe at import time: the digest is computed inside
|
|
25
|
+
* `resolveRollupValue`, which only adapters call. The remote client uses
|
|
26
|
+
* `rollupEntry`, which needs no hashing.
|
|
27
|
+
*/
|
|
28
|
+
import { READ_CATALOG_IDENTITY } from '../events/compatibility'
|
|
29
|
+
import { ROLLUPS } from '../kernel/reducer-registry'
|
|
30
|
+
import type { AnyRollupDefinition } from '../kernel/rollup'
|
|
31
|
+
import { type ChangedBuilds, compareChangePositions } from './build-feed'
|
|
32
|
+
import {
|
|
33
|
+
canonical,
|
|
34
|
+
type ReducerValue,
|
|
35
|
+
type ReducerValueRequest,
|
|
36
|
+
reducerValueRequestSchema,
|
|
37
|
+
} from './reducer-values'
|
|
38
|
+
import { REDUCER_VALUE_SNAPSHOT_PREFIX, type RollupScope } from './snapshots'
|
|
39
|
+
|
|
40
|
+
/** The registered rollup `name`, or a thrown unknown-rollup error. Pure. */
|
|
41
|
+
export function rollupEntry(name: string): AnyRollupDefinition {
|
|
42
|
+
const def = Object.hasOwn(ROLLUPS, name) ? ROLLUPS[name] : undefined
|
|
43
|
+
if (!def) throw new Error(`unknown rollup "${name}"`)
|
|
44
|
+
return def
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ResolvedRollup {
|
|
48
|
+
name: string
|
|
49
|
+
def: AnyRollupDefinition
|
|
50
|
+
args: unknown
|
|
51
|
+
read: unknown
|
|
52
|
+
version: number
|
|
53
|
+
identity: string
|
|
54
|
+
/** The rollup row's reducer name in the rollup scope. */
|
|
55
|
+
key: string
|
|
56
|
+
/** Each absorbed contribution's reducer name in its build's scope. */
|
|
57
|
+
contributionKey: string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Validate a rollup request and derive its key. Key arguments are parsed with
|
|
61
|
+
* their defaults before hashing, so `{}` and the explicit defaults share one
|
|
62
|
+
* key; read-time arguments never enter it. */
|
|
63
|
+
export function resolveRollupValue(
|
|
64
|
+
repo: string,
|
|
65
|
+
input: ReducerValueRequest,
|
|
66
|
+
catalogIdentity = READ_CATALOG_IDENTITY,
|
|
67
|
+
): ResolvedRollup {
|
|
68
|
+
const request = reducerValueRequestSchema.parse(input)
|
|
69
|
+
const def = rollupEntry(request.reducer)
|
|
70
|
+
const args = def.args.parse(request.args ?? {})
|
|
71
|
+
const read = def.read.parse(request.read ?? {})
|
|
72
|
+
const identity = canonical({
|
|
73
|
+
scope: { kind: 'rollup', repo },
|
|
74
|
+
reducer: request.reducer,
|
|
75
|
+
version: def.version,
|
|
76
|
+
catalogIdentity,
|
|
77
|
+
args,
|
|
78
|
+
})
|
|
79
|
+
const digest = new Bun.CryptoHasher('sha256').update(identity).digest('hex').slice(0, 54)
|
|
80
|
+
return {
|
|
81
|
+
name: request.reducer,
|
|
82
|
+
def,
|
|
83
|
+
args,
|
|
84
|
+
read,
|
|
85
|
+
version: def.version,
|
|
86
|
+
identity,
|
|
87
|
+
key: `${REDUCER_VALUE_SNAPSHOT_PREFIX}rollup.v1.${digest}`,
|
|
88
|
+
contributionKey: `${REDUCER_VALUE_SNAPSHOT_PREFIX}absorbed.v1.${digest}`,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A stored rollup row: its version column, decoded state, and a token naming
|
|
93
|
+
* the exact bytes read, so a commit can be conditional on them. */
|
|
94
|
+
export interface RollupRow {
|
|
95
|
+
version: number
|
|
96
|
+
state: unknown
|
|
97
|
+
token: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The unserialized reads the fast path makes. */
|
|
101
|
+
export interface RollupReads {
|
|
102
|
+
/** The repository's change position. */
|
|
103
|
+
head(): Promise<string>
|
|
104
|
+
read(key: string): Promise<RollupRow | null>
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** What an advance may do while it holds the key's serialization. Every call
|
|
108
|
+
* runs under that serialization (for Postgres, on its one transaction). */
|
|
109
|
+
export interface RollupAdvance extends RollupReads {
|
|
110
|
+
changed(since: string): Promise<ChangedBuilds>
|
|
111
|
+
/** The build's saved build-reducer value, advanced by delta; `null` for a
|
|
112
|
+
* build the store no longer has. */
|
|
113
|
+
buildValue(slug: string, request: ReducerValueRequest): Promise<ReducerValue | null>
|
|
114
|
+
/** Stored absorbed-contribution states for `slugs`, by slug. Absent slugs
|
|
115
|
+
* have none. */
|
|
116
|
+
contributions(key: string, slugs: readonly string[]): Promise<Map<string, unknown>>
|
|
117
|
+
/** Atomically write the rollup row and the absorbed contributions (`null`
|
|
118
|
+
* deletes), only if the stored row is still `observed` (`null`: none) and
|
|
119
|
+
* this advance still holds the serialization. */
|
|
120
|
+
commit(
|
|
121
|
+
key: string,
|
|
122
|
+
observed: string | null,
|
|
123
|
+
row: { version: number; state: unknown },
|
|
124
|
+
contributionKey: string,
|
|
125
|
+
writes: ReadonlyMap<string, unknown | null>,
|
|
126
|
+
): Promise<boolean>
|
|
127
|
+
/** Extend the serialization; throws when it was lost. Called after every
|
|
128
|
+
* batch of build-value reads. */
|
|
129
|
+
renew(): Promise<void>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface RollupStorage extends RollupReads {
|
|
133
|
+
now(): Date
|
|
134
|
+
/** How many build values an advance reads at once. */
|
|
135
|
+
buildReadConcurrency: number
|
|
136
|
+
/** Hold the store-wide per-key serialization from before the re-read until
|
|
137
|
+
* after the commit, across store instances and processes. */
|
|
138
|
+
serialize<T>(key: string, run: (advance: RollupAdvance) => Promise<T>): Promise<T>
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Build-value reads between two `renew()` calls. */
|
|
142
|
+
export const ROLLUP_RENEW_BATCH = 16
|
|
143
|
+
|
|
144
|
+
interface SavedRollup {
|
|
145
|
+
position: string
|
|
146
|
+
acc: unknown
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface RollupState {
|
|
150
|
+
identity: string
|
|
151
|
+
position: string
|
|
152
|
+
acc: unknown
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function decodeRow(resolved: ResolvedRollup, row: RollupRow | null): SavedRollup | null {
|
|
156
|
+
if (row === null || row.version !== resolved.version) return null
|
|
157
|
+
try {
|
|
158
|
+
const state = row.state as Partial<RollupState> | null
|
|
159
|
+
if (state === null || typeof state !== 'object' || state.identity !== resolved.identity)
|
|
160
|
+
return null
|
|
161
|
+
if (typeof state.position !== 'string') return null
|
|
162
|
+
compareChangePositions(state.position, '0')
|
|
163
|
+
const acc = resolved.def.accSchema.safeParse(state.acc)
|
|
164
|
+
return acc.success ? { position: state.position, acc: state.acc } : null
|
|
165
|
+
} catch {
|
|
166
|
+
return null // malformed nested data is a miss, never a crash
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function answer(resolved: ResolvedRollup, acc: unknown, position: string, now: Date): ReducerValue {
|
|
171
|
+
return {
|
|
172
|
+
version: resolved.version,
|
|
173
|
+
cursor: 0,
|
|
174
|
+
value: resolved.def.finish(acc, resolved.read, now, position) as ReducerValue['value'],
|
|
175
|
+
catalogIdentity: READ_CATALOG_IDENTITY,
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** A malformed stored contribution during an incremental advance: recompute. */
|
|
180
|
+
class MalformedContribution extends Error {}
|
|
181
|
+
|
|
182
|
+
/** Answer one rollup read. See the module comment for the algorithm. */
|
|
183
|
+
export async function readRollupValue(
|
|
184
|
+
scope: RollupScope,
|
|
185
|
+
request: ReducerValueRequest,
|
|
186
|
+
storage: RollupStorage,
|
|
187
|
+
): Promise<ReducerValue> {
|
|
188
|
+
const resolved = resolveRollupValue(scope.repo, request)
|
|
189
|
+
const { def, key, contributionKey, identity } = resolved
|
|
190
|
+
const head = await storage.head()
|
|
191
|
+
const row = await storage.read(key)
|
|
192
|
+
const saved = decodeRow(resolved, row)
|
|
193
|
+
const now = storage.now()
|
|
194
|
+
// Fast path: current and nothing expired. Two constant reads.
|
|
195
|
+
if (saved && saved.position === head && !def.expired(saved.acc, now))
|
|
196
|
+
return answer(resolved, saved.acc, saved.position, now)
|
|
197
|
+
// An unknown or empty repository answers the empty value and writes nothing.
|
|
198
|
+
if (head === '0') return answer(resolved, def.initial(), '0', now)
|
|
199
|
+
|
|
200
|
+
return storage.serialize(key, async (advance) => {
|
|
201
|
+
// Another reader may have advanced or pruned the row while we waited.
|
|
202
|
+
const observed = await advance.read(key)
|
|
203
|
+
const current = await advance.head()
|
|
204
|
+
let base = decodeRow(resolved, observed)
|
|
205
|
+
// A saved position above the head means the repository was reset.
|
|
206
|
+
if (base && compareChangePositions(base.position, current) > 0) base = null
|
|
207
|
+
const encode = (acc: unknown, position: string) => ({
|
|
208
|
+
version: resolved.version,
|
|
209
|
+
state: { identity, position, acc } satisfies RollupState,
|
|
210
|
+
})
|
|
211
|
+
const lost = async (): Promise<ReducerValue> => {
|
|
212
|
+
const winner = decodeRow(resolved, await advance.read(key))
|
|
213
|
+
if (!winner) throw new Error(`rollup "${resolved.name}" advance lost to an unreadable row`)
|
|
214
|
+
return answer(resolved, winner.acc, winner.position, storage.now())
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (base && base.position === current) {
|
|
218
|
+
// Current; only retention has work. Saved at the same position with no
|
|
219
|
+
// feed query and no event read.
|
|
220
|
+
const acc = structuredClone(base.acc)
|
|
221
|
+
if (def.prune(acc, now)) {
|
|
222
|
+
const committed = await advance.commit(
|
|
223
|
+
key,
|
|
224
|
+
observed!.token,
|
|
225
|
+
encode(acc, base.position),
|
|
226
|
+
contributionKey,
|
|
227
|
+
new Map(),
|
|
228
|
+
)
|
|
229
|
+
if (!committed) return lost()
|
|
230
|
+
}
|
|
231
|
+
return answer(resolved, acc, base.position, now)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const advanceFrom = async (start: SavedRollup | null) => {
|
|
235
|
+
const first = start === null
|
|
236
|
+
const acc = first ? def.initial() : structuredClone(start.acc)
|
|
237
|
+
def.prune(acc, now)
|
|
238
|
+
const feed = await advance.changed(first ? '0' : start.position)
|
|
239
|
+
const slugs = feed.builds.map((build) => build.slug)
|
|
240
|
+
// A first computation ignores and overwrites any stored contribution
|
|
241
|
+
// for this key, so a stale row can never be subtracted.
|
|
242
|
+
const absorbed = first
|
|
243
|
+
? new Map<string, unknown>()
|
|
244
|
+
: await advance.contributions(contributionKey, slugs)
|
|
245
|
+
const previous = new Map<string, unknown>()
|
|
246
|
+
for (const [slug, stored] of absorbed) {
|
|
247
|
+
const state = stored as { identity?: unknown; contribution?: unknown } | null
|
|
248
|
+
const parsed =
|
|
249
|
+
state !== null && typeof state === 'object' && state.identity === identity
|
|
250
|
+
? def.contributionSchema.safeParse(state.contribution)
|
|
251
|
+
: undefined
|
|
252
|
+
if (!parsed?.success) throw new MalformedContribution(slug)
|
|
253
|
+
previous.set(slug, state!.contribution)
|
|
254
|
+
}
|
|
255
|
+
const writes = new Map<string, unknown | null>()
|
|
256
|
+
const request = { reducer: def.buildReducer }
|
|
257
|
+
const width = Math.max(1, storage.buildReadConcurrency)
|
|
258
|
+
let sinceRenew = 0
|
|
259
|
+
for (let i = 0; i < slugs.length; i += width) {
|
|
260
|
+
const batch = slugs.slice(i, i + width)
|
|
261
|
+
const values = await Promise.all(batch.map((slug) => advance.buildValue(slug, request)))
|
|
262
|
+
for (const [index, slug] of batch.entries()) {
|
|
263
|
+
const value = values[index] ?? null
|
|
264
|
+
const next = value === null ? null : def.contribute(value.value, resolved.args, now, slug)
|
|
265
|
+
const prior = previous.get(slug)
|
|
266
|
+
if (prior !== undefined) def.subtract(acc, prior)
|
|
267
|
+
if (next !== null) {
|
|
268
|
+
def.add(acc, next)
|
|
269
|
+
writes.set(slug, { identity, contribution: next })
|
|
270
|
+
} else if (first || prior !== undefined) writes.set(slug, null)
|
|
271
|
+
}
|
|
272
|
+
sinceRenew += batch.length
|
|
273
|
+
if (sinceRenew >= ROLLUP_RENEW_BATCH) {
|
|
274
|
+
sinceRenew = 0
|
|
275
|
+
await advance.renew()
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return { acc, position: feed.position, writes }
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
let result: Awaited<ReturnType<typeof advanceFrom>>
|
|
282
|
+
try {
|
|
283
|
+
result = await advanceFrom(base)
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (!(error instanceof MalformedContribution) || base === null) throw error
|
|
286
|
+
result = await advanceFrom(null)
|
|
287
|
+
}
|
|
288
|
+
const committed = await advance.commit(
|
|
289
|
+
key,
|
|
290
|
+
observed?.token ?? null,
|
|
291
|
+
encode(result.acc, result.position),
|
|
292
|
+
contributionKey,
|
|
293
|
+
result.writes,
|
|
294
|
+
)
|
|
295
|
+
if (!committed) return lost()
|
|
296
|
+
return answer(resolved, result.acc, result.position, now)
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** A promise chain per key: serializes same-key work inside one store
|
|
301
|
+
* instance. */
|
|
302
|
+
export class KeyedMutex {
|
|
303
|
+
private readonly tails = new Map<string, Promise<unknown>>()
|
|
304
|
+
|
|
305
|
+
async run<T>(key: string, body: () => Promise<T>): Promise<T> {
|
|
306
|
+
const previous = this.tails.get(key) ?? Promise.resolve()
|
|
307
|
+
const next = previous.catch(() => {}).then(body)
|
|
308
|
+
this.tails.set(key, next)
|
|
309
|
+
try {
|
|
310
|
+
return await next
|
|
311
|
+
} finally {
|
|
312
|
+
if (this.tails.get(key) === next) this.tails.delete(key)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** A store-wide rollup lease (the SQLite adapter's per-key serialization). */
|
|
318
|
+
export const ROLLUP_LEASE_MS = 120_000
|
|
319
|
+
/** How long a reader waits on another holder's lease before giving up. */
|
|
320
|
+
export const ROLLUP_LEASE_WAIT_MS = 600_000
|
|
321
|
+
|
|
322
|
+
/** A reader waited `ROLLUP_LEASE_WAIT_MS` on another holder's lease. */
|
|
323
|
+
export class RollupLeaseTimeoutError extends Error {
|
|
324
|
+
override readonly name = 'RollupLeaseTimeoutError'
|
|
325
|
+
constructor(readonly key: string) {
|
|
326
|
+
super(`timed out waiting for the rollup lease on ${key}`)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** An advance's lease expired and another holder took it over; the advance
|
|
331
|
+
* commits nothing. */
|
|
332
|
+
export class RollupLeaseLostError extends Error {
|
|
333
|
+
override readonly name = 'RollupLeaseLostError'
|
|
334
|
+
constructor(readonly key: string) {
|
|
335
|
+
super(`lost the rollup lease on ${key}`)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReducerValueRequest, ReducerValue } from './reducer-values'
|
|
2
|
-
import type { ReducerSnapshot, SnapshotScope } from './snapshots'
|
|
2
|
+
import type { ReducerSnapshot, ReducerValueScope, SnapshotScope } from './snapshots'
|
|
3
3
|
import type { EventType } from '../events/payloads'
|
|
4
4
|
import type { EventWrite } from '../events/catalog'
|
|
5
5
|
import type { RepositoryEventType, RepositoryEventWrite } from '../events/repository'
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
ArtifactInput,
|
|
17
17
|
ArtifactMeta,
|
|
18
18
|
BuildDigest,
|
|
19
|
+
OpenBuild,
|
|
19
20
|
BuildRecord,
|
|
20
21
|
BuildStore,
|
|
21
22
|
NewBuildInput,
|
|
@@ -29,6 +30,7 @@ import type {
|
|
|
29
30
|
SubscribeOptions,
|
|
30
31
|
Unsubscribe,
|
|
31
32
|
} from './types'
|
|
33
|
+
import type { BuildPage, ChangedBuilds } from './types'
|
|
32
34
|
import type {
|
|
33
35
|
TicketAsset,
|
|
34
36
|
TicketAssetInput,
|
|
@@ -121,6 +123,12 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
121
123
|
getRepoChangePosition(repo: string): Promise<string> {
|
|
122
124
|
return Promise.reject(new SessionScopeError(scope, 'getRepoChangePosition', repo))
|
|
123
125
|
},
|
|
126
|
+
listBuildsChangedSince(repo: string): Promise<ChangedBuilds> {
|
|
127
|
+
return Promise.reject(new SessionScopeError(scope, 'listBuildsChangedSince', repo))
|
|
128
|
+
},
|
|
129
|
+
listBuildsPage(repo: string): Promise<BuildPage> {
|
|
130
|
+
return Promise.reject(new SessionScopeError(scope, 'listBuildsPage', repo))
|
|
131
|
+
},
|
|
124
132
|
listBuilds(): Promise<BuildRecord[]> {
|
|
125
133
|
return Promise.reject(new SessionScopeError(scope, 'listBuilds'))
|
|
126
134
|
},
|
|
@@ -210,6 +218,13 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
210
218
|
): Promise<RepositoryEventEnvelope<T>> {
|
|
211
219
|
return Promise.reject(new SessionScopeError(scope, 'appendRepo', repo))
|
|
212
220
|
},
|
|
221
|
+
appendRepoIfCurrent<T extends RepositoryEventType>(
|
|
222
|
+
repo: string,
|
|
223
|
+
_expectedSeq: number,
|
|
224
|
+
_event: RepositoryEventWrite<T>,
|
|
225
|
+
): Promise<RepositoryEventEnvelope<T> | null> {
|
|
226
|
+
return Promise.reject(new SessionScopeError(scope, 'appendRepoIfCurrent', repo))
|
|
227
|
+
},
|
|
213
228
|
appendRepoWithArtifacts<T extends RepositoryEventType>(
|
|
214
229
|
repo: string,
|
|
215
230
|
_artifacts: ArtifactInput[],
|
|
@@ -227,7 +242,7 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
227
242
|
return Promise.reject(new SessionScopeError(scope, 'getRepoHighWater', repo))
|
|
228
243
|
},
|
|
229
244
|
async getReducerValue(
|
|
230
|
-
target:
|
|
245
|
+
target: ReducerValueScope,
|
|
231
246
|
_request: ReducerValueRequest,
|
|
232
247
|
): Promise<ReducerValue> {
|
|
233
248
|
return Promise.reject(
|
|
@@ -267,6 +282,9 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
267
282
|
getRepoBuildDigests(repo: string): Promise<Map<string, BuildDigest>> {
|
|
268
283
|
return Promise.reject(new SessionScopeError(scope, 'getRepoBuildDigests', repo))
|
|
269
284
|
},
|
|
285
|
+
listOpenBuilds(repo: string): Promise<OpenBuild[]> {
|
|
286
|
+
return Promise.reject(new SessionScopeError(scope, 'listOpenBuilds', repo))
|
|
287
|
+
},
|
|
270
288
|
putRepoArtifact(repo: string, _artifact: ArtifactInput): Promise<RepositoryArtifactMeta> {
|
|
271
289
|
return Promise.reject(new SessionScopeError(scope, 'putRepoArtifact', repo))
|
|
272
290
|
},
|
|
@@ -17,6 +17,16 @@ import type { BuildStore } from './types'
|
|
|
17
17
|
|
|
18
18
|
export type SnapshotScope = { kind: 'build'; slug: string } | { kind: 'repo'; repo: string }
|
|
19
19
|
|
|
20
|
+
/** A repository rollup (SPEC §7.7): a derived value over every build of one
|
|
21
|
+
* repository. Only `getReducerValue` answers it; snapshot APIs never do. */
|
|
22
|
+
export type RollupScope = { kind: 'rollup'; repo: string }
|
|
23
|
+
/** Every scope `getReducerValue` answers. */
|
|
24
|
+
export type ReducerValueScope = SnapshotScope | RollupScope
|
|
25
|
+
|
|
26
|
+
export function rollupScopeKey(scope: RollupScope): string {
|
|
27
|
+
return `rollup:${scope.repo}`
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
export interface ReducerSnapshot {
|
|
21
31
|
/** The reducer version that wrote `state`; a reader on another version
|
|
22
32
|
* ignores the snapshot. */
|
|
@@ -2,6 +2,15 @@ import type { ScanCadence } from './scan-cadence'
|
|
|
2
2
|
import type { BoundedEventReads } from './event-reads'
|
|
3
3
|
import type { OperatorIdentity, OperatorPresence } from './operator-presence'
|
|
4
4
|
export type { OperatorIdentity, OperatorPresence } from './operator-presence'
|
|
5
|
+
import type { BuildPage, BuildPageOptions, ChangedBuilds } from './build-feed'
|
|
6
|
+
export type {
|
|
7
|
+
BuildPage,
|
|
8
|
+
BuildPageFilters,
|
|
9
|
+
BuildPageKind,
|
|
10
|
+
BuildPageOptions,
|
|
11
|
+
ChangedBuild,
|
|
12
|
+
ChangedBuilds,
|
|
13
|
+
} from './build-feed'
|
|
5
14
|
import type { ReducerValueRequest, ReducerValue } from './reducer-values'
|
|
6
15
|
/**
|
|
7
16
|
* The BuildStore seam (SPEC §7): the durable home of everything a build
|
|
@@ -31,8 +40,8 @@ import type {
|
|
|
31
40
|
} from '../events/sessions'
|
|
32
41
|
export type { SessionEventEnvelope }
|
|
33
42
|
import type { TicketRef } from '../ontology'
|
|
34
|
-
import type { ReducerSnapshot, SnapshotScope } from './snapshots'
|
|
35
|
-
export type { ReducerSnapshot, SnapshotScope }
|
|
43
|
+
import type { ReducerSnapshot, ReducerValueScope, RollupScope, SnapshotScope } from './snapshots'
|
|
44
|
+
export type { ReducerSnapshot, ReducerValueScope, RollupScope, SnapshotScope }
|
|
36
45
|
import type {
|
|
37
46
|
TicketAsset,
|
|
38
47
|
TicketAssetInput,
|
|
@@ -122,6 +131,13 @@ export interface BuildDigestTicketWait {
|
|
|
122
131
|
tickets: TicketRef[]
|
|
123
132
|
}
|
|
124
133
|
|
|
134
|
+
/** One entry of `BuildStore.listOpenBuilds`: a nonterminal build's record
|
|
135
|
+
* with its persisted digest. */
|
|
136
|
+
export interface OpenBuild {
|
|
137
|
+
record: BuildRecord
|
|
138
|
+
digest: BuildDigest
|
|
139
|
+
}
|
|
140
|
+
|
|
125
141
|
export interface BuildDigest {
|
|
126
142
|
compatibility?: import('../events/compatibility').CompatibilityState
|
|
127
143
|
/** A kernel landing requested an audit and no audit settlement has followed. */
|
|
@@ -170,6 +186,11 @@ export interface BuildDigest {
|
|
|
170
186
|
/** The latest `execution.started` has no later `execution.ended` with the
|
|
171
187
|
* same `instance` (the `openExecution` rule). Absent otherwise. */
|
|
172
188
|
executionOpen?: true
|
|
189
|
+
/** Every `execution.started` and `execution.ended` the build recorded:
|
|
190
|
+
* what an optimization node's activity pass compares with the facts its
|
|
191
|
+
* clock has accounted. Always present from current stores; absent only
|
|
192
|
+
* from an older service's answer. */
|
|
193
|
+
executionFacts?: number
|
|
173
194
|
/** An optimization node has a settled, non-accepted attempt whose ticket
|
|
174
195
|
* has not moved to the rejected role yet: a post-terminal duty that keeps
|
|
175
196
|
* a completed node polled, like `reclaimPending`. Absent otherwise. */
|
|
@@ -342,14 +363,61 @@ export interface BuildStore extends BoundedEventReads {
|
|
|
342
363
|
*/
|
|
343
364
|
listBuildsForRepo(repo: string): Promise<BuildRecord[]>
|
|
344
365
|
|
|
345
|
-
/** Repository-wide
|
|
366
|
+
/** Repository-wide change position, a canonical unsigned decimal string.
|
|
346
367
|
* Advances atomically with repository/build event insertions, build creation,
|
|
347
|
-
* and stored repository lease holder transitions.
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
368
|
+
* and stored repository lease holder transitions. Positions are ordered: a
|
|
369
|
+
* later such write yields a strictly greater value, compared numerically
|
|
370
|
+
* (`compareChangePositions`). Unknown repos return "0" without creating
|
|
371
|
+
* state. Renewals/heartbeats and passive expiry do not move it. Independent
|
|
372
|
+
* of event cursors; consumers periodically refresh mutable facts outside its
|
|
373
|
+
* coverage. */
|
|
351
374
|
getRepoChangePosition(repo: string): Promise<string>
|
|
352
375
|
|
|
376
|
+
/**
|
|
377
|
+
* The changed-builds feed: builds of `repo` whose latest change position is
|
|
378
|
+
* greater than `position`, ascending by position, each once at its latest
|
|
379
|
+
* position. A build's position moves in the same transaction as its creation
|
|
380
|
+
* and every build event. The returned `position` is the repository head,
|
|
381
|
+
* read in the same snapshot, so a caller may save it as its next watermark.
|
|
382
|
+
* Cost is proportional to the answer and reads no event rows. An unknown
|
|
383
|
+
* repository answers `{position: '0', builds: []}` and creates no state; an
|
|
384
|
+
* argument at or above the head answers no builds; a head below the
|
|
385
|
+
* argument means the repository was reset. A non-canonical position rejects
|
|
386
|
+
* with `BuildFeedValidationError`.
|
|
387
|
+
*/
|
|
388
|
+
listBuildsChangedSince(repo: string, position: string): Promise<ChangedBuilds>
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* One page of `repo`'s builds, newest first by creation with slug
|
|
392
|
+
* descending to break ties. Records match `listBuildsForRepo` records,
|
|
393
|
+
* including the ticket projection. `next` is null on the last page. Cursors
|
|
394
|
+
* are opaque, valid only for the adapter that issued them, and continue
|
|
395
|
+
* only a request with the same filters.
|
|
396
|
+
*
|
|
397
|
+
* Optional filters narrow the page: `kind` (`leaf` or `node`, from the
|
|
398
|
+
* build's `build.created` kind), `outcome: 'merged'` (the latest
|
|
399
|
+
* `build.completed` was merged and no `build.reopened` followed) and
|
|
400
|
+
* `activeSince` (an ISO instant; `updatedAt` at or after it). They are
|
|
401
|
+
* answered from per-build facts written in the same transaction as the
|
|
402
|
+
* event or write that changes them, never from events or reduced values.
|
|
403
|
+
* Without `activeSince` a filtered page is the filtered subsequence of the
|
|
404
|
+
* creation order. With it, the page is ordered by `updatedAt` descending,
|
|
405
|
+
* then slug descending, and its cursor carries `(updatedAt, slug)`. Because
|
|
406
|
+
* `updatedAt` moves, a build written between two page requests may appear
|
|
407
|
+
* twice in one traversal or be skipped once; consumers dedupe by slug.
|
|
408
|
+
* Every write bumps `updatedAt` and a build's span never ends later than its
|
|
409
|
+
* latest event, so `activeSince` matches a superset of the builds whose span
|
|
410
|
+
* overlaps the window.
|
|
411
|
+
*
|
|
412
|
+
* Every filter combination is one bounded range scan: a page reads at most
|
|
413
|
+
* `limit + 1` entries, whatever the repository's build count or the number
|
|
414
|
+
* of matches. An unknown repository answers `{builds: [], next: null}` and
|
|
415
|
+
* creates no state. A malformed cursor, a cursor of the other order, an
|
|
416
|
+
* invalid filter or a limit outside 1..100 rejects with
|
|
417
|
+
* `BuildFeedValidationError`.
|
|
418
|
+
*/
|
|
419
|
+
listBuildsPage(repo: string, opts?: BuildPageOptions): Promise<BuildPage>
|
|
420
|
+
|
|
353
421
|
/**
|
|
354
422
|
* Append one validated event; the store assigns `seq` (per-build,
|
|
355
423
|
* monotonic, starting at 1) and `ts` (§15.1). Writes must pass
|
|
@@ -448,6 +516,16 @@ export interface BuildStore extends BoundedEventReads {
|
|
|
448
516
|
|
|
449
517
|
getRepoBuildDigests(repo: string): Promise<Map<string, BuildDigest>>
|
|
450
518
|
|
|
519
|
+
/** The records and persisted digests of the repository's open builds —
|
|
520
|
+
* those whose latest terminal fact is not `build.completed`, so queued,
|
|
521
|
+
* running, paused, blocked and settled-awaiting-merge builds plus aborted
|
|
522
|
+
* builds still in cleanup — ordered by createdAt then slug. Membership is
|
|
523
|
+
* maintained with each build insert and with each `build.completed`,
|
|
524
|
+
* `build.aborted` and `build.reopened` append, in the appending
|
|
525
|
+
* transaction, so the cost is proportional to open builds and never to
|
|
526
|
+
* settled history. Read-only; an unknown repo answers an empty list. */
|
|
527
|
+
listOpenBuilds(repo: string): Promise<OpenBuild[]>
|
|
528
|
+
|
|
451
529
|
putArtifact(slug: string, artifact: ArtifactInput): Promise<ArtifactMeta>
|
|
452
530
|
/** Latest revision when `rev` is omitted; null if kind (or rev) absent. */
|
|
453
531
|
getArtifact(slug: string, kind: string, rev?: number): Promise<Artifact | null>
|
|
@@ -498,6 +576,19 @@ export interface BuildStore extends BoundedEventReads {
|
|
|
498
576
|
repo: string,
|
|
499
577
|
event: RepositoryEventWrite<T>,
|
|
500
578
|
): Promise<RepositoryEventEnvelope<T>>
|
|
579
|
+
/** Atomically append one validated repository event only when the
|
|
580
|
+
* repository journal's current sequence equals `expectedSeq` (0 for an
|
|
581
|
+
* empty journal). Returns null when the journal has advanced; a miss must
|
|
582
|
+
* not mutate the journal or the stream timestamp. Invalid events and
|
|
583
|
+
* unknown repositories reject as `appendRepo` does. The repository mirror
|
|
584
|
+
* of the build log's `appendIfCurrent`: the operator sandbox service
|
|
585
|
+
* records a background attempt's outcome through it exactly once across
|
|
586
|
+
* processes. */
|
|
587
|
+
appendRepoIfCurrent<T extends RepositoryEventType>(
|
|
588
|
+
repo: string,
|
|
589
|
+
expectedSeq: number,
|
|
590
|
+
event: RepositoryEventWrite<T>,
|
|
591
|
+
): Promise<RepositoryEventEnvelope<T> | null>
|
|
501
592
|
appendRepoWithArtifacts<T extends RepositoryEventType>(
|
|
502
593
|
repo: string,
|
|
503
594
|
artifacts: ArtifactInput[],
|
|
@@ -532,8 +623,16 @@ export interface BuildStore extends BoundedEventReads {
|
|
|
532
623
|
* never an `ensureRepo` side effect. */
|
|
533
624
|
getRepoHighWater(repo: string): Promise<number>
|
|
534
625
|
/** A named JSON answer reduced from the authoritative log. Checkpoints are
|
|
535
|
-
* maintained privately by the adapter and cannot be supplied by callers.
|
|
536
|
-
|
|
626
|
+
* maintained privately by the adapter and cannot be supplied by callers.
|
|
627
|
+
*
|
|
628
|
+
* A `{kind: 'rollup', repo}` scope names a derived reducer (SPEC §7.7,
|
|
629
|
+
* `ROLLUPS` in `kernel/reducer-registry.ts`): the adapter advances it by
|
|
630
|
+
* the builds changed since its saved change position, serialized per key
|
|
631
|
+
* and committed atomically, and answers `cursor: 0` with the reflected
|
|
632
|
+
* position inside the value. `request.read` carries its read-time
|
|
633
|
+
* arguments; named reducers reject them. An unknown repository answers the
|
|
634
|
+
* empty value and creates nothing. */
|
|
635
|
+
getReducerValue(scope: ReducerValueScope, request: ReducerValueRequest): Promise<ReducerValue>
|
|
537
636
|
/** The stored reducer snapshot for a scope (a build log or a repository
|
|
538
637
|
* journal), a cache beside the log and never an authority. `null` when
|
|
539
638
|
* absent, when the stored version differs from `version`, when the stored
|