pantheon-opencode 1.6.0-beta.9 → 1.6.1
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 +118 -0
- package/AGENTS.md +18 -168
- package/CHANGELOG.md +144 -365
- package/README.md +124 -607
- package/README.pt-BR.md +120 -345
- package/bin/pantheon-init.mjs +504 -141
- package/commands/pantheon-deepwork.md +14 -3
- package/commands/pantheon-vision.md +61 -12
- package/package.json +22 -13
- package/plugin.json +1 -1
- package/pyproject.toml +6 -2
- package/scripts/_pantheon_paths.py +24 -0
- package/scripts/build-agents-md.mjs +368 -69
- package/scripts/changelog-merge.mjs +161 -0
- package/scripts/check-plugin-v2-coverage.mjs +11 -8
- package/scripts/docs-check-changelog.mjs +204 -0
- package/scripts/docs-link-check.mjs +314 -0
- package/scripts/docs-media.mjs +157 -0
- package/scripts/doctor.mjs +850 -45
- package/scripts/install/agents-md.mjs +2 -2
- package/scripts/install/backup.mjs +648 -0
- package/scripts/install/cli-ui.mjs +303 -72
- package/scripts/install/component-selection.mjs +61 -0
- package/scripts/install/config-migration.mjs +583 -27
- package/scripts/install/exit-codes.mjs +26 -0
- package/scripts/install/file-inventory.mjs +555 -0
- package/scripts/install/health-check.mjs +31 -25
- package/scripts/install/interactive.mjs +99 -383
- package/scripts/install/interrupt.mjs +78 -0
- package/scripts/install/migrate.mjs +49 -25
- package/scripts/install/model-picker.mjs +218 -250
- package/scripts/install/opencode-state.mjs +91 -0
- package/scripts/install/opencode-version.mjs +83 -21
- package/scripts/install/opencode.mjs +1675 -187
- package/scripts/install/plan-artifact.mjs +517 -0
- package/scripts/install/plan.mjs +475 -0
- package/scripts/install/plugin.mjs +214 -27
- package/scripts/install/prompt-result.mjs +2 -0
- package/scripts/install/run-record.mjs +115 -0
- package/scripts/install/shared.mjs +256 -99
- package/scripts/install/state.mjs +63 -8
- package/scripts/install/strings.mjs +93 -8
- package/scripts/install/v2-capabilities.mjs +205 -0
- package/scripts/install/venv.mjs +90 -47
- package/scripts/install/verify.mjs +128 -0
- package/scripts/install/vision-prompt.mjs +173 -0
- package/scripts/install-mcp.mjs +2 -2
- package/scripts/manifest-inventory.mjs +49 -3
- package/scripts/mcp_persistence.py +1535 -1050
- package/scripts/memory_mcp.py +12 -843
- package/scripts/node-engine-policy.mjs +85 -0
- package/scripts/package-evidence.mjs +10 -2
- package/scripts/postinstall.mjs +26 -26
- package/scripts/probe-pantheon-cost.mjs +118 -19
- package/scripts/prune.mjs +9 -3
- package/scripts/reconcile.mjs +325 -0
- package/scripts/release-gates.mjs +687 -0
- package/scripts/restore.mjs +222 -0
- package/scripts/run-node-tests.mjs +24 -8
- package/scripts/sync-artifacts.mjs +19 -7
- package/scripts/sync-tui.mjs +5 -1
- package/scripts/test-opencode-v2-sandbox.sh +36 -123
- package/scripts/uninstall.mjs +369 -34
- package/scripts/update.mjs +164 -0
- package/scripts/validate-node-engine-policy.mjs +13 -0
- package/scripts/version-check.mjs +34 -1
- package/scripts/versioning.mjs +23 -3
- package/scripts/vision-status.mjs +682 -0
- package/skills-lock.json +8 -8
- package/src/agents/aphrodite.md +13 -10
- package/src/agents/apollo.md +4 -5
- package/src/agents/athena.md +74 -46
- package/src/agents/demeter.md +10 -7
- package/src/agents/gaia.md +0 -1
- package/src/agents/hephaestus.md +4 -3
- package/src/agents/hermes.md +10 -9
- package/src/agents/iris.md +6 -1
- package/src/agents/mnemosyne.md +10 -4
- package/src/agents/nyx.md +4 -4
- package/src/agents/prometheus.md +12 -11
- package/src/agents/talos.md +6 -0
- package/src/agents/zeus.md +84 -56
- package/src/instructions/agent-return-format.instructions.md +12 -41
- package/src/instructions/memory-protocol.instructions.md +5 -11
- package/src/instructions/test-economy.instructions.md +12 -0
- package/src/instructions/yagni.instructions.md +6 -15
- package/src/instructions/zeus-anti-stall.instructions.md +6 -6
- package/src/instructions/zeus-communication-rules.instructions.md +6 -6
- package/src/instructions/zeus-council-synthesis.instructions.md +11 -12
- package/src/instructions/zeus-memory-operations.instructions.md +13 -7
- package/src/instructions/zeus-timeout-retry.instructions.md +36 -10
- package/src/mcp/_pantheon_paths.py +24 -0
- package/src/mcp/mcp_codemap_module.py +86 -18
- package/src/mcp/mcp_persistence.py +1535 -1050
- package/src/mcp/memory_mcp.py +444 -94
- package/src/mcp/pantheon_vision.py +285 -41
- package/src/mcp/requirements-mcp.txt +6 -1
- package/src/mcp/requirements-vision.txt +1 -1
- package/src/pantheon/context-pruner.ts +541 -0
- package/src/pantheon/cost-command.ts +901 -60
- package/src/pantheon/delegation-enforce.ts +160 -23
- package/src/pantheon/goal-loop.ts +11 -8
- package/src/pantheon/guard-path.ts +162 -0
- package/src/pantheon/memory-context.ts +1017 -0
- package/src/pantheon/model-agents.ts +19 -0
- package/src/pantheon/model-command.ts +218 -56
- package/src/pantheon/model-pricing.ts +536 -0
- package/src/pantheon/presets.mjs +2 -0
- package/src/pantheon/task-result-guard.ts +50 -14
- package/src/pantheon/v2-bounded-read.ts +654 -0
- package/src/pantheon/v2-bridge.ts +27 -0
- package/src/pantheon/v2-delegation-enforce.ts +133 -6
- package/src/pantheon/v2-execute-after.ts +135 -24
- package/src/pantheon/v2-model-overrides.ts +275 -0
- package/src/pantheon/v2-shell-hooks.ts +260 -0
- package/src/pantheon/v2-tools.ts +89 -35
- package/src/pantheon/v2-unsupported.mjs +34 -7
- package/src/pantheon/v2-vision.ts +622 -0
- package/src/pantheon/vision-local.ts +531 -0
- package/src/pantheon/vision.ts +1166 -116
- package/src/plugin-v2.ts +1039 -171
- package/src/plugin.ts +37 -13
- package/src/plugins/tui/dist/tui-v2.d.ts +1029 -2
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +3742 -85
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +15 -15
- package/src/plugins/tui/package.json +7 -5
- package/src/plugins/tui/src/index-v2.tsx +4314 -50
- package/src/plugins/tui/tsconfig.typecheck.json +5 -0
- package/src/routing.yml +50 -5
- package/src/skills/agent-coordination/SKILL.md +7 -2
- package/src/skills/artifact-management/SKILL.md +5 -1
- package/src/skills/auto-continue/SKILL.md +14 -6
- package/src/skills/codemap/SKILL.md +1 -1
- package/src/skills/memory-bank/SKILL.md +21 -13
- package/src/skills/session-goal/SKILL.md +12 -22
- package/src/skills/spec-driven-development/SKILL.md +3 -1
- package/src/skills/worktrees/SKILL.md +30 -11
- package/scripts/probe-context-rehydrate.mjs +0 -263
package/bin/pantheon-init.mjs
CHANGED
|
@@ -11,23 +11,41 @@
|
|
|
11
11
|
* under BOTH OpenCode V1 (`opencode` 1.18.x) and V2 (`opencode2`, OpenCode 2.x —
|
|
12
12
|
* `opencode2 --version` prints "opencode v2.0.22"; an early 2.x prerelease
|
|
13
13
|
* printed "0.0.0-next-17444", which is history and not a host observation).
|
|
14
|
-
* V2 reads the same config locations and normalizes V1
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* V2 reads the same config locations and normalizes V1 fields in memory through
|
|
15
|
+
* migrateV1toV2() (scripts/install/config-migration.mjs), then writes the
|
|
16
|
+
* V2-native `plugins` list. `--version v2` selects that path.
|
|
17
|
+
*
|
|
18
|
+
* State is NOT isolated per generation: both host generations read one OpenCode
|
|
19
|
+
* store, so this CLI claims neither a separate database nor a service port. The
|
|
20
|
+
* installer prints the path an actual resolver returns
|
|
21
|
+
* (scripts/install/opencode-state.mjs).
|
|
18
22
|
*/
|
|
19
23
|
import fs from 'node:fs'
|
|
20
24
|
import os from 'node:os'
|
|
21
25
|
import path from 'node:path'
|
|
22
26
|
import { fileURLToPath } from 'node:url'
|
|
27
|
+
import { configure as configureUi, endGaugeLine, tag } from '../scripts/install/cli-ui.mjs'
|
|
28
|
+
import { resolveComponentSelection } from '../scripts/install/component-selection.mjs'
|
|
29
|
+
import { resolveInstallExitCode } from '../scripts/install/exit-codes.mjs'
|
|
30
|
+
import { createInterruptHandler } from '../scripts/install/interrupt.mjs'
|
|
31
|
+
import {
|
|
32
|
+
createPlanArtifact,
|
|
33
|
+
loadPlanArtifact,
|
|
34
|
+
savePlanArtifact,
|
|
35
|
+
} from '../scripts/install/plan-artifact.mjs'
|
|
36
|
+
import { PROMPT_CANCELED } from '../scripts/install/prompt-result.mjs'
|
|
37
|
+
import { buildRunRecord, readRunRecord, writeRunRecord } from '../scripts/install/run-record.mjs'
|
|
38
|
+
import {
|
|
39
|
+
isSupportedNodeVersion,
|
|
40
|
+
unsupportedNodeVersionMessage,
|
|
41
|
+
} from '../scripts/node-engine-policy.mjs'
|
|
42
|
+
import { runUpdate } from '../scripts/update.mjs'
|
|
23
43
|
|
|
24
44
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
25
45
|
const ROOT = path.resolve(__dirname, '..')
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.error(`❌ Node.js >= ${REQUIRED_NODE_MAJOR} required (current: ${process.versions.node})`)
|
|
30
|
-
console.error(' Install a newer Node via nvm: https://github.com/nvm-sh/nvm')
|
|
47
|
+
if (!isSupportedNodeVersion(process.versions.node)) {
|
|
48
|
+
console.error(unsupportedNodeVersionMessage(process.versions.node))
|
|
31
49
|
process.exit(1)
|
|
32
50
|
}
|
|
33
51
|
|
|
@@ -47,6 +65,10 @@ function printUsage() {
|
|
|
47
65
|
console.log(' npx pantheon-opencode init # Install globally')
|
|
48
66
|
console.log(' npx pantheon-opencode init --project # Install in project')
|
|
49
67
|
console.log(' npx pantheon-opencode init --dry-run # Preview only')
|
|
68
|
+
console.log(' npx pantheon-opencode init --dry-run --save-plan <file> # Save reviewed plan')
|
|
69
|
+
console.log(' npx pantheon-opencode init --apply-plan <file> [--yes] # Apply reviewed plan')
|
|
70
|
+
console.log(' npx pantheon-opencode init --dry-run --json # Versioned JSON preview')
|
|
71
|
+
console.log(' npx pantheon-opencode init --verbose # Step-by-step install detail')
|
|
50
72
|
console.log(' npx pantheon-opencode init --no-mcp # Skip MCP + venv')
|
|
51
73
|
console.log(' npx pantheon-opencode init --force # Overwrite + recreate venv')
|
|
52
74
|
console.log(' npx pantheon-opencode init --doctor # Run health check after install')
|
|
@@ -69,10 +91,35 @@ function printUsage() {
|
|
|
69
91
|
console.log(' npx pantheon-opencode prune # List legacy artifacts (dry-run)')
|
|
70
92
|
console.log(' npx pantheon-opencode prune --apply # Remove stale backups')
|
|
71
93
|
console.log(' npx pantheon-opencode doctor [--profile] # Run health check')
|
|
94
|
+
console.log(
|
|
95
|
+
' npx pantheon-opencode restore [--project] [--yes] # Restore an exact installer backup',
|
|
96
|
+
)
|
|
72
97
|
console.log(' npx pantheon-opencode uninstall --project # Remove project artifacts safely')
|
|
73
98
|
console.log(' npx pantheon-opencode uninstall --global # Remove global artifacts safely')
|
|
99
|
+
console.log(' npx pantheon-opencode reconcile --project # Review stale owned installer files')
|
|
74
100
|
console.log(' npx pantheon-opencode --version, -v # Print version and exit')
|
|
75
101
|
console.log(' npx pantheon-opencode --help # Show this help')
|
|
102
|
+
console.log('')
|
|
103
|
+
console.log('Apply authorization:')
|
|
104
|
+
console.log(' A non-interactive run without --yes prints the plan and applies NOTHING.')
|
|
105
|
+
console.log(' Re-run with --yes to apply; an interactive TTY run prompts (default: no).')
|
|
106
|
+
console.log('')
|
|
107
|
+
console.log('Exit codes:')
|
|
108
|
+
console.log(' 0 success, or plan/no-apply (declined)')
|
|
109
|
+
console.log(' 1 failure')
|
|
110
|
+
console.log(' 2 apply was requested without authorization (non-interactive, no --yes)')
|
|
111
|
+
console.log(' 3 drift detected (a planned file changed after the plan)')
|
|
112
|
+
console.log(' 130 canceled')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function authorizeReviewedPlan(plan) {
|
|
116
|
+
const operations = plan.operations.filter((operation) => operation.action !== 'unchanged')
|
|
117
|
+
console.log(`Reviewed plan: ${plan.target.path} (${operations.length} change(s))`)
|
|
118
|
+
for (const operation of operations) {
|
|
119
|
+
console.log(` ${operation.action.padEnd(9)} ${operation.path}`)
|
|
120
|
+
}
|
|
121
|
+
const { promptReview } = await import('../scripts/install/interactive.mjs')
|
|
122
|
+
return promptReview('Apply this reviewed plan?', { default: false })
|
|
76
123
|
}
|
|
77
124
|
|
|
78
125
|
async function main() {
|
|
@@ -109,6 +156,27 @@ async function main() {
|
|
|
109
156
|
process.exit(result.status ?? 1)
|
|
110
157
|
}
|
|
111
158
|
|
|
159
|
+
if (command === 'reconcile') {
|
|
160
|
+
const { spawnSync } = await import('node:child_process')
|
|
161
|
+
const reconcileScript = path.join(ROOT, 'scripts', 'reconcile.mjs')
|
|
162
|
+
const result = spawnSync(process.execPath, [reconcileScript, ...args.slice(1)], {
|
|
163
|
+
stdio: 'inherit',
|
|
164
|
+
cwd: process.cwd(),
|
|
165
|
+
})
|
|
166
|
+
process.exit(result.status ?? 1)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// restore delegates to scripts/restore.mjs (same spawnSync pattern as prune).
|
|
170
|
+
if (command === 'restore') {
|
|
171
|
+
const { spawnSync } = await import('node:child_process')
|
|
172
|
+
const restoreScript = path.join(ROOT, 'scripts', 'restore.mjs')
|
|
173
|
+
const result = spawnSync(process.execPath, [restoreScript, ...args.slice(1)], {
|
|
174
|
+
stdio: 'inherit',
|
|
175
|
+
cwd: process.cwd(),
|
|
176
|
+
})
|
|
177
|
+
process.exit(result.status ?? 1)
|
|
178
|
+
}
|
|
179
|
+
|
|
112
180
|
// doctor delegates to scripts/doctor.mjs (same spawnSync pattern as prune).
|
|
113
181
|
// Forwarding the FULL args (profile, target, --fix, ...) keeps the packaged
|
|
114
182
|
// CLI a thin wrapper; the doctor banner reports the resolved profile.
|
|
@@ -125,72 +193,12 @@ async function main() {
|
|
|
125
193
|
// beta.5: one-command update — check npm dist-tag, install, re-init.
|
|
126
194
|
// Default channel is `beta` (the prerelease line); `--stable` uses `latest`.
|
|
127
195
|
if (command === 'update') {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log(`Pantheon OpenCode v${current} — checking the "${channel}" channel...`)
|
|
134
|
-
const view = spawnSync('npm', ['view', `pantheon-opencode@${channel}`, 'version'], {
|
|
135
|
-
encoding: 'utf8',
|
|
136
|
-
timeout: 30_000,
|
|
196
|
+
const status = runUpdate(args, {
|
|
197
|
+
root: ROOT,
|
|
198
|
+
currentVersion: readVersion(),
|
|
199
|
+
runningScript: process.argv[1],
|
|
137
200
|
})
|
|
138
|
-
|
|
139
|
-
if (view.status !== 0 || !latest) {
|
|
140
|
-
console.error(
|
|
141
|
-
`❌ Could not reach the npm registry: ${(view.stderr || view.stdout || '').trim() || 'no version returned'}`,
|
|
142
|
-
)
|
|
143
|
-
process.exit(1)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Prerelease-aware compare: core (major.minor.patch) first, then the
|
|
147
|
-
// beta counter; a stable release outranks any beta of the same core.
|
|
148
|
-
const parsePantheonVersion = (v) => {
|
|
149
|
-
const m = String(v)
|
|
150
|
-
.trim()
|
|
151
|
-
.match(/^(\d+)\.(\d+)\.(\d+)(?:-beta\.(\d+))?$/)
|
|
152
|
-
if (!m) return null
|
|
153
|
-
return {
|
|
154
|
-
core: [+m[1], +m[2], +m[3]],
|
|
155
|
-
beta: m[4] === undefined ? Number.POSITIVE_INFINITY : +m[4],
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const cmp = (a, b) => {
|
|
159
|
-
const pa = parsePantheonVersion(a)
|
|
160
|
-
const pb = parsePantheonVersion(b)
|
|
161
|
-
if (!pa || !pb) return 0
|
|
162
|
-
for (let i = 0; i < 3; i++) {
|
|
163
|
-
if (pa.core[i] !== pb.core[i]) return pa.core[i] - pb.core[i]
|
|
164
|
-
}
|
|
165
|
-
return pa.beta - pb.beta
|
|
166
|
-
}
|
|
167
|
-
if (cmp(latest, current) <= 0) {
|
|
168
|
-
console.log(`✅ Already up to date (installed v${current}; ${channel} channel: v${latest}).`)
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
console.log(`Updating v${current} → v${latest} (channel: ${channel})...`)
|
|
173
|
-
const install = spawnSync('npm', ['install', '-g', `pantheon-opencode@${channel}`], {
|
|
174
|
-
stdio: 'inherit',
|
|
175
|
-
})
|
|
176
|
-
if (install.status !== 0) {
|
|
177
|
-
console.error('❌ npm install failed — the previous installation is untouched.')
|
|
178
|
-
process.exit(install.status ?? 1)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Refresh config/venv/MCP entries with the NEW package (resolved via
|
|
182
|
-
// PATH — the freshly installed global bin).
|
|
183
|
-
const init = spawnSync('pantheon-opencode', ['init', '--yes', '--headless'], {
|
|
184
|
-
stdio: 'inherit',
|
|
185
|
-
shell: process.platform === 'win32',
|
|
186
|
-
})
|
|
187
|
-
if (init.status !== 0 || init.error) {
|
|
188
|
-
console.error(
|
|
189
|
-
'⚠️ Updated, but the config refresh did not complete — run `npx pantheon-opencode init` manually.',
|
|
190
|
-
)
|
|
191
|
-
process.exit(init.status ?? 1)
|
|
192
|
-
}
|
|
193
|
-
console.log(`✅ Updated to v${latest}.`)
|
|
201
|
+
if (status !== 0) process.exit(status)
|
|
194
202
|
return
|
|
195
203
|
}
|
|
196
204
|
|
|
@@ -248,7 +256,8 @@ async function main() {
|
|
|
248
256
|
|
|
249
257
|
if (name === 'none') {
|
|
250
258
|
if (isDryRun) {
|
|
251
|
-
|
|
259
|
+
configureUi({ dryRun: true })
|
|
260
|
+
console.log(tag('Would clear model preset'))
|
|
252
261
|
} else {
|
|
253
262
|
if (fs.existsSync(filePath)) {
|
|
254
263
|
fs.mkdirSync(path.dirname(bakPath), { recursive: true })
|
|
@@ -274,15 +283,88 @@ async function main() {
|
|
|
274
283
|
}
|
|
275
284
|
|
|
276
285
|
if (command === 'init' || !command) {
|
|
277
|
-
const
|
|
278
|
-
const
|
|
279
|
-
const
|
|
286
|
+
const applyPlanIndex = args.indexOf('--apply-plan')
|
|
287
|
+
const inlineApplyPlan = args.find((arg) => arg.startsWith('--apply-plan='))
|
|
288
|
+
const applyPlanPath =
|
|
289
|
+
applyPlanIndex >= 0
|
|
290
|
+
? (args[applyPlanIndex + 1] ?? null)
|
|
291
|
+
: (inlineApplyPlan?.split('=', 2)[1] ?? null)
|
|
292
|
+
if (applyPlanIndex >= 0 && !applyPlanPath) {
|
|
293
|
+
console.error('❌ --apply-plan requires a plan file path')
|
|
294
|
+
process.exit(1)
|
|
295
|
+
}
|
|
296
|
+
let reviewedPlan = null
|
|
297
|
+
if (applyPlanPath !== null) {
|
|
298
|
+
const allowed = new Set(['init', '--apply-plan', applyPlanPath, '--yes', '-y', '--headless'])
|
|
299
|
+
const normalized = args.map((value) =>
|
|
300
|
+
value.startsWith('--apply-plan=') ? '--apply-plan' : value,
|
|
301
|
+
)
|
|
302
|
+
if (normalized.some((value) => !allowed.has(value))) {
|
|
303
|
+
console.error('❌ --apply-plan accepts only the plan path and fresh authorization flags')
|
|
304
|
+
process.exit(1)
|
|
305
|
+
}
|
|
306
|
+
reviewedPlan = loadPlanArtifact(applyPlanPath)
|
|
307
|
+
if (
|
|
308
|
+
reviewedPlan.artifact_path &&
|
|
309
|
+
path.resolve(applyPlanPath) !== reviewedPlan.artifact_path
|
|
310
|
+
) {
|
|
311
|
+
console.error('❌ The reviewed plan artifact was moved; use its original path')
|
|
312
|
+
process.exit(1)
|
|
313
|
+
}
|
|
314
|
+
const options = reviewedPlan.options
|
|
315
|
+
if (
|
|
316
|
+
!Array.isArray(options.components) ||
|
|
317
|
+
options.components.some(
|
|
318
|
+
(component) =>
|
|
319
|
+
!['agents', 'skills', 'instructions', 'commands', 'plugins', 'runtime'].includes(
|
|
320
|
+
component,
|
|
321
|
+
),
|
|
322
|
+
) ||
|
|
323
|
+
options.clean !== false ||
|
|
324
|
+
!['v1', 'v2', 'auto'].includes(options.version) ||
|
|
325
|
+
typeof options.isProject !== 'boolean'
|
|
326
|
+
) {
|
|
327
|
+
console.error('❌ Install-plan options are invalid or unsupported')
|
|
328
|
+
process.exit(1)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const isProject = reviewedPlan ? reviewedPlan.options.isProject : args.includes('--project')
|
|
332
|
+
const isDryRun = reviewedPlan ? false : args.includes('--dry-run')
|
|
280
333
|
// --clean is an alias of --force (both wipe component dirs + recreate venv).
|
|
281
|
-
const forceReinstall =
|
|
282
|
-
|
|
283
|
-
|
|
334
|
+
const forceReinstall = reviewedPlan
|
|
335
|
+
? reviewedPlan.options.clean
|
|
336
|
+
: args.includes('--force') || args.includes('--clean')
|
|
337
|
+
const runDoctor = !reviewedPlan && args.includes('--doctor')
|
|
338
|
+
const forceInteractive = !reviewedPlan && args.includes('--interactive')
|
|
284
339
|
const forceHeadless = args.includes('--headless')
|
|
285
|
-
|
|
340
|
+
let autoYes = args.includes('--yes') || args.includes('-y')
|
|
341
|
+
const isJson = args.includes('--json')
|
|
342
|
+
const savePlanIndex = args.indexOf('--save-plan')
|
|
343
|
+
const inlineSavePlan = args.find((arg) => arg.startsWith('--save-plan='))
|
|
344
|
+
const savePlanPath =
|
|
345
|
+
savePlanIndex >= 0
|
|
346
|
+
? (args[savePlanIndex + 1] ?? null)
|
|
347
|
+
: (inlineSavePlan?.split('=', 2)[1] ?? null)
|
|
348
|
+
if (savePlanIndex >= 0 && !savePlanPath) {
|
|
349
|
+
console.error('❌ --save-plan requires a plan file path')
|
|
350
|
+
process.exit(1)
|
|
351
|
+
}
|
|
352
|
+
if (savePlanPath !== null && (!isDryRun || reviewedPlan)) {
|
|
353
|
+
console.error('❌ --save-plan is available only with init --dry-run')
|
|
354
|
+
process.exit(1)
|
|
355
|
+
}
|
|
356
|
+
if (savePlanPath !== null && forceReinstall) {
|
|
357
|
+
console.error('❌ Saving a reviewed plan with --force/--clean is not supported safely')
|
|
358
|
+
process.exit(1)
|
|
359
|
+
}
|
|
360
|
+
if (isJson && (!isDryRun || reviewedPlan)) {
|
|
361
|
+
console.error('❌ --json is supported only with init --dry-run')
|
|
362
|
+
process.exit(1)
|
|
363
|
+
}
|
|
364
|
+
if (isJson && forceReinstall) {
|
|
365
|
+
console.error('❌ --force/--clean cleanup is not supported with --json')
|
|
366
|
+
process.exit(1)
|
|
367
|
+
}
|
|
286
368
|
|
|
287
369
|
// beta.5: warn on unrecognized flags instead of silently ignoring them.
|
|
288
370
|
const VALUE_FLAGS = new Set([
|
|
@@ -293,6 +375,8 @@ async function main() {
|
|
|
293
375
|
'--opencode-version',
|
|
294
376
|
'--components',
|
|
295
377
|
'--merge-dev-config',
|
|
378
|
+
'--apply-plan',
|
|
379
|
+
'--save-plan',
|
|
296
380
|
])
|
|
297
381
|
for (let i = 1; i < args.length; i++) {
|
|
298
382
|
const arg = args[i]
|
|
@@ -315,6 +399,8 @@ async function main() {
|
|
|
315
399
|
'--headless',
|
|
316
400
|
'--yes',
|
|
317
401
|
'-y',
|
|
402
|
+
'--json',
|
|
403
|
+
'--verbose',
|
|
318
404
|
].includes(bare)
|
|
319
405
|
) {
|
|
320
406
|
console.error(`⚠️ Unknown option ignored: ${arg}`)
|
|
@@ -322,20 +408,44 @@ async function main() {
|
|
|
322
408
|
}
|
|
323
409
|
|
|
324
410
|
const presetIndex = args.indexOf('--preset')
|
|
325
|
-
const
|
|
411
|
+
const inlinePreset = args.find((arg) => arg.startsWith('--preset='))
|
|
412
|
+
const hasPresetOption = presetIndex >= 0 || inlinePreset !== undefined
|
|
413
|
+
const parsedPreset =
|
|
414
|
+
presetIndex >= 0
|
|
415
|
+
? (args[presetIndex + 1] ?? null)
|
|
416
|
+
: (inlinePreset?.slice('--preset='.length) ?? null)
|
|
417
|
+
if (
|
|
418
|
+
hasPresetOption &&
|
|
419
|
+
(typeof parsedPreset !== 'string' ||
|
|
420
|
+
parsedPreset.trim() === '' ||
|
|
421
|
+
parsedPreset.startsWith('--'))
|
|
422
|
+
) {
|
|
423
|
+
console.error('❌ --preset requires a non-empty value')
|
|
424
|
+
process.exit(1)
|
|
425
|
+
}
|
|
426
|
+
const presetOpt = reviewedPlan ? (reviewedPlan.options.preset ?? null) : parsedPreset
|
|
326
427
|
// Explicit top-level model overrides for the generated config.
|
|
327
428
|
const modelIndex = args.indexOf('--model')
|
|
328
|
-
const modelOpt =
|
|
429
|
+
const modelOpt = reviewedPlan
|
|
430
|
+
? (reviewedPlan.options.model ?? null)
|
|
431
|
+
: modelIndex >= 0
|
|
432
|
+
? (args[modelIndex + 1] ?? null)
|
|
433
|
+
: null
|
|
329
434
|
const smallModelIndex = args.indexOf('--small-model')
|
|
330
|
-
const smallModelOpt =
|
|
435
|
+
const smallModelOpt = reviewedPlan
|
|
436
|
+
? (reviewedPlan.options.smallModel ?? null)
|
|
437
|
+
: smallModelIndex >= 0
|
|
438
|
+
? (args[smallModelIndex + 1] ?? null)
|
|
439
|
+
: null
|
|
331
440
|
// --version v1|v2|auto labels the install target. `auto` resolves the
|
|
332
441
|
// generation from the opencode binary at install time (see
|
|
333
442
|
// scripts/install/opencode-version.mjs). Invalid values fail fast.
|
|
334
443
|
const versionIndex = args.indexOf('--version')
|
|
335
444
|
const legacyVersionIndex = args.indexOf('--opencode-version')
|
|
336
445
|
const inlineVersion = args.find((arg) => arg.startsWith('--opencode-version='))
|
|
337
|
-
const versionOpt =
|
|
338
|
-
|
|
446
|
+
const versionOpt = reviewedPlan
|
|
447
|
+
? reviewedPlan.options.version
|
|
448
|
+
: versionIndex >= 0
|
|
339
449
|
? (args[versionIndex + 1] ?? null)
|
|
340
450
|
: legacyVersionIndex >= 0
|
|
341
451
|
? (args[legacyVersionIndex + 1] ?? null)
|
|
@@ -350,29 +460,18 @@ async function main() {
|
|
|
350
460
|
process.exit(1)
|
|
351
461
|
}
|
|
352
462
|
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (componentsOpt !== null) {
|
|
364
|
-
requestedComponents = componentsOpt
|
|
365
|
-
.split(',')
|
|
366
|
-
.map((c) => c.trim())
|
|
367
|
-
.filter(Boolean)
|
|
368
|
-
const unknown = requestedComponents.filter((c) => !KNOWN_COMPONENTS.includes(c))
|
|
369
|
-
if (requestedComponents.length === 0 || unknown.length > 0) {
|
|
370
|
-
console.error(
|
|
371
|
-
`❌ Invalid --components "${componentsOpt}" — expected comma-separated names from: ${KNOWN_COMPONENTS.join(', ')}`,
|
|
372
|
-
)
|
|
373
|
-
process.exit(1)
|
|
374
|
-
}
|
|
463
|
+
// Resolve the user's explicit selection separately from the defaults. An
|
|
464
|
+
// unscoped install gets runtime by default; explicit --components does not.
|
|
465
|
+
let componentSelection
|
|
466
|
+
try {
|
|
467
|
+
componentSelection = resolveComponentSelection(args, {
|
|
468
|
+
reviewedComponents: reviewedPlan?.options.components ?? null,
|
|
469
|
+
})
|
|
470
|
+
} catch (err) {
|
|
471
|
+
console.error(`❌ ${err.message}`)
|
|
472
|
+
process.exit(1)
|
|
375
473
|
}
|
|
474
|
+
const { components, requestedComponentsForPrompt, noMcp: skipMCP } = componentSelection
|
|
376
475
|
|
|
377
476
|
// --merge-dev-config <path> opts IN to merging a contributor's personal
|
|
378
477
|
// OpenCode config into the generated one. Only third-party plugin/provider/
|
|
@@ -381,8 +480,9 @@ async function main() {
|
|
|
381
480
|
// from the installer code, never from a dev checkout).
|
|
382
481
|
const mergeDevConfigIndex = args.indexOf('--merge-dev-config')
|
|
383
482
|
const inlineMergeDevConfig = args.find((arg) => arg.startsWith('--merge-dev-config='))
|
|
384
|
-
const mergeDevConfigOpt =
|
|
385
|
-
|
|
483
|
+
const mergeDevConfigOpt = reviewedPlan
|
|
484
|
+
? (reviewedPlan.options.mergeDevConfig ?? null)
|
|
485
|
+
: mergeDevConfigIndex >= 0
|
|
386
486
|
? (args[mergeDevConfigIndex + 1] ?? null)
|
|
387
487
|
: (inlineMergeDevConfig?.split('=', 2)[1] ?? null)
|
|
388
488
|
if (mergeDevConfigIndex >= 0 && mergeDevConfigOpt === null) {
|
|
@@ -390,61 +490,324 @@ async function main() {
|
|
|
390
490
|
process.exit(1)
|
|
391
491
|
}
|
|
392
492
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
'skills',
|
|
396
|
-
'instructions',
|
|
397
|
-
'commands',
|
|
398
|
-
'plugins',
|
|
399
|
-
]
|
|
400
|
-
if (!skipMCP && !components.includes('runtime')) components.push('runtime')
|
|
401
|
-
if (skipMCP) {
|
|
402
|
-
const runtimeIndex = components.indexOf('runtime')
|
|
403
|
-
if (runtimeIndex >= 0) components.splice(runtimeIndex, 1)
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// Version info
|
|
493
|
+
// Version info (resolved BEFORE the authorization prompts: every
|
|
494
|
+
// termination path below has to name its reason from the same table).
|
|
407
495
|
const version = readVersion()
|
|
408
496
|
const { strings } = await import('../scripts/install/strings.mjs')
|
|
409
497
|
const S = strings()
|
|
498
|
+
// Declared before the authorization prompts so a cancel/decline can record
|
|
499
|
+
// what the run decided; filled by the apply below.
|
|
500
|
+
let result = null
|
|
501
|
+
// Where a run record goes when the installer never reports a target: the
|
|
502
|
+
// interactive prompts can cancel before a location is chosen. Mirrors the
|
|
503
|
+
// installer's own default (`~/.config/opencode`), so the record lands next
|
|
504
|
+
// to the config the next run will read.
|
|
505
|
+
const fallbackTarget = isProject
|
|
506
|
+
? process.cwd()
|
|
507
|
+
: path.join(os.homedir(), '.config', 'opencode')
|
|
508
|
+
/**
|
|
509
|
+
* Persist the one-line record of this run. Bookkeeping is best-effort: a
|
|
510
|
+
* failure is reported, never fatal, and never changes the exit code.
|
|
511
|
+
*
|
|
512
|
+
* @param {{status: string, reason?: string|null, cancelPoint?: string|null, applied: boolean, target?: string}} outcome
|
|
513
|
+
*/
|
|
514
|
+
const recordRun = (outcome) => {
|
|
515
|
+
const recordTarget = outcome.target ?? result?.target ?? fallbackTarget
|
|
516
|
+
const record = buildRunRecord({
|
|
517
|
+
status: outcome.status,
|
|
518
|
+
reason: outcome.reason ?? null,
|
|
519
|
+
cancelPoint: outcome.cancelPoint ?? null,
|
|
520
|
+
mode: 'apply',
|
|
521
|
+
applied: outcome.applied,
|
|
522
|
+
pantheonVersion: version,
|
|
523
|
+
})
|
|
524
|
+
const written = writeRunRecord(recordTarget, record)
|
|
525
|
+
if (!written.written) {
|
|
526
|
+
console.error(S.runRecordFailed(written.error ?? written.path))
|
|
527
|
+
}
|
|
528
|
+
}
|
|
410
529
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
530
|
+
// A previous run that applied nothing is worth one line on the next run:
|
|
531
|
+
// "canceled at the review prompt" is otherwise a thing the user has to
|
|
532
|
+
// rediscover. Only non-applied outcomes are surfaced; a normal re-install is
|
|
533
|
+
// not news.
|
|
534
|
+
if (!isDryRun && !isJson) {
|
|
535
|
+
const previous = readRunRecord(reviewedPlan ? reviewedPlan.target.path : fallbackTarget)
|
|
536
|
+
if (previous !== null && previous.applied === false && previous.status !== 'plan') {
|
|
537
|
+
console.log(` ${S.previousRun(previous.summary ?? previous.status)}`)
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (reviewedPlan && !autoYes) {
|
|
542
|
+
if (!forceHeadless && process.stdin.isTTY && process.stdout.isTTY) {
|
|
543
|
+
const authorization = await authorizeReviewedPlan(reviewedPlan)
|
|
544
|
+
if (authorization === PROMPT_CANCELED) {
|
|
545
|
+
// The prompt already printed the single cancel line, naming the
|
|
546
|
+
// review point; only the exit code and the record are left.
|
|
547
|
+
recordRun({
|
|
548
|
+
status: 'canceled',
|
|
549
|
+
reason: 'canceled',
|
|
550
|
+
cancelPoint: 'review',
|
|
551
|
+
applied: false,
|
|
552
|
+
target: reviewedPlan.target.path,
|
|
553
|
+
})
|
|
554
|
+
process.exitCode = 130
|
|
555
|
+
return
|
|
556
|
+
}
|
|
557
|
+
if (!authorization) {
|
|
558
|
+
console.error(S.declinedAt(S.cancelPoints.review))
|
|
559
|
+
recordRun({
|
|
560
|
+
status: 'declined',
|
|
561
|
+
reason: 'declined',
|
|
562
|
+
cancelPoint: 'review',
|
|
563
|
+
applied: false,
|
|
564
|
+
target: reviewedPlan.target.path,
|
|
565
|
+
})
|
|
566
|
+
return
|
|
567
|
+
}
|
|
568
|
+
} else {
|
|
569
|
+
console.error('❌ Applying a reviewed plan requires --yes or an interactive TTY prompt.')
|
|
570
|
+
process.exit(2)
|
|
571
|
+
}
|
|
572
|
+
autoYes = true
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const planTimestamp = reviewedPlan?.planned_at ?? new Date().toISOString()
|
|
576
|
+
const stdoutWrite = process.stdout.write
|
|
577
|
+
if (isJson) process.stdout.write = () => true
|
|
578
|
+
if (!isJson) {
|
|
414
579
|
console.log('')
|
|
580
|
+
if (!forceInteractive || isDryRun) {
|
|
581
|
+
console.log(`Pantheon OpenCode v${version} — ${isDryRun ? S.dryRun : S.installing}`)
|
|
582
|
+
console.log('')
|
|
583
|
+
}
|
|
415
584
|
}
|
|
416
585
|
|
|
586
|
+
// Ctrl-C was unhandled anywhere in bin/ or scripts/install/, so an
|
|
587
|
+
// interrupted install died without printing anything and without leaving a
|
|
588
|
+
// trace. The handler makes the interrupt behave like every other cancel:
|
|
589
|
+
// ONE explainable line, a record on disk, and exit 130. The prompt library
|
|
590
|
+
// consumes Ctrl-C in raw mode while a question is on screen (that path is
|
|
591
|
+
// the interactive cancel above), so this covers the rest of the run.
|
|
592
|
+
const onInterrupt = createInterruptHandler({
|
|
593
|
+
message: S.canceledAt(S.cancelPoints.interrupt),
|
|
594
|
+
json: isJson,
|
|
595
|
+
endGaugeLine,
|
|
596
|
+
onInterrupt: () => {
|
|
597
|
+
if (!isDryRun) {
|
|
598
|
+
recordRun({
|
|
599
|
+
status: 'canceled',
|
|
600
|
+
reason: 'canceled',
|
|
601
|
+
cancelPoint: 'interrupt',
|
|
602
|
+
applied: false,
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
})
|
|
607
|
+
|
|
608
|
+
let installError = null
|
|
417
609
|
try {
|
|
418
610
|
const { installOpenCode } = await import('../scripts/install/opencode.mjs')
|
|
419
|
-
const target = isProject ? process.cwd() : undefined
|
|
420
|
-
await installOpenCode(target, isDryRun, forceReinstall, components, {
|
|
611
|
+
const target = reviewedPlan ? reviewedPlan.target.path : isProject ? process.cwd() : undefined
|
|
612
|
+
result = await installOpenCode(target, isDryRun, forceReinstall, components, {
|
|
421
613
|
interactive: forceInteractive,
|
|
422
|
-
headless: forceHeadless,
|
|
614
|
+
headless: reviewedPlan ? true : forceHeadless,
|
|
423
615
|
yes: autoYes,
|
|
424
616
|
model: modelOpt,
|
|
425
617
|
smallModel: smallModelOpt,
|
|
426
618
|
preset: presetOpt,
|
|
427
619
|
version: versionOpt ?? 'auto',
|
|
428
620
|
mergeDevConfig: mergeDevConfigOpt,
|
|
621
|
+
expectedPlan: reviewedPlan,
|
|
622
|
+
requestedComponents: requestedComponentsForPrompt,
|
|
623
|
+
noMcp: skipMCP,
|
|
624
|
+
planTimestamp,
|
|
625
|
+
quiet: isJson,
|
|
626
|
+
verbose: args.includes('--verbose') && !isJson,
|
|
429
627
|
})
|
|
430
628
|
} catch (err) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
629
|
+
installError = err
|
|
630
|
+
} finally {
|
|
631
|
+
if (isJson) process.stdout.write = stdoutWrite
|
|
632
|
+
}
|
|
633
|
+
if (installError) {
|
|
634
|
+
if (isJson) {
|
|
635
|
+
process.stdout.write(
|
|
636
|
+
`${JSON.stringify({
|
|
637
|
+
schema_version: 1,
|
|
638
|
+
command: 'init',
|
|
639
|
+
mode: 'dry-run',
|
|
640
|
+
status: 'error',
|
|
641
|
+
error: installError.message,
|
|
642
|
+
})}\n`,
|
|
643
|
+
)
|
|
644
|
+
console.error(`❌ Init dry-run failed: ${installError.message}`)
|
|
645
|
+
} else {
|
|
646
|
+
console.error(
|
|
647
|
+
`${S.installFailed(installError.message)}\n${S.failHintNoMcp}\n${S.failHintForce}`,
|
|
648
|
+
)
|
|
434
649
|
}
|
|
435
|
-
|
|
436
|
-
|
|
650
|
+
// No record for a thrown failure: the error itself is the explanation,
|
|
651
|
+
// and a run that failed has nothing to remember beyond its message.
|
|
652
|
+
process.exitCode = 1
|
|
653
|
+
return
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (savePlanPath !== null && result?.reason === 'plan') {
|
|
657
|
+
try {
|
|
658
|
+
const artifact = createPlanArtifact({
|
|
659
|
+
target: result.target,
|
|
660
|
+
packageRoot: ROOT,
|
|
661
|
+
packageVersion: version,
|
|
662
|
+
plannedAt: planTimestamp,
|
|
663
|
+
artifactPath: savePlanPath,
|
|
664
|
+
options: {
|
|
665
|
+
clean: forceReinstall,
|
|
666
|
+
components,
|
|
667
|
+
version: result.openCodeVersion,
|
|
668
|
+
isProject,
|
|
669
|
+
model: modelOpt,
|
|
670
|
+
smallModel: smallModelOpt,
|
|
671
|
+
preset: presetOpt,
|
|
672
|
+
mergeDevConfig: mergeDevConfigOpt,
|
|
673
|
+
},
|
|
674
|
+
files: result.files,
|
|
675
|
+
snapshots: result.snapshots,
|
|
676
|
+
})
|
|
677
|
+
savePlanArtifact(savePlanPath, artifact)
|
|
678
|
+
} catch (error) {
|
|
679
|
+
if (!isJson) throw error
|
|
680
|
+
process.stdout.write(
|
|
681
|
+
`${JSON.stringify({
|
|
682
|
+
schema_version: 1,
|
|
683
|
+
command: 'init',
|
|
684
|
+
mode: 'dry-run',
|
|
685
|
+
status: 'error',
|
|
686
|
+
error: error.message,
|
|
687
|
+
})}\n`,
|
|
688
|
+
)
|
|
689
|
+
console.error(`❌ Could not save reviewed install plan: ${error.message}`)
|
|
690
|
+
process.exitCode = 1
|
|
691
|
+
return
|
|
692
|
+
}
|
|
693
|
+
if (!isJson) console.log(`Reviewed plan saved to ${path.resolve(savePlanPath)} (mode 0600).`)
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
if (isJson) {
|
|
697
|
+
const files = result.files ?? []
|
|
698
|
+
const totals = { create: 0, update: 0, remove: 0, unchanged: 0, conflict: 0 }
|
|
699
|
+
for (const file of files) {
|
|
700
|
+
if (Object.hasOwn(totals, file.action)) totals[file.action] += 1
|
|
701
|
+
}
|
|
702
|
+
const mcpServers = result.mcpServers ?? []
|
|
703
|
+
process.stdout.write(
|
|
704
|
+
`${JSON.stringify({
|
|
705
|
+
schema_version: 1,
|
|
706
|
+
command: 'init',
|
|
707
|
+
mode: 'dry-run',
|
|
708
|
+
status: 'planned',
|
|
709
|
+
target: result.target,
|
|
710
|
+
open_code_version: result.openCodeVersion,
|
|
711
|
+
advisories: [
|
|
712
|
+
...(result.versionAssumed
|
|
713
|
+
? [
|
|
714
|
+
'The OpenCode host generation could not be detected; this plan assumes V1 ' +
|
|
715
|
+
'and may diverge from the apply. Pass --opencode-version v1|v2 to pin it.',
|
|
716
|
+
]
|
|
717
|
+
: []),
|
|
718
|
+
// Warnings printed in text mode are suppressed by --quiet, so the
|
|
719
|
+
// machine-readable plan carries them too (e.g. a sibling
|
|
720
|
+
// opencode.jsonc the installer neither reads nor writes).
|
|
721
|
+
...(result.configAdvisories ?? []),
|
|
722
|
+
],
|
|
723
|
+
// A V2 plan carries the same capability facts the text notice prints:
|
|
724
|
+
// what the generation registers, what it does not (the static seed),
|
|
725
|
+
// and whether the written plugin entry can receive `options` at all.
|
|
726
|
+
v2_capabilities: result.v2Capabilities ?? null,
|
|
727
|
+
plugin_options: result.pluginOptions ?? null,
|
|
728
|
+
totals,
|
|
729
|
+
mcp_servers: mcpServers,
|
|
730
|
+
mcp_server_count: mcpServers.length,
|
|
731
|
+
files: files.map(({ path: filePath, action, bytes }) => ({
|
|
732
|
+
path: path.relative(result.target, filePath) || '.',
|
|
733
|
+
action,
|
|
734
|
+
bytes,
|
|
735
|
+
})),
|
|
736
|
+
saved_plan: savePlanPath ? path.resolve(savePlanPath) : null,
|
|
737
|
+
})}\n`,
|
|
738
|
+
)
|
|
739
|
+
return
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// Beta 11 Setup phases 3-4: a run that did NOT apply (declined /
|
|
743
|
+
// unauthorized / drift) must never print a success banner. Exit codes:
|
|
744
|
+
// 0 ok / no-apply · 2 apply-requested-without-authorization · 3 drift
|
|
745
|
+
// 130 canceled · 1 failure (thrown above).
|
|
746
|
+
if (result?.applied === false) {
|
|
747
|
+
if (!isDryRun) {
|
|
748
|
+
// The installer already printed the ONE line for this outcome naming
|
|
749
|
+
// its reason (cancel point / decline / not-authorized). Printing
|
|
750
|
+
// another here is what made a cancel appear twice on two paths. All
|
|
751
|
+
// that is left is to make the DECISION survive the terminal.
|
|
752
|
+
//
|
|
753
|
+
// Gate refusals (`not-authorized`, `drift`) are deliberately NOT
|
|
754
|
+
// recorded: those runs are refused before anything is written, and
|
|
755
|
+
// "an unauthorized run writes nothing" is a guarantee of this
|
|
756
|
+
// installer, not an accident. They still print their own reason and
|
|
757
|
+
// their own exit code.
|
|
758
|
+
if (result.reason === 'canceled' || result.reason === 'declined') {
|
|
759
|
+
recordRun({
|
|
760
|
+
status: result.reason,
|
|
761
|
+
reason: result.reason,
|
|
762
|
+
cancelPoint: result.cancelPoint ?? null,
|
|
763
|
+
applied: false,
|
|
764
|
+
target: result.target,
|
|
765
|
+
})
|
|
766
|
+
}
|
|
767
|
+
process.exit(resolveInstallExitCode(result, isDryRun))
|
|
768
|
+
}
|
|
769
|
+
// Dry-run preview: report honestly instead of the "installed!" banner.
|
|
770
|
+
console.log('')
|
|
771
|
+
console.log(` ${S.dryRunNothingWritten}`)
|
|
772
|
+
return
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// Applied: record it, so the next run can tell an apply from a cancel or a
|
|
776
|
+
// decline without reading install-state.json (written only on apply).
|
|
777
|
+
if (!isDryRun) {
|
|
778
|
+
recordRun({
|
|
779
|
+
status: 'applied',
|
|
780
|
+
reason: 'applied',
|
|
781
|
+
applied: true,
|
|
782
|
+
target: result?.target,
|
|
783
|
+
})
|
|
784
|
+
// The interrupt handler describes an install that was in flight. It must
|
|
785
|
+
// not outlive it: `--doctor` runs AFTER this point, and a Ctrl-C there
|
|
786
|
+
// would otherwise rewrite a completed install as canceled/applied:false
|
|
787
|
+
// and print "nothing was applied".
|
|
788
|
+
onInterrupt.deactivate()
|
|
437
789
|
}
|
|
438
790
|
|
|
439
791
|
if (runDoctor && !isDryRun) {
|
|
440
792
|
console.log('')
|
|
441
793
|
console.log(` ${S.runningHealthCheck}`)
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
794
|
+
const doctorStartedAt = Date.now()
|
|
795
|
+
const { spawnSync } = await import('node:child_process')
|
|
796
|
+
const doctorScript = path.join(ROOT, 'scripts', 'doctor.mjs')
|
|
797
|
+
const doctor = spawnSync(process.execPath, [doctorScript], { stdio: 'inherit', cwd: ROOT })
|
|
798
|
+
const doctorSeconds = ((Date.now() - doctorStartedAt) / 1000).toFixed(1)
|
|
799
|
+
// Never leave "Running health check..." as the last word: report the
|
|
800
|
+
// outcome and duration, and propagate the child's exit code so CI sees
|
|
801
|
+
// the failure instead of a silent zero.
|
|
802
|
+
if (doctor.error) {
|
|
803
|
+
console.error(` ⚠️ Could not run doctor.mjs: ${doctor.error.message}`)
|
|
804
|
+
process.exitCode = 1
|
|
805
|
+
} else if (doctor.status === 0) {
|
|
806
|
+
console.log(` ${S.healthCheckFinished(doctorSeconds, 0)}`)
|
|
807
|
+
} else {
|
|
808
|
+
const status = doctor.status ?? 1
|
|
809
|
+
console.error(` ${S.healthCheckExit(doctorSeconds, status)}`)
|
|
810
|
+
process.exitCode = status
|
|
448
811
|
}
|
|
449
812
|
}
|
|
450
813
|
|