@kabmo-labs/kabmo 0.18.0 → 0.21.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 +43 -13
- package/dist/client/index.html +3 -3
- package/dist/client/index.js +485 -484
- package/dist/client/static/js/index-0721wrkf.css +1 -0
- package/dist/client/static/js/{index-tc09dtca.js → index-zg32n2sk.js} +778 -777
- package/dist/client/static/{manifest-42r8wcmg.webmanifest → manifest-q6h8k9e0.webmanifest} +1 -1
- package/index.html +1 -1
- 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/public/manifest.webmanifest +1 -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 +142 -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.test.tsx +124 -0
- package/src/client/components/common/panel-mark/index.tsx +105 -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/GitFreshness.test.tsx +46 -0
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +7 -9
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +34 -7
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +66 -2
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +47 -10
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +7 -1
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +35 -2
- 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-sticky.test.ts +46 -0
- package/src/client/glass.css +795 -0
- package/src/client/glass.test.ts +306 -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 +213 -0
- package/src/client/hooks/ui/stuck-header.ts +122 -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/hooks/workspace/panel-registry.ts +8 -4
- 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/lifecycle/tls.test.ts +6 -1
- 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/git-update.server.test.ts +20 -0
- package/src/server/lib/panels/git-update.server.ts +20 -4
- 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/panels/sync.server.ts +9 -1
- package/src/server/lib/panels/update.server.test.ts +193 -0
- package/src/server/lib/panels/update.server.ts +210 -0
- package/src/server/lib/plugins/server-half.server.ts +42 -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/lib/terminal/attach-replay.test.ts +26 -8
- package/src/server/plugins/ssr.ts +22 -5
- package/src/server/routes/panels/install-route.test.ts +238 -0
- package/src/server/routes/panels/install.ts +36 -64
- package/src/server/routes/panels/panel-routes.test-util.ts +6 -1
- package/src/server/routes/panels/routes.test.ts +1 -118
- package/src/shared/lib/icons/file-brand-color.ts +38 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +235 -0
- package/src/shared/lib/icons/icon-paint-css.ts +285 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +109 -0
- package/src/shared/lib/icons/icon-tone.ts +166 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +277 -0
- package/src/shared/lib/icons/tint.test.ts +333 -0
- package/src/shared/lib/icons/tint.ts +248 -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/panels/update.test.ts +107 -0
- package/src/shared/lib/panels/update.ts +73 -0
- 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/color.ts +50 -0
- 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,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The dispatch the pane's Update buttons go through.
|
|
8
|
+
*
|
|
9
|
+
* `updatePanelPlugin` is the one entry point for both sources, so the cases that
|
|
10
|
+
* matter are the ones a per-source button would have got wrong: a git clone is
|
|
11
|
+
* fetched and reset AND its freshness is written (a stale status would leave the
|
|
12
|
+
* card offering the update it just applied), while a directory with no source is
|
|
13
|
+
* refused by name rather than silently succeeding.
|
|
14
|
+
*
|
|
15
|
+
* `updateAllPanelPlugins` probes before it fetches: only a clone that is actually
|
|
16
|
+
* behind is moved, so an up-to-date one costs a ref lookup and nothing else.
|
|
17
|
+
*
|
|
18
|
+
* Driven against REAL git repositories, like `git-update.server.test.ts`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterEach, beforeEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import { tmpdir } from 'node:os';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { installPanelPluginFromGit } from '@/server/lib/panels/install.server';
|
|
27
|
+
import { installPanelPluginFromBundled } from '@/server/lib/panels/install.server';
|
|
28
|
+
import { updateAllPanelPlugins, updatePanelPlugin } from '@/server/lib/panels/update.server';
|
|
29
|
+
import { readGitStatus } from '@/server/lib/panels/git-status.server';
|
|
30
|
+
import { invalidatePanelScan } from '@/server/lib/panels/registry.server';
|
|
31
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
32
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
33
|
+
|
|
34
|
+
const hasGit = Boolean(Bun.which('git'));
|
|
35
|
+
|
|
36
|
+
/** Real git processes plus a plugin build; see the note in the sibling suite. */
|
|
37
|
+
setDefaultTimeout(30_000);
|
|
38
|
+
|
|
39
|
+
let work = '';
|
|
40
|
+
let root = '';
|
|
41
|
+
let store = '';
|
|
42
|
+
|
|
43
|
+
const VALID = { id: 'from-git', name: 'From Git', version: '1.0.0', app: 'dist/app.js' };
|
|
44
|
+
|
|
45
|
+
function git(dir: string, args: string[]): void {
|
|
46
|
+
Bun.spawnSync(['git', '-C', dir, ...args], { stdout: 'pipe', stderr: 'pipe' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function makeRepo(): string {
|
|
50
|
+
const dir = fs.mkdtempSync(join(work, 'repo-'));
|
|
51
|
+
fs.writeFileSync(join(dir, 'kabmo.json'), JSON.stringify(VALID));
|
|
52
|
+
fs.mkdirSync(join(dir, 'dist'), { recursive: true });
|
|
53
|
+
fs.writeFileSync(join(dir, 'dist', 'app.js'), 'export default {};');
|
|
54
|
+
git(dir, ['init', '-q']);
|
|
55
|
+
git(dir, ['config', 'core.autocrlf', 'false']);
|
|
56
|
+
git(dir, ['config', 'core.eol', 'lf']);
|
|
57
|
+
git(dir, ['config', 'user.email', 'test@example.com']);
|
|
58
|
+
git(dir, ['config', 'user.name', 'Test']);
|
|
59
|
+
git(dir, ['add', '-A']);
|
|
60
|
+
git(dir, ['commit', '-q', '-m', 'init']);
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function advance(repo: string, version: string): void {
|
|
65
|
+
fs.writeFileSync(join(repo, 'kabmo.json'), JSON.stringify({ ...VALID, version }));
|
|
66
|
+
git(repo, ['add', '-A']);
|
|
67
|
+
git(repo, ['commit', '-q', '-m', `v${version}`]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
beforeEach(async () => {
|
|
71
|
+
work = fs.mkdtempSync(join(tmpdir(), 'omp-panels-update-repos-'));
|
|
72
|
+
root = fs.mkdtempSync(join(tmpdir(), 'omp-panels-update-work-'));
|
|
73
|
+
store = fs.mkdtempSync(join(tmpdir(), 'omp-panels-update-store-'));
|
|
74
|
+
process.env.KABMO_MARKETPLACE_DIR = root;
|
|
75
|
+
process.env.KABMO_BUNDLED_MARKETPLACE_DIR = store;
|
|
76
|
+
// The baselines and the refusal records live in `app_settings`, so a suite
|
|
77
|
+
// without this reads — and writes — the developer's own database, and the
|
|
78
|
+
// edit gate then answers from another install's history.
|
|
79
|
+
await isolateDb();
|
|
80
|
+
globalThis.__kabmoPanelGitStatus?.clear();
|
|
81
|
+
invalidatePanelScan();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
afterEach(async () => {
|
|
85
|
+
delete process.env.KABMO_MARKETPLACE_DIR;
|
|
86
|
+
delete process.env.KABMO_BUNDLED_MARKETPLACE_DIR;
|
|
87
|
+
// The freshness cache is a `globalThis` map, so a status this suite wrote
|
|
88
|
+
// would outlive it and answer for a plugin another suite never probed.
|
|
89
|
+
globalThis.__kabmoPanelGitStatus?.clear();
|
|
90
|
+
await releaseDb();
|
|
91
|
+
invalidatePanelScan();
|
|
92
|
+
for (const dir of [work, root, store]) removeDir(dir);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function installedVersion(pluginId: string): string {
|
|
96
|
+
const manifest = JSON.parse(fs.readFileSync(join(root, 'plugins', pluginId, 'kabmo.json'), 'utf8')) as {
|
|
97
|
+
version: string;
|
|
98
|
+
};
|
|
99
|
+
return manifest.version;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe('updatePanelPlugin on a git clone', () => {
|
|
103
|
+
test.skipIf(!hasGit)('moves the files and writes the freshness it just achieved', async () => {
|
|
104
|
+
const repo = makeRepo();
|
|
105
|
+
await installPanelPluginFromGit(repo);
|
|
106
|
+
advance(repo, '2.0.0');
|
|
107
|
+
|
|
108
|
+
const result = await updatePanelPlugin('from-git');
|
|
109
|
+
expect(result.updated).toBe(true);
|
|
110
|
+
expect(result.error).toBeUndefined();
|
|
111
|
+
expect(installedVersion('from-git')).toBe('2.0.0');
|
|
112
|
+
|
|
113
|
+
// The status must say CURRENT after the update: leaving the previous
|
|
114
|
+
// "behind" verdict would keep offering an update that already happened.
|
|
115
|
+
expect(readGitStatus('from-git')?.updateAvailable).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test.skipIf(!hasGit)('reports a dirty clone by name and touches nothing', async () => {
|
|
119
|
+
const repo = makeRepo();
|
|
120
|
+
await installPanelPluginFromGit(repo);
|
|
121
|
+
advance(repo, '2.0.0');
|
|
122
|
+
fs.writeFileSync(join(root, 'plugins', 'from-git', 'dist', 'app.js'), 'export default { edited: true };');
|
|
123
|
+
|
|
124
|
+
const result = await updatePanelPlugin('from-git');
|
|
125
|
+
expect(result.updated).toBe(false);
|
|
126
|
+
expect(result.error).toContain('uncommitted changes');
|
|
127
|
+
expect(installedVersion('from-git')).toBe('1.0.0');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('updatePanelPlugin on a directory nothing publishes', () => {
|
|
132
|
+
test('refuses it by naming why', async () => {
|
|
133
|
+
const dir = join(root, 'plugins', 'plain');
|
|
134
|
+
fs.mkdirSync(join(dir, 'dist'), { recursive: true });
|
|
135
|
+
fs.writeFileSync(join(dir, 'kabmo.json'), JSON.stringify({ ...VALID, id: 'plain' }));
|
|
136
|
+
fs.writeFileSync(join(dir, 'dist', 'app.js'), 'export default {};');
|
|
137
|
+
|
|
138
|
+
const result = await updatePanelPlugin('plain');
|
|
139
|
+
expect(result.updated).toBe(false);
|
|
140
|
+
expect(result.error).toContain('local directory');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('refuses an id that is not installed at all', async () => {
|
|
144
|
+
expect((await updatePanelPlugin('ghost')).error).toContain('No installed plugin');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('updateAllPanelPlugins', () => {
|
|
149
|
+
test.skipIf(!hasGit)('updates a clone that is behind and leaves a current one alone', async () => {
|
|
150
|
+
const behind = makeRepo();
|
|
151
|
+
await installPanelPluginFromGit(behind);
|
|
152
|
+
advance(behind, '2.0.0');
|
|
153
|
+
|
|
154
|
+
// A second plugin whose remote never moved.
|
|
155
|
+
const current = fs.mkdtempSync(join(work, 'repo-'));
|
|
156
|
+
fs.writeFileSync(join(current, 'kabmo.json'), JSON.stringify({ ...VALID, id: 'current', name: 'Current' }));
|
|
157
|
+
fs.mkdirSync(join(current, 'dist'), { recursive: true });
|
|
158
|
+
fs.writeFileSync(join(current, 'dist', 'app.js'), 'export default {};');
|
|
159
|
+
git(current, ['init', '-q']);
|
|
160
|
+
git(current, ['config', 'core.autocrlf', 'false']);
|
|
161
|
+
git(current, ['config', 'user.email', 'test@example.com']);
|
|
162
|
+
git(current, ['config', 'user.name', 'Test']);
|
|
163
|
+
git(current, ['add', '-A']);
|
|
164
|
+
git(current, ['commit', '-q', '-m', 'init']);
|
|
165
|
+
await installPanelPluginFromGit(current);
|
|
166
|
+
|
|
167
|
+
invalidatePanelScan();
|
|
168
|
+
const outcome = await updateAllPanelPlugins();
|
|
169
|
+
|
|
170
|
+
expect(outcome.updated).toEqual(['from-git']);
|
|
171
|
+
expect(installedVersion('from-git')).toBe('2.0.0');
|
|
172
|
+
// The current clone was probed, found equal, and not fetched or reset.
|
|
173
|
+
expect(outcome.refused).toEqual([]);
|
|
174
|
+
expect(readGitStatus('current')?.updateAvailable).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('applies a store update for a bundled install', async () => {
|
|
178
|
+
// The store path of the same pass: installed 1.0.0, store ships 1.1.0.
|
|
179
|
+
const bundled = { ...VALID, id: 'demo', name: 'Demo' };
|
|
180
|
+
for (const dir of [join(root, 'plugins', 'demo'), join(store, 'plugins', 'demo')]) {
|
|
181
|
+
fs.mkdirSync(join(dir, 'dist'), { recursive: true });
|
|
182
|
+
fs.writeFileSync(join(dir, 'kabmo.json'), JSON.stringify(bundled));
|
|
183
|
+
fs.writeFileSync(join(dir, 'dist', 'app.js'), 'export default {};');
|
|
184
|
+
}
|
|
185
|
+
await installPanelPluginFromBundled('demo');
|
|
186
|
+
fs.writeFileSync(join(store, 'plugins', 'demo', 'kabmo.json'), JSON.stringify({ ...bundled, version: '1.1.0' }));
|
|
187
|
+
invalidatePanelScan();
|
|
188
|
+
|
|
189
|
+
const outcome = await updateAllPanelPlugins();
|
|
190
|
+
expect(outcome.updated).toContain('demo');
|
|
191
|
+
expect(installedVersion('demo')).toBe('1.1.0');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bringing one installed panel plugin — or all of them — up to whatever owns it.
|
|
8
|
+
*
|
|
9
|
+
* Two sources publish plugin updates and the pane offers ONE Update button, so
|
|
10
|
+
* the dispatch lives here rather than in the route: a git clone is fetched and
|
|
11
|
+
* reset to its remote's HEAD (`git-update.server.ts`), while a bundled install
|
|
12
|
+
* takes the store's copy (`sync.server.ts`) under the same edit gate the boot
|
|
13
|
+
* pass uses. A directory with neither source is refused by name — "nothing
|
|
14
|
+
* updates it" is a fact the reader needs, not a silent no-op.
|
|
15
|
+
*
|
|
16
|
+
* Every update unloads the plugin's SERVER half BEFORE the files move and
|
|
17
|
+
* reloads it afterwards, and only when it was loaded to begin with: the module
|
|
18
|
+
* is already imported and its registrations are live, so a half that kept
|
|
19
|
+
* running would answer from code the directory no longer holds — while loading
|
|
20
|
+
* one that was never running (a disabled plugin, or one with no server entry)
|
|
21
|
+
* would invent a half the user switched off.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { join } from 'path';
|
|
25
|
+
import { pathExists } from '@/server/lib/omp/core/paths';
|
|
26
|
+
import {
|
|
27
|
+
discoverPanelPlugins,
|
|
28
|
+
getBundledMarketplaceDir,
|
|
29
|
+
getMarketplacePluginsDir,
|
|
30
|
+
invalidatePanelScan,
|
|
31
|
+
} from '@/server/lib/panels/registry.server';
|
|
32
|
+
import { readGitOrigin } from '@/server/lib/panels/git-clone.server';
|
|
33
|
+
import { probeGitUpdate, updateGitPlugin } from '@/server/lib/panels/git-update.server';
|
|
34
|
+
import { writeGitStatus } from '@/server/lib/panels/git-status.server';
|
|
35
|
+
import { syncBundledPlugins } from '@/server/lib/panels/sync.server';
|
|
36
|
+
import { loadedPlugin } from '@/server/lib/plugins/loader.server';
|
|
37
|
+
import { syncPluginServer } from '@/server/lib/plugins/server-half.server';
|
|
38
|
+
|
|
39
|
+
/** What one plugin's update did. */
|
|
40
|
+
export interface PanelUpdateOutcome {
|
|
41
|
+
pluginId: string;
|
|
42
|
+
/** True when files actually moved. */
|
|
43
|
+
updated: boolean;
|
|
44
|
+
/** The version or commit it was at, for a bundled update. */
|
|
45
|
+
from?: string;
|
|
46
|
+
/** The version or commit it moved to. */
|
|
47
|
+
to?: string;
|
|
48
|
+
/** Why nothing moved — a refusal names its reason. */
|
|
49
|
+
error?: string;
|
|
50
|
+
/** A rebuild that failed after the files moved. */
|
|
51
|
+
warning?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** What an update-all pass did, per plugin. */
|
|
55
|
+
export interface PanelUpdateAllOutcome {
|
|
56
|
+
/** Plugins whose files moved. */
|
|
57
|
+
updated: string[];
|
|
58
|
+
/** Plugins left as they were, with the reason. */
|
|
59
|
+
refused: Array<{ pluginId: string; error: string }>;
|
|
60
|
+
/** Updates that moved files but left a message, e.g. a failed rebuild. */
|
|
61
|
+
warnings: Array<{ pluginId: string; warning: string }>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Where an install's updates come from, read off the directory itself. */
|
|
65
|
+
async function sourceOf(pluginId: string, dir: string): Promise<'git' | 'bundled' | 'local'> {
|
|
66
|
+
if (await readGitOrigin(dir)) return 'git';
|
|
67
|
+
const storeDir = join(getBundledMarketplaceDir(), 'plugins', pluginId);
|
|
68
|
+
return (await pathExists(storeDir)) ? 'bundled' : 'local';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Bring ONE installed plugin up to its source.
|
|
73
|
+
*
|
|
74
|
+
* Never throws for an expected refusal (a dirty clone, a hand-edited bundled
|
|
75
|
+
* copy, a plugin that is not there): the answer is a value the pane reports.
|
|
76
|
+
*/
|
|
77
|
+
export async function updatePanelPlugin(pluginId: string): Promise<PanelUpdateOutcome> {
|
|
78
|
+
const dir = join(getMarketplacePluginsDir(), pluginId);
|
|
79
|
+
if (!(await pathExists(dir))) {
|
|
80
|
+
return { pluginId, updated: false, error: `No installed plugin with id "${pluginId}".` };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const source = await sourceOf(pluginId, dir);
|
|
84
|
+
if (source === 'local') {
|
|
85
|
+
return {
|
|
86
|
+
pluginId,
|
|
87
|
+
updated: false,
|
|
88
|
+
error: `${pluginId} is a local directory — it has no remote and the store does not ship it, so nothing publishes an update for it.`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Read BEFORE the unload: after it, the registry can no longer say whether
|
|
93
|
+
// this plugin's server half was running.
|
|
94
|
+
const wasLoaded = loadedPlugin(pluginId) !== undefined;
|
|
95
|
+
await syncPluginServer(pluginId, false);
|
|
96
|
+
try {
|
|
97
|
+
return source === 'git' ? await updateFromRemote(pluginId) : await updateFromStore(pluginId);
|
|
98
|
+
} finally {
|
|
99
|
+
if (wasLoaded) await syncPluginServer(pluginId, true);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Fetch the remote's HEAD, move the clone to it, rebuild. */
|
|
104
|
+
async function updateFromRemote(pluginId: string): Promise<PanelUpdateOutcome> {
|
|
105
|
+
const result = await updateGitPlugin(pluginId);
|
|
106
|
+
if (!result.ok) return { pluginId, updated: false, error: result.error };
|
|
107
|
+
|
|
108
|
+
// The freshness this update just achieved is WRITTEN rather than probed
|
|
109
|
+
// again: the commit is known, and a second round trip could only disagree
|
|
110
|
+
// with the reset that already happened.
|
|
111
|
+
writeGitStatus(pluginId, {
|
|
112
|
+
current: result.commit ?? null,
|
|
113
|
+
latest: result.commit ?? null,
|
|
114
|
+
updateAvailable: false,
|
|
115
|
+
checkedAt: Date.now(),
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
pluginId,
|
|
119
|
+
updated: result.updated,
|
|
120
|
+
...(result.commit ? { to: result.commit } : {}),
|
|
121
|
+
...(result.warning ? { warning: result.warning } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Apply the store's copy under the sync's own gate.
|
|
127
|
+
*
|
|
128
|
+
* The gate — not the caller — decides whether anything is applied: a tree the
|
|
129
|
+
* user edited is REFUSED here exactly as it is at boot, and the files that
|
|
130
|
+
* differ are named so the pane's blocked notice can offer the override. An
|
|
131
|
+
* update button that overwrote them would be the force-sync escape hatch
|
|
132
|
+
* without the warning.
|
|
133
|
+
*/
|
|
134
|
+
async function updateFromStore(pluginId: string): Promise<PanelUpdateOutcome> {
|
|
135
|
+
const synced = await syncBundledPlugins({ only: pluginId });
|
|
136
|
+
|
|
137
|
+
const failure = synced.failed.find((entry) => entry.pluginId === pluginId);
|
|
138
|
+
if (failure) return { pluginId, updated: false, error: failure.error };
|
|
139
|
+
|
|
140
|
+
const blocked = synced.blocked.find((entry) => entry.pluginId === pluginId);
|
|
141
|
+
if (blocked) return { pluginId, updated: false, error: blockedReason(pluginId, blocked.changed.length) };
|
|
142
|
+
|
|
143
|
+
const applied = synced.updated.find((entry) => entry.pluginId === pluginId);
|
|
144
|
+
if (!applied) return { pluginId, updated: false };
|
|
145
|
+
return {
|
|
146
|
+
pluginId,
|
|
147
|
+
updated: true,
|
|
148
|
+
from: applied.from,
|
|
149
|
+
to: applied.to,
|
|
150
|
+
...(applied.warning ? { warning: applied.warning } : {}),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Apply every update that is actually available, and report each one.
|
|
156
|
+
*
|
|
157
|
+
* Git clones are PROBED first and only the ones behind are fetched-and-reset:
|
|
158
|
+
* an update against a clone already at its remote's HEAD would be a network
|
|
159
|
+
* round trip that changes nothing.
|
|
160
|
+
*
|
|
161
|
+
* Bundled installs run one pass over the store — the same pass the boot runs —
|
|
162
|
+
* and only the plugins it actually moved are reloaded afterwards. Unloading
|
|
163
|
+
* every bundled server half BEFORE the pass would be the safer ordering for a
|
|
164
|
+
* plugin that is about to be replaced, but it also stops the panels of every
|
|
165
|
+
* bundled plugin on a pass that usually changes nothing; the pass replaces
|
|
166
|
+
* files rather than removing them, so the reload afterwards is what keeps the
|
|
167
|
+
* running code honest.
|
|
168
|
+
*/
|
|
169
|
+
export async function updateAllPanelPlugins(): Promise<PanelUpdateAllOutcome> {
|
|
170
|
+
const outcome: PanelUpdateAllOutcome = { updated: [], refused: [], warnings: [] };
|
|
171
|
+
const { plugins } = await discoverPanelPlugins();
|
|
172
|
+
|
|
173
|
+
const record = (result: PanelUpdateOutcome): void => {
|
|
174
|
+
if (result.updated) outcome.updated.push(result.pluginId);
|
|
175
|
+
if (result.error) outcome.refused.push({ pluginId: result.pluginId, error: result.error });
|
|
176
|
+
if (result.warning) outcome.warnings.push({ pluginId: result.pluginId, warning: result.warning });
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
for (const plugin of plugins) {
|
|
180
|
+
if (!plugin.gitOrigin) continue;
|
|
181
|
+
const status = await probeGitUpdate(plugin.pluginId);
|
|
182
|
+
writeGitStatus(plugin.pluginId, status);
|
|
183
|
+
if (!status.updateAvailable) continue;
|
|
184
|
+
record(await updatePanelPlugin(plugin.pluginId));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const synced = await syncBundledPlugins();
|
|
188
|
+
for (const entry of synced.updated) {
|
|
189
|
+
outcome.updated.push(entry.pluginId);
|
|
190
|
+
if (entry.warning) outcome.warnings.push({ pluginId: entry.pluginId, warning: entry.warning });
|
|
191
|
+
// Reload only a half that was RUNNING: loading one that was not would switch
|
|
192
|
+
// a disabled plugin's routes on behind the switch that says off.
|
|
193
|
+
if (loadedPlugin(entry.pluginId)) {
|
|
194
|
+
await syncPluginServer(entry.pluginId, false);
|
|
195
|
+
await syncPluginServer(entry.pluginId, true);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
for (const entry of synced.blocked) {
|
|
199
|
+
outcome.refused.push({ pluginId: entry.pluginId, error: blockedReason(entry.pluginId, entry.changed.length) });
|
|
200
|
+
}
|
|
201
|
+
for (const entry of synced.failed) outcome.refused.push(entry);
|
|
202
|
+
|
|
203
|
+
invalidatePanelScan();
|
|
204
|
+
return outcome;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The one sentence a refused bundled update reports, so both callers agree. */
|
|
208
|
+
function blockedReason(pluginId: string, changed: number): string {
|
|
209
|
+
return `${pluginId} has local changes in ${changed} file${changed === 1 ? '' : 's'}, so its bundled update is paused. Nothing was replaced.`;
|
|
210
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bringing one plugin's SERVER half in line with its on-disk state, now.
|
|
8
|
+
*
|
|
9
|
+
* The half is otherwise loaded once at boot (`loadPluginServers` in the entry),
|
|
10
|
+
* so every action that moves a plugin's files or its enablement — install,
|
|
11
|
+
* remove, enable, disable, update — has to load or unload it itself. Without
|
|
12
|
+
* this the plugin's routes, RPC methods and realtime topic stay registered
|
|
13
|
+
* against code the directory no longer holds: a panel that installed cleanly and
|
|
14
|
+
* then answered "no plugin is loaded", or a Stats panel stuck on "No sample
|
|
15
|
+
* yet." with nothing on screen to explain it.
|
|
16
|
+
*
|
|
17
|
+
* Never throws: a plugin whose server half cannot load is a plugin whose PANEL
|
|
18
|
+
* still works, and the failure is recorded through `notePluginLoadFailure` — the
|
|
19
|
+
* same list `GET /api/plugins/state` serves to the pane — so the reader sees
|
|
20
|
+
* WHY. Folding it into a 4xx at the call site would hide a successful install
|
|
21
|
+
* behind an unrelated fault.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { disposePlugin, loadPluginServer, notePluginLoadFailure } from '@/server/lib/plugins/loader.server';
|
|
25
|
+
|
|
26
|
+
export async function syncPluginServer(pluginId: string, enabled: boolean): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
if (enabled) {
|
|
29
|
+
await loadPluginServer(pluginId);
|
|
30
|
+
// A later success clears an earlier failure, or the pane would keep
|
|
31
|
+
// reporting a fault the user has already fixed.
|
|
32
|
+
notePluginLoadFailure(pluginId, null);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await disposePlugin(pluginId);
|
|
36
|
+
notePluginLoadFailure(pluginId, null);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
39
|
+
notePluginLoadFailure(pluginId, reason);
|
|
40
|
+
console.error(`[plugins] ${pluginId}: server half ${enabled ? 'load' : 'unload'} failed — ${reason}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -211,4 +211,52 @@ describe('queue dispatch', () => {
|
|
|
211
211
|
|
|
212
212
|
expect(delivered).toBe(false);
|
|
213
213
|
});
|
|
214
|
+
|
|
215
|
+
// omp refused the prompt because a turn was already in flight while the
|
|
216
|
+
// wrapper still read idle (a probe's stale answer had cleared its flags).
|
|
217
|
+
// Measured: 104 `agent_busy` failures in one session. The refusal is omp's
|
|
218
|
+
// own word that the session is busy, so the wrapper keeps `isBusy()` true and
|
|
219
|
+
// every later tick parks — one attempted dispatch, not one per retry — and the
|
|
220
|
+
// head keeps its place.
|
|
221
|
+
test('a busy refusal parks the queue instead of redispatching on every tick', async () => {
|
|
222
|
+
const sessionId = beginQueueTest();
|
|
223
|
+
queue.set(sessionId, [queueItem('a'), queueItem('b'), queueItem('c')]);
|
|
224
|
+
const { host, sent } = makeHost(sessionId);
|
|
225
|
+
// The wrapper's flags say idle; omp is actually mid-turn.
|
|
226
|
+
let wrapperBusy = false;
|
|
227
|
+
let ompBusy = true;
|
|
228
|
+
host.isBusy = () => wrapperBusy;
|
|
229
|
+
host.send = async (command) => {
|
|
230
|
+
if (command.type !== 'prompt') return {};
|
|
231
|
+
if (!ompBusy) {
|
|
232
|
+
sent.push(command);
|
|
233
|
+
return {};
|
|
234
|
+
}
|
|
235
|
+
// What the command dispatcher does with omp's `agent_busy` refusal: the
|
|
236
|
+
// typed error, and omp's verdict kept on the wrapper's own flags.
|
|
237
|
+
wrapperBusy = true;
|
|
238
|
+
throw new Error('agent_busy');
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const delivered = await deliverQueueNow(host);
|
|
242
|
+
await flush();
|
|
243
|
+
expect(delivered).toBe(false);
|
|
244
|
+
|
|
245
|
+
// The retry timer and a client nudge both arrive while omp is still busy:
|
|
246
|
+
// neither may dispatch at the child again.
|
|
247
|
+
jest.advanceTimersByTime(2_000);
|
|
248
|
+
await flush();
|
|
249
|
+
await deliverQueueNow(host);
|
|
250
|
+
await flush();
|
|
251
|
+
expect(sent).toEqual([]);
|
|
252
|
+
expect(queue.get(sessionId)?.map((item) => item.text)).toEqual(['a', 'b', 'c']);
|
|
253
|
+
|
|
254
|
+
// The run ends: the head goes out, ahead of everything queued behind it.
|
|
255
|
+
ompBusy = false;
|
|
256
|
+
wrapperBusy = false;
|
|
257
|
+
await deliverQueueNow(host);
|
|
258
|
+
await flush();
|
|
259
|
+
expect(sent.map((command) => command.message)).toEqual(['a']);
|
|
260
|
+
expect(queue.get(sessionId)?.map((item) => item.text)).toEqual(['b', 'c']);
|
|
261
|
+
});
|
|
214
262
|
});
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
import { jest, mock } from 'bun:test';
|
|
23
23
|
import type { QueuedMessage } from '@/shared/types/chat';
|
|
24
|
+
import type { ClaimedQueueItem } from '@/server/lib/queue/store.server';
|
|
24
25
|
import type { QueueDeliveryHost } from '@/server/lib/queue/delivery.server';
|
|
25
26
|
|
|
26
27
|
// Hoisted above the registration, so spreading it here snapshots the REAL
|
|
@@ -40,14 +41,17 @@ export const queue = new Map<string, QueuedMessage[]>();
|
|
|
40
41
|
* after another has restored the real one. */
|
|
41
42
|
export function installStoreMock(): void {
|
|
42
43
|
mock.module('@/server/lib/queue/store.server', () => ({
|
|
43
|
-
claimHeadQueueItem: async (sessionId: string): Promise<
|
|
44
|
+
claimHeadQueueItem: async (sessionId: string): Promise<ClaimedQueueItem | null> => {
|
|
44
45
|
const items = queue.get(sessionId);
|
|
45
|
-
|
|
46
|
+
const head = items?.shift();
|
|
47
|
+
// The list index IS the position here, and the head is always index 0.
|
|
48
|
+
return head ? { ...head, position: 0 } : null;
|
|
46
49
|
},
|
|
47
50
|
hasQueuedItem: async (sessionId: string): Promise<boolean> => (queue.get(sessionId)?.length ?? 0) > 0,
|
|
48
|
-
requeueHeadQueueItem: async (sessionId: string, item:
|
|
51
|
+
requeueHeadQueueItem: async (sessionId: string, item: ClaimedQueueItem): Promise<void> => {
|
|
49
52
|
const items = queue.get(sessionId) ?? [];
|
|
50
|
-
|
|
53
|
+
const { position: _position, ...row } = item;
|
|
54
|
+
items.splice(0, 0, row);
|
|
51
55
|
queue.set(sessionId, items);
|
|
52
56
|
},
|
|
53
57
|
}));
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import { afterAll, afterEach, beforeAll, describe, expect, jest, mock, test } from 'bun:test';
|
|
25
25
|
import {
|
|
26
26
|
beginQueueTest,
|
|
27
|
+
deliverQueueNow,
|
|
27
28
|
flush,
|
|
28
29
|
installStoreMock,
|
|
29
30
|
makeHost,
|
|
@@ -203,4 +204,32 @@ describe('queue delivery scheduling', () => {
|
|
|
203
204
|
expect(sent.filter((c) => c.type === 'prompt').length).toBe(1);
|
|
204
205
|
expect(queue.get(sessionId)).toEqual([]);
|
|
205
206
|
});
|
|
207
|
+
|
|
208
|
+
// The nudge path (`deliverQueueNow`) has no timer to dedupe it: a tab's 3s
|
|
209
|
+
// poll, a focus nudge and a run end can all be inside `deliverNext` at once.
|
|
210
|
+
// Two overlapping attempts claim two heads, and the requeues that follow
|
|
211
|
+
// decide which of the pair comes back first — measured on a live session as
|
|
212
|
+
// the panel's order changing on every `agent_busy` retry.
|
|
213
|
+
test('overlapping delivery attempts share one dispatch and leave the order alone', async () => {
|
|
214
|
+
const sessionId = beginQueueTest();
|
|
215
|
+
queue.set(sessionId, [queueItem('a'), queueItem('b'), queueItem('c')]);
|
|
216
|
+
const { host } = makeHost(sessionId);
|
|
217
|
+
let attempts = 0;
|
|
218
|
+
host.send = async () => {
|
|
219
|
+
attempts++;
|
|
220
|
+
throw new Error('agent_busy');
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const results = await Promise.all([
|
|
224
|
+
deliverQueueNow(host),
|
|
225
|
+
deliverQueueNow(host),
|
|
226
|
+
deliverQueueNow(host),
|
|
227
|
+
]);
|
|
228
|
+
await flush();
|
|
229
|
+
|
|
230
|
+
expect(results).toEqual([false, false, false]);
|
|
231
|
+
// One claim, one failed dispatch, one requeue — not three of each.
|
|
232
|
+
expect(attempts).toBe(1);
|
|
233
|
+
expect(queue.get(sessionId)?.map((item) => item.text)).toEqual(['a', 'b', 'c']);
|
|
234
|
+
});
|
|
206
235
|
});
|
|
@@ -70,6 +70,8 @@ interface PendingDelivery {
|
|
|
70
70
|
declare global {
|
|
71
71
|
// eslint-disable-next-line no-var
|
|
72
72
|
var __ompQueueDeliveryTimers: Map<string, PendingDelivery> | undefined;
|
|
73
|
+
// eslint-disable-next-line no-var
|
|
74
|
+
var __ompQueueDeliveryInFlight: Map<string, Promise<boolean>> | undefined;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/** Per-session pending delivery timer, so a second agent_end while one is
|
|
@@ -93,6 +95,24 @@ function clearPendingTimer(sessionId: string): void {
|
|
|
93
95
|
pendingTimers.delete(sessionId);
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
/**
|
|
99
|
+
* The delivery currently running for a session, if any.
|
|
100
|
+
*
|
|
101
|
+
* Every trigger — a run end, the retry timer, a tab's nudge (which runs
|
|
102
|
+
* {@link deliverQueueNow} with no timer at all) — enters here, and they overlap
|
|
103
|
+
* freely: a nudge fires while the retry's dispatch is still awaiting the RPC.
|
|
104
|
+
* Two overlapping attempts claim two different heads, and each requeue then
|
|
105
|
+
* decides the order the pair comes back in. Serialized per session, so one
|
|
106
|
+
* dispatch is in flight at a time and the queue is only ever touched by it.
|
|
107
|
+
*
|
|
108
|
+
* On `globalThis` for the same reason as the timers: a `--hot` reload must not
|
|
109
|
+
* lose track of a running delivery.
|
|
110
|
+
*/
|
|
111
|
+
function getInFlightDeliveries(): Map<string, Promise<boolean>> {
|
|
112
|
+
if (!globalThis.__ompQueueDeliveryInFlight) globalThis.__ompQueueDeliveryInFlight = new Map();
|
|
113
|
+
return globalThis.__ompQueueDeliveryInFlight;
|
|
114
|
+
}
|
|
115
|
+
|
|
96
116
|
/** Send one queued item to the session as a normal prompt. The model snapshot
|
|
97
117
|
* rides first (set_model / set_thinking_level) exactly like the composer's
|
|
98
118
|
* queued delivery did. Returns false when the dispatch failed.
|
|
@@ -202,8 +222,27 @@ async function armRetryIfQueued(session: QueueDeliveryHost): Promise<void> {
|
|
|
202
222
|
* strand the queue permanently: the timer had already been deleted from the map
|
|
203
223
|
* by its own callback, so nothing remained to retry it and no later trigger was
|
|
204
224
|
* guaranteed to arrive. Re-arming keeps the retry owned by this module.
|
|
225
|
+
*
|
|
226
|
+
* Concurrent calls share the running attempt instead of starting a second one:
|
|
227
|
+
* the dispatches that provoke them (`agent_busy` from omp while `isBusy()` still
|
|
228
|
+
* reads idle) otherwise overlap, and two overlapping claims plus two requeues
|
|
229
|
+
* reorder the queue.
|
|
205
230
|
*/
|
|
206
231
|
async function deliverNext(session: QueueDeliveryHost): Promise<boolean> {
|
|
232
|
+
const sessionId = session.sessionId;
|
|
233
|
+
const inFlight = getInFlightDeliveries();
|
|
234
|
+
const running = inFlight.get(sessionId);
|
|
235
|
+
if (running) return running;
|
|
236
|
+
const attempt = runDelivery(session);
|
|
237
|
+
inFlight.set(sessionId, attempt);
|
|
238
|
+
try {
|
|
239
|
+
return await attempt;
|
|
240
|
+
} finally {
|
|
241
|
+
if (inFlight.get(sessionId) === attempt) inFlight.delete(sessionId);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function runDelivery(session: QueueDeliveryHost): Promise<boolean> {
|
|
207
246
|
const sessionId = session.sessionId;
|
|
208
247
|
if (!session.isAlive()) return false;
|
|
209
248
|
if (session.isBusy()) {
|
|
@@ -35,9 +35,9 @@ import {
|
|
|
35
35
|
requeueHeadQueueItem,
|
|
36
36
|
reorderQueue,
|
|
37
37
|
rowToQueuedMessage,
|
|
38
|
+
type ClaimedQueueItem,
|
|
38
39
|
} from '@/server/lib/queue/store.server';
|
|
39
40
|
import { restoreStore } from '@/server/lib/queue/delivery-harness';
|
|
40
|
-
import type { QueuedMessage } from '@/shared/types/chat';
|
|
41
41
|
import { removeDir } from '@/test-support/remove-dir';
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -240,7 +240,7 @@ describe('claim, requeue and presence', () => {
|
|
|
240
240
|
useTempDb();
|
|
241
241
|
await appendQueueItem('s1', { text: 'first' });
|
|
242
242
|
await appendQueueItem('s1', { text: 'second' });
|
|
243
|
-
const failed = (await claimHeadQueueItem('s1')) as
|
|
243
|
+
const failed = (await claimHeadQueueItem('s1')) as ClaimedQueueItem;
|
|
244
244
|
expect(failed.text).toBe('first');
|
|
245
245
|
|
|
246
246
|
await requeueHeadQueueItem('s1', failed);
|
|
@@ -248,6 +248,26 @@ describe('claim, requeue and presence', () => {
|
|
|
248
248
|
expect((await claimHeadQueueItem('s1'))?.text).toBe('first');
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
+
// Measured live: a busy session rejected each dispatch (`agent_busy`) once
|
|
252
|
+
// per retry while the client's 3s nudge kept entering `deliverNext`, so two
|
|
253
|
+
// claims were in flight at once. `MIN(position) - 1` then put each failed
|
|
254
|
+
// item one slot too low and the pair came back swapped — the panel's order
|
|
255
|
+
// changed on every retry, and positions walked to -8..-1.
|
|
256
|
+
test('a requeue returns the item to its own slot, not below the queue', async () => {
|
|
257
|
+
useTempDb();
|
|
258
|
+
await appendQueueItem('s1', { text: 'a' });
|
|
259
|
+
await appendQueueItem('s1', { text: 'b' });
|
|
260
|
+
await appendQueueItem('s1', { text: 'c' });
|
|
261
|
+
|
|
262
|
+
// Two overlapping attempts: the second claims while the first dispatches.
|
|
263
|
+
const first = (await claimHeadQueueItem('s1')) as ClaimedQueueItem;
|
|
264
|
+
const second = (await claimHeadQueueItem('s1')) as ClaimedQueueItem;
|
|
265
|
+
await requeueHeadQueueItem('s1', first);
|
|
266
|
+
await requeueHeadQueueItem('s1', second);
|
|
267
|
+
|
|
268
|
+
expect((await listQueue('s1')).map((item) => item.text)).toEqual(['a', 'b', 'c']);
|
|
269
|
+
});
|
|
270
|
+
|
|
251
271
|
test('hasQueuedItem reports presence without claiming', async () => {
|
|
252
272
|
useTempDb();
|
|
253
273
|
expect(await hasQueuedItem('s1')).toBe(false);
|