@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
@@ -22,12 +22,13 @@
22
22
  * section's children are only headings and cards.
23
23
  */
24
24
 
25
- import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
25
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
26
26
  import { Window } from 'happy-dom';
27
27
  import { h, render } from 'preact';
28
28
  import { act } from 'preact/test-utils';
29
29
  import { ToolCallingSection } from '@/client/components/workspace/chat-timeline/ToolCallingSection';
30
30
  import { SessionStateProvider } from '@/client/components/common/session-state-provider';
31
+ import { primeKabmoSettings } from '@/shared/lib/settings/client';
31
32
  import type { ToolCallData } from '@/shared/types/chat';
32
33
 
33
34
  const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'Event', 'MouseEvent', 'KeyboardEvent'] as const;
@@ -51,6 +52,19 @@ afterAll(() => {
51
52
  }
52
53
  });
53
54
 
55
+ /**
56
+ * The `card` style, pinned.
57
+ *
58
+ * The style is read from Kabmo's settings snapshot, which is PROCESS-wide and
59
+ * primed by whichever file ran last — `styles.test.tsx` leaves `trace` behind.
60
+ * Bun's file order differs per platform, so an unpinned run drew whatever the
61
+ * previous file had chosen: measured, this file passed on macOS and its three
62
+ * order assertions failed on Windows with the card rows missing entirely.
63
+ */
64
+ beforeEach(() => {
65
+ primeKabmoSettings({ kabmo_settings: { toolRenderStyle: 'card' } });
66
+ });
67
+
54
68
  function tool(id: string, intent: string | undefined, title = 'Bash'): ToolCallData {
55
69
  return { id, type: 'bash', name: 'bash', title, intent, status: 'success', output: 'ok' } as ToolCallData;
56
70
  }
