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

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 (71) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +41 -29
  3. package/README.pt-BR.md +12 -1
  4. package/bin/pantheon-init.mjs +51 -13
  5. package/package.json +2 -1
  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/install/component-selection.mjs +9 -4
  23. package/scripts/install/health-check.mjs +20 -11
  24. package/scripts/install/interactive.mjs +9 -16
  25. package/scripts/install/interrupt.mjs +4 -3
  26. package/scripts/install/migrate.mjs +123 -72
  27. package/scripts/install/opencode.mjs +150 -114
  28. package/scripts/install/plan.mjs +8 -1
  29. package/scripts/install/state.mjs +7 -0
  30. package/scripts/install/strings.mjs +6 -0
  31. package/scripts/install/venv.mjs +34 -17
  32. package/scripts/restore.mjs +22 -10
  33. package/scripts/test-opencode-v2-sandbox.sh +10 -6
  34. package/src/pantheon/cost-command.ts +30 -133
  35. package/src/pantheon/model-pricing.ts +1 -536
  36. package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
  37. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +749 -0
  38. package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +1 -0
  39. package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -1
  40. package/src/plugins/tui/dist/quota-adapters.js +1 -1
  41. package/src/plugins/tui/dist/{quota-rpc-UL2HuFRJ.js → quota-rpc-DMmXBhBe.js} +295 -1
  42. package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +1 -0
  43. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -1
  44. package/src/plugins/tui/dist/server-v2.js +135 -12
  45. package/src/plugins/tui/dist/server-v2.js.map +1 -1
  46. package/src/plugins/tui/dist/tui-v2.d.ts +132 -5
  47. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  48. package/src/plugins/tui/dist/tui-v2.js +3720 -337
  49. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  50. package/src/plugins/tui/dist/tui.js +1 -1
  51. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +118 -0
  52. package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +1 -0
  53. package/src/plugins/tui/dist/usage-history-worker.js +25 -0
  54. package/src/plugins/tui/dist/usage-history-worker.js.map +1 -0
  55. package/src/plugins/tui/package-lock.json +17 -2
  56. package/src/plugins/tui/package.json +4 -2
  57. package/src/plugins/tui/src/cost-data.ts +607 -0
  58. package/src/plugins/tui/src/index-v2.tsx +32 -0
  59. package/src/plugins/tui/src/model-pricing.ts +536 -0
  60. package/src/plugins/tui/src/quota-rpc.ts +164 -0
  61. package/src/plugins/tui/src/quota-v2-model.ts +2 -2
  62. package/src/plugins/tui/src/quota-v2.tsx +338 -86
  63. package/src/plugins/tui/src/server-v2.ts +159 -15
  64. package/src/plugins/tui/src/usage-history-contract.ts +217 -0
  65. package/src/plugins/tui/src/usage-history-validation.ts +104 -0
  66. package/src/plugins/tui/src/usage-history-view.tsx +236 -0
  67. package/src/plugins/tui/src/usage-history-worker.ts +25 -0
  68. package/src/plugins/tui/src/usage-view-model.ts +272 -0
  69. package/src/plugins/tui/tsconfig.typecheck.json +6 -1
  70. package/src/plugins/tui/tsdown.config.ts +36 -4
  71. package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +0 -1
@@ -60,7 +60,7 @@ import {
60
60
  mcpPermissionAliases,
61
61
  normalizeMcpPermissionSegment,
62
62
  } from './mcp-permissions.mjs'
63
- import { detectVersion, runMigrations } from './migrate.mjs'
63
+ import { runMigrations } from './migrate.mjs'
64
64
  import { describeSharedState } from './opencode-state.mjs'
65
65
  import { DRY_RUN_PROBE_TIMEOUT_MS, resolveOpenCodeVersion } from './opencode-version.mjs'
