pantheon-opencode 1.6.3-beta.10 → 1.6.3-beta.12
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/CHANGELOG.md +39 -6
- package/README.md +6 -0
- package/bin/pantheon-init.mjs +15 -27
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +102 -2
- package/scripts/decision-router-v2-budget.mjs +2 -2
- package/scripts/decision-router.mjs +82 -25
- package/scripts/install/decision-router-config.mjs +12 -4
- package/scripts/install/interactive.mjs +44 -27
- package/scripts/install/opencode.mjs +6 -0
- package/scripts/jev-live-probe.mjs +110 -84
- package/scripts/skill-search.mjs +242 -0
- package/src/agents/aphrodite.md +34 -1
- package/src/agents/apollo.md +227 -0
- package/src/agents/athena.md +24 -0
- package/src/agents/demeter.md +33 -0
- package/src/agents/gaia.md +24 -0
- package/src/agents/hephaestus.md +24 -0
- package/src/agents/hermes.md +33 -0
- package/src/agents/iris.md +24 -0
- package/src/agents/mnemosyne.md +25 -3
- package/src/agents/nyx.md +53 -22
- package/src/agents/prometheus.md +242 -1
- package/src/agents/talos.md +24 -0
- package/src/agents/themis.md +24 -0
- package/src/agents/zeus.md +36 -20
- package/src/pantheon/jev-decision-tool.ts +69 -11
- package/src/pantheon/jev-decisions.ts +68 -5
- package/src/pantheon/jev-quality-score.ts +1 -1
- package/src/pantheon/jev-rank-verify.ts +22 -7
- package/src/pantheon/jev-risk-gate.ts +1 -0
- package/src/pantheon/local-decision-budget.ts +169 -2
- package/src/pantheon/local-decision-router.ts +10 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +2 -2
- package/src/pantheon/pantheon-decision-catalog.ts +1 -1
- package/src/pantheon/v2-decision-budget.ts +4 -2
- package/src/plugins/tui/dist/tui-v2.js +128 -25
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/whats-new-highlights.ts +59 -5
- package/src/plugins/tui/src/whats-new-open.ts +41 -1
- package/src/plugins/tui/src/whats-new.tsx +61 -8
package/CHANGELOG.md
CHANGED
|
@@ -10,12 +10,46 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
10
10
|
<!-- Add new changes here. Running `node scripts/versioning.mjs apply` will
|
|
11
11
|
move this section to a versioned entry and reset the template below. -->
|
|
12
12
|
|
|
13
|
+
## [v1.6.3-beta.12] - 2026-11-05
|
|
14
|
+
|
|
15
|
+
## 🆕 What's New
|
|
16
|
+
- Delegation answers are domain-aware again: agent descriptions ride with every choice — live probe 5/5 exact (FastAPI→hermes, WCAG→aphrodite, Alembic→demeter, security→themis, poem→none).
|
|
17
|
+
- The input envelope is enforced on EVERY path now: presets, review, rank and verify all refuse missing/unknown keys with the exact cause.
|
|
18
|
+
- Rank accepts up to 20 candidates (typesafe_rank contract) and names the accepted range on refusal.
|
|
19
|
+
- Skills results report where the candidates came from (`candidateSource`), ending silent prefilter misses.
|
|
20
|
+
- The local router respects open gates: review/approval required → abstain (`GATE_OPEN`), never route around.
|
|
21
|
+
|
|
22
|
+
## [v1.6.3-beta.11] - 2026-11-05
|
|
23
|
+
|
|
24
|
+
### 🆕 What's New
|
|
25
|
+
- Measured MCP usage policy across the roster — governance ladder byte-identical in all 13 specialists.
|
|
26
|
+
- Skill-discovery pipeline with the trust cascade: Anthropic catalog → skills.sh → GitHub; Jev ranks, you install.
|
|
27
|
+
- Dead-route holds release (ledger schema v4) — the fix for budgets frozen by removed routes.
|
|
28
|
+
- Roster reform: nyx re-scoped to chaos & adversarial, talos aligned to hotfix, domain docs per agent.
|
|
29
|
+
- Jev validated end to end in the field: N4 dead, verify field-verified, sandbox 28/28.
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **agents** — The roster reform, measured: the governance ladder (session context → free local selector → one typed Jev question → MCP last resort, with the durable-store, milestone-checkpoint and one-pass-vision rules) now sits byte-identical in all 13 specialist agents, pinned by `tests/agent-mcp-policy.test.mjs`; nyx is re-scoped to its intended chaos & adversarial identity (its observability body duplicated prometheus and left fuzzing uncovered — the observability material moved to prometheus); mnemosyne's description names its memory-MCP curation ownership; the live scorecard's talos scenario now matches the real hotfix-express-lane identity. Post-reform live scorecard: 14/16 exact, 8/8 on the zero-dispatch agents.
|
|
34
|
+
- **skills** — The skill-discovery pipeline: installed pool first (one Jev `mode: "skills"`), then one read-only search across the trust cascade — the canonical `anthropics/skills` catalog first (so `pdf`/`docx`/`mcp-builder` outrank the clones popularity ranking surfaces), the skills.sh index with install counts, then raw GitHub `SKILL.md` code search (8,480 hits where the index offered three) — via `scripts/skill-search.mjs` emitting tier-ordered `{skill, installs, url, source}` JSON, pinned by `tests/skill-search.test.mjs`, then one typed Jev choice question ranking the candidates (only names/counts/descriptions cross — skill contents are untrusted), then the winning candidate is PROPOSED to the user with the project-scoped install command. Pantheon never installs; the review is the user's. The ladder is documented in `docs/reference/native-decisions.md` and carried in `zeus.md`.
|
|
35
|
+
- **routing** — `decision-router holds release --provider <dead> --reason "<why>"`: the administrative correction for holds of routes that no longer exist (they can never reconcile and froze budget forever — the mechanical story behind the mid-month Jev die-offs). Ledger schema v4 adds the immutable `released_holds` archive; live providers are refused, their holds roll off with the period. First field application: the 10 `jev-free` fossils of the removed free route released, $1.00 of reserved budget freed.
|
|
36
|
+
- **mcp** — `bench/mcp-usage-audit.mjs`: the measured native-MCP usage audit (transcript, memory db, persistence kv, bench lines → dated report in `bench/results/`; reports are local-only, they carry bounded session excerpts). First run measured the whole field history: 5.7k memory touches, 2.5k persistence, 84 vision — the verdicts and cost model live in `docs/mcp-tools.md`.
|
|
37
|
+
|
|
38
|
+
- **agents** — The 14-agent domain-artifact analysis (docs/agents/README.md): each specialist owns its domain's durable file — aphrodite keeps docs/ui/conventions.md current whenever the project has a graphical surface, demeter docs/data, hermes docs/api, prometheus docs/infra — read-first, propose-when-missing, update-only-what-you-changed; new exclusive per-agent tools fail the measured bar (grants already enforce the exclusivity that pays).
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- **agents** — The zeus usage policy is measured, not decorative: `memory_store` takes durable, reusable facts only (session narration goes to a checkpoint or nowhere; per-project namespaces; update instead of duplicate), checkpoints fire at milestones only (never per turn, never re-saving an unchanged key), and vision runs one pass per image (zeus and aphrodite) — each vision call is real gateway spend. The contradictory store phrases that produced the narration excess are gone, pinned by `tests/agent-mcp-policy.test.mjs`.
|
|
44
|
+
|
|
13
45
|
## [v1.6.3-beta.10] - 2026-11-04
|
|
14
46
|
|
|
15
47
|
### Fixed
|
|
16
48
|
|
|
17
49
|
- **routing** — The Jev input envelope is enforced: schemaVersion is required (SCHEMA_VERSION_INVALID) and unknown keys are rejected (UNKNOWN_INPUT_KEYS) — the declared contract is now the enforced contract (field report N2/N3).
|
|
18
50
|
|
|
51
|
+
<!-- beta.7–beta.9 were landed together in 548fc6d; separate commits for these releases are absent from repository history. Per-beta attribution follows that commit’s grouped changelog snapshot. -->
|
|
52
|
+
|
|
19
53
|
## [v1.6.3-beta.9] - 2026-11-04
|
|
20
54
|
|
|
21
55
|
### Changed
|
|
@@ -23,20 +57,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
23
57
|
- **agents** — The live scorecard now runs the full 13-specialist catalog (was a 5-agent sample); first full-catalog run: 6 exact hits, 2 domain-adjacent judgment calls, measured per agent.
|
|
24
58
|
- **agents** — Zeus gains consolidated MCP call-timing rules: when to recall, when to store, when to checkpoint, when vision fires, and the escalation order (local selector -> Jev -> MCP last resort).
|
|
25
59
|
|
|
26
|
-
## [v1.6.3-beta.
|
|
60
|
+
## [v1.6.3-beta.8] - 2026-11-04
|
|
27
61
|
|
|
28
62
|
### Added
|
|
29
63
|
|
|
30
|
-
- **routing** —
|
|
64
|
+
- **routing** — The v3.1 **rank** and **verify** primitives on `pantheon_jev_decide`: `mode: "rank"` picks the winner among up to 8 candidates with a fit score (the host answers one scalar per question, so full ordering is impossible — documented); `mode: "verify"` checks 1–4 claims as predicate questions with **BLOCK fail-closed**. Hostile inputs rejected. Zeus-only, same gate chain.
|
|
31
65
|
|
|
32
|
-
## [v1.6.3-beta.
|
|
66
|
+
## [v1.6.3-beta.7] - 2026-11-04
|
|
33
67
|
|
|
34
68
|
### Added
|
|
35
69
|
|
|
36
|
-
- **routing** —
|
|
37
|
-
- **agents** — The live scorecard runs the full 13-specialist catalog (first full run: 6/8 exact, 2 domain-adjacent); Zeus gains consolidated MCP call-timing rules.
|
|
70
|
+
- **routing** — `jev-live-probe.mjs`: the operator-run live measurement tool. `--ping` only resolves the configured route locally (exit 0 when valid; no provider call); `--scorecard` runs the 16 configured live scenarios against that route and writes the dated scorecard into `bench/results/`. First live run: 7/8 correct specialist picks via OpenRouter.
|
|
38
71
|
|
|
39
|
-
## [v1.6.3-beta.
|
|
72
|
+
## [v1.6.3-beta.6] - 2026-11-04
|
|
40
73
|
|
|
41
74
|
### Added
|
|
42
75
|
|
package/README.md
CHANGED
|
@@ -430,6 +430,12 @@ the current project root per request while preserving the trusted
|
|
|
430
430
|
`PANTHEON_HOME` fallback. See [Memory](docs/MEMORY.md) for store separation and
|
|
431
431
|
[MCP tools](docs/mcp-tools.md) for details.
|
|
432
432
|
|
|
433
|
+
Native-MCP usage is measured, not assumed: `node bench/mcp-usage-audit.mjs`
|
|
434
|
+
writes a dated audit of real memory/persistence/vision/code-mode/resource
|
|
435
|
+
usage (reports stay local — they carry bounded session excerpts), and the
|
|
436
|
+
agent usage policies derived from it are documented in
|
|
437
|
+
[MCP tools](docs/mcp-tools.md).
|
|
438
|
+
|
|
433
439
|
The release install gate's tool canary loads the installed tarball's V2 plugin
|
|
434
440
|
entry under OpenCode 2.0.30 and verifies `hashline_edit` registration, Code Mode
|
|
435
441
|
visibility, and a bounded edit in an isolated project. It does not prove npm
|
package/bin/pantheon-init.mjs
CHANGED
|
@@ -26,7 +26,6 @@ import { fileURLToPath } from 'node:url'
|
|
|
26
26
|
import { configure as configureUi, endGaugeLine, tag } from '../scripts/install/cli-ui.mjs'
|
|
27
27
|
import { resolveComponentSelection } from '../scripts/install/component-selection.mjs'
|
|
28
28
|
import { resolveGlobalConfigDirectory } from '../scripts/install/config-paths.mjs'
|
|
29
|
-
import { provisionTypesafeHostProvider } from '../scripts/install/decision-router-config.mjs'
|
|
30
29
|
import { resolveInstallExitCode } from '../scripts/install/exit-codes.mjs'
|
|
31
30
|
import { createInterruptHandler } from '../scripts/install/interrupt.mjs'
|
|
32
31
|
import { parseOpenCodeVersion } from '../scripts/install/opencode-version.mjs'
|
|
@@ -61,23 +60,6 @@ function readVersion() {
|
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
/**
|
|
65
|
-
* Merge the TypeSafe decision-model provider entry into the user's
|
|
66
|
-
* `opencode.json` (never replaces existing keys; a non-JSON file is reported,
|
|
67
|
-
* never overwritten). Returns true, or a short failure reason.
|
|
68
|
-
*/
|
|
69
|
-
/**
|
|
70
|
-
* Merge (never overwrite) the TypeSafe decision-model entry into the user's
|
|
71
|
-
* OpenCode config, so choosing the TypeSafe route in the wizard needs only the
|
|
72
|
-
* user's own sign-in afterwards. Delegates to the shared installer module —
|
|
73
|
-
* the same provisioner `decision-router setup-model typesafe-jev/...` uses.
|
|
74
|
-
* Returns true, or a short failure reason for the installer to print.
|
|
75
|
-
*/
|
|
76
|
-
function provisionTypesafeProvider() {
|
|
77
|
-
const result = provisionTypesafeHostProvider({ env: process.env })
|
|
78
|
-
return result.ok ? true : result.reason
|
|
79
|
-
}
|
|
80
|
-
|
|
81
63
|
/** Value of a repeatable installer flag from the raw argv, or undefined. */
|
|
82
64
|
function readArgValue(name) {
|
|
83
65
|
const prefix = `${name}=`
|
|
@@ -1032,25 +1014,31 @@ async function main() {
|
|
|
1032
1014
|
{ stdout: (line) => console.log(` ${line}`) },
|
|
1033
1015
|
)
|
|
1034
1016
|
console.log(` ${S.jevConfigured(decisionTarget)}`)
|
|
1035
|
-
if (decisionTarget.startsWith('typesafe-jev')) {
|
|
1036
|
-
const provisioned = provisionTypesafeProvider()
|
|
1037
|
-
console.log(
|
|
1038
|
-
provisioned === true
|
|
1039
|
-
? ' TypeSafe provider entry merged into opencode.json (adapter + baseURL + apiKey via {env:TYPESAFE_API_KEY}, type "decision"). Activate: export TYPESAFE_API_KEY=<your TypeSafe key> and restart OpenCode. /connect does not carry custom providers.'
|
|
1040
|
-
: ` TypeSafe provider entry NOT merged (${provisioned}); merge it manually — see docs/reference/native-decisions.md.`,
|
|
1041
|
-
)
|
|
1042
|
-
}
|
|
1043
1017
|
} catch (error) {
|
|
1044
1018
|
console.error(
|
|
1045
1019
|
` ${S.jevConfigureFailed(error instanceof Error ? error.message : String(error))}`,
|
|
1046
1020
|
)
|
|
1047
1021
|
console.error(
|
|
1048
|
-
` Fix later with: npx pantheon-opencode decision-router setup-model ${decisionTarget} --monthly-usd ${monthly} --per-decision-usd ${perDecision}`,
|
|
1022
|
+
` Fix later with: npx pantheon-opencode decision-router setup-model ${decisionTarget} ${decisionTarget.startsWith('cloudflare-workers-jev/') ? '--account-id=<32-hex-id> ' : ''}--monthly-usd ${monthly} --per-decision-usd ${perDecision}`,
|
|
1049
1023
|
)
|
|
1050
1024
|
}
|
|
1051
1025
|
}
|
|
1052
1026
|
}
|
|
1053
1027
|
|
|
1028
|
+
const deferredJevSetup = result.decisionModelDeferredSetup ?? null
|
|
1029
|
+
if (deferredJevSetup?.target === 'cloudflare-workers-jev/clef') {
|
|
1030
|
+
console.log('')
|
|
1031
|
+
console.log(
|
|
1032
|
+
' Cloudflare Clef was not activated: its host provider entry requires your Cloudflare account ID.',
|
|
1033
|
+
)
|
|
1034
|
+
console.log(
|
|
1035
|
+
' After install, provision it with: npx pantheon-opencode decision-router setup-model cloudflare-workers-jev/clef --account-id=<32-hex-id> --monthly-usd 5 --per-decision-usd 0.10',
|
|
1036
|
+
)
|
|
1037
|
+
console.log(
|
|
1038
|
+
' Also set CLOUDFLARE_API_TOKEN to a Workers AI-scoped token in the OpenCode host environment, then restart OpenCode.',
|
|
1039
|
+
)
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1054
1042
|
// Old-version residue: every `npx pantheon-opencode` invocation materializes
|
|
1055
1043
|
// a full copy under the npm cache's _npx/ and nothing in npm removes old
|
|
1056
1044
|
// ones. The registration points at THIS run's copy, so every other copy is
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantheon",
|
|
3
3
|
"publisher": "ils15",
|
|
4
|
-
"version": "1.6.3-beta.
|
|
4
|
+
"version": "1.6.3-beta.12",
|
|
5
5
|
"displayName": "Pantheon",
|
|
6
6
|
"description": "Conductor-Delegate orchestration platform with 14 specialized agents, 20 skills, and OpenCode support.",
|
|
7
7
|
"agents": "./src/agents",
|
package/pyproject.toml
CHANGED
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.backends._legacy:_Backend"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pantheon"
|
|
7
|
-
version = "1.6.3-beta.
|
|
7
|
+
version = "1.6.3-beta.12"
|
|
8
8
|
description = "Multi-agent orchestration framework"
|
|
9
9
|
requires-python = ">=3.11"
|
|
10
10
|
# Python sources under src/mcp/ import fastmcp/pydantic at runtime, but those
|
|
@@ -18,9 +18,10 @@ function getVerifiedUsageEvidenceDetails(value) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/pantheon/local-decision-budget.ts
|
|
21
|
-
var SCHEMA_VERSION =
|
|
21
|
+
var SCHEMA_VERSION = 4;
|
|
22
22
|
var VERSION_TWO = 2;
|
|
23
23
|
var APPLICATION_ID = 1346522161;
|
|
24
|
+
var RELEASE_REASON_MAX_LENGTH = 200;
|
|
24
25
|
var DB_FILENAME = "decision-budget.sqlite";
|
|
25
26
|
var LOCAL_DECISION_BUDGET_PROVIDERS = Object.freeze([
|
|
26
27
|
"openai-decisions",
|
|
@@ -381,6 +382,70 @@ function openLocalDecisionBudgetLedger(options = {}) {
|
|
|
381
382
|
return safeChangeCount(result.changes);
|
|
382
383
|
});
|
|
383
384
|
}
|
|
385
|
+
function releaseHoldsForProvider(provider, reason) {
|
|
386
|
+
if (typeof provider !== "string" || provider.length < 1 || provider.length > 64) {
|
|
387
|
+
return { released: 0, freedMicros: 0 };
|
|
388
|
+
}
|
|
389
|
+
if (typeof reason !== "string" || reason.length < 1 || reason.length > RELEASE_REASON_MAX_LENGTH) {
|
|
390
|
+
return { released: 0, freedMicros: 0 };
|
|
391
|
+
}
|
|
392
|
+
return inImmediateTransaction(() => {
|
|
393
|
+
const timestamp = now();
|
|
394
|
+
const rows = db.prepare(
|
|
395
|
+
`SELECT id, provider, model, period_utc, reserved_micros, state, created_at_ms
|
|
396
|
+
FROM reservations WHERE provider = ? AND state IN ('pending', 'uncertain')
|
|
397
|
+
ORDER BY created_at_ms, id`
|
|
398
|
+
).all(provider);
|
|
399
|
+
if (rows.length === 0) return { released: 0, freedMicros: 0 };
|
|
400
|
+
const archive = db.prepare(
|
|
401
|
+
`INSERT INTO released_holds
|
|
402
|
+
(reservation_id, provider, model, period_utc, reserved_micros, state_at_release,
|
|
403
|
+
reason, created_at_ms, released_at_ms)
|
|
404
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
405
|
+
);
|
|
406
|
+
let freedMicros = 0;
|
|
407
|
+
for (const row of rows) {
|
|
408
|
+
archive.run(
|
|
409
|
+
row.id,
|
|
410
|
+
row.provider,
|
|
411
|
+
row.model,
|
|
412
|
+
row.period_utc,
|
|
413
|
+
row.reserved_micros,
|
|
414
|
+
row.state,
|
|
415
|
+
reason,
|
|
416
|
+
row.created_at_ms,
|
|
417
|
+
timestamp
|
|
418
|
+
);
|
|
419
|
+
freedMicros = safeMicrosTotal(freedMicros + row.reserved_micros);
|
|
420
|
+
}
|
|
421
|
+
const remove = db.prepare(
|
|
422
|
+
`DELETE FROM reservations WHERE provider = ? AND state IN ('pending', 'uncertain')`
|
|
423
|
+
).run(provider);
|
|
424
|
+
if (safeChangeCount(remove.changes) !== rows.length) {
|
|
425
|
+
throw new Error("Reservation rows changed during release");
|
|
426
|
+
}
|
|
427
|
+
return { released: rows.length, freedMicros };
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
function listReleasedHolds(limit) {
|
|
431
|
+
const bound = typeof limit === "number" && Number.isInteger(limit) && limit > 0 ? Math.min(limit, 200) : 20;
|
|
432
|
+
const rows = db.prepare(
|
|
433
|
+
`SELECT reservation_id, provider, model, period_utc, reserved_micros, state_at_release,
|
|
434
|
+
reason, created_at_ms, released_at_ms
|
|
435
|
+
FROM released_holds ORDER BY released_at_ms DESC, reservation_id LIMIT ?`
|
|
436
|
+
).all(bound);
|
|
437
|
+
return rows.map((row) => ({
|
|
438
|
+
reservationId: row.reservation_id,
|
|
439
|
+
provider: row.provider,
|
|
440
|
+
model: row.model,
|
|
441
|
+
period: row.period_utc,
|
|
442
|
+
reservedMicros: row.reserved_micros,
|
|
443
|
+
stateAtRelease: row.state_at_release === "uncertain" ? "uncertain" : "pending",
|
|
444
|
+
reason: row.reason,
|
|
445
|
+
createdAtMs: row.created_at_ms,
|
|
446
|
+
releasedAtMs: row.released_at_ms
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
384
449
|
function pruneCompletedPeriods() {
|
|
385
450
|
return inImmediateTransaction(() => {
|
|
386
451
|
let currentPeriod;
|
|
@@ -436,6 +501,8 @@ function openLocalDecisionBudgetLedger(options = {}) {
|
|
|
436
501
|
reconcileVerified,
|
|
437
502
|
listUncertainReservations,
|
|
438
503
|
recoverPendingReservations,
|
|
504
|
+
releaseHoldsForProvider,
|
|
505
|
+
listReleasedHolds,
|
|
439
506
|
pruneCompletedPeriods,
|
|
440
507
|
close: () => db.close()
|
|
441
508
|
};
|
|
@@ -450,12 +517,16 @@ function ensureSchema(db) {
|
|
|
450
517
|
if (applicationId !== 0 || tables.length !== 0) {
|
|
451
518
|
throw new Error("Refusing to initialize an unrecognized SQLite database");
|
|
452
519
|
}
|
|
453
|
-
|
|
520
|
+
createSchemaV4(db);
|
|
454
521
|
} else if (version === 1 && applicationId === APPLICATION_ID) {
|
|
455
522
|
migrateVersionOne(db);
|
|
456
523
|
migrateVersionTwoToThree(db);
|
|
524
|
+
migrateVersionThreeToFour(db);
|
|
457
525
|
} else if (version === VERSION_TWO && applicationId === APPLICATION_ID) {
|
|
458
526
|
migrateVersionTwoToThree(db);
|
|
527
|
+
migrateVersionThreeToFour(db);
|
|
528
|
+
} else if (version === 3 && applicationId === APPLICATION_ID) {
|
|
529
|
+
migrateVersionThreeToFour(db);
|
|
459
530
|
} else if (version !== SCHEMA_VERSION || applicationId !== APPLICATION_ID) {
|
|
460
531
|
throw new Error("Unsupported or incompatible local decision budget database schema");
|
|
461
532
|
}
|
|
@@ -550,9 +621,38 @@ function migrateVersionTwoToThree(db) {
|
|
|
550
621
|
INSERT INTO ledger_state (id, active_period_utc)
|
|
551
622
|
SELECT id, NULL FROM ledger_state_v2;
|
|
552
623
|
DROP TABLE ledger_state_v2;
|
|
624
|
+
PRAGMA user_version = 3;
|
|
625
|
+
`);
|
|
626
|
+
}
|
|
627
|
+
function migrateVersionThreeToFour(db) {
|
|
628
|
+
validateVersionThreeSchema(db);
|
|
629
|
+
db.exec(`
|
|
630
|
+
CREATE TABLE released_holds (
|
|
631
|
+
reservation_id TEXT PRIMARY KEY NOT NULL,
|
|
632
|
+
provider TEXT NOT NULL,
|
|
633
|
+
model TEXT NOT NULL,
|
|
634
|
+
period_utc TEXT NOT NULL CHECK (length(period_utc) = 7),
|
|
635
|
+
reserved_micros INTEGER NOT NULL CHECK (reserved_micros > 0),
|
|
636
|
+
state_at_release TEXT NOT NULL CHECK (state_at_release IN ('pending', 'uncertain')),
|
|
637
|
+
reason TEXT NOT NULL CHECK (length(reason) BETWEEN 1 AND ${RELEASE_REASON_MAX_LENGTH}),
|
|
638
|
+
created_at_ms INTEGER NOT NULL,
|
|
639
|
+
released_at_ms INTEGER NOT NULL
|
|
640
|
+
) STRICT;
|
|
641
|
+
CREATE INDEX released_holds_released_idx ON released_holds (released_at_ms, reservation_id);
|
|
553
642
|
PRAGMA user_version = ${SCHEMA_VERSION};
|
|
554
643
|
`);
|
|
555
644
|
}
|
|
645
|
+
function createSchemaV4(db) {
|
|
646
|
+
createSchemaV3(db);
|
|
647
|
+
migrateVersionThreeToFour(db);
|
|
648
|
+
}
|
|
649
|
+
function validateVersionThreeSchema(db) {
|
|
650
|
+
db.prepare(
|
|
651
|
+
`SELECT id, provider, model, period_utc, reserved_micros, actual_micros, state,
|
|
652
|
+
created_at_ms, updated_at_ms FROM reservations LIMIT 0`
|
|
653
|
+
);
|
|
654
|
+
db.prepare("SELECT id, active_period_utc FROM ledger_state LIMIT 0");
|
|
655
|
+
}
|
|
556
656
|
function migrateVersionOne(db) {
|
|
557
657
|
validateVersionOneSchema(db);
|
|
558
658
|
const providers = db.prepare("SELECT DISTINCT provider FROM reservations UNION SELECT provider FROM provider_caps").all();
|
|
@@ -101,7 +101,7 @@ function readDecisionBudgetLedgerFacts(dbPath) {
|
|
|
101
101
|
try {
|
|
102
102
|
const version = db.prepare("PRAGMA user_version").get().user_version;
|
|
103
103
|
const applicationId = db.prepare("PRAGMA application_id").get().application_id;
|
|
104
|
-
if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3) {
|
|
104
|
+
if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3 && version !== 4) {
|
|
105
105
|
return { present: true, readable: false, reason: "unsupported-schema" };
|
|
106
106
|
}
|
|
107
107
|
const activeRow = db.prepare("SELECT active_period_utc FROM ledger_state WHERE id = 1").get();
|
|
@@ -185,7 +185,7 @@ function listDecisionHoldsReadOnly(dbPath) {
|
|
|
185
185
|
try {
|
|
186
186
|
const applicationId = db.prepare("PRAGMA application_id").get().application_id;
|
|
187
187
|
const version = db.prepare("PRAGMA user_version").get().user_version;
|
|
188
|
-
if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3) return null;
|
|
188
|
+
if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3 && version !== 4) return null;
|
|
189
189
|
const rows = db.prepare(
|
|
190
190
|
`SELECT id, provider, model, period_utc, reserved_micros, state
|
|
191
191
|
FROM reservations WHERE state IN ('pending', 'uncertain')
|
|
@@ -65,6 +65,7 @@ export function decisionRouterHelp() {
|
|
|
65
65
|
' setup [options] computed artifact diff; writes only with --apply',
|
|
66
66
|
' preview alias of `setup` (never writes)',
|
|
67
67
|
' holds unresolved reservations, read-only',
|
|
68
|
+
' holds release --provider <p> --reason "<why>" archive+release dead-route holds',
|
|
68
69
|
'',
|
|
69
70
|
'Explicit actions (each one changes exactly one thing):',
|
|
70
71
|
' select local|auto|<provider>/<model> record a selection; enables nothing',
|
|
@@ -75,7 +76,7 @@ export function decisionRouterHelp() {
|
|
|
75
76
|
' period confirm --current none|YYYY-MM --next YYYY-MM',
|
|
76
77
|
'',
|
|
77
78
|
'Guided (each does the whole chain in one command):',
|
|
78
|
-
' setup-model <provider>/<model> --monthly-usd N --per-decision-usd N [--no-consent]',
|
|
79
|
+
' setup-model <provider>/<model> --monthly-usd N --per-decision-usd N [--no-consent] [--account-id=<32-hex-id>]',
|
|
79
80
|
' select + enable + consent + caps + period in one write,',
|
|
80
81
|
' then print the verification summary',
|
|
81
82
|
' doctor read-only diagnosis of the native decision route with',
|
|
@@ -280,6 +281,49 @@ export async function runDecisionRouterCommand(
|
|
|
280
281
|
return
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
if (command === 'holds' && rest[0] === 'release') {
|
|
285
|
+
// Administrative correction for holds of routes that no longer exist:
|
|
286
|
+
// a dead provider can never reconcile, so its holds would freeze budget
|
|
287
|
+
// forever. Live providers are refused — their holds roll off with the
|
|
288
|
+
// period. Every released row is archived with the mandatory reason.
|
|
289
|
+
const [, ...releaseArgs] = rest
|
|
290
|
+
const options = parseNamedOptions(releaseArgs, ['--provider', '--reason'])
|
|
291
|
+
const provider = options['--provider']
|
|
292
|
+
const reason = options['--reason']
|
|
293
|
+
if (provider === undefined || reason === undefined) {
|
|
294
|
+
throw new DecisionRouterUsageError(
|
|
295
|
+
'Usage: decision-router holds release --provider <dead-provider> --reason "<why>"',
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
if (Object.hasOwn(DECISION_ROUTER_MODELS, provider)) {
|
|
299
|
+
throw new DecisionRouterUsageError(
|
|
300
|
+
`Provider ${provider} is a live catalog route — its holds are not releasable; ` +
|
|
301
|
+
'they reconcile or roll off with the budget period.',
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
const ledger = openLedger(env)
|
|
305
|
+
try {
|
|
306
|
+
const result = ledger.releaseHoldsForProvider(provider, reason)
|
|
307
|
+
if (result.released === 0) {
|
|
308
|
+
stdout(`No unresolved holds for provider ${provider}.`)
|
|
309
|
+
} else {
|
|
310
|
+
stdout(
|
|
311
|
+
`Released ${result.released} hold(s) of provider ${provider}; ` +
|
|
312
|
+
`freed ${(result.freedMicros / 1_000_000).toFixed(2)} USD of reserved budget.`,
|
|
313
|
+
)
|
|
314
|
+
for (const hold of ledger.listReleasedHolds(5)) {
|
|
315
|
+
stdout(
|
|
316
|
+
`Archived ${hold.reservationId}: provider=${hold.provider} model=${hold.model} ` +
|
|
317
|
+
`state_at_release=${hold.stateAtRelease} reason="${hold.reason}"`,
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} finally {
|
|
322
|
+
ledger.close()
|
|
323
|
+
}
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
|
|
283
327
|
if (command === 'period') {
|
|
284
328
|
const [action, ...periodArgs] = rest
|
|
285
329
|
if (action !== 'confirm')
|
|
@@ -326,6 +370,29 @@ export async function runDecisionRouterCommand(
|
|
|
326
370
|
const { provider, model } = selection
|
|
327
371
|
const candidate = { provider, model }
|
|
328
372
|
|
|
373
|
+
// Cloudflare's native module requires an account-specific custom host
|
|
374
|
+
// provider entry. Fail before selecting/enabling the route if that entry
|
|
375
|
+
// cannot be provisioned; a warning after activation would leave a route
|
|
376
|
+
// that cannot be resolved by the host.
|
|
377
|
+
let cloudflareProvision = null
|
|
378
|
+
if (provider === 'cloudflare-workers-jev') {
|
|
379
|
+
const accountIdFlag = flagArgs.find((arg) => arg.startsWith('--account-id='))
|
|
380
|
+
if (!accountIdFlag) {
|
|
381
|
+
throw new DecisionRouterUsageError(
|
|
382
|
+
'Cloudflare route requires --account-id=<32-hex-id>; route was not activated',
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
|
+
cloudflareProvision = provisionCloudflareHostProvider({
|
|
386
|
+
accountId: accountIdFlag.slice('--account-id='.length),
|
|
387
|
+
env,
|
|
388
|
+
})
|
|
389
|
+
if (!cloudflareProvision.ok) {
|
|
390
|
+
throw new DecisionRouterUsageError(
|
|
391
|
+
`Cloudflare route was not activated: ${cloudflareProvision.reason}`,
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
329
396
|
// One update names selection, enablement, candidates and (unless refused)
|
|
330
397
|
// consent together: selecting a different target revokes consent unless
|
|
331
398
|
// the same update names it, so this single write is the consent act.
|
|
@@ -340,26 +407,11 @@ export async function runDecisionRouterCommand(
|
|
|
340
407
|
noConsent ? 'Egress consent NOT recorded (--no-consent).' : 'Egress consent recorded: yes.',
|
|
341
408
|
)
|
|
342
409
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const provision = provisionCloudflareHostProvider({
|
|
349
|
-
accountId: accountId?.split('=')[1],
|
|
350
|
-
env,
|
|
351
|
-
})
|
|
352
|
-
if (provision.ok) {
|
|
353
|
-
stdout(
|
|
354
|
-
`Cloudflare provider entry merged into ${provision.path} (accountId + models.clef, type "decision"). ` +
|
|
355
|
-
'The token comes from CLOUDFLARE_API_TOKEN (Workers AI-scoped token) in the host environment.',
|
|
356
|
-
)
|
|
357
|
-
} else {
|
|
358
|
-
stdout(
|
|
359
|
-
`⚠ Cloudflare provider entry NOT merged: ${provision.reason}` +
|
|
360
|
-
' — pass --account-id=<32-hex Cloudflare account id>.',
|
|
361
|
-
)
|
|
362
|
-
}
|
|
410
|
+
if (cloudflareProvision) {
|
|
411
|
+
stdout(
|
|
412
|
+
`Cloudflare provider entry merged into ${cloudflareProvision.path} (accountId + models.clef, type "decision"). ` +
|
|
413
|
+
'The token comes from CLOUDFLARE_API_TOKEN (Workers AI-scoped token) in the host environment.',
|
|
414
|
+
)
|
|
363
415
|
}
|
|
364
416
|
|
|
365
417
|
// The TypeSafe route needs a host-side provider entry the decisions API
|
|
@@ -642,11 +694,16 @@ function formatInstallState(config, target) {
|
|
|
642
694
|
|
|
643
695
|
function parseSelectionTarget(target) {
|
|
644
696
|
if (target === 'local' || target === 'auto') return { mode: target }
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
697
|
+
const value = String(target)
|
|
698
|
+
for (const provider of Object.keys(DECISION_ROUTER_MODELS)) {
|
|
699
|
+
const prefix = `${provider}/`
|
|
700
|
+
if (!value.startsWith(prefix)) continue
|
|
701
|
+
const model = value.slice(prefix.length)
|
|
702
|
+
if (DECISION_ROUTER_MODELS[provider].includes(model)) {
|
|
703
|
+
return { mode: 'explicit', provider, model }
|
|
704
|
+
}
|
|
648
705
|
}
|
|
649
|
-
|
|
706
|
+
throw new DecisionRouterUsageError('Selection must name one supported provider/model pair')
|
|
650
707
|
}
|
|
651
708
|
|
|
652
709
|
function parseNamedFlags(args, expected) {
|
|
@@ -656,10 +656,18 @@ export function provisionCloudflareHostProvider({ accountId, env = process.env }
|
|
|
656
656
|
data.providers ??= {}
|
|
657
657
|
data.providers['cloudflare-workers-ai'] ??= {}
|
|
658
658
|
data.providers['cloudflare-workers-ai'].options ??= {}
|
|
659
|
-
data.providers['cloudflare-workers-ai']
|
|
660
|
-
|
|
661
|
-
if (
|
|
662
|
-
|
|
659
|
+
const provider = data.providers['cloudflare-workers-ai']
|
|
660
|
+
const existingAccountId = provider.options.accountId
|
|
661
|
+
if (existingAccountId != null && String(existingAccountId).trim() !== '') {
|
|
662
|
+
if (String(existingAccountId).trim().toLowerCase() !== trimmed.toLowerCase()) {
|
|
663
|
+
return { ok: false, reason: 'existing accountId conflicts with --account-id' }
|
|
664
|
+
}
|
|
665
|
+
} else {
|
|
666
|
+
provider.options.accountId = trimmed
|
|
667
|
+
}
|
|
668
|
+
provider.models ??= {}
|
|
669
|
+
if (provider.models.clef === undefined) {
|
|
670
|
+
provider.models.clef = {
|
|
663
671
|
name: 'Clef (Cloudflare Workers AI)',
|
|
664
672
|
type: 'decision',
|
|
665
673
|
}
|