@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.
Files changed (205) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +579 -510
  3. package/dist/client/static/js/index-bc9aa4mx.css +1 -0
  4. package/dist/client/static/js/{index-jcr5twtp.js → index-ga8cbpt4.js} +1072 -1174
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
  15. package/src/client/components/common/session-actions-menu/index.tsx +33 -2
  16. package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
  17. package/src/client/components/common/session-row/index.tsx +27 -1
  18. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  19. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
  20. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
  21. package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
  22. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +36 -5
  23. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
  24. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
  26. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -35
  28. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
  29. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
  30. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
  31. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  32. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  33. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
  34. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  35. package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
  36. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  37. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  38. package/src/client/components/workspace/chat-timeline/index.tsx +3 -1
  39. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  40. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  41. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  42. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  43. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  44. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  45. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  46. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  47. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  48. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  49. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  50. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  51. package/src/client/data/settings/omp-schema.json +1 -1
  52. package/src/client/data/theme/terminal.test.ts +25 -0
  53. package/src/client/data/theme/terminal.ts +96 -79
  54. package/src/client/hooks/chat/composer/items.test.ts +12 -26
  55. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  56. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  57. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  58. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  59. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  60. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  61. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  62. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  63. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  64. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  65. package/src/client/hooks/chat/timeline/send.ts +51 -50
  66. package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
  67. package/src/client/hooks/models/use-harness-update.test.ts +193 -0
  68. package/src/client/hooks/models/use-harness-update.ts +202 -0
  69. package/src/client/hooks/workspace/child-expansion.ts +33 -0
  70. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  71. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  72. package/src/client/lib/session-tree.test.ts +50 -0
  73. package/src/client/lib/session-tree.ts +59 -0
  74. package/src/client/tailwind.css +17 -11
  75. package/src/server/index.ts +2 -0
  76. package/src/server/lib/auth/guard.ts +10 -0
  77. package/src/server/lib/btw/session-copy.server.ts +6 -44
  78. package/src/server/lib/btw/session-copy.test.ts +2 -1
  79. package/src/server/lib/db/schema.ts +4 -0
  80. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  81. package/src/server/lib/db/seed.test.ts +1 -1
  82. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  83. package/src/server/lib/harness/acp/background-work.ts +320 -0
  84. package/src/server/lib/harness/acp/client.ts +2 -2
  85. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  86. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  87. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  88. package/src/server/lib/harness/acp/prompt.ts +19 -3
  89. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  90. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  91. package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
  92. package/src/server/lib/harness/acp/session-handshake.ts +27 -1
  93. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  94. package/src/server/lib/harness/acp/session-requests.ts +47 -0
  95. package/src/server/lib/harness/acp/session-turns.ts +20 -5
  96. package/src/server/lib/harness/acp/session.test-util.ts +23 -1
  97. package/src/server/lib/harness/acp/session.ts +59 -59
  98. package/src/server/lib/harness/acp/turn.test.ts +81 -0
  99. package/src/server/lib/harness/acp/turn.ts +26 -9
  100. package/src/server/lib/harness/acp/verbs.ts +12 -2
  101. package/src/server/lib/harness/launch.ts +3 -1
  102. package/src/server/lib/harness/spawn.server.ts +15 -2
  103. package/src/server/lib/harness/update-job-store.test.ts +126 -0
  104. package/src/server/lib/harness/update-job-store.ts +109 -0
  105. package/src/server/lib/harness/update-job.server.ts +203 -0
  106. package/src/server/lib/harness/update-worker.test.ts +153 -0
  107. package/src/server/lib/harness/update-worker.ts +197 -0
  108. package/src/server/lib/lifecycle/paths.ts +23 -0
  109. package/src/server/lib/omp/rpc/manager.ts +5 -5
  110. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  111. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  112. package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
  113. package/src/server/lib/omp/session/delete-flow.server.ts +47 -0
  114. package/src/server/lib/omp/session/delete.server.ts +5 -0
  115. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  116. package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
  117. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  118. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  119. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  120. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  121. package/src/server/lib/sessions/answers.server.ts +37 -0
  122. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  123. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  124. package/src/server/lib/sessions/fork.server.test.ts +209 -0
  125. package/src/server/lib/sessions/fork.server.ts +304 -0
  126. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  127. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  128. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  129. package/src/server/lib/sessions/notify.server.ts +212 -0
  130. package/src/server/lib/sessions/relation-types.ts +76 -0
  131. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  132. package/src/server/lib/sessions/relations.server.ts +337 -0
  133. package/src/server/lib/sessions/resolve.server.ts +106 -0
  134. package/src/server/lib/sessions/schema.server.ts +82 -0
  135. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  136. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  137. package/src/server/lib/sessions/spawn.server.test.ts +196 -0
  138. package/src/server/lib/sessions/spawn.server.ts +310 -0
  139. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  140. package/src/server/lib/terminal/output.test.ts +2 -2
  141. package/src/server/lib/terminal/output.ts +1 -1
  142. package/src/server/lib/terminal/resize.test.ts +99 -0
  143. package/src/server/lib/terminal/runtime.server.ts +26 -6
  144. package/src/server/lib/terminal/send-result.test.ts +18 -1
  145. package/src/server/lib/terminal/send-result.ts +26 -2
  146. package/src/server/lib/terminal/session.server.ts +6 -6
  147. package/src/server/lib/usage/new-api.test.ts +92 -0
  148. package/src/server/lib/usage/new-api.ts +131 -0
  149. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  150. package/src/server/lib/usage/provider-key.ts +33 -0
  151. package/src/server/lib/usage/providers.server.ts +10 -3
  152. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  153. package/src/server/lib/usage/vendor-http.ts +41 -0
  154. package/src/server/lib/usage/window.ts +55 -0
  155. package/src/server/routes/agent/command.ts +14 -1
  156. package/src/server/routes/agent/harness-command.ts +6 -0
  157. package/src/server/routes/agent/new.ts +15 -0
  158. package/src/server/routes/harness/add-provider.test.ts +9 -1
  159. package/src/server/routes/harness/import-action.ts +4 -0
  160. package/src/server/routes/harness/import.test.ts +1 -1
  161. package/src/server/routes/harness/index.ts +5 -1
  162. package/src/server/routes/harness/update-status.ts +26 -0
  163. package/src/server/routes/harness/update.test.ts +119 -0
  164. package/src/server/routes/harness/update.ts +59 -147
  165. package/src/server/routes/sessions/answer.ts +24 -0
  166. package/src/server/routes/sessions/batch-delete.ts +11 -5
  167. package/src/server/routes/sessions/delete.ts +4 -2
  168. package/src/server/routes/sessions/fork.ts +74 -0
  169. package/src/server/routes/sessions/index.ts +14 -0
  170. package/src/server/routes/sessions/relations.ts +85 -0
  171. package/src/server/routes/sessions/session.ts +4 -0
  172. package/src/server/routes/sessions/spawn.ts +134 -0
  173. package/src/server/routes/terminal/ws.ts +3 -3
  174. package/src/shared/lib/chat/composer/client.ts +31 -2
  175. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  176. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  177. package/src/shared/lib/chat/notice-text.ts +1 -1
  178. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  179. package/src/shared/lib/code/ansi.ts +1 -1
  180. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  181. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  182. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  183. package/src/shared/lib/harness/providers.ts +35 -1
  184. package/src/shared/lib/harness/update-job.ts +33 -0
  185. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  186. package/src/shared/lib/harness/update-plan.ts +12 -4
  187. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  188. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  189. package/src/shared/lib/theme/catalog.test.ts +13 -9
  190. package/src/shared/lib/theme/color.test.ts +2 -2
  191. package/src/shared/lib/theme/color.ts +4 -4
  192. package/src/shared/lib/theme/theme.test.ts +1 -1
  193. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  194. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  195. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  196. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  197. package/src/shared/types/chat.ts +1 -1
  198. package/src/shared/types/harness-update.ts +65 -0
  199. package/src/shared/types/omp/agent.ts +19 -2
  200. package/src/shared/types/workspace.ts +4 -0
  201. package/src/test-support/fake-omp-fork.ts +16 -2
  202. package/src/test-support/harness-table.test-util.ts +15 -1
  203. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  204. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  205. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -6923,7 +6923,7 @@