@@ -73,17 +87,23 @@ async function mount(tools: ToolCallData[]) {
73
87
  /**
74
88
  * The section's direct children in render order: intent headings and their
75
89
  * cards. A section renders nothing else.
90
+ *
91
+ * A card is found by `data-tool-row`, the contract every style sets, not by a
92
+ * substring of its Tailwind classes. The class form was measured failing on
93
+ * Windows: the same three assertions reported `Received: 0` cards, with the
94
+ * heading text still present, and the class string it looked for is assembled
95
+ * from a template that platform does not change — so the lookup was the
96
+ * fragile part, not the render.
76
97
  */
77
98
  function sequence(el: HTMLElement): Array<{ kind: 'heading' | 'card'; text: string }> {
78
99
  const section = el.querySelector('[data-tool-section]')!;
79
100
  const items = Array.from(section.children).map((child) => {
80
- const cls = (child.className || '').toString();
81
- if (cls.includes('overflow-hidden rounded-xl')) {
82
- const col = child.querySelector('button')!.children[1];
83
- return { kind: 'card' as const, text: (col.children[0]?.textContent || '').trim() };
101
+ if (!(child instanceof HTMLElement) || !child.hasAttribute('data-tool-row')) {
102
+ const label = child.querySelector('span');
103
+ return { kind: 'heading' as const, text: label ? (label.textContent || '').trim() : '' };
84
104
  }
85
- const label = child.querySelector('span');
86
- return { kind: 'heading' as const, text: label ? (label.textContent || '').trim() : '' };
105
+ const col = child.querySelector('button')!.children[1];
106
+ return { kind: 'card' as const, text: (col.children[0]?.textContent || '').trim() };
87
107
  });
88
108
  return items.filter((item) => item.kind !== 'heading' || item.text);
89
109
  }
@@ -111,7 +131,7 @@ describe('ToolCallingSection per-card intent heading', () => {
111
131
  // No header row: every direct child is a card.
112
132
  const children = Array.from(el.querySelector('[data-tool-section]')!.children) as HTMLElement[];
113
133
  expect(children).toHaveLength(2);
114
- expect(children.every((child) => child.className.includes('overflow-hidden rounded-xl'))).toBe(true);
134
+ expect(children.every((child) => child.getAttribute('data-tool-row') === 'card')).toBe(true);
115
135
  });
116
136
 
117
137
  test('a card without an intent simply has no heading', async () => {
@@ -3,12 +3,37 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
+ /**
7
+ * A block of tool calls in the transcript, drawn in the style the user chose.
8
+ *
9
+ * The section owns three things and delegates the rest:
10
+ *
11
+ * 1. **Normalization** — the MOCK/sample path carries `AgentActionData`, which
12
+ * is mapped onto `ToolCallData` so every style reads one shape.
13
+ * 2. **Openness** — persisted per session by `useToolOpenState`, so a reload or
14
+ * a history page-in does not close the call the reader opened.
15
+ * 3. **The intent heading** — one line above a call, naming what the call was
16
+ * for. It is drawn by the section, not by a style, so the four styles cannot
17
+ * disagree about it.
18
+ *
19
+ * The STYLE decides the frame: `card` draws `CardRow`, `compact` a status line,
20
+ * `trace` a rail node, `minimal` a faint line. Every style receives the same
21
+ * tool and the same openness, and each renders the shared `ToolBody`.
22
+ */
23
+
6
24
  import { Fragment } from 'preact';
7
25
  import { useMemo } from 'preact/hooks';
26
+ import type { FunctionComponent } from 'preact/compat';
8
27
  import type { AgentActionData, ToolCallData, ToolType } from '@/shared/types';
9
- import { ToolCallCard } from '@/client/components/workspace/chat-timeline/ToolCallCard';
10
28
  import { useToolOpenState } from '@/client/hooks/chat/timeline/tool-open';
29
+ import { useToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
11
30
  import { transcriptGutter } from '@/shared/lib/chat/timeline/gutter';
31
+ import type { ToolRenderMode } from '@/shared/lib/chat/timeline/tool-render-mode';
32
+ import { CardRow } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/Card';
33
+ import { CompactRow } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/Compact';
34
+ import { TraceRow } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/Trace';
35
+ import { MinimalRow } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal';
36
+ import type { ToolRowProps } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/props';
12
37
 
13
38
  interface ToolCallingSectionProps {
14
39
  tools: (ToolCallData | AgentActionData)[];
@@ -17,6 +42,14 @@ interface ToolCallingSectionProps {
17
42
  isMobile?: boolean;
18
43
  }
19
44
 
45
+ /** One renderer per mode — a total map, so a new mode is a build error here. */
46
+ const ROW_BY_MODE: Record<ToolRenderMode, FunctionComponent<ToolRowProps>> = {
47
+ card: CardRow,
48
+ compact: CompactRow,
49
+ trace: TraceRow,
50
+ minimal: MinimalRow,
51
+ };
52
+
20
53
  function normalizeToolData(action: ToolCallData | AgentActionData, index: number): ToolCallData {
21
54
  if ('id' in action && action.id) {
22
55
  return action as ToolCallData;
@@ -57,6 +90,9 @@ function normalizeToolData(action: ToolCallData | AgentActionData, index: number
57
90
  }
58
91
 
59
92
  export function ToolCallingSection({ tools, defaultExpanded = false, isMobile = false }: ToolCallingSectionProps) {
93
+ const mode = useToolRenderMode();
94
+ const Row = ROW_BY_MODE[mode];
95
+
60
96
  const normalizedTools = useMemo(() => {
61
97
  return (tools || []).map((t, i) => normalizeToolData(t, i));
62
98
  }, [tools]);
@@ -68,13 +104,21 @@ export function ToolCallingSection({ tools, defaultExpanded = false, isMobile =
68
104
  if (!normalizedTools || normalizedTools.length === 0) return null;
69
105
 
70
106
  return (
71
- <div className={`${transcriptGutter(isMobile)} space-y-1.5`} data-tool-section>
107
+ <div
108
+ className={`${transcriptGutter(isMobile)} ${mode === 'trace' ? 'relative' : 'space-y-1.5'}`}
109
+ data-tool-section
110
+ data-tool-style={mode}
111
+ >
112
+ {/* The rail itself is drawn ONCE per turn by `TurnRail` (see
113
+ `MessageItem`): a segment per section broke wherever prose sat between
114
+ two blocks, which is exactly what a trace may not do. A row still
115
+ places its own node. */}
72
116
  {normalizedTools.map((tool) => {
73
117
  const intent = tool.intent?.trim();
74
118
  return (
75
119
  <Fragment key={tool.id}>
76
120
  {intent && (
77
- <div className="flex items-center gap-2 px-1 pt-0.5">
121
+ <div className={`flex items-center gap-2 px-1 pt-0.5 ${mode === 'trace' ? 'pl-4' : ''}`}>
78
122
  {/* Label sizes to its text; the rule takes everything left over,
79
123
  so the line runs to the panel edge the way `ThinkingSection`
80
124
  draws it. The label is NOT `flex-1` — two `flex-1` items split
@@ -91,7 +135,7 @@ export function ToolCallingSection({ tools, defaultExpanded = false, isMobile =
91
135
  <span className="h-px min-w-6 flex-1 bg-ink/8" />
92
136
  </div>
93
137
  )}
94
- <ToolCallCard
138
+ <Row
95
139
  tool={tool}
96
140
  isOpen={Boolean(openMap[tool.id])}
97
141
  onToggle={toggle}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `trace` rail for ONE turn, drawn by the turn rather than by each block.
8
+ *
9
+ * The first shape gave every block (thinking, the tool section, a notice) its
10
+ * own segment sized to that block. Measured on the 39-call sample session in the
11
+ * browser, that produced three disconnected lines with real gaps between them:
12
+ *
13
+ * thinking -1390 → -1356 (34px)
14
+ * gap 256px ← the answer text in between
15
+ * tool section -1100 → 368 (1468px)
16
+ * gap 99px
17
+ * notice 467 → 512 (45px)
18
+ *
19
+ * A rail whose whole job is to say "these steps are one sequence" cannot break
20
+ * wherever prose happens to sit between them, so the line belongs to the
21
+ * container that holds them all and each block only places its NODE on it.
22
+ *
23
+ * The horizontal origin is the blocks' own gutter: every block is inset by
24
+ * `transcriptGutter` (12px on desktop, 0 on a phone) and puts its node at its
25
+ * own `left-0`, so the rail sits at `gutter + 3.5px` — measured `rail 315 /
26
+ * node 315` for thinking, a notice and a tool row alike.
27
+ *
28
+ * Rendered only when the turn actually has a trace block; a line drawn beside a
29
+ * plain answer would claim a sequence that is not there.
30
+ */
31
+
32
+ interface TurnRailProps {
33
+ /** The turn has at least one block that draws a node. */
34
+ visible: boolean;
35
+ isMobile: boolean;
36
+ }
37
+
38
+ export function TurnRail({ visible, isMobile }: TurnRailProps) {
39
+ if (!visible) return null;
40
+ return (
41
+ <span
42
+ aria-hidden="true"
43
+ data-turn-rail
44
+ // The line spans the run, so it starts a little above the first node and
45
+ // ends a little below the last (the row's own margin plus the node's 9px
46
+ // offset — measured 21px / 32px). Both ends taper, so the rail reads as the
47
+ // run's column rather than a bar with cut ends.
48
+ //
49
+ // The taper is an INLINE style, not `[mask-image:…]`: an arbitrary-value
50
+ // class only exists if the CSS generator emitted that exact string, and
51
+ // measured in the browser the computed `mask-image` was `none` — the class
52
+ // was in the bundle but the dev asset serving the page had not been
53
+ // regenerated, which is the silent failure mode the wiki records for
54
+ // arbitrary classes (a missing rule fails without an error).
55
+ style={{
56
+ maskImage: 'linear-gradient(to bottom, transparent 0, black 10px, black calc(100% - 10px), transparent 100%)',
57
+ WebkitMaskImage: 'linear-gradient(to bottom, transparent 0, black 10px, black calc(100% - 10px), transparent 100%)',
58
+ }}
59
+ className={`pointer-events-none absolute top-0 bottom-0 w-px bg-ink/15 ${
60
+ isMobile ? 'left-[3.5px]' : 'left-[15.5px]'
61
+ }`}
62
+ />
63
+ );
64
+ }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Every transcript block wears the frame of the chosen style — not just the
8
+ * tool rows.
9
+ *
10
+ * The defect this pins: `toolRenderStyle` reached `ToolCallingSection` only, so
11
+ * a user on `compact` got compact tool rows sandwiched between a thinking card
12
+ * and a notice card in the old frame. A setting that half applies is a setting
13
+ * that reads as broken, and the fix is structural — one `blockChrome` table
14
+ * consulted by every block.
15
+ *
16
+ * Mounted against happy-dom and read from RENDERED markup, because the classes
17
+ * were right in the table while a component still spelled its own frame out.
18
+ */
19
+
20
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
21
+ import { Window } from 'happy-dom';
22
+ import { h, render } from 'preact';
23
+ import { act } from 'preact/test-utils';
24
+ import { ThinkingSection } from '@/client/components/workspace/chat-timeline/ThinkingSection';
25
+ import { SystemNotice } from '@/client/components/workspace/chat-timeline/SystemNotice';
26
+ import { primeKabmoSettings } from '@/shared/lib/settings/client';
27
+ import { applyToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
28
+ import { blockChrome } from '@/shared/lib/chat/timeline/block-chrome';
29
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
30
+
31
+ let container: HTMLElement;
32
+
33
+ beforeAll(() => installDomGlobals(new Window({ url: 'http://localhost' })));
34
+ afterAll(() => restoreDomGlobals());
35
+
36
+ beforeEach(() => {
37
+ // The DOM globals are installed ONCE for the file (beforeAll): swapping
38
+ // them per test churns `window`/`Event` for every other suite sharing the
39
+ // process, which made a later file register its hooks after the run had
40
+ // completed (`Cannot call beforeEach() after the test run has completed`).
41
+ container = document.createElement('div');
42
+ document.body.appendChild(container);
43
+ });
44
+
45
+ afterEach(() => {
46
+ render(null, container);
47
+ container.remove();
48
+ });
49
+
50
+ /** A thought long enough that the block renders (an empty one renders nothing). */
51
+ const THOUGHT = { thought: 'Read the summary module, then patch the header row.', duration: '1.2s' };
52
+ /** A multi-line notice: single-line notices have nothing to expand. */
53
+ const NOTICE = 'Line one\nLine two';
54
+ const MULTI_LINE_NOTICE = NOTICE;
55
+
56
+ async function paint(style: string, node: preact.ComponentChildren): Promise<HTMLElement> {
57
+ // Unmount first: preact reuses the instance for a same-type vnode, so a
58
+ // mounted hook keeps the mode it read on its FIRST render and a second
59
+ // paint would assert against the previous style.
60
+ render(null, container);
61
+ primeKabmoSettings({ kabmo_settings: { toolRenderStyle: style } });
62
+ await act(async () => {
63
+ render(node as never, container);
64
+ });
65
+ return container;
66
+ }
67
+
68
+ describe('blockChrome', () => {
69
+ test('only the card style has a frame', () => {
70
+ expect(blockChrome('card').frame).toContain('rounded-xl');
71
+ expect(blockChrome('card').frame).toContain('border-ink/10');
72
+ for (const mode of ['compact', 'trace', 'minimal'] as const) {
73
+ expect(blockChrome(mode).frame).toBe('');
74
+ }
75
+ });
76
+
77
+ test('only the trace style places a node, and it is the only one with a relative root', () => {
78
+ expect(blockChrome('trace').node).toBeDefined();
79
+ expect(blockChrome('trace').root).toContain('relative');
80
+ expect(blockChrome('compact').node).toBeUndefined();
81
+ expect(blockChrome('card').node).toBeUndefined();
82
+ expect(blockChrome('minimal').node).toBeUndefined();
83
+ });
84
+
85
+ test('the minimal style is the smallest type, the frame styles the largest', () => {
86
+ expect(blockChrome('minimal').title).toContain('text-[11.5px]');
87
+ expect(blockChrome('card').title).toContain('text-[12px]');
88
+ expect(blockChrome('card').header).toContain('px-3 py-2.5');
89
+ expect(blockChrome('compact').header).toContain('py-1');
90
+ });
91
+ });
92
+
93
+ describe('thinking follows the render style', () => {
94
+ test('the card frame is present on card, absent on every line style', async () => {
95
+ const card = await paint('card', h(ThinkingSection, { thinking: THOUGHT }));
96
+ expect(card.innerHTML).toContain('rounded-xl');
97
+
98
+ for (const style of ['compact', 'trace', 'minimal']) {
99
+ const el = await paint(style, h(ThinkingSection, { thinking: THOUGHT }));
100
+ expect(el.innerHTML).not.toContain('rounded-xl');
101
+ }
102
+ });
103
+
104
+ test('trace places a NODE on the turn rail; the other styles place none', async () => {
105
+ const trace = await paint('trace', h(ThinkingSection, { thinking: THOUGHT }));
106
+ const marks = Array.from(trace.querySelectorAll('[aria-hidden="true"]')) as HTMLElement[];
107
+ // The block contributes its node only — the LINE is the turn's (TurnRail),
108
+ // because a per-block segment broke wherever prose sat between blocks.
109
+ expect(marks.some((el) => el.className.includes('rounded-full'))).toBe(true);
110
+ expect(marks.some((el) => el.className.includes('w-px'))).toBe(false);
111
+
112
+ const compact = await paint('compact', h(ThinkingSection, { thinking: THOUGHT }));
113
+ const compactMarks = Array.from(compact.querySelectorAll('[aria-hidden="true"]')) as HTMLElement[];
114
+ expect(compactMarks.some((el) => el.className.includes('rounded-full'))).toBe(false);
115
+ });
116
+
117
+ test('a style change reaches a mounted thinking block', async () => {
118
+ await paint('card', h(ThinkingSection, { thinking: THOUGHT }));
119
+ expect(container.innerHTML).toContain('rounded-xl');
120
+
121
+ await act(async () => applyToolRenderMode('minimal'));
122
+ expect(container.innerHTML).not.toContain('rounded-xl');
123
+ });
124
+ });
125
+
126
+ describe('system notice follows the render style', () => {
127
+ test('the card frame is present on card, absent on every line style', async () => {
128
+ const card = await paint('card', h(SystemNotice, { notice: MULTI_LINE_NOTICE }));
129
+ expect(card.innerHTML).toContain('rounded-xl');
130
+
131
+ for (const style of ['compact', 'trace', 'minimal']) {
132
+ const el = await paint(style, h(SystemNotice, { notice: MULTI_LINE_NOTICE }));
133
+ expect(el.innerHTML).not.toContain('rounded-xl');
134
+ }
135
+ });
136
+
137
+ test('the notice body uses the style body container, so it hangs off the same rail', async () => {
138
+ const el = await paint('compact', h(SystemNotice, { notice: MULTI_LINE_NOTICE }));
139
+ const toggle = el.querySelector('button[aria-expanded]') as HTMLButtonElement;
140
+ expect(toggle.getAttribute('aria-expanded')).toBe('false');
141
+ await act(async () => {
142
+ toggle.click();
143
+ });
144
+ expect(el.querySelector('.border-l.border-dashed')).not.toBeNull();
145
+ expect(el.textContent).toContain('Line two');
146
+ });
147
+
148
+ test('a goal notice still renders OPEN with no toggle, in every style', async () => {
149
+ for (const style of ['card', 'compact', 'trace', 'minimal']) {
150
+ const el = await paint(style, h(SystemNotice, {
151
+ notice: '<objective>Ship it.</objective>\n`goal` tool: get.',
152
+ source: 'goal-mode-context',
153
+ }));
154
+ expect(el.textContent).toContain('Goal context');
155
+ expect(el.querySelector('button[aria-expanded]')).toBeNull();
156
+ }
157
+ });
158
+ });
@@ -49,7 +49,7 @@ export function AttachmentToolbar({ attachments, onFilesSelected, onRemove, mode
49
49
  {/* No separator and no second surface: the card is ONE colour, so the
50
50
  header, the draft and the toolbar read as one panel. A hairline over
51
51
  a tinted strip made the composer look like three stacked bars. */}
52
- <div className="flex items-center flex-wrap gap-1.5 px-3 py-2 text-ink/60">
52
+ <div className="composer-attach-row flex items-center flex-wrap gap-1.5 px-3 py-2 text-ink/60">
53
53
  <button
54
54
  onClick={() => fileInputRef.current?.click()}
55
55
  className="flex items-center justify-center hover:bg-ink/5 p-1 rounded transition-colors text-ink/60 hover:text-ink shrink-0"
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's refusal strip: a send that the pipeline rejected, or a
8
+ * mode-command the child answered with an error.
9
+ *
10
+ * Both are the same question and share one row, because a user cannot act on
11
+ * two refusals at once and the strip sits directly above the draft they belong
12
+ * to. Split out of `ChatInput` for the per-file ceiling; it owns no state — the
13
+ * two messages and their two dismissers come from the caller.
14
+ */
15
+
16
+ import { AlertTriangle, X } from 'lucide-preact';
17
+
18
+ export interface ComposerNoticeProps {
19
+ /** The pipeline's refusal (unreadable attachment, refused send, …). */
20
+ notice: string | null;
21
+ /** The mode command's refusal, from the route or the extension. */
22
+ modeError?: string | null;
23
+ onDismissNotice: () => void;
24
+ onDismissModeError?: () => void;
25
+ }
26
+
27
+ export function ComposerNotice({
28
+ notice,
29
+ modeError,
30
+ onDismissNotice,
31
+ onDismissModeError,
32
+ }: ComposerNoticeProps) {
33
+ const message = notice || modeError;
34
+ if (!message) return null;
35
+
36
+ return (
37
+ <div className="flex items-start gap-1.5 bg-error/5 px-3 py-1.5 text-[11px] text-error">
38
+ <AlertTriangle size={11} className="mt-0.5 shrink-0" />
39
+ <span className="min-w-0 flex-1 break-words">{message}</span>
40
+ <button
41
+ type="button"
42
+ onClick={() => (notice ? onDismissNotice() : onDismissModeError?.())}
43
+ className="shrink-0 text-error/60 hover:text-error transition-colors"
44
+ title="Dismiss"
45
+ >
46
+ <X size={11} />
47
+ </button>
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's five rows, built once and handed to `ComposerFrame`.
8
+ *
9
+ * Every row is ALWAYS constructed here — the frame decides only their ORDER,
10
+ * never whether they exist. That split is what makes "a style cannot drop a
11
+ * control" a property of the code rather than of a reviewer's attention.
12
+ *
13
+ * Split out of `ChatInput` for the per-file ceiling: the composer owns state
14
+ * (draft, attachments, expansion, compact, voice, pipeline) and this file owns
15
+ * the markup those states produce.
16
+ */
17
+
18
+ import type { ClipboardEvent, RefObject } from 'preact/compat';
19
+ import type { ComponentChildren } from 'preact';
20
+ import type { AIModelOption, Attachment } from '@/shared/types';
21
+ import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
22
+ import type { ComposerRow } from '@/shared/lib/chat/composer/style';
23
+ import type { ComposerModes } from '@/client/components/workspace/chat-timeline/chat-input/modes-props';
24
+ import type { ComposerPickerPlacement } from '@/client/components/common/ComposerPicker';
25
+ import { AttachmentToolbar } from '@/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar';
26
+ import { ComposerNotice } from '@/client/components/workspace/chat-timeline/chat-input/ComposerNotice';
27
+ import { ComposerTextarea } from '@/client/components/common/ComposerTextarea';
28
+ import { ComposerToolbar } from '@/client/components/workspace/chat-timeline/chat-input/Toolbar';
29
+ import { VoiceNotice } from '@/client/components/workspace/chat-timeline/chat-input/VoiceNotice';
30
+
31
+ export interface ComposerRowsInput {
32
+ /** Textarea sizing from `composerExpansion` (the style's own pixels are CSS). */
33
+ textareaClass: string;
34
+ wrapperClass: string;
35
+ pickerPlacement: ComposerPickerPlacement;
36
+
37
+ attachments: Attachment[];
38
+ onFilesSelected: (files: File[]) => void;
39
+ onRemoveAttachment: (id: string) => void;
40
+ modes?: ComposerModes;
41
+ onOpenGoal: () => void;
42
+ expanded?: boolean;
43
+ onToggleExpand?: () => void;
44
+ compact: boolean;
45
+ onExpandComposer: () => void;
46
+
47
+ notice: string | null;
48
+ dismissNotice: () => void;
49
+
50
+ value: string;
51
+ onChange: (value: string) => void;
52
+ submit: (options?: { steering?: boolean }) => void;
53
+ sendDisabled: boolean;
54
+ disabled: boolean;
55
+ appSettings?: Record<string, any>;
56
+ rootPath?: string | null;
57
+ enablePicker?: boolean;
58
+ placeholder?: string;
59
+ onPaste: (event: ClipboardEvent<HTMLTextAreaElement>) => void;
60
+ variant: 'desktop' | 'mobile';
61
+ textareaRef: RefObject<HTMLTextAreaElement>;
62
+ onTextareaReady: (element: HTMLTextAreaElement | null) => void;
63
+
64
+ voiceStatus: Parameters<typeof VoiceNotice>[0]['status'];
65
+ voiceError: string | null;
66
+
67
+ isMobile: boolean;
68
+ selectedModel: AIModelOption | null;
69
+ onSelectModel: (model: AIModelOption) => void;
70
+ thinkingLevels: string[];
71
+ currentThinking: string;
72
+ onSelectThinking: (level: string) => void;
73
+ onThinkingLevelChange?: (level: string) => void;
74
+ isGenerating: boolean;
75
+ chatRunning?: boolean;
76
+ onStop?: () => void;
77
+ accessMode?: ApprovalMode;
78
+ onSelectAccess?: (mode: ApprovalMode) => void;
79
+ showModel?: boolean;
80
+ showThinking?: boolean;
81
+ showAccess?: boolean;
82
+ voiceSupported?: boolean;
83
+ voiceListening?: boolean;
84
+ voiceBusy?: boolean;
85
+ onVoiceToggle?: () => void;
86
+ }
87
+
88
+ export function composerRows({
89
+ textareaClass,
90
+ wrapperClass,
91
+ pickerPlacement,
92
+ ...input
93
+ }: ComposerRowsInput): Record<ComposerRow, ComponentChildren> {
94
+ return {
95
+ attachments: (
96
+ <AttachmentToolbar
97
+ attachments={input.attachments}
98
+ onFilesSelected={input.onFilesSelected}
99
+ onRemove={input.onRemoveAttachment}
100
+ // The phone hosts the mode toggles here; the desktop keeps them in the
101
+ // bottom toolbar, which has room. `showAccess` gates both hosts.
102
+ modes={input.isMobile && input.showAccess ? input.modes : undefined}
103
+ onOpenGoal={input.onOpenGoal}
104
+ // Only the chat's own composer stretches; a caller that owns its size
105
+ // (the New Chat modal) gets no control and cannot be stretched.
106
+ expanded={input.onToggleExpand ? input.expanded : undefined}
107
+ onToggleExpand={input.onToggleExpand}
108
+ compact={input.compact}
109
+ onExpandComposer={input.onExpandComposer}
110
+ />
111
+ ),
112
+
113
+ notice: (
114
+ <ComposerNotice
115
+ notice={input.notice}
116
+ modeError={input.modes?.error}
117
+ onDismissNotice={input.dismissNotice}
118
+ onDismissModeError={input.modes?.clearError}
119
+ />
120
+ ),
121
+
122
+ // Not rendered at all while compact: the phone gives the transcript its
123
+ // height back by removing the box, not by shrinking it, and the attachment
124
+ // row then carries the "Type here" target that brings it back. A `h-0` box
125
+ // would keep a focusable element with no pixels.
126
+ draft: input.compact ? null : (
127
+ <ComposerTextarea
128
+ value={input.value}
129
+ onChange={input.onChange}
130
+ onSend={input.submit}
131
+ disabled={input.disabled}
132
+ appSettings={input.appSettings}
133
+ rootPath={input.rootPath}
134
+ enablePicker={input.enablePicker}
135
+ placement={pickerPlacement}
136
+ wrapperClassName={wrapperClass}
137
+ placeholder={input.placeholder}
138
+ className={`composer-draft w-full bg-transparent border-none focus:outline-none resize-none text-ink placeholder-ink/40 disabled:opacity-50 disabled:cursor-not-allowed ${textareaClass}`}
139
+ onPaste={input.onPaste}
140
+ variant={input.variant}
141
+ textareaRef={input.textareaRef}
142
+ onReady={input.onTextareaReady}
143
+ />
144
+ ),
145
+
146
+ // Dictation progress / failure, beside the toolbar that owns the mic.
147
+ voice: <VoiceNotice status={input.voiceStatus} error={input.voiceError} />,
148
+
149
+ toolbar: (
150
+ <ComposerToolbar
151
+ isMobile={input.isMobile}
152
+ selectedModel={input.selectedModel}
153
+ onSelectModel={input.onSelectModel}
154
+ thinkingLevels={input.thinkingLevels}
155
+ currentThinking={input.currentThinking}
156
+ onSelectThinking={input.onSelectThinking}
157
+ onThinkingLevelChange={input.onThinkingLevelChange}
158
+ isGenerating={input.isGenerating}
159
+ chatRunning={input.chatRunning}
160
+ onStop={input.onStop}
161
+ onSend={() => input.submit()}
162
+ sendDisabled={input.sendDisabled}
163
+ accessMode={input.accessMode}
164
+ onSelectAccess={input.onSelectAccess}
165
+ showModel={input.showModel}
166
+ showThinking={input.showThinking}
167
+ showAccess={input.showAccess}
168
+ modes={input.modes}
169
+ onOpenGoal={input.onOpenGoal}
170
+ voiceSupported={input.voiceSupported}
171
+ voiceListening={input.voiceListening}
172
+ voiceBusy={input.voiceBusy}
173
+ onVoiceToggle={input.onVoiceToggle}
174
+ text={input.value}
175
+ />
176
+ ),
177
+ };
178
+ }
@@ -107,7 +107,7 @@ export function ComposerToolbar({
107
107
  // footer read as a second, heavier bar under the draft. A 32px target
108
108
  // still clears the 28px minimum for a touch control while bringing the
109
109
  // row to 44px — the same height as the compact textarea above it.
110
- className="@container flex items-center justify-between rounded-b-[inherit] px-3 py-1.5"
110
+ className="composer-toolbar-row @container flex items-center justify-between rounded-b-[inherit] px-3 py-1.5"
111
111
  >
112
112
  <div className={`flex items-center min-w-0 ${isMobile ? 'space-x-1' : 'space-x-2'}`}>
113
113
  {showModel && (