pantheon-opencode 1.6.1 → 1.6.2-beta.2

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