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
@@ -1,14 +1,10 @@
1
1
  /**
2
- * Consent/config gate and host assertion contract for the single
3
- * decision-provider egress action.
2
+ * Host kill-switch contract for the single decision-egress action.
4
3
  *
5
- * Source of truth: the user-level decision-router configuration. Egress
6
- * requires `enabled`, `egress_consent: true`, exactly one enabled and cap-valid
7
- * provider/model candidate, a confirmed UTC budget period, and positive
8
- * user/provider/model caps. Local mode, missing consent, or an unconfirmed
9
- * period means no request, and the host is not even asked.
10
- *
11
- * `permission.assert` is a host kill-switch layered on top, never consent:
4
+ * `permission.assert` is a host kill-switch layered on top of the user-level
5
+ * config, never consent itself. The native `pantheon_jev_decide` tool asks it
6
+ * with the logical resource `pantheon-native-decisions://<providerID>/<id>`
7
+ * after its own config/route/ledger gates pass.
12
8
  *
13
9
  * - Deny is observable: the host throws (`Permission.BlockedError`, whose
14
10
  * message is `Permission denied: <action>` unless an evaluate hook supplied a
@@ -16,44 +12,16 @@
16
12
  * - Allow is NOT observable as a positive value. The measured host contract
17
13
  * (`Permission.assert` in the bundled opencode host) resolves `undefined` when
18
14
  * every rule admits the request. A resolved non-denial therefore only means
19
- * "the host did not block it"; the configuration above remains the authority.
15
+ * "the host did not block it"; the configuration gates remain the authority.
20
16
  *
21
17
  * The custom action has no default rule, and the measured v2.2.0 canary showed
22
18
  * the host is NOT deny-by-default for it: an assertion with no matching rule
23
- * resolved allow. The config/consent gate above is therefore the source of
24
- * truth for authorization, and an explicit `deny` rule is the kill-switch; the
25
- * fix for a blocked host is an explicit user permission rule for
26
- * `decision.egress`, not a bypass in this plugin. This module never retries,
27
- * downgrades, or reinterprets a denial.
28
- *
29
- * `assert` is called by the plugin in the same process it protects. It is not a
30
- * boundary against hostile same-process code; the fixed endpoints, redirect
31
- * refusal, timeout, response cap, and accounting ledger are the real protection
32
- * against an accidental or over-broad egress.
33
- *
34
- * Canary note: a real host canary of v2.2.0 observed that `permission.assert`
35
- * reaches the `evaluate` hook on the allow path and is not invoked for an
36
- * explicit deny, that an assertion with no rule for this custom action resolved
37
- * allow rather than deny, and that the host accepts a rule under root
38
- * `permission`/`permissions` or `agents.<id>.permissions` while ignoring an
39
- * `agents.<id>.permission` map. Egress therefore must not depend on an
40
- * evaluate-hook decision, and the plugin does not mint or consume an
41
- * allowance.
19
+ * resolved allow. The config/consent gate is therefore the source of truth for
20
+ * authorization, and an explicit `deny` rule is the kill-switch; the fix for a
21
+ * blocked host is an explicit user permission rule for `decision.egress`, not a
22
+ * bypass in this plugin. This module never retries, downgrades, or reinterprets
23
+ * a denial. Pantheon owns no transport: there is no endpoint to fall back to.
42
24
  */
43
- import {
44
- readUserDecisionRouterConfig,
45
- resolveUserDecisionRouterCandidate,
46
- type UserDecisionRouterCandidate,
47
- } from '../../scripts/install/decision-router-config.mjs'
48
- import {
49
- openLocalDecisionBudgetLedger,
50
- resolveLocalDecisionBudgetDbPath,
51
- } from './local-decision-budget.ts'
52
- import {
53
- DECISION_PROVIDER_ADAPTERS,
54
- type DecisionProviderId,
55
- } from './local-decision-provider-matrix.ts'
56
-
57
25
  /**
58
26
  * Custom host action, distinct from `webfetch`. It has no default host rule; the
59
27
  * measured host resolves an unruled assertion as allow, so only an explicit
@@ -70,16 +38,6 @@ export interface DecisionEgressSource {
70
38
  messageID: string
71
39
  }
72
40
 
73
- /** Reason codes shared with the provider runner's fallback contract. */
74
- export type DecisionEgressGateReason =
75
- | 'CONFIG_UNAVAILABLE'
76
- | 'DISABLED'
77
- | 'CONSENT_MISSING'
78
- | 'NO_ELIGIBLE_CANDIDATE'
79
- | 'CAP_OR_PERIOD_DENIED'
80
- | 'PERMISSION_UNAVAILABLE'
81
- | 'PERMISSION_DENIED'
82
-
83
41
  export type PermissionAssert = (input: Record<string, unknown>) => Promise<unknown>
