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.
- package/CHANGELOG.md +27 -0
- package/README.md +202 -29
- package/README.pt-BR.md +9 -0
- package/bin/pantheon-init.mjs +6 -1
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +7 -8
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +268 -46
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +162 -34
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/versioning.mjs +41 -5
- 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/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 +184 -45
- package/src/pantheon/local-decision-provider-matrix.ts +14 -62
- package/src/pantheon/local-decision-skills.ts +115 -5
- package/src/pantheon/local-decision-tool.ts +35 -1
- 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-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-native-decisions.ts +365 -0
- package/src/pantheon/v2-tools.ts +24 -2
- package/src/plugin-v2.ts +360 -14
- 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
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Internal, parser-issued usage capabilities
|
|
3
|
-
* exported from the package entrypoints;
|
|
2
|
+
* Internal, parser-issued usage capabilities for the native Decisions route.
|
|
3
|
+
* This module is deliberately not exported from the package entrypoints;
|
|
4
|
+
* callers cannot provide a cost value — the cost comes from the host's own
|
|
5
|
+
* DecisionResult, and this module only mints the opaque capability the ledger
|
|
6
|
+
* accepts. The legacy direct-fetch receipt verifier was removed with the fetch
|
|
7
|
+
* runner.
|
|
4
8
|
*/
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
/** Providers that can appear in usage details: native Decisions routes. */
|
|
11
|
+
export type UsageProvider = 'typesafe-jev' | 'opencode-console' | 'jev-free'
|
|
12
|
+
|
|
13
|
+
export interface ParsedUsageCounts {
|
|
14
|
+
provider: UsageProvider
|
|
15
|
+
model: string
|
|
16
|
+
inputTokens: number
|
|
17
|
+
outputTokens: number
|
|
18
|
+
cachedInputTokens: number
|
|
19
|
+
cacheWriteInputTokens: number
|
|
20
|
+
}
|
|
7
21
|
|
|
8
22
|
export interface UsageReservationBinding {
|
|
9
23
|
reservationId: string
|
|
10
|
-
provider:
|
|
24
|
+
provider: UsageProvider
|
|
11
25
|
model: string
|
|
12
26
|
period: string
|
|
13
27
|
}
|
|
@@ -17,38 +31,39 @@ export type VerifiedUsageEvidence = {
|
|
|
17
31
|
readonly [verifiedUsageEvidenceBrand]: true
|
|
18
32
|
}
|
|
19
33
|
|
|
20
|
-
export interface ParsedUsageCounts {
|
|
21
|
-
provider: ReconciliableUsageProvider
|
|
22
|
-
model: string
|
|
23
|
-
inputTokens: number
|
|
24
|
-
outputTokens: number
|
|
25
|
-
cachedInputTokens: number
|
|
26
|
-
cacheWriteInputTokens: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
34
|
export interface VerifiedUsageEvidenceDetails extends ParsedUsageCounts {
|
|
30
35
|
reservationId: string
|
|
31
36
|
period: string
|
|
32
37
|
actualCostMicros: number
|
|
33
|
-
pricingSnapshot: '
|
|
38
|
+
pricingSnapshot: 'host-reported'
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
const MODEL_IDS: Readonly<Record<ReconciliableUsageProvider, string>> = Object.freeze({
|
|
37
|
-
'openai-decisions': 'gpt-6-luna',
|
|
38
|
-
'typesafe-jev': 'jev-1.14.0',
|
|
39
|
-
})
|
|
40
41
|
const RESERVATION_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/
|
|
41
42
|
const UTC_PERIOD = /^\d{4}-(0[1-9]|1[0-2])$/
|
|
42
43
|
const evidenceDetails = new WeakMap<object, VerifiedUsageEvidenceDetails>()
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* Console models and zero-cost results deliberately produce no capability.
|
|
46
|
+
* Budget providers with a native host Decisions route. `openai-decisions` is
|
|
47
|
+
* absent: direct OpenAI has no native route, so it can never settle one.
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
function isNativeUsageProvider(value: string): value is UsageProvider {
|
|
50
|
+
return value === 'typesafe-jev' || value === 'opencode-console' || value === 'jev-free'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mint a reconciliation capability from a native host Decisions result.
|
|
55
|
+
*
|
|
56
|
+
* On the native route the host is the billing authority (it owns the provider
|
|
57
|
+
* credentials and the Console ledger), so the host-reported `cost` plays the
|
|
58
|
+
* role the fetch path's provider receipt played. Absent cost is a real zero —
|
|
59
|
+
* the free Console variant and hosts that do not price Decisions both land
|
|
60
|
+
* here, and reconciling at zero releases the reservation instead of burning
|
|
61
|
+
* the period's budget. A result that produced no answer settles nothing: an
|
|
62
|
+
* error payload is not evidence that a decision was paid for.
|
|
63
|
+
*/
|
|
64
|
+
export function verifyNativeUsageForReservation(
|
|
50
65
|
bindingInput: unknown,
|
|
51
|
-
|
|
66
|
+
result: unknown,
|
|
52
67
|
): VerifiedUsageEvidence | null {
|
|
53
68
|
try {
|
|
54
69
|
if (
|
|
@@ -62,8 +77,10 @@ export function verifyProviderUsageForReservation(
|
|
|
62
77
|
const reservationId = bindingInput.reservationId
|
|
63
78
|
const period = bindingInput.period
|
|
64
79
|
if (
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
typeof provider !== 'string' ||
|
|
81
|
+
!isNativeUsageProvider(provider) ||
|
|
82
|
+
typeof model !== 'string' ||
|
|
83
|
+
model.length === 0 ||
|
|
67
84
|
typeof reservationId !== 'string' ||
|
|
68
85
|
!RESERVATION_ID.test(reservationId) ||
|
|
69
86
|
typeof period !== 'string' ||
|
|
@@ -71,21 +88,50 @@ export function verifyProviderUsageForReservation(
|
|
|
71
88
|
) {
|
|
72
89
|
return null
|
|
73
90
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
if (
|
|
92
|
+
!isPlainRecord(result) ||
|
|
93
|
+
!Array.isArray(result.answers) ||
|
|
94
|
+
result.answers.length === 0 ||
|
|
95
|
+
!result.answers.every((answer) => isPlainRecord(answer))
|
|
96
|
+
) {
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let actualCostMicros = 0
|
|
101
|
+
if (result.cost !== undefined) {
|
|
102
|
+
if (!isNonNegativeFinite(result.cost)) return null
|
|
103
|
+
actualCostMicros = Math.round(result.cost * 1_000_000)
|
|
104
|
+
if (!Number.isSafeInteger(actualCostMicros)) return null
|
|
105
|
+
}
|
|
106
|
+
let inputTokens = 0
|
|
107
|
+
let outputTokens = 0
|
|
108
|
+
if (result.tokens !== undefined) {
|
|
109
|
+
if (!isPlainRecord(result.tokens)) return null
|
|
110
|
+
const { input, output } = result.tokens
|
|
111
|
+
if (
|
|
112
|
+
(input !== undefined && !isNonNegativeFinite(input)) ||
|
|
113
|
+
(output !== undefined && !isNonNegativeFinite(output))
|
|
114
|
+
) {
|
|
115
|
+
return null
|
|
116
|
+
}
|
|
117
|
+
inputTokens = typeof input === 'number' ? input : 0
|
|
118
|
+
outputTokens = typeof output === 'number' ? output : 0
|
|
119
|
+
}
|
|
79
120
|
|
|
80
121
|
const evidence = Object.freeze(Object.create(null)) as VerifiedUsageEvidence
|
|
81
122
|
evidenceDetails.set(
|
|
82
123
|
evidence,
|
|
83
124
|
Object.freeze({
|
|
84
|
-
|
|
125
|
+
provider,
|
|
126
|
+
model,
|
|
127
|
+
inputTokens,
|
|
128
|
+
outputTokens,
|
|
129
|
+
cachedInputTokens: 0,
|
|
130
|
+
cacheWriteInputTokens: 0,
|
|
85
131
|
reservationId,
|
|
86
132
|
period,
|
|
87
133
|
actualCostMicros,
|
|
88
|
-
pricingSnapshot: '
|
|
134
|
+
pricingSnapshot: 'host-reported',
|
|
89
135
|
}),
|
|
90
136
|
)
|
|
91
137
|
return evidence
|
|
@@ -102,93 +148,8 @@ export function getVerifiedUsageEvidenceDetails(
|
|
|
102
148
|
return evidenceDetails.get(value as object) ?? null
|
|
103
149
|
}
|
|
104
150
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
provider: unknown,
|
|
108
|
-
response: unknown,
|
|
109
|
-
): ParsedUsageCounts | null {
|
|
110
|
-
try {
|
|
111
|
-
if (
|
|
112
|
-
!isReconciliableProvider(provider) ||
|
|
113
|
-
!isPlainRecord(response) ||
|
|
114
|
-
response.model !== MODEL_IDS[provider] ||
|
|
115
|
-
!isPlainRecord(response.usage)
|
|
116
|
-
) {
|
|
117
|
-
return null
|
|
118
|
-
}
|
|
119
|
-
const usage = response.usage
|
|
120
|
-
if (provider === 'openai-decisions') {
|
|
121
|
-
if (
|
|
122
|
-
!hasExactKeys(usage, [
|
|
123
|
-
'input_tokens',
|
|
124
|
-
'input_tokens_details',
|
|
125
|
-
'output_tokens',
|
|
126
|
-
'output_tokens_details',
|
|
127
|
-
'total_tokens',
|
|
128
|
-
]) ||
|
|
129
|
-
!isPlainRecord(usage.input_tokens_details) ||
|
|
130
|
-
!hasExactKeys(usage.input_tokens_details, ['cache_write_tokens', 'cached_tokens']) ||
|
|
131
|
-
!isPlainRecord(usage.output_tokens_details) ||
|
|
132
|
-
!hasExactKeys(usage.output_tokens_details, ['reasoning_tokens']) ||
|
|
133
|
-
!isNonNegativeSafeInteger(usage.input_tokens) ||
|
|
134
|
-
!isNonNegativeSafeInteger(usage.output_tokens) ||
|
|
135
|
-
!isNonNegativeSafeInteger(usage.total_tokens) ||
|
|
136
|
-
!isNonNegativeSafeInteger(usage.input_tokens_details.cache_write_tokens) ||
|
|
137
|
-
!isNonNegativeSafeInteger(usage.input_tokens_details.cached_tokens) ||
|
|
138
|
-
!isNonNegativeSafeInteger(usage.output_tokens_details.reasoning_tokens) ||
|
|
139
|
-
!Number.isSafeInteger(usage.input_tokens + usage.output_tokens) ||
|
|
140
|
-
usage.input_tokens + usage.output_tokens !== usage.total_tokens ||
|
|
141
|
-
usage.input_tokens_details.cache_write_tokens + usage.input_tokens_details.cached_tokens >
|
|
142
|
-
usage.input_tokens ||
|
|
143
|
-
usage.output_tokens_details.reasoning_tokens > usage.output_tokens
|
|
144
|
-
) {
|
|
145
|
-
return null
|
|
146
|
-
}
|
|
147
|
-
} else if (
|
|
148
|
-
!hasExactKeys(usage, ['input_tokens', 'output_tokens']) ||
|
|
149
|
-
!isNonNegativeSafeInteger(usage.input_tokens) ||
|
|
150
|
-
!isNonNegativeSafeInteger(usage.output_tokens)
|
|
151
|
-
) {
|
|
152
|
-
return null
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
provider,
|
|
156
|
-
model: MODEL_IDS[provider],
|
|
157
|
-
inputTokens: usage.input_tokens as number,
|
|
158
|
-
outputTokens: usage.output_tokens as number,
|
|
159
|
-
cachedInputTokens:
|
|
160
|
-
provider === 'openai-decisions'
|
|
161
|
-
? ((usage.input_tokens_details as Record<string, number>).cached_tokens as number)
|
|
162
|
-
: 0,
|
|
163
|
-
cacheWriteInputTokens:
|
|
164
|
-
provider === 'openai-decisions'
|
|
165
|
-
? ((usage.input_tokens_details as Record<string, number>).cache_write_tokens as number)
|
|
166
|
-
: 0,
|
|
167
|
-
}
|
|
168
|
-
} catch {
|
|
169
|
-
return null
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function priceUsageMicros(usage: ParsedUsageCounts): number | null {
|
|
174
|
-
// Snapshot: GPT-6 Luna standard rates are $0.10/M input and $0.50/M output;
|
|
175
|
-
// TypeSafe Jev 1.14 is $0.042/M input and $0 output. Discounts are not applied.
|
|
176
|
-
const numerator =
|
|
177
|
-
usage.provider === 'openai-decisions'
|
|
178
|
-
? BigInt(usage.inputTokens) + 5n * BigInt(usage.outputTokens)
|
|
179
|
-
: 42n * BigInt(usage.inputTokens)
|
|
180
|
-
const denominator = usage.provider === 'openai-decisions' ? 10n : 1_000n
|
|
181
|
-
const roundedMicros = (numerator + denominator - 1n) / denominator
|
|
182
|
-
if (roundedMicros <= 0n || roundedMicros > BigInt(Number.MAX_SAFE_INTEGER)) return null
|
|
183
|
-
return Number(roundedMicros)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function isReconciliableProvider(value: unknown): value is ReconciliableUsageProvider {
|
|
187
|
-
return value === 'openai-decisions' || value === 'typesafe-jev'
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function isNonNegativeSafeInteger(value: unknown): value is number {
|
|
191
|
-
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0
|
|
151
|
+
function isNonNegativeFinite(value: unknown): value is number {
|
|
152
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
192
153
|
}
|
|
193
154
|
|
|
194
155
|
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|