@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.
Files changed (232) hide show
  1. package/bunfig.toml +6 -0
  2. package/dist/client/index.html +2 -2
  3. package/dist/client/index.js +481 -472
  4. package/dist/client/static/js/{index-xzvyrxya.js → index-5vjbp04s.js} +1193 -1049
  5. package/dist/client/static/js/index-naa91727.css +1 -0
  6. package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
  7. package/package.json +3 -2
  8. package/public/manifest.webmanifest +1 -0
  9. package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
  10. package/src/client/components/common/ComposerTextarea.tsx +6 -0
  11. package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
  12. package/src/client/components/common/ReloadPageButton.tsx +11 -2
  13. package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
  14. package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
  15. package/src/client/components/common/file-icon/index.tsx +7 -1
  16. package/src/client/components/common/harness-glyph/brands.ts +7 -1
  17. package/src/client/components/common/image-viewer/index.tsx +37 -165
  18. package/src/client/components/common/picker-search/index.tsx +70 -0
  19. package/src/client/components/common/search-select/index.tsx +2 -7
  20. package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
  21. package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
  22. package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
  23. package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
  26. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
  28. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
  29. package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
  30. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +6 -4
  31. package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
  32. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +25 -0
  33. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
  34. package/src/client/components/settings/Sidebar.tsx +6 -8
  35. package/src/client/components/settings/categories/HarnessSettings.tsx +4 -2
  36. package/src/client/components/settings/categories/PanelPluginSettings.tsx +2 -2
  37. package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
  38. package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
  39. package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
  40. package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
  41. package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
  42. package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
  43. package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
  44. package/src/client/components/settings/groups.test.tsx +2 -2
  45. package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
  46. package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
  47. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +4 -1
  48. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
  49. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +8 -3
  50. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
  51. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +42 -15
  52. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +28 -0
  53. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +28 -10
  54. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
  55. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
  56. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
  57. package/src/client/components/workspace/editor/FilePane.tsx +32 -0
  58. package/src/client/components/workspace/editor/Toolbar.tsx +4 -0
  59. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +1 -0
  60. package/src/client/components/workspace/editor/toolbar-clusters.tsx +5 -2
  61. package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
  62. package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
  63. package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
  64. package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
  65. package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
  66. package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
  67. package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
  68. package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
  69. package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
  70. package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
  71. package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
  72. package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
  73. package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
  74. package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
  75. package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
  76. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
  77. package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
  78. package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
  79. package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
  80. package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
  81. package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
  82. package/src/client/components/workspace/file-explorer/index.tsx +53 -29
  83. package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
  84. package/src/client/data/settings/omp-schema.json +169 -22
  85. package/src/client/glass-palette.test.ts +72 -0
  86. package/src/client/glass.css +39 -14
  87. package/src/client/glass.test.ts +28 -67
  88. package/src/client/hooks/chat/composer/history.test.ts +267 -0
  89. package/src/client/hooks/chat/composer/history.ts +146 -0
  90. package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
  91. package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
  92. package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
  93. package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
  94. package/src/client/hooks/editor/file-editor-types.ts +15 -0
  95. package/src/client/hooks/editor/save-bytes.ts +79 -0
  96. package/src/client/hooks/editor/use-dirty-tracking.test.ts +73 -0
  97. package/src/client/hooks/editor/use-dirty-tracking.ts +96 -0
  98. package/src/client/hooks/editor/use-file-cache.ts +1 -0
  99. package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
  100. package/src/client/hooks/editor/use-file-editor.ts +20 -17
  101. package/src/client/hooks/editor/use-file-read.ts +21 -2
  102. package/src/client/hooks/editor/use-grid-selection.ts +160 -0
  103. package/src/client/hooks/models/use-harness-update.test.ts +35 -2
  104. package/src/client/hooks/models/use-harness-update.ts +49 -10
  105. package/src/client/hooks/workspace/diff-file.test.ts +72 -0
  106. package/src/client/hooks/workspace/diff-file.ts +12 -6
  107. package/src/client/hooks/workspace/file-archive.ts +220 -0
  108. package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
  109. package/src/client/hooks/workspace/file-clipboard.ts +37 -26
  110. package/src/client/hooks/workspace/file-selection.test.ts +67 -0
  111. package/src/client/hooks/workspace/file-selection.ts +156 -0
  112. package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
  113. package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
  114. package/src/client/lib/editor/workbook-drafts.ts +42 -0
  115. package/src/client/lib/launch/file-handlers.ts +2 -2
  116. package/src/client/lib/scrollbar-activity.test.ts +21 -88
  117. package/src/client/lib/scrollbar-activity.ts +71 -73
  118. package/src/client/lib/scrollbar-events.ts +143 -0
  119. package/src/client/lib/scrollbar-input.test.ts +126 -0
  120. package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
  121. package/src/client/tailwind.css +32 -1
  122. package/src/server/db.server.test.ts +50 -1
  123. package/src/server/db.server.ts +36 -3
  124. package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
  125. package/src/server/lib/chat/prompt-history.server.ts +65 -0
  126. package/src/server/lib/chat/schema.server.ts +35 -0
  127. package/src/server/lib/db/schema.ts +3 -0
  128. package/src/server/lib/fs/archive.test.ts +198 -0
  129. package/src/server/lib/fs/archive.ts +278 -0
  130. package/src/server/lib/fs/git-diff.test.ts +26 -1
  131. package/src/server/lib/fs/git-diff.ts +43 -15
  132. package/src/server/lib/harness/launch-table.ts +19 -0
  133. package/src/server/lib/harness/provider-entry.ts +1 -1
  134. package/src/server/lib/harness/provider-file.server.ts +1 -1
  135. package/src/server/lib/harness/provider-sources.server.ts +2 -1
  136. package/src/server/lib/harness/provider-write.server.ts +2 -1
  137. package/src/server/lib/harness/update-job-store.ts +12 -0
  138. package/src/server/lib/harness/update-queue.server.ts +15 -10
  139. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
  140. package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
  141. package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
  142. package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
  143. package/src/server/lib/omp/session/delete.server.ts +1 -0
  144. package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
  145. package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
  146. package/src/server/lib/panels/auto-update.server.test.ts +5 -2
  147. package/src/server/lib/panels/git-update.server.test.ts +5 -2
  148. package/src/server/lib/panels/install.server.test.ts +5 -2
  149. package/src/server/lib/panels/remove.server.test.ts +5 -2
  150. package/src/server/routes/agent/command.ts +11 -0
  151. package/src/server/routes/agent/new.ts +5 -0
  152. package/src/server/routes/chat/index.ts +5 -0
  153. package/src/server/routes/chat/prompt-history.test.ts +67 -0
  154. package/src/server/routes/chat/prompt-history.ts +31 -0
  155. package/src/server/routes/chat/stream.test.ts +21 -0
  156. package/src/server/routes/chat/stream.ts +5 -0
  157. package/src/server/routes/fs/action-archive.test.ts +128 -0
  158. package/src/server/routes/fs/action-bulk.ts +106 -0
  159. package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
  160. package/src/server/routes/fs/action-transfer.test.ts +26 -0
  161. package/src/server/routes/fs/action.ts +91 -11
  162. package/src/server/routes/fs/archive.ts +20 -0
  163. package/src/server/routes/fs/grant.test.ts +5 -2
  164. package/src/server/routes/fs/index.ts +2 -0
  165. package/src/server/routes/fs/scope.test.ts +6 -2
  166. package/src/server/routes/harness/import-action.ts +1 -1
  167. package/src/server/routes/harness/root.ts +6 -1
  168. package/src/server/routes/harness/summary.test.ts +50 -0
  169. package/src/server/routes/harness/update-status.ts +41 -2
  170. package/src/server/routes/harness/update.test.ts +56 -2
  171. package/src/server/routes/sessions/delete.test.ts +4 -0
  172. package/src/shared/lib/chat/ask-form/index.ts +39 -31
  173. package/src/shared/lib/chat/ask-form/labels.ts +46 -0
  174. package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
  175. package/src/shared/lib/chat/ask-form.test.ts +57 -0
  176. package/src/shared/lib/chat/ask-questions.ts +31 -0
  177. package/src/shared/lib/chat/composer/history.test.ts +67 -0
  178. package/src/shared/lib/chat/composer/history.ts +61 -0
  179. package/src/shared/lib/chat/irc-notice.ts +42 -0
  180. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
  181. package/src/shared/lib/chat/todo/parser.ts +6 -4
  182. package/src/shared/lib/fs/archive.test.ts +101 -0
  183. package/src/shared/lib/fs/archive.ts +191 -0
  184. package/src/shared/lib/fs/clipboard.test.ts +32 -7
  185. package/src/shared/lib/fs/clipboard.ts +59 -14
  186. package/src/shared/lib/fs/csv.test.ts +50 -0
  187. package/src/shared/lib/fs/csv.ts +40 -0
  188. package/src/shared/lib/fs/document-kind.test.ts +13 -6
  189. package/src/shared/lib/fs/document-kind.ts +18 -6
  190. package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
  191. package/src/shared/lib/fs/file-kind.test.ts +2 -7
  192. package/src/shared/lib/fs/file-kind.ts +4 -2
  193. package/src/shared/lib/fs/grid-edit.test.ts +24 -0
  194. package/src/shared/lib/fs/grid-edit.ts +29 -0
  195. package/src/shared/lib/fs/grid-selection.test.ts +137 -0
  196. package/src/shared/lib/fs/grid-selection.ts +138 -0
  197. package/src/shared/lib/harness/brand-color.ts +5 -0
  198. package/src/shared/lib/harness/catalog.test.ts +22 -0
  199. package/src/shared/lib/harness/catalog.ts +12 -1
  200. package/src/shared/lib/harness/config-fields.test.ts +25 -0
  201. package/src/shared/lib/harness/config-fields.ts +33 -3
  202. package/src/shared/lib/harness/dialects.ts +1 -1
  203. package/src/shared/lib/harness/mcp-facts.ts +4 -0
  204. package/src/shared/lib/harness/provider-contracts.ts +109 -0
  205. package/src/shared/lib/harness/provider-facts.test.ts +2 -1
  206. package/src/shared/lib/harness/provider-facts.ts +24 -115
  207. package/src/shared/lib/harness/provider-lookup.ts +37 -0
  208. package/src/shared/lib/harness/providers.ts +2 -1
  209. package/src/shared/lib/harness/updates.ts +10 -0
  210. package/src/shared/lib/icons/tint-hues.generated.ts +14 -13
  211. package/src/shared/lib/omp/session/mapper.test.ts +31 -0
  212. package/src/shared/lib/omp/session/mapper.ts +17 -0
  213. package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
  214. package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
  215. package/src/shared/lib/omp/session/messages-map.ts +17 -0
  216. package/src/shared/lib/omp/session/wait.ts +10 -1
  217. package/src/shared/lib/settings/sections.ts +8 -4
  218. package/src/shared/lib/ui/picker-filter.test.ts +23 -0
  219. package/src/shared/lib/ui/picker-filter.ts +20 -0
  220. package/src/shared/types/chat.ts +4 -0
  221. package/src/shared/types/harness.ts +5 -1
  222. package/src/shared/types/omp/session.ts +18 -0
  223. package/src/shared/types/settings/state.ts +6 -6
  224. package/src/shared/types/todo.ts +3 -1
  225. package/src/test-support/file-actions.test-util.ts +4 -0
  226. package/src/test-support/file-archive.test-util.ts +41 -0
  227. package/src/test-support/file-clipboard.test-util.ts +9 -6
  228. package/src/test-support/file-editor.test-util.ts +3 -2
  229. package/src/test-support/glass-css.ts +30 -0
  230. package/src/test-support/harness-table.test-util.ts +2 -0
  231. package/src/test-support/preload.ts +46 -0
  232. package/dist/client/static/js/index-81f7berm.css +0 -1
