herm-tui 1.0.0-dev.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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -0
  3. package/package.json +82 -0
  4. package/scripts/postinstall.ts +29 -0
  5. package/src/app/gateway.tsx +83 -0
  6. package/src/app/gatewayEvents.ts +203 -0
  7. package/src/app/launch.ts +41 -0
  8. package/src/app/skin.tsx +31 -0
  9. package/src/app/spawnHistory.ts +75 -0
  10. package/src/app/tabs.ts +23 -0
  11. package/src/app/turnReducer.ts +390 -0
  12. package/src/app/useAppKeys.ts +268 -0
  13. package/src/app/useAtRefPopover.ts +99 -0
  14. package/src/app/useInputHistory.ts +66 -0
  15. package/src/app/useSession.ts +102 -0
  16. package/src/app/useSlashCommands.ts +70 -0
  17. package/src/app/useSlashPopover.ts +48 -0
  18. package/src/app.tsx +917 -0
  19. package/src/commands/slash.ts +151 -0
  20. package/src/components/avatar/AnimatedAvatar.tsx +66 -0
  21. package/src/components/avatar/eikon.ts +144 -0
  22. package/src/components/avatar/states/error.ts +1155 -0
  23. package/src/components/avatar/states/idle.ts +1155 -0
  24. package/src/components/avatar/states/index.ts +30 -0
  25. package/src/components/avatar/states/listening.ts +1155 -0
  26. package/src/components/avatar/states/speaking.ts +1155 -0
  27. package/src/components/avatar/states/thinking.ts +1155 -0
  28. package/src/components/avatar/states/working.ts +1155 -0
  29. package/src/components/chat/AtRefPopover.tsx +54 -0
  30. package/src/components/chat/CodeBlock.tsx +67 -0
  31. package/src/components/chat/Composer.tsx +347 -0
  32. package/src/components/chat/DiffBlock.tsx +116 -0
  33. package/src/components/chat/ErrorBlock.tsx +70 -0
  34. package/src/components/chat/MediaChip.tsx +114 -0
  35. package/src/components/chat/MessageItem.tsx +282 -0
  36. package/src/components/chat/MessageList.tsx +114 -0
  37. package/src/components/chat/PromptCard.tsx +359 -0
  38. package/src/components/chat/SlashPopover.tsx +158 -0
  39. package/src/components/chat/ThoughtCloud.tsx +185 -0
  40. package/src/components/chat/TypingIndicator.tsx +25 -0
  41. package/src/components/chat/tool/Subagent.tsx +75 -0
  42. package/src/components/chat/tool/frame.tsx +69 -0
  43. package/src/components/chat/tool/index.tsx +65 -0
  44. package/src/components/chat/tool/preview.ts +57 -0
  45. package/src/components/sidebar/ContextGauge.tsx +102 -0
  46. package/src/components/sidebar/Sidebar.tsx +143 -0
  47. package/src/components/tabs/TabBar.tsx +50 -0
  48. package/src/components/ui/FileLink.tsx +52 -0
  49. package/src/config/index.ts +156 -0
  50. package/src/config/lane.ts +161 -0
  51. package/src/config/models.ts +95 -0
  52. package/src/config/rules.ts +80 -0
  53. package/src/config/schema.ts +308 -0
  54. package/src/dialogs/alert.tsx +52 -0
  55. package/src/dialogs/chafa.tsx +72 -0
  56. package/src/dialogs/confirm.tsx +58 -0
  57. package/src/dialogs/curator.tsx +153 -0
  58. package/src/dialogs/eikon-picker.tsx +95 -0
  59. package/src/dialogs/help.tsx +80 -0
  60. package/src/dialogs/history.tsx +92 -0
  61. package/src/dialogs/info.tsx +115 -0
  62. package/src/dialogs/keys.tsx +170 -0
  63. package/src/dialogs/logs.tsx +42 -0
  64. package/src/dialogs/message.tsx +38 -0
  65. package/src/dialogs/model-picker.tsx +123 -0
  66. package/src/dialogs/new-profile.tsx +69 -0
  67. package/src/dialogs/new-task.tsx +103 -0
  68. package/src/dialogs/profile.tsx +55 -0
  69. package/src/dialogs/rollback.tsx +190 -0
  70. package/src/dialogs/spawn-history.tsx +80 -0
  71. package/src/dialogs/text-prompt.tsx +68 -0
  72. package/src/dialogs/theme-picker.tsx +50 -0
  73. package/src/home/index.ts +23 -0
  74. package/src/home/store.ts +267 -0
  75. package/src/index.tsx +113 -0
  76. package/src/keys/catalog.ts +115 -0
  77. package/src/keys/chord.ts +125 -0
  78. package/src/keys/conflicts.ts +48 -0
  79. package/src/keys/context.tsx +112 -0
  80. package/src/keys/index.ts +5 -0
  81. package/src/keys/list.ts +94 -0
  82. package/src/keys/oc-compat.ts +87 -0
  83. package/src/tabs/Agents.tsx +607 -0
  84. package/src/tabs/Analytics.tsx +154 -0
  85. package/src/tabs/Chat.tsx +50 -0
  86. package/src/tabs/Config.tsx +605 -0
  87. package/src/tabs/Context.tsx +599 -0
  88. package/src/tabs/Cron.tsx +294 -0
  89. package/src/tabs/Env.tsx +227 -0
  90. package/src/tabs/Kanban.tsx +367 -0
  91. package/src/tabs/Memory.tsx +294 -0
  92. package/src/tabs/Sessions.tsx +786 -0
  93. package/src/tabs/Skills.tsx +507 -0
  94. package/src/tabs/Toolsets.tsx +266 -0
  95. package/src/theme/builtin.ts +78 -0
  96. package/src/theme/context.tsx +106 -0
  97. package/src/theme/index.ts +4 -0
  98. package/src/theme/resolve.ts +134 -0
  99. package/src/theme/syntax.ts +31 -0
  100. package/src/theme/themes/aura.json +69 -0
  101. package/src/theme/themes/ayu.json +80 -0
  102. package/src/theme/themes/carbonfox.json +248 -0
  103. package/src/theme/themes/catppuccin-frappe.json +233 -0
  104. package/src/theme/themes/catppuccin-macchiato.json +233 -0
  105. package/src/theme/themes/catppuccin.json +112 -0
  106. package/src/theme/themes/cobalt2.json +228 -0
  107. package/src/theme/themes/cursor.json +249 -0
  108. package/src/theme/themes/dracula.json +219 -0
  109. package/src/theme/themes/everforest.json +241 -0
  110. package/src/theme/themes/flexoki.json +237 -0
  111. package/src/theme/themes/github.json +233 -0
  112. package/src/theme/themes/gruvbox.json +242 -0
  113. package/src/theme/themes/kanagawa.json +77 -0
  114. package/src/theme/themes/lucent-orng.json +237 -0
  115. package/src/theme/themes/material.json +235 -0
  116. package/src/theme/themes/matrix.json +77 -0
  117. package/src/theme/themes/mercury.json +252 -0
  118. package/src/theme/themes/monokai.json +221 -0
  119. package/src/theme/themes/nightowl.json +221 -0
  120. package/src/theme/themes/nord.json +223 -0
  121. package/src/theme/themes/one-dark.json +84 -0
  122. package/src/theme/themes/opencode.json +245 -0
  123. package/src/theme/themes/orng.json +249 -0
  124. package/src/theme/themes/osaka-jade.json +93 -0
  125. package/src/theme/themes/palenight.json +222 -0
  126. package/src/theme/themes/rosepine.json +234 -0
  127. package/src/theme/themes/solarized.json +223 -0
  128. package/src/theme/themes/synthwave84.json +226 -0
  129. package/src/theme/themes/tokyonight.json +243 -0
  130. package/src/theme/themes/vercel.json +245 -0
  131. package/src/theme/themes/vesper.json +218 -0
  132. package/src/theme/themes/zenburn.json +223 -0
  133. package/src/theme/types.ts +119 -0
  134. package/src/types/message.ts +97 -0
  135. package/src/ui/ChafaImage.tsx +64 -0
  136. package/src/ui/Splash.tsx +118 -0
  137. package/src/ui/borders.ts +28 -0
  138. package/src/ui/command.tsx +104 -0
  139. package/src/ui/dialog-select.tsx +164 -0
  140. package/src/ui/dialog.tsx +102 -0
  141. package/src/ui/fmt.ts +82 -0
  142. package/src/ui/kv.tsx +28 -0
  143. package/src/ui/shell.tsx +45 -0
  144. package/src/ui/spinner.tsx +59 -0
  145. package/src/ui/splash-art.ts +123 -0
  146. package/src/ui/table.tsx +117 -0
  147. package/src/ui/ticker.tsx +90 -0
  148. package/src/ui/toast.tsx +130 -0
  149. package/src/utils/categorical.ts +77 -0
  150. package/src/utils/chafa.ts +173 -0
  151. package/src/utils/clipboard.ts +67 -0
  152. package/src/utils/context-segments.ts +317 -0
  153. package/src/utils/control.ts +495 -0
  154. package/src/utils/drop.ts +25 -0
  155. package/src/utils/editor.ts +33 -0
  156. package/src/utils/fuzzy.ts +45 -0
  157. package/src/utils/gateway-client.ts +253 -0
  158. package/src/utils/gateway-types.ts +282 -0
  159. package/src/utils/git.ts +57 -0
  160. package/src/utils/hermes-analytics.ts +134 -0
  161. package/src/utils/hermes-home.ts +821 -0
  162. package/src/utils/hermes-kanban.ts +154 -0
  163. package/src/utils/hermes-profiles.ts +217 -0
  164. package/src/utils/interpolate.ts +31 -0
  165. package/src/utils/math-unicode.ts +818 -0
  166. package/src/utils/memory-activity.ts +140 -0
  167. package/src/utils/open-file.ts +13 -0
  168. package/src/utils/paths.ts +52 -0
  169. package/src/utils/perf.ts +235 -0
  170. package/src/utils/preferences.ts +150 -0
  171. package/src/utils/sessions-db.ts +396 -0
  172. package/src/utils/subagent-tree.ts +146 -0
  173. package/src/utils/terminal-reset.ts +129 -0
  174. package/src/utils/tips.ts +67 -0
  175. package/src/utils/tokens.ts +87 -0
