@defrex/autobuild 1.0.1 → 1.2.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 +10 -18
- package/SPEC.md +499 -238
- package/bin/ab-dispatch-generation.ts +11 -2
- package/docs/accounts.md +119 -0
- package/docs/agent-runtimes.md +4 -4
- package/docs/answering-blocked-builds.md +2 -2
- package/docs/architecture.md +262 -53
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +3 -41
- package/docs/builds.md +4 -4
- package/docs/cli.md +18 -4
- package/docs/configuration-overview.md +115 -4
- package/docs/configuration.md +488 -334
- package/docs/dispatcher-hosting.md +19 -34
- 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/intake.md +2 -0
- package/docs/integration-overview.md +15 -15
- package/docs/integration-tree.md +45 -38
- package/docs/integration.md +6 -6
- package/{skills/guide/references/landing-policy.md → docs/merge-policy.md} +40 -24
- package/docs/migration-1.0.md +17 -13
- package/docs/operating.md +41 -19
- package/docs/operator-api.md +180 -51
- package/docs/operator-surfaces.md +5 -18
- package/docs/overview.md +3 -3
- package/docs/plugin-authoring.md +21 -0
- package/docs/remote-store-protocol.md +242 -68
- package/docs/remote-ticket-protocol.md +30 -50
- package/docs/restacking.md +54 -15
- package/docs/seams.md +8 -8
- package/docs/setup.md +59 -119
- package/docs/skills.md +1 -1
- package/docs/spec-standard.md +6 -6
- package/docs/ticket-dependencies.md +7 -7
- package/docs/ticket-sources.md +18 -0
- package/docs/tickets.md +8 -2
- package/docs/troubleshooting.md +8 -12
- package/docs/upgrading.md +9 -4
- package/docs/verification.md +60 -14
- package/docs/workspaces.md +4 -4
- package/package.json +17 -6
- package/packages/core/src/accounts/chatgpt-oauth.ts +216 -0
- package/packages/core/src/accounts/chatgpt-state.ts +41 -0
- package/packages/core/src/accounts/local-credentials.ts +194 -0
- package/packages/core/src/accounts/local-inference.ts +106 -0
- package/packages/core/src/accounts/local-owner.ts +123 -0
- package/packages/core/src/accounts/sensitive.ts +2 -0
- package/packages/core/src/cli/accounts.ts +147 -0
- 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/binary.ts +3 -1
- package/packages/core/src/cli/build-control.ts +83 -28
- package/packages/core/src/cli/connect.ts +3 -3
- 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-handoff.ts +125 -44
- package/packages/core/src/cli/dispatch-launch-contract.ts +187 -0
- package/packages/core/src/cli/dispatch-launcher.ts +54 -21
- package/packages/core/src/cli/dispatch-preflight.ts +6 -1
- package/packages/core/src/cli/dispatch.ts +106 -11
- package/packages/core/src/cli/env.ts +4 -0
- package/packages/core/src/cli/help.ts +46 -23
- package/packages/core/src/cli/init-readiness-remote.ts +22 -1
- package/packages/core/src/cli/init-readiness-shared.ts +5 -1
- package/packages/core/src/cli/init-validation.ts +160 -18
- package/packages/core/src/cli/main.ts +68 -8
- package/packages/core/src/cli/node-verification-provenance.ts +1 -97
- package/packages/core/src/cli/publication-settlement.ts +47 -21
- package/packages/core/src/cli/repository-status.ts +20 -9
- package/packages/core/src/cli/secrets.ts +173 -0
- package/packages/core/src/cli/status.ts +42 -5
- package/packages/core/src/cli/store-opening.ts +17 -2
- package/packages/core/src/cli/terminal.ts +22 -1
- package/packages/core/src/cli/terminals.ts +14 -10
- package/packages/core/src/cli/upgrade-agent.ts +9 -1
- 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 +635 -510
- package/packages/core/src/config/accounts.ts +101 -0
- 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/live.ts +14 -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/roles.ts +54 -3
- package/packages/core/src/config/schema.ts +146 -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/compatibility.ts +2 -1
- package/packages/core/src/events/globs.ts +1 -1
- package/packages/core/src/events/payloads.ts +73 -1
- package/packages/core/src/events/policy.ts +7 -0
- package/packages/core/src/events/repository.ts +4 -4
- package/packages/core/src/events/sessions.ts +6 -6
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +574 -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 +85 -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 +3 -7
- package/packages/core/src/operator/landings.ts +5 -1
- package/packages/core/src/operator/presentation.ts +6 -1
- package/packages/core/src/operator/protocol.ts +6 -0
- package/packages/core/src/operator/query.ts +14 -18
- package/packages/core/src/operator/registry.ts +39 -7
- 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/operator/tickets.ts +25 -4
- package/packages/core/src/plugins/manifest.ts +2 -1
- 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/runner/account-env.ts +88 -0
- package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
- package/packages/core/src/ports/runner/claude.ts +26 -2
- package/packages/core/src/ports/runner/codex.ts +63 -31
- package/packages/core/src/ports/runner/one-shot.ts +2 -0
- package/packages/core/src/ports/runner/provider-error.ts +5 -0
- package/packages/core/src/ports/runner/routing.ts +35 -4
- package/packages/core/src/ports/tickets/contract.ts +58 -0
- package/packages/core/src/ports/tickets/tree.ts +1 -1
- package/packages/core/src/ports/types.ts +28 -7
- package/packages/core/src/ports/workspace/account-policy.ts +72 -0
- package/packages/core/src/ports/workspace/build-execution.ts +9 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +1 -0
- package/packages/core/src/ports/workspace/create.ts +2 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +6 -1
- package/packages/core/src/ports/workspace/phase-scratch.ts +4 -3
- package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +182 -72
- 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 +554 -99
- package/packages/core/src/processes/dispatcher.ts +209 -101
- package/packages/core/src/processes/execution-no-progress.ts +8 -1
- package/packages/core/src/processes/execution-settlement.ts +21 -3
- package/packages/core/src/processes/harvest-runner.ts +68 -8
- 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/project-secrets.ts +105 -0
- package/packages/core/src/{integration → scenarios}/harness.ts +330 -317
- package/packages/core/src/secret-name.ts +41 -0
- package/packages/core/src/store/account-redaction.ts +156 -0
- 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 +116 -2
- 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 +5185 -4156
- package/packages/core/src/store/remote/client.ts +89 -48
- package/packages/core/src/store/remote/compatibility.ts +20 -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/dispatch-read-budget.ts +122 -0
- package/packages/core/src/testing/index.ts +12 -1
- package/packages/core/src/testing/reduced-read-budget.ts +47 -0
- 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 +373 -148
- package/skills/guide/references/accounts.md +119 -0
- package/skills/guide/references/integration-tree.md +45 -38
- package/{docs/landing-policy.md → skills/guide/references/merge-policy.md} +40 -24
- package/skills/guide/references/migration-1.0.md +17 -13
- package/skills/guide/references/operator-api.md +180 -51
- package/skills/guide/references/plugin-authoring.md +21 -0
- package/skills/guide/references/remote-store-protocol.md +242 -68
- package/skills/guide/references/remote-ticket-protocol.md +30 -50
- package/skills/guide/references/restacking.md +54 -15
- package/skills/guide/references/setup.md +59 -119
- package/skills/guide/references/spec-standard.md +6 -6
- package/skills/guide/references/ticket-dependencies.md +7 -7
- package/skills/harvest/SKILL.md +3 -1
- package/skills/harvest-review/SKILL.md +3 -1
- package/skills/implement/SKILL.md +43 -17
- package/skills/operate/SKILL.md +118 -118
- 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 +20 -20
- package/skills/tickets/SKILL.md +12 -9
- package/templates/autobuild.toml +1 -1
- package/templates/hosted-service/package.json +2 -2
- package/docs/hosted-dispatcher-cutover-validation.md +0 -178
- package/docs/hosted-dispatcher.md +0 -275
- package/docs/hosted-service.md +0 -293
- package/docs/mcp.md +0 -149
- 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))
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { SECRET_NAME_EXPLANATION } from '../secret-name'
|
|
2
|
+
import { connectedProject } from './connect'
|
|
3
|
+
import { ProjectCredentials } from './project-credentials'
|
|
4
|
+
import type { Exec } from '../ports/workspace/git-worktree'
|
|
5
|
+
import { decodeSecretMetadata, validateSecretName, validateSecretValue } from '../project-secrets'
|
|
6
|
+
import {
|
|
7
|
+
AUTOBUILD_VERSION,
|
|
8
|
+
AUTOBUILD_VERSION_HEADER,
|
|
9
|
+
REMOTE_STORE_PROTOCOL_VERSION,
|
|
10
|
+
REMOTE_STORE_PROTOCOL_VERSION_HEADER,
|
|
11
|
+
} from '../store/remote/version'
|
|
12
|
+
/** Raw mode disables terminal echo before listening. Restore the exact prior state on every exit. */
|
|
13
|
+
export async function readSecretInput(
|
|
14
|
+
input: NodeJS.ReadStream = process.stdin,
|
|
15
|
+
prompt: (s: string) => void = (s) => {
|
|
16
|
+
process.stderr.write(s)
|
|
17
|
+
},
|
|
18
|
+
): Promise<string> {
|
|
19
|
+
if (!input.isTTY) {
|
|
20
|
+
const chunks: Buffer[] = []
|
|
21
|
+
let size = 0
|
|
22
|
+
for await (const chunk of input) {
|
|
23
|
+
const b = Buffer.from(chunk)
|
|
24
|
+
size += b.length
|
|
25
|
+
if (size > 65538) throw new Error('Secret input too large')
|
|
26
|
+
chunks.push(b)
|
|
27
|
+
}
|
|
28
|
+
return Buffer.concat(chunks)
|
|
29
|
+
.toString()
|
|
30
|
+
.replace(/\r?\n$/, '')
|
|
31
|
+
}
|
|
32
|
+
const wasPaused = input.isPaused()
|
|
33
|
+
const wasRaw = input.isRaw
|
|
34
|
+
input.setRawMode(true)
|
|
35
|
+
try {
|
|
36
|
+
prompt('Secret value: ')
|
|
37
|
+
} catch {
|
|
38
|
+
input.setRawMode(wasRaw)
|
|
39
|
+
throw new Error('Secret input failed')
|
|
40
|
+
}
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
let value = ''
|
|
43
|
+
const finish = (error?: Error) => {
|
|
44
|
+
input.off('data', data)
|
|
45
|
+
input.off('end', end)
|
|
46
|
+
input.off('error', failed)
|
|
47
|
+
process.off('SIGINT', cancel)
|
|
48
|
+
input.setRawMode(wasRaw)
|
|
49
|
+
if (wasPaused) input.pause()
|
|
50
|
+
else input.resume()
|
|
51
|
+
prompt('\n')
|
|
52
|
+
if (error) reject(error)
|
|
53
|
+
else resolve(value)
|
|
54
|
+
}
|
|
55
|
+
const cancel = () => finish(new Error('Secret input cancelled'))
|
|
56
|
+
const end = () => finish(new Error('Secret input ended'))
|
|
57
|
+
const failed = () => finish(new Error('Secret input failed'))
|
|
58
|
+
const data = (chunk: Buffer) => {
|
|
59
|
+
for (const c of chunk.toString()) {
|
|
60
|
+
if (c === '\x03') {
|
|
61
|
+
cancel()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
if (c === '\x04') {
|
|
65
|
+
end()
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
if (c === '\r' || c === '\n') {
|
|
69
|
+
finish()
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
if (c === '\x7f' || c === '\b') value = value.slice(0, -1)
|
|
73
|
+
else value += c
|
|
74
|
+
if (Buffer.byteLength(value) > 65536) {
|
|
75
|
+
finish(new Error('Secret input too large'))
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
input.on('data', data)
|
|
81
|
+
input.once('end', end)
|
|
82
|
+
input.once('error', failed)
|
|
83
|
+
process.once('SIGINT', cancel)
|
|
84
|
+
input.resume()
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
export async function abSecrets(
|
|
88
|
+
operation: string | undefined,
|
|
89
|
+
name: string | undefined,
|
|
90
|
+
opts: {
|
|
91
|
+
cwd: string
|
|
92
|
+
env: Record<string, string | undefined>
|
|
93
|
+
exec: Exec
|
|
94
|
+
print: (s: string) => void
|
|
95
|
+
json?: boolean
|
|
96
|
+
readValue?: () => Promise<string>
|
|
97
|
+
fetch?: (input: string, init?: RequestInit) => Promise<Response>
|
|
98
|
+
},
|
|
99
|
+
): Promise<void> {
|
|
100
|
+
if (
|
|
101
|
+
!['list', 'set', 'remove'].includes(operation ?? '') ||
|
|
102
|
+
(operation === 'list' ? name !== undefined : name === undefined)
|
|
103
|
+
)
|
|
104
|
+
throw new Error('usage: ab secrets list [--json] | set NAME | remove NAME')
|
|
105
|
+
if (name !== undefined) {
|
|
106
|
+
try {
|
|
107
|
+
validateSecretName(name)
|
|
108
|
+
} catch {
|
|
109
|
+
throw new Error(SECRET_NAME_EXPLANATION)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const project = await connectedProject(opts)
|
|
113
|
+
if (!project.service) throw new Error('No connected build service; run ab connect <url>')
|
|
114
|
+
const credential = new ProjectCredentials(opts.env).load(project.service, project.repo)
|
|
115
|
+
if (!credential) throw new Error('Missing saved project credential; run ab connect')
|
|
116
|
+
const body: Record<string, unknown> = { version: 1, repo: project.repo, name }
|
|
117
|
+
if (operation === 'set') {
|
|
118
|
+
const value = await (opts.readValue ?? readSecretInput)()
|
|
119
|
+
validateSecretValue(value)
|
|
120
|
+
body.value = value
|
|
121
|
+
}
|
|
122
|
+
let response: Response
|
|
123
|
+
try {
|
|
124
|
+
response = await (opts.fetch ?? fetch)(
|
|
125
|
+
`${project.service}/secrets/v1/${operation}${operation === 'list' ? `?repo=${encodeURIComponent(project.repo)}` : ''}`,
|
|
126
|
+
{
|
|
127
|
+
method: operation === 'list' ? 'GET' : 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
'content-type': 'application/json',
|
|
130
|
+
authorization: `Bearer ${credential.token}`,
|
|
131
|
+
[AUTOBUILD_VERSION_HEADER]: AUTOBUILD_VERSION,
|
|
132
|
+
[REMOTE_STORE_PROTOCOL_VERSION_HEADER]: REMOTE_STORE_PROTOCOL_VERSION,
|
|
133
|
+
},
|
|
134
|
+
...(operation === 'list' ? {} : { body: JSON.stringify(body) }),
|
|
135
|
+
signal: AbortSignal.timeout(15000),
|
|
136
|
+
redirect: 'error',
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
} catch {
|
|
140
|
+
throw new Error('Project secrets request failed')
|
|
141
|
+
}
|
|
142
|
+
if (!response.ok) throw new Error(`Project secrets request refused (${response.status})`)
|
|
143
|
+
try {
|
|
144
|
+
const result = await response.json()
|
|
145
|
+
if (
|
|
146
|
+
!result ||
|
|
147
|
+
typeof result !== 'object' ||
|
|
148
|
+
Object.keys(result).length !== 2 ||
|
|
149
|
+
result.version !== 1
|
|
150
|
+
)
|
|
151
|
+
throw new Error()
|
|
152
|
+
if (operation === 'list') {
|
|
153
|
+
if (!Array.isArray(result.secrets)) throw new Error()
|
|
154
|
+
const secrets: ReturnType<typeof decodeSecretMetadata>[] =
|
|
155
|
+
result.secrets.map(decodeSecretMetadata)
|
|
156
|
+
opts.print(
|
|
157
|
+
opts.json
|
|
158
|
+
? JSON.stringify({ version: 1, secrets })
|
|
159
|
+
: secrets
|
|
160
|
+
.map(
|
|
161
|
+
(s) =>
|
|
162
|
+
`${s.name}\t${s.status}\t${s.owner}\t${s.setAt}\t${s.fingerprint}\t${s.lastSuppliedAt ?? 'never supplied'}${s.warnings?.length ? `\t${s.warnings.join(', ')}` : ''}`,
|
|
163
|
+
)
|
|
164
|
+
.join('\n') || 'No project secrets.',
|
|
165
|
+
)
|
|
166
|
+
} else {
|
|
167
|
+
if (result.ok !== true) throw new Error()
|
|
168
|
+
opts.print(`Secret ${operation === 'set' ? 'saved' : 'removed'}.`)
|
|
169
|
+
}
|
|
170
|
+
} catch {
|
|
171
|
+
throw new Error('Invalid project secrets response')
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -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,5 @@
|
|
|
1
|
+
import { AccountRedactor, redactAccountStore } from '../store/account-redaction'
|
|
2
|
+
import { untilDeadline } from './watch-lifetime'
|
|
1
3
|
/**
|
|
2
4
|
* Production BuildStore composition for CLI commands.
|
|
3
5
|
*
|
|
@@ -34,10 +36,19 @@ function optionalToken(value: string | undefined): string | undefined {
|
|
|
34
36
|
* and does not import the HTTP adapter. */
|
|
35
37
|
export const openProductionStore: StoreOpener = (ref, token) => {
|
|
36
38
|
const forwardedToken = optionalToken(token)
|
|
37
|
-
|
|
39
|
+
const store = resolveStore(ref, {
|
|
38
40
|
remoteFactory: (url, remoteToken) => new RemoteBuildStore({ url, token: remoteToken }),
|
|
39
41
|
...(forwardedToken !== undefined ? { token: forwardedToken } : {}),
|
|
40
42
|
})
|
|
43
|
+
const raw = process.env.AB_ACCOUNT_CREDENTIAL_ENVS
|
|
44
|
+
if (!raw) return store
|
|
45
|
+
const names: unknown = JSON.parse(raw)
|
|
46
|
+
if (!Array.isArray(names) || !names.every((name) => typeof name === 'string'))
|
|
47
|
+
throw new Error('Invalid account credential variable inventory')
|
|
48
|
+
return redactAccountStore(
|
|
49
|
+
store,
|
|
50
|
+
new AccountRedactor(() => names.map((name) => process.env[name])),
|
|
51
|
+
)
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
/** Apply validated ambient authority to a selected Store handle. Remote
|
|
@@ -99,6 +110,8 @@ export function openStoreForRepoState(
|
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
export interface SessionlessStoreOpts extends OpenStoreForRepoStateOpts {
|
|
113
|
+
/** Optional command-owned shutdown budget for handle closure. */
|
|
114
|
+
closeDeadline?: AbortSignal
|
|
102
115
|
targetRepo: string
|
|
103
116
|
exec: Exec
|
|
104
117
|
/** Explicit --store; precedence is applied by repo-state.ts. */
|
|
@@ -170,6 +183,8 @@ export async function withAmbientReadStore<T>(
|
|
|
170
183
|
try {
|
|
171
184
|
return await use(context)
|
|
172
185
|
} finally {
|
|
173
|
-
|
|
186
|
+
const closing = context.store.close()
|
|
187
|
+
if (opts.closeDeadline) await untilDeadline(closing, opts.closeDeadline)
|
|
188
|
+
else await closing
|
|
174
189
|
}
|
|
175
190
|
}
|
|
@@ -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
|
|
|
@@ -87,6 +87,7 @@ export function upgradeConflictPrompt(input: {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
interface ResolvedCompletion {
|
|
90
|
+
account?: import('../config/accounts').SelectedAccount
|
|
90
91
|
oneShot: OneShotCompletion
|
|
91
92
|
model?: string
|
|
92
93
|
args: readonly string[]
|
|
@@ -110,7 +111,12 @@ export function createUpgradeAgentResolver(opts: UpgradeAgentResolverOpts): Reso
|
|
|
110
111
|
repoRoot: opts.targetRepo,
|
|
111
112
|
env: opts.env,
|
|
112
113
|
})
|
|
113
|
-
const selected = createRuntimeResolver(
|
|
114
|
+
const selected = createRuntimeResolver(
|
|
115
|
+
runtimes,
|
|
116
|
+
config.roles,
|
|
117
|
+
config.policy.sessionBudgetSeconds,
|
|
118
|
+
config.accounts,
|
|
119
|
+
).resolve(UPGRADE_ROLE)
|
|
114
120
|
const oneShot = runtimes[selected.runtime]?.oneShot
|
|
115
121
|
if (oneShot === undefined) {
|
|
116
122
|
throw new Error(
|
|
@@ -122,6 +128,7 @@ export function createUpgradeAgentResolver(opts: UpgradeAgentResolverOpts): Reso
|
|
|
122
128
|
oneShot,
|
|
123
129
|
...(selected.model !== undefined ? { model: selected.model } : {}),
|
|
124
130
|
args: selected.args,
|
|
131
|
+
account: selected.account,
|
|
125
132
|
}
|
|
126
133
|
})()
|
|
127
134
|
return resolved
|
|
@@ -167,6 +174,7 @@ export function createUpgradeAgentResolver(opts: UpgradeAgentResolverOpts): Reso
|
|
|
167
174
|
signal: controller.signal,
|
|
168
175
|
...(selected.model !== undefined ? { model: selected.model } : {}),
|
|
169
176
|
args: selected.args,
|
|
177
|
+
account: selected.account,
|
|
170
178
|
}),
|
|
171
179
|
stopped,
|
|
172
180
|
])
|
|
@@ -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
|
|