pantheon-opencode 2.0.0-beta.4 → 2.0.0-beta.5
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.
- package/CHANGELOG.md +17 -68
- package/README.md +18 -5
- package/bin/pantheon-init.mjs +1 -2
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/changelog-format.mjs +345 -0
- package/scripts/changelog-merge.mjs +5 -10
- package/scripts/docs-check-changelog.mjs +36 -137
- package/scripts/install/interactive.mjs +5 -254
- package/scripts/install/opencode.mjs +6 -75
- package/scripts/release-gates.mjs +33 -13
- package/scripts/release-notes.mjs +51 -36
- package/scripts/release-retrofit.mjs +158 -0
- package/scripts/versioning.mjs +1 -1
- package/src/plugins/tui/dist/tui.d.ts +3 -2
- package/src/plugins/tui/dist/tui.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui.js +470 -233
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/index.tsx +86 -29
- package/src/plugins/tui/src/pantheon-settings.tsx +18 -0
- package/src/plugins/tui/src/tui-prefs.ts +378 -0
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
setupPantheonSettings,
|
|
31
31
|
} from './pantheon-settings'
|
|
32
32
|
import { cellWidth, GRAPHEMES, SIDEBAR_CONTENT_WIDTH } from './sidebar-width'
|
|
33
|
+
import { initTuiPrefs, tuiPrefs } from './tui-prefs'
|
|
33
34
|
import { nextCheckState, pickUpdateNotice, type UpdateCheckState } from './update-notice.ts'
|
|
34
35
|
import { maybeShowWhatsNewV2 } from './whats-new'
|
|
35
36
|
|
|
@@ -686,10 +687,12 @@ export type ContextBlockRows = {
|
|
|
686
687
|
* `$<spent> spent`. The percentage row carries the only semantic tone, the
|
|
687
688
|
* gauge bar (12 cells) and is omitted entirely when the percentage is
|
|
688
689
|
* unavailable (never `undefined%`). A block with neither tokens nor cost
|
|
689
|
-
* yields null.
|
|
690
|
+
* yields null. `gaugeStyle` (the TUI tab's pref) picks the percent-row
|
|
691
|
+
* shape: `both` (default), `bar`, `percent`, or `off` (row omitted). Pure. */
|
|
690
692
|
export function contextBlockRows(
|
|
691
693
|
usage: ContextUsage | null,
|
|
692
694
|
cost: number | null | undefined,
|
|
695
|
+
gaugeStyle: 'both' | 'bar' | 'percent' | 'off' = 'both',
|
|
693
696
|
): ContextBlockRows | null {
|
|
694
697
|
const spentValue = formatSpent(cost)
|
|
695
698
|
const spent: ContextRow | null =
|
|
@@ -707,16 +710,30 @@ export function contextBlockRows(
|
|
|
707
710
|
const percentValue = numberOrNull(usage.percent)
|
|
708
711
|
const window = formatContextWindow(usage.limit)
|
|
709
712
|
const bar = contextBar(percentValue)
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
713
|
+
let percent: ContextRow | null = null
|
|
714
|
+
if (gaugeStyle !== 'off' && bar !== null && percentValue !== null) {
|
|
715
|
+
const suffix = window === null ? null : ` of ${window}`
|
|
716
|
+
const tone = contextUsageTone(percentValue)
|
|
717
|
+
if (gaugeStyle === 'bar') {
|
|
718
|
+
percent = { lead: bar.filled, value: '', tail: bar.empty, suffix, tone }
|
|
719
|
+
} else if (gaugeStyle === 'percent') {
|
|
720
|
+
percent = {
|
|
721
|
+
lead: null,
|
|
722
|
+
value: ` ${Math.round(percentValue)}%`,
|
|
723
|
+
tail: null,
|
|
724
|
+
suffix: null,
|
|
725
|
+
tone,
|
|
726
|
+
}
|
|
727
|
+
} else {
|
|
728
|
+
percent = {
|
|
729
|
+
lead: bar.filled,
|
|
730
|
+
value: ` ${Math.round(percentValue)}%`,
|
|
731
|
+
tail: bar.empty,
|
|
732
|
+
suffix,
|
|
733
|
+
tone,
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
720
737
|
|
|
721
738
|
if (tokens === null && percent === null && spent === null) return null
|
|
722
739
|
return { tokens, percent, spent }
|
|
@@ -3792,16 +3809,23 @@ export function createSidebarModel(
|
|
|
3792
3809
|
|
|
3793
3810
|
// Which blocks render, and where a blank line goes. The conditions mirror the
|
|
3794
3811
|
// ones in the view's own `<Show>`s — both read these same memos, so a spacer
|
|
3795
|
-
// can never outlive the block it separates.
|
|
3812
|
+
// can never outlive the block it separates. The TUI tab's prefs gate first
|
|
3813
|
+
// (a disabled block never renders, and the spacer math already tolerates
|
|
3814
|
+
// absence), then the content conditions.
|
|
3796
3815
|
const blocks = createMemo(() => {
|
|
3816
|
+
const prefs = tuiPrefs()
|
|
3797
3817
|
const present: SidebarBlockKey[] = []
|
|
3798
3818
|
// Context also owns the spend line, so the stats totals alone keep it up.
|
|
3799
|
-
if (
|
|
3819
|
+
if (
|
|
3820
|
+
prefs.sidebar.blocks.context &&
|
|
3821
|
+
(contextBlockRows(contextUsage(), cost(), prefs.sidebar.context.gauge) !== null ||
|
|
3822
|
+
(prefs.sidebar.context.localSpend && contextSpendLine(spend()) !== null))
|
|
3823
|
+
) {
|
|
3800
3824
|
present.push('context')
|
|
3801
3825
|
}
|
|
3802
|
-
if (branch() !== null || gitLine() !== null) present.push('git')
|
|
3803
|
-
if (todo().visible.length > 0) present.push('todo')
|
|
3804
|
-
if (dispatch() !== null) present.push('dispatch')
|
|
3826
|
+
if (prefs.sidebar.blocks.git && (branch() !== null || gitLine() !== null)) present.push('git')
|
|
3827
|
+
if (prefs.sidebar.blocks.todo && todo().visible.length > 0) present.push('todo')
|
|
3828
|
+
if (prefs.sidebar.blocks.dispatch && dispatch() !== null) present.push('dispatch')
|
|
3805
3829
|
return withBlockSpacers(present)
|
|
3806
3830
|
})
|
|
3807
3831
|
|
|
@@ -3994,12 +4018,27 @@ function Sidebar(props: SidebarProps): JSX.Element {
|
|
|
3994
4018
|
/* Read the flag live (not through a captured entry) so a block that becomes
|
|
3995
4019
|
* the first one loses its spacer instead of keeping a stale blank line. */
|
|
3996
4020
|
const spacer = (key: SidebarBlockKey) => block(key)?.spacer === true
|
|
3997
|
-
const usageRows = () => modelUsageRows(model.modelUsage().visible)
|
|
3998
4021
|
const usageHidden = () =>
|
|
3999
4022
|
hiddenModelUsageText(model.modelUsage().hidden, model.modelUsage().hiddenCost)
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4023
|
+
// The TUI tab's prefs gate the context rows: gauge style shapes the percent
|
|
4024
|
+
// row; the token/spent lines drop entirely (the prefs live in the reactive
|
|
4025
|
+
// host store, so a flip in /pantheon-settings re-renders here instantly).
|
|
4026
|
+
const contextRows = () => {
|
|
4027
|
+
const prefs = tuiPrefs()
|
|
4028
|
+
const rows = contextBlockRows(model.contextUsage(), model.cost(), prefs.sidebar.context.gauge)
|
|
4029
|
+
if (rows === null) return null
|
|
4030
|
+
return {
|
|
4031
|
+
tokens: prefs.sidebar.context.tokens ? rows.tokens : null,
|
|
4032
|
+
percent: rows.percent,
|
|
4033
|
+
spent: prefs.sidebar.context.spent ? rows.spent : null,
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
const spendLine = () =>
|
|
4037
|
+
tuiPrefs().sidebar.context.localSpend ? contextSpendLine(model.spend()) : null
|
|
4038
|
+
const performanceLine = () =>
|
|
4039
|
+
tuiPrefs().sidebar.context.performance ? contextPerformanceLine(model.performance()) : null
|
|
4040
|
+
const usageRows = () =>
|
|
4041
|
+
tuiPrefs().sidebar.context.modelUsage ? modelUsageRows(model.modelUsage().visible) : []
|
|
4003
4042
|
/* Filled cells and the percent value resolve through the same stage, so the
|
|
4004
4043
|
* bar and its number can never disagree. */
|
|
4005
4044
|
const gaugeFg = (row: ContextRow) => contextProgressColor(row.tone ?? 'warning', context.theme)
|
|
@@ -4010,16 +4049,27 @@ function Sidebar(props: SidebarProps): JSX.Element {
|
|
|
4010
4049
|
}
|
|
4011
4050
|
const failedSuffix = () => failedSuffixText(dispatchView()?.failures)
|
|
4012
4051
|
|
|
4052
|
+
// The fixed header lines are prefs-gated too (TUI tab): version, preset and
|
|
4053
|
+
// session each drop independently; nothing reflows — the column just shortens.
|
|
4054
|
+
const header = () => tuiPrefs().sidebar.header
|
|
4013
4055
|
return (
|
|
4014
4056
|
<box flexDirection="column" width="100%" padding={1}>
|
|
4015
|
-
<
|
|
4057
|
+
<Show when={header().version}>
|
|
4058
|
+
<text fg={text()} attributes={1}>{`Pantheon v${__PANTHEON_VERSION__}`}</text>
|
|
4059
|
+
</Show>
|
|
4016
4060
|
{/* Preset plus the provider of the model in use — both derived from host
|
|
4017
4061
|
state. The provider is dropped when nothing resolves, so the row is
|
|
4018
4062
|
never a placeholder. */}
|
|
4019
|
-
<
|
|
4063
|
+
<Show when={header().preset}>
|
|
4064
|
+
<text fg={muted()}>{presetHeaderLine(model.preset().name ?? '', model.provider())}</text>
|
|
4065
|
+
</Show>
|
|
4020
4066
|
<Show
|
|
4021
|
-
when={model.activeSessionID() !== '' && model.session()}
|
|
4022
|
-
fallback={
|
|
4067
|
+
when={header().session && model.activeSessionID() !== '' && model.session()}
|
|
4068
|
+
fallback={
|
|
4069
|
+
<Show when={header().session} fallback={<box height={0} />}>
|
|
4070
|
+
<text fg={muted()}>{sidebarPlaceholder(props.sessionID)}</text>
|
|
4071
|
+
</Show>
|
|
4072
|
+
}
|
|
4023
4073
|
>
|
|
4024
4074
|
{(current: any) => (
|
|
4025
4075
|
<text fg={text()}>{`Sessão: ${truncateLabel(current().title || current().id)}`}</text>
|
|
@@ -4060,7 +4110,7 @@ function Sidebar(props: SidebarProps): JSX.Element {
|
|
|
4060
4110
|
numbers right-aligned; the gauge above remains the block's
|
|
4061
4111
|
single accent. When no message carries cost this loop is empty
|
|
4062
4112
|
and the block keeps its original token/spend rows. */}
|
|
4063
|
-
<Show when={usageRows().length > 0}>
|
|
4113
|
+
<Show when={tuiPrefs().sidebar.context.modelUsage && usageRows().length > 0}>
|
|
4064
4114
|
<text fg={muted()}>Sessão · custo reportado</text>
|
|
4065
4115
|
<text fg={muted()}>
|
|
4066
4116
|
{'Modelo'.padEnd(MODEL_USAGE_MODEL_WIDTH) +
|
|
@@ -4432,9 +4482,11 @@ function HomeStatus(props: { context: any }) {
|
|
|
4432
4482
|
const preset = useActivePreset(props.context).preset
|
|
4433
4483
|
const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base
|
|
4434
4484
|
return (
|
|
4435
|
-
<
|
|
4436
|
-
|
|
4437
|
-
|
|
4485
|
+
<Show when={tuiPrefs().footer.home}>
|
|
4486
|
+
<text
|
|
4487
|
+
fg={muted()}
|
|
4488
|
+
>{`Pantheon v${__PANTHEON_VERSION__}${preset().name ? ` ${PRESET_MARKER} ${preset().name}` : ''}`}</text>
|
|
4489
|
+
</Show>
|
|
4438
4490
|
)
|
|
4439
4491
|
}
|
|
4440
4492
|
|
|
@@ -4495,7 +4547,7 @@ function PromptFooter(props: { context: any; sessionID?: string | undefined }) {
|
|
|
4495
4547
|
const model = createFooterModel(props.context, () => props.sessionID)
|
|
4496
4548
|
const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base
|
|
4497
4549
|
return (
|
|
4498
|
-
<Show when={model.running() > 0}>
|
|
4550
|
+
<Show when={tuiPrefs().footer.prompt && model.running() > 0}>
|
|
4499
4551
|
<text fg={muted()}>
|
|
4500
4552
|
{`${PRESET_MARKER}${model.preset().name ?? 'default'} · ✦${model.running()} ativos`}
|
|
4501
4553
|
</text>
|
|
@@ -4512,6 +4564,11 @@ const plugin = Plugin.define({
|
|
|
4512
4564
|
if (globalState[SINGLETON]) return
|
|
4513
4565
|
globalState[SINGLETON] = true
|
|
4514
4566
|
|
|
4567
|
+
// The durable TUI prefs store — created before any consumer (sidebar,
|
|
4568
|
+
// footers, dispatch panel, settings) reads it, so their first reactive
|
|
4569
|
+
// read hits the live store instead of the defaults.
|
|
4570
|
+
initTuiPrefs(context)
|
|
4571
|
+
|
|
4515
4572
|
const location = resolveLocation(context)
|
|
4516
4573
|
// Eager load/sync at setup so the cache is warm before the slot's first
|
|
4517
4574
|
// render (Known Issue: empty sidebar before the first prompt).
|
|
@@ -68,6 +68,7 @@ import {
|
|
|
68
68
|
readActivePresetMarker,
|
|
69
69
|
writeActivePreset,
|
|
70
70
|
} from './preset-state.ts'
|
|
71
|
+
import { applyTuiRow, buildTuiTab, mutateTuiPrefs, tuiPrefs } from './tui-prefs.ts'
|
|
71
72
|
import { nextCheckState, type UpdateCheckState } from './update-notice.ts'
|
|
72
73
|
import {
|
|
73
74
|
buildUpdatesTab,
|
|
@@ -341,6 +342,7 @@ function createWindowController(
|
|
|
341
342
|
buildGatesTab(load()),
|
|
342
343
|
buildDecisionTab(decision()),
|
|
343
344
|
buildPresetTab(presetInput()),
|
|
345
|
+
buildTuiTab(tuiPrefs()),
|
|
344
346
|
buildJ1Tab(process.env, false),
|
|
345
347
|
buildUpdatesTab(updatesInput()),
|
|
346
348
|
buildDoctorTab({
|
|
@@ -432,6 +434,22 @@ function createWindowController(
|
|
|
432
434
|
}
|
|
433
435
|
}
|
|
434
436
|
}
|
|
437
|
+
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
|
+
try {
|
|
443
|
+
mutateTuiPrefs((prefsDraft) => applyTuiRow(prefsDraft, id, value))
|
|
444
|
+
.then(() => setNotice(undefined))
|
|
445
|
+
.catch(() =>
|
|
446
|
+
setNotice('tui prefs: persist failed — the change is active for this session only'),
|
|
447
|
+
)
|
|
448
|
+
return { ok: true }
|
|
449
|
+
} catch {
|
|
450
|
+
return { ok: false, reason: 'tui prefs storage unavailable' }
|
|
451
|
+
}
|
|
452
|
+
}
|
|
435
453
|
return { ok: false, reason: 'unknown staged row' }
|
|
436
454
|
}
|
|
437
455
|
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: stored prefs are host JSON of a known shape.
|
|
2
|
+
/**
|
|
3
|
+
* tui-prefs.ts — the TUI personalization core (the settings window's TUI tab).
|
|
4
|
+
*
|
|
5
|
+
* TUI-local copy doctrine (same as cost-data.ts): the bundle must stay
|
|
6
|
+
* self-contained. Persistence is the HOST's durable plugin storage
|
|
7
|
+
* (`context.storage.store('tui-prefs', { initial })` — reactive solid store,
|
|
8
|
+
* live-synced across TUI instances); this module owns the SHAPE and the pure
|
|
9
|
+
* operations, never the store handle.
|
|
10
|
+
*
|
|
11
|
+
* v1 surfaces: sidebar fixed headers, sidebar blocks, the Context block's
|
|
12
|
+
* sub-lines and gauge style, and the two Pantheon footer lines. Everything
|
|
13
|
+
* defaults to on — the window exists to turn things OFF.
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from '@opencode/plugin/tui/context'
|
|
16
|
+
import type { SettingsRow, SettingsTab } from './pantheon-settings-state.ts'
|
|
17
|
+
|
|
18
|
+
// ── The durable store handle (host storage, one per plugin) ────────────
|
|
19
|
+
// Created once at setup and stashed under a globalThis symbol so
|
|
20
|
+
// hot-reload generations keep sharing the same live store (the same
|
|
21
|
+
// singleton doctrine as the plugin's SINGLETON guard).
|
|
22
|
+
|
|
23
|
+
const PREFS_SYMBOL = Symbol.for('pantheon.tui.prefs.v1')
|
|
24
|
+
type PrefsStore = readonly [TuiPrefs, (mutation: (draft: TuiPrefs) => void) => Promise<void>]
|
|
25
|
+
|
|
26
|
+
function stash(): PrefsStore | undefined {
|
|
27
|
+
return (globalThis as Record<PropertyKey, unknown>)[PREFS_SYMBOL] as PrefsStore | undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Create (or reuse) the durable prefs store. Fail-open: without host
|
|
31
|
+
* storage the consumers fall back to DEFAULT_TUI_PREFS (read-only). */
|
|
32
|
+
export function initTuiPrefs(context: Context): void {
|
|
33
|
+
if (stash() !== undefined) return
|
|
34
|
+
try {
|
|
35
|
+
const handle = context.storage?.store?.('tui-prefs', { initial: DEFAULT_TUI_PREFS }) as
|
|
36
|
+
| PrefsStore
|
|
37
|
+
| undefined
|
|
38
|
+
if (handle !== undefined) {
|
|
39
|
+
;(globalThis as unknown as Record<PropertyKey, unknown>)[PREFS_SYMBOL] = handle
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
/* no host storage — defaults stay read-only */
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The live reactive prefs (read properties inside memos/JSX — tracked). */
|
|
47
|
+
export function tuiPrefs(): TuiPrefs {
|
|
48
|
+
return stash()?.[0] ?? DEFAULT_TUI_PREFS
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Stage a mutation against the durable store; resolves when persisted. */
|
|
52
|
+
export function mutateTuiPrefs(mutation: (draft: TuiPrefs) => void): Promise<void> {
|
|
53
|
+
const handle = stash()
|
|
54
|
+
if (handle === undefined) return Promise.resolve()
|
|
55
|
+
return handle[1](mutation)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const GAUGE_STYLES: readonly string[] = Object.freeze(['both', 'bar', 'percent', 'off'])
|
|
59
|
+
export const ENABLED_CYCLE: readonly string[] = Object.freeze(['enabled', 'disabled'])
|
|
60
|
+
|
|
61
|
+
export type GaugeStyle = 'both' | 'bar' | 'percent' | 'off'
|
|
62
|
+
|
|
63
|
+
export interface TuiPrefs {
|
|
64
|
+
version: 1
|
|
65
|
+
sidebar: {
|
|
66
|
+
header: { version: boolean; preset: boolean; session: boolean }
|
|
67
|
+
blocks: { context: boolean; git: boolean; todo: boolean; dispatch: boolean }
|
|
68
|
+
context: {
|
|
69
|
+
gauge: GaugeStyle
|
|
70
|
+
tokens: boolean
|
|
71
|
+
spent: boolean
|
|
72
|
+
modelUsage: boolean
|
|
73
|
+
performance: boolean
|
|
74
|
+
localSpend: boolean
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
footer: { prompt: boolean; home: boolean }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const DEFAULT_TUI_PREFS: TuiPrefs = {
|
|
81
|
+
version: 1,
|
|
82
|
+
sidebar: {
|
|
83
|
+
header: { version: true, preset: true, session: true },
|
|
84
|
+
blocks: { context: true, git: true, todo: true, dispatch: true },
|
|
85
|
+
context: {
|
|
86
|
+
gauge: 'both',
|
|
87
|
+
tokens: true,
|
|
88
|
+
spent: true,
|
|
89
|
+
modelUsage: true,
|
|
90
|
+
performance: true,
|
|
91
|
+
localSpend: true,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
footer: { prompt: true, home: true },
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function asBool(value: unknown, fallback: boolean): boolean {
|
|
98
|
+
return typeof value === 'boolean' ? value : fallback
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Deep-merge stored JSON over the defaults; unknown keys and junk are ignored. */
|
|
102
|
+
export function normalizeTuiPrefs(raw: unknown): TuiPrefs {
|
|
103
|
+
const stored = (typeof raw === 'object' && raw !== null ? raw : {}) as Record<string, any>
|
|
104
|
+
const sidebar = (
|
|
105
|
+
typeof stored.sidebar === 'object' && stored.sidebar !== null ? stored.sidebar : {}
|
|
106
|
+
) as Record<string, any>
|
|
107
|
+
const header = (
|
|
108
|
+
typeof sidebar.header === 'object' && sidebar.header !== null ? sidebar.header : {}
|
|
109
|
+
) as Record<string, any>
|
|
110
|
+
const blocks = (
|
|
111
|
+
typeof sidebar.blocks === 'object' && sidebar.blocks !== null ? sidebar.blocks : {}
|
|
112
|
+
) as Record<string, any>
|
|
113
|
+
const context = (
|
|
114
|
+
typeof sidebar.context === 'object' && sidebar.context !== null ? sidebar.context : {}
|
|
115
|
+
) as Record<string, any>
|
|
116
|
+
const footer = (
|
|
117
|
+
typeof stored.footer === 'object' && stored.footer !== null ? stored.footer : {}
|
|
118
|
+
) as Record<string, any>
|
|
119
|
+
const gauge = GAUGE_STYLES.includes(context.gauge as string)
|
|
120
|
+
? (context.gauge as GaugeStyle)
|
|
121
|
+
: DEFAULT_TUI_PREFS.sidebar.context.gauge
|
|
122
|
+
return {
|
|
123
|
+
version: 1,
|
|
124
|
+
sidebar: {
|
|
125
|
+
header: {
|
|
126
|
+
version: asBool(header.version, true),
|
|
127
|
+
preset: asBool(header.preset, true),
|
|
128
|
+
session: asBool(header.session, true),
|
|
129
|
+
},
|
|
130
|
+
blocks: {
|
|
131
|
+
context: asBool(blocks.context, true),
|
|
132
|
+
git: asBool(blocks.git, true),
|
|
133
|
+
todo: asBool(blocks.todo, true),
|
|
134
|
+
dispatch: asBool(blocks.dispatch, true),
|
|
135
|
+
},
|
|
136
|
+
context: {
|
|
137
|
+
gauge,
|
|
138
|
+
tokens: asBool(context.tokens, true),
|
|
139
|
+
spent: asBool(context.spent, true),
|
|
140
|
+
modelUsage: asBool(context.modelUsage, true),
|
|
141
|
+
performance: asBool(context.performance, true),
|
|
142
|
+
localSpend: asBool(context.localSpend, true),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
footer: {
|
|
146
|
+
prompt: asBool(footer.prompt, true),
|
|
147
|
+
home: asBool(footer.home, true),
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ── The TUI tab (cycler rows over the dotted pref paths) ───────────────
|
|
153
|
+
|
|
154
|
+
const onOff = ENABLED_CYCLE
|
|
155
|
+
const row = (id: string, name: string, value: boolean, note: string): SettingsRow => ({
|
|
156
|
+
id,
|
|
157
|
+
name,
|
|
158
|
+
value: value ? 'enabled' : 'disabled',
|
|
159
|
+
cycle: onOff,
|
|
160
|
+
note,
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
export function buildTuiTab(prefs: TuiPrefs): SettingsTab {
|
|
164
|
+
return {
|
|
165
|
+
id: 'tui',
|
|
166
|
+
title: 'TUI',
|
|
167
|
+
groups: [
|
|
168
|
+
{
|
|
169
|
+
title: 'Sidebar header',
|
|
170
|
+
rows: [
|
|
171
|
+
row(
|
|
172
|
+
'tui.sidebar.header.version',
|
|
173
|
+
'Version line',
|
|
174
|
+
prefs.sidebar.header.version,
|
|
175
|
+
'the `Pantheon v…` line',
|
|
176
|
+
),
|
|
177
|
+
row(
|
|
178
|
+
'tui.sidebar.header.preset',
|
|
179
|
+
'Preset line',
|
|
180
|
+
prefs.sidebar.header.preset,
|
|
181
|
+
'the `▸ preset · provider` line',
|
|
182
|
+
),
|
|
183
|
+
row(
|
|
184
|
+
'tui.sidebar.header.session',
|
|
185
|
+
'Session line',
|
|
186
|
+
prefs.sidebar.header.session,
|
|
187
|
+
'the active session title',
|
|
188
|
+
),
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
title: 'Sidebar blocks',
|
|
193
|
+
rows: [
|
|
194
|
+
row(
|
|
195
|
+
'tui.sidebar.block.context',
|
|
196
|
+
'Context block',
|
|
197
|
+
prefs.sidebar.blocks.context,
|
|
198
|
+
'tokens, gauge, spend, model usage',
|
|
199
|
+
),
|
|
200
|
+
row(
|
|
201
|
+
'tui.sidebar.block.git',
|
|
202
|
+
'Git block',
|
|
203
|
+
prefs.sidebar.blocks.git,
|
|
204
|
+
'branch + working-tree counts',
|
|
205
|
+
),
|
|
206
|
+
row(
|
|
207
|
+
'tui.sidebar.block.todo',
|
|
208
|
+
'Todo block',
|
|
209
|
+
prefs.sidebar.blocks.todo,
|
|
210
|
+
'the newest todowrite',
|
|
211
|
+
),
|
|
212
|
+
row(
|
|
213
|
+
'tui.sidebar.block.dispatch',
|
|
214
|
+
'Dispatch block',
|
|
215
|
+
prefs.sidebar.blocks.dispatch,
|
|
216
|
+
'live delegations + rollup',
|
|
217
|
+
),
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
title: 'Context block detail',
|
|
222
|
+
rows: [
|
|
223
|
+
{
|
|
224
|
+
id: 'tui.sidebar.context.gauge',
|
|
225
|
+
name: 'Gauge style',
|
|
226
|
+
value: prefs.sidebar.context.gauge,
|
|
227
|
+
cycle: GAUGE_STYLES,
|
|
228
|
+
note: 'both | bar | percent | off — `▰▱ 42% of 200k`',
|
|
229
|
+
},
|
|
230
|
+
row(
|
|
231
|
+
'tui.sidebar.context.tokens',
|
|
232
|
+
'Tokens row',
|
|
233
|
+
prefs.sidebar.context.tokens,
|
|
234
|
+
'the raw token count line',
|
|
235
|
+
),
|
|
236
|
+
row(
|
|
237
|
+
'tui.sidebar.context.spent',
|
|
238
|
+
'Spent row',
|
|
239
|
+
prefs.sidebar.context.spent,
|
|
240
|
+
'the `$… gasto na sessão` line',
|
|
241
|
+
),
|
|
242
|
+
row(
|
|
243
|
+
'tui.sidebar.context.modelUsage',
|
|
244
|
+
'Model usage table',
|
|
245
|
+
prefs.sidebar.context.modelUsage,
|
|
246
|
+
'per-model tokens/USD',
|
|
247
|
+
),
|
|
248
|
+
row(
|
|
249
|
+
'tui.sidebar.context.performance',
|
|
250
|
+
'Performance line',
|
|
251
|
+
prefs.sidebar.context.performance,
|
|
252
|
+
'cache % + tok/s',
|
|
253
|
+
),
|
|
254
|
+
row(
|
|
255
|
+
'tui.sidebar.context.localSpend',
|
|
256
|
+
'Local spend',
|
|
257
|
+
prefs.sidebar.context.localSpend,
|
|
258
|
+
'hoje / 30d totals',
|
|
259
|
+
),
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
title: 'Footers',
|
|
264
|
+
rows: [
|
|
265
|
+
row(
|
|
266
|
+
'tui.footer.prompt',
|
|
267
|
+
'Prompt footer',
|
|
268
|
+
prefs.footer.prompt,
|
|
269
|
+
'the `▸preset · ✦n ativos` line while delegations run',
|
|
270
|
+
),
|
|
271
|
+
row(
|
|
272
|
+
'tui.footer.home',
|
|
273
|
+
'Home status',
|
|
274
|
+
prefs.footer.home,
|
|
275
|
+
'the `Pantheon v…` line under the home prompt',
|
|
276
|
+
),
|
|
277
|
+
],
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Apply one staged row INTO a prefs draft (in place — the storage mutate
|
|
285
|
+
* callback hands an immer-style draft). Unknown ids or junk values are no-ops.
|
|
286
|
+
*/
|
|
287
|
+
export function applyTuiRow(draft: TuiPrefs, id: string, value: string): void {
|
|
288
|
+
const enabled = value === 'enabled'
|
|
289
|
+
switch (id) {
|
|
290
|
+
case 'tui.sidebar.header.version':
|
|
291
|
+
draft.sidebar.header.version = enabled
|
|
292
|
+
return
|
|
293
|
+
case 'tui.sidebar.header.preset':
|
|
294
|
+
draft.sidebar.header.preset = enabled
|
|
295
|
+
return
|
|
296
|
+
case 'tui.sidebar.header.session':
|
|
297
|
+
draft.sidebar.header.session = enabled
|
|
298
|
+
return
|
|
299
|
+
case 'tui.sidebar.block.context':
|
|
300
|
+
draft.sidebar.blocks.context = enabled
|
|
301
|
+
return
|
|
302
|
+
case 'tui.sidebar.block.git':
|
|
303
|
+
draft.sidebar.blocks.git = enabled
|
|
304
|
+
return
|
|
305
|
+
case 'tui.sidebar.block.todo':
|
|
306
|
+
draft.sidebar.blocks.todo = enabled
|
|
307
|
+
return
|
|
308
|
+
case 'tui.sidebar.block.dispatch':
|
|
309
|
+
draft.sidebar.blocks.dispatch = enabled
|
|
310
|
+
return
|
|
311
|
+
case 'tui.sidebar.context.gauge':
|
|
312
|
+
if (GAUGE_STYLES.includes(value)) draft.sidebar.context.gauge = value as GaugeStyle
|
|
313
|
+
return
|
|
314
|
+
case 'tui.sidebar.context.tokens':
|
|
315
|
+
draft.sidebar.context.tokens = enabled
|
|
316
|
+
return
|
|
317
|
+
case 'tui.sidebar.context.spent':
|
|
318
|
+
draft.sidebar.context.spent = enabled
|
|
319
|
+
return
|
|
320
|
+
case 'tui.sidebar.context.modelUsage':
|
|
321
|
+
draft.sidebar.context.modelUsage = enabled
|
|
322
|
+
return
|
|
323
|
+
case 'tui.sidebar.context.performance':
|
|
324
|
+
draft.sidebar.context.performance = enabled
|
|
325
|
+
return
|
|
326
|
+
case 'tui.sidebar.context.localSpend':
|
|
327
|
+
draft.sidebar.context.localSpend = enabled
|
|
328
|
+
return
|
|
329
|
+
case 'tui.footer.prompt':
|
|
330
|
+
draft.footer.prompt = enabled
|
|
331
|
+
return
|
|
332
|
+
case 'tui.footer.home':
|
|
333
|
+
draft.footer.home = enabled
|
|
334
|
+
return
|
|
335
|
+
default:
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Read the current pref value for a row id ('enabled'/'disabled'/gauge). */
|
|
341
|
+
export function tuiRowValue(prefs: TuiPrefs, id: string): string | undefined {
|
|
342
|
+
if (id === 'tui.sidebar.context.gauge') return prefs.sidebar.context.gauge
|
|
343
|
+
const enabled = (() => {
|
|
344
|
+
switch (id) {
|
|
345
|
+
case 'tui.sidebar.header.version':
|
|
346
|
+
return prefs.sidebar.header.version
|
|
347
|
+
case 'tui.sidebar.header.preset':
|
|
348
|
+
return prefs.sidebar.header.preset
|
|
349
|
+
case 'tui.sidebar.header.session':
|
|
350
|
+
return prefs.sidebar.header.session
|
|
351
|
+
case 'tui.sidebar.block.context':
|
|
352
|
+
return prefs.sidebar.blocks.context
|
|
353
|
+
case 'tui.sidebar.block.git':
|
|
354
|
+
return prefs.sidebar.blocks.git
|
|
355
|
+
case 'tui.sidebar.block.todo':
|
|
356
|
+
return prefs.sidebar.blocks.todo
|
|
357
|
+
case 'tui.sidebar.block.dispatch':
|
|
358
|
+
return prefs.sidebar.blocks.dispatch
|
|
359
|
+
case 'tui.sidebar.context.tokens':
|
|
360
|
+
return prefs.sidebar.context.tokens
|
|
361
|
+
case 'tui.sidebar.context.spent':
|
|
362
|
+
return prefs.sidebar.context.spent
|
|
363
|
+
case 'tui.sidebar.context.modelUsage':
|
|
364
|
+
return prefs.sidebar.context.modelUsage
|
|
365
|
+
case 'tui.sidebar.context.performance':
|
|
366
|
+
return prefs.sidebar.context.performance
|
|
367
|
+
case 'tui.sidebar.context.localSpend':
|
|
368
|
+
return prefs.sidebar.context.localSpend
|
|
369
|
+
case 'tui.footer.prompt':
|
|
370
|
+
return prefs.footer.prompt
|
|
371
|
+
case 'tui.footer.home':
|
|
372
|
+
return prefs.footer.home
|
|
373
|
+
default:
|
|
374
|
+
return undefined
|
|
375
|
+
}
|
|
376
|
+
})()
|
|
377
|
+
return enabled === undefined ? undefined : enabled ? 'enabled' : 'disabled'
|
|
378
|
+
}
|