@abacus-ai/cli 1.106.25007 → 2.0.0-canary.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 (200) hide show
  1. package/.oxlintrc.json +8 -0
  2. package/dist/index.mjs +12603 -0
  3. package/package.json +7 -39
  4. package/resources/abacus.ico +0 -0
  5. package/resources/entitlements.plist +9 -0
  6. package/src/__e2e__/README.md +196 -0
  7. package/src/__e2e__/agent-interactions.e2e.test.tsx +61 -0
  8. package/src/__e2e__/cli-commands.e2e.test.tsx +77 -0
  9. package/src/__e2e__/conversation-throttle.e2e.test.ts +453 -0
  10. package/src/__e2e__/conversation.e2e.test.tsx +56 -0
  11. package/src/__e2e__/diff-preview.e2e.test.tsx +3399 -0
  12. package/src/__e2e__/file-creation.e2e.test.tsx +149 -0
  13. package/src/__e2e__/helpers/test-helpers.ts +450 -0
  14. package/src/__e2e__/keyboard-navigation.e2e.test.tsx +34 -0
  15. package/src/__e2e__/llm-models.e2e.test.ts +402 -0
  16. package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +71 -0
  17. package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +167 -0
  18. package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +185 -0
  19. package/src/__e2e__/repl.e2e.test.tsx +78 -0
  20. package/src/__e2e__/shell-compatibility.e2e.test.tsx +76 -0
  21. package/src/__e2e__/theme-mcp.e2e.test.tsx +98 -0
  22. package/src/__e2e__/tool-permissions.e2e.test.tsx +66 -0
  23. package/src/args.ts +22 -0
  24. package/src/components/__tests__/react-compiler.test.tsx +78 -0
  25. package/src/components/__tests__/status-indicator.test.tsx +403 -0
  26. package/src/components/composer/__tests__/bash-runner.test.tsx +263 -0
  27. package/src/components/composer/agent-mode-indicator.tsx +63 -0
  28. package/src/components/composer/bash-runner.tsx +54 -0
  29. package/src/components/composer/commands/default-commands.tsx +615 -0
  30. package/src/components/composer/commands/handler.tsx +59 -0
  31. package/src/components/composer/commands/picker.tsx +273 -0
  32. package/src/components/composer/commands/registry.ts +233 -0
  33. package/src/components/composer/commands/types.ts +33 -0
  34. package/src/components/composer/context.tsx +88 -0
  35. package/src/components/composer/file-mention-picker.tsx +83 -0
  36. package/src/components/composer/help.tsx +44 -0
  37. package/src/components/composer/index.tsx +1006 -0
  38. package/src/components/composer/mentions.ts +57 -0
  39. package/src/components/composer/message-queue.tsx +70 -0
  40. package/src/components/composer/mode-panel.tsx +35 -0
  41. package/src/components/composer/modes/__tests__/bash-handler.test.tsx +755 -0
  42. package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +1108 -0
  43. package/src/components/composer/modes/bash-handler.tsx +132 -0
  44. package/src/components/composer/modes/bash-renderer.tsx +175 -0
  45. package/src/components/composer/modes/default-handlers.tsx +33 -0
  46. package/src/components/composer/modes/index.ts +41 -0
  47. package/src/components/composer/modes/types.ts +21 -0
  48. package/src/components/composer/persistent-shell.ts +283 -0
  49. package/src/components/composer/process.ts +65 -0
  50. package/src/components/composer/types.ts +9 -0
  51. package/src/components/composer/use-mention-search.ts +68 -0
  52. package/src/components/error-boundry.tsx +60 -0
  53. package/src/components/exit-message.tsx +29 -0
  54. package/src/components/expanded-view.tsx +74 -0
  55. package/src/components/file-completion.tsx +127 -0
  56. package/src/components/header.tsx +47 -0
  57. package/src/components/logo.tsx +37 -0
  58. package/src/components/segments.tsx +356 -0
  59. package/src/components/status-indicator.tsx +306 -0
  60. package/src/components/tool-group-summary.tsx +263 -0
  61. package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +312 -0
  62. package/src/components/tool-permissions/diff-preview.tsx +355 -0
  63. package/src/components/tool-permissions/index.ts +5 -0
  64. package/src/components/tool-permissions/permission-options.tsx +375 -0
  65. package/src/components/tool-permissions/permission-preview-header.tsx +57 -0
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +398 -0
  67. package/src/components/tools/agent/ask-user-question.tsx +101 -0
  68. package/src/components/tools/agent/enter-plan-mode.tsx +49 -0
  69. package/src/components/tools/agent/exit-plan-mode.tsx +75 -0
  70. package/src/components/tools/agent/handoff-to-main.tsx +27 -0
  71. package/src/components/tools/agent/subagent.tsx +37 -0
  72. package/src/components/tools/agent/todo-write.tsx +104 -0
  73. package/src/components/tools/browser/close-tab.tsx +58 -0
  74. package/src/components/tools/browser/computer.tsx +70 -0
  75. package/src/components/tools/browser/get-interactive-elements.tsx +54 -0
  76. package/src/components/tools/browser/get-tab-content.tsx +51 -0
  77. package/src/components/tools/browser/navigate-to.tsx +59 -0
  78. package/src/components/tools/browser/new-tab.tsx +60 -0
  79. package/src/components/tools/browser/perform-action.tsx +63 -0
  80. package/src/components/tools/browser/refresh-tab.tsx +43 -0
  81. package/src/components/tools/browser/switch-tab.tsx +58 -0
  82. package/src/components/tools/filesystem/delete-file.tsx +104 -0
  83. package/src/components/tools/filesystem/edit.tsx +220 -0
  84. package/src/components/tools/filesystem/list-dir.tsx +78 -0
  85. package/src/components/tools/filesystem/read-file.tsx +180 -0
  86. package/src/components/tools/filesystem/upload-image.tsx +76 -0
  87. package/src/components/tools/ide/ide-diagnostics.tsx +62 -0
  88. package/src/components/tools/index.ts +91 -0
  89. package/src/components/tools/mcp/mcp-tool.tsx +158 -0
  90. package/src/components/tools/search/fetch-url.tsx +73 -0
  91. package/src/components/tools/search/file-search.tsx +78 -0
  92. package/src/components/tools/search/grep.tsx +90 -0
  93. package/src/components/tools/search/semantic-search.tsx +66 -0
  94. package/src/components/tools/search/web-search.tsx +71 -0
  95. package/src/components/tools/shared/index.tsx +48 -0
  96. package/src/components/tools/shared/zod-coercion.ts +35 -0
  97. package/src/components/tools/terminal/bash-tool-output.tsx +174 -0
  98. package/src/components/tools/terminal/get-terminal-output.tsx +85 -0
  99. package/src/components/tools/terminal/run-in-terminal.tsx +106 -0
  100. package/src/components/tools/types.ts +16 -0
  101. package/src/components/tools.tsx +66 -0
  102. package/src/components/ui/__tests__/divider.test.tsx +61 -0
  103. package/src/components/ui/__tests__/gradient.test.tsx +125 -0
  104. package/src/components/ui/__tests__/input.test.tsx +166 -0
  105. package/src/components/ui/__tests__/select.test.tsx +273 -0
  106. package/src/components/ui/__tests__/shimmer.test.tsx +99 -0
  107. package/src/components/ui/blinking-indicator.tsx +25 -0
  108. package/src/components/ui/divider.tsx +162 -0
  109. package/src/components/ui/gradient.tsx +56 -0
  110. package/src/components/ui/input.tsx +228 -0
  111. package/src/components/ui/select.tsx +151 -0
  112. package/src/components/ui/shimmer.tsx +84 -0
  113. package/src/context/agent-mode.tsx +95 -0
  114. package/src/context/extension-file.tsx +136 -0
  115. package/src/context/network-activity.tsx +45 -0
  116. package/src/context/notification.tsx +62 -0
  117. package/src/context/shell-size.tsx +49 -0
  118. package/src/context/shell-title.tsx +38 -0
  119. package/src/entrypoints/print-mode.ts +312 -0
  120. package/src/entrypoints/repl.tsx +401 -0
  121. package/src/hooks/use-agent.ts +15 -0
  122. package/src/hooks/use-api-client.ts +1 -0
  123. package/src/hooks/use-available-height.ts +8 -0
  124. package/src/hooks/use-cleanup.ts +29 -0
  125. package/src/hooks/use-interrupt-manager.ts +242 -0
  126. package/src/hooks/use-models.ts +22 -0
  127. package/src/index.ts +217 -0
  128. package/src/lib/__tests__/ansi.test.ts +255 -0
  129. package/src/lib/__tests__/cli.test.ts +122 -0
  130. package/src/lib/__tests__/commands.test.ts +325 -0
  131. package/src/lib/__tests__/constants.test.ts +15 -0
  132. package/src/lib/__tests__/focusables.test.ts +25 -0
  133. package/src/lib/__tests__/fs.test.ts +231 -0
  134. package/src/lib/__tests__/markdown.test.tsx +348 -0
  135. package/src/lib/__tests__/mcpCommandHandler.test.ts +173 -0
  136. package/src/lib/__tests__/mcpManagement.test.ts +38 -0
  137. package/src/lib/__tests__/path-paste.test.ts +144 -0
  138. package/src/lib/__tests__/path.test.ts +300 -0
  139. package/src/lib/__tests__/queries.test.ts +39 -0
  140. package/src/lib/__tests__/standaloneMcpService.test.ts +71 -0
  141. package/src/lib/__tests__/text-buffer.test.ts +328 -0
  142. package/src/lib/__tests__/text-utils.test.ts +32 -0
  143. package/src/lib/__tests__/timing.test.ts +78 -0
  144. package/src/lib/__tests__/utils.test.ts +238 -0
  145. package/src/lib/__tests__/vim-buffer-actions.test.ts +154 -0
  146. package/src/lib/ansi.ts +150 -0
  147. package/src/lib/cli-push-server.ts +112 -0
  148. package/src/lib/cli.ts +44 -0
  149. package/src/lib/clipboard.ts +226 -0
  150. package/src/lib/command-utils.ts +93 -0
  151. package/src/lib/commands.ts +270 -0
  152. package/src/lib/constants.ts +3 -0
  153. package/src/lib/extension-connection.ts +181 -0
  154. package/src/lib/focusables.ts +7 -0
  155. package/src/lib/fs.ts +533 -0
  156. package/src/lib/markdown/code-block.tsx +63 -0
  157. package/src/lib/markdown/index.ts +4 -0
  158. package/src/lib/markdown/link.tsx +19 -0
  159. package/src/lib/markdown/markdown.tsx +372 -0
  160. package/src/lib/markdown/types.ts +15 -0
  161. package/src/lib/mcpCommandHandler.ts +121 -0
  162. package/src/lib/mcpManagement.ts +44 -0
  163. package/src/lib/path-paste.ts +185 -0
  164. package/src/lib/path.ts +179 -0
  165. package/src/lib/queries.ts +15 -0
  166. package/src/lib/standaloneMcpService.ts +688 -0
  167. package/src/lib/status-utils.ts +237 -0
  168. package/src/lib/test-utils.tsx +72 -0
  169. package/src/lib/text-buffer.ts +2415 -0
  170. package/src/lib/text-utils.ts +272 -0
  171. package/src/lib/timing.ts +63 -0
  172. package/src/lib/types.ts +295 -0
  173. package/src/lib/utils.ts +182 -0
  174. package/src/lib/vim-buffer-actions.ts +732 -0
  175. package/src/providers/agent.tsx +1075 -0
  176. package/src/providers/api-client.tsx +43 -0
  177. package/src/services/logger.ts +85 -0
  178. package/src/terminal/detection.ts +187 -0
  179. package/src/terminal/exit.ts +279 -0
  180. package/src/terminal/notification.ts +83 -0
  181. package/src/terminal/progress.ts +201 -0
  182. package/src/terminal/setup.ts +797 -0
  183. package/src/terminal/suspend.ts +58 -0
  184. package/src/terminal/types.ts +51 -0
  185. package/src/theme/context.tsx +57 -0
  186. package/src/theme/index.ts +4 -0
  187. package/src/theme/themed.tsx +35 -0
  188. package/src/theme/themes.json +546 -0
  189. package/src/theme/types.ts +110 -0
  190. package/src/tools/types.ts +59 -0
  191. package/src/tools/utils/__tests__/zod-coercion.test.ts +33 -0
  192. package/src/tools/utils/tool-ui-components.tsx +631 -0
  193. package/src/tools/utils/zod-coercion.ts +35 -0
  194. package/tsconfig.json +11 -0
  195. package/tsconfig.node.json +29 -0
  196. package/tsconfig.test.json +27 -0
  197. package/tsdown.config.ts +17 -0
  198. package/vitest.config.ts +76 -0
  199. package/README.md +0 -28
  200. package/dist/index.js +0 -26
