@kabmo-labs/kabmo 0.13.0 → 0.14.1

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 (148) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +319 -319
  3. package/dist/client/static/js/index-bnrrw242.css +1 -0
  4. package/dist/client/static/js/{index-vzb1qz51.js → index-w6jx0h0p.js} +780 -780
  5. package/marketplace/plugins/command-runner/package.json +2 -2
  6. package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
  7. package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
  8. package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
  9. package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
  10. package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
  11. package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
  12. package/package.json +2 -2
  13. package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
  14. package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
  15. package/src/client/components/common/code-surface/extensions.ts +7 -1
  16. package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
  17. package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
  18. package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
  19. package/src/client/components/common/session-row/index.tsx +215 -0
  20. package/src/client/components/common/session-row/session-row.test.tsx +154 -0
  21. package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
  22. package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
  23. package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
  24. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
  25. package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
  26. package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
  27. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +56 -0
  28. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +193 -0
  29. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
  30. package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
  31. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
  32. package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
  33. package/src/client/components/mobile/SessionSidebar.tsx +137 -146
  34. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
  35. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
  36. package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
  37. package/src/client/components/settings/Modal.tsx +5 -27
  38. package/src/client/components/settings/Sidebar.tsx +1 -1
  39. package/src/client/components/settings/apply-side-effects.test.ts +102 -0
  40. package/src/client/components/settings/apply-side-effects.ts +90 -0
  41. package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
  42. package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
  43. package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
  44. package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
  45. package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
  46. package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
  47. package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
  48. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
  49. package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
  50. package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
  51. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
  52. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
  53. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +15 -5
  55. package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
  56. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
  57. package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
  58. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +117 -75
  59. package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
  60. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
  61. package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
  62. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +178 -0
  63. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
  64. package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
  65. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
  66. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
  67. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
  68. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
  69. package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
  70. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
  71. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
  73. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
  82. package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
  87. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
  88. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
  89. package/src/client/components/workspace/diff-panel/folding.ts +6 -1
  90. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
  91. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
  92. package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
  93. package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
  94. package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
  95. package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
  96. package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
  97. package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
  98. package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
  99. package/src/client/data/settings/omp-schema.json +151 -6
  100. package/src/client/hooks/chat/composer/style.ts +66 -0
  101. package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
  102. package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
  103. package/src/client/hooks/chat/timeline/row-window.ts +59 -133
  104. package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
  105. package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
  106. package/src/client/hooks/settings/providers/login.ts +11 -2
  107. package/src/client/hooks/ui/window-event.ts +20 -4
  108. package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
  109. package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
  110. package/src/client/hooks/workspace/batch-archive.ts +78 -0
  111. package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
  112. package/src/client/hooks/workspace/sidebar-style.ts +66 -0
  113. package/src/client/tailwind.css +111 -0
  114. package/src/server/index.ts +10 -134
  115. package/src/server/lib/lifecycle/after-listen.ts +178 -0
  116. package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
  117. package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
  118. package/src/server/lib/lifecycle/tls.test.ts +7 -7
  119. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
  120. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
  121. package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
  122. package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
  123. package/src/server/lib/plugins/background.server.ts +17 -1
  124. package/src/server/lib/plugins/background.test.ts +33 -0
  125. package/src/server/routes/sessions/batch-archive.test.ts +113 -0
  126. package/src/server/routes/sessions/batch-archive.ts +80 -0
  127. package/src/server/routes/sessions/index.ts +4 -0
  128. package/src/shared/lib/chat/composer/style.test.ts +126 -0
  129. package/src/shared/lib/chat/composer/style.ts +171 -0
  130. package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
  131. package/src/shared/lib/chat/composer/tui-only.ts +5 -0
  132. package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
  133. package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
  134. package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
  135. package/src/shared/lib/chat/timeline/trace-groups.test.ts +132 -0
  136. package/src/shared/lib/chat/timeline/trace-groups.ts +95 -0
  137. package/src/shared/lib/settings/defaults.ts +6 -0
  138. package/src/shared/lib/workspace/session-focus.test.ts +93 -0
  139. package/src/shared/lib/workspace/session-focus.ts +71 -0
  140. package/src/shared/lib/workspace/session-state/store.ts +5 -0
  141. package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
  142. package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
  143. package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
  144. package/src/shared/lib/workspace/sidebar-style.ts +86 -0
  145. package/src/shared/types/omp/agent.ts +6 -0
  146. package/src/shared/types/settings/state.ts +31 -0
  147. package/dist/client/static/js/index-68w8h33q.css +0 -1
  148. package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "command-runner",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": true,
