@kabmo-labs/kabmo 0.17.0 → 0.19.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 (438) hide show
  1. package/README.md +10 -7
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +523 -441
  4. package/dist/client/static/js/{index-rerjq5th.js → index-fcee4c13.js} +828 -818
  5. package/dist/client/static/js/index-sxdw908m.css +1 -0
  6. package/marketplace/plugins/command-runner/package.json +3 -2
  7. package/marketplace/plugins/git-forge/package.json +3 -2
  8. package/marketplace/plugins/session-info/package.json +3 -2
  9. package/marketplace/plugins/stats/package.json +3 -2
  10. package/package.json +3 -1
  11. package/src/client/components/auth/login-screen/index.tsx +2 -1
  12. package/src/client/components/common/ComposerPicker.tsx +1 -1
  13. package/src/client/components/common/FolderPicker.tsx +2 -2
  14. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  15. package/src/client/components/common/Modal.tsx +2 -2
  16. package/src/client/components/common/PWAInstallButton.tsx +2 -2
  17. package/src/client/components/common/ViewportSelector.tsx +1 -1
  18. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  19. package/src/client/components/common/anchored-menu/index.tsx +147 -0
  20. package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
  21. package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
  22. package/src/client/components/common/brand-wordmark/index.tsx +13 -2
  23. package/src/client/components/common/checkbox/style.test.ts +139 -0
  24. package/src/client/components/common/checkbox/style.ts +51 -0
  25. package/src/client/components/common/context-usage-button/index.tsx +2 -2
  26. package/src/client/components/common/file-icon/index.tsx +23 -9
  27. package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
  28. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  29. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  30. package/src/client/components/common/markdown-review/index.tsx +129 -0
  31. package/src/client/components/common/panel-mark/index.tsx +97 -0
  32. package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
  33. package/src/client/components/common/provider-icon/index.test.ts +14 -0
  34. package/src/client/components/common/provider-icon/index.tsx +4 -0
  35. package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
  36. package/src/client/components/common/provider-icon/resolve.ts +16 -3
  37. package/src/client/components/common/server-control/Panel.tsx +33 -23
  38. package/src/client/components/common/server-control/index.test.tsx +11 -5
  39. package/src/client/components/common/server-control/index.tsx +10 -8
  40. package/src/client/components/common/session-actions-menu/index.tsx +1 -1
  41. package/src/client/components/common/toolbar-row/index.tsx +1 -1
  42. package/src/client/components/layout/ActivityBar.tsx +22 -3
  43. package/src/client/components/layout/LeftDock.tsx +9 -2
  44. package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
  45. package/src/client/components/layout/WindowAura.tsx +27 -0
  46. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
  47. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
  48. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
  49. package/src/client/components/layout/desktop-layout/index.tsx +3 -1
  50. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +44 -23
  51. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  52. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  53. package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
  54. package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
  55. package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
  56. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  57. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  58. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  59. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  60. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
  61. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +40 -14
  62. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  63. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  64. package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
  65. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
  66. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
  67. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  68. package/src/client/components/layout/update-popup/index.tsx +5 -1
  69. package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
  70. package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
  71. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  72. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  73. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  74. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  75. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
  76. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  77. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  78. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
  79. package/src/client/components/mobile/panel-chips.tsx +10 -2
  80. package/src/client/components/settings/Modal.tsx +4 -4
  81. package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
  82. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  83. package/src/client/components/settings/apply-side-effects.test.ts +30 -0
  84. package/src/client/components/settings/apply-side-effects.ts +14 -0
  85. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  86. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  87. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  88. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  89. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  90. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  91. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  92. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  93. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  94. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  95. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  96. package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
  97. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
  98. package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
  99. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
  100. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
  101. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  102. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  103. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  104. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  105. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +93 -77
  106. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  107. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +28 -15
  108. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  109. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  110. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  111. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  112. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  113. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  114. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  115. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  116. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  117. package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
  118. package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
  119. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +1 -1
  120. package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +51 -2
  121. package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +43 -10
  122. package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
  123. package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
  124. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
  125. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  126. package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
  127. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
  128. package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
  129. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
  130. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +37 -8
  131. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  132. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  133. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  134. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  135. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  136. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  137. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  138. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  139. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  140. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  141. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  142. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  143. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  144. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  145. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  146. package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
  147. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
  148. package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
  149. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  150. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  151. package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
  152. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  153. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
  154. package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
  155. package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
  156. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
  157. package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
  158. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
  159. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
  160. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
  161. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  162. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  163. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  164. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  165. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  166. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  167. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  168. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  169. package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
  170. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  171. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  172. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  173. package/src/client/components/workspace/diff-panel/index.tsx +2 -2
  174. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  175. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  176. package/src/client/components/workspace/editor/Body.tsx +7 -0
  177. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  178. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  179. package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
  180. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  181. package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
  182. package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
  183. package/src/client/components/workspace/editor/Tabs.tsx +1 -1
  184. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  185. package/src/client/components/workspace/editor/index.tsx +25 -22
  186. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  187. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  188. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  189. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  190. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
  191. package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
  192. package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
  193. package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
  194. package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
  195. package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
  196. package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
  197. package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
  198. package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
  199. package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
  200. package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
  201. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  202. package/src/client/components/workspace/git-panel/index.tsx +7 -0
  203. package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
  204. package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
  205. package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
  206. package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
  207. package/src/client/components/workspace/search-panel/Body.tsx +1 -1
  208. package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
  209. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  210. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  211. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  212. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  213. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  214. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  215. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  216. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  217. package/src/client/data/agent-data/builtin.ts +0 -10
  218. package/src/client/data/agent-data/orchestrator.ts +0 -45
  219. package/src/client/data/agent-data/specialist.ts +0 -100
  220. package/src/client/data/mock/token-usage.ts +170 -120
  221. package/src/client/data/settings/omp-schema.json +33 -1
  222. package/src/client/glass.css +785 -0
  223. package/src/client/glass.test.ts +346 -0
  224. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  225. package/src/client/hooks/browser/use-annotate.ts +98 -0
  226. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  227. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  228. package/src/client/hooks/browser/use-screencast.ts +13 -1
  229. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  230. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  231. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  232. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  233. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  234. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  235. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  236. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  237. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  238. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  239. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  240. package/src/client/hooks/settings/agents.ts +149 -0
  241. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  242. package/src/client/hooks/settings/crud-list.ts +96 -57
  243. package/src/client/hooks/settings/omp-config.ts +164 -0
  244. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  245. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  246. package/src/client/hooks/settings/write-feedback.ts +63 -0
  247. package/src/client/hooks/ui/glass-support.ts +57 -0
  248. package/src/client/hooks/ui/icon-style.ts +59 -0
  249. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  250. package/src/client/hooks/ui/stuck-header.test.ts +188 -0
  251. package/src/client/hooks/ui/stuck-header.ts +91 -0
  252. package/src/client/hooks/ui/style-attributes.test.ts +120 -0
  253. package/src/client/hooks/ui/surface-style.ts +56 -0
  254. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  255. package/src/client/hooks/ui/updates/index.ts +50 -0
  256. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  257. package/src/client/hooks/ui/updates/notes.ts +57 -0
  258. package/src/client/hooks/workspace/panel-hues.ts +23 -0
  259. package/src/client/lib/browser/element-at.test.ts +229 -0
  260. package/src/client/lib/browser/element-at.ts +139 -0
  261. package/src/client/lib/review/client.ts +73 -0
  262. package/src/client/lib/router/search-params.ts +42 -20
  263. package/src/client/main.tsx +10 -0
  264. package/src/client/tailwind.css +329 -11
  265. package/src/server/lib/assets/shell-attributes.server.ts +80 -0
  266. package/src/server/lib/assets/shell-attributes.test.ts +86 -0
  267. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  268. package/src/server/lib/db/schema.ts +7 -0
  269. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  270. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  271. package/src/server/lib/omp/config/agents.ts +231 -61
  272. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  273. package/src/server/lib/omp/config/extensions.ts +16 -7
  274. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  275. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  276. package/src/server/lib/omp/rpc/constants.ts +15 -0
  277. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
  278. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
  279. package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
  280. package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
  281. package/src/server/lib/omp/rpc/manager.ts +2 -2
  282. package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
  283. package/src/server/lib/omp/rpc/process.test.ts +106 -0
  284. package/src/server/lib/omp/rpc/process.ts +39 -18
  285. package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
  286. package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
  287. package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
  288. package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
  289. package/src/server/lib/omp/rpc/session-commands.ts +17 -3
  290. package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
  291. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  292. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  293. package/src/server/lib/omp/rpc/utility.ts +12 -0
  294. package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
  295. package/src/server/lib/panels/manifest.test.ts +20 -0
  296. package/src/server/lib/panels/manifest.ts +12 -0
  297. package/src/server/lib/panels/scan.server.ts +4 -0
  298. package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
  299. package/src/server/lib/queue/delivery-harness.ts +8 -4
  300. package/src/server/lib/queue/delivery.server.test.ts +29 -0
  301. package/src/server/lib/queue/delivery.server.ts +39 -0
  302. package/src/server/lib/queue/store.server.test.ts +22 -2
  303. package/src/server/lib/queue/store.server.ts +33 -11
  304. package/src/server/lib/review/schema.server.ts +45 -0
  305. package/src/server/lib/review/store.server.ts +138 -0
  306. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  307. package/src/server/lib/terminal/output.test.ts +166 -0
  308. package/src/server/lib/terminal/output.ts +104 -0
  309. package/src/server/lib/terminal/runtime.server.ts +5 -0
  310. package/src/server/lib/terminal/send-result.test.ts +33 -0
  311. package/src/server/lib/terminal/send-result.ts +32 -0
  312. package/src/server/lib/terminal/session.server.ts +45 -11
  313. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  314. package/src/server/lib/updates/active-notes.test.ts +149 -0
  315. package/src/server/lib/updates/active-notes.ts +75 -0
  316. package/src/server/lib/updates/changelog-file.ts +42 -11
  317. package/src/server/lib/updates/changelog.test.ts +15 -1
  318. package/src/server/lib/updates/omp.ts +42 -15
  319. package/src/server/lib/updates/release-url.ts +27 -1
  320. package/src/server/lib/usage/index-parse.test.ts +200 -0
  321. package/src/server/lib/usage/index-parse.ts +178 -0
  322. package/src/server/lib/usage/index-query.server.ts +248 -0
  323. package/src/server/lib/usage/index-scan.server.ts +343 -0
  324. package/src/server/lib/usage/index-schema.server.ts +82 -0
  325. package/src/server/lib/usage/index.test.ts +234 -0
  326. package/src/server/lib/usage/providers.server.ts +4 -53
  327. package/src/server/plugins/ssr.ts +22 -5
  328. package/src/server/routes/browser/index.ts +3 -0
  329. package/src/server/routes/browser/stream.ts +31 -2
  330. package/src/server/routes/browser/tabs.test.ts +94 -0
  331. package/src/server/routes/browser/tabs.ts +85 -0
  332. package/src/server/routes/index.ts +2 -0
  333. package/src/server/routes/review/bindings.ts +11 -0
  334. package/src/server/routes/review/index.ts +127 -0
  335. package/src/server/routes/review/routes.test.ts +191 -0
  336. package/src/server/routes/settings/agents.test.ts +180 -0
  337. package/src/server/routes/settings/agents.ts +95 -102
  338. package/src/server/routes/settings/mcp.test.ts +135 -0
  339. package/src/server/routes/settings/mcp.ts +14 -6
  340. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  341. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  342. package/src/server/routes/telemetry/tokens.ts +70 -149
  343. package/src/server/routes/terminal/ws.ts +6 -5
  344. package/src/server/routes/updates/index.ts +2 -0
  345. package/src/server/routes/updates/notes.ts +34 -0
  346. package/src/server/routes/updates/routes.test.ts +49 -0
  347. package/src/shared/lib/browser/annotate.test.ts +283 -0
  348. package/src/shared/lib/browser/annotate.ts +231 -0
  349. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  350. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  351. package/src/shared/lib/browser/frame-gate.ts +69 -0
  352. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  353. package/src/shared/lib/browser/frame-params.ts +60 -0
  354. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  355. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  356. package/src/shared/lib/browser/page-context.ts +60 -4
  357. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  358. package/src/shared/lib/browser/snapshot.ts +112 -0
  359. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  360. package/src/shared/lib/browser/tab-close.ts +77 -0
  361. package/src/shared/lib/browser/viewer.ts +45 -26
  362. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  363. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  364. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  365. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  366. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  367. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  368. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  369. package/src/shared/lib/chat/tool/summary.ts +3 -32
  370. package/src/shared/lib/icons/file-brand-color.ts +38 -0
  371. package/src/shared/lib/icons/icon-paint-css.test.ts +234 -0
  372. package/src/shared/lib/icons/icon-paint-css.ts +284 -0
  373. package/src/shared/lib/icons/icon-paint-panel.ts +100 -0
  374. package/src/shared/lib/icons/tint-hues.generated.ts +230 -0
  375. package/src/shared/lib/icons/tint.test.ts +273 -0
  376. package/src/shared/lib/icons/tint.ts +219 -0
  377. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  378. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  379. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  380. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  381. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  382. package/src/shared/lib/markdown/marked.ts +58 -147
  383. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  384. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  385. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  386. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  387. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  388. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  389. package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
  390. package/src/shared/lib/models/provider/brand-color.ts +103 -0
  391. package/src/shared/lib/models/provider/label.ts +57 -0
  392. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  393. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  394. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  395. package/src/shared/lib/omp/config/row-value.ts +97 -0
  396. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  397. package/src/shared/lib/omp/config/schema.ts +6 -0
  398. package/src/shared/lib/omp/rpc/frame.test.ts +113 -47
  399. package/src/shared/lib/omp/rpc/frame.ts +107 -43
  400. package/src/shared/lib/settings/defaults.ts +4 -0
  401. package/src/shared/lib/theme/catalog.test.ts +5 -4
  402. package/src/shared/lib/theme/catalog.ts +18 -3
  403. package/src/shared/lib/theme/glass-support.test.ts +38 -0
  404. package/src/shared/lib/theme/glass-support.ts +73 -0
  405. package/src/shared/lib/theme/icon-style.test.ts +74 -0
  406. package/src/shared/lib/theme/icon-style.ts +90 -0
  407. package/src/shared/lib/theme/legibility.ts +91 -0
  408. package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
  409. package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
  410. package/src/shared/lib/theme/surface-style.test.ts +68 -0
  411. package/src/shared/lib/theme/surface-style.ts +91 -0
  412. package/src/shared/lib/theme/theme.test.ts +11 -7
  413. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  414. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  415. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  416. package/src/shared/lib/usage/breakdown.ts +241 -0
  417. package/src/shared/lib/usage/range.test.ts +204 -0
  418. package/src/shared/lib/usage/range.ts +240 -0
  419. package/src/shared/lib/usage/view.test.ts +85 -0
  420. package/src/shared/lib/usage/view.ts +74 -0
  421. package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
  422. package/src/shared/lib/workspace/panel-hues.ts +57 -0
  423. package/src/shared/types/browser.ts +78 -0
  424. package/src/shared/types/index.ts +1 -0
  425. package/src/shared/types/panels-registry.ts +6 -0
  426. package/src/shared/types/panels.ts +14 -0
  427. package/src/shared/types/settings/agent.ts +28 -6
  428. package/src/shared/types/settings/state.ts +30 -3
  429. package/src/shared/types/settings/write.ts +6 -0
  430. package/src/shared/types/tokenUsage.ts +128 -21
  431. package/src/shared/types/updates.ts +20 -0
  432. package/src/test-support/fake-omp-frames.ts +163 -0
  433. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  434. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  435. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  436. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  437. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
  438. /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
