@defrex/autobuild 1.0.0-beta.0 → 1.0.0-beta.2
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 +9 -4
- package/SPEC.md +295 -62
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +179 -25
- package/docs/configuration.md +41 -6
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +81 -4
- package/docs/landing-policy.md +11 -0
- package/docs/migration-1.0.md +9 -0
- package/docs/operator-api.md +18 -0
- package/docs/remote-store-protocol.md +11 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/ticket-dependencies.md +6 -45
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +4 -1
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +53 -1
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/detail.ts +45 -1
- package/packages/core/src/cli/dashboard/facts.ts +7 -2
- package/packages/core/src/cli/dashboard/integration-detail.ts +142 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +248 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +140 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- package/packages/core/src/cli/dashboard/refresh.ts +20 -13
- package/packages/core/src/cli/dashboard/render.ts +106 -5
- package/packages/core/src/cli/dashboard/transcript.ts +2 -1
- package/packages/core/src/cli/dispatch-frontend.ts +22 -12
- package/packages/core/src/cli/dispatch.ts +59 -25
- package/packages/core/src/cli/help.ts +19 -2
- package/packages/core/src/cli/main.ts +37 -0
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +97 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/wait.ts +11 -2
- package/packages/core/src/cli/watch.ts +12 -0
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +38 -0
- package/packages/core/src/events/compatibility.ts +183 -0
- package/packages/core/src/events/native-session.ts +13 -0
- package/packages/core/src/events/payloads.ts +148 -2
- package/packages/core/src/events/policy.ts +209 -0
- package/packages/core/src/events/repository.ts +48 -0
- package/packages/core/src/integration/harness.ts +4 -4
- package/packages/core/src/kernel/__snapshots__/{reducer-registry.test.ts.snap → reducer-accumulator-shapes.json} +771 -538
- package/packages/core/src/kernel/change-presence.ts +4 -2
- package/packages/core/src/kernel/dispatch-capacity.ts +119 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +5 -1
- package/packages/core/src/kernel/engine.ts +25 -5
- package/packages/core/src/kernel/forge-health.ts +19 -0
- package/packages/core/src/kernel/generators/build-log.ts +18 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +1 -1
- package/packages/core/src/kernel/generators/repository-journals.ts +10 -0
- package/packages/core/src/kernel/guarded-forge.ts +159 -0
- package/packages/core/src/kernel/incremental.ts +4 -2
- package/packages/core/src/kernel/integration-completeness.ts +61 -0
- package/packages/core/src/kernel/integration-landing.ts +5 -4
- package/packages/core/src/kernel/janitor-failure.ts +36 -0
- package/packages/core/src/kernel/landing-publication.ts +35 -15
- package/packages/core/src/kernel/landing-state.ts +7 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +1 -1
- package/packages/core/src/kernel/log-index.ts +12 -1
- package/packages/core/src/kernel/mixed-version.ts +52 -0
- package/packages/core/src/kernel/node-landing.ts +14 -11
- package/packages/core/src/kernel/node-restack-demand.ts +29 -0
- package/packages/core/src/kernel/node-restack-state.ts +46 -16
- package/packages/core/src/kernel/node-restack-transaction.ts +151 -8
- package/packages/core/src/kernel/node-restack.ts +34 -10
- package/packages/core/src/kernel/publication.ts +22 -0
- package/packages/core/src/kernel/read-deferrals.ts +111 -0
- package/packages/core/src/kernel/read-facts.ts +27 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +15 -2
- package/packages/core/src/kernel/reducer.ts +196 -10
- package/packages/core/src/kernel/repository-attention.ts +38 -1
- package/packages/core/src/kernel/terminal-guard.ts +11 -4
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/presentation.ts +5 -0
- package/packages/core/src/operator/query.ts +45 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/load.ts +3 -4
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/contract.ts +23 -0
- package/packages/core/src/ports/forge/fake.ts +6 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +92 -64
- package/packages/core/src/ports/forge/github-transport.ts +45 -2
- package/packages/core/src/ports/forge/github.ts +56 -17
- package/packages/core/src/ports/forge/local-git.ts +7 -2
- package/packages/core/src/ports/forge-failure.ts +40 -0
- package/packages/core/src/ports/forge-request-context.ts +35 -0
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/claude.ts +136 -9
- package/packages/core/src/ports/runner/codex.ts +112 -7
- package/packages/core/src/ports/runner/contract.ts +78 -0
- package/packages/core/src/ports/runner/fake.ts +59 -1
- package/packages/core/src/ports/runner/native-cli-fixture.ts +86 -0
- package/packages/core/src/ports/runner/native-process-fixture.ts +38 -0
- package/packages/core/src/ports/runner/native-session.ts +110 -0
- package/packages/core/src/ports/runner/pi-rpc.ts +7 -1
- package/packages/core/src/ports/runner/pi.ts +162 -2
- package/packages/core/src/ports/types.ts +53 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +45 -51
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +28 -12
- package/packages/core/src/processes/build-child-exit.ts +50 -2
- package/packages/core/src/processes/build-child.ts +15 -7
- package/packages/core/src/processes/build-runner.ts +909 -213
- package/packages/core/src/processes/dispatcher.ts +652 -334
- package/packages/core/src/processes/execution-no-progress.ts +15 -0
- package/packages/core/src/processes/pause-execution-fixture.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +2 -1
- package/packages/core/src/processes/publication-loss.ts +7 -3
- package/packages/core/src/processes/repo-view.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +6 -2
- package/packages/core/src/runtime-identity.ts +37 -0
- package/packages/core/src/store/adapter.ts +4 -2
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +203 -16
- package/packages/core/src/store/digest.ts +20 -2
- package/packages/core/src/store/local/schema.ts +6 -0
- package/packages/core/src/store/local/store.ts +57 -4
- package/packages/core/src/store/memory.ts +83 -2
- package/packages/core/src/store/new-build.ts +2 -2
- package/packages/core/src/store/phase-session.ts +13 -0
- package/packages/core/src/store/reduced-reads.ts +43 -4
- package/packages/core/src/store/reducer-value-shapes.json +8238 -5764
- package/packages/core/src/store/reducer-value-validation.ts +103 -3
- package/packages/core/src/store/reducer-values.ts +21 -6
- package/packages/core/src/store/remote/client.ts +146 -20
- package/packages/core/src/store/remote/compatibility.ts +6 -0
- package/packages/core/src/store/remote/index.ts +2 -0
- package/packages/core/src/store/remote/protocol.ts +19 -0
- package/packages/core/src/store/remote/version.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +6 -1
- package/packages/core/src/store/session-handle.ts +8 -0
- package/packages/core/src/store/snapshots.ts +21 -5
- package/packages/core/src/store/types.ts +19 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +17 -2
- package/packages/core/src/testing/index.ts +7 -0
- package/packages/core/src/testing/newer-writer.ts +37 -0
- package/packages/core/src/testing/reduced-read-budget.ts +3 -0
- package/skills/guide/SKILL.md +144 -27
- package/skills/guide/references/integration-tree.md +81 -4
- package/skills/guide/references/landing-policy.md +11 -0
- package/skills/guide/references/migration-1.0.md +9 -0
- package/skills/guide/references/operator-api.md +18 -0
- package/skills/guide/references/plugin-authoring.md +55 -7
- package/skills/guide/references/remote-store-protocol.md +11 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/implement/SKILL.md +4 -2
- package/skills/operate/SKILL.md +63 -6
- package/skills/reconcile/SKILL.md +3 -1
- package/skills/spec/SKILL.md +49 -39
- package/skills/tickets/SKILL.md +15 -43
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
advanceCompatibility,
|
|
3
|
+
initialCompatibility,
|
|
4
|
+
type CompatibilityState,
|
|
5
|
+
type StoredEvent,
|
|
6
|
+
} from '../events/compatibility'
|
|
1
7
|
/**
|
|
2
8
|
* The shared build-digest derivation (AUT-487): every BuildStore adapter
|
|
3
9
|
* answers `getRepoBuildDigests` by fetching only the digest-relevant event
|
|
@@ -37,6 +43,7 @@ export const DIGEST_EVENT_TYPES = [
|
|
|
37
43
|
* `pr-attachment.reclaimed` rows and `instance` for `execution.started` /
|
|
38
44
|
* `execution.ended` rows instead of whole payloads. */
|
|
39
45
|
export type DigestEventRow = Pick<AbEvent, 'type' | 'seq' | 'ts'> & {
|
|
46
|
+
rawUnknown?: StoredEvent
|
|
40
47
|
auditRequested?: boolean
|
|
41
48
|
mergedSha?: string
|
|
42
49
|
nodeContribution?: BuildDigest['nodeContribution']
|
|
@@ -55,6 +62,7 @@ export type DigestEvent = DigestEventRow
|
|
|
55
62
|
|
|
56
63
|
/** The carried accumulator for `reduceBuildDigest`. */
|
|
57
64
|
export interface DigestAcc {
|
|
65
|
+
compatibility: CompatibilityState
|
|
58
66
|
integrationAuditPending?: true
|
|
59
67
|
mergedSha?: string
|
|
60
68
|
nodeContribution?: BuildDigest['nodeContribution']
|
|
@@ -74,7 +82,7 @@ export interface DigestAcc {
|
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
/** Bump when `DigestAcc`'s shape or fold semantics change. */
|
|
77
|
-
export const BUILD_DIGEST_REDUCER_VERSION =
|
|
85
|
+
export const BUILD_DIGEST_REDUCER_VERSION = 10
|
|
78
86
|
|
|
79
87
|
export const buildDigestReducer: IncrementalReducer<
|
|
80
88
|
DigestAcc,
|
|
@@ -82,11 +90,19 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
82
90
|
Omit<BuildDigest, 'slug'>
|
|
83
91
|
> = defineReducer({
|
|
84
92
|
version: BUILD_DIGEST_REDUCER_VERSION,
|
|
85
|
-
initial: (): DigestAcc => ({
|
|
93
|
+
initial: (): DigestAcc => ({
|
|
94
|
+
compatibility: initialCompatibility(),
|
|
95
|
+
observations: [],
|
|
96
|
+
hosted: [],
|
|
97
|
+
reclaimed: [],
|
|
98
|
+
openInstance: null,
|
|
99
|
+
}),
|
|
86
100
|
fold(acc, events) {
|
|
87
101
|
for (const event of events) {
|
|
102
|
+
if (event.rawUnknown) advanceCompatibility(acc.compatibility, [event.rawUnknown])
|
|
88
103
|
if (
|
|
89
104
|
[
|
|
105
|
+
'node.writer-settled',
|
|
90
106
|
'node.opened',
|
|
91
107
|
'node.contribution-recorded',
|
|
92
108
|
'pr.closed',
|
|
@@ -122,6 +138,7 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
122
138
|
}
|
|
123
139
|
},
|
|
124
140
|
finish: ({
|
|
141
|
+
compatibility,
|
|
125
142
|
integrationAuditPending,
|
|
126
143
|
mergedSha,
|
|
127
144
|
nodeContribution,
|
|
@@ -139,6 +156,7 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
139
156
|
const reclaimedSet = new Set(reclaimed)
|
|
140
157
|
const reclaimPending = hosted.some((seq) => !reclaimedSet.has(seq))
|
|
141
158
|
return {
|
|
159
|
+
...(compatibility.unknownFacts ? { compatibility: structuredClone(compatibility) } : {}),
|
|
142
160
|
...(integrationAuditPending ? { integrationAuditPending } : {}),
|
|
143
161
|
...(mergedSha !== undefined ? { mergedSha } : {}),
|
|
144
162
|
...(nodeContribution !== undefined
|
|
@@ -46,6 +46,9 @@ export const events = sqliteTable(
|
|
|
46
46
|
actor: text('actor', { mode: 'json' }).notNull().$type<Actor>(),
|
|
47
47
|
type: text('type').notNull(),
|
|
48
48
|
payload: text('payload', { mode: 'json' }).notNull(),
|
|
49
|
+
compatibility: text('compatibility', { mode: 'json' }).$type<
|
|
50
|
+
import('../../events/policy').CompatibilityMetadata
|
|
51
|
+
>(),
|
|
49
52
|
},
|
|
50
53
|
// Mirrors the BOOTSTRAP_DDL digest-scan index (AUT-487), type-leading so the
|
|
51
54
|
// digest query's cost grows with digest-relevant events, not total history.
|
|
@@ -75,6 +78,9 @@ export const repoEvents = sqliteTable(
|
|
|
75
78
|
actor: text('actor', { mode: 'json' }).notNull().$type<Actor>(),
|
|
76
79
|
type: text('type').notNull(),
|
|
77
80
|
payload: text('payload', { mode: 'json' }).notNull(),
|
|
81
|
+
compatibility: text('compatibility', { mode: 'json' }).$type<
|
|
82
|
+
import('../../events/policy').CompatibilityMetadata
|
|
83
|
+
>(),
|
|
78
84
|
},
|
|
79
85
|
(t) => [primaryKey({ columns: [t.repo, t.seq] })],
|
|
80
86
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { READ_CATALOG_IDENTITY } from '../../events/compatibility'
|
|
1
2
|
import { readPersistedBuildDigests } from '../reduced-reads'
|
|
2
3
|
import { assertPublicSnapshotReducer } from '../snapshots'
|
|
3
4
|
import {
|
|
@@ -29,14 +30,14 @@ import { tmpdir } from 'node:os'
|
|
|
29
30
|
import { join } from 'node:path'
|
|
30
31
|
import { humanActor } from '../../events/envelope'
|
|
31
32
|
import {
|
|
32
|
-
validateEventWrite,
|
|
33
|
+
prepareEventWrite as validateEventWrite,
|
|
33
34
|
type AbEvent,
|
|
34
35
|
type EventEnvelope,
|
|
35
36
|
type EventWrite,
|
|
36
37
|
} from '../../events/catalog'
|
|
37
38
|
import type { EventType } from '../../events/payloads'
|
|
38
39
|
import {
|
|
39
|
-
validateRepositoryEventWrite,
|
|
40
|
+
prepareRepositoryEventWrite as validateRepositoryEventWrite,
|
|
40
41
|
type RepositoryEvent,
|
|
41
42
|
type RepositoryEventEnvelope,
|
|
42
43
|
type RepositoryEventType,
|
|
@@ -199,6 +200,7 @@ export const BOOTSTRAP_DDL = [
|
|
|
199
200
|
actor TEXT NOT NULL,
|
|
200
201
|
type TEXT NOT NULL,
|
|
201
202
|
payload TEXT NOT NULL,
|
|
203
|
+
compatibility TEXT,
|
|
202
204
|
PRIMARY KEY (build, seq)
|
|
203
205
|
)`,
|
|
204
206
|
// The build-digest scan (AUT-487): type-leading so the digest query's cost
|
|
@@ -231,6 +233,7 @@ export const BOOTSTRAP_DDL = [
|
|
|
231
233
|
actor TEXT NOT NULL,
|
|
232
234
|
type TEXT NOT NULL,
|
|
233
235
|
payload TEXT NOT NULL,
|
|
236
|
+
compatibility TEXT,
|
|
234
237
|
PRIMARY KEY (repo, seq)
|
|
235
238
|
)`,
|
|
236
239
|
`CREATE TABLE IF NOT EXISTS repo_artifacts (
|
|
@@ -344,6 +347,7 @@ function ticketAssetKey(repo: string, ticketId: string, kind: string, name: stri
|
|
|
344
347
|
}
|
|
345
348
|
|
|
346
349
|
export class SqliteBuildStore implements BuildStore {
|
|
350
|
+
readonly catalogIdentity = READ_CATALOG_IDENTITY
|
|
347
351
|
private readonly sqlite: Database
|
|
348
352
|
private readonly db: BunSQLiteDatabase
|
|
349
353
|
/** Per-stream in-process mutex (store/streams/lock.ts): serializes a
|
|
@@ -366,6 +370,11 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
366
370
|
this.sqlite.exec('PRAGMA busy_timeout = 5000')
|
|
367
371
|
this.sqlite.exec('PRAGMA journal_mode = WAL')
|
|
368
372
|
for (const ddl of BOOTSTRAP_DDL) this.sqlite.exec(ddl)
|
|
373
|
+
for (const table of ['events', 'repo_events']) {
|
|
374
|
+
const columns = this.sqlite.query(`PRAGMA table_info('${table}')`).all() as { name: string }[]
|
|
375
|
+
if (!columns.some((column) => column.name === 'compatibility'))
|
|
376
|
+
this.sqlite.exec(`ALTER TABLE ${table} ADD COLUMN compatibility TEXT`)
|
|
377
|
+
}
|
|
369
378
|
// Stores created before `repo_origin` existed keep working: add the column
|
|
370
379
|
// idempotently when a pre-existing table lacks it (the bootstrap DDL above
|
|
371
380
|
// covers fresh stores). No migration framework — one guarded ALTER at open.
|
|
@@ -605,6 +614,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
605
614
|
actor: validated.actor,
|
|
606
615
|
type: validated.type,
|
|
607
616
|
payload: validated.payload,
|
|
617
|
+
compatibility: validated.compatibility,
|
|
608
618
|
})
|
|
609
619
|
.run()
|
|
610
620
|
this.db.update(builds).set({ updatedAt: ts }).where(eq(builds.slug, slug)).run()
|
|
@@ -615,6 +625,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
615
625
|
actor: validated.actor,
|
|
616
626
|
type: validated.type,
|
|
617
627
|
payload: validated.payload,
|
|
628
|
+
compatibility: validated.compatibility,
|
|
618
629
|
}
|
|
619
630
|
}
|
|
620
631
|
|
|
@@ -783,6 +794,41 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
783
794
|
})
|
|
784
795
|
}
|
|
785
796
|
|
|
797
|
+
async appendWithArtifactsIfCurrent<T extends EventType>(
|
|
798
|
+
slug: string,
|
|
799
|
+
expectedSeq: number,
|
|
800
|
+
artifactInputs: ArtifactInput[],
|
|
801
|
+
makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
802
|
+
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] } | null> {
|
|
803
|
+
validateExpectedSeq(expectedSeq)
|
|
804
|
+
const prepared: PreparedArtifact[] = []
|
|
805
|
+
for (const input of artifactInputs) {
|
|
806
|
+
prepared.push(await this.prepareArtifact(input))
|
|
807
|
+
}
|
|
808
|
+
// One synchronous transaction: deposits + event append commit together;
|
|
809
|
+
// an invalid event throws, rolling back every deposit (D6).
|
|
810
|
+
//
|
|
811
|
+
// Ordering invariant (AUT-322): the batch event is validated BEFORE any
|
|
812
|
+
// retention prune runs. Deposits land unpruned, validation gates the
|
|
813
|
+
// whole batch, and only then does one prune per distinct batch kind
|
|
814
|
+
// execute — still inside this transaction. A same-kind batch whose prune
|
|
815
|
+
// scope covers a sibling therefore never deletes that sibling before the
|
|
816
|
+
// batch's event is validated. Pruning once per kind (not per deposit) is
|
|
817
|
+
// equivalent: `revisionsToPrune` is a pure function of the full
|
|
818
|
+
// post-batch revision set, and pruned revisions are always older than
|
|
819
|
+
// the current MAX, so revision assignment is unaffected.
|
|
820
|
+
return this.writeTx(() => {
|
|
821
|
+
if (this.currentSeqInTx(slug) !== expectedSeq) return null
|
|
822
|
+
const deposited = prepared.map((p) => this.depositInTx(slug, p, { prune: false }))
|
|
823
|
+
const validated = validateEventWrite(makeEvent(deposited))
|
|
824
|
+
for (const kind of new Set(deposited.map((meta) => meta.kind))) {
|
|
825
|
+
this.pruneBuildInTx(slug, kind)
|
|
826
|
+
}
|
|
827
|
+
const event = this.appendInTx(slug, validated) as EventEnvelope<T>
|
|
828
|
+
return { event, artifacts: deposited }
|
|
829
|
+
})
|
|
830
|
+
}
|
|
831
|
+
|
|
786
832
|
async getEvents(
|
|
787
833
|
slug: string,
|
|
788
834
|
sinceSeq = 0,
|
|
@@ -806,6 +852,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
806
852
|
actor: row.actor,
|
|
807
853
|
type: row.type,
|
|
808
854
|
payload: row.payload,
|
|
855
|
+
...(row.compatibility ? { compatibility: row.compatibility } : {}),
|
|
809
856
|
}) as AbEvent,
|
|
810
857
|
)
|
|
811
858
|
},
|
|
@@ -1035,6 +1082,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1035
1082
|
actor: validated.actor,
|
|
1036
1083
|
type: validated.type,
|
|
1037
1084
|
payload: validated.payload,
|
|
1085
|
+
compatibility: validated.compatibility,
|
|
1038
1086
|
})
|
|
1039
1087
|
.run()
|
|
1040
1088
|
this.db.update(repoStreams).set({ updatedAt: ts }).where(eq(repoStreams.repo, repo)).run()
|
|
@@ -1045,6 +1093,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1045
1093
|
actor: validated.actor,
|
|
1046
1094
|
type: validated.type,
|
|
1047
1095
|
payload: validated.payload,
|
|
1096
|
+
compatibility: validated.compatibility,
|
|
1048
1097
|
}
|
|
1049
1098
|
}
|
|
1050
1099
|
|
|
@@ -1147,6 +1196,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1147
1196
|
actor: row.actor,
|
|
1148
1197
|
type: row.type,
|
|
1149
1198
|
payload: row.payload,
|
|
1199
|
+
...(row.compatibility ? { compatibility: row.compatibility } : {}),
|
|
1150
1200
|
}) as RepositoryEvent,
|
|
1151
1201
|
)
|
|
1152
1202
|
},
|
|
@@ -1212,11 +1262,13 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1212
1262
|
actor: string
|
|
1213
1263
|
type: string
|
|
1214
1264
|
payload: string
|
|
1265
|
+
compatibility?: string | null
|
|
1215
1266
|
}[]
|
|
1216
1267
|
return rows.map((row) => ({
|
|
1217
1268
|
...row,
|
|
1218
1269
|
actor: JSON.parse(row.actor),
|
|
1219
1270
|
payload: JSON.parse(row.payload),
|
|
1271
|
+
compatibility: row.compatibility ? JSON.parse(row.compatibility) : undefined,
|
|
1220
1272
|
})) as (AbEvent | RepositoryEvent)[]
|
|
1221
1273
|
},
|
|
1222
1274
|
put: (key, snapshot) => this.putSnapshot(scope, key, snapshot),
|
|
@@ -1315,8 +1367,8 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1315
1367
|
ON CONFLICT (scope_kind, scope_key, reducer) DO UPDATE SET
|
|
1316
1368
|
version = excluded.version, cursor = excluded.cursor,
|
|
1317
1369
|
state = excluded.state, updated_at = excluded.updated_at
|
|
1318
|
-
WHERE excluded.cursor > reducer_snapshots.cursor
|
|
1319
|
-
OR (excluded.cursor = reducer_snapshots.cursor AND excluded.version > reducer_snapshots.version)`,
|
|
1370
|
+
WHERE excluded.version >= reducer_snapshots.version AND (excluded.cursor > reducer_snapshots.cursor
|
|
1371
|
+
OR (excluded.cursor = reducer_snapshots.cursor AND excluded.version > reducer_snapshots.version))`,
|
|
1320
1372
|
)
|
|
1321
1373
|
.run(
|
|
1322
1374
|
scope.kind,
|
|
@@ -1404,6 +1456,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1404
1456
|
actor: row.actor,
|
|
1405
1457
|
type: row.type,
|
|
1406
1458
|
payload: row.payload,
|
|
1459
|
+
...(row.compatibility ? { compatibility: row.compatibility } : {}),
|
|
1407
1460
|
}) as RepositoryEvent,
|
|
1408
1461
|
)
|
|
1409
1462
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { READ_CATALOG_IDENTITY } from '../events/compatibility'
|
|
1
2
|
import { readPersistedBuildDigests } from './reduced-reads'
|
|
2
3
|
import { assertPublicSnapshotReducer } from './snapshots'
|
|
3
4
|
import {
|
|
@@ -14,14 +15,14 @@ import type { RepoTickCompletion, RepoTickFinish, RepoTickObservation } from './
|
|
|
14
15
|
* every other adapter (SQLite, remote HTTP) must match it.
|
|
15
16
|
*/
|
|
16
17
|
import {
|
|
17
|
-
validateEventWrite,
|
|
18
|
+
prepareEventWrite as validateEventWrite,
|
|
18
19
|
type AbEvent,
|
|
19
20
|
type EventEnvelope,
|
|
20
21
|
type EventWrite,
|
|
21
22
|
} from '../events/catalog'
|
|
22
23
|
import type { EventType } from '../events/payloads'
|
|
23
24
|
import {
|
|
24
|
-
validateRepositoryEventWrite,
|
|
25
|
+
prepareRepositoryEventWrite as validateRepositoryEventWrite,
|
|
25
26
|
type RepositoryEvent,
|
|
26
27
|
type RepositoryEventEnvelope,
|
|
27
28
|
type RepositoryEventType,
|
|
@@ -173,6 +174,7 @@ interface SessionState {
|
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
export class MemoryBuildStore implements BuildStore {
|
|
177
|
+
readonly catalogIdentity = READ_CATALOG_IDENTITY
|
|
176
178
|
private readonly builds = new Map<string, BuildState>()
|
|
177
179
|
private readonly repos = new Map<string, RepoState>()
|
|
178
180
|
private readonly streams = new Map<string, StreamState>()
|
|
@@ -310,6 +312,7 @@ export class MemoryBuildStore implements BuildStore {
|
|
|
310
312
|
actor: created.actor,
|
|
311
313
|
type: created.type,
|
|
312
314
|
payload: created.payload,
|
|
315
|
+
compatibility: created.compatibility,
|
|
313
316
|
}) as AbEvent,
|
|
314
317
|
)
|
|
315
318
|
}
|
|
@@ -360,6 +363,7 @@ export class MemoryBuildStore implements BuildStore {
|
|
|
360
363
|
actor: validated.actor,
|
|
361
364
|
type: validated.type,
|
|
362
365
|
payload: validated.payload,
|
|
366
|
+
compatibility: validated.compatibility,
|
|
363
367
|
} as EventEnvelope<T>
|
|
364
368
|
state.events.push(structuredClone(envelope) as AbEvent)
|
|
365
369
|
this.advanceRepo(state.record.repo)
|
|
@@ -387,6 +391,7 @@ export class MemoryBuildStore implements BuildStore {
|
|
|
387
391
|
actor: validated.actor,
|
|
388
392
|
type: validated.type,
|
|
389
393
|
payload: validated.payload,
|
|
394
|
+
compatibility: validated.compatibility,
|
|
390
395
|
} as EventEnvelope<T>
|
|
391
396
|
state.events.push(structuredClone(envelope) as AbEvent)
|
|
392
397
|
this.advanceRepo(state.record.repo)
|
|
@@ -456,6 +461,80 @@ export class MemoryBuildStore implements BuildStore {
|
|
|
456
461
|
actor: validated.actor,
|
|
457
462
|
type: validated.type,
|
|
458
463
|
payload: validated.payload,
|
|
464
|
+
compatibility: validated.compatibility,
|
|
465
|
+
} as EventEnvelope<T>
|
|
466
|
+
state.events.push(structuredClone(envelope) as AbEvent)
|
|
467
|
+
this.advanceRepo(state.record.repo)
|
|
468
|
+
state.record.updatedAt = ts
|
|
469
|
+
return { event: envelope, artifacts: structuredClone(deposited) }
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
async appendWithArtifactsIfCurrent<T extends EventType>(
|
|
473
|
+
slug: string,
|
|
474
|
+
expectedSeq: number,
|
|
475
|
+
artifacts: ArtifactInput[],
|
|
476
|
+
makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
477
|
+
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] } | null> {
|
|
478
|
+
const state = this.state(slug)
|
|
479
|
+
// Prepare phase — validate every input and store the blobs *before*
|
|
480
|
+
// touching build state, mirroring the SQLite adapter: an invalid input
|
|
481
|
+
// mid-bundle persists nothing, and orphaned blobs are harmless because
|
|
482
|
+
// they are content-addressed (D6, §8.5).
|
|
483
|
+
validateExpectedSeq(expectedSeq)
|
|
484
|
+
const prepared: { kind: string; blobRef: string; metadata: Record<string, unknown> }[] = []
|
|
485
|
+
for (const artifact of artifacts) {
|
|
486
|
+
if (!artifact.kind) throw new Error('artifact kind is required')
|
|
487
|
+
const bytes = toBytes(artifact.content)
|
|
488
|
+
const blobRef = contentHash(bytes)
|
|
489
|
+
await this.blobs.put(blobRef, bytes)
|
|
490
|
+
prepared.push({
|
|
491
|
+
kind: artifact.kind,
|
|
492
|
+
blobRef,
|
|
493
|
+
metadata: structuredClone(artifact.metadata ?? {}),
|
|
494
|
+
})
|
|
495
|
+
}
|
|
496
|
+
// Commit phase — fully synchronous (no await), so no interleaved writer
|
|
497
|
+
// can slip between revision assignment, event validation, and the
|
|
498
|
+
// deposits landing: "there is no state where an artifact exists without
|
|
499
|
+
// its event or vice versa" (D6, §8.5). Everything is validated before
|
|
500
|
+
// the first mutation, so no rollback path exists to get wrong.
|
|
501
|
+
//
|
|
502
|
+
// Ordering invariant (AUT-322): event validation precedes any retention
|
|
503
|
+
// prune — validation runs before the deposit loop below, and the per-kind
|
|
504
|
+
// prune happens inside that loop after the deposit, so a same-kind batch
|
|
505
|
+
// whose prune scope covers a sibling never deletes that sibling before
|
|
506
|
+
// the batch's event is validated.
|
|
507
|
+
if (state.events.length !== expectedSeq) return null
|
|
508
|
+
const ts = this.now()
|
|
509
|
+
const nextRev = new Map<string, number>()
|
|
510
|
+
const deposited: ArtifactMeta[] = prepared.map((p) => {
|
|
511
|
+
const revision =
|
|
512
|
+
nextRev.get(p.kind) ?? MemoryBuildStore.nextRevision(state.artifacts.get(p.kind))
|
|
513
|
+
nextRev.set(p.kind, revision + 1)
|
|
514
|
+
return {
|
|
515
|
+
build: slug,
|
|
516
|
+
kind: p.kind,
|
|
517
|
+
revision,
|
|
518
|
+
blobRef: p.blobRef,
|
|
519
|
+
metadata: p.metadata,
|
|
520
|
+
createdAt: ts,
|
|
521
|
+
}
|
|
522
|
+
})
|
|
523
|
+
const validated = validateEventWrite(makeEvent(structuredClone(deposited)))
|
|
524
|
+
for (const meta of deposited) {
|
|
525
|
+
const revs = state.artifacts.get(meta.kind) ?? []
|
|
526
|
+
revs.push(meta)
|
|
527
|
+
state.artifacts.set(meta.kind, revs)
|
|
528
|
+
this.pruneBuildKind(state, meta.kind)
|
|
529
|
+
}
|
|
530
|
+
const envelope = {
|
|
531
|
+
build: slug,
|
|
532
|
+
seq: state.events.length + 1,
|
|
533
|
+
ts,
|
|
534
|
+
actor: validated.actor,
|
|
535
|
+
type: validated.type,
|
|
536
|
+
payload: validated.payload,
|
|
537
|
+
compatibility: validated.compatibility,
|
|
459
538
|
} as EventEnvelope<T>
|
|
460
539
|
state.events.push(structuredClone(envelope) as AbEvent)
|
|
461
540
|
this.advanceRepo(state.record.repo)
|
|
@@ -651,6 +730,7 @@ export class MemoryBuildStore implements BuildStore {
|
|
|
651
730
|
actor: validated.actor,
|
|
652
731
|
type: validated.type,
|
|
653
732
|
payload: validated.payload,
|
|
733
|
+
compatibility: validated.compatibility,
|
|
654
734
|
} as RepositoryEventEnvelope<T>
|
|
655
735
|
state.events.push(structuredClone(envelope) as RepositoryEvent)
|
|
656
736
|
this.advanceRepo(repo)
|
|
@@ -716,6 +796,7 @@ export class MemoryBuildStore implements BuildStore {
|
|
|
716
796
|
actor: validated.actor,
|
|
717
797
|
type: validated.type,
|
|
718
798
|
payload: validated.payload,
|
|
799
|
+
compatibility: validated.compatibility,
|
|
719
800
|
} as RepositoryEventEnvelope<T>
|
|
720
801
|
state.events.push(structuredClone(envelope) as RepositoryEvent)
|
|
721
802
|
this.advanceRepo(repo)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventValidationError,
|
|
1
|
+
import { EventValidationError, prepareEventWrite, type EventWrite } from '../events/catalog'
|
|
2
2
|
import type { NewBuildInput } from './types'
|
|
3
3
|
|
|
4
4
|
/** Validate `input.created` before an adapter opens its create transaction, so
|
|
@@ -7,7 +7,7 @@ export function validateCreatedEvent(
|
|
|
7
7
|
input: NewBuildInput,
|
|
8
8
|
): EventWrite<'build.created'> | undefined {
|
|
9
9
|
if (input.created === undefined) return undefined
|
|
10
|
-
const validated =
|
|
10
|
+
const validated = prepareEventWrite(input.created)
|
|
11
11
|
if (validated.type !== 'build.created') {
|
|
12
12
|
throw new EventValidationError(
|
|
13
13
|
`createBuild's initial event must be "build.created", got "${validated.type}"`,
|
|
@@ -255,6 +255,19 @@ export function scopeLocalStoreToPhaseSession(
|
|
|
255
255
|
return event
|
|
256
256
|
})
|
|
257
257
|
},
|
|
258
|
+
async appendWithArtifactsIfCurrent<T extends EventType>(
|
|
259
|
+
slug: string,
|
|
260
|
+
expectedSeq: number,
|
|
261
|
+
artifacts: ArtifactInput[],
|
|
262
|
+
makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
263
|
+
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] } | null> {
|
|
264
|
+
own('appendWithArtifactsIfCurrent', 'build', slug)
|
|
265
|
+
return store.appendWithArtifactsIfCurrent(slug, expectedSeq, artifacts, (deposited) => {
|
|
266
|
+
const event = makeEvent(deposited)
|
|
267
|
+
authorizeActor('appendWithArtifactsIfCurrent', event.actor)
|
|
268
|
+
return event
|
|
269
|
+
})
|
|
270
|
+
},
|
|
258
271
|
async getEvents(
|
|
259
272
|
slug: string,
|
|
260
273
|
sinceSeq?: number,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { decodeLog } from '../kernel/log-index-value'
|
|
2
2
|
/** The consumer boundary for current reductions. Raw event reads are for event output. */
|
|
3
3
|
import type { BuildStore } from './types'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
diagnoseReducerValue,
|
|
6
|
+
validateReducerValue,
|
|
7
|
+
type ValidationFailure,
|
|
8
|
+
} from './reducer-value-validation'
|
|
5
9
|
import type {
|
|
6
10
|
buildReadFactsReducer,
|
|
7
11
|
buildStreamSeedReducer,
|
|
@@ -10,6 +14,20 @@ import type {
|
|
|
10
14
|
import { publicationStateReducer } from '../processes/publication-state'
|
|
11
15
|
import type { SnapshotScope } from './snapshots'
|
|
12
16
|
|
|
17
|
+
export class ReducerValueValidationError extends Error {
|
|
18
|
+
constructor(
|
|
19
|
+
readonly reducer: string,
|
|
20
|
+
readonly scope: SnapshotScope,
|
|
21
|
+
readonly cursor: number,
|
|
22
|
+
readonly failure: ValidationFailure,
|
|
23
|
+
) {
|
|
24
|
+
super(
|
|
25
|
+
`invalid persisted value for ${reducer}; scope=${JSON.stringify(scope)}; cursor=${cursor}; path=${failure.path}; expected=${failure.expected}`,
|
|
26
|
+
)
|
|
27
|
+
this.name = 'ReducerValueValidationError'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
type Reader = Pick<BuildStore, 'getReducerValue'>
|
|
14
32
|
export async function readBuildStreamSeed(store: Reader, slug: string) {
|
|
15
33
|
return readValue<ReturnType<typeof buildStreamSeedReducer.finish>>(
|
|
@@ -40,8 +58,8 @@ async function readValue<T>(
|
|
|
40
58
|
reducer: string,
|
|
41
59
|
): Promise<{ cursor: number; value: T }> {
|
|
42
60
|
const result = await store.getReducerValue(scope, { reducer })
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
const failure = diagnoseReducerValue(reducer, result.value)
|
|
62
|
+
if (failure) throw new ReducerValueValidationError(reducer, scope, result.cursor, failure)
|
|
45
63
|
// The generated validator checks the complete finished contract before decoding.
|
|
46
64
|
return { cursor: result.cursor, value: result.value as T }
|
|
47
65
|
}
|
|
@@ -156,6 +174,16 @@ export async function readTerminalGuard(
|
|
|
156
174
|
phase: import('../ontology').Phase,
|
|
157
175
|
round: number,
|
|
158
176
|
session: string,
|
|
177
|
+
) {
|
|
178
|
+
return (await readTerminalGuardBoundary(store, slug, phase, round, session)).value
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function readTerminalGuardBoundary(
|
|
182
|
+
store: Reader,
|
|
183
|
+
slug: string,
|
|
184
|
+
phase: import('../ontology').Phase,
|
|
185
|
+
round: number,
|
|
186
|
+
session: string,
|
|
159
187
|
) {
|
|
160
188
|
const result = await store.getReducerValue(
|
|
161
189
|
{ kind: 'build', slug },
|
|
@@ -163,7 +191,7 @@ export async function readTerminalGuard(
|
|
|
163
191
|
)
|
|
164
192
|
if (!validateReducerValue('terminalGuard', result.value))
|
|
165
193
|
throw new Error('invalid terminalGuard value')
|
|
166
|
-
return result.value as { diagnostic?: string }
|
|
194
|
+
return { cursor: result.cursor, value: result.value as { diagnostic?: string } }
|
|
167
195
|
}
|
|
168
196
|
|
|
169
197
|
export async function readOpenTick(store: Reader, repo: string, run: string, historical = true) {
|
|
@@ -238,3 +266,14 @@ export async function readDispatcherRunFacts(
|
|
|
238
266
|
value: result.value as import('../kernel/read-facts').DispatcherRunFacts,
|
|
239
267
|
}
|
|
240
268
|
}
|
|
269
|
+
|
|
270
|
+
/** Narrow durable health read for each forge boundary. */
|
|
271
|
+
export async function readForgeHealth(store: Reader & Pick<BuildStore, 'getRepo'>, repo: string) {
|
|
272
|
+
if ((await store.getRepo(repo)) === null) return undefined
|
|
273
|
+
const result = await readValue<{ value?: import('../kernel/forge-health').ForgeDegradation }>(
|
|
274
|
+
store,
|
|
275
|
+
{ kind: 'repo', repo },
|
|
276
|
+
'forgeHealthValue',
|
|
277
|
+
)
|
|
278
|
+
return result.value.value
|
|
279
|
+
}
|