pantheon-opencode 1.6.2-beta.9 → 1.6.2

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 (68) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +34 -60
  3. package/README.pt-BR.md +10 -12
  4. package/bin/pantheon-init.mjs +22 -32
  5. package/package.json +3 -3
  6. package/plugin.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/scripts/decision-router.mjs +41 -56
  9. package/scripts/install/decision-router-config.mjs +67 -1
  10. package/scripts/install/npx-cache-sweep.mjs +103 -0
  11. package/scripts/install/opencode.mjs +7 -7
  12. package/scripts/install/plugin.mjs +4 -3
  13. package/scripts/install/strings.mjs +4 -0
  14. package/scripts/release-gates.mjs +6 -82
  15. package/scripts/sync-tui.mjs +3 -3
  16. package/src/agents/zeus.md +4 -2
  17. package/src/pantheon/jev-decision-tool.ts +366 -114
  18. package/src/pantheon/jev-decisions.ts +11 -13
  19. package/src/pantheon/jev-escalation.ts +639 -0
  20. package/src/pantheon/jev-quality-score.ts +432 -0
  21. package/src/pantheon/jev-risk-gate.ts +479 -0
  22. package/src/pantheon/local-decision-prompt.ts +12 -18
  23. package/src/pantheon/v2-decision-telemetry.ts +14 -4
  24. package/src/pantheon/v2-native-decisions.ts +1 -1
  25. package/src/plugin-v2.ts +201 -24
  26. package/src/plugins/tui/dist/server-v2.d.ts +19 -11
  27. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
  28. package/src/plugins/tui/dist/server-v2.js +19 -789
  29. package/src/plugins/tui/dist/server-v2.js.map +1 -1
  30. package/src/plugins/tui/dist/tui-v2.d.ts +12 -331
  31. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  32. package/src/plugins/tui/dist/tui-v2.js +257 -5370
  33. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  34. package/src/plugins/tui/dist/tui.js +1 -1
  35. package/src/plugins/tui/package-lock.json +2 -2
  36. package/src/plugins/tui/package.json +1 -1
  37. package/src/plugins/tui/src/index-v2.tsx +213 -86
  38. package/src/plugins/tui/src/server-v2.ts +18 -982
  39. package/src/plugins/tui/tsconfig.typecheck.json +1 -6
  40. package/src/plugins/tui/tsdown.config.ts +1 -11
  41. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +0 -749
  42. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +0 -1
  43. package/src/plugins/tui/dist/quota-adapters.d.ts +0 -89
  44. package/src/plugins/tui/dist/quota-adapters.d.ts.map +0 -1
  45. package/src/plugins/tui/dist/quota-adapters.js +0 -1142
  46. package/src/plugins/tui/dist/quota-adapters.js.map +0 -1
  47. package/src/plugins/tui/dist/quota-cli.d.ts +0 -17
  48. package/src/plugins/tui/dist/quota-cli.d.ts.map +0 -1
  49. package/src/plugins/tui/dist/quota-cli.js +0 -184
  50. package/src/plugins/tui/dist/quota-cli.js.map +0 -1
  51. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js +0 -684
  52. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +0 -1
  53. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +0 -118
  54. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +0 -1
  55. package/src/plugins/tui/dist/usage-history-worker.js +0 -25
  56. package/src/plugins/tui/dist/usage-history-worker.js.map +0 -1
  57. package/src/plugins/tui/src/go-key-diagnostic-ui.ts +0 -100
  58. package/src/plugins/tui/src/go-key-diagnostic.ts +0 -125
  59. package/src/plugins/tui/src/quota-adapters.ts +0 -1598
  60. package/src/plugins/tui/src/quota-cli.ts +0 -237
  61. package/src/plugins/tui/src/quota-rpc.ts +0 -373
  62. package/src/plugins/tui/src/quota-v2-model.ts +0 -1032
  63. package/src/plugins/tui/src/quota-v2.tsx +0 -1238
  64. package/src/plugins/tui/src/usage-history-contract.ts +0 -217
  65. package/src/plugins/tui/src/usage-history-validation.ts +0 -104
  66. package/src/plugins/tui/src/usage-history-view.tsx +0 -236
  67. package/src/plugins/tui/src/usage-history-worker.ts +0 -25
  68. package/src/plugins/tui/src/usage-view-model.ts +0 -272
