pantheon-opencode 1.6.0-beta.8 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/AGENTS.global.md +118 -0
  2. package/AGENTS.md +18 -168
  3. package/CHANGELOG.md +126 -346
  4. package/README.md +83 -608
  5. package/README.pt-BR.md +120 -345
  6. package/bin/pantheon-init.mjs +366 -132
  7. package/commands/pantheon-audit.md +7 -1
  8. package/commands/pantheon-consolidate.md +1 -1
  9. package/commands/pantheon-deepwork.md +14 -3
  10. package/commands/pantheon-focus.md +17 -0
  11. package/commands/pantheon-vision.md +61 -12
  12. package/package.json +19 -11
  13. package/plugin.json +1 -1
  14. package/pyproject.toml +6 -2
  15. package/scripts/_pantheon_paths.py +24 -0
  16. package/scripts/build-agents-md.mjs +368 -69
  17. package/scripts/changelog-merge.mjs +161 -0
  18. package/scripts/check-plugin-v2-coverage.mjs +11 -8
  19. package/scripts/docs-check-changelog.mjs +204 -0
  20. package/scripts/docs-link-check.mjs +314 -0
  21. package/scripts/docs-media.mjs +157 -0
  22. package/scripts/doctor.mjs +828 -40
  23. package/scripts/install/agents-md.mjs +2 -2
  24. package/scripts/install/backup.mjs +648 -0
  25. package/scripts/install/cli-ui.mjs +303 -72
  26. package/scripts/install/component-selection.mjs +61 -0
  27. package/scripts/install/config-migration.mjs +583 -27
  28. package/scripts/install/exit-codes.mjs +26 -0
  29. package/scripts/install/file-inventory.mjs +555 -0
  30. package/scripts/install/health-check.mjs +31 -25
  31. package/scripts/install/interactive.mjs +78 -383
  32. package/scripts/install/migrate.mjs +49 -25
  33. package/scripts/install/model-picker.mjs +218 -250
  34. package/scripts/install/opencode-version.mjs +83 -21
  35. package/scripts/install/opencode.mjs +1465 -180
  36. package/scripts/install/plan-artifact.mjs +517 -0
  37. package/scripts/install/plan.mjs +475 -0
  38. package/scripts/install/plugin.mjs +251 -30
  39. package/scripts/install/prompt-result.mjs +2 -0
  40. package/scripts/install/shared.mjs +256 -99
  41. package/scripts/install/state.mjs +63 -8
  42. package/scripts/install/strings.mjs +60 -4
  43. package/scripts/install/venv.mjs +90 -47
  44. package/scripts/install/verify.mjs +128 -0
  45. package/scripts/install/vision-prompt.mjs +173 -0
  46. package/scripts/install-mcp.mjs +2 -2
  47. package/scripts/manifest-inventory.mjs +49 -3
  48. package/scripts/mcp_persistence.py +1535 -1050
  49. package/scripts/memory_mcp.py +12 -843
  50. package/scripts/node-engine-policy.mjs +85 -0
  51. package/scripts/package-evidence.mjs +10 -2
  52. package/scripts/postinstall.mjs +26 -26
  53. package/scripts/probe-pantheon-cost.mjs +118 -19
  54. package/scripts/prune.mjs +9 -3
  55. package/scripts/reconcile.mjs +325 -0
  56. package/scripts/release-gates.mjs +682 -0
  57. package/scripts/restore.mjs +222 -0
  58. package/scripts/run-node-tests.mjs +24 -8
  59. package/scripts/sync-artifacts.mjs +20 -7
  60. package/scripts/sync-tui.mjs +29 -4
  61. package/scripts/test-opencode-v2-sandbox.sh +36 -123
  62. package/scripts/uninstall.mjs +369 -34
  63. package/scripts/update.mjs +164 -0
  64. package/scripts/validate-node-engine-policy.mjs +13 -0
  65. package/scripts/version-check.mjs +34 -1
  66. package/scripts/versioning.mjs +23 -3
  67. package/scripts/vision-status.mjs +682 -0
  68. package/skills-lock.json +8 -8
  69. package/src/agents/aphrodite.md +13 -10
  70. package/src/agents/apollo.md +4 -5
  71. package/src/agents/athena.md +74 -46
  72. package/src/agents/demeter.md +10 -7
  73. package/src/agents/gaia.md +0 -1
  74. package/src/agents/hephaestus.md +4 -3
  75. package/src/agents/hermes.md +10 -9
  76. package/src/agents/iris.md +6 -1
  77. package/src/agents/mnemosyne.md +14 -15
  78. package/src/agents/nyx.md +4 -4
  79. package/src/agents/prometheus.md +12 -11
  80. package/src/agents/talos.md +6 -0
  81. package/src/agents/zeus.md +84 -56
  82. package/src/instructions/agent-return-format.instructions.md +12 -41
  83. package/src/instructions/memory-protocol.instructions.md +5 -11
  84. package/src/instructions/test-economy.instructions.md +12 -0
  85. package/src/instructions/yagni.instructions.md +6 -15
  86. package/src/instructions/zeus-anti-stall.instructions.md +6 -6
  87. package/src/instructions/zeus-communication-rules.instructions.md +6 -6
  88. package/src/instructions/zeus-council-synthesis.instructions.md +11 -12
  89. package/src/instructions/zeus-memory-operations.instructions.md +13 -7
  90. package/src/instructions/zeus-timeout-retry.instructions.md +36 -10
  91. package/src/mcp/_pantheon_paths.py +24 -0
  92. package/src/mcp/mcp_codemap_module.py +86 -18
  93. package/src/mcp/mcp_persistence.py +1535 -1050
  94. package/src/mcp/memory_mcp.py +444 -94
  95. package/src/mcp/pantheon_vision.py +285 -41
  96. package/src/mcp/requirements-mcp.txt +5 -0
  97. package/src/pantheon/context-pruner.ts +541 -0
  98. package/src/pantheon/cost-command.ts +814 -60
  99. package/src/pantheon/goal-loop.ts +11 -8
  100. package/src/pantheon/memory-context.ts +1017 -0
  101. package/src/pantheon/model-agents.ts +19 -0
  102. package/src/pantheon/model-command.ts +218 -56
  103. package/src/pantheon/model-pricing.ts +536 -0
  104. package/src/pantheon/presets.mjs +2 -0
  105. package/src/pantheon/task-result-guard.ts +50 -14
  106. package/src/pantheon/v2-bounded-read.ts +640 -0
  107. package/src/pantheon/v2-delegation-enforce.ts +133 -6
  108. package/src/pantheon/v2-execute-after.ts +135 -24
  109. package/src/pantheon/v2-model-overrides.ts +275 -0
  110. package/src/pantheon/v2-tools.ts +89 -35
  111. package/src/pantheon/v2-unsupported.mjs +2 -3
  112. package/src/pantheon/v2-vision.ts +622 -0
  113. package/src/pantheon/vision-local.ts +531 -0
  114. package/src/pantheon/vision.ts +1160 -115
  115. package/src/plugin-v2.ts +654 -162
  116. package/src/plugin.ts +15 -11
  117. package/src/plugins/tui/dist/tui-v2.d.ts +1036 -0
  118. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -0
  119. package/src/plugins/tui/dist/tui-v2.js +3808 -0
  120. package/src/plugins/tui/dist/tui-v2.js.map +1 -0
  121. package/src/plugins/tui/dist/tui.js +4 -4
  122. package/src/plugins/tui/index-v2.ts +6 -0
  123. package/src/plugins/tui/package-lock.json +5416 -1297
  124. package/src/plugins/tui/package.json +14 -10
  125. package/src/plugins/tui/src/index-v2.tsx +4372 -0
  126. package/src/plugins/tui/src/index.tsx +3 -3
  127. package/src/plugins/tui/src/opencode-v2.d.ts +13 -0
  128. package/src/plugins/tui/tsconfig.typecheck.json +5 -0
  129. package/src/plugins/tui/tsdown.config.ts +2 -2
  130. package/src/plugins/tui/tui-v2.ts +2 -0
  131. package/src/plugins/tui/tui.ts +3 -0
  132. package/src/routing.yml +50 -5
  133. package/src/skills/agent-coordination/SKILL.md +7 -2
  134. package/src/skills/artifact-management/SKILL.md +5 -1
  135. package/src/skills/auto-continue/SKILL.md +14 -6
  136. package/src/skills/codemap/SKILL.md +1 -1
  137. package/src/skills/memory-bank/SKILL.md +21 -13
  138. package/src/skills/session-goal/SKILL.md +14 -15
  139. package/src/skills/spec-driven-development/SKILL.md +3 -1
  140. package/src/skills/worktrees/SKILL.md +30 -11
  141. package/scripts/probe-context-rehydrate.mjs +0 -263
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * restore.mjs — Pantheon exact-restore CLI (Beta 11 Setup, phase 2).
4
+ *
5
+ * Restores a backup set created by the installer back into the config dir,
6
+ * reproducing each file byte-for-byte and re-applying its recorded mode. The
7
+ * restore is itself reversible: the CURRENT state is backed up first.
8
+ *
9
+ * Safety contract:
10
+ * - the backup manifest is verified (hash of every backed-up file) before any
11
+ * restore; a tampered or incomplete set is refused outright;
12
+ * - the backup-vs-current diff is shown BY PATH ONLY (never file contents);
13
+ * - writing requires explicit authorization (`--yes`); a non-TTY run without
14
+ * `--yes` previews and exits without writing.
15
+ *
16
+ * Usage:
17
+ * pantheon-opencode restore [--project] [--from <dir>] [--dry-run] [--yes]
18
+ *
19
+ * Exit codes:
20
+ * 0 = restored (or preview shown with --dry-run)
21
+ * 1 = refused (missing/tampered backup, or no authorization)
22
+ * 2 = usage error
23
+ */
24
+
25
+ import { existsSync } from 'node:fs'
26
+ import { homedir } from 'node:os'
27
+ import { isAbsolute, join, resolve } from 'node:path'
28
+
29
+ import {
30
+ backupRoot,
31
+ createBackupSet,
32
+ isBackupDirName,
33
+ listBackupSets,
34
+ planRestore,
35
+ restoreBackupSet,
36
+ verifyBackupSet,
37
+ } from './install/backup.mjs'
38
+
39
+ /**
40
+ * Resolve the config dir whose `opencode.json` the installer manages.
41
+ * `--project` targets the CWD; otherwise XDG / PANTHEON_HOME.
42
+ * @param {{ project?: boolean }} opts
43
+ * @returns {string}
44
+ */
45
+ export function resolveConfigDir({ project = false } = {}) {
46
+ if (project) return resolve(process.cwd())
47
+ if (process.env.PANTHEON_HOME) return resolve(process.env.PANTHEON_HOME)
48
+ const base = process.env.XDG_CONFIG_HOME || join(homedir(), '.config')
49
+ return join(base, 'opencode')
50
+ }
51
+
52
+ export function parseArgs(argv) {
53
+ const args = { project: false, from: null, dryRun: false, yes: false, help: false }
54
+ for (let i = 0; i < argv.length; i++) {
55
+ const arg = argv[i]
56
+ switch (arg) {
57
+ case '--project':
58
+ args.project = true
59
+ break
60
+ case '--dry-run':
61
+ args.dryRun = true
62
+ break
63
+ case '--yes':
64
+ case '-y':
65
+ args.yes = true
66
+ break
67
+ case '--from':
68
+ args.from = argv[++i] ?? null
69
+ break
70
+ case '--help':
71
+ case '-h':
72
+ args.help = true
73
+ break
74
+ default:
75
+ break
76
+ }
77
+ }
78
+ return args
79
+ }
80
+
81
+ export function showHelp() {
82
+ console.log(`
83
+ pantheon-opencode restore — restore an exact installer backup
84
+
85
+ Usage:
86
+ pantheon-opencode restore restore newest backup (global config)
87
+ pantheon-opencode restore --project restore newest backup (project)
88
+ pantheon-opencode restore --from <dir> restore a specific backup set
89
+ pantheon-opencode restore --dry-run preview only (writes nothing)
90
+ pantheon-opencode restore --yes authorize the write (non-interactive)
91
+
92
+ A backup set lives under <config-dir>/.pantheon/backups/<timestamp>/.
93
+ Restore reproduces each file byte-for-byte and re-applies its recorded mode.
94
+ File contents are never printed.
95
+ `)
96
+ }
97
+
98
+ /**
99
+ * Choose the backup set to restore.
100
+ * @param {string} configDir
101
+ * @param {string|null} from
102
+ * @returns {{ dir: string, name: string } | null}
103
+ */
104
+ export function pickBackupSet(configDir, from) {
105
+ if (from) {
106
+ // Accept either a bare timestamp set name (resolved under the backups root)
107
+ // or an explicit directory path.
108
+ if (isBackupDirName(from)) {
109
+ const dir = join(backupRoot(configDir), from)
110
+ return existsSync(dir) ? { dir, name: from } : null
111
+ }
112
+ const dir = isAbsolute(from) ? from : resolve(process.cwd(), from)
113
+ if (!existsSync(dir)) return null
114
+ return { dir, name: dir.split(/[\\/]/).pop() }
115
+ }
116
+ return listBackupSets(configDir)[0] ?? null
117
+ }
118
+
119
+ /**
120
+ * @param {object} opts
121
+ * @param {string} opts.configDir
122
+ * @param {string} opts.backupDir
123
+ * @param {boolean} [opts.dryRun]
124
+ * @param {boolean} [opts.yes]
125
+ * @returns {Promise<{ ok: boolean, code: number, entries?: object[] }>}
126
+ */
127
+ export async function runRestore({ configDir, backupDir, dryRun = false, yes = false }) {
128
+ const verify = verifyBackupSet(backupDir)
129
+ if (!verify.ok) {
130
+ console.error(
131
+ `❌ Refusing to restore: backup failed integrity verification (${verify.reason ?? 'hash mismatch'}).`,
132
+ )
133
+ return { ok: false, code: 1 }
134
+ }
135
+
136
+ const plan = planRestore(backupDir, configDir)
137
+ if (plan.error) {
138
+ console.error(`❌ Refusing to restore: ${plan.error}.`)
139
+ return { ok: false, code: 1 }
140
+ }
141
+
142
+ const counts = { create: 0, update: 0, remove: 0, unchanged: 0 }
143
+ for (const entry of plan.entries) counts[entry.action] += 1
144
+
145
+ console.log('')
146
+ console.log(`Restore plan — ${configDir}`)
147
+ console.log(` from ${backupDir}`)
148
+ for (const entry of plan.entries) {
149
+ if (entry.action === 'unchanged') continue
150
+ console.log(` ${entry.action.padEnd(9)} ${entry.relativePath}`)
151
+ }
152
+ console.log(
153
+ ` ${counts.create} create · ${counts.update} update · ${counts.remove} remove · ${counts.unchanged} unchanged`,
154
+ )
155
+
156
+ if (dryRun) {
157
+ console.log(' (dry-run) No files were written.')
158
+ return { ok: true, code: 0, entries: plan.entries }
159
+ }
160
+
161
+ if (!yes) {
162
+ // Reuse the shared confirm semantics (default NO). An interactive TTY may
163
+ // authorize without --yes; a non-TTY run must never proceed silently.
164
+ const tty = Boolean(process.stdin.isTTY && process.stdout.isTTY)
165
+ if (!tty) {
166
+ console.error('❌ Refusing to restore without authorization. Re-run with --yes.')
167
+ return { ok: false, code: 1 }
168
+ }
169
+ const { promptReview } = await import('./install/interactive.mjs')
170
+ const accepted = await promptReview('Restore these changes?', { default: false })
171
+ if (!accepted) {
172
+ console.log(' Nothing restored.')
173
+ return { ok: true, code: 0, entries: plan.entries }
174
+ }
175
+ }
176
+
177
+ // Reversible: snapshot the CURRENT state of exactly the affected paths first.
178
+ // Retention is DISABLED here (`keep: 0`): a retention pass at this point could
179
+ // delete the very set being restored once 5 older sets already exist (the new
180
+ // snapshot would be the 6th, and pruning would drop the oldest two — including
181
+ // the source). Apply still prunes; restore never deletes backups.
182
+ const { dir: preDir } = createBackupSet({
183
+ configDir,
184
+ entries: plan.manifest.entries.map((e) => e.relativePath),
185
+ packageVersion: plan.manifest.packageVersion,
186
+ keep: 0,
187
+ })
188
+ console.log(` pre-restore backup: ${preDir}`)
189
+
190
+ restoreBackupSet(backupDir, configDir, { dryRun: false })
191
+ console.log(` ✅ Restored ${plan.entries.length} path(s).`)
192
+ return { ok: true, code: 0, entries: plan.entries }
193
+ }
194
+
195
+ async function main() {
196
+ const args = parseArgs(process.argv.slice(2))
197
+ if (args.help) {
198
+ showHelp()
199
+ return
200
+ }
201
+ const configDir = resolveConfigDir({ project: args.project })
202
+ const backup = pickBackupSet(configDir, args.from)
203
+ if (!backup) {
204
+ console.error(`❌ No backup set found under ${backupRoot(configDir)}`)
205
+ process.exitCode = 1
206
+ return
207
+ }
208
+ const result = await runRestore({
209
+ configDir,
210
+ backupDir: backup.dir,
211
+ dryRun: args.dryRun,
212
+ yes: args.yes,
213
+ })
214
+ if (!result.ok) process.exitCode = result.code
215
+ }
216
+
217
+ if (import.meta.url === `file://${process.argv[1]}`) {
218
+ main().catch((err) => {
219
+ console.error(`❌ Restore failed: ${err instanceof Error ? err.message : String(err)}`)
220
+ process.exitCode = 1
221
+ })
222
+ }
@@ -22,16 +22,23 @@
22
22
  * the TAP reporter is diverted to a scratch file that is read once and deleted.
