@kabmo-labs/kabmo 0.17.0 → 0.18.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 (269) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +538 -457
  3. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  4. package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
  5. package/package.json +1 -1
  6. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  7. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  8. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  9. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  10. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  11. package/src/client/components/common/markdown-review/index.tsx +129 -0
  12. package/src/client/components/common/server-control/Panel.tsx +33 -23
  13. package/src/client/components/common/server-control/index.test.tsx +11 -5
  14. package/src/client/components/common/server-control/index.tsx +10 -8
  15. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  16. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  17. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  18. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  19. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  20. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  23. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  24. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  25. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  26. package/src/client/components/layout/update-popup/index.tsx +5 -1
  27. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  28. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  29. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  30. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  31. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  32. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  33. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  34. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  35. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  36. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  37. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  38. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  39. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  40. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  41. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  42. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  43. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  44. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  45. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  46. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  47. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  48. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  49. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  50. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  51. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  52. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  53. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  54. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  55. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  56. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  57. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  58. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  59. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  60. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
  61. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  62. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  63. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  64. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  65. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  66. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  67. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  68. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  69. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  70. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  71. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  72. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  73. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  74. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  75. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  76. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  77. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  78. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  87. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  88. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  89. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  90. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  91. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  92. package/src/client/components/workspace/editor/Body.tsx +7 -0
  93. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  94. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  95. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  96. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  97. package/src/client/components/workspace/editor/index.tsx +25 -22
  98. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  99. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  100. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  101. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  102. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  103. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  104. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  105. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  106. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  107. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  108. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  109. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  110. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  111. package/src/client/data/agent-data/builtin.ts +0 -10
  112. package/src/client/data/agent-data/orchestrator.ts +0 -45
  113. package/src/client/data/agent-data/specialist.ts +0 -100
  114. package/src/client/data/mock/token-usage.ts +170 -120
  115. package/src/client/data/settings/omp-schema.json +33 -1
  116. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  117. package/src/client/hooks/browser/use-annotate.ts +98 -0
  118. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  119. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  120. package/src/client/hooks/browser/use-screencast.ts +13 -1
  121. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  122. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  123. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  124. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  125. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  126. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  127. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  128. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  129. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  130. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  131. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  132. package/src/client/hooks/settings/agents.ts +149 -0
  133. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  134. package/src/client/hooks/settings/crud-list.ts +96 -57
  135. package/src/client/hooks/settings/omp-config.ts +164 -0
  136. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  137. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  138. package/src/client/hooks/settings/write-feedback.ts +63 -0
  139. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  140. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  141. package/src/client/hooks/ui/updates/index.ts +50 -0
  142. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  143. package/src/client/hooks/ui/updates/notes.ts +57 -0
  144. package/src/client/lib/browser/element-at.test.ts +229 -0
  145. package/src/client/lib/browser/element-at.ts +139 -0
  146. package/src/client/lib/review/client.ts +73 -0
  147. package/src/client/lib/router/search-params.ts +42 -20
  148. package/src/client/tailwind.css +65 -0
  149. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  150. package/src/server/lib/db/schema.ts +7 -0
  151. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  152. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  153. package/src/server/lib/omp/config/agents.ts +231 -61
  154. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  155. package/src/server/lib/omp/config/extensions.ts +16 -7
  156. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  157. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  158. package/src/server/lib/omp/rpc/constants.ts +15 -0
  159. package/src/server/lib/omp/rpc/process.ts +11 -14
  160. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  161. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  162. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  163. package/src/server/lib/omp/rpc/utility.ts +12 -0
  164. package/src/server/lib/review/schema.server.ts +45 -0
  165. package/src/server/lib/review/store.server.ts +138 -0
  166. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  167. package/src/server/lib/terminal/output.test.ts +166 -0
  168. package/src/server/lib/terminal/output.ts +104 -0
  169. package/src/server/lib/terminal/runtime.server.ts +5 -0
  170. package/src/server/lib/terminal/send-result.test.ts +33 -0
  171. package/src/server/lib/terminal/send-result.ts +32 -0
  172. package/src/server/lib/terminal/session.server.ts +45 -11
  173. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  174. package/src/server/lib/updates/active-notes.test.ts +149 -0
  175. package/src/server/lib/updates/active-notes.ts +75 -0
  176. package/src/server/lib/updates/changelog-file.ts +42 -11
  177. package/src/server/lib/updates/changelog.test.ts +15 -1
  178. package/src/server/lib/updates/omp.ts +42 -15
  179. package/src/server/lib/updates/release-url.ts +27 -1
  180. package/src/server/lib/usage/index-parse.test.ts +200 -0
  181. package/src/server/lib/usage/index-parse.ts +178 -0
  182. package/src/server/lib/usage/index-query.server.ts +248 -0
  183. package/src/server/lib/usage/index-scan.server.ts +343 -0
  184. package/src/server/lib/usage/index-schema.server.ts +82 -0
  185. package/src/server/lib/usage/index.test.ts +234 -0
  186. package/src/server/lib/usage/providers.server.ts +4 -53
  187. package/src/server/routes/browser/index.ts +3 -0
  188. package/src/server/routes/browser/stream.ts +31 -2
  189. package/src/server/routes/browser/tabs.test.ts +94 -0
  190. package/src/server/routes/browser/tabs.ts +85 -0
  191. package/src/server/routes/index.ts +2 -0
  192. package/src/server/routes/review/bindings.ts +11 -0
  193. package/src/server/routes/review/index.ts +127 -0
  194. package/src/server/routes/review/routes.test.ts +191 -0
  195. package/src/server/routes/settings/agents.test.ts +180 -0
  196. package/src/server/routes/settings/agents.ts +95 -102
  197. package/src/server/routes/settings/mcp.test.ts +135 -0
  198. package/src/server/routes/settings/mcp.ts +14 -6
  199. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  200. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  201. package/src/server/routes/telemetry/tokens.ts +70 -149
  202. package/src/server/routes/terminal/ws.ts +6 -5
  203. package/src/server/routes/updates/index.ts +2 -0
  204. package/src/server/routes/updates/notes.ts +34 -0
  205. package/src/server/routes/updates/routes.test.ts +49 -0
  206. package/src/shared/lib/browser/annotate.test.ts +283 -0
  207. package/src/shared/lib/browser/annotate.ts +231 -0
  208. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  209. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  210. package/src/shared/lib/browser/frame-gate.ts +69 -0
  211. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  212. package/src/shared/lib/browser/frame-params.ts +60 -0
  213. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  214. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  215. package/src/shared/lib/browser/page-context.ts +60 -4
  216. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  217. package/src/shared/lib/browser/snapshot.ts +112 -0
  218. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  219. package/src/shared/lib/browser/tab-close.ts +77 -0
  220. package/src/shared/lib/browser/viewer.ts +45 -26
  221. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  222. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  223. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  224. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  225. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  226. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  227. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  228. package/src/shared/lib/chat/tool/summary.ts +3 -32
  229. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  230. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  231. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  232. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  233. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  234. package/src/shared/lib/markdown/marked.ts +58 -147
  235. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  236. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  237. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  238. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  239. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  240. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  241. package/src/shared/lib/models/provider/label.ts +57 -0
  242. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  243. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  244. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  245. package/src/shared/lib/omp/config/row-value.ts +97 -0
  246. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  247. package/src/shared/lib/omp/config/schema.ts +6 -0
  248. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  249. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  250. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  251. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  252. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  253. package/src/shared/lib/usage/breakdown.ts +241 -0
  254. package/src/shared/lib/usage/range.test.ts +204 -0
  255. package/src/shared/lib/usage/range.ts +240 -0
  256. package/src/shared/lib/usage/view.test.ts +85 -0
  257. package/src/shared/lib/usage/view.ts +74 -0
  258. package/src/shared/types/browser.ts +78 -0
  259. package/src/shared/types/index.ts +1 -0
  260. package/src/shared/types/settings/agent.ts +28 -6
  261. package/src/shared/types/settings/state.ts +4 -3
  262. package/src/shared/types/settings/write.ts +6 -0
  263. package/src/shared/types/tokenUsage.ts +128 -21
  264. package/src/shared/types/updates.ts +20 -0
  265. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  266. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  267. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  268. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  269. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
