@kabmo-labs/kabmo 0.16.0 → 0.17.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 (131) hide show
  1. package/README.md +2 -2
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +417 -417
  4. package/dist/client/static/js/index-3ve31rzx.css +1 -0
  5. package/dist/client/static/js/{index-cpydmygd.js → index-rerjq5th.js} +839 -837
  6. package/package.json +1 -1
  7. package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
  8. package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
  9. package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
  10. package/src/client/components/common/code-surface/extensions.ts +7 -4
  11. package/src/client/components/common/code-surface/theme.ts +34 -9
  12. package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
  13. package/src/client/components/common/code-surface/whitespace.ts +140 -0
  14. package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +73 -35
  15. package/src/client/components/common/{server-switcher → server-control}/index.test.tsx +98 -37
  16. package/src/client/components/common/server-control/index.tsx +118 -0
  17. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
  18. package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
  19. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
  20. package/src/client/components/settings/Modal.tsx +9 -3
  21. package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
  22. package/src/client/components/settings/categories/AgentSettings.tsx +27 -6
  23. package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
  24. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
  25. package/src/client/components/settings/categories/SkillSettings.tsx +6 -3
  26. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +5 -0
  27. package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
  28. package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
  29. package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
  30. package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
  31. package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
  32. package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
  33. package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
  34. package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
  35. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
  36. package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
  37. package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
  38. package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
  39. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
  40. package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
  41. package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
  42. package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
  43. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +208 -0
  44. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +137 -232
  45. package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
  46. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +123 -87
  47. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +179 -0
  48. package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
  49. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  50. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
  51. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
  52. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
  53. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
  54. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
  55. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
  56. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
  57. package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
  58. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
  59. package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
  60. package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
  61. package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
  62. package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
  63. package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
  64. package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
  65. package/src/client/components/workspace/file-explorer/index.tsx +21 -20
  66. package/src/client/data/settings/omp-schema.json +91 -4
  67. package/src/client/data/settings/project.ts +9 -28
  68. package/src/client/data/settings/skill.ts +6 -32
  69. package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
  70. package/src/client/hooks/settings/projects/index.ts +294 -0
  71. package/src/client/hooks/settings/projects.test.ts +237 -0
  72. package/src/client/hooks/settings/skill-catalog.ts +101 -9
  73. package/src/client/hooks/settings/skill-git-import.ts +153 -0
  74. package/src/client/hooks/shell/servers.test.ts +166 -0
  75. package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
  76. package/src/client/hooks/ui/updates/shell-download.ts +1 -1
  77. package/src/client/hooks/ui/updates/shell-update.ts +2 -6
  78. package/src/client/hooks/workspace/file-row-drag.ts +41 -0
  79. package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
  80. package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
  81. package/src/client/hooks/workspace/root-drop-target.ts +77 -0
  82. package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
  83. package/src/client/lib/desktop/dropped-paths.ts +1 -1
  84. package/src/client/lib/desktop/titlebar.test.ts +12 -3
  85. package/src/client/lib/desktop/titlebar.ts +1 -1
  86. package/src/client/lib/shell/desktop.ts +117 -0
  87. package/src/client/lib/shell/servers.ts +75 -0
  88. package/src/client/lib/shell/transport.ts +216 -0
  89. package/src/client/main.tsx +9 -0
  90. package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
  91. package/src/server/lib/omp/config/skill-sources.ts +49 -0
  92. package/src/server/lib/omp/config/skills-git-install.ts +155 -0
  93. package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
  94. package/src/server/lib/omp/config/skills-git.test.ts +220 -0
  95. package/src/server/lib/workspace/project-model.server.test.ts +102 -0
  96. package/src/server/lib/workspace/project-model.server.ts +47 -0
  97. package/src/server/lib/workspace/project-patch.server.ts +156 -0
  98. package/src/server/routes/agent/new.ts +8 -1
  99. package/src/server/routes/settings/agents.ts +19 -7
  100. package/src/server/routes/settings/projects.ts +53 -19
  101. package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
  102. package/src/server/routes/settings/settings-store-routes.test.ts +5 -2
  103. package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
  104. package/src/server/routes/settings/skills.test.ts +225 -0
  105. package/src/server/routes/settings/skills.ts +18 -15
  106. package/src/shared/lib/fs/folder-chain.test.ts +81 -1
  107. package/src/shared/lib/fs/folder-chain.ts +84 -0
  108. package/src/shared/lib/omp/config/schema.test.ts +35 -0
  109. package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
  110. package/src/shared/lib/omp/session/job-progress.ts +31 -0
  111. package/src/shared/lib/omp/session/proc.ts +5 -0
  112. package/src/shared/lib/omp/session/wait.ts +5 -0
  113. package/src/shared/lib/ui/mobile-overlay.ts +61 -0
  114. package/src/shared/lib/ui/svg-scope.test.ts +97 -0
  115. package/src/shared/lib/ui/svg-scope.ts +134 -0
  116. package/src/shared/lib/workspace/project-accent.test.ts +69 -0
  117. package/src/shared/lib/workspace/project-accent.ts +63 -0
  118. package/src/shared/lib/workspace/project-icon.ts +40 -0
  119. package/src/shared/lib/workspace/project-model.test.ts +79 -0
  120. package/src/shared/lib/workspace/project-model.ts +64 -0
  121. package/src/shared/types/settings/skill.ts +53 -3
  122. package/src/test-support/file-explorer-disk.test-util.ts +25 -1
  123. package/src/test-support/file-explorer-drag.test-util.ts +88 -0
  124. package/src/test-support/file-explorer.test-util.ts +47 -47
  125. package/dist/client/static/js/index-fjnq2z2d.css +0 -1
  126. package/src/client/components/common/code-surface/indent-guide.ts +0 -104
  127. package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
  128. package/src/client/hooks/desktop/servers.test.ts +0 -73
  129. package/src/client/lib/desktop/bridge.ts +0 -203
  130. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
  131. package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
