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

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 (54) hide show
  1. package/AGENTS.global.md +1 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +81 -0
  4. package/README.md +20 -2
  5. package/bin/pantheon-init.mjs +15 -27
  6. package/package.json +1 -1
  7. package/plugin.json +1 -1
  8. package/pyproject.toml +1 -1
  9. package/scripts/decision-router-budget.mjs +103 -4
  10. package/scripts/decision-router-v2-budget.mjs +2 -2
  11. package/scripts/decision-router-v2-egress.mjs +0 -2
  12. package/scripts/decision-router.mjs +88 -6
  13. package/scripts/install/decision-router-config.mjs +53 -2
  14. package/scripts/install/interactive.mjs +96 -11
  15. package/scripts/install/opencode.mjs +26 -0
  16. package/scripts/install/plugin.mjs +17 -0
  17. package/scripts/jev-live-probe.mjs +210 -0
  18. package/scripts/skill-search.mjs +242 -0
  19. package/scripts/sync-tui.mjs +11 -0
  20. package/src/agents/aphrodite.md +34 -1
  21. package/src/agents/apollo.md +227 -0
  22. package/src/agents/athena.md +24 -0
  23. package/src/agents/demeter.md +33 -0
  24. package/src/agents/gaia.md +24 -0
  25. package/src/agents/hephaestus.md +24 -0
  26. package/src/agents/hermes.md +33 -0
  27. package/src/agents/iris.md +24 -0
  28. package/src/agents/mnemosyne.md +25 -3
  29. package/src/agents/nyx.md +53 -22
  30. package/src/agents/prometheus.md +242 -1
  31. package/src/agents/talos.md +24 -0
  32. package/src/agents/themis.md +24 -0
  33. package/src/agents/zeus.md +46 -6
  34. package/src/pantheon/j-telemetry-file.ts +96 -0
  35. package/src/pantheon/jev-decision-tool.ts +160 -24
  36. package/src/pantheon/jev-decisions.ts +18 -3
  37. package/src/pantheon/jev-rank-verify.ts +435 -0
  38. package/src/pantheon/jev-risk-gate.ts +1 -0
  39. package/src/pantheon/local-decision-budget.ts +170 -5
  40. package/src/pantheon/local-decision-provider-matrix.ts +0 -1
  41. package/src/pantheon/local-decision-usage-evidence.internal.ts +2 -2
  42. package/src/pantheon/v2-decision-budget.ts +4 -2
  43. package/src/plugin-v2.ts +9 -2
  44. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  45. package/src/plugins/tui/dist/tui-v2.js +457 -4
  46. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  47. package/src/plugins/tui/dist/tui.js +1 -1
  48. package/src/plugins/tui/package-lock.json +2 -2
  49. package/src/plugins/tui/package.json +1 -1
  50. package/src/plugins/tui/src/index-v2.tsx +6 -0
  51. package/src/plugins/tui/src/whats-new-highlights.ts +263 -0
  52. package/src/plugins/tui/src/whats-new-open.ts +80 -0
  53. package/src/plugins/tui/src/whats-new-state.ts +128 -0
  54. package/src/plugins/tui/src/whats-new.tsx +119 -0
