@defrex/autobuild 1.0.0 → 1.1.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 +6 -6
- package/SPEC.md +360 -229
- package/docs/answering-blocked-builds.md +2 -2
- package/docs/architecture.md +155 -45
- package/docs/assets/headline-wide.png +0 -0
- package/docs/builds.md +4 -4
- package/docs/cli.md +4 -4
- package/docs/configuration-overview.md +4 -4
- package/docs/configuration.md +245 -210
- package/docs/dispatcher-hosting.md +2 -2
- package/docs/dispatcher.md +1 -1
- package/docs/forges.md +5 -5
- package/docs/getting-started.md +2 -2
- package/docs/glossary.md +6 -6
- package/docs/hosted-dispatcher.md +6 -3
- package/docs/hosted-service.md +16 -5
- package/docs/integration-overview.md +15 -15
- package/docs/integration-tree.md +45 -38
- package/docs/integration.md +6 -6
- package/docs/mcp.md +16 -15
- package/docs/{landing-policy.md → merge-policy.md} +42 -24
- package/docs/migration-1.0.md +17 -13
- package/docs/operating.md +41 -18
- package/docs/operator-api.md +91 -15
- package/docs/operator-surfaces.md +8 -4
- package/docs/overview.md +3 -3
- package/docs/remote-store-protocol.md +76 -11
- package/docs/remote-ticket-protocol.md +1 -1
- package/docs/restacking.md +54 -15
- package/docs/setup.md +41 -6
- package/docs/skills.md +1 -1
- package/docs/spec-standard.md +6 -6
- package/docs/ticket-dependencies.md +7 -7
- package/docs/tickets.md +8 -2
- package/docs/troubleshooting.md +2 -2
- package/docs/upgrading.md +8 -3
- package/docs/verification.md +60 -14
- package/package.json +7 -5
- package/packages/core/src/cli/binary-direct.ts +13 -1
- package/packages/core/src/cli/binary-lifecycle.ts +65 -2
- package/packages/core/src/cli/build-control.ts +83 -28
- package/packages/core/src/cli/context.ts +81 -38
- package/packages/core/src/cli/dashboard/facts.ts +2 -1
- package/packages/core/src/cli/dashboard/integration-detail.ts +8 -8
- package/packages/core/src/cli/dashboard/integration-row.ts +40 -13
- package/packages/core/src/cli/dashboard/landing-display.ts +25 -0
- package/packages/core/src/cli/dashboard/model.ts +56 -33
- package/packages/core/src/cli/dashboard/poll.ts +9 -3
- package/packages/core/src/cli/dashboard/render.ts +59 -37
- package/packages/core/src/cli/dashboard/target-distance.ts +14 -0
- package/packages/core/src/cli/dashboard/tree.ts +3 -2
- package/packages/core/src/cli/dispatch-args.ts +1 -1
- package/packages/core/src/cli/dispatch-frontend.ts +6 -3
- package/packages/core/src/cli/dispatch.ts +35 -9
- package/packages/core/src/cli/env.ts +4 -0
- package/packages/core/src/cli/help.ts +30 -23
- package/packages/core/src/cli/main.ts +24 -8
- package/packages/core/src/cli/node-verification-provenance.ts +1 -97
- package/packages/core/src/cli/publication-settlement.ts +43 -20
- package/packages/core/src/cli/repository-status.ts +20 -9
- package/packages/core/src/cli/status.ts +42 -5
- package/packages/core/src/cli/store-opening.ts +6 -1
- package/packages/core/src/cli/terminal.ts +22 -1
- package/packages/core/src/cli/terminals.ts +14 -10
- package/packages/core/src/cli/upgrade-landing.ts +70 -30
- package/packages/core/src/cli/upgrade.ts +3 -1
- package/packages/core/src/cli/wait.ts +15 -7
- package/packages/core/src/cli/watch-lifetime.ts +111 -0
- package/packages/core/src/cli/watch.ts +634 -511
- package/packages/core/src/config/effective-artifact.fixture.ts +27 -0
- package/packages/core/src/config/effective-artifact.ts +13 -0
- package/packages/core/src/config/landing.ts +1 -1
- package/packages/core/src/config/load.ts +21 -1
- package/packages/core/src/config/pipeline-source.ts +28 -0
- package/packages/core/src/config/reference-metadata.ts +2 -0
- package/packages/core/src/config/reference.ts +22 -7
- package/packages/core/src/config/schema.ts +86 -162
- package/packages/core/src/context-directory.ts +26 -0
- package/packages/core/src/distribution-packaging.ts +26 -5
- package/packages/core/src/events/catalog.ts +10 -2
- package/packages/core/src/events/globs.ts +1 -1
- package/packages/core/src/events/payloads.ts +70 -1
- package/packages/core/src/events/policy.ts +7 -0
- package/packages/core/src/events/repository.ts +2 -4
- package/packages/core/src/events/sessions.ts +6 -6
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +571 -0
- package/packages/core/src/kernel/auto-merge.ts +2 -2
- package/packages/core/src/kernel/engine.ts +255 -26
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +10 -0
- package/packages/core/src/kernel/integration-landing.ts +3 -3
- package/packages/core/src/kernel/integration-state.ts +27 -4
- package/packages/core/src/kernel/leaf-restack-state.ts +28 -3
- package/packages/core/src/kernel/log-index.ts +13 -1
- package/packages/core/src/kernel/node-landing.ts +8 -8
- package/packages/core/src/kernel/node-parent.ts +2 -2
- package/packages/core/src/kernel/node-restack-transaction.ts +1 -1
- package/packages/core/src/kernel/node-verification-context.ts +216 -0
- package/packages/core/src/kernel/phases.ts +1 -1
- package/packages/core/src/kernel/plan-verify-selection.ts +16 -0
- package/packages/core/src/kernel/publication-retry.ts +168 -0
- package/packages/core/src/kernel/reconcile-restack.ts +29 -1
- package/packages/core/src/kernel/reducer.ts +82 -5
- package/packages/core/src/kernel/target-distance.ts +45 -0
- package/packages/core/src/kernel/terminal-guard.ts +10 -1
- package/packages/core/src/kernel/verify-stage-state.ts +123 -0
- package/packages/core/src/kernel/verify-stages.ts +39 -0
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/control.ts +1 -1
- package/packages/core/src/operator/index.ts +1 -7
- package/packages/core/src/operator/landings.ts +5 -1
- package/packages/core/src/operator/presentation.ts +6 -1
- package/packages/core/src/operator/query.ts +14 -18
- package/packages/core/src/operator/registry.ts +17 -6
- package/packages/core/src/operator/sandbox-host.ts +64 -40
- package/packages/core/src/operator/sandbox.ts +3 -0
- package/packages/core/src/operator/ticket-source-backend.ts +3 -12
- package/packages/core/src/ports/forge/contract.ts +2 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +25 -2
- package/packages/core/src/ports/forge/github-readiness.ts +2 -2
- package/packages/core/src/ports/forge/github.ts +26 -7
- package/packages/core/src/ports/forge/local-git.ts +4 -4
- package/packages/core/src/ports/forge/readiness.ts +1 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/workspace/build-execution.ts +3 -1
- package/packages/core/src/ports/workspace/phase-scratch.ts +4 -3
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +59 -39
- package/packages/core/src/processes/build-child.ts +6 -8
- package/packages/core/src/processes/build-execution-state.ts +8 -5
- package/packages/core/src/processes/build-runner.ts +522 -98
- package/packages/core/src/processes/dispatcher.ts +186 -101
- package/packages/core/src/processes/execution-no-progress.ts +8 -1
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/publication-loss.ts +8 -2
- package/packages/core/src/processes/publication-state.ts +42 -4
- package/packages/core/src/processes/repo-view.ts +14 -0
- package/packages/core/src/processes/verify-cycle-config.ts +96 -0
- package/packages/core/src/{integration → scenarios}/harness.ts +330 -317
- package/packages/core/src/store/adapter.ts +1 -0
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +113 -1
- package/packages/core/src/store/local/schema.ts +13 -0
- package/packages/core/src/store/local/store.ts +42 -0
- package/packages/core/src/store/memory.ts +47 -0
- package/packages/core/src/store/operator-presence.ts +21 -0
- package/packages/core/src/store/phase-session.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +5081 -4160
- package/packages/core/src/store/remote/client.ts +47 -1
- package/packages/core/src/store/remote/compatibility.ts +2 -0
- package/packages/core/src/store/remote/protocol.ts +4 -0
- package/packages/core/src/store/remote/version.ts +3 -1
- package/packages/core/src/store/retention.ts +2 -3
- package/packages/core/src/store/session-handle.ts +9 -0
- package/packages/core/src/store/streams/session-writer.ts +1 -1
- package/packages/core/src/store/types.ts +12 -2
- package/packages/core/src/testing/index.ts +11 -1
- package/packages/core/src/testing/temp-directories.ts +58 -0
- package/skills/code-review/SKILL.md +23 -9
- package/skills/finalize/SKILL.md +15 -7
- package/skills/guide/SKILL.md +253 -118
- package/skills/guide/references/integration-tree.md +45 -38
- package/skills/guide/references/{landing-policy.md → merge-policy.md} +42 -24
- package/skills/guide/references/migration-1.0.md +17 -13
- package/skills/guide/references/operator-api.md +91 -15
- package/skills/guide/references/remote-store-protocol.md +76 -11
- package/skills/guide/references/remote-ticket-protocol.md +1 -1
- package/skills/guide/references/restacking.md +54 -15
- package/skills/guide/references/setup.md +41 -6
- package/skills/guide/references/spec-standard.md +6 -6
- package/skills/guide/references/ticket-dependencies.md +7 -7
- package/skills/implement/SKILL.md +43 -17
- package/skills/operate/SKILL.md +117 -116
- package/skills/plan/SKILL.md +39 -13
- package/skills/plan-review/SKILL.md +15 -10
- package/skills/reconcile/SKILL.md +22 -3
- package/skills/spec/SKILL.md +19 -19
- package/skills/tickets/SKILL.md +9 -7
- package/templates/autobuild.toml +1 -1
- package/templates/hosted-service/package.json +2 -2
- package/packages/core/src/orchestrator/approvals.ts +0 -115
- package/packages/core/src/orchestrator/conversation.ts +0 -167
- package/packages/core/src/orchestrator/model.ts +0 -86
- package/packages/core/src/orchestrator/prompt.ts +0 -63
- package/packages/core/src/orchestrator/tools.ts +0 -117
- package/packages/core/src/orchestrator/turn-runner.ts +0 -457
- package/packages/core/src/processes/orchestrator-tick.ts +0 -360
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
|
|
2
|
+
import { OPERATOR_PRESENCE_TTL_MS, type OperatorPresence } from '../store/operator-presence'
|
|
1
3
|
import { migrationIdentity } from '../kernel/ticket-migrations'
|
|
2
4
|
import { dispatchUpgradeReducer, type DispatchUpgradeState } from '../kernel/dispatch-upgrade'
|
|
3
5
|
import { formatRuntimeIdentity } from '../events/runtime'
|
|
@@ -31,6 +33,7 @@ import { withSessionlessStore, type StoreOpener } from './store-opening'
|
|
|
31
33
|
|
|
32
34
|
/** Script-facing projection returned by `ab repository status`. */
|
|
33
35
|
export interface RepositoryStatus extends DispatchSettings {
|
|
36
|
+
operator: { registrations: Array<OperatorPresence & { heartbeatAgeMs: number }> }
|
|
34
37
|
repo: string
|
|
35
38
|
upgrades: DispatchUpgradeState
|
|
36
39
|
rollbackHold?: DispatchUpgradeState['lastRollback']
|
|
@@ -114,6 +117,7 @@ export function projectRepositoryStatus(
|
|
|
114
117
|
: {}),
|
|
115
118
|
...(active === undefined ? {} : { ticketSourceDegradation: active }),
|
|
116
119
|
repo,
|
|
120
|
+
operator: { registrations: [] },
|
|
117
121
|
upgrades: dispatchUpgradeReducer.reduce(events),
|
|
118
122
|
rollbackHold: effectiveRollbackHold(dispatchUpgradeReducer.reduce(events), dispatcher),
|
|
119
123
|
...(warningLines.length ? { warningLines } : {}),
|
|
@@ -148,6 +152,7 @@ export function repositoryStatusFromFacts(
|
|
|
148
152
|
const warningLines = facts.status ? forgeReadinessWarnings(facts.status) : []
|
|
149
153
|
return {
|
|
150
154
|
repo,
|
|
155
|
+
operator: { registrations: [] },
|
|
151
156
|
upgrades: facts.upgrades,
|
|
152
157
|
rollbackHold: effectiveRollbackHold(facts.upgrades, dispatcher),
|
|
153
158
|
...(warningLines.length ? { warningLines } : {}),
|
|
@@ -207,6 +212,9 @@ export function renderRepositoryStatus(status: RepositoryStatus): string[] {
|
|
|
207
212
|
const setting = (enabled: boolean): string => (enabled ? 'ON' : 'OFF')
|
|
208
213
|
const active = status.ticketSourceDegradation
|
|
209
214
|
return [
|
|
215
|
+
status.operator.registrations.length
|
|
216
|
+
? `operator: present (${status.operator.registrations.length} registrations)`
|
|
217
|
+
: 'operator: absent',
|
|
210
218
|
...(status.upgrades.lastRollback
|
|
211
219
|
? [
|
|
212
220
|
`runtime rollback: ${status.upgrades.lastRollback.payload.failed.version} → ${status.upgrades.lastRollback.payload.restored.version}; ${status.upgrades.lastRollback.payload.reason}`,
|
|
@@ -317,7 +325,9 @@ export async function readRepositoryCapacity(
|
|
|
317
325
|
const ref = facts.status.effectiveConfig
|
|
318
326
|
const artifact = await store.getRepoArtifact(repo, ref.kind, ref.rev)
|
|
319
327
|
if (artifact) {
|
|
320
|
-
const config = configSchema.parse(
|
|
328
|
+
const config = configSchema.parse(
|
|
329
|
+
normalizeEffectiveConfigArtifact(JSON.parse(new TextDecoder().decode(artifact.content))),
|
|
330
|
+
)
|
|
321
331
|
const builds: CapacityBuild[] = []
|
|
322
332
|
const records = await store.listBuildsForRepo(repo)
|
|
323
333
|
const digests = await store.getRepoBuildDigests(repo)
|
|
@@ -350,16 +360,17 @@ export async function abRepositoryStatus(opts: RepositoryStatusOpts): Promise<vo
|
|
|
350
360
|
await withSessionlessStore(opts, async ({ store, repo }) => {
|
|
351
361
|
// A fresh store has no repository row. Do not call ensureRepo: this query's
|
|
352
362
|
// empty-stream defaults must remain a genuinely read-only operation.
|
|
353
|
-
const
|
|
363
|
+
const observedAt = opts.now?.() ?? new Date()
|
|
364
|
+
const { dispatcher } = await readDispatcherLiveness(store, repo, observedAt)
|
|
354
365
|
const facts = (await readRepositoryFacts(store, repo)).value
|
|
355
366
|
const status = repositoryStatusFromFacts(repo, facts, dispatcher)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
)
|
|
367
|
+
status.operator.registrations = (await store.listOperatorPresence(repo))
|
|
368
|
+
.map((row) => ({
|
|
369
|
+
...row,
|
|
370
|
+
heartbeatAgeMs: Math.max(0, observedAt.getTime() - Date.parse(row.heartbeatAt)),
|
|
371
|
+
}))
|
|
372
|
+
.filter((row) => row.heartbeatAgeMs < OPERATOR_PRESENCE_TTL_MS)
|
|
373
|
+
const capacity = await readRepositoryCapacity(store, repo, facts, dispatcher, observedAt)
|
|
363
374
|
if (capacity) status.capacity = capacity
|
|
364
375
|
if (opts.json === true) {
|
|
365
376
|
opts.stdout(JSON.stringify(status, null, 2))
|
|
@@ -115,6 +115,8 @@ export interface BuildSummary {
|
|
|
115
115
|
/** The reducer's effective status (§15.5) — never mixed with lease health. */
|
|
116
116
|
status: BuildStatus
|
|
117
117
|
phase?: Phase
|
|
118
|
+
runningVerifySteps?: string[]
|
|
119
|
+
cancelledVerifySteps?: { step: string; cause: { step: string } }[]
|
|
118
120
|
round?: number
|
|
119
121
|
attempt?: number
|
|
120
122
|
pr?: { number: number; url: string; state?: PrLifecycle }
|
|
@@ -130,6 +132,8 @@ export interface VerifyProgress {
|
|
|
130
132
|
/** Current cycle only — selected by sequence boundary, never attempt. */
|
|
131
133
|
steps: { step: string; outcome: VerifyOutcome; reason?: string }[]
|
|
132
134
|
currentStep?: string
|
|
135
|
+
runningSteps?: string[]
|
|
136
|
+
cancelled?: { step: string; cause: { step: string } }[]
|
|
133
137
|
}
|
|
134
138
|
|
|
135
139
|
export interface SetupFailureDetail {
|
|
@@ -167,6 +171,7 @@ export interface BuildDetail extends BuildSummary {
|
|
|
167
171
|
* cancelling) — the same projection the dashboards render, so `--json` and
|
|
168
172
|
* the text agree and `waiting: on PR` can say why it is waiting. */
|
|
169
173
|
autoMerge: AutoMergeDisplay
|
|
174
|
+
supersededEscalations?: BuildState['verifyStage']['superseded']
|
|
170
175
|
openEscalations: OpenEscalation[]
|
|
171
176
|
/** Per-loop review overrides for the current spec; omitted when none are set. */
|
|
172
177
|
reviewRoundCeilings?: { plan?: number; code?: number }
|
|
@@ -252,6 +257,16 @@ export function summarizeFrom(record: BuildRecord, state: BuildState, now: Date)
|
|
|
252
257
|
return {
|
|
253
258
|
slug: record.slug,
|
|
254
259
|
...buildVocabulary(state),
|
|
260
|
+
...((state.verify.running?.length ?? 0) > 1
|
|
261
|
+
? { runningVerifySteps: state.verify.running }
|
|
262
|
+
: {}),
|
|
263
|
+
...(Object.values(state.verifyStage.cancellations).some((c) => c.seq > state.verify.cycleSince)
|
|
264
|
+
? {
|
|
265
|
+
cancelledVerifySteps: Object.values(state.verifyStage.cancellations)
|
|
266
|
+
.filter((c) => c.seq > state.verify.cycleSince)
|
|
267
|
+
.map((c) => ({ step: c.step, cause: c.cause })),
|
|
268
|
+
}
|
|
269
|
+
: {}),
|
|
255
270
|
...(state.kind === 'node' ? { integrationState: state.integration } : {}),
|
|
256
271
|
...(state.kind === 'node'
|
|
257
272
|
? { nodeRestack: state.nodeRestack, handPushedCommits: projectHandPushed(state.nodeRestack) }
|
|
@@ -371,6 +386,9 @@ export function detailFromFacts(
|
|
|
371
386
|
autoMerge: autoMergeDisplay(state),
|
|
372
387
|
...(state.landing && Object.keys(state.landing).length ? { landing: state.landing } : {}),
|
|
373
388
|
...(decision !== undefined ? { decision } : {}),
|
|
389
|
+
...(state.verifyStage.superseded.length
|
|
390
|
+
? { supersededEscalations: state.verifyStage.superseded }
|
|
391
|
+
: {}),
|
|
374
392
|
openEscalations: state.openEscalations,
|
|
375
393
|
...(state.reviewRoundCeilings.plan !== undefined || state.reviewRoundCeilings.code !== undefined
|
|
376
394
|
? { reviewRoundCeilings: { ...state.reviewRoundCeilings } }
|
|
@@ -419,6 +437,16 @@ export function detailFromFacts(
|
|
|
419
437
|
// from the reducer's full-log high-water, never from cycle membership.
|
|
420
438
|
attempt: state.verify.maxAttemptSeen,
|
|
421
439
|
steps,
|
|
440
|
+
...((state.verify.running?.length ?? 0) > 1 ? { runningSteps: state.verify.running } : {}),
|
|
441
|
+
...(Object.values(state.verifyStage.cancellations).some(
|
|
442
|
+
(c) => c.seq > state.verify.cycleSince,
|
|
443
|
+
)
|
|
444
|
+
? {
|
|
445
|
+
cancelled: Object.values(state.verifyStage.cancellations)
|
|
446
|
+
.filter((c) => c.seq > state.verify.cycleSince)
|
|
447
|
+
.map((c) => ({ step: c.step, cause: c.cause })),
|
|
448
|
+
}
|
|
449
|
+
: {}),
|
|
422
450
|
...(state.verify.currentStep !== undefined ? { currentStep: state.verify.currentStep } : {}),
|
|
423
451
|
},
|
|
424
452
|
...(state.lastEvent !== undefined
|
|
@@ -458,6 +486,8 @@ function safeStatusText(value: string): string {
|
|
|
458
486
|
|
|
459
487
|
/** `r<round>` / `a<attempt>` suffixed onto the phase — the loop vs verify axis. */
|
|
460
488
|
function phaseCell(summary: BuildSummary): string {
|
|
489
|
+
if (summary.runningVerifySteps?.length)
|
|
490
|
+
return `${summary.runningVerifySteps.map((step) => `verify:${step}`).join(', ')}${summary.attempt === undefined ? '' : ` a${summary.attempt}`}`
|
|
461
491
|
if (summary.phase === undefined) return '—'
|
|
462
492
|
if (summary.attempt !== undefined) return `${summary.phase} a${summary.attempt}`
|
|
463
493
|
if (summary.round !== undefined) return `${summary.phase} r${summary.round}`
|
|
@@ -793,9 +823,11 @@ export function renderDetail(d: BuildDetail, now: Date): string[] {
|
|
|
793
823
|
lines.push(` ${step.outcome === 'pass' ? 'pass' : 'FAIL'} ${step.step}`)
|
|
794
824
|
}
|
|
795
825
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
826
|
+
for (const step of d.verify.runningSteps ??
|
|
827
|
+
(d.verify.currentStep ? [d.verify.currentStep] : []))
|
|
828
|
+
lines.push(` running ${step}`)
|
|
829
|
+
for (const cancelled of d.verify.cancelled ?? [])
|
|
830
|
+
lines.push(` not run ${cancelled.step}: cancelled by ${cancelled.cause.step}`)
|
|
799
831
|
}
|
|
800
832
|
|
|
801
833
|
if (d.lastEvent !== undefined) {
|
|
@@ -992,7 +1024,11 @@ async function projectBuildDecision(
|
|
|
992
1024
|
// Source 1 — the store deposit. A deposit that fails to parse is itself
|
|
993
1025
|
// reportable state: it is surfaced as unavailable naming the artifact rather
|
|
994
1026
|
// than silently falling back to a possibly stale workspace file.
|
|
995
|
-
const artifact = await store.getArtifact(
|
|
1027
|
+
const artifact = await store.getArtifact(
|
|
1028
|
+
slug,
|
|
1029
|
+
state.verify.configPin?.artifact.kind ?? BUILD_EFFECTIVE_CONFIG_ARTIFACT,
|
|
1030
|
+
state.verify.configPin?.artifact.rev,
|
|
1031
|
+
)
|
|
996
1032
|
if (artifact !== null) {
|
|
997
1033
|
try {
|
|
998
1034
|
return decideFromConfig(facts, parseEffectiveBuildConfig(artifact))
|
|
@@ -1104,7 +1140,8 @@ export async function abBuildStatus(opts: AbBuildStatusOpts): Promise<void> {
|
|
|
1104
1140
|
// pinned pipeline came from, alongside the effective-config revision.
|
|
1105
1141
|
const configArtifact = await context.store.getArtifact(
|
|
1106
1142
|
opts.slug,
|
|
1107
|
-
BUILD_EFFECTIVE_CONFIG_ARTIFACT,
|
|
1143
|
+
facts.state.verify.configPin?.artifact.kind ?? BUILD_EFFECTIVE_CONFIG_ARTIFACT,
|
|
1144
|
+
facts.state.verify.configPin?.artifact.rev,
|
|
1108
1145
|
)
|
|
1109
1146
|
const configMeta =
|
|
1110
1147
|
configArtifact !== null ? parseBuildConfigMetadata(configArtifact) : undefined
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { untilDeadline } from './watch-lifetime'
|
|
1
2
|
/**
|
|
2
3
|
* Production BuildStore composition for CLI commands.
|
|
3
4
|
*
|
|
@@ -99,6 +100,8 @@ export function openStoreForRepoState(
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
export interface SessionlessStoreOpts extends OpenStoreForRepoStateOpts {
|
|
103
|
+
/** Optional command-owned shutdown budget for handle closure. */
|
|
104
|
+
closeDeadline?: AbortSignal
|
|
102
105
|
targetRepo: string
|
|
103
106
|
exec: Exec
|
|
104
107
|
/** Explicit --store; precedence is applied by repo-state.ts. */
|
|
@@ -170,6 +173,8 @@ export async function withAmbientReadStore<T>(
|
|
|
170
173
|
try {
|
|
171
174
|
return await use(context)
|
|
172
175
|
} finally {
|
|
173
|
-
|
|
176
|
+
const closing = context.store.close()
|
|
177
|
+
if (opts.closeDeadline) await untilDeadline(closing, opts.closeDeadline)
|
|
178
|
+
else await closing
|
|
174
179
|
}
|
|
175
180
|
}
|
|
@@ -332,6 +332,12 @@ export function processTerminalInput(stream: NodeJS.ReadStream = process.stdin):
|
|
|
332
332
|
const priorRaw = stream.isRaw === true
|
|
333
333
|
const priorFlowing = stream.readableFlowing
|
|
334
334
|
let cleaned = false
|
|
335
|
+
let maintenance: ReturnType<typeof setInterval> | undefined
|
|
336
|
+
const reassertRaw = (): void => {
|
|
337
|
+
// Bun caches isRaw even when a retired process restores shared termios.
|
|
338
|
+
stream.setRawMode(false)
|
|
339
|
+
stream.setRawMode(true)
|
|
340
|
+
}
|
|
335
341
|
// One decoder per activation: its paste and CSI state belongs to this
|
|
336
342
|
// region's lifetime, and an unterminated paste dies with it.
|
|
337
343
|
const decoder = createTerminalInputDecoder(hooks)
|
|
@@ -344,6 +350,7 @@ export function processTerminalInput(stream: NodeJS.ReadStream = process.stdin):
|
|
|
344
350
|
const cleanup = (): void => {
|
|
345
351
|
if (cleaned) return
|
|
346
352
|
cleaned = true
|
|
353
|
+
clearInterval(maintenance)
|
|
347
354
|
decoder.cleanup()
|
|
348
355
|
if (listening) stream.removeListener('keypress', listener)
|
|
349
356
|
try {
|
|
@@ -358,8 +365,22 @@ export function processTerminalInput(stream: NodeJS.ReadStream = process.stdin):
|
|
|
358
365
|
emitKeypressEvents(stream)
|
|
359
366
|
stream.on('keypress', listener)
|
|
360
367
|
listening = true
|
|
361
|
-
|
|
368
|
+
reassertRaw()
|
|
362
369
|
stream.resume()
|
|
370
|
+
maintenance = setInterval(() => {
|
|
371
|
+
if (cleaned) return
|
|
372
|
+
try {
|
|
373
|
+
reassertRaw()
|
|
374
|
+
} catch {
|
|
375
|
+
// A lost terminal must not throw from a timer or retain ownership.
|
|
376
|
+
try {
|
|
377
|
+
cleanup()
|
|
378
|
+
} catch {
|
|
379
|
+
// Restoration is best-effort after the terminal has failed.
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}, 100)
|
|
383
|
+
maintenance.unref()
|
|
363
384
|
hooks.onListening?.()
|
|
364
385
|
return cleanup
|
|
365
386
|
} catch (error) {
|
|
@@ -806,11 +806,13 @@ async function agentVerifyVerdict(
|
|
|
806
806
|
return [event]
|
|
807
807
|
}
|
|
808
808
|
return [
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
809
|
+
(
|
|
810
|
+
await terminalDeposit(deps, [], () => ({
|
|
811
|
+
actor,
|
|
812
|
+
type: 'verify.completed',
|
|
813
|
+
payload: { ...evidence, step, attempt: env.round, outcome: 'pass' },
|
|
814
|
+
}))
|
|
815
|
+
).event,
|
|
814
816
|
]
|
|
815
817
|
}
|
|
816
818
|
|
|
@@ -823,11 +825,13 @@ async function agentVerifyVerdict(
|
|
|
823
825
|
)
|
|
824
826
|
}
|
|
825
827
|
return [
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
828
|
+
(
|
|
829
|
+
await terminalDeposit(deps, [], () => ({
|
|
830
|
+
actor,
|
|
831
|
+
type: 'verify.completed',
|
|
832
|
+
payload: { ...evidence, step, attempt: env.round, outcome: 'skipped', reason },
|
|
833
|
+
}))
|
|
834
|
+
).event,
|
|
831
835
|
]
|
|
832
836
|
}
|
|
833
837
|
|
|
@@ -20,44 +20,84 @@ export async function migrateLandingPolicy(opts: {
|
|
|
20
20
|
source = await readFile(path, 'utf8')
|
|
21
21
|
} catch {
|
|
22
22
|
throw new Error(
|
|
23
|
-
`
|
|
23
|
+
`Merge policy migration requires readable ${path}; restore its configuration and retry ab upgrade`,
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
// Parsing proves that the explicit array is valid; retain its exact bytes.
|
|
27
|
-
parseConfig(source, path)
|
|
27
|
+
parseConfig(source, path, () => {})
|
|
28
28
|
const parsed = Bun.TOML.parse(source) as Record<string, unknown>
|
|
29
|
-
if (Object.hasOwn(parsed, '
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
if (Object.hasOwn(parsed, 'merge')) return { changed: false }
|
|
30
|
+
const explicit = Object.hasOwn(parsed, 'landing')
|
|
31
|
+
let result: string
|
|
32
|
+
let enabled: boolean | undefined
|
|
33
|
+
if (explicit) {
|
|
34
|
+
let root = true
|
|
35
|
+
result = source
|
|
36
|
+
.split('\n')
|
|
37
|
+
.map((line) => {
|
|
38
|
+
const header = /^\s*\[/.test(line)
|
|
39
|
+
const renamed = line.replace(
|
|
40
|
+
/^(\s*\[\[\s*)(?:landing|"landing"|'landing')(\s*\]\])/,
|
|
41
|
+
'$1merge$2',
|
|
42
|
+
)
|
|
43
|
+
if (header) root = false
|
|
44
|
+
return root
|
|
45
|
+
? renamed.replace(/^(\s*)(?:landing|"landing"|'landing')(\s*=)/, '$1merge$2')
|
|
46
|
+
: renamed
|
|
46
47
|
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
.join('\n')
|
|
49
|
+
const expected: Record<string, unknown> = { ...parsed, merge: parsed.landing }
|
|
50
|
+
delete expected.landing
|
|
51
|
+
const manualEdit = () =>
|
|
52
|
+
new Error(
|
|
53
|
+
`Cannot safely rename the deprecated config key in ${path}; manually rename the root landing key and [[landing]] headers to merge, preserving their values, then retry ab upgrade`,
|
|
54
|
+
)
|
|
55
|
+
let actual: unknown
|
|
56
|
+
try {
|
|
57
|
+
actual = Bun.TOML.parse(result)
|
|
58
|
+
} catch {
|
|
59
|
+
throw manualEdit()
|
|
60
|
+
}
|
|
61
|
+
const canonical = (value: unknown): string =>
|
|
62
|
+
JSON.stringify(value, (_key, item) =>
|
|
63
|
+
item && typeof item === 'object' && !Array.isArray(item)
|
|
64
|
+
? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)))
|
|
65
|
+
: item,
|
|
66
|
+
)
|
|
67
|
+
if (canonical(actual) !== canonical(expected)) throw manualEdit()
|
|
68
|
+
} else {
|
|
69
|
+
enabled = false
|
|
70
|
+
try {
|
|
71
|
+
const paths = await resolveRepoState({ targetRepo: opts.targetRepo, exec: opts.exec })
|
|
72
|
+
let journalAbsent = false
|
|
73
|
+
if (!opts.openStore && !isRemoteStoreRef(paths.storeRef)) {
|
|
74
|
+
try {
|
|
75
|
+
await access(join(paths.storeRef, 'autobuild.sqlite'))
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
78
|
+
journalAbsent = true
|
|
79
|
+
}
|
|
52
80
|
}
|
|
81
|
+
if (!journalAbsent) {
|
|
82
|
+
const context = await openSessionlessStore({
|
|
83
|
+
...opts,
|
|
84
|
+
env: { ...(opts.env ?? process.env), AB_STORE: undefined },
|
|
85
|
+
})
|
|
86
|
+
try {
|
|
87
|
+
const facts = await readRepositoryFacts(context.store, context.repo)
|
|
88
|
+
enabled = facts.value.autoMerge.latest?.enabled ?? false
|
|
89
|
+
} finally {
|
|
90
|
+
await context.store.close()
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Cannot read the target repository's legacy auto-merge journal; restore store access and retry ab upgrade, or configure explicit [[merge]] rules (merge = [] selects the new defaults): ${error instanceof Error ? error.message : String(error)}`,
|
|
96
|
+
)
|
|
53
97
|
}
|
|
54
|
-
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Cannot read the target repository's legacy auto-merge journal; restore store access and retry ab upgrade, or configure explicit [[landing]] rules (landing = [] selects the new defaults): ${error instanceof Error ? error.message : String(error)}`,
|
|
57
|
-
)
|
|
98
|
+
result = `${source.replace(/\n?$/, '\n')}\n# Migrated from the durable auto-merge default. First matching rule wins.\n[[merge]]\nfrom = "leaf"\nmode = "${enabled ? 'auto' : 'consent'}"\n\n[[merge]]\nfrom = "node"\nmode = "consent"\n`
|
|
58
99
|
}
|
|
59
|
-
|
|
60
|
-
parseConfig(result, path)
|
|
100
|
+
parseConfig(result, path, () => {})
|
|
61
101
|
const temporary = `${path}.${randomUUID()}.tmp`
|
|
62
102
|
try {
|
|
63
103
|
await writeFile(temporary, result)
|
|
@@ -558,7 +558,9 @@ export async function abUpgrade(opts: {
|
|
|
558
558
|
})
|
|
559
559
|
if (landing.changed)
|
|
560
560
|
stdout(
|
|
561
|
-
|
|
561
|
+
landing.legacyDefault === undefined
|
|
562
|
+
? 'Merge policy migrated: renamed deprecated landing to merge; rule values and order preserved.'
|
|
563
|
+
: `Merge policy migrated: legacy default ${landing.legacyDefault ? 'ON → leaf auto' : 'OFF → leaf consent'}; nodes consent. Configure [[merge]] rules to change it.`,
|
|
562
564
|
)
|
|
563
565
|
await migrateLegacyAgentSkills(targetRepo)
|
|
564
566
|
|
|
@@ -89,7 +89,7 @@ const TERMINAL_STATUSES: readonly BuildStatus[] = ['done', 'aborted']
|
|
|
89
89
|
/** The `--for` condition vocabulary, in the order the help documents it. */
|
|
90
90
|
const CONDITION_VOCABULARY =
|
|
91
91
|
'blocked, paused, running, collecting, done, aborted, terminal, pr=open, pr=merged, pr=closed, ' +
|
|
92
|
-
'consent, node-
|
|
92
|
+
'consent, node-merged, restack-conflicted, pr=conflicted, phase=<phase> (a core phase or verify:<step>), attention'
|
|
93
93
|
|
|
94
94
|
// ── Conditions ───────────────────────────────────────────────────────────────
|
|
95
95
|
|
|
@@ -99,7 +99,7 @@ type ConditionBody =
|
|
|
99
99
|
| { kind: 'pr'; prState: PrLifecycle }
|
|
100
100
|
| { kind: 'phase'; phase: Phase }
|
|
101
101
|
| { kind: 'attention' }
|
|
102
|
-
| { kind: 'consent' | 'node-
|
|
102
|
+
| { kind: 'consent' | 'node-merged' | 'restack-conflicted' }
|
|
103
103
|
|
|
104
104
|
interface WaitCondition {
|
|
105
105
|
/** The original `--for` value — what a matching record's `condition` names. */
|
|
@@ -135,7 +135,11 @@ export function parseConditions(
|
|
|
135
135
|
` — ${WAIT_USAGE}`,
|
|
136
136
|
)
|
|
137
137
|
const conditions = forValues.map((value): WaitCondition => {
|
|
138
|
-
if (value === '
|
|
138
|
+
if (value === 'node-landed') {
|
|
139
|
+
console.error('node-landed is deprecated; use node-merged')
|
|
140
|
+
value = 'node-merged'
|
|
141
|
+
}
|
|
142
|
+
if (value === 'consent' || value === 'node-merged' || value === 'restack-conflicted')
|
|
139
143
|
return { text: value, cond: { kind: value } }
|
|
140
144
|
if (value === 'terminal') return { text: value, cond: { kind: 'terminal' } }
|
|
141
145
|
if (value === 'attention') return { text: value, cond: { kind: 'attention' } }
|
|
@@ -207,10 +211,14 @@ function stateSatisfies(
|
|
|
207
211
|
case 'pr':
|
|
208
212
|
return state.prState === cond.prState
|
|
209
213
|
case 'phase':
|
|
210
|
-
return (
|
|
214
|
+
return (
|
|
215
|
+
(state.phase ?? null) === cond.phase ||
|
|
216
|
+
(cond.phase.startsWith('verify:') &&
|
|
217
|
+
(state.verify.running ?? []).includes(cond.phase.slice(7)))
|
|
218
|
+
)
|
|
211
219
|
case 'consent':
|
|
212
220
|
return awaitsConsent(state, restack)
|
|
213
|
-
case 'node-
|
|
221
|
+
case 'node-merged':
|
|
214
222
|
return !!state.integration?.landing
|
|
215
223
|
case 'restack-conflicted':
|
|
216
224
|
return !!state.nodeRestack?.conflict || !!(restack.active && restack.replay?.conflicted)
|
|
@@ -257,7 +265,7 @@ export function matchEvent(
|
|
|
257
265
|
| { state: BuildState; deferral: DeferralLedger; restack?: LeafRestackState } = [],
|
|
258
266
|
): string | null {
|
|
259
267
|
for (const { text, cond } of conditions) {
|
|
260
|
-
if (cond.kind === 'node-
|
|
268
|
+
if (cond.kind === 'node-merged' && event.type === 'integration.landed') return text
|
|
261
269
|
if (
|
|
262
270
|
cond.kind === 'restack-conflicted' &&
|
|
263
271
|
(event.type === 'node.item-conflicted' ||
|
|
@@ -304,7 +312,7 @@ function matchFirst(
|
|
|
304
312
|
): string | null {
|
|
305
313
|
for (const { text, cond } of conditions) {
|
|
306
314
|
if (stateSatisfies(cond, state, events)) return text
|
|
307
|
-
if (cond.kind === 'node-
|
|
315
|
+
if (cond.kind === 'node-merged' && event.type === 'integration.landed') return text
|
|
308
316
|
if (
|
|
309
317
|
cond.kind === 'restack-conflicted' &&
|
|
310
318
|
(event.type === 'node.item-conflicted' ||
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { BuildStore, OperatorIdentity } from '../store/types'
|
|
2
|
+
|
|
3
|
+
/** A single budget covers cancellation, ordered withdrawal and handle closure. */
|
|
4
|
+
export class WatchLifetime {
|
|
5
|
+
readonly writes = new AbortController()
|
|
6
|
+
readonly deadline = new AbortController()
|
|
7
|
+
private timer: ReturnType<typeof setTimeout> | undefined
|
|
8
|
+
private pending: Promise<unknown> = Promise.resolve()
|
|
9
|
+
private withdrawal: Promise<void> | undefined
|
|
10
|
+
private identity: OperatorIdentity | undefined
|
|
11
|
+
private store: BuildStore | undefined
|
|
12
|
+
private repo = ''
|
|
13
|
+
private reported = false
|
|
14
|
+
private withdrawn = false
|
|
15
|
+
private readonly terminate = (): void => {
|
|
16
|
+
this.timer ??= setTimeout(() => this.deadline.abort(), 2_000)
|
|
17
|
+
this.writes.abort()
|
|
18
|
+
if (this.identity) this.withdrawal ??= this.withdraw()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly signal: AbortSignal | undefined,
|
|
23
|
+
private readonly stderr: (line: string) => void,
|
|
24
|
+
) {
|
|
25
|
+
signal?.addEventListener('abort', this.terminate, { once: true })
|
|
26
|
+
if (signal?.aborted) this.terminate()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get terminated(): boolean {
|
|
30
|
+
return this.signal?.aborted === true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
register(store: BuildStore, repo: string, identity: OperatorIdentity): Promise<unknown> {
|
|
34
|
+
this.store = store
|
|
35
|
+
this.repo = repo
|
|
36
|
+
this.identity = identity
|
|
37
|
+
// Even an already-terminated invocation must not leave a registration behind.
|
|
38
|
+
if (this.terminated) {
|
|
39
|
+
this.withdrawal ??= this.withdraw()
|
|
40
|
+
return Promise.resolve()
|
|
41
|
+
}
|
|
42
|
+
return this.renew()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
renew(): Promise<unknown> {
|
|
46
|
+
if (this.terminated) return Promise.resolve()
|
|
47
|
+
this.pending = this.store!.upsertOperatorPresence(this.repo, this.identity!, this.writes.signal)
|
|
48
|
+
return this.pending
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private report(error: unknown): void {
|
|
52
|
+
if (this.reported || !this.identity) return
|
|
53
|
+
this.reported = true
|
|
54
|
+
this.stderr(
|
|
55
|
+
`ab watch: operator withdrawal failed (${String(error)}); falling back to TTL expiry`,
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private async withdraw(): Promise<void> {
|
|
60
|
+
try {
|
|
61
|
+
// Abort and drain the writer before DELETE: a late heartbeat must never
|
|
62
|
+
// recreate the registration. Never race DELETE ahead of an unacknowledged write.
|
|
63
|
+
await this.pending.catch(() => {})
|
|
64
|
+
if (this.identity && !this.deadline.signal.aborted) {
|
|
65
|
+
await this.store!.removeOperatorPresence(this.repo, this.identity.id, this.deadline.signal)
|
|
66
|
+
this.withdrawn = true
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
this.report(error)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
limitCallback<A, T>(run: (arg: A) => Promise<T>): (arg: A) => Promise<T | undefined> {
|
|
74
|
+
return (arg) => this.limit(run(arg))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async limit<T>(task: Promise<T>): Promise<T | undefined> {
|
|
78
|
+
return untilDeadline(task, this.deadline.signal)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async finish(): Promise<void> {
|
|
82
|
+
if (!this.terminated) return
|
|
83
|
+
await this.limit(this.withdrawal ?? Promise.resolve())
|
|
84
|
+
if (this.deadline.signal.aborted && !this.withdrawn) this.report('shutdown deadline exceeded')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
close(): void {
|
|
88
|
+
this.signal?.removeEventListener('abort', this.terminate)
|
|
89
|
+
if (this.timer !== undefined) clearTimeout(this.timer)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function untilDeadline<T>(
|
|
94
|
+
task: Promise<T>,
|
|
95
|
+
signal: AbortSignal,
|
|
96
|
+
): Promise<T | undefined> {
|
|
97
|
+
if (signal.aborted) {
|
|
98
|
+
void task.catch(() => {})
|
|
99
|
+
return undefined
|
|
100
|
+
}
|
|
101
|
+
let expired: () => void = () => {}
|
|
102
|
+
const deadline = new Promise<undefined>((resolve) => {
|
|
103
|
+
expired = () => resolve(undefined)
|
|
104
|
+
signal.addEventListener('abort', expired, { once: true })
|
|
105
|
+
})
|
|
106
|
+
try {
|
|
107
|
+
return await Promise.race([task, deadline])
|
|
108
|
+
} finally {
|
|
109
|
+
signal.removeEventListener('abort', expired)
|
|
110
|
+
}
|
|
111
|
+
}
|