@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,4 @@
|
|
|
1
|
+
import { accountRedactor, redactAccountStore } from '../store/account-redaction'
|
|
1
2
|
import {
|
|
2
3
|
guardNativeHandle,
|
|
3
4
|
nativeSessionHandleSchema,
|
|
@@ -5,7 +6,6 @@ import {
|
|
|
5
6
|
} from '../ports/runner/native-session'
|
|
6
7
|
import type { NativeSessionHandle, AgentStartOpts } from '../ports/types'
|
|
7
8
|
import { readRepositoryFacts } from '../store/reduced-reads'
|
|
8
|
-
import { ticketIdentity } from '../ports/tickets/identity'
|
|
9
9
|
import { issueTicketGrant } from '../ports/tickets/grants'
|
|
10
10
|
import { delegateCredential } from '../store/remote/credentials'
|
|
11
11
|
/**
|
|
@@ -208,6 +208,15 @@ export class HarvestRunner {
|
|
|
208
208
|
private producer: ProducerSession | undefined
|
|
209
209
|
|
|
210
210
|
constructor(private readonly deps: HarvestRunnerDeps) {
|
|
211
|
+
const redactor = accountRedactor(
|
|
212
|
+
() => (deps.getConfig?.() ?? deps.config).accounts,
|
|
213
|
+
() => ({
|
|
214
|
+
...process.env,
|
|
215
|
+
...deps.sessionEnv,
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
deps.store = redactAccountStore(deps.store, redactor)
|
|
219
|
+
|
|
211
220
|
this.leaseTtlMs = deps.opts?.leaseTtlMs ?? 60_000
|
|
212
221
|
this.heartbeatMs = deps.opts?.heartbeatMs ?? 15_000
|
|
213
222
|
this.maxSessionAttempts = deps.opts?.maxSessionAttempts ?? 2
|
|
@@ -219,7 +228,12 @@ export class HarvestRunner {
|
|
|
219
228
|
throw new Error('maxRecoveryAttempts must be a positive integer')
|
|
220
229
|
}
|
|
221
230
|
// Preserve eager validation for static callers and startup failures.
|
|
222
|
-
createRuntimeResolver(
|
|
231
|
+
createRuntimeResolver(
|
|
232
|
+
deps.runtimes,
|
|
233
|
+
deps.config.roles,
|
|
234
|
+
deps.config.policy.sessionBudgetSeconds,
|
|
235
|
+
deps.config.accounts,
|
|
236
|
+
)
|
|
223
237
|
}
|
|
224
238
|
|
|
225
239
|
private currentConfig(): Config {
|
|
@@ -232,6 +246,7 @@ export class HarvestRunner {
|
|
|
232
246
|
this.deps.runtimes,
|
|
233
247
|
config.roles,
|
|
234
248
|
config.policy.sessionBudgetSeconds,
|
|
249
|
+
config.accounts,
|
|
235
250
|
)
|
|
236
251
|
}
|
|
237
252
|
|
|
@@ -673,13 +688,29 @@ export class HarvestRunner {
|
|
|
673
688
|
JSON.stringify(t.args) === JSON.stringify(prior.args ?? []),
|
|
674
689
|
)
|
|
675
690
|
: undefined
|
|
676
|
-
const
|
|
691
|
+
const frozen =
|
|
692
|
+
prior && this.deps.runtimes[prior.runner]
|
|
693
|
+
? {
|
|
694
|
+
target: {
|
|
695
|
+
...primary,
|
|
696
|
+
...this.deps.runtimes[prior.runner],
|
|
697
|
+
runner: this.deps.runtimes[prior.runner]!.runner,
|
|
698
|
+
runtime: prior.runner,
|
|
699
|
+
model: prior.model,
|
|
700
|
+
args: prior.args ?? [],
|
|
701
|
+
account: prior.account,
|
|
702
|
+
},
|
|
703
|
+
index: selected?.index ?? 0,
|
|
704
|
+
}
|
|
705
|
+
: undefined
|
|
706
|
+
const targets = frozen ? [frozen, ...candidates.filter((t) => t !== selected)] : candidates
|
|
677
707
|
const attempts: HarvestProviderAttempt[] = []
|
|
678
708
|
let substitution: HarvestProviderAttempt | undefined
|
|
679
709
|
const primaryRoute = JSON.stringify({
|
|
680
710
|
runtime: primary.runtime,
|
|
681
711
|
model: primary.model,
|
|
682
712
|
args: primary.args,
|
|
713
|
+
account: primary.account,
|
|
683
714
|
})
|
|
684
715
|
let primaryLive = spec.producer ? this.producer : undefined
|
|
685
716
|
if (
|
|
@@ -715,6 +746,7 @@ export class HarvestRunner {
|
|
|
715
746
|
session,
|
|
716
747
|
role: spec.role,
|
|
717
748
|
runner: target.runtime,
|
|
749
|
+
...(target.account === undefined ? {} : { account: target.account }),
|
|
718
750
|
...(target.model !== undefined ? { model: target.model } : {}),
|
|
719
751
|
phase: `harvest:${spec.step}`,
|
|
720
752
|
round: spec.round,
|
|
@@ -730,6 +762,7 @@ export class HarvestRunner {
|
|
|
730
762
|
...(continuation ? { continuation } : {}),
|
|
731
763
|
role: spec.role,
|
|
732
764
|
runner: target.runtime,
|
|
765
|
+
...(target.account === undefined ? {} : { account: target.account }),
|
|
733
766
|
...(target.model !== undefined ? { model: target.model } : {}),
|
|
734
767
|
args: [...target.args],
|
|
735
768
|
step: spec.step,
|
|
@@ -805,6 +838,7 @@ export class HarvestRunner {
|
|
|
805
838
|
skill: spec.skill,
|
|
806
839
|
invocation: spec.run,
|
|
807
840
|
workspacePath,
|
|
841
|
+
...(target.account === undefined ? {} : { account: target.account }),
|
|
808
842
|
...(target.model !== undefined ? { model: target.model } : {}),
|
|
809
843
|
args: target.args,
|
|
810
844
|
env: await this.sessionEnv(spec.run, spec.step, spec.round, session),
|
|
@@ -1062,6 +1096,7 @@ export class HarvestRunner {
|
|
|
1062
1096
|
index,
|
|
1063
1097
|
session,
|
|
1064
1098
|
runner: target.runtime,
|
|
1099
|
+
...(target.account === undefined ? {} : { account: target.account }),
|
|
1065
1100
|
...(target.model !== undefined ? { model: target.model } : {}),
|
|
1066
1101
|
error: failure.message,
|
|
1067
1102
|
...(failure.cause !== undefined ? { cause: failure.cause } : {}),
|
|
@@ -1175,14 +1210,36 @@ export class HarvestRunner {
|
|
|
1175
1210
|
)
|
|
1176
1211
|
const packet = await loadScanPacket(store, repo, current.scan)
|
|
1177
1212
|
const observations = packet.observations
|
|
1178
|
-
|
|
1213
|
+
// One fresh lookup view per filing attempt, shared only by ledger and joins.
|
|
1214
|
+
// Blocker refreshes retain their own authoritative boundary.
|
|
1215
|
+
const lookups = new Map<string, ReturnType<typeof tickets.get>>()
|
|
1216
|
+
const lookup = (id: string): ReturnType<typeof tickets.get> => {
|
|
1217
|
+
let pending = lookups.get(id)
|
|
1218
|
+
if (!pending) {
|
|
1219
|
+
pending = tickets.get(id).then((ticket) => {
|
|
1220
|
+
if (ticket?.ref.source === tickets.name) {
|
|
1221
|
+
lookups.set(ticket.ref.id, Promise.resolve(ticket))
|
|
1222
|
+
}
|
|
1223
|
+
return ticket
|
|
1224
|
+
})
|
|
1225
|
+
lookups.set(id, pending)
|
|
1226
|
+
}
|
|
1227
|
+
return pending
|
|
1228
|
+
}
|
|
1229
|
+
const identity = async (ref: { source: string; id: string }): Promise<string> => {
|
|
1230
|
+
const ticket =
|
|
1231
|
+
ref.source === tickets.name && tickets.name === 'hosted' ? await lookup(ref.id) : null
|
|
1232
|
+
return `${ref.source}:${ticket?.ref.source === ref.source ? ticket.ref.id : ref.id}`
|
|
1233
|
+
}
|
|
1179
1234
|
const knownLedger = new Map<string, (typeof packet.ledger)[number]>()
|
|
1180
1235
|
for (const entry of packet.ledger) {
|
|
1181
|
-
const current =
|
|
1182
|
-
|
|
1183
|
-
knownLedger.set(
|
|
1236
|
+
const current = entry.ticket.source === tickets.name ? await lookup(entry.ticket.id) : null
|
|
1237
|
+
const ref = current?.ref.source === entry.ticket.source ? current.ref : entry.ticket
|
|
1238
|
+
knownLedger.set(`${ref.source}:${ref.id}`, {
|
|
1184
1239
|
...entry,
|
|
1185
|
-
ticket:
|
|
1240
|
+
ticket: ref,
|
|
1241
|
+
exists: current !== null,
|
|
1242
|
+
resolved: current?.resolved ?? false,
|
|
1186
1243
|
})
|
|
1187
1244
|
}
|
|
1188
1245
|
const alreadyFiled = new Map(current.filed.map((entry) => [entry.proposalKey, entry]))
|
|
@@ -1658,6 +1715,9 @@ export class HarvestRunner {
|
|
|
1658
1715
|
)
|
|
1659
1716
|
: undefined
|
|
1660
1717
|
return {
|
|
1718
|
+
AB_ACCOUNT_CREDENTIAL_ENVS: JSON.stringify(
|
|
1719
|
+
Object.values(this.currentConfig().accounts).map((account) => account.credentialEnv),
|
|
1720
|
+
),
|
|
1661
1721
|
AB_STORE: 'local',
|
|
1662
1722
|
...this.deps.sessionEnv,
|
|
1663
1723
|
...(ticketGrant ? { AB_TICKET_TOKEN: ticketGrant.token } : {}),
|
|
@@ -15,6 +15,7 @@ export const POLICY_PHASE_FAILURE_RESET_SCOPES = {
|
|
|
15
15
|
'execution-no-progress': 'none',
|
|
16
16
|
'setup-failure-limit': 'none',
|
|
17
17
|
'infrastructure-failure-limit': 'none',
|
|
18
|
+
'publication-retry-limit': 'none',
|
|
18
19
|
'phase-attempt-limit': 'matching-round',
|
|
19
20
|
'non-retryable-phase-failure': 'matching-round',
|
|
20
21
|
} as const satisfies Record<PolicyEscalationCause, PhaseFailureBudgetResetScope>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PublicationRetryPersistenceError } from '../kernel/publication-retry'
|
|
1
2
|
import { ForgeRequestDeferred } from '../ports/forge-request-context'
|
|
2
3
|
import { isRemoteWorkspace } from '../events/workspace-remote'
|
|
3
4
|
/**
|
|
@@ -63,7 +64,11 @@ export async function settlePublicationFactsBeforeRelease(
|
|
|
63
64
|
try {
|
|
64
65
|
await deps.settlePublication?.(slug)
|
|
65
66
|
} catch (error) {
|
|
66
|
-
if (
|
|
67
|
+
if (
|
|
68
|
+
error instanceof ForgeRequestDeferred ||
|
|
69
|
+
error instanceof PublicationRetryPersistenceError
|
|
70
|
+
)
|
|
71
|
+
throw error
|
|
67
72
|
/* Summary is best effort. */
|
|
68
73
|
}
|
|
69
74
|
return (await readBuildFacts(deps.store, slug)).value
|
|
@@ -73,7 +78,8 @@ export async function settlePublicationFactsBeforeRelease(
|
|
|
73
78
|
try {
|
|
74
79
|
await deps.settlePublication?.(slug)
|
|
75
80
|
} catch (error) {
|
|
76
|
-
if (error instanceof ForgeRequestDeferred
|
|
81
|
+
if (error instanceof ForgeRequestDeferred || error instanceof PublicationRetryPersistenceError)
|
|
82
|
+
throw error
|
|
77
83
|
/* Record loss before release. */
|
|
78
84
|
}
|
|
79
85
|
const refreshed = (await readBuildFacts(deps.store, slug)).value
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
publicationRetryState,
|
|
3
|
+
type PublicationOperation,
|
|
4
|
+
type PublicationRetryEvent,
|
|
5
|
+
} from '../kernel/publication-retry'
|
|
1
6
|
import { reconcileHead } from '../kernel/reconcile-head'
|
|
2
7
|
import type { AbEvent } from '../events/catalog'
|
|
3
8
|
import { defineReducer, type IncrementalReducer } from '../kernel/incremental'
|
|
@@ -28,10 +33,11 @@ type LedgerItem =
|
|
|
28
33
|
* any type) whose seq exceeds the request's. */
|
|
29
34
|
export interface PublicationLedger {
|
|
30
35
|
ledger: LedgerItem[]
|
|
36
|
+
retries: PublicationRetryEvent[]
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
/** Bump when `PublicationLedger` or its fold changes. */
|
|
34
|
-
export const PUBLICATION_STATE_REDUCER_VERSION =
|
|
40
|
+
export const PUBLICATION_STATE_REDUCER_VERSION = 6
|
|
35
41
|
|
|
36
42
|
function compact(event: AbEvent): LedgerItem | undefined {
|
|
37
43
|
switch (event.type) {
|
|
@@ -111,6 +117,7 @@ function itemCompletes(item: LedgerItem, request: PublicationRequest): boolean {
|
|
|
111
117
|
|
|
112
118
|
/** The publication selectors, derived from one ledger. */
|
|
113
119
|
export interface PublicationView {
|
|
120
|
+
retry(operation: PublicationOperation, id: string): ReturnType<typeof publicationRetryState>
|
|
114
121
|
requestCompleted(request: PublicationRequest): boolean
|
|
115
122
|
requestSettled(request: PublicationRequest): boolean
|
|
116
123
|
latestUncompletedRequest(): PublicationRequest | undefined
|
|
@@ -119,7 +126,10 @@ export interface PublicationView {
|
|
|
119
126
|
pending(): boolean
|
|
120
127
|
}
|
|
121
128
|
|
|
122
|
-
function viewOf(
|
|
129
|
+
function viewOf(
|
|
130
|
+
ledger: readonly LedgerItem[],
|
|
131
|
+
retries: readonly PublicationRetryEvent[],
|
|
132
|
+
): PublicationView {
|
|
123
133
|
const requestCompleted = (request: PublicationRequest): boolean =>
|
|
124
134
|
ledger.some((item) => itemCompletes(item, request))
|
|
125
135
|
|
|
@@ -153,6 +163,7 @@ function viewOf(ledger: readonly LedgerItem[]): PublicationView {
|
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
return {
|
|
166
|
+
retry: (operation, id) => publicationRetryState(retries, operation, id),
|
|
156
167
|
requestCompleted,
|
|
157
168
|
requestSettled,
|
|
158
169
|
latestUncompletedRequest,
|
|
@@ -172,9 +183,36 @@ export const publicationStateReducer: IncrementalReducer<
|
|
|
172
183
|
PublicationView
|
|
173
184
|
> = defineReducer<PublicationLedger, AbEvent, PublicationView>({
|
|
174
185
|
version: PUBLICATION_STATE_REDUCER_VERSION,
|
|
175
|
-
initial: () => ({ ledger: [] }),
|
|
186
|
+
initial: () => ({ ledger: [], retries: [] }),
|
|
176
187
|
fold(acc, events) {
|
|
177
188
|
for (const event of events) {
|
|
189
|
+
if (
|
|
190
|
+
event.type === 'publication.retry-scheduled' ||
|
|
191
|
+
event.type === 'publication.retry-exhausted' ||
|
|
192
|
+
event.type === 'escalation.answered'
|
|
193
|
+
)
|
|
194
|
+
acc.retries.push(event)
|
|
195
|
+
if (
|
|
196
|
+
event.type === 'restack.completed' ||
|
|
197
|
+
event.type === 'restack.contended' ||
|
|
198
|
+
event.type === 'reconcile.contended' ||
|
|
199
|
+
(event.type === 'reconcile.completed' && 'rewriteId' in event.payload)
|
|
200
|
+
) {
|
|
201
|
+
const id =
|
|
202
|
+
'id' in event.payload
|
|
203
|
+
? event.payload.id
|
|
204
|
+
: 'rewriteId' in event.payload
|
|
205
|
+
? event.payload.rewriteId
|
|
206
|
+
: undefined
|
|
207
|
+
const operation = event.type.startsWith('restack.') ? 'restack' : 'reconcile'
|
|
208
|
+
acc.retries = acc.retries.filter(
|
|
209
|
+
(e) =>
|
|
210
|
+
e.type === 'escalation.answered' ||
|
|
211
|
+
e.payload.operation !== operation ||
|
|
212
|
+
e.payload.rewriteId !== id,
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
if (event.type === 'workspace.released') acc.retries = []
|
|
178
216
|
const item = compact(event)
|
|
179
217
|
const last = acc.ledger[acc.ledger.length - 1]
|
|
180
218
|
if (item !== undefined) acc.ledger.push(item)
|
|
@@ -182,7 +220,7 @@ export const publicationStateReducer: IncrementalReducer<
|
|
|
182
220
|
else acc.ledger.push({ t: 'barrier', seq: event.seq })
|
|
183
221
|
}
|
|
184
222
|
},
|
|
185
|
-
finish: (acc) => viewOf(acc.ledger),
|
|
223
|
+
finish: (acc) => viewOf(acc.ledger, acc.retries),
|
|
186
224
|
})
|
|
187
225
|
|
|
188
226
|
export function publicationRequestCompleted(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OperatorIdentity, OperatorPresence } from '../store/operator-presence'
|
|
1
2
|
import { readBuildDigests } from '../store/reduced-reads'
|
|
2
3
|
/** Repository-scoped sequencing and metadata coordination. Current reductions
|
|
3
4
|
* come exclusively from persisted values; raw methods return actual event output. */
|
|
@@ -461,6 +462,19 @@ export class RepoViewStore implements BuildStore {
|
|
|
461
462
|
await this.backing.releaseLease(slug, holder)
|
|
462
463
|
this.invalidate()
|
|
463
464
|
}
|
|
465
|
+
upsertOperatorPresence(
|
|
466
|
+
repo: string,
|
|
467
|
+
identity: OperatorIdentity,
|
|
468
|
+
signal?: AbortSignal,
|
|
469
|
+
): Promise<OperatorPresence> {
|
|
470
|
+
return this.backing.upsertOperatorPresence(repo, identity, signal)
|
|
471
|
+
}
|
|
472
|
+
removeOperatorPresence(repo: string, id: string, signal?: AbortSignal): Promise<void> {
|
|
473
|
+
return this.backing.removeOperatorPresence(repo, id, signal)
|
|
474
|
+
}
|
|
475
|
+
listOperatorPresence(repo: string): Promise<OperatorPresence[]> {
|
|
476
|
+
return this.backing.listOperatorPresence(repo)
|
|
477
|
+
}
|
|
464
478
|
ensureRepo(repo: string): Promise<RepositoryRecord> {
|
|
465
479
|
return this.backing.ensureRepo(repo)
|
|
466
480
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { BUILD_OWNED_CONFIG_PATHS, composeBuildConfig } from '../config/live'
|
|
3
|
+
import type { PipelineSource } from '../config/pipeline-source'
|
|
4
|
+
import type { Config } from '../config/schema'
|
|
5
|
+
import { KERNEL } from '../events/envelope'
|
|
6
|
+
import type { BuildState } from '../kernel/reducer'
|
|
7
|
+
import type { Exec } from '../ports/workspace/git-worktree'
|
|
8
|
+
import type { BuildScopedStore } from '../store/types'
|
|
9
|
+
import { effectiveBuildConfigContent, parseEffectiveBuildConfig } from './build-execution-state'
|
|
10
|
+
|
|
11
|
+
export type VerifyPipelineReader = () => Promise<PipelineSource & { head: string }>
|
|
12
|
+
export function buildConfigIdentity(config: Config): string {
|
|
13
|
+
return createHash('sha256')
|
|
14
|
+
.update(JSON.stringify(BUILD_OWNED_CONFIG_PATHS.map((path) => config[path])))
|
|
15
|
+
.digest('hex')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A capture owns its immutable artifact revision; latest-artifact races cannot retarget it. */
|
|
19
|
+
export async function capturedBuildConfig(
|
|
20
|
+
store: Pick<BuildScopedStore, 'getArtifact'>,
|
|
21
|
+
slug: string,
|
|
22
|
+
state: BuildState,
|
|
23
|
+
deployment: Config,
|
|
24
|
+
): Promise<Config> {
|
|
25
|
+
const pin = state.verify.configPin
|
|
26
|
+
if (!pin) return deployment
|
|
27
|
+
const artifact = await store.getArtifact(slug, pin.artifact.kind, pin.artifact.rev)
|
|
28
|
+
if (!artifact)
|
|
29
|
+
throw new Error(`missing captured verify config ${pin.artifact.kind}@${pin.artifact.rev}`)
|
|
30
|
+
return composeBuildConfig(parseEffectiveBuildConfig(artifact), deployment)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Called only after a whole stage settles and workspace mutation completes. */
|
|
34
|
+
export async function refreshVerifyCycle(input: {
|
|
35
|
+
store: BuildScopedStore
|
|
36
|
+
slug: string
|
|
37
|
+
state: BuildState
|
|
38
|
+
deployment: Config
|
|
39
|
+
read: VerifyPipelineReader
|
|
40
|
+
exec: Exec
|
|
41
|
+
workspacePath: string
|
|
42
|
+
/** A waiting leaf runs no further verifier; clean replay may retain its receipts. */
|
|
43
|
+
retainCompletedVerification?: boolean
|
|
44
|
+
}): Promise<boolean> {
|
|
45
|
+
const { store, slug, state, deployment } = input
|
|
46
|
+
const observed = await input.read()
|
|
47
|
+
const identity = buildConfigIdentity(observed.config)
|
|
48
|
+
const pin = state.verify.configPin
|
|
49
|
+
if (pin && pin.cycle === state.verify.cycleSince) {
|
|
50
|
+
// Ancestry gates execution, not historical evidence. A clean waiting-leaf
|
|
51
|
+
// replay replaces the canonical commit without changing the verified work.
|
|
52
|
+
// Content changes still supersede, and a future cycle captures before work.
|
|
53
|
+
if (input.retainCompletedVerification && identity === pin.identity) return false
|
|
54
|
+
let ancestral = true
|
|
55
|
+
if (pin.source.commit) {
|
|
56
|
+
const result = await input.exec(
|
|
57
|
+
['git', 'merge-base', '--is-ancestor', pin.source.commit, observed.head],
|
|
58
|
+
{ cwd: input.workspacePath },
|
|
59
|
+
)
|
|
60
|
+
if (result.exitCode !== 0 && result.exitCode !== 1)
|
|
61
|
+
throw new Error(`cannot establish verify pin ancestry: ${result.stderr}`)
|
|
62
|
+
ancestral = result.exitCode === 0
|
|
63
|
+
}
|
|
64
|
+
if (identity === pin.identity && ancestral) return false
|
|
65
|
+
await store.appendIfCurrent(slug, state.lastSeq, {
|
|
66
|
+
actor: KERNEL,
|
|
67
|
+
type: 'verify.config-superseded',
|
|
68
|
+
payload: { captureSeq: pin.seq, head: observed.head, identity },
|
|
69
|
+
})
|
|
70
|
+
return true
|
|
71
|
+
}
|
|
72
|
+
const config = composeBuildConfig(observed.config, deployment)
|
|
73
|
+
const artifact = await store.putArtifact(slug, {
|
|
74
|
+
kind: 'verify-cycle-config',
|
|
75
|
+
content: effectiveBuildConfigContent(config),
|
|
76
|
+
metadata: { pipelineSource: observed.meta, cycle: state.verify.cycleSince },
|
|
77
|
+
})
|
|
78
|
+
// Publishing an artifact is not a cycle transition. Only the capture fact
|
|
79
|
+
// makes these bytes authoritative; keep the mutable launch/reload artifact
|
|
80
|
+
// untouched so a crash before this append cannot expose an uncommitted pin.
|
|
81
|
+
await store.appendIfCurrent(slug, state.lastSeq, {
|
|
82
|
+
actor: KERNEL,
|
|
83
|
+
type: 'verify.config-captured',
|
|
84
|
+
payload: {
|
|
85
|
+
cycle: state.lastSeq + 1,
|
|
86
|
+
artifact: { kind: artifact.kind, rev: artifact.revision },
|
|
87
|
+
head: observed.head,
|
|
88
|
+
identity,
|
|
89
|
+
source:
|
|
90
|
+
observed.meta.ref === 'worktree-dirty'
|
|
91
|
+
? { ref: 'worktree-dirty' }
|
|
92
|
+
: { ref: 'branch-head', commit: observed.head },
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** Public, write-only project-secret protocol. Plaintext resolution is server-internal. */
|
|
2
|
+
export const PROJECT_SECRETS_VERSION = 1
|
|
3
|
+
export class ProjectSecretError extends Error {
|
|
4
|
+
constructor(
|
|
5
|
+
readonly code: 'invalid-secret' | 'key-unavailable' | 'secret-unavailable' | 'stale-secrets',
|
|
6
|
+
) {
|
|
7
|
+
super(`Project secrets: ${code}`)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface ProjectSecretMetadata {
|
|
11
|
+
name: string
|
|
12
|
+
kind: string
|
|
13
|
+
owner: string
|
|
14
|
+
setAt: string
|
|
15
|
+
fingerprint: string
|
|
16
|
+
status: 'ready' | 'refreshing' | 'failed'
|
|
17
|
+
failureCode: string | null
|
|
18
|
+
lastSuppliedAt: string | null
|
|
19
|
+
warnings?: Array<'refresh-window-too-short'>
|
|
20
|
+
}
|
|
21
|
+
export interface SecretSetRequest {
|
|
22
|
+
version: 1
|
|
23
|
+
repo: string
|
|
24
|
+
name: string
|
|
25
|
+
value: string
|
|
26
|
+
}
|
|
27
|
+
export interface SecretRemoveRequest {
|
|
28
|
+
version: 1
|
|
29
|
+
repo: string
|
|
30
|
+
name: string
|
|
31
|
+
}
|
|
32
|
+
export interface SecretListResponse {
|
|
33
|
+
version: 1
|
|
34
|
+
secrets: ProjectSecretMetadata[]
|
|
35
|
+
}
|
|
36
|
+
export { SECRET_NAME_EXPLANATION } from './secret-name'
|
|
37
|
+
import { validateSecretName as checkSecretName } from './secret-name'
|
|
38
|
+
export function validateSecretName(name: unknown): asserts name is string {
|
|
39
|
+
try {
|
|
40
|
+
checkSecretName(name)
|
|
41
|
+
} catch {
|
|
42
|
+
throw new ProjectSecretError('invalid-secret')
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function validateSecretValue(value: unknown): asserts value is string {
|
|
46
|
+
if (
|
|
47
|
+
typeof value !== 'string' ||
|
|
48
|
+
value.length === 0 ||
|
|
49
|
+
Buffer.byteLength(value) > 65536 ||
|
|
50
|
+
value.includes('\0')
|
|
51
|
+
)
|
|
52
|
+
throw new ProjectSecretError('invalid-secret')
|
|
53
|
+
}
|
|
54
|
+
/** Decode an allowlisted DTO, never echo arbitrary server fields. */
|
|
55
|
+
export function decodeSecretMetadata(raw: unknown): ProjectSecretMetadata {
|
|
56
|
+
const r = raw as ProjectSecretMetadata
|
|
57
|
+
if (
|
|
58
|
+
!r ||
|
|
59
|
+
typeof r !== 'object' ||
|
|
60
|
+
typeof r.name !== 'string' ||
|
|
61
|
+
typeof r.kind !== 'string' ||
|
|
62
|
+
typeof r.owner !== 'string' ||
|
|
63
|
+
Object.keys(r).length !== (r.warnings === undefined ? 8 : 9) ||
|
|
64
|
+
Object.keys(r).some(
|
|
65
|
+
(key) =>
|
|
66
|
+
![
|
|
67
|
+
'name',
|
|
68
|
+
'kind',
|
|
69
|
+
'owner',
|
|
70
|
+
'setAt',
|
|
71
|
+
'fingerprint',
|
|
72
|
+
'status',
|
|
73
|
+
'failureCode',
|
|
74
|
+
'lastSuppliedAt',
|
|
75
|
+
'warnings',
|
|
76
|
+
].includes(key),
|
|
77
|
+
) ||
|
|
78
|
+
(r.warnings !== undefined &&
|
|
79
|
+
(!Array.isArray(r.warnings) || r.warnings.some((v) => v !== 'refresh-window-too-short'))) ||
|
|
80
|
+
typeof r.setAt !== 'string' ||
|
|
81
|
+
typeof r.fingerprint !== 'string' ||
|
|
82
|
+
!(r.lastSuppliedAt === null || typeof r.lastSuppliedAt === 'string') ||
|
|
83
|
+
!Number.isFinite(Date.parse(r.setAt)) ||
|
|
84
|
+
!/^[a-f0-9]{16}$/.test(r.fingerprint) ||
|
|
85
|
+
!['ready', 'refreshing', 'failed'].includes(r.status) ||
|
|
86
|
+
!(r.failureCode === null || ['refresh-failed', 'refresh-expired'].includes(r.failureCode)) ||
|
|
87
|
+
!(r.lastSuppliedAt === null || Number.isFinite(Date.parse(r.lastSuppliedAt)))
|
|
88
|
+
)
|
|
89
|
+
throw new ProjectSecretError('secret-unavailable')
|
|
90
|
+
validateSecretName(r.name)
|
|
91
|
+
return {
|
|
92
|
+
name: r.name,
|
|
93
|
+
kind: r.kind,
|
|
94
|
+
owner: r.owner,
|
|
95
|
+
setAt: r.setAt,
|
|
96
|
+
fingerprint: r.fingerprint,
|
|
97
|
+
status: r.status,
|
|
98
|
+
failureCode: r.failureCode,
|
|
99
|
+
lastSuppliedAt: r.lastSuppliedAt,
|
|
100
|
+
...(r.warnings === undefined ? {} : { warnings: [...r.warnings] }),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { chatgptStateSchema, credentialValues, type ChatGPTState } from './accounts/chatgpt-state'
|
|
105
|
+
export { refreshChatGPT } from './accounts/chatgpt-oauth'
|