@@ -8,8 +8,9 @@
8
8
  * Protocol v1: commands `{id, type, ...}` on stdin; `{type:"response", id, ...}`
9
9
  * plus interleaved event frames on stdout. omp announces readiness with a
10
10
  * `{type:"ready"}` frame before accepting commands. When readiness advertises
11
- * protocol v2, callers negotiate it before sending normal commands; oversized
12
- * logical frames are then carried as bounded `rpc_chunk` sequences.
11
+ * protocol v2, callers negotiate it so OMP's own OVERSIZED EVENTS arrive as
12
+ * bounded `rpc_chunk` sequences (see `frame.ts` for why the same encoding must
13
+ * never be used in the other direction).
13
14
  *
14
15
  * Faithful port of omp-web/lib/omp/rpc-process.ts.
15
16
  */
@@ -18,7 +19,7 @@ import type { Subprocess } from 'bun';
18
19
  import { signalName, stripKabmoHostEnv } from '@kabmo-labs/kabmo-sdk';
19
20
  import { describeSpawnFailure } from '@/server/lib/lifecycle/fd-pressure';
20
21
  import { resolveOmpBin } from '@/server/lib/omp/core/cli';
21
- import { RpcFrameDecoder, encodeRpcFrames, type RpcFrameRecord, type RpcProtocolVersion } from '@/shared/lib/omp/rpc/frame';
22
+ import { RpcFrameDecoder, encodeRpcFrameLine, type RpcFrameRecord, type RpcProtocolVersion } from '@/shared/lib/omp/rpc/frame';
22
23
  import { killProcessTree } from '@/server/lib/lifecycle/kill-tree';