5
5
  "description": "Lists a repository's commands and runs them, in the foreground or as background jobs.",
6
6
  "type": "module",
7
7
  "kabmo": {
8
8
  "id": "command-runner",
9
9
  "name": "Runner",
10
- "version": "0.1.1",
10
+ "version": "0.1.2",
11
11
  "description": "Lists a repository's commands and runs them, in the foreground or as background jobs.",
12
12
  "app": "dist/app.js",
13
13
  "server": "dist/server.js",
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The pure half of the log buffer: the ring's tail read, and the ANSI strip a
8
+ * log is rendered through.
9
+ *
10
+ * Split from `runner.test.ts` when that file carried a third subject and crossed
11
+ * the ceiling. These cases need no process, so they are also the fast ones.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+
16
+ import { ringText, stripAnsi } from './ring';
17
+
18
+ describe('ringText', () => {
19
+ test('returns the last N bytes of the ring', () => {
20
+ expect(ringText({ chunks: [Buffer.from('abcdefghij')], held: 10 }, 4)).toBe('ghij');
21
+ });
22
+
23
+ test('returns everything when the tail is larger than the buffer', () => {
24
+ expect(ringText({ chunks: [Buffer.from('abc')], held: 3 }, 1024)).toBe('abc');
25
+ });
26
+ });
27
+
28
+ describe('stripAnsi', () => {
29
+ test('removes colour and cursor sequences', () => {
30
+ // What a coloured build actually emits, including a 256-colour code.
31
+ expect(stripAnsi('\u001b[0m\u001b[2;38;5;11m$\u001b[0m make build')).toBe('$ make build');
32
+ });
33
+
34
+ test('removes an OSC sequence terminated by BEL', () => {
35
+ expect(stripAnsi('\u001b]0;title\u0007plain')).toBe('plain');
36
+ });
37
+
38
+ test('leaves ordinary text alone', () => {
39
+ expect(stripAnsi('12 pass · 0 fail')).toBe('12 pass · 0 fail');
40
+ });
41
+ });
@@ -54,4 +54,10 @@ export interface RunnerDeps {
54
54
  log(message: string, detail?: unknown): void;
55
55
  /** Read a plugin setting. */
56
56
  setting<T extends string | number | boolean>(key: string): Promise<T | undefined>;
57
+ /**
58
+ * The environment a run starts from — Kabmo's own, because this plugin's
59
+ * server half runs inside the host's process. A test hands in a minimal one
60
+ * to exercise the PATH repair without touching the runner's real environ.
61
+ */
62
+ env?: Record<string, string | undefined>;
57
63
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The harness the registry's suites share: a registry whose host calls are
8
+ * recorded instead of sent, and a way to wait for a REAL process to reach a
9
+ * state.
10
+ *
11
+ * Extracted when `runner.test.ts` crossed the file ceiling with a second subject
12
+ * (executable resolution) beside the first (the run lifecycle). Both suites drive
13
+ * the same class against real processes, so the alternative — two copies of
14
+ * `makeRegistry` and `waitFor` — would let the two drift and would hide which
15
+ * one a failing assertion came from.
16
+ */
17
+
18
+ import { expect } from 'bun:test';
19
+
20
+ import { RunRegistry } from './runner';
21
+ import { scopeKeyOf } from './run-store';
22
+ import type { RunnerState } from '../protocol';
23
+
24
+ /** The scope every test run is recorded against. */
25
+ export const SCOPE = scopeKeyOf('/ws', '.');
26
+
27
+ /** A registry whose publish/log/setting calls are recorded instead of sent. */
28
+ export function makeRegistry(
29
+ settings: Record<string, unknown> = {},
30
+ env?: Record<string, string | undefined>,
31
+ ) {
32
+ const published: RunnerState[] = [];
33
+ const logs: string[] = [];
34
+ const registry = new RunRegistry({
35
+ publish: (state) => published.push(state),
36
+ log: (message) => logs.push(message),
37
+ setting: async <T extends string | number | boolean>(key: string) => settings[key] as T | undefined,
38
+ ...(env ? { env } : {}),
39
+ });
40
+ return { registry, published, logs };
41
+ }
42
+
43
+ /**
44
+ * Wait for a condition, so a test never sleeps for a FIXED time.
45
+ *
46
+ * The clock is real here on purpose, and this is the documented exception:
47
+ * every condition below is "an actual OS process reached a state" — a `sleep 30`
48
+ * child that the group kill reaped, a pipe that drained. Fake timers cannot
49
+ * advance a real process, and awaiting the registry's own promise is not
50
+ * possible because it deliberately keeps no per-run promise (a panel reads state,
51
+ * it does not await a run). The poll interval is 10 ms and the bound is generous,
52
+ * so a pass costs milliseconds and a failure names the condition.
53
+ */
54
+ export async function waitFor(done: () => boolean, timeoutMs = 10_000): Promise<void> {
55
+ const deadline = Date.now() + timeoutMs;
56
+ for (;;) {
57
+ if (done()) return;
58
+ if (Date.now() >= deadline) throw new Error('waitFor timed out');
59
+ const gate = Promise.withResolvers<void>();
60
+ setTimeout(gate.resolve, 10);
61
+ await gate.promise;
62
+ }
63
+ }
64
+
65
+ /** The run a registry holds, by its only id. */
66
+ export function onlyRun(state: RunnerState) {
67
+ expect(state.runs).toHaveLength(1);
68
+ return state.runs[0];
69
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Where a run's executable comes from, when the host itself was started with
8
+ * almost no PATH.
9
+ *
10
+ * This is the reported failure: a Kabmo started by launchd (the desktop app, a
11
+ * LaunchAgent, `--launch-mode=daemon`) inherits
12
+ * `/usr/bin:/bin:/usr/sbin:/sbin`, so `Bun.spawn` answered
13
+ * `Executable not found in $PATH: "bun"` for every row in the Command Runner
14
+ * panel — while the same command in the user's terminal ran, because a terminal
15
+ * launches a LOGIN shell that re-reads the profile and a plugin's `Bun.spawn`
16
+ * has no profile to read.
17
+ *
18
+ * The run is driven against a REAL process for the same reason the lifecycle
19
+ * suite is: the property under test is "the OS found and started this binary",
20
+ * which no fake spawn can show.
21
+ */
22
+
23
+ import { describe, expect, test } from 'bun:test';
24
+ import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
25
+ import { tmpdir } from 'node:os';
26
+ import { join } from 'node:path';
27
+
28
+ import { onlyRun, makeRegistry, waitFor, SCOPE } from './runner-harness';
29
+
30
+ /**
31
+ * Both cases are POSIX-only, for the two reasons `src/test-support/platform.ts`
32
+ * names — a plugin cannot import it, so the guard is the same one
33
+ * `runner.test.ts` uses beside it:
34
+ *
35
+ * - the probe is a `#!/bin/sh` stub whose only "executability" is mode `0o755`,
36
+ * and `CreateProcess` cannot start that file;
37
+ * - the repair under test is itself a no-op on Windows (`toolchainPathDirs`
38
+ * returns nothing there), so there is no PATH to assert about.
39
+ *
40
+ * A skip is named in the log rather than weakened into an assertion that passes
41
+ * on both platforms while proving nothing.
42
+ */
43
+ const testPosix = process.platform === 'win32' ? test.skip : test;
44
+
45
+ describe('RunRegistry executable resolution', () => {
46
+ testPosix('a command resolves when the host PATH has no toolchain directories', async () => {
47
+ // The probe binary exists ONLY under `$HOME/.bun/bin`, which the inherited
48
+ // PATH does not name, so a resolved run proves the repair appended it.
49
+ const home = mkdtempSync(join(tmpdir(), 'cr-path-'));
50
+ const bin = join(home, '.bun', 'bin');
51
+ mkdirSync(bin, { recursive: true });
52
+ const tool = join(bin, 'cr-probe-tool');
53
+ writeFileSync(tool, '#!/bin/sh\necho probe-ok\n');
54
+ chmodSync(tool, 0o755);
55
+ const env = { PATH: '/usr/bin:/bin', HOME: home };
56
+
57
+ try {
58
+ const { registry } = makeRegistry({}, env);
59
+ const started = await registry.start({
60
+ id: 'path',
61
+ sessionId: null,
62
+ scopeKey: SCOPE,
63
+ commandId: 'x#package:probe',
64
+ file: 'package.json',
65
+ cwd: home,
66
+ argv: ['cr-probe-tool'],
67
+ label: 'cr-probe-tool',
68
+ background: false,
69
+ });
70
+ expect(started).toEqual({ runId: 'path' });
71
+ await waitFor(() => onlyRun(registry.state()).status !== 'running');
72
+ expect(onlyRun(registry.state()).status).toBe('exited');
73
+ expect(registry.log('path', 4096)!.text).toContain('probe-ok');
74
+
75
+ // The repair has to reach the CHILD too, not just the spawn: `bun run dev`
76
+ // resolves `vite` from the PATH its own process was given.
77
+ const { registry: shell } = makeRegistry({}, env);
78
+ await shell.start({
79
+ id: 'path-child',
80
+ sessionId: null,
81
+ scopeKey: SCOPE,
82
+ commandId: 'x#package:path',
83
+ file: 'package.json',
84
+ cwd: home,
85
+ argv: ['sh', '-c', 'echo "CHILD_PATH=$PATH"'],
86
+ label: 'path probe',
87
+ background: false,
88
+ });
89
+ await waitFor(() => onlyRun(shell.state()).status !== 'running');
90
+ const childPath = /CHILD_PATH=(.*)/.exec(shell.log('path-child', 4096)!.text)?.[1] ?? '';
91
+ const segments = childPath.trim().split(':');
92
+ expect(segments).toContain(bin);
93
+ // The inherited entries keep their precedence.
94
+ expect(segments.slice(0, 2)).toEqual(['/usr/bin', '/bin']);
95
+ } finally {
96
+ rmSync(home, { recursive: true, force: true });
97
+ }
98
+ }, 20_000);
99
+
100
+ testPosix('a name that is already a path is left alone', async () => {
101
+ // A detector may write `./scripts/build.sh`; resolving that against PATH
102
+ // would run a different file than the one the command names.
103
+ const dir = mkdtempSync(join(tmpdir(), 'cr-path-rel-'));
104
+ const script = join(dir, 'run-me.sh');
105
+ writeFileSync(script, '#!/bin/sh\necho relative-ok\n');
106
+ chmodSync(script, 0o755);
107
+ try {
108
+ const { registry } = makeRegistry({}, { PATH: '/usr/bin:/bin', HOME: dir });
109
+ await registry.start({
110
+ id: 'relative',
111
+ sessionId: null,
112
+ scopeKey: SCOPE,
113
+ commandId: 'x#make:relative',
114
+ file: 'Makefile',
115
+ cwd: dir,
116
+ argv: ['./run-me.sh'],
117
+ label: './run-me.sh',
118
+ background: false,
119
+ });
120
+ await waitFor(() => onlyRun(registry.state()).status !== 'running');
121
+ expect(onlyRun(registry.state()).status).toBe('exited');
122
+ expect(registry.log('relative', 4096)!.text).toContain('relative-ok');
123
+ } finally {
124
+ rmSync(dir, { recursive: true, force: true });
125
+ }
126
+ }, 20_000);
127
+ });
@@ -28,52 +28,8 @@
28
28
 
29
29
  import { describe, expect, test } from 'bun:test';
30
30
 
31
- import { RunRegistry } from './runner';
32
- import { scopeKeyOf } from './run-store';
33
- import { RUN_BUFFER_BYTES, ringText, stripAnsi } from './ring';
34
- import type { RunnerState } from '../protocol';
35
-
36
- /** A registry whose publish/log/setting calls are recorded instead of sent. */
37
- function makeRegistry(settings: Record<string, unknown> = {}) {
38
- const published: RunnerState[] = [];
39
- const logs: string[] = [];
40
- const registry = new RunRegistry({
41
- publish: (state) => published.push(state),
42
- log: (message) => logs.push(message),
43
- setting: async <T extends string | number | boolean>(key: string) => settings[key] as T | undefined,
44
- });
45
- return { registry, published, logs };
46
- }
47
-
48
- /**
49
- * Wait for a condition, so a test never sleeps for a FIXED time.
50
- *
51
- * The clock is real here on purpose, and this is the documented exception:
52
- * every condition below is "an actual OS process reached a state" — a `sleep 30`
53
- * child that the group kill reaped, a pipe that drained. Fake timers cannot
54
- * advance a real process, and awaiting the registry's own promise is not
55
- * possible because it deliberately keeps no per-run promise (a panel reads state,
56
- * it does not await a run). The poll interval is 10 ms and the bound is generous,
57
- * so a pass costs milliseconds and a failure names the condition.
58
- */
59
- async function waitFor(done: () => boolean, timeoutMs = 10_000): Promise<void> {
60
- const deadline = Date.now() + timeoutMs;
61
- for (;;) {
62
- if (done()) return;
63
- if (Date.now() >= deadline) throw new Error('waitFor timed out');
64
- const gate = Promise.withResolvers<void>();
65
- setTimeout(gate.resolve, 10);
66
- await gate.promise;
67
- }
68
- }
69
-
70
- const SCOPE = scopeKeyOf('/ws', '.');
71
-
72
- /** The run a registry holds, by its only id. */
73
- function onlyRun(state: RunnerState) {
74
- expect(state.runs).toHaveLength(1);
75
- return state.runs[0];
76
- }
31
+ import { RUN_BUFFER_BYTES } from './ring';
32
+ import { makeRegistry, onlyRun, SCOPE, waitFor } from './runner-harness';
77
33
 
78
34
  describe('RunRegistry', () => {
79
35
  test('runs a command and records its output and exit code', async () => {
@@ -307,29 +263,3 @@ describe('RunRegistry', () => {
307
263
  expect(registry.log('nope', 1024)).toBeNull();
308
264
  });
309
265
  });
310
-
311
- describe('ringText', () => {
312
- test('returns the last N bytes of the ring', () => {
313
- expect(ringText({ chunks: [Buffer.from('abcdefghij')], held: 10 }, 4)).toBe('ghij');
314
- });
315
-
316
- test('returns everything when the tail is larger than the buffer', () => {
317
- expect(ringText({ chunks: [Buffer.from('abc')], held: 3 }, 1024)).toBe('abc');
318
- });
319
- });
320
-
321
- describe('stripAnsi', () => {
322
- test('removes colour and cursor sequences', () => {
323
- // What a coloured build actually emits, including a 256-colour code.
324
- expect(stripAnsi('\u001b[0m\u001b[2;38;5;11m$\u001b[0m make build')).toBe('$ make build');
325
- });
326
-
327
- test('removes an OSC sequence terminated by BEL', () => {
328
- expect(stripAnsi('\u001b]0;title\u0007plain')).toBe('plain');
329
- });
330
-
331
- test('leaves ordinary text alone', () => {
332
- expect(stripAnsi('12 pass · 0 fail')).toBe('12 pass · 0 fail');
333
- });
334
- });
335
-
@@ -12,7 +12,7 @@
12
12
  * ONE run and needs the process, while everything there happens to the SET.
13
13
  */
14
14
 
15
- import { signalName, stripKabmoHostEnv } from '@kabmo-labs/kabmo-sdk';
15
+ import { signalName, stripKabmoHostEnv, withToolchainPath } from '@kabmo-labs/kabmo-sdk';
16
16
 
17
17
  import type { Run } from './run-types';
18
18
  import { appendToRing, emptyRing } from './ring';
@@ -21,6 +21,23 @@ import { RunStore } from './run-store';
21
21
  /** How often a growing buffer is announced on the topic, per run. */
22
22
  const OUTPUT_PUBLISH_MS = 250;
23
23
 
24
+ /**
25
+ * The absolute path of a bare executable, or the name unchanged.
26
+ *
27
+ * `Bun.spawn` resolves a bare name against the `PATH` of the env it is handed —
28
+ * measured on 1.4.4, and that is why the repaired PATH alone would be enough.
29
+ * An absolute path removes the dependency on that detail anyway, and it is what
30
+ * turns "the file is there but the spawn searched elsewhere" into an ordinary
31
+ * `Executable not found` only when the binary really is absent.
32
+ *
33
+ * A name that already carries a separator is a path the detector wrote, so it is
34
+ * left alone: rewriting it would resolve it against the wrong directory.
35
+ */
36
+ function resolveExecutable(name: string, path: string | undefined): string {
37
+ if (!name || !path || name.includes('/') || name.includes('\\')) return name;
38
+ return Bun.which(name, { PATH: path }) ?? name;
39
+ }
40
+
24
41
  /** The registry the server half holds: one instance per plugin load. */
25
42
  export class RunRegistry extends RunStore {
26
43
  /**
@@ -73,8 +90,19 @@ export class RunRegistry extends RunStore {
73
90
 
74
91
  let proc: Bun.Subprocess;
75
92
  try {
93
+ // The environment the child gets, in two steps that answer two different
94
+ // problems: the host's own variables are REMOVED (see below), and the
95
+ // toolchain directories a GUI/launchd launch never had are ADDED. Without
96
+ // the second, every command this panel offers fails at `Bun.spawn` with
97
+ // `Executable not found in $PATH: "bun"` — measured under a daemon started
98
+ // by launchd, whose PATH is `/usr/bin:/bin:/usr/sbin:/sbin`, while the
99
+ // same command in the user's terminal ran fine.
100
+ const env = withToolchainPath(
101
+ stripKabmoHostEnv(this.deps.env ?? Bun.env, process.platform),
102
+ process.platform,
103
+ );
76
104
  proc = Bun.spawn({
77
- cmd: input.argv,
105
+ cmd: [resolveExecutable(input.argv[0], env.PATH), ...input.argv.slice(1)],
78
106
  cwd: input.cwd,
79
107
  stdout: 'pipe',
80
108
  stderr: 'pipe',
@@ -89,7 +117,7 @@ export class RunRegistry extends RunStore {
89
117
  // served by Kabmo" while the same command in a plain terminal (where
90
118
  // `PORT` is unset) ran on 3000. The rule is the SDK's, shared with the
91
119
  // host's own child spawns so the two cannot drift.
92
- env: stripKabmoHostEnv(Bun.env, process.platform),
120
+ env,
93
121
  });
94
122
  } catch (error) {
95
123
  // A missing binary THROWS here (measured), so this is the only path that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabmo-labs/kabmo",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
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>",
@@ -74,7 +74,7 @@
74
74
  "@codemirror/state": "6.7.6",
75
75
  "@codemirror/view": "6.43.15",
76
76
  "@fontsource/fira-code": "^5.3.0",
77
- "@kabmo-labs/kabmo-sdk": "0.1.1",
77
+ "@kabmo-labs/kabmo-sdk": "0.1.2",
78
78
  "@kabmo-labs/kabmo-ui": "0.0.2",
79
79
  "@shikijs/langs": "^4.4.3",
80
80
  "@shikijs/themes": "^4.4.3",
@@ -6,11 +6,13 @@
6
6
  /**
7
7
  * The batch bar's contract, rendered.
8
8
  *
9
- * Three properties are load-bearing and each is a way a batch delete can go
9
+ * The properties here are load-bearing and each is a way a batch action can go
10
10
  * wrong: the bar names the mode's noun (a session batch that says "workspace"
11
- * deletes the wrong thing), Delete is refused with nothing selected, and
12
- * Select-all is refused once everything already is — a control that looks
13
- * available but does nothing is how a user concludes the feature is broken.
11
+ * deletes the wrong thing), Delete and Archive are refused with nothing
12
+ * selected, Select-all is refused once everything already is, and Archive never
13
+ * appears in workspace mode — a workspace has no archive state. A control that
14
+ * looks available but does nothing is how a user concludes the feature is
15
+ * broken.
14
16
  */
15
17
 
16
18
  import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
@@ -48,7 +50,7 @@ afterEach(() => {
48
50
  });
49
51
 
50
52
  async function mount(overrides: Partial<BatchActionBarProps> = {}) {
51
- const calls = { selectAll: 0, unselectAll: 0, del: 0, cancel: 0 };
53
+ const calls = { selectAll: 0, unselectAll: 0, del: 0, arch: 0, cancel: 0 };
52
54
  container = document.createElement('div');
53
55
  document.body.appendChild(container);
54
56
  await act(async () => {
@@ -60,6 +62,7 @@ async function mount(overrides: Partial<BatchActionBarProps> = {}) {
60
62
  onSelectAll: () => { calls.selectAll += 1; },
61
63
  onUnselectAll: () => { calls.unselectAll += 1; },
62
64
  onDelete: () => { calls.del += 1; },
65
+ onArchive: () => { calls.arch += 1; },
63
66
  onCancel: () => { calls.cancel += 1; },
64
67
  ...overrides,
65
68
  }), container);
@@ -129,4 +132,38 @@ describe('BatchActionBar', () => {
129
132
  expect((button as HTMLButtonElement).disabled).toBe(true);
130
133
  }
131
134
  });
135
+
136
+ test('Archive is drawn in session mode and names the session noun', async () => {
137
+ const { el, calls } = await mount({ count: 2, total: 5 });
138
+ const archive = buttonContaining(el, 'Archive');
139
+ expect(archive).not.toBeNull();
140
+ expect(archive?.textContent).toContain('2 sessions');
141
+ expect(archive?.disabled).toBe(false);
142
+ await act(async () => { archive?.click(); });
143
+ expect(calls.arch).toBe(1);
144
+ });
145
+
146
+ test('Archive is refused with nothing selected', async () => {
147
+ const { el, calls } = await mount({ count: 0 });
148
+ const archive = buttonContaining(el, 'Archive');
149
+ expect(archive?.disabled).toBe(true);
150
+ await act(async () => { archive?.click(); });
151
+ expect(calls.arch).toBe(0);
152
+ });
153
+
154
+ test('Archive is never drawn in workspace mode — a workspace has no archive state', async () => {
155
+ const { el } = await mount({ mode: 'workspace', count: 2, total: 4 });
156
+ expect(buttonContaining(el, 'Archive')).toBeNull();
157
+ expect(buttonContaining(el, 'Delete')).not.toBeNull();
158
+ });
159
+
160
+ test('a running archive says so on its own control, not on Delete', async () => {
161
+ const { el } = await mount({ count: 2, archiving: true });
162
+ expect(el.textContent).toContain('Archiving…');
163
+ expect(el.textContent).not.toContain('Deleting…');
164
+ // Every control is locked while the request is unresolved.
165
+ for (const button of Array.from(el.querySelectorAll('button'))) {
166
+ expect((button as HTMLButtonElement).disabled).toBe(true);
167
+ }
168
+ });
132
169
  });
@@ -5,20 +5,27 @@
5
5
 
6
6
  /**
7
7
  * The bar a batch selection raises: what is selected, select-all / unselect-all,
8
- * Delete and Cancel.
8
+ * Archive (session mode only), Delete and Cancel.
9
9
  *
10
10
  * It sits at the bottom of the sidebar (desktop) or above the list (phone) and
11
- * is the ONLY place a delete can be started — the checkboxes themselves never
12
- * act, so a mis-tap on a row cannot delete anything. Select-all and unselect-all
13
- * are two buttons rather than one toggle: after a partial selection the user
14
- * needs both directions, and one alternating control cannot say which it means.
11
+ * is the ONLY place a destructive action can be started — the checkboxes
12
+ * themselves never act, so a mis-tap on a row cannot delete anything. Select-all
13
+ * and unselect-all are two buttons rather than one toggle: after a partial
14
+ * selection the user needs both directions, and one alternating control cannot
15
+ * say which it means.
15
16
  *
16
17
  * The scope noun is the mode's, not the bar's: "Select all" on the session mode
17
18
  * means every session of the workspace whose menu started it, and on the
18
19
  * workspace mode every workspace on screen.
20
+ *
21
+ * Archive is a SESSION verb — a workspace has no archive state — so the caller
22
+ * passes `onArchive` only in session mode, and the bar omits the control when it
23
+ * is absent. The action row is a grid: three columns when Archive is absent
24
+ * (Select all / Unselect all / Delete) and two when it is present, so the four
25
+ * labels stay readable in a 264px sidebar instead of truncating to nothing.
19
26
  */
20
27
 
21
- import { CheckCheck, Loader2, Trash2, X } from 'lucide-preact';
28
+ import { Archive, CheckCheck, Loader2, Trash2, X } from 'lucide-preact';
22
29
  import type { BatchMode } from '@/shared/lib/workspace/batch-select';
23
30
 
24
31
  export interface BatchActionBarProps {
@@ -29,11 +36,15 @@ export interface BatchActionBarProps {
29
36
  total: number;
30
37
  /** True while a batch delete is in flight. */
31
38
  busy: boolean;
39
+ /** True while a batch archive is in flight. */
40
+ archiving?: boolean;
32
41
  /** The scope's name, for the sentence ("in kabmo"). Omitted in workspace mode. */
33
42
  scopeLabel?: string;
34
43
  onSelectAll: () => void;
35
44
  onUnselectAll: () => void;
36
45
  onDelete: () => void;
46
+ /** Present only in session mode; the bar draws Archive when it is. */
47
+ onArchive?: () => void;
37
48
  onCancel: () => void;
38
49
  /**
39
50
  * The bar sits in the phone drawer, whose list and toolbar are both `p-3`.
@@ -48,16 +59,28 @@ export function BatchActionBar({
48
59
  count,
49
60
  total,
50
61
  busy,
62
+ archiving = false,
51
63
  scopeLabel,
52
64
  onSelectAll,
53
65
  onUnselectAll,
54
66
  onDelete,
67
+ onArchive,
55
68
  onCancel,
56
69
  drawer = false,
57
70
  }: BatchActionBarProps) {
58
71
  const noun = mode === 'workspace' ? 'workspace' : 'session';
59
72
  const plural = count === 1 ? noun : `${noun}s`;
60
73
  const where = mode === 'session' && scopeLabel ? ` in ${scopeLabel}` : '';
74
+ // Any mutation in flight locks the whole bar: a second click while the first
75
+ // request is unresolved would act on a selection the server is already
76
+ // changing.
77
+ const inFlight = busy || archiving;
78
+ const actionDisabled = inFlight || count === 0;
79
+ // Archive is a session verb: a workspace has no archive state, so a caller
80
+ // that passes `onArchive` in workspace mode cannot draw one here.
81
+ const showArchive = mode === 'session' && Boolean(onArchive);
82
+ const actionClass = 'min-w-0 w-full h-7 flex items-center justify-center gap-1 px-2 rounded border text-[11px] font-medium transition-colors cursor-pointer disabled:opacity-40';
83
+ const actionIdle = 'border-ink/20 text-ink hover:bg-ink/5';
61
84
 
62
85
  return (
63
86
  <div
@@ -72,7 +95,7 @@ export function BatchActionBar({
72
95
  <button
73
96
  type="button"
74
97
  onClick={onCancel}
75
- disabled={busy}
98
+ disabled={inFlight}
76
99
  title="Cancel selection"
77
100
  aria-label="Cancel selection"
78
101
  className="shrink-0 w-5 h-5 flex items-center justify-center rounded text-ink/50 hover:text-ink hover:bg-ink/10 transition-colors cursor-pointer disabled:opacity-50"
@@ -81,12 +104,12 @@ export function BatchActionBar({
81
104
  </button>
82
105
  </div>
83
106
 
84
- <div className="flex items-center gap-1.5">
107
+ <div className={`grid gap-1.5 ${showArchive ? 'grid-cols-2' : 'grid-cols-3'}`}>
85
108
  <button
86
109
  type="button"
87
110
  onClick={onSelectAll}
88
- disabled={busy || total === 0 || count === total}
89
- className="flex-1 min-w-0 h-7 flex items-center justify-center gap-1 px-2 rounded border border-ink/20 text-[11px] font-medium text-ink hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-40"
111
+ disabled={inFlight || total === 0 || count === total}
112
+ className={`${actionClass} ${actionIdle}`}
90
113
  >
91
114
  <CheckCheck size={12} className="shrink-0" />
92
115
  <span className="truncate">Select all</span>
@@ -94,16 +117,36 @@ export function BatchActionBar({
94
117
  <button
95
118
  type="button"
96
119
  onClick={onUnselectAll}
97
- disabled={busy || count === 0}
98
- className="flex-1 min-w-0 h-7 flex items-center justify-center gap-1 px-2 rounded border border-ink/20 text-[11px] font-medium text-ink hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-40"
120
+ disabled={inFlight || count === 0}
121
+ className={`${actionClass} ${actionIdle}`}
99
122
  >
100
123
  <span className="truncate">Unselect all</span>
101
124
  </button>
125
+ {showArchive && (
126
+ <button
127
+ type="button"
128
+ onClick={onArchive}
129
+ disabled={actionDisabled}
130
+ className={`${actionClass} ${actionIdle}`}
131
+ >
132
+ {archiving ? (
133
+ <>
134
+ <Loader2 size={12} className="animate-spin shrink-0" />
135
+ <span className="truncate">Archiving…</span>
136
+ </>
137
+ ) : (
138
+ <>
139
+ <Archive size={12} className="shrink-0" />
140
+ <span className="truncate">Archive {count > 0 ? `${count} ${plural}` : plural}</span>
141
+ </>
142
+ )}
143
+ </button>
144
+ )}
102
145
  <button
103
146
  type="button"
104
147
  onClick={onDelete}
105
- disabled={busy || count === 0}
106
- className="flex-1 min-w-0 h-7 flex items-center justify-center gap-1 px-2 rounded bg-error text-canvas text-[11px] font-semibold hover:opacity-90 transition-opacity cursor-pointer disabled:opacity-40"
148
+ disabled={actionDisabled}
149
+ className="min-w-0 w-full h-7 flex items-center justify-center gap-1 px-2 rounded bg-error text-canvas text-[11px] font-semibold hover:opacity-90 transition-opacity cursor-pointer disabled:opacity-40"
107
150
  >
108
151
  {busy ? (
109
152
  <>