@kabmo-labs/kabmo 0.14.0 → 0.15.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 (51) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +1 -1
  3. package/dist/client/static/js/index-28pwtt69.css +1 -0
  4. package/dist/client/static/js/{index-nfsg1jpt.js → index-mx658m43.js} +624 -624
  5. package/marketplace/plugins/command-runner/README.md +5 -3
  6. package/marketplace/plugins/command-runner/package.json +2 -2
  7. package/marketplace/plugins/command-runner/src/app.tsx +3 -3
  8. package/marketplace/plugins/command-runner/src/panel/Groups.test.tsx +25 -21
  9. package/marketplace/plugins/command-runner/src/panel/Groups.tsx +4 -1
  10. package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
  11. package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
  12. package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
  13. package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
  14. package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
  15. package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
  16. package/package.json +2 -2
  17. package/src/client/components/common/session-row/index.tsx +11 -1
  18. package/src/client/components/common/session-row/session-row.test.tsx +10 -0
  19. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +5 -4
  20. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +11 -2
  21. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
  22. package/src/client/components/mobile/LayoutWrapper.tsx +11 -10
  23. package/src/client/components/mobile/open-file-payload.test.ts +29 -1
  24. package/src/client/components/mobile/open-file-payload.ts +28 -0
  25. package/src/client/components/settings/Modal.tsx +2 -2
  26. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +1 -0
  27. package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
  28. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +10 -9
  29. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +21 -1
  30. package/src/client/components/workspace/editor/index.tsx +6 -8
  31. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
  32. package/src/client/components/workspace/git-panel/branch-modal/index.tsx +4 -3
  33. package/src/client/components/workspace/git-panel/commit-modal/index.tsx +1 -1
  34. package/src/client/hooks/chat/timeline/index.ts +3 -6
  35. package/src/client/hooks/chat/timeline/jump-landing.ts +121 -0
  36. package/src/client/hooks/chat/timeline/jump-rail.ts +19 -10
  37. package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
  38. package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
  39. package/src/client/hooks/chat/timeline/row-window.ts +100 -134
  40. package/src/client/hooks/chat/timeline/scroll-probe.test-util.ts +23 -10
  41. package/src/client/hooks/chat/timeline/scroll.test.ts +61 -4
  42. package/src/client/hooks/chat/timeline/scroll.ts +77 -26
  43. package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
  44. package/src/client/hooks/workspace/missing-files.test.ts +20 -3
  45. package/src/client/hooks/workspace/missing-files.ts +41 -7
  46. package/src/client/tailwind.css +12 -1
  47. package/src/server/routes/fs/exists.test.ts +26 -1
  48. package/src/shared/lib/chat/timeline/trace-groups.test.ts +12 -0
  49. package/src/shared/lib/chat/timeline/trace-groups.ts +29 -2
  50. package/src/shared/lib/workspace/session-state/store.ts +5 -0
  51. package/dist/client/static/js/index-tsgy3gd1.css +0 -1
@@ -35,6 +35,15 @@
35
35
  * The actions are the same components the classic header uses — `+` opens a
36
36
  * chat in THIS folder and `⋯` is `WorkspaceOptionsMenu` — so pin, delete,
37
37
  * reveal, worktree and session-selection exist in both styles by construction.
38
+ *
39
+ * ## The sticky surface is the list's surface
40
+ *
41
+ * The header must be opaque — rows scroll underneath it — and the colour it
42
+ * paints has to be the one the list sits on, or every folder draws a band.
43
+ * `--theme-paper` is the desktop column's surface and `--theme-canvas` the phone
44
+ * drawer's (see `shared/lib/theme/chrome.ts`); a single `bg-paper` therefore
45
+ * put a lighter stripe behind each folder in the phone drawer, where the rows
46
+ * behind it are canvas.
38
47
  */
39
48
 
40
49
  import type { ReactNode } from 'preact/compat';
