pantheon-opencode 1.7.0 → 2.0.0-beta.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 (173) hide show
  1. package/AGENTS.global.md +2 -2
  2. package/AGENTS.md +3 -3
  3. package/CHANGELOG.md +85 -59
  4. package/README.md +74 -48
  5. package/README.pt-BR.md +19 -19
  6. package/bin/pantheon-init.mjs +11 -48
  7. package/package.json +9 -13
  8. package/plugin.json +2 -2
  9. package/pyproject.toml +1 -1
  10. package/scripts/build-agents-md.mjs +7 -6
  11. package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
  12. package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
  13. package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
  14. package/scripts/decision-router.mjs +2 -2
  15. package/scripts/docs-media.mjs +1 -1
  16. package/scripts/doctor.mjs +225 -136
  17. package/scripts/install/behavior-overrides.bundle.mjs +123 -0
  18. package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
  19. package/scripts/install/config-migration.mjs +60 -253
  20. package/scripts/install/file-inventory.mjs +6 -4
  21. package/scripts/install/interactive.mjs +1 -1
  22. package/scripts/install/opencode-state.mjs +13 -12
  23. package/scripts/install/opencode-version.mjs +97 -162
  24. package/scripts/install/opencode.mjs +271 -428
  25. package/scripts/install/plan.mjs +1 -9
  26. package/scripts/install/plugin.mjs +19 -35
  27. package/scripts/install/shared.mjs +40 -1
  28. package/scripts/package-evidence.mjs +1 -4
  29. package/scripts/probe-pantheon-cost.mjs +1 -1
  30. package/scripts/reconcile.mjs +5 -7
  31. package/scripts/release-gates.mjs +22 -61
  32. package/scripts/setup-v2-config.mjs +10 -8
  33. package/scripts/setup.mjs +12 -22
  34. package/scripts/sync-tui.mjs +9 -17
  35. package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
  36. package/scripts/update-skills-lock.mjs +24 -12
  37. package/scripts/update.mjs +17 -1
  38. package/scripts/validate-routing.mjs +79 -4
  39. package/scripts/validate-sandbox-install.mjs +3 -3
  40. package/skills-lock.json +25 -8
  41. package/src/agents/zeus.md +1 -0
  42. package/src/pantheon/behavior-overrides.ts +191 -0
  43. package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
  44. package/src/pantheon/cost-command.ts +1 -1
  45. package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
  46. package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
  47. package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
  48. package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
  49. package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
  50. package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
  51. package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
  52. package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
  53. package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
  54. package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
  55. package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
  56. package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
  57. package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
  58. package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
  59. package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
  60. package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
  61. package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
  62. package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
  63. package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
  64. package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
  65. package/src/pantheon/goal-store.ts +7 -0
  66. package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
  67. package/src/pantheon/jev-decision-tool.ts +3 -3
  68. package/src/pantheon/jev-decisions.ts +12 -6
  69. package/src/pantheon/jev-escalation.ts +6 -6
  70. package/src/pantheon/jev-quality-score.ts +2 -2
  71. package/src/pantheon/jev-rank-verify.ts +2 -2
  72. package/src/pantheon/jev-risk-gate.ts +4 -4
  73. package/src/pantheon/local-decision-agents.ts +1 -1
  74. package/src/pantheon/local-decision-router.ts +1 -1
  75. package/src/pantheon/local-decision-tool.ts +2 -2
  76. package/src/pantheon/local-orchestration.ts +1 -1
  77. package/src/pantheon/model-command.ts +1 -1
  78. package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
  79. package/src/pantheon/pantheon-decision-catalog.ts +12 -0
  80. package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
  81. package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
  82. package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
  83. package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
  84. package/src/pantheon/update-notifier.ts +101 -0
  85. package/src/pantheon/vision-local.ts +12 -3
  86. package/src/pantheon/vision.ts +120 -2
  87. package/src/{plugin-v2 → plugin}/index.ts +7 -7
  88. package/src/plugin.ts +2870 -500
  89. package/src/plugins/hook-runner.ts +3 -3
  90. package/src/plugins/tui/dist/server.d.ts +23 -9
  91. package/src/plugins/tui/dist/server.d.ts.map +1 -1
  92. package/src/plugins/tui/dist/server.js +25 -12
  93. package/src/plugins/tui/dist/server.js.map +1 -1
  94. package/src/plugins/tui/dist/tui.d.ts +1023 -494
  95. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  96. package/src/plugins/tui/dist/tui.js +5612 -2086
  97. package/src/plugins/tui/dist/tui.js.map +1 -1
  98. package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
  99. package/src/plugins/tui/package-lock.json +2 -42
  100. package/src/plugins/tui/package.json +4 -10
  101. package/src/plugins/tui/src/cost-data.ts +1 -1
  102. package/src/plugins/tui/src/decision-router-state.ts +242 -0
  103. package/src/plugins/tui/src/doctor-state.ts +198 -0
  104. package/src/plugins/tui/src/index.tsx +4222 -2822
  105. package/src/plugins/tui/src/j1-gate-status.ts +85 -0
  106. package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
  107. package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
  108. package/src/plugins/tui/src/preset-state.ts +143 -0
  109. package/src/plugins/tui/src/server.ts +23 -10
  110. package/src/plugins/tui/src/update-notice.ts +90 -0
  111. package/src/plugins/tui/src/update-status.ts +98 -0
  112. package/src/plugins/tui/tsconfig.typecheck.json +9 -2
  113. package/src/plugins/tui/tsdown.config.ts +3 -5
  114. package/src/plugins/tui/tui.ts +1 -2
  115. package/src/routing.yml +36 -0
  116. package/src/skills/README.md +16 -1
  117. package/src/skills/artifact-management/SKILL.md +10 -67
  118. package/src/skills/artifact-management/references/artifact-templates.md +71 -0
  119. package/src/skills/auto-continue/SKILL.md +10 -0
  120. package/src/skills/code-review-checklist/SKILL.md +11 -44
  121. package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
  122. package/src/skills/instruction-forge/SKILL.md +57 -0
  123. package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
  124. package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
  125. package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
  126. package/src/skills/memory-bank/SKILL.md +11 -90
  127. package/src/skills/memory-bank/references/anti-patterns.md +33 -0
  128. package/src/skills/memory-bank/references/product-adoption.md +19 -0
  129. package/src/skills/memory-bank/references/storage-model.md +21 -0
  130. package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
  131. package/src/skills/reflect/SKILL.md +1 -0
  132. package/src/skills/session-goal/SKILL.md +7 -54
  133. package/src/skills/session-goal/references/goal-format.md +26 -0
  134. package/src/skills/session-goal/references/session-reuse.md +44 -0
  135. package/src/skills/tdd-with-agents/SKILL.md +11 -101
  136. package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
  137. package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
  138. package/src/skills/visual-review-pipeline/SKILL.md +11 -120
  139. package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
  140. package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
  141. package/scripts/hooks/log-session-start.sh +0 -48
  142. package/scripts/hooks/validate-post-conditions.sh +0 -21
  143. package/scripts/hooks/validate-talos-scope.sh +0 -50
  144. package/scripts/hooks/validate-tool-safety.sh +0 -49
  145. package/src/pantheon/goal-loop.ts +0 -314
  146. package/src/pantheon/idle-continuation.ts +0 -52
  147. package/src/pantheon/todo-preserve.ts +0 -301
  148. package/src/pantheon/tool-ceiling.ts +0 -159
  149. package/src/pantheon/v2-bridge.ts +0 -153
  150. package/src/plugin-v2.ts +0 -2954
  151. package/src/plugins/pantheon-hooks.ts +0 -1433
  152. package/src/plugins/tui/dist/server-v2.d.ts +0 -30
  153. package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
  154. package/src/plugins/tui/dist/server-v2.js +0 -33
  155. package/src/plugins/tui/dist/server-v2.js.map +0 -1
  156. package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
  157. package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
  158. package/src/plugins/tui/dist/tui-v2.js +0 -4597
  159. package/src/plugins/tui/dist/tui-v2.js.map +0 -1
  160. package/src/plugins/tui/src/index-v2.tsx +0 -4496
  161. package/src/plugins/tui/src/server-v2.ts +0 -28
  162. package/src/plugins/tui/tui-v2.ts +0 -2
  163. /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
  164. /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
  165. /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
  166. /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
  167. /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
  168. /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
  169. /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
  170. /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
  171. /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
  172. /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
  173. /package/src/plugins/tui/src/{opencode-v2.d.ts → opencode.d.ts} +0 -0
