@kabmo-labs/kabmo 0.15.0 → 0.16.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 (53) hide show
  1. package/README.md +1 -0
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +374 -356
  4. package/dist/client/static/js/{index-mx658m43.js → index-cpydmygd.js} +644 -644
  5. package/dist/client/static/js/index-fjnq2z2d.css +1 -0
  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/layout/LeftDock.tsx +1 -0
  34. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +1 -0
  35. package/src/client/components/mobile/RightSidebar.tsx +1 -0
  36. package/src/client/components/mobile/mobile-session-sidebar/use-dock.ts +1 -0
  37. package/src/client/components/workspace/model-dropdown/Panel.tsx +7 -2
  38. package/src/client/components/workspace/model-dropdown/Section.test.tsx +13 -0
  39. package/src/client/components/workspace/model-dropdown/Section.tsx +5 -1
  40. package/src/client/components/workspace/panels/builtin.tsx +7 -0
  41. package/src/client/components/workspace/wiki-panel/NavModal.test.tsx +136 -0
  42. package/src/client/components/workspace/wiki-panel/NavModal.tsx +94 -0
  43. package/src/client/components/workspace/wiki-panel/PageView.tsx +16 -10
  44. package/src/client/components/workspace/wiki-panel/index.tsx +44 -9
  45. package/src/server/lib/db/schema.ts +11 -0
  46. package/src/server/lib/lifecycle/memory.test.ts +41 -1
  47. package/src/server/lib/lifecycle/memory.ts +131 -14
  48. package/src/server/lib/omp/session/subagent-presence-scan.test.ts +137 -0
  49. package/src/server/lib/omp/session/subagent-presence-scan.ts +120 -0
  50. package/src/server/lib/omp/session/subagent-presence-store.test.ts +120 -0
  51. package/src/server/lib/omp/session/subagent-presence-store.ts +65 -0
  52. package/src/server/lib/omp/session/subagent-presence.ts +52 -15
  53. package/dist/client/static/js/index-28pwtt69.css +0 -1
@@ -25,7 +25,7 @@ import { createSampler, type SampleDeps } from './sampler';
25
25
  const SERVER_PID = 100;
26
26
 
27
27
  function proc(pid: number, ppid: number, argv: string[] | null, extra: Partial<ProcessInfo> = {}): ProcessInfo {
28
- return { pid, ppid, rss: 1024, cpuNs: 0, threads: 1, argv, cwd: null, startedAt: 1, ...extra };
28
+ return { pid, ppid, rss: 1024, footprint: null, cpuNs: 0, threads: 1, argv, cwd: null, startedAt: 1, ...extra };
29
29
  }
30
30
 
31
31
  /** A probe whose table the test controls, so the sampler's math is deterministic. */
@@ -42,6 +42,8 @@ function deps(rows: ProcessInfo[], overrides: Partial<SampleDeps> = {}): SampleD
42
42
  readDaemons: () => [],
43
43
  includeDaemons: false,
44
44
  historyPoints: 5,
45
+ // Injected so a sample never spawns `vm_stat` in a unit test.
46
+ readMachine: () => ({ totalMemBytes: 16 * 1024 ** 3, freeMemBytes: 8 * 1024 ** 3, cpuCount: 8, loadPerCore: 0.1 }),
45
47
  // No leases by default: every rpc-ui host reads as a prewarm unless a test
46
48
  // supplies one, which is exactly what a fresh pool looks like.
47
49
  readLease: () => null,
