Skip to content

Commit 9cde2e1

Browse files
committed
feat: add debug dialog showing system information
1 parent 1f170ed commit 9cde2e1

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { useMemo, useEffect } from "react"
2+
import { c } from "../theme.js"
3+
import { loadConfig } from "../../services/config.js"
4+
import { listConnectedServers } from "../../integrations/mcp/index.js"
5+
import { readAll } from "../../services/auth-store.js"
6+
import { getGlobalConfigDir, getGlobalDataDir } from "../../utils/paths.js"
7+
import { getPlatformInfo } from "../../utils/platform.js"
8+
import type { SessionStore } from "../../services/session-store.js"
9+
import { titlecase } from "../utils.js"
10+
11+
export interface DebugDialogProps {
12+
termWidth: number; termHeight: number
13+
selectedModel: string | null
14+
provider: string | null
15+
selectedAgent: string
16+
thinkingEffort?: string
17+
sessionStore: SessionStore
18+
mcpCount: number
19+
onClose: () => void
20+
registerHandler: (fn: ((key: any) => void) | null) => void
21+
}
22+
23+
export function DebugDialog(props: DebugDialogProps) {
24+
const { termWidth, termHeight, selectedModel, provider, selectedAgent, thinkingEffort, sessionStore, mcpCount, onClose, registerHandler } = props
25+
26+
const mw = Math.min(64, termWidth - 4)
27+
const ml = Math.floor((termWidth - mw) / 2)
28+
const mh = Math.min(26, termHeight - 4)
29+
const mt = Math.max(1, Math.floor((termHeight - mh) / 2))
30+
const innerW = mw - 4
31+
32+
const info = useMemo(() => {
33+
const config = loadConfig()
34+
const connected = listConnectedServers()
35+
const authStore = readAll()
36+
const platform = getPlatformInfo()
37+
const sessions = sessionStore.list()
38+
39+
const configDir = getGlobalConfigDir()
40+
const dataDir = getGlobalDataDir()
41+
42+
const lines: { label: string; value: string }[] = [
43+
{ label: "Version", value: "0.4.1" },
44+
{ label: "Directory", value: platform.cwd },
45+
{ label: "Platform", value: `${platform.os} (${platform.arch})` },
46+
{ label: "Shell", value: platform.shell },
47+
{ label: "", value: "" },
48+
{ label: "Agent", value: titlecase(selectedAgent) },
49+
{ label: "Model", value: selectedModel || "(none)" },
50+
{ label: "Provider", value: provider || "(none)" },
51+
{ label: "Thinking effort", value: thinkingEffort || "default" },
52+
{ label: "", value: "" },
53+
{ label: "MCP servers", value: `${config.mcp?.length ?? 0} configured, ${mcpCount} connected` },
54+
{ label: "Sessions", value: `${sessions.length} total` },
55+
{ label: "Auth keys", value: `${Object.keys(authStore).length} provider(s)` },
56+
{ label: "", value: "" },
57+
{ label: "Config dir", value: configDir },
58+
{ label: "Data dir", value: dataDir },
59+
]
60+
return lines
61+
}, [selectedModel, provider, selectedAgent, thinkingEffort, sessionStore, mcpCount])
62+
63+
const maxLabel = useMemo(() => Math.max(...info.map((l) => l.label.length)), [info])
64+
65+
useEffect(() => {
66+
registerHandler((key: any) => {
67+
if (key.name === "escape") { onClose(); return }
68+
})
69+
return () => registerHandler(null)
70+
}, [onClose, registerHandler])
71+
72+
return (
73+
<box position="absolute" left={0} right={0} top={0} bottom={0} backgroundColor={c.bgOverlay}>
74+
<box position="absolute" left={ml} top={mt} width={mw} height={mh} backgroundColor={c.bgCard}
75+
flexDirection="column" paddingX={2} paddingY={1}>
76+
<box height={1} flexDirection="row" justifyContent="space-between" alignItems="center">
77+
<text fg={c.accent} attributes={1}>Debug Info</text>
78+
<text fg={c.dim}>esc</text>
79+
</box>
80+
<box height={1} />
81+
<box>
82+
<text fg={c.border}>{"─".repeat(innerW)}</text>
83+
</box>
84+
<scrollbox height={mh - 5} scrollY={true} scrollbarOptions={{ visible: false }}>
85+
<box flexDirection="column" gap={0}>
86+
{info.map((row, i) => {
87+
if (!row.label) return <box key={i} height={1} />
88+
const pad = maxLabel - row.label.length + 1
89+
return (
90+
<box key={i} height={1} flexDirection="row">
91+
<text fg={c.dim}>{row.label}:</text>
92+
<text fg={c.text}>{" ".repeat(pad)}{row.value}</text>
93+
</box>
94+
)
95+
})}
96+
</box>
97+
</scrollbox>
98+
<box paddingTop={1} flexDirection="row" justifyContent="center">
99+
<text fg={c.dim}>esc close</text>
100+
</box>
101+
</box>
102+
</box>
103+
)
104+
}

0 commit comments

Comments
 (0)