@defrex/autobuild 1.11.1 → 1.13.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 +601 -203
- package/bin/ab-build-runner.ts +8 -0
- package/docs/answering-blocked-builds.md +32 -2
- package/docs/architecture.md +188 -57
- package/docs/assets/headline-wide.png +0 -0
- package/docs/cli.md +1 -1
- package/docs/configuration.md +120 -23
- package/docs/dispatcher.md +19 -8
- package/docs/integration-overview.md +1 -1
- package/docs/integration-tree.md +33 -18
- package/docs/merge-policy.md +7 -2
- package/docs/operating.md +5 -3
- package/docs/operator-api.md +48 -25
- package/docs/operator-surfaces.md +39 -3
- package/docs/optimization-nodes.md +10 -8
- package/docs/plugin-authoring.md +46 -18
- package/docs/remote-store-protocol.md +51 -12
- package/docs/remote-ticket-protocol.md +85 -38
- package/docs/restacking.md +48 -3
- package/docs/setup.md +2 -1
- package/docs/ticket-migration.md +2 -2
- package/docs/ticket-sources.md +23 -8
- package/docs/tickets.md +4 -4
- package/docs/troubleshooting.md +17 -2
- package/docs/verification.md +3 -1
- package/package.json +3 -3
- package/packages/core/src/cli/ambient-errors.ts +17 -0
- package/packages/core/src/cli/bounded-io.ts +174 -0
- package/packages/core/src/cli/build-control.ts +72 -6
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
- package/packages/core/src/cli/dashboard/model.ts +93 -29
- package/packages/core/src/cli/dashboard/poll.ts +231 -34
- package/packages/core/src/cli/dashboard/queue.ts +21 -10
- package/packages/core/src/cli/dashboard/render.ts +14 -37
- package/packages/core/src/cli/dashboard/row-text.ts +26 -8
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +165 -20
- package/packages/core/src/cli/dispatch-frontend.ts +2 -1
- package/packages/core/src/cli/dispatch-handoff.ts +41 -10
- package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
- package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
- package/packages/core/src/cli/dispatch-launcher.ts +9 -10
- package/packages/core/src/cli/dispatch-preflight.ts +12 -3
- package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
- package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
- package/packages/core/src/cli/dispatch-tickets.ts +33 -12
- package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
- package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
- package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
- package/packages/core/src/cli/dispatch.ts +595 -149
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +43 -28
- package/packages/core/src/cli/main.ts +11 -7
- package/packages/core/src/cli/production-store.ts +102 -0
- package/packages/core/src/cli/publication-settlement.ts +4 -0
- package/packages/core/src/cli/remote-poll.ts +22 -5
- package/packages/core/src/cli/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +44 -28
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +188 -47
- package/packages/core/src/cli/store-opening.ts +26 -57
- package/packages/core/src/cli/store-ref.ts +6 -1
- package/packages/core/src/cli/ticket-start.ts +3 -3
- package/packages/core/src/cli/ticket.ts +12 -11
- package/packages/core/src/cli/wait.ts +8 -28
- package/packages/core/src/cli/watch.ts +113 -50
- package/packages/core/src/config/reference-metadata.ts +7 -1
- package/packages/core/src/config/reference.ts +5 -2
- package/packages/core/src/config/schema.ts +51 -16
- package/packages/core/src/distribution-packaging.ts +156 -18
- package/packages/core/src/events/catalog-identity.ts +28 -0
- package/packages/core/src/events/catalog.ts +3 -9
- package/packages/core/src/events/compatibility.ts +2 -30
- package/packages/core/src/events/payloads.ts +85 -14
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +15 -4
- package/packages/core/src/events/sessions.ts +1 -1
- package/packages/core/src/events/validation-error.ts +12 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
- package/packages/core/src/kernel/auto-merge-default.ts +2 -1
- package/packages/core/src/kernel/capacity-build.ts +21 -0
- package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
- package/packages/core/src/kernel/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +578 -235
- package/packages/core/src/kernel/done-escalations.ts +269 -0
- package/packages/core/src/kernel/engine.ts +30 -17
- package/packages/core/src/kernel/integration-landing.ts +24 -4
- package/packages/core/src/kernel/integration-stack.ts +39 -0
- package/packages/core/src/kernel/janitor-failure.ts +20 -1
- package/packages/core/src/kernel/log-index-value.ts +3 -0
- package/packages/core/src/kernel/log-index.ts +41 -2
- package/packages/core/src/kernel/measurement.ts +24 -0
- package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
- package/packages/core/src/kernel/read-facts.ts +8 -370
- package/packages/core/src/kernel/reducer-registry.ts +43 -125
- package/packages/core/src/kernel/reducer-revisions.ts +18 -0
- package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
- package/packages/core/src/kernel/reducer-value-index.ts +75 -0
- package/packages/core/src/kernel/reducer.ts +84 -16
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-attention.ts +14 -5
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/ticket-starts.ts +15 -4
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- package/packages/core/src/kernel/verify-stages.ts +46 -7
- package/packages/core/src/operator/attention.ts +28 -3
- package/packages/core/src/operator/done-escalations.ts +38 -0
- package/packages/core/src/operator/presentation.ts +14 -1
- package/packages/core/src/operator/protocol.ts +8 -5
- package/packages/core/src/operator/query.ts +72 -57
- package/packages/core/src/operator/registry.ts +19 -15
- package/packages/core/src/operator/ticket-start.ts +8 -7
- package/packages/core/src/operator/tickets.ts +28 -9
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/manifest.ts +14 -1
- package/packages/core/src/ports/forge/create.ts +8 -0
- package/packages/core/src/ports/forge/github-transport.ts +5 -1
- package/packages/core/src/ports/forge/github.ts +3 -0
- package/packages/core/src/ports/tickets/contract.ts +147 -76
- package/packages/core/src/ports/tickets/create.ts +47 -7
- package/packages/core/src/ports/tickets/fake.ts +8 -4
- package/packages/core/src/ports/tickets/file-codec.ts +4 -3
- package/packages/core/src/ports/tickets/file.ts +7 -3
- package/packages/core/src/ports/tickets/github.ts +1 -0
- package/packages/core/src/ports/tickets/grants.ts +11 -3
- package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
- package/packages/core/src/ports/tickets/linear.ts +28 -9
- package/packages/core/src/ports/tickets/migration.ts +4 -4
- package/packages/core/src/ports/tickets/operations.ts +4 -2
- package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
- package/packages/core/src/ports/tickets/priority.ts +127 -21
- package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
- package/packages/core/src/ports/tickets/remote.ts +104 -11
- package/packages/core/src/ports/tickets/revision.ts +5 -3
- package/packages/core/src/ports/tickets/search.ts +9 -0
- package/packages/core/src/ports/tickets/tree.ts +8 -6
- package/packages/core/src/ports/types.ts +30 -15
- package/packages/core/src/ports/workspace/build-execution.ts +4 -0
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
- package/packages/core/src/ports/workspace/create.ts +16 -3
- package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
- package/packages/core/src/ports/workspace/fake.ts +15 -3
- package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
- package/packages/core/src/processes/build-execution-state.ts +4 -0
- package/packages/core/src/processes/build-runner.ts +14 -1
- package/packages/core/src/processes/dispatcher.ts +777 -288
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- package/packages/core/src/processes/execution-settlement.ts +1 -0
- package/packages/core/src/processes/harvest-runner.ts +12 -7
- package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
- package/packages/core/src/processes/invocation-budget.ts +176 -0
- package/packages/core/src/processes/publication-loss.ts +38 -3
- package/packages/core/src/processes/workspace-preservation.ts +86 -15
- package/packages/core/src/store/contract.ts +81 -3
- package/packages/core/src/store/event-reads.ts +30 -1
- package/packages/core/src/store/local/capabilities.ts +115 -0
- package/packages/core/src/store/local/store.ts +86 -56
- package/packages/core/src/store/reduced-reads.ts +32 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +6722 -6475
- package/packages/core/src/store/reducer-value-validation.ts +181 -33
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/client.ts +169 -29
- package/packages/core/src/store/remote/compatibility.ts +113 -56
- package/packages/core/src/store/remote/credentials.ts +4 -1
- package/packages/core/src/store/remote/protocol.ts +3 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
- package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/remote/released-value-policy.ts +144 -0
- package/packages/core/src/store/remote/retry.ts +406 -0
- package/packages/core/src/store/rollup-lease.ts +41 -0
- package/packages/core/src/store/rollups.ts +7 -38
- package/packages/core/src/store/snapshots.ts +1 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +409 -14
- package/packages/core/src/testing/import-graph.ts +78 -0
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/invocation-budget.ts +42 -0
- package/packages/core/src/testing/reduced-read-budget.ts +602 -40
- package/packages/core/src/testing/released-value-coverage.ts +423 -0
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/packages/core/src/web/overview-source.ts +19 -6
- package/skills/guide/SKILL.md +245 -103
- package/skills/guide/references/integration-tree.md +33 -18
- package/skills/guide/references/merge-policy.md +7 -2
- package/skills/guide/references/operator-api.md +48 -25
- package/skills/guide/references/optimization-nodes.md +10 -8
- package/skills/guide/references/plugin-authoring.md +46 -18
- package/skills/guide/references/remote-store-protocol.md +51 -12
- package/skills/guide/references/remote-ticket-protocol.md +85 -38
- package/skills/guide/references/restacking.md +48 -3
- package/skills/guide/references/setup.md +2 -1
- package/skills/guide/references/ticket-migration.md +2 -2
- package/skills/operate/SKILL.md +114 -65
- package/skills/plan/SKILL.md +4 -3
- package/skills/spec/SKILL.md +9 -5
- package/skills/tickets/SKILL.md +25 -17
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store capabilities a short-lived reader may never use, initialized on first
|
|
3
|
+
* need. A process that only reads its repository record and change position
|
|
4
|
+
* never evaluates the event catalogs, the write validators or the reducers.
|
|
5
|
+
*
|
|
6
|
+
* Rule for every use: take `capability.value ?? (await capability.load())` as
|
|
7
|
+
* the method's first statement, before any transaction, read or mutation, and
|
|
8
|
+
* use the resolved functions synchronously where they were used before. Every
|
|
9
|
+
* write is therefore still validated before it mutates anything, and once a
|
|
10
|
+
* capability is loaded a method runs with no added await at all. A failed load
|
|
11
|
+
* is not remembered: the next use retries it, and the error reaches the caller.
|
|
12
|
+
*/
|
|
13
|
+
export class Capability<T> {
|
|
14
|
+
value: T | undefined
|
|
15
|
+
private pending: Promise<T> | undefined
|
|
16
|
+
|
|
17
|
+
constructor(private readonly initialize: () => Promise<T>) {}
|
|
18
|
+
|
|
19
|
+
load(): Promise<T> {
|
|
20
|
+
this.pending ??= this.initialize().then(
|
|
21
|
+
(value) => {
|
|
22
|
+
this.value = value
|
|
23
|
+
return value
|
|
24
|
+
},
|
|
25
|
+
(error: unknown) => {
|
|
26
|
+
this.pending = undefined
|
|
27
|
+
throw error
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
return this.pending
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Build, repository and session event validation, plus the build-creation and
|
|
35
|
+
* tick-finish checks. */
|
|
36
|
+
export const writeValidation = new Capability(async () => {
|
|
37
|
+
const [catalog, repository, sessions, newBuild, repoTick] = await Promise.all([
|
|
38
|
+
import('../../events/catalog'),
|
|
39
|
+
import('../../events/repository'),
|
|
40
|
+
import('../../events/sessions'),
|
|
41
|
+
import('../new-build'),
|
|
42
|
+
import('../repo-tick'),
|
|
43
|
+
])
|
|
44
|
+
return {
|
|
45
|
+
validateEventWrite: catalog.prepareEventWrite,
|
|
46
|
+
validateRepositoryEventWrite: repository.prepareRepositoryEventWrite,
|
|
47
|
+
validateSessionEventWrite: sessions.validateSessionEventWrite,
|
|
48
|
+
validateCreatedEvent: newBuild.validateCreatedEvent,
|
|
49
|
+
validateTickFinish: repoTick.validateTickFinish,
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
/** Strict build-event payload schemas. */
|
|
54
|
+
export const payloadSchemas = new Capability(async () => {
|
|
55
|
+
const { eventPayloadSchemas } = await import('../../events/payloads')
|
|
56
|
+
return { eventPayloadSchemas }
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
/** Named reducer values over the selective index: only the requested reducer's
|
|
60
|
+
* module initializes. Never the complete catalog unless a request names a
|
|
61
|
+
* reducer outside the index. */
|
|
62
|
+
export const reducedValues = new Capability(async () => {
|
|
63
|
+
const [read, index] = await Promise.all([
|
|
64
|
+
import('../reducer-value-read'),
|
|
65
|
+
import('../../kernel/reducer-value-index'),
|
|
66
|
+
])
|
|
67
|
+
return {
|
|
68
|
+
parseValueRequest: read.parseValueRequest,
|
|
69
|
+
resolveRegisteredValue: read.resolveRegisteredValue,
|
|
70
|
+
readResolvedReducerValue: read.readResolvedReducerValue,
|
|
71
|
+
loadValueRegistration: index.loadValueRegistration,
|
|
72
|
+
loadedValueRegistration: index.loadedValueRegistration,
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
/** Saved build digests for open-build and repository digest listings. */
|
|
77
|
+
export const buildDigests = new Capability(async () => {
|
|
78
|
+
const { readPersistedBuildDigests } = await import('../reduced-reads')
|
|
79
|
+
return { readPersistedBuildDigests }
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
/** Repository rollups (the derived-reducer engine). */
|
|
83
|
+
export const rollups = new Capability(async () => {
|
|
84
|
+
const { readRollupValue } = await import('../rollups')
|
|
85
|
+
return { readRollupValue }
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
/** The repository state-event selection. */
|
|
89
|
+
export const repositoryStateEvents = new Capability(async () => {
|
|
90
|
+
const module = await import('../repo-state-events')
|
|
91
|
+
return {
|
|
92
|
+
REPOSITORY_STATE_EVENT_TYPES: module.REPOSITORY_STATE_EVENT_TYPES,
|
|
93
|
+
REPOSITORY_LATEST_EVENT_TYPES: module.REPOSITORY_LATEST_EVENT_TYPES,
|
|
94
|
+
readRepoStateEventsWithAnchorRecheck: module.readRepoStateEventsWithAnchorRecheck,
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
/** Ticket asset storage and pinning. */
|
|
99
|
+
export const ticketAssetCapability = new Capability(async () => {
|
|
100
|
+
const module = await import('../ticket-assets')
|
|
101
|
+
return {
|
|
102
|
+
DEFAULT_TICKET_ASSET_LIMITS: module.DEFAULT_TICKET_ASSET_LIMITS,
|
|
103
|
+
loadTicketAsset: module.loadTicketAsset,
|
|
104
|
+
storeTicketAssetBlobs: module.storeTicketAssetBlobs,
|
|
105
|
+
resolvePinnedAsset: module.resolvePinnedAsset,
|
|
106
|
+
summarizeTicketAsset: module.summarizeTicketAsset,
|
|
107
|
+
validateTicketAssetInput: module.validateTicketAssetInput,
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
/** UI message stream assembly at close. */
|
|
112
|
+
export const streamAssembly = new Capability(async () => {
|
|
113
|
+
const { assembleUIMessageDocument } = await import('../streams/assemble')
|
|
114
|
+
return { assembleUIMessageDocument }
|
|
115
|
+
})
|
|
@@ -6,16 +6,9 @@ import {
|
|
|
6
6
|
type OperatorIdentity,
|
|
7
7
|
type OperatorPresence,
|
|
8
8
|
} from '../operator-presence'
|
|
9
|
-
import { READ_CATALOG_IDENTITY } from '../../events/
|
|
10
|
-
import { readPersistedBuildDigests } from '../reduced-reads'
|
|
9
|
+
import { READ_CATALOG_IDENTITY } from '../../events/catalog-identity'
|
|
11
10
|
import { assertPublicSnapshotReducer } from '../snapshots'
|
|
12
|
-
import {
|
|
13
|
-
readReducerValue,
|
|
14
|
-
resolveReducerValue,
|
|
15
|
-
type ReducerValueRequest,
|
|
16
|
-
type ReducerValue,
|
|
17
|
-
} from '../reducer-values'
|
|
18
|
-
import { validateTickFinish } from '../repo-tick'
|
|
11
|
+
import type { ReducerValueRequest, ReducerValue } from '../reducer-value-read'
|
|
19
12
|
import {
|
|
20
13
|
buildPageOrder,
|
|
21
14
|
decodeBuildPageCursor,
|
|
@@ -37,7 +30,8 @@ import type { RepoTickCompletion, RepoTickFinish, RepoTickObservation } from '..
|
|
|
37
30
|
* explicitly resolved local state root. Repository/default selection belongs
|
|
38
31
|
* to the CLI; this adapter only opens the path it is given.
|
|
39
32
|
*
|
|
40
|
-
* Every write goes through `validateEventWrite` (§8 — the enforced ontology)
|
|
33
|
+
* Every write goes through `validateEventWrite` (§8 — the enforced ontology),
|
|
34
|
+
* loaded on first use (`./capabilities`) before the write's transaction.
|
|
41
35
|
* Seq assignment and `appendWithArtifacts` are transactional: bun:sqlite
|
|
42
36
|
* transactions are synchronous, so the atomic path (D6) runs inside one
|
|
43
37
|
* `db.transaction` while blob writes happen *before* it — a rolled-back
|
|
@@ -52,26 +46,19 @@ import { access, copyFile, mkdtemp, rm } from 'node:fs/promises'
|
|
|
52
46
|
import { tmpdir } from 'node:os'
|
|
53
47
|
import { join } from 'node:path'
|
|
54
48
|
import { humanActor } from '../../events/envelope'
|
|
55
|
-
import {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
import {
|
|
63
|
-
prepareRepositoryEventWrite as validateRepositoryEventWrite,
|
|
64
|
-
type RepositoryEvent,
|
|
65
|
-
type RepositoryEventEnvelope,
|
|
66
|
-
type RepositoryEventType,
|
|
67
|
-
type RepositoryEventWrite,
|
|
49
|
+
import type { AbEvent, EventEnvelope, EventWrite } from '../../events/catalog'
|
|
50
|
+
import type { EventType } from '../../events/payloads'
|
|
51
|
+
import type {
|
|
52
|
+
RepositoryEvent,
|
|
53
|
+
RepositoryEventEnvelope,
|
|
54
|
+
RepositoryEventType,
|
|
55
|
+
RepositoryEventWrite,
|
|
68
56
|
} from '../../events/repository'
|
|
69
|
-
import {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
type SessionEventWrite,
|
|
57
|
+
import type {
|
|
58
|
+
SessionEvent,
|
|
59
|
+
SessionEventEnvelope,
|
|
60
|
+
SessionEventType,
|
|
61
|
+
SessionEventWrite,
|
|
75
62
|
} from '../../events/sessions'
|
|
76
63
|
import { createBuildScopedStore } from '../build-scope'
|
|
77
64
|
import type { ReducerSnapshot, ReducerValueScope, RollupScope, SnapshotScope } from '../snapshots'
|
|
@@ -81,17 +68,9 @@ import {
|
|
|
81
68
|
ROLLUP_LEASE_WAIT_MS,
|
|
82
69
|
RollupLeaseLostError,
|
|
83
70
|
RollupLeaseTimeoutError,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type RollupStorage,
|
|
87
|
-
} from '../rollups'
|
|
88
|
-
import { validateCreatedEvent } from '../new-build'
|
|
71
|
+
} from '../rollup-lease'
|
|
72
|
+
import type { RollupAdvance, RollupStorage } from '../rollups'
|
|
89
73
|
import { createSessionScopedStore } from '../session-handle'
|
|
90
|
-
import {
|
|
91
|
-
REPOSITORY_STATE_EVENT_TYPES,
|
|
92
|
-
REPOSITORY_LATEST_EVENT_TYPES,
|
|
93
|
-
readRepoStateEventsWithAnchorRecheck,
|
|
94
|
-
} from '../repo-state-events'
|
|
95
74
|
import {
|
|
96
75
|
DEFAULT_ARTIFACT_RETENTION_MAX_REVISIONS,
|
|
97
76
|
isRetentionManagedKind,
|
|
@@ -99,7 +78,6 @@ import {
|
|
|
99
78
|
} from '../retention'
|
|
100
79
|
import { pollingSubscribe } from '../subscribe'
|
|
101
80
|
import { StreamLocks } from '../streams/lock'
|
|
102
|
-
import { assembleUIMessageDocument } from '../streams/assemble'
|
|
103
81
|
import { EVENT_WAIT_POLL_MS, readEventsWithWait, readStreamWithWait } from '../streams/wait'
|
|
104
82
|
import {
|
|
105
83
|
serializedBatchSize,
|
|
@@ -150,19 +128,23 @@ import {
|
|
|
150
128
|
HEAD as ASSET_HEAD,
|
|
151
129
|
NEXT_NAME_SAME_KIND as ASSET_NEXT_NAME_SAME_KIND,
|
|
152
130
|
} from './ticket-asset-heads'
|
|
153
|
-
import {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
validateTicketAssetInput,
|
|
160
|
-
type TicketAsset,
|
|
161
|
-
type TicketAssetInput,
|
|
162
|
-
type TicketAssetLimits,
|
|
163
|
-
type TicketAssetMeta,
|
|
164
|
-
type TicketAssetSummary,
|
|
131
|
+
import type {
|
|
132
|
+
TicketAsset,
|
|
133
|
+
TicketAssetInput,
|
|
134
|
+
TicketAssetLimits,
|
|
135
|
+
TicketAssetMeta,
|
|
136
|
+
TicketAssetSummary,
|
|
165
137
|
} from '../ticket-assets'
|
|
138
|
+
import {
|
|
139
|
+
buildDigests,
|
|
140
|
+
payloadSchemas,
|
|
141
|
+
reducedValues,
|
|
142
|
+
repositoryStateEvents,
|
|
143
|
+
rollups,
|
|
144
|
+
streamAssembly,
|
|
145
|
+
ticketAssetCapability,
|
|
146
|
+
writeValidation,
|
|
147
|
+
} from './capabilities'
|
|
166
148
|
import { DirBlobStore } from './blobs'
|
|
167
149
|
import {
|
|
168
150
|
artifacts,
|
|
@@ -966,6 +948,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
966
948
|
}
|
|
967
949
|
|
|
968
950
|
async createBuild(input: NewBuildInput): Promise<BuildRecord> {
|
|
951
|
+
const { validateCreatedEvent } = writeValidation.value ?? (await writeValidation.load())
|
|
969
952
|
const created = validateCreatedEvent(input)
|
|
970
953
|
const ts = this.now()
|
|
971
954
|
return this.writeTx(() => {
|
|
@@ -1074,6 +1057,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1074
1057
|
}
|
|
1075
1058
|
|
|
1076
1059
|
async getNodeRewrite(slug: string, previous?: string, beforePrevious?: string) {
|
|
1060
|
+
const { eventPayloadSchemas } = payloadSchemas.value ?? (await payloadSchemas.load())
|
|
1077
1061
|
this.requireBuild(slug)
|
|
1078
1062
|
const row = (
|
|
1079
1063
|
beforePrevious !== undefined
|
|
@@ -1100,6 +1084,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1100
1084
|
}
|
|
1101
1085
|
|
|
1102
1086
|
async listOpenBuilds(repo: string): Promise<OpenBuild[]> {
|
|
1087
|
+
const { readPersistedBuildDigests } = buildDigests.value ?? (await buildDigests.load())
|
|
1103
1088
|
const records = this.db
|
|
1104
1089
|
.select({ build: builds })
|
|
1105
1090
|
.from(openBuilds)
|
|
@@ -1113,6 +1098,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1113
1098
|
}
|
|
1114
1099
|
|
|
1115
1100
|
async getRepoBuildDigests(repo: string): Promise<Map<string, BuildDigest>> {
|
|
1101
|
+
const { readPersistedBuildDigests } = buildDigests.value ?? (await buildDigests.load())
|
|
1116
1102
|
return readPersistedBuildDigests(
|
|
1117
1103
|
this,
|
|
1118
1104
|
repo,
|
|
@@ -1169,6 +1155,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1169
1155
|
}
|
|
1170
1156
|
|
|
1171
1157
|
async append<T extends EventType>(slug: string, event: EventWrite<T>): Promise<EventEnvelope<T>> {
|
|
1158
|
+
const { validateEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1172
1159
|
const validated = validateEventWrite(event)
|
|
1173
1160
|
return this.writeTx(() => this.appendInTx(slug, validated)) as EventEnvelope<T>
|
|
1174
1161
|
}
|
|
@@ -1178,6 +1165,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1178
1165
|
expectedSeq: number,
|
|
1179
1166
|
event: EventWrite<T>,
|
|
1180
1167
|
): Promise<EventEnvelope<T> | null> {
|
|
1168
|
+
const { validateEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1181
1169
|
validateExpectedSeq(expectedSeq)
|
|
1182
1170
|
const validated = validateEventWrite(event)
|
|
1183
1171
|
return this.writeTx(() => {
|
|
@@ -1306,6 +1294,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1306
1294
|
artifactInputs: ArtifactInput[],
|
|
1307
1295
|
makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
1308
1296
|
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] }> {
|
|
1297
|
+
const { validateEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1309
1298
|
const prepared: PreparedArtifact[] = []
|
|
1310
1299
|
for (const input of artifactInputs) {
|
|
1311
1300
|
prepared.push(await this.prepareArtifact(input))
|
|
@@ -1339,6 +1328,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1339
1328
|
artifactInputs: ArtifactInput[],
|
|
1340
1329
|
makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
1341
1330
|
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] } | null> {
|
|
1331
|
+
const { validateEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1342
1332
|
validateExpectedSeq(expectedSeq)
|
|
1343
1333
|
const prepared: PreparedArtifact[] = []
|
|
1344
1334
|
for (const input of artifactInputs) {
|
|
@@ -1707,6 +1697,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1707
1697
|
repo: string,
|
|
1708
1698
|
event: RepositoryEventWrite<T>,
|
|
1709
1699
|
): Promise<RepositoryEventEnvelope<T>> {
|
|
1700
|
+
const { validateRepositoryEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1710
1701
|
const validated = validateRepositoryEventWrite(event)
|
|
1711
1702
|
return this.writeTx(() => this.appendRepoInTx(repo, validated)) as RepositoryEventEnvelope<T>
|
|
1712
1703
|
}
|
|
@@ -1716,6 +1707,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1716
1707
|
expectedSeq: number,
|
|
1717
1708
|
event: RepositoryEventWrite<T>,
|
|
1718
1709
|
): Promise<RepositoryEventEnvelope<T> | null> {
|
|
1710
|
+
const { validateRepositoryEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1719
1711
|
validateExpectedSeq(expectedSeq)
|
|
1720
1712
|
const validated = validateRepositoryEventWrite(event)
|
|
1721
1713
|
return this.writeTx(() => {
|
|
@@ -1781,6 +1773,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1781
1773
|
event: RepositoryEventEnvelope<T>
|
|
1782
1774
|
artifacts: RepositoryArtifactMeta[]
|
|
1783
1775
|
}> {
|
|
1776
|
+
const { validateRepositoryEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
1784
1777
|
const prepared: PreparedArtifact[] = []
|
|
1785
1778
|
for (const input of artifactInputs) {
|
|
1786
1779
|
prepared.push(await this.prepareArtifact(input))
|
|
@@ -1911,10 +1904,27 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1911
1904
|
scope: ReducerValueScope,
|
|
1912
1905
|
request: ReducerValueRequest,
|
|
1913
1906
|
): Promise<ReducerValue> {
|
|
1914
|
-
if (scope.kind === 'rollup')
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1907
|
+
if (scope.kind === 'rollup') {
|
|
1908
|
+
const { readRollupValue } = rollups.value ?? (await rollups.load())
|
|
1909
|
+
return readRollupValue(scope, request, this.rollupStorage(scope))
|
|
1910
|
+
}
|
|
1911
|
+
const {
|
|
1912
|
+
parseValueRequest,
|
|
1913
|
+
resolveRegisteredValue,
|
|
1914
|
+
readResolvedReducerValue,
|
|
1915
|
+
loadValueRegistration,
|
|
1916
|
+
loadedValueRegistration,
|
|
1917
|
+
} = reducedValues.value ?? (await reducedValues.load())
|
|
1918
|
+
// Reject invalid requests before touching storage. Only the requested
|
|
1919
|
+
// reducer's registration initializes; a loaded one adds no await.
|
|
1920
|
+
const parsed = parseValueRequest(request)
|
|
1921
|
+
const loaded = loadedValueRegistration(parsed.reducer)
|
|
1922
|
+
const resolved = resolveRegisteredValue(
|
|
1923
|
+
scope,
|
|
1924
|
+
parsed,
|
|
1925
|
+
loaded !== null ? loaded : await loadValueRegistration(parsed.reducer),
|
|
1926
|
+
)
|
|
1927
|
+
return readResolvedReducerValue(resolved, {
|
|
1918
1928
|
highWater: async () => {
|
|
1919
1929
|
const tail = this.snapshotTail(scope)
|
|
1920
1930
|
if (tail === undefined) throw new Error('unknown reducer scope')
|
|
@@ -2231,6 +2241,11 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2231
2241
|
}
|
|
2232
2242
|
|
|
2233
2243
|
async getRepoStateEvents(repo: string): Promise<RepositoryEvent[]> {
|
|
2244
|
+
const {
|
|
2245
|
+
REPOSITORY_STATE_EVENT_TYPES,
|
|
2246
|
+
REPOSITORY_LATEST_EVENT_TYPES,
|
|
2247
|
+
readRepoStateEventsWithAnchorRecheck,
|
|
2248
|
+
} = repositoryStateEvents.value ?? (await repositoryStateEvents.load())
|
|
2234
2249
|
this.requireRepo(repo)
|
|
2235
2250
|
// Two queries, mirroring the oracle's derivation: the latest
|
|
2236
2251
|
// run-started anchor, then one select of durable types plus the tail
|
|
@@ -2368,6 +2383,8 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2368
2383
|
}
|
|
2369
2384
|
|
|
2370
2385
|
async ticketAssetLimits(_repo: string): Promise<TicketAssetLimits> {
|
|
2386
|
+
const { DEFAULT_TICKET_ASSET_LIMITS } =
|
|
2387
|
+
ticketAssetCapability.value ?? (await ticketAssetCapability.load())
|
|
2371
2388
|
return { ...DEFAULT_TICKET_ASSET_LIMITS }
|
|
2372
2389
|
}
|
|
2373
2390
|
|
|
@@ -2390,6 +2407,8 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2390
2407
|
ticketId: string,
|
|
2391
2408
|
asset: TicketAssetInput,
|
|
2392
2409
|
): Promise<TicketAssetMeta> {
|
|
2410
|
+
const { validateTicketAssetInput, storeTicketAssetBlobs } =
|
|
2411
|
+
ticketAssetCapability.value ?? (await ticketAssetCapability.load())
|
|
2393
2412
|
const size = validateTicketAssetInput(asset)
|
|
2394
2413
|
const entries = await storeTicketAssetBlobs(this.blobs, asset.entries)
|
|
2395
2414
|
return this.writeTx(() => {
|
|
@@ -2424,6 +2443,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2424
2443
|
name: string,
|
|
2425
2444
|
rev?: number,
|
|
2426
2445
|
): Promise<TicketAsset | null> {
|
|
2446
|
+
const { loadTicketAsset } = ticketAssetCapability.value ?? (await ticketAssetCapability.load())
|
|
2427
2447
|
const scoped = ticketAssetKey(repo, ticketId, kind, name)
|
|
2428
2448
|
const row =
|
|
2429
2449
|
rev === undefined
|
|
@@ -2449,6 +2469,8 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2449
2469
|
name: string,
|
|
2450
2470
|
rev?: number,
|
|
2451
2471
|
): Promise<TicketAsset | null> {
|
|
2472
|
+
const { resolvePinnedAsset } =
|
|
2473
|
+
ticketAssetCapability.value ?? (await ticketAssetCapability.load())
|
|
2452
2474
|
return resolvePinnedAsset(this, slug, kind, name, rev)
|
|
2453
2475
|
}
|
|
2454
2476
|
|
|
@@ -2457,6 +2479,8 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2457
2479
|
ticketId: string,
|
|
2458
2480
|
opts?: { revisions?: boolean },
|
|
2459
2481
|
): Promise<TicketAssetSummary[]> {
|
|
2482
|
+
const { summarizeTicketAsset } =
|
|
2483
|
+
ticketAssetCapability.value ?? (await ticketAssetCapability.load())
|
|
2460
2484
|
if (opts?.revisions) {
|
|
2461
2485
|
return this.db
|
|
2462
2486
|
.select()
|
|
@@ -2571,6 +2595,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2571
2595
|
completion: RepoTickCompletion,
|
|
2572
2596
|
events: RepositoryEventWrite[],
|
|
2573
2597
|
): Promise<RepoTickFinish | null> {
|
|
2598
|
+
const { validateTickFinish } = writeValidation.value ?? (await writeValidation.load())
|
|
2574
2599
|
const validated = validateTickFinish(holder, completion, events)
|
|
2575
2600
|
return this.writeTx(() => {
|
|
2576
2601
|
const row = this.requireRepo(repo)
|
|
@@ -2718,6 +2743,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2718
2743
|
}
|
|
2719
2744
|
|
|
2720
2745
|
async createSession(input: NewSessionInput): Promise<SessionRecord> {
|
|
2746
|
+
const { validateSessionEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
2721
2747
|
const operator = normalizeOperator(input.operator)
|
|
2722
2748
|
if (!input.repo) throw new Error('repo is required')
|
|
2723
2749
|
const ts = this.now()
|
|
@@ -2789,6 +2815,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2789
2815
|
id: string,
|
|
2790
2816
|
event: SessionEventWrite<T>,
|
|
2791
2817
|
): Promise<SessionEventEnvelope<T>> {
|
|
2818
|
+
const { validateSessionEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
2792
2819
|
const validated = validateSessionEventWrite(event)
|
|
2793
2820
|
return this.writeTx(() => this.appendSessionInTx(id, validated) as SessionEventEnvelope<T>)
|
|
2794
2821
|
}
|
|
@@ -2798,6 +2825,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2798
2825
|
expectedSeq: number,
|
|
2799
2826
|
event: SessionEventWrite<T>,
|
|
2800
2827
|
): Promise<SessionEventEnvelope<T> | null> {
|
|
2828
|
+
const { validateSessionEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
2801
2829
|
validateExpectedSeq(expectedSeq)
|
|
2802
2830
|
const validated = validateSessionEventWrite(event)
|
|
2803
2831
|
return this.writeTx(() => {
|
|
@@ -2886,6 +2914,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2886
2914
|
artifactInputs: ArtifactInput[],
|
|
2887
2915
|
makeEvent: (deposited: SessionArtifactMeta[]) => SessionEventWrite<T>,
|
|
2888
2916
|
): Promise<{ event: SessionEventEnvelope<T>; artifacts: SessionArtifactMeta[] }> {
|
|
2917
|
+
const { validateSessionEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
2889
2918
|
const prepared: PreparedArtifact[] = []
|
|
2890
2919
|
for (const input of artifactInputs) {
|
|
2891
2920
|
prepared.push(await this.prepareArtifact(input))
|
|
@@ -3136,6 +3165,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
3136
3165
|
}
|
|
3137
3166
|
|
|
3138
3167
|
async closeStream(streamId: string, outcome: StreamOutcome): Promise<StreamRecord> {
|
|
3168
|
+
const { assembleUIMessageDocument } = streamAssembly.value ?? (await streamAssembly.load())
|
|
3139
3169
|
// The per-stream mutex holds across the entire prepare→commit loop
|
|
3140
3170
|
// (AUT-348): a same-process append issued during this close waits for it
|
|
3141
3171
|
// to finish and then rejects on the closed check with StreamClosedError.
|
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
buildStreamSeedReducer,
|
|
12
12
|
repositoryReadFactsReducer,
|
|
13
13
|
} from '../kernel/read-facts'
|
|
14
|
-
import { publicationStateReducer } from '../processes/publication-state'
|
|
15
14
|
import type { SnapshotScope } from './snapshots'
|
|
15
|
+
import type { DoneEscalationsValue } from '../kernel/done-escalations'
|
|
16
16
|
|
|
17
17
|
export class ReducerValueValidationError extends Error {
|
|
18
18
|
constructor(
|
|
@@ -43,6 +43,9 @@ export async function readBuildFacts(store: Reader, slug: string) {
|
|
|
43
43
|
'buildReadFacts',
|
|
44
44
|
)
|
|
45
45
|
const value = result.value
|
|
46
|
+
// A build reducer: repository readers of this module never initialize it.
|
|
47
|
+
// Once loaded, the read adds no await.
|
|
48
|
+
if (!publicationStateReducer) publicationStateReducer = await loadPublicationStateReducer()
|
|
46
49
|
return {
|
|
47
50
|
cursor: result.cursor,
|
|
48
51
|
value: {
|
|
@@ -52,6 +55,12 @@ export async function readBuildFacts(store: Reader, slug: string) {
|
|
|
52
55
|
},
|
|
53
56
|
}
|
|
54
57
|
}
|
|
58
|
+
let publicationStateReducer:
|
|
59
|
+
| typeof import('../processes/publication-state').publicationStateReducer
|
|
60
|
+
| undefined
|
|
61
|
+
async function loadPublicationStateReducer() {
|
|
62
|
+
return (await import('../processes/publication-state')).publicationStateReducer
|
|
63
|
+
}
|
|
55
64
|
async function readValue<T>(
|
|
56
65
|
store: Reader,
|
|
57
66
|
scope: SnapshotScope,
|
|
@@ -64,6 +73,19 @@ async function readValue<T>(
|
|
|
64
73
|
return { cursor: result.cursor, value: result.value as T }
|
|
65
74
|
}
|
|
66
75
|
|
|
76
|
+
/** The `doneEscalations` rollup (SPEC §7.7): every `done` build with an open
|
|
77
|
+
* escalation. Two constant reads and zero event rows while nothing changed. */
|
|
78
|
+
export async function readDoneEscalations(
|
|
79
|
+
store: Reader,
|
|
80
|
+
repo: string,
|
|
81
|
+
): Promise<DoneEscalationsValue> {
|
|
82
|
+
const { value } = await store.getReducerValue(
|
|
83
|
+
{ kind: 'rollup', repo },
|
|
84
|
+
{ reducer: 'doneEscalations' },
|
|
85
|
+
)
|
|
86
|
+
return value as unknown as DoneEscalationsValue
|
|
87
|
+
}
|
|
88
|
+
|
|
67
89
|
/** One served constant-size value naming the current hosted harvest
|
|
68
90
|
* authority; no `getRepo` call, no event download. */
|
|
69
91
|
export async function readHostedHarvestAuthority(store: Reader, repo: string) {
|
|
@@ -261,6 +283,15 @@ export async function readPersistedBuildDigests(
|
|
|
261
283
|
return new Map(entries)
|
|
262
284
|
}
|
|
263
285
|
|
|
286
|
+
/** One build's persisted digest with the build-log cursor it was served at. */
|
|
287
|
+
export async function readPersistedBuildDigest(store: Reader, slug: string) {
|
|
288
|
+
return readValue<ReturnType<typeof import('./digest').buildDigestReducer.finish>>(
|
|
289
|
+
store,
|
|
290
|
+
{ kind: 'build', slug },
|
|
291
|
+
'buildDigest',
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
|
|
264
295
|
/** Keep the batch boundary for hosted callers; adapter implementations use
|
|
265
296
|
* readPersistedBuildDigests so each digest still comes from a persisted value. */
|
|
266
297
|
export function readBuildDigests(store: Pick<BuildStore, 'getRepoBuildDigests'>, repo: string) {
|