@defrex/autobuild 1.7.0 → 1.8.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 (115) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +316 -47
  3. package/docs/answering-blocked-builds.md +44 -3
  4. package/docs/architecture.md +62 -7
  5. package/docs/cli.md +1 -0
  6. package/docs/configuration-overview.md +1 -1
  7. package/docs/configuration.md +49 -9
  8. package/docs/dispatcher.md +1 -1
  9. package/docs/integration-overview.md +2 -2
  10. package/docs/integration-tree.md +7 -4
  11. package/docs/merge-policy.md +78 -6
  12. package/docs/migration-1.0.md +4 -2
  13. package/docs/operating.md +3 -2
  14. package/docs/operator-api.md +26 -5
  15. package/docs/operator-surfaces.md +10 -0
  16. package/docs/plugin-authoring.md +1 -1
  17. package/docs/remote-store-protocol.md +9 -1
  18. package/docs/restacking.md +23 -4
  19. package/docs/ticket-dependencies.md +9 -4
  20. package/docs/tickets.md +1 -1
  21. package/docs/troubleshooting.md +1 -1
  22. package/package.json +3 -3
  23. package/packages/core/src/cli/attention.ts +1 -0
  24. package/packages/core/src/cli/build-control.ts +65 -7
  25. package/packages/core/src/cli/context.ts +55 -14
  26. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  27. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  28. package/packages/core/src/cli/dashboard/model.ts +61 -8
  29. package/packages/core/src/cli/dashboard/render.ts +28 -3
  30. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  31. package/packages/core/src/cli/help.ts +69 -7
  32. package/packages/core/src/cli/landings.ts +1 -1
  33. package/packages/core/src/cli/main.ts +60 -9
  34. package/packages/core/src/cli/publication-settlement.ts +10 -0
  35. package/packages/core/src/cli/status.ts +178 -12
  36. package/packages/core/src/cli/terminals.ts +197 -4
  37. package/packages/core/src/cli/wait.ts +1 -0
  38. package/packages/core/src/cli/watch.ts +71 -0
  39. package/packages/core/src/config/landing.ts +12 -0
  40. package/packages/core/src/config/path-selectors.ts +68 -0
  41. package/packages/core/src/config/schema.ts +40 -58
  42. package/packages/core/src/events/catalog.ts +17 -3
  43. package/packages/core/src/events/compatibility.ts +2 -1
  44. package/packages/core/src/events/head-paths-limits.ts +25 -0
  45. package/packages/core/src/events/payloads.ts +315 -20
  46. package/packages/core/src/events/policy.ts +21 -0
  47. package/packages/core/src/events/repository.ts +30 -1
  48. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +247 -6
  49. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  50. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  51. package/packages/core/src/kernel/engine.ts +48 -8
  52. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  53. package/packages/core/src/kernel/head-paths.ts +401 -0
  54. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  55. package/packages/core/src/kernel/landing-policy.ts +55 -2
  56. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  57. package/packages/core/src/kernel/landing-state.ts +44 -4
  58. package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
  59. package/packages/core/src/kernel/log-index.ts +27 -1
  60. package/packages/core/src/kernel/node-polling.ts +13 -3
  61. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  62. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  63. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  64. package/packages/core/src/kernel/read-facts.ts +28 -1
  65. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  66. package/packages/core/src/kernel/reducer.ts +316 -17
  67. package/packages/core/src/kernel/target-observation.ts +2 -5
  68. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  69. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  70. package/packages/core/src/kernel/ticket-preparation.ts +12 -1
  71. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  72. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  73. package/packages/core/src/ontology.ts +1 -0
  74. package/packages/core/src/operator/annotations.ts +6 -0
  75. package/packages/core/src/operator/index.ts +3 -0
  76. package/packages/core/src/operator/protocol.ts +15 -2
  77. package/packages/core/src/operator/registry.ts +97 -5
  78. package/packages/core/src/operator/repository-events.ts +67 -0
  79. package/packages/core/src/ports/tickets/fake.ts +5 -0
  80. package/packages/core/src/ports/types.ts +3 -2
  81. package/packages/core/src/processes/build-execution-state.ts +30 -1
  82. package/packages/core/src/processes/build-runner.ts +150 -18
  83. package/packages/core/src/processes/dispatcher.ts +739 -97
  84. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  85. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  86. package/packages/core/src/processes/publication-state.ts +6 -1
  87. package/packages/core/src/store/digest.ts +41 -2
  88. package/packages/core/src/store/reduced-reads.ts +4 -1
  89. package/packages/core/src/store/reducer-value-shapes.json +10108 -8432
  90. package/packages/core/src/store/remote/client.ts +28 -2
  91. package/packages/core/src/store/remote/protocol.ts +11 -1
  92. package/packages/core/src/store/remote/released-clients.json +11 -0
  93. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  94. package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
  95. package/packages/core/src/store/repo-state-events.ts +2 -0
  96. package/packages/core/src/store/types.ts +16 -0
  97. package/packages/core/src/testing/reduced-read-budget.ts +347 -0
  98. package/skills/code-review/SKILL.md +8 -0
  99. package/skills/finalize/SKILL.md +4 -0
  100. package/skills/guide/SKILL.md +125 -26
  101. package/skills/guide/references/integration-tree.md +7 -4
  102. package/skills/guide/references/merge-policy.md +78 -6
  103. package/skills/guide/references/migration-1.0.md +4 -2
  104. package/skills/guide/references/operator-api.md +26 -5
  105. package/skills/guide/references/plugin-authoring.md +1 -1
  106. package/skills/guide/references/remote-store-protocol.md +9 -1
  107. package/skills/guide/references/restacking.md +23 -4
  108. package/skills/guide/references/ticket-dependencies.md +9 -4
  109. package/skills/implement/SKILL.md +15 -1
  110. package/skills/operate/SKILL.md +104 -13
  111. package/skills/plan/SKILL.md +17 -2
  112. package/skills/plan-review/SKILL.md +8 -0
  113. package/skills/reconcile/SKILL.md +21 -5
  114. package/skills/tickets/SKILL.md +5 -4
  115. package/templates/hosted-service/package.json +2 -2
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Revoking protected merge consent.
3
+ *
4
+ * Consent given under a `[[merge]]` rule with `paths` or `within` predicates
5
+ * approved the protected change the operator read. When a reconcile's own
6
+ * edits (its recorded resolution) touch a file those predicates match, the
7
+ * change that would merge is no longer the reviewed one: the kernel appends
8
+ * `landing.consent-revoked` where the reconcile records its head, never on a
9
+ * poll. Clean restacks record no resolution and never revoke.
10
+ */
11
+ import { compilePathSelectors } from '../config/path-selectors'
12
+ import type { EventPayload } from '../events/payloads'
13
+ import { LANDING_MATCHED_PATHS_PREVIEW } from '../events/head-paths-limits'
14
+ import { readHeadPaths, type RecordedHeadPaths } from './head-paths'
15
+ import type { LandingState } from './landing-state'
16
+ import type { BuildStore } from '../store/types'
17
+
18
+ export type ConsentRevocation = EventPayload<'landing.consent-revoked'>
19
+
20
+ /** Cheap guard: whether any reconcile edit could revoke the current consent. */
21
+ export function revocableConsent(landing: LandingState | undefined): boolean {
22
+ const command = landing?.command
23
+ return command?.kind === 'land' && !command.legacy && command.rule !== undefined
24
+ }
25
+
26
+ /** The revocation a reconcile's resolution causes, or undefined. Each
27
+ * resolution path is matched against the union of the consent rule's `paths`
28
+ * and `within` selectors; `within`'s every-path condition does not apply. */
29
+ export function consentRevocation(
30
+ landing: LandingState | undefined,
31
+ input: {
32
+ source: ConsentRevocation['source']
33
+ previousHead: string
34
+ head: string
35
+ resolution: readonly string[]
36
+ },
37
+ ): ConsentRevocation | undefined {
38
+ const command = landing?.command
39
+ if (!revocableConsent(landing) || command?.rule === undefined) return undefined
40
+ const { paths, within } = command.rule.snapshot
41
+ const protectedPath = compilePathSelectors(
42
+ [...(paths ?? []), ...(within ?? [])],
43
+ (selector, error) =>
44
+ `invalid [[merge]] path selector ${JSON.stringify(selector)} in consent rule ${command.rule!.index}: ${error}`,
45
+ )
46
+ const matched = [...new Set(input.resolution)].sort().filter(protectedPath)
47
+ if (matched.length === 0) return undefined
48
+ return {
49
+ commandSeq: command.seq,
50
+ source: input.source,
51
+ rule: { index: command.rule.index, snapshot: { ...command.rule.snapshot } },
52
+ previousHead: input.previousHead,
53
+ head: input.head,
54
+ ...(command.head === undefined ? {} : { consentedHead: command.head }),
55
+ paths: { total: matched.length, preview: matched.slice(0, LANDING_MATCHED_PATHS_PREVIEW) },
56
+ }
57
+ }
58
+
59
+ /** The complete resolution paths behind a recorded head, without git: the
60
+ * facts just deposited, else a complete summary preview, else one artifact
61
+ * read (a retried terminal recording a resolution beyond the preview). */
62
+ export async function resolutionPathsFor(
63
+ store: Pick<BuildStore, 'getArtifact'>,
64
+ slug: string,
65
+ recorded: RecordedHeadPaths,
66
+ ): Promise<string[]> {
67
+ if (recorded.recorded === 'appended') return recorded.facts.resolution?.paths ?? []
68
+ const resolution = recorded.record.resolution
69
+ if (resolution === undefined) return []
70
+ if (resolution.total === resolution.preview.length) return [...resolution.preview]
71
+ return (await readHeadPaths(store, slug, recorded.record)).resolution?.paths ?? []
72
+ }
@@ -2,14 +2,16 @@ import type { TicketRef } from '../ontology'
2
2
  import type { BuildRecord } from '../store/types'
