pantheon-opencode 1.6.1 → 1.6.2-beta.10
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/AGENTS.global.md +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +179 -0
- package/README.md +268 -20
- package/README.pt-BR.md +34 -11
- package/bin/pantheon-init.mjs +301 -32
- package/package.json +13 -4
- package/plugin.json +1 -1
- package/prompts/README.md +58 -0
- package/prompts/debug-issue.prompt.md +46 -0
- package/prompts/dynamic/agora-generated.txt +38 -0
- package/prompts/dynamic/orchestrate-generated.txt +51 -0
- package/prompts/focus.prompt.md +42 -0
- package/prompts/implement-feature.prompt.md +39 -0
- package/prompts/optimize-database.prompt.md +58 -0
- package/prompts/orchestrate-with-zeus.prompt.md +441 -0
- package/prompts/plan-architecture.prompt.md +59 -0
- package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
- package/prompts/quick-plan-large-feature.prompt.md +197 -0
- package/prompts/semantic-summarize.md +50 -0
- package/prompts/sketch.prompt.md +91 -0
- package/prompts/subtask.prompt.md +131 -0
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +1 -1
- package/scripts/decision-router-budget.mjs +780 -0
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +758 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/doctor.mjs +213 -45
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/component-selection.mjs +9 -4
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +560 -0
- package/scripts/install/health-check.mjs +20 -11
- package/scripts/install/interactive.mjs +103 -14
- package/scripts/install/interrupt.mjs +4 -3
- package/scripts/install/mcp-permissions.mjs +164 -0
- package/scripts/install/migrate.mjs +123 -72
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +411 -184
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plan.mjs +8 -1
- package/scripts/install/plugin.mjs +18 -1
- package/scripts/install/state.mjs +12 -0
- package/scripts/install/strings.mjs +22 -0
- package/scripts/install/v2-capabilities.mjs +5 -6
- package/scripts/install/venv.mjs +34 -17
- package/scripts/mcp_resources.py +11 -9
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/release-notes.mjs +30 -7
- package/scripts/restore.mjs +22 -10
- package/scripts/sandbox-env.sh +174 -0
- package/scripts/setup-v2-config.mjs +1703 -0
- package/scripts/setup.mjs +415 -0
- package/scripts/sync-tui.mjs +9 -1
- package/scripts/test-opencode-v2-sandbox.sh +448 -157
- package/scripts/update-skills-lock.mjs +30 -0
- package/scripts/versioning.mjs +41 -5
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +11 -3
- package/src/agents/apollo.md +6 -0
- package/src/agents/athena.md +7 -1
- package/src/agents/demeter.md +6 -2
- package/src/agents/gaia.md +5 -0
- package/src/agents/hephaestus.md +7 -2
- package/src/agents/hermes.md +14 -13
- package/src/agents/iris.md +6 -2
- package/src/agents/mnemosyne.md +21 -50
- package/src/agents/nyx.md +6 -2
- package/src/agents/prometheus.md +5 -1
- package/src/agents/talos.md +10 -1
- package/src/agents/themis.md +5 -1
- package/src/agents/zeus.md +61 -65
- package/src/instructions/agent-return-format.instructions.md +1 -1
- package/src/instructions/memory-protocol.instructions.md +3 -3
- package/src/instructions/test-economy.instructions.md +6 -6
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/mcp/pantheon_vision.py +37 -36
- package/src/pantheon/cost-command.ts +30 -133
- package/src/pantheon/jev-decision-tool.ts +347 -0
- package/src/pantheon/jev-decisions.ts +625 -0
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1046 -0
- package/src/pantheon/local-decision-egress-gate.ts +144 -0
- package/src/pantheon/local-decision-prompt.ts +256 -0
- package/src/pantheon/local-decision-provider-matrix.ts +44 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -0
- package/src/pantheon/local-decision-turn.ts +101 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/model-pricing.ts +1 -536
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-hook-engine.ts +307 -0
- package/src/pantheon/v2-native-decisions.ts +365 -0
- package/src/pantheon/v2-shell-hooks.ts +66 -2
- package/src/pantheon/v2-tools.ts +38 -15
- package/src/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +43 -10
- package/src/plugin-v2.ts +449 -79
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
- package/src/plugins/tui/dist/server-v2.d.ts +22 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +26 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +54 -51
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +762 -529
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/index-v2.ts +3 -6
- package/src/plugins/tui/package-lock.json +17 -2
- package/src/plugins/tui/package.json +6 -3
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/index-v2.tsx +360 -242
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/server-v2.ts +21 -0
- package/src/plugins/tui/src/sidebar-width.ts +129 -0
- package/src/plugins/tui/tsconfig.typecheck.json +1 -1
- package/src/plugins/tui/tsdown.config.ts +34 -5
- package/src/routing.yml +72 -13
- package/src/skills/README.md +4 -0
- package/src/skills/agent-coordination/SKILL.md +0 -3
- package/src/skills/artifact-management/SKILL.md +0 -3
- package/src/skills/auto-continue/SKILL.md +0 -3
- package/src/skills/code-review-checklist/SKILL.md +0 -3
- package/src/skills/context-compression/SKILL.md +0 -3
- package/src/skills/memory-bank/SKILL.md +6 -28
- package/src/skills/session-goal/SKILL.md +0 -3
- package/src/skills/simplify/SKILL.md +5 -4
- package/src/skills/tdd-with-agents/SKILL.md +0 -3
- package/src/skills/visual-review-pipeline/SKILL.md +0 -1
- package/src/pantheon/memory-context.ts +0 -1017
|
@@ -0,0 +1,347 @@
|
|
|
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
|
+
/**
|
|
91
|
+
* Refusal with the error CLASS only (`TypeError`, `RangeError`, …). The
|
|
92
|
+
* message never crosses into the chat: it can carry paths, config or provider
|
|
93
|
+
* detail, and the class alone already separates a detached-call failure from
|
|
94
|
+
* a host-side data failure.
|
|
95
|
+
*/
|
|
96
|
+
function refusalDetail(reasonCode: JevDecisionRunFailure, err: unknown): string {
|
|
97
|
+
const detail = err instanceof Error ? err.name : 'UnknownFailure'
|
|
98
|
+
return JSON.stringify({ advisory: false, effect: 'none', reasonCode, detail })
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isNonBlankString(value: unknown): value is string {
|
|
102
|
+
return typeof value === 'string' && value.trim().length > 0
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Read the host's installed skills for the stacking preset. Anything that is
|
|
107
|
+
* not a plain {id, description?} record is skipped; a missing or hostile
|
|
108
|
+
* registry degrades to the catalog-only preset. Reading the registry applies
|
|
109
|
+
* no trust: installation already was the user's manual, reviewed act.
|
|
110
|
+
*/
|
|
111
|
+
async function readHostSkills(runtime: V2JevDecisionRuntime): Promise<JevHostSkill[] | undefined> {
|
|
112
|
+
if (typeof runtime.listSkills !== 'function') return undefined
|
|
113
|
+
let raw: unknown
|
|
114
|
+
try {
|
|
115
|
+
raw = await runtime.listSkills()
|
|
116
|
+
} catch {
|
|
117
|
+
return undefined
|
|
118
|
+
}
|
|
119
|
+
if (!Array.isArray(raw)) return undefined
|
|
120
|
+
const skills: JevHostSkill[] = []
|
|
121
|
+
for (const entry of raw) {
|
|
122
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) continue
|
|
123
|
+
const record = entry as { id?: unknown; description?: unknown }
|
|
124
|
+
if (typeof record.id !== 'string' || record.id.length === 0) continue
|
|
125
|
+
skills.push({
|
|
126
|
+
id: record.id,
|
|
127
|
+
...(typeof record.description === 'string' && record.description.length > 0
|
|
128
|
+
? { description: record.description }
|
|
129
|
+
: {}),
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
return skills
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function readCatalog(runtime: V2JevDecisionRuntime): Promise<JevDecisionCatalogEntry[]> {
|
|
136
|
+
const raw = await runtime.listModels()
|
|
137
|
+
if (!Array.isArray(raw)) throw new TypeError('Model catalog is not a list')
|
|
138
|
+
const entries: JevDecisionCatalogEntry[] = []
|
|
139
|
+
for (const model of raw) {
|
|
140
|
+
if (model === null || typeof model !== 'object' || Array.isArray(model)) continue
|
|
141
|
+
const record = model as Record<string, unknown>
|
|
142
|
+
if (!isNonBlankString(record.providerID) || !isNonBlankString(record.id)) continue
|
|
143
|
+
if (typeof record.type !== 'string') continue
|
|
144
|
+
entries.push({
|
|
145
|
+
providerID: record.providerID,
|
|
146
|
+
id: record.id,
|
|
147
|
+
type: record.type,
|
|
148
|
+
} as JevDecisionCatalogEntry)
|
|
149
|
+
}
|
|
150
|
+
return entries
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Run one explicit, gate-checked native Jev decision. Every failure path
|
|
155
|
+
* returns a bounded refusal JSON; the only caller-visible success output is
|
|
156
|
+
* the validated advice with `effect: 'none'`.
|
|
157
|
+
*/
|
|
158
|
+
export async function runJevDecision(
|
|
159
|
+
input: unknown,
|
|
160
|
+
toolContext: unknown,
|
|
161
|
+
runtime: V2JevDecisionRuntime,
|
|
162
|
+
): Promise<string> {
|
|
163
|
+
const context =
|
|
164
|
+
toolContext !== null && typeof toolContext === 'object' && !Array.isArray(toolContext)
|
|
165
|
+
? (toolContext as JevToolContext)
|
|
166
|
+
: undefined
|
|
167
|
+
if (context?.agent !== 'zeus') return refusal('CALLER_NOT_ZEUS')
|
|
168
|
+
const sessionID = context?.sessionID
|
|
169
|
+
const messageID = context?.messageID
|
|
170
|
+
if (!isNonBlankString(sessionID) || !isNonBlankString(messageID)) {
|
|
171
|
+
return refusal('CONTEXT_UNAVAILABLE')
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let config: ReturnType<typeof readUserDecisionRouterConfig>
|
|
175
|
+
try {
|
|
176
|
+
config = readUserDecisionRouterConfig()
|
|
177
|
+
} catch {
|
|
178
|
+
return refusal('CONFIG_UNAVAILABLE')
|
|
179
|
+
}
|
|
180
|
+
if (!config.enabled) return refusal('DISABLED')
|
|
181
|
+
if (!config.egress_consent) return refusal('CONSENT_MISSING')
|
|
182
|
+
|
|
183
|
+
let catalog: JevDecisionCatalogEntry[]
|
|
184
|
+
try {
|
|
185
|
+
catalog = await readCatalog(runtime)
|
|
186
|
+
} catch (err) {
|
|
187
|
+
return refusalDetail('CATALOG_UNAVAILABLE', err)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const ledger = openLocalDecisionBudgetLedger({ dbPath: resolveLocalDecisionBudgetDbPath() })
|
|
191
|
+
try {
|
|
192
|
+
const selection = resolveNativeJevRoute(
|
|
193
|
+
config,
|
|
194
|
+
catalog,
|
|
195
|
+
(provider, model) => ledger.canReserve(provider, model).status === 'eligible',
|
|
196
|
+
)
|
|
197
|
+
if (!selection.ok) return refusal(selection.reasonCode)
|
|
198
|
+
|
|
199
|
+
if (typeof runtime.permissionAssert !== 'function') return refusal('PERMISSION_UNAVAILABLE')
|
|
200
|
+
const assertion = await assertDecisionEgressPermission(
|
|
201
|
+
runtime.permissionAssert,
|
|
202
|
+
buildDecisionEgressRequest({
|
|
203
|
+
sessionID,
|
|
204
|
+
messageID,
|
|
205
|
+
endpoint: nativeJevPermissionResource(
|
|
206
|
+
selection.selection.route.model.providerID,
|
|
207
|
+
selection.selection.route.model.id,
|
|
208
|
+
),
|
|
209
|
+
agent: 'zeus',
|
|
210
|
+
}),
|
|
211
|
+
)
|
|
212
|
+
if (assertion === 'deny') return refusal('PERMISSION_DENIED')
|
|
213
|
+
|
|
214
|
+
const requested = (input ?? {}) as { mode?: unknown; questions?: unknown }
|
|
215
|
+
const prepared =
|
|
216
|
+
requested.mode === undefined
|
|
217
|
+
? prepareJevDecisionRequest(selection.selection.route, input ?? {})
|
|
218
|
+
: isJevDecisionPreset(requested.mode)
|
|
219
|
+
? prepareJevPresetRequest(
|
|
220
|
+
selection.selection.route,
|
|
221
|
+
requested.mode,
|
|
222
|
+
input ?? {},
|
|
223
|
+
requested.mode === 'skills' ? await readHostSkills(runtime) : undefined,
|
|
224
|
+
)
|
|
225
|
+
: { ok: false as const, reasonCode: 'PRESET_INVALID' as const }
|
|
226
|
+
if (!prepared.ok) return refusal(prepared.reasonCode)
|
|
227
|
+
|
|
228
|
+
const reservation = ledger.reserve(
|
|
229
|
+
selection.selection.accountingProvider,
|
|
230
|
+
selection.selection.model,
|
|
231
|
+
)
|
|
232
|
+
if (reservation.status !== 'reserved') return refusal('RESERVATION_DENIED')
|
|
233
|
+
|
|
234
|
+
let response: unknown
|
|
235
|
+
try {
|
|
236
|
+
response = await runtime.decide(prepared.request)
|
|
237
|
+
} catch (err) {
|
|
238
|
+
return refusalDetail('DECISION_CALL_FAILED', err)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const evidence = verifyNativeUsageForReservation(
|
|
242
|
+
{
|
|
243
|
+
reservationId: reservation.reservationId,
|
|
244
|
+
provider: selection.selection.accountingProvider,
|
|
245
|
+
model: selection.selection.model,
|
|
246
|
+
period: reservation.period,
|
|
247
|
+
},
|
|
248
|
+
response,
|
|
249
|
+
)
|
|
250
|
+
if (evidence === null) return refusal('USAGE_UNRECONCILED')
|
|
251
|
+
const reconciliation = ledger.reconcileVerified(reservation.reservationId, evidence)
|
|
252
|
+
if (reconciliation.status !== 'reconciled') return refusal('USAGE_UNRECONCILED')
|
|
253
|
+
|
|
254
|
+
const advice = consumeJevDecisionResult(response, prepared.request)
|
|
255
|
+
return JSON.stringify({
|
|
256
|
+
advisory: true,
|
|
257
|
+
effect: 'none',
|
|
258
|
+
reason: 'JEV_DECISION',
|
|
259
|
+
route: {
|
|
260
|
+
providerID: selection.selection.route.model.providerID,
|
|
261
|
+
id: selection.selection.route.model.id,
|
|
262
|
+
billing: selection.selection.route.billing,
|
|
263
|
+
},
|
|
264
|
+
...(requested.mode === undefined ? {} : { preset: requested.mode }),
|
|
265
|
+
answers: advice.answers,
|
|
266
|
+
missing: advice.missing,
|
|
267
|
+
usage: { costUsd: advice.costUsd, tokens: advice.tokens },
|
|
268
|
+
frozen: reconciliation.frozen,
|
|
269
|
+
})
|
|
270
|
+
} finally {
|
|
271
|
+
ledger.close()
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const TOOL_DESCRIPTION =
|
|
276
|
+
'Zeus-only advisory typed decisions via the host native Jev route (OpenCode Console or a ' +
|
|
277
|
+
'configured decision model). Two ways to ask: pass `mode: "skills"` to stack skills for the ' +
|
|
278
|
+
'state text (local prefilter shortlist, catalog fallback, plus every skill installed in the ' +
|
|
279
|
+
'host), `mode: "delegation"` to pick ' +
|
|
280
|
+
'a specialist, or pass explicit typed `questions` (choice, score, predicate). Returns ' +
|
|
281
|
+
'probabilistic answers with confidence. Requires decision-router egress consent and budget ' +
|
|
282
|
+
'caps; asks host permission first. It never dispatches agents, runs skills, executes tools, ' +
|
|
283
|
+
'or alters permissions — results are advisory only.'
|
|
284
|
+
|
|
285
|
+
const questionSchema = {
|
|
286
|
+
type: 'object',
|
|
287
|
+
additionalProperties: false,
|
|
288
|
+
required: ['type', 'name', 'instructions'],
|
|
289
|
+
properties: {
|
|
290
|
+
type: { type: 'string', enum: ['choice', 'score', 'predicate'] },
|
|
291
|
+
name: { type: 'string', minLength: 1, maxLength: 64 },
|
|
292
|
+
instructions: { type: 'string', minLength: 1, maxLength: 2000 },
|
|
293
|
+
choices: {
|
|
294
|
+
type: 'array',
|
|
295
|
+
minItems: 2,
|
|
296
|
+
maxItems: 16,
|
|
297
|
+
items: {
|
|
298
|
+
type: 'object',
|
|
299
|
+
additionalProperties: false,
|
|
300
|
+
required: ['value'],
|
|
301
|
+
properties: {
|
|
302
|
+
value: { type: 'string', minLength: 1, maxLength: 64 },
|
|
303
|
+
description: { type: 'string', minLength: 1, maxLength: 500 },
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
levels: {
|
|
308
|
+
type: 'array',
|
|
309
|
+
minItems: 2,
|
|
310
|
+
maxItems: 10,
|
|
311
|
+
items: {
|
|
312
|
+
type: 'object',
|
|
313
|
+
additionalProperties: false,
|
|
314
|
+
required: ['label'],
|
|
315
|
+
properties: {
|
|
316
|
+
label: { type: 'string', minLength: 1, maxLength: 64 },
|
|
317
|
+
description: { type: 'string', minLength: 1, maxLength: 500 },
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const JEV_INPUT_SCHEMA: Record<string, unknown> = {
|
|
325
|
+
type: 'object',
|
|
326
|
+
additionalProperties: false,
|
|
327
|
+
required: ['schemaVersion', 'state'],
|
|
328
|
+
properties: {
|
|
329
|
+
schemaVersion: { type: 'integer', const: 1 },
|
|
330
|
+
state: { type: 'string', minLength: 1, maxLength: 12_000 },
|
|
331
|
+
mode: { type: 'string', enum: ['skills', 'delegation'] },
|
|
332
|
+
questions: { type: 'array', minItems: 1, maxItems: 4, items: questionSchema },
|
|
333
|
+
},
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Create the V2 tool definition; registration is the caller's decision. */
|
|
337
|
+
export function createV2JevDecisionDefinition(runtime: V2JevDecisionRuntime): V2ToolDef {
|
|
338
|
+
return {
|
|
339
|
+
name: 'pantheon_jev_decide',
|
|
340
|
+
description: TOOL_DESCRIPTION,
|
|
341
|
+
input: JEV_INPUT_SCHEMA,
|
|
342
|
+
output: {},
|
|
343
|
+
execute: async (input: Record<string, unknown>, context: unknown) => ({
|
|
344
|
+
output: await runJevDecision(input, context, runtime),
|
|
345
|
+
}),
|
|
346
|
+
}
|
|
347
|
+
}
|