@@ -0,0 +1,103 @@
1
+ /**
2
+ * npx-cache-sweep.mjs — stale pantheon-opencode copy detection and removal.
3
+ *
4
+ * `npx pantheon-opencode` materializes a full package copy under
5
+ * `<npm-cache>/_npx/<hash>/node_modules/pantheon-opencode` and reuses it per
6
+ * spec+version. Old copies accumulate across versions (field evidence: a
7
+ * 1.6.1 copy next to the registered 1.6.2-beta.12 made `npx
8
+ * pantheon-opencode doctor` report the registered plugin as outdated), and
9
+ * nothing in npm removes them. This module finds and removes those copies —
10
+ * ONLY the `pantheon-opencode` subtree, never a whole `_npx/<hash>` entry,
11
+ * which may hold unrelated packages.
12
+ *
13
+ * After a successful init the registration in the user's opencode config
14
+ * points at the freshly installed copy, so every other copy is unreferenced:
15
+ * removing it only costs a re-download if that exact spec is invoked again.
16
+ */
17
+
18
+ import { execFile } from 'node:child_process'
19
+ import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs'
20
+ import { homedir } from 'node:os'
21
+ import { join, resolve } from 'node:path'
22
+ import { promisify } from 'node:util'
23
+
24
+ const execFileAsync = promisify(execFile)
25
+
26
+ const PACKAGE_DIR_NAME = 'pantheon-opencode'
27
+
28
+ /**
29
+ * Resolve the npm cache root that holds `_npx/`. Injection first (tests),
30
+ * then `npm config get cache` (portable across Linux/macOS/Windows), then the
31
+ * POSIX default. A resolvable cache root is never guaranteed: callers must
32
+ * treat a missing `_npx` as "nothing to do".
33
+ * @param {{ npmCache?: string }} [options]
34
+ * @returns {Promise<string>}
35
+ */
36
+ export async function resolveNpxCacheRoot({ npmCache } = {}) {
37
+ if (npmCache) return resolve(npmCache)
38
+ try {
39
+ const { stdout } = await execFileAsync('npm', ['config', 'get', 'cache'], { timeout: 15000 })
40
+ const value = String(stdout).trim()
41
+ if (value) return resolve(value)
42
+ } catch {
43
+ // npm missing or slow — the POSIX default covers the common case.
44
+ }
45
+ return join(homedir(), '.npm')
46
+ }
47
+
48
+ /** True when the directory looks like an installed pantheon-opencode copy. */
49
+ function isPantheonCopy(dir) {
50
+ return existsSync(join(dir, 'package.json'))
51
+ }
52
+
53
+ /**
54
+ * List every installed pantheon-opencode copy under the npm cache's `_npx/`.
55
+ * @param {{ cacheRoot?: string }} [options]
56
+ * @returns {Promise<Array<{ dir: string, version: string | null }>>}
57
+ */
58
+ export async function findPantheonNpxCacheCopies({ cacheRoot } = {}) {
59
+ const root = cacheRoot ?? (await resolveNpxCacheRoot())
60
+ const npxDir = join(root, '_npx')
61
+ if (!existsSync(npxDir)) return []
62
+ const copies = []
63
+ for (const entry of readdirSync(npxDir, { withFileTypes: true })) {
64
+ if (!entry.isDirectory()) continue
65
+ const dir = resolve(join(npxDir, entry.name, 'node_modules', PACKAGE_DIR_NAME))
66
+ if (!isPantheonCopy(dir)) continue
67
+ let version = null
68
+ try {
69
+ version = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).version ?? null
70
+ } catch {
71
+ // An unreadable package.json still marks a sweepable copy.
72
+ version = null
73
+ }
74
+ copies.push({ dir, version })
75
+ }
76
+ return copies
77
+ }
78
+
79
+ /**
80
+ * Remove every installed pantheon-opencode copy under `_npx/` except `keep`.
81
+ * `keep: null` is the defensive no-op: without an explicit survivor, nothing
82
+ * is removed.
83
+ * @param {{ keep?: string | null, cacheRoot?: string }} options
84
+ * @returns {Promise<{ removed: string[] }>}
85
+ */
86
+ export async function sweepStalePantheonNpxCaches({ keep = null, cacheRoot } = {}) {
87
+ const keepResolved = keep ? resolve(keep) : null
88
+ if (keepResolved === null) return { removed: [] }
89
+ const copies = await findPantheonNpxCacheCopies({ cacheRoot })
90
+ const removed = []
91
+ for (const copy of copies) {
92
+ if (copy.dir === keepResolved) continue
93
+ try {
94
+ rmSync(copy.dir, { recursive: true, force: true })
95
+ } catch {
96
+ // A copy that cannot be removed (locked by a running host) is left in
97
+ // place; the next init retries. Never rethrow into the install flow.
98
+ continue
99
+ }
100
+ if (!existsSync(copy.dir)) removed.push(copy.dir)
101
+ }
102
+ return { removed }
103
+ }
@@ -847,13 +847,13 @@ export function deduplicatePluginReferences(refs) {
847
847
  /**
848
848
  * Register the copied Pantheon TUI plugin in the V2 `plugins` list.
849
849
  *
850
- * The OpenCode 2.x host does not load server-side RPC from a local plugin
851
- * folder by free discovery — only entries listed in `config.plugins` are
852
- * loaded (sandbox probe evidence: no entry → `rpc.unavailable`; with the
853
- * entry the host logs `loading plugin id=…/pantheon-tui` and the V2-only
854
- * RPC (`pantheon.quota`) answers HTTP 200). Without this registration a
855
- * postinstall/sync that re-copies the payload after `init` can never restore
856
- * it, so the quota status stays "unavailable".
850
+ * The OpenCode 2.x host does not load a local plugin folder by free discovery —
851
+ * only entries listed in `config.plugins` are loaded (sandbox probe evidence:
852
+ * no entry → the copy's server half never attaches; with the entry the host
853
+ * logs `loading plugin id=…/pantheon-tui`). The server half is what wires the
854
+ * TUI runtime's reactive channel, so without this registration a
855
+ * postinstall/sync that re-copies the payload after `init` leaves a sidebar
856
+ * that mounts dead (the "mudo panel" symptom).
857
857
  *
858
858
  * Idempotent: the existing entry for the copy (same identity) is retained
859
859
  * and kept after the core plugin, while every other entry stays in place.
@@ -146,9 +146,10 @@ export function copyPluginFiles(
146
146
  packageJson.exports['./tui'] = packageJson.exports['./tui-v2']
147
147
  }
148
148
  // The OpenCode host resolves the plugin server through the `./server` export.
149
- // In the V2 copy it must point at the V2 server bundle so V2-only RPCs
150
- // (pantheon.quota) are registered; otherwise the host loads the V1 server
151
- // and the quota status stays "unavailable".
149
+ // In the V2 copy it must point at the V2 server entry so the host attaches
150
+ // the copy's V2 server half (the TUI reactive channel depends on it);
151
+ // otherwise the host loads the V1 server stub of the previous generation's
152
+ // payload.
152
153
  if (version === 'v2' && packageJson.exports?.['./server-v2']) {
153
154
  packageJson.exports['./server'] = packageJson.exports['./server-v2']
154
155
  }
@@ -51,6 +51,8 @@ const TABLE = {
51
51
  healthCheckExit: (seconds, status) =>
52
52
  `Health check finished in ${seconds}s and reported problems (exit ${status}); the installation itself completed`,
53
53
  installedTitle: (v) => `Pantheon OpenCode v${v} installed.`,
54
+ sweptNpxCaches: (n) =>
55
+ `Removed ${n} stale pantheon-opencode npx cache cop${n === 1 ? 'y' : 'ies'} (old-version residue).`,
54
56
  nextSteps: 'Next steps:',
55
57
  nextVerify: '1. Verify installation:\n npx pantheon-opencode doctor',
56
58
  nextLaunch: '2. Launch OpenCode',
@@ -149,6 +151,8 @@ const TABLE = {
149
151
  healthCheckExit: (seconds, status) =>
150
152
  `Verificação de saúde concluída em ${seconds}s e reportou problemas (exit ${status}); a instalação em si foi concluída`,
151
153
  installedTitle: (v) => `Pantheon OpenCode v${v} instalado.`,
154
+ sweptNpxCaches: (n) =>
155
+ `Removida${n === 1 ? '' : 's'} ${n} cópia${n === 1 ? '' : 's'} velha${n === 1 ? '' : 's'} de pantheon-opencode do cache npx.`,
152
156
  nextSteps: 'Próximos passos:',
153
157
  nextVerify: '1. Verifique a instalação:\n npx pantheon-opencode doctor',
154
158
  nextLaunch: '2. Abra o OpenCode',
@@ -40,9 +40,7 @@
40
40
  import { spawnSync } from 'node:child_process'
41
41
  import { createHash } from 'node:crypto'
42
42
  import {
43
- accessSync,
44
43
  existsSync,
45
- constants as fsConstants,
46
44
  mkdirSync,
47
45
  readdirSync,
48
46
  readFileSync,
@@ -56,7 +54,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url'
56
54
 
57
55
  const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
58
56
 
59
- const GATE_NAMES = ['tests', 'host', 'install', 'package', 'changelog', 'metadata']
57
+ const GATE_NAMES = ['host', 'install', 'package', 'changelog', 'metadata']
60
58
 
61
59
  /** Support is family-level: these are the families this release supports. */
62
60
  export const SUPPORTED_FAMILIES = Object.freeze(['1.19.x', '2.x'])
@@ -66,14 +64,13 @@ export const KNOWN_BROKEN_HOSTS = Object.freeze(['2.0.22'])
66
64
  const UNSUPPORTED_HOSTS = new Set(KNOWN_BROKEN_HOSTS)
67
65
 
68
66
  /**
69
- * The measured hosts at the time of freezing. Rows are evidence, not the
70
- * boundary of support: `PANTHEON_RELEASE_MATRIX` overrides them when a release
71
- * needs to exercise a different host.
67
+ * Boundary testing: the oldest supported 2.x line member and the newest.
68
+ * Middle hosts add little for a beta patch (host APIs move monotonically);
69
+ * a release that wants the full measured set overrides this via
70
+ * `PANTHEON_RELEASE_MATRIX` (JSON array, same row shape).
72
71
  */
73
72
  const DEFAULT_MATRIX = [
74
73
  { host: '2.0.29', line: '2.x', kind: 'sandbox-v2' },
75
- { host: '2.0.30', line: '2.x', kind: 'sandbox-v2' },
76
- { host: '2.1.0', line: '2.x', kind: 'sandbox-v2' },
77
74
  { host: '2.1.3', line: '2.x', kind: 'sandbox-v2' },
78
75
  ]
79
76
 
@@ -242,78 +239,6 @@ function assertCandidateSha(options) {
242
239
  }
243
240
  return sha
244
241
  }
