@onpoint-dev-tools/crewcoder-opentui 0.0.0-stage → 0.1.0

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 (325) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +262 -2
  3. package/THIRD_PARTY_NOTICES.md +51 -0
  4. package/dist/App.d.ts +16 -0
  5. package/dist/App.d.ts.map +1 -0
  6. package/dist/App.js +428 -0
  7. package/dist/App.js.map +1 -0
  8. package/dist/Root.d.ts +11 -0
  9. package/dist/Root.d.ts.map +1 -0
  10. package/dist/Root.js +13 -0
  11. package/dist/Root.js.map +1 -0
  12. package/dist/alert-model.d.ts +31 -0
  13. package/dist/alert-model.d.ts.map +1 -0
  14. package/dist/alert-model.js +34 -0
  15. package/dist/alert-model.js.map +1 -0
  16. package/dist/args.d.ts +13 -0
  17. package/dist/args.d.ts.map +1 -0
  18. package/dist/args.js +63 -0
  19. package/dist/args.js.map +1 -0
  20. package/dist/attachments.d.ts +29 -0
  21. package/dist/attachments.d.ts.map +1 -0
  22. package/dist/attachments.js +38 -0
  23. package/dist/attachments.js.map +1 -0
  24. package/dist/block-panels.d.ts +43 -0
  25. package/dist/block-panels.d.ts.map +1 -0
  26. package/dist/block-panels.js +210 -0
  27. package/dist/block-panels.js.map +1 -0
  28. package/dist/cli.d.ts +3 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/cli.js +138 -0
  31. package/dist/cli.js.map +1 -0
  32. package/dist/command-format.d.ts +18 -0
  33. package/dist/command-format.d.ts.map +1 -0
  34. package/dist/command-format.js +66 -0
  35. package/dist/command-format.js.map +1 -0
  36. package/dist/command-runner.d.ts +128 -0
  37. package/dist/command-runner.d.ts.map +1 -0
  38. package/dist/command-runner.js +571 -0
  39. package/dist/command-runner.js.map +1 -0
  40. package/dist/commands.d.ts +47 -0
  41. package/dist/commands.d.ts.map +1 -0
  42. package/dist/commands.js +108 -0
  43. package/dist/commands.js.map +1 -0
  44. package/dist/components/AttachmentRow.d.ts +11 -0
  45. package/dist/components/AttachmentRow.d.ts.map +1 -0
  46. package/dist/components/AttachmentRow.js +17 -0
  47. package/dist/components/AttachmentRow.js.map +1 -0
  48. package/dist/components/Composer.d.ts +23 -0
  49. package/dist/components/Composer.d.ts.map +1 -0
  50. package/dist/components/Composer.js +45 -0
  51. package/dist/components/Composer.js.map +1 -0
  52. package/dist/components/ExtensionQuestion.d.ts +18 -0
  53. package/dist/components/ExtensionQuestion.d.ts.map +1 -0
  54. package/dist/components/ExtensionQuestion.js +45 -0
  55. package/dist/components/ExtensionQuestion.js.map +1 -0
  56. package/dist/components/GoalForm.d.ts +18 -0
  57. package/dist/components/GoalForm.d.ts.map +1 -0
  58. package/dist/components/GoalForm.js +26 -0
  59. package/dist/components/GoalForm.js.map +1 -0
  60. package/dist/components/Home.d.ts +21 -0
  61. package/dist/components/Home.d.ts.map +1 -0
  62. package/dist/components/Home.js +48 -0
  63. package/dist/components/Home.js.map +1 -0
  64. package/dist/components/MentionList.d.ts +14 -0
  65. package/dist/components/MentionList.d.ts.map +1 -0
  66. package/dist/components/MentionList.js +24 -0
  67. package/dist/components/MentionList.js.map +1 -0
  68. package/dist/components/SearchBar.d.ts +19 -0
  69. package/dist/components/SearchBar.d.ts.map +1 -0
  70. package/dist/components/SearchBar.js +28 -0
  71. package/dist/components/SearchBar.js.map +1 -0
  72. package/dist/components/Sidebar.d.ts +19 -0
  73. package/dist/components/Sidebar.d.ts.map +1 -0
  74. package/dist/components/Sidebar.js +35 -0
  75. package/dist/components/Sidebar.js.map +1 -0
  76. package/dist/components/SummaryEditor.d.ts +16 -0
  77. package/dist/components/SummaryEditor.d.ts.map +1 -0
  78. package/dist/components/SummaryEditor.js +21 -0
  79. package/dist/components/SummaryEditor.js.map +1 -0
  80. package/dist/components/Transcript.d.ts +37 -0
  81. package/dist/components/Transcript.d.ts.map +1 -0
  82. package/dist/components/Transcript.js +314 -0
  83. package/dist/components/Transcript.js.map +1 -0
  84. package/dist/components/ui/alert.d.ts +9 -0
  85. package/dist/components/ui/alert.d.ts.map +1 -0
  86. package/dist/components/ui/alert.js +18 -0
  87. package/dist/components/ui/alert.js.map +1 -0
  88. package/dist/components/ui/command-palette.d.ts +15 -0
  89. package/dist/components/ui/command-palette.d.ts.map +1 -0
  90. package/dist/components/ui/command-palette.js +14 -0
  91. package/dist/components/ui/command-palette.js.map +1 -0
  92. package/dist/components/ui/confirm.d.ts +12 -0
  93. package/dist/components/ui/confirm.d.ts.map +1 -0
  94. package/dist/components/ui/confirm.js +16 -0
  95. package/dist/components/ui/confirm.js.map +1 -0
  96. package/dist/components/ui/select.d.ts +11 -0
  97. package/dist/components/ui/select.d.ts.map +1 -0
  98. package/dist/components/ui/select.js +29 -0
  99. package/dist/components/ui/select.js.map +1 -0
  100. package/dist/components/ui/spinner.d.ts +14 -0
  101. package/dist/components/ui/spinner.d.ts.map +1 -0
  102. package/dist/components/ui/spinner.js +17 -0
  103. package/dist/components/ui/spinner.js.map +1 -0
  104. package/dist/components/ui/tool-approval.d.ts +14 -0
  105. package/dist/components/ui/tool-approval.d.ts.map +1 -0
  106. package/dist/components/ui/tool-approval.js +37 -0
  107. package/dist/components/ui/tool-approval.js.map +1 -0
  108. package/dist/components/ui/tool-call.d.ts +12 -0
  109. package/dist/components/ui/tool-call.d.ts.map +1 -0
  110. package/dist/components/ui/tool-call.js +69 -0
  111. package/dist/components/ui/tool-call.js.map +1 -0
  112. package/dist/components/ui/types.d.ts +82 -0
  113. package/dist/components/ui/types.d.ts.map +1 -0
  114. package/dist/components/ui/types.js +2 -0
  115. package/dist/components/ui/types.js.map +1 -0
  116. package/dist/crewcoder-cli.d.ts +51 -0
  117. package/dist/crewcoder-cli.d.ts.map +1 -0
  118. package/dist/crewcoder-cli.js +26 -0
  119. package/dist/crewcoder-cli.js.map +1 -0
  120. package/dist/diff-anchors.d.ts +14 -0
  121. package/dist/diff-anchors.d.ts.map +1 -0
  122. package/dist/diff-anchors.js +43 -0
  123. package/dist/diff-anchors.js.map +1 -0
  124. package/dist/footer-layout.d.ts +49 -0
  125. package/dist/footer-layout.d.ts.map +1 -0
  126. package/dist/footer-layout.js +79 -0
  127. package/dist/footer-layout.js.map +1 -0
  128. package/dist/glyphs.d.ts +32 -0
  129. package/dist/glyphs.d.ts.map +1 -0
  130. package/dist/glyphs.js +35 -0
  131. package/dist/glyphs.js.map +1 -0
  132. package/dist/goal-form.d.ts +47 -0
  133. package/dist/goal-form.d.ts.map +1 -0
  134. package/dist/goal-form.js +59 -0
  135. package/dist/goal-form.js.map +1 -0
  136. package/dist/hooks/use-animation.d.ts +6 -0
  137. package/dist/hooks/use-animation.d.ts.map +1 -0
  138. package/dist/hooks/use-animation.js +52 -0
  139. package/dist/hooks/use-animation.js.map +1 -0
  140. package/dist/hooks/use-app-colors.d.ts +6 -0
  141. package/dist/hooks/use-app-colors.d.ts.map +1 -0
  142. package/dist/hooks/use-app-colors.js +6 -0
  143. package/dist/hooks/use-app-colors.js.map +1 -0
  144. package/dist/hooks/use-glyph-set.d.ts +8 -0
  145. package/dist/hooks/use-glyph-set.d.ts.map +1 -0
  146. package/dist/hooks/use-glyph-set.js +22 -0
  147. package/dist/hooks/use-glyph-set.js.map +1 -0
  148. package/dist/hooks/use-motion.d.ts +6 -0
  149. package/dist/hooks/use-motion.d.ts.map +1 -0
  150. package/dist/hooks/use-motion.js +8 -0
  151. package/dist/hooks/use-motion.js.map +1 -0
  152. package/dist/hooks/use-terminal-focus.d.ts +16 -0
  153. package/dist/hooks/use-terminal-focus.d.ts.map +1 -0
  154. package/dist/hooks/use-terminal-focus.js +30 -0
  155. package/dist/hooks/use-terminal-focus.js.map +1 -0
  156. package/dist/hooks/use-theme.d.ts +6 -0
  157. package/dist/hooks/use-theme.d.ts.map +1 -0
  158. package/dist/hooks/use-theme.js +11 -0
  159. package/dist/hooks/use-theme.js.map +1 -0
  160. package/dist/hunk.d.ts +27 -0
  161. package/dist/hunk.d.ts.map +1 -0
  162. package/dist/hunk.js +43 -0
  163. package/dist/hunk.js.map +1 -0
  164. package/dist/image-view.d.ts +33 -0
  165. package/dist/image-view.d.ts.map +1 -0
  166. package/dist/image-view.js +51 -0
  167. package/dist/image-view.js.map +1 -0
  168. package/dist/keybindings.d.ts +28 -0
  169. package/dist/keybindings.d.ts.map +1 -0
  170. package/dist/keybindings.js +105 -0
  171. package/dist/keybindings.js.map +1 -0
  172. package/dist/lib/terminal-themes/default.d.ts +3 -0
  173. package/dist/lib/terminal-themes/default.d.ts.map +1 -0
  174. package/dist/lib/terminal-themes/default.js +49 -0
  175. package/dist/lib/terminal-themes/default.js.map +1 -0
  176. package/dist/logo-pulse.d.ts +23 -0
  177. package/dist/logo-pulse.d.ts.map +1 -0
  178. package/dist/logo-pulse.js +30 -0
  179. package/dist/logo-pulse.js.map +1 -0
  180. package/dist/markdown-style.d.ts +47 -0
  181. package/dist/markdown-style.d.ts.map +1 -0
  182. package/dist/markdown-style.js +138 -0
  183. package/dist/markdown-style.js.map +1 -0
  184. package/dist/mentions.d.ts +57 -0
  185. package/dist/mentions.d.ts.map +1 -0
  186. package/dist/mentions.js +109 -0
  187. package/dist/mentions.js.map +1 -0
  188. package/dist/palette-model.d.ts +42 -0
  189. package/dist/palette-model.d.ts.map +1 -0
  190. package/dist/palette-model.js +77 -0
  191. package/dist/palette-model.js.map +1 -0
  192. package/dist/path-suggestions.d.ts +50 -0
  193. package/dist/path-suggestions.d.ts.map +1 -0
  194. package/dist/path-suggestions.js +99 -0
  195. package/dist/path-suggestions.js.map +1 -0
  196. package/dist/picker-flows.d.ts +78 -0
  197. package/dist/picker-flows.d.ts.map +1 -0
  198. package/dist/picker-flows.js +444 -0
  199. package/dist/picker-flows.js.map +1 -0
  200. package/dist/pickers.d.ts +34 -0
  201. package/dist/pickers.d.ts.map +1 -0
  202. package/dist/pickers.js +136 -0
  203. package/dist/pickers.js.map +1 -0
  204. package/dist/prompt-history.d.ts +32 -0
  205. package/dist/prompt-history.d.ts.map +1 -0
  206. package/dist/prompt-history.js +40 -0
  207. package/dist/prompt-history.js.map +1 -0
  208. package/dist/providers/app-theme-provider.d.ts +12 -0
  209. package/dist/providers/app-theme-provider.d.ts.map +1 -0
  210. package/dist/providers/app-theme-provider.js +14 -0
  211. package/dist/providers/app-theme-provider.js.map +1 -0
  212. package/dist/providers/theme-provider.d.ts +10 -0
  213. package/dist/providers/theme-provider.d.ts.map +1 -0
  214. package/dist/providers/theme-provider.js +57 -0
  215. package/dist/providers/theme-provider.js.map +1 -0
  216. package/dist/question-model.d.ts +71 -0
  217. package/dist/question-model.d.ts.map +1 -0
  218. package/dist/question-model.js +176 -0
  219. package/dist/question-model.js.map +1 -0
  220. package/dist/search-controller.d.ts +46 -0
  221. package/dist/search-controller.d.ts.map +1 -0
  222. package/dist/search-controller.js +89 -0
  223. package/dist/search-controller.js.map +1 -0
  224. package/dist/search-jump.d.ts +27 -0
  225. package/dist/search-jump.d.ts.map +1 -0
  226. package/dist/search-jump.js +65 -0
  227. package/dist/search-jump.js.map +1 -0
  228. package/dist/session-controller.d.ts +268 -0
  229. package/dist/session-controller.d.ts.map +1 -0
  230. package/dist/session-controller.js +941 -0
  231. package/dist/session-controller.js.map +1 -0
  232. package/dist/sidebar-model.d.ts +45 -0
  233. package/dist/sidebar-model.d.ts.map +1 -0
  234. package/dist/sidebar-model.js +223 -0
  235. package/dist/sidebar-model.js.map +1 -0
  236. package/dist/sidebar.d.ts +49 -0
  237. package/dist/sidebar.d.ts.map +1 -0
  238. package/dist/sidebar.js +106 -0
  239. package/dist/sidebar.js.map +1 -0
  240. package/dist/status-line.d.ts +32 -0
  241. package/dist/status-line.d.ts.map +1 -0
  242. package/dist/status-line.js +69 -0
  243. package/dist/status-line.js.map +1 -0
  244. package/dist/syntax/filetype.d.ts +12 -0
  245. package/dist/syntax/filetype.d.ts.map +1 -0
  246. package/dist/syntax/filetype.js +28 -0
  247. package/dist/syntax/filetype.js.map +1 -0
  248. package/dist/syntax/grammars.d.ts +42 -0
  249. package/dist/syntax/grammars.d.ts.map +1 -0
  250. package/dist/syntax/grammars.js +52 -0
  251. package/dist/syntax/grammars.js.map +1 -0
  252. package/dist/text-offset.d.ts +5 -0
  253. package/dist/text-offset.d.ts.map +1 -0
  254. package/dist/text-offset.js +38 -0
  255. package/dist/text-offset.js.map +1 -0
  256. package/dist/text-wrap.d.ts +12 -0
  257. package/dist/text-wrap.d.ts.map +1 -0
  258. package/dist/text-wrap.js +53 -0
  259. package/dist/text-wrap.js.map +1 -0
  260. package/dist/theme-controller.d.ts +77 -0
  261. package/dist/theme-controller.d.ts.map +1 -0
  262. package/dist/theme-controller.js +178 -0
  263. package/dist/theme-controller.js.map +1 -0
  264. package/dist/theme.d.ts +51 -0
  265. package/dist/theme.d.ts.map +1 -0
  266. package/dist/theme.js +86 -0
  267. package/dist/theme.js.map +1 -0
  268. package/dist/tmux-check.d.ts +35 -0
  269. package/dist/tmux-check.d.ts.map +1 -0
  270. package/dist/tmux-check.js +66 -0
  271. package/dist/tmux-check.js.map +1 -0
  272. package/dist/tmux.d.ts +69 -0
  273. package/dist/tmux.d.ts.map +1 -0
  274. package/dist/tmux.js +135 -0
  275. package/dist/tmux.js.map +1 -0
  276. package/dist/tool-diff.d.ts +51 -0
  277. package/dist/tool-diff.d.ts.map +1 -0
  278. package/dist/tool-diff.js +158 -0
  279. package/dist/tool-diff.js.map +1 -0
  280. package/dist/tool-presentation.d.ts +46 -0
  281. package/dist/tool-presentation.d.ts.map +1 -0
  282. package/dist/tool-presentation.js +148 -0
  283. package/dist/tool-presentation.js.map +1 -0
  284. package/dist/tool-renderer-view.d.ts +14 -0
  285. package/dist/tool-renderer-view.d.ts.map +1 -0
  286. package/dist/tool-renderer-view.js +10 -0
  287. package/dist/tool-renderer-view.js.map +1 -0
  288. package/dist/transcript-search.d.ts +54 -0
  289. package/dist/transcript-search.d.ts.map +1 -0
  290. package/dist/transcript-search.js +160 -0
  291. package/dist/transcript-search.js.map +1 -0
  292. package/dist/transcript.d.ts +59 -0
  293. package/dist/transcript.d.ts.map +1 -0
  294. package/dist/transcript.js +123 -0
  295. package/dist/transcript.js.map +1 -0
  296. package/dist/workflow-tools.d.ts +42 -0
  297. package/dist/workflow-tools.d.ts.map +1 -0
  298. package/dist/workflow-tools.js +89 -0
  299. package/dist/workflow-tools.js.map +1 -0
  300. package/examples/themes/ember.json +75 -0
  301. package/grammars/bash/LICENSE +21 -0
  302. package/grammars/bash/highlights.scm +56 -0
  303. package/grammars/bash/tree-sitter-bash.wasm +0 -0
  304. package/grammars/css/LICENSE +21 -0
  305. package/grammars/css/highlights.scm +76 -0
  306. package/grammars/css/tree-sitter-css.wasm +0 -0
  307. package/grammars/go/LICENSE +21 -0
  308. package/grammars/go/highlights.scm +123 -0
  309. package/grammars/go/tree-sitter-go.wasm +0 -0
  310. package/grammars/html/LICENSE +21 -0
  311. package/grammars/html/highlights.scm +13 -0
  312. package/grammars/html/tree-sitter-html.wasm +0 -0
  313. package/grammars/json/LICENSE +21 -0
  314. package/grammars/json/highlights.scm +16 -0
  315. package/grammars/json/tree-sitter-json.wasm +0 -0
  316. package/grammars/python/LICENSE +21 -0
  317. package/grammars/python/highlights.scm +137 -0
  318. package/grammars/python/tree-sitter-python.wasm +0 -0
  319. package/grammars/rust/LICENSE +21 -0
  320. package/grammars/rust/highlights.scm +161 -0
  321. package/grammars/rust/tree-sitter-rust.wasm +0 -0
  322. package/grammars/yaml/LICENSE +20 -0
  323. package/grammars/yaml/highlights.scm +79 -0
  324. package/grammars/yaml/tree-sitter-yaml.wasm +0 -0
  325. package/package.json +56 -5
