@kabmo-labs/kabmo 0.13.0 → 0.14.0

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 (133) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +319 -319
  3. package/dist/client/static/js/{index-vzb1qz51.js → index-nfsg1jpt.js} +779 -779
  4. package/dist/client/static/js/index-tsgy3gd1.css +1 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
  7. package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
  8. package/src/client/components/common/code-surface/extensions.ts +7 -1
  9. package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
  10. package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
  11. package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
  12. package/src/client/components/common/session-row/index.tsx +205 -0
  13. package/src/client/components/common/session-row/session-row.test.tsx +144 -0
  14. package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
  15. package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
  16. package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
  17. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
  18. package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
  19. package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
  20. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +55 -0
  21. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +184 -0
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
  23. package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
  24. package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
  25. package/src/client/components/mobile/SessionSidebar.tsx +137 -146
  26. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
  27. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
  28. package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
  29. package/src/client/components/settings/Modal.tsx +5 -27
  30. package/src/client/components/settings/Sidebar.tsx +1 -1
  31. package/src/client/components/settings/apply-side-effects.test.ts +102 -0
  32. package/src/client/components/settings/apply-side-effects.ts +90 -0
  33. package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
  34. package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
  35. package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
  36. package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
  37. package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
  38. package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
  39. package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
  40. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
  41. package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
  42. package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
  43. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
  44. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
  45. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  46. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +14 -5
  47. package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
  48. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
  49. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +108 -67
  50. package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
  51. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
  52. package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
  53. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +158 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
  55. package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
  56. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
  58. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
  59. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
  60. package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
  61. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
  62. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  63. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
  64. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
  65. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
  66. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
  67. package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
  68. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
  69. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
  70. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
  71. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
  73. package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
  80. package/src/client/components/workspace/diff-panel/folding.ts +6 -1
  81. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
  82. package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
  83. package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
  84. package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
  85. package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
  86. package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
  87. package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
  88. package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
  89. package/src/client/data/settings/omp-schema.json +151 -6
  90. package/src/client/hooks/chat/composer/style.ts +66 -0
  91. package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
  92. package/src/client/hooks/settings/providers/login.ts +11 -2
  93. package/src/client/hooks/ui/window-event.ts +20 -4
  94. package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
  95. package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
  96. package/src/client/hooks/workspace/batch-archive.ts +78 -0
  97. package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
  98. package/src/client/hooks/workspace/sidebar-style.ts +66 -0
  99. package/src/client/tailwind.css +111 -0
  100. package/src/server/index.ts +10 -134
  101. package/src/server/lib/lifecycle/after-listen.ts +178 -0
  102. package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
  103. package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
  104. package/src/server/lib/lifecycle/tls.test.ts +7 -7
  105. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
  106. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
  107. package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
  108. package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
  109. package/src/server/lib/plugins/background.server.ts +17 -1
  110. package/src/server/lib/plugins/background.test.ts +33 -0
  111. package/src/server/routes/sessions/batch-archive.test.ts +113 -0
  112. package/src/server/routes/sessions/batch-archive.ts +80 -0
  113. package/src/server/routes/sessions/index.ts +4 -0
  114. package/src/shared/lib/chat/composer/style.test.ts +126 -0
  115. package/src/shared/lib/chat/composer/style.ts +171 -0
  116. package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
  117. package/src/shared/lib/chat/composer/tui-only.ts +5 -0
  118. package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
  119. package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
  120. package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
  121. package/src/shared/lib/chat/timeline/trace-groups.test.ts +120 -0
  122. package/src/shared/lib/chat/timeline/trace-groups.ts +68 -0
  123. package/src/shared/lib/settings/defaults.ts +6 -0
  124. package/src/shared/lib/workspace/session-focus.test.ts +93 -0
  125. package/src/shared/lib/workspace/session-focus.ts +71 -0
  126. package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
  127. package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
  128. package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
  129. package/src/shared/lib/workspace/sidebar-style.ts +86 -0
  130. package/src/shared/types/omp/agent.ts +6 -0
  131. package/src/shared/types/settings/state.ts +31 -0
  132. package/dist/client/static/js/index-68w8h33q.css +0 -1
  133. package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  /**
7
- * The Usage panel, the model picker, and the composer's thinking-level rule.
7
+ * The Usage panel and the composer's thinking-level rule.
8
8
  *
9
9
  * - `format.ts` renders every number the panel shows. The boundaries are the
10
10
  * point: the compact-token thresholds sit exactly at 1_000/1_000_000/1_000_000_000,
@@ -14,9 +14,6 @@
14
14
  * fixed precedence (kenari plan → DeepSeek balance → quota window), and picks
15
15
  * the WORST used fraction — picking the first window instead shows a provider
16
16
  * at 3% while it is actually at 98%.
17
- * - `buildPickerGroups` keys its hover index on the composite `provider:id`, not
18
- * the bare id: the same model id is served by several providers, and an
19
- * id-only key highlighted every provider's row at once.
20
17
  * - `resolveThinkingLevel` must keep a session's level when the ladder is
21
18
  * unknown/empty, because an async catalog fetch resolving later used to reset
22
19
  * the user's chosen effort to a ladder default.
@@ -40,7 +37,6 @@ import {
40
37
  statusLabel,
41
38
  type ProviderEntry,
42
39
  } from '@/client/components/settings/categories/usage-settings/providers';
43
- import { buildPickerGroups } from '@/client/components/workspace/model-dropdown/groups';
44
40
  import {
45
41
  resolveThinkingLevel,
46
42
  selectionFor,
@@ -241,69 +237,6 @@ describe('buildProviders', () => {
241
237
  });
242
238
  });
243
239
 
244
- describe('buildPickerGroups', () => {
245
- const model = (provider: string, id: string, name: string, extra: Partial<AIModelOption> = {}): AIModelOption =>
246
- ({ id, name, provider, ...extra }) as AIModelOption;
247
-
248
- const catalog: AIModelOption[] = [
249
- model('deepseek', 'v4-flash', 'Flash', { contextWindow: 128000, capabilities: ['tools'] }),
250
- model('kenari', 'v4-flash', 'Flash (Kenari)', { contextWindow: 64000 }),
251
- model('openai', 'gpt-5', 'GPT-5'),
252
- ];
253
-
254
- test('a search filters on name, provider, context window and capability', () => {
255
- expect(buildPickerGroups(catalog, 'flash', {}, [], []).filtered).toHaveLength(2);
256
- expect(buildPickerGroups(catalog, 'OPENAI', {}, [], []).filtered.map((m) => m.id)).toEqual(['gpt-5']);
257
- expect(buildPickerGroups(catalog, '64000', {}, [], []).filtered.map((m) => m.provider)).toEqual(['kenari']);
258
- expect(buildPickerGroups(catalog, 'tools', {}, [], []).filtered.map((m) => m.provider)).toEqual(['deepseek']);
259
- expect(buildPickerGroups(catalog, ' ', {}, [], []).filtered).toHaveLength(3);
260
- });
261
-
262
- test('the rails follow the stored key order, not the catalog order', () => {
263
- const groups = buildPickerGroups(catalog, '', {}, ['openai:gpt-5', 'deepseek:v4-flash'], ['kenari:v4-flash', 'openai:gpt-5']);
264
- expect(groups.favorites.map((m) => m.id)).toEqual(['gpt-5', 'v4-flash']);
265
- expect(groups.recent.map((m) => m.provider)).toEqual(['kenari']);
266
- });
267
-
268
- test('the rails are narrowed by the search like every other section', () => {
269
- const groups = buildPickerGroups(catalog, 'flash', {}, ['openai:gpt-5', 'deepseek:v4-flash'], []);
270
- expect(groups.favorites.map((m) => m.provider)).toEqual(['deepseek']);
271
- });
272
-
273
- test('providers are grouped under upper-cased names in catalog order', () => {
274
- const groups = buildPickerGroups(catalog, '', {}, [], []);
275
- expect(Object.keys(groups.byProvider)).toEqual(['DEEPSEEK', 'KENARI', 'OPENAI']);
276
- expect(groups.byProvider.DEEPSEEK).toHaveLength(1);
277
- });
278
-
279
- test('the flat list renders rails first, then provider sections', () => {
280
- const groups = buildPickerGroups(catalog, '', {}, ['openai:gpt-5'], ['deepseek:v4-flash']);
281
- // A rail model is NOT removed from its provider section: the flat list is the
282
- // order the panel walks for hover/keyboard focus, and a model appearing once
283
- // under a rail and again under its provider is the shipped behavior.
284
- expect(groups.visibleFlatList.map((m) => `${m.provider}:${m.id}`)).toEqual([
285
- 'openai:gpt-5', // favorites rail
286
- 'deepseek:v4-flash', // recent rail
287
- 'deepseek:v4-flash', // DEEPSEEK section
288
- 'kenari:v4-flash', // KENARI section
289
- 'openai:gpt-5', // OPENAI section
290
- ]);
291
- });
292
-
293
- test('a collapsed section is dropped from the flat list but keeps its group', () => {
294
- const groups = buildPickerGroups(catalog, '', { favorites: true, KENARI: true }, ['openai:gpt-5'], []);
295
- expect(groups.visibleFlatList.map((m) => m.provider)).toEqual(['deepseek', 'openai']);
296
- expect(groups.byProvider.KENARI).toHaveLength(1);
297
- });
298
-
299
- test('the hover index is keyed by provider+id, so shared ids stay distinct', () => {
300
- const groups = buildPickerGroups(catalog, '', {}, [], []);
301
- expect(groups.index['deepseek:v4-flash']).toBe(0);
302
- expect(groups.index['kenari:v4-flash']).toBe(1);
303
- expect(groups.index['deepseek:v4-flash']).not.toBe(groups.index['kenari:v4-flash']);
304
- });
305
- });
306
-
307
240
  describe('resolveThinkingLevel', () => {
308
241
  test('a session level the model offers is authoritative', () => {
309
242
  expect(resolveThinkingLevel(['off', 'low', 'high'], 'high', 'low')).toBe('high');
@@ -59,6 +59,11 @@ interface ComposerDockProps {
59
59
  * scroll-to-bottom affordance.
60
60
  */
