@kabmo-labs/kabmo 0.13.0 → 0.14.1

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 (148) 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-bnrrw242.css +1 -0
  4. package/dist/client/static/js/{index-vzb1qz51.js → index-w6jx0h0p.js} +780 -780
  5. package/marketplace/plugins/command-runner/package.json +2 -2
  6. package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
  7. package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
  8. package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
  9. package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
  10. package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
  11. package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
  12. package/package.json +2 -2
  13. package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
  14. package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
  15. package/src/client/components/common/code-surface/extensions.ts +7 -1
  16. package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
  17. package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
  18. package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
  19. package/src/client/components/common/session-row/index.tsx +215 -0
  20. package/src/client/components/common/session-row/session-row.test.tsx +154 -0
  21. package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
  22. package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
  23. package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
  24. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
  25. package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
  26. package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
  27. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +56 -0
  28. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +193 -0
  29. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
  30. package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
  31. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
  32. package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
  33. package/src/client/components/mobile/SessionSidebar.tsx +137 -146
  34. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
  35. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
  36. package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
  37. package/src/client/components/settings/Modal.tsx +5 -27
  38. package/src/client/components/settings/Sidebar.tsx +1 -1
  39. package/src/client/components/settings/apply-side-effects.test.ts +102 -0
  40. package/src/client/components/settings/apply-side-effects.ts +90 -0
  41. package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
  42. package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
  43. package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
  44. package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
  45. package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
  46. package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
  47. package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
  48. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
  49. package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
  50. package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
  51. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
  52. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
  53. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +15 -5
  55. package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
  56. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
  57. package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
  58. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +117 -75
  59. package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
  60. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
  61. package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
  62. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +178 -0
  63. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
  64. package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
  65. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
  66. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
  67. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
  68. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
  69. package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
  70. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
  71. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
  73. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
  82. package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
  87. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
  88. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
  89. package/src/client/components/workspace/diff-panel/folding.ts +6 -1
  90. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
  91. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
  92. package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
  93. package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
  94. package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
  95. package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
  96. package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
  97. package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
  98. package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
  99. package/src/client/data/settings/omp-schema.json +151 -6
  100. package/src/client/hooks/chat/composer/style.ts +66 -0
  101. package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
  102. package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
  103. package/src/client/hooks/chat/timeline/row-window.ts +59 -133
  104. package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
  105. package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
  106. package/src/client/hooks/settings/providers/login.ts +11 -2
  107. package/src/client/hooks/ui/window-event.ts +20 -4
  108. package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
  109. package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
  110. package/src/client/hooks/workspace/batch-archive.ts +78 -0
  111. package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
  112. package/src/client/hooks/workspace/sidebar-style.ts +66 -0
  113. package/src/client/tailwind.css +111 -0
  114. package/src/server/index.ts +10 -134
  115. package/src/server/lib/lifecycle/after-listen.ts +178 -0
  116. package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
  117. package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
  118. package/src/server/lib/lifecycle/tls.test.ts +7 -7
  119. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
  120. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
  121. package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
  122. package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
  123. package/src/server/lib/plugins/background.server.ts +17 -1
  124. package/src/server/lib/plugins/background.test.ts +33 -0
  125. package/src/server/routes/sessions/batch-archive.test.ts +113 -0
  126. package/src/server/routes/sessions/batch-archive.ts +80 -0
  127. package/src/server/routes/sessions/index.ts +4 -0
  128. package/src/shared/lib/chat/composer/style.test.ts +126 -0
  129. package/src/shared/lib/chat/composer/style.ts +171 -0
  130. package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
  131. package/src/shared/lib/chat/composer/tui-only.ts +5 -0
  132. package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
  133. package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
  134. package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
  135. package/src/shared/lib/chat/timeline/trace-groups.test.ts +132 -0
  136. package/src/shared/lib/chat/timeline/trace-groups.ts +95 -0
  137. package/src/shared/lib/settings/defaults.ts +6 -0
  138. package/src/shared/lib/workspace/session-focus.test.ts +93 -0
  139. package/src/shared/lib/workspace/session-focus.ts +71 -0
  140. package/src/shared/lib/workspace/session-state/store.ts +5 -0
  141. package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
  142. package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
  143. package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
  144. package/src/shared/lib/workspace/sidebar-style.ts +86 -0
  145. package/src/shared/types/omp/agent.ts +6 -0
  146. package/src/shared/types/settings/state.ts +31 -0
  147. package/dist/client/static/js/index-68w8h33q.css +0 -1
  148. package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's four styles, rendered.