3
3
  import type { BuildState } from './reducer'
4
4
  import { integrationAdmissible, integrationNeedsRunner } from './integration-state'
5
+ import { waitParked, waitResumeDue } from './ticket-wait'
5
6
 
6
7
  /** Repository-scoped, reduced facts. Provisioning reserves a slot before a workspace exists.
7
8
  *
8
- * `capacity` counts builds running work. A leaf that has finished its pipeline
9
- * (settled, see `epilogueLeaf`) and holds no runner is parked: it waits for a
10
- * merge decision, merge gates or the forge and holds no slot, though it keeps
9
+ * `capacity` counts builds running work. A leaf that holds no runner is
10
+ * parked when it has finished its pipeline (settled, see `epilogueLeaf`) and
11
+ * waits for a merge decision, merge gates or the forge, or when it waits on
12
+ * other tickets (`waitParked`). A parked leaf holds no slot, though it keeps
11
13
  * its workspace. Every other unfinished leaf holds a slot, paused or blocked
12
- * included. Nodes hold a slot only while they need a runner. */
14
+ * on a question included. Nodes hold a slot only while they need a runner. */
13
15
  export interface CapacityBuild {
14
16
  record: BuildRecord
15
17
  state: BuildState
@@ -19,8 +21,9 @@ export interface CapacityBuild {
19
21
  restackDue?: boolean
20
22
  }
21
23
 
22
- /** The runner a node or parked leaf has durably requested and does not yet hold. */
23
- export type SlotRequest = 'verification' | 'reconcile'
24
+ /** The runner a node or parked leaf has durably requested and does not yet
25
+ * hold. `resume` is a leaf whose ticket wait ended. */
26
+ export type SlotRequest = 'verification' | 'reconcile' | 'resume'
24
27
 
25
28
  export interface DispatchCapacity {
26
29
  configured: number
@@ -74,9 +77,14 @@ function executionOpen(state: BuildState): boolean {
74
77
  return state.openExecution?.commandId !== undefined
75
78
  }
76
79
 
77
- /** A finished leaf with no runner working. It holds no slot; its workspace does not count. */
80
+ /** A finished or ticket-waiting leaf with no runner working. It holds no
81
+ * slot; its workspace does not count. */
78
82
  export function parkedLeaf(build: CapacityBuild, now: Date): boolean {
79
- return epilogueLeaf(build.state) && !runnerAllocated(build, now) && !executionOpen(build.state)
83
+ return (
84
+ (epilogueLeaf(build.state) || waitParked(build.state)) &&
85
+ !runnerAllocated(build, now) &&
86
+ !executionOpen(build.state)
87
+ )
80
88
  }
81
89
 
82
90
  /** A finished leaf whose latest verify cycle or finalize has not been settled
@@ -114,6 +122,9 @@ function leafSlotRequest(build: CapacityBuild, now: Date): SlotRequest | undefin
114
122
  state.targetRewrite !== undefined
115
123
  )
116
124
  return undefined
125
+ // A ticket wait parks a leaf mid-pipeline: it asks for a slot only once the
126
+ // wait has ended, to resume the phase that declared it.
127
+ if (waitParked(state)) return waitResumeDue(state) ? 'resume' : undefined
117
128
  if (state.prState === 'conflicted') return 'reconcile'
118
129
  if (build.restackDue || epilogueUnsettled(state)) return 'verification'
119
130
  return undefined
@@ -43,6 +43,8 @@ import {
43
43
  import { indexLog, type LogIndex, type LoopIndex } from './log-index'
44
44
  import { reduceBuild, type AnsweredEscalation, type BuildState } from './reducer'
45
45
  import { stalledChains, type FindingChain } from './stall'
46
+ import { pendingWaitRequest, waitGuidance, waitResumeRestackCycle } from './ticket-wait'
47
+ import { leafRestackedBase } from './leaf-restack-state'
46
48
 
47
49
  // ── The decision contract ────────────────────────────────────────────────────
48
50
 
@@ -51,6 +53,7 @@ export type WaitReason =
51
53
  | 'publication-retry'
52
54
  | 'verify-stage'
53
55
  | 'mixed-version'
56
+ | 'ticket-wait'
54
57
  | 'blocked'
55
58
  | 'paused'
56
59
  | 'awaiting-spec'
@@ -96,7 +99,11 @@ export type Decision =
96
99
  failure: import('../events/payloads').EventPayload<'verify.stage-failed'>
97
100
  }
98
101
  | ({ kind: 'raise-read-deferral' } & import('./read-deferrals').ReadDeferral)
99
- | { kind: 'restack'; trigger: 'verify-entry' | 'awaiting-landing'; cycle: number }
102
+ | {
103
+ kind: 'restack'
104
+ trigger: 'verify-entry' | 'awaiting-landing' | 'wait-resume'
105
+ cycle: number
106
+ }
100
107
  | { kind: 'capture-reconcile-policy'; reconcileSeq: number }
101
108
  | { kind: 'wait'; reason: WaitReason }
102
109
  | { kind: 'acknowledge'; command: 'pause' | 'resume' | 'abort' }
@@ -230,6 +237,11 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
230
237
  return { kind: 'acknowledge', command: 'pause' }
231
238
  }
232
239
 
240
+ // A declared ticket wait parks the build until the dispatcher validates it
241
+ // (SPEC §11 "Ticket waits"): accepted, it becomes an open escalation below;
242
+ // refused, the declaring phase re-runs with the refusal as guidance.
243
+ if (pendingWaitRequest(state)) return { kind: 'wait', reason: 'ticket-wait' }
244
+
233
245
  // Frozen transactions retain their original destination and may recover.
234
246
  if (state.targetRewrite && !log.restack.active && !state.nodeRestack?.active)
235
247
  return { kind: 'wait', reason: 'target-rewritten' }
@@ -273,6 +285,7 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
273
285
  (e) =>
274
286
  !(
275
287
  stage &&
288
+ e.wait === undefined &&
276
289
  e.source === 'agent' &&
277
290
  e.session !== undefined &&
278
291
  stage.stage.some(
@@ -450,10 +463,13 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
450
463
  // same-destination answers, so consuming the winner cannot reveal one of them
451
464
  // later. An answer appended after that delivery becomes the new winner and
452
465
  // remains eligible.
466
+ // A refused ticket wait is guidance for the phase that declared it, keyed by
467
+ // the wait request id and delivered by the same rule.
453
468
  const guidanceFeedback = (destination: GuidanceDestination): Feedback | undefined => {
454
- let latest: AnsweredEscalation | undefined
455
- for (const e of state.answeredEscalations) {
456
- if (e.resolution !== 'guidance' || guidanceDestination(e) !== destination) continue
469
+ let latest: Pick<AnsweredEscalation, 'id' | 'answer' | 'answeredSeq'> | undefined
470
+ for (const e of [...state.answeredEscalations, ...waitGuidance(state)]) {
471
+ if ('resolution' in e && e.resolution !== 'guidance') continue
472
+ if (guidanceDestination(e) !== destination) continue
457
473
  if (latest === undefined || e.answeredSeq > latest.answeredSeq) latest = e
458
474
  }
459
475
  if (
@@ -496,6 +512,22 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
496
512
  ? undefined
497
513
  : { verify: { step: pendingFail.step, report: pendingFail.report } }
498
514
 
515
+ // ── Wait resume (SPEC §11 "Ticket waits"): a build leaving a ticket wait
516
+ // first restacks onto its target's current head, so the declaring phase
517
+ // sees the merged blockers. Supersession of a reconcile-declared wait or a
518
+ // fresh wait-resume restack outranks every open transaction, including an
519
+ // earlier wait-resume conflict. Never-waited builds have no `state.wait`.
520
+ const waitCycle = waitResumeRestackCycle(state, log)
521
+ if (waitCycle !== undefined) return { kind: 'restack', trigger: 'wait-resume', cycle: waitCycle }
522
+ const waitRestack = log.restack.active?.trigger === 'wait-resume' ? log.restack.active : undefined
523
+ if (waitRestack) {
524
+ if (log.restack.replay?.conflicted) {
525
+ const round = log.restack.reconcileAttempt ?? state.reconcileAttempts + 1
526
+ return { kind: 'run-phase', phase: 'reconcile', round, reconcile: { attempt: round } }
527
+ }
528
+ return { kind: 'restack', trigger: 'wait-resume', cycle: waitRestack.cycle }
529
+ }
530
+
499
531
  // ── 5. Plan loop (§5, §10): rounds pair plan ⇄ plan-review ─────────────────
500
532
  const planDecision = decideLoop({
501
533
  loop: log.plan,
@@ -842,7 +874,7 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
842
874
  export function landingRestackDue(state: BuildState, log: Pick<LogIndex, 'restack'>): boolean {
843
875
  return (
844
876
  log.restack.target !== undefined &&
845
- (log.restack.target.sha !== (log.restack.completed?.targetBase ?? log.restack.initialBase) ||
877
+ (log.restack.target.sha !== leafRestackedBase(log.restack) ||
846
878
  (state.target !== undefined &&
847
879
  (log.restack.postStepAt ?? 0) > (log.restack.completedAt ?? 0)))
848
880
  )
@@ -986,17 +1018,25 @@ type GuidanceDestination = 'plan' | 'code' | `verify:${string}` | 'other'
986
1018
  * feeds implement. Finalize/reconcile guidance travels through `ab context`.
987
1019
  */
988
1020
  function guidanceDestination(
989
- escalation: Pick<AnsweredEscalation, 'phase' | 'source' | 'deferral'>,
1021
+ escalation: Pick<AnsweredEscalation, 'phase' | 'source' | 'deferral' | 'wait'>,
990
1022
  ): GuidanceDestination {
991
1023
  const { phase, source } = escalation
1024
+ // A reviewer's own-build-read deferral or ticket wait re-runs that same
1025
+ // review round, which reads its guidance through `ab context`.
992
1026
  if (
993
- escalation.deferral === 'own-build-read' &&
1027
+ (escalation.deferral === 'own-build-read' || escalation.wait !== undefined) &&
994
1028
  (phase === 'plan-review' || phase === 'code-review')
995
1029
  )
996
1030
  return 'other'
997
1031
  if (phase === 'plan' || phase === 'plan-review') return 'plan'
998
1032
  if (phase === 'implement' || phase === 'code-review') return 'code'
1033
+ // A ticket wait's escalations, including the dispatcher's unresolvable
1034
+ // raise that ended one, resume the verify step that declared it.
999
1035
  if (isVerifyPhase(phase))
1000
- return source === 'agent' || escalation.deferral === 'own-build-read' ? phase : 'code'
1036
+ return source === 'agent' ||
1037
+ escalation.deferral === 'own-build-read' ||
1038
+ escalation.wait !== undefined
1039
+ ? phase
1040
+ : 'code'
1001
1041
  return 'other'
1002
1042
  }
@@ -0,0 +1,63 @@
1
+ /** Pure half of the head path facts (`kernel/head-paths.ts`): the folded
2
+ * summary shape, the reducer step and the selectors. No IO, so the build
3
+ * reducer can import it. */
4
+ import type { EventPayload } from '../events/payloads'
5
+ import { HEAD_PATHS_RECORDS } from '../events/head-paths-limits'
6
+ import type { BuildState } from './reducer'
7
+
8
+ export type HeadPathsPayload = EventPayload<'head.paths-recorded'>
9
+ export type HeadPathsSource = HeadPathsPayload['source']
10
+ /** One folded fact: the event's bounded summary plus its seq. */
11
+ export type HeadPathsSummary = HeadPathsPayload & { seq: number }
12
+
13
+ export type HeadPathsAnswer = { recorded: false } | { recorded: true; record: HeadPathsSummary }
14
+
15
+ // ── Selectors (pure, no IO) ──────────────────────────────────────────────────
16
+
17
+ /** The head a landing decision would judge: a node's integration-cycle head,
18
+ * a leaf's PR head. */
19
+ export function candidateHead(
20
+ state: Pick<BuildState, 'kind' | 'integration' | 'pr'>,
21
+ ): string | undefined {
22
+ return state.kind === 'node' ? state.integration?.cycle?.head : state.pr?.headSha
23
+ }
24
+
25
+ /** "Not recorded" is distinct from "recorded and empty". */
26
+ export function headPathsFor(
27
+ state: Pick<BuildState, 'headPaths'>,
28
+ head: string | undefined,
29
+ ): HeadPathsAnswer {
30
+ const record = head === undefined ? undefined : state.headPaths?.find((r) => r.head === head)
31
+ return record === undefined ? { recorded: false } : { recorded: true, record }
32
+ }
33
+
34
+ export function candidateHeadPaths(
35
+ state: Pick<BuildState, 'kind' | 'integration' | 'pr' | 'headPaths'>,
36
+ ): HeadPathsAnswer {
37
+ return headPathsFor(state, candidateHead(state))
38
+ }
39
+
40
+ /** Reducer step: the first summary per head wins (retries and races record
41
+ * the same head again), and only the newest `HEAD_PATHS_RECORDS` are kept. */
42
+ export function foldHeadPaths(
43
+ current: readonly HeadPathsSummary[] | undefined,
44
+ payload: HeadPathsPayload,
45
+ seq: number,
46
+ ): HeadPathsSummary[] | undefined {
47
+ if (current?.some((record) => record.head === payload.head)) return current as HeadPathsSummary[]
48
+ const { source, head, destination, mergeBase, total, preview, resolution, artifact } = payload
49
+ const record: HeadPathsSummary = {
50
+ source,
51
+ head,
52
+ destination,
53
+ mergeBase,
54
+ total,
55
+ preview: [...preview],
56
+ ...(resolution === undefined
57
+ ? {}
58
+ : { resolution: { total: resolution.total, preview: [...resolution.preview] } }),
59
+ artifact: { kind: artifact.kind, rev: artifact.rev },
60
+ seq,
61
+ }
62
+ return [...(current ?? []), record].slice(-HEAD_PATHS_RECORDS)
63
+ }