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

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,238 @@
1
+ import { Data, Match, Predicate } from "effect"
2
+
3
+ export type PartRef = {
4
+ messageID: string
5
+ partID: string
6
+ }
7
+
8
+ export type PartGroup =
9
+ | {
10
+ key: string
11
+ type: "part"
12
+ ref: PartRef
13
+ }
14
+ | {
15
+ key: string
16
+ type: "context"
17
+ refs: PartRef[]
18
+ }
19
+ | {
20
+ key: string
21
+ /** A subagent row holds one call or report; events count background shells; thought holds thoughts one after another. */
22
+ type: "file" | "read" | "events" | "subagent" | "thought"
23
+ refs: PartRef[]
24
+ }
25
+
26
+ export namespace TimelineRow {
27
+ export class TurnGap extends Data.TaggedClass("TurnGap")<{
28
+ userMessageID: string
29
+ }> {}
30
+
31
+ export class UserMessage extends Data.TaggedClass("UserMessage")<{
32
+ userMessageID: string
33
+ }> {}
34
+
35
+ export class Shell extends Data.TaggedClass("Shell")<{
36
+ userMessageID: string
37
+ messageID: string
38
+ }> {}
39
+
40
+ export class Notice extends Data.TaggedClass("Notice")<{
41
+ userMessageID: string
42
+ messageID: string
43
+ }> {}
44
+
45
+ export class TurnDivider extends Data.TaggedClass("TurnDivider")<{
46
+ userMessageID: string
47
+ }> {}
48
+
49
+ export class AssistantPart extends Data.TaggedClass("AssistantPart")<{
50
+ userMessageID: string
51
+ group: PartGroup
52
+ previousAssistantPart: boolean
53
+ spacing?: "tool" | "content"
54
+ }> {}
55
+
56
+ /** The thought the model is writing, after the finished thoughts (`before`) it follows with nothing between. */
57
+ export class Thinking extends Data.TaggedClass("Thinking")<{
58
+ userMessageID: string
59
+ ref: PartRef
60
+ before?: readonly PartRef[]
61
+ }> {}
62
+
63
+ /**
64
+ * `free-limit` marks OpenCode Zen's daily free allowance running out and `go-limit` an OpenCode Go subscription's
65
+ * usage limit. `budget-limit` marks an OpenCode Console budget
66
+ * on all spend pausing paid models, and `model-budget-limit` one pausing only the models it covers. `resetAt` is when
67
+ * the allowance or budget comes back, if known.
68
+ */
69
+ export class Error extends Data.TaggedClass("Error")<{
70
+ userMessageID: string
71
+ text: string
72
+ kind?: "free-limit" | "go-limit" | "budget-limit" | "model-budget-limit"
73
+ resetAt?: number
74
+ }> {}
75
+
76
+ /** The active turn waits to retry its step: `attempt` counts tries, `next` is when the next one starts. */
77
+ export class Retry extends Data.TaggedClass("Retry")<{
78
+ userMessageID: string
79
+ attempt: number
80
+ message: string
81
+ next: number
82
+ }> {}
83
+
84
+ /** A compaction the server has admitted but not started. */
85
+ export class CompactionQueued extends Data.TaggedClass("CompactionQueued")<{
86
+ userMessageID: string
87
+ inboxID: string
88
+ }> {}
89
+
90
+ /**
91
+ * The files a finished turn changed, shown once the Session goes idle. `messageID` is the
92
+ * idle marker that ended the turn; `from` is the prompt that opened it, which names the turn
93
+ * to the session diff route even when later prompts were steered in. `files` are the paths its
94
+ * steps recorded, listed before the diff loads; the diff can omit a file a later step reverted.
95
+ */
96
+ export class TurnDiff extends Data.TaggedClass("TurnDiff")<{
97
+ userMessageID: string
98
+ messageID: string
99
+ from: string
100
+ files: readonly string[]
101
+ }> {}
102
+
103
+ /** How long a turn the user stopped worked, in the New timeline where the setting hides all the agent's activity. */
104
+ export class Worked extends Data.TaggedClass("Worked")<{
105
+ userMessageID: string
106
+ }> {}
107
+
108
+ /** Where the host shows the active turn's live status when undelivered input waits below it. */
109
+ export class Activity extends Data.TaggedClass("Activity")<{
110
+ userMessageID: string
111
+ }> {}
112
+
113
+ export type TimelineRow =
114
+ | TurnGap
115
+ | UserMessage
116
+ | Shell
117
+ | Notice
118
+ | TurnDivider
119
+ | AssistantPart
120
+ | Thinking
121
+ | Error
122
+ | Retry
123
+ | CompactionQueued
124
+ | TurnDiff
125
+ | Worked
126
+ | Activity
127
+
128
+ export const key: (row: TimelineRow) => string = Match.typeTags<TimelineRow>()({
129
+ TurnGap: (row) => `turn-gap:${row.userMessageID}`,
130
+ UserMessage: (row) => `user-message:${row.userMessageID}`,
131
+ Shell: (row) => `shell:${row.messageID}`,
132
+ Notice: (row) => `notice:${row.messageID}`,
133
+ TurnDivider: (row) => `turn-divider:${row.userMessageID}`,
134
+ // Keyed by part identity alone: a page boundary can truncate the leading turn,
135
+ // and its rows regroup under the real user message once older history loads.
136
+ // The group key already carries the owning message and part IDs.
137
+ AssistantPart: (row) => `assistant-part:${row.group.type}:${row.group.key}`,
138
+ Thinking: (row) => `thinking:${row.userMessageID}`,
139
+ Error: (row) => `error:${row.userMessageID}`,
140
+ Retry: (row) => `retry:${row.userMessageID}`,
141
+ CompactionQueued: (row) => `compaction-queued:${row.inboxID}`,
142
+ TurnDiff: (row) => `turn-diff:${row.messageID}`,
143
+ Worked: (row) => `worked:${row.userMessageID}`,
144
+ // One live status exists at a time; it keeps its identity when the active turn changes.
145
+ Activity: () => "activity",
146
+ })
147
+
148
+ // Every projection change compares each row with its previous version. Effect's structural `Equal.equals` hashes
149
+ // every nested group and ref of the new row first, which cost milliseconds per change on long sessions. A field added
150
+ // to a row needs a comparison here, or a change to only that field keeps the previous row.
151
+ const sameFields: (row: TimelineRow) => (other: TimelineRow) => boolean = Match.typeTags<TimelineRow>()({
152
+ TurnGap: () => (other: TimelineRow) => Predicate.isTagged(other, "TurnGap"),
153
+ UserMessage: () => (other: TimelineRow) => Predicate.isTagged(other, "UserMessage"),
154
+ Shell: (row) => (other: TimelineRow) => Predicate.isTagged(other, "Shell") && other.messageID === row.messageID,
155
+ Notice: (row) => (other: TimelineRow) => Predicate.isTagged(other, "Notice") && other.messageID === row.messageID,
156
+ TurnDivider: () => (other: TimelineRow) => Predicate.isTagged(other, "TurnDivider"),
157
+ AssistantPart: (row) => (other: TimelineRow) =>
158
+ Predicate.isTagged(other, "AssistantPart") &&
159
+ other.previousAssistantPart === row.previousAssistantPart &&
160
+ other.spacing === row.spacing &&
161
+ sameGroup(other.group, row.group),
162
+ Thinking: (row) => (other: TimelineRow) =>
163
+ Predicate.isTagged(other, "Thinking") &&
164
+ sameRef(other.ref, row.ref) &&
165
+ (other.before?.length ?? 0) === (row.before?.length ?? 0) &&
166
+ (row.before ?? []).every((ref, index) => sameRef(ref, other.before![index]!)),
167
+ Error: (row) => (other: TimelineRow) =>
168
+ Predicate.isTagged(other, "Error") &&
169
+ other.text === row.text &&
170
+ other.kind === row.kind &&
171
+ other.resetAt === row.resetAt,
172
+ Retry: (row) => (other: TimelineRow) =>
173
+ Predicate.isTagged(other, "Retry") &&
174
+ other.attempt === row.attempt &&
175
+ other.message === row.message &&
176
+ other.next === row.next,
177
+ CompactionQueued: (row) => (other: TimelineRow) =>
178
+ Predicate.isTagged(other, "CompactionQueued") && other.inboxID === row.inboxID,
179
+ TurnDiff: (row) => (other: TimelineRow) =>
180
+ Predicate.isTagged(other, "TurnDiff") &&
181
+ other.messageID === row.messageID &&
182
+ other.from === row.from &&
183
+ other.files.length === row.files.length &&
184
+ other.files.every((file, index) => file === row.files[index]),
185
+ Worked: () => (other: TimelineRow) => Predicate.isTagged(other, "Worked"),
186
+ Activity: () => (other: TimelineRow) => Predicate.isTagged(other, "Activity"),
187
+ })
188
+
189
+ export function equals(a: TimelineRow, b: TimelineRow) {
190
+ return a === b || (a.userMessageID === b.userMessageID && sameFields(a)(b))
191
+ }
192
+ }
193
+
194
+ function sameGroup(a: PartGroup, b: PartGroup) {
195
+ if (a.key !== b.key) return false
196
+
197
+ if (a.type === "part") return b.type === "part" && sameRef(a.ref, b.ref)
198
+
199
+ return (
200
+ b.type === a.type &&
201
+ b.refs.length === a.refs.length &&
202
+ a.refs.every((ref, index) => {
203
+ const other = b.refs[index]
204
+
205
+ return other !== undefined && sameRef(ref, other)
206
+ })
207
+ )
208
+ }
209
+
210
+ function sameRef(a: PartRef, b: PartRef) {
211
+ return a.messageID === b.messageID && a.partID === b.partID
212
+ }
213
+
214
+ export type TimelineRowMap = {
215
+ TurnGap: { userMessageID: string }
216
+ UserMessage: { userMessageID: string }
217
+ Shell: { userMessageID: string; messageID: string }
218
+ Notice: { userMessageID: string; messageID: string }
219
+ TurnDivider: { userMessageID: string }
220
+ AssistantPart: {
221
+ userMessageID: string
222
+ group: PartGroup
223
+ previousAssistantPart: boolean
224
+ spacing?: "tool" | "content"
225
+ }
226
+ Thinking: { userMessageID: string; ref: PartRef; before?: readonly PartRef[] }
227
+ Retry: { userMessageID: string; attempt: number; message: string; next: number }
228
+ Error: {
229
+ userMessageID: string
230
+ text: string
231
+ kind?: "free-limit" | "go-limit" | "budget-limit" | "model-budget-limit"
232
+ resetAt?: number
233
+ }
234
+ CompactionQueued: { userMessageID: string; inboxID: string }
235
+ TurnDiff: { userMessageID: string; messageID: string; from: string; files: readonly string[] }
236
+ Worked: { userMessageID: string }
237
+ Activity: { userMessageID: string }
238
+ }
@@ -0,0 +1,112 @@
1
+ import type { PartRef } from "./timeline-row"
2
+
3
+ export type TurnLimitKind = "free-limit" | "go-limit" | "budget-limit" | "model-budget-limit"
4
+
5
+ export type TurnErrorInfo = {
6
+ readonly text: string
7
+ readonly kind?: TurnLimitKind
8
+ readonly resetAt?: number
9
+ }
10
+
11
+ export type TurnThinkingPlacement = "separate" | "grouped" | "hidden"
12
+
13
+ /**
14
+ * Where one turn stands. `working` means the model runs, between steps too; `thinking` is working with a reasoning part
15
+ * still streaming where the reader can see it. `retrying`, `failed` and `interrupted` end the live phase even while the
16
+ * Session status has not settled yet.
17
+ */
18
+ export type TurnPhase =
19
+ | { readonly status: "idle" }
20
+ | { readonly status: "working" }
21
+ | { readonly status: "thinking"; readonly ref: PartRef; readonly placement: "separate" | "grouped" }
22
+ | { readonly status: "retrying"; readonly attempt: number; readonly message: string; readonly next: number }
23
+ | { readonly status: "failed"; readonly error: TurnErrorInfo }
24
+ | { readonly status: "interrupted" }
25
+
26
+ /** The facts of one turn in order: whether it can run, then each step it took. Notices are not steps. */
27
+ export type TurnPhaseEvent =
28
+ | { readonly type: "started"; readonly live: boolean }
29
+ | {
30
+ readonly type: "step"
31
+ readonly active: boolean
32
+ readonly session: "idle" | "busy" | "retry"
33
+ readonly completed: boolean
34
+ readonly reasoning?: { readonly ref: PartRef; readonly placement: TurnThinkingPlacement }
35
+ readonly retry?: { readonly attempt: number; readonly message: string; readonly next: number }
36
+ readonly error?: { readonly interrupted: true } | { readonly interrupted: false; readonly info: TurnErrorInfo }
37
+ }
38
+ | { readonly type: "idle.failed"; readonly error: TurnErrorInfo }
39
+
40
+ export const IDLE_TURN_PHASE: TurnPhase = Object.freeze({ status: "idle" })
41
+
42
+ export const WORKING_TURN_PHASE: TurnPhase = Object.freeze({ status: "working" })
43
+
44
+ export const INTERRUPTED_TURN_PHASE: TurnPhase = Object.freeze({ status: "interrupted" })
45
+
46
+ export function transitionTurnPhase(state: TurnPhase, event: TurnPhaseEvent): TurnPhase {
47
+ if (event.type === "started") return event.live ? WORKING_TURN_PHASE : IDLE_TURN_PHASE
48
+
49
+ if (event.type === "idle.failed") return { status: "failed", error: event.error }
50
+
51
+ if (event.active && event.retry) return { status: "retrying", ...event.retry }
52
+
53
+ if (event.error)
54
+ return event.error.interrupted ? INTERRUPTED_TURN_PHASE : { status: "failed", error: event.error.info }
55
+
56
+ if (!event.active || event.session === "idle") return IDLE_TURN_PHASE
57
+
58
+ if (event.session === "busy" && !event.completed && event.reasoning && event.reasoning.placement !== "hidden")
59
+ return state.status === "thinking" &&
60
+ state.placement === event.reasoning.placement &&
61
+ sameRef(state.ref, event.reasoning.ref)
62
+ ? state
63
+ : { status: "thinking", ref: event.reasoning.ref, placement: event.reasoning.placement }
64
+
65
+ return WORKING_TURN_PHASE
66
+ }
67
+
68
+ export function viewTurnPhase(state: TurnPhase) {
69
+ const live = state.status === "working" || state.status === "thinking"
70
+
71
+ return {
72
+ /** The model is producing this turn, so its content is still changing. */
73
+ live,
74
+ /** Settled turns keep their last text as the answer. */
75
+ settled: state.status === "idle" || state.status === "failed" || state.status === "interrupted",
76
+ /** The reply is not final yet, so it offers no Copy. */
77
+ hideCopy: live || state.status === "retrying",
78
+ separateThinkingRef: state.status === "thinking" && state.placement === "separate" ? state.ref : undefined,
79
+ streamingReasoningRef: state.status === "thinking" ? state.ref : undefined,
80
+ retry: state.status === "retrying" ? state : undefined,
81
+ error: state.status === "failed" ? state.error : undefined,
82
+ }
83
+ }
84
+
85
+ export function sameTurnPhase(a: TurnPhase, b: TurnPhase) {
86
+ if (a === b) return true
87
+
88
+ if (a.status === "thinking") return b.status === "thinking" && a.placement === b.placement && sameRef(a.ref, b.ref)
89
+
90
+ if (a.status === "retrying")
91
+ return b.status === "retrying" && a.attempt === b.attempt && a.message === b.message && a.next === b.next
92
+
93
+ if (a.status === "failed")
94
+ return (
95
+ b.status === "failed" &&
96
+ a.error.text === b.error.text &&
97
+ a.error.kind === b.error.kind &&
98
+ a.error.resetAt === b.error.resetAt
99
+ )
100
+
101
+ return a.status === b.status
102
+ }
103
+
104
+ export function isInterruptedError(error: { readonly type: string } | undefined) {
105
+ const type = error?.type.toLowerCase()
106
+
107
+ return !!type && (type.includes("abort") || type.includes("interrupt"))
108
+ }
109
+
110
+ export function sameRef(a: PartRef | undefined, b: PartRef | undefined) {
111
+ return a === b || (!!a && !!b && a.messageID === b.messageID && a.partID === b.partID)
112
+ }
@@ -0,0 +1,194 @@
1
+ import type { SessionMessageAssistant, SessionMessageInfo, SessionMessageUser } from "@zyro-sec/client/promise"
2
+ import { createMemo } from "solid-js"
3
+ import type { SessionDocument } from "../document"
4
+ import { SessionTimeline, type SessionUserPresentation } from "./session-timeline"
5
+ import { CurrentSessionProviders } from "../storybook/current-session-story"
6
+ import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures"
7
+
8
+ export default {
9
+ title: "OpenCode/Conversation/Long user messages",
10
+ id: "user-message-fold",
11
+ parameters: { layout: "fullscreen" },
12
+ args: { width: 760, turn: "thread" },
13
+ argTypes: {
14
+ width: { control: { type: "range", min: 320, max: 960, step: 10 } },
15
+ turn: { options: ["thread", "one_liner", "three_lines", "pasted", "code", "image", "voice", "short_last"] },
16
+ },
17
+ render: (args: { width: number; turn: string }) => <LongUserMessages {...args} />,
18
+ }
19
+
20
+ export const Thread = {}
21
+
22
+ function LongUserMessages(props: { width: number; turn: string }) {
23
+ const document = createMemo(() => {
24
+ if (props.turn === "thread") return thread
25
+ const prompt = `msg_fold_${props.turn}`
26
+
27
+ return {
28
+ ...thread,
29
+ messages: thread.messages.filter((message) => message.id === prompt || message.id === `${prompt}_reply`),
30
+ }
31
+ })
32
+
33
+ return (
34
+ <section
35
+ data-story="user-message-fold"
36
+ class="mx-auto w-full px-6 py-8"
37
+ style={{ "max-width": `${props.width}px` }}
38
+ >
39
+ <CurrentSessionProviders document={document()}>
40
+ <SessionTimeline document={document()} presentation={presentation} />
41
+ </CurrentSessionProviders>
42
+ </section>
43
+ )
44
+ }
45
+
46
+ let offset = 0
47
+
48
+ function user(id: string, text: string, files?: SessionMessageUser["files"]): SessionMessageUser {
49
+ offset += 60_000
50
+
51
+ return {
52
+ id,
53
+ type: "user",
54
+ text,
55
+ files,
56
+ time: { created: STORY_TIME + offset },
57
+ metadata: { agent: "build", model: STORY_MODEL },
58
+ }
59
+ }
60
+
61
+ function reply(id: string, text: string): SessionMessageAssistant {
62
+ offset += 20_000
63
+
64
+ return {
65
+ id,
66
+ type: "assistant",
67
+ agent: "build",
68
+ model: STORY_MODEL,
69
+ content: [{ type: "text", text }],
70
+ time: { created: STORY_TIME + offset, completed: STORY_TIME + offset + 9_000 },
71
+ }
72
+ }
73
+
74
+ const threeLines = [
75
+ "Can you make the sidebar remember its width?",
76
+ "It resets every time I reopen the app.",
77
+ "Keep it per project if that's easy, otherwise global is fine.",
78
+ ].join("\n")
79
+
80
+ const pastedPrompt = [
81
+ "The desktop app crashes when I restore a window with a lot of tabs. Here's what I see in the log:",
82
+ "",
83
+ "[14:02:11.204] INFO window.restore start tabs=38 workspace=opencode",
84
+ "[14:02:11.209] INFO session.hydrate ses_7f1c count=38",
85
+ "[14:02:11.311] WARN timeline.cache miss key=ses_7f1c:0 rows=0",
86
+ "[14:02:11.312] WARN timeline.cache miss key=ses_7f1c:1 rows=0",
87
+ "[14:02:11.318] INFO virtualizer.mount estimate=160 rows=412",
88
+ "[14:02:11.402] INFO virtualizer.measure batch=64",
89
+ "[14:02:11.455] INFO virtualizer.measure batch=64",
90
+ "[14:02:11.497] INFO virtualizer.measure batch=64",
91
+ "[14:02:11.533] WARN scroll.anchor lost key=row:msg_91 delta=-1840",
92
+ "[14:02:11.534] WARN scroll.anchor lost key=row:msg_92 delta=-1840",
93
+ "[14:02:11.601] ERROR Uncaught RangeError: Maximum call stack size exceeded",
94
+ " at resizeItem (virtualizer.tsx:379:11)",
95
+ " at batch (solid-js/dist/solid.js:771:12)",
96
+ " at queueMicrotask (virtualizer.tsx:374:7)",
97
+ " at pinAnchor (virtualizer.tsx:504:43)",
98
+ " at settleColdBottom (virtualizer.tsx:648:9)",
99
+ " at ResizeObserver.<anonymous> (virtualizer.tsx:688:5)",
100
+ "[14:02:11.602] ERROR renderer crashed reason=oom code=-36861",
101
+ "[14:02:11.950] INFO window.restore retry 1/3",
102
+ "[14:02:12.408] ERROR renderer crashed reason=oom code=-36861",
103
+ "[14:02:12.911] INFO window.restore retry 2/3",
104
+ "[14:02:13.377] ERROR renderer crashed reason=oom code=-36861",
105
+ "[14:02:13.380] INFO window.restore giving up, opening empty window",
106
+ "",
107
+ "Things I already tried:",
108
+ "- Clearing the timeline cache in Settings > Advanced. Same crash.",
109
+ "- Restoring with 10 tabs works. 20 works. Somewhere around 30 it falls over.",
110
+ "- It only happens when the restored session is the one that was streaming when I quit.",
111
+ "- Turning off the new virtualizer flag makes it go away, but scrolling is janky without it.",
112
+ "",
113
+ "My machine: M3 Max, 64 GB, macOS 26.1, OpenCode Beta 2.4.0-beta.18.",
114
+ "",
115
+ "I think the measure batches keep re-entering pinAnchor while the cold bottom is still settling, and each pass",
116
+ "schedules another one. But I'm not sure why only the streaming session triggers it.",
117
+ "",
118
+ "Can you find the loop, explain why the streaming session is the trigger, and fix it without turning the",
119
+ "flag off? Add a test that restores 40 tabs.",
120
+ ].join("\n")
121
+
122
+ const codeBlock = [
123
+ "This throws on an empty array and I don't see why:",
124
+ "",
125
+ "```ts",
126
+ "export function latest<T extends { time: number }>(items: T[]) {",
127
+ " return items.reduce((best, item) => {",
128
+ " if (item.time > best.time) return item",
129
+ " return best",
130
+ " })",
131
+ "}",
132
+ "",
133
+ "const sessions = await store.list({ archived: false })",
134
+ "const current = latest(sessions)",
135
+ "render(current.title)",
136
+ "```",
137
+ "",
138
+ "It works everywhere except a brand new workspace.",
139
+ "Should latest return undefined, or should the caller check first?",
140
+ ].join("\n")
141
+
142
+ const voiceDictation =
143
+ "okay so I was looking at the session list on my laptop and the thing that keeps bugging me is when I have a bunch of sessions going at once I can't tell which ones actually need me, like the ones waiting on a permission or a question look exactly the same as the ones that are just running, and then I end up clicking into each one to check, which is kind of the whole thing I wanted to stop doing, so can you add some kind of quiet marker for sessions that are blocked on me, not a big red badge or anything, just something I can scan for, and maybe sort them to the top of the project group but only if that doesn't make the list jump around while I'm looking at it, because that would be worse, and also check what the phone app does here because I think it already has something like this and it'd be nice if they matched, and if it's a bigger change than it sounds then just tell me the plan first before you build it"
144
+
145
+ const screenshot = `data:image/svg+xml;base64,${btoa(
146
+ `<svg xmlns="http://www.w3.org/2000/svg" width="640" height="400" viewBox="0 0 640 400"><rect width="640" height="400" fill="#17171a"/><rect width="180" height="400" fill="#1f1f23"/><g fill="#3a3a40"><rect x="20" y="28" width="120" height="10" rx="5"/><rect x="20" y="58" width="96" height="10" rx="5"/><rect x="20" y="88" width="132" height="10" rx="5"/><rect x="20" y="118" width="84" height="10" rx="5"/></g><rect x="216" y="40" width="300" height="14" rx="7" fill="#4a4a52"/><g fill="#2c2c32"><rect x="216" y="80" width="388" height="10" rx="5"/><rect x="216" y="102" width="360" height="10" rx="5"/><rect x="216" y="124" width="372" height="10" rx="5"/></g><rect x="384" y="170" width="220" height="64" rx="10" fill="#2a2a30"/><rect x="216" y="270" width="388" height="96" rx="12" fill="none" stroke="#e5484d" stroke-width="3"/></svg>`,
147
+ )}`
148
+
149
+ const thread = {
150
+ sessionID: CURRENT_SESSION_ID,
151
+ status: { type: "idle" },
152
+ diffs: [],
153
+ messages: [
154
+ user("msg_fold_one_liner", "Run the desktop tests again, the flaky one should be fixed now."),
155
+ reply("msg_fold_one_liner_reply", "All 214 desktop tests pass, including the window restore test that was flaky."),
156
+ user("msg_fold_three_lines", threeLines),
157
+ reply(
158
+ "msg_fold_three_lines_reply",
159
+ "The sidebar now saves its width per project and restores it on launch. A project you haven't resized uses the last width you picked anywhere.",
160
+ ),
161
+ user("msg_fold_pasted", pastedPrompt),
162
+ reply(
163
+ "msg_fold_pasted_reply",
164
+ "Found it. A restored streaming session replays its last delta after mount, which resizes the tail row while the cold bottom is still settling. Each resize re-pins the anchor, and pinning schedules another measure. I broke the loop by settling the cold bottom once per batch and added a 40-tab restore test.",
165
+ ),
166
+ user("msg_fold_code", codeBlock),
167
+ reply(
168
+ "msg_fold_code_reply",
169
+ "`reduce` with no initial value throws on an empty array. `latest` now returns `undefined` for an empty list, and its two callers show the empty state instead.",
170
+ ),
171
+ user("msg_fold_image", "The spacing under the composer looks off on this screen, see the red box.", [
172
+ {
173
+ data: screenshot.slice(screenshot.indexOf(",") + 1),
174
+ mime: "image/svg+xml",
175
+ name: "composer-spacing.svg",
176
+ source: { type: "inline" },
177
+ },
178
+ ]),
179
+ reply(
180
+ "msg_fold_image_reply",
181
+ "The dock added its own 12px margin on top of the composer's padding. I removed the dock's margin, so the gap is 8px like everywhere else.",
182
+ ),
183
+ user("msg_fold_voice", voiceDictation),
184
+ reply(
185
+ "msg_fold_voice_reply",
186
+ "Sessions waiting on you now show a small dot in the list, the same one the phone app uses. I left the order alone: moving rows while you scan felt worse, as you guessed.",
187
+ ),
188
+ user("msg_fold_short_last", "Nice. Ship it."),
189
+ ] satisfies SessionMessageInfo[],
190
+ } satisfies SessionDocument
191
+
192
+ const presentation = {
193
+ msg_fold_voice: { voice: true },
194
+ } satisfies Record<string, SessionUserPresentation>
@@ -0,0 +1,87 @@
1
+ import type { SessionMessageAssistant, SessionMessageInfo } from "@zyro-sec/client/promise"
2
+ import { Predicate } from "effect"
3
+ import type { TimelineRow } from "./timeline-row"
4
+
5
+ /** A user message's place in a run of consecutive user messages: joined to the one above, below, or both. */
6
+ export type UserRun = { above: boolean; below: boolean }
7
+
8
+ /** What a user message brings to a run: its delivery, the agent and model its meta line names, and its surfaces. */
9
+ export type UserRunMember = {
10
+ kind: "sent" | "pending"
11
+ agent: string
12
+ model: SessionMessageAssistant["model"]
13
+ /** It has a text bubble, the surface that carries a run's meta line. */
14
+ text: boolean
15
+ /** Attachments sit above its bubble. */
16
+ attachments: boolean
17
+ }
18
+
19
+ /** Layout moves in a run settle on Kit's calm spring: .4 s, bounce 0. */
20
+ export const userRunSpring = { omega: (2 * Math.PI) / 0.4, zeta: 1 }
21
+
22
+ /**
23
+ * Like the iOS app's grouped corners, consecutive user messages with nothing but turn gaps between them read as
24
+ * one block under a single meta line. Text bubbles with the same agent and model join, and steers waiting for
25
+ * delivery group the same way, but never with a sent message. An agent, model, location or compaction boundary
26
+ * between them ends the run even when the timeline hides its notice.
27
+ */
28
+ export function userMessageRuns(
29
+ rows: readonly TimelineRow.TimelineRow[],
30
+ messages: readonly SessionMessageInfo[],
31
+ member: (messageID: string) => UserRunMember | undefined,
32
+ ) {
33
+ const segments = boundarySegments(messages)
34
+ const members = rows.filter((row) => !Predicate.isTagged(row, "TurnGap"))
35
+
36
+ const joins = (above: TimelineRow.TimelineRow | undefined, below: TimelineRow.TimelineRow | undefined) => {
37
+ if (!Predicate.isTagged(above, "UserMessage") || !Predicate.isTagged(below, "UserMessage")) return false
38
+ const upper = member(above.userMessageID)
39
+ const lower = member(below.userMessageID)
40
+
41
+ return (
42
+ !!upper &&
43
+ !!lower &&
44
+ upper.kind === lower.kind &&
45
+ upper.text &&
46
+ lower.text &&
47
+ !lower.attachments &&
48
+ upper.agent === lower.agent &&
49
+ upper.model.providerID === lower.model.providerID &&
50
+ upper.model.id === lower.model.id &&
51
+ upper.model.variant === lower.model.variant &&
52
+ segments.get(above.userMessageID) === segments.get(below.userMessageID)
53
+ )
54
+ }
55
+
56
+ return new Map(
57
+ members.flatMap((row, index) =>
58
+ Predicate.isTagged(row, "UserMessage")
59
+ ? [
60
+ [
61
+ row.userMessageID,
62
+ { above: joins(members[index - 1], row), below: joins(row, members[index + 1]) } satisfies UserRun,
63
+ ] as const,
64
+ ]
65
+ : [],
66
+ ),
67
+ )
68
+ }
69
+
70
+ /** Each user message's count of agent, model, location and compaction boundaries before it. */
71
+ function boundarySegments(messages: readonly SessionMessageInfo[]) {
72
+ const segments = new Map<string, number>()
73
+ let segment = 0
74
+ messages.forEach((message) => {
75
+ if (
76
+ message.type === "agent-switched" ||
77
+ message.type === "model-switched" ||
78
+ message.type === "location-switched" ||
79
+ message.type === "compaction"
80
+ )
81
+ segment += 1
82
+
83
+ if (message.type === "user") segments.set(message.id, segment)
84
+ })
85
+
86
+ return segments
87
+ }