8
+ *
9
+ * The contract these pin is not cosmetic: **a style may reorder the card's rows
10
+ * and change its frame, and may never remove a control.** The worst case of a
11
+ * violation is the access-mode selector — the one control that decides whether
12
+ * a turn may write to disk — silently missing from a card the user is about to
13
+ * send from.
14
+ *
15
+ * The style reaches the composer through the primed settings snapshot
16
+ * (`readKabmoSetting('composerStyle')`), which is what `main.tsx` does at boot,
17
+ * so priming is also the honest way to mount it here.
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 { ChatInput } from '@/client/components/workspace/chat-timeline/chat-input';
25
+ import { primeKabmoSettings } from '@/shared/lib/settings/client';
26
+ import { delay } from '@/client/hooks/chat/composer/file-reads';
27
+ import { restoreRealtime, silenceRealtime } from '@/test-support/silent-socket';
28
+ import { COMPOSER_STYLES, type ComposerStyle } from '@/shared/lib/chat/composer/style';
29
+
30
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'HTMLTextAreaElement', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent'] as const;
31
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
32
+
33
+ beforeAll(() => {
34
+ const win = new Window({ url: 'http://localhost' });
35
+ const target = globalThis as unknown as Record<string, unknown>;
36
+ for (const key of DOM_GLOBALS) {
37
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
38
+ target[key] = (win as unknown as Record<string, unknown>)[key];
39
+ }
40
+ });
41
+
42
+ afterAll(() => {
43
+ const target = globalThis as unknown as Record<string, unknown>;
44
+ for (const key of DOM_GLOBALS) {
45
+ if (nativeGlobals[key] === undefined) delete target[key];
46
+ else target[key] = nativeGlobals[key];
47
+ }
48
+ });
49
+
50
+ let container: HTMLElement | null = null;
51
+
52
+ beforeEach(() => {
53
+ silenceRealtime();
54
+ });
55
+
56
+ afterEach(async () => {
57
+ // Unmount, then drain while this window still exists — see `compact.test.tsx`
58
+ // for why the order is load-bearing (the model picker keeps a realtime
59
+ // subscription and a reconnect timer).
60
+ const host = container;
61
+ if (host) {
62
+ await act(async () => { render(null, host); });
63
+ host.remove();
64
+ }
65
+ container = null;
66
+ restoreRealtime();
67
+ await delay(50);
68
+ });
69
+
70
+ async function mount(style: ComposerStyle): Promise<HTMLElement> {
71
+ primeKabmoSettings({ kabmo_settings: { composerStyle: style } });
72
+ const host = document.createElement('div');
73
+ document.body.appendChild(host);
74
+ container = host;
75
+
76
+ await act(async () => {
77
+ render(
78
+ h(ChatInput, {
79
+ value: '',
80
+ onChange: () => {},
81
+ onSend: () => {},
82
+ isGenerating: false,
83
+ composerModelRef: { current: null },
84
+ variant: 'desktop',
85
+ sessionId: 'composer-style-test',
86
+ expandable: true,
87
+ accessMode: 'always-ask',
88
+ onAccessModeChange: () => {},
89
+ modes: {
90
+ plan: false,
91
+ goal: false,
92
+ goalOpen: false,
93
+ goalRecord: null,
94
+ goalContinuation: null,
95
+ goalEvaluating: false,
96
+ pending: false,
97
+ planAvailable: true,
98
+ error: null,
99
+ clearError: () => {},
100
+ onTogglePlan: () => {},
101
+ onGoalAction: () => {},
102
+ },
103
+ }),
104
+ host,
105
+ );
106
+ });
107
+ await act(async () => { await delay(20); });
108
+ return host;
109
+ }
110
+
111
+ describe('composer styles', () => {
112
+ for (const style of COMPOSER_STYLES) {
113
+ test(`${style} renders every control`, async () => {
114
+ const host = await mount(style);
115
+
116
+ // The card carries the style, so CSS can key its pixels off it.
117
+ const card = host.querySelector('[data-composer-style]');
118
+ expect(card?.getAttribute('data-composer-style')).toBe(style);
119
+
120
+ // Draft.
121
+ expect(host.querySelector('[data-testid="composer-input"]')).not.toBeNull();
122
+ // Attach + its file input.
123
+ expect(host.querySelector('button[title="Attach file or image"]')).not.toBeNull();
124
+ expect(host.querySelector('input[type="file"]')).not.toBeNull();
125
+ // The stretch control.
126
+ expect(host.querySelector('button[aria-label="Maximize composer"]')).not.toBeNull();
127
+ // Plan and Goal: `aria-label` carries the mode, so it survives a narrow
128
+ // card whose labels are hidden by the container query.
129
+ expect(host.querySelector('button[aria-label="Enter plan mode"]')).not.toBeNull();
130
+ expect(host.querySelector('button[aria-label="Set a goal"]')).not.toBeNull();
131
+ // Send. The VOICE button is not asserted: `useVoiceInput` reports support
132
+ // from `navigator.mediaDevices`, which happy-dom does not implement, so its
133
+ // absence here says nothing about a style. It is gated on capability
134
+ // inside the toolbar, identically for every style.
135
+ expect(host.querySelector('button[aria-label="Send message"]')).not.toBeNull();
136
+ // The access selector is a menu, not a labelled button, so it is found by
137
+ // its own trigger text — the value the composer was handed.
138
+ expect(host.textContent ?? '').toContain('Always ask');
139
+ });
140
+ }
141
+
142
+ test('the calm and console styles put the draft above the attachment row', async () => {
143
+ for (const style of ['calm', 'console'] as const) {
144
+ const host = await mount(style);
145
+ const card = host.querySelector('[data-composer-style]');
146
+ const children = Array.from(card?.children ?? []);
147
+ const draftIndex = children.findIndex((el) => el.querySelector('[data-testid="composer-input"]'));
148
+ const attachIndex = children.findIndex((el) => el.className.includes('composer-attach-row'));
149
+ expect(draftIndex).toBeGreaterThanOrEqual(0);
150
+ expect(attachIndex).toBeGreaterThanOrEqual(0);
151
+ expect(draftIndex).toBeLessThan(attachIndex);
152
+
153
+ await act(async () => { render(null, host); });
154
+ host.remove();
155
+ container = null;
156
+ }
157
+ });
158
+
159
+ test('classic keeps the attachment row first', async () => {
160
+ const host = await mount('classic');
161
+ const card = host.querySelector('[data-composer-style]');
162
+ const children = Array.from(card?.children ?? []);
163
+ const attachIndex = children.findIndex((el) => el.className.includes('composer-attach-row'));
164
+ const draftIndex = children.findIndex((el) => el.querySelector('[data-testid="composer-input"]'));
165
+ expect(attachIndex).toBe(0);
166
+ expect(attachIndex).toBeLessThan(draftIndex);
167
+ });
168
+
169
+ test('the console style is the only one that draws the prompt glyph', async () => {
170
+ for (const style of COMPOSER_STYLES) {
171
+ const host = await mount(style);
172
+ const glyphs = Array.from(host.querySelectorAll('span[aria-hidden="true"]'))
173
+ .filter((el) => (el.textContent ?? '').includes('omp ›'));
174
+ expect(glyphs.length).toBe(style === 'console' ? 1 : 0);
175
+
176
+ await act(async () => { render(null, host); });
177
+ host.remove();
178
+ container = null;
179
+ }
180
+ });
181
+ });
@@ -306,6 +306,9 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
306
306
  // transcript, so a phone composer may give its height back.
