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

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 (188) hide show
  1. package/db.worker.js +81 -0
  2. package/highlights-eq9cgrbb.scm +604 -0
  3. package/highlights-ghv9g403.scm +205 -0
  4. package/highlights-hk7bwhj4.scm +284 -0
  5. package/highlights-r812a2qc.scm +150 -0
  6. package/highlights-x6tmsnaa.scm +115 -0
  7. package/index.js +10374 -0
  8. package/injections-73j83es3.scm +27 -0
  9. package/package.json +14 -64
  10. package/parser.worker.js +8 -0
  11. package/tree-sitter-3jzf13jk.wasm +0 -0
  12. package/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
  13. package/tree-sitter-markdown-411r6y9b.wasm +0 -0
  14. package/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
  15. package/tree-sitter-typescript-zxjzwt75.wasm +0 -0
  16. package/tree-sitter-zig-e78zbjpm.wasm +0 -0
  17. package/scripts/postinstall.ts +0 -29
  18. package/src/app/gateway.tsx +0 -83
  19. package/src/app/gatewayEvents.ts +0 -203
  20. package/src/app/launch.ts +0 -41
  21. package/src/app/skin.tsx +0 -31
  22. package/src/app/spawnHistory.ts +0 -75
  23. package/src/app/tabs.ts +0 -23
  24. package/src/app/turnReducer.ts +0 -390
  25. package/src/app/useAppKeys.ts +0 -268
  26. package/src/app/useAtRefPopover.ts +0 -99
  27. package/src/app/useInputHistory.ts +0 -66
  28. package/src/app/useSession.ts +0 -102
  29. package/src/app/useSlashCommands.ts +0 -70
  30. package/src/app/useSlashPopover.ts +0 -48
  31. package/src/app.tsx +0 -917
  32. package/src/commands/slash.ts +0 -151
  33. package/src/components/avatar/AnimatedAvatar.tsx +0 -66
  34. package/src/components/avatar/eikon.ts +0 -144
  35. package/src/components/avatar/states/error.ts +0 -1155
  36. package/src/components/avatar/states/idle.ts +0 -1155
  37. package/src/components/avatar/states/index.ts +0 -30
  38. package/src/components/avatar/states/listening.ts +0 -1155
  39. package/src/components/avatar/states/speaking.ts +0 -1155
  40. package/src/components/avatar/states/thinking.ts +0 -1155
  41. package/src/components/avatar/states/working.ts +0 -1155
  42. package/src/components/chat/AtRefPopover.tsx +0 -54
  43. package/src/components/chat/CodeBlock.tsx +0 -67
  44. package/src/components/chat/Composer.tsx +0 -347
  45. package/src/components/chat/DiffBlock.tsx +0 -116
  46. package/src/components/chat/ErrorBlock.tsx +0 -70
  47. package/src/components/chat/MediaChip.tsx +0 -114
  48. package/src/components/chat/MessageItem.tsx +0 -282
  49. package/src/components/chat/MessageList.tsx +0 -114
  50. package/src/components/chat/PromptCard.tsx +0 -359
  51. package/src/components/chat/SlashPopover.tsx +0 -158
  52. package/src/components/chat/ThoughtCloud.tsx +0 -185
  53. package/src/components/chat/TypingIndicator.tsx +0 -25
  54. package/src/components/chat/tool/Subagent.tsx +0 -75
  55. package/src/components/chat/tool/frame.tsx +0 -69
  56. package/src/components/chat/tool/index.tsx +0 -65
  57. package/src/components/chat/tool/preview.ts +0 -57
  58. package/src/components/sidebar/ContextGauge.tsx +0 -102
  59. package/src/components/sidebar/Sidebar.tsx +0 -143
  60. package/src/components/tabs/TabBar.tsx +0 -50
  61. package/src/components/ui/FileLink.tsx +0 -52
  62. package/src/config/index.ts +0 -156
  63. package/src/config/lane.ts +0 -161
  64. package/src/config/models.ts +0 -95
  65. package/src/config/rules.ts +0 -80
  66. package/src/config/schema.ts +0 -308
  67. package/src/dialogs/alert.tsx +0 -52
  68. package/src/dialogs/chafa.tsx +0 -72
  69. package/src/dialogs/confirm.tsx +0 -58
  70. package/src/dialogs/curator.tsx +0 -153
  71. package/src/dialogs/eikon-picker.tsx +0 -95
  72. package/src/dialogs/help.tsx +0 -80
  73. package/src/dialogs/history.tsx +0 -92
  74. package/src/dialogs/info.tsx +0 -115
  75. package/src/dialogs/keys.tsx +0 -170
  76. package/src/dialogs/logs.tsx +0 -42
  77. package/src/dialogs/message.tsx +0 -38
  78. package/src/dialogs/model-picker.tsx +0 -123
  79. package/src/dialogs/new-profile.tsx +0 -69
  80. package/src/dialogs/new-task.tsx +0 -103
  81. package/src/dialogs/profile.tsx +0 -55
  82. package/src/dialogs/rollback.tsx +0 -190
  83. package/src/dialogs/spawn-history.tsx +0 -80
  84. package/src/dialogs/text-prompt.tsx +0 -68
  85. package/src/dialogs/theme-picker.tsx +0 -50
  86. package/src/home/index.ts +0 -23
  87. package/src/home/store.ts +0 -267
  88. package/src/index.tsx +0 -113
  89. package/src/keys/catalog.ts +0 -115
  90. package/src/keys/chord.ts +0 -125
  91. package/src/keys/conflicts.ts +0 -48
  92. package/src/keys/context.tsx +0 -112
  93. package/src/keys/index.ts +0 -5
  94. package/src/keys/list.ts +0 -94
  95. package/src/keys/oc-compat.ts +0 -87
  96. package/src/tabs/Agents.tsx +0 -607
  97. package/src/tabs/Analytics.tsx +0 -154
  98. package/src/tabs/Chat.tsx +0 -50
  99. package/src/tabs/Config.tsx +0 -605
  100. package/src/tabs/Context.tsx +0 -599
  101. package/src/tabs/Cron.tsx +0 -294
  102. package/src/tabs/Env.tsx +0 -227
  103. package/src/tabs/Kanban.tsx +0 -367
  104. package/src/tabs/Memory.tsx +0 -294
  105. package/src/tabs/Sessions.tsx +0 -786
  106. package/src/tabs/Skills.tsx +0 -507
  107. package/src/tabs/Toolsets.tsx +0 -266
  108. package/src/theme/builtin.ts +0 -78
  109. package/src/theme/context.tsx +0 -106
  110. package/src/theme/index.ts +0 -4
  111. package/src/theme/resolve.ts +0 -134
  112. package/src/theme/syntax.ts +0 -31
  113. package/src/theme/themes/aura.json +0 -69
  114. package/src/theme/themes/ayu.json +0 -80
  115. package/src/theme/themes/carbonfox.json +0 -248
  116. package/src/theme/themes/catppuccin-frappe.json +0 -233
  117. package/src/theme/themes/catppuccin-macchiato.json +0 -233
  118. package/src/theme/themes/catppuccin.json +0 -112
  119. package/src/theme/themes/cobalt2.json +0 -228
  120. package/src/theme/themes/cursor.json +0 -249
  121. package/src/theme/themes/dracula.json +0 -219
  122. package/src/theme/themes/everforest.json +0 -241
  123. package/src/theme/themes/flexoki.json +0 -237
  124. package/src/theme/themes/github.json +0 -233
  125. package/src/theme/themes/gruvbox.json +0 -242
  126. package/src/theme/themes/kanagawa.json +0 -77
  127. package/src/theme/themes/lucent-orng.json +0 -237
  128. package/src/theme/themes/material.json +0 -235
  129. package/src/theme/themes/matrix.json +0 -77
  130. package/src/theme/themes/mercury.json +0 -252
  131. package/src/theme/themes/monokai.json +0 -221
  132. package/src/theme/themes/nightowl.json +0 -221
  133. package/src/theme/themes/nord.json +0 -223
  134. package/src/theme/themes/one-dark.json +0 -84
  135. package/src/theme/themes/opencode.json +0 -245
  136. package/src/theme/themes/orng.json +0 -249
  137. package/src/theme/themes/osaka-jade.json +0 -93
  138. package/src/theme/themes/palenight.json +0 -222
  139. package/src/theme/themes/rosepine.json +0 -234
  140. package/src/theme/themes/solarized.json +0 -223
  141. package/src/theme/themes/synthwave84.json +0 -226
  142. package/src/theme/themes/tokyonight.json +0 -243
  143. package/src/theme/themes/vercel.json +0 -245
  144. package/src/theme/themes/vesper.json +0 -218
  145. package/src/theme/themes/zenburn.json +0 -223
  146. package/src/theme/types.ts +0 -119
  147. package/src/types/message.ts +0 -97
  148. package/src/ui/ChafaImage.tsx +0 -64
  149. package/src/ui/Splash.tsx +0 -118
  150. package/src/ui/borders.ts +0 -28
  151. package/src/ui/command.tsx +0 -104
  152. package/src/ui/dialog-select.tsx +0 -164
  153. package/src/ui/dialog.tsx +0 -102
  154. package/src/ui/fmt.ts +0 -82
  155. package/src/ui/kv.tsx +0 -28
  156. package/src/ui/shell.tsx +0 -45
  157. package/src/ui/spinner.tsx +0 -59
  158. package/src/ui/splash-art.ts +0 -123
  159. package/src/ui/table.tsx +0 -117
  160. package/src/ui/ticker.tsx +0 -90
  161. package/src/ui/toast.tsx +0 -130
  162. package/src/utils/categorical.ts +0 -77
  163. package/src/utils/chafa.ts +0 -173
  164. package/src/utils/clipboard.ts +0 -67
  165. package/src/utils/context-segments.ts +0 -317
  166. package/src/utils/control.ts +0 -495
  167. package/src/utils/drop.ts +0 -25
  168. package/src/utils/editor.ts +0 -33
  169. package/src/utils/fuzzy.ts +0 -45
  170. package/src/utils/gateway-client.ts +0 -253
  171. package/src/utils/gateway-types.ts +0 -282
  172. package/src/utils/git.ts +0 -57
  173. package/src/utils/hermes-analytics.ts +0 -134
  174. package/src/utils/hermes-home.ts +0 -821
  175. package/src/utils/hermes-kanban.ts +0 -154
  176. package/src/utils/hermes-profiles.ts +0 -217
  177. package/src/utils/interpolate.ts +0 -31
  178. package/src/utils/math-unicode.ts +0 -818
  179. package/src/utils/memory-activity.ts +0 -140
  180. package/src/utils/open-file.ts +0 -13
  181. package/src/utils/paths.ts +0 -52
  182. package/src/utils/perf.ts +0 -235
  183. package/src/utils/preferences.ts +0 -150
  184. package/src/utils/sessions-db.ts +0 -396
  185. package/src/utils/subagent-tree.ts +0 -146
  186. package/src/utils/terminal-reset.ts +0 -129
  187. package/src/utils/tips.ts +0 -67
  188. package/src/utils/tokens.ts +0 -87
