pantheon-opencode 2.0.0-beta.6 → 2.0.0-rc.1

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 (58) hide show
  1. package/AGENTS.global.md +6 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +45 -0
  4. package/README.md +169 -510
  5. package/README.pt-BR.md +177 -149
  6. package/bin/pantheon-init.mjs +1 -1
  7. package/commands/pantheon-deepwork.md +6 -1
  8. package/commands/pantheon.md +10 -5
  9. package/package.json +1 -1
  10. package/plugin.json +2 -2
  11. package/prompts/orchestrate-with-zeus.prompt.md +82 -290
  12. package/prompts/subtask.prompt.md +1 -1
  13. package/pyproject.toml +1 -1
  14. package/scripts/doctor.mjs +27 -11
  15. package/scripts/hooks/format-multi-language.sh +30 -48
  16. package/scripts/jev-live-probe.mjs +1 -1
  17. package/scripts/release-gates.mjs +19 -5
  18. package/scripts/skill-search.mjs +27 -3
  19. package/scripts/test-opencode-sandbox.sh +44 -15
  20. package/scripts/update.mjs +9 -2
  21. package/skills-lock.json +5 -3
  22. package/src/agents/aphrodite.md +2 -0
  23. package/src/agents/apollo.md +8 -206
  24. package/src/agents/athena.md +25 -29
  25. package/src/agents/hermes.md +3 -1
  26. package/src/agents/mnemosyne.md +1 -1
  27. package/src/agents/nyx.md +1 -1
  28. package/src/agents/prometheus.md +0 -203
  29. package/src/agents/talos.md +2 -0
  30. package/src/agents/themis.md +8 -3
  31. package/src/agents/zeus.md +18 -12
  32. package/src/instructions/memory-protocol.instructions.md +4 -0
  33. package/src/instructions/test-economy.instructions.md +1 -0
  34. package/src/instructions/zeus-council-synthesis.instructions.md +13 -1
  35. package/src/pantheon/pantheon-decision-catalog.ts +8 -0
  36. package/src/pantheon/skill-search-tool.ts +193 -0
  37. package/src/pantheon/tools.ts +2 -0
  38. package/src/plugins/tui/dist/tui.d.ts +12 -2
  39. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  40. package/src/plugins/tui/dist/tui.js +980 -358
  41. package/src/plugins/tui/dist/tui.js.map +1 -1
  42. package/src/plugins/tui/package-lock.json +2 -2
  43. package/src/plugins/tui/package.json +1 -1
  44. package/src/plugins/tui/src/autonomy-state.ts +1 -1
  45. package/src/plugins/tui/src/context-gauge.ts +64 -5
  46. package/src/plugins/tui/src/decision-router-state.ts +49 -2
  47. package/src/plugins/tui/src/index.tsx +25 -3
  48. package/src/plugins/tui/src/pantheon-settings-state.ts +99 -0
  49. package/src/plugins/tui/src/pantheon-settings.tsx +391 -101
  50. package/src/plugins/tui/src/tui-prefs.ts +161 -9
  51. package/src/plugins/tui/src/update-status.ts +27 -8
  52. package/src/routing.yml +9 -0
  53. package/src/skills/README.md +35 -25
  54. package/src/skills/fast-path-execution/SKILL.md +54 -0
  55. package/src/skills/prompt-refinery/SKILL.md +51 -65
  56. package/src/skills/tdd-with-agents/SKILL.md +22 -10
  57. package/src/skills/test-slicing/SKILL.md +56 -0
  58. package/src/skills/verification-planning/SKILL.md +4 -3
@@ -23,6 +23,7 @@
23
23
  * dispatch-panel layer must never win while this window is open; field
24
24
  * report beta.2: navigation "stopped working" was exactly that theft).
25
25
  */
26
+ import { execFile } from 'node:child_process'
26
27
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
27
28
  import { join } from 'node:path'
28
29
  import type { Context } from '@opencode/plugin/tui/context'
@@ -33,8 +34,6 @@ import {
33
34
  DEFAULT_GOAL_LOOP_PREFS,
34
35
  type DecisionBudgets,
35
36
  type GoalLoopPrefs,
36
- MONTHLY_USD_CYCLE,
37
- PER_DECISION_USD_CYCLE,
38
37
  parseUsd,
39
38
  } from './autonomy-state.ts'
