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

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 (46) hide show
  1. package/CHANGELOG.md +39 -6
  2. package/README.md +6 -0
  3. package/bin/pantheon-init.mjs +15 -27
  4. package/package.json +1 -1
  5. package/plugin.json +1 -1
  6. package/pyproject.toml +1 -1
  7. package/scripts/decision-router-budget.mjs +102 -2
  8. package/scripts/decision-router-v2-budget.mjs +2 -2
  9. package/scripts/decision-router.mjs +82 -25
  10. package/scripts/install/decision-router-config.mjs +12 -4
  11. package/scripts/install/interactive.mjs +44 -27
  12. package/scripts/install/opencode.mjs +6 -0
  13. package/scripts/jev-live-probe.mjs +110 -84
  14. package/scripts/skill-search.mjs +242 -0
  15. package/src/agents/aphrodite.md +34 -1
  16. package/src/agents/apollo.md +227 -0
  17. package/src/agents/athena.md +24 -0
  18. package/src/agents/demeter.md +33 -0
  19. package/src/agents/gaia.md +24 -0
  20. package/src/agents/hephaestus.md +24 -0
  21. package/src/agents/hermes.md +33 -0
  22. package/src/agents/iris.md +24 -0
  23. package/src/agents/mnemosyne.md +25 -3
  24. package/src/agents/nyx.md +53 -22
  25. package/src/agents/prometheus.md +242 -1
  26. package/src/agents/talos.md +24 -0
  27. package/src/agents/themis.md +24 -0
  28. package/src/agents/zeus.md +36 -20
  29. package/src/pantheon/jev-decision-tool.ts +69 -11
  30. package/src/pantheon/jev-decisions.ts +68 -5
  31. package/src/pantheon/jev-quality-score.ts +1 -1
  32. package/src/pantheon/jev-rank-verify.ts +22 -7
  33. package/src/pantheon/jev-risk-gate.ts +1 -0
  34. package/src/pantheon/local-decision-budget.ts +169 -2
  35. package/src/pantheon/local-decision-router.ts +10 -0
  36. package/src/pantheon/local-decision-usage-evidence.internal.ts +2 -2
  37. package/src/pantheon/pantheon-decision-catalog.ts +1 -1
  38. package/src/pantheon/v2-decision-budget.ts +4 -2
  39. package/src/plugins/tui/dist/tui-v2.js +128 -25
  40. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  41. package/src/plugins/tui/dist/tui.js +1 -1
  42. package/src/plugins/tui/package-lock.json +2 -2
  43. package/src/plugins/tui/package.json +1 -1
  44. package/src/plugins/tui/src/whats-new-highlights.ts +59 -5
  45. package/src/plugins/tui/src/whats-new-open.ts +41 -1
  46. package/src/plugins/tui/src/whats-new.tsx +61 -8
@@ -224,14 +224,59 @@ export type JevDecisionPreparationDetail =
224
224
  | 'SCHEMA_VERSION_INVALID'
225
225
  | 'UNKNOWN_INPUT_KEYS'
226
226
 
227
+ export type JevSkillCandidateSource = 'prefilter' | 'full-catalog' | 'host-skills'
228
+
227
229
  export type JevDecisionPreparation =
228
- | { readonly ok: true; readonly request: NativeDecisionRequest }
230
+ | {
231
+ readonly ok: true
232
+ readonly request: NativeDecisionRequest
233
+ /** Skills mode only: which path produced the candidate pool. */
234
+ readonly candidateSource?: JevSkillCandidateSource
235
+ }
229
236
  | {
230
237
  readonly ok: false
231
238
  readonly reasonCode: JevDecisionPreparationFailure
232
239
  readonly detail?: JevDecisionPreparationDetail
233
240
  }
234
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
+
235
280
  function isBoundedNonBlankString(value: unknown, max: number): value is string {
236
281
  return typeof value === 'string' && value.trim().length > 0 && value.length <= max
237
282
  }
@@ -420,12 +465,21 @@ export function isJevDecisionPreset(value: unknown): value is JevDecisionPreset
420
465
  }
421
466
 
422
467
  /** Every canonical specialist except the orchestrator itself. */
