pantheon-opencode 2.0.0-beta.6 → 2.0.0

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 (93) hide show
  1. package/AGENTS.global.md +7 -2
  2. package/AGENTS.md +8 -8
  3. package/CHANGELOG.md +99 -0
  4. package/README.md +171 -510
  5. package/README.pt-BR.md +179 -149
  6. package/bin/pantheon-init.mjs +14 -1
  7. package/commands/pantheon-audit.md +1 -1
  8. package/commands/pantheon-deepwork.md +7 -2
  9. package/commands/pantheon-optimize.md +41 -63
  10. package/commands/pantheon.md +10 -5
  11. package/package.json +4 -3
  12. package/plugin.json +2 -2
  13. package/prompts/optimize-database.prompt.md +5 -5
  14. package/prompts/orchestrate-with-zeus.prompt.md +82 -290
  15. package/prompts/plan-architecture.prompt.md +6 -6
  16. package/prompts/subtask.prompt.md +1 -1
  17. package/pyproject.toml +1 -1
  18. package/scripts/build-agents-md.mjs +10 -10
  19. package/scripts/build-plugin.mjs +26 -0
  20. package/scripts/doctor.mjs +27 -11
  21. package/scripts/hooks/format-multi-language.sh +30 -48
  22. package/scripts/install/opencode-version.mjs +17 -5
  23. package/scripts/install/opencode.mjs +8 -1
  24. package/scripts/jev-live-probe.mjs +1 -1
  25. package/scripts/optimize.mjs +322 -0
  26. package/scripts/prune.mjs +105 -14
  27. package/scripts/release-gates.mjs +19 -5
  28. package/scripts/skill-search.mjs +27 -3
  29. package/scripts/test-opencode-sandbox.sh +44 -15
  30. package/scripts/update.mjs +29 -17
  31. package/skills-lock.json +15 -13
  32. package/src/agents/aphrodite.md +17 -14
  33. package/src/agents/apollo.md +10 -207
  34. package/src/agents/athena.md +30 -34
  35. package/src/agents/demeter.md +2 -0
  36. package/src/agents/hephaestus.md +1 -0
  37. package/src/agents/hermes.md +21 -95
  38. package/src/agents/iris.md +3 -0
  39. package/src/agents/mnemosyne.md +1 -1
  40. package/src/agents/nyx.md +2 -1
  41. package/src/agents/prometheus.md +2 -203
  42. package/src/agents/talos.md +5 -0
  43. package/src/agents/themis.md +93 -84
  44. package/src/agents/zeus.md +44 -263
  45. package/src/instructions/agent-return-format.instructions.md +1 -1
  46. package/src/instructions/memory-protocol.instructions.md +5 -1
  47. package/src/instructions/test-economy.instructions.md +1 -0
  48. package/src/instructions/zeus-anti-stall.instructions.md +3 -3
  49. package/src/instructions/zeus-communication-rules.instructions.md +1 -1
  50. package/src/instructions/zeus-council-synthesis.instructions.md +15 -3
  51. package/src/instructions/zeus-timeout-retry.instructions.md +10 -10
  52. package/src/pantheon/model-command.ts +12 -12
  53. package/src/pantheon/pantheon-decision-catalog.ts +8 -0
  54. package/src/pantheon/skill-search-tool.ts +193 -0
  55. package/src/pantheon/tools.ts +6 -0
  56. package/src/pantheon/tui-version-check.ts +1 -1
  57. package/src/pantheon/update-notifier.ts +13 -8
  58. package/src/pantheon/vision.ts +20 -20
  59. package/src/plugin/index.js +14594 -0
  60. package/src/plugins/tui/dist/tui.d.ts +15 -5
  61. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  62. package/src/plugins/tui/dist/tui.js +1761 -556
  63. package/src/plugins/tui/dist/tui.js.map +1 -1
  64. package/src/plugins/tui/package-lock.json +2 -2
  65. package/src/plugins/tui/package.json +1 -1
  66. package/src/plugins/tui/src/autonomy-state.ts +28 -16
  67. package/src/plugins/tui/src/context-gauge.ts +64 -5
  68. package/src/plugins/tui/src/decision-router-state.ts +49 -2
  69. package/src/plugins/tui/src/index.tsx +69 -26
  70. package/src/plugins/tui/src/pantheon-settings-state.ts +99 -0
  71. package/src/plugins/tui/src/pantheon-settings.tsx +771 -125
  72. package/src/plugins/tui/src/tui-prefs.ts +266 -12
  73. package/src/plugins/tui/src/update-notice.ts +9 -6
  74. package/src/plugins/tui/src/update-status.ts +27 -8
  75. package/src/plugins/tui/src/whats-new-open.ts +4 -4
  76. package/src/plugins/tui/src/whats-new.tsx +119 -17
  77. package/src/routing.yml +9 -0
  78. package/src/skills/README.md +35 -25
  79. package/src/skills/agent-coordination/SKILL.md +6 -6
  80. package/src/skills/artifact-management/SKILL.md +43 -39
  81. package/src/skills/artifact-management/references/artifact-templates.md +103 -48
  82. package/src/skills/auto-continue/references/auto-continue-details.md +13 -13
  83. package/src/skills/code-review-checklist/SKILL.md +6 -6
  84. package/src/skills/fast-path-execution/SKILL.md +54 -0
  85. package/src/skills/incremental-implementation/SKILL.md +13 -13
  86. package/src/skills/memory-bank/references/anti-patterns.md +3 -3
  87. package/src/skills/prompt-refinery/SKILL.md +51 -65
  88. package/src/skills/spec-driven-development/SKILL.md +12 -14
  89. package/src/skills/tdd-with-agents/SKILL.md +23 -10
  90. package/src/skills/test-slicing/SKILL.md +56 -0
  91. package/src/skills/verification-planning/SKILL.md +4 -3
  92. package/src/skills/visual-review-pipeline/SKILL.md +1 -1
  93. package/src/skills/visual-review-pipeline/references/workflow-steps.md +1 -1