@@ -0,0 +1,148 @@
1
+ import { readOutputFiletype } from "./syntax/filetype.js";
2
+ import { normalize } from "./transcript.js";
3
+ const KIND_STYLES = {
4
+ read: { icons: { emoji: "📖", text: "→" }, title: "Read File", layout: "stacked" },
5
+ edit: { icons: { emoji: "±", text: "±" }, title: "Edit File", layout: "inline" },
6
+ write: { icons: { emoji: "+", text: "+" }, title: "Write File", layout: "inline" },
7
+ command: { icons: { emoji: "💻", text: "$" }, title: "Run Command", layout: "stacked" },
8
+ search: { icons: { emoji: "🔍", text: "✱" }, title: "Search", layout: "stacked" },
9
+ list: { icons: { emoji: "📂", text: "≡" }, title: "List Files", layout: "stacked" },
10
+ web: { icons: { emoji: "🌐", text: "%" }, title: "Web", layout: "stacked" },
11
+ tasks: { icons: { emoji: "☑", text: "#" }, title: "Update Tasks", layout: "inline" },
12
+ agent: { icons: { emoji: "🤖", text: "@" }, title: "Delegate", layout: "stacked" },
13
+ other: { icons: { emoji: "⚙", text: "*" }, title: "", layout: "inline" }
14
+ };
15
+ /**
16
+ * Tool names across providers, normalized (MCP `mcp__server__` prefix removed,
17
+ * lower case, no separators): CrewCoder's own tools, Claude Code's, and the
18
+ * Codex app-server's `Codex command` / `Codex file change`.
19
+ */
20
+ const KINDS_BY_NAME = {
21
+ read: "read", readfile: "read", view: "read", notebookread: "read",
22
+ edit: "edit", multiedit: "edit", editsymbol: "edit", edittransaction: "edit", codexfilechange: "edit", applypatch: "edit", strreplace: "edit", notebookedit: "edit",
23
+ write: "write", writefile: "write", createfile: "write",
24
+ bash: "command", shell: "command", exec: "command", codexcommand: "command", runcommand: "command", backgroundjob: "command",
25
+ grep: "search", glob: "search", search: "search", codesearch: "search",
26
+ listfiles: "list", ls: "list", list: "list",
27
+ webfetch: "web", websearch: "web", fetch: "web",
28
+ todowrite: "tasks", taskcreate: "tasks", taskupdate: "tasks", tasklist: "tasks", taskget: "tasks", taskdelete: "tasks",
29
+ task: "agent", agent: "agent", delegateworker: "agent"
30
+ };
31
+ /** Output lines a collapsed tool shows; the rest open with its toggle or Ctrl+O. */
32
+ export const COLLAPSED_OUTPUT_LINES = 12;
33
+ const MAX_TARGET_CHARS = 160;
34
+ export function toolKind(name) {
35
+ const key = name.replace(/^mcp__[^_]+(?:_[^_]+)*__/, "").toLowerCase().replace(/[^a-z0-9]/g, "");
36
+ return Object.hasOwn(KINDS_BY_NAME, key) ? KINDS_BY_NAME[key] : "other";
37
+ }
38
+ /**
39
+ * `cwd` shortens absolute paths under the workspace to workspace-relative ones.
40
+ * `glyphs` picks the icon set the terminal can draw (`resolveGlyphSet`).
41
+ */
42
+ export function toolPresentation(block, cwd, glyphs = "emoji") {
43
+ const kind = toolKind(block.name);
44
+ const style = KIND_STYLES[kind];
45
+ const args = block.args ?? {};
46
+ const failed = block.status === "error";
47
+ // The reducer's stand-in when a tool returned no text says nothing the title does not.
48
+ const raw = normalize(block.text ?? "").trimEnd();
49
+ const text = raw === `tool completed: ${block.name}` ? "" : raw;
50
+ const title = kind === "other" ? block.name.replace(/^mcp__[^_]+(?:_[^_]+)*__/, "") : kind === "web" ? webTitle(block.name) : style.title;
51
+ const target = toolTarget(kind, args, cwd);
52
+ const filetype = kind === "read" && !failed && text ? readOutputFiletype(argPaths(args)[0], text) : undefined;
53
+ return {
54
+ kind,
55
+ icon: style.icons[glyphs],
56
+ title,
57
+ target: target ? fit(normalize(target)) : undefined,
58
+ layout: style.layout,
59
+ output: text || undefined,
60
+ diff: kind === "edit" || kind === "write",
61
+ ...(filetype ? { filetype } : {}),
62
+ failed
63
+ };
64
+ }
65
+ /** The output lines to draw and how many a collapsed view hides. */
66
+ export function clampOutput(output, expanded, max = COLLAPSED_OUTPUT_LINES) {
67
+ const lines = output.split("\n");
68
+ if (expanded || lines.length <= max)
69
+ return { lines, hidden: 0 };
70
+ return { lines: lines.slice(0, max), hidden: lines.length - max };
71
+ }
72
+ /** How a line of edit/write output reads as a diff. File headers (`+++`/`---`) stay plain. */
73
+ export function diffLineTone(line) {
74
+ if (line.startsWith("@@"))
75
+ return "hunk";
76
+ if (line.startsWith("+++") || line.startsWith("---"))
77
+ return "plain";
78
+ if (line.startsWith("+"))
79
+ return "added";
80
+ if (line.startsWith("-"))
81
+ return "removed";
82
+ return "plain";
83
+ }
84
+ function toolTarget(kind, args, cwd) {
85
+ const paths = argPaths(args).map((path) => relativePath(path, cwd));
86
+ switch (kind) {
87
+ case "read":
88
+ case "edit":
89
+ case "write":
90
+ case "list":
91
+ return paths.length ? paths.join(", ") : undefined;
92
+ case "command":
93
+ return firstLine(stringArg(args, "command", "cmd"));
94
+ case "search": {
95
+ const pattern = stringArg(args, "pattern", "query", "regex");
96
+ const where = paths[0] ?? stringArg(args, "glob");
97
+ return pattern && where ? `${pattern} in ${where}` : pattern ?? where;
98
+ }
99
+ case "web":
100
+ return stringArg(args, "url", "query");
101
+ case "agent":
102
+ return stringArg(args, "description", "worker", "subagent_type", "task");
103
+ case "tasks":
104
+ return stringArg(args, "subject");
105
+ case "other":
106
+ return paths[0] ?? firstLine(firstStringArg(args));
107
+ }
108
+ }
109
+ /** Paths from the argument shapes providers use, including multi-file edits. */
110
+ function argPaths(args) {
111
+ const direct = stringArg(args, "path", "file_path", "filePath", "notebook_path");
112
+ if (direct)
113
+ return [direct];
114
+ const lists = [args.edits, args.changes].filter(Array.isArray);
115
+ const paths = lists.flat().map((entry) => (isRecord(entry) ? stringArg(entry, "path", "file_path") : undefined));
116
+ return [...new Set(paths.filter((path) => Boolean(path)))];
117
+ }
118
+ /** `path` relative to `cwd` when it is under it; otherwise unchanged. */
119
+ export function relativePath(path, cwd) {
120
+ if (!cwd || cwd === "/")
121
+ return path;
122
+ const root = cwd.endsWith("/") ? cwd : `${cwd}/`;
123
+ return path.startsWith(root) ? path.slice(root.length) : path;
124
+ }
125
+ function webTitle(name) {
126
+ return /search/i.test(name) ? "Web Search" : "Fetch";
127
+ }
128
+ function stringArg(args, ...keys) {
129
+ for (const key of keys) {
130
+ const value = args[key];
131
+ if (typeof value === "string" && value.trim())
132
+ return value.trim();
133
+ }
134
+ return undefined;
135
+ }
136
+ function firstStringArg(args) {
137
+ return Object.values(args).find((value) => typeof value === "string" && value.trim() !== "")?.trim();
138
+ }
139
+ function firstLine(text) {
140
+ return text?.split("\n", 1)[0];
141
+ }
142
+ function fit(text) {
143
+ return text.length <= MAX_TARGET_CHARS ? text : `${text.slice(0, MAX_TARGET_CHARS - 1)}…`;
144
+ }
145
+ function isRecord(value) {
146
+ return typeof value === "object" && value !== null && !Array.isArray(value);
147
+ }
148
+ //# sourceMappingURL=tool-presentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-presentation.js","sourceRoot":"","sources":["../src/tool-presentation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA8B5C,MAAM,WAAW,GAA0C;IACzD,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE;IAClF,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE;IAChF,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE;IAClF,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;IACvF,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE;IACjF,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE;IACnF,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAA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AO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;AACxH,CAAC;AAED,SAAS,SAAS,CAAC,IAAwB;IACzC,OAAO,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAI,CAAC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,CAAC;AAC5F,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import type { TuiEventBlock } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tui-store\";\nimport type { GlyphSet } from \"./glyphs.js\";\nimport { readOutputFiletype } from \"./syntax/filetype.js\";\nimport { normalize } from \"./transcript.js\";\n\ntype ToolBlock = Extract<TuiEventBlock, { type: \"tool\" }>;\n\nexport type ToolKind = \"read\" | \"edit\" | \"write\" | \"command\" | \"search\" | \"list\" | \"web\" | \"tasks\" | \"agent\" | \"other\";\n\n/**\n * How one tool call reads in the transcript: an icon and title, the thing it\n * acted on, and output only where it helps. `stacked` puts the target on its\n * own row under the title (`📖 Read File` / `src/App.jsx`); `inline` keeps it\n * on the title row (`± Edit File: src/App.jsx`).\n */\nexport type ToolPresentation = {\n kind: ToolKind;\n icon: string;\n title: string;\n target?: string;\n layout: \"inline\" | \"stacked\";\n /** The tool's whole output, every kind (the view clamps it, see `clampOutput`). */\n output?: string;\n /** Output lines read as a diff (`+`/`-`/`@@`), for edits and writes. */\n diff: boolean;\n /** Tree-sitter filetype of a read tool's output (from the read path), when it highlights. */\n filetype?: string;\n failed: boolean;\n};\n\n/** `emoji` for terminals that draw two-cell emoji correctly, `text` (one cell) for the rest; see `glyphs.ts`. */\ntype KindStyle = { icons: Readonly<Record<GlyphSet, string>>; title: string; layout: ToolPresentation[\"layout\"] };\n\nconst KIND_STYLES: Readonly<Record<ToolKind, KindStyle>> = {\n read: { icons: { emoji: \"📖\", text: \"→\" }, title: \"Read File\", layout: \"stacked\" },\n edit: { icons: { emoji: \"±\", text: \"±\" }, title: \"Edit File\", layout: \"inline\" },\n write: { icons: { emoji: \"+\", text: \"+\" }, title: \"Write File\", layout: \"inline\" },\n command: { icons: { emoji: \"💻\", text: \"$\" }, title: \"Run Command\", layout: \"stacked\" },\n search: { icons: { emoji: \"🔍\", text: \"✱\" }, title: \"Search\", layout: \"stacked\" },\n list: { icons: { emoji: \"📂\", text: \"≡\" }, title: \"List Files\", layout: \"stacked\" },\n web: { icons: { emoji: \"🌐\", text: \"%\" }, title: \"Web\", layout: \"stacked\" },\n tasks: { icons: { emoji: \"☑\", text: \"#\" }, title: \"Update Tasks\", layout: \"inline\" },\n agent: { icons: { emoji: \"🤖\", text: \"@\" }, title: \"Delegate\", layout: \"stacked\" },\n other: { icons: { emoji: \"⚙\", text: \"*\" }, title: \"\", layout: \"inline\" }\n};\n\n/**\n * Tool names across providers, normalized (MCP `mcp__server__` prefix removed,\n * lower case, no separators): CrewCoder's own tools, Claude Code's, and the\n * Codex app-server's `Codex command` / `Codex file change`.\n */\nconst KINDS_BY_NAME: Readonly<Record<string, ToolKind>> = {\n read: \"read\", readfile: \"read\", view: \"read\", notebookread: \"read\",\n edit: \"edit\", multiedit: \"edit\", editsymbol: \"edit\", edittransaction: \"edit\", codexfilechange: \"edit\", applypatch: \"edit\", strreplace: \"edit\", notebookedit: \"edit\",\n write: \"write\", writefile: \"write\", createfile: \"write\",\n bash: \"command\", shell: \"command\", exec: \"command\", codexcommand: \"command\", runcommand: \"command\", backgroundjob: \"command\",\n grep: \"search\", glob: \"search\", search: \"search\", codesearch: \"search\",\n listfiles: \"list\", ls: \"list\", list: \"list\",\n webfetch: \"web\", websearch: \"web\", fetch: \"web\",\n todowrite: \"tasks\", taskcreate: \"tasks\", taskupdate: \"tasks\", tasklist: \"tasks\", taskget: \"tasks\", taskdelete: \"tasks\",\n task: \"agent\", agent: \"agent\", delegateworker: \"agent\"\n};\n\n/** Output lines a collapsed tool shows; the rest open with its toggle or Ctrl+O. */\nexport const COLLAPSED_OUTPUT_LINES = 12;\nconst MAX_TARGET_CHARS = 160;\n\nexport function toolKind(name: string): ToolKind {\n const key = name.replace(/^mcp__[^_]+(?:_[^_]+)*__/, \"\").toLowerCase().replace(/[^a-z0-9]/g, \"\");\n return Object.hasOwn(KINDS_BY_NAME, key) ? KINDS_BY_NAME[key]! : \"other\";\n}\n\n/**\n * `cwd` shortens absolute paths under the workspace to workspace-relative ones.\n * `glyphs` picks the icon set the terminal can draw (`resolveGlyphSet`).\n */\nexport function toolPresentation(block: ToolBlock, cwd?: string, glyphs: GlyphSet = \"emoji\"): ToolPresentation {\n const kind = toolKind(block.name);\n const style = KIND_STYLES[kind];\n const args = block.args ?? {};\n const failed = block.status === \"error\";\n // The reducer's stand-in when a tool returned no text says nothing the title does not.\n const raw = normalize(block.text ?? \"\").trimEnd();\n const text = raw === `tool completed: ${block.name}` ? \"\" : raw;\n const title = kind === \"other\" ? block.name.replace(/^mcp__[^_]+(?:_[^_]+)*__/, \"\") : kind === \"web\" ? webTitle(block.name) : style.title;\n const target = toolTarget(kind, args, cwd);\n const filetype = kind === \"read\" && !failed && text ? readOutputFiletype(argPaths(args)[0], text) : undefined;\n return {\n kind,\n icon: style.icons[glyphs],\n title,\n target: target ? fit(normalize(target)) : undefined,\n layout: style.layout,\n output: text || undefined,\n diff: kind === \"edit\" || kind === \"write\",\n ...(filetype ? { filetype } : {}),\n failed\n };\n}\n\n/** The output lines to draw and how many a collapsed view hides. */\nexport function clampOutput(output: string, expanded: boolean, max = COLLAPSED_OUTPUT_LINES): { lines: string[]; hidden: number } {\n const lines = output.split(\"\\n\");\n if (expanded || lines.length <= max) return { lines, hidden: 0 };\n return { lines: lines.slice(0, max), hidden: lines.length - max };\n}\n\nexport type DiffLineTone = \"added\" | \"removed\" | \"hunk\" | \"plain\";\n\n/** How a line of edit/write output reads as a diff. File headers (`+++`/`---`) stay plain. */\nexport function diffLineTone(line: string): DiffLineTone {\n if (line.startsWith(\"@@\")) return \"hunk\";\n if (line.startsWith(\"+++\") || line.startsWith(\"---\")) return \"plain\";\n if (line.startsWith(\"+\")) return \"added\";\n if (line.startsWith(\"-\")) return \"removed\";\n return \"plain\";\n}\n\nfunction toolTarget(kind: ToolKind, args: Record<string, unknown>, cwd?: string): string | undefined {\n const paths = argPaths(args).map((path) => relativePath(path, cwd));\n switch (kind) {\n case \"read\":\n case \"edit\":\n case \"write\":\n case \"list\":\n return paths.length ? paths.join(\", \") : undefined;\n case \"command\":\n return firstLine(stringArg(args, \"command\", \"cmd\"));\n case \"search\": {\n const pattern = stringArg(args, \"pattern\", \"query\", \"regex\");\n const where = paths[0] ?? stringArg(args, \"glob\");\n return pattern && where ? `${pattern} in ${where}` : pattern ?? where;\n }\n case \"web\":\n return stringArg(args, \"url\", \"query\");\n case \"agent\":\n return stringArg(args, \"description\", \"worker\", \"subagent_type\", \"task\");\n case \"tasks\":\n return stringArg(args, \"subject\");\n case \"other\":\n return paths[0] ?? firstLine(firstStringArg(args));\n }\n}\n\n/** Paths from the argument shapes providers use, including multi-file edits. */\nfunction argPaths(args: Record<string, unknown>): string[] {\n const direct = stringArg(args, \"path\", \"file_path\", \"filePath\", \"notebook_path\");\n if (direct) return [direct];\n const lists = [args.edits, args.changes].filter(Array.isArray) as unknown[][];\n const paths = lists.flat().map((entry) => (isRecord(entry) ? stringArg(entry, \"path\", \"file_path\") : undefined));\n return [...new Set(paths.filter((path): path is string => Boolean(path)))];\n}\n\n/** `path` relative to `cwd` when it is under it; otherwise unchanged. */\nexport function relativePath(path: string, cwd?: string): string {\n if (!cwd || cwd === \"/\") return path;\n const root = cwd.endsWith(\"/\") ? cwd : `${cwd}/`;\n return path.startsWith(root) ? path.slice(root.length) : path;\n}\n\nfunction webTitle(name: string): string {\n return /search/i.test(name) ? \"Web Search\" : \"Fetch\";\n}\n\nfunction stringArg(args: Record<string, unknown>, ...keys: string[]): string | undefined {\n for (const key of keys) {\n const value = args[key];\n if (typeof value === \"string\" && value.trim()) return value.trim();\n }\n return undefined;\n}\n\nfunction firstStringArg(args: Record<string, unknown>): string | undefined {\n return Object.values(args).find((value): value is string => typeof value === \"string\" && value.trim() !== \"\")?.trim();\n}\n\nfunction firstLine(text: string | undefined): string | undefined {\n return text?.split(\"\\n\", 1)[0];\n}\n\nfunction fit(text: string): string {\n return text.length <= MAX_TARGET_CHARS ? text : `${text.slice(0, MAX_TARGET_CHARS - 1)}…`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { TuiRendererHook } from "@onpoint-dev-tools/crewcoder-tui-core/state/tui-store";
2
+ import { type ToolBlock } from "./transcript.js";
3
+ /**
4
+ * What an extension tool renderer draws (`docs/TRANSCRIPT.md#extension-tool-renderers`):
5
+ * its title, the extension it came from, and the filled-in template. Agent and extension
6
+ * text go through `normalize()`, like every other transcript text. Pure.
7
+ */
8
+ export type RenderedToolView = {
9
+ title: string;
10
+ source: string;
11
+ body: string;
12
+ };
13
+ export declare function renderedTool(block: ToolBlock, renderer: TuiRendererHook): RenderedToolView;
14
+ //# sourceMappingURL=tool-renderer-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-renderer-view.d.ts","sourceRoot":"","sources":["../src/tool-renderer-view.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAC;AAC7F,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,GAAG,gBAAgB,CAM1F"}
@@ -0,0 +1,10 @@
1
+ import { renderToolTemplate } from "@onpoint-dev-tools/crewcoder-tui-core/state/tool-renderers";
2
+ import { normalize } from "./transcript.js";
3
+ export function renderedTool(block, renderer) {
4
+ return {
5
+ title: normalize(renderer.title).trim() || block.name,
6
+ source: normalize(renderer.extensionId),
7
+ body: normalize(renderToolTemplate(renderer.template, block)).trim()
8
+ };
9
+ }
10
+ //# sourceMappingURL=tool-renderer-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-renderer-view.js","sourceRoot":"","sources":["../src/tool-renderer-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4DAA4D,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAS5D,MAAM,UAAU,YAAY,CAAC,KAAgB,EAAE,QAAyB;IACtE,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,IAAI;QACrD,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC;QACvC,IAAI,EAAE,SAAS,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;KACrE,CAAC;AACJ,CAAC","sourcesContent":["import { renderToolTemplate } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tool-renderers\";\nimport type { TuiRendererHook } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tui-store\";\nimport { normalize, type ToolBlock } from \"./transcript.js\";\n\n/**\n * What an extension tool renderer draws (`docs/TRANSCRIPT.md#extension-tool-renderers`):\n * its title, the extension it came from, and the filled-in template. Agent and extension\n * text go through `normalize()`, like every other transcript text. Pure.\n */\nexport type RenderedToolView = { title: string; source: string; body: string };\n\nexport function renderedTool(block: ToolBlock, renderer: TuiRendererHook): RenderedToolView {\n return {\n title: normalize(renderer.title).trim() || block.name,\n source: normalize(renderer.extensionId),\n body: normalize(renderToolTemplate(renderer.template, block)).trim()\n };\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import type { TuiEventBlock } from "@onpoint-dev-tools/crewcoder-tui-core/state/tui-store";
2
+ import { type LineAnchors } from "./tool-diff.js";
3
+ import { type ToolBlock } from "./transcript.js";
4
+ import type { TuiRendererHook } from "@onpoint-dev-tools/crewcoder-tui-core/state/tui-store";
5
+ /**
6
+ * Transcript search (`docs/TRANSCRIPT.md#search`): which blocks match a query,
7
+ * in event order. Pure, so it is tested without a renderer. It searches the
8
+ * text each block draws, not labels such as `CREW CODER`, and covers what a
9
+ * collapse hides (tool output past `COLLAPSED_OUTPUT_LINES`, hidden diffs) so a
10
+ * jump can reveal it first.
11
+ */
12
+ /** Where in a block the text sits: `output` and `diff` may be collapsed or hidden. */
13
+ export type SearchPartKind = "text" | "output" | "diff";
14
+ export type SearchPart = {
15
+ kind: SearchPartKind;
16
+ text: string;
17
+ };
18
+ export type SearchMatch = {
19
+ /** Index into `state.blocks`. */
20
+ block: number;
21
+ /** Which occurrence in that block, in drawn order (0 = first). */
22
+ ordinal: number;
23
+ kind: SearchPartKind;
24
+ /** Line index within its part (output lines decide whether a collapse hides it). */
25
+ line: number;
26
+ /** The whole line the match is on, and the match's [start, end) in it. */
27
+ text: string;
28
+ start: number;
29
+ end: number;
30
+ };
31
+ /** More than this many matches show as `999+`; the search stops collecting there. */
32
+ export declare const MAX_SEARCH_MATCHES = 999;
33
+ /** Smart case: a query with a capital letter matches case; otherwise case is ignored. */
34
+ export declare function caseSensitive(query: string): boolean;
35
+ /** Every [start, end) of `query` in `text` under the smart-case rule; empty for an empty query. */
36
+ export declare function occurrences(text: string, query: string): Array<[number, number]>;
37
+ /** The searchable text of one block, in the order the transcript draws it. */
38
+ export declare function searchableParts(block: TuiEventBlock, cwd: string, anchors?: LineAnchors, renderers?: readonly TuiRendererHook[]): SearchPart[];
39
+ /** Every match of `query` across the transcript, oldest first, capped at `MAX_SEARCH_MATCHES`. */
40
+ export declare function findMatches(blocks: readonly TuiEventBlock[], query: string, cwd: string, anchors?: (block: ToolBlock) => LineAnchors | undefined, renderers?: readonly TuiRendererHook[]): SearchMatch[];
41
+ /** `3/12`, `0/0`, or `1/999+` at the cap. */
42
+ export declare function matchCounter(index: number | undefined, total: number): string;
43
+ /** Whether a tool must expand (or show its diff) for this match to be drawn. */
44
+ export declare function revealNeeded(match: SearchMatch): {
45
+ expand: boolean;
46
+ showDiff: boolean;
47
+ };
48
+ /** The match line cut to `width` cells around the match: `before`, `match`, `after`, with `…` where cut. */
49
+ export declare function matchSnippet(match: Pick<SearchMatch, "text" | "start" | "end">, width: number): {
50
+ before: string;
51
+ match: string;
52
+ after: string;
53
+ };
54
+ //# sourceMappingURL=transcript-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript-search.d.ts","sourceRoot":"","sources":["../src/transcript-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uDAAuD,CAAC;AAG3F,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAC;AAE7F;;;;;;GAMG;AAEH,sFAAsF;AACtF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAA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,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAIvF;AAED,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAehJ"}
@@ -0,0 +1,160 @@
1
+ import stringWidth from "string-width";
2
+ import { blockPanel, isPanelBlock } from "./block-panels.js";
3
+ import { toolDiffs } from "./tool-diff.js";
4
+ import { COLLAPSED_OUTPUT_LINES, toolPresentation } from "./tool-presentation.js";
5
+ import { blockToRow, normalize } from "./transcript.js";
6
+ import { workflowTexts, workflowView } from "./workflow-tools.js";
7
+ import { renderedTool } from "./tool-renderer-view.js";
8
+ import { findToolRenderer } from "@onpoint-dev-tools/crewcoder-tui-core/state/tool-renderers";
9
+ /** More than this many matches show as `999+`; the search stops collecting there. */
10
+ export const MAX_SEARCH_MATCHES = 999;
11
+ /** Smart case: a query with a capital letter matches case; otherwise case is ignored. */
12
+ export function caseSensitive(query) {
13
+ return /\p{Lu}/u.test(query);
14
+ }
15
+ /** Every [start, end) of `query` in `text` under the smart-case rule; empty for an empty query. */
16
+ export function occurrences(text, query) {
17
+ if (!query)
18
+ return [];
19
+ const sensitive = caseSensitive(query);
20
+ const haystack = sensitive ? text : text.toLowerCase();
21
+ const needle = sensitive ? query : query.toLowerCase();
22
+ // Lowercasing can change length (e.g. "İ"); fall back to the original text then.
23
+ if (haystack.length !== text.length)
24
+ return exactOccurrences(text, query);
25
+ return exactOccurrences(haystack, needle);
26
+ }
27
+ function exactOccurrences(text, query) {
28
+ const found = [];
29
+ for (let index = text.indexOf(query); index !== -1; index = text.indexOf(query, index + query.length)) {
30
+ found.push([index, index + query.length]);
31
+ }
32
+ return found;
33
+ }
34
+ /** The searchable text of one block, in the order the transcript draws it. */
35
+ export function searchableParts(block, cwd, anchors, renderers = []) {
36
+ if (block.type === "tool")
37
+ return toolParts(block, cwd, anchors, renderers);
38
+ if (block.type === "approval") {
39
+ const status = block.status === "pending" ? "waiting for approval" : block.status;
40
+ return parts([`Approval · ${block.toolName ?? "tool"} · ${status}`, block.resolutionReason ? normalize(block.resolutionReason) : undefined]);
41
+ }
42
+ if (isPanelBlock(block)) {
43
+ const panel = blockPanel(block);
44
+ return parts([panel.meta ? `${panel.title} ${panel.meta}` : panel.title, ...panel.lines.map((line) => line.text)]);
45
+ }
46
+ const row = blockToRow(block);
47
+ return parts([row.text, row.detail]);
48
+ }
49
+ function parts(texts) {
50
+ return texts.filter((text) => Boolean(text)).map((text) => ({ kind: "text", text }));
51
+ }
52
+ /** Title row (title, target, status), then the output or the edit's diff lines. */
53
+ function toolParts(block, cwd, anchors, renderers) {
54
+ const tool = toolPresentation(block, cwd, "text");
55
+ const status = block.status === "running" ? "running…" : tool.failed ? "failed" : undefined;
56
+ // An extension renderer replaces the whole view: its title, source, and filled-in template.
57
+ const renderer = findToolRenderer(block, renderers);
58
+ if (renderer) {
59
+ const view = renderedTool(block, renderer);
60
+ return parts([[view.title, view.source, status].filter(Boolean).join(" "), view.body]);
61
+ }
62
+ const workflow = workflowView(block);
63
+ // A plan or clarify step shows its arguments, never collapsed, instead of a target and output.
64
+ if (workflow) {
65
+ const header = [workflow.title, status].filter(Boolean).join(" ");
66
+ return [header, ...workflowTexts(workflow)].map((text) => ({ kind: "text", text }));
67
+ }
68
+ const header = [tool.title || block.name, tool.layout === "inline" ? tool.target : undefined, status].filter(Boolean).join(" ");
69
+ const result = [{ kind: "text", text: header }];
70
+ if (tool.layout === "stacked" && tool.target)
71
+ result.push({ kind: "text", text: tool.target });
72
+ const diffs = toolDiffs(block, cwd, anchors);
73
+ if (diffs.length === 0) {
74
+ if (tool.output)
75
+ result.push({ kind: "output", text: tool.output });
76
+ return result;
77
+ }
78
+ // `<diff>` draws +/- in its gutter, so exact diffs search the line without its sign.
79
+ const body = diffs.flatMap((diff) => (diff.exactLines ? diff.body.map(stripSign) : diff.body));
80
+ if (body.length > 0)
81
+ result.push({ kind: "diff", text: body.join("\n") });
82
+ return result;
83
+ }
84
+ function stripSign(line) {
85
+ return /^[+\- ]/.test(line) ? line.slice(1) : line;
86
+ }
87
+ /** Every match of `query` across the transcript, oldest first, capped at `MAX_SEARCH_MATCHES`. */
88
+ export function findMatches(blocks, query, cwd, anchors, renderers = []) {
89
+ const matches = [];
90
+ if (!query)
91
+ return matches;
92
+ for (const [index, block] of blocks.entries()) {
93
+ let ordinal = 0;
94
+ for (const part of searchableParts(block, cwd, block.type === "tool" ? anchors?.(block) : undefined, renderers)) {
95
+ for (const [line, text] of part.text.split("\n").entries()) {
96
+ for (const [start, end] of occurrences(text, query)) {
97
+ matches.push({ block: index, ordinal, kind: part.kind, line, text, start, end });
98
+ ordinal += 1;
99
+ if (matches.length >= MAX_SEARCH_MATCHES)
100
+ return matches;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ return matches;
106
+ }
107
+ /** `3/12`, `0/0`, or `1/999+` at the cap. */
108
+ export function matchCounter(index, total) {
109
+ const count = total >= MAX_SEARCH_MATCHES ? `${MAX_SEARCH_MATCHES}+` : String(total);
110
+ return `${index === undefined ? 0 : index + 1}/${count}`;
111
+ }
112
+ /** Whether a tool must expand (or show its diff) for this match to be drawn. */
113
+ export function revealNeeded(match) {
114
+ if (match.kind === "output")
115
+ return { expand: match.line >= COLLAPSED_OUTPUT_LINES, showDiff: false };
116
+ if (match.kind === "diff")
117
+ return { expand: match.line >= COLLAPSED_OUTPUT_LINES, showDiff: true };
118
+ return { expand: false, showDiff: false };
119
+ }
120
+ /** The match line cut to `width` cells around the match: `before`, `match`, `after`, with `…` where cut. */
121
+ export function matchSnippet(match, width) {
122
+ const line = match.text.replace(/\t/g, " ");
123
+ let before = line.slice(0, match.start).trimStart();
124
+ let hit = line.slice(match.start, match.end);
125
+ let after = line.slice(match.end).trimEnd();
126
+ const room = Math.max(1, width);
127
+ // A line that fits is shown whole.
128
+ if (stringWidth(before + hit + after) <= room)
129
+ return { before, match: hit, after };
130
+ hit = fitEnd(hit, room);
131
+ // Context on the left gets up to a third of what is left; the rest goes to the right.
132
+ const left = Math.floor((room - stringWidth(hit)) / 3);
133
+ if (stringWidth(before) > left)
134
+ before = left > 1 ? `…${fitStart(before, left - 1)}` : "";
135
+ const right = room - stringWidth(before) - stringWidth(hit);
136
+ if (stringWidth(after) > right)
137
+ after = right > 1 ? `${fitEnd(after, right - 1)}…` : "";
138
+ return { before, match: hit, after };
139
+ }
140
+ /** The longest start of `text` that fits `width` cells. */
141
+ function fitEnd(text, width) {
142
+ let result = "";
143
+ for (const char of text) {
144
+ if (stringWidth(result + char) > width)
145
+ break;
146
+ result += char;
147
+ }
148
+ return result;
149
+ }
150
+ /** The longest end of `text` that fits `width` cells. */
151
+ function fitStart(text, width) {
152
+ let result = "";
153
+ for (const char of Array.from(text).reverse()) {
154
+ if (stringWidth(char + result) > width)
155
+ break;
156
+ result = char + result;
157
+ }
158
+ return result;
159
+ }
160
+ //# sourceMappingURL=transcript-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript-search.js","sourceRoot":"","sources":["../src/transcript-search.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAoB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE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a;IACzC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,KAAK;YAAE,MAAM;QAC9C,MAAM,IAAI,IAAI,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,yDAAyD;AACzD,SAAS,QAAQ,CAAC,IAAY,EAAE,KAAa;IAC3C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC9C,IAAI,WAAW,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,KAAK;YAAE,MAAM;QAC9C,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { TuiEventBlock } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tui-store\";\nimport stringWidth from \"string-width\";\nimport { blockPanel, isPanelBlock } from \"./block-panels.js\";\nimport { toolDiffs, type LineAnchors } from \"./tool-diff.js\";\nimport { COLLAPSED_OUTPUT_LINES, toolPresentation } from \"./tool-presentation.js\";\nimport { blockToRow, normalize, type ToolBlock } from \"./transcript.js\";\nimport { workflowTexts, workflowView } from \"./workflow-tools.js\";\nimport { renderedTool } from \"./tool-renderer-view.js\";\nimport { findToolRenderer } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tool-renderers\";\nimport type { TuiRendererHook } from \"@onpoint-dev-tools/crewcoder-tui-core/state/tui-store\";\n\n/**\n * Transcript search (`docs/TRANSCRIPT.md#search`): which blocks match a query,\n * in event order. Pure, so it is tested without a renderer. It searches the\n * text each block draws, not labels such as `CREW CODER`, and covers what a\n * collapse hides (tool output past `COLLAPSED_OUTPUT_LINES`, hidden diffs) so a\n * jump can reveal it first.\n */\n\n/** Where in a block the text sits: `output` and `diff` may be collapsed or hidden. */\nexport type SearchPartKind = \"text\" | \"output\" | \"diff\";\n\nexport type SearchPart = { kind: SearchPartKind; text: string };\n\nexport type SearchMatch = {\n /** Index into `state.blocks`. */\n block: number;\n /** Which occurrence in that block, in drawn order (0 = first). */\n ordinal: number;\n kind: SearchPartKind;\n /** Line index within its part (output lines decide whether a collapse hides it). */\n line: number;\n /** The whole line the match is on, and the match's [start, end) in it. */\n text: string;\n start: number;\n end: number;\n};\n\n/** More than this many matches show as `999+`; the search stops collecting there. */\nexport const MAX_SEARCH_MATCHES = 999;\n\n/** Smart case: a query with a capital letter matches case; otherwise case is ignored. */\nexport function caseSensitive(query: string): boolean {\n return /\\p{Lu}/u.test(query);\n}\n\n/** Every [start, end) of `query` in `text` under the smart-case rule; empty for an empty query. */\nexport function occurrences(text: string, query: string): Array<[number, number]> {\n if (!query) return [];\n const sensitive = caseSensitive(query);\n const haystack = sensitive ? text : text.toLowerCase();\n const needle = sensitive ? query : query.toLowerCase();\n // Lowercasing can change length (e.g. \"İ\"); fall back to the original text then.\n if (haystack.length !== text.length) return exactOccurrences(text, query);\n return exactOccurrences(haystack, needle);\n}\n\nfunction exactOccurrences(text: string, query: string): Array<[number, number]> {\n const found: Array<[number, number]> = [];\n for (let index = text.indexOf(query); index !== -1; index = text.indexOf(query, index + query.length)) {\n found.push([index, index + query.length]);\n }\n return found;\n}\n\n/** The searchable text of one block, in the order the transcript draws it. */\nexport function searchableParts(block: TuiEventBlock, cwd: string, anchors?: LineAnchors, renderers: readonly TuiRendererHook[] = []): SearchPart[] {\n if (block.type === \"tool\") return toolParts(block, cwd, anchors, renderers);\n if (block.type === \"approval\") {\n const status = block.status === \"pending\" ? \"waiting for approval\" : block.status;\n return parts([`Approval · ${block.toolName ?? \"tool\"} · ${status}`, block.resolutionReason ? normalize(block.resolutionReason) : undefined]);\n }\n if (isPanelBlock(block)) {\n const panel = blockPanel(block);\n return parts([panel.meta ? `${panel.title} ${panel.meta}` : panel.title, ...panel.lines.map((line) => line.text)]);\n }\n const row = blockToRow(block);\n return parts([row.text, row.detail]);\n}\n\nfunction parts(texts: ReadonlyArray<string | undefined>): SearchPart[] {\n return texts.filter((text): text is string => Boolean(text)).map((text) => ({ kind: \"text\", text }));\n}\n\n/** Title row (title, target, status), then the output or the edit's diff lines. */\nfunction toolParts(block: ToolBlock, cwd: string, anchors: LineAnchors | undefined, renderers: readonly TuiRendererHook[]): SearchPart[] {\n const tool = toolPresentation(block, cwd, \"text\");\n const status = block.status === \"running\" ? \"running…\" : tool.failed ? \"failed\" : undefined;\n // An extension renderer replaces the whole view: its title, source, and filled-in template.\n const renderer = findToolRenderer(block, renderers);\n if (renderer) {\n const view = renderedTool(block, renderer);\n return parts([[view.title, view.source, status].filter(Boolean).join(\" \"), view.body]);\n }\n const workflow = workflowView(block);\n // A plan or clarify step shows its arguments, never collapsed, instead of a target and output.\n if (workflow) {\n const header = [workflow.title, status].filter(Boolean).join(\" \");\n return [header, ...workflowTexts(workflow)].map((text): SearchPart => ({ kind: \"text\", text }));\n }\n const header = [tool.title || block.name, tool.layout === \"inline\" ? tool.target : undefined, status].filter(Boolean).join(\" \");\n const result: SearchPart[] = [{ kind: \"text\", text: header }];\n if (tool.layout === \"stacked\" && tool.target) result.push({ kind: \"text\", text: tool.target });\n const diffs = toolDiffs(block, cwd, anchors);\n if (diffs.length === 0) {\n if (tool.output) result.push({ kind: \"output\", text: tool.output });\n return result;\n }\n // `<diff>` draws +/- in its gutter, so exact diffs search the line without its sign.\n const body = diffs.flatMap((diff) => (diff.exactLines ? diff.body.map(stripSign) : diff.body));\n if (body.length > 0) result.push({ kind: \"diff\", text: body.join(\"\\n\") });\n return result;\n}\n\nfunction stripSign(line: string): string {\n return /^[+\\- ]/.test(line) ? line.slice(1) : line;\n}\n\n/** Every match of `query` across the transcript, oldest first, capped at `MAX_SEARCH_MATCHES`. */\nexport function findMatches(\n blocks: readonly TuiEventBlock[],\n query: string,\n cwd: string,\n anchors?: (block: ToolBlock) => LineAnchors | undefined,\n renderers: readonly TuiRendererHook[] = []\n): SearchMatch[] {\n const matches: SearchMatch[] = [];\n if (!query) return matches;\n for (const [index, block] of blocks.entries()) {\n let ordinal = 0;\n for (const part of searchableParts(block, cwd, block.type === \"tool\" ? anchors?.(block) : undefined, renderers)) {\n for (const [line, text] of part.text.split(\"\\n\").entries()) {\n for (const [start, end] of occurrences(text, query)) {\n matches.push({ block: index, ordinal, kind: part.kind, line, text, start, end });\n ordinal += 1;\n if (matches.length >= MAX_SEARCH_MATCHES) return matches;\n }\n }\n }\n }\n return matches;\n}\n\n/** `3/12`, `0/0`, or `1/999+` at the cap. */\nexport function matchCounter(index: number | undefined, total: number): string {\n const count = total >= MAX_SEARCH_MATCHES ? `${MAX_SEARCH_MATCHES}+` : String(total);\n return `${index === undefined ? 0 : index + 1}/${count}`;\n}\n\n/** Whether a tool must expand (or show its diff) for this match to be drawn. */\nexport function revealNeeded(match: SearchMatch): { expand: boolean; showDiff: boolean } {\n if (match.kind === \"output\") return { expand: match.line >= COLLAPSED_OUTPUT_LINES, showDiff: false };\n if (match.kind === \"diff\") return { expand: match.line >= COLLAPSED_OUTPUT_LINES, showDiff: true };\n return { expand: false, showDiff: false };\n}\n\n/** The match line cut to `width` cells around the match: `before`, `match`, `after`, with `…` where cut. */\nexport function matchSnippet(match: Pick<SearchMatch, \"text\" | \"start\" | \"end\">, width: number): { before: string; match: string; after: string } {\n const line = match.text.replace(/\\t/g, \" \");\n let before = line.slice(0, match.start).trimStart();\n let hit = line.slice(match.start, match.end);\n let after = line.slice(match.end).trimEnd();\n const room = Math.max(1, width);\n // A line that fits is shown whole.\n if (stringWidth(before + hit + after) <= room) return { before, match: hit, after };\n hit = fitEnd(hit, room);\n // Context on the left gets up to a third of what is left; the rest goes to the right.\n const left = Math.floor((room - stringWidth(hit)) / 3);\n if (stringWidth(before) > left) before = left > 1 ? `…${fitStart(before, left - 1)}` : \"\";\n const right = room - stringWidth(before) - stringWidth(hit);\n if (stringWidth(after) > right) after = right > 1 ? `${fitEnd(after, right - 1)}…` : \"\";\n return { before, match: hit, after };\n}\n\n/** The longest start of `text` that fits `width` cells. */\nfunction fitEnd(text: string, width: number): string {\n let result = \"\";\n for (const char of text) {\n if (stringWidth(result + char) > width) break;\n result += char;\n }\n return result;\n}\n\n/** The longest end of `text` that fits `width` cells. */\nfunction fitStart(text: string, width: number): string {\n let result = \"\";\n for (const char of Array.from(text).reverse()) {\n if (stringWidth(char + result) > width) break;\n result = char + result;\n }\n return result;\n}\n"]}
@@ -0,0 +1,59 @@
1
+ import type { TuiEventBlock } from "@onpoint-dev-tools/crewcoder-tui-core/state/tui-store";
2
+ export type TranscriptTone = "user" | "assistant" | "thinking" | "tool" | "approval" | "error" | "system" | "muted";
3
+ export type TranscriptRow = {
4
+ label: string;
5
+ tone: TranscriptTone;
6
+ text: string;
7
+ /** Muted context rendered under the row, such as user-message background. */
8
+ detail?: string;
9
+ };
10
+ export type ToolBlock = Extract<TuiEventBlock, {
11
+ type: "tool";
12
+ }>;
13
+ export type ApprovalBlock = Extract<TuiEventBlock, {
14
+ type: "approval";
15
+ }>;
16
+ /** Blocks that belong to the agent's work: tool calls and the approvals that gate them. */
17
+ export type WorkBlock = ToolBlock | ApprovalBlock;
18
+ /**
19
+ * A turn reads as sections in event order: a run of consecutive tool calls and
20
+ * approvals is one `work` section (the Agent work box); every other block is
21
+ * its own section. Blocks are never reordered.
22
+ */
23
+ export type TranscriptSection = {
24
+ kind: "work";
25
+ blocks: WorkBlock[];
26
+ start: number;
27
+ } | {
28
+ kind: "block";
29
+ block: TuiEventBlock;
30
+ start: number;
31
+ };
32
+ export declare function transcriptSections(blocks: readonly TuiEventBlock[]): TranscriptSection[];
33
+ /** The crew worker that produced a block, if any (`worker` is set by the reducer during crews). */
34
+ export declare function workerOf(block: TuiEventBlock | undefined): string | undefined;
35
+ /** Per-tool display state, owned by SessionController. */
36
+ export type ToolExpansion = {
37
+ /** Long output or diff shown in full rather than collapsed. */
38
+ isExpanded(block: ToolBlock): boolean;
39
+ toggle(block: ToolBlock): void;
40
+ /** The file diff of an edit is shown (not hidden). */
41
+ isDiffShown(block: ToolBlock): boolean;
42
+ toggleDiff(block: ToolBlock): void;
43
+ /** Real file lines of a finished snippet edit, once read (see `computeLineAnchors`). */
44
+ lineAnchors(block: ToolBlock): ReadonlyMap<string, number> | undefined;
45
+ };
46
+ /** The last assistant/thinking block of an active run still grows; the reducer only appends to it. */
47
+ export declare function isStreaming(block: TuiEventBlock, isLast: boolean, running: boolean): boolean;
48
+ /** Convert a reducer block into a display row. Pure, so it is tested without a renderer. */
49
+ export declare function blockToRow(block: TuiEventBlock): TranscriptRow;
50
+ /**
51
+ * A reply's generation speed beside its label (`42.3 tok/s`), once its
52
+ * `message_end` reported it. The agent times only generation, not tools or
53
+ * approvals inside the call (`GenerationClock`). Streaming, replayed, and
54
+ * synthetic replies have none.
55
+ */
56
+ export declare function throughputLabel(block: TuiEventBlock): string | undefined;
57
+ /** Normalize line endings and strip terminal control sequences from agent text. */
58
+ export declare function normalize(text: string): string;
59
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uDAAuD,CAAC;AAI3F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEpH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,MAAM,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