245
-
246
- // ── Gate (a): tests ──────────────────────────────────────────────────────────
247
-
248
- /**
249
- * The Python interpreter used by gate (a).
250
- *
251
- * The suite imports `fastmcp`/`mcp` at collection time, so it only means
252
- * anything when run against the exact pins in `src/mcp/requirements-mcp.txt`.
253
- * `PANTHEON_PYTHON` (the same variable `scripts/doctor.mjs` honours) points at
254
- * the isolated venv prepared from those pins. When it is set, a missing or
255
- * non-executable path is a hard failure: falling back to the ambient `python3`
256
- * is what produced environment-only collection errors instead of a real
257
- * verdict. Only an unset variable keeps the developer default.
258
- */
259
- function gatePython() {
260
- const configured = String(process.env.PANTHEON_PYTHON ?? '').trim()
261
- if (!configured) return 'python3'
262
- const resolved = resolve(configured)
263
- if (!existsSync(resolved)) {
264
- throw new Error(`PANTHEON_PYTHON does not exist: ${resolved}`)
265
- }
266
- try {
267
- accessSync(resolved, fsConstants.X_OK)
268
- } catch {
269
- throw new Error(`PANTHEON_PYTHON is not executable: ${resolved}`)
270
- }
271
- return resolved
272
- }
273
-
274
- function testsGate() {
275
- const python = gatePython()
276
- const pythonVersion = run('python-version', python, ['--version'], { echo: false }).output.trim()
277
- const checks = [
278
- run('python-tests-coverage', python, [
279
- '-m',
280
- 'coverage',
281
- 'run',
282
- '--branch',
283
- '--source=src/mcp',
284
- '-m',
285
- 'pytest',
286
- '-q',
287
- '--tb=short',
288
- ]),
289
- run('python-coverage-threshold', python, ['-m', 'coverage', 'report', '--fail-under=80']),
290
- run('node-tests', 'npm', ['run', 'test:node']),
291
- run('typescript-tests', 'npm', ['run', 'test:ts']),
292
- run('plugin-v2-line-coverage', 'npm', ['run', 'coverage:plugin-v2']),
293
- // Mandatory here and optional in the developer loop: the release gate may
294
- // not publish without the real-install tier.
295
- run('install-tier', 'npm', ['run', 'test:install'], {
296
- env: { PANTHEON_RUN_INSTALL_TESTS: '1' },
297
- }),
298
- ]
299
- return {
300
- checks,
301
- details: {
302
- pythonInterpreter: python,
303
- pythonVersion,
304
- pinnedRequirements: ['src/mcp/requirements-mcp.txt', 'src/mcp/requirements-vision.txt'],
305
- requiredCoverage: [
306
- 'python: src/mcp branch coverage >= 80% (coverage report --fail-under=80)',
307
- 'typescript: src/plugin-v2.ts line coverage (coverage:plugin-v2)',
308
- ],
309
- notPass: [
310
- 'Node coverage (`npm run coverage`) is report-only and is NOT a PASS signal.',
311
- 'TypeScript under src/ outside the plugin-v2 measurement is unmeasured, NOT PASS.',
312
- ],
313
- },
314
- }
315
- }
316
-
317
242
  // ── Gate (b): host compatibility ─────────────────────────────────────────────
