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,223 @@
1
+ {
2
+ "$schema": "https://opencode.ai/theme.json",
3
+ "defs": {
4
+ "bg": "#3f3f3f",
5
+ "bgAlt": "#4f4f4f",
6
+ "bgPanel": "#5f5f5f",
7
+ "fg": "#dcdccc",
8
+ "fgMuted": "#9f9f9f",
9
+ "red": "#cc9393",
10
+ "redBright": "#dca3a3",
11
+ "green": "#7f9f7f",
12
+ "greenBright": "#8fb28f",
13
+ "yellow": "#f0dfaf",
14
+ "yellowDim": "#e0cf9f",
15
+ "blue": "#8cd0d3",
16
+ "blueDim": "#7cb8bb",
17
+ "magenta": "#dc8cc3",
18
+ "cyan": "#93e0e3",
19
+ "orange": "#dfaf8f"
20
+ },
21
+ "theme": {
22
+ "primary": {
23
+ "dark": "blue",
24
+ "light": "#5f7f8f"
25
+ },
26
+ "secondary": {
27
+ "dark": "magenta",
28
+ "light": "#8f5f8f"
29
+ },
30
+ "accent": {
31
+ "dark": "cyan",
32
+ "light": "#5f8f8f"
33
+ },
34
+ "error": {
35
+ "dark": "red",
36
+ "light": "#8f5f5f"
37
+ },
38
+ "warning": {
39
+ "dark": "yellow",
40
+ "light": "#8f8f5f"
41
+ },
42
+ "success": {
43
+ "dark": "green",
44
+ "light": "#5f8f5f"
45
+ },
46
+ "info": {
47
+ "dark": "orange",
48
+ "light": "#8f7f5f"
49
+ },
50
+ "text": {
51
+ "dark": "fg",
52
+ "light": "#3f3f3f"
53
+ },
54
+ "textMuted": {
55
+ "dark": "fgMuted",
56
+ "light": "#6f6f6f"
57
+ },
58
+ "background": {
59
+ "dark": "bg",
60
+ "light": "#ffffef"
61
+ },
62
+ "backgroundPanel": {
63
+ "dark": "bgAlt",
64
+ "light": "#f5f5e5"
65
+ },
66
+ "backgroundElement": {
67
+ "dark": "bgPanel",
68
+ "light": "#ebebdb"
69
+ },
70
+ "border": {
71
+ "dark": "#5f5f5f",
72
+ "light": "#d0d0c0"
73
+ },
74
+ "borderActive": {
75
+ "dark": "blue",
76
+ "light": "#5f7f8f"
77
+ },
78
+ "borderSubtle": {
79
+ "dark": "#4f4f4f",
80
+ "light": "#e0e0d0"
81
+ },
82
+ "diffAdded": {
83
+ "dark": "green",
84
+ "light": "#5f8f5f"
85
+ },
86
+ "diffRemoved": {
87
+ "dark": "red",
88
+ "light": "#8f5f5f"
89
+ },
90
+ "diffContext": {
91
+ "dark": "fgMuted",
92
+ "light": "#6f6f6f"
93
+ },
94
+ "diffHunkHeader": {
95
+ "dark": "cyan",
96
+ "light": "#5f8f8f"
97
+ },
98
+ "diffHighlightAdded": {
99
+ "dark": "greenBright",
100
+ "light": "#5f8f5f"
101
+ },
102
+ "diffHighlightRemoved": {
103
+ "dark": "redBright",
104
+ "light": "#8f5f5f"
105
+ },
106
+ "diffAddedBg": {
107
+ "dark": "#4f5f4f",
108
+ "light": "#efffef"
109
+ },
110
+ "diffRemovedBg": {
111
+ "dark": "#5f4f4f",
112
+ "light": "#ffefef"
113
+ },
114
+ "diffContextBg": {
115
+ "dark": "bgAlt",
116
+ "light": "#f5f5e5"
117
+ },
118
+ "diffLineNumber": {
119
+ "dark": "#6f6f6f",
120
+ "light": "#b0b0a0"
121
+ },
122
+ "diffAddedLineNumberBg": {
123
+ "dark": "#4f5f4f",
124
+ "light": "#efffef"
125
+ },
126
+ "diffRemovedLineNumberBg": {
127
+ "dark": "#5f4f4f",
128
+ "light": "#ffefef"
129
+ },
130
+ "markdownText": {
131
+ "dark": "fg",
132
+ "light": "#3f3f3f"
133
+ },
134
+ "markdownHeading": {
135
+ "dark": "yellow",
136
+ "light": "#8f8f5f"
137
+ },
138
+ "markdownLink": {
139
+ "dark": "blue",
140
+ "light": "#5f7f8f"
141
+ },
142
+ "markdownLinkText": {
143
+ "dark": "cyan",
144
+ "light": "#5f8f8f"
145
+ },
146
+ "markdownCode": {
147
+ "dark": "green",
148
+ "light": "#5f8f5f"
149
+ },
150
+ "markdownBlockQuote": {
151
+ "dark": "fgMuted",
152
+ "light": "#6f6f6f"
153
+ },
154
+ "markdownEmph": {
155
+ "dark": "yellowDim",
156
+ "light": "#8f8f5f"
157
+ },
158
+ "markdownStrong": {
159
+ "dark": "orange",
160
+ "light": "#8f7f5f"
161
+ },
162
+ "markdownHorizontalRule": {
163
+ "dark": "fgMuted",
164
+ "light": "#6f6f6f"
165
+ },
166
+ "markdownListItem": {
167
+ "dark": "blue",
168
+ "light": "#5f7f8f"
169
+ },
170
+ "markdownListEnumeration": {
171
+ "dark": "cyan",
172
+ "light": "#5f8f8f"
173
+ },
174
+ "markdownImage": {
175
+ "dark": "blue",
176
+ "light": "#5f7f8f"
177
+ },
178
+ "markdownImageText": {
179
+ "dark": "cyan",
180
+ "light": "#5f8f8f"
181
+ },
182
+ "markdownCodeBlock": {
183
+ "dark": "fg",
184
+ "light": "#3f3f3f"
185
+ },
186
+ "syntaxComment": {
187
+ "dark": "#7f9f7f",
188
+ "light": "#5f7f5f"
189
+ },
190
+ "syntaxKeyword": {
191
+ "dark": "yellow",
192
+ "light": "#8f8f5f"
193
+ },
194
+ "syntaxFunction": {
195
+ "dark": "blue",
196
+ "light": "#5f7f8f"
197
+ },
198
+ "syntaxVariable": {
199
+ "dark": "fg",
200
+ "light": "#3f3f3f"
201
+ },
202
+ "syntaxString": {
203
+ "dark": "red",
204
+ "light": "#8f5f5f"
205
+ },
206
+ "syntaxNumber": {
207
+ "dark": "greenBright",
208
+ "light": "#5f8f5f"
209
+ },
210
+ "syntaxType": {
211
+ "dark": "cyan",
212
+ "light": "#5f8f8f"
213
+ },
214
+ "syntaxOperator": {
215
+ "dark": "yellow",
216
+ "light": "#8f8f5f"
217
+ },
218
+ "syntaxPunctuation": {
219
+ "dark": "fg",
220
+ "light": "#3f3f3f"
221
+ }
222
+ }
223
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Theme type definitions — mirrors OpenCode's token model exactly.
3
+ * All 44 RGBA color tokens + 1 numeric token.
4
+ */
5
+
6
+ import type { RGBA } from "@opentui/core";
7
+
8
+ /** All color token names (excludes thinkingOpacity) */
9
+ export type ThemeColor = Exclude<keyof ThemeCurrent, "thinkingOpacity">;
10
+
11
+ /** Resolved theme — all values are RGBA or number, ready for rendering */
12
+ export type ThemeCurrent = {
13
+ // Core
14
+ readonly primary: RGBA;
15
+ readonly secondary: RGBA;
16
+ readonly accent: RGBA;
17
+ readonly error: RGBA;
18
+ readonly warning: RGBA;
19
+ readonly success: RGBA;
20
+ readonly info: RGBA;
21
+
22
+ // Text
23
+ readonly text: RGBA;
24
+ readonly textMuted: RGBA;
25
+ readonly selectedListItemText: RGBA;
26
+
27
+ // Backgrounds
28
+ readonly background: RGBA;
29
+ readonly backgroundPanel: RGBA;
30
+ readonly backgroundElement: RGBA;
31
+ readonly backgroundMenu: RGBA;
32
+
33
+ // Borders
34
+ readonly border: RGBA;
35
+ readonly borderActive: RGBA;
36
+ readonly borderSubtle: RGBA;
37
+
38
+ // Diff
39
+ readonly diffAdded: RGBA;
40
+ readonly diffRemoved: RGBA;
41
+ readonly diffContext: RGBA;
42
+ readonly diffHunkHeader: RGBA;
43
+ readonly diffHighlightAdded: RGBA;
44
+ readonly diffHighlightRemoved: RGBA;
45
+ readonly diffAddedBg: RGBA;
46
+ readonly diffRemovedBg: RGBA;
47
+ readonly diffContextBg: RGBA;
48
+ readonly diffLineNumber: RGBA;
49
+ readonly diffAddedLineNumberBg: RGBA;
50
+ readonly diffRemovedLineNumberBg: RGBA;
51
+
52
+ // Markdown
53
+ readonly markdownText: RGBA;
54
+ readonly markdownHeading: RGBA;
55
+ readonly markdownLink: RGBA;
56
+ readonly markdownLinkText: RGBA;
57
+ readonly markdownCode: RGBA;
58
+ readonly markdownBlockQuote: RGBA;
59
+ readonly markdownEmph: RGBA;
60
+ readonly markdownStrong: RGBA;
61
+ readonly markdownHorizontalRule: RGBA;
62
+ readonly markdownListItem: RGBA;
63
+ readonly markdownListEnumeration: RGBA;
64
+ readonly markdownImage: RGBA;
65
+ readonly markdownImageText: RGBA;
66
+ readonly markdownCodeBlock: RGBA;
67
+
68
+ // Syntax
69
+ readonly syntaxComment: RGBA;
70
+ readonly syntaxKeyword: RGBA;
71
+ readonly syntaxFunction: RGBA;
72
+ readonly syntaxVariable: RGBA;
73
+ readonly syntaxString: RGBA;
74
+ readonly syntaxNumber: RGBA;
75
+ readonly syntaxType: RGBA;
76
+ readonly syntaxOperator: RGBA;
77
+ readonly syntaxPunctuation: RGBA;
78
+
79
+ // Numeric
80
+ readonly thinkingOpacity: number;
81
+ };
82
+
83
+ /** Herm-specific tokens — the sidebar "pillar" identity */
84
+ export type HermTokens = {
85
+ /** Avatar (bust) color — top of the herm */
86
+ readonly hermAvatar: RGBA;
87
+ /** Body (pillar) background — bottom of the herm */
88
+ readonly hermBody: RGBA;
89
+ /** Auto-computed text color for legibility on hermBody */
90
+ readonly hermBodyText: RGBA;
91
+ /** Dimmed hermBodyText — labels/secondary content on the pillar */
92
+ readonly hermBodyTextMuted: RGBA;
93
+ };
94
+
95
+ /** Internal resolved theme with extra tracking + herm tokens */
96
+ export type Theme = ThemeCurrent &
97
+ HermTokens & {
98
+ _hasSelectedListItemText: boolean;
99
+ };
100
+
101
+ /** Color value in a theme JSON file */
102
+ export type HexColor = `#${string}`;
103
+ export type RefName = string;
104
+ export type Variant = { dark: HexColor | RefName; light: HexColor | RefName };
105
+ export type ColorValue = HexColor | RefName | Variant | RGBA;
106
+
107
+ /** Theme JSON file format */
108
+ export type ThemeJson = {
109
+ $schema?: string;
110
+ defs?: Record<string, HexColor | RefName>;
111
+ theme: Omit<
112
+ Record<ThemeColor, ColorValue>,
113
+ "selectedListItemText" | "backgroundMenu"
114
+ > & {
115
+ selectedListItemText?: ColorValue;
116
+ backgroundMenu?: ColorValue;
117
+ thinkingOpacity?: number;
118
+ };
119
+ };
@@ -0,0 +1,97 @@
1
+ // Message types for herm chat — parts-based like OpenCode
2
+
3
+ export type TextPart = {
4
+ type: "text"
5
+ key?: string
6
+ content: string
7
+ streaming: boolean
8
+ }
9
+
10
+ export type ToolPart = {
11
+ type: "tool"
12
+ id: string
13
+ name: string
14
+ args: string
15
+ status: "running" | "done" | "error"
16
+ startedAt?: number
17
+ duration?: number
18
+ preview?: string
19
+ result?: string
20
+ diff?: string
21
+ /** Subagent only — child tool calls accumulated from subagent.tool events. */
22
+ trail?: Array<{ name: string; preview?: string }>
23
+ /** Subagent only — goal text from subagent.start. */
24
+ goal?: string
25
+ /** Subagent only — spawn depth, 0 = direct child of the main agent. */
26
+ depth?: number
27
+ }
28
+
29
+ export type ThinkingPart = {
30
+ type: "thinking"
31
+ key?: string
32
+ content: string
33
+ streaming: boolean
34
+ }
35
+
36
+ /** Agent-originated interactive prompt. Renders inline in the
37
+ * transcript; `answered` is set (in place) once the user responds,
38
+ * collapsing the card to a one-line outcome row that persists in
39
+ * history. */
40
+ export type PromptPart = {
41
+ type: "prompt"
42
+ id: string
43
+ variant: "approval" | "clarify" | "sudo" | "secret"
44
+ req: PromptReq
45
+ answered?: { label: string; ok: boolean; at: number }
46
+ }
47
+
48
+ export type PromptReq =
49
+ | { variant: "approval"; command: string; description: string }
50
+ | { variant: "clarify"; request_id: string; question: string; choices: string[] | null }
51
+ | { variant: "sudo"; request_id: string }
52
+ | { variant: "secret"; request_id: string; prompt: string; env_var: string }
53
+
54
+ export type Part = TextPart | ToolPart | ThinkingPart | PromptPart
55
+
56
+ export type Usage = {
57
+ input: number
58
+ output: number
59
+ total: number
60
+ // Context-compression fields — populated when the agent has a
61
+ // ContextCompressor attached (default). Absent on sessions without
62
+ // compression, so consumers must guard with `typeof x === "number"`.
63
+ context_used?: number
64
+ context_max?: number
65
+ context_percent?: number
66
+ compressions?: number
67
+ }
68
+
69
+ export type Message = {
70
+ id: string
71
+ role: "user" | "assistant" | "system"
72
+ parts: Part[]
73
+ timestamp: number
74
+ model?: string
75
+ duration?: number
76
+ usage?: Usage
77
+ error?: string
78
+ }
79
+
80
+ // Helper to extract all text content from a message
81
+ export function text(msg: Message): string {
82
+ return msg.parts
83
+ .filter((p): p is TextPart => p.type === "text")
84
+ .map(p => p.content)
85
+ .join("")
86
+ }
87
+
88
+ // Create a unique message ID
89
+ export function mid(): string {
90
+ return `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
91
+ }
92
+
93
+ let pn = 0
94
+ /** Stable per-part key so React doesn't remount when parts shift index. */
95
+ export function pid(): string {
96
+ return `p${++pn}`
97
+ }
@@ -0,0 +1,64 @@
1
+ // Inline image rendering via chafa + the SGR parser (utils/chafa.ts).
2
+ // Shown in-transcript when an assistant response or user attachment contains
3
+ // MEDIA:/path/to/image.ext. Click to collapse to a compact chip; click chip
4
+ // to re-expand. Any render failure (chafa missing, file gone, timeout)
5
+ // silently degrades to the plain MediaChip — no error chrome in the stream.
6
+
7
+ import { memo, useMemo, useState } from "react"
8
+ import type { MouseEvent } from "@opentui/core"
9
+ import { useTheme } from "../theme"
10
+ import { openFile } from "../utils/open-file"
11
+ import { renderChafa, hex, chafaBin } from "../utils/chafa"
12
+ import { MediaChip } from "../components/chat/MediaChip"
13
+
14
+ const basename = (p: string) => p.split(/[/\\]/).pop() || p
15
+
16
+ type Props = { path: string; width?: number }
17
+
18
+ export const ChafaImage = memo(({ path, width }: Props) => {
19
+ const theme = useTheme().theme
20
+ const [collapsed, setCollapsed] = useState(false)
21
+ const w = Math.max(20, Math.min(80, width ?? 60))
22
+ const hasChafa = chafaBin() !== null
23
+ const result = useMemo(
24
+ () => hasChafa ? renderChafa(path, w) : ({ err: "chafa not installed" } as const),
25
+ [path, w, hasChafa],
26
+ )
27
+
28
+ // chafa missing or render failed → stream the MediaChip, no chrome
29
+ if (!hasChafa || "err" in result) return <MediaChip path={path} />
30
+
31
+ // Collapsed → chip re-expands on click. Override MediaChip's default
32
+ // openFile so the click does exactly one thing; stopPropagation keeps
33
+ // it from reaching the message's useClick (→ actions menu).
34
+ if (collapsed) {
35
+ return (
36
+ <MediaChip path={path}
37
+ onMouseDown={(e: MouseEvent) => { e.stopPropagation(); setCollapsed(false) }} />
38
+ )
39
+ }
40
+
41
+ return (
42
+ <box flexDirection="column" marginTop={1}>
43
+ <box flexDirection="column"
44
+ onMouseDown={(e: MouseEvent) => { e.stopPropagation(); setCollapsed(true) }}>
45
+ {result.rows.map((row, i) => (
46
+ <text key={i}>
47
+ {row.map((c, j) => (
48
+ <span key={j} fg={hex(c.fg)} bg={hex(c.bg)}>{c.ch}</span>
49
+ ))}
50
+ </text>
51
+ ))}
52
+ </box>
53
+ <box height={1}
54
+ onMouseDown={(e: MouseEvent) => { e.stopPropagation(); openFile(path) }}>
55
+ <text>
56
+ <span fg={theme.textMuted}>{" "}</span>
57
+ <span fg={theme.accent}>◉ </span>
58
+ <span fg={theme.text}>{basename(path)}</span>
59
+ <span fg={theme.textMuted}>{" click image to collapse · click name to open"}</span>
60
+ </text>
61
+ </box>
62
+ </box>
63
+ )
64
+ })
@@ -0,0 +1,118 @@
1
+ // Launch splash — ornate braille frame over an empty transcript, with
2
+ // wordmark, version/behind info, and a continue-last-session prompt.
3
+ // Presentational only: dismissal + Enter-to-continue live in app.tsx.
4
+
5
+ import { useRef, useState, useEffect, useMemo } from "react"
6
+ import { useRenderer } from "@opentui/react"
7
+ import { measureText, type ASCIIFontName } from "@opentui/core"
8
+ import type { BoxRenderable } from "@opentui/core"
9
+ import { useTheme } from "../theme"
10
+ import { frame } from "./splash-art"
11
+ import pkg from "../../package.json" with { type: "json" }
12
+
13
+ export type SplashInfo = {
14
+ agentVersion?: string
15
+ behind?: number | null
16
+ model?: string
17
+ }
18
+
19
+ export type SplashProps = {
20
+ /** Gateway-derived facts; undefined until session.info arrives. */
21
+ info?: SplashInfo
22
+ /** Last real TUI session — shows the continue prompt when present. */
23
+ last?: { id: string; title: string | null }
24
+ /** True once the user has typed in the composer — hides the prompt. */
25
+ composing?: boolean
26
+ /** Cron-generated first-bullet from ~/.hermes/herm/changelog.md. */
27
+ news?: string
28
+ }
29
+
30
+ // Wordmark font tiers, widest first. `measureText` is cheap (table lookup).
31
+ const TIERS: ASCIIFontName[] = ["block", "slick", "tiny"]
32
+ const pickFont = (innerW: number): ASCIIFontName =>
33
+ TIERS.find(f => measureText({ text: "HERM", font: f }).width <= innerW) ?? "tiny"
34
+
35
+ const clip = (s: string, w: number) =>
36
+ [...s].length <= w ? s : [...s].slice(0, Math.max(1, w - 1)).join("") + "…"
37
+
38
+ export function Splash(p: SplashProps) {
39
+ const theme = useTheme().theme
40
+ const ref = useRef<BoxRenderable | null>(null)
41
+ const [box, setBox] = useState({ w: 0, h: 0 })
42
+
43
+ // Measure after yoga has laid out. frameCallbacks run once per render
44
+ // tick (before the next layout pass), so this reads the previous
45
+ // frame's computed size — same one-frame latency the old 50ms poll
46
+ // had, but synced to the render loop instead of a free-running timer.
47
+ const renderer = useRenderer()
48
+ useEffect(() => {
49
+ const cb = async () => {
50
+ const r = ref.current
51
+ if (!r) return
52
+ setBox(b => (b.w === r.width && b.h === r.height) ? b : { w: r.width, h: r.height })
53
+ }
54
+ renderer.setFrameCallback(cb)
55
+ return () => renderer.removeFrameCallback(cb)
56
+ }, [renderer])
57
+
58
+ const { lines, inner } = useMemo(() => frame(box.w, box.h), [box.w, box.h])
59
+ const font = useMemo(() => pickFont(inner.w), [inner.w])
60
+
61
+ const behind = p.info?.behind
62
+ const sub = [
63
+ `v${pkg.version}`,
64
+ p.info ? `hermes ${p.info.agentVersion ?? "?"}` : "…",
65
+ behind == null ? null : behind === 0 ? "up to date" : `${behind} behind`,
66
+ p.info?.model,
67
+ ].filter(Boolean).join(" · ")
68
+
69
+ const prompt = p.last && !p.composing
70
+ const title = p.last?.title?.trim() || p.last?.id
71
+
72
+ return (
73
+ <box ref={ref} position="absolute" left={0} top={0} right={0} bottom={0}
74
+ zIndex={50} backgroundColor={theme.background}>
75
+ {lines.map((l, i) => (
76
+ <box key={i} position="absolute" top={i} left={0} height={1}>
77
+ <text fg={theme.accent}>{l}</text>
78
+ </box>
79
+ ))}
80
+ {lines.length > 0 && (
81
+ <box position="absolute" left={inner.x} top={inner.y}
82
+ width={inner.w} height={inner.h}
83
+ flexDirection="column" alignItems="center" justifyContent="center">
84
+ <box>
85
+ <ascii-font text="HERM" font={font}
86
+ color={[theme.accent, theme.textMuted]} selectable={false} />
87
+ </box>
88
+ <box height={1}>
89
+ <text fg={theme.textMuted}>{clip(sub, inner.w)}</text>
90
+ </box>
91
+ {p.news ? (
92
+ <box height={1}>
93
+ <text fg={theme.textMuted}>{clip(`› ${p.news}`, inner.w)}</text>
94
+ </box>
95
+ ) : null}
96
+ <box height={2} />
97
+ {prompt ? (
98
+ <>
99
+ <text fg={theme.textMuted}>
100
+ {"continue "}
101
+ <span fg={theme.text}>"{clip(title ?? "", Math.max(8, inner.w - 14))}"</span>
102
+ {" ?"}
103
+ </text>
104
+ <text fg={theme.textMuted}>
105
+ <span fg={theme.accent}>[enter]</span>
106
+ {" yes · type to start fresh"}
107
+ </text>
108
+ </>
109
+ ) : (
110
+ <text fg={theme.textMuted}>
111
+ <span fg={theme.accent}>[enter]</span> to send
112
+ </text>
113
+ )}
114
+ </box>
115
+ )}
116
+ </box>
117
+ )
118
+ }
@@ -0,0 +1,28 @@
1
+ // Hoisted BorderCharacters constants. @opentui/react's host
2
+ // reconciler compares props by reference (`newProp !== oldProp`), so
3
+ // an inline `customBorderChars={{…}}` re-sets the renderable's border
4
+ // config and calls `requestRender()` on every parent reconcile even
5
+ // when nothing changed. Module-level objects fix the identity.
6
+
7
+ import type { BorderCharacters } from "@opentui/core"
8
+
9
+ /** Left-edge heavy bar only — panel/card accent. */
10
+ export const LEFT_BAR: BorderCharacters = {
11
+ topLeft: "", bottomLeft: "", topRight: "", bottomRight: "",
12
+ horizontal: "", vertical: "┃",
13
+ topT: "", bottomT: "", leftT: "", rightT: "", cross: "",
14
+ }
15
+
16
+ /** Light single vertical on both sides, no horizontals. */
17
+ export const SIDE_PIPE: BorderCharacters = {
18
+ topLeft: "│", bottomLeft: "│", vertical: "│",
19
+ topRight: "│", bottomRight: "│", horizontal: "",
20
+ topT: "", bottomT: "", leftT: "", rightT: "", cross: "",
21
+ }
22
+
23
+ /** Corners only — the Context heat-grid frame. */
24
+ export const CORNERS: BorderCharacters = {
25
+ topLeft: "┌", topRight: "┐", bottomLeft: "└", bottomRight: "┘",
26
+ horizontal: " ", vertical: " ",
27
+ topT: " ", bottomT: " ", leftT: " ", rightT: " ", cross: " ",
28
+ }