pantheon-opencode 1.6.3-beta.1 → 1.6.3-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/AGENTS.global.md +1 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +57 -0
  4. package/README.md +14 -2
  5. package/package.json +1 -1
  6. package/plugin.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/scripts/decision-router-budget.mjs +1 -2
  9. package/scripts/decision-router-v2-egress.mjs +0 -2
  10. package/scripts/decision-router.mjs +26 -1
  11. package/scripts/install/decision-router-config.mjs +45 -2
  12. package/scripts/install/interactive.mjs +78 -10
  13. package/scripts/install/opencode.mjs +20 -0
  14. package/scripts/install/plugin.mjs +17 -0
  15. package/scripts/jev-live-probe.mjs +184 -0
  16. package/scripts/sync-tui.mjs +11 -0
  17. package/src/agents/zeus.md +24 -0
  18. package/src/pantheon/j-telemetry-file.ts +96 -0
  19. package/src/pantheon/jev-decision-tool.ts +151 -24
  20. package/src/pantheon/jev-decisions.ts +18 -3
  21. package/src/pantheon/jev-rank-verify.ts +435 -0
  22. package/src/pantheon/local-decision-budget.ts +1 -3
  23. package/src/pantheon/local-decision-provider-matrix.ts +0 -1
  24. package/src/pantheon/local-decision-usage-evidence.internal.ts +2 -2
  25. package/src/plugin-v2.ts +9 -2
  26. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  27. package/src/plugins/tui/dist/tui-v2.js +457 -4
  28. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  29. package/src/plugins/tui/dist/tui.js +1 -1
  30. package/src/plugins/tui/package-lock.json +2 -2
  31. package/src/plugins/tui/package.json +1 -1
  32. package/src/plugins/tui/src/index-v2.tsx +6 -0
  33. package/src/plugins/tui/src/whats-new-highlights.ts +263 -0
  34. package/src/plugins/tui/src/whats-new-open.ts +80 -0
  35. package/src/plugins/tui/src/whats-new-state.ts +128 -0
  36. package/src/plugins/tui/src/whats-new.tsx +119 -0
@@ -106,6 +106,17 @@ export function copyPluginFiles(srcDir, dstDir, version) {
106
106
  else result.skipped++
107
107
  }
108
108
 
109
+ // CHANGELOG.md — the copy's one-time "What's new" window reads the release
110
+ // highlights for the running version from its own installed root. Best
111
+ // effort: a missing source simply means no window (the TUI fails open).
112
+ // src/plugins/tui → src/plugins → src → package root.
113
+ const changelogSrc = join(srcDir, '..', '..', '..', 'CHANGELOG.md')
114
+ if (existsSync(changelogSrc)) {
115
+ if (writeIfChanged(join(dstDir, 'CHANGELOG.md'), readFileSync(changelogSrc, 'utf8'))) {
116
+ result.created++
117
+ } else result.skipped++
118
+ }
119
+
109
120
  const tuiEntry = join(srcDir, version === 'v2' ? 'tui-v2.ts' : 'tui.ts')
