@aiwg/cli 2026.10.5 → 2026.10.7
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/agentic/code/addons/composition-engine/lib/runtime.mjs +1401 -0
- package/agentic/code/addons/composition-engine/lib/validator.mjs +513 -0
- package/agentic/code/addons/composition-engine/schemas/flow-graph.schema.json +372 -0
- package/agentic/code/providers/model-capabilities.v1.json +74 -50
- package/bin/aiwg.mjs +7 -3
- package/dist/src/a2a/agent-card.js +11 -0
- package/dist/src/api/index.d.ts +1 -0
- package/dist/src/api/index.js +1 -0
- package/dist/src/artifacts/browser-export.js +1 -0
- package/dist/src/artifacts/citation-parser.js +8 -1
- package/dist/src/artifacts/cli.js +57 -6
- package/dist/src/artifacts/fortemi-core-query-adapter.js +2 -0
- package/dist/src/artifacts/fortemi-core-sync.js +26 -8
- package/dist/src/artifacts/fortemi-shard-contract/2.2.0/contract.json +103 -0
- package/dist/src/artifacts/fortemi-shard-contract/2.2.0/full-v1-embedding-config.schema.json +212 -0
- package/dist/src/artifacts/fortemi-shard-contract/2.2.0/full-v1-embedding-set.schema.json +240 -0
- package/dist/src/artifacts/fortemi-shard-contract/2.2.0/full-v1-manifest.schema.json +451 -0
- package/dist/src/artifacts/fortemi-shard-export.js +284 -0
- package/dist/src/artifacts/graph-query.js +18 -8
- package/dist/src/artifacts/index-adapters.js +339 -0
- package/dist/src/artifacts/index-builder.js +143 -14
- package/dist/src/artifacts/index-files.js +15 -4
- package/dist/src/artifacts/index-preparation.js +2 -0
- package/dist/src/artifacts/index-reader.js +44 -0
- package/dist/src/artifacts/index-refresh.js +114 -55
- package/dist/src/artifacts/index-status.js +20 -5
- package/dist/src/artifacts/memory-maintenance.js +503 -0
- package/dist/src/artifacts/prebuilt-relations.js +3 -1
- package/dist/src/artifacts/query-engine.js +263 -108
- package/dist/src/artifacts/relations-builder.js +2 -2
- package/dist/src/artifacts/source-graph.js +2 -2
- package/dist/src/artifacts/types.js +9 -1
- package/dist/src/auth/client.js +5 -1
- package/dist/src/auth/credential-store.js +5 -1
- package/dist/src/auth/sensitive-input.js +151 -0
- package/dist/src/channel/manager.mjs +3 -0
- package/dist/src/cli/handlers/agentcard.js +47 -25
- package/dist/src/cli/handlers/auth.js +22 -2
- package/dist/src/cli/handlers/decision.js +22 -3
- package/dist/src/cli/handlers/effect.js +4 -84
- package/dist/src/cli/handlers/guided-setup.js +470 -0
- package/dist/src/cli/handlers/help.js +2 -2
- package/dist/src/cli/handlers/housekeeper.js +1110 -0
- package/dist/src/cli/handlers/index.js +4 -2
- package/dist/src/cli/handlers/init.js +41 -6
- package/dist/src/cli/handlers/install.js +6 -0
- package/dist/src/cli/handlers/local-executor.js +5 -3
- package/dist/src/cli/handlers/marketplace.js +15 -4
- package/dist/src/cli/handlers/mc.js +509 -53
- package/dist/src/cli/handlers/models.js +32 -2
- package/dist/src/cli/handlers/ralph-launcher.js +76 -4
- package/dist/src/cli/handlers/rules.js +1 -1
- package/dist/src/cli/handlers/script-runner.js +73 -2
- package/dist/src/cli/handlers/serve.js +5 -3
- package/dist/src/cli/handlers/sessions.js +1 -0
- package/dist/src/cli/handlers/setup.js +432 -1
- package/dist/src/cli/handlers/skill-lint.js +1 -1
- package/dist/src/cli/handlers/subcommands.js +118 -8
- package/dist/src/cli/handlers/use.js +335 -107
- package/dist/src/cli/handlers/workspace.js +3 -1
- package/dist/src/cli/prompt-utils.js +81 -0
- package/dist/src/cli/router.js +16 -1
- package/dist/src/config/aiwg-config.js +42 -0
- package/dist/src/config/cli.js +7 -3
- package/dist/src/config/decision-config.js +14 -1
- package/dist/src/config/gitignore.js +4 -0
- package/dist/src/config/native-sandbox-warnings.js +25 -0
- package/dist/src/config/workspace.js +2 -1
- package/dist/src/contributors/validation.js +6 -5
- package/dist/src/decision/adapters/jev.js +20 -31
- package/dist/src/decision/admission.js +7 -3
- package/dist/src/decision/ask.js +6 -1
- package/dist/src/decision/benchmark.js +482 -0
- package/dist/src/decision/ledger.js +22 -3
- package/dist/src/decision/pricing.js +147 -0
- package/dist/src/decision/qualification/gate-evidence.js +23 -18
- package/dist/src/decision/qualification/load-staged.js +576 -0
- package/dist/src/decision/qualification/load.js +109 -33
- package/dist/src/decision/qualification/runner.js +12 -5
- package/dist/src/decision/review/service.js +6 -4
- package/dist/src/decision/review/validate.js +23 -2
- package/dist/src/decision/savings.js +8 -3
- package/dist/src/discovery/index.js +492 -0
- package/dist/src/discovery/interview.js +238 -0
- package/dist/src/discovery/plan-apply.js +567 -0
- package/dist/src/discovery/plan-store.js +171 -0
- package/dist/src/discovery/plan-types.js +2 -0
- package/dist/src/discovery/plan-validation.js +139 -0
- package/dist/src/discovery/types.js +2 -0
- package/dist/src/effects/host.js +91 -0
- package/dist/src/extensions/commands/definitions.js +49 -9
- package/dist/src/extensions/manifest.js +71 -44
- package/dist/src/extensions/project-local-discovery.js +1 -1
- package/dist/src/extensions/project-local-gitignore.js +2 -0
- package/dist/src/extensions/project-quickref.js +18 -17
- package/dist/src/extensions/validation.js +32 -29
- package/dist/src/housekeeper/daemon-config.js +148 -0
- package/dist/src/housekeeper/ipc.js +84 -0
- package/dist/src/housekeeper/lifecycle.js +148 -0
- package/dist/src/housekeeper/platform.js +35 -0
- package/dist/src/housekeeper/status.js +70 -0
- package/dist/src/housekeeper/units.js +114 -0
- package/dist/src/issues/cli.js +16 -5
- package/dist/src/issues/live.js +44 -12
- package/dist/src/jobs/flow.js +22 -21
- package/dist/src/lint/rule-activation.js +20 -5
- package/dist/src/lint/runner.js +1 -1
- package/dist/src/marketplace/exchange.js +18 -6
- package/dist/src/marketplace/provenance.js +3 -2
- package/dist/src/mcp/adapters/codex-runtime.js +46 -76
- package/dist/src/mcp/cli.mjs +22 -96
- package/dist/src/mcp/config-file.mjs +6 -2
- package/dist/src/mcp/config-layers.mjs +23 -7
- package/dist/src/mcp/grok-build-config.mjs +2 -1
- package/dist/src/mcp/muse-native-config.mjs +2 -1
- package/dist/src/mcp/profiles.js +18 -31
- package/dist/src/mcp/profiles.mjs +18 -32
- package/dist/src/mcp/registry.js +7 -27
- package/dist/src/mcp/registry.mjs +7 -28
- package/dist/src/mcp/server.mjs +34 -1
- package/dist/src/mcp/tools/agentic-sandbox.mjs +8 -7
- package/dist/src/mcp/tools/command-run.mjs +3 -2
- package/dist/src/mcp/tools/decision.mjs +49 -48
- package/dist/src/mcp/tools/discovery.mjs +46 -21
- package/dist/src/mcp/tools/orchestration.mjs +22 -22
- package/dist/src/mcp/tools/subsystems.mjs +9 -8
- package/dist/src/mcp/tools/worker-invoke.mjs +30 -6
- package/dist/src/mcp/tools/writer-profiles.mjs +1 -1
- package/dist/src/memory/audit.js +719 -0
- package/dist/src/memory/canonical-context.js +392 -13
- package/dist/src/memory/canonical-maintenance.js +95 -0
- package/dist/src/memory/cli-result.js +22 -0
- package/dist/src/memory/cli.js +176 -0
- package/dist/src/memory/context-pack.js +57 -6
- package/dist/src/memory/cost.js +512 -0
- package/dist/src/memory/firewall-classification.d.mts +7 -0
- package/dist/src/memory/firewall-classification.mjs +32 -0
- package/dist/src/memory/index.js +8 -0
- package/dist/src/memory/line-maintenance.js +68 -0
- package/dist/src/memory/maintenance-cli.js +286 -0
- package/dist/src/memory/maintenance-contract.js +136 -0
- package/dist/src/memory/maintenance-index.js +18 -0
- package/dist/src/memory/maintenance-owner.js +2 -0
- package/dist/src/memory/maintenance-record.js +138 -0
- package/dist/src/memory/maintenance.js +254 -0
- package/dist/src/memory/project-registry.js +2 -1
- package/dist/src/memory/provider-memory-adapter.js +154 -0
- package/dist/src/memory/recommend-cli.js +83 -0
- package/dist/src/memory/recommend.js +269 -0
- package/dist/src/memory/scheduled.js +81 -0
- package/dist/src/memory/taxonomy.js +44 -0
- package/dist/src/mission-protocol/codecs.js +19 -9
- package/dist/src/mission-protocol/worker-status.js +91 -1
- package/dist/src/models/config-loader.js +11 -1
- package/dist/src/models/model-capabilities.v1.json +74 -50
- package/dist/src/models/provider-policy.js +125 -62
- package/dist/src/models/resolver.js +45 -8
- package/dist/src/models/worker-installation.d.mts +8 -1
- package/dist/src/models/worker-installation.mjs +231 -38
- package/dist/src/models/wrapper-route.js +1 -1
- package/dist/src/output-modes/registry.js +8 -7
- package/dist/src/packages/adapters/git.js +99 -23
- package/dist/src/packages/adapters/gitea.js +8 -27
- package/dist/src/packages/adapters/github.js +7 -25
- package/dist/src/packages/registry.js +4 -4
- package/dist/src/plugin/metadata-validator.js +1 -1
- package/dist/src/process/cli-command.d.mts +5 -0
- package/dist/src/process/cli-command.mjs +42 -0
- package/dist/src/providers/deploy-version.d.mts +1 -0
- package/dist/src/providers/deploy-version.mjs +17 -0
- package/dist/src/providers/provider-definitions.js +19 -16
- package/dist/src/providers/skill-ownership.d.mts +11 -2
- package/dist/src/providers/skill-ownership.mjs +35 -17
- package/dist/src/rules/activation.d.mts +11 -2
- package/dist/src/rules/activation.mjs +82 -6
- package/dist/src/rules/inventory.js +1 -1
- package/dist/src/rules/rule-frontmatter.schema.json +2 -0
- package/dist/src/schema/zod-validation.d.mts +6 -0
- package/dist/src/schema/zod-validation.mjs +50 -0
- package/dist/src/serve/executor-registry.js +297 -20
- package/dist/src/serve/executor-token.d.mts +1 -0
- package/dist/src/serve/executor-token.mjs +8 -0
- package/dist/src/serve/shared-host-scheduler.js +1102 -31
- package/dist/src/serve/worker-invocation.js +124 -15
- package/dist/src/sessions/adapters/claude.js +19 -18
- package/dist/src/sessions/adapters/codex.js +10 -9
- package/dist/src/sessions/adapters/copilot.js +14 -13
- package/dist/src/sessions/adapters/cursor.js +19 -18
- package/dist/src/sessions/adapters/deepseek-harness.js +9 -8
- package/dist/src/sessions/adapters/factory.js +11 -10
- package/dist/src/sessions/adapters/generic.js +32 -23
- package/dist/src/sessions/adapters/grokbot.js +35 -35
- package/dist/src/sessions/adapters/hermes.js +20 -19
- package/dist/src/sessions/adapters/muse.js +50 -49
- package/dist/src/sessions/adapters/omp.js +5 -4
- package/dist/src/sessions/adapters/openclaw.js +30 -29
- package/dist/src/sessions/adapters/opencode.js +26 -26
- package/dist/src/sessions/adapters/openhuman.js +24 -23
- package/dist/src/sessions/adapters/pi.js +5 -4
- package/dist/src/sessions/adapters/windsurf.js +8 -8
- package/dist/src/sessions/analytics.js +10 -9
- package/dist/src/sessions/candidates.js +7 -6
- package/dist/src/sessions/contracts.js +63 -53
- package/dist/src/sessions/output-registration.js +11 -10
- package/dist/src/sessions/workspace-discovery.js +3 -4
- package/dist/src/smiths/context-pipeline/aiwg-md.js +18 -1
- package/dist/src/smiths/context-pipeline/claude-hook.js +46 -10
- package/dist/src/smiths/context-pipeline/context-file-safety.js +330 -9
- package/dist/src/smiths/context-pipeline/finalization.js +3 -2
- package/dist/src/smiths/context-pipeline/generator.js +7 -19
- package/dist/src/smiths/context-pipeline/legacy-inject.js +3 -10
- package/dist/src/smiths/context-pipeline/managed-hook.js +5 -5
- package/dist/src/smiths/context-pipeline/parallelism-section.js +72 -5
- package/dist/src/smiths/context-pipeline/workspace-context.js +110 -22
- package/dist/src/tracker/project-inputs.js +2 -0
- package/dist/src/update/checker.d.mts +4 -0
- package/dist/src/update/checker.mjs +14 -0
- package/dist/src/update/notifier.mjs +2 -4
- package/dist/src/writing/exemplar-selection.js +6 -6
- package/dist/src/writing/voice-evaluation.js +24 -23
- package/dist/src/writing/writer-migration.js +14 -13
- package/dist/src/writing/writer-profile.js +19 -18
- package/dist/src/writing/writing-brief.js +18 -17
- package/dist/src/writing/writing-receipt.js +47 -46
- package/package.json +5 -2
- package/schemas/decision/DecisionReview.schema.json +78 -1
- package/schemas/mission-v1.schema.json +3 -0
- package/tools/agents/deploy-agents.mjs +67 -39
- package/tools/agents/providers/antigravity.mjs +6 -1
- package/tools/agents/providers/base.mjs +24 -14
- package/tools/agents/providers/claude.mjs +6 -3
- package/tools/agents/providers/codex.mjs +54 -57
- package/tools/agents/providers/context-write.mjs +28 -0
- package/tools/agents/providers/copilot.mjs +13 -4
- package/tools/agents/providers/cursor.mjs +1 -1
- package/tools/agents/providers/deepseek-harness.mjs +1 -1
- package/tools/agents/providers/factory.mjs +7 -1
- package/tools/agents/providers/grok-build.mjs +18 -2
- package/tools/agents/providers/grokbot.mjs +1 -1
- package/tools/agents/providers/hermes.mjs +12 -15
- package/tools/agents/providers/muse-hooks.mjs +21 -14
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/omp.mjs +31 -5
- package/tools/agents/providers/opencode.mjs +14 -5
- package/tools/agents/providers/openhuman.mjs +1 -1
- package/tools/agents/providers/pi.mjs +1 -1
- package/tools/agents/providers/provider-prepare-coordinator.mjs +29 -9
- package/tools/agents/providers/rule-delivery.mjs +289 -80
- package/tools/agents/providers/warp.mjs +4 -1
- package/tools/agents/providers/windsurf.mjs +13 -3
- package/tools/cli/workspace-status.mjs +5 -0
- package/tools/commands/deploy-prompts-codex.mjs +11 -8
- package/tools/ralph-external/lib/codex-adapter.mjs +6 -2
- package/tools/ralph-external/lib/consecutive-failure-circuit-breaker.mjs +26 -0
- package/tools/ralph-external/lib/launcher-recovery-evidence.mjs +7 -1
- package/tools/ralph-external/lib/muse-adapter.mjs +12 -2
- package/tools/ralph-external/lib/recovery-probe.mjs +14 -4
- package/tools/ralph-external/lib/worker-health.mjs +1 -1
- package/tools/ralph-external/lib/worker-isolation.mjs +65 -9
- package/tools/ralph-external/process-monitor.mjs +49 -8
- package/tools/ralph-external/session-launcher.mjs +405 -35
- package/tools/skills/deploy-skills-codex.mjs +11 -7
- package/vscode-extension/schemas/aiwg.config.v1.json +11 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { emptyConfig, readAiwgConfig, writeAiwgConfig } from '../config/aiwg-config.js';
|
|
2
|
+
import { decisionSavingsWeights } from './savings.js';
|
|
3
|
+
export const JEV_PRICING_SOURCE = 'https://docs.typesafe.ai/models.md';
|
|
4
|
+
export const BUNDLED_JEV_PRICING = {
|
|
5
|
+
schema: 'aiwg-decision-pricing/v1', source: JEV_PRICING_SOURCE,
|
|
6
|
+
checkedAt: '2026-10-18T00:00:00.000Z', currency: 'USD', endpointOrigin: 'https://api.typesafe.ai',
|
|
7
|
+
models: { 'jev-1.13.0': { inputPerMillionUsd: 0.042, outputPerMillionUsd: 0 },
|
|
8
|
+
'jev-1.14.0': { inputPerMillionUsd: 0.042, outputPerMillionUsd: 0 } },
|
|
9
|
+
};
|
|
10
|
+
const MAX_BYTES = 256 * 1024;
|
|
11
|
+
export function validTokenPrice(value) {
|
|
12
|
+
const p = value;
|
|
13
|
+
return !!p && [p.inputPerMillionUsd, p.outputPerMillionUsd, ...(p.cachedInputPerMillionUsd === undefined ? [] : [p.cachedInputPerMillionUsd])]
|
|
14
|
+
.every(n => typeof n === 'number' && Number.isFinite(n) && n >= 0 && n <= 1_000_000);
|
|
15
|
+
}
|
|
16
|
+
function validSnapshot(value) {
|
|
17
|
+
const p = value;
|
|
18
|
+
return !!p && p.schema === BUNDLED_JEV_PRICING.schema && p.source === JEV_PRICING_SOURCE && p.currency === 'USD'
|
|
19
|
+
&& p.endpointOrigin === BUNDLED_JEV_PRICING.endpointOrigin && Number.isFinite(Date.parse(p.checkedAt))
|
|
20
|
+
&& !!p.models && Object.keys(p.models).length > 0 && Object.entries(p.models).every(([id, price]) => /^jev-\d+\.\d+\.\d+$/.test(id) && validTokenPrice(price));
|
|
21
|
+
}
|
|
22
|
+
/** Parse only the official versioned-model table; never guess output billing or aliases. */
|
|
23
|
+
export function parseJevPricing(markdown, checkedAt = new Date().toISOString()) {
|
|
24
|
+
const rows = markdown.split('\n').filter(line => line.trim().startsWith('|')).map(line => line.split('|').slice(1, -1).map(cell => cell.trim()));
|
|
25
|
+
const ids = rows.find(row => row[0] === 'Model ID');
|
|
26
|
+
const prices = rows.find(row => row[0] === 'Price (per Btok / per Mtok)');
|
|
27
|
+
if (!ids || !prices || ids.length !== prices.length || !/Output tokens are free\./i.test(markdown))
|
|
28
|
+
throw new Error('Official Jev pricing format changed; keeping the prior snapshot.');
|
|
29
|
+
const models = {};
|
|
30
|
+
for (let i = 1; i < ids.length; i++) {
|
|
31
|
+
const id = /^`(jev-\d+\.\d+\.\d+)`$/.exec(ids[i])?.[1];
|
|
32
|
+
const price = /^\\?\$([\d.]+)\s*\/\s*\\?\$([\d.]+)$/.exec(prices[i]);
|
|
33
|
+
if (!id || !price || !Number.isFinite(Number(price[1])) || !Number.isFinite(Number(price[2])) || Math.abs(Number(price[1]) / 1000 - Number(price[2])) > 1e-10)
|
|
34
|
+
throw new Error('Invalid official Jev price table.');
|
|
35
|
+
if (models[id])
|
|
36
|
+
throw new Error('Duplicate Jev model in official price table.');
|
|
37
|
+
models[id] = { inputPerMillionUsd: Number(price[2]), outputPerMillionUsd: 0 };
|
|
38
|
+
}
|
|
39
|
+
const snapshot = { ...BUNDLED_JEV_PRICING, models, checkedAt };
|
|
40
|
+
if (!validSnapshot(snapshot))
|
|
41
|
+
throw new Error('Invalid Jev pricing snapshot.');
|
|
42
|
+
return snapshot;
|
|
43
|
+
}
|
|
44
|
+
/** Explicit public-document fetch only; no credentials, redirects, cache or model calls. */
|
|
45
|
+
async function fetchPricing(fetcher, now) {
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
let timeout;
|
|
48
|
+
const operation = async () => {
|
|
49
|
+
const response = await fetcher(JEV_PRICING_SOURCE, {
|
|
50
|
+
redirect: 'error', credentials: 'omit', signal: controller.signal, headers: { Accept: 'text/markdown' },
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok || !response.body)
|
|
53
|
+
throw new Error(`Jev pricing refresh failed (${response.status}).`);
|
|
54
|
+
const reader = response.body.getReader();
|
|
55
|
+
const chunks = [];
|
|
56
|
+
let size = 0;
|
|
57
|
+
try {
|
|
58
|
+
while (true) {
|
|
59
|
+
const chunk = await reader.read();
|
|
60
|
+
if (chunk.done)
|
|
61
|
+
break;
|
|
62
|
+
size += chunk.value.byteLength;
|
|
63
|
+
if (size > MAX_BYTES)
|
|
64
|
+
throw new Error('Jev pricing document exceeds limit.');
|
|
65
|
+
chunks.push(chunk.value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
void reader.cancel().catch(() => { });
|
|
70
|
+
}
|
|
71
|
+
return parseJevPricing(Buffer.concat(chunks).toString('utf8'), now.toISOString());
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
// Bound the entire body read, including injected fetchers which ignore abort.
|
|
75
|
+
return await Promise.race([operation(), new Promise((_, reject) => {
|
|
76
|
+
timeout = setTimeout(() => { controller.abort(); reject(new Error('Jev pricing refresh timed out.')); }, 5000);
|
|
77
|
+
})]);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The existing project config is the only persisted pricing system. */
|
|
84
|
+
export async function decisionPricing(options) {
|
|
85
|
+
if (!options.refresh && (options.offline || options.allowSnapshot || options.dryRun || options.model)) {
|
|
86
|
+
throw new Error('--offline, --allow-snapshot, --dry-run and --model require --refresh');
|
|
87
|
+
}
|
|
88
|
+
const config = (await readAiwgConfig(options.cwd)) ?? emptyConfig();
|
|
89
|
+
const before = config.decision?.ask?.cost ?? {};
|
|
90
|
+
if (!options.refresh) {
|
|
91
|
+
const weights = decisionSavingsWeights(config.decision?.ask);
|
|
92
|
+
return { refreshed: false, written: false, current: { llm_per_mtok: weights.llm_per_mtok, jev_per_mtok: weights.jev_per_mtok,
|
|
93
|
+
...before, source: before.source ?? 'manual', checked_at: before.checked_at ?? null, jev_model: before.jev_model ?? null }, sourceUrl: JEV_PRICING_SOURCE };
|
|
94
|
+
}
|
|
95
|
+
// Validate selection before starting any network operation.
|
|
96
|
+
const model = options.model ?? before.jev_model;
|
|
97
|
+
if (!model || !/^jev-\d+\.\d+\.\d+$/.test(model))
|
|
98
|
+
throw new Error('Refresh requires --model jev-X.Y.Z or a configured jev_model. Config unchanged.');
|
|
99
|
+
let snapshot;
|
|
100
|
+
let warning = null;
|
|
101
|
+
let source = 'typesafe-docs';
|
|
102
|
+
if (options.offline) {
|
|
103
|
+
snapshot = structuredClone(BUNDLED_JEV_PRICING);
|
|
104
|
+
source = 'typesafe-snapshot';
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
try {
|
|
108
|
+
snapshot = await fetchPricing(options.fetch ?? fetch, options.now ?? new Date());
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (!options.allowSnapshot)
|
|
112
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)} Config unchanged; use --allow-snapshot to permit the dated bundled snapshot.`);
|
|
113
|
+
snapshot = structuredClone(BUNDLED_JEV_PRICING);
|
|
114
|
+
source = 'typesafe-snapshot';
|
|
115
|
+
warning = error instanceof Error ? error.message : String(error);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Require an explicit or previously selected version rather than guessing latest.
|
|
119
|
+
const price = snapshot.models[model];
|
|
120
|
+
if (!price)
|
|
121
|
+
throw new Error(`No sourced rates for ${model}. Config unchanged.`);
|
|
122
|
+
const after = { ...before, jev_input_per_mtok: price.inputPerMillionUsd, jev_output_per_mtok: price.outputPerMillionUsd,
|
|
123
|
+
source, checked_at: snapshot.checkedAt.slice(0, 10), jev_model: model };
|
|
124
|
+
const diff = Object.entries(after).filter(([key, value]) => before[key] !== value)
|
|
125
|
+
.map(([key, value]) => ({ key: `decision.ask.cost.${key}`, before: before[key] ?? null, after: value }));
|
|
126
|
+
if (!options.dryRun) {
|
|
127
|
+
config.decision = { ...config.decision, ask: { ...config.decision?.ask, cost: after } };
|
|
128
|
+
await writeAiwgConfig(options.cwd, config);
|
|
129
|
+
}
|
|
130
|
+
return { refreshed: true, written: !options.dryRun, dryRun: !!options.dryRun, current: after, diff,
|
|
131
|
+
sourceUrl: snapshot.source, warning, snapshotDate: source === 'typesafe-snapshot' ? after.checked_at : null };
|
|
132
|
+
}
|
|
133
|
+
/** API-equivalent cost from complete billable usage. Missing cache billing stays unknown. */
|
|
134
|
+
export function tokenCost(usage, price) {
|
|
135
|
+
if (!validTokenPrice(price) || !usage || usage.inputTokens === null
|
|
136
|
+
|| (price.outputPerMillionUsd > 0 && usage.outputTokens === null))
|
|
137
|
+
return null;
|
|
138
|
+
if (![usage.inputTokens, usage.outputTokens ?? 0].every(n => Number.isSafeInteger(n) && n >= 0))
|
|
139
|
+
return null;
|
|
140
|
+
const cached = price.cachedInputPerMillionUsd === undefined ? 0 : usage.cachedInputTokens;
|
|
141
|
+
if (cached == null || !Number.isSafeInteger(cached) || cached < 0 || cached > usage.inputTokens)
|
|
142
|
+
return null;
|
|
143
|
+
return ((usage.inputTokens - cached) * price.inputPerMillionUsd
|
|
144
|
+
+ cached * (price.cachedInputPerMillionUsd ?? price.inputPerMillionUsd)
|
|
145
|
+
+ (usage.outputTokens ?? 0) * price.outputPerMillionUsd) / 1_000_000;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -4,6 +4,8 @@ import { matchEvidenceDigest } from '../../gates/stats/index.js';
|
|
|
4
4
|
import { CalibrationRegistry, calibrationArtifactDigest } from '../calibration/registry.js';
|
|
5
5
|
import { validateCaseInventory } from './manifest.js';
|
|
6
6
|
import { verifyQualificationSplits } from './quality.js';
|
|
7
|
+
import { DECISION_STAGED_LOAD_RESULT_VERSIONS, verifyDecisionStagedLoadRecord } from './load.js';
|
|
8
|
+
import { validateReviewEvaluation } from '../review/validate.js';
|
|
7
9
|
const range = (prefix, from, to) => Array.from({ length: to - from + 1 }, (_, index) => `${prefix}${String(from + index).padStart(2, '0')}`);
|
|
8
10
|
export const DECISION_GATE_SUITES = {
|
|
9
11
|
'contract-suite-complete': { gate: 'G0', caseIds: ['C36'], evidenceIds: [
|
|
@@ -32,7 +34,7 @@ export const DECISION_GATE_SUITES = {
|
|
|
32
34
|
export const GATE_ARTIFACT_SCHEMAS = {
|
|
33
35
|
'immutable-splits': 'decision-binary-benchmark-plan/v2',
|
|
34
36
|
'calibration-qualified': 'decision-calibration-artifact/v1',
|
|
35
|
-
'load-manifest-qualified': 'decision-load-result/
|
|
37
|
+
'load-manifest-qualified': 'decision-load-result/v2',
|
|
36
38
|
'review-decision-recorded': 'decision-qualification-review/v1',
|
|
37
39
|
};
|
|
38
40
|
export const GATE_ARTIFACT_FLAGS = Object.keys(GATE_ARTIFACT_SCHEMAS);
|
|
@@ -124,33 +126,30 @@ function validCalibration(value, context) {
|
|
|
124
126
|
&& artifact.metrics.calibrationError <= artifact.profile.maximumCalibrationError
|
|
125
127
|
&& artifact.metrics.selectiveRisk <= artifact.profile.maximumSelectiveRisk;
|
|
126
128
|
}
|
|
127
|
-
function validLoadResult(value) {
|
|
128
|
-
if (!record(value) || value.schemaVersion
|
|
129
|
+
function validLoadResult(value, context) {
|
|
130
|
+
if (!record(value) || !DECISION_STAGED_LOAD_RESULT_VERSIONS.includes(String(value.schemaVersion)))
|
|
129
131
|
return false;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
// Legacy records remain readable, but only completed live v3 evidence bound to
|
|
133
|
+
// this exact clean source revision can qualify the performance gate.
|
|
134
|
+
if (context.manifest.dirty !== false || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(context.manifest.sourceCommit))
|
|
133
135
|
return false;
|
|
134
|
-
let digest;
|
|
135
136
|
try {
|
|
136
|
-
|
|
137
|
+
return verifyDecisionStagedLoadRecord(value, context.manifest.sourceCommit);
|
|
137
138
|
}
|
|
138
139
|
catch {
|
|
139
140
|
return false;
|
|
140
141
|
}
|
|
141
|
-
const bounds = Object.entries(result.manifest.bounds);
|
|
142
|
-
return digest === result.manifestDigest && bounds.length > 0
|
|
143
|
-
&& Object.keys(result.observations).length === bounds.length
|
|
144
|
-
&& bounds.every(([name, limit]) => {
|
|
145
|
-
const observed = result.observations[name];
|
|
146
|
-
return Number.isFinite(limit) && limit >= 0 && typeof observed === 'number' && Number.isFinite(observed)
|
|
147
|
-
&& observed >= 0 && observed <= limit;
|
|
148
|
-
});
|
|
149
142
|
}
|
|
150
143
|
function validReview(value, context) {
|
|
151
144
|
if (!record(value) || value.schemaVersion !== GATE_ARTIFACT_SCHEMAS['review-decision-recorded'])
|
|
152
145
|
return false;
|
|
153
146
|
const review = value;
|
|
147
|
+
try {
|
|
148
|
+
validateReviewEvaluation(review.evaluation);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
154
153
|
return review.runId === context.manifest.runId && review.sourceCommit === context.manifest.sourceCommit
|
|
155
154
|
&& typeof review.reviewer === 'string' && review.reviewer.trim().length > 0 && review.decision === 'approve'
|
|
156
155
|
&& validDate(review.recordedAt) && review.outcomesDigest === qualificationOutcomesDigest(context.manifest);
|
|
@@ -160,7 +159,7 @@ export function validateGateArtifact(flag, value, context) {
|
|
|
160
159
|
switch (flag) {
|
|
161
160
|
case 'immutable-splits': return validSplitPlan(value);
|
|
162
161
|
case 'calibration-qualified': return validCalibration(value, context);
|
|
163
|
-
case 'load-manifest-qualified': return validLoadResult(value);
|
|
162
|
+
case 'load-manifest-qualified': return validLoadResult(value, context);
|
|
164
163
|
case 'review-decision-recorded': return validReview(value, context);
|
|
165
164
|
default: return false;
|
|
166
165
|
}
|
|
@@ -178,9 +177,15 @@ export function deriveGateEvidence(manifest, proof = {}) {
|
|
|
178
177
|
const ref = manifest.gateArtifacts?.[flag];
|
|
179
178
|
const versionOk = flag === 'immutable-splits'
|
|
180
179
|
? ref !== undefined && IMMUTABLE_SPLIT_VERSIONS.includes(ref.schemaVersion)
|
|
181
|
-
:
|
|
180
|
+
: flag === 'load-manifest-qualified'
|
|
181
|
+
? ref !== undefined && DECISION_STAGED_LOAD_RESULT_VERSIONS.includes(ref.schemaVersion)
|
|
182
|
+
: ref !== undefined && ref.schemaVersion === GATE_ARTIFACT_SCHEMAS[flag];
|
|
182
183
|
flags[flag] = versionOk && ref !== undefined
|
|
183
184
|
&& typeof ref.artifact === 'string' && ref.artifact.length > 0 && sha256Pattern.test(ref.digest);
|
|
185
|
+
if (flag === 'load-manifest-qualified') {
|
|
186
|
+
flags[flag] = flags[flag] === true && proof.loadArtifactVerified === true && manifest.dirty === false
|
|
187
|
+
&& /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(manifest.sourceCommit);
|
|
188
|
+
}
|
|
184
189
|
}
|
|
185
190
|
return flags;
|
|
186
191
|
}
|