@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,105 @@
1
+ import { createSignal } from "solid-js"
2
+ import type { SessionDocument } from "../document"
3
+ import { MarkdownProvider } from "../context/markdown"
4
+ import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures"
5
+ import { CurrentSessionProviders } from "../storybook/current-session-story"
6
+ import { SessionTimeline } from "./session-timeline"
7
+
8
+ export default {
9
+ title: "OpenCode/Conversation/Code blocks",
10
+ id: "current-session-code-blocks",
11
+ component: SessionTimeline,
12
+ parameters: { layout: "fullscreen" },
13
+ }
14
+
15
+ const earlier = [
16
+ "The type check passes locally on Bun 1.4.4 with the default heap. CI uses the same lockfile, so the difference is",
17
+ "in how the runner starts the process rather than in the dependencies.",
18
+ ].join(" ")
19
+
20
+ const reply = [
21
+ "The runner sets `NODE_OPTIONS` before install, so the type check runs out of memory. Reproduce it with:",
22
+ "",
23
+ "```sh",
24
+ 'NODE_OPTIONS="--max-old-space-size=4096 --enable-source-maps" bun install --frozen-lockfile --filter "@zyro-sec/session-ui" && bun run --cwd packages/session-ui typecheck:tsc',
25
+ "```",
26
+ "",
27
+ "The failing line reads the setting before the override:",
28
+ "",
29
+ "```ts",
30
+ "export const resolveCodeBlockPreference = (settings: Settings, block: MarkdownCodeBlock, override?: boolean) => override ?? settings.general.wrapCodeBlocks()",
31
+ "return resolveCodeBlockPreference(settings, block)",
32
+ "```",
33
+ "",
34
+ "Then run the check again:",
35
+ "",
36
+ "```sh",
37
+ "bun typecheck",
38
+ "```",
39
+ ].join("\n")
40
+
41
+ export const LongLines = {
42
+ args: { wrap: false },
43
+ render: (args: { wrap: boolean }) => <CodeBlockTimeline wrap={args.wrap} />,
44
+ }
45
+
46
+ // The timeline scrolls inside its own pane below the setting, as it does in the app.
47
+ function CodeBlockTimeline(props: { wrap: boolean }) {
48
+ const [wrap, setWrap] = createSignal(props.wrap)
49
+
50
+ const document: SessionDocument = {
51
+ sessionID: CURRENT_SESSION_ID,
52
+ status: { type: "idle" },
53
+ diffs: [],
54
+ messages: [
55
+ {
56
+ id: "msg_code_blocks_earlier_user",
57
+ type: "user",
58
+ text: "Does the type check pass locally?",
59
+ time: { created: STORY_TIME },
60
+ metadata: { agent: "build", model: STORY_MODEL },
61
+ },
62
+ {
63
+ id: "msg_code_blocks_earlier_assistant",
64
+ type: "assistant",
65
+ agent: "build",
66
+ model: STORY_MODEL,
67
+ time: { created: STORY_TIME + 100, completed: STORY_TIME + 2000 },
68
+ content: [{ type: "text", text: earlier }],
69
+ },
70
+ {
71
+ id: "msg_code_blocks_user",
72
+ type: "user",
73
+ text: "Why does the type check fail on CI but not locally?",
74
+ time: { created: STORY_TIME + 3000 },
75
+ metadata: { agent: "build", model: STORY_MODEL },
76
+ },
77
+ {
78
+ id: "msg_code_blocks_assistant",
79
+ type: "assistant",
80
+ agent: "build",
81
+ model: STORY_MODEL,
82
+ time: { created: STORY_TIME + 3100, completed: STORY_TIME + 7000 },
83
+ content: [{ type: "text", text: reply }],
84
+ },
85
+ ],
86
+ }
87
+
88
+ return (
89
+ <div class="flex h-screen flex-col">
90
+ <label class="mx-auto flex w-full max-w-[744px] items-center gap-2 px-6 py-3 text-13-regular text-v2-text-text-muted">
91
+ <input type="checkbox" checked={wrap()} onChange={(event) => setWrap(event.currentTarget.checked)} />
92
+ Wrap code blocks
93
+ </label>
94
+ <div data-scrollable data-testid="code-blocks-scroll" class="min-h-0 flex-1 overflow-y-auto">
95
+ <section class="mx-auto w-full max-w-[744px] px-6 pb-10">
96
+ <MarkdownProvider codeWrap={wrap()}>
97
+ <CurrentSessionProviders document={document}>
98
+ <SessionTimeline document={document} />
99
+ </CurrentSessionProviders>
100
+ </MarkdownProvider>
101
+ </section>
102
+ </div>
103
+ </div>
104
+ )
105
+ }
@@ -0,0 +1,70 @@
1
+ import type { SessionMessageAssistant } from "@zyro-sec/client/promise"
2
+ import type { SessionDocument } from "../document"
3
+ import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures"
4
+ import { storyTool } from "../storybook/current-session-scenarios"
5
+ import { CurrentSessionProviders } from "../storybook/current-session-story"
6
+ import { timelinePresets, type TimelinePlacement } from "./detail"
7
+ import { SessionTimeline } from "./session-timeline"
8
+
9
+ export default {
10
+ title: "OpenCode/Conversation/Commentary",
11
+ id: "current-session-commentary",
12
+ component: SessionTimeline,
13
+ parameters: { layout: "fullscreen" },
14
+ args: { commentary: "grouped" },
15
+ argTypes: { commentary: { control: { type: "inline-radio" }, options: ["separate", "grouped", "hidden"] } },
16
+ }
17
+
18
+ const step = (id: string, offset: number, content: SessionMessageAssistant["content"]) =>
19
+ ({
20
+ id,
21
+ type: "assistant",
22
+ agent: "build",
23
+ model: STORY_MODEL,
24
+ content,
25
+ time: { created: STORY_TIME + offset, completed: STORY_TIME + offset + 900 },
26
+ }) satisfies SessionDocument["messages"][number]
27
+
28
+ const document = {
29
+ sessionID: CURRENT_SESSION_ID,
30
+ status: { type: "idle" },
31
+ diffs: [],
32
+ messages: [
33
+ {
34
+ id: "msg_commentary_user",
35
+ type: "user",
36
+ text: "The timeline setting resets after a restart. Can you fix it?",
37
+ metadata: { agent: "build", model: STORY_MODEL },
38
+ time: { created: STORY_TIME },
39
+ },
40
+ step("msg_commentary_1", 100, [
41
+ { type: "text", text: "I'll find where the timeline setting is stored." },
42
+ storyTool("commentary_grep", "grep", "completed", { pattern: "timelineDetail" }),
43
+ storyTool("commentary_read", "read", "completed", { filePath: "src/settings/model.tsx" }),
44
+ ]),
45
+ step("msg_commentary_2", 1100, [
46
+ { type: "text", text: "The stored value is missing the new category, so decoding falls back. Running the tests." },
47
+ storyTool("commentary_shell", "shell", "completed", { command: "bun test settings" }, { output: "12 pass" }),
48
+ ]),
49
+ step("msg_commentary_3", 2100, [
50
+ { type: "text", text: "Tests pass. Writing up the fix.", native: { phase: "commentary" } },
51
+ {
52
+ type: "text",
53
+ text: "Fixed. Stored settings that lack a category now take that category from the default preset, so the value survives a restart.",
54
+ },
55
+ ]),
56
+ ],
57
+ } satisfies SessionDocument
58
+
59
+ export const Placement = {
60
+ render: (args: { commentary: TimelinePlacement }) => (
61
+ <section class="mx-auto min-h-screen w-full max-w-[720px] bg-v2-background-bg-base p-6">
62
+ <CurrentSessionProviders document={document}>
63
+ <SessionTimeline
64
+ document={document}
65
+ timelineDetail={{ ...timelinePresets[2].value, commentary: { placement: args.commentary } }}
66
+ />
67
+ </CurrentSessionProviders>
68
+ </section>
69
+ ),
70
+ }
@@ -0,0 +1,38 @@
1
+ import type { SessionMessageAssistant } from "@zyro-sec/client/promise"
2
+
3
+ type Content = SessionMessageAssistant["content"][number]
4
+
5
+ // A user message starts a new turn, but wake-ups from watches, subagents and jobs add idle-bounded runs to the same turn.
6
+ export function turnCommentary(
7
+ steps: readonly { message: SessionMessageAssistant; run: number }[],
8
+ openRun: number,
9
+ settled: boolean,
10
+ visible: (content: Content) => boolean,
11
+ ) {
12
+ const runs = steps.reduce((runs, step) => {
13
+ const contents = runs.get(step.run) ?? []
14
+ contents.push(...step.message.content)
15
+
16
+ return runs.set(step.run, contents)
17
+ }, new Map<number, Content[]>())
18
+
19
+ return [...runs].flatMap(([run, contents]) => runCommentary(contents, run < openRun || settled, visible))
20
+ }
21
+
22
+ // Provider phase labels take precedence over tool order. A settled run with no answer keeps its last visible text
23
+ // so an interrupted or tool-ending run still leaves something to read.
24
+ function runCommentary(contents: Content[], settled: boolean, visible: (content: Content) => boolean) {
25
+ const lastTool = contents.findLastIndex((content) => content.type === "tool")
26
+
27
+ const commentary = contents.filter(
28
+ (content, index) =>
29
+ content.type === "text" &&
30
+ (content.native?.phase === "commentary" || (content.native?.phase !== "final_answer" && index < lastTool)),
31
+ )
32
+
33
+ const texts = contents.filter((content) => content.type === "text" && visible(content))
34
+
35
+ if (!settled || texts.some((content) => !commentary.includes(content))) return commentary
36
+
37
+ return commentary.filter((content) => content !== texts.at(-1))
38
+ }
@@ -0,0 +1,111 @@
1
+ import type { SessionMessageInfo } from "@zyro-sec/client/promise"
2
+ import { shellResultFailed } from "../message/current-tool-state"
3
+
4
+ export const timelineCategories = ["shell", "edit", "thinking", "subagents", "notices", "tools", "commentary"] as const
5
+
6
+ export type TimelineCategory = (typeof timelineCategories)[number]
7
+
8
+ export type TimelinePlacement = "separate" | "grouped" | "hidden"
9
+
10
+ export type TimelineExpansion = "collapsed" | "expanded"
11
+
12
+ export type TimelineDetail = {
13
+ shell: { placement: TimelinePlacement; details: TimelineExpansion }
14
+ edit: { placement: TimelinePlacement; details: TimelineExpansion }
15
+ thinking: { placement: TimelinePlacement; details: TimelineExpansion }
16
+ subagents: { placement: TimelinePlacement }
17
+ notices: { placement: TimelinePlacement }
18
+ tools: { placement: TimelinePlacement }
19
+ commentary: { placement: TimelinePlacement }
20
+ }
21
+
22
+ export const timelinePresets = [
23
+ {
24
+ id: "everything",
25
+ value: {
26
+ shell: { placement: "separate", details: "expanded" },
27
+ edit: { placement: "separate", details: "expanded" },
28
+ thinking: { placement: "separate", details: "expanded" },
29
+ subagents: { placement: "separate" },
30
+ notices: { placement: "separate" },
31
+ tools: { placement: "separate" },
32
+ commentary: { placement: "separate" },
33
+ },
34
+ },
35
+ {
36
+ id: "detailed",
37
+ value: {
38
+ shell: { placement: "separate", details: "expanded" },
39
+ edit: { placement: "separate", details: "expanded" },
40
+ thinking: { placement: "grouped", details: "collapsed" },
41
+ subagents: { placement: "separate" },
42
+ notices: { placement: "grouped" },
43
+ tools: { placement: "grouped" },
44
+ commentary: { placement: "separate" },
45
+ },
46
+ },
47
+ {
48
+ id: "compact",
49
+ value: {
50
+ shell: { placement: "grouped", details: "collapsed" },
51
+ edit: { placement: "grouped", details: "collapsed" },
52
+ thinking: { placement: "grouped", details: "collapsed" },
53
+ subagents: { placement: "separate" },
54
+ notices: { placement: "grouped" },
55
+ tools: { placement: "grouped" },
56
+ commentary: { placement: "separate" },
57
+ },
58
+ },
59
+ {
60
+ id: "quiet",
61
+ value: {
62
+ shell: { placement: "hidden", details: "collapsed" },
63
+ edit: { placement: "grouped", details: "collapsed" },
64
+ thinking: { placement: "hidden", details: "collapsed" },
65
+ subagents: { placement: "separate" },
66
+ notices: { placement: "hidden" },
67
+ tools: { placement: "hidden" },
68
+ commentary: { placement: "separate" },
69
+ },
70
+ },
71
+ {
72
+ id: "text-only",
73
+ value: {
74
+ shell: { placement: "hidden", details: "collapsed" },
75
+ edit: { placement: "hidden", details: "collapsed" },
76
+ thinking: { placement: "hidden", details: "collapsed" },
77
+ subagents: { placement: "hidden" },
78
+ notices: { placement: "hidden" },
79
+ tools: { placement: "hidden" },
80
+ commentary: { placement: "separate" },
81
+ },
82
+ },
83
+ ] as const satisfies readonly { id: string; value: TimelineDetail }[]
84
+
85
+ export function timelinePreset(value: TimelineDetail) {
86
+ return timelinePresets.find((preset) =>
87
+ timelineCategories.every((category) => {
88
+ const current = value[category]
89
+ const expected = preset.value[category]
90
+
91
+ return (
92
+ current.placement === expected.placement &&
93
+ (current.placement === "hidden" ||
94
+ !("details" in current) ||
95
+ ("details" in expected && current.details === expected.details))
96
+ )
97
+ }),
98
+ )
99
+ }
100
+
101
+ export function timelineNoticeRequired(message: SessionMessageInfo) {
102
+ if (message.type === "compaction") return message.status !== "completed"
103
+
104
+ if (message.type !== "synthetic") return false
105
+ const metadata = message.metadata
106
+
107
+ return (
108
+ metadata?.state === "error" ||
109
+ (metadata?.source === "shell" && metadata.state === "completed" && shellResultFailed(metadata))
110
+ )
111
+ }
@@ -0,0 +1,134 @@
1
+ import type { SessionDocument } from "../document"
2
+ import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME, thinkingDocument } from "../storybook/current-session-fixtures"
3
+ import { CurrentSessionTimelineStory } from "../storybook/current-session-story"
4
+ import { SessionTimeline } from "./session-timeline"
5
+
6
+ export default {
7
+ title: "OpenCode/Conversation/Error card",
8
+ id: "current-session-error-card",
9
+ component: SessionTimeline,
10
+ parameters: { layout: "fullscreen" },
11
+ args: { width: 480 },
12
+ argTypes: { width: { control: { type: "range", min: 320, max: 960, step: 10 } } },
13
+ }
14
+
15
+ const document = {
16
+ sessionID: CURRENT_SESSION_ID,
17
+ messages: [
18
+ ...thinkingDocument.messages,
19
+ {
20
+ id: "msg_story_error_short",
21
+ type: "assistant",
22
+ agent: "build",
23
+ model: STORY_MODEL,
24
+ content: [],
25
+ error: { type: "provider.content-filter", message: "Provider blocked the response: Request declined." },
26
+ time: { created: STORY_TIME + 33_000, completed: STORY_TIME + 34_000 },
27
+ },
28
+ { id: "msg_story_error_retry", type: "user", text: "Try again.", time: { created: STORY_TIME + 34_500 } },
29
+ {
30
+ id: "msg_story_error_long",
31
+ type: "assistant",
32
+ agent: "build",
33
+ model: STORY_MODEL,
34
+ content: [],
35
+ error: {
36
+ type: "provider.content-filter",
37
+ message:
38
+ "Provider blocked the response: This request could not be completed. Check the provider's documentation for the applicable policy, then try a different approach or model.",
39
+ },
40
+ time: { created: STORY_TIME + 35_000, completed: STORY_TIME + 36_000 },
41
+ },
42
+ ],
43
+ status: { type: "idle" },
44
+ diffs: [],
45
+ } satisfies SessionDocument
46
+
47
+ export const ProviderErrors = {
48
+ render: (args: { width: number }) => (
49
+ <CurrentSessionTimelineStory
50
+ title="Provider errors"
51
+ description="Short and wrapped provider errors in the production timeline."
52
+ document={document}
53
+ width={`${args.width}px`}
54
+ />
55
+ ),
56
+ }
57
+
58
+ const executionErrorsDocument = {
59
+ sessionID: CURRENT_SESSION_ID,
60
+ messages: [
61
+ {
62
+ id: "msg_story_exec_user_1",
63
+ type: "user",
64
+ text: "Reply with the single word ok.",
65
+ time: { created: STORY_TIME + 40_000 },
66
+ },
67
+ {
68
+ id: "msg_story_exec_idle_1",
69
+ type: "idle",
70
+ outcome: "failed",
71
+ error: { type: "provider.no-route", message: "Model unavailable: opencode/gpt-5.2" },
72
+ time: { created: STORY_TIME + 40_500 },
73
+ },
74
+ {
75
+ id: "msg_story_exec_user_2",
76
+ type: "user",
77
+ text: "Check the changed files and run lint.",
78
+ time: { created: STORY_TIME + 42_000 },
79
+ },
80
+ ...thinkingDocument.messages.slice(1),
81
+ {
82
+ id: "msg_story_exec_idle_2",
83
+ type: "idle",
84
+ outcome: "failed",
85
+ error: { type: "unknown", message: "Failed to execute statement" },
86
+ time: { created: STORY_TIME + 45_000 },
87
+ },
88
+ ],
89
+ status: { type: "idle" },
90
+ diffs: [],
91
+ } satisfies SessionDocument
92
+
93
+ export const ExecutionErrors = {
94
+ render: (args: { width: number }) => (
95
+ <CurrentSessionTimelineStory
96
+ title="Execution errors"
97
+ description="Pre-step and between-step session execution failures surfaced from the idle marker."
98
+ document={executionErrorsDocument}
99
+ width={`${args.width}px`}
100
+ />
101
+ ),
102
+ }
103
+
104
+ const linkDocument = {
105
+ sessionID: CURRENT_SESSION_ID,
106
+ messages: [
107
+ ...thinkingDocument.messages,
108
+ {
109
+ id: "msg_story_error_link",
110
+ type: "assistant",
111
+ agent: "build",
112
+ model: STORY_MODEL,
113
+ content: [],
114
+ error: {
115
+ type: "provider.transport",
116
+ message: "Could not connect to http://localhost:11434/api. Check that Ollama is running.",
117
+ },
118
+ time: { created: STORY_TIME + 33_000, completed: STORY_TIME + 34_000 },
119
+ },
120
+ ],
121
+ status: { type: "idle" },
122
+ diffs: [],
123
+ } satisfies SessionDocument
124
+
125
+ export const LinkedError = {
126
+ render: (args: { width: number }) => (
127
+ <CurrentSessionTimelineStory
128
+ title="Linked error"
129
+ description="A provider error whose message includes a URL."
130
+ document={linkDocument}
131
+ width={`${args.width}px`}
132
+ />
133
+ ),
134
+ }
@@ -0,0 +1,71 @@
1
+ import type { SessionDocument } from "../document"
2
+ import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures"
3
+ import { CurrentSessionProviders } from "../storybook/current-session-story"
4
+ import { timelinePresets } from "./detail"
5
+ import { SessionTimeline } from "./session-timeline"
6
+
7
+ export default {
8
+ title: "OpenCode/Conversation/Error spacing",
9
+ id: "current-session-error-spacing",
10
+ component: SessionTimeline,
11
+ parameters: { layout: "fullscreen" },
12
+ }
13
+
14
+ const document = {
15
+ sessionID: CURRENT_SESSION_ID,
16
+ status: { type: "idle" },
17
+ diffs: [],
18
+ messages: [
19
+ {
20
+ id: "msg_user_shell_error",
21
+ type: "user",
22
+ text: "Check the shell command and its result.",
23
+ metadata: { agent: "build", model: STORY_MODEL },
24
+ time: { created: STORY_TIME },
25
+ },
26
+ {
27
+ id: "msg_shell_error",
28
+ type: "assistant",
29
+ agent: "build",
30
+ model: STORY_MODEL,
31
+ content: [
32
+ {
33
+ type: "tool",
34
+ id: "tool_shell_error",
35
+ name: "shell",
36
+ state: {
37
+ status: "completed",
38
+ input: { command: "cd ~/Documents/Local/opencode && ls packages/tui" },
39
+ content: [{ type: "text", text: "AGENTS.md\nbunfig.toml\nnode_modules\npackage.json\nsrc" }],
40
+ metadata: {},
41
+ },
42
+ time: { created: STORY_TIME + 100, ran: STORY_TIME + 150, completed: STORY_TIME + 300 },
43
+ },
44
+ ],
45
+ error: { type: "ProviderError", message: "getaddrinfo ENOTFOUND opencode.ai" },
46
+ time: { created: STORY_TIME + 50, completed: STORY_TIME + 400 },
47
+ },
48
+ {
49
+ id: "msg_after_error_updates",
50
+ type: "system",
51
+ description: "Instructions updated: core/codemode, core/mcp-guidance",
52
+ text: "Instructions updated: core/codemode, core/mcp-guidance",
53
+ time: { created: STORY_TIME + 500 },
54
+ },
55
+ ],
56
+ } satisfies SessionDocument
57
+
58
+ export const ErrorAndUpdates = {
59
+ args: { preset: "detailed" },
60
+ argTypes: { preset: { options: timelinePresets.map((preset) => preset.id) } },
61
+ render: (args: { preset: string }) => (
62
+ <section class="mx-auto min-h-screen w-full max-w-[720px] bg-v2-background-bg-base p-6">
63
+ <CurrentSessionProviders document={document}>
64
+ <SessionTimeline
65
+ document={document}
66
+ timelineDetail={timelinePresets.find((preset) => preset.id === args.preset)!.value}
67
+ />
68
+ </CurrentSessionProviders>
69
+ </section>
70
+ ),
71
+ }