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
@@ -47,9 +47,19 @@ import {
47
47
  mergeContextSandboxBlocks,
48
48
  migrateMcpEntrypointPaths,
49
49
  migrateV1toV2,
50
+ validateMcpV1toV2Source,
50
51
  } from './config-migration.mjs'
52
+ import { resolveGlobalConfigDirectory } from './config-paths.mjs'
51
53
  import { componentForInstalledPath, updateFileInventory } from './file-inventory.mjs'
52
54
  import { healthCheck } from './health-check.mjs'
55
+ import {
56
+ assertMcpGeneratedPermissionsDoNotWeakenExplicitRules,
57
+ assertMcpPermissionNamesUnambiguous,
58
+ assertMcpPermissionScopesDoNotAliasConfiguredServers,
59
+ assertMcpPermissionServerGrantsUnambiguous,
60
+ mcpPermissionAliases,
61
+ normalizeMcpPermissionSegment,
62
+ } from './mcp-permissions.mjs'
53
63
  import { detectVersion, runMigrations } from './migrate.mjs'
54
64
  import { describeSharedState } from './opencode-state.mjs'
55
65
  import { DRY_RUN_PROBE_TIMEOUT_MS, resolveOpenCodeVersion } from './opencode-version.mjs'
@@ -393,9 +403,7 @@ const PANTHEON_MCP_SERVER_ENTRIES = Object.freeze([
393
403
  /** The managed server names, in write order. */
394
404
  const PANTHEON_MCP_SERVERS = Object.freeze(PANTHEON_MCP_SERVER_ENTRIES.map((entry) => entry.name))
395
405
 
396
- function normalizeMcpPermissionSegment(value) {
397
- return value.replace(/[^a-zA-Z0-9_]/g, '_')
398
- }
406
+ export { normalizeMcpPermissionSegment, PANTHEON_MCP_SERVERS }
399
407
 
400
408
  /**
401
409
  * Translate an agent's `mcp_tools` frontmatter into per-tool native
@@ -407,7 +415,7 @@ function normalizeMcpPermissionSegment(value) {
407
415
  * @param {Record<string, 'all' | string[]>} mcpTools
408
416
  * @returns {Record<string, 'allow' | 'deny'>}
409
417
  */
410
- export function deriveNativeMcpPermissions(mcpTools) {
418
+ export function deriveNativeMcpPermissions(mcpTools, configuredServers = []) {
411
419
  if (mcpTools === null || typeof mcpTools !== 'object' || Array.isArray(mcpTools)) {
412
420
  throw new TypeError('mcp_tools must be an object keyed by MCP server name')
413
421
  }
@@ -427,21 +435,36 @@ export function deriveNativeMcpPermissions(mcpTools) {
427
435
  ) {
428
436
  throw new TypeError(`mcp_tools.${server} must be "all" or an array of tool names`)
429
437
  }
438
+ }
430
439
 
431
- const serverAliases = new Set([server, normalizeMcpPermissionSegment(server)])
440
+ assertMcpPermissionNamesUnambiguous(servers)
441
+ assertMcpPermissionScopesDoNotAliasConfiguredServers(servers, configuredServers)
442
+ for (const server of servers) {
443
+ const tools = Object.hasOwn(mcpTools, server) ? mcpTools[server] : []
444
+ if (Array.isArray(tools)) assertMcpPermissionNamesUnambiguous(tools)
445
+ }
446
+ assertMcpPermissionServerGrantsUnambiguous(
447
+ [...servers].map((server) => ({
448
+ server,
449
+ tools: Object.hasOwn(mcpTools, server) ? mcpTools[server] : [],
450
+ })),
451
+ )
452
+
453
+ for (const server of servers) {
454
+ const serverAliases = mcpPermissionAliases(server)
432
455
  for (const alias of serverAliases) permissions[`${alias}_*`] = 'deny'
433
456
  }
434
457
 
435
458
  for (const server of servers) {
436
459
  const tools = Object.hasOwn(mcpTools, server) ? mcpTools[server] : []
437
- const serverAliases = new Set([server, normalizeMcpPermissionSegment(server)])
460
+ const serverAliases = mcpPermissionAliases(server)
438
461
  if (tools === 'all') {
439
462
  for (const alias of serverAliases) permissions[`${alias}_*`] = 'allow'
440
463
  continue
441
464
  }
442
465
 
443
466
  for (const tool of tools) {
444
- const toolAliases = new Set([tool, normalizeMcpPermissionSegment(tool)])
467
+ const toolAliases = mcpPermissionAliases(tool)
445
468
  for (const serverAlias of serverAliases) {
446
469
  for (const toolAlias of toolAliases) {
447
470
  permissions[`${serverAlias}_${toolAlias}`] = 'allow'
@@ -453,10 +476,58 @@ export function deriveNativeMcpPermissions(mcpTools) {
453
476
  return permissions
454
477
  }
455
478
 
479
+ /** Merge generated MCP grants only when they do not weaken explicit agent policy. */
480
+ export function mergeAgentMcpPermissions(explicit, mcpTools, configuredServers = []) {
481
+ const generated = deriveNativeMcpPermissions(mcpTools, configuredServers)
482
+ assertMcpGeneratedPermissionsDoNotWeakenExplicitRules(explicit, generated)
483
+ return { ...(explicit ?? {}), ...generated }
484
+ }
485
+
486
+ /** Build a fail-closed skill allowlist from an agent's canonical `skills` list. */
487
+ export function deriveNativeSkillPermissions(skills) {
488
+ if (!Array.isArray(skills)) {
489
+ throw new TypeError('agent skills must be an array of skill IDs')
490
+ }
491
+
492
+ const permissions = { '*': 'deny' }
493
+ const seen = new Set()
494
+ for (const skill of skills) {
495
+ if (typeof skill !== 'string' || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(skill)) {
496
+ throw new TypeError(`agent skill ID is invalid: ${String(skill)}`)
497
+ }
498
+ if (seen.has(skill)) throw new TypeError(`agent skill list contains duplicate skill: ${skill}`)
499
+ seen.add(skill)
500
+ permissions[skill] = 'allow'
501
+ }
502
+ return permissions
503
+ }
504
+
505
+ /**
506
+ * Add the canonical skill allowlist to one agent's permission map. An explicit
507
+ * skill policy in canonical frontmatter would make last-match precedence
508
+ * ambiguous, so require that policy to be expressed through `skills:` instead.
509
+ */
510
+ export function mergeAgentSkillPermissions(explicit, skills) {
511
+ if (explicit?.skill !== undefined) {
512
+ throw new TypeError('agent skill access must be declared only through the skills list')
513
+ }
514
+ return { ...(explicit ?? {}), skill: deriveNativeSkillPermissions(skills) }
515
+ }
516
+
456
517
  function deepClone(value) {
457
518
  return JSON.parse(JSON.stringify(value))
458
519
  }
459
520
 
521
+ function configuredMcpServerNames(mcpConfig) {
522
+ if (mcpConfig === null || typeof mcpConfig !== 'object' || Array.isArray(mcpConfig)) return []
523
+ const { hasV2ServersMap, legacyServersToggle } = validateMcpV1toV2Source(mcpConfig)
524
+ return Object.entries(mcpConfig).flatMap(([name, value]) => {
525
+ if (hasV2ServersMap && name === 'servers') return Object.keys(value)
526
+ if (legacyServersToggle && name === 'servers') return []
527
+ return [name]
528
+ })
529
+ }
530
+
460
531
  /**
461
532
  * (Re)generate the code-mode manifest with SHA-256 digests for every bundled
462
533
  * script, and write it to the destination. This is the explicit installation
@@ -782,6 +853,35 @@ export function deduplicatePluginReferences(refs) {
782
853
  })
783
854
  }
784
855
 
856
+ /**
857
+ * Register the copied Pantheon TUI plugin in the V2 `plugins` list.
858
+ *
859
+ * The OpenCode 2.x host does not load server-side RPC from a local plugin
860
+ * folder by free discovery — only entries listed in `config.plugins` are
861
+ * loaded (sandbox probe evidence: no entry → `rpc.unavailable`; with the
862
+ * entry the host logs `loading plugin id=…/pantheon-tui` and the V2-only
863
+ * RPC (`pantheon.quota`) answers HTTP 200). Without this registration a
864
+ * postinstall/sync that re-copies the payload after `init` can never restore
865
+ * it, so the quota status stays "unavailable".
866
+ *
867
+ * Idempotent: the existing entry for the copy (same identity) is retained
868
+ * and kept after the core plugin, while every other entry stays in place.
869
+ * Gated on the copy existing so an install without the plugins component does
870
+ * not register a dangling path.
871
+ *
872
+ * @param {{ plugins?: unknown }} config - the config object about to be written (mutated)
873
+ * @param {{ tuiCopyDir: string }} opts - absolute path of the copied plugin directory
874
+ */
875
+ export function ensureTuiCopyRegistered(config, { tuiCopyDir }) {
876
+ if (!Array.isArray(config.plugins)) config.plugins = []
877
+ if (!existsSync(tuiCopyDir)) return
878
+
879
+ const identity = pluginReferenceIdentity(tuiCopyDir)
880
+ const existing = config.plugins.find((entry) => pluginReferenceIdentity(entry) === identity)
881
+ config.plugins = config.plugins.filter((entry) => pluginReferenceIdentity(entry) !== identity)
882
+ config.plugins.push(existing ?? tuiCopyDir)
883
+ }
884
+
785
885
  /**
786
886
  * Duplicate the V1 top-level `context_sandbox` block into the exact Pantheon V2
787
887
  * plugin entry's `options`, converting a plain-string entry into the
@@ -877,8 +977,9 @@ export function isGlobalConfigDir(target) {
877
977
  *
878
978
  * <configDir>/plugins/pantheon-tui (tui.ts + dist/ + package manifests)
879
979
  *
880
- * V1 registers that copy through tui.json. V2 discovers the local plugin's
881
- * index.ts + tui.ts pair; the V2 shim re-exports dist/tui-v2.js.
980
+ * V1 registers that copy through tui.json. V2 loads the copy only through the
981
+ * `plugins` entry (see ensureTuiCopyRegistered); the V2 shim re-exports
982
+ * dist/tui-v2.js.
882
983
  *
883
984
  * @param {string} configDir - OpenCode config directory (target for global
884
985
  * installs, <target>/.opencode for project installs)
@@ -1149,8 +1250,9 @@ export function applyContextSidebarNegation(
1149
1250
  }
1150
1251
 
1151
1252
  /**
1152
- * Sync the Pantheon TUI plugin payload and V1 registration. V2 discovers the
1153
- * copied local-plugin entrypoints and does not use a project tui.json.
1253
+ * Sync the Pantheon TUI plugin payload and V1 registration. V2 does not use a
1254
+ * project tui.json; it loads the copy's server ONLY through the config
1255
+ * `plugins` entry written by ensureTuiCopyRegistered().
1154
1256
  *
1155
1257
  * Contract (single source of truth):
1156
1258
  * 1. ALWAYS copy src/plugins/tui → <configDir>/plugins/pantheon-tui with the
@@ -1161,8 +1263,9 @@ export function applyContextSidebarNegation(
1161
1263
  * paths, in-package src/plugins/tui dirs, bare plugins/pantheon-tui
1162
1264
  * copies, and npx paths. A stale ref left in the non-target location
1163
1265
  * would still be loaded and break the TUI.
1164
- * 3. V1 registers the copied directory in the selected target. V2 relies on
1165
- * local-plugin discovery and does not write a project tui.json entry.
1266
+ * 3. V1 registers the copied directory in the selected target. V2 does not
1267
+ * write a project tui.json entry; its `plugins` registration is written
1268
+ * by the config merge (ensureTuiCopyRegistered).
1166
1269
  *
1167
1270
  * @param {string} target - install target directory
1168
1271
  * @param {object} [opts]
@@ -1225,9 +1328,10 @@ export function syncTuiRegistration(
1225
1328
  })
1226
1329
  }
1227
1330
 
1228
- // OpenCode V2 discovers local plugins from the config plugins directories;
1229
- // its TUI plugin API is exposed by the sibling tui.ts entrypoint. V1 still
1230
- // requires the explicit tui.json registration.
1331
+ // The V2 host loads the copy's server-side RPC only from the config
1332
+ // `plugins` list — ensureTuiCopyRegistered writes that entry during the
1333
+ // config merge, so no tui.json is written here. V1 still requires the
1334
+ // explicit tui.json registration.
1231
1335
  if (version === 'v2') return 'skipped'
1232
1336
 
1233
1337
  // 3. Register the copied directory in the selected target only.
@@ -1338,63 +1442,80 @@ export function setupRuntimePhase(
1338
1442
  * order) — the dry-run preview reports exactly these
1339
1443
  */
1340
1444
  export function applyMcpServerEntries(config, { runtimeTarget, venvPython, version = 'v2' }) {
1341
- config.mcp = config.mcp || {}
1342
- // MCP stays a flat named-server map for BOTH V1 and V2: OpenCode 1.18.x has
1343
- // no `mcp.servers` wrapper and rejects one with "Missing key
1344
- // mcp.servers.enabled". config-migration.mjs normalizes any legacy
1345
- // wrapper-shaped entries back to the flat map.
1346
- const healed = migrateMcpEntrypointPaths(config.mcp)
1445
+ if (version === 'v2') {
1446
+ if (Object.hasOwn(config, 'mcp')) validateMcpV1toV2Source(config.mcp)
1447
+ else config.mcp = {}
1448
+ } else {
1449
+ config.mcp = config.mcp || {}
1450
+ }
1451
+ let serverMap = config.mcp
1452
+ if (version === 'v2') {
1453
+ const { hasV2ServersMap, legacyServersToggle } = validateMcpV1toV2Source(config.mcp)
1454
+ const existingServers = config.mcp.servers
1455
+ if (hasV2ServersMap) {
1456
+ serverMap = existingServers
1457
+ } else {
1458
+ serverMap = { ...config.mcp }
1459
+ if (legacyServersToggle) delete serverMap.servers
1460
+ config.mcp = { servers: serverMap }
1461
+ }
1462
+ }
1463
+ const healed = migrateMcpEntrypointPaths(serverMap)
1347
1464
 
1348
1465
  // Only add if not already configured by user.
1349
1466
  const servers = []
1350
1467
  for (const entry of PANTHEON_MCP_SERVER_ENTRIES) {
1351
- if (config.mcp[entry.name]) continue
1352
- config.mcp[entry.name] = {
1468
+ if (serverMap[entry.name]) continue
1469
+ serverMap[entry.name] = {
1353
1470
  type: 'local',
1354
1471
  cwd: runtimeTarget,
1355
1472
  command: [venvPython, entry.script],
1356
- enabled: true,
1473
+ ...(version === 'v1' ? { enabled: true } : {}),
1357
1474
  }
1358
1475
  servers.push(entry.name)
1359
1476
  }
1360
1477
 
1361
- // Default MCP permissions.
1478
+ // V1 compatibility defaults. V2 setup converts user `ask` entries only after
1479
+ // explicit review; the inert legacy defaults are not seeded into V2 configs.
1362
1480
  //
1363
- // WARNING: on OpenCode 2.x, `permission.mcp.<server>` is NOT enforced. The
1364
- // host evaluates an MCP call as the action `<server>_<tool>` with resources
1365
- // ["*"]; `permission.mcp.<server>` and `action:"mcp"` are inert (measured on
1366
- // 2.0.29–2.1.3). These defaults are kept for V1 compatibility, but `ask` does
1367
- // not prompt and `allow` grants nothing it did not already have — every `ask`
1368
- // server below is reported to the user as unenforced. The enforceable form is
1369
- // `{ action: "<server>_*", resource: "*", effect: "deny" }`; `ask` there
1370
- // HIDES the tool instead of asking, so it is never emitted as a default.
1371
- config.permission = config.permission || {}
1372
- config.permission.mcp = config.permission.mcp || {}
1373
- if (!config.permission.mcp['pantheon-resources']) {
1374
- config.permission.mcp['pantheon-resources'] = 'allow'
1375
- }
1376
- if (!config.permission.mcp['pantheon-code-mode']) {
1377
- config.permission.mcp['pantheon-code-mode'] = 'ask'
1378
- }
1379
- if (!config.permission.mcp['pantheon-memory']) {
1380
- config.permission.mcp['pantheon-memory'] = 'allow'
1381
- }
1382
- if (!config.permission.mcp['pantheon-persistence']) {
1383
- config.permission.mcp['pantheon-persistence'] = 'allow'
1384
- }
1385
- if (!config.permission.mcp['pantheon-vision']) {
1386
- config.permission.mcp['pantheon-vision'] = 'ask'
1481
+ // Legacy defaults remain V1-only. V2 requires explicit native permissions;
1482
+ // absent a rule, MCP servers remain accessible without a prompt.
1483
+ if (version === 'v1') {
1484
+ config.permission = config.permission || {}
1485
+ config.permission.mcp = config.permission.mcp || {}
1486
+ if (!config.permission.mcp['pantheon-resources']) {
1487
+ config.permission.mcp['pantheon-resources'] = 'allow'
1488
+ }
1489
+ if (!config.permission.mcp['pantheon-code-mode']) {
1490
+ config.permission.mcp['pantheon-code-mode'] = 'ask'
1491
+ }
1492
+ if (!config.permission.mcp['pantheon-memory']) {
1493
+ config.permission.mcp['pantheon-memory'] = 'allow'
1494
+ }
1495
+ if (!config.permission.mcp['pantheon-persistence']) {
1496
+ config.permission.mcp['pantheon-persistence'] = 'allow'
1497
+ }
1498
+ if (!config.permission.mcp['pantheon-vision']) {
1499
+ config.permission.mcp['pantheon-vision'] = 'ask'
1500
+ }
1387
1501
  }
1388
1502
 
1389
1503
  // Report every `ask` entry, whether just seeded or left by a previous
1390
1504
  // install: the config claims a gate the host does not apply. V1's MCP
1391
1505
  // permission semantics were not measured, so the warning is V2-only.
1392
- const S = strings()
1506
+ const askCount = Object.values(config.permission?.mcp ?? {}).filter(
1507
+ (effect) => effect === 'ask',
1508
+ ).length
1393
1509
  const warnings =
1394
1510
  version === 'v2'
1395
- ? Object.entries(config.permission.mcp)
1396
- .filter(([, effect]) => effect === 'ask')
1397
- .map(([server]) => S.mcpAskNotEnforceable(server))
1511
+ ? [
1512
+ ...(askCount > 0
1513
+ ? [
1514
+ `${askCount} legacy MCP ask rule(s) cannot be enforced; run setup for an explicit policy choice.`,
1515
+ ]
1516
+ : []),
1517
+ 'V2 Pantheon MCP servers without an explicit permission rule remain accessible without a prompt.',
1518
+ ]
1398
1519
  : []
1399
1520
 
1400
1521
  return { healed, warnings, servers }
@@ -1490,9 +1611,13 @@ async function installPass(
1490
1611
  components = ['agents', 'skills', 'instructions', 'commands', 'plugins', 'runtime'],
1491
1612
  opts = {},
1492
1613
  ) {
1614
+ if (opts.configPreview !== undefined && opts.configPreview !== null && !dryRun) {
1615
+ throw new Error('A setup config preview is accepted only during a dry run.')
1616
+ }
1617
+
1493
1618
  // Default target if not provided (global ~/.config/opencode)
1494
1619
  if (!target) {
1495
- target = join(homedir(), '.config', 'opencode')
1620
+ target = resolveGlobalConfigDirectory(process.env)
1496
1621
  }
1497
1622
 
1498
1623
  const componentSet = new Set(
@@ -1711,7 +1836,24 @@ async function installPass(
1711
1836
  // real --dry-run) prints it once.
1712
1837
  if (!opts.planOnly) warning(configAdvisories[0])
1713
1838
  }
1714
- const { config, raw: configRaw } = readJsonConfigWithRaw(targetConfigPath)
1839
+ const { config: diskConfig, raw: configRaw } = readJsonConfigWithRaw(targetConfigPath)
1840
+ let config = diskConfig
1841
+ if (opts.configPreview !== undefined && opts.configPreview !== null) {
1842
+ try {
1843
+ config = JSON.parse(opts.configPreview)
1844
+ if (config === null || typeof config !== 'object' || Array.isArray(config)) {
1845
+ throw new Error('not an object')
1846
+ }
1847
+ } catch {
1848
+ throw new Error('The setup config preview input is invalid.')
1849
+ }
1850
+ }
1851
+ // Validate the original MCP shape before runtime entries can be seeded or a
1852
+ // flat map can be wrapped. Seeding first can turn malformed nested input into
1853
+ // an apparently valid wrapper and let migration silently discard user data.
1854
+ if (version === 'v2' && Object.hasOwn(config, 'mcp')) {
1855
+ validateMcpV1toV2Source(config.mcp)
1856
+ }
1715
1857
  const pantheonConfig =
1716
1858
  pantheonConfigPath !== null && existsSync(pantheonConfigPath)
1717
1859
  ? readJsonConfig(pantheonConfigPath)
@@ -1780,6 +1922,16 @@ async function installPass(
1780
1922
  target,
1781
1923
  packageRoot: ROOT,
1782
1924
  packageVersion,
1925
+ options: {
1926
+ clean,
1927
+ components: [...components],
1928
+ version,
1929
+ isProject: opts.isProject === true,
1930
+ model: opts.model ?? null,
1931
+ smallModel: opts.smallModel ?? null,
1932
+ preset: opts.preset ?? null,
1933
+ mergeDevConfig: mergeDevConfigOpt,
1934
+ },
1783
1935
  files: planned?.files ?? [],
1784
1936
  snapshots: planned?.snapshots ?? [],
1785
1937
  })
@@ -2407,11 +2559,15 @@ async function installPass(
2407
2559
  if (fm.permission) {
2408
2560
  agent.permission = JSON.parse(JSON.stringify(fm.permission))
2409
2561
  }
2562
+ if (fm.skills !== undefined) {
2563
+ agent.permission = mergeAgentSkillPermissions(agent.permission, fm.skills)
2564
+ }
2410
2565
  if (fm.mcp_tools !== undefined) {
2411
- agent.permission = {
2412
- ...(agent.permission ?? {}),
2413
- ...deriveNativeMcpPermissions(fm.mcp_tools),
2414
- }
2566
+ agent.permission = mergeAgentMcpPermissions(
2567
+ agent.permission,
2568
+ fm.mcp_tools,
2569
+ configuredMcpServersForPolicies,
2570
+ )
2415
2571
  }
2416
2572
 
2417
2573
  config[name] = agent
@@ -2419,6 +2575,8 @@ async function installPass(
2419
2575
  return config
2420
2576
  }
2421
2577
 
2578
+ const configuredMcpServersForPolicies =
2579
+ version === 'v2' ? configuredMcpServerNames(config.mcp) : []
2422
2580
  const canonicalAgentConfig = readAgentConfigFromCanonical()
2423
2581
  const agentSources = getAgentSources(agentPrefix)
2424
2582
 
@@ -2655,18 +2813,23 @@ async function installPass(
2655
2813
  config.plugins = config.plugins.filter(
2656
2814
  (plugin) => pluginReferenceIdentity(plugin) !== pluginReferenceIdentity(resolvedV2),
2657
2815
  )
2658
- // ALWAYS the object form, even on a fresh install with nothing to preserve.
2659
- // The host hands a plugin its `options` only from `{ package, options }`,
2660
- // and the opt-in features (`context_pruner`, `memory_injection`) read
2661
- // `ctx.options`. Emitting a bare string — which a fresh install used to do —
2662
- // left those features unreachable for anyone who did not already know the
2663
- // object syntax from the docs, so the shape (with an empty options bag) is
2664
- // written from the start and a user's hand-added keys survive a re-run.
2816
+ // Always use object form, even on a fresh install. The host passes plugin
2817
+ // options only from `{ package, options }`, and `context_pruner` reads
2818
+ // `ctx.options`. A bare string left the option unreachable; an empty object
2819
+ // keeps the contract visible and preserves user-added keys on re-run.
2665
2820
  config.plugins.push({
2666
2821
  package: resolvedV2,
2667
2822
  options: existingV2Options === null ? {} : deepClone(existingV2Options),
2668
2823
  })
2669
2824
 
2825
+ // See ensureTuiCopyRegistered: OpenCode 2.x loads server-side RPC of the
2826
+ // copied TUI plugin ONLY through an explicit `plugins` entry.
2827
+ ensureTuiCopyRegistered(config, {
2828
+ tuiCopyDir: isGlobal
2829
+ ? join(target, 'plugins', 'pantheon-tui')
2830
+ : join(target, '.opencode', 'plugins', 'pantheon-tui'),
2831
+ })
2832
+
2670
2833
  // A path that LOOKS like a Pantheon V2 entry but is not one this package
2671
2834
  // can prove it owns (managedPluginIdentity only recognizes installed copies
2672
2835
  // and this package's own paths) would now be registered twice: the host
@@ -2717,6 +2880,10 @@ async function installPass(
2717
2880
  // --------------------------------------------------------------------
2718
2881
  // C. Merge permissions
2719
2882
  // --------------------------------------------------------------------
2883
+ // A native V2 array is an explicit policy, including an empty one. Do not
2884
+ // append legacy defaults to it: reruns would duplicate rules, and custom V2
2885
+ // configs would gain grants the user did not choose.
2886
+ const hasNativeV2Permissions = version === 'v2' && Array.isArray(config.permissions)
2720
2887
  if (config.permission === undefined) config.permission = {}
2721
2888
  if (
2722
2889
  typeof config.permission === 'object' &&
@@ -2736,7 +2903,11 @@ async function installPass(
2736
2903
  // must not seed the key. It used to anyway, via the unconditional
2737
2904
  // PRODUCT_CONFIG_DEFAULTS.permission merge that sat above this block —
2738
2905
  // which also made this gate dead code.
2739
- if (componentSet.has('skills') && config.permission.skill === undefined) {
2906
+ if (
2907
+ componentSet.has('skills') &&
2908
+ config.permission.skill === undefined &&
2909
+ !hasNativeV2Permissions
2910
+ ) {
2740
2911
  config.permission.skill = { '*': 'allow' }
2741
2912
  }
2742
2913
  // These five are the commands Pantheon's OWN agents must be able to run
@@ -2762,7 +2933,7 @@ async function installPass(
2762
2933
  // NOTE: this grant is NOT gated on the skills component — unlike
2763
2934
  // permission.skill above, agents are installed by the agents component and
2764
2935
  // the test/lint commands are needed whichever components were selected.
2765
- if (config.permission.bash === undefined) {
2936
+ if (config.permission.bash === undefined && !hasNativeV2Permissions) {
2766
2937
  config.permission.bash = {
2767
2938
  'git *': 'allow',
2768
2939
  'npm *': 'allow',
@@ -36,6 +36,11 @@ function hash(value) {
36
36
  return createHash('sha256').update(value).digest('hex')
37
37
  }
38
38
 
39
+ /** Bind an in-memory reviewed plan to the exact JSON payload passed to init. */
40
+ export function planArtifactDigest(artifact) {
41
+ return hash(JSON.stringify(artifact))
42
+ }
43
+
39
44
  function lstatOrNull(path) {
40
45
  try {
41
46
  return lstatSync(path)
@@ -471,7 +476,10 @@ export function loadPlanArtifact(path) {
471
476
  }
472
477
 
473
478
  /** Compare current inputs and destinations against a saved reviewed plan. */
474
- export function findPlanDrift(artifact, { target, packageRoot, packageVersion, files, snapshots }) {
479
+ export function findPlanDrift(
480
+ artifact,
481
+ { target, packageRoot, packageVersion, options, files, snapshots },
482
+ ) {
475
483
  validatePlanArtifact(artifact)
476
484
  const root = resolve(target)
477
485
  const reasons = []
@@ -485,6 +493,9 @@ export function findPlanDrift(artifact, { target, packageRoot, packageVersion, f
485
493
  sourceFingerprint(packageRoot, [artifact.artifact_path]) !== artifact.package.source_fingerprint
486
494
  )
487
495
  reasons.push('source')
496
+ if (options !== undefined && JSON.stringify(options) !== JSON.stringify(artifact.options)) {
497
+ reasons.push('options')
498
+ }
488
499
 
489
500
  const currentSnapshots = new Map(snapshots.map((item) => [resolve(item.path), item]))
490
501
  for (const operation of artifact.operations) {
@@ -100,6 +100,15 @@ export function copyPluginFiles(
100
100
  'plugin entrypoint that re-exports a missing bundle. Reinstall pantheon-opencode.',
101
101
  )
102
102
  }
103
+ const requiredServerBundle = join(srcDir, 'dist', 'server-v2.js')
104
+ const serverBundleAvailable = version !== 'v2' || existsSync(requiredServerBundle)
105
+ if (!serverBundleAvailable) {
106
+ result.errors++
107
+ result.problems.push(
108
+ `TUI server bundle not found in the package: ${requiredServerBundle} — refusing to install a ` +
109
+ 'plugin entrypoint that re-exports a missing bundle. Reinstall pantheon-opencode.',
110
+ )
111
+ }
103
112
 
104
113
  if (!dryRun) {
105
114
  assertNoSymlinkAncestors(dstDir)
@@ -136,6 +145,13 @@ export function copyPluginFiles(
136
145
  if (version === 'v2' && packageJson.exports?.['./tui-v2']) {
137
146
  packageJson.exports['./tui'] = packageJson.exports['./tui-v2']
138
147
  }
148
+ // The OpenCode host resolves the plugin server through the `./server` export.
149
+ // In the V2 copy it must point at the V2 server bundle so V2-only RPCs
150
+ // (pantheon.quota) are registered; otherwise the host loads the V1 server
151
+ // and the quota status stays "unavailable".
152
+ if (version === 'v2' && packageJson.exports?.['./server-v2']) {
153
+ packageJson.exports['./server'] = packageJson.exports['./server-v2']
154
+ }
139
155
  const pkgStatus = writeIfChanged(
140
156
  join(dstDir, 'package.json'),
141
157
  `${JSON.stringify(packageJson, null, 2)}\n`,
@@ -166,7 +182,7 @@ export function copyPluginFiles(
166
182
 
167
183
  const v2ServerEntry = join(srcDir, 'index-v2.ts')
168
184
  const v2ServerDestination = join(dstDir, 'index.ts')
169
- if (version === 'v2' && existsSync(v2ServerEntry)) {
185
+ if (version === 'v2' && serverBundleAvailable && existsSync(v2ServerEntry)) {
170
186
  const entryStatus = writeIfChanged(
171
187
  v2ServerDestination,
172
188
  readFileSync(v2ServerEntry, 'utf8'),
@@ -149,8 +149,8 @@ export function isPantheonV2Reference(ref) {
149
149
  * Whether the installed Pantheon V2 entry can receive plugin `options`.
150
150
  *
151
151
  * The host hands a plugin its `options` only from the OBJECT form
152
- * (`{ package, options }`); a bare string entry leaves `ctx.options` empty, and
153
- * `context_pruner` / `memory_injection` read exactly that object. A fresh
152
+ * (`{ package, options }`); a bare string entry leaves `ctx.options` empty.
153
+ * `context_pruner` is the remaining opt-in that reads that object. A fresh
154
154
  * install that emitted a bare string therefore had no reachable opt-in switch
155
155
  * at all — this is the check that reports it after install.
156
156
  *
@@ -183,8 +183,7 @@ export function describePluginOptionsReachability(plugins) {
183
183
  reachable: true,
184
184
  form: 'object',
185
185
  detail:
186
- 'at least one Pantheon V2 entry carries an "options" object, so context_pruner and ' +
187
- 'memory_injection can be configured there' +
186
+ 'at least one Pantheon V2 entry carries an "options" object, so context_pruner can be configured there' +
188
187
  (extra.length === 0
189
188
  ? ''
190
189
  : `; ${extra.length} other Pantheon entr${extra.length === 1 ? 'y' : 'ies'} in the same list cannot carry options`),
@@ -197,9 +196,9 @@ export function describePluginOptionsReachability(plugins) {
197
196
  form: stringOnly ? 'string' : 'object',
198
197
  detail: stringOnly
199
198
  ? 'the Pantheon V2 entry is a bare string, so the host passes no options and ' +
200
- 'context_pruner/memory_injection cannot be enabled; the object form ' +
199
+ 'context_pruner cannot be enabled; the object form ' +
201
200
  '{"package": …, "options": {…}} makes them reachable'
202
201
  : 'the Pantheon V2 entry has no "options" object, so the host passes an empty ' +
203
- 'options bag and context_pruner/memory_injection stay at their defaults',
202
+ 'options bag and context_pruner stays at its default',
204
203
  }
205
204
  }
@@ -31,6 +31,7 @@ const REQUIRED_PAYLOAD = [
31
31
  'package/src/pantheon/v2-bridge.ts',
32
32
  'package/src/plugins/tui/dist/tui.js',
33
33
  'package/src/plugins/tui/dist/server.js',
34
+ 'package/src/plugins/tui/dist/server-v2.js',
34
35
  'package/bin/pantheon-init.mjs',
35
36
  'package/scripts/doctor.mjs',
36
37
  'package/scripts/node-engine-policy.mjs',