pantheon-opencode 1.6.3-beta.2 → 1.6.3-beta.20
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 +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +137 -0
- package/README.md +21 -3
- package/README.pt-BR.md +1 -1
- package/bin/pantheon-init.mjs +46 -28
- package/package.json +1 -1
- package/plugin.json +2 -2
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +103 -3
- package/scripts/decision-router-v2-budget.mjs +2 -2
- package/scripts/decision-router.mjs +88 -6
- package/scripts/install/cli-ui.mjs +2 -1
- package/scripts/install/decision-router-config.mjs +53 -0
- package/scripts/install/interactive.mjs +103 -9
- package/scripts/install/opencode.mjs +101 -30
- package/scripts/install/plugin.mjs +17 -0
- package/scripts/jev-live-probe.mjs +210 -0
- package/scripts/skill-search.mjs +273 -0
- package/scripts/sync-tui.mjs +11 -0
- package/skills-lock.json +1 -0
- package/src/agents/aphrodite.md +34 -1
- package/src/agents/apollo.md +227 -0
- package/src/agents/athena.md +26 -0
- package/src/agents/demeter.md +33 -0
- package/src/agents/gaia.md +24 -0
- package/src/agents/hephaestus.md +24 -0
- package/src/agents/hermes.md +33 -0
- package/src/agents/iris.md +24 -0
- package/src/agents/mnemosyne.md +25 -3
- package/src/agents/nyx.md +50 -22
- package/src/agents/prometheus.md +242 -1
- package/src/agents/talos.md +24 -0
- package/src/agents/themis.md +24 -0
- package/src/agents/zeus.md +67 -6
- package/src/pantheon/j-telemetry-file.ts +96 -0
- package/src/pantheon/jev-decision-tool.ts +262 -34
- package/src/pantheon/jev-decisions.ts +92 -8
- package/src/pantheon/jev-quality-score.ts +7 -2
- package/src/pantheon/jev-rank-verify.ts +637 -0
- package/src/pantheon/jev-risk-gate.ts +70 -6
- package/src/pantheon/local-decision-budget.ts +170 -3
- package/src/pantheon/local-decision-router.ts +16 -0
- package/src/pantheon/local-decision-turn.ts +39 -4
- package/src/pantheon/local-decision-usage-evidence.internal.ts +2 -2
- package/src/pantheon/pantheon-decision-catalog.ts +9 -2
- package/src/pantheon/v2-decision-budget.ts +4 -2
- package/src/plugin-v2.ts +44 -7
- package/src/plugins/tui/dist/server-v2.d.ts +14 -6
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/server-v2.js +16 -9
- package/src/plugins/tui/dist/server-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +560 -4
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- 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/plugins/tui/src/index-v2.tsx +6 -0
- package/src/plugins/tui/src/server-v2.ts +14 -7
- package/src/plugins/tui/src/whats-new-highlights.ts +317 -0
- package/src/plugins/tui/src/whats-new-open.ts +120 -0
- package/src/plugins/tui/src/whats-new-state.ts +128 -0
- package/src/plugins/tui/src/whats-new.tsx +172 -0
- package/src/routing.yml +1 -0
- package/src/skills/README.md +1 -1
- package/src/skills/prompt-refinery/SKILL.md +41 -0
|
@@ -24,8 +24,11 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { readUserDecisionRouterConfig } from '../../scripts/install/decision-router-config.mjs'
|
|
26
26
|
import {
|
|
27
|
+
checkJevEnvelope,
|
|
27
28
|
consumeJevDecisionResult,
|
|
28
29
|
isJevDecisionPreset,
|
|
30
|
+
JEV_EXPLICIT_ENVELOPE_KEYS,
|
|
31
|
+
JEV_PRESET_ENVELOPE_KEYS,
|
|
29
32
|
type JevDecisionPreparation,
|
|
30
33
|
type JevHostSkill,
|
|
31
34
|
type NativeJevRouteFailure,
|
|
@@ -41,7 +44,19 @@ import {
|
|
|
41
44
|
J4_QUALITY_SCORE_POINT,
|
|
42
45
|
type QualityScoreEvaluation,
|
|
43
46
|
qualityVerdict,
|
|
47
|
+
REVIEW_ENVELOPE_KEYS,
|
|
44
48
|
} from './jev-quality-score.ts'
|
|
49
|
+
import {
|
|
50
|
+
buildJevOrderRequest,
|
|
51
|
+
buildJevRankRequest,
|
|
52
|
+
buildJevVerifyRequest,
|
|
53
|
+
consumeJevOrderResult,
|
|
54
|
+
consumeJevRankResult,
|
|
55
|
+
consumeJevVerifyResult,
|
|
56
|
+
ORDER_ENVELOPE_KEYS,
|
|
57
|
+
RANK_ENVELOPE_KEYS,
|
|
58
|
+
VERIFY_ENVELOPE_KEYS,
|
|
59
|
+
} from './jev-rank-verify.ts'
|
|
45
60
|
import { mapGateFailureToSkipReason } from './jev-risk-gate.ts'
|
|
46
61
|
import {
|
|
47
62
|
openLocalDecisionBudgetLedger,
|
|
@@ -70,7 +85,8 @@ export interface V2JevDecisionRuntime {
|
|
|
70
85
|
/**
|
|
71
86
|
* Allowlisted specialist callers for explicit-questions mode (parsed from
|
|
72
87
|
* `PANTHEON_JEV_SPECIALIST_CALLERS` by the plugin wiring). Empty/absent =
|
|
73
|
-
* Zeus only. Preset modes
|
|
88
|
+
* Zeus only. Preset and v3.1 modes (skills, delegation, review, rank,
|
|
89
|
+
* verify) stay Zeus-only regardless.
|
|
74
90
|
*/
|
|
75
91
|
readonly specialistCallers?: readonly string[]
|
|
76
92
|
/**
|
|
@@ -98,11 +114,12 @@ export const SPECIALIST_CALLERS_FLAG_ENV = 'PANTHEON_JEV_SPECIALIST_CALLERS'
|
|
|
98
114
|
|
|
99
115
|
/**
|
|
100
116
|
* Parse the caller allowlist from the flag's CSV value. Unset/empty = Zeus
|
|
101
|
-
* only (the default). Preset modes (skills, delegation, review
|
|
102
|
-
* Zeus-only regardless of the flag: owner/skill selection
|
|
103
|
-
* scoring
|
|
104
|
-
* questions mid-task, nothing
|
|
105
|
-
*
|
|
117
|
+
* only (the default). Preset and v3.1 modes (skills, delegation, review,
|
|
118
|
+
* rank, verify) stay Zeus-only regardless of the flag: owner/skill selection,
|
|
119
|
+
* result scoring, candidate ranking and claim verification are orchestration
|
|
120
|
+
* decisions; specialists may ask bounded typed questions mid-task, nothing
|
|
121
|
+
* else. Lives in the plugin wiring (which owns flag reads); this module
|
|
122
|
+
* receives the parsed list via the runtime.
|
|
106
123
|
*/
|
|
107
124
|
export function specialistCallerAllowlist(flagValue: string | undefined): readonly string[] {
|
|
108
125
|
const raw = String(flagValue ?? '').trim()
|
|
@@ -118,6 +135,12 @@ export type JevDecisionRunFailure =
|
|
|
118
135
|
| 'CALLER_NOT_ALLOWED'
|
|
119
136
|
| 'REVIEW_INPUT_INVALID'
|
|
120
137
|
| 'CRITERIA_INVALID'
|
|
138
|
+
| 'RANK_INPUT_INVALID'
|
|
139
|
+
| 'CANDIDATE_INVALID'
|
|
140
|
+
| 'ORDER_INPUT_INVALID'
|
|
141
|
+
| 'ORDER_CANDIDATE_INVALID'
|
|
142
|
+
| 'VERIFY_INPUT_INVALID'
|
|
143
|
+
| 'CLAIM_INVALID'
|
|
121
144
|
| 'CONTEXT_UNAVAILABLE'
|
|
122
145
|
| 'CONFIG_UNAVAILABLE'
|
|
123
146
|
| 'DISABLED'
|
|
@@ -131,6 +154,7 @@ export type JevDecisionRunFailure =
|
|
|
131
154
|
| 'PRESET_INVALID'
|
|
132
155
|
| 'RESERVATION_DENIED'
|
|
133
156
|
| 'DECISION_CALL_FAILED'
|
|
157
|
+
| 'USAGE_EVIDENCE_UNAVAILABLE'
|
|
134
158
|
| 'USAGE_UNRECONCILED'
|
|
135
159
|
|
|
136
160
|
interface JevToolContext {
|
|
@@ -139,8 +163,12 @@ interface JevToolContext {
|
|
|
139
163
|
agent?: unknown
|
|
140
164
|
}
|
|
141
165
|
|
|
142
|
-
function refusal(reasonCode: JevDecisionRunFailure): string {
|
|
143
|
-
return JSON.stringify(
|
|
166
|
+
function refusal(reasonCode: JevDecisionRunFailure, detail?: string): string {
|
|
167
|
+
return JSON.stringify(
|
|
168
|
+
detail === undefined
|
|
169
|
+
? { advisory: false, effect: 'none', reasonCode }
|
|
170
|
+
: { advisory: false, effect: 'none', reasonCode, detail },
|
|
171
|
+
)
|
|
144
172
|
}
|
|
145
173
|
|
|
146
174
|
function isNonBlankString(value: unknown): value is string {
|
|
@@ -159,15 +187,24 @@ function reviewRefusalSkipReason(reasonCode: JevDecisionRunFailure): string {
|
|
|
159
187
|
/**
|
|
160
188
|
* Every gate-chain failure the shared runner can produce. It is
|
|
161
189
|
* {@link JevDecisionRunFailure} minus the tool-surface properties:
|
|
162
|
-
* `CALLER_NOT_ALLOWED` (the caller check) and the
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
190
|
+
* `CALLER_NOT_ALLOWED` (the caller check) and the input validation of the
|
|
191
|
+
* prebuilt-request modes — the review mode (`REVIEW_INPUT_INVALID` /
|
|
192
|
+
* `CRITERIA_INVALID`) and the v3.1 rank and verify modes
|
|
193
|
+
* (`RANK_INPUT_INVALID` / `CANDIDATE_INVALID` / `VERIFY_INPUT_INVALID` /
|
|
194
|
+
* `CLAIM_INVALID`). All of these are properties of the explicit tool surface,
|
|
195
|
+
* whose input the caller supplies directly, not of the gate chain; the
|
|
196
|
+
* J1/J3 shadow observers run the same chain for any agent and can never
|
|
197
|
+
* produce them.
|
|
167
198
|
*/
|
|
168
199
|
export type GatedNativeJevFailure = Exclude<
|
|
169
200
|
JevDecisionRunFailure,
|
|
170
|
-
|
|
201
|
+
| 'CALLER_NOT_ALLOWED'
|
|
202
|
+
| 'REVIEW_INPUT_INVALID'
|
|
203
|
+
| 'CRITERIA_INVALID'
|
|
204
|
+
| 'RANK_INPUT_INVALID'
|
|
205
|
+
| 'CANDIDATE_INVALID'
|
|
206
|
+
| 'VERIFY_INPUT_INVALID'
|
|
207
|
+
| 'CLAIM_INVALID'
|
|
171
208
|
>
|
|
172
209
|
|
|
173
210
|
/** The minimal runtime slice the gate chain needs. */
|
|
@@ -264,6 +301,14 @@ export async function runGatedNativeJevCall(params: {
|
|
|
264
301
|
)
|
|
265
302
|
if (!selection.ok) return { ok: false, reasonCode: selection.reasonCode }
|
|
266
303
|
|
|
304
|
+
// Cloudflare Workers AI has no supported native-usage evidence parser yet.
|
|
305
|
+
// Reject its Jev route before permission, request preparation, or budget
|
|
306
|
+
// reservation; otherwise the provider could be called and leave a pending
|
|
307
|
+
// reservation when reconciliation cannot be verified.
|
|
308
|
+
if (selection.selection.provider === 'cloudflare-workers-jev') {
|
|
309
|
+
return { ok: false, reasonCode: 'USAGE_EVIDENCE_UNAVAILABLE' }
|
|
310
|
+
}
|
|
311
|
+
|
|
267
312
|
if (typeof params.runtime.permissionAssert !== 'function') {
|
|
268
313
|
return { ok: false, reasonCode: 'PERMISSION_UNAVAILABLE' }
|
|
269
314
|
}
|
|
@@ -409,10 +454,14 @@ export async function runJevDecision(
|
|
|
409
454
|
? (toolContext as JevToolContext)
|
|
410
455
|
: undefined
|
|
411
456
|
const caller = context?.agent
|
|
412
|
-
if (typeof caller !== 'string' || caller.length === 0)
|
|
457
|
+
if (typeof caller !== 'string' || caller.length === 0)
|
|
458
|
+
return refusal('CALLER_NOT_ALLOWED', 'CALLER_NOT_ALLOWLISTED')
|
|
413
459
|
const allowlist = runtime.specialistCallers ?? []
|
|
414
460
|
if (caller !== 'zeus' && !allowlist.includes(caller)) {
|
|
415
|
-
return refusal(
|
|
461
|
+
return refusal(
|
|
462
|
+
'CALLER_NOT_ALLOWED',
|
|
463
|
+
'CALLER_NOT_ALLOWLISTED — allowlist this caller via PANTHEON_JEV_SPECIALIST_CALLERS (then restart) or ask Zeus to route',
|
|
464
|
+
)
|
|
416
465
|
}
|
|
417
466
|
|
|
418
467
|
const requested = (input ?? {}) as { mode?: unknown; questions?: unknown }
|
|
@@ -423,10 +472,50 @@ export async function runJevDecision(
|
|
|
423
472
|
if (caller !== 'zeus' && requested.mode !== undefined) {
|
|
424
473
|
return refusal('CALLER_NOT_ALLOWED')
|
|
425
474
|
}
|
|
475
|
+
// The ONE envelope gate every path passes through before its builder:
|
|
476
|
+
// schemaVersion required, unknown keys rejected — explicit questions,
|
|
477
|
+
// presets, review, rank and verify alike (beta.10 claimed this contract;
|
|
478
|
+
// beta.12 applies it uniformly). Builders keep their semantic checks.
|
|
479
|
+
const envelopeKeys =
|
|
480
|
+
requested.mode === undefined
|
|
481
|
+
? JEV_EXPLICIT_ENVELOPE_KEYS
|
|
482
|
+
: requested.mode === 'review'
|
|
483
|
+
? REVIEW_ENVELOPE_KEYS
|
|
484
|
+
: requested.mode === 'rank'
|
|
485
|
+
? RANK_ENVELOPE_KEYS
|
|
486
|
+
: requested.mode === 'verify'
|
|
487
|
+
? VERIFY_ENVELOPE_KEYS
|
|
488
|
+
: requested.mode === 'order'
|
|
489
|
+
? ORDER_ENVELOPE_KEYS
|
|
490
|
+
: isJevDecisionPreset(requested.mode)
|
|
491
|
+
? JEV_PRESET_ENVELOPE_KEYS
|
|
492
|
+
: undefined
|
|
493
|
+
if (envelopeKeys !== undefined) {
|
|
494
|
+
const envelope = checkJevEnvelope(input, envelopeKeys)
|
|
495
|
+
if (!envelope.ok) {
|
|
496
|
+
const reasonCode: JevDecisionRunFailure =
|
|
497
|
+
requested.mode === undefined
|
|
498
|
+
? 'QUESTIONS_INVALID'
|
|
499
|
+
: requested.mode === 'review'
|
|
500
|
+
? 'REVIEW_INPUT_INVALID'
|
|
501
|
+
: requested.mode === 'rank'
|
|
502
|
+
? 'RANK_INPUT_INVALID'
|
|
503
|
+
: requested.mode === 'verify'
|
|
504
|
+
? 'VERIFY_INPUT_INVALID'
|
|
505
|
+
: requested.mode === 'order'
|
|
506
|
+
? 'ORDER_INPUT_INVALID'
|
|
507
|
+
: 'PRESET_INVALID'
|
|
508
|
+
return refusal(reasonCode, envelope.detail)
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
426
512
|
// Review mode (J4): the bounded request is built before any gate work, and
|
|
427
513
|
// an invalid review input is a tool-surface refusal — same class as the
|
|
428
|
-
// caller check, never a gate failure.
|
|
429
|
-
|
|
514
|
+
// caller check, never a gate failure. The v3.1 rank and verify modes follow
|
|
515
|
+
// the same prebuilt-request pattern (no gate work for a malformed input);
|
|
516
|
+
// neither has a telemetry point — they are tool modes, not shadow gates.
|
|
517
|
+
let prebuilt: Omit<NativeDecisionRequest, 'model'> | undefined
|
|
518
|
+
let candidateSource: JevDecisionPreparation['candidateSource'] | undefined
|
|
430
519
|
if (requested.mode === 'review') {
|
|
431
520
|
const prepared = buildJevReviewRequest(input ?? {})
|
|
432
521
|
if (!prepared.ok) {
|
|
@@ -441,7 +530,19 @@ export async function runJevDecision(
|
|
|
441
530
|
)
|
|
442
531
|
return refusal(prepared.reasonCode)
|
|
443
532
|
}
|
|
444
|
-
|
|
533
|
+
prebuilt = prepared.request
|
|
534
|
+
} else if (requested.mode === 'rank') {
|
|
535
|
+
const prepared = buildJevRankRequest(input ?? {})
|
|
536
|
+
if (!prepared.ok) return refusal(prepared.reasonCode, prepared.detail)
|
|
537
|
+
prebuilt = prepared.request
|
|
538
|
+
} else if (requested.mode === 'verify') {
|
|
539
|
+
const prepared = buildJevVerifyRequest(input ?? {})
|
|
540
|
+
if (!prepared.ok) return refusal(prepared.reasonCode)
|
|
541
|
+
prebuilt = prepared.request
|
|
542
|
+
} else if (requested.mode === 'order') {
|
|
543
|
+
const prepared = buildJevOrderRequest(input ?? {})
|
|
544
|
+
if (!prepared.ok) return refusal(prepared.reasonCode, prepared.detail)
|
|
545
|
+
prebuilt = prepared.request
|
|
445
546
|
}
|
|
446
547
|
const result = await runGatedNativeJevCall({
|
|
447
548
|
sessionID: context?.sessionID,
|
|
@@ -449,24 +550,28 @@ export async function runJevDecision(
|
|
|
449
550
|
agent: caller,
|
|
450
551
|
runtime,
|
|
451
552
|
prepare: async (route) =>
|
|
452
|
-
|
|
553
|
+
prebuilt !== undefined
|
|
453
554
|
? {
|
|
454
555
|
ok: true as const,
|
|
455
556
|
request: {
|
|
456
557
|
model: route.model,
|
|
457
|
-
input:
|
|
458
|
-
questions:
|
|
558
|
+
input: prebuilt.input,
|
|
559
|
+
questions: prebuilt.questions,
|
|
459
560
|
},
|
|
460
561
|
}
|
|
461
562
|
: requested.mode === undefined
|
|
462
563
|
? prepareJevDecisionRequest(route, input ?? {})
|
|
463
564
|
: isJevDecisionPreset(requested.mode)
|
|
464
|
-
?
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
565
|
+
? (async () => {
|
|
566
|
+
const prepared = prepareJevPresetRequest(
|
|
567
|
+
route,
|
|
568
|
+
requested.mode,
|
|
569
|
+
input ?? {},
|
|
570
|
+
requested.mode === 'skills' ? await readHostSkills(runtime) : undefined,
|
|
571
|
+
)
|
|
572
|
+
if (prepared.ok) candidateSource = prepared.candidateSource
|
|
573
|
+
return prepared
|
|
574
|
+
})()
|
|
470
575
|
: { ok: false as const, reasonCode: 'PRESET_INVALID' as const },
|
|
471
576
|
})
|
|
472
577
|
if (!result.ok) {
|
|
@@ -541,6 +646,76 @@ export async function runJevDecision(
|
|
|
541
646
|
frozen: result.call.frozen,
|
|
542
647
|
})
|
|
543
648
|
}
|
|
649
|
+
if (requested.mode === 'rank') {
|
|
650
|
+
// v3.1 rank: the winner choice plus that candidate's fit score. The host
|
|
651
|
+
// API answers one scalar per question, so no runner-up or full ordering is
|
|
652
|
+
// returned — see jev-rank-verify.ts for the honest limitation.
|
|
653
|
+
const rank = consumeJevRankResult(result.call.response, result.call.request)
|
|
654
|
+
return JSON.stringify({
|
|
655
|
+
advisory: true,
|
|
656
|
+
effect: 'none',
|
|
657
|
+
reason: 'JEV_DECISION',
|
|
658
|
+
caller,
|
|
659
|
+
route: {
|
|
660
|
+
providerID: result.call.selection.route.model.providerID,
|
|
661
|
+
id: result.call.selection.route.model.id,
|
|
662
|
+
billing: result.call.selection.route.billing,
|
|
663
|
+
},
|
|
664
|
+
mode: 'rank',
|
|
665
|
+
winner: rank.winner,
|
|
666
|
+
winnerFit: rank.winnerFit,
|
|
667
|
+
answers: advice.answers,
|
|
668
|
+
missing: advice.missing,
|
|
669
|
+
usage: { costUsd: advice.costUsd, tokens: advice.tokens },
|
|
670
|
+
frozen: result.call.frozen,
|
|
671
|
+
})
|
|
672
|
+
}
|
|
673
|
+
if (requested.mode === 'order') {
|
|
674
|
+
// v3.1 ordering: one fit question per candidate (2-4), sorted descending.
|
|
675
|
+
// Null score = the host answered nothing usable for that candidate —
|
|
676
|
+
// visible, placed last, never guessed.
|
|
677
|
+
const ordering = consumeJevOrderResult(result.call.response, result.call.request)
|
|
678
|
+
return JSON.stringify({
|
|
679
|
+
advisory: true,
|
|
680
|
+
effect: 'none',
|
|
681
|
+
reason: 'JEV_DECISION',
|
|
682
|
+
caller,
|
|
683
|
+
route: {
|
|
684
|
+
providerID: result.call.selection.route.model.providerID,
|
|
685
|
+
id: result.call.selection.route.model.id,
|
|
686
|
+
billing: result.call.selection.route.billing,
|
|
687
|
+
},
|
|
688
|
+
mode: 'order',
|
|
689
|
+
ordering,
|
|
690
|
+
answers: advice.answers,
|
|
691
|
+
missing: advice.missing,
|
|
692
|
+
usage: { costUsd: advice.costUsd, tokens: advice.tokens },
|
|
693
|
+
frozen: result.call.frozen,
|
|
694
|
+
})
|
|
695
|
+
}
|
|
696
|
+
if (requested.mode === 'verify') {
|
|
697
|
+
// v3.1 verify: one PASS/FAIL/BLOCK verdict per claim, fail-closed. The
|
|
698
|
+
// tool never acts on the verdicts; a caller that requires a verdict
|
|
699
|
+
// treats a refusal (which never reaches this branch) as BLOCK.
|
|
700
|
+
const results = consumeJevVerifyResult(result.call.response, result.call.request)
|
|
701
|
+
return JSON.stringify({
|
|
702
|
+
advisory: true,
|
|
703
|
+
effect: 'none',
|
|
704
|
+
reason: 'JEV_DECISION',
|
|
705
|
+
caller,
|
|
706
|
+
route: {
|
|
707
|
+
providerID: result.call.selection.route.model.providerID,
|
|
708
|
+
id: result.call.selection.route.model.id,
|
|
709
|
+
billing: result.call.selection.route.billing,
|
|
710
|
+
},
|
|
711
|
+
mode: 'verify',
|
|
712
|
+
results,
|
|
713
|
+
answers: advice.answers,
|
|
714
|
+
missing: advice.missing,
|
|
715
|
+
usage: { costUsd: advice.costUsd, tokens: advice.tokens },
|
|
716
|
+
frozen: result.call.frozen,
|
|
717
|
+
})
|
|
718
|
+
}
|
|
544
719
|
return JSON.stringify({
|
|
545
720
|
advisory: true,
|
|
546
721
|
effect: 'none',
|
|
@@ -552,6 +727,7 @@ export async function runJevDecision(
|
|
|
552
727
|
billing: result.call.selection.route.billing,
|
|
553
728
|
},
|
|
554
729
|
...(requested.mode === undefined ? {} : { preset: requested.mode }),
|
|
730
|
+
...(candidateSource === undefined ? {} : { candidateSource }),
|
|
555
731
|
answers: advice.answers,
|
|
556
732
|
missing: advice.missing,
|
|
557
733
|
usage: { costUsd: advice.costUsd, tokens: advice.tokens },
|
|
@@ -567,7 +743,13 @@ const TOOL_DESCRIPTION =
|
|
|
567
743
|
'host), `mode: "delegation"` to pick ' +
|
|
568
744
|
'a specialist, `mode: "review"` to score a finished delegated result against named criteria ' +
|
|
569
745
|
'(advisory quality score + needs-review flag; the result content itself is never sent — ' +
|
|
570
|
-
'shape metrics and criteria only),
|
|
746
|
+
'shape metrics and criteria only), `mode: "rank"` to pick the best of 2-20 named candidates ' +
|
|
747
|
+
'(winner + fit; no full ordering), `mode: "order"` to ORDER 2-4 candidates by fit (one ' +
|
|
748
|
+
'score question per candidate; returns the descending ordering with per-candidate scores), ' +
|
|
749
|
+
'(returns the winner and its fit score; no full ordering), `mode: "verify"` to check 1-4 ' +
|
|
750
|
+
'named claims, with optional `state` evidence the claims are judged against ' +
|
|
751
|
+
'(verdicts PASS, FAIL, or UNVERIFIABLE for the 0.35-0.65 band; any refusal, timeout or ' +
|
|
752
|
+
'malformed answer is BLOCK, fail-closed), or pass explicit typed `questions` (choice, score, ' +
|
|
571
753
|
'predicate). Invalid-input refusals carry a `detail` token naming the exact cause. Returns ' +
|
|
572
754
|
'probabilistic answers with confidence. Requires decision-router egress ' +
|
|
573
755
|
'consent and budget caps; asks host permission first. It never dispatches agents, runs ' +
|
|
@@ -622,13 +804,45 @@ const REVIEW_METRICS_SCHEMA = {
|
|
|
622
804
|
},
|
|
623
805
|
} as const
|
|
624
806
|
|
|
807
|
+
const RANK_CANDIDATE_SCHEMA = {
|
|
808
|
+
type: 'object',
|
|
809
|
+
additionalProperties: false,
|
|
810
|
+
required: ['id'],
|
|
811
|
+
properties: {
|
|
812
|
+
id: {
|
|
813
|
+
type: 'string',
|
|
814
|
+
minLength: 1,
|
|
815
|
+
maxLength: 64,
|
|
816
|
+
pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$',
|
|
817
|
+
},
|
|
818
|
+
description: { type: 'string', minLength: 1, maxLength: 500 },
|
|
819
|
+
},
|
|
820
|
+
} as const
|
|
821
|
+
|
|
822
|
+
const VERIFY_CLAIM_SCHEMA = {
|
|
823
|
+
type: 'object',
|
|
824
|
+
additionalProperties: false,
|
|
825
|
+
required: ['name', 'claim'],
|
|
826
|
+
properties: {
|
|
827
|
+
name: {
|
|
828
|
+
type: 'string',
|
|
829
|
+
minLength: 1,
|
|
830
|
+
maxLength: 64,
|
|
831
|
+
pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$',
|
|
832
|
+
},
|
|
833
|
+
claim: { type: 'string', minLength: 1, maxLength: 200 },
|
|
834
|
+
},
|
|
835
|
+
} as const
|
|
836
|
+
|
|
625
837
|
/**
|
|
626
|
-
* One schema,
|
|
627
|
-
* questions carry the state text)
|
|
838
|
+
* One schema, four disjoint payloads: the state branch (presets and explicit
|
|
839
|
+
* questions carry the state text), the review branch (J4 takes structural
|
|
628
840
|
* shape metrics, a delegate id and named criteria — never a state text, never
|
|
629
841
|
* result content; the criteria are the only free text, bounded at the DSH
|
|
630
|
-
* caps: at most 4, each 1–120 chars)
|
|
631
|
-
*
|
|
842
|
+
* caps: at most 4, each 1–120 chars), the rank branch (v3.1: a state plus
|
|
843
|
+
* 2–8 named candidates) and the verify branch (v3.1: 1–4 named claims, no
|
|
844
|
+
* state). The preparers are the authority; the schema is the model-facing
|
|
845
|
+
* contract.
|
|
632
846
|
*/
|
|
633
847
|
const JEV_INPUT_SCHEMA: Record<string, unknown> = {
|
|
634
848
|
type: 'object',
|
|
@@ -637,11 +851,13 @@ const JEV_INPUT_SCHEMA: Record<string, unknown> = {
|
|
|
637
851
|
anyOf: [
|
|
638
852
|
{ required: ['state'] },
|
|
639
853
|
{ required: ['delegateId', 'resultSummaryKind', 'resultMetrics', 'criteria'] },
|
|
854
|
+
{ required: ['candidates'] },
|
|
855
|
+
{ required: ['claims'] },
|
|
640
856
|
],
|
|
641
857
|
properties: {
|
|
642
858
|
schemaVersion: { type: 'integer', const: 1 },
|
|
643
859
|
state: { type: 'string', minLength: 1, maxLength: 12_000 },
|
|
644
|
-
mode: { type: 'string', enum: ['skills', 'delegation', 'review'] },
|
|
860
|
+
mode: { type: 'string', enum: ['skills', 'delegation', 'review', 'rank', 'verify', 'order'] },
|
|
645
861
|
questions: { type: 'array', minItems: 1, maxItems: 4, items: questionSchema },
|
|
646
862
|
delegateId: {
|
|
647
863
|
type: 'string',
|
|
@@ -657,6 +873,18 @@ const JEV_INPUT_SCHEMA: Record<string, unknown> = {
|
|
|
657
873
|
maxItems: 4,
|
|
658
874
|
items: { type: 'string', minLength: 1, maxLength: 120 },
|
|
659
875
|
},
|
|
876
|
+
candidates: {
|
|
877
|
+
type: 'array',
|
|
878
|
+
minItems: 2,
|
|
879
|
+
maxItems: 20,
|
|
880
|
+
items: RANK_CANDIDATE_SCHEMA,
|
|
881
|
+
},
|
|
882
|
+
claims: {
|
|
883
|
+
type: 'array',
|
|
884
|
+
minItems: 1,
|
|
885
|
+
maxItems: 4,
|
|
886
|
+
items: VERIFY_CLAIM_SCHEMA,
|
|
887
|
+
},
|
|
660
888
|
},
|
|
661
889
|
}
|
|
662
890
|
|
|
@@ -221,15 +221,62 @@ export type JevDecisionPreparationDetail =
|
|
|
221
221
|
| 'SCORE_INVALID'
|
|
222
222
|
| 'PREDICATE_HAS_CHOICES_OR_LEVELS'
|
|
223
223
|
| 'QUESTION_TYPE_INVALID'
|
|
224
|
+
| 'SCHEMA_VERSION_INVALID'
|
|
225
|
+
| 'UNKNOWN_INPUT_KEYS'
|
|
226
|
+
|
|
227
|
+
export type JevSkillCandidateSource = 'prefilter' | 'full-catalog' | 'host-skills'
|
|
224
228
|
|
|
225
229
|
export type JevDecisionPreparation =
|
|
226
|
-
| {
|
|
230
|
+
| {
|
|
231
|
+
readonly ok: true
|
|
232
|
+
readonly request: NativeDecisionRequest
|
|
233
|
+
/** Skills mode only: which path produced the candidate pool. */
|
|
234
|
+
readonly candidateSource?: JevSkillCandidateSource
|
|
235
|
+
}
|
|
227
236
|
| {
|
|
228
237
|
readonly ok: false
|
|
229
238
|
readonly reasonCode: JevDecisionPreparationFailure
|
|
230
239
|
readonly detail?: JevDecisionPreparationDetail
|
|
231
240
|
}
|
|
232
241
|
|
|
242
|
+
/**
|
|
243
|
+
* The ONE envelope check every tool path passes through before its builder:
|
|
244
|
+
* `schemaVersion` is required (and must be 1) and unknown keys are rejected —
|
|
245
|
+
* the declared contract, now enforced uniformly (beta.10 claimed it; beta.12
|
|
246
|
+
* applies it to presets, review, rank and verify too).
|
|
247
|
+
*/
|
|
248
|
+
export type JevEnvelopeCheck = { ok: true } | { ok: false; detail: JevDecisionPreparationDetail }
|
|
249
|
+
|
|
250
|
+
export function checkJevEnvelope(
|
|
251
|
+
input: unknown,
|
|
252
|
+
allowedKeys: ReadonlySet<string>,
|
|
253
|
+
): JevEnvelopeCheck {
|
|
254
|
+
if (
|
|
255
|
+
input === null ||
|
|
256
|
+
typeof input !== 'object' ||
|
|
257
|
+
Array.isArray(input) ||
|
|
258
|
+
(input as Record<string, unknown>).schemaVersion !== 1
|
|
259
|
+
) {
|
|
260
|
+
return { ok: false, detail: 'SCHEMA_VERSION_INVALID' }
|
|
261
|
+
}
|
|
262
|
+
const unknown = Object.keys(input as Record<string, unknown>).filter(
|
|
263
|
+
(key) => !allowedKeys.has(key),
|
|
264
|
+
)
|
|
265
|
+
if (unknown.length > 0) return { ok: false, detail: 'UNKNOWN_INPUT_KEYS' }
|
|
266
|
+
return { ok: true }
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export const JEV_EXPLICIT_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
|
|
270
|
+
'schemaVersion',
|
|
271
|
+
'state',
|
|
272
|
+
'questions',
|
|
273
|
+
])
|
|
274
|
+
export const JEV_PRESET_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
|
|
275
|
+
'schemaVersion',
|
|
276
|
+
'mode',
|
|
277
|
+
'state',
|
|
278
|
+
])
|
|
279
|
+
|
|
233
280
|
function isBoundedNonBlankString(value: unknown, max: number): value is string {
|
|
234
281
|
return typeof value === 'string' && value.trim().length > 0 && value.length <= max
|
|
235
282
|
}
|
|
@@ -311,8 +358,23 @@ function readScoreQuestion(
|
|
|
311
358
|
*/
|
|
312
359
|
export function prepareJevDecisionRequest(
|
|
313
360
|
route: ResolvedNativeDecisionRoute,
|
|
314
|
-
input: {
|
|
361
|
+
input: {
|
|
362
|
+
readonly schemaVersion?: unknown
|
|
363
|
+
readonly state?: unknown
|
|
364
|
+
readonly questions?: unknown
|
|
365
|
+
},
|
|
315
366
|
): JevDecisionPreparation {
|
|
367
|
+
// Envelope enforcement (field report N2/N3): schemaVersion was documented
|
|
368
|
+
// as required but never checked, and unknown keys passed silently to the
|
|
369
|
+
// provider against the declared additionalProperties: false.
|
|
370
|
+
if (input.schemaVersion !== 1) {
|
|
371
|
+
return { ok: false, reasonCode: 'QUESTIONS_INVALID', detail: 'SCHEMA_VERSION_INVALID' }
|
|
372
|
+
}
|
|
373
|
+
const knownKeys = new Set(['schemaVersion', 'state', 'questions'])
|
|
374
|
+
const unknown = Object.keys(input).filter((key) => !knownKeys.has(key))
|
|
375
|
+
if (unknown.length > 0) {
|
|
376
|
+
return { ok: false, reasonCode: 'QUESTIONS_INVALID', detail: 'UNKNOWN_INPUT_KEYS' }
|
|
377
|
+
}
|
|
316
378
|
const state = input.state
|
|
317
379
|
if (!isBoundedNonBlankString(state, NATIVE_DECISION_MAX_PROMPT_LENGTH)) {
|
|
318
380
|
return { ok: false, reasonCode: 'STATE_INVALID' }
|
|
@@ -403,12 +465,21 @@ export function isJevDecisionPreset(value: unknown): value is JevDecisionPreset
|
|
|
403
465
|
}
|
|
404
466
|
|
|
405
467
|
/** Every canonical specialist except the orchestrator itself. */
|
|
406
|
-
const SPECIALIST_CHOICES: ReadonlyArray<{ value: string }> = Object.freeze(
|
|
468
|
+
const SPECIALIST_CHOICES: ReadonlyArray<{ value: string; description?: string }> = Object.freeze(
|
|
407
469
|
PANTHEON_AGENT_CATALOG.filter((agent) => agent.id !== 'zeus').map((agent) => ({
|
|
408
470
|
value: agent.id,
|
|
471
|
+
description: boundedCatalogDescription(agent.description),
|
|
409
472
|
})),
|
|
410
473
|
)
|
|
411
474
|
|
|
475
|
+
/** Catalog descriptions are short; truncate defensively at the documented bound. */
|
|
476
|
+
function boundedCatalogDescription(value: unknown): string | undefined {
|
|
477
|
+
if (typeof value !== 'string' || value.trim() === '') return undefined
|
|
478
|
+
return value.length > JEV_DECISION_MAX_DESCRIPTION_LENGTH
|
|
479
|
+
? `${value.slice(0, JEV_DECISION_MAX_DESCRIPTION_LENGTH - 1)}…`
|
|
480
|
+
: value
|
|
481
|
+
}
|
|
482
|
+
|
|
412
483
|
const SKILL_DESCRIPTIONS = new Map(
|
|
413
484
|
PANTHEON_SKILL_CATALOG.map((entry) => [entry.id, entry.description]),
|
|
414
485
|
)
|
|
@@ -504,15 +575,25 @@ export function prepareJevPresetRequest(
|
|
|
504
575
|
instructions:
|
|
505
576
|
'Choose one listed specialist only when the described task clearly needs it; ' +
|
|
506
577
|
'otherwise choose none. This is advisory only; nothing is dispatched.',
|
|
507
|
-
choices: [
|
|
578
|
+
choices: [
|
|
579
|
+
...SPECIALIST_CHOICES,
|
|
580
|
+
{ value: 'none', description: 'No specialist fits the described task.' },
|
|
581
|
+
],
|
|
508
582
|
},
|
|
509
583
|
],
|
|
510
584
|
} satisfies NativeDecisionRequest
|
|
511
585
|
return { ok: true, request: Object.freeze(request) }
|
|
512
586
|
}
|
|
513
587
|
|
|
514
|
-
|
|
515
|
-
|
|
588
|
+
// Field report beta.15 §skills: the lexical prefilter dropped the exact
|
|
589
|
+
// skill the state described (codemap → none 0.88 from a prefiltered pool).
|
|
590
|
+
// The local catalog is 12 entries and the choice bound is 24 — recall beats
|
|
591
|
+
// a filter that saves half of $0.00003. The full local catalog + host
|
|
592
|
+
// skills always ride; `candidateSource` keeps reporting which pool the
|
|
593
|
+
// caller got.
|
|
594
|
+
const hostHasSkills = Array.isArray(hostSkills) && hostSkills.length > 0
|
|
595
|
+
const candidateSource: JevSkillCandidateSource = hostHasSkills ? 'host-skills' : 'full-catalog'
|
|
596
|
+
const pool = CATALOG_SKILL_IDS
|
|
516
597
|
const descriptions = new Map(PANTHEON_SKILL_CATALOG.map((entry) => [entry.id, entry.description]))
|
|
517
598
|
const request = {
|
|
518
599
|
model: route.model,
|
|
@@ -524,11 +605,14 @@ export function prepareJevPresetRequest(
|
|
|
524
605
|
instructions:
|
|
525
606
|
'Choose the skills worth stacking for the described task, or none when none apply. ' +
|
|
526
607
|
'This is advisory only; nothing is loaded or executed by this decision.',
|
|
527
|
-
choices: [
|
|
608
|
+
choices: [
|
|
609
|
+
...mergeHostSkills(pool, hostSkills, descriptions),
|
|
610
|
+
{ value: 'none', description: 'No skill stack fits the described task.' },
|
|
611
|
+
],
|
|
528
612
|
},
|
|
529
613
|
],
|
|
530
614
|
} satisfies NativeDecisionRequest
|
|
531
|
-
return { ok: true, request: Object.freeze(request) }
|
|
615
|
+
return { ok: true, request: Object.freeze(request), candidateSource }
|
|
532
616
|
}
|
|
533
617
|
// ─── Response consumption ───────────────────────────────────────────────
|
|
534
618
|
|
|
@@ -63,7 +63,12 @@ export const J4_QUALITY_SCORE_POINT = 'J4'
|
|
|
63
63
|
|
|
64
64
|
/** Question names of the two prepared questions, matched on consumption. */
|
|
65
65
|
export const QUALITY_QUESTION_NAME = 'quality'
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Field report (beta.13→16): the review question was literally named 'noul'
|
|
68
|
+
* — the decision model's internal archetype leaked into a user-visible
|
|
69
|
+
* payload. The name is ours to choose; `quality` says what it measures.
|
|
70
|
+
*/
|
|
71
|
+
export const REVIEW_QUESTION_NAME = 'needs_review'
|
|
67
72
|
|
|
68
73
|
/** DSH hard-cap mirror: at most 4 criteria per review request. */
|
|
69
74
|
export const J4_MAX_CRITERIA = 4
|
|
@@ -356,7 +361,7 @@ export function encodeQualityScoreReason(input: {
|
|
|
356
361
|
* ANY other key — `state`, `questions`, or a smuggled content field — refuses
|
|
357
362
|
* the preparation, so no content slot exists even at the input boundary.
|
|
358
363
|
*/
|
|
359
|
-
const REVIEW_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
|
|
364
|
+
export const REVIEW_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
|
|
360
365
|
'schemaVersion',
|
|
361
366
|
'mode',
|
|
362
367
|
'delegateId',
|