@kabmo-labs/kabmo 0.15.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 (177) hide show
  1. package/README.md +3 -2
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +412 -394
  4. package/dist/client/static/js/index-3ve31rzx.css +1 -0
  5. package/dist/client/static/js/{index-mx658m43.js → index-rerjq5th.js} +846 -844
  6. package/marketplace/plugins/stats/README.md +27 -8
  7. package/marketplace/plugins/stats/package.json +2 -2
  8. package/marketplace/plugins/stats/src/HeaderReadout.test.tsx +2 -1
  9. package/marketplace/plugins/stats/src/HeaderReadout.tsx +6 -2
  10. package/marketplace/plugins/stats/src/KillConfirm.test.tsx +159 -0
  11. package/marketplace/plugins/stats/src/KillConfirm.tsx +145 -0
  12. package/marketplace/plugins/stats/src/ProcessTable.tsx +54 -8
  13. package/marketplace/plugins/stats/src/TotalsBar.test.tsx +5 -2
  14. package/marketplace/plugins/stats/src/TotalsBar.tsx +13 -3
  15. package/marketplace/plugins/stats/src/app.test.tsx +100 -4
  16. package/marketplace/plugins/stats/src/app.tsx +51 -4
  17. package/marketplace/plugins/stats/src/groups.test.ts +1 -1
  18. package/marketplace/plugins/stats/src/kill.test.ts +131 -0
  19. package/marketplace/plugins/stats/src/kill.ts +74 -0
  20. package/marketplace/plugins/stats/src/labels.test.ts +1 -0
  21. package/marketplace/plugins/stats/src/machine.test.ts +77 -0
  22. package/marketplace/plugins/stats/src/machine.ts +115 -0
  23. package/marketplace/plugins/stats/src/proc/darwin.ts +38 -0
  24. package/marketplace/plugins/stats/src/proc/linux.ts +4 -0
  25. package/marketplace/plugins/stats/src/proc/ps.ts +1 -0
  26. package/marketplace/plugins/stats/src/proc/types.ts +11 -0
  27. package/marketplace/plugins/stats/src/sampler.test.ts +42 -4
  28. package/marketplace/plugins/stats/src/sampler.ts +32 -18
  29. package/marketplace/plugins/stats/src/server.ts +29 -2
  30. package/marketplace/plugins/stats/src/snapshot.ts +31 -3
  31. package/package.json +3 -2
  32. package/src/client/components/common/Modal.tsx +7 -0
  33. package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
  34. package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
  35. package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
  36. package/src/client/components/common/code-surface/extensions.ts +7 -4
  37. package/src/client/components/common/code-surface/theme.ts +34 -9
  38. package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
  39. package/src/client/components/common/code-surface/whitespace.ts +140 -0
  40. package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +73 -35
  41. package/src/client/components/common/{server-switcher → server-control}/index.test.tsx +98 -37
  42. package/src/client/components/common/server-control/index.tsx +118 -0
  43. package/src/client/components/layout/LeftDock.tsx +1 -0
  44. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
  45. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +1 -0
  46. package/src/client/components/mobile/RightSidebar.tsx +1 -0
  47. package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
  48. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
  49. package/src/client/components/mobile/mobile-session-sidebar/use-dock.ts +1 -0
  50. package/src/client/components/settings/Modal.tsx +9 -3
  51. package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
  52. package/src/client/components/settings/categories/AgentSettings.tsx +27 -6
  53. package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
  54. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
  55. package/src/client/components/settings/categories/SkillSettings.tsx +6 -3
  56. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +5 -0
  57. package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
  58. package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
  59. package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
  60. package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
  61. package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
  62. package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
  63. package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
  64. package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
  65. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
  66. package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
  67. package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
  68. package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
  69. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
  70. package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
  71. package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
  72. package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
  73. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +208 -0
  74. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +137 -232
  75. package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
  76. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +123 -87
  77. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +179 -0
  78. package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
  79. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
  86. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
  87. package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
  88. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
  89. package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
  90. package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
  91. package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
  92. package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
  93. package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
  94. package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
  95. package/src/client/components/workspace/file-explorer/index.tsx +21 -20
  96. package/src/client/components/workspace/model-dropdown/Panel.tsx +7 -2
  97. package/src/client/components/workspace/model-dropdown/Section.test.tsx +13 -0
  98. package/src/client/components/workspace/model-dropdown/Section.tsx +5 -1
  99. package/src/client/components/workspace/panels/builtin.tsx +7 -0
  100. package/src/client/components/workspace/wiki-panel/NavModal.test.tsx +136 -0
  101. package/src/client/components/workspace/wiki-panel/NavModal.tsx +94 -0
  102. package/src/client/components/workspace/wiki-panel/PageView.tsx +16 -10
  103. package/src/client/components/workspace/wiki-panel/index.tsx +44 -9
  104. package/src/client/data/settings/omp-schema.json +91 -4
  105. package/src/client/data/settings/project.ts +9 -28
  106. package/src/client/data/settings/skill.ts +6 -32
  107. package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
  108. package/src/client/hooks/settings/projects/index.ts +294 -0
  109. package/src/client/hooks/settings/projects.test.ts +237 -0
  110. package/src/client/hooks/settings/skill-catalog.ts +101 -9
  111. package/src/client/hooks/settings/skill-git-import.ts +153 -0
  112. package/src/client/hooks/shell/servers.test.ts +166 -0
  113. package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
  114. package/src/client/hooks/ui/updates/shell-download.ts +1 -1
  115. package/src/client/hooks/ui/updates/shell-update.ts +2 -6
  116. package/src/client/hooks/workspace/file-row-drag.ts +41 -0
  117. package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
  118. package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
  119. package/src/client/hooks/workspace/root-drop-target.ts +77 -0
  120. package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
  121. package/src/client/lib/desktop/dropped-paths.ts +1 -1
  122. package/src/client/lib/desktop/titlebar.test.ts +12 -3
  123. package/src/client/lib/desktop/titlebar.ts +1 -1
  124. package/src/client/lib/shell/desktop.ts +117 -0
  125. package/src/client/lib/shell/servers.ts +75 -0
  126. package/src/client/lib/shell/transport.ts +216 -0
  127. package/src/client/main.tsx +9 -0
  128. package/src/server/lib/db/schema.ts +11 -0
  129. package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
  130. package/src/server/lib/lifecycle/memory.test.ts +41 -1
  131. package/src/server/lib/lifecycle/memory.ts +131 -14
  132. package/src/server/lib/omp/config/skill-sources.ts +49 -0
  133. package/src/server/lib/omp/config/skills-git-install.ts +155 -0
  134. package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
  135. package/src/server/lib/omp/config/skills-git.test.ts +220 -0
  136. package/src/server/lib/omp/session/subagent-presence-scan.test.ts +137 -0
  137. package/src/server/lib/omp/session/subagent-presence-scan.ts +120 -0
  138. package/src/server/lib/omp/session/subagent-presence-store.test.ts +120 -0
  139. package/src/server/lib/omp/session/subagent-presence-store.ts +65 -0
  140. package/src/server/lib/omp/session/subagent-presence.ts +52 -15
  141. package/src/server/lib/workspace/project-model.server.test.ts +102 -0
  142. package/src/server/lib/workspace/project-model.server.ts +47 -0
  143. package/src/server/lib/workspace/project-patch.server.ts +156 -0
  144. package/src/server/routes/agent/new.ts +8 -1
  145. package/src/server/routes/settings/agents.ts +19 -7
  146. package/src/server/routes/settings/projects.ts +53 -19
  147. package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
  148. package/src/server/routes/settings/settings-store-routes.test.ts +5 -2
  149. package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
  150. package/src/server/routes/settings/skills.test.ts +225 -0
  151. package/src/server/routes/settings/skills.ts +18 -15
  152. package/src/shared/lib/fs/folder-chain.test.ts +81 -1
  153. package/src/shared/lib/fs/folder-chain.ts +84 -0
  154. package/src/shared/lib/omp/config/schema.test.ts +35 -0
  155. package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
  156. package/src/shared/lib/omp/session/job-progress.ts +31 -0
  157. package/src/shared/lib/omp/session/proc.ts +5 -0
  158. package/src/shared/lib/omp/session/wait.ts +5 -0
  159. package/src/shared/lib/ui/mobile-overlay.ts +61 -0
  160. package/src/shared/lib/ui/svg-scope.test.ts +97 -0
  161. package/src/shared/lib/ui/svg-scope.ts +134 -0
  162. package/src/shared/lib/workspace/project-accent.test.ts +69 -0
  163. package/src/shared/lib/workspace/project-accent.ts +63 -0
  164. package/src/shared/lib/workspace/project-icon.ts +40 -0
  165. package/src/shared/lib/workspace/project-model.test.ts +79 -0
  166. package/src/shared/lib/workspace/project-model.ts +64 -0
  167. package/src/shared/types/settings/skill.ts +53 -3
  168. package/src/test-support/file-explorer-disk.test-util.ts +25 -1
  169. package/src/test-support/file-explorer-drag.test-util.ts +88 -0
  170. package/src/test-support/file-explorer.test-util.ts +47 -47
  171. package/dist/client/static/js/index-28pwtt69.css +0 -1
  172. package/src/client/components/common/code-surface/indent-guide.ts +0 -104
  173. package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
  174. package/src/client/hooks/desktop/servers.test.ts +0 -73
  175. package/src/client/lib/desktop/bridge.ts +0 -203
  176. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
  177. package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