@@ -4,37 +4,33 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Which server the window is on, and how to change it.
7
+ * The server panel's own markup: one row per server, the empty state, and the
8
+ * two footers a shell may or may not offer.
8
9
  *
9
- * The panel lists three groups, and the split is the whole design:
10
- *
11
- * - **This window** — the servers the shell remembers, with the active one
12
- * marked. A remote entry is a URL somebody typed; a managed entry is a local
13
- * server this shell started, which is why it can be stopped here.
14
- * - **Found on this machine** — servers the shell did NOT start: `kabmo serve`
15
- * in a terminal, `bun run dev`, a login entry. They are read from the
16
- * per-port records the servers themselves write, so a server that appeared
17
- * after the panel opened shows up on the next refresh. They can be connected
18
- * to but not stopped — this window did not start them, and a Stop here would
19
- * kill a process somebody else is watching.
20
- * - **Add a server** — a URL and a label.
21
- *
22
- * A server is only offered as connectable while it ANSWERS: the shell probes
23
- * every URL before answering, so `running: false` is a real fact rather than a
24
- * guess, and the row says so instead of letting a click fail on a blank window.
10
+ * Split from `ServerControl` so the trigger (a chip on a phone, a labelled
11
+ * button in a desktop navbar) and the list can be read and tested apart. The
12
+ * STORE is the control's, not the panel's: the old panel opened a second
13
+ * `useShellServers`, which meant two copies of the list, two 4-second polls and
14
+ * a trigger that could disagree with the rows directly under it.
25
15
  */
26
16
 
27
17
  import { useState } from 'preact/hooks';
28
18
  import { Check, Loader2, Play, Plus, RefreshCw, Server, Square, Trash2 } from 'lucide-preact';
29
- import { useDesktopServers } from '@/client/hooks/desktop/servers';
30
- import type { DesktopServer } from '@/client/lib/desktop/bridge';
19
+ import type { ShellServersStore } from '@/client/hooks/shell/servers';
20
+ import type { ShellServer } from '@/client/lib/shell/servers';
21
+ import { mobileOverlayStyle } from '@/shared/lib/ui/mobile-overlay';
31
22
 