@@ -81,8 +90,8 @@ export function WorkspaceHeader({
81
90
 
82
91
  return (
83
92
  <div
84
- className={`group/ws sticky top-0 z-10 -mx-1 flex items-center gap-1 rounded-md bg-paper px-1 text-xs font-semibold text-ink ${
85
- touch ? 'h-8' : 'h-[26px]'
93
+ className={`group/ws sticky top-0 z-10 -mx-1 flex items-center gap-1 rounded-md px-1 text-xs font-semibold text-ink ${
94
+ touch ? 'h-8 bg-canvas' : 'h-[26px] bg-paper'
86
95
  }`}
87
96
  >
88
97
  <button
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `modern` workspace header's sticky surface.
8
+ *
9
+ * The header is opaque because rows scroll under it, so the colour it paints is
10
+ * visible as a band behind every folder. It must be the surface the list sits
11
+ * on: `--theme-paper` in the desktop column, `--theme-canvas` in the phone
12
+ * drawer (`shared/lib/theme/chrome.ts`). Shipping one `bg-paper` put a lighter
13
+ * stripe behind each folder on the phone — the reported "belang" list.
14
+ *
15
+ * Rendered with `h()` against happy-dom, following
16
+ * `common/session-row/session-row.test.tsx`.
17
+ */
18
+
19
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
20
+ import { Window } from 'happy-dom';
21
+ import { h, render } from 'preact';
22
+
23
+ import { WorkspaceHeader } from '@/client/components/layout/session-sidebar/modern/WorkspaceHeader';
24
+ import type { WorkspaceHeaderProps } from '@/client/components/layout/session-sidebar/modern/WorkspaceHeader';
25
+ import type { WorkspaceFolderData } from '@/shared/types';
26
+
27
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'MouseEvent'] as const;
28
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
29
+
30
+ let container: HTMLElement;
31
+
32
+ beforeAll(() => {
33
+ const win = new Window({ url: 'http://localhost' });
34
+ const target = globalThis as unknown as Record<string, unknown>;
35
+ for (const key of DOM_GLOBALS) {
36
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
37
+ target[key] = (win as unknown as Record<string, unknown>)[key];
38
+ }
39
+ });
40
+
41
+ afterAll(() => {
42
+ const target = globalThis as unknown as Record<string, unknown>;
43
+ for (const key of DOM_GLOBALS) {
44
+ if (nativeGlobals[key] === undefined) delete target[key];
45
+ else target[key] = nativeGlobals[key];
46
+ }
47
+ });
48
+
49
+ afterEach(() => {
50
+ if (container) render(null, container);
51
+ container?.remove();
52
+ });
53
+
54
+ const FOLDER: WorkspaceFolderData = {
55
+ id: 1,
56
+ name: 'kabmo',
57
+ isExpanded: true,
58
+ sessions: [],
59
+ hasMore: false,
60
+ totalSessions: 0,
61
+ };
62
+
63
+ function mount(overrides: Partial<WorkspaceHeaderProps> = {}) {
64
+ if (container) {
65
+ render(null, container);
66
+ container.remove();
67
+ }
68
+ container = document.createElement('div');
69
+ document.body.appendChild(container);
70
+ render(
71
+ h(WorkspaceHeader, {
72
+ folder: FOLDER,
73
+ isOpen: true,
74
+ onToggleFolder: () => {},
75
+ sessionCount: 0,
76
+ checkbox: null,
77
+ batchActive: false,
78
+ menuRef: { current: null },
79
+ showMenu: false,
80
+ onToggleMenu: () => {},
81
+ onNewSession: () => {},
82
+ ...overrides,
83
+ }),
84
+ container,
85
+ );
86
+ return container.firstElementChild as HTMLElement;
87
+ }
88
+
89
+ describe('modern workspace header', () => {
90
+ test('the desktop header paints the column surface', () => {
91
+ const header = mount();
92
+ expect(header.className).toContain('bg-paper');
93
+ expect(header.className).not.toContain('bg-canvas');
94
+ });
95
+
96
+ test('the phone header paints the drawer surface, so no folder band appears', () => {
97
+ const header = mount({ touch: true });
98
+ expect(header.className).toContain('bg-canvas');
99
+ expect(header.className).not.toContain('bg-paper');
100
+ });
101
+
102
+ test('it stays sticky in both densities', () => {
103
+ expect(mount().className).toContain('sticky');
104
+ expect(mount({ touch: true }).className).toContain('sticky');
105
+ });
106
+
107
+ test('the phone header is 32px, the height its rows match', () => {
108
+ expect(mount({ touch: true }).className).toContain('h-8');
109
+ expect(mount().className).toContain('h-[26px]');
110
+ });
111
+ });
@@ -19,7 +19,7 @@ import { ToastStack } from '@/client/components/common/ToastStack';
19
19
  import { useEditorDrop, type EditorDropResult } from '@/client/hooks/editor/use-editor-drop';
20
20
  import { EditorDropOverlay } from '@/client/components/workspace/editor/EditorDropOverlay';
21
21
  import { PluginBootstrap } from '@/client/lib/plugins/bootstrap';
22
- import { mobileEditorFileFrom, type MobileEditorFile } from '@/client/components/mobile/open-file-payload';
22
+ import { mobileEditorFileFrom, mobileProbeTabs, type MobileEditorFile } from '@/client/components/mobile/open-file-payload';
23
23
  import { useLeftDock } from '@/client/hooks/workspace/left-dock';
24
24
  import { useSessionStateContext } from '@/client/hooks/workspace/session-state/context';
25
25
  import { setSessionKey } from '@/shared/lib/workspace/session-state/store';
@@ -61,13 +61,11 @@ export function MobileLayoutWrapper({ onDesktopToggle, appSettings = {} }: Mobil
61
61
  // The phone's full-screen editor shows ONE file at a time, so the probe has a
62
62
  // single subject and a constant id. `refreshKey` is what carries a deletion
63
63
  // here: the Files panel's delete, an agent `rm` that triggers a workspace
64
- // refresh, and the editor's own save all bump it.
65
- const mobileEditorMissingIds = useMissingFiles(
66
- mobileEditorFile?.path
67
- ? [{ id: 'mobile-editor', path: mobileEditorFile.path, root: mobileEditorFile.root }]
68
- : [],
69
- refreshKey,
70
- );
64
+ // refresh, and the editor's own save all bump it. The scope comes from
65
+ // `mobileProbeTabs` so `repo` travels with it — without it the server resolved
66
+ // a nested-repo file against the workspace root and answered "gone" for a file
67
+ // that had just been read.
68
+ const mobileEditorMissingIds = useMissingFiles(mobileProbeTabs(mobileEditorFile), refreshKey);
71
69
  const { toasts, pushToast, dismissToast } = useToasts();
72
70
  const handleDropResult = useCallback(
73
71
  (result: EditorDropResult) => pushToast(result.message, result.ok ? 'success' : 'error'),
@@ -118,10 +116,13 @@ export function MobileLayoutWrapper({ onDesktopToggle, appSettings = {} }: Mobil
118
116
  // never receive the first drop.
119
117
  const editorDrop = useEditorDrop({ enabled: hasContext, onResult: handleDropResult });
120
118
 
121
- // Listen to open-file event on mobile
119
+ // Listen to open-file event on mobile. The active project is the fallback
120
+ // root, exactly as the desktop tab opener applies it: a payload with no root
121
+ // of its own (a chat link, a plugin readout) then reads AND probes against the
122
+ // workspace it belongs to instead of the server's default root.
122
123
  useKabmoEvent('omp:open-file', (e) => {
123
124
  const customEvent = e as CustomEvent<unknown>;
124
- const next = mobileEditorFileFrom(customEvent.detail);
125
+ const next = mobileEditorFileFrom(customEvent.detail, activeProjectPath);
125
126
  if (next) setMobileEditorFile(next);
126
127
  });
127
128
 
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  import { describe, expect, test } from 'bun:test';
19
- import { mobileEditorFileFrom } from '@/client/components/mobile/open-file-payload';
19
+ import { mobileEditorFileFrom, mobileProbeTabs } from '@/client/components/mobile/open-file-payload';
20
20
 
21
21
  describe('mobileEditorFileFrom', () => {
22
22
  test('carries repo and handleId through', () => {
@@ -34,6 +34,7 @@ describe('mobileEditorFileFrom', () => {
34
34
  root: '/ws',
35
35
  repo: 'projects/token',
36
36
  handleId: 'handle-7',
37
+ deviceFile: undefined,
37
38
  });
38
39
  });
39
40
 
@@ -68,4 +69,31 @@ describe('mobileEditorFileFrom', () => {
68
69
  expect(result?.repo).toBeUndefined();
69
70
  expect(result?.handleId).toBeUndefined();
70
71
  });
72
+
73
+ test('a device file is marked, so the existence probe refuses it', () => {
74
+ expect(mobileEditorFileFrom({ path: 'report.md', deviceFile: true })?.deviceFile).toBe(true);
75
+ expect(mobileEditorFileFrom({ path: 'x.md', deviceFile: 'yes' })?.deviceFile).toBeUndefined();
76
+ });
77
+ });
78
+
79
+ describe('mobileProbeTabs', () => {
80
+ test('carries the tree the file was opened from — repo included', () => {
81
+ // The regression: the phone's probe sent `root` + `path` and dropped `repo`,
82
+ // so the server resolved a nested-repo file against the workspace root and
83
+ // answered "gone" for a file the editor had just read.
84
+ const file = mobileEditorFileFrom({ path: 'src/inner.ts', root: '/ws', repo: 'pkg/nested' });
85
+ expect(mobileProbeTabs(file)).toEqual([{
86
+ id: 'mobile-editor',
87
+ path: 'src/inner.ts',
88
+ root: '/ws',
89
+ repo: 'pkg/nested',
90
+ content: undefined,
91
+ handleId: undefined,
92
+ deviceFile: undefined,
93
+ }]);
94
+ });
95
+
96
+ test('nothing open means nothing to probe', () => {
97
+ expect(mobileProbeTabs(null)).toEqual([]);
98
+ });
71
99
  });
@@ -14,6 +14,8 @@
14
14
  * server-reachable path, so its bytes come from the live handle instead).
15
15
  */
16
16
 
17
+ import type { ProbeableTab } from '@/client/hooks/workspace/missing-files';
18
+
17
19
  /** The one file the phone's full-screen editor has open. */
18
20
  export interface MobileEditorFile {
19
21
  name: string;
@@ -24,6 +26,8 @@ export interface MobileEditorFile {
24
26
  repo?: string;
25
27
  /** A dropped/launched file's live handle — its bytes have no server path. */
26
28
  handleId?: string;
29
+ /** The bytes came from the DEVICE: renderable, with no path the server can stat. */
30
+ deviceFile?: boolean;
27
31
  }
28
32
 
29
33
  function readString(source: Record<string, unknown>, key: string): string | undefined {
@@ -56,5 +60,29 @@ export function mobileEditorFileFrom(payload: unknown, fallbackRoot?: string | n
56
60
  root: readString(source, 'root') ?? fallbackRoot ?? undefined,
57
61
  repo: readString(source, 'repo'),
58
62
  handleId: readString(source, 'handleId'),
63
+ deviceFile: source.deviceFile === true ? true : undefined,
59
64
  };
60
65
  }
66
+
67
+ /**
68
+ * The scope the phone's "is this file still there?" probe must ask about.
69
+ *
70
+ * `repo` is load-bearing and used to be dropped here: the server resolves
71
+ * `root` + `repo` + `path` exactly as the READ route does, so a file opened from
72
+ * a nested repository — the tree lists it relative to that repo — was read
73
+ * successfully and then reported as deleted by a probe that named the workspace
74
+ * root instead. Everything else (inline content, a launched handle, a device
75
+ * file) is carried through so `isProbeableTab` can refuse it in one place.
76
+ */
77
+ export function mobileProbeTabs(file: MobileEditorFile | null): ProbeableTab[] {
78
+ if (!file) return [];
79
+ return [{
80
+ id: 'mobile-editor',
81
+ path: file.path,
82
+ root: file.root,
83
+ repo: file.repo,
84
+ content: file.content,
85
+ handleId: file.handleId,
86
+ deviceFile: file.deviceFile,
87
+ }];
88
+ }
@@ -187,11 +187,11 @@ export function SettingsModal({
187
187
  onClick={onClose}
188
188
  >
189
189
  <div
190
- className="relative bg-paper border border-ink/15 md:rounded-2xl shadow-2xl w-full h-full md:max-w-4xl lg:max-w-5xl xl:max-w-[1150px] md:h-[782px] md:max-h-[92vh] flex flex-col md:flex-row overflow-hidden text-ink"
190
+ className="relative bg-paper border border-ink/15 md:rounded-2xl shadow-2xl w-full h-full md:max-w-5xl lg:max-w-6xl xl:max-w-[1280px] md:h-[min(90vh,900px)] md:max-h-[92vh] flex flex-col md:flex-row overflow-hidden text-ink"
191
191
  onClick={(e) => e.stopPropagation()}
192
192
  >
193
193
  {/* DESKTOP VIEW: 2-Column Split */}
194
- <div className="hidden md:flex w-64 flex-shrink-0 h-full">
194
+ <div className="hidden md:flex w-72 flex-shrink-0 h-full">
195
195
  <SettingsSidebar
196
196
  activeCategory={activeCategory}
197
197
  onSelectCategory={(catId) => setActiveCategory(catId)}
@@ -208,6 +208,7 @@ export const ChatMessageItem = memo(function ChatMessageItem({
208
208
  {thinkingData && (
209
209
  <ThinkingSection
210
210
  thinking={thinkingData}
211
+ messageId={String(msg.id)}
211
212
  defaultExpanded={false}
212
213
  showSeparator={isPrevAssistant}
213
214
  isMobile={isMobile}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A thinking block's open state belongs to the conversation, not to the mounted
8
+ * component instance.
9
+ *
10
+ * The defect this pins: the accordion kept its openness in a local
11
+ * `useState`, and `MessageList` mounts a WINDOW of rows. Expanding a thought
12
+ * grows its row, the next measurement moves the viewport, the row leaves the
13
+ * window and comes back with a fresh `useState(false)` — so the block snapped
14
+ * shut, and whether it did depended on how much content sat below it ("sometimes
15
+ * it works"). Measured in the browser on a real session: one click removed and
16
+ * re-added every row at the window's edge.
17
+ *
18
+ * Mounted against happy-dom and driven through the rendered button, because the
19
+ * claim is about what a click on the real control does across a remount.
20
+ */
21
+
22
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
23
+ import { Window } from 'happy-dom';
24
+ import { h, render } from 'preact';
25
+ import { act } from 'preact/test-utils';
26
+ import { ThinkingSection } from '@/client/components/workspace/chat-timeline/ThinkingSection';
27
+ import { SessionStateProvider } from '@/client/components/common/session-state-provider';
28
+ import { forgetSession } from '@/shared/lib/workspace/session-state/store';
29
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
30
+
31
+ const SESSION = 'spec-thinking-open';
32
+ /** The runner's own fetch, so a leaked stub cannot be mistaken for it. */
33
+ const nativeFetch = Bun.fetch;
34
+
35
+ let container: HTMLElement;
36
+
37
+ const THOUGHT = { thought: 'Read the summary module, then patch the header row.', duration: '1.2s' };
38
+
39
+ beforeAll(() => installDomGlobals(new Window({ url: 'http://localhost' })));
40
+ afterAll(() => restoreDomGlobals());
41
+
42
+ beforeEach(() => {
43
+ container = document.createElement('div');
44
+ document.body.appendChild(container);
45
+ (globalThis as unknown as Record<string, unknown>).fetch = async () =>
46
+ new Response(JSON.stringify({ sessionId: SESSION, state: {} }), {
47
+ status: 200,
48
+ headers: { 'content-type': 'application/json' },
49
+ });
50
+ });
51
+
52
+ afterEach(() => {
53
+ render(null, container);
54
+ container.remove();
55
+ forgetSession(SESSION);
56
+ (globalThis as unknown as Record<string, unknown>).fetch = nativeFetch;
57
+ });
58
+
59
+ async function mount(messageId: string, thinking: typeof THOUGHT & { isGenerating?: boolean } = THOUGHT): Promise<void> {
60
+ await act(async () => {
61
+ render(
62
+ h(SessionStateProvider, {
63
+ sessionId: SESSION,
64
+ children: h(ThinkingSection, { thinking, messageId }),
65
+ }) as never,
66
+ container,
67
+ );
68
+ });
69
+ for (let i = 0; i < 4; i += 1) await act(async () => {});
70
+ }
71
+
72
+ function toggle(): HTMLButtonElement {
73
+ const button = container.querySelector<HTMLButtonElement>('button[aria-expanded]');
74
+ if (!button) throw new Error('no thinking toggle');
75
+ return button;
76
+ }
77
+
78
+ async function click(): Promise<void> {
79
+ await act(async () => { toggle().click(); });
80
+ }
81
+
82
+ describe('thinking open state', () => {
83
+ test('a block starts closed and a click opens it', async () => {
84
+ await mount('m1');
85
+ expect(toggle().getAttribute('aria-expanded')).toBe('false');
86
+ await click();
87
+ expect(toggle().getAttribute('aria-expanded')).toBe('true');
88
+ });
89
+
90
+ test('the choice survives the row being unmounted and remounted', async () => {
91
+ await mount('m1');
92
+ await click();
93
+ // What the timeline's row window does when the expanded row grows and the
94
+ // reader moves: the row leaves the DOM and comes back.
95
+ render(null, container);
96
+ await mount('m1');
97
+ expect(toggle().getAttribute('aria-expanded')).toBe('true');
98
+ });
99
+
100
+ test('each row remembers its own choice', async () => {
101
+ await mount('m1');
102
+ await click();
103
+ render(null, container);
104
+ await mount('m2');
105
+ expect(toggle().getAttribute('aria-expanded')).toBe('false');
106
+ });
107
+
108
+ test('a generating run opens itself, and closing it during the run sticks', async () => {
109
+ await mount('m1', { ...THOUGHT, isGenerating: true });
110
+ expect(toggle().getAttribute('aria-expanded')).toBe('true');
111
+
112
+ // The reader closes it mid-run. The run is still generating, so a default
113
+ // re-applied on the next frame would re-open it under their cursor.
114
+ await click();
115
+ expect(toggle().getAttribute('aria-expanded')).toBe('false');
116
+ });
117
+ });
@@ -23,7 +23,7 @@
23
23
  * a tool card with a title of "Thinking".
24
24
  */
25
25
 
26
- import { useEffect, useRef, useState } from 'preact/hooks';
26
+ import { useEffect, useRef } from 'preact/hooks';
27
27
  import { BrainCircuit, ChevronDown, Sparkles } from 'lucide-preact';
28
28
  import type { ThinkingData } from '@/shared/types';
29
29
  import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
@@ -31,9 +31,16 @@ import { CopyButton } from '@/client/components/common/CopyButton';
31
31
  import { transcriptGutter } from '@/shared/lib/chat/timeline/gutter';
32
32
  import { blockChrome, traceInset } from '@/shared/lib/chat/timeline/block-chrome';
33
33
  import { useToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
34
+ import { useThinkingOpenState } from '@/client/hooks/chat/timeline/thinking-open';
34
35
 
35
36
  interface ThinkingSectionProps {
36
37
  thinking: ThinkingData | string;
38
+ /**
39
+ * The row this block belongs to, and the key its open state is stored under.
40
+ * Optional: a block mounted outside a timeline still toggles, it just cannot
41
+ * remember the choice across the row being unmounted (see `thinking-open`).
42
+ */
43
+ messageId?: string;
37
44
  defaultExpanded?: boolean;
38
45
  showSeparator?: boolean;
39
46
  /** Phone layout: the section's frame is the timeline gutter itself. */
@@ -42,6 +49,7 @@ interface ThinkingSectionProps {
42
49
 
43
50
  export function ThinkingSection({
44
51
  thinking,
52
+ messageId,
45
53
  defaultExpanded = false,
46
54
  showSeparator = false,
47
55
  isMobile = false,
@@ -51,13 +59,9 @@ export function ThinkingSection({
51
59
  const framed = mode === 'card';
52
60
 
53
61
  const isGenerating = typeof thinking === 'object' ? Boolean(thinking.isGenerating) : false;
54
- const [isOpen, setIsOpen] = useState(defaultExpanded || isGenerating);
62
+ const { isOpen, toggle: toggleOpen } = useThinkingOpenState(messageId, defaultExpanded, isGenerating);
55
63
  const thoughtBodyRef = useRef<HTMLDivElement>(null);
56
64
 
57
- useEffect(() => {
58
- if (isGenerating) setIsOpen(true);
59
- }, [isGenerating]);
60
-
61
65
  const thoughtText = typeof thinking === 'string' ? thinking : thinking.thought || '';
62
66
  const noticeMatch = thoughtText.match(/<system-notice[^>]*>([\s\S]*?)<\/system-notice>/);
63
67
  const noticeText = noticeMatch?.[1]?.trim() ?? '';
@@ -73,10 +77,7 @@ export function ThinkingSection({
73
77
  if (el) el.scrollTop = el.scrollHeight;
74
78
  }, [isOpen, cleanThought, isGenerating]);
75
79
 
76
- const toggleOpen = () => setIsOpen(prev => !prev);
77
-
78
80
  if (!cleanThought) return null;
79
-
80
81
  const iconTone = framed ? 'bg-ink/5 text-ink/70' : 'text-ink/40';
81
82
 
82
83
  return (
@@ -23,12 +23,18 @@ import { h, render } from 'preact';
23
23
  import { act } from 'preact/test-utils';
24
24
  import { ThinkingSection } from '@/client/components/workspace/chat-timeline/ThinkingSection';
25
25
  import { SystemNotice } from '@/client/components/workspace/chat-timeline/SystemNotice';
26
+ import { SessionStateProvider } from '@/client/components/common/session-state-provider';
26
27
  import { primeKabmoSettings } from '@/shared/lib/settings/client';
27
28
  import { applyToolRenderMode } from '@/client/hooks/chat/timeline/tool-render-mode';
28
29
  import { blockChrome } from '@/shared/lib/chat/timeline/block-chrome';
30
+ import { forgetSession } from '@/shared/lib/workspace/session-state/store';
29
31
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
30
32
 
31
33
  let container: HTMLElement;
34
+ /** The runner's own fetch, so a leaked stub cannot be mistaken for it. */
35
+ const nativeFetch = Bun.fetch;
36
+ /** A pending id: the provider loads it like any other and nothing is stored. */
37
+ const SESSION = 'spec-block-chrome';
32
38
 
33
39
  beforeAll(() => installDomGlobals(new Window({ url: 'http://localhost' })));
34
40
  afterAll(() => restoreDomGlobals());
@@ -40,11 +46,20 @@ beforeEach(() => {
40
46
  // completed (`Cannot call beforeEach() after the test run has completed`).
41
47
  container = document.createElement('div');
42
48
  document.body.appendChild(container);
49
+ // The blocks remember their openness per session, so the provider they are
50
+ // mounted under asks for this session's blob.
51
+ (globalThis as unknown as Record<string, unknown>).fetch = async () =>
52
+ new Response(JSON.stringify({ sessionId: SESSION, state: {} }), {
53
+ status: 200,
54
+ headers: { 'content-type': 'application/json' },
55
+ });
43
56
  });
44
57
 
45
58
  afterEach(() => {
46
59
  render(null, container);
47
60
  container.remove();
61
+ forgetSession(SESSION);
62
+ (globalThis as unknown as Record<string, unknown>).fetch = nativeFetch;
48
63
  });
49
64
 
50
65
  /** A thought long enough that the block renders (an empty one renders nothing). */
@@ -59,9 +74,14 @@ async function paint(style: string, node: preact.ComponentChildren): Promise<HTM
59
74
  // paint would assert against the previous style.
60
75
  render(null, container);
61
76
  primeKabmoSettings({ kabmo_settings: { toolRenderStyle: style } });
77
+ // The blocks remember their openness per session (`useToolOpenState`,
78
+ // `useThinkingOpenState`), so they are mounted the way the timeline mounts
79
+ // them: inside the provider.
62
80
  await act(async () => {
63
- render(node as never, container);
81
+ render(h(SessionStateProvider, { sessionId: SESSION, children: node }) as never, container);
64
82
  });
83
+ // The provider's blob load settles across a tick.
84
+ for (let i = 0; i < 4; i += 1) await act(async () => {});
65
85
  return container;
66
86
  }
67
87
 
@@ -79,14 +79,12 @@ export function Editor({
79
79
  const editorTheme = useEditorTheme();
80
80
 
81
81
  // A deleted file keeps its tab (its buffer is still on screen), but the tab
82
- // strip must say so. Only a plain FILE tab is probed: a diff tab's path names
83
- // a change rather than a document, and an attachment chip carries inline
84
- // `content` with no file behind its `path` at all — probing that name would
85
- // strike the chip through the moment it was opened.
86
- const missingIds = useMissingFiles(
87
- openedFiles.filter((file) => !file.isDiff && file.content === undefined),
88
- refreshKey,
89
- );
82
+ // strip must say so. Which tabs can be probed is the hook's own rule
83
+ // (`isProbeableTab`): a diff tab's path names a change rather than a document,
84
+ // and an attachment chip carries inline `content` with no file behind its
85
+ // `path` at all — probing that name would strike the chip through the moment
86
+ // it was opened.
87
+ const missingIds = useMissingFiles(openedFiles, refreshKey);
90
88
  const activeFileMissing = Boolean(activeFile && missingIds.has(activeFile.id));
91
89
 
92
90
  const editor = useFileEditor(activeFile ?? null, {
@@ -36,10 +36,24 @@ export function SvgPreview({ content, name }: SvgPreviewProps) {
36
36
  {/* A checkerboard would be wrong here: an SVG is normally opaque or
37
37
  intended to sit on a surface, and the panel's paper is that surface.
38
38
  The SVG scales to the container via the CSS below rather than a
39
- measured size, so no layout pass is needed. */}
39
+ measured size, so no layout pass is needed.
40
+
41
+ `w-full` on the wrapper is load-bearing, not cosmetic. A flex item is
42
+ shrink-to-fit, and an SVG that carries only a `viewBox` — no `width`
43
+ or `height` attributes, which is how most icon SVGs ship — defaults to
44
+ `width:100%` of its containing block. With no definite width above it,
45
+ that resolves against itself and the picture collapses to a 0x0 box:
46
+ the markup is in the DOM and nothing is drawn. The wrapper takes the
47
+ row's width, and the SVG then fills it, keeping its aspect ratio and
48
+ capped by `max-h`.
49
+
50
+ `mx-auto` pays for that width: an SVG that DOES declare its own size
51
+ is narrower than the wrapper, and the row's `justify-center` no longer
52
+ reaches it through a full-width child. It is a no-op for the filling
53
+ case above. */}
40
54
  <div className="flex min-h-full items-center justify-center p-6">
41
55
  <div
42
- className="svg-preview max-w-full [&>svg]:h-auto [&>svg]:max-h-[80vh] [&>svg]:w-auto [&>svg]:max-w-full"
56
+ className="svg-preview w-full max-w-full [&>svg]:mx-auto [&>svg]:block [&>svg]:h-auto [&>svg]:max-h-[80vh] [&>svg]:w-auto [&>svg]:max-w-full"
43
57
  role="img"
44
58
  aria-label={name}
45
59
  dangerouslySetInnerHTML={{ __html: safeSvg }}
@@ -39,9 +39,10 @@ interface GitBranchModalProps {
39
39
  * actions — the row's click is already checkout — and a row that both checks
40
40
  * out and merges is a row whose click means two things.
41
41
  *
42
- * Follows the commit modal's shell (`lg:w-[min(96vw,980px)] lg:h-[88vh]`,
43
- * full-screen on phones), so this is a sibling of an existing surface rather
44
- * than a new convention.
42
+ * Follows the commit modal's shell SHAPE — a desktop-capped, centred card that
43
+ * is full-screen on phones — but takes its own width from `Modal`
44
+ * (`max-w-[min(96vw,720px)]`): a branch list is one column, while the commit
45
+ * history spends the extra width on the graph gutter and the message column.
45
46
  *
46
47
  * **Everything the row shows comes from ONE read** (`?branches=1`, a single
47
48
  * `for-each-ref` with the upstream/ahead-behind/date/subject fields), fetched
@@ -232,7 +232,7 @@ export function GitCommitModal({
232
232
  <div
233
233
  className="bg-paper border-ink/20 shadow-2xl flex flex-col overflow-hidden
234
234
  w-full h-full rounded-none border-0
235
- lg:w-[min(96vw,980px)] lg:h-[88vh] lg:rounded-xl lg:border
235
+ lg:w-[min(94vw,1200px)] lg:h-[88vh] lg:rounded-xl lg:border
236
236
  pt-[env(safe-area-inset-top,0px)] lg:pt-0"
237
237
  onClick={(e) => e.stopPropagation()}
238
238
  >
@@ -48,9 +48,8 @@ export function useChatTimeline({
48
48
  // without re-creating it (useSessionLoad is defined below the scroll hook).
49
49
  const loadOlderRef = useRef<() => void>(() => {});
50
50
 
51
- const { scrollRef, scrollNodeRef, scrollNode, contentRef, showScrollBottom, readingBack, handleScroll, scrollToBottom, jumpToBottom, followRef, jumpActiveRef, jumpCountRef } = useChatTimelineScroll({
52
- onScrollTop: () => loadOlderRef.current(),
53
- });
51
+ const scroll = useChatTimelineScroll({ onScrollTop: () => loadOlderRef.current() });
52
+ const { scrollRef, scrollNodeRef, contentRef, showScrollBottom, readingBack, handleScroll, scrollToBottom, jumpToBottom, jumpActiveRef, jumpCountRef } = scroll;
54
53
 
55
54
  const { inputValue, setInputValue, inputAttachments, setInputAttachments } = useComposerDraft();
56
55
  const [localMessages, setLocalMessages] = useState<ChatMessageData[]>([]);
@@ -158,9 +157,7 @@ export function useChatTimeline({
158
157
  sessionId,
159
158
  messages: localMessages,
160
159
  jumpToTurn,
161
- followRef,
162
- scrollRef,
163
- scrollNode,
160
+ scroll,
164
161
  });
165
162
 
166
163
  // The composer's model/thinking mirrors and the mid-run stash (see the hook).