318
243
 
319
244
  function matrixFromEnv() {
@@ -326,7 +251,7 @@ function matrixFromEnv() {
326
251
  throw new Error(`PANTHEON_RELEASE_MATRIX is not valid JSON: ${error.message}`)
327
252
  }
328
253
  if (!Array.isArray(parsed)) {
329
- throw new Error('PANTHEON_RELEASE_MATRIX must be a JSON array')
254
+ throw new Error(`PANTHEON_RELEASE_MATRIX must be a JSON array`)
330
255
  }
331
256
  return parsed
332
257
  }
@@ -614,7 +539,6 @@ function metadataGate(options) {
614
539
  }
615
540
 
616
541
  const GATES = {
617
- tests: testsGate,
618
542
  host: hostGate,
619
543
  install: installGate,
620
544
  package: packageGate,
@@ -95,9 +95,9 @@ export function copyPluginFiles(srcDir, dstDir, version) {
95
95
  }
96
96
  // Mirror of scripts/install/plugin.mjs: the OpenCode host resolves the
97
97
  // plugin server through the `./server` export. In the V2 copy it must
98
- // point at the V2 server bundle so V2-only RPCs (pantheon.quota) are
99
- // registered; otherwise the host loads the V1 server and the quota
100
- // status stays "unavailable".
98
+ // point at the V2 server entry so the host attaches the copy's V2 server
99
+ // half (the TUI reactive channel depends on it); otherwise the host loads
100
+ // the V1 server stub of the previous generation's payload.
101
101
  if (version === 'v2' && packageJson.exports?.['./server-v2']) {
102
102
  packageJson.exports['./server'] = packageJson.exports['./server-v2']
103
103
  }
@@ -48,8 +48,10 @@ skills:
48
48
  - When a task would benefit from stacking several skills, prefer one `pantheon_jev_decide` with `mode: "skills"`: it offers your locally prefiltered shortlist (or the installed skill pool) and returns what is worth stacking. Load only the chosen skills.
49
49
  - Construct the final Brief locally and use native `subagent` unchanged; native dispatch is always the final routing action. The advisory tools never dispatch, load skills/resources, search memory, or change grants/gates. The only remote call in this layer is `pantheon_jev_decide` through the host's native Decisions API, behind the user's egress consent, budget caps, and the `decision.egress` permission gate; a missing gate is a refusal, never a bypass.
50
50
  This local-only guarantee applies only to decision routing, not all product egress.
51
- Separately documented quota (including manual `/quota-go-check`) and Vision
52
- integrations retain their own external-request behavior.
51
+ The Vision integration retains its own external-request behavior. Provider
52
+ quota/usage UI is delegated to the community plugin documented in
53
+ `docs/tui-v2-quota-providers.md` — it is not a Pantheon surface and never a
54
+ Pantheon egress path.
53
55
 
54
56
  ## Missing capability? Find a skill before inventing one
55
57