40
39
  import {
@@ -50,7 +49,9 @@ import { buildJ1Tab } from './j1-gate-status.ts'
50
49
  import {
51
50
  applyDraft,
52
51
  buildAboutTab,
52
+ buildChangelogTab,
53
53
  buildGatesTab,
54
+ type ChangelogHighlightItem,
54
55
  canWriteOverrides,
55
56
  type DraftWriter,
56
57
  type DraftWriterResult,
@@ -66,6 +67,7 @@ import {
66
67
  serializeOverrides,
67
68
  setOverrideState,
68
69
  settledDraft,
70
+ stageDefaults,
69
71
  stageValue,
70
72
  tabDirty,
71
73
  tabRows,
@@ -84,9 +86,11 @@ import { nextCheckState, type UpdateCheckState } from './update-notice.ts'
84
86
  import {
85
87
  buildUpdatesTab,
86
88
  registryUrlForChannel,
89
+ type UpdateChannel,
87
90
  type UpdatesSectionInput,
88
91
  updateChannelFor,
89
92
  } from './update-status.ts'
93
+ import { extractHighlights, readChangelogForBundle } from './whats-new-highlights.ts'
90
94
 
91
95
  export const ROUTE_NAME = 'pantheon-settings'
92
96
 
@@ -269,6 +273,40 @@ function writeDecisionBudget(budgets: { monthlyUsd: number; perDecisionUsd: numb
269
273
  renameSync(temp, path)
270
274
  }
271
275
 
276
+ function decisionAuthStorePath(): string {
277
+ const xdgData = process.env.XDG_DATA_HOME ?? join(process.env.HOME ?? '', '.local', 'share')
278
+ return join(xdgData, 'opencode', 'auth.json')
279
+ }
280
+
281
+ /** Provider ids registered in the host auth store (existence only — never values). */
282
+ function readAuthProviders(): Set<string> {
283
+ const names = new Set<string>()
284
+ try {
285
+ const parsed = JSON.parse(readFileSync(decisionAuthStorePath(), 'utf8')) as Record<
286
+ string,
287
+ unknown
288
+ >
289
+ for (const key of Object.keys(parsed)) names.add(key)
290
+ } catch {
291
+ /* no auth store — nothing recognized */
292
+ }
293
+ return names
294
+ }
295
+
296
+ /** Provider ids present in opencode.json `providers` (the config copy the host reads). */
297
+ function readConfigProviders(): Set<string> {
298
+ const names = new Set<string>()
299
+ try {
300
+ const parsed = JSON.parse(readFileSync(userOpenCodeConfigPath(), 'utf8')) as {
301
+ providers?: Record<string, unknown>
302
+ }
303
+ for (const key of Object.keys(parsed?.providers ?? {})) names.add(key)
304
+ } catch {
305
+ /* no config providers */
306
+ }
307
+ return names
308
+ }
309
+
272
310
  function updateCheckStatePath(): string {
273
311
  const stateDir = process.env.XDG_STATE_HOME ?? join(process.env.HOME ?? '', '.local', 'state')
274
312
  return join(stateDir, 'pantheon', 'update-check.json')
@@ -282,9 +320,9 @@ function readUpdateCheckState(): UpdateCheckState {
282
320
  }
283
321
  }
284
322
 
285
- async function fetchLatestForChannel(currentVersion: string): Promise<string | null> {
323
+ async function fetchLatestForChannel(channel: UpdateChannel): Promise<string | null> {
286
324
  try {
287
- const response = await fetch(registryUrlForChannel(updateChannelFor(currentVersion)), {
325
+ const response = await fetch(registryUrlForChannel(channel), {
288
326
  signal: AbortSignal.timeout(5000),
289
327
  })
290
328
  const latest = String(((await response.json()) as { version?: unknown })?.version ?? '')
@@ -334,96 +372,213 @@ export function SettingsWindow(props: {
334
372
  version: string
335
373
  tabs: () => SettingsTab[]
336
374
  page: () => number
337
- selected: () => number
375
+ selectedId: () => string | undefined
338
376
  draft: () => SettingsDraft
339
377
  notice: () => string | undefined
378
+ confirmExit?: () => boolean
340
379
  fg?: any
341
380
  muted?: any
342
381
  warn?: any
343
382
  }) {
344
383
  const tab = () => props.tabs()[props.page()] ?? props.tabs()[0] ?? EMPTY_TAB
345
- const rows = () => tabRows(tab())
346
384
  return (
347
385
  <box flexDirection="column" paddingLeft={1} paddingRight={1} paddingTop={1}>
348
- <box flexDirection="row">
349
- <text flexShrink={0} attributes={1} fg={props.fg}>
386
+ {/* ── Top Header bar: Title + Horizontal Tabs + ESC (matching image.png) ── */}
387
+ <box flexDirection="row" alignItems="center">
388
+ <text attributes={1} fg={props.fg}>
350
389
  {`Pantheon v${props.version}`}
351
390
  </text>
352
- <For each={props.tabs()}>
353
- {(t, index) => (
354
- <text
355
- flexShrink={0}
356
- fg={index() === props.page() ? props.fg : props.muted}
357
- {...(index() === props.page() ? { attributes: 1 } : {})}
358
- >
359
- {` ${t.title}${tabDirty(props.draft(), t) ? ' ●' : ''}`}
360
- </text>
361
- )}
362
- </For>
363
- <box flexGrow={1} />
364
- <text flexShrink={0} fg={props.muted}>
365
- {'esc'}
366
- </text>
391
+ <box width={2} />
392
+ <box flexDirection="row" flexGrow={1} flexShrink={1}>
393
+ <For each={props.tabs()}>
394
+ {(t, index) => {
395
+ const isActive = () => index() === props.page()
396
+ return (
397
+ <text
398
+ flexShrink={0}
399
+ fg={isActive() ? (props.warn ?? props.fg) : props.muted}
400
+ {...(isActive() ? { attributes: 1 } : {})}
401
+ >
402
+ {`${t.title}${tabDirty(props.draft(), t) ? ' ●' : ''} `}
403
+ </text>
404
+ )
405
+ }}
406
+ </For>
407
+ </box>
408
+ <text fg={props.muted}>{'esc'}</text>
367
409
  </box>
368
- <text fg={props.muted}>{'─'.repeat(72)}</text>
369
- <For each={tab().groups}>
370
- {(group) => (
371
- <box flexDirection="column">
372
- <Show when={group.title !== undefined}>
373
- <text attributes={1} fg={props.fg}>
374
- {group.title}
375
- </text>
376
- </Show>
377
- <For each={group.rows}>
378
- {(row: SettingsRow) => {
379
- const isSelected = () => rows()[props.selected()]?.id === row.id
380
- const display = () => props.draft()[row.id] ?? row.value
381
- const staged = () => props.draft()[row.id] !== undefined
382
- const gutter = () => (isSelected() ? '▸ ' : ' ')
383
- const valueCell = () => (row.cycle !== undefined ? `< ${display()} >` : display())
384
- return (
385
- <box flexDirection="row">
386
- <box width={NAME_WIDTH + 2}>
387
- <text fg={props.fg} {...(isSelected() ? { attributes: 1 } : {})}>
388
- {`${gutter()}${row.name}`.padEnd(NAME_WIDTH + 2)}
389
- </text>
390
- </box>
391
- <box width={VALUE_WIDTH}>
392
- <text
393
- fg={isSelected() || staged() ? props.fg : props.muted}
394
- {...(isSelected() ? { attributes: 1 } : {})}
410
+
411
+ {/* ── Thin divider under header ── */}
412
+ <box flexDirection="row" height={1}>
413
+ <box flexGrow={1}>
414
+ <text fg={props.muted}>{'─'.repeat(78)}</text>
415
+ </box>
416
+ </box>
417
+
418
+ {/* ── Main Body: Left Rail + Content (matching image.png & image_2.png) ── */}
419
+ <box flexDirection="row">
420
+ {/* Left Rail: Tab list with active indicator */}
421
+ <box width={18} flexDirection="column">
422
+ <For each={props.tabs()}>
423
+ {(t, index) => {
424
+ const isActive = () => index() === props.page()
425
+ return (
426
+ <text
427
+ fg={isActive() ? (props.warn ?? props.fg) : props.muted}
428
+ {...(isActive() ? { attributes: 1 } : {})}
429
+ >
430
+ {`${isActive() ? '▸ ' : ' '}${t.title}${tabDirty(props.draft(), t) ? ' ●' : ''}`}
431
+ </text>
432
+ )
433
+ }}
434
+ </For>
435
+ <box height={1} />
436
+ <text fg={props.muted}>{'1-9: tab'}</text>
437
+ <text fg={props.muted}>{'tab: next'}</text>
438
+ </box>
439
+
440
+ {/* Content panel */}
441
+ <box flexGrow={1} flexShrink={1} flexDirection="column" paddingLeft={1}>
442
+ <text attributes={1} fg={props.warn ?? props.fg}>
443
+ {tab().title}
444
+ </text>
445
+ <text fg={props.muted}>{'─'.repeat(40)}</text>
446
+ <For each={tab().groups}>
447
+ {(group) => (
448
+ <box flexDirection="column">
449
+ <Show when={group.title !== undefined}>
450
+ <text attributes={1} fg={props.warn ?? props.fg}>
451
+ {group.title}
452
+ </text>
453
+ </Show>
454
+ <For each={group.rows}>
455
+ {(row: SettingsRow) => {
456
+ const isSelected = () => row.id === props.selectedId()
457
+ const display = () => props.draft()[row.id] ?? row.value
458
+ const staged = () => props.draft()[row.id] !== undefined
459
+ const gutter = () => (isSelected() ? ' ' : ' ')
460
+ const valueCell = () =>
461
+ row.cycle !== undefined ? `< ${display()} >` : display()
462
+ return (
463
+ <box
464
+ flexDirection="row"
465
+ backgroundColor={isSelected() ? (props.warn ?? '#f59e0b') : undefined}
395
466
  >
396
- {`${valueCell()}${staged() ? ' ●' : ''}`.padEnd(VALUE_WIDTH)}
397
- </text>
398
- </box>
399
- <Show when={row.note !== undefined}>
400
- <box flexGrow={1} flexShrink={1}>
401
- <text fg={props.muted}>{row.note}</text>
467
+ <box width={NAME_WIDTH + 2}>
468
+ <text
469
+ fg={isSelected() ? '#000000' : props.fg}
470
+ {...(isSelected() ? { attributes: 1 } : {})}
471
+ >
472
+ {`${gutter()}${row.name}`.padEnd(NAME_WIDTH + 2)}
473
+ </text>
474
+ </box>
475
+ <box width={VALUE_WIDTH}>
476
+ <text
477
+ fg={
478
+ isSelected()
479
+ ? '#000000'
480
+ : staged()
481
+ ? (props.warn ?? props.fg)
482
+ : props.muted
483
+ }
484
+ {...(isSelected() || staged() ? { attributes: 1 } : {})}
485
+ >
486
+ {`${valueCell()}${staged() ? ' ●' : ''}`.padEnd(VALUE_WIDTH)}
487
+ </text>
488
+ </box>
489
+ <Show when={row.note !== undefined}>
490
+ <box flexGrow={1} flexShrink={1}>
491
+ <text fg={isSelected() ? '#111827' : props.muted}>{row.note}</text>
492
+ </box>
493
+ </Show>
402
494
  </box>
403
- </Show>
404
- </box>
405
- )
406
- }}
407
- </For>
408
- <box height={1} />
409
- </box>
410
- )}
411
- </For>
495
+ )
496
+ }}
497
+ </For>
498
+ <box height={1} />
499
+ </box>
500
+ )}
501
+ </For>
502
+ </box>
503
+ </box>
504
+
505
+ {/* ── Footer: notice + botões (chips) + keys (matching image.png & image_2.png) ── */}
412
506
  <Show when={props.notice() !== undefined}>
413
- <text fg={props.notice()?.startsWith('saved') ? props.muted : (props.warn ?? props.muted)}>
414
- {props.notice()?.startsWith('saved') ? props.notice() : `⚠ ${props.notice()}`}
507
+ <text fg={props.notice()?.startsWith('✅') ? props.fg : (props.warn ?? props.muted)}>
508
+ {props.notice()?.startsWith('✅') || props.notice()?.startsWith('saved')
509
+ ? props.notice()
510
+ : `⚠ ${props.notice()}`}
415
511
  </text>
416
512
  </Show>
417
- <text fg={draftDirty(props.draft()) ? (props.warn ?? props.fg) : props.muted}>
418
- {draftDirty(props.draft())
419
- ? `● unsaved (${draftCount(props.draft())}) — ctrl+s save · ctrl+r reset page`
420
- : 'no staged changes'}
421
- </text>
422
- <text fg={props.muted}>
423
- {
424
- '1-9 tab · ←/→ change value · enter apply · tab next tab · ctrl+s save · ctrl+r reset page · esc/q close'
513
+
514
+ <Show
515
+ when={props.confirmExit?.()}
516
+ fallback={
517
+ <box flexDirection="column">
518
+ <Show
519
+ when={draftDirty(props.draft())}
520
+ fallback={
521
+ <box flexDirection="row">
522
+ <box backgroundColor="#262626">
523
+ <text fg="#ffffff">{' Close '}</text>
524
+ </box>
525
+ <text fg={props.muted}>{' '}</text>
526
+ <box backgroundColor="#262626">
527
+ <text fg="#ffffff">{' Reset page '}</text>
528
+ </box>
529
+ <text fg={props.muted}>{' '}</text>
530
+ <box backgroundColor="#262626">
531
+ <text fg="#ffffff">{' Defaults '}</text>
532
+ </box>
533
+ <box flexGrow={1} />
534
+ <text fg={props.muted}>{'no staged changes'}</text>
535
+ </box>
536
+ }
537
+ >
538
+ <box flexDirection="row">
539
+ <box backgroundColor="#fba970">
540
+ <text fg="#000000">{' Save '}</text>
541
+ </box>
542
+ <text fg={props.muted}>{' '}</text>
543
+ <box backgroundColor="#262626">
544
+ <text fg="#ffffff">{' Discard '}</text>
545
+ </box>
546
+ <text fg={props.muted}>{' '}</text>
547
+ <box backgroundColor="#262626">
548
+ <text fg="#ffffff">{' Reset page '}</text>
549
+ </box>
550
+ <box flexGrow={1} />
551
+ <text fg={props.warn ?? '#f59e0b'}>{'unsaved changes'}</text>
552
+ </box>
553
+ </Show>
554
+ <text fg={props.muted}>
555
+ {
556
+ '› or ←/→ change · ↑↓ select · tab next tab · ctrl+s save · ctrl+r reset page · esc close'
557
+ }
558
+ </text>
559
+ </box>
425
560
  }
426
- </text>
561
+ >
562
+ <box flexDirection="column">
563
+ <box flexDirection="row">
564
+ <text fg={props.warn ?? '#f59e0b'} attributes={1}>
565
+ {'Keep your changes? '}
566
+ </text>
567
+ <box backgroundColor="#fba970">
568
+ <text fg="#000000">{' Save '}</text>
569
+ </box>
570
+ <text fg={props.muted}>{' '}</text>
571
+ <box backgroundColor="#262626">
572
+ <text fg="#ffffff">{' Discard '}</text>
573
+ </box>
574
+ <text fg={props.muted}>{' '}</text>
575
+ <box backgroundColor="#262626">
576
+ <text fg="#ffffff">{' Keep editing '}</text>
577
+ </box>
578
+ </box>
579
+ <text fg={props.muted}>{'ctrl+s save · d discard the changes · esc keep editing'}</text>
580
+ </box>
581
+ </Show>
427
582
  </box>
428
583
  )
429
584
  }
@@ -438,7 +593,11 @@ interface PageApi {
438
593
  jumpTab: (index: number) => void
439
594
  save: () => void
440
595
  resetPage: () => void
596
+ stageDefaults: () => void
441
597
  close: () => void
598
+ discard?: () => void
599
+ cancelExit?: () => void
600
+ confirmExit?: () => boolean
442
601
  }
443
602
 
444
603
  let pageApi: PageApi | undefined
@@ -449,12 +608,14 @@ function createWindowController(
449
608
  ): {
450
609
  tabs: () => SettingsTab[]
451
610
  page: () => number
452
- selected: () => number
611
+ selectedId: () => string | undefined
453
612
  draft: () => SettingsDraft
454
613
  notice: () => string | undefined
614
+ confirmExit: () => boolean
455
615
  api: PageApi
456
616
  cleanup: () => void
457
617
  } {
618
+ const currentVersion = resolveRunningVersion()
458
619
  const [page, setPage] = createSignal(0)
459
620
  const [selected, setSelected] = createSignal(0)
460
621
  const [load, setLoad] = createSignal(readOverridesLoad())
@@ -463,12 +624,33 @@ function createWindowController(
463
624
  const [budgets, setBudgets] = createSignal<DecisionBudgets>(readDecisionBudgets())
464
625
  const [autonomyRestartPending, setAutonomyRestartPending] = createSignal(false)
465
626
  const [presetTick, setPresetTick] = createSignal(0)
627
+ const [selectedChannel, setSelectedChannel] = createSignal<UpdateChannel>(
628
+ updateChannelFor(currentVersion),
629
+ )
466
630
  const [lastChecked, setLastChecked] = createSignal<string | undefined>(undefined)
467
631
  const [checking, setChecking] = createSignal(false)
632
+ const [updating, setUpdating] = createSignal(false)
633
+ const [changelogItems, setChangelogItems] = createSignal<ChangelogHighlightItem[]>([])
468
634
  const [draft, setDraft] = createSignal<SettingsDraft>({})
469
635
  const [notice, setNotice] = createSignal<string | undefined>(undefined)
636
+ const [confirmExit, setConfirmExit] = createSignal(false)
470
637
 
471
- const currentVersion = resolveRunningVersion()
638
+ // Load changelog highlights asynchronously
639
+ void readChangelogForBundle(import.meta.url).then((text) => {
640
+ if (!text) return
641
+ const hl = extractHighlights(text, currentVersion)
642
+ if (hl.found) {
643
+ const items: ChangelogHighlightItem[] = []
644
+ for (const group of hl.groups) {
645
+ for (const item of group.items) {
646
+ const dash = item.indexOf('—')
647
+ const title = dash !== -1 ? item.slice(0, dash).trim() : item.slice(0, 26)
648
+ items.push({ title, detail: item, group: group.heading ?? undefined })
649
+ }
650
+ }
651
+ setChangelogItems(items)
652
+ }
653
+ })
472
654
 
473
655
  const presetInput = () => {
474
656
  void presetTick()
@@ -482,7 +664,9 @@ function createWindowController(
482
664
  const input: UpdatesSectionInput = {
483
665
  currentVersion,
484
666
  state: readUpdateCheckState(),
667
+ selectedChannel: selectedChannel(),
485
668
  checking: checking(),
669
+ updating: updating(),
486
670
  nowMs: Date.now(),
487
671
  }
488
672
  const seen = lastChecked()
@@ -492,7 +676,7 @@ function createWindowController(
492
676
 
493
677
  const tabs = (): SettingsTab[] => [
494
678
  buildGatesTab(load()),
495
- buildDecisionTab(decision()),
679
+ buildDecisionTab(decision(), process.env, readAuthProviders(), readConfigProviders()),
496
680
  buildPresetTab(presetInput()),
497
681
  buildTuiTab(tuiPrefs()),
498
682
  buildAutonomyTab({
@@ -502,6 +686,7 @@ function createWindowController(
502
686
  }),
503
687
  buildJ1Tab(process.env, false),
504
688
  buildUpdatesTab(updatesInput()),
689
+ buildChangelogTab(currentVersion, changelogItems()),
505
690
  buildDoctorTab({
506
691
  runningVersion: currentVersion,
507
692
  nodeVersion: process.versions.node,
@@ -513,34 +698,77 @@ function createWindowController(
513
698
  const rows = () => tabRows(tabs()[page()] ?? tabs()[0] ?? EMPTY_TAB)
514
699
 
515
700
  const move = (delta: number) => {
701
+ if (confirmExit()) setConfirmExit(false)
516
702
  const list = rows()
517
703
  if (list.length === 0) return
518
704
  setSelected((current) => Math.min(Math.max(current + delta, 0), list.length - 1))
519
705
  }
520
706
 
521
707
  const step = (direction: 1 | -1) => {
708
+ if (confirmExit()) setConfirmExit(false)
522
709
  const row = rows()[selected()]
523
710
  if (row === undefined) return
524
711
  setNotice(undefined)
525
712
  setDraft(stageValue(draft(), row, direction))
526
713
  }
527
714
 
528
- const checkUpdatesNow = () => {
715
+ const checkUpdatesNow = (targetChannel: UpdateChannel = selectedChannel()) => {
529
716
  if (checking()) return
530
717
  setChecking(true)
531
718
  setNotice(undefined)
532
- void fetchLatestForChannel(currentVersion)
719
+ void fetchLatestForChannel(targetChannel)
533
720
  .then((latest) => {
534
- if (latest) setLastChecked(latest)
535
- persistUpdateCheckState(readUpdateCheckState(), latest)
721
+ if (latest) {
722
+ setLastChecked(latest)
723
+ persistUpdateCheckState(readUpdateCheckState(), latest)
724
+ }
536
725
  })
537
726
  .catch(() => {
538
- /* offline — the row keeps the last known state */
727
+ /* offline */
539
728
  })
540
729
  .finally(() => setChecking(false))
541
730
  }
542
731
 
732
+ const runUpdateNow = () => {
733
+ if (updating()) return
734
+ setUpdating(true)
735
+ setNotice(`updating to ${selectedChannel()} channel…`)
736
+ execFile(
737
+ 'npm',
738
+ ['install', '-g', `pantheon-opencode@${selectedChannel()}`],
739
+ { timeout: 60_000 },
740
+ (err) => {
741
+ setUpdating(false)
742
+ if (err) {
743
+ setNotice('run in terminal: pantheon-opencode update')
744
+ try {
745
+ context.ui.toast?.show?.({
746
+ variant: 'warning',
747
+ message: 'Update requires terminal permissions: run `pantheon-opencode update`',
748
+ })
749
+ } catch {}
750
+ } else {
751
+ setNotice('✅ update complete — restart OpenCode or run `npx pantheon-opencode init`')
752
+ try {
753
+ context.ui.toast?.show?.({
754
+ variant: 'info',
755
+ message: 'Pantheon updated successfully!',
756
+ })
757
+ } catch {}
758
+ }
759
+ },
760
+ )
761
+ }
762
+
543
763
  const dispatchWrite = (id: string, value: string): DraftWriterResult => {
764
+ if (id === 'update.channel') {
765
+ if (value === 'stable' || value === 'beta') {
766
+ setSelectedChannel(value as UpdateChannel)
767
+ checkUpdatesNow(value as UpdateChannel)
768
+ return { ok: true }
769
+ }
770
+ return { ok: false, reason: 'unknown channel' }
771
+ }
544
772
  if (id.startsWith('gate.')) {
545
773
  if (!canWriteOverrides(load())) {
546
774
  return { ok: false, reason: 'overrides file unreadable — repair with `doctor --fix`' }
@@ -654,10 +882,6 @@ function createWindowController(
654
882
  }
655
883
  }
656
884
  if (id.startsWith('tui.')) {
657
- // The prefs live in the host's durable reactive store: the mutation is
658
- // async (persist), but the in-memory store flips immediately — the
659
- // sidebar/footer/panel re-render on save, no restart. A persist
660
- // failure surfaces in the notice line when it settles.
661
885
  try {
662
886
  mutateTuiPrefs((prefsDraft) => applyTuiRow(prefsDraft, id, value))
663
887
  .then(() => setNotice(undefined))
@@ -689,27 +913,40 @@ function createWindowController(
689
913
  setNotice(`${failed.map((f) => `${f.id}: ${f.reason}`).join(' · ')} — staged changes kept`)
690
914
  } else {
691
915
  setNotice(`saved ${applied.length} change${applied.length === 1 ? '' : 's'}`)
916
+ if (confirmExit()) {
917
+ exit()
918
+ }
692
919
  }
693
920
  }
694
921
 
695
922
  const resetPage = () => {
923
+ if (confirmExit()) setConfirmExit(false)
696
924
  const tab = tabs()[page()]
697
925
  if (tab === undefined) return
698
926
  setDraft(resetTab(draft(), tab))
699
927
  setNotice(undefined)
700
928
  }
701
929
 
930
+ const stageDefaultsPage = () => {
931
+ if (confirmExit()) setConfirmExit(false)
932
+ const tab = tabs()[page()]
933
+ if (tab === undefined) return
934
+ setNotice(undefined)
935
+ setDraft(stageDefaults(draft(), tab))
936
+ }
937
+
702
938
  const nextTab = () => {
939
+ if (confirmExit()) setConfirmExit(false)
703
940
  setPage((current) => (current + 1) % tabs().length)
704
941
  setSelected(0)
705
942
  }
706
943
 
707
944
  const close = () => {
708
- // A dialog.confirm here would render in the home/session view chrome,
709
- // which a full-screen ROUTE page replaces — an invisible prompt that
710
- // pends forever (field report beta.5: esc "did nothing" with staged
711
- // changes). Close always exits; discarding is announced, never asked.
712
945
  const staged = draftCount(draft())
946
+ if (staged > 0 && !confirmExit()) {
947
+ setConfirmExit(true)
948
+ return
949
+ }
713
950
  if (staged > 0) {
714
951
  setDraft({})
715
952
  try {
@@ -724,16 +961,42 @@ function createWindowController(
724
961
  exit()
725
962
  }
726
963
 
964
+ const discard = () => {
965
+ const staged = draftCount(draft())
966
+ setDraft({})
967
+ setConfirmExit(false)
968
+ if (staged > 0) {
969
+ try {
970
+ context.ui.toast?.show?.({
971
+ variant: 'info',
972
+ message: `settings: ${staged} staged change${staged === 1 ? '' : 's'} discarded`,
973
+ })
974
+ } catch {
975
+ /* toast unavailable */
976
+ }
977
+ }
978
+ exit()
979
+ }
980
+
981
+ const cancelExit = () => {
982
+ setConfirmExit(false)
983
+ }
984
+
985
+ const selectedId = () => rows()[selected()]?.id
986
+
727
987
  const api: PageApi = {
728
988
  move,
729
989
  step,
730
990
  actuate: () => {
991
+ if (confirmExit()) setConfirmExit(false)
731
992
  const row = rows()[selected()]
732
993
  if (row?.action === 'update-check') checkUpdatesNow()
994
+ else if (row?.action === 'update-run') runUpdateNow()
733
995
  else step(1)
734
996
  },
735
997
  nextTab,
736
998
  jumpTab: (index) => {
999
+ if (confirmExit()) setConfirmExit(false)
737
1000
  if (index >= 0 && index < tabs().length) {
738
1001
  setPage(index)
739
1002
  setSelected(0)
@@ -741,15 +1004,20 @@ function createWindowController(
741
1004
  },
742
1005
  save,
743
1006
  resetPage,
1007
+ stageDefaults: stageDefaultsPage,
744
1008
  close,
1009
+ discard,
1010
+ cancelExit,
1011
+ confirmExit: () => confirmExit(),
745
1012
  }
746
1013
 
747
1014
  return {
748
1015
  tabs,
749
1016
  page,
750
- selected,
1017
+ selectedId,
751
1018
  draft,
752
1019
  notice,
1020
+ confirmExit: () => confirmExit(),
753
1021
  api,
754
1022
  cleanup: () => {
755
1023
  pageApi = undefined
@@ -787,9 +1055,10 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
787
1055
  version={resolveRunningVersion()}
788
1056
  tabs={controller.tabs}
789
1057
  page={controller.page}
790
- selected={controller.selected}
1058
+ selectedId={controller.selectedId}
791
1059
  draft={controller.draft}
792
1060
  notice={controller.notice}
1061
+ confirmExit={controller.confirmExit}
793
1062
  fg={theme.base}
794
1063
  muted={theme.muted}
795
1064
  warn={warn}
@@ -800,12 +1069,7 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
800
1069
  function navigateBack(context: Context, data?: { returnRoute?: WindowRoute }): void {
801
1070
  try {
802
1071
  const fallback: WindowRoute = { type: 'home' }
803
- const destination = data?.returnRoute ?? fallback
804
- context.ui.toast?.show?.({
805
- variant: 'info',
806
- message: `settings: navigating ${JSON.stringify(destination)}`,
807
- })
808
- context.ui.router.navigate(destination)
1072
+ context.ui.router.navigate(data?.returnRoute ?? fallback)
809
1073
  } catch {
810
1074
  /* router unavailable — the failure is observable only as a stuck page */
811
1075
  }
@@ -848,9 +1112,10 @@ function openSettingsDialog(context: Context): void {
848
1112
  version={resolveRunningVersion()}
849
1113
  tabs={controller.tabs}
850
1114
  page={controller.page}
851
- selected={controller.selected}
1115
+ selectedId={controller.selectedId}
852
1116
  draft={controller.draft}
853
1117
  notice={controller.notice}
1118
+ confirmExit={controller.confirmExit}
854
1119
  fg={theme.base}
855
1120
  muted={theme.muted}
856
1121
  warn={warn}
@@ -904,10 +1169,26 @@ export function setupPantheonSettings(context: Context): void {
904
1169
  }
905
1170
  return undefined
906
1171
  }
1172
+ if (pageApi.confirmExit?.()) {
1173
+ pageApi.cancelExit?.()
1174
+ return undefined
1175
+ }
907
1176
  pageApi.close()
908
1177
  return undefined
909
1178
  },
910
1179
  },
1180
+ {
1181
+ id: 'pantheon.settings.discard',
1182
+ title: 'Discard staged changes and exit',
1183
+ bind: 'd',
1184
+ run: () => {
1185
+ if (pageApi?.confirmExit?.()) {
1186
+ pageApi.discard?.()
1187
+ return undefined
1188
+ }
1189
+ return undefined
1190
+ },
1191
+ },
911
1192
  {
912
1193
  id: 'pantheon.settings.down',
913
1194
  title: 'Select next row',
@@ -980,6 +1261,15 @@ export function setupPantheonSettings(context: Context): void {
980
1261
  return undefined
981
1262
  },
982
1263
  },
1264
+ {
1265
+ id: 'pantheon.settings.defaults',
1266
+ title: 'Stage defaults for this tab',
1267
+ bind: 'ctrl+d',
1268
+ run: () => {
1269
+ pageApi?.stageDefaults()
1270
+ return undefined
1271
+ },
1272
+ },
983
1273
  ...Array.from({ length: 9 }, (_, index) => ({
984
1274
  id: `pantheon.settings.tab.${index + 1}`,
985
1275
  title: `Jump to tab ${index + 1}`,