@@ -29,7 +29,6 @@ export const DECISION_ROUTER_MODELS = Object.freeze({
29
29
  'openai-decisions': Object.freeze(['gpt-6-luna']),
30
30
  'typesafe-jev': Object.freeze(['jev-1.14.0']),
31
31
  'opencode-console-jev': Object.freeze(['jev-1.13']),
32
- 'opencode-console-jev-free': Object.freeze(['jev-1.13-free']),
33
32
  // Host-embedded decision modules confirmed in the 2.2.5 binary; the model
34
33
  // ids are the provider-side decision models (see
35
34
  // docs/reference/native-decisions.md for credential acquisition).
@@ -43,7 +42,6 @@ export const DECISION_PROVIDER_BUDGET_MAPPING = Object.freeze({
43
42
  'openai-decisions': 'openai-decisions',
44
43
  'typesafe-jev': 'typesafe-jev',
45
44
  'opencode-console-jev': 'opencode-console',
46
- 'opencode-console-jev-free': 'jev-free',
47
45
  'openrouter-jev': 'openrouter',
48
46
  'vercel-gateway-jev': 'vercel-ai-gateway',
49
47
  'cloudflare-workers-jev': 'cloudflare-workers-ai',
@@ -629,6 +627,59 @@ export function provisionTypesafeHostProvider({ env = process.env } = {}) {
629
627
  }
630
628
  }
631
629
 
630
+ /**
631
+ * Additively merge the Cloudflare Workers AI decision provider entry into the
632
+ * user's host `opencode.json`. The host's embedded `cloudflare-workers-ai`
633
+ * decisions module needs the accountId in the entry options and reads the
634
+ * token from `CLOUDFLARE_API_TOKEN` (a Workers AI-scoped token — not the
635
+ * global Cloudflare key). Existing entries are preserved.
636
+ * @param {{ accountId: string, env?: Record<string, string | undefined> }} options
637
+ * @returns {{ ok: true, path: string } | { ok: false, reason: string }}
638
+ */
639
+ export function provisionCloudflareHostProvider({ accountId, env = process.env } = {}) {
640
+ const trimmed = String(accountId ?? '').trim()
641
+ if (!/^[a-f0-9]{32}$/i.test(trimmed)) {
642
+ return { ok: false, reason: 'accountId must be the 32-hex Cloudflare account id' }
643
+ }
644
+ const configPath = resolveHostOpenCodeConfigPath(env)
645
+ if (!existsSync(configPath)) return { ok: false, reason: 'opencode.json not found' }
646
+ let data
647
+ try {
648
+ const parsed = JSON.parse(readFileSync(configPath, 'utf8'))
649
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
650
+ return { ok: false, reason: 'opencode.json is not a JSON object' }
651
+ }
652
+ data = parsed
653
+ } catch {
654
+ return { ok: false, reason: 'opencode.json is not plain JSON (comments?)' }
655
+ }
656
+ data.providers ??= {}
657
+ data.providers['cloudflare-workers-ai'] ??= {}
658
+ data.providers['cloudflare-workers-ai'].options ??= {}
659
+ const provider = data.providers['cloudflare-workers-ai']
660
+ const existingAccountId = provider.options.accountId
661
+ if (existingAccountId != null && String(existingAccountId).trim() !== '') {
662
+ if (String(existingAccountId).trim().toLowerCase() !== trimmed.toLowerCase()) {
663
+ return { ok: false, reason: 'existing accountId conflicts with --account-id' }
664
+ }
665
+ } else {
666
+ provider.options.accountId = trimmed
667
+ }
668
+ provider.models ??= {}
669
+ if (provider.models.clef === undefined) {
670
+ provider.models.clef = {
671
+ name: 'Clef (Cloudflare Workers AI)',
672
+ type: 'decision',
673
+ }
674
+ }
675
+ try {
676
+ writeFileSync(configPath, `${JSON.stringify(data, null, 2)}\n`)
677
+ return { ok: true, path: configPath }
678
+ } catch (error) {
679
+ return { ok: false, reason: String(error instanceof Error ? error.message : error) }
680
+ }
681
+ }
682
+
632
683
  /**
633
684
  * Read-only check that the TypeSafe provider entry exists in the host config.
634
685
  * Never writes; an unreadable config reports present:false with the path for
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { mkdirSync, writeFileSync } from 'node:fs'
4
+ import { join } from 'node:path'
3
5
  import * as clack from '@clack/prompts'
4
6
  import {
5
7
  createDecisionRouterConfig,
@@ -54,8 +56,8 @@ export async function promptReview(
54
56
  /**
55
57
  * Collect interactive setup choices before the installer begins any writes.
56
58
  *
57
- * @param {{ components?: string[], defaultComponents?: string[], noMcp?: boolean, prompts?: typeof clack, isTTY?: boolean, getDecisionRouterConfig?: (target: string) => unknown }} [options]
58
- * @returns {Promise<{ components?: Set<string>, target?: string, decisionRouterConfig?: object, canceled?: boolean, cancelPoint?: string }>}
59
+ * @param {{ components?: string[], defaultComponents?: string[], noMcp?: boolean, prompts?: typeof clack, isTTY?: boolean, env?: Record<string, string | undefined>, getDecisionRouterConfig?: (target: string) => unknown }} [options]
60
+ * @returns {Promise<{ components?: Set<string>, target?: string, decisionRouterConfig?: object, decisionModelActivation?: object | null, decisionModelDeferredSetup?: object | null, canceled?: boolean, cancelPoint?: string }>}
59
61
  *
60
62
  * `cancelPoint` names the setup choice where the user stopped (`components` or
61
63
  * `target`), so the caller can print one explainable line and persist the same
@@ -65,6 +67,7 @@ export async function runInteractiveInstall({
65
67
  components = [],
66
68
  defaultComponents = [],
67
69
  noMcp = false,
70
+ env = process.env,
68
71
  getDecisionRouterConfig = () => DEFAULT_DECISION_ROUTER_CONFIG,
69
72
  prompts = clack,
70
73
  isTTY = isTerminal(),
@@ -136,7 +139,7 @@ export async function runInteractiveInstall({
136
139
  // that setup-model writes.
137
140
  const jevActivation = await prompts.select({
138
141
  message:
139
- 'Configure the Jev decision model now? (advisory tool for Zeus; one write: selection, consent, caps, period — USD caps are required)',
142
+ 'Configure the Jev decision model now? (Console, OpenRouter, and TypeSafe activate here; Cloudflare is provisioned after install)',
140
143
  options: [
141
144
  {
142
145
  label: 'Skip (default)',
@@ -146,17 +149,22 @@ export async function runInteractiveInstall({
146
149
  {
147
150
  label: 'OpenCode Console Jev (stock)',
148
151
  value: 'opencode-console-jev/jev-1.13',
149
- hint: 'Billed to your Console; uses host-owned auth',
152
+ hint: consoleJevHint(env),
150
153
  },
151
154
  {
152
- label: 'Console Jev free variant',
153
- value: 'opencode-console-jev-free/jev-1.13-free',
154
- hint: 'No paid budget consumed; host-owned auth',
155
+ label: 'OpenRouter-hosted Jev',
156
+ value: 'openrouter-jev/typesafe/jev-1.13',
157
+ hint: openrouterJevHint(),
155
158
  },
156
159
  {
157
160
  label: 'TypeSafe Jev (direct)',
158
161
  value: 'typesafe-jev/jev-1.14.0',
159
- hint: 'Installer merges the provider entry; you sign in with your TypeSafe key (/connect)',
162
+ hint: typesafeJevHint(env),
163
+ },
164
+ {
165
+ label: 'Cloudflare Clef (provision after install)',
166
+ value: 'cloudflare-workers-jev/clef',
167
+ hint: cloudflareJevHint(env),
160
168
  },
161
169
  ],
162
170
  initialValue: 'skip',
@@ -164,18 +172,54 @@ export async function runInteractiveInstall({
164
172
  if (cancelPrompt(prompts, jevActivation, 'decisionRouter')) {
165
173
  return { canceled: true, cancelPoint: 'decisionRouter' }
166
174
  }
167
- // Only known targets activate; anything else (a stale stub, a renamed
168
- // option) degrades to skip instead of configuring a wrong route.
175
+
176
+ // Decision-layer options: the shadow gates and the specialist-caller
177
+ // allowlist are first-class setup choices. The installer writes a flags
178
+ // file the user sources (the host reads these at plugin registration from
179
+ // its own environment — the installer never edits shell profiles silently).
180
+ const jevFlags = await prompts.multiselect({
181
+ message:
182
+ 'Decision layer extras (shadow gates are observe-only; specialist access is explicit):',
183
+ options: [
184
+ {
185
+ label: 'J1 risk-score shadow gate',
186
+ value: 'PANTHEON_J1_RISK_SCORE=on',
187
+ hint: 'Records a Jev risk-score per exfil-capable tool call; observe-only',
188
+ },
189
+ {
190
+ label: 'J3 escalation shadow classifier',
191
+ value: 'PANTHEON_J3_ESCALATION=on',
192
+ hint: 'Records cheap-vs-main per delegate dispatch; never applies overrides in shadow',
193
+ },
194
+ {
195
+ label: 'Specialist callers: athena + themis (explicit questions)',
196
+ value: 'PANTHEON_JEV_SPECIALIST_CALLERS=athena,themis',
197
+ hint: 'Allowlisted specialists may ask bounded Jev questions mid-task; presets stay Zeus-only',
198
+ },
199
+ ],
200
+ required: false,
201
+ initialValues: [],
202
+ })
203
+ if (cancelPrompt(prompts, jevFlags, 'decisionFlags')) {
204
+ return { canceled: true, cancelPoint: 'decisionFlags' }
205
+ }
206
+ // Cloudflare needs an account-specific host provider entry. It remains an
207
+ // explicit deferred choice; setup-model must receive --account-id before any
208
+ // route is enabled.
169
209
  const KNOWN_JEV_TARGETS = new Set([
170
210
  'opencode-console-jev/jev-1.13',
171
- 'opencode-console-jev-free/jev-1.13-free',
211
+ 'openrouter-jev/typesafe/jev-1.13',
172
212
  'typesafe-jev/jev-1.14.0',
173
213
  ])
214
+ const cloudflareDeferred = jevActivation === 'cloudflare-workers-jev/clef'
174
215
  const activationChoice =
175
216
  typeof jevActivation === 'string' && KNOWN_JEV_TARGETS.has(jevActivation)
176
217
  ? jevActivation
177
218
  : 'skip'
178
219
  let decisionModelActivation = null
220
+ const decisionModelDeferredSetup = cloudflareDeferred
221
+ ? { target: 'cloudflare-workers-jev/clef' }
222
+ : null
179
223
  if (activationChoice !== 'skip') {
180
224
  // Caps prompts degrade to the recommended defaults when the prompt
181
225
  // implementation has no text input (stubbed tests, restricted TTYs).
@@ -202,10 +246,51 @@ export async function runInteractiveInstall({
202
246
  }
203
247
  }
204
248
 
249
+ // Empty/absent caller allowlist is intentionally Zeus-only. Persist that
250
+ // default too, so rerunning the wizard cannot leave a prior allowlist active.
251
+ const selectedFlags = Array.isArray(jevFlags) ? jevFlags : []
252
+ const hasCallerFlag = selectedFlags.some((flag) =>
253
+ flag.startsWith('PANTHEON_JEV_SPECIALIST_CALLERS='),
254
+ )
255
+ const flagsDir = join(env.XDG_CONFIG_HOME || `${env.HOME}/.config`, 'pantheon')
256
+ mkdirSync(flagsDir, { recursive: true, mode: 0o700 })
257
+ const flagsPath = join(flagsDir, 'decision-flags.env')
258
+ const lines = selectedFlags.map((flag) => `export ${flag}`)
259
+ if (!hasCallerFlag) lines.push('export PANTHEON_JEV_SPECIALIST_CALLERS=')
260
+ writeFileSync(
261
+ flagsPath,
262
+ `# Pantheon decision layer — source from your shell profile\n${lines.join('\n')}\n`,
263
+ )
264
+
205
265
  return {
206
266
  components: selectedComponents,
207
267
  target,
208
268
  decisionRouterConfig: createDecisionRouterConfig(DECISION_ROUTER_PROVIDERS[0], false),
209
269
  decisionModelActivation,
270
+ decisionModelDeferredSetup,
210
271
  }
211
272
  }
273
+
274
+ /** Credential-state hints for the Jev wizard routes (set at prompt time). */
275
+ function consoleJevHint(env = process.env) {
276
+ return env.OPENCODE_API_KEY
277
+ ? 'Zen credits via OPENCODE_API_KEY — ✓ detected in this shell'
278
+ : 'Zen credits via OPENCODE_API_KEY — export it first (opencode.ai/console)'
279
+ }
280
+
281
+ function openrouterJevHint() {
282
+ return 'Uses the host OpenRouter credential (opencode auth list); billed per decision'
283
+ }
284
+
285
+ function typesafeJevHint(env = process.env) {
286
+ return env.TYPESAFE_API_KEY
287
+ ? '✓ TYPESAFE_API_KEY detected — the installer merges the provider entry'
288
+ : 'export TYPESAFE_API_KEY first; the installer merges the provider entry'
289
+ }
290
+
291
+ function cloudflareJevHint(env = process.env) {
292
+ const tokenHint = env.CLOUDFLARE_API_TOKEN
293
+ ? 'CLOUDFLARE_API_TOKEN detected'
294
+ : 'requires a Workers AI-scoped CLOUDFLARE_API_TOKEN'
295
+ return `${tokenHint}; not activated by this wizard. After install run: npx pantheon-opencode decision-router setup-model cloudflare-workers-jev/clef --account-id=<32-hex-id> --monthly-usd 5 --per-decision-usd 0.10`
296
+ }
@@ -1646,6 +1646,8 @@ async function installPass(
1646
1646
  )
1647
1647
  /** Wizard-confirmed Jev activation (target + caps), surfaced on the result. */
1648
1648
  let decisionModelActivation = null
1649
+ /** Cloudflare needs a user-supplied account ID, so the wizard defers it. */
1650
+ let decisionModelDeferredSetup = null
1649
1651
  const stats = summary.opencode
1650
1652
  // Per-call baseline. `stats` is the module-level cumulative summary, so the
1651
1653
  // consistency guard must compare against THIS call's delta, not the total.
@@ -1804,6 +1806,7 @@ async function installPass(
1804
1806
  },
1805
1807
  prompts: opts.deps?.prompts,
1806
1808
  isTTY: opts.deps?.isTTY,
1809
+ env: opts.deps?.env ?? opts.env ?? process.env,
1807
1810
  })