@@ -2,7 +2,7 @@
2
2
  * opencode-state.mjs — where an OpenCode host keeps its state, resolved once.
3
3
  *
4
4
  * WHY THIS MODULE EXISTS: the installer used to PRINT a hardcoded claim about
5
- * state isolation (`~/.local/share/opencode/opencode-v2.db`, "open service port
5
+ * state isolation (`~/.local/share/opencode/opencode.db`, "open service port
6
6
  * 49375"). Nothing in this package ever set `OPENCODE_DB`, no installer created
7
7
  * that file, and no code bound that port — it was a sentence about a
8
8
  * configuration that never existed outside a sandbox. A notice is a statement
@@ -13,15 +13,15 @@
13
13
  * and from the credential-store lookup in scripts/vision-status.mjs):
14
14
  *
15
15
  * 1. `OPENCODE_DB` — an explicit file override (what a SANDBOX uses; it is
16
- * also the only reason an `opencode-v2.db` name ever appears anywhere);
16
+ * also the only reason an `opencode.db` name ever appears anywhere);
17
17
  * 2. otherwise the XDG default `<data dir>/opencode.db`, where `<data dir>` is
18
18
  * `$XDG_DATA_HOME/opencode` when `XDG_DATA_HOME` is set, else
19
19
  * `~/.local/share/opencode`.
