pantheon-opencode 1.6.2-beta.5 → 1.6.2-beta.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/CHANGELOG.md +19 -0
- package/README.md +40 -38
- package/README.pt-BR.md +9 -0
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +4 -5
- package/scripts/install/decision-router-config.mjs +4 -23
- package/src/pantheon/jev-decision-tool.ts +336 -0
- package/src/pantheon/jev-decisions.ts +625 -0
- package/src/pantheon/local-decision-budget.ts +4 -1
- package/src/pantheon/local-decision-egress-gate.ts +16 -136
- package/src/pantheon/local-decision-prompt.ts +3 -9
- package/src/pantheon/local-decision-provider-matrix.ts +14 -62
- package/src/pantheon/local-decision-turn.ts +15 -252
- package/src/pantheon/local-decision-usage-evidence.internal.ts +80 -119
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +3 -2
- package/src/pantheon/v2-decision-points.ts +1 -1
- package/src/pantheon/v2-native-decisions.ts +365 -0
- package/src/pantheon/v2-tools.ts +3 -0
- package/src/plugin-v2.ts +59 -15
- package/src/plugins/tui/dist/tui-v2.js +3 -3
- 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/pantheon/local-decision-provider-protocol.ts +0 -335
- package/src/pantheon/local-decision-provider.internal.ts +0 -260
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,25 @@ 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.2-beta.6] - 2026-11-01
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **routing** — Added the Zeus-only `pantheon_jev_decide` advisory tool: 1–4 typed questions (choice, score, predicate) answered by the Jev decision model through the host's native Decisions API; it registers only on hosts exposing that API and never dispatches agents, runs skills, or changes permissions.
|
|
18
|
+
- **routing** — Added native route selection from the user-level decision-router config (OpenCode Console `jev-1.13` and custom `typesafe-ai` decision models) with a frozen provider→host mapping; direct OpenAI is refused and never substituted.
|
|
19
|
+
- **routing** — Added host-reported settlement: the budget reservation reconciles from the host-reported DecisionResult cost (a reported zero releases the hold), and a failed or unreconciled call stays fail-closed.
|
|
20
|
+
- **routing** — Added catalog presets to `pantheon_jev_decide`: `mode: "skills"` stacks the locally prefiltered skill shortlist (whole-catalog fallback) and `mode: "delegation"` picks a specialist, both single typed calls with `none` always offered.
|
|
21
|
+
- **routing** — Extended the `skills` preset to decide over installed host skills (`ctx.skill.list()`) in addition to the Pantheon catalog: any Agent-Skills-format skill installed in the host becomes stackable without a Pantheon change. Installs stay manual and reviewed; Pantheon never installs or updates skills.
|
|
22
|
+
- **docs** — Documented the native gate chain, routes, and verification boundary in one reference (`docs/reference/native-decisions.md`) and indexed the decision-layer references in the docs nav; added a real-host canary assertion for the new tool's registration.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- **security** — Removed the direct-fetch decision-provider path entirely (runner, payload protocol, fetch-path usage verifier, per-turn provider cache): Pantheon owns no transport, and the only egress is the host's native layer behind the enabled/consent/budget/permission chain. The per-turn prompt hook stays local-only.
|
|
27
|
+
- **security** — The budget ledger now treats a host-reported zero cost as a real zero (releasing the hold) while still freezing user/provider/model buckets when actual cost exceeds the reservation.
|
|
28
|
+
- **docs** — Consolidated the decision-status narrative to one source of truth per surface, corrected stale env-var rows (no decision credential is read on any production path), and removed an orphan planning note (the tracked deepwork note stays: it is the checkout fixture the resources server resolves against).
|
|
29
|
+
|
|
30
|
+
<!-- Add new changes here. Running `node scripts/versioning.mjs apply` will
|
|
31
|
+
move this section to a versioned entry and reset the template below. -->
|
|
13
32
|
## [v1.6.2-beta.5] - 2026-11-01
|
|
14
33
|
|
|
15
34
|
## 🆕 What's New
|
package/README.md
CHANGED
|
@@ -97,14 +97,16 @@ see [Quick Start](docs/QUICKSTART.md).
|
|
|
97
97
|
and documenting work.
|
|
98
98
|
- **5 local MCP servers** for project memory, persistence, resources, confined
|
|
99
99
|
script execution, and vision.
|
|
100
|
-
- **A selective, advisory decision router** with structured local results and
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
decision
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
- **A selective, advisory decision router** with structured local results and
|
|
101
|
+
deterministic per-turn skill/specialist recommendations when enabled.
|
|
102
|
+
Pantheon-owned direct-provider egress is inactive; native egress exists only
|
|
103
|
+
via the explicit, Zeus-only `pantheon_jev_decide` advisory tool, which calls
|
|
104
|
+
the host's native Decisions API (TypeSafe Jev via OpenCode Console or a
|
|
105
|
+
configured decision model) behind the user's consent and budget gates — it
|
|
106
|
+
never dispatches agents, runs skills, or changes permissions. This does not
|
|
107
|
+
change separately documented quota and Vision integrations. See the
|
|
108
|
+
[router reference](docs/reference/local-decision-router.md) and the
|
|
109
|
+
[Native Decisions (Jev)](docs/reference/native-decisions.md).
|
|
108
110
|
- **An optional TUI** with a dispatch sidebar block and a full-width
|
|
109
111
|
`/dispatch` panel. The V2 TUI also provides a quota overview in the
|
|
110
112
|
sidebar/footer and a `/quota` details panel. Quota display is enabled by
|
|
@@ -242,26 +244,29 @@ fan-in or job recovery without an exposed mechanism.
|
|
|
242
244
|
The delegation model, caller/target matrix, and approval gates are documented
|
|
243
245
|
in [Architecture](docs/ARCHITECTURE.md) and
|
|
244
246
|
[Permissions, Gates & Delegation](docs/PERMISSIONS-QUALITY-DELEGATION.md).
|
|
245
|
-
The [local decision router](docs/reference/local-decision-router.md)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
247
|
+
The [local decision router](docs/reference/local-decision-router.md) provides a
|
|
248
|
+
default-off standalone local API (`PANTHEON_LOCAL_DECISION_ROUTER=1`), the
|
|
249
|
+
separate manual `pantheon_local_decision` advisory tool, and deterministic
|
|
250
|
+
per-turn local recommendations when the user-level `enabled` preference is on.
|
|
251
|
+
The prompt hook may add an advisory marker and narrow an existing `prompt.skills`
|
|
252
|
+
array only when identifiable skill IDs overlap the local selection; this never
|
|
253
|
+
dispatches child sessions or changes permissions or approvals. Per-turn selection
|
|
254
|
+
uses no provider egress: the formerly documented direct-provider route remains
|
|
255
|
+
historical/inactive, and legacy consent, caps, period, provider selection, or
|
|
256
|
+
credentials cannot activate it. Native child-session dispatch remains separate.
|
|
257
|
+
|
|
258
|
+
The one native egress surface is the Zeus-only `pantheon_jev_decide` tool,
|
|
259
|
+
available on hosts that expose the V2.2.5 native Decisions API; its full gate
|
|
260
|
+
chain, routes, and settlement rules are documented once in
|
|
261
|
+
[V2 native Decisions](docs/reference/native-decisions.md).
|
|
258
262
|
|
|
259
263
|
The installer may retain a legacy target-specific preference; it does not control
|
|
260
|
-
runtime routing. `npx pantheon-opencode decision-router ...` manages
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
credentials. The published CLI imports
|
|
264
|
+
runtime routing. `npx pantheon-opencode decision-router ...` manages stored
|
|
265
|
+
user-level preferences and budget state: `enabled` gates the local per-turn
|
|
266
|
+
recommendation only; provider-selection and budget/consent state do not activate
|
|
267
|
+
egress. The separate SQLite ledger has no default caps. Installation does not
|
|
268
|
+
contact a model provider or inspect credentials. The published CLI imports
|
|
269
|
+
committed ESM bundles:
|
|
265
270
|
`npm run build:decision-router` regenerates them and `npm run check:decision-router`
|
|
266
271
|
(the `prepack`/`prepublishOnly` drift gate) fails when any is stale. The
|
|
267
272
|
`pantheon-opencode/local-decision-router` subpath itself is TypeScript source, so
|
|
@@ -287,17 +292,14 @@ extra copy is made. Installer file-ownership tracking is partial and asymmetric
|
|
|
287
292
|
are not separately indexed — so this preview compares the decision-layer
|
|
288
293
|
artifacts it owns, not "everything the installer touched".
|
|
289
294
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
absence on an unexercised path; `permission.evaluate.egress` is likewise
|
|
299
|
-
unreachable in the probed host (a tool declaring it is never advertised to the
|
|
300
|
-
provider). Measured surface coverage is
|
|
295
|
+
The old OpenAI/TypeSafe per-turn provider adapters and endpoint descriptions are
|
|
296
|
+
retained as historical, inert code; no legacy consent, cap, period, provider, or
|
|
297
|
+
permission setting wires them into the production prompt hook. The captured-hook
|
|
298
|
+
boundary test supplies an isolated synthetic consent/provider config and fake
|
|
299
|
+
test-only credential, verifies a local recommendation marker, and verifies zero
|
|
300
|
+
native Decisions or global `fetch` calls. This is an offline regression check of
|
|
301
|
+
that hook, not a claim about unexercised network paths or a live-provider test.
|
|
302
|
+
Measured surface coverage is
|
|
301
303
|
reported honestly rather than implied: P7 runs behind `PANTHEON_V2_P7_LOOP` with
|
|
302
304
|
an **advisory** execution cap (never described as enforcement), P2 is
|
|
303
305
|
**advisory-only** (an empirical no-op on the default path), P9 was measured on
|
|
@@ -432,7 +434,7 @@ recorded in the [router reference](docs/reference/local-decision-router.md).
|
|
|
432
434
|
| [Compatibility](docs/COMPATIBILITY.md) | [OpenCode V2](docs/opencode-v2.md) |
|
|
433
435
|
| [Agents & Skills](docs/agents/README.md) | [Platforms](docs/PLATFORMS.md) |
|
|
434
436
|
| [Release Process](docs/RELEASING.md) | [Branch Protection](docs/BRANCH-PROTECTION.md) |
|
|
435
|
-
| [Model Routing](docs/reference/model-routing.md) | [Local Decision Router](docs/reference/local-decision-router.md) · [Offline Evaluation Protocol](docs/reference/offline-evaluation.md) · [Env Vars](docs/reference/env-vars.md) · [Code Mode](docs/reference/code-mode.md) |
|
|
437
|
+
| [Model Routing](docs/reference/model-routing.md) | [Local Decision Router](docs/reference/local-decision-router.md) · [V2 Native Decisions](docs/reference/native-decisions.md) · [Offline Evaluation Protocol](docs/reference/offline-evaluation.md) · [Env Vars](docs/reference/env-vars.md) · [Code Mode](docs/reference/code-mode.md) |
|
|
436
438
|
| [Contributing](CONTRIBUTING.md) | [Roadmap](ROADMAP.md) · [Changelog](CHANGELOG.md) |
|
|
437
439
|
|
|
438
440
|
Memory writes through `pantheon-memory` are serialized, and failed writes are
|
package/README.pt-BR.md
CHANGED
|
@@ -75,6 +75,15 @@ apenas — `init` → reiniciar → `/dispatch` → primeiro resultado — veja
|
|
|
75
75
|
documentar.
|
|
76
76
|
- **5 servidores MCP locais** para memória de projeto, persistência, recursos,
|
|
77
77
|
execução confinada de scripts e visão.
|
|
78
|
+
- **Um roteador de decisão seletivo e consultivo**, com resultados locais
|
|
79
|
+
estruturados e recomendações por turno quando habilitado. O egress direto
|
|
80
|
+
pertencente ao Pantheon é inativo; o egress nativo existe apenas na tool
|
|
81
|
+
explícita `pantheon_jev_decide` (só para o Zeus), que chama a API nativa de
|
|
82
|
+
Decisions do host (Jev/TypeSafe via OpenCode Console ou modelo configurado)
|
|
83
|
+
atrás do consentimento e dos limites de orçamento do usuário — ela nunca
|
|
84
|
+
despacha agentes, executa skills ou altera permissões. Veja a
|
|
85
|
+
[referência do roteador](docs/reference/local-decision-router.md) e o
|
|
86
|
+
[Decisions nativas (Jev)](docs/reference/native-decisions.md).
|
|
78
87
|
- **Uma TUI opcional**, com bloco de dispatch na sidebar e painel `/dispatch`
|
|
79
88
|
em largura total. A TUI V2 também inclui um resumo de quota na sidebar/rodapé
|
|
80
89
|
e o painel `/quota`, com abas Usage, Limits, Plugin e Settings. Usage mostra
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantheon-opencode",
|
|
3
|
-
"version": "1.6.2-beta.
|
|
3
|
+
"version": "1.6.2-beta.6",
|
|
4
4
|
"description": "Multi-agent orchestration for OpenCode — 14 specialized agents, TDD, Themis review gates.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"workspaces": [
|
|
@@ -120,6 +120,7 @@
|
|
|
120
120
|
"@biomejs/biome": "2.5.14",
|
|
121
121
|
"@commitlint/cli": "21.2.3",
|
|
122
122
|
"@commitlint/config-conventional": "21.2.3",
|
|
123
|
+
"@opencode/plugin": "2.2.5",
|
|
123
124
|
"ajv": "8.20.0",
|
|
124
125
|
"esbuild": "0.28.2",
|
|
125
126
|
"husky": "^9.1.7",
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantheon",
|
|
3
3
|
"publisher": "ils15",
|
|
4
|
-
"version": "1.6.2-beta.
|
|
4
|
+
"version": "1.6.2-beta.6",
|
|
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.2-beta.
|
|
7
|
+
version = "1.6.2-beta.6"
|
|
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
|
|
@@ -11,10 +11,6 @@ import { performance } from "node:perf_hooks";
|
|
|
11
11
|
import { DatabaseSync } from "node:sqlite";
|
|
12
12
|
|
|
13
13
|
// src/pantheon/local-decision-usage-evidence.internal.ts
|
|
14
|
-
var MODEL_IDS = Object.freeze({
|
|
15
|
-
"openai-decisions": "gpt-6-luna",
|
|
16
|
-
"typesafe-jev": "jev-1.14.0"
|
|
17
|
-
});
|
|
18
14
|
var evidenceDetails = /* @__PURE__ */ new WeakMap();
|
|
19
15
|
function getVerifiedUsageEvidenceDetails(value) {
|
|
20
16
|
if (typeof value !== "object" && typeof value !== "function" || value === null) return null;
|
|
@@ -287,7 +283,10 @@ function openLocalDecisionBudgetLedger(options = {}) {
|
|
|
287
283
|
return { status: "unknown" };
|
|
288
284
|
}
|
|
289
285
|
const verified = getVerifiedUsageEvidenceDetails(evidence);
|
|
290
|
-
if (!verified || !Number.isSafeInteger(verified.actualCostMicros) ||
|
|
286
|
+
if (!verified || !Number.isSafeInteger(verified.actualCostMicros) || // Zero is a legitimate host-reported cost on the native route (the free
|
|
287
|
+
// Console variant and hosts that do not price Decisions); reconciling at
|
|
288
|
+
// zero releases the hold instead of burning the period's budget.
|
|
289
|
+
verified.actualCostMicros < 0 || !isAllowedProvider(verified.provider) || !isAllowedModel(verified.model) || !isValidPeriod(verified.period)) {
|
|
291
290
|
return { status: "unknown" };
|
|
292
291
|
}
|
|
293
292
|
return inImmediateTransaction(() => {
|
|
@@ -80,7 +80,6 @@ const LEGACY_USER_CONFIG_KEYS = [
|
|
|
80
80
|
* new install-time option appears.
|
|
81
81
|
*/
|
|
82
82
|
const ACCEPTED_INSTALL_STATE_PROVIDERS = new Set([...DECISION_ROUTER_PROVIDERS, 'typesafe-jev'])
|
|
83
|
-
const externalProviderSet = new Set(['openai-decisions', 'jev', 'typesafe-jev'])
|
|
84
83
|
|
|
85
84
|
/** Canonicalize the legacy `jev` spelling once, at every user-config boundary. */
|
|
86
85
|
export function normalizeDecisionProviderId(provider) {
|
|
@@ -125,29 +124,11 @@ export function createDecisionRouterConfig(provider, egressConsent = false) {
|
|
|
125
124
|
|
|
126
125
|
/**
|
|
127
126
|
* Resolve a preference without probing the environment or credentials.
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @returns {'local'|'openai-decisions'|'jev'|'typesafe-jev'}
|
|
127
|
+
* (The legacy `resolveDecisionRouterProvider` auto resolver was removed with
|
|
128
|
+
* the direct-fetch provider path; runtime selection uses
|
|
129
|
+
* `resolveUserDecisionRouterCandidate` / `explainUserDecisionRouterAutoSelection`
|
|
130
|
+
* and the native route resolver.)
|
|
133
131
|
*/
|
|
134
|
-
export function resolveDecisionRouterProvider(
|
|
135
|
-
config,
|
|
136
|
-
{ authorizedProviders = [], budgetConfigured = false } = {},
|
|
137
|
-
) {
|
|
138
|
-
const preference = migrateDecisionRouterConfig(config)
|
|
139
|
-
if (!preference.egress_consent || budgetConfigured !== true) return 'local'
|
|
140
|
-
if (preference.provider === 'local') return 'local'
|
|
141
|
-
|
|
142
|
-
if (preference.provider === 'auto') {
|
|
143
|
-
const candidates = [
|
|
144
|
-
...new Set(authorizedProviders.filter((provider) => externalProviderSet.has(provider))),
|
|
145
|
-
]
|
|
146
|
-
return candidates.length === 1 ? candidates[0] : 'local'
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return externalProviderSet.has(preference.provider) ? preference.provider : 'local'
|
|
150
|
-
}
|
|
151
132
|
|
|
152
133
|
/**
|
|
153
134
|
* Resolve Pantheon's private non-secret user configuration path.
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The explicit V2 tool surface for native Jev Decisions.
|
|
3
|
+
*
|
|
4
|
+
* This is the one production call site for the native Decisions scaffold. The
|
|
5
|
+
* surface is an explicit tool invocation, which resolves the hook path's
|
|
6
|
+
* correlation problem by construction: the model calls the tool during its own
|
|
7
|
+
* turn, so there is no queued/steer ambiguity to prove. Egress still passes the
|
|
8
|
+
* full gate chain before the host's `experimental.generate.decisions` is ever
|
|
9
|
+
* invoked — user-level config (`enabled`, `egress_consent`), exactly one
|
|
10
|
+
* cap-valid native candidate from the budget ledger, the host permission
|
|
11
|
+
* kill-switch on the `decision.egress` action, and the bounded request
|
|
12
|
+
* preparer. Transport is the host's own provider layer: this module never
|
|
13
|
+
* touches fetch, endpoints, or credentials.
|
|
14
|
+
*
|
|
15
|
+
* Settlement follows the fetch runner's fail-closed contract: reserve before
|
|
16
|
+
* the call, reconcile from the host-reported cost after it, and leave the
|
|
17
|
+
* reservation pending (budget held for the period) when no evidence can be
|
|
18
|
+
* minted. A failed or unreconciled call is a refusal, never a retry.
|
|
19
|
+
*/
|
|
20
|
+
import { readUserDecisionRouterConfig } from '../../scripts/install/decision-router-config.mjs'
|
|
21
|
+
import {
|
|
22
|
+
consumeJevDecisionResult,
|
|
23
|
+
isJevDecisionPreset,
|
|
24
|
+
type JevDecisionCatalogEntry,
|
|
25
|
+
type JevHostSkill,
|
|
26
|
+
type NativeJevRouteFailure,
|
|
27
|
+
prepareJevDecisionRequest,
|
|
28
|
+
prepareJevPresetRequest,
|
|
29
|
+
resolveNativeJevRoute,
|
|
30
|
+
} from './jev-decisions.ts'
|
|
31
|
+
import {
|
|
32
|
+
openLocalDecisionBudgetLedger,
|
|
33
|
+
resolveLocalDecisionBudgetDbPath,
|
|
34
|
+
} from './local-decision-budget.ts'
|
|
35
|
+
import {
|
|
36
|
+
assertDecisionEgressPermission,
|
|
37
|
+
buildDecisionEgressRequest,
|
|
38
|
+
} from './local-decision-egress-gate.ts'
|
|
39
|
+
import { verifyNativeUsageForReservation } from './local-decision-usage-evidence.internal.ts'
|
|
40
|
+
import type { NativeDecisionRequest } from './v2-native-decisions.ts'
|
|
41
|
+
import type { V2ToolDef } from './v2-tools.ts'
|
|
42
|
+
|
|
43
|
+
export interface V2JevDecisionRuntime {
|
|
44
|
+
/** Raw host model catalog (`ctx.model.list`); may resolve to anything. */
|
|
45
|
+
readonly listModels: () => Promise<unknown>
|
|
46
|
+
/** The host's native Decisions API (`ctx.experimental.generate.decisions`). */
|
|
47
|
+
readonly decide: (request: NativeDecisionRequest) => Promise<unknown>
|
|
48
|
+
/**
|
|
49
|
+
* Raw host skill registry (`ctx.skill.list()`); optional. Its entries extend
|
|
50
|
+
* the skills preset so installed Agent Skills become decidable.
|
|
51
|
+
*/
|
|
52
|
+
readonly listSkills?: () => Promise<unknown>
|
|
53
|
+
/** Host permission kill-switch (`ctx.permission.assert`), when present. */
|
|
54
|
+
readonly permissionAssert?: (input: Record<string, unknown>) => Promise<unknown>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Logical permission resource: no endpoint URL exists on the native route. */
|
|
58
|
+
export function nativeJevPermissionResource(providerID: string, id: string): string {
|
|
59
|
+
return `pantheon-native-decisions://${providerID}/${id}`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type JevDecisionRunFailure =
|
|
63
|
+
| 'CALLER_NOT_ZEUS'
|
|
64
|
+
| 'CONTEXT_UNAVAILABLE'
|
|
65
|
+
| 'CONFIG_UNAVAILABLE'
|
|
66
|
+
| 'DISABLED'
|
|
67
|
+
| 'CONSENT_MISSING'
|
|
68
|
+
| 'CATALOG_UNAVAILABLE'
|
|
69
|
+
| 'CAP_OR_PERIOD_DENIED'
|
|
70
|
+
| NativeJevRouteFailure
|
|
71
|
+
| 'PERMISSION_UNAVAILABLE'
|
|
72
|
+
| 'PERMISSION_DENIED'
|
|
73
|
+
| 'STATE_INVALID'
|
|
74
|
+
| 'QUESTIONS_INVALID'
|
|
75
|
+
| 'PRESET_INVALID'
|
|
76
|
+
| 'RESERVATION_DENIED'
|
|
77
|
+
| 'DECISION_CALL_FAILED'
|
|
78
|
+
| 'USAGE_UNRECONCILED'
|
|
79
|
+
|
|
80
|
+
interface JevToolContext {
|
|
81
|
+
sessionID?: unknown
|
|
82
|
+
messageID?: unknown
|
|
83
|
+
agent?: unknown
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function refusal(reasonCode: JevDecisionRunFailure): string {
|
|
87
|
+
return JSON.stringify({ advisory: false, effect: 'none', reasonCode })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isNonBlankString(value: unknown): value is string {
|
|
91
|
+
return typeof value === 'string' && value.trim().length > 0
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Read the host's installed skills for the stacking preset. Anything that is
|
|
96
|
+
* not a plain {id, description?} record is skipped; a missing or hostile
|
|
97
|
+
* registry degrades to the catalog-only preset. Reading the registry applies
|
|
98
|
+
* no trust: installation already was the user's manual, reviewed act.
|
|
99
|
+
*/
|
|
100
|
+
async function readHostSkills(runtime: V2JevDecisionRuntime): Promise<JevHostSkill[] | undefined> {
|
|
101
|
+
if (typeof runtime.listSkills !== 'function') return undefined
|
|
102
|
+
let raw: unknown
|
|
103
|
+
try {
|
|
104
|
+
raw = await runtime.listSkills()
|
|
105
|
+
} catch {
|
|
106
|
+
return undefined
|
|
107
|
+
}
|
|
108
|
+
if (!Array.isArray(raw)) return undefined
|
|
109
|
+
const skills: JevHostSkill[] = []
|
|
110
|
+
for (const entry of raw) {
|
|
111
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) continue
|
|
112
|
+
const record = entry as { id?: unknown; description?: unknown }
|
|
113
|
+
if (typeof record.id !== 'string' || record.id.length === 0) continue
|
|
114
|
+
skills.push({
|
|
115
|
+
id: record.id,
|
|
116
|
+
...(typeof record.description === 'string' && record.description.length > 0
|
|
117
|
+
? { description: record.description }
|
|
118
|
+
: {}),
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
return skills
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function readCatalog(runtime: V2JevDecisionRuntime): Promise<JevDecisionCatalogEntry[]> {
|
|
125
|
+
const raw = await runtime.listModels()
|
|
126
|
+
if (!Array.isArray(raw)) throw new TypeError('Model catalog is not a list')
|
|
127
|
+
const entries: JevDecisionCatalogEntry[] = []
|
|
128
|
+
for (const model of raw) {
|
|
129
|
+
if (model === null || typeof model !== 'object' || Array.isArray(model)) continue
|
|
130
|
+
const record = model as Record<string, unknown>
|
|
131
|
+
if (!isNonBlankString(record.providerID) || !isNonBlankString(record.id)) continue
|
|
132
|
+
if (typeof record.type !== 'string') continue
|
|
133
|
+
entries.push({
|
|
134
|
+
providerID: record.providerID,
|
|
135
|
+
id: record.id,
|
|
136
|
+
type: record.type,
|
|
137
|
+
} as JevDecisionCatalogEntry)
|
|
138
|
+
}
|
|
139
|
+
return entries
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Run one explicit, gate-checked native Jev decision. Every failure path
|
|
144
|
+
* returns a bounded refusal JSON; the only caller-visible success output is
|
|
145
|
+
* the validated advice with `effect: 'none'`.
|
|
146
|
+
*/
|
|
147
|
+
export async function runJevDecision(
|
|
148
|
+
input: unknown,
|
|
149
|
+
toolContext: unknown,
|
|
150
|
+
runtime: V2JevDecisionRuntime,
|
|
151
|
+
): Promise<string> {
|
|
152
|
+
const context =
|
|
153
|
+
toolContext !== null && typeof toolContext === 'object' && !Array.isArray(toolContext)
|
|
154
|
+
? (toolContext as JevToolContext)
|
|
155
|
+
: undefined
|
|
156
|
+
if (context?.agent !== 'zeus') return refusal('CALLER_NOT_ZEUS')
|
|
157
|
+
const sessionID = context?.sessionID
|
|
158
|
+
const messageID = context?.messageID
|
|
159
|
+
if (!isNonBlankString(sessionID) || !isNonBlankString(messageID)) {
|
|
160
|
+
return refusal('CONTEXT_UNAVAILABLE')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let config: ReturnType<typeof readUserDecisionRouterConfig>
|
|
164
|
+
try {
|
|
165
|
+
config = readUserDecisionRouterConfig()
|
|
166
|
+
} catch {
|
|
167
|
+
return refusal('CONFIG_UNAVAILABLE')
|
|
168
|
+
}
|
|
169
|
+
if (!config.enabled) return refusal('DISABLED')
|
|
170
|
+
if (!config.egress_consent) return refusal('CONSENT_MISSING')
|
|
171
|
+
|
|
172
|
+
let catalog: JevDecisionCatalogEntry[]
|
|
173
|
+
try {
|
|
174
|
+
catalog = await readCatalog(runtime)
|
|
175
|
+
} catch {
|
|
176
|
+
return refusal('CATALOG_UNAVAILABLE')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const ledger = openLocalDecisionBudgetLedger({ dbPath: resolveLocalDecisionBudgetDbPath() })
|
|
180
|
+
try {
|
|
181
|
+
const selection = resolveNativeJevRoute(
|
|
182
|
+
config,
|
|
183
|
+
catalog,
|
|
184
|
+
(provider, model) => ledger.canReserve(provider, model).status === 'eligible',
|
|
185
|
+
)
|
|
186
|
+
if (!selection.ok) return refusal(selection.reasonCode)
|
|
187
|
+
|
|
188
|
+
if (typeof runtime.permissionAssert !== 'function') return refusal('PERMISSION_UNAVAILABLE')
|
|
189
|
+
const assertion = await assertDecisionEgressPermission(
|
|
190
|
+
runtime.permissionAssert,
|
|
191
|
+
buildDecisionEgressRequest({
|
|
192
|
+
sessionID,
|
|
193
|
+
messageID,
|
|
194
|
+
endpoint: nativeJevPermissionResource(
|
|
195
|
+
selection.selection.route.model.providerID,
|
|
196
|
+
selection.selection.route.model.id,
|
|
197
|
+
),
|
|
198
|
+
agent: 'zeus',
|
|
199
|
+
}),
|
|
200
|
+
)
|
|
201
|
+
if (assertion === 'deny') return refusal('PERMISSION_DENIED')
|
|
202
|
+
|
|
203
|
+
const requested = (input ?? {}) as { mode?: unknown; questions?: unknown }
|
|
204
|
+
const prepared =
|
|
205
|
+
requested.mode === undefined
|
|
206
|
+
? prepareJevDecisionRequest(selection.selection.route, input ?? {})
|
|
207
|
+
: isJevDecisionPreset(requested.mode)
|
|
208
|
+
? prepareJevPresetRequest(
|
|
209
|
+
selection.selection.route,
|
|
210
|
+
requested.mode,
|
|
211
|
+
input ?? {},
|
|
212
|
+
requested.mode === 'skills' ? await readHostSkills(runtime) : undefined,
|
|
213
|
+
)
|
|
214
|
+
: { ok: false as const, reasonCode: 'PRESET_INVALID' as const }
|
|
215
|
+
if (!prepared.ok) return refusal(prepared.reasonCode)
|
|
216
|
+
|
|
217
|
+
const reservation = ledger.reserve(
|
|
218
|
+
selection.selection.accountingProvider,
|
|
219
|
+
selection.selection.model,
|
|
220
|
+
)
|
|
221
|
+
if (reservation.status !== 'reserved') return refusal('RESERVATION_DENIED')
|
|
222
|
+
|
|
223
|
+
let response: unknown
|
|
224
|
+
try {
|
|
225
|
+
response = await runtime.decide(prepared.request)
|
|
226
|
+
} catch {
|
|
227
|
+
return refusal('DECISION_CALL_FAILED')
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const evidence = verifyNativeUsageForReservation(
|
|
231
|
+
{
|
|
232
|
+
reservationId: reservation.reservationId,
|
|
233
|
+
provider: selection.selection.accountingProvider,
|
|
234
|
+
model: selection.selection.model,
|
|
235
|
+
period: reservation.period,
|
|
236
|
+
},
|
|
237
|
+
response,
|
|
238
|
+
)
|
|
239
|
+
if (evidence === null) return refusal('USAGE_UNRECONCILED')
|
|
240
|
+
const reconciliation = ledger.reconcileVerified(reservation.reservationId, evidence)
|
|
241
|
+
if (reconciliation.status !== 'reconciled') return refusal('USAGE_UNRECONCILED')
|
|
242
|
+
|
|
243
|
+
const advice = consumeJevDecisionResult(response, prepared.request)
|
|
244
|
+
return JSON.stringify({
|
|
245
|
+
advisory: true,
|
|
246
|
+
effect: 'none',
|
|
247
|
+
reason: 'JEV_DECISION',
|
|
248
|
+
route: {
|
|
249
|
+
providerID: selection.selection.route.model.providerID,
|
|
250
|
+
id: selection.selection.route.model.id,
|
|
251
|
+
billing: selection.selection.route.billing,
|
|
252
|
+
},
|
|
253
|
+
...(requested.mode === undefined ? {} : { preset: requested.mode }),
|
|
254
|
+
answers: advice.answers,
|
|
255
|
+
missing: advice.missing,
|
|
256
|
+
usage: { costUsd: advice.costUsd, tokens: advice.tokens },
|
|
257
|
+
frozen: reconciliation.frozen,
|
|
258
|
+
})
|
|
259
|
+
} finally {
|
|
260
|
+
ledger.close()
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const TOOL_DESCRIPTION =
|
|
265
|
+
'Zeus-only advisory typed decisions via the host native Jev route (OpenCode Console or a ' +
|
|
266
|
+
'configured decision model). Two ways to ask: pass `mode: "skills"` to stack skills for the ' +
|
|
267
|
+
'state text (local prefilter shortlist, catalog fallback, plus every skill installed in the ' +
|
|
268
|
+
'host), `mode: "delegation"` to pick ' +
|
|
269
|
+
'a specialist, or pass explicit typed `questions` (choice, score, predicate). Returns ' +
|
|
270
|
+
'probabilistic answers with confidence. Requires decision-router egress consent and budget ' +
|
|
271
|
+
'caps; asks host permission first. It never dispatches agents, runs skills, executes tools, ' +
|
|
272
|
+
'or alters permissions — results are advisory only.'
|
|
273
|
+
|
|
274
|
+
const questionSchema = {
|
|
275
|
+
type: 'object',
|
|
276
|
+
additionalProperties: false,
|
|
277
|
+
required: ['type', 'name', 'instructions'],
|
|
278
|
+
properties: {
|
|
279
|
+
type: { type: 'string', enum: ['choice', 'score', 'predicate'] },
|
|
280
|
+
name: { type: 'string', minLength: 1, maxLength: 64 },
|
|
281
|
+
instructions: { type: 'string', minLength: 1, maxLength: 2000 },
|
|
282
|
+
choices: {
|
|
283
|
+
type: 'array',
|
|
284
|
+
minItems: 2,
|
|
285
|
+
maxItems: 16,
|
|
286
|
+
items: {
|
|
287
|
+
type: 'object',
|
|
288
|
+
additionalProperties: false,
|
|
289
|
+
required: ['value'],
|
|
290
|
+
properties: {
|
|
291
|
+
value: { type: 'string', minLength: 1, maxLength: 64 },
|
|
292
|
+
description: { type: 'string', minLength: 1, maxLength: 500 },
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
levels: {
|
|
297
|
+
type: 'array',
|
|
298
|
+
minItems: 2,
|
|
299
|
+
maxItems: 10,
|
|
300
|
+
items: {
|
|
301
|
+
type: 'object',
|
|
302
|
+
additionalProperties: false,
|
|
303
|
+
required: ['label'],
|
|
304
|
+
properties: {
|
|
305
|
+
label: { type: 'string', minLength: 1, maxLength: 64 },
|
|
306
|
+
description: { type: 'string', minLength: 1, maxLength: 500 },
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const JEV_INPUT_SCHEMA: Record<string, unknown> = {
|
|
314
|
+
type: 'object',
|
|
315
|
+
additionalProperties: false,
|
|
316
|
+
required: ['schemaVersion', 'state'],
|
|
317
|
+
properties: {
|
|
318
|
+
schemaVersion: { type: 'integer', const: 1 },
|
|
319
|
+
state: { type: 'string', minLength: 1, maxLength: 12_000 },
|
|
320
|
+
mode: { type: 'string', enum: ['skills', 'delegation'] },
|
|
321
|
+
questions: { type: 'array', minItems: 1, maxItems: 4, items: questionSchema },
|
|
322
|
+
},
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Create the V2 tool definition; registration is the caller's decision. */
|
|
326
|
+
export function createV2JevDecisionDefinition(runtime: V2JevDecisionRuntime): V2ToolDef {
|
|
327
|
+
return {
|
|
328
|
+
name: 'pantheon_jev_decide',
|
|
329
|
+
description: TOOL_DESCRIPTION,
|
|
330
|
+
input: JEV_INPUT_SCHEMA,
|
|
331
|
+
output: {},
|
|
332
|
+
execute: async (input: Record<string, unknown>, context: unknown) => ({
|
|
333
|
+
output: await runJevDecision(input, context, runtime),
|
|
334
|
+
}),
|
|
335
|
+
}
|
|
336
|
+
}
|