Default is back to 'on' (inline, above the input) — bottom was too far from the input and felt disconnected. Users who want it pinned can opt in explicitly. - UiState.statusBar: boolean → 'on' | 'off' | 'bottom' | 'top' - /statusbar [on|off|bottom|top|toggle]; no-arg still binary-toggles between off and on (preserves muscle memory) - appLayout renders StatusRulePane in three slots (inline inside ComposerPane for 'on', above transcript row for 'top', after ComposerPane for 'bottom'); only the slot matching ui.statusBar actually mounts - drop the input's marginBottom when 'bottom' so the rule sits tight against the input instead of floating a row below - useConfigSync.normalizeStatusBar coerces legacy bool (true→on, false→off) and unknown shapes to 'on' for forward-compat reads - tui_gateway: split compact from statusbar config handlers; persist string enum with _coerce_statusbar helper for legacy bool configs
114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
|
|
import { resolveDetailsMode } from '../domain/details.js'
|
|
import type { GatewayClient } from '../gatewayClient.js'
|
|
import type {
|
|
ConfigFullResponse,
|
|
ConfigMtimeResponse,
|
|
ReloadMcpResponse,
|
|
VoiceToggleResponse
|
|
} from '../gatewayTypes.js'
|
|
import { asRpcResult } from '../lib/rpc.js'
|
|
|
|
import type { StatusBarMode } from './interfaces.js'
|
|
import { turnController } from './turnController.js'
|
|
import { patchUiState } from './uiStore.js'
|
|
|
|
const STATUSBAR_MODES = new Set<StatusBarMode>(['bottom', 'off', 'on', 'top'])
|
|
|
|
// Legacy configs stored tui_statusbar as a bool; new configs write a string
|
|
// ('on' | 'off' | 'bottom' | 'top'). Coerce both shapes so existing users
|
|
// keep their preference without manual migration.
|
|
export const normalizeStatusBar = (raw: unknown): StatusBarMode => {
|
|
if (raw === false) return 'off'
|
|
if (raw === true || raw == null) return 'on'
|
|
if (typeof raw === 'string' && STATUSBAR_MODES.has(raw as StatusBarMode)) return raw as StatusBarMode
|
|
|
|
return 'on'
|
|
}
|
|
|
|
const MTIME_POLL_MS = 5000
|
|
|
|
const quietRpc = async <T extends Record<string, any> = Record<string, any>>(
|
|
gw: GatewayClient,
|
|
method: string,
|
|
params: Record<string, unknown> = {}
|
|
): Promise<null | T> => {
|
|
try {
|
|
return asRpcResult<T>(await gw.request<T>(method, params))
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const applyDisplay = (cfg: ConfigFullResponse | null, setBell: (v: boolean) => void) => {
|
|
const d = cfg?.config?.display ?? {}
|
|
|
|
setBell(!!d.bell_on_complete)
|
|
patchUiState({
|
|
compact: !!d.tui_compact,
|
|
detailsMode: resolveDetailsMode(d),
|
|
inlineDiffs: d.inline_diffs !== false,
|
|
showCost: !!d.show_cost,
|
|
showReasoning: !!d.show_reasoning,
|
|
statusBar: normalizeStatusBar(d.tui_statusbar),
|
|
streaming: d.streaming !== false
|
|
})
|
|
}
|
|
|
|
export function useConfigSync({ gw, setBellOnComplete, setVoiceEnabled, sid }: UseConfigSyncOptions) {
|
|
const mtimeRef = useRef(0)
|
|
|
|
useEffect(() => {
|
|
if (!sid) {
|
|
return
|
|
}
|
|
|
|
quietRpc<VoiceToggleResponse>(gw, 'voice.toggle', { action: 'status' }).then(r => setVoiceEnabled(!!r?.enabled))
|
|
quietRpc<ConfigMtimeResponse>(gw, 'config.get', { key: 'mtime' }).then(r => {
|
|
mtimeRef.current = Number(r?.mtime ?? 0)
|
|
})
|
|
quietRpc<ConfigFullResponse>(gw, 'config.get', { key: 'full' }).then(r => applyDisplay(r, setBellOnComplete))
|
|
}, [gw, setBellOnComplete, setVoiceEnabled, sid])
|
|
|
|
useEffect(() => {
|
|
if (!sid) {
|
|
return
|
|
}
|
|
|
|
const id = setInterval(() => {
|
|
quietRpc<ConfigMtimeResponse>(gw, 'config.get', { key: 'mtime' }).then(r => {
|
|
const next = Number(r?.mtime ?? 0)
|
|
|
|
if (!mtimeRef.current) {
|
|
if (next) {
|
|
mtimeRef.current = next
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if (!next || next === mtimeRef.current) {
|
|
return
|
|
}
|
|
|
|
mtimeRef.current = next
|
|
|
|
quietRpc<ReloadMcpResponse>(gw, 'reload.mcp', { session_id: sid }).then(
|
|
r => r && turnController.pushActivity('MCP reloaded after config change')
|
|
)
|
|
quietRpc<ConfigFullResponse>(gw, 'config.get', { key: 'full' }).then(r => applyDisplay(r, setBellOnComplete))
|
|
})
|
|
}, MTIME_POLL_MS)
|
|
|
|
return () => clearInterval(id)
|
|
}, [gw, setBellOnComplete, sid])
|
|
}
|
|
|
|
export interface UseConfigSyncOptions {
|
|
gw: GatewayClient
|
|
setBellOnComplete: (v: boolean) => void
|
|
setVoiceEnabled: (v: boolean) => void
|
|
sid: null | string
|
|
}
|