110
121
  if (existsSync(tuiEntry)) {
111
122
  if (writeIfChanged(join(dstDir, 'tui.ts'), readFileSync(tuiEntry, 'utf8'))) result.created++
@@ -53,6 +53,30 @@ skills:
53
53
  `docs/tui-v2-quota-providers.md` — it is not a Pantheon surface and never a
54
54
  Pantheon egress path.
55
55
 
56
+ ## MCP call timing (when each integration fires)
57
+
58
+ - **Memory (recall)** — only when prior project history could change the
59
+ outcome of the current decision, and at most one selective search per
60
+ turn. Never recall for context you already hold; never recall during a
61
+ delegation (the Brief is self-contained by design).
62
+ - **Memory (store)** — when YOU judge it prudent: durable, reusable facts
63
+ (decisions, root causes, conventions) that a future session would need.
64
+ Not per-turn noise; never store secrets, user content or transient state.
65
+ The user can always ask to store or purge — your judgment handles the
66
+ rest.
67
+ - **Persistence (checkpoint)** — when prudent: session milestones where the
68
+ work done so far would be expensive to lose (after a risky migration, a
69
+ long investigation, a structural change). Never per turn; never for
70
+ trivial progress.
71
+ - **Vision (`vision_describe`)** — only when a tool call or attachment
72
+ actually carries an image; a text-only turn never fires it.
73
+ - **Code-mode / quota** — infrastructure reads (sessions, models, worktrees)
74
+ are cheap and on demand; never for decisions that `pantheon_jev_decide`
75
+ or the local selector already answer.
76
+ - When in doubt: the local selector answers free, the Jev tool answers
77
+ cheap and typed, an MCP call is the LAST resort for state the session
78
+ cannot reconstruct.
79
+
56
80
  ## Missing capability? Find a skill before inventing one
57
81
 
58
82
  When no installed skill covers a recurring need, search the open ecosystem before writing new instructions:
@@ -0,0 +1,96 @@
1
+ /**
2
+ * j-telemetry-file.ts — field-baseline mirror for the J-series shadow
3
+ * records (J1 risk gate, J3 escalation, J4 review).
4
+ *
5
+ * The in-memory sink (`createTelemetrySink`) is deliberately I/O-free and
6
+ * "the plugin never reads back" — which made the shadow records impossible
7
+ * to measure in the field, and the J1/J3 activation gate requires a measured
8
+ * baseline. This module adds the measurement channel: an opt-in JSONL mirror
9
+ * (`.pantheon/logs/j-telemetry.jsonl`) written ONLY when the J-series flags
10
+ * are on, carrying ONLY the already-sanitized record fields (point, mode,
11
+ * effect, reason tokens — the same bounded vocabulary the in-memory records
12
+ * carry; no user content exists on this path by construction).
13
+ *
14
+ * Fire-and-forget like every plugin log: a write failure is swallowed and
15
+ * never reaches the hook. The file is size-capped (rotate to `.1`, drop the
16
+ * oldest) so a long session cannot grow it unbounded.
17
+ */
18
+
19
+ import { appendFile, mkdir, rename, stat } from 'node:fs/promises'
20
+ import { dirname, join } from 'node:path'
21
+
22
+ const MAX_FILE_BYTES = 1_048_576
23
+
24
+ /** Default mirror target: the established Pantheon logs directory. */
25
+ export function defaultMirrorPath(cwd: string = process.cwd()): string {
26
+ return join(cwd, '.pantheon', 'logs', 'j-telemetry.jsonl')
27
+ }
28
+
29
+ /** The record fields allowed on the wire. Everything else is dropped. */
30
+ const ALLOWED_FIELDS = ['point', 'mode', 'effect', 'decision', 'reason'] as const
31
+
32
+ /** Extract the bounded projection a mirror line may carry. */
33
+ export function mirrorProjection(record: unknown): Record<string, unknown> | null {
34
+ if (record === null || typeof record !== 'object' || Array.isArray(record)) return null
35
+ const source = record as Record<string, unknown>
36
+ const projected: Record<string, unknown> = { ts: new Date().toISOString() }
37
+ for (const field of ALLOWED_FIELDS) {
38
+ const value = source[field]
39
+ if (value === undefined) continue
40
+ if (typeof value !== 'string') return null
41
+ if (value.length > 200) return null
42
+ projected[field] = value
43
+ }
44
+ return projected
45
+ }
46
+
47
+ export interface JTelemetryMirror {
48
+ /**
49
+ * Append one sanitized record line; best-effort, never throws. Fire-and-
50
+ * forget at call sites (the promise may be ignored); it is returned so a
51
+ * test can await the write.
52
+ */
53
+ record(record: unknown): Promise<void>
54
+ }
55
+
56
+ /**
57
+ * Create the opt-in JSONL mirror. Returns null when `enabled` is false so
58
+ * callers keep the zero-overhead path branch-free.
59
+ * @param {{ enabled: boolean, path?: string }} options
60
+ */
61
+ export function createJTelemetryMirror(options: {
62
+ enabled: boolean
63
+ path?: string
64
+ }): JTelemetryMirror | null {
65
+ if (!options.enabled) return null
66
+ const path = options.path ?? defaultMirrorPath()
67
+ let rotating = false
68
+ return {
69
+ record(record: unknown): Promise<void> {
70
+ try {
71
+ const projected = mirrorProjection(record)
72
+ if (projected === null) return Promise.resolve()
73
+ const line = `${JSON.stringify(projected)}\n`
74
+ return (async () => {
75
+ try {
76
+ if (!rotating) {
77
+ const current = await stat(path).catch(() => null)
78
+ if (current !== null && current.size > MAX_FILE_BYTES) {
79
+ rotating = true
80
+ await rename(path, `${path}.1`).catch(() => {})
81
+ rotating = false
82
+ }
83
+ }
84
+ await mkdir(dirname(path), { recursive: true })
85
+ await appendFile(path, line, 'utf8')
86
+ } catch {
87
+ // Best-effort mirror — never break the plugin over telemetry.
88
+ }
89
+ })()
90
+ } catch {
91
+ // Swallow: projection failures are data-shaped, never fatal.
92
+ return Promise.resolve()
93
+ }
94
+ },
95
+ }
96
+ }
@@ -42,6 +42,12 @@ import {
42
42
  type QualityScoreEvaluation,
43
43
  qualityVerdict,
44
44
  } from './jev-quality-score.ts'
45
+ import {
46
+ buildJevRankRequest,
47
+ buildJevVerifyRequest,
48
+ consumeJevRankResult,
49
+ consumeJevVerifyResult,
50
+ } from './jev-rank-verify.ts'
45
51
  import { mapGateFailureToSkipReason } from './jev-risk-gate.ts'
46
52
  import {
47
53
  openLocalDecisionBudgetLedger,
@@ -70,7 +76,8 @@ export interface V2JevDecisionRuntime {
70
76
  /**
71
77
  * Allowlisted specialist callers for explicit-questions mode (parsed from
72
78
  * `PANTHEON_JEV_SPECIALIST_CALLERS` by the plugin wiring). Empty/absent =
73
- * Zeus only. Preset modes stay Zeus-only regardless.
79
+ * Zeus only. Preset and v3.1 modes (skills, delegation, review, rank,
80
+ * verify) stay Zeus-only regardless.
74
81
  */
75
82
  readonly specialistCallers?: readonly string[]
76
83
  /**
@@ -98,11 +105,12 @@ export const SPECIALIST_CALLERS_FLAG_ENV = 'PANTHEON_JEV_SPECIALIST_CALLERS'
98
105
 
99
106
  /**
100
107
  * Parse the caller allowlist from the flag's CSV value. Unset/empty = Zeus
101
- * only (the default). Preset modes (skills, delegation, review) stay
102
- * Zeus-only regardless of the flag: owner/skill selection and result
103
- * scoring are orchestration decisions; specialists may ask bounded typed
104
- * questions mid-task, nothing else. Lives in the plugin wiring (which owns
105
- * flag reads); this module receives the parsed list via the runtime.
108
+ * only (the default). Preset and v3.1 modes (skills, delegation, review,
109
+ * rank, verify) stay Zeus-only regardless of the flag: owner/skill selection,
110
+ * result scoring, candidate ranking and claim verification are orchestration
111
+ * decisions; specialists may ask bounded typed questions mid-task, nothing
112
+ * else. Lives in the plugin wiring (which owns flag reads); this module
113
+ * receives the parsed list via the runtime.
106
114
  */
107
115
  export function specialistCallerAllowlist(flagValue: string | undefined): readonly string[] {
108
116
  const raw = String(flagValue ?? '').trim()
@@ -118,6 +126,10 @@ export type JevDecisionRunFailure =
118
126
  | 'CALLER_NOT_ALLOWED'
119
127
  | 'REVIEW_INPUT_INVALID'
120
128
  | 'CRITERIA_INVALID'
129
+ | 'RANK_INPUT_INVALID'
130
+ | 'CANDIDATE_INVALID'
131
+ | 'VERIFY_INPUT_INVALID'
132
+ | 'CLAIM_INVALID'
121
133
  | 'CONTEXT_UNAVAILABLE'
122
134
  | 'CONFIG_UNAVAILABLE'
123
135
  | 'DISABLED'
@@ -159,15 +171,24 @@ function reviewRefusalSkipReason(reasonCode: JevDecisionRunFailure): string {
159
171
  /**
160
172
  * Every gate-chain failure the shared runner can produce. It is
161
173
  * {@link JevDecisionRunFailure} minus the tool-surface properties:
162
- * `CALLER_NOT_ALLOWED` (the caller check) and the review mode's input
163
- * validation (`REVIEW_INPUT_INVALID` / `CRITERIA_INVALID`) — all three are
164
- * properties of the explicit tool surface, whose input the caller supplies
165
- * directly, not of the gate chain; the J1/J3 shadow observers run the same
166
- * chain for any agent and can never produce them.
174
+ * `CALLER_NOT_ALLOWED` (the caller check) and the input validation of the
175
+ * prebuilt-request modes — the review mode (`REVIEW_INPUT_INVALID` /
176
+ * `CRITERIA_INVALID`) and the v3.1 rank and verify modes
177
+ * (`RANK_INPUT_INVALID` / `CANDIDATE_INVALID` / `VERIFY_INPUT_INVALID` /
178
+ * `CLAIM_INVALID`). All of these are properties of the explicit tool surface,
179
+ * whose input the caller supplies directly, not of the gate chain; the
180
+ * J1/J3 shadow observers run the same chain for any agent and can never
181
+ * produce them.
167
182
  */
168
183
  export type GatedNativeJevFailure = Exclude<
169
184
  JevDecisionRunFailure,
170
- 'CALLER_NOT_ALLOWED' | 'REVIEW_INPUT_INVALID' | 'CRITERIA_INVALID'
185
+ | 'CALLER_NOT_ALLOWED'
186
+ | 'REVIEW_INPUT_INVALID'
187
+ | 'CRITERIA_INVALID'
188
+ | 'RANK_INPUT_INVALID'
189
+ | 'CANDIDATE_INVALID'
190
+ | 'VERIFY_INPUT_INVALID'
191
+ | 'CLAIM_INVALID'
171
192
  >
172
193
 
173
194
  /** The minimal runtime slice the gate chain needs. */
@@ -425,8 +446,10 @@ export async function runJevDecision(
425
446
  }
426
447
  // Review mode (J4): the bounded request is built before any gate work, and
427
448
  // an invalid review input is a tool-surface refusal — same class as the
428
- // caller check, never a gate failure.
429
- let reviewRequest: Omit<NativeDecisionRequest, 'model'> | undefined
449
+ // caller check, never a gate failure. The v3.1 rank and verify modes follow
450
+ // the same prebuilt-request pattern (no gate work for a malformed input);
451
+ // neither has a telemetry point — they are tool modes, not shadow gates.
452
+ let prebuilt: Omit<NativeDecisionRequest, 'model'> | undefined
430
453
  if (requested.mode === 'review') {
431
454
  const prepared = buildJevReviewRequest(input ?? {})
432
455
  if (!prepared.ok) {
@@ -441,7 +464,15 @@ export async function runJevDecision(
441
464
  )
442
465
  return refusal(prepared.reasonCode)
443
466
  }
444
- reviewRequest = prepared.request
467
+ prebuilt = prepared.request
468
+ } else if (requested.mode === 'rank') {
469
+ const prepared = buildJevRankRequest(input ?? {})
470
+ if (!prepared.ok) return refusal(prepared.reasonCode)
471
+ prebuilt = prepared.request
472
+ } else if (requested.mode === 'verify') {
473
+ const prepared = buildJevVerifyRequest(input ?? {})
474
+ if (!prepared.ok) return refusal(prepared.reasonCode)
475
+ prebuilt = prepared.request
445
476
  }
446
477
  const result = await runGatedNativeJevCall({
447
478
  sessionID: context?.sessionID,
@@ -449,13 +480,13 @@ export async function runJevDecision(
449
480
  agent: caller,
450
481
  runtime,
451
482
  prepare: async (route) =>
452
- reviewRequest !== undefined
483
+ prebuilt !== undefined
453
484
  ? {
454
485
  ok: true as const,
455
486
  request: {
456
487
  model: route.model,
457
- input: reviewRequest.input,
458
- questions: reviewRequest.questions,
488
+ input: prebuilt.input,
489
+ questions: prebuilt.questions,
459
490
  },
460
491
  }
461
492
  : requested.mode === undefined
@@ -541,6 +572,53 @@ export async function runJevDecision(
541
572
  frozen: result.call.frozen,
542
573
  })
543
574
  }
575
+ if (requested.mode === 'rank') {
576
+ // v3.1 rank: the winner choice plus that candidate's fit score. The host
577
+ // API answers one scalar per question, so no runner-up or full ordering is
578
+ // returned — see jev-rank-verify.ts for the honest limitation.
579
+ const rank = consumeJevRankResult(result.call.response, result.call.request)
580
+ return JSON.stringify({
581
+ advisory: true,
582
+ effect: 'none',
583
+ reason: 'JEV_DECISION',
584
+ caller,
585
+ route: {
586
+ providerID: result.call.selection.route.model.providerID,
587
+ id: result.call.selection.route.model.id,
588
+ billing: result.call.selection.route.billing,
589
+ },
590
+ mode: 'rank',
591
+ winner: rank.winner,
592
+ winnerFit: rank.winnerFit,
593
+ answers: advice.answers,
594
+ missing: advice.missing,
595
+ usage: { costUsd: advice.costUsd, tokens: advice.tokens },
596
+ frozen: result.call.frozen,
597
+ })
598
+ }
599
+ if (requested.mode === 'verify') {
600
+ // v3.1 verify: one PASS/FAIL/BLOCK verdict per claim, fail-closed. The
601
+ // tool never acts on the verdicts; a caller that requires a verdict
602
+ // treats a refusal (which never reaches this branch) as BLOCK.
603
+ const results = consumeJevVerifyResult(result.call.response, result.call.request)
604
+ return JSON.stringify({
605
+ advisory: true,
606
+ effect: 'none',
607
+ reason: 'JEV_DECISION',
608
+ caller,
609
+ route: {
610
+ providerID: result.call.selection.route.model.providerID,
611
+ id: result.call.selection.route.model.id,
612
+ billing: result.call.selection.route.billing,
613
+ },
614
+ mode: 'verify',
615
+ results,
616
+ answers: advice.answers,
617
+ missing: advice.missing,
618
+ usage: { costUsd: advice.costUsd, tokens: advice.tokens },
619
+ frozen: result.call.frozen,
620
+ })
621
+ }
544
622
  return JSON.stringify({
545
623
  advisory: true,
546
624
  effect: 'none',
@@ -567,7 +645,10 @@ const TOOL_DESCRIPTION =
567
645
  'host), `mode: "delegation"` to pick ' +
568
646
  'a specialist, `mode: "review"` to score a finished delegated result against named criteria ' +
569
647
  '(advisory quality score + needs-review flag; the result content itself is never sent — ' +
570
- 'shape metrics and criteria only), or pass explicit typed `questions` (choice, score, ' +
648
+ 'shape metrics and criteria only), `mode: "rank"` to pick the best of 2-8 named candidates ' +
649
+ '(returns the winner and its fit score; no full ordering), `mode: "verify"` to check 1-4 ' +
650
+ 'named claims (PASS/FAIL per claim; any refusal, timeout or malformed answer is BLOCK, ' +
651
+ 'fail-closed), or pass explicit typed `questions` (choice, score, ' +
571
652
  'predicate). Invalid-input refusals carry a `detail` token naming the exact cause. Returns ' +
572
653
  'probabilistic answers with confidence. Requires decision-router egress ' +
573
654
  'consent and budget caps; asks host permission first. It never dispatches agents, runs ' +
@@ -622,13 +703,45 @@ const REVIEW_METRICS_SCHEMA = {
622
703
  },
623
704
  } as const
624
705
 
706
+ const RANK_CANDIDATE_SCHEMA = {
707
+ type: 'object',
708
+ additionalProperties: false,
709
+ required: ['id'],
710
+ properties: {
711
+ id: {
712
+ type: 'string',
713
+ minLength: 1,
714
+ maxLength: 64,
715
+ pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$',
716
+ },
717
+ description: { type: 'string', minLength: 1, maxLength: 500 },
718
+ },
719
+ } as const
720
+
721
+ const VERIFY_CLAIM_SCHEMA = {
722
+ type: 'object',
723
+ additionalProperties: false,
724
+ required: ['name', 'claim'],
725
+ properties: {
726
+ name: {
727
+ type: 'string',
728
+ minLength: 1,
729
+ maxLength: 64,
730
+ pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$',
731
+ },
732
+ claim: { type: 'string', minLength: 1, maxLength: 200 },
733
+ },
734
+ } as const
735
+
625
736
  /**
626
- * One schema, two disjoint payloads: the state branch (presets and explicit
627
- * questions carry the state text) and the review branch (J4 takes structural
737
+ * One schema, four disjoint payloads: the state branch (presets and explicit
738
+ * questions carry the state text), the review branch (J4 takes structural
628
739
  * shape metrics, a delegate id and named criteria — never a state text, never
629
740
  * result content; the criteria are the only free text, bounded at the DSH
630
- * caps: at most 4, each 1–120 chars). The preparers are the authority; the
631
- * schema is the model-facing contract.
741
+ * caps: at most 4, each 1–120 chars), the rank branch (v3.1: a state plus
742
+ * 2–8 named candidates) and the verify branch (v3.1: 1–4 named claims, no
743
+ * state). The preparers are the authority; the schema is the model-facing
744
+ * contract.
632
745
  */
633
746
  const JEV_INPUT_SCHEMA: Record<string, unknown> = {
634
747
  type: 'object',
@@ -637,11 +750,13 @@ const JEV_INPUT_SCHEMA: Record<string, unknown> = {
637
750
  anyOf: [
638
751
  { required: ['state'] },
639
752
  { required: ['delegateId', 'resultSummaryKind', 'resultMetrics', 'criteria'] },
753
+ { required: ['candidates'] },
754
+ { required: ['claims'] },
640
755
  ],
641
756
  properties: {
642
757
  schemaVersion: { type: 'integer', const: 1 },
643
758
  state: { type: 'string', minLength: 1, maxLength: 12_000 },
644
- mode: { type: 'string', enum: ['skills', 'delegation', 'review'] },
759
+ mode: { type: 'string', enum: ['skills', 'delegation', 'review', 'rank', 'verify'] },
645
760
  questions: { type: 'array', minItems: 1, maxItems: 4, items: questionSchema },
646
761
  delegateId: {
647
762
  type: 'string',
@@ -657,6 +772,18 @@ const JEV_INPUT_SCHEMA: Record<string, unknown> = {
657
772
  maxItems: 4,
658
773
  items: { type: 'string', minLength: 1, maxLength: 120 },
659
774
  },
775
+ candidates: {
776
+ type: 'array',
777
+ minItems: 2,
778
+ maxItems: 8,
779
+ items: RANK_CANDIDATE_SCHEMA,
780
+ },
781
+ claims: {
782
+ type: 'array',
783
+ minItems: 1,
784
+ maxItems: 4,
785
+ items: VERIFY_CLAIM_SCHEMA,
786
+ },
660
787
  },
661
788
  }
662
789
 
@@ -36,7 +36,6 @@ export type NativeJevProviderId = Extract<
36
36
  DecisionProviderId,
37
37
  | 'typesafe-jev'
38
38
  | 'opencode-console-jev'
39
- | 'opencode-console-jev-free'
40
39
  | 'openrouter-jev'
41
40
  | 'vercel-gateway-jev'
42
41
  | 'cloudflare-workers-jev'
@@ -51,7 +50,6 @@ export type NativeJevProviderId = Extract<
51
50
  export const NATIVE_JEV_HOST_PROVIDERS = Object.freeze({
52
51
  'typesafe-jev': 'typesafe-ai',
53
52
  'opencode-console-jev': 'opencode',
54
- 'opencode-console-jev-free': 'opencode',
55
53
  // Host-embedded decision modules confirmed in the 2.2.5 binary
56
54
  // (providers/<id>/decisions, System One transport — the host normalizes
57
55
  // the request/response, so consumers only need the providerID mapping):
@@ -223,6 +221,8 @@ export type JevDecisionPreparationDetail =
223
221
  | 'SCORE_INVALID'
224
222
  | 'PREDICATE_HAS_CHOICES_OR_LEVELS'
225
223
  | 'QUESTION_TYPE_INVALID'
224
+ | 'SCHEMA_VERSION_INVALID'
225
+ | 'UNKNOWN_INPUT_KEYS'
226
226
 
227
227
  export type JevDecisionPreparation =
228
228
  | { readonly ok: true; readonly request: NativeDecisionRequest }
@@ -313,8 +313,23 @@ function readScoreQuestion(
313
313
  */
314
314
  export function prepareJevDecisionRequest(
315
315
  route: ResolvedNativeDecisionRoute,
316
- input: { readonly state?: unknown; readonly questions?: unknown },
316
+ input: {
317
+ readonly schemaVersion?: unknown
318
+ readonly state?: unknown
319
+ readonly questions?: unknown
320
+ },
317
321
  ): JevDecisionPreparation {
322
+ // Envelope enforcement (field report N2/N3): schemaVersion was documented
323
+ // as required but never checked, and unknown keys passed silently to the
324
+ // provider against the declared additionalProperties: false.
325
+ if (input.schemaVersion !== 1) {
326
+ return { ok: false, reasonCode: 'QUESTIONS_INVALID', detail: 'SCHEMA_VERSION_INVALID' }
327
+ }
328
+ const knownKeys = new Set(['schemaVersion', 'state', 'questions'])
329
+ const unknown = Object.keys(input).filter((key) => !knownKeys.has(key))
330
+ if (unknown.length > 0) {
331
+ return { ok: false, reasonCode: 'QUESTIONS_INVALID', detail: 'UNKNOWN_INPUT_KEYS' }
332
+ }
318
333
  const state = input.state
319
334
  if (!isBoundedNonBlankString(state, NATIVE_DECISION_MAX_PROMPT_LENGTH)) {
320
335
  return { ok: false, reasonCode: 'STATE_INVALID' }