423
- const SPECIALIST_CHOICES: ReadonlyArray<{ value: string }> = Object.freeze(
468
+ const SPECIALIST_CHOICES: ReadonlyArray<{ value: string; description?: string }> = Object.freeze(
424
469
  PANTHEON_AGENT_CATALOG.filter((agent) => agent.id !== 'zeus').map((agent) => ({
425
470
  value: agent.id,
471
+ description: boundedCatalogDescription(agent.description),
426
472
  })),
427
473
  )
428
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
+
429
483
  const SKILL_DESCRIPTIONS = new Map(
430
484
  PANTHEON_SKILL_CATALOG.map((entry) => [entry.id, entry.description]),
431
485
  )
@@ -521,7 +575,10 @@ export function prepareJevPresetRequest(
521
575
  instructions:
522
576
  'Choose one listed specialist only when the described task clearly needs it; ' +
523
577
  'otherwise choose none. This is advisory only; nothing is dispatched.',
524
- choices: [...SPECIALIST_CHOICES, { value: 'none' }],
578
+ choices: [
579
+ ...SPECIALIST_CHOICES,
580
+ { value: 'none', description: 'No specialist fits the described task.' },
581
+ ],
525
582
  },
526
583
  ],
527
584
  } satisfies NativeDecisionRequest
@@ -529,6 +586,9 @@ export function prepareJevPresetRequest(
529
586
  }
530
587
 
531
588
  const shortlist = selectPantheonSkills(state).skillIds
589
+ const hostHasSkills = Array.isArray(hostSkills) && hostSkills.length > 0
590
+ const candidateSource: JevSkillCandidateSource =
591
+ shortlist.length > 0 ? 'prefilter' : hostHasSkills ? 'host-skills' : 'full-catalog'
532
592
  const pool = shortlist.length > 0 ? shortlist : CATALOG_SKILL_IDS
533
593
  const descriptions = new Map(PANTHEON_SKILL_CATALOG.map((entry) => [entry.id, entry.description]))
534
594
  const request = {
@@ -541,11 +601,14 @@ export function prepareJevPresetRequest(
541
601
  instructions:
542
602
  'Choose the skills worth stacking for the described task, or none when none apply. ' +
543
603
  'This is advisory only; nothing is loaded or executed by this decision.',
544
- choices: [...mergeHostSkills(pool, hostSkills, descriptions), { value: 'none' }],
604
+ choices: [
605
+ ...mergeHostSkills(pool, hostSkills, descriptions),
606
+ { value: 'none', description: 'No skill stack fits the described task.' },
607
+ ],
545
608
  },
546
609
  ],
547
610
  } satisfies NativeDecisionRequest
548
- return { ok: true, request: Object.freeze(request) }
611
+ return { ok: true, request: Object.freeze(request), candidateSource }
549
612
  }
550
613
  // ─── Response consumption ───────────────────────────────────────────────
551
614
 
