ompchamber 0.8.0 → 1.0.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 (79) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/static/css/{index.5c0447cefe.css → index.e880517fcd.css} +1 -1
  3. package/dist/client/static/js/async/g.a06ca3b3e9.js +2 -0
  4. package/dist/client/static/js/async/{m.0896dab823.js → m.c038c71b9f.js} +2 -2
  5. package/dist/client/static/js/async/ms.98960af4eb.js +67 -0
  6. package/dist/client/static/js/async/ms.98960af4eb.js.LICENSE.txt +12 -0
  7. package/dist/client/static/js/async/ot.84c71b308f.js +2 -0
  8. package/dist/client/static/js/async/{x4.69ec69c61b.js.LICENSE.txt → ot.84c71b308f.js.LICENSE.txt} +5 -0
  9. package/dist/client/static/js/{index.dc5f5fabe8.js → index.0de15c5e17.js} +10 -10
  10. package/package.json +2 -1
  11. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +1 -1
  12. package/src/client/components/layout/session-sidebar/SessionItem.tsx +1 -1
  13. package/src/client/components/layout/session-sidebar/SessionList.tsx +1 -1
  14. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +1 -1
  15. package/src/client/components/mobile/mobile-session-sidebar/List.tsx +1 -1
  16. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +2 -2
  17. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +11 -4
  18. package/src/client/components/workspace/chat-timeline/QueueList.tsx +18 -14
  19. package/src/client/components/workspace/chat-timeline/index.tsx +4 -2
  20. package/src/client/components/workspace/git-panel/BranchToolbar.tsx +2 -2
  21. package/src/client/components/workspace/git-panel/index.tsx +5 -1
  22. package/src/client/components/workspace/terminal-panel/Header.tsx +51 -19
  23. package/src/client/components/workspace/terminal-panel/RealtimeXtermView.tsx +86 -282
  24. package/src/client/components/workspace/terminal-panel/index.tsx +76 -50
  25. package/src/client/components/workspace/terminal-panel/mount.ts +275 -0
  26. package/src/client/data/theme/terminal.ts +27 -29
  27. package/src/client/hooks/chat/omp/session-list.tsx +19 -2
  28. package/src/client/hooks/chat/omp/session-sidebar-controller.ts +1 -1
  29. package/src/client/hooks/chat/timeline/actions.ts +23 -25
  30. package/src/client/hooks/chat/timeline/index.ts +12 -20
  31. package/src/client/hooks/chat/timeline/queue.ts +110 -46
  32. package/src/client/hooks/workspace/terminal/index.ts +217 -0
  33. package/src/client/hooks/workspace/terminal/socket.ts +227 -0
  34. package/src/server/db.server.ts +19 -0
  35. package/src/server/lib/fs/git-sync.ts +191 -0
  36. package/src/server/lib/omp/rpc/manager.ts +58 -3
  37. package/src/server/lib/omp/rpc/session-commands.ts +6 -0
  38. package/src/server/lib/omp/session/sidebar-data.server.ts +3 -3
  39. package/src/server/lib/queue/delivery.server.ts +114 -0
  40. package/src/server/lib/queue/schema-migration.server.ts +50 -0
  41. package/src/server/lib/queue/store.server.ts +185 -0
  42. package/src/server/lib/terminal/foreground.ts +73 -0
  43. package/src/server/lib/terminal/history.test.ts +118 -0
  44. package/src/server/lib/terminal/history.ts +205 -0
  45. package/src/server/lib/terminal/runtime.server.ts +338 -0
  46. package/src/server/lib/terminal/session.server.ts +215 -0
  47. package/src/server/lib/terminal/shell.test.ts +97 -0
  48. package/src/server/lib/terminal/shell.ts +103 -0
  49. package/src/server/routes/fs/git.ts +22 -12
  50. package/src/server/routes/index.ts +2 -1
  51. package/src/server/routes/sessions/index.ts +11 -3
  52. package/src/server/routes/sessions/queue.ts +121 -0
  53. package/src/server/routes/sessions/session.ts +1 -132
  54. package/src/server/routes/settings/commands.ts +1 -1
  55. package/src/server/routes/terminal/index.ts +2 -2
  56. package/src/server/routes/terminal/run.ts +8 -100
  57. package/src/server/routes/terminal/sessions.ts +24 -0
  58. package/src/server/routes/terminal/ws.ts +149 -0
  59. package/src/shared/lib/chat/omp/agent-events.test.ts +37 -1
  60. package/src/shared/lib/chat/omp/agent-events.ts +30 -0
  61. package/src/shared/lib/chat/timeline/omp-callbacks.test.ts +9 -1
  62. package/src/shared/lib/chat/timeline/omp-callbacks.ts +45 -8
  63. package/src/shared/lib/omp/session/stream-state.server.ts +2 -3
  64. package/src/shared/lib/workspace/session-state/store.ts +1 -4
  65. package/src/shared/lib/workspace/terminal/protocol.ts +222 -0
  66. package/src/shared/types/omp/agent.ts +12 -0
  67. package/src/shared/types/terminal.ts +17 -15
  68. package/src/shared/types/workspace.ts +2 -2
  69. package/dist/client/static/js/async/g.d1c2fe09aa.js +0 -2
  70. package/dist/client/static/js/async/x4.69ec69c61b.js +0 -6
  71. package/src/client/components/workspace/terminal-panel/InputBar.tsx +0 -82
  72. package/src/client/components/workspace/terminal-panel/LogEntry.tsx +0 -70
  73. package/src/client/hooks/workspace/terminal-output.ts +0 -66
  74. package/src/client/hooks/workspace/terminal.ts +0 -283
  75. package/src/server/lib/fs/terminal-cwd.ts +0 -49
  76. package/src/server/routes/terminal/stream.ts +0 -100
  77. /package/dist/client/static/js/async/{g.d1c2fe09aa.js.LICENSE.txt → g.a06ca3b3e9.js.LICENSE.txt} +0 -0
  78. /package/dist/client/static/js/async/{m.0896dab823.js.LICENSE.txt → m.c038c71b9f.js.LICENSE.txt} +0 -0
  79. /package/dist/client/static/js/{index.dc5f5fabe8.js.LICENSE.txt → index.0de15c5e17.js.LICENSE.txt} +0 -0
