@defrex/autobuild 1.7.0 → 1.8.1
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 +316 -47
- package/docs/answering-blocked-builds.md +44 -3
- package/docs/architecture.md +62 -7
- package/docs/cli.md +1 -0
- package/docs/configuration-overview.md +1 -1
- package/docs/configuration.md +49 -9
- package/docs/dispatcher.md +1 -1
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +7 -4
- package/docs/merge-policy.md +78 -6
- package/docs/migration-1.0.md +4 -2
- package/docs/operating.md +3 -2
- package/docs/operator-api.md +26 -5
- package/docs/operator-surfaces.md +10 -0
- package/docs/plugin-authoring.md +1 -1
- package/docs/remote-store-protocol.md +9 -1
- package/docs/restacking.md +23 -4
- package/docs/ticket-dependencies.md +9 -4
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +1 -0
- package/packages/core/src/cli/build-control.ts +65 -7
- package/packages/core/src/cli/context.ts +55 -14
- package/packages/core/src/cli/dashboard/actions.ts +13 -4
- package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
- package/packages/core/src/cli/dashboard/model.ts +61 -8
- package/packages/core/src/cli/dashboard/render.ts +28 -3
- package/packages/core/src/cli/dashboard/tree.ts +9 -1
- package/packages/core/src/cli/help.ts +69 -7
- package/packages/core/src/cli/landings.ts +1 -1
- package/packages/core/src/cli/main.ts +60 -9
- package/packages/core/src/cli/publication-settlement.ts +10 -0
- package/packages/core/src/cli/status.ts +178 -12
- package/packages/core/src/cli/terminals.ts +197 -4
- package/packages/core/src/cli/wait.ts +1 -0
- package/packages/core/src/cli/watch.ts +71 -0
- package/packages/core/src/config/landing.ts +12 -0
- package/packages/core/src/config/path-selectors.ts +68 -0
- package/packages/core/src/config/schema.ts +40 -58
- package/packages/core/src/events/catalog.ts +17 -3
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/head-paths-limits.ts +25 -0
- package/packages/core/src/events/payloads.ts +315 -20
- package/packages/core/src/events/policy.ts +21 -0
- package/packages/core/src/events/repository.ts +30 -1
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +247 -6
- package/packages/core/src/kernel/consent-revocation.ts +72 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
- package/packages/core/src/kernel/engine.ts +48 -8
- package/packages/core/src/kernel/head-paths-state.ts +63 -0
- package/packages/core/src/kernel/head-paths.ts +401 -0
- package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
- package/packages/core/src/kernel/landing-policy.ts +55 -2
- package/packages/core/src/kernel/landing-readiness.ts +104 -9
- package/packages/core/src/kernel/landing-state.ts +44 -4
- package/packages/core/src/kernel/leaf-restack-base.ts +34 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +22 -2
- package/packages/core/src/kernel/log-index.ts +27 -1
- package/packages/core/src/kernel/node-polling.ts +13 -3
- package/packages/core/src/kernel/node-restack-state.ts +8 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
- package/packages/core/src/kernel/read-deferrals.ts +3 -1
- package/packages/core/src/kernel/read-facts.ts +28 -1
- package/packages/core/src/kernel/reducer-registry.ts +22 -1
- package/packages/core/src/kernel/reducer.ts +316 -17
- package/packages/core/src/kernel/target-observation.ts +2 -5
- package/packages/core/src/kernel/terminal-guard.ts +52 -3
- package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
- package/packages/core/src/kernel/ticket-preparation.ts +12 -1
- package/packages/core/src/kernel/ticket-wait.ts +345 -0
- package/packages/core/src/kernel/verify-applicability.ts +9 -19
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +3 -0
- package/packages/core/src/operator/protocol.ts +15 -2
- package/packages/core/src/operator/registry.ts +97 -5
- package/packages/core/src/operator/repository-events.ts +67 -0
- package/packages/core/src/ports/tickets/fake.ts +5 -0
- package/packages/core/src/ports/types.ts +3 -2
- package/packages/core/src/processes/build-execution-state.ts +30 -1
- package/packages/core/src/processes/build-runner.ts +150 -18
- package/packages/core/src/processes/dispatcher.ts +739 -97
- package/packages/core/src/processes/execution-no-progress.ts +22 -2
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/publication-state.ts +6 -1
- package/packages/core/src/store/digest.ts +41 -2
- package/packages/core/src/store/reduced-reads.ts +4 -1
- package/packages/core/src/store/reducer-value-shapes.json +10108 -8432
- package/packages/core/src/store/remote/client.ts +28 -2
- package/packages/core/src/store/remote/protocol.ts +11 -1
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/types.ts +16 -0
- package/packages/core/src/testing/reduced-read-budget.ts +347 -0
- package/skills/code-review/SKILL.md +8 -0
- package/skills/finalize/SKILL.md +4 -0
- package/skills/guide/SKILL.md +125 -26
- package/skills/guide/references/integration-tree.md +7 -4
- package/skills/guide/references/merge-policy.md +78 -6
- package/skills/guide/references/migration-1.0.md +4 -2
- package/skills/guide/references/operator-api.md +26 -5
- package/skills/guide/references/plugin-authoring.md +1 -1
- package/skills/guide/references/remote-store-protocol.md +9 -1
- package/skills/guide/references/restacking.md +23 -4
- package/skills/guide/references/ticket-dependencies.md +9 -4
- package/skills/implement/SKILL.md +15 -1
- package/skills/operate/SKILL.md +104 -13
- package/skills/plan/SKILL.md +17 -2
- package/skills/plan-review/SKILL.md +8 -0
- package/skills/reconcile/SKILL.md +21 -5
- package/skills/tickets/SKILL.md +5 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SelectedAccount } from '../config/accounts'
|
|
2
|
+
import { foldHeadPaths, type HeadPathsSummary } from './head-paths-state'
|
|
2
3
|
import {
|
|
3
4
|
advanceVerifyStage,
|
|
4
5
|
initialVerifyStageState,
|
|
@@ -31,7 +32,13 @@ import { reconcileRewriteHead } from './reconcile-head'
|
|
|
31
32
|
*/
|
|
32
33
|
import type { Actor } from '../events/envelope'
|
|
33
34
|
import type { AbEvent } from '../events/catalog'
|
|
34
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
normalizeVerifyCompletion,
|
|
37
|
+
type EventPayload,
|
|
38
|
+
type PinnedAsset,
|
|
39
|
+
type ReducedWaitEndCause,
|
|
40
|
+
type WaitRefusalCause,
|
|
41
|
+
} from '../events/payloads'
|
|
35
42
|
import type {
|
|
36
43
|
ArtifactRef,
|
|
37
44
|
BuildOutcome,
|
|
@@ -43,6 +50,7 @@ import type {
|
|
|
43
50
|
Finding,
|
|
44
51
|
Phase,
|
|
45
52
|
PolicyEscalationCause,
|
|
53
|
+
TicketRef,
|
|
46
54
|
VerifyOutcome,
|
|
47
55
|
} from '../ontology'
|
|
48
56
|
import { verifyPhase } from '../ontology'
|
|
@@ -84,6 +92,11 @@ export interface OpenEscalation {
|
|
|
84
92
|
/** Raised by `build.janitor-escalated`. Its routing is inert (`setup`
|
|
85
93
|
* target, no cause); the janitor's recovery closes it unanswered. */
|
|
86
94
|
janitor?: true
|
|
95
|
+
/** Opened by `wait.entered`: this escalation is a ticket wait, and
|
|
96
|
+
* answering it ends the wait (SPEC §11 "Ticket waits"). Also carried by
|
|
97
|
+
* the `policy/wait-unresolvable` raise that ended a wait, so its answer
|
|
98
|
+
* routes and resumes like the wait's own. */
|
|
99
|
+
wait?: { id: string }
|
|
87
100
|
question: string
|
|
88
101
|
refs?: string[]
|
|
89
102
|
/** seq of the `escalation.raised` event — what `spec.revised` cites (§15.3). */
|
|
@@ -227,6 +240,63 @@ export interface DrainExecution {
|
|
|
227
240
|
suspended?: true
|
|
228
241
|
}
|
|
229
242
|
|
|
243
|
+
/** The latest ticket-wait request (`wait.requested`) and its dispatcher
|
|
244
|
+
* outcome (SPEC §11 "Ticket waits", §15.3). `outcome` is absent while the
|
|
245
|
+
* dispatcher has not yet validated it. */
|
|
246
|
+
export interface WaitRequestState {
|
|
247
|
+
id: string
|
|
248
|
+
session: string
|
|
249
|
+
phase: Phase
|
|
250
|
+
round: number
|
|
251
|
+
tickets: string[]
|
|
252
|
+
reason: string
|
|
253
|
+
seq: number
|
|
254
|
+
/** An implement declaration's commits to publish before the wait is
|
|
255
|
+
* entered. `published` once pushed: by the CLI (local) or by the
|
|
256
|
+
* dispatcher's `wait.published` (remote); `requestSeq` is the remote
|
|
257
|
+
* `publication.requested` seq and `lost` marks its `publication.lost`. */
|
|
258
|
+
publication?: {
|
|
259
|
+
branch: string
|
|
260
|
+
base: string
|
|
261
|
+
sha: string
|
|
262
|
+
published: boolean
|
|
263
|
+
requestSeq?: number
|
|
264
|
+
lost?: true
|
|
265
|
+
}
|
|
266
|
+
outcome?:
|
|
267
|
+
| { kind: 'entered'; seq: number }
|
|
268
|
+
| {
|
|
269
|
+
kind: 'refused'
|
|
270
|
+
cause: WaitRefusalCause
|
|
271
|
+
tickets: string[]
|
|
272
|
+
message: string
|
|
273
|
+
seq: number
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** The latest entered ticket wait (`wait.entered`). Retained after it ends
|
|
278
|
+
* so the resumed session can be told what it waited on. */
|
|
279
|
+
export interface TicketWaitState {
|
|
280
|
+
id: string
|
|
281
|
+
escalation: string
|
|
282
|
+
session: string
|
|
283
|
+
phase: Phase
|
|
284
|
+
round: number
|
|
285
|
+
tickets: TicketRef[]
|
|
286
|
+
reason: string
|
|
287
|
+
enteredSeq: number
|
|
288
|
+
/** Envelope ts of `wait.entered`. */
|
|
289
|
+
enteredAt: string
|
|
290
|
+
/** The first end: an answer to the wait's escalation (`operator`),
|
|
291
|
+
* `wait.ended` with its cause, or the dispatcher's
|
|
292
|
+
* `policy/wait-unresolvable` raise (`unresolvable`). */
|
|
293
|
+
ended?: { cause: ReducedWaitEndCause; seq: number; message: string }
|
|
294
|
+
/** seq of the first `session.started`, `spec.revised`, wait-resume
|
|
295
|
+
* `restack.prepared` or `restack.advanced` after `ended`: the build has
|
|
296
|
+
* left the wait and holds a slot again. */
|
|
297
|
+
resumedSeq?: number
|
|
298
|
+
}
|
|
299
|
+
|
|
230
300
|
export interface BuildState {
|
|
231
301
|
drainingExecutions?: Record<string, DrainExecution>
|
|
232
302
|
compatibility: CompatibilityState
|
|
@@ -248,6 +318,11 @@ export interface BuildState {
|
|
|
248
318
|
* `links` is the running union; `published` is the last confirmed PR body
|
|
249
319
|
* readback. Absent until the first fact. */
|
|
250
320
|
nodeIssueLinks?: NodeIssueLinksState
|
|
321
|
+
/** The bounded summaries of the newest recorded candidate-head path facts
|
|
322
|
+
* (`head.paths-recorded`), first per head, newest last. Previews only: the
|
|
323
|
+
* complete sets are the `head-paths` artifact (`readHeadPaths`). Absent
|
|
324
|
+
* until the first fact; read through `candidateHeadPaths`. */
|
|
325
|
+
headPaths?: HeadPathsSummary[]
|
|
251
326
|
|
|
252
327
|
/**
|
|
253
328
|
* §15.5: 'queued' until `runner.attached`, 'running' after;
|
|
@@ -286,6 +361,10 @@ export interface BuildState {
|
|
|
286
361
|
openEscalations: OpenEscalation[]
|
|
287
362
|
/** In answer order, with resolutions for engine routing (§15.6-B). */
|
|
288
363
|
answeredEscalations: AnsweredEscalation[]
|
|
364
|
+
/** The latest ticket-wait request; see `WaitRequestState`. */
|
|
365
|
+
waitRequest?: WaitRequestState
|
|
366
|
+
/** The latest entered ticket wait; see `TicketWaitState`. */
|
|
367
|
+
wait?: TicketWaitState
|
|
289
368
|
/** Human-selected absolute caps for the current spec's independent loops. */
|
|
290
369
|
reviewRoundCeilings: { plan?: number; code?: number }
|
|
291
370
|
/** From `finalize.completed` (§15.3) — the kernel opened the PR (D7). */
|
|
@@ -368,7 +447,14 @@ export interface BuildState {
|
|
|
368
447
|
/** Round tracks the latest implementation start/completion; artifact identifies
|
|
369
448
|
* its latest completion. Commits tracks the current contribution, including
|
|
370
449
|
* successful leaf replays. */
|
|
371
|
-
implement: {
|
|
450
|
+
implement: {
|
|
451
|
+
round: number
|
|
452
|
+
commits?: CommitRange
|
|
453
|
+
artifactRev?: number
|
|
454
|
+
/** A leaf's contribution base moved by a restack before any implement
|
|
455
|
+
* round completed (a wait-resume restack or fast-forward). */
|
|
456
|
+
contributionBase?: string
|
|
457
|
+
}
|
|
372
458
|
/** ≡ the latest `code-review.verdict` is 'approve'. */
|
|
373
459
|
codeReviewApproved: boolean
|
|
374
460
|
/** The `code-review.verdict` approve that currently stands — its event seq
|
|
@@ -421,7 +507,9 @@ export interface BuildState {
|
|
|
421
507
|
/** The latest execution, while no instance-matched `execution.ended` follows it. */
|
|
422
508
|
openExecution?: EventPayload<'execution.started'> & { seq: number }
|
|
423
509
|
infrastructureFailures: Array<EventPayload<'infrastructure.failed'> & { seq: number }>
|
|
424
|
-
infrastructureFailure?: EventPayload<'infrastructure.failed'> & {
|
|
510
|
+
infrastructureFailure?: EventPayload<'infrastructure.failed'> & {
|
|
511
|
+
seq: number
|
|
512
|
+
}
|
|
425
513
|
cleanupAttempts: Array<EventPayload<'infrastructure.cleanup-attempted'> & { seq: number }>
|
|
426
514
|
/** Outstanding human discard intent. It is settled only by terminal completion. */
|
|
427
515
|
discardRequest?: { seq: number; actor: Actor }
|
|
@@ -475,6 +563,7 @@ export interface BuildAcc {
|
|
|
475
563
|
* `links` is the running union; `published` is the last confirmed PR body
|
|
476
564
|
* readback. Absent until the first fact. */
|
|
477
565
|
nodeIssueLinks?: NodeIssueLinksState
|
|
566
|
+
headPaths?: HeadPathsSummary[]
|
|
478
567
|
|
|
479
568
|
attached: boolean
|
|
480
569
|
pausedFlag: boolean
|
|
@@ -485,6 +574,13 @@ export interface BuildAcc {
|
|
|
485
574
|
lastCompletedPhase?: PhaseContext
|
|
486
575
|
openEscalations: OpenEscalation[]
|
|
487
576
|
answeredEscalations: AnsweredEscalation[]
|
|
577
|
+
waitRequest?: WaitRequestState
|
|
578
|
+
/** Each `publication.requested {operation: 'wait'}` by wait id, awaiting
|
|
579
|
+
* the `wait.requested` that follows it. The dispatcher may settle the
|
|
580
|
+
* request before the declaration lands, so an early `wait.published` sha
|
|
581
|
+
* or `publication.lost` is held here and folded into the declaration. */
|
|
582
|
+
waitPublicationRequests?: Record<string, { seq: number; publishedSha?: string; lost?: true }>
|
|
583
|
+
wait?: TicketWaitState
|
|
488
584
|
reviewRoundCeilings: BuildState['reviewRoundCeilings']
|
|
489
585
|
pr: BuildState['pr']
|
|
490
586
|
prState?: PrLifecycle
|
|
@@ -539,7 +635,7 @@ export interface BuildAcc {
|
|
|
539
635
|
}
|
|
540
636
|
|
|
541
637
|
/** Bump when `BuildAcc`'s shape or the fold's semantics change. */
|
|
542
|
-
export const BUILD_REDUCER_VERSION =
|
|
638
|
+
export const BUILD_REDUCER_VERSION = 39
|
|
543
639
|
|
|
544
640
|
function initialBuildAcc(): BuildAcc {
|
|
545
641
|
return {
|
|
@@ -776,6 +872,9 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
776
872
|
case 'node.compared':
|
|
777
873
|
acc.nodeComparison = event.payload
|
|
778
874
|
break
|
|
875
|
+
case 'head.paths-recorded':
|
|
876
|
+
acc.headPaths = foldHeadPaths(acc.headPaths, event.payload, event.seq)
|
|
877
|
+
break
|
|
779
878
|
case 'node.issue-links-recorded': {
|
|
780
879
|
// Idempotent by construction: a repeated fact for a recorded build
|
|
781
880
|
// re-merges the same links and leaves `builds` unchanged.
|
|
@@ -794,14 +893,20 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
794
893
|
...(acc.nodeIssueLinks ?? { builds: [], links: [] }),
|
|
795
894
|
published: {
|
|
796
895
|
pr: event.payload.pr,
|
|
797
|
-
issueLinks: event.payload.issueLinks.map(({ issue, intent }) => ({
|
|
896
|
+
issueLinks: event.payload.issueLinks.map(({ issue, intent }) => ({
|
|
897
|
+
issue,
|
|
898
|
+
intent,
|
|
899
|
+
})),
|
|
798
900
|
seq: event.seq,
|
|
799
901
|
},
|
|
800
902
|
}
|
|
801
903
|
break
|
|
802
904
|
case 'node.rewritten':
|
|
803
905
|
if (acc.nodeComparison)
|
|
804
|
-
acc.nodeComparison = {
|
|
906
|
+
acc.nodeComparison = {
|
|
907
|
+
...acc.nodeComparison,
|
|
908
|
+
headSha: event.payload.head,
|
|
909
|
+
}
|
|
805
910
|
if (pr) pr = { ...pr, headSha: event.payload.head }
|
|
806
911
|
break
|
|
807
912
|
case 'pr.opened':
|
|
@@ -813,7 +918,9 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
813
918
|
acc.target = event.payload.target
|
|
814
919
|
acc.baseBranch = event.payload.baseBranch
|
|
815
920
|
pinnedAssets = event.payload.assets ?? []
|
|
816
|
-
acc.issueLinks = (event.payload.issueLinks ?? []).map((link) => ({
|
|
921
|
+
acc.issueLinks = (event.payload.issueLinks ?? []).map((link) => ({
|
|
922
|
+
...link,
|
|
923
|
+
}))
|
|
817
924
|
if (event.payload.profile !== undefined)
|
|
818
925
|
acc.profile = { name: event.payload.profile, configured: true }
|
|
819
926
|
break
|
|
@@ -846,7 +953,42 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
846
953
|
break
|
|
847
954
|
case 'publication.requested':
|
|
848
955
|
if (event.payload.operation === 'finalize') acc.issueLinksSealedSeq ??= event.seq
|
|
956
|
+
if (event.payload.operation === 'wait')
|
|
957
|
+
acc.waitPublicationRequests = {
|
|
958
|
+
...acc.waitPublicationRequests,
|
|
959
|
+
[event.payload.id]: { seq: event.seq },
|
|
960
|
+
}
|
|
961
|
+
break
|
|
962
|
+
case 'publication.lost': {
|
|
963
|
+
if (event.payload.operation !== 'wait') break
|
|
964
|
+
if (acc.waitRequest?.publication?.requestSeq === event.payload.request) {
|
|
965
|
+
acc.waitRequest.publication.lost = true
|
|
966
|
+
break
|
|
967
|
+
}
|
|
968
|
+
const pending = Object.entries(acc.waitPublicationRequests ?? {}).find(
|
|
969
|
+
([, request]) => request.seq === event.payload.request,
|
|
970
|
+
)
|
|
971
|
+
if (pending !== undefined)
|
|
972
|
+
acc.waitPublicationRequests = {
|
|
973
|
+
...acc.waitPublicationRequests,
|
|
974
|
+
[pending[0]]: { ...pending[1], lost: true },
|
|
975
|
+
}
|
|
976
|
+
break
|
|
977
|
+
}
|
|
978
|
+
case 'wait.published': {
|
|
979
|
+
if (acc.waitRequest?.id === event.payload.id) {
|
|
980
|
+
if (acc.waitRequest.publication?.sha === event.payload.sha)
|
|
981
|
+
acc.waitRequest.publication.published = true
|
|
982
|
+
break
|
|
983
|
+
}
|
|
984
|
+
const pending = acc.waitPublicationRequests?.[event.payload.id]
|
|
985
|
+
if (pending !== undefined)
|
|
986
|
+
acc.waitPublicationRequests = {
|
|
987
|
+
...acc.waitPublicationRequests,
|
|
988
|
+
[event.payload.id]: { ...pending, publishedSha: event.payload.sha },
|
|
989
|
+
}
|
|
849
990
|
break
|
|
991
|
+
}
|
|
850
992
|
// Inert loss fact (AUT-328): the dispatcher released a workspace with a
|
|
851
993
|
// pending publication. Recovery runs through the existing
|
|
852
994
|
// abandoned-publication flow (abandonedPublicationPending), which re-runs
|
|
@@ -854,7 +996,6 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
854
996
|
case 'publication.retry-scheduled':
|
|
855
997
|
case 'publication.retry-exhausted':
|
|
856
998
|
case 'publication.candidate-retired':
|
|
857
|
-
case 'publication.lost':
|
|
858
999
|
case 'dispatch.comment-posted':
|
|
859
1000
|
case 'pr-attachment.designated':
|
|
860
1001
|
case 'pr-attachment.hosted':
|
|
@@ -989,13 +1130,18 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
989
1130
|
// matching engine.ts:710-712.
|
|
990
1131
|
restartSince = event.seq
|
|
991
1132
|
verify.cycleSince = Math.max(verify.cycleSince, event.seq)
|
|
1133
|
+
if (acc.wait?.ended && acc.wait.resumedSeq === undefined) acc.wait.resumedSeq = event.seq
|
|
992
1134
|
delete reviewRoundCeilings.plan
|
|
993
1135
|
delete reviewRoundCeilings.code
|
|
994
1136
|
break
|
|
995
1137
|
|
|
996
1138
|
case 'session.started': {
|
|
1139
|
+
if (acc.wait?.ended && acc.wait.resumedSeq === undefined) acc.wait.resumedSeq = event.seq
|
|
997
1140
|
if (event.payload.profile !== undefined && event.payload.profile.name === acc.profile?.name)
|
|
998
|
-
acc.profile = {
|
|
1141
|
+
acc.profile = {
|
|
1142
|
+
...acc.profile,
|
|
1143
|
+
configured: event.payload.profile.configured,
|
|
1144
|
+
}
|
|
999
1145
|
const root = event.payload.continuation?.root ?? event.payload.session
|
|
1000
1146
|
acc.sessionTotals[root] ??= { activeMs: 0, transcripts: [] }
|
|
1001
1147
|
const totals = acc.sessionTotals[root]
|
|
@@ -1072,7 +1218,10 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1072
1218
|
const open = openSessions.get(event.payload.session)
|
|
1073
1219
|
if (open) {
|
|
1074
1220
|
const { nativeHandle: _handle, resumed: _resumed, ...fresh } = open
|
|
1075
|
-
openSessions.set(open.session, {
|
|
1221
|
+
openSessions.set(open.session, {
|
|
1222
|
+
...fresh,
|
|
1223
|
+
nativeResumeFallback: true,
|
|
1224
|
+
})
|
|
1076
1225
|
}
|
|
1077
1226
|
break
|
|
1078
1227
|
}
|
|
@@ -1174,7 +1323,9 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1174
1323
|
acc.verifyStage.cancellations[verifyMemberKey(event.payload.step, event.payload.attempt)]
|
|
1175
1324
|
?.seq === event.seq
|
|
1176
1325
|
)
|
|
1177
|
-
complete(verifyPhase(event.payload.step), event.seq, {
|
|
1326
|
+
complete(verifyPhase(event.payload.step), event.seq, {
|
|
1327
|
+
attempt: event.payload.attempt,
|
|
1328
|
+
})
|
|
1178
1329
|
break
|
|
1179
1330
|
case 'verify.stage-failed':
|
|
1180
1331
|
break
|
|
@@ -1229,14 +1380,24 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1229
1380
|
// §5: post-steps are independent and failure-tolerant — a completion
|
|
1230
1381
|
// counts whether `ok` is true or false. Retain full-log history with
|
|
1231
1382
|
// occurrence identity; readers scope it with `seq > restartBoundary`.
|
|
1232
|
-
finalizeSteps.push({
|
|
1383
|
+
finalizeSteps.push({
|
|
1384
|
+
step: event.payload.step,
|
|
1385
|
+
ok: event.payload.ok,
|
|
1386
|
+
seq: event.seq,
|
|
1387
|
+
})
|
|
1233
1388
|
break
|
|
1234
1389
|
|
|
1235
1390
|
case 'pr.auto-merge-enabled':
|
|
1236
|
-
autoMerge.applied = {
|
|
1391
|
+
autoMerge.applied = {
|
|
1392
|
+
enabled: true,
|
|
1393
|
+
commandSeq: event.payload.commandSeq,
|
|
1394
|
+
}
|
|
1237
1395
|
break
|
|
1238
1396
|
case 'pr.auto-merge-disabled':
|
|
1239
|
-
autoMerge.applied = {
|
|
1397
|
+
autoMerge.applied = {
|
|
1398
|
+
enabled: false,
|
|
1399
|
+
commandSeq: event.payload.commandSeq,
|
|
1400
|
+
}
|
|
1240
1401
|
break
|
|
1241
1402
|
case 'pr.merged':
|
|
1242
1403
|
acc.mergedSha = event.payload.sha
|
|
@@ -1259,7 +1420,11 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1259
1420
|
case 'restack.rewritten':
|
|
1260
1421
|
case 'restack.completed':
|
|
1261
1422
|
if (acc.kind !== 'node' && implement.commits)
|
|
1262
|
-
implement.commits = {
|
|
1423
|
+
implement.commits = {
|
|
1424
|
+
base: event.payload.targetBase,
|
|
1425
|
+
head: event.payload.headSha,
|
|
1426
|
+
}
|
|
1427
|
+
else if (acc.kind !== 'node') implement.contributionBase = event.payload.targetBase
|
|
1263
1428
|
if (event.type === 'restack.completed' && prState === 'conflicted') prState = 'open'
|
|
1264
1429
|
if (pr !== undefined)
|
|
1265
1430
|
pr = {
|
|
@@ -1270,9 +1435,35 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1270
1435
|
: event.payload.headSha,
|
|
1271
1436
|
}
|
|
1272
1437
|
break
|
|
1438
|
+
case 'restack.advanced':
|
|
1439
|
+
if (acc.kind !== 'node') implement.contributionBase = event.payload.to
|
|
1440
|
+
if (acc.wait?.ended && acc.wait.resumedSeq === undefined) acc.wait.resumedSeq = event.seq
|
|
1441
|
+
break
|
|
1442
|
+
case 'restack.prepared':
|
|
1443
|
+
// A wait-resume restack is the resumed build's first step; it holds a
|
|
1444
|
+
// slot from here even when no session follows.
|
|
1445
|
+
if (
|
|
1446
|
+
event.payload.trigger === 'wait-resume' &&
|
|
1447
|
+
acc.wait?.ended &&
|
|
1448
|
+
acc.wait.resumedSeq === undefined
|
|
1449
|
+
)
|
|
1450
|
+
acc.wait.resumedSeq = event.seq
|
|
1451
|
+
break
|
|
1452
|
+
case 'reconcile.superseded':
|
|
1453
|
+
// The abandoned occurrence completed nothing; prState is unchanged.
|
|
1454
|
+
if (
|
|
1455
|
+
currentPhase?.phase === 'reconcile' &&
|
|
1456
|
+
(currentPhase.attempt === undefined || currentPhase.attempt === event.payload.attempt)
|
|
1457
|
+
)
|
|
1458
|
+
currentPhase = undefined
|
|
1459
|
+
break
|
|
1273
1460
|
case 'reconcile.rewritten':
|
|
1274
1461
|
if (acc.kind !== 'node' && implement.commits)
|
|
1275
|
-
implement.commits = {
|
|
1462
|
+
implement.commits = {
|
|
1463
|
+
base: event.payload.targetBase,
|
|
1464
|
+
head: event.payload.headSha,
|
|
1465
|
+
}
|
|
1466
|
+
else if (acc.kind !== 'node') implement.contributionBase = event.payload.targetBase
|
|
1276
1467
|
if (pr !== undefined) pr = { ...pr, headSha: reconcileRewriteHead(event.payload) }
|
|
1277
1468
|
break
|
|
1278
1469
|
case 'reconcile.completed': {
|
|
@@ -1308,6 +1499,84 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1308
1499
|
seq: event.seq,
|
|
1309
1500
|
})
|
|
1310
1501
|
break
|
|
1502
|
+
case 'wait.requested':
|
|
1503
|
+
if (event.actor.kind !== 'agent') break
|
|
1504
|
+
acc.waitRequest = {
|
|
1505
|
+
id: event.payload.id,
|
|
1506
|
+
session: event.actor.session,
|
|
1507
|
+
phase: event.payload.phase,
|
|
1508
|
+
round: event.payload.round,
|
|
1509
|
+
tickets: [...event.payload.tickets],
|
|
1510
|
+
reason: event.payload.reason,
|
|
1511
|
+
seq: event.seq,
|
|
1512
|
+
}
|
|
1513
|
+
if (event.payload.publication !== undefined) {
|
|
1514
|
+
const { settlement, ...publication } = event.payload.publication
|
|
1515
|
+
const request =
|
|
1516
|
+
settlement === 'requested' ? acc.waitPublicationRequests?.[event.payload.id] : undefined
|
|
1517
|
+
acc.waitRequest.publication = {
|
|
1518
|
+
...publication,
|
|
1519
|
+
published: settlement === 'published' || request?.publishedSha === publication.sha,
|
|
1520
|
+
...(request !== undefined ? { requestSeq: request.seq } : {}),
|
|
1521
|
+
...(request?.lost ? { lost: true as const } : {}),
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
delete acc.waitPublicationRequests
|
|
1525
|
+
break
|
|
1526
|
+
case 'wait.refused':
|
|
1527
|
+
if (acc.waitRequest?.id !== event.payload.id || acc.waitRequest.outcome) break
|
|
1528
|
+
acc.waitRequest.outcome = {
|
|
1529
|
+
kind: 'refused',
|
|
1530
|
+
cause: event.payload.cause,
|
|
1531
|
+
tickets: [...event.payload.tickets],
|
|
1532
|
+
message: event.payload.message,
|
|
1533
|
+
seq: event.seq,
|
|
1534
|
+
}
|
|
1535
|
+
break
|
|
1536
|
+
case 'wait.entered': {
|
|
1537
|
+
const request = acc.waitRequest
|
|
1538
|
+
if (request?.id !== event.payload.id || request.outcome) break
|
|
1539
|
+
request.outcome = { kind: 'entered', seq: event.seq }
|
|
1540
|
+
acc.wait = {
|
|
1541
|
+
id: request.id,
|
|
1542
|
+
escalation: event.payload.escalation,
|
|
1543
|
+
session: request.session,
|
|
1544
|
+
phase: request.phase,
|
|
1545
|
+
round: request.round,
|
|
1546
|
+
tickets: event.payload.tickets.map((ticket) => ({ ...ticket })),
|
|
1547
|
+
reason: event.payload.reason,
|
|
1548
|
+
enteredSeq: event.seq,
|
|
1549
|
+
enteredAt: event.ts,
|
|
1550
|
+
}
|
|
1551
|
+
openEscalations.set(event.payload.escalation, {
|
|
1552
|
+
id: event.payload.escalation,
|
|
1553
|
+
phase: request.phase,
|
|
1554
|
+
round: request.round,
|
|
1555
|
+
source: 'agent',
|
|
1556
|
+
session: request.session,
|
|
1557
|
+
wait: { id: request.id },
|
|
1558
|
+
question: event.payload.question,
|
|
1559
|
+
refs: event.payload.tickets.map((ticket) => ticket.id),
|
|
1560
|
+
seq: event.seq,
|
|
1561
|
+
})
|
|
1562
|
+
break
|
|
1563
|
+
}
|
|
1564
|
+
case 'wait.ended': {
|
|
1565
|
+
const wait = acc.wait
|
|
1566
|
+
if (wait?.id !== event.payload.id || wait.ended) break
|
|
1567
|
+
wait.ended = { cause: event.payload.cause, seq: event.seq, message: event.payload.message }
|
|
1568
|
+
const open = openEscalations.get(wait.escalation)
|
|
1569
|
+
if (open) {
|
|
1570
|
+
openEscalations.delete(open.id)
|
|
1571
|
+
answeredEscalations.push({
|
|
1572
|
+
...open,
|
|
1573
|
+
answer: event.payload.message,
|
|
1574
|
+
resolution: 'guidance',
|
|
1575
|
+
answeredSeq: event.seq,
|
|
1576
|
+
})
|
|
1577
|
+
}
|
|
1578
|
+
break
|
|
1579
|
+
}
|
|
1311
1580
|
case 'build.janitor-escalated':
|
|
1312
1581
|
if (!openEscalations.has(event.payload.id))
|
|
1313
1582
|
openEscalations.set(event.payload.id, {
|
|
@@ -1333,6 +1602,28 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1333
1602
|
refs: event.payload.refs,
|
|
1334
1603
|
seq: event.seq,
|
|
1335
1604
|
}
|
|
1605
|
+
// A waited ticket can never complete: the raise ends the open wait
|
|
1606
|
+
// (closing its escalation as answered, like `wait.ended`) and carries
|
|
1607
|
+
// the wait marker, so its answer resumes the declaring phase.
|
|
1608
|
+
const wait = acc.wait
|
|
1609
|
+
const waitEscalation = wait === undefined ? undefined : openEscalations.get(wait.escalation)
|
|
1610
|
+
if (
|
|
1611
|
+
event.payload.source === 'policy' &&
|
|
1612
|
+
event.payload.policyCause === 'wait-unresolvable' &&
|
|
1613
|
+
wait !== undefined &&
|
|
1614
|
+
wait.ended === undefined &&
|
|
1615
|
+
waitEscalation !== undefined
|
|
1616
|
+
) {
|
|
1617
|
+
wait.ended = { cause: 'unresolvable', seq: event.seq, message: event.payload.question }
|
|
1618
|
+
openEscalations.delete(waitEscalation.id)
|
|
1619
|
+
answeredEscalations.push({
|
|
1620
|
+
...waitEscalation,
|
|
1621
|
+
answer: event.payload.question,
|
|
1622
|
+
resolution: 'guidance',
|
|
1623
|
+
answeredSeq: event.seq,
|
|
1624
|
+
})
|
|
1625
|
+
escalation.wait = { id: wait.id }
|
|
1626
|
+
}
|
|
1336
1627
|
const key =
|
|
1337
1628
|
escalation.session === undefined ? undefined : acc.verifyStage.owners[escalation.session]
|
|
1338
1629
|
const cancellation = key === undefined ? undefined : acc.verifyStage.cancellations[key]
|
|
@@ -1358,6 +1649,8 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
|
|
|
1358
1649
|
answeredSeq: event.seq,
|
|
1359
1650
|
})
|
|
1360
1651
|
if (open.janitor && acc.janitor?.escalation === open.id) acc.janitor.retryRequested = true
|
|
1652
|
+
if (open.wait && acc.wait?.id === open.wait.id && !acc.wait.ended)
|
|
1653
|
+
acc.wait.ended = { cause: 'operator', seq: event.seq, message: event.payload.answer }
|
|
1361
1654
|
if (
|
|
1362
1655
|
event.payload.reviewRoundCeiling !== undefined &&
|
|
1363
1656
|
open.source === 'policy' &&
|
|
@@ -1475,6 +1768,7 @@ function finishBuild(acc: BuildAcc): BuildState {
|
|
|
1475
1768
|
nodePolling: acc.nodePolling,
|
|
1476
1769
|
nodeComparison: acc.nodeComparison,
|
|
1477
1770
|
...(acc.nodeIssueLinks !== undefined ? { nodeIssueLinks: acc.nodeIssueLinks } : {}),
|
|
1771
|
+
...(acc.headPaths !== undefined ? { headPaths: structuredClone(acc.headPaths) } : {}),
|
|
1478
1772
|
nodeRestack: acc.nodeRestack,
|
|
1479
1773
|
status,
|
|
1480
1774
|
...(statusWithoutJanitorEscalation !== undefined ? { statusWithoutJanitorEscalation } : {}),
|
|
@@ -1485,6 +1779,8 @@ function finishBuild(acc: BuildAcc): BuildState {
|
|
|
1485
1779
|
lastCompletedPhase,
|
|
1486
1780
|
openEscalations: [...acc.openEscalations],
|
|
1487
1781
|
answeredEscalations: acc.answeredEscalations,
|
|
1782
|
+
...(acc.waitRequest !== undefined ? { waitRequest: acc.waitRequest } : {}),
|
|
1783
|
+
...(acc.wait !== undefined ? { wait: acc.wait } : {}),
|
|
1488
1784
|
reviewRoundCeilings: acc.reviewRoundCeilings,
|
|
1489
1785
|
pr: acc.pr,
|
|
1490
1786
|
prState: acc.prState,
|
|
@@ -1514,7 +1810,10 @@ function finishBuild(acc: BuildAcc): BuildState {
|
|
|
1514
1810
|
implement: acc.implement,
|
|
1515
1811
|
codeReviewApproved: acc.codeReviewApproved,
|
|
1516
1812
|
codeReviewApproval: acc.codeReviewApproval,
|
|
1517
|
-
reviewFindings: {
|
|
1813
|
+
reviewFindings: {
|
|
1814
|
+
planReview: acc.planReviewFindings,
|
|
1815
|
+
codeReview: acc.codeReviewFindings,
|
|
1816
|
+
},
|
|
1518
1817
|
verifyStage: acc.verifyStage,
|
|
1519
1818
|
verify: acc.verify,
|
|
1520
1819
|
reconcileAttempts: acc.reconcileAttempts,
|
|
@@ -4,6 +4,7 @@ import type { Forge } from '../ports/types'
|
|
|
4
4
|
import type { EventWrite } from '../events/catalog'
|
|
5
5
|
import { readBuildFacts } from '../store/reduced-reads'
|
|
6
6
|
import { gitOid } from '../events/payloads'
|
|
7
|
+
import { leafBaseInUse } from './leaf-restack-state'
|
|
7
8
|
|
|
8
9
|
export function assertTargetOid(sha: string): void {
|
|
9
10
|
if (!gitOid.safeParse(sha).success) throw new Error('invalid target commit OID')
|
|
@@ -34,11 +35,7 @@ export async function observeTarget(input: {
|
|
|
34
35
|
const accepted = restack.target?.branch === branch ? restack.target.sha : undefined
|
|
35
36
|
// Reparent acceptance establishes a new branch scope. Until its replay
|
|
36
37
|
// settles the old parent's contribution boundary is not a baseline here.
|
|
37
|
-
const
|
|
38
|
-
const leafBase =
|
|
39
|
-
reconcile && reconcile.completedSeq > (restack.completedAt ?? 0)
|
|
40
|
-
? reconcile.baseSha
|
|
41
|
-
: (restack.completed?.targetBase ?? restack.initialBase)
|
|
38
|
+
const leafBase = leafBaseInUse(log)
|
|
42
39
|
const used =
|
|
43
40
|
state.kind === 'node'
|
|
44
41
|
? node?.parentChange && node.parentReplay !== node.parentChange.id
|
|
@@ -9,11 +9,14 @@ interface TerminalGuardAcc {
|
|
|
9
9
|
sessionStartedSeq?: number
|
|
10
10
|
permanent?: { seq: number; diagnostic: string }
|
|
11
11
|
completion?: { seq: number; diagnostic: string }
|
|
12
|
+
/** The build's undecided or open ticket wait, from any session. Waits are
|
|
13
|
+
* build-wide, so a concurrent verifier may not declare a second one. */
|
|
14
|
+
wait?: { id: string; session: string; tickets: string[]; escalation?: string }
|
|
12
15
|
}
|
|
13
16
|
export function terminalGuardReducer(env: CliEnv) {
|
|
14
17
|
const spec = phaseSpecFor(env.phase)
|
|
15
|
-
return defineReducer<TerminalGuardAcc, AbEvent, { diagnostic?: string }>({
|
|
16
|
-
version:
|
|
18
|
+
return defineReducer<TerminalGuardAcc, AbEvent, { diagnostic?: string; waitHeld?: string }>({
|
|
19
|
+
version: 5,
|
|
17
20
|
initial: () => ({ reconcileAttempt: 0 }),
|
|
18
21
|
fold(acc, events) {
|
|
19
22
|
for (const event of events) {
|
|
@@ -22,6 +25,7 @@ export function terminalGuardReducer(env: CliEnv) {
|
|
|
22
25
|
if (event.type === 'reconcile.started') acc.reconcileAttempt = event.payload.attempt
|
|
23
26
|
if (event.type === 'session.started' && event.payload.session === env.session)
|
|
24
27
|
acc.sessionStartedSeq = event.seq
|
|
28
|
+
foldWait(acc, event)
|
|
25
29
|
try {
|
|
26
30
|
checkEvent(event, env, acc.reconcileAttempt, acc.sessionStartedSeq)
|
|
27
31
|
} catch (error) {
|
|
@@ -34,10 +38,44 @@ export function terminalGuardReducer(env: CliEnv) {
|
|
|
34
38
|
const first = [acc.permanent, acc.completion]
|
|
35
39
|
.filter((item) => item !== undefined)
|
|
36
40
|
.sort((a, b) => a.seq - b.seq)[0]
|
|
37
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
...(first ? { diagnostic: first.diagnostic } : {}),
|
|
43
|
+
...(acc.wait ? { waitHeld: waitHeldDiagnostic(acc.wait) } : {}),
|
|
44
|
+
}
|
|
38
45
|
},
|
|
39
46
|
})
|
|
40
47
|
}
|
|
48
|
+
function foldWait(acc: TerminalGuardAcc, event: AbEvent): void {
|
|
49
|
+
if (event.type === 'wait.requested' && event.actor.kind === 'agent')
|
|
50
|
+
acc.wait = {
|
|
51
|
+
id: event.payload.id,
|
|
52
|
+
session: event.actor.session,
|
|
53
|
+
tickets: [...event.payload.tickets],
|
|
54
|
+
}
|
|
55
|
+
else if (event.type === 'wait.entered' && acc.wait?.id === event.payload.id)
|
|
56
|
+
acc.wait.escalation = event.payload.escalation
|
|
57
|
+
else if (
|
|
58
|
+
(event.type === 'wait.refused' || event.type === 'wait.ended') &&
|
|
59
|
+
acc.wait?.id === event.payload.id
|
|
60
|
+
)
|
|
61
|
+
delete acc.wait
|
|
62
|
+
else if (
|
|
63
|
+
event.type === 'escalation.answered' &&
|
|
64
|
+
acc.wait?.escalation !== undefined &&
|
|
65
|
+
acc.wait.escalation === event.payload.id
|
|
66
|
+
)
|
|
67
|
+
delete acc.wait
|
|
68
|
+
}
|
|
69
|
+
/** One wait per build at a time: a second declaration while another session's
|
|
70
|
+
* wait is undecided or open would replace it, losing its tickets. */
|
|
71
|
+
function waitHeldDiagnostic(wait: NonNullable<TerminalGuardAcc['wait']>): string {
|
|
72
|
+
return (
|
|
73
|
+
`wait rejected: session "${wait.session}" already declared wait "${wait.id}" on ` +
|
|
74
|
+
`${wait.tickets.join(', ')}, and a build holds one ticket wait at a time. ` +
|
|
75
|
+
'End this session with its ordinary terminal; if it also depends on other ' +
|
|
76
|
+
'tickets, name them with ab escalate instead.'
|
|
77
|
+
)
|
|
78
|
+
}
|
|
41
79
|
function checkEvent(
|
|
42
80
|
event: AbEvent,
|
|
43
81
|
env: CliEnv,
|
|
@@ -85,6 +123,17 @@ function checkEvent(
|
|
|
85
123
|
'Every phase ends with exactly one terminal command (§8.4).',
|
|
86
124
|
)
|
|
87
125
|
}
|
|
126
|
+
if (
|
|
127
|
+
event.type === 'wait.requested' &&
|
|
128
|
+
event.actor.kind === 'agent' &&
|
|
129
|
+
event.actor.session === env.session
|
|
130
|
+
) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`second terminal call rejected (D5): this session already declared a wait — ` +
|
|
133
|
+
`wait.requested "${event.payload.id}" at seq ${event.seq}. ` +
|
|
134
|
+
'Every phase ends with exactly one terminal command (§8.4).',
|
|
135
|
+
)
|
|
136
|
+
}
|
|
88
137
|
if (
|
|
89
138
|
event.type === 'publication.requested' &&
|
|
90
139
|
event.actor.kind === 'agent' &&
|