@@ -1,16 +1,38 @@
1
- export type AgentMode = 'primary' | 'subagent' | 'all';
1
+ /**
2
+ * An omp agent definition.
3
+ *
4
+ * The field set is omp's OWN frontmatter contract (`parseAgentFields` in
5
+ * `@oh-my-pi/pi-coding-agent`), not a shape Kabmo invented: `name`,
6
+ * `description`, `tools`, `spawns`, `model`, `thinkingLevel`, and the body as
7
+ * the system prompt. `mode`/`temperature`/`topP` used to be offered here and
8
+ * were never read by omp, so three controls edited a file to no effect — they
9
+ * are gone, and the pane no longer implies they work.
10
+ */
11
+
2
12
  export type AgentScope = 'system' | 'user' | 'project';
3
13
 
14
+ /** A model selector: `provider/model`, or a role selector such as `@smol`. */
15
+ export type AgentModelSelector = string;
16
+
4
17
  export interface AgentItem {
5
18
  id: string;
6
19
  name: string;
7
20
  description: string;
8
21
  scope: AgentScope;
9
- mode: AgentMode;
10
- overrideModel?: string;
11
- thinkingVariant?: string;
12
- temperature?: number | null;
13
- topP?: number | null;
22
+ /** Absent means omp's default tool set. */
23
+ tools?: string[];
24
+ /** `"*"` or a name list: which agents this one may spawn. */
25
+ spawns?: string;
26
+ model?: AgentModelSelector;
27
+ /** `off` … `max`, or `auto`; absent means the session's level. */
28
+ thinkingLevel?: string;
14
29
  systemPrompt: string;
30
+ /** Listed but not editable: a project agent belongs to that workspace. */
15
31
  isBuiltIn?: boolean;
32
+ /** Absolute path of the definition file omp loads; absent for a demo preset. */
33
+ filePath?: string;
34
+ /** Base name of that file (no `.md`), which is what a write sends. */
35
+ fileName?: string;
36
+ /** Which root the definition was discovered in. */
37
+ sourceRoot?: 'user' | 'project';
16
38
  }
