@defrex/autobuild 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -13
- package/SPEC.md +249 -15
- package/bin/ab-dispatch-generation.ts +11 -2
- package/docs/accounts.md +130 -0
- package/docs/agent-runtimes.md +4 -4
- package/docs/answering-blocked-builds.md +4 -1
- package/docs/architecture.md +224 -12
- package/docs/build-store.md +3 -41
- package/docs/builds.md +2 -0
- package/docs/cli.md +14 -0
- package/docs/configuration-overview.md +117 -0
- package/docs/configuration.md +266 -141
- package/docs/dispatcher-hosting.md +18 -33
- package/docs/intake.md +2 -0
- package/docs/integration-tree.md +16 -5
- package/docs/merge-policy.md +1 -3
- package/docs/operating.md +1 -2
- package/docs/operator-api.md +144 -53
- package/docs/operator-surfaces.md +32 -20
- package/docs/overview.md +1 -1
- package/docs/plugin-authoring.md +27 -1
- package/docs/remote-store-protocol.md +259 -91
- package/docs/remote-ticket-protocol.md +29 -49
- package/docs/restacking.md +45 -0
- package/docs/seams.md +8 -8
- package/docs/setup.md +34 -129
- package/docs/spec-standard.md +4 -2
- package/docs/ticket-dependencies.md +8 -0
- package/docs/ticket-sources.md +18 -0
- package/docs/troubleshooting.md +7 -11
- package/docs/upgrading.md +1 -1
- package/docs/workspaces.md +4 -4
- package/package.json +14 -5
- 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.ts +3 -1
- package/packages/core/src/cli/connect.ts +3 -3
- package/packages/core/src/cli/dispatch-frontend.ts +1 -0
- 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-repository-feed.ts +107 -26
- package/packages/core/src/cli/dispatch.ts +135 -27
- package/packages/core/src/cli/dispatcher-liveness.ts +6 -1
- package/packages/core/src/cli/forge-clear.ts +30 -0
- package/packages/core/src/cli/help.ts +17 -0
- 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 +72 -0
- package/packages/core/src/cli/publication-settlement.ts +4 -1
- package/packages/core/src/cli/secrets.ts +173 -0
- package/packages/core/src/cli/store-opening.ts +11 -1
- package/packages/core/src/cli/upgrade-agent.ts +9 -1
- package/packages/core/src/cli/watch.ts +12 -14
- package/packages/core/src/config/accounts.ts +101 -0
- package/packages/core/src/config/live.ts +14 -1
- package/packages/core/src/config/roles.ts +54 -3
- package/packages/core/src/config/schema.ts +60 -0
- package/packages/core/src/events/catalog.ts +1 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/forge-degradation-policy.ts +11 -0
- package/packages/core/src/events/payloads.ts +13 -0
- package/packages/core/src/events/policy.ts +9 -0
- package/packages/core/src/events/repository.ts +75 -2
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +278 -0
- package/packages/core/src/kernel/change-presence.ts +74 -8
- package/packages/core/src/kernel/engine.ts +8 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +14 -0
- package/packages/core/src/kernel/node-polling.ts +40 -7
- package/packages/core/src/kernel/node-restack-demand.ts +74 -0
- package/packages/core/src/kernel/node-restack-state.ts +5 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +33 -1
- package/packages/core/src/kernel/read-facts.ts +6 -0
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer.ts +4 -1
- package/packages/core/src/kernel/ticket-preparation.ts +66 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/control.ts +20 -0
- package/packages/core/src/operator/index.ts +4 -0
- package/packages/core/src/operator/protocol.ts +6 -0
- package/packages/core/src/operator/registry.ts +42 -1
- package/packages/core/src/operator/tickets.ts +25 -4
- package/packages/core/src/plugins/manifest.ts +2 -1
- package/packages/core/src/ports/runner/account-env.ts +139 -0
- package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
- package/packages/core/src/ports/runner/claude.ts +70 -42
- 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 +6 -1
- 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/provider-capabilities.ts +1 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +125 -35
- package/packages/core/src/processes/build-runner.ts +32 -1
- package/packages/core/src/processes/dispatcher.ts +493 -121
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- 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/harvest.ts +11 -16
- package/packages/core/src/processes/repo-view.ts +3 -0
- package/packages/core/src/project-secrets.ts +105 -0
- package/packages/core/src/secret-name.ts +41 -0
- package/packages/core/src/store/account-redaction.ts +156 -0
- package/packages/core/src/store/artifact-meta.ts +7 -0
- package/packages/core/src/store/contract.ts +60 -1
- package/packages/core/src/store/memory.ts +4 -0
- package/packages/core/src/store/reducer-value-shapes.json +7389 -6647
- package/packages/core/src/store/reducer-value-validation.ts +106 -6
- package/packages/core/src/store/remote/client.ts +85 -50
- package/packages/core/src/store/remote/compatibility.ts +57 -0
- package/packages/core/src/store/remote/index.ts +6 -0
- package/packages/core/src/store/remote/protocol.ts +8 -1
- package/packages/core/src/store/remote/released-reducer-values/1.2.0.json +8129 -0
- package/packages/core/src/store/remote/version.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +4 -2
- package/packages/core/src/store/snapshots.ts +16 -3
- package/packages/core/src/store/types.ts +2 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +266 -5
- package/packages/core/src/testing/index.ts +2 -1
- package/packages/core/src/testing/reduced-read-budget.ts +560 -5
- package/skills/guide/SKILL.md +164 -37
- package/skills/guide/references/accounts.md +130 -0
- package/skills/guide/references/integration-tree.md +16 -5
- package/skills/guide/references/merge-policy.md +1 -3
- package/skills/guide/references/operator-api.md +144 -53
- package/skills/guide/references/plugin-authoring.md +27 -1
- package/skills/guide/references/remote-store-protocol.md +259 -91
- package/skills/guide/references/remote-ticket-protocol.md +29 -49
- package/skills/guide/references/restacking.md +45 -0
- package/skills/guide/references/setup.md +34 -129
- package/skills/guide/references/spec-standard.md +4 -2
- package/skills/guide/references/ticket-dependencies.md +8 -0
- package/skills/harvest/SKILL.md +3 -1
- package/skills/harvest-review/SKILL.md +3 -1
- package/skills/operate/SKILL.md +26 -11
- package/skills/reconcile/SKILL.md +6 -0
- package/skills/spec/SKILL.md +1 -1
- package/skills/tickets/SKILL.md +10 -5
- package/templates/hosted-service/package.json +2 -2
- package/docs/hosted-dispatcher-cutover-validation.md +0 -178
- package/docs/hosted-dispatcher.md +0 -278
- package/docs/hosted-service.md +0 -304
- package/docs/mcp.md +0 -150
|
@@ -52,6 +52,7 @@ export const executionProgress = {
|
|
|
52
52
|
'node.inventory': 'bookkeeping',
|
|
53
53
|
'node.restack-requested': 'bookkeeping',
|
|
54
54
|
'node.restack-satisfied': 'progress',
|
|
55
|
+
'node.restack-availability-observed': 'bookkeeping',
|
|
55
56
|
'node.parent-distance': 'bookkeeping',
|
|
56
57
|
'node.parent-requested': 'bookkeeping',
|
|
57
58
|
'node.parent-accepted': 'progress',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomIds, type IdSource } from '../ids'
|
|
1
2
|
/**
|
|
2
3
|
* Settlement of foreign build executions from durable facts plus provider
|
|
3
4
|
* liveness (AUT-301). Today's completion handling hangs off the in-memory
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
* is treated as `running`. Supervision decisions reap or settle only on
|
|
12
13
|
* provider proof, never on an unknown.
|
|
13
14
|
*/
|
|
14
|
-
import { DISPATCHER } from '../events/envelope'
|
|
15
|
+
import { DISPATCHER, KERNEL } from '../events/envelope'
|
|
15
16
|
import type { AbEvent, EventWrite } from '../events/catalog'
|
|
16
17
|
import type {
|
|
17
18
|
BuildExecution,
|
|
@@ -121,11 +122,12 @@ function observationIdentity(open: {
|
|
|
121
122
|
* a recorded completion was written and publication was settled; `lost` means
|
|
122
123
|
* the provider proved the execution gone without an exit code (publication is
|
|
123
124
|
* deliberately left to the existing abandonment flow); `running` means the
|
|
124
|
-
* guest is alive or unknowable
|
|
125
|
+
* guest is alive or unknowable. Independent host attention may still be recorded. */
|
|
125
126
|
export type ExecutionSettlement = 'running' | 'settled' | 'lost'
|
|
126
127
|
|
|
127
128
|
export interface ExecutionSettlementDeps {
|
|
128
129
|
store: BuildStore
|
|
130
|
+
ids?: IdSource
|
|
129
131
|
/** The observing provider's executor. Settlement requires the `observe`
|
|
130
132
|
* capability; without it the caller supervises as before. */
|
|
131
133
|
execution: BuildExecution
|
|
@@ -163,7 +165,7 @@ export function settleExecution(
|
|
|
163
165
|
/** `settleExecution` over an already-derived open execution, for callers that
|
|
164
166
|
* hold the projection (a reducer snapshot advanced to the log tail) and so
|
|
165
167
|
* never need the event array. A `running` result or an observation error
|
|
166
|
-
* touches no event rows. */
|
|
168
|
+
* touches no event rows unless the provider also reports actionable attention. */
|
|
167
169
|
export async function settleOpenExecution(
|
|
168
170
|
deps: ExecutionSettlementDeps,
|
|
169
171
|
slug: string,
|
|
@@ -177,6 +179,22 @@ export async function settleOpenExecution(
|
|
|
177
179
|
} catch {
|
|
178
180
|
return 'running'
|
|
179
181
|
}
|
|
182
|
+
if (observation.attention) {
|
|
183
|
+
const state = (await readBuildFacts(deps.store, slug)).value.state
|
|
184
|
+
if (!state.openEscalations.some((entry) => entry.question === observation.attention))
|
|
185
|
+
await deps.store.append(slug, {
|
|
186
|
+
actor: KERNEL,
|
|
187
|
+
type: 'escalation.raised',
|
|
188
|
+
payload: {
|
|
189
|
+
id: (deps.ids ?? randomIds())('esc'),
|
|
190
|
+
phase: state.phase ?? 'setup',
|
|
191
|
+
...(state.round > 0 ? { round: state.round } : {}),
|
|
192
|
+
source: 'policy',
|
|
193
|
+
policyCause: 'non-retryable-phase-failure',
|
|
194
|
+
question: observation.attention,
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
}
|
|
180
198
|
if (observation.state === 'running') return 'running'
|
|
181
199
|
|
|
182
200
|
const request = (await readBuildFacts(deps.store, slug)).value.state.drainingExecutions?.[
|
|
@@ -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 } : {}),
|
|
@@ -229,16 +229,12 @@ export function collectUnclaimedObservations(input: {
|
|
|
229
229
|
return { observations, merges, state }
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* runner's packet scan — the only source of observation payloads — and its
|
|
239
|
-
* gate re-confirmation; the dispatcher's harvest-launch gate itself evaluates
|
|
240
|
-
* from digests, AUT-521). Occurrences are keyed `{build, seq}`; payload ids
|
|
241
|
-
* are not assumed globally unique. */
|
|
232
|
+
/** Count unclaimed occurrences from already reduced build digests and harvest
|
|
233
|
+
* facts, without backing reads. The operator query and interactive dispatcher
|
|
234
|
+
* tick consume this directly; the tick reuses its shared refreshed view.
|
|
235
|
+
* The Store-only terminal frontend owns a separate refresh.
|
|
236
|
+
* Occurrences are keyed by {build, seq}, never by payload id.
|
|
237
|
+
* The harvest runner's scan still supplies full observation payloads. */
|
|
242
238
|
export function unclaimedObservationCount(input: {
|
|
243
239
|
digests: Map<string, BuildDigest>
|
|
244
240
|
harvestEvents: RepositoryEvent[] | HarvestState
|
|
@@ -275,12 +271,11 @@ export async function readRepoEventsIfRecorded(
|
|
|
275
271
|
return (await store.getRepo(repo)) === null ? [] : store.getRepoStateEvents(repo)
|
|
276
272
|
}
|
|
277
273
|
|
|
278
|
-
/**
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* shared helper's, above. */
|
|
274
|
+
/** Store-reading count helper: one repository-record probe, one canonical
|
|
275
|
+
* repository-facts request when recorded, and one repository-scoped digest
|
|
276
|
+
* request. No journal replay or writes. An absent record supplies empty harvest
|
|
277
|
+
* facts. Dispatcher ticks use unclaimedObservationCount with their shared view
|
|
278
|
+
* instead, avoiding these additional acquisitions. */
|
|
284
279
|
export async function sampleUnclaimedObservationCount(
|
|
285
280
|
store: BuildStore,
|
|
286
281
|
repo: string,
|
|
@@ -495,6 +495,9 @@ export class RepoViewStore implements BuildStore {
|
|
|
495
495
|
getArtifact(slug: string, kind: string, rev?: number): Promise<Artifact | null> {
|
|
496
496
|
return this.backing.getArtifact(slug, kind, rev)
|
|
497
497
|
}
|
|
498
|
+
get getLatestArtifactMeta(): BuildStore['getLatestArtifactMeta'] {
|
|
499
|
+
return this.backing.getLatestArtifactMeta?.bind(this.backing)
|
|
500
|
+
}
|
|
498
501
|
listArtifacts(slug: string, kind?: string): Promise<ArtifactMeta[]> {
|
|
499
502
|
return this.backing.listArtifacts(slug, kind)
|
|
500
503
|
}
|
|
@@ -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'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const SECRET_NAME_EXPLANATION =
|
|
2
|
+
'Use 1–128 uppercase letters, digits or underscores, starting with a letter or underscore. Reserved process and infrastructure names and prefixes (including AB_) are not allowed.'
|
|
3
|
+
const reserved =
|
|
4
|
+
/^(?:AB_|XDG_|BASH_|ZSH_|PYTHON|PERL|RUBY|GEM_|JAVA_|JDK_|_JAVA_|DOCKER_|KUBE|CARGO_|RUSTC_|RUSTUP_|GITHUB_|GH_|VERCEL_|CRON_|DATABASE_|POSTGRES_|PG|AWS_|AZURE_|GOOGLE_|GCP_|S3_|BLOB_|R2_|UPSTASH_|REDIS_|NEON_|SUPABASE_|BETTER_AUTH_|NEXT_|NPM_|npm_|BUN_|NODE_|LD_|DYLD_|GIT_|SSH_|SSL_|CURL_|HTTP_|HTTPS_|ALL_PROXY|NO_PROXY)/i
|
|
5
|
+
const processNames = new Set([
|
|
6
|
+
'PATH',
|
|
7
|
+
'HOME',
|
|
8
|
+
'SHELL',
|
|
9
|
+
'SHELLOPTS',
|
|
10
|
+
'BASHOPTS',
|
|
11
|
+
'COMSPEC',
|
|
12
|
+
'PATHEXT',
|
|
13
|
+
'EDITOR',
|
|
14
|
+
'VISUAL',
|
|
15
|
+
'PAGER',
|
|
16
|
+
'MANPAGER',
|
|
17
|
+
'LESSOPEN',
|
|
18
|
+
'LESSCLOSE',
|
|
19
|
+
'INPUTRC',
|
|
20
|
+
'ENV',
|
|
21
|
+
'BASH_ENV',
|
|
22
|
+
'ZDOTDIR',
|
|
23
|
+
'TMPDIR',
|
|
24
|
+
'TMP',
|
|
25
|
+
'TEMP',
|
|
26
|
+
'USER',
|
|
27
|
+
'LOGNAME',
|
|
28
|
+
'PWD',
|
|
29
|
+
'IFS',
|
|
30
|
+
'CDPATH',
|
|
31
|
+
'NODE_EXTRA_CA_CERTS',
|
|
32
|
+
])
|
|
33
|
+
export function validateSecretName(name: unknown): asserts name is string {
|
|
34
|
+
if (
|
|
35
|
+
typeof name !== 'string' ||
|
|
36
|
+
!/^[A-Z_][A-Z0-9_]{0,127}$/.test(name) ||
|
|
37
|
+
reserved.test(name) ||
|
|
38
|
+
processNames.has(name)
|
|
39
|
+
)
|
|
40
|
+
throw new Error(SECRET_NAME_EXPLANATION)
|
|
41
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { sensitiveAccountValues } from '../accounts/sensitive'
|
|
2
|
+
import type { Accounts } from '../config/accounts'
|
|
3
|
+
import type { BuildStore } from './types'
|
|
4
|
+
import type { StreamPart } from './streams/types'
|
|
5
|
+
|
|
6
|
+
/** Values stay host-local. Previously observed values remain redacted after rotation. */
|
|
7
|
+
export class AccountRedactor {
|
|
8
|
+
private readonly observed = new Set<string>()
|
|
9
|
+
constructor(private readonly source: () => readonly (string | undefined)[]) {}
|
|
10
|
+
private secrets(): string[] {
|
|
11
|
+
for (const value of this.source()) if (value) this.observed.add(value)
|
|
12
|
+
return [
|
|
13
|
+
...new Set(
|
|
14
|
+
[...this.observed].flatMap((value) => [value, JSON.stringify(value).slice(1, -1)]),
|
|
15
|
+
),
|
|
16
|
+
].sort((a, b) => b.length - a.length)
|
|
17
|
+
}
|
|
18
|
+
text(value: string): string {
|
|
19
|
+
for (const secret of this.secrets()) value = value.split(secret).join('[REDACTED]')
|
|
20
|
+
return value
|
|
21
|
+
}
|
|
22
|
+
value<T>(value: T): T {
|
|
23
|
+
if (typeof value === 'string') return this.text(value) as T
|
|
24
|
+
if (value instanceof Uint8Array) {
|
|
25
|
+
const copy = new Uint8Array(value)
|
|
26
|
+
for (const secret of this.secrets()) {
|
|
27
|
+
const needle = new TextEncoder().encode(secret)
|
|
28
|
+
for (let i = 0; i <= copy.length - needle.length; i++) {
|
|
29
|
+
if (needle.every((byte, j) => copy[i + j] === byte)) {
|
|
30
|
+
copy.fill(42, i, i + needle.length)
|
|
31
|
+
i += needle.length - 1
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return copy as T
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(value)) return value.map((item) => this.value(item)) as T
|
|
38
|
+
if (value !== null && typeof value === 'object')
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
Object.entries(value).map(([key, item]) => [this.text(key), this.value(item)]),
|
|
41
|
+
) as T
|
|
42
|
+
return value
|
|
43
|
+
}
|
|
44
|
+
/** Retain only a suffix that could begin a secret. Never persist a prefix
|
|
45
|
+
* until the following delta disambiguates it, even across flush batches. */
|
|
46
|
+
stream(parts: StreamPart[], tails: Map<string, string>): StreamPart[] {
|
|
47
|
+
const result: StreamPart[] = []
|
|
48
|
+
for (const part of parts) {
|
|
49
|
+
const record = part as Record<string, unknown>
|
|
50
|
+
if (
|
|
51
|
+
(part.type === 'text-delta' || part.type === 'reasoning-delta') &&
|
|
52
|
+
typeof record.delta === 'string'
|
|
53
|
+
) {
|
|
54
|
+
const id = `${part.type}:${record.id}`
|
|
55
|
+
let text = (tails.get(id) ?? '') + record.delta
|
|
56
|
+
const secrets = this.secrets()
|
|
57
|
+
text = this.text(text)
|
|
58
|
+
let retained = 0
|
|
59
|
+
for (const secret of secrets)
|
|
60
|
+
for (let n = 1; n < secret.length && n <= text.length; n++)
|
|
61
|
+
if (text.endsWith(secret.slice(0, n))) retained = Math.max(retained, n)
|
|
62
|
+
tails.set(id, retained ? text.slice(-retained) : '')
|
|
63
|
+
result.push({ ...part, delta: retained ? text.slice(0, -retained) : text } as StreamPart)
|
|
64
|
+
} else {
|
|
65
|
+
if (part.type === 'text-end' || part.type === 'reasoning-end') {
|
|
66
|
+
const type = part.type === 'text-end' ? 'text-delta' : 'reasoning-delta'
|
|
67
|
+
const id = `${type}:${record.id}`
|
|
68
|
+
const tail = tails.get(id)
|
|
69
|
+
if (tail) result.push({ type, id: record.id, delta: tail } as StreamPart)
|
|
70
|
+
tails.delete(id)
|
|
71
|
+
}
|
|
72
|
+
result.push(this.value(part))
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function accountRedactor(
|
|
80
|
+
accounts: () => Accounts,
|
|
81
|
+
env:
|
|
82
|
+
| Readonly<Record<string, string | undefined>>
|
|
83
|
+
| (() => Readonly<Record<string, string | undefined>>),
|
|
84
|
+
): AccountRedactor {
|
|
85
|
+
return new AccountRedactor(() => {
|
|
86
|
+
const current = typeof env === 'function' ? env() : env
|
|
87
|
+
return [
|
|
88
|
+
...sensitiveAccountValues,
|
|
89
|
+
...Object.values(accounts()).map((account) => current[account.credentialEnv]),
|
|
90
|
+
]
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const WRITES = new Set([
|
|
95
|
+
'append',
|
|
96
|
+
'appendIfCurrent',
|
|
97
|
+
'appendWithArtifacts',
|
|
98
|
+
'appendWithArtifactsIfCurrent',
|
|
99
|
+
'putArtifact',
|
|
100
|
+
'appendRepo',
|
|
101
|
+
'appendRepoWithArtifacts',
|
|
102
|
+
'putRepoArtifact',
|
|
103
|
+
'appendSessionEvent',
|
|
104
|
+
'appendSessionEventIfCurrent',
|
|
105
|
+
'appendSessionWithArtifacts',
|
|
106
|
+
'putSessionArtifact',
|
|
107
|
+
'putTicketAsset',
|
|
108
|
+
'putReducerSnapshot',
|
|
109
|
+
'createSession',
|
|
110
|
+
])
|
|
111
|
+
|
|
112
|
+
/** Covers actual event/artifact write interfaces, including atomic callbacks.
|
|
113
|
+
* The underlying adapter still validates schemas and computes content hashes. */
|
|
114
|
+
export function redactAccountStore<T extends BuildStore>(store: T, redactor: AccountRedactor): T {
|
|
115
|
+
const streams = new Map<string, Map<string, string>>()
|
|
116
|
+
return new Proxy(store, {
|
|
117
|
+
get(target, property) {
|
|
118
|
+
const member = Reflect.get(target, property, target)
|
|
119
|
+
if (typeof member !== 'function') return member
|
|
120
|
+
if (property === 'scopeBuild' || property === 'scopeSession')
|
|
121
|
+
return (...args: unknown[]) => redactAccountStore(member.apply(target, args), redactor)
|
|
122
|
+
if (
|
|
123
|
+
!WRITES.has(String(property)) &&
|
|
124
|
+
property !== 'appendStreamParts' &&
|
|
125
|
+
property !== 'closeStream'
|
|
126
|
+
)
|
|
127
|
+
return member.bind(target)
|
|
128
|
+
return async (...args: unknown[]) => {
|
|
129
|
+
let committedTails: { id: string; tails: Map<string, string> } | undefined
|
|
130
|
+
if (property === 'appendStreamParts') {
|
|
131
|
+
const id = args[0] as string
|
|
132
|
+
const tails = new Map(streams.get(id) ?? [])
|
|
133
|
+
committedTails = { id, tails }
|
|
134
|
+
args[1] = redactor.stream(args[1] as StreamPart[], tails)
|
|
135
|
+
} else if (property === 'closeStream') streams.delete(args[0] as string)
|
|
136
|
+
else if (WRITES.has(String(property)))
|
|
137
|
+
args = args.map((arg) =>
|
|
138
|
+
typeof arg === 'function'
|
|
139
|
+
? (...values: unknown[]) => redactor.value(arg(...values))
|
|
140
|
+
: redactor.value(arg),
|
|
141
|
+
)
|
|
142
|
+
try {
|
|
143
|
+
const result = await member.apply(target, args)
|
|
144
|
+
if (committedTails) streams.set(committedTails.id, committedTails.tails)
|
|
145
|
+
return result
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (error instanceof Error) {
|
|
148
|
+
error.message = redactor.text(error.message)
|
|
149
|
+
throw error
|
|
150
|
+
}
|
|
151
|
+
throw new Error(redactor.text(String(error)))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** An optional metadata capability is unavailable; callers may use ordinary artifact reads. */
|
|
2
|
+
export class ArtifactMetaUnsupportedError extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super('latest artifact metadata is unsupported')
|
|
5
|
+
this.name = 'ArtifactMetaUnsupportedError'
|
|
6
|
+
}
|
|
7
|
+
}
|