@@ -0,0 +1,275 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Mounts an xterm instance on a container and keeps it bound to a PTY.
8
+ *
9
+ * Extracted from the view component so the mount lifecycle (xterm import, fit
10
+ * addon, input wiring, observers) stays readable and the component remains a
11
+ * render layer. Everything the caller must know travels through `callbacks`;
12
+ * the returned handle is the only way back in.
13
+ *
14
+ * Two behaviours here are deliberate:
15
+ *
16
+ * - **Attach waits for a real grid.** The terminal panel stays mounted while
17
+ * its view is CSS-hidden (that is what keeps a shell alive across panel
18
+ * switches), and a hidden container measures 0px — fitting is skipped and
19
+ * xterm keeps its 80x24 default. Attaching then would create the shell at a
20
+ * size the panel never had, and the retained scrollback would replay at that
21
+ * width forever. So attach is driven by the same ResizeObserver that detects
22
+ * the panel becoming visible.
23
+ * - **Raw bytes in, raw bytes out.** `onData`/`onBinary` forward keystrokes
24
+ * untouched, and `write` takes a `Uint8Array` so xterm's streaming UTF-8
25
+ * decoder reassembles a character split across two PTY reads.
26
+ * - **xterm and the WebGL addon are dynamically imported on purpose.** xterm is
27
+ * ~300 KB and the addon pulls a WebGL context into the panel; both stay out
28
+ * of the initial client bundle until the terminal panel is actually opened.
29
+ * The module shape varies by build, hence the probe pattern below.
30
+ */
31
+
32
+ import type { Terminal } from '@xterm/xterm';
33
+ import type { FitAddon } from '@xterm/addon-fit';
34
+ import type { WebglAddon } from '@xterm/addon-webgl';
35
+ import {
36
+ getXtermTheme,
37
+ XTERM_FONT_FAMILY,
38
+ safePatchFitAddon,
39
+ safePatchRenderService,
40
+ type XtermCore,
41
+ type XtermModule,
42
+ } from '@/client/data/theme/terminal';
43
+
44
+ export interface XtermMountCallbacks {
45
+ /** Keystrokes, paste, mouse reports — straight to the PTY. */
46
+ onInput: (data: string) => void;
47
+ /** Non-UTF-8 payloads xterm reports separately (some mouse reports). */
48
+ onBinaryInput: (data: string) => void;
49
+ /** The grid changed; the PTY must be resized to match. */
50
+ onGridChange: (cols: number, rows: number) => void;
51
+ /** The terminal is measurable and knows its size; attach with these. */
52
+ onReady: (cols: number, rows: number) => void;
53
+ /** Viewport scrolled away from the live bottom. */
54
+ onScrolledUpChange: (scrolledUp: boolean) => void;
55
+ }
56
+
57
+ export interface XtermMount {
58
+ term: Terminal;
59
+ fitAddon: FitAddon;
60
+ /**
61
+ * Lay the retained scrollback out at the size it was drawn for, then fit the
62
+ * panel. Grid reports are suppressed until the replay has been consumed.
63
+ */
64
+ writeReplay: (bytes: Uint8Array, cols: number, rows: number) => void;
65
+ dispose: () => void;
66
+ }
67
+
68
+ /**
69
+ * Mount xterm inside `container`. Resolves to null when the module could not be
70
+ * loaded or the component unmounted while importing.
71
+ */
72
+ export async function mountXterm(
73
+ container: HTMLElement,
74
+ isDark: boolean,
75
+ callbacks: XtermMountCallbacks,
76
+ isCancelled: () => boolean,
77
+ ): Promise<XtermMount | null> {
78
+ // Dynamic on purpose: xterm is ~300 KB and is only needed once the terminal
79
+ // panel is actually opened, so it stays out of the initial client bundle
80
+ // (the module shape varies by build, hence the probes).
81
+ const xtermModule = (await import('@xterm/xterm')) as unknown as XtermModule<typeof Terminal>;
82
+ const fitModule = (await import('@xterm/addon-fit')) as unknown as XtermModule<typeof FitAddon>;
83
+
84
+ const TerminalClass = xtermModule.Terminal || xtermModule.default?.Terminal || xtermModule.default;
85
+ const FitAddonClass = fitModule.FitAddon || fitModule.default?.FitAddon || fitModule.default;
86
+ if (!TerminalClass || !FitAddonClass || isCancelled()) return null;
87
+
88
+ safePatchFitAddon(FitAddonClass);
89
+
90
+ const term = new TerminalClass({
91
+ cursorBlink: true,
92
+ cursorStyle: 'block',
93
+ fontSize: 12,
94
+ lineHeight: 1.25,
95
+ fontFamily: XTERM_FONT_FAMILY,
96
+ theme: getXtermTheme(isDark),
97
+ // No `convertEol`: the PTY already emits CRLF, and converting a lone LF
98
+ // would re-introduce the line-feed doubling a real terminal avoids.
99
+ scrollback: 10000,
100
+ scrollSensitivity: 1.5,
101
+ fastScrollSensitivity: 5,
102
+ smoothScrollDuration: 0,
103
+ allowProposedApi: true,
104
+ }) as Terminal;
105
+
106
+ term.open(container);
107
+ safePatchRenderService(term);
108
+
109
+ // WebGL renderer: draws powerline glyphs (U+E0B0 etc.) as full-cell vector
110
+ // paths, so segmented prompts stay seamless the way a local terminal does.
111
+ // The DOM renderer draws them as ordinary glyphs inside the font box, which
112
+ // leaves notches at every segment joint. WebGL can fail (no GPU context,
113
+ // context-lost), and the DOM renderer is the automatic fallback.
114
+ try {
115
+ const webglModule = (await import('@xterm/addon-webgl')) as unknown as {
116
+ WebglAddon?: typeof WebglAddon;
117
+ default?: { WebglAddon?: typeof WebglAddon } & typeof WebglAddon;
118
+ };
119
+ const WebglAddonClass = webglModule.WebglAddon || webglModule.default?.WebglAddon || webglModule.default;
120
+ if (WebglAddonClass) {
121
+ const webgl = new WebglAddonClass() as WebglAddon;
122
+ webgl.onContextLoss(() => webgl.dispose());
123
+ term.loadAddon(webgl);
124
+ }
125
+ } catch {}
126
+
127
+ const fitAddon = new FitAddonClass() as FitAddon;
128
+ term.loadAddon(fitAddon);
129
+
130
+ term.attachCustomKeyEventHandler((event: globalThis.KeyboardEvent) => handleKeyNavigation(term, event));
131
+
132
+ const disposables = [
133
+ term.onScroll(() => {
134
+ const buffer = term.buffer.active;
135
+ callbacks.onScrolledUpChange(buffer.viewportY < buffer.baseY);
136
+ }),
137
+ term.onData((data: string) => callbacks.onInput(data)),
138
+ term.onBinary((data: string) => callbacks.onBinaryInput(data)),
139
+ // FitAddon changes the grid on fit; the shell has to hear about it or a TUI
140
+ // keeps drawing at the old width. Reports are dropped while the replay is
141
+ // being laid out: that grid belongs to the recorded history, not the panel.
142
+ term.onResize(({ cols, rows }) => {
143
+ if (replaying) return;
144
+ callbacks.onGridChange(cols, rows);
145
+ }),
146
+ ];
147
+
148
+ let attached = false;
149
+ let fitTimer: ReturnType<typeof setTimeout> | null = null;
150
+ let frame: number | null = null;
151
+ /**
152
+ * Set while the retained scrollback is being laid out at its recorded size.
153
+ * That transient grid is not the panel's, so it must not be reported as a
154
+ * resize — the shell would answer with a prompt repaint for a size the user
155
+ * never chose, which is how a reattach used to print a second prompt.
156
+ */
157
+ let replaying = false;
158
+
159
+ const safeFit = () => {
160
+ if (isCancelled()) return;
161
+ if (container.clientWidth <= 0 || container.clientHeight <= 0) return;
162
+ const core = (term as unknown as XtermCore)._core;
163
+ const dims = core?._renderService?.dimensions;
164
+ if (!dims?.css?.cell?.width || !dims?.css?.cell?.height) return;
165
+ try {
166
+ fitAddon.fit();
167
+ } catch {}
168
+ };
169
+
170
+ /** Fit now, once xterm has consumed everything already queued. */
171
+ const fitAfterWrites = () => {
172
+ term.write('', () => {
173
+ if (isCancelled()) return;
174
+ replaying = false;
175
+ safeFit();
176
+ });
177
+ };
178
+
179
+ /**
180
+ * Lay the retained scrollback out at the size it was drawn for, then converge
181
+ * on the panel's grid. Re-wrapping history at another width leaves wrapped
182
+ * fragments the shell's own redraw never clears.
183
+ */
184
+ const writeReplay = (bytes: Uint8Array, cols: number, rows: number) => {
185
+ replaying = true;
186
+ if (term.cols !== cols || term.rows !== rows) term.resize(cols, rows);
187
+ if (bytes.length === 0) {
188
+ fitAfterWrites();
189
+ return;
190
+ }
191
+ term.write(bytes, fitAfterWrites);
192
+ };
193
+
194
+ const attachIfSized = () => {
195
+ if (attached || isCancelled()) return;
196
+ if (container.clientWidth <= 0 || container.clientHeight <= 0) return;
197
+ const core = (term as unknown as XtermCore)._core;
198
+ if (!core?._renderService?.dimensions?.css?.cell?.width) return;
199
+ attached = true;
200
+ callbacks.onReady(term.cols, term.rows);
201
+ term.focus();
202
+ };
203
+
204
+ const resizeObserver = new ResizeObserver(() => {
205
+ if (fitTimer) clearTimeout(fitTimer);
206
+ fitTimer = setTimeout(() => {
207
+ safeFit();
208
+ // A panel that was hidden at mount becomes measurable here, which is when
209
+ // the shell should be created — at its real size.
210
+ attachIfSized();
211
+ }, 35);
212
+ });
213
+ resizeObserver.observe(container);
214
+
215
+ const touch = attachTouchScroll(container, term);
216
+
217
+ // The container may already be measurable (the view was active at mount), in
218
+ // which case the observer never fires a first time.
219
+ frame = requestAnimationFrame(() => {
220
+ safeFit();
221
+ attachIfSized();
222
+ });
223
+
224
+ return {
225
+ term,
226
+ fitAddon,
227
+ writeReplay,
228
+ dispose() {
229
+ if (frame !== null) cancelAnimationFrame(frame);
230
+ clearTimeout(fitTimer ?? undefined);
231
+ touch();
232
+ for (const disposable of disposables) disposable.dispose();
233
+ resizeObserver.disconnect();
234
+ try {
235
+ fitAddon.dispose();
236
+ } catch {}
237
+ try {
238
+ term.dispose();
239
+ } catch {}
240
+ },
241
+ };
242
+ }
243
+
244
+ /** Shift+PageUp/Home/End scroll the viewport instead of reaching the shell. */
245
+ function handleKeyNavigation(term: Terminal, event: globalThis.KeyboardEvent): boolean {
246
+ if (event.type !== 'keydown' || !event.shiftKey) return true;
247
+ if (event.key === 'PageUp') { term.scrollPages(-1); return false; }
248
+ if (event.key === 'PageDown') { term.scrollPages(1); return false; }
249
+ if (event.key === 'Home') { term.scrollToTop(); return false; }
250
+ if (event.key === 'End') { term.scrollToBottom(); return false; }
251
+ if (event.key === 'ArrowUp') { term.scrollLines(-1); return false; }
252
+ if (event.key === 'ArrowDown') { term.scrollLines(1); return false; }
253
+ return true;
254
+ }
255
+
256
+ /** Touch drags scroll the scrollback; xterm has no touch handling of its own. */
257
+ function attachTouchScroll(container: HTMLElement, term: Terminal): () => void {
258
+ let startY = 0;
259
+ const onStart = (event: globalThis.TouchEvent) => {
260
+ if (event.touches.length === 1) startY = event.touches[0].clientY;
261
+ };
262
+ const onMove = (event: globalThis.TouchEvent) => {
263
+ if (event.touches.length !== 1) return;
264
+ const deltaY = startY - event.touches[0].clientY;
265
+ if (Math.abs(deltaY) < 16) return;
266
+ term.scrollLines(Math.trunc(deltaY / 16));
267
+ startY = event.touches[0].clientY;
268
+ };
269
+ container.addEventListener('touchstart', onStart, { passive: true });
270
+ container.addEventListener('touchmove', onMove, { passive: true });
271
+ return () => {
272
+ container.removeEventListener('touchstart', onStart);
273
+ container.removeEventListener('touchmove', onMove);
274
+ };
275
+ }
@@ -54,7 +54,33 @@ export function getXtermTheme(isDark: boolean) {
54
54
 
55
55
  export const XTERM_THEME = XTERM_DARK_THEME;
56
56
 
57
- export const XTERM_FONT_FAMILY = "'Fira Code', Menlo, Monaco, 'Courier New', monospace";
57
+ /**
58
+ * Font stack for the terminal canvas.
59
+ *
60
+ * The glyph fallbacks after the text faces are load-bearing. A shell prompt is
61
+ * usually drawn with private-use symbols (powerline separators, devicons,
62
+ * Material Design icons) that **no** coding webfont contains — `@fontsource/
63
+ * fira-code`'s latin subset maps 226 codepoints and not one of them is above
64
+ * U+FFFF — so without a face that supplies them the browser paints a hollow
65
+ * tofu box for every prompt segment. The names below cover the Nerd Font
66
+ * families a user is most likely to have installed (plus the *fontconfig*
67
+ * symbol faces on Linux); a face that is absent is simply skipped by the
68
+ * normal fallback chain, so listing many costs nothing.
69
+ *
70
+ * This is the same shape OpenChamber ships (`TERMINAL_GLYPH_FALLBACKS` in its
71
+ * `ghostty/surface.ts`), which additionally bundles `SymbolsNerdFontMono` as a
72
+ * webfont so the coverage never depends on the machine.
73
+ *
74
+ * Only glyphs the text face lacks reach these entries, so Latin metrics are
75
+ * untouched — verified: `A`/`m`/`W` keep identical advance and ink.
76
+ */
77
+ export const XTERM_GLYPH_FALLBACKS =
78
+ "'FiraCode Nerd Font Mono', 'FiraCode Nerd Font', 'JetBrainsMono Nerd Font', " +
79
+ "'JetBrainsMono NF', 'JetBrains Mono Nerd Font', 'Hack Nerd Font', 'MesloLGS NF', " +
80
+ "'MesloLGM Nerd Font', 'CaskaydiaCove Nerd Font', 'SauceCodePro Nerd Font', " +
81
+ "'Symbols Nerd Font Mono', 'Symbols Nerd Font', 'PowerlineSymbols'";
82
+
83
+ export const XTERM_FONT_FAMILY = `'Fira Code', ${XTERM_GLYPH_FALLBACKS}, Menlo, Monaco, 'Courier New', monospace`;
58
84
 
59
85
  /** xterm's private render service, read only to size-check before fitting. */
60
86
  export interface XtermCore {
@@ -120,31 +146,3 @@ export function safePatchRenderService(term: any) {
120
146
  }
121
147
  } catch {}
122
148
  }
