pantheon-opencode 1.6.2-beta.2 → 1.6.2-beta.4

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 (57) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +56 -16
  3. package/bin/pantheon-init.mjs +68 -13
  4. package/package.json +10 -3
  5. package/plugin.json +1 -1
  6. package/prompts/README.md +58 -0
  7. package/prompts/debug-issue.prompt.md +46 -0
  8. package/prompts/dynamic/agora-generated.txt +38 -0
  9. package/prompts/dynamic/orchestrate-generated.txt +51 -0
  10. package/prompts/focus.prompt.md +42 -0
  11. package/prompts/implement-feature.prompt.md +39 -0
  12. package/prompts/optimize-database.prompt.md +58 -0
  13. package/prompts/orchestrate-with-zeus.prompt.md +441 -0
  14. package/prompts/plan-architecture.prompt.md +59 -0
  15. package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
  16. package/prompts/quick-plan-large-feature.prompt.md +197 -0
  17. package/prompts/semantic-summarize.md +50 -0
  18. package/prompts/sketch.prompt.md +91 -0
  19. package/prompts/subtask.prompt.md +131 -0
  20. package/pyproject.toml +1 -1
  21. package/scripts/decision-router-budget.mjs +781 -0
  22. package/scripts/decision-router.mjs +297 -0
  23. package/scripts/install/component-selection.mjs +9 -4
  24. package/scripts/install/decision-router-config.mjs +432 -0
  25. package/scripts/install/health-check.mjs +20 -11
  26. package/scripts/install/interactive.mjs +78 -14
  27. package/scripts/install/interrupt.mjs +4 -3
  28. package/scripts/install/migrate.mjs +123 -72
  29. package/scripts/install/opencode.mjs +162 -114
  30. package/scripts/install/plan.mjs +8 -1
  31. package/scripts/install/state.mjs +12 -0
  32. package/scripts/install/strings.mjs +10 -0
  33. package/scripts/install/venv.mjs +34 -17
  34. package/scripts/restore.mjs +22 -10
  35. package/scripts/test-opencode-v2-sandbox.sh +10 -6
  36. package/src/agents/zeus.md +12 -0
  37. package/src/pantheon/local-decision-agents.ts +170 -0
  38. package/src/pantheon/local-decision-budget.ts +1043 -0
  39. package/src/pantheon/local-decision-egress-gate.ts +264 -0
  40. package/src/pantheon/local-decision-prompt.ts +123 -0
  41. package/src/pantheon/local-decision-provider-matrix.ts +92 -0
  42. package/src/pantheon/local-decision-provider-protocol.ts +335 -0
  43. package/src/pantheon/local-decision-provider.internal.ts +260 -0
  44. package/src/pantheon/local-decision-router.ts +225 -0
  45. package/src/pantheon/local-decision-skills.ts +171 -0
  46. package/src/pantheon/local-decision-tool.ts +126 -0
  47. package/src/pantheon/local-decision-turn.ts +338 -0
  48. package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
  49. package/src/pantheon/local-orchestration.ts +322 -0
  50. package/src/pantheon/pantheon-decision-catalog.ts +101 -0
  51. package/src/pantheon/v2-tools.ts +15 -14
  52. package/src/plugin-v2.ts +52 -19
  53. package/src/plugin.ts +4 -0
  54. package/src/plugins/tui/dist/tui-v2.js +3 -3
  55. package/src/plugins/tui/dist/tui.js +1 -1
  56. package/src/plugins/tui/package-lock.json +2 -2
  57. package/src/plugins/tui/package.json +1 -1
@@ -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
  }
@@ -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,14 @@ 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
+ )
1626
1647
  const stats = summary.opencode
1627
1648
  // Per-call baseline. `stats` is the module-level cumulative summary, so the
1628
1649
  // consistency guard must compare against THIS call's delta, not the total.
