@kabmo-labs/kabmo 0.28.0 → 0.30.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-5vjbp04s.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-palette.test.ts +72 -0
- package/src/client/glass.css +39 -14
- package/src/client/glass.test.ts +28 -67
- 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-dirty-tracking.test.ts +73 -0
- package/src/client/hooks/editor/use-dirty-tracking.ts +96 -0
- package/src/client/hooks/editor/use-file-cache.ts +1 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
- package/src/client/hooks/editor/use-file-editor.ts +20 -17
- 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 +198 -0
- package/src/server/lib/fs/archive.ts +278 -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/icons/tint-hues.generated.ts +14 -13
- 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/file-editor.test-util.ts +3 -2
- package/src/test-support/glass-css.ts +30 -0
- 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
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,
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The archive verbs against the real system tools.
|
|
8
|
+
*
|
|
9
|
+
* The formats are gated on `Bun.which` so the suite measures the machine it
|
|
10
|
+
* runs on instead of assuming `rar` exists: a CI image without `7z` must skip
|
|
11
|
+
* that case, not fail. The round trips are the point — a command that exits 0
|
|
12
|
+
* but stores the wrong paths is exactly what a naming bug looks like.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { gzipSync } from 'node:zlib';
|
|
20
|
+
import { compressEntries, compressFormats, extractArchive, findTool } from '@/server/lib/fs/archive';
|
|
21
|
+
import { runShell } from '@/server/lib/fs/shell';
|
|
22
|
+
|
|
23
|
+
let dir: string;
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-archive-'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function write(rel: string, content: string): string {
|
|
34
|
+
const target = path.join(dir, rel);
|
|
35
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
36
|
+
fs.writeFileSync(target, content);
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const hasZip = Bun.which('zip') !== null && Bun.which('unzip') !== null;
|
|
41
|
+
const hasTar = Bun.which('tar') !== null;
|
|
42
|
+
const hasGzip = Bun.which('gzip') !== null;
|
|
43
|
+
const hasBzip2 = Bun.which('bzip2') !== null;
|
|
44
|
+
const hasXz = Bun.which('xz') !== null;
|
|
45
|
+
|
|
46
|
+
describe('compressFormats', () => {
|
|
47
|
+
test('names the tool each format needs and whether it is installed', () => {
|
|
48
|
+
const formats = compressFormats();
|
|
49
|
+
expect(formats.map((format) => format.id)).toEqual(['zip', '7z', 'rar', 'tar', 'tar.gz']);
|
|
50
|
+
for (const format of formats) {
|
|
51
|
+
expect(format.tool).toBeTruthy();
|
|
52
|
+
expect(typeof format.available).toBe('boolean');
|
|
53
|
+
}
|
|
54
|
+
expect(formats.find((format) => format.id === 'zip')?.available).toBe(Bun.which('zip') !== null);
|
|
55
|
+
expect(findTool(['definitely-not-a-binary'])).toBeNull();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('compressEntries / extractArchive', () => {
|
|
60
|
+
test.skipIf(!hasZip)('a zip round-trips the selected entries', async () => {
|
|
61
|
+
const a = write('src/a.ts', 'A');
|
|
62
|
+
write('src/deep/b.ts', 'B');
|
|
63
|
+
const destinationDir = path.join(dir, 'src');
|
|
64
|
+
|
|
65
|
+
const compressed = await compressEntries({
|
|
66
|
+
destinationDir,
|
|
67
|
+
name: 'bundle.zip',
|
|
68
|
+
format: 'zip',
|
|
69
|
+
sources: [a, path.join(destinationDir, 'deep')],
|
|
70
|
+
});
|
|
71
|
+
expect(compressed.ok).toBe(true);
|
|
72
|
+
expect(fs.existsSync(path.join(destinationDir, 'bundle.zip'))).toBe(true);
|
|
73
|
+
|
|
74
|
+
const out = path.join(dir, 'unpacked');
|
|
75
|
+
const extracted = await extractArchive({ archivePath: path.join(destinationDir, 'bundle.zip'), destinationDir: out });
|
|
76
|
+
expect(extracted.ok).toBe(true);
|
|
77
|
+
expect(fs.readFileSync(path.join(out, 'a.ts'), 'utf8')).toBe('A');
|
|
78
|
+
expect(fs.readFileSync(path.join(out, 'deep/b.ts'), 'utf8')).toBe('B');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test.skipIf(!hasTar)('a tar.gz round-trips a folder', async () => {
|
|
82
|
+
write('src/a.ts', 'A');
|
|
83
|
+
const destinationDir = dir;
|
|
84
|
+
const compressed = await compressEntries({
|
|
85
|
+
destinationDir,
|
|
86
|
+
name: 'src.tar.gz',
|
|
87
|
+
format: 'tar.gz',
|
|
88
|
+
sources: [path.join(dir, 'src')],
|
|
89
|
+
});
|
|
90
|
+
expect(compressed.ok, compressed.ok ? '' : compressed.error).toBe(true);
|
|
91
|
+
|
|
92
|
+
const out = path.join(dir, 'unpacked');
|
|
93
|
+
const extracted = await extractArchive({ archivePath: path.join(dir, 'src.tar.gz'), destinationDir: out });
|
|
94
|
+
expect(extracted.ok, extracted.ok ? '' : extracted.error).toBe(true);
|
|
95
|
+
expect(fs.readFileSync(path.join(out, 'src/a.ts'), 'utf8')).toBe('A');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test.skipIf(!hasGzip)('a single .gz file decompresses to its stem', async () => {
|
|
99
|
+
const archive = write('notes.txt.gz', '');
|
|
100
|
+
fs.writeFileSync(archive, gzipSync('hello'));
|
|
101
|
+
|
|
102
|
+
const out = path.join(dir, 'out');
|
|
103
|
+
const extracted = await extractArchive({ archivePath: archive, destinationDir: out });
|
|
104
|
+
expect(extracted.ok).toBe(true);
|
|
105
|
+
expect(fs.readFileSync(path.join(out, 'notes.txt'), 'utf8')).toBe('hello');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('refuses a destination that already exists', async () => {
|
|
109
|
+
const source = write('src/a.ts', 'A');
|
|
110
|
+
write('src/bundle.zip', 'not really a zip');
|
|
111
|
+
|
|
112
|
+
const outcome = await compressEntries({
|
|
113
|
+
destinationDir: path.join(dir, 'src'),
|
|
114
|
+
name: 'bundle.zip',
|
|
115
|
+
format: 'zip',
|
|
116
|
+
sources: [source],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(outcome.ok).toBe(false);
|
|
120
|
+
if (!outcome.ok) expect(outcome.error).toContain('already exists');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('refuses a source outside the destination folder', async () => {
|
|
124
|
+
const source = write('other/a.ts', 'A');
|
|
125
|
+
const outcome = await compressEntries({
|
|
126
|
+
destinationDir: path.join(dir, 'src'),
|
|
127
|
+
name: 'bundle.zip',
|
|
128
|
+
format: 'zip',
|
|
129
|
+
sources: [source],
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(outcome.ok).toBe(false);
|
|
133
|
+
if (!outcome.ok) expect(outcome.error).toContain('contains every selected item');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// The refusal is a property of the REQUEST, so it must not depend on which
|
|
137
|
+
// tools this machine happens to have: the Windows gate has no `zip`, and both
|
|
138
|
+
// refusal cases above answered "zip is not installed" there instead of the
|
|
139
|
+
// 409/400 they assert. `rar` is the format least likely to be installed, so
|
|
140
|
+
// this case fails on the ordering wherever it runs.
|
|
141
|
+
test('an invalid request is refused before the tool is looked up', async () => {
|
|
142
|
+
const source = write('src/a.ts', 'A');
|
|
143
|
+
write('src/bundle.rar', 'not really a rar');
|
|
144
|
+
|
|
145
|
+
const outcome = await compressEntries({
|
|
146
|
+
destinationDir: path.join(dir, 'src'),
|
|
147
|
+
name: 'bundle.rar',
|
|
148
|
+
format: 'rar',
|
|
149
|
+
sources: [source],
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(outcome.ok).toBe(false);
|
|
153
|
+
if (!outcome.ok) {
|
|
154
|
+
expect(outcome.status).toBe(409);
|
|
155
|
+
expect(outcome.error).toContain('already exists');
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// The birth of the regression this pins: `tar -xf -` opened a `.tar.gz` that
|
|
160
|
+
// `tar -xzf -` opened, on one machine, and refused it on another with "Archive
|
|
161
|
+
// is compressed. Use -z option". A compressed stream cannot be sniffed the way
|
|
162
|
+
// a named file can, so the decompressor is named per kind — and each kind is
|
|
163
|
+
// checked against the tool that produces it rather than assumed.
|
|
164
|
+
test.skipIf(!hasTar || !hasBzip2)('a .tar.bz2 names its decompressor', async () => {
|
|
165
|
+
write('src/a.ts', 'A');
|
|
166
|
+
const archive = path.join(dir, 'src.tar.bz2');
|
|
167
|
+
// Relative names with the temp dir as the cwd: GNU tar reads a `C:\…`
|
|
168
|
+
// argument as a REMOTE `host:path` and dies with "Cannot connect to C:",
|
|
169
|
+
// which is the same trap `extractArchive` avoids by feeding the archive on
|
|
170
|
+
// stdin. Measured on the Windows gate.
|
|
171
|
+
const packed = await runShell('tar -cjf src.tar.bz2 ./src', { cwd: dir });
|
|
172
|
+
expect(packed.exitCode).toBe(0);
|
|
173
|
+
|
|
174
|
+
const out = path.join(dir, 'unpacked-bz2');
|
|
175
|
+
const extracted = await extractArchive({ archivePath: archive, destinationDir: out });
|
|
176
|
+
expect(extracted.ok, extracted.ok ? '' : extracted.error).toBe(true);
|
|
177
|
+
expect(fs.readFileSync(path.join(out, 'src/a.ts'), 'utf8')).toBe('A');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test.skipIf(!hasTar || !hasXz)('a .tar.xz names its decompressor', async () => {
|
|
181
|
+
write('src/a.ts', 'A');
|
|
182
|
+
const archive = path.join(dir, 'src.tar.xz');
|
|
183
|
+
const packed = await runShell('tar -cJf src.tar.xz ./src', { cwd: dir });
|
|
184
|
+
expect(packed.exitCode).toBe(0);
|
|
185
|
+
|
|
186
|
+
const out = path.join(dir, 'unpacked-xz');
|
|
187
|
+
const extracted = await extractArchive({ archivePath: archive, destinationDir: out });
|
|
188
|
+
expect(extracted.ok, extracted.ok ? '' : extracted.error).toBe(true);
|
|
189
|
+
expect(fs.readFileSync(path.join(out, 'src/a.ts'), 'utf8')).toBe('A');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('refuses a file that is not an archive', async () => {
|
|
193
|
+
const archive = write('notes.txt', 'hello');
|
|
194
|
+
const outcome = await extractArchive({ archivePath: archive, destinationDir: path.join(dir, 'out') });
|
|
195
|
+
expect(outcome.ok).toBe(false);
|
|
196
|
+
if (!outcome.ok) expect(outcome.status).toBe(400);
|
|
197
|
+
});
|
|
198
|
+
});
|