pantheon-opencode 2.0.0-beta.5 → 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 (63) hide show
  1. package/AGENTS.global.md +6 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +67 -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/install/opencode.mjs +13 -1
  17. package/scripts/jev-live-probe.mjs +1 -1
  18. package/scripts/release-gates.mjs +19 -5
  19. package/scripts/skill-search.mjs +66 -7
  20. package/scripts/test-opencode-sandbox.sh +44 -15
  21. package/scripts/update.mjs +9 -2
  22. package/skills-lock.json +5 -3
  23. package/src/agents/aphrodite.md +2 -0
  24. package/src/agents/apollo.md +8 -206
  25. package/src/agents/athena.md +25 -29
  26. package/src/agents/hermes.md +3 -1
  27. package/src/agents/mnemosyne.md +1 -1
  28. package/src/agents/nyx.md +1 -1
  29. package/src/agents/prometheus.md +0 -203
  30. package/src/agents/talos.md +2 -0
  31. package/src/agents/themis.md +8 -3
  32. package/src/agents/zeus.md +18 -12
  33. package/src/instructions/memory-protocol.instructions.md +4 -0
  34. package/src/instructions/test-economy.instructions.md +1 -0
  35. package/src/instructions/zeus-council-synthesis.instructions.md +13 -1
  36. package/src/pantheon/goal-loop-config.ts +55 -0
  37. package/src/pantheon/native-vision.ts +9 -5
  38. package/src/pantheon/pantheon-decision-catalog.ts +8 -0
  39. package/src/pantheon/skill-search-tool.ts +193 -0
  40. package/src/pantheon/tools.ts +2 -0
  41. package/src/pantheon/vision.ts +14 -1
  42. package/src/plugin.ts +39 -7
  43. package/src/plugins/tui/dist/tui.d.ts +12 -2
  44. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  45. package/src/plugins/tui/dist/tui.js +1399 -365
  46. package/src/plugins/tui/dist/tui.js.map +1 -1
  47. package/src/plugins/tui/package-lock.json +2 -2
  48. package/src/plugins/tui/package.json +1 -1
  49. package/src/plugins/tui/src/autonomy-state.ts +149 -0
  50. package/src/plugins/tui/src/context-gauge.ts +64 -5
  51. package/src/plugins/tui/src/decision-router-state.ts +175 -6
  52. package/src/plugins/tui/src/index.tsx +25 -3
  53. package/src/plugins/tui/src/pantheon-settings-state.ts +99 -0
  54. package/src/plugins/tui/src/pantheon-settings.tsx +647 -103
  55. package/src/plugins/tui/src/tui-prefs.ts +161 -9
  56. package/src/plugins/tui/src/update-status.ts +27 -8
  57. package/src/routing.yml +9 -0
  58. package/src/skills/README.md +35 -25
  59. package/src/skills/fast-path-execution/SKILL.md +54 -0
  60. package/src/skills/prompt-refinery/SKILL.md +53 -37
  61. package/src/skills/tdd-with-agents/SKILL.md +22 -10
  62. package/src/skills/test-slicing/SKILL.md +56 -0
  63. package/src/skills/verification-planning/SKILL.md +4 -3
