@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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { accountRemedy, type SelectedAccount } from '../../config/accounts'
|
|
2
|
+
import { chatgptProvider } from './chatgpt-provider'
|
|
1
3
|
import { hostname } from 'node:os'
|
|
2
4
|
import {
|
|
3
5
|
guardNativeHandle,
|
|
@@ -53,6 +55,7 @@ import type { RuntimeUsabilityInput, RuntimeUsabilityResult } from './runtime'
|
|
|
53
55
|
import { sessionEnv } from './session-env'
|
|
54
56
|
|
|
55
57
|
export interface CodexCliInvocation {
|
|
58
|
+
account?: SelectedAccount
|
|
56
59
|
/** Arguments after the `codex` executable. */
|
|
57
60
|
args: string[]
|
|
58
61
|
cwd: string
|
|
@@ -251,14 +254,21 @@ export class CodexAgentRunner implements AgentRunner, OneShotCompletion {
|
|
|
251
254
|
]
|
|
252
255
|
for (const feature of ONE_SHOT_DISABLED_FEATURES) args.push('--disable', feature)
|
|
253
256
|
if (input.model !== undefined) args.push(CODEX_MODEL_ARG, input.model)
|
|
254
|
-
|
|
257
|
+
const provider = await chatgptProvider(input.account, sessionEnv(input.env), input.cwd)
|
|
258
|
+
args.push(
|
|
259
|
+
...(input.args ?? []),
|
|
260
|
+
...provider.args.filter((arg) => arg !== '--ignore-user-config'),
|
|
261
|
+
CODEX_PROMPT_BOUNDARY,
|
|
262
|
+
input.prompt,
|
|
263
|
+
)
|
|
255
264
|
|
|
256
265
|
const turn = await this.runPrompt({
|
|
257
266
|
args,
|
|
258
267
|
cwd: input.cwd,
|
|
259
|
-
|
|
268
|
+
account: input.account,
|
|
269
|
+
env: provider.env,
|
|
260
270
|
...(input.signal !== undefined ? { signal: input.signal } : {}),
|
|
261
|
-
})
|
|
271
|
+
}).finally(provider.close)
|
|
262
272
|
if (turn.failure !== undefined) throw new Error(turn.failure.message)
|
|
263
273
|
if (turn.toolItems.length > 0) {
|
|
264
274
|
throw new Error(
|
|
@@ -445,40 +455,49 @@ export class CodexAgentRunner implements AgentRunner, OneShotCompletion {
|
|
|
445
455
|
SHELL_ENV_INHERIT,
|
|
446
456
|
)
|
|
447
457
|
if (opts.model !== undefined) args.push(CODEX_MODEL_ARG, opts.model)
|
|
448
|
-
|
|
458
|
+
const provider =
|
|
459
|
+
opts.account?.descriptor.kind === 'chatgpt-subscription'
|
|
460
|
+
? await chatgptProvider(opts.account, sessionEnv(opts.env), opts.workspacePath)
|
|
461
|
+
: { env: sessionEnv(opts.env), args: [] as string[], close: async () => {} }
|
|
462
|
+
args.push(...(opts.args ?? []), ...provider.args)
|
|
449
463
|
if (resume !== undefined) args.push(resume)
|
|
450
464
|
args.push(CODEX_PROMPT_BOUNDARY, prompt)
|
|
451
465
|
const invocation: CodexCliInvocation = {
|
|
452
466
|
args,
|
|
453
467
|
cwd: opts.workspacePath,
|
|
454
|
-
|
|
468
|
+
account: opts.account,
|
|
469
|
+
env: provider.env,
|
|
455
470
|
...(signal !== undefined ? { signal } : {}),
|
|
456
471
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
472
|
+
try {
|
|
473
|
+
if (opts.stream === undefined && opts.onNativeSession === undefined)
|
|
474
|
+
return await this.runPrompt(invocation)
|
|
475
|
+
if (opts.stream === undefined) {
|
|
476
|
+
if (this.runCliStream !== undefined)
|
|
477
|
+
return await this.runStreamingPrompt(invocation, undefined, observe)
|
|
478
|
+
const turn = await this.runPrompt(invocation)
|
|
479
|
+
for (const event of turn.events) await observeEvent(event)
|
|
480
|
+
return turn
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Streaming turn: translate while the CLI runs. Without an injected
|
|
484
|
+
// streaming boundary (offline fakes), the buffered path still translates
|
|
485
|
+
// after completion — degraded latency, same content.
|
|
486
|
+
const emitter = opts.stream
|
|
487
|
+
emitter.append([promptPart(prompt), startPart(crypto.randomUUID())])
|
|
488
|
+
let turn: CodexTurn
|
|
489
|
+
if (this.runCliStream !== undefined) {
|
|
490
|
+
turn = await this.runStreamingPrompt(invocation, emitter, observe)
|
|
491
|
+
} else {
|
|
492
|
+
turn = await this.runPrompt(invocation)
|
|
493
|
+
for (const event of turn.events) await observeEvent(event)
|
|
494
|
+
translateBufferedCodexTurn(turn, (parts) => emitter?.append(parts))
|
|
495
|
+
}
|
|
496
|
+
this.emitTurnEnd(turn, emitter, signal)
|
|
464
497
|
return turn
|
|
498
|
+
} finally {
|
|
499
|
+
await provider.close()
|
|
465
500
|
}
|
|
466
|
-
|
|
467
|
-
// Streaming turn: translate while the CLI runs. Without an injected
|
|
468
|
-
// streaming boundary (offline fakes), the buffered path still translates
|
|
469
|
-
// after completion — degraded latency, same content.
|
|
470
|
-
const emitter = opts.stream
|
|
471
|
-
emitter.append([promptPart(prompt), startPart(crypto.randomUUID())])
|
|
472
|
-
let turn: CodexTurn
|
|
473
|
-
if (this.runCliStream !== undefined) {
|
|
474
|
-
turn = await this.runStreamingPrompt(invocation, emitter, observe)
|
|
475
|
-
} else {
|
|
476
|
-
turn = await this.runPrompt(invocation)
|
|
477
|
-
for (const event of turn.events) await observeEvent(event)
|
|
478
|
-
translateBufferedCodexTurn(turn, (parts) => emitter?.append(parts))
|
|
479
|
-
}
|
|
480
|
-
this.emitTurnEnd(turn, emitter, signal)
|
|
481
|
-
return turn
|
|
482
501
|
}
|
|
483
502
|
|
|
484
503
|
/** Completed-turn, failed-turn, and cancelled-turn closing parts. */
|
|
@@ -550,7 +569,7 @@ export class CodexAgentRunner implements AgentRunner, OneShotCompletion {
|
|
|
550
569
|
// The result promise below still carries the CLI's exit and stderr.
|
|
551
570
|
}
|
|
552
571
|
const cli = await handle.result
|
|
553
|
-
return this.finishTurn(cli, acc.snapshot())
|
|
572
|
+
return this.finishTurn(cli, acc.snapshot(), invocation.account)
|
|
554
573
|
}
|
|
555
574
|
|
|
556
575
|
private async runPrompt(invocation: CodexCliInvocation): Promise<CodexTurn> {
|
|
@@ -560,11 +579,15 @@ export class CodexAgentRunner implements AgentRunner, OneShotCompletion {
|
|
|
560
579
|
} catch (error) {
|
|
561
580
|
return launchFailure(error)
|
|
562
581
|
}
|
|
563
|
-
return this.finishTurn(cli, parseCodexOutput(cli.stdout))
|
|
582
|
+
return this.finishTurn(cli, parseCodexOutput(cli.stdout), invocation.account)
|
|
564
583
|
}
|
|
565
584
|
|
|
566
585
|
/** Shared post-processing of a completed CLI run. */
|
|
567
|
-
private finishTurn(
|
|
586
|
+
private finishTurn(
|
|
587
|
+
cli: CodexCliResult,
|
|
588
|
+
parsed: ParsedCodexOutput,
|
|
589
|
+
account?: SelectedAccount,
|
|
590
|
+
): CodexTurn {
|
|
568
591
|
const text = parsed.assistantText.join('\n')
|
|
569
592
|
let failureMessage: string | undefined
|
|
570
593
|
let loggedOut = false
|
|
@@ -588,6 +611,15 @@ export class CodexAgentRunner implements AgentRunner, OneShotCompletion {
|
|
|
588
611
|
failureMessage = `${this.name} runtime: Codex CLI stream ended without a turn.completed event`
|
|
589
612
|
}
|
|
590
613
|
|
|
614
|
+
if (
|
|
615
|
+
failureMessage &&
|
|
616
|
+
account?.descriptor.kind === 'chatgpt-subscription' &&
|
|
617
|
+
classifyProviderError(failureMessage, { status: parsed.statuses[0], codes: parsed.codes })
|
|
618
|
+
.cause === 'credentials'
|
|
619
|
+
) {
|
|
620
|
+
failureMessage = accountRemedy(account)
|
|
621
|
+
loggedOut = true
|
|
622
|
+
}
|
|
591
623
|
return {
|
|
592
624
|
text,
|
|
593
625
|
usage: parsed.usage,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SelectedAccount } from '../../config/accounts'
|
|
1
2
|
/**
|
|
2
3
|
* A narrow, tool-free, non-phase judgment capability. Unlike AgentRunner,
|
|
3
4
|
* one-shot completions have no resumable session, skill invocation,
|
|
@@ -6,6 +7,7 @@
|
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
export interface OneShotCompletionInput {
|
|
10
|
+
account?: SelectedAccount
|
|
9
11
|
prompt: string
|
|
10
12
|
/** Working directory used for project context and runtime resolution. */
|
|
11
13
|
cwd: string
|
|
@@ -10,12 +10,14 @@ export interface ProviderErrorHints {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const EXHAUSTION_CODE_PATTERNS = [
|
|
13
|
+
/^subscription_sharing_usage_(?:limit_exceeded|unavailable)$/,
|
|
13
14
|
/(?:^|[_-])(?:billing|payment|quota|credit|balance|budget)(?:[_-]|$)/,
|
|
14
15
|
/^(?:insufficient|out_of)_(?:quota|credits?|balance|funds)$/,
|
|
15
16
|
/^usage_(?:limit|quota)(?:_|$)/,
|
|
16
17
|
] as const
|
|
17
18
|
|
|
18
19
|
const CREDENTIAL_CODE_PATTERNS = [
|
|
20
|
+
/^(?:invalid_grant|refresh_token_invalidated|subscription_sharing_user_not_eligible)$/,
|
|
19
21
|
/^(?:auth|authentication|authorization)(?:_|-)/,
|
|
20
22
|
/^(?:unauthorized|forbidden)$/,
|
|
21
23
|
/^(?:invalid|expired|missing|revoked)_(?:api_)?(?:key|token|credential)s?$/,
|
|
@@ -24,6 +26,7 @@ const CREDENTIAL_CODE_PATTERNS = [
|
|
|
24
26
|
] as const
|
|
25
27
|
|
|
26
28
|
const EXHAUSTION_TEXT_PATTERNS = [
|
|
29
|
+
/subscription_sharing_usage_(?:limit_exceeded|unavailable)/i,
|
|
27
30
|
/(?:^|[^a-z0-9])(?:quota(?:[_ -](?:exceeded|exhausted|depleted|refreshes?))?|(?:insufficient|exhausted|depleted)[_ -]quota)(?:$|[^a-z0-9])/i,
|
|
28
31
|
/\busage[_ -]?(?:limit|quota)\b/i,
|
|
29
32
|
/\b(?:billing|spending|monthly)\s+(?:limit|cap|cycle)\b/i,
|
|
@@ -36,6 +39,8 @@ const EXHAUSTION_TEXT_PATTERNS = [
|
|
|
36
39
|
] as const
|
|
37
40
|
|
|
38
41
|
const CREDENTIAL_TEXT_PATTERNS = [
|
|
42
|
+
/\b(?:invalid|expired|revoked)\s+(?:oauth\s+access|bearer)\s+token\b/i,
|
|
43
|
+
/\bfailed to authenticate\b/i,
|
|
39
44
|
/\b(?:authentication|authorization)[_ -](?:failed|required|error|invalid)\b/i,
|
|
40
45
|
/\bunauthori[sz]ed\b/i,
|
|
41
46
|
/\bforbidden\b/i,
|
|
@@ -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
|