23
23
  *
24
24
  * Usage:
25
- * node scripts/run-node-tests.mjs [--label <name>] [-- <node flags...>] <glob>...
25
+ * node scripts/run-node-tests.mjs [--label <name>] [--exclude <glob>]... \
26
+ * [-- <node flags...>] <glob>...
27
+ *
28
+ * `--exclude` removes files from the expanded set before the runner starts. It
29
+ * exists so a heavy tier (the real-install tests) can be kept out of the default
30
+ * suite without turning the default glob into a hand-maintained file list: a
31
+ * newly added test file is still collected automatically.
26
32
  *
27
33
  * Examples:
28
34
  * node scripts/run-node-tests.mjs 'tests/*.mjs' 'tests/pantheon/*.mjs'
35
+ * node scripts/run-node-tests.mjs --exclude 'tests/install-e2e.test.mjs' 'tests/*.mjs'
29
36
  * node scripts/run-node-tests.mjs -- --experimental-test-coverage 'tests/*.mjs'
30
37
  */
31
38
  import { spawnSync } from 'node:child_process'
32
39
  import { globSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
33
40
  import { tmpdir } from 'node:os'
34
- import { join } from 'node:path'
41
+ import { join, matchesGlob } from 'node:path'
35
42
  import { fileURLToPath } from 'node:url'
36
43
 
37
44
  const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..')
@@ -39,12 +46,12 @@ const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..')
39
46
  function usage(message) {
40
47
  console.error(`zero-test-guard: ${message}`)
41
48
  console.error(
42
- 'usage: node scripts/run-node-tests.mjs [--label <name>] [-- <node flags...>] <glob>...',
49
+ 'usage: node scripts/run-node-tests.mjs [--label <name>] [--exclude <glob>]... [-- <node flags...>] <glob>...',
43
50
  )
44
51
  process.exit(1)
45
52
  }
46
53
 
47
- /** Parse `[--label <name>] [-- <node flags...>] <glob>...`. */
54
+ /** Parse `[--label <name>] [--exclude <glob>]... [-- <node flags...>] <glob>...`. */
48
55
  function parseArgs(argv) {
49
56
  const separator = argv.indexOf('--')
50
57
  const own = separator === -1 ? argv : argv.slice(0, separator)
@@ -52,6 +59,7 @@ function parseArgs(argv) {
52
59
 
53
60
  let label = 'node tests'
54
61
  const globs = []
62
+ const excludes = []
55
63
  for (let i = 0; i < own.length; i++) {
56
64
  if (own[i] === '--label') {
57
65
  const value = own[i + 1]
@@ -60,11 +68,18 @@ function parseArgs(argv) {
60
68
  i += 1
61
69
  continue
62
70
  }
71
+ if (own[i] === '--exclude') {
72
+ const value = own[i + 1]
73
+ if (value === undefined) usage('--exclude requires a value')
74
+ excludes.push(value)
75
+ i += 1
76
+ continue
77
+ }
63
78
  if (own[i].startsWith('-')) usage(`unknown option ${own[i]}`)
64
79
  globs.push(own[i])
65
80
  }
66
81
  if (globs.length === 0) usage('at least one glob is required')
67
- return { label, globs, nodeFlags }
82
+ return { label, globs, excludes, nodeFlags }
68
83
  }
69
84
 
70
85
  /**
@@ -72,7 +87,7 @@ function parseArgs(argv) {
72
87
  * Order follows the positional order of the globs so that the suite runs in the same order
73
88
  * as the shell used to; within a glob, matches are sorted for determinism.
74
89
  */
75
- function expand(globs) {
90
+ function expand(globs, excludes = []) {
76
91
  const files = []
77
92
  const seen = new Set()
78
93
  for (const pattern of globs) {
@@ -81,6 +96,7 @@ function expand(globs) {
81
96
  .sort()
82
97
  for (const match of matches) {
83
98
  if (seen.has(match)) continue
99
+ if (excludes.some((exclude) => matchesGlob(match, exclude))) continue
84
100
  seen.add(match)
85
101
  files.push(match)
86
102
  }
@@ -136,8 +152,8 @@ function countCollectedTests(tapPath, files) {
136
152
  return collected
137
153
  }
138
154
 
139
- const { label, globs, nodeFlags } = parseArgs(process.argv.slice(2))
140
- const files = expand(globs)
155
+ const { label, globs, excludes, nodeFlags } = parseArgs(process.argv.slice(2))
156
+ const files = expand(globs, excludes)
141
157
 
142
158
  if (files.length === 0) {
143
159
  reportMissingFiles(label, globs)
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync } from 'node:fs'
21
21
  import { join } from 'node:path'
22
- import { copyAgentPrompts } from './build-agents-md.mjs'
22
+ import { copyAgentPrompts, writeAgentsMdManaged } from './build-agents-md.mjs'
23
23
 
24
24
  import {
25
25
  collectSkillNames,
@@ -40,6 +40,7 @@ const MCP_SCRIPTS = {
40
40
  'pantheon_vision.py': () => join(ROOT, 'src', 'mcp', 'pantheon_vision.py'),
41
41
  'eval_store.py': () => join(ROOT, 'src', 'mcp', 'eval_store.py'),
42
42
  'scrub-secrets.py': () => join(ROOT, 'scripts', 'scrub-secrets.py'),
43
+ 'themis_heuristic_scan.py': () => join(ROOT, 'scripts', 'themis_heuristic_scan.py'),
43
44
  }
44
45
 
45
46
  /**
@@ -82,15 +83,27 @@ export function syncCopyArtifacts(configDir) {
82
83
  result.errors.push(`skills: ${err.message}`)
83
84
  }
84
85
 
85
- // ── instructions (AGENTS.md) ──
86
+ // ── instructions (global AGENTS.md artifact) ──
87
+ // The config dir is GLOBAL context: it receives the repo-agnostic global
88
+ // artifact, never the repository artifact. Managed-region writer keeps any
89
+ // user content around the markers intact.
86
90
  try {
87
- const src = join(ROOT, 'AGENTS.md')
91
+ const src = join(ROOT, 'AGENTS.global.md')
88
92
  if (existsSync(src)) {
89
- if (
90
- writeIfChanged(join(configDir, 'AGENTS.md'), readFileSync(src, 'utf8'), false) === 'created'
91
- ) {
93
+ const status = writeAgentsMdManaged(
94
+ join(configDir, 'AGENTS.md'),
95
+ readFileSync(src, 'utf8'),
96
+ false,
97
+ )
98
+ if (status === 'skipped') result.skipped++
99
+ else {
92
100
  result.created++
93
- } else result.skipped++
101
+ if (status === 'merged') {
102
+ result.errors.push(
103
+ 'instructions: non-generated content found in AGENTS.md — preserved around the Pantheon managed region',
104
+ )
105
+ }
106
+ }
94
107
  }
95
108
  } catch (err) {
96
109
  result.errors.push(`instructions: ${err.message}`)
@@ -14,6 +14,8 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync
14
14
  import { homedir } from 'node:os'
15
15
  import { join } from 'node:path'
16
16
  import { fileURLToPath, pathToFileURL } from 'node:url'
17
+ import { resolveOpenCodeVersion } from './install/opencode-version.mjs'
18
+ import { isSupportedNodeVersion } from './node-engine-policy.mjs'
17
19
 
18
20
  const __dirname = fileURLToPath(new URL('.', import.meta.url))
19
21
  const ROOT = join(__dirname, '..')
@@ -63,7 +65,7 @@ function resolveConfigDir() {
63
65
  * The raw TSX source is never copied — the loader consumes only the bundle.
64
66
  * @returns {{ created: number, skipped: number }}
65
67
  */
66
- function copyPluginFiles(srcDir, dstDir) {
68
+ function copyPluginFiles(srcDir, dstDir, version) {
67
69
  const result = { created: 0, skipped: 0 }
68
70
 
69
71
  mkdirSync(dstDir, { recursive: true })
@@ -87,11 +89,30 @@ function copyPluginFiles(srcDir, dstDir) {
87
89
  // package.json
88
90
  const pkgSrc = join(srcDir, 'package.json')
89
91
  if (existsSync(pkgSrc)) {
90
- const content = readFileSync(pkgSrc, 'utf8')
92
+ const packageJson = JSON.parse(readFileSync(pkgSrc, 'utf8'))
93
+ if (version === 'v2' && packageJson.exports?.['./tui-v2']) {
94
+ packageJson.exports['./tui'] = packageJson.exports['./tui-v2']
95
+ }
96
+ const content = `${JSON.stringify(packageJson, null, 2)}\n`
91
97
  if (writeIfChanged(join(dstDir, 'package.json'), content)) result.created++
92
98
  else result.skipped++
93
99
  }
94
100
 
101
+ const tuiEntry = join(srcDir, version === 'v2' ? 'tui-v2.ts' : 'tui.ts')
102
+ if (existsSync(tuiEntry)) {
103
+ if (writeIfChanged(join(dstDir, 'tui.ts'), readFileSync(tuiEntry, 'utf8'))) result.created++
104
+ else result.skipped++
105
+ }
106
+
107
+ const v2ServerEntry = join(srcDir, 'index-v2.ts')
108
+ const v2ServerDestination = join(dstDir, 'index.ts')
109
+ if (version === 'v2' && existsSync(v2ServerEntry)) {
110
+ if (writeIfChanged(v2ServerDestination, readFileSync(v2ServerEntry, 'utf8'))) result.created++
111
+ else result.skipped++
112
+ } else if (existsSync(v2ServerDestination)) {
113
+ rmSync(v2ServerDestination, { force: true })
114
+ }
115
+
95
116
  // Keep the copied plugin installable with deterministic npm ci.
96
117
  const lockSrc = join(srcDir, 'package-lock.json')
97
118
  if (existsSync(lockSrc)) {
@@ -169,7 +190,8 @@ async function main() {
169
190
  const sourceVersion = readVersion(join(tuiSrcDir, 'package.json'))
170
191
 
171
192
  // Copy fresh files
172
- const { created } = copyPluginFiles(tuiSrcDir, tuiCopyDir)
193
+ const version = resolveOpenCodeVersion('auto', { warn: (message) => console.warn(message) })
194
+ const { created } = copyPluginFiles(tuiSrcDir, tuiCopyDir, version)
173
195
 
174
196
  // Lockfile installation is the only accepted dependency path. Strip
175
197
  // global-context npm vars so a global postinstall can't trigger ECIGLOBAL.
@@ -236,7 +258,10 @@ async function main() {
236
258
  const isDirectRun =
237
259
  Boolean(process.argv[1]) && pathToFileURL(process.argv[1]).href === import.meta.url
238
260
 
239
- if (isDirectRun) {
261
+ if (isDirectRun && !isSupportedNodeVersion(process.versions.node)) {
262
+ // postinstall.mjs already reports the engine mismatch. Do not call npm ci or
263
+ // touch the user's config with an incompatible lifecycle runtime.
264
+ } else if (isDirectRun) {
240
265
  main().catch((err) => {
241
266
  console.error(`❌ TUI sync failed: ${err.message}`)
242
267
  process.exitCode = 1