@@ -23,11 +23,21 @@
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 { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
26
+ import { execFile } from 'node:child_process'
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
30
  import { createSignal, For, onCleanup, Show } from 'solid-js'
30
31
  import {
32
+ buildAutonomyTab,
33
+ DEFAULT_DECISION_BUDGETS,
34
+ DEFAULT_GOAL_LOOP_PREFS,
35
+ type DecisionBudgets,
36
+ type GoalLoopPrefs,
37
+ parseUsd,
38
+ } from './autonomy-state.ts'
39
+ import {
40
+ applyDecisionRow,
31
41
  buildDecisionTab,
32
42
  type DecisionConfigRead,
33
43
  readDecisionRouterConfig,
@@ -39,7 +49,9 @@ import { buildJ1Tab } from './j1-gate-status.ts'
39
49
  import {
40
50
  applyDraft,
41
51
  buildAboutTab,
52
+ buildChangelogTab,
42
53
  buildGatesTab,
54
+ type ChangelogHighlightItem,
43
55
  canWriteOverrides,
44
56
  type DraftWriter,
45
57
  type DraftWriterResult,
@@ -55,6 +67,7 @@ import {
55
67
  serializeOverrides,
56
68
  setOverrideState,
57
69
  settledDraft,
70
+ stageDefaults,
58
71
  stageValue,
59
72
  tabDirty,
60
73
  tabRows,
@@ -73,18 +86,41 @@ import { nextCheckState, type UpdateCheckState } from './update-notice.ts'
73
86
  import {
74
87
  buildUpdatesTab,
75
88
  registryUrlForChannel,
89
+ type UpdateChannel,
76
90
  type UpdatesSectionInput,
77
91
  updateChannelFor,
78
92
  } from './update-status.ts'
93
+ import { extractHighlights, readChangelogForBundle } from './whats-new-highlights.ts'
79
94
 
80
95
  export const ROUTE_NAME = 'pantheon-settings'
81
96
 
97
+ /** The input mode the page pushes while mounted (composer layers sleep). */
98
+ export const ROUTE_MODE = 'pantheon-settings'
99
+
82
100
  /** Loose local shape of a host route (the real Route lives in the host typings). */
83
101
  type WindowRoute =
84
102
  | { type: 'home' }
85
103
  | { type: 'session'; sessionID: string }
86
104
  | { type: 'plugin'; name: string; data?: Record<string, unknown> }
87
105
 
106
+ /**
107
+ * Strip a LIVE route object down to the plain shape the route store expects.
108
+ * `router.current()` returns the host's live data (reactive proxies, location
109
+ * objects with cycles) and the host's navigate deep-clones via JSON.stringify
110
+ * — passing the live object through throws "cyclic structures" and the
111
+ * window could never close (field report beta.5, root cause).
112
+ */
113
+ function plainRoute(route: WindowRoute | undefined): WindowRoute {
114
+ if (route === undefined) return { type: 'home' }
115
+ if (route.type === 'session' && 'sessionID' in route && typeof route.sessionID === 'string') {
116
+ return { type: 'session', sessionID: route.sessionID }
117
+ }
118
+ if (route.type === 'plugin' && typeof route.name === 'string') {
119
+ return { type: 'plugin', name: route.name }
120
+ }
121
+ return { type: 'home' }
122
+ }
123
+
88
124
  // ── Shared blocking state (the dispatch panel gates on this) ───────────
89
125
 
90
126
  const [blocking, setBlocking] = createSignal(false)
@@ -133,6 +169,144 @@ function writeOverridesToDisk(load: OverridesLoad): void {
133
169
  writeFileSync(globalOverridesPath(), serializeOverrides(load.global), 'utf8')
134
170
  }
135
171
 
172
+ function userOpenCodeConfigPath(): string {
173
+ const xdgConfig = process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? '', '.config')
174
+ return join(xdgConfig, 'opencode', 'opencode.json')
175
+ }
176
+
177
+ /** Read options.goal_loop from the user's opencode.json (fail-open). */
178
+ function readGoalLoopPrefs(): GoalLoopPrefs {
179
+ const fallback = { ...DEFAULT_GOAL_LOOP_PREFS }
180
+ try {
181
+ const parsed = JSON.parse(readFileSync(userOpenCodeConfigPath(), 'utf8')) as {
182
+ options?: { goal_loop?: Partial<GoalLoopPrefs> }
183
+ }
184
+ const raw = parsed?.options?.goal_loop
185
+ if (raw && typeof raw === 'object') {
186
+ return {
187
+ enabled: typeof raw.enabled === 'boolean' ? raw.enabled : fallback.enabled,
188
+ cooldownMs:
189
+ typeof raw.cooldownMs === 'number' && raw.cooldownMs >= 1000
190
+ ? Math.floor(raw.cooldownMs)
191
+ : fallback.cooldownMs,
192
+ maxContinuations:
193
+ typeof raw.maxContinuations === 'number' && raw.maxContinuations >= 1
194
+ ? Math.min(200, Math.floor(raw.maxContinuations))
195
+ : fallback.maxContinuations,
196
+ }
197
+ }
198
+ } catch {
199
+ /* fail-open */
200
+ }
201
+ return fallback
202
+ }
203
+
204
+ /** Read the decision budgets from decision-router.json's `budget` envelope (fail-open). */
205
+ function readDecisionBudgets(): DecisionBudgets {
206
+ const fallback = { ...DEFAULT_DECISION_BUDGETS }
207
+ try {
208
+ const path = join(
209
+ process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? '', '.config'),
210
+ 'pantheon',
211
+ 'decision-router.json',
212
+ )
213
+ const parsed = JSON.parse(readFileSync(path, 'utf8')) as { budget?: Partial<DecisionBudgets> }
214
+ const raw = parsed?.budget
215
+ if (raw && typeof raw === 'object') {
216
+ return {
217
+ monthlyUsd:
218
+ typeof raw.monthlyUsd === 'number' && raw.monthlyUsd > 0
219
+ ? raw.monthlyUsd
220
+ : fallback.monthlyUsd,
221
+ perDecisionUsd:
222
+ typeof raw.perDecisionUsd === 'number' && raw.perDecisionUsd > 0
223
+ ? raw.perDecisionUsd
224
+ : fallback.perDecisionUsd,
225
+ }
226
+ }
227
+ } catch {
228
+ /* fail-open */
229
+ }
230
+ return fallback
231
+ }
232
+
233
+ /**
234
+ * Surgically set one key under `options` in the user's opencode.json
235
+ * (preserving every other key). Startup-applied options live here — the
236
+ * runtime resolves them once at plugin setup.
237
+ */
238
+ function writeUserOption(key: string, value: unknown): void {
239
+ const path = userOpenCodeConfigPath()
240
+ let doc: Record<string, unknown> = {}
241
+ try {
242
+ const parsed = JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>
243
+ if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) doc = parsed
244
+ } catch {
245
+ /* start a fresh object — nothing parseable to preserve */
246
+ }
247
+ const options =
248
+ typeof doc.options === 'object' && doc.options !== null && !Array.isArray(doc.options)
249
+ ? { ...(doc.options as Record<string, unknown>) }
250
+ : {}
251
+ options[key] = value
252
+ doc.options = options
253
+ writeFileSync(path, `${JSON.stringify(doc, null, 2)}\n`)
254
+ }
255
+
256
+ /** Merge the `budget` envelope into decision-router.json (0600 preserved). */
257
+ function writeDecisionBudget(budgets: { monthlyUsd: number; perDecisionUsd: number }): void {
258
+ const path = join(
259
+ process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? '', '.config'),
260
+ 'pantheon',
261
+ 'decision-router.json',
262
+ )
263
+ let doc: Record<string, unknown> = {}
264
+ try {
265
+ const parsed = JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>
266
+ if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) doc = parsed
267
+ } catch {
268
+ throw new Error('decision-router.json unreadable — repair via `decision-router setup-model`')
269
+ }
270
+ doc.budget = { ...budgets }
271
+ const temp = `${path}.tui.tmp`
272
+ writeFileSync(temp, `${JSON.stringify(doc, null, 2)}\n`, { mode: 0o600 })
273
+ renameSync(temp, path)
274
+ }
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
+
136
310
  function updateCheckStatePath(): string {
137
311
  const stateDir = process.env.XDG_STATE_HOME ?? join(process.env.HOME ?? '', '.local', 'state')
138
312
  return join(stateDir, 'pantheon', 'update-check.json')
@@ -146,9 +320,9 @@ function readUpdateCheckState(): UpdateCheckState {
146
320
  }
147
321
  }
