@zyro-sec/session-ui 0.0.0-stage → 1.0.4

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 (261) hide show
  1. package/AGENTS.md +25 -0
  2. package/bunfig.toml +2 -0
  3. package/component-tests/basic-tool.fixture.tsx +46 -0
  4. package/component-tests/basic-tool.spec.ts +63 -0
  5. package/component-tests/file-media.fixture.tsx +39 -0
  6. package/component-tests/file-media.spec.ts +13 -0
  7. package/component-tests/file-tool.spec.ts +62 -0
  8. package/component-tests/file-viewer.fixture.tsx +109 -0
  9. package/component-tests/file-viewer.spec.ts +134 -0
  10. package/component-tests/file.spec.ts +33 -0
  11. package/component-tests/line-comment-v2.spec.ts +15 -0
  12. package/component-tests/markdown-code-wrap.spec.ts +94 -0
  13. package/component-tests/markdown-readiness.spec.ts +95 -0
  14. package/component-tests/markdown.fixture.tsx +104 -0
  15. package/component-tests/markdown.spec.ts +1564 -0
  16. package/component-tests/mermaid-preview.spec.ts +43 -0
  17. package/component-tests/patch-group.spec.ts +79 -0
  18. package/component-tests/read-group.spec.ts +72 -0
  19. package/component-tests/read-image.fixture.tsx +66 -0
  20. package/component-tests/read-image.spec.ts +154 -0
  21. package/component-tests/session-compaction.spec.ts +254 -0
  22. package/component-tests/session-lifecycle.spec.ts +190 -0
  23. package/component-tests/session-message-projection.spec.ts +639 -0
  24. package/component-tests/session-notice-projection.spec.ts +20 -0
  25. package/component-tests/session-review-comments.spec.ts +179 -0
  26. package/component-tests/session-shell.spec.ts +93 -0
  27. package/component-tests/session-timeline-mobile.spec.ts +201 -0
  28. package/component-tests/session-timeline-notices.spec.ts +38 -0
  29. package/component-tests/session-timeline-reasoning.spec.ts +107 -0
  30. package/component-tests/session-timeline.spec.ts +157 -0
  31. package/component-tests/session-tool-projection.spec.ts +323 -0
  32. package/component-tests/text-lifecycle.fixture.tsx +26 -0
  33. package/component-tests/text-lifecycle.spec.ts +42 -0
  34. package/component-tests/timeline-subagent-rows.spec.ts +33 -0
  35. package/component-tests/tool-disclosure.spec.ts +48 -0
  36. package/component-tests/tool-group-sticky.spec.ts +37 -0
  37. package/component-tests/tool-group.spec.ts +290 -0
  38. package/component-tests/tool-status-title.fixture.tsx +22 -0
  39. package/component-tests/tool-status-title.spec.ts +30 -0
  40. package/component-tests/user-message-quotes.spec.ts +111 -0
  41. package/package.json +91 -4
  42. package/playwright.components.config.ts +4 -0
  43. package/playwright.local.config.ts +2 -0
  44. package/src/actions.ts +54 -0
  45. package/src/components/apply-patch-file.ts +122 -0
  46. package/src/components/basic-tool.css +487 -0
  47. package/src/components/basic-tool.tsx +258 -0
  48. package/src/components/copy-machine.ts +78 -0
  49. package/src/components/copy.ts +85 -0
  50. package/src/components/diagram-preview.tsx +28 -0
  51. package/src/components/disclosure-machine.ts +188 -0
  52. package/src/components/disclosure.ts +129 -0
  53. package/src/components/dock-prompt.stories.tsx +73 -0
  54. package/src/components/dock-prompt.tsx +29 -0
  55. package/src/components/file-comment-selection.tsx +146 -0
  56. package/src/components/file-media-machine.ts +165 -0
  57. package/src/components/file-media.stories.tsx +112 -0
  58. package/src/components/file-media.tsx +323 -0
  59. package/src/components/file-search.tsx +73 -0
  60. package/src/components/file.css +59 -0
  61. package/src/components/file.tsx +1300 -0
  62. package/src/components/image-preview.tsx +35 -0
  63. package/src/components/line-comment-annotations.tsx +580 -0
  64. package/src/components/line-comment-machine.ts +262 -0
  65. package/src/components/line-comment-styles.ts +293 -0
  66. package/src/components/line-comment.stories.tsx +152 -0
  67. package/src/components/line-comment.tsx +448 -0
  68. package/src/components/link-segments.ts +20 -0
  69. package/src/components/linked-text.tsx +21 -0
  70. package/src/components/markdown-cache-machine.ts +257 -0
  71. package/src/components/markdown-cache.tsx +556 -0
  72. package/src/components/markdown-clipboard.ts +101 -0
  73. package/src/components/markdown-code-machine.ts +200 -0
  74. package/src/components/markdown-code-state.ts +22 -0
  75. package/src/components/markdown-fragment-links.ts +74 -0
  76. package/src/components/markdown-github.svg +3 -0
  77. package/src/components/markdown-globe.svg +5 -0
  78. package/src/components/markdown-image-machine.ts +170 -0
  79. package/src/components/markdown-image.ts +156 -0
  80. package/src/components/markdown-inline-code-kind.ts +39 -0
  81. package/src/components/markdown-mermaid.ts +18 -0
  82. package/src/components/markdown-phase-machine.ts +102 -0
  83. package/src/components/markdown-projection.ts +13 -0
  84. package/src/components/markdown-session-links.ts +183 -0
  85. package/src/components/markdown-solid.test.tsx +92 -0
  86. package/src/components/markdown-solid.tsx +113 -0
  87. package/src/components/markdown-stream.ts +95 -0
  88. package/src/components/markdown-worker-machine.ts +516 -0
  89. package/src/components/markdown-worker-protocol.ts +73 -0
  90. package/src/components/markdown-worker.ts +250 -0
  91. package/src/components/markdown.css +672 -0
  92. package/src/components/markdown.stories.tsx +199 -0
  93. package/src/components/markdown.tsx +1612 -0
  94. package/src/components/markdown.worker.ts +188 -0
  95. package/src/components/message-file.ts +102 -0
  96. package/src/components/message-nav.css +134 -0
  97. package/src/components/message-nav.tsx +159 -0
  98. package/src/components/message-part.css +2109 -0
  99. package/src/components/message-part.tsx +3 -0
  100. package/src/components/question-prompt-experimental.css +576 -0
  101. package/src/components/question-prompt.css +527 -0
  102. package/src/components/quote-highlight.css +59 -0
  103. package/src/components/review-focus-driver.ts +142 -0
  104. package/src/components/review-focus-machine.ts +95 -0
  105. package/src/components/session-compaction.css +270 -0
  106. package/src/components/session-diff.ts +358 -0
  107. package/src/components/session-error.tsx +41 -0
  108. package/src/components/session-retry.tsx +92 -0
  109. package/src/components/session-review-machine.ts +241 -0
  110. package/src/components/session-review.css +264 -0
  111. package/src/components/session-review.stories.tsx +232 -0
  112. package/src/components/session-review.tsx +733 -0
  113. package/src/components/session-turn.css +282 -0
  114. package/src/components/shell-submessage.css +24 -0
  115. package/src/components/timeline-separator.tsx +69 -0
  116. package/src/components/tool-count-label.css +57 -0
  117. package/src/components/tool-count-label.tsx +76 -0
  118. package/src/components/tool-count-summary.css +102 -0
  119. package/src/components/tool-count-summary.stories.tsx +99 -0
  120. package/src/components/tool-count-summary.tsx +44 -0
  121. package/src/components/tool-error-card.css +178 -0
  122. package/src/components/tool-error-card.stories.tsx +113 -0
  123. package/src/components/tool-error-card.tsx +202 -0
  124. package/src/components/tool-status-title-machine.ts +128 -0
  125. package/src/components/tool-status-title.css +89 -0
  126. package/src/components/tool-status-title.tsx +163 -0
  127. package/src/context/data.tsx +107 -0
  128. package/src/context/index.ts +1 -0
  129. package/src/context/markdown.tsx +129 -0
  130. package/src/context/sources.tsx +34 -0
  131. package/src/document.ts +8 -0
  132. package/src/file-presentation.ts +34 -0
  133. package/src/message/action-machine.ts +72 -0
  134. package/src/message/agent-label.ts +3 -0
  135. package/src/message/attachment-card.css +119 -0
  136. package/src/message/attachment-card.tsx +40 -0
  137. package/src/message/attachment-media-machine.ts +213 -0
  138. package/src/message/comment-card.tsx +155 -0
  139. package/src/message/compaction-entrance-machine.ts +93 -0
  140. package/src/message/current-message.tsx +157 -0
  141. package/src/message/current-tool-state.ts +161 -0
  142. package/src/message/message-content.tsx +1391 -0
  143. package/src/message/paced-text-machine.ts +73 -0
  144. package/src/message/prompt-message.stories.tsx +149 -0
  145. package/src/message/relative-time.ts +45 -0
  146. package/src/message/user-message-quote-parts.ts +16 -0
  147. package/src/message/user-message-quotes.stories.tsx +797 -0
  148. package/src/message/user-message-quotes.tsx +135 -0
  149. package/src/pierre/comment-hover-machine.ts +53 -0
  150. package/src/pierre/comment-hover.ts +131 -0
  151. package/src/pierre/comment-selection-machine.ts +257 -0
  152. package/src/pierre/commented-lines.ts +106 -0
  153. package/src/pierre/diff-selection.ts +91 -0
  154. package/src/pierre/file-find-machine.ts +323 -0
  155. package/src/pierre/file-find.ts +537 -0
  156. package/src/pierre/file-runtime.ts +42 -0
  157. package/src/pierre/file-selection.ts +140 -0
  158. package/src/pierre/index.ts +344 -0
  159. package/src/pierre/media.ts +140 -0
  160. package/src/pierre/render-machine.ts +381 -0
  161. package/src/pierre/selection-bridge.ts +82 -0
  162. package/src/pierre/selection-machine.ts +198 -0
  163. package/src/pierre/virtualizer.ts +114 -0
  164. package/src/pierre/worker.ts +46 -0
  165. package/src/sources/experiment.ts +59 -0
  166. package/src/sources/site-icon.tsx +53 -0
  167. package/src/sources/sources-chip.tsx +57 -0
  168. package/src/sources/sources-expand-machine.ts +101 -0
  169. package/src/sources/sources-panel.tsx +249 -0
  170. package/src/sources/sources-title.tsx +21 -0
  171. package/src/sources/sources.css +266 -0
  172. package/src/sources/sources.ts +141 -0
  173. package/src/storybook/current-session-fixtures.ts +1492 -0
  174. package/src/storybook/current-session-scenarios.ts +76 -0
  175. package/src/storybook/current-session-story.tsx +154 -0
  176. package/src/storybook/index.ts +43 -0
  177. package/src/styles/index.css +19 -0
  178. package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
  179. package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
  180. package/src/timeline/code-blocks.stories.tsx +105 -0
  181. package/src/timeline/commentary.stories.tsx +70 -0
  182. package/src/timeline/commentary.ts +38 -0
  183. package/src/timeline/detail.ts +111 -0
  184. package/src/timeline/error-card.stories.tsx +134 -0
  185. package/src/timeline/error-spacing.stories.tsx +71 -0
  186. package/src/timeline/facts.ts +493 -0
  187. package/src/timeline/file-changes.stories.tsx +436 -0
  188. package/src/timeline/group-label-fixtures.ts +97 -0
  189. package/src/timeline/mermaid.stories.tsx +131 -0
  190. package/src/timeline/place.ts +280 -0
  191. package/src/timeline/placement-fixtures.ts +365 -0
  192. package/src/timeline/placement-reactivity.ts +133 -0
  193. package/src/timeline/projection.ts +1261 -0
  194. package/src/timeline/research-and-agents.stories.tsx +461 -0
  195. package/src/timeline/session-timeline-row.tsx +1675 -0
  196. package/src/timeline/session-timeline.tsx +68 -0
  197. package/src/timeline/steer-arrival-machine.ts +134 -0
  198. package/src/timeline/terminal-work.stories.tsx +464 -0
  199. package/src/timeline/timeline-row.stories.tsx +1069 -0
  200. package/src/timeline/timeline-row.ts +238 -0
  201. package/src/timeline/turn-phase-machine.ts +112 -0
  202. package/src/timeline/user-message-fold.stories.tsx +194 -0
  203. package/src/timeline/user-runs.ts +87 -0
  204. package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
  205. package/src/timeline-next/compaction.tsx +236 -0
  206. package/src/timeline-next/errors.ts +101 -0
  207. package/src/timeline-next/event-row.tsx +168 -0
  208. package/src/timeline-next/events.ts +103 -0
  209. package/src/timeline-next/index.ts +10 -0
  210. package/src/timeline-next/nested-rail.ts +125 -0
  211. package/src/timeline-next/projection.ts +1028 -0
  212. package/src/timeline-next/row.tsx +1728 -0
  213. package/src/timeline-next/rules.ts +89 -0
  214. package/src/timeline-next/separator.tsx +73 -0
  215. package/src/timeline-next/spacing.ts +127 -0
  216. package/src/timeline-next/status-line.tsx +41 -0
  217. package/src/timeline-next/status.ts +33 -0
  218. package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
  219. package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
  220. package/src/timeline-next/stories/compare.stories.tsx +486 -0
  221. package/src/timeline-next/stories/playground.stories.tsx +297 -0
  222. package/src/timeline-next/stories/session-replay.ts +1156 -0
  223. package/src/timeline-next/stories/session-timeline.tsx +50 -0
  224. package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
  225. package/src/timeline-next/timeline-next.css +649 -0
  226. package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
  227. package/src/timeline-next/tools/activity-label.ts +166 -0
  228. package/src/timeline-next/tools/assistant-content.tsx +84 -0
  229. package/src/timeline-next/tools/context-group.tsx +619 -0
  230. package/src/timeline-next/tools/error-card.tsx +147 -0
  231. package/src/timeline-next/tools/explore.tsx +119 -0
  232. package/src/timeline-next/tools/file-group.tsx +128 -0
  233. package/src/timeline-next/tools/patch.tsx +174 -0
  234. package/src/timeline-next/tools/shell.tsx +186 -0
  235. package/src/timeline-next/tools/thought.tsx +87 -0
  236. package/src/timeline-next/tools/tool-display.tsx +119 -0
  237. package/src/tools/ansi.ts +8 -0
  238. package/src/tools/context-group-label.ts +123 -0
  239. package/src/tools/file-runs.ts +35 -0
  240. package/src/tools/project-path.ts +18 -0
  241. package/src/tools/read-group.stories.tsx +159 -0
  242. package/src/tools/run-machine.ts +185 -0
  243. package/src/tools/shell-output-machine.ts +233 -0
  244. package/src/tools/shell-output.ts +91 -0
  245. package/src/tools/subagent-row-variants.stories.tsx +129 -0
  246. package/src/tools/tool-group.stories.tsx +345 -0
  247. package/src/tools/tool-renderer.tsx +2876 -0
  248. package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
  249. package/src/v2/components/session-file-panel-v2.tsx +149 -0
  250. package/src/v2/components/session-progress-indicator-v2.css +5 -0
  251. package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
  252. package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
  253. package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
  254. package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
  255. package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
  256. package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
  257. package/src/v2/components/session-review-v2.css +653 -0
  258. package/src/v2/components/session-review-v2.tsx +422 -0
  259. package/src/v2/components/sidebar-presence-machine.ts +69 -0
  260. package/tsconfig.json +20 -0
  261. package/README.md +0 -3