123
-
124
- let terminalSessionOutput = '';
125
-
126
- export function getTerminalSessionOutput(): string {
127
- return terminalSessionOutput;
128
- }
129
-
130
- export function appendTerminalSessionOutput(chunk: string): void {
131
- terminalSessionOutput += chunk;
132
- if (terminalSessionOutput.length > 250000) {
133
- terminalSessionOutput = terminalSessionOutput.slice(-200000);
134
- }
135
- }
136
-
137
- export function clearTerminalSessionOutput(): void {
138
- terminalSessionOutput = '';
139
- }
140
-
141
- const TERMINAL_OUTPUT_SNAPSHOT_LIMIT = 8000;
142
-
143
- export function getTerminalOutputSnapshot(): string {
144
- if (terminalSessionOutput.length <= TERMINAL_OUTPUT_SNAPSHOT_LIMIT) return terminalSessionOutput;
145
- return terminalSessionOutput.slice(-TERMINAL_OUTPUT_SNAPSHOT_LIMIT);
146
- }
147
-
148
- export function setTerminalOutputSnapshot(value: string): void {
149
- terminalSessionOutput = value;
150
- }
@@ -116,11 +116,28 @@ export function SidebarDataProvider({ children, initialFolders = [] }: { childre
116
116
  const value = useMemo<SidebarDataHandle>(() => {
117
117
  const data = fetcher.data;
118
118
  const seen = seenRef.current;
119
+ // A session that streams again earns a fresh badge lifecycle: forget the
120
+ // ack from an earlier run. Without this, a session opened with a terminal
121
+ // badge stays stripped for the whole mount — its spinner never renders no
122
+ // matter how many times the list refetches, and only a page reload (fresh
123
+ // mount) brings it back.
124
+ if (seen.size && data?.folders) {
125
+ for (const folder of data.folders) {
126
+ for (const session of folder.sessions ?? []) {
127
+ if (session.streamStatus === 'stream') seen.delete(String(session.id));
128
+ }
129
+ }
130
+ }
119
131
  return {
120
132
  folders: ((data?.folders ?? initialFolders) as WorkspaceFolderData[])
121
- // Optimistic badge strip for sessions marked seen this mount.
133
+ // Optimistic badge strip for sessions marked seen this mount. NEVER
134
+ // strip a live `stream` row — the spinner must always render.
122
135
  .map((f) => seen.size
123
- ? { ...f, sessions: (f.sessions ?? []).map((s) => (seen.has(String(s.id)) ? { ...s, streamStatus: undefined } : s)) }
136
+ ? { ...f, sessions: (f.sessions ?? []).map((s) => (
137
+ seen.has(String(s.id)) && s.streamStatus && s.streamStatus !== 'stream'
138
+ ? { ...s, streamStatus: undefined }
139
+ : s
140
+ )) }
124
141
  : f),
125
142
  isMock: data?.isMock ?? false,
126
143
  initializing: !hasLoaded,
@@ -62,7 +62,7 @@ export interface SessionSidebarController {
62
62
  sortOption: SessionSortOption;
63
63
  handleSortChange: (opt: SessionSortOption) => void;
64
64
  processedFolders: WorkspaceFolderData[];
65
- sessionStatus: Record<string, 'stream' | 'finish' | 'abort' | 'error'>;
65
+ sessionStatus: Record<string, 'stream' | 'finish' | 'abort'>;
66
66
  handleSelectSession: (id: number | string) => void;
67
67
  }
68
68
 
@@ -28,7 +28,9 @@ export interface ChatTimelineActionsDeps {
28
28
  sessionId: string | null;
29
29
  appSettings: Record<string, any>;
30
30
  messageQueue: QueuedMessage[];
31
- setMessageQueue: (updater: SetStateAction<QueuedMessage[]>) => void;
31
+ /** Server-backed per-item queue ops (append/remove/reorder). */
32
+ enqueueMessage: (item: Omit<QueuedMessage, 'id'>) => void;
33
+ removeMessage: (id: string) => void;
32
34
  executeSend: (text: string, attachments: Attachment[], options?: { model?: QueuedMessageModel | null }) => Promise<void>;
33
35
  steerOmpAgent: (text: string, attachments: Attachment[]) => Promise<void>;
34
36
  ompAgent: OmpAgentHandle;
@@ -74,7 +76,8 @@ export function useChatTimelineActions(deps: ChatTimelineActionsDeps): ChatTimel
74
76
  sessionId,
75
77
  appSettings,
76
78
  messageQueue,
77
- setMessageQueue,
79
+ enqueueMessage,
80
+ removeMessage,
78
81
  executeSend,
79
82
  steerOmpAgent,
80
83
  ompAgent,
@@ -123,41 +126,36 @@ export function useChatTimelineActions(deps: ChatTimelineActionsDeps): ChatTimel
123
126
  return;
124
127
  }
125
128
  const composerPick = composerModelRef.current;
126
- const queuedItem: QueuedMessage = {
127
- id: `queue-${Date.now()}`,
128
- text: textToSend,
129
- attachments,
130
- // Snapshot the composer's model/thinking plus the live access mode so
131
- // auto-delivery runs the item with exactly these settings.
132
- model: composerPick
133
- ? { ...composerPick, accessMode: accessModeRef.current }
134
- : null,
135
- };
136
- // Both modes: hold the follow-up in the client queue. The panel is the
137
- // source of truth (editable, removable, survives reload via the
138
- // session-state blob); delivery happens when the run ends — the
139
- // auto-process effect sends the head item. For omp this replaces the
140
- // old immediate `follow_up` RPC, whose server-side queue the client
141
- // could never cancel (Stop kept executing it).
129
+ // Snapshot the composer's model/thinking plus the live access mode so
130
+ // server-side auto-delivery runs the item with exactly these settings.
131
+ const model = composerPick
132
+ ? { ...composerPick, accessMode: accessModeRef.current }
133
+ : null;
134
+ // Both modes: the item is stored server-side (`queued_messages`) and the
135
+ // panel is a view of it. Delivery happens when the run ends — the
136
+ // wrapper's terminal `agent_end` claims the head and dispatches it.
142
137
  setInputValue('');
143
- setMessageQueue(prev => [...prev, queuedItem]);
138
+ enqueueMessage({ text: textToSend, attachments, model });
144
139
  return;
145
140
  }
146
141
 
147
142
  setInputValue('');
148
143
  executeSend(textToSend, attachments);
149
- }, [inputValue, isGenerating, executeSend, setMessageQueue, isOmpSession, appSettings, steerOmpAgent, setInputValue, abortControllerRef, setGenerating, stopHoldRef, composerModelRef, accessModeRef]);
144
+ }, [inputValue, isGenerating, executeSend, enqueueMessage, isOmpSession, appSettings, steerOmpAgent, setInputValue, abortControllerRef, setGenerating, stopHoldRef, composerModelRef, accessModeRef]);
150
145
 
