@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,436 @@
1
+ import { createTwoFilesPatch } from "diff"
2
+ import { createEffect, createMemo, createSignal, untrack } from "solid-js"
3
+ import { Dynamic } from "solid-js/web"
4
+ import { createStore } from "solid-js/store"
5
+ import type { TurnDiffSource, TurnDiffState } from "../context/data"
6
+ import { CurrentSessionProviders, CurrentSessionTimelineStory } from "../storybook/current-session-story"
7
+ import {
8
+ editThenTestDocument,
9
+ fileChangeLoadingDocument,
10
+ fileChangeRunningDocument,
11
+ multiFilePatchDocument,
12
+ writeFileDocument,
13
+ } from "../storybook/current-session-fixtures"
14
+ import { storyDocument, storyPatchFile, storyTool } from "../storybook/current-session-scenarios"
15
+ import type { SessionDocument } from "../document"
16
+ import { SessionTimeline } from "./session-timeline"
17
+ import { ToolDisplay } from "../tools/tool-renderer"
18
+
19
+ export default {
20
+ title: "OpenCode/Work/File changes",
21
+ id: "current-session-file-changes",
22
+ component: SessionTimeline,
23
+ parameters: {
24
+ layout: "fullscreen",
25
+ docs: {
26
+ description: {
27
+ component:
28
+ "Production file-change messages using current tool states and deterministic diff content. Loading and running states show the disclosure header; completed edits and patches render the real diff viewer.",
29
+ },
30
+ },
31
+ },
32
+ }
33
+
34
+ export const PreparingAnEdit = {
35
+ render: () => (
36
+ <CurrentSessionTimelineStory
37
+ title="Preparing an edit"
38
+ description="Tool input is still streaming, so the file change presents its loading state."
39
+ document={fileChangeLoadingDocument}
40
+ width="720px"
41
+ />
42
+ ),
43
+ }
44
+
45
+ export const ApplyingAnEdit = {
46
+ render: () => (
47
+ <CurrentSessionTimelineStory
48
+ title="Applying an edit"
49
+ description="The file is known and the edit is running, but no completed diff is available yet."
50
+ document={fileChangeRunningDocument}
51
+ width="720px"
52
+ />
53
+ ),
54
+ }
55
+
56
+ export const EditedAndVerified = {
57
+ render: () => (
58
+ <CurrentSessionTimelineStory
59
+ title="Edited and verified"
60
+ description="A completed one-file edit shows its real diff before the focused test and result."
61
+ document={editThenTestDocument}
62
+ width="860px"
63
+ editToolDefaultOpen
64
+ shellToolDefaultOpen
65
+ />
66
+ ),
67
+ }
68
+
69
+ export const PatchedTwoFiles = {
70
+ render: () => (
71
+ <CurrentSessionTimelineStory
72
+ title="Patched two files"
73
+ description="A common implementation step updates one component and adds its focused test."
74
+ document={multiFilePatchDocument}
75
+ width="860px"
76
+ editToolDefaultOpen
77
+ />
78
+ ),
79
+ }
80
+
81
+ const RepeatedEdits = {
82
+ render: () => (
83
+ <CurrentSessionTimelineStory
84
+ title="Repeated edits of one file"
85
+ description="Consecutive improvements to the same source file remain together in one expanded change."
86
+ document={storyDocument([
87
+ storyTool(
88
+ "tool_grouped_edit_first",
89
+ "edit",
90
+ "completed",
91
+ { path: "src/first.ts", oldString: "one", newString: "two" },
92
+ {
93
+ metadata: { files: [storyPatchFile("src/first.ts")] },
94
+ },
95
+ ),
96
+ storyTool(
97
+ "tool_grouped_edit_second",
98
+ "edit",
99
+ "completed",
100
+ { path: "src/first.ts", oldString: "two", newString: "three" },
101
+ {
102
+ metadata: { files: [storyPatchFile("src/first.ts")] },
103
+ },
104
+ ),
105
+ ])}
106
+ editToolDefaultOpen
107
+ />
108
+ ),
109
+ }
110
+
111
+ function EditSiblingUpdateStory() {
112
+ const [state, setState] = createStore({ sibling: false })
113
+
114
+ const document = createMemo(() => ({
115
+ ...editThenTestDocument,
116
+ status: { type: "busy" as const },
117
+ messages: editThenTestDocument.messages
118
+ .filter((message) => message.id === "msg_user_edit" || message.id === "msg_assistant_edit")
119
+ .map((message) => {
120
+ if (message.type !== "assistant") return message
121
+
122
+ return {
123
+ ...message,
124
+ time: { created: message.time.created },
125
+ content: [
126
+ ...message.content,
127
+ ...(state.sibling ? [{ type: "text" as const, text: "Streaming added a later assistant text part." }] : []),
128
+ ],
129
+ }
130
+ }),
131
+ }))
132
+
133
+ return (
134
+ <section class="mx-auto flex w-full max-w-[860px] flex-col gap-4 p-6">
135
+ <button type="button" onClick={() => setState("sibling", true)}>
136
+ Stream sibling content
137
+ </button>
138
+ <CurrentSessionProviders document={document()}>
139
+ <SessionTimeline document={document()} editToolDefaultOpen />
140
+ </CurrentSessionProviders>
141
+ </section>
142
+ )
143
+ }
144
+
145
+ const EditWithStreamedSibling = { render: () => <EditSiblingUpdateStory /> }
146
+
147
+ const ThreeFilePatch = {
148
+ render: () => {
149
+ const source = (changed: boolean) =>
150
+ Array.from({ length: 12 }, (_, index) => `export const value${index} = ${changed ? index + 1 : index}\n`).join("")
151
+
152
+ const files = [
153
+ { file: "src/a.ts", status: "modified" },
154
+ { file: "src/b.ts", status: "added" },
155
+ { file: "src/old.ts", status: "deleted" },
156
+ ].map(({ file, status }) => ({
157
+ file,
158
+ status,
159
+ patch: createTwoFilesPatch(
160
+ `a/${file}`,
161
+ `b/${file}`,
162
+ status === "added" ? "" : source(false),
163
+ status === "deleted" ? "" : source(true),
164
+ ),
165
+ additions: status === "deleted" ? 0 : 4,
166
+ deletions: status === "added" ? 0 : 3,
167
+ }))
168
+
169
+ return (
170
+ <CurrentSessionTimelineStory
171
+ title="Update, create, and remove files"
172
+ description="Each changed file can be opened and closed independently."
173
+ document={storyDocument([
174
+ storyTool(
175
+ "prt_nested_patch",
176
+ "patch",
177
+ "completed",
178
+ { patchText: "Update three files" },
179
+ { metadata: { files } },
180
+ ),
181
+ ])}
182
+ editToolDefaultOpen
183
+ />
184
+ )
185
+ },
186
+ }
187
+
188
+ const WrittenSource = {
189
+ render: () => (
190
+ <CurrentSessionTimelineStory
191
+ title="Create a source file"
192
+ description="A completed TypeScript write renders its generated source."
193
+ document={storyDocument([
194
+ storyTool("prt_file_projection_write", "write", "completed", {
195
+ path: "src/write.ts",
196
+ content: "export const written = true\n",
197
+ }),
198
+ ])}
199
+ editToolDefaultOpen
200
+ />
201
+ ),
202
+ }
203
+
204
+ // A finished turn: the step records which files changed, and the idle marker ends the turn.
205
+ function finishedTurnDocument(files: { file: string; before: string; after: string }[]): SessionDocument {
206
+ const document = storyDocument([
207
+ storyTool("tool_turn_shell", "shell", "completed", { command: "bun run format" }, { output: "Formatted" }),
208
+ ])
209
+
210
+ const step = document.messages.at(-1)
211
+
212
+ if (step?.type !== "assistant") throw new Error("Expected the story document to end with a step")
213
+
214
+ return {
215
+ ...document,
216
+ messages: [
217
+ ...document.messages.slice(0, -1),
218
+ { ...step, snapshot: { files: files.map((item) => item.file) } },
219
+ { id: "msg_turn_idle", type: "idle", outcome: "succeeded", time: { created: step.time.created + 400 } },
220
+ ],
221
+ diffs: files.map((item) => {
222
+ const lines = (text: string) => (text ? text.split("\n").length - 1 : 0)
223
+ const changes = createTwoFilesPatch(item.file, item.file, item.before, item.after)
224
+
225
+ return {
226
+ file: item.file,
227
+ patch: changes,
228
+ additions: item.before ? (item.after ? 1 : 0) : lines(item.after),
229
+ deletions: item.after ? (item.before ? 1 : 0) : lines(item.before),
230
+ status: !item.before ? "added" : !item.after ? "deleted" : "modified",
231
+ }
232
+ }),
233
+ }
234
+ }
235
+
236
+ export const TurnChangeSummary = {
237
+ render: () => (
238
+ <CurrentSessionTimelineStory
239
+ title="Turn change summary"
240
+ description="Once the turn ends, every file it changed is summarized below it, including changes made by shell commands."
241
+ document={finishedTurnDocument([
242
+ {
243
+ file: "packages/app/src/session/timeline/message-timeline.tsx",
244
+ before: "export const before = true\n",
245
+ after: "export const after = true\n",
246
+ },
247
+ { file: "packages/app/src/session/turn-summary.ts", before: "", after: "export const summary = []\n" },
248
+ { file: "packages/app/src/session/legacy-summary.ts", before: "export const legacy = []\n", after: "" },
249
+ ])}
250
+ width="860px"
251
+ turnDiffs
252
+ />
253
+ ),
254
+ }
255
+
256
+ export const TurnChangeSummaryOverflow = {
257
+ render: () => (
258
+ <CurrentSessionTimelineStory
259
+ title="Turn change summary with many files"
260
+ description="Past five files, the rest of the turn's changes wait behind Show all."
261
+ document={finishedTurnDocument(
262
+ Array.from({ length: 14 }, (_, index) => ({
263
+ file: `src/modules/module-${index + 1}.ts`,
264
+ before: `export const value = ${index}\n`,
265
+ after: `export const value = ${index + 1}\n`,
266
+ })),
267
+ )}
268
+ width="860px"
269
+ turnDiffs
270
+ />
271
+ ),
272
+ }
273
+
274
+ // The first load fails, as a dropped connection or a stalled response would, and a retry loads the diffs.
275
+ function retryableTurnDiff(document: SessionDocument): TurnDiffSource {
276
+ const [state, setState] = createSignal<TurnDiffState>({ status: "loading" })
277
+
278
+ return {
279
+ state: () => state(),
280
+ load: () => {
281
+ const current = untrack(state)
282
+
283
+ if (current.status === "loading") return setState({ status: "failed" })
284
+
285
+ if (current.status === "failed") setState({ status: "ready", diffs: document.diffs })
286
+ },
287
+ }
288
+ }
289
+
290
+ export const TurnChangeSummaryFailed = {
291
+ render: () => {
292
+ const document = finishedTurnDocument([
293
+ { file: "src/session/reconnect.ts", before: "export const delay = 1\n", after: "export const delay = 2\n" },
294
+ { file: "src/session/reconnect.test.ts", before: "", after: "test('reconnects', () => {})\n" },
295
+ ])
296
+
297
+ // Built once: Solid reads a call written in a prop again on every access.
298
+ const turnDiff = retryableTurnDiff(document)
299
+
300
+ return (
301
+ <CurrentSessionTimelineStory
302
+ title="Turn change summary that failed to load"
303
+ description="The turn's files stay listed without counts, and Retry loads them again."
304
+ document={document}
305
+ width="860px"
306
+ turnDiffs
307
+ turnDiff={turnDiff}
308
+ />
309
+ )
310
+ },
311
+ }
312
+
313
+ const fileScenarios = {
314
+ repeated: RepeatedEdits,
315
+ streaming: EditWithStreamedSibling,
316
+ patch: ThreeFilePatch,
317
+ write: WrittenSource,
318
+ }
319
+
320
+ export const AppendingToolCalls = {
321
+ args: { calls: 0 },
322
+ argTypes: { calls: { control: { type: "range", min: 0, max: 12, step: 1 } } },
323
+ render: (args: { calls: number }) => {
324
+ const [state, setState] = createStore({ calls: args.calls })
325
+ createEffect(() => setState("calls", args.calls))
326
+
327
+ const files = ["src/a.ts", "src/b.ts"].map((file) => ({
328
+ ...storyPatchFile(file),
329
+ patch: createTwoFilesPatch(file, file, "export const before = true\n", "export const after = true\n"),
330
+ }))
331
+
332
+ const document = createMemo(() =>
333
+ storyDocument([
334
+ storyTool("tool_shell_existing", "shell", "completed", { command: "printf checked" }, { output: "checked" }),
335
+ storyTool(
336
+ "tool_patch_existing",
337
+ "patch",
338
+ "completed",
339
+ { patchText: "Update two files" },
340
+ {
341
+ metadata: { files },
342
+ },
343
+ ),
344
+ ...Array.from({ length: state.calls }, (_, index) =>
345
+ storyTool(
346
+ `tool_patch_next_${index}`,
347
+ "patch",
348
+ "completed",
349
+ { patchText: "Update src/a.ts again" },
350
+ {
351
+ metadata: { files: [files[0]] },
352
+ },
353
+ ),
354
+ ),
355
+ ]),
356
+ )
357
+
358
+ return (
359
+ <section class="mx-auto flex w-full max-w-[860px] flex-col gap-4 p-6">
360
+ <button type="button" onClick={() => setState("calls", (count) => count + 1)}>
361
+ Append tool call
362
+ </button>
363
+ <CurrentSessionProviders document={document()}>
364
+ <SessionTimeline document={document()} />
365
+ </CurrentSessionProviders>
366
+ </section>
367
+ )
368
+ },
369
+ }
370
+
371
+ export const ChangingFiles = {
372
+ args: { scenario: "streaming" },
373
+ argTypes: { scenario: { control: "select", options: Object.keys(fileScenarios) } },
374
+ render: (args: { scenario: keyof typeof fileScenarios }) => (
375
+ <Dynamic component={fileScenarios[args.scenario]?.render ?? fileScenarios.streaming.render} />
376
+ ),
377
+ }
378
+
379
+ export const CreatedANewFile = {
380
+ render: () => (
381
+ <CurrentSessionTimelineStory
382
+ title="Created a new file"
383
+ description="A completed write renders the generated Markdown file through the production file viewer."
384
+ document={writeFileDocument}
385
+ width="760px"
386
+ editToolDefaultOpen
387
+ />
388
+ ),
389
+ }
390
+
391
+ export const FileToolFallbacks = {
392
+ args: { tool: "edit", empty: false, forceOpen: false, controlled: true, completed: false },
393
+ argTypes: {
394
+ tool: { control: "select", options: ["edit", "write"] },
395
+ empty: { control: "boolean" },
396
+ forceOpen: { control: "boolean" },
397
+ controlled: { control: "boolean" },
398
+ },
399
+ render: (args: { tool: string; empty: boolean; forceOpen: boolean; controlled: boolean; completed: boolean }) => {
400
+ const [state, setState] = createStore({ completed: args.completed, open: false })
401
+ createEffect(() => setState("completed", args.completed))
402
+
403
+ return (
404
+ <section class="mx-auto flex w-full max-w-[860px] flex-col gap-4 p-6">
405
+ <button type="button" onClick={() => setState("completed", true)}>
406
+ Complete file tool
407
+ </button>
408
+ <CurrentSessionProviders document={storyDocument([])}>
409
+ <ToolDisplay
410
+ id="tool_file_fallback"
411
+ tool={args.tool}
412
+ status={state.completed ? "completed" : "running"}
413
+ input={{
414
+ path: "src/example.ts",
415
+ oldString: "export const before = true\n",
416
+ newString: "export const after = true\n",
417
+ content: args.empty ? "" : "export const written = true\n",
418
+ }}
419
+ metadata={{
420
+ diagnostics: state.completed
421
+ ? {
422
+ "src/example.ts": [
423
+ { severity: 1, message: "Example diagnostic", range: { start: { line: 0, character: 0 } } },
424
+ ],
425
+ }
426
+ : {},
427
+ }}
428
+ open={args.controlled ? state.open : undefined}
429
+ onOpenChange={(open) => setState("open", open)}
430
+ forceOpen={args.forceOpen}
431
+ />
432
+ </CurrentSessionProviders>
433
+ </section>
434
+ )
435
+ },
436
+ }
@@ -0,0 +1,97 @@
1
+ import type { SessionMessageAssistantReasoning, SessionMessageAssistantTool } from "@zyro-sec/client/promise"
2
+ import { storyTool } from "../storybook/current-session-scenarios"
3
+
4
+ // Representative groups whose labels the timeline tests pin.
5
+
6
+ type Outcome = {
7
+ type: "event"
8
+ id: string
9
+ event: { verb: "finished" | "stopped"; kind: "shell"; failed: boolean; shellID: string; title: string }
10
+ }
11
+
12
+ export type GroupFixturePart =
13
+ | SessionMessageAssistantTool
14
+ | (SessionMessageAssistantReasoning & { id: string })
15
+ | Outcome
16
+
17
+ const thought = (id: string): GroupFixturePart => ({ type: "reasoning", id, text: "hmm", time: { created: 1 } })
18
+
19
+ const tool = storyTool
20
+
21
+ const shellOutcome = (id: string, shellID: string, verb: "finished" | "stopped", failed = false): Outcome => ({
22
+ type: "event",
23
+ id,
24
+ event: { verb, kind: "shell", failed, shellID, title: "sleep 5" },
25
+ })
26
+
27
+ export const labelGroups = {
28
+ "reads and searches": [
29
+ tool("r1", "read", "completed", { path: "/repo/a.ts" }),
30
+ tool("r2", "read", "completed", { path: "/repo/a.ts", offset: 10 }),
31
+ tool("r3", "read", "completed", { path: "/repo/b.ts" }),
32
+ tool("g1", "grep", "completed", { pattern: "x" }),
33
+ tool("g2", "glob", "completed", { pattern: "*.ts" }),
34
+ tool("w1", "webfetch", "completed", { url: "https://a.dev" }),
35
+ tool("w2", "websearch", "completed", { query: "q" }),
36
+ ],
37
+ "one edit": [tool("e1", "edit", "completed", { path: "/repo/a.ts", oldString: "a", newString: "b" })],
38
+ edits: [
39
+ tool("e1", "edit", "completed", { path: "/repo/a.ts", oldString: "a", newString: "b" }),
40
+ tool("e2", "write", "completed", { path: "/repo/b.ts", content: "b" }),
41
+ tool(
42
+ "e3",
43
+ "patch",
44
+ "completed",
45
+ { patchText: "" },
46
+ {
47
+ metadata: { files: [{ file: "/repo/c.ts" }, { file: "/repo/a.ts" }] },
48
+ },
49
+ ),
50
+ tool("r1", "read", "completed", { path: "/repo/d.ts" }),
51
+ ],
52
+ "shells with background outcomes": [
53
+ tool("s1", "shell", "completed", { command: "ls" }),
54
+ tool("s2", "shell", "completed", { command: "sleep 5", background: true }, { metadata: { shellID: "sh_1" } }),
55
+ tool("s3", "shell", "completed", { command: "sleep 9", background: true }, { metadata: { shellID: "sh_2" } }),
56
+ shellOutcome("n1", "sh_1", "finished"),
57
+ shellOutcome("n2", "sh_3", "stopped"),
58
+ ],
59
+ "background outcomes only": [shellOutcome("n1", "sh_1", "finished", true), shellOutcome("n2", "sh_2", "finished")],
60
+ "mixed tools": [
61
+ tool("q1", "question", "completed", { questions: [] }),
62
+ tool("x1", "browser", "completed", {}),
63
+ tool("x2", "custom_tool", "completed", {}),
64
+ tool("x3", "custom_tool", "completed", {}),
65
+ tool("s1", "shell", "completed", { command: "ls" }),
66
+ tool("r1", "read", "completed", { path: "/repo/a.ts" }),
67
+ ],
68
+ thoughts: [thought("t1"), thought("t2")],
69
+ "thoughts and tools": [thought("t1"), tool("r1", "read", "completed", { path: "/repo/a.ts" }), thought("t2")],
70
+ "failed calls": [
71
+ tool("r1", "read", "error", { path: "/repo/missing.ts" }),
72
+ tool("s1", "shell", "error", { command: "false" }),
73
+ tool("e1", "edit", "error", { path: "/repo/a.ts", oldString: "a", newString: "b" }),
74
+ ],
75
+ skills: [
76
+ tool("k1", "skill", "completed", { name: "review" }),
77
+ tool("k2", "skill", "completed", { name: "simplify" }),
78
+ ],
79
+ "v1 tool names": [
80
+ tool("b1", "bash", "completed", { command: "ls" }),
81
+ tool(
82
+ "t1",
83
+ "task",
84
+ "completed",
85
+ { description: "look", subagent_type: "explore" },
86
+ {
87
+ metadata: { sessionID: "ses_1", status: "completed" },
88
+ },
89
+ ),
90
+ tool("p1", "apply_patch", "completed", { patchText: "" }, { metadata: { files: [{ file: "/repo/z.ts" }] } }),
91
+ ],
92
+ "still running": [
93
+ tool("r1", "read", "running", { path: "/repo/a.ts" }),
94
+ tool("s1", "shell", "streaming", { command: "ls" }),
95
+ ],
96
+ empty: [],
97
+ } satisfies Record<string, GroupFixturePart[]>
@@ -0,0 +1,131 @@
1
+ import { createEffect, createMemo, createSignal } from "solid-js"
2
+ import type { SessionDocument } from "../document"
3
+ import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures"
4
+ import { CurrentSessionProviders } from "../storybook/current-session-story"
5
+ import { SessionTimeline } from "./session-timeline"
6
+
7
+ export default {
8
+ title: "OpenCode/Conversation/Mermaid diagrams",
9
+ id: "current-session-mermaid",
10
+ component: SessionTimeline,
11
+ parameters: { layout: "fullscreen" },
12
+ }
13
+
14
+ export const Diagrams = {
15
+ args: { streaming: false },
16
+ render: (args: { streaming: boolean }) => <MermaidTimeline streaming={args.streaming} />,
17
+ }
18
+
19
+ export const StateGraph = {
20
+ render: () => <StateGraphTimeline />,
21
+ }
22
+
23
+ // Wide enough that its labels are too small to read inline, which is what the maximized view is for.
24
+ const SESSION_STATES = `stateDiagram-v2
25
+ direction LR
26
+ [*] --> Idle
27
+ Idle --> Running: wake() or resume()
28
+ state Running {
29
+ direction LR
30
+ [*] --> Boundary
31
+ Boundary --> Step: next step to continue
32
+ Boundary --> Compact: context over the limit
33
+ Boundary --> Drain: inbox has queued items
34
+ Step --> Boundary: step finished
35
+ Compact --> Boundary: summary written
36
+ Drain --> Boundary: item admitted
37
+ }
38
+ Running --> Stopping: interrupt() or cancel
39
+ Stopping --> Settled: fiber exits
40
+ Running --> Settled: no step and an empty inbox
41
+ Running --> Suspended: waiting for a permission or question
42
+ Suspended --> Running: answered
43
+ Running --> Failed: unrecoverable error
44
+ Settled --> Idle: execution.ended published
45
+ Failed --> Idle: execution.ended with an error`
46
+
47
+ function StateGraphTimeline() {
48
+ const document: SessionDocument = {
49
+ sessionID: CURRENT_SESSION_ID,
50
+ status: { type: "idle" },
51
+ diffs: [],
52
+ messages: [
53
+ {
54
+ id: "msg_state_graph_user",
55
+ type: "user",
56
+ text: "Show me the state graph of a session.",
57
+ time: { created: STORY_TIME },
58
+ metadata: { agent: "build", model: STORY_MODEL },
59
+ },
60
+ {
61
+ id: "msg_state_graph_assistant",
62
+ type: "assistant",
63
+ agent: "build",
64
+ model: STORY_MODEL,
65
+ time: { created: STORY_TIME + 100, completed: STORY_TIME + 1000 },
66
+ content: [{ type: "text", text: "## State graph\n\n```mermaid\n" + SESSION_STATES + "\n```" }],
67
+ },
68
+ ],
69
+ }
70
+
71
+ return (
72
+ <section class="mx-auto flex w-full max-w-[840px] flex-col gap-4 p-6">
73
+ <CurrentSessionProviders document={document}>
74
+ <SessionTimeline document={document} />
75
+ </CurrentSessionProviders>
76
+ </section>
77
+ )
78
+ }
79
+
80
+ function MermaidTimeline(props: { streaming: boolean }) {
81
+ const [completed, setCompleted] = createSignal(!props.streaming)
82
+ createEffect(() => setCompleted(!props.streaming))
83
+
84
+ const document = createMemo(
85
+ (): SessionDocument => ({
86
+ sessionID: CURRENT_SESSION_ID,
87
+ status: { type: completed() ? "idle" : "busy" },
88
+ diffs: [],
89
+ messages: [
90
+ {
91
+ id: "msg_mermaid_user",
92
+ type: "user",
93
+ text: "Show the request flow and sequence as Mermaid diagrams.",
94
+ time: { created: STORY_TIME },
95
+ metadata: { agent: "build", model: STORY_MODEL },
96
+ },
97
+ {
98
+ id: "msg_mermaid_assistant",
99
+ type: "assistant",
100
+ agent: "build",
101
+ model: STORY_MODEL,
102
+ time: { created: STORY_TIME + 100, completed: completed() ? STORY_TIME + 1000 : undefined },
103
+ content: [
104
+ {
105
+ type: "text",
106
+ text: [
107
+ "## Request flow",
108
+ "```mermaid\nflowchart LR\n Client[Client] --> Server[Server]\n Server --> Model[Model]\n```",
109
+ "## Request sequence",
110
+ "```mermaid\nsequenceDiagram\n Client->>Server: Send prompt\n Server->>Model: Generate response\n Model-->>Client: Response\n" +
111
+ (completed() ? "```" : ""),
112
+ ].join("\n\n"),
113
+ native: completed() ? undefined : { phase: "streaming" },
114
+ },
115
+ ],
116
+ },
117
+ ],
118
+ }),
119
+ )
120
+
121
+ return (
122
+ <section class="mx-auto flex w-full max-w-[840px] flex-col gap-4 p-6">
123
+ <button type="button" onClick={() => setCompleted((value) => !value)}>
124
+ {completed() ? "Stream response" : "Complete response"}
125
+ </button>
126
+ <CurrentSessionProviders document={document()}>
127
+ <SessionTimeline document={document()} />
128
+ </CurrentSessionProviders>
129
+ </section>
130
+ )
131
+ }