@@ -23,18 +23,17 @@
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'
29
- import { createSignal, For, onCleanup, Show } from 'solid-js'
30
+ import { createEffect, createSignal, For, onCleanup, onMount, Show } from 'solid-js'
30
31
  import {
31
32
  buildAutonomyTab,
32
33
  DEFAULT_DECISION_BUDGETS,
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,
@@ -58,6 +59,7 @@ import {
58
59
  draftDirty,
59
60
  type EffectiveOverrides,
60
61
  EMPTY_TAB,
62
+ findRow,
61
63
  type OverridesLoad,
62
64
  resetTab,
63
65
  type SettingsDraft,
@@ -66,6 +68,7 @@ import {
66
68
  serializeOverrides,
67
69
  setOverrideState,
68
70
  settledDraft,
71
+ stageDefaults,
69
72
  stageValue,
70
73
  tabDirty,
71
74
  tabRows,
@@ -79,14 +82,24 @@ import {
79
82
  readActivePresetMarker,
80
83
  writeActivePreset,
81
84
  } from './preset-state.ts'
82
- import { applyTuiRow, buildTuiTab, mutateTuiPrefs, tuiPrefs } from './tui-prefs.ts'
85
+ import {
86
+ applyTuiRow,
87
+ buildTuiTab,
88
+ clearTuiDraftPreview,
89
+ mutateTuiPrefs,
90
+ savedTuiPrefs,
91
+ setTuiDraftPreview,
92
+ tuiPrefs,
93
+ } from './tui-prefs.ts'
83
94
  import { nextCheckState, type UpdateCheckState } from './update-notice.ts'
84
95
  import {
85
96
  buildUpdatesTab,
86
97
  registryUrlForChannel,
98
+ type UpdateChannel,
87
99
  type UpdatesSectionInput,
88
100
  updateChannelFor,
89
101
  } from './update-status.ts'
102
+ import { extractHighlights, readChangelogForBundle } from './whats-new-highlights.ts'
90
103
 
91
104
  export const ROUTE_NAME = 'pantheon-settings'
92
105
 
@@ -269,6 +282,40 @@ function writeDecisionBudget(budgets: { monthlyUsd: number; perDecisionUsd: numb
269
282
  renameSync(temp, path)
270
283
  }
271
284
 
285
+ function decisionAuthStorePath(): string {
286
+ const xdgData = process.env.XDG_DATA_HOME ?? join(process.env.HOME ?? '', '.local', 'share')
287
+ return join(xdgData, 'opencode', 'auth.json')
288
+ }
289
+
290
+ /** Provider ids registered in the host auth store (existence only — never values). */
291
+ function readAuthProviders(): Set<string> {
292
+ const names = new Set<string>()
293
+ try {
294
+ const parsed = JSON.parse(readFileSync(decisionAuthStorePath(), 'utf8')) as Record<
295
+ string,
296
+ unknown
297
+ >
298
+ for (const key of Object.keys(parsed)) names.add(key)
299
+ } catch {
300
+ /* no auth store — nothing recognized */
301
+ }
302
+ return names
303
+ }
304
+
305
+ /** Provider ids present in opencode.json `providers` (the config copy the host reads). */
306
+ function readConfigProviders(): Set<string> {
307
+ const names = new Set<string>()
308
+ try {
309
+ const parsed = JSON.parse(readFileSync(userOpenCodeConfigPath(), 'utf8')) as {
310
+ providers?: Record<string, unknown>
311
+ }
312
+ for (const key of Object.keys(parsed?.providers ?? {})) names.add(key)
313
+ } catch {
314
+ /* no config providers */
315
+ }
316
+ return names
317
+ }
318
+
272
319
  function updateCheckStatePath(): string {
273
320
  const stateDir = process.env.XDG_STATE_HOME ?? join(process.env.HOME ?? '', '.local', 'state')
274
321
  return join(stateDir, 'pantheon', 'update-check.json')
@@ -282,9 +329,9 @@ function readUpdateCheckState(): UpdateCheckState {
282
329
  }
283
330
  }
284
331
 
285
- async function fetchLatestForChannel(currentVersion: string): Promise<string | null> {
332
+ async function fetchLatestForChannel(channel: UpdateChannel): Promise<string | null> {
286
333
  try {
287
- const response = await fetch(registryUrlForChannel(updateChannelFor(currentVersion)), {
334
+ const response = await fetch(registryUrlForChannel(channel), {
288
335
  signal: AbortSignal.timeout(5000),
289
336
  })
290
337
  const latest = String(((await response.json()) as { version?: unknown })?.version ?? '')
@@ -327,103 +374,324 @@ function resolveRunningVersion(): string {
327
374
 
328
375
  // ── The window view (presentational; both surfaces render it) ──────────
329
376
 
330
- const NAME_WIDTH = 28
331
- const VALUE_WIDTH = 22
377
+ const NAME_WIDTH = 26
378
+ const VALUE_WIDTH = 24
332
379
 
333
380
  export function SettingsWindow(props: {
334
381
  version: string
335
382
  tabs: () => SettingsTab[]
336
383
  page: () => number
337
- selected: () => number
384
+ selectedId: () => string | undefined
338
385
  draft: () => SettingsDraft
339
386
  notice: () => string | undefined
387
+ confirmExit?: () => boolean
340
388
  fg?: any
341
389
  muted?: any
342
390
  warn?: any
391
+ hasKeyboard?: () => boolean
392
+ onJumpTab?: (index: number) => void
393
+ onSelectRow?: (id: string) => void
394
+ onCycleValue?: (id: string, direction: 1 | -1) => void
395
+ onSave?: () => void
396
+ onResetPage?: () => void
397
+ onStageDefaults?: () => void
398
+ onClose?: () => void
399
+ onDiscard?: () => void
400
+ onCancelExit?: () => void
401
+ isDialog?: boolean
402
+ maxHeight?: number
403
+ height?: number
404
+ boxRef?: (el: any) => void
405
+ onMouseDown?: () => void
343
406
  }) {
344
407
  const tab = () => props.tabs()[props.page()] ?? props.tabs()[0] ?? EMPTY_TAB
345
- const rows = () => tabRows(tab())
346
408
  return (
347
- <box flexDirection="column" paddingLeft={1} paddingRight={1} paddingTop={1}>
348
- <box flexDirection="row">
349
- <text flexShrink={0} attributes={1} fg={props.fg}>
350
- {`Pantheon v${props.version}`}
351
- </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'}
409
+ <box
410
+ {...(props.boxRef !== undefined ? { ref: props.boxRef } : {})}
411
+ focusable
412
+ flexDirection="column"
413
+ {...(props.height !== undefined ? { height: props.height } : { flexGrow: 1, flexBasis: 0 })}
414
+ minHeight={0}
415
+ border={!props.isDialog}
416
+ {...(props.isDialog ? {} : { borderStyle: 'rounded' as const })}
417
+ borderColor={
418
+ props.isDialog
419
+ ? undefined
420
+ : props.hasKeyboard?.()
421
+ ? (props.warn ?? '#fba970')
422
+ : (props.muted ?? '#52525b')
423
+ }
424
+ paddingLeft={1}
425
+ paddingRight={1}
426
+ paddingTop={0}
427
+ paddingBottom={0}
428
+ {...(props.onMouseDown !== undefined ? { onMouseDown: props.onMouseDown } : {})}
429
+ >
430
+ {/* ── Top Header bar: Title + Horizontal Clickable Tabs + ESC (matching opencode-quota) ── */}
431
+ <box
432
+ flexDirection="row"
433
+ flexWrap="wrap"
434
+ alignItems="center"
435
+ flexShrink={0}
436
+ marginBottom={1}
437
+ rowGap={1}
438
+ >
439
+ <text fg={props.fg} attributes={1} wrapMode="none">
440
+ <b>{'Pantheon'}</b>
441
+ <span style={{ fg: props.muted }}>{` v${props.version}`}</span>
366
442
  </text>
443
+ <box width={2} />
444
+ <box
445
+ flexDirection="row"
446
+ flexWrap="wrap"
447
+ flexGrow={1}
448
+ flexShrink={0}
449
+ columnGap={1}
450
+ rowGap={1}
451
+ >
452
+ <For each={props.tabs()}>
453
+ {(t, index) => {
454
+ const isActive = () => index() === props.page()
455
+ return (
456
+ <box
457
+ onMouseDown={() => props.onJumpTab?.(index())}
458
+ paddingLeft={1}
459
+ paddingRight={1}
460
+ flexShrink={0}
461
+ {...(isActive() ? { backgroundColor: '#262626' } : {})}
462
+ >
463
+ <text
464
+ wrapMode="none"
465
+ fg={isActive() ? (props.warn ?? '#fba970') : props.muted}
466
+ {...(isActive() ? { attributes: 1 } : {})}
467
+ >
468
+ {`${t.title}${tabDirty(props.draft(), t) ? ' ●' : ''}`}
469
+ </text>
470
+ </box>
471
+ )
472
+ }}
473
+ </For>
474
+ </box>
475
+ <box onMouseDown={() => props.onClose?.()} paddingLeft={1} flexShrink={0}>
476
+ <text fg={props.muted} wrapMode="none">
477
+ {'esc'}
478
+ </text>
479
+ </box>
367
480
  </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 } : {})}
481
+
482
+ {/* ── Main Body: Scrollable content panel ── */}
483
+ <box flexDirection="column" flexGrow={1} flexBasis={0} minHeight={0} overflow="hidden">
484
+ <scrollbox
485
+ flexGrow={1}
486
+ flexBasis={0}
487
+ minHeight={0}
488
+ {...(props.maxHeight !== undefined ? { maxHeight: props.maxHeight } : {})}
489
+ >
490
+ <For each={tab().groups}>
491
+ {(group) => (
492
+ <box flexDirection="column" marginBottom={1}>
493
+ <Show when={group.title !== undefined}>
494
+ <text attributes={1} fg={props.warn ?? props.fg}>
495
+ {group.title}
496
+ </text>
497
+ </Show>
498
+ <For each={group.rows}>
499
+ {(row: SettingsRow) => {
500
+ const isSelected = () => row.id === props.selectedId()
501
+ const display = () => props.draft()[row.id] ?? row.value
502
+ const staged = () => props.draft()[row.id] !== undefined
503
+ const gutter = () => (isSelected() ? '▸ ' : ' ')
504
+ const valueCell = () => {
505
+ if (row.cycle !== undefined) return `< ${display()} >`
506
+ if (row.action !== undefined) return `[ ${display()} ]`
507
+ if (row.id.startsWith('autonomy.gradient.')) return `[ref] ${display()}`
508
+ return display()
509
+ }
510
+ return (
511
+ <box
512
+ flexDirection="row"
513
+ {...(isSelected() ? { backgroundColor: '#262626' } : {})}
514
+ onMouseDown={() => {
515
+ props.onSelectRow?.(row.id)
516
+ }}
395
517
  >
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>
518
+ <box width={NAME_WIDTH + 2}>
519
+ <text
520
+ fg={isSelected() ? (props.warn ?? '#fba970') : props.fg}
521
+ {...(isSelected() ? { attributes: 1 } : {})}
522
+ >
523
+ {`${gutter()}${row.name}`.padEnd(NAME_WIDTH + 2)}
524
+ </text>
525
+ </box>
526
+ <box
527
+ width={VALUE_WIDTH}
528
+ onMouseDown={() => {
529
+ props.onSelectRow?.(row.id)
530
+ props.onCycleValue?.(row.id, 1)
531
+ }}
532
+ >
533
+ <text
534
+ fg={
535
+ isSelected()
536
+ ? '#ffffff'
537
+ : staged()
538
+ ? (props.warn ?? props.fg)
539
+ : props.muted
540
+ }
541
+ {...(isSelected() || staged() ? { attributes: 1 } : {})}
542
+ >
543
+ {`${valueCell()}${staged() ? ' ●' : ''}`.padEnd(VALUE_WIDTH)}
544
+ </text>
545
+ </box>
546
+ <Show when={row.note !== undefined}>
547
+ <box flexGrow={1} flexShrink={1}>
548
+ <text fg={isSelected() ? '#e5e7eb' : props.muted}>{row.note}</text>
549
+ </box>
550
+ </Show>
402
551
  </box>
403
- </Show>
404
- </box>
405
- )
406
- }}
407
- </For>
408
- <box height={1} />
409
- </box>
410
- )}
411
- </For>
552
+ )
553
+ }}
554
+ </For>
555
+ </box>
556
+ )}
557
+ </For>
558
+ </scrollbox>
559
+ </box>
560
+
561
+ {/* ── Footer: notice + botões (chips) + keys (matching image.png & image_2.png) ── */}
412
562
  <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()}`}
563
+ <text
564
+ fg={
565
+ props.notice()?.startsWith('[OK]') || props.notice()?.startsWith('saved')
566
+ ? props.fg
567
+ : (props.warn ?? props.muted)
568
+ }
569
+ >
570
+ {props.notice()?.startsWith('[OK]') || props.notice()?.startsWith('saved')
571
+ ? props.notice()
572
+ : `[WARN] ${props.notice()}`}
415
573
  </text>
416
574
  </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'
575
+
576
+ <Show
577
+ when={props.confirmExit?.()}
578
+ fallback={
579
+ <box flexDirection="column">
580
+ <Show
581
+ when={draftDirty(props.draft())}
582
+ fallback={
583
+ <box
584
+ flexDirection="row"
585
+ flexWrap="wrap"
586
+ alignItems="center"
587
+ flexShrink={0}
588
+ rowGap={1}
589
+ >
590
+ <box
591
+ backgroundColor="#262626"
592
+ flexShrink={0}
593
+ onMouseDown={() => props.onClose?.()}
594
+ >
595
+ <text fg="#ffffff">{' Close '}</text>
596
+ </box>
597
+ <text fg={props.muted} flexShrink={0}>
598
+ {' '}
599
+ </text>
600
+ <box
601
+ backgroundColor="#262626"
602
+ flexShrink={0}
603
+ onMouseDown={() => props.onResetPage?.()}
604
+ >
605
+ <text fg="#ffffff">{' Reset page '}</text>
606
+ </box>
607
+ <text fg={props.muted} flexShrink={0}>
608
+ {' '}
609
+ </text>
610
+ <box
611
+ backgroundColor="#262626"
612
+ flexShrink={0}
613
+ onMouseDown={() => props.onStageDefaults?.()}
614
+ >
615
+ <text fg="#ffffff">{' Defaults '}</text>
616
+ </box>
617
+ <box flexGrow={1} minWidth={1} />
618
+ <text fg={props.muted} flexShrink={0}>
619
+ {'no staged changes'}
620
+ </text>
621
+ </box>
622
+ }
623
+ >
624
+ <box
625
+ flexDirection="row"
626
+ flexWrap="wrap"
627
+ alignItems="center"
628
+ flexShrink={0}
629
+ rowGap={1}
630
+ >
631
+ <box backgroundColor="#fba970" flexShrink={0} onMouseDown={() => props.onSave?.()}>
632
+ <text fg="#000000">{' Save '}</text>
633
+ </box>
634
+ <text fg={props.muted} flexShrink={0}>
635
+ {' '}
636
+ </text>
637
+ <box
638
+ backgroundColor="#262626"
639
+ flexShrink={0}
640
+ onMouseDown={() => props.onDiscard?.()}
641
+ >
642
+ <text fg="#ffffff">{' Discard '}</text>
643
+ </box>
644
+ <text fg={props.muted} flexShrink={0}>
645
+ {' '}
646
+ </text>
647
+ <box
648
+ backgroundColor="#262626"
649
+ flexShrink={0}
650
+ onMouseDown={() => props.onResetPage?.()}
651
+ >
652
+ <text fg="#ffffff">{' Reset page '}</text>
653
+ </box>
654
+ <box flexGrow={1} minWidth={1} />
655
+ <text fg={props.warn ?? '#f59e0b'} flexShrink={0}>
656
+ {'unsaved changes'}
657
+ </text>
658
+ </box>
659
+ </Show>
660
+ <text fg={props.muted}>
661
+ {(() => {
662
+ const currentRow = findRow(tab(), props.selectedId() ?? '')
663
+ if (currentRow?.cycle !== undefined) {
664
+ return 'click or ›/←/→ change · ↑↓ select · tab next tab · ctrl+s save · ctrl+r reset page · esc close'
665
+ }
666
+ if (currentRow?.action !== undefined) {
667
+ return 'enter or space run action · ↑↓ select · tab next tab · ctrl+s save · ctrl+r reset page · esc close'
668
+ }
669
+ return '[ref] documented reference (read-only) · ↑↓ select · tab next tab · esc close'
670
+ })()}
671
+ </text>
672
+ </box>
425
673
  }
426
- </text>
674
+ >
675
+ <box flexDirection="column">
676
+ <box flexDirection="row">
677
+ <text fg={props.warn ?? '#f59e0b'} attributes={1}>
678
+ {'Keep your changes? '}
679
+ </text>
680
+ <box backgroundColor="#fba970" onMouseDown={() => props.onSave?.()}>
681
+ <text fg="#000000">{' Save '}</text>
682
+ </box>
683
+ <text fg={props.muted}>{' '}</text>
684
+ <box backgroundColor="#262626" onMouseDown={() => props.onDiscard?.()}>
685
+ <text fg="#ffffff">{' Discard '}</text>
686
+ </box>
687
+ <text fg={props.muted}>{' '}</text>
688
+ <box backgroundColor="#262626" onMouseDown={() => props.onCancelExit?.()}>
689
+ <text fg="#ffffff">{' Keep editing '}</text>
690
+ </box>
691
+ </box>
692
+ <text fg={props.muted}>{'ctrl+s save · d discard the changes · esc keep editing'}</text>
693
+ </box>
694
+ </Show>
427
695
  </box>
428
696
  )
429
697
  }
@@ -433,12 +701,19 @@ export function SettingsWindow(props: {
433
701
  interface PageApi {
434
702
  move: (delta: number) => void
435
703
  step: (direction: 1 | -1) => void
704
+ selectById?: (id: string) => void
705
+ cycleRowById?: (id: string, direction: 1 | -1) => void
436
706
  actuate: () => void
437
707
  nextTab: () => void
708
+ prevTab?: () => void
438
709
  jumpTab: (index: number) => void
439
710
  save: () => void
440
711
  resetPage: () => void
712
+ stageDefaults: () => void
441
713
  close: () => void
714
+ discard?: () => void
715
+ cancelExit?: () => void
716
+ confirmExit?: () => boolean
442
717
  }
443
718
 
444
719
  let pageApi: PageApi | undefined
@@ -449,12 +724,14 @@ function createWindowController(
449
724
  ): {
450
725
  tabs: () => SettingsTab[]
451
726
  page: () => number
452
- selected: () => number
727
+ selectedId: () => string | undefined
453
728
  draft: () => SettingsDraft
454
729
  notice: () => string | undefined
730
+ confirmExit: () => boolean
455
731
  api: PageApi
456
732
  cleanup: () => void
457
733
  } {
734
+ const currentVersion = resolveRunningVersion()
458
735
  const [page, setPage] = createSignal(0)
459
736
  const [selected, setSelected] = createSignal(0)
460
737
  const [load, setLoad] = createSignal(readOverridesLoad())
@@ -463,12 +740,38 @@ function createWindowController(
463
740
  const [budgets, setBudgets] = createSignal<DecisionBudgets>(readDecisionBudgets())
464
741
  const [autonomyRestartPending, setAutonomyRestartPending] = createSignal(false)
465
742
  const [presetTick, setPresetTick] = createSignal(0)
743
+ const [selectedChannel, setSelectedChannel] = createSignal<UpdateChannel>(
744
+ updateChannelFor(currentVersion),
745
+ )
466
746
  const [lastChecked, setLastChecked] = createSignal<string | undefined>(undefined)
467
747
  const [checking, setChecking] = createSignal(false)
748
+ const [updating, setUpdating] = createSignal(false)
749
+ const [changelogItems, setChangelogItems] = createSignal<ChangelogHighlightItem[]>([])
468
750
  const [draft, setDraft] = createSignal<SettingsDraft>({})
469
751
  const [notice, setNotice] = createSignal<string | undefined>(undefined)
752
+ const [confirmExit, setConfirmExit] = createSignal(false)
470
753
 
471
- const currentVersion = resolveRunningVersion()
754
+ // Real-time preview of staged draft preferences across open TUI views
755
+ createEffect(() => {
756
+ setTuiDraftPreview(draft())
757
+ })
758
+
759
+ // Load changelog highlights asynchronously
760
+ void readChangelogForBundle(import.meta.url).then((text) => {
761
+ if (!text) return
762
+ const hl = extractHighlights(text, currentVersion)
763
+ if (hl.found) {
764
+ const items: ChangelogHighlightItem[] = []
765
+ for (const group of hl.groups) {
766
+ for (const item of group.items) {
767
+ const dash = item.indexOf('—')
768
+ const title = dash !== -1 ? item.slice(0, dash).trim() : item.slice(0, 26)
769
+ items.push({ title, detail: item, group: group.heading ?? undefined })
770
+ }
771
+ }
772
+ setChangelogItems(items)
773
+ }
774
+ })
472
775
 
473
776
  const presetInput = () => {
474
777
  void presetTick()
@@ -482,7 +785,9 @@ function createWindowController(
482
785
  const input: UpdatesSectionInput = {
483
786
  currentVersion,
484
787
  state: readUpdateCheckState(),
788
+ selectedChannel: selectedChannel(),
485
789
  checking: checking(),
790
+ updating: updating(),
486
791
  nowMs: Date.now(),
487
792
  }
488
793
  const seen = lastChecked()
@@ -492,9 +797,9 @@ function createWindowController(
492
797
 
493
798
  const tabs = (): SettingsTab[] => [
494
799
  buildGatesTab(load()),
495
- buildDecisionTab(decision()),
800
+ buildDecisionTab(decision(), process.env, readAuthProviders(), readConfigProviders()),
496
801
  buildPresetTab(presetInput()),
497
- buildTuiTab(tuiPrefs()),
802
+ buildTuiTab(savedTuiPrefs()),
498
803
  buildAutonomyTab({
499
804
  goalLoop: goalLoop(),
500
805
  budgets: budgets(),
@@ -502,6 +807,7 @@ function createWindowController(
502
807
  }),
503
808
  buildJ1Tab(process.env, false),
504
809
  buildUpdatesTab(updatesInput()),
810
+ buildChangelogTab(currentVersion, changelogItems()),
505
811
  buildDoctorTab({
506
812
  runningVersion: currentVersion,
507
813
  nodeVersion: process.versions.node,
@@ -513,34 +819,77 @@ function createWindowController(
513
819
  const rows = () => tabRows(tabs()[page()] ?? tabs()[0] ?? EMPTY_TAB)
514
820
 
515
821
  const move = (delta: number) => {
822
+ if (confirmExit()) setConfirmExit(false)
516
823
  const list = rows()
517
824
  if (list.length === 0) return
518
825
  setSelected((current) => Math.min(Math.max(current + delta, 0), list.length - 1))
519
826
  }
520
827
 
521
828
  const step = (direction: 1 | -1) => {
829
+ if (confirmExit()) setConfirmExit(false)
522
830
  const row = rows()[selected()]
523
831
  if (row === undefined) return
524
832
  setNotice(undefined)
525
833
  setDraft(stageValue(draft(), row, direction))
526
834
  }
527
835
 
528
- const checkUpdatesNow = () => {
836
+ const checkUpdatesNow = (targetChannel: UpdateChannel = selectedChannel()) => {
529
837
  if (checking()) return
530
838
  setChecking(true)
531
839
  setNotice(undefined)
532
- void fetchLatestForChannel(currentVersion)
840
+ void fetchLatestForChannel(targetChannel)
533
841
  .then((latest) => {
534
- if (latest) setLastChecked(latest)
535
- persistUpdateCheckState(readUpdateCheckState(), latest)
842
+ if (latest) {
843
+ setLastChecked(latest)
844
+ persistUpdateCheckState(readUpdateCheckState(), latest)
845
+ }
536
846
  })
537
847
  .catch(() => {
538
- /* offline — the row keeps the last known state */
848
+ /* offline */
539
849
  })
540
850
  .finally(() => setChecking(false))
541
851
  }
542
852
 
853
+ const runUpdateNow = () => {
854
+ if (updating()) return
855
+ setUpdating(true)
856
+ setNotice(`updating to ${selectedChannel()} channel…`)
857
+ execFile(
858
+ 'npm',
859
+ ['install', '-g', `pantheon-opencode@${selectedChannel()}`],
860
+ { timeout: 60_000 },
861
+ (err) => {
862
+ setUpdating(false)
863
+ if (err) {
864
+ setNotice('run in terminal: pantheon-opencode update')
865
+ try {
866
+ context.ui.toast?.show?.({
867
+ variant: 'warning',
868
+ message: 'Update requires terminal permissions: run `pantheon-opencode update`',
869
+ })
870
+ } catch {}
871
+ } else {
872
+ setNotice('[OK] update complete — restart OpenCode or run `npx pantheon-opencode init`')
873
+ try {
874
+ context.ui.toast?.show?.({
875
+ variant: 'info',
876
+ message: 'Pantheon updated successfully!',
877
+ })
878
+ } catch {}
879
+ }
880
+ },
881
+ )
882
+ }
883
+
543
884
  const dispatchWrite = (id: string, value: string): DraftWriterResult => {
885
+ if (id === 'update.channel') {
886
+ if (value === 'stable' || value === 'beta') {
887
+ setSelectedChannel(value as UpdateChannel)
888
+ checkUpdatesNow(value as UpdateChannel)
889
+ return { ok: true }
890
+ }
891
+ return { ok: false, reason: 'unknown channel' }
892
+ }
544
893
  if (id.startsWith('gate.')) {
545
894
  if (!canWriteOverrides(load())) {
546
895
  return { ok: false, reason: 'overrides file unreadable — repair with `doctor --fix`' }
@@ -654,10 +1003,6 @@ function createWindowController(
654
1003
  }
655
1004
  }
656
1005
  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
1006
  try {
662
1007
  mutateTuiPrefs((prefsDraft) => applyTuiRow(prefsDraft, id, value))
663
1008
  .then(() => setNotice(undefined))
@@ -689,28 +1034,42 @@ function createWindowController(
689
1034
  setNotice(`${failed.map((f) => `${f.id}: ${f.reason}`).join(' · ')} — staged changes kept`)
690
1035
  } else {
691
1036
  setNotice(`saved ${applied.length} change${applied.length === 1 ? '' : 's'}`)
1037
+ if (confirmExit()) {
1038
+ exit()
1039
+ }
692
1040
  }
693
1041
  }
694
1042
 
695
1043
  const resetPage = () => {
1044
+ if (confirmExit()) setConfirmExit(false)
696
1045
  const tab = tabs()[page()]
697
1046
  if (tab === undefined) return
698
1047
  setDraft(resetTab(draft(), tab))
699
1048
  setNotice(undefined)
700
1049
  }
701
1050
 
1051
+ const stageDefaultsPage = () => {
1052
+ if (confirmExit()) setConfirmExit(false)
1053
+ const tab = tabs()[page()]
1054
+ if (tab === undefined) return
1055
+ setNotice(undefined)
1056
+ setDraft(stageDefaults(draft(), tab))
1057
+ }
1058
+
702
1059
  const nextTab = () => {
1060
+ if (confirmExit()) setConfirmExit(false)
703
1061
  setPage((current) => (current + 1) % tabs().length)
704
1062
  setSelected(0)
705
1063
  }
706
1064
 
707
1065
  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
1066
  const staged = draftCount(draft())
1067
+ if (staged > 0 && !confirmExit()) {
1068
+ setConfirmExit(true)
1069
+ return
1070
+ }
713
1071
  if (staged > 0) {
1072
+ clearTuiDraftPreview()
714
1073
  setDraft({})
715
1074
  try {
716
1075
  context.ui.toast?.show?.({
@@ -724,16 +1083,76 @@ function createWindowController(
724
1083
  exit()
725
1084
  }
726
1085
 
1086
+ const discard = () => {
1087
+ const staged = draftCount(draft())
1088
+ clearTuiDraftPreview()
1089
+ setDraft({})
1090
+ setConfirmExit(false)
1091
+ if (staged > 0) {
1092
+ try {
1093
+ context.ui.toast?.show?.({
1094
+ variant: 'info',
1095
+ message: `settings: ${staged} staged change${staged === 1 ? '' : 's'} discarded`,
1096
+ })
1097
+ } catch {
1098
+ /* toast unavailable */
1099
+ }
1100
+ }
1101
+ exit()
1102
+ }
1103
+
1104
+ const cancelExit = () => {
1105
+ setConfirmExit(false)
1106
+ }
1107
+
1108
+ const selectedId = () => rows()[selected()]?.id
1109
+
1110
+ const selectById = (id: string) => {
1111
+ if (confirmExit()) setConfirmExit(false)
1112
+ const list = rows()
1113
+ const index = list.findIndex((r) => r.id === id)
1114
+ if (index !== -1) setSelected(index)
1115
+ }
1116
+
1117
+ const cycleRowById = (id: string, direction: 1 | -1) => {
1118
+ if (confirmExit()) setConfirmExit(false)
1119
+ const list = rows()
1120
+ const index = list.findIndex((r) => r.id === id)
1121
+ if (index !== -1) {
1122
+ setSelected(index)
1123
+ const row = list[index]
1124
+ if (row?.action === 'update-check') checkUpdatesNow()
1125
+ else if (row?.action === 'update-run') runUpdateNow()
1126
+ else if (row) {
1127
+ setNotice(undefined)
1128
+ setDraft(stageValue(draft(), row, direction))
1129
+ }
1130
+ }
1131
+ }
1132
+
727
1133
  const api: PageApi = {
728
1134
  move,
729
1135
  step,
1136
+ selectById,
1137
+ cycleRowById,
730
1138
  actuate: () => {
1139
+ if (confirmExit()) setConfirmExit(false)
731
1140
  const row = rows()[selected()]
732
1141
  if (row?.action === 'update-check') checkUpdatesNow()
1142
+ else if (row?.action === 'update-run') runUpdateNow()
733
1143
  else step(1)
734
1144
  },
735
1145
  nextTab,
1146
+ prevTab: () => {
1147
+ if (confirmExit()) setConfirmExit(false)
1148
+ const count = tabs().length
1149
+ if (count > 0) {
1150
+ setPage((current) => (current - 1 + count) % count)
1151
+ setSelected(0)
1152
+ }
1153
+ },
736
1154
  jumpTab: (index) => {
1155
+ if (confirmExit()) setConfirmExit(false)
737
1156
  if (index >= 0 && index < tabs().length) {
738
1157
  setPage(index)
739
1158
  setSelected(0)
@@ -741,17 +1160,23 @@ function createWindowController(
741
1160
  },
742
1161
  save,
743
1162
  resetPage,
1163
+ stageDefaults: stageDefaultsPage,
744
1164
  close,
1165
+ discard,
1166
+ cancelExit,
1167
+ confirmExit: () => confirmExit(),
745
1168
  }
746
1169
 
747
1170
  return {
748
1171
  tabs,
749
1172
  page,
750
- selected,
1173
+ selectedId,
751
1174
  draft,
752
1175
  notice,
1176
+ confirmExit: () => confirmExit(),
753
1177
  api,
754
1178
  cleanup: () => {
1179
+ clearTuiDraftPreview()
755
1180
  pageApi = undefined
756
1181
  setBlocking(false)
757
1182
  },
@@ -787,12 +1212,22 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
787
1212
  version={resolveRunningVersion()}
788
1213
  tabs={controller.tabs}
789
1214
  page={controller.page}
790
- selected={controller.selected}
1215
+ selectedId={controller.selectedId}
791
1216
  draft={controller.draft}
792
1217
  notice={controller.notice}
1218
+ confirmExit={controller.confirmExit}
793
1219
  fg={theme.base}
794
1220
  muted={theme.muted}
795
1221
  warn={warn}
1222
+ onJumpTab={(idx) => controller.api.jumpTab(idx)}
1223
+ onSelectRow={(id) => controller.api.selectById?.(id)}
1224
+ onCycleValue={(id, dir) => controller.api.cycleRowById?.(id, dir)}
1225
+ onSave={() => controller.api.save()}
1226
+ onResetPage={() => controller.api.resetPage()}
1227
+ onStageDefaults={() => controller.api.stageDefaults()}
1228
+ onClose={() => controller.api.close()}
1229
+ onDiscard={() => controller.api.discard?.()}
1230
+ onCancelExit={() => controller.api.cancelExit?.()}
796
1231
  />
797
1232
  )
798
1233
  }
@@ -800,12 +1235,7 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
800
1235
  function navigateBack(context: Context, data?: { returnRoute?: WindowRoute }): void {
801
1236
  try {
802
1237
  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)
1238
+ context.ui.router.navigate(data?.returnRoute ?? fallback)
809
1239
  } catch {
810
1240
  /* router unavailable — the failure is observable only as a stuck page */
811
1241
  }
@@ -841,6 +1271,8 @@ function openSettingsDialog(context: Context): void {
841
1271
  setBlocking(true)
842
1272
  setDialogOpen(true)
843
1273
  pageApi = controller.api
1274
+ const rendererHeight = () => (context as any).renderer?.height ?? 30
1275
+ const maxHeight = () => Math.min(16, Math.max(8, Math.floor(rendererHeight() * 0.55)))
844
1276
  try {
845
1277
  context.ui.dialog.show(
846
1278
  () => (
@@ -848,21 +1280,185 @@ function openSettingsDialog(context: Context): void {
848
1280
  version={resolveRunningVersion()}
849
1281
  tabs={controller.tabs}
850
1282
  page={controller.page}
851
- selected={controller.selected}
1283
+ selectedId={controller.selectedId}
852
1284
  draft={controller.draft}
853
1285
  notice={controller.notice}
1286
+ confirmExit={controller.confirmExit}
854
1287
  fg={theme.base}
855
1288
  muted={theme.muted}
856
1289
  warn={warn}
1290
+ isDialog={true}
1291
+ maxHeight={maxHeight()}
1292
+ onJumpTab={(idx) => controller.api.jumpTab(idx)}
1293
+ onSelectRow={(id) => controller.api.selectById?.(id)}
1294
+ onCycleValue={(id, dir) => controller.api.cycleRowById?.(id, dir)}
1295
+ onSave={() => controller.api.save()}
1296
+ onResetPage={() => controller.api.resetPage()}
1297
+ onStageDefaults={() => controller.api.stageDefaults()}
1298
+ onClose={() => controller.api.close()}
1299
+ onDiscard={() => controller.api.discard?.()}
1300
+ onCancelExit={() => controller.api.cancelExit?.()}
857
1301
  />
858
1302
  ),
859
1303
  close,
860
1304
  )
1305
+ context.ui.dialog.set({ size: 'large' })
861
1306
  } catch {
862
1307
  /* dialog stack unavailable — fail-open */
863
1308
  }
864
1309
  }
865
1310
 
1311
+ // ── In-session docked window (session.composer.top) ─────────────────────
1312
+
1313
+ const [settingsOpen, setSettingsOpen] = createSignal(false)
1314
+ const [activeSessionId, setActiveSessionId] = createSignal<string | undefined>()
1315
+
1316
+ export function isPantheonSettingsOpen(): boolean {
1317
+ return settingsOpen()
1318
+ }
1319
+
1320
+ export function routeSessionID(context: any): string | undefined {
1321
+ try {
1322
+ const route = context?.ui?.router?.current?.()
1323
+ return route?.type === 'session' ? route?.sessionID : undefined
1324
+ } catch {
1325
+ return undefined
1326
+ }
1327
+ }
1328
+
1329
+ export function closePantheonSettings(): void {
1330
+ if (pageApi) {
1331
+ pageApi.close()
1332
+ if (pageApi.confirmExit?.()) {
1333
+ return
1334
+ }
1335
+ }
1336
+ setSettingsOpen(false)
1337
+ setBlocking(false)
1338
+ }
1339
+
1340
+ export function PantheonSettingsSlot(props: { context: Context; sessionID: string }) {
1341
+ onMount(() => {
1342
+ setActiveSessionId(props.sessionID)
1343
+ })
1344
+ onCleanup(() => {
1345
+ if (activeSessionId() === props.sessionID) {
1346
+ setActiveSessionId(undefined)
1347
+ }
1348
+ })
1349
+ return (
1350
+ <Show when={settingsOpen() && (activeSessionId() === props.sessionID || !activeSessionId())}>
1351
+ <InSessionSettingsWindow context={props.context} sessionID={props.sessionID} />
1352
+ </Show>
1353
+ )
1354
+ }
1355
+
1356
+ function InSessionSettingsWindow(props: { context: Context; sessionID: string }) {
1357
+ let windowBox: any
1358
+ const context = props.context
1359
+ const initialRoom = () => Math.max(14, ((context as any).renderer?.height ?? 30) - 10)
1360
+ const [roomHeight, setRoomHeight] = createSignal<number>(initialRoom())
1361
+ const [hasKeyboard, setHasKeyboard] = createSignal(false)
1362
+
1363
+ function measureRoom(): void {
1364
+ const box = windowBox
1365
+ if (!box || box.isDestroyed) return
1366
+ let child = box
1367
+ for (let parent = box.parent; parent; child = parent, parent = parent.parent) {
1368
+ const siblings = parent.getChildren?.() ?? []
1369
+ const messages = siblings[0]
1370
+ if (
1371
+ messages === child ||
1372
+ !messages?.getChildren?.().some((item: any) => 'scrollChildIntoView' in item)
1373
+ ) {
1374
+ continue
1375
+ }
1376
+ const otherRows = siblings
1377
+ .filter((item: any) => item !== child && item !== messages)
1378
+ .reduce((total: number, item: any) => total + (item.height ?? 0), 0)
1379
+ const room = Math.max(
1380
+ 12,
1381
+ (parent.height ?? 24) - 1 - otherRows - ((child.height ?? 0) - (box.height ?? 0)),
1382
+ )
1383
+ if (room !== roomHeight()) queueMicrotask(() => setRoomHeight(room))
1384
+ return
1385
+ }
1386
+ }
1387
+
1388
+ onMount(() => {
1389
+ try {
1390
+ ;(context as any).renderer?.root?.on?.('layout-changed', measureRoom)
1391
+ ;(context as any).renderer?.on?.('resize', measureRoom)
1392
+ onCleanup(() => {
1393
+ try {
1394
+ ;(context as any).renderer?.root?.off?.('layout-changed', measureRoom)
1395
+ ;(context as any).renderer?.off?.('resize', measureRoom)
1396
+ } catch {}
1397
+ })
1398
+ } catch {}
1399
+ measureRoom()
1400
+ setTimeout(() => {
1401
+ try {
1402
+ windowBox?.focus?.()
1403
+ } catch {}
1404
+ }, 50)
1405
+ })
1406
+
1407
+ try {
1408
+ const popMode = (context as any).keymap?.mode?.push?.(ROUTE_MODE)
1409
+ if (popMode !== undefined) onCleanup(() => popMode())
1410
+ } catch {}
1411
+
1412
+ const controller = createWindowController(context, () => {
1413
+ setSettingsOpen(false)
1414
+ setBlocking(false)
1415
+ })
1416
+
1417
+ onCleanup(controller.cleanup)
1418
+ pageApi = controller.api
1419
+
1420
+ const theme = (context as any).theme?.text ?? {}
1421
+ const warn = (theme?.feedback as any)?.warning?.base ?? '#fba970'
1422
+
1423
+ return (
1424
+ <SettingsWindow
1425
+ boxRef={(el: any) => {
1426
+ windowBox = el
1427
+ if (el) {
1428
+ el.on?.('focused', () => setHasKeyboard(true))
1429
+ el.on?.('blurred', () => setHasKeyboard(false))
1430
+ }
1431
+ }}
1432
+ height={roomHeight()}
1433
+ version={resolveRunningVersion()}
1434
+ tabs={controller.tabs}
1435
+ page={controller.page}
1436
+ selectedId={controller.selectedId}
1437
+ draft={controller.draft}
1438
+ notice={controller.notice}
1439
+ confirmExit={controller.confirmExit}
1440
+ fg={theme.base}
1441
+ muted={theme.muted}
1442
+ warn={warn}
1443
+ hasKeyboard={hasKeyboard}
1444
+ onJumpTab={(idx) => controller.api.jumpTab(idx)}
1445
+ onSelectRow={(id) => controller.api.selectById?.(id)}
1446
+ onCycleValue={(id, dir) => controller.api.cycleRowById?.(id, dir)}
1447
+ onSave={() => controller.api.save()}
1448
+ onResetPage={() => controller.api.resetPage()}
1449
+ onStageDefaults={() => controller.api.stageDefaults()}
1450
+ onClose={() => closePantheonSettings()}
1451
+ onDiscard={() => controller.api.discard?.()}
1452
+ onCancelExit={() => controller.api.cancelExit?.()}
1453
+ onMouseDown={() => {
1454
+ try {
1455
+ windowBox?.focus?.()
1456
+ } catch {}
1457
+ }}
1458
+ />
1459
+ )
1460
+ }
1461
+
866
1462
  // ── Setup: register once, gate once, priority 1 (anti-theft) ───────────
867
1463
 
868
1464
  export function setupPantheonSettings(context: Context): void {
@@ -890,21 +1486,27 @@ export function setupPantheonSettings(context: Context): void {
890
1486
  title: 'Close settings',
891
1487
  bind: 'escape,q',
892
1488
  run: () => {
893
- try {
894
- context.ui.toast?.show?.({ variant: 'info', message: 'settings: close command fired' })
895
- } catch {}
896
1489
  if (pageApi === undefined) {
897
- try {
898
- context.ui.toast?.show?.({
899
- variant: 'warning',
900
- message: 'settings: no window controller bound',
901
- })
902
- } catch {
903
- /* toast unavailable */
904
- }
1490
+ closePantheonSettings()
1491
+ return undefined
1492
+ }
1493
+ if (pageApi.confirmExit?.()) {
1494
+ pageApi.cancelExit?.()
1495
+ return undefined
1496
+ }
1497
+ closePantheonSettings()
1498
+ return undefined
1499
+ },
1500
+ },
1501
+ {
1502
+ id: 'pantheon.settings.discard',
1503
+ title: 'Discard staged changes and exit',
1504
+ bind: 'd',
1505
+ run: () => {
1506
+ if (pageApi?.confirmExit?.()) {
1507
+ pageApi.discard?.()
905
1508
  return undefined
906
1509
  }
907
- pageApi.close()
908
1510
  return undefined
909
1511
  },
910
1512
  },
@@ -962,6 +1564,15 @@ export function setupPantheonSettings(context: Context): void {
962
1564
  return undefined
963
1565
  },
964
1566
  },
1567
+ {
1568
+ id: 'pantheon.settings.prev.tab',
1569
+ title: 'Previous settings tab',
1570
+ bind: 'shift+tab',
1571
+ run: () => {
1572
+ pageApi?.prevTab?.()
1573
+ return undefined
1574
+ },
1575
+ },
965
1576
  {
966
1577
  id: 'pantheon.settings.save',
967
1578
  title: 'Save staged changes',
@@ -980,6 +1591,15 @@ export function setupPantheonSettings(context: Context): void {
980
1591
  return undefined
981
1592
  },
982
1593
  },
1594
+ {
1595
+ id: 'pantheon.settings.defaults',
1596
+ title: 'Stage defaults for this tab',
1597
+ bind: 'ctrl+d',
1598
+ run: () => {
1599
+ pageApi?.stageDefaults()
1600
+ return undefined
1601
+ },
1602
+ },
983
1603
  ...Array.from({ length: 9 }, (_, index) => ({
984
1604
  id: `pantheon.settings.tab.${index + 1}`,
985
1605
  title: `Jump to tab ${index + 1}`,
@@ -999,7 +1619,7 @@ export function setupPantheonSettings(context: Context): void {
999
1619
  context.keymap.layer(() => ({
1000
1620
  mode: ROUTE_MODE,
1001
1621
  priority: 1,
1002
- enabled: () => routeGated(),
1622
+ enabled: () => routeGated() || settingsOpen(),
1003
1623
  commands,
1004
1624
  }))
1005
1625
  } catch {
@@ -1010,7 +1630,7 @@ export function setupPantheonSettings(context: Context): void {
1010
1630
  context.keymap.layer(() => ({
1011
1631
  mode: 'global' as const,
1012
1632
  priority: 1,
1013
- enabled: () => dialogOpen(),
1633
+ enabled: () => dialogOpen() || settingsOpen(),
1014
1634
  commands,
1015
1635
  }))
1016
1636
  } catch {
@@ -1022,7 +1642,9 @@ export function setupPantheonSettings(context: Context): void {
1022
1642
 
1023
1643
  export async function openPantheonSettings(context: Context): Promise<void> {
1024
1644
  try {
1025
- if (routerAvailable && context.ui?.router?.navigate) {
1645
+ const prefs = tuiPrefs()
1646
+ const viewMode = prefs.layout?.settingsView ?? 'docked'
1647
+ if (viewMode === 'fullscreen' && routerAvailable && context.ui?.router?.navigate) {
1026
1648
  let returnRoute: WindowRoute | undefined
1027
1649
  try {
1028
1650
  const current = context.ui.router.current()
@@ -1041,8 +1663,32 @@ export async function openPantheonSettings(context: Context): Promise<void> {
1041
1663
  })
1042
1664
  return
1043
1665
  }
1666
+ if (viewMode === 'dialog') {
1667
+ openSettingsDialog(context)
1668
+ return
1669
+ }
1044
1670
  } catch {
1045
- /* router unusable — fall through to the dialog */
1671
+ /* preferences check failed — fall through to docked */
1672
+ }
1673
+
1674
+ // Primary mode: docked in session.composer.top
1675
+ const sessionID = (context as any)?.sessionID ?? routeSessionID(context) ?? activeSessionId()
1676
+ if (!sessionID) {
1677
+ try {
1678
+ context.ui?.toast?.show?.({
1679
+ variant: 'info',
1680
+ title: 'Pantheon',
1681
+ message: 'Open a session first: Pantheon settings opens above the prompt box.',
1682
+ })
1683
+ } catch {}
1684
+ return
1685
+ }
1686
+
1687
+ if (settingsOpen()) {
1688
+ closePantheonSettings()
1689
+ return
1046
1690
  }
1047
- openSettingsDialog(context)
1691
+
1692
+ setSettingsOpen(true)
1693
+ setBlocking(true)
1048
1694
  }