151
146
  const handleEditQueueItem = useCallback((item: QueuedMessage) => {
152
- setMessageQueue(q => q.filter(i => i.id !== item.id));
147
+ // Lift the text into the composer and drop the row. If the user never
148
+ // re-submits, the delete (below) already removed it — the old flow had a
149
+ // dead window here where removing from the local list was the only edit.
153
150
  setInputValue(item.text);
154
151
  setInputAttachments(item.attachments);
155
- }, [setMessageQueue, setInputValue, setInputAttachments]);
152
+ removeMessage(item.id);
153
+ }, [removeMessage, setInputValue, setInputAttachments]);
156
154
 
157
155
  const handleSendNowQueueItem = useCallback(async (item: QueuedMessage) => {
158
- // Explicit delivery also lifts the Stop hold.
156
+ // Explicit delivery also lifts the Stop hold (mock path).
159
157
  stopHoldRef.current = false;
160
- setMessageQueue(q => q.filter(i => i.id !== item.id));
158
+ removeMessage(item.id);
161
159
 
162
160
  if (isGenerating) {
163
161
  if (isOmpSession) {
@@ -173,7 +171,7 @@ export function useChatTimelineActions(deps: ChatTimelineActionsDeps): ChatTimel
173
171
  } else {
174
172
  executeSend(item.text, item.attachments, { model: item.model });
175
173
  }
176
- }, [isGenerating, executeSend, setMessageQueue, isOmpSession, steerOmpAgent, abortControllerRef, setGenerating, stopHoldRef]);
174
+ }, [isGenerating, executeSend, removeMessage, isOmpSession, steerOmpAgent, abortControllerRef, setGenerating, stopHoldRef]);
177
175
 