20
20
  *
21
21
  * There is deliberately NO per-generation filename and no per-generation port:
22
- * both host generations read the same store, and the schema — not the filename
23
- * — is what distinguishes their ledgers. `PANTHEON_COST_DB` is NOT part of this
24
- * rule: it redirects the cost REPORT only, never the host's store.
22
+ * one host generation reads one store, and the schema — not the filename — is
23
+ * what distinguishes ledgers. `PANTHEON_COST_DB` is NOT part of this rule: it
24
+ * redirects the cost REPORT only, never the host's store.
25
25
  *
26
26
  * Plain Node ESM on purpose: this is consumed by the installer (no TypeScript)
27
27
  * and by tests, and the equivalent TypeScript resolver is not importable there.
@@ -70,11 +70,12 @@ export function resolveOpenCodeStatePath(env = process.env, home = homedir()) {
70
70
  }
71
71
 
72
72
  /**
73
- * One honest sentence about state sharing for the generation being installed.
73
+ * One honest sentence about state sharing for the install being performed.
74
74
  *
75
- * Both generations read one store, so "isolated" is never the right word. The
76
- * sentence names the resolved path, says where that path came from, and states
77
- * that Pantheon binds no service port (there is nothing to name).
75
+ * The host reads one store, so "isolated" is never the right word. The sentence
76
+ * names the resolved path, says where that path came from, and states that
77
+ * Pantheon binds no service port (there is nothing to name) and writes no
78
+ * per-generation store file.
78
79
  *
79
80
  * @param {NodeJS.ProcessEnv} [env]
80
81
  * @param {string} [home]
@@ -84,8 +85,8 @@ export function describeSharedState(env = process.env, home = homedir()) {
84
85
  const { path: dbPath, source } = resolveOpenCodeStatePath(env, home)
85
86
  const origin = source === 'OPENCODE_DB' ? 'set by OPENCODE_DB' : 'the host default'
86
87
  return (
87
- `State is shared, not isolated per generation: OpenCode V1 and V2 read the same ` +
88
- `store (${dbPath}; ${origin}). Pantheon configures no separate database and binds ` +
89
- 'no service port.'
88
+ `State is shared, not isolated: OpenCode reads one store ` +
89
+ `(${dbPath}; ${origin}). Pantheon configures no separate database, writes no ` +
90
+ 'per-generation store file and binds no service port.'
90
91
  )
91
92
  }
@@ -1,56 +1,36 @@
1
- /** OpenCode major-version selection shared by the CLI and installer. */
1
+ /** OpenCode host gate shared by the CLI and installer. */
2
2
 
3
3
  import { spawnSync } from 'node:child_process'
4
4
  import { mkdtempSync, rmSync } from 'node:fs'
5
5
  import { tmpdir } from 'node:os'
6
6
  import { join } from 'node:path'
7
7
 
