pantheon-opencode 1.6.2-beta.1 → 1.6.2-beta.11

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 (145) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +236 -60
  3. package/README.pt-BR.md +19 -1
  4. package/bin/pantheon-init.mjs +195 -13
  5. package/package.json +11 -3
  6. package/plugin.json +1 -1
  7. package/prompts/README.md +58 -0
  8. package/prompts/debug-issue.prompt.md +46 -0
  9. package/prompts/dynamic/agora-generated.txt +38 -0
  10. package/prompts/dynamic/orchestrate-generated.txt +51 -0
  11. package/prompts/focus.prompt.md +42 -0
  12. package/prompts/implement-feature.prompt.md +39 -0
  13. package/prompts/optimize-database.prompt.md +58 -0
  14. package/prompts/orchestrate-with-zeus.prompt.md +441 -0
  15. package/prompts/plan-architecture.prompt.md +59 -0
  16. package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
  17. package/prompts/quick-plan-large-feature.prompt.md +197 -0
  18. package/prompts/semantic-summarize.md +50 -0
  19. package/prompts/sketch.prompt.md +91 -0
  20. package/prompts/subtask.prompt.md +131 -0
  21. package/pyproject.toml +1 -1
  22. package/scripts/decision-router-budget.mjs +780 -0
  23. package/scripts/decision-router-v2-budget.mjs +218 -0
  24. package/scripts/decision-router-v2-egress.mjs +272 -0
  25. package/scripts/decision-router.mjs +758 -0
  26. package/scripts/docs-check-changelog.mjs +5 -3
  27. package/scripts/install/component-selection.mjs +9 -4
  28. package/scripts/install/decision-layer-preview.mjs +376 -0
  29. package/scripts/install/decision-router-config.mjs +560 -0
  30. package/scripts/install/health-check.mjs +20 -11
  31. package/scripts/install/interactive.mjs +103 -14
  32. package/scripts/install/interrupt.mjs +4 -3
  33. package/scripts/install/migrate.mjs +123 -72
  34. package/scripts/install/opencode.mjs +178 -122
  35. package/scripts/install/plan.mjs +8 -1
  36. package/scripts/install/plugin.mjs +4 -3
  37. package/scripts/install/state.mjs +12 -0
  38. package/scripts/install/strings.mjs +22 -0
  39. package/scripts/install/venv.mjs +34 -17
  40. package/scripts/mcp_resources.py +11 -9
  41. package/scripts/release-gates.mjs +6 -82
  42. package/scripts/release-notes.mjs +30 -7
  43. package/scripts/restore.mjs +22 -10
  44. package/scripts/sync-tui.mjs +3 -3
  45. package/scripts/test-opencode-v2-sandbox.sh +10 -6
  46. package/scripts/versioning.mjs +41 -5
  47. package/src/agents/aphrodite.md +6 -1
  48. package/src/agents/apollo.md +1 -0
  49. package/src/agents/athena.md +1 -0
  50. package/src/agents/demeter.md +1 -1
  51. package/src/agents/gaia.md +1 -0
  52. package/src/agents/hephaestus.md +1 -1
  53. package/src/agents/hermes.md +8 -10
  54. package/src/agents/iris.md +1 -1
  55. package/src/agents/mnemosyne.md +1 -0
  56. package/src/agents/nyx.md +1 -1
  57. package/src/agents/prometheus.md +1 -1
  58. package/src/agents/talos.md +6 -1
  59. package/src/agents/themis.md +1 -1
  60. package/src/agents/zeus.md +52 -62
  61. package/src/mcp/eval_store.py +11 -4
  62. package/src/mcp/mcp_resources.py +11 -9
  63. package/src/mcp/memory_mcp.py +293 -150
  64. package/src/pantheon/cost-command.ts +30 -133
  65. package/src/pantheon/jev-decision-tool.ts +359 -0
  66. package/src/pantheon/jev-decisions.ts +625 -0
  67. package/src/pantheon/local-decision-agents.ts +170 -0
  68. package/src/pantheon/local-decision-budget.ts +1046 -0
  69. package/src/pantheon/local-decision-egress-gate.ts +144 -0
  70. package/src/pantheon/local-decision-prompt.ts +256 -0
  71. package/src/pantheon/local-decision-provider-matrix.ts +44 -0
  72. package/src/pantheon/local-decision-router.ts +225 -0
  73. package/src/pantheon/local-decision-skills.ts +281 -0
  74. package/src/pantheon/local-decision-tool.ts +160 -0
  75. package/src/pantheon/local-decision-turn.ts +101 -0
  76. package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
  77. package/src/pantheon/local-orchestration.ts +322 -0
  78. package/src/pantheon/model-pricing.ts +1 -536
  79. package/src/pantheon/pantheon-decision-catalog.ts +101 -0
  80. package/src/pantheon/v2-decision-budget.ts +456 -0
  81. package/src/pantheon/v2-decision-contracts.ts +300 -0
  82. package/src/pantheon/v2-decision-egress.ts +203 -0
  83. package/src/pantheon/v2-decision-events.ts +180 -0
  84. package/src/pantheon/v2-decision-heuristic.ts +121 -0
  85. package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
  86. package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
  87. package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
  88. package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
  89. package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
  90. package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
  91. package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
  92. package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
  93. package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
  94. package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
  95. package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
  96. package/src/pantheon/v2-decision-points.ts +242 -0
  97. package/src/pantheon/v2-decision-policy.ts +166 -0
  98. package/src/pantheon/v2-decision-premises.ts +146 -0
  99. package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
  100. package/src/pantheon/v2-decision-rank.ts +91 -0
  101. package/src/pantheon/v2-decision-registry.ts +391 -0
  102. package/src/pantheon/v2-decision-resource-ids.ts +127 -0
  103. package/src/pantheon/v2-decision-shadow.ts +123 -0
  104. package/src/pantheon/v2-decision-telemetry.ts +214 -0
  105. package/src/pantheon/v2-decision-verify.ts +51 -0
  106. package/src/pantheon/v2-hook-engine.ts +307 -0
  107. package/src/pantheon/v2-native-decisions.ts +365 -0
  108. package/src/pantheon/v2-shell-hooks.ts +66 -2
  109. package/src/pantheon/v2-tools.ts +38 -15
  110. package/src/plugin-v2.ts +419 -26
  111. package/src/plugin.ts +4 -0
  112. package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
  113. package/src/plugins/tui/dist/server-v2.d.ts +19 -11
  114. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
  115. package/src/plugins/tui/dist/server-v2.js +19 -666
  116. package/src/plugins/tui/dist/server-v2.js.map +1 -1
  117. package/src/plugins/tui/dist/tui-v2.d.ts +11 -203
  118. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  119. package/src/plugins/tui/dist/tui-v2.js +187 -1917
  120. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  121. package/src/plugins/tui/dist/tui.js +1 -1
  122. package/src/plugins/tui/package-lock.json +17 -2
  123. package/src/plugins/tui/package.json +4 -2
  124. package/src/plugins/tui/src/cost-data.ts +607 -0
  125. package/src/plugins/tui/src/index-v2.tsx +213 -54
  126. package/src/plugins/tui/src/model-pricing.ts +536 -0
  127. package/src/plugins/tui/src/server-v2.ts +18 -838
  128. package/src/plugins/tui/tsdown.config.ts +28 -6
  129. package/src/plugins/tui/dist/quota-adapters.d.ts +0 -89
  130. package/src/plugins/tui/dist/quota-adapters.d.ts.map +0 -1
  131. package/src/plugins/tui/dist/quota-adapters.js +0 -1142
  132. package/src/plugins/tui/dist/quota-adapters.js.map +0 -1
  133. package/src/plugins/tui/dist/quota-cli.d.ts +0 -17
  134. package/src/plugins/tui/dist/quota-cli.d.ts.map +0 -1
  135. package/src/plugins/tui/dist/quota-cli.js +0 -184
  136. package/src/plugins/tui/dist/quota-cli.js.map +0 -1
  137. package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js +0 -390
  138. package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +0 -1
  139. package/src/plugins/tui/src/go-key-diagnostic-ui.ts +0 -100
  140. package/src/plugins/tui/src/go-key-diagnostic.ts +0 -125
  141. package/src/plugins/tui/src/quota-adapters.ts +0 -1598
  142. package/src/plugins/tui/src/quota-cli.ts +0 -237
  143. package/src/plugins/tui/src/quota-rpc.ts +0 -209
  144. package/src/plugins/tui/src/quota-v2-model.ts +0 -1032
  145. package/src/plugins/tui/src/quota-v2.tsx +0 -986
