pantheon-opencode 1.6.2-beta.4 → 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.
Files changed (65) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +202 -29
  3. package/README.pt-BR.md +9 -0
  4. package/bin/pantheon-init.mjs +6 -1
  5. package/package.json +2 -1
  6. package/plugin.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/scripts/decision-router-budget.mjs +7 -8
  9. package/scripts/decision-router-v2-budget.mjs +218 -0
  10. package/scripts/decision-router-v2-egress.mjs +272 -0
  11. package/scripts/decision-router.mjs +268 -46
  12. package/scripts/docs-check-changelog.mjs +5 -3
  13. package/scripts/install/decision-layer-preview.mjs +376 -0
  14. package/scripts/install/decision-router-config.mjs +162 -34
  15. package/scripts/mcp_resources.py +11 -9
  16. package/scripts/release-notes.mjs +30 -7
  17. package/scripts/versioning.mjs +41 -5
  18. package/src/mcp/eval_store.py +11 -4
  19. package/src/mcp/mcp_resources.py +11 -9
  20. package/src/mcp/memory_mcp.py +293 -150
  21. package/src/pantheon/jev-decision-tool.ts +336 -0
  22. package/src/pantheon/jev-decisions.ts +625 -0
  23. package/src/pantheon/local-decision-budget.ts +4 -1
  24. package/src/pantheon/local-decision-egress-gate.ts +16 -136
  25. package/src/pantheon/local-decision-prompt.ts +184 -45
  26. package/src/pantheon/local-decision-provider-matrix.ts +14 -62
  27. package/src/pantheon/local-decision-skills.ts +115 -5
  28. package/src/pantheon/local-decision-tool.ts +35 -1
  29. package/src/pantheon/local-decision-turn.ts +15 -252
  30. package/src/pantheon/local-decision-usage-evidence.internal.ts +80 -119
  31. package/src/pantheon/v2-decision-budget.ts +456 -0
  32. package/src/pantheon/v2-decision-contracts.ts +300 -0
  33. package/src/pantheon/v2-decision-egress.ts +203 -0
  34. package/src/pantheon/v2-decision-events.ts +180 -0
  35. package/src/pantheon/v2-decision-heuristic.ts +121 -0
  36. package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
  37. package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
  38. package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
  39. package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
  40. package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
  41. package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
  42. package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
  43. package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
  44. package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
  45. package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
  46. package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
  47. package/src/pantheon/v2-decision-points.ts +242 -0
  48. package/src/pantheon/v2-decision-policy.ts +166 -0
  49. package/src/pantheon/v2-decision-premises.ts +146 -0
  50. package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
  51. package/src/pantheon/v2-decision-rank.ts +91 -0
  52. package/src/pantheon/v2-decision-registry.ts +391 -0
  53. package/src/pantheon/v2-decision-resource-ids.ts +127 -0
  54. package/src/pantheon/v2-decision-shadow.ts +123 -0
  55. package/src/pantheon/v2-decision-telemetry.ts +214 -0
  56. package/src/pantheon/v2-decision-verify.ts +51 -0
  57. package/src/pantheon/v2-native-decisions.ts +365 -0
  58. package/src/pantheon/v2-tools.ts +24 -2
  59. package/src/plugin-v2.ts +360 -14
  60. package/src/plugins/tui/dist/tui-v2.js +3 -3
  61. package/src/plugins/tui/dist/tui.js +1 -1
  62. package/src/plugins/tui/package-lock.json +2 -2
  63. package/src/plugins/tui/package.json +1 -1
  64. package/src/pantheon/local-decision-provider-protocol.ts +0 -335
  65. package/src/pantheon/local-decision-provider.internal.ts +0 -260
@@ -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
+ }