@@ -0,0 +1,186 @@
1
+ import type { SessionMessageShell } from "@zyro-sec/client/promise"
2
+ import { Predicate } from "effect"
3
+ import { type UiI18n, useI18n } from "@zyro-sec/ui/context/i18n"
4
+ import { Badge } from "@zyro-sec/ui/badge"
5
+ import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
6
+ import { createComputed, createEffect, createMemo, createSignal, on, onCleanup, Show, untrack } from "solid-js"
7
+ import { useData } from "../../context"
8
+ import {
9
+ createShellRunState,
10
+ shellRunProps,
11
+ transitionShellRun,
12
+ viewShellRun,
13
+ type ShellRunEvent,
14
+ } from "../../tools/run-machine"
15
+ import { createShellFollower } from "../../tools/shell-output"
16
+ import { BasicTool } from "../../components/basic-tool"
17
+ import { ConsoleOutput, ShellSubmessage, toolInput, toolMetadata, type ToolProps } from "../../tools/tool-renderer"
18
+
19
+ /**
20
+ * An agent's shell call is a row of activity, as in the current timeline: Shell, then its command, cut to the row while
21
+ * closed. Opening it shows the command and its output in full. How it ended sits at the end of the row when it did not
22
+ * succeed: the exit code, a timeout, or that it was stopped.
23
+ */
24
+ export function ShellTool(props: ToolProps) {
25
+ const i18n = useI18n()
26
+ const run = shellRun(props)
27
+ const outcome = createMemo(() => shellOutcome(props.metadata, i18n))
28
+ // The row animates the command in only when it mounted while the model was still writing it.
29
+ const animateCommand = untrack(run.state).status === "writing"
30
+
31
+ function Output() {
32
+ run.follow()
33
+
34
+ return <ConsoleOutput command={run.view().command} output={run.view().output} />
35
+ }
36
+
37
+ return (
38
+ <BasicTool
39
+ {...props}
40
+ status={run.view().basicStatus}
41
+ icon="terminal"
42
+ rail={false}
43
+ hasContent
44
+ compact
45
+ allowOpenWhilePending
46
+ trigger={(open) => (
47
+ <div data-slot="basic-tool-tool-info-structured">
48
+ <div data-slot="basic-tool-tool-info-main">
49
+ <span data-slot="basic-tool-tool-title">
50
+ <TextShimmer text={i18n.t("ui.tool.shell")} active={run.view().pending} />
51
+ </span>
52
+ <Show when={!open()}>
53
+ <Show
54
+ when={run.view().command}
55
+ fallback={
56
+ <Show when={run.view().writingPlaceholder}>
57
+ <span data-slot="basic-tool-tool-subtitle">{i18n.t("ui.tool.shell.writingCommand")}</span>
58
+ </Show>
59
+ }
60
+ >
61
+ {(command) => <ShellSubmessage text={command()} animate={animateCommand} />}
62
+ </Show>
63
+ </Show>
64
+ <Show when={outcome()}>{(value) => <Badge variant={value().tone}>{value().label}</Badge>}</Show>
65
+ </div>
66
+ </div>
67
+ )}
68
+ >
69
+ <Output />
70
+ </BasicTool>
71
+ )
72
+ }
73
+
74
+ /**
75
+ * A command the user ran shows as an agent's shell call does once opened, its command and output, without the row above
76
+ * them to open it.
77
+ */
78
+ function ShellCard(props: ToolProps) {
79
+ const i18n = useI18n()
80
+ const run = shellRun(props)
81
+
82
+ run.follow()
83
+
84
+ return (
85
+ <div data-component="shell-tool">
86
+ <Show
87
+ when={run.view().command}
88
+ fallback={
89
+ <Show when={run.view().writingPlaceholder}>
90
+ <span data-slot="shell-tool-writing">
91
+ <TextShimmer text={i18n.t("ui.tool.shell.writingCommand")} active />
92
+ </span>
93
+ </Show>
94
+ }
95
+ >
96
+ <ConsoleOutput command={run.view().command} output={run.view().output} />
97
+ </Show>
98
+ </div>
99
+ )
100
+ }
101
+
102
+ // A shell call's run: its state as the call and the shell's live output change it. `follow` streams the output of a
103
+ // command still running, for as long as the calling scope lives.
104
+ function shellRun(props: ToolProps) {
105
+ const data = useData()
106
+
107
+ const runProps = () =>
108
+ shellRunProps(
109
+ {
110
+ status: props.status,
111
+ input: toolInput(props.input),
112
+ metadata: toolMetadata(props.metadata),
113
+ output: props.output,
114
+ },
115
+ (id) => data.shellRunning?.(id) === true,
116
+ )
117
+
118
+ const [state, setState] = createSignal(createShellRunState(untrack(runProps)))
119
+
120
+ const dispatch = (event: ShellRunEvent) => {
121
+ const next = transitionShellRun(untrack(state), event)
122
+
123
+ if (next !== untrack(state)) setState(next)
124
+ }
125
+
126
+ // Synchronous, so the row never renders a pass with the previous phase.
127
+ createComputed(on(runProps, (value) => dispatch({ type: "sync", props: value }), { defer: true }))
128
+ const view = createMemo(() => viewShellRun(state()))
129
+
130
+ const follow = () => {
131
+ const followID = createMemo(() => view().follow?.id)
132
+ const followRunning = createMemo(() => view().follow?.running === true)
133
+
134
+ createEffect(() => {
135
+ const id = followID()
136
+ const load = data.shellOutput
137
+
138
+ if (id === undefined || !load) return
139
+
140
+ const follower = createShellFollower({
141
+ id,
142
+ directory: data.directory,
143
+ running: untrack(followRunning),
144
+ load,
145
+ onOutput: (output) => dispatch({ type: "output.received", shellID: id, output }),
146
+ })
147
+
148
+ createEffect(on(followRunning, (running) => follower.setRunning(running), { defer: true }))
149
+ onCleanup(follower.dispose)
150
+ })
151
+ }
152
+
153
+ return { state, view, follow }
154
+ }
155
+
156
+ // How a command ended, where it did not succeed.
157
+ function shellOutcome(metadata: ToolProps["metadata"], i18n: UiI18n) {
158
+ if (metadata.interrupted === true || metadata.status === "killed")
159
+ return { tone: "neutral" as const, label: i18n.t("ui.timeline.shell.stopped") }
160
+
161
+ if (metadata.timeout === true || metadata.status === "timeout")
162
+ return { tone: "danger" as const, label: i18n.t("ui.timeline.shell.timedOut") }
163
+
164
+ if (Predicate.isNumber(metadata.exit) && metadata.exit !== 0)
165
+ return { tone: "danger" as const, label: i18n.t("ui.timeline.shell.exit", { code: metadata.exit }) }
166
+ }
167
+
168
+ /** A command the user ran. */
169
+ export function ShellMessage(props: { message: SessionMessageShell }) {
170
+ return (
171
+ <div data-component="session-shell-message" data-timeline-part-id={props.message.id}>
172
+ <ShellCard
173
+ tool="shell"
174
+ input={{ command: props.message.command }}
175
+ metadata={{
176
+ shellID: props.message.shellID,
177
+ status: props.message.status,
178
+ exit: props.message.exit,
179
+ truncated: props.message.output?.truncated,
180
+ }}
181
+ output={props.message.output?.output}
182
+ status={props.message.status === "running" ? "running" : "completed"}
183
+ />
184
+ </div>
185
+ )
186
+ }
@@ -0,0 +1,87 @@
1
+ import type { SessionMessageAssistantReasoning } from "@zyro-sec/client/promise"
2
+ import { useI18n } from "@zyro-sec/ui/context/i18n"
3
+ import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
4
+ import { createMemo, Index, Show } from "solid-js"
5
+ import { BasicTool } from "../../components/basic-tool"
6
+ import { PacedMarkdown } from "../../message/message-content"
7
+
8
+ export type ThoughtPart = SessionMessageAssistantReasoning & { id: string; streaming?: boolean }
9
+
10
+ /**
11
+ * Thoughts one after another read like one row of activity: Thought, then how long they took together. Opening it
12
+ * shows each thought in turn.
13
+ */
14
+ export function ThoughtRow(props: {
15
+ parts: ThoughtPart[]
16
+ streaming: boolean
17
+ defaultOpen?: boolean
18
+ open?: boolean
19
+ onOpenChange?: (open: boolean) => void
20
+ onContentRendered?: () => void
21
+ }) {
22
+ const i18n = useI18n()
23
+
24
+ const duration = createMemo(() => {
25
+ const durations = props.parts.flatMap((part) =>
26
+ part.time?.completed === undefined ? [] : [Math.max(0, part.time.completed - part.time.created)],
27
+ )
28
+
29
+ if (props.parts.length === 0 || durations.length < props.parts.length) return undefined
30
+ const total = Math.round(durations.reduce((sum, duration) => sum + duration, 0) / 1000)
31
+ const numfmt = new Intl.NumberFormat(i18n.locale())
32
+
33
+ if (total < 60) return i18n.t("ui.message.duration.seconds", { count: numfmt.format(total) })
34
+
35
+ return i18n.t("ui.message.duration.minutesSeconds", {
36
+ minutes: numfmt.format(Math.floor(total / 60)),
37
+ seconds: numfmt.format(total % 60),
38
+ })
39
+ })
40
+
41
+ return (
42
+ // Each thought's body carries its own ID, so quotes and anchors resolve to that body rather than the header.
43
+ <div data-component="reasoning-part" data-timeline-part-ids={props.parts.map((part) => part.id).join(",")}>
44
+ <BasicTool
45
+ icon="mcp"
46
+ status={props.streaming ? "running" : "completed"}
47
+ compact
48
+ hasContent
49
+ allowOpenWhilePending
50
+ hideDetails={props.parts.every((part) => !part.text.trim())}
51
+ open={props.open}
52
+ defaultOpen={props.defaultOpen}
53
+ onOpenChange={(value) => {
54
+ props.onOpenChange?.(value)
55
+ props.onContentRendered?.()
56
+ }}
57
+ trigger={
58
+ <div data-component="context-tool-group-trigger">
59
+ <span data-slot="context-tool-group-title" data-activity="">
60
+ <span data-slot="context-tool-group-verb">
61
+ <TextShimmer
62
+ text={i18n.t(props.streaming ? "ui.sessionTurn.status.thinking" : "ui.message.thought")}
63
+ active={props.streaming}
64
+ />
65
+ </span>
66
+ <Show when={!props.streaming && duration()}>
67
+ {(value) => <span data-slot="context-tool-group-elapsed">{value()}</span>}
68
+ </Show>
69
+ </span>
70
+ </div>
71
+ }
72
+ >
73
+ <div data-slot="reasoning-part-run">
74
+ <Index each={props.parts}>
75
+ {(part) => (
76
+ <Show when={part().text.trim() || part().streaming}>
77
+ <div data-timeline-part-id={part().id}>
78
+ <PacedMarkdown text={part().text} cacheKey={part().id} streaming={part().streaming ?? false} />
79
+ </div>
80
+ </Show>
81
+ )}
82
+ </Index>
83
+ </div>
84
+ </BasicTool>
85
+ </div>
86
+ )
87
+ }
@@ -0,0 +1,119 @@
1
+ import { useI18n } from "@zyro-sec/ui/context/i18n"
2
+ import { createMemo, Match, Show, Switch, type Component } from "solid-js"
3
+ import { Dynamic } from "solid-js/web"
4
+ import { GenericTool } from "../../components/basic-tool"
5
+ import { useData } from "../../context"
6
+ import { stoppedShell } from "../../tools/run-machine"
7
+ import {
8
+ sessionLink,
9
+ toolDisplayError,
10
+ toolErrorSubtitle,
11
+ toolInput,
12
+ toolMetadata,
13
+ ToolRegistry,
14
+ type ToolProps,
15
+ } from "../../tools/tool-renderer"
16
+ import { ErrorCard } from "./error-card"
17
+ import { GlobTool, GrepTool, ListTool, WebFetchTool, WebSearchTool } from "./explore"
18
+ import { PatchTool } from "./patch"
19
+ import { ShellTool } from "./shell"
20
+
21
+ /** The tools the New timeline draws its own way. Every other tool draws as it does in the current timeline. */
22
+ const tools = new Map<string, Component<ToolProps>>([
23
+ ["list", ListTool],
24
+ ["glob", GlobTool],
25
+ ["grep", GrepTool],
26
+ ["webfetch", WebFetchTool],
27
+ ["websearch", WebSearchTool],
28
+ ["shell", ShellTool],
29
+ ["patch", PatchTool],
30
+ ])
31
+
32
+ /**
33
+ * One call. A call that failed shows as an error card. One the user stopped (`stopped`, from the rules) shows as one
34
+ * that ran does, a shell saying it was stopped on its row. `tool` is the tool's current name, from the rules.
35
+ */
36
+ export function ToolDisplay(props: ToolProps & { id: string; error?: string; stopped?: boolean }) {
37
+ const data = useData()
38
+ const i18n = useI18n()
39
+
40
+ if (props.tool === "todowrite") return null
41
+ const hideQuestion = () => props.tool === "question" && (props.status === "streaming" || props.status === "running")
42
+
43
+ const taskId = createMemo(() => {
44
+ if (props.tool !== "subagent") return undefined
45
+
46
+ return toolMetadata(props.metadata).sessionID || undefined
47
+ })
48
+
49
+ const taskHref = createMemo(() => sessionLink(taskId(), data.sessionHref))
50
+
51
+ const taskSubtitle = createMemo(() => {
52
+ if (props.tool !== "subagent") return undefined
53
+
54
+ return toolInput(props.input).description || taskId()
55
+ })
56
+
57
+ const errorSubtitle = createMemo(() => toolErrorSubtitle(props, i18n))
58
+ const error = createMemo(() => toolDisplayError(props))
59
+ const stopped = createMemo(() => stoppedShell({ ...props, metadata: toolMetadata(props.metadata) }))
60
+ const render = createMemo(() => tools.get(props.tool) ?? ToolRegistry.render(props.tool) ?? GenericTool)
61
+
62
+ return (
63
+ <Show when={!hideQuestion()}>
64
+ <div data-component="tool-part-wrapper" data-timeline-part-id={props.id}>
65
+ <Switch>
66
+ <Match when={stopped()}>
67
+ {(stopped) => <Dynamic component={render()} {...props} output={stopped().output} />}
68
+ </Match>
69
+ <Match when={props.stopped}>
70
+ <Dynamic
71
+ component={render()}
72
+ {...props}
73
+ error={undefined}
74
+ metadata={props.tool === "shell" ? { ...props.metadata, interrupted: true } : props.metadata}
75
+ />
76
+ </Match>
77
+ <Match when={error()}>
78
+ {(error) => {
79
+ if (props.tool === "question" && error().replace("Error: ", "").includes("dismissed this question")) {
80
+ return (
81
+ <div style="width: 100%; display: flex; justify-content: flex-end;">
82
+ <span class="text-13-regular text-v2-text-text-faint cursor-default">
83
+ {i18n.t("ui.messagePart.questions.dismissed")}
84
+ </span>
85
+ </div>
86
+ )
87
+ }
88
+
89
+ return (
90
+ <ErrorCard
91
+ tool={props.tool}
92
+ error={error()}
93
+ defaultOpen={props.defaultOpen}
94
+ open={props.open}
95
+ onOpenChange={props.onOpenChange}
96
+ subtitle={taskSubtitle() ?? errorSubtitle()}
97
+ href={taskHref()}
98
+ onSubtitleClick={(event) => {
99
+ if (!data.navigateToSession) return
100
+
101
+ if (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
102
+ const id = taskId()
103
+
104
+ if (!id) return
105
+ event.preventDefault()
106
+ data.navigateToSession(id)
107
+ }}
108
+ />
109
+ )
110
+ }}
111
+ </Match>
112
+ <Match when={true}>
113
+ <Dynamic component={render()} {...props} />
114
+ </Match>
115
+ </Switch>
116
+ </div>
117
+ </Show>
118
+ )
119
+ }
@@ -0,0 +1,8 @@
1
+ // The pattern from ansi-regex 6.3.0, the one strip-ansi 7 uses: OSC sequences ending in BEL, ESC\ or 0x9c, plus CSI
2
+ // and related escapes. An OSC payload stops at its first terminator so an unterminated `ESC ]` cannot rescan the input.
3
+ const ANSI =
4
+ /(?:\u001B\][^\u0007\u001B\u009C]*(?:\u0007|\u001B\u005C|\u009C))|[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]/g
5
+
6
+ export function stripAnsi(text: string) {
7
+ return text.replace(ANSI, "")
8
+ }
@@ -0,0 +1,123 @@
1
+ import type { UiI18n } from "@zyro-sec/ui/context/i18n"
2
+ import { factsOf, summarize, type FactPart, type Summary } from "../timeline/facts"
3
+ import type { ContextGroupPart } from "./tool-renderer"
4
+
5
+ const webSearchProviderNames = new Map([
6
+ ["tinyfish", "TinyFish"],
7
+ ["opencode", "OpenCode"],
8
+ ])
9
+
10
+ export function webSearchProviderLabel(provider: string | undefined, i18n: UiI18n) {
11
+ if (!provider) return i18n.t("ui.tool.websearch")
12
+ const name = webSearchProviderNames.get(provider) ?? `${provider[0].toUpperCase()}${provider.slice(1)}`
13
+
14
+ return i18n.t("ui.tool.websearch.provider", { provider: name })
15
+ }
16
+
17
+ // Context group labels name each tool once; detailed subtitles belong to the tool rows.
18
+ function toolTitle(tool: Summary["toolNames"][number], i18n: UiI18n) {
19
+ switch (tool.tool) {
20
+ case "read":
21
+ return i18n.t("ui.tool.read")
22
+ case "list":
23
+ return i18n.t("ui.tool.list")
24
+ case "glob":
25
+ return i18n.t("ui.tool.glob")
26
+ case "grep":
27
+ return i18n.t("ui.tool.grep")
28
+ case "browser":
29
+ return i18n.t("ui.tool.browser")
30
+ case "webfetch":
31
+ return i18n.t("ui.tool.webfetch")
32
+ case "websearch":
33
+ return webSearchProviderLabel(tool.provider, i18n)
34
+ case "subagent":
35
+ return i18n.t("ui.tool.agent.default")
36
+ case "shell":
37
+ return i18n.t("ui.tool.shell")
38
+ case "execute":
39
+ return i18n.t("ui.tool.execute")
40
+ case "edit":
41
+ return i18n.t("ui.messagePart.title.edit")
42
+ case "write":
43
+ return i18n.t("ui.messagePart.title.write")
44
+ case "patch":
45
+ return i18n.t("ui.tool.patch")
46
+ case "question":
47
+ return i18n.t("ui.tool.questions")
48
+ case "skill":
49
+ return i18n.t("ui.tool.skill")
50
+ default:
51
+ return tool.tool
52
+ }
53
+ }
54
+
55
+ /**
56
+ * A context group's parts as facts. A user's shell command counts as a call; notices and text count nothing. A script's
57
+ * files count where they are placed, so only those in the group.
58
+ */
59
+ export function contextGroupFacts(parts: readonly ContextGroupPart[]) {
60
+ return parts.flatMap((part) => {
61
+ if (part.type === "file") return [part.file]
62
+
63
+ const own: FactPart[] =
64
+ part.type === "tool" || part.type === "reasoning"
65
+ ? [part]
66
+ : part.type === "shell"
67
+ ? [{ type: "shell", id: part.id }]
68
+ : []
69
+
70
+ return factsOf(own).filter((fact) => fact.kind !== "file" || fact.via !== "script")
71
+ })
72
+ }
73
+
74
+ /** The closed label of a group of calls and thoughts: "Used 3 Read, Grep". */
75
+ export function contextGroupLabel(parts: readonly ContextGroupPart[], i18n: UiI18n) {
76
+ const facts = contextGroupFacts(parts)
77
+ const summary = summarize(facts)
78
+ const thoughts = summary.thoughts
79
+ // Rows pass calls by their part id and a script's changes by message and part id, so a change names its script by either.
80
+ const calls = new Set(facts.flatMap((fact) => (fact.kind === "call" ? [fact.id] : [])))
81
+ const shown = (by: string) => calls.has(by) || calls.has(by.slice(by.indexOf(":") + 1))
82
+
83
+ // A hidden script's changes read as the patch a direct edit shows as, one call per script, in the order they came.
84
+ const scripts = new Set(
85
+ facts.flatMap((fact) => (fact.kind === "file" && fact.via === "script" && !shown(fact.by) ? [fact.by] : [])),
86
+ )
87
+
88
+ const names = i18n.list([
89
+ ...new Set(
90
+ facts.flatMap((fact) => {
91
+ if (fact.kind === "call") return [toolTitle({ tool: fact.tool, provider: fact.provider }, i18n)]
92
+
93
+ return fact.kind === "file" && scripts.has(fact.by) ? [toolTitle({ tool: "patch" }, i18n)] : []
94
+ }),
95
+ ),
96
+ ])
97
+
98
+ if (!names && !thoughts) {
99
+ const text = i18n.t("ui.messagePart.context.updates")
100
+
101
+ return { text, title: "", before: text, count: undefined, between: "", after: "" }
102
+ }
103
+
104
+ const title = names || i18n.plural("ui.messagePart.context.thought", thoughts)
105
+ const count = summary.calls + scripts.size || thoughts
106
+ const text = i18n.plural("ui.messagePart.tools.used", count, { tools: title })
107
+ const index = text.indexOf(title)
108
+ const before = text.slice(0, index).trim()
109
+ const countText = String(count)
110
+ const countIndex = before.indexOf(countText)
111
+ const after = text.slice(index + title.length).trim()
112
+
113
+ if (countIndex === -1) return { text, title, before, count: undefined, between: "", after }
114
+
115
+ return {
116
+ text,
117
+ title,
118
+ before: before.slice(0, countIndex).trim(),
119
+ count,
120
+ between: before.slice(countIndex + countText.length).trim(),
121
+ after,
122
+ }
123
+ }
@@ -0,0 +1,35 @@
1
+ import type { SessionMessageAssistantTool } from "@zyro-sec/client/promise"
2
+ import type { FileFact } from "../timeline/facts"
3
+
4
+ /** Direct file changes and a script's changes in one file group, as runs in the order they happened. */
5
+ export type FileRun = { type: "tools"; tools: SessionMessageAssistantTool[] } | { type: "script"; files: FileFact[] }
6
+
7
+ /** Splits a file group's parts into runs: calls one after another stay one card, and each script's changes follow. */
8
+ export function fileRuns(items: readonly (SessionMessageAssistantTool | FileFact)[]) {
9
+ return items.reduce<FileRun[]>((runs, item) => {
10
+ const last = runs.at(-1)
11
+
12
+ if ("type" in item) {
13
+ if (last?.type === "tools") last.tools.push(item)
14
+ else runs.push({ type: "tools", tools: [item] })
15
+
16
+ return runs
17
+ }
18
+
19
+ if (last?.type === "script") last.files.push(item)
20
+ else runs.push({ type: "script", files: [item] })
21
+
22
+ return runs
23
+ }, [])
24
+ }
25
+
26
+ /**
27
+ * The disclosure key a run of direct calls opens its files under. The group's first run keeps the group's key, so a group
28
+ * without a script keeps its files' state; a later run is scoped by its first call, so two runs that change the same file
29
+ * open on their own.
30
+ */
31
+ export function runDisclosureKey(groupKey: string, run: readonly { id: string }[], first: { id: string } | undefined) {
32
+ const head = run[0]
33
+
34
+ return head && head.id !== first?.id ? `${groupKey}:${head.id}` : groupKey
35
+ }
@@ -0,0 +1,18 @@
1
+ import { comparablePath, containsDirectory } from "@zyro-sec/util/path"
2
+
3
+ /** `path` relative to the project `directory`, or `path` itself when it is outside the project. */
4
+ export function relativizeProjectPath(path: string, directory?: string) {
5
+ if (!path) return ""
6
+
7
+ if (!directory) return path
8
+
9
+ if (directory === "/") return path
10
+
11
+ if (directory === "\\") return path
12
+
13
+ // A Windows path names the same folder with either separator and any drive letter case, so `c:/repo/src` and
14
+ // `getDirectory`'s `C:/repo/src/` are both inside `C:\repo`.
15
+ if (!containsDirectory(directory, path)) return path
16
+
17
+ return path.slice(comparablePath(directory).replace(/\/$/, "").length).replace(/^[/\\]+/, "")
18
+ }