@defrex/autobuild 1.11.0 → 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 +186 -57
- package/docs/answering-blocked-builds.md +10 -2
- package/docs/architecture.md +76 -10
- package/docs/assets/headline-wide.png +0 -0
- package/docs/cli.md +1 -1
- package/docs/configuration.md +13 -11
- package/docs/dispatcher.md +5 -4
- package/docs/integration-tree.md +28 -16
- package/docs/operator-api.md +4 -4
- package/docs/operator-surfaces.md +38 -3
- 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/header.ts +10 -0
- package/packages/core/src/cli/dashboard/model.ts +81 -23
- package/packages/core/src/cli/dashboard/poll.ts +24 -34
- package/packages/core/src/cli/dashboard/render.ts +44 -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-frontend.ts +12 -3
- 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 +70 -9
- 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 +36 -28
- 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 +74 -30
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -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/dispatch-status.ts +139 -0
- 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 +9 -369
- package/packages/core/src/kernel/reducer-registry.ts +40 -125
- package/packages/core/src/kernel/reducer-revisions.ts +5 -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 +47 -41
- 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 +3796 -3670
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -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 +20 -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-journals.ts +117 -0
- 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/packages/core/src/web/repository-source.ts +6 -2
- package/skills/guide/SKILL.md +126 -47
- 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
|
@@ -192,6 +192,145 @@ export function dispatchStatusReducer(
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/** Shared current reads retain a fixed recent window of dispatcher runs. It
|
|
196
|
+
* bounds `recentRuns` in repository read facts and the pending runs the
|
|
197
|
+
* reported dispatch status tracks. Historical holder correlations outside it
|
|
198
|
+
* use the explicitly parameterized cache. */
|
|
199
|
+
export const RECENT_DISPATCH_RUN_LIMIT = 16
|
|
200
|
+
|
|
201
|
+
/** A started, unstopped run other than the reported one, folded from its own
|
|
202
|
+
* `dispatcher.run-started` onward. `started` is that start's seq. */
|
|
203
|
+
export interface PendingDispatchRun {
|
|
204
|
+
started: number
|
|
205
|
+
status: DispatchStatus
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Which dispatcher run the repository's reduced status describes. */
|
|
209
|
+
export interface ReportedDispatch {
|
|
210
|
+
run?: string
|
|
211
|
+
status: DispatchStatus
|
|
212
|
+
/** Whether the reported run has recorded a tick boundary. */
|
|
213
|
+
ticked: boolean
|
|
214
|
+
/** Seq of the reported run's latest retained start; 0 when never seen. */
|
|
215
|
+
started: number
|
|
216
|
+
/** Sorted ascending by `started`, at most `RECENT_DISPATCH_RUN_LIMIT`. */
|
|
217
|
+
pending: PendingDispatchRun[]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function initialReportedDispatch(): ReportedDispatch {
|
|
221
|
+
return {
|
|
222
|
+
status: dispatchStatusReducer('initial').initial(),
|
|
223
|
+
ticked: false,
|
|
224
|
+
started: 0,
|
|
225
|
+
pending: [],
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function stopped(status: Readonly<DispatchStatus>): boolean {
|
|
230
|
+
return status.health === 'stopped' || status.health === 'failed'
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function tickBoundary(event: RepositoryEvent): boolean {
|
|
234
|
+
return (
|
|
235
|
+
event.type === 'dispatcher.tick-started' ||
|
|
236
|
+
event.type === 'dispatcher.tick-completed' ||
|
|
237
|
+
event.type === 'dispatcher.tick-failed'
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Insert in start order, then evict the oldest starts beyond the bound. */
|
|
242
|
+
function retain(state: ReportedDispatch, entry: PendingDispatchRun): void {
|
|
243
|
+
let index = state.pending.length
|
|
244
|
+
while (index > 0 && state.pending[index - 1]!.started > entry.started) index--
|
|
245
|
+
state.pending.splice(index, 0, entry)
|
|
246
|
+
while (state.pending.length > RECENT_DISPATCH_RUN_LIMIT) state.pending.shift()
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Move the reported run aside (while it is live) and report `status`. */
|
|
250
|
+
function report(
|
|
251
|
+
state: ReportedDispatch,
|
|
252
|
+
status: DispatchStatus,
|
|
253
|
+
started: number,
|
|
254
|
+
ticked: boolean,
|
|
255
|
+
): void {
|
|
256
|
+
if (state.run !== undefined && !stopped(state.status))
|
|
257
|
+
retain(state, { started: state.started, status: state.status })
|
|
258
|
+
state.run = status.run
|
|
259
|
+
state.status = status
|
|
260
|
+
state.started = started
|
|
261
|
+
state.ticked = ticked
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Fold one repository event into the reported dispatcher run, in place.
|
|
265
|
+
*
|
|
266
|
+
* The reported run is the one that holds repository authority, or held it
|
|
267
|
+
* most recently, as far as the journal shows: a run that has recorded a tick
|
|
268
|
+
* boundary (`tick-started`, `tick-completed`, `tick-failed`). A run that
|
|
269
|
+
* starts while a ticked, live run is reported waits in `pending` and only
|
|
270
|
+
* displaces it by recording its own tick boundary, so a newcomer that yields
|
|
271
|
+
* and stops never touches the holder's status. When the reported run has
|
|
272
|
+
* stopped or has not ticked yet, a new start is reported at once, as is any
|
|
273
|
+
* start when no run is reported. A tick boundary from a run whose start is
|
|
274
|
+
* no longer retained promotes it too, carrying the last known effective
|
|
275
|
+
* config until the run records its own. Other events from unknown runs are
|
|
276
|
+
* ignored; a run's stop is its last event, so a stopped pending run is
|
|
277
|
+
* dropped rather than remembered.
|
|
278
|
+
*
|
|
279
|
+
* Pending holds at most `RECENT_DISPATCH_RUN_LIMIT` runs, the most recently
|
|
280
|
+
* started, so the state is bounded independent of journal length.
|
|
281
|
+
*
|
|
282
|
+
* `repositoryReadFacts` persists this state: changing this fold or its shape
|
|
283
|
+
* requires a `repositoryReadFacts` reducer revision. */
|
|
284
|
+
export function foldReportedDispatch(state: ReportedDispatch, event: RepositoryEvent): void {
|
|
285
|
+
const run = (event.payload as { run?: unknown }).run
|
|
286
|
+
if (typeof run !== 'string') return
|
|
287
|
+
if (event.type === 'dispatcher.run-started') {
|
|
288
|
+
const fresh = reduceDispatchStatus([event], run)
|
|
289
|
+
if (state.run === run) {
|
|
290
|
+
state.status = fresh
|
|
291
|
+
state.started = event.seq
|
|
292
|
+
state.ticked = false
|
|
293
|
+
return
|
|
294
|
+
}
|
|
295
|
+
const index = state.pending.findIndex((entry) => entry.status.run === run)
|
|
296
|
+
if (index !== -1) state.pending.splice(index, 1)
|
|
297
|
+
if (state.run === undefined || stopped(state.status) || !state.ticked)
|
|
298
|
+
report(state, fresh, event.seq, false)
|
|
299
|
+
else retain(state, { started: event.seq, status: fresh })
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
if (state.run === run) {
|
|
303
|
+
state.status = reduceDispatchStatus([event], run, state.status)
|
|
304
|
+
if (tickBoundary(event)) state.ticked = true
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
const index = state.pending.findIndex((entry) => entry.status.run === run)
|
|
308
|
+
if (index !== -1) {
|
|
309
|
+
const entry = state.pending[index]!
|
|
310
|
+
if (tickBoundary(event)) {
|
|
311
|
+
state.pending.splice(index, 1)
|
|
312
|
+
report(state, reduceDispatchStatus([event], run, entry.status), entry.started, true)
|
|
313
|
+
} else if (event.type === 'dispatcher.run-stopped') {
|
|
314
|
+
state.pending.splice(index, 1)
|
|
315
|
+
} else {
|
|
316
|
+
entry.status = reduceDispatchStatus([event], run, entry.status)
|
|
317
|
+
}
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
if (!tickBoundary(event)) return
|
|
321
|
+
const seed: DispatchStatus = {
|
|
322
|
+
run,
|
|
323
|
+
health: 'running',
|
|
324
|
+
...(state.status.effectiveConfig !== undefined
|
|
325
|
+
? { effectiveConfig: state.status.effectiveConfig }
|
|
326
|
+
: {}),
|
|
327
|
+
roleWarnings: [],
|
|
328
|
+
diagnostics: [],
|
|
329
|
+
lastSeq: 0,
|
|
330
|
+
}
|
|
331
|
+
report(state, reduceDispatchStatus([event], run, seed), 0, true)
|
|
332
|
+
}
|
|
333
|
+
|
|
195
334
|
export function forgeReadinessWarnings(status: Readonly<DispatchStatus>): string[] {
|
|
196
335
|
return (status.forgeReadinessFailures ?? []).map(formatReadinessFailure)
|
|
197
336
|
}
|
|
@@ -5,7 +5,7 @@ import { verifyMemberKey } from './verify-stage-state'
|
|
|
5
5
|
import { mixedVersionDeferred } from './mixed-version'
|
|
6
6
|
import { integrationCurrent, integrationConfig, integrationFailed } from './integration-state'
|
|
7
7
|
import { proposeRunDue, proposeStarted } from './optimization'
|
|
8
|
-
import { reopenSpecPending } from './reopen-state'
|
|
8
|
+
import { reopenSpecPending, reviseSpecPending } from './reopen-state'
|
|
9
9
|
/**
|
|
10
10
|
* The kernel pipeline engine (SPEC §8): "read the event log, decide the next
|
|
11
11
|
* phase per the transition table, invoke the AgentRunner with `/{skill}
|
|
@@ -501,13 +501,7 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
501
501
|
// below. guidance and dismiss-finding resolutions do not decide anything
|
|
502
502
|
// here — they route inside the loop rules (feedback priority and stall
|
|
503
503
|
// suppression respectively).
|
|
504
|
-
if (
|
|
505
|
-
state.answeredEscalations.some(
|
|
506
|
-
(e) => e.resolution === 'revise-spec' && e.answeredSeq > log.restartSeq,
|
|
507
|
-
)
|
|
508
|
-
) {
|
|
509
|
-
return { kind: 'wait', reason: 'awaiting-spec' }
|
|
510
|
-
}
|
|
504
|
+
if (reviseSpecPending(state)) return { kind: 'wait', reason: 'awaiting-spec' }
|
|
511
505
|
|
|
512
506
|
// ── 4. Spec (§6.3: dispatch owns the import; `spec` is not a phase §5) ─────
|
|
513
507
|
if (state.specRev === undefined) return { kind: 'wait', reason: 'awaiting-spec' }
|
|
@@ -389,6 +389,30 @@ export function nodeMeasurementDue(state: BuildState): boolean {
|
|
|
389
389
|
return baselineMeasurementDue(state) || progressMeasurementDue(state) !== undefined
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
/** The key of the node measurement owed now, starting or progress, for slot
|
|
393
|
+
* accounting (SPEC §12 "What holds a slot"): `measure:baseline:<revision>:<pin>`
|
|
394
|
+
* or `measure:progress:<head>`. Unlike `nodeMeasurementDue` it is not gated
|
|
395
|
+
* on a pause or pending commands, so an admitted measurement keeps its slot
|
|
396
|
+
* until its runner acknowledges a requested pause or abort. Read from
|
|
397
|
+
* reduced state alone. */
|
|
398
|
+
export function nodeMeasurementNeed(state: BuildState): string | undefined {
|
|
399
|
+
const optimization = state.optimization
|
|
400
|
+
if (
|
|
401
|
+
state.kind !== 'node' ||
|
|
402
|
+
state.nodeOpened === undefined ||
|
|
403
|
+
optimization === undefined ||
|
|
404
|
+
terminal(state)
|
|
405
|
+
)
|
|
406
|
+
return undefined
|
|
407
|
+
if (optimization.starting === undefined)
|
|
408
|
+
return optimization.stopped === undefined
|
|
409
|
+
? `measure:baseline:${optimization.revision}:${optimization.accepted.harnessPin}`
|
|
410
|
+
: undefined
|
|
411
|
+
const head = optimization.progressQueue?.[0]
|
|
412
|
+
if (optimization.objective.metric.kind !== 'panel' || head === undefined) return undefined
|
|
413
|
+
return `measure:progress:${head}`
|
|
414
|
+
}
|
|
415
|
+
|
|
392
416
|
/** The deterministic id of the escalation a failed node panel raises. */
|
|
393
417
|
export function nodePanelEscalationId(panelId: string): string {
|
|
394
418
|
return `node-panel-failed-${panelId}`
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { ticketPreparationReducer } from './ticket-preparation'
|
|
2
|
-
import { ticketHandbacksReducer } from './ticket-handbacks'
|
|
3
|
-
import { ticketStartsReducer } from './ticket-starts'
|
|
4
1
|
import { ticketMigrationsReducer } from './ticket-migrations'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
advanceCompatibility,
|
|
8
|
-
initialCompatibility,
|
|
9
|
-
projectEvents,
|
|
10
|
-
type CompatibilityState,
|
|
11
|
-
} from '../events/compatibility'
|
|
2
|
+
import { projectEvents } from '../events/compatibility'
|
|
12
3
|
import { awaitsConsent } from './landing-readiness'
|
|
13
4
|
import { leafRestackReducer, type LeafRestackState } from './leaf-restack-state'
|
|
14
5
|
import { landingCandidateId } from './landing-policy'
|
|
@@ -621,362 +612,11 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
621
612
|
}),
|
|
622
613
|
})
|
|
623
614
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
import { autoMergeDefaultReducer } from './auto-merge-default'
|
|
633
|
-
import { effectiveConfigReducer } from './service-facts'
|
|
634
|
-
import { sandboxStatesReducer } from '../processes/sandbox-state'
|
|
635
|
-
import { openHarvestExecutionsReducer } from '../processes/harvest-execution-state'
|
|
636
|
-
import { dispatchStatusReducer } from './dispatch-status'
|
|
637
|
-
|
|
638
|
-
/** Shared current reads retain a fixed recent window. Historical holder
|
|
639
|
-
* correlations outside it use the explicitly parameterized cache. */
|
|
640
|
-
export const RECENT_DISPATCH_RUN_LIMIT = 16
|
|
641
|
-
export interface RepositoryReadAcc {
|
|
642
|
-
missingAccounts: Record<string, import('../accounts/availability').MissingAccountCredential>
|
|
643
|
-
preparation: ReturnType<typeof ticketPreparationReducer.initial>
|
|
644
|
-
handbacks: ReturnType<typeof ticketHandbacksReducer.initial>
|
|
645
|
-
ticketStarts: ReturnType<typeof ticketStartsReducer.initial>
|
|
646
|
-
compatibility: CompatibilityState
|
|
647
|
-
presence: Record<
|
|
648
|
-
string,
|
|
649
|
-
Extract<RepositoryEvent, { type: 'change-presence.observed' }>['payload']
|
|
650
|
-
>
|
|
651
|
-
|
|
652
|
-
upgrades: ReturnType<typeof dispatchUpgradeReducer.initial>
|
|
653
|
-
openHarvest: ReturnType<typeof openHarvestExecutionsReducer.initial>
|
|
654
|
-
attention: ReturnType<typeof repositoryAttentionReducer.initial>
|
|
655
|
-
harvestFailures: Record<
|
|
656
|
-
string,
|
|
657
|
-
{ count: number; latest: Extract<RepositoryEvent, { type: 'harvest.failed' }> }
|
|
658
|
-
>
|
|
659
|
-
harvestTerminals: Record<
|
|
660
|
-
string,
|
|
661
|
-
Extract<RepositoryEvent, { type: 'harvest.proposals.submitted' | 'harvest.review.verdict' }>
|
|
662
|
-
>
|
|
663
|
-
harvestVerdicts: Record<
|
|
664
|
-
string,
|
|
665
|
-
{
|
|
666
|
-
first: Extract<RepositoryEvent, { type: 'harvest.review.verdict' }>
|
|
667
|
-
latest: Extract<RepositoryEvent, { type: 'harvest.review.verdict' }>
|
|
668
|
-
}
|
|
669
|
-
>
|
|
670
|
-
harvestAuthorizations: Record<
|
|
671
|
-
string,
|
|
672
|
-
Extract<RepositoryEvent, { type: 'harvest.execution.authorized' }>
|
|
673
|
-
>
|
|
674
|
-
harvestExecutionStarts: Record<string, string>
|
|
675
|
-
latestHarvestResumedSeq: number
|
|
676
|
-
harvestSessionEndings: Record<string, number>
|
|
677
|
-
harvestSessions: (import('../cli/harvest').HarvestSessionStatusView & { run: string })[]
|
|
678
|
-
pendingHumanResume?: number
|
|
679
|
-
dismissedThrough: number
|
|
680
|
-
failedAt: Record<string, string>
|
|
681
|
-
settings: ReturnType<typeof dispatchSettingsReducer.initial>
|
|
682
|
-
harvest: ReturnType<typeof harvestReducer.initial>
|
|
683
|
-
forgeHealth: ReturnType<typeof forgeHealthReducer.initial>
|
|
684
|
-
forgeCredentialLimits: ReturnType<typeof forgeCredentialLimitsReducer.initial>
|
|
685
|
-
kernelGit: ReturnType<typeof kernelGitHealthReducer.initial>
|
|
686
|
-
openPrBackpressure: ReturnType<typeof openPrBackpressureReducer.initial>
|
|
687
|
-
ticketMigrations: ReturnType<typeof ticketMigrationsReducer.initial>
|
|
688
|
-
health: ReturnType<typeof ticketSourceHealthReducer.initial>
|
|
689
|
-
autoMerge: ReturnType<typeof autoMergeDefaultReducer.initial>
|
|
690
|
-
config: ReturnType<typeof effectiveConfigReducer.initial>
|
|
691
|
-
sandboxes: ReturnType<typeof sandboxStatesReducer.initial>
|
|
692
|
-
status: ReturnType<ReturnType<typeof dispatchStatusReducer>['initial']>
|
|
693
|
-
run?: string
|
|
694
|
-
scanSeq?: number
|
|
695
|
-
scan?: Extract<RepositoryEvent, { type: 'dispatcher.ticket-scan-completed' }>['payload']
|
|
696
|
-
recentRuns: [string, DispatcherRunFacts][]
|
|
697
|
-
latestRun?: string
|
|
698
|
-
latestStoppedRun?: string
|
|
699
|
-
publications: Extract<RepositoryEvent, { type: 'orchestrator.sandbox.published' }>[]
|
|
700
|
-
}
|
|
701
|
-
export const repositoryReadFactsReducer = defineReducer({
|
|
702
|
-
rawEvents: true,
|
|
703
|
-
identity: 'repositoryReadFacts',
|
|
704
|
-
parts: [
|
|
705
|
-
ticketMigrationsReducer,
|
|
706
|
-
dispatchUpgradeReducer,
|
|
707
|
-
ticketPreparationReducer,
|
|
708
|
-
ticketHandbacksReducer,
|
|
709
|
-
ticketStartsReducer,
|
|
710
|
-
dispatcherRunFactsReducer('version'),
|
|
711
|
-
openHarvestExecutionsReducer,
|
|
712
|
-
forgeHealthReducer,
|
|
713
|
-
forgeCredentialLimitsReducer,
|
|
714
|
-
kernelGitHealthReducer,
|
|
715
|
-
openPrBackpressureReducer,
|
|
716
|
-
repositoryAttentionReducer,
|
|
717
|
-
dispatchSettingsReducer,
|
|
718
|
-
harvestReducer,
|
|
719
|
-
ticketSourceHealthReducer,
|
|
720
|
-
autoMergeDefaultReducer,
|
|
721
|
-
effectiveConfigReducer,
|
|
722
|
-
sandboxStatesReducer,
|
|
723
|
-
dispatchStatusReducer('version'),
|
|
724
|
-
],
|
|
725
|
-
initial: (): RepositoryReadAcc => ({
|
|
726
|
-
missingAccounts: {},
|
|
727
|
-
compatibility: initialCompatibility(),
|
|
728
|
-
presence: {},
|
|
729
|
-
preparation: ticketPreparationReducer.initial(),
|
|
730
|
-
handbacks: ticketHandbacksReducer.initial(),
|
|
731
|
-
ticketStarts: ticketStartsReducer.initial(),
|
|
732
|
-
upgrades: dispatchUpgradeReducer.initial(),
|
|
733
|
-
recentRuns: [],
|
|
734
|
-
openHarvest: openHarvestExecutionsReducer.initial(),
|
|
735
|
-
attention: repositoryAttentionReducer.initial(),
|
|
736
|
-
dismissedThrough: 0,
|
|
737
|
-
failedAt: {},
|
|
738
|
-
harvestSessions: [],
|
|
739
|
-
harvestSessionEndings: {},
|
|
740
|
-
harvestFailures: {},
|
|
741
|
-
harvestTerminals: {},
|
|
742
|
-
harvestVerdicts: {},
|
|
743
|
-
harvestAuthorizations: {},
|
|
744
|
-
latestHarvestResumedSeq: 0,
|
|
745
|
-
harvestExecutionStarts: {},
|
|
746
|
-
settings: dispatchSettingsReducer.initial(),
|
|
747
|
-
harvest: harvestReducer.initial(),
|
|
748
|
-
forgeHealth: forgeHealthReducer.initial(),
|
|
749
|
-
forgeCredentialLimits: forgeCredentialLimitsReducer.initial(),
|
|
750
|
-
kernelGit: kernelGitHealthReducer.initial(),
|
|
751
|
-
openPrBackpressure: openPrBackpressureReducer.initial(),
|
|
752
|
-
ticketMigrations: ticketMigrationsReducer.initial(),
|
|
753
|
-
health: ticketSourceHealthReducer.initial(),
|
|
754
|
-
autoMerge: autoMergeDefaultReducer.initial(),
|
|
755
|
-
config: effectiveConfigReducer.initial(),
|
|
756
|
-
sandboxes: sandboxStatesReducer.initial(),
|
|
757
|
-
status: dispatchStatusReducer('initial').initial(),
|
|
758
|
-
publications: [],
|
|
759
|
-
}),
|
|
760
|
-
fold(acc: RepositoryReadAcc, events: readonly RepositoryEvent[]) {
|
|
761
|
-
acc.preparation = ticketPreparationReducer.advance(acc.preparation, events)
|
|
762
|
-
acc.handbacks = ticketHandbacksReducer.advance(acc.handbacks, events)
|
|
763
|
-
acc.ticketStarts = ticketStartsReducer.advance(acc.ticketStarts, events)
|
|
764
|
-
advanceCompatibility(acc.compatibility, events)
|
|
765
|
-
acc.upgrades = dispatchUpgradeReducer.advance(acc.upgrades, events)
|
|
766
|
-
acc.attention = repositoryAttentionReducer.advance(acc.attention, events)
|
|
767
|
-
acc.openHarvest = openHarvestExecutionsReducer.advance(acc.openHarvest, events)
|
|
768
|
-
acc.settings = dispatchSettingsReducer.advance(acc.settings, events)
|
|
769
|
-
acc.harvest = harvestReducer.advance(acc.harvest, events)
|
|
770
|
-
acc.forgeHealth = forgeHealthReducer.advance(acc.forgeHealth, events)
|
|
771
|
-
acc.forgeCredentialLimits = forgeCredentialLimitsReducer.advance(
|
|
772
|
-
acc.forgeCredentialLimits,
|
|
773
|
-
events,
|
|
774
|
-
)
|
|
775
|
-
acc.kernelGit = kernelGitHealthReducer.advance(acc.kernelGit, events)
|
|
776
|
-
acc.openPrBackpressure = openPrBackpressureReducer.advance(acc.openPrBackpressure, events)
|
|
777
|
-
acc.ticketMigrations = ticketMigrationsReducer.advance(acc.ticketMigrations, events)
|
|
778
|
-
acc.health = ticketSourceHealthReducer.advance(acc.health, events)
|
|
779
|
-
acc.autoMerge = autoMergeDefaultReducer.advance(acc.autoMerge, events)
|
|
780
|
-
acc.config = effectiveConfigReducer.advance(acc.config, events)
|
|
781
|
-
acc.sandboxes = sandboxStatesReducer.advance(acc.sandboxes, events)
|
|
782
|
-
for (const event of projectEvents(events)) {
|
|
783
|
-
if (event.type === 'account.credentials-unavailable')
|
|
784
|
-
acc.missingAccounts[event.payload.name] = event.payload
|
|
785
|
-
if (event.type === 'account.credentials-recovered')
|
|
786
|
-
delete acc.missingAccounts[event.payload.name]
|
|
787
|
-
if (event.type === 'change-presence.observed')
|
|
788
|
-
acc.presence[event.payload.destination] = event.payload
|
|
789
|
-
if (event.type === 'harvest.failed') {
|
|
790
|
-
const key = JSON.stringify([event.payload.run, event.payload.step, event.payload.round])
|
|
791
|
-
acc.harvestFailures[key] = {
|
|
792
|
-
count: (acc.harvestFailures[key]?.count ?? 0) + 1,
|
|
793
|
-
latest: event,
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
if (
|
|
797
|
-
(event.type === 'harvest.proposals.submitted' || event.type === 'harvest.review.verdict') &&
|
|
798
|
-
event.actor.kind === 'agent'
|
|
799
|
-
)
|
|
800
|
-
acc.harvestTerminals[event.actor.session] = event
|
|
801
|
-
if (event.type === 'harvest.review.verdict') {
|
|
802
|
-
const key = JSON.stringify([event.payload.run, event.payload.round])
|
|
803
|
-
acc.harvestVerdicts[key] = {
|
|
804
|
-
first: acc.harvestVerdicts[key]?.first ?? event,
|
|
805
|
-
latest: event,
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
if (event.type === 'harvest.execution.started')
|
|
809
|
-
acc.harvestExecutionStarts[String(event.seq)] = event.payload.execution
|
|
810
|
-
if (event.type === 'harvest.execution.authorized')
|
|
811
|
-
acc.harvestAuthorizations[JSON.stringify(event.payload.execution)] ??= event
|
|
812
|
-
if (event.type === 'harvest.resumed') acc.latestHarvestResumedSeq = event.seq
|
|
813
|
-
if (event.type === 'harvest.session.started' && event.payload.continuation) {
|
|
814
|
-
const prior = acc.harvestSessions.find(
|
|
815
|
-
(s) => s.session === event.payload.continuation!.predecessor,
|
|
816
|
-
)
|
|
817
|
-
if (prior) prior.status = 'ended'
|
|
818
|
-
}
|
|
819
|
-
if (event.type === 'harvest.session.started')
|
|
820
|
-
acc.harvestSessions.push({
|
|
821
|
-
run: event.payload.run,
|
|
822
|
-
session: event.payload.session,
|
|
823
|
-
role: event.payload.role,
|
|
824
|
-
step: event.payload.step,
|
|
825
|
-
round: event.payload.round,
|
|
826
|
-
status: 'open',
|
|
827
|
-
...(event.payload.continuation ? { continuation: event.payload.continuation } : {}),
|
|
828
|
-
...(event.payload.stream === undefined ? {} : { stream: event.payload.stream }),
|
|
829
|
-
streamStatus: event.payload.stream === undefined ? 'closed' : 'open',
|
|
830
|
-
})
|
|
831
|
-
if (event.type === 'harvest.session.ended' || event.type === 'harvest.session.suspended') {
|
|
832
|
-
acc.harvestSessionEndings[JSON.stringify(event.payload.session)] ??= event.seq
|
|
833
|
-
const session = acc.harvestSessions.findLast(
|
|
834
|
-
(session) => session.session === event.payload.session && session.status === 'open',
|
|
835
|
-
)
|
|
836
|
-
if (session) {
|
|
837
|
-
session.status = event.type === 'harvest.session.suspended' ? 'suspended' : 'ended'
|
|
838
|
-
session.transcript = event.payload.transcript
|
|
839
|
-
session.streamStatus = 'closed'
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
if (event.type === 'harvest.resume-requested' && event.actor.kind === 'human')
|
|
843
|
-
acc.pendingHumanResume = event.seq
|
|
844
|
-
if (event.type === 'harvest.pause-requested') delete acc.pendingHumanResume
|
|
845
|
-
if (event.type === 'harvest.resumed' && acc.pendingHumanResume !== undefined)
|
|
846
|
-
acc.dismissedThrough = Math.max(acc.dismissedThrough, acc.pendingHumanResume)
|
|
847
|
-
if (event.type === 'harvest.failed' && !event.payload.willRetry)
|
|
848
|
-
acc.failedAt[JSON.stringify(event.payload.run)] = event.ts
|
|
849
|
-
if (event.type === 'dispatcher.run-started') {
|
|
850
|
-
acc.run = event.payload.run
|
|
851
|
-
acc.status = dispatchStatusReducer(acc.run).initial()
|
|
852
|
-
}
|
|
853
|
-
if (acc.run) acc.status = dispatchStatusReducer(acc.run).advance(acc.status, [event])
|
|
854
|
-
if (event.type === 'dispatcher.ticket-scan-completed') {
|
|
855
|
-
acc.scan = event.payload
|
|
856
|
-
acc.scanSeq = event.seq
|
|
857
|
-
}
|
|
858
|
-
if (event.type === 'dispatcher.run-started') acc.latestRun = event.payload.run
|
|
859
|
-
if (event.type === 'dispatcher.run-stopped') acc.latestStoppedRun = event.payload.run
|
|
860
|
-
if (
|
|
861
|
-
event.type.startsWith('dispatcher.') &&
|
|
862
|
-
'run' in event.payload &&
|
|
863
|
-
typeof event.payload.run === 'string'
|
|
864
|
-
) {
|
|
865
|
-
const run = event.payload.run
|
|
866
|
-
let entry = acc.recentRuns.find(([id]) => id === run)
|
|
867
|
-
if (!entry) {
|
|
868
|
-
entry = [run, {}]
|
|
869
|
-
acc.recentRuns.push(entry)
|
|
870
|
-
}
|
|
871
|
-
foldDispatcherRunFact(entry[1], event)
|
|
872
|
-
while (acc.recentRuns.length > RECENT_DISPATCH_RUN_LIMIT) {
|
|
873
|
-
const index = acc.recentRuns.findIndex(
|
|
874
|
-
([id]) => id !== acc.latestRun && id !== acc.latestStoppedRun,
|
|
875
|
-
)
|
|
876
|
-
acc.recentRuns.splice(index, 1)
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
if (event.type === 'orchestrator.sandbox.published') {
|
|
880
|
-
acc.publications = acc.publications.filter(
|
|
881
|
-
(prior) =>
|
|
882
|
-
prior.payload.operator !== event.payload.operator ||
|
|
883
|
-
prior.payload.branch !== event.payload.branch,
|
|
884
|
-
)
|
|
885
|
-
acc.publications.push(event)
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
},
|
|
889
|
-
finish: (acc: RepositoryReadAcc) => ({
|
|
890
|
-
missingAccounts: structuredClone(acc.missingAccounts),
|
|
891
|
-
compatibility: structuredClone(acc.compatibility),
|
|
892
|
-
presence: structuredClone(acc.presence),
|
|
893
|
-
preparation: ticketPreparationReducer.finish(acc.preparation),
|
|
894
|
-
handbacks: ticketHandbacksReducer.finish(acc.handbacks),
|
|
895
|
-
ticketStarts: ticketStartsReducer.finish(acc.ticketStarts),
|
|
896
|
-
upgrades: dispatchUpgradeReducer.finish(acc.upgrades),
|
|
897
|
-
harvestFailures: structuredClone(acc.harvestFailures),
|
|
898
|
-
harvestTerminals: structuredClone(acc.harvestTerminals),
|
|
899
|
-
harvestVerdicts: structuredClone(acc.harvestVerdicts),
|
|
900
|
-
harvestAuthorizations: structuredClone(acc.harvestAuthorizations),
|
|
901
|
-
harvestExecutionStarts: { ...acc.harvestExecutionStarts },
|
|
902
|
-
latestHarvestResumedSeq: acc.latestHarvestResumedSeq,
|
|
903
|
-
harvestSessionEndings: { ...acc.harvestSessionEndings },
|
|
904
|
-
harvestSessions: structuredClone(acc.harvestSessions),
|
|
905
|
-
attention: repositoryAttentionReducer.finish(acc.attention),
|
|
906
|
-
dismissedThrough: acc.dismissedThrough,
|
|
907
|
-
failedAt: { ...acc.failedAt },
|
|
908
|
-
openHarvest: openHarvestExecutionsReducer.finish(acc.openHarvest),
|
|
909
|
-
settings: dispatchSettingsReducer.finish(acc.settings),
|
|
910
|
-
harvest: harvestReducer.finish(acc.harvest),
|
|
911
|
-
forgeHealth: forgeHealthReducer.finish(acc.forgeHealth),
|
|
912
|
-
forgeCredentialLimits: forgeCredentialLimitsReducer.finish(acc.forgeCredentialLimits),
|
|
913
|
-
kernelGit: kernelGitHealthReducer.finish(acc.kernelGit),
|
|
914
|
-
openPrBackpressure: openPrBackpressureReducer.finish(acc.openPrBackpressure),
|
|
915
|
-
ticketMigrations: ticketMigrationsReducer.finish(acc.ticketMigrations),
|
|
916
|
-
health: ticketSourceHealthReducer.finish(acc.health),
|
|
917
|
-
autoMerge: autoMergeDefaultReducer.finish(acc.autoMerge),
|
|
918
|
-
config: effectiveConfigReducer.finish(acc.config),
|
|
919
|
-
sandboxes: sandboxStatesReducer.finish(acc.sandboxes),
|
|
920
|
-
status: acc.run ? dispatchStatusReducer(acc.run).finish(acc.status) : undefined,
|
|
921
|
-
scan: acc.scan,
|
|
922
|
-
scanSeq: acc.scanSeq,
|
|
923
|
-
recentRuns: structuredClone(acc.recentRuns),
|
|
924
|
-
latestRun: acc.latestRun,
|
|
925
|
-
latestStoppedRun: acc.latestStoppedRun,
|
|
926
|
-
publications: structuredClone(acc.publications),
|
|
927
|
-
}),
|
|
928
|
-
})
|
|
929
|
-
|
|
930
|
-
import type { IncrementalReducer } from './incremental'
|
|
931
|
-
/** Companion for an optional finished answer: absence is represented by an
|
|
932
|
-
* omitted object field, never top-level undefined. */
|
|
933
|
-
export function optionalValue<A, E, V>(reducer: IncrementalReducer<A, E, V>) {
|
|
934
|
-
return {
|
|
935
|
-
...reducer,
|
|
936
|
-
finish: (acc: A) => ({ value: reducer.finish(acc) }),
|
|
937
|
-
reduce: (events: readonly E[]) => ({ value: reducer.reduce(events) }),
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
/** One run's correlation facts. History for unrelated runs never enters this value. */
|
|
942
|
-
export interface DispatcherRunFacts {
|
|
943
|
-
runtime?: RepositoryEvent
|
|
944
|
-
start?: RepositoryEvent
|
|
945
|
-
latestStart?: RepositoryEvent
|
|
946
|
-
stop?: RepositoryEvent
|
|
947
|
-
tick?: RepositoryEvent
|
|
948
|
-
completed?: RepositoryEvent
|
|
949
|
-
boundary?: 'dispatcher.tick-started' | 'dispatcher.tick-completed' | 'dispatcher.tick-failed'
|
|
950
|
-
stopRequest?: Extract<RepositoryEvent, { type: 'dispatcher.stop-requested' }>
|
|
951
|
-
}
|
|
952
|
-
export function dispatcherRunFactsReducer(run: string) {
|
|
953
|
-
return defineReducer<DispatcherRunFacts, RepositoryEvent, DispatcherRunFacts>({
|
|
954
|
-
identity: 'dispatcherRunFacts',
|
|
955
|
-
initial: () => ({}),
|
|
956
|
-
fold(acc, events) {
|
|
957
|
-
for (const event of projectEvents(events)) {
|
|
958
|
-
if (!('run' in event.payload) || event.payload.run !== run) continue
|
|
959
|
-
foldDispatcherRunFact(acc, event)
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
finish: (acc) => structuredClone(acc),
|
|
963
|
-
})
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
function foldDispatcherRunFact(acc: DispatcherRunFacts, event: RepositoryEvent): void {
|
|
967
|
-
if (event.type === 'dispatcher.run-started') {
|
|
968
|
-
acc.start ??= event
|
|
969
|
-
acc.latestStart = event
|
|
970
|
-
} else if (event.type === 'dispatcher.runtime-recorded') acc.runtime = event
|
|
971
|
-
else if (event.type === 'dispatcher.run-stopped') acc.stop = event
|
|
972
|
-
else if (event.type === 'dispatcher.stop-requested') acc.stopRequest ??= event
|
|
973
|
-
else if (
|
|
974
|
-
event.type === 'dispatcher.tick-started' ||
|
|
975
|
-
event.type === 'dispatcher.tick-completed' ||
|
|
976
|
-
event.type === 'dispatcher.tick-failed'
|
|
977
|
-
) {
|
|
978
|
-
acc.boundary = event.type
|
|
979
|
-
if (event.type !== 'dispatcher.tick-started') acc.tick = event
|
|
980
|
-
if (event.type === 'dispatcher.tick-completed') acc.completed = event
|
|
981
|
-
}
|
|
982
|
-
}
|
|
615
|
+
export {
|
|
616
|
+
RECENT_DISPATCH_RUN_LIMIT,
|
|
617
|
+
repositoryReadFactsReducer,
|
|
618
|
+
optionalValue,
|
|
619
|
+
dispatcherRunFactsReducer,
|
|
620
|
+
type RepositoryReadAcc,
|
|
621
|
+
type DispatcherRunFacts,
|
|
622
|
+
} from './repository-read-facts'
|