@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,262 @@
1
+ import type { SelectedLineRange } from "@pierre/diffs"
2
+ import { cloneSelectedLineRange } from "../pierre/selection-bridge"
3
+
4
+ /** What one file's line comments are doing. A new comment's draft and a saved comment's edit live in different variants, so one never overwrites the other. */
5
+ export type LineCommentMode =
6
+ | { readonly status: "idle" }
7
+ | { readonly status: "selecting"; readonly range: SelectedLineRange }
8
+ | { readonly status: "drafting"; readonly range: SelectedLineRange; readonly text: string }
9
+ | { readonly status: "viewing"; readonly id: string; readonly range: SelectedLineRange }
10
+ | { readonly status: "editing"; readonly id: string; readonly range: SelectedLineRange; readonly text: string }
11
+
12
+ export type LineCommentEvent =
13
+ | { readonly type: "line.selected"; readonly range: SelectedLineRange | null }
14
+ | { readonly type: "line.selection-ended"; readonly range: SelectedLineRange | null }
15
+ | { readonly type: "draft.opened"; readonly range: SelectedLineRange }
16
+ | { readonly type: "draft.changed"; readonly text: string }
17
+ | { readonly type: "draft.cancelled" }
18
+ | { readonly type: "draft.submitted"; readonly text: string; readonly send?: boolean }
19
+ | { readonly type: "comment.hovered"; readonly range: SelectedLineRange }
20
+ | { readonly type: "comment.toggled"; readonly id: string; readonly range: SelectedLineRange }
21
+ | { readonly type: "comment.focused"; readonly id: string; readonly range: SelectedLineRange }
22
+ | { readonly type: "comment.deleted"; readonly id: string }
23
+ | { readonly type: "edit.opened"; readonly id: string; readonly range: SelectedLineRange; readonly text: string }
24
+ | { readonly type: "edit.changed"; readonly text: string }
25
+ | { readonly type: "edit.cancelled" }
26
+ | { readonly type: "edit.submitted"; readonly text: string; readonly send?: boolean }
27
+ | { readonly type: "passive.cleared" }
28
+ | { readonly type: "reset" }
29
+
30
+ export type LineCommentEffect =
31
+ | { readonly type: "sync-selected"; readonly range: SelectedLineRange | null }
32
+ | {
33
+ readonly type: "submit-draft"
34
+ readonly comment: string
35
+ readonly selection: SelectedLineRange
36
+ readonly send: boolean
37
+ }
38
+ | {
39
+ readonly type: "submit-edit"
40
+ readonly id: string
41
+ readonly comment: string
42
+ readonly selection: SelectedLineRange
43
+ readonly send: boolean
44
+ }
45
+ | { readonly type: "delete-comment"; readonly id: string }
46
+
47
+ export type LineCommentTransition = {
48
+ readonly state: LineCommentMode
49
+ readonly effects: readonly LineCommentEffect[]
50
+ }
51
+
52
+ /** The modes of every file in a multi-file review. Idle files have no entry. */
53
+ export type ReviewCommentModes = Readonly<Record<string, ActiveLineCommentMode>>
54
+
55
+ type ActiveLineCommentMode = Exclude<LineCommentMode, { status: "idle" }>
56
+
57
+ export const IDLE_LINE_COMMENT_MODE: LineCommentMode = Object.freeze({ status: "idle" })
58
+
59
+ export const EMPTY_REVIEW_COMMENT_MODES: ReviewCommentModes = Object.freeze({})
60
+
61
+ const NO_EFFECTS: readonly LineCommentEffect[] = Object.freeze([])
62
+
63
+ export function transitionLineComment(state: LineCommentMode, event: LineCommentEvent): LineCommentTransition {
64
+ switch (event.type) {
65
+ case "line.selected":
66
+ if (!event.range) return clear(state)
67
+
68
+ // The viewer reports every highlight it applies, including the range this mode just handed it.
69
+ if (state.status !== "idle" && sameSelectedRange(state.range, event.range)) return stay(state)
70
+
71
+ if (state.status === "editing") return restore(state, event.range)
72
+
73
+ if (state.status === "drafting")
74
+ return enter({ status: "drafting", range: cloneSelectedLineRange(event.range), text: state.text })
75
+
76
+ return enter({ status: "selecting", range: cloneSelectedLineRange(event.range) })
77
+ case "line.selection-ended":
78
+ if (!event.range) return clear(state)
79
+
80
+ if (state.status === "editing") return restore(state, event.range)
81
+
82
+ return openDraft(state, event.range)
83
+ case "draft.opened":
84
+ return openDraft(state, event.range)
85
+ case "draft.changed":
86
+ if (state.status !== "drafting" || state.text === event.text) return stay(state)
87
+
88
+ return { state: { ...state, text: event.text }, effects: NO_EFFECTS }
89
+ case "draft.cancelled":
90
+ if (state.status !== "drafting") return stay(state)
91
+
92
+ return enter(IDLE_LINE_COMMENT_MODE)
93
+ case "draft.submitted": {
94
+ const comment = event.text.trim()
95
+
96
+ if (state.status !== "drafting" || !comment) return stay(state)
97
+
98
+ return enter(IDLE_LINE_COMMENT_MODE, {
99
+ type: "submit-draft",
100
+ comment,
101
+ selection: cloneSelectedLineRange(state.range),
102
+ send: !!event.send,
103
+ })
104
+ }
105
+
106
+ case "comment.hovered":
107
+ if (state.status !== "idle" && state.status !== "selecting") return stay(state)
108
+
109
+ if (state.status === "selecting" && sameSelectedRange(state.range, event.range)) return stay(state)
110
+
111
+ return enter({ status: "selecting", range: cloneSelectedLineRange(event.range) })
112
+ case "comment.toggled":
113
+ if (holdsText(state)) return stay(state)
114
+
115
+ if (state.status === "viewing" && state.id === event.id) return enter(IDLE_LINE_COMMENT_MODE)
116
+
117
+ return enter({ status: "viewing", id: event.id, range: cloneSelectedLineRange(event.range) })
118
+ case "comment.focused":
119
+ if (holdsText(state)) return stay(state)
120
+
121
+ if (state.status === "viewing" && state.id === event.id && sameSelectedRange(state.range, event.range))
122
+ return stay(state)
123
+
124
+ return enter({ status: "viewing", id: event.id, range: cloneSelectedLineRange(event.range) })
125
+ case "comment.deleted": {
126
+ const effect: LineCommentEffect = { type: "delete-comment", id: event.id }
127
+
128
+ if ((state.status === "viewing" || state.status === "editing") && state.id === event.id)
129
+ return enter(IDLE_LINE_COMMENT_MODE, effect)
130
+
131
+ return { state, effects: [effect] }
132
+ }
133
+
134
+ case "edit.opened":
135
+ if (holdsText(state)) return stay(state)
136
+
137
+ return enter({ status: "editing", id: event.id, range: cloneSelectedLineRange(event.range), text: event.text })
138
+ case "edit.changed":
139
+ if (state.status !== "editing" || state.text === event.text) return stay(state)
140
+
141
+ return { state: { ...state, text: event.text }, effects: NO_EFFECTS }
142
+ case "edit.cancelled":
143
+ if (state.status !== "editing") return stay(state)
144
+
145
+ return enter(IDLE_LINE_COMMENT_MODE)
146
+ case "edit.submitted": {
147
+ const comment = event.text.trim()
148
+
149
+ if (state.status !== "editing" || !comment) return stay(state)
150
+
151
+ return enter(IDLE_LINE_COMMENT_MODE, {
152
+ type: "submit-edit",
153
+ id: state.id,
154
+ comment,
155
+ selection: cloneSelectedLineRange(state.range),
156
+ send: !!event.send,
157
+ })
158
+ }
159
+
160
+ case "passive.cleared":
161
+ if (state.status !== "selecting" && state.status !== "viewing") return stay(state)
162
+
163
+ return { state: IDLE_LINE_COMMENT_MODE, effects: NO_EFFECTS }
164
+ case "reset":
165
+ if (state.status === "idle") return stay(state)
166
+
167
+ return { state: IDLE_LINE_COMMENT_MODE, effects: NO_EFFECTS }
168
+ }
169
+ }
170
+
171
+ /** Applies `event` to `file`. A file that becomes active clears passive selections in the other files and keeps their drafts and edits. */
172
+ export function transitionReviewCommentModes(modes: ReviewCommentModes, file: string, event: LineCommentEvent) {
173
+ const current = reviewFileCommentMode(modes, file)
174
+ const step = transitionLineComment(current, event)
175
+
176
+ if (step.state === current) return { modes, effects: step.effects }
177
+
178
+ const next = Object.fromEntries(
179
+ Object.entries(modes).filter(
180
+ ([other, mode]) =>
181
+ other !== file && (step.state.status === "idle" || mode.status === "drafting" || mode.status === "editing"),
182
+ ),
183
+ )
184
+
185
+ if (step.state.status !== "idle") next[file] = step.state
186
+
187
+ return {
188
+ modes: Object.keys(next).length === 0 ? EMPTY_REVIEW_COMMENT_MODES : next,
189
+ effects: step.effects,
190
+ }
191
+ }
192
+
193
+ export function viewLineComment(state: LineCommentMode) {
194
+ return {
195
+ selected: state.status === "idle" ? null : state.range,
196
+ draftRange: state.status === "drafting" ? state.range : null,
197
+ draftText: state.status === "drafting" ? state.text : "",
198
+ gutterSelected: state.status === "selecting" || state.status === "drafting" ? state.range : null,
199
+ }
200
+ }
201
+
202
+ export function viewCommentItem(state: LineCommentMode, id: string) {
203
+ const editing = state.status === "editing" && state.id === id
204
+
205
+ return {
206
+ open: editing || (state.status === "viewing" && state.id === id),
207
+ editing,
208
+ editText: editing ? state.text : "",
209
+ }
210
+ }
211
+
212
+ export function reviewFileCommentMode(modes: ReviewCommentModes, file: string): LineCommentMode {
213
+ return modes[file] ?? IDLE_LINE_COMMENT_MODE
214
+ }
215
+
216
+ function sameSelectedRange(a: SelectedLineRange, b: SelectedLineRange) {
217
+ return a.start === b.start && a.end === b.end && a.side === b.side && (a.endSide ?? a.side) === (b.endSide ?? b.side)
218
+ }
219
+
220
+ function openDraft(state: LineCommentMode, range: SelectedLineRange): LineCommentTransition {
221
+ if (state.status === "editing") return stay(state)
222
+
223
+ if (state.status !== "drafting") return enter({ status: "drafting", range: cloneSelectedLineRange(range), text: "" })
224
+
225
+ if (sameSelectedRange(state.range, range)) return stay(state)
226
+
227
+ return enter({ status: "drafting", range: cloneSelectedLineRange(range), text: state.text })
228
+ }
229
+
230
+ function clear(state: LineCommentMode): LineCommentTransition {
231
+ if (state.status === "idle") return stay(state)
232
+
233
+ if (holdsText(state)) return restore(state, null)
234
+
235
+ return enter(IDLE_LINE_COMMENT_MODE)
236
+ }
237
+
238
+ // The viewer highlights a clicked range before the machine sees it. When typed text keeps its range, a fresh copy of
239
+ // that range makes the `selectedLines` prop change, so the viewer highlights the held lines again.
240
+ function restore(state: ActiveLineCommentMode, range: SelectedLineRange | null): LineCommentTransition {
241
+ if (range && sameSelectedRange(state.range, range)) return stay(state)
242
+
243
+ return enter({ ...state, range: cloneSelectedLineRange(state.range) })
244
+ }
245
+
246
+ // Typed draft text and an open edit are never discarded by a selection, click or focus elsewhere in the file.
247
+ function holdsText(state: LineCommentMode) {
248
+ if (state.status === "editing") return true
249
+
250
+ return state.status === "drafting" && state.text.trim().length > 0
251
+ }
252
+
253
+ function enter(state: LineCommentMode, ...effects: LineCommentEffect[]): LineCommentTransition {
254
+ return {
255
+ state,
256
+ effects: [{ type: "sync-selected", range: state.status === "idle" ? null : state.range }, ...effects],
257
+ }
258
+ }
259
+
260
+ function stay(state: LineCommentMode): LineCommentTransition {
261
+ return { state, effects: NO_EFFECTS }
262
+ }
@@ -0,0 +1,293 @@
1
+ export const lineCommentStyles = `
2
+ [data-annotation-slot] {
3
+ padding: 12px;
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ [data-component="line-comment"] {
8
+ position: absolute;
9
+ right: 24px;
10
+ z-index: var(--line-comment-z, 30);
11
+ }
12
+
13
+ [data-component="line-comment"][data-inline] {
14
+ position: relative;
15
+ right: auto;
16
+ display: flex;
17
+ width: 100%;
18
+ min-width: 0;
19
+ align-items: flex-start;
20
+ }
21
+
22
+ [data-component="line-comment"][data-open] {
23
+ z-index: var(--line-comment-open-z, 100);
24
+ }
25
+
26
+ [data-component="line-comment"] [data-slot="line-comment-button"] {
27
+ width: 20px;
28
+ height: 20px;
29
+ border-radius: var(--radius-md);
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ background: var(--icon-interactive-base);
34
+ box-shadow: var(--shadow-xs);
35
+ cursor: default;
36
+ border: none;
37
+ }
38
+
39
+ [data-component="line-comment"] [data-slot="icon-svg"] {
40
+ color: var(--white);
41
+ }
42
+
43
+ [data-component="line-comment"] [data-slot="line-comment-icon"] {
44
+ width: 12px;
45
+ height: 12px;
46
+ color: var(--white);
47
+ }
48
+
49
+ [data-component="line-comment"] [data-slot="line-comment-button"]:focus {
50
+ outline: none;
51
+ }
52
+
53
+ [data-component="line-comment"] [data-slot="line-comment-button"]:focus-visible {
54
+ box-shadow: var(--shadow-xs-border-focus);
55
+ }
56
+
57
+ [data-component="line-comment"] [data-slot="line-comment-popover"] {
58
+ position: absolute;
59
+ top: calc(100% + 4px);
60
+ right: -8px;
61
+ z-index: var(--line-comment-popover-z, 40);
62
+ min-width: 200px;
63
+ max-width: none;
64
+ box-sizing: border-box;
65
+ border-radius: 8px;
66
+ background: var(--surface-raised-stronger-non-alpha);
67
+ box-shadow: var(--shadow-xxs-border);
68
+ padding: 12px;
69
+ }
70
+
71
+ [data-component="line-comment"][data-inline] [data-slot="line-comment-popover"] {
72
+ position: relative;
73
+ top: auto;
74
+ right: auto;
75
+ margin-left: 8px;
76
+ flex: 1 1 0%;
77
+ width: auto;
78
+ max-width: 100%;
79
+ min-width: 0;
80
+ }
81
+
82
+ [data-component="line-comment"][data-inline] [data-slot="line-comment-popover"][data-inline-body] {
83
+ margin-left: 0;
84
+ }
85
+
86
+ [data-component="line-comment"][data-inline][data-variant="default"] [data-slot="line-comment-popover"][data-inline-body] {
87
+ cursor: pointer;
88
+ }
89
+
90
+ [data-component="line-comment"][data-variant="editor"] [data-slot="line-comment-popover"] {
91
+ width: 380px;
92
+ max-width: none;
93
+ padding: 8px;
94
+ border-radius: 14px;
95
+ }
96
+
97
+ [data-component="line-comment"][data-inline][data-variant="editor"] [data-slot="line-comment-popover"] {
98
+ width: 100%;
99
+ }
100
+
101
+ [data-component="line-comment"] [data-slot="line-comment-content"] {
102
+ display: flex;
103
+ flex-direction: column;
104
+ gap: 6px;
105
+ width: 100%;
106
+ min-width: 0;
107
+ }
108
+
109
+ [data-component="line-comment"] [data-slot="line-comment-head"] {
110
+ display: flex;
111
+ align-items: flex-start;
112
+ gap: 8px;
113
+ min-width: 0;
114
+ }
115
+
116
+ [data-component="line-comment"] [data-slot="line-comment-text"] {
117
+ flex: 1;
118
+ min-width: 0;
119
+ font-family: var(--font-family-sans);
120
+ font-size: var(--font-size-base);
121
+ font-weight: var(--font-weight-regular);
122
+ line-height: var(--line-height-x-large);
123
+ letter-spacing: var(--letter-spacing-normal);
124
+ color: var(--v2-text-text-base);
125
+ white-space: pre-wrap;
126
+ overflow-wrap: anywhere;
127
+ }
128
+
129
+ [data-component="line-comment"] [data-slot="line-comment-tools"] {
130
+ flex: 0 0 auto;
131
+ display: flex;
132
+ align-items: center;
133
+ justify-content: flex-end;
134
+ min-width: 0;
135
+ }
136
+
137
+ [data-component="line-comment"] [data-slot="line-comment-label"],
138
+ [data-component="line-comment"] [data-slot="line-comment-editor-label"] {
139
+ font-family: var(--font-family-sans);
140
+ font-size: var(--font-size-small);
141
+ font-weight: var(--font-weight-medium);
142
+ line-height: var(--line-height-large);
143
+ letter-spacing: var(--letter-spacing-normal);
144
+ color: var(--v2-text-text-faint);
145
+ min-width: 0;
146
+ white-space: normal;
147
+ overflow-wrap: anywhere;
148
+ }
149
+
150
+ [data-component="line-comment"] [data-slot="line-comment-editor"] {
151
+ display: flex;
152
+ flex-direction: column;
153
+ gap: 8px;
154
+ width: 100%;
155
+ min-width: 0;
156
+ }
157
+
158
+ [data-component="line-comment"] [data-slot="line-comment-textarea"] {
159
+ width: 100%;
160
+ box-sizing: border-box;
161
+ resize: vertical;
162
+ padding: 8px;
163
+ border-radius: var(--radius-md);
164
+ background: var(--surface-base);
165
+ border: 1px solid var(--v2-border-border-base);
166
+ color: var(--v2-text-text-base);
167
+ font-family: var(--font-family-sans);
168
+ font-size: var(--font-size-small);
169
+ line-height: var(--line-height-large);
170
+ }
171
+
172
+ /* An outline, not a shadow: forced colours drop shadows, and the outline outside the border still marks focus there. */
173
+ [data-component="line-comment"] [data-slot="line-comment-textarea"]:focus {
174
+ border-color: var(--v2-border-border-focus);
175
+ outline: 1px solid var(--v2-border-border-focus);
176
+ outline-offset: 0;
177
+ }
178
+
179
+ [data-component="line-comment"] [data-slot="line-comment-mention-list"] {
180
+ display: flex;
181
+ flex-direction: column;
182
+ gap: 4px;
183
+ max-height: 180px;
184
+ overflow: auto;
185
+ padding: 4px;
186
+ border: 1px solid var(--v2-border-border-base);
187
+ border-radius: var(--radius-md);
188
+ background: var(--surface-base);
189
+ }
190
+
191
+ [data-component="line-comment"] [data-slot="line-comment-mention-item"] {
192
+ display: flex;
193
+ align-items: center;
194
+ gap: 8px;
195
+ width: 100%;
196
+ min-width: 0;
197
+ padding: 6px 8px;
198
+ border: 0;
199
+ border-radius: var(--radius-sm);
200
+ background: transparent;
201
+ color: var(--v2-text-text-base);
202
+ text-align: left;
203
+ }
204
+
205
+ [data-component="line-comment"] [data-slot="line-comment-mention-item"][data-active] {
206
+ background: var(--surface-raised-base-hover);
207
+ }
208
+
209
+ [data-component="line-comment"] [data-slot="line-comment-mention-path"] {
210
+ display: flex;
211
+ align-items: center;
212
+ min-width: 0;
213
+ font-family: var(--font-family-sans);
214
+ font-size: var(--font-size-small);
215
+ line-height: var(--line-height-large);
216
+ }
217
+
218
+ [data-component="line-comment"] [data-slot="line-comment-mention-dir"] {
219
+ min-width: 0;
220
+ color: var(--v2-text-text-faint);
221
+ white-space: nowrap;
222
+ overflow: hidden;
223
+ text-overflow: ellipsis;
224
+ }
225
+
226
+ [data-component="line-comment"] [data-slot="line-comment-mention-file"] {
227
+ color: var(--v2-text-text-base);
228
+ white-space: nowrap;
229
+ }
230
+
231
+ [data-component="line-comment"] [data-slot="line-comment-actions"] {
232
+ display: flex;
233
+ align-items: center;
234
+ flex-wrap: wrap;
235
+ gap: 8px;
236
+ padding-left: 8px;
237
+ min-width: 0;
238
+ }
239
+
240
+ [data-component="line-comment"] [data-slot="line-comment-editor-label"] {
241
+ flex: 1 1 220px;
242
+ margin-right: auto;
243
+ }
244
+
245
+ [data-component="line-comment"] [data-slot="line-comment-action"] {
246
+ border: 1px solid var(--v2-border-border-base);
247
+ background: var(--surface-base);
248
+ color: var(--v2-text-text-base);
249
+ border-radius: var(--radius-md);
250
+ height: 28px;
251
+ padding: 0 10px;
252
+ font-family: var(--font-family-sans);
253
+ font-size: var(--font-size-small);
254
+ font-weight: var(--font-weight-medium);
255
+ }
256
+
257
+ [data-component="line-comment"] [data-slot="line-comment-action"][data-variant="ghost"] {
258
+ background: transparent;
259
+ }
260
+
261
+ [data-component="line-comment"] [data-slot="line-comment-action"][data-variant="primary"] {
262
+ background: var(--v2-background-bg-contrast);
263
+ border-color: var(--v2-background-bg-contrast);
264
+ color: var(--v2-text-text-contrast);
265
+ }
266
+
267
+ [data-component="line-comment"] [data-slot="line-comment-action"]:disabled {
268
+ opacity: 0.5;
269
+ pointer-events: none;
270
+ }
271
+ `
272
+
273
+ let installed = false
274
+
275
+ export function installLineCommentStyles() {
276
+ if (installed) return
277
+
278
+ if (typeof document === "undefined") return
279
+
280
+ const id = "opencode-line-comment-styles"
281
+
282
+ if (document.getElementById(id)) {
283
+ installed = true
284
+
285
+ return
286
+ }
287
+
288
+ const style = document.createElement("style")
289
+ style.id = id
290
+ style.textContent = lineCommentStyles
291
+ document.head.appendChild(style)
292
+ installed = true
293
+ }
@@ -0,0 +1,152 @@
1
+ import { createEffect, createSignal } from "solid-js"
2
+ import { LineComment, LineCommentAnchor, LineCommentEditor } from "./line-comment"
3
+
4
+ const docs = `### Overview
5
+ Inline comment anchor and editor for code review or annotation flows.
6
+
7
+ Pair with \`Diff\` or \`Code\` to align comments to lines.
8
+
9
+ ### API
10
+ - \`LineCommentAnchor\`: position with \`top\`, control \`open\`, render custom children.
11
+ - \`LineComment\`: convenience wrapper for displaying comment + selection label.
12
+ - \`LineCommentEditor\`: controlled textarea with submit/cancel handlers.
13
+
14
+ ### Variants and states
15
+ - Default display and editor display variants.
16
+
17
+ ### Behavior
18
+ - Anchor positions relative to a containing element.
19
+ - Editor submits on Enter (Shift+Enter for newline).
20
+
21
+ ### Accessibility
22
+ - TODO: confirm ARIA labeling for comment button and editor textarea.
23
+
24
+ ### Theming/tokens
25
+ - Uses \`data-component="line-comment"\` and related slots.
26
+
27
+ `
28
+
29
+ export default {
30
+ title: "OpenCode/Review/Line comments",
31
+ id: "components-line-comment",
32
+ component: LineComment,
33
+ args: { inline: false },
34
+ tags: ["autodocs"],
35
+ parameters: {
36
+ docs: {
37
+ description: {
38
+ component: docs,
39
+ },
40
+ },
41
+ },
42
+ }
43
+
44
+ export const Default = {
45
+ args: { open: true, comment: "Consider guarding against empty arrays.", selection: "L12-L13" },
46
+ render: (args: { inline: boolean; open: boolean; comment: string; selection: string }) => {
47
+ const [open, setOpen] = createSignal(args.open)
48
+ createEffect(() => setOpen(args.open))
49
+
50
+ return (
51
+ <div
52
+ style={{
53
+ position: "relative",
54
+ height: "160px",
55
+ padding: "16px 16px 16px 40px",
56
+ border: "1px solid var(--border-weak)",
57
+ "border-radius": "8px",
58
+ "font-family": "var(--font-family-mono)",
59
+ "font-size": "12px",
60
+ color: "var(--text-weak)",
61
+ }}
62
+ >
63
+ <div>12 | const total = sum(values)</div>
64
+ <div>13 | return total / values.length</div>
65
+ <LineComment
66
+ inline={args.inline}
67
+ open={open()}
68
+ top={18}
69
+ comment={args.comment}
70
+ selection={args.selection}
71
+ buttonLabel="Toggle comment"
72
+ onClick={() => setOpen(!open())}
73
+ />
74
+ </div>
75
+ )
76
+ },
77
+ }
78
+
79
+ export const Editor = {
80
+ args: { comment: "Add context for this change.", selection: "L40", mentions: false },
81
+ render: (args: { inline: boolean; comment: string; selection: string; mentions: boolean }) => {
82
+ const [value, setValue] = createSignal(args.comment)
83
+ createEffect(() => setValue(args.comment))
84
+
85
+ return (
86
+ <div
87
+ style={{
88
+ position: "relative",
89
+ height: "220px",
90
+ padding: "16px 16px 16px 40px",
91
+ border: "1px solid var(--border-weak)",
92
+ "border-radius": "8px",
93
+ "font-family": "var(--font-family-mono)",
94
+ "font-size": "12px",
95
+ color: "var(--text-weak)",
96
+ }}
97
+ >
98
+ <div>40 | if (values.length === 0) return 0</div>
99
+ <LineCommentEditor
100
+ top={24}
101
+ inline={args.inline}
102
+ value={value()}
103
+ selection={args.selection}
104
+ mention={
105
+ args.mentions
106
+ ? { items: (query) => ["src/sum.ts", "src/sum.test.ts"].filter((path) => path.includes(query)) }
107
+ : undefined
108
+ }
109
+ onInput={setValue}
110
+ onCancel={() => setValue("")}
111
+ onSubmit={(next) => setValue(next)}
112
+ />
113
+ </div>
114
+ )
115
+ },
116
+ }
117
+
118
+ export const AnchorOnly = {
119
+ args: { open: false, icon: "comment" },
120
+ argTypes: { icon: { options: ["comment", "plus"] } },
121
+ render: (args: { inline: boolean; open: boolean; icon: "comment" | "plus" }) => {
122
+ const [open, setOpen] = createSignal(args.open)
123
+ createEffect(() => setOpen(args.open))
124
+
125
+ return (
126
+ <div
127
+ style={{
128
+ position: "relative",
129
+ height: "120px",
130
+ padding: "16px 16px 16px 40px",
131
+ border: "1px solid var(--border-weak)",
132
+ "border-radius": "8px",
133
+ "font-family": "var(--font-family-mono)",
134
+ "font-size": "12px",
135
+ color: "var(--text-weak)",
136
+ }}
137
+ >
138
+ <div>20 | const ready = true</div>
139
+ <LineCommentAnchor
140
+ top={18}
141
+ inline={args.inline}
142
+ open={open()}
143
+ icon={args.icon}
144
+ buttonLabel="Toggle comment"
145
+ onClick={() => setOpen(!open())}
146
+ >
147
+ <div data-slot="line-comment-content">Anchor content</div>
148
+ </LineCommentAnchor>
149
+ </div>
150
+ )
151
+ },
152
+ }