@kabmo-labs/kabmo 0.13.0 → 0.14.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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +319 -319
- package/dist/client/static/js/{index-vzb1qz51.js → index-nfsg1jpt.js} +779 -779
- package/dist/client/static/js/index-tsgy3gd1.css +1 -0
- package/package.json +1 -1
- 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 +205 -0
- package/src/client/components/common/session-row/session-row.test.tsx +144 -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 +55 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +184 -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/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 +14 -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.tsx +108 -67
- 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 +158 -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/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/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 +120 -0
- package/src/shared/lib/chat/timeline/trace-groups.ts +68 -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/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,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Everything the server starts AFTER its listener is accepting requests.
|
|
8
|
+
*
|
|
9
|
+
* Split out of `index.ts` so the entry file stays a readable boot script: the
|
|
10
|
+
* ordering rules below are the whole content of this module, and they are the
|
|
11
|
+
* part a reader needs to see in one place.
|
|
12
|
+
*
|
|
13
|
+
* The order is not cosmetic. Each clock starts once the thing it reads exists:
|
|
14
|
+
* the scheduled-task and waiting-prompt runtimes after the watchers (their first
|
|
15
|
+
* sweep may spawn an omp child), the bundled plugin sync before the server
|
|
16
|
+
* halves are imported (a half is `import()`ed from its BUILT bundle, so the copy
|
|
17
|
+
* on disk at that moment is the code this process runs until it restarts), and
|
|
18
|
+
* the tray last because its config carries the URL the listener now serves.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { getDb } from '@/server/db.server';
|
|
22
|
+
import { compactChatOverlayRows } from '@/server/lib/db/compact-chat-overlay';
|
|
23
|
+
import { packageDir } from '@/server/lib/fs/package-root';
|
|
24
|
+
import { isTrayEnabledByArgv } from '@/server/lib/lifecycle/argv-flags';
|
|
25
|
+
import { installMemoryMaintenance, stopMemoryMaintenance } from '@/server/lib/lifecycle/memory';
|
|
26
|
+
import { syncDiscoveryRootsWatch, stopDiscoveryRootsWatch } from '@/server/lib/omp/config/roots-watch.server';
|
|
27
|
+
import { startPanelAutoUpdate } from '@/server/lib/panels/auto-update.server';
|
|
28
|
+
import { syncBundledPlugins } from '@/server/lib/panels/sync.server';
|
|
29
|
+
import { disposeAllPluginsOnShutdown, loadPluginServers } from '@/server/lib/plugins/loader.server';
|
|
30
|
+
import { startScheduleRuntime, stopScheduleRuntime } from '@/server/lib/schedule/runtime.server';
|
|
31
|
+
import { ensureTray } from '@/server/lib/tray/runtime.server';
|
|
32
|
+
import { startWaitingRuntime, stopWaitingRuntime } from '@/server/lib/waiting/runtime.server';
|
|
33
|
+
|
|
34
|
+
/** What the tray needs from the listener that is already up. */
|
|
35
|
+
export interface AfterListenTarget {
|
|
36
|
+
port: number;
|
|
37
|
+
host: string;
|
|
38
|
+
tls: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Start every post-listen clock, in the order their inputs appear.
|
|
43
|
+
*
|
|
44
|
+
* Never throws: each step reports its own failure and the server keeps serving.
|
|
45
|
+
*/
|
|
46
|
+
export async function runAfterListenTasks(target: AfterListenTarget): Promise<void> {
|
|
47
|
+
await compactChatOverlay();
|
|
48
|
+
await watchDiscoveryRoots();
|
|
49
|
+
|
|
50
|
+
// The scheduled-task clock. Started after the listener is up and the watchers
|
|
51
|
+
// are attached, so a task that fires early cannot race the schema or the
|
|
52
|
+
// discovery roots; the runtime's own first tick is delayed for the same
|
|
53
|
+
// reason. Idempotent, and anchored on `globalThis` — a `bun --hot` reload must
|
|
54
|
+
// not leave a second interval running.
|
|
55
|
+
startScheduleRuntime();
|
|
56
|
+
|
|
57
|
+
// The waiting-prompt clock: a prompt held until another session finishes.
|
|
58
|
+
// Same shape and placement — its first sweep may spawn an omp child.
|
|
59
|
+
startWaitingRuntime();
|
|
60
|
+
|
|
61
|
+
await syncBundledPluginsAndReport();
|
|
62
|
+
await loadPluginServerHalves();
|
|
63
|
+
startPanelAutoUpdate();
|
|
64
|
+
startTray(target);
|
|
65
|
+
|
|
66
|
+
// A full collection past the ceiling, never a schedule (`lifecycle/memory.ts`).
|
|
67
|
+
installMemoryMaintenance();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Stop every clock this module started, and the listener, then exit.
|
|
72
|
+
*
|
|
73
|
+
* `stopListener` is passed in because the Elysia app belongs to the entry file;
|
|
74
|
+
* this only owns the order and the await-before-exit rule.
|
|
75
|
+
*/
|
|
76
|
+
export function installShutdownHandlers(stopListener: () => void | Promise<void>): void {
|
|
77
|
+
for (const signal of ['SIGTERM', 'SIGINT'] as const) {
|
|
78
|
+
process.once(signal, () => {
|
|
79
|
+
stopDiscoveryRootsWatch();
|
|
80
|
+
stopMemoryMaintenance();
|
|
81
|
+
stopScheduleRuntime();
|
|
82
|
+
stopWaitingRuntime();
|
|
83
|
+
void stopListener();
|
|
84
|
+
// Plugins own children and listeners nothing else releases, and a detached
|
|
85
|
+
// child outlives its parent — so this is awaited BEFORE the exit. It is
|
|
86
|
+
// bounded internally, so a plugin that hangs cannot hold the port.
|
|
87
|
+
void disposeAllPluginsOnShutdown().finally(() => process.exit(0));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* One-time rewrite of the overlay rows written before
|
|
94
|
+
* `overlayRowsForOmpSession` existed. Deliberately HERE and NOT inside `getDb()`:
|
|
95
|
+
* the test suite reaches `getDb()` in real mode, and opening a database must not
|
|
96
|
+
* launch a rewrite of every mirrored conversation (measured: a `bun test` run
|
|
97
|
+
* compacted a live one). Marker-keyed, so from the second start it is one
|
|
98
|
+
* indexed SELECT.
|
|
99
|
+
*/
|
|
100
|
+
async function compactChatOverlay(): Promise<void> {
|
|
101
|
+
try {
|
|
102
|
+
await compactChatOverlayRows(await getDb());
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('[chat-overlay] compaction skipped:', error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Watch the skill/command roots omp reads, so a SKILL.md written by anything
|
|
110
|
+
* other than Kabmo (a hand edit, `git pull`, the skills CLI, another agent)
|
|
111
|
+
* reaches the live sessions without a restart. See the module — the refresh
|
|
112
|
+
* itself is `/reload-plugins`, this only decides when.
|
|
113
|
+
*/
|
|
114
|
+
async function watchDiscoveryRoots(): Promise<void> {
|
|
115
|
+
try {
|
|
116
|
+
await syncDiscoveryRootsWatch();
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error('[discovery-watch] watcher setup skipped:', error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Bring installed BUNDLED plugins up to the copy this package ships.
|
|
124
|
+
*
|
|
125
|
+
* A Kabmo update replaces the store and leaves the install — it is a copied
|
|
126
|
+
* directory of ordinary files — so this is the only thing that notices. An
|
|
127
|
+
* install Kabmo wrote is compared by CONTENT, so a shipped fix applies even when
|
|
128
|
+
* its version did not move; a directory of unknown provenance keeps the version
|
|
129
|
+
* gate, and git clones are skipped, so a plugin the user installed from a URL is
|
|
130
|
+
* never overwritten by a store entry that happens to share its id.
|
|
131
|
+
*/
|
|
132
|
+
async function syncBundledPluginsAndReport(): Promise<void> {
|
|
133
|
+
try {
|
|
134
|
+
const synced = await syncBundledPlugins();
|
|
135
|
+
for (const item of synced.updated) {
|
|
136
|
+
// A content-only sync has no version to show, and printing `1.0.0 → 1.0.0`
|
|
137
|
+
// would read as a no-op when a shipped fix actually landed.
|
|
138
|
+
const span = item.contentOnly ? `${item.to} (content changed, version unchanged)` : `${item.from} → ${item.to}`;
|
|
139
|
+
console.log(`[kabmo] plugins: synced ${item.pluginId} ${span}`);
|
|
140
|
+
if (item.warning) console.error(`[plugins] ${item.pluginId}: rebuild after sync failed — ${item.warning}`);
|
|
141
|
+
}
|
|
142
|
+
for (const failure of synced.failed) console.error(`[plugins] ${failure.pluginId}: bundled sync failed — ${failure.error}`);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error('[plugins] bundled sync skipped:', error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The plugin platform's server half. After the listener is up, the scheduled-task
|
|
150
|
+
* clock exists — a plugin's own schedules register with that runtime — and the
|
|
151
|
+
* bundled sync ran, so the module imported here is the copy this package ships.
|
|
152
|
+
* Never throws: one broken plugin must not stop the boot, and its reason is
|
|
153
|
+
* reported here and by `GET /api/plugins`.
|
|
154
|
+
*/
|
|
155
|
+
async function loadPluginServerHalves(): Promise<void> {
|
|
156
|
+
try {
|
|
157
|
+
const result = await loadPluginServers();
|
|
158
|
+
if (result.loaded.length > 0) {
|
|
159
|
+
console.log(`[kabmo] plugins: ${result.loaded.length} server half(s) loaded (${result.loaded.join(', ')})`);
|
|
160
|
+
}
|
|
161
|
+
for (const failure of result.errors) console.error(`[plugins] ${failure.pluginId}: ${failure.reason}`);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('[plugins] server halves skipped:', error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The tray icon, when `--tray` was passed (`serve --tray`, or the login entry the
|
|
169
|
+
* CLI writes for `--startup`). After the listener is up, because the config
|
|
170
|
+
* carries the URL the icon opens. Never throws: a machine with no tray client
|
|
171
|
+
* (Linux without yad/zenity) reports why and keeps serving.
|
|
172
|
+
*/
|
|
173
|
+
function startTray(target: AfterListenTarget): void {
|
|
174
|
+
if (!isTrayEnabledByArgv()) return;
|
|
175
|
+
const result = ensureTray({ ...target, pkgRoot: packageDir() });
|
|
176
|
+
if (result.started) console.log('[kabmo] tray: icon shown');
|
|
177
|
+
else console.log(`[kabmo] tray: not shown — ${result.reason}`);
|
|
178
|
+
}
|
|
@@ -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;
|