6923
6923
  "tab": "files",
6924
6924
  "group": "LSP",
6925
6925
  "label": "LSP",
6926
- "description": "Enable the lsp tool for code intelligence (definitions, references, diagnostics, rename)"
6926
+ "description": "Language-server integration: the lsp tool, diagnostics on write/edit, and format on write (--no-lsp disables for the run)"
6927
6927
  }
6928
6928
  },
6929
6929
  "lsp.lazy": {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { describe, expect, test } from 'bun:test';
7
+ import {
8
+ TERMINAL_SCROLLBACK_BYTES,
9
+ TERMINAL_SCROLLBACK_LINES,
10
+ scrollbackBytesForLines,
11
+ } from '@/client/data/theme/terminal';
12
+
13
+ describe('terminal scrollback budget', () => {
14
+ test('is a byte budget, not xterm’s line count', () => {
15
+ // Ghostty charges roughly one 16-byte cell per retained column.
16
+ expect(scrollbackBytesForLines(10_000, 100)).toBe(16_000_000);
17
+ expect(TERMINAL_SCROLLBACK_BYTES).toBe(scrollbackBytesForLines(TERMINAL_SCROLLBACK_LINES, 100));
18
+ // Passing xterm's `10000` through as the option would be ~1000× too small.
19
+ expect(TERMINAL_SCROLLBACK_BYTES).toBeGreaterThan(10_000);
20
+ });
21
+
22
+ test('never returns a zero budget', () => {
23
+ expect(scrollbackBytesForLines(0, 0)).toBe(16);
24
+ });
25
+ });
@@ -5,12 +5,11 @@ import { resolveTheme } from '@/shared/lib/theme/catalog';
5
5
  * The terminal palette for a theme, derived from the same eight colors the rest
6
6
  * of the app paints with.
7
7
  *
8
- * xterm parses its own colors and understands only literal notations (hex,
9
- * `rgb()`, `hsl()`, named) — `color-mix()` is not among them in either the DOM
10
- * or the WebGL renderer — so every blend is computed here in hex instead of
11
- * being left to CSS. The result follows the active theme rather than a fixed
12
- * light/dark pair: a Nord terminal is Nord, and switching themes repaints the
13
- * scrollback instead of leaving the previous palette on screen.
8
+ * The palette is applied when the WASM terminal is created: ANSI cells carry
9
+ * RGB resolved at parse time, so a running terminal cannot simply be recolored
10
+ * (see the theme rebuild in `terminal-panel/mount.ts`). Every blend is computed
11
+ * here in hex — the canvas renderer understands literal colors, not
12
+ * `color-mix()`.
14
13
  *
15
14
  * ANSI slots map onto the semantic colors the palette does carry (red=error,
16
15
  * green=success, yellow=warning, blue=info, magenta=accent); `cyan` has no
@@ -19,18 +18,48 @@ import { resolveTheme } from '@/shared/lib/theme/catalog';
19
18
  * the foreground, which is lighter on a dark theme and darker on a light one —
20
19
  * the direction that increases contrast on both.
21
20
  */
22
- export function getXtermTheme(themeId: string) {
21
+ export function getTerminalTheme(themeId: string) {
23
22
  const palette = resolveTheme(themeId);
24
- const { canvas, ink } = palette;
23
+ const { canvas, ink, paper } = palette;
25
24
 
26
25
  const towardInk = (color: string) => mixHex(color, ink, 0.2);
27
26
  const grayscale = (ratio: number) => mixHex(canvas, ink, ratio);
28
27
 
28
+ // Two slots the canvas renderer paints OPAQUELY, so their values are
29
+ // deliberate departures from xterm's:
30
+ // - `selectionBackground` is a 28% ink-over-canvas gray rather than a
31
+ // translucent wash. The renderer's selection branch does
32
+ // `fillRect(...)` with the raw color — no alpha is applied and an
33
+ // `rgba()` value is NOT parsed (see the renderer's selection branch,
34
+ // which reads `this.theme.selectionBackground` directly) — so a
35
+ // translucent value would paint as the literal CSS color, and a light
36
+ // wash would vanish against the canvas. Opaque + mixed keeps the
37
+ // selection visible on every theme.
38
+ // - `cursor: palette.meta` is the theme's own accent rather than xterm's
39
+ // `cursor: ink`. The block cursor is a filled rect in the meta color
40
+ // with `cursorAccent` drawn through the glyph, so the blink reads on
41
+ // both light and dark palettes without a second constant.
42
+ //
43
+ // `background` is TRANSPARENT: the terminal has no surface of its own.
44
+ //
45
+ // It used to be `canvas`, a slightly darker rectangle that also stopped a cell
46
+ // short of the panel on the right (the fit addon reserves 15 px for its
47
+ // in-canvas scrollbar) — measured as a terminal that was not full width.
48
+ // Painting the panel's `paper` fixed the colour mismatch but still drew a
49
+ // surface over the panel's material, which under `[data-surface="glass"]` is
50
+ // the frosted chrome (`glass.css` makes the view ROOT transparent for exactly
51
+ // this reason). Transparent lets that chrome — and the aura behind it — show
52
+ // through the canvas; the classic look is unchanged because the chrome's own
53
+ // fill is `--theme-paper` there. `renderLine` clears each row before filling,
54
+ // so a transparent ground leaves the previous frame erased, not smeared.
55
+ //
56
+ // `cursorAccent` stays `paper`: it is the glyph drawn INSIDE the dark cursor
57
+ // block, so it needs a real colour, not the surface.
29
58
  return {
30
- background: canvas,
59
+ background: 'transparent',
31
60
  foreground: ink,
32
61
  cursor: palette.meta,
33
- cursorAccent: canvas,
62
+ cursorAccent: paper,
34
63
  selectionBackground: grayscale(0.28),
35
64
  selectionForeground: ink,
36
65
  black: grayscale(0.2),
@@ -52,6 +81,9 @@ export function getXtermTheme(themeId: string) {
52
81
  };
53
82
  }
54
83
 
84
+ /** The text face the renderer measures its cell width from. */
85
+ export const TERMINAL_TEXT_FAMILY = 'Fira Code';
86
+
55
87
  /**
56
88
  * Font stack for the terminal canvas.
57
89
  *
@@ -71,22 +103,20 @@ export function getXtermTheme(themeId: string) {
71
103
  * (`src/shared/lib/fonts/nerd-symbols.css`), and it is deliberately LAST: a
72
104
  * machine that already has a Nerd Font renders from it and never fetches these
73
105
  * bytes, while a phone — which has none — falls through to it instead of
74
- * painting tofu. Verified: with the bundled face last and a local Nerd Font
75
- * ahead of it, laying out a PUA glyph issued zero font requests; with no local
76
- * family present, the face is fetched and all of the prompt's codepoints
77
- * render.
106
+ * painting tofu.
78
107
  *
79
108
  * Only glyphs the text face lacks reach these entries, so Latin metrics are
80
- * untouched — verified: `A`/`m`/`W` keep identical advance and ink.
109
+ * untouched.
81
110
  */
82
- export const XTERM_GLYPH_FALLBACKS =
111
+ export const TERMINAL_GLYPH_FALLBACKS =
83
112
  "'FiraCode Nerd Font Mono', 'FiraCode Nerd Font', 'JetBrainsMono Nerd Font', " +
84
113
  "'JetBrainsMono NF', 'JetBrains Mono Nerd Font', 'Hack Nerd Font', 'MesloLGS NF', " +
85
114
  "'MesloLGM Nerd Font', 'CaskaydiaCove Nerd Font', 'SauceCodePro Nerd Font', " +
86
115
  "'Symbols Nerd Font Mono', 'Symbols Nerd Font', 'PowerlineSymbols'";
87
116
 
88
117
  /**
89
- * The bundled symbols face, kept separate so `mount.ts` can await it by name.
118
+ * The bundled symbols face, kept separate so `mount.ts` can await/watch it by
119
+ * name.
90
120
  *
91
121
  * It must stay last in the stack (see above) and its family name must match the
92
122
  * `@font-face` in `nerd-symbols.css` — the two are one contract, which is why
@@ -94,70 +124,57 @@ export const XTERM_GLYPH_FALLBACKS =
94
124
  */
95
125
  export const NERD_SYMBOLS_FAMILY = 'Kabmo Nerd Symbols';
96
126
 
97
- export const XTERM_FONT_FAMILY =
98
- `'Fira Code', ${XTERM_GLYPH_FALLBACKS}, '${NERD_SYMBOLS_FAMILY}', Menlo, Monaco, 'Courier New', monospace`;
99
-
100
- /** xterm's private render service, read only to size-check before fitting. */
101
- export interface XtermCore {
102
- _core?: { _renderService?: { dimensions?: { css?: { cell?: { width?: number; height?: number } } } } };
103
- }
127
+ /** The faces whose late arrival changes what the canvas should rasterize. */
128
+ export const TERMINAL_FACES = [TERMINAL_TEXT_FAMILY, NERD_SYMBOLS_FAMILY] as const;
104
129
 
105
- /** Interop shape of the dynamically imported xterm modules: the class sits at
106
- * the root export on some builds and under `.default` on others. */
107
- export interface XtermModule<T> {
108
- Terminal?: T;
109
- FitAddon?: T;
110
- default?: { Terminal?: T; FitAddon?: T } & T;
111
- }
130
+ /**
131
+ * The canvas renderer composes its font string as `[italic ][bold ]SIZE FAMILY`
132
+ * when a cell is bold, and the shorthand grammar allows ONE weight before the
133
+ * size — not one per family — so the stack cannot ask for a real 700 per
134
+ * face (`'Fira Code';700` is not a valid family token and the whole
135
+ * declaration is dropped, leaving the renderer's `monospace` default). Bold
136
+ * therefore goes through the CSS font-matching rules: the first family that
137
+ * SHIPS a 700 wins, and `@fontsource/fira-code` does — `fira-code-fonts.css`
138
+ * bundles 400/500/600/700 — so bold cells rasterize from the real 700 and
139
+ * match xterm. Verified in Chromium: `bold 12px 'Fira Code', …` with the 700
140
+ * face unloaded reports `12px "Fira Code"` (the 400 face) and downloads
141
+ * `fira-code-latin-700-normal.woff2` the moment a bold cell is laid out.
142
+ */
143
+ export const TERMINAL_FONT_FAMILY =
144
+ `'${TERMINAL_TEXT_FAMILY}', ${TERMINAL_GLYPH_FALLBACKS}, '${NERD_SYMBOLS_FAMILY}', Menlo, Monaco, 'Courier New', monospace`;
112
145
 
113
- export function safePatchFitAddon(FitAddonClass: any) {
114
- try {
115
- const fitProto = FitAddonClass?.prototype;
116
- if (fitProto && !fitProto.__safePatched) {
117
- fitProto.__safePatched = true;
118
- const origPropose = fitProto.proposeDimensions;
119
- fitProto.proposeDimensions = function () {
120
- try {
121
- const core = this._terminal?._core;
122
- if (!core?._renderService) return undefined;
123
- const dims = core._renderService.dimensions;
124
- if (!dims?.css?.cell?.width || !dims?.css?.cell?.height) return undefined;
125
- return origPropose?.call(this);
126
- } catch {
127
- return undefined;
128
- }
129
- };
130
- }
131
- } catch {}
132
- }
146
+ /**
147
+ * The cell font size in CSS px.
148
+ *
149
+ * 12px is a measured choice: the right panel is ~350 px wide at its default
150
+ * width, and 12px keeps a normal prompt unwrapped. The renderer has no
151
+ * `lineHeight` option, so the cell box is measured instead — `measureTerminalCell`
152
+ * in `terminal-panel/fonts.ts` pads the glyph ink (`Mg`) by 2.5 px above and 1 px
153
+ * below: 15 px per cell, which is what a painted background block needs to read
154
+ * as a rectangle rather than a band.
155
+ */
156
+ export const TERMINAL_FONT_SIZE = 12;
133
157
 
134
- const DEFAULT_DIMENSIONS = {
135
- device: { char: { width: 9, height: 17, left: 0, top: 0 }, cell: { width: 9, height: 17 }, canvas: { width: 0, height: 0 } },
136
- css: { canvas: { width: 0, height: 0 }, cell: { width: 9, height: 17 } }
137
- };
158
+ /**
159
+ * Ghostty's `max_scrollback` is a BYTE budget, not a line count.
160
+ *
161
+ * The wrapper types it as lines and passes xterm's `scrollback: 10000` through
162
+ * unchanged, which retains roughly 600 rows at a 98-column panel (measured).
163
+ * Kabmo wants xterm's old 10,000-line depth, so the budget is stated in the
164
+ * renderer's own unit.
165
+ *
166
+ * Ghostty charges roughly one 16-byte cell per retained column, so
167
+ * `lines × cols × 16` is the deliberate over-estimate: at 100 columns it is
168
+ * 16 MB for 10,000 lines, and the byte cap trims earlier only if the estimate
169
+ * is too small. The server's replay history is capped separately at 512 KiB
170
+ * (`lib/terminal/history.ts`), so a reconnect is bounded regardless.
171
+ */
172
+ export const TERMINAL_SCROLLBACK_CELL_BYTES = 16;
173
+ export const TERMINAL_SCROLLBACK_LINES = 10_000;
138
174
 
139
- export function safePatchRenderService(term: any) {
140
- try {
141
- const core = term?._core;
142
- if (core?._renderService) {
143
- const proto = Object.getPrototypeOf(core._renderService);
144
- const desc = Object.getOwnPropertyDescriptor(proto, 'dimensions');
145
- if (desc?.get && !proto.__safePatched) {
146
- proto.__safePatched = true;
147
- const origGet = desc.get;
148
- Object.defineProperty(proto, 'dimensions', {
149
- get() {
150
- try {
151
- if (!this._renderer?.value) return DEFAULT_DIMENSIONS;
152
- return origGet.call(this);
153
- } catch {
154
- return DEFAULT_DIMENSIONS;
155
- }
156
- },
157
- configurable: true,
158
- enumerable: true
159
- });
160
- }
161
- }
162
- } catch {}
175
+ export function scrollbackBytesForLines(lines: number, cols: number): number {
176
+ return Math.max(1, lines) * Math.max(1, cols) * TERMINAL_SCROLLBACK_CELL_BYTES;
163
177
  }
178
+
179
+ /** The default budget: 10,000 lines at the panel's usual 100 columns. */
180
+ export const TERMINAL_SCROLLBACK_BYTES = scrollbackBytesForLines(TERMINAL_SCROLLBACK_LINES, 100);
@@ -32,8 +32,6 @@ import { registerListSlot, resetListSlots } from '@/client/lib/plugins/list-slot
32
32
  import {
33
33
  invalidateComposerCache,
34
34
  loadComposerItems,
35
- toAgentPickItems,
36
- toFilePickItems,
37
35
  } from '@/shared/lib/chat/composer/client';
38
36
 
39
37
  const DOM_GLOBALS = ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event', 'CustomEvent'] as const;
@@ -144,7 +142,10 @@ describe('useComposerItems', () => {
144
142
 
145
143
  await mount('mention', '/repo');
146
144
  await settle(6);
147
- expect(state.items.map((item) => item.token)).toEqual(['@sonic', '@file:src/a.ts']);
145
+ const tokens = state.items.map((item) => item.token);
146
+ expect(tokens[0]).toBe('@sonic');
147
+ expect(tokens.at(-1)).toBe('@file:src/a.ts');
148
+ expect(tokens).toContain('@harness:claude');
148
149
  expect(state.error).toBeNull();
149
150
  });
150
151
 
@@ -240,7 +241,8 @@ describe('plugin commands in the popup', () => {
240
241
  await mount('mention', '/repo');
241
242
  await settle(6);
242
243
 
243
- expect(state.items).toEqual([]);
244
+ expect(state.items.every((item) => item.source === 'harness')).toBe(true);
245
+ expect(state.items.length).toBeGreaterThan(0);
244
246
  });
245
247
 
246
248
  test('a closed menu offers nothing, not even a plugin row', async () => {
@@ -252,26 +254,6 @@ describe('plugin commands in the popup', () => {
252
254
  });
253
255
  });
254
256
 
255
- describe('pick item mapping', () => {
256
- test('an agent becomes a bare @name token', () => {
257
- const [item] = toAgentPickItems([
258
- { id: 'a1', name: 'sonic', description: 'fast', scope: 'user', systemPrompt: '' },
259
- ]);
260
- expect(item).toMatchObject({ id: 'agent-sonic', name: 'sonic', kind: 'agent', source: 'agent', token: '@sonic' });
261
- });
262
-
263
- test('a file is namespaced under file:, so a root-level name cannot shadow an agent', () => {
264
- const [item] = toFilePickItems([{ name: 'sonic', path: 'sonic' }]);
265
- expect(item.token).toBe('@file:sonic');
266
- expect(item.path).toBe('sonic');
267
- });
268
-
269
- test('a path with whitespace is quoted, so the token cannot end early', () => {
270
- const [item] = toFilePickItems([{ name: 'my notes.md', path: 'docs/my notes.md' }]);
271
- expect(item.token).toBe('@"file:docs/my notes.md"');
272
- });
273
- });
274
-
275
257
  describe('loadComposerItems', () => {
276
258
  test('mention merges agents first, then workspace files', async () => {
277
259
  answer = (url) => url.includes('/api/settings/agents')
@@ -279,7 +261,9 @@ describe('loadComposerItems', () => {
279
261
  : { body: { files: [{ name: 'a.ts', path: 'src/a.ts' }] } };
280
262
 
281
263
  const items = await loadComposerItems('mention', '/repo');
282
- expect(items.map((item) => item.source)).toEqual(['agent', 'file']);
264
+ expect(items[0].source).toBe('agent');
265
+ expect(items.at(-1)?.source).toBe('file');
266
+ expect(items.some((item) => item.source === 'harness')).toBe(true);
283
267
  expect(requested).toContain('/api/fs/list?root=%2Frepo');
284
268
  });
285
269
 
@@ -289,7 +273,9 @@ describe('loadComposerItems', () => {
289
273
  : { body: { files: [{ name: 'a.ts', path: 'src/a.ts' }] } };
290
274
 
291
275
  const items = await loadComposerItems('mention', '/repo', 's1', { includeAgents: false });
292
- expect(items.map((item) => item.source)).toEqual(['file']);
276
+ expect(items.at(-1)?.source).toBe('file');
277
+ expect(items.some((item) => item.source === 'harness')).toBe(true);
278
+ expect(items.some((item) => item.source === 'agent')).toBe(false);
293
279
  // The agents request is skipped entirely, not fetched and filtered.
294
280
  expect(requested.some((url) => url.includes('/api/settings/agents'))).toBe(false);
295
281
  });
@@ -0,0 +1,42 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import {
3
+ toAgentPickItems,
4
+ toFilePickItems,
5
+ toHarnessPickItems,
6
+ } from '@/shared/lib/chat/composer/client';
7
+
8
+ describe('pick item mapping', () => {
9
+ test('an agent becomes a bare @name token', () => {
10
+ const [item] = toAgentPickItems([
11
+ { id: 'a1', name: 'sonic', description: 'fast', scope: 'user', systemPrompt: '' },
12
+ ]);
13
+ expect(item).toMatchObject({
14
+ id: 'agent-sonic',
15
+ name: 'sonic',
16
+ kind: 'agent',
17
+ source: 'agent',
18
+ token: '@sonic',
19
+ });
20
+ });
21
+
22
+ test('a harness becomes a namespaced default-model token', () => {
23
+ const [item] = toHarnessPickItems().filter((entry) => entry.token === '@harness:claude');
24
+ expect(item).toMatchObject({
25
+ id: 'harness-claude',
26
+ kind: 'harness',
27
+ source: 'harness',
28
+ token: '@harness:claude',
29
+ });
30
+ });
31
+
32
+ test('a file is namespaced under file:, so a root-level name cannot shadow an agent', () => {
33
+ const [item] = toFilePickItems([{ name: 'sonic', path: 'sonic' }]);
34
+ expect(item.token).toBe('@file:sonic');
35
+ expect(item.path).toBe('sonic');
36
+ });
37
+
38
+ test('a path with whitespace is quoted, so the token cannot end early', () => {
39
+ const [item] = toFilePickItems([{ name: 'my notes.md', path: 'docs/my notes.md' }]);
40
+ expect(item.token).toBe('@"file:docs/my notes.md"');
41
+ });
42
+ });
@@ -222,7 +222,7 @@ describe('useOmpPromptSender.sendNewPrompt — ordering', () => {
222
222
  return false;
223
223
  });
224
224
 
225
- expect(result).toEqual({ sessionId: 'omp-5', model: null });
225
+ expect(result).toEqual({ ok: true, session: { sessionId: 'omp-5', model: null } });
226
226
  expect(order).toEqual([NEW, 'goal:omp-5', '/api/agent/omp-5']);
227
227
  expect(requests.length).toBe(2);
228
228
  });
@@ -254,7 +254,7 @@ describe('useOmpPromptSender.sendNewPrompt', () => {
254
254
  modes: { plan: true, goal: false },
255
255
  });
256
256
 
257
- expect(result).toEqual({ sessionId: 'omp-9', model: { provider: 'anthropic', modelId: 'claude' } });
257
+ expect(result).toEqual({ ok: true, session: { sessionId: 'omp-9', model: { provider: 'anthropic', modelId: 'claude' } } });
258
258
  expect(requests[0].url).toBe(NEW);
259
259
  expect(requests[0].body).toEqual({
260
260
  type: 'ensure_session',
@@ -278,21 +278,21 @@ describe('useOmpPromptSender.sendNewPrompt', () => {
278
278
 
279
279
  expect(requests[0].body).toEqual({ type: 'ensure_session', cwd: '/w' });
280
280
  expect(requests[1].body).toEqual({ type: 'prompt', message: 'first' });
281
- expect(result).toEqual({ sessionId: 'omp-1', model: null });
281
+ expect(result).toEqual({ ok: true, session: { sessionId: 'omp-1', model: null } });
282
282
  });
283
283
 
284
- test('a create failure returns null without connecting or prompting', async () => {
284
+ test('a create failure returns the server reason without connecting or prompting', async () => {
285
285
  const requests = installFetch({ [NEW]: { status: 500, body: { error: 'no workspace' } } });
286
286
  const probe = mountSender(null);
287
287
  const result = await probe.sender().sendNewPrompt('first', '/w');
288
288
 
289
- expect(result).toBeNull();
289
+ expect(result).toEqual({ ok: false, error: 'no workspace' });
290
290
  expect(requests.length).toBe(1);
291
291
  expect(probe.connected).toEqual([]);
292
292
  expect(probe.state().error).toBe('no workspace');
293
293
  });
294
294
 
295
- test('a prompt failure returns null even though the session was created', async () => {
295
+ test('a prompt failure returns the reason even though the session was created', async () => {
296
296
  const requests = installFetch({ [NEW]: { body: { success: true, sessionId: 'omp-3' } } });
297
297
  let call = 0;
298
298
  (globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown, init?: { method?: string; body?: string }) => {
@@ -305,7 +305,7 @@ describe('useOmpPromptSender.sendNewPrompt', () => {
305
305
  const probe = mountSender(null);
306
306
  const result = await probe.sender().sendNewPrompt('first', '/w');
307
307
 
308
- expect(result).toBeNull();
308
+ expect(result).toEqual({ ok: false, error: 'boom' });
309
309
  expect(probe.connected).toEqual(['omp-3']);
310
310
  expect(probe.state().isGenerating).toBe(false);
311
311
  });
@@ -20,7 +20,7 @@ import { useCallback } from 'preact/hooks';
20
20
  import type { Dispatch, SetStateAction } from 'preact/compat';
21
21
  import { setSessionTitleHint } from '@/client/hooks/chat/omp/sidebar-overlay';
22
22
  import { redirectToOwningInstance, type SessionOwnerConflict } from '@/client/hooks/chat/omp/owner-redirect';
23
- import type { AgentImage, OmpAgentState, PromptDispatchResult, SpawnOptions, SpawnedSession } from '@/shared/types';
23
+ import type { AgentImage, OmpAgentState, PromptDispatchResult, SpawnOptions, SpawnPromptResult } from '@/shared/types';
24
24
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
25
25
 
26
26
  export interface OmpPromptSenderDeps {
@@ -49,7 +49,7 @@ export interface OmpPromptSender {
49
49
  * the raw message after it would be a second turn asking the same thing.
50
50
  */
51
51
  beforePrompt?: (sessionId: string) => Promise<boolean>,
52
- ) => Promise<SpawnedSession | null>;
52
+ ) => Promise<SpawnPromptResult>;
53
53
  }
54
54
 
55
55
  export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
@@ -114,16 +114,15 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
114
114
  * the prompt through the existing session route so no agent events are
115
115
  * missed. Model/thinking picks ride the ensure_session body so omp applies
116
116
  * them BEFORE the first prompt (and their JSONL change entries are written
117
- * up front, not after the run starts). Returns the new session id on
118
- * success, or null on failure — the caller adopts the id as the active
119
- * session. */
117
+ * up front, not after the run starts). Returns the adopted session, or the
118
+ * server's refusal reason — the caller must report it, never simulate one. */
120
119
  const sendNewPrompt = useCallback(async (
121
120
  message: string,
122
121
  cwd: string,
123
122
  images?: AgentImage[],
124
123
  composerOptions?: SpawnOptions,
125
124
  beforePrompt?: (sessionId: string) => Promise<boolean>,
126
- ): Promise<SpawnedSession | null> => {
125
+ ): Promise<SpawnPromptResult> => {
127
126
  setState((prev) => ({ ...prev, isGenerating: true, error: null }));
128
127
  // The real id does not exist until `ensure_session` answers, so the mark
129
128
  // can only be armed past that point — the spawn itself is covered by the
@@ -151,10 +150,15 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
151
150
  model?: { provider: string; modelId: string } | null;
152
151
  harness?: string;
153
152
  error?: string;
153
+ code?: string;
154
154
  };
155
155
  if (!created.ok || !createdBody.sessionId) {
156
- setState((prev) => ({ ...prev, isGenerating: false, error: createdBody.error ?? `HTTP ${created.status}` }));
157
- return null;
156
+ const error = createdBody.error ?? `HTTP ${created.status}`;
157
+ setState((prev) => ({ ...prev, isGenerating: false, error }));
158
+ // The CODE travels: `mock_mode` is a "there is nothing to spawn here",
159
+ // which the caller answers with the simulated stream rather than an
160
+ // error the operator cannot act on.
161
+ return { ok: false, error, ...(createdBody.code ? { code: createdBody.code } : {}) };
158
162
  }
159
163
  sid = createdBody.sessionId;
160
164
  connect(sid);
@@ -168,7 +172,10 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
168
172
  // is what makes the order a fact rather than a race. An armed interview
169
173
  // answers true: it already opened the turn, so this prompt is not sent.
170
174
  if (beforePrompt && await beforePrompt(sid)) {
171
- return { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) };
175
+ return {
176
+ ok: true,
177
+ session: { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) },
178
+ };
172
179
  }
173
180
  const res = await fetch(`/api/agent/${encodeURIComponent(sid)}`, {
174
181
  method: 'POST',
@@ -181,13 +188,18 @@ export function useOmpPromptSender(deps: OmpPromptSenderDeps): OmpPromptSender {
181
188
  });
182
189
  const body = (await res.json().catch(() => ({}))) as { success?: boolean; error?: string };
183
190
  if (!res.ok || body.error) {
184
- setState((prev) => ({ ...prev, isGenerating: false, error: body.error ?? `HTTP ${res.status}` }));
185
- return null;
191
+ const error = body.error ?? `HTTP ${res.status}`;
192
+ setState((prev) => ({ ...prev, isGenerating: false, error }));
193
+ return { ok: false, error };
186
194
  }
187
- return { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) };
195
+ return {
196
+ ok: true,
197
+ session: { sessionId: sid, model: createdBody.model ?? null, ...(createdBody.harness ? { harness: createdBody.harness } : {}) },
198
+ };
188
199
  } catch (e) {
189
- setState((prev) => ({ ...prev, isGenerating: false, error: e instanceof Error ? e.message : String(e) }));
190
- return null;
200
+ const error = e instanceof Error ? e.message : String(e);
201
+ setState((prev) => ({ ...prev, isGenerating: false, error }));
202
+ return { ok: false, error };
191
203
  }
192
204
  }, [connect, setState]);
193
205
 
@@ -20,7 +20,7 @@
20
20
  */
21
21
 
22
22
  import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
23
- import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
23
+ import { buildPromptText, DelegationPromptError } from '@/client/hooks/chat/timeline/prompt-text';
24
24
  import { invalidateComposerCache } from '@/shared/lib/chat/composer/client';
25
25
 
26
26
  type TextFile = Parameters<typeof buildPromptText>[1][number] & { missing?: boolean };
@@ -60,6 +60,39 @@ function file(name: string, content: string): TextFile {
60
60
  return { name, mimeType: 'text/plain', content, size: content.length };
61
61
  }
62
62
 
63
+ describe('buildPromptText harness delegation', () => {
64
+ test('a bare harness mention compiles to a default-model spawn command', async () => {
65
+ const prompt = await buildPromptText('@claude review src/auth', []);
66
+ expect(prompt).toContain('[kabmo orchestration contract]');
67
+ expect(prompt).toContain('--harness claude --prompt-file -');
68
+ expect(prompt).not.toContain('--model');
69
+ expect(prompt).toContain('review src/auth');
70
+ });
71
+
72
+ test('an explicit model rides the command', async () => {
73
+ const prompt = await buildPromptText('@harness:claude:opus review this', []);
74
+ expect(prompt).toContain('--harness claude --model opus');
75
+ });
76
+
77
+ test('an omp agent mention still becomes a task directive', async () => {
78
+ const prompt = await buildPromptText('fix @architect the bug', []);
79
+ expect(prompt.startsWith('Use the task tool')).toBe(true);
80
+ expect(prompt).not.toContain('[kabmo orchestration contract]');
81
+ });
82
+
83
+ test('two harnesses in one paragraph are refused before sending', async () => {
84
+ await expect(buildPromptText('@claude and @codex review', [])).rejects.toBeInstanceOf(
85
+ DelegationPromptError,
86
+ );
87
+ });
88
+
89
+ test('an unknown namespaced harness is refused', async () => {
90
+ await expect(buildPromptText('@harness:nope do it', [])).rejects.toBeInstanceOf(
91
+ DelegationPromptError,
92
+ );
93
+ });
94
+ });
95
+
63
96
  describe('buildPromptText mentions', () => {
64
97
  test('an agent mention becomes a task-tool delegation directive', async () => {
65
98
  const result = await buildPromptText('fix @architect the bug', []);