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