@@ -0,0 +1,356 @@
1
+ import { View, Text } from "@codellm/jar";
2
+ import { Fragment, memo, useMemo, useState, useEffect, useRef, startTransition } from "react";
3
+
4
+ import { Markdown } from "../lib/markdown/index.js";
5
+ import { capitalize, getRandomWord } from "../lib/status-utils.js";
6
+ import { formatDurationMs } from "../lib/timing.js";
7
+ import { HistorySegment } from "../lib/types.js";
8
+ import { getSegmentContent } from "../lib/utils.js";
9
+ import { useTheme } from "../theme/index.js";
10
+ import { ErrorBoundary } from "./error-boundry.js";
11
+ import { Tool } from "./tools.js";
12
+ import { BlinkingIndicator } from "./ui/blinking-indicator.js";
13
+ import { Shimmer } from "./ui/shimmer.js";
14
+
15
+ const TextSegment = memo((props: HistorySegment) => {
16
+ const { type, segment, isSpinny = false, source } = props;
17
+ if (type !== "text") {
18
+ throw Error(`Can only render text segments, got ${type}`);
19
+ }
20
+
21
+ const content = useMemo(() => getSegmentContent(segment), [segment]);
22
+
23
+ if (!content?.trim()) {
24
+ return null;
25
+ }
26
+
27
+ // User text segments - dim italic with ❯ prefix
28
+ if (source === "user") {
29
+ return (
30
+ <View flexDirection="row" gap={1}>
31
+ <Text color="white">❯</Text>
32
+ <Text dimColor italic>
33
+ {content}
34
+ </Text>
35
+ </View>
36
+ );
37
+ }
38
+
39
+ // Bot text segments - spinny shows shimmer, normal shows markdown with ⏺ prefix
40
+ if (isSpinny) {
41
+ return (
42
+ <View flexDirection="row" alignItems="center" gap={1}>
43
+ <Shimmer text={content} />
44
+ </View>
45
+ );
46
+ }
47
+
48
+ return (
49
+ <View flexDirection="column">
50
+ <View flexDirection="row" gap={1}>
51
+ <Text color="white">⏺</Text>
52
+ <Markdown>{content.trimStart()}</Markdown>
53
+ </View>
54
+ </View>
55
+ );
56
+ });
57
+ TextSegment.displayName = "TextSegment";
58
+
59
+ /**
60
+ * Expanded thinking segment: shows full thought content + duration.
61
+ * Used in expanded view where thoughts are always visible.
62
+ */
63
+ export const ExpandedThinkingSegment = memo((props: HistorySegment) => {
64
+ const { segment, thinkingStartTime, thinkingEndTime } = props;
65
+ const { colors } = useTheme();
66
+ const content = useMemo(() => getSegmentContent(segment), [segment]);
67
+ const duration = useMemo(() => {
68
+ if (thinkingStartTime && thinkingEndTime) {
69
+ return `thought for ${formatDurationMs(thinkingEndTime - thinkingStartTime)}`;
70
+ }
71
+ return null;
72
+ }, [thinkingStartTime, thinkingEndTime]);
73
+
74
+ return (
75
+ <View flexDirection="row" gap={1} alignItems="flex-start">
76
+ <Text color={colors.textSubtle}>✳</Text>
77
+ <View flexDirection="column" gap={0}>
78
+ {duration && <Text dimColor>({duration})</Text>}
79
+ {content && (
80
+ <Text color={colors.textSubtle} wrap="wrap">
81
+ {content}
82
+ </Text>
83
+ )}
84
+ </View>
85
+ </View>
86
+ );
87
+ });
88
+ ExpandedThinkingSegment.displayName = "ExpandedThinkingSegment";
89
+
90
+ /** Duration threshold (ms) below which we don't show timing numbers */
91
+ const THINKING_DURATION_THRESHOLD = 5000;
92
+
93
+ /** SDK-native thinking segment — emitted by thinking_delta / thinking_complete events.
94
+ * Visible while active and for 2s after completion, then hides. */
95
+ const ThinkingSegment = memo((props: HistorySegment) => {
96
+ const { isSpinny = false, thinkingStartTime, thinkingEndTime } = props;
97
+ const [currentTime, setCurrentTime] = useState(performance.now());
98
+ const [hidden, setHidden] = useState(false);
99
+
100
+ // Tick timer while actively thinking
101
+ useEffect(() => {
102
+ if (!isSpinny || !thinkingStartTime) return undefined;
103
+ const interval = setInterval(() => {
104
+ startTransition(() => setCurrentTime(performance.now()));
105
+ }, 1000);
106
+ return () => clearInterval(interval);
107
+ }, [isSpinny, thinkingStartTime]);
108
+
109
+ // After thinking completes, hide after 2s
110
+ useEffect(() => {
111
+ if (isSpinny || !thinkingEndTime) return undefined;
112
+ const timer = setTimeout(() => setHidden(true), 2000);
113
+ return () => clearTimeout(timer);
114
+ }, [isSpinny, thinkingEndTime]);
115
+
116
+ if (hidden) return null;
117
+
118
+ const label = useMemo(() => {
119
+ if (isSpinny) {
120
+ if (!thinkingStartTime) return "thinking...";
121
+ const elapsed = currentTime - thinkingStartTime;
122
+ // Only show duration if thinking has lasted >5s
123
+ return elapsed < THINKING_DURATION_THRESHOLD
124
+ ? "thinking..."
125
+ : `thinking for ${formatDurationMs(elapsed)}`;
126
+ }
127
+ if (thinkingStartTime && thinkingEndTime) {
128
+ const duration = thinkingEndTime - thinkingStartTime;
129
+ return duration < THINKING_DURATION_THRESHOLD
130
+ ? "thought"
131
+ : `thought for ${formatDurationMs(duration)}`;
132
+ }
133
+ return "thinking...";
134
+ }, [thinkingStartTime, thinkingEndTime, isSpinny, currentTime]);
135
+
136
+ return (
137
+ <View flexDirection="row" gap={1} alignItems="flex-start">
138
+ {isSpinny ? <BlinkingIndicator char="●" color="cyan" /> : <Text color="green">●</Text>}
139
+ <Text dimColor>{label}</Text>
140
+ </View>
141
+ );
142
+ });
143
+ ThinkingSegment.displayName = "ThinkingSegment";
144
+
145
+ /** SDK-native tool call segment — emitted by tool_requested / tool_execution_complete events */
146
+ const ToolCallSegment = memo((props: HistorySegment) => {
147
+ const { toolUseRequest, toolUseResult, toolDisplayData, parsedResult } = props;
148
+
149
+ if (!toolUseRequest) return null;
150
+
151
+ if (Array.isArray(toolUseRequest)) {
152
+ return (
153
+ <>
154
+ {toolUseRequest.map((req, index) => (
155
+ <Tool
156
+ key={req.id ?? index}
157
+ {...req}
158
+ result={toolUseResult}
159
+ displayData={toolDisplayData}
160
+ parsedResult={parsedResult}
161
+ />
162
+ ))}
163
+ </>
164
+ );
165
+ }
166
+
167
+ return (
168
+ <Tool
169
+ {...toolUseRequest}
170
+ result={toolUseResult}
171
+ displayData={toolDisplayData}
172
+ parsedResult={parsedResult}
173
+ />
174
+ );
175
+ });
176
+ ToolCallSegment.displayName = "ToolCallSegment";
177
+
178
+ /** Generic collapsible — used for in-flight spinners ("Processing…", "Analyzing result…") */
179
+ const CollapsibleComponentSegment = memo((props: HistorySegment) => {
180
+ const { type, segment, title, isSpinny = false } = props;
181
+ const { colors } = useTheme();
182
+ const wordRef = useRef<string>(getRandomWord());
183
+
184
+ if (type !== "collapsible_component") {
185
+ throw Error(`Can only render collapsible component segments, got ${type}`);
186
+ }
187
+
188
+ const content = useMemo(() => getSegmentContent(segment), [segment]);
189
+
190
+ if (!content && !title) {
191
+ throw Error("Collapsible component segment must have content or title");
192
+ }
193
+
194
+ const displayTitle = title || capitalize(wordRef.current);
195
+
196
+ return (
197
+ <View
198
+ borderStyle={content ? "single" : undefined}
199
+ borderColor={colors.border}
200
+ flexDirection="column"
201
+ alignItems="flex-start"
202
+ gap={1}
203
+ >
204
+ {displayTitle && (
205
+ <View flexDirection="row" alignItems="center" gap={1}>
206
+ {isSpinny ? (
207
+ <>
208
+ <Shimmer text={`${displayTitle}...`} />
209
+ <Text dimColor>(esc to interrupt)</Text>
210
+ </>
211
+ ) : (
212
+ <>
213
+ <Text> </Text>
214
+ <Text color={colors.textMuted}>{displayTitle}</Text>
215
+ </>
216
+ )}
217
+ </View>
218
+ )}
219
+ {content && <Markdown>{content}</Markdown>}
220
+ </View>
221
+ );
222
+ });
223
+ CollapsibleComponentSegment.displayName = "CollapsibleComponentSegment";
224
+
225
+ const NotificationSegment = memo((props: HistorySegment) => {
226
+ const { type, message, severity = "info", actions, flashKey } = props;
227
+ const { colors } = useTheme();
228
+
229
+ if (type !== "code_llm_notification") {
230
+ throw Error(`Can only render notification segments, got ${type}`);
231
+ }
232
+ const [isFlashing, setIsFlashing] = useState(false);
233
+ const prevFlashKeyRef = useRef(flashKey);
234
+
235
+ // Flash effect: when flashKey changes (duplicate notification), briefly highlight
236
+ useEffect(() => {
237
+ if (flashKey !== prevFlashKeyRef.current && flashKey != null) {
238
+ prevFlashKeyRef.current = flashKey;
239
+ setIsFlashing(true);
240
+ const timer = setTimeout(() => setIsFlashing(false), 600);
241
+ return () => clearTimeout(timer);
242
+ }
243
+ return undefined;
244
+ }, [flashKey]);
245
+
246
+ if (!message) {
247
+ throw Error("Notification segment must have message");
248
+ }
249
+
250
+ const validSeverity = useMemo(
251
+ () =>
252
+ severity === "info" ||
253
+ severity === "success" ||
254
+ severity === "error" ||
255
+ severity === "warning"
256
+ ? severity
257
+ : "info",
258
+ [severity],
259
+ );
260
+
261
+ const textColor = useMemo(() => {
262
+ switch (validSeverity) {
263
+ case "info":
264
+ return colors.info;
265
+ case "success":
266
+ return colors.success;
267
+ case "warning":
268
+ return colors.warning;
269
+ case "error":
270
+ return colors.error;
271
+ default:
272
+ return colors.info;
273
+ }
274
+ }, [validSeverity, colors]);
275
+
276
+ const formatActionLabel = (actionType: string): string => {
277
+ const words = actionType
278
+ .replace(/_/g, " ")
279
+ .replace(/([A-Z])/g, " $1")
280
+ .trim()
281
+ .split(" ")
282
+ .filter((word) => word.length > 0);
283
+ return words
284
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
285
+ .join(" ");
286
+ };
287
+
288
+ const actionLinks = useMemo(() => (actions || []).filter((action) => action.link), [actions]);
289
+
290
+ return (
291
+ <View flexDirection="column" gap={0}>
292
+ <View flexDirection="row" gap={1}>
293
+ <Text color={textColor}>{isFlashing ? "◉" : "●"}</Text>
294
+ <Text color={textColor} bold={isFlashing} inverse={isFlashing}>
295
+ {isFlashing ? ` ${message} ` : message}
296
+ </Text>
297
+ </View>
298
+ {actionLinks.length > 0 && (
299
+ <View marginLeft={2} flexDirection="row" gap={1}>
300
+ {actionLinks.map((action, index) => (
301
+ <Fragment key={index}>
302
+ {index > 0 && <Text> | </Text>}
303
+ <Text color="cyan" underline>
304
+ {formatActionLabel(action.type)}
305
+ </Text>
306
+ </Fragment>
307
+ ))}
308
+ </View>
309
+ )}
310
+ </View>
311
+ );
312
+ });
313
+ NotificationSegment.displayName = "NotificationSegment";
314
+
315
+ const SegmentBase = memo(({ segment }: { segment: HistorySegment }) => {
316
+ switch (segment.type) {
317
+ case "text":
318
+ return <TextSegment {...segment} />;
319
+ case "thinking":
320
+ return <ThinkingSegment {...segment} />;
321
+ case "code_llm_tool_call":
322
+ return <ToolCallSegment {...segment} />;
323
+ case "collapsible_component":
324
+ return <CollapsibleComponentSegment {...segment} />;
325
+ case "code_llm_agent_tool_request":
326
+ // History hydration produces this for older conversations — render same as tool call
327
+ return <ToolCallSegment {...segment} />;
328
+ case "code_llm_notification":
329
+ return <NotificationSegment {...segment} />;
330
+ default:
331
+ // Silently skip unknown/unsupported segment types rather than crashing
332
+ return null;
333
+ }
334
+ });
335
+ SegmentBase.displayName = "SegmentBase";
336
+
337
+ function SegmentErrorFallback(error: Error, _errorInfo: React.ErrorInfo | null) {
338
+ const errorSegment: HistorySegment = {
339
+ id: "error-fallback",
340
+ status: "completed",
341
+ source: "bot",
342
+ type: "code_llm_notification",
343
+ message: error.message,
344
+ severity: "error",
345
+ };
346
+
347
+ return <NotificationSegment {...errorSegment} />;
348
+ }
349
+
350
+ export function Segment({ segment }: { segment: HistorySegment }) {
351
+ return (
352
+ <ErrorBoundary fallback={SegmentErrorFallback}>
353
+ <SegmentBase segment={segment} />
354
+ </ErrorBoundary>
355
+ );
356
+ }
@@ -0,0 +1,306 @@
1
+ import { View, Text } from "@codellm/jar";
2
+ import { useEffect, useRef, useState } from "react";
3
+
4
+ import { useNetworkActivity } from "../context/network-activity.js";
5
+ import { formatDurationMs } from "../lib/timing.js";
6
+ import { AgentStatus, type RetryState } from "../providers/agent.js";
7
+ import { Shimmer } from "./ui/shimmer.js";
8
+
9
+ const STATUS_WORDS = [
10
+ "baking",
11
+ "beaming",
12
+ "booping",
13
+ "bouncing",
14
+ "brewing",
15
+ "bubbling",
16
+ "chasing",
17
+ "churning",
18
+ "coalescing",
19
+ "conjuring",
20
+ "cooking",
21
+ "crafting",
22
+ "crunching",
23
+ "cuddling",
24
+ "dancing",
25
+ "dazzling",
26
+ "discovering",
27
+ "doodling",
28
+ "dreaming",
29
+ "drifting",
30
+ "enchanting",
31
+ "exploring",
32
+ "finding",
33
+ "floating",
34
+ "fluttering",
35
+ "foraging",
36
+ "forging",
37
+ "frolicking",
38
+ "gathering",
39
+ "giggling",
40
+ "gliding",
41
+ "greeting",
42
+ "growing",
43
+ "hatching",
44
+ "herding",
45
+ "honking",
46
+ "hopping",
47
+ "hugging",
48
+ "humming",
49
+ "imagining",
50
+ "inventing",
51
+ "jingling",
52
+ "juggling",
53
+ "jumping",
54
+ "kindling",
55
+ "knitting",
56
+ "launching",
57
+ "leaping",
58
+ "mapping",
59
+ "marinating",
60
+ "meandering",
61
+ "mixing",
62
+ "moseying",
63
+ "munching",
64
+ "napping",
65
+ "nibbling",
66
+ "noodling",
67
+ "orbiting",
68
+ "painting",
69
+ "percolating",
70
+ "petting",
71
+ "plotting",
72
+ "pondering",
73
+ "popping",
74
+ "prancing",
75
+ "purring",
76
+ "puzzling",
77
+ "questing",
78
+ "riding",
79
+ "roaming",
80
+ "rolling",
81
+ "sauteeing",
82
+ "scribbling",
83
+ "seeking",
84
+ "shimmying",
85
+ "singing",
86
+ "skipping",
87
+ "sleeping",
88
+ "snacking",
89
+ "sniffing",
90
+ "snuggling",
91
+ "soaring",
92
+ "sparking",
93
+ "spinning",
94
+ "splashing",
95
+ "sprouting",
96
+ "squishing",
97
+ "stargazing",
98
+ "stirring",
99
+ "strolling",
100
+ "swimming",
101
+ "swinging",
102
+ "tickling",
103
+ "tinkering",
104
+ "toasting",
105
+ "tumbling",
106
+ "twirling",
107
+ "waddling",
108
+ "wandering",
109
+ "watching",
110
+ "weaving",
111
+ "whistling",
112
+ "wibbling",
113
+ "wiggling",
114
+ "wishing",
115
+ "wobbling",
116
+ "wondering",
117
+ "yawning",
118
+ "zooming",
119
+ ];
120
+
121
+ interface StatusIndicatorProps {
122
+ status: AgentStatus;
123
+ /** Start time of the most recent thinking block (ms epoch) */
124
+ thinkingStartTime?: number | null;
125
+ /** End time of the most recent thinking block (ms epoch), null if still thinking */
126
+ thinkingEndTime?: number | null;
127
+ /** Current retry state, if retrying */
128
+ retryState?: RetryState | null;
129
+ /** Whether the network is currently online */
130
+ networkOnline?: boolean;
131
+ }
132
+
133
+ function capitalize(word: string): string {
134
+ return word.charAt(0).toUpperCase() + word.slice(1);
135
+ }
136
+
137
+ function getRandomWord(): string {
138
+ const index = Math.floor(Math.random() * STATUS_WORDS.length);
139
+ return STATUS_WORDS[index];
140
+ }
141
+
142
+ /** Thinking indicator: "thinking" → "thinking for 5s" → "thought for 1.2m" (shown 5s after done) */
143
+ function useThinkingLabel(
144
+ thinkingStartTime: number | null | undefined,
145
+ thinkingEndTime: number | null | undefined,
146
+ ): string | null {
147
+ const [tick, setTick] = useState(0);
148
+ const hideAfterRef = useRef<number | null>(null);
149
+
150
+ useEffect(() => {
151
+ if (!thinkingStartTime) return;
152
+
153
+ const interval = setInterval(() => {
154
+ setTick((t) => t + 1);
155
+ }, 500);
156
+
157
+ return () => clearInterval(interval);
158
+ }, [thinkingStartTime]);
159
+
160
+ if (!thinkingStartTime) return null;
161
+
162
+ const now = Date.now();
163
+
164
+ if (thinkingEndTime) {
165
+ // After completion, show label for 5 seconds then hide
166
+ if (hideAfterRef.current === null) {
167
+ hideAfterRef.current = thinkingEndTime + 5000;
168
+ }
169
+ if (now > hideAfterRef.current) return null;
170
+ const durationMs = thinkingEndTime - thinkingStartTime;
171
+ // Only show duration if thinking lasted >5s
172
+ return durationMs < 5000 ? "thought" : `thought for ${formatDurationMs(durationMs)}`;
173
+ }
174
+
175
+ // Reset hide timer when thinking restarts
176
+ hideAfterRef.current = null;
177
+
178
+ void tick; // consumed by interval to force re-render
179
+
180
+ // Still thinking — show elapsed, only show duration if >5s
181
+ const elapsedMs = now - thinkingStartTime;
182
+ if (elapsedMs < 5000) return "thinking";
183
+ return `thinking for ${formatDurationMs(elapsedMs)}`;
184
+ }
185
+
186
+ /** Countdown hook for retry delay. Returns remaining seconds. */
187
+ function useRetryCountdown(retryState: RetryState | null): number {
188
+ const [remaining, setRemaining] = useState(0);
189
+ const startRef = useRef<number>(0);
190
+
191
+ useEffect(() => {
192
+ if (!retryState) {
193
+ setRemaining(0);
194
+ return;
195
+ }
196
+ startRef.current = Date.now();
197
+ setRemaining(Math.ceil(retryState.delayMs / 1000));
198
+
199
+ const interval = setInterval(() => {
200
+ const elapsed = Date.now() - startRef.current;
201
+ const left = Math.max(0, Math.ceil((retryState.delayMs - elapsed) / 1000));
202
+ setRemaining(left);
203
+ }, 1000);
204
+
205
+ return () => clearInterval(interval);
206
+ }, [retryState]);
207
+
208
+ return remaining;
209
+ }
210
+
211
+ export const StatusIndicator = ({
212
+ status,
213
+ thinkingStartTime,
214
+ thinkingEndTime,
215
+ retryState,
216
+ networkOnline = true,
217
+ }: StatusIndicatorProps) => {
218
+ const { activity } = useNetworkActivity();
219
+ const [word, setWord] = useState(() => getRandomWord());
220
+ const previousStatusRef = useRef<AgentStatus>(AgentStatus.Idle);
221
+ const [justReconnected, setJustReconnected] = useState(false);
222
+ const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
223
+
224
+ useEffect(() => {
225
+ if (previousStatusRef.current === AgentStatus.Idle && status !== AgentStatus.Idle) {
226
+ setWord(getRandomWord());
227
+ }
228
+ previousStatusRef.current = status;
229
+ }, [status]);
230
+
231
+ // Track "back online" flash
232
+ const prevOnlineRef = useRef(networkOnline);
233
+ useEffect(() => {
234
+ if (!prevOnlineRef.current && networkOnline) {
235
+ setJustReconnected(true);
236
+ reconnectTimerRef.current = setTimeout(() => setJustReconnected(false), 2000);
237
+ }
238
+ prevOnlineRef.current = networkOnline;
239
+ return () => {
240
+ if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current);
241
+ };
242
+ }, [networkOnline]);
243
+
244
+ const thinkingLabel = useThinkingLabel(thinkingStartTime, thinkingEndTime);
245
+ const retryCountdown = useRetryCountdown(retryState ?? null);
246
+
247
+ // ── Offline state ──
248
+ if (!networkOnline) {
249
+ return (
250
+ <View paddingLeft={1} flexDirection="row" gap={1}>
251
+ <Text color="red">⚠</Text>
252
+ <Text color="red">You are offline</Text>
253
+ <Text dimColor>— will retry when you're back online</Text>
254
+ </View>
255
+ );
256
+ }
257
+
258
+ // ── Just reconnected flash ──
259
+ if (justReconnected) {
260
+ return (
261
+ <View paddingLeft={1} flexDirection="row" gap={1}>
262
+ <Text color="green">✓</Text>
263
+ <Text color="green">Back online</Text>
264
+ </View>
265
+ );
266
+ }
267
+
268
+ // ── Retry state ──
269
+ if (retryState) {
270
+ const countdownLabel =
271
+ retryCountdown > 0
272
+ ? `(in ${retryCountdown}s)`
273
+ : `(attempt ${retryState.attempt}/${retryState.maxAttempts})`;
274
+ return (
275
+ <View paddingLeft={1} flexDirection="row" gap={1}>
276
+ <Text color="yellow">↻</Text>
277
+ <Shimmer text="Retrying..." />
278
+ <Text color="yellow">{countdownLabel}</Text>
279
+ <Text dimColor>
280
+ (attempt {retryState.attempt}/{retryState.maxAttempts} · esc to cancel)
281
+ </Text>
282
+ </View>
283
+ );
284
+ }
285
+
286
+ // ── Normal operation ──
287
+ const shouldShow = status !== AgentStatus.Idle && status !== AgentStatus.WaitingForToolPermission;
288
+
289
+ if (!shouldShow) {
290
+ return null;
291
+ }
292
+
293
+ const displayWord = status === AgentStatus.LoadingConversation ? "Resuming" : capitalize(word);
294
+ const indicator = activity === "upload" ? "↑" : activity === "download" ? "↓" : "•";
295
+
296
+ return (
297
+ <View paddingLeft={1} flexDirection="row" gap={1}>
298
+ <Text color="cyan">{indicator}</Text>
299
+ <Shimmer text={`${displayWord}...`} />
300
+ {thinkingLabel && <Text color="cyan">({thinkingLabel})</Text>}
301
+ {status !== AgentStatus.LoadingConversation && (
302
+ <Text dimColor>(esc/ctrl+c to interrupt)</Text>
303
+ )}
304
+ </View>
305
+ );
306
+ };