307
307
  // `composerExpansion` ignores it on a desktop.
308
308
  shrinkWhileReading={readingBack}
309
+ // No turns yet: the `stage` composer style draws its wider,
310
+ // taller card only here.
311
+ hero={localMessages.length === 0 && !timelineRunning}
309
312
  />
310
313
  )}
311
314
  </>
@@ -84,6 +84,7 @@ export function FrameControl({ frame, multi, selected, onAnswer, onToggle, onRes
84
84
  ) : (
85
85
  <input
86
86
  autoFocus
87
+ type={frame.secret === true ? 'password' : 'text'}
87
88
  value={text}
88
89
  placeholder={frame.placeholder || 'Type your answer…'}
89
90
  onChange={(event) => setText(event.currentTarget.value)}
@@ -143,3 +143,34 @@ describe('the gate\'s answer', () => {
143
143
  expect(sent).toEqual([{ value: 'Approve' }]);
144
144
  });
145
145
  });
146
+
147
+ /**
148
+ * omp 18.14.0 added `secret` to an `input` dialog (`ctx.ui.input({ secret:
149
+ * true })`) and forwards it on the frame. A client that ignores it draws the
150
+ * password in clear text on screen.
151
+ *
152
+ * The frame shape is upstream's: `InputUiRequest` gained `"secret": boolean`,
153
+ * validated as an optional member — measured against 18.14.0's
154
+ * `rpc-wire.schema.json`, where it is the only change to that definition.
155
+ */
156
+ describe('a secret input dialog', () => {
157
+ const SECRET_INPUT: ExtensionUiDialogRequest = {
158
+ type: 'extension_ui_request',
159
+ id: 'i1',
160
+ method: 'input',
161
+ title: 'Paste the API key',
162
+ placeholder: 'sk-…',
163
+ secret: true,
164
+ };
165
+
166
+ test('masks what the user types', () => {
167
+ draw(SECRET_INPUT);
168
+ const field = container.querySelector('input');
169
+ expect(field?.getAttribute('type')).toBe('password');
170
+ });
171
+
172
+ test('a plain input stays readable', () => {
173
+ draw({ ...SECRET_INPUT, id: 'i2', secret: undefined });
174
+ expect(container.querySelector('input')?.getAttribute('type')).toBe('text');
175
+ });
176
+ });
@@ -218,7 +218,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
218
218
  </div>
