@cortex-agent/server 2026.8.3-2 → 2026.8.6
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/defaults/config/thread-templates/agents/benchmark-coder.json +2 -2
- package/defaults/config/thread-templates/agents/benchmark-fixer.json +17 -0
- package/defaults/config/thread-templates/agents/benchmark-reviewer.json +5 -5
- package/defaults/config/thread-templates/templates/benchmark-coder-review-fix.json +21 -0
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +1 -0
- package/defaults/prompts/directives/benchmark-coder.md +1 -0
- package/defaults/prompts/directives/benchmark-fixer.md +1 -0
- package/defaults/prompts/directives/benchmark-reviewer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-coder.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-fixer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-reviewer.md +1 -0
- package/dist/agent-adapter/capabilities.d.ts +32 -1
- package/dist/agent-adapter/capabilities.js +39 -1
- package/dist/agent-adapter/claude/adapter.d.ts +15 -0
- package/dist/agent-adapter/claude/adapter.js +29 -7
- package/dist/agent-adapter/claude/spawn-args.d.ts +5 -2
- package/dist/agent-adapter/claude/spawn-args.js +29 -6
- package/dist/agent-adapter/index.js +11 -1
- package/dist/agent-adapter/normalize/tool-names.d.ts +4 -0
- package/dist/agent-adapter/normalize/tool-names.js +10 -0
- package/dist/agent-adapter/pi/adapter.d.ts +20 -8
- package/dist/agent-adapter/pi/adapter.js +130 -35
- package/dist/agent-adapter/pi/agent-dir.d.ts +20 -53
- package/dist/agent-adapter/pi/agent-dir.js +48 -89
- package/dist/agent-adapter/pi/custom-catalog.d.ts +10 -0
- package/dist/agent-adapter/pi/custom-catalog.js +42 -0
- package/dist/agent-adapter/pi/defaults.d.ts +9 -0
- package/dist/agent-adapter/pi/defaults.js +14 -4
- package/dist/agent-adapter/pi/discovery.d.ts +1 -3
- package/dist/agent-adapter/pi/discovery.js +3 -15
- package/dist/agent-adapter/pi/event-parser.js +8 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +31 -6
- package/dist/agent-adapter/pi/mcp-duration.d.ts +28 -0
- package/dist/agent-adapter/pi/mcp-duration.js +48 -0
- package/dist/agent-adapter/pi/policy-guard.d.ts +40 -0
- package/dist/agent-adapter/pi/policy-guard.js +111 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +62 -0
- package/dist/agent-adapter/pi/providers-config.js +101 -0
- package/dist/agent-adapter/pi/quota-probe.d.ts +11 -0
- package/dist/agent-adapter/pi/quota-probe.js +36 -0
- package/dist/agent-adapter/pi/quota-sink.d.ts +25 -0
- package/dist/agent-adapter/pi/quota-sink.js +31 -0
- package/dist/agent-adapter/pi/session-files.d.ts +2 -0
- package/dist/agent-adapter/pi/session-files.js +19 -0
- package/dist/agent-adapter/pi/session-support.d.ts +14 -3
- package/dist/agent-adapter/pi/session-support.js +8 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +11 -1
- package/dist/agent-adapter/pi/spawn-args.js +13 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +2 -2
- package/dist/agent-adapter/pi/tool-shims.js +32 -21
- package/dist/agent-adapter/pi/web-search.js +36 -8
- package/dist/agent-adapter/types.d.ts +14 -0
- package/dist/core/locales/en.d.ts +54 -1
- package/dist/core/locales/en.js +2 -0
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/providers.d.ts +45 -0
- package/dist/core/locales/slices/providers.js +95 -0
- package/dist/core/locales/zh.js +2 -0
- package/dist/core/resilient-watch.d.ts +28 -0
- package/dist/core/resilient-watch.js +110 -0
- package/dist/core/settings.js +15 -20
- package/dist/core/types/agent-types.d.ts +6 -0
- package/dist/core/types/thread-types.d.ts +21 -3
- package/dist/domain/agent-run/agent-run-cli.js +3 -1
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +31 -0
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +231 -24
- package/dist/domain/agent-run/benchmark-thread-identity.d.ts +15 -2
- package/dist/domain/agent-run/benchmark-thread-identity.js +123 -34
- package/dist/domain/agent-run/identity.d.ts +5 -0
- package/dist/domain/agent-run/identity.js +4 -1
- package/dist/domain/agent-run/journal.d.ts +3 -2
- package/dist/domain/agent-run/manifest.js +11 -4
- package/dist/domain/agent-run/pinned-node-process.d.ts +4 -0
- package/dist/domain/agent-run/pinned-node-process.js +9 -0
- package/dist/domain/agent-run/role-surface.d.ts +2 -2
- package/dist/domain/agent-run/role-surface.js +7 -3
- package/dist/domain/agent-run/run-config.d.ts +10 -1
- package/dist/domain/agent-run/run-config.js +57 -6
- package/dist/domain/agent-run/runner.js +149 -31
- package/dist/domain/agents/facade.d.ts +37 -122
- package/dist/domain/agents/facade.js +47 -115
- package/dist/domain/agents/spawn-config.d.ts +135 -0
- package/dist/domain/agents/spawn-config.js +121 -0
- package/dist/domain/benchmark/accounting-reconciliation.d.ts +98 -0
- package/dist/domain/benchmark/accounting-reconciliation.js +218 -0
- package/dist/domain/benchmark/arm-schema.d.ts +43 -0
- package/dist/domain/benchmark/arm-schema.js +243 -0
- package/dist/domain/benchmark/capabilities.d.ts +4 -0
- package/dist/domain/benchmark/capabilities.js +54 -0
- package/dist/domain/benchmark/decimal-text.d.ts +27 -0
- package/dist/domain/benchmark/decimal-text.js +67 -0
- package/dist/domain/benchmark/lease-echo.d.ts +43 -0
- package/dist/domain/benchmark/lease-echo.js +56 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.d.ts +14 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.js +47 -0
- package/dist/domain/benchmark/policy-compiler.d.ts +68 -0
- package/dist/domain/benchmark/policy-compiler.js +680 -0
- package/dist/domain/benchmark/resolved-policy.d.ts +110 -0
- package/dist/domain/benchmark/resolved-policy.js +195 -0
- package/dist/domain/benchmark/trial-adapter-factory.d.ts +38 -0
- package/dist/domain/benchmark/trial-adapter-factory.js +165 -0
- package/dist/domain/benchmark/trial-thread-adapter.d.ts +25 -0
- package/dist/domain/benchmark/trial-thread-adapter.js +106 -0
- package/dist/domain/benchmark/variant-proposal.d.ts +45 -0
- package/dist/domain/benchmark/variant-proposal.js +42 -0
- package/dist/domain/benchmark/workspace-lease.d.ts +99 -0
- package/dist/domain/benchmark/workspace-lease.js +272 -0
- package/dist/domain/costs/codex-quota.d.ts +29 -0
- package/dist/domain/costs/codex-quota.js +102 -0
- package/dist/domain/costs/cost-tracker.d.ts +48 -9
- package/dist/domain/costs/cost-tracker.js +74 -18
- package/dist/domain/costs/rate-limit-throttle.d.ts +23 -1
- package/dist/domain/costs/rate-limit-throttle.js +61 -6
- package/dist/domain/costs/resume-registry.d.ts +3 -1
- package/dist/domain/costs/resume-registry.js +10 -1
- package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +26 -2
- package/dist/domain/mcp/tools/benchmark-thread-run.js +63 -20
- package/dist/domain/mcp/tools/cost.js +15 -6
- package/dist/domain/pi-providers/custom-provider-model.d.ts +53 -0
- package/dist/domain/pi-providers/custom-provider-model.js +122 -0
- package/dist/domain/pi-providers/custom-provider-service.d.ts +59 -0
- package/dist/domain/pi-providers/custom-provider-service.js +143 -0
- package/dist/domain/pi-providers/gateway-route-store.d.ts +23 -0
- package/dist/domain/pi-providers/gateway-route-store.js +78 -0
- package/dist/domain/pi-providers/index.d.ts +4 -0
- package/dist/domain/pi-providers/index.js +8 -0
- package/dist/domain/pi-providers/models-json-store.d.ts +6 -0
- package/dist/domain/pi-providers/models-json-store.js +77 -0
- package/dist/domain/scheduling/jobs/_shared.d.ts +4 -1
- package/dist/domain/scheduling/jobs/_shared.js +11 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +1 -0
- package/dist/domain/scheduling/jobs/task-dispatch.js +49 -54
- package/dist/domain/sessions/session-lifecycle.d.ts +22 -0
- package/dist/domain/sessions/session-lifecycle.js +20 -1
- package/dist/domain/system/system-notice.d.ts +4 -1
- package/dist/domain/system/system-notice.js +6 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +0 -4
- package/dist/domain/tasks/dispatch-utils.js +24 -37
- package/dist/domain/threads/runner.d.ts +16 -1
- package/dist/domain/threads/runner.js +62 -8
- package/dist/domain/threads/template-loader.d.ts +5 -0
- package/dist/domain/threads/template-loader.js +120 -36
- package/dist/domain/threads/template-validate.d.ts +244 -0
- package/dist/domain/threads/template-validate.js +574 -0
- package/dist/domain/threads/template-validate.parity.d.ts +1 -0
- package/dist/domain/threads/template-validate.parity.js +47 -0
- package/dist/domain/threads/template-writer.d.ts +55 -0
- package/dist/domain/threads/template-writer.js +131 -0
- package/dist/domain/ui-service/app-router.d.ts +143 -1
- package/dist/domain/ui-service/app-router.js +29 -3
- package/dist/domain/ui-service/input-schemas.d.ts +228 -4
- package/dist/domain/ui-service/input-schemas.js +132 -1
- package/dist/domain/ui-service/mutate/config.d.ts +10 -1
- package/dist/domain/ui-service/mutate/config.js +45 -5
- package/dist/domain/ui-service/mutate/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/mutate/custom-providers.js +37 -0
- package/dist/domain/ui-service/mutate/profiles.d.ts +21 -0
- package/dist/domain/ui-service/mutate/profiles.js +156 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
- package/dist/domain/ui-service/mutate/schedules.js +53 -3
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +25 -1
- package/dist/domain/ui-service/mutate/system.d.ts +2 -1
- package/dist/domain/ui-service/mutate/system.js +17 -3
- package/dist/domain/ui-service/mutate/thread-templates.d.ts +4 -0
- package/dist/domain/ui-service/mutate/thread-templates.js +71 -0
- package/dist/domain/ui-service/query/config.js +30 -0
- package/dist/domain/ui-service/query/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/query/custom-providers.js +13 -0
- package/dist/domain/ui-service/query/machine-detail.d.ts +2 -0
- package/dist/domain/ui-service/query/machine-detail.js +56 -0
- package/dist/domain/ui-service/query/machine-probe.d.ts +18 -0
- package/dist/domain/ui-service/query/machine-probe.js +136 -0
- package/dist/domain/ui-service/query/schedules.js +5 -0
- package/dist/domain/ui-service/query/sessions.js +8 -2
- package/dist/domain/ui-service/query/thread-template-detail.d.ts +8 -0
- package/dist/domain/ui-service/query/thread-template-detail.js +94 -0
- package/dist/domain/ui-service/query/thread-templates.d.ts +5 -3
- package/dist/domain/ui-service/query/thread-templates.js +44 -7
- package/dist/domain/ui-service/types.d.ts +298 -7
- package/dist/domain/ui-service/ui-service.js +27 -3
- package/dist/entry/app.js +24 -3
- package/dist/entry/auth-cli.d.ts +4 -1
- package/dist/entry/auth-cli.js +10 -2
- package/dist/entry/cli-help.js +6 -2
- package/dist/entry/cli.js +2 -1
- package/dist/entry/daemon.d.ts +0 -11
- package/dist/entry/daemon.js +5 -49
- package/dist/entry/provider-cli.d.ts +16 -0
- package/dist/entry/provider-cli.js +203 -0
- package/dist/events/event-types.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +3 -2
- package/dist/orchestration/routing/commands/cost.d.ts +8 -0
- package/dist/orchestration/routing/commands/cost.js +93 -21
- package/dist/orchestration/routing/commands/login-custom.d.ts +26 -0
- package/dist/orchestration/routing/commands/login-custom.js +89 -0
- package/dist/orchestration/routing/commands/login.d.ts +3 -0
- package/dist/orchestration/routing/commands/login.js +7 -0
- package/dist/orchestration/routing/message-router.js +48 -33
- package/dist/orchestration/routing/webhook.js +1 -1
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/thread-callback.js +1 -1
- package/dist/store/conversation-history-repo.d.ts +5 -1
- package/dist/store/conversation-history-repo.js +2 -1
- package/dist/store/cost-repo.d.ts +17 -0
- package/dist/store/cost-repo.js +47 -5
- package/dist/store/profile-repo.d.ts +0 -10
- package/dist/store/profile-repo.js +34 -56
- package/dist/store/session-registry-repo.d.ts +12 -0
- package/dist/store/session-registry-repo.js +16 -0
- package/package.json +1 -1
- package/web/dist/assets/index-DYMfaAi4.css +1 -0
- package/web/dist/assets/index-uOoZjGKa.js +141 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-XqBCYtkw.js +0 -139
- package/web/dist/assets/index-zpf3OSKC.css +0 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// input: parsed arm and phase-A resolution documents
|
|
2
|
+
// output: validated v2 arms and versioned resolution shapes
|
|
3
|
+
// pos: Closed schema and ordered cross-field validation
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export const ARM_SCHEMA_VERSION = 'cortex-benchmark-arm/2';
|
|
7
|
+
export const ARM_RESOLUTION_SCHEMA_VERSION = 'cortex-benchmark-arm-resolution/1';
|
|
8
|
+
export class ArmValidationError extends Error {
|
|
9
|
+
reason;
|
|
10
|
+
constructor(reason, detail) {
|
|
11
|
+
super(`${reason}: ${detail}`);
|
|
12
|
+
this.reason = reason;
|
|
13
|
+
this.name = 'ArmValidationError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const safeName = /^[A-Za-z0-9._-]+$/;
|
|
17
|
+
const safeProvider = /^[A-Za-z0-9_-]+$/;
|
|
18
|
+
const decimal = /^\d+(?:\.\d+)?$/;
|
|
19
|
+
const limitsSchema = z.object({
|
|
20
|
+
max_thread_starts: z.number(),
|
|
21
|
+
max_parent_questions: z.number(),
|
|
22
|
+
max_task_depth: z.number(),
|
|
23
|
+
max_tasks: z.number(),
|
|
24
|
+
max_provider_requests: z.number(),
|
|
25
|
+
max_resident_agent_processes: z.number(),
|
|
26
|
+
max_cost_usd: z.string(),
|
|
27
|
+
deadline_seconds: z.number(),
|
|
28
|
+
}).strict();
|
|
29
|
+
const orchestrationSchema = z.object({
|
|
30
|
+
mode: z.enum(['direct', 'coder-review', 'manager']),
|
|
31
|
+
coder_review_variant: z.string().optional(),
|
|
32
|
+
ask_manager: z.boolean().optional().default(false),
|
|
33
|
+
}).strict();
|
|
34
|
+
const armSchema = z.object({
|
|
35
|
+
schema_version: z.literal(ARM_SCHEMA_VERSION),
|
|
36
|
+
kind: z.enum(['cortex', 'vendor-baseline']),
|
|
37
|
+
name: z.string().min(1).regex(safeName),
|
|
38
|
+
backend: z.enum(['claude', 'pi']).optional(),
|
|
39
|
+
vendor_agent: z.enum(['claude-code', 'pi', 'codex']).optional(),
|
|
40
|
+
provider: z.string().regex(safeProvider).nullable().optional().default(null),
|
|
41
|
+
model: z.string().min(1),
|
|
42
|
+
credential_capability: z.string().min(1),
|
|
43
|
+
orchestration: orchestrationSchema.optional(),
|
|
44
|
+
limits: limitsSchema,
|
|
45
|
+
}).strict();
|
|
46
|
+
const namedStrings = z.record(z.string(), z.string().min(1));
|
|
47
|
+
const credentialProjectionSchema = z.object({
|
|
48
|
+
id: z.string().min(1),
|
|
49
|
+
state: z.enum(['unsupported', 'offline-contract-passed', 'live-handshake-passed']),
|
|
50
|
+
key: z.object({
|
|
51
|
+
runner_or_backend: z.string().min(1),
|
|
52
|
+
provider: z.string(),
|
|
53
|
+
protocol: z.string(),
|
|
54
|
+
credential_kind: z.string().min(1),
|
|
55
|
+
proxy_adapter_version: z.string().min(1),
|
|
56
|
+
}).strict(),
|
|
57
|
+
}).strict();
|
|
58
|
+
const roleAssetSchema = z.object({
|
|
59
|
+
system_prompt_path: z.string().min(1),
|
|
60
|
+
directive_path: z.string().min(1),
|
|
61
|
+
tools: z.array(z.string().min(1)).min(1),
|
|
62
|
+
plugin_dirs: z.array(z.string().min(1)),
|
|
63
|
+
mcp_composition: z.enum(['direct', 'thread-control', 'none', 'benchmark-thread-run']),
|
|
64
|
+
mcp_config_paths: z.array(z.string().min(1)),
|
|
65
|
+
disable_hooks: z.literal(true),
|
|
66
|
+
// No `benchmark_policy_guard` member: the compiler derives the guard from the role (design §13.10
|
|
67
|
+
// GE2/GE5), so `.strict()` below refuses a phase-A document that authors one — a guard the model
|
|
68
|
+
// could read out of its own agent dir is the objection route RT1 was rejected for.
|
|
69
|
+
}).strict();
|
|
70
|
+
const armResolutionSchema = z.object({
|
|
71
|
+
schema_version: z.literal(ARM_RESOLUTION_SCHEMA_VERSION),
|
|
72
|
+
arm: z.unknown(), arm_path: z.string().min(1), trial_id: z.string().min(1),
|
|
73
|
+
root_run_id: z.string().min(1),
|
|
74
|
+
task: z.object({
|
|
75
|
+
task_id: z.string().min(1), image_ref: z.string().min(1), image_digest: z.string(),
|
|
76
|
+
}).strict(),
|
|
77
|
+
profile_name: z.string().min(1), paid_run: z.boolean(),
|
|
78
|
+
credential_capabilities: z.array(credentialProjectionSchema),
|
|
79
|
+
credential: z.object({
|
|
80
|
+
upstream_base_url: z.string().min(1), route_identity_host: z.string().min(1),
|
|
81
|
+
proxy_base_url: z.string().min(1), dummy_token_ref: z.string().min(1),
|
|
82
|
+
}).strict(),
|
|
83
|
+
cli_artifact: z.object({ path: z.string().min(1), version: z.string().min(1) }).strict(),
|
|
84
|
+
model_alias_policy: z.unknown(), roles: z.record(z.string(), roleAssetSchema),
|
|
85
|
+
thread_templates: namedStrings, thread_agents: namedStrings,
|
|
86
|
+
artifact_inventory_spec: z.unknown(), expected_asset_hashes: namedStrings.optional(),
|
|
87
|
+
pi_benchmark_capability_proven: z.boolean().optional(),
|
|
88
|
+
}).strict();
|
|
89
|
+
function fail(reason, detail) {
|
|
90
|
+
throw new ArmValidationError(reason, detail);
|
|
91
|
+
}
|
|
92
|
+
function isNonnegativeInteger(value) {
|
|
93
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
94
|
+
}
|
|
95
|
+
function validateCountLimits(limits) {
|
|
96
|
+
const nonnegative = [
|
|
97
|
+
limits.max_parent_questions, limits.max_task_depth, limits.max_tasks,
|
|
98
|
+
];
|
|
99
|
+
if (!nonnegative.every(isNonnegativeInteger)) {
|
|
100
|
+
fail('limit_out_of_range', 'question, depth, and task limits must be nonnegative integers');
|
|
101
|
+
}
|
|
102
|
+
if (!Number.isSafeInteger(limits.max_thread_starts)
|
|
103
|
+
|| ![0, 1].includes(limits.max_thread_starts)) {
|
|
104
|
+
fail('limit_out_of_range', 'max_thread_starts must be 0 or 1');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function validatePositiveLimits(limits) {
|
|
108
|
+
const positive = [
|
|
109
|
+
limits.max_provider_requests,
|
|
110
|
+
limits.max_resident_agent_processes,
|
|
111
|
+
limits.deadline_seconds,
|
|
112
|
+
];
|
|
113
|
+
if (!positive.every(value => Number.isSafeInteger(value) && value > 0)) {
|
|
114
|
+
fail('limit_out_of_range', 'provider, resident, and deadline limits must be positive integers');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function validateCostLimit(value) {
|
|
118
|
+
if (!decimal.test(value))
|
|
119
|
+
fail('limit_out_of_range', 'max_cost_usd must be a decimal string');
|
|
120
|
+
if (!/[1-9]/.test(value))
|
|
121
|
+
fail('limit_out_of_range', 'max_cost_usd must be positive');
|
|
122
|
+
}
|
|
123
|
+
function validateLimitRanges(limits) {
|
|
124
|
+
validateCountLimits(limits);
|
|
125
|
+
validatePositiveLimits(limits);
|
|
126
|
+
validateCostLimit(limits.max_cost_usd);
|
|
127
|
+
}
|
|
128
|
+
function validateKindFields(arm) {
|
|
129
|
+
const cortexValid = arm.backend !== undefined
|
|
130
|
+
&& arm.orchestration !== undefined && arm.vendor_agent === undefined;
|
|
131
|
+
if (arm.kind === 'cortex' && !cortexValid) {
|
|
132
|
+
fail('arm_field_conflict', 'cortex requires backend and orchestration, without vendor_agent');
|
|
133
|
+
}
|
|
134
|
+
const baselineValid = arm.vendor_agent !== undefined
|
|
135
|
+
&& arm.backend === undefined && arm.orchestration === undefined;
|
|
136
|
+
if (arm.kind === 'vendor-baseline' && !baselineValid) {
|
|
137
|
+
fail('arm_field_conflict', 'vendor-baseline requires vendor_agent only');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function validateCoderVariant(arm) {
|
|
141
|
+
const orchestration = arm.orchestration;
|
|
142
|
+
if (!orchestration)
|
|
143
|
+
return;
|
|
144
|
+
const hasVariant = orchestration.coder_review_variant !== undefined;
|
|
145
|
+
if ((orchestration.mode === 'coder-review') !== hasVariant) {
|
|
146
|
+
fail('coder_review_variant_invalid', 'coder-review mode and variant must be present together');
|
|
147
|
+
}
|
|
148
|
+
if (hasVariant && !['audit-retry', 'reviewer-fix'].includes(orchestration.coder_review_variant)) {
|
|
149
|
+
fail('coder_review_variant_invalid', 'unknown coder-review variant');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function validateAskManager(arm) {
|
|
153
|
+
const orchestration = arm.orchestration;
|
|
154
|
+
if (orchestration?.ask_manager === true && orchestration.mode !== 'manager') {
|
|
155
|
+
fail('ask_manager_unsupported_mode', 'ask_manager requires manager mode');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function expectedThreadStarts(arm) {
|
|
159
|
+
const mode = arm.orchestration?.mode;
|
|
160
|
+
return arm.kind === 'cortex' && (mode === 'coder-review' || mode === 'manager') ? 1 : 0;
|
|
161
|
+
}
|
|
162
|
+
function validateThreadStarts(arm) {
|
|
163
|
+
if (arm.limits.max_thread_starts !== expectedThreadStarts(arm)) {
|
|
164
|
+
fail('arm_field_conflict', 'max_thread_starts is inconsistent with kind and mode');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function validateQuestionLimit(arm) {
|
|
168
|
+
if (arm.orchestration?.ask_manager !== true && arm.limits.max_parent_questions !== 0) {
|
|
169
|
+
fail('arm_field_conflict', 'max_parent_questions must be zero when ask_manager is false');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function validateTaskLimits(arm) {
|
|
173
|
+
const manager = arm.orchestration?.mode === 'manager';
|
|
174
|
+
if (!manager && (arm.limits.max_task_depth !== 0 || arm.limits.max_tasks !== 0)) {
|
|
175
|
+
fail('arm_field_conflict', 'non-manager modes require zero task depth and task count');
|
|
176
|
+
}
|
|
177
|
+
if (manager && arm.limits.max_tasks < 1) {
|
|
178
|
+
fail('limit_out_of_range', 'manager mode requires at least one task');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function validateCapacity(arm) {
|
|
182
|
+
if (arm.limits.max_resident_agent_processes < arm.limits.max_task_depth + 1) {
|
|
183
|
+
fail('capacity_rule_violated', 'resident processes must cover task depth plus answerer');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function validatePiBaselineProvider(arm) {
|
|
187
|
+
if (arm.kind === 'vendor-baseline' && arm.vendor_agent === 'pi' && arm.provider === null) {
|
|
188
|
+
fail('arm_field_conflict', 'the pi vendor baseline requires provider');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function validateCrossFields(arm) {
|
|
192
|
+
validateKindFields(arm);
|
|
193
|
+
validateCoderVariant(arm);
|
|
194
|
+
validateAskManager(arm);
|
|
195
|
+
validateThreadStarts(arm);
|
|
196
|
+
validateQuestionLimit(arm);
|
|
197
|
+
validateTaskLimits(arm);
|
|
198
|
+
validateCapacity(arm);
|
|
199
|
+
}
|
|
200
|
+
function schemaFailure(error) {
|
|
201
|
+
if (!(error instanceof z.ZodError))
|
|
202
|
+
return error;
|
|
203
|
+
const issue = error.issues[0];
|
|
204
|
+
const field = issue?.path.join('.') || 'arm';
|
|
205
|
+
return new ArmValidationError('arm_schema_invalid', `${field}: ${issue?.message ?? 'invalid'}`);
|
|
206
|
+
}
|
|
207
|
+
function parsedArm(value) {
|
|
208
|
+
try {
|
|
209
|
+
return armSchema.parse(value);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
throw schemaFailure(error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
export function validateArmResolutionShape(value) {
|
|
216
|
+
try {
|
|
217
|
+
armResolutionSchema.parse(value);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
throw schemaFailure(error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export function parseArmDefinitionForCompiler(value) {
|
|
224
|
+
const arm = parsedArm(value);
|
|
225
|
+
validateLimitRanges(arm.limits);
|
|
226
|
+
validateCrossFields(arm);
|
|
227
|
+
return arm;
|
|
228
|
+
}
|
|
229
|
+
export function validateArmPostCredential(arm) {
|
|
230
|
+
validatePiBaselineProvider(arm);
|
|
231
|
+
}
|
|
232
|
+
export function parseArmDefinition(value) {
|
|
233
|
+
const arm = parseArmDefinitionForCompiler(value);
|
|
234
|
+
validateArmPostCredential(arm);
|
|
235
|
+
return arm;
|
|
236
|
+
}
|
|
237
|
+
export function parseArmDefinitionSet(values) {
|
|
238
|
+
const arms = values.map(parseArmDefinition);
|
|
239
|
+
const names = new Set(arms.map(arm => arm.name));
|
|
240
|
+
if (names.size !== arms.length)
|
|
241
|
+
fail('arm_schema_invalid', 'arm names must be unique');
|
|
242
|
+
return arms;
|
|
243
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ArmDefinition } from './arm-schema.js';
|
|
2
|
+
export type BenchmarkBrokerCapability = 'task.read' | 'task.create' | 'task.decompose' | 'task.claim' | 'task.propose_complete' | 'task.propose_block' | 'artifact.write' | 'dependency.declare' | 'qa.ask' | 'qa.answer';
|
|
3
|
+
export declare function childTemplateWhitelistForArm(arm: ArmDefinition): string[];
|
|
4
|
+
export declare function capabilityWhitelistForArm(arm: ArmDefinition): BenchmarkBrokerCapability[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// input: validated benchmark arm orchestration
|
|
2
|
+
// output: closed child-template and broker capability lists
|
|
3
|
+
// pos: Compile-time admission whitelist derivation
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
|
+
const CODER_REVIEW_CAPABILITIES = [
|
|
6
|
+
'artifact.write', 'task.read',
|
|
7
|
+
];
|
|
8
|
+
const MANAGER_CAPABILITIES = [
|
|
9
|
+
'artifact.write',
|
|
10
|
+
'dependency.declare',
|
|
11
|
+
'task.claim',
|
|
12
|
+
'task.create',
|
|
13
|
+
'task.decompose',
|
|
14
|
+
'task.propose_block',
|
|
15
|
+
'task.propose_complete',
|
|
16
|
+
'task.read',
|
|
17
|
+
];
|
|
18
|
+
const CHILD_TEMPLATES_BY_MODE = {
|
|
19
|
+
direct: [],
|
|
20
|
+
manager: ['benchmark-coder-review', 'benchmark-manager'],
|
|
21
|
+
};
|
|
22
|
+
const CODER_TEMPLATE_BY_VARIANT = {
|
|
23
|
+
'audit-retry': 'benchmark-coder-review',
|
|
24
|
+
'reviewer-fix': 'benchmark-coder-review-fix',
|
|
25
|
+
};
|
|
26
|
+
const CAPABILITIES_BY_MODE = {
|
|
27
|
+
direct: [],
|
|
28
|
+
'coder-review': CODER_REVIEW_CAPABILITIES,
|
|
29
|
+
manager: MANAGER_CAPABILITIES,
|
|
30
|
+
};
|
|
31
|
+
function sorted(values) {
|
|
32
|
+
return [...values].sort();
|
|
33
|
+
}
|
|
34
|
+
export function childTemplateWhitelistForArm(arm) {
|
|
35
|
+
if (arm.kind !== 'cortex')
|
|
36
|
+
return [];
|
|
37
|
+
const orchestration = arm.orchestration;
|
|
38
|
+
if (orchestration.mode === 'coder-review') {
|
|
39
|
+
return [CODER_TEMPLATE_BY_VARIANT[orchestration.coder_review_variant]];
|
|
40
|
+
}
|
|
41
|
+
return [...CHILD_TEMPLATES_BY_MODE[orchestration.mode]];
|
|
42
|
+
}
|
|
43
|
+
export function capabilityWhitelistForArm(arm) {
|
|
44
|
+
if (arm.kind !== 'cortex')
|
|
45
|
+
return [];
|
|
46
|
+
const orchestration = arm.orchestration;
|
|
47
|
+
const capabilities = [
|
|
48
|
+
...CAPABILITIES_BY_MODE[orchestration.mode],
|
|
49
|
+
];
|
|
50
|
+
if (orchestration.mode === 'manager' && orchestration.ask_manager) {
|
|
51
|
+
capabilities.push('qa.ask', 'qa.answer');
|
|
52
|
+
}
|
|
53
|
+
return sorted(capabilities);
|
|
54
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A decimal as an exact integer of `units` scaled by 10^-`scale`. Costs are compared across a
|
|
3
|
+
* language boundary, so a binary float would make the comparison depend on representation: two
|
|
4
|
+
* sides that agree on the value could disagree on the bytes. BigInt units never do.
|
|
5
|
+
*/
|
|
6
|
+
export interface DecimalValue {
|
|
7
|
+
readonly units: bigint;
|
|
8
|
+
readonly scale: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class DecimalTextError extends Error {
|
|
11
|
+
constructor(text: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function isDecimalText(text: unknown): text is string;
|
|
14
|
+
export declare function parseDecimal(text: string): DecimalValue;
|
|
15
|
+
/** Renders with trailing fraction zeros stripped, matching the proxy's own decimal serialiser. */
|
|
16
|
+
export declare function decimalText(value: DecimalValue): string;
|
|
17
|
+
export declare function subtractDecimal(left: DecimalValue, right: DecimalValue): DecimalValue;
|
|
18
|
+
export declare function multiplyDecimal(left: DecimalValue, right: DecimalValue): DecimalValue;
|
|
19
|
+
export declare function compareDecimal(left: DecimalValue, right: DecimalValue): number;
|
|
20
|
+
export declare function absDecimal(value: DecimalValue): DecimalValue;
|
|
21
|
+
export declare function maxDecimal(left: DecimalValue, right: DecimalValue): DecimalValue;
|
|
22
|
+
/**
|
|
23
|
+
* The one lossy step in the pipeline, isolated here on purpose: a journal cost arrives as a
|
|
24
|
+
* JavaScript number and its shortest round-tripping decimal is the most that value can honestly
|
|
25
|
+
* claim. Everything downstream of this call is exact.
|
|
26
|
+
*/
|
|
27
|
+
export declare function decimalFromNumber(value: number): DecimalValue;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// input: decimal strings from the proxy export and the journal cost boundary
|
|
2
|
+
// output: exact parse, render, compare and arithmetic over BigInt scaled units
|
|
3
|
+
// pos: Exact decimal arithmetic for cost reconciliation
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
|
+
const DECIMAL_PATTERN = /^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/;
|
|
6
|
+
export class DecimalTextError extends Error {
|
|
7
|
+
constructor(text) {
|
|
8
|
+
super(`not a decimal string: ${text}`);
|
|
9
|
+
this.name = 'DecimalTextError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function isDecimalText(text) {
|
|
13
|
+
return typeof text === 'string' && DECIMAL_PATTERN.test(text);
|
|
14
|
+
}
|
|
15
|
+
export function parseDecimal(text) {
|
|
16
|
+
if (!isDecimalText(text))
|
|
17
|
+
throw new DecimalTextError(String(text));
|
|
18
|
+
const [mantissa, exponent] = text.split(/[eE]/);
|
|
19
|
+
const [whole, fraction = ''] = mantissa.replace(/^[+-]/, '').split('.');
|
|
20
|
+
const units = BigInt(`${whole}${fraction}`) * (text.startsWith('-') ? -1n : 1n);
|
|
21
|
+
return rescale({ units, scale: fraction.length - Number(exponent ?? 0) });
|
|
22
|
+
}
|
|
23
|
+
/** Renders with trailing fraction zeros stripped, matching the proxy's own decimal serialiser. */
|
|
24
|
+
export function decimalText(value) {
|
|
25
|
+
const negative = value.units < 0n;
|
|
26
|
+
const digits = (negative ? -value.units : value.units).toString().padStart(value.scale + 1, '0');
|
|
27
|
+
const point = digits.length - value.scale;
|
|
28
|
+
const fraction = value.scale > 0 ? digits.slice(point).replace(/0+$/, '') : '';
|
|
29
|
+
const text = fraction ? `${digits.slice(0, point)}.${fraction}` : digits.slice(0, point);
|
|
30
|
+
return negative && value.units !== 0n ? `-${text}` : text;
|
|
31
|
+
}
|
|
32
|
+
export function subtractDecimal(left, right) {
|
|
33
|
+
const scale = Math.max(left.scale, right.scale);
|
|
34
|
+
return { units: atScale(left, scale) - atScale(right, scale), scale };
|
|
35
|
+
}
|
|
36
|
+
export function multiplyDecimal(left, right) {
|
|
37
|
+
return { units: left.units * right.units, scale: left.scale + right.scale };
|
|
38
|
+
}
|
|
39
|
+
export function compareDecimal(left, right) {
|
|
40
|
+
const scale = Math.max(left.scale, right.scale);
|
|
41
|
+
const difference = atScale(left, scale) - atScale(right, scale);
|
|
42
|
+
return difference === 0n ? 0 : Number(difference > 0n) * 2 - 1;
|
|
43
|
+
}
|
|
44
|
+
export function absDecimal(value) {
|
|
45
|
+
return value.units < 0n ? { units: -value.units, scale: value.scale } : value;
|
|
46
|
+
}
|
|
47
|
+
export function maxDecimal(left, right) {
|
|
48
|
+
return compareDecimal(left, right) >= 0 ? left : right;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The one lossy step in the pipeline, isolated here on purpose: a journal cost arrives as a
|
|
52
|
+
* JavaScript number and its shortest round-tripping decimal is the most that value can honestly
|
|
53
|
+
* claim. Everything downstream of this call is exact.
|
|
54
|
+
*/
|
|
55
|
+
export function decimalFromNumber(value) {
|
|
56
|
+
if (!Number.isFinite(value))
|
|
57
|
+
throw new DecimalTextError(String(value));
|
|
58
|
+
return parseDecimal(String(value));
|
|
59
|
+
}
|
|
60
|
+
function rescale(value) {
|
|
61
|
+
if (value.scale >= 0)
|
|
62
|
+
return value;
|
|
63
|
+
return { units: value.units * 10n ** BigInt(-value.scale), scale: 0 };
|
|
64
|
+
}
|
|
65
|
+
function atScale(value, scale) {
|
|
66
|
+
return value.units * 10n ** BigInt(scale - value.scale);
|
|
67
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ResolvedTrialPolicy } from './resolved-policy.js';
|
|
2
|
+
export declare const LEASE_ECHO_SCHEMA_VERSION = "cortex-bench-lease-echo/1";
|
|
3
|
+
export declare const LEASE_ECHO_PATH = "/_cortex/lease-echo";
|
|
4
|
+
/**
|
|
5
|
+
* Everything here is read on a container clock: the two instants come from the frozen policy's own
|
|
6
|
+
* compile-time wall-clock reads, and the remaining budget from the monotonic clock. No host instant
|
|
7
|
+
* is read, and none is sent — only durations may cross to the host, because a duration is a
|
|
8
|
+
* difference of two readings of one clock and so survives any offset between the two clocks.
|
|
9
|
+
*/
|
|
10
|
+
export interface LeaseEchoDocument {
|
|
11
|
+
schema_version: typeof LEASE_ECHO_SCHEMA_VERSION;
|
|
12
|
+
trial_id: string;
|
|
13
|
+
compiled_at_epoch_ms: number;
|
|
14
|
+
absolute_epoch_ms: number;
|
|
15
|
+
remaining_ms: number;
|
|
16
|
+
}
|
|
17
|
+
export interface LeaseEchoResult {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
lease_state: 'reconciled' | 'clamped';
|
|
20
|
+
armed_remaining_ms: number;
|
|
21
|
+
}
|
|
22
|
+
export interface LeaseEchoTransportResponse {
|
|
23
|
+
status: number;
|
|
24
|
+
body: string;
|
|
25
|
+
}
|
|
26
|
+
export interface LeaseEchoDependencies {
|
|
27
|
+
monotonic_ns(): bigint;
|
|
28
|
+
post?(url: string, headers: Record<string, string>, body: string): Promise<LeaseEchoTransportResponse>;
|
|
29
|
+
}
|
|
30
|
+
export declare class LeaseEchoRefused extends Error {
|
|
31
|
+
readonly status: number;
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
constructor(status: number, reason: string);
|
|
34
|
+
}
|
|
35
|
+
export declare function composeLeaseEcho(policy: ResolvedTrialPolicy, monotonicNowNs: bigint): LeaseEchoDocument;
|
|
36
|
+
export declare function leaseEchoUrl(proxyBaseUrl: string): string;
|
|
37
|
+
/** The echo runs before the model process is admitted, so it may not stall the trial's startup. */
|
|
38
|
+
export declare const LEASE_ECHO_TIMEOUT_MS = 10000;
|
|
39
|
+
/**
|
|
40
|
+
* Publish the echo to the trial's own proxy. The route authenticates it exactly as it authenticates
|
|
41
|
+
* a model call, so the container presents the same dummy bearer it presents there.
|
|
42
|
+
*/
|
|
43
|
+
export declare function publishLeaseEcho(policy: ResolvedTrialPolicy, deps: LeaseEchoDependencies): Promise<LeaseEchoResult>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// input: the frozen phase-B policy and the container's monotonic clock
|
|
2
|
+
// output: the lease-echo document and its delivery to the per-trial proxy's control route
|
|
3
|
+
// pos: Container-side credential-lease echo writer
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
|
+
import { remainingDeadlineMs } from './resolved-policy.js';
|
|
6
|
+
export const LEASE_ECHO_SCHEMA_VERSION = 'cortex-bench-lease-echo/1';
|
|
7
|
+
export const LEASE_ECHO_PATH = '/_cortex/lease-echo';
|
|
8
|
+
export class LeaseEchoRefused extends Error {
|
|
9
|
+
status;
|
|
10
|
+
reason;
|
|
11
|
+
constructor(status, reason) {
|
|
12
|
+
super(`lease echo refused: ${status} ${reason}`);
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.reason = reason;
|
|
15
|
+
this.name = 'LeaseEchoRefused';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function composeLeaseEcho(policy, monotonicNowNs) {
|
|
19
|
+
return {
|
|
20
|
+
schema_version: LEASE_ECHO_SCHEMA_VERSION,
|
|
21
|
+
trial_id: policy.trial_id,
|
|
22
|
+
compiled_at_epoch_ms: policy.deadline.compiled_at_epoch_ms,
|
|
23
|
+
absolute_epoch_ms: policy.deadline.absolute_epoch_ms,
|
|
24
|
+
remaining_ms: remainingDeadlineMs(policy, monotonicNowNs),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function leaseEchoUrl(proxyBaseUrl) {
|
|
28
|
+
return `${proxyBaseUrl.replace(/\/+$/, '')}${LEASE_ECHO_PATH}`;
|
|
29
|
+
}
|
|
30
|
+
/** The echo runs before the model process is admitted, so it may not stall the trial's startup. */
|
|
31
|
+
export const LEASE_ECHO_TIMEOUT_MS = 10_000;
|
|
32
|
+
async function fetchTransport(url, headers, body) {
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
method: 'POST', headers, body, signal: AbortSignal.timeout(LEASE_ECHO_TIMEOUT_MS),
|
|
35
|
+
});
|
|
36
|
+
return { status: response.status, body: await response.text() };
|
|
37
|
+
}
|
|
38
|
+
function parseResult(response) {
|
|
39
|
+
const document = JSON.parse(response.body);
|
|
40
|
+
if (response.status !== 200) {
|
|
41
|
+
throw new LeaseEchoRefused(response.status, document.error ?? 'lease_echo_refused');
|
|
42
|
+
}
|
|
43
|
+
return document;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Publish the echo to the trial's own proxy. The route authenticates it exactly as it authenticates
|
|
47
|
+
* a model call, so the container presents the same dummy bearer it presents there.
|
|
48
|
+
*/
|
|
49
|
+
export async function publishLeaseEcho(policy, deps) {
|
|
50
|
+
const document = composeLeaseEcho(policy, deps.monotonic_ns());
|
|
51
|
+
const response = await (deps.post ?? fetchTransport)(leaseEchoUrl(policy.credential.proxy_base_url), {
|
|
52
|
+
'content-type': 'application/json',
|
|
53
|
+
authorization: `Bearer ${policy.credential.dummy_token_ref}`,
|
|
54
|
+
}, JSON.stringify(document));
|
|
55
|
+
return parseResult(response);
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentDefinition, AgentSlotConfig, ThreadTemplate } from '../../core/types/thread-types.js';
|
|
2
|
+
import type { ResolvedProfileConfig } from '../agents/profile-manager.js';
|
|
3
|
+
import type { LocalThreadRuntimeDeps } from '../threads/local-runtime-deps.js';
|
|
4
|
+
import { type FailureStderr, type ResolvedTrialPolicy } from './resolved-policy.js';
|
|
5
|
+
export interface PolicyRuntimeSnapshot {
|
|
6
|
+
profileName: string;
|
|
7
|
+
profile: ResolvedProfileConfig;
|
|
8
|
+
agents: Record<string, AgentDefinition>;
|
|
9
|
+
templates: Record<string, ThreadTemplate>;
|
|
10
|
+
templateAgents: Record<string, AgentSlotConfig[]>;
|
|
11
|
+
}
|
|
12
|
+
type ResolutionDeps = Pick<LocalThreadRuntimeDeps, 'resolveProfile' | 'loadTemplates' | 'getTemplate' | 'resolveTemplateAgents'>;
|
|
13
|
+
export declare function createPolicyBackedResolutionDeps(policy: ResolvedTrialPolicy, snapshot: PolicyRuntimeSnapshot, stderr?: FailureStderr): ResolutionDeps;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// input: frozen trial policy and compile-time runtime snapshots
|
|
2
|
+
// output: policy-backed profile and template resolver dependencies
|
|
3
|
+
// pos: Prevents watched benchmark assets from runtime re-resolution
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
|
+
import { PolicyCompilationError, reportBenchmarkFailure, } from './resolved-policy.js';
|
|
6
|
+
function freezeValue(value) {
|
|
7
|
+
if (value === null || typeof value !== 'object')
|
|
8
|
+
return;
|
|
9
|
+
for (const child of Object.values(value))
|
|
10
|
+
freezeValue(child);
|
|
11
|
+
Object.freeze(value);
|
|
12
|
+
}
|
|
13
|
+
function frozenSnapshot(snapshot) {
|
|
14
|
+
const clone = structuredClone(snapshot);
|
|
15
|
+
freezeValue(clone);
|
|
16
|
+
return clone;
|
|
17
|
+
}
|
|
18
|
+
function reject(kind, name, stderr) {
|
|
19
|
+
const error = new PolicyCompilationError('policy_reresolution_attempted', `${kind}:${name}`);
|
|
20
|
+
reportBenchmarkFailure(error, stderr);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
function closedSnapshot(snapshot, allowedTemplates) {
|
|
24
|
+
const templates = Object.fromEntries(Object.entries(snapshot.templates).filter(([name]) => allowedTemplates.has(name)));
|
|
25
|
+
const templateAgents = Object.fromEntries(Object.entries(snapshot.templateAgents).filter(([name]) => allowedTemplates.has(name)));
|
|
26
|
+
const slots = new Set(Object.values(templateAgents).flat().map(agent => agent.slotId));
|
|
27
|
+
const agents = Object.fromEntries(Object.entries(snapshot.agents).filter(([name]) => slots.has(name)));
|
|
28
|
+
const closed = { agents, templates, templateAgents };
|
|
29
|
+
freezeValue(closed);
|
|
30
|
+
return closed;
|
|
31
|
+
}
|
|
32
|
+
export function createPolicyBackedResolutionDeps(policy, snapshot, stderr) {
|
|
33
|
+
const frozen = frozenSnapshot(snapshot);
|
|
34
|
+
const allowedTemplates = new Set(policy.child_template_whitelist);
|
|
35
|
+
const closed = closedSnapshot(frozen, allowedTemplates);
|
|
36
|
+
const getTemplate = (name) => {
|
|
37
|
+
const template = closed.templates[name];
|
|
38
|
+
return template ?? reject('template', name, stderr);
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
resolveProfile: name => (name === frozen.profileName ? frozen.profile : reject('profile', name, stderr)),
|
|
42
|
+
loadTemplates: () => ({ agents: closed.agents, templates: closed.templates }),
|
|
43
|
+
getTemplate,
|
|
44
|
+
resolveTemplateAgents: template => (closed.templateAgents[getTemplate(template.name).name]
|
|
45
|
+
?? reject('template-agents', template.name, stderr)),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { McpComposition } from '../../agent-adapter/types.js';
|
|
2
|
+
import type { ResolvedProfileConfig } from '../agents/profile-manager.js';
|
|
3
|
+
import { type IdentityJsonValue } from '../agent-run/identity.js';
|
|
4
|
+
import { ARM_RESOLUTION_SCHEMA_VERSION } from './arm-schema.js';
|
|
5
|
+
import { type CredentialCapabilityState, type FailureStderr, type ResolvedTrialPolicy } from './resolved-policy.js';
|
|
6
|
+
export { PolicyCompilationError } from './resolved-policy.js';
|
|
7
|
+
export interface CredentialCapabilityProjection {
|
|
8
|
+
id: string;
|
|
9
|
+
state: CredentialCapabilityState;
|
|
10
|
+
key: {
|
|
11
|
+
runner_or_backend: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
protocol: string;
|
|
14
|
+
credential_kind: string;
|
|
15
|
+
proxy_adapter_version: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface ResolvedRoleAsset {
|
|
19
|
+
system_prompt_path: string;
|
|
20
|
+
directive_path: string;
|
|
21
|
+
tools: string[];
|
|
22
|
+
plugin_dirs: string[];
|
|
23
|
+
mcp_composition: McpComposition;
|
|
24
|
+
mcp_config_paths: string[];
|
|
25
|
+
disable_hooks: true;
|
|
26
|
+
}
|
|
27
|
+
export interface ArmResolution {
|
|
28
|
+
schema_version: typeof ARM_RESOLUTION_SCHEMA_VERSION;
|
|
29
|
+
arm: unknown;
|
|
30
|
+
arm_path: string;
|
|
31
|
+
trial_id: string;
|
|
32
|
+
root_run_id: string;
|
|
33
|
+
task: {
|
|
34
|
+
task_id: string;
|
|
35
|
+
image_ref: string;
|
|
36
|
+
image_digest: string;
|
|
37
|
+
};
|
|
38
|
+
profile_name: string;
|
|
39
|
+
paid_run: boolean;
|
|
40
|
+
credential_capabilities: CredentialCapabilityProjection[];
|
|
41
|
+
credential: {
|
|
42
|
+
upstream_base_url: string;
|
|
43
|
+
route_identity_host: string;
|
|
44
|
+
proxy_base_url: string;
|
|
45
|
+
dummy_token_ref: string;
|
|
46
|
+
};
|
|
47
|
+
cli_artifact: {
|
|
48
|
+
path: string;
|
|
49
|
+
version: string;
|
|
50
|
+
};
|
|
51
|
+
model_alias_policy: IdentityJsonValue;
|
|
52
|
+
roles: Record<string, ResolvedRoleAsset>;
|
|
53
|
+
thread_templates: Record<string, string>;
|
|
54
|
+
thread_agents: Record<string, string>;
|
|
55
|
+
artifact_inventory_spec: IdentityJsonValue;
|
|
56
|
+
expected_asset_hashes?: Record<string, string>;
|
|
57
|
+
pi_benchmark_capability_proven?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface PolicyCompilerDependencies {
|
|
60
|
+
wall_clock_ms(): number;
|
|
61
|
+
monotonic_ns(): bigint;
|
|
62
|
+
resolve_profile(name: string): ResolvedProfileConfig;
|
|
63
|
+
read_file?(file: string): Buffer;
|
|
64
|
+
stderr?: FailureStderr;
|
|
65
|
+
}
|
|
66
|
+
export declare function compileResolvedTrialPolicy(input: ArmResolution, deps: PolicyCompilerDependencies): ResolvedTrialPolicy;
|
|
67
|
+
export declare function rejectPolicyReresolution(kind: string, name: string, stderr?: FailureStderr): never;
|
|
68
|
+
export declare function projectAgentRunConfig(policy: ResolvedTrialPolicy, slot: string, baseDirectory?: string): IdentityJsonValue;
|