@@ -3,6 +3,8 @@ import type { ChatWidthMode } from '@/shared/lib/chat/timeline/width-mode';
3
3
  import type { ToolRenderMode } from '@/shared/lib/chat/timeline/tool-render-mode';
4
4
  import type { SidebarStyle } from '@/shared/lib/workspace/sidebar-style';
5
5
  import type { ComposerStyle } from '@/shared/lib/chat/composer/style';
6
+ import type { SurfaceStyle } from '@/shared/lib/theme/surface-style';
7
+ import type { IconStyle } from '@/shared/lib/theme/icon-style';
6
8
 
7
9
  /** Wire protocol for the live agent event stream (chat timeline). */
8
10
  export type SettingsCategoryId =
@@ -100,9 +102,10 @@ export interface SettingsState {
100
102
  chatWidthMode: ChatWidthMode;
101
103
  /**
102
104
  * How a tool call is drawn in the transcript (`card` | `compact` | `trace` |
103
- * `minimal`). A reading style: every mode renders the same call, facts and
104
- * body — only the frame, density and grouping change. Global, like the chat
105
- * width, because density is a property of the person and the display.
105
+ * `minimal` | `tui`). A reading style: every mode renders the same call,
106
+ * facts and body — only the frame, density and grouping change. Global, like
107
+ * the chat width, because density is a property of the person and the
108
+ * display.
106
109
  */
107
110
  toolRenderStyle: ToolRenderMode;
108
111
  /**
@@ -126,6 +129,30 @@ export interface SettingsState {
126
129
  * style. `classic` is the default so an upgrade rearranges nothing.
127
130
  */
128
131
  composerStyle: ComposerStyle;
132
+ /**
133
+ * What the app's surfaces are cut from (`classic` | `glass`). A
134
+ * PRESENTATION choice over one shell: both styles draw the same panels, rows,
135
+ * controls and dialogs, and only the material changes. The table lives in
136
+ * `shared/lib/theme/surface-style.ts`; the pixels are the `[data-surface]`
137
+ * blocks in `tailwind.css`.
138
+ *
139
+ * It reaches the document as `data-surface` on `<html>` because the sidebar,
140
+ * navbar, composer and every modal are separate subtrees — a prop would be one
141
+ * call site each. `classic` is the default so an upgrade restyles nothing.
142
+ */
143
+ surfaceStyle: SurfaceStyle;
144
+ /**
145
+ * How EVERY icon is painted (`monochrome` | `color`): functional Lucide
146
+ * glyphs, provider/model marks and file-type marks. `color` gives each glyph
147
+ * its own hue, keeps the palette signals for the ones whose meaning is a
148
+ * signal, and paints brand art in the brand's colour; a colour that would
149
+ * vanish on the active variant falls back to the ink. The rules are
150
+ * `:where()`-wrapped, so a control's own colour still wins.
151
+ *
152
+ * Document attribute `data-icon-style`; see `shared/lib/theme/icon-style.ts`
153
+ * and `shared/lib/icons/icon-paint-css.ts`.
154
+ */
155
+ iconStyle: IconStyle;
129
156
  followUpBehavior: 'queue' | 'steering';
130
157
  keybindingSend: 'Enter' | 'Shift + Enter' | 'Ctrl / Cmd + Enter';
131
158
  keybindingNewLine: 'Enter' | 'Shift + Enter' | 'Ctrl / Cmd + Enter';
@@ -0,0 +1,6 @@
1
+ /** What a settings write did, so a pane reports the server's own answer. */
2
+ export interface WriteOutcome {
3
+ ok: boolean;
4
+ /** The refusal's sentence (the payload's `error`, or the transport failure). */
5
+ error?: string;
6
+ }
@@ -1,44 +1,151 @@
1
- export type CadenceType = 'daily' | 'weekly' | 'monthly';
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Token Usage surface's wire contract (`GET /api/telemetry/tokens`).
8
+ *
9
+ * One payload carries every view the panel can draw for the requested period:
10
+ * totals, the provider → model tree, the per-day rows the chart and the time
11
+ * breakdown are both derived from, and the project rows. The breakdown tabs
12
+ * therefore cost no request — they re-bucket data the client already holds.
13
+ *
14
+ * Every number here is RAW. Formatting (`$1.23`, `2.2M`) is the client's job,
15
+ * because a formatted string cannot be re-aggregated and cannot be compared
16
+ * against a threshold.
17
+ */
18
+
19
+ /**
20
+ * The PERIOD the panel reports — the one thing the header's switch selects.
21
+ *
22
+ * `today`/`7d`/`30d`/`90d` are trailing calendar spans ending today, labelled
23
+ * Day/Week/Month/90 days; `all` is unbounded. None of them is a grouping
24
+ * cadence: a period is a period, and every figure on the panel is the total for
25
+ * exactly that period.
26
+ */
2
27
  export type TimeRangeType = 'today' | '7d' | '30d' | '90d' | 'all' | 'custom';
3
- export type BreakdownTab = 'model' | 'day' | 'project';
28
+
29
+ /**
30
+ * How the selected period is chopped up for the chart and the time tab only.
31
+ *
32
+ * Derived from the period's own length (`granularityFor`), never chosen by the
33
+ * user: a month draws days, a quarter draws weeks, all time draws months.
34
+ */
35
+ export type BucketGranularity = 'day' | 'week' | 'month';
36
+ /** Breakdown tabs. `provider` and `model` render as one two-level tree. */
37
+ export type BreakdownTab = 'provider' | 'model' | 'day' | 'project';
4
38
  export type ChartMetric = 'cost' | 'tokens';
5
39
 
6
- export interface ChartSeriesPoint {
40
+ export interface TimeRangeOption {
41
+ id: TimeRangeType;
7
42
  label: string;
8
- cost: number;
9
- tokens: number;
43
+ /** The dates this range covers, already formatted for the header. */
44
+ dateRange: string;
10
45
  }
11
46
 
12
- export interface CustomRange {
13
- from: string;
14
- to: string;
47
+ /** Token and cost counters shared by every rollup row. */
48
+ export interface UsageCounters {
49
+ cost: number;
50
+ tokens: number;
51
+ input: number;
52
+ output: number;
53
+ cacheRead: number;
54
+ cacheWrite: number;
55
+ reasoning: number;
56
+ /** Cache-read rate: the observed input that was served from cache. */
57
+ cacheReadCost: number;
58
+ /** Usage records folded into this row. */
59
+ records: number;
60
+ /** Records carrying tokens but no provider-reported cost. */
61
+ unpriced: number;
15
62
  }
16
63
 
17
- export interface BreakdownRow {
18
- name: string;
19
- cost: string;
20
- share: string;
21
- tokens: string;
22
- sharePercent: number;
23
- dotColorClass: string;
64
+ /** Totals for the selected period. */
65
+ export interface UsageTotals extends UsageCounters {
66
+ /** Distinct days with at least one record. */
67
+ activeDays: number;
24
68
  }
25
69
 
26
- export interface TimeRangeOption {
27
- id: TimeRangeType;
70
+ /** One point of the flat chart series (single line, e.g. the mobile view). */
71
+ export interface ChartSeriesPoint {
28
72
  label: string;
29
- dateRange: string;
73
+ cost: number;
74
+ tokens: number;
30
75
  }
31
76
 
77
+ /** Display strings behind the headline tiles, already formatted. */
32
78
  export interface TokenUsageMetricSet {
33
79
  rawCost: string;
80
+ costPerMillion: string;
34
81
  processedTokens: string;
35
82
  activeRate: string;
36
83
  cachedInput: string;
37
84
  cachedPercent: string;
38
85
  uncachedInput: string;
86
+ cacheWrite: string;
39
87
  outputTokens: string;
40
88
  reasoning: string;
41
- cacheSavings: string;
42
- scannedTranscripts: number;
43
- usageRecords: number;
89
+ records: number;
90
+ unpricedRecords: number;
91
+ }
92
+
93
+ /** One model under a provider. `model` is omp's own id, verbatim. */
94
+ export interface UsageModelRow extends UsageCounters {
95
+ model: string;
96
+ }
97
+
98
+ /** One provider, with its models ordered by cost. */
99
+ export interface UsageProviderRow extends UsageCounters {
100
+ /** Canonical provider slug — stable identity, used as the selection key. */
101
+ id: string;
102
+ /** Display name (`Kenari.id`, `DeepSeek`, `Command Code`, …). */
103
+ name: string;
104
+ models: UsageModelRow[];
105
+ }
106
+
107
+ /** One calendar day, with the per-provider split the stacked chart needs. */
108
+ export interface UsageDayRow extends UsageCounters {
109
+ /** `YYYY-MM-DD` in the reader's local calendar. */
110
+ day: string;
111
+ /** Cost/tokens keyed by canonical provider slug. */
112
+ providers: Record<string, { cost: number; tokens: number }>;
113
+ }
114
+
115
+ /** One project (the sessions-tree folder the transcript lives in). */
116
+ export interface UsageProjectRow extends UsageCounters {
117
+ project: string;
118
+ }
119
+
120
+ /** How far the on-disk index has got, shown in the panel's footer. */
121
+ export interface UsageIndexState {
122
+ /** `building` while a scan is in flight; the panel polls and keeps the data. */
123
+ state: 'ready' | 'building' | 'failed';
124
+ /** Transcripts indexed (or visited so far, while building). */
125
+ transcripts: number;
126
+ /** Usage records indexed across every period. */
127
+ records: number;
128
+ /** Epoch ms of the last completed scan. */
129
+ indexedAt: number;
130
+ /** Wall-clock cost of that scan, so a slow disk is visible rather than guessed. */
131
+ scanMs: number;
132
+ /** Sentence for the panel when `state` is `failed`. */
133
+ error?: string;
134
+ }
135
+
136
+ /** Response body of `GET /api/telemetry/tokens`. */
137
+ export interface TokenUsagePayload {
138
+ generatedAt: number;
139
+ index: UsageIndexState;
140
+ timeRanges: TimeRangeOption[];
141
+ range: TimeRangeType;
142
+ /** Human period label, e.g. `Oct 5 – Nov 3, 2026`. */
143
+ periodLabel: string;
144
+ totals: UsageTotals;
145
+ /** Providers ordered by cost, each with its models ordered by cost. */
146
+ providers: UsageProviderRow[];
147
+ /** Daily rows ordered by day, ascending. */
148
+ days: UsageDayRow[];
149
+ /** Projects ordered by cost. */
150
+ projects: UsageProjectRow[];
44
151
  }
@@ -78,6 +78,26 @@ export interface UpdateChangelog {
78
78
  error: string | null;
79
79
  }
80
80
 
81
+ /**
82
+ * The release notes for the version a target is ACTUALLY RUNNING.
83
+ *
84
+ * This is the About modal's pair of "What's new" buttons: the update popup
85
+ * answers "what would I get", these answer "what am I running". Both versions
86
+ * are read server-side from the install itself, never from the caller, so the
87
+ * section shown always belongs to the copy on disk.
88
+ */
89
+ export interface ActiveReleaseNotes {
90
+ target: UpdateTarget;
91
+ /** The installed/running version whose section is shown, or null when unreadable. */
92
+ version: string | null;
93
+ /** That version's changelog section, or null when the file does not name it. */
94
+ note: ReleaseNote | null;
95
+ /** The repository changelog, for the "Full changelog" link. */
96
+ changelogUrl: string;
97
+ /** Human-readable reason `note` is absent, or null. */
98
+ error: string | null;
99
+ }
100
+
81
101
  export interface UpdateApplyResult {
82
102
  success: boolean;
83
103
  target: UpdateTarget;
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * @license
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ /**
8
+ * A scripted `omp` RPC child for the TRANSPORT questions `RpcProcess` owns.
9
+ *
10
+ * It exists because those questions cannot be asked of a real child: omp 18.16.0
11
+ * never advertises ceilings other than its own, and it never emits a malformed
12
+ * `rpc_chunk` sequence. Both are exactly what the reader must survive, so the
13
+ * child says what the test needs it to say.
14
+ *
15
+ * `ready` advertises what these env vars name, defaulting to omp's own values:
16
+ * FAKE_OMP_READY_MAX_FRAME_BYTES (default 1048576)
17
+ * FAKE_OMP_READY_MAX_REASSEMBLED_BYTES (default 67108864)
18
+ *
19
+ * `bash` is the trigger: it writes `FAKE_OMP_CHUNK` BEFORE answering, which is
20
+ * the only way to put a chunk record in front of the reader from inside the
21
+ * protocol. Values:
22
+ * `valid-1mib` — a complete 1 MiB sequence. Valid under the default 1 MiB
23
+ * physical ceiling, invalid under an advertised 4 MiB one
24
+ * (a frame that small is never chunked there).
25
+ * `bad-index` — a chunk that does not start at index 0: a hard fault.
26
+ * Anything else writes nothing.
27
+ *
28
+ * The source MUST stay constant: it is spawned as-is on every run.
29
+ */
30
+
31
+ import { appendFileSync } from 'node:fs';
32
+
33
+ const encoder = new TextEncoder();
34
+ const write = (frame: unknown) => {
35
+ process.stdout.write(encoder.encode(`${JSON.stringify(frame)}\n`));
36
+ };
37
+
38
+ const numberFromEnv = (name: string, fallback: number): number => {
39
+ const raw = Bun.env[name];
40
+ const parsed = raw === undefined ? Number.NaN : Number(raw);
41
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback;
42
+ };
43
+
44
+ const ready = {
45
+ type: 'ready',
46
+ protocolVersion: 1,
47
+ supportedProtocolVersions: [1, 2],
48
+ maxFrameBytes: numberFromEnv('FAKE_OMP_READY_MAX_FRAME_BYTES', 1024 * 1024),
49
+ maxReassembledFrameBytes: numberFromEnv('FAKE_OMP_READY_MAX_REASSEMBLED_BYTES', 64 * 1024 * 1024),
50
+ };
51
+
52
+ /**
53
+ * A complete, VALID chunk sequence for a 1 MiB logical frame — 4 slices of the
54
+ * 256 KiB a chunk may carry, and a byte length exactly at omp's default physical
55
+ * ceiling (so `byteLength >= maxFrameBytes` holds there and fails under any
56
+ * larger advertised ceiling).
57
+ *
58
+ * The demand is what makes the ceiling test meaningful: the SAME bytes are a
59
+ * valid sequence under the default ceiling and a protocol fault under an
60
+ * advertised 4 MiB one, because a frame that small is never chunked then.
61
+ */
62
+ const CHUNK_BYTES = 1024 * 1024;
63
+ const CHUNK_SLICE = 256 * 1024;
64
+ const CHUNK_COUNT = CHUNK_BYTES / CHUNK_SLICE;
65
+
66
+ function validSequence(): Uint8Array[] {
67
+ const head = '{"type":"noop","pad":"';
68
+ const tail = '"}';
69
+ const json = `${head}${'A'.repeat(CHUNK_BYTES - head.length - tail.length)}${tail}`;
70
+ const bytes = new TextEncoder().encode(json);
71
+ return Array.from({ length: CHUNK_COUNT }, (_, index) => bytes.subarray(index * CHUNK_SLICE, (index + 1) * CHUNK_SLICE));
72
+ }
73
+
74
+ function scriptedChunks(mode: string | undefined): Record<string, unknown>[] {
75
+ if (mode === 'valid-1mib') {
76
+ const slices = validSequence();
77
+ return slices.map((slice, index) => ({
78
+ type: 'rpc_chunk',
79
+ chunkId: 'fake-1',
80
+ index,
81
+ count: CHUNK_COUNT,
82
+ byteLength: CHUNK_BYTES,
83
+ data: slice.toBase64(),
84
+ }));
85
+ }
86
+ if (mode === 'bad-index') {
87
+ return [{
88
+ type: 'rpc_chunk',
89
+ chunkId: 'fake-2',
90
+ index: 5,
91
+ count: CHUNK_COUNT,
92
+ byteLength: CHUNK_BYTES,
93
+ data: new Uint8Array(1024).fill(65).toBase64(),
94
+ }];
95
+ }
96
+ return [];
97
+ }
98
+
99
+ const respond = (id: unknown, command: string, data: unknown) => {
100
+ write({ type: 'response', id, command, success: true, data });
101
+ };
102
+
103
+ const state = {
104
+ sessionId: 'fake-session',
105
+ sessionFile: '/tmp/fake-session.jsonl',
106
+ isStreaming: false,
107
+ isSettled: true,
108
+ isCompacting: false,
109
+ autoCompactionEnabled: true,
110
+ interruptMode: 'immediate',
111
+ steeringMode: 'one-at-a-time',
112
+ followUpMode: 'one-at-a-time',
113
+ messageCount: 0,
114
+ };
115
+
116
+ write(ready);
117
+
118
+ const decoder = new TextDecoder();
119
+ let buffer = '';
120
+ const stdin = Bun.stdin.stream().getReader();
121
+
122
+ for (;;) {
123
+ const { done, value } = await stdin.read();
124
+ if (done) break;
125
+ buffer += decoder.decode(value, { stream: true });
126
+ let newline = buffer.indexOf('\n');
127
+ while (newline !== -1) {
128
+ const line = buffer.slice(0, newline).trim();
129
+ buffer = buffer.slice(newline + 1);
130
+ newline = buffer.indexOf('\n');
131
+ if (!line) continue;
132
+ let frame: Record<string, unknown>;
133
+ try {
134
+ frame = JSON.parse(line) as Record<string, unknown>;
135
+ } catch {
136
+ continue;
137
+ }
138
+ const id = frame.id;
139
+ switch (frame.type) {
140
+ case 'negotiate_protocol':
141
+ respond(id, 'negotiate_protocol', { protocolVersion: 2 });
142
+ break;
143
+ case 'bash': {
144
+ for (const chunk of scriptedChunks(Bun.env.FAKE_OMP_CHUNK)) write(chunk);
145
+ respond(id, 'bash', { output: 'fake', exitCode: 0, cancelled: false, truncated: false, totalLines: 1, totalBytes: 4, outputLines: 1, outputBytes: 4 });
146
+ break;
147
+ }
148
+ case 'prompt': {
149
+ const log = Bun.env.FAKE_OMP_PROMPT_LOG;
150
+ if (log) {
151
+ try {
152
+ appendFileSync(log, `${JSON.stringify({ id, type: frame.type })}\n`);
153
+ } catch {}
154
+ }
155
+ respond(id, 'prompt', { agentInvoked: false });
156
+ break;
157
+ }
158
+ default:
159
+ respond(id, String(frame.type), state);
160
+ break;
161
+ }
162
+ }
163
+ }