herm-tui 1.0.0-dev.1 → 1.0.0-dev.11

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 (192) hide show
  1. package/README.md +8 -4
  2. package/assets/eikons/ares.eikon +367 -0
  3. package/assets/eikons/default.eikon +398 -0
  4. package/assets/eikons/mono.eikon +395 -0
  5. package/db.worker.js +81 -0
  6. package/highlights-eq9cgrbb.scm +604 -0
  7. package/highlights-ghv9g403.scm +205 -0
  8. package/highlights-hk7bwhj4.scm +284 -0
  9. package/highlights-r812a2qc.scm +150 -0
  10. package/highlights-x6tmsnaa.scm +115 -0
  11. package/index.js +4151 -0
  12. package/injections-73j83es3.scm +27 -0
  13. package/package.json +14 -64
  14. package/parser.worker.js +8 -0
  15. package/tree-sitter-3jzf13jk.wasm +0 -0
  16. package/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
  17. package/tree-sitter-markdown-411r6y9b.wasm +0 -0
  18. package/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
  19. package/tree-sitter-typescript-zxjzwt75.wasm +0 -0
  20. package/tree-sitter-zig-e78zbjpm.wasm +0 -0
  21. package/scripts/postinstall.ts +0 -29
  22. package/src/app/gateway.tsx +0 -83
  23. package/src/app/gatewayEvents.ts +0 -203
  24. package/src/app/launch.ts +0 -41
  25. package/src/app/skin.tsx +0 -31
  26. package/src/app/spawnHistory.ts +0 -75
  27. package/src/app/tabs.ts +0 -23
  28. package/src/app/turnReducer.ts +0 -390
  29. package/src/app/useAppKeys.ts +0 -268
  30. package/src/app/useAtRefPopover.ts +0 -99
  31. package/src/app/useInputHistory.ts +0 -66
  32. package/src/app/useSession.ts +0 -102
  33. package/src/app/useSlashCommands.ts +0 -70
  34. package/src/app/useSlashPopover.ts +0 -48
  35. package/src/app.tsx +0 -917
  36. package/src/commands/slash.ts +0 -151
  37. package/src/components/avatar/AnimatedAvatar.tsx +0 -66
  38. package/src/components/avatar/eikon.ts +0 -144
  39. package/src/components/avatar/states/error.ts +0 -1155
  40. package/src/components/avatar/states/idle.ts +0 -1155
  41. package/src/components/avatar/states/index.ts +0 -30
  42. package/src/components/avatar/states/listening.ts +0 -1155
  43. package/src/components/avatar/states/speaking.ts +0 -1155
  44. package/src/components/avatar/states/thinking.ts +0 -1155
  45. package/src/components/avatar/states/working.ts +0 -1155
  46. package/src/components/chat/AtRefPopover.tsx +0 -54
  47. package/src/components/chat/CodeBlock.tsx +0 -67
  48. package/src/components/chat/Composer.tsx +0 -347
  49. package/src/components/chat/DiffBlock.tsx +0 -116
  50. package/src/components/chat/ErrorBlock.tsx +0 -70
  51. package/src/components/chat/MediaChip.tsx +0 -114
  52. package/src/components/chat/MessageItem.tsx +0 -282
  53. package/src/components/chat/MessageList.tsx +0 -114
  54. package/src/components/chat/PromptCard.tsx +0 -359
  55. package/src/components/chat/SlashPopover.tsx +0 -158
  56. package/src/components/chat/ThoughtCloud.tsx +0 -185
  57. package/src/components/chat/TypingIndicator.tsx +0 -25
  58. package/src/components/chat/tool/Subagent.tsx +0 -75
  59. package/src/components/chat/tool/frame.tsx +0 -69
  60. package/src/components/chat/tool/index.tsx +0 -65
  61. package/src/components/chat/tool/preview.ts +0 -57
  62. package/src/components/sidebar/ContextGauge.tsx +0 -102
  63. package/src/components/sidebar/Sidebar.tsx +0 -143
  64. package/src/components/tabs/TabBar.tsx +0 -50
  65. package/src/components/ui/FileLink.tsx +0 -52
  66. package/src/config/index.ts +0 -156
  67. package/src/config/lane.ts +0 -161
  68. package/src/config/models.ts +0 -95
  69. package/src/config/rules.ts +0 -80
  70. package/src/config/schema.ts +0 -308
  71. package/src/dialogs/alert.tsx +0 -52
  72. package/src/dialogs/chafa.tsx +0 -72
  73. package/src/dialogs/confirm.tsx +0 -58
  74. package/src/dialogs/curator.tsx +0 -153
  75. package/src/dialogs/eikon-picker.tsx +0 -95
  76. package/src/dialogs/help.tsx +0 -80
  77. package/src/dialogs/history.tsx +0 -92
  78. package/src/dialogs/info.tsx +0 -115
  79. package/src/dialogs/keys.tsx +0 -170
  80. package/src/dialogs/logs.tsx +0 -42
  81. package/src/dialogs/message.tsx +0 -38
  82. package/src/dialogs/model-picker.tsx +0 -123
  83. package/src/dialogs/new-profile.tsx +0 -69
  84. package/src/dialogs/new-task.tsx +0 -103
  85. package/src/dialogs/profile.tsx +0 -55
  86. package/src/dialogs/rollback.tsx +0 -190
  87. package/src/dialogs/spawn-history.tsx +0 -80
  88. package/src/dialogs/text-prompt.tsx +0 -68
  89. package/src/dialogs/theme-picker.tsx +0 -50
  90. package/src/home/index.ts +0 -23
  91. package/src/home/store.ts +0 -267
  92. package/src/index.tsx +0 -113
  93. package/src/keys/catalog.ts +0 -115
  94. package/src/keys/chord.ts +0 -125
  95. package/src/keys/conflicts.ts +0 -48
  96. package/src/keys/context.tsx +0 -112
  97. package/src/keys/index.ts +0 -5
  98. package/src/keys/list.ts +0 -94
  99. package/src/keys/oc-compat.ts +0 -87
  100. package/src/tabs/Agents.tsx +0 -607
  101. package/src/tabs/Analytics.tsx +0 -154
  102. package/src/tabs/Chat.tsx +0 -50
  103. package/src/tabs/Config.tsx +0 -605
  104. package/src/tabs/Context.tsx +0 -599
  105. package/src/tabs/Cron.tsx +0 -294
  106. package/src/tabs/Env.tsx +0 -227
  107. package/src/tabs/Kanban.tsx +0 -367
  108. package/src/tabs/Memory.tsx +0 -294
  109. package/src/tabs/Sessions.tsx +0 -786
  110. package/src/tabs/Skills.tsx +0 -507
  111. package/src/tabs/Toolsets.tsx +0 -266
  112. package/src/theme/builtin.ts +0 -78
  113. package/src/theme/context.tsx +0 -106
  114. package/src/theme/index.ts +0 -4
  115. package/src/theme/resolve.ts +0 -134
  116. package/src/theme/syntax.ts +0 -31
  117. package/src/theme/themes/aura.json +0 -69
  118. package/src/theme/themes/ayu.json +0 -80
  119. package/src/theme/themes/carbonfox.json +0 -248
  120. package/src/theme/themes/catppuccin-frappe.json +0 -233
  121. package/src/theme/themes/catppuccin-macchiato.json +0 -233
  122. package/src/theme/themes/catppuccin.json +0 -112
  123. package/src/theme/themes/cobalt2.json +0 -228
  124. package/src/theme/themes/cursor.json +0 -249
  125. package/src/theme/themes/dracula.json +0 -219
  126. package/src/theme/themes/everforest.json +0 -241
  127. package/src/theme/themes/flexoki.json +0 -237
  128. package/src/theme/themes/github.json +0 -233
  129. package/src/theme/themes/gruvbox.json +0 -242
  130. package/src/theme/themes/kanagawa.json +0 -77
  131. package/src/theme/themes/lucent-orng.json +0 -237
  132. package/src/theme/themes/material.json +0 -235
  133. package/src/theme/themes/matrix.json +0 -77
  134. package/src/theme/themes/mercury.json +0 -252
  135. package/src/theme/themes/monokai.json +0 -221
  136. package/src/theme/themes/nightowl.json +0 -221
  137. package/src/theme/themes/nord.json +0 -223
  138. package/src/theme/themes/one-dark.json +0 -84
  139. package/src/theme/themes/opencode.json +0 -245
  140. package/src/theme/themes/orng.json +0 -249
  141. package/src/theme/themes/osaka-jade.json +0 -93
  142. package/src/theme/themes/palenight.json +0 -222
  143. package/src/theme/themes/rosepine.json +0 -234
  144. package/src/theme/themes/solarized.json +0 -223
  145. package/src/theme/themes/synthwave84.json +0 -226
  146. package/src/theme/themes/tokyonight.json +0 -243
  147. package/src/theme/themes/vercel.json +0 -245
  148. package/src/theme/themes/vesper.json +0 -218
  149. package/src/theme/themes/zenburn.json +0 -223
  150. package/src/theme/types.ts +0 -119
  151. package/src/types/message.ts +0 -97
  152. package/src/ui/ChafaImage.tsx +0 -64
  153. package/src/ui/Splash.tsx +0 -118
  154. package/src/ui/borders.ts +0 -28
  155. package/src/ui/command.tsx +0 -104
  156. package/src/ui/dialog-select.tsx +0 -164
  157. package/src/ui/dialog.tsx +0 -102
  158. package/src/ui/fmt.ts +0 -82
  159. package/src/ui/kv.tsx +0 -28
  160. package/src/ui/shell.tsx +0 -45
  161. package/src/ui/spinner.tsx +0 -59
  162. package/src/ui/splash-art.ts +0 -123
  163. package/src/ui/table.tsx +0 -117
  164. package/src/ui/ticker.tsx +0 -90
  165. package/src/ui/toast.tsx +0 -130
  166. package/src/utils/categorical.ts +0 -77
  167. package/src/utils/chafa.ts +0 -173
  168. package/src/utils/clipboard.ts +0 -67
  169. package/src/utils/context-segments.ts +0 -317
  170. package/src/utils/control.ts +0 -495
  171. package/src/utils/drop.ts +0 -25
  172. package/src/utils/editor.ts +0 -33
  173. package/src/utils/fuzzy.ts +0 -45
  174. package/src/utils/gateway-client.ts +0 -253
  175. package/src/utils/gateway-types.ts +0 -282
  176. package/src/utils/git.ts +0 -57
  177. package/src/utils/hermes-analytics.ts +0 -134
  178. package/src/utils/hermes-home.ts +0 -821
  179. package/src/utils/hermes-kanban.ts +0 -154
  180. package/src/utils/hermes-profiles.ts +0 -217
  181. package/src/utils/interpolate.ts +0 -31
  182. package/src/utils/math-unicode.ts +0 -818
  183. package/src/utils/memory-activity.ts +0 -140
  184. package/src/utils/open-file.ts +0 -13
  185. package/src/utils/paths.ts +0 -52
  186. package/src/utils/perf.ts +0 -235
  187. package/src/utils/preferences.ts +0 -150
  188. package/src/utils/sessions-db.ts +0 -396
  189. package/src/utils/subagent-tree.ts +0 -146
  190. package/src/utils/terminal-reset.ts +0 -129
  191. package/src/utils/tips.ts +0 -67
  192. package/src/utils/tokens.ts +0 -87
