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,367 @@
1
+ import { useState, useEffect, useCallback, useMemo, useRef, memo } from "react"
2
+ import { useKeyboard, useTerminalDimensions } from "@opentui/react"
3
+ import type { ScrollBoxRenderable } from "@opentui/core"
4
+ import {
5
+ board, detail, assignees, tailLog, q, STATUSES,
6
+ type Task, type Status, type Detail,
7
+ } from "../utils/hermes-kanban"
8
+ import { useKeys } from "../keys"
9
+ import { useTheme } from "../theme"
10
+ import { useGateway } from "../app/gateway"
11
+ import { useDialog } from "../ui/dialog"
12
+ import { useToast } from "../ui/toast"
13
+ import { DialogSelect } from "../ui/dialog-select"
14
+ import { openConfirm } from "../dialogs/confirm"
15
+ import { openTextPrompt } from "../dialogs/text-prompt"
16
+ import { openCreateTask } from "../dialogs/new-task"
17
+ import { TabShell } from "../ui/shell"
18
+ import { KVBlock } from "../ui/kv"
19
+ import { ago, trunc } from "../ui/fmt"
20
+
21
+ // Operator board for ~/.hermes/kanban.db.
22
+ //
23
+ // Reads are sidecar SQLite. Every write routes through
24
+ // `shell.exec → hermes kanban <verb>` so kanban_db.py owns the state
25
+ // machine (recompute_ready, link-cycle guard, task_events, notify
26
+ // subs) and herm can't drift from the CLI/dashboard.
27
+ //
28
+ // Verbs exposed here cover the human-operator loop from the
29
+ // kanban-orchestrator/worker skills:
30
+ //
31
+ // n create c comment a assign
32
+ // N create-child u unblock (+answer) d archive
33
+ // D dispatch r reload l worker log
34
+ // Enter detail ←→↑↓ nav Esc close pane
35
+
36
+ type Sh = { stdout: string; stderr: string; code: number }
37
+
38
+ const HEAD: Record<Status, string> = {
39
+ triage: "triage", todo: "todo", ready: "ready",
40
+ running: "running", blocked: "blocked", done: "done",
41
+ }
42
+
43
+ const Card = memo((p: { id: string; t: Task; on: boolean; colOn: boolean; onPick: () => void }) => {
44
+ const theme = useTheme().theme
45
+ const fg = p.on ? theme.accent : p.colOn ? theme.text : theme.textMuted
46
+ return (
47
+ <box id={p.id} height={2} flexDirection="column"
48
+ backgroundColor={p.on ? theme.backgroundElement : undefined}
49
+ onMouseDown={p.onPick}>
50
+ <box height={1} overflow="hidden">
51
+ <text>
52
+ <span fg={p.on ? theme.primary : theme.textMuted}>{p.on ? "▸ " : " "}</span>
53
+ <span fg={fg}>{trunc(p.t.title, 60)}</span>
54
+ </text>
55
+ </box>
56
+ <box height={1} overflow="hidden">
57
+ <text fg={theme.textMuted}>
58
+ {` ${p.t.id.slice(0, 8)} ${p.t.assignee ?? "—"}${p.t.priority ? ` P${p.t.priority}` : ""}${p.t.pid ? ` pid ${p.t.pid}` : ""}`}
59
+ </text>
60
+ </box>
61
+ </box>
62
+ )
63
+ })
64
+
65
+ const Column = memo((p: {
66
+ status: Status; tasks: Task[]; on: boolean; sel: number
67
+ onPick: (i: number) => void
68
+ }) => {
69
+ const theme = useTheme().theme
70
+ const box = useRef<ScrollBoxRenderable | null>(null)
71
+ const id = (i: number) => `kb-${p.status}-${i}`
72
+ // Keep the selected card in view. Fires on ↑↓ and on ←→ (p.on flips
73
+ // true) so entering a column that was previously scrolled away snaps
74
+ // to row 0. No-op while this column isn't active.
75
+ useEffect(() => {
76
+ if (p.on && p.tasks.length > 0) box.current?.scrollChildIntoView(id(p.sel))
77
+ }, [p.on, p.sel, p.tasks.length])
78
+ const tint = p.status === "blocked" ? theme.warning
79
+ : p.status === "running" ? theme.success
80
+ : p.status === "done" ? theme.textMuted : theme.primary
81
+ return (
82
+ <box flexDirection="column" flexGrow={1} flexBasis={0} minWidth={20}
83
+ border borderColor={p.on ? theme.primary : theme.border} paddingLeft={1} paddingRight={1}>
84
+ <box height={1}>
85
+ <text>
86
+ <span fg={tint}><strong>{HEAD[p.status]}</strong></span>
87
+ <span fg={theme.textMuted}>{` ${p.tasks.length}`}</span>
88
+ </text>
89
+ </box>
90
+ <scrollbox ref={box} scrollY flexGrow={1}>
91
+ <box flexDirection="column" width="100%">
92
+ {p.tasks.map((t, i) => (
93
+ <Card key={t.id} id={id(i)} t={t} on={p.on && i === p.sel} colOn={p.on}
94
+ onPick={() => p.onPick(i)} />
95
+ ))}
96
+ </box>
97
+ </scrollbox>
98
+ </box>
99
+ )
100
+ })
101
+
102
+ type Pane = { kind: "detail"; d: Detail } | { kind: "log"; id: string; text: string }
103
+
104
+ const SidePane = memo((p: { pane: Pane }) => {
105
+ const { theme, syntaxStyle } = useTheme()
106
+ if (p.pane.kind === "log") return (
107
+ <box flexDirection="column" padding={1} border borderColor={theme.border}
108
+ backgroundColor={theme.backgroundPanel} width="50%">
109
+ <box height={1}><text>
110
+ <span fg={theme.primary}><strong>{p.pane.id}</strong></span>
111
+ <span fg={theme.textMuted}>{" · worker log (tail)"}</span>
112
+ </text></box>
113
+ <box height={1} />
114
+ <scrollbox scrollY flexGrow={1}>
115
+ <text wrapMode="word" fg={theme.textMuted}>{p.pane.text || "(empty)"}</text>
116
+ </scrollbox>
117
+ </box>
118
+ )
119
+ const d = p.pane.d
120
+ return (
121
+ <box flexDirection="column" padding={1} border borderColor={theme.border}
122
+ backgroundColor={theme.backgroundPanel} width="50%">
123
+ <box height={1}>
124
+ <text>
125
+ <span fg={theme.primary}><strong>{d.id}</strong></span>
126
+ <span fg={theme.textMuted}>{` · ${d.status} · ${ago(d.updated_at)}`}</span>
127
+ </text>
128
+ </box>
129
+ <box height={1}><text fg={theme.accent}><strong>{d.title}</strong></text></box>
130
+ <box height={1} />
131
+ <KVBlock rows={[
132
+ ["Assignee", d.assignee ?? "—"],
133
+ ["Priority", d.priority ? `P${d.priority}` : "—"],
134
+ ["Tenant", d.tenant ?? undefined],
135
+ ["Parents", d.parents.length ? d.parents.join(", ") : undefined],
136
+ ["Children", d.children.length ? d.children.join(", ") : undefined],
137
+ ["PID", d.pid ? String(d.pid) : undefined],
138
+ ["Error", d.error ?? undefined, theme.error],
139
+ ]} />
140
+ <box height={1} />
141
+ <scrollbox scrollY flexGrow={1}>
142
+ <box flexDirection="column" width="100%">
143
+ {d.body ? <markdown content={d.body} fg={theme.markdownText} syntaxStyle={syntaxStyle} /> : null}
144
+ {d.result ? <>
145
+ <box height={1} />
146
+ <box height={1}><text fg={theme.textMuted}>Result</text></box>
147
+ <markdown content={d.result} fg={theme.markdownText} syntaxStyle={syntaxStyle} />
148
+ </> : null}
149
+ {d.comments.length > 0 ? <>
150
+ <box height={1} />
151
+ <box height={1}><text fg={theme.textMuted}>{`Comments (${d.comments.length})`}</text></box>
152
+ {d.comments.map((c, i) => (
153
+ <box key={i} flexDirection="column" marginTop={1}>
154
+ <box height={1}><text fg={theme.textMuted}>{`${c.author} · ${ago(c.at)}`}</text></box>
155
+ <text wrapMode="word">{c.body}</text>
156
+ </box>
157
+ ))}
158
+ </> : null}
159
+ </box>
160
+ </scrollbox>
161
+ <box height={1}><text fg={theme.textMuted}>a assign c comment u unblock d archive l log N child</text></box>
162
+ </box>
163
+ )
164
+ })
165
+
166
+ export const Kanban = memo((props: { focused?: boolean }) => {
167
+ const theme = useTheme().theme
168
+ const gw = useGateway()
169
+ const dialog = useDialog()
170
+ const toast = useToast()
171
+ const dims = useTerminalDimensions()
172
+ const keys = useKeys()
173
+
174
+ const [data, setData] = useState(() => board())
175
+ const [col, setCol] = useState(0)
176
+ const [row, setRow] = useState(0)
177
+ const [pane, setPane] = useState<Pane | null>(null)
178
+
179
+ const load = useCallback(() => {
180
+ setData(board())
181
+ setPane(p => p?.kind === "detail" ? (d => d ? { kind: "detail", d } : null)(detail(p.d.id)) : p)
182
+ }, [])
183
+ useEffect(load, [load])
184
+
185
+ // Cheap live-ish refresh while focused AND something is running.
186
+ // `running` changing length recreates the interval; back off to
187
+ // manual `r` when idle — no dispatcher → no row churn.
188
+ const running = data.get("running")?.length ?? 0
189
+ useEffect(() => {
190
+ if (!props.focused || running === 0) return
191
+ const t = setInterval(load, 3000)
192
+ return () => clearInterval(t)
193
+ }, [props.focused, running, load])
194
+
195
+ const total = [...data.values()].reduce((a, v) => a + v.length, 0)
196
+
197
+ // Drop empty columns at narrow widths but never collapse the one
198
+ // the selection is on. An entirely empty board keeps full chrome so
199
+ // the layout reads as a kanban, not a blank slate.
200
+ const cols = useMemo(() => {
201
+ const all = STATUSES.map(s => ({ status: s, tasks: data.get(s) ?? [] }))
202
+ if (dims.width >= 160 || total === 0) return all
203
+ return all.filter((c, i) => c.tasks.length > 0 || i === col)
204
+ }, [data, dims.width, col, total])
205
+
206
+ const cur = cols[Math.min(col, cols.length - 1)]
207
+ const task = cur?.tasks[Math.min(row, (cur?.tasks.length ?? 1) - 1)]
208
+
209
+ // `shell.exec → hermes kanban <verb>`. Non-zero → toast the CLI's
210
+ // own stderr (cycle detected, unknown id, etc). reload on success.
211
+ const sh = useCallback((argv: string, ok?: string) =>
212
+ gw.request<Sh>("shell.exec", { command: `hermes kanban ${argv}` }).then(r => {
213
+ if (r.code !== 0) throw new Error((r.stderr || r.stdout || `exit ${r.code}`).trim())
214
+ if (ok) toast.show({ variant: "success", message: ok })
215
+ load()
216
+ return r.stdout
217
+ }).catch((e: Error) => void toast.show({ variant: "error", message: trunc(e.message, 120) })),
218
+ [gw, toast, load])
219
+
220
+ // ── Actions ────────────────────────────────────────────────────────
221
+
222
+ const live = useRef({ task })
223
+ live.current = { task }
224
+
225
+ const create = useCallback((parent?: Task) =>
226
+ openCreateTask(dialog, {
227
+ assignees: assignees(),
228
+ parent: parent ? { id: parent.id, title: parent.title } : undefined,
229
+ }).then(d => {
230
+ if (!d) return
231
+ const flags = [
232
+ d.assignee ? `--assignee ${q(d.assignee)}` : "",
233
+ d.body ? `--body ${q(d.body)}` : "",
234
+ d.priority ? `--priority ${d.priority}` : "",
235
+ d.parent ? `--parent ${q(d.parent)}` : "",
236
+ ].filter(Boolean).join(" ")
237
+ return sh(`create ${q(d.title)} ${flags}`.trim(),
238
+ `Created${d.assignee ? ` → ${d.assignee}` : ""}`)
239
+ }), [dialog, sh])
240
+
241
+ const assign = useCallback((t: Task) => {
242
+ const opts = [{ title: "(unassigned)", value: "none" },
243
+ ...assignees().map(n => ({ title: n, value: n }))]
244
+ dialog.replace(
245
+ <DialogSelect title={`Assign ${t.id}`} options={opts} current={t.assignee ?? "none"}
246
+ placeholder="Search profiles…"
247
+ onSelect={o => {
248
+ dialog.clear()
249
+ void sh(`assign ${q(t.id)} ${q(o.value)}`,
250
+ o.value === "none" ? `Unassigned ${t.id}` : `${t.id} → ${o.value}`)
251
+ }} />,
252
+ )
253
+ }, [dialog, sh])
254
+
255
+ const comment = useCallback((t: Task) =>
256
+ openTextPrompt(dialog, { title: `Comment on ${t.id}`, label: t.title })
257
+ .then(v => v && sh(`comment ${q(t.id)} ${q(v)} --author user`, "Comment added")),
258
+ [dialog, sh])
259
+
260
+ const unblock = useCallback((t: Task) => {
261
+ if (t.status !== "blocked")
262
+ return void toast.show({ variant: "info", message: `${t.id} is ${t.status}, not blocked` })
263
+ return openTextPrompt(dialog, {
264
+ title: `Unblock ${t.id}`, label: "Answer (posted as comment, then task → ready)",
265
+ }).then(async v => {
266
+ // Comment first so the respawned worker sees the answer in its
267
+ // context (build_worker_context reads the thread). Empty answer
268
+ // still unblocks — operator just wants a retry.
269
+ if (v) await sh(`comment ${q(t.id)} ${q(v)} --author user`)
270
+ return sh(`unblock ${q(t.id)}`, `Unblocked ${t.id}`)
271
+ })
272
+ }, [dialog, sh, toast])
273
+
274
+ const archive = useCallback((t: Task) =>
275
+ openConfirm(dialog, {
276
+ title: "Archive task?", danger: true, yes: "archive",
277
+ body: `${t.id} · ${trunc(t.title, 60)}\n\nMoves to 'archived' and ends any open run. Children stay; their dependency on this task is treated as satisfied.`,
278
+ }).then(ok => { if (ok) void sh(`archive ${q(t.id)}`, `Archived ${t.id}`) }),
279
+ [dialog, sh])
280
+
281
+ const dispatch = useCallback(() => {
282
+ const ready = data.get("ready")?.length ?? 0
283
+ if (ready === 0)
284
+ return void toast.show({ variant: "info", message: "No tasks in 'ready'" })
285
+ return openConfirm(dialog, {
286
+ title: "Dispatch ready tasks?",
287
+ body: `${ready} task${ready === 1 ? "" : "s"} in 'ready'. Spawns one worker per task (one pass).`,
288
+ yes: "dispatch",
289
+ }).then(ok => { if (ok) void sh("dispatch --json", `Dispatched (${ready} ready)`) })
290
+ }, [dialog, sh, toast, data])
291
+
292
+ const showLog = useCallback((t: Task) => {
293
+ const text = tailLog(t.id)
294
+ if (text == null)
295
+ return void toast.show({ variant: "info", message: `No worker log for ${t.id}` })
296
+ setPane({ kind: "log", id: t.id, text })
297
+ }, [toast])
298
+
299
+ // Data-driven verb table. `when` gates availability; anything that
300
+ // needs a selected task reads through `live.current`.
301
+ type Act = { key: string; title: string; when: (t?: Task) => boolean; run: (t?: Task) => void }
302
+ const ACTS = useMemo<Act[]>(() => [
303
+ { key: "n", title: "New task", when: () => true, run: () => void create() },
304
+ { key: "N", title: "New child", when: t => !!t, run: t => void create(t) },
305
+ { key: "a", title: "Assign", when: t => !!t, run: t => assign(t!) },
306
+ { key: "c", title: "Comment", when: t => !!t, run: t => void comment(t!) },
307
+ { key: "u", title: "Unblock", when: t => t?.status === "blocked", run: t => void unblock(t!) },
308
+ { key: "d", title: "Archive", when: t => !!t, run: t => void archive(t!) },
309
+ { key: "l", title: "Worker log", when: t => !!t, run: t => showLog(t!) },
310
+ { key: "D", title: "Dispatch", when: () => true, run: () => void dispatch() },
311
+ ], [create, assign, comment, unblock, archive, showLog, dispatch])
312
+
313
+ useKeyboard((key) => {
314
+ if (!props.focused || dialog.stack.length > 0) return
315
+ if (key.name === "escape" && pane) return setPane(null)
316
+ if (keys.match("list.refresh", key)) return load()
317
+ if (key.name === "left")
318
+ return setCol(c => { const n = Math.max(0, c - 1); setRow(0); return n })
319
+ if (key.name === "right")
320
+ return setCol(c => { const n = Math.min(cols.length - 1, c + 1); setRow(0); return n })
321
+ if (key.name === "up")
322
+ return setRow(r => Math.max(0, r - 1))
323
+ if (key.name === "down")
324
+ return setRow(r => Math.min((cur?.tasks.length ?? 1) - 1, r + 1))
325
+ if (key.name === "return" && task)
326
+ return setPane(p => p?.kind === "detail" && p.d.id === task.id
327
+ ? null : (d => d ? { kind: "detail", d } : null)(detail(task.id)))
328
+ const t = live.current.task
329
+ const hit = ACTS.find(a => a.key === key.raw && a.when(t))
330
+ if (hit) return hit.run(t)
331
+ })
332
+
333
+ const hint = useMemo(() => {
334
+ const t = task
335
+ return ["←→↑↓ nav", "Enter detail",
336
+ ...ACTS.filter(a => a.when(t)).map(a => `${a.key} ${a.title.toLowerCase()}`),
337
+ "r reload"].join(" ")
338
+ }, [ACTS, task])
339
+
340
+ return (
341
+ <box flexDirection="row" flexGrow={1}>
342
+ <TabShell
343
+ title={`Kanban · ${total} task${total === 1 ? "" : "s"}${running ? ` · ${running} running` : ""}`}
344
+ hint={hint}
345
+ >
346
+ <box flexDirection="row" flexGrow={1} gap={1}>
347
+ {cols.map((c, i) => (
348
+ <Column key={c.status} status={c.status} tasks={c.tasks}
349
+ on={i === Math.min(col, cols.length - 1)} sel={row}
350
+ onPick={r => {
351
+ setCol(i); setRow(r)
352
+ const d = detail(c.tasks[r].id)
353
+ if (d) setPane({ kind: "detail", d })
354
+ }} />
355
+ ))}
356
+ </box>
357
+ {total === 0 && (
358
+ <box flexDirection="column" marginTop={1}>
359
+ <text fg={theme.textMuted}>no tasks — board at ~/.hermes/kanban.db</text>
360
+ <text fg={theme.textMuted}>press <span fg={theme.accent}>n</span> to create one</text>
361
+ </box>
362
+ )}
363
+ </TabShell>
364
+ {pane ? <SidePane pane={pane} /> : null}
365
+ </box>
366
+ )
367
+ })
@@ -0,0 +1,294 @@
1
+ import { useState, memo } from "react"
2
+ import type { MemoryProviderInfo, MemoryFileInfo } from "../utils/hermes-home"
3
+ import type { MemoryActivity } from "../utils/memory-activity"
4
+ import { useHome, home } from "../home"
5
+ import { ago } from "../ui/fmt"
6
+ import { useTheme, type Theme } from "../theme"
7
+ import { useListKeys } from "../keys"
8
+ import { useDialog } from "../ui/dialog"
9
+ import { useToast } from "../ui/toast"
10
+ import { useGateway } from "../app/gateway"
11
+ import { openConfirm } from "../dialogs/confirm"
12
+ import { TabShell } from "../ui/shell"
13
+ import { KVBlock } from "../ui/kv"
14
+
15
+ // ─── Helpers ──────────────────────────────────────────────────────────
16
+
17
+ function usageColor(pct: number, theme: Theme): string {
18
+ if (pct >= 95) return theme.error.toString()
19
+ if (pct >= 80) return theme.warning.toString()
20
+ return theme.success.toString()
21
+ }
22
+
23
+ function bar(pct: number, w: number): string {
24
+ const filled = Math.round((pct / 100) * w)
25
+ return "█".repeat(filled) + "░".repeat(w - filled)
26
+ }
27
+
28
+ const DESC: Record<string, string> = {
29
+ builtin: "File-based §-delimited entries (MEMORY.md + USER.md). Always active.",
30
+ mem0: "Server-side LLM fact extraction with semantic search and reranking.",
31
+ honcho: "AI-native cross-session user modeling with dialectic Q&A.",
32
+ hindsight: "Knowledge graph with entity resolution and multi-strategy retrieval.",
33
+ holographic: "Local SQLite fact store with FTS5, trust scoring, HRR retrieval.",
34
+ openviking: "Session-managed memory with tiered retrieval.",
35
+ retaindb: "Cloud memory API with hybrid search and 7 memory types.",
36
+ byterover: "Persistent knowledge tree via brv CLI.",
37
+ supermemory: "Semantic long-term memory with profile recall and session ingest.",
38
+ }
39
+
40
+ // ─── Component ────────────────────────────────────────────────────────
41
+
42
+ export const Memory = memo((props: { focused?: boolean }) => {
43
+ const theme = useTheme().theme
44
+ const dialog = useDialog()
45
+ const toast = useToast()
46
+ const gw = useGateway()
47
+ const [sel, setSel] = useState(0)
48
+
49
+ const config = useHome("config")
50
+ const memory = useHome("memory")
51
+ const userProfile = useHome("userProfile")
52
+ const providers = useHome("memoryProviders") ?? []
53
+ const activity = useHome("memoryActivity") ?? []
54
+
55
+ const cfg = config?.memory
56
+ const active = cfg?.provider || ""
57
+
58
+ const cur = providers[sel]
59
+ const on = !!cur && (cur.name === "builtin" || cur.name === active)
60
+
61
+ // Activate/deactivate writes memory.provider to disk via cli.exec
62
+ // (the gateway's config.set whitelist doesn't include it, so the RPC
63
+ // path 4002s). Applies on the next session — the running agent keeps
64
+ // the provider it was constructed with.
65
+ const toggle = async () => {
66
+ if (!cur || cur.name === "builtin") return
67
+ const isOn = cur.name === active
68
+ const ok = await openConfirm(dialog, {
69
+ title: isOn ? "Deactivate memory provider?" : "Activate memory provider?",
70
+ body: isOn
71
+ ? `Clear '${cur.name}' as the active provider (revert to built-in only).`
72
+ : `Set '${cur.name}' as the active provider. Ensure required env vars are set (Env tab).`,
73
+ yes: isOn ? "deactivate" : "activate",
74
+ })
75
+ if (!ok) return
76
+ const { writeConfig } = await import("../config/lane")
77
+ const r = await writeConfig(gw, [{ key: "memory.provider", to: isOn ? "" : cur.name }])
78
+ if (r.failed.length) return toast.show({ variant: "error", message: r.failed[0].err })
79
+ home.invalidate("config")
80
+ home.invalidate("memoryProviders")
81
+ toast.show({ variant: "success", message: isOn ? "Deactivated" : `Activated ${cur.name} — new sessions pick this up` })
82
+ }
83
+
84
+ const keys = useListKeys({
85
+ active: !!props.focused && dialog.stack.length === 0,
86
+ count: providers.length, setSel,
87
+ onToggle: toggle,
88
+ onRefresh: () => {
89
+ home.invalidate("memoryProviders")
90
+ home.invalidate("memoryActivity")
91
+ toast.show({ variant: "info", message: "Reloaded", duration: 1000 })
92
+ },
93
+ })
94
+
95
+ const feed = !cur ? []
96
+ : cur.name === "builtin" ? activity
97
+ : activity.filter(a => a.provider === cur.name)
98
+
99
+ return (
100
+ <box flexDirection="row" flexGrow={1}>
101
+ <TabShell title="Memory Providers" grow={1}
102
+ hint={`${keys.print("list.up")}${keys.print("list.down")} select ${keys.print("list.toggle")} activate`}>
103
+ <scrollbox scrollY flexGrow={1}>
104
+ {providers.map((p, i) => {
105
+ const pOn = p.name === "builtin" || p.name === active
106
+ const has = Object.keys(p.config).length > 0
107
+ const dot = pOn ? "●" : has ? "◐" : "○"
108
+ const fg = pOn ? theme.success : has ? theme.warning : theme.textMuted
109
+ const tag = pOn ? "active" : has ? "configured" : ""
110
+ return (
111
+ <box
112
+ key={p.name}
113
+ flexDirection="column"
114
+ marginBottom={1}
115
+ backgroundColor={i === sel ? theme.backgroundElement : undefined}
116
+ onMouseDown={() => setSel(i)}
117
+ onMouseMove={() => setSel(i)}
118
+ >
119
+ <box height={1}>
120
+ <text>
121
+ <span fg={fg}>{dot} </span>
122
+ <span fg={i === sel ? theme.accent : theme.text}>{p.name}</span>
123
+ {tag ? <span fg={fg}> ({tag})</span> : null}
124
+ </text>
125
+ </box>
126
+ <box height={1} overflow="hidden" paddingLeft={2}>
127
+ <text fg={theme.textMuted}>{DESC[p.name] || "—"}</text>
128
+ </box>
129
+ </box>
130
+ )
131
+ })}
132
+ </scrollbox>
133
+ </TabShell>
134
+
135
+ <TabShell
136
+ title={cur?.name ?? "Provider"}
137
+ hint={on ? "● active" : "○ inactive"}
138
+ grow={2}
139
+ >
140
+ {cur ? (
141
+ <ProviderDetail provider={cur} active={active} cfg={cfg}
142
+ memory={memory} userProfile={userProfile} feed={feed} />
143
+ ) : (
144
+ <text fg={theme.textMuted}>Select a provider</text>
145
+ )}
146
+ </TabShell>
147
+ </box>
148
+ )
149
+ })
150
+
151
+ // ─── Provider Detail ──────────────────────────────────────────────────
152
+
153
+ type MemoryCfg = {
154
+ memory_enabled: boolean
155
+ user_profile_enabled: boolean
156
+ memory_char_limit: number
157
+ user_char_limit: number
158
+ provider: string
159
+ nudge_interval: number
160
+ flush_min_turns: number
161
+ }
162
+
163
+ const ProviderDetail = memo((props: {
164
+ provider: MemoryProviderInfo
165
+ active: string
166
+ cfg: MemoryCfg | undefined
167
+ memory: MemoryFileInfo | null | undefined
168
+ userProfile: MemoryFileInfo | null | undefined
169
+ feed: MemoryActivity[]
170
+ }) => {
171
+ const theme = useTheme().theme
172
+ const p = props.provider
173
+ const on = p.name === "builtin" || p.name === props.active
174
+
175
+ return (
176
+ <scrollbox scrollY flexGrow={1}>
177
+ <box flexDirection="column">
178
+ <box minHeight={1}>
179
+ <text wrapMode="word" fg={theme.textMuted}>{DESC[p.name] || "Memory provider"}</text>
180
+ </box>
181
+ <box height={1} />
182
+
183
+ {p.name === "builtin" ? (
184
+ <box flexDirection="column">
185
+ {props.cfg ? (
186
+ <>
187
+ <KVBlock rows={[
188
+ ["Notes", props.cfg.memory_enabled ? "enabled" : "disabled",
189
+ props.cfg.memory_enabled ? theme.success : theme.error],
190
+ ["Profile", props.cfg.user_profile_enabled ? "enabled" : "disabled",
191
+ props.cfg.user_profile_enabled ? theme.success : theme.error],
192
+ ]} />
193
+ <box height={1} />
194
+ </>
195
+ ) : null}
196
+ <CapacityBar title="Notes (MEMORY.md)" info={props.memory ?? null} />
197
+ <box height={1} />
198
+ <CapacityBar title="Profile (USER.md)" info={props.userProfile ?? null} />
199
+ </box>
200
+ ) : null}
201
+
202
+ {p.name !== "builtin" && on && props.cfg ? (
203
+ <>
204
+ <box height={1}><text fg={theme.accent}><strong>Agent Settings</strong></text></box>
205
+ <KVBlock rows={[
206
+ ["Nudge", `every ${props.cfg.nudge_interval} turns`],
207
+ ["Flush", `after ${props.cfg.flush_min_turns} turns`],
208
+ ]} />
209
+ <box height={1} />
210
+ </>
211
+ ) : null}
212
+
213
+ {Object.keys(p.config).length > 0 ? (
214
+ <>
215
+ <box height={1}><text fg={theme.accent}><strong>Local Configuration</strong></text></box>
216
+ <KVBlock rows={Object.entries(p.config).map(([k, v]) => [k, String(v)] as [string, string])} />
217
+ </>
218
+ ) : p.name !== "builtin" ? (
219
+ <box height={1} marginTop={1}>
220
+ <text fg={theme.textMuted}>No local config found. Run `hermes memory setup` to configure.</text>
221
+ </box>
222
+ ) : null}
223
+
224
+ <ActivityFeed items={props.feed} own={p.name} />
225
+ </box>
226
+ </scrollbox>
227
+ )
228
+ })
229
+
230
+ // ─── Activity Feed ────────────────────────────────────────────────────
231
+
232
+ const OP_GLYPH = { write: "+", read: "?" } as const
233
+
234
+ const ActivityFeed = memo((props: { items: MemoryActivity[]; own: string }) => {
235
+ const theme = useTheme().theme
236
+ const all = props.own === "builtin"
237
+ const nW = props.items.filter(a => a.op === "write").length
238
+ return (
239
+ <box flexDirection="column" marginTop={1}>
240
+ <box height={1}>
241
+ <text>
242
+ <span fg={theme.accent}><strong>Recent Activity</strong></span>
243
+ {props.items.length
244
+ ? <span fg={theme.textMuted}> · {nW} writes, {props.items.length - nW} reads</span>
245
+ : null}
246
+ </text>
247
+ </box>
248
+ {props.items.length === 0 ? (
249
+ <box height={1}>
250
+ <text fg={theme.textMuted}>No memory-tool calls in the last ~2000 messages</text>
251
+ </box>
252
+ ) : null}
253
+ {props.items.map((a, i) => (
254
+ <box key={i} height={1} flexDirection="row" overflow="hidden">
255
+ <text>
256
+ <span fg={a.op === "write" ? theme.success : theme.textMuted}>{OP_GLYPH[a.op]} </span>
257
+ <span fg={theme.textMuted}>{ago(a.ts).padEnd(8)}</span>
258
+ {all && a.provider !== "builtin"
259
+ ? <span fg={theme.primary}>{a.provider}·</span>
260
+ : null}
261
+ <span fg={theme.text}>{a.verb}</span>
262
+ <span fg={theme.textMuted}> {a.summary}</span>
263
+ </text>
264
+ </box>
265
+ ))}
266
+ </box>
267
+ )
268
+ })
269
+
270
+ // ─── Capacity Bar ─────────────────────────────────────────────────────
271
+
272
+ const CapacityBar = memo((props: { title: string; info: MemoryFileInfo | null }) => {
273
+ const theme = useTheme().theme
274
+ if (!props.info) {
275
+ return <box height={1}><text fg={theme.textMuted}>{props.title}: unavailable</text></box>
276
+ }
277
+ const color = usageColor(props.info.usagePercent, theme)
278
+ return (
279
+ <box flexDirection="column">
280
+ <box height={1}>
281
+ <text>
282
+ <span fg={theme.text}>{props.title}</span>
283
+ <span fg={theme.textMuted}> · {props.info.entryCount} entries</span>
284
+ </text>
285
+ </box>
286
+ <box height={1}>
287
+ <text>
288
+ <span fg={color}>{bar(props.info.usagePercent, 20)}</span>
289
+ <span fg={theme.textMuted}> {props.info.charCount}/{props.info.charLimit} ({props.info.usagePercent}%)</span>
290
+ </text>
291
+ </box>
292
+ </box>
293
+ )
294
+ })