219
219
  <input
220
220
  ref={inputRef}
221
- type="text"
221
+ type={request.secret === true ? 'password' : 'text'}
222
222
  value={value}
223
223
  placeholder={request.placeholder || 'Type your response...'}
224
224
  onChange={(e) => setValue(e.currentTarget.value)}
@@ -155,7 +155,7 @@ const TOOL_KEY_TITLES: Record<string, true> = {
155
155
  };
156
156
 
157
157
  /**
158
- * Panel khusus per tool family — dirender di dalam body ToolCallCard.
158
+ * Panel khusus per tool family — dirender di dalam body setiap render style.
159
159
  * Classification is pure (`toolPanelKind`); this only maps the key to a
160
160
  * component, so asking "does this tool have a panel?" no longer builds one.
161
161
  */
@@ -166,7 +166,7 @@ export function ToolDetailsPanel({ tool }: { tool: ToolCallData }): ReactNode {
166
166
  }
167
167
 
168
168
  /** True kalau tool punya panel khusus yang sudah merender input/output sendiri —
169
- * ToolCallCard tidak boleh render Input/Output generik lagi (anti dobel). */
169
+ * ToolBody tidak boleh render Input/Output generik lagi (anti dobel). */
170
170
  export function hasToolDetailsPanel(tool: ToolCallData): boolean {
171
171
  return toolPanelKind(tool) !== null;
172
172
  }
@@ -30,8 +30,13 @@ import { useListSlotRows } from '@/client/hooks/workspace/list-slots';
30
30
  * plugin's surface: a plugin's stylesheet is scoped to
31
31
  * `[data-plugin-surface="<id>"]`, so a renderer drawn outside its own surface
32
32
  * would have no CSS at all.
33
+ *
34
+ * The type is NAMED here rather than derived with `ReturnType<typeof …>` at the
35
+ * consumer, so the tool-view contract does not couple to this hook's signature.
33
36
  */