@@ -1,266 +0,0 @@
1
- import { useState, useEffect, useCallback, useRef, memo, type ReactNode } from "react";
2
- import { useGateway } from "../app/gateway";
3
- import { useListKeys, useFollow } from "../keys";
4
- import { useTheme } from "../theme";
5
- import { useDialog } from "../ui/dialog";
6
- import { useToast } from "../ui/toast";
7
- import { TabShell } from "../ui/shell";
8
- import { KVBlock } from "../ui/kv";
9
- import { Col, Hdr, VBAR } from "../ui/table";
10
-
11
- // ─── Types ────────────────────────────────────────────────────────────
12
-
13
- // Wire shape from tui_gateway's `toolsets.list`. v1 only guarantees the
14
- // first four; the rest are optional so a future tui_gateway that passes
15
- // get_toolset_info()/get_available_toolsets() through lands here without
16
- // a client change.
17
- type Toolset = {
18
- name: string
19
- description: string
20
- tool_count: number
21
- enabled: boolean
22
- tools?: string[]
23
- includes?: string[]
24
- available?: boolean
25
- requirements?: string[]
26
- }
27
-
28
- type Kind = "core" | "platform" | "mcp"
29
-
30
- // ─── Classification ───────────────────────────────────────────────────
31
-
32
- // Name-only heuristic — tui_gateway doesn't expose includes/is_composite
33
- // on the wire yet, so composites fold into their name-derived bucket.
34
- // `hermes-*` are the per-platform bundles that all clone _HERMES_CORE_TOOLS
35
- // upstream; separating them cuts ~20 near-identical rows out of "core".
36
- const kindOf = (ts: Toolset): Kind =>
37
- ts.name.includes(":") ? "mcp"
38
- : ts.name.startsWith("hermes-") ? "platform"
39
- : "core"
40
-
41
- const KIND_LABEL: Record<Kind, string> = {
42
- core: "core",
43
- platform: "platform bundles",
44
- mcp: "mcp",
45
- }
46
-
47
- type Section = { kind: Kind; items: Toolset[] }
48
-
49
- const group = (list: Toolset[]): Section[] => {
50
- const by = { core: [], platform: [], mcp: [] } as Record<Kind, Toolset[]>
51
- for (const ts of list) by[kindOf(ts)].push(ts)
52
- return (["core", "platform", "mcp"] as const)
53
- .filter(k => by[k].length > 0)
54
- .map(k => ({ kind: k, items: by[k] }))
55
- }
56
-
57
- // ─── Toolset Row ──────────────────────────────────────────────────────
58
-
59
- const Row = memo((props: {
60
- id: string;
61
- ts: Toolset;
62
- selected: boolean;
63
- onSelect: () => void;
64
- onHover: () => void;
65
- }) => {
66
- const theme = useTheme().theme;
67
- const ts = props.ts;
68
- const bg = props.selected ? theme.backgroundElement : undefined;
69
- const unavail = ts.available === false;
70
- const glyph = unavail ? "◌" : ts.enabled ? "●" : "○";
71
- const glyphFg = unavail ? theme.warning : ts.enabled ? theme.success : theme.textMuted;
72
-
73
- return (
74
- <box id={props.id} flexDirection="row" height={1} backgroundColor={bg}
75
- onMouseDown={props.onSelect} onMouseMove={props.onHover}>
76
- <Col w={2} fg={props.selected ? theme.primary : theme.text}>{props.selected ? "▸ " : " "}</Col>
77
- <Col w={2} fg={glyphFg}>{`${glyph} `}</Col>
78
- <Col grow fg={props.selected ? theme.accent : theme.text}>{ts.name}</Col>
79
- <Col w={9} fg={theme.info} right>{`${ts.tool_count} tools`}</Col>
80
- </box>
81
- );
82
- });
83
-
84
- // ─── Detail Panel ─────────────────────────────────────────────────────
85
-
86
- const DetailPanel = memo((props: { ts: Toolset }) => {
87
- const theme = useTheme().theme;
88
- const ts = props.ts;
89
- const unavail = ts.available === false;
90
-
91
- return (
92
- <box
93
- flexDirection="column" padding={1} border
94
- borderColor={theme.border} backgroundColor={theme.backgroundPanel} width="40%"
95
- >
96
- <box height={1}><text fg={theme.accent}><strong>{ts.name}</strong></text></box>
97
- <box height={1}><text fg={theme.textMuted}>{KIND_LABEL[kindOf(ts)]}</text></box>
98
- <box height={1} />
99
- <KVBlock rows={[
100
- ["Status", unavail ? "unavailable" : ts.enabled ? "enabled" : "disabled",
101
- unavail ? theme.warning : ts.enabled ? theme.success : theme.textMuted],
102
- ["Tools", String(ts.tool_count), theme.info],
103
- ["Includes", ts.includes?.length ? ts.includes.join(", ") : undefined, theme.text],
104
- ["Requires", ts.requirements?.length ? ts.requirements.join(", ") : undefined,
105
- unavail ? theme.warning : theme.text],
106
- ]} />
107
- <box height={1} />
108
- <box minHeight={1}>
109
- <text wrapMode="word" fg={theme.text}>{ts.description || "—"}</text>
110
- </box>
111
- {ts.tools?.length ? (
112
- <>
113
- <box height={1} />
114
- <box height={1}><text fg={theme.textMuted}>Tools ({ts.tools.length}):</text></box>
115
- <scrollbox flexGrow={1} scrollY>
116
- {ts.tools.map(n => <text key={n} fg={theme.text}>· {n}</text>)}
117
- </scrollbox>
118
- </>
119
- ) : null}
120
- </box>
121
- );
122
- });
123
-
124
- // ─── Main Component ───────────────────────────────────────────────────
125
-
126
- export const Toolsets = memo((props: { focused?: boolean }) => {
127
- const theme = useTheme().theme;
128
- const gw = useGateway();
129
- const dialog = useDialog();
130
- const toast = useToast();
131
- const [list, setList] = useState<Toolset[]>([]);
132
- const [sel, setSel] = useState(0);
133
- const [err, setErr] = useState<string | null>(null);
134
-
135
- // Flat nav list derived from grouped sections, so ↑/↓ crosses section
136
- // boundaries in render order. `live` mirrors for callbacks that must
137
- // read current selection without closing over stale state.
138
- const secs = group(list);
139
- const flat = secs.flatMap(s => s.items);
140
- const live = useRef({ flat, sel });
141
- live.current = { flat, sel };
142
-
143
- const load = useCallback(() => {
144
- gw.request<{ toolsets?: Toolset[] }>("toolsets.list", {})
145
- .then(r => { setList(r.toolsets ?? []); setErr(null); })
146
- .catch(e => setErr(e instanceof Error ? e.message : String(e)));
147
- }, [gw]);
148
-
149
- useEffect(() => { load(); }, [load]);
150
-
151
- // tools.configure response (tui_gateway/server.py @method("tools.configure")).
152
- // `enabled_toolsets` is the authoritative post-change list — reconcile
153
- // from it instead of a round-trip `toolsets.list`. `unknown` = names
154
- // the gateway's whitelist rejected (e.g. platform bundles, composites).
155
- type ConfigureResult = {
156
- changed: string[]
157
- enabled_toolsets: string[]
158
- missing_servers: string[]
159
- unknown: string[]
160
- }
161
-
162
- const toggle = useCallback(() => {
163
- const ts = live.current.flat[live.current.sel];
164
- if (!ts) return;
165
- if (ts.available === false) {
166
- toast.show({ variant: "warning", message: `${ts.name} is unavailable` });
167
- return;
168
- }
169
- const action = ts.enabled ? "disable" : "enable";
170
- const was = ts.enabled;
171
- // optimistic flip
172
- setList(prev => prev.map(t => t.name === ts.name ? { ...t, enabled: !t.enabled } : t));
173
- gw.request<ConfigureResult>("tools.configure", { action, names: [ts.name] })
174
- .then(r => {
175
- if (r.unknown?.includes(ts.name)) {
176
- // Gateway rejected the name — revert the optimistic flip and tell
177
- // the user why (matches config.yaml whitelist in hermes_cli/tools_config.py).
178
- setList(prev => prev.map(t => t.name === ts.name ? { ...t, enabled: was } : t));
179
- toast.show({ variant: "warning", message: `${ts.name} is not configurable` });
180
- return;
181
- }
182
- if (r.missing_servers?.length && ts.name.includes(":")) {
183
- const server = ts.name.split(":", 1)[0];
184
- if (r.missing_servers.includes(server)) {
185
- setList(prev => prev.map(t => t.name === ts.name ? { ...t, enabled: was } : t));
186
- toast.show({ variant: "warning", message: `MCP server '${server}' not in config` });
187
- return;
188
- }
189
- }
190
- // Reconcile from the authoritative list. Tolerant of future shape
191
- // changes (missing `enabled_toolsets` falls back to `load()`).
192
- if (Array.isArray(r.enabled_toolsets)) {
193
- const on = new Set(r.enabled_toolsets);
194
- setList(prev => prev.map(t => ({ ...t, enabled: on.has(t.name) })));
195
- } else {
196
- load();
197
- }
198
- })
199
- .catch((e: Error) => {
200
- setList(prev => prev.map(t => t.name === ts.name ? { ...t, enabled: was } : t));
201
- toast.show({ variant: "error", message: e.message });
202
- });
203
- }, [gw, toast, load]);
204
-
205
- const count = flat.length;
206
- const ts = flat[sel] ?? null;
207
- const follow = useFollow("ts");
208
-
209
- const keys = useListKeys({
210
- active: !!props.focused && dialog.stack.length === 0,
211
- count, setSel, ...follow.opts,
212
- onToggle: toggle,
213
- onRefresh: () => { load(); toast.show({ variant: "info", message: "Reloaded", duration: 1000 }) },
214
- });
215
-
216
- return (
217
- <box flexDirection="row" flexGrow={1}>
218
- <TabShell
219
- title={`Toolsets (${count})`}
220
- error={err}
221
- hint={`↑↓ nav ${keys.print("list.toggle")} toggle ${keys.print("list.refresh")} refresh`}
222
- >
223
- <Hdr>
224
- <Col w={4} fg={theme.textMuted}>{""}</Col>
225
- <Col grow fg={theme.textMuted} bold>Name</Col>
226
- <Col w={9} fg={theme.textMuted} bold right>Tools</Col>
227
- </Hdr>
228
- <box height={1} />
229
-
230
- {count === 0 ? (
231
- <box key="empty" flexGrow={1} padding={2}>
232
- <text fg={theme.textMuted}>No toolsets found</text>
233
- </box>
234
- ) : (
235
- <scrollbox ref={follow.ref} key="list" scrollY flexGrow={1}
236
- verticalScrollbarOptions={VBAR}>
237
- {secs.reduce<{ base: number; out: ReactNode[] }>((acc, s) => {
238
- acc.out.push(
239
- <box key={`§${s.kind}`} height={1} marginTop={acc.base > 0 ? 1 : 0}>
240
- <text fg={theme.textMuted}>─ {KIND_LABEL[s.kind]} ({s.items.length}) </text>
241
- </box>
242
- );
243
- s.items.forEach((t, j) => {
244
- const i = acc.base + j;
245
- acc.out.push(
246
- <Row
247
- key={t.name}
248
- id={follow.id(i)}
249
- ts={t}
250
- selected={i === sel}
251
- onSelect={() => setSel(i)}
252
- onHover={() => setSel(i)}
253
- />
254
- );
255
- });
256
- acc.base += s.items.length;
257
- return acc;
258
- }, { base: 0, out: [] }).out}
259
- </scrollbox>
260
- )}
261
- </TabShell>
262
-
263
- {ts ? <DetailPanel ts={ts} /> : null}
264
- </box>
265
- );
266
- });
@@ -1,78 +0,0 @@
1
- /**
2
- * Built-in themes — imported statically from JSON files.
3
- * Same set as OpenCode.
4
- */
5
-
6
- import type { ThemeJson } from "./types";
7
-
8
- import aura from "./themes/aura.json";
9
- import ayu from "./themes/ayu.json";
10
- import carbonfox from "./themes/carbonfox.json";
11
- import catppuccin from "./themes/catppuccin.json";
12
- import catppuccinFrappe from "./themes/catppuccin-frappe.json";
13
- import catppuccinMacchiato from "./themes/catppuccin-macchiato.json";
14
- import cobalt2 from "./themes/cobalt2.json";
15
- import cursor from "./themes/cursor.json";
16
- import dracula from "./themes/dracula.json";
17
- import everforest from "./themes/everforest.json";
18
- import flexoki from "./themes/flexoki.json";
19
- import github from "./themes/github.json";
20
- import gruvbox from "./themes/gruvbox.json";
21
- import kanagawa from "./themes/kanagawa.json";
22
- import lucentOrng from "./themes/lucent-orng.json";
23
- import material from "./themes/material.json";
24
- import matrix from "./themes/matrix.json";
25
- import mercury from "./themes/mercury.json";
26
- import monokai from "./themes/monokai.json";
27
- import nightowl from "./themes/nightowl.json";
28
- import nord from "./themes/nord.json";
29
- import oneDark from "./themes/one-dark.json";
30
- import opencode from "./themes/opencode.json";
31
- import orng from "./themes/orng.json";
32
- import osakaJade from "./themes/osaka-jade.json";
33
- import palenight from "./themes/palenight.json";
34
- import rosepine from "./themes/rosepine.json";
35
- import solarized from "./themes/solarized.json";
36
- import synthwave84 from "./themes/synthwave84.json";
37
- import tokyonight from "./themes/tokyonight.json";
38
- import vercel from "./themes/vercel.json";
39
- import vesper from "./themes/vesper.json";
40
- import zenburn from "./themes/zenburn.json";
41
-
42
- export const DEFAULT_THEMES: Record<string, ThemeJson> = {
43
- aura: aura as ThemeJson,
44
- ayu: ayu as ThemeJson,
45
- carbonfox: carbonfox as ThemeJson,
46
- catppuccin: catppuccin as ThemeJson,
47
- "catppuccin-frappe": catppuccinFrappe as ThemeJson,
48
- "catppuccin-macchiato": catppuccinMacchiato as ThemeJson,
49
- cobalt2: cobalt2 as ThemeJson,
50
- cursor: cursor as ThemeJson,
51
- dracula: dracula as ThemeJson,
52
- everforest: everforest as ThemeJson,
53
- flexoki: flexoki as ThemeJson,
54
- github: github as ThemeJson,
55
- gruvbox: gruvbox as ThemeJson,
56
- kanagawa: kanagawa as ThemeJson,
57
- "lucent-orng": lucentOrng as ThemeJson,
58
- material: material as ThemeJson,
59
- matrix: matrix as ThemeJson,
60
- mercury: mercury as ThemeJson,
61
- monokai: monokai as ThemeJson,
62
- nightowl: nightowl as ThemeJson,
63
- nord: nord as ThemeJson,
64
- "one-dark": oneDark as ThemeJson,
65
- opencode: opencode as ThemeJson,
66
- orng: orng as ThemeJson,
67
- "osaka-jade": osakaJade as ThemeJson,
68
- palenight: palenight as ThemeJson,
69
- rosepine: rosepine as ThemeJson,
70
- solarized: solarized as ThemeJson,
71
- synthwave84: synthwave84 as ThemeJson,
72
- tokyonight: tokyonight as ThemeJson,
73
- vercel: vercel as ThemeJson,
74
- vesper: vesper as ThemeJson,
75
- zenburn: zenburn as ThemeJson,
76
- };
77
-
78
- export const DEFAULT_THEME = "tokyonight";
@@ -1,106 +0,0 @@
1
- /**
2
- * Theme React context — provides resolved theme to all components.
3
- *
4
- * Usage:
5
- * // In app root:
6
- * <ThemeProvider><App /></ThemeProvider>
7
- *
8
- * // In any component:
9
- * const { theme, name, set, names } = useTheme();
10
- * <box backgroundColor={theme.backgroundPanel}>
11
- * <text fg={theme.text}>
12
- */
13
-
14
- import { createContext, useContext, useState, useCallback, useMemo } from "react";
15
- import type { ReactNode } from "react";
16
- import type { SyntaxStyle } from "@opentui/core";
17
- import type { Theme, ThemeJson } from "./types";
18
- import { resolveTheme } from "./resolve";
19
- import { DEFAULT_THEMES, DEFAULT_THEME } from "./builtin";
20
- import { syntax } from "./syntax";
21
- import * as preferences from "../utils/preferences";
22
-
23
- interface ThemeContext {
24
- /** Resolved theme — all RGBA values ready for JSX props */
25
- theme: Theme;
26
- /** SyntaxStyle for code/markdown rendering */
27
- syntaxStyle: SyntaxStyle;
28
- /** Currently active theme name */
29
- name: string;
30
- /** Dark or light mode */
31
- mode: "dark" | "light";
32
- /** Switch to a theme by name. Returns false if not found. */
33
- set: (name: string) => boolean;
34
- /** All available theme names, sorted */
35
- names: string[];
36
- /** Check if a theme exists */
37
- has: (name: string) => boolean;
38
- }
39
-
40
- const Ctx = createContext<ThemeContext | null>(null);
41
-
42
- interface ThemeProviderProps {
43
- children: ReactNode;
44
- initial?: string;
45
- mode?: "dark" | "light";
46
- }
47
-
48
- export const ThemeProvider = ({
49
- children,
50
- initial,
51
- mode: initialMode = "dark",
52
- }: ThemeProviderProps) => {
53
- const [active, setActive] = useState(initial ?? DEFAULT_THEME);
54
- const [mode] = useState(initialMode);
55
- const [themes] = useState<Record<string, ThemeJson>>(DEFAULT_THEMES);
56
-
57
- const resolved = useMemo(() => {
58
- const json = themes[active] ?? themes[DEFAULT_THEME];
59
- try {
60
- return resolveTheme(json, mode);
61
- } catch {
62
- return resolveTheme(themes[DEFAULT_THEME], mode);
63
- }
64
- }, [active, mode, themes]);
65
-
66
- const names = useMemo(
67
- () => Object.keys(themes).sort(),
68
- [themes],
69
- );
70
-
71
- const set = useCallback(
72
- (name: string) => {
73
- if (!themes[name]) return false;
74
- setActive(name);
75
- preferences.set("theme", name);
76
- return true;
77
- },
78
- [themes],
79
- );
80
-
81
- const has = useCallback(
82
- (name: string) => themes[name] !== undefined,
83
- [themes],
84
- );
85
-
86
- const syntaxStyle = useMemo(() => syntax(resolved), [resolved]);
87
-
88
- const value = useMemo<ThemeContext>(() => ({
89
- theme: resolved,
90
- syntaxStyle,
91
- name: active,
92
- mode,
93
- set,
94
- names,
95
- has,
96
- }), [resolved, syntaxStyle, active, mode, set, names, has]);
97
-
98
- return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
99
- };
100
-
101
- /** Access the current theme. Must be inside <ThemeProvider>. */
102
- export const useTheme = (): ThemeContext => {
103
- const ctx = useContext(Ctx);
104
- if (!ctx) throw new Error("useTheme() must be used inside <ThemeProvider>");
105
- return ctx;
106
- };
@@ -1,4 +0,0 @@
1
- export { ThemeProvider, useTheme } from "./context";
2
- export { resolveTheme } from "./resolve";
3
- export { DEFAULT_THEMES, DEFAULT_THEME } from "./builtin";
4
- export type { ThemeCurrent, Theme, ThemeJson, ThemeColor } from "./types";
@@ -1,134 +0,0 @@
1
- /**
2
- * Theme resolver — takes a ThemeJson + mode, returns a fully resolved Theme.
3
- *
4
- * Handles: hex colors, defs references, cross-token references,
5
- * dark/light variants, ANSI codes, transparent/none, circular detection.
6
- */
7
-
8
- import { RGBA } from "@opentui/core";
9
- import type { Theme, ThemeJson, ThemeColor, ColorValue, HermTokens } from "./types";
10
-
11
- /** Resolve a ThemeJson into a concrete Theme with all RGBA values */
12
- export function resolveTheme(
13
- theme: ThemeJson,
14
- mode: "dark" | "light",
15
- ): Theme {
16
- const defs = theme.defs ?? {};
17
-
18
- function resolve(c: ColorValue, chain: string[] = []): RGBA {
19
- if (c instanceof RGBA) return c;
20
-
21
- if (typeof c === "string") {
22
- if (c === "transparent" || c === "none") return RGBA.fromInts(0, 0, 0, 0);
23
- if (c.startsWith("#")) return RGBA.fromHex(c);
24
-
25
- // Reference — check for circular
26
- if (chain.includes(c)) {
27
- throw new Error(`Circular color reference: ${[...chain, c].join(" -> ")}`);
28
- }
29
- const next = defs[c] ?? theme.theme[c as ThemeColor];
30
- if (next === undefined) {
31
- throw new Error(`Color reference "${c}" not found in defs or theme`);
32
- }
33
- return resolve(next, [...chain, c]);
34
- }
35
-
36
- if (typeof c === "number") return ansiToRgba(c);
37
-
38
- // Variant — pick dark or light
39
- return resolve(c[mode], chain);
40
- }
41
-
42
- const resolved = Object.fromEntries(
43
- Object.entries(theme.theme)
44
- .filter(
45
- ([key]) =>
46
- key !== "selectedListItemText" &&
47
- key !== "backgroundMenu" &&
48
- key !== "thinkingOpacity",
49
- )
50
- .map(([key, value]) => [key, resolve(value as ColorValue)]),
51
- ) as Partial<Record<ThemeColor, RGBA>>;
52
-
53
- // Optional tokens with fallbacks
54
- const hasList = theme.theme.selectedListItemText !== undefined;
55
- resolved.selectedListItemText = hasList
56
- ? resolve(theme.theme.selectedListItemText!)
57
- : resolved.background;
58
-
59
- resolved.backgroundMenu =
60
- theme.theme.backgroundMenu !== undefined
61
- ? resolve(theme.theme.backgroundMenu)
62
- : resolved.backgroundElement;
63
-
64
- const base = {
65
- ...resolved,
66
- _hasSelectedListItemText: hasList,
67
- thinkingOpacity: theme.theme.thinkingOpacity ?? 0.6,
68
- };
69
-
70
- // Compute herm-specific tokens (accent is a required token)
71
- const herm = resolveHermTokens(resolved.accent!);
72
-
73
- return { ...base, ...herm } as Theme;
74
- }
75
-
76
- /**
77
- * Compute herm pillar tokens.
78
- * hermAvatar and hermBody default to accent.
79
- * hermBodyText is auto-computed for legibility against hermBody.
80
- */
81
- function resolveHermTokens(accent: RGBA): HermTokens {
82
- const text = contrastText(accent);
83
- return {
84
- hermAvatar: accent,
85
- hermBody: accent,
86
- hermBodyText: text,
87
- hermBodyTextMuted: mix(text, accent, 0.45),
88
- };
89
- }
90
-
91
- /** Linear mix a→b by t (0=a, 1=b). */
92
- function mix(a: RGBA, b: RGBA, t: number): RGBA {
93
- const l = (x: number, y: number) => x + (y - x) * t;
94
- return RGBA.fromValues(l(a.r, b.r), l(a.g, b.g), l(a.b, b.b), 1);
95
- }
96
-
97
- /**
98
- * Pick black or white text for maximum legibility on a background.
99
- * Uses WCAG relative luminance formula.
100
- */
101
- function contrastText(bg: RGBA): RGBA {
102
- // RGBA stores 0-1 floats
103
- const lum = 0.299 * bg.r + 0.587 * bg.g + 0.114 * bg.b;
104
- return lum > 0.5
105
- ? RGBA.fromInts(0, 0, 0) // dark text on light bg
106
- : RGBA.fromInts(255, 255, 255); // light text on dark bg
107
- }
108
-
109
- /** Convert ANSI 256-color code to RGBA */
110
- function ansiToRgba(code: number): RGBA {
111
- if (code < 16) {
112
- const colors = [
113
- "#000000", "#800000", "#008000", "#808000",
114
- "#000080", "#800080", "#008080", "#c0c0c0",
115
- "#808080", "#ff0000", "#00ff00", "#ffff00",
116
- "#0000ff", "#ff00ff", "#00ffff", "#ffffff",
117
- ];
118
- return RGBA.fromHex(colors[code] ?? "#000000");
119
- }
120
- if (code < 232) {
121
- const idx = code - 16;
122
- const val = (x: number) => (x === 0 ? 0 : x * 40 + 55);
123
- return RGBA.fromInts(
124
- val(Math.floor(idx / 36)),
125
- val(Math.floor(idx / 6) % 6),
126
- val(idx % 6),
127
- );
128
- }
129
- if (code < 256) {
130
- const gray = (code - 232) * 10 + 8;
131
- return RGBA.fromInts(gray, gray, gray);
132
- }
133
- return RGBA.fromInts(0, 0, 0);
134
- }
@@ -1,31 +0,0 @@
1
- import { SyntaxStyle, type ThemeTokenStyle } from "@opentui/core"
2
- import type { Theme } from "./types"
3
-
4
- export function syntax(theme: Theme): SyntaxStyle {
5
- return SyntaxStyle.fromTheme(rules(theme))
6
- }
7
-
8
- function rules(theme: Theme): ThemeTokenStyle[] {
9
- return [
10
- { scope: ["default"], style: { foreground: theme.text } },
11
- { scope: ["comment", "comment.documentation"], style: { foreground: theme.syntaxComment, italic: true } },
12
- { scope: ["string", "symbol"], style: { foreground: theme.syntaxString } },
13
- { scope: ["number", "boolean"], style: { foreground: theme.syntaxNumber } },
14
- { scope: ["keyword"], style: { foreground: theme.syntaxKeyword, italic: true } },
15
- { scope: ["keyword.return", "keyword.conditional", "keyword.repeat"], style: { foreground: theme.syntaxKeyword, italic: true } },
16
- { scope: ["keyword.type"], style: { foreground: theme.syntaxType, bold: true } },
17
- { scope: ["keyword.function", "function.method"], style: { foreground: theme.syntaxFunction } },
18
- { scope: ["function", "function.call"], style: { foreground: theme.syntaxFunction } },
19
- { scope: ["variable", "variable.parameter"], style: { foreground: theme.syntaxVariable } },
20
- { scope: ["type"], style: { foreground: theme.syntaxType } },
21
- { scope: ["operator"], style: { foreground: theme.syntaxOperator } },
22
- { scope: ["punctuation", "punctuation.bracket", "punctuation.delimiter"], style: { foreground: theme.syntaxPunctuation } },
23
- // Markdown-specific
24
- { scope: ["markup.heading"], style: { foreground: theme.markdownHeading, bold: true } },
25
- { scope: ["markup.strong"], style: { foreground: theme.markdownStrong, bold: true } },
26
- { scope: ["markup.italic"], style: { foreground: theme.markdownEmph, italic: true } },
27
- { scope: ["markup.link"], style: { foreground: theme.markdownLink, underline: true } },
28
- { scope: ["markup.raw"], style: { foreground: theme.markdownCode } },
29
- { scope: ["markup.list"], style: { foreground: theme.markdownListItem } },
30
- ]
31
- }