8
- import { warning } from './cli-ui.mjs'
9
-
10
- const VALID_VERSIONS = new Set(['v1', 'v2', 'auto'])
11
-
12
- /** @param {string[]} args @returns {'v1'|'v2'|'auto'|null} */
13
- export function parseOpenCodeVersion(args) {
14
- // Match init's selector precedence: modern --version wins over the legacy
15
- // alias regardless of argument order. The package-level --version command is
16
- // handled before this init selector parser is called.
17
- const inlineModern = args.find((arg) => arg.startsWith('--version='))
18
- if (inlineModern !== undefined) {
19
- const value = inlineModern.slice('--version='.length)
20
- if (!value) throw missingVersionValue('--version')
21
- return normalize(value)
22
- }
23
- const modernIndex = args.indexOf('--version')
24
- if (modernIndex >= 0) {
25
- const modern = args[modernIndex + 1]
26
- if (modern === undefined || modern.startsWith('-')) throw missingVersionValue('--version')
27
- return normalize(modern)
28
- }
29
- const inlineLegacy = args.find((arg) => arg.startsWith('--opencode-version='))
30
- if (inlineLegacy !== undefined) {
31
- const value = inlineLegacy.slice('--opencode-version='.length)
32
- if (!value) throw missingVersionValue('--opencode-version')
33
- return normalize(value)
34
- }
35
- const legacyIndex = args.indexOf('--opencode-version')
36
- if (legacyIndex < 0) return null
37
- const legacy = args[legacyIndex + 1]
38
- if (legacy === undefined || legacy.startsWith('-')) {
39
- throw missingVersionValue('--opencode-version')
40
- }
41
- return normalize(legacy)
42
- }
8
+ /**
9
+ * The only host generation this installer writes. Pantheon registers the plugin
10
+ * surface through the plural `plugins` key with directory entries, which an
11
+ * OpenCode 1.x host ignores entirely — so a host the probe cannot confirm as
12
+ * 2.x is refused before any write, never served a config it cannot load.
13
+ */
14
+ const SUPPORTED_GENERATION = 'v2'
43
15
 