@@ -1,151 +0,0 @@
1
- /**
2
- * Slash command definitions for the chat input.
3
- *
4
- * Commands are fetched dynamically from Hermes `GET /api/commands` — the
5
- * unified registry of built-ins + skills + plugins + MCP prompts. There is
6
- * no static fallback: if the gateway is unreachable, no slash commands are
7
- * available (the popover simply won't open).
8
- *
9
- * `target` is derived: "local" if the name is a client-handled command,
10
- * otherwise "gateway" (forwarded as /{name} to the Hermes API).
11
- */
12
-
13
- export type SlashSource = "command" | "skill" | "plugin" | "mcp" | "local"
14
-
15
- export type SlashCommand = {
16
- readonly name: string
17
- readonly description: string
18
- readonly category: string
19
- readonly aliases: ReadonlyArray<string>
20
- readonly argsHint: string
21
- readonly subcommands: ReadonlyArray<string>
22
- readonly source: SlashSource
23
- readonly target: "local" | "gateway"
24
- readonly keybind?: string
25
- }
26
-
27
- /**
28
- * Names of purely client-side commands — intercepted before gateway dispatch.
29
- * These are always treated as local regardless of what the gateway returns.
30
- * Anything that must act on the *live* gateway session (not the slash-worker
31
- * subprocess) belongs here — see docs/slash-parity-audit.md.
32
- */
33
- export const LOCAL_NAMES = new Set([
34
- "clear", "new", "theme", "help", "keys", "logs", "eikon", "title",
35
- "rollback", "save", "history", "status", "usage", "profile", "steer",
36
- "reload", "reload-mcp", "chafa", "splash",
37
- // parity: session-mutating commands the slash-worker can't service
38
- "resume", "branch", "compress", "undo", "retry", "model", "quit",
39
- "copy", "paste", "image", "background", "voice", "mouse", "redraw", "queue",
40
- // Ink-only UI toggles — local no-op with a note
41
- "compact", "setup",
42
- ])
43
-
44
- /**
45
- * Descriptions for locally-handled commands. Used to render them in the
46
- * popover when the gateway registry doesn't include them (or to override
47
- * the gateway's description for things like /new, which we intercept).
48
- */
49
- export const LOCAL_COMMANDS: ReadonlyArray<SlashCommand> = [
50
- { name: "clear", description: "Clear chat messages", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
51
- { name: "new", description: "Start a new session", category: "Client", aliases: ["reset"], argsHint: "", subcommands: [], source: "local", target: "local" },
52
- { name: "theme", description: "Switch color theme", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
53
- { name: "help", description: "Show keyboard shortcuts", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
54
- { name: "keys", description: "Rebind keyboard shortcuts", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
55
- { name: "logs", description: "Show gateway stderr log", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
56
- { name: "eikon", description: "Pick sidebar avatar", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
57
- { name: "title", description: "Set session title", category: "Client", aliases: [], argsHint: "[text]", subcommands: [], source: "local", target: "local" },
58
- { name: "rollback", description: "Browse & restore checkpoints", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
59
- { name: "history", description: "Server-side transcript viewer", category: "Info", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
60
- { name: "status", description: "Version, model, paths", category: "Info", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
61
- { name: "usage", description: "Tokens, context fill, cost", category: "Info", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
62
- { name: "profile", description: "Active profile details", category: "Info", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
63
- { name: "steer", description: "Inject a note mid-turn (no interrupt)", category: "Session", aliases: [], argsHint: "[text]", subcommands: [], source: "local", target: "local" },
64
- { name: "reload-mcp", description: "Restart MCP servers & rediscover tools", category: "Session", aliases: [], argsHint: "[now|always]", subcommands: ["now", "always"], source: "local", target: "local" },
65
- { name: "reload", description: "Hot-reload ~/.hermes/.env (API keys)", category: "Session", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
66
- { name: "chafa", description: "Render image via chafa (demo)", category: "Client", aliases: [], argsHint: "<path>", subcommands: [], source: "local", target: "local" },
67
- { name: "splash", description: "Show the launch splash", category: "Client", aliases: [], argsHint: "", subcommands: [], source: "local", target: "local" },
68
- ]
69
-
70
- /** Filter commands by prefix (text after `/`). Searches names + aliases. */
71
- export function filter(list: ReadonlyArray<SlashCommand>, prefix: string): SlashCommand[] {
72
- if (!prefix) return [...list]
73
- const q = prefix.toLowerCase()
74
- return list.filter(c =>
75
- c.name.toLowerCase().startsWith(q) ||
76
- c.aliases.some(a => a.toLowerCase().startsWith(q))
77
- )
78
- }
79
-
80
- type Resolved =
81
- | { hit: SlashCommand }
82
- | { miss: true }
83
- | { ambiguous: string[] }
84
-
85
- /**
86
- * Resolve a typed command name to a single SlashCommand. Exact name or
87
- * alias wins even when it's also a prefix of something longer (`/status`
88
- * vs `/statusbar`). Otherwise a unique prefix match across the names +
89
- * aliases space resolves; multiple distinct targets is ambiguous.
90
- */
91
- export function resolve(list: ReadonlyArray<SlashCommand>, name: string): Resolved {
92
- const q = name.toLowerCase()
93
- for (const c of list)
94
- if (c.name.toLowerCase() === q || c.aliases.some(a => a.toLowerCase() === q))
95
- return { hit: c }
96
- const hits = new Set<SlashCommand>()
97
- for (const c of list)
98
- for (const n of [c.name, ...c.aliases])
99
- if (n.toLowerCase().startsWith(q)) { hits.add(c); break }
100
- if (hits.size === 1) return { hit: [...hits][0] }
101
- if (hits.size === 0) return { miss: true }
102
- return { ambiguous: [...hits].map(c => `/${c.name}`).sort() }
103
- }
104
-
105
- /**
106
- * If input matches `/cmd <sub>` (with space) and the command has declared
107
- * subcommands, return synthetic entries for subcommand completion.
108
- */
109
- export function matchSub(list: ReadonlyArray<SlashCommand>, input: string): SlashCommand[] | null {
110
- const m = input.match(/^\/(\w+)\s+(\S*)$/)
111
- if (!m) return null
112
- const name = m[1]
113
- const sub = m[2]
114
- const cmd = list.find(c => c.name === name || c.aliases.includes(name))
115
- if (!cmd || cmd.subcommands.length === 0) return null
116
- const q = sub.toLowerCase()
117
- const matches = cmd.subcommands.filter(s => s.toLowerCase().startsWith(q))
118
- if (matches.length === 0) return null
119
- return matches.map(s => ({
120
- ...cmd,
121
- name: `${cmd.name} ${s}`,
122
- description: `${cmd.name} → ${s}`,
123
- argsHint: "",
124
- subcommands: [],
125
- }))
126
- }
127
-
128
- /** Category ordering for display. Unknown categories fall to the end. */
129
- const CATEGORY_ORDER = [
130
- "Client",
131
- "Session",
132
- "Configuration",
133
- "Config",
134
- "Tools & Skills",
135
- "Skills",
136
- "Plugins",
137
- "MCP",
138
- "Info",
139
- "Exit",
140
- ] as const
141
-
142
- export function sort(list: ReadonlyArray<SlashCommand>): SlashCommand[] {
143
- const idx = (c: string) => {
144
- const i = (CATEGORY_ORDER as readonly string[]).indexOf(c)
145
- return i < 0 ? 999 : i
146
- }
147
- return [...list].sort((a, b) => {
148
- const ca = idx(a.category) - idx(b.category)
149
- return ca !== 0 ? ca : a.name.localeCompare(b.name)
150
- })
151
- }
@@ -1,66 +0,0 @@
1
- import { useState, useEffect, useRef, memo } from "react"
2
- import { STATE_FRAMES, FPS, type AvatarState } from "./states"
3
- import type { ParsedEikon } from "./eikon"
4
- import { useTheme } from "../../theme"
5
- import * as perf from "../../utils/perf"
6
-
7
- /**
8
- * Animation loop:
9
- * 1. Pause on frame 0 for PAUSE_FIRST ms
10
- * 2. Play forward (0 → last) at FPS
11
- * 3. Pause on last frame for PAUSE_LAST ms
12
- * 4. Play reverse (last → 0) at FPS
13
- * 5. Goto 1
14
- *
15
- * Restarts from frame 0 whenever `state` changes.
16
- *
17
- * When an `eikon` is supplied and it defines the current state, its
18
- * frames and fps take precedence over the baked-in set; states missing
19
- * from the eikon fall back to the baked-in frames.
20
- */
21
-
22
- export const AnimatedAvatar = memo(({ state = "idle", eikon }: { state?: AvatarState; eikon?: ParsedEikon }) => {
23
- const theme = useTheme().theme
24
- const [frame, setFrame] = useState(0)
25
- const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
26
-
27
- const ext = eikon?.states.get(state)
28
- const frames: string[][] = ext ? ext.frames : STATE_FRAMES[state]
29
- const fps = ext?.fps ?? FPS
30
- const count = frames.length
31
-
32
- // Restart animation loop when state or source changes
33
- useEffect(() => {
34
- let idx = 0
35
- let dir = 1
36
-
37
- const tick = () => {
38
- perf.count("avatar:tick")
39
- idx += dir
40
- if (idx >= count - 1) dir = -1
41
- if (idx <= 0) dir = 1
42
- setFrame(idx)
43
- timer.current = setTimeout(tick, 1000 / fps)
44
- }
45
-
46
- setFrame(0)
47
- timer.current = setTimeout(tick, 1000 / fps)
48
- return () => { if (timer.current) clearTimeout(timer.current) }
49
- }, [state, count, fps])
50
-
51
- const end = perf.mark("avatar:render")
52
- const idx = Math.min(frame, count - 1)
53
- const lines = frames[idx] ?? []
54
-
55
- const result = (
56
- <box flexDirection="column">
57
- {lines.map((line, i) => (
58
- <text key={i}>
59
- <span fg={theme.hermAvatar}>{line}</span>
60
- </text>
61
- ))}
62
- </box>
63
- )
64
- end()
65
- return result
66
- })
@@ -1,144 +0,0 @@
1
- /**
2
- * .eikon file parser — NDJSON stateful ASCII animation format.
3
- *
4
- * Line 1 is a header object. Subsequent lines are either state
5
- * declarations (`{state, fps, frame_count, ...}`) or frame objects
6
- * (`{f, data, ...}`) belonging to the most recent state. Unknown
7
- * fields are ignored; unknown format versions are tolerated.
8
- *
9
- * Spec: https://github.com/liftaris/eikon (separate repo).
10
- */
11
-
12
- import { readdirSync, openSync, readSync, closeSync } from "fs"
13
- import { join } from "path"
14
-
15
- export type EikonMeta = {
16
- version: number
17
- name: string
18
- author?: string
19
- width: number
20
- height: number
21
- states: string[]
22
- [k: string]: unknown
23
- }
24
-
25
- export type EikonState = {
26
- fps: number
27
- /** Each frame as an array of lines (row-per-string). */
28
- frames: string[][]
29
- }
30
-
31
- export type ParsedEikon = {
32
- meta: EikonMeta
33
- states: Map<string, EikonState>
34
- }
35
-
36
- type Row = Record<string, unknown>
37
-
38
- const num = (v: unknown, d: number) => typeof v === "number" && isFinite(v) ? v : d
39
- const str = (v: unknown, d = "") => typeof v === "string" ? v : d
40
-
41
- function parse(line: string, n: number): Row {
42
- try { return JSON.parse(line) as Row }
43
- catch (e) {
44
- const msg = e instanceof Error ? e.message : String(e)
45
- throw new Error(`eikon: malformed JSON on line ${n}: ${msg}`)
46
- }
47
- }
48
-
49
- function median(xs: number[]): number {
50
- const s = [...xs].sort((a, b) => a - b)
51
- const m = s.length >> 1
52
- return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2
53
- }
54
-
55
- /** Parse a full .eikon NDJSON document. Throws with line number on bad JSON. */
56
- export function parseEikon(text: string): ParsedEikon {
57
- const lines = text.split("\n")
58
- if (!lines[0]?.trim()) throw new Error("eikon: empty file (no header on line 1)")
59
-
60
- const head = parse(lines[0], 1)
61
- const meta: EikonMeta = {
62
- ...head,
63
- version: num(head.eikon ?? head.version, 1),
64
- name: str(head.name, "unnamed"),
65
- author: typeof head.author === "string" ? head.author : undefined,
66
- width: num(head.width, 0),
67
- height: num(head.height, 0),
68
- states: Array.isArray(head.states) ? (head.states as string[]) : [],
69
- }
70
-
71
- const states = new Map<string, EikonState>()
72
- let cur: { name: string; fps?: number; frames: string[][]; durs: number[] } | null = null
73
-
74
- const seal = () => {
75
- if (!cur) return
76
- const fps = cur.fps ?? (cur.durs.length ? Math.round(1000 / median(cur.durs)) || 12 : 12)
77
- states.set(cur.name, { fps, frames: cur.frames })
78
- cur = null
79
- }
80
-
81
- for (let i = 1; i < lines.length; i++) {
82
- const raw = lines[i]
83
- if (!raw || !raw.trim()) continue
84
- const obj = parse(raw, i + 1)
85
-
86
- if (typeof obj.state === "string") {
87
- seal()
88
- cur = {
89
- name: obj.state,
90
- fps: typeof obj.fps === "number" ? obj.fps : undefined,
91
- frames: [],
92
- durs: [],
93
- }
94
- continue
95
- }
96
-
97
- // Frame line — attach to current state.
98
- if (!cur) continue
99
- const data = typeof obj.data === "string"
100
- ? obj.data.split("\n")
101
- : Array.isArray(obj.lines) ? (obj.lines as string[]) : []
102
- cur.frames.push(data)
103
- const ms = num(obj.duration_ms, 0) || num(obj.pause, 0) * 1000
104
- if (ms > 0) cur.durs.push(ms)
105
- }
106
- seal()
107
-
108
- if (meta.states.length === 0) meta.states = Array.from(states.keys())
109
- return { meta, states }
110
- }
111
-
112
- /** Read just the header (line 1) of a .eikon file without loading the rest. */
113
- function peek(path: string): EikonMeta | null {
114
- const fd = openSync(path, "r")
115
- try {
116
- const buf = Buffer.alloc(8192)
117
- const n = readSync(fd, buf, 0, buf.length, 0)
118
- const first = buf.toString("utf8", 0, n).split("\n", 1)[0]
119
- if (!first) return null
120
- return parseEikon(first).meta
121
- } catch {
122
- return null
123
- } finally {
124
- closeSync(fd)
125
- }
126
- }
127
-
128
- /**
129
- * Scan directories (non-recursive per dir, but walks one level deep) for
130
- * `*.eikon` files and return their header metadata. Missing dirs are
131
- * silently skipped.
132
- */
133
- export function listEikons(dirs: string[]): { path: string; meta: EikonMeta }[] {
134
- return dirs.flatMap(dir => {
135
- let entries: string[]
136
- try { entries = readdirSync(dir, { recursive: true }) as string[] }
137
- catch { return [] }
138
- return entries
139
- .filter(e => e.endsWith(".eikon"))
140
- .map(e => join(dir, e))
141
- .map(path => ({ path, meta: peek(path) }))
142
- .filter((x): x is { path: string; meta: EikonMeta } => x.meta !== null)
143
- })
144
- }