@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 { selectAccount, type Accounts, type SelectedAccount } from '../../config/accounts'
|
|
1
2
|
/**
|
|
2
3
|
* Eager runtime/model/args role resolution (SPEC §9, §16.1). Primary
|
|
3
4
|
* fields and the ordered alternate list inherit independently from the
|
|
@@ -10,6 +11,7 @@ import { serves, type RuntimeRegistration, type RuntimeRegistry } from './runtim
|
|
|
10
11
|
|
|
11
12
|
/** A resolved runtime/model pair plus the adapter to run it (§9). */
|
|
12
13
|
export interface ResolvedRuntime {
|
|
14
|
+
account?: SelectedAccount
|
|
13
15
|
runner: AgentRunner
|
|
14
16
|
/** The registry key == the frozen `session.started.runner` value. */
|
|
15
17
|
runtime: string
|
|
@@ -30,6 +32,7 @@ export interface ResolvedRole extends ResolvedRuntime {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export interface RuntimeAxes {
|
|
35
|
+
account?: string
|
|
33
36
|
runtime?: string
|
|
34
37
|
model?: string
|
|
35
38
|
args?: readonly string[]
|
|
@@ -74,6 +77,7 @@ function mergeAxes(spec: RuntimeAxes, base: RuntimeAxes): RuntimeAxes {
|
|
|
74
77
|
return {
|
|
75
78
|
...(runtime !== undefined ? { runtime } : {}),
|
|
76
79
|
...(model !== undefined ? { model } : {}),
|
|
80
|
+
account: spec.account ?? base.account,
|
|
77
81
|
args: spec.args ?? base.args ?? [],
|
|
78
82
|
}
|
|
79
83
|
}
|
|
@@ -85,6 +89,7 @@ function resolveAxes(
|
|
|
85
89
|
registry: RuntimeRegistry,
|
|
86
90
|
label: string,
|
|
87
91
|
problems: string[],
|
|
92
|
+
accounts: Accounts,
|
|
88
93
|
): ResolvedRuntime | undefined {
|
|
89
94
|
const runtime = axes.runtime
|
|
90
95
|
if (runtime === undefined || runtime.trim().length === 0) {
|
|
@@ -105,8 +110,21 @@ function resolveAxes(
|
|
|
105
110
|
}
|
|
106
111
|
const reg = registry[runtime]!
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
let account: SelectedAccount | undefined
|
|
114
|
+
try {
|
|
115
|
+
account = selectAccount(accounts, runtime, axes.account, label)
|
|
116
|
+
} catch (error) {
|
|
117
|
+
problems.push((error as Error).message)
|
|
118
|
+
return undefined
|
|
119
|
+
}
|
|
120
|
+
const kimi = account?.descriptor.kind === 'kimi-code'
|
|
121
|
+
const model = axes.model ?? (kimi ? 'kimi-for-coding' : reg.defaultModel)
|
|
122
|
+
const modelValid = kimi
|
|
123
|
+
? model !== undefined &&
|
|
124
|
+
/^(kimi-for-coding(?:-highspeed)?|k3(?:-256k)?|k3\.1-pro(?:-highspeed)?)(?:\[1m\])?$/.test(
|
|
125
|
+
model,
|
|
126
|
+
)
|
|
127
|
+
: model === undefined || serves(reg, model)
|
|
110
128
|
if (!modelValid) {
|
|
111
129
|
problems.push(
|
|
112
130
|
`${label} resolves runtime "${runtime}" with model "${model}", but ` +
|
|
@@ -115,7 +133,14 @@ function resolveAxes(
|
|
|
115
133
|
}
|
|
116
134
|
|
|
117
135
|
const args = axes.args ?? []
|
|
118
|
-
const ownedArgs = new Set(
|
|
136
|
+
const ownedArgs = new Set([
|
|
137
|
+
...(reg.ownedArgs ?? []),
|
|
138
|
+
...(account?.descriptor.kind === 'chatgpt-subscription'
|
|
139
|
+
? ['-c', '--config', '--profile', '-p', '--enable', '--disable']
|
|
140
|
+
: account
|
|
141
|
+
? ['--settings', '--setting-sources', '--bare']
|
|
142
|
+
: []),
|
|
143
|
+
])
|
|
119
144
|
for (const arg of args) {
|
|
120
145
|
if (arg === reg.promptBoundary) {
|
|
121
146
|
problems.push(
|
|
@@ -146,6 +171,7 @@ function resolveAxes(
|
|
|
146
171
|
if (!modelValid) return undefined
|
|
147
172
|
|
|
148
173
|
return {
|
|
174
|
+
...(account === undefined ? {} : { account }),
|
|
149
175
|
runner: reg.runner,
|
|
150
176
|
runtime,
|
|
151
177
|
...(model !== undefined ? { model } : {}),
|
|
@@ -161,9 +187,10 @@ function resolveRole(
|
|
|
161
187
|
registry: RuntimeRegistry,
|
|
162
188
|
label: string,
|
|
163
189
|
problems: string[],
|
|
190
|
+
accounts: Accounts,
|
|
164
191
|
): ResolvedRole | undefined {
|
|
165
192
|
const primaryAxes = mergeAxes(spec, defaultSpec)
|
|
166
|
-
const primary = resolveAxes(primaryAxes, registry, label, problems)
|
|
193
|
+
const primary = resolveAxes(primaryAxes, registry, label, problems, accounts)
|
|
167
194
|
const alternateSpecs = spec.alternates ?? defaultSpec.alternates ?? []
|
|
168
195
|
const alternates: ResolvedRuntime[] = []
|
|
169
196
|
alternateSpecs.forEach((alternate, index) => {
|
|
@@ -172,6 +199,7 @@ function resolveRole(
|
|
|
172
199
|
registry,
|
|
173
200
|
`${label}.alternates[${index}]`,
|
|
174
201
|
problems,
|
|
202
|
+
accounts,
|
|
175
203
|
)
|
|
176
204
|
if (resolved !== undefined) alternates.push(resolved)
|
|
177
205
|
})
|
|
@@ -192,6 +220,7 @@ export function createRuntimeResolver(
|
|
|
192
220
|
registry: RuntimeRegistry,
|
|
193
221
|
roles: Record<string, RuntimeSpec>,
|
|
194
222
|
policySessionBudgetSeconds = 3600,
|
|
223
|
+
accounts: Accounts = {},
|
|
195
224
|
): RuntimeResolver {
|
|
196
225
|
const problems: string[] = []
|
|
197
226
|
const defaultSpec = roles.default ?? {}
|
|
@@ -202,6 +231,7 @@ export function createRuntimeResolver(
|
|
|
202
231
|
registry,
|
|
203
232
|
'[roles.default]',
|
|
204
233
|
problems,
|
|
234
|
+
accounts,
|
|
205
235
|
)
|
|
206
236
|
|
|
207
237
|
const resolvedRoles: Record<string, ResolvedRole> = Object.create(null)
|
|
@@ -214,6 +244,7 @@ export function createRuntimeResolver(
|
|
|
214
244
|
registry,
|
|
215
245
|
`[roles.${role}]`,
|
|
216
246
|
problems,
|
|
247
|
+
accounts,
|
|
217
248
|
)
|
|
218
249
|
if (resolved !== undefined) resolvedRoles[role] = resolved
|
|
219
250
|
}
|
|
@@ -7,8 +7,27 @@ import type {
|
|
|
7
7
|
TicketDraft,
|
|
8
8
|
TicketSource,
|
|
9
9
|
TicketUpdate,
|
|
10
|
+
TicketCriteria,
|
|
11
|
+
TicketPage,
|
|
10
12
|
} from '../types'
|
|
11
13
|
|
|
14
|
+
/** Shared assertion also used by negative controls for declared capabilities. */
|
|
15
|
+
export async function assertTicketPage(
|
|
16
|
+
source: TicketSource,
|
|
17
|
+
criteria: TicketCriteria,
|
|
18
|
+
page: TicketPage,
|
|
19
|
+
full: Awaited<ReturnType<TicketSource['listReady']>>,
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
const actual = await source.listPage!(criteria, page)
|
|
22
|
+
const ordered = page.order === 'newest' ? [...full.tickets].reverse() : full.tickets
|
|
23
|
+
const offset = page.offset ?? 0
|
|
24
|
+
expect(actual).toEqual({
|
|
25
|
+
tickets: ordered.slice(offset, offset + page.limit),
|
|
26
|
+
diagnostics: full.diagnostics,
|
|
27
|
+
total: full.tickets.length,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
/** Lifecycle names supplied by an adapter's contract fixture. */
|
|
13
32
|
export interface TicketSourceContractStates {
|
|
14
33
|
/** A state from which the fixture's source can claim a ticket. */
|
|
@@ -117,6 +136,45 @@ export function describeTicketSourceContract(
|
|
|
117
136
|
factory: TicketSourceContractFactory,
|
|
118
137
|
): void {
|
|
119
138
|
describe(`TicketSource contract: ${name}`, () => {
|
|
139
|
+
test('native pages equal exhaustive listing windows when declared', async () => {
|
|
140
|
+
await withTicketSource(factory, async (harness) => {
|
|
141
|
+
const source = harness.source
|
|
142
|
+
if (!source.listPage) return
|
|
143
|
+
const first = await freshLabel(harness, 'page')
|
|
144
|
+
const second = await freshLabel(harness, 'page-intersection')
|
|
145
|
+
for (let i = 0; i < 5; i++)
|
|
146
|
+
await createTracked(
|
|
147
|
+
harness,
|
|
148
|
+
{
|
|
149
|
+
title: contractTicketTitle('page'),
|
|
150
|
+
body: CONTRACT_TICKET_BODY,
|
|
151
|
+
labels: i % 2 ? [first] : [first, second],
|
|
152
|
+
},
|
|
153
|
+
{ state: i === 4 ? harness.states.completed : harness.states.ready },
|
|
154
|
+
)
|
|
155
|
+
for (const criteria of [
|
|
156
|
+
{ labels: [first] },
|
|
157
|
+
{ state: harness.states.ready, labels: [first] },
|
|
158
|
+
{ state: harness.states.completed, labels: [first] },
|
|
159
|
+
{ labels: [first, second] },
|
|
160
|
+
{ labels: [await freshLabel(harness, 'missing')] },
|
|
161
|
+
{ state: harness.states.ready, labels: [] },
|
|
162
|
+
]) {
|
|
163
|
+
const full = await source.listReady(criteria)
|
|
164
|
+
for (const order of [undefined, 'oldest', 'newest'] as const)
|
|
165
|
+
for (const window of [
|
|
166
|
+
{ limit: 2 },
|
|
167
|
+
{ limit: 2, offset: 1 },
|
|
168
|
+
{ limit: 2, offset: full.tickets.length + 1 },
|
|
169
|
+
{ limit: 0 },
|
|
170
|
+
]) {
|
|
171
|
+
const page = { ...window, ...(order ? { order } : {}) }
|
|
172
|
+
await assertTicketPage(source, criteria, page, full)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
|
120
178
|
test('optional integration tree metadata preserves graph invariants', async () => {
|
|
121
179
|
await withTicketSource(factory, async (harness) => {
|
|
122
180
|
const source = harness.source
|
|
@@ -79,7 +79,7 @@ export function compatibleTicketSource(source: TicketSource): TicketSource {
|
|
|
79
79
|
const ticket = await target.get(id)
|
|
80
80
|
return ticket ? normalizeTicket(ticket, !!target.integrationTree) : null
|
|
81
81
|
}
|
|
82
|
-
if (property === 'listReady' || property === 'listAll')
|
|
82
|
+
if (property === 'listReady' || property === 'listAll' || property === 'listPage')
|
|
83
83
|
return async (...args: unknown[]) => {
|
|
84
84
|
const listing = await value.apply(target, args)
|
|
85
85
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SelectedAccount } from '../config/accounts'
|
|
1
2
|
export type { ForgeReadinessCheck, ForgeReadinessInput } from './forge/readiness'
|
|
2
3
|
import type { ForgeReadinessCheck, ForgeReadinessInput } from './forge/readiness'
|
|
3
4
|
import type { BuildStore } from '../store/types'
|
|
@@ -90,6 +91,25 @@ export interface Ticket {
|
|
|
90
91
|
blockedBy?: string[]
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
export interface TicketCriteria {
|
|
95
|
+
labels?: string[]
|
|
96
|
+
state?: string
|
|
97
|
+
/** `me` (the API key's owner) or a user's email; only sources that can honour it
|
|
98
|
+
* accept it — others reject `[tickets].readyAssignee` at config parse. */
|
|
99
|
+
assignee?: string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface TicketPage {
|
|
103
|
+
limit: number
|
|
104
|
+
offset?: number
|
|
105
|
+
order?: 'oldest' | 'newest'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface TicketPageListing extends TicketListing {
|
|
109
|
+
/** Matching count before ordering and slicing. No operator-specific limit cap. */
|
|
110
|
+
total: number
|
|
111
|
+
}
|
|
112
|
+
|
|
93
113
|
/** A partial source scan. Diagnostics name source records that were excluded
|
|
94
114
|
* from eligibility; infrastructure failures and source-wide invariants still
|
|
95
115
|
* reject `listReady` rather than appearing here. */
|
|
@@ -214,13 +234,13 @@ export interface TicketSource {
|
|
|
214
234
|
/** Ready tickets matching the dispatch criteria (label/state — §3.3), plus
|
|
215
235
|
* actionable diagnostics for individual source records excluded as invalid.
|
|
216
236
|
* Fatal source failures and invariants still reject the call. */
|
|
217
|
-
listReady(criteria:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
237
|
+
listReady(criteria: TicketCriteria): Promise<TicketListing>
|
|
238
|
+
/** Optional native window, equivalent to listReady then reverse/slice.
|
|
239
|
+
* Defaults: offset 0, order oldest. Arguments are nonnegative integers;
|
|
240
|
+
* zero limit returns no tickets with the full matching total. Diagnostics
|
|
241
|
+
* and failures match listReady; a failure must not trigger a full-read fallback.
|
|
242
|
+
* listReady and listAll remain exhaustive. */
|
|
243
|
+
listPage?(criteria: TicketCriteria, page: TicketPage): Promise<TicketPageListing>
|
|
224
244
|
get(id: string): Promise<Ticket | null>
|
|
225
245
|
/** Claim-before-launch (§12): acquires nonterminal work and returns true.
|
|
226
246
|
* Returns false for an unknown, already-claimed/contested, or terminal ticket.
|
|
@@ -733,6 +753,7 @@ export interface Transcript {
|
|
|
733
753
|
}
|
|
734
754
|
|
|
735
755
|
export interface AgentStartOpts {
|
|
756
|
+
account?: SelectedAccount
|
|
736
757
|
/** Await before further native output/prompt processing. Rejections are
|
|
737
758
|
* infrastructure failures and must propagate to the caller. */
|
|
738
759
|
onNativeSession?: NativeSessionObserver
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { sensitiveAccountValues } from '../../accounts/sensitive'
|
|
2
|
+
import type { NetworkPolicy, NetworkPolicyRule } from '@vercel/sandbox'
|
|
3
|
+
import {
|
|
4
|
+
accountPlaceholder,
|
|
5
|
+
accountRemedy,
|
|
6
|
+
kimiEndpoint,
|
|
7
|
+
type Accounts,
|
|
8
|
+
} from '../../config/accounts'
|
|
9
|
+
|
|
10
|
+
/** Only exact provider + account-specific header matches receive credentials. */
|
|
11
|
+
export function accountPolicy(
|
|
12
|
+
base: NetworkPolicy,
|
|
13
|
+
accounts: Accounts,
|
|
14
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
15
|
+
): { policy: NetworkPolicy; missing: string[] } {
|
|
16
|
+
if (Object.keys(accounts).length === 0) return { policy: base, missing: [] }
|
|
17
|
+
if (base === 'deny-all' || (typeof base === 'object' && Array.isArray(base.allow)))
|
|
18
|
+
throw new Error('Account policy requires a rule-based network policy')
|
|
19
|
+
const allow: Record<string, NetworkPolicyRule[]> =
|
|
20
|
+
typeof base === 'object'
|
|
21
|
+
? { ...(base.allow as Record<string, NetworkPolicyRule[]>) }
|
|
22
|
+
: { '*': [] }
|
|
23
|
+
const missing: string[] = []
|
|
24
|
+
for (const [name, descriptor] of Object.entries(accounts)) {
|
|
25
|
+
const credential = env[descriptor.credentialEnv]
|
|
26
|
+
if (!credential) {
|
|
27
|
+
missing.push(accountRemedy({ name, descriptor }))
|
|
28
|
+
continue
|
|
29
|
+
}
|
|
30
|
+
const claude = descriptor.kind !== 'kimi-code'
|
|
31
|
+
const host =
|
|
32
|
+
descriptor.kind === 'chatgpt-subscription'
|
|
33
|
+
? 'api.openai.com'
|
|
34
|
+
: descriptor.kind === 'kimi-code'
|
|
35
|
+
? kimiEndpoint(descriptor.region).host
|
|
36
|
+
: 'api.anthropic.com'
|
|
37
|
+
const key = claude ? 'authorization' : 'x-api-key'
|
|
38
|
+
const prefix = claude ? 'Bearer ' : ''
|
|
39
|
+
allow[host] = [
|
|
40
|
+
...(allow[host] ?? []),
|
|
41
|
+
{
|
|
42
|
+
match: {
|
|
43
|
+
headers: [{ key: { exact: key }, value: { exact: prefix + accountPlaceholder(name) } }],
|
|
44
|
+
},
|
|
45
|
+
transform: [{ headers: { [key]: prefix + credential } }],
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
return { policy: { ...(typeof base === 'object' ? base : {}), allow }, missing }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Declared credential variables and aliases containing their values never cross
|
|
53
|
+
* into the guest. Placeholders let sessions choose accounts without host RPC. */
|
|
54
|
+
export function accountGuestEnvironment(
|
|
55
|
+
forwarded: Record<string, string>,
|
|
56
|
+
accounts: Accounts,
|
|
57
|
+
host: Readonly<Record<string, string | undefined>>,
|
|
58
|
+
): Record<string, string> {
|
|
59
|
+
const env = { ...forwarded }
|
|
60
|
+
if (Object.keys(accounts).length) env.AB_ACCOUNT_PLACEHOLDERS = '1'
|
|
61
|
+
const secrets = [
|
|
62
|
+
...sensitiveAccountValues,
|
|
63
|
+
...Object.values(accounts)
|
|
64
|
+
.map((a) => host[a.credentialEnv])
|
|
65
|
+
.filter((v): v is string => !!v),
|
|
66
|
+
]
|
|
67
|
+
for (const [key, value] of Object.entries(env))
|
|
68
|
+
if (secrets.some((secret) => value.includes(secret))) delete env[key]
|
|
69
|
+
for (const [name, account] of Object.entries(accounts))
|
|
70
|
+
env[account.credentialEnv] = accountPlaceholder(name)
|
|
71
|
+
return env
|
|
72
|
+
}
|
|
@@ -107,10 +107,15 @@ export interface BuildExecutionHandle {
|
|
|
107
107
|
* A command exit without confirmed teardown is not terminal. `ended` carries the observed
|
|
108
108
|
* exit code; `lost` means the provider proved the environment/command no
|
|
109
109
|
* longer exists without an exit code. */
|
|
110
|
-
export type ExecutionObservation =
|
|
110
|
+
export type ExecutionObservation = (
|
|
111
111
|
| { state: 'running' }
|
|
112
112
|
| { state: 'ended'; exitCode?: number }
|
|
113
113
|
| { state: 'lost' }
|
|
114
|
+
) & {
|
|
115
|
+
/** Actionable host diagnosis, independent of command liveness. Callers must
|
|
116
|
+
* persist attention without suppressing observation or terminal settlement. */
|
|
117
|
+
attention?: string
|
|
118
|
+
}
|
|
114
119
|
|
|
115
120
|
/** The substitutable seam at the workspace boundary. A remote workspace
|
|
116
121
|
* provider may implement this by starting the fixed build process beside its
|
|
@@ -77,6 +77,7 @@ const BUILTINS: Record<string, BuiltinWorkspaceProviderDeclaration> = {
|
|
|
77
77
|
storeToken: opts.storeToken!,
|
|
78
78
|
repo: resolve(opts.repoRoot),
|
|
79
79
|
runtimeReferences: opts.runtimeReferences ?? [],
|
|
80
|
+
accounts: opts.accounts,
|
|
80
81
|
setupCommand: opts.sandboxSetupCommand,
|
|
81
82
|
sandboxEnvironmentVariables: opts.sandboxEnvironmentVariables,
|
|
82
83
|
...(opts.origin !== undefined ? { origin: opts.origin } : {}),
|
|
@@ -25,6 +25,7 @@ export interface CreateWorkspaceProviderOptions {
|
|
|
25
25
|
storeRef?: string
|
|
26
26
|
storeToken?: string
|
|
27
27
|
/** Host-derived effective routes; consumed only by the built-in sandbox. */
|
|
28
|
+
accounts?: () => import('../../config/accounts').Accounts
|
|
28
29
|
runtimeReferences?: RuntimeReferencesSource
|
|
29
30
|
/** Checkout-less seams for the built-in sandbox: the repository's HTTPS
|
|
30
31
|
* origin, and a remote branch-head reader returning `undefined` for an
|
|
@@ -148,6 +149,7 @@ export async function createWorkspaceProvider(
|
|
|
148
149
|
) => delegateCredential(opts.storeRef!, opts.storeToken, target),
|
|
149
150
|
}
|
|
150
151
|
: {}),
|
|
152
|
+
...(opts.accounts !== undefined ? { accounts: opts.accounts } : {}),
|
|
151
153
|
...(opts.runtimeReferences !== undefined
|
|
152
154
|
? { runtimeReferences: opts.runtimeReferences }
|
|
153
155
|
: {}),
|
|
@@ -45,7 +45,12 @@ export const spawnExec: Exec = async (cmd, opts) => {
|
|
|
45
45
|
stdin: 'ignore',
|
|
46
46
|
stdout: 'pipe',
|
|
47
47
|
stderr: 'pipe',
|
|
48
|
-
env: {
|
|
48
|
+
env: {
|
|
49
|
+
...process.env,
|
|
50
|
+
...opts.env,
|
|
51
|
+
AB_DISPATCH_GENERATION: undefined,
|
|
52
|
+
AB_PROJECT_SECRETS_KEY: undefined,
|
|
53
|
+
},
|
|
49
54
|
...(opts.signal === undefined ? {} : { signal: opts.signal }),
|
|
50
55
|
})
|
|
51
56
|
const [stdout, stderr, exitCode] = await Promise.all([
|
|
@@ -163,6 +163,7 @@ export interface WorkspaceReadinessContext {
|
|
|
163
163
|
configBytes: string
|
|
164
164
|
exec: Exec
|
|
165
165
|
redact: (value: unknown) => string
|
|
166
|
+
accounts?: import('../../config/accounts').Accounts
|
|
166
167
|
runtimeReferences: readonly RuntimeReferenceGroup[]
|
|
167
168
|
stdout: (line: string) => void
|
|
168
169
|
signal?: AbortSignal
|