pantheon-opencode 2.1.6 → 2.2.0-beta.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.
@@ -84,13 +84,16 @@ import {
84
84
  writeActivePreset,
85
85
  writeConfiguredVisionModel,
86
86
  } from './preset-state.ts'
87
+ import { buildQuotaTab } from './quota-state.ts'
87
88
  import { resolveLanguage } from './settings-i18n.ts'
88
89
  import {
89
90
  applyTuiRow,
90
91
  buildTuiTab,
91
92
  clearTuiDraftPreview,
92
93
  mutateTuiPrefs,
94
+ resolveAccentColor,
93
95
  setTuiDraftPreview,
96
+ tuiDraftPreview,
94
97
  tuiPrefs,
95
98
  } from './tui-prefs.ts'
96
99
  import { nextCheckState, type UpdateCheckState } from './update-notice.ts'
@@ -676,7 +679,11 @@ export function SettingsWindow(props: {
676
679
  flexShrink={0}
677
680
  rowGap={1}
678
681
  >
679
- <box backgroundColor="#fba970" flexShrink={0} onMouseDown={() => props.onSave?.()}>
682
+ <box
683
+ backgroundColor={props.warn ?? '#fba970'}
684
+ flexShrink={0}
685
+ onMouseDown={() => props.onSave?.()}
686
+ >
680
687
  <text fg="#000000">{isPt() ? ' Salvar ' : ' Save '}</text>
681
688
  </box>
682
689
  <text fg={props.muted} flexShrink={0}>
@@ -731,7 +738,7 @@ export function SettingsWindow(props: {
731
738
  <text fg={props.warn ?? '#f59e0b'} attributes={1}>
732
739
  {isPt() ? 'Deseja salvar as alterações? ' : 'Keep your changes? '}
733
740
  </text>
734
- <box backgroundColor="#fba970" onMouseDown={() => props.onSave?.()}>
741
+ <box backgroundColor={props.warn ?? '#fba970'} onMouseDown={() => props.onSave?.()}>
735
742
  <text fg="#000000">{isPt() ? ' Salvar ' : ' Save '}</text>
736
743
  </box>
737
744
  <text fg={props.muted}>{' '}</text>
@@ -864,6 +871,7 @@ function createWindowController(
864
871
  buildGatesTab(load(), lang),
865
872
  buildDecisionTab(decision(), process.env, readAuthProviders(), readConfigProviders(), lang),
866
873
  buildPresetTab(presetInput(), lang),
874
+ buildQuotaTab(undefined, lang),
867
875
  buildTuiTab(tuiPrefs(), lang),
868
876
  buildAutonomyTab({
869
877
  goalLoop: goalLoop(),
@@ -1100,6 +1108,9 @@ function createWindowController(
1100
1108
  return { ok: false, reason: 'tui prefs storage unavailable' }
1101
1109
  }
1102
1110
  }
1111
+ if (id.startsWith('quota.')) {
1112
+ return { ok: true }
1113
+ }
1103
1114
  return { ok: false, reason: 'unknown staged row' }
1104
1115
  }
1105
1116
 
@@ -1282,14 +1293,20 @@ function createWindowController(
1282
1293
 
1283
1294
  // ── The router page (the primary surface) ──────────────────────────────
1284
1295
 
1285
- function SettingsPage(props: { context: Context; data: Record<string, any> | undefined }) {
1296
+ function SettingsPage(props: {
1297
+ context: Context
1298
+ data: Record<string, any> | undefined
1299
+ renderSidebar?: (context: Context) => any
1300
+ }) {
1286
1301
  const returnRoute = (props.data as { returnRoute?: WindowRoute } | undefined)?.returnRoute
1287
1302
  const context = props.context
1288
1303
  const controller = createWindowController(context, () =>
1289
1304
  navigateBack(context, returnRoute !== undefined ? { returnRoute } : {}),
1290
1305
  )
1291
1306
  const theme = context.theme?.text ?? {}
1292
- const warn = (theme?.feedback as any)?.warning?.base ?? theme.muted
1307
+ const accent = () =>
1308
+ resolveAccentColor(tuiDraftPreview()?.theme?.accent ?? tuiPrefs().theme?.accent, context.theme)
1309
+ const warn = () => accent()
1293
1310
  // The page owns the keyboard while mounted: push an input MODE so the
1294
1311
  // composer's base-mode layers sleep (they eat escape and plain letters —
1295
1312
  // the host's own menus push a mode for exactly this). The page layer is
@@ -1304,7 +1321,8 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
1304
1321
  onCleanup(controller.cleanup)
1305
1322
  setBlocking(true)
1306
1323
  pageApi = controller.api
1307
- return (
1324
+
1325
+ const window = () => (
1308
1326
  <SettingsWindow
1309
1327
  version={resolveRunningVersion()}
1310
1328
  tabs={controller.tabs}
@@ -1315,7 +1333,7 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
1315
1333
  confirmExit={controller.confirmExit}
1316
1334
  fg={theme.base}
1317
1335
  muted={theme.muted}
1318
- warn={warn}
1336
+ warn={warn()}
1319
1337
  onJumpTab={(idx) => controller.api.jumpTab(idx)}
1320
1338
  onSelectRow={(id) => controller.api.selectById?.(id)}
1321
1339
  onCycleValue={(id, dir) => controller.api.cycleRowById?.(id, dir)}
@@ -1327,6 +1345,27 @@ function SettingsPage(props: { context: Context; data: Record<string, any> | und
1327
1345
  onCancelExit={() => controller.api.cancelExit?.()}
1328
1346
  />
1329
1347
  )
1348
+
1349
+ const sidebar = () => (props.renderSidebar ? props.renderSidebar(context) : null)
1350
+
1351
+ return (
1352
+ <Show when={sidebar()} fallback={window()}>
1353
+ <box flexDirection="row" flexGrow={1} flexBasis={0} minHeight={0} width="100%">
1354
+ <box flexDirection="column" flexGrow={1} flexBasis={0} minHeight={0} minWidth={0}>
1355
+ {window()}
1356
+ </box>
1357
+ <box
1358
+ width={32}
1359
+ flexShrink={0}
1360
+ border
1361
+ borderStyle="single"
1362
+ borderColor={theme.muted ?? '#333333'}
1363
+ >
1364
+ {sidebar()}
1365
+ </box>
1366
+ </box>
1367
+ </Show>
1368
+ )
1330
1369
  }
1331
1370
 
1332
1371
  function navigateBack(context: Context, data?: { returnRoute?: WindowRoute }): void {
@@ -1346,7 +1385,9 @@ let dialogDismiss: () => void = () => {}
1346
1385
  function openSettingsDialog(context: Context): void {
1347
1386
  const controller = createWindowController(context, () => dialogDismiss())
1348
1387
  const theme = context.theme?.text ?? {}
1349
- const warn = (theme?.feedback as any)?.warning?.base ?? theme.muted
1388
+ const accent = () =>
1389
+ resolveAccentColor(tuiDraftPreview()?.theme?.accent ?? tuiPrefs().theme?.accent, context.theme)
1390
+ const warn = () => accent()
1350
1391
  controller.cleanup = () => {
1351
1392
  pageApi = undefined
1352
1393
  setBlocking(false)
@@ -1383,7 +1424,7 @@ function openSettingsDialog(context: Context): void {
1383
1424
  confirmExit={controller.confirmExit}
1384
1425
  fg={theme.base}
1385
1426
  muted={theme.muted}
1386
- warn={warn}
1427
+ warn={warn()}
1387
1428
  isDialog={true}
1388
1429
  maxHeight={maxHeight()}
1389
1430
  onJumpTab={(idx) => controller.api.jumpTab(idx)}
@@ -1399,7 +1440,7 @@ function openSettingsDialog(context: Context): void {
1399
1440
  ),
1400
1441
  close,
1401
1442
  )
1402
- context.ui.dialog.set({ size: 'large' })
1443
+ context.ui.dialog.set({ size: 'medium', centered: true })
1403
1444
  } catch {
1404
1445
  /* dialog stack unavailable — fail-open */
1405
1446
  }
@@ -1515,7 +1556,9 @@ function InSessionSettingsWindow(props: { context: Context; sessionID: string })
1515
1556
  pageApi = controller.api
1516
1557
 
1517
1558
  const theme = (context as any).theme?.text ?? {}
1518
- const warn = (theme?.feedback as any)?.warning?.base ?? '#fba970'
1559
+ const accent = () =>
1560
+ resolveAccentColor(tuiDraftPreview()?.theme?.accent ?? tuiPrefs().theme?.accent, context.theme)
1561
+ const warn = () => accent()
1519
1562
 
1520
1563
  return (
1521
1564
  <SettingsWindow
@@ -1536,7 +1579,7 @@ function InSessionSettingsWindow(props: { context: Context; sessionID: string })
1536
1579
  confirmExit={controller.confirmExit}
1537
1580
  fg={theme.base}
1538
1581
  muted={theme.muted}
1539
- warn={warn}
1582
+ warn={warn()}
1540
1583
  hasKeyboard={hasKeyboard}
1541
1584
  onJumpTab={(idx) => controller.api.jumpTab(idx)}
1542
1585
  onSelectRow={(id) => controller.api.selectById?.(id)}
@@ -1558,11 +1601,19 @@ function InSessionSettingsWindow(props: { context: Context; sessionID: string })
1558
1601
 
1559
1602
  // ── Setup: register once, gate once, priority 1 (anti-theft) ───────────
1560
1603
 
1561
- export function setupPantheonSettings(context: Context): void {
1604
+ let registeredSidebarRenderer: ((context: Context) => any) | undefined
1605
+
1606
+ export function setupPantheonSettings(
1607
+ context: Context,
1608
+ options?: { renderSidebar?: (context: Context) => any },
1609
+ ): void {
1610
+ registeredSidebarRenderer = options?.renderSidebar
1562
1611
  try {
1563
1612
  context.ui.router?.register?.({
1564
1613
  name: ROUTE_NAME,
1565
- render: ({ data }) => <SettingsPage context={context} data={data} />,
1614
+ render: ({ data }) => (
1615
+ <SettingsPage context={context} data={data} renderSidebar={registeredSidebarRenderer} />
1616
+ ),
1566
1617
  })
1567
1618
  routerAvailable = true
1568
1619
  } catch {
@@ -0,0 +1,128 @@
1
+ /**
2
+ * quota-state.ts — the Quotas & Spend tab (inspired by opencode-quota).
3
+ *
4
+ * Exposes live model token spending, daily budgets, rate-limits per provider,
5
+ * and context token telemetry in a dedicated tab in the Pantheon Settings window.
6
+ */
7
+ import type { SettingsTab } from './pantheon-settings-state.ts'
8
+ import { resolveLanguage } from './settings-i18n.ts'
9
+
10
+ export interface QuotaSnapshot {
11
+ todaySpend?: string
12
+ monthSpend?: string
13
+ sessionSpend?: string
14
+ sessionTokens?: string
15
+ cacheHit?: string
16
+ speed?: string
17
+ }
18
+
19
+ export function buildQuotaTab(snapshot?: QuotaSnapshot, languagePref?: string): SettingsTab {
20
+ const isPt = resolveLanguage(languagePref) === 'pt-BR'
21
+
22
+ return {
23
+ id: 'quota',
24
+ title: isPt ? 'Cotas & Gastos' : 'Quotas & Spend',
25
+ groups: [
26
+ {
27
+ title: isPt ? 'Consumo & Gastos de Sessão' : 'Session Spend & Tokens',
28
+ rows: [
29
+ {
30
+ id: 'quota.spend.today',
31
+ name: isPt ? 'Gasto hoje (00h-agora)' : 'Spend today (00h-now)',
32
+ value: snapshot?.todaySpend ?? '$0.00',
33
+ note: isPt ? 'Calculado a partir de opencode.db' : 'Derived from opencode.db ledger',
34
+ },
35
+ {
36
+ id: 'quota.spend.month',
37
+ name: isPt ? 'Gasto acumulado (30d)' : 'Spend last 30 days',
38
+ value: snapshot?.monthSpend ?? '$0.00',
39
+ note: isPt ? 'Janela móvel de 30 dias' : 'Rolling 30-day window',
40
+ },
41
+ {
42
+ id: 'quota.spend.session',
43
+ name: isPt ? 'Gasto na sessão ativa' : 'Active session spend',
44
+ value: snapshot?.sessionSpend ?? '$0.00',
45
+ note: isPt ? 'Custo de todas as mensagens do turno' : 'Sum of turn assistant messages',
46
+ },
47
+ {
48
+ id: 'quota.tokens.context',
49
+ name: isPt ? 'Tokens de contexto' : 'Context tokens',
50
+ value: snapshot?.sessionTokens ?? '19.1k / 1.0M (2%)',
51
+ note: isPt
52
+ ? 'Tokens consumidos vs janela do modelo'
53
+ : 'Tokens used vs model context limit',
54
+ },
55
+ {
56
+ id: 'quota.tokens.cache',
57
+ name: isPt ? 'Eficiência de cache' : 'Prompt cache hit',
58
+ value: snapshot?.cacheHit ?? '97%',
59
+ note: isPt ? 'Desconto de leitura em cache aplicado' : 'Cache read discount applied',
60
+ },
61
+ ],
62
+ },
63
+ {
64
+ title: isPt ? 'Limites & Teto de Orçamento' : 'Rate Limits & Budget Caps',
65
+ rows: [
66
+ {
67
+ id: 'quota.budget.sessionCap',
68
+ name: isPt ? 'Teto por sessão' : 'Session budget cap',
69
+ value: '$5.00',
70
+ cycle: ['$1.00', '$2.00', '$5.00', '$10.00', 'unlimited'],
71
+ note: isPt
72
+ ? 'Avisa ou pausa ao atingir o teto'
73
+ : 'Warns or pauses when session spend reaches cap',
74
+ },
75
+ {
76
+ id: 'quota.budget.alertThreshold',
77
+ name: isPt ? 'Alerta em 80% do teto' : 'Alert at 80% of cap',
78
+ value: 'enabled',
79
+ cycle: ['enabled', 'disabled'],
80
+ note: isPt
81
+ ? 'Emite aviso visual no footer da TUI'
82
+ : 'Shows visual notice in TUI footer',
83
+ },
84
+ {
85
+ id: 'quota.compaction.auto',
86
+ name: isPt ? 'Auto-compactar em 80% do contexto' : 'Auto-compact at 80% context',
87
+ value: 'enabled',
88
+ cycle: ['enabled', 'disabled'],
89
+ note: isPt
90
+ ? 'Aciona compressão automática de histórico'
91
+ : 'Triggers automatic context compaction',
92
+ },
93
+ ],
94
+ },
95
+ {
96
+ title: isPt
97
+ ? 'Provedores & Janelas de Cota (Referência)'
98
+ : 'Providers & Quota Windows (Reference)',
99
+ rows: [
100
+ {
101
+ id: 'quota.ref.anthropic',
102
+ name: 'Anthropic (Claude 3.7)',
103
+ value: 'Tier 4',
104
+ note: isPt
105
+ ? '400k TPM · Reset diário às 00:00 UTC'
106
+ : '400k TPM · Daily reset at 00:00 UTC',
107
+ },
108
+ {
109
+ id: 'quota.ref.openai',
110
+ name: 'OpenAI (GPT-4o)',
111
+ value: 'Tier 4',
112
+ note: isPt
113
+ ? '800k TPM · Reset por janela móvel de 1 min'
114
+ : '800k TPM · 1-minute rolling window',
115
+ },
116
+ {
117
+ id: 'quota.ref.google',
118
+ name: 'Google (Gemini 2.5)',
119
+ value: 'Pay-as-you-go',
120
+ note: isPt
121
+ ? '4M TPM · Alta capacidade com cota flexível'
122
+ : '4M TPM · High capacity with flexible quota',
123
+ },
124
+ ],
125
+ },
126
+ ],
127
+ }
128
+ }
@@ -69,12 +69,24 @@ export function initTuiPrefs(context: Context): void {
69
69
  | undefined
70
70
  if (handle !== undefined) {
71
71
  ;(globalThis as unknown as Record<PropertyKey, unknown>)[PREFS_SYMBOL] = handle
72
- // Self-heal: if store was persisted before layout existed, backfill missing top-level defaults
73
- if (!handle[0]?.layout) {
72
+ // Self-heal: if store was persisted before layout existed or lacks new fields, backfill defaults
73
+ if (
74
+ !handle[0]?.layout ||
75
+ typeof handle[0]?.sidebar?.context?.turnCost !== 'boolean' ||
76
+ typeof handle[0]?.sidebar?.context?.tokenAnatomy !== 'boolean'
77
+ ) {
74
78
  handle[1]((draft: any) => {
75
79
  if (!draft.layout) {
76
80
  draft.layout = { ...DEFAULT_TUI_PREFS.layout }
77
81
  }
82
+ if (draft.sidebar?.context) {
83
+ if (typeof draft.sidebar.context.turnCost !== 'boolean') {
84
+ draft.sidebar.context.turnCost = true
85
+ }
86
+ if (typeof draft.sidebar.context.tokenAnatomy !== 'boolean') {
87
+ draft.sidebar.context.tokenAnatomy = true
88
+ }
89
+ }
78
90
  }).catch(() => {})
79
91
  }
80
92
  }
@@ -119,13 +131,7 @@ export function previewTuiPrefs(base: TuiPrefs, draft?: SettingsDraft): TuiPrefs
119
131
  export function savedTuiPrefs(): TuiPrefs {
120
132
  const s = stash()?.[0]
121
133
  if (!s) return DEFAULT_TUI_PREFS
122
- if (!s.layout) {
123
- return {
124
- ...s,
125
- layout: DEFAULT_TUI_PREFS.layout,
126
- }
127
- }
128
- return s
134
+ return normalizeTuiPrefs(s)
129
135
  }
130
136
 
131
137
  /** The live reactive prefs (read properties inside memos/JSX — tracked).
@@ -149,9 +155,9 @@ export const GAUGE_STYLES: readonly string[] = Object.freeze(['both', 'bar', 'pe
149
155
  export const ENABLED_CYCLE: readonly string[] = Object.freeze(['enabled', 'disabled'])
150
156
 
151
157
  export const BAR_SHAPES_CYCLE: readonly string[] = Object.freeze([
158
+ 'smooth',
152
159
  'line',
153
160
  'block',
154
- 'smooth',
155
161
  'ascii',
156
162
  'dots',
157
163
  'braille',
@@ -185,6 +191,40 @@ export type LanguagePref = 'auto' | 'pt-BR' | 'en'
185
191
 
186
192
  export const LANGUAGE_CYCLE: readonly string[] = Object.freeze(['auto', 'pt-BR', 'en'])
187
193
 
194
+ export type ThemeModePref = 'auto' | 'dark' | 'light'
195
+ export const THEME_MODES_CYCLE: readonly string[] = Object.freeze(['auto', 'dark', 'light'])
196
+
197
+ export type AccentColorPref = 'host' | 'pantheon' | 'emerald' | 'cyan' | 'amber' | 'purple' | 'rose'
198
+ export const ACCENT_COLORS_CYCLE: readonly string[] = Object.freeze([
199
+ 'host',
200
+ 'pantheon',
201
+ 'emerald',
202
+ 'cyan',
203
+ 'amber',
204
+ 'purple',
205
+ 'rose',
206
+ ])
207
+
208
+ export const ACCENT_PALETTE: Record<
209
+ AccentColorPref,
210
+ { primary: string; hover: string; muted: string }
211
+ > = {
212
+ host: { primary: '#fba970', hover: '#fdba74', muted: '#a1a1aa' },
213
+ pantheon: { primary: '#fba970', hover: '#fdba74', muted: '#a1a1aa' },
214
+ emerald: { primary: '#10b981', hover: '#34d399', muted: '#059669' },
215
+ cyan: { primary: '#06b6d4', hover: '#22d3ee', muted: '#0891b2' },
216
+ amber: { primary: '#f59e0b', hover: '#fbbf24', muted: '#d97706' },
217
+ purple: { primary: '#a855f7', hover: '#c084fc', muted: '#9333ea' },
218
+ rose: { primary: '#f43f5e', hover: '#fb7185', muted: '#e11d48' },
219
+ }
220
+
221
+ export function resolveAccentColor(accent: AccentColorPref | undefined, contextTheme: any): string {
222
+ if (!accent || accent === 'host') {
223
+ return contextTheme?.text?.feedback?.warning?.base ?? contextTheme?.text?.base ?? '#fba970'
224
+ }
225
+ return ACCENT_PALETTE[accent]?.primary ?? '#fba970'
226
+ }
227
+
188
228
  export interface TuiPrefs {
189
229
  version: 1
190
230
  layout: {
@@ -193,8 +233,13 @@ export interface TuiPrefs {
193
233
  settingsView?: SettingsViewModePref
194
234
  language?: LanguagePref
195
235
  }
236
+ theme?: {
237
+ mode?: ThemeModePref
238
+ accent?: AccentColorPref
239
+ }
196
240
  sidebar: {
197
241
  header: { version: boolean; preset: boolean; session: boolean }
242
+ pinnedSessions?: string[]
198
243
  blocks: { context: boolean; git: boolean; todo?: boolean; dispatch: boolean }
199
244
  context: {
200
245
  gauge: GaugeStyle
@@ -206,6 +251,8 @@ export interface TuiPrefs {
206
251
  modelUsage: boolean
207
252
  performance: boolean
208
253
  localSpend: boolean
254
+ turnCost: boolean
255
+ tokenAnatomy: boolean
209
256
  }
210
257
  }
211
258
  footer: { prompt: boolean; home: boolean }
@@ -216,15 +263,20 @@ export const DEFAULT_TUI_PREFS: TuiPrefs = {
216
263
  layout: {
217
264
  preset: 'comfortable',
218
265
  separator: 'spaces',
219
- settingsView: 'fullscreen',
266
+ settingsView: 'docked',
220
267
  language: 'auto',
221
268
  },
269
+ theme: {
270
+ mode: 'auto',
271
+ accent: 'host',
272
+ },
222
273
  sidebar: {
223
274
  header: { version: true, preset: true, session: true },
275
+ pinnedSessions: [],
224
276
  blocks: { context: true, git: true, todo: false, dispatch: true },
225
277
  context: {
226
278
  gauge: 'both',
227
- barShape: 'line',
279
+ barShape: 'smooth',
228
280
  barWidth: 'standard',
229
281
  evenMark: false,
230
282
  tokens: true,
@@ -232,6 +284,8 @@ export const DEFAULT_TUI_PREFS: TuiPrefs = {
232
284
  modelUsage: true,
233
285
  performance: true,
234
286
  localSpend: true,
287
+ turnCost: true,
288
+ tokenAnatomy: true,
235
289
  },
236
290
  },
237
291
  footer: { prompt: true, home: true },
@@ -262,6 +316,15 @@ export function normalizeTuiPrefs(raw: unknown): TuiPrefs {
262
316
  const footer = (
263
317
  typeof stored.footer === 'object' && stored.footer !== null ? stored.footer : {}
264
318
  ) as Record<string, any>
319
+ const rawTheme = (
320
+ typeof stored.theme === 'object' && stored.theme !== null ? stored.theme : {}
321
+ ) as Record<string, any>
322
+ const themeMode = THEME_MODES_CYCLE.includes(rawTheme.mode as string)
323
+ ? (rawTheme.mode as ThemeModePref)
324
+ : (DEFAULT_TUI_PREFS.theme?.mode ?? 'auto')
325
+ const themeAccent = ACCENT_COLORS_CYCLE.includes(rawTheme.accent as string)
326
+ ? (rawTheme.accent as AccentColorPref)
327
+ : (DEFAULT_TUI_PREFS.theme?.accent ?? 'host')
265
328
  const preset = LAYOUT_PRESETS_CYCLE.includes(layout.preset as string)
266
329
  ? (layout.preset as LayoutPresetPref)
267
330
  : DEFAULT_TUI_PREFS.layout.preset
@@ -297,12 +360,19 @@ export function normalizeTuiPrefs(raw: unknown): TuiPrefs {
297
360
  settingsView,
298
361
  language,
299
362
  },
363
+ theme: {
364
+ mode: themeMode,
365
+ accent: themeAccent,
366
+ },
300
367
  sidebar: {
301
368
  header: {
302
369
  version: asBool(header.version, true),
303
370
  preset: asBool(header.preset, true),
304
371
  session: asBool(header.session, true),
305
372
  },
373
+ pinnedSessions: Array.isArray(sidebar.pinnedSessions)
374
+ ? sidebar.pinnedSessions.filter((s: unknown) => typeof s === 'string')
375
+ : [],
306
376
  blocks: {
307
377
  context: asBool(blocks.context, true),
308
378
  git: asBool(blocks.git, true),
@@ -319,6 +389,8 @@ export function normalizeTuiPrefs(raw: unknown): TuiPrefs {
319
389
  modelUsage: asBool(context.modelUsage, true),
320
390
  performance: asBool(context.performance, true),
321
391
  localSpend: asBool(context.localSpend, true),
392
+ turnCost: asBool(context.turnCost, true),
393
+ tokenAnatomy: asBool(context.tokenAnatomy, true),
322
394
  },
323
395
  },
324
396
  footer: {
@@ -386,6 +458,29 @@ export function buildTuiTab(prefs: TuiPrefs, languagePref?: string): SettingsTab
386
458
  },
387
459
  ],
388
460
  },
461
+ {
462
+ title: isPt ? 'Cores & Tema' : 'Colors & Theme',
463
+ rows: [
464
+ {
465
+ id: 'tui.theme.mode',
466
+ name: isPt ? 'Modo do tema' : 'Theme mode',
467
+ value: tuiRowValue(prefs, 'tui.theme.mode') ?? 'auto',
468
+ cycle: THEME_MODES_CYCLE,
469
+ note: isPt
470
+ ? 'auto (segue o OpenCode) | dark | light'
471
+ : 'auto (follow OpenCode theme) | dark | light',
472
+ },
473
+ {
474
+ id: 'tui.theme.accent',
475
+ name: isPt ? 'Cor de destaque' : 'Accent color',
476
+ value: tuiRowValue(prefs, 'tui.theme.accent') ?? 'host',
477
+ cycle: ACCENT_COLORS_CYCLE,
478
+ note: isPt
479
+ ? 'host (segue tema) | pantheon | emerald | cyan | amber | purple | rose'
480
+ : 'host (follow theme) | pantheon | emerald | cyan | amber | purple | rose',
481
+ },
482
+ ],
483
+ },
389
484
  {
390
485
  title: isPt ? 'Barras & Medidores' : 'Bars & Gauges',
391
486
  rows: [
@@ -495,6 +590,18 @@ export function buildTuiTab(prefs: TuiPrefs, languagePref?: string): SettingsTab
495
590
  prefs.sidebar.context.performance,
496
591
  isPt ? 'tokens/segundo e latência' : 'cache % + tok/s',
497
592
  ),
593
+ row(
594
+ 'tui.sidebar.context.turnCost',
595
+ isPt ? 'Custo do turno' : 'Turn cost',
596
+ prefs.sidebar.context.turnCost,
597
+ isPt ? 'linha `Turn: $… (prev: $…)`' : 'the `Turn: $… (prev: $…)` line',
598
+ ),
599
+ row(
600
+ 'tui.sidebar.context.tokenAnatomy',
601
+ isPt ? 'Anatomia de tokens' : 'Token anatomy',
602
+ prefs.sidebar.context.tokenAnatomy,
603
+ isPt ? 'linha `↑in ↓out ✦think`' : 'the `↑in ↓out ✦think` line',
604
+ ),
498
605
  row(
499
606
  'tui.sidebar.context.localSpend',
500
607
  isPt ? 'Linha de custo local' : 'Local spend row',
@@ -559,6 +666,18 @@ export function applyTuiRow(draft: TuiPrefs, id: string, value: string): void {
559
666
  draft.layout.language = value as LanguagePref
560
667
  }
561
668
  return
669
+ case 'tui.theme.mode':
670
+ if (THEME_MODES_CYCLE.includes(value)) {
671
+ if (!draft.theme) draft.theme = { ...DEFAULT_TUI_PREFS.theme }
672
+ draft.theme.mode = value as ThemeModePref
673
+ }
674
+ return
675
+ case 'tui.theme.accent':
676
+ if (ACCENT_COLORS_CYCLE.includes(value)) {
677
+ if (!draft.theme) draft.theme = { ...DEFAULT_TUI_PREFS.theme }
678
+ draft.theme.accent = value as AccentColorPref
679
+ }
680
+ return
562
681
  case 'tui.sidebar.context.barShape':
563
682
  if (BAR_SHAPES_CYCLE.includes(value)) draft.sidebar.context.barShape = value as BarShapePref
564
683
  return
@@ -607,6 +726,12 @@ export function applyTuiRow(draft: TuiPrefs, id: string, value: string): void {
607
726
  case 'tui.sidebar.context.localSpend':
608
727
  draft.sidebar.context.localSpend = enabled
609
728
  return
729
+ case 'tui.sidebar.context.turnCost':
730
+ draft.sidebar.context.turnCost = enabled
731
+ return
732
+ case 'tui.sidebar.context.tokenAnatomy':
733
+ draft.sidebar.context.tokenAnatomy = enabled
734
+ return
610
735
  case 'tui.footer.prompt':
611
736
  draft.footer.prompt = enabled
612
737
  return
@@ -626,6 +751,9 @@ export function tuiRowValue(prefs: TuiPrefs, id: string): string | undefined {
626
751
  if (id === 'tui.layout.settingsView')
627
752
  return prefs.layout?.settingsView ?? DEFAULT_TUI_PREFS.layout.settingsView ?? 'docked'
628
753
  if (id === 'tui.layout.language') return prefs.layout?.language ?? 'auto'
754
+ if (id === 'tui.theme.mode') return prefs.theme?.mode ?? DEFAULT_TUI_PREFS.theme?.mode ?? 'auto'
755
+ if (id === 'tui.theme.accent')
756
+ return prefs.theme?.accent ?? DEFAULT_TUI_PREFS.theme?.accent ?? 'host'
629
757
  if (id === 'tui.sidebar.context.barShape') return prefs.sidebar.context.barShape
630
758
  if (id === 'tui.sidebar.context.barWidth') return prefs.sidebar.context.barWidth
631
759
  if (id === 'tui.sidebar.context.gauge') return prefs.sidebar.context.gauge
@@ -667,3 +795,24 @@ export function tuiRowValue(prefs: TuiPrefs, id: string): string | undefined {
667
795
  })()
668
796
  return enabled === undefined ? undefined : enabled ? 'enabled' : 'disabled'
669
797
  }
798
+
799
+ export function isSessionPinned(sessionID: string | undefined): boolean {
800
+ if (!sessionID) return false
801
+ const list = tuiPrefs().sidebar.pinnedSessions
802
+ return Array.isArray(list) && list.includes(sessionID)
803
+ }
804
+
805
+ export function togglePinSession(sessionID: string | undefined): Promise<void> {
806
+ if (!sessionID) return Promise.resolve()
807
+ return mutateTuiPrefs((draft) => {
808
+ if (!Array.isArray(draft.sidebar.pinnedSessions)) {
809
+ draft.sidebar.pinnedSessions = []
810
+ }
811
+ const idx = draft.sidebar.pinnedSessions.indexOf(sessionID)
812
+ if (idx >= 0) {
813
+ draft.sidebar.pinnedSessions.splice(idx, 1)
814
+ } else {
815
+ draft.sidebar.pinnedSessions.push(sessionID)
816
+ }
817
+ })
818
+ }