@defrex/autobuild 1.11.1 → 1.12.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 +177 -54
- package/docs/answering-blocked-builds.md +10 -2
- package/docs/architecture.md +66 -6
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +13 -11
- package/docs/dispatcher.md +1 -1
- package/docs/integration-tree.md +28 -16
- package/docs/operator-api.md +4 -4
- package/docs/operator-surfaces.md +35 -0
- package/docs/optimization-nodes.md +3 -2
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -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/dashboard/model.ts +81 -23
- package/packages/core/src/cli/dashboard/poll.ts +20 -31
- package/packages/core/src/cli/dashboard/render.ts +14 -37
- package/packages/core/src/cli/dashboard/row-text.ts +24 -7
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
- 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-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 +68 -5
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +5 -4
- package/packages/core/src/cli/main.ts +4 -2
- package/packages/core/src/cli/production-store.ts +102 -0
- package/packages/core/src/cli/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +28 -22
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +169 -40
- package/packages/core/src/cli/store-opening.ts +15 -58
- package/packages/core/src/cli/store-ref.ts +6 -1
- package/packages/core/src/config/schema.ts +1 -1
- 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 +11 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +1 -1
- 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 +9 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -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/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
- package/packages/core/src/kernel/engine.ts +2 -8
- package/packages/core/src/kernel/measurement.ts +24 -0
- package/packages/core/src/kernel/read-facts.ts +8 -370
- package/packages/core/src/kernel/reducer-registry.ts +40 -125
- package/packages/core/src/kernel/reducer-revisions.ts +3 -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 +57 -9
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- package/packages/core/src/operator/presentation.ts +13 -0
- package/packages/core/src/operator/query.ts +40 -39
- package/packages/core/src/operator/registry.ts +3 -3
- package/packages/core/src/ports/workspace/fake.ts +15 -3
- package/packages/core/src/processes/dispatcher.ts +232 -75
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- 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 +9 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +1437 -1349
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/released-clients.json +11 -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/index.ts +18 -16
- 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 +265 -4
- package/packages/core/src/testing/import-graph.ts +78 -0
- package/packages/core/src/testing/reduced-read-budget.ts +221 -22
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/skills/guide/SKILL.md +115 -44
- package/skills/guide/references/integration-tree.md +28 -16
- package/skills/guide/references/operator-api.md +4 -4
- package/skills/guide/references/optimization-nodes.md +3 -2
- package/skills/operate/SKILL.md +38 -20
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { CheckpointIntegrityError, REPOSITORY_TAIL_WINDOW } from './event-reads'
|
|
2
|
+
import { projectStoredEvents } from '../events/compatibility'
|
|
3
|
+
import { READ_CATALOG_IDENTITY } from '../events/catalog-identity'
|
|
4
|
+
/** Named JSON answers over persisted incremental state. The event log remains authoritative.
|
|
5
|
+
* This core never names the complete catalog: callers resolve a registration
|
|
6
|
+
* (`reducer-values.ts` over the registry, the local store through the selective
|
|
7
|
+
* index) and hand it to `resolveRegisteredValue`. */
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
import type { AbEvent } from '../events/catalog'
|
|
10
|
+
import type { RepositoryEvent } from '../events/repository'
|
|
11
|
+
import type { RegisteredReducer } from '../kernel/reducer-value-entry'
|
|
12
|
+
import type { IncrementalReducer } from '../kernel/incremental'
|
|
13
|
+
import {
|
|
14
|
+
REDUCER_VALUE_SNAPSHOT_PREFIX,
|
|
15
|
+
type ReducerSnapshot,
|
|
16
|
+
type SnapshotScope,
|
|
17
|
+
} from './snapshots'
|
|
18
|
+
|
|
19
|
+
export const reducerValueRequestSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
reducer: z.string().min(1).max(64),
|
|
22
|
+
args: z.record(z.string(), z.json()).optional(),
|
|
23
|
+
/** Read-time arguments: they shape a rollup's finished value without
|
|
24
|
+
* creating a key (SPEC §7.7). Named reducers reject them. */
|
|
25
|
+
read: z.record(z.string(), z.json()).optional(),
|
|
26
|
+
})
|
|
27
|
+
.strict()
|
|
28
|
+
export type ReducerValueRequest = z.infer<typeof reducerValueRequestSchema>
|
|
29
|
+
export type JsonValue = z.infer<ReturnType<typeof z.json>>
|
|
30
|
+
export interface ReducerValue {
|
|
31
|
+
catalogIdentity?: string
|
|
32
|
+
version: number
|
|
33
|
+
cursor: number
|
|
34
|
+
value: JsonValue
|
|
35
|
+
}
|
|
36
|
+
export const reducerValueSchema = z
|
|
37
|
+
.object({
|
|
38
|
+
version: z.number().int().positive(),
|
|
39
|
+
cursor: z.number().int().nonnegative(),
|
|
40
|
+
value: z.json(),
|
|
41
|
+
})
|
|
42
|
+
.strict()
|
|
43
|
+
|
|
44
|
+
export interface ValueCatalogEntry {
|
|
45
|
+
scope: SnapshotScope['kind']
|
|
46
|
+
args: z.ZodType
|
|
47
|
+
validate(state: unknown): boolean
|
|
48
|
+
adapt(events: readonly (AbEvent | RepositoryEvent)[]): readonly unknown[]
|
|
49
|
+
value(state: unknown): JsonValue
|
|
50
|
+
// biome-ignore lint/suspicious/noExplicitAny: heterogeneous executable catalog
|
|
51
|
+
create(args: any): IncrementalReducer<any, any, any>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function canonical(value: unknown): string {
|
|
55
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`
|
|
56
|
+
if (value !== null && typeof value === 'object')
|
|
57
|
+
return `{${Object.entries(value)
|
|
58
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
59
|
+
.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`)
|
|
60
|
+
.join(',')}}`
|
|
61
|
+
return JSON.stringify(value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Parse a value request; named reducers take no read-time arguments. */
|
|
65
|
+
export function parseValueRequest(input: ReducerValueRequest): ReducerValueRequest {
|
|
66
|
+
const request = reducerValueRequestSchema.parse(input)
|
|
67
|
+
if (request.read !== undefined)
|
|
68
|
+
throw new Error(`reducer "${request.reducer}" takes no read-time arguments`)
|
|
69
|
+
return request
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Validate a parsed request against its registration and derive its key. */
|
|
73
|
+
export function resolveRegisteredValue(
|
|
74
|
+
scope: SnapshotScope,
|
|
75
|
+
request: ReducerValueRequest,
|
|
76
|
+
registration: RegisteredReducer | undefined,
|
|
77
|
+
catalogIdentity = READ_CATALOG_IDENTITY,
|
|
78
|
+
) {
|
|
79
|
+
if (!registration) throw new Error(`unknown reducer "${request.reducer}"`)
|
|
80
|
+
const entry = registration.valueRead
|
|
81
|
+
if ('excluded' in entry)
|
|
82
|
+
throw new Error(`excluded reducer "${request.reducer}": ${entry.excluded}`)
|
|
83
|
+
if (entry.scope !== scope.kind) throw new Error(`wrong scope for reducer "${request.reducer}"`)
|
|
84
|
+
const args = entry.args.parse(request.args ?? {})
|
|
85
|
+
const reducer = entry.create(args)
|
|
86
|
+
const identity = canonical({
|
|
87
|
+
scope,
|
|
88
|
+
reducer: request.reducer,
|
|
89
|
+
version: reducer.version,
|
|
90
|
+
catalogIdentity,
|
|
91
|
+
args,
|
|
92
|
+
})
|
|
93
|
+
// v2 ignores checkpoints from the former client-writable key format.
|
|
94
|
+
const key = `${REDUCER_VALUE_SNAPSHOT_PREFIX}v2.${new Bun.CryptoHasher('sha256').update(identity).digest('hex').slice(0, 54)}`
|
|
95
|
+
return { name: request.reducer, reducer, identity, key, entry }
|
|
96
|
+
}
|
|
97
|
+
export type ResolvedReducerValue = ReturnType<typeof resolveRegisteredValue>
|
|
98
|
+
|
|
99
|
+
/** Raw cache reads and conditional repairs are private adapter operations: clients
|
|
100
|
+
* cannot submit a new accumulator through the value API. `token` identifies the
|
|
101
|
+
* exact row read, including malformed bytes that could not be decoded. */
|
|
102
|
+
export interface ValueCacheRow {
|
|
103
|
+
snapshot: ReducerSnapshot
|
|
104
|
+
token: string
|
|
105
|
+
}
|
|
106
|
+
export interface ReducerValueStorage {
|
|
107
|
+
checkpoints?: {
|
|
108
|
+
publish(key: string, snapshot: ReducerSnapshot, checkpoints: ReducerSnapshot[]): Promise<void>
|
|
109
|
+
coverage(key: string, cursor: number): Promise<boolean>
|
|
110
|
+
latest(key: string, through: number): Promise<ReducerSnapshot | null>
|
|
111
|
+
}
|
|
112
|
+
highWater(): Promise<number>
|
|
113
|
+
read(key: string): Promise<ValueCacheRow | null>
|
|
114
|
+
events(since: number, through: number): Promise<(AbEvent | RepositoryEvent)[]>
|
|
115
|
+
put(key: string, snapshot: ReducerSnapshot): Promise<boolean>
|
|
116
|
+
repair(key: string, observed: ValueCacheRow, snapshot: ReducerSnapshot): Promise<boolean>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Serve one resolved value: load its saved row, advance it over the delta
|
|
120
|
+
* since its cursor, and save the result. */
|
|
121
|
+
export async function readResolvedReducerValue(
|
|
122
|
+
resolved: ResolvedReducerValue,
|
|
123
|
+
storage: ReducerValueStorage,
|
|
124
|
+
): Promise<ReducerValue> {
|
|
125
|
+
const { reducer, identity, key, entry } = resolved
|
|
126
|
+
let boundary = await storage.highWater()
|
|
127
|
+
let row: ValueCacheRow | null = null
|
|
128
|
+
try {
|
|
129
|
+
row = await storage.read(key)
|
|
130
|
+
} catch {
|
|
131
|
+
if (storage.checkpoints) throw new CheckpointIntegrityError('unreadable canonical stream seed')
|
|
132
|
+
/* unreadable cache is a miss */
|
|
133
|
+
}
|
|
134
|
+
// A concurrent reader may have persisted beyond our first boundary. Only a
|
|
135
|
+
// fresh authoritative boundary can establish ahead-of-log poison.
|
|
136
|
+
if (row && row.snapshot.cursor > boundary) boundary = await storage.highWater()
|
|
137
|
+
let acc = reducer.initial()
|
|
138
|
+
let cursor = 0
|
|
139
|
+
let valid = false
|
|
140
|
+
if (row) {
|
|
141
|
+
const { snapshot } = row
|
|
142
|
+
const state = snapshot.state as { identity?: unknown; acc?: unknown } | null
|
|
143
|
+
try {
|
|
144
|
+
valid =
|
|
145
|
+
snapshot.version === reducer.version &&
|
|
146
|
+
Number.isSafeInteger(snapshot.cursor) &&
|
|
147
|
+
snapshot.cursor >= 0 &&
|
|
148
|
+
snapshot.cursor <= boundary &&
|
|
149
|
+
state !== null &&
|
|
150
|
+
typeof state === 'object' &&
|
|
151
|
+
state.identity === identity &&
|
|
152
|
+
entry.validate(state.acc)
|
|
153
|
+
} catch {
|
|
154
|
+
valid = false // malformed nested cache data must never prevent replay
|
|
155
|
+
}
|
|
156
|
+
if (valid) {
|
|
157
|
+
acc = structuredClone(state!.acc)
|
|
158
|
+
cursor = snapshot.cursor
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (storage.checkpoints && row && !valid)
|
|
162
|
+
throw new CheckpointIntegrityError('corrupt canonical stream seed')
|
|
163
|
+
let recovering = false
|
|
164
|
+
if (storage.checkpoints && valid && !(await storage.checkpoints.coverage(key, cursor))) {
|
|
165
|
+
// A pre-checkpoint server may advance the shared canonical row during a
|
|
166
|
+
// rolling deploy or rollback. Its accumulator cannot supply the missing
|
|
167
|
+
// intermediate seeds. Refold only the uncovered suffix under the seed lock.
|
|
168
|
+
const checkpoint = await storage.checkpoints.latest(key, cursor)
|
|
169
|
+
if (checkpoint) {
|
|
170
|
+
const state = checkpoint.state as { identity?: unknown; acc?: unknown } | null
|
|
171
|
+
if (
|
|
172
|
+
checkpoint.version !== reducer.version ||
|
|
173
|
+
!Number.isSafeInteger(checkpoint.cursor) ||
|
|
174
|
+
checkpoint.cursor < 0 ||
|
|
175
|
+
checkpoint.cursor > cursor ||
|
|
176
|
+
state?.identity !== identity ||
|
|
177
|
+
!entry.validate(state.acc)
|
|
178
|
+
)
|
|
179
|
+
throw new CheckpointIntegrityError('corrupt recovery stream-seed checkpoint')
|
|
180
|
+
acc = structuredClone(state.acc)
|
|
181
|
+
cursor = checkpoint.cursor
|
|
182
|
+
} else {
|
|
183
|
+
// Initial legacy adoption with no checkpoint to resume from.
|
|
184
|
+
acc = reducer.initial()
|
|
185
|
+
cursor = 0
|
|
186
|
+
}
|
|
187
|
+
recovering = true
|
|
188
|
+
}
|
|
189
|
+
const start = cursor
|
|
190
|
+
const delta = (await storage.events(cursor, boundary)).filter((event) => event.seq <= boundary)
|
|
191
|
+
for (const event of delta) {
|
|
192
|
+
if (event.seq !== cursor + 1) throw new Error('noncontiguous reducer log')
|
|
193
|
+
cursor = event.seq
|
|
194
|
+
}
|
|
195
|
+
if (cursor !== boundary) throw new Error('incomplete reducer log')
|
|
196
|
+
const checkpoints: ReducerSnapshot[] = []
|
|
197
|
+
if (storage.checkpoints) {
|
|
198
|
+
const oldest = Math.max(0, boundary - REPOSITORY_TAIL_WINDOW)
|
|
199
|
+
const prefix = delta.filter((event) => event.seq <= oldest)
|
|
200
|
+
acc = reducer.advance(acc, entry.adapt(projectStoredEvents(prefix)))
|
|
201
|
+
if (start <= oldest)
|
|
202
|
+
checkpoints.push({
|
|
203
|
+
version: reducer.version,
|
|
204
|
+
cursor: oldest,
|
|
205
|
+
state: { identity, acc: structuredClone(acc) },
|
|
206
|
+
})
|
|
207
|
+
for (const event of delta) {
|
|
208
|
+
if (event.seq <= oldest) continue
|
|
209
|
+
acc = reducer.advance(acc, entry.adapt(projectStoredEvents([event])))
|
|
210
|
+
checkpoints.push({
|
|
211
|
+
version: reducer.version,
|
|
212
|
+
cursor: event.seq,
|
|
213
|
+
state: { identity, acc: structuredClone(acc) },
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
} else acc = reducer.advance(acc, entry.adapt(projectStoredEvents(delta)))
|
|
217
|
+
const value = entry.value(reducer.finish(acc))
|
|
218
|
+
if (!valid || recovering || delta.length > 0) {
|
|
219
|
+
const next = { version: reducer.version, cursor, state: { identity, acc } }
|
|
220
|
+
if (storage.checkpoints) {
|
|
221
|
+
await storage.checkpoints.publish(key, next, checkpoints)
|
|
222
|
+
return { version: reducer.version, cursor, value, catalogIdentity: READ_CATALOG_IDENTITY }
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
if (row && !valid && row.snapshot.version === reducer.version)
|
|
226
|
+
await storage.repair(key, row, next)
|
|
227
|
+
else if (row && !valid && row.snapshot.version !== reducer.version) {
|
|
228
|
+
/* foreign cache is read-only */
|
|
229
|
+
} else await storage.put(key, next)
|
|
230
|
+
} catch {
|
|
231
|
+
/* best-effort cache; log and reduction errors propagate */
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return { version: reducer.version, cursor, value, catalogIdentity: READ_CATALOG_IDENTITY }
|
|
235
|
+
}
|