@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
@@ -0,0 +1,273 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Native agent definitions: discovery, and the writer that edits omp's own
8
+ * markdown files in place.
9
+ *
10
+ * The field set here is omp's contract, measured against the installed
11
+ * `@oh-my-pi/pi-coding-agent` 18.16.0 (`discovery/helpers.ts`
12
+ * `parseAgentFields`): `name`, `description`, `tools`, `spawns`, `model`,
13
+ * `thinkingLevel`, and the body as the system prompt. Two failures are pinned:
14
+ *
15
+ * - **A key omp ignores must not be offered or written.** `mode`,
16
+ * `temperature` and `top_p` are none of omp's business; a pane editing them
17
+ * changed a file to no effect.
18
+ * - **A write must not delete what it does not own.** A shipped agent's
19
+ * block-list `tools:`, its `spawns:` and its nested `output:` schema have to
20
+ * survive an edit to the prompt or the model.
21
+ */
22
+
23
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
24
+ import fs from 'node:fs';
25
+ import { tmpdir } from 'node:os';
26
+ import { join } from 'node:path';
27
+
28
+ import { deleteAgentDefinition, discoverNativeAgents, writeAgentDefinition } from '@/server/lib/omp/config/agents';
29
+
30
+ let root = '';
31
+ let agentDir = '';
32
+ let userAgents = '';
33
+ let projectAgents = '';
34
+ let prevAgentDir: string | undefined;
35
+
36
+ /** Write a fixture file, creating its parent directory. */
37
+ function write(file: string, content: string): string {
38
+ fs.mkdirSync(join(file, '..'), { recursive: true });
39
+ fs.writeFileSync(file, content);
40
+ return file;
41
+ }
42
+
43
+ beforeAll(() => {
44
+ root = fs.mkdtempSync(join(tmpdir(), 'kabmo-agent-definitions-'));
45
+ agentDir = join(root, 'agent');
46
+ userAgents = join(agentDir, 'agents');
47
+ projectAgents = join(root, 'project-agents');
48
+ fs.mkdirSync(userAgents, { recursive: true });
49
+ fs.mkdirSync(projectAgents, { recursive: true });
50
+ prevAgentDir = Bun.env.PI_CODING_AGENT_DIR;
51
+ Bun.env.PI_CODING_AGENT_DIR = agentDir;
52
+ });
53
+
54
+ beforeEach(() => {
55
+ for (const dir of [userAgents, projectAgents]) {
56
+ for (const entry of fs.readdirSync(dir)) fs.rmSync(join(dir, entry), { recursive: true, force: true });
57
+ }
58
+ Bun.env.PI_CODING_AGENT_DIR = agentDir;
59
+ });
60
+
61
+ afterAll(() => {
62
+ if (prevAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
63
+ else Bun.env.PI_CODING_AGENT_DIR = prevAgentDir;
64
+ fs.rmSync(root, { recursive: true, force: true });
65
+ });
66
+
67
+ describe('discoverNativeAgents', () => {
68
+ /**
69
+ * Only the keys omp actually parses are surfaced. `mode` and `temperature`
70
+ * are NOT among them (measured against 18.16.0 `parseAgentFields`), so a
71
+ * panel that offered them was editing a file omp ignores.
72
+ */
73
+ test('shapes the frontmatter keys omp parses and skips non-markdown entries', async () => {
74
+ write(join(userAgents, 'one.md'), [
75
+ '---',
76
+ 'name: First',
77
+ 'description: "a description"',
78
+ 'model: kenari/deepseek-v4-flash',
79
+ 'thinking: high',
80
+ 'temperature: 0.5',
81
+ 'spawns: "*"',
82
+ '---',
83
+ '',
84
+ ' system prompt ',
85
+ '',
86
+ ].join('\n'));
87
+ write(join(userAgents, 'two.md'), 'no frontmatter body\n');
88
+ write(join(userAgents, 'ignored.txt'), 'x');
89
+ fs.mkdirSync(join(userAgents, 'nested.md'), { recursive: true });
90
+
91
+ const found = await discoverNativeAgents();
92
+ expect(found.map((agent) => agent.id).sort()).toEqual(['omp-user-one', 'omp-user-two']);
93
+ // By id, never by index: `readdir` order is not guaranteed (Windows returned `two` first).
94
+ const byId = new Map(found.map((agent) => [agent.id, agent]));
95
+ expect(byId.get('omp-user-one')).toMatchObject({
96
+ name: 'First',
97
+ description: 'a description',
98
+ model: 'kenari/deepseek-v4-flash',
99
+ thinkingLevel: 'high',
100
+ spawns: '*',
101
+ systemPrompt: 'system prompt',
102
+ sourceRoot: 'user',
103
+ filePath: join(userAgents, 'one.md'),
104
+ });
105
+ // `temperature` is not an agent key omp reads, so it is not carried.
106
+ expect(byId.get('omp-user-one')).not.toHaveProperty('temperature');
107
+ expect(byId.get('omp-user-two')).toMatchObject({
108
+ name: 'two', description: '', systemPrompt: 'no frontmatter body',
109
+ });
110
+ });
111
+
112
+ test('a model written as a block list is read, not missed', async () => {
113
+ // omp writes `model:` as a YAML sequence (its own shipped agents do), which
114
+ // a scalar-only frontmatter parser reads as an empty value.
115
+ write(join(userAgents, 'block.md'), '---\nname: Block\nmodel:\n - "@smol"\nthinkingLevel: medium\n---\nbody\n');
116
+ const agent = (await discoverNativeAgents()).find((item) => item.id === 'omp-user-block');
117
+ expect(agent).toMatchObject({ model: '@smol', thinkingLevel: 'medium' });
118
+ });
119
+
120
+ test('a user agent wins over a project agent with the same base name', async () => {
121
+ write(join(userAgents, 'shared.md'), '---\nname: FromUser\n---\nuser body\n');
122
+ write(join(projectAgents, 'shared.md'), '---\nname: FromProject\n---\nproject body\n');
123
+ write(join(projectAgents, 'project-only.md'), '---\nname: OnlyProject\n---\nbody\n');
124
+
125
+ const found = await discoverNativeAgents(projectAgents);
126
+ expect(found.find((agent) => agent.filePath === join(userAgents, 'shared.md'))?.name).toBe('FromUser');
127
+ expect(found.some((agent) => agent.filePath === join(projectAgents, 'shared.md'))).toBe(false);
128
+ expect(found.find((agent) => agent.id === 'omp-project-project-only')?.sourceRoot).toBe('project');
129
+ });
130
+
131
+ test('an oversized definition is skipped and a missing directory is not an error', async () => {
132
+ write(join(userAgents, 'huge.md'), `---\nname: Huge\n---\n${'x'.repeat(512 * 1024 + 1)}\n`);
133
+ const found = await discoverNativeAgents();
134
+ expect(found.some((agent) => agent.name === 'Huge')).toBe(false);
135
+ expect(await discoverNativeAgents(join(root, 'no-such-dir'))).toEqual(found);
136
+ });
137
+ });
138
+
139
+ describe('writeAgentDefinition', () => {
140
+ test('refuses an unsafe file name and an empty system prompt', async () => {
141
+ await expect(writeAgentDefinition({ fileName: '../escape', name: 'X', description: '', systemPrompt: 'x' }))
142
+ .rejects.toThrow(/may contain letters/);
143
+ await expect(writeAgentDefinition({ fileName: 'ok', name: 'X', description: '', systemPrompt: ' ' }))
144
+ .rejects.toThrow(/cannot be empty/);
145
+ expect(fs.existsSync(join(userAgents, 'ok.md'))).toBe(false);
146
+ });
147
+
148
+ test('writes the keys omp reads, quoting scalars, then deletes on request', async () => {
149
+ const { path } = await writeAgentDefinition({
150
+ fileName: 'written',
151
+ name: 'Written Agent',
152
+ description: 'has "quotes" and \\ slashes',
153
+ model: 'kenari/deepseek-v4-flash',
154
+ thinkingLevel: 'low',
155
+ spawns: '*',
156
+ tools: ['read', 'bash'],
157
+ systemPrompt: 'do the thing',
158
+ });
159
+ expect(path).toBe(join(userAgents, 'written.md'));
160
+ const text = fs.readFileSync(path, 'utf8');
161
+ expect(text).toContain('name: "Written Agent"');
162
+ expect(text).toContain('model: "kenari/deepseek-v4-flash"');
163
+ expect(text).toContain('thinkingLevel: low');
164
+ expect(text).toContain('spawns: "*"');
165
+ expect(text).toContain('tools: read, bash');
166
+ expect(text).toContain('has \\"quotes\\" and \\\\ slashes');
167
+ // Keys omp ignores are never written: they would be dead config.
168
+ expect(text).not.toContain('mode:');
169
+ expect(text).not.toContain('temperature');
170
+ expect(text).not.toContain('top_p');
171
+ expect(text.endsWith('\n')).toBe(true);
172
+
173
+ expect(await deleteAgentDefinition('written')).toBe(true);
174
+ expect(await deleteAgentDefinition('written')).toBe(false);
175
+ await expect(deleteAgentDefinition('bad/name')).rejects.toThrow(/Invalid agent file name/);
176
+ });
177
+
178
+ test('editing a shipped definition keeps the keys the panel does not own', async () => {
179
+ // A real omp agent file: a tools block list, an `output:` schema, and a key
180
+ // order the panel has no business rewriting.
181
+ write(join(userAgents, 'shipped.md'), [
182
+ '---',
183
+ 'name: shipped',
184
+ 'description: "Ship it"',
185
+ 'tools:',
186
+ ' - read',
187
+ ' - grep',
188
+ 'model:',
189
+ ' - "@smol"',
190
+ 'thinkingLevel: medium',
191
+ 'output:',
192
+ ' properties:',
193
+ ' summary:',
194
+ ' type: string',
195
+ '---',
196
+ '',
197
+ 'old prompt',
198
+ '',
199
+ ].join('\n'));
200
+
201
+ await writeAgentDefinition({
202
+ fileName: 'shipped',
203
+ name: 'shipped',
204
+ description: 'Ship it',
205
+ model: 'kenari/deepseek-v4-flash',
206
+ thinkingLevel: 'high',
207
+ systemPrompt: 'new prompt',
208
+ });
209
+
210
+ const text = fs.readFileSync(join(userAgents, 'shipped.md'), 'utf8');
211
+ // Preserved verbatim: the panel never touched them.
212
+ expect(text).toContain('tools:\n - read\n - grep\n');
213
+ expect(text).toContain('output:\n properties:\n summary:\n type: string\n');
214
+ // Replaced where it stood, so a stale `model:` block list cannot survive.
215
+ expect(text).toContain('model: "kenari/deepseek-v4-flash"');
216
+ expect(text).toContain('thinkingLevel: high');
217
+ expect(text).not.toContain('"@smol"');
218
+ expect(text).toContain('new prompt');
219
+ expect(text).not.toContain('old prompt');
220
+ // One name and one description, never a duplicate appended below.
221
+ expect(text.match(/^name:/gm)).toHaveLength(1);
222
+ expect(text.match(/^description:/gm)).toHaveLength(1);
223
+ });
224
+
225
+ test('an untouched tools field leaves the block list exactly as it was', async () => {
226
+ // The pane's tools box is a CSV view of a YAML list. Re-sending the same
227
+ // names as CSV rewrote four lines into one, which is a silent reformat of a
228
+ // file the user never edited.
229
+ const original = [
230
+ '---',
231
+ 'name: keep',
232
+ 'description: "Keep the list"',
233
+ 'tools:',
234
+ ' - read',
235
+ ' - grep',
236
+ '---',
237
+ '',
238
+ 'body',
239
+ '',
240
+ ].join('\n');
241
+ write(join(userAgents, 'keep.md'), original);
242
+
243
+ await writeAgentDefinition({
244
+ fileName: 'keep',
245
+ name: 'keep',
246
+ description: 'Keep the list',
247
+ systemPrompt: 'new body',
248
+ });
249
+
250
+ const text = fs.readFileSync(join(userAgents, 'keep.md'), 'utf8');
251
+ expect(text).toContain('tools:\n - read\n - grep\n');
252
+ expect(text).toContain('new body');
253
+ });
254
+
255
+ test('clearing the model removes the key so omp falls back to the role default', async () => {
256
+ await writeAgentDefinition({
257
+ fileName: 'clear',
258
+ name: 'clear',
259
+ description: '',
260
+ model: 'kenari/deepseek-v4-flash',
261
+ systemPrompt: 'body',
262
+ });
263
+ await writeAgentDefinition({
264
+ fileName: 'clear',
265
+ name: 'clear',
266
+ description: '',
267
+ model: '',
268
+ systemPrompt: 'body',
269
+ });
270
+ const text = fs.readFileSync(join(userAgents, 'clear.md'), 'utf8');
271
+ expect(text).not.toContain('model:');
272
+ });
273
+ });
@@ -4,58 +4,181 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Native OMP agent discovery — reads agent definition markdown files from
8
- * ~/.omp/agent/agents and <project>/.omp/agents so the settings agents list
9
- * surfaces the same agent definitions the omp agent loads. Discovery is
10
- * read-only: Kabmo never mutates native agent files.
7
+ * Native OMP agent discovery and writing.
8
+ *
9
+ * An agent definition is a markdown file with frontmatter, and omp reads a
10
+ * FIXED set of keys out of it — measured against the installed
11
+ * `@oh-my-pi/pi-coding-agent` 18.16.0 (`discovery/helpers.ts` `parseAgentFields`):
12
+ *
13
+ * name, description, tools, spawns, model, output, thinkingLevel,
14
+ * blocking, structured, prewalk, advisor, autoloadSkills, readSummarize
15
+ *
16
+ * Anything else in the file is ignored by omp, so a panel that offered `mode`,
17
+ * `temperature` or `top_p` was offering three controls that changed a file omp
18
+ * never reads — the agent kept behaving exactly as before. Worse, a writer that
19
+ * emitted ONLY its own keys silently DELETED `tools`, `spawns` and the nested
20
+ * `output:` schema from a shipped agent the moment its prompt was edited.
21
+ *
22
+ * Two rules follow, and both are load-bearing:
23
+ *
24
+ * - discovery parses the keys omp honours, including `model` as a block list
25
+ * (`model:\n - "@smol"`, which the scalar-only parser read as empty);
26
+ * - writing edits the frontmatter IN PLACE: a key the file already has is
27
+ * replaced where it stands, a key it lacks is appended, and every line the
28
+ * panel does not own — including a multi-line `output:` block — survives
29
+ * byte for byte.
11
30
  */
12
31
 
13
32
  import fs from 'fs';
14
33
  import { basename, join } from 'path';
15
34
  import { getAgentDir, pathExists } from '@/server/lib/omp/core/paths';
16
35
  import { writeFileAtomic } from '@/server/lib/fs/atomic-write';
17
- import { parseFrontmatter } from '@/server/lib/omp/config/yaml';
18
36
 
19
37
  export interface DiscoveredAgent {
20
38
  id: string;
21
39
  name: string;
22
40
  description: string;
23
- mode: 'primary' | 'subagent' | 'all';
24
- overrideModel?: string;
25
- thinkingVariant?: string;
26
- temperature?: number | null;
27
- topP?: number | null;
41
+ /** Tool allowlist; absent means omp's default set. */
42
+ tools?: string[];
43
+ /** `"*"` or a name list: which agents this one may spawn. */
44
+ spawns?: string;
45
+ /** `provider/model`, or a role selector such as `@smol`. */
46
+ model?: string;
47
+ /** `off` … `max`, or `auto`; absent means the session's level. */
48
+ thinkingLevel?: string;
28
49
  systemPrompt: string;
29
- /** Which disk root the agent was discovered from. */
30
50
  sourceRoot: 'user' | 'project';
31
51
  filePath: string;
32
52
  }
33
53
 
34
- function toMode(value: string | undefined): 'primary' | 'subagent' | 'all' {
35
- return value === 'primary' || value === 'subagent' || value === 'all' ? value : 'all';
54
+ /** A key the panel owns, so it may be rewritten. Everything else is preserved. */
55
+ export interface AgentFileInput {
56
+ fileName: string;
57
+ name: string;
58
+ description: string;
59
+ /** Cleared when empty — an absent key is how omp spells "use the default". */
60
+ model?: string;
61
+ thinkingLevel?: string;
62
+ /** `undefined` leaves the file's own tools line untouched. */
63
+ tools?: string[];
64
+ spawns?: string;
65
+ systemPrompt: string;
66
+ }
67
+
68
+ /** Frontmatter scalar keys the panel edits. */
69
+ const OWNED_KEYS = ['name', 'description', 'model', 'thinkingLevel', 'tools', 'spawns'] as const;
70
+ type OwnedKey = (typeof OWNED_KEYS)[number];
71
+
72
+ /** Unquote a frontmatter scalar the way omp writes it. */
73
+ function unquote(raw: string): string {
74
+ const trimmed = raw.trim();
75
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') && trimmed.length >= 2) {
76
+ return trimmed.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
77
+ }
78
+ if (trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length >= 2) {
79
+ return trimmed.slice(1, -1);
80
+ }
81
+ return trimmed;
82
+ }
83
+
84
+ /** Quote a value so a `:` or `#` in it cannot change the document's meaning. */
85
+ function quote(value: string): string {
86
+ return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
87
+ }
88
+
89
+ interface FrontmatterBlock {
90
+ /** Lines between the fences (`[]` for a file with an empty block). */
91
+ lines: string[];
92
+ /** Everything after the closing fence, fence included in `body`'s own prefix. */
93
+ body: string;
94
+ /** True when the file has no frontmatter fences at all. */
95
+ missing: boolean;
96
+ }
97
+
98
+ /** Split a definition file into its frontmatter lines and its body. */
99
+ function splitDefinition(text: string): FrontmatterBlock {
100
+ const match = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*\r?\n?/.exec(text);
101
+ if (!match) return { lines: [], body: text, missing: true };
102
+ return {
103
+ lines: match[1].split(/\r?\n/),
104
+ body: text.slice(match[0].length),
105
+ missing: false,
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Read the frontmatter of a definition into the keys omp actually parses.
111
+ *
112
+ * `parseFrontmatter` in `yaml.ts` is scalar-only and cannot see a block list —
113
+ * and `model` is written as one (`model:\n - "@smol"`), so probing it with that
114
+ * parser reported every shipped agent as having no model.
115
+ */
116
+ export function parseAgentDefinition(text: string): {
117
+ name?: string;
118
+ description?: string;
119
+ model?: string;
120
+ thinkingLevel?: string;
121
+ tools?: string[];
122
+ spawns?: string;
123
+ body: string;
124
+ } {
125
+ const { lines, body } = splitDefinition(text);
126
+ const scalars = new Map<string, string>();
127
+ const lists = new Map<string, string[]>();
128
+ let current: string | null = null;
129
+
130
+ for (const line of lines) {
131
+ const listItem = /^\s*-\s+(.*)$/.exec(line);
132
+ if (listItem && current) {
133
+ const values = lists.get(current) ?? [];
134
+ values.push(unquote(listItem[1]));
135
+ lists.set(current, values);
136
+ continue;
137
+ }
138
+ const entry = /^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(line);
139
+ if (!entry) continue;
140
+ current = entry[1];
141
+ const value = unquote(entry[2]);
142
+ if (value) scalars.set(current, value);
143
+ else if (!lists.has(current)) lists.set(current, []);
144
+ }
145
+
146
+ const toolsRaw = scalars.get('tools') ?? lists.get('tools')?.join(',');
147
+ const tools = toolsRaw
148
+ ? toolsRaw.split(',').map((item) => item.trim()).filter(Boolean)
149
+ : undefined;
150
+
151
+ return {
152
+ ...(scalars.has('name') ? { name: scalars.get('name') } : {}),
153
+ ...(scalars.has('description') ? { description: scalars.get('description') } : {}),
154
+ // omp accepts either spelling; `thinkingLevel` is the one it writes.
155
+ ...(scalars.has('thinkingLevel') ? { thinkingLevel: scalars.get('thinkingLevel') }
156
+ : scalars.has('thinking') ? { thinkingLevel: scalars.get('thinking') } : {}),
157
+ ...(scalars.has('model') ? { model: scalars.get('model') }
158
+ : lists.get('model')?.length ? { model: lists.get('model')![0] } : {}),
159
+ ...(tools ? { tools } : {}),
160
+ ...(scalars.has('spawns') ? { spawns: scalars.get('spawns') } : {}),
161
+ body: body.trim(),
162
+ };
36
163
  }
37
164
 
38
165
  async function parseAgentFile(filePath: string, sourceRoot: 'user' | 'project'): Promise<DiscoveredAgent | undefined> {
39
166
  try {
40
167
  const file = Bun.file(filePath);
41
168
  if ((await file.stat()).size > 512 * 1024) return undefined;
42
- const text = await file.text();
43
- const { data, body } = parseFrontmatter(text);
169
+ const parsed = parseAgentDefinition(await file.text());
44
170
  const base = basename(filePath).replace(/\.md$/, '') || filePath;
45
- const name = data.name || base;
171
+ const name = parsed.name || base;
46
172
  if (!name) return undefined;
47
- const temperature = data.temperature !== undefined && data.temperature !== '' ? Number(data.temperature) : null;
48
- const topP = data.top_p !== undefined && data.top_p !== '' ? Number(data.top_p) : null;
49
173
  return {
50
174
  id: `omp-${sourceRoot}-${base}`,
51
175
  name,
52
- description: data.description || '',
53
- mode: toMode(data.mode),
54
- overrideModel: data.model || undefined,
55
- thinkingVariant: data.thinking || undefined,
56
- temperature: Number.isFinite(temperature) ? temperature : null,
57
- topP: Number.isFinite(topP) ? topP : null,
58
- systemPrompt: body.trim(),
176
+ description: parsed.description ?? '',
177
+ ...(parsed.tools ? { tools: parsed.tools } : {}),
178
+ ...(parsed.spawns ? { spawns: parsed.spawns } : {}),
179
+ ...(parsed.model ? { model: parsed.model } : {}),
180
+ ...(parsed.thinkingLevel ? { thinkingLevel: parsed.thinkingLevel } : {}),
181
+ systemPrompt: parsed.body,
59
182
  sourceRoot,
60
183
  filePath,
61
184
  };
@@ -98,34 +221,49 @@ export async function discoverNativeAgents(projectDir?: string): Promise<Discove
98
221
  return [...byBase.values()];
99
222
  }
100
223
 
101
- /** Escape a frontmatter scalar value into a safe quoted string. */
102
- function fmValue(value: string): string {
103
- return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
104
- }
105
-
106
- function optionalFmLine(lines: string[], key: string, value: string | number | null | undefined): void {
107
- if (value === null || value === undefined || value === '') return;
108
- lines.push(`${key}: ${typeof value === 'number' ? value : fmValue(String(value))}`);
224
+ /** How many lines a top-level key occupies, continuation lines included. */
225
+ function blockLength(lines: string[], start: number): number {
226
+ let end = start + 1;
227
+ while (end < lines.length && /^\s+\S/.test(lines[end])) end++;
228
+ return end - start;
109
229
  }
110
230
 
111
- export interface AgentFileInput {
112
- /** File base name without .md (also the agent name unless name is given). */
113
- fileName: string;
114
- name?: string;
115
- description?: string;
116
- mode?: string;
117
- model?: string;
118
- thinking?: string;
119
- temperature?: number | null;
120
- topP?: number | null;
121
- tools?: string[];
122
- systemPrompt: string;
231
+ /**
232
+ * The YAML lines for one owned key.
233
+ *
234
+ * - `string[]` — write these lines;
235
+ * - `null` — REMOVE the key (that is how omp spells "use the default");
236
+ * - `undefined` — leave whatever the file already has alone.
237
+ *
238
+ * `tools: undefined` is the third case on purpose: the pane does not offer a
239
+ * tool allowlist, and re-serializing one would flatten a block list or, worse,
240
+ * delete a restriction the shipped agent depends on.
241
+ */
242
+ function renderKey(key: OwnedKey, input: AgentFileInput): string[] | null | undefined {
243
+ if (key === 'tools') {
244
+ if (input.tools === undefined) return undefined;
245
+ return input.tools.length === 0 ? null : [`tools: ${input.tools.join(', ')}`];
246
+ }
247
+ const value = key === 'name' ? input.name
248
+ : key === 'description' ? input.description
249
+ : key === 'model' ? input.model
250
+ : input.spawns;
251
+ if (key === 'thinkingLevel') {
252
+ return input.thinkingLevel ? ['thinkingLevel: ' + input.thinkingLevel] : null;
253
+ }
254
+ if (!value || !value.trim()) return null;
255
+ // `spawns: *` is a YAML alias, so a bare star has to be quoted.
256
+ return [`${key}: ${key === 'spawns' ? quote(value.trim()) : quote(value)}`];
123
257
  }
124
258
 
125
259
  /**
126
- * Write (create or replace) a user-level agent definition markdown file.
127
- * Project agents are intentionally not writable from Kabmo — the agent
128
- * dir belongs to omp.
260
+ * Rewrite one definition file, preserving every line the panel does not own.
261
+ *
262
+ * The owned key is replaced WHERE IT STANDS (rather than the frontmatter being
263
+ * re-serialized from a record), so a shipped agent keeps its key order, its
264
+ * comments, its `tools` list style and its nested `output:` schema. Keys the
265
+ * file lacks are appended in a stable order, so re-saving an untouched file
266
+ * changes nothing but the key that was edited.
129
267
  */
130
268
  export async function writeAgentDefinition(input: AgentFileInput): Promise<{ path: string }> {
131
269
  if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(input.fileName)) {
@@ -134,22 +272,54 @@ export async function writeAgentDefinition(input: AgentFileInput): Promise<{ pat
134
272
  if (!input.systemPrompt.trim()) {
135
273
  throw new Error('Agent system prompt cannot be empty');
136
274
  }
275
+
137
276
  const dir = join(getAgentDir(), 'agents');
138
277
  const path = join(dir, `${input.fileName}.md`);
139
- const lines: string[] = ['---'];
140
- optionalFmLine(lines, 'name', input.name ?? input.fileName);
141
- optionalFmLine(lines, 'description', input.description);
142
- optionalFmLine(lines, 'mode', input.mode);
143
- optionalFmLine(lines, 'model', input.model);
144
- optionalFmLine(lines, 'thinking-level', input.thinking);
145
- optionalFmLine(lines, 'temperature', input.temperature ?? null);
146
- optionalFmLine(lines, 'top_p', input.topP ?? null);
147
- if (input.tools && input.tools.length > 0) {
148
- lines.push(`tools: ${input.tools.map(fmValue).join(', ')}`);
278
+ const existing = (await Bun.file(path).exists()) ? await Bun.file(path).text() : '';
279
+ const { lines, missing } = splitDefinition(existing);
280
+
281
+ /** Old spellings of keys the panel owns are dropped, so one file cannot carry two. */
282
+ const aliases = new Map<string, OwnedKey>([
283
+ ['thinking', 'thinkingLevel'],
284
+ ['thinking-level', 'thinkingLevel'],
285
+ ]);
286
+
287
+ const output: string[] = [];
288
+ const handled = new Set<OwnedKey>();
289
+
290
+ for (let index = 0; index < lines.length;) {
291
+ const entry = /^([A-Za-z_][\w-]*)\s*:/.exec(lines[index]);
292
+ if (!entry) {
293
+ output.push(lines[index]);
294
+ index += 1;
295
+ continue;
296
+ }
297
+ const key = entry[1];
298
+ const length = blockLength(lines, index);
299
+ const ownedKey = OWNED_KEYS.includes(key as OwnedKey)
300
+ ? (key as OwnedKey)
301
+ : aliases.get(key) ?? null;
302
+ const keepVerbatim = ownedKey === null || handled.has(ownedKey);
303
+ const rendered = ownedKey === null ? undefined : renderKey(ownedKey, input);
304
+ if (ownedKey !== null) handled.add(ownedKey);
305
+ if (keepVerbatim || rendered === undefined) {
306
+ for (let offset = 0; offset < length; offset++) output.push(lines[index + offset]);
307
+ } else if (rendered) {
308
+ output.push(...rendered);
309
+ }
310
+ index += length;
149
311
  }
150
- lines.push('---');
151
- const content = `${lines.join('\n')}\n\n${input.systemPrompt.trim()}\n`;
152
- await writeFileAtomic(path, content);
312
+
313
+ for (const key of OWNED_KEYS) {
314
+ if (handled.has(key)) continue;
315
+ const rendered = renderKey(key, input);
316
+ if (rendered) output.push(...rendered);
317
+ }
318
+
319
+ const prompt = input.systemPrompt.trim();
320
+ const block = `---\n${output.join('\n')}\n---\n\n${prompt}\n`;
321
+ // A file with no frontmatter fences gets one prepended; nothing it held is lost.
322
+ await writeFileAtomic(path, missing && existing.trim() ? `---\n${output.join('\n')}\n---\n\n${existing.trim()}\n` : block);
153
323
  return { path };
154
324
  }
155
325