@@ -104,7 +106,7 @@ describe('createSampler', () => {
104
106
  const pids = snapshot.rows.map((row) => row.pid).sort((a, b) => a - b);
105
107
  expect(pids).toEqual([SERVER_PID, 101, 199, 200, 201]);
106
108
  expect(snapshot.total.processes).toBe(5);
107
- expect(snapshot.total.rss).toBe(1500);
109
+ expect(snapshot.total.memory).toBe(1500);
108
110
  // Deduped: pid 199 is reached by the daemon walk AND (via its own child
109
111
  // chain) by nothing else, but the browser subtree must appear once each.
110
112
  expect(new Set(pids).size).toBe(pids.length);
@@ -143,7 +145,7 @@ describe('createSampler', () => {
143
145
  const host = snapshot.groups.find((group) => group.key === 'prewarm:101');
144
146
  expect(host).toBeDefined();
145
147
  expect(host?.processes).toBe(2);
146
- expect(host?.rss).toBe(500);
148
+ expect(host?.memory).toBe(500);
147
149
  // The rows carry the same key, so the table can group them.
148
150
  expect(snapshot.rows.find((row) => row.pid === 102)?.groupKey).toBe('prewarm:101');
149
151
  });
@@ -179,12 +181,48 @@ describe('createSampler', () => {
179
181
  const sampler = createSampler(deps(rows, { historyPoints: 3 }));
180
182
  for (let i = 0; i < 6; i += 1) sampler.sample();
181
183
  const bounded = sampler.sample();
182
- expect(bounded.history?.rss).toHaveLength(3);
184
+ expect(bounded.history?.memory).toHaveLength(3);
183
185
 
184
186
  const noHistory = createSampler(deps(rows, { historyPoints: 0 })).sample();
185
187
  expect(noHistory.history).toBeUndefined();
186
188
  });
187
189
 
190
+ test('the memory figure is the footprint when the probe has one, and RSS when it does not', () => {
191
+ // Measured on the live server: 317 MB resident for a process whose
192
+ // footprint was 134 MB. The panel shows the second, because that is what
193
+ // the OS is actually charging; a row that cannot report one keeps RSS
194
+ // rather than contributing nothing.
195
+ const rows: ProcessInfo[] = [
196
+ proc(SERVER_PID, 1, ['bun', '--kabmo-server'], { rss: 317, footprint: 134 }),
197
+ proc(101, SERVER_PID, ['bun', '/bin/omp', '--mode', 'rpc-ui'], { rss: 200, footprint: null }),
198
+ ];
199
+ const snapshot = createSampler(deps(rows)).sample();
200
+ const server = snapshot.rows.find((row) => row.pid === SERVER_PID);
201
+ const host = snapshot.rows.find((row) => row.pid === 101);
202
+ expect(server?.memory).toBe(134);
203
+ expect(server?.memorySource).toBe('footprint');
204
+ expect(server?.rss).toBe(317);
205
+ expect(host?.memory).toBe(200);
206
+ expect(host?.memorySource).toBe('rss');
207
+ // One of each: the totals sum what the rows print, and say they mixed.
208
+ expect(snapshot.total.memory).toBe(334);
209
+ expect(snapshot.memorySource).toBe('mixed');
210
+ });
211
+
212
+ test('a fully-footprint sample says so, and a fully-resident one says that', () => {
213
+ const footprinted = createSampler(
214
+ deps([proc(SERVER_PID, 1, ['bun', '--kabmo-server'], { rss: 317, footprint: 134 })]),
215
+ ).sample();
216
+ expect(footprinted.memorySource).toBe('footprint');
217
+ expect(footprinted.total.memory).toBe(134);
218
+
219
+ const resident = createSampler(
220
+ deps([proc(SERVER_PID, 1, ['bun', '--kabmo-server'], { rss: 317, footprint: null })]),
221
+ ).sample();
222
+ expect(resident.memorySource).toBe('rss');
223
+ expect(resident.total.memory).toBe(317);
224
+ });
225
+
188
226
  test('an unsupported probe reports its reason instead of an empty table', () => {
189
227
  const sampler = createSampler(
190
228
  deps([], {
@@ -37,11 +37,19 @@
37
37
  *
38
38
  * A process that appeared since the last sweep has no baseline and reports no
39
39
  * rate for one sample — the same honest gap, for the same reason.
40
+ *
41
+ * ## The memory figure is the OS's charge, not RSS
42
+ *
43
+ * RSS on macOS counts pages Bun has freed but not returned: measured on the
44
+ * live server, 317 MB resident for a process whose physical footprint was
45
+ * 134 MB. The panel is what a reader uses to decide whether to restart
46
+ * something, so each row reports `footprint ?? rss` and remembers which it is;
47
+ * the totals sum that same figure, and `memorySource` says when the sample
48
+ * mixed the two (see `./machine` for the platform rules).
40
49
  */
41
50
 
42
- import os from 'node:os';
43
-
44
51
  import { type DaemonEntry, readDaemonRegistry } from './daemons';
52
+ import { readMachine } from './machine';
45
53
  import { assignGroups, type GroupKind } from './groups';
46
54
  import { describeProcess } from './labels';
47
55
  import { leaseOfPid } from './proc/identity';
@@ -151,15 +159,16 @@ export function createSampler(deps: SampleDeps): Sampler {
151
159
  const readLease = deps.readLease ?? leaseOfPid;
152
160
  const includeDaemons = deps.includeDaemons ?? true;
153
161
  const historyPoints = deps.historyPoints ?? 60;
162
+ const readFacts = deps.readMachine ?? readMachine;
154
163
 
155
164
  let baseline: Baseline | null = null;
156
- const rssHistory: number[] = [];
165
+ const memoryHistory: number[] = [];
157
166
  const cpuHistory: number[] = [];
158
167
 
159
168
  return {
160
169
  reset() {
161
170
  baseline = null;
162
- rssHistory.length = 0;
171
+ memoryHistory.length = 0;
163
172
  cpuHistory.length = 0;
164
173
  },
165
174
  sample(): StatsSnapshot {
@@ -204,6 +213,8 @@ export function createSampler(deps: SampleDeps): Sampler {
204
213
  serverPid: deps.serverPid,
205
214
  lease: leases.get(process.pid) ?? null,
206
215
  });
216
+ const footprint = process.footprint;
217
+ const memory = footprint ?? process.rss;
207
218
 
208
219
  rows.push({
209
220
  pid: process.pid,
@@ -212,6 +223,8 @@ export function createSampler(deps: SampleDeps): Sampler {
212
223
  detail: label.detail,
213
224
  groupKey: assignment.key,
214
225
  depth: assignment.depth,
226
+ memory,
227
+ memorySource: footprint === null ? 'rss' : 'footprint',
215
228
  rss: process.rss,
216
229
  cpuPercent,
217
230
  threads: process.threads,
@@ -226,11 +239,11 @@ export function createSampler(deps: SampleDeps): Sampler {
226
239
  title: label.title,
227
240
  detail: label.detail,
228
241
  processes: 0,
229
- rss: 0,
242
+ memory: 0,
230
243
  cpuPercent: 0,
231
244
  };
232
245
  group.processes += 1;
233
- group.rss += process.rss;
246
+ group.memory += memory;
234
247
  group.cpuPercent += cpuPercent ?? 0;
235
248
  if (process.pid === assignment.ownerPid) {
236
249
  group.title = label.title;
@@ -241,21 +254,26 @@ export function createSampler(deps: SampleDeps): Sampler {
241
254
 
242
255
  baseline = { at, cpuNs: cpuNsNow };
243
256
 
244
- rows.sort((a, b) => b.rss - a.rss);
245
- const groups = [...byGroup.values()].sort((a, b) => groupRank(a) - groupRank(b) || b.rss - a.rss);
257
+ const footprints = rows.filter((row) => row.memorySource === 'footprint').length;
258
+ const memorySource: StatsSnapshot['memorySource'] = footprints === 0 ? 'rss'
259
+ : footprints === rows.length ? 'footprint'
260
+ : 'mixed';
261
+
262
+ rows.sort((a, b) => b.memory - a.memory);
263
+ const groups = [...byGroup.values()].sort((a, b) => groupRank(a) - groupRank(b) || b.memory - a.memory);
246
264
  const total = {
247
265
  processes: rows.length,
248
- rss: groups.reduce((sum, entry) => sum + entry.rss, 0),
266
+ memory: groups.reduce((sum, entry) => sum + entry.memory, 0),
249
267
  cpuPercent: groups.reduce((sum, entry) => sum + entry.cpuPercent, 0),
250
268
  };
251
269
 
252
270
  let history: StatsSnapshot['history'];
253
271
  if (historyPoints > 0) {
254
- rssHistory.push(total.rss);
272
+ memoryHistory.push(total.memory);
255
273
  cpuHistory.push(Number(total.cpuPercent.toFixed(1)));
256
- while (rssHistory.length > historyPoints) rssHistory.shift();
274
+ while (memoryHistory.length > historyPoints) memoryHistory.shift();
257
275
  while (cpuHistory.length > historyPoints) cpuHistory.shift();
258
- history = { rss: [...rssHistory], cpuPercent: [...cpuHistory] };
276
+ history = { memory: [...memoryHistory], cpuPercent: [...cpuHistory] };
259
277
  }
260
278
 
261
279
  const snapshot: StatsSnapshot = {
@@ -264,12 +282,8 @@ export function createSampler(deps: SampleDeps): Sampler {
264
282
  rows,
265
283
  groups,
266
284
  total,
267
- machine: {
268
- totalMemBytes: os.totalmem(),
269
- freeMemBytes: os.freemem(),
270
- cpuCount: os.cpus().length,
271
- loadPerCore: os.cpus().length > 0 ? os.loadavg()[0] / os.cpus().length : os.loadavg()[0],
272
- },
285
+ memorySource,
286
+ machine: readFacts(),
273
287
  daemons,
274
288
  serverPid: deps.serverPid,
275
289
  ...(history ? { history } : {}),
@@ -36,6 +36,7 @@ import type { KabmoPluginApi, PluginJson } from '@kabmo-labs/kabmo-sdk';
36
36
 
37
37
  import { createSampler, type StatsSnapshot } from './sampler';
38
38
  import { readDaemonRegistry } from './daemons';
39
+ import { killStackProcess, type KillOutcome } from './kill';
39
40
 
40
41
  /** The tick's floor: below this a CPU delta is noise against the clock. */
41
42
  const MIN_SAMPLE_MS = 200;
@@ -113,7 +114,8 @@ export default function plugin(api: KabmoPluginApi) {
113
114
  probe: { name: 'unknown', supported: false, reason },
114
115
  rows: [],
115
116
  groups: [],
116
- total: { processes: 0, rss: 0, cpuPercent: 0 },
117
+ total: { processes: 0, memory: 0, cpuPercent: 0 },
118
+ memorySource: 'rss',
117
119
  machine: {
118
120
  totalMemBytes: 0,
119
121
  freeMemBytes: 0,
@@ -136,7 +138,8 @@ export default function plugin(api: KabmoPluginApi) {
136
138
  probe: { name: 'pending', supported: true },
137
139
  rows: [],
138
140
  groups: [],
139
- total: { processes: 0, rss: 0, cpuPercent: 0 },
141
+ total: { processes: 0, memory: 0, cpuPercent: 0 },
142
+ memorySource: 'rss',
140
143
  machine: { totalMemBytes: 0, freeMemBytes: 0, cpuCount: 0, loadPerCore: 0 },
141
144
  daemons: [],
142
145
  serverPid: process.pid,
@@ -219,6 +222,30 @@ export default function plugin(api: KabmoPluginApi) {
219
222
  },
220
223
  });
221
224
 
225
+ /**
226
+ * Stop one process in the measured stack.
227
+ *
228
+ * The sample taken HERE is the authority, not the table the panel drew: a
229
+ * pid the caller read off a stale snapshot may since have been recycled, and
230
+ * the fresh union is what turns "some pid" into "a process this panel
231
+ * measured". `killStackProcess` owns the refusals and never throws; a
232
+ * refusal is a result the dialog renders, not a 500.
233
+ */
234
+ api.rpc.register<{ pid: number }, KillOutcome>('kill', {
235
+ handler: ({ pid } = { pid: 0 }) => {
236
+ const outcome = killStackProcess(pid, {
237
+ sample: () => sampler.sample(),
238
+ serverPid: process.pid,
239
+ });
240
+ api.log.info(
241
+ outcome.killed
242
+ ? `signalled pid ${outcome.pid} (${outcome.title})`
243
+ : `refused to signal pid ${String(pid)}: ${outcome.reason}`,
244
+ );
245
+ return outcome;
246
+ },
247
+ });
248
+
222
249
  /**
223
250
  * The HTTP surface: a first paint for anything that is not the panel, and the
224
251
  * shape a `curl` or a monitor can read.
@@ -29,6 +29,20 @@ export interface ProcessRow {
29
29
  groupKey: string;
30
30
  /** Distance from the group's owner; 0 is the owner itself. */
31
31
  depth: number;
32
+ /**
33
+ * The figure the panel shows and sorts by: the OS's physical footprint when
34
+ * it reports one, resident size otherwise. See `memorySource`.
35
+ */
36
+ memory: number;
37
+ /**
38
+ * Which of the two `memory` is, per row.
39
+ *
40
+ * Both exist because a row can fall back independently: on macOS a process
41
+ * owned by another user answers no footprint, and dropping its RSS would
42
+ * remove it from the totals instead of reporting what is known.
43
+ */
44
+ memorySource: 'footprint' | 'rss';
45
+ /** Resident set size, kept beside `memory` so a row can explain the gap. */
32
46
  rss: number;
33
47
  cpuPercent: number | null;
34
48
  threads: number;
@@ -52,7 +66,8 @@ export interface GroupSummary {
52
66
  /** The owner's detail line. */
53
67
  detail: string;
54
68
  processes: number;
55
- rss: number;
69
+ /** Sum of the members' `memory` — the same figures the rows print. */
70
+ memory: number;
56
71
  cpuPercent: number;
57
72
  }
58
73
 
@@ -84,14 +99,22 @@ export interface StatsSnapshot {
84
99
  */
85
100
  groups: GroupSummary[];
86
101
  /** The whole union. */
87
- total: { processes: number; rss: number; cpuPercent: number };
102
+ total: { processes: number; memory: number; cpuPercent: number };
103
+ /**
104
+ * Which figure `memory` is across the sample.
105
+ *
106
+ * `footprint` when every row reported one, `rss` when none did, `mixed` when
107
+ * both appear — the panel needs to say which, because a sum of two different
108
+ * quantities must not be labelled as one of them.
109
+ */
110
+ memorySource: 'footprint' | 'rss' | 'mixed';
88
111
  machine: MachineContext;
89
112
  /** omp daemons the registry reports, so a row can be named by its daemon. */
90
113
  daemons: DaemonEntry[];
91
114
  /** The Kabmo's own pid, so the panel can mark it. */
92
115
  serverPid: number;
93
116
  /** Sparkline series, oldest first. Absent when history is disabled. */
94
- history?: { rss: number[]; cpuPercent: number[] };
117
+ history?: { memory: number[]; cpuPercent: number[] };
95
118
  /** Why the table is empty, when it is. */
96
119
  error?: string;
97
120
  }
@@ -110,6 +133,11 @@ export interface SampleDeps {
110
133
  includeDaemons?: boolean;
111
134
  /** Samples retained for the sparklines; 0 disables history. */
112
135
  historyPoints?: number;
136
+ /**
137
+ * The machine reading, injected so a unit test does not spawn `vm_stat`.
138
+ * Defaults to `readMachine` from `./machine`.
139
+ */
140
+ readMachine?: () => MachineContext;
113
141
  /**
114
142
  * The lease lookup, injected so the sampler is testable without libproc.
115
143
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabmo-labs/kabmo",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Web console and diagnostic workbench for AI coding agents — Elysia + Preact on Bun.",
5
5
  "license": "MIT",
6
6
  "author": "Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",
@@ -61,6 +61,7 @@
61
61
  "shell:docs": "bun run scripts/shell-document-types.mjs --write",
62
62
  "shell:docs:check": "bun run scripts/shell-document-types.mjs --check",
63
63
  "typecheck:e2e": "tsc --noEmit -p tests/e2e",
64
+ "typecheck:consumer": "tsc --noEmit -p tsconfig.consumer.json",
64
65
  "publish:plugins": "bash .github/scripts/publish-plugin-packages.sh packages/kabmo-sdk packages/kabmo-ui"
65
66
  },
66
67
  "dependencies": {
@@ -74,7 +75,7 @@
74
75
  "@codemirror/state": "6.7.6",
75
76
  "@codemirror/view": "6.43.15",
76
77
  "@fontsource/fira-code": "^5.3.0",
77
- "@kabmo-labs/kabmo-sdk": "0.1.2",
78
+ "@kabmo-labs/kabmo-sdk": "0.1.3",
78
79
  "@kabmo-labs/kabmo-ui": "0.0.2",
79
80
  "@shikijs/langs": "^4.4.3",
80
81
  "@shikijs/themes": "^4.4.3",
@@ -19,6 +19,11 @@ export interface ModalProps {
19
19
  maxWidthClass?: string;
20
20
  /** Backdrop z-index class. Default `z-[60]`. */
21
21
  zClass?: string;
22
+ /**
23
+ * Accessible name for the dialog. The header is ordinary content, so without
24
+ * this the `role="dialog"` announces itself anonymously to a screen reader.
25
+ */
26
+ ariaLabel?: string;
22
27
  }
23
28
 
24
29
  /**
@@ -34,6 +39,7 @@ export function Modal({
34
39
  form,
35
40
  maxWidthClass = 'max-w-md',
36
41
  zClass = 'z-[60]',
42
+ ariaLabel,
37
43
  }: ModalProps) {
38
44
  const body = (
39
45
  <>
@@ -62,6 +68,7 @@ export function Modal({
62
68
  <div
63
69
  role="dialog"
64
70
  aria-modal="true"
71
+ aria-label={ariaLabel}
65
72
  className={`bg-paper border border-ink/15 rounded-xl shadow-2xl w-full ${maxWidthClass} max-h-full flex flex-col overflow-hidden text-ink`}
66
73
  onClick={(e) => e.stopPropagation()}
67
74
  >
@@ -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 (
@@ -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 (
@@ -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
  }
@@ -93,9 +93,14 @@ export function ModelDropdownPanel({
93
93
  onAddProvider={onAddProvider}
94
94
  />
95
95
 
96
- {/* Scrollable Model Lists */}
96
+ {/* Scrollable Model Lists. Deliberately no top padding: Chrome's
97
+ sticky view rectangle is the scrollport's CONTENT box, so a
98
+ `sticky top-0` heading inside a padded list pins below the padding
99
+ and leaves that strip showing rows sliding above it (measured: a
100
+ `p-1.5` list pinned its heading 6px down and `elementFromPoint` at
101
+ 2px returned a row). The first heading sits flush instead. */}
97
102
  <div
98
- className="flex-1 scrollbar-overlay-container p-1.5 space-y-2 max-h-80"
103
+ className="flex-1 scrollbar-overlay-container px-1.5 pb-1.5 space-y-2 max-h-80"
99
104
  onMouseLeave={onMouseLeave}
100
105
  // The row under a resting pointer moves when the list scrolls; the
101
106
  // card follows it instead of staying where the hover started.
@@ -123,6 +123,19 @@ describe('model picker section header columns', () => {
123
123
  expect(chevronSlot.querySelector('svg')).not.toBeNull();
124
124
  });
125
125
 
126
+ test('the header pins to the top of the scrolling list', () => {
127
+ mountSection();
128
+
129
+ // The list is capped (`max-h-80`), so a provider heading that scrolled
130
+ // away left its rows unnamed. `sticky top-0` keeps it in view; the opaque
131
+ // paper background is what hides the rows passing underneath, and z-10
132
+ // keeps the heading above them.
133
+ expect(header().className).toContain('sticky');
134
+ expect(header().className).toContain('top-0');
135
+ expect(header().className).toContain('bg-paper');
136
+ expect(header().className).toContain('z-10');
137
+ });
138
+
126
139
  test('a row carries its row id, which the specs card anchors to', () => {
127
140
  mountSection();
128
141
 
@@ -56,7 +56,11 @@ export function ModelDropdownSection({
56
56
  <button
57
57
  type="button"
58
58
  onClick={() => onToggleCollapse(id)}
59
- className="w-full flex items-center justify-between gap-2 pl-1 pr-2 py-1 text-[11px] font-semibold text-ink/60 uppercase tracking-wider hover:text-ink cursor-pointer select-none"
59
+ // Sticky: the list is capped at `max-h-80`, and a section heading that
60
+ // scrolled away left the rows below it with no provider to name them.
61
+ // The opaque paper background is what hides those rows as they pass
62
+ // under the pinned heading; `z-10` keeps the heading above the rows.
63
+ className="sticky top-0 z-10 w-full flex items-center justify-between gap-2 pl-1 pr-2 py-1 text-[11px] font-semibold text-ink/60 uppercase tracking-wider hover:text-ink cursor-pointer select-none bg-paper"
60
64
  >
61
65
  <div className="flex items-center gap-2 min-w-0">
62
66
  {iconType === 'star' && (
@@ -52,6 +52,13 @@ export interface PanelBodyProps {
52
52
  onClose?: () => void;
53
53
  /** The phone's drawer hides a view's own header; the desktop stack does not. */
54
54
  showHeader?: boolean;
55
+ /**
56
+ * Which shell is drawing this body. A view with its own small-screen form
57
+ * (the wiki's floating page-list button) must know the PHONE from a merely
58
+ * narrow desktop column; no container or media query can tell the two apart.
59
+ * Omitted means desktop.
60
+ */
61
+ layout?: 'desktop' | 'phone';
55
62
  /**
56
63
  * The boot settings snapshot, for the views that read it (the session list
57
64
  * passes it to its own Settings modal and to the prewarm's access mode).
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The narrow wiki nav: an outlined floating trigger opens the page list as a
8
+ * modal, and reaching a page closes it.
9
+ *
10
+ * Three properties are pinned because each is invisible to a markup screenshot:
11
+ * the trigger reports its open state (`aria-expanded`), Escape closes the modal
12
+ * the reader opened (no other UI unmounts it), and a page click closes it too —
13
+ * a modal left covering the page the reader just chose is the bug this pair
14
+ * exists to avoid.
15
+ */
16
+
17
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
18
+ import { Window } from 'happy-dom';
19
+ import { render, type ComponentChild } from 'preact';
20
+ import { act } from 'preact/test-utils';
21
+ import { WikiNavModal, WikiNavTrigger } from '@/client/components/workspace/wiki-panel/NavModal';
22
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
23
+ import type { WikiNavSection } from '@/shared/types/wiki';
24
+
25
+ const SECTIONS: WikiNavSection[] = [
26
+ {
27
+ title: 'Navigation',
28
+ links: [
29
+ { label: 'Home', target: 'Home', path: 'Home.md', url: null },
30
+ { label: 'Deploying', target: 'Deploying', path: 'Deploying.md', url: null },
31
+ ],
32
+ notes: ['**Version**: 1.6.0'],
33
+ },
34
+ ];
35
+
36
+ let container: HTMLElement | null = null;
37
+
38
+ function mount(node: ComponentChild): HTMLElement {
39
+ container = document.createElement('div');
40
+ document.body.appendChild(container);
41
+ act(() => render(node, container as HTMLElement));
42
+ return container;
43
+ }
44
+
45
+ beforeAll(() => {
46
+ installDomGlobals(new Window({ url: 'http://localhost' }));
47
+ });
48
+
49
+ afterEach(() => {
50
+ if (container) {
51
+ render(null, container);
52
+ container.remove();
53
+ container = null;
54
+ }
55
+ });
56
+
57
+ afterAll(() => {
58
+ restoreDomGlobals();
59
+ });
60
+
61
+ describe('WikiNavTrigger', () => {
62
+ test('is an outlined button that reports the state it opens', () => {
63
+ let clicks = 0;
64
+ const root = mount(<WikiNavTrigger open={false} onClick={() => { clicks += 1; }} />);
65
+ const button = root.querySelector('button');
66
+
67
+ expect(button).not.toBeNull();
68
+ expect(button?.getAttribute('aria-expanded')).toBe('false');
69
+ // Outline, not fill: the trigger floats over the document it belongs to.
70
+ expect(button?.getAttribute('class')).toContain('border');
71
+
72
+ act(() => button?.click());
73
+ expect(clicks).toBe(1);
74
+ });
75
+
76
+ test('reports the modal as expanded while it is open', () => {
77
+ const root = mount(<WikiNavTrigger open onClick={() => {}} />);
78
+ expect(root.querySelector('button')?.getAttribute('aria-expanded')).toBe('true');
79
+ });
80
+ });
81
+
82
+ describe('WikiNavModal', () => {
83
+ test('renders nothing while closed', () => {
84
+ const root = mount(
85
+ <WikiNavModal open={false} sections={SECTIONS} selected={null} onSelect={() => {}} onClose={() => {}} />,
86
+ );
87
+ expect(root.querySelector('[role="dialog"]')).toBeNull();
88
+ });
89
+
90
+ test('shows the wiki sections and closes when a page is chosen', () => {
91
+ const selected: string[] = [];
92
+ let closed = 0;
93
+ const root = mount(
94
+ <WikiNavModal
95
+ open
96
+ sections={SECTIONS}
97
+ selected="Home.md"
98
+ onSelect={(path) => selected.push(path)}
99
+ onClose={() => { closed += 1; }}
100
+ />,
101
+ );
102
+
103
+ const dialog = root.querySelector('[role="dialog"]');
104
+ expect(dialog).not.toBeNull();
105
+ expect(dialog?.getAttribute('aria-label')).toBe('Wiki pages');
106
+ expect(dialog?.textContent).toContain('Navigation');
107
+ expect(dialog?.textContent).toContain('1.6.0');
108
+
109
+ const page = Array.from(dialog?.querySelectorAll<HTMLButtonElement>('button') ?? []).find(
110
+ (button) => button.textContent === 'Deploying',
111
+ );
112
+ expect(page).not.toBeNull();
113
+ act(() => page?.click());
114
+
115
+ expect(selected).toEqual(['Deploying.md']);
116
+ expect(closed).toBe(1);
117
+ });
118
+
119
+ test('Escape closes the modal', () => {
120
+ let closed = 0;
121
+ mount(
122
+ <WikiNavModal
123
+ open
124
+ sections={SECTIONS}
125
+ selected={null}
126
+ onSelect={() => {}}
127
+ onClose={() => { closed += 1; }}
128
+ />,
129
+ );
130
+
131
+ act(() => {
132
+ document.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape' }));
133
+ });
134
+ expect(closed).toBe(1);
135
+ });
136
+ });