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.
- package/AGENTS.global.md +2 -2
- package/AGENTS.md +3 -3
- package/CHANGELOG.md +85 -59
- package/README.md +74 -48
- package/README.pt-BR.md +19 -19
- package/bin/pantheon-init.mjs +11 -48
- package/package.json +9 -13
- package/plugin.json +2 -2
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +7 -6
- package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
- package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
- package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
- package/scripts/decision-router.mjs +2 -2
- package/scripts/docs-media.mjs +1 -1
- package/scripts/doctor.mjs +225 -136
- package/scripts/install/behavior-overrides.bundle.mjs +123 -0
- package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
- package/scripts/install/config-migration.mjs +60 -253
- package/scripts/install/file-inventory.mjs +6 -4
- package/scripts/install/interactive.mjs +1 -1
- package/scripts/install/opencode-state.mjs +13 -12
- package/scripts/install/opencode-version.mjs +97 -162
- package/scripts/install/opencode.mjs +271 -428
- package/scripts/install/plan.mjs +1 -9
- package/scripts/install/plugin.mjs +19 -35
- package/scripts/install/shared.mjs +40 -1
- package/scripts/package-evidence.mjs +1 -4
- package/scripts/probe-pantheon-cost.mjs +1 -1
- package/scripts/reconcile.mjs +5 -7
- package/scripts/release-gates.mjs +22 -61
- package/scripts/setup-v2-config.mjs +10 -8
- package/scripts/setup.mjs +12 -22
- package/scripts/sync-tui.mjs +9 -17
- package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
- package/scripts/update-skills-lock.mjs +24 -12
- package/scripts/update.mjs +17 -1
- package/scripts/validate-routing.mjs +79 -4
- package/scripts/validate-sandbox-install.mjs +3 -3
- package/skills-lock.json +25 -8
- package/src/agents/zeus.md +1 -0
- package/src/pantheon/behavior-overrides.ts +191 -0
- package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
- package/src/pantheon/cost-command.ts +1 -1
- package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
- package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
- package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
- package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
- package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
- package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
- package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
- package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
- package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
- package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
- package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
- package/src/pantheon/goal-store.ts +7 -0
- package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
- package/src/pantheon/jev-decision-tool.ts +3 -3
- package/src/pantheon/jev-decisions.ts +12 -6
- package/src/pantheon/jev-escalation.ts +6 -6
- package/src/pantheon/jev-quality-score.ts +2 -2
- package/src/pantheon/jev-rank-verify.ts +2 -2
- package/src/pantheon/jev-risk-gate.ts +4 -4
- package/src/pantheon/local-decision-agents.ts +1 -1
- package/src/pantheon/local-decision-router.ts +1 -1
- package/src/pantheon/local-decision-tool.ts +2 -2
- package/src/pantheon/local-orchestration.ts +1 -1
- package/src/pantheon/model-command.ts +1 -1
- package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
- package/src/pantheon/pantheon-decision-catalog.ts +12 -0
- package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
- package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
- package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
- package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
- package/src/pantheon/update-notifier.ts +101 -0
- package/src/pantheon/vision-local.ts +12 -3
- package/src/pantheon/vision.ts +120 -2
- package/src/{plugin-v2 → plugin}/index.ts +7 -7
- package/src/plugin.ts +2870 -500
- package/src/plugins/hook-runner.ts +3 -3
- package/src/plugins/tui/dist/server.d.ts +23 -9
- package/src/plugins/tui/dist/server.d.ts.map +1 -1
- package/src/plugins/tui/dist/server.js +25 -12
- package/src/plugins/tui/dist/server.js.map +1 -1
- package/src/plugins/tui/dist/tui.d.ts +1023 -494
- package/src/plugins/tui/dist/tui.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui.js +5612 -2086
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
- package/src/plugins/tui/package-lock.json +2 -42
- package/src/plugins/tui/package.json +4 -10
- package/src/plugins/tui/src/cost-data.ts +1 -1
- package/src/plugins/tui/src/decision-router-state.ts +242 -0
- package/src/plugins/tui/src/doctor-state.ts +198 -0
- package/src/plugins/tui/src/index.tsx +4222 -2822
- package/src/plugins/tui/src/j1-gate-status.ts +85 -0
- package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
- package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
- package/src/plugins/tui/src/preset-state.ts +143 -0
- package/src/plugins/tui/src/server.ts +23 -10
- package/src/plugins/tui/src/update-notice.ts +90 -0
- package/src/plugins/tui/src/update-status.ts +98 -0
- package/src/plugins/tui/tsconfig.typecheck.json +9 -2
- package/src/plugins/tui/tsdown.config.ts +3 -5
- package/src/plugins/tui/tui.ts +1 -2
- package/src/routing.yml +36 -0
- package/src/skills/README.md +16 -1
- package/src/skills/artifact-management/SKILL.md +10 -67
- package/src/skills/artifact-management/references/artifact-templates.md +71 -0
- package/src/skills/auto-continue/SKILL.md +10 -0
- package/src/skills/code-review-checklist/SKILL.md +11 -44
- package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
- package/src/skills/instruction-forge/SKILL.md +57 -0
- package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
- package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
- package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
- package/src/skills/memory-bank/SKILL.md +11 -90
- package/src/skills/memory-bank/references/anti-patterns.md +33 -0
- package/src/skills/memory-bank/references/product-adoption.md +19 -0
- package/src/skills/memory-bank/references/storage-model.md +21 -0
- package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
- package/src/skills/reflect/SKILL.md +1 -0
- package/src/skills/session-goal/SKILL.md +7 -54
- package/src/skills/session-goal/references/goal-format.md +26 -0
- package/src/skills/session-goal/references/session-reuse.md +44 -0
- package/src/skills/tdd-with-agents/SKILL.md +11 -101
- package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
- package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
- package/src/skills/visual-review-pipeline/SKILL.md +11 -120
- package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
- package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
- package/scripts/hooks/log-session-start.sh +0 -48
- package/scripts/hooks/validate-post-conditions.sh +0 -21
- package/scripts/hooks/validate-talos-scope.sh +0 -50
- package/scripts/hooks/validate-tool-safety.sh +0 -49
- package/src/pantheon/goal-loop.ts +0 -314
- package/src/pantheon/idle-continuation.ts +0 -52
- package/src/pantheon/todo-preserve.ts +0 -301
- package/src/pantheon/tool-ceiling.ts +0 -159
- package/src/pantheon/v2-bridge.ts +0 -153
- package/src/plugin-v2.ts +0 -2954
- package/src/plugins/pantheon-hooks.ts +0 -1433
- package/src/plugins/tui/dist/server-v2.d.ts +0 -30
- package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
- package/src/plugins/tui/dist/server-v2.js +0 -33
- package/src/plugins/tui/dist/server-v2.js.map +0 -1
- package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
- package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
- package/src/plugins/tui/dist/tui-v2.js +0 -4597
- package/src/plugins/tui/dist/tui-v2.js.map +0 -1
- package/src/plugins/tui/src/index-v2.tsx +0 -4496
- package/src/plugins/tui/src/server-v2.ts +0 -28
- package/src/plugins/tui/tui-v2.ts +0 -2
- /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
- /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
- /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
- /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
- /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
- /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
- /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
- /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
- /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
- /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
- /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
|
|
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
|
|
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
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
|
73
|
+
* One honest sentence about state sharing for the install being performed.
|
|
74
74
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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
|
|
88
|
-
`
|
|
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
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
*
|
|
64
|
-
*
|
|
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
|
|
83
|
-
*
|
|
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`
|
|
131
|
-
// rejects a mid-sentence "opencode X.Y.Z" — but "node v22.1.0
|
|
132
|
-
// is exactly such a mid-sentence anchor, and it is the
|
|
133
|
-
// dropping it lets a leading runtime token
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
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
|
|
150
|
-
// turn a quiet resolution into a
|
|
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"
|
|
159
|
-
//
|
|
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
|
|
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
|
|
194
|
-
*
|
|
195
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
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
|
-
*
|
|
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(
|
|
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
|
|
291
|
-
|
|
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
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
`
|
|
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
|
|
333
|
-
//
|
|
334
|
-
|
|
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
|
-
`
|
|
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).
|
|
346
|
-
//
|
|
347
|
-
|
|
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
|
-
|
|
352
|
-
`calendar year).
|
|
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
|
-
//
|
|
359
|
-
//
|
|
360
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
}
|