178
176
  const handleUndo = useCallback(async (msgId: string, content?: string): Promise<boolean> => {
179
177
  if (isGenerating) {
@@ -177,10 +177,11 @@ export function useChatTimeline({ folders = [], appSettings = {} }: UseChatTimel
177
177
 
178
178
  const {
179
179
  messageQueue,
180
- setMessageQueue,
180
+ enqueueMessage,
181
+ removeMessage,
182
+ reorderMessages,
181
183
  steeringQueue,
182
184
  setSteeringQueue,
183
- removeDeliveredFromQueue,
184
185
  } = useChatTimelineQueue(sessionId);
185
186
  const {
186
187
  pending: extensionDialogs,
@@ -190,7 +191,6 @@ export function useChatTimeline({ folders = [], appSettings = {} }: UseChatTimel
190
191
  } = useExtensionDialogQueue(sessionId);
191
192
 
192
193
  const ompAgent = useOmpAgent(isOmpSession ? sessionId : null, createOmpAgentCallbacks({
193
- removeDeliveredFromQueue,
194
194
  setGenerating,
195
195
  setGeneratingVerb,
196
196
  scrollToBottom,
@@ -236,21 +236,11 @@ export function useChatTimeline({ folders = [], appSettings = {} }: UseChatTimel
236
236
  setSearchParams,
237
237
  });
238
238
 
239
- // Auto-process queue: when the run ends (or was never active), deliver the
240
- // head item. Both modes queue client-side now — omp sends it as a normal
241
- // prompt via executeSend (which routes to the omp bridge); the mock path
242
- // streams the same way. A user Stop arms `stopHoldRef`: the run ends but the
243
- // queue stays put (stop-all semantics — the toast offers Send now); the next
244
- // explicit send disarms it.
245
- useEffect(() => {
246
- if (stopHoldRef.current) return;
247
- if (!isGenerating && messageQueue.length > 0) {
248
- const nextMessage = messageQueue[0];
249
- setMessageQueue(q => q.slice(1));
250
- // The queued snapshot re-applies model/thinking/access before the prompt.
251
- executeSend(nextMessage.text, nextMessage.attachments, { model: nextMessage.model });
252
- }
253
- }, [isGenerating, messageQueue, executeSend, setMessageQueue]);
239
+ // Queue auto-delivery moved server-side: the wrapper's terminal `agent_end`
240
+ // schedules the next queued prompt (`lib/queue/delivery.server.ts`), with a
241
+ // transactional head claim so no reload/tab race can double-send or wipe the
242
+ // table. The client panel is a view; the mount nudge lives in the queue
243
+ // hook. `stopHoldRef` remains only for the mock path below.
254
244
 
255
245
  const {
256
246
  handleSend,
@@ -271,7 +261,8 @@ export function useChatTimeline({ folders = [], appSettings = {} }: UseChatTimel
271
261
  sessionId,
272
262
  appSettings,
273
263
  messageQueue,
274
- setMessageQueue,
264
+ enqueueMessage,
265
+ removeMessage,
275
266
  executeSend,
276
267
  steerOmpAgent,
277
268
  ompAgent,
@@ -303,7 +294,8 @@ export function useChatTimeline({ folders = [], appSettings = {} }: UseChatTimel
303
294
  loadOlder,
304
295
  generatingVerb,
305
296
  messageQueue,
306
- setMessageQueue,
297
+ removeMessage,
298
+ reorderMessages,
307
299
  steeringQueue,
308
300
  setSteeringQueue,
309
301
  inputValue,