@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,72 @@
1
+ /** A user-message action: `queue` and `remove` act on a pending steer, `revert` and `fork` on a delivered message. */
2
+ export type MessageAction = "queue" | "remove" | "revert" | "fork"
3
+
4
+ /** What the message offers right now: the host's actions and whether the server has delivered the message yet. */
5
+ export type MessageActionCapabilities = {
6
+ readonly pending: boolean
7
+ readonly canPending: boolean
8
+ readonly canRevert: boolean
9
+ readonly canFork: boolean
10
+ }
11
+
12
+ /** At most one action runs per message; `attempts` counts started actions so a late result cannot settle a newer one. */
13
+ export type MessageActionState =
14
+ | { readonly status: "idle"; readonly attempts: number }
15
+ | { readonly status: "running"; readonly action: MessageAction; readonly attempt: number }
16
+
17
+ export type MessageActionEvent =
18
+ | { readonly type: "requested"; readonly action: MessageAction; readonly capabilities: MessageActionCapabilities }
19
+ | { readonly type: "succeeded"; readonly attempt: number }
20
+ | { readonly type: "failed"; readonly attempt: number }
21
+ | { readonly type: "disposed" }
22
+
23
+ export type MessageActionEffect = { readonly type: "run"; readonly action: MessageAction; readonly attempt: number }
24
+
25
+ export type MessageActionTransition = {
26
+ readonly state: MessageActionState
27
+ readonly effects: readonly MessageActionEffect[]
28
+ }
29
+
30
+ export function createMessageActionState(): MessageActionState {
31
+ return { status: "idle", attempts: 0 }
32
+ }
33
+
34
+ export function transitionMessageAction(state: MessageActionState, event: MessageActionEvent): MessageActionTransition {
35
+ if (event.type === "requested") {
36
+ if (state.status === "running" || !canStart(event.action, event.capabilities)) return { state, effects: [] }
37
+ const attempt = state.attempts + 1
38
+
39
+ return {
40
+ state: { status: "running", action: event.action, attempt },
41
+ effects: [{ type: "run", action: event.action, attempt }],
42
+ }
43
+ }
44
+
45
+ if (state.status === "idle") return { state, effects: [] }
46
+
47
+ // A failure settles like a success: the host reports the error, and the message's actions stay usable.
48
+ if (event.type !== "disposed" && event.attempt !== state.attempt) return { state, effects: [] }
49
+
50
+ return { state: { status: "idle", attempts: state.attempt }, effects: [] }
51
+ }
52
+
53
+ export function viewMessageActions(state: MessageActionState, capabilities: MessageActionCapabilities) {
54
+ const disabled = (action: MessageAction) => state.status === "running" || !canStart(action, capabilities)
55
+
56
+ return {
57
+ disabled: {
58
+ queue: disabled("queue"),
59
+ remove: disabled("remove"),
60
+ revert: disabled("revert"),
61
+ fork: disabled("fork"),
62
+ },
63
+ }
64
+ }
65
+
66
+ function canStart(action: MessageAction, capabilities: MessageActionCapabilities) {
67
+ if (action === "queue" || action === "remove") return capabilities.canPending && capabilities.pending
68
+
69
+ if (action === "revert") return capabilities.canRevert && !capabilities.pending
70
+
71
+ return capabilities.canFork && !capabilities.pending
72
+ }
@@ -0,0 +1,3 @@
1
+ export function agentLabel(agent: string | undefined, visible: boolean) {
2
+ return visible && agent ? agent[0]?.toUpperCase() + agent.slice(1) : ""
3
+ }
@@ -0,0 +1,119 @@
1
+ [data-component="attachment-card"] {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 6px;
5
+ box-sizing: border-box;
6
+ width: 160px;
7
+ min-width: 160px;
8
+ max-width: 160px;
9
+ padding: 8px;
10
+ border-radius: 6px;
11
+ background: var(--v2-overlay-simple-overlay-hover);
12
+ box-shadow: inset 0 0 0 0.5px var(--v2-border-border-base);
13
+ cursor: default;
14
+
15
+ &[data-wide] {
16
+ width: 100%;
17
+ min-width: 0;
18
+ max-width: none;
19
+ }
20
+
21
+ &[data-surface="base"] {
22
+ background: var(--v2-background-bg-base);
23
+ }
24
+
25
+ &[data-active] {
26
+ box-shadow: inset 0 0 0 0.5px var(--v2-border-border-strong);
27
+ }
28
+
29
+ &[data-clickable] {
30
+ cursor: pointer;
31
+ }
32
+
33
+ [data-slot="attachment-card-title"],
34
+ [data-slot="attachment-card-subtitle"] {
35
+ max-width: 100%;
36
+ font-family: var(--v2-font-family-sans, "Inter", sans-serif);
37
+ font-style: normal;
38
+ font-size: 11px;
39
+ /* Inter's descenders need 14px at 11px; a tighter line box clips them where the text truncates. */
40
+ line-height: 14px;
41
+ letter-spacing: 0.05px;
42
+ font-variation-settings: "slnt" 0;
43
+ }
44
+
45
+ [data-slot="attachment-card-title"] {
46
+ width: 100%;
47
+ min-width: 0;
48
+ overflow: hidden;
49
+ text-overflow: ellipsis;
50
+ white-space: nowrap;
51
+ font-weight: 530;
52
+ color: var(--v2-text-text-base);
53
+ }
54
+
55
+ [data-slot="attachment-card-subtitle"] {
56
+ display: flex;
57
+ align-items: center;
58
+ gap: 4px;
59
+ min-width: 0;
60
+ min-height: 16px;
61
+ overflow: hidden;
62
+ white-space: nowrap;
63
+ font-weight: 440;
64
+ color: var(--v2-text-text-muted);
65
+
66
+ [data-component="file-icon"],
67
+ [data-slot="icon-svg"] {
68
+ width: 12px;
69
+ height: 12px;
70
+ flex: none;
71
+ }
72
+
73
+ [data-slot="attachment-card-label"] {
74
+ min-width: 0;
75
+ overflow: hidden;
76
+ text-overflow: ellipsis;
77
+ }
78
+ }
79
+ }
80
+
81
+ [data-component="attachment-card"] {
82
+ [data-slot="comment-card-quote"],
83
+ [data-slot="comment-card-action"] {
84
+ display: flex;
85
+ align-items: center;
86
+ gap: 4px;
87
+ min-width: 0;
88
+ }
89
+
90
+ [data-slot="comment-card-action"] {
91
+ display: none;
92
+ color: var(--v2-text-text-base);
93
+ }
94
+ }
95
+
96
+ @media (hover: hover) {
97
+ [data-component="attachment-card"]:hover:has([data-slot="comment-card-action"]) [data-slot="comment-card-quote"] {
98
+ display: none;
99
+ }
100
+
101
+ [data-component="attachment-card"]:hover [data-slot="comment-card-action"] {
102
+ display: flex;
103
+ }
104
+ }
105
+
106
+ @media (hover: none) {
107
+ [data-component="attachment-card"]:has([data-slot="comment-card-action"]:not([data-commented]))
108
+ [data-slot="comment-card-quote"] {
109
+ display: none;
110
+ }
111
+
112
+ [data-component="attachment-card"] [data-slot="comment-card-action"]:not([data-commented]) {
113
+ display: flex;
114
+ }
115
+ }
116
+
117
+ [data-color-scheme="dark"] [data-component="attachment-card"][data-surface="base"] {
118
+ background: var(--v2-overlay-simple-overlay-hover);
119
+ }
@@ -0,0 +1,40 @@
1
+ import type { JSX } from "solid-js"
2
+ import "./attachment-card.css"
3
+
4
+ /** Shared 160px two-line card used by file and comment attachments. */
5
+ export function AttachmentCard(props: {
6
+ title: string
7
+ active?: boolean
8
+ clickable?: boolean
9
+ wide?: boolean
10
+ surface?: "base"
11
+ /** native title attribute */
12
+ hover?: string
13
+ titleRef?: (element: HTMLSpanElement) => void
14
+ onClick?: () => void
15
+ children: JSX.Element
16
+ }) {
17
+ return (
18
+ <div
19
+ data-component="attachment-card"
20
+ data-active={props.active ? "true" : undefined}
21
+ data-clickable={props.clickable ? "true" : undefined}
22
+ data-wide={props.wide ? "true" : undefined}
23
+ data-surface={props.surface}
24
+ role={props.clickable ? "button" : undefined}
25
+ tabIndex={props.clickable ? 0 : undefined}
26
+ title={props.hover}
27
+ onClick={() => props.onClick?.()}
28
+ onKeyDown={(event) => {
29
+ if (!props.clickable || (event.key !== "Enter" && event.key !== " ")) return
30
+ event.preventDefault()
31
+ props.onClick?.()
32
+ }}
33
+ >
34
+ <span ref={(element) => props.titleRef?.(element)} data-slot="attachment-card-title">
35
+ {props.title}
36
+ </span>
37
+ <span data-slot="attachment-card-subtitle">{props.children}</span>
38
+ </div>
39
+ )
40
+ }
@@ -0,0 +1,213 @@
1
+ import type { PromptAttachment } from "@zyro-sec/client/promise"
2
+
3
+ /** A media read that never settles shows the failed tile after this long, as file and markdown images do. */
4
+ export const ATTACHMENT_MEDIA_TIMEOUT_MS = 15_000
5
+
6
+ /**
7
+ * What an attachment slot shows, read from its current attachment: nothing (not an image), a URL already in hand, a
8
+ * `media:` reference nothing here can read, or a reference the host reads.
9
+ */
10
+ export type AttachmentMediaTarget =
11
+ | { readonly kind: "none" }
12
+ | { readonly kind: "direct"; readonly src: string }
13
+ | { readonly kind: "unreadable" }
14
+ | { readonly kind: "remote"; readonly key: string; readonly uri: string; readonly mime: string }
15
+
16
+ /** The host read of one `remote` target. `attempt` lets only the latest read and its own timeout settle it. */
17
+ export type AttachmentMediaState =
18
+ | { readonly status: "idle"; readonly attempt: number }
19
+ | { readonly status: "loading"; readonly attempt: number; readonly key: string }
20
+ | { readonly status: "ready"; readonly attempt: number; readonly key: string; readonly src: string }
21
+ | { readonly status: "failed"; readonly attempt: number; readonly key: string }
22
+ | { readonly status: "disposed" }
23
+
24
+ export type AttachmentMediaEvent =
25
+ | { readonly type: "target.synced"; readonly target: AttachmentMediaTarget }
26
+ | { readonly type: "retry.requested"; readonly target: AttachmentMediaTarget }
27
+ | { readonly type: "read.succeeded"; readonly attempt: number; readonly src: string }
28
+ | { readonly type: "read.failed"; readonly attempt: number }
29
+ | { readonly type: "read.timed-out"; readonly attempt: number }
30
+ | { readonly type: "disposed" }
31
+
32
+ export type AttachmentMediaEffect =
33
+ | {
34
+ readonly type: "read"
35
+ readonly attempt: number
36
+ readonly uri: string
37
+ readonly mime: string
38
+ readonly timeoutMs: number
39
+ }
40
+ /** Aborts the read in flight and clears its timer. */
41
+ | { readonly type: "cancel" }
42
+
43
+ export type AttachmentMediaTransition = {
44
+ readonly state: AttachmentMediaState
45
+ readonly effects: readonly AttachmentMediaEffect[]
46
+ }
47
+
48
+ export type AttachmentMediaView = {
49
+ readonly status: "idle" | "loading" | "ready" | "failed"
50
+ readonly src: string | undefined
51
+ readonly placeholder: boolean
52
+ readonly clickable: boolean
53
+ readonly canRetry: boolean
54
+ }
55
+
56
+ export const NONE_ATTACHMENT_MEDIA_TARGET: AttachmentMediaTarget = Object.freeze({ kind: "none" })
57
+
58
+ export const UNREADABLE_ATTACHMENT_MEDIA_TARGET: AttachmentMediaTarget = Object.freeze({ kind: "unreadable" })
59
+
60
+ export const INITIAL_ATTACHMENT_MEDIA_STATE: AttachmentMediaState = Object.freeze({ status: "idle", attempt: 0 })
61
+
62
+ export const DISPOSED_ATTACHMENT_MEDIA_STATE: AttachmentMediaState = Object.freeze({ status: "disposed" })
63
+
64
+ export const DISPOSED_ATTACHMENT_MEDIA_EVENT: AttachmentMediaEvent = Object.freeze({ type: "disposed" })
65
+
66
+ const NO_EFFECTS: readonly AttachmentMediaEffect[] = Object.freeze([])
67
+
68
+ const CANCEL_EFFECT: AttachmentMediaEffect = Object.freeze({ type: "cancel" })
69
+
70
+ const CANCEL: readonly AttachmentMediaEffect[] = Object.freeze([CANCEL_EFFECT])
71
+
72
+ export function resolveAttachmentMediaTarget(
73
+ file: PromptAttachment,
74
+ options: { readonly peekMedia?: (uri: string, mime: string) => string | undefined; readonly hasReader: boolean },
75
+ ): AttachmentMediaTarget {
76
+ if (!file.mime.startsWith("image/")) return NONE_ATTACHMENT_MEDIA_TARGET
77
+
78
+ if (file.source?.type === "uri") return { kind: "direct", src: file.source.uri }
79
+
80
+ if ("data" in file && file.data !== undefined) return { kind: "direct", src: `data:${file.mime};base64,${file.data}` }
81
+
82
+ const uri = "uri" in file ? file.uri : undefined
83
+
84
+ if (!uri) return UNREADABLE_ATTACHMENT_MEDIA_TARGET
85
+
86
+ const peeked = options.peekMedia?.(uri, file.mime)
87
+
88
+ if (peeked !== undefined) return { kind: "direct", src: peeked }
89
+
90
+ if (options.hasReader) return { kind: "remote", key: `${file.mime}:${uri}`, uri, mime: file.mime }
91
+
92
+ // Without a reader a `media:` reference names no loadable URL; anything else is one.
93
+ if (uri.startsWith("media:")) return UNREADABLE_ATTACHMENT_MEDIA_TARGET
94
+
95
+ return { kind: "direct", src: uri }
96
+ }
97
+
98
+ export function transitionAttachmentMedia(
99
+ state: AttachmentMediaState,
100
+ event: AttachmentMediaEvent,
101
+ ): AttachmentMediaTransition {
102
+ if (state.status === "disposed") return { state, effects: NO_EFFECTS }
103
+
104
+ if (event.type === "disposed") {
105
+ return { state: DISPOSED_ATTACHMENT_MEDIA_STATE, effects: state.status === "loading" ? CANCEL : NO_EFFECTS }
106
+ }
107
+
108
+ if (event.type === "target.synced") return sync(state, event.target)
109
+
110
+ if (event.type === "retry.requested") {
111
+ if (state.status !== "failed" || event.target.kind !== "remote" || event.target.key !== state.key) {
112
+ return { state, effects: NO_EFFECTS }
113
+ }
114
+
115
+ return read(state, event.target)
116
+ }
117
+
118
+ if (state.status !== "loading" || event.attempt !== state.attempt) return { state, effects: NO_EFFECTS }
119
+
120
+ if (event.type === "read.succeeded" && event.src.length > 0) {
121
+ return { state: { status: "ready", attempt: state.attempt, key: state.key, src: event.src }, effects: CANCEL }
122
+ }
123
+
124
+ return { state: { status: "failed", attempt: state.attempt, key: state.key }, effects: CANCEL }
125
+ }
126
+
127
+ export function viewAttachmentMedia(state: AttachmentMediaState, target: AttachmentMediaTarget): AttachmentMediaView {
128
+ if (target.kind === "none") return IDLE_VIEW
129
+
130
+ if (target.kind === "direct")
131
+ return { status: "ready", src: target.src, placeholder: false, clickable: true, canRetry: false }
132
+
133
+ if (target.kind === "unreadable") return UNREADABLE_VIEW
134
+
135
+ // Before the slot's effect syncs a new target, the state still describes the previous attachment: never show it.
136
+ if (state.status === "idle" || state.status === "disposed" || state.key !== target.key) return LOADING_VIEW
137
+
138
+ if (state.status === "loading") return LOADING_VIEW
139
+
140
+ if (state.status === "failed") return FAILED_VIEW
141
+
142
+ return { status: "ready", src: state.src, placeholder: false, clickable: true, canRetry: false }
143
+ }
144
+
145
+ const IDLE_VIEW: AttachmentMediaView = Object.freeze({
146
+ status: "idle",
147
+ src: undefined,
148
+ placeholder: false,
149
+ clickable: false,
150
+ canRetry: false,
151
+ })
152
+
153
+ const LOADING_VIEW: AttachmentMediaView = Object.freeze({
154
+ status: "loading",
155
+ src: undefined,
156
+ placeholder: true,
157
+ clickable: false,
158
+ canRetry: false,
159
+ })
160
+
161
+ const FAILED_VIEW: AttachmentMediaView = Object.freeze({
162
+ status: "failed",
163
+ src: undefined,
164
+ placeholder: false,
165
+ clickable: true,
166
+ canRetry: true,
167
+ })
168
+
169
+ const UNREADABLE_VIEW: AttachmentMediaView = Object.freeze({
170
+ status: "failed",
171
+ src: undefined,
172
+ placeholder: false,
173
+ clickable: false,
174
+ canRetry: false,
175
+ })
176
+
177
+ function sync(
178
+ state: Exclude<AttachmentMediaState, { status: "disposed" }>,
179
+ target: AttachmentMediaTarget,
180
+ ): AttachmentMediaTransition {
181
+ if (target.kind === "remote") {
182
+ if (state.status !== "idle" && state.key === target.key) return { state, effects: NO_EFFECTS }
183
+
184
+ return read(state, target)
185
+ }
186
+
187
+ if (state.status === "idle") return { state, effects: NO_EFFECTS }
188
+
189
+ return {
190
+ state: { status: "idle", attempt: state.attempt },
191
+ effects: state.status === "loading" ? CANCEL : NO_EFFECTS,
192
+ }
193
+ }
194
+
195
+ function read(
196
+ state: Exclude<AttachmentMediaState, { status: "disposed" }>,
197
+ target: Extract<AttachmentMediaTarget, { kind: "remote" }>,
198
+ ): AttachmentMediaTransition {
199
+ const attempt = state.attempt + 1
200
+
201
+ const effect: AttachmentMediaEffect = {
202
+ type: "read",
203
+ attempt,
204
+ uri: target.uri,
205
+ mime: target.mime,
206
+ timeoutMs: ATTACHMENT_MEDIA_TIMEOUT_MS,
207
+ }
208
+
209
+ return {
210
+ state: { status: "loading", attempt, key: target.key },
211
+ effects: state.status === "loading" ? [CANCEL_EFFECT, effect] : [effect],
212
+ }
213
+ }
@@ -0,0 +1,155 @@
1
+ import { createSignal, Match, onCleanup, onMount, Show, Switch } from "solid-js"
2
+ import { FileIcon } from "@zyro-sec/ui/file-icon"
3
+ import { Icon } from "@zyro-sec/ui/icon"
4
+ import { useI18n } from "@zyro-sec/ui/context/i18n"
5
+ import { getFilenameTruncated } from "@zyro-sec/util/path"
6
+ import { Tooltip } from "@zyro-sec/ui/tooltip"
7
+ import { AttachmentCard } from "./attachment-card"
8
+
9
+ /**
10
+ * What a comment is about: lines of a file, a labelled subject such as an element picked in a page, or quoted text.
11
+ * A quote from outside the timeline names its source, such as a terminal.
12
+ */
13
+ export type CommentCardTarget =
14
+ | { type: "file"; path: string; selection?: { startLine: number; endLine: number } }
15
+ | { type: "note"; label: string; icon: string; title?: string; subtitle?: string }
16
+ | { type: "quote"; text: string; source?: { label: string; icon: string } }
17
+
18
+ export function commentCardTarget(
19
+ comment:
20
+ | { type?: "file"; path: string; selection?: { startLine: number; endLine: number } }
21
+ | { type: "note"; label: string; icon: string; title?: string; subtitle?: string }
22
+ | { type: "quote"; text: string; source?: { label: string; icon: string } },
23
+ ): CommentCardTarget {
24
+ if (comment.type === "note")
25
+ return { type: "note", label: comment.label, icon: comment.icon, title: comment.title, subtitle: comment.subtitle }
26
+
27
+ if (comment.type === "quote") return { type: "quote", text: comment.text, source: comment.source }
28
+
29
+ return { type: "file", path: comment.path, selection: comment.selection }
30
+ }
31
+
32
+ const QUOTE_PREVIEW_LENGTH = 200
33
+
34
+ const QUOTE_TOOLTIP_LENGTH = 600
35
+
36
+ export function quoteTooltip(quote: { text: string; comment?: string }) {
37
+ const text = quote.text.length > QUOTE_TOOLTIP_LENGTH ? `${quote.text.slice(0, QUOTE_TOOLTIP_LENGTH)}…` : quote.text
38
+
39
+ return quote.comment ? `${quote.comment}\n\n${text}` : text
40
+ }
41
+
42
+ export function CommentCard(props: {
43
+ comment: string
44
+ target: CommentCardTarget
45
+ active?: boolean
46
+ title?: string
47
+ tooltip?: boolean
48
+ wide?: boolean
49
+ onClick?: () => void
50
+ }) {
51
+ const i18n = useI18n()
52
+ let title: HTMLSpanElement | undefined
53
+ const [truncated, setTruncated] = createSignal(false)
54
+ const quote = () => (props.target.type === "quote" ? props.target.text.slice(0, QUOTE_PREVIEW_LENGTH) : undefined)
55
+ const source = () => (props.target.type === "quote" ? props.target.source : undefined)
56
+ const note = () => (props.target.type === "note" ? props.target : undefined)
57
+
58
+ const subtitle = () => note()?.subtitle?.trim() || note()?.label
59
+
60
+ const heading = () => {
61
+ const target = note()
62
+
63
+ if (target) return props.comment.trim() ? props.comment : target.title?.trim() || target.label
64
+
65
+ return props.comment || (quote() ?? "")
66
+ }
67
+
68
+ const tooltipDisabled = () =>
69
+ !props.tooltip ||
70
+ (!truncated() && !(note() && !props.comment.trim()) && !(props.target.type === "quote" && props.comment))
71
+
72
+ onMount(() => {
73
+ const element = title
74
+
75
+ if (!element) return
76
+ const sync = () => setTruncated(element.scrollWidth > element.clientWidth)
77
+ const measure = () => requestAnimationFrame(sync)
78
+ const observer = new ResizeObserver(sync)
79
+ observer.observe(element)
80
+ measure()
81
+ void document.fonts?.ready.then(measure)
82
+ onCleanup(() => observer.disconnect())
83
+ })
84
+
85
+ return (
86
+ <Tooltip
87
+ placement="top"
88
+ openDelay={1000}
89
+ value={props.title ?? (note() && !props.comment.trim() ? `${heading()}\n${subtitle()}` : heading())}
90
+ disabled={tooltipDisabled()}
91
+ class={props.wide ? "w-full" : undefined}
92
+ contentStyle={{ "max-width": "320px", "white-space": "pre-wrap" }}
93
+ >
94
+ <AttachmentCard
95
+ title={heading()}
96
+ active={props.active}
97
+ clickable={!!props.onClick}
98
+ wide={props.wide}
99
+ surface="base"
100
+ titleRef={(element) => {
101
+ title = element
102
+ }}
103
+ onClick={props.onClick}
104
+ >
105
+ <Switch>
106
+ <Match when={props.target.type === "file" ? props.target : undefined}>
107
+ {(file) => (
108
+ <>
109
+ <FileIcon node={{ path: file().path, type: "file" }} />
110
+ <span>
111
+ {getFilenameTruncated(file().path, 14)}
112
+ <Show when={file().selection}>
113
+ {(sel) =>
114
+ sel().startLine === sel().endLine ? `:${sel().startLine}` : `:${sel().startLine}-${sel().endLine}`
115
+ }
116
+ </Show>
117
+ </span>
118
+ </>
119
+ )}
120
+ </Match>
121
+ <Match when={props.target.type === "note" ? props.target : undefined}>
122
+ {(note) => (
123
+ <>
124
+ <Icon name={note().icon} />
125
+ <span data-slot="attachment-card-label" dir="ltr">
126
+ {subtitle()}
127
+ </span>
128
+ </>
129
+ )}
130
+ </Match>
131
+ <Match when={quote()}>
132
+ {(text) => (
133
+ <>
134
+ <span data-slot="comment-card-quote">
135
+ <Icon name={source()?.icon ?? "outline-quote"} />
136
+ <span data-slot="attachment-card-label" dir="auto">
137
+ {props.comment ? text() : (source()?.label ?? i18n.t("ui.commentCard.quote"))}
138
+ </span>
139
+ </span>
140
+ <Show when={props.onClick}>
141
+ <span data-slot="comment-card-action" data-commented={props.comment ? "" : undefined}>
142
+ <Icon name="comment" />
143
+ <span data-slot="attachment-card-label">
144
+ {props.comment ? i18n.t("ui.commentCard.editComment") : i18n.t("ui.commentCard.addComment")}
145
+ </span>
146
+ </span>
147
+ </Show>
148
+ </>
149
+ )}
150
+ </Match>
151
+ </Switch>
152
+ </AttachmentCard>
153
+ </Tooltip>
154
+ )
155
+ }