61
61
  shrinkWhileReading?: boolean;
62
+ /**
63
+ * The chat has no turns yet. Only the `stage` composer style reads it, and it
64
+ * only ever changes the card's frame — never which controls exist.
65
+ */
66
+ hero?: boolean;
62
67
  }
63
68
 
64
69
  /**
@@ -99,6 +104,7 @@ export function ComposerDock({
99
104
  sessionThinkingLevel,
100
105
  variant,
101
106
  shrinkWhileReading = false,
107
+ hero = false,
102
108
  }: ComposerDockProps) {
103
109
  // Side questions take over the composer entirely: the chat's own input is
104
110
  // hidden while the form is open, so a stray Enter cannot send to the wrong
@@ -167,6 +173,7 @@ export function ComposerDock({
167
173
  sessionThinkingLevel={sessionThinkingLevel}
168
174
  variant={variant}
169
175
  expandable
176
+ hero={hero}
170
177
  shrinkWhileReading={shrinkWhileReading}
171
178
  />
172
179
  )}
@@ -303,6 +303,9 @@ export function EmptyWorkspacePrompt({
303
303
  deferredComposerPickRef={deferredComposerPickRef}
304
304
  variant={variant}
305
305
  expandable
306
+ // A brand-new chat has no turns: the `stage` composer style draws its
307
+ // wider, taller card here and nowhere else.
308
+ hero={messages.length === 0}
306
309
  />
307
310
  </div>
308
311
  </div>
@@ -15,6 +15,8 @@ import { capitalizeFirstLetter } from '@/shared/lib/chat/capitalize';
15
15
  import { isNoticeRow, messageAnswerText } from '@/shared/lib/chat/notice-row';
16
16
  import { formatMessageStamp } from '@/shared/lib/format/time';
17
17
  import { transcriptBlockPadding, transcriptGutter } from '@/shared/lib/chat/timeline/gutter';
18
+ import { traceInset } from '@/shared/lib/chat/timeline/block-chrome';
19
+ import { useToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
18
20
 
19
21
  interface ChatMessageItemProps {
20
22
  msg: ChatMessageData | any;
@@ -182,6 +184,13 @@ export const ChatMessageItem = memo(function ChatMessageItem({
182
184
  const cleanIntent = msg.intent ? capitalizeFirstLetter(msg.intent.replace(/^[.\s]+/, '')) : null;
183
185
  const hasToolCalls = Boolean(allToolCalls && allToolCalls.length > 0);
184
186
 
187
+ // `trace` draws a rail in the run's left gutter; content that reserves nothing
188
+ // there would be struck through by it. The inset is the same fact as the
189
+ // rail's own column, so it lives beside `blockChrome` (`traceInset`).
190
+ const mode = useToolRenderMode();
191
+ const textInset = traceInset(mode, isMobile);
192
+ const boxInset = traceInset(mode, isMobile, true);
193
+
185
194
  return (
186
195
  <div
187
196
  id={msg.id}
@@ -207,7 +216,7 @@ export const ChatMessageItem = memo(function ChatMessageItem({
207
216
 
208
217
  {/* Provider / API Error Alert */}
