pantheon-opencode 1.6.1 → 1.6.2-beta.10
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 +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +179 -0
- package/README.md +268 -20
- package/README.pt-BR.md +34 -11
- package/bin/pantheon-init.mjs +301 -32
- package/package.json +13 -4
- package/plugin.json +1 -1
- package/prompts/README.md +58 -0
- package/prompts/debug-issue.prompt.md +46 -0
- package/prompts/dynamic/agora-generated.txt +38 -0
- package/prompts/dynamic/orchestrate-generated.txt +51 -0
- package/prompts/focus.prompt.md +42 -0
- package/prompts/implement-feature.prompt.md +39 -0
- package/prompts/optimize-database.prompt.md +58 -0
- package/prompts/orchestrate-with-zeus.prompt.md +441 -0
- package/prompts/plan-architecture.prompt.md +59 -0
- package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
- package/prompts/quick-plan-large-feature.prompt.md +197 -0
- package/prompts/semantic-summarize.md +50 -0
- package/prompts/sketch.prompt.md +91 -0
- package/prompts/subtask.prompt.md +131 -0
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +1 -1
- package/scripts/decision-router-budget.mjs +780 -0
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +758 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/doctor.mjs +213 -45
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/component-selection.mjs +9 -4
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +560 -0
- package/scripts/install/health-check.mjs +20 -11
- package/scripts/install/interactive.mjs +103 -14
- package/scripts/install/interrupt.mjs +4 -3
- package/scripts/install/mcp-permissions.mjs +164 -0
- package/scripts/install/migrate.mjs +123 -72
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +411 -184
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plan.mjs +8 -1
- package/scripts/install/plugin.mjs +18 -1
- package/scripts/install/state.mjs +12 -0
- package/scripts/install/strings.mjs +22 -0
- package/scripts/install/v2-capabilities.mjs +5 -6
- package/scripts/install/venv.mjs +34 -17
- package/scripts/mcp_resources.py +11 -9
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/release-notes.mjs +30 -7
- package/scripts/restore.mjs +22 -10
- package/scripts/sandbox-env.sh +174 -0
- package/scripts/setup-v2-config.mjs +1703 -0
- package/scripts/setup.mjs +415 -0
- package/scripts/sync-tui.mjs +9 -1
- package/scripts/test-opencode-v2-sandbox.sh +448 -157
- package/scripts/update-skills-lock.mjs +30 -0
- package/scripts/versioning.mjs +41 -5
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +11 -3
- package/src/agents/apollo.md +6 -0
- package/src/agents/athena.md +7 -1
- package/src/agents/demeter.md +6 -2
- package/src/agents/gaia.md +5 -0
- package/src/agents/hephaestus.md +7 -2
- package/src/agents/hermes.md +14 -13
- package/src/agents/iris.md +6 -2
- package/src/agents/mnemosyne.md +21 -50
- package/src/agents/nyx.md +6 -2
- package/src/agents/prometheus.md +5 -1
- package/src/agents/talos.md +10 -1
- package/src/agents/themis.md +5 -1
- package/src/agents/zeus.md +61 -65
- package/src/instructions/agent-return-format.instructions.md +1 -1
- package/src/instructions/memory-protocol.instructions.md +3 -3
- package/src/instructions/test-economy.instructions.md +6 -6
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/mcp/pantheon_vision.py +37 -36
- package/src/pantheon/cost-command.ts +30 -133
- package/src/pantheon/jev-decision-tool.ts +347 -0
- package/src/pantheon/jev-decisions.ts +625 -0
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1046 -0
- package/src/pantheon/local-decision-egress-gate.ts +144 -0
- package/src/pantheon/local-decision-prompt.ts +256 -0
- package/src/pantheon/local-decision-provider-matrix.ts +44 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -0
- package/src/pantheon/local-decision-turn.ts +101 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/model-pricing.ts +1 -536
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-hook-engine.ts +307 -0
- package/src/pantheon/v2-native-decisions.ts +365 -0
- package/src/pantheon/v2-shell-hooks.ts +66 -2
- package/src/pantheon/v2-tools.ts +38 -15
- package/src/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +43 -10
- package/src/plugin-v2.ts +449 -79
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
- package/src/plugins/tui/dist/server-v2.d.ts +22 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +26 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +54 -51
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +762 -529
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/index-v2.ts +3 -6
- package/src/plugins/tui/package-lock.json +17 -2
- package/src/plugins/tui/package.json +6 -3
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/index-v2.tsx +360 -242
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/server-v2.ts +21 -0
- package/src/plugins/tui/src/sidebar-width.ts +129 -0
- package/src/plugins/tui/tsconfig.typecheck.json +1 -1
- package/src/plugins/tui/tsdown.config.ts +34 -5
- package/src/routing.yml +72 -13
- package/src/skills/README.md +4 -0
- package/src/skills/agent-coordination/SKILL.md +0 -3
- package/src/skills/artifact-management/SKILL.md +0 -3
- package/src/skills/auto-continue/SKILL.md +0 -3
- package/src/skills/code-review-checklist/SKILL.md +0 -3
- package/src/skills/context-compression/SKILL.md +0 -3
- package/src/skills/memory-bank/SKILL.md +6 -28
- package/src/skills/session-goal/SKILL.md +0 -3
- package/src/skills/simplify/SKILL.md +5 -4
- package/src/skills/tdd-with-agents/SKILL.md +0 -3
- package/src/skills/visual-review-pipeline/SKILL.md +0 -1
- package/src/pantheon/memory-context.ts +0 -1017
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
7
|
+
import * as clack from '@clack/prompts'
|
|
8
|
+
import { parseOpenCodeVersion, resolveOpenCodeVersion } from './install/opencode-version.mjs'
|
|
9
|
+
import { planArtifactDigest } from './install/plan-artifact.mjs'
|
|
10
|
+
import {
|
|
11
|
+
applyConfigChanges,
|
|
12
|
+
prepareV2Config,
|
|
13
|
+
resolveGlobalConfigDirectory,
|
|
14
|
+
verifyConfigPreconditions,
|
|
15
|
+
} from './setup-v2-config.mjs'
|
|
16
|
+
|
|
17
|
+
const INIT_CLI = fileURLToPath(new URL('../bin/pantheon-init.mjs', import.meta.url))
|
|
18
|
+
|
|
19
|
+
function writeOutput(output, text) {
|
|
20
|
+
if (typeof output.write === 'function') output.write(text)
|
|
21
|
+
else output.log?.(text.trimEnd())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isHeadless(args, env, interactive) {
|
|
25
|
+
return (
|
|
26
|
+
!interactive ||
|
|
27
|
+
args.includes('--headless') ||
|
|
28
|
+
env.CI === 'true' ||
|
|
29
|
+
env.CI === '1' ||
|
|
30
|
+
env.GITHUB_ACTIONS === 'true'
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function passthroughArgs(args) {
|
|
35
|
+
const omitWithValue = new Set(['--save-plan', '--apply-plan', '--version', '--opencode-version'])
|
|
36
|
+
const result = []
|
|
37
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
38
|
+
const arg = args[index]
|
|
39
|
+
if (omitWithValue.has(arg)) {
|
|
40
|
+
index += 1
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
if (
|
|
44
|
+
['--yes', '-y', '--dry-run', '--json', '--headless', '--interactive'].includes(arg) ||
|
|
45
|
+
arg.startsWith('--save-plan=') ||
|
|
46
|
+
arg.startsWith('--apply-plan=') ||
|
|
47
|
+
arg.startsWith('--version=') ||
|
|
48
|
+
arg.startsWith('--opencode-version=')
|
|
49
|
+
) {
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
result.push(arg)
|
|
53
|
+
}
|
|
54
|
+
return result
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function summarizeInitPreview(stdout) {
|
|
58
|
+
let plan
|
|
59
|
+
try {
|
|
60
|
+
plan = JSON.parse(stdout)
|
|
61
|
+
} catch {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
if (plan?.status !== 'planned' || !plan.totals || typeof plan.totals !== 'object') return null
|
|
65
|
+
const actions = ['create', 'update', 'remove', 'unchanged', 'conflict']
|
|
66
|
+
const totals = Object.fromEntries(
|
|
67
|
+
actions.map((action) => [
|
|
68
|
+
action,
|
|
69
|
+
Number.isSafeInteger(plan.totals[action]) ? plan.totals[action] : 0,
|
|
70
|
+
]),
|
|
71
|
+
)
|
|
72
|
+
const reportedOperationCount = Object.values(totals).reduce((sum, count) => sum + count, 0)
|
|
73
|
+
const files = plan.files ?? (reportedOperationCount === 0 ? [] : null)
|
|
74
|
+
if (
|
|
75
|
+
!Array.isArray(files) ||
|
|
76
|
+
files.length !== reportedOperationCount ||
|
|
77
|
+
files.some(
|
|
78
|
+
(file) => !['create', 'update', 'remove', 'unchanged', 'conflict'].includes(file?.action),
|
|
79
|
+
)
|
|
80
|
+
) {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
!plan.setup_plan ||
|
|
85
|
+
!Array.isArray(plan.setup_plan.operations) ||
|
|
86
|
+
!/^[a-f0-9]{64}$/.test(plan.setup_plan_digest ?? '') ||
|
|
87
|
+
planArtifactDigest(plan.setup_plan) !== plan.setup_plan_digest ||
|
|
88
|
+
plan.setup_plan.operations.length !== files.length ||
|
|
89
|
+
plan.setup_plan.operations.some(
|
|
90
|
+
(operation, index) => operation.action !== files[index].action,
|
|
91
|
+
) ||
|
|
92
|
+
!Array.isArray(plan.mcp_servers)
|
|
93
|
+
) {
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
const operations = files.flatMap((file) => {
|
|
97
|
+
const action = file.action
|
|
98
|
+
if (!['create', 'update', 'remove', 'conflict'].includes(action)) return []
|
|
99
|
+
return [{ action, path: safeOperationPath(file.path) ?? '[redacted path]' }]
|
|
100
|
+
})
|
|
101
|
+
return {
|
|
102
|
+
totals,
|
|
103
|
+
operations,
|
|
104
|
+
setupPlan: plan.setup_plan,
|
|
105
|
+
setupPlanDigest: plan.setup_plan_digest,
|
|
106
|
+
mcpServers: plan.mcp_servers,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function planComparisonView(plan) {
|
|
111
|
+
return {
|
|
112
|
+
package: plan.package,
|
|
113
|
+
target: plan.target,
|
|
114
|
+
options: plan.options,
|
|
115
|
+
operations: plan.operations,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function plansMatchAfterConfigApply(reviewed, current, prepared) {
|
|
120
|
+
if (!reviewed || !current) return false
|
|
121
|
+
const expected = structuredClone(reviewed)
|
|
122
|
+
const approvedConfig = prepared.changes?.find(
|
|
123
|
+
(change) =>
|
|
124
|
+
path.resolve(change.path) === path.resolve(path.join(prepared.configDir, 'opencode.json')),
|
|
125
|
+
)
|
|
126
|
+
if (approvedConfig) {
|
|
127
|
+
const priorOperation = expected.operations.find(
|
|
128
|
+
(operation) => path.resolve(operation.path) === path.resolve(approvedConfig.path),
|
|
129
|
+
)
|
|
130
|
+
const currentOperation = current.operations.find(
|
|
131
|
+
(operation) => path.resolve(operation.path) === path.resolve(approvedConfig.path),
|
|
132
|
+
)
|
|
133
|
+
if (priorOperation || currentOperation) {
|
|
134
|
+
if (!priorOperation || !currentOperation) return false
|
|
135
|
+
priorOperation.before = currentOperation.before
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return isDeepStrictEqual(planComparisonView(expected), planComparisonView(current))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function safeOperationPath(value) {
|
|
142
|
+
if (
|
|
143
|
+
typeof value !== 'string' ||
|
|
144
|
+
value.length === 0 ||
|
|
145
|
+
value.includes('\\') ||
|
|
146
|
+
path.isAbsolute(value) ||
|
|
147
|
+
path.win32.isAbsolute(value)
|
|
148
|
+
) {
|
|
149
|
+
return null
|
|
150
|
+
}
|
|
151
|
+
const parts = value.split('/')
|
|
152
|
+
if (
|
|
153
|
+
parts.some((part) => !part || part === '.' || part === '..' || !/^[A-Za-z0-9_.-]+$/.test(part))
|
|
154
|
+
) {
|
|
155
|
+
return null
|
|
156
|
+
}
|
|
157
|
+
return parts.join('/')
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Review and apply the opt-in V2 migration before allowing init to write. */
|
|
161
|
+
export async function runSetup({
|
|
162
|
+
args = process.argv.slice(2),
|
|
163
|
+
env = process.env,
|
|
164
|
+
cwd = process.cwd(),
|
|
165
|
+
home = os.homedir(),
|
|
166
|
+
interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
167
|
+
runInit = async (initArgs, initEnv = env, approvedPlan = null) =>
|
|
168
|
+
spawnSync(process.execPath, [INIT_CLI, ...initArgs], {
|
|
169
|
+
cwd,
|
|
170
|
+
env: initEnv,
|
|
171
|
+
...(approvedPlan === null
|
|
172
|
+
? { stdio: 'inherit' }
|
|
173
|
+
: { input: JSON.stringify(approvedPlan), stdio: ['pipe', 'inherit', 'inherit'] }),
|
|
174
|
+
}),
|
|
175
|
+
prepare = prepareV2Config,
|
|
176
|
+
resolveVersion = resolveOpenCodeVersion,
|
|
177
|
+
applyConfig = applyConfigChanges,
|
|
178
|
+
confirmInit = async () =>
|
|
179
|
+
clack.confirm({
|
|
180
|
+
message:
|
|
181
|
+
'Authorize the reviewed config changes and installer plan? This will write config and managed files.',
|
|
182
|
+
initialValue: false,
|
|
183
|
+
}),
|
|
184
|
+
previewInit = async (initArgs, initEnv = env, configPreview = null) =>
|
|
185
|
+
spawnSync(process.execPath, [INIT_CLI, ...initArgs], {
|
|
186
|
+
cwd,
|
|
187
|
+
env: initEnv,
|
|
188
|
+
encoding: 'utf8',
|
|
189
|
+
input: configPreview === null ? undefined : configPreview,
|
|
190
|
+
stdio: configPreview === null ? ['ignore', 'pipe', 'pipe'] : ['pipe', 'pipe', 'pipe'],
|
|
191
|
+
}),
|
|
192
|
+
output = console,
|
|
193
|
+
} = {}) {
|
|
194
|
+
if (args.includes('--help')) {
|
|
195
|
+
const helpResult = await runInit(['init', ...args], env)
|
|
196
|
+
return helpResult?.status ?? helpResult?.code ?? 0
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let detectionFallback = false
|
|
200
|
+
const warnings = []
|
|
201
|
+
let generation
|
|
202
|
+
try {
|
|
203
|
+
const requested = parseOpenCodeVersion(args) ?? 'auto'
|
|
204
|
+
generation = resolveVersion(requested, {
|
|
205
|
+
env,
|
|
206
|
+
warn: () =>
|
|
207
|
+
warnings.push('OpenCode version detection was inconclusive; pass --version v1 or v2.'),
|
|
208
|
+
onFallback: () => {
|
|
209
|
+
detectionFallback = true
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
} catch (error) {
|
|
213
|
+
writeOutput(
|
|
214
|
+
output,
|
|
215
|
+
`${error instanceof Error ? error.message : 'OpenCode generation selection is invalid; pass --version v1, v2, or auto.'}\n`,
|
|
216
|
+
)
|
|
217
|
+
return 1
|
|
218
|
+
}
|
|
219
|
+
for (const warning of warnings) writeOutput(output, `${warning}\n`)
|
|
220
|
+
|
|
221
|
+
const migrationEnabled =
|
|
222
|
+
generation === 'v2' &&
|
|
223
|
+
!detectionFallback &&
|
|
224
|
+
!args.includes('--project') &&
|
|
225
|
+
!args.includes('--help')
|
|
226
|
+
const dryRun = args.includes('--dry-run')
|
|
227
|
+
let initEnv = env
|
|
228
|
+
let prepared = { status: 'unchanged', changes: [] }
|
|
229
|
+
if (migrationEnabled) {
|
|
230
|
+
let configDir
|
|
231
|
+
try {
|
|
232
|
+
configDir = resolveGlobalConfigDirectory(env, home)
|
|
233
|
+
} catch (error) {
|
|
234
|
+
writeOutput(
|
|
235
|
+
output,
|
|
236
|
+
`${error instanceof Error ? error.message : 'OpenCode config path is invalid.'}\n`,
|
|
237
|
+
)
|
|
238
|
+
return 1
|
|
239
|
+
}
|
|
240
|
+
const headless = isHeadless(args, env, interactive) || dryRun
|
|
241
|
+
try {
|
|
242
|
+
prepared = await prepare({
|
|
243
|
+
configDir,
|
|
244
|
+
interactive: !headless,
|
|
245
|
+
dryRun,
|
|
246
|
+
output,
|
|
247
|
+
})
|
|
248
|
+
} catch {
|
|
249
|
+
writeOutput(output, 'V2 config preparation stopped safely; init was not started.\n')
|
|
250
|
+
return 1
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!dryRun && !headless && !['planned', 'unchanged'].includes(prepared?.status)) {
|
|
254
|
+
if (['canceled', 'skipped'].includes(prepared?.status)) {
|
|
255
|
+
writeOutput(output, 'V2 config review was not completed; init was not started.\n')
|
|
256
|
+
return 0
|
|
257
|
+
}
|
|
258
|
+
writeOutput(output, 'V2 config preflight is blocked; init was not started.\n')
|
|
259
|
+
return 1
|
|
260
|
+
}
|
|
261
|
+
if (['blocked', 'failed'].includes(prepared?.status)) {
|
|
262
|
+
writeOutput(output, 'V2 config preflight is blocked; init was not started.\n')
|
|
263
|
+
return 1
|
|
264
|
+
}
|
|
265
|
+
initEnv = { ...env, PANTHEON_SETUP_TARGET: configDir }
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const pinnedArgs = [...passthroughArgs(args), `--version=${generation}`]
|
|
269
|
+
const previewArgs = [
|
|
270
|
+
'init',
|
|
271
|
+
'--dry-run',
|
|
272
|
+
'--json',
|
|
273
|
+
'--headless',
|
|
274
|
+
'--setup-plan-json',
|
|
275
|
+
...pinnedArgs,
|
|
276
|
+
]
|
|
277
|
+
const configPreview = prepared.status === 'planned' ? (prepared.configPreview ?? null) : null
|
|
278
|
+
if (configPreview !== null) previewArgs.push('--setup-config-preview-stdin')
|
|
279
|
+
const preview = await previewInit(previewArgs, initEnv, configPreview)
|
|
280
|
+
if (preview?.error || preview?.status !== 0) {
|
|
281
|
+
if (dryRun || isHeadless(args, env, interactive)) {
|
|
282
|
+
writeOutput(
|
|
283
|
+
output,
|
|
284
|
+
'Preview only; the installer plan needs interactive resolution. Rerun `npm run setup` in an interactive terminal. No files were changed.\n',
|
|
285
|
+
)
|
|
286
|
+
return 0
|
|
287
|
+
}
|
|
288
|
+
writeOutput(output, 'Installer preflight failed safely; no files were changed.\n')
|
|
289
|
+
return 1
|
|
290
|
+
}
|
|
291
|
+
const initPlan = summarizeInitPreview(preview.stdout ?? '')
|
|
292
|
+
if (!initPlan) {
|
|
293
|
+
writeOutput(output, 'Installer preflight did not return a valid plan; no files were changed.\n')
|
|
294
|
+
return 1
|
|
295
|
+
}
|
|
296
|
+
if (prepared.unsafeMcpNames?.some((name) => initPlan.mcpServers.includes(name))) {
|
|
297
|
+
writeOutput(
|
|
298
|
+
output,
|
|
299
|
+
'An unsafe Pantheon MCP entry would be duplicated by init; abort setup and reconcile the JSONC entry first. No files were changed.\n',
|
|
300
|
+
)
|
|
301
|
+
return 1
|
|
302
|
+
}
|
|
303
|
+
const { totals, operations } = initPlan
|
|
304
|
+
writeOutput(
|
|
305
|
+
output,
|
|
306
|
+
`Init plan: ${totals.create} create, ${totals.update} update, ${totals.remove} remove, ${totals.unchanged} unchanged operation(s).\n`,
|
|
307
|
+
)
|
|
308
|
+
for (const operation of operations) {
|
|
309
|
+
writeOutput(output, `Init operation: ${operation.action} ${operation.path}.\n`)
|
|
310
|
+
}
|
|
311
|
+
if (prepared.status === 'planned') {
|
|
312
|
+
writeOutput(output, `Config migration plan: ${prepared.changes.length} file(s) to update.\n`)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (dryRun || isHeadless(args, env, interactive)) {
|
|
316
|
+
writeOutput(
|
|
317
|
+
output,
|
|
318
|
+
'Preview only; no config, backup, init, or run-record files were written. Rerun `npm run setup` in an interactive terminal to authorize setup.\n',
|
|
319
|
+
)
|
|
320
|
+
return 0
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let accepted
|
|
324
|
+
try {
|
|
325
|
+
accepted = await confirmInit()
|
|
326
|
+
} catch {
|
|
327
|
+
writeOutput(output, 'Setup authorization failed; no files were changed.\n')
|
|
328
|
+
return 1
|
|
329
|
+
}
|
|
330
|
+
if (clack.isCancel?.(accepted) || accepted !== true) {
|
|
331
|
+
writeOutput(output, 'Setup was not authorized; no files were changed.\n')
|
|
332
|
+
return 0
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
let migrationBackup = null
|
|
336
|
+
const configPreconditions = prepared.configPreconditions ?? []
|
|
337
|
+
if (
|
|
338
|
+
configPreconditions.length > 0 &&
|
|
339
|
+
!verifyConfigPreconditions(configPreconditions, {
|
|
340
|
+
configDir: prepared.configDir,
|
|
341
|
+
stage: 'original',
|
|
342
|
+
})
|
|
343
|
+
) {
|
|
344
|
+
writeOutput(
|
|
345
|
+
output,
|
|
346
|
+
'Reviewed config inputs changed after preflight; setup stopped before writes.\n',
|
|
347
|
+
)
|
|
348
|
+
return 1
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (prepared.status === 'planned') {
|
|
352
|
+
try {
|
|
353
|
+
migrationBackup = await applyConfig(prepared.changes, { configDir: prepared.configDir })
|
|
354
|
+
} catch {
|
|
355
|
+
writeOutput(
|
|
356
|
+
output,
|
|
357
|
+
'Config migration apply failed. If any file changed, use `pantheon-opencode restore` to review the setup backup. Init was not started.\n',
|
|
358
|
+
)
|
|
359
|
+
return 1
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (
|
|
364
|
+
configPreconditions.length > 0 &&
|
|
365
|
+
!verifyConfigPreconditions(configPreconditions, {
|
|
366
|
+
configDir: prepared.configDir,
|
|
367
|
+
stage: 'expected',
|
|
368
|
+
})
|
|
369
|
+
) {
|
|
370
|
+
writeOutput(
|
|
371
|
+
output,
|
|
372
|
+
`Config inputs drifted after the reviewed migration; init was not started.${migrationBackup?.dir ? ` Review the backup at ${migrationBackup.dir}; run pantheon-opencode restore to recover.` : ''}\n`,
|
|
373
|
+
)
|
|
374
|
+
return 1
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const postMigrationArgs = previewArgs.filter((arg) => arg !== '--setup-config-preview-stdin')
|
|
378
|
+
const postMigrationPreview = await previewInit(postMigrationArgs, initEnv)
|
|
379
|
+
const postMigrationPlan =
|
|
380
|
+
postMigrationPreview?.status === 0 && !postMigrationPreview.error
|
|
381
|
+
? summarizeInitPreview(postMigrationPreview.stdout ?? '')
|
|
382
|
+
: null
|
|
383
|
+
if (
|
|
384
|
+
!postMigrationPlan ||
|
|
385
|
+
!plansMatchAfterConfigApply(initPlan.setupPlan, postMigrationPlan.setupPlan, prepared)
|
|
386
|
+
) {
|
|
387
|
+
writeOutput(
|
|
388
|
+
output,
|
|
389
|
+
`Installer inputs or plan drifted after review; init was not started.${migrationBackup?.dir ? ` Review the backup at ${migrationBackup.dir}; run pantheon-opencode restore to recover.` : ''}\n`,
|
|
390
|
+
)
|
|
391
|
+
return 1
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const initResult = await runInit(
|
|
395
|
+
['init', '--yes', '--headless', '--setup-approved-plan-stdin', ...pinnedArgs],
|
|
396
|
+
initEnv,
|
|
397
|
+
{
|
|
398
|
+
schema_version: 1,
|
|
399
|
+
plan: postMigrationPlan.setupPlan,
|
|
400
|
+
digest: postMigrationPlan.setupPlanDigest,
|
|
401
|
+
configPreconditions,
|
|
402
|
+
},
|
|
403
|
+
)
|
|
404
|
+
if (initResult?.error) {
|
|
405
|
+
writeOutput(output, 'Setup init failed; see the installer output for details.\n')
|
|
406
|
+
return initResult.status ?? 1
|
|
407
|
+
}
|
|
408
|
+
if (initResult?.status !== undefined && initResult.status !== 0) return initResult.status ?? 1
|
|
409
|
+
if (initResult?.status === undefined && initResult?.code !== 0) return initResult?.code ?? 1
|
|
410
|
+
return 0
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
414
|
+
process.exitCode = await runSetup()
|
|
415
|
+
}
|
package/scripts/sync-tui.mjs
CHANGED
|
@@ -65,7 +65,7 @@ function resolveConfigDir() {
|
|
|
65
65
|
* The raw TSX source is never copied — the loader consumes only the bundle.
|
|
66
66
|
* @returns {{ created: number, skipped: number }}
|
|
67
67
|
*/
|
|
68
|
-
function copyPluginFiles(srcDir, dstDir, version) {
|
|
68
|
+
export function copyPluginFiles(srcDir, dstDir, version) {
|
|
69
69
|
const result = { created: 0, skipped: 0 }
|
|
70
70
|
|
|
71
71
|
mkdirSync(dstDir, { recursive: true })
|
|
@@ -93,6 +93,14 @@ function copyPluginFiles(srcDir, dstDir, version) {
|
|
|
93
93
|
if (version === 'v2' && packageJson.exports?.['./tui-v2']) {
|
|
94
94
|
packageJson.exports['./tui'] = packageJson.exports['./tui-v2']
|
|
95
95
|
}
|
|
96
|
+
// Mirror of scripts/install/plugin.mjs: the OpenCode host resolves the
|
|
97
|
+
// plugin server through the `./server` export. In the V2 copy it must
|
|
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
|
+
if (version === 'v2' && packageJson.exports?.['./server-v2']) {
|
|
102
|
+
packageJson.exports['./server'] = packageJson.exports['./server-v2']
|
|
103
|
+
}
|
|
96
104
|
const content = `${JSON.stringify(packageJson, null, 2)}\n`
|
|
97
105
|
if (writeIfChanged(join(dstDir, 'package.json'), content)) result.created++
|
|
98
106
|
else result.skipped++
|