@defrex/autobuild 1.1.0 → 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 +5 -13
- package/SPEC.md +140 -10
- package/bin/ab-dispatch-generation.ts +11 -2
- package/docs/accounts.md +119 -0
- package/docs/agent-runtimes.md +4 -4
- package/docs/architecture.md +107 -8
- package/docs/build-store.md +3 -41
- package/docs/cli.md +14 -0
- package/docs/configuration-overview.md +111 -0
- package/docs/configuration.md +260 -141
- package/docs/dispatcher-hosting.md +18 -33
- package/docs/intake.md +2 -0
- package/docs/merge-policy.md +1 -3
- package/docs/operating.md +1 -2
- package/docs/operator-api.md +100 -47
- package/docs/operator-surfaces.md +3 -20
- package/docs/overview.md +1 -1
- package/docs/plugin-authoring.md +21 -0
- package/docs/remote-store-protocol.md +198 -89
- package/docs/remote-ticket-protocol.md +29 -49
- package/docs/seams.md +8 -8
- package/docs/setup.md +34 -129
- 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-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 +71 -2
- package/packages/core/src/cli/help.ts +16 -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 +44 -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 +3 -1
- 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/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +3 -0
- package/packages/core/src/events/repository.ts +2 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +3 -0
- package/packages/core/src/kernel/reducer.ts +4 -1
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/protocol.ts +6 -0
- package/packages/core/src/operator/registry.ts +22 -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 +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 +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 +23 -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/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/contract.ts +3 -1
- package/packages/core/src/store/reducer-value-shapes.json +2889 -2781
- package/packages/core/src/store/remote/client.ts +42 -47
- package/packages/core/src/store/remote/compatibility.ts +18 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +122 -0
- package/packages/core/src/testing/index.ts +1 -0
- package/packages/core/src/testing/reduced-read-budget.ts +47 -0
- package/skills/guide/SKILL.md +120 -30
- package/skills/guide/references/accounts.md +119 -0
- package/skills/guide/references/merge-policy.md +1 -3
- package/skills/guide/references/operator-api.md +100 -47
- package/skills/guide/references/plugin-authoring.md +21 -0
- package/skills/guide/references/remote-store-protocol.md +198 -89
- package/skills/guide/references/remote-ticket-protocol.md +29 -49
- package/skills/guide/references/setup.md +34 -129
- package/skills/harvest/SKILL.md +3 -1
- package/skills/harvest-review/SKILL.md +3 -1
- package/skills/operate/SKILL.md +5 -6
- package/skills/spec/SKILL.md +1 -1
- package/skills/tickets/SKILL.md +3 -2
- 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
|
@@ -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 } : {}),
|
|
@@ -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
|
+
}
|
|
@@ -2514,7 +2514,9 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2514
2514
|
),
|
|
2515
2515
|
).toHaveLength(520)
|
|
2516
2516
|
})
|
|
2517
|
-
|
|
2517
|
+
// The full hosted HTTP/Postgres workload took 5.33s with unit/build/
|
|
2518
|
+
// integration overlapping on 4 vCPUs (2.77s focused). Keep all 520 scans.
|
|
2519
|
+
}, 15_000)
|
|
2518
2520
|
|
|
2519
2521
|
test('unknown repo rejects like getRepoEvents', async () => {
|
|
2520
2522
|
await withStore(factory, undefined, async (store) => {
|