@kabmo-labs/kabmo 0.28.0 → 0.29.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/bunfig.toml +6 -0
- package/dist/client/index.html +2 -2
- package/dist/client/index.js +481 -472
- package/dist/client/static/js/{index-xzvyrxya.js → index-43z47ngg.js} +1193 -1049
- package/dist/client/static/js/index-naa91727.css +1 -0
- package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
- package/package.json +3 -2
- package/public/manifest.webmanifest +1 -0
- package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
- package/src/client/components/common/ComposerTextarea.tsx +6 -0
- package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
- package/src/client/components/common/ReloadPageButton.tsx +11 -2
- package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
- package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
- package/src/client/components/common/file-icon/index.tsx +7 -1
- package/src/client/components/common/harness-glyph/brands.ts +7 -1
- package/src/client/components/common/image-viewer/index.tsx +37 -165
- package/src/client/components/common/picker-search/index.tsx +70 -0
- package/src/client/components/common/search-select/index.tsx +2 -7
- package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
- package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
- package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
- package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
- package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +6 -4
- package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
- package/src/client/components/settings/Sidebar.tsx +6 -8
- package/src/client/components/settings/categories/HarnessSettings.tsx +4 -2
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +2 -2
- package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
- package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
- package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
- package/src/client/components/settings/groups.test.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
- package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +8 -3
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +42 -15
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +28 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +28 -10
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
- package/src/client/components/workspace/editor/FilePane.tsx +32 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +4 -0
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +1 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +5 -2
- package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
- package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
- package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
- package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
- package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
- package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
- package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
- package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
- package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
- package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
- package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
- package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
- package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
- package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
- package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
- package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
- package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
- package/src/client/components/workspace/file-explorer/index.tsx +53 -29
- package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
- package/src/client/data/settings/omp-schema.json +169 -22
- package/src/client/glass.css +39 -14
- package/src/client/glass.test.ts +37 -0
- package/src/client/hooks/chat/composer/history.test.ts +267 -0
- package/src/client/hooks/chat/composer/history.ts +146 -0
- package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
- package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
- package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
- package/src/client/hooks/editor/file-editor-types.ts +15 -0
- package/src/client/hooks/editor/save-bytes.ts +79 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
- package/src/client/hooks/editor/use-file-editor.ts +53 -5
- package/src/client/hooks/editor/use-file-read.ts +21 -2
- package/src/client/hooks/editor/use-grid-selection.ts +160 -0
- package/src/client/hooks/models/use-harness-update.test.ts +35 -2
- package/src/client/hooks/models/use-harness-update.ts +49 -10
- package/src/client/hooks/workspace/diff-file.test.ts +72 -0
- package/src/client/hooks/workspace/diff-file.ts +12 -6
- package/src/client/hooks/workspace/file-archive.ts +220 -0
- package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
- package/src/client/hooks/workspace/file-clipboard.ts +37 -26
- package/src/client/hooks/workspace/file-selection.test.ts +67 -0
- package/src/client/hooks/workspace/file-selection.ts +156 -0
- package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
- package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
- package/src/client/lib/editor/workbook-drafts.ts +42 -0
- package/src/client/lib/launch/file-handlers.ts +2 -2
- package/src/client/lib/scrollbar-activity.test.ts +21 -88
- package/src/client/lib/scrollbar-activity.ts +71 -73
- package/src/client/lib/scrollbar-events.ts +143 -0
- package/src/client/lib/scrollbar-input.test.ts +126 -0
- package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
- package/src/client/tailwind.css +32 -1
- package/src/server/db.server.test.ts +50 -1
- package/src/server/db.server.ts +36 -3
- package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
- package/src/server/lib/chat/prompt-history.server.ts +65 -0
- package/src/server/lib/chat/schema.server.ts +35 -0
- package/src/server/lib/db/schema.ts +3 -0
- package/src/server/lib/fs/archive.test.ts +139 -0
- package/src/server/lib/fs/archive.ts +259 -0
- package/src/server/lib/fs/git-diff.test.ts +26 -1
- package/src/server/lib/fs/git-diff.ts +43 -15
- package/src/server/lib/harness/launch-table.ts +19 -0
- package/src/server/lib/harness/provider-entry.ts +1 -1
- package/src/server/lib/harness/provider-file.server.ts +1 -1
- package/src/server/lib/harness/provider-sources.server.ts +2 -1
- package/src/server/lib/harness/provider-write.server.ts +2 -1
- package/src/server/lib/harness/update-job-store.ts +12 -0
- package/src/server/lib/harness/update-queue.server.ts +15 -10
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
- package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
- package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
- package/src/server/lib/omp/session/delete.server.ts +1 -0
- package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
- package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
- package/src/server/lib/panels/auto-update.server.test.ts +5 -2
- package/src/server/lib/panels/git-update.server.test.ts +5 -2
- package/src/server/lib/panels/install.server.test.ts +5 -2
- package/src/server/lib/panels/remove.server.test.ts +5 -2
- package/src/server/routes/agent/command.ts +11 -0
- package/src/server/routes/agent/new.ts +5 -0
- package/src/server/routes/chat/index.ts +5 -0
- package/src/server/routes/chat/prompt-history.test.ts +67 -0
- package/src/server/routes/chat/prompt-history.ts +31 -0
- package/src/server/routes/chat/stream.test.ts +21 -0
- package/src/server/routes/chat/stream.ts +5 -0
- package/src/server/routes/fs/action-archive.test.ts +128 -0
- package/src/server/routes/fs/action-bulk.ts +106 -0
- package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
- package/src/server/routes/fs/action-transfer.test.ts +26 -0
- package/src/server/routes/fs/action.ts +91 -11
- package/src/server/routes/fs/archive.ts +20 -0
- package/src/server/routes/fs/grant.test.ts +5 -2
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.test.ts +6 -2
- package/src/server/routes/harness/import-action.ts +1 -1
- package/src/server/routes/harness/root.ts +6 -1
- package/src/server/routes/harness/summary.test.ts +50 -0
- package/src/server/routes/harness/update-status.ts +41 -2
- package/src/server/routes/harness/update.test.ts +56 -2
- package/src/server/routes/sessions/delete.test.ts +4 -0
- package/src/shared/lib/chat/ask-form/index.ts +39 -31
- package/src/shared/lib/chat/ask-form/labels.ts +46 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
- package/src/shared/lib/chat/ask-form.test.ts +57 -0
- package/src/shared/lib/chat/ask-questions.ts +31 -0
- package/src/shared/lib/chat/composer/history.test.ts +67 -0
- package/src/shared/lib/chat/composer/history.ts +61 -0
- package/src/shared/lib/chat/irc-notice.ts +42 -0
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
- package/src/shared/lib/chat/todo/parser.ts +6 -4
- package/src/shared/lib/fs/archive.test.ts +101 -0
- package/src/shared/lib/fs/archive.ts +191 -0
- package/src/shared/lib/fs/clipboard.test.ts +32 -7
- package/src/shared/lib/fs/clipboard.ts +59 -14
- package/src/shared/lib/fs/csv.test.ts +50 -0
- package/src/shared/lib/fs/csv.ts +40 -0
- package/src/shared/lib/fs/document-kind.test.ts +13 -6
- package/src/shared/lib/fs/document-kind.ts +18 -6
- package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
- package/src/shared/lib/fs/file-kind.test.ts +2 -7
- package/src/shared/lib/fs/file-kind.ts +4 -2
- package/src/shared/lib/fs/grid-edit.test.ts +24 -0
- package/src/shared/lib/fs/grid-edit.ts +29 -0
- package/src/shared/lib/fs/grid-selection.test.ts +137 -0
- package/src/shared/lib/fs/grid-selection.ts +138 -0
- package/src/shared/lib/harness/brand-color.ts +5 -0
- package/src/shared/lib/harness/catalog.test.ts +22 -0
- package/src/shared/lib/harness/catalog.ts +12 -1
- package/src/shared/lib/harness/config-fields.test.ts +25 -0
- package/src/shared/lib/harness/config-fields.ts +33 -3
- package/src/shared/lib/harness/dialects.ts +1 -1
- package/src/shared/lib/harness/mcp-facts.ts +4 -0
- package/src/shared/lib/harness/provider-contracts.ts +109 -0
- package/src/shared/lib/harness/provider-facts.test.ts +2 -1
- package/src/shared/lib/harness/provider-facts.ts +24 -115
- package/src/shared/lib/harness/provider-lookup.ts +37 -0
- package/src/shared/lib/harness/providers.ts +2 -1
- package/src/shared/lib/harness/updates.ts +10 -0
- package/src/shared/lib/omp/session/mapper.test.ts +31 -0
- package/src/shared/lib/omp/session/mapper.ts +17 -0
- package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
- package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
- package/src/shared/lib/omp/session/messages-map.ts +17 -0
- package/src/shared/lib/omp/session/wait.ts +10 -1
- package/src/shared/lib/settings/sections.ts +8 -4
- package/src/shared/lib/ui/picker-filter.test.ts +23 -0
- package/src/shared/lib/ui/picker-filter.ts +20 -0
- package/src/shared/types/chat.ts +4 -0
- package/src/shared/types/harness.ts +5 -1
- package/src/shared/types/omp/session.ts +18 -0
- package/src/shared/types/settings/state.ts +6 -6
- package/src/shared/types/todo.ts +3 -1
- package/src/test-support/file-actions.test-util.ts +4 -0
- package/src/test-support/file-archive.test-util.ts +41 -0
- package/src/test-support/file-clipboard.test-util.ts +9 -6
- package/src/test-support/harness-table.test-util.ts +2 -0
- package/src/test-support/preload.ts +46 -0
- package/dist/client/static/js/index-81f7berm.css +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { afterAll, afterEach, beforeAll, describe, expect, jest, test } from 'bun:test';
|
|
7
|
+
|
|
8
|
+
import { SCROLLBAR_ACTIVE_ATTRIBUTE } from '@/client/lib/scrollbar-activity';
|
|
9
|
+
import {
|
|
10
|
+
IDLE_MS,
|
|
11
|
+
freshPage,
|
|
12
|
+
inputAt,
|
|
13
|
+
keyAt,
|
|
14
|
+
restoreNativeGlobals,
|
|
15
|
+
saveNativeGlobals,
|
|
16
|
+
scrollAt,
|
|
17
|
+
scrollSurface,
|
|
18
|
+
scroller,
|
|
19
|
+
} from '@/client/lib/scrollbar-probe.test-util';
|
|
20
|
+
|
|
21
|
+
beforeAll(saveNativeGlobals);
|
|
22
|
+
afterAll(restoreNativeGlobals);
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
jest.useRealTimers();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The bar appears the moment the reader scrolls.
|
|
29
|
+
*
|
|
30
|
+
* Every case here asserts paint WITHOUT a `scroll` event: the reveal is driven
|
|
31
|
+
* by the input itself, so these fail if the rule goes back to waiting for the
|
|
32
|
+
* frame the browser dispatches `scroll` on (the reported "the scrollbar does
|
|
33
|
+
* not show up immediately when I scroll"). Measured before this rule: the
|
|
34
|
+
* attribute landed 13-27ms after a wheel, on the scroll frame, and a scroll
|
|
35
|
+
* the gate declined painted nothing at all.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
describe('the scrollbar reveal on input', () => {
|
|
39
|
+
test('a wheel paints the surface it is over, before any scroll event', () => {
|
|
40
|
+
jest.useFakeTimers();
|
|
41
|
+
freshPage();
|
|
42
|
+
const box = scrollSurface();
|
|
43
|
+
|
|
44
|
+
// No `scrollAt()`: this is the whole point. The bar is painted by the
|
|
45
|
+
// input, not by a scroll event the browser dispatches a frame later (or
|
|
46
|
+
// never, when the gate declines it). Measured before this rule: the
|
|
47
|
+
// attribute landed 13-27ms after the wheel, i.e. on the scroll frame, and
|
|
48
|
+
// a scroll the gate refused painted nothing at all.
|
|
49
|
+
inputAt(box);
|
|
50
|
+
|
|
51
|
+
expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('a wheel over a child paints the scroller that holds it', () => {
|
|
55
|
+
jest.useFakeTimers();
|
|
56
|
+
freshPage();
|
|
57
|
+
const box = scrollSurface();
|
|
58
|
+
const row = document.createElement('p');
|
|
59
|
+
box.appendChild(row);
|
|
60
|
+
|
|
61
|
+
inputAt(row);
|
|
62
|
+
|
|
63
|
+
expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
|
|
64
|
+
expect(row.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('a wheel over something that cannot scroll paints nothing', () => {
|
|
68
|
+
jest.useFakeTimers();
|
|
69
|
+
freshPage();
|
|
70
|
+
const plain = scroller();
|
|
71
|
+
|
|
72
|
+
inputAt(plain);
|
|
73
|
+
|
|
74
|
+
// The page's own reveal belongs to its `scroll` event, where the painted
|
|
75
|
+
// surface is the root element. Lighting it here would paint the page's bar
|
|
76
|
+
// for a wheel that moved nothing at all.
|
|
77
|
+
expect(plain.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
|
|
78
|
+
expect(document.documentElement.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('every wheel of a gesture restarts the idle window', () => {
|
|
82
|
+
jest.useFakeTimers();
|
|
83
|
+
freshPage();
|
|
84
|
+
const box = scrollSurface();
|
|
85
|
+
|
|
86
|
+
inputAt(box);
|
|
87
|
+
jest.advanceTimersByTime(IDLE_MS - 100);
|
|
88
|
+
inputAt(box);
|
|
89
|
+
jest.advanceTimersByTime(IDLE_MS - 100);
|
|
90
|
+
|
|
91
|
+
// The user is STILL scrolling: a bar that faded here would disappear from
|
|
92
|
+
// under a hand that never stopped.
|
|
93
|
+
expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
|
|
94
|
+
|
|
95
|
+
jest.advanceTimersByTime(100);
|
|
96
|
+
expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('a keyboard scroll reveals the surface the engine scrolled', () => {
|
|
100
|
+
jest.useFakeTimers();
|
|
101
|
+
freshPage();
|
|
102
|
+
const box = scroller();
|
|
103
|
+
|
|
104
|
+
// MEASURED in Chromium and WebKit 27.2: PageDown with nothing focused walks
|
|
105
|
+
// the focused scroll chain, so the keydown's target is `body` while the
|
|
106
|
+
// panel that moves is a sibling subtree. Binding the arm to `body` refused
|
|
107
|
+
// every keyboard scroll, so the bar never appeared for them.
|
|
108
|
+
keyAt('PageDown');
|
|
109
|
+
scrollAt(box);
|
|
110
|
+
|
|
111
|
+
expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('a key that cannot scroll does not arm a reveal', () => {
|
|
115
|
+
jest.useFakeTimers();
|
|
116
|
+
freshPage();
|
|
117
|
+
const box = scroller();
|
|
118
|
+
|
|
119
|
+
// Typing in the composer must not let a stream's next auto-follow paint a
|
|
120
|
+
// bar: the key says nothing about scrolling.
|
|
121
|
+
keyAt('a');
|
|
122
|
+
scrollAt(box);
|
|
123
|
+
|
|
124
|
+
expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The scaffolding both scrollbar suites mount against.
|
|
8
|
+
*
|
|
9
|
+
* Every case gets its OWN document and its own install, because the module is
|
|
10
|
+
* idempotent per document and its input clock is per install: a shared document
|
|
11
|
+
* would make every case inherit the previous one's wheel (and would make a
|
|
12
|
+
* `useFakeTimers` clock that restarts at real time read as recent input).
|
|
13
|
+
*
|
|
14
|
+
* Mounted against happy-dom, the same way the other client tests are.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { SCROLLBAR_INPUT_ARM_MS, installScrollbarActivity } from '@/client/lib/scrollbar-activity';
|
|
19
|
+
|
|
20
|
+
const DOM_GLOBALS = [
|
|
21
|
+
'window',
|
|
22
|
+
'document',
|
|
23
|
+
'navigator',
|
|
24
|
+
'Node',
|
|
25
|
+
'Element',
|
|
26
|
+
'HTMLElement',
|
|
27
|
+
'Event',
|
|
28
|
+
'CustomEvent',
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
/** Short enough to drive in a test, long enough that the two windows do not overlap. */
|
|
32
|
+
export const IDLE_MS = 1_000;
|
|
33
|
+
/** The production arm; its real value is what the gate is about. */
|
|
34
|
+
export const ARM_MS = SCROLLBAR_INPUT_ARM_MS;
|
|
35
|
+
|
|
36
|
+
/** The runner's own globals, restored on teardown so later files still see native Event/CustomEvent/window. */
|
|
37
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
38
|
+
|
|
39
|
+
export function saveNativeGlobals(): void {
|
|
40
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
41
|
+
for (const key of DOM_GLOBALS) {
|
|
42
|
+
if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function restoreNativeGlobals(): void {
|
|
47
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
48
|
+
for (const key of DOM_GLOBALS) {
|
|
49
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
50
|
+
else target[key] = nativeGlobals[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A fresh document with the reveal rule installed on it. */
|
|
55
|
+
export function freshPage(): void {
|
|
56
|
+
const win = new Window({ url: 'http://localhost' });
|
|
57
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
58
|
+
for (const key of DOM_GLOBALS) target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
59
|
+
installScrollbarActivity(IDLE_MS, ARM_MS);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A scroll container in the live document. */
|
|
63
|
+
export function scroller(): HTMLElement {
|
|
64
|
+
const element = document.createElement('div');
|
|
65
|
+
document.body.appendChild(element);
|
|
66
|
+
return element;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A container that MEASURES as scrollable.
|
|
71
|
+
*
|
|
72
|
+
* happy-dom lays nothing out, so every `scrollHeight`/`clientHeight` is 0 and
|
|
73
|
+
* the "can this overflow" test the input path uses would skip every node. The
|
|
74
|
+
* numbers are what Chromium reports for the same DOM shape.
|
|
75
|
+
*/
|
|
76
|
+
export function scrollSurface(): HTMLElement {
|
|
77
|
+
const element = document.createElement('div');
|
|
78
|
+
element.style.overflowY = 'auto';
|
|
79
|
+
Object.defineProperties(element, {
|
|
80
|
+
scrollHeight: { value: 900, configurable: true },
|
|
81
|
+
clientHeight: { value: 300, configurable: true },
|
|
82
|
+
scrollWidth: { value: 100, configurable: true },
|
|
83
|
+
clientWidth: { value: 100, configurable: true },
|
|
84
|
+
});
|
|
85
|
+
document.body.appendChild(element);
|
|
86
|
+
return element;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The event a browser dispatches at a scroller — it does not bubble. */
|
|
90
|
+
export function scrollAt(element: Element): void {
|
|
91
|
+
element.dispatchEvent(new Event('scroll'));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The input a browser delivers before a scroll the USER caused.
|
|
95
|
+
*
|
|
96
|
+
* Dispatched ON the scroller, because that is what a wheel does: it is targeted
|
|
97
|
+
* at the element under the pointer, and the arm is bound to that subtree so a
|
|
98
|
+
* wheel that could not move its container cannot later vouch for a programmatic
|
|
99
|
+
* scroll somewhere else. */
|
|
100
|
+
export function inputAt(element: Element = document.body): void {
|
|
101
|
+
element.dispatchEvent(new Event('wheel'));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The keydown a browser delivers when the reader presses a scrolling key. */
|
|
105
|
+
export function keyAt(key: string): void {
|
|
106
|
+
document.body.dispatchEvent(new window.KeyboardEvent('keydown', { key, bubbles: true }));
|
|
107
|
+
}
|
package/src/client/tailwind.css
CHANGED
|
@@ -372,6 +372,36 @@
|
|
|
372
372
|
background-color: color-mix(in srgb, var(--theme-error) 75%, var(--theme-ink));
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
/* MONOCHROME: the composer's action pair (Stop / Send) is INK, not red/blue.
|
|
376
|
+
*
|
|
377
|
+
* The pair differs by hue in the colour mode — `bg-error-text` against
|
|
378
|
+
* `bg-info-text` — because that mode is the one place a user asks for chroma.
|
|
379
|
+
* Monochrome is the DEFAULT and it states itself as "every icon in the palette
|
|
380
|
+
* ink" (`icon-paint-ink.ts`), so two filled signal buttons were the only
|
|
381
|
+
* saturated objects left in a window that said it had no colour; reported as
|
|
382
|
+
* "btn send dan btn stop di mode monochrome kenapa masih berwarna?".
|
|
383
|
+
*
|
|
384
|
+
* The fill follows the app's own inverted surface (`bg-ink text-canvas`, used by
|
|
385
|
+
* every primary button), so the pair keeps the same geometry and the glyph's
|
|
386
|
+
* `text-canvas` stays the house pair — the palette's ink/canvas relationship,
|
|
387
|
+
* which is the one every body text already relies on.
|
|
388
|
+
*
|
|
389
|
+
* These rules are UNLAYERED and scoped to `:root:not([data-icon-style="color"])`
|
|
390
|
+
* for two reasons: a rule inside `@layer utilities` would sit at the same layer
|
|
391
|
+
* as the caller's `bg-info-text` and win only by source order, and the
|
|
392
|
+
* `:not(:disabled)` on hover keeps a disabled Send from re-stating the colour
|
|
393
|
+
* fill it was just moved off. The glyph itself is already handled by
|
|
394
|
+
* `monochromeSolidFillRules`, which keys on the very `bg-info-text` /
|
|
395
|
+
* `bg-error-text` classes this rule repaints.
|
|
396
|
+
*/
|
|
397
|
+
:root:not([data-icon-style="color"]) .composer-action {
|
|
398
|
+
background-color: var(--theme-ink);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
:root:not([data-icon-style="color"]) .composer-action:hover:not(:disabled) {
|
|
402
|
+
background-color: color-mix(in srgb, var(--theme-ink) 90%, transparent);
|
|
403
|
+
}
|
|
404
|
+
|
|
375
405
|
/* (The hero card's dot-grain texture lived here and was used by nothing: the
|
|
376
406
|
deploy hero it decorated is not part of this product. A texture with no
|
|
377
407
|
consumer is a rule that only drifts.) */
|
|
@@ -396,7 +426,8 @@
|
|
|
396
426
|
* The thumb is TRANSPARENT at rest and painted only while the user is
|
|
397
427
|
* scrolling that element. `installScrollbarActivity()` (see
|
|
398
428
|
* `src/client/lib/scrollbar-activity.ts`) puts `data-scrollbar-active` on the
|
|
399
|
-
* scroller itself
|
|
429
|
+
* scroller itself: on the input that starts a scroll, and again on each of its
|
|
430
|
+
* own `scroll` events, keeping it there for 5s after the last one. This
|
|
400
431
|
* stylesheet is the other half of that contract: a global `scroll` listener is
|
|
401
432
|
* one listener for every scroll container in the document, including ones that
|
|
402
433
|
* do not exist yet, which is why no component has to opt in.
|
|
@@ -200,7 +200,9 @@ describe('closeDb', () => {
|
|
|
200
200
|
// slot while `getDb()` was still opening, so the continuation assigned
|
|
201
201
|
// `resolved` on the DROPPED slot object. Nothing could reach that handle
|
|
202
202
|
// again, and on Windows its temp directory stayed locked — `EBUSY … a
|
|
203
|
-
// handle outlived its test`, reported against the two PRECEDING cases.
|
|
203
|
+
// handle outlived its test`, reported against the two PRECEDING cases. A
|
|
204
|
+
// retirement in this window never reaches `createDb`; the `disposed` check
|
|
205
|
+
// after it still closes a handle retired DURING initialisation.
|
|
204
206
|
const savedSlot = globalThis.__kabmoDb;
|
|
205
207
|
try {
|
|
206
208
|
Bun.env.KABMO_DB_PATH = path.join(tempRoot(), 'in-flight', 'db.sqlite');
|
|
@@ -244,6 +246,53 @@ describe('closeDb', () => {
|
|
|
244
246
|
}
|
|
245
247
|
});
|
|
246
248
|
|
|
249
|
+
test('an open uses the path configured when it was requested', async () => {
|
|
250
|
+
// A fire-and-forget `getDb()` can still be resolving while its suite tears
|
|
251
|
+
// down and deletes `KABMO_DB_PATH`. Re-reading the environment at resolution
|
|
252
|
+
// time then opens the DEFAULT path — the developer's real database — so the
|
|
253
|
+
// path is snapshotted when the open is requested.
|
|
254
|
+
const savedSlot = globalThis.__kabmoDb;
|
|
255
|
+
try {
|
|
256
|
+
const requested = path.join(tempRoot(), 'snapshot', 'db.sqlite');
|
|
257
|
+
Bun.env.KABMO_DB_PATH = requested;
|
|
258
|
+
globalThis.__kabmoDb = undefined;
|
|
259
|
+
|
|
260
|
+
const pending = getDb();
|
|
261
|
+
// The teardown that used to redirect this open.
|
|
262
|
+
delete Bun.env.KABMO_DB_PATH;
|
|
263
|
+
|
|
264
|
+
const db = await pending;
|
|
265
|
+
expect(existsSync(requested)).toBe(true);
|
|
266
|
+
await closeDb();
|
|
267
|
+
expect(db).toBeDefined();
|
|
268
|
+
} finally {
|
|
269
|
+
globalThis.__kabmoDb = savedSlot;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('a retired open never creates the file it would have opened', async () => {
|
|
274
|
+
// The leak this pins: an open still resolving its path while the slot is
|
|
275
|
+
// retired used to reach `createDb` and leave a database file behind, then
|
|
276
|
+
// close it and reject. A fire-and-forget caller whose suite had already
|
|
277
|
+
// restored its environment resolved the DEFAULT path, so the file it
|
|
278
|
+
// created was the developer's real `~/.kabmo/db.sqlite` (measured on a full
|
|
279
|
+
// `bun test`, from an ACP child-outcome write finishing after teardown).
|
|
280
|
+
const savedSlot = globalThis.__kabmoDb;
|
|
281
|
+
try {
|
|
282
|
+
const dbPath = path.join(tempRoot(), 'never-opened', 'db.sqlite');
|
|
283
|
+
Bun.env.KABMO_DB_PATH = dbPath;
|
|
284
|
+
globalThis.__kabmoDb = undefined;
|
|
285
|
+
|
|
286
|
+
const pending = getDb();
|
|
287
|
+
await closeDb();
|
|
288
|
+
|
|
289
|
+
await expect(pending).rejects.toThrow(/retired/);
|
|
290
|
+
expect(existsSync(dbPath)).toBe(false);
|
|
291
|
+
} finally {
|
|
292
|
+
globalThis.__kabmoDb = savedSlot;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
247
296
|
test('the returned promise settles only once the in-flight handle is closed', async () => {
|
|
248
297
|
// The bug this pins is a RACE, and it is the one the Release gate hit:
|
|
249
298
|
// retiring the slot is synchronous, but an open already in flight still
|
package/src/server/db.server.ts
CHANGED
|
@@ -113,6 +113,26 @@ function noop(): void {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
export async function getDatabasePath(): Promise<string> {
|
|
116
|
+
return resolveDatabasePath(configuredDbOverride(), isMockMode());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The raw override, read at the instant `getDb()` is CALLED.
|
|
121
|
+
*
|
|
122
|
+
* Reading it later is a real leak: a fire-and-forget write (`void
|
|
123
|
+
* clearStreamStatus(...)`, a debounced discovery-root reconcile) can still be
|
|
124
|
+
* resuming when its suite tears down and deletes `KABMO_DB_PATH`, so the path
|
|
125
|
+
* that was configured for that work is gone by the time it is resolved and the
|
|
126
|
+
* DEFAULT `~/.kabmo/db.sqlite` is opened instead. Measured on a full `bun test`
|
|
127
|
+
* with a tracer around `createDb`: two opens of the developer's database, one
|
|
128
|
+
* from `roots-watch`'s reconcile, one from an ACP child-outcome write, both
|
|
129
|
+
* from an open requested before the suite removed its environment.
|
|
130
|
+
*/
|
|
131
|
+
function configuredDbOverride(): string | undefined {
|
|
132
|
+
return Bun.env.KABMO_DB_PATH || Bun.env.OMPCHAMBER_DB_PATH || Bun.env.DB_PATH;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function resolveDatabasePath(customPath: string | undefined, mock: boolean): Promise<string> {
|
|
116
136
|
// An explicit override wins over BOTH defaults, mock included. It has to come
|
|
117
137
|
// first: the mock default is cwd-relative, so a `MOCK=true` server started
|
|
118
138
|
// from a checkout wrote the repository's own `workspace.db` no matter what
|
|
@@ -120,7 +140,6 @@ export async function getDatabasePath(): Promise<string> {
|
|
|
120
140
|
// instance needs the variable for. Verified before the fix: a mock boot with
|
|
121
141
|
// `KABMO_DB_PATH` set to a temp file still answered the repo path on
|
|
122
142
|
// this line.
|
|
123
|
-
const customPath = Bun.env.KABMO_DB_PATH || Bun.env.OMPCHAMBER_DB_PATH || Bun.env.DB_PATH;
|
|
124
143
|
if (customPath) {
|
|
125
144
|
const resolvedPath = customPath.startsWith('~')
|
|
126
145
|
? path.join(os.homedir(), customPath.slice(1))
|
|
@@ -132,7 +151,7 @@ export async function getDatabasePath(): Promise<string> {
|
|
|
132
151
|
return resolvedPath;
|
|
133
152
|
}
|
|
134
153
|
|
|
135
|
-
if (
|
|
154
|
+
if (mock) {
|
|
136
155
|
return path.join(process.cwd(), 'workspace.db');
|
|
137
156
|
}
|
|
138
157
|
|
|
@@ -163,7 +182,21 @@ export function getDb(): Promise<DbClient> {
|
|
|
163
182
|
if (state.resolved) return Promise.resolve(state.resolved);
|
|
164
183
|
|
|
165
184
|
const opening = (async () => {
|
|
166
|
-
|
|
185
|
+
// Snapshot the configuration HERE, when the open is requested. Resolving it
|
|
186
|
+
// later re-reads an environment a suite may already have restored, which is
|
|
187
|
+
// how a fire-and-forget write opened the developer's `~/.kabmo/db.sqlite`.
|
|
188
|
+
const dbPath = await resolveDatabasePath(configuredDbOverride(), isMockMode());
|
|
189
|
+
|
|
190
|
+
// The slot can be retired WHILE the path is being resolved, and opening a
|
|
191
|
+
// file for it is the leak this check prevents: the handle would be cached
|
|
192
|
+
// on an object nothing reaches (closed again below, only after the file and
|
|
193
|
+
// its schema exist). Measured on a full `bun test`: a fire-and-forget
|
|
194
|
+
// `void clearStreamStatus(...)` outlived its suite's `releaseDb`, so
|
|
195
|
+
// `getDatabasePath` resolved AFTER `KABMO_DB_PATH` was deleted and created
|
|
196
|
+
// the developer's real `~/.kabmo/db.sqlite`. A retired slot must open
|
|
197
|
+
// NOTHING, at any path.
|
|
198
|
+
if (state.disposed) throw new Error('database open was retired before it finished');
|
|
199
|
+
|
|
167
200
|
const db = createDb(dbPath);
|
|
168
201
|
|
|
169
202
|
await initSchema(db);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The prompt-recall store: one row per prompt the operator sent, scoped to a
|
|
8
|
+
* session or merged across all of them, newest first, duplicates collapsed.
|
|
9
|
+
*
|
|
10
|
+
* Runs against a throwaway SQLite file (never the developer's own database).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
14
|
+
import { getDb } from '@/server/db.server';
|
|
15
|
+
import { listPrompts, recordPrompt } from '@/server/lib/chat/prompt-history.server';
|
|
16
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
await isolateDb();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await releaseDb();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('recordPrompt', () => {
|
|
27
|
+
test('stores a prompt under its session', async () => {
|
|
28
|
+
await recordPrompt('s1', 'first prompt');
|
|
29
|
+
expect(await listPrompts('s1')).toEqual(['first prompt']);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('trims the text and ignores an empty prompt', async () => {
|
|
33
|
+
await recordPrompt('s1', ' padded ');
|
|
34
|
+
await recordPrompt('s1', ' ');
|
|
35
|
+
expect(await listPrompts('s1')).toEqual(['padded']);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('ignores a prompt with no session', async () => {
|
|
39
|
+
await recordPrompt(null, 'orphan');
|
|
40
|
+
expect(await listPrompts(null)).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('drops a repeat of the session\'s newest entry', async () => {
|
|
44
|
+
await recordPrompt('s1', 'same');
|
|
45
|
+
await recordPrompt('s1', 'same');
|
|
46
|
+
const db = await getDb();
|
|
47
|
+
const row = await db.get<{ count: number }>('SELECT COUNT(*) AS count FROM prompt_history');
|
|
48
|
+
expect(row?.count).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('keeps a repeat that is not the newest entry', async () => {
|
|
52
|
+
await recordPrompt('s1', 'a');
|
|
53
|
+
await recordPrompt('s1', 'b');
|
|
54
|
+
await recordPrompt('s1', 'a');
|
|
55
|
+
expect(await listPrompts('s1')).toEqual(['a', 'b']);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('listPrompts', () => {
|
|
60
|
+
test('answers newest first', async () => {
|
|
61
|
+
await recordPrompt('s1', 'one');
|
|
62
|
+
await recordPrompt('s1', 'two');
|
|
63
|
+
await recordPrompt('s1', 'three');
|
|
64
|
+
expect(await listPrompts('s1')).toEqual(['three', 'two', 'one']);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('scopes to one session', async () => {
|
|
68
|
+
await recordPrompt('s1', 'mine');
|
|
69
|
+
await recordPrompt('s2', 'theirs');
|
|
70
|
+
expect(await listPrompts('s1')).toEqual(['mine']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('merges every session when no session is named', async () => {
|
|
74
|
+
await recordPrompt('s1', 'mine');
|
|
75
|
+
await recordPrompt('s2', 'theirs');
|
|
76
|
+
expect(await listPrompts(null)).toEqual(['theirs', 'mine']);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('collapses the same text sent in two sessions to its newest occurrence', async () => {
|
|
80
|
+
await recordPrompt('s1', 'shared');
|
|
81
|
+
await recordPrompt('s2', 'other');
|
|
82
|
+
await recordPrompt('s2', 'shared');
|
|
83
|
+
expect(await listPrompts(null)).toEqual(['shared', 'other']);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('honours the limit', async () => {
|
|
87
|
+
await recordPrompt('s1', 'one');
|
|
88
|
+
await recordPrompt('s1', 'two');
|
|
89
|
+
await recordPrompt('s1', 'three');
|
|
90
|
+
expect(await listPrompts('s1', 2)).toEqual(['three', 'two']);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The composer's prompt recall (ArrowUp / ArrowDown).
|
|
8
|
+
*
|
|
9
|
+
* Written at the HTTP boundary where a client's prompt enters (the agent
|
|
10
|
+
* routes), not inside the RPC dispatch: the dispatch also carries Kabmo's own
|
|
11
|
+
* control prompts (`/kabmo-mode …`, title requests, goal kickoffs), and those
|
|
12
|
+
* are not something the operator typed.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { getDb } from '@/server/db.server';
|
|
16
|
+
import { PROMPT_HISTORY_LIMIT } from '@/server/lib/chat/schema.server';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Record one prompt the operator sent.
|
|
20
|
+
*
|
|
21
|
+
* A repeat of the session's newest entry is dropped: a refused send is retried
|
|
22
|
+
* (and a queued item is delivered later) through the same route, and the
|
|
23
|
+
* operator typed the text once. A failed write is logged, never thrown — the
|
|
24
|
+
* prompt itself must not fail because its recall row did.
|
|
25
|
+
*/
|
|
26
|
+
export async function recordPrompt(sessionId: string | null, text: string): Promise<void> {
|
|
27
|
+
const trimmed = text.trim();
|
|
28
|
+
if (!sessionId || !trimmed) return;
|
|
29
|
+
try {
|
|
30
|
+
const db = await getDb();
|
|
31
|
+
const last = await db.get<{ text: string }>(
|
|
32
|
+
'SELECT text FROM prompt_history WHERE session_id = ? ORDER BY id DESC LIMIT 1',
|
|
33
|
+
[sessionId],
|
|
34
|
+
);
|
|
35
|
+
if (last?.text === trimmed) return;
|
|
36
|
+
await db.run('INSERT INTO prompt_history (session_id, text, created_at) VALUES (?, ?, ?)', [
|
|
37
|
+
sessionId,
|
|
38
|
+
trimmed,
|
|
39
|
+
Date.now(),
|
|
40
|
+
]);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('[prompt-history] could not record a prompt:', error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The recall list, newest first.
|
|
48
|
+
*
|
|
49
|
+
* `sessionId` scopes it to one chat; `null` merges every session, which is what
|
|
50
|
+
* a pending `new-…` chat asks for. Duplicates collapse to their newest
|
|
51
|
+
* occurrence — the same prompt sent in two chats is one thing to recall.
|
|
52
|
+
*/
|
|
53
|
+
export async function listPrompts(sessionId: string | null, limit = PROMPT_HISTORY_LIMIT): Promise<string[]> {
|
|
54
|
+
const db = await getDb();
|
|
55
|
+
const rows = sessionId
|
|
56
|
+
? await db.all<{ text: string }>(
|
|
57
|
+
'SELECT text, MAX(id) AS last_id FROM prompt_history WHERE session_id = ? GROUP BY text ORDER BY last_id DESC LIMIT ?',
|
|
58
|
+
[sessionId, limit],
|
|
59
|
+
)
|
|
60
|
+
: await db.all<{ text: string }>(
|
|
61
|
+
'SELECT text, MAX(id) AS last_id FROM prompt_history GROUP BY text ORDER BY last_id DESC LIMIT ?',
|
|
62
|
+
[limit],
|
|
63
|
+
);
|
|
64
|
+
return rows.map((row) => row.text);
|
|
65
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Prompt-recall schema, kept out of `db.server.ts`'s bootstrap block for the
|
|
8
|
+
* same reason `btw/schema.server.ts` and `waiting/schema.server.ts` are: called
|
|
9
|
+
* once per database open, from `initSchema`.
|
|
10
|
+
*
|
|
11
|
+
* A table of its own rather than a scan of the transcripts: a session's user
|
|
12
|
+
* turns live in omp's JSONL (or the `chat_sessions` overlay), so the merged
|
|
13
|
+
* list a NEW chat asks for would mean reading every session file on the
|
|
14
|
+
* machine. One indexed row per dispatched prompt answers both scopes.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
18
|
+
|
|
19
|
+
const PROMPT_HISTORY_SCHEMA_SQL = `
|
|
20
|
+
CREATE TABLE IF NOT EXISTS prompt_history (
|
|
21
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
22
|
+
session_id TEXT NOT NULL,
|
|
23
|
+
text TEXT NOT NULL,
|
|
24
|
+
created_at INTEGER NOT NULL
|
|
25
|
+
);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS idx_prompt_history_session ON prompt_history (session_id, id);
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
/** How many entries one recall list may carry. */
|
|
30
|
+
export const PROMPT_HISTORY_LIMIT = 200;
|
|
31
|
+
|
|
32
|
+
/** Idempotent: the prompt-recall table, created on every database open. */
|
|
33
|
+
export async function ensurePromptHistorySchema(db: DbClient): Promise<void> {
|
|
34
|
+
await db.exec(PROMPT_HISTORY_SCHEMA_SQL);
|
|
35
|
+
}
|
|
@@ -24,6 +24,7 @@ import { ensureWorktreeSchema } from '@/server/lib/db/worktree-registry.server';
|
|
|
24
24
|
import { ensureReviewSchema } from '@/server/lib/review/schema.server';
|
|
25
25
|
import { ensureHarnessSchema } from '@/server/lib/harness/schema.server';
|
|
26
26
|
import { ensureSessionRelationsSchema } from '@/server/lib/sessions/schema.server';
|
|
27
|
+
import { ensurePromptHistorySchema } from '@/server/lib/chat/schema.server';
|
|
27
28
|
import { migrateWorkspaceFolderColumns } from '@/shared/lib/workspace/schema-migrations';
|
|
28
29
|
import { migrateSessionStreamStateColumns } from '@/shared/lib/omp/session/schema-migrations';
|
|
29
30
|
|
|
@@ -146,6 +147,8 @@ export async function initSchema(db: DbClient): Promise<void> {
|
|
|
146
147
|
// Session trees: parent, cleanup ownership and fork origin. Keyed by the id
|
|
147
148
|
// the sidebar and the URL use, so it works for omp files and ACP sessions.
|
|
148
149
|
await ensureSessionRelationsSchema(db);
|
|
150
|
+
// The composer's ArrowUp recall: one row per prompt the operator sent.
|
|
151
|
+
await ensurePromptHistorySchema(db);
|
|
149
152
|
await db.exec(`
|
|
150
153
|
CREATE TABLE IF NOT EXISTS files (
|
|
151
154
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|