@@ -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
+ }
@@ -86,6 +86,7 @@ export function LeftDockView({
86
86
  ...(onClose ? { onClose } : {}),
87
87
  appSettings,
88
88
  ...(streamStatus ? { streamStatus } : {}),
89
+ layout: 'desktop',
89
90
  };
90
91
 
91
92
  return (
@@ -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}
@@ -299,6 +299,7 @@ export function WorkspacePanels(props: WorkspacePanelsProps) {
299
299
  onRefresh: onRefreshWorkspace,
300
300
  onOpenFile,
301
301
  onClose: onToggleRightPanel,
302
+ layout: 'desktop',
302
303
  };
303
304
  return (
304
305
  <div key={panel.id} className={isActiveView ? 'w-full h-full' : 'hidden'}>
@@ -85,6 +85,7 @@ export function MobileRightSidebar({
85
85
  onClose,
86
86
  // The drawer draws its own tab bar, so a view's own header would be a second one.
87
87
  showHeader: false,
88
+ layout: 'phone',
88
89
  };
89
90
 
90
91
  return (
@@ -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"
@@ -1,8 +1,30 @@
1
1
  import { X } from 'lucide-preact';
2
2
  import { BrandWordmark } from '@/client/components/common/brand-wordmark';
3
+ import { ServerControl } from '@/client/components/common/server-control';
3
4
  import { titlebarPaddingLeft, titlebarPaddingRight } from '@/shared/lib/ui/titlebar';
4
5
  import { dragRegionProps, titlebarInsetLeft } from '@/client/lib/desktop/titlebar';
5
6
 
7
+ /**
8
+ * The session drawer's title bar.
9
+ *
10
+ * Two controls on the right, and the second one is why this row exists in the
11
+ * shape it does:
12
+ *
13
+ * - the **server chip** — which server this window is on. A PHONE puts its
14
+ * server control here rather than in the chat header because this row has the
15
+ * room and that one does not: measured at 390px with a password set, the chat
16
+ * header has ~100px spare while the session title is the one thing that may
17
+ * give up width, and adding 40px there left the title 49px. This row has
18
+ * ~158px spare and truncates nothing to pay for the chip.
19
+ * - the **close** button.
20
+ *
21
+ * The chip is also what a DESKTOP shell window narrowed below the layout
22
+ * breakpoint relies on: it renders the phone layout, so its navbar — and the
23
+ * server control in it — is gone, and this is the only surface left.
24
+ *
25
+ * `viewLabel` says what the drawer is showing (Sessions, or a panel's name), so
26
+ * the chip is available in every view the drawer has.
27
+ */
6
28
  export function MobileSessionHeader({ onClose, viewLabel = 'Sessions' }: { onClose: () => void; viewLabel?: string }) {
7
29
  return (
8
30
  <div
@@ -22,23 +44,29 @@ export function MobileSessionHeader({ onClose, viewLabel = 'Sessions' }: { onClo
22
44
  paddingTop: 'env(safe-area-inset-top, 0px)',
23
45
  }}
24
46
  >
25
- <div className="flex items-center space-x-2.5 titlebar-no-drag">
26
- <span className="font-bold text-sm tracking-tight flex items-center">
47
+ <div className="flex items-center space-x-2.5 titlebar-no-drag min-w-0">
48
+ <span className="font-bold text-sm tracking-tight flex items-center flex-shrink-0">
27
49
  <BrandWordmark className="text-[16px]" />
28
50
  </span>
29
- <span className="text-ink/25 text-xs select-none">/</span>
30
- <span className="text-[11px] font-semibold text-ink/60 uppercase tracking-wider font-mono">{viewLabel}</span>
51
+ <span className="text-ink/25 text-xs select-none flex-shrink-0">/</span>
52
+ <span className="text-[11px] font-semibold text-ink/60 uppercase tracking-wider font-mono truncate">{viewLabel}</span>
31
53
  </div>
32
54
 
33
- <button
34
- type="button"
35
- onClick={onClose}
36
- className="w-9 h-9 rounded-xl hover:bg-ink/5 active:bg-ink/10 text-ink flex items-center justify-center transition-colors cursor-pointer titlebar-no-drag"
37
- title="Close sidebar"
38
- aria-label="Close sidebar"
39
- >
40
- <X size={19} strokeWidth={2} />
41
- </button>
55
+ <div className="flex items-center gap-1 titlebar-no-drag flex-shrink-0">
56
+ {/* Draws nothing in a browser: `ServerControl` hides itself when no
57
+ native host is present, which is the same rule the desktop navbar
58
+ follows rather than a second one stated here. */}
59
+ <ServerControl variant="chip" />
60
+ <button
61
+ type="button"
62
+ onClick={onClose}
63
+ className="w-9 h-9 rounded-xl hover:bg-ink/5 active:bg-ink/10 text-ink flex items-center justify-center transition-colors cursor-pointer"
64
+ title="Close sidebar"
65
+ aria-label="Close sidebar"
66
+ >
67
+ <X size={19} strokeWidth={2} />
68
+ </button>
69
+ </div>
42
70
  </div>
43
71
  );
44
72
  }
@@ -85,5 +85,6 @@ export function dockBodyProps(input: {
85
85
  ...(input.onOpenFile ? { onOpenFile: input.onOpenFile } : {}),
86
86
  onClose: input.onClose,
87
87
  showHeader: false,
88
+ layout: 'phone',
88
89
  };
89
90
  }
@@ -21,7 +21,7 @@ import { McpSettings } from '@/client/components/settings/categories/McpSettings
21
21
  import { SkillSettings } from '@/client/components/settings/categories/SkillSettings';
22
22
  import { PluginSettings } from '@/client/components/settings/categories/PluginSettings';
23
23
  import { PanelPluginSettings } from '@/client/components/settings/categories/PanelPluginSettings';
24
- import { SkillCatalogSettings } from '@/client/components/settings/categories/SkillCatalogSettings';
24
+ import { SkillCatalogSettings, type CatalogTab } from '@/client/components/settings/categories/SkillCatalogSettings';
25
25
  import { OtherSettings } from '@/client/components/settings/categories/OtherSettings';
26
26
  import { OmpSettings } from '@/client/components/settings/categories/OmpSettings';
27
27
  import { TokenUsageSettings } from '@/client/components/settings/categories/TokenUsageSettings';
@@ -44,6 +44,9 @@ export function SettingsModal({
44
44
  autoOpenAddProvider = false,
45
45
  }: SettingsModalProps) {
46
46
  const [activeCategory, setActiveCategory] = useState<SettingsCategoryId>(initialCategory);
47
+ // Which catalog tab a navigation asked for; the catalog itself owns the state
48
+ // once it is mounted, so this only seeds the mount.
49
+ const [catalogTab, setCatalogTab] = useState<CatalogTab>('browse');
47
50
  const [autoOpenAdd, setAutoOpenAdd] = useState(autoOpenAddProvider);
48
51
  const [searchQuery, setSearchQuery] = useState('');
49
52
  const [isMobileDrilled, setIsMobileDrilled] = useState(false);
@@ -167,11 +170,14 @@ export function SettingsModal({
167
170
  <SkillSettings
168
171
  settings={settings}
169
172
  onUpdate={handleUpdateSettings}
170
- onNavigateToCatalog={() => setActiveCategory('skills-catalog')}
173
+ onNavigateToCatalog={(tab) => {
174
+ setCatalogTab(tab ?? 'browse');
175
+ setActiveCategory('skills-catalog');
176
+ }}
171
177
  />
172
178
  );
173
179
  case 'skills-catalog':
174
- return <SkillCatalogSettings />;
180
+ return <SkillCatalogSettings initialTab={catalogTab} />;
175
181
  case 'omp':
176
182
  return <OmpSettings settings={settings} onUpdate={handleUpdateSettings} />;
177
183
  case 'usage':
@@ -13,13 +13,6 @@ export interface ProjectOption {
13
13
  value?: string;
14
14
  }
15
15
 
16
- /** Static project list shared by the agent, command, and skill sidebars. */
17
- export const PROJECT_OPTIONS: ProjectOption[] = [
18
- { id: 'kabmo', name: 'kabmo', label: 'kabmo' },
19
- { id: 'workspace-edge', name: 'workspace-edge', label: 'workspace-edge' },
20
- { id: 'global', name: 'global config', label: 'Global (All Projects)' },
21
- ];
22
-
23
16
  const optionValue = (option: ProjectOption): string => option.value ?? option.id;
24
17
 
25
18
  /**
@@ -34,7 +27,11 @@ const defaultTriggerLabel = (options: ProjectOption[], selectedProject: string):
34
27
  interface ProjectSelectorDropdownProps {
35
28
  selectedProject: string;
36
29
  onChangeProject: (value: string) => void;
37
- /** Defaults to {@link PROJECT_OPTIONS}. */
30
+ /**
31
+ * The real workspace folders (`useWorkspaceRoots`). Defaults to NONE: this
32
+ * used to fall back to a hardcoded list of made-up projects, so a panel that
33
+ * forgot to pass its options offered scopes that resolved to nothing.
34
+ */
38
35
  options?: ProjectOption[];
39
36
  /** Trigger label resolver; defaults to a `name` lookup by value. */
40
37
  getTriggerLabel?: (options: ProjectOption[], selectedProject: string) => string;
@@ -50,7 +47,7 @@ interface ProjectSelectorDropdownProps {
50
47
  export const ProjectSelectorDropdown: FunctionComponent<ProjectSelectorDropdownProps> = ({
51
48
  selectedProject,
52
49
  onChangeProject,
53
- options = PROJECT_OPTIONS,
50
+ options = [],
54
51
  getTriggerLabel = defaultTriggerLabel,
55
52
  variant = 'default',
56
53
  }) => {
@@ -97,6 +94,19 @@ export const ProjectSelectorDropdown: FunctionComponent<ProjectSelectorDropdownP
97
94
  );
98
95
  });
99
96
 
97
+ // No projects at all: the trigger says why instead of opening an empty menu
98
+ // (or, worse, naming a scope that does not exist).
99
+ if (options.length === 0) {
100
+ return (
101
+ <div className={variant === 'compact' ? 'p-2.5 border-b border-ink/10' : 'p-3 border-b border-ink/10'}>
102
+ <div className="flex items-center gap-2 px-2.5 py-1.5 rounded-lg border border-dashed border-ink/15 text-[11px] text-ink/50">
103
+ <Folder size={13} className="text-ink/40 flex-shrink-0" />
104
+ <span className="truncate">No projects yet — add one in Settings → Projects</span>
105
+ </div>
106
+ </div>
107
+ );
108
+ }
109
+
100
110
  if (variant === 'compact') {
101
111
  return (
102
112
  <div className="p-2.5 border-b border-ink/10 relative" ref={dropdownRef}>