@xemahq/ui-kernel 0.1.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 (208) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +72 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +19 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/biome-host/biome-mode.d.ts +2 -0
  8. package/dist/lib/biome-host/biome-mode.d.ts.map +1 -0
  9. package/dist/lib/biome-host/biome-mode.js +3 -0
  10. package/dist/lib/biome-host/biome-mode.js.map +1 -0
  11. package/dist/lib/biome-host/biome-registry.d.ts +30 -0
  12. package/dist/lib/biome-host/biome-registry.d.ts.map +1 -0
  13. package/dist/lib/biome-host/biome-registry.js +134 -0
  14. package/dist/lib/biome-host/biome-registry.js.map +1 -0
  15. package/dist/lib/biome-host/composition-validation.d.ts +22 -0
  16. package/dist/lib/biome-host/composition-validation.d.ts.map +1 -0
  17. package/dist/lib/biome-host/composition-validation.js +127 -0
  18. package/dist/lib/biome-host/composition-validation.js.map +1 -0
  19. package/dist/lib/biome-host/frontend-biome.d.ts +47 -0
  20. package/dist/lib/biome-host/frontend-biome.d.ts.map +1 -0
  21. package/dist/lib/biome-host/frontend-biome.js +3 -0
  22. package/dist/lib/biome-host/frontend-biome.js.map +1 -0
  23. package/dist/lib/biome-host/host-bridge.d.ts +55 -0
  24. package/dist/lib/biome-host/host-bridge.d.ts.map +1 -0
  25. package/dist/lib/biome-host/host-bridge.js +16 -0
  26. package/dist/lib/biome-host/host-bridge.js.map +1 -0
  27. package/dist/lib/biome-host/host-sources.d.ts +12 -0
  28. package/dist/lib/biome-host/host-sources.d.ts.map +1 -0
  29. package/dist/lib/biome-host/host-sources.js +3 -0
  30. package/dist/lib/biome-host/host-sources.js.map +1 -0
  31. package/dist/lib/biome-host/index.d.ts +10 -0
  32. package/dist/lib/biome-host/index.d.ts.map +1 -0
  33. package/dist/lib/biome-host/index.js +26 -0
  34. package/dist/lib/biome-host/index.js.map +1 -0
  35. package/dist/lib/biome-host/nav.d.ts +17 -0
  36. package/dist/lib/biome-host/nav.d.ts.map +1 -0
  37. package/dist/lib/biome-host/nav.js +52 -0
  38. package/dist/lib/biome-host/nav.js.map +1 -0
  39. package/dist/lib/biome-host/session-contributions.d.ts +143 -0
  40. package/dist/lib/biome-host/session-contributions.d.ts.map +1 -0
  41. package/dist/lib/biome-host/session-contributions.js +3 -0
  42. package/dist/lib/biome-host/session-contributions.js.map +1 -0
  43. package/dist/lib/biome-host/session-profiles.d.ts +18 -0
  44. package/dist/lib/biome-host/session-profiles.d.ts.map +1 -0
  45. package/dist/lib/biome-host/session-profiles.js +39 -0
  46. package/dist/lib/biome-host/session-profiles.js.map +1 -0
  47. package/dist/lib/system-bus/capability-invoke.d.ts +18 -0
  48. package/dist/lib/system-bus/capability-invoke.d.ts.map +1 -0
  49. package/dist/lib/system-bus/capability-invoke.js +3 -0
  50. package/dist/lib/system-bus/capability-invoke.js.map +1 -0
  51. package/dist/lib/system-bus/deeplink.d.ts +33 -0
  52. package/dist/lib/system-bus/deeplink.d.ts.map +1 -0
  53. package/dist/lib/system-bus/deeplink.js +99 -0
  54. package/dist/lib/system-bus/deeplink.js.map +1 -0
  55. package/dist/lib/system-bus/enums.d.ts +27 -0
  56. package/dist/lib/system-bus/enums.d.ts.map +1 -0
  57. package/dist/lib/system-bus/enums.js +35 -0
  58. package/dist/lib/system-bus/enums.js.map +1 -0
  59. package/dist/lib/system-bus/host-ports.d.ts +24 -0
  60. package/dist/lib/system-bus/host-ports.d.ts.map +1 -0
  61. package/dist/lib/system-bus/host-ports.js +3 -0
  62. package/dist/lib/system-bus/host-ports.js.map +1 -0
  63. package/dist/lib/system-bus/index.d.ts +11 -0
  64. package/dist/lib/system-bus/index.d.ts.map +1 -0
  65. package/dist/lib/system-bus/index.js +27 -0
  66. package/dist/lib/system-bus/index.js.map +1 -0
  67. package/dist/lib/system-bus/intent-registry.d.ts +14 -0
  68. package/dist/lib/system-bus/intent-registry.d.ts.map +1 -0
  69. package/dist/lib/system-bus/intent-registry.js +66 -0
  70. package/dist/lib/system-bus/intent-registry.js.map +1 -0
  71. package/dist/lib/system-bus/intents.d.ts +30 -0
  72. package/dist/lib/system-bus/intents.d.ts.map +1 -0
  73. package/dist/lib/system-bus/intents.js +3 -0
  74. package/dist/lib/system-bus/intents.js.map +1 -0
  75. package/dist/lib/system-bus/palette.d.ts +25 -0
  76. package/dist/lib/system-bus/palette.d.ts.map +1 -0
  77. package/dist/lib/system-bus/palette.js +3 -0
  78. package/dist/lib/system-bus/palette.js.map +1 -0
  79. package/dist/lib/system-bus/system-bus-builder.d.ts +10 -0
  80. package/dist/lib/system-bus/system-bus-builder.d.ts.map +1 -0
  81. package/dist/lib/system-bus/system-bus-builder.js +82 -0
  82. package/dist/lib/system-bus/system-bus-builder.js.map +1 -0
  83. package/dist/lib/system-bus/system-bus.d.ts +13 -0
  84. package/dist/lib/system-bus/system-bus.d.ts.map +1 -0
  85. package/dist/lib/system-bus/system-bus.js +3 -0
  86. package/dist/lib/system-bus/system-bus.js.map +1 -0
  87. package/dist/lib/system-bus/windows.d.ts +21 -0
  88. package/dist/lib/system-bus/windows.d.ts.map +1 -0
  89. package/dist/lib/system-bus/windows.js +3 -0
  90. package/dist/lib/system-bus/windows.js.map +1 -0
  91. package/dist/org-db/components/DbResultTable.d.ts +13 -0
  92. package/dist/org-db/components/DbResultTable.d.ts.map +1 -0
  93. package/dist/org-db/components/DbResultTable.js +58 -0
  94. package/dist/org-db/components/DbResultTable.js.map +1 -0
  95. package/dist/org-db/index.d.ts +2 -0
  96. package/dist/org-db/index.d.ts.map +1 -0
  97. package/dist/org-db/index.js +6 -0
  98. package/dist/org-db/index.js.map +1 -0
  99. package/dist/registry/index.d.ts +9 -0
  100. package/dist/registry/index.d.ts.map +1 -0
  101. package/dist/registry/index.js +25 -0
  102. package/dist/registry/index.js.map +1 -0
  103. package/dist/registry/lib/biome-slot.d.ts +7 -0
  104. package/dist/registry/lib/biome-slot.d.ts.map +1 -0
  105. package/dist/registry/lib/biome-slot.js +18 -0
  106. package/dist/registry/lib/biome-slot.js.map +1 -0
  107. package/dist/registry/lib/biomes-enabled-context.d.ts +3 -0
  108. package/dist/registry/lib/biomes-enabled-context.d.ts.map +1 -0
  109. package/dist/registry/lib/biomes-enabled-context.js +11 -0
  110. package/dist/registry/lib/biomes-enabled-context.js.map +1 -0
  111. package/dist/registry/lib/composition-validation-host.d.ts +3 -0
  112. package/dist/registry/lib/composition-validation-host.d.ts.map +1 -0
  113. package/dist/registry/lib/composition-validation-host.js +10 -0
  114. package/dist/registry/lib/composition-validation-host.js.map +1 -0
  115. package/dist/registry/lib/extension-points.d.ts +15 -0
  116. package/dist/registry/lib/extension-points.d.ts.map +1 -0
  117. package/dist/registry/lib/extension-points.js +17 -0
  118. package/dist/registry/lib/extension-points.js.map +1 -0
  119. package/dist/registry/lib/primitives/SessionEventCard.d.ts +14 -0
  120. package/dist/registry/lib/primitives/SessionEventCard.d.ts.map +1 -0
  121. package/dist/registry/lib/primitives/SessionEventCard.js +60 -0
  122. package/dist/registry/lib/primitives/SessionEventCard.js.map +1 -0
  123. package/dist/registry/lib/primitives/SessionEventTimeline.d.ts +13 -0
  124. package/dist/registry/lib/primitives/SessionEventTimeline.d.ts.map +1 -0
  125. package/dist/registry/lib/primitives/SessionEventTimeline.js +35 -0
  126. package/dist/registry/lib/primitives/SessionEventTimeline.js.map +1 -0
  127. package/dist/registry/lib/primitives/SessionMutationBar.d.ts +10 -0
  128. package/dist/registry/lib/primitives/SessionMutationBar.d.ts.map +1 -0
  129. package/dist/registry/lib/primitives/SessionMutationBar.js +37 -0
  130. package/dist/registry/lib/primitives/SessionMutationBar.js.map +1 -0
  131. package/dist/registry/lib/primitives/SessionTabbedDrawer.d.ts +19 -0
  132. package/dist/registry/lib/primitives/SessionTabbedDrawer.d.ts.map +1 -0
  133. package/dist/registry/lib/primitives/SessionTabbedDrawer.js +75 -0
  134. package/dist/registry/lib/primitives/SessionTabbedDrawer.js.map +1 -0
  135. package/dist/registry/lib/primitives/index.d.ts +5 -0
  136. package/dist/registry/lib/primitives/index.d.ts.map +1 -0
  137. package/dist/registry/lib/primitives/index.js +21 -0
  138. package/dist/registry/lib/primitives/index.js.map +1 -0
  139. package/dist/registry/lib/session-context-builder.d.ts +13 -0
  140. package/dist/registry/lib/session-context-builder.d.ts.map +1 -0
  141. package/dist/registry/lib/session-context-builder.js +39 -0
  142. package/dist/registry/lib/session-context-builder.js.map +1 -0
  143. package/dist/registry/lib/session-context-provider.d.ts +10 -0
  144. package/dist/registry/lib/session-context-provider.d.ts.map +1 -0
  145. package/dist/registry/lib/session-context-provider.js +24 -0
  146. package/dist/registry/lib/session-context-provider.js.map +1 -0
  147. package/dist/registry/lib/session-selectors.d.ts +9 -0
  148. package/dist/registry/lib/session-selectors.d.ts.map +1 -0
  149. package/dist/registry/lib/session-selectors.js +149 -0
  150. package/dist/registry/lib/session-selectors.js.map +1 -0
  151. package/dist/session/comments/CommentRail.d.ts +20 -0
  152. package/dist/session/comments/CommentRail.d.ts.map +1 -0
  153. package/dist/session/comments/CommentRail.js +16 -0
  154. package/dist/session/comments/CommentRail.js.map +1 -0
  155. package/dist/session/index.d.ts +4 -0
  156. package/dist/session/index.d.ts.map +1 -0
  157. package/dist/session/index.js +10 -0
  158. package/dist/session/index.js.map +1 -0
  159. package/dist/session/lib/cn.d.ts +3 -0
  160. package/dist/session/lib/cn.d.ts.map +1 -0
  161. package/dist/session/lib/cn.js +9 -0
  162. package/dist/session/lib/cn.js.map +1 -0
  163. package/dist/session/shell/SessionWorkspaceShell.d.ts +16 -0
  164. package/dist/session/shell/SessionWorkspaceShell.d.ts.map +1 -0
  165. package/dist/session/shell/SessionWorkspaceShell.js +15 -0
  166. package/dist/session/shell/SessionWorkspaceShell.js.map +1 -0
  167. package/package.json +84 -0
  168. package/src/index.ts +2 -0
  169. package/src/lib/biome-host/biome-mode.ts +6 -0
  170. package/src/lib/biome-host/biome-registry.ts +245 -0
  171. package/src/lib/biome-host/composition-validation.ts +215 -0
  172. package/src/lib/biome-host/frontend-biome.ts +162 -0
  173. package/src/lib/biome-host/host-bridge.ts +178 -0
  174. package/src/lib/biome-host/host-sources.ts +41 -0
  175. package/src/lib/biome-host/index.ts +23 -0
  176. package/src/lib/biome-host/nav.ts +83 -0
  177. package/src/lib/biome-host/session-contributions.ts +293 -0
  178. package/src/lib/biome-host/session-profiles.ts +99 -0
  179. package/src/lib/system-bus/capability-invoke.ts +92 -0
  180. package/src/lib/system-bus/deeplink.ts +200 -0
  181. package/src/lib/system-bus/enums.ts +86 -0
  182. package/src/lib/system-bus/host-ports.ts +96 -0
  183. package/src/lib/system-bus/index.ts +16 -0
  184. package/src/lib/system-bus/intent-registry.ts +106 -0
  185. package/src/lib/system-bus/intents.ts +109 -0
  186. package/src/lib/system-bus/palette.ts +77 -0
  187. package/src/lib/system-bus/system-bus-builder.ts +157 -0
  188. package/src/lib/system-bus/system-bus.ts +37 -0
  189. package/src/lib/system-bus/windows.ts +51 -0
  190. package/src/org-db/components/DbResultTable.tsx +143 -0
  191. package/src/org-db/index.ts +1 -0
  192. package/src/registry/index.ts +8 -0
  193. package/src/registry/lib/biome-slot.tsx +47 -0
  194. package/src/registry/lib/biomes-enabled-context.ts +20 -0
  195. package/src/registry/lib/composition-validation-host.ts +37 -0
  196. package/src/registry/lib/extension-points.ts +134 -0
  197. package/src/registry/lib/primitives/SessionEventCard.tsx +138 -0
  198. package/src/registry/lib/primitives/SessionEventTimeline.tsx +89 -0
  199. package/src/registry/lib/primitives/SessionMutationBar.tsx +76 -0
  200. package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +155 -0
  201. package/src/registry/lib/primitives/index.ts +18 -0
  202. package/src/registry/lib/session-context-builder.ts +68 -0
  203. package/src/registry/lib/session-context-provider.tsx +50 -0
  204. package/src/registry/lib/session-selectors.ts +231 -0
  205. package/src/session/comments/CommentRail.tsx +164 -0
  206. package/src/session/index.ts +3 -0
  207. package/src/session/lib/cn.ts +11 -0
  208. package/src/session/shell/SessionWorkspaceShell.tsx +141 -0
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Typed selector hooks the host session shell calls to read biome
3
+ * contributions for the current session. Each selector:
4
+ *
5
+ * 1. Walks `biomeRegistry.list()` once.
6
+ * 2. Filters by the contribution's `appliesTo` predicate against the
7
+ * current `SessionContext`.
8
+ * 3. Sorts deterministically (`weight`/`order`, then `id`).
9
+ * 4. Re-runs whenever the registry revision changes (biome add /
10
+ * remove) or the session context changes.
11
+ *
12
+ * Selectors return frozen arrays — consumers should not mutate them.
13
+ *
14
+ * Naming: each selector is named after the contribution surface
15
+ * (`useSessionSlashCommands`, `useSessionDrawerTabs`, …) so the call
16
+ * site reads as "give me all session X for this context".
17
+ */
18
+ import { useMemo } from 'react';
19
+
20
+ import {
21
+ type ActivityRendererContribution,
22
+ type AttachmentClassContribution,
23
+ type HeaderChipContribution,
24
+ type MutationBarContribution,
25
+ type SecondaryDrawerTabContribution,
26
+ type SessionActivityEvent,
27
+ type SessionContext,
28
+ type SessionToolCallEvent,
29
+ type SlashCommandContribution,
30
+ type ToolCallRendererContribution,
31
+ biomeRegistry,
32
+ useBiomeRegistryRevision,
33
+ } from '../../index';
34
+
35
+ function sortByWeight<
36
+ T extends { readonly id: string; readonly weight?: number; readonly order?: number },
37
+ >(items: readonly T[]): readonly T[] {
38
+ return [...items].sort((a, b) => {
39
+ const aw = a.weight ?? a.order ?? 100;
40
+ const bw = b.weight ?? b.order ?? 100;
41
+ if (aw !== bw) return aw - bw;
42
+ return a.id.localeCompare(b.id);
43
+ });
44
+ }
45
+
46
+ type PredicateOf<T> = T extends { readonly appliesTo?: (...args: infer A) => boolean }
47
+ ? (...args: A) => boolean
48
+ : never;
49
+
50
+ function applies<T extends { readonly appliesTo?: (...args: never[]) => boolean }>(
51
+ item: T,
52
+ args: Parameters<PredicateOf<T>>,
53
+ ): boolean {
54
+ const predicate = item.appliesTo as PredicateOf<T> | undefined;
55
+ return predicate == null ? true : predicate(...args);
56
+ }
57
+
58
+ // ── Slash commands ────────────────────────────────────────────────────
59
+
60
+ export function useSessionSlashCommands(
61
+ session: SessionContext,
62
+ ): readonly SlashCommandContribution[] {
63
+ const revision = useBiomeRegistryRevision();
64
+ return useMemo(() => {
65
+ const out: SlashCommandContribution[] = [];
66
+ for (const biome of biomeRegistry.list()) {
67
+ for (const cmd of biome.session?.slashCommands ?? []) {
68
+ if (!applies(cmd, [session])) continue;
69
+ out.push(cmd);
70
+ }
71
+ }
72
+ return Object.freeze(sortByWeight(out));
73
+ // eslint-disable-next-line react-hooks/exhaustive-deps
74
+ }, [revision, session]);
75
+ }
76
+
77
+ // ── Secondary drawer tabs ─────────────────────────────────────────────
78
+
79
+ export function useSessionDrawerTabs(
80
+ session: SessionContext,
81
+ ): readonly SecondaryDrawerTabContribution[] {
82
+ const revision = useBiomeRegistryRevision();
83
+ return useMemo(() => {
84
+ const out: SecondaryDrawerTabContribution[] = [];
85
+ for (const biome of biomeRegistry.list()) {
86
+ for (const tab of biome.session?.secondaryDrawerTabs ?? []) {
87
+ if (!applies(tab, [session])) continue;
88
+ out.push(tab);
89
+ }
90
+ }
91
+ return Object.freeze(sortByWeight(out));
92
+ // eslint-disable-next-line react-hooks/exhaustive-deps
93
+ }, [revision, session]);
94
+ }
95
+
96
+ // ── Activity renderers ────────────────────────────────────────────────
97
+
98
+ /**
99
+ * Hook returning the **first** activity renderer whose `entryKind`
100
+ * matches the event AND whose `appliesTo` predicate passes. Returns
101
+ * `null` if no biome handles this entry kind — the host then falls
102
+ * back to its generic renderer.
103
+ *
104
+ * Ties broken by `id` so biome authors can predict which renderer
105
+ * wins. To force a specific biome to win, use a lexicographically
106
+ * smaller id (e.g. `'00-debug/…'`).
107
+ */
108
+ export function useActivityRenderer(
109
+ session: SessionContext,
110
+ event: SessionActivityEvent,
111
+ ): ActivityRendererContribution | null {
112
+ const revision = useBiomeRegistryRevision();
113
+ return useMemo(() => {
114
+ const candidates: ActivityRendererContribution[] = [];
115
+ for (const biome of biomeRegistry.list()) {
116
+ for (const r of biome.session?.activityRenderers ?? []) {
117
+ if (r.entryKind !== event.kind) continue;
118
+ if (!applies(r, [{ session, event }])) continue;
119
+ candidates.push(r);
120
+ }
121
+ }
122
+ if (candidates.length === 0) return null;
123
+ return sortByWeight(candidates)[0] ?? null;
124
+ // eslint-disable-next-line react-hooks/exhaustive-deps
125
+ }, [revision, session, event]);
126
+ }
127
+
128
+ // ── Tool-call renderers ───────────────────────────────────────────────
129
+
130
+ type ToolMatch = 'exact' | 'glob' | 'none';
131
+
132
+ function matchToolName(toolName: string, eventName: string): ToolMatch {
133
+ if (toolName === eventName) return 'exact';
134
+ if (toolName.endsWith('.*') && eventName.startsWith(toolName.slice(0, -1))) return 'glob';
135
+ return 'none';
136
+ }
137
+
138
+ function collectToolCallCandidates(
139
+ session: SessionContext,
140
+ event: SessionToolCallEvent,
141
+ ): { exact: ToolCallRendererContribution[]; glob: ToolCallRendererContribution[] } {
142
+ const exact: ToolCallRendererContribution[] = [];
143
+ const glob: ToolCallRendererContribution[] = [];
144
+ for (const biome of biomeRegistry.list()) {
145
+ for (const r of biome.session?.toolCallRenderers ?? []) {
146
+ const match = matchToolName(r.toolName, event.name);
147
+ if (match === 'none') continue;
148
+ if (!applies(r, [{ session, event }])) continue;
149
+ if (match === 'exact') exact.push(r);
150
+ else glob.push(r);
151
+ }
152
+ }
153
+ return { exact, glob };
154
+ }
155
+
156
+ /**
157
+ * Tool-call renderer resolution. Exact `toolName` matches outrank glob
158
+ * (`'<prefix>.*'`) matches; ties broken by `weight`, then `id`. Returns
159
+ * `null` if no biome handles this tool — host falls back to its
160
+ * generic key-value renderer.
161
+ */
162
+ export function useToolCallRenderer(
163
+ session: SessionContext,
164
+ event: SessionToolCallEvent,
165
+ ): ToolCallRendererContribution | null {
166
+ const revision = useBiomeRegistryRevision();
167
+ return useMemo(() => {
168
+ const { exact, glob } = collectToolCallCandidates(session, event);
169
+ if (exact.length > 0) return sortByWeight(exact)[0] ?? null;
170
+ if (glob.length > 0) return sortByWeight(glob)[0] ?? null;
171
+ return null;
172
+ // eslint-disable-next-line react-hooks/exhaustive-deps
173
+ }, [revision, session, event]);
174
+ }
175
+
176
+ // ── Mutation bars ─────────────────────────────────────────────────────
177
+
178
+ export function useSessionMutationBars(
179
+ session: SessionContext,
180
+ ): readonly MutationBarContribution[] {
181
+ const revision = useBiomeRegistryRevision();
182
+ return useMemo(() => {
183
+ const out: MutationBarContribution[] = [];
184
+ for (const biome of biomeRegistry.list()) {
185
+ for (const bar of biome.session?.mutationBars ?? []) {
186
+ if (!applies(bar, [session])) continue;
187
+ out.push(bar);
188
+ }
189
+ }
190
+ return Object.freeze(sortByWeight(out));
191
+ // eslint-disable-next-line react-hooks/exhaustive-deps
192
+ }, [revision, session]);
193
+ }
194
+
195
+ // ── Header chips ──────────────────────────────────────────────────────
196
+
197
+ export function useSessionHeaderChips(
198
+ session: SessionContext,
199
+ ): readonly HeaderChipContribution[] {
200
+ const revision = useBiomeRegistryRevision();
201
+ return useMemo(() => {
202
+ const out: HeaderChipContribution[] = [];
203
+ for (const biome of biomeRegistry.list()) {
204
+ for (const chip of biome.session?.headerChips ?? []) {
205
+ if (!applies(chip, [session])) continue;
206
+ out.push(chip);
207
+ }
208
+ }
209
+ return Object.freeze(sortByWeight(out));
210
+ // eslint-disable-next-line react-hooks/exhaustive-deps
211
+ }, [revision, session]);
212
+ }
213
+
214
+ // ── Attachment classes ────────────────────────────────────────────────
215
+
216
+ export function useSessionAttachmentClasses(
217
+ session: SessionContext,
218
+ ): readonly AttachmentClassContribution[] {
219
+ const revision = useBiomeRegistryRevision();
220
+ return useMemo(() => {
221
+ const out: AttachmentClassContribution[] = [];
222
+ for (const biome of biomeRegistry.list()) {
223
+ for (const cls of biome.session?.attachmentClasses ?? []) {
224
+ if (!applies(cls, [session])) continue;
225
+ out.push(cls);
226
+ }
227
+ }
228
+ return Object.freeze(sortByWeight(out));
229
+ // eslint-disable-next-line react-hooks/exhaustive-deps
230
+ }, [revision, session]);
231
+ }
@@ -0,0 +1,164 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import { cn } from '../lib/cn';
4
+
5
+ /**
6
+ * Generic, data-layer-agnostic comment shape. Host surfaces map their
7
+ * own DTOs (KB `DocumentCommentResponseDto`, workflow `InquiryReply`,
8
+ * …) into this before handing the array to `CommentRail`.
9
+ */
10
+ export interface RailComment {
11
+ readonly id: string;
12
+ readonly body: string;
13
+ /** Anchored quote text shown above the body. Omit for whole-doc comments. */
14
+ readonly quotedText?: string;
15
+ /** `true` once the comment is resolved/closed. */
16
+ readonly resolved: boolean;
17
+ /** Optional author label (name / "Agent" / …). */
18
+ readonly authorLabel?: string;
19
+ }
20
+
21
+ /**
22
+ * Headless anchored-comment rail shared by every interactive-session
23
+ * surface (Document Buddy today; workflow review once `ReviewRail`
24
+ * migrates). It owns ONLY layout + rendering — no data fetching, no
25
+ * mutations. The host passes:
26
+ *
27
+ * • `comments` — already-mapped `RailComment[]`
28
+ * • `onResolve` — resolve callback (host owns the mutation)
29
+ * • `composerSlot` — the host's composer node (host owns its state)
30
+ * • `headerSlot` — optional extra header content
31
+ *
32
+ * Keeping it headless is what lets the same component render both KB
33
+ * document comments and workflow review threads without either data
34
+ * stack leaking into the package layer.
35
+ */
36
+ export function CommentRail({
37
+ comments,
38
+ title = 'Comments',
39
+ emptyHint,
40
+ composerSlot,
41
+ headerSlot,
42
+ onResolve,
43
+ resolvingId,
44
+ renderResolveIcon,
45
+ renderResolvedIcon,
46
+ }: {
47
+ readonly comments: readonly RailComment[];
48
+ readonly title?: string;
49
+ readonly emptyHint?: ReactNode;
50
+ readonly composerSlot?: ReactNode;
51
+ readonly headerSlot?: ReactNode;
52
+ readonly onResolve?: (id: string) => void;
53
+ readonly resolvingId?: string | null;
54
+ /** Host supplies the icon set so the package carries no icon dep. */
55
+ readonly renderResolveIcon?: (busy: boolean) => ReactNode;
56
+ readonly renderResolvedIcon?: () => ReactNode;
57
+ }) {
58
+ const open = comments.filter((c) => !c.resolved);
59
+ const resolved = comments.filter((c) => c.resolved);
60
+
61
+ return (
62
+ <div className="flex h-full min-h-0 flex-col gap-2 bg-paper p-3 text-[12px]">
63
+ <div className="flex items-center gap-2">
64
+ <span className="font-medium text-ink">{title}</span>
65
+ {open.length > 0 && (
66
+ <span className="rounded-full bg-ink/10 px-2 py-0.5 text-[11px] text-ink-2">
67
+ {open.length}
68
+ </span>
69
+ )}
70
+ {headerSlot}
71
+ </div>
72
+
73
+ {composerSlot}
74
+
75
+ {comments.length === 0 && !composerSlot && emptyHint && (
76
+ <div className="text-ink-3">{emptyHint}</div>
77
+ )}
78
+
79
+ <div className="flex min-h-0 flex-1 flex-col gap-2 overflow-auto pr-1">
80
+ {open.map((comment) => (
81
+ <CommentRow
82
+ key={comment.id}
83
+ comment={comment}
84
+ onResolve={onResolve}
85
+ busy={resolvingId === comment.id}
86
+ renderResolveIcon={renderResolveIcon}
87
+ renderResolvedIcon={renderResolvedIcon}
88
+ />
89
+ ))}
90
+ {resolved.length > 0 && (
91
+ <div className="mt-1 text-[11px] uppercase tracking-wide text-ink-3">
92
+ Resolved
93
+ </div>
94
+ )}
95
+ {resolved.map((comment) => (
96
+ <CommentRow
97
+ key={comment.id}
98
+ comment={comment}
99
+ onResolve={onResolve}
100
+ busy={resolvingId === comment.id}
101
+ renderResolveIcon={renderResolveIcon}
102
+ renderResolvedIcon={renderResolvedIcon}
103
+ />
104
+ ))}
105
+ </div>
106
+ </div>
107
+ );
108
+ }
109
+
110
+ function CommentRow({
111
+ comment,
112
+ onResolve,
113
+ busy,
114
+ renderResolveIcon,
115
+ renderResolvedIcon,
116
+ }: {
117
+ readonly comment: RailComment;
118
+ readonly onResolve?: ((id: string) => void) | undefined;
119
+ readonly busy: boolean;
120
+ readonly renderResolveIcon?: ((busy: boolean) => ReactNode) | undefined;
121
+ readonly renderResolvedIcon?: (() => ReactNode) | undefined;
122
+ }) {
123
+ return (
124
+ <div
125
+ className={cn(
126
+ 'rounded-md border p-2',
127
+ comment.resolved
128
+ ? 'border-rule/60 bg-paper-elev/30 opacity-70'
129
+ : 'border-rule/70 bg-paper-elev/40',
130
+ )}
131
+ >
132
+ {comment.quotedText && (
133
+ <div className="mb-1 border-l-2 border-[hsl(var(--comment-anchor))] pl-2 text-[11px] italic text-ink-3">
134
+ “{comment.quotedText.slice(0, 120)}
135
+ {comment.quotedText.length > 120 ? '…' : ''}”
136
+ </div>
137
+ )}
138
+ <div className="flex items-start justify-between gap-2">
139
+ <div className="flex flex-col gap-0.5">
140
+ {comment.authorLabel && (
141
+ <span className="text-[11px] font-medium text-ink-2">
142
+ {comment.authorLabel}
143
+ </span>
144
+ )}
145
+ <span className="whitespace-pre-wrap text-ink">{comment.body}</span>
146
+ </div>
147
+ {!comment.resolved && onResolve && (
148
+ <button
149
+ type="button"
150
+ title="Resolve"
151
+ disabled={busy}
152
+ onClick={() => onResolve(comment.id)}
153
+ className="flex h-6 w-6 shrink-0 items-center justify-center rounded text-ink-3 hover:bg-ink/5 hover:text-ink disabled:opacity-50"
154
+ >
155
+ {renderResolveIcon ? renderResolveIcon(busy) : busy ? '…' : '✓'}
156
+ </button>
157
+ )}
158
+ {comment.resolved && renderResolvedIcon && (
159
+ <span className="shrink-0 text-ink-3">{renderResolvedIcon()}</span>
160
+ )}
161
+ </div>
162
+ </div>
163
+ );
164
+ }
@@ -0,0 +1,3 @@
1
+ export { cn } from './lib/cn';
2
+ export { SessionWorkspaceShell } from './shell/SessionWorkspaceShell';
3
+ export { CommentRail, type RailComment } from './comments/CommentRail';
@@ -0,0 +1,11 @@
1
+ import { clsx, type ClassValue } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+
4
+ /**
5
+ * Tailwind-aware class merge. Local copy so this package stays
6
+ * self-contained (no `@/lib/utils` host import) — the host shell has
7
+ * its own identical `cn`, and the duplication is one trivial line.
8
+ */
9
+ export function cn(...inputs: ClassValue[]): string {
10
+ return twMerge(clsx(inputs));
11
+ }
@@ -0,0 +1,141 @@
1
+ import type { ReactNode, MouseEvent, RefObject } from 'react';
2
+
3
+ import { cn } from '../lib/cn';
4
+
5
+ interface SessionWorkspaceShellProps {
6
+ /**
7
+ * Container ref from `useHorizontalSplit`. The shell forwards mouse
8
+ * coordinates to the hook through this ref.
9
+ */
10
+ readonly splitContainerRef: RefObject<HTMLDivElement>;
11
+ /** Width of the left (chat) pane as a percentage 0-100. */
12
+ readonly chatPanePercent: number;
13
+ /** True while the resize handle is being dragged — applies cursor styling. */
14
+ readonly isResizing: boolean;
15
+ /** Mouse-down handler for the resize handle. */
16
+ readonly startResize: (event: MouseEvent<HTMLElement>) => void;
17
+
18
+ /** Mount for the Chat surface in the left pane. */
19
+ readonly chatSlot: ReactNode;
20
+ /**
21
+ * Mount for the right (preview) pane. Pass `null` for sessions that
22
+ * have no preview surface — the shell hides the right pane entirely
23
+ * (and the resize handle along with it) so chat takes the full
24
+ * width. Used by Document Buddy sessions, whose mechanic is a
25
+ * file-backed sync loop, not a previewed project.
26
+ */
27
+ readonly previewSlot: ReactNode;
28
+
29
+ /**
30
+ * Optional header strip at the top of the RIGHT pane. Used for
31
+ * preview-pane toolbars (KB references, attachments, actions menu).
32
+ */
33
+ readonly rightHeaderSlot?: ReactNode;
34
+
35
+ /**
36
+ * Optional content rendered *below* the chat surface, inside the left
37
+ * pane. Used for things like Brainstorming's `PendingCommentsBar`.
38
+ */
39
+ readonly chatFooterSlot?: ReactNode;
40
+
41
+ /**
42
+ * When true, the left pane and resize handle are hidden — the preview
43
+ * occupies the full width. Pages own this state.
44
+ */
45
+ readonly previewFullscreen?: boolean;
46
+
47
+ /** Optional override for the minimum left pane width (default 320px). */
48
+ readonly minLeftPaneWidth?: number;
49
+ }
50
+
51
+ /**
52
+ * Two-pane workspace layout shared by interactive session-like pages
53
+ * (sessions, design-system-builds, document buddy, …). The left pane renders
54
+ * the chat surface; the right pane always renders the preview slot.
55
+ *
56
+ * Auxiliary surfaces (Activity, Files, …) are no longer panes — they are
57
+ * surfaced through the floating `InspectorDock` and the right-pane
58
+ * overflow menu, so the shell stays a clean chat ⇄ preview split.
59
+ *
60
+ * Lives in `@xemahq/ui-kernel/session` so every session-like
61
+ * surface composes the identical layout. Biome extensibility lands
62
+ * inside the slot content (chat, preview) via the host's
63
+ * `HostExtensionSlots` SDK plumbing — the shell itself stays free of
64
+ * biome coupling.
65
+ */
66
+ export function SessionWorkspaceShell({
67
+ splitContainerRef,
68
+ chatPanePercent,
69
+ isResizing,
70
+ startResize,
71
+ chatSlot,
72
+ previewSlot,
73
+ rightHeaderSlot,
74
+ chatFooterSlot,
75
+ previewFullscreen = false,
76
+ minLeftPaneWidth = 320,
77
+ }: SessionWorkspaceShellProps) {
78
+ // `previewSlot === null` means the session declared no preview
79
+ // surface (Document Buddy). Hide the right pane + resize handle and
80
+ // let the chat pane occupy the full width.
81
+ const hasPreviewSlot = previewSlot !== null;
82
+ return (
83
+ <div
84
+ ref={splitContainerRef}
85
+ className={cn(
86
+ 'relative flex h-full w-full overflow-hidden',
87
+ isResizing && 'cursor-col-resize',
88
+ )}
89
+ >
90
+ {!previewFullscreen && (
91
+ <div
92
+ className={cn(
93
+ 'flex h-full w-full flex-col overflow-hidden bg-paper',
94
+ hasPreviewSlot ? 'lg:flex-none' : '',
95
+ )}
96
+ style={
97
+ hasPreviewSlot
98
+ ? {
99
+ minWidth: `${minLeftPaneWidth}px`,
100
+ width: `${chatPanePercent}%`,
101
+ }
102
+ : undefined
103
+ }
104
+ >
105
+ <div className="flex min-h-0 flex-1 flex-col overflow-hidden">
106
+ <div className="relative min-h-0 flex-1">{chatSlot}</div>
107
+ {chatFooterSlot}
108
+ </div>
109
+ </div>
110
+ )}
111
+
112
+ {!previewFullscreen && hasPreviewSlot && (
113
+ <div className="relative hidden w-px shrink-0 bg-rule/30 lg:block">
114
+ {/* Invisible 8px hot-environment for easier grabbing; visible divider
115
+ stays a single hair-line. On hover we tint only a 1px
116
+ accent column so the cursor change is the primary signal,
117
+ not a fat coloured strip. */}
118
+ <button
119
+ type="button"
120
+ onMouseDown={startResize}
121
+ aria-label="Resize chat and preview panels"
122
+ title="Drag to resize"
123
+ className="group absolute inset-y-0 left-1/2 w-2 -translate-x-1/2 cursor-col-resize"
124
+ >
125
+ <span
126
+ aria-hidden
127
+ className="absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-transparent transition-colors group-hover:bg-primary/40"
128
+ />
129
+ </button>
130
+ </div>
131
+ )}
132
+
133
+ {hasPreviewSlot && (
134
+ <div className="flex min-w-0 flex-1 flex-col overflow-hidden bg-paper">
135
+ {rightHeaderSlot}
136
+ <div className="min-h-0 flex-1 overflow-hidden">{previewSlot}</div>
137
+ </div>
138
+ )}
139
+ </div>
140
+ );
141
+ }