84
42
 
85
43
  export type DecisionEgressAssertion = 'allow' | 'deny'
@@ -103,9 +61,9 @@ export function decisionPermissionSource(
103
61
  }
104
62
 
105
63
  /**
106
- * The only shape the provider runner and the cached-turn recheck send to
107
- * `permission.assert`. Keeping it in one place prevents the prompt-source
108
- * schema mismatch the canary caught.
64
+ * The only shape the native tool sends to `permission.assert`. The resource is
65
+ * a logical URI (the host owns any real endpoint), so permission rules can
66
+ * target the native route without exposing a URL.
109
67
  */
110
68
  export function buildDecisionEgressRequest(input: {
111
69
  sessionID: string
@@ -169,8 +127,8 @@ export function isDecisionAssertionDenial(result: unknown): boolean {
169
127
  *
170
128
  * A throw is a deny. A resolved explicit denial marker is a deny. Everything
171
129
  * else is `allow` — not because the host promised consent, but because the
172
- * host's allow path is indistinguishable from `undefined`; the config gate
173
- * above is what actually authorizes egress.
130
+ * host's allow path is indistinguishable from `undefined`; the config gates
131
+ * are what actually authorize egress.
174
132
  */
175
133
  export async function assertDecisionEgressPermission(
176
134
  permissionAssert: PermissionAssert,
@@ -184,81 +142,3 @@ export async function assertDecisionEgressPermission(
184
142
  }
185
143
  return isDecisionAssertionDenial(result) ? 'deny' : 'allow'
186
144
  }
187
-
188
- export interface CapValidDecisionCandidate {
189
- provider: DecisionProviderId
190
- adapter: (typeof DECISION_PROVIDER_ADAPTERS)[DecisionProviderId]
191
- candidate: UserDecisionRouterCandidate
192
- }
193
-
194
- /**
195
- * Single cap-valid selection shared by the provider runner and the cached-turn
196
- * recheck. Opens the ledger, keeps only enabled, egress-eligible candidates
197
- * whose period and caps admit a reservation, resolves the preference, and
198
- * requires the resolved model to match the fixed matrix row.
199
- *
200
- * Throws when the ledger cannot be opened or queried; callers map that to
201
- * `CAP_OR_PERIOD_DENIED`. Returns `null` when no candidate qualifies.
202
- */
203
- export function selectCapValidDecisionCandidate(
204
- config: ReturnType<typeof readUserDecisionRouterConfig>,
205
- ): CapValidDecisionCandidate | null {
206
- const ledger = openLocalDecisionBudgetLedger({ dbPath: resolveLocalDecisionBudgetDbPath() })
207
- try {
208
- const valid: UserDecisionRouterCandidate[] = []
209
- for (const candidate of config.enabled_candidates) {
210
- const provider = candidate.provider as DecisionProviderId
211
- const adapter = DECISION_PROVIDER_ADAPTERS[provider]
212
- if (adapter === undefined || !adapter.egressEligible) continue
213
- if (ledger.canReserve(adapter.accountingProvider, candidate.model).status !== 'eligible') {
214
- continue
215
- }
216
- valid.push(candidate)
217
- }
218
- const selected = resolveUserDecisionRouterCandidate(config, valid)
219
- if (selected === null) return null
220
- const provider = selected.provider as DecisionProviderId
221
- const adapter = DECISION_PROVIDER_ADAPTERS[provider]
222
- if (adapter === undefined || !adapter.egressEligible) return null
223
- if (selected.model !== adapter.model) return null
224
- return { provider, adapter, candidate: selected }
225
- } finally {
226
- ledger.close()
227
- }
228
- }
229
-
230
- export type DecisionEgressConsent =
231
- | { ok: true; selected: CapValidDecisionCandidate }
232
- | {
233
- ok: false
234
- reasonCode: Exclude<DecisionEgressGateReason, 'PERMISSION_UNAVAILABLE' | 'PERMISSION_DENIED'>
235
- }
236
-
237
- /**
238
- * Evaluate the consent/config gate without touching the network or the host.
239
- *
240
- * Callers run this BEFORE `permission.assert`: an invalid configuration is not
241
- * worth an interactive prompt, and the host must not be asked to approve a
242
- * request that the user's own configuration already forbids.
243
- */
244
- export function resolveDecisionEgressConsent(): DecisionEgressConsent {
245
- let config: ReturnType<typeof readUserDecisionRouterConfig>
246
- try {
247
- config = readUserDecisionRouterConfig()
248
- } catch {
249
- return { ok: false, reasonCode: 'CONFIG_UNAVAILABLE' }
250
- }
251
- if (!config.enabled) return { ok: false, reasonCode: 'DISABLED' }
252
- if (!config.egress_consent || config.selection.mode === 'local') {
253
- return { ok: false, reasonCode: 'CONSENT_MISSING' }
254
- }
255
-
256
- let selected: CapValidDecisionCandidate | null
257
- try {
258
- selected = selectCapValidDecisionCandidate(config)
259
- } catch {
260
- return { ok: false, reasonCode: 'CAP_OR_PERIOD_DENIED' }
261
- }
262
- if (selected === null) return { ok: false, reasonCode: 'NO_ELIGIBLE_CANDIDATE' }
263
- return { ok: true, selected }
264
- }
@@ -1,12 +1,64 @@
1
- import { decideForTurn, type TurnDecision, type TurnDecisionInput } from './local-decision-turn.ts'
1
+ import { decideLocalForTurn, type TurnDecision } from './local-decision-turn.ts'
2
2
  import { isPantheonAgentId, isPantheonSkillId } from './pantheon-decision-catalog.ts'
3
3
 
4
4
  const MARKER_PREFIX = '<!-- pantheon-decision-router:v1'
5
5
  const MARKER_PATTERN = /<!-- pantheon-decision-router:v1\b[^>]*-->/
6
6
 
7
+ /** The host sends the *string* `"undefined"` for absent prompt fields (F-08). */
8
+ const MEASURED_SENTINELS: ReadonlySet<string> = new Set(['undefined', 'null'])
9
+
10
+ /** Where the observed skill list came from: the prompt array, the draft, or nowhere. */
11
+ export type SkillsSource = 'none' | 'prompt' | 'draft'
12
+
13
+ /**
14
+ * Why the skill outcome is what it is. Tokens only — no content, no count of
15
+ * user text. Every result carries one, so an empty selection is never silent.
16
+ */
17
+ export type PromptApplicationReason =
18
+ | 'invalid.payload'
19
+ | 'request.empty'
20
+ | 'marker.present'
21
+ | 'decision.inactive'
22
+ | 'selection.empty'
23
+ | 'skills.source.prompt'
24
+ | 'skills.source.draft'
25
+ | 'skills.source.absent'
26
+ | 'skills.source.empty'
27
+ | 'skills.source.unstable'
28
+ | 'skills.selection.disjoint'
29
+ | 'skills.synthetic.narrowed'
30
+
7
31
  export interface PromptApplicationResult {
8
32
  markerApplied: boolean
9
33
  skillsFiltered: boolean
34
+ /** Observable source of the skill list; `none` in the measured host shape (F-08). */
35
+ skillsSource: SkillsSource
36
+ /** Always present: explains the skill outcome, including every empty selection. */
37
+ reason: PromptApplicationReason
38
+ }
39
+
40
+ export interface SkillSourceResolution {
41
+ readonly skillsSource: SkillsSource
42
+ /** Stable identifiers found in the chosen source, deduplicated, in order. */
43
+ readonly skillIds: readonly string[]
44
+ readonly reason: PromptApplicationReason
45
+ }
46
+
47
+ interface SkillNarrowing {
48
+ readonly skillsFiltered: boolean
49
+ readonly skillsSource: SkillsSource
50
+ readonly reason: PromptApplicationReason
51
+ }
52
+
53
+ /** True when the value is the measured placeholder string, not real data. */
54
+ function isMeasuredSentinel(value: unknown): boolean {
55
+ return typeof value === 'string' && MEASURED_SENTINELS.has(value)
56
+ }
57
+
58
+ /** Normalize a measured prompt field: a sentinel string or null means "absent". */
59
+ export function normalizeMeasuredValue(value: unknown): unknown {
60
+ if (value === null || value === undefined) return undefined
61
+ return isMeasuredSentinel(value) ? undefined : value
10
62
  }
11
63
 
12
64
  function skillIdentifier(value: unknown): string | undefined {
@@ -19,28 +71,103 @@ function skillIdentifier(value: unknown): string | undefined {
19
71
  return undefined
20
72
  }
21
73
 
74
+ function identifiers(list: readonly unknown[]): { ids: string[]; unstable: boolean } {
75
+ const ids: string[] = []
76
+ let unstable = false
77
+ for (const item of list) {
78
+ const identifier = skillIdentifier(item)
79
+ if (identifier === undefined) unstable = true
80
+ else if (!ids.includes(identifier)) ids.push(identifier)
81
+ }
82
+ return { ids, unstable }
83
+ }
84
+
22
85
  /**
23
- * Best-effort rewrite of the host's pre-resolution skill list. If the host
24
- * list is absent/empty, has no stable identifiers, or the advisory selection is
25
- * empty or does not intersect the host list, everything is left untouched: an
26
- * empty advisory selection must never erase skills the host or user chose. This
27
- * is not measured as a token saving; it only narrows what the host may offer
28
- * for this turn.
86
+ * Resolve the observed skill list and say where it came from.
87
+ *
88
+ * The prompt list wins when it is a real array. Otherwise the per-turn draft
89
+ * (`ctx.skill.list()`, F-06) is reported as `draft`. The measured host shape
90
+ * carries the sentinel string `"undefined"` (F-08), which is treated as absent.
91
+ *
92
+ * The `draft` branch has **no production caller**: the shipped prompt hook calls
93
+ * `applyTurnDecisionToPrompt(prompt, decision)` without `skillsDraft`, and
94
+ * `ctx.skill.list()` is never read by it. At runtime `skillsSource` is therefore
95
+ * `none` or `prompt` only, and the `draft` source is exercised by tests alone.
29
96
  */
30
- function filterSkills(prompt: Record<string, unknown>, skillIds: readonly string[]): boolean {
31
- const skills = prompt.skills
32
- if (!Array.isArray(skills) || skills.length === 0) return false
33
- if (skillIds.length === 0) return false
34
- const identifiers = skills.map(skillIdentifier)
35
- if (identifiers.some((identifier) => identifier === undefined)) return false
36
- const selected = new Set(skillIds)
37
- const filtered = skills.filter((_, index) => {
38
- const identifier = identifiers[index]
97
+ export function resolveSkillSource(
98
+ promptSkills: unknown,
99
+ draftSkills?: unknown,
100
+ ): SkillSourceResolution {
101
+ const promptList = normalizeMeasuredValue(promptSkills)
102
+ const draftList = normalizeMeasuredValue(draftSkills)
103
+
104
+ if (Array.isArray(promptList) && promptList.length > 0) {
105
+ const resolved = identifiers(promptList)
106
+ return {
107
+ skillsSource: 'prompt',
108
+ skillIds: resolved.ids,
109
+ reason: resolved.unstable ? 'skills.source.unstable' : 'skills.source.prompt',
110
+ }
111
+ }
112
+ if (Array.isArray(draftList) && draftList.length > 0) {
113
+ const resolved = identifiers(draftList)
114
+ return {
115
+ skillsSource: 'draft',
116
+ skillIds: resolved.ids,
117
+ reason: resolved.unstable ? 'skills.source.unstable' : 'skills.source.draft',
118
+ }
119
+ }
120
+ return {
121
+ skillsSource: 'none',
122
+ skillIds: [],
123
+ reason: Array.isArray(promptList) ? 'skills.source.empty' : 'skills.source.absent',
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Best-effort narrowing of the host's pre-resolution skill list.
129
+ *
130
+ * Only a real prompt array can be narrowed, and an empty advisory selection
131
+ * must never erase skills the host or user chose. The measured host shape is
132
+ * the sentinel string (F-08), so this is unreachable on the default path: P2 is
133
+ * an empirical no-op there (F-09). The array shape is synthetic — never
134
+ * observed — and its outcome is not a measured effect: PROBE-E measured no
135
+ * effect for any `prompt.skills`/`prompt.agents` mutation (F-24), while C6 as a
136
+ * question is closed for `skill.transform` and `prompt.text`.
137
+ */
138
+ function narrowSkills(
139
+ prompt: Record<string, unknown>,
140
+ selection: readonly string[],
141
+ draftSkills?: unknown,
142
+ ): SkillNarrowing {
143
+ const resolution = resolveSkillSource(prompt.skills, draftSkills)
144
+ if (selection.length === 0) {
145
+ return {
146
+ skillsFiltered: false,
147
+ skillsSource: resolution.skillsSource,
148
+ reason: 'selection.empty',
149
+ }
150
+ }
151
+ if (resolution.skillsSource !== 'prompt') {
152
+ return {
153
+ skillsFiltered: false,
154
+ skillsSource: resolution.skillsSource,
155
+ reason: resolution.reason,
156
+ }
157
+ }
158
+ if (resolution.skillIds.length === 0) {
159
+ return { skillsFiltered: false, skillsSource: 'prompt', reason: 'skills.source.unstable' }
160
+ }
161
+ const selected = new Set(selection)
162
+ const kept = (prompt.skills as readonly unknown[]).filter((item) => {
163
+ const identifier = skillIdentifier(item)
39
164
  return identifier !== undefined && selected.has(identifier)
40
165
  })
41
- if (filtered.length === 0) return false
42
- prompt.skills = filtered
43
- return true
166
+ if (kept.length === 0) {
167
+ return { skillsFiltered: false, skillsSource: 'prompt', reason: 'skills.selection.disjoint' }
168
+ }
169
+ prompt.skills = kept
170
+ return { skillsFiltered: true, skillsSource: 'prompt', reason: 'skills.synthetic.narrowed' }
44
171
  }
45
172
 
46
173
  function buildMarker(decision: TurnDecision): string | null {
@@ -56,32 +183,39 @@ function buildMarker(decision: TurnDecision): string | null {
56
183
  /**
57
184
  * Apply an advisory decision to the host prompt payload in place. It never
58
185
  * dispatches, changes permissions, or removes a pre-existing host marker.
186
+ * `skillsDraft` is the per-turn draft list; it is observed for `skillsSource`
187
+ * and never applied to admission.
59
188
  */
60
189
  export function applyTurnDecisionToPrompt(
61
190
  prompt: unknown,
62
191
  decision: TurnDecision | null,
192
+ skillsDraft?: unknown,
63
193
  ): PromptApplicationResult {
64
- const result: PromptApplicationResult = { markerApplied: false, skillsFiltered: false }
65
- if (
66
- prompt === null ||
67
- typeof prompt !== 'object' ||
68
- Array.isArray(prompt) ||
69
- decision === null ||
70
- !decision.active
71
- ) {
72
- return result
194
+ const invalid: PromptApplicationResult = {
195
+ markerApplied: false,
196
+ skillsFiltered: false,
197
+ skillsSource: 'none',
198
+ reason: 'invalid.payload',
73
199
  }
200
+ if (prompt === null || typeof prompt !== 'object' || Array.isArray(prompt)) return invalid
201
+ if (decision === null || !decision.active) return { ...invalid, reason: 'decision.inactive' }
74
202
  const target = prompt as Record<string, unknown>
75
- result.skillsFiltered = filterSkills(
203
+ const narrowing = narrowSkills(
76
204
  target,
77
205
  decision.skillIds.filter((id) => isPantheonSkillId(id)),
206
+ skillsDraft,
78
207
  )
208
+ const result: PromptApplicationResult = {
209
+ markerApplied: false,
210
+ skillsFiltered: narrowing.skillsFiltered,
211
+ skillsSource: narrowing.skillsSource,
212
+ reason: narrowing.reason,
213
+ }
79
214
  if (typeof target.text !== 'string' || target.text.includes(MARKER_PREFIX)) return result
80
215
  const marker = buildMarker(decision)
81
216
  if (marker === null) return result
82
217
  target.text = `${target.text}\n\n${marker}`
83
- result.markerApplied = true
84
- return result
218
+ return { ...result, markerApplied: true }
85
219
  }
86
220
 
87
221
  /** True when the prompt already carries a decision-router marker. */
@@ -89,35 +223,40 @@ export function hasDecisionRouterMarker(text: unknown): boolean {
89
223
  return typeof text === 'string' && MARKER_PATTERN.test(text)
90
224
  }
91
225
 
92
- /**
93
- * Compute and apply the advisory decision to a host admission payload. The
94
- * optional `requestText` lets the caller keep Pantheon's own visual context out
95
- * of the decision input; malformed payloads are a no-op.
96
- */
226
+ /** Apply the local advisory selector while keeping provider egress out of this route. */
97
227
  export async function applyDecisionRouterToPrompt(
98
228
  admission: unknown,
99
- permissionAssert?: TurnDecisionInput['permissionAssert'],
100
229
  requestText?: string,
101
230
  ): Promise<PromptApplicationResult> {
102
- const none: PromptApplicationResult = { markerApplied: false, skillsFiltered: false }
103
- if (admission === null || typeof admission !== 'object' || Array.isArray(admission)) return none
231
+ const none = (reason: PromptApplicationReason): PromptApplicationResult => ({
232
+ markerApplied: false,
233
+ skillsFiltered: false,
234
+ skillsSource: 'none',
235
+ reason,
236
+ })
237
+ if (admission === null || typeof admission !== 'object' || Array.isArray(admission)) {
238
+ return none('invalid.payload')
239
+ }
104
240
  const event = admission as { sessionID?: unknown; messageID?: unknown; prompt?: unknown }
105
241
  const prompt = event.prompt
106
- if (prompt === null || typeof prompt !== 'object' || Array.isArray(prompt)) return none
242
+ if (prompt === null || typeof prompt !== 'object' || Array.isArray(prompt)) {
243
+ return none('invalid.payload')
244
+ }
107
245
  const promptText = (prompt as { text?: unknown }).text
108
- if (typeof promptText !== 'string' || promptText.trim().length === 0) return none
246
+ if (typeof promptText !== 'string' || promptText.trim().length === 0) {
247
+ return none('request.empty')
248
+ }
109
249
  const text =
110
250
  typeof requestText === 'string' && requestText.trim().length > 0 ? requestText : promptText
111
- if (hasDecisionRouterMarker(text)) return none
251
+ if (hasDecisionRouterMarker(text)) return none('marker.present')
112
252
  try {
113
- const decision = await decideForTurn({
253
+ const decision = await decideLocalForTurn({
114
254
  request: text,
115
255
  sessionID: event.sessionID,
116
256
  messageID: event.messageID,
117
- permissionAssert,
118
257
  })
119
258
  return applyTurnDecisionToPrompt(prompt, decision)
120
259
  } catch {
121
- return none
260
+ return none('invalid.payload')
122
261
  }
123
262
  }
@@ -1,7 +1,10 @@
1
1
  /**
2
- * Private provider matrix: fixed provider/model/endpoint/credential rows and
3
- * their ledger accounting mapping. No network I/O and no caller-supplied
4
- * transport, config, env, or ledger.
2
+ * Private provider matrix: fixed provider/model rows and their ledger
3
+ * accounting mapping. No network I/O, no endpoints, no credentials — the
4
+ * direct-fetch adapter fields were removed with the legacy fetch runner; the
5
+ * only egress transport is the host's native Decisions layer, whose provider
6
+ * and credentials the host owns. Pantheon uses this matrix for the config
7
+ * candidate model IDs and ledger accounting names only.
5
8
  */
6
9
  import {
7
10
  DECISION_PROVIDER_BUDGET_MAPPING,
@@ -15,78 +18,27 @@ export type DecisionProviderId =
15
18
  | 'opencode-console-jev'
16
19
  | 'opencode-console-jev-free'
17
20
 
18
- export type DecisionProtocol = 'openai' | 'systemone'
19
-
20
- export const PROVIDER_MAX_RESPONSE_BYTES = 64 * 1024
21
- export const PROVIDER_REQUEST_TIMEOUT_MS = 5_000
22
-
23
- export interface DecisionProviderAdapter {
24
- model: string
25
- endpoint: string
26
- credentialEnv: string
27
- accountingProvider: BudgetProvider
28
- egressEligible: boolean
29
- protocol: DecisionProtocol
30
- }
31
-
32
- const ADAPTER_DEFINITIONS: Readonly<
33
- Record<
34
- DecisionProviderId,
35
- {
36
- endpoint: string
37
- credentialEnv: string
38
- egressEligible: boolean
39
- protocol: DecisionProtocol
40
- }
41
- >
42
- > = Object.freeze({
43
- 'openai-decisions': {
44
- endpoint: 'https://api.openai.com/v1/decisions',
45
- credentialEnv: 'OPENAI_API_KEY',
46
- egressEligible: true,
47
- protocol: 'openai',
48
- },
49
- 'typesafe-jev': {
50
- endpoint: 'https://api.typesafe.ai/v1/systemone',
51
- credentialEnv: 'TYPESAFE_API_KEY',
52
- egressEligible: true,
53
- protocol: 'systemone',
54
- },
55
- 'opencode-console-jev': {
56
- endpoint: 'https://opencode.ai/inference/systemone/v1/systemone',
57
- credentialEnv: 'OPENCODE_API_KEY',
58
- egressEligible: false,
59
- protocol: 'systemone',
60
- },
61
- 'opencode-console-jev-free': {
62
- endpoint: 'https://opencode.ai/inference/systemone/v1/systemone',
63
- credentialEnv: 'OPENCODE_API_KEY',
64
- egressEligible: false,
65
- protocol: 'systemone',
66
- },
67
- })
68
-
69
21
  /**
70
22
  * Single provider matrix. Model and accounting IDs come from the canonical
71
- * config so the adapter and the ledger can never drift silently.
23
+ * config so the route resolver and the ledger can never drift silently.
72
24
  */
73
25
  export const DECISION_PROVIDER_ADAPTERS: Readonly<
74
- Record<DecisionProviderId, DecisionProviderAdapter>
26
+ Record<DecisionProviderId, { model: string; accountingProvider: BudgetProvider }>
75
27
  > = Object.freeze(
76
28
  Object.fromEntries(
77
- (Object.keys(ADAPTER_DEFINITIONS) as DecisionProviderId[]).map((provider) => {
78
- const definition = ADAPTER_DEFINITIONS[provider]
79
- const models = DECISION_ROUTER_MODELS[provider]
80
- const model = models?.[0]
29
+ (Object.keys(DECISION_ROUTER_MODELS) as DecisionProviderId[]).map((provider) => {
30
+ const model = DECISION_ROUTER_MODELS[provider]?.[0]
81
31
  if (model === undefined) throw new Error(`Missing decision provider model: ${provider}`)
82
32
  return [
83
33
  provider,
84
34
  Object.freeze({
85
- ...definition,
86
35
  model,
87
36
  accountingProvider: DECISION_PROVIDER_BUDGET_MAPPING[provider] as BudgetProvider,
88
37
  }),
89
38
  ]
90
39
  }),
91
- ) as Record<DecisionProviderId, DecisionProviderAdapter>,
40
+ ) as Record<
41
+ DecisionProviderId,
42
+ { readonly model: string; readonly accountingProvider: BudgetProvider }
43
+ >,
92
44
  )