66
66
  import {
@@ -102,16 +102,6 @@ import {
102
102
  import { setupVenv, venvPythonPath } from './venv.mjs'
103
103
  import { assertNoSymlinkAncestors, assertPathWithin, assertSafeRemoval } from './verify.mjs'
104
104
 
105
- const COMPONENT_NAMES = [
106
- 'agents',
107
- 'skills',
108
- 'instructions',
109
- 'prompts',
110
- 'commands',
111
- 'plugins',
112
- 'runtime',
113
- ]
114
-
115
105
  /**
116
106
  * The ordered phases one install invocation really runs, derived from the
117
107
  * FINAL component selection (the interactive wizard may have changed it) and
@@ -144,7 +134,7 @@ export function planInstallPhases({ components, dryRun }) {
144
134
  if (!dryRun) phases.push(S.runningHealthChecks)
145
135
  }
146
136
  phases.push(S.writingConfiguration)
147
- if (selected.has('runtime')) phases.push(S.runningMigrations)
137
+ phases.push(S.runningMigrations)
148
138
  if (!dryRun) phases.push(S.recordingState)
149
139
  return phases
150
140
  }
@@ -1355,6 +1345,8 @@ export function setupRuntimePhase(
1355
1345
  reviewedSnapshots = null,
1356
1346
  onVenvDone = null,
1357
1347
  onHealthDone = null,
1348
+ onRuntimeEffects = null,
1349
+ verbose = false,
1358
1350
  },
1359
1351
  stats,
1360
1352
  deps = {},
@@ -1365,14 +1357,27 @@ export function setupRuntimePhase(
1365
1357
  let stopProgress
1366
1358
  try {
1367
1359
  stopProgress = spinner(S.settingUpRuntime)
1360
+ let setupResult
1368
1361
  try {
1369
- setup(target, {
1362
+ setupResult = setup(target, {
1370
1363
  dryRun,
1371
1364
  force: clean,
1365
+ verbose,
1372
1366
  recorder,
1373
1367
  reviewedRemovals,
1374
1368
  reviewedSnapshots,
1375
1369
  })
1370
+ const pythonExists = existsSync(venvPythonPath(target))
1371
+ const runtimeEffects = setupResult?.runtimeEffects ?? {
1372
+ venv:
1373
+ clean && existsSync(join(target, '.venv'))
1374
+ ? 'recreate'
1375
+ : pythonExists
1376
+ ? 'reuse'
1377
+ : 'create',
1378
+ dependencies: 'install',
1379
+ }
1380
+ onRuntimeEffects?.(runtimeEffects)
1376
1381
  } finally {
1377
1382
  // Count the phase even when setup throws: it DID run (and failed). The
1378
1383
  // failure is reported below as a warning, not as a missing phase.
@@ -1410,6 +1415,7 @@ export function setupRuntimePhase(
1410
1415
  stopProgress = null
1411
1416
  warning(`${health.failed.length} check(s) failed — review above`)
1412
1417
  stats.warnings += health.failed.length
1418
+ stats.errors += 1
1413
1419
  return false
1414
1420
  }
1415
1421
  stopProgress(true)
@@ -1420,6 +1426,7 @@ export function setupRuntimePhase(
1420
1426
  error(S.runtimeFailed(err.message))
1421
1427
  warning(S.runtimeSkippedMcp)
1422
1428
  stats.warnings += 1
1429
+ stats.errors += 1
1423
1430
  return false
1424
1431
  }
1425
1432
  }
@@ -1567,7 +1574,7 @@ export async function installOpenCode(
1567
1574
  target,
1568
1575
  dryRun = false,
1569
1576
  clean = false,
1570
- components = ['agents', 'skills', 'instructions', 'commands', 'plugins', 'runtime'],
1577
+ components = ['agents', 'skills', 'instructions', 'commands', 'plugins'],
1571
1578
  opts = {},
1572
1579
  ) {
1573
1580
  // Reset per-call so a stale run can never leak into a fresh failure report.
@@ -1582,6 +1589,15 @@ export async function installOpenCode(
1582
1589
  _activeGauge?.fail(err instanceof Error ? err.message : String(err))
1583
1590
  const run = dryRun ? null : _lastRun
1584
1591
  if (run) {
1592
+ try {
1593
+ err.installOutcome = {
1594
+ target: run.target,
1595
+ applied: run.applied,
1596
+ backupDir: run.backupDir,
1597
+ }
1598
+ } catch {
1599
+ // An exotic frozen error must not hide the installer failure.
1600
+ }
1585
1601
  const S = strings()
1586
1602
  const paths = summarizeChanges(run.entries ?? [])
1587
1603
  .files.filter((f) => f.action !== ACTIONS.UNCHANGED && f.action !== ACTIONS.CONFLICT)
@@ -1608,7 +1624,7 @@ async function installPass(
1608
1624
  target,
1609
1625
  dryRun = false,
1610
1626
  clean = false,
1611
- components = ['agents', 'skills', 'instructions', 'commands', 'plugins', 'runtime'],
1627
+ components = ['agents', 'skills', 'instructions', 'commands', 'plugins'],
1612
1628
  opts = {},
1613
1629
  ) {
1614
1630
  if (opts.configPreview !== undefined && opts.configPreview !== null && !dryRun) {
@@ -1619,6 +1635,7 @@ async function installPass(
1619
1635
  if (!target) {
1620
1636
  target = resolveGlobalConfigDirectory(process.env)
1621
1637
  }
1638
+ opts.onTargetResolved?.(target)
1622
1639
 
1623
1640
  const componentSet = new Set(
1624
1641
  opts.noMcp ? components.filter((component) => component !== 'runtime') : components,
@@ -1631,6 +1648,7 @@ async function installPass(
1631
1648
  let plannedChanges = 0
1632
1649
  let planFiles = []
1633
1650
  let planTotals = null
1651
+ let runtimeEffects = null
1634
1652
  let removalPaths = []
1635
1653
  // MCP servers this pass seeds into opencode.json, in write order. Filled by
1636
1654
  // applyMcpServerEntries so the preview names exactly what the apply writes.
@@ -1658,6 +1676,23 @@ async function installPass(
1658
1676
  const ownRecorder = opts.recorder ? null : createRecorder()
1659
1677
  const preview = dryRun && ownRecorder ? ownRecorder : null
1660
1678
  let recorder = opts.recorder ?? ownRecorder.recorder
1679
+ const baseRecorder = recorder
1680
+ const markAppliedWrite = () => {
1681
+ if (dryRun) return
1682
+ if (_lastRun) {
1683
+ _lastRun.target = target
1684
+ _lastRun.applied = true
1685
+ }
1686
+ if (typeof opts.onWrite === 'function') {
1687
+ opts.onWrite({ target, backupDir: _lastRun?.backupDir ?? null })
1688
+ }
1689
+ }
1690
+ if (!dryRun) {
1691
+ recorder = (change) => {
1692
+ baseRecorder(change)
1693
+ if (['create', 'update', 'remove'].includes(change?.action)) markAppliedWrite()
1694
+ }
1695
+ }
1661
1696
  // Test-only failure seam: throw after N recorded writes so the failure path is
1662
1697
  // deterministic. Never reachable from production callers (opts.deps is not a
1663
1698
  // CLI flag) and never applied to the internal dry plan pass.
@@ -1671,7 +1706,9 @@ async function installPass(
1671
1706
  }
1672
1707
  }
1673
1708
  // Track this apply so the wrapper can report the paths written on a failure.
1674
- if (!dryRun) _lastRun = { target, entries: ownRecorder?.entries ?? [], backupDir: null }
1709
+ if (!dryRun) {
1710
+ _lastRun = { target, entries: ownRecorder?.entries ?? [], backupDir: null, applied: false }
1711
+ }
1675
1712
 
1676
1713
  // V1/V2 dual-version awareness (Phase 3): the installer builds a unified
1677
1714
  // config, then applies V2-native migration (migrateV1toV2) when
@@ -1739,17 +1776,15 @@ async function installPass(
1739
1776
  const forceInteractive = opts.interactive === true
1740
1777
  const forceHeadless = opts.headless === true
1741
1778
  const autoYes = opts.yes === true
1742
- const interactive = forceInteractive || (stdinTTY && !forceHeadless)
1779
+ const interactive = !autoYes && (forceInteractive || (stdinTTY && !forceHeadless))
1743
1780
 
1744
1781
  if (interactive && !dryRun) {
1745
1782
  const { runInteractiveInstall } = await import('./interactive.mjs')
1746
1783
  const hasRequestedComponents = Array.isArray(opts.requestedComponents)
1747
1784
  const promptComponents = hasRequestedComponents ? opts.requestedComponents : components
1748
- const promptDefaults = hasRequestedComponents
1749
- ? []
1750
- : opts.noMcp
1751
- ? COMPONENT_NAMES.filter((component) => component !== 'runtime')
1752
- : COMPONENT_NAMES
1785
+ const promptDefaults = (hasRequestedComponents ? opts.requestedComponents : components).filter(
1786
+ (component) => !opts.noMcp || component !== 'runtime',
1787
+ )
1753
1788
  const result = await runInteractiveInstall({
1754
1789
  components: promptComponents,
1755
1790
  defaultComponents: promptDefaults,
@@ -1764,6 +1799,7 @@ async function installPass(
1764
1799
  // recorded target is where the user was installing, not where a file was
1765
1800
  // written (nothing was written either way).
1766
1801
  const selectedTarget = result.target === 'project' ? process.cwd() : target
1802
+ opts.onTargetResolved?.(selectedTarget)
1767
1803
 
1768
1804
  if (result.canceled) {
1769
1805
  // The named point is what makes the message explainable. The interactive
@@ -1780,20 +1816,6 @@ async function installPass(
1780
1816
  }
1781
1817
  }
1782
1818
 
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
1819
  // Map target selection to actual path
1798
1820
  const newComponents = [...result.components].filter(
1799
1821
  (component) => !opts.noMcp || component !== 'runtime',
@@ -1802,6 +1824,15 @@ async function installPass(
1802
1824
  for (const c of newComponents) componentSet.add(c)
1803
1825
 
1804
1826
  target = selectedTarget
1827
+ if (!dryRun && _lastRun) _lastRun.target = target
1828
+ }
1829
+
1830
+ // Reject invalid or newer persisted migration schemas before planning or
1831
+ // applying any target writes. The migration runner repeats this check at the
1832
+ // actual migration point to catch a marker changed during the install.
1833
+ const migrationPreflight = runMigrations(target, { dryRun: true })
1834
+ if (migrationPreflight.status === 'unsupported' || migrationPreflight.status === 'invalid') {
1835
+ throw new Error(migrationPreflight.message)
1805
1836
  }
1806
1837
 
1807
1838
  // Product defaults live in code (PRODUCT_CONFIG_DEFAULTS). A repository-root
@@ -1894,9 +1925,8 @@ async function installPass(
1894
1925
  let planned
1895
1926
  try {
1896
1927
  // 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.
1928
+ // Every apply computes and shows the concise plan before writing. --yes
1929
+ // suppresses prompts, not the summary or integrity/drift checks.
1900
1930
  planned = await installOpenCode(target, true, clean, [...componentSet], {
1901
1931
  ...opts,
1902
1932
  // Hand the RESOLVED generation to the plan pass. Re-resolving would
@@ -1907,7 +1937,7 @@ async function installPass(
1907
1937
  planTimestamp,
1908
1938
  planOnly: true,
1909
1939
  quiet: autoYes,
1910
- quietPlan: autoYes,
1940
+ quietPlan: false,
1911
1941
  })
1912
1942
  } finally {
1913
1943
  Object.assign(stats, savedStats)
@@ -1938,7 +1968,7 @@ async function installPass(
1938
1968
  if (drift.length > 0) {
1939
1969
  warning('Reviewed install plan drifted; no files were written.')
1940
1970
  for (const item of drift) warning(` ${item}`)
1941
- return { ...stats, applied: false, reason: 'drift', drift }
1971
+ return { ...stats, applied: false, reason: 'drift', drift, target }
1942
1972
  }
1943
1973
  }
1944
1974
 
@@ -1959,18 +1989,18 @@ async function installPass(
1959
1989
  // prints nothing, so this is the single place that guarantees the
1960
1990
  // message exists exactly once, and it names the point.
1961
1991
  if (typeof injected === 'function') notice(S.canceledAt(S.cancelPoints.review))
1962
- return { ...stats, applied: false, reason: 'canceled', cancelPoint: 'review' }
1992
+ return { ...stats, applied: false, reason: 'canceled', cancelPoint: 'review', target }
1963
1993
  }
1964
1994
  if (!accepted) {
1965
1995
  // Answering "No" is not a cancel: it used to reach the caller as a
1966
1996
  // silent `reason: 'declined'` and exit 0 with "Nothing applied." and
1967
1997
  // no explanation at all.
1968
1998
  notice(S.declinedAt(S.cancelPoints.review))
1969
- return { ...stats, applied: false, reason: 'declined', cancelPoint: 'review' }
1999
+ return { ...stats, applied: false, reason: 'declined', cancelPoint: 'review', target }
1970
2000
  }
1971
2001
  } else {
1972
2002
  notice(S.planOnlyNoYes)
1973
- return { ...stats, applied: false, reason: 'not-authorized' }
2003
+ return { ...stats, applied: false, reason: 'not-authorized', target }
1974
2004
  }
1975
2005
  }
1976
2006
 
@@ -1988,6 +2018,7 @@ async function installPass(
1988
2018
  applied: false,
1989
2019
  reason: 'drift',
1990
2020
  drift: drifted.map((p) => displayPath(target, p)),
2021
+ target,
1991
2022
  }
1992
2023
  }
1993
2024
  reviewedRemovals = new Set((planned?.removals ?? []).map((filePath) => resolve(filePath)))
@@ -2499,6 +2530,10 @@ async function installPass(
2499
2530
  // UI object into the runtime module.
2500
2531
  onVenvDone: () => advancePhase(S.settingUpRuntime),
2501
2532
  onHealthDone: () => advancePhase(S.runningHealthChecks),
2533
+ onRuntimeEffects: (effects) => {
2534
+ runtimeEffects = effects
2535
+ },
2536
+ verbose: opts.verbose === true,
2502
2537
  },
2503
2538
  stats,
2504
2539
  opts.deps,
@@ -3085,29 +3120,28 @@ async function installPass(
3085
3120
  advancePhase()
3086
3121
 
3087
3122
  // -----------------------------------------------------------------------
3088
- // 3.5 Run migrations (--components runtime)
3123
+ // 3.5 Run state/schema migrations on every init, independent of runtime
3124
+ // selection. Migration schema has its own marker and remains idempotent.
3089
3125
  // -----------------------------------------------------------------------
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
- }
3126
+ const migrationStep = step(S.runningMigrations)
3127
+ const migration = runMigrations(target, {
3128
+ dryRun,
3129
+ recorder,
3130
+ updatedAt: planTimestamp,
3131
+ })
3132
+ if (migration.status === 'unsupported' || migration.status === 'invalid') {
3133
+ migrationStep(false)
3134
+ throw new Error(migration.message)
3135
+ }
3136
+ migrationStep(true)
3137
+ if (migration.plannedState) projectedState = migration.plannedState
3138
+ if (migration.applied > 0) {
3139
+ success(`Applied ${migration.applied} migration(s)`)
3140
+ for (const msg of migration.messages) {
3141
+ bullet(msg, 1)
3107
3142
  }
3108
- // Counted even when there is nothing to migrate: the phase ran its check.
3109
- advancePhase()
3110
3143
  }
3144
+ advancePhase()
3111
3145
 
3112
3146
  if (opts.preset && dryRun) {
3113
3147
  const { writeActivePreset } = await import('./model-picker.mjs')
@@ -3168,6 +3202,7 @@ async function installPass(
3168
3202
  // names `applyMcpServerEntries` seeded in THIS pass, in write order (empty
3169
3203
  // when the runtime component is not selected or failed its prerequisites).
3170
3204
  plan.mcpServers = mcpServers
3205
+ if (componentSet.has('runtime')) plan.runtimeEffects = runtimeEffects
3171
3206
  plan.versionAssumed = versionAssumed
3172
3207
  planFiles = plan.files
3173
3208
  planTotals = plan.totals
@@ -3205,9 +3240,8 @@ async function installPass(
3205
3240
  // were written"), never one line per file — the gauge already answered
3206
3241
  // "is it moving?" and per-file detail is opt-in via --verbose. `[DRY-RUN]`
3207
3242
  // 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.
3243
+ // `--yes` still exposes the concise preview before this apply pass runs;
3244
+ // only explicit quiet callers (JSON/doctor) suppress it.
3211
3245
  if (!opts.quietPlan) {
3212
3246
  const verbose = opts.verbose === true
3213
3247
  const planText = formatChangePlan(target, plan, { perFile: verbose })
@@ -3231,43 +3265,6 @@ async function installPass(
3231
3265
  // entries are only added when the Python runtime is actually healthy)
3232
3266
  // -----------------------------------------------------------------------
3233
3267
 
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
3268
  // -----------------------------------------------------------------------
3272
3269
  // 5. V1 model preset selection (--components agents). V2 ignores the legacy
3273
3270
  // active-preset marker, so it has no profile wizard or --preset support.
@@ -3275,12 +3272,20 @@ async function installPass(
3275
3272
  // Q1 default "herdar do chat" (inherit) writes no active-preset.json —
3276
3273
  // delegates inherit the parent chat model (native inheritance).
3277
3274
  // -----------------------------------------------------------------------
3278
- if (interactive && stdinTTY && version === 'v1' && !dryRun && !autoYes && !opts.preset) {
3275
+ if (
3276
+ interactive &&
3277
+ stdinTTY &&
3278
+ version === 'v1' &&
3279
+ !dryRun &&
3280
+ !autoYes &&
3281
+ !opts.preset &&
3282
+ stats.errors === 0
3283
+ ) {
3279
3284
  const { runInitWizard } = await import('./model-picker.mjs')
3280
3285
  await runInitWizard({ presetDir: target, logger: console, prompts: opts.deps?.prompts })
3281
3286
  }
3282
3287
 
3283
- if (opts.preset && !dryRun) {
3288
+ if (opts.preset && !dryRun && stats.errors === 0) {
3284
3289
  const { writeActivePreset } = await import('./model-picker.mjs')
3285
3290
  writeActivePreset(target, opts.preset, { source: 'cli', updatedAt: planTimestamp, recorder })
3286
3291
  }
@@ -3292,7 +3297,7 @@ async function installPass(
3292
3297
  // blocks on stdin and the default behavior is unchanged. A failure here
3293
3298
  // must never fail the install: vision stays optional.
3294
3299
  // -----------------------------------------------------------------------
3295
- if (interactive && !dryRun && !autoYes) {
3300
+ if (interactive && !dryRun && !autoYes && stats.errors === 0) {
3296
3301
  const runVisionPrompt =
3297
3302
  opts.deps?.runVisionPrompt ?? (await import('./vision-prompt.mjs')).runVisionPrompt
3298
3303
  try {
@@ -3302,13 +3307,8 @@ async function installPass(
3302
3307
  }
3303
3308
  }
3304
3309
 
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
3310
+ // Record component state even on a degraded runtime result so doctor and a
3311
+ // later init can distinguish a failed runtime from an installed one. The
3312
3312
  // postinstall marker can predate `init` and start with every component
3313
3313
  // pending; leaving it untouched made a healthy beta install look incomplete
3314
3314
  // to `doctor` forever. Unselected components retain their previous state.
@@ -3348,10 +3348,17 @@ async function installPass(
3348
3348
  verifiedFiles,
3349
3349
  })
3350
3350
  writeState(target, state, { updatedAt: planTimestamp })
3351
+ markAppliedWrite()
3351
3352
  stateStep(true)
3352
3353
  advancePhase()
3353
3354
  }
3354
3355
 
3356
+ // Fail closed only after the degraded state is persisted. The caller records
3357
+ // the partial application and reports its exact target/recovery backup.
3358
+ if (stats.errors > 0) {
3359
+ throw new Error(`installation completed with ${stats.errors} error(s); see output above`)
3360
+ }
3361
+
3355
3362
  // The apply gauge ends before the human summary; a dry run already closed it
3356
3363
  // before its plan block (`done()` is idempotent). A preview must NOT print
3357
3364
  // the installed banner: bin/pantheon-init prints the preview-only line.
@@ -3359,6 +3366,33 @@ async function installPass(
3359
3366
  if (!interactive && !dryRun && !opts.planOnly) {
3360
3367
  printSummary(target, ['opencode'], stats)
3361
3368
  }
3369
+ if (interactive && !dryRun && !opts.planOnly) {
3370
+ endGaugeLine()
3371
+ const created = stats.created
3372
+ const skipped = stats.skipped
3373
+ const warnings = stats.warnings ?? 0
3374
+ process.stdout.write('\n')
3375
+ process.stdout.write(` ${colors.bold(colors.green('Installation complete'))}\n`)
3376
+ process.stdout.write(
3377
+ ` ${colors.dim('\u2500'.repeat(Math.min(process.stdout.columns || 60, 60)))}\n`,
3378
+ )
3379
+ process.stdout.write(` [OK] ${created} component(s) installed\n`)
3380
+ if (skipped > 0)
3381
+ process.stdout.write(` ${colors.dim('\u2014')} ${skipped} already up-to-date\n`)
3382
+ if (warnings > 0)
3383
+ process.stdout.write(
3384
+ ` [WARN] ${warnings} warning(s) — run 'pantheon-opencode doctor' for details\n`,
3385
+ )
3386
+ process.stdout.write('\n')
3387
+ process.stdout.write(` ${colors.bold('Next steps:')}\n`)
3388
+ process.stdout.write(` ${colors.dim('\u2022')} Configure agents in opencode.json\n`)
3389
+ process.stdout.write(` ${colors.dim('\u2022')} Run 'pantheon-opencode doctor' to verify\n`)
3390
+ process.stdout.write(
3391
+ ` ${colors.dim('\u2022')} Run 'opencode' to start using Pantheon agents\n`,
3392
+ )
3393
+ process.stdout.write('\n')
3394
+ printWorktreeGuidance({ projectRoot: process.cwd(), interactive: true })
3395
+ }
3362
3396
 
3363
3397
  // Beta 11 Setup phase 3: report whether this call APPLIED, so the caller can
3364
3398
  // avoid a success banner for a plan-only / unauthorized run. The dry pass also
@@ -3373,6 +3407,7 @@ async function installPass(
3373
3407
  files: planFiles,
3374
3408
  totals: planTotals,
3375
3409
  mcpServers,
3410
+ runtimeEffects,
3376
3411
  removals: removalPaths,
3377
3412
  target,
3378
3413
  openCodeVersion: version,
@@ -3386,6 +3421,7 @@ async function installPass(
3386
3421
  applied: true,
3387
3422
  reason: 'applied',
3388
3423
  target,
3424
+ runtimeEffects,
3389
3425
  openCodeVersion: version,
3390
3426
  configAdvisories,
3391
3427
  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,
@@ -34,6 +35,7 @@ import { assertNoSymlinkAncestors, writeFileAtomically } from './verify.mjs'
34
35
 
35
36
  const STATE_FILE = 'install-state.json'
36
37
  const STATE_DIR = '.pantheon'
38
+ export const MIGRATION_SCHEMA_VERSION = '3.19.2'
37
39
 
38
40
  function emptyFileInventory(legacyUnknown = true) {
39
41
  return {
@@ -69,6 +71,7 @@ export function createInitialState(version, updatedAt = new Date().toISOString()
69
71
  return {
70
72
  schema_version: 2,
71
73
  pantheon_version: version || '0.0.0',
74
+ migration_schema_version: MIGRATION_SCHEMA_VERSION,
72
75
  previous_version: null,
73
76
  updated_at: updatedAt,
74
77
  migration_checkpoint: null,
@@ -122,6 +125,7 @@ export function upgradeStateV1toV2(state) {
122
125
  return {
123
126
  schema_version: 2,
124
127
  pantheon_version: state.pantheon_version || state.version || 'unknown',
128
+ migration_schema_version: state.migration_schema_version ?? null,
125
129
  previous_version: state.previous_version || null,
126
130
  updated_at: state.updated_at || now,
127
131
  migration_checkpoint: null,
@@ -153,6 +157,7 @@ export function upgradeStateV1toV2(state) {
153
157
  * @returns {object} the same state object with required collections present
154
158
  */
155
159
  function ensureV2Shape(state) {
160
+ if (!Object.hasOwn(state, 'migration_schema_version')) state.migration_schema_version = null
156
161
  if (!Array.isArray(state.applied_migrations)) state.applied_migrations = []
157
162
  if (
158
163
  !state.components ||
@@ -199,6 +204,8 @@ export function writeState(target, state, options = {}) {
199
204
  assertNoSymlinkAncestors(stateFile)
200
205
  state.updated_at = options.updatedAt ?? new Date().toISOString()
201
206
  state.schema_version = 2
207
+ if (!Object.hasOwn(state, 'migration_schema_version')) state.migration_schema_version = null
208
+ if (!Array.isArray(state.applied_migrations)) state.applied_migrations = []
202
209
  if (!Object.hasOwn(state, 'file_inventory')) {
203
210
  state.file_inventory = emptyFileInventory(true)
204
211
  } else if (
@@ -30,6 +30,9 @@ const TABLE = {
30
30
  // stronger claim would be false.
31
31
  canceledAt: (point) =>
32
32
  `Installation canceled at ${point} — nothing was applied; no configuration was changed.`,
33
+ interruptedAfterWrite: (backupDir) =>
34
+ `Installation interrupted at Ctrl-C — changes may be partially applied; no automatic rollback was attempted. ` +
35
+ `The backup is preserved${backupDir ? ` at ${backupDir}` : ''}; inspect it and restore manually if needed.`,
33
36
  declinedAt: (point) =>
34
37
  `Installation declined at ${point} — nothing was applied; no configuration was changed; ` +
35
38
  're-run init to review the plan again.',
@@ -117,6 +120,9 @@ const TABLE = {
117
120
  },
118
121
  canceledAt: (point) =>
119
122
  `Instalação cancelada em ${point} — nada foi aplicado; nenhuma configuração foi alterada.`,
123
+ interruptedAfterWrite: (backupDir) =>
124
+ `Instalação interrompida por Ctrl-C — alterações podem ter sido aplicadas parcialmente; nenhum rollback automático foi feito. ` +
125
+ `O backup foi preservado${backupDir ? ` em ${backupDir}` : ''}; revise e restaure manualmente se necessário.`,
120
126
  declinedAt: (point) =>
121
127
  `Instalação recusada em ${point} — nada foi aplicado; nenhuma configuração foi alterada; ` +
122
128
  'rode init de novo para revisar o plano.',