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,143 @@
1
+ import { useState, memo, type ReactNode } from "react"
2
+ import { AnimatedAvatar } from "../avatar/AnimatedAvatar"
3
+ import type { ParsedEikon } from "../avatar/eikon"
4
+ import { useTheme } from "../../theme"
5
+ import type { AvatarState } from "../avatar/states"
6
+ import type { SessionInfo } from "../../utils/gateway-types"
7
+ import type { Usage } from "../../types/message"
8
+ import { useGitBranch, rtrunc } from "../../utils/git"
9
+ import { Tail } from "../chat/ThoughtCloud"
10
+ import { ContextGauge } from "./ContextGauge"
11
+
12
+ // The pillar body carries a compact identity block, the MCP operational
13
+ // section, and a context-usage gauge at the bottom. Stats/Memory/Recent/
14
+ // Identity wrapper and the Plugins section were removed — they duplicated
15
+ // dedicated tabs and cluttered the most-visible surface.
16
+
17
+ const WIDTH = 48
18
+ const PAD_L = 12
19
+
20
+ const trunc = (s: string, max: number) => s.length <= max ? s : s.slice(0, max - 1) + "…"
21
+
22
+ // ─── Primitives (pillar-colored) ─────────────────────────────────────
23
+
24
+ const Section = memo((props: {
25
+ title: string; hint?: string
26
+ open: boolean; onToggle: () => void
27
+ children: ReactNode
28
+ }) => {
29
+ const theme = useTheme().theme
30
+ const [hover, setHover] = useState(false)
31
+ return (
32
+ <box flexDirection="column" marginBottom={props.open ? 1 : 0}>
33
+ <box height={1}
34
+ onMouseDown={props.onToggle}
35
+ onMouseOver={() => setHover(true)}
36
+ onMouseOut={() => setHover(false)}>
37
+ <text>
38
+ <span fg={hover ? theme.hermBodyText : theme.hermBodyTextMuted}>
39
+ {props.open ? "▾ " : "▸ "}
40
+ </span>
41
+ <span fg={theme.hermBodyText}><strong>{props.title}</strong></span>
42
+ {props.hint ? <span fg={theme.hermBodyTextMuted}>{` ${props.hint}`}</span> : null}
43
+ </text>
44
+ </box>
45
+ {props.open ? <box flexDirection="column">{props.children}</box> : null}
46
+ </box>
47
+ )
48
+ })
49
+
50
+ const Row = (props: { label: string; value: string; strong?: boolean }) => {
51
+ const theme = useTheme().theme
52
+ return (
53
+ <box height={1}>
54
+ <text>
55
+ <span fg={theme.hermBodyTextMuted}>{` ${props.label.padEnd(PAD_L)}`}</span>
56
+ {props.strong
57
+ ? <span fg={theme.hermBodyText}><strong>{trunc(props.value, WIDTH - PAD_L - 4)}</strong></span>
58
+ : <span fg={theme.hermBodyText}>{trunc(props.value, WIDTH - PAD_L - 4)}</span>}
59
+ </text>
60
+ </box>
61
+ )
62
+ }
63
+
64
+ // ─── Main ────────────────────────────────────────────────────────────
65
+
66
+ export const Sidebar = memo((props: {
67
+ agentState?: AvatarState
68
+ info?: SessionInfo | null
69
+ usage?: Usage
70
+ eikon?: ParsedEikon
71
+ profile?: string
72
+ title?: string
73
+ cloud?: boolean
74
+ pulse?: boolean
75
+ onAvatar?: () => void
76
+ }) => {
77
+ const theme = useTheme().theme
78
+ const state = props.agentState ?? "idle"
79
+ const info = props.info
80
+
81
+ const [mcpOpen, setMcpOpen] = useState(false)
82
+
83
+ const cwd = info?.cwd ?? process.cwd()
84
+ const branch = useGitBranch(cwd)
85
+
86
+ return (
87
+ <box width={WIDTH} flexDirection="column">
88
+ {/* Avatar (bust) — also the anchor for the thought-cloud tail */}
89
+ <box position="relative" flexDirection="column" height={24} overflow="hidden"
90
+ onMouseDown={props.onAvatar}>
91
+ <AnimatedAvatar state={state} eikon={props.eikon} />
92
+ {props.cloud ? (
93
+ <box position="absolute" left={0} top={0}>
94
+ <Tail run={!!props.pulse} />
95
+ </box>
96
+ ) : null}
97
+ </box>
98
+
99
+ {/* Body (pillar) */}
100
+ <box padding={1} flexDirection="column" flexGrow={1}
101
+ backgroundColor={theme.hermBody} overflow="hidden">
102
+
103
+ {/* Flat identity block — Title is primary (always rendered so the
104
+ block doesn't reflow when `/title` fires), then Profile
105
+ (which IS agent lineage — each profile is an isolated
106
+ HERMES_HOME), then model/cwd/branch. */}
107
+ <Row label="Title" value={props.title || "—"} strong={!!props.title} />
108
+ <Row label="Profile" value={props.profile ?? "default"}
109
+ strong={!!props.profile && props.profile !== "default"} />
110
+ <Row label="Model" value={info?.model ?? "—"} />
111
+ {info?.cwd ? <Row label="cwd" value={info.cwd} /> : null}
112
+ {branch ? <Row label="Branch" value={rtrunc(branch, WIDTH - PAD_L - 4)} /> : null}
113
+
114
+ {(info?.mcp_servers?.length ?? 0) > 0 ? (() => {
115
+ const srv = info!.mcp_servers!
116
+ const ok = srv.filter(s => s.connected).length
117
+ return (
118
+ <Section title="MCP"
119
+ hint={`${ok}/${srv.length} up`}
120
+ open={mcpOpen} onToggle={() => setMcpOpen(o => !o)}>
121
+ {srv.map(s => (
122
+ <box key={s.name} height={1}>
123
+ <text>
124
+ <span fg={theme.hermBodyTextMuted}>{" "}</span>
125
+ <span fg={s.connected ? theme.hermBodyText : theme.hermBodyTextMuted}>
126
+ {(s.connected ? "● " : "○ ") + trunc(s.name, 16).padEnd(16)}
127
+ </span>
128
+ <span fg={theme.hermBodyTextMuted}>
129
+ {s.connected ? ` ${s.transport} · ${s.tools}t` : " failed"}
130
+ </span>
131
+ </text>
132
+ </box>
133
+ ))}
134
+ </Section>
135
+ )
136
+ })() : null}
137
+
138
+ <box flexGrow={1} />
139
+ <ContextGauge info={info} usage={props.usage} width={WIDTH - 4} />
140
+ </box>
141
+ </box>
142
+ )
143
+ })
@@ -0,0 +1,50 @@
1
+ import { memo } from "react"
2
+ import { useTheme } from "../../theme"
3
+ import { useKeys } from "../../keys"
4
+
5
+ type Tab = {
6
+ name: string
7
+ description: string
8
+ }
9
+
10
+ type TabBarProps = {
11
+ tabs: ReadonlyArray<Tab>
12
+ activeTab: number
13
+ onTabChange: (index: number) => void
14
+ }
15
+
16
+ // 1..9, 0, - — mirrors the <leader>+digit map in useAppKeys.
17
+ const idx = (i: number) => i < 9 ? String(i + 1) : i === 9 ? "0" : "-"
18
+
19
+ export const TabBar = memo(({ tabs, activeTab, onTabChange }: TabBarProps) => {
20
+ const theme = useTheme().theme
21
+ const keys = useKeys()
22
+
23
+ return (
24
+ <box width="100%" flexDirection="column" height={1}>
25
+ <box flexDirection="row" overflow="hidden">
26
+ {tabs.map((tab, i) => (
27
+ <box
28
+ key={i}
29
+ onMouseDown={() => onTabChange(i)}
30
+ paddingX={2}
31
+ marginRight={1}
32
+ flexShrink={0}
33
+ backgroundColor={i === activeTab ? theme.backgroundElement : undefined}
34
+ >
35
+ <text attributes={3}>
36
+ <span fg={theme.borderSubtle}>{idx(i)} </span>
37
+ <span fg={i === activeTab ? theme.primary : theme.textMuted}>{tab.name}</span>
38
+ </text>
39
+ </box>
40
+ ))}
41
+ <box flexGrow={1} minWidth={0} />
42
+ <box paddingX={1} flexShrink={1} minWidth={0} overflow="hidden">
43
+ <text fg={theme.borderSubtle}>
44
+ {`${keys.print("tab.prev")}/${keys.print("tab.next")} or ${keys.print("leader")} N`}
45
+ </text>
46
+ </box>
47
+ </box>
48
+ </box>
49
+ )
50
+ })
@@ -0,0 +1,52 @@
1
+ /**
2
+ * FileLink — Generic clickable file reference.
3
+ *
4
+ * Wraps in a box for mouse hit-testing. Opens the source file
5
+ * in the OS default handler when clicked. Underlines on hover.
6
+ */
7
+
8
+ import { useState, memo } from "react";
9
+ import { TextAttributes } from "@opentui/core";
10
+ import type { Source } from "../../utils/hermes-home";
11
+ import { openFile } from "../../utils/open-file";
12
+ import { useTheme } from "../../theme";
13
+
14
+ interface FileLinkProps {
15
+ source: Source;
16
+ children?: string;
17
+ }
18
+
19
+ export const FileLink = memo(({ source, children }: FileLinkProps) => {
20
+ const theme = useTheme().theme;
21
+ const [hovered, setHovered] = useState(false);
22
+
23
+ return (
24
+ <box
25
+ height={1}
26
+ onMouseDown={() => openFile(source.file)}
27
+ onMouseOver={() => setHovered(true)}
28
+ onMouseOut={() => setHovered(false)}
29
+ >
30
+ <text
31
+ fg={theme.info}
32
+ attributes={hovered ? TextAttributes.UNDERLINE : TextAttributes.NONE}
33
+ >
34
+ {children ?? source.label}
35
+ </text>
36
+ </box>
37
+ );
38
+ });
39
+
40
+ // KV row whose value is a clickable FileLink. Lives beside FileLink
41
+ // rather than in ui/kv so that module stays free of data-layer deps.
42
+ export const KVLink = (props: { label: string; source: Source; text?: string }) => {
43
+ const theme = useTheme().theme;
44
+ return (
45
+ <box height={1} flexDirection="row">
46
+ <box width={13} flexShrink={0}><text fg={theme.textMuted}>{props.label}</text></box>
47
+ <box flexGrow={1} minWidth={0} height={1} overflow="hidden">
48
+ <FileLink source={props.source}>{props.text ?? props.source.label}</FileLink>
49
+ </box>
50
+ </box>
51
+ );
52
+ };
@@ -0,0 +1,156 @@
1
+ import { SCHEMA, SCHEMA_KEYS, type ConfigEffect } from "./schema"
2
+ import { route } from "./lane"
3
+
4
+ export type FieldType = "boolean" | "select" | "number" | "string" | "readonly"
5
+
6
+ export type Field = {
7
+ key: string
8
+ label: string
9
+ type: FieldType
10
+ value: unknown
11
+ /** True when the user's config.yaml has this key; false when
12
+ * falling through to the schema default. */
13
+ set: boolean
14
+ doc: string
15
+ effect: ConfigEffect
16
+ options?: string[]
17
+ }
18
+
19
+ // Enum-valued string fields the schema doesn't carry options for.
20
+ // Kept minimal — most enums are validated by rules.ts on commit; these
21
+ // are the ones worth cycling with [h/l] instead of free-typing.
22
+ const SELECTS: Record<string, string[]> = {
23
+ "terminal.backend": ["local", "docker", "ssh", "modal", "daytona", "singularity", "vercel_sandbox"],
24
+ "tts.provider": ["edge", "elevenlabs", "openai", "neutts", "xai", "mistral"],
25
+ "display.skin": ["default", "ares", "mono", "slate"],
26
+ "logging.level": ["DEBUG", "INFO", "WARNING", "ERROR"],
27
+ "agent.reasoning_effort": ["", "none", "minimal", "low", "medium", "high", "xhigh"],
28
+ "display.busy_input_mode": ["queue", "steer", "interrupt"],
29
+ "display.details_mode": ["hidden", "collapsed", "expanded"],
30
+ "display.thinking_mode": ["collapsed", "truncated", "full"],
31
+ "display.tool_progress": ["off", "new", "all", "verbose"],
32
+ "approvals.mode": ["manual", "ask", "yolo", "deny"],
33
+ }
34
+
35
+ const get = (obj: Record<string, unknown>, path: string): unknown => {
36
+ let cur: unknown = obj
37
+ for (const p of path.split(".")) {
38
+ if (cur && typeof cur === "object" && !Array.isArray(cur)) cur = (cur as Record<string, unknown>)[p]
39
+ else return undefined
40
+ }
41
+ return cur
42
+ }
43
+
44
+ const classify = (key: string, t: string): FieldType => {
45
+ if (route(key).via === "readonly") return "readonly"
46
+ if (SELECTS[key]) return "select"
47
+ if (t === "bool") return "boolean"
48
+ if (t === "int" || t === "float") return "number"
49
+ return "string"
50
+ }
51
+
52
+ const labelOf = (key: string): string => {
53
+ const raw = SCHEMA[key]?.group ?? key.split(".")[0]
54
+ return key.startsWith(`${raw}.`) ? key.slice(raw.length + 1) : key
55
+ }
56
+
57
+ /** Build the full field model: every schema key, value = user-set
58
+ * else default, plus any user keys the schema doesn't know about
59
+ * (so surprises in config.yaml still surface). */
60
+ export const buildFields = (user: Record<string, unknown>): Field[] => {
61
+ const seen = new Set<string>()
62
+ const out: Field[] = []
63
+
64
+ for (const key of SCHEMA_KEYS) {
65
+ const s = SCHEMA[key]
66
+ const uv = get(user, key)
67
+ const set = uv !== undefined
68
+ out.push({
69
+ key,
70
+ label: labelOf(key),
71
+ type: classify(key, s.type),
72
+ value: set ? uv : s.default,
73
+ set,
74
+ doc: s.doc,
75
+ effect: s.effect,
76
+ options: SELECTS[key],
77
+ })
78
+ seen.add(key)
79
+ }
80
+
81
+ // Unknown user keys (future agent version, hand-edits, plugins).
82
+ const walk = (obj: Record<string, unknown>, prefix = "") => {
83
+ for (const [k, v] of Object.entries(obj)) {
84
+ const key = prefix ? `${prefix}.${k}` : k
85
+ if (v && typeof v === "object" && !Array.isArray(v)) {
86
+ // Don't recurse into a dict that's itself a known readonly leaf.
87
+ if (SCHEMA[key]?.type === "dict") { seen.add(key); continue }
88
+ walk(v as Record<string, unknown>, key)
89
+ continue
90
+ }
91
+ if (seen.has(key)) continue
92
+ out.push({
93
+ key,
94
+ label: labelOf(key),
95
+ type: Array.isArray(v) ? "readonly"
96
+ : typeof v === "boolean" ? "boolean"
97
+ : typeof v === "number" ? "number"
98
+ : "string",
99
+ value: v, set: true, doc: "", effect: "live",
100
+ })
101
+ }
102
+ }
103
+ walk(user)
104
+
105
+ return out
106
+ }
107
+
108
+ // Small/satellite groups fold into a parent. This is a UX decision,
109
+ // not derivable from source — keeps the sidebar to ~18 entries instead
110
+ // of 34 with a dozen 1-field groups.
111
+ const MERGE: Record<string, string> = {
112
+ approvals: "security", privacy: "security",
113
+ checkpoints: "agent", context: "agent", cron: "agent", network: "agent",
114
+ model_catalog: "general", onboarding: "general",
115
+ human_delay: "display", dashboard: "display",
116
+ tool_output: "agent", prompt_caching: "compression", code_execution: "terminal",
117
+ slack: "platforms", telegram: "platforms", mattermost: "platforms",
118
+ discord: "platforms", whatsapp: "platforms",
119
+ }
120
+
121
+ export const rawGroupOf = (key: string): string =>
122
+ SCHEMA[key]?.group ?? (key.includes(".") ? key.split(".")[0] : "general")
123
+
124
+ export const groupOf = (key: string): string => {
125
+ const raw = rawGroupOf(key)
126
+ return MERGE[raw] ?? raw
127
+ }
128
+
129
+ export type Section = { head: string | null; items: Field[] }
130
+
131
+ /** Chunk a merged-group field list by its raw (pre-merge) groups so the
132
+ * UI can render sub-headers. Single-chunk → head=null. Multi-chunk →
133
+ * the self-named chunk (raw === merged name) floats to the front. */
134
+ export const sections = (group: string, fields: Field[]): Section[] => {
135
+ const by = new Map<string, Field[]>()
136
+ for (const f of fields) {
137
+ const r = rawGroupOf(f.key)
138
+ if (!by.has(r)) by.set(r, [])
139
+ by.get(r)!.push(f)
140
+ }
141
+ if (by.size <= 1) return [{ head: null, items: fields }]
142
+ const order = [...by.keys()].sort((a, b) =>
143
+ a === group ? -1 : b === group ? 1 : a.localeCompare(b))
144
+ return order.map(r => ({ head: r, items: by.get(r)! }))
145
+ }
146
+
147
+ /** Distinct groups in schema after merging, 'general' pinned first. */
148
+ export const GROUPS: string[] = (() => {
149
+ const g = new Set<string>(["general"])
150
+ for (const k of SCHEMA_KEYS) g.add(groupOf(k))
151
+ return [...g]
152
+ })()
153
+
154
+ export const EFFECT_GLYPH: Record<ConfigEffect, string> = {
155
+ live: "", session: "↻", restart: "⟳",
156
+ }
@@ -0,0 +1,161 @@
1
+ import { SCHEMA, type ConfigSchemaEntry, type ConfigEffect } from "./schema"
2
+
3
+ // ─── RPC alias map ───────────────────────────────────────────────────
4
+ //
5
+ // `config.set` on the gateway accepts a short whitelist of ALIAS keys,
6
+ // not dotted paths (anything else → 4002). Several of these mutate the
7
+ // live agent in place (reasoning effort, model, tool verbosity, …), so
8
+ // routing those through the RPC lane is what makes Config-tab edits
9
+ // apply to the running conversation without a new session.
10
+
11
+ type RpcAlias = {
12
+ alias: string
13
+ /** Map the schema-typed value to the wire value the alias expects. */
14
+ toWire?: (v: unknown) => string
15
+ }
16
+
17
+ const onOff = (v: unknown) => (v ? "on" : "off")
18
+
19
+ export const RPC_ALIAS: Record<string, RpcAlias> = {
20
+ model: { alias: "model" },
21
+ provider: { alias: "model" },
22
+ "agent.service_tier": { alias: "fast" },
23
+ "agent.reasoning_effort": { alias: "reasoning" },
24
+ "display.show_reasoning": { alias: "reasoning", toWire: v => (v ? "show" : "hide") },
25
+ "display.tool_progress": { alias: "verbose" },
26
+ "display.busy_input_mode": { alias: "busy" },
27
+ "display.details_mode": { alias: "details_mode" },
28
+ "display.thinking_mode": { alias: "thinking_mode" },
29
+ "display.tui_compact": { alias: "compact", toWire: onOff },
30
+ "display.tui_statusbar": { alias: "statusbar" },
31
+ "display.tui_mouse": { alias: "mouse", toWire: onOff },
32
+ "display.skin": { alias: "skin" },
33
+ "display.personality": { alias: "personality" },
34
+ custom_prompt: { alias: "prompt" },
35
+ }
36
+
37
+ // ─── lane routing ────────────────────────────────────────────────────
38
+
39
+ export type Lane =
40
+ | { via: "rpc"; alias: string; toWire?: (v: unknown) => string }
41
+ | { via: "cli" }
42
+ | { via: "readonly" }
43
+
44
+ export const route = (key: string): Lane => {
45
+ const a = RPC_ALIAS[key]
46
+ if (a) return { via: "rpc", alias: a.alias, toWire: a.toWire }
47
+ if (key.startsWith("display.sections."))
48
+ return { via: "rpc", alias: `details_mode.${key.slice("display.sections.".length)}` }
49
+ const s = SCHEMA[key]
50
+ if (s && (s.type === "list" || s.type === "dict")) return { via: "readonly" }
51
+ return { via: "cli" }
52
+ }
53
+
54
+ // ─── value coercion for cli.exec ─────────────────────────────────────
55
+ //
56
+ // `hermes config set` parses the string argv[2] with heuristics
57
+ // (true/false/on/off/yes/no → bool, all-digits → int, digits.digits →
58
+ // float, else raw string). We pre-format so the heuristic lands on the
59
+ // schema's declared type — in particular, a str-typed field whose
60
+ // value *looks* numeric stays a string by going through the cli raw.
61
+
62
+ export const toCliString = (key: string, v: unknown): string => {
63
+ const t: ConfigSchemaEntry["type"] = SCHEMA[key]?.type ?? "str"
64
+ if (t === "bool") return v ? "true" : "false"
65
+ if (t === "int") return String(Math.trunc(Number(v)))
66
+ if (t === "float") return String(Number(v))
67
+ return String(v ?? "")
68
+ }
69
+
70
+ // ─── write engine ────────────────────────────────────────────────────
71
+
72
+ export type Diff = { key: string; to: unknown }
73
+ export type WriteResult = {
74
+ ok: string[]
75
+ failed: { key: string; err: string }[]
76
+ warnings: { key: string; msg: string }[]
77
+ }
78
+
79
+ type Gw = {
80
+ request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>
81
+ }
82
+
83
+ /** Apply a batch of config edits, routing each through its lane. RPC
84
+ * calls run first (they may refuse with a structured error and carry
85
+ * optional `warning`), then cli calls run serially — each one rewrites
86
+ * the whole config file, so Promise.all would last-write-wins. */
87
+ export const writeConfig = async (gw: Gw, diffs: Diff[]): Promise<WriteResult> => {
88
+ const ok: string[] = []
89
+ const failed: WriteResult["failed"] = []
90
+ const warnings: WriteResult["warnings"] = []
91
+
92
+ const rpc = diffs.filter(d => route(d.key).via === "rpc")
93
+ const cli = diffs.filter(d => route(d.key).via === "cli")
94
+ const ro = diffs.filter(d => route(d.key).via === "readonly")
95
+ for (const d of ro) failed.push({ key: d.key, err: "structured value — edit in YAML mode" })
96
+
97
+ for (const d of rpc) {
98
+ const lane = route(d.key) as Extract<Lane, { via: "rpc" }>
99
+ const value = lane.toWire ? lane.toWire(d.to) : String(d.to ?? "")
100
+ try {
101
+ const res = await gw.request<{ warning?: string }>("config.set", { key: lane.alias, value })
102
+ ok.push(d.key)
103
+ if (res?.warning) warnings.push({ key: d.key, msg: res.warning })
104
+ } catch (e) {
105
+ failed.push({ key: d.key, err: e instanceof Error ? e.message : String(e) })
106
+ }
107
+ }
108
+
109
+ for (const d of cli) {
110
+ try {
111
+ const res = await gw.request<{ code: number; output: string; blocked?: boolean; hint?: string }>(
112
+ "cli.exec", { argv: ["config", "set", d.key, toCliString(d.key, d.to)], timeout: 30 },
113
+ )
114
+ if (res.blocked) failed.push({ key: d.key, err: res.hint ?? "blocked" })
115
+ else if (res.code !== 0) failed.push({ key: d.key, err: res.output.split("\n")[0] || `exit ${res.code}` })
116
+ else ok.push(d.key)
117
+ } catch (e) {
118
+ failed.push({ key: d.key, err: e instanceof Error ? e.message : String(e) })
119
+ }
120
+ }
121
+
122
+ return { ok, failed, warnings }
123
+ }
124
+
125
+ // ─── effect aggregation ──────────────────────────────────────────────
126
+
127
+ const EFFECT_RANK: Record<ConfigEffect, number> = { live: 0, session: 1, restart: 2 }
128
+
129
+ export const maxEffect = (keys: string[]): ConfigEffect =>
130
+ keys.reduce<ConfigEffect>((acc, k) => {
131
+ const e = SCHEMA[k]?.effect ?? "live"
132
+ return EFFECT_RANK[e] > EFFECT_RANK[acc] ? e : acc
133
+ }, "live")
134
+
135
+ // ─── verification ────────────────────────────────────────────────────
136
+
137
+ const get = (obj: Record<string, unknown>, path: string): unknown => {
138
+ let cur: unknown = obj
139
+ for (const p of path.split(".")) {
140
+ if (cur && typeof cur === "object" && !Array.isArray(cur)) cur = (cur as Record<string, unknown>)[p]
141
+ else return undefined
142
+ }
143
+ return cur
144
+ }
145
+
146
+ const eq = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
147
+
148
+ /** After a write, compare intended values against a fresh config.get.
149
+ * RPC-aliased keys are skipped — several aliases write to a different
150
+ * dotted path than the one edited (e.g. reasoning:show →
151
+ * display.show_reasoning), so a literal readback would false-positive. */
152
+ export const verifyWrite = async (gw: Gw, applied: Diff[]): Promise<string[]> => {
153
+ const res = await gw.request<{ config?: Record<string, unknown> }>("config.get", { key: "full" })
154
+ const cfg = res.config ?? {}
155
+ const miss: string[] = []
156
+ for (const d of applied) {
157
+ if (route(d.key).via !== "cli") continue
158
+ if (!eq(get(cfg, d.key), d.to)) miss.push(d.key)
159
+ }
160
+ return miss
161
+ }
@@ -0,0 +1,95 @@
1
+ // Model-slot view over config.yaml — the "Models" category in Config.
2
+ //
3
+ // Reads are pure projections over the `config.get {key:"full"}` object
4
+ // Config.tsx already holds, so there's no second RPC. Writes route
5
+ // through the existing lanes: main → `config.set key=model` (rpc lane,
6
+ // hot-swaps the live agent and persists with --global); aux →
7
+ // `writeConfig()` (cli lane, `hermes config set auxiliary.<t>.…`).
8
+ //
9
+ // Intentionally NOT a gateway client of /api/model/auxiliary or
10
+ // /api/model/set — those are web_server-only endpoints. Everything
11
+ // here is derivable from config + the stock tui_gateway surface.
12
+
13
+ import { writeConfig, type WriteResult } from "./lane"
14
+ import type { ConfigSetResponse } from "../utils/gateway-types"
15
+
16
+ type Gw = {
17
+ request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>
18
+ }
19
+
20
+ // Mirrors _AUX_TASK_SLOTS in hermes_cli/web_server.py — ordering kept
21
+ // so herm and the webui read the same top-to-bottom.
22
+ export const AUX_TASKS = [
23
+ { key: "vision", label: "Vision", hint: "Image analysis" },
24
+ { key: "web_extract", label: "Web Extract", hint: "Page summarization" },
25
+ { key: "compression", label: "Compression", hint: "Context compaction" },
26
+ { key: "session_search", label: "Session Search", hint: "Recall queries" },
27
+ { key: "skills_hub", label: "Skills Hub", hint: "Skill search" },
28
+ { key: "approval", label: "Approval", hint: "Smart auto-approve" },
29
+ { key: "mcp", label: "MCP", hint: "MCP tool routing" },
30
+ { key: "title_generation", label: "Title Gen", hint: "Session titles" },
31
+ { key: "curator", label: "Curator", hint: "Skill-usage review" },
32
+ ] as const
33
+
34
+ export type AuxKey = typeof AUX_TASKS[number]["key"]
35
+
36
+ export type Slot =
37
+ | { kind: "main"; key: "main"; label: string; hint: string
38
+ provider: string; model: string; auto: false }
39
+ | { kind: "aux"; key: AuxKey; label: string; hint: string
40
+ provider: string; model: string; auto: boolean }
41
+
42
+ const dig = (o: unknown, ...path: string[]): unknown =>
43
+ path.reduce<unknown>((c, p) =>
44
+ c && typeof c === "object" ? (c as Record<string, unknown>)[p] : undefined, o)
45
+
46
+ const str = (v: unknown) => typeof v === "string" ? v : ""
47
+
48
+ /** Project config.yaml → 1 main + 9 aux slots. */
49
+ export const readSlots = (raw: Record<string, unknown>): Slot[] => {
50
+ const main: Slot = {
51
+ kind: "main", key: "main", label: "Main model", hint: "Primary agent model",
52
+ provider: str(dig(raw, "model", "provider")),
53
+ model: str(dig(raw, "model", "default")) || str(dig(raw, "model", "name")),
54
+ auto: false,
55
+ }
56
+ const aux = AUX_TASKS.map<Slot>(t => {
57
+ const p = str(dig(raw, "auxiliary", t.key, "provider"))
58
+ return {
59
+ kind: "aux", key: t.key, label: t.label, hint: t.hint,
60
+ provider: p, model: str(dig(raw, "auxiliary", t.key, "model")),
61
+ auto: p === "" || p === "auto",
62
+ }
63
+ })
64
+ return [main, ...aux]
65
+ }
66
+
67
+ export type AssignResult = WriteResult & { warning?: string }
68
+
69
+ /** Write a slot. Main goes via the rpc `config.set key=model` alias
70
+ * (same path as /model --global — live-applies and clears stale
71
+ * base_url/context_length upstream). Aux writes two cli-lane keys. */
72
+ export const assign = async (
73
+ gw: Gw, slot: Slot["key"], provider: string, model: string,
74
+ ): Promise<AssignResult> => {
75
+ if (slot === "main") {
76
+ const r = await gw.request<ConfigSetResponse>("config.set", {
77
+ key: "model", value: `${model} --provider ${provider} --global`,
78
+ session_id: undefined,
79
+ })
80
+ return { ok: ["model.default", "model.provider"], failed: [], warnings: [], warning: r.warning }
81
+ }
82
+ return writeConfig(gw, [
83
+ { key: `auxiliary.${slot}.provider`, to: provider },
84
+ { key: `auxiliary.${slot}.model`, to: model },
85
+ ])
86
+ }
87
+
88
+ /** Reset one aux slot (or all) to provider="auto", model="". */
89
+ export const resetAux = (gw: Gw, slot: AuxKey | "all"): Promise<WriteResult> => {
90
+ const keys = slot === "all" ? AUX_TASKS.map(t => t.key) : [slot]
91
+ return writeConfig(gw, keys.flatMap(k => [
92
+ { key: `auxiliary.${k}.provider`, to: "auto" },
93
+ { key: `auxiliary.${k}.model`, to: "" },
94
+ ]))
95
+ }