@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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +319 -319
- package/dist/client/static/js/index-bnrrw242.css +1 -0
- package/dist/client/static/js/{index-vzb1qz51.js → index-w6jx0h0p.js} +780 -780
- package/marketplace/plugins/command-runner/package.json +2 -2
- package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
- package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
- package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
- package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
- package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
- package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
- package/package.json +2 -2
- package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
- package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
- package/src/client/components/common/code-surface/extensions.ts +7 -1
- package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
- package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
- package/src/client/components/common/session-row/index.tsx +215 -0
- package/src/client/components/common/session-row/session-row.test.tsx +154 -0
- package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
- package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
- package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
- package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
- package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +56 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +193 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
- package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
- package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
- package/src/client/components/mobile/SessionSidebar.tsx +137 -146
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
- package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
- package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
- package/src/client/components/settings/Modal.tsx +5 -27
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/apply-side-effects.test.ts +102 -0
- package/src/client/components/settings/apply-side-effects.ts +90 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
- package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
- package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
- package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
- package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
- package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
- package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
- package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
- package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +15 -5
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
- package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
- package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +117 -75
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
- package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +178 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
- package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
- package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
- package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
- package/src/client/components/workspace/diff-panel/folding.ts +6 -1
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
- package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
- package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
- package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
- package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
- package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
- package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
- package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
- package/src/client/data/settings/omp-schema.json +151 -6
- package/src/client/hooks/chat/composer/style.ts +66 -0
- package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
- package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
- package/src/client/hooks/chat/timeline/row-window.ts +59 -133
- package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
- package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
- package/src/client/hooks/settings/providers/login.ts +11 -2
- package/src/client/hooks/ui/window-event.ts +20 -4
- package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
- package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
- package/src/client/hooks/workspace/batch-archive.ts +78 -0
- package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
- package/src/client/hooks/workspace/sidebar-style.ts +66 -0
- package/src/client/tailwind.css +111 -0
- package/src/server/index.ts +10 -134
- package/src/server/lib/lifecycle/after-listen.ts +178 -0
- package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
- package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
- package/src/server/lib/lifecycle/tls.test.ts +7 -7
- package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
- package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
- package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
- package/src/server/lib/plugins/background.server.ts +17 -1
- package/src/server/lib/plugins/background.test.ts +33 -0
- package/src/server/routes/sessions/batch-archive.test.ts +113 -0
- package/src/server/routes/sessions/batch-archive.ts +80 -0
- package/src/server/routes/sessions/index.ts +4 -0
- package/src/shared/lib/chat/composer/style.test.ts +126 -0
- package/src/shared/lib/chat/composer/style.ts +171 -0
- package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
- package/src/shared/lib/chat/composer/tui-only.ts +5 -0
- package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
- package/src/shared/lib/chat/timeline/trace-groups.test.ts +132 -0
- package/src/shared/lib/chat/timeline/trace-groups.ts +95 -0
- package/src/shared/lib/settings/defaults.ts +6 -0
- package/src/shared/lib/workspace/session-focus.test.ts +93 -0
- package/src/shared/lib/workspace/session-focus.ts +71 -0
- package/src/shared/lib/workspace/session-state/store.ts +5 -0
- package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
- package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
- package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
- package/src/shared/lib/workspace/sidebar-style.ts +86 -0
- package/src/shared/types/omp/agent.ts +6 -0
- package/src/shared/types/settings/state.ts +31 -0
- package/dist/client/static/js/index-68w8h33q.css +0 -1
- package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The process-level rejection guard.
|
|
8
|
+
*
|
|
9
|
+
* The property worth pinning is the one a crash taught: a rejection from code
|
|
10
|
+
* this server does not own must produce a LOG LINE and leave the process alive,
|
|
11
|
+
* because the alternative is every live session dying with it. The listener is
|
|
12
|
+
* asserted directly (rather than by rejecting inside a test) so the spec cannot
|
|
13
|
+
* itself trip the runner's own unhandled-rejection handling.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import {
|
|
18
|
+
describeRejection,
|
|
19
|
+
installRejectionGuard,
|
|
20
|
+
resetRejectionGuardForTests,
|
|
21
|
+
} from '@/server/lib/lifecycle/rejection-guard';
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
process.removeAllListeners('unhandledRejection');
|
|
25
|
+
resetRejectionGuardForTests();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('describeRejection', () => {
|
|
29
|
+
test('an Error reports its stack, which names the line that threw', () => {
|
|
30
|
+
const described = describeRejection(new Error('disk I/O error'));
|
|
31
|
+
expect(described).toContain('disk I/O error');
|
|
32
|
+
expect(described).toContain('at ');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('a thrown string is passed through', () => {
|
|
36
|
+
expect(describeRejection('boom')).toBe('boom');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('a plain object is serialized', () => {
|
|
40
|
+
expect(describeRejection({ code: 'SQLITE_IOERR_VNODE' })).toBe('{"code":"SQLITE_IOERR_VNODE"}');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('a value with a circular reference still produces a line', () => {
|
|
44
|
+
const circular: Record<string, unknown> = {};
|
|
45
|
+
circular.self = circular;
|
|
46
|
+
expect(describeRejection(circular)).toBe('[object Object]');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('installRejectionGuard', () => {
|
|
51
|
+
test('installs exactly one listener, however many times the entry re-runs', () => {
|
|
52
|
+
installRejectionGuard();
|
|
53
|
+
installRejectionGuard();
|
|
54
|
+
installRejectionGuard();
|
|
55
|
+
expect(process.listenerCount('unhandledRejection')).toBe(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('the installed listener logs instead of throwing, so the process survives', () => {
|
|
59
|
+
const logged: string[] = [];
|
|
60
|
+
const original = console.error;
|
|
61
|
+
console.error = (...args: unknown[]) => void logged.push(args.map(String).join(' '));
|
|
62
|
+
try {
|
|
63
|
+
installRejectionGuard();
|
|
64
|
+
const listener = process.listeners('unhandledRejection')[0] as (reason: unknown) => void;
|
|
65
|
+
expect(() => listener(new Error('plugin sampler died'))).not.toThrow();
|
|
66
|
+
} finally {
|
|
67
|
+
console.error = original;
|
|
68
|
+
}
|
|
69
|
+
expect(logged).toHaveLength(1);
|
|
70
|
+
expect(logged[0]).toContain('plugin sampler died');
|
|
71
|
+
expect(logged[0]).toContain('contained');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('it never claims uncaughtException — a synchronous throw still fails fast', () => {
|
|
75
|
+
const before = process.listenerCount('uncaughtException');
|
|
76
|
+
installRejectionGuard();
|
|
77
|
+
expect(process.listenerCount('uncaughtException')).toBe(before);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Contain an unhandled promise rejection instead of letting it kill the server.
|
|
8
|
+
*
|
|
9
|
+
* Bun's default is to exit 1 on an unhandled rejection. For a CLI that is the
|
|
10
|
+
* right answer; for this process it is not, because it hosts every live session
|
|
11
|
+
* and every loaded plugin, and the rejections that actually arrive are from code
|
|
12
|
+
* we do not own. Measured: the stats plugin's sampler re-reads its interval from
|
|
13
|
+
* the database inside a floating `async` IIFE —
|
|
14
|
+
*
|
|
15
|
+
* start() { (async () => { while (…) { … await readSampleMs() } })() }
|
|
16
|
+
*
|
|
17
|
+
* — so a data directory that vanished under it produced `SQLITE_IOERR_VNODE`
|
|
18
|
+
* with no handler anywhere, and the whole server exited 1 while a browser was
|
|
19
|
+
* mid-session. The plugin is a marketplace bundle; there is no line of it to fix,
|
|
20
|
+
* and `service.start()` returning nothing means the loader cannot attach a
|
|
21
|
+
* `.catch` either (its `void Promise.resolve(...).catch(...)` never sees this
|
|
22
|
+
* rejection, because the promise it would catch is `undefined`).
|
|
23
|
+
*
|
|
24
|
+
* So the containment lives at the process boundary, and it REPORTS: the error
|
|
25
|
+
* and its stack go to the log under the server's own prefix. That is the
|
|
26
|
+
* difference between this and swallowing — a swallowed failure is one nobody can
|
|
27
|
+
* find, and this one is one line away from the code that caused it.
|
|
28
|
+
*
|
|
29
|
+
* `uncaughtException` is deliberately NOT handled. A synchronous throw out of a
|
|
30
|
+
* request handler leaves the process in an unknown state, and continuing from
|
|
31
|
+
* there is how a server answers from half-applied writes; a rejection is a
|
|
32
|
+
* promise nobody awaited, which leaves the process intact.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** The flag lives on `globalThis` because `bun --hot` re-evaluates this module. */
|
|
36
|
+
interface RejectionGuardHost {
|
|
37
|
+
__kabmoRejectionGuard?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const PREFIX = '[kabmo] unhandled rejection (contained)';
|
|
41
|
+
|
|
42
|
+
function guardHost(): RejectionGuardHost {
|
|
43
|
+
return globalThis as RejectionGuardHost;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The message and stack of a rejection reason, whatever was thrown. */
|
|
47
|
+
export function describeRejection(reason: unknown): string {
|
|
48
|
+
if (reason instanceof Error) return reason.stack ?? `${reason.name}: ${reason.message}`;
|
|
49
|
+
if (typeof reason === 'string') return reason;
|
|
50
|
+
try {
|
|
51
|
+
return JSON.stringify(reason) ?? String(reason);
|
|
52
|
+
} catch {
|
|
53
|
+
// A rejected value with a circular reference must still produce a line.
|
|
54
|
+
return String(reason);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Install the handler. Idempotent: the entry re-runs under `bun --hot` in the
|
|
60
|
+
* same process, and a second listener would log every rejection twice.
|
|
61
|
+
*/
|
|
62
|
+
export function installRejectionGuard(): void {
|
|
63
|
+
const host = guardHost();
|
|
64
|
+
if (host.__kabmoRejectionGuard) return;
|
|
65
|
+
host.__kabmoRejectionGuard = true;
|
|
66
|
+
process.on('unhandledRejection', (reason) => {
|
|
67
|
+
console.error(`${PREFIX}: ${describeRejection(reason)}`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Test seam: forget the installation so a spec can assert the listener. */
|
|
72
|
+
export function resetRejectionGuardForTests(): void {
|
|
73
|
+
guardHost().__kabmoRejectionGuard = false;
|
|
74
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
15
|
+
import { X509Certificate } from 'node:crypto';
|
|
15
16
|
import fs from 'node:fs';
|
|
16
17
|
import os from 'node:os';
|
|
17
18
|
import path from 'node:path';
|
|
@@ -51,13 +52,12 @@ describe('ensureTlsCertificate', () => {
|
|
|
51
52
|
expect(fs.existsSync(result.certPath)).toBe(true);
|
|
52
53
|
expect(fs.existsSync(result.keyPath)).toBe(true);
|
|
53
54
|
|
|
54
|
-
// A certificate
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const san = parsed.stdout.toString();
|
|
55
|
+
// A certificate the runtime cannot parse is not a certificate. Read it back
|
|
56
|
+
// through `node:crypto` rather than `openssl x509 -ext`: the `-ext` flag is
|
|
57
|
+
// OpenSSL 1.1.1+, and macOS ships LibreSSL 3.3.6 on PATH, where the flag is
|
|
58
|
+
// rejected as an unknown option — a red test that says nothing about the pair.
|
|
59
|
+
const parsed = new X509Certificate(fs.readFileSync(result.certPath));
|
|
60
|
+
const san = parsed.subjectAltName ?? '';
|
|
61
61
|
// Loopback under both names a browser may use, or the warning is a name
|
|
62
62
|
// mismatch on top of the self-signed warning.
|
|
63
63
|
expect(san).toContain('DNS:localhost');
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The frames whose fold is a SESSION-state decision rather than a trigger.
|
|
8
|
+
*
|
|
9
|
+
* Split from `frame-fold.test.ts` by subject: that file pins WHEN the
|
|
10
|
+
* auto-title trigger fires, while these three pin what a frame does to the row
|
|
11
|
+
* the sidebar draws and to the caches that describe the session file. Each
|
|
12
|
+
* expectation is a defect that shipped once — a spinner that never stopped, a
|
|
13
|
+
* title that did not appear until an unrelated tool call republished, and an
|
|
14
|
+
* idle-looking session in the middle of a compaction.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, expect, test } from 'bun:test';
|
|
18
|
+
|
|
19
|
+
import { foldSessionFrame } from '@/server/lib/omp/rpc/frame-fold';
|
|
20
|
+
import { releasesStreamRowOnPromptResult } from '@/shared/lib/omp/session/stream-heal.server';
|
|
21
|
+
import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The `prompt_result` frame is where omp reports `agentInvoked`, and the
|
|
25
|
+
* dispatch-time `stream` row hangs on it.
|
|
26
|
+
*
|
|
27
|
+
* The shipped defect: the chamber's own `/chamber-mode` extension (the
|
|
28
|
+
* composer's Plan/Goal toggles) acks a BARE `{success:true}` — no
|
|
29
|
+
* `agentInvoked` — and reports `agentInvoked:false` on this frame instead. The
|
|
30
|
+
* dispatcher read that bare ack as a run, armed the awaiting-agent-start
|
|
31
|
+
* deadline, and left the row `stream` with a LIVE owner, which
|
|
32
|
+
* `healStaleStreamStatuses` can never reach. The sidebar spinner turned
|
|
33
|
+
* forever. Reproduced end to end against the real omp child before the fix.
|
|
34
|
+
*/
|
|
35
|
+
describe('releasesStreamRowOnPromptResult', () => {
|
|
36
|
+
const live = { streaming: false, sessionId: 's1' };
|
|
37
|
+
|
|
38
|
+
test('releases the row for a prompt that opened no turn', () => {
|
|
39
|
+
expect(releasesStreamRowOnPromptResult({ agentInvoked: false }, live)).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('never releases a row for a prompt that DID open a turn', () => {
|
|
43
|
+
// omp's own trailing `prompt_result` for a real run carries `true`.
|
|
44
|
+
expect(releasesStreamRowOnPromptResult({ agentInvoked: true }, live)).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('a frame with no agentInvoked field is not proof of anything', () => {
|
|
48
|
+
// An older omp, or any other prompt_result shape. Reading absence as
|
|
49
|
+
// "no turn" would clear the spinner of a run that is working.
|
|
50
|
+
expect(releasesStreamRowOnPromptResult({}, live)).toBe(false);
|
|
51
|
+
expect(releasesStreamRowOnPromptResult({ agentInvoked: undefined }, live)).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('keeps the running turn’s row when the command lands mid-turn', () => {
|
|
55
|
+
// Measured: a `/chamber-mode` sent while a turn streams is answered in
|
|
56
|
+
// ~20 ms from omp's command loop with the turn STILL running. Clearing
|
|
57
|
+
// here would blank the spinner of a run that is demonstrably working.
|
|
58
|
+
expect(releasesStreamRowOnPromptResult({ agentInvoked: false }, { streaming: true, sessionId: 's1' })).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('does nothing before the session id is known', () => {
|
|
62
|
+
expect(releasesStreamRowOnPromptResult({ agentInvoked: false }, { streaming: false, sessionId: '' })).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A rename writes the title SLOT in place, which no mtime-keyed scan can see.
|
|
68
|
+
*
|
|
69
|
+
* The sidebar therefore has to be republished from this frame, not only from
|
|
70
|
+
* the turn-boundary signals: measured, a session named by its own run kept
|
|
71
|
+
* `New Session - <timestamp>` in the list while the header already showed the
|
|
72
|
+
* title, until an unrelated tool call happened to republish.
|
|
73
|
+
*/
|
|
74
|
+
describe('session_info_update', () => {
|
|
75
|
+
test('drops the sidebar scan cache, which the in-place title write cannot invalidate itself', () => {
|
|
76
|
+
// The title is rewritten in a fixed-width slot INSIDE the session file, so
|
|
77
|
+
// the mtime the scan cache keys on does not move. Without this the list
|
|
78
|
+
// kept `New Session - <timestamp>` while the header already showed the
|
|
79
|
+
// title, until an unrelated tool call happened to republish.
|
|
80
|
+
globalThis.__kabmoSidebarDataCache = {
|
|
81
|
+
data: {} as never,
|
|
82
|
+
expiresAt: Date.now() + 60_000,
|
|
83
|
+
inFlight: null,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const host = makeHost({ sessionId: 's1' });
|
|
87
|
+
const result = foldSessionFrame(host, { type: 'session_info_update', title: 'A new name' });
|
|
88
|
+
|
|
89
|
+
expect(result.suppressForward).toBe(false);
|
|
90
|
+
expect(globalThis.__kabmoSidebarDataCache?.expiresAt).toBe(0);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Both compaction pairs drive `compacting`, and the session-file caches.
|
|
96
|
+
*
|
|
97
|
+
* `auto_*` is omp's own threshold pass; `manual_*` is one the user asked for
|
|
98
|
+
* (the `compact` command, a typed `/compact`, an extension's `ctx.compact()`).
|
|
99
|
+
* 18.14.0 emits the manual pair — measured against a real child: a `/compact`
|
|
100
|
+
* prompt answers `manual_compaction_start`, then `_end`, then a `command_output`
|
|
101
|
+
* carrying omp's own sentence. Before it a typed `/compact` emitted nothing, so
|
|
102
|
+
* the flag stayed false and `isBusy()` called the session idle mid-pass.
|
|
103
|
+
*/
|
|
104
|
+
describe('compaction frames', () => {
|
|
105
|
+
test('the auto pair sets and clears `compacting`', () => {
|
|
106
|
+
const host = makeHost({ sessionId: 's1' });
|
|
107
|
+
|
|
108
|
+
foldSessionFrame(host, { type: 'auto_compaction_start', reason: 'context-full', action: 'context-full' });
|
|
109
|
+
expect(host.compacting).toBe(true);
|
|
110
|
+
|
|
111
|
+
foldSessionFrame(host, { type: 'auto_compaction_end', aborted: false, willRetry: false });
|
|
112
|
+
expect(host.compacting).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('the manual pair does too, and drops the session-file caches on the way out', () => {
|
|
116
|
+
const host = makeHost({ sessionId: 's1' });
|
|
117
|
+
|
|
118
|
+
foldSessionFrame(host, { type: 'manual_compaction_start' });
|
|
119
|
+
expect(host.compacting).toBe(true);
|
|
120
|
+
|
|
121
|
+
// The compaction rewrote the transcript, so a cached scan would keep
|
|
122
|
+
// serving the pre-compaction read of the same file — the scan cache is
|
|
123
|
+
// keyed on `(size, mtimeMs)`, and omp rewrites the file in place.
|
|
124
|
+
globalThis.__kabmoSessionScanCache = { version: 3, entries: new Map([['/tmp/s.jsonl', {} as never]]) };
|
|
125
|
+
foldSessionFrame(host, { type: 'manual_compaction_end', aborted: false, skipped: true });
|
|
126
|
+
|
|
127
|
+
expect(host.compacting).toBe(false);
|
|
128
|
+
expect(globalThis.__kabmoSessionScanCache.entries.size).toBe(0);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The host the frame-fold tests drive.
|
|
8
|
+
*
|
|
9
|
+
* Shared by `frame-fold.test.ts` (when a trigger fires) and
|
|
10
|
+
* `frame-fold-frames.test.ts` (what a frame does to the session's row and
|
|
11
|
+
* caches) so the two cannot disagree about what a default host looks like —
|
|
12
|
+
* a second copy would drift the moment a field is added to `SessionFrameHost`.
|
|
13
|
+
*
|
|
14
|
+
* No session id by default, so a fold that would reach the settings database
|
|
15
|
+
* returns first and the tests stay pure.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold';
|
|
19
|
+
import { ModeMirror } from '@/server/lib/omp/rpc/mode-mirror';
|
|
20
|
+
|
|
21
|
+
export function makeHost(overrides: Partial<SessionFrameHost> = {}): SessionFrameHost {
|
|
22
|
+
return {
|
|
23
|
+
sessionId: '',
|
|
24
|
+
autoTitleWindowUntil: 0,
|
|
25
|
+
autoTitleClaims: 0,
|
|
26
|
+
autoTitleDispatch: null,
|
|
27
|
+
autoTitlePending: true,
|
|
28
|
+
autoTitleRequested: false,
|
|
29
|
+
promptRunning: false,
|
|
30
|
+
streaming: false,
|
|
31
|
+
compacting: false,
|
|
32
|
+
awaitingAgentStart: false,
|
|
33
|
+
awaitingAgentStartDeadline: 0,
|
|
34
|
+
continuationGraceUntil: 0,
|
|
35
|
+
proc: { sendCommand: async () => undefined as never },
|
|
36
|
+
emit() {},
|
|
37
|
+
trackUiDialog() {},
|
|
38
|
+
observeSubagent() {},
|
|
39
|
+
syncRunModel() {},
|
|
40
|
+
modeMirror: new ModeMirror(),
|
|
41
|
+
isAlive: () => true,
|
|
42
|
+
isBusy: () => false,
|
|
43
|
+
send: async () => undefined,
|
|
44
|
+
...overrides,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -20,36 +20,8 @@
|
|
|
20
20
|
import { describe, expect, test } from 'bun:test';
|
|
21
21
|
|
|
22
22
|
import { foldSessionFrame, type SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold';
|
|
23
|
-
import { releasesStreamRowOnPromptResult } from '@/shared/lib/omp/session/stream-heal.server';
|
|
24
23
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
function makeHost(overrides: Partial<SessionFrameHost> = {}): SessionFrameHost {
|
|
28
|
-
return {
|
|
29
|
-
sessionId: '',
|
|
30
|
-
autoTitleWindowUntil: 0,
|
|
31
|
-
autoTitleClaims: 0,
|
|
32
|
-
autoTitleDispatch: null,
|
|
33
|
-
autoTitlePending: true,
|
|
34
|
-
autoTitleRequested: false,
|
|
35
|
-
promptRunning: false,
|
|
36
|
-
streaming: false,
|
|
37
|
-
compacting: false,
|
|
38
|
-
awaitingAgentStart: false,
|
|
39
|
-
awaitingAgentStartDeadline: 0,
|
|
40
|
-
continuationGraceUntil: 0,
|
|
41
|
-
proc: { sendCommand: async () => undefined as never },
|
|
42
|
-
emit() {},
|
|
43
|
-
trackUiDialog() {},
|
|
44
|
-
observeSubagent() {},
|
|
45
|
-
syncRunModel() {},
|
|
46
|
-
modeMirror: new ModeMirror(),
|
|
47
|
-
isAlive: () => true,
|
|
48
|
-
isBusy: () => false,
|
|
49
|
-
send: async () => undefined,
|
|
50
|
-
...overrides,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
24
|
+
import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
|
|
53
25
|
|
|
54
26
|
/** Fold one frame and report the flags the trigger leaves behind. */
|
|
55
27
|
function fold(host: SessionFrameHost, event: AgentEvent): void {
|
|
@@ -256,74 +228,3 @@ describe('model_changed wiring', () => {
|
|
|
256
228
|
expect(synced).toBe(1);
|
|
257
229
|
});
|
|
258
230
|
});
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* The `prompt_result` frame is where omp reports `agentInvoked`, and the
|
|
262
|
-
* dispatch-time `stream` row hangs on it.
|
|
263
|
-
*
|
|
264
|
-
* The shipped defect: the chamber's own `/chamber-mode` extension (the
|
|
265
|
-
* composer's Plan/Goal toggles) acks a BARE `{success:true}` — no
|
|
266
|
-
* `agentInvoked` — and reports `agentInvoked:false` on this frame instead. The
|
|
267
|
-
* dispatcher read that bare ack as a run, armed the awaiting-agent-start
|
|
268
|
-
* deadline, and left the row `stream` with a LIVE owner, which
|
|
269
|
-
* `healStaleStreamStatuses` can never reach. The sidebar spinner turned
|
|
270
|
-
* forever. Reproduced end to end against the real omp child before the fix.
|
|
271
|
-
*/
|
|
272
|
-
describe('releasesStreamRowOnPromptResult', () => {
|
|
273
|
-
const live = { streaming: false, sessionId: 's1' };
|
|
274
|
-
|
|
275
|
-
test('releases the row for a prompt that opened no turn', () => {
|
|
276
|
-
expect(releasesStreamRowOnPromptResult({ agentInvoked: false }, live)).toBe(true);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
test('never releases a row for a prompt that DID open a turn', () => {
|
|
280
|
-
// omp's own trailing `prompt_result` for a real run carries `true`.
|
|
281
|
-
expect(releasesStreamRowOnPromptResult({ agentInvoked: true }, live)).toBe(false);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test('a frame with no agentInvoked field is not proof of anything', () => {
|
|
285
|
-
// An older omp, or any other prompt_result shape. Reading absence as
|
|
286
|
-
// "no turn" would clear the spinner of a run that is working.
|
|
287
|
-
expect(releasesStreamRowOnPromptResult({}, live)).toBe(false);
|
|
288
|
-
expect(releasesStreamRowOnPromptResult({ agentInvoked: undefined }, live)).toBe(false);
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
test('keeps the running turn’s row when the command lands mid-turn', () => {
|
|
292
|
-
// Measured: a `/chamber-mode` sent while a turn streams is answered in
|
|
293
|
-
// ~20 ms from omp's command loop with the turn STILL running. Clearing
|
|
294
|
-
// here would blank the spinner of a run that is demonstrably working.
|
|
295
|
-
expect(releasesStreamRowOnPromptResult({ agentInvoked: false }, { streaming: true, sessionId: 's1' })).toBe(false);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test('does nothing before the session id is known', () => {
|
|
299
|
-
expect(releasesStreamRowOnPromptResult({ agentInvoked: false }, { streaming: false, sessionId: '' })).toBe(false);
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* A rename writes the title SLOT in place, which no mtime-keyed scan can see.
|
|
305
|
-
*
|
|
306
|
-
* The sidebar therefore has to be republished from this frame, not only from
|
|
307
|
-
* the turn-boundary signals: measured, a session named by its own run kept
|
|
308
|
-
* `New Session - <timestamp>` in the list while the header already showed the
|
|
309
|
-
* title, until an unrelated tool call happened to republish.
|
|
310
|
-
*/
|
|
311
|
-
describe('session_info_update', () => {
|
|
312
|
-
test('drops the sidebar scan cache, which the in-place title write cannot invalidate itself', () => {
|
|
313
|
-
// The title is rewritten in a fixed-width slot INSIDE the session file, so
|
|
314
|
-
// the mtime the scan cache keys on does not move. Without this the list
|
|
315
|
-
// kept `New Session - <timestamp>` while the header already showed the
|
|
316
|
-
// title, until an unrelated tool call happened to republish.
|
|
317
|
-
globalThis.__kabmoSidebarDataCache = {
|
|
318
|
-
data: {} as never,
|
|
319
|
-
expiresAt: Date.now() + 60_000,
|
|
320
|
-
inFlight: null,
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const host = makeHost({ sessionId: 's1' });
|
|
324
|
-
const result = foldSessionFrame(host, { type: 'session_info_update', title: 'A new name' });
|
|
325
|
-
|
|
326
|
-
expect(result.suppressForward).toBe(false);
|
|
327
|
-
expect(globalThis.__kabmoSidebarDataCache?.expiresAt).toBe(0);
|
|
328
|
-
});
|
|
329
|
-
});
|
|
@@ -246,10 +246,23 @@ export function foldSessionFrame(host: SessionFrameHost, event: AgentEvent): Fra
|
|
|
246
246
|
case 'prompt_result':
|
|
247
247
|
result.suppressForward = handlePromptResult(host, event);
|
|
248
248
|
break;
|
|
249
|
+
// omp reports compaction progress in two pairs. `auto_*` is the one it runs
|
|
250
|
+
// itself at a threshold; `manual_*` is a pass the user asked for — the RPC
|
|
251
|
+
// `compact` command, a `/compact` typed into the composer, or an extension's
|
|
252
|
+
// `ctx.compact()`. 18.14.0 emits the manual pair (measured: a `/compact`
|
|
253
|
+
// prompt answers `manual_compaction_start`, then `_end`, then the
|
|
254
|
+
// `command_output` carrying omp's own sentence). Before it, a typed
|
|
255
|
+
// `/compact` emitted NOTHING, so `compacting` stayed false for the whole
|
|
256
|
+
// pass: `isBusy()` reported an idle session while omp was rewriting the
|
|
257
|
+
// transcript, and a reset (or a command timeout's reset) could kill it —
|
|
258
|
+
// and the session-file caches were never dropped, so the sidebar and the
|
|
259
|
+
// timeline kept serving the pre-compaction read. Both pairs fold here.
|
|
249
260
|
case 'auto_compaction_start':
|
|
261
|
+
case 'manual_compaction_start':
|
|
250
262
|
host.compacting = true;
|
|
251
263
|
break;
|
|
252
264
|
case 'auto_compaction_end':
|
|
265
|
+
case 'manual_compaction_end':
|
|
253
266
|
host.compacting = false;
|
|
254
267
|
clearSessionFileCaches();
|
|
255
268
|
break;
|
|
@@ -81,7 +81,23 @@ export function createPluginBackground(pluginId: string, now = Date.now()): {
|
|
|
81
81
|
// The start runs HERE, at declaration: a service that needed the loader to
|
|
82
82
|
// begin would be a service that does not exist for the first tick, and the
|
|
83
83
|
// ordering between "started" and "scheduled" would depend on the loader.
|
|
84
|
-
|
|
84
|
+
//
|
|
85
|
+
// Its RETURNED promise is contained, because a service is plugin code and a
|
|
86
|
+
// rejection nobody holds is fatal to the whole server. A synchronous throw
|
|
87
|
+
// still propagates (the loader reports a plugin that cannot load); only the
|
|
88
|
+
// async half is caught, and it is reported under the plugin's own name
|
|
89
|
+
// rather than swallowed.
|
|
90
|
+
//
|
|
91
|
+
// This catches a plugin that `return`s its promise. It does NOT catch one
|
|
92
|
+
// that starts a floating `async` IIFE inside `start()` — measured, the
|
|
93
|
+
// stats plugin's sampler does exactly that, so its `SQLITE_IOERR_VNODE`
|
|
94
|
+
// never reached this line. The process boundary handles that case
|
|
95
|
+
// (`installRejectionGuard`, called from the entry).
|
|
96
|
+
void Promise.resolve(service.start()).catch((error) => {
|
|
97
|
+
console.error(
|
|
98
|
+
`[plugins] ${pluginId}: service "${id}" failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
85
101
|
},
|
|
86
102
|
schedule(id, spec, run) {
|
|
87
103
|
if (typeof run !== 'function') throw new Error(`schedule "${id}" has no run()`);
|
|
@@ -44,6 +44,39 @@ describe('background', () => {
|
|
|
44
44
|
expect(handle.services[0]?.id).toBe('poller');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
+
test('a service that rejects is reported, not left to kill the process', async () => {
|
|
48
|
+
// Measured failure this pins: the stats plugin's sampler re-reads its
|
|
49
|
+
// interval from the database, and a data directory that vanished under it
|
|
50
|
+
// produced `SQLITE_IOERR_VNODE` from a floating promise — Bun exits 1 on an
|
|
51
|
+
// unhandled rejection, so one plugin's background loop took the whole server
|
|
52
|
+
// (and every session in it) down. The rejection must be logged instead.
|
|
53
|
+
const rejections: unknown[] = [];
|
|
54
|
+
const onRejection = (reason: unknown) => void rejections.push(reason);
|
|
55
|
+
process.on('unhandledRejection', onRejection);
|
|
56
|
+
const errors: string[] = [];
|
|
57
|
+
const originalError = console.error;
|
|
58
|
+
console.error = (...args: unknown[]) => void errors.push(args.map(String).join(' '));
|
|
59
|
+
try {
|
|
60
|
+
const { api } = createPluginBackground('alpha');
|
|
61
|
+
api.service('sampler', { start: async () => { throw new Error('disk I/O error'); } });
|
|
62
|
+
// One macrotask is enough for the rejection to settle and be handled.
|
|
63
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
64
|
+
} finally {
|
|
65
|
+
console.error = originalError;
|
|
66
|
+
process.off('unhandledRejection', onRejection);
|
|
67
|
+
}
|
|
68
|
+
expect(rejections).toEqual([]);
|
|
69
|
+
expect(errors).toHaveLength(1);
|
|
70
|
+
expect(errors[0]).toContain('alpha');
|
|
71
|
+
expect(errors[0]).toContain('sampler');
|
|
72
|
+
expect(errors[0]).toContain('disk I/O error');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a service that throws synchronously still refuses to load the plugin', () => {
|
|
76
|
+
const { api } = createPluginBackground('alpha');
|
|
77
|
+
expect(() => api.service('broken', { start: () => { throw new Error('no start'); } })).toThrow('no start');
|
|
78
|
+
});
|
|
79
|
+
|
|
47
80
|
test('a schedule resolves its next fire with Kabmo own grammar', () => {
|
|
48
81
|
const { api, handle } = createPluginBackground('alpha', 1_000_000);
|
|
49
82
|
api.schedule('sweep', '5m', () => {});
|