148
322
 
149
- async function fetchLatestForChannel(currentVersion: string): Promise<string | null> {
323
+ async function fetchLatestForChannel(channel: UpdateChannel): Promise<string | null> {
150
324
  try {
151
- const response = await fetch(registryUrlForChannel(updateChannelFor(currentVersion)), {
325
+ const response = await fetch(registryUrlForChannel(channel), {
152
326
  signal: AbortSignal.timeout(5000),
153
327
  })
154
328
  const latest = String(((await response.json()) as { version?: unknown })?.version ?? '')
@@ -172,9 +346,16 @@ function persistUpdateCheckState(previous: UpdateCheckState, latest: string | nu
172
346
  }
173
347
 
174
348
  function resolveRunningVersion(): string {
349
+ // The tsdown embed (same source the sidebar footer uses) is authoritative —
350
+ // the naive ../../package.json read breaks in every real layout (the dev
351
+ // tree and the installed TUI copy both put package.json one level above
352
+ // dist, not two — field report beta.5: the header showed vunknown).
353
+ if (typeof __PANTHEON_VERSION__ !== 'undefined' && __PANTHEON_VERSION__ !== '') {
354
+ return __PANTHEON_VERSION__
355
+ }
175
356
  try {
176
357
  const manifest = JSON.parse(
177
- readFileSync(new URL('../../package.json', import.meta.url), 'utf8'),
358
+ readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
178
359
  ) as { version?: string }
179
360
  return manifest.version ?? 'unknown'
180
361
  } catch {
@@ -184,97 +365,220 @@ function resolveRunningVersion(): string {
184
365
 
185
366
  // ── The window view (presentational; both surfaces render it) ──────────
186
367
 
187
- const NAME_WIDTH = 26
368
+ const NAME_WIDTH = 28
188
369
  const VALUE_WIDTH = 22
189
370
 
190
371
  export function SettingsWindow(props: {
191
372
  version: string
192
373
  tabs: () => SettingsTab[]
193
374
  page: () => number
194
- selected: () => number
375
+ selectedId: () => string | undefined
195
376
  draft: () => SettingsDraft
196
377
  notice: () => string | undefined
378
+ confirmExit?: () => boolean
197
379
  fg?: any
198
380
  muted?: any
199
381
  warn?: any
200
382
  }) {
201
383
  const tab = () => props.tabs()[props.page()] ?? props.tabs()[0] ?? EMPTY_TAB
202
- const rows = () => tabRows(tab())
203
384
  return (
204
385
  <box flexDirection="column" paddingLeft={1} paddingRight={1} paddingTop={1}>
205
- <box flexDirection="row">
386
+ {/* ── Top Header bar: Title + Horizontal Tabs + ESC (matching image.png) ── */}
387
+ <box flexDirection="row" alignItems="center">
206
388
  <text attributes={1} fg={props.fg}>
207
389
  {`Pantheon v${props.version}`}
208
390
  </text>
209
- <For each={props.tabs()}>
210
- {(t, index) => (
211
- <text
212
- fg={index() === props.page() ? props.fg : props.muted}
213
- {...(index() === props.page() ? { attributes: 1 } : {})}
214
- >
215
- {` ${t.title}${tabDirty(props.draft(), t) ? ' ●' : ''}`}
216
- </text>
217
- )}
218
- </For>
219
- <text fg={props.muted}>{' esc'}</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>
220
409
  </box>
221
- <text fg={props.muted}>{'─'.repeat(72)}</text>
222
- <For each={tab().groups}>
223
- {(group) => (
224
- <box flexDirection="column">
225
- <Show when={group.title !== undefined}>
226
- <text attributes={1} fg={props.fg}>
227
- {group.title}
228
- </text>
229
- </Show>
230
- <For each={group.rows}>
231
- {(row: SettingsRow) => {
232
- const isSelected = () => rows()[props.selected()]?.id === row.id
233
- const display = () => props.draft()[row.id] ?? row.value
234
- const staged = () => props.draft()[row.id] !== undefined
235
- const gutter = () => (isSelected() ? '▸ ' : ' ')
236
- const valueCell = () => (row.cycle !== undefined ? `< ${display()} >` : display())
237
- return (
238
- <box flexDirection="row">
239
- <box width={NAME_WIDTH + 2}>
240
- <text fg={props.fg} {...(isSelected() ? { attributes: 1 } : {})}>
241
- {`${gutter()}${row.name}`.padEnd(NAME_WIDTH + 2)}
242
- </text>
243
- </box>
244
- <box width={VALUE_WIDTH}>
245
- <text
246
- fg={isSelected() || staged() ? props.fg : props.muted}
247
- {...(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}
248
466
  >
249
- {`${valueCell()}${staged() ? ' ●' : ''}`.padEnd(VALUE_WIDTH)}
250
- </text>
251
- </box>
252
- <Show when={row.note !== undefined}>
253
- <box flexGrow={1} flexShrink={1}>
254
- <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>
255
494
  </box>
256
- </Show>
257
- </box>
258
- )
259
- }}
260
- </For>
261
- <box height={1} />
262
- </box>
263
- )}
264
- </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) ── */}
265
506
  <Show when={props.notice() !== undefined}>
266
- <text fg={props.warn ?? props.muted}>{`⚠ ${props.notice()}`}</text>
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()}`}
511
+ </text>
267
512
  </Show>
268
- <text fg={draftDirty(props.draft()) ? (props.warn ?? props.fg) : props.muted}>
269
- {draftDirty(props.draft())
270
- ? `● unsaved (${draftCount(props.draft())}) — ctrl+s save · ctrl+r reset page`
271
- : 'no staged changes'}
272
- </text>
273
- <text fg={props.muted}>
274
- {
275
- '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>
276
560
  }
277
- </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>
278
582
  </box>
279
583
  )
280
584
  }
@@ -289,7 +593,11 @@ interface PageApi {
289
593
  jumpTab: (index: number) => void
290
594
  save: () => void
291
595
  resetPage: () => void
596
+ stageDefaults: () => void
292
597
  close: () => void
598
+ discard?: () => void
599
+ cancelExit?: () => void
600
+ confirmExit?: () => boolean
293
601
  }
294
602
 
295
603
  let pageApi: PageApi | undefined
@@ -300,23 +608,49 @@ function createWindowController(
300
608
  ): {
301
609
  tabs: () => SettingsTab[]
302
610
  page: () => number
303
- selected: () => number
611
+ selectedId: () => string | undefined
304
612
  draft: () => SettingsDraft
305
613
  notice: () => string | undefined
614
+ confirmExit: () => boolean
306
615
  api: PageApi
307
616
  cleanup: () => void
308
617
  } {
618
+ const currentVersion = resolveRunningVersion()
309
619
  const [page, setPage] = createSignal(0)
310
620
  const [selected, setSelected] = createSignal(0)
311
621
  const [load, setLoad] = createSignal(readOverridesLoad())
312
622
  const [decision, setDecision] = createSignal<DecisionConfigRead>(readDecisionRouterConfig())
623
+ const [goalLoop, setGoalLoop] = createSignal<GoalLoopPrefs>(readGoalLoopPrefs())
624
+ const [budgets, setBudgets] = createSignal<DecisionBudgets>(readDecisionBudgets())
625
+ const [autonomyRestartPending, setAutonomyRestartPending] = createSignal(false)
313
626
  const [presetTick, setPresetTick] = createSignal(0)
627
+ const [selectedChannel, setSelectedChannel] = createSignal<UpdateChannel>(
628
+ updateChannelFor(currentVersion),
629
+ )
314
630
  const [lastChecked, setLastChecked] = createSignal<string | undefined>(undefined)
315
631
  const [checking, setChecking] = createSignal(false)
632
+ const [updating, setUpdating] = createSignal(false)
633
+ const [changelogItems, setChangelogItems] = createSignal<ChangelogHighlightItem[]>([])
316
634
  const [draft, setDraft] = createSignal<SettingsDraft>({})
317
635
  const [notice, setNotice] = createSignal<string | undefined>(undefined)
636
+ const [confirmExit, setConfirmExit] = createSignal(false)
318
637
 
319
- 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
+ })
320
654
 
321
655
  const presetInput = () => {
322
656
  void presetTick()
@@ -330,7 +664,9 @@ function createWindowController(
330
664
  const input: UpdatesSectionInput = {
331
665
  currentVersion,
332
666
  state: readUpdateCheckState(),
667
+ selectedChannel: selectedChannel(),
333
668
  checking: checking(),
669
+ updating: updating(),
334
670
  nowMs: Date.now(),
335
671
  }
336
672
  const seen = lastChecked()
@@ -340,11 +676,17 @@ function createWindowController(
340
676
 
341
677
  const tabs = (): SettingsTab[] => [
342
678
  buildGatesTab(load()),
343
- buildDecisionTab(decision()),
679
+ buildDecisionTab(decision(), process.env, readAuthProviders(), readConfigProviders()),
344
680
  buildPresetTab(presetInput()),
345
681
  buildTuiTab(tuiPrefs()),
682
+ buildAutonomyTab({
683
+ goalLoop: goalLoop(),
684
+ budgets: budgets(),
685
+ goalLoopRestartPending: autonomyRestartPending(),
686
+ }),
346
687
  buildJ1Tab(process.env, false),
347
688
  buildUpdatesTab(updatesInput()),
689
+ buildChangelogTab(currentVersion, changelogItems()),
348
690
  buildDoctorTab({
349
691
  runningVersion: currentVersion,
350
692
  nodeVersion: process.versions.node,
@@ -356,34 +698,77 @@ function createWindowController(
356
698
  const rows = () => tabRows(tabs()[page()] ?? tabs()[0] ?? EMPTY_TAB)
357
699
 
358
700
  const move = (delta: number) => {
701
+ if (confirmExit()) setConfirmExit(false)
359
702
  const list = rows()
360
703
  if (list.length === 0) return
361
704
  setSelected((current) => Math.min(Math.max(current + delta, 0), list.length - 1))
362
705
  }
363
706
 
364
707
  const step = (direction: 1 | -1) => {
708
+ if (confirmExit()) setConfirmExit(false)
365
709
  const row = rows()[selected()]
366
710
  if (row === undefined) return
367
711
  setNotice(undefined)
368
712
  setDraft(stageValue(draft(), row, direction))
369
713
  }
370
714
 
371
- const checkUpdatesNow = () => {
715
+ const checkUpdatesNow = (targetChannel: UpdateChannel = selectedChannel()) => {
372
716
  if (checking()) return
373
717
  setChecking(true)
374
718
  setNotice(undefined)
375
- void fetchLatestForChannel(currentVersion)
719
+ void fetchLatestForChannel(targetChannel)
376
720
  .then((latest) => {
377
- if (latest) setLastChecked(latest)
378
- persistUpdateCheckState(readUpdateCheckState(), latest)
721
+ if (latest) {
722
+ setLastChecked(latest)
723
+ persistUpdateCheckState(readUpdateCheckState(), latest)
724
+ }
379
725
  })
380
726
  .catch(() => {
381
- /* offline — the row keeps the last known state */
727
+ /* offline */
382
728
  })
383
729
  .finally(() => setChecking(false))
384
730
  }
385
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
+
386
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
+ }
387
772
  if (id.startsWith('gate.')) {
388
773
  if (!canWriteOverrides(load())) {
389
774
  return { ok: false, reason: 'overrides file unreadable — repair with `doctor --fix`' }
@@ -421,6 +806,28 @@ function createWindowController(
421
806
  return { ok: false, reason: 'decision-router disk write failed' }
422
807
  }
423
808
  }
809
+ if (
810
+ id === 'decision.selection.mode' ||
811
+ id === 'decision.selection.target' ||
812
+ id === 'decision.consent'
813
+ ) {
814
+ const current = decision()
815
+ if (current.corrupt) {
816
+ return {
817
+ ok: false,
818
+ reason: 'decision-router.json unreadable — repair via `decision-router setup-model`',
819
+ }
820
+ }
821
+ const staged = applyDecisionRow(current.config, id, value)
822
+ if (staged === current.config) return { ok: false, reason: 'unknown or invalid value' }
823
+ try {
824
+ writeDecisionRouterConfig(staged)
825
+ setDecision({ config: staged, corrupt: false })
826
+ return { ok: true }
827
+ } catch {
828
+ return { ok: false, reason: 'decision-router disk write failed' }
829
+ }
830
+ }
424
831
  if (id === 'preset') {
425
832
  try {
426
833
  if (value === PRESET_NONE) clearActivePreset(globalActivePresetPath())
@@ -434,11 +841,47 @@ function createWindowController(
434
841
  }
435
842
  }
436
843
  }
844
+ if (id.startsWith('autonomy.goal_loop.')) {
845
+ const next = { ...goalLoop() }
846
+ if (id === 'autonomy.goal_loop.enabled') {
847
+ next.enabled = value === 'enabled'
848
+ } else if (id === 'autonomy.goal_loop.maxContinuations') {
849
+ const parsed = Number(value)
850
+ if (!Number.isFinite(parsed) || parsed < 1 || parsed > 200) {
851
+ return { ok: false, reason: 'max continuations must be 1..200' }
852
+ }
853
+ next.maxContinuations = Math.floor(parsed)
854
+ } else if (id === 'autonomy.goal_loop.cooldownMs') {
855
+ const parsed = Number(value)
856
+ if (!Number.isFinite(parsed) || parsed < 1000) {
857
+ return { ok: false, reason: 'cooldown must be >= 1000ms' }
858
+ }
859
+ next.cooldownMs = Math.floor(parsed)
860
+ }
861
+ try {
862
+ writeUserOption('goal_loop', next)
863
+ setGoalLoop(next)
864
+ setAutonomyRestartPending(true)
865
+ return { ok: true }
866
+ } catch {
867
+ return { ok: false, reason: 'opencode.json write failed' }
868
+ }
869
+ }
870
+ if (id === 'autonomy.budget.monthly' || id === 'autonomy.budget.perDecision') {
871
+ const parsed = parseUsd(value)
872
+ if (parsed === null) return { ok: false, reason: 'invalid USD value' }
873
+ const next = { ...budgets() }
874
+ if (id === 'autonomy.budget.monthly') next.monthlyUsd = parsed
875
+ else next.perDecisionUsd = parsed
876
+ try {
877
+ writeDecisionBudget(next)
878
+ setBudgets(next)
879
+ return { ok: true }
880
+ } catch {
881
+ return { ok: false, reason: 'budget write failed' }
882
+ }
883
+ }
437
884
  if (id.startsWith('tui.')) {
438
- // The prefs live in the host's durable reactive store: the mutation is
439
- // async (persist), but the in-memory store flips immediately — the
440
- // sidebar/footer/panel re-render on save, no restart. A persist
441
- // failure surfaces in the notice line when it settles.
442
885
  try {
443
886
  mutateTuiPrefs((prefsDraft) => applyTuiRow(prefsDraft, id, value))
444
887
  .then(() => setNotice(undefined))
@@ -470,50 +913,90 @@ function createWindowController(
470
913
  setNotice(`${failed.map((f) => `${f.id}: ${f.reason}`).join(' · ')} — staged changes kept`)
471
914
  } else {
472
915
  setNotice(`saved ${applied.length} change${applied.length === 1 ? '' : 's'}`)
916
+ if (confirmExit()) {
917
+ exit()
918
+ }
473
919
  }
474
920
  }
475
921
 
476
922
  const resetPage = () => {
923
+ if (confirmExit()) setConfirmExit(false)
477
924
  const tab = tabs()[page()]
478
925
  if (tab === undefined) return
479
926
  setDraft(resetTab(draft(), tab))
480
927
  setNotice(undefined)
481
928
  }
482
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
+
483
938
  const nextTab = () => {
939
+ if (confirmExit()) setConfirmExit(false)
484
940
  setPage((current) => (current + 1) % tabs().length)
485
941
  setSelected(0)
486
942
  }
487
943
 
488
944
  const close = () => {
489
- if (draftDirty(draft())) {
945
+ const staged = draftCount(draft())
946
+ if (staged > 0 && !confirmExit()) {
947
+ setConfirmExit(true)
948
+ return
949
+ }
950
+ if (staged > 0) {
951
+ setDraft({})
490
952
  try {
491
- void Promise.resolve(
492
- context.ui.dialog.confirm({
493
- title: 'Pantheon settings',
494
- message: 'Discard unsaved settings changes?',
495
- }),
496
- ).then((confirmed) => {
497
- if (confirmed === true) exit()
953
+ context.ui.toast?.show?.({
954
+ variant: 'info',
955
+ message: `settings: ${staged} staged change${staged === 1 ? '' : 's'} discarded`,
498
956
  })
499
957
  } catch {
500
- /* confirm unavailable — stay open; the user can ctrl+r first */
958
+ /* toast unavailable */
959
+ }
960
+ }
961
+ exit()
962
+ }
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 */
501
976
  }
502
- return
503
977
  }
504
978
  exit()
505
979
  }
506
980
 
981
+ const cancelExit = () => {
982
+ setConfirmExit(false)
983
+ }
984
+
985
+ const selectedId = () => rows()[selected()]?.id
986
+
507
987
  const api: PageApi = {
508
988
  move,
509
989
  step,
510
990
  actuate: () => {
991
+ if (confirmExit()) setConfirmExit(false)
511
992
  const row = rows()[selected()]
512
993
  if (row?.action === 'update-check') checkUpdatesNow()
994
+ else if (row?.action === 'update-run') runUpdateNow()
513
995
  else step(1)
514
996
  },
515
997
  nextTab,
516
998
  jumpTab: (index) => {
999
+ if (confirmExit()) setConfirmExit(false)
517
1000
  if (index >= 0 && index < tabs().length) {
518
1001
  setPage(index)
519
1002
  setSelected(0)
@@ -521,15 +1004,20 @@ function createWindowController(
521
1004
  },
522
1005
  save,
523
1006
  resetPage,
1007
+ stageDefaults: stageDefaultsPage,
524
1008
  close,
1009
+ discard,
1010
+ cancelExit,
1011
+ confirmExit: () => confirmExit(),
525
1012
  }
526
1013
 
527
1014
  return {
528
1015
  tabs,
529
1016
  page,
530
- selected,
1017
+ selectedId,
531
1018
  draft,
532
1019
  notice,
1020
+ confirmExit: () => confirmExit(),
533
1021
  api,
534
1022
  cleanup: () => {
535
1023
  pageApi = undefined
@@ -548,6 +1036,17 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
548
1036
  )
549
1037
  const theme = context.theme?.text ?? {}
550
1038
  const warn = (theme?.feedback as any)?.warning?.base ?? theme.muted
1039
+ // The page owns the keyboard while mounted: push an input MODE so the
1040
+ // composer's base-mode layers sleep (they eat escape and plain letters —
1041
+ // the host's own menus push a mode for exactly this). The page layer is
1042
+ // scoped to this mode; cleanup pops it.
1043
+ try {
1044
+ const popMode = context.keymap?.mode?.push?.(ROUTE_MODE)
1045
+ if (popMode !== undefined) onCleanup(() => popMode())
1046
+ } catch {
1047
+ /* mode API unavailable — composer layers stay active; keys still fall
1048
+ through to the mode-less fallback layer below */
1049
+ }
551
1050
  onCleanup(controller.cleanup)
552
1051
  setBlocking(true)
553
1052
  pageApi = controller.api
@@ -556,9 +1055,10 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
556
1055
  version={resolveRunningVersion()}
557
1056
  tabs={controller.tabs}
558
1057
  page={controller.page}
559
- selected={controller.selected}
1058
+ selectedId={controller.selectedId}
560
1059
  draft={controller.draft}
561
1060
  notice={controller.notice}
1061
+ confirmExit={controller.confirmExit}
562
1062
  fg={theme.base}
563
1063
  muted={theme.muted}
564
1064
  warn={warn}
@@ -571,7 +1071,7 @@ function navigateBack(context: Context, data?: { returnRoute?: WindowRoute }): v
571
1071
  const fallback: WindowRoute = { type: 'home' }
572
1072
  context.ui.router.navigate(data?.returnRoute ?? fallback)
573
1073
  } catch {
574
- /* router unavailable — nothing to navigate back to */
1074
+ /* router unavailable — the failure is observable only as a stuck page */
575
1075
  }
576
1076
  }
577
1077
 
@@ -612,9 +1112,10 @@ function openSettingsDialog(context: Context): void {
612
1112
  version={resolveRunningVersion()}
613
1113
  tabs={controller.tabs}
614
1114
  page={controller.page}
615
- selected={controller.selected}
1115
+ selectedId={controller.selectedId}
616
1116
  draft={controller.draft}
617
1117
  notice={controller.notice}
1118
+ confirmExit={controller.confirmExit}
618
1119
  fg={theme.base}
619
1120
  muted={theme.muted}
620
1121
  warn={warn}
@@ -654,7 +1155,37 @@ export function setupPantheonSettings(context: Context): void {
654
1155
  title: 'Close settings',
655
1156
  bind: 'escape,q',
656
1157
  run: () => {
657
- pageApi?.close()
1158
+ try {
1159
+ context.ui.toast?.show?.({ variant: 'info', message: 'settings: close command fired' })
1160
+ } catch {}
1161
+ if (pageApi === undefined) {
1162
+ try {
1163
+ context.ui.toast?.show?.({
1164
+ variant: 'warning',
1165
+ message: 'settings: no window controller bound',
1166
+ })
1167
+ } catch {
1168
+ /* toast unavailable */
1169
+ }
1170
+ return undefined
1171
+ }
1172
+ if (pageApi.confirmExit?.()) {
1173
+ pageApi.cancelExit?.()
1174
+ return undefined
1175
+ }
1176
+ pageApi.close()
1177
+ return undefined
1178
+ },
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
+ }
658
1189
  return undefined
659
1190
  },
660
1191
  },
@@ -730,6 +1261,15 @@ export function setupPantheonSettings(context: Context): void {
730
1261
  return undefined
731
1262
  },
732
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
+ },
733
1273
  ...Array.from({ length: 9 }, (_, index) => ({
734
1274
  id: `pantheon.settings.tab.${index + 1}`,
735
1275
  title: `Jump to tab ${index + 1}`,
@@ -740,11 +1280,14 @@ export function setupPantheonSettings(context: Context): void {
740
1280
  },
741
1281
  })),
742
1282
  ]
743
- // The PAGE layer: gated on the route, priority 1 beats any stale
744
- // same-bind layer while the window is open (beta.2 field report).
1283
+ // The PAGE layer: scoped to the mode the page pushes while mounted, so the
1284
+ // composer's base-mode layers sleep and escape/q reach the close command
1285
+ // (field report beta.5: a global layer on a route lost escape/q to the
1286
+ // composer — the host's own menus push a mode for exactly this). The
1287
+ // route gate stays as a belt-and-suspenders against stale modes.
745
1288
  try {
746
1289
  context.keymap.layer(() => ({
747
- mode: 'global' as const,
1290
+ mode: ROUTE_MODE,
748
1291
  priority: 1,
749
1292
  enabled: () => routeGated(),
750
1293
  commands,
@@ -773,9 +1316,10 @@ export async function openPantheonSettings(context: Context): Promise<void> {
773
1316
  let returnRoute: WindowRoute | undefined
774
1317
  try {
775
1318
  const current = context.ui.router.current()
776
- // Never return INTO the settings page itself.
1319
+ // Never return INTO the settings page itself; always pass a PLAIN
1320
+ // route (see plainRoute — live objects are cyclic).
777
1321
  if (!(current.type === 'plugin' && current.name === ROUTE_NAME)) {
778
- returnRoute = current as WindowRoute
1322
+ returnRoute = plainRoute(current as WindowRoute)
779
1323
  }
780
1324
  } catch {
781
1325
  returnRoute = undefined