@defrex/autobuild 0.13.0 → 1.0.0-beta.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 +5 -3
- package/SPEC.md +673 -99
- package/bin/ab-dispatch-kernel.ts +4 -6
- package/docs/architecture.md +322 -75
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +112 -12
- package/docs/hosted-service.md +20 -2
- package/docs/integration-tree.md +117 -0
- package/docs/landing-policy.md +150 -0
- package/docs/mcp.md +24 -0
- package/docs/migration-1.0.md +68 -0
- package/docs/operator-api.md +20 -9
- package/docs/remote-store-protocol.md +114 -9
- package/docs/remote-ticket-protocol.md +26 -5
- package/docs/restacking.md +79 -0
- package/docs/setup.md +49 -6
- package/docs/ticket-dependencies.md +69 -0
- package/docs/ticket-migration.md +8 -0
- package/package.json +4 -3
- package/packages/core/src/cli/attention.ts +40 -163
- package/packages/core/src/cli/build-control.ts +75 -55
- package/packages/core/src/cli/bulk-control.ts +3 -2
- package/packages/core/src/cli/context.ts +68 -78
- package/packages/core/src/cli/dashboard/actions.ts +6 -3
- package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
- package/packages/core/src/cli/dashboard/live.ts +5 -0
- package/packages/core/src/cli/dashboard/model.ts +178 -40
- package/packages/core/src/cli/dashboard/poll.ts +15 -9
- package/packages/core/src/cli/dashboard/refresh.ts +176 -0
- package/packages/core/src/cli/dashboard/render.ts +78 -28
- package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
- package/packages/core/src/cli/dashboard/selection.ts +7 -1
- package/packages/core/src/cli/dashboard/tree.ts +107 -0
- package/packages/core/src/cli/dispatch-frontend.ts +173 -169
- package/packages/core/src/cli/dispatch-process.ts +14 -7
- package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
- package/packages/core/src/cli/dispatch.ts +397 -214
- package/packages/core/src/cli/dispatcher-liveness.ts +41 -21
- package/packages/core/src/cli/harvest.ts +71 -39
- package/packages/core/src/cli/help.ts +49 -32
- package/packages/core/src/cli/historical-build-state.ts +27 -0
- package/packages/core/src/cli/init-validation.ts +43 -2
- package/packages/core/src/cli/keyboard.ts +6 -0
- package/packages/core/src/cli/landings.ts +18 -0
- package/packages/core/src/cli/main.ts +52 -18
- package/packages/core/src/cli/mcp.ts +9 -0
- package/packages/core/src/cli/pr-attachments.ts +10 -13
- package/packages/core/src/cli/pr-summary-publication.ts +27 -60
- package/packages/core/src/cli/pr-summary.ts +43 -13
- package/packages/core/src/cli/publication-settlement.ts +177 -21
- package/packages/core/src/cli/repository-status.ts +49 -2
- package/packages/core/src/cli/status.ts +133 -36
- package/packages/core/src/cli/terminal-restore.ts +54 -0
- package/packages/core/src/cli/terminal.ts +16 -2
- package/packages/core/src/cli/terminals.ts +121 -219
- package/packages/core/src/cli/ticket-editor.ts +10 -3
- package/packages/core/src/cli/ticket.ts +115 -20
- package/packages/core/src/cli/upgrade-commit.ts +4 -0
- package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
- package/packages/core/src/cli/upgrade-landing.ts +69 -0
- package/packages/core/src/cli/upgrade.ts +16 -0
- package/packages/core/src/cli/wait.ts +194 -91
- package/packages/core/src/cli/watch.ts +111 -109
- package/packages/core/src/config/landing.ts +22 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/pipeline-source.ts +4 -3
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +48 -3
- package/packages/core/src/events/payloads.ts +295 -6
- package/packages/core/src/events/repository.ts +38 -3
- package/packages/core/src/integration/harness.ts +11 -2
- package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +3330 -119
- package/packages/core/src/kernel/auto-merge-default.ts +1 -0
- package/packages/core/src/kernel/auto-merge.ts +29 -4
- package/packages/core/src/kernel/build-identity.ts +94 -0
- package/packages/core/src/kernel/change-presence.ts +179 -0
- package/packages/core/src/kernel/dispatch-status.ts +17 -1
- package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
- package/packages/core/src/kernel/engine.ts +89 -2
- package/packages/core/src/kernel/generators/build-log.ts +23 -0
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +25 -3
- package/packages/core/src/kernel/harvest.ts +25 -23
- package/packages/core/src/kernel/integration-completeness.ts +81 -0
- package/packages/core/src/kernel/integration-landing.ts +263 -0
- package/packages/core/src/kernel/integration-stack.ts +36 -0
- package/packages/core/src/kernel/integration-state.ts +135 -0
- package/packages/core/src/kernel/landing-policy.ts +47 -0
- package/packages/core/src/kernel/landing-publication.ts +41 -0
- package/packages/core/src/kernel/landing-readiness.ts +67 -0
- package/packages/core/src/kernel/landing-state.ts +96 -0
- package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
- package/packages/core/src/kernel/log-index-value.ts +38 -0
- package/packages/core/src/kernel/log-index.ts +35 -5
- package/packages/core/src/kernel/node-landing.ts +439 -0
- package/packages/core/src/kernel/node-parent.ts +184 -0
- package/packages/core/src/kernel/node-restack-state.ts +191 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
- package/packages/core/src/kernel/node-restack.ts +274 -0
- package/packages/core/src/kernel/read-facts.ts +704 -0
- package/packages/core/src/kernel/reconcile-head.ts +51 -0
- package/packages/core/src/kernel/reconcile-restack.ts +560 -0
- package/packages/core/src/kernel/reducer-registry.ts +153 -3
- package/packages/core/src/kernel/reducer.ts +121 -6
- package/packages/core/src/kernel/repository-attention.ts +179 -0
- package/packages/core/src/kernel/service-facts.ts +135 -0
- package/packages/core/src/kernel/snapshot-parent.ts +33 -0
- package/packages/core/src/kernel/terminal-guard.ts +133 -0
- package/packages/core/src/ontology.ts +9 -1
- package/packages/core/src/operator/annotations.ts +12 -0
- package/packages/core/src/operator/control.ts +11 -6
- package/packages/core/src/operator/index.ts +6 -0
- package/packages/core/src/operator/landings.ts +35 -0
- package/packages/core/src/operator/presentation.ts +1 -0
- package/packages/core/src/operator/protocol.ts +12 -3
- package/packages/core/src/operator/query.ts +40 -21
- package/packages/core/src/operator/read-view.ts +4 -13
- package/packages/core/src/operator/registry.ts +48 -19
- package/packages/core/src/operator/requests.ts +3 -22
- package/packages/core/src/operator/sandbox.ts +10 -9
- package/packages/core/src/operator/tickets.ts +57 -11
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/ports/forge/contract.ts +91 -3
- package/packages/core/src/ports/forge/fake.ts +142 -4
- package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
- package/packages/core/src/ports/forge/github-readiness.ts +421 -0
- package/packages/core/src/ports/forge/github.ts +631 -35
- package/packages/core/src/ports/forge/local-git.ts +119 -5
- package/packages/core/src/ports/forge/readiness.ts +99 -0
- package/packages/core/src/ports/tickets/contract.ts +41 -0
- package/packages/core/src/ports/tickets/create.ts +8 -1
- package/packages/core/src/ports/tickets/fake.ts +32 -1
- package/packages/core/src/ports/tickets/file-codec.ts +7 -0
- package/packages/core/src/ports/tickets/file.ts +18 -1
- package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
- package/packages/core/src/ports/tickets/linear.ts +124 -4
- package/packages/core/src/ports/tickets/migration.ts +25 -1
- package/packages/core/src/ports/tickets/operations.ts +7 -2
- package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
- package/packages/core/src/ports/tickets/remote.ts +10 -1
- package/packages/core/src/ports/tickets/revision.ts +3 -1
- package/packages/core/src/ports/tickets/tree.ts +148 -0
- package/packages/core/src/ports/tickets/update.ts +15 -2
- package/packages/core/src/ports/types.ts +135 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
- package/packages/core/src/processes/build-child.ts +6 -6
- package/packages/core/src/processes/build-runner.ts +586 -87
- package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
- package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
- package/packages/core/src/processes/dispatcher.ts +2239 -357
- package/packages/core/src/processes/execution-no-progress.ts +46 -1
- package/packages/core/src/processes/harvest-execution-state.ts +15 -9
- package/packages/core/src/processes/harvest-runner.ts +34 -70
- package/packages/core/src/processes/harvest.ts +38 -15
- package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
- package/packages/core/src/processes/orchestrator-tick.ts +2 -2
- package/packages/core/src/processes/publication-loss.ts +35 -21
- package/packages/core/src/processes/publication-state.ts +30 -5
- package/packages/core/src/processes/repo-view.ts +244 -1130
- package/packages/core/src/processes/tick-publication.ts +110 -0
- package/packages/core/src/store/adapter.ts +23 -0
- package/packages/core/src/store/build-scope.ts +35 -0
- package/packages/core/src/store/contract.ts +909 -0
- package/packages/core/src/store/digest.ts +52 -4
- package/packages/core/src/store/local/schema.ts +26 -13
- package/packages/core/src/store/local/store.ts +296 -55
- package/packages/core/src/store/memory.ts +181 -30
- package/packages/core/src/store/phase-session.ts +34 -0
- package/packages/core/src/store/reduced-reads.ts +240 -0
- package/packages/core/src/store/reducer-value-shapes.json +18323 -0
- package/packages/core/src/store/reducer-value-validation.ts +96 -0
- package/packages/core/src/store/reducer-values.ts +145 -0
- package/packages/core/src/store/remote/client.ts +85 -0
- package/packages/core/src/store/remote/compatibility.ts +21 -9
- package/packages/core/src/store/remote/index.ts +19 -0
- package/packages/core/src/store/remote/protocol.ts +27 -0
- package/packages/core/src/store/remote/version.ts +3 -1
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +72 -0
- package/packages/core/src/store/session-handle.ts +34 -0
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/subscribe.ts +1 -1
- package/packages/core/src/store/ticket-assets.ts +4 -4
- package/packages/core/src/store/types.ts +71 -6
- package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
- package/packages/core/src/testing/index.ts +10 -0
- package/packages/core/src/testing/reduced-read-budget.ts +502 -0
- package/packages/core/src/testing/refresh-scheduler.ts +32 -0
- package/skills/guide/SKILL.md +116 -62
- package/skills/guide/references/integration-tree.md +117 -0
- package/skills/guide/references/landing-policy.md +150 -0
- package/skills/guide/references/migration-1.0.md +68 -0
- package/skills/guide/references/operator-api.md +13 -6
- package/skills/guide/references/plugin-authoring.md +34 -0
- package/skills/guide/references/remote-store-protocol.md +114 -9
- package/skills/guide/references/remote-ticket-protocol.md +26 -5
- package/skills/guide/references/restacking.md +79 -0
- package/skills/guide/references/setup.md +49 -6
- package/skills/guide/references/ticket-dependencies.md +69 -0
- package/skills/guide/references/ticket-migration.md +8 -0
- package/skills/operate/SKILL.md +55 -5
- package/skills/reconcile/SKILL.md +55 -48
- package/skills/spec/SKILL.md +67 -1
- package/skills/tickets/SKILL.md +55 -2
- package/templates/autobuild.toml +3 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -32,6 +32,13 @@ export const BRACKETED_PASTE_MODE = {
|
|
|
32
32
|
restoreOrder: 20,
|
|
33
33
|
} as const satisfies TerminalMode
|
|
34
34
|
|
|
35
|
+
export const FOCUS_REPORTING_MODE = {
|
|
36
|
+
name: 'focus-reporting',
|
|
37
|
+
enter: '\x1b[?1004h',
|
|
38
|
+
restore: '\x1b[?1004l',
|
|
39
|
+
restoreOrder: 5,
|
|
40
|
+
} as const satisfies TerminalMode
|
|
41
|
+
|
|
35
42
|
export const KITTY_KEYBOARD_FLAGS = 0b1_1101
|
|
36
43
|
|
|
37
44
|
export const KITTY_KEYBOARD_MODE = {
|
|
@@ -172,3 +179,50 @@ export function installTerminalRestoreHook(
|
|
|
172
179
|
},
|
|
173
180
|
}
|
|
174
181
|
}
|
|
182
|
+
|
|
183
|
+
/** Presentation-owned job control. The kernel is a separately supervised
|
|
184
|
+
* process and is deliberately absent from these callbacks. */
|
|
185
|
+
export function installPresentationSuspension(
|
|
186
|
+
modes: TerminalModeController,
|
|
187
|
+
suspend: () => void,
|
|
188
|
+
resume: () => void,
|
|
189
|
+
boundary: TerminalRestoreProcess = process as unknown as TerminalRestoreProcess,
|
|
190
|
+
): { close(): void; suspend(): void } {
|
|
191
|
+
let closed = false
|
|
192
|
+
let paused = false
|
|
193
|
+
let saved: readonly TerminalMode[] = []
|
|
194
|
+
const onContinue = (): void => {
|
|
195
|
+
if (closed || !paused) return
|
|
196
|
+
paused = false
|
|
197
|
+
resume()
|
|
198
|
+
for (const mode of saved) modes.enter(mode)
|
|
199
|
+
saved = []
|
|
200
|
+
}
|
|
201
|
+
const onStop = (): void => {
|
|
202
|
+
if (closed || paused) return
|
|
203
|
+
paused = true
|
|
204
|
+
saved = modes.activeModes
|
|
205
|
+
modes.restoreAll()
|
|
206
|
+
suspend()
|
|
207
|
+
boundary.removeListener('SIGTSTP', onStop)
|
|
208
|
+
// Replay with the default disposition. SIGCONT reinstalls our handler.
|
|
209
|
+
boundary.kill(boundary.pid, 'SIGTSTP')
|
|
210
|
+
}
|
|
211
|
+
const continued = (): void => {
|
|
212
|
+
if (closed) return
|
|
213
|
+
boundary.removeListener('SIGTSTP', onStop)
|
|
214
|
+
boundary.on('SIGTSTP', onStop)
|
|
215
|
+
onContinue()
|
|
216
|
+
}
|
|
217
|
+
boundary.on('SIGTSTP', onStop)
|
|
218
|
+
boundary.on('SIGCONT', continued)
|
|
219
|
+
return {
|
|
220
|
+
suspend: onStop,
|
|
221
|
+
close(): void {
|
|
222
|
+
closed = true
|
|
223
|
+
saved = []
|
|
224
|
+
boundary.removeListener('SIGTSTP', onStop)
|
|
225
|
+
boundary.removeListener('SIGCONT', continued)
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -44,6 +44,9 @@ export type TerminalInputEvent =
|
|
|
44
44
|
| { type: 'paste'; text: string }
|
|
45
45
|
|
|
46
46
|
export interface TerminalInputHooks {
|
|
47
|
+
onFocus?(focused: boolean): void
|
|
48
|
+
onInteraction?(): void
|
|
49
|
+
onSuspend?(): void
|
|
47
50
|
onListening?(): void
|
|
48
51
|
onKeyboardFlags?(flags: number): void
|
|
49
52
|
onDeviceAttributes?(): void
|
|
@@ -169,6 +172,9 @@ export function createTerminalInputDecoder(hooks: TerminalInputHooks = {}): Term
|
|
|
169
172
|
let watch: string | undefined
|
|
170
173
|
|
|
171
174
|
const reportEvent = (report: CsiReport): TerminalInputEvent | undefined => {
|
|
175
|
+
if (report.kind === 'suspend') hooks.onSuspend?.()
|
|
176
|
+
if (report.kind === 'focus') hooks.onFocus?.(report.focused)
|
|
177
|
+
if (report.kind === 'ignored') hooks.onInteraction?.()
|
|
172
178
|
if (report.kind === 'input') return report.event
|
|
173
179
|
if (report.kind === 'keyboard-flags') hooks.onKeyboardFlags?.(report.flags)
|
|
174
180
|
if (report.kind === 'device-attributes') hooks.onDeviceAttributes?.()
|
|
@@ -267,11 +273,15 @@ export function createTerminalInputDecoder(hooks: TerminalInputHooks = {}): Term
|
|
|
267
273
|
}
|
|
268
274
|
|
|
269
275
|
const restart = fragment.startsWith('\x1b[')
|
|
270
|
-
if (csi !== undefined ||
|
|
276
|
+
if (csi !== undefined || restart) {
|
|
271
277
|
const consumed = consumeCsi(fragment, restart)
|
|
272
278
|
if (consumed.consumed) return consumed.event
|
|
273
279
|
}
|
|
274
280
|
|
|
281
|
+
if (key.ctrl === true && key.name === 'z') {
|
|
282
|
+
hooks.onSuspend?.()
|
|
283
|
+
return undefined
|
|
284
|
+
}
|
|
275
285
|
if (key.name === 'up') return { type: 'up' }
|
|
276
286
|
if (key.name === 'down') return { type: 'down' }
|
|
277
287
|
if (key.name === 'left') return { type: 'left' }
|
|
@@ -287,7 +297,10 @@ export function createTerminalInputDecoder(hooks: TerminalInputHooks = {}): Term
|
|
|
287
297
|
}
|
|
288
298
|
if (key.name === 'escape' || key.sequence === '\u001b') return { type: 'escape' }
|
|
289
299
|
|
|
290
|
-
if (key.ctrl === true || key.meta === true)
|
|
300
|
+
if (key.ctrl === true || key.meta === true) {
|
|
301
|
+
hooks.onInteraction?.()
|
|
302
|
+
return undefined
|
|
303
|
+
}
|
|
291
304
|
const printable =
|
|
292
305
|
text ??
|
|
293
306
|
(key.name?.length === 1 ? key.name : key.sequence !== undefined ? key.sequence : undefined)
|
|
@@ -296,6 +309,7 @@ export function createTerminalInputDecoder(hooks: TerminalInputHooks = {}): Term
|
|
|
296
309
|
printable.length === 0 ||
|
|
297
310
|
/[\u0000-\u001f\u007f]/u.test(printable)
|
|
298
311
|
) {
|
|
312
|
+
hooks.onInteraction?.()
|
|
299
313
|
return undefined
|
|
300
314
|
}
|
|
301
315
|
return { type: 'text', text: printable }
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { suspendNativeLanding } from '../kernel/landing-publication'
|
|
2
|
+
import { validateNodeChange } from '../kernel/node-restack'
|
|
3
|
+
import { validateRestack, retainReplay } from '../kernel/reconcile-restack'
|
|
4
|
+
import { readBuildFacts, readTerminalGuard, type CurrentBuildFacts } from '../store/reduced-reads'
|
|
1
5
|
/**
|
|
2
6
|
* The three terminal commands — `ab done`, `ab verdict`, `ab escalate`
|
|
3
7
|
* (SPEC §8.4 D5, §8.5 D6, §8.6 D7).
|
|
@@ -18,18 +22,12 @@
|
|
|
18
22
|
import { join } from 'node:path'
|
|
19
23
|
import { z } from 'zod'
|
|
20
24
|
import { loadConfig } from '../config/load'
|
|
21
|
-
import type {
|
|
25
|
+
import type { EventEnvelope } from '../events/catalog'
|
|
22
26
|
import { agentActor, KERNEL } from '../events/envelope'
|
|
23
27
|
import { isRemoteWorkspace } from '../events/workspace-remote'
|
|
24
28
|
import type { IdSource } from '../ids'
|
|
25
|
-
import {
|
|
26
|
-
autoMergeApplicationType,
|
|
27
|
-
pendingAutoMerge,
|
|
28
|
-
recordAutoMergeDeferralObservation,
|
|
29
|
-
} from '../kernel/auto-merge'
|
|
30
29
|
import { phaseSpecFor } from '../kernel/phases'
|
|
31
30
|
import { resolvePlanVerifySteps } from '../kernel/plan-verify-selection'
|
|
32
|
-
import { reduceBuild } from '../kernel/reducer'
|
|
33
31
|
import {
|
|
34
32
|
findingDraftSchema,
|
|
35
33
|
isVerifyPhase,
|
|
@@ -40,11 +38,7 @@ import {
|
|
|
40
38
|
type ReviewVerdictKind,
|
|
41
39
|
} from '../ontology'
|
|
42
40
|
import type { Forge } from '../ports/types'
|
|
43
|
-
import {
|
|
44
|
-
phaseScratchRejection,
|
|
45
|
-
reconcileScratchViolations,
|
|
46
|
-
scratchPathsTouchedInRange,
|
|
47
|
-
} from '../ports/workspace/phase-scratch'
|
|
41
|
+
import { phaseScratchRejection, scratchPathsTouchedInRange } from '../ports/workspace/phase-scratch'
|
|
48
42
|
import type { Exec } from '../ports/workspace/git-worktree'
|
|
49
43
|
import type { ArtifactMeta, BuildStore } from '../store/types'
|
|
50
44
|
import { textContent } from '../store/types'
|
|
@@ -75,114 +69,9 @@ export interface TerminalDeps {
|
|
|
75
69
|
* round, so a still-in-flight CLI process from the failed session must not
|
|
76
70
|
* land a terminal the runner will misattribute to the retry).
|
|
77
71
|
*/
|
|
78
|
-
function assertNoPriorTerminal(
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
// across a spec.revised (decideNext ignores pre-restart results and
|
|
82
|
-
// re-runs the pipeline from plan), so a pre-restart verify.completed or
|
|
83
|
-
// finalize.completed must not shadow the rebuilt pipeline's terminal.
|
|
84
|
-
// Loop-phase rounds continue monotonically across restarts (engine
|
|
85
|
-
// LoopIndex.maxRoundEver) and never collide, so they match over the full
|
|
86
|
-
// log; the reconcile epilogue is restart-orthogonal (§15.7).
|
|
87
|
-
let restartSeq = 0
|
|
88
|
-
for (const event of events) {
|
|
89
|
-
if (event.type === 'spec.revised') restartSeq = event.seq
|
|
90
|
-
}
|
|
91
|
-
// reconcile.completed carries no attempt (§15.3); pair it with the latest
|
|
92
|
-
// reconcile.started seen before it.
|
|
93
|
-
let reconcileAttempt = 0
|
|
94
|
-
let sessionStartedSeq: number | undefined
|
|
95
|
-
for (const event of events) {
|
|
96
|
-
if (event.type === 'reconcile.started') reconcileAttempt = event.payload.attempt
|
|
97
|
-
if (event.type === 'session.started' && event.payload.session === env.session) {
|
|
98
|
-
sessionStartedSeq = event.seq
|
|
99
|
-
}
|
|
100
|
-
if (event.type === 'session.ended' && event.payload.session === env.session) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
`terminal rejected (D5): session "${env.session}" already ended ` +
|
|
103
|
-
`(session.ended at seq ${event.seq}) — a session that ended without ` +
|
|
104
|
-
'a terminal was failed and retried; only the live retry may complete ' +
|
|
105
|
-
'this phase round (§8.4).',
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
if (
|
|
109
|
-
sessionStartedSeq !== undefined &&
|
|
110
|
-
event.type === 'phase.failed' &&
|
|
111
|
-
event.payload.phase === env.phase &&
|
|
112
|
-
event.payload.round === env.round &&
|
|
113
|
-
event.seq > sessionStartedSeq
|
|
114
|
-
) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`terminal rejected (D5): ${env.phase}@${env.round} already failed after ` +
|
|
117
|
-
`this session started (phase.failed at seq ${event.seq}) — the retry ` +
|
|
118
|
-
'session owns this round now (§8.4).',
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
if (
|
|
122
|
-
event.type === 'escalation.raised' &&
|
|
123
|
-
event.actor.kind === 'agent' &&
|
|
124
|
-
event.actor.session === env.session
|
|
125
|
-
) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`second terminal call rejected (D5): this session already escalated — ` +
|
|
128
|
-
`escalation.raised "${event.payload.id}" at seq ${event.seq}. ` +
|
|
129
|
-
'Every phase ends with exactly one terminal command (§8.4).',
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
if (
|
|
133
|
-
event.type === 'publication.requested' &&
|
|
134
|
-
event.actor.kind === 'agent' &&
|
|
135
|
-
event.actor.session === env.session &&
|
|
136
|
-
((env.phase === 'implement' &&
|
|
137
|
-
event.payload.operation === 'implement' &&
|
|
138
|
-
event.payload.round === env.round) ||
|
|
139
|
-
(env.phase === 'reconcile' && event.payload.operation === 'reconcile') ||
|
|
140
|
-
(env.phase === 'finalize' && event.payload.operation === 'finalize'))
|
|
141
|
-
) {
|
|
142
|
-
throw new Error(
|
|
143
|
-
`second terminal call rejected (D5): ${event.type} for ` +
|
|
144
|
-
`${env.phase}@${env.round} already recorded at seq ${event.seq}. ` +
|
|
145
|
-
'Remote publication is pending; do not run ab done again (§8.4).',
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
if (event.type !== spec.terminalEvent) continue
|
|
149
|
-
if (
|
|
150
|
-
(event.type === 'verify.completed' || event.type === 'finalize.completed') &&
|
|
151
|
-
event.seq <= restartSeq
|
|
152
|
-
) {
|
|
153
|
-
continue
|
|
154
|
-
}
|
|
155
|
-
if (!terminalMatchesRound(event, env, reconcileAttempt)) continue
|
|
156
|
-
throw new Error(
|
|
157
|
-
`second terminal call rejected (D5): ${event.type} for ` +
|
|
158
|
-
`${env.phase}@${env.round} already recorded at seq ${event.seq}. ` +
|
|
159
|
-
'Every phase ends with exactly one terminal command (§8.4).',
|
|
160
|
-
)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function terminalMatchesRound(event: AbEvent, env: CliEnv, reconcileAttempt: number): boolean {
|
|
165
|
-
switch (event.type) {
|
|
166
|
-
case 'plan.completed':
|
|
167
|
-
case 'plan-review.verdict':
|
|
168
|
-
case 'implement.completed':
|
|
169
|
-
case 'code-review.verdict':
|
|
170
|
-
return event.payload.round === env.round
|
|
171
|
-
case 'verify.completed':
|
|
172
|
-
return (
|
|
173
|
-
isVerifyPhase(env.phase) &&
|
|
174
|
-
event.payload.step === verifyStep(env.phase) &&
|
|
175
|
-
event.payload.attempt === env.round
|
|
176
|
-
)
|
|
177
|
-
case 'finalize.completed':
|
|
178
|
-
// finalize runs once per build (§5) — any prior completion counts.
|
|
179
|
-
return true
|
|
180
|
-
case 'reconcile.completed':
|
|
181
|
-
// No started event before it → conservative match (total over any log).
|
|
182
|
-
return reconcileAttempt === env.round || reconcileAttempt === 0
|
|
183
|
-
default:
|
|
184
|
-
return false
|
|
185
|
-
}
|
|
72
|
+
async function assertNoPriorTerminal(store: BuildStore, env: CliEnv): Promise<void> {
|
|
73
|
+
const result = await readTerminalGuard(store, env.build, env.phase, env.round, env.session)
|
|
74
|
+
if (result.diagnostic) throw new Error(result.diagnostic)
|
|
186
75
|
}
|
|
187
76
|
|
|
188
77
|
// ── Small helpers ────────────────────────────────────────────────────────────
|
|
@@ -240,28 +129,21 @@ async function assertCleanWorktree(deps: TerminalDeps): Promise<void> {
|
|
|
240
129
|
}
|
|
241
130
|
}
|
|
242
131
|
|
|
243
|
-
function baseBranchOf(events:
|
|
244
|
-
|
|
245
|
-
if (event.type === 'build.created') return event.payload.baseBranch
|
|
246
|
-
}
|
|
132
|
+
function baseBranchOf(events: CurrentBuildFacts): string {
|
|
133
|
+
if (events.state.baseBranch) return events.state.baseBranch
|
|
247
134
|
throw new Error('this build has no build.created event — cannot resolve its baseBranch (§15.3)')
|
|
248
135
|
}
|
|
249
136
|
|
|
250
|
-
function requireImplementationProvisioning(events:
|
|
251
|
-
if (events.
|
|
137
|
+
function requireImplementationProvisioning(events: CurrentBuildFacts): void {
|
|
138
|
+
if (events.workspaceGenerations > 0) return
|
|
252
139
|
throw new Error(
|
|
253
140
|
"implement's 'ab done' requires workspace.provisioned provenance — " +
|
|
254
141
|
'this build has no workspace.provisioned event (§7.4, §15.3)',
|
|
255
142
|
)
|
|
256
143
|
}
|
|
257
144
|
|
|
258
|
-
function remotePublication(events:
|
|
259
|
-
|
|
260
|
-
for (const event of events) {
|
|
261
|
-
if (event.type === 'workspace.provisioned') remote = isRemoteWorkspace(event.payload)
|
|
262
|
-
else if (event.type === 'workspace.released') remote = false
|
|
263
|
-
}
|
|
264
|
-
return remote
|
|
145
|
+
function remotePublication(events: CurrentBuildFacts): boolean {
|
|
146
|
+
return events.workspace !== null && isRemoteWorkspace(events.workspace)
|
|
265
147
|
}
|
|
266
148
|
|
|
267
149
|
async function buildBranch(deps: TerminalDeps): Promise<string> {
|
|
@@ -281,7 +163,7 @@ async function buildBranch(deps: TerminalDeps): Promise<string> {
|
|
|
281
163
|
*/
|
|
282
164
|
async function implementationReviewBoundary(
|
|
283
165
|
deps: TerminalDeps,
|
|
284
|
-
events:
|
|
166
|
+
events: CurrentBuildFacts,
|
|
285
167
|
): Promise<{ branch: string; base: string; head: string }> {
|
|
286
168
|
const diagnostic = 'cannot establish implementation review boundary'
|
|
287
169
|
try {
|
|
@@ -384,7 +266,7 @@ export interface FinalizePrInput {
|
|
|
384
266
|
* requested head before entering this idempotent PR-side sequence. */
|
|
385
267
|
export async function completeFinalizePr(
|
|
386
268
|
deps: TerminalDeps,
|
|
387
|
-
events:
|
|
269
|
+
events: CurrentBuildFacts,
|
|
388
270
|
input: FinalizePrInput,
|
|
389
271
|
): Promise<EventEnvelope> {
|
|
390
272
|
const { env, store } = deps
|
|
@@ -404,42 +286,19 @@ export async function completeFinalizePr(
|
|
|
404
286
|
|
|
405
287
|
await preparePrAttachments(deps, events, pr.url)
|
|
406
288
|
|
|
407
|
-
const latest = await store
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
289
|
+
const latest = (await readBuildFacts(store, env.build)).value
|
|
290
|
+
const nodeTarget = latest.state.target !== undefined
|
|
291
|
+
if (nodeTarget) {
|
|
292
|
+
const cancellation = await deps.forge.setAutoMerge(deps.workspacePath, pr.number, false)
|
|
293
|
+
if (cancellation.kind !== 'applied')
|
|
294
|
+
throw new Error('node-target native auto-merge cancellation unconfirmed')
|
|
295
|
+
}
|
|
414
296
|
const event = await store.append(env.build, {
|
|
415
297
|
actor: KERNEL,
|
|
416
298
|
type: 'finalize.completed',
|
|
417
299
|
payload: { pr },
|
|
418
300
|
})
|
|
419
301
|
|
|
420
|
-
if (autoMerge !== undefined) {
|
|
421
|
-
try {
|
|
422
|
-
if (autoMergeResult?.kind === 'applied') {
|
|
423
|
-
await store.append(env.build, {
|
|
424
|
-
actor: KERNEL,
|
|
425
|
-
type: autoMergeApplicationType(autoMerge.enabled),
|
|
426
|
-
payload: { commandSeq: autoMerge.commandSeq },
|
|
427
|
-
})
|
|
428
|
-
} else if (autoMergeResult?.kind === 'deferred' && autoMergeResult.reason !== undefined) {
|
|
429
|
-
await recordAutoMergeDeferralObservation(
|
|
430
|
-
store,
|
|
431
|
-
env.build,
|
|
432
|
-
autoMergeResult.reason,
|
|
433
|
-
pr.number,
|
|
434
|
-
autoMerge.commandSeq,
|
|
435
|
-
deps.ids('obs'),
|
|
436
|
-
)
|
|
437
|
-
}
|
|
438
|
-
} catch {
|
|
439
|
-
// The janitor retries unmatched commands and provider diagnostics.
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
302
|
return event
|
|
444
303
|
}
|
|
445
304
|
|
|
@@ -452,8 +311,8 @@ export async function done(deps: TerminalDeps, opts: DoneOpts = {}): Promise<Eve
|
|
|
452
311
|
`${spec.kind} phase; use 'ab verdict' (§8.2)`,
|
|
453
312
|
)
|
|
454
313
|
}
|
|
455
|
-
const events = await store
|
|
456
|
-
assertNoPriorTerminal(
|
|
314
|
+
const events = (await readBuildFacts(store, env.build)).value
|
|
315
|
+
await assertNoPriorTerminal(store, env)
|
|
457
316
|
const actor = agentActor(env.phase, env.session)
|
|
458
317
|
|
|
459
318
|
switch (spec.name) {
|
|
@@ -466,12 +325,7 @@ export async function done(deps: TerminalDeps, opts: DoneOpts = {}): Promise<Eve
|
|
|
466
325
|
// still the already-reviewed plan, re-entering review as if revised.
|
|
467
326
|
const revs = await store.listArtifacts(env.build, 'plan')
|
|
468
327
|
const latest = revs[revs.length - 1]
|
|
469
|
-
|
|
470
|
-
for (const event of events) {
|
|
471
|
-
if (event.type === 'plan.completed') {
|
|
472
|
-
lastCited = Math.max(lastCited, event.payload.artifact.rev)
|
|
473
|
-
}
|
|
474
|
-
}
|
|
328
|
+
const lastCited = events.maxPlanRevision
|
|
475
329
|
if (latest === undefined || latest.revision <= lastCited) {
|
|
476
330
|
throw new Error(
|
|
477
331
|
`plan@${env.round} 'ab done' requires this round's plan deposit: found ` +
|
|
@@ -538,6 +392,7 @@ export async function done(deps: TerminalDeps, opts: DoneOpts = {}): Promise<Eve
|
|
|
538
392
|
return event
|
|
539
393
|
}
|
|
540
394
|
// Local publication remains immediate and push-before-fact.
|
|
395
|
+
await suspendNativeLanding({ ...deps, slug: env.build }, `implement:${env.round}`)
|
|
541
396
|
await deps.forge.pushBranch(deps.workspacePath, branch)
|
|
542
397
|
const { event } = await store.appendWithArtifacts(
|
|
543
398
|
env.build,
|
|
@@ -600,55 +455,81 @@ export async function done(deps: TerminalDeps, opts: DoneOpts = {}): Promise<Eve
|
|
|
600
455
|
const notesPath = requireNotes(opts.notes, "reconcile's 'ab done' deposits reconcile-notes")
|
|
601
456
|
const notes = await readTextFile(notesPath, '--notes')
|
|
602
457
|
await assertCleanWorktree(deps)
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
`HEAD ${head} has ${parts.length - 1} parent(s); merge the base branch ` +
|
|
612
|
-
'into this branch first (§15.7, D1: never rebase)',
|
|
613
|
-
)
|
|
614
|
-
}
|
|
615
|
-
const scratchPaths = await reconcileScratchViolations(
|
|
616
|
-
deps.exec,
|
|
617
|
-
deps.workspacePath,
|
|
618
|
-
head,
|
|
619
|
-
parts.slice(1),
|
|
620
|
-
)
|
|
621
|
-
if (scratchPaths.length > 0) throw phaseScratchRejection(scratchPaths)
|
|
622
|
-
const branch = await buildBranch(deps)
|
|
623
|
-
if (remotePublication(events)) {
|
|
624
|
-
const { event } = await store.appendWithArtifacts(
|
|
458
|
+
const node = events.state.nodeRestack
|
|
459
|
+
if (node?.conflict && node.active) {
|
|
460
|
+
const conflict = node.conflict
|
|
461
|
+
const change = node.active.changes[conflict.index]!
|
|
462
|
+
const head = (await git(deps, ['rev-parse', 'HEAD'])).trim()
|
|
463
|
+
await validateNodeChange(deps, change, conflict.base, head)
|
|
464
|
+
await retainReplay({ ...deps, slug: env.build }, head, conflict.base)
|
|
465
|
+
const deposited = await store.appendWithArtifacts(
|
|
625
466
|
env.build,
|
|
626
467
|
[{ kind: 'reconcile-notes', content: notes }],
|
|
627
|
-
(
|
|
628
|
-
actor,
|
|
629
|
-
type: '
|
|
468
|
+
() => ({
|
|
469
|
+
actor: KERNEL,
|
|
470
|
+
type: 'node.item-replayed',
|
|
630
471
|
payload: {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
472
|
+
id: node.active!.id,
|
|
473
|
+
index: conflict.index,
|
|
474
|
+
base: conflict.base,
|
|
475
|
+
head,
|
|
476
|
+
dropped: false,
|
|
635
477
|
},
|
|
636
478
|
}),
|
|
637
479
|
)
|
|
638
|
-
return
|
|
480
|
+
return store.append(env.build, {
|
|
481
|
+
actor,
|
|
482
|
+
type: 'reconcile.completed',
|
|
483
|
+
payload: {
|
|
484
|
+
headSha: head,
|
|
485
|
+
rewriteId: node.active.id,
|
|
486
|
+
artifact: refOf(deposited.artifacts[0]),
|
|
487
|
+
},
|
|
488
|
+
})
|
|
639
489
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
490
|
+
const transaction = events.reconcileTransaction
|
|
491
|
+
if (transaction === undefined || transaction.attempt !== env.round)
|
|
492
|
+
throw new Error(
|
|
493
|
+
'reconcile requires a kernel-prepared single-change replay; restart this reconcile occurrence',
|
|
494
|
+
)
|
|
495
|
+
const head = (await git(deps, ['rev-parse', 'HEAD'])).trim()
|
|
496
|
+
const priorIntent = events.reconcileHistory.findLast(
|
|
497
|
+
(event) =>
|
|
498
|
+
event.type === 'reconcile.publish-intended' && event.payload.id === transaction.id,
|
|
499
|
+
)
|
|
500
|
+
if (
|
|
501
|
+
priorIntent?.type === 'reconcile.publish-intended' &&
|
|
502
|
+
priorIntent.payload.headSha !== head
|
|
503
|
+
)
|
|
504
|
+
throw new Error(
|
|
505
|
+
'the durable reconcile publication intent names another resolved head; restore that head before retrying completion',
|
|
506
|
+
)
|
|
507
|
+
const restack = { ...deps, slug: env.build }
|
|
508
|
+
await validateRestack(restack, transaction, head)
|
|
509
|
+
await retainReplay(restack, head, transaction.targetBase)
|
|
510
|
+
const conflicted =
|
|
511
|
+
events.reconcileReplay?.id === transaction.id && events.reconcileReplay.conflicted
|
|
512
|
+
const { event: intended } = await store.appendWithArtifacts(
|
|
643
513
|
env.build,
|
|
644
514
|
[{ kind: 'reconcile-notes', content: notes }],
|
|
645
515
|
(deposited) => ({
|
|
646
|
-
actor,
|
|
647
|
-
type: 'reconcile.
|
|
648
|
-
payload: {
|
|
516
|
+
actor: KERNEL,
|
|
517
|
+
type: 'reconcile.publish-intended',
|
|
518
|
+
payload: { ...transaction, headSha: head, conflicted, artifact: refOf(deposited[0]) },
|
|
649
519
|
}),
|
|
650
520
|
)
|
|
651
|
-
|
|
521
|
+
// All resolver publications wait until the agent turn has ended.
|
|
522
|
+
return store.append(env.build, {
|
|
523
|
+
actor,
|
|
524
|
+
type: 'publication.requested',
|
|
525
|
+
payload: {
|
|
526
|
+
operation: 'reconcile',
|
|
527
|
+
branch: transaction.branch,
|
|
528
|
+
sha: head,
|
|
529
|
+
artifact: intended.payload.artifact,
|
|
530
|
+
rewrite: { ...transaction, conflicted },
|
|
531
|
+
},
|
|
532
|
+
})
|
|
652
533
|
}
|
|
653
534
|
|
|
654
535
|
default:
|
|
@@ -704,8 +585,8 @@ export async function verdict(deps: TerminalDeps, opts: VerdictOpts): Promise<Ev
|
|
|
704
585
|
`accept pass|fail|skip. ${env.phase} accepts: ${vocabulary.join('|')}`,
|
|
705
586
|
)
|
|
706
587
|
}
|
|
707
|
-
const events = await store
|
|
708
|
-
assertNoPriorTerminal(
|
|
588
|
+
const events = (await readBuildFacts(store, env.build)).value
|
|
589
|
+
await assertNoPriorTerminal(store, env)
|
|
709
590
|
const actor = agentActor(env.phase, env.session)
|
|
710
591
|
|
|
711
592
|
if (spec.kind === 'agent-verify') {
|
|
@@ -717,7 +598,7 @@ export async function verdict(deps: TerminalDeps, opts: VerdictOpts): Promise<Ev
|
|
|
717
598
|
async function reviewVerdict(
|
|
718
599
|
deps: TerminalDeps,
|
|
719
600
|
opts: VerdictOpts,
|
|
720
|
-
events:
|
|
601
|
+
events: CurrentBuildFacts,
|
|
721
602
|
actor: ReturnType<typeof agentActor>,
|
|
722
603
|
): Promise<EventEnvelope[]> {
|
|
723
604
|
const { env, store } = deps
|
|
@@ -816,7 +697,7 @@ export function renderFindingsIssues(issues: readonly z.core.$ZodIssue[]): strin
|
|
|
816
697
|
async function parseFindings(
|
|
817
698
|
deps: TerminalDeps,
|
|
818
699
|
path: string,
|
|
819
|
-
events:
|
|
700
|
+
events: CurrentBuildFacts,
|
|
820
701
|
): Promise<Finding[]> {
|
|
821
702
|
const raw = await readTextFile(path, '--findings')
|
|
822
703
|
let json: unknown
|
|
@@ -841,7 +722,7 @@ async function parseFindings(
|
|
|
841
722
|
// `persists` may only reference ids from prior rounds of THIS loop (§15.4;
|
|
842
723
|
// ids are deposit-stamped, so a reviewer can only ever see rounds it was
|
|
843
724
|
// shown — §8.3).
|
|
844
|
-
const state =
|
|
725
|
+
const state = events.state
|
|
845
726
|
const loop =
|
|
846
727
|
deps.env.phase === 'plan-review'
|
|
847
728
|
? state.reviewFindings.planReview
|
|
@@ -881,6 +762,25 @@ async function agentVerifyVerdict(
|
|
|
881
762
|
}
|
|
882
763
|
const step = verifyStep(env.phase)
|
|
883
764
|
const reportKind = verifyReportKind(step)
|
|
765
|
+
const facts = (await readBuildFacts(store, env.build)).value
|
|
766
|
+
const start =
|
|
767
|
+
facts.log.restack.gates[
|
|
768
|
+
String(Math.max(facts.log.code.latestApproveSeq, facts.log.lastReconcileCompletedSeq))
|
|
769
|
+
]
|
|
770
|
+
const integrationStart =
|
|
771
|
+
facts.state.kind === 'node'
|
|
772
|
+
? facts.log.verifyStarted.findLast((record) => record.attempt === env.round)
|
|
773
|
+
: undefined
|
|
774
|
+
const evidence =
|
|
775
|
+
integrationStart !== undefined
|
|
776
|
+
? {
|
|
777
|
+
baseSha: integrationStart.baseSha,
|
|
778
|
+
headSha: integrationStart.headSha,
|
|
779
|
+
restackId: integrationStart.restackId,
|
|
780
|
+
}
|
|
781
|
+
: start === undefined
|
|
782
|
+
? {}
|
|
783
|
+
: { baseSha: start.targetBase, headSha: start.headSha, restackId: start.id }
|
|
884
784
|
|
|
885
785
|
if (opts.verdict === 'pass') {
|
|
886
786
|
// Optional --notes are deposited as the step's report kind and the event
|
|
@@ -894,6 +794,7 @@ async function agentVerifyVerdict(
|
|
|
894
794
|
actor,
|
|
895
795
|
type: 'verify.completed',
|
|
896
796
|
payload: {
|
|
797
|
+
...evidence,
|
|
897
798
|
step,
|
|
898
799
|
attempt: env.round,
|
|
899
800
|
outcome: 'pass',
|
|
@@ -907,7 +808,7 @@ async function agentVerifyVerdict(
|
|
|
907
808
|
await store.append(env.build, {
|
|
908
809
|
actor,
|
|
909
810
|
type: 'verify.completed',
|
|
910
|
-
payload: { step, attempt: env.round, outcome: 'pass' },
|
|
811
|
+
payload: { ...evidence, step, attempt: env.round, outcome: 'pass' },
|
|
911
812
|
}),
|
|
912
813
|
]
|
|
913
814
|
}
|
|
@@ -924,7 +825,7 @@ async function agentVerifyVerdict(
|
|
|
924
825
|
await store.append(env.build, {
|
|
925
826
|
actor,
|
|
926
827
|
type: 'verify.completed',
|
|
927
|
-
payload: { step, attempt: env.round, outcome: 'skipped', reason },
|
|
828
|
+
payload: { ...evidence, step, attempt: env.round, outcome: 'skipped', reason },
|
|
928
829
|
}),
|
|
929
830
|
]
|
|
930
831
|
}
|
|
@@ -944,6 +845,7 @@ async function agentVerifyVerdict(
|
|
|
944
845
|
actor,
|
|
945
846
|
type: 'verify.completed',
|
|
946
847
|
payload: {
|
|
848
|
+
...evidence,
|
|
947
849
|
step,
|
|
948
850
|
attempt: env.round,
|
|
949
851
|
outcome: 'fail',
|
|
@@ -969,8 +871,8 @@ export async function escalate(
|
|
|
969
871
|
if (opts.question.trim() === '') {
|
|
970
872
|
throw new Error("'ab escalate' requires a question — it is what the human answers (§11)")
|
|
971
873
|
}
|
|
972
|
-
const
|
|
973
|
-
assertNoPriorTerminal(
|
|
874
|
+
const _events = (await readBuildFacts(store, env.build)).value
|
|
875
|
+
await assertNoPriorTerminal(store, env)
|
|
974
876
|
return store.append(env.build, {
|
|
975
877
|
actor: agentActor(env.phase, env.session),
|
|
976
878
|
type: 'escalation.raised',
|
|
@@ -31,14 +31,19 @@ export async function editTicket(
|
|
|
31
31
|
const ticket = await requireTicket(source, id)
|
|
32
32
|
const front = {
|
|
33
33
|
id,
|
|
34
|
+
kind: ticket.kind ?? 'work',
|
|
35
|
+
...(ticket.target !== undefined ? { target: ticket.target } : {}),
|
|
34
36
|
title: ticket.title,
|
|
35
37
|
labels: [...ticket.labels],
|
|
36
38
|
blockedBy: [...(ticket.blockedBy ?? [])],
|
|
37
39
|
...(ticket.creationKey !== undefined ? { idempotencyKey: ticket.creationKey } : {}),
|
|
38
40
|
}
|
|
39
41
|
// Reference comments remain part of the frontmatter, outside the editable keys.
|
|
40
|
-
const reference = `# Read-only reference\n# state = ${JSON.stringify(ticket.state ?? null)}\n# revision = ${JSON.stringify(ticket.revision)}\n`
|
|
41
|
-
const serialized = serializeTicketFile(front, ticket.body)
|
|
42
|
+
const reference = `# Read-only reference\n# target = ${JSON.stringify(ticket.target ?? null)} (root when null)\n# state = ${JSON.stringify(ticket.state ?? null)}\n# revision = ${JSON.stringify(ticket.revision)}\n`
|
|
43
|
+
const serialized = serializeTicketFile({ ...front, kind: 'work' }, ticket.body).replace(
|
|
44
|
+
'+++\n',
|
|
45
|
+
`+++\nkind = ${JSON.stringify(front.kind)}\n`,
|
|
46
|
+
)
|
|
42
47
|
const original = serialized.replace('+++\n', `+++\n${reference}`)
|
|
43
48
|
const directory = await mkdtemp(join(tmpdir(), 'ab-ticket-edit-'))
|
|
44
49
|
const path = join(directory, 'ticket.md')
|
|
@@ -58,11 +63,13 @@ export async function editTicket(
|
|
|
58
63
|
if (comments !== reference.trimEnd())
|
|
59
64
|
throw new Error('read-only reference comments cannot change')
|
|
60
65
|
if (
|
|
66
|
+
parsed.front.kind !== front.kind ||
|
|
67
|
+
parsed.front.target !== front.target ||
|
|
61
68
|
parsed.front.id !== id ||
|
|
62
69
|
parsed.front.idempotencyKey !== front.idempotencyKey ||
|
|
63
70
|
JSON.stringify(parsed.front.blockedBy ?? []) !== JSON.stringify(front.blockedBy)
|
|
64
71
|
)
|
|
65
|
-
throw new Error('id, idempotencyKey and blockedBy are read-only')
|
|
72
|
+
throw new Error('kind, target, id, idempotencyKey and blockedBy are read-only')
|
|
66
73
|
const patch: TicketUpdate = {}
|
|
67
74
|
if (parsed.front.title !== ticket.title) patch.title = parsed.front.title
|
|
68
75
|
if (parsed.body !== ticket.body) patch.body = parsed.body
|