@@ -50,6 +50,7 @@ import {
50
50
  validateMcpV1toV2Source,
51
51
  } from './config-migration.mjs'
52
52
  import { resolveGlobalConfigDirectory } from './config-paths.mjs'
53
+ import { migrateDecisionRouterConfig } from './decision-router-config.mjs'
53
54
  import { componentForInstalledPath, updateFileInventory } from './file-inventory.mjs'
54
55
  import { healthCheck } from './health-check.mjs'
55
56
  import {
@@ -60,7 +61,7 @@ import {
60
61
  mcpPermissionAliases,
61
62
  normalizeMcpPermissionSegment,
62
63
  } from './mcp-permissions.mjs'
63
- import { detectVersion, runMigrations } from './migrate.mjs'
64
+ import { runMigrations } from './migrate.mjs'
64
65
  import { describeSharedState } from './opencode-state.mjs'
65
66
  import { DRY_RUN_PROBE_TIMEOUT_MS, resolveOpenCodeVersion } from './opencode-version.mjs'
66
67
  import {
@@ -102,16 +103,6 @@ import {
102
103
  import { setupVenv, venvPythonPath } from './venv.mjs'
103
104
  import { assertNoSymlinkAncestors, assertPathWithin, assertSafeRemoval } from './verify.mjs'
104
105
 
105
- const COMPONENT_NAMES = [
106
- 'agents',
107
- 'skills',
108
- 'instructions',
109
- 'prompts',
110
- 'commands',
111
- 'plugins',
112
- 'runtime',
113
- ]
114
-
115
106
  /**
116
107
  * The ordered phases one install invocation really runs, derived from the
117
108
  * FINAL component selection (the interactive wizard may have changed it) and
@@ -144,7 +135,7 @@ export function planInstallPhases({ components, dryRun }) {
144
135
  if (!dryRun) phases.push(S.runningHealthChecks)
145
136
  }
146
137
  phases.push(S.writingConfiguration)
147
- if (selected.has('runtime')) phases.push(S.runningMigrations)
138
+ phases.push(S.runningMigrations)
148
139
  if (!dryRun) phases.push(S.recordingState)
149
140
  return phases
150
141
  }
@@ -856,13 +847,13 @@ export function deduplicatePluginReferences(refs) {
856
847
  /**
857
848
  * Register the copied Pantheon TUI plugin in the V2 `plugins` list.
858
849
  *
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".
850
+ * The OpenCode 2.x host does not load a local plugin folder by free discovery —
851
+ * only entries listed in `config.plugins` are loaded (sandbox probe evidence:
852
+ * no entry → the copy's server half never attaches; with the entry the host
853
+ * logs `loading plugin id=…/pantheon-tui`). The server half is what wires the
854
+ * TUI runtime's reactive channel, so without this registration a
855
+ * postinstall/sync that re-copies the payload after `init` leaves a sidebar
856
+ * that mounts dead (the "mudo panel" symptom).
866
857
  *
867
858
  * Idempotent: the existing entry for the copy (same identity) is retained
868
859
  * and kept after the core plugin, while every other entry stays in place.
@@ -1355,6 +1346,8 @@ export function setupRuntimePhase(
1355
1346
  reviewedSnapshots = null,
1356
1347
  onVenvDone = null,
1357
1348
  onHealthDone = null,
1349
+ onRuntimeEffects = null,
1350
+ verbose = false,
1358
1351
  },
1359
1352
  stats,
1360
1353
  deps = {},
@@ -1365,14 +1358,27 @@ export function setupRuntimePhase(
1365
1358
  let stopProgress
1366
1359
  try {
1367
1360
  stopProgress = spinner(S.settingUpRuntime)
1361
+ let setupResult
1368
1362
  try {
1369
- setup(target, {
1363
+ setupResult = setup(target, {
1370
1364
  dryRun,
1371
1365
  force: clean,
1366
+ verbose,
1372
1367
  recorder,
1373
1368
  reviewedRemovals,
1374
1369
  reviewedSnapshots,
1375
1370
  })
1371
+ const pythonExists = existsSync(venvPythonPath(target))
1372
+ const runtimeEffects = setupResult?.runtimeEffects ?? {
1373
+ venv:
1374
+ clean && existsSync(join(target, '.venv'))
1375
+ ? 'recreate'
1376
+ : pythonExists
1377
+ ? 'reuse'
1378
+ : 'create',
1379
+ dependencies: 'install',
1380
+ }
1381
+ onRuntimeEffects?.(runtimeEffects)
1376
1382
  } finally {
1377
1383
  // Count the phase even when setup throws: it DID run (and failed). The
1378
1384
  // failure is reported below as a warning, not as a missing phase.
@@ -1410,6 +1416,7 @@ export function setupRuntimePhase(
1410
1416
  stopProgress = null
1411
1417
  warning(`${health.failed.length} check(s) failed — review above`)
1412
1418
  stats.warnings += health.failed.length
1419
+ stats.errors += 1
1413
1420
  return false
1414
1421
  }
1415
1422
  stopProgress(true)
@@ -1420,6 +1427,7 @@ export function setupRuntimePhase(
1420
1427
  error(S.runtimeFailed(err.message))
1421
1428
  warning(S.runtimeSkippedMcp)
1422
1429
  stats.warnings += 1
1430
+ stats.errors += 1
1423
1431
  return false
1424
1432
  }
1425
1433
  }
@@ -1567,7 +1575,7 @@ export async function installOpenCode(
1567
1575
  target,
1568
1576
  dryRun = false,
1569
1577
  clean = false,
1570
- components = ['agents', 'skills', 'instructions', 'commands', 'plugins', 'runtime'],
1578
+ components = ['agents', 'skills', 'instructions', 'commands', 'plugins'],
1571
1579
  opts = {},
1572
1580
  ) {
1573
1581
  // Reset per-call so a stale run can never leak into a fresh failure report.
@@ -1582,6 +1590,15 @@ export async function installOpenCode(
1582
1590
  _activeGauge?.fail(err instanceof Error ? err.message : String(err))
1583
1591
  const run = dryRun ? null : _lastRun
1584
1592
  if (run) {
1593
+ try {
1594
+ err.installOutcome = {
1595
+ target: run.target,
1596
+ applied: run.applied,
1597
+ backupDir: run.backupDir,
1598
+ }
1599
+ } catch {
1600
+ // An exotic frozen error must not hide the installer failure.
1601
+ }
1585
1602
  const S = strings()
1586
1603
  const paths = summarizeChanges(run.entries ?? [])
1587
1604
  .files.filter((f) => f.action !== ACTIONS.UNCHANGED && f.action !== ACTIONS.CONFLICT)
@@ -1608,7 +1625,7 @@ async function installPass(
1608
1625
  target,
1609
1626
  dryRun = false,
1610
1627
  clean = false,
1611
- components = ['agents', 'skills', 'instructions', 'commands', 'plugins', 'runtime'],
1628
+ components = ['agents', 'skills', 'instructions', 'commands', 'plugins'],
1612
1629
  opts = {},
1613
1630
  ) {
1614
1631
  if (opts.configPreview !== undefined && opts.configPreview !== null && !dryRun) {
@@ -1619,10 +1636,16 @@ async function installPass(
1619
1636
  if (!target) {
1620
1637
  target = resolveGlobalConfigDirectory(process.env)
1621
1638
  }
1639
+ opts.onTargetResolved?.(target)
1622
1640
 
1623
1641
  const componentSet = new Set(
1624
1642
  opts.noMcp ? components.filter((component) => component !== 'runtime') : components,
1625
1643
  )
1644
+ let decisionRouterConfig = migrateDecisionRouterConfig(
1645
+ opts.decisionRouterConfig ?? readState(target)?.decision_router,
1646
+ )
1647
+ /** Wizard-confirmed Jev activation (target + caps), surfaced on the result. */
1648
+ let decisionModelActivation = null
1626
1649
  const stats = summary.opencode
1627
1650
  // Per-call baseline. `stats` is the module-level cumulative summary, so the
1628
1651
  // consistency guard must compare against THIS call's delta, not the total.
@@ -1631,6 +1654,7 @@ async function installPass(
1631
1654
  let plannedChanges = 0
1632
1655
  let planFiles = []
1633
1656
  let planTotals = null
1657
+ let runtimeEffects = null
1634
1658
  let removalPaths = []
1635
1659
  // MCP servers this pass seeds into opencode.json, in write order. Filled by
1636
1660
  // applyMcpServerEntries so the preview names exactly what the apply writes.
@@ -1658,6 +1682,23 @@ async function installPass(
1658
1682
  const ownRecorder = opts.recorder ? null : createRecorder()
1659
1683
  const preview = dryRun && ownRecorder ? ownRecorder : null
1660
1684
  let recorder = opts.recorder ?? ownRecorder.recorder
1685
+ const baseRecorder = recorder
1686
+ const markAppliedWrite = () => {
1687
+ if (dryRun) return
1688
+ if (_lastRun) {
1689
+ _lastRun.target = target
1690
+ _lastRun.applied = true
1691
+ }
1692
+ if (typeof opts.onWrite === 'function') {
1693
+ opts.onWrite({ target, backupDir: _lastRun?.backupDir ?? null })
1694
+ }
1695
+ }
1696
+ if (!dryRun) {
1697
+ recorder = (change) => {
1698
+ baseRecorder(change)
1699
+ if (['create', 'update', 'remove'].includes(change?.action)) markAppliedWrite()
1700
+ }
1701
+ }
1661
1702
  // Test-only failure seam: throw after N recorded writes so the failure path is
1662
1703
  // deterministic. Never reachable from production callers (opts.deps is not a
1663
1704
  // CLI flag) and never applied to the internal dry plan pass.
@@ -1671,7 +1712,9 @@ async function installPass(
1671
1712
  }
1672
1713
  }
1673
1714
  // Track this apply so the wrapper can report the paths written on a failure.
1674
- if (!dryRun) _lastRun = { target, entries: ownRecorder?.entries ?? [], backupDir: null }
1715
+ if (!dryRun) {
1716
+ _lastRun = { target, entries: ownRecorder?.entries ?? [], backupDir: null, applied: false }
1717
+ }
1675
1718
 
1676
1719
  // V1/V2 dual-version awareness (Phase 3): the installer builds a unified
1677
1720
  // config, then applies V2-native migration (migrateV1toV2) when
@@ -1731,7 +1774,10 @@ async function installPass(
1731
1774
  // this notice cannot drift from what the plugin reports; the notice says
1732
1775
  // so, because the live list is a superset that grows at runtime. Advisory:
1733
1776
  // a V2 install is a supported configuration, not a failure.
1734
- notice(formatV2CapabilityNotice())
1777
+ // Default-quiet: the eleven-fact block is install *detail*, not an action
1778
+ // the user must take, so it prints only under --verbose (the recorded
1779
+ // run-state keeps it either way).
1780
+ if (opts.verbose === true) notice(formatV2CapabilityNotice())
1735
1781
  }
1736
1782
 
1737
1783
  // Interactive mode handling
@@ -1739,21 +1785,23 @@ async function installPass(
1739
1785
  const forceInteractive = opts.interactive === true
1740
1786
  const forceHeadless = opts.headless === true
1741
1787
  const autoYes = opts.yes === true
1742
- const interactive = forceInteractive || (stdinTTY && !forceHeadless)
1788
+ const interactive = !autoYes && (forceInteractive || (stdinTTY && !forceHeadless))
1743
1789
 
1744
1790
  if (interactive && !dryRun) {
1745
1791
  const { runInteractiveInstall } = await import('./interactive.mjs')
1746
1792
  const hasRequestedComponents = Array.isArray(opts.requestedComponents)
1747
1793
  const promptComponents = hasRequestedComponents ? opts.requestedComponents : components
1748
- const promptDefaults = hasRequestedComponents
1749
- ? []
1750
- : opts.noMcp
1751
- ? COMPONENT_NAMES.filter((component) => component !== 'runtime')
1752
- : COMPONENT_NAMES
1794
+ const promptDefaults = (hasRequestedComponents ? opts.requestedComponents : components).filter(
1795
+ (component) => !opts.noMcp || component !== 'runtime',
1796
+ )
1753
1797
  const result = await runInteractiveInstall({
1754
1798
  components: promptComponents,
1755
1799
  defaultComponents: promptDefaults,
1756
1800
  noMcp: opts.noMcp === true,
1801
+ getDecisionRouterConfig: (selection) => {
1802
+ const selectionTarget = selection === 'project' ? process.cwd() : target
1803
+ return readState(selectionTarget)?.decision_router
1804
+ },
1757
1805
  prompts: opts.deps?.prompts,
1758
1806
  isTTY: opts.deps?.isTTY,
1759
1807
  })
@@ -1764,6 +1812,7 @@ async function installPass(
1764
1812
  // recorded target is where the user was installing, not where a file was
1765
1813
  // written (nothing was written either way).
1766
1814
  const selectedTarget = result.target === 'project' ? process.cwd() : target
1815
+ opts.onTargetResolved?.(selectedTarget)
1767
1816
 
1768
1817
  if (result.canceled) {
1769
1818
  // The named point is what makes the message explainable. The interactive
@@ -1780,20 +1829,6 @@ async function installPass(
1780
1829
  }
1781
1830
  }
1782
1831
 
1783
- if (!result.confirmed) {
1784
- // Answering "No" at the pre-install confirmation is not the prompt
1785
- // library's cancel channel, so nothing was printed yet: this is the one
1786
- // message, and it names the point.
1787
- notice(S.canceledAt(S.cancelPoints.confirmation))
1788
- return {
1789
- ...stats,
1790
- applied: false,
1791
- reason: 'canceled',
1792
- cancelPoint: 'confirmation',
1793
- target: selectedTarget,
1794
- }
1795
- }
1796
-
1797
1832
  // Map target selection to actual path
1798
1833
  const newComponents = [...result.components].filter(
1799
1834
  (component) => !opts.noMcp || component !== 'runtime',
@@ -1802,6 +1837,18 @@ async function installPass(
1802
1837
  for (const c of newComponents) componentSet.add(c)
1803
1838
 
1804
1839
  target = selectedTarget
1840
+ decisionRouterConfig = migrateDecisionRouterConfig(result.decisionRouterConfig)
1841
+ opts.decisionRouterConfig = decisionRouterConfig
1842
+ decisionModelActivation = result.decisionModelActivation ?? null
1843
+ if (!dryRun && _lastRun) _lastRun.target = target
1844
+ }
1845
+
1846
+ // Reject invalid or newer persisted migration schemas before planning or
1847
+ // applying any target writes. The migration runner repeats this check at the
1848
+ // actual migration point to catch a marker changed during the install.
1849
+ const migrationPreflight = runMigrations(target, { dryRun: true })
1850
+ if (migrationPreflight.status === 'unsupported' || migrationPreflight.status === 'invalid') {
1851
+ throw new Error(migrationPreflight.message)
1805
1852
  }
1806
1853
 
1807
1854
  // Product defaults live in code (PRODUCT_CONFIG_DEFAULTS). A repository-root
@@ -1894,9 +1941,8 @@ async function installPass(
1894
1941
  let planned
1895
1942
  try {
1896
1943
  // Use the LIVE selection: the wizard above may have changed componentSet.
1897
- // An AUTHORIZED apply (`--yes`) is not a preview: compute the plan +
1898
- // snapshots but stay silent. The gate path (no `--yes`) still prints the
1899
- // plan for the review / decline preview.
1944
+ // Every apply computes and shows the concise plan before writing. --yes
1945
+ // suppresses prompts, not the summary or integrity/drift checks.
1900
1946
  planned = await installOpenCode(target, true, clean, [...componentSet], {
1901
1947
  ...opts,
1902
1948
  // Hand the RESOLVED generation to the plan pass. Re-resolving would
@@ -1907,7 +1953,7 @@ async function installPass(
1907
1953
  planTimestamp,
1908
1954
  planOnly: true,
1909
1955
  quiet: autoYes,
1910
- quietPlan: autoYes,
1956
+ quietPlan: false,
1911
1957
  })
1912
1958
  } finally {
1913
1959
  Object.assign(stats, savedStats)
@@ -1938,7 +1984,7 @@ async function installPass(
1938
1984
  if (drift.length > 0) {
1939
1985
  warning('Reviewed install plan drifted; no files were written.')
1940
1986
  for (const item of drift) warning(` ${item}`)
1941
- return { ...stats, applied: false, reason: 'drift', drift }
1987
+ return { ...stats, applied: false, reason: 'drift', drift, target }
1942
1988
  }
1943
1989
  }
1944
1990
 
@@ -1959,18 +2005,18 @@ async function installPass(
1959
2005
  // prints nothing, so this is the single place that guarantees the
1960
2006
  // message exists exactly once, and it names the point.
1961
2007
  if (typeof injected === 'function') notice(S.canceledAt(S.cancelPoints.review))
1962
- return { ...stats, applied: false, reason: 'canceled', cancelPoint: 'review' }
2008
+ return { ...stats, applied: false, reason: 'canceled', cancelPoint: 'review', target }
1963
2009
  }
1964
2010
  if (!accepted) {
1965
2011
  // Answering "No" is not a cancel: it used to reach the caller as a
1966
2012
  // silent `reason: 'declined'` and exit 0 with "Nothing applied." and
1967
2013
  // no explanation at all.
1968
2014
  notice(S.declinedAt(S.cancelPoints.review))
1969
- return { ...stats, applied: false, reason: 'declined', cancelPoint: 'review' }
2015
+ return { ...stats, applied: false, reason: 'declined', cancelPoint: 'review', target }
1970
2016
  }
1971
2017
  } else {
1972
2018
  notice(S.planOnlyNoYes)
1973
- return { ...stats, applied: false, reason: 'not-authorized' }
2019
+ return { ...stats, applied: false, reason: 'not-authorized', target }
1974
2020
  }
1975
2021
  }
1976
2022
 
@@ -1988,6 +2034,7 @@ async function installPass(
1988
2034
  applied: false,
1989
2035
  reason: 'drift',
1990
2036
  drift: drifted.map((p) => displayPath(target, p)),
2037
+ target,
1991
2038
  }
1992
2039
  }
1993
2040
  reviewedRemovals = new Set((planned?.removals ?? []).map((filePath) => resolve(filePath)))
@@ -2499,6 +2546,10 @@ async function installPass(
2499
2546
  // UI object into the runtime module.
2500
2547
  onVenvDone: () => advancePhase(S.settingUpRuntime),
2501
2548
  onHealthDone: () => advancePhase(S.runningHealthChecks),
2549
+ onRuntimeEffects: (effects) => {
2550
+ runtimeEffects = effects
2551
+ },
2552
+ verbose: opts.verbose === true,
2502
2553
  },
2503
2554
  stats,
2504
2555
  opts.deps,
@@ -3085,29 +3136,28 @@ async function installPass(
3085
3136
  advancePhase()
3086
3137
 
3087
3138
  // -----------------------------------------------------------------------
3088
- // 3.5 Run migrations (--components runtime)
3139
+ // 3.5 Run state/schema migrations on every init, independent of runtime
3140
+ // selection. Migration schema has its own marker and remains idempotent.
3089
3141
  // -----------------------------------------------------------------------
3090
- if (componentSet.has('runtime')) {
3091
- const currentVersion = detectVersion(target)
3092
- if (currentVersion) {
3093
- const migrationStep = step(S.runningMigrations)
3094
- const migration = runMigrations(target, currentVersion, {
3095
- dryRun,
3096
- recorder,
3097
- updatedAt: planTimestamp,
3098
- })
3099
- migrationStep(true)
3100
- if (migration.plannedState) projectedState = migration.plannedState
3101
- if (migration.applied > 0) {
3102
- success(`Applied ${migration.applied} migration(s)`)
3103
- for (const msg of migration.messages) {
3104
- bullet(msg, 1)
3105
- }
3106
- }
3142
+ const migrationStep = step(S.runningMigrations)
3143
+ const migration = runMigrations(target, {
3144
+ dryRun,
3145
+ recorder,
3146
+ updatedAt: planTimestamp,
3147
+ })
3148
+ if (migration.status === 'unsupported' || migration.status === 'invalid') {
3149
+ migrationStep(false)
3150
+ throw new Error(migration.message)
3151
+ }
3152
+ migrationStep(true)
3153
+ if (migration.plannedState) projectedState = migration.plannedState
3154
+ if (migration.applied > 0) {
3155
+ success(`Applied ${migration.applied} migration(s)`)
3156
+ for (const msg of migration.messages) {
3157
+ bullet(msg, 1)
3107
3158
  }
3108
- // Counted even when there is nothing to migrate: the phase ran its check.
3109
- advancePhase()
3110
3159
  }
3160
+ advancePhase()
3111
3161
 
3112
3162
  if (opts.preset && dryRun) {
3113
3163
  const { writeActivePreset } = await import('./model-picker.mjs')
@@ -3137,6 +3187,7 @@ async function installPass(
3137
3187
  const packageVersion = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).version
3138
3188
  let state = projectedState ?? readState(target)
3139
3189
  if (!state) state = createInitialState(packageVersion, planTimestamp)
3190
+ state.decision_router = decisionRouterConfig
3140
3191
  state.pantheon_version = packageVersion
3141
3192
  state.updated_at = planTimestamp
3142
3193
  state.schema_version = 2
@@ -3168,6 +3219,7 @@ async function installPass(
3168
3219
  // names `applyMcpServerEntries` seeded in THIS pass, in write order (empty
3169
3220
  // when the runtime component is not selected or failed its prerequisites).
3170
3221
  plan.mcpServers = mcpServers
3222
+ if (componentSet.has('runtime')) plan.runtimeEffects = runtimeEffects
3171
3223
  plan.versionAssumed = versionAssumed
3172
3224
  planFiles = plan.files
3173
3225
  planTotals = plan.totals
@@ -3205,9 +3257,8 @@ async function installPass(
3205
3257
  // were written"), never one line per file — the gauge already answered
3206
3258
  // "is it moving?" and per-file detail is opt-in via --verbose. `[DRY-RUN]`
3207
3259
  // marks the header only; it no longer prefixes every line.
3208
- // An internal snapshot pass on the apply path (`quietPlan`, e.g. an
3209
- // authorized `--yes` run) computes the plan and snapshots but must NOT
3210
- // echo it — a real apply is not a dry run.
3260
+ // `--yes` still exposes the concise preview before this apply pass runs;
3261
+ // only explicit quiet callers (JSON/doctor) suppress it.
3211
3262
  if (!opts.quietPlan) {
3212
3263
  const verbose = opts.verbose === true
3213
3264
  const planText = formatChangePlan(target, plan, { perFile: verbose })
@@ -3231,43 +3282,6 @@ async function installPass(
3231
3282
  // entries are only added when the Python runtime is actually healthy)
3232
3283
  // -----------------------------------------------------------------------
3233
3284
 
3234
- if (interactive && !dryRun) {
3235
- endGaugeLine()
3236
- const created = stats.created
3237
- const skipped = stats.skipped
3238
- const errors = stats.errors
3239
- const warnings = stats.warnings ?? 0
3240
-
3241
- process.stdout.write('\n')
3242
- process.stdout.write(
3243
- ` ${colors.bold(
3244
- errors > 0
3245
- ? colors.yellow('Installation completed with errors')
3246
- : colors.green('Installation complete'),
3247
- )}\n`,
3248
- )
3249
- process.stdout.write(
3250
- ` ${colors.dim('\u2500'.repeat(Math.min(process.stdout.columns || 60, 60)))}\n`,
3251
- )
3252
- process.stdout.write(` [OK] ${created} component(s) installed\n`)
3253
- if (skipped > 0)
3254
- process.stdout.write(` ${colors.dim('\u2014')} ${skipped} already up-to-date\n`)
3255
- if (errors > 0) process.stdout.write(` [WARN] ${errors} error(s) encountered\n`)
3256
- if (warnings > 0)
3257
- process.stdout.write(
3258
- ` [WARN] ${warnings} warning(s) — run 'pantheon-opencode doctor' for details\n`,
3259
- )
3260
- process.stdout.write('\n')
3261
- process.stdout.write(` ${colors.bold('Next steps:')}\n`)
3262
- process.stdout.write(` ${colors.dim('\u2022')} Configure agents in opencode.json\n`)
3263
- process.stdout.write(` ${colors.dim('\u2022')} Run 'pantheon-opencode doctor' to verify\n`)
3264
- process.stdout.write(
3265
- ` ${colors.dim('\u2022')} Run 'opencode' to start using Pantheon agents\n`,
3266
- )
3267
- process.stdout.write('\n')
3268
- printWorktreeGuidance({ projectRoot: process.cwd(), interactive: true })
3269
- }
3270
-
3271
3285
  // -----------------------------------------------------------------------
3272
3286
  // 5. V1 model preset selection (--components agents). V2 ignores the legacy
3273
3287
  // active-preset marker, so it has no profile wizard or --preset support.
@@ -3275,12 +3289,20 @@ async function installPass(
3275
3289
  // Q1 default "herdar do chat" (inherit) writes no active-preset.json —
3276
3290
  // delegates inherit the parent chat model (native inheritance).
3277
3291
  // -----------------------------------------------------------------------
3278
- if (interactive && stdinTTY && version === 'v1' && !dryRun && !autoYes && !opts.preset) {
3292
+ if (
3293
+ interactive &&
3294
+ stdinTTY &&
3295
+ version === 'v1' &&
3296
+ !dryRun &&
3297
+ !autoYes &&
3298
+ !opts.preset &&
3299
+ stats.errors === 0
3300
+ ) {
3279
3301
  const { runInitWizard } = await import('./model-picker.mjs')
3280
3302
  await runInitWizard({ presetDir: target, logger: console, prompts: opts.deps?.prompts })
3281
3303
  }
3282
3304
 
3283
- if (opts.preset && !dryRun) {
3305
+ if (opts.preset && !dryRun && stats.errors === 0) {
3284
3306
  const { writeActivePreset } = await import('./model-picker.mjs')
3285
3307
  writeActivePreset(target, opts.preset, { source: 'cli', updatedAt: planTimestamp, recorder })
3286
3308
  }
@@ -3292,7 +3314,7 @@ async function installPass(
3292
3314
  // blocks on stdin and the default behavior is unchanged. A failure here
3293
3315
  // must never fail the install: vision stays optional.
3294
3316
  // -----------------------------------------------------------------------
3295
- if (interactive && !dryRun && !autoYes) {
3317
+ if (interactive && !dryRun && !autoYes && stats.errors === 0) {
3296
3318
  const runVisionPrompt =
3297
3319
  opts.deps?.runVisionPrompt ?? (await import('./vision-prompt.mjs')).runVisionPrompt
3298
3320
  try {
@@ -3302,13 +3324,8 @@ async function installPass(
3302
3324
  }
3303
3325
  }
3304
3326
 
3305
- // Fail-closed: accumulated stats.errors (bad sources, missing requirements,
3306
- // failed health checks) must never masquerade as a successful installation.
3307
- if (stats.errors > 0) {
3308
- throw new Error(`installation completed with ${stats.errors} error(s); see output above`)
3309
- }
3310
-
3311
- // Record the component state only after the install has completed. The
3327
+ // Record component state even on a degraded runtime result so doctor and a
3328
+ // later init can distinguish a failed runtime from an installed one. The
3312
3329
  // postinstall marker can predate `init` and start with every component
3313
3330
  // pending; leaving it untouched made a healthy beta install look incomplete
3314
3331
  // to `doctor` forever. Unselected components retain their previous state.
@@ -3319,6 +3336,7 @@ async function installPass(
3319
3336
  throw new Error('Installation state exists but cannot be read; refusing to replace it')
3320
3337
  }
3321
3338
  state ??= createInitialState(packageVersion, planTimestamp)
3339
+ state.decision_router = decisionRouterConfig
3322
3340
  state.pantheon_version = packageVersion
3323
3341
  state.updated_at = planTimestamp
3324
3342
  for (const component of ['agents', 'skills', 'plugins', 'runtime']) {
@@ -3348,10 +3366,17 @@ async function installPass(
3348
3366
  verifiedFiles,
3349
3367
  })
3350
3368
  writeState(target, state, { updatedAt: planTimestamp })
3369
+ markAppliedWrite()
3351
3370
  stateStep(true)
3352
3371
  advancePhase()
3353
3372
  }
3354
3373
 
3374
+ // Fail closed only after the degraded state is persisted. The caller records
3375
+ // the partial application and reports its exact target/recovery backup.
3376
+ if (stats.errors > 0) {
3377
+ throw new Error(`installation completed with ${stats.errors} error(s); see output above`)
3378
+ }
3379
+
3355
3380
  // The apply gauge ends before the human summary; a dry run already closed it
3356
3381
  // before its plan block (`done()` is idempotent). A preview must NOT print
3357
3382
  // the installed banner: bin/pantheon-init prints the preview-only line.
@@ -3359,6 +3384,33 @@ async function installPass(
3359
3384
  if (!interactive && !dryRun && !opts.planOnly) {
3360
3385
  printSummary(target, ['opencode'], stats)
3361
3386
  }
3387
+ if (interactive && !dryRun && !opts.planOnly) {
3388
+ endGaugeLine()
3389
+ const created = stats.created
3390
+ const skipped = stats.skipped
3391
+ const warnings = stats.warnings ?? 0
3392
+ process.stdout.write('\n')
3393
+ process.stdout.write(` ${colors.bold(colors.green('Installation complete'))}\n`)
3394
+ process.stdout.write(
3395
+ ` ${colors.dim('\u2500'.repeat(Math.min(process.stdout.columns || 60, 60)))}\n`,
3396
+ )
3397
+ process.stdout.write(` [OK] ${created} component(s) installed\n`)
3398
+ if (skipped > 0)
3399
+ process.stdout.write(` ${colors.dim('\u2014')} ${skipped} already up-to-date\n`)
3400
+ if (warnings > 0)
3401
+ process.stdout.write(
3402
+ ` [WARN] ${warnings} warning(s) — run 'pantheon-opencode doctor' for details\n`,
3403
+ )
3404
+ process.stdout.write('\n')
3405
+ process.stdout.write(` ${colors.bold('Next steps:')}\n`)
3406
+ process.stdout.write(` ${colors.dim('\u2022')} Configure agents in opencode.json\n`)
3407
+ process.stdout.write(` ${colors.dim('\u2022')} Run 'pantheon-opencode doctor' to verify\n`)
3408
+ process.stdout.write(
3409
+ ` ${colors.dim('\u2022')} Run 'opencode' to start using Pantheon agents\n`,
3410
+ )
3411
+ process.stdout.write('\n')
3412
+ printWorktreeGuidance({ projectRoot: process.cwd(), interactive: true })
3413
+ }
3362
3414
 
3363
3415
  // Beta 11 Setup phase 3: report whether this call APPLIED, so the caller can
3364
3416
  // avoid a success banner for a plan-only / unauthorized run. The dry pass also
@@ -3373,19 +3425,23 @@ async function installPass(
3373
3425
  files: planFiles,
3374
3426
  totals: planTotals,
3375
3427
  mcpServers,
3428
+ runtimeEffects,
3376
3429
  removals: removalPaths,
3377
3430
  target,
3378
3431
  openCodeVersion: version,
3379
3432
  versionAssumed,
3380
3433
  configAdvisories,
3381
3434
  v2Capabilities: version === 'v2' ? v2Capabilities() : null,
3435
+ decisionModelActivation,
3382
3436
  pluginOptions: v2PluginOptions,
3383
3437
  }
3384
3438
  : {
3385
3439
  ...stats,
3386
3440
  applied: true,
3387
3441
  reason: 'applied',
3442
+ decisionModelActivation,
3388
3443
  target,
3444
+ runtimeEffects,
3389
3445
  openCodeVersion: version,
3390
3446
  configAdvisories,
3391
3447
  v2Capabilities: version === 'v2' ? v2Capabilities() : null,
@@ -232,7 +232,7 @@ export function displayPath(target, filePath) {
232
232
  * assumes V1 and may diverge from an apply on a 2.x host.
233
233
  *
234
234
  * @param {string} target - install target (used to relativize paths)
235
- * @param {{ files: object[], totals: object, mcpServers?: string[], versionAssumed?: boolean }} plan
235
+ * @param {{ files: object[], totals: object, mcpServers?: string[], runtimeEffects?: { venv: string, dependencies: string }, versionAssumed?: boolean }} plan
236
236
  * @param {{ perFile?: boolean }} [options] - `perFile: false` renders the
237
237
  * summary (totals + MCP servers + "No files were written.") without the
238
238
  * per-file list. That is the DEFAULT dry-run surface; the per-file list is
@@ -261,6 +261,13 @@ export function formatChangePlan(target, plan, { perFile = true } = {}) {
261
261
  names.length === 0 ? 'none (already configured or runtime skipped)' : names.join(', ')
262
262
  lines.push(` MCP servers (${names.length}): ${servers}`)
263
263
  }
264
+ if (plan.runtimeEffects) {
265
+ const { venv, dependencies } = plan.runtimeEffects
266
+ lines.push(` Python virtual environment: ${venv}`)
267
+ lines.push(
268
+ ` MCP dependencies: ${dependencies === 'install' ? 'install (may download packages)' : dependencies}`,
269
+ )
270
+ }
264
271
  if (plan.versionAssumed) {
265
272
  lines.push(
266
273
  ' OpenCode host generation unknown — this plan assumes V1 and may diverge from the ' +
@@ -146,9 +146,10 @@ export function copyPluginFiles(
146
146
  packageJson.exports['./tui'] = packageJson.exports['./tui-v2']
147
147
  }
148
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".
149
+ // In the V2 copy it must point at the V2 server entry so the host attaches
150
+ // the copy's V2 server half (the TUI reactive channel depends on it);
151
+ // otherwise the host loads the V1 server stub of the previous generation's
152
+ // payload.
152
153
  if (version === 'v2' && packageJson.exports?.['./server-v2']) {
153
154
  packageJson.exports['./server'] = packageJson.exports['./server-v2']
154
155
  }