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
|
@@ -4,8 +4,61 @@
|
|
|
4
4
|
|
|
5
5
|
import { execSync } from 'node:child_process'
|
|
6
6
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs'
|
|
7
|
-
import { isAbsolute, join, resolve } from 'node:path'
|
|
7
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
8
|
+
import { sanitizeNpmEnv } from '../sync-tui.mjs'
|
|
9
|
+
import { step } from './cli-ui.mjs'
|
|
10
|
+
import { ACTIONS, recordChange, recordRemovalTree, removeReviewedTree, snapshot } from './plan.mjs'
|
|
8
11
|
import { ROOT, writeIfChanged } from './shared.mjs'
|
|
12
|
+
import { strings } from './strings.mjs'
|
|
13
|
+
import {
|
|
14
|
+
assertNoSymlinkAncestors,
|
|
15
|
+
assertPathWithin,
|
|
16
|
+
assertSafeRemoval,
|
|
17
|
+
verifyPathRemoved,
|
|
18
|
+
} from './verify.mjs'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Upper bound for the copied plugin's `npm ci`. Dependency installation is a
|
|
22
|
+
* bounded operation; without a timeout a hung registry leaves `init` blocked
|
|
23
|
+
* forever with no output to explain it.
|
|
24
|
+
*/
|
|
25
|
+
export const NPM_CI_TIMEOUT_MS = 180_000
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Run `npm ci` for a copied plugin directory.
|
|
29
|
+
*
|
|
30
|
+
* Two guarantees the install path needs and a bare `execSync` does not give:
|
|
31
|
+
* - the npm environment is sanitized. When Pantheon itself is installed with
|
|
32
|
+
* `npm install -g`, npm injects `npm_config_global`/`npm_config_prefix` into
|
|
33
|
+
* the lifecycle env and a nested `npm ci` aborts with ECIGLOBAL;
|
|
34
|
+
* - the call is bounded by {@link NPM_CI_TIMEOUT_MS} and reports a timeout as
|
|
35
|
+
* an actionable error instead of a silent hang.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} cwd - directory holding the copied package.json + lockfile
|
|
38
|
+
* @param {{ timeoutMs?: number, env?: NodeJS.ProcessEnv }} [options]
|
|
39
|
+
*/
|
|
40
|
+
export function runNpmCi(cwd, { timeoutMs = NPM_CI_TIMEOUT_MS, env = sanitizeNpmEnv() } = {}) {
|
|
41
|
+
try {
|
|
42
|
+
execSync('npm ci --omit=dev --no-audit --no-fund', {
|
|
43
|
+
cwd,
|
|
44
|
+
stdio: 'pipe',
|
|
45
|
+
env,
|
|
46
|
+
timeout: timeoutMs,
|
|
47
|
+
})
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (err?.signal || err?.code === 'ETIMEDOUT') {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`TUI dependency install timed out after ${Math.round(timeoutMs / 1000)}s in ${cwd}. ` +
|
|
52
|
+
'Run `npm ci --omit=dev` there manually and re-run init.',
|
|
53
|
+
{ cause: err },
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
const detail = err?.stderr?.toString?.().trim()
|
|
57
|
+
throw new Error(`TUI dependency install failed in ${cwd}${detail ? `: ${detail}` : ''}`, {
|
|
58
|
+
cause: err,
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
9
62
|
|
|
10
63
|
/**
|
|
11
64
|
* Copy a plugin's runtime payload (the root TUI loader, bundled dist/*,
|
|
@@ -17,18 +70,50 @@ import { ROOT, writeIfChanged } from './shared.mjs'
|
|
|
17
70
|
* @param {object} [options]
|
|
18
71
|
* @param {boolean} [options.dryRun=false] - If true, don't write files
|
|
19
72
|
* @param {'v1'|'v2'} [options.version='v1'] - Host plugin generation
|
|
20
|
-
* @
|
|
73
|
+
* @param {(change: object) => void} [options.recorder] - optional change recorder for preview
|
|
74
|
+
* @param {Set<string>|null} [options.reviewedRemovals] - paths approved by the current plan
|
|
75
|
+
* @param {Map<string, object>|null} [options.reviewedSnapshots] - pre-apply path snapshots
|
|
76
|
+
* @returns {{ created: number, skipped: number, errors: number, problems: string[] }}
|
|
21
77
|
*/
|
|
22
|
-
export function copyPluginFiles(
|
|
23
|
-
|
|
78
|
+
export function copyPluginFiles(
|
|
79
|
+
srcDir,
|
|
80
|
+
dstDir,
|
|
81
|
+
{
|
|
82
|
+
dryRun = false,
|
|
83
|
+
version = 'v1',
|
|
84
|
+
recorder = null,
|
|
85
|
+
reviewedRemovals = null,
|
|
86
|
+
reviewedSnapshots = null,
|
|
87
|
+
} = {},
|
|
88
|
+
) {
|
|
89
|
+
const result = { created: 0, skipped: 0, errors: 0, problems: [] }
|
|
90
|
+
const distDir = join(dstDir, 'dist')
|
|
91
|
+
// The root loader (tui.ts / tui-v2.ts) is only a re-export of the compiled
|
|
92
|
+
// bundle. Writing it while the bundle is missing installs a plugin the host
|
|
93
|
+
// loads and then fails to resolve — a silent broken install, so refuse.
|
|
94
|
+
const requiredBundle = join(srcDir, 'dist', version === 'v2' ? 'tui-v2.js' : 'tui.js')
|
|
95
|
+
const bundleAvailable = existsSync(requiredBundle)
|
|
96
|
+
if (!bundleAvailable) {
|
|
97
|
+
result.errors++
|
|
98
|
+
result.problems.push(
|
|
99
|
+
`TUI bundle not found in the package: ${requiredBundle} — refusing to install a ` +
|
|
100
|
+
'plugin entrypoint that re-exports a missing bundle. Reinstall pantheon-opencode.',
|
|
101
|
+
)
|
|
102
|
+
}
|
|
24
103
|
|
|
25
|
-
if (!dryRun)
|
|
26
|
-
|
|
104
|
+
if (!dryRun) {
|
|
105
|
+
assertNoSymlinkAncestors(dstDir)
|
|
106
|
+
mkdirSync(dstDir, { recursive: true })
|
|
107
|
+
assertNoSymlinkAncestors(dstDir)
|
|
108
|
+
assertPathWithin(dstDir, distDir)
|
|
109
|
+
assertNoSymlinkAncestors(distDir)
|
|
110
|
+
mkdirSync(distDir, { recursive: true })
|
|
111
|
+
assertNoSymlinkAncestors(distDir)
|
|
112
|
+
}
|
|
27
113
|
|
|
28
114
|
// Drop legacy raw copies from previous installs (root index.tsx + dist/tui.tsx).
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
rmSync(join(dstDir, 'dist', 'tui.tsx'), { force: true })
|
|
115
|
+
for (const legacyPath of [join(dstDir, 'index.tsx'), join(distDir, 'tui.tsx')]) {
|
|
116
|
+
removeLegacyFile(legacyPath, dstDir, { dryRun, recorder, reviewedRemovals, reviewedSnapshots })
|
|
32
117
|
}
|
|
33
118
|
|
|
34
119
|
// Copy dist/* files
|
|
@@ -36,7 +121,9 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
36
121
|
if (existsSync(distSrc)) {
|
|
37
122
|
for (const f of readdirSync(distSrc)) {
|
|
38
123
|
const c = readFileSync(join(distSrc, f), 'utf8')
|
|
39
|
-
const
|
|
124
|
+
const destination = join(distDir, f)
|
|
125
|
+
assertPathWithin(dstDir, destination)
|
|
126
|
+
const status = writeIfChanged(destination, c, dryRun, { recorder })
|
|
40
127
|
if (status === 'created') result.created++
|
|
41
128
|
else result.skipped++
|
|
42
129
|
}
|
|
@@ -53,6 +140,7 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
53
140
|
join(dstDir, 'package.json'),
|
|
54
141
|
`${JSON.stringify(packageJson, null, 2)}\n`,
|
|
55
142
|
dryRun,
|
|
143
|
+
{ recorder },
|
|
56
144
|
)
|
|
57
145
|
if (pkgStatus === 'created') result.created++
|
|
58
146
|
else result.skipped++
|
|
@@ -60,11 +148,17 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
60
148
|
|
|
61
149
|
// Each host generation receives its own root loader and compiled bundle.
|
|
62
150
|
const tuiEntrySrc = join(srcDir, version === 'v2' ? 'tui-v2.ts' : 'tui.ts')
|
|
63
|
-
if (existsSync(tuiEntrySrc)) {
|
|
151
|
+
if (!existsSync(tuiEntrySrc)) {
|
|
152
|
+
result.errors++
|
|
153
|
+
result.problems.push(
|
|
154
|
+
`TUI entrypoint not found in the package: ${tuiEntrySrc} — reinstall pantheon-opencode.`,
|
|
155
|
+
)
|
|
156
|
+
} else if (bundleAvailable) {
|
|
64
157
|
const entryStatus = writeIfChanged(
|
|
65
158
|
join(dstDir, 'tui.ts'),
|
|
66
159
|
readFileSync(tuiEntrySrc, 'utf8'),
|
|
67
160
|
dryRun,
|
|
161
|
+
{ recorder },
|
|
68
162
|
)
|
|
69
163
|
if (entryStatus === 'created') result.created++
|
|
70
164
|
else result.skipped++
|
|
@@ -77,11 +171,17 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
77
171
|
v2ServerDestination,
|
|
78
172
|
readFileSync(v2ServerEntry, 'utf8'),
|
|
79
173
|
dryRun,
|
|
174
|
+
{ recorder },
|
|
80
175
|
)
|
|
81
176
|
if (entryStatus === 'created') result.created++
|
|
82
177
|
else result.skipped++
|
|
83
|
-
} else
|
|
84
|
-
|
|
178
|
+
} else {
|
|
179
|
+
removeLegacyFile(v2ServerDestination, dstDir, {
|
|
180
|
+
dryRun,
|
|
181
|
+
recorder,
|
|
182
|
+
reviewedRemovals,
|
|
183
|
+
reviewedSnapshots,
|
|
184
|
+
})
|
|
85
185
|
}
|
|
86
186
|
|
|
87
187
|
// Copy the lockfile so dependency installation is reproducible. A missing
|
|
@@ -92,6 +192,7 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
92
192
|
join(dstDir, 'package-lock.json'),
|
|
93
193
|
readFileSync(lockSrc, 'utf8'),
|
|
94
194
|
dryRun,
|
|
195
|
+
{ recorder },
|
|
95
196
|
)
|
|
96
197
|
if (lockStatus === 'created') result.created++
|
|
97
198
|
else result.skipped++
|
|
@@ -100,6 +201,45 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
100
201
|
return result
|
|
101
202
|
}
|
|
102
203
|
|
|
204
|
+
function removeLegacyFile(
|
|
205
|
+
filePath,
|
|
206
|
+
rootDir,
|
|
207
|
+
{ dryRun, recorder, reviewedRemovals, reviewedSnapshots },
|
|
208
|
+
) {
|
|
209
|
+
assertSafeRemoval(rootDir, filePath)
|
|
210
|
+
const present = existsSync(filePath)
|
|
211
|
+
// A legacy path absent from BOTH source and target is not an operation: the
|
|
212
|
+
// apply skips it silently, so the preview must not invent an entry for it.
|
|
213
|
+
// Recording `unchanged` here listed phantom paths (`index.tsx`,
|
|
214
|
+
// `dist/tui.tsx`, the V1 `index.ts` shim) with `before.exists: false`.
|
|
215
|
+
if (!present) return
|
|
216
|
+
if (dryRun) {
|
|
217
|
+
recordChange({ path: filePath, action: ACTIONS.REMOVE, bytes: 0, scored: false }, recorder)
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const normalizedPath = resolve(filePath)
|
|
222
|
+
if (reviewedRemovals && !reviewedRemovals.has(normalizedPath)) {
|
|
223
|
+
throw new Error(`Refusing unreviewed plugin removal: ${filePath}`)
|
|
224
|
+
}
|
|
225
|
+
const expected = reviewedSnapshots?.get(normalizedPath)
|
|
226
|
+
if (reviewedSnapshots && (!expected || !sameSnapshot(snapshot(filePath), expected))) {
|
|
227
|
+
throw new Error(`Plugin removal target drifted after review: ${filePath}`)
|
|
228
|
+
}
|
|
229
|
+
rmSync(filePath, { force: true })
|
|
230
|
+
verifyPathRemoved(filePath)
|
|
231
|
+
recordChange({ path: filePath, action: ACTIONS.REMOVE, bytes: 0, scored: false }, recorder)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function sameSnapshot(left, right) {
|
|
235
|
+
return (
|
|
236
|
+
left.exists === right.exists &&
|
|
237
|
+
left.sha256 === right.sha256 &&
|
|
238
|
+
left.size === right.size &&
|
|
239
|
+
left.mode === right.mode
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
|
|
103
243
|
/**
|
|
104
244
|
* Install a plugin from source to destination.
|
|
105
245
|
* @param {string} srcDir - Source plugin directory (e.g. ROOT/src/plugins/tui)
|
|
@@ -107,27 +247,70 @@ export function copyPluginFiles(srcDir, dstDir, { dryRun = false, version = 'v1'
|
|
|
107
247
|
* @param {object} [options]
|
|
108
248
|
* @param {boolean} [options.dryRun=false] - If true, don't write files
|
|
109
249
|
* @param {boolean} [options.clean=false] - If true, remove existing before install
|
|
110
|
-
* @
|
|
250
|
+
* @param {(change: object) => void} [options.recorder] - optional change recorder for preview
|
|
251
|
+
* @returns {{ created: number, skipped: number, errors: number, problems: string[] }}
|
|
111
252
|
*/
|
|
112
253
|
export function installPlugin(
|
|
113
254
|
srcDir,
|
|
114
255
|
dstDir,
|
|
115
|
-
{
|
|
256
|
+
{
|
|
257
|
+
dryRun = false,
|
|
258
|
+
clean = false,
|
|
259
|
+
version = 'v1',
|
|
260
|
+
recorder = null,
|
|
261
|
+
reviewedRemovals = null,
|
|
262
|
+
reviewedSnapshots = null,
|
|
263
|
+
} = {},
|
|
116
264
|
) {
|
|
117
|
-
const result = { created: 0, skipped: 0, errors: 0 }
|
|
265
|
+
const result = { created: 0, skipped: 0, errors: 0, problems: [] }
|
|
266
|
+
const cleanTargetExisted = clean && existsSync(dstDir)
|
|
118
267
|
|
|
119
|
-
|
|
120
|
-
|
|
268
|
+
assertNoSymlinkAncestors(dstDir)
|
|
269
|
+
if (cleanTargetExisted) {
|
|
270
|
+
assertSafeRemoval(dirname(dstDir), dstDir)
|
|
271
|
+
if (dryRun) {
|
|
272
|
+
recordRemovalTree(dstDir, recorder)
|
|
273
|
+
} else {
|
|
274
|
+
removeReviewedTree(dstDir, reviewedRemovals, reviewedSnapshots)
|
|
275
|
+
}
|
|
121
276
|
}
|
|
122
277
|
|
|
123
|
-
const copyResult = copyPluginFiles(srcDir, dstDir, {
|
|
278
|
+
const copyResult = copyPluginFiles(srcDir, dstDir, {
|
|
279
|
+
dryRun,
|
|
280
|
+
version,
|
|
281
|
+
recorder,
|
|
282
|
+
reviewedRemovals,
|
|
283
|
+
reviewedSnapshots,
|
|
284
|
+
})
|
|
124
285
|
result.created += copyResult.created
|
|
125
286
|
result.skipped += copyResult.skipped
|
|
287
|
+
result.errors += copyResult.errors
|
|
288
|
+
result.problems.push(...copyResult.problems)
|
|
289
|
+
if (cleanTargetExisted) {
|
|
290
|
+
// The clean pass removes these directories before rebuilding their files;
|
|
291
|
+
// keep the net plan truthful while the separate removal review still lists
|
|
292
|
+
// every path actually cleared.
|
|
293
|
+
recordChange({ path: dstDir, action: ACTIONS.UNCHANGED, bytes: 0, scored: false }, recorder)
|
|
294
|
+
if (existsSync(join(srcDir, 'dist'))) {
|
|
295
|
+
recordChange(
|
|
296
|
+
{ path: join(dstDir, 'dist'), action: ACTIONS.UNCHANGED, bytes: 0, scored: false },
|
|
297
|
+
recorder,
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
126
301
|
|
|
127
302
|
// Install plugin dependencies (@opentui/core, @opentui/solid, solid-js).
|
|
128
|
-
// Lockfile installation is the only accepted dependency path.
|
|
129
|
-
|
|
130
|
-
|
|
303
|
+
// Lockfile installation is the only accepted dependency path. A copy that
|
|
304
|
+
// already failed its bundle check is not worth installing dependencies for.
|
|
305
|
+
if (!dryRun && result.errors === 0) {
|
|
306
|
+
const depsStep = step(strings().installingTuiDeps)
|
|
307
|
+
try {
|
|
308
|
+
runNpmCi(dstDir)
|
|
309
|
+
} catch (err) {
|
|
310
|
+
depsStep(false)
|
|
311
|
+
throw err
|
|
312
|
+
}
|
|
313
|
+
depsStep(true)
|
|
131
314
|
}
|
|
132
315
|
|
|
133
316
|
return result
|
|
@@ -141,7 +324,7 @@ export function installPlugin(
|
|
|
141
324
|
*/
|
|
142
325
|
export function installPluginDependencies(pluginDir, { dryRun = false } = {}) {
|
|
143
326
|
if (dryRun) return
|
|
144
|
-
|
|
327
|
+
runNpmCi(pluginDir)
|
|
145
328
|
}
|
|
146
329
|
|
|
147
330
|
/**
|
|
@@ -150,9 +333,10 @@ export function installPluginDependencies(pluginDir, { dryRun = false } = {}) {
|
|
|
150
333
|
* @param {string} pluginId - Plugin identifier string
|
|
151
334
|
* @param {object} [options]
|
|
152
335
|
* @param {boolean} [options.dryRun=false]
|
|
336
|
+
* @param {(change: object) => void} [options.recorder] - optional change recorder for preview
|
|
153
337
|
* @returns {'created'|'skipped'}
|
|
154
338
|
*/
|
|
155
|
-
export function registerPlugin(tuiJsonPath, pluginId, { dryRun = false } = {}) {
|
|
339
|
+
export function registerPlugin(tuiJsonPath, pluginId, { dryRun = false, recorder = null } = {}) {
|
|
156
340
|
let tuiConfig = { plugin: [] }
|
|
157
341
|
if (existsSync(tuiJsonPath)) {
|
|
158
342
|
try {
|
|
@@ -168,7 +352,7 @@ export function registerPlugin(tuiJsonPath, pluginId, { dryRun = false } = {}) {
|
|
|
168
352
|
tuiConfig.plugin.push(pluginId)
|
|
169
353
|
}
|
|
170
354
|
const tuiContent = `${JSON.stringify(tuiConfig, null, 2)}\n`
|
|
171
|
-
return writeIfChanged(tuiJsonPath, tuiContent, dryRun)
|
|
355
|
+
return writeIfChanged(tuiJsonPath, tuiContent, dryRun, { recorder })
|
|
172
356
|
}
|
|
173
357
|
|
|
174
358
|
/**
|
|
@@ -256,12 +440,14 @@ export function staleTuiRefs(pluginArray, knownPantheonPaths = []) {
|
|
|
256
440
|
* @param {string} pluginId - Plugin to unregister
|
|
257
441
|
* @param {object} [options]
|
|
258
442
|
* @param {boolean} [options.dryRun=false]
|
|
443
|
+
* @param {string[]} [options.knownPantheonPaths=[]]
|
|
444
|
+
* @param {(change: object) => void} [options.recorder] - optional change recorder for preview
|
|
259
445
|
* @returns {'created'|'skipped'}
|
|
260
446
|
*/
|
|
261
447
|
export function unregisterPlugin(
|
|
262
448
|
tuiJsonPath,
|
|
263
449
|
pluginId,
|
|
264
|
-
{ dryRun = false, knownPantheonPaths = [] } = {},
|
|
450
|
+
{ dryRun = false, knownPantheonPaths = [], recorder = null } = {},
|
|
265
451
|
) {
|
|
266
452
|
if (!existsSync(tuiJsonPath)) {
|
|
267
453
|
// Nothing to clean — and never create an empty tui.json in a location
|
|
@@ -292,5 +478,6 @@ export function unregisterPlugin(
|
|
|
292
478
|
return !isPantheonTuiRef(ref, knownPantheonPaths)
|
|
293
479
|
})
|
|
294
480
|
const tuiContent = `${JSON.stringify(tuiConfig, null, 2)}\n`
|
|
295
|
-
|
|
481
|
+
// Stale-ref cleanup is not part of the install summary, so record it unscored.
|
|
482
|
+
return writeIfChanged(tuiJsonPath, tuiContent, dryRun, { recorder, scored: false })
|
|
296
483
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run-record.mjs — the one-line record of what the LAST `init` run did.
|
|
3
|
+
*
|
|
4
|
+
* WHY A SEPARATE FILE, AND NOT `install-state.json`: that manifest is written
|
|
5
|
+
* only by an APPLY, so it answers "what is installed" and cannot answer "what
|
|
6
|
+
* did the previous run decide". A canceled or declined run previously left no
|
|
7
|
+
* trace at all: the user saw a line scroll past, and a re-run could not tell
|
|
8
|
+
* whether the last attempt was interrupted, refused at the review prompt, or
|
|
9
|
+
* never authorized. This record is written on every non-preview termination,
|
|
10
|
+
* including the ones that apply nothing, so the answer survives the terminal.
|
|
11
|
+
*
|
|
12
|
+
* It is deliberately NOT an install artifact:
|
|
13
|
+
* - it is never registered in the file inventory, so it is not "owned" and
|
|
14
|
+
* uninstall/reconcile do not treat it as installed content;
|
|
15
|
+
* - it never replaces, mirrors or edits `install-state.json`;
|
|
16
|
+
* - a failure to write it never changes the exit code (see the caller): an
|
|
17
|
+
* explanation is worth having, not worth failing a run for.
|
|
18
|
+
*
|
|
19
|
+
* No secrets and no config contents are recorded — status, reason, cancel
|
|
20
|
+
* point, mode, version, timestamp and target only.
|
|
21
|
+
*
|
|
22
|
+
* @module run-record
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { mkdirSync, readFileSync } from 'node:fs'
|
|
26
|
+
import { join } from 'node:path'
|
|
27
|
+
import { writeFileAtomically } from './verify.mjs'
|
|
28
|
+
|
|
29
|
+
/** Directory inside the install target that holds Pantheon bookkeeping. */
|
|
30
|
+
export const RUN_RECORD_DIR = '.pantheon'
|
|
31
|
+
|
|
32
|
+
/** File name of the last-run record. */
|
|
33
|
+
export const RUN_RECORD_FILENAME = 'last-run.json'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Absolute path of the record for an install target.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} target
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function runRecordPath(target) {
|
|
42
|
+
return join(target, RUN_RECORD_DIR, RUN_RECORD_FILENAME)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Build the record. Pure, so the shape is testable without touching disk.
|
|
47
|
+
*
|
|
48
|
+
* @param {{
|
|
49
|
+
* status: string,
|
|
50
|
+
* reason?: string|null,
|
|
51
|
+
* cancelPoint?: string|null,
|
|
52
|
+
* mode: 'apply'|'dry-run',
|
|
53
|
+
* applied: boolean,
|
|
54
|
+
* pantheonVersion?: string|null,
|
|
55
|
+
* at?: string,
|
|
56
|
+
* }} input
|
|
57
|
+
* @returns {object}
|
|
58
|
+
*/
|
|
59
|
+
export function buildRunRecord({
|
|
60
|
+
status,
|
|
61
|
+
reason = null,
|
|
62
|
+
cancelPoint = null,
|
|
63
|
+
mode,
|
|
64
|
+
applied,
|
|
65
|
+
pantheonVersion = null,
|
|
66
|
+
at = new Date().toISOString(),
|
|
67
|
+
}) {
|
|
68
|
+
const where = cancelPoint === null ? '' : ` at ${cancelPoint}`
|
|
69
|
+
return {
|
|
70
|
+
schema_version: 1,
|
|
71
|
+
command: 'init',
|
|
72
|
+
status,
|
|
73
|
+
reason,
|
|
74
|
+
cancel_point: cancelPoint,
|
|
75
|
+
mode,
|
|
76
|
+
applied,
|
|
77
|
+
pantheon_version: pantheonVersion,
|
|
78
|
+
at,
|
|
79
|
+
summary: `init ${status}${where} — ${applied ? 'changes were applied' : 'nothing was applied'} (${at})`,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Persist the record. Never throws: a bookkeeping failure is reported to the
|
|
85
|
+
* caller, which prints it as a warning instead of hiding it.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} target
|
|
88
|
+
* @param {object} record
|
|
89
|
+
* @returns {{written: boolean, path: string, error: string|null}}
|
|
90
|
+
*/
|
|
91
|
+
export function writeRunRecord(target, record) {
|
|
92
|
+
const path = runRecordPath(target)
|
|
93
|
+
try {
|
|
94
|
+
mkdirSync(join(target, RUN_RECORD_DIR), { recursive: true })
|
|
95
|
+
writeFileAtomically(path, `${JSON.stringify(record, null, 2)}\n`)
|
|
96
|
+
return { written: true, path, error: null }
|
|
97
|
+
} catch (err) {
|
|
98
|
+
return { written: false, path, error: err instanceof Error ? err.message : String(err) }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Read the previous run's record, or null when there is none / it is unreadable.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} target
|
|
106
|
+
* @returns {object|null}
|
|
107
|
+
*/
|
|
108
|
+
export function readRunRecord(target) {
|
|
109
|
+
try {
|
|
110
|
+
const parsed = JSON.parse(readFileSync(runRecordPath(target), 'utf8'))
|
|
111
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null
|
|
112
|
+
} catch {
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
}
|