@@ -356,7 +356,7 @@ export function encodeQualityScoreReason(input: {
356
356
  * ANY other key — `state`, `questions`, or a smuggled content field — refuses
357
357
  * the preparation, so no content slot exists even at the input boundary.
358
358
  */
359
- const REVIEW_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
359
+ export const REVIEW_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
360
360
  'schemaVersion',
361
361
  'mode',
362
362
  'delegateId',
@@ -54,8 +54,8 @@ import { NATIVE_DECISION_MAX_PROMPT_LENGTH } from './v2-native-decisions.ts'
54
54
 
55
55
  /** A ranking needs at least two candidates to choose between. */
56
56
  export const RANK_MIN_CANDIDATES = 2
57
- /** Above eight, ranking degrades to explicit questions with a real rubric. */
58
- export const RANK_MAX_CANDIDATES = 8
57
+ /** Mirrors the typesafe_rank reference contract (1-20 accepted upstream). */
58
+ export const RANK_MAX_CANDIDATES = 20
59
59
 
60
60
  /** Question name of the rank's choice question. */
61
61
  export const RANK_WINNER_QUESTION_NAME = 'winner'
@@ -164,7 +164,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
164
164
 
165
165
  // ─── Rank: request building ──────────────────────────────────────────────
166
166
 
167
- const RANK_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
167
+ export const RANK_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
168
168
  'schemaVersion',
169
169
  'mode',
170
170
  'state',
@@ -173,13 +173,24 @@ const RANK_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
173
173
 
174
174
  export type JevRankBuildFailure = 'RANK_INPUT_INVALID' | 'CANDIDATE_INVALID' | 'STATE_INVALID'
175
175
 
176
+ /** Per-cause token attached to a rank build refusal (e.g. the accepted count range). */
177
+ export type JevRankBuildDetail = 'RANK_CANDIDATE_COUNT_RANGE'
178
+
176
179
  export type JevRankBuild =
177
180
  | { readonly ok: true; readonly request: Omit<NativeDecisionRequest, 'model'> }
178
- | { readonly ok: false; readonly reasonCode: JevRankBuildFailure }
181
+ | {
182
+ readonly ok: false
183
+ readonly reasonCode: JevRankBuildFailure
184
+ readonly detail?: JevRankBuildDetail
185
+ }
179
186
 
180
187
  export type JevRankPreparation =
181
188
  | { readonly ok: true; readonly request: NativeDecisionRequest }
182
- | { readonly ok: false; readonly reasonCode: JevRankBuildFailure }
189
+ | {
190
+ readonly ok: false
191
+ readonly reasonCode: JevRankBuildFailure
192
+ readonly detail?: JevRankBuildDetail
193
+ }
183
194
 
184
195
  /**
185
196
  * Validate the rank tool input and build the model-less request. The state is
@@ -205,7 +216,7 @@ export function buildJevRankRequest(input: unknown): JevRankBuild {
205
216
  if (rawCandidates === undefined) return { ok: false, reasonCode: 'RANK_INPUT_INVALID' }
206
217
  if (!Array.isArray(rawCandidates)) return { ok: false, reasonCode: 'CANDIDATE_INVALID' }
207
218
  if (rawCandidates.length < RANK_MIN_CANDIDATES || rawCandidates.length > RANK_MAX_CANDIDATES) {
208
- return { ok: false, reasonCode: 'CANDIDATE_INVALID' }
219
+ return { ok: false, reasonCode: 'CANDIDATE_INVALID', detail: 'RANK_CANDIDATE_COUNT_RANGE' }
209
220
  }
210
221
  const seen = new Set<string>()
211
222
  const choices: Array<{ value: string; description?: string }> = []
@@ -274,7 +285,11 @@ export function prepareJevRankRequest(
274
285
 
275
286
  // ─── Verify: request building ────────────────────────────────────────────
276
287
 
277
- const VERIFY_ENVELOPE_KEYS: ReadonlySet<string> = new Set(['schemaVersion', 'mode', 'claims'])
288
+ export const VERIFY_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
289
+ 'schemaVersion',
290
+ 'mode',
291
+ 'claims',
292
+ ])
278
293
 
279
294
  export type JevVerifyBuildFailure = 'VERIFY_INPUT_INVALID' | 'CLAIM_INVALID'
280
295
 
@@ -349,6 +349,7 @@ const SKIP_REASON_BY_GATE_FAILURE: Readonly<Record<GatedNativeJevFailure, string
349
349
  PRESET_INVALID: 'skip-request-invalid',
350
350
  RESERVATION_DENIED: 'skip-reservation-denied',
351
351
  DECISION_CALL_FAILED: 'skip-decision-call-failed',
352
+ USAGE_EVIDENCE_UNAVAILABLE: 'skip-usage-evidence-unavailable',
352
353
  USAGE_UNRECONCILED: 'skip-usage-unreconciled',
353
354
  })
354
355
 
@@ -82,6 +82,20 @@ export interface UncertainReservation {
82
82
  updatedAtMs: number
83
83
  }
84
84
 
85
+ export interface ReleasedHold {
86
+ reservationId: string
87
+ provider: string
88
+ model: string
89
+ period: string
90
+ reservedMicros: number
91
+ stateAtRelease: 'pending' | 'uncertain'
92
+ reason: string
93
+ createdAtMs: number
94
+ releasedAtMs: number
95
+ }
96
+
97
+ export type ReleaseHoldsResult = { released: number; freedMicros: number }
98
+
85
99
  export interface LocalDecisionBudgetLedger {
86
100
  /** Admin/configuration API: writes policy to the local user-level DB. */
87
101
  configureUserCaps(caps: BudgetCaps): void
@@ -107,6 +121,16 @@ export interface LocalDecisionBudgetLedger {
107
121
  listUncertainReservations(): UncertainReservation[]
108
122
  /** Recovery only moves pending rows to uncertain; it never releases budget. */
109
123
  recoverPendingReservations(): number
124
+ /**
125
+ * Release every unresolved hold of one provider, archiving each row into
126
+ * `released_holds` with the mandatory reason. Deliberately narrow: this is
127
+ * the administrative correction for holds of routes that no longer exist
128
+ * (they can never reconcile, so they would freeze budget forever). Live
129
+ * providers roll their holds off with the period instead.
130
+ */
131
+ releaseHoldsForProvider(provider: string, reason: string): ReleaseHoldsResult
132
+ /** Recent archived releases, newest first — the audit view of the above. */
133
+ listReleasedHolds(limit?: number): ReleasedHold[]
110
134
  /** Prune resolved reservations from past UTC periods with no unresolved holds. */
111
135
  pruneCompletedPeriods(): number
112
136
  close(): void
@@ -123,9 +147,11 @@ export interface OpenLocalDecisionBudgetOptions {
123
147
  busyTimeoutMs?: number
124
148
  }
125
149
 
126
- const SCHEMA_VERSION = 3
150
+ const SCHEMA_VERSION = 4
127
151
  const VERSION_TWO = 2
128
152
  const APPLICATION_ID = 0x50424c31
153
+ /** Reason strings recorded on a released hold are bounded for the audit trail. */
154
+ const RELEASE_REASON_MAX_LENGTH = 200
129
155
  const DB_FILENAME = 'decision-budget.sqlite'
130
156
  /** Accounting provider IDs accepted by the ledger. */
131
157
  export const LOCAL_DECISION_BUDGET_PROVIDERS: readonly BudgetProvider[] = Object.freeze([
@@ -608,6 +634,101 @@ export function openLocalDecisionBudgetLedger(
608
634
  })
609
635
  }
610
636
 
637
+ function releaseHoldsForProvider(provider: string, reason: string): ReleaseHoldsResult {
638
+ if (typeof provider !== 'string' || provider.length < 1 || provider.length > 64) {
639
+ return { released: 0, freedMicros: 0 }
640
+ }
641
+ if (
642
+ typeof reason !== 'string' ||
643
+ reason.length < 1 ||
644
+ reason.length > RELEASE_REASON_MAX_LENGTH
645
+ ) {
646
+ return { released: 0, freedMicros: 0 }
647
+ }
648
+ return inImmediateTransaction(() => {
649
+ const timestamp = now()
650
+ const rows = db
651
+ .prepare(
652
+ `SELECT id, provider, model, period_utc, reserved_micros, state, created_at_ms
653
+ FROM reservations WHERE provider = ? AND state IN ('pending', 'uncertain')
654
+ ORDER BY created_at_ms, id`,
655
+ )
656
+ .all(provider) as Array<{
657
+ id: string
658
+ provider: string
659
+ model: string
660
+ period_utc: string
661
+ reserved_micros: number
662
+ state: 'pending' | 'uncertain'
663
+ created_at_ms: number
664
+ }>
665
+ if (rows.length === 0) return { released: 0, freedMicros: 0 }
666
+ const archive = db.prepare(
667
+ `INSERT INTO released_holds
668
+ (reservation_id, provider, model, period_utc, reserved_micros, state_at_release,
669
+ reason, created_at_ms, released_at_ms)
670
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
671
+ )
672
+ let freedMicros = 0
673
+ for (const row of rows) {
674
+ archive.run(
675
+ row.id,
676
+ row.provider,
677
+ row.model,
678
+ row.period_utc,
679
+ row.reserved_micros,
680
+ row.state,
681
+ reason,
682
+ row.created_at_ms,
683
+ timestamp,
684
+ )
685
+ freedMicros = safeMicrosTotal(freedMicros + row.reserved_micros)
686
+ }
687
+ const remove = db
688
+ .prepare(
689
+ `DELETE FROM reservations WHERE provider = ? AND state IN ('pending', 'uncertain')`,
690
+ )
691
+ .run(provider)
692
+ if (safeChangeCount(remove.changes) !== rows.length) {
693
+ throw new Error('Reservation rows changed during release')
694
+ }
695
+ return { released: rows.length, freedMicros }
696
+ })
697
+ }
698
+
699
+ function listReleasedHolds(limit?: number): ReleasedHold[] {
700
+ const bound =
701
+ typeof limit === 'number' && Number.isInteger(limit) && limit > 0 ? Math.min(limit, 200) : 20
702
+ const rows = db
703
+ .prepare(
704
+ `SELECT reservation_id, provider, model, period_utc, reserved_micros, state_at_release,
705
+ reason, created_at_ms, released_at_ms
706
+ FROM released_holds ORDER BY released_at_ms DESC, reservation_id LIMIT ?`,
707
+ )
708
+ .all(bound) as Array<{
709
+ reservation_id: string
710
+ provider: string
711
+ model: string
712
+ period_utc: string
713
+ reserved_micros: number
714
+ state_at_release: string
715
+ reason: string
716
+ created_at_ms: number
717
+ released_at_ms: number
718
+ }>
719
+ return rows.map((row) => ({
720
+ reservationId: row.reservation_id,
721
+ provider: row.provider,
722
+ model: row.model,
723
+ period: row.period_utc,
724
+ reservedMicros: row.reserved_micros,
725
+ stateAtRelease: row.state_at_release === 'uncertain' ? 'uncertain' : 'pending',
726
+ reason: row.reason,
727
+ createdAtMs: row.created_at_ms,
728
+ releasedAtMs: row.released_at_ms,
729
+ }))
730
+ }
731
+
611
732
  function pruneCompletedPeriods(): number {
612
733
  return inImmediateTransaction(() => {
613
734
  let currentPeriod: string
@@ -675,6 +796,8 @@ export function openLocalDecisionBudgetLedger(
675
796
  reconcileVerified,
676
797
  listUncertainReservations,
677
798
  recoverPendingReservations,
799
+ releaseHoldsForProvider,
800
+ listReleasedHolds,
678
801
  pruneCompletedPeriods,
679
802
  close: () => db.close(),
680
803
  }
@@ -699,12 +822,16 @@ function ensureSchema(db: DatabaseSync): void {
699
822
  if (applicationId !== 0 || tables.length !== 0) {
700
823
  throw new Error('Refusing to initialize an unrecognized SQLite database')
701
824
  }
702
- createSchemaV3(db)
825
+ createSchemaV4(db)
703
826
  } else if (version === 1 && applicationId === APPLICATION_ID) {
704
827
  migrateVersionOne(db)
705
828
  migrateVersionTwoToThree(db)
829
+ migrateVersionThreeToFour(db)
706
830
  } else if (version === VERSION_TWO && applicationId === APPLICATION_ID) {
707
831
  migrateVersionTwoToThree(db)
832
+ migrateVersionThreeToFour(db)
833
+ } else if (version === 3 && applicationId === APPLICATION_ID) {
834
+ migrateVersionThreeToFour(db)
708
835
  } else if (version !== SCHEMA_VERSION || applicationId !== APPLICATION_ID) {
709
836
  throw new Error('Unsupported or incompatible local decision budget database schema')
710
837
  }
@@ -802,10 +929,50 @@ function migrateVersionTwoToThree(db: DatabaseSync): void {
802
929
  INSERT INTO ledger_state (id, active_period_utc)
803
930
  SELECT id, NULL FROM ledger_state_v2;
804
931
  DROP TABLE ledger_state_v2;
932
+ PRAGMA user_version = 3;
933
+ `)
934
+ }
935
+
936
+ /**
937
+ * v4 adds the `released_holds` archive (immutable audit trail for the
938
+ * administrative release of dead-route holds). The live `reservations` table
939
+ * and its state CHECK are untouched — a release archives the row and deletes
940
+ * it, so the accounting keeps summing only live states.
941
+ */
942
+ function migrateVersionThreeToFour(db: DatabaseSync): void {
943
+ validateVersionThreeSchema(db)
944
+ db.exec(`
945
+ CREATE TABLE released_holds (
946
+ reservation_id TEXT PRIMARY KEY NOT NULL,
947
+ provider TEXT NOT NULL,
948
+ model TEXT NOT NULL,
949
+ period_utc TEXT NOT NULL CHECK (length(period_utc) = 7),
950
+ reserved_micros INTEGER NOT NULL CHECK (reserved_micros > 0),
951
+ state_at_release TEXT NOT NULL CHECK (state_at_release IN ('pending', 'uncertain')),
952
+ reason TEXT NOT NULL CHECK (length(reason) BETWEEN 1 AND ${RELEASE_REASON_MAX_LENGTH}),
953
+ created_at_ms INTEGER NOT NULL,
954
+ released_at_ms INTEGER NOT NULL
955
+ ) STRICT;
956
+ CREATE INDEX released_holds_released_idx ON released_holds (released_at_ms, reservation_id);
805
957
  PRAGMA user_version = ${SCHEMA_VERSION};
806
958
  `)
807
959
  }
808
960
 
961
+ function createSchemaV4(db: DatabaseSync): void {
962
+ createSchemaV3(db)
963
+ migrateVersionThreeToFour(db)
964
+ }
965
+
966
+ function validateVersionThreeSchema(db: DatabaseSync): void {
967
+ // The v3 tables match the post-migration shape; the v4 step adds
968
+ // released_holds on top of them.
969
+ db.prepare(
970
+ `SELECT id, provider, model, period_utc, reserved_micros, actual_micros, state,
971
+ created_at_ms, updated_at_ms FROM reservations LIMIT 0`,
972
+ )
973
+ db.prepare('SELECT id, active_period_utc FROM ledger_state LIMIT 0')
974
+ }
975
+
809
976
  function migrateVersionOne(db: DatabaseSync): void {
810
977
  validateVersionOneSchema(db)
811
978
  const providers = db
@@ -32,6 +32,7 @@ export interface LocalDecisionInput {
32
32
 
33
33
  export type LocalDecisionRouteReasonCode =
34
34
  | 'DISABLED'
35
+ | 'GATE_OPEN'
35
36
  | 'INVALID_INPUT'
36
37
  | 'NO_DOMAIN'
37
38
  | 'AMBIGUOUS_DOMAIN'
@@ -192,6 +193,15 @@ function evaluateEnabledInput(input: unknown): LocalDecisionRecommendation {
192
193
  }
193
194
  }
194
195
 
196
+ // D1 (field report beta.11→12): gateStatus must influence the output. An
197
+ // open review/approval gate abstains — the advisory never routes around a
198
+ // gate; resolving the gate is the caller's move, then this router answers.
199
+ if (gateStatus === 'review_required' || gateStatus === 'human_approval_required') {
200
+ return {
201
+ ...createAbstention('GATE_OPEN', complexity.reasonCode, gateStatus),
202
+ complexity,
203
+ }
204
+ }
195
205
  return {
196
206
  schemaVersion: 1,
197
207
  policyVersion: LOCAL_DECISION_ROUTER_POLICY_VERSION,
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  /** Providers that can appear in usage details: native Decisions routes. */
11
- export type UsageProvider = 'typesafe-jev' | 'opencode-console'
11
+ export type UsageProvider = 'typesafe-jev' | 'opencode-console' | 'openrouter'
12
12
 
13
13
  export interface ParsedUsageCounts {
14
14
  provider: UsageProvider
@@ -47,7 +47,7 @@ const evidenceDetails = new WeakMap<object, VerifiedUsageEvidenceDetails>()
47
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'
50
+ return value === 'typesafe-jev' || value === 'opencode-console' || value === 'openrouter'
51
51
  }
52
52
 
53
53
  /**
@@ -53,7 +53,7 @@ export const PANTHEON_AGENT_CATALOG: readonly DecisionCatalogEntry[] = Object.fr
53
53
  { id: 'themis', description: 'Quality and security review gate.' },
54
54
  { id: 'prometheus', description: 'Infrastructure, Docker, CI, and model providers.' },
55
55
  { id: 'hephaestus', description: 'AI pipelines: LangChain, RAG, vector stores.' },
56
- { id: 'nyx', description: 'Observability, tracing, and cost analytics.' },
56
+ { id: 'nyx', description: 'Chaos and adversarial testing: fuzzing, hostile inputs, boundaries.' },
57
57
  { id: 'gaia', description: 'Remote sensing and geospatial analysis.' },
58
58
  { id: 'iris', description: 'GitHub branches, pull requests, issues, releases.' },
59
59
  { id: 'mnemosyne', description: 'Memory bank and ADR authoring on request.' },
@@ -288,7 +288,9 @@ export function readDecisionBudgetLedgerFacts(dbPath: string): DecisionBudgetLed
288
288
  .user_version
289
289
  const applicationId = (db.prepare('PRAGMA application_id').get() as { application_id: number })
290
290
  .application_id
291
- if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3) {
291
+ // v4 adds the released_holds archive; the live tables this module reads
292
+ // are identical from v3 through v4.
293
+ if (applicationId !== EXPECTED_APPLICATION_ID || (version !== 3 && version !== 4)) {
292
294
  return { present: true, readable: false, reason: 'unsupported-schema' }
293
295
  }
294
296
  const activeRow = db.prepare('SELECT active_period_utc FROM ledger_state WHERE id = 1').get() as
@@ -425,7 +427,7 @@ export function listDecisionHoldsReadOnly(dbPath: string): DecisionHoldRow[] | n
425
427
  .application_id
426
428
  const version = (db.prepare('PRAGMA user_version').get() as { user_version: number })
427
429
  .user_version
428
- if (applicationId !== EXPECTED_APPLICATION_ID || version !== 3) return null
430
+ if (applicationId !== EXPECTED_APPLICATION_ID || (version !== 3 && version !== 4)) return null
429
431
  const rows = db
430
432
  .prepare(
431
433
  `SELECT id, provider, model, period_utc, reserved_micros, state