209
218
  {msg.error && (
210
- <div className={`flex items-start space-x-2.5 bg-error/10 border border-error/30 rounded-lg ${transcriptGutter(isMobile)} px-3.5 py-2.5 text-[12px] text-ink select-text`}>
219
+ <div className={`flex items-start space-x-2.5 bg-error/10 border border-error/30 rounded-lg ${boxInset || transcriptGutter(isMobile)} px-3.5 py-2.5 text-[12px] text-ink select-text`}>
211
220
  <AlertCircle size={15} className="text-error flex-shrink-0 mt-0.5" />
212
221
  <div className="min-w-0 flex-1 space-y-0.5">
213
222
  <div className="flex items-center space-x-2 flex-wrap">
@@ -239,14 +248,14 @@ export const ChatMessageItem = memo(function ChatMessageItem({
239
248
 
240
249
  {/* Main AI Response Content (Rich Markdown with code blocks, tables, lists) rendered before tool calls */}
241
250
  {hasRenderableContent && (
242
- <div className="text-[13px] text-ink leading-relaxed font-sans bg-transparent px-3 py-1 select-text">
251
+ <div className={`text-[13px] text-ink leading-relaxed font-sans bg-transparent px-3 py-1 select-text ${textInset}`}>
243
252
  <MarkdownRenderer content={assistantContent} />
244
253
  </div>
245
254
  )}
246
255
 
247
256
  {/* Tool Call Intent (rendered standalone only when there are no tool calls to absorb it as title) */}
248
257
  {cleanIntent && !hasToolCalls && (!hasRenderableContent || !msg.content.toLowerCase().includes(msg.intent.toLowerCase().trim())) && (
249
- <div className={`leading-relaxed font-sans px-3 select-text ${
258
+ <div className={`leading-relaxed font-sans px-3 select-text ${textInset} ${
250
259
  hasRenderableContent
251
260
  ? 'text-[12px] text-ink/70 py-0.5'
252
261
  : 'text-[13px] text-ink py-1'
@@ -266,7 +275,7 @@ export const ChatMessageItem = memo(function ChatMessageItem({
266
275
 
267
276
  {/* Intermediate Diagnostic Note */}
268
277
  {msg.systemNote && (
269
- <div className="text-[12px] text-ink leading-relaxed border-l-2 border-ink/30 bg-paper/60 px-3 py-2 rounded-r-md font-mono break-words whitespace-pre-wrap select-text">
278
+ <div className={`text-[12px] text-ink leading-relaxed border-l-2 border-ink/30 bg-paper/60 px-3 py-2 rounded-r-md font-mono break-words whitespace-pre-wrap select-text ${boxInset}`}>
270
279
  <span className="text-[10px] text-ink/50 uppercase tracking-wider block mb-0.5 font-sans font-semibold">
271
280
  Diagnostic Note
272
281
  </span>
@@ -285,7 +294,7 @@ export const ChatMessageItem = memo(function ChatMessageItem({
285
294
 
286
295
  {/* AI Final Summary / Conclusion Card (Only shown when not streaming) */}
287
296
  {!isStreaming && msg.summary && (
288
- <div className="text-[12px] text-ink bg-paper border border-ink/15 rounded-lg p-3 space-y-1 select-text font-sans">
297
+ <div className={`text-[12px] text-ink bg-paper border border-ink/15 rounded-lg p-3 space-y-1 select-text font-sans ${boxInset}`}>
289
298
  <div className="font-semibold text-ink flex items-center space-x-1.5 text-[12px]">
290
299
  <span className="w-1.5 h-1.5 rounded-full bg-success" />
291
300
  <span>Resolution Summary</span>
@@ -1,10 +1,14 @@
1
+ import { Fragment } from 'preact';
1
2
  import { useMemo } from 'preact/hooks';
2
3
  import { memo } from 'preact/compat';
3
4
 
4
5
  import { ChatMessageItem } from '@/client/components/workspace/chat-timeline/MessageItem';
5
6
  import { RunFooter } from '@/client/components/workspace/chat-timeline/RunFooter';
7
+ import { TurnRail } from '@/client/components/workspace/chat-timeline/TurnRail';
8
+ import { useToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
6
9
  import { isNoticeRow } from '@/shared/lib/chat/notice-row';
7
10
  import { previousNonNoticeIndex, resolveRunFooters, streamingRowIndex } from '@/shared/lib/chat/timeline/run-footer';
11
+ import { groupTraceRows } from '@/shared/lib/chat/timeline/trace-groups';
8
12
  import type { TimelineRowWindow } from '@/client/hooks/chat/timeline/row-window';
9
13
  import type { Attachment, ChatMessageData } from '@/shared/types';
10
14
 
@@ -81,6 +85,16 @@ export const MessageList = memo(function MessageList({
81
85
  const start = rowWindow ? rowWindow.start : 0;
82
86
  const end = rowWindow ? Math.min(rowWindow.end, messages.length) : messages.length;
83
87
  const visible = start === 0 && end === messages.length ? messages : messages.slice(start, end);
88
+ const mode = useToolRenderMode();
89
+
90
+ // A `trace` rail belongs to the RUN, not to a row and not to one message.
91
+ // omp writes a turn as several rows (thinking + tools, then a notice, then the
92
+ // answer), so a per-row segment broke at every row boundary and a per-message
93
+ // one broke wherever a notice sat in its own row — measured in the browser as
94
+ // three disconnected segments with gaps of 256px and 99px. The rows of one run
95
+ // are therefore grouped under a single `relative` container that draws one
96
+ // line, and each block inside only places its node.
97
+ const groups = useMemo(() => groupTraceRows(messages, start, start + visible.length), [messages, start, visible.length]);
84
98
 
85
99
  return (
86
100
  <>
@@ -88,48 +102,83 @@ export const MessageList = memo(function MessageList({
88
102
  geometry read in `scroll.ts` still see the whole session's height,
89
103
  while only the rows around the viewport are DOM. */}
90
104
  {start > 0 && <div data-timeline-spacer="top" aria-hidden="true" style={{ height: rowWindow?.padTop ?? 0 }} />}
91
- {visible.map((msg, offset) => {
92
- const idx = start + offset;
93
- const prev = messages[idx - 1];
94
- const isLoading = isGenerating && idx === streamingIdx && msg.role === 'ai';
95
- const isAiFragment = msg.role !== 'user' && prev && prev.role !== 'user' && !isNoticeRow(prev);
96
- const prevRealIdx = prevNonNoticeIdx[idx];
97
- const prevReal = prevRealIdx >= 0 ? messages[prevRealIdx] : null;
98
- const isPrevAssistant = Boolean(msg.role !== 'user' && prevReal && prevReal.role !== 'user');
99
- const footer = footers[idx];
105
+ {groups.map((group) => {
106
+ // The run footer belongs to the run but NOT to its trace: it is a model
107
+ // and duration stamp, not a step. Left inside the rail container it drew
108
+ // the line 58px past the last node (measured), so it renders after the
109
+ // grouped rows instead.
110
+ const lastIdx = group.rows[group.rows.length - 1];
111
+ const trailingFooter = footers[lastIdx];
100
112
  return (
101
- // `flow-root` contains the row's own margins, so the measured height
102
- // is the row PLUS the gap it draws — a plain wrapper would let the
103
- // margin collapse out and the layout would sit a few px short per row.
104
- <div key={msg.id} data-row-id={msg.id} style={{ display: 'flow-root' }}>
105
- <ChatMessageItem
106
- msg={msg}
107
- isStreaming={isLoading}
108
- onUndo={onUndo}
109
- onNewChat={onNewChat}
110
- isPrevAssistant={isPrevAssistant}
111
- userActions={userActions}
112
- isMobile={isMobile}
113
- className={isNoticeRow(msg) ? 'mt-3 mb-1' : isAiFragment ? 'mt-1' : 'mt-3'}
114
- />
115
- {footer && (
116
- <RunFooter
117
- msg={footer.msg}
118
- provider={provider}
119
- providerNames={providerNames}
120
- modelName={modelName}
121
- modelNames={modelNames}
122
- thinkingLevel={thinkingLevel}
123
- durationMs={footer.durationMs}
124
- answerText={footer.answerText}
125
- retryTargetId={footer.runUserId}
126
- onRetry={onRetry}
127
- onNewChat={onNewChat}
128
- isMobile={isMobile}
129
- showActions={userActions}
130
- />
131
- )}
132
- </div>
113
+ <Fragment key={group.key}>
114
+ <div className={group.trace ? 'relative' : undefined} data-trace-group={group.trace || undefined}>
115
+ {group.trace && <TurnRail visible={mode === 'trace'} isMobile={isMobile} />}
116
+ {group.rows.map((idx) => {
117
+ const msg = messages[idx];
118
+ const prev = messages[idx - 1];
119
+ const isLoading = isGenerating && idx === streamingIdx && msg.role === 'ai';
120
+ const isAiFragment = msg.role !== 'user' && prev && prev.role !== 'user' && !isNoticeRow(prev);
121
+ const prevRealIdx = prevNonNoticeIdx[idx];
122
+ const prevReal = prevRealIdx >= 0 ? messages[prevRealIdx] : null;
123
+ const isPrevAssistant = Boolean(msg.role !== 'user' && prevReal && prevReal.role !== 'user');
124
+ const footer = footers[idx];
125
+ // A footer that is NOT the group's trailing one still renders in
126
+ // place — it closes an earlier run's row and the rail already ended.
127
+ const inlineFooter = footer && idx !== lastIdx ? footer : null;
128
+ return (
129
+ // `flow-root` contains the row's own margins, so the measured height
130
+ // is the row PLUS the gap it draws — a plain wrapper would let the
131
+ // margin collapse out and the layout would sit a few px short per row.
132
+ <div key={msg.id} data-row-id={msg.id} style={{ display: 'flow-root' }}>
133
+ <ChatMessageItem
134
+ msg={msg}
135
+ isStreaming={isLoading}
136
+ onUndo={onUndo}
137
+ onNewChat={onNewChat}
138
+ isPrevAssistant={isPrevAssistant}
139
+ userActions={userActions}
140
+ isMobile={isMobile}
141
+ className={isNoticeRow(msg) ? 'mt-3 mb-1' : isAiFragment ? 'mt-1' : 'mt-3'}
142
+ />
143
+ {inlineFooter && (
144
+ <RunFooter
145
+ msg={inlineFooter.msg}
146
+ provider={provider}
147
+ providerNames={providerNames}
148
+ modelName={modelName}
149
+ modelNames={modelNames}
150
+ thinkingLevel={thinkingLevel}
151
+ durationMs={inlineFooter.durationMs}
152
+ answerText={inlineFooter.answerText}
153
+ retryTargetId={inlineFooter.runUserId}
154
+ onRetry={onRetry}
155
+ onNewChat={onNewChat}
156
+ isMobile={isMobile}
157
+ showActions={userActions}
158
+ />
159
+ )}
160
+ </div>
161
+ );
162
+ })}
163
+ </div>
164
+ {trailingFooter && (
165
+ <RunFooter
166
+ msg={trailingFooter.msg}
167
+ provider={provider}
168
+ providerNames={providerNames}
169
+ modelName={modelName}
170
+ modelNames={modelNames}
171
+ thinkingLevel={thinkingLevel}
172
+ durationMs={trailingFooter.durationMs}
173
+ answerText={trailingFooter.answerText}
174
+ retryTargetId={trailingFooter.runUserId}
175
+ onRetry={onRetry}
176
+ onNewChat={onNewChat}
177
+ isMobile={isMobile}
178
+ showActions={userActions}
179
+ />
180
+ )}
181
+ </Fragment>
133
182
  );
134
183
  })}
135
184
  {end < messages.length && <div data-timeline-spacer="bottom" aria-hidden="true" style={{ height: rowWindow?.padBottom ?? 0 }} />}
@@ -10,6 +10,8 @@ import { GoalNotice } from '@/client/components/workspace/chat-timeline/GoalNoti
10
10
  import { TaskResultContent } from '@/client/components/workspace/chat-timeline/TaskResultContent';
11
11
  import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
12
12
  import { transcriptGutter } from '@/shared/lib/chat/timeline/gutter';
13
+ import { blockChrome } from '@/shared/lib/chat/timeline/block-chrome';
14
+ import { useToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
13
15
 
14
16
  const KIND_LABEL: Record<GoalNoticeData['kind'], string> = {
15
17
  start: 'Goal started',
@@ -51,6 +53,8 @@ interface SystemNoticeProps {
51
53
  * jobs, and <system-reminder> blocks, all collapsed by default; a goal-mode
52
54
  * injection renders open and has no collapse control (see `forcedOpen`). */
53
55
  export function SystemNotice({ notice, source, isMobile = false }: SystemNoticeProps) {
56
+ const mode = useToolRenderMode();
57
+ const chrome = blockChrome(mode);
54
58
  const [userOpen, setUserOpen] = useState(false);
55
59
 
56
60
  // 1. Check if notice contains a structured <task-result> block
@@ -203,20 +207,22 @@ export function SystemNotice({ notice, source, isMobile = false }: SystemNoticeP
203
207
 
204
208
  return (
205
209
  <div
206
- className={`${transcriptGutter(isMobile)} overflow-hidden rounded-xl border border-ink/10 bg-paper text-[12px] text-ink transition-colors ${
207
- canToggle ? 'hover:border-ink/20' : ''
208
- } select-text`}
210
+ className={`${transcriptGutter(isMobile)} text-[12px] text-ink select-text ${chrome.root}`}
209
211
  >
212
+ {/* The rail is drawn once per TURN by `TurnRail`; this block only places
213
+ its node. A segment per block broke wherever prose sat between two. */}
214
+ {mode === 'trace' && <span aria-hidden="true" className={chrome.node} />}
215
+ <div className={chrome.frame || undefined}>
210
216
  <button
211
217
  type="button"
212
218
  onClick={handleToggle}
213
219
  disabled={!canToggle}
214
220
  aria-expanded={canToggle ? isOpen : undefined}
215
- className={`flex w-full items-center gap-2.5 px-3 py-2.5 text-left transition-colors ${
221
+ className={`${chrome.header} ${
216
222
  canToggle ? 'cursor-pointer hover:bg-ink/[0.03]' : 'cursor-default'
217
223
  } focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ink/20`}
218
224
  >
219
- <span className={`flex h-7 w-7 shrink-0 items-center justify-center rounded-lg ${noticeStyle.badgeClass}`}>
225
+ <span className={`${chrome.icon} ${noticeStyle.badgeClass}`}>
220
226
  {noticeStyle.icon}
221
227
  </span>
222
228
  <span className="flex min-w-0 flex-1 flex-col">
@@ -276,7 +282,7 @@ export function SystemNotice({ notice, source, isMobile = false }: SystemNoticeP
276
282
  </button>
277
283
 
278
284
  {(forcedOpen || (isOpen && isExpandable)) && (
279
- <div className="border-t border-ink/8 bg-canvas/40 px-3.5 py-2.5">
285
+ <div className={chrome.body}>
280
286
  {taskNotice ? (
281
287
  <TaskResultContent task={taskNotice} />
282
288
  ) : goalNotice ? (
@@ -299,6 +305,7 @@ export function SystemNotice({ notice, source, isMobile = false }: SystemNoticeP
299
305
  )}
300
306
  </div>
301
307
  )}
308
+ </div>
302
309
  </div>
303
310
  );
304
311
  }
@@ -1,9 +1,36 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The thinking accordion, drawn in the same style as the tool rows around it.
8
+ *
9
+ * It used to spell the tool card's frame out itself, so `toolRenderStyle`
10
+ * reached the tool blocks and left thinking sitting in the old card — a setting
11
+ * that half applied. The frame, the header row and the body container now come
12
+ * from `blockChrome` (`shared/lib/chat/timeline/block-chrome.ts`), the one
13
+ * place that states them per style.
14
+ *
15
+ * What is NOT shared, deliberately: this block's own rules. A generating run
16
+ * opens itself, the body follows the tail while it streams, and a notice
17
+ * embedded in the thought renders as its own inset — behaviour that belongs to
18
+ * thinking and to nothing else.
19
+ *
20
+ * The toggle carries `aria-expanded` and no `aria-label`, as it always has:
21
+ * `chat.e2e.ts` collects `[aria-label^="Expand "]` and requires every entry to
22
+ * name a TOOL, so a second block spelling its control that way would be read as
23
+ * a tool card with a title of "Thinking".
24
+ */
25
+
1
26
  import { useEffect, useRef, useState } from 'preact/hooks';
2
27
  import { BrainCircuit, ChevronDown, Sparkles } from 'lucide-preact';
3
28
  import type { ThinkingData } from '@/shared/types';
4
29
  import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
5
30
  import { CopyButton } from '@/client/components/common/CopyButton';
6
31
  import { transcriptGutter } from '@/shared/lib/chat/timeline/gutter';
32
+ import { blockChrome, traceInset } from '@/shared/lib/chat/timeline/block-chrome';
33
+ import { useToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
7
34
 
8
35
  interface ThinkingSectionProps {
9
36
  thinking: ThinkingData | string;
@@ -13,12 +40,16 @@ interface ThinkingSectionProps {
13
40
  isMobile?: boolean;
14
41
  }
15
42
 
16
- export function ThinkingSection({
17
- thinking,
43
+ export function ThinkingSection({
44
+ thinking,
18
45
  defaultExpanded = false,
19
46
  showSeparator = false,
20
47
  isMobile = false,
21
48
  }: ThinkingSectionProps) {
49
+ const mode = useToolRenderMode();
50
+ const chrome = blockChrome(mode);
51
+ const framed = mode === 'card';
52
+
22
53
  const isGenerating = typeof thinking === 'object' ? Boolean(thinking.isGenerating) : false;
23
54
  const [isOpen, setIsOpen] = useState(defaultExpanded || isGenerating);
24
55
  const thoughtBodyRef = useRef<HTMLDivElement>(null);
@@ -46,88 +77,98 @@ export function ThinkingSection({
46
77
 
47
78
  if (!cleanThought) return null;
48
79
 
80
+ const iconTone = framed ? 'bg-ink/5 text-ink/70' : 'text-ink/40';
81
+
49
82
  return (
50
83
  <div className={`${transcriptGutter(isMobile)} ${showSeparator ? 'space-y-1.5' : ''}`}>
51
84
  {showSeparator && (
52
- <div className="flex items-center gap-2 px-1 pt-0.5">
85
+ <div className={`flex items-center gap-2 px-1 pt-0.5 ${traceInset(mode, isMobile)}`}>
53
86
  <span className="text-[9.5px] font-semibold uppercase tracking-[0.14em] text-ink/35">
54
87
  Thinking
55
88
  </span>
56
89
  <span className="h-px flex-1 bg-ink/8" />
57
90
  </div>
58
91
  )}
59
- <div className="overflow-hidden rounded-xl border border-ink/10 bg-paper transition-colors hover:border-ink/20">
60
- <button
61
- type="button"
62
- onClick={toggleOpen}
63
- className="flex w-full items-center gap-2.5 px-3 py-2.5 text-left transition-colors hover:bg-ink/[0.03] cursor-pointer select-none"
64
- aria-expanded={isOpen}
65
- >
66
- <span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-ink/5 text-ink/70">
67
- <Sparkles size={13} />
68
- </span>
69
- <span className="flex min-w-0 flex-1 flex-col">
70
- <span className="flex items-center gap-1.5">
71
- <span className="text-[12px] font-semibold tracking-tight text-ink">Thinking</span>
72
- {isGenerating && <span className="h-1.5 w-1.5 rounded-full bg-ink/60 animate-pulse" />}
73
- </span>
74
- {!isOpen && summary && (
75
- <span className="truncate font-mono text-[10.5px] text-ink/45">{summary}</span>
76
- )}
77
- </span>
78
- {duration && (
79
- <span className="shrink-0 rounded-full bg-ink/5 px-2 py-0.5 font-mono text-[10px] text-ink/50">
80
- {duration}
81
- </span>
82
- )}
83
- <ChevronDown
84
- size={14}
85
- className={`shrink-0 text-ink/35 transition-transform duration-200 ${isOpen ? 'rotate-180' : ''}`}
86
- />
87
- </button>
88
-
89
- {isOpen && (
90
- <div className="border-t border-ink/8 bg-canvas/40 px-3 py-3">
91
- <div className="flex items-center justify-between pb-1.5">
92
- <span className="text-[9.5px] font-semibold uppercase tracking-[0.14em] text-ink/40">
93
- Model Reasoning & Strategy
92
+ <div className={chrome.root || undefined}>
93
+ {/* The rail is drawn once per TURN by `TurnRail`; this block only places
94
+ its node. `trace` is the one style with a node. */}
95
+ {mode === 'trace' && <span aria-hidden="true" className={chrome.node} />}
96
+ <div className={chrome.frame || undefined}>
97
+ <button
98
+ type="button"
99
+ onClick={toggleOpen}
100
+ aria-expanded={isOpen}
101
+ className={`${chrome.header} cursor-pointer select-none ${
102
+ framed ? 'hover:bg-ink/[0.03]' : 'hover:bg-ink/[0.03] rounded-md'
103
+ } focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ink/20`}
104
+ >
105
+ <span className={`${chrome.icon} ${iconTone}`}>
106
+ <Sparkles size={13} />
107
+ </span>
108
+ <span className="flex min-w-0 flex-1 items-center gap-1.5">
109
+ <span className={chrome.title}>Thinking</span>
110
+ {isGenerating && <span className="h-1.5 w-1.5 rounded-full bg-ink/60 animate-pulse" />}
111
+ {!isOpen && (
112
+ <>
113
+ {!framed && <span className="text-ink/25">—</span>}
114
+ <span className={`${chrome.subtitle} ${framed ? '' : 'flex-1'}`}>{summary}</span>
115
+ </>
116
+ )}
94
117
  </span>
95
- <CopyButton
96
- text={cleanThought}
97
- className="flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] text-ink/45 transition-colors hover:bg-ink/5 hover:text-ink"
98
- title="Copy thinking"
99
- wrapLabel
100
- label="Copy"
118
+ {duration && (
119
+ <span className="shrink-0 rounded-full bg-ink/5 px-2 py-0.5 font-mono text-[10px] text-ink/50">
120
+ {duration}
121
+ </span>
122
+ )}
123
+ <ChevronDown
124
+ size={14}
125
+ className={`shrink-0 text-ink/35 transition-transform duration-200 ${isOpen ? 'rotate-180' : ''}`}
101
126
  />
102
- </div>
127
+ </button>
103
128
 
104
- {noticeText && (
105
- <div className="mb-2 flex items-start gap-2.5 rounded-lg border border-ink/15 bg-paper px-3 py-2.5">
106
- <span className="mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-ink/10">
107
- <BrainCircuit size={13} className="text-ink/70" />
108
- </span>
109
- <div className="min-w-0 flex-1">
110
- <div className="mb-0.5 text-[9.5px] font-semibold uppercase tracking-[0.12em] text-ink/50">
111
- System Notice
112
- </div>
113
- <div className="text-[12px] leading-relaxed text-ink/85">
114
- <MarkdownRenderer content={noticeText} className="text-[12px] text-ink/85 leading-relaxed" />
129
+ {isOpen && (
130
+ <div className={chrome.body}>
131
+ <div className="flex items-center justify-between pb-1.5">
132
+ <span className="text-[9.5px] font-semibold uppercase tracking-[0.14em] text-ink/40">
133
+ Model Reasoning & Strategy
134
+ </span>
135
+ <CopyButton
136
+ text={cleanThought}
137
+ className="flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] text-ink/45 transition-colors hover:bg-ink/5 hover:text-ink"
138
+ title="Copy thinking"
139
+ wrapLabel
140
+ label="Copy"
141
+ />
142
+ </div>
143
+
144
+ {noticeText && (
145
+ <div className="mb-2 flex items-start gap-2.5 rounded-lg border border-ink/15 bg-paper px-3 py-2.5">
146
+ <span className="mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-ink/10">
147
+ <BrainCircuit size={13} className="text-ink/70" />
148
+ </span>
149
+ <div className="min-w-0 flex-1">
150
+ <div className="mb-0.5 text-[9.5px] font-semibold uppercase tracking-[0.12em] text-ink/50">
151
+ System Notice
152
+ </div>
153
+ <div className="text-[12px] leading-relaxed text-ink/85">
154
+ <MarkdownRenderer content={noticeText} className="text-[12px] text-ink/85 leading-relaxed" />
155
+ </div>
156
+ </div>
115
157
  </div>
158
+ )}
159
+
160
+ <div
161
+ ref={thoughtBodyRef}
162
+ className="max-h-72 overflow-auto border-l-2 border-ink/15 py-1 pl-3 text-ink/80 scrollbar-overlay-container select-text"
163
+ >
164
+ <MarkdownRenderer
165
+ content={cleanThought}
166
+ className="text-[12px] leading-relaxed text-ink/85 [&_.code-block]:my-2 [&_p]:my-1.5 [&_ul]:my-1.5 [&_ol]:my-1.5"
167
+ />
116
168
  </div>
117
169
  </div>
118
170
  )}
119
-
120
- <div
121
- ref={thoughtBodyRef}
122
- className="max-h-72 overflow-auto border-l-2 border-ink/15 py-1 pl-3 text-ink/80 scrollbar-overlay-container select-text"
123
- >
124
- <MarkdownRenderer
125
- content={cleanThought}
126
- className="text-[12px] leading-relaxed text-ink/85 [&_.code-block]:my-2 [&_p]:my-1.5 [&_ul]:my-1.5 [&_ol]:my-1.5"
127
- />
128
- </div>
129
171
  </div>
130
- )}
131
172
  </div>
132
173
  </div>
133
174
  );