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,123 @@
1
+ // GENERATED by scripts/bake-splash.ts — do not edit.
2
+ // Baked braille 9-patch frame pieces for the launch splash (herm-tji.2).
3
+ // Source: docs/splash/frame/nine/2-*.png @ PICK.md settings.
4
+
5
+ /* eslint-disable */
6
+
7
+ export const FRAME = { cw: 16, ch: 8, tw: 20, tv: 8 } as const
8
+
9
+ const TL = [
10
+ "⠀⢀⣤⠤⢄⣀⠄⢀⣠⣤⣄⡤⡄⡀⠀⠀",
11
+ "⠀⣜⡁⢩⣈⡂⢀⣋⣭⠉⠈⢈⣮⣻⡑⣶",
12
+ "⠀⢸⡖⢿⠏⣤⣶⣽⣫⢶⣢⡌⠹⣧⡏⠻",
13
+ "⠀⠈⡤⢒⣦⢻⣿⣿⣿⢿⣅⡇⣆⡉⠂⢀",
14
+ "⠁⢸⡏⠘⠋⢞⢳⣿⣿⣟⡍⡍⣤⠅⠀⢨",
15
+ "⠀⠤⢯⣆⣀⠙⢦⣿⡋⢀⣜⠇⣁⣒⣊⣉",
16
+ "⠀⢀⣷⣝⣻⣶⣶⢄⠍⠘⡁⡇⣧⣠⣤⡢",
17
+ "⠀⠀⠘⢎⢿⣯⠃⠁⡤⣚⡼⠀⡏⣹⣿⡩",
18
+ ]
19
+
20
+ const TR = [
21
+ "⠀⠀⢀⢠⢠⣠⣤⣀⡀⠠⣀⡠⠤⣤⣀⠀",
22
+ "⣶⢊⣟⣵⡁⠁⠉⣭⣙⠀⢐⣂⡍⢈⣣⠀",
23
+ "⠟⢹⣼⠏⢡⣔⢶⣝⣯⣶⣤⠹⡿⢲⡇⠀",
24
+ "⡀⠁⢉⣰⢸⣨⡿⣿⣿⣿⡟⣴⡒⢤⠁⠀",
25
+ "⡅⠄⠨⣤⢩⢩⣻⣿⣿⡞⡳⠙⠃⢹⡇⠀",
26
+ "⣉⣑⣒⣈⠸⣣⡀⢙⣿⡴⠋⣀⣰⡽⠤⢀",
27
+ "⢄⣤⣄⣸⢸⢈⠃⠩⡠⣶⣶⣟⣫⣾⠂⠀",
28
+ "⢍⣿⢟⢹⠀⢧⣒⢤⠁⠈⣽⡿⡱⠇⠀⠀",
29
+ ]
30
+
31
+ const BL = [
32
+ "⠀⠀⣀⣿⣿⡟⠁⠀⠻⢬⣳⠀⣇⣲⣟⢿",
33
+ "⠀⢐⡺⣛⡯⣭⠷⠌⢂⢀⡂⡇⡏⠙⠛⠧",
34
+ "⠀⠖⡼⠉⠉⢠⣰⠥⢭⠘⣛⣄⢋⣉⣉⡙",
35
+ "⠀⢸⡌⢀⣠⣵⣿⣿⣿⣿⣨⠃⠷⠂⠐⢍",
36
+ "⠀⠀⠻⠝⠿⣴⣿⣿⡿⣿⣟⣋⡏⡁⠄⠘",
37
+ "⠀⢸⣰⣶⣄⠻⠿⣿⣹⠰⠟⢂⢠⡟⣆⣴",
38
+ "⠀⢪⡉⠸⣻⠇⠀⡝⣛⢀⡀⣘⡟⡷⣫⡯",
39
+ "⠀⠙⠻⠪⠜⠓⠂⠈⠛⠓⠛⠙⠚⠈⠁⠀",
40
+ ]
41
+
42
+ const BR = [
43
+ "⡿⣻⣖⣸⠀⣞⡡⠟⢀⠄⢻⣿⣿⣀⠀⠀",
44
+ "⠶⠛⠋⢹⢸⢐⡀⡐⠡⠾⣭⢽⣛⢗⡂⠀",
45
+ "⢋⣉⣉⡙⣠⣛⠃⡭⠬⣆⡄⠉⠩⢧⠲⠀",
46
+ "⡩⠂⠐⠾⠘⣅⣿⣿⣿⣿⣮⣄⡀⢱⡇⠀",
47
+ "⠃⢀⢈⢳⣙⣻⣿⣟⣿⣿⣦⠿⠫⠟⠀⠀",
48
+ "⣦⣰⢻⡄⡐⠻⠃⣏⣿⠿⠟⣠⣶⣆⡇⠀",
49
+ "⢽⣝⢯⢻⣃⢀⡀⣛⣩⠀⠸⣟⠇⢉⡕⠀",
50
+ "⠁⠀⠁⠓⠋⠛⠚⠛⠁⠐⠚⠣⠇⠟⠋⠀",
51
+ ]
52
+
53
+ const T = [
54
+ "⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
55
+ "⡄⣢⣴⣶⠶⠖⠲⣌⠘⠉⠢⡛⢡⠴⠲⠶⣰⢖⢴⣤",
56
+ "⣾⣥⠿⠀⣠⢰⠿⢾⡐⠾⠿⢇⡳⣿⣗⠄⠀⠣⣑⣵",
57
+ "⢾⡟⠄⠐⢭⣍⢖⡄⠨⢻⣫⠽⡼⡿⢽⢥⡂⠄⠻⡽",
58
+ "⠓⡻⢶⣄⡈⠘⠭⠚⠍⢻⡉⠋⠋⠭⠃⠃⡡⣶⣟⢾",
59
+ "⠁⠄⠉⠉⠚⠤⠤⠬⠟⠰⠧⠊⠯⠴⠤⠓⠛⠉⠐⠢",
60
+ "⣛⣛⡟⣛⡛⣛⣛⢛⣛⣛⡛⣛⣛⢛⣻⣻⣟⠛⣻⢻",
61
+ "⣊⣉⣉⣛⣋⣙⣋⣼⣷⣥⣯⣺⣋⣵⣷⣭⣙⣑⣻⣽",
62
+ ]
63
+
64
+ const B = [
65
+ "⣿⢿⣿⣿⢿⣿⡿⡿⣿⣿⠿⣿⢿⡿⣿⣿⡿⣿⡿⢿",
66
+ "⣃⣛⣈⣓⣚⣚⣃⣙⣛⣉⣛⣛⣁⣛⣙⣙⣋⣘⣉⣙",
67
+ "⠠⢄⢄⣀⡤⣤⠐⣠⢄⢠⡄⡤⣄⠀⡤⢄⣀⡀⢀⢀",
68
+ "⣱⠬⠫⠑⢁⣠⢠⡫⣡⣠⣤⣉⢅⢄⣄⠉⠻⡐⢥⣌",
69
+ "⢔⣈⠀⢰⡁⢶⣿⣿⣟⣿⣃⡛⠕⠍⣦⣃⡄⠂⣹⡢",
70
+ "⡿⢏⢄⠀⠃⣫⣿⢜⢩⣶⣦⠉⡶⣾⡖⠛⠀⣠⡛⡿",
71
+ "⠼⢾⠿⣵⣖⣘⠴⠃⠈⢆⢀⠀⡳⠤⣂⣲⣾⠯⠚⠏",
72
+ "⠀⠀⠁⠀⠀⠀⠀⠈⠉⠙⠋⠉⠁⠀⠀⠀⠀⠀⠀⠀",
73
+ ]
74
+
75
+ const L = [
76
+ "⠀⠀⢐⢟⣾⠿⠮⠶⡷⣪⠾⠂⡗⢭⢿⢹",
77
+ "⠀⠀⣨⡕⠉⡡⠤⣁⡌⠪⢧⠁⡇⣰⣿⢼",
78
+ "⠀⠀⠹⡃⢾⣕⣷⡦⣓⡀⡉⡆⡏⣶⡣⣻",
79
+ "⠀⢰⡶⢬⣭⡜⣿⣿⣯⢈⢓⠁⡏⣚⡾⣿",
80
+ "⠀⠘⡛⢊⣙⠣⢇⢯⣿⠨⡭⡁⡧⢼⣲⣿",
81
+ "⠀⠀⢱⡉⢿⡇⠤⣝⡄⠀⡁⠁⡏⣶⢖⢿",
82
+ "⠀⠀⢰⣧⡀⠓⠓⠉⢁⣴⡍⠀⡇⠺⠽⢺",
83
+ "⠀⠀⠨⠺⣽⣷⣦⡴⡚⠃⢀⠀⡇⡾⣿⢹",
84
+ ]
85
+
86
+ const R = [
87
+ "⡏⡿⡭⢺⢀⠷⢝⢾⠶⠵⠿⣷⡻⡂⠀⠀",
88
+ "⡧⣿⣆⢸⠀⡼⠕⢡⣀⠤⢌⠉⢪⣅⠁⠀",
89
+ "⣟⢜⣶⢹⢰⢉⢀⣚⢴⣾⣪⡷⢘⠏⠀⠀",
90
+ "⣿⢷⡛⢹⠈⡚⡁⣽⣿⣿⢣⣭⡥⢶⡆⠀",
91
+ "⣿⣖⡧⢼⢈⢭⠅⣿⡽⡸⡘⣋⡑⢛⠃⠀",
92
+ "⡿⡲⣶⢹⠈⢈⠀⢠⣫⠤⢸⡿⢉⡆⠀⠀",
93
+ "⡗⠯⠗⢸⠀⢩⣦⡈⠉⠚⠚⢀⣼⡆⠀⠀",
94
+ "⡏⣿⢯⢸⠀⢀⠘⢓⢦⢶⣾⣯⠗⠅⠀⠀",
95
+ ]
96
+
97
+ export type Inner = { x: number; y: number; w: number; h: number }
98
+
99
+ /** Assemble the frame at terminal size. Returns the full row list plus
100
+ * the inner text window (where wordmark + info + prompt go). Rows are
101
+ * exactly `w` grapheme-columns wide. Returns no frame below minimum. */
102
+ export function frame(w: number, h: number): { lines: string[]; inner: Inner } {
103
+ const { cw, ch, tw, tv } = FRAME
104
+ const mw = w - 2 * cw
105
+ const mh = h - 2 * ch
106
+ const inner: Inner = { x: cw, y: ch, w: Math.max(0, mw), h: Math.max(0, mh) }
107
+ if (mw < 4 || mh < 2) return { lines: [], inner }
108
+
109
+ const repH = (p: string[], span: number) =>
110
+ p.map(l => l.repeat(Math.ceil(span / tw)).slice(0, span))
111
+ const repV = (p: string[], span: number) =>
112
+ Array.from({ length: span }, (_, i) => p[i % tv])
113
+
114
+ const t = repH(T, mw), b = repH(B, mw)
115
+ const l = repV(L, mh), r = repV(R, mh)
116
+ const mid = " ".repeat(mw)
117
+
118
+ const out: string[] = []
119
+ for (let i = 0; i < ch; i++) out.push(TL[i] + t[i] + TR[i])
120
+ for (let i = 0; i < mh; i++) out.push(l[i] + mid + r[i])
121
+ for (let i = 0; i < ch; i++) out.push(BL[i] + b[i] + BR[i])
122
+ return { lines: out, inner }
123
+ }
@@ -0,0 +1,117 @@
1
+ import { useRef, useEffect, type ReactNode } from "react"
2
+ import type { RGBA } from "@opentui/core"
3
+ import { useTheme } from "../theme"
4
+ import * as prefs from "../utils/preferences"
5
+
6
+ // Flex-cell column primitive for list tabs. Replaces the .padEnd(N)
7
+ // single-<text> pattern that bleeds whenever a value exceeds its pad
8
+ // width or the terminal narrows. A Col is either fixed-width-clipped
9
+ // (w) or grow-truncated (grow); height=1 + overflow=hidden guarantees
10
+ // single-line, so the worst case is an ellipsis-free cut, never a
11
+ // shove into the neighbouring column.
12
+
13
+ // Scrollbox v-bar steals 1 col from body rows. Headers that sit
14
+ // outside the scrollbox pad by the same so the grow column lands on
15
+ // identical x in both. Requires the scrollbox to force its v-bar
16
+ // visible (auto-hide would make the gutter conditional → post-layout
17
+ // feedback loop).
18
+ export const VBAR_W = 1
19
+
20
+ // Stable prop for list scrollboxes so `updateProperties`' `!==`
21
+ // check doesn't re-set the scrollbar config on every host reconcile.
22
+ // Inline `{{ visible: true }}` is a new object each render → every
23
+ // reconcile triggers `setProperty → requestRender()` for nothing.
24
+ export const VBAR = { visible: true } as const
25
+
26
+ export const Col = (p: {
27
+ /** Fixed width in cells. Mutually exclusive with `grow`. */
28
+ w?: number
29
+ /** Take remaining width; truncates under narrow terminals. */
30
+ grow?: boolean
31
+ /** Floor for a grow column (default 12). Ignored when `w` is set. */
32
+ min?: number
33
+ right?: boolean
34
+ fg?: RGBA
35
+ bold?: boolean
36
+ children: string
37
+ }) => {
38
+ const theme = useTheme().theme
39
+ const fg = p.fg ?? theme.text
40
+ return (
41
+ <box width={p.w} flexGrow={p.grow ? 1 : 0} flexShrink={p.grow ? 1 : 0}
42
+ minWidth={p.grow ? (p.min ?? 12) : p.w} height={1} overflow="hidden"
43
+ flexDirection="row" justifyContent={p.right ? "flex-end" : "flex-start"}>
44
+ <text>{p.bold
45
+ ? <span fg={fg}><strong>{p.children}</strong></span>
46
+ : <span fg={fg}>{p.children}</span>}</text>
47
+ </box>
48
+ )
49
+ }
50
+
51
+ // Header row container. paddingRight mirrors the body scrollbox's
52
+ // v-bar so header and data Cols share available width.
53
+ export const Hdr = (p: { children: ReactNode }) => (
54
+ <box flexDirection="row" height={1} paddingRight={VBAR_W}>
55
+ {p.children}
56
+ </box>
57
+ )
58
+
59
+ // A Col that horizontal-scrolls its text while active. The box still
60
+ // truncates via overflow; the string is just rotated each tick so the
61
+ // clipped slice advances. Only animates when the full text doesn't
62
+ // fit (measured post-layout from the renderable's width), so
63
+ // non-truncated cells and unselected rows don't tick.
64
+ export const Marquee = (p: {
65
+ w?: number; grow?: boolean; min?: number
66
+ fg?: RGBA; bold?: boolean
67
+ active: boolean
68
+ /** ms per character step (default 180). */
69
+ speed?: number
70
+ /** ms to sit still before scrolling starts (default 600). */
71
+ hold?: number
72
+ children: string
73
+ }) => {
74
+ const theme = useTheme().theme
75
+ const fg = p.fg ?? theme.text
76
+ const text = p.children
77
+ const box = useRef<import("@opentui/core").BoxRenderable | null>(null)
78
+ const node = useRef<import("@opentui/core").TextRenderable | null>(null)
79
+
80
+ const animate = prefs.get("animations") !== false && p.active
81
+ useEffect(() => {
82
+ const tn = node.current
83
+ if (!tn) return
84
+ if (!animate) { tn.scrollX = 0; return }
85
+ // Hold static briefly before scrolling so the cell is readable at
86
+ // rest on select; also keeps frame-snapshot tests deterministic.
87
+ // scrollX on the TextRenderable is a direct native paint request
88
+ // — zero React reconciles per tick (vs ~5/s at 180ms with the
89
+ // previous setState(off)).
90
+ let id: ReturnType<typeof setInterval> | undefined
91
+ const period = text.length + GAP.length
92
+ const hold = setTimeout(() => {
93
+ id = setInterval(() => {
94
+ const w = box.current?.width ?? 0
95
+ if (text.length <= w) { tn.scrollX = 0; return }
96
+ tn.scrollX = (tn.scrollX + 1) % period
97
+ }, p.speed ?? 180)
98
+ }, p.hold ?? 600)
99
+ return () => {
100
+ clearTimeout(hold); if (id) clearInterval(id)
101
+ if (node.current) node.current.scrollX = 0
102
+ }
103
+ }, [animate, text, p.speed, p.hold])
104
+
105
+ // `text + GAP + text` renders once; scrollX wraps at period so the
106
+ // visible window always has GAP-then-head following the tail.
107
+ return (
108
+ <box ref={box}
109
+ width={p.w} flexGrow={p.grow ? 1 : 0} flexShrink={p.grow ? 1 : 0}
110
+ minWidth={p.grow ? (p.min ?? 12) : p.w} height={1} overflow="hidden">
111
+ <text ref={node} wrapMode="none">{p.bold
112
+ ? <span fg={fg}><strong>{text + GAP + text}</strong></span>
113
+ : <span fg={fg}>{text + GAP + text}</span>}</text>
114
+ </box>
115
+ )
116
+ }
117
+ const GAP = " "
@@ -0,0 +1,90 @@
1
+ // Single-line styled text that horizontally auto-scrolls when active.
2
+ //
3
+ // Differs from ui/table.tsx Marquee in two ways:
4
+ // 1. Content is a ReactNode (styled <span>s), not a plain string —
5
+ // the component can't slice it, so it animates the text node's
6
+ // native scrollX instead of rebuilding a substring each tick.
7
+ // 2. Because scrollX is driven via ref (not React state), there's
8
+ // exactly one React render regardless of scroll position. At
9
+ // 35ms/char that's 0 extra renders vs Marquee's ~28/s.
10
+ //
11
+ // The trade-off: no gap-and-loop. When scrollX hits maxScrollX the
12
+ // animation reverses back to 0 (ping-pong). Cheaper than duplicating
13
+ // the span tree to fake a seamless loop.
14
+
15
+ import { useEffect, useRef, type ReactNode } from "react"
16
+ import type { TextRenderable } from "@opentui/core"
17
+ import * as prefs from "../utils/preferences"
18
+
19
+ export const Ticker = (p: {
20
+ active: boolean
21
+ /** ms per cell (default 35 — fast). */
22
+ speed?: number
23
+ /** ms to sit still before scrolling (default 150). */
24
+ hold?: number
25
+ fg?: import("@opentui/core").RGBA
26
+ children: ReactNode
27
+ }) => {
28
+ const ref = useRef<TextRenderable | null>(null)
29
+
30
+ const animate = prefs.get("animations") !== false && p.active
31
+ useEffect(() => {
32
+ const node = ref.current
33
+ if (!node) return
34
+ if (!animate) { node.scrollX = 0; return }
35
+ let dir = 1
36
+ let id: ReturnType<typeof setInterval> | undefined
37
+ const hold = setTimeout(() => {
38
+ id = setInterval(() => {
39
+ const max = node.maxScrollX
40
+ if (max <= 0) return
41
+ const next = node.scrollX + dir
42
+ if (next >= max) { dir = -1; node.scrollX = max; return }
43
+ if (next <= 0) { dir = 1; node.scrollX = 0; return }
44
+ node.scrollX = next
45
+ }, p.speed ?? 35)
46
+ }, p.hold ?? 150)
47
+ return () => {
48
+ clearTimeout(hold)
49
+ if (id) clearInterval(id)
50
+ if (ref.current) ref.current.scrollX = 0
51
+ }
52
+ }, [animate, p.speed, p.hold])
53
+
54
+ return (
55
+ <box flexGrow={1} flexShrink={1} minWidth={0} height={1} overflow="hidden">
56
+ <text ref={ref} wrapMode="none" fg={p.fg}>{p.children}</text>
57
+ </box>
58
+ )
59
+ }
60
+
61
+ // ─── Inline markdown → spans ─────────────────────────────────────────
62
+ // Just enough for a one-line peek: **bold**, `code`, _italic_/*italic*.
63
+ // Block syntax (headings, lists, fences) was already flattened by the
64
+ // caller's whitespace collapse; we strip the markers we don't style.
65
+
66
+ type Seg = { t: string; b?: boolean; c?: boolean; i?: boolean }
67
+
68
+ // Order matters — code first so ** inside backticks stays literal.
69
+ // Single * / _ require a non-word char (or start/end) on the outer
70
+ // side so snake_case and a*b don't become italics.
71
+ const RX = /(`[^`]+`)|(\*\*[^*]+\*\*)|(__[^_]+__)|((?<![\w*])\*[^*\s][^*]*\*(?![\w*]))|((?<!\w)_[^_\s][^_]*_(?!\w))/g
72
+
73
+ /** Tokenize one line of collapsed markdown into styled segments. */
74
+ export const inline = (s: string): Seg[] => {
75
+ const out: Seg[] = []
76
+ let last = 0
77
+ for (const m of s.matchAll(RX)) {
78
+ const at = m.index ?? 0
79
+ if (at > last) out.push({ t: s.slice(last, at) })
80
+ const hit = m[0]
81
+ if (hit.startsWith("`")) out.push({ t: hit.slice(1, -1), c: true })
82
+ else if (hit.startsWith("**") || hit.startsWith("__"))
83
+ out.push({ t: hit.slice(2, -2), b: true })
84
+ else out.push({ t: hit.slice(1, -1), i: true })
85
+ last = at + hit.length
86
+ }
87
+ if (last < s.length) out.push({ t: s.slice(last) })
88
+ // Scrub residual block markers that survived the collapse.
89
+ return out.map(seg => seg.c ? seg : { ...seg, t: seg.t.replace(/^#{1,6}\s+/, "") })
90
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Toast notification system — auto-dismiss messages.
3
+ *
4
+ * Usage:
5
+ * <ToastProvider><App /></ToastProvider>
6
+ *
7
+ * const toast = useToast()
8
+ * toast.show({ variant: "success", message: "Done!" })
9
+ * toast.error(new Error("oops"))
10
+ */
11
+
12
+ import { createContext, useContext, useState, useCallback, useRef, useMemo, useEffect } from "react"
13
+ import type { ReactNode } from "react"
14
+ import { useTheme } from "../theme"
15
+ import type { RGBA } from "@opentui/core"
16
+
17
+ type ToastVariant = "info" | "error" | "warning" | "success"
18
+
19
+ type ToastOptions = {
20
+ readonly variant: ToastVariant
21
+ readonly title?: string
22
+ readonly message: string
23
+ readonly duration?: number
24
+ /** Clickable affordance on the toast (e.g. "view" → open dialog). */
25
+ readonly action?: { label: string; run: () => void }
26
+ }
27
+
28
+ type ToastEntry = ToastOptions & {
29
+ readonly id: number
30
+ }
31
+
32
+ type ToastContext = {
33
+ readonly show: (opts: ToastOptions) => void
34
+ readonly error: (err: Error) => void
35
+ }
36
+
37
+ const Ctx = createContext<ToastContext | null>(null)
38
+
39
+ const DEFAULT_DURATION = 3000
40
+
41
+ export const ToastProvider = ({ children }: { children: ReactNode }) => {
42
+ const [items, setItems] = useState<ToastEntry[]>([])
43
+ const counter = useRef(0)
44
+ const timers = useRef(new Map<number, ReturnType<typeof setTimeout>>())
45
+
46
+ useEffect(() => () => {
47
+ for (const t of timers.current.values()) clearTimeout(t)
48
+ }, [])
49
+
50
+ const show = useCallback((opts: ToastOptions) => {
51
+ const id = ++counter.current
52
+ setItems(prev => [...prev, { ...opts, id }])
53
+ const dur = opts.duration ?? DEFAULT_DURATION
54
+ timers.current.set(id, setTimeout(() => {
55
+ timers.current.delete(id)
56
+ setItems(prev => prev.filter(t => t.id !== id))
57
+ }, dur))
58
+ }, [])
59
+
60
+ const error = useCallback((err: Error) => {
61
+ show({ variant: "error", title: "Error", message: err.message })
62
+ }, [show])
63
+
64
+ const value = useMemo<ToastContext>(() => ({ show, error }), [show, error])
65
+
66
+ return (
67
+ <Ctx.Provider value={value}>
68
+ {children}
69
+ {items.length > 0 ? <ToastOverlay items={items} /> : null}
70
+ </Ctx.Provider>
71
+ )
72
+ }
73
+
74
+ const ToastOverlay = ({ items }: { items: ReadonlyArray<ToastEntry> }) => {
75
+ const theme = useTheme().theme
76
+
77
+ const color = (variant: ToastVariant): RGBA => {
78
+ switch (variant) {
79
+ case "error": return theme.error
80
+ case "warning": return theme.warning
81
+ case "success": return theme.success
82
+ default: return theme.info
83
+ }
84
+ }
85
+
86
+ return (
87
+ <box
88
+ position="absolute"
89
+ top={2}
90
+ right={2}
91
+ flexDirection="column"
92
+ gap={1}
93
+ zIndex={200}
94
+ maxWidth={60}
95
+ >
96
+ {items.map(item => (
97
+ <box
98
+ key={item.id}
99
+ backgroundColor={theme.backgroundPanel}
100
+ border={["left"] as const}
101
+ borderStyle="single"
102
+ borderColor={color(item.variant)}
103
+ paddingLeft={1}
104
+ paddingRight={1}
105
+ flexDirection="column"
106
+ >
107
+ {item.title ? (
108
+ <text fg={theme.text}>
109
+ <strong>{item.title}</strong>
110
+ </text>
111
+ ) : null}
112
+ <text fg={theme.textMuted} wrapMode="word">
113
+ {item.message}
114
+ </text>
115
+ {item.action ? (
116
+ <box height={1} marginTop={0} onMouseDown={item.action.run}>
117
+ <text fg={color(item.variant)}><u>{item.action.label}</u></text>
118
+ </box>
119
+ ) : null}
120
+ </box>
121
+ ))}
122
+ </box>
123
+ )
124
+ }
125
+
126
+ export const useToast = (): ToastContext => {
127
+ const ctx = useContext(Ctx)
128
+ if (!ctx) throw new Error("useToast() must be inside <ToastProvider>")
129
+ return ctx
130
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Categorical color ramp — golden-angle HSL walk anchored on a seed color.
3
+ *
4
+ * Used by the Context grid where N adjacent category swatches must be
5
+ * mutually distinguishable. Theme-semantic keys (info/accent/…) weren't
6
+ * designed for that; this generates the ramp at runtime so no per-theme
7
+ * palette is needed.
8
+ */
9
+
10
+ import { RGBA } from "@opentui/core"
11
+
12
+ /** Golden angle in degrees — maximally irrational, so successive hues spread evenly for any N. */
13
+ const GOLDEN_ANGLE = 137.50776405003785
14
+
15
+ export function luminance(c: RGBA): number {
16
+ return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b
17
+ }
18
+
19
+ /** RGBA (0–1 floats) → [h°, s, l] with h in [0,360), s/l in [0,1]. */
20
+ export function rgbaToHsl(c: RGBA): [number, number, number] {
21
+ const r = c.r, g = c.g, b = c.b
22
+ const max = Math.max(r, g, b), min = Math.min(r, g, b)
23
+ const l = (max + min) / 2
24
+ const d = max - min
25
+ if (d === 0) return [0, 0, l]
26
+ const s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
27
+ let h: number
28
+ switch (max) {
29
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break
30
+ case g: h = (b - r) / d + 2; break
31
+ default: h = (r - g) / d + 4
32
+ }
33
+ return [h * 60, s, l]
34
+ }
35
+
36
+ /** [h°, s, l] → RGBA (0–1 floats, alpha=1). */
37
+ export function hslToRgba(h: number, s: number, l: number): RGBA {
38
+ h = ((h % 360) + 360) % 360 / 360
39
+ if (s === 0) return RGBA.fromValues(l, l, l, 1)
40
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s
41
+ const p = 2 * l - q
42
+ const ch = (t: number) => {
43
+ if (t < 0) t += 1
44
+ if (t > 1) t -= 1
45
+ if (t < 1 / 6) return p + (q - p) * 6 * t
46
+ if (t < 1 / 2) return q
47
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
48
+ return p
49
+ }
50
+ return RGBA.fromValues(ch(h + 1 / 3), ch(h), ch(h - 1 / 3), 1)
51
+ }
52
+
53
+ /**
54
+ * Generate N categorical colors.
55
+ *
56
+ * Hue starts at `seed`'s hue and steps by the golden angle. Saturation and
57
+ * lightness are picked from `bg` luminance so swatches stay legible on both
58
+ * dark and light themes without per-theme tuning. Slot i is stable across
59
+ * calls: same id → same slot → same hue family on every theme.
60
+ */
61
+ export function categorical(seed: RGBA, bg: RGBA, n: number): RGBA[] {
62
+ const [h0] = rgbaToHsl(seed)
63
+ const dark = luminance(bg) < 0.5
64
+ const s = dark ? 0.60 : 0.70
65
+ const l = dark ? 0.62 : 0.42
66
+ const out: RGBA[] = []
67
+ for (let i = 0; i < n; i++) out.push(hslToRgba(h0 + i * GOLDEN_ANGLE, s, l))
68
+ return out
69
+ }
70
+
71
+ /** Minimum hue separation (degrees) across N golden-angle slots. Useful for test assertions. */
72
+ export function minHueSeparation(n: number): number {
73
+ const hs = Array.from({ length: n }, (_, i) => (i * GOLDEN_ANGLE) % 360).sort((a, b) => a - b)
74
+ let min = 360 - hs[n - 1] + hs[0]
75
+ for (let i = 1; i < n; i++) min = Math.min(min, hs[i] - hs[i - 1])
76
+ return min
77
+ }