34
- export function usePluginTimelineRenderer(tool: string): ListSlotEntry<TimelineRendererRegistration> | null {
37
+ export type PluginTimelineRenderer = ListSlotEntry<TimelineRendererRegistration> | null;
38
+
39
+ export function usePluginTimelineRenderer(tool: string): PluginTimelineRenderer {
35
40
  const rows = useListSlotRows<TimelineRendererRegistration>('timelineRenderer');
36
41
  for (const entry of rows) {
37
42
  if (entry.registration.tool === tool) return entry;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The expanded body of a tool call — one implementation for every render style.
8
+ *
9
+ * The card owned this markup inline. With four styles the body is the ONE part
10
+ * that must not be duplicated: a `bash` panel drawn twice is two places to fix
11
+ * when the panel changes, and the two would drift. The styles differ in their
12
+ * frame, their density and their grouping; what a call SHOWS when opened is the
13
+ * same everywhere.
14
+ *
15
+ * Three shapes, in priority order:
16
+ *
17
+ * 1. A plugin's own renderer, when the host has no panel for the tool (the
18
+ * slot's contract — a plugin must not shadow `bash` or `read`).
19
+ * 2. The host's specialized panel (`ToolDetailsPanel`).
20
+ * 3. The generic Input / Diff / Output, for a tool with no panel at all.
21
+ */
22
+
23
+ import type { ReactNode } from 'preact/compat';
24
+ import { PluginIdProvider } from '@kabmo-labs/kabmo-ui';
25
+ import type { ToolCallData } from '@/shared/types';
26
+ import { CopyButton } from '@/client/components/common/CopyButton';
27
+ import { ToolDetailsPanel } from '@/client/components/workspace/chat-timeline/tool-renderers';
28
+ import { DiffView } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView';
29
+ import { FallbackOutput } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/FallbackOutput';
30
+ import { JsonCodeBlock } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock';
31
+ import type { ToolView } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view';
32
+ import { usePluginSlotContext } from '@/client/hooks/workspace/list-slots';
33
+
34
+ function SectionLabel({ children }: { children: string }) {
35
+ return (
36
+ <div className="text-[9.5px] font-semibold uppercase tracking-[0.14em] text-ink/40">
37
+ {children}
38
+ </div>
39
+ );
40
+ }
41
+
42
+ export function ToolBody({ tool, view }: { tool: ToolCallData; view: ToolView }): ReactNode {
43
+ const slotContext = usePluginSlotContext();
44
+
45
+ return (
46
+ <>
47
+ {view.pluginPanel ? (
48
+ <PluginIdProvider pluginId={view.pluginPanel.pluginId}>
49
+ <view.pluginPanel.registration.component
50
+ {...slotContext}
51
+ toolName={view.toolKey}
52
+ args={tool.input}
53
+ output={view.outputText}
54
+ />
55
+ </PluginIdProvider>
56
+ ) : (
57
+ <ToolDetailsPanel tool={tool} />
58
+ )}
59
+
60
+ {!view.hasBody && view.commandOrInput && (
61
+ <div className="space-y-1.5 code-surface">
62
+ <div className="flex items-center justify-between">
63
+ <div className="flex items-center gap-1.5">
64
+ <SectionLabel>Input</SectionLabel>
65
+ {view.inputJson?.isValid && (
66
+ <span className="rounded bg-ink/5 px-1.5 py-0.2 font-mono text-[9px] uppercase tracking-wider text-ink/45">
67
+ JSON
68
+ </span>
69
+ )}
70
+ </div>
71
+ <CopyButton
72
+ text={view.inputJson?.isValid && view.inputJson.pretty ? view.inputJson.pretty : view.commandOrInput}
73
+ 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"
74
+ onClick={(e) => e.stopPropagation()}
75
+ label="Copy"
76
+ />
77
+ </div>
78
+ {view.inputJson?.isValid && view.inputJson.pretty ? (
79
+ <JsonCodeBlock jsonString={view.inputJson.pretty} maxHeightClass="max-h-60" showHeader={false} />
80
+ ) : (
81
+ <pre className="overflow-x-auto rounded-lg border border-ink/8 bg-paper px-3 py-2.5 font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-all text-ink/80 select-text">
82
+ {view.commandOrInput}
83
+ </pre>
84
+ )}
85
+ </div>
86
+ )}
87
+
88
+ {!view.hasBody && view.diffText && (
89
+ <div className="space-y-1.5">
90
+ <SectionLabel>Diff</SectionLabel>
91
+ <DiffView text={view.diffText} path={view.subtitle} />
92
+ </div>
93
+ )}
94
+
95
+ {!view.hasBody && view.outputText && <FallbackOutput text={view.outputText} />}
96
+ </>
97
+ );
98
+ }
@@ -27,6 +27,7 @@ import type { ToolCallData } from '@/shared/types';
27
27
  import { isSkippedTool } from '@/shared/lib/chat/tool-status';
28
28
  import type { ToolSummary } from '@/shared/lib/chat/tool/summary';
29
29
  import { ToolFactChips } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/ToolFactChips';
30
+ import { toolToggleLabel } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label';
30
31
 
31
32
  interface ToolCardShellProps {
32
33
  tool: ToolCallData;
@@ -124,10 +125,11 @@ export function ToolCardShell({
124
125
  };
125
126
 
126
127
  const isSkipped = isSkippedTool(tool);
127
- const toggleLabel = `${isExpanded ? 'Collapse' : 'Expand'} ${title}${subtitle ? ` — ${subtitle}` : ''}`;
128
+ const toggleLabel = toolToggleLabel(title, subtitle, isExpanded);
128
129
 
129
130
  return (
130
131
  <div
132
+ data-tool-row="card"
131
133
  className={`group overflow-hidden rounded-xl border transition-all duration-200 ${
132
134
  status === 'error' && !isSkipped
133
135
  ? 'border-error/25 bg-error/[0.03]'
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The status glyph every non-card style uses, and the tone that goes with it.
8
+ *
9
+ * The card spells the outcome as a badge with a word (`Done`, `Failed`,
10
+ * `Running`, `Skipped`, `Aborted`). A one-line style has no room for the word,
11
+ * so the glyph carries it — which makes the glyph load-bearing, not decorative:
12
+ * `aborted` and `skipped` are distinct outcomes omp records, and collapsing
13
+ * either into a check mark would tell the reader the model declined when the
14
+ * user had interrupted. The card's badge rules are mirrored here for that
15
+ * reason (`ToolCardShell`'s `statusBadge`).
16
+ */
17
+
18
+ import type { ReactNode } from 'preact/compat';
19
+ import { AlertCircle, Check, CircleSlash, Loader2, OctagonX } from 'lucide-preact';
20
+ import type { ToolCallData } from '@/shared/types';
21
+ import { isSkippedTool } from '@/shared/lib/chat/tool-status';
22
+
23
+ export type ToolStatusTone = 'ok' | 'error' | 'warn' | 'muted';
24
+
25
+ export interface ToolStatusGlyph {
26
+ /** The glyph itself, sized for a one-line row. */
27
+ glyph: ReactNode;
28
+ tone: ToolStatusTone;
29
+ /** The word a screen reader hears — the glyph is not enough on its own. */
30
+ word: string;
31
+ }
32
+
33
+ /** Tone → text class. `--theme-error` is the only chroma a tool row may use. */
34
+ export const STATUS_TONE_CLASS: Record<ToolStatusTone, string> = {
35
+ ok: 'text-success',
36
+ error: 'text-error',
37
+ warn: 'text-warning',
38
+ muted: 'text-ink/30',
39
+ };
40
+
41
+ export function toolStatusGlyph(tool: ToolCallData): ToolStatusGlyph {
42
+ if (tool.status === 'aborted') {
43
+ return { glyph: <OctagonX size={12} />, tone: 'warn', word: 'Aborted' };
44
+ }
45
+ if (isSkippedTool(tool)) {
46
+ return { glyph: <CircleSlash size={12} />, tone: 'muted', word: 'Skipped' };
47
+ }
48
+ const status = tool.status || (tool.error ? 'error' : 'success');
49
+ if (status === 'error') {
50
+ return { glyph: <AlertCircle size={12} />, tone: 'error', word: 'Failed' };
51
+ }
52
+ if (status === 'running') {
53
+ return { glyph: <Loader2 size={12} className="animate-spin" />, tone: 'muted', word: 'Running' };
54
+ }
55
+ return { glyph: <Check size={12} />, tone: 'ok', word: 'Done' };
56
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The one wording every tool render style uses for its expand control.
8
+ *
9
+ * `chat.e2e.ts` collects the transcript's tool rows by
10
+ * `[aria-label^="Expand "]` and requires each to name its tool, and
11
+ * `mobile.e2e.ts` / `tool-diff-scroll.e2e.ts` click `/^Expand Bash/` and
12
+ * `/^Expand Edit/`. A style that invented its own wording would read as a card
13
+ * with no title, so the builder lives here and every style — the card included
14
+ * — calls it.
15
+ */
16
+
17
+ export function toolToggleLabel(title: string, subtitle: string | undefined, isExpanded: boolean): string {
18
+ return `${isExpanded ? 'Collapse' : 'Expand'} ${title}${subtitle ? ` — ${subtitle}` : ''}`;
19
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Everything a tool call's row SAYS, derived once per call and shared by every
8
+ * render style.
9
+ *
10
+ * The card used to own this derivation inline. When the transcript gained
11
+ * alternative styles (`compact`, `trace`, `minimal`) each one would have needed
12
+ * the same header, the same facts, the same fallback text — four copies of one
13
+ * fact, which is exactly how a card and a rail start disagreeing about what a
14
+ * call did. The derivation is a hook (it consults the plugin slot registry) but
15
+ * it holds no state: `useMemo` keys on the tool, and the result is plain data
16
+ * plus a VNode for the icon.
17
+ *
18
+ * Nothing here decides layout. `tool-renderers/styles/*` do that.
19
+ */
20
+
21
+ import { useMemo } from 'preact/hooks';
22
+ import type { ReactNode } from 'preact/compat';
23
+ import type { ToolCallData } from '@/shared/types';
24
+ import { stripAnsiCodes } from '@/shared/lib/code/ansi';
25
+ import { isReminderTag, unwrapXmlEnvelopes } from '@/shared/lib/chat/xml-envelope';
26
+ import { toolSummary, type ToolSummary } from '@/shared/lib/chat/tool/summary';
27
+ import { tryParseJson, type JsonDetectionResult } from '@/shared/lib/code/syntax-highlight';
28
+ import { resolveToolKey } from '@/client/components/workspace/chat-timeline/tool-renderers';
29
+ import { usePluginTimelineRenderer, type PluginTimelineRenderer } from '@/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers';
30
+ import { toolPanelKind } from '@/client/components/workspace/chat-timeline/tool-renderers/registry';
31
+ import {
32
+ commandOrInputOf,
33
+ diffTextOf,
34
+ evalLanguageIcon,
35
+ toolIcon,
36
+ } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/card-helpers';
37
+ import {
38
+ toolCardHeader,
39
+ toolCardSubtitle,
40
+ type ToolCardHeader,
41
+ } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/card-header';
42
+
43
+ export interface ToolView {
44
+ /** Canonical tool key — icon, panel and header all derive from it. */
45
+ toolKey: string;
46
+ /** A host panel exists for this tool; the generic Input/Diff/Output is skipped. */
47
+ hasPanel: boolean;
48
+ /** The plugin renderer to use INSTEAD, when the host has no panel. */
49
+ pluginPanel: PluginTimelineRenderer;
50
+ /** Whether there is anything to expand. */
51
+ hasBody: boolean;
52
+ summary: ToolSummary | null;
53
+ header: ToolCardHeader;
54
+ subtitle: string | undefined;
55
+ icon: ReactNode;
56
+ outputText: string;
57
+ diffText: string | undefined;
58
+ commandOrInput: string;
59
+ inputJson: JsonDetectionResult | null;
60
+ /** The result carried a runtime reminder envelope, not an outcome. */
61
+ isReminder: boolean;
62
+ /** Panels that are never collapsible (`ask`, `goal`, `yield`). */
63
+ alwaysExpanded: boolean;
64
+ }
65
+
66
+ /** Panels whose whole point is a decision the reader is in the middle of. */
67
+ const ALWAYS_EXPANDED_KEYS: Record<string, true> = { yield: true, goal: true, ask: true };
68
+
69
+ export function useToolView(tool: ToolCallData): ToolView {
70
+ const toolKey = resolveToolKey(tool);
71
+ // A pure classification, not a probe render: the old `hasToolDetailsPanel`
72
+ // built the panel's VNode and threw it away, once per card per streaming
73
+ // frame. `toolPanelKind` is a lookup, so this is free.
74
+ const hasPanel = useMemo(() => toolPanelKind(tool) !== null, [tool]);
75
+ // A plugin renderer is consulted only for a tool the host has NO panel for,
76
+ // so a plugin can ship its own agent tool without shadowing `bash` or `read`.
77
+ const pluginRenderer = usePluginTimelineRenderer(toolKey);
78
+ const pluginPanel = hasPanel ? null : pluginRenderer;
79
+ const hasBody = hasPanel || pluginPanel !== null;
80
+ const summary = useMemo(() => toolSummary(tool), [tool]);
81
+ const header = useMemo(() => toolCardHeader(tool, toolKey), [tool, toolKey]);
82
+ const subtitle = toolCardSubtitle(tool, header);
83
+
84
+ const commandOrInput = commandOrInputOf(tool);
85
+ const outputText = tool.output || (tool.error ? `Error: ${tool.error}` : '');
86
+ const diffText = diffTextOf(tool);
87
+
88
+ const inputJson = useMemo(
89
+ () => (!hasBody && commandOrInput ? tryParseJson(commandOrInput) : null),
90
+ [hasBody, commandOrInput],
91
+ );
92
+
93
+ // A reminder envelope in the result is the runtime interrupting the call, not
94
+ // its outcome — the row flags it beside the status.
95
+ const isReminder = useMemo(
96
+ () => unwrapXmlEnvelopes(stripAnsiCodes(outputText)).some((envelope) => isReminderTag(envelope.tag)),
97
+ [outputText],
98
+ );
99
+
100
+ // The intent chip is deliberately NOT part of this row. It used to be the
101
+ // first chip, which pushed a real fact out: an `edit` showed
102
+ // `Preferring dt.files for real files · +43 −16 · +1`, so `line 25` — the
103
+ // thing the reader wants — sat behind the overflow counter. The row is
104
+ // `path + facts` now, and the intent stays where it always was for every tool
105
+ // except eval: nowhere, or inside the body's own panel.
106
+ //
107
+ // eval is the exception and shows its intent as the TITLE (`input.title` is
108
+ // omp's label for the cell), so it carries no facts row at all — a second
109
+ // line of `js · 1 cell · browser.open` under a title that already names the
110
+ // action is the duplication this removes.
111
+ const headerSummary = toolKey === 'eval' ? null : summary;
112
+
113
+ // The eval card is marked by the language it runs, not a generic code glyph.
114
+ const icon = tool.icon || (toolKey === 'eval' ? evalLanguageIcon(tool) : null) || toolIcon(toolKey);
115
+
116
+ return {
117
+ toolKey,
118
+ hasPanel,
119
+ pluginPanel,
120
+ hasBody,
121
+ summary: headerSummary,
122
+ header,
123
+ subtitle,
124
+ icon,
125
+ outputText,
126
+ diffText,
127
+ commandOrInput,
128
+ inputJson,
129
+ isReminder,
130
+ alwaysExpanded: hasPanel && Boolean(ALWAYS_EXPANDED_KEYS[toolKey]),
131
+ };
132
+ }
@@ -24,7 +24,7 @@ import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:tes
24
24
  import { Window } from 'happy-dom';
25
25
  import { h, render } from 'preact';
26
26
  import { act } from 'preact/test-utils';
27
- import { ToolCallCard } from '@/client/components/workspace/chat-timeline/ToolCallCard';
27
+ import { CardRow } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/Card';
28
28
  import { registerListSlot, resetListSlots } from '@/client/lib/plugins/list-slots';
29
29
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
30
30
  import type { ToolCallData } from '@/shared/types';
@@ -65,12 +65,12 @@ const tool = (name: string): ToolCallData => ({
65
65
 
66
66
  function mount(name: string, isOpen = true) {
67
67
  act(() => {
68
- render(h(ToolCallCard, { tool: tool(name), isOpen, defaultExpanded: true }), container);
68
+ render(h(CardRow, { tool: tool(name), isOpen, defaultExpanded: true }), container);
69
69
  });
70
70
  return container;
71
71
  }
72
72
 
73
- describe('ToolCallCard plugin renderer', () => {
73
+ describe('CardRow plugin renderer', () => {
74
74
  test('renders no plugin panel when nothing was contributed', () => {
75
75
  mount('mytool');
76
76
  expect(container.querySelector('[data-testid="plugin-panel"]')).toBeNull();