@kabmo-labs/kabmo 0.24.0 → 0.25.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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +579 -510
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-jcr5twtp.js → index-ga8cbpt4.js} +1072 -1174
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +36 -5
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -35
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +3 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +1 -1
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
- package/src/client/hooks/chat/timeline/send.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.ts +51 -50
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +17 -11
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +27 -1
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +23 -1
- package/src/server/lib/harness/acp/session.ts +59 -59
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +26 -9
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/launch.ts +3 -1
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +47 -0
- package/src/server/lib/omp/session/delete.server.ts +5 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +4 -0
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +59 -147
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/provider-facts.test.ts +27 -0
- package/src/shared/lib/harness/providers.ts +35 -1
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +21 -6
- package/src/shared/lib/harness/update-plan.ts +12 -4
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/theme.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/harness-table.test-util.ts +15 -1
- package/dist/client/static/js/index-z3w7n85q.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The pending chat's dock is the REAL timeline's dock.
|
|
8
|
+
*
|
|
9
|
+
* The generating indicator is drawn from one component, but its height in the
|
|
10
|
+
* pane came from two different wrappers: the real timeline docked it in
|
|
11
|
+
* `ComposerDock` (`p-4 pt-1`), while the pending `new-…` chat kept the landing
|
|
12
|
+
* page's centred `p-8` column with a `space-y-3` stack. Measured with the
|
|
13
|
+
* built CSS at 1200x1400: the indicator sat **141px** above the pane's bottom
|
|
14
|
+
* while the spawn was in flight (`Loading…`) and **113px** once the run
|
|
15
|
+
* streamed (`Thinking…`) — the row jumped 28px at adoption, which is why the
|
|
16
|
+
* two states read as two different indicators.
|
|
17
|
+
*
|
|
18
|
+
* Both are `ComposerDockFrame` now. What this suite pins is that the frame is
|
|
19
|
+
* the ONE wrapper for the pending dock, that the indicator is inside it in both
|
|
20
|
+
* identity states, and that the landing page — which has no run to report — is
|
|
21
|
+
* the only state that keeps the centred column.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
25
|
+
import { Window } from 'happy-dom';
|
|
26
|
+
import { h, render } from 'preact';
|
|
27
|
+
import { act } from 'preact/test-utils';
|
|
28
|
+
|
|
29
|
+
import { EmptyWorkspacePrompt } from '@/client/components/workspace/chat-timeline/EmptyWorkspacePrompt';
|
|
30
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
31
|
+
import { silenceRealtime, restoreRealtime } from '@/test-support/silent-socket';
|
|
32
|
+
import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
|
|
33
|
+
import { invalidateModelsCache } from '@/shared/lib/models/client';
|
|
34
|
+
|
|
35
|
+
let container: HTMLElement;
|
|
36
|
+
|
|
37
|
+
beforeAll(() => {
|
|
38
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
39
|
+
// The composer measures its textarea through the BARE global (`auto-grow.ts`),
|
|
40
|
+
// which happy-dom only provides on the window it installed.
|
|
41
|
+
(globalThis as unknown as Record<string, unknown>).getComputedStyle = window.getComputedStyle.bind(window);
|
|
42
|
+
});
|
|
43
|
+
afterAll(() => restoreDomGlobals());
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
silenceRealtime();
|
|
47
|
+
resetHarnessesStore();
|
|
48
|
+
invalidateModelsCache();
|
|
49
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
50
|
+
const url = String(input);
|
|
51
|
+
if (url.startsWith('/api/harness')) {
|
|
52
|
+
return Response.json({ harnesses: [], configs: {}, providerSupport: {} });
|
|
53
|
+
}
|
|
54
|
+
if (url.startsWith('/api/models')) {
|
|
55
|
+
return Response.json({ models: {}, modelList: [], selectedModel: null, defaultModel: null, thinkingLevels: {} });
|
|
56
|
+
}
|
|
57
|
+
return Response.json({});
|
|
58
|
+
}) as typeof fetch;
|
|
59
|
+
container = document.createElement('div');
|
|
60
|
+
document.body.appendChild(container);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
render(null, container);
|
|
65
|
+
container.remove();
|
|
66
|
+
restoreRealtime();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function mount(props: Record<string, unknown>) {
|
|
70
|
+
act(() => {
|
|
71
|
+
render(h(EmptyWorkspacePrompt, {
|
|
72
|
+
selectedFolderId: 1,
|
|
73
|
+
setSelectedFolderId: () => {},
|
|
74
|
+
inputValue: '',
|
|
75
|
+
setInputValue: () => {},
|
|
76
|
+
onSend: () => {},
|
|
77
|
+
isGenerating: false,
|
|
78
|
+
accessMode: 'always-ask',
|
|
79
|
+
onAccessModeChange: () => {},
|
|
80
|
+
composerModelRef: { current: null },
|
|
81
|
+
deferredComposerPickRef: { current: null },
|
|
82
|
+
...props,
|
|
83
|
+
} as never), container);
|
|
84
|
+
});
|
|
85
|
+
return container;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The model catalog is read through a promise chain; one macrotask drains it. */
|
|
89
|
+
async function settle(): Promise<void> {
|
|
90
|
+
await act(async () => {
|
|
91
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
92
|
+
setTimeout(resolve, 30);
|
|
93
|
+
await promise;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const USER_ROW = { id: 'msg-1-user', role: 'user', content: 'halo', date: 'Today, 12:22 PM' };
|
|
98
|
+
|
|
99
|
+
describe('pending chat dock frame', () => {
|
|
100
|
+
test('the indicator rides the dock frame in both identity states', async () => {
|
|
101
|
+
// `Loading…` — the spawn has not answered, so neither half is known.
|
|
102
|
+
const loading = mount({ messages: [USER_ROW], isGenerating: true, generatingVerb: 'Thinking' });
|
|
103
|
+
await settle();
|
|
104
|
+
const loadingDock = loading.querySelector('[data-composer-dock]');
|
|
105
|
+
const loadingIndicator = loading.querySelector('#generating-docked-indicator');
|
|
106
|
+
expect(loadingDock).not.toBeNull();
|
|
107
|
+
expect(loadingIndicator).not.toBeNull();
|
|
108
|
+
expect(loadingDock!.contains(loadingIndicator!)).toBe(true);
|
|
109
|
+
expect(loading.textContent).toContain('Loading');
|
|
110
|
+
|
|
111
|
+
render(null, container);
|
|
112
|
+
// `Thinking…` — same run, identity resolved.
|
|
113
|
+
const thinking = mount({
|
|
114
|
+
messages: [USER_ROW],
|
|
115
|
+
isGenerating: true,
|
|
116
|
+
generatingVerb: 'Thinking',
|
|
117
|
+
provider: 'kenari',
|
|
118
|
+
modelName: 'DeepSeek V4',
|
|
119
|
+
});
|
|
120
|
+
await settle();
|
|
121
|
+
const thinkingDock = thinking.querySelector('[data-composer-dock]');
|
|
122
|
+
const thinkingIndicator = thinking.querySelector('#generating-docked-indicator');
|
|
123
|
+
expect(thinkingDock).not.toBeNull();
|
|
124
|
+
expect(thinkingDock!.contains(thinkingIndicator!)).toBe(true);
|
|
125
|
+
expect(thinking.textContent).toContain('Thinking');
|
|
126
|
+
|
|
127
|
+
// The one fact: no second wrapper may change between the two states.
|
|
128
|
+
expect(thinkingDock!.className).toBe(loadingDock!.className);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('the frame carries the real dock padding on both layouts', async () => {
|
|
132
|
+
const desktop = mount({ messages: [USER_ROW], isGenerating: true });
|
|
133
|
+
await settle();
|
|
134
|
+
const desktopDock = desktop.querySelector('[data-composer-dock]') as HTMLElement;
|
|
135
|
+
// The dock's box, not the landing page's `p-8`.
|
|
136
|
+
expect(desktopDock.className).toContain('p-4');
|
|
137
|
+
expect(desktopDock.className).not.toContain('p-8');
|
|
138
|
+
|
|
139
|
+
render(null, container);
|
|
140
|
+
const mobile = mount({ messages: [USER_ROW], isGenerating: true, variant: 'mobile' });
|
|
141
|
+
await settle();
|
|
142
|
+
const mobileDock = mobile.querySelector('[data-composer-dock]') as HTMLElement;
|
|
143
|
+
expect(mobileDock.className).toContain('px-3');
|
|
144
|
+
expect(mobileDock.className).not.toContain('p-8');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('the landing page keeps the centred column and draws no dock', async () => {
|
|
148
|
+
const el = mount({ messages: [], isGenerating: false });
|
|
149
|
+
await settle();
|
|
150
|
+
expect(el.querySelector('[data-composer-dock]')).toBeNull();
|
|
151
|
+
const column = el.firstElementChild?.firstElementChild as HTMLElement;
|
|
152
|
+
expect(column.className).toContain('my-auto');
|
|
153
|
+
expect(column.className).toContain('justify-center');
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -13,6 +13,7 @@ import { useChatTimeline } from '@/client/hooks/chat/timeline';
|
|
|
13
13
|
import { useSessionTitle } from '@/client/hooks/chat/timeline/session-title';
|
|
14
14
|
import { useSubagentView } from '@/client/hooks/chat/timeline/subagent-view';
|
|
15
15
|
import { useUndoConfirmation } from '@/client/hooks/chat/timeline/undo-confirmation';
|
|
16
|
+
import { useForkSession } from '@/client/hooks/chat/timeline/use-fork-session';
|
|
16
17
|
import { useModelNames } from '@/client/hooks/models/use-model-names';
|
|
17
18
|
import { useRunIdentity } from '@/client/hooks/chat/timeline/run-identity';
|
|
18
19
|
import { useProviderNames } from '@/client/hooks/models/use-provider-names';
|
|
@@ -148,7 +149,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
148
149
|
}, [jumpToUserTurn]);
|
|
149
150
|
|
|
150
151
|
const handleNewChat = newChat.open;
|
|
151
|
-
|
|
152
|
+
const handleFork = useForkSession(sessionId, pushToast);
|
|
152
153
|
const modelNames = useModelNames();
|
|
153
154
|
const { sessionProvider, sessionModelName } = useRunIdentity({ folders, sessionId, sessionData, modelNames });
|
|
154
155
|
const providerNames = useProviderNames();
|
|
@@ -266,6 +267,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
|
|
|
266
267
|
onUndo={handleRequestUndo}
|
|
267
268
|
onRetry={handleRetry}
|
|
268
269
|
onNewChat={handleNewChat}
|
|
270
|
+
onFork={handleFork}
|
|
269
271
|
showScrollBottom={showScrollBottom}
|
|
270
272
|
jumpToBottom={jumpToBottom}
|
|
271
273
|
rowWindow={rowWindow}
|
|
@@ -47,15 +47,17 @@ const ARMED_CLASS = 'bg-ink text-canvas border-ink';
|
|
|
47
47
|
* **Copy and Paste stand in for Cmd+C / Cmd+V**, which is what those chords mean
|
|
48
48
|
* in a terminal and the one thing a phone genuinely cannot do: it has no
|
|
49
49
|
* selection to right-click and no paste without a long-press the terminal canvas
|
|
50
|
-
* does not offer. There is no raw Cmd button because
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
50
|
+
* does not offer. There is no raw Cmd button because the renderer treats Cmd as
|
|
51
|
+
* the host's modifier, not the terminal's: a printable character with `metaKey`
|
|
52
|
+
* set sends nothing (`isPrintableCharacter` returns false), and Cmd+C / Cmd+V
|
|
53
|
+
* are its own copy and paste. A Cmd button would therefore send nothing, while
|
|
54
|
+
* the Cmd chords the user does have keep working untouched. Copy reports when
|
|
55
|
+
* there was no selection rather than flashing a check for a clipboard it did not
|
|
56
|
+
* fill.
|
|
55
57
|
*
|
|
56
|
-
* `pointerdown` is swallowed so tapping a key never moves focus out of
|
|
57
|
-
* hidden
|
|
58
|
-
* the keyboard disappear is worse than no key bar.
|
|
58
|
+
* `pointerdown` is swallowed so tapping a key never moves focus out of the
|
|
59
|
+
* renderer's hidden input: blurring it closes the OS keyboard, and a key bar
|
|
60
|
+
* that makes the keyboard disappear is worse than no key bar.
|
|
59
61
|
*
|
|
60
62
|
* Wrapping, not horizontal scrolling. The diff toolbar taught that a
|
|
61
63
|
* `no-scrollbar` overflow hides actions with nothing on screen to say so
|
|
@@ -2,11 +2,10 @@ import { useEffect, useRef, useState, useImperativeHandle, useCallback } from 'p
|
|
|
2
2
|
import { forwardRef } from 'preact/compat';
|
|
3
3
|
import { ArrowDown } from 'lucide-preact';
|
|
4
4
|
import { useTheme } from '@/client/hooks/ui/theme';
|
|
5
|
-
import {
|
|
6
|
-
import { mountXterm, type XtermMount } from '@/client/components/workspace/terminal-panel/mount';
|
|
5
|
+
import { mountTerminal, type TerminalMount } from '@/client/components/workspace/terminal-panel/mount';
|
|
7
6
|
|
|
8
|
-
export interface
|
|
9
|
-
/** Raw PTY output. Bytes, not text:
|
|
7
|
+
export interface RealtimeTerminalHandle {
|
|
8
|
+
/** Raw PTY output. Bytes, not text: the WASM parser reassembles them. */
|
|
10
9
|
write: (bytes: Uint8Array) => void;
|
|
11
10
|
/**
|
|
12
11
|
* Write the retained scrollback at the size it was drawn for, then fit back
|
|
@@ -26,40 +25,43 @@ export interface RealtimeXtermHandle {
|
|
|
26
25
|
/** The current selection, empty when nothing is selected. */
|
|
27
26
|
getSelection: () => string;
|
|
28
27
|
/**
|
|
29
|
-
* Feed text in as a paste. Goes through
|
|
30
|
-
* wraps it in the bracketed-paste markers when the shell asked for
|
|
31
|
-
* writing the bytes directly would make a multi-line paste execute
|
|
32
|
-
* line in an editor that expects one block.
|
|
28
|
+
* Feed text in as a paste. Goes through the terminal's own `paste`, which is
|
|
29
|
+
* what wraps it in the bracketed-paste markers when the shell asked for
|
|
30
|
+
* them — writing the bytes directly would make a multi-line paste execute
|
|
31
|
+
* line by line in an editor that expects one block.
|
|
33
32
|
*/
|
|
34
33
|
paste: (text: string) => void;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
interface
|
|
36
|
+
interface RealtimeTerminalViewProps {
|
|
38
37
|
/** Keystrokes and paste, raw. */
|
|
39
38
|
onInput: (data: string) => void;
|
|
40
|
-
/** Non-UTF-8 payloads
|
|
41
|
-
onBinaryInput: (
|
|
39
|
+
/** Non-UTF-8 payloads (legacy X10 mouse reports), as latin-1 bytes. */
|
|
40
|
+
onBinaryInput: (bytes: Uint8Array) => void;
|
|
42
41
|
/** The grid changed; the PTY must be resized to match. */
|
|
43
42
|
onGridChange: (cols: number, rows: number) => void;
|
|
44
43
|
/** The terminal is measurable and knows its size; attach with these. */
|
|
45
44
|
onReady: (cols: number, rows: number) => void;
|
|
46
|
-
/**
|
|
47
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The theme changed and the terminal was rebuilt with the new palette; the
|
|
47
|
+
* server's retained scrollback has to be requested again.
|
|
48
|
+
*/
|
|
49
|
+
onReattach?: () => void;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
*
|
|
53
|
+
* ghostty-web view bound to a real PTY.
|
|
52
54
|
*
|
|
53
55
|
* Every keystroke goes to the shell as bytes — line editing, history, tab
|
|
54
56
|
* completion and Ctrl+C are the shell's job, not this component's. Output is
|
|
55
57
|
* written as bytes so a character split across two PTY reads is reassembled by
|
|
56
|
-
*
|
|
58
|
+
* the WASM parser rather than by a decode step here.
|
|
57
59
|
*/
|
|
58
|
-
export const
|
|
59
|
-
({ onInput, onBinaryInput, onGridChange, onReady,
|
|
60
|
+
export const RealtimeTerminalView = forwardRef<RealtimeTerminalHandle, RealtimeTerminalViewProps>(
|
|
61
|
+
({ onInput, onBinaryInput, onGridChange, onReady, onReattach }, ref) => {
|
|
60
62
|
const { theme } = useTheme();
|
|
61
63
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
62
|
-
const mountRef = useRef<
|
|
64
|
+
const mountRef = useRef<TerminalMount | null>(null);
|
|
63
65
|
const [isScrolledUp, setIsScrolledUp] = useState(false);
|
|
64
66
|
|
|
65
67
|
const inputRef = useRef(onInput);
|
|
@@ -70,63 +72,50 @@ export const RealtimeXtermView = forwardRef<RealtimeXtermHandle, RealtimeXtermVi
|
|
|
70
72
|
gridChangeRef.current = onGridChange;
|
|
71
73
|
const readyRef = useRef(onReady);
|
|
72
74
|
readyRef.current = onReady;
|
|
75
|
+
const reattachRef = useRef(onReattach);
|
|
76
|
+
reattachRef.current = onReattach;
|
|
73
77
|
const themeRef = useRef(theme);
|
|
74
78
|
themeRef.current = theme;
|
|
75
|
-
// Read when the async mount RESOLVES, not when this effect ran: `mountXterm`
|
|
76
|
-
// imports xterm and the WebGL addon, so `mountRef.current` is still null on
|
|
77
|
-
// the first pass and an effect that only ran then would leave the context
|
|
78
|
-
// held by a panel that was never on screen.
|
|
79
|
-
const visibleRef = useRef(visible);
|
|
80
|
-
visibleRef.current = visible;
|
|
81
|
-
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
const term = mountRef.current?.term;
|
|
84
|
-
if (!term) return;
|
|
85
|
-
term.options.theme = getXtermTheme(theme);
|
|
86
|
-
term.refresh(0, term.rows - 1);
|
|
87
|
-
}, [theme]);
|
|
88
79
|
|
|
89
80
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* hidden, because it owns a PTY. That made its GPU context permanent: eight
|
|
95
|
-
* terminals held eight contexts, and `vmmap` on the desktop shell showed
|
|
96
|
-
* `owned unmapped (graphics)` at 541.8 MB of an 817.7 MB footprint while the
|
|
97
|
-
* JS heap was 12.6 MB. Releasing on hide drops the context — xterm's DOM
|
|
98
|
-
* renderer keeps the buffer readable — and showing the panel re-creates it.
|
|
81
|
+
* The WASM palette is fixed when the terminal is created, so a theme switch
|
|
82
|
+
* is a terminal rebuild plus a scrollback replay, not a repaint. The effect
|
|
83
|
+
* runs before the async mount resolves on first render (`mountRef` is null
|
|
84
|
+
* then); that initial theme is the one `mountTerminal` was called with.
|
|
99
85
|
*/
|
|
100
86
|
useEffect(() => {
|
|
101
|
-
mountRef.current
|
|
102
|
-
|
|
87
|
+
const mount = mountRef.current;
|
|
88
|
+
if (!mount) return;
|
|
89
|
+
mount.setTheme(theme);
|
|
90
|
+
reattachRef.current?.();
|
|
91
|
+
}, [theme]);
|
|
103
92
|
|
|
104
93
|
useImperativeHandle(ref, () => ({
|
|
105
94
|
write(bytes: Uint8Array) {
|
|
106
|
-
mountRef.current?.
|
|
95
|
+
mountRef.current?.write(bytes);
|
|
107
96
|
},
|
|
108
97
|
writeReplay(bytes: Uint8Array, cols: number, rows: number) {
|
|
109
98
|
mountRef.current?.writeReplay(bytes, cols, rows);
|
|
110
99
|
},
|
|
111
100
|
reset() {
|
|
112
|
-
mountRef.current?.
|
|
101
|
+
mountRef.current?.reset();
|
|
113
102
|
},
|
|
114
103
|
focus() {
|
|
115
|
-
mountRef.current?.
|
|
104
|
+
mountRef.current?.focus();
|
|
116
105
|
},
|
|
117
106
|
applicationCursorKeys() {
|
|
118
|
-
return mountRef.current?.
|
|
107
|
+
return mountRef.current?.applicationCursorKeys() ?? false;
|
|
119
108
|
},
|
|
120
109
|
getSelection() {
|
|
121
|
-
return mountRef.current?.
|
|
110
|
+
return mountRef.current?.getSelection() ?? '';
|
|
122
111
|
},
|
|
123
112
|
paste(text: string) {
|
|
124
|
-
mountRef.current?.
|
|
113
|
+
mountRef.current?.paste(text);
|
|
125
114
|
},
|
|
126
115
|
}), []);
|
|
127
116
|
|
|
128
117
|
const scrollToBottom = useCallback(() => {
|
|
129
|
-
mountRef.current?.
|
|
118
|
+
mountRef.current?.scrollToBottom();
|
|
130
119
|
setIsScrolledUp(false);
|
|
131
120
|
}, []);
|
|
132
121
|
|
|
@@ -137,12 +126,12 @@ export const RealtimeXtermView = forwardRef<RealtimeXtermHandle, RealtimeXtermVi
|
|
|
137
126
|
if (!container) return;
|
|
138
127
|
let cancelled = false;
|
|
139
128
|
|
|
140
|
-
void
|
|
129
|
+
void mountTerminal(
|
|
141
130
|
container,
|
|
142
131
|
themeRef.current,
|
|
143
132
|
{
|
|
144
133
|
onInput: (data) => inputRef.current(data),
|
|
145
|
-
onBinaryInput: (
|
|
134
|
+
onBinaryInput: (bytes) => binaryInputRef.current(bytes),
|
|
146
135
|
onGridChange: (cols, rows) => gridChangeRef.current(cols, rows),
|
|
147
136
|
onReady: (cols, rows) => readyRef.current(cols, rows),
|
|
148
137
|
onScrolledUpChange: setIsScrolledUp,
|
|
@@ -155,10 +144,9 @@ export const RealtimeXtermView = forwardRef<RealtimeXtermHandle, RealtimeXtermVi
|
|
|
155
144
|
return;
|
|
156
145
|
}
|
|
157
146
|
mountRef.current = mount;
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
mount.setWebgl(visibleRef.current);
|
|
147
|
+
// E2E types into the terminal's hidden input. The renderer creates it
|
|
148
|
+
// inside `open`, so the hook cannot be written on the JSX element.
|
|
149
|
+
container.querySelector('textarea')?.setAttribute('data-terminal-input', '');
|
|
162
150
|
});
|
|
163
151
|
|
|
164
152
|
return () => {
|
|
@@ -168,11 +156,16 @@ export const RealtimeXtermView = forwardRef<RealtimeXtermHandle, RealtimeXtermVi
|
|
|
168
156
|
};
|
|
169
157
|
}, []);
|
|
170
158
|
|
|
159
|
+
// No background and no padding: the terminal is not a surface of its own,
|
|
160
|
+
// and the panel's paper shows through the strip the fit addon leaves for
|
|
161
|
+
// its in-canvas scrollbar. `p-1.5` also made the grid narrower than the
|
|
162
|
+
// panel, which read as a terminal that was not full width.
|
|
171
163
|
return (
|
|
172
|
-
<div className="relative flex-1 w-full h-full
|
|
164
|
+
<div className="relative flex-1 w-full h-full overflow-hidden">
|
|
173
165
|
<div
|
|
174
166
|
ref={containerRef}
|
|
175
|
-
|
|
167
|
+
data-terminal-root=""
|
|
168
|
+
className="kabmo-terminal w-full h-full cursor-text"
|
|
176
169
|
style={{ height: '100%', width: '100%' }}
|
|
177
170
|
/>
|
|
178
171
|
|
|
@@ -192,4 +185,4 @@ export const RealtimeXtermView = forwardRef<RealtimeXtermHandle, RealtimeXtermVi
|
|
|
192
185
|
}
|
|
193
186
|
);
|
|
194
187
|
|
|
195
|
-
|
|
188
|
+
RealtimeTerminalView.displayName = 'RealtimeTerminalView';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import { gridForContainer } from '@/client/components/workspace/terminal-panel/fit';
|
|
8
|
+
|
|
9
|
+
// The measured cell box at 12 px Fira Code.
|
|
10
|
+
const CELL = { width: 8, height: 16 };
|
|
11
|
+
|
|
12
|
+
describe('gridForContainer', () => {
|
|
13
|
+
test('divides the whole panel, with no scrollbar reservation', () => {
|
|
14
|
+
// 334 × 759 is the host measured in the right panel at 1440 × 900.
|
|
15
|
+
// ghostty-web's own proposal subtracts 15 px first and would answer 39;
|
|
16
|
+
// that shortfall is what read as a terminal that was not full width.
|
|
17
|
+
expect(gridForContainer(334, 759, CELL)).toEqual({ cols: 41, rows: 47 });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('drops the sub-cell remainder instead of overflowing the box', () => {
|
|
21
|
+
// One pixel short of a column still fits 41; the extra 7 px of a 335 box
|
|
22
|
+
// must not become a 42nd cell that hangs outside the panel.
|
|
23
|
+
expect(gridForContainer(335, 767, CELL)).toEqual({ cols: 41, rows: 47 });
|
|
24
|
+
expect(gridForContainer(333, 758, CELL)).toEqual({ cols: 41, rows: 47 });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('keeps a usable grid for a box smaller than a cell', () => {
|
|
28
|
+
// A hidden panel measures 0 while the view stays mounted; the caller guards
|
|
29
|
+
// that, and this floor is the last line of defence against 0 × 0.
|
|
30
|
+
expect(gridForContainer(0, 0, CELL)).toEqual({ cols: 2, rows: 1 });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('refuses to divide by an unmeasured cell', () => {
|
|
34
|
+
expect(gridForContainer(320, 640, { width: 0, height: 16 })).toBeNull();
|
|
35
|
+
expect(gridForContainer(320, 640, { width: 8, height: 0 })).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fit the terminal's grid to the whole container.
|
|
8
|
+
*
|
|
9
|
+
* ghostty-web's `FitAddon.proposeDimensions` subtracts a hard-coded 15 px for
|
|
10
|
+
* its in-canvas scrollbar before dividing by the cell width, so the grid always
|
|
11
|
+
* stopped one to three columns short of the panel: with the terminal painting
|
|
12
|
+
* its own background that showed as a strip, and a full-width TUI (tmux status
|
|
13
|
+
* line, `htop`) ran out of room the panel visibly had. The scrollbar is drawn
|
|
14
|
+
* INSIDE the canvas, 8 px at the right edge and only while scrolling, so the
|
|
15
|
+
* reservation buys nothing here — it can overlap the last column instead.
|
|
16
|
+
*
|
|
17
|
+
* Everything else stays the addon's: it resizes only when the grid changes and
|
|
18
|
+
* it still reads `renderer.getMetrics()`, which is Kabmo's measured cell box
|
|
19
|
+
* (see `installCellMetrics` in `fonts.ts`).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { FitAddon, Terminal } from 'ghostty-web';
|
|
23
|
+
import type { TerminalCellMetrics } from '@/client/components/workspace/terminal-panel/fonts';
|
|
24
|
+
|
|
25
|
+
export interface TerminalGrid {
|
|
26
|
+
cols: number;
|
|
27
|
+
rows: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The grid a box of `width` × `height` CSS px holds, at the measured cell size.
|
|
32
|
+
*
|
|
33
|
+
* Pure, so the arithmetic is pinned without a renderer: it divides the FULL box,
|
|
34
|
+
* with the container's own padding subtracted because the host may keep some.
|
|
35
|
+
*/
|
|
36
|
+
export function gridForContainer(
|
|
37
|
+
width: number,
|
|
38
|
+
height: number,
|
|
39
|
+
metrics: Pick<TerminalCellMetrics, 'width' | 'height'>,
|
|
40
|
+
): TerminalGrid | null {
|
|
41
|
+
if (!metrics.width || !metrics.height) return null;
|
|
42
|
+
return {
|
|
43
|
+
cols: Math.max(2, Math.floor(width / metrics.width)),
|
|
44
|
+
rows: Math.max(1, Math.floor(height / metrics.height)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Replace the addon's proposal with `gridForContainer` over the live host. */
|
|
49
|
+
export function installFullWidthFit(fitAddon: FitAddon, term: Terminal): void {
|
|
50
|
+
const addon = fitAddon as unknown as {
|
|
51
|
+
proposeDimensions: () => TerminalGrid | undefined;
|
|
52
|
+
};
|
|
53
|
+
addon.proposeDimensions = () => {
|
|
54
|
+
const host = term.element;
|
|
55
|
+
const metrics = term.renderer?.getMetrics();
|
|
56
|
+
if (!host || !metrics) return undefined;
|
|
57
|
+
const style = getComputedStyle(host);
|
|
58
|
+
const padX = (parseFloat(style.paddingLeft) || 0) + (parseFloat(style.paddingRight) || 0);
|
|
59
|
+
const padY = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
|
|
60
|
+
return (
|
|
61
|
+
gridForContainer(host.clientWidth - padX, host.clientHeight - padY, metrics) ?? undefined
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
}
|