23
24
  import { readLines } from '@/server/lib/omp/rpc/lines';
24
25
  import { RpcCommandError, RpcCommandTimeoutError, STDERR_TAIL_LIMIT, type PendingCommand, type RpcFrame, type RpcProcessOptions, type RpcResponseFrame } from '@/server/lib/omp/rpc/process-helpers';
@@ -37,11 +38,8 @@ export class RpcProcess {
37
38
  private exited = false;
38
39
  private exitInfo: { code: number | null; signal: string | null } | null = null;
39
40
  private protocolVersion: RpcProtocolVersion = 1;
40
- private nextChunkId = 1;
41
- // Serializes physical stdin writes: a v2 logical frame can span multiple
42
- // `rpc_chunk` records (>1 MiB payloads), and two frames written concurrently
43
- // would interleave their chunk sequences on stdin, which RpcFrameDecoder
44
- // rejects. Each logical frame is enqueued whole.
41
+ // Serializes stdin writes: a frame is queued whole so two writers cannot
42
+ // interleave halves of two frames on the pipe.
45
43
  private writeQueue: Promise<void> = Promise.resolve();
46
44
 
47
45
  constructor(options: RpcProcessOptions) {
@@ -252,16 +250,15 @@ export class RpcProcess {
252
250
  }
253
251
 
254
252
  private writeFrame(frame: RpcFrame, callback: (error?: Error | null) => void): void {
255
- let lines: string[];
253
+ let line: string;
256
254
  try {
257
- lines = encodeRpcFrames(frame, this.protocolVersion, `web-${this.nextChunkId++}`);
255
+ line = encodeRpcFrameLine(frame);
258
256
  } catch (error) {
259
257
  callback(error instanceof Error ? error : new Error(String(error)));
260
258
  return;
261
259
  }
262
- // Enqueue the entire encoded logical frame; the next frame's physical
263
- // records only start after this frame has been fully handed to the stdin
264
- // sink, so two frames can never interleave their chunk sequences.
260
+ // Serialized: a frame is handed to stdin whole before the next one starts,
261
+ // so two writers cannot interleave halves of two frames on the pipe.
265
262
  this.writeQueue = this.writeQueue.then(
266
263
  () => new Promise<void>((resolve) => {
267
264
  if (this.exited || !this.child.stdin) {
@@ -270,7 +267,7 @@ export class RpcProcess {
270
267
  return;
271
268
  }
272
269
  try {
273
- for (const line of lines) this.child.stdin.write(line);
270
+ this.child.stdin.write(line);
274
271
  callback(null);
275
272
  } catch (error) {
276
273
  callback(error instanceof Error ? error : new Error(String(error)));
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  import { RpcCommandError, RpcCommandTimeoutError } from '@/server/lib/omp/rpc/process';
13
- import { AGENT_BUSY_MESSAGE, AGENT_BUSY_REFUSAL_RE, AWAITING_AGENT_START_TIMEOUT_MS, GET_STATE_TIMEOUT_MS, IMAGE_BEARING_COMMANDS, PASSTHROUGH_COMMANDS, PROMPT_ACK_TIMEOUT_MS, RESTARTING_MESSAGE, STEER_ACK_TIMEOUT_MS, WebRpcError, toImageContents, type RpcSessionState, validateAgentImages } from '@/server/lib/omp/rpc/constants';
13
+ import { AGENT_BUSY_MESSAGE, AGENT_BUSY_REFUSAL_RE, AWAITING_AGENT_START_TIMEOUT_MS, GET_STATE_TIMEOUT_MS, IMAGE_BEARING_COMMANDS, PASSTHROUGH_COMMANDS, RESTARTING_MESSAGE, STEER_ACK_TIMEOUT_MS, WebRpcError, promptAckTimeoutMs, toImageContents, type RpcSessionState, validateAgentImages } from '@/server/lib/omp/rpc/constants';
14
14
  import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
15
15
  import { awaitTitleDispatch } from '@/server/lib/omp/session/title-request.server';
16
16
  import { scheduleQueueDelivery } from '@/server/lib/queue/delivery.server';
@@ -88,12 +88,15 @@ export async function dispatchSessionCommand(host: SessionCommandHost, command:
88
88
  if (ownsStreamRow) void markStreamStatus(host.sessionId, 'stream', host.runModel);
89
89
  }
90
90
  try {
91
+ // Resolved once: the same payload decides both what rides the command
92
+ // and how long its ack may take.
93
+ const images = toImageContents(command.images);
91
94
  const ack = await host.proc.sendCommand<{ agentInvoked?: boolean } | undefined>({
92
95
  type: 'prompt',
93
96
  message: command.message as string,
94
- ...(toImageContents(command.images) ? { images: toImageContents(command.images) } : {}),
97
+ ...(images ? { images } : {}),
95
98
  ...(streamingBehavior ? { streamingBehavior } : {}),
96
- }, PROMPT_ACK_TIMEOUT_MS);
99
+ }, promptAckTimeoutMs(command.images));
97
100
  if (ack?.agentInvoked === false && !streamingBehavior) {
98
101
  // Only a dispatch that CLAIMED the turn slot may settle it. A command
99
102
  // dispatched while a run is in flight — a mode toggle, the plan-review
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The MCP-free agent-dir overlay: what the utility child is allowed to see, and
8
+ * what must reach the real tree.
9
+ *
10
+ * The rule this pins is the ONE thing the overlay exists for — `mcp.json` is
11
+ * absent, so omp spawns no MCP process — plus the property that makes deferring
12
+ * to symlinks safe: every other entry still resolves to the real file, so a
13
+ * `logout` or a `models.yml` read sees the user's actual state. A regression to
14
+ * "copy the files" would pass a naive smoke test and silently fork credentials.
15
+ */
16
+
17
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
18
+ import fs from 'fs';
19
+ import { tmpdir } from 'os';
20
+ import path from 'path';
21
+
22
+ import { ensureUtilityAgentDir, removeUtilityAgentDir } from '@/server/lib/omp/rpc/utility-agent-dir';
23
+
24
+ let realAgentDir = '';
25
+ let previousAgentDir: string | undefined;
26
+
27
+ function write(file: string, content: string): void {
28
+ fs.mkdirSync(path.dirname(file), { recursive: true });
29
+ fs.writeFileSync(file, content);
30
+ }
31
+
32
+ beforeEach(() => {
33
+ realAgentDir = fs.mkdtempSync(path.join(tmpdir(), 'kabmo-util-real-'));
34
+ previousAgentDir = Bun.env.PI_CODING_AGENT_DIR;
35
+ Bun.env.PI_CODING_AGENT_DIR = realAgentDir;
36
+ });
37
+
38
+ afterEach(async () => {
39
+ await removeUtilityAgentDir();
40
+ if (previousAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
41
+ else Bun.env.PI_CODING_AGENT_DIR = previousAgentDir;
42
+ fs.rmSync(realAgentDir, { recursive: true, force: true });
43
+ });
44
+
45
+ describe('ensureUtilityAgentDir', () => {
46
+ test('omits mcp.json and sessions, and mirrors every other entry', async () => {
47
+ write(path.join(realAgentDir, 'mcp.json'), '{"mcpServers":{}}');
48
+ write(path.join(realAgentDir, 'models.yml'), 'providers: []\n');
49
+ write(path.join(realAgentDir, 'agent.db'), 'db');
50
+ fs.mkdirSync(path.join(realAgentDir, 'sessions'), { recursive: true });
51
+ fs.mkdirSync(path.join(realAgentDir, 'skills'), { recursive: true });
52
+
53
+ const overlay = await ensureUtilityAgentDir();
54
+ expect(overlay).toBeString();
55
+
56
+ const entries = fs.readdirSync(overlay!).sort();
57
+ // The whole point of the overlay: no MCP config reaches the child.
58
+ expect(entries).not.toContain('mcp.json');
59
+ // These children run --no-session; a second view of the tree is a bug.
60
+ expect(entries).not.toContain('sessions');
61
+ expect(entries).toContain('models.yml');
62
+ expect(entries).toContain('agent.db');
63
+ });
64
+
65
+ test('state files are symlinks to the real ones, so writes land there', async () => {
66
+ write(path.join(realAgentDir, 'models.yml'), 'providers: [kenari]\n');
67
+
68
+ const overlay = await ensureUtilityAgentDir();
69
+ const link = path.join(overlay!, 'models.yml');
70
+
71
+ expect(fs.lstatSync(link).isSymbolicLink()).toBe(true);
72
+ expect(fs.realpathSync(link)).toBe(fs.realpathSync(path.join(realAgentDir, 'models.yml')));
73
+ // A read through the overlay is the real content, not a stale copy.
74
+ expect(fs.readFileSync(link, 'utf8')).toContain('kenari');
75
+ });
76
+
77
+ test('directories are linked, not materialised empty, so discovery sees them', async () => {
78
+ fs.mkdirSync(path.join(realAgentDir, 'skills'), { recursive: true });
79
+ fs.mkdirSync(path.join(realAgentDir, 'skills', 'diagnose'), { recursive: true });
80
+
81
+ const overlay = await ensureUtilityAgentDir();
82
+ const mounted = path.join(overlay!, 'skills');
83
+
84
+ // An empty stand-in dropped every `skill:` entry from get_available_commands
85
+ // (measured 60 → 52 commands, 1 skill left). The overlay must expose the
86
+ // real root, so a linked child discovers exactly what a plain child does.
87
+ expect(fs.lstatSync(mounted).isSymbolicLink()).toBe(true);
88
+ expect(fs.realpathSync(mounted)).toBe(fs.realpathSync(path.join(realAgentDir, 'skills')));
89
+ expect(fs.readdirSync(mounted)).toEqual(['diagnose']);
90
+ });
91
+
92
+ test('a second call is idempotent and returns the same directory', async () => {
93
+ write(path.join(realAgentDir, 'models.yml'), 'a\n');
94
+
95
+ const first = await ensureUtilityAgentDir();
96
+ const second = await ensureUtilityAgentDir();
97
+
98
+ expect(second).toBe(first!);
99
+ expect(fs.readdirSync(second!)).toContain('models.yml');
100
+ });
101
+
102
+ test('an unreadable agent dir falls back to undefined rather than failing', async () => {
103
+ Bun.env.PI_CODING_AGENT_DIR = path.join(realAgentDir, 'does-not-exist');
104
+ expect(await ensureUtilityAgentDir()).toBeUndefined();
105
+ });
106
+
107
+ test('a file added after the first build appears in the next build', async () => {
108
+ write(path.join(realAgentDir, 'models.yml'), 'a\n');
109
+ const before = await ensureUtilityAgentDir();
110
+ expect(fs.readdirSync(before!)).not.toContain('auth.json');
111
+
112
+ write(path.join(realAgentDir, 'auth.json'), '{}');
113
+ await ensureUtilityAgentDir();
114
+
115
+ expect(fs.readdirSync(before!)).toContain('auth.json');
116
+ });
117
+ });
118
+
119
+ describe('removeUtilityAgentDir', () => {
120
+ test('removes the overlay but never the real files it linked to', async () => {
121
+ write(path.join(realAgentDir, 'auth.json'), '{"token":"x"}');
122
+ const overlay = await ensureUtilityAgentDir();
123
+ expect(fs.existsSync(overlay!)).toBe(true);
124
+
125
+ await removeUtilityAgentDir();
126
+
127
+ expect(fs.existsSync(overlay!)).toBe(false);
128
+ expect(fs.readFileSync(path.join(realAgentDir, 'auth.json'), 'utf8')).toBe('{"token":"x"}');
129
+ });
130
+
131
+ test('is a no-op when nothing was built', () => {
132
+ expect(removeUtilityAgentDir()).toBeInstanceOf(Promise);
133
+ });
134
+ });
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * An MCP-free view of the agent directory, for the shared utility process.
8
+ *
9
+ * ## Why
10
+ *
11
+ * `omp --mode rpc-ui` connects every configured MCP server at startup, and the
12
+ * child has no flag to skip them (`--no-tools` does not: measured, the codegraph
13
+ * proxy still spawned). The utility pool only answers registry/auth/slash-command
14
+ * queries — `get_available_models`, `get_login_providers`, `get_available_commands`,
15
+ * `get_state`, `get_logout_accounts`/`logout` — and never runs an agent turn, so
16
+ * the `codegraph serve --mcp` proxy plus its main-thread watchdog it spawned were
17
+ * ~88 MB that served nothing. Verified by the `xd://` device notice: with MCP on,
18
+ * omp mounts `mcp__codegraph_explore` into a child that can never call it.
19
+ *
20
+ * The only switch that measurably suppresses it is the agent directory itself:
21
+ * `PI_CODING_AGENT_DIR` pointing at a directory with no `mcp.json` makes the
22
+ * child spawn NO MCP process at all (measured `children=[]`), while every
23
+ * utility command keeps answering — because each state file (models.yml,
24
+ * auth.json, projects.json, the DBs) is symlinked through to the real one.
25
+ *
26
+ * ## Why symlinks, not copies
27
+ *
28
+ * A copy would fork state: `logout` writes credentials, `models.yml` is user
29
+ * config, and the `.db` files are live SQLite with a WAL. Symlinking each entry
30
+ * means the child reads and writes exactly the file the real agent dir uses, so
31
+ * a logout through the utility child lands in the real auth storage. Directories
32
+ * are symlinked too, not materialised empty: `skills/` holds the roots omp
33
+ * DISCOVERS at startup, and an empty stand-in silently dropped every
34
+ * `skill:<name>` entry from `get_available_commands` (measured 60 → 52
35
+ * commands, 1 skill left). A write through a linked directory reaches the real
36
+ * tree, which is exactly what the child does when it runs without an overlay.
37
+ *
38
+ * The one entry never linked is `mcp.json` — that is the whole point — and
39
+ * `sessions/` is skipped because these children run `--no-session` and must not
40
+ * create a second view of the session tree.
41
+ *
42
+ * ## Failure posture
43
+ *
44
+ * An overlay that cannot be built returns `undefined`, and the caller spawns
45
+ * against the real agent dir: a slow registry query is better than a boot
46
+ * failure, and MCP discovery is not worth failing a models list over. The
47
+ * overlay is rebuilt per spawn (cheap: one readdir plus N symlinks) so an agent
48
+ * dir that gains a file after boot is picked up by the next child.
49
+ */
50
+
51
+ import fs from 'fs';
52
+ import path from 'path';
53
+ import { tmpdir } from 'os';
54
+
55
+ import { getAgentDir } from '@/server/lib/omp/core/paths';
56
+
57
+ /** Entries a child must never see from the overlay: the whole point, plus a
58
+ * session tree these `--no-session` children have no business mounting. */
59
+ const EXCLUDED: Record<string, true> = { 'mcp.json': true, sessions: true };
60
+
61
+ /** Prefix for the per-process overlay root, so a stale one is recognisable. */
62
+ const OVERLAY_PREFIX = 'kabmo-omp-utility-';
63
+
64
+ function overlayRoot(): string {
65
+ return path.join(tmpdir(), `${OVERLAY_PREFIX}${process.pid}`);
66
+ }
67
+
68
+ /** Narrow the only field read from a failed `fs` call. */
69
+ function errorCode(error: unknown): string | undefined {
70
+ if (error && typeof error === 'object' && 'code' in error && typeof error.code === 'string') {
71
+ return error.code;
72
+ }
73
+ return undefined;
74
+ }
75
+
76
+ /**
77
+ * Build (idempotently) the MCP-free agent directory and return its path.
78
+ *
79
+ * Returns `undefined` when the real agent dir cannot be read — the caller then
80
+ * uses the real dir, which trades the saved processes for a working child.
81
+ */
82
+ export async function ensureUtilityAgentDir(): Promise<string | undefined> {
83
+ const real = getAgentDir();
84
+ let entries: fs.Dirent[];
85
+ try {
86
+ entries = await fs.promises.readdir(real, { withFileTypes: true });
87
+ } catch {
88
+ return undefined;
89
+ }
90
+
91
+ const root = overlayRoot();
92
+ try {
93
+ await fs.promises.mkdir(root, { recursive: true });
94
+ for (const entry of entries) {
95
+ if (EXCLUDED[entry.name]) continue;
96
+ const target = path.join(root, entry.name);
97
+ try {
98
+ await fs.promises.symlink(path.join(real, entry.name), target);
99
+ } catch (error) {
100
+ // EEXIST: a previous spawn in this process already linked it. Any other
101
+ // failure skips THIS entry rather than failing the whole overlay; the
102
+ // child still boots, it just sees one fewer file.
103
+ if (errorCode(error) !== 'EEXIST') continue;
104
+ }
105
+ }
106
+ return root;
107
+ } catch {
108
+ return undefined;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Remove this process's overlay. Called from the utility pool's shutdown paths
114
+ * so a long-lived server does not accumulate one directory per restart; a
115
+ * removed overlay is rebuilt on the next spawn, so this is safe at any time.
116
+ *
117
+ * Only symlinks and directories are removed — never a file the child created
118
+ * that might hold credentials.
119
+ */
120
+ export async function removeUtilityAgentDir(): Promise<void> {
121
+ const root = overlayRoot();
122
+ try {
123
+ const entries = await fs.promises.readdir(root, { withFileTypes: true });
124
+ await Promise.all(entries.map(async (entry) => {
125
+ const full = path.join(root, entry.name);
126
+ try {
127
+ // unlink removes a symlink itself, never its target.
128
+ await (entry.isDirectory() ? fs.promises.rmdir(full) : fs.promises.unlink(full));
129
+ } catch {
130
+ // A directory with content (omp created files in a writable mount) or a
131
+ // file the child owns: leave it. The next boot reuses the same path.
132
+ }
133
+ }));
134
+ await fs.promises.rmdir(root);
135
+ } catch {
136
+ // Nothing to remove, or a directory still in use by a live child.
137
+ }
138
+ }
@@ -20,6 +20,7 @@
20
20
  import { homedir } from 'os';
21
21
  import { RpcProcess } from '@/server/lib/omp/rpc/process';
22
22
  import { RELOAD_PLUGINS_TIMEOUT_MS } from '@/server/lib/omp/rpc/constants';
23
+ import { ensureUtilityAgentDir, removeUtilityAgentDir } from '@/server/lib/omp/rpc/utility-agent-dir';
23
24
 
24
25
  // Extensions stay ENABLED: they can register models and login providers, and
25
26
  // omitting them made the web UI's model/provider lists disagree with the CLI's.
@@ -124,6 +125,9 @@ export function disposeUtilityRpc(): void {
124
125
  if (proc) void proc.dispose();
125
126
  }
126
127
  states.clear();
128
+ // The overlay is rebuilt on the next spawn; removing it here keeps a server
129
+ // that restarts often from leaving one symlink farm per process behind.
130
+ void removeUtilityAgentDir();
127
131
  }
128
132
 
129
133
  /**
@@ -210,9 +214,17 @@ function scheduleIdleKill(state: UtilityRpcState): void {
210
214
  }
211
215
 
212
216
  async function startProcess(state: UtilityRpcState, cwd: string): Promise<RpcProcess> {
217
+ // MCP is removed for THIS child only, by pointing its agent dir at an overlay
218
+ // with every state file symlinked through and `mcp.json` left out: these
219
+ // children answer registry/auth queries and never run a turn, so an MCP server
220
+ // here is a proxy plus its watchdog (~88 MB) serving nothing. `undefined`
221
+ // means the real dir — a working child beats a saved process.
222
+ // See `utility-agent-dir.ts` for the measurements.
223
+ const agentDir = await ensureUtilityAgentDir();
213
224
  const proc = new RpcProcess({
214
225
  cwd,
215
226
  extraArgs: UTILITY_EXTRA_ARGS,
227
+ env: agentDir ? { PI_CODING_AGENT_DIR: agentDir } : undefined,
216
228
  onExit: () => {
217
229
  if (state.proc === proc) state.proc = null;
218
230
  },
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The review-annotation table, kept out of `db.server.ts`'s bootstrap block for
8
+ * the same reason `schedule/schema.server.ts` is: created once per database open,
9
+ * owned by the feature that reads it.
10
+ *
11
+ * Why a table and not `session_ui_state`: that blob is the CLIENT's whole
12
+ * in-memory map, rewritten wholesale on every debounce, so two tabs (or two
13
+ * Kabmo instances on one database) clobber each other. An annotation is a
14
+ * judgement about a FILE and has to outlive the tab that made it.
15
+ *
16
+ * `block_key` is the identity — `type:hash#occurrence`, derived from the block's
17
+ * own text — so a judgement follows its paragraph when text above it moves. The
18
+ * line columns are display data refreshed on every save, never a join key.
19
+ */
20
+
21
+ import type { DbClient } from '@/server/lib/db/client';
22
+
23
+ const REVIEW_SCHEMA_SQL = `
24
+ CREATE TABLE IF NOT EXISTS document_annotations (
25
+ id TEXT PRIMARY KEY,
26
+ scope TEXT NOT NULL,
27
+ path TEXT NOT NULL,
28
+ block_key TEXT NOT NULL,
29
+ line_start INTEGER NOT NULL DEFAULT 0,
30
+ line_end INTEGER NOT NULL DEFAULT 0,
31
+ verdict TEXT NOT NULL,
32
+ note TEXT NOT NULL DEFAULT '',
33
+ quote TEXT NOT NULL DEFAULT '',
34
+ created_at INTEGER NOT NULL,
35
+ updated_at INTEGER NOT NULL,
36
+ UNIQUE (scope, path, block_key)
37
+ );
38
+ CREATE INDEX IF NOT EXISTS idx_document_annotations_doc
39
+ ON document_annotations (scope, path);
40
+ `;
41
+
42
+ /** Idempotent: the review annotations, created on every database open. */
43
+ export async function ensureReviewSchema(db: DbClient): Promise<void> {
44
+ await db.exec(REVIEW_SCHEMA_SQL);
45
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * SQLite-backed store for a document's review annotations.
8
+ *
9
+ * One row per (scope, path, block key), and a save is an UPSERT: a block carries
10
+ * one judgement, and a second click changes the answer rather than stacking a
11
+ * thread. The `UNIQUE` constraint in the schema is the enforcement — two tabs
12
+ * saving the same block at once ends with one row, not two.
13
+ *
14
+ * `created_at` is preserved across an upsert while `updated_at` moves, so
15
+ * "oldest note first" and "most recently touched" are both answerable.
16
+ */
17
+
18
+ import { randomUUID } from 'node:crypto';
19
+
20
+ import { getDb } from '@/server/db.server';
21
+ import type { DocumentAnnotation, BlockVerdict } from '@/shared/lib/markdown/blocks/types';
22
+
23
+ interface AnnotationRow {
24
+ id: string;
25
+ scope: string;
26
+ path: string;
27
+ block_key: string;
28
+ line_start: number;
29
+ line_end: number;
30
+ verdict: string;
31
+ note: string;
32
+ quote: string;
33
+ created_at: number;
34
+ updated_at: number;
35
+ }
36
+
37
+ function isVerdict(value: unknown): value is BlockVerdict {
38
+ return value === 'good' || value === 'needs-work';
39
+ }
40
+
41
+ function toAnnotation(row: AnnotationRow): DocumentAnnotation {
42
+ return {
43
+ id: row.id,
44
+ scope: row.scope,
45
+ path: row.path,
46
+ blockKey: row.block_key,
47
+ lineStart: row.line_start,
48
+ lineEnd: row.line_end,
49
+ // A row written by a future version with a third verdict reads as
50
+ // `needs-work` rather than disappearing: a judgement that cannot be
51
+ // interpreted is still a block the user flagged.
52
+ verdict: isVerdict(row.verdict) ? row.verdict : 'needs-work',
53
+ note: row.note,
54
+ quote: row.quote,
55
+ createdAt: row.created_at,
56
+ updatedAt: row.updated_at,
57
+ };
58
+ }
59
+
60
+ /** Every judgement stored for one document, oldest first. */
61
+ export async function listAnnotations(scope: string, path: string): Promise<DocumentAnnotation[]> {
62
+ const db = await getDb();
63
+ const rows = (await db.all(
64
+ 'SELECT * FROM document_annotations WHERE scope = ? AND path = ? ORDER BY created_at ASC',
65
+ [scope, path],
66
+ )) as AnnotationRow[];
67
+ return rows.map(toAnnotation);
68
+ }
69
+
70
+ export interface AnnotationInput {
71
+ scope: string;
72
+ path: string;
73
+ blockKey: string;
74
+ lineStart: number;
75
+ lineEnd: number;
76
+ verdict: BlockVerdict;
77
+ note: string;
78
+ quote: string;
79
+ }
80
+
81
+ /** Insert or replace the judgement for one block, and answer the stored row. */
82
+ export async function saveAnnotation(input: AnnotationInput): Promise<DocumentAnnotation> {
83
+ const db = await getDb();
84
+ const now = Date.now();
85
+ const existing = (await db.get(
86
+ 'SELECT id, created_at FROM document_annotations WHERE scope = ? AND path = ? AND block_key = ?',
87
+ [input.scope, input.path, input.blockKey],
88
+ )) as { id: string; created_at: number } | undefined;
89
+ const id = existing?.id ?? randomUUID();
90
+ const createdAt = existing?.created_at ?? now;
91
+
92
+ await db.run(
93
+ `INSERT INTO document_annotations
94
+ (id, scope, path, block_key, line_start, line_end, verdict, note, quote, created_at, updated_at)
95
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
96
+ ON CONFLICT (scope, path, block_key) DO UPDATE SET
97
+ line_start = excluded.line_start,
98
+ line_end = excluded.line_end,
99
+ verdict = excluded.verdict,
100
+ note = excluded.note,
101
+ quote = excluded.quote,
102
+ updated_at = excluded.updated_at`,
103
+ [
104
+ id,
105
+ input.scope,
106
+ input.path,
107
+ input.blockKey,
108
+ input.lineStart,
109
+ input.lineEnd,
110
+ input.verdict,
111
+ input.note,
112
+ input.quote,
113
+ createdAt,
114
+ now,
115
+ ],
116
+ );
117
+
118
+ return {
119
+ id,
120
+ scope: input.scope,
121
+ path: input.path,
122
+ blockKey: input.blockKey,
123
+ lineStart: input.lineStart,
124
+ lineEnd: input.lineEnd,
125
+ verdict: input.verdict,
126
+ note: input.note,
127
+ quote: input.quote,
128
+ createdAt,
129
+ updatedAt: now,
130
+ };
131
+ }
132
+
133
+ /** Remove one judgement. `false` means there was no row with that id. */
134
+ export async function deleteAnnotation(id: string): Promise<boolean> {
135
+ const db = await getDb();
136
+ const result = await db.run('DELETE FROM document_annotations WHERE id = ?', [id]);
137
+ return result.changes > 0;
138
+ }