@kabmo-labs/kabmo 0.18.0 → 0.19.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/README.md +10 -7
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +475 -474
- package/dist/client/static/js/{index-tc09dtca.js → index-fcee4c13.js} +766 -765
- package/dist/client/static/js/index-sxdw908m.css +1 -0
- package/marketplace/plugins/command-runner/package.json +3 -2
- package/marketplace/plugins/git-forge/package.json +3 -2
- package/marketplace/plugins/session-info/package.json +3 -2
- package/marketplace/plugins/stats/package.json +3 -2
- package/package.json +3 -1
- package/src/client/components/auth/login-screen/index.tsx +2 -1
- package/src/client/components/common/ComposerPicker.tsx +1 -1
- package/src/client/components/common/FolderPicker.tsx +2 -2
- package/src/client/components/common/Modal.tsx +2 -2
- package/src/client/components/common/PWAInstallButton.tsx +2 -2
- package/src/client/components/common/ViewportSelector.tsx +1 -1
- package/src/client/components/common/anchored-menu/index.tsx +5 -1
- package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
- package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
- package/src/client/components/common/brand-wordmark/index.tsx +13 -2
- package/src/client/components/common/checkbox/style.test.ts +139 -0
- package/src/client/components/common/checkbox/style.ts +51 -0
- package/src/client/components/common/context-usage-button/index.tsx +2 -2
- package/src/client/components/common/file-icon/index.tsx +23 -9
- package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +1 -1
- package/src/client/components/common/panel-mark/index.tsx +97 -0
- package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
- package/src/client/components/common/provider-icon/index.test.ts +14 -0
- package/src/client/components/common/provider-icon/index.tsx +4 -0
- package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
- package/src/client/components/common/provider-icon/resolve.ts +16 -3
- package/src/client/components/common/session-actions-menu/index.tsx +1 -1
- package/src/client/components/common/toolbar-row/index.tsx +1 -1
- package/src/client/components/layout/ActivityBar.tsx +22 -3
- package/src/client/components/layout/LeftDock.tsx +9 -2
- package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
- package/src/client/components/layout/WindowAura.tsx +27 -0
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
- package/src/client/components/layout/desktop-layout/index.tsx +3 -1
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +3 -3
- package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
- package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
- package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -2
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +13 -5
- package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
- package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
- package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/mobile/panel-chips.tsx +10 -2
- package/src/client/components/settings/Modal.tsx +4 -4
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
- package/src/client/components/settings/apply-side-effects.test.ts +30 -0
- package/src/client/components/settings/apply-side-effects.ts +14 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +2 -1
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +2 -2
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +51 -2
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +43 -10
- package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
- package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +2 -1
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +1 -1
- package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
- package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
- package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
- package/src/client/components/workspace/diff-panel/index.tsx +2 -2
- package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
- package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
- package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
- package/src/client/components/workspace/editor/Tabs.tsx +1 -1
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
- package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
- package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
- package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
- package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
- package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
- package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
- package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
- package/src/client/components/workspace/git-panel/index.tsx +7 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
- package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
- package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
- package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
- package/src/client/components/workspace/search-panel/Body.tsx +1 -1
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
- package/src/client/glass.css +785 -0
- package/src/client/glass.test.ts +346 -0
- package/src/client/hooks/ui/glass-support.ts +57 -0
- package/src/client/hooks/ui/icon-style.ts +59 -0
- package/src/client/hooks/ui/stuck-header.test.ts +188 -0
- package/src/client/hooks/ui/stuck-header.ts +91 -0
- package/src/client/hooks/ui/style-attributes.test.ts +120 -0
- package/src/client/hooks/ui/surface-style.ts +56 -0
- package/src/client/hooks/workspace/panel-hues.ts +23 -0
- package/src/client/main.tsx +10 -0
- package/src/client/tailwind.css +264 -11
- package/src/server/lib/assets/shell-attributes.server.ts +80 -0
- package/src/server/lib/assets/shell-attributes.test.ts +86 -0
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
- package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
- package/src/server/lib/omp/rpc/manager.ts +2 -2
- package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
- package/src/server/lib/omp/rpc/process.test.ts +106 -0
- package/src/server/lib/omp/rpc/process.ts +28 -4
- package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
- package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
- package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
- package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
- package/src/server/lib/omp/rpc/session-commands.ts +11 -0
- package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
- package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
- package/src/server/lib/panels/manifest.test.ts +20 -0
- package/src/server/lib/panels/manifest.ts +12 -0
- package/src/server/lib/panels/scan.server.ts +4 -0
- package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
- package/src/server/lib/queue/delivery-harness.ts +8 -4
- package/src/server/lib/queue/delivery.server.test.ts +29 -0
- package/src/server/lib/queue/delivery.server.ts +39 -0
- package/src/server/lib/queue/store.server.test.ts +22 -2
- package/src/server/lib/queue/store.server.ts +33 -11
- package/src/server/plugins/ssr.ts +22 -5
- package/src/shared/lib/icons/file-brand-color.ts +38 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +234 -0
- package/src/shared/lib/icons/icon-paint-css.ts +284 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +100 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +230 -0
- package/src/shared/lib/icons/tint.test.ts +273 -0
- package/src/shared/lib/icons/tint.ts +219 -0
- package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
- package/src/shared/lib/models/provider/brand-color.ts +103 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +65 -0
- package/src/shared/lib/omp/rpc/frame.ts +58 -3
- package/src/shared/lib/settings/defaults.ts +4 -0
- package/src/shared/lib/theme/catalog.test.ts +5 -4
- package/src/shared/lib/theme/catalog.ts +18 -3
- package/src/shared/lib/theme/glass-support.test.ts +38 -0
- package/src/shared/lib/theme/glass-support.ts +73 -0
- package/src/shared/lib/theme/icon-style.test.ts +74 -0
- package/src/shared/lib/theme/icon-style.ts +90 -0
- package/src/shared/lib/theme/legibility.ts +91 -0
- package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
- package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
- package/src/shared/lib/theme/surface-style.test.ts +68 -0
- package/src/shared/lib/theme/surface-style.ts +91 -0
- package/src/shared/lib/theme/theme.test.ts +11 -7
- package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
- package/src/shared/lib/workspace/panel-hues.ts +57 -0
- package/src/shared/types/panels-registry.ts +6 -0
- package/src/shared/types/panels.ts +14 -0
- package/src/shared/types/settings/state.ts +26 -0
- package/src/test-support/fake-omp-frames.ts +163 -0
- package/dist/client/static/js/index-hp75vsv9.css +0 -1
- /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `<html>` attributes of the served shell, written in one place.
|
|
8
|
+
*
|
|
9
|
+
* `index.html` is a static template that every request rewrites, and the
|
|
10
|
+
* attributes it carries are the FIRST FRAME's whole appearance: the palette, the
|
|
11
|
+
* surface material and the brand-mark paint. A second replacement pass for the
|
|
12
|
+
* two new attributes was one `String.replace` away from silently missing — a
|
|
13
|
+
* missing attribute is not an error, it is the default look — so all four are
|
|
14
|
+
* stated together, in a function a test can call without rendering the shell.
|
|
15
|
+
*
|
|
16
|
+
* Two properties are load-bearing:
|
|
17
|
+
*
|
|
18
|
+
* - **`data-theme` and `data-theme-variant` are ALWAYS written.** They are the
|
|
19
|
+
* palette; `applyDocumentTheme` owns them after hydration, and a document
|
|
20
|
+
* served without them keeps `:root`'s shipped palette.
|
|
21
|
+
* - **The two style attributes are written only when they are not the default.**
|
|
22
|
+
* `applySurfaceStyle` / `applyIconStyle` remove the attribute for the default,
|
|
23
|
+
* so emitting `data-surface="classic"` here would make the server and the
|
|
24
|
+
* client disagree about the document's own state — and every CSS rule keys on
|
|
25
|
+
* the value, not on its absence.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { ThemePalette } from '@/shared/types/theme';
|
|
29
|
+
import {
|
|
30
|
+
DEFAULT_ICON_STYLE,
|
|
31
|
+
ICON_STYLE_ATTRIBUTE,
|
|
32
|
+
resolveIconStyle,
|
|
33
|
+
} from '@/shared/lib/theme/icon-style';
|
|
34
|
+
import {
|
|
35
|
+
DEFAULT_SURFACE_STYLE,
|
|
36
|
+
SURFACE_ATTRIBUTE,
|
|
37
|
+
resolveSurfaceStyle,
|
|
38
|
+
} from '@/shared/lib/theme/surface-style';
|
|
39
|
+
|
|
40
|
+
export interface ShellDocumentFacts {
|
|
41
|
+
palette: ThemePalette;
|
|
42
|
+
/** The stored surface style, unresolved — any value this build cannot draw
|
|
43
|
+
* falls to the default rather than to an attribute no rule matches. */
|
|
44
|
+
surfaceStyle: unknown;
|
|
45
|
+
iconStyle: unknown;
|
|
46
|
+
/** The `<meta name="theme-color">` value for this request. */
|
|
47
|
+
chromeColor: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The template's own values, which the replacements below look for. */
|
|
51
|
+
const TEMPLATE_THEME = 'data-theme="paper"';
|
|
52
|
+
const TEMPLATE_VARIANT = 'data-theme-variant="light"';
|
|
53
|
+
const TEMPLATE_META = '<meta name="theme-color" content="#faf8f3" />';
|
|
54
|
+
|
|
55
|
+
/** The extra `<html>` attributes for the stored presentation styles. */
|
|
56
|
+
export function styleAttributes(surfaceStyle: unknown, iconStyle: unknown): string {
|
|
57
|
+
const surface = resolveSurfaceStyle(surfaceStyle);
|
|
58
|
+
const icon = resolveIconStyle(iconStyle);
|
|
59
|
+
const parts: string[] = [];
|
|
60
|
+
if (surface !== DEFAULT_SURFACE_STYLE) parts.push(`${SURFACE_ATTRIBUTE}="${surface}"`);
|
|
61
|
+
if (icon !== DEFAULT_ICON_STYLE) parts.push(`${ICON_STYLE_ATTRIBUTE}="${icon}"`);
|
|
62
|
+
return parts.length > 0 ? ` ${parts.join(' ')}` : '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Rewrite the template's palette and chrome placeholders for one request.
|
|
67
|
+
*
|
|
68
|
+
* Returns the html unchanged for a document that predates the markers — the
|
|
69
|
+
* client's `initDocumentTheme` / `initSurfaceStyle` repair that case, which is
|
|
70
|
+
* why this does not throw: a stale template must still serve a page.
|
|
71
|
+
*/
|
|
72
|
+
export function applyShellDocumentFacts(html: string, facts: ShellDocumentFacts): string {
|
|
73
|
+
return html
|
|
74
|
+
.replace(
|
|
75
|
+
TEMPLATE_THEME,
|
|
76
|
+
`data-theme="${facts.palette.id}"${styleAttributes(facts.surfaceStyle, facts.iconStyle)}`,
|
|
77
|
+
)
|
|
78
|
+
.replace(TEMPLATE_VARIANT, `data-theme-variant="${facts.palette.variant}"`)
|
|
79
|
+
.replace(TEMPLATE_META, `<meta name="theme-color" content="${facts.chromeColor}" />`);
|
|
80
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The first frame's `<html>` attributes.
|
|
8
|
+
*
|
|
9
|
+
* The rule worth pinning is the ASYMMETRY: the palette is always written, and
|
|
10
|
+
* the two presentation styles are written only when they are not the default —
|
|
11
|
+
* because the client's writers REMOVE the attribute for the default, and a
|
|
12
|
+
* server that emitted `data-surface="classic"` would leave a document the
|
|
13
|
+
* client thinks is "explicitly classic" and a reload flipping between two
|
|
14
|
+
* spellings of the same state.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, expect, test } from 'bun:test';
|
|
18
|
+
import {
|
|
19
|
+
applyShellDocumentFacts,
|
|
20
|
+
styleAttributes,
|
|
21
|
+
} from '@/server/lib/assets/shell-attributes.server';
|
|
22
|
+
import { KABMO_PALETTES } from '@/shared/lib/theme/palettes/kabmo';
|
|
23
|
+
|
|
24
|
+
const TEMPLATE = `<html lang="en" data-theme="paper" data-theme-variant="light">
|
|
25
|
+
<head>
|
|
26
|
+
<meta name="theme-color" content="#faf8f3" />
|
|
27
|
+
</head>
|
|
28
|
+
</html>`;
|
|
29
|
+
|
|
30
|
+
const dark = KABMO_PALETTES[0];
|
|
31
|
+
|
|
32
|
+
describe('styleAttributes', () => {
|
|
33
|
+
test('the defaults add nothing at all', () => {
|
|
34
|
+
expect(styleAttributes('classic', 'monochrome')).toBe('');
|
|
35
|
+
expect(styleAttributes(undefined, undefined)).toBe('');
|
|
36
|
+
expect(styleAttributes('nonsense', 'nonsense')).toBe('');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('each non-default style contributes its own attribute', () => {
|
|
40
|
+
expect(styleAttributes('glass', 'monochrome')).toBe(' data-surface="glass"');
|
|
41
|
+
expect(styleAttributes('classic', 'color')).toBe(' data-icon-style="color"');
|
|
42
|
+
expect(styleAttributes('glass', 'color')).toBe(' data-surface="glass" data-icon-style="color"');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('applyShellDocumentFacts', () => {
|
|
47
|
+
test('writes the palette and the chrome colour, and nothing else by default', () => {
|
|
48
|
+
const html = applyShellDocumentFacts(TEMPLATE, {
|
|
49
|
+
palette: dark,
|
|
50
|
+
surfaceStyle: undefined,
|
|
51
|
+
iconStyle: undefined,
|
|
52
|
+
chromeColor: '#123456',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(html).toContain(`<html lang="en" data-theme="${dark.id}" data-theme-variant="${dark.variant}">`);
|
|
56
|
+
expect(html).toContain('<meta name="theme-color" content="#123456" />');
|
|
57
|
+
expect(html).not.toContain('data-surface');
|
|
58
|
+
expect(html).not.toContain('data-icon-style');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a stored glass style lands on the FIRST frame, not after hydration', () => {
|
|
62
|
+
const html = applyShellDocumentFacts(TEMPLATE, {
|
|
63
|
+
palette: dark,
|
|
64
|
+
surfaceStyle: 'glass',
|
|
65
|
+
iconStyle: 'color',
|
|
66
|
+
chromeColor: '#123456',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(html).toContain(
|
|
70
|
+
`<html lang="en" data-theme="${dark.id}" data-surface="glass" data-icon-style="color" data-theme-variant="${dark.variant}">`,
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a document without the template markers is returned untouched, not thrown', () => {
|
|
75
|
+
const stale = '<html><head></head><body>an older build</body></html>';
|
|
76
|
+
|
|
77
|
+
expect(
|
|
78
|
+
applyShellDocumentFacts(stale, {
|
|
79
|
+
palette: dark,
|
|
80
|
+
surfaceStyle: 'glass',
|
|
81
|
+
iconStyle: 'color',
|
|
82
|
+
chromeColor: '#123456',
|
|
83
|
+
}),
|
|
84
|
+
).toBe(stale);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -29,6 +29,7 @@ export function makeHost(overrides: Partial<SessionFrameHost> = {}): SessionFram
|
|
|
29
29
|
promptRunning: false,
|
|
30
30
|
streaming: false,
|
|
31
31
|
compacting: false,
|
|
32
|
+
runAborted: false,
|
|
32
33
|
awaitingAgentStart: false,
|
|
33
34
|
awaitingAgentStartDeadline: 0,
|
|
34
35
|
continuationGraceUntil: 0,
|
|
@@ -25,37 +25,9 @@
|
|
|
25
25
|
|
|
26
26
|
import { describe, expect, test } from 'bun:test';
|
|
27
27
|
|
|
28
|
-
import { foldSessionFrame
|
|
28
|
+
import { foldSessionFrame } from '@/server/lib/omp/rpc/frame-fold';
|
|
29
|
+
import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
|
|
29
30
|
import { onRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
30
|
-
import { ModeMirror } from '@/server/lib/omp/rpc/mode-mirror';
|
|
31
|
-
|
|
32
|
-
/** The same minimal host the sibling suite uses. */
|
|
33
|
-
function makeHost(overrides: Partial<SessionFrameHost> = {}): SessionFrameHost {
|
|
34
|
-
return {
|
|
35
|
-
sessionId: '',
|
|
36
|
-
autoTitleWindowUntil: 0,
|
|
37
|
-
autoTitleClaims: 0,
|
|
38
|
-
autoTitleDispatch: null,
|
|
39
|
-
autoTitlePending: true,
|
|
40
|
-
autoTitleRequested: false,
|
|
41
|
-
promptRunning: false,
|
|
42
|
-
streaming: false,
|
|
43
|
-
compacting: false,
|
|
44
|
-
awaitingAgentStart: false,
|
|
45
|
-
awaitingAgentStartDeadline: 0,
|
|
46
|
-
continuationGraceUntil: 0,
|
|
47
|
-
proc: { sendCommand: async () => undefined as never },
|
|
48
|
-
emit() {},
|
|
49
|
-
trackUiDialog() {},
|
|
50
|
-
observeSubagent() {},
|
|
51
|
-
syncRunModel() {},
|
|
52
|
-
modeMirror: new ModeMirror(),
|
|
53
|
-
isAlive: () => true,
|
|
54
|
-
isBusy: () => false,
|
|
55
|
-
send: async () => undefined,
|
|
56
|
-
...overrides,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
31
|
|
|
60
32
|
/**
|
|
61
33
|
* The `tool_execution_end` frame is what moves a running session's sidebar row
|
|
@@ -119,6 +119,61 @@ describe('auto-title trigger wiring', () => {
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
+
describe('the abort verdict survives agent_end compaction', () => {
|
|
123
|
+
test('an aborted assistant message is remembered before agent_end trims it', () => {
|
|
124
|
+
// omp drops the messages it already delivered via `message_end` when the
|
|
125
|
+
// terminal frame is oversized, and the aborted assistant message is one of
|
|
126
|
+
// them — so reading the verdict from `agent_end.messages` alone reports a
|
|
127
|
+
// stopped run as finished. Measured on 18.16.0: `message_end`
|
|
128
|
+
// (role=assistant, stopReason=aborted) arrives BEFORE `agent_end`.
|
|
129
|
+
const host = makeHost();
|
|
130
|
+
fold(host, { type: 'agent_start' });
|
|
131
|
+
fold(host, { type: 'message_end', message: { role: 'user', content: 'go' } });
|
|
132
|
+
fold(host, { type: 'message_end', message: { role: 'assistant', stopReason: 'aborted' } });
|
|
133
|
+
|
|
134
|
+
expect(host.runAborted).toBe(true);
|
|
135
|
+
|
|
136
|
+
// The compacted terminal frame: everything streamed, nothing left to carry
|
|
137
|
+
// the stopReason.
|
|
138
|
+
fold(host, { type: 'agent_end', isTerminal: true, messages: [], messageCount: 2 });
|
|
139
|
+
|
|
140
|
+
// A stopped turn is not a settle, so the title latch must survive.
|
|
141
|
+
expect(host.autoTitlePending).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('a natural stop is not remembered as an abort', () => {
|
|
145
|
+
const host = makeHost();
|
|
146
|
+
fold(host, { type: 'agent_start' });
|
|
147
|
+
fold(host, { type: 'message_end', message: { role: 'assistant', stopReason: 'stop' } });
|
|
148
|
+
|
|
149
|
+
expect(host.runAborted).toBe(false);
|
|
150
|
+
fold(host, { type: 'agent_end', isTerminal: true, messages: [] });
|
|
151
|
+
expect(host.autoTitlePending).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('a new run starts un-aborted', () => {
|
|
155
|
+
const host = makeHost();
|
|
156
|
+
fold(host, { type: 'agent_start' });
|
|
157
|
+
fold(host, { type: 'message_end', message: { role: 'assistant', stopReason: 'aborted' } });
|
|
158
|
+
expect(host.runAborted).toBe(true);
|
|
159
|
+
|
|
160
|
+
fold(host, { type: 'agent_start' });
|
|
161
|
+
expect(host.runAborted).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('the frame is still read for a host that attached mid-run', () => {
|
|
165
|
+
// A synthetic terminal frame (`run-settle.server.ts`) carries no
|
|
166
|
+
// `message_end` history, so the array remains the fallback source.
|
|
167
|
+
const host = makeHost();
|
|
168
|
+
fold(host, {
|
|
169
|
+
type: 'agent_end',
|
|
170
|
+
isTerminal: true,
|
|
171
|
+
messages: [{ role: 'assistant', stopReason: 'aborted' }],
|
|
172
|
+
});
|
|
173
|
+
expect(host.autoTitlePending).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
122
177
|
/**
|
|
123
178
|
* The Kabmo's own background `/rename` answers on `prompt_result` with
|
|
124
179
|
* `agentInvoked:false` — auto-title fires it right after the first settled user
|
|
@@ -46,6 +46,8 @@ export interface SessionFrameHost extends AutoTitleHost, QueueDeliveryHost {
|
|
|
46
46
|
promptRunning: boolean;
|
|
47
47
|
streaming: boolean;
|
|
48
48
|
compacting: boolean;
|
|
49
|
+
/** Abort verdict of the current run — see `endedAborted` in `terminal-settle.ts`. */
|
|
50
|
+
runAborted: boolean;
|
|
49
51
|
awaitingAgentStart: boolean;
|
|
50
52
|
awaitingAgentStartDeadline: number;
|
|
51
53
|
continuationGraceUntil: number;
|
|
@@ -99,6 +101,7 @@ export interface FrameFoldResult {
|
|
|
99
101
|
*/
|
|
100
102
|
function handleMessageEnd(host: SessionFrameHost, event: AgentEvent): void {
|
|
101
103
|
const message = event.message as Record<string, unknown> | undefined;
|
|
104
|
+
if (message?.role === 'assistant' && message.stopReason === 'aborted') host.runAborted = true;
|
|
102
105
|
if (message?.role === 'user') void triggerAutoSessionTitle(host, 'opening');
|
|
103
106
|
else if (message?.role === 'custom' && message.customType === SKILL_PROMPT_CUSTOM_TYPE) {
|
|
104
107
|
void triggerAutoSessionTitle(host, 'opening');
|
|
@@ -188,6 +191,7 @@ export function foldSessionFrame(host: SessionFrameHost, event: AgentEvent): Fra
|
|
|
188
191
|
case 'agent_start':
|
|
189
192
|
host.promptRunning = true;
|
|
190
193
|
host.streaming = true;
|
|
194
|
+
host.runAborted = false;
|
|
191
195
|
host.awaitingAgentStart = false;
|
|
192
196
|
host.awaitingAgentStartDeadline = 0;
|
|
193
197
|
host.continuationGraceUntil = 0;
|
|
@@ -52,8 +52,7 @@ export class AgentSessionWrapper {
|
|
|
52
52
|
promptDispatchPendingCount = 0;
|
|
53
53
|
awaitingAgentStart = false;
|
|
54
54
|
awaitingAgentStartDeadline = 0;
|
|
55
|
-
/** Watches the deadline above so a dispatch
|
|
56
|
-
* strand the session (see `AgentStartWatchdog`). */
|
|
55
|
+
/** Watches the deadline above so a stranded dispatch is settled (`AgentStartWatchdog`). */
|
|
57
56
|
private readonly agentStartWatchdog: AgentStartWatchdog;
|
|
58
57
|
/** Settles a run omp no longer owns (see `run-settle.server.ts`). */
|
|
59
58
|
readonly runSettle: RunSettle;
|
|
@@ -61,6 +60,7 @@ export class AgentSessionWrapper {
|
|
|
61
60
|
bashRunning = false;
|
|
62
61
|
streaming = false;
|
|
63
62
|
compacting = false;
|
|
63
|
+
runAborted = false;
|
|
64
64
|
fastModeEnabled = false;
|
|
65
65
|
runModel: SessionRunModel | null = null;
|
|
66
66
|
private onDestroyCallback: (() => void) | null = null;
|
|
@@ -68,3 +68,14 @@ export interface RpcProcessOptions {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export const STDERR_TAIL_LIMIT = 8 * 1024;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* How many transport notices one child may push before the reader stops
|
|
74
|
+
* repeating itself.
|
|
75
|
+
*
|
|
76
|
+
* A malformed chunk sequence is recoverable (the logical frame is lost, the
|
|
77
|
+
* session is not), but a server stuck emitting invalid chunks would otherwise
|
|
78
|
+
* append a notice per line and bury the transcript. Three is enough to prove
|
|
79
|
+
* the fault is real; the stderr tail keeps the full account for diagnostics.
|
|
80
|
+
*/
|
|
81
|
+
export const MAX_PROTOCOL_ERROR_NOTICES = 3;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The transport faults `RpcProcess` has to survive.
|
|
8
|
+
*
|
|
9
|
+
* Two behaviours are pinned here, and neither can be observed against a real
|
|
10
|
+
* child (omp 18.16.0 advertises one set of ceilings and never emits a malformed
|
|
11
|
+
* chunk), so the scripted child says what the test needs:
|
|
12
|
+
*
|
|
13
|
+
* - **The ceilings come from `ready`.** The same chunk record is valid under
|
|
14
|
+
* the default 1 MiB physical ceiling and invalid under an advertised 4 MiB
|
|
15
|
+
* one — a 2 MiB logical frame is never chunked at 4 MiB — so the two runs
|
|
16
|
+
* differ only in what the server advertised.
|
|
17
|
+
* - **A malformed chunk sequence does not kill the session.** It used to call
|
|
18
|
+
* `dispose(0)`, which took the child's LSP servers, browser targets and
|
|
19
|
+
* prewarm slot down for a transport fault; now the reader reports a notice,
|
|
20
|
+
* loses that one logical frame, and keeps answering.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { afterEach, expect, test } from 'bun:test';
|
|
24
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
25
|
+
import { tmpdir } from 'node:os';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
|
|
28
|
+
import { describePosix } from '@/test-support/platform';
|
|
29
|
+
import { RpcProcess, type RpcFrame } from '@/server/lib/omp/rpc/process';
|
|
30
|
+
|
|
31
|
+
const FAKE_OMP = join(import.meta.dir, '../../../../test-support/fake-omp-frames.ts');
|
|
32
|
+
|
|
33
|
+
const started: RpcProcess[] = [];
|
|
34
|
+
let root = '';
|
|
35
|
+
|
|
36
|
+
function start(env: Record<string, string>): { proc: RpcProcess; frames: RpcFrame[] } {
|
|
37
|
+
root ||= mkdtempSync(join(tmpdir(), 'omp-frames-test-'));
|
|
38
|
+
const frames: RpcFrame[] = [];
|
|
39
|
+
const proc = new RpcProcess({
|
|
40
|
+
cwd: root,
|
|
41
|
+
env,
|
|
42
|
+
onFrame: (frame) => frames.push(frame),
|
|
43
|
+
dependencies: { resolveOmpBin: () => FAKE_OMP },
|
|
44
|
+
});
|
|
45
|
+
started.push(proc);
|
|
46
|
+
return { proc, frames };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Ready + v2 negotiation, the state every chunk test needs. */
|
|
50
|
+
async function negotiated(env: Record<string, string>): Promise<{ proc: RpcProcess; frames: RpcFrame[] }> {
|
|
51
|
+
const { proc, frames } = start(env);
|
|
52
|
+
const ready = await proc.waitReady(20_000);
|
|
53
|
+
await proc.negotiateProtocol(ready);
|
|
54
|
+
return { proc, frames };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
afterEach(async () => {
|
|
58
|
+
for (const proc of started.splice(0)) await proc.dispose(500);
|
|
59
|
+
if (root) {
|
|
60
|
+
rmSync(root, { recursive: true, force: true });
|
|
61
|
+
root = '';
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describePosix('RpcProcess framing', () => {
|
|
66
|
+
test('the advertised frame ceiling is what the decoder applies', async () => {
|
|
67
|
+
// 4 MiB advertised: a 2 MiB logical frame is below it, so it would never be
|
|
68
|
+
// chunked — the record is a protocol fault and must be reported, once.
|
|
69
|
+
const { proc, frames } = await negotiated({
|
|
70
|
+
FAKE_OMP_READY_MAX_FRAME_BYTES: String(4 * 1024 * 1024),
|
|
71
|
+
FAKE_OMP_CHUNK: 'valid-1mib',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const result = await proc.sendCommand<{ exitCode?: number }>({ type: 'bash', command: 'true' }, 20_000);
|
|
75
|
+
|
|
76
|
+
// The response still arrived: the reader continued past the bad record.
|
|
77
|
+
expect(result.exitCode).toBe(0);
|
|
78
|
+
const notices = frames.filter((frame) => frame.type === 'notice');
|
|
79
|
+
expect(notices).toHaveLength(1);
|
|
80
|
+
expect(String(notices[0].message)).toContain('malformed RPC frame');
|
|
81
|
+
expect(proc.isAlive).toBe(true);
|
|
82
|
+
}, 30_000);
|
|
83
|
+
|
|
84
|
+
test('the same record is accepted under the default ceiling', async () => {
|
|
85
|
+
// Control for the test above: identical bytes, no advertised override. The
|
|
86
|
+
// record is a valid FIRST slice, so nothing is reported and nothing is lost.
|
|
87
|
+
const { proc, frames } = await negotiated({ FAKE_OMP_CHUNK: 'valid-1mib' });
|
|
88
|
+
|
|
89
|
+
const result = await proc.sendCommand<{ exitCode?: number }>({ type: 'bash', command: 'true' }, 20_000);
|
|
90
|
+
|
|
91
|
+
expect(result.exitCode).toBe(0);
|
|
92
|
+
expect(frames.filter((frame) => frame.type === 'notice')).toHaveLength(0);
|
|
93
|
+
}, 30_000);
|
|
94
|
+
|
|
95
|
+
test('a malformed sequence costs one frame, not the child', async () => {
|
|
96
|
+
const { proc, frames } = await negotiated({ FAKE_OMP_CHUNK: 'bad-index' });
|
|
97
|
+
|
|
98
|
+
await proc.sendCommand({ type: 'bash', command: 'true' }, 20_000);
|
|
99
|
+
expect(frames.filter((frame) => frame.type === 'notice')).toHaveLength(1);
|
|
100
|
+
|
|
101
|
+
// The session is still there: a later command is answered by the SAME child.
|
|
102
|
+
const state = await proc.sendCommand<{ sessionId?: string }>({ type: 'get_state' }, 20_000);
|
|
103
|
+
expect(state.sessionId).toBe('fake-session');
|
|
104
|
+
expect(proc.isAlive).toBe(true);
|
|
105
|
+
}, 30_000);
|
|
106
|
+
});
|
|
@@ -20,9 +20,10 @@ import { signalName, stripKabmoHostEnv } from '@kabmo-labs/kabmo-sdk';
|
|
|
20
20
|
import { describeSpawnFailure } from '@/server/lib/lifecycle/fd-pressure';
|
|
21
21
|
import { resolveOmpBin } from '@/server/lib/omp/core/cli';
|
|
22
22
|
import { RpcFrameDecoder, encodeRpcFrameLine, type RpcFrameRecord, type RpcProtocolVersion } from '@/shared/lib/omp/rpc/frame';
|
|
23
|
+
import { isRecord } from '@/shared/lib/util/guards';
|
|
23
24
|
import { killProcessTree } from '@/server/lib/lifecycle/kill-tree';
|
|
24
25
|
import { readLines } from '@/server/lib/omp/rpc/lines';
|
|
25
|
-
import { RpcCommandError, RpcCommandTimeoutError, STDERR_TAIL_LIMIT, type PendingCommand, type RpcFrame, type RpcProcessOptions, type RpcResponseFrame } from '@/server/lib/omp/rpc/process-helpers';
|
|
26
|
+
import { MAX_PROTOCOL_ERROR_NOTICES, RpcCommandError, RpcCommandTimeoutError, STDERR_TAIL_LIMIT, type PendingCommand, type RpcFrame, type RpcProcessOptions, type RpcResponseFrame } from '@/server/lib/omp/rpc/process-helpers';
|
|
26
27
|
|
|
27
28
|
export { RpcCommandError, RpcCommandTimeoutError } from '@/server/lib/omp/rpc/process-helpers';
|
|
28
29
|
export type { RpcFrame, RpcProcessOptions, RpcResponseFrame } from '@/server/lib/omp/rpc/process-helpers';
|
|
@@ -90,6 +91,7 @@ export class RpcProcess {
|
|
|
90
91
|
this.readyPromise.catch(() => {});
|
|
91
92
|
|
|
92
93
|
const decoder = new RpcFrameDecoder();
|
|
94
|
+
let protocolErrorNotices = 0;
|
|
93
95
|
void readLines(this.child.stdout, (line) => {
|
|
94
96
|
const trimmed = line.trim();
|
|
95
97
|
if (!trimmed) return;
|
|
@@ -102,18 +104,40 @@ export class RpcProcess {
|
|
|
102
104
|
}
|
|
103
105
|
let frame: RpcFrameRecord;
|
|
104
106
|
try {
|
|
105
|
-
if (parsed &&
|
|
107
|
+
if (isRecord(parsed) && parsed.type === 'rpc_chunk' && this.protocolVersion !== 2) {
|
|
106
108
|
throw new Error('RPC chunk received before protocol negotiation');
|
|
107
109
|
}
|
|
108
110
|
const decoded = decoder.push(parsed);
|
|
109
111
|
if (!decoded) return;
|
|
110
112
|
frame = decoded;
|
|
111
113
|
} catch (error) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
// A malformed chunk sequence costs ONE logical frame, not the session:
|
|
115
|
+
// killing the child took its LSP servers, browser targets and prewarm
|
|
116
|
+
// slot down for a transport fault. Report the lost event, then resync.
|
|
117
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
118
|
+
decoder.resync();
|
|
119
|
+
this.stderrTail = (this.stderrTail + `\nRPC protocol error: ${detail}`).slice(-STDERR_TAIL_LIMIT);
|
|
120
|
+
if (protocolErrorNotices < MAX_PROTOCOL_ERROR_NOTICES) {
|
|
121
|
+
protocolErrorNotices++;
|
|
122
|
+
const notice: RpcFrame = {
|
|
123
|
+
type: 'notice',
|
|
124
|
+
level: 'warning',
|
|
125
|
+
message: `OMP sent a malformed RPC frame (${detail}). One event was dropped; the session is still running.`,
|
|
126
|
+
};
|
|
127
|
+
for (const listener of this.frameListeners) {
|
|
128
|
+
try {
|
|
129
|
+
listener(notice);
|
|
130
|
+
} catch {}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
114
133
|
return;
|
|
115
134
|
}
|
|
116
135
|
if (frame.type === 'ready') {
|
|
136
|
+
// The server's own ceilings, which may grow without a protocol bump.
|
|
137
|
+
decoder.setLimits({
|
|
138
|
+
maxFrameBytes: frame.maxFrameBytes,
|
|
139
|
+
maxReassembledFrameBytes: frame.maxReassembledFrameBytes,
|
|
140
|
+
});
|
|
117
141
|
resolveReady(frame);
|
|
118
142
|
return;
|
|
119
143
|
}
|
|
@@ -154,6 +154,18 @@ export class RunSettle {
|
|
|
154
154
|
this.#quietUntil = 0;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Start watching a run the frame path did not announce.
|
|
159
|
+
*
|
|
160
|
+
* A refused dispatch (`agent_busy`) proves a turn is in flight even when this
|
|
161
|
+
* wrapper read idle. The wrapper records that verdict in its own flags, and
|
|
162
|
+
* this clock is what retires them again if the run's terminal frame never
|
|
163
|
+
* arrives — the same repair every other lost-frame run gets.
|
|
164
|
+
*/
|
|
165
|
+
arm(): void {
|
|
166
|
+
this.#arm();
|
|
167
|
+
}
|
|
168
|
+
|
|
157
169
|
/**
|
|
158
170
|
* Probe omp and settle the run when omp itself reports the session quiescent.
|
|
159
171
|
* Returns true when this call released a run.
|
|
@@ -213,6 +213,28 @@ describe('settling a run omp no longer owns', () => {
|
|
|
213
213
|
}
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
+
// A refusal is the only evidence some stranded runs ever leave: omp says a
|
|
217
|
+
// turn is in flight, the wrapper raised its flags from that verdict, and the
|
|
218
|
+
// terminal frame it expects may never arrive (that is what strands a queue —
|
|
219
|
+
// measured: 104 refusals in one session, one per retry). The clock is what
|
|
220
|
+
// retires the flags, exactly as it does for a lost terminal frame.
|
|
221
|
+
test('a run announced only by a refusal is settled on omp\'s quiescence verdict', async () => {
|
|
222
|
+
const { host, emitted } = makeHost(sessionState());
|
|
223
|
+
vi.useFakeTimers();
|
|
224
|
+
try {
|
|
225
|
+
const clock = settle(host, { silenceMs: 10 });
|
|
226
|
+
clock.arm();
|
|
227
|
+
vi.advanceTimersByTime(50);
|
|
228
|
+
await flushMicrotasks();
|
|
229
|
+
expect(host.streaming).toBe(false);
|
|
230
|
+
expect(host.promptRunning).toBe(false);
|
|
231
|
+
expect(emitted).toEqual([{ type: 'agent_end', isTerminal: true, messages: [] }]);
|
|
232
|
+
clock.stop();
|
|
233
|
+
} finally {
|
|
234
|
+
vi.useRealTimers();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
216
238
|
test('stop() cancels the clock', async () => {
|
|
217
239
|
const { host, sent } = makeHost(sessionState());
|
|
218
240
|
vi.useFakeTimers();
|
|
@@ -49,6 +49,11 @@ export interface SessionCommandHost extends WebStateHost {
|
|
|
49
49
|
/** Arm the deadline watchdog for a dispatch whose turn never opened. Optional
|
|
50
50
|
* so a test host can omit it; the real wrapper always implements it. */
|
|
51
51
|
armAgentStartWatchdog?(): void;
|
|
52
|
+
/** The run-settle clock. A refused dispatch (`agent_busy`) reveals a run this
|
|
53
|
+
* wrapper did not see open, so the clock must be armed for it or a lost
|
|
54
|
+
* terminal frame leaves the session marked busy forever. Optional for the
|
|
55
|
+
* same reason as the watchdog. */
|
|
56
|
+
runSettle?: { arm(): void };
|
|
52
57
|
/** The background `/rename` dispatch a following prompt must be ordered
|
|
53
58
|
* behind (see `session/title-request.server.ts`). Absent on a host that
|
|
54
59
|
* never titles, which is why the barrier treats it as idle. */
|
|
@@ -179,7 +179,8 @@ describe('prompt', () => {
|
|
|
179
179
|
});
|
|
180
180
|
|
|
181
181
|
test('a busy session refuses a retry, and omp\'s own mid-turn refusal is the typed `agent_busy`', async () => {
|
|
182
|
-
|
|
182
|
+
let settleArms = 0;
|
|
183
|
+
const h = makeHarness({ isBusy: () => true, runSettle: { arm: () => { settleArms += 1; } } });
|
|
183
184
|
h.respond(() => {
|
|
184
185
|
throw new RpcCommandTimeoutError('prompt', 1);
|
|
185
186
|
});
|
|
@@ -191,6 +192,13 @@ describe('prompt', () => {
|
|
|
191
192
|
h.respond(() => { throw new RpcCommandError('prompt', 'Agent is already processing.'); });
|
|
192
193
|
const busy = await rejectionOf(dispatchSessionCommand(h.host, { type: 'prompt', message: 'hi' })) as WebRpcError;
|
|
193
194
|
expect([busy.code, busy.message]).toEqual(['agent_busy', AGENT_BUSY_MESSAGE]);
|
|
195
|
+
// The refusal is proof of a live turn, and the wrapper must keep it: the
|
|
196
|
+
// queue's delivery gate and the sidebar both read these flags, so clearing
|
|
197
|
+
// them here is what let a session dispatch at a busy child on every retry.
|
|
198
|
+
expect(h.host.streaming).toBe(true);
|
|
199
|
+
// ...and the settle clock must be able to retire that flag if the run's
|
|
200
|
+
// terminal frame never arrives.
|
|
201
|
+
expect(settleArms).toBe(1);
|
|
194
202
|
});
|
|
195
203
|
|
|
196
204
|
test('a command dispatched during a run\'s ack window does not settle the run', async () => {
|
|
@@ -142,6 +142,17 @@ export async function dispatchSessionCommand(host: SessionCommandHost, command:
|
|
|
142
142
|
// not know a run was in flight (a second tab, a reload, another
|
|
143
143
|
// instance) recover instead of losing the prompt.
|
|
144
144
|
if (error instanceof RpcCommandError && AGENT_BUSY_REFUSAL_RE.test(error.message)) {
|
|
145
|
+
// omp's verdict outranks our flags: a turn IS in flight, whatever
|
|
146
|
+
// this wrapper believed. The queue's delivery gate reads `isBusy()`,
|
|
147
|
+
// so without this a stale-idle wrapper (a `get_state` probe whose
|
|
148
|
+
// answer landed after `agent_start` clears both flags) dispatched at
|
|
149
|
+
// the child every retry and collected `agent_busy` for the rest of
|
|
150
|
+
// the run — measured as 104 failures in one session, each one
|
|
151
|
+
// requeueing the head. `agent_end`, or the settle probe's `isSettled`,
|
|
152
|
+
// is what clears it again.
|
|
153
|
+
host.streaming = true;
|
|
154
|
+
// ...and the run-settle clock retires it if that frame never comes.
|
|
155
|
+
host.runSettle?.arm();
|
|
145
156
|
throw new WebRpcError(AGENT_BUSY_MESSAGE, 'agent_busy');
|
|
146
157
|
}
|
|
147
158
|
throw error;
|