1808
1811
 
1809
1812
  // Resolve the location from the SELECTION before any cancel return: a
@@ -1840,6 +1843,7 @@ async function installPass(
1840
1843
  decisionRouterConfig = migrateDecisionRouterConfig(result.decisionRouterConfig)
1841
1844
  opts.decisionRouterConfig = decisionRouterConfig
1842
1845
  decisionModelActivation = result.decisionModelActivation ?? null
1846
+ decisionModelDeferredSetup = result.decisionModelDeferredSetup ?? null
1843
1847
  if (!dryRun && _lastRun) _lastRun.target = target
1844
1848
  }
1845
1849
 
@@ -2789,6 +2793,26 @@ async function installPass(
2789
2793
  // .ts path is not a registrable entry on this host and must not be moved.
2790
2794
  config.plugin = removePantheonPluginReferences(config.plugin)
2791
2795
  if (!Array.isArray(config.plugins)) config.plugins = []
2796
+ // Preflight: a Pantheon-owned registration whose target directory is
2797
+ // missing means the previous install was invalidated (the npx cache
2798
+ // recycles `_npx/<hash>` dirs — field evidence: a registered copy
2799
+ // vanished and the host silently dropped the plugin, so the whole tool
2800
+ // surface disappeared until the next init). Name the cause loudly
2801
+ // before the re-registration below fixes it.
2802
+ for (const ref of Array.isArray(config.plugins) ? config.plugins : []) {
2803
+ const refPath = typeof ref === 'string' ? ref : ref?.package
2804
+ if (typeof refPath !== 'string' || managedPluginIdentity(refPath) === null) continue
2805
+ const absolute = isAbsolute(refPath) ? refPath : resolve(target, refPath)
2806
+ if (existsSync(absolute)) continue
2807
+ const staleNpx = refPath.includes('_npx/')
2808
+ warning(
2809
+ `Existing Pantheon registration points to ${refPath}, which no longer exists` +
2810
+ (staleNpx
2811
+ ? ' (the npx cache recycled that copy) — re-registering to the freshly installed tree'
2812
+ : ' — re-registering to the freshly installed tree'),
2813
+ )
2814
+ }
2815
+
2792
2816
  const migrated = []
2793
2817
  const blocked = []
2794
2818
  for (const plugin of config.plugin) {
@@ -3433,6 +3457,7 @@ async function installPass(
3433
3457
  configAdvisories,
3434
3458
  v2Capabilities: version === 'v2' ? v2Capabilities() : null,
3435
3459
  decisionModelActivation,
3460
+ decisionModelDeferredSetup,
3436
3461
  pluginOptions: v2PluginOptions,
3437
3462
  }
3438
3463
  : {
@@ -3440,6 +3465,7 @@ async function installPass(
3440
3465
  applied: true,
3441
3466
  reason: 'applied',
3442
3467
  decisionModelActivation,
3468
+ decisionModelDeferredSetup,
3443
3469
  target,
3444
3470
  runtimeEffects,
3445
3471
  openCodeVersion: version,
@@ -215,6 +215,23 @@ export function copyPluginFiles(
215
215
  else result.skipped++
216
216
  }
217
217
 
218
+ // CHANGELOG.md — the copy's one-time "What's new" window reads the release
219
+ // highlights for the running version from its own installed root. Best
220
+ // effort: a missing source simply means no window (the TUI fails open).
221
+ // src/plugins/tui → src/plugins → src → the package root, which ships
222
+ // CHANGELOG.md in its npm `files` allow-list.
223
+ const changelogSrc = join(srcDir, '..', '..', '..', 'CHANGELOG.md')
224
+ if (existsSync(changelogSrc)) {
225
+ const changelogStatus = writeIfChanged(
226
+ join(dstDir, 'CHANGELOG.md'),
227
+ readFileSync(changelogSrc, 'utf8'),
228
+ dryRun,
229
+ { recorder },
230
+ )
231
+ if (changelogStatus === 'created') result.created++
232
+ else result.skipped++
233
+ }
234
+
218
235
  return result
219
236
  }
220
237
 
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * jev-live-probe.mjs — operator-run live measurement for the Jev decision
4
+ * route (config-only route check + live scorecard).
5
+ *
6
+ * The ping resolves the configured route without contacting a provider. The
7
+ * scorecard talks to the HOST's decisions API through `opencode api` (the same
8
+ * route the plugin uses), so no credentials cross this script and each live
9
+ * call is billed to the user's configured route. Operator-run by design: the
10
+ * J2 scorecard is the consented live-model measurement; the offline harness
11
+ * measures plumbing only.
12
+ *
13
+ * Usage:
14
+ * node scripts/jev-live-probe.mjs --ping # config-only route resolution; no provider call
15
+ * node scripts/jev-live-probe.mjs --scorecard # N scenarios, dated scorecard
16
+ */
17
+
18
+ import { spawnSync } from 'node:child_process'
19
+ import { writeFileSync } from 'node:fs'
20
+ import { pathToFileURL } from 'node:url'
21
+ import {
22
+ DECISION_ROUTER_MODELS,
23
+ readUserDecisionRouterConfig,
24
+ } from './install/decision-router-config.mjs'
25
+
26
+ const HOST_TIMEOUT_MS = 30_000
27
+
28
+ /** Config provider IDs translated to the host's native Decisions provider IDs. */
29
+ export const HOST_PROVIDERS = Object.freeze({
30
+ 'typesafe-jev': 'typesafe-ai',
31
+ 'opencode-console-jev': 'opencode',
32
+ 'openrouter-jev': 'openrouter',
33
+ 'vercel-gateway-jev': 'vercel-ai-gateway',
34
+ 'cloudflare-workers-jev': 'cloudflare-workers-ai',
35
+ })
36
+
37
+ /** Live scenarios: state → the skill a correct picker would choose. */
38
+ const SCENARIOS = [
39
+ { state: 'Investigate why the payment webhook drops events under load', expect: 'apollo' },
40
+ { state: 'Plan the database migration for the new billing table', expect: 'athena' },
41
+ { state: 'Review the auth flow for security gaps before the release', expect: 'themis' },
42
+ { state: 'Implement the retry queue endpoint for the notifications service', expect: 'hermes' },
43
+ { state: 'Set up the CI pipeline for the new monorepo layout', expect: 'prometheus' },
44
+ { state: 'Audit the permissions matrix across all specialists', expect: 'themis' },
45
+ { state: 'Design the caching layer for the read-heavy dashboard', expect: 'athena' },
46
+ { state: 'none — greet the user and ask what they want', expect: 'none' },
47
+ // Zero-dispatch agents' domains (roster-reform evidence batch)
48
+ { state: 'Write the SQL indexes and stored procedures for the orders schema', expect: 'demeter' },
49
+ { state: 'Process the satellite imagery tiles and classify land use', expect: 'gaia' },
50
+ {
51
+ state: 'Integrate the new LLM provider SDK and wire the prompt templates',
52
+ expect: 'hephaestus',
53
+ },
54
+ { state: 'Migrate the open issues to the new milestone labels via the API', expect: 'iris' },
55
+ { state: 'Decide which stale session summaries are worth keeping', expect: 'mnemosyne' },
56
+ { state: 'Fuzz the input parser with malformed payloads to find crashes', expect: 'nyx' },
57
+ { state: 'Fix the typo that makes the CLI parse --verbose as the output path', expect: 'talos' },
58
+ { state: 'Polish the onboarding screen layout and micro-interactions', expect: 'aphrodite' },
59
+ ]
60
+
61
+ function callDecisions(modelRef, state) {
62
+ const payload = JSON.stringify({
63
+ model: modelRef,
64
+ input: [{ type: 'text', text: state }],
65
+ questions: [
66
+ {
67
+ type: 'choice',
68
+ name: 'pick',
69
+ instructions:
70
+ 'Pick the single best specialist for this task, or none. Required skills beat preferred ones; judge from the state alone.',
71
+ choices: [
72
+ { value: 'apollo', description: 'read-only investigation and research' },
73
+ { value: 'athena', description: 'planning and architecture' },
74
+ { value: 'themis', description: 'security, review and compliance gates' },
75
+ { value: 'hermes', description: 'backend implementation' },
76
+ { value: 'prometheus', description: 'infrastructure, CI and pipelines' },
77
+ { value: 'hephaestus', description: 'AI tooling and model integration' },
78
+ { value: 'demeter', description: 'databases and data layer' },
79
+ { value: 'gaia', description: 'remote sensing and geospatial' },
80
+ { value: 'iris', description: 'GitHub operations and automation' },
81
+ { value: 'aphrodite', description: 'UI and frontend craft' },
82
+ { value: 'mnemosyne', description: 'memory curation and recall' },
83
+ { value: 'nyx', description: 'chaos and adversarial testing' },
84
+ { value: 'talos', description: 'hotfix express lane - small direct fixes, no ceremony' },
85
+ { value: 'none', description: 'no specialist fits' },
86
+ ],
87
+ },
88
+ ],
89
+ })
90
+ const result = spawnSync(
91
+ 'opencode',
92
+ ['api', 'POST', '/api/experimental/generate/decisions', '-d', payload],
93
+ {
94
+ encoding: 'utf8',
95
+ timeout: HOST_TIMEOUT_MS,
96
+ },
97
+ )
98
+ if (result.status !== 0) {
99
+ return { ok: false, raw: (result.stderr || result.stdout || '').slice(0, 300) }
100
+ }
101
+ try {
102
+ return { ok: true, data: JSON.parse(result.stdout) }
103
+ } catch {
104
+ return { ok: false, raw: result.stdout.slice(0, 300) }
105
+ }
106
+ }
107
+
108
+ function answerChoice(data) {
109
+ const answers = data?.data?.answers ?? data?.answers
110
+ if (!Array.isArray(answers)) return null
111
+ const pick = answers.find((a) => a.name === 'pick')
112
+ return pick?.choice ?? null
113
+ }
114
+
115
+ /** Resolve the configured explicit route without probing the provider. */
116
+ export function resolveConfiguredRoute(config) {
117
+ if (!config?.enabled || config.selection?.mode !== 'explicit') {
118
+ throw new Error('the router must be enabled with an explicit selection')
119
+ }
120
+ const { provider, model } = config.selection
121
+ const hostProvider = HOST_PROVIDERS[provider]
122
+ if (
123
+ !Object.hasOwn(HOST_PROVIDERS, provider) ||
124
+ !DECISION_ROUTER_MODELS[provider]?.includes(model)
125
+ ) {
126
+ throw new Error(`unknown or unsupported selection: ${provider}/${model}`)
127
+ }
128
+ return { providerID: hostProvider, id: model }
129
+ }
130
+
131
+ /** Report the configured route only; deliberately makes no Decisions call. */
132
+ export function pingConfiguredRoute(config, { stdout = console.log } = {}) {
133
+ const modelRef = resolveConfiguredRoute(config)
134
+ stdout(`✅ configured route: ${modelRef.providerID}/${modelRef.id} (no live provider call)`)
135
+ return modelRef
136
+ }
137
+
138
+ function main(args = process.argv.slice(2)) {
139
+ if (args.includes('--ping')) {
140
+ try {
141
+ pingConfiguredRoute(readUserDecisionRouterConfig())
142
+ process.exit(0)
143
+ } catch (error) {
144
+ console.error(
145
+ `❌ route unresolved: ${error instanceof Error ? error.message : String(error)}`,
146
+ )
147
+ process.exit(1)
148
+ }
149
+ }
150
+
151
+ if (args.includes('--scorecard')) {
152
+ // Route from the user's decision-router config (explicit selection only).
153
+ let cfg
154
+ let modelRef
155
+ try {
156
+ cfg = readUserDecisionRouterConfig()
157
+ modelRef = resolveConfiguredRoute(cfg)
158
+ } catch (error) {
159
+ console.error(error instanceof Error ? error.message : String(error))
160
+ process.exit(1)
161
+ }
162
+
163
+ const rows = []
164
+ let totalCost = 0
165
+ for (const scenario of SCENARIOS) {
166
+ const r = callDecisions(modelRef, scenario.state)
167
+ if (!r.ok) {
168
+ rows.push({ state: scenario.state, expect: scenario.expect, got: `ERROR: ${r.raw}` })
169
+ continue
170
+ }
171
+ const cost = r.data?.cost ?? 0
172
+ totalCost += Number(cost) || 0
173
+ rows.push({ state: scenario.state, expect: scenario.expect, got: answerChoice(r.data), cost })
174
+ }
175
+
176
+ const date = new Date().toISOString().slice(0, 10)
177
+ const out = [
178
+ `# Live J2 scorecard — ${date}`,
179
+ '',
180
+ `Route: \`${modelRef.providerID}/${modelRef.id}\`. Operator-run via \`opencode api\``,
181
+ '(consented route, billed to the user). 12 scenarios; agreement between the',
182
+ 'live model and the expected pick is the metric — this measures the MODEL,',
183
+ 'unlike the offline harness that measures the plumbing.',
184
+ '',
185
+ '| state (truncated) | expect | live | cost |',
186
+ '| --- | --- | --- | --- |',
187
+ ...rows.map(
188
+ (r) =>
189
+ `| ${r.state.slice(0, 48)}${r.state.length > 48 ? '…' : ''} | ${r.expect} | ${r.got ?? '—'} | ${r.cost ?? '—'} |`,
190
+ ),
191
+ '',
192
+ `Total cost: $${totalCost.toFixed(6)}. Honest caveat: one run is a smoke`,
193
+ 'measurement, not a calibration — a claim about model quality needs',
194
+ 'repeated runs and a bigger scenario set.',
195
+ '',
196
+ ].join('\n')
197
+ const outPath = `bench/results/j2-live-scorecard-${date}.md`
198
+ writeFileSync(outPath, out)
199
+ console.log(`✅ live scorecard written: ${outPath} (total $${totalCost.toFixed(6)})`)
200
+ process.exit(0)
201
+ }
202
+
203
+ console.error('usage: node scripts/jev-live-probe.mjs --ping | --scorecard')
204
+ process.exit(1)
205
+ }
206
+
207
+ const invokedDirectly =
208
+ process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href
209
+
210
+ if (invokedDirectly) main()