44
- function missingVersionValue(flag) {
45
- return new Error(`${flag} requires a value: v1, v2, or auto.`)
16
+ /**
17
+ * The hard refusal for a confirmed 1.x host. Exported so the CLI, setup and
18
+ * tests quote exactly one sentence for the same fact.
19
+ * @param {number|string} major
20
+ * @returns {string}
21
+ */
22
+ export function unsupportedHostMessage(major = 1) {
23
+ return (
24
+ `Pantheon 2.0 requires OpenCode 2.x; this host is ${major}.x — uninstall Pantheon 1.x ` +
25
+ 'or upgrade the host'
26
+ )
46
27
  }
47
28
 
48
- function normalize(value) {
49
- if (!VALID_VERSIONS.has(value)) {
50
- throw new Error(`Invalid OpenCode version "${value}" — expected v1, v2, or auto`)
51
- }
52
- return value
53
- }
29
+ /**
30
+ * How to make the gate deterministic when no host binary can be probed. Shared
31
+ * by every unreadable-host refusal so the escape hatch is stated exactly once.
32
+ */
33
+ const PIN_HINT = 'pin OPENCODE_VERSION=v2 to skip the probe'
54
34
 
55
35
  /**
56
36
  * Budget for `opencode --version` during a real install. A hung host binary
@@ -59,10 +39,9 @@ function normalize(value) {
59
39
  const HOST_PROBE_TIMEOUT_MS = 5000
60
40
 
61
41
  /**
62
- * Budget for the same probe during a DRY RUN. A preview is bounded: the dry
63
- * run now probes the host (it used to skip the probe and assume V1, which made
64
- * the plan describe a different generation than the apply), so its latency
65
- * must stay small even on a host that hangs.
42
+ * Budget for the same probe during a DRY RUN. A preview is bounded: the dry run
43
+ * probes the host like the apply does (plan and apply must make the SAME
44
+ * decision), so its latency must stay small even on a host that hangs.
66
45
  */
67
46
  export const DRY_RUN_PROBE_TIMEOUT_MS = 2000
68
47
 
@@ -79,9 +58,8 @@ export const DRY_RUN_PROBE_TIMEOUT_MS = 2000
79
58
  * would otherwise let them disagree — the exact divergence the shared probe
80
59
  * exists to prevent.
81
60
  *
82
- * stderr is captured alongside stdout. A host that prints its version banner to
83
- * stderr and nothing to stdout would otherwise soft-fail to V1 — a wrong
84
- * answer whose cause has nothing to do with the host's generation.
61
+ * stderr is captured alongside stdout so a host that prints its version banner
62
+ * to stderr is still readable.
85
63
  * @param {string} binary
86
64
  * @param {number} [timeoutMs=HOST_PROBE_TIMEOUT_MS]
87
65
  * @returns {{stdout: string, stderr: string}}
@@ -127,17 +105,14 @@ const VERSION_TOKEN = /(?<![\d.])v?(\d+)\.(\d+)/gi
127
105
  // KNOWN LIMIT, deliberately not worked around: this anchor is a NAME anchor, so
128
106
  // any sentence that puts "opencode" in front of a version-shaped token reads as
129
107
  // a host banner. A probe whose output is `warning: deprecated, upgrade to
130
- // opencode 2.0.0` resolves to v2 in silence. Closing it would need a rule that
131
- // rejects a mid-sentence "opencode X.Y.Z" — but "node v22.1.0 (opencode 1.18.33)"
132
- // is exactly such a mid-sentence anchor, and it is the reason the anchor exists:
133
- // dropping it lets a leading runtime token flip a genuine 1.x host to v2. The
134
- // defect class is not the nag wording (a phrase blacklist closes these three
135
- // strings and none of the others), it is name-adjacency. `probeHostVersion`
136
- // spawns whatever OPENCODE_BIN names and accepts any exit-0 binary, so a wrapper
137
- // or shim printing a bare path is indistinguishable from the real host by
138
- // construction. An operator whose `opencode` is a wrapper gets v2 silently; the
139
- // documented remedy is `--opencode-version`, not a heuristic that would trade
140
- // this silent misclassification for a different one.
108
+ // opencode 2.0.0` reads as the host naming itself 2.x. Closing it would need a
109
+ // rule that rejects a mid-sentence "opencode X.Y.Z" — but "node v22.1.0
110
+ // (opencode 2.0.22)" is exactly such a mid-sentence anchor, and it is the
111
+ // reason the anchor exists: dropping it lets a leading runtime token pose as
112
+ // the host's version. `probeHostVersion` spawns whatever OPENCODE_BIN names and
113
+ // accepts any exit-0 binary, so a wrapper or shim printing a bare path is
114
+ // indistinguishable from the real host by construction; an unknown output is
115
+ // handled by a loud refusal below, never by a silent guess.
141
116
  const ANCHOR_NAME = 'opencode'
142
117
 
143
118
  // How far back the anchor scan looks. `[\s:=]*` is unbounded, so no finite
@@ -146,8 +121,8 @@ const ANCHOR_NAME = 'opencode'
146
121
  // 5s spawn timeout (that timeout guards the spawn, not the parse). The budget is
147
122
  // sized from the anchor itself (ANCHOR_NAME plus separators), not guessed: the
148
123
  // longest separator run in any realistic banner is ~10 bytes. Past the budget an
149
- // anchor is simply missed, and that degrades to the loud consensus path — it can
150
- // turn a quiet resolution into a warned one, never into a different resolution.
124
+ // anchor is simply missed, and that degrades to the loud refusal path — it can
125
+ // turn a quiet resolution into a refusal, never into a different resolution.
151
126
  const ANCHOR_SEPARATOR_BUDGET = 56
152
127
  const ANCHOR_WINDOW_BYTES = ANCHOR_NAME.length + ANCHOR_SEPARATOR_BUDGET
153
128
  const TOOL_NAME_BEFORE = new RegExp(`${ANCHOR_NAME}[\\s:=]*$`, 'i')
@@ -155,8 +130,8 @@ const TOOL_NAME_BEFORE = new RegExp(`${ANCHOR_NAME}[\\s:=]*$`, 'i')
155
130
  // A major at or above this is a calendar year, not a release number:
156
131
  // "built 2026.10.04" is version-SHAPED but describes no release. So is major 0,
157
132
  // which is a prerelease placeholder rather than a release — and major 0 read as
158
- // "older than 2" is the original defect (V1 config on a 2.x host) recurring for
159
- // a 2.x beta. Which brings the subtlety this gate turns on:
133
+ // "older than 2" would be the original defect (a 2.x beta refused as a 1.x
134
+ // host). Which brings the subtlety this gate turns on:
160
135
  //
161
136
  // * UNANCHORED and implausible -> noise. A date or a build counter says
162
137
  // nothing about the host's generation, so dropping it is a resolution, not a
@@ -166,9 +141,7 @@ const TOOL_NAME_BEFORE = new RegExp(`${ANCHOR_NAME}[\\s:=]*$`, 'i')
166
141
  // and answer in silence — "opencode 100.0.0 (node v22.1.0)" would resolve to
167
142
  // v2 with no warning. So a refused anchored major is reported, not dropped.
168
143
  //
169
- // Both cases fail LOUD rather than silently, which is the safe direction, and
170
- // the loud-v1 claim holds for the anchored case without depending on the dropped
171
- // token being the only candidate.
144
+ // Both cases stay LOUD rather than silent, which is the safe direction.
172
145
  const FIRST_PLAUSIBLE_MAJOR = 100
173
146
 
174
147
  /** Is `major` a value we refuse to read as a release number? */
@@ -190,9 +163,9 @@ function anchorWindow(source, index) {
190
163
  *
191
164
  * Anchoring on the tool name — rather than taking the first or the last
192
165
  * version-shaped token — is what makes this robust on both sides. First-match
193
- * anchoring lets a leading `node v22` outrank the tool's own version and flips
194
- * a 1.x host to v2; last-match anchoring lets a trailing `built 2026.10.04`
195
- * outrank it and does the same. A name-anchored token defeats both.
166
+ * anchoring lets a leading `node v22` outrank the tool's own version; last-match
167
+ * anchoring lets a trailing `built 2026.10.04` outrank it. A name-anchored token
168
+ * defeats both.
196
169
  *
197
170
  * @param {string} text raw `--version` output from one stream
198
171
  * @returns {{major: number}|{ambiguous: number[]}|{unreadable: number}|null}
@@ -230,77 +203,42 @@ function parseHostMajor(text) {
230
203
  }
231
204
 
232
205
  /**
233
- * Resolve the target OpenCode generation.
234
- *
235
- * `auto` precedence — the order is load-bearing, do not "simplify" it:
236
- * 1. explicit `--opencode-version` argument
237
- * 2. OPENCODE_VERSION env var
238
- * 3. an `opencode2` binary basename
239
- * 4. a `--version` probe of the host binary (major >= 2 => v2)
240
- * 5. soft-fail to v1 with one visible warning
241
- *
242
- * Step 3 stays ahead of step 4 because of WHAT THE TWO STEPS ARE. Step 3 is an
243
- * explicit operator hint: naming a binary `opencode2` and pointing
244
- * `OPENCODE_BIN` at it is a deliberate act, and it is the only one of the two
245
- * the operator gets to state. Step 4 is a heuristic read of a free-form string
246
- * that some program chose to print. A hint must not be overruled by a
247
- * heuristic — and the argument holds no matter what any given build prints.
248
- *
249
- * Historical note, NOT an observation of this host: an OpenCode 2.x prerelease
250
- * once printed "0.0.0-next-17444", which any "major >= 2 => v2" probe reads as
251
- * major 0 and would resolve to v1. That string does not come from the host —
252
- * it survives only in this repo's comments and test fixtures. It is also why a
253
- * major-0 anchored token now takes the loud path rather than resolving to v1 in
254
- * silence (see FIRST_PLAUSIBLE_MAJOR). Verified 2026-10-04: `opencode2` here is
255
- * a 47-byte shim that execs `opencode`, and `opencode2 --version` prints
256
- * "opencode v2.0.22" on stdout. So for a real `opencode2` today both the
257
- * basename and the probe return v2 and the ordering is harmless rather than
258
- * load-bearing; what it still defends is the general case above.
259
- *
260
- * Step 5 falls back to v1 rather than v2 on purpose. Writing a plural
261
- * `plugins` directory entry on an unknown 1.x host would be ignored there,
262
- * losing the plugin on that host AND dropping the V1-only surface — strictly
263
- * worse than the V1 default, which at least still works. The fallback is only
264
- * tolerable because it warns; a silent v1 is what made this a silent failure.
206
+ * Resolve the target OpenCode generation. There is exactly one, and the probe
207
+ * must CONFIRM the host is 2.x before any write: there is no generation to fall
208
+ * back to, so an unreadable host is a refusal, not a warning.
265
209
  *
266
- * Every fallback also reports through `onFallback`, so a caller (the dry-run
267
- * preview) can tell the user its plan ASSUMED V1 instead of detecting it. A
268
- * probe that succeeds never reports: only an unknown host does.
210
+ * Precedence:
211
+ * 1. `OPENCODE_VERSION=v2` env pin — skips the probe entirely. It exists so
212
+ * CI, sandboxes and operators can make the answer deterministic without a
213
+ * runnable host binary. `v1` (or any other value) is refused.
214
+ * 2. an `opencode2` binary basename — an explicit operator hint
215
+ * (`OPENCODE_BIN` pointing at it is a deliberate act) and always 2.x.
216
+ * 3. a `--version` probe of the host binary:
217
+ * - major >= 2 -> v2, quiet.
218
+ * - major === 1 -> HARD ERROR before any write: a 1.x host is a fact,
219
+ * not a detection gap, and the registry this installer writes would be
220
+ * silently ignored there.
221
+ * - probe failed / unreadable / ambiguous / unparseable -> HARD ERROR
222
+ * before any write. The installer cannot confirm the one premise it
223
+ * writes for, so it refuses loudly instead of guessing; the env pin is
224
+ * the deterministic escape hatch for hosts that cannot be probed.
269
225
  *
270
- * A dry run probes too. It used to pass `skipProbe` and assume V1, which made
271
- * `init --dry-run` describe the V1 plan on a V2 host (a target `tui.json` and a
272
- * removed `index.ts`) while the apply wrote `index.ts` and no `tui.json`. The
273
- * probe is `opencode --version` run inside a throwaway state directory (see
274
- * `probeHostVersion`), and `probeTimeoutMs` bounds it.
275
- *
276
- * @param {'v1'|'v2'|'auto'|null|undefined} requested
277
226
  * @param {{env?: Record<string, string|undefined>, binary?: string,
278
227
  * probe?: () => string|{stdout?: string, stderr?: string},
279
- * probeTimeoutMs?: number,
280
- * warn?: (message: string) => void,
281
- * onFallback?: (reason: 'probe-failed'|'unparseable'|'unreadable'|'ambiguous') => void}} [options]
282
- * @returns {'v1'|'v2'}
228
+ * probeTimeoutMs?: number}} [options]
229
+ * @returns {'v2'}
283
230
  */
284
- export function resolveOpenCodeVersion(requested = 'auto', options = {}) {
285
- if (!VALID_VERSIONS.has(requested)) {
286
- throw new Error(`Invalid OpenCode version "${requested}" — expected v1, v2, or auto`)
287
- }
288
- if (requested === 'v1' || requested === 'v2') return requested
231
+ export function resolveOpenCodeVersion(options = {}) {
289
232
  const env = options.env ?? process.env
290
- if (env.OPENCODE_VERSION === 'v1' || env.OPENCODE_VERSION === 'v2') {
291
- return env.OPENCODE_VERSION
233
+ if (env.OPENCODE_VERSION !== undefined) {
234
+ if (env.OPENCODE_VERSION === SUPPORTED_GENERATION) return SUPPORTED_GENERATION
235
+ if (env.OPENCODE_VERSION === 'v1') throw new Error(unsupportedHostMessage(1))
236
+ throw new Error(
237
+ `Invalid OPENCODE_VERSION "${env.OPENCODE_VERSION}" — only "${SUPPORTED_GENERATION}" can be pinned`,
238
+ )
292
239
  }
293
240
  const binary = options.binary ?? env.OPENCODE_BIN ?? ''
294
- const warn = options.warn ?? warning
295
- if (/(?:^|[\\/])opencode2(?:\.exe)?$/i.test(binary)) return 'v2'
296
-
297
- // One exit for every "we could not read the host" path: the warning and the
298
- // caller notification can never drift apart.
299
- const fallbackToV1 = (reason, message) => {
300
- warn(message)
301
- options.onFallback?.(reason)
302
- return 'v1'
303
- }
241
+ if (/(?:^|[\\/])opencode2(?:\.exe)?$/i.test(binary)) return SUPPORTED_GENERATION
304
242
 
305
243
  const probe =
306
244
  options.probe ?? (() => probeHostVersion(binary || 'opencode', options.probeTimeoutMs))
@@ -308,11 +246,10 @@ export function resolveOpenCodeVersion(requested = 'auto', options = {}) {
308
246
  try {
309
247
  raw = probe()
310
248
  } catch (err) {
311
- return fallbackToV1(
312
- 'probe-failed',
313
- `Could not read the host OpenCode version (${err.message}). Falling back to the V1 ` +
314
- `configuration; if this host is OpenCode 2.x re-run with --opencode-version v2 ` +
315
- `(or v1 to force V1).`,
249
+ throw new Error(
250
+ `Could not probe the host OpenCode version (${err.message}). ` +
251
+ `Pantheon 2.0 requires OpenCode 2.x — install OpenCode 2.x and put it on PATH, ` +
252
+ `or ${PIN_HINT}.`,
316
253
  )
317
254
  }
318
255
 
@@ -329,41 +266,39 @@ export function resolveOpenCodeVersion(requested = 'auto', options = {}) {
329
266
  const parsed = parseHostMajor(streams.stdout) ?? parseHostMajor(streams.stderr)
330
267
 
331
268
  if (parsed === null) {
332
- // A probe that RAN but whose output we cannot read is just as dangerous as
333
- // one that failed: silently landing on V1 is the bug this gate exists to
334
- // fix, so it gets the same visible warning.
335
- return fallbackToV1(
336
- 'unparseable',
269
+ // A probe that RAN but printed nothing version-shaped is not evidence of a
270
+ // 2.x host, so the gate refuses rather than guess.
271
+ throw new Error(
337
272
  `Could not parse the host OpenCode version from ` +
338
273
  `${JSON.stringify(`${streams.stdout}${streams.stderr}`.trim())}. ` +
339
- `Falling back to the V1 configuration; if this host is OpenCode 2.x re-run with ` +
340
- `--opencode-version v2 (or v1 to force V1).`,
274
+ `Pantheon 2.0 requires OpenCode 2.x — upgrade the host, or ${PIN_HINT}.`,
341
275
  )
342
276
  }
343
277
  if (parsed.unreadable !== undefined) {
344
278
  // The host named itself and reported a major this gate refuses to read (0,
345
- // or a calendar year). That is not noise like a trailing build date — it is
346
- // the host's own version, so letting a surviving runtime token decide would
347
- // be a silent guess. Say what we saw and fall back loudly.
348
- return fallbackToV1(
349
- 'unreadable',
279
+ // or a calendar year). It is an unreadable self-report — not a confirmed
280
+ // 2.x host — so the gate refuses.
281
+ throw new Error(
350
282
  `The host OpenCode version output reports major ${parsed.unreadable}, which is ` +
351
- `not a release number this gate can interpret (a prerelease placeholder or a ` +
352
- `calendar year). Falling back to the V1 configuration; pass --opencode-version v2 ` +
353
- `if this host is OpenCode 2.x (or v1 to force V1).`,
283
+ 'not a release number this gate can interpret (a prerelease placeholder or a ' +
284
+ `calendar year). Pantheon 2.0 requires OpenCode 2.x — upgrade the host, or ${PIN_HINT}.`,
354
285
  )
355
286
  }
356
287
  if (parsed.ambiguous) {
357
288
  // Version-shaped tokens that disagree, with no tool name to break the tie.
358
- // The reviewer accepted "wrong but loud" here; guessing silently is the
359
- // defect this branch exists to prevent.
360
- return fallbackToV1(
361
- 'ambiguous',
289
+ // Guessing silently is the defect this gate exists to prevent, and there is
290
+ // no generation to fall back to, so the contradiction is a refusal.
291
+ throw new Error(
362
292
  `The host OpenCode version output has contradictory versions ` +
363
293
  `(${parsed.ambiguous.map((major) => `major ${major}`).join(', ')}) and does not say ` +
364
- `which is the host's. Falling back to the V1 configuration; pass ` +
365
- `--opencode-version v2 if this host is OpenCode 2.x (or v1 to force V1).`,
294
+ `which is the host's. Pantheon 2.0 requires OpenCode 2.x — or ${PIN_HINT}.`,
366
295
  )
367
296
  }
368
- return parsed.major >= 2 ? 'v2' : 'v1'
297
+ if (parsed.major === 1) {
298
+ // A CONFIRMED 1.x host is a fact, not a detection gap: the plugin registry
299
+ // this installer writes would be silently ignored there, losing the plugin
300
+ // AND writing a config the host cannot use. Refuse before any write.
301
+ throw new Error(unsupportedHostMessage(parsed.major))
302
+ }
303
+ return SUPPORTED_GENERATION
369
304
  }