@@ -0,0 +1,278 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Creating and unpacking archives for the Files panel.
8
+ *
9
+ * There is no archive library in this repository, and one is not worth adding:
10
+ * every desktop already carries the platform tools, and a pure-JS replacement
11
+ * would still miss `.rar`. So the work is delegated to the system binaries and
12
+ * the module's job is the two things an external command cannot decide for us:
13
+ * which tool is present, and which failure sentence a user reads when none is.
14
+ *
15
+ * The argv is quoted for `/bin/sh` because `runShell` is the one spawn path in
16
+ * the server with a timeout that kills the whole process group — an archive of
17
+ * a large tree must not outlive the request. Output is captured, not parsed:
18
+ * the tools' own stderr is the best description of a refusal.
19
+ */
20
+
21
+ import path from 'node:path';
22
+ import fs from 'node:fs';
23
+ import { runShell, shellOk, type ShellResult } from '@/server/lib/fs/shell';
24
+ import {
25
+ archiveKindOf,
26
+ type ArchiveFormat,
27
+ COMPRESS_FORMATS,
28
+ } from '@/shared/lib/fs/archive';
29
+
30
+ export interface CompressFormatAvailability {
31
+ id: ArchiveFormat;
32
+ label: string;
33
+ extension: string;
34
+ available: boolean;
35
+ /** The binary the format needs, for the dialog's refusal. */
36
+ tool: string;
37
+ }
38
+
39
+ /** A tool name and the binaries that can stand in for it, best first. */
40
+ const TOOLS: Record<string, readonly string[]> = {
41
+ zip: ['zip'],
42
+ unzip: ['unzip'],
43
+ sevenZip: ['7z', '7zz', '7za'],
44
+ rar: ['rar'],
45
+ unrar: ['unrar'],
46
+ tar: ['tar'],
47
+ bsdtar: ['bsdtar'],
48
+ gzip: ['gzip'],
49
+ bzip2: ['bzip2'],
50
+ xz: ['xz'],
51
+ };
52
+
53
+ /** The first binary of `names` that exists on this machine, or null. */
54
+ export function findTool(names: readonly string[]): string | null {
55
+ for (const name of names) {
56
+ if (Bun.which(name)) return name;
57
+ }
58
+ return null;
59
+ }
60
+
61
+ /** Which compress formats this machine can actually write. */
62
+ export function compressFormats(): CompressFormatAvailability[] {
63
+ return COMPRESS_FORMATS.map((format) => {
64
+ const needed = compressToolFor(format.id);
65
+ return { ...format, available: needed !== null, tool: needed ?? toolLabelFor(format.id) };
66
+ });
67
+ }
68
+
69
+ /** The binary a format writes with, or null when it is not installed. */
70
+ function compressToolFor(format: ArchiveFormat): string | null {
71
+ switch (format) {
72
+ case 'zip':
73
+ return findTool(TOOLS.zip!);
74
+ case '7z':
75
+ return findTool(TOOLS.sevenZip!);
76
+ case 'rar':
77
+ return findTool(TOOLS.rar!);
78
+ case 'tar':
79
+ case 'tar.gz':
80
+ return findTool(TOOLS.tar!);
81
+ }
82
+ }
83
+
84
+ function toolLabelFor(format: ArchiveFormat): string {
85
+ switch (format) {
86
+ case 'zip':
87
+ return 'zip';
88
+ case '7z':
89
+ return '7z';
90
+ case 'rar':
91
+ return 'rar';
92
+ case 'tar':
93
+ case 'tar.gz':
94
+ return 'tar';
95
+ }
96
+ }
97
+
98
+ /** Quote one argument for `/bin/sh`. */
99
+ function q(value: string): string {
100
+ return `'${value.replaceAll("'", `'\\''`)}'`;
101
+ }
102
+
103
+ /** A bounded, single-line description of a failed command. */
104
+ function failureText(result: { stderr: string; stdout: string }, fallback: string): string {
105
+ const text = (result.stderr.trim() || result.stdout.trim()).split('\n')[0]?.trim();
106
+ return text ? text.slice(0, 300) : fallback;
107
+ }
108
+
109
+ export interface CompressOptions {
110
+ /** Absolute folder that becomes the command's working directory. */
111
+ destinationDir: string;
112
+ /** Archive file name, one segment, inside `destinationDir`. */
113
+ name: string;
114
+ format: ArchiveFormat;
115
+ /** Absolute paths of the entries to add; each must live inside the destination. */
116
+ sources: string[];
117
+ }
118
+
119
+ export type ArchiveOutcome = { ok: true; path: string } | { ok: false; error: string; status: number };
120
+
121
+ /**
122
+ * Write `sources` into one new archive beside them.
123
+ *
124
+ * The destination is refused when it exists: the same rule Create, Save As and
125
+ * Rename follow. `--` and a `./` prefix keep a file whose name begins with a
126
+ * dash from being read as an option, and every argument is a path relative to
127
+ * the working directory so the archive stores clean names.
128
+ */
129
+ export async function compressEntries(options: CompressOptions): Promise<ArchiveOutcome> {
130
+ const { destinationDir, name, format, sources } = options;
131
+ if (sources.length === 0) return { ok: false, status: 400, error: 'Nothing to compress' };
132
+
133
+ const destination = path.join(destinationDir, name);
134
+ if (await Bun.file(destination).exists()) {
135
+ return { ok: false, status: 409, error: `${name} already exists` };
136
+ }
137
+
138
+ const relative: string[] = [];
139
+ for (const source of sources) {
140
+ const rel = path.relative(destinationDir, source).split(path.sep).join('/');
141
+ if (rel === '' || rel.startsWith('../') || path.isAbsolute(rel)) {
142
+ return {
143
+ ok: false,
144
+ status: 400,
145
+ error: 'Compress into a folder that contains every selected item',
146
+ };
147
+ }
148
+ relative.push(rel);
149
+ }
150
+
151
+ // The tool is looked up LAST: a request that is invalid whatever is installed
152
+ // must answer 400/409, not "install zip". Measured on the Windows gate, which
153
+ // has no `zip`: both refusal cases reported the missing tool instead of the
154
+ // refusal they assert.
155
+ const binary = compressToolFor(format);
156
+ if (!binary) {
157
+ return {
158
+ ok: false,
159
+ status: 501,
160
+ error: `${toolLabelFor(format)} is not installed on this machine`,
161
+ };
162
+ }
163
+
164
+ const args = relative.map((rel) => `./${rel}`).join(' ');
165
+ const command = (() => {
166
+ switch (format) {
167
+ case 'zip':
168
+ return `${binary} -r -q ${q(name)} ${args}`;
169
+ case '7z':
170
+ return `${binary} a -y -- ${q(name)} ${args}`;
171
+ case 'rar':
172
+ return `${binary} a -r -ep1 ${q(name)} ${args}`;
173
+ case 'tar':
174
+ return `${binary} -cf ${q(name)} ${args}`;
175
+ case 'tar.gz':
176
+ return `${binary} -czf ${q(name)} ${args}`;
177
+ }
178
+ })();
179
+
180
+ const result = await runShell(command, { cwd: destinationDir, timeout: 120_000 });
181
+ if (!shellOk(result)) {
182
+ return { ok: false, status: 500, error: failureText(result, `Could not write ${name}`) };
183
+ }
184
+ return { ok: true, path: destination };
185
+ }
186
+
187
+ export interface ExtractOptions {
188
+ /** Absolute archive path. */
189
+ archivePath: string;
190
+ /** Absolute folder the entries land in; created when missing. */
191
+ destinationDir: string;
192
+ }
193
+
194
+ /** Unpack one archive into `destinationDir`. */
195
+ export async function extractArchive(options: ExtractOptions): Promise<ArchiveOutcome> {
196
+ const { archivePath, destinationDir } = options;
197
+ const kind = archiveKindOf(path.basename(archivePath));
198
+ if (!kind) return { ok: false, status: 400, error: 'That file is not a recognised archive' };
199
+
200
+ const stat = await Bun.file(archivePath).stat().catch(() => null);
201
+ if (!stat || stat.isDirectory()) return { ok: false, status: 404, error: 'That archive no longer exists' };
202
+
203
+ await fs.promises.mkdir(destinationDir, { recursive: true });
204
+
205
+ const quotedArchive = q(archivePath);
206
+ const quotedDestination = q(destinationDir);
207
+ const run = (command: string) => runShell(command, { timeout: 300_000 });
208
+
209
+ const archive = quotedArchive;
210
+ const dest = quotedDestination;
211
+ const sevenZip = findTool(TOOLS.sevenZip!);
212
+ const bsdtar = findTool(TOOLS.bsdtar!);
213
+
214
+ switch (kind) {
215
+ case 'zip': {
216
+ const unzip = findTool(TOOLS.unzip!);
217
+ if (unzip) return outcome(await run(`${unzip} -o -q ${archive} -d ${dest}`), archivePath);
218
+ if (bsdtar) return outcome(await run(`${bsdtar} -xf ${archive} -C ${dest}`), archivePath);
219
+ return missingTool('unzip');
220
+ }
221
+ case '7z': {
222
+ if (sevenZip) return outcome(await run(`${sevenZip} x -y -o${dest} ${archive}`), archivePath);
223
+ if (bsdtar) return outcome(await run(`${bsdtar} -xf ${archive} -C ${dest}`), archivePath);
224
+ return missingTool('7z');
225
+ }
226
+ case 'rar': {
227
+ const unrar = findTool(TOOLS.unrar!);
228
+ if (unrar) return outcome(await run(`${unrar} x -o+ ${archive} ${dest}`), archivePath);
229
+ if (sevenZip) return outcome(await run(`${sevenZip} x -y -o${dest} ${archive}`), archivePath);
230
+ if (bsdtar) return outcome(await run(`${bsdtar} -xf ${archive} -C ${dest}`), archivePath);
231
+ return missingTool('unrar or 7z');
232
+ }
233
+ case 'tar':
234
+ case 'tar.gz':
235
+ case 'tar.bz2':
236
+ case 'tar.xz': {
237
+ const tar = findTool(TOOLS.tar!);
238
+ // Two mechanisms, each measured on a gate:
239
+ //
240
+ // - The archive arrives on STDIN, not as `-f <path>`: GNU tar reads a
241
+ // `C:\…` argument as a REMOTE `host:path` and dies with "Cannot
242
+ // connect to C: resolve failed" (the Windows gate, where `tar` is
243
+ // Git's GNU tar). A redirect is the shell's business, so the path
244
+ // never reaches tar's file-spec parser, and bsdtar reads the same
245
+ // stream.
246
+ // - The compression is named EXPLICITLY, because a stream is not
247
+ // sniffed the way a named file is: the Linux gate answered "tar:
248
+ // Archive is compressed. Use -z option" for a `.tar.gz` the same
249
+ // command opened by path. `-z`/`-j`/`-J` are accepted by GNU tar and
250
+ // bsdtar alike.
251
+ const compression = kind === 'tar.gz' ? 'z' : kind === 'tar.bz2' ? 'j' : kind === 'tar.xz' ? 'J' : '';
252
+ if (tar) return outcome(await run(`${tar} -x${compression}f - -C ${dest} < ${archive}`), archivePath);
253
+ if (bsdtar) return outcome(await run(`${bsdtar} -xf ${archive} -C ${dest}`), archivePath);
254
+ return missingTool('tar');
255
+ }
256
+ case 'gz':
257
+ case 'bz2':
258
+ case 'xz': {
259
+ const decompressor = kind === 'gz' ? findTool(TOOLS.gzip!) : kind === 'bz2' ? findTool(TOOLS.bzip2!) : findTool(TOOLS.xz!);
260
+ const outName = path.basename(archivePath).replace(/\.(gz|bz2|xz)$/i, '');
261
+ const out = q(path.join(destinationDir, outName));
262
+ if (decompressor) {
263
+ return outcome(await run(`${decompressor} -dc ${archive} > ${out}`), outName);
264
+ }
265
+ if (bsdtar) return outcome(await run(`${bsdtar} -xf ${archive} -C ${dest}`), archivePath);
266
+ return missingTool(kind);
267
+ }
268
+ }
269
+ }
270
+
271
+ function outcome(result: ShellResult, successPath: string): ArchiveOutcome {
272
+ if (shellOk(result)) return { ok: true, path: successPath };
273
+ return { ok: false, status: 500, error: failureText(result, 'The archive could not be extracted') };
274
+ }
275
+
276
+ function missingTool(name: string): ArchiveOutcome {
277
+ return { ok: false, status: 501, error: `No tool available to extract this archive (install ${name})` };
278
+ }
@@ -51,6 +51,7 @@ beforeAll(() => {
51
51
  git('config', 'user.name', 'Test');
52
52
  write('mod.txt', EIGHT_LINES);
53
53
  write('staged.txt', 's1\n');
54
+ write('both.txt', 'b1\nb2\nb3\n');
54
55
  write('clean.txt', 'c1\n');
55
56
  write('deleted.txt', 'd1\nd2\n');
56
57
  write('sub dir/f.txt', 'sub1\n');
@@ -73,6 +74,11 @@ beforeAll(() => {
73
74
  write('mod.txt', 'l1\nl2\nCHANGED\nl4\nl5\nl6\nl7\nl8\n');
74
75
  write('staged.txt', 's1\ns2\n');
75
76
  git('add', 'staged.txt');
77
+ // One file with BOTH a staged edit and a further unstaged edit: the two
78
+ // views must not answer with the same pair.
79
+ write('both.txt', 'b1\nSTAGED\nb3\n');
80
+ git('add', 'both.txt');
81
+ write('both.txt', 'b1\nSTAGED\nWORKTREE\n');
76
82
  write('untracked.txt', 'u1\nu2\n');
77
83
  git('rm', '-q', 'deleted.txt');
78
84
  write('sub dir/f.txt', 'sub1\nsub2\n');
@@ -124,8 +130,27 @@ describe('tracked changes', () => {
124
130
  expect(result.diff).toContain('+s2');
125
131
  });
126
132
 
133
+ // A file can be in both lists at once. The staged view is HEAD -> index and
134
+ // the unstaged view is index -> working file; reading HEAD vs the working
135
+ // file for both made the two tabs show the same patch.
136
+ test('a file with staged and unstaged edits reports a different pair per view', async () => {
137
+ const staged = await fetchWorkingFileDiff(repo, 'both.txt', true);
138
+ expect(staged.oldContent).toBe('b1\nb2\nb3\n');
139
+ expect(staged.newContent).toBe('b1\nSTAGED\nb3\n');
140
+ expect(staged.diff).toContain('+STAGED');
141
+ expect(staged.diff).not.toContain('WORKTREE');
142
+
143
+ const unstaged = await fetchWorkingFileDiff(repo, 'both.txt', false);
144
+ expect(unstaged.oldContent).toBe('b1\nSTAGED\nb3\n');
145
+ expect(unstaged.newContent).toBe('b1\nSTAGED\nWORKTREE\n');
146
+ expect(unstaged.diff).toContain('+WORKTREE');
147
+ expect(unstaged.diff).not.toContain('+STAGED');
148
+ });
149
+
127
150
  test('a deletion is counted as deletions, not additions', async () => {
128
- const result = await fetchWorkingFileDiff(repo, 'deleted.txt');
151
+ // `git rm` stages the deletion, so the staged view is the one that carries
152
+ // it; the unstaged view of the same file has nothing left to compare.
153
+ const result = await fetchWorkingFileDiff(repo, 'deleted.txt', true);
129
154
  expect(result.status).toBe('D');
130
155
  expect(result.additions).toBe(0);
131
156
  expect(result.deletions).toBe(2);
@@ -24,6 +24,18 @@ async function gitOut(args: string[], cwd: string, timeout: number, maxBuffer: n
24
24
  return result.error === undefined && result.exitCode === 0 ? result.stdout : '';
25
25
  }
26
26
 
27
+ /**
28
+ * One `git show <rev>` read, or `null` when the rev does not resolve.
29
+ *
30
+ * Distinct from `gitOut` because `''` is a real answer here: a file that is
31
+ * empty in the index or at HEAD must not be confused with a path that is
32
+ * absent from that tree — the pair below is chosen from which side exists.
33
+ */
34
+ async function gitShow(rev: string, cwd: string): Promise<string | null> {
35
+ const result = await runGit(['show', rev], { cwd, timeout: 5000 });
36
+ return result.error === undefined && result.exitCode === 0 ? result.stdout : null;
37
+ }
38
+
27
39
  /**
28
40
  * Fetch git diff for a specific file in the working directory or index.
29
41
  *
@@ -68,16 +80,34 @@ export async function fetchWorkingFileDiff(
68
80
  status = statusLine.slice(0, 2).trim() || status;
69
81
  }
70
82
 
71
- // Try reading current new content from disk if it exists
83
+ // The two SIDES depend on which view was asked for, and reading them off
84
+ // the wrong trees is what made a file's staged and unstaged views
85
+ // identical: a staged read compares HEAD with the index, an unstaged read
86
+ // compares the index with the working file. Reading HEAD vs the working
87
+ // file for both is a different diff from either.
88
+ const headContent = await gitShow(`HEAD:${cleanFile}`, targetDir);
89
+ const indexContent = await gitShow(`:0:${cleanFile}`, targetDir);
90
+ let workingContent = '';
72
91
  try {
73
- newContent = await Bun.file(fullPath).text();
92
+ workingContent = await Bun.file(fullPath).text();
74
93
  } catch {
75
- newContent = '';
94
+ workingContent = '';
95
+ }
96
+ if (staged) {
97
+ oldContent = headContent ?? '';
98
+ // `null` means the path is not in the index. For a staged deletion that
99
+ // is the empty side of the pair, not a reason to fall back to the file;
100
+ // an untracked path has no index entry either, and its "would be added"
101
+ // side is the file on disk.
102
+ newContent = indexContent ?? (status === '??' ? workingContent : '');
103
+ } else {
104
+ // An untracked or unmerged path has no stage-0 entry; its "before" side is
105
+ // HEAD for the unmerged case and empty otherwise. A path deleted from the
106
+ // index (`git rm --cached`) is the exception: its index side is empty, so
107
+ // HEAD would claim a change the working tree does not have.
108
+ oldContent = indexContent ?? (status.startsWith('D') ? '' : headContent ?? '');
109
+ newContent = workingContent;
76
110
  }
77
-
78
- // Read old content from index or HEAD
79
- oldContent = await gitOut(['show', `HEAD:${cleanFile}`], targetDir, 5000)
80
- || await gitOut(['show', `:0:${cleanFile}`], targetDir, 5000);
81
111
 
82
112
  // `-U<n>` on every probe: the full-code mode asks for the whole file, and
83
113
  // the diff-only mode keeps git's own default by passing no flag at all.
@@ -91,21 +121,19 @@ export async function fetchWorkingFileDiff(
91
121
  ? Math.max(1024 * 1024 * 16, (oldContent.length + newContent.length) * 2 + 1024 * 1024)
92
122
  : 1024 * 1024 * 2;
93
123
 
124
+ // No fallbacks between the two views. `git diff --cached` is the staged
125
+ // view and `git diff` is the unstaged one; substituting the other when the
126
+ // asked-for diff is empty is how a file listed under "Changes" showed its
127
+ // staged patch.
94
128
  if (staged) {
95
- // 1. Try staged diff (index vs HEAD), 2. HEAD diff, 3. unstaged diff
96
- diff = await gitOut(['diff', ...ctx, '--cached', '--', cleanFile], targetDir, 10000, buf)
97
- || await gitOut(['diff', ...ctx, 'HEAD', '--', cleanFile], targetDir, 10000, buf)
98
- || await gitOut(['diff', ...ctx, '--', cleanFile], targetDir, 10000, buf);
129
+ diff = await gitOut(['diff', ...ctx, '--cached', '--', cleanFile], targetDir, 10000, buf);
99
130
  } else if (status === '??' || status === 'U' || status === '?') {
100
131
  // Untracked file: `--no-index` exits 1 when it produced a diff, so read
101
132
  // stdout directly instead of relying on the exit code.
102
133
  const untracked = await runGit(['diff', ...ctx, '--no-index', '/dev/null', cleanFile], { cwd: targetDir, timeout: 10000, maxBuffer: buf });
103
134
  diff = untracked.stdout.trim() ? untracked.stdout : '';
104
135
  } else {
105
- // 1. Working tree diff, 2. cached diff, 3. HEAD diff
106
- diff = await gitOut(['diff', ...ctx, '--', cleanFile], targetDir, 10000, buf)
107
- || await gitOut(['diff', ...ctx, '--cached', '--', cleanFile], targetDir, 10000, buf)
108
- || await gitOut(['diff', ...ctx, 'HEAD', '--', cleanFile], targetDir, 10000, buf);
136
+ diff = await gitOut(['diff', ...ctx, '--', cleanFile], targetDir, 10000, buf);
109
137
  }
110
138
 
111
139
  // 4. If git diff is still empty but new content exists:
@@ -192,4 +192,23 @@ export const HARNESS_LAUNCH: Readonly<Partial<Record<HarnessId, HarnessLaunch>>>
192
192
  install: 'npm i -g zcode-acp-server zcode-app-cli # the app-server runtime (or install the ZCode desktop app)',
193
193
  note: 'bridges `zcode app-server --stdio`; measured 1 model · 3 thought levels · 5 modes, list/resume/fork + steering; needs a ZCode runtime — the desktop app, or `zcode-app-cli` on PATH (`ZCODE_BIN` for a custom install). Custom providers go in ~/.zcode/v2/provider_config.json; the bridge lists only selectable ones',
194
194
  },
195
+ // jcode's OWN ACP adapter: `jcode acp` runs the stdio server backed by the
196
+ // Jcode daemon (measured against 1jehuang/jcode's `src/cli/acp.rs`). The
197
+ // binary is installed by the vendor's script, so there is no npm package to
198
+ // pin here.
199
+ jcode: {
200
+ id: 'jcode',
201
+ command: ['jcode', 'acp'],
202
+ install: 'curl -fsSL https://jcode.sh/install | bash',
203
+ note: 'ACP adapter backed by the Jcode daemon; configure a provider once in ~/.jcode/config.toml (`jcode provider add …`, or the first `jcode` setup wizard)',
204
+ },
205
+ // Grok Build ships its OWN ACP server; `--always-approve` is deliberately not
206
+ // passed, so tool calls arrive as `session/request_permission` and Kabmo's
207
+ // access tiers decide. Models and reasoning show up as config options.
208
+ grok: {
209
+ id: 'grok',
210
+ command: ['grok', 'agent', 'stdio'],
211
+ install: 'curl -fsSL https://x.ai/cli/install.sh | bash',
212
+ note: 'native ACP (`grok agent stdio`); xAI models need `grok login` once. A custom model as a [model.<name>] table in ~/.grok/config.toml (base_url + api_key) runs WITHOUT an xAI login — measured on 1.0.77. Sessions advertise model + reasoning_effort options',
213
+ },
195
214
  };
@@ -28,7 +28,7 @@
28
28
  * value has to be injected into `env` or all imported models answer 401.
29
29
  */
30
30
 
31
- import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
31
+ import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-contracts';
32
32
  import type { CanonicalProtocol } from '@/shared/lib/harness/dialects';
33
33
  import { dialectFor, wireApiFor } from '@/shared/lib/harness/dialects';
34
34
  import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
@@ -20,7 +20,7 @@
20
20
  import YAML from 'yaml';
21
21
  import { parse as parseToml, stringify as stringifyToml } from 'smol-toml';
22
22
 
23
- import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
23
+ import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-contracts';
24
24
  import { asRecord } from '@/server/lib/harness/provider-entry';
25
25
  import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
26
26
 
@@ -37,7 +37,8 @@ import { join } from 'path';
37
37
  import YAML from 'yaml';
38
38
  import { parse as parseToml } from 'smol-toml';
39
39
 
40
- import { providerFacts, type ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
40
+ import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-contracts';
41
+ import { providerFacts } from '@/shared/lib/harness/provider-lookup';
41
42
  import { protocolOfSourceDialect, type CanonicalProtocol } from '@/shared/lib/harness/dialects';
42
43
  import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
43
44
  import { HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
@@ -29,7 +29,8 @@
29
29
  import { writeFileAtomic } from '@/server/lib/fs/atomic-write';
30
30
  import { parseDocument, providerMap, serialise } from '@/server/lib/harness/provider-file.server';
31
31
  import { withConfigLock } from '@/server/lib/fs/config-lock';
32
- import { providerFacts, type ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
32
+ import type { ProviderRegistryKind } from '@/shared/lib/harness/provider-contracts';
33
+ import { providerFacts } from '@/shared/lib/harness/provider-lookup';
33
34
  import {
34
35
  adaptBaseUrl,
35
36
  dialectFor,
@@ -51,6 +51,18 @@ export async function readUpdateJob(path: string): Promise<HarnessUpdateJob | nu
51
51
  }
52
52
  }
53
53
 
54
+ /**
55
+ * Delete the record.
56
+ *
57
+ * A settled record is a result the reader has seen, and nothing else reads it:
58
+ * the queue only starts WAITING records, and a new press writes a fresh one. So
59
+ * dismissing it is a delete, not a flag — and the row stops carrying a message
60
+ * that has nothing left to say, across a reload included.
61
+ */
62
+ export async function removeUpdateJob(path: string): Promise<void> {
63
+ await fs.promises.rm(path, { force: true });
64
+ }
65
+
54
66
  /** Replace the record atomically. A reader sees the previous one or this one. */
55
67
  export async function writeUpdateJob(job: HarnessUpdateJob, path: string): Promise<void> {
56
68
  const target = path;
@@ -148,16 +148,21 @@ async function probeAfterUpdate(
148
148
  console.error(`[harness-update] probe after updating ${harness} failed:`, cause);
149
149
  }
150
150
  const path = getHarnessUpdateStatusPath(harness);
151
- const current = await readUpdateJob(path);
152
- // A NEW run for the same harness may have replaced the record while this
153
- // probe ran; writing here would revert that run to the previous one.
154
- if (!current || current.startedAt !== startedAt) return;
155
- // The version is stated only when the agent itself answered it: a claim about
156
- // a number nobody read is the fabrication this whole record exists to avoid.
157
- const message = version && current.message && !current.message.includes(version)
158
- ? `${current.message} — it now reports ${version}`
159
- : current.message;
160
- await writeUpdateJob({ ...current, probe: 'done', message }, path);
151
+ // The read and the write are one step against the queue's own passes: a
152
+ // dismissal deletes the record, and a write landing after that delete would
153
+ // resurrect the message the reader just dismissed.
154
+ await serializeUpdateWork(async () => {
155
+ const current = await readUpdateJob(path);
156
+ // A NEW run for the same harness may have replaced the record while this
157
+ // probe ran; writing here would revert that run to the previous one.
158
+ if (!current || current.startedAt !== startedAt) return;
159
+ // The version is stated only when the agent itself answered it: a claim about
160
+ // a number nobody read is the fabrication this whole record exists to avoid.
161
+ const message = version && current.message && !current.message.includes(version)
162
+ ? `${current.message} — it now reports ${version}`
163
+ : current.message;
164
+ await writeUpdateJob({ ...current, probe: 'done', message }, path);
165
+ });
161
166
  }
162
167
 
163
168
  /** Run the probe for a settled record, once per run, in the background. */
@@ -23,11 +23,15 @@
23
23
  * per-file ceiling.
24
24
  */
25
25
 
26
- import { describe, expect, test } from 'bun:test';
26
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
27
27
 
28
28
  import { foldSessionFrame } from '@/server/lib/omp/rpc/frame-fold';
29
29
  import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
30
30
  import { onRealtimeSignal } from '@/server/lib/realtime/signals.server';
31
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
32
+
33
+ beforeEach(isolateDb);
34
+ afterEach(releaseDb);
31
35
 
32
36
  /**
33
37
  * The `tool_execution_end` frame is what moves a running session's sidebar row
@@ -17,12 +17,16 @@
17
17
  * observable proof that the branch was reached.
18
18
  */
19
19
 
20
- import { describe, expect, test } from 'bun:test';
20
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
21
21
 
22
22
  import { foldSessionFrame } from '@/server/lib/omp/rpc/frame-fold';
23
23
  import type { SessionFrameHost } from '@/server/lib/omp/rpc/frame-fold-contract';
24
24
  import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
25
25
  import { makeHost } from '@/server/lib/omp/rpc/frame-fold-host.test-util';
26
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
27
+
28
+ beforeEach(isolateDb);
29
+ afterEach(releaseDb);
26
30
 
27
31
  /** Fold one frame and report the flags the trigger leaves behind. */
28
32
  function fold(host: SessionFrameHost, event: AgentEvent): void {
@@ -13,6 +13,10 @@ import { afterEach, beforeEach, describe, expect, test, vi } from 'bun:test';
13
13
 
14
14
  import { AgentSessionWrapper, WebRpcError } from '@/server/lib/omp/rpc/manager';
15
15
  import { RpcCommandTimeoutError, type RpcProcess } from '@/server/lib/omp/rpc/process';
16
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
17
+
18
+ beforeEach(isolateDb);
19
+ afterEach(releaseDb);
16
20
 
17
21
  /** Commands whose ack is fabricated as timed out; everything else resolves, so
18
22
  * only the timeout policy is under test. */
@@ -38,6 +38,10 @@ import {
38
38
  type AutoTitleHost,
39
39
  } from '@/server/lib/omp/session/auto-title.server';
40
40
  import { titleModelOverlayPath } from '@/server/lib/omp/session/title-model-overlay.server';
41
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
42
+
43
+ beforeAll(isolateDb);
44
+ afterAll(releaseDb);
41
45
 
42
46
  /**
43
47
  * The model pin is a FILE under the agent dir, so the suite points that dir at
@@ -65,6 +65,7 @@ const SESSION_ROW_DELETES: readonly (readonly [string, string])[] = [
65
65
  ['session_ui_state', 'session_id'],
66
66
  ['session_stream_state', 'session_id'],
67
67
  ['queued_messages', 'session_id'],
68
+ ['prompt_history', 'session_id'],
68
69
  ['chat_sessions', 'session_id'],
69
70
  ['files', 'session_id'],
70
71
  // An ACP chat has no transcript for the scan to lose: `harness_sessions` IS
@@ -15,7 +15,7 @@
15
15
  * or read session files (same reason `runScheduledTask` takes its deps).
16
16
  */
17
17
 
18
- import { describe, expect, test } from 'bun:test';
18
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
19
19
  import {
20
20
  driveGoalAfterTurn,
21
21
  lastAssistantText,
@@ -25,6 +25,10 @@ import {
25
25
  } from '@/server/lib/omp/session/goal-driver.server';
26
26
  import type { GoalAuditAnswers } from '@/server/lib/omp/session/goal-auditor.server';
27
27
  import type { GoalRecord } from '@/shared/lib/omp/mode/types';
28
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
29
+
30
+ beforeEach(isolateDb);
31
+ afterEach(releaseDb);
28
32
 
29
33
  const goal: GoalRecord = {
30
34
  id: 'g1',
@@ -13,9 +13,13 @@
13
13
  * loop's own guard.
14
14
  */
15
15
 
16
- import { describe, expect, test } from 'bun:test';
16
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
17
17
  import { normalizeGoalBudget } from '@/shared/lib/omp/mode/budget';
18
18
  import { readGoalSettings } from '@/server/lib/omp/session/goal-settings.server';
19
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
20
+
21
+ beforeEach(isolateDb);
22
+ afterEach(releaseDb);
19
23
 
20
24
  describe('normalizeGoalBudget', () => {
21
25
  test('a positive integer is a budget, whatever shape it arrived in', () => {