32
- interface ServerSwitcherProps {
23
+ export type ServerControlVariant = 'nav' | 'chip';
24
+
25
+ interface ServerPanelProps {
33
26
  open: boolean;
34
27
  onClose: () => void;
28
+ /** `nav` hangs under a desktop navbar button; `chip` is a phone sheet. */
29
+ variant: ServerControlVariant;
30
+ store: ShellServersStore;
35
31
  }
36
32
 
37
- function statusLine(server: DesktopServer): string {
33
+ function statusLine(server: ShellServer): string {
38
34
  if (!server.running) return 'Stopped';
39
35
  const parts: string[] = [];
40
36
  if (server.version) parts.push(`v${server.version}`);
@@ -51,7 +47,7 @@ function Row({
51
47
  onStop,
52
48
  onRemove,
53
49
  }: {
54
- server: DesktopServer;
50
+ server: ShellServer;
55
51
  active: boolean;
56
52
  busy: boolean;
57
53
  onActivate: () => void;
@@ -113,8 +109,30 @@ function Row({
113
109
  );
114
110
  }
115
111
 
116
- export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
117
- const store = useDesktopServers(open);
112
+ /**
113
+ * Which server this window is on, and how to change it.
114
+ *
115
+ * The panel lists two groups, and the split is the whole design:
116
+ *
117
+ * - **This window** — the servers the shell remembers, with the active one
118
+ * marked. A remote entry is a URL somebody typed; a managed entry is a local
119
+ * server this shell started, which is why it can be stopped here.
120
+ * - **Found on this machine** — servers the shell did NOT start: `kabmo serve`
121
+ * in a terminal, `bun run dev`, a login entry. They are read from the
122
+ * per-port records the servers themselves write, so a server that appeared
123
+ * after the panel opened shows up on the next refresh. They can be connected
124
+ * to but not stopped — this window did not start them, and a Stop here would
125
+ * kill a process somebody else is watching.
126
+ *
127
+ * A phone answers neither group's second half: it cannot spawn a server, and it
128
+ * has no per-port records on the device, so those two sections are ABSENT there
129
+ * rather than drawn empty (`startable: false` and `detected: []` are the facts).
130
+ *
131
+ * A server is only offered as connectable while it ANSWERS: the shell probes
132
+ * every URL before answering, so `running: false` is a real fact rather than a
133
+ * guess, and the row says so instead of letting a click fail on a blank window.
134
+ */
135
+ export function ServerPanel({ open, onClose, variant, store }: ServerPanelProps) {
118
136
  const [label, setLabel] = useState('');
119
137
  const [url, setUrl] = useState('');
120
138
  const [adding, setAdding] = useState(false);
@@ -125,6 +143,7 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
125
143
  const entries = state?.entries ?? [];
126
144
  const detected = state?.detected ?? [];
127
145
  const activeId = state?.activeId;
146
+ const startable = state?.startable !== false;
128
147
 
129
148
  const submit = async () => {
130
149
  if (!url.trim()) return;
@@ -136,11 +155,24 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
136
155
  }
137
156
  };
138
157
 
158
+ // Desktop hangs under its navbar button; a phone pins to the VIEWPORT, because
159
+ // its trigger sits in the drawer header and a 340px panel anchored there runs
160
+ // off the right edge (measured at 390) and past the bottom in landscape.
161
+ const placement =
162
+ variant === 'chip'
163
+ ? mobileOverlayStyle()
164
+ : undefined;
165
+
139
166
  return (
140
167
  <div
141
168
  role="dialog"
142
169
  aria-label="Servers"
143
- className="absolute right-2 top-full mt-1 z-50 w-[340px] rounded-xl border border-ink/15 bg-paper shadow-xl overflow-hidden"
170
+ className={
171
+ variant === 'chip'
172
+ ? 'fixed z-50 rounded-xl border border-ink/15 bg-paper shadow-xl overflow-hidden'
173
+ : 'absolute right-2 top-full mt-1 z-50 w-[340px] rounded-xl border border-ink/15 bg-paper shadow-xl overflow-hidden'
174
+ }
175
+ style={placement}
144
176
  onKeyDown={(event) => {
145
177
  if (event.key === 'Escape') {
146
178
  event.stopPropagation();
@@ -156,7 +188,7 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
156
188
  type="button"
157
189
  onClick={() => void store.reload()}
158
190
  disabled={store.busy}
159
- title="Refresh — re-probe every server and look for new local ones"
191
+ title="Refresh — re-probe every server"
160
192
  aria-label="Refresh servers"
161
193
  className="p-1 rounded text-ink/40 hover:text-ink hover:bg-ink/10 cursor-pointer disabled:opacity-40"
162
194
  >
@@ -207,7 +239,7 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
207
239
 
208
240
  {state && entries.length === 0 && detected.length === 0 && (
209
241
  <p className="px-1 py-2 text-[11px] text-ink/50">
210
- Nothing running yet. Start a local server, or add one by address.
242
+ Nothing here yet. Add a server by address.
211
243
  </p>
212
244
  )}
213
245
  </div>
@@ -217,14 +249,20 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
217
249
  )}
218
250
 
219
251
  <div className="border-t border-ink/10 px-2 py-2 space-y-1.5">
220
- <button
221
- type="button"
222
- onClick={() => void store.start()}
223
- disabled={store.busy}
224
- className="w-full flex items-center gap-1.5 rounded-lg border border-ink/15 px-2.5 py-1.5 text-xs text-ink hover:bg-ink/5 cursor-pointer disabled:opacity-40"
225
- >
226
- <Play size={12} /> Start a local server
227
- </button>
252
+ {/* A phone cannot spawn a server: there is no process to start and no
253
+ terminal to own it. The control is ABSENT rather than disabled,
254
+ because a disabled button would promise a capability the shell does
255
+ not have. */}
256
+ {startable && (
257
+ <button
258
+ type="button"
259
+ onClick={() => void store.start()}
260
+ disabled={store.busy}
261
+ className="w-full flex items-center gap-1.5 rounded-lg border border-ink/15 px-2.5 py-1.5 text-xs text-ink hover:bg-ink/5 cursor-pointer disabled:opacity-40"
262
+ >
263
+ <Play size={12} /> Start a local server
264
+ </button>
265
+ )}
228
266
 
229
267
  {adding ? (
230
268
  <form
@@ -6,37 +6,40 @@
6
6
  /**
7
7
  * The server panel, rendered against a real shell bridge.
8
8
  *
9
- * Three rules are what this suite exists for, and each was a decision rather
9
+ * Four rules are what this suite exists for, and each was a decision rather
10
10
  * than a style:
11
11
  *
12
- * 1. **In a browser the control does not exist.** There is no shell to control,
13
- * and a button that opened onto "not available" would be a button that never
14
- * works. The panel is rendered with no bridge at all and must produce
15
- * nothing.
16
- * 2. **A stopped server cannot be connected to.** The shell probes every URL
12
+ * 1. **A stopped server cannot be connected to.** The shell probes every URL
17
13
  * before it answers, so `running: false` is a fact; the row says `Stopped`
18
14
  * and its button is disabled rather than letting a click land on a blank
19
15
  * window.
20
- * 3. **Only a server this shell started offers Stop.** A server found on the
16
+ * 2. **Only a server this shell started offers Stop.** A server found on the
21
17
  * machine belongs to whoever started it — `kabmo serve` in a terminal — and a
22
18
  * Stop here would kill a process somebody else is watching.
19
+ * 3. **A phone is offered no Start.** `startable: false` is the fact the shell
20
+ * reports, and the control is ABSENT rather than disabled: a disabled button
21
+ * would promise a capability the phone does not have.
22
+ * 4. **The trigger and the panel share ONE store.** Two copies is how a trigger
23
+ * says "running" over rows that say `Stopped`, and how two 4-second polls
24
+ * probe every server twice.
23
25
  */
24
26
 
25
27
  import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
26
28
  import { Window } from 'happy-dom';
27
29
  import { h, render } from 'preact';
28
30
  import { act } from 'preact/test-utils';
29
- import { ServerSwitcher } from '@/client/components/common/server-switcher';
30
- import type { DesktopServersState } from '@/client/lib/desktop/bridge';
31
+ import { ServerControl } from '@/client/components/common/server-control';
32
+ import { MobileSessionHeader } from '@/client/components/mobile/mobile-session-sidebar/Header';
33
+ import type { ShellServersState } from '@/client/lib/shell/servers';
31
34
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
32
35
 
33
- const state = (overrides: Partial<DesktopServersState> = {}): DesktopServersState => ({
36
+ const state = (overrides: Partial<ShellServersState> = {}): ShellServersState => ({
34
37
  entries: [],
35
38
  detected: [],
36
39
  ...overrides,
37
40
  });
38
41
 
39
- const LOCAL: DesktopServersState = state({
42
+ const LOCAL: ShellServersState = state({
40
43
  entries: [
41
44
  { id: 'local:3001', label: 'Local :3001', url: 'http://127.0.0.1:3001', kind: 'managed', port: 3001, running: true, owned: true, version: '0.5.3', mode: 'prod', pid: 42, source: 'stored' },
42
45
  { id: 'remote:https://nas:8443', label: 'NAS', url: 'https://nas:8443', kind: 'remote', running: false, owned: false, source: 'stored' },
@@ -48,18 +51,32 @@ const LOCAL: DesktopServersState = state({
48
51
  activeUrl: 'http://127.0.0.1:3001',
49
52
  });
50
53
 
54
+ /** What the three desktop shells answer: they can start a server of their own. */
55
+ const DESKTOP = LOCAL;
56
+
57
+ /** What a phone answers: no spawning, no per-port records on the device. */
58
+ const PHONE: ShellServersState = state({
59
+ entries: [
60
+ { id: 'local:3001', label: 'Home NAS', url: 'http://192.168.1.10:3000', kind: 'remote', running: true, owned: false, version: '0.5.3', source: 'stored' },
61
+ { id: 'remote:https://office', label: 'Office', url: 'https://office.example:3000', kind: 'remote', running: false, owned: false, source: 'stored' },
62
+ ],
63
+ activeId: 'local:3001',
64
+ activeUrl: 'http://192.168.1.10:3000',
65
+ startable: false,
66
+ });
67
+
51
68
  let win: Window;
52
69
  let container: HTMLElement;
53
70
  let calls: Array<{ command: string; args?: Record<string, unknown> }>;
54
71
 
55
- function mount(next: DesktopServersState | Error) {
72
+ function mount(next: ShellServersState | Error, variant: 'nav' | 'chip' = 'nav', open = true) {
56
73
  calls = [];
57
74
  win.document.body.innerHTML = '';
58
75
  container = win.document.createElement('div') as unknown as HTMLElement;
59
76
  win.document.body.appendChild(container as never);
60
- // The transport the macOS shell installs: `__kabmoCall` answers through the
61
- // same door the shell uses, which is what makes this a test of the bridge
62
- // rather than of a stub only this suite knows about.
77
+ // The transport the shells install: `__kabmoCall` answers through the same
78
+ // door the shell uses, which is what makes this a test of the bridge rather
79
+ // than of a stub only this suite knows about.
63
80
  const shellWindow = win as unknown as {
64
81
  __kabmoCall?: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
65
82
  };
@@ -69,8 +86,14 @@ function mount(next: DesktopServersState | Error) {
69
86
  return next;
70
87
  };
71
88
  act(() => {
72
- render(h(ServerSwitcher, { open: true, onClose: () => {} }), container as never);
89
+ render(h(ServerControl, { variant }), container as never);
73
90
  });
91
+ if (open) {
92
+ const trigger = container.querySelector('button');
93
+ act(() => {
94
+ (trigger as HTMLButtonElement | null)?.click();
95
+ });
96
+ }
74
97
  }
75
98
 
76
99
  async function settle() {
@@ -92,9 +115,21 @@ afterEach(() => {
92
115
  restoreDomGlobals();
93
116
  });
94
117
 
95
- describe('ServerSwitcher', () => {
118
+ describe('ServerControl', () => {
119
+ test('a browser renders nothing, because there is no shell to control', async () => {
120
+ win.document.body.innerHTML = '';
121
+ const bare = win.document.createElement('div');
122
+ win.document.body.appendChild(bare as never);
123
+ act(() => {
124
+ render(h(ServerControl, { variant: 'chip' }), bare as never);
125
+ });
126
+ await settle();
127
+ expect((bare.textContent ?? '').trim()).toBe('');
128
+ expect(bare.querySelector('button')).toBeNull();
129
+ });
130
+
96
131
  test('lists the stored servers, the detected ones, and marks the active row', async () => {
97
- mount(LOCAL);
132
+ mount(DESKTOP);
98
133
  await settle();
99
134
  expect(text()).toContain('This window');
100
135
  expect(text()).toContain('Local :3001');
@@ -105,8 +140,14 @@ describe('ServerSwitcher', () => {
105
140
  expect(container.querySelector('[aria-label="Active"]')).not.toBeNull();
106
141
  });
107
142
 
143
+ test('the trigger and the panel read ONE list — one read, not two polls', async () => {
144
+ mount(DESKTOP);
145
+ await settle();
146
+ expect(calls.filter((call) => call.command === 'servers_state')).toHaveLength(1);
147
+ });
148
+
108
149
  test('a stopped server is offered as Stopped and cannot be connected to', async () => {
109
- mount(LOCAL);
150
+ mount(DESKTOP);
110
151
  await settle();
111
152
  expect(text()).toContain('Stopped');
112
153
  const nas = [...container.querySelectorAll('button')].find((button) =>
@@ -117,7 +158,7 @@ describe('ServerSwitcher', () => {
117
158
  });
118
159
 
119
160
  test('Stop is offered only for a server this shell started', async () => {
120
- mount(LOCAL);
161
+ mount(DESKTOP);
121
162
  await settle();
122
163
  const stops = [...container.querySelectorAll('button')].filter((button) =>
123
164
  (button.getAttribute('aria-label') ?? '').startsWith('Stop '),
@@ -125,26 +166,46 @@ describe('ServerSwitcher', () => {
125
166
  expect(stops.map((button) => button.getAttribute('aria-label'))).toEqual(['Stop Local :3001']);
126
167
  });
127
168
 
128
- test('a refused add shows the shell’s own sentence', async () => {
129
- mount(new Error("Use the server's root address — a base path is not supported."));
169
+ test('a phone is offered no Start, and no local discovery', async () => {
170
+ mount(PHONE, 'chip');
130
171
  await settle();
131
- expect(text()).toContain('root address');
172
+ expect(text()).toContain('Home NAS');
173
+ expect(text()).not.toContain('Start a local server');
174
+ expect(text()).not.toContain('Found on this machine');
175
+ // The chip's own accessible name carries the server, since it has no label.
176
+ expect(container.querySelector('[aria-label^="Server: Home NAS"]')).not.toBeNull();
132
177
  });
133
178
 
134
- test('a browser renders nothing, because there is no shell to control', async () => {
135
- mount(LOCAL);
136
- delete (win as unknown as { __kabmoCall?: unknown }).__kabmoCall;
137
- calls = [];
138
- win.document.body.innerHTML = '';
139
- const bare = win.document.createElement('div');
140
- win.document.body.appendChild(bare as never);
141
- act(() => {
142
- render(h(ServerSwitcher, { open: true, onClose: () => {} }), bare as never);
143
- });
179
+ /**
180
+ * The phone's trigger lives in the DRAWER's title bar, not in the chat header:
181
+ * measured at 390px with a password set, the chat header has ~100px spare and
182
+ * adding 40px left the session title 49px, while this row has ~158px spare.
183
+ */
184
+ test('the drawer header carries the chip, but only inside a shell', async () => {
185
+ const mountHeader = () => {
186
+ win.document.body.innerHTML = '';
187
+ container = win.document.createElement('div') as unknown as HTMLElement;
188
+ win.document.body.appendChild(container as never);
189
+ act(() => {
190
+ render(h(MobileSessionHeader, { onClose: () => {} }), container as never);
191
+ });
192
+ };
193
+
194
+ mountHeader();
195
+ await settle();
196
+ expect(container.querySelector('[aria-label="Choose a server"]')).toBeNull();
197
+
198
+ (win as unknown as { __kabmoCall?: unknown }).__kabmoCall = async () => state();
199
+ mountHeader();
144
200
  await settle();
145
- // The panel still draws (it is a component with an explicit `open`), but it
146
- // must not have issued a single bridge call — that is what would throw in a
147
- // browser. The navbar is what hides the control entirely.
148
- expect(calls).toEqual([]);
201
+ expect(container.querySelector('[aria-label="Choose a server"]')).not.toBeNull();
202
+ // The drawer's own control is untouched.
203
+ expect(container.querySelector('[aria-label="Close sidebar"]')).not.toBeNull();
204
+ });
205
+
206
+ test('a refused add shows the shell’s own sentence', async () => {
207
+ mount(new Error("Use the server's root address — a base path is not supported."));
208
+ await settle();
209
+ expect(text()).toContain('root address');
149
210
  });
150
211
  });
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The server control: a trigger that says which server this window is on, and
8
+ * the panel that changes it.
9
+ *
10
+ * ONE control for five shells, with two triggers because the surfaces differ and
11
+ * the fact does not:
12
+ *
13
+ * - `nav` — the desktop navbar's labelled button (icon, label, status dot). The
14
+ * macOS / Windows / Linux windows have the room.
15
+ * - `chip` — a phone's icon-only button. The chat header has no room left (a
16
+ * measured 100px free at 390 once the session title and the control cluster
17
+ * are paid for), so it sits in the DRAWER's title bar instead, where the row
18
+ * has ~158px spare and nothing has to be truncated to pay for it.
19
+ *
20
+ * The store lives HERE and not in the panel: the trigger and its popover must
21
+ * read one list. Two copies is how a trigger says "running" over rows that say
22
+ * `Stopped` — and how two 4-second polls probe every server twice.
23
+ *
24
+ * A desktop shell narrowed below the layout breakpoint renders the PHONE layout,
25
+ * so its navbar is gone and only the drawer's chip is left. That is the same
26
+ * control, not a second one, which is why it is drawn whenever an answer exists
27
+ * rather than on a desktop-vs-phone test.
28
+ */
29
+
30
+ import { useEffect, useRef, useState } from 'preact/hooks';
31
+ import { ServerCog } from 'lucide-preact';
32
+ import { useShellServers } from '@/client/hooks/shell/servers';
33
+ import { hasShellBridge } from '@/client/lib/shell/transport';
34
+ import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
35
+ import { ServerPanel } from '@/client/components/common/server-control/Panel';
36
+
37
+ export type ServerControlVariant = 'nav' | 'chip';
38
+
39
+ interface ServerControlProps {
40
+ variant: ServerControlVariant;
41
+ }
42
+
43
+ /** The chip's box, matched to the drawer header's own close button. */
44
+ const CHIP_CLASS =
45
+ 'w-8 h-8 rounded-lg flex items-center justify-center text-ink/60 hover:text-ink hover:bg-ink/5 active:bg-ink/10 transition-colors cursor-pointer flex-shrink-0 titlebar-no-drag';
46
+
47
+ export function ServerControl({ variant }: ServerControlProps) {
48
+ // A native host has to be PRESENT before the control exists at all: a browser
49
+ // has no shell to control, and a button that opened onto "not available"
50
+ // would be a button that never works.
51
+ const available = hasShellBridge();
52
+ const [open, setOpen] = useState(false);
53
+ const ref = useRef<HTMLDivElement>(null);
54
+ const store = useShellServers(open);
55
+ const active =
56
+ store.state?.entries.find((entry) => entry.id === store.state?.activeId) ??
57
+ store.state?.detected.find((entry) => entry.url === store.state?.activeUrl) ??
58
+ null;
59
+
60
+ useOnClickOutside(ref, () => setOpen(false));
61
+
62
+ // A shell that went away (a page kept across a host restart) must not leave a
63
+ // dangling promise behind: closing it is the honest state.
64
+ useEffect(() => {
65
+ if (!available) setOpen(false);
66
+ }, [available]);
67
+
68
+ if (!available) return null;
69
+
70
+ const summary = active
71
+ ? `Server: ${active.label} — ${active.running ? 'running' : 'stopped'}`
72
+ : 'Choose a server';
73
+
74
+ if (variant === 'chip') {
75
+ return (
76
+ <div className="relative flex-shrink-0" ref={ref}>
77
+ <button
78
+ type="button"
79
+ onClick={() => setOpen((was) => !was)}
80
+ className={CHIP_CLASS}
81
+ title={summary}
82
+ aria-label={summary}
83
+ aria-haspopup="dialog"
84
+ aria-expanded={open}
85
+ >
86
+ <ServerCog size={18} strokeWidth={1.8} />
87
+ </button>
88
+ <ServerPanel open={open} onClose={() => setOpen(false)} variant="chip" store={store} />
89
+ </div>
90
+ );
91
+ }
92
+
93
+ return (
94
+ <div className="relative" ref={ref}>
95
+ <button
96
+ type="button"
97
+ onClick={() => setOpen((was) => !was)}
98
+ className="flex items-center gap-1.5 rounded px-1.5 py-1 text-ink/60 hover:text-ink hover:bg-ink/10 transition-colors cursor-pointer"
99
+ title={summary}
100
+ aria-label="Servers"
101
+ aria-haspopup="dialog"
102
+ aria-expanded={open}
103
+ >
104
+ <ServerCog size={16} />
105
+ {active && (
106
+ <span className="max-w-[120px] truncate text-[11px] font-medium text-ink/70">
107
+ {active.label}
108
+ </span>
109
+ )}
110
+ <span
111
+ className={`w-1.5 h-1.5 rounded-full ${active?.running ? 'bg-success' : 'bg-ink/25'}`}
112
+ aria-hidden="true"
113
+ />
114
+ </button>
115
+ <ServerPanel open={open} onClose={() => setOpen(false)} variant="nav" store={store} />
116
+ </div>
117
+ );
118
+ }
@@ -1,5 +1,4 @@
1
- import { useRef, useState } from 'preact/hooks';
2
- import { Loader2, MoreHorizontal, PanelLeft, ServerCog } from 'lucide-preact';
1
+ import { Loader2, MoreHorizontal, PanelLeft } from 'lucide-preact';
3
2
  import { HeaderControls } from '@/client/components/common/header-controls';
4
3
  import { BrandWordmark } from '@/client/components/common/brand-wordmark';
5
4
  import { StreamStatusDot } from '@/client/components/common/StreamStatusDot';
@@ -9,11 +8,8 @@ import { useSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
9
8
  import type { AgentStreamStatus } from '@/shared/lib/chat/omp/status';
10
9
  import { withChord } from '@/client/lib/ui/with-chord';
11
10
  import { titlebarPaddingLeft, titlebarPaddingRight } from '@/shared/lib/ui/titlebar';
12
- import { ServerSwitcher } from '@/client/components/common/server-switcher';
13
- import { useDesktopServers } from '@/client/hooks/desktop/servers';
14
- import { isDesktopShell } from '@/client/lib/desktop/bridge';
11
+ import { ServerControl } from '@/client/components/common/server-control';
15
12
  import { dragRegionProps, titlebarInsetLeft } from '@/client/lib/desktop/titlebar';
16
- import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
17
13
 
18
14
  interface TopNavbarProps {
19
15
  sessionTitle: string | null;
@@ -61,19 +57,6 @@ export function TopNavbar({
61
57
  // sidebar row may be scrolled out of view — so the header says the wait is
62
58
  // happening even when the row that started it is not on screen.
63
59
  const renaming = useSessionRenaming(sessionId);
64
- // The shell's server control: which server this window is on, and how to
65
- // change it. Absent in a browser — there is no shell to control there, and a
66
- // button that opened onto "not available" would never work.
67
- const shell = isDesktopShell();
68
- const [serverPanelOpen, setServerPanelOpen] = useState(false);
69
- const serverPanelRef = useRef<HTMLDivElement>(null);
70
- const servers = useDesktopServers(serverPanelOpen);
71
- const activeServer =
72
- servers.state?.entries.find((entry) => entry.id === servers.state?.activeId) ??
73
- servers.state?.detected.find((entry) => entry.url === servers.state?.activeUrl) ??
74
- null;
75
- useOnClickOutside(serverPanelRef, () => setServerPanelOpen(false));
76
-
77
60
  const hasSessionActions = Boolean(
78
61
  sessionActions && (sessionActions.onRename || sessionActions.onRenameWithAi || sessionActions.onArchive || sessionActions.onDelete)
79
62
  );
@@ -162,37 +145,12 @@ export function TopNavbar({
162
145
  <div className="flex items-center space-x-3 titlebar-no-drag">
163
146
  {/* One cluster, one order, shared with the phone's header. Each layout
164
147
  passes only what it has; the order is stated in `HeaderControls`. */}
165
- {shell && (
166
- <div className="relative" ref={serverPanelRef}>
167
- <button
168
- type="button"
169
- onClick={() => setServerPanelOpen((open) => !open)}
170
- title={
171
- activeServer
172
- ? `Server: ${activeServer.label} — ${activeServer.running ? 'running' : 'stopped'}`
173
- : 'Choose a server'
174
- }
175
- aria-label="Servers"
176
- aria-haspopup="dialog"
177
- aria-expanded={serverPanelOpen}
178
- className="flex items-center gap-1.5 rounded px-1.5 py-1 text-ink/60 hover:text-ink hover:bg-ink/10 transition-colors cursor-pointer"
179
- >
180
- <ServerCog size={16} />
181
- {activeServer && (
182
- <span className="max-w-[120px] truncate text-[11px] font-medium text-ink/70">
183
- {activeServer.label}
184
- </span>
185
- )}
186
- <span
187
- className={`w-1.5 h-1.5 rounded-full ${
188
- activeServer?.running ? 'bg-success' : 'bg-ink/25'
189
- }`}
190
- aria-hidden="true"
191
- />
192
- </button>
193
- <ServerSwitcher open={serverPanelOpen} onClose={() => setServerPanelOpen(false)} />
194
- </div>
195
- )}
148
+ {/* The shell's server control. It draws nothing in a browser; a shell
149
+ window narrowed below the layout breakpoint renders the PHONE layout
150
+ and gets the same control in the drawer's header instead — which is
151
+ why the trigger, the store and the panel all live in one component
152
+ rather than in this file. */}
153
+ <ServerControl variant="nav" />
196
154
  <HeaderControls
197
155
  layout="desktop"
198
156
  sessionId={sessionId ?? null}
@@ -9,6 +9,7 @@ import { StreamStatusDot } from '@/client/components/common/StreamStatusDot';
9
9
  import { BrandWordmark } from '@/client/components/common/brand-wordmark';
10
10
  import { HeaderControls } from '@/client/components/common/header-controls';
11
11
  import { titlebarPaddingLeft, titlebarPaddingRight } from '@/shared/lib/ui/titlebar';
12
+ import { mobileOverlayStyle } from '@/shared/lib/ui/mobile-overlay';
12
13
  import { dragRegionProps, titlebarInsetLeft } from '@/client/lib/desktop/titlebar';
13
14
 
14
15
  interface MobileHeaderProps {
@@ -174,21 +175,14 @@ export function MobileHeader({
174
175
 
175
176
  {/* Pinned to the viewport, not to the trigger: the trigger sits
176
177
  ~155px from the left edge, so a 288px panel anchored at its
177
- `left-0` ran off the right edge of a phone screen. Fixed with
178
- both insets keeps it inside the safe area at any width. */}
178
+ `left-0` ran off the right edge of a phone screen. The six numbers
179
+ that keep it inside the safe area at any width live in
180
+ `mobileOverlayStyle`, shared with the server panel — the two used
181
+ to state them separately and drifted. */}
179
182
  {showSessionPicker && (
180
183
  <div
181
184
  className="fixed z-50 bg-paper border border-ink/15 rounded-xl shadow-lg p-2 text-xs"
182
- style={{
183
- top: 'calc(3.5rem + env(safe-area-inset-top, 0px) + 0.375rem)',
184
- left: 'max(0.75rem, env(safe-area-inset-left, 0px))',
185
- right: 'max(0.75rem, env(safe-area-inset-right, 0px))',
186
- maxWidth: '18rem',
187
- // A landscape phone is only ~390px tall; without this the list
188
- // ran past the bottom edge the same way it ran past the right.
189
- maxHeight: 'calc(100dvh - 3.5rem - env(safe-area-inset-top, 0px) - 1.125rem)',
190
- overflowY: 'auto',
191
- }}
185
+ style={mobileOverlayStyle()}
192
186
  >
193
187
  <button
194
188
  type="button"