@@ -1631,6 +1652,7 @@ async function installPass(
1631
1652
  let plannedChanges = 0
1632
1653
  let planFiles = []
1633
1654
  let planTotals = null
1655
+ let runtimeEffects = null
1634
1656
  let removalPaths = []
1635
1657
  // MCP servers this pass seeds into opencode.json, in write order. Filled by
1636
1658
  // applyMcpServerEntries so the preview names exactly what the apply writes.
@@ -1658,6 +1680,23 @@ async function installPass(
1658
1680
  const ownRecorder = opts.recorder ? null : createRecorder()
1659
1681
  const preview = dryRun && ownRecorder ? ownRecorder : null
1660
1682
  let recorder = opts.recorder ?? ownRecorder.recorder
1683
+ const baseRecorder = recorder
1684
+ const markAppliedWrite = () => {
1685
+ if (dryRun) return
1686
+ if (_lastRun) {
1687
+ _lastRun.target = target
1688
+ _lastRun.applied = true
1689
+ }
1690
+ if (typeof opts.onWrite === 'function') {
1691
+ opts.onWrite({ target, backupDir: _lastRun?.backupDir ?? null })
1692
+ }
1693
+ }
1694
+ if (!dryRun) {
1695
+ recorder = (change) => {
1696
+ baseRecorder(change)
1697
+ if (['create', 'update', 'remove'].includes(change?.action)) markAppliedWrite()
1698
+ }
1699
+ }
1661
1700
  // Test-only failure seam: throw after N recorded writes so the failure path is
1662
1701
  // deterministic. Never reachable from production callers (opts.deps is not a
1663
1702
  // CLI flag) and never applied to the internal dry plan pass.
@@ -1671,7 +1710,9 @@ async function installPass(
1671
1710
  }
1672
1711
  }
1673
1712
  // Track this apply so the wrapper can report the paths written on a failure.
1674
- if (!dryRun) _lastRun = { target, entries: ownRecorder?.entries ?? [], backupDir: null }
1713
+ if (!dryRun) {
1714
+ _lastRun = { target, entries: ownRecorder?.entries ?? [], backupDir: null, applied: false }
1715
+ }
1675
1716
 
1676
1717
  // V1/V2 dual-version awareness (Phase 3): the installer builds a unified
1677
1718
  // config, then applies V2-native migration (migrateV1toV2) when
@@ -1739,21 +1780,23 @@ async function installPass(
1739
1780
  const forceInteractive = opts.interactive === true
1740
1781
  const forceHeadless = opts.headless === true
1741
1782
  const autoYes = opts.yes === true
1742
- const interactive = forceInteractive || (stdinTTY && !forceHeadless)
1783
+ const interactive = !autoYes && (forceInteractive || (stdinTTY && !forceHeadless))
1743
1784
 
1744
1785
  if (interactive && !dryRun) {
1745
1786
  const { runInteractiveInstall } = await import('./interactive.mjs')
1746
1787
  const hasRequestedComponents = Array.isArray(opts.requestedComponents)
1747
1788
  const promptComponents = hasRequestedComponents ? opts.requestedComponents : components
1748
- const promptDefaults = hasRequestedComponents
1749
- ? []
1750
- : opts.noMcp
1751
- ? COMPONENT_NAMES.filter((component) => component !== 'runtime')
1752
- : COMPONENT_NAMES
1789
+ const promptDefaults = (hasRequestedComponents ? opts.requestedComponents : components).filter(
1790
+ (component) => !opts.noMcp || component !== 'runtime',
1791
+ )
1753
1792
  const result = await runInteractiveInstall({
1754
1793
  components: promptComponents,
1755
1794
  defaultComponents: promptDefaults,
1756
1795
  noMcp: opts.noMcp === true,
1796
+ getDecisionRouterConfig: (selection) => {
1797
+ const selectionTarget = selection === 'project' ? process.cwd() : target
1798
+ return readState(selectionTarget)?.decision_router
1799
+ },
1757
1800
  prompts: opts.deps?.prompts,
1758
1801
  isTTY: opts.deps?.isTTY,
1759
1802
  })
@@ -1764,6 +1807,7 @@ async function installPass(
1764
1807
  // recorded target is where the user was installing, not where a file was
1765
1808
  // written (nothing was written either way).
1766
1809
  const selectedTarget = result.target === 'project' ? process.cwd() : target
1810
+ opts.onTargetResolved?.(selectedTarget)
1767
1811
 
1768
1812
  if (result.canceled) {
1769
1813
  // The named point is what makes the message explainable. The interactive
@@ -1780,20 +1824,6 @@ async function installPass(
1780
1824
  }
1781
1825
  }
1782
1826
 
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
1827
  // Map target selection to actual path
1798
1828
  const newComponents = [...result.components].filter(
1799
1829
  (component) => !opts.noMcp || component !== 'runtime',
@@ -1802,6 +1832,17 @@ async function installPass(
1802
1832
  for (const c of newComponents) componentSet.add(c)
1803
1833
 
1804
1834
  target = selectedTarget
1835
+ decisionRouterConfig = migrateDecisionRouterConfig(result.decisionRouterConfig)
1836
+ opts.decisionRouterConfig = decisionRouterConfig
1837
+ if (!dryRun && _lastRun) _lastRun.target = target
1838
+ }
1839
+
1840
+ // Reject invalid or newer persisted migration schemas before planning or
1841
+ // applying any target writes. The migration runner repeats this check at the
1842
+ // actual migration point to catch a marker changed during the install.
1843
+ const migrationPreflight = runMigrations(target, { dryRun: true })
1844
+ if (migrationPreflight.status === 'unsupported' || migrationPreflight.status === 'invalid') {
1845
+ throw new Error(migrationPreflight.message)
1805
1846
  }
1806
1847
 
1807
1848
  // Product defaults live in code (PRODUCT_CONFIG_DEFAULTS). A repository-root
@@ -1894,9 +1935,8 @@ async function installPass(
1894
1935
  let planned
1895
1936
  try {
1896
1937
  // 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.
1938
+ // Every apply computes and shows the concise plan before writing. --yes
1939
+ // suppresses prompts, not the summary or integrity/drift checks.
1900
1940
  planned = await installOpenCode(target, true, clean, [...componentSet], {
1901
1941
  ...opts,
1902
1942
  // Hand the RESOLVED generation to the plan pass. Re-resolving would
@@ -1907,7 +1947,7 @@ async function installPass(
1907
1947
  planTimestamp,
1908
1948
  planOnly: true,
1909
1949
  quiet: autoYes,
1910
- quietPlan: autoYes,
1950
+ quietPlan: false,
1911
1951
  })
1912
1952
  } finally {
1913
1953
  Object.assign(stats, savedStats)
@@ -1938,7 +1978,7 @@ async function installPass(
1938
1978
  if (drift.length > 0) {
1939
1979
  warning('Reviewed install plan drifted; no files were written.')
1940
1980
  for (const item of drift) warning(` ${item}`)
1941
- return { ...stats, applied: false, reason: 'drift', drift }
1981
+ return { ...stats, applied: false, reason: 'drift', drift, target }
1942
1982
  }
1943
1983
  }
1944
1984
 
@@ -1959,18 +1999,18 @@ async function installPass(
1959
1999
  // prints nothing, so this is the single place that guarantees the
1960
2000
  // message exists exactly once, and it names the point.
1961
2001
  if (typeof injected === 'function') notice(S.canceledAt(S.cancelPoints.review))
1962
- return { ...stats, applied: false, reason: 'canceled', cancelPoint: 'review' }
2002
+ return { ...stats, applied: false, reason: 'canceled', cancelPoint: 'review', target }
1963
2003
  }
1964
2004
  if (!accepted) {
1965
2005
  // Answering "No" is not a cancel: it used to reach the caller as a
1966
2006
  // silent `reason: 'declined'` and exit 0 with "Nothing applied." and
1967
2007
  // no explanation at all.
1968
2008
  notice(S.declinedAt(S.cancelPoints.review))
1969
- return { ...stats, applied: false, reason: 'declined', cancelPoint: 'review' }
2009
+ return { ...stats, applied: false, reason: 'declined', cancelPoint: 'review', target }
1970
2010
  }
1971
2011
  } else {
1972
2012
  notice(S.planOnlyNoYes)
1973
- return { ...stats, applied: false, reason: 'not-authorized' }
2013
+ return { ...stats, applied: false, reason: 'not-authorized', target }
1974
2014
  }
1975
2015
  }
1976
2016
 
@@ -1988,6 +2028,7 @@ async function installPass(
1988
2028
  applied: false,
1989
2029
  reason: 'drift',
1990
2030
  drift: drifted.map((p) => displayPath(target, p)),
2031
+ target,
1991
2032
  }
1992
2033
  }
1993
2034
  reviewedRemovals = new Set((planned?.removals ?? []).map((filePath) => resolve(filePath)))
@@ -2499,6 +2540,10 @@ async function installPass(
2499
2540
  // UI object into the runtime module.
2500
2541
  onVenvDone: () => advancePhase(S.settingUpRuntime),
2501
2542
  onHealthDone: () => advancePhase(S.runningHealthChecks),
2543
+ onRuntimeEffects: (effects) => {
2544
+ runtimeEffects = effects
2545
+ },
2546
+ verbose: opts.verbose === true,
2502
2547
  },
2503
2548
  stats,
2504
2549
  opts.deps,
@@ -3085,29 +3130,28 @@ async function installPass(
3085
3130
  advancePhase()
3086
3131
 
3087
3132
  // -----------------------------------------------------------------------
3088
- // 3.5 Run migrations (--components runtime)
3133
+ // 3.5 Run state/schema migrations on every init, independent of runtime
3134
+ // selection. Migration schema has its own marker and remains idempotent.
3089
3135
  // -----------------------------------------------------------------------
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
- }
3136
+ const migrationStep = step(S.runningMigrations)
3137
+ const migration = runMigrations(target, {
3138
+ dryRun,
3139
+ recorder,
3140
+ updatedAt: planTimestamp,
3141
+ })
3142
+ if (migration.status === 'unsupported' || migration.status === 'invalid') {
3143
+ migrationStep(false)
3144
+ throw new Error(migration.message)
3145
+ }
3146
+ migrationStep(true)
3147
+ if (migration.plannedState) projectedState = migration.plannedState
3148
+ if (migration.applied > 0) {
3149
+ success(`Applied ${migration.applied} migration(s)`)
3150
+ for (const msg of migration.messages) {
3151
+ bullet(msg, 1)
3107
3152
  }
3108
- // Counted even when there is nothing to migrate: the phase ran its check.
3109
- advancePhase()
3110
3153
  }
3154
+ advancePhase()
3111
3155
 
3112
3156
  if (opts.preset && dryRun) {
3113
3157
  const { writeActivePreset } = await import('./model-picker.mjs')
@@ -3137,6 +3181,7 @@ async function installPass(
3137
3181
  const packageVersion = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).version
3138
3182
  let state = projectedState ?? readState(target)
3139
3183
  if (!state) state = createInitialState(packageVersion, planTimestamp)
3184
+ state.decision_router = decisionRouterConfig
3140
3185
  state.pantheon_version = packageVersion
3141
3186
  state.updated_at = planTimestamp
3142
3187
  state.schema_version = 2
@@ -3168,6 +3213,7 @@ async function installPass(
3168
3213
  // names `applyMcpServerEntries` seeded in THIS pass, in write order (empty
3169
3214
  // when the runtime component is not selected or failed its prerequisites).
3170
3215
  plan.mcpServers = mcpServers
3216
+ if (componentSet.has('runtime')) plan.runtimeEffects = runtimeEffects
3171
3217
  plan.versionAssumed = versionAssumed
3172
3218
  planFiles = plan.files
3173
3219
  planTotals = plan.totals
@@ -3205,9 +3251,8 @@ async function installPass(
3205
3251
  // were written"), never one line per file — the gauge already answered
3206
3252
  // "is it moving?" and per-file detail is opt-in via --verbose. `[DRY-RUN]`
3207
3253
  // 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.
3254
+ // `--yes` still exposes the concise preview before this apply pass runs;
3255
+ // only explicit quiet callers (JSON/doctor) suppress it.
3211
3256
  if (!opts.quietPlan) {
3212
3257
  const verbose = opts.verbose === true
3213
3258
  const planText = formatChangePlan(target, plan, { perFile: verbose })
@@ -3231,43 +3276,6 @@ async function installPass(
3231
3276
  // entries are only added when the Python runtime is actually healthy)
3232
3277
  // -----------------------------------------------------------------------
3233
3278
 
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
3279
  // -----------------------------------------------------------------------
3272
3280
  // 5. V1 model preset selection (--components agents). V2 ignores the legacy
3273
3281
  // active-preset marker, so it has no profile wizard or --preset support.
@@ -3275,12 +3283,20 @@ async function installPass(
3275
3283
  // Q1 default "herdar do chat" (inherit) writes no active-preset.json —
3276
3284
  // delegates inherit the parent chat model (native inheritance).
3277
3285
  // -----------------------------------------------------------------------
3278
- if (interactive && stdinTTY && version === 'v1' && !dryRun && !autoYes && !opts.preset) {
3286
+ if (
3287
+ interactive &&
3288
+ stdinTTY &&
3289
+ version === 'v1' &&
3290
+ !dryRun &&
3291
+ !autoYes &&
3292
+ !opts.preset &&
3293
+ stats.errors === 0
3294
+ ) {
3279
3295
  const { runInitWizard } = await import('./model-picker.mjs')
3280
3296
  await runInitWizard({ presetDir: target, logger: console, prompts: opts.deps?.prompts })
3281
3297
  }
3282
3298
 
3283
- if (opts.preset && !dryRun) {
3299
+ if (opts.preset && !dryRun && stats.errors === 0) {
3284
3300
  const { writeActivePreset } = await import('./model-picker.mjs')
3285
3301
  writeActivePreset(target, opts.preset, { source: 'cli', updatedAt: planTimestamp, recorder })
3286
3302
  }
@@ -3292,7 +3308,7 @@ async function installPass(
3292
3308
  // blocks on stdin and the default behavior is unchanged. A failure here
3293
3309
  // must never fail the install: vision stays optional.
3294
3310
  // -----------------------------------------------------------------------
3295
- if (interactive && !dryRun && !autoYes) {
3311
+ if (interactive && !dryRun && !autoYes && stats.errors === 0) {
3296
3312
  const runVisionPrompt =
3297
3313
  opts.deps?.runVisionPrompt ?? (await import('./vision-prompt.mjs')).runVisionPrompt
3298
3314
  try {
@@ -3302,13 +3318,8 @@ async function installPass(
3302
3318
  }
3303
3319
  }
3304
3320
 
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
3321
+ // Record component state even on a degraded runtime result so doctor and a
3322
+ // later init can distinguish a failed runtime from an installed one. The
3312
3323
  // postinstall marker can predate `init` and start with every component
3313
3324
  // pending; leaving it untouched made a healthy beta install look incomplete
3314
3325
  // to `doctor` forever. Unselected components retain their previous state.
@@ -3319,6 +3330,7 @@ async function installPass(
3319
3330
  throw new Error('Installation state exists but cannot be read; refusing to replace it')
3320
3331
  }
3321
3332
  state ??= createInitialState(packageVersion, planTimestamp)
3333
+ state.decision_router = decisionRouterConfig
3322
3334
  state.pantheon_version = packageVersion
3323
3335
  state.updated_at = planTimestamp
3324
3336
  for (const component of ['agents', 'skills', 'plugins', 'runtime']) {
@@ -3348,10 +3360,17 @@ async function installPass(
3348
3360
  verifiedFiles,
3349
3361
  })
3350
3362
  writeState(target, state, { updatedAt: planTimestamp })
3363
+ markAppliedWrite()
3351
3364
  stateStep(true)
3352
3365
  advancePhase()
3353
3366
  }
3354
3367
 
3368
+ // Fail closed only after the degraded state is persisted. The caller records
3369
+ // the partial application and reports its exact target/recovery backup.
3370
+ if (stats.errors > 0) {
3371
+ throw new Error(`installation completed with ${stats.errors} error(s); see output above`)
3372
+ }
3373
+
3355
3374
  // The apply gauge ends before the human summary; a dry run already closed it
3356
3375
  // before its plan block (`done()` is idempotent). A preview must NOT print
3357
3376
  // the installed banner: bin/pantheon-init prints the preview-only line.
@@ -3359,6 +3378,33 @@ async function installPass(
3359
3378
  if (!interactive && !dryRun && !opts.planOnly) {
3360
3379
  printSummary(target, ['opencode'], stats)
3361
3380
  }
3381
+ if (interactive && !dryRun && !opts.planOnly) {
3382
+ endGaugeLine()
3383
+ const created = stats.created
3384
+ const skipped = stats.skipped
3385
+ const warnings = stats.warnings ?? 0
3386
+ process.stdout.write('\n')
3387
+ process.stdout.write(` ${colors.bold(colors.green('Installation complete'))}\n`)
3388
+ process.stdout.write(
3389
+ ` ${colors.dim('\u2500'.repeat(Math.min(process.stdout.columns || 60, 60)))}\n`,
3390
+ )
3391
+ process.stdout.write(` [OK] ${created} component(s) installed\n`)
3392
+ if (skipped > 0)
3393
+ process.stdout.write(` ${colors.dim('\u2014')} ${skipped} already up-to-date\n`)
3394
+ if (warnings > 0)
3395
+ process.stdout.write(
3396
+ ` [WARN] ${warnings} warning(s) — run 'pantheon-opencode doctor' for details\n`,
3397
+ )
3398
+ process.stdout.write('\n')
3399
+ process.stdout.write(` ${colors.bold('Next steps:')}\n`)
3400
+ process.stdout.write(` ${colors.dim('\u2022')} Configure agents in opencode.json\n`)
3401
+ process.stdout.write(` ${colors.dim('\u2022')} Run 'pantheon-opencode doctor' to verify\n`)
3402
+ process.stdout.write(
3403
+ ` ${colors.dim('\u2022')} Run 'opencode' to start using Pantheon agents\n`,
3404
+ )
3405
+ process.stdout.write('\n')
3406
+ printWorktreeGuidance({ projectRoot: process.cwd(), interactive: true })
3407
+ }
3362
3408
 
3363
3409
  // Beta 11 Setup phase 3: report whether this call APPLIED, so the caller can
3364
3410
  // avoid a success banner for a plan-only / unauthorized run. The dry pass also
@@ -3373,6 +3419,7 @@ async function installPass(
3373
3419
  files: planFiles,
3374
3420
  totals: planTotals,
3375
3421
  mcpServers,
3422
+ runtimeEffects,
3376
3423
  removals: removalPaths,
3377
3424
  target,
3378
3425
  openCodeVersion: version,
@@ -3386,6 +3433,7 @@ async function installPass(
3386
3433
  applied: true,
3387
3434
  reason: 'applied',
3388
3435
  target,
3436
+ runtimeEffects,
3389
3437
  openCodeVersion: version,
3390
3438
  configAdvisories,
3391
3439
  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 ' +
@@ -9,6 +9,7 @@
9
9
  * {
10
10
  * "schema_version": 2,
11
11
  * "pantheon_version": "1.1.1",
12
+ * "migration_schema_version": "3.19.2",
12
13
  * "previous_version": "1.1.0",
13
14
  * "updated_at": "2026-07-26T10:30:00Z",
14
15
  * "migration_checkpoint": null,
@@ -30,10 +31,12 @@
30
31
 
31
32
  import { existsSync, mkdirSync, readFileSync } from 'node:fs'
32
33
  import { join, resolve } from 'node:path'
34
+ import { migrateDecisionRouterConfig } from './decision-router-config.mjs'
33
35
  import { assertNoSymlinkAncestors, writeFileAtomically } from './verify.mjs'
34
36
 
35
37
  const STATE_FILE = 'install-state.json'
36
38
  const STATE_DIR = '.pantheon'
39
+ export const MIGRATION_SCHEMA_VERSION = '3.19.2'
37
40
 
38
41
  function emptyFileInventory(legacyUnknown = true) {
39
42
  return {
@@ -69,6 +72,7 @@ export function createInitialState(version, updatedAt = new Date().toISOString()
69
72
  return {
70
73
  schema_version: 2,
71
74
  pantheon_version: version || '0.0.0',
75
+ migration_schema_version: MIGRATION_SCHEMA_VERSION,
72
76
  previous_version: null,
73
77
  updated_at: updatedAt,
74
78
  migration_checkpoint: null,
@@ -79,6 +83,7 @@ export function createInitialState(version, updatedAt = new Date().toISOString()
79
83
  plugins: { version: 1, status: 'pending' },
80
84
  runtime: { version: 1, status: 'pending' },
81
85
  },
86
+ decision_router: migrateDecisionRouterConfig(undefined),
82
87
  file_inventory: emptyFileInventory(false),
83
88
  }
84
89
  }
@@ -122,6 +127,7 @@ export function upgradeStateV1toV2(state) {
122
127
  return {
123
128
  schema_version: 2,
124
129
  pantheon_version: state.pantheon_version || state.version || 'unknown',
130
+ migration_schema_version: state.migration_schema_version ?? null,
125
131
  previous_version: state.previous_version || null,
126
132
  updated_at: state.updated_at || now,
127
133
  migration_checkpoint: null,
@@ -135,6 +141,7 @@ export function upgradeStateV1toV2(state) {
135
141
  plugins: { version: 1, status: 'unknown' },
136
142
  runtime: { version: 1, status: 'unknown' },
137
143
  },
144
+ decision_router: migrateDecisionRouterConfig(state.decision_router),
138
145
  file_inventory: normalizeFileInventory(state),
139
146
  }
140
147
  }
@@ -153,6 +160,7 @@ export function upgradeStateV1toV2(state) {
153
160
  * @returns {object} the same state object with required collections present
154
161
  */
155
162
  function ensureV2Shape(state) {
163
+ if (!Object.hasOwn(state, 'migration_schema_version')) state.migration_schema_version = null
156
164
  if (!Array.isArray(state.applied_migrations)) state.applied_migrations = []
157
165
  if (
158
166
  !state.components ||
@@ -169,6 +177,7 @@ function ensureV2Shape(state) {
169
177
  ) {
170
178
  state.file_inventory = invalidFileInventory()
171
179
  }
180
+ state.decision_router = migrateDecisionRouterConfig(state.decision_router)
172
181
  return state
173
182
  }
174
183
 
@@ -199,6 +208,9 @@ export function writeState(target, state, options = {}) {
199
208
  assertNoSymlinkAncestors(stateFile)
200
209
  state.updated_at = options.updatedAt ?? new Date().toISOString()
201
210
  state.schema_version = 2
211
+ if (!Object.hasOwn(state, 'migration_schema_version')) state.migration_schema_version = null
212
+ if (!Array.isArray(state.applied_migrations)) state.applied_migrations = []
213
+ state.decision_router = migrateDecisionRouterConfig(state.decision_router)
202
214
  if (!Object.hasOwn(state, 'file_inventory')) {
203
215
  state.file_inventory = emptyFileInventory(true)
204
216
  } else if (