@@ -0,0 +1,72 @@
1
+ // Throwaway demo dialog — `/chafa <path>` renders an image inline via
2
+ // chafa's symbol mode + our SGR parser (src/utils/chafa.ts). Proof that
3
+ // 24-bit colored image rendering in OpenTUI works end-to-end. Will be
4
+ // superseded by inline rendering in MessageItem (herm-mzb.7).
5
+
6
+ import { useMemo, useState } from "react"
7
+ import { spawnSync } from "child_process"
8
+ import { existsSync } from "fs"
9
+ import { useTheme } from "../theme"
10
+ import type { DialogContext } from "../ui/dialog"
11
+ import { parseChafa, hex, type Cell } from "../utils/chafa"
12
+
13
+ const CHAFA = ["/usr/sbin/chafa", "/usr/bin/chafa", "/usr/local/bin/chafa", "/opt/homebrew/bin/chafa"]
14
+
15
+ function whichChafa(): string | null {
16
+ for (const p of CHAFA) if (existsSync(p)) return p
17
+ return null
18
+ }
19
+
20
+ function render(path: string, w: number, h: number): { rows?: Cell[][]; err?: string } {
21
+ const bin = whichChafa()
22
+ if (!bin) return { err: "chafa not installed (brew/apt install chafa)" }
23
+ const full = path.startsWith("~") ? path.replace(/^~/, process.env.HOME ?? "") : path
24
+ if (!existsSync(full)) return { err: `file not found: ${full}` }
25
+ const r = spawnSync(bin, [
26
+ `--size=${w}x${h}`,
27
+ "--format=symbols",
28
+ "--symbols=block",
29
+ "--colors=full",
30
+ full,
31
+ ], { encoding: "utf8" })
32
+ if (r.status !== 0) return { err: r.stderr || `chafa exit ${r.status}` }
33
+ return { rows: parseChafa(r.stdout) }
34
+ }
35
+
36
+ const ChafaDialog = ({ path }: { path: string }) => {
37
+ const theme = useTheme().theme
38
+ const [w] = useState(80)
39
+ const [h] = useState(28)
40
+ const result = useMemo(() => render(path, w, h), [path, w, h])
41
+
42
+ return (
43
+ <box flexDirection="column" minWidth={w + 4} gap={1}>
44
+ <box height={1}>
45
+ <text fg={theme.primary}><strong>chafa demo · {path}</strong></text>
46
+ </box>
47
+ {result.err
48
+ ? <box height={1}><text fg={theme.error}>{result.err}</text></box>
49
+ : (
50
+ <box flexDirection="column">
51
+ {result.rows!.map((row, i) => (
52
+ <text key={i}>
53
+ {row.map((c, j) => (
54
+ <span key={j} fg={hex(c.fg)} bg={hex(c.bg)}>{c.ch}</span>
55
+ ))}
56
+ </text>
57
+ ))}
58
+ </box>
59
+ )}
60
+ <box height={1}>
61
+ <text fg={theme.borderSubtle}>
62
+ {result.rows ? `${result.rows.length} rows · ${result.rows.reduce((a, r) => a + r.length, 0)} cells · ` : ""}
63
+ Esc to close
64
+ </text>
65
+ </box>
66
+ </box>
67
+ )
68
+ }
69
+
70
+ export function openChafa(dialog: DialogContext, path: string) {
71
+ dialog.replace(<ChafaDialog path={path} />)
72
+ }
@@ -0,0 +1,58 @@
1
+ // Generic y/n confirm dialog. `openConfirm(dialog, {...})` resolves to
2
+ // true on [y], false on [n]/Esc.
3
+
4
+ import { useKeyboard } from "@opentui/react"
5
+ import { useKeys } from "../keys"
6
+ import { useTheme } from "../theme"
7
+ import type { DialogContext } from "../ui/dialog"
8
+
9
+ type Props = {
10
+ title: string
11
+ body: string
12
+ yes?: string
13
+ no?: string
14
+ danger?: boolean
15
+ onConfirm: () => void
16
+ onCancel: () => void
17
+ }
18
+
19
+ const Confirm = (props: Props) => {
20
+ const theme = useTheme().theme
21
+ const keys = useKeys()
22
+ useKeyboard((key) => {
23
+ if (keys.match("dialog.confirm", key) || keys.match("dialog.accept", key)) return props.onConfirm()
24
+ if (keys.match("dialog.deny", key) || keys.match("dialog.cancel", key)) return props.onCancel()
25
+ })
26
+ return (
27
+ <box flexDirection="column" width={54}>
28
+ <box height={1}>
29
+ <text fg={props.danger ? theme.warning : theme.primary}>
30
+ <strong>{props.title}</strong>
31
+ </text>
32
+ </box>
33
+ <box height={1} />
34
+ <box minHeight={1}><text wrapMode="word">{props.body}</text></box>
35
+ <box height={1} />
36
+ <box height={1}>
37
+ <text fg={theme.textMuted}>
38
+ {`[${keys.print("dialog.confirm")}/${keys.print("dialog.accept")}] ${props.yes ?? "confirm"} [${keys.print("dialog.deny")}] ${props.no ?? "cancel"}`}
39
+ </text>
40
+ </box>
41
+ </box>
42
+ )
43
+ }
44
+
45
+ export function openConfirm(
46
+ dialog: DialogContext,
47
+ opts: Omit<Props, "onConfirm" | "onCancel">,
48
+ ): Promise<boolean> {
49
+ return new Promise((resolve) => {
50
+ dialog.replace(
51
+ <Confirm
52
+ {...opts}
53
+ onConfirm={() => { dialog.clear(); resolve(true) }}
54
+ onCancel={() => { dialog.clear(); resolve(false) }}
55
+ />,
56
+ )
57
+ })
58
+ }
@@ -0,0 +1,153 @@
1
+ // Curator control panel. Reads .curator_state + config.curator.*; the
2
+ // report pane shows the newest logs/curator/*/REPORT.md. Writes route
3
+ // through `shell.exec → hermes curator <verb>` so the CLI owns the
4
+ // state machine (see Agents.tsx / Kanban.tsx for the precedent).
5
+
6
+ import { useEffect, useState, useCallback } from "react"
7
+ import { useKeyboard } from "@opentui/react"
8
+ import { useTheme } from "../theme"
9
+ import type { DialogContext } from "../ui/dialog"
10
+ import { useGateway } from "../app/gateway"
11
+ import { useHome, home } from "../home"
12
+ import { useToast } from "../ui/toast"
13
+ import { readLatestCuratorReport, type CuratorReportInfo } from "../utils/hermes-home"
14
+ import { KVLink } from "../components/ui/FileLink"
15
+ import { KVBlock } from "../ui/kv"
16
+ import { Spinner } from "../ui/spinner"
17
+ import { ago, until, dur, trunc } from "../ui/fmt"
18
+
19
+ const iso = (s: string | null | undefined): number | null => {
20
+ if (!s) return null
21
+ const t = Date.parse(s)
22
+ return Number.isFinite(t) ? Math.floor(t / 1000) : null
23
+ }
24
+
25
+ type Sh = { stdout: string; stderr: string; code: number }
26
+
27
+ const CuratorDialog = () => {
28
+ const { theme, syntaxStyle } = useTheme()
29
+ const gw = useGateway()
30
+ const toast = useToast()
31
+ const state = useHome("curatorState")
32
+ const cfg = useHome("config")?.curator
33
+ const [report, setReport] = useState<CuratorReportInfo | null>(null)
34
+ const [loaded, setLoaded] = useState(false)
35
+ const [busy, setBusy] = useState<"run" | "pause" | "resume" | null>(null)
36
+
37
+ useEffect(() => {
38
+ readLatestCuratorReport()
39
+ .then(r => { setReport(r); setLoaded(true) })
40
+ .catch(() => setLoaded(true))
41
+ }, [])
42
+
43
+ const sh = useCallback((verb: "run" | "pause" | "resume", ok: string) => {
44
+ if (busy) return
45
+ setBusy(verb)
46
+ gw.request<Sh>("shell.exec", { command: `hermes curator ${verb}` })
47
+ .then(r => {
48
+ if (r.code !== 0) throw new Error((r.stderr || r.stdout || `exit ${r.code}`).trim())
49
+ toast.show({ variant: "success", message: ok })
50
+ home.invalidate("curatorState")
51
+ })
52
+ .catch((e: Error) => toast.show({ variant: "error", message: trunc(e.message, 120) }))
53
+ .finally(() => setBusy(null))
54
+ }, [gw, toast, busy])
55
+
56
+ useKeyboard((key) => {
57
+ if (key.raw === "r") return sh("run", "Curator run started (background)")
58
+ if (key.raw === "p") return state?.paused
59
+ ? sh("resume", "Curator resumed")
60
+ : sh("pause", "Curator paused")
61
+ })
62
+
63
+ const last = iso(state?.last_run_at ?? null)
64
+ // Next-due is last_run_at + interval_hours. CLI additionally gates on
65
+ // min_idle_hours, so this is "eligible from", not "will fire at".
66
+ const due = last && cfg ? last + cfg.interval_hours * 3600 : null
67
+ const status = cfg?.enabled === false ? "disabled"
68
+ : state?.paused ? "paused"
69
+ : "enabled"
70
+ const tint = status === "enabled" ? theme.success
71
+ : status === "paused" ? theme.warning : theme.textMuted
72
+
73
+ return (
74
+ <box flexDirection="column" width={120} height={34}>
75
+ <box height={1} flexDirection="row">
76
+ <text>
77
+ <span fg={theme.primary}><strong>Skill Curator</strong></span>
78
+ <span fg={tint}>{` · ${status}`}</span>
79
+ </text>
80
+ {busy ? <box marginLeft={2}><Spinner color={theme.textMuted} label={busy} /></box> : null}
81
+ </box>
82
+ <box height={1}>
83
+ <text fg={theme.textMuted}>
84
+ {state
85
+ ? `${state.run_count} run${state.run_count === 1 ? "" : "s"}${last ? " · last " + ago(last) : " · never"} · Esc to close`
86
+ : "No curator state yet · Esc to close"}
87
+ </text>
88
+ </box>
89
+ <box height={1} />
90
+
91
+ <box flexDirection="row" flexGrow={1} gap={2}>
92
+ <box flexDirection="column" width={40} height="100%" flexShrink={0}>
93
+ <KVBlock rows={[
94
+ ["Next run", status !== "enabled" ? `— (${status})`
95
+ : due ? until(due) : "when idle"],
96
+ ["Last run", last ? ago(last) : "never"],
97
+ ["Duration", state?.last_run_duration_seconds
98
+ ? dur(state.last_run_duration_seconds) : undefined],
99
+ ]} />
100
+ <box height={1} />
101
+ <box height={1}><text fg={theme.textMuted}>Config · edit in Config tab</text></box>
102
+ <KVBlock rows={[
103
+ ["Interval", cfg ? `${cfg.interval_hours}h` : "—"],
104
+ ["Stale after", cfg ? `${cfg.stale_after_days}d` : "—"],
105
+ ["Archive after", cfg ? `${cfg.archive_after_days}d` : "—"],
106
+ ]} />
107
+ <box height={1} />
108
+ <box flexDirection="column">
109
+ <box height={1}><text>
110
+ <span fg={theme.accent}>r </span>
111
+ <span fg={theme.text}>run now</span>
112
+ <span fg={theme.textMuted}> (background)</span>
113
+ </text></box>
114
+ <box height={1}><text>
115
+ <span fg={theme.accent}>p </span>
116
+ <span fg={theme.text}>{state?.paused ? "resume" : "pause"}</span>
117
+ </text></box>
118
+ </box>
119
+ {state?.last_run_summary ? <>
120
+ <box height={1} />
121
+ <box height={1}><text fg={theme.textMuted}>Last run</text></box>
122
+ <scrollbox scrollY flexGrow={1}>
123
+ <markdown content={state.last_run_summary}
124
+ fg={theme.markdownText} syntaxStyle={syntaxStyle} />
125
+ </scrollbox>
126
+ </> : null}
127
+ </box>
128
+
129
+ {!loaded ? (
130
+ <box height={1}><text fg={theme.textMuted}>loading report…</text></box>
131
+ ) : report ? (
132
+ <box flexDirection="column" flexGrow={1} height="100%" minWidth={0}>
133
+ <box height={1}><text fg={theme.info}><strong>{`▾ Report · ${report.runId}`}</strong></text></box>
134
+ <KVLink label="File" source={report.source} text={report.source.relative} />
135
+ <box height={1} />
136
+ <scrollbox scrollY flexGrow={1} border borderColor={theme.border}
137
+ paddingLeft={1} paddingRight={1}>
138
+ <box flexDirection="column" width="100%">
139
+ <markdown content={report.content || "(empty)"}
140
+ fg={theme.markdownText} syntaxStyle={syntaxStyle} />
141
+ </box>
142
+ </scrollbox>
143
+ </box>
144
+ ) : (
145
+ <box height={1}><text fg={theme.textMuted}>No runs yet — curator has not completed a cycle.</text></box>
146
+ )}
147
+ </box>
148
+ </box>
149
+ )
150
+ }
151
+
152
+ export const openCurator = (dialog: DialogContext) =>
153
+ dialog.replace(<CuratorDialog />)
@@ -0,0 +1,95 @@
1
+ // Browse available .eikon avatars from known directories with a live
2
+ // preview. ↑/↓ to navigate, Enter to select, Esc closes (via DialogProvider).
3
+
4
+ import { useMemo, useState } from "react"
5
+ import { readFileSync } from "fs"
6
+ import { homedir } from "os"
7
+ import { join } from "path"
8
+ import { useListKeys } from "../keys"
9
+ import { useTheme } from "../theme"
10
+ import { useDialog } from "../ui/dialog"
11
+ import { AnimatedAvatar } from "../components/avatar/AnimatedAvatar"
12
+ import { listEikons, parseEikon, type ParsedEikon } from "../components/avatar/eikon"
13
+
14
+ const trunc = (s: string, n: number) => s.length <= n ? s : s.slice(0, n - 1) + "…"
15
+
16
+ // Default search path for .eikon avatars: $HERMES_HOME/eikons.
17
+ // If nothing is found the picker shows an empty state — see README
18
+ // "Avatars (.eikon)" for where to drop files.
19
+ const defaultDirs = (): string[] => {
20
+ const hermesHome = process.env.HERMES_HOME || join(homedir(), ".hermes")
21
+ return [join(hermesHome, "eikons")]
22
+ }
23
+
24
+ export const EikonPickerDialog = (props: {
25
+ dirs?: string[]
26
+ onSelect: (path: string) => void
27
+ }) => {
28
+ const theme = useTheme().theme
29
+ const dialog = useDialog()
30
+ const dirs = props.dirs ?? defaultDirs()
31
+
32
+ const found = useMemo(() => listEikons(dirs), [dirs])
33
+ const [cursor, setCursor] = useState(0)
34
+
35
+ const cur = found[cursor]
36
+ const parsed = useMemo<ParsedEikon | undefined>(() => {
37
+ if (!cur) return undefined
38
+ try { return parseEikon(readFileSync(cur.path, "utf8")) }
39
+ catch { return undefined }
40
+ }, [cur])
41
+
42
+ useListKeys({
43
+ active: true,
44
+ count: found.length, setSel: setCursor,
45
+ onActivate: () => { if (cur) { props.onSelect(cur.path); dialog.clear() } },
46
+ })
47
+
48
+ const w = (parsed?.meta.width ?? 48) + 2
49
+ const h = Math.max(parsed?.meta.height ?? 24, 12)
50
+
51
+ return (
52
+ <box flexDirection="column" width={40 + w} height={h + 4}>
53
+ <box height={1}><text fg={theme.primary}><strong>Pick Avatar</strong></text></box>
54
+ <box height={1}><text fg={theme.textMuted}>{`${found.length} found · ↑↓ nav · Enter select · Esc close`}</text></box>
55
+ <box height={1} />
56
+ <box flexDirection="row" flexGrow={1}>
57
+ {/* list */}
58
+ <box width={38} marginRight={2}>
59
+ <scrollbox scrollY flexGrow={1}>
60
+ <box flexDirection="column" width="100%">
61
+ {found.length === 0 ? (
62
+ <box key="empty" height={1}><text fg={theme.textMuted}>No .eikon files found.</text></box>
63
+ ) : found.map((e, i) => {
64
+ const on = i === cursor
65
+ return (
66
+ <box key={e.path} flexDirection="column" paddingLeft={1} paddingRight={1}
67
+ backgroundColor={on ? theme.backgroundElement : undefined}
68
+ onMouseDown={() => setCursor(i)}>
69
+ <box height={1}>
70
+ <text fg={on ? theme.text : theme.textMuted}><strong>{trunc(e.meta.name, 34)}</strong></text>
71
+ </box>
72
+ <box height={1}>
73
+ <text fg={theme.textMuted}>
74
+ {`${e.meta.author ?? "—"} · ${e.meta.states.length} states · ${e.meta.width}×${e.meta.height}`}
75
+ </text>
76
+ </box>
77
+ </box>
78
+ )
79
+ })}
80
+ </box>
81
+ </scrollbox>
82
+ </box>
83
+ {/* preview */}
84
+ <box flexGrow={1} flexDirection="column" overflow="hidden">
85
+ {parsed
86
+ ? <AnimatedAvatar key={cur?.path ?? "none"} state="idle" eikon={parsed} />
87
+ : <box key="blank" height={1}><text fg={theme.textMuted}>No preview.</text></box>}
88
+ </box>
89
+ </box>
90
+ </box>
91
+ )
92
+ }
93
+
94
+ export const openEikonPicker = (dialog: ReturnType<typeof useDialog>, onSelect: (path: string) => void) =>
95
+ dialog.replace(<EikonPickerDialog onSelect={onSelect} />)
@@ -0,0 +1,80 @@
1
+ // Help dialog — keyboard shortcut reference, generated from the
2
+ // action catalog so it stays correct under user rebinds.
3
+
4
+ import { useMemo } from "react"
5
+ import { useTheme } from "../theme"
6
+ import { useKeys, type Scope } from "../keys"
7
+
8
+ type Group = { title: string; scope: Scope }
9
+
10
+ const GROUPS: ReadonlyArray<Group> = [
11
+ { title: "Global", scope: "global" },
12
+ { title: "Composer", scope: "composer" },
13
+ { title: "Lists", scope: "list" },
14
+ { title: "Dialogs", scope: "dialog" },
15
+ { title: "Sessions", scope: "sessions" },
16
+ { title: "Agents", scope: "agents" },
17
+ { title: "Config", scope: "config" },
18
+ ]
19
+
20
+ const COLS = 2
21
+
22
+ export const HelpDialog = () => {
23
+ const theme = useTheme().theme
24
+ const keys = useKeys()
25
+
26
+ const sections = useMemo(() =>
27
+ GROUPS.map(g => ({
28
+ title: g.title,
29
+ rows: keys.all(g.scope)
30
+ .filter(e => e.id !== "leader" && e.chord.length > 0)
31
+ .map(e => [keys.print(e.id), e.desc] as const),
32
+ })).filter(s => s.rows.length > 0),
33
+ [keys])
34
+
35
+ const total = sections.reduce((n, s) => n + s.rows.length + 2, 0)
36
+ const split = Math.ceil(total / COLS)
37
+
38
+ // Flow sections into two roughly-equal columns. A section goes to
39
+ // column 1 once placing it in column 0 would overshoot the split.
40
+ const cols: typeof sections[] = [[], []]
41
+ let acc = 0
42
+ for (const s of sections) {
43
+ const h = s.rows.length + 2
44
+ const i = acc + h <= split || cols[0].length === 0 ? 0 : 1
45
+ cols[i].push(s)
46
+ if (i === 0) acc += h
47
+ }
48
+
49
+ return (
50
+ <box flexDirection="column" width={104}>
51
+ <box height={1} flexDirection="row">
52
+ <box flexGrow={1}>
53
+ <text fg={theme.text}><strong>Keyboard Shortcuts</strong></text>
54
+ </box>
55
+ <text fg={theme.textMuted}>{`leader = ${keys.print("leader")}`}</text>
56
+ </box>
57
+ <box height={1} />
58
+ <box flexDirection="row" gap={3}>
59
+ {cols.map((col, ci) => (
60
+ <box key={ci} flexDirection="column" flexGrow={1} flexBasis={0}>
61
+ {col.map(s => (
62
+ <box key={s.title} flexDirection="column" marginBottom={1}>
63
+ <text fg={theme.primary}><strong>{s.title}</strong></text>
64
+ {s.rows.map(([chord, desc]) => (
65
+ <box key={chord + desc} flexDirection="row" height={1} paddingLeft={1}>
66
+ <box width={14}><text fg={theme.accent}>{chord}</text></box>
67
+ <box flexGrow={1} minWidth={0} height={1} overflow="hidden">
68
+ <text fg={theme.textMuted}>{desc}</text>
69
+ </box>
70
+ </box>
71
+ ))}
72
+ </box>
73
+ ))}
74
+ </box>
75
+ ))}
76
+ </box>
77
+ <text fg={theme.textMuted}>esc to close</text>
78
+ </box>
79
+ )
80
+ }
@@ -0,0 +1,92 @@
1
+ // Read-only transcript viewer for the *live* session (authoritative
2
+ // gateway history, not herm's render state). Useful after resuming a
3
+ // session (shows server messages herm hasn't rendered) and for sanity
4
+ // checking what session.undo / rewind actually removed.
5
+ //
6
+ // Row shape comes from tui_gateway `_history_to_messages`:
7
+ // user/assistant/system → {role, text}
8
+ // tool → {role, name, context} (args summary, no result)
9
+
10
+ import { useEffect, useState } from "react"
11
+ import { useTheme, type Theme } from "../theme"
12
+ import type { DialogContext } from "../ui/dialog"
13
+ import type { Gateway } from "../app/gateway"
14
+ import type { TranscriptMessage } from "../utils/gateway-types"
15
+ import { trunc } from "../ui/fmt"
16
+
17
+ type Res = { count: number; messages: TranscriptMessage[] }
18
+
19
+ const tag = (m: TranscriptMessage, theme: Theme) =>
20
+ m.role === "user" ? { label: "▸ You", fg: theme.info }
21
+ : m.role === "assistant" ? { label: "◂ Agent", fg: theme.success }
22
+ : m.role === "tool" ? { label: `⚙ ${m.name ?? "tool"}`, fg: theme.warning }
23
+ : { label: "· system", fg: theme.textMuted }
24
+
25
+ // Flatten native-mode parts-lists to the first text fragment so the
26
+ // history preview renders something meaningful instead of [object Object].
27
+ const flatten = (t: TranscriptMessage["text"]): string => {
28
+ if (typeof t === "string") return t
29
+ if (!Array.isArray(t)) return ""
30
+ for (const p of t)
31
+ if (p && typeof p === "object" && "type" in p && p.type === "text"
32
+ && "text" in p && typeof p.text === "string") return p.text
33
+ return ""
34
+ }
35
+
36
+ const body = (m: TranscriptMessage) =>
37
+ m.role === "tool" ? (m.context ?? "") : flatten(m.text)
38
+
39
+ const HistoryDialog = (props: { gw: Gateway }) => {
40
+ const theme = useTheme().theme
41
+ const [rows, setRows] = useState<TranscriptMessage[] | null>(null)
42
+ const [err, setErr] = useState("")
43
+
44
+ useEffect(() => {
45
+ props.gw.request<Res>("session.history")
46
+ .then(r => setRows(r.messages ?? []))
47
+ .catch((e: Error) => { setErr(e.message); setRows([]) })
48
+ }, [props.gw])
49
+
50
+ const n = rows?.length ?? 0
51
+ const h = Math.min(34, Math.max(8, n + 5))
52
+
53
+ return (
54
+ <box flexDirection="column" width={110} height={h}>
55
+ <box height={1}><text fg={theme.primary}><strong>Session History</strong></text></box>
56
+ <box height={1}>
57
+ <text fg={err ? theme.error : theme.textMuted}>
58
+ {err ? `⚠ ${err}` : `${n} messages · server-authoritative · Esc to close`}
59
+ </text>
60
+ </box>
61
+ <box height={1} />
62
+ {rows === null ? (
63
+ <box height={1}><text fg={theme.textMuted}>loading…</text></box>
64
+ ) : n === 0 ? (
65
+ <box height={1}><text fg={theme.textMuted}>Empty — no turns yet.</text></box>
66
+ ) : (
67
+ <scrollbox scrollY flexGrow={1}>
68
+ <box flexDirection="column">
69
+ {rows.map((m, i) => {
70
+ const t = tag(m, theme)
71
+ return (
72
+ <box key={i} height={1} flexDirection="row">
73
+ <box width={14} flexShrink={0}>
74
+ <text fg={t.fg}>{trunc(t.label, 13)}</text>
75
+ </box>
76
+ <box flexGrow={1} minWidth={0} height={1} overflow="hidden">
77
+ <text fg={m.role === "tool" || m.role === "system" ? theme.textMuted : theme.text}>
78
+ {body(m).replace(/\n/g, " ")}
79
+ </text>
80
+ </box>
81
+ </box>
82
+ )
83
+ })}
84
+ </box>
85
+ </scrollbox>
86
+ )}
87
+ </box>
88
+ )
89
+ }
90
+
91
+ export const openHistory = (dialog: DialogContext, gw: Gateway) =>
92
+ dialog.replace(<HistoryDialog gw={gw} />)
@@ -0,0 +1,115 @@
1
+ // Small read-only KV dialogs for /status, /usage, /profile.
2
+ // /platforms has no structured RPC — it falls through to slash.exec
3
+ // and renders as a system line (see UPSTREAM.md).
4
+
5
+ import { useEffect, useState } from "react"
6
+ import type { RGBA } from "@opentui/core"
7
+ import { useTheme } from "../theme"
8
+ import { KVBlock } from "../ui/kv"
9
+ import { fmt, cost } from "../ui/fmt"
10
+ import type { DialogContext } from "../ui/dialog"
11
+ import type { Gateway } from "../app/gateway"
12
+ import type { SessionInfo, SessionUsageResponse } from "../utils/gateway-types"
13
+ import { listProfiles, activeProfileName } from "../utils/hermes-profiles"
14
+ import { hermesPath } from "../utils/hermes-home"
15
+
16
+ type Row = [string, string | undefined, RGBA?]
17
+
18
+ const InfoDialog = (props: { title: string; rows: Row[]; note?: string }) => {
19
+ const theme = useTheme().theme
20
+ const body = props.rows.filter(r => r[1] !== undefined)
21
+ return (
22
+ <box flexDirection="column" minWidth={52} gap={1}>
23
+ <box height={1}><text fg={theme.primary}><strong>{props.title}</strong></text></box>
24
+ <box flexDirection="column"><KVBlock rows={body} /></box>
25
+ {props.note
26
+ ? <box height={1}><text fg={theme.textMuted}>{props.note}</text></box>
27
+ : null}
28
+ <box height={1}><text fg={theme.borderSubtle}>Esc to close</text></box>
29
+ </box>
30
+ )
31
+ }
32
+
33
+ // ── /status ──────────────────────────────────────────────────────────
34
+
35
+ export function openStatus(dialog: DialogContext, info: SessionInfo | null, sid: string) {
36
+ const toolsets = Object.keys(info?.tools ?? {})
37
+ const nTools = Object.values(info?.tools ?? {}).reduce((n, v) => n + v.length, 0)
38
+ const mcp = info?.mcp_servers ?? []
39
+ const up = mcp.filter(s => s.connected).length
40
+ dialog.replace(
41
+ <InfoDialog title="Status" rows={[
42
+ ["Version", info?.version || "—"],
43
+ ["Model", info?.model || "—"],
44
+ ["Profile", activeProfileName()],
45
+ ["Home", hermesPath("")],
46
+ ["CWD", info?.cwd || process.cwd()],
47
+ ["Session", sid || "—"],
48
+ ["Tools", `${nTools} in ${toolsets.length} toolset${toolsets.length === 1 ? "" : "s"}`],
49
+ ["Skills", String(Object.values(info?.skills ?? {}).reduce((n, v) => n + v.length, 0))],
50
+ ["MCP", mcp.length ? `${up}/${mcp.length} connected` : undefined],
51
+ ]} />,
52
+ )
53
+ }
54
+
55
+ // ── /usage ───────────────────────────────────────────────────────────
56
+
57
+ const UsageDialog = ({ gw }: { gw: Gateway }) => {
58
+ const theme = useTheme().theme
59
+ const [u, setU] = useState<SessionUsageResponse | null>(null)
60
+ const [err, setErr] = useState("")
61
+ useEffect(() => {
62
+ gw.request<SessionUsageResponse>("session.usage")
63
+ .then(setU).catch(e => setErr(e instanceof Error ? e.message : String(e)))
64
+ }, [gw])
65
+
66
+ if (err) return <InfoDialog title="Usage" rows={[["Error", err, theme.error]]} />
67
+ if (!u) return <InfoDialog title="Usage" rows={[["", "…"]]} />
68
+
69
+ const ctx = u.context_max
70
+ ? `${fmt(u.context_used ?? 0)} / ${fmt(u.context_max)} (${Math.round(u.context_percent ?? 0)}%)`
71
+ : undefined
72
+ return (
73
+ <InfoDialog title="Usage" note={u.cost_status === "estimated" ? "cost is estimated" : undefined} rows={[
74
+ ["Model", u.model || "—"],
75
+ ["API calls", String(u.calls ?? 0)],
76
+ ["Input", fmt(u.input ?? 0)],
77
+ ["Output", fmt(u.output ?? 0)],
78
+ ["Cache r/w", (u.cache_read || u.cache_write) ? `${fmt(u.cache_read ?? 0)} / ${fmt(u.cache_write ?? 0)}` : undefined],
79
+ ["Total", fmt(u.total ?? 0)],
80
+ ["Context", ctx],
81
+ ["Cost", u.cost_usd != null ? cost(u.cost_usd) : undefined, theme.accent],
82
+ ]} />
83
+ )
84
+ }
85
+
86
+ export const openUsage = (dialog: DialogContext, gw: Gateway) =>
87
+ dialog.replace(<UsageDialog gw={gw} />)
88
+
89
+ // ── /profile ─────────────────────────────────────────────────────────
90
+
91
+ const ProfileDialog = () => {
92
+ const [p, setP] = useState<import("../utils/hermes-profiles").ProfileInfo | null | undefined>(undefined)
93
+ const active = activeProfileName()
94
+ useEffect(() => {
95
+ listProfiles().then(ps => setP(ps.find(x => x.name === active) ?? null))
96
+ .catch(() => setP(null))
97
+ }, [])
98
+ if (p === undefined) return <InfoDialog title="Profile" rows={[["", "…"]]} />
99
+ return (
100
+ <InfoDialog title="Profile" note={p ? undefined : "profile directory not found"} rows={[
101
+ ["Active", active],
102
+ ["Home", p?.path ?? hermesPath("")],
103
+ ["Model", p?.model ?? "—"],
104
+ ["Provider", p?.provider ?? "—"],
105
+ ["Skills", p ? String(p.skill_count) : undefined],
106
+ ["Gateway", p?.gateway_running ? "running" : "stopped"],
107
+ ["Sticky", p?.is_sticky ? "yes" : undefined],
108
+ ["Alias", p?.is_default ? undefined : p?.has_alias ? `~/.local/bin/${active}` : "—"],
109
+ [".env", p?.has_env ? "present" : "—"],
110
+ ]} />
111
+ )
112
+ }
113
+
114
+ export const openProfile = (dialog: DialogContext) =>
115
+ dialog.replace(<ProfileDialog />)