@kabmo-labs/kabmo 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +538 -457
  3. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  4. package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
  5. package/package.json +1 -1
  6. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  7. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  8. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  9. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  10. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  11. package/src/client/components/common/markdown-review/index.tsx +129 -0
  12. package/src/client/components/common/server-control/Panel.tsx +33 -23
  13. package/src/client/components/common/server-control/index.test.tsx +11 -5
  14. package/src/client/components/common/server-control/index.tsx +10 -8
  15. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  16. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  17. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  18. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  19. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  20. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  23. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  24. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  25. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  26. package/src/client/components/layout/update-popup/index.tsx +5 -1
  27. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  28. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  29. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  30. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  31. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  32. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  33. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  34. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  35. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  36. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  37. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  38. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  39. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  40. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  41. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  42. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  43. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  44. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  45. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  46. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  47. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  48. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  49. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  50. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  51. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  52. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  53. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  54. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  55. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  56. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  57. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  58. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  59. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  60. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
  61. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  62. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  63. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  64. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  65. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  66. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  67. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  68. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  69. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  70. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  71. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  72. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  73. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  74. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  75. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  76. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  77. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  78. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  87. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  88. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  89. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  90. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  91. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  92. package/src/client/components/workspace/editor/Body.tsx +7 -0
  93. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  94. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  95. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  96. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  97. package/src/client/components/workspace/editor/index.tsx +25 -22
  98. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  99. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  100. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  101. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  102. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  103. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  104. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  105. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  106. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  107. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  108. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  109. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  110. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  111. package/src/client/data/agent-data/builtin.ts +0 -10
  112. package/src/client/data/agent-data/orchestrator.ts +0 -45
  113. package/src/client/data/agent-data/specialist.ts +0 -100
  114. package/src/client/data/mock/token-usage.ts +170 -120
  115. package/src/client/data/settings/omp-schema.json +33 -1
  116. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  117. package/src/client/hooks/browser/use-annotate.ts +98 -0
  118. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  119. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  120. package/src/client/hooks/browser/use-screencast.ts +13 -1
  121. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  122. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  123. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  124. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  125. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  126. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  127. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  128. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  129. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  130. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  131. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  132. package/src/client/hooks/settings/agents.ts +149 -0
  133. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  134. package/src/client/hooks/settings/crud-list.ts +96 -57
  135. package/src/client/hooks/settings/omp-config.ts +164 -0
  136. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  137. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  138. package/src/client/hooks/settings/write-feedback.ts +63 -0
  139. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  140. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  141. package/src/client/hooks/ui/updates/index.ts +50 -0
  142. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  143. package/src/client/hooks/ui/updates/notes.ts +57 -0
  144. package/src/client/lib/browser/element-at.test.ts +229 -0
  145. package/src/client/lib/browser/element-at.ts +139 -0
  146. package/src/client/lib/review/client.ts +73 -0
  147. package/src/client/lib/router/search-params.ts +42 -20
  148. package/src/client/tailwind.css +65 -0
  149. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  150. package/src/server/lib/db/schema.ts +7 -0
  151. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  152. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  153. package/src/server/lib/omp/config/agents.ts +231 -61
  154. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  155. package/src/server/lib/omp/config/extensions.ts +16 -7
  156. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  157. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  158. package/src/server/lib/omp/rpc/constants.ts +15 -0
  159. package/src/server/lib/omp/rpc/process.ts +11 -14
  160. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  161. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  162. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  163. package/src/server/lib/omp/rpc/utility.ts +12 -0
  164. package/src/server/lib/review/schema.server.ts +45 -0
  165. package/src/server/lib/review/store.server.ts +138 -0
  166. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  167. package/src/server/lib/terminal/output.test.ts +166 -0
  168. package/src/server/lib/terminal/output.ts +104 -0
  169. package/src/server/lib/terminal/runtime.server.ts +5 -0
  170. package/src/server/lib/terminal/send-result.test.ts +33 -0
  171. package/src/server/lib/terminal/send-result.ts +32 -0
  172. package/src/server/lib/terminal/session.server.ts +45 -11
  173. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  174. package/src/server/lib/updates/active-notes.test.ts +149 -0
  175. package/src/server/lib/updates/active-notes.ts +75 -0
  176. package/src/server/lib/updates/changelog-file.ts +42 -11
  177. package/src/server/lib/updates/changelog.test.ts +15 -1
  178. package/src/server/lib/updates/omp.ts +42 -15
  179. package/src/server/lib/updates/release-url.ts +27 -1
  180. package/src/server/lib/usage/index-parse.test.ts +200 -0
  181. package/src/server/lib/usage/index-parse.ts +178 -0
  182. package/src/server/lib/usage/index-query.server.ts +248 -0
  183. package/src/server/lib/usage/index-scan.server.ts +343 -0
  184. package/src/server/lib/usage/index-schema.server.ts +82 -0
  185. package/src/server/lib/usage/index.test.ts +234 -0
  186. package/src/server/lib/usage/providers.server.ts +4 -53
  187. package/src/server/routes/browser/index.ts +3 -0
  188. package/src/server/routes/browser/stream.ts +31 -2
  189. package/src/server/routes/browser/tabs.test.ts +94 -0
  190. package/src/server/routes/browser/tabs.ts +85 -0
  191. package/src/server/routes/index.ts +2 -0
  192. package/src/server/routes/review/bindings.ts +11 -0
  193. package/src/server/routes/review/index.ts +127 -0
  194. package/src/server/routes/review/routes.test.ts +191 -0
  195. package/src/server/routes/settings/agents.test.ts +180 -0
  196. package/src/server/routes/settings/agents.ts +95 -102
  197. package/src/server/routes/settings/mcp.test.ts +135 -0
  198. package/src/server/routes/settings/mcp.ts +14 -6
  199. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  200. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  201. package/src/server/routes/telemetry/tokens.ts +70 -149
  202. package/src/server/routes/terminal/ws.ts +6 -5
  203. package/src/server/routes/updates/index.ts +2 -0
  204. package/src/server/routes/updates/notes.ts +34 -0
  205. package/src/server/routes/updates/routes.test.ts +49 -0
  206. package/src/shared/lib/browser/annotate.test.ts +283 -0
  207. package/src/shared/lib/browser/annotate.ts +231 -0
  208. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  209. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  210. package/src/shared/lib/browser/frame-gate.ts +69 -0
  211. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  212. package/src/shared/lib/browser/frame-params.ts +60 -0
  213. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  214. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  215. package/src/shared/lib/browser/page-context.ts +60 -4
  216. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  217. package/src/shared/lib/browser/snapshot.ts +112 -0
  218. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  219. package/src/shared/lib/browser/tab-close.ts +77 -0
  220. package/src/shared/lib/browser/viewer.ts +45 -26
  221. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  222. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  223. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  224. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  225. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  226. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  227. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  228. package/src/shared/lib/chat/tool/summary.ts +3 -32
  229. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  230. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  231. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  232. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  233. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  234. package/src/shared/lib/markdown/marked.ts +58 -147
  235. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  236. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  237. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  238. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  239. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  240. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  241. package/src/shared/lib/models/provider/label.ts +57 -0
  242. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  243. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  244. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  245. package/src/shared/lib/omp/config/row-value.ts +97 -0
  246. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  247. package/src/shared/lib/omp/config/schema.ts +6 -0
  248. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  249. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  250. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  251. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  252. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  253. package/src/shared/lib/usage/breakdown.ts +241 -0
  254. package/src/shared/lib/usage/range.test.ts +204 -0
  255. package/src/shared/lib/usage/range.ts +240 -0
  256. package/src/shared/lib/usage/view.test.ts +85 -0
  257. package/src/shared/lib/usage/view.ts +74 -0
  258. package/src/shared/types/browser.ts +78 -0
  259. package/src/shared/types/index.ts +1 -0
  260. package/src/shared/types/settings/agent.ts +28 -6
  261. package/src/shared/types/settings/state.ts +4 -3
  262. package/src/shared/types/settings/write.ts +6 -0
  263. package/src/shared/types/tokenUsage.ts +128 -21
  264. package/src/shared/types/updates.ts +20 -0
  265. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  266. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  267. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  268. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  269. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
@@ -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
 
@@ -4,17 +4,15 @@
4
4
  */
5
5
 
6
6
  /**
7
- * The definition files Kabmo owns (agents, instruction files) and the plugin CLI wrapper. Agent discovery is read-only and forgiving: a malformed
8
- * frontmatter field becomes a default (`mode: all`, `temperature: null`) rather
9
- * than dropping the agent, a non-`.md` entry and an oversized file are skipped,
10
- * and a USER agent wins over a project agent with the same base name.
11
- * `writeAgentDefinition` is the only writer — it refuses a name that escapes the
12
- * agents directory and an empty prompt, and emits exactly the frontmatter keys
13
- * omp reads (`thinking-level`, `top_p`) with quoted scalars. An instruction file
14
- * of only whitespace REMOVES the file, or an empty AGENTS.md would still claim
15
- * the context scope; plugin wrappers pass `--scope` only where omp accepts it,
16
- * and `pluginCliError` prefers stderr. `PI_CODING_AGENT_DIR` points at a temp
17
- * dir and `KABMO_OMP_BIN` at a stub recording its argv — no real process (the stub is a compiled executable, so it spawns on both platforms).
7
+ * The definition files Kabmo owns besides agent definitions (the instruction
8
+ * files) and the plugin CLI wrapper. Agent discovery and the agent-file writer
9
+ * have their own suite, `agent-definitions.test.ts`.
10
+ *
11
+ * An instruction file of only whitespace REMOVES the file, or an empty AGENTS.md
12
+ * would still claim the context scope; plugin wrappers pass `--scope` only where
13
+ * omp accepts it, and `pluginCliError` prefers stderr. `PI_CODING_AGENT_DIR`
14
+ * points at a temp dir and `KABMO_OMP_BIN` at a stub recording its argv — no real
15
+ * process (the stub is a compiled executable, so it spawns on both platforms).
18
16
  */
19
17
 
20
18
  import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
@@ -23,7 +21,6 @@ import fs from 'node:fs';
23
21
  import { tmpdir } from 'node:os';
24
22
  import { join } from 'node:path';
25
23
 
26
- import { deleteAgentDefinition, discoverNativeAgents, writeAgentDefinition } from '@/server/lib/omp/config/agents';
27
24
  import { invalidateOmpCliCache } from '@/server/lib/omp/core/cli';
28
25
  import {
29
26
  clearInstructionFile,
@@ -111,99 +108,6 @@ afterAll(() => {
111
108
  fs.rmSync(root, { recursive: true, force: true });
112
109
  });
113
110
 
114
- describe('discoverNativeAgents', () => {
115
- test('shapes frontmatter, defaults malformed fields, and skips non-markdown entries', async () => {
116
- write(join(userAgents, 'one.md'), [
117
- '---',
118
- 'name: First',
119
- 'description: "a description"',
120
- 'mode: subagent',
121
- 'model: fast',
122
- 'thinking: high',
123
- 'temperature: 0.5',
124
- 'top_p: nope',
125
- '---',
126
- '',
127
- ' system prompt ',
128
- '',
129
- ].join('\n'));
130
- write(join(userAgents, 'two.md'), 'no frontmatter body\n');
131
- write(join(userAgents, 'ignored.txt'), 'x');
132
- fs.mkdirSync(join(userAgents, 'nested.md'), { recursive: true });
133
-
134
- const found = await discoverNativeAgents();
135
- expect(found.map((agent) => agent.id).sort()).toEqual(['omp-user-one', 'omp-user-two']);
136
- // By id, never by index: `readdir` order is not guaranteed (Windows returned `two` first).
137
- const byId = new Map(found.map((agent) => [agent.id, agent]));
138
- expect(byId.get('omp-user-one')).toMatchObject({
139
- name: 'First', description: 'a description', mode: 'subagent', overrideModel: 'fast', thinkingVariant: 'high',
140
- temperature: 0.5, topP: null, systemPrompt: 'system prompt', sourceRoot: 'user', filePath: join(userAgents, 'one.md'),
141
- });
142
- expect(byId.get('omp-user-two')).toMatchObject({
143
- name: 'two', description: '', mode: 'all', temperature: null, topP: null, systemPrompt: 'no frontmatter body',
144
- });
145
- });
146
-
147
- test('an unrecognized mode and a non-numeric temperature degrade to defaults', async () => {
148
- write(join(userAgents, 'weird.md'), '---\nmode: wizard\ntemperature: hot\n---\nbody\n');
149
- const agent = (await discoverNativeAgents()).find((item) => item.id === 'omp-user-weird');
150
- expect(agent).toMatchObject({ mode: 'all', temperature: null });
151
- });
152
-
153
- test('a user agent wins over a project agent with the same base name', async () => {
154
- write(join(userAgents, 'shared.md'), '---\nname: FromUser\n---\nuser body\n');
155
- write(join(projectAgents, 'shared.md'), '---\nname: FromProject\n---\nproject body\n');
156
- write(join(projectAgents, 'project-only.md'), '---\nname: OnlyProject\n---\nbody\n');
157
-
158
- const found = await discoverNativeAgents(projectAgents);
159
- expect(found.find((agent) => agent.filePath === join(userAgents, 'shared.md'))?.name).toBe('FromUser');
160
- expect(found.some((agent) => agent.filePath === join(projectAgents, 'shared.md'))).toBe(false);
161
- expect(found.find((agent) => agent.id === 'omp-project-project-only')?.sourceRoot).toBe('project');
162
- });
163
-
164
- test('an oversized definition is skipped and a missing directory is not an error', async () => {
165
- write(join(userAgents, 'huge.md'), `---\nname: Huge\n---\n${'x'.repeat(512 * 1024 + 1)}\n`);
166
- const found = await discoverNativeAgents();
167
- expect(found.some((agent) => agent.name === 'Huge')).toBe(false);
168
- expect(await discoverNativeAgents(join(root, 'no-such-dir'))).toEqual(found);
169
- });
170
- });
171
-
172
- describe('writeAgentDefinition', () => {
173
- test('refuses an unsafe file name and an empty system prompt', async () => {
174
- await expect(writeAgentDefinition({ fileName: '../escape', systemPrompt: 'x' })).rejects.toThrow(/may contain letters/);
175
- await expect(writeAgentDefinition({ fileName: 'ok', systemPrompt: ' ' })).rejects.toThrow(/cannot be empty/);
176
- expect(fs.existsSync(join(userAgents, 'ok.md'))).toBe(false);
177
- });
178
-
179
- test('writes omp frontmatter keys, quoting scalars, then deletes on request', async () => {
180
- const { path } = await writeAgentDefinition({
181
- fileName: 'written',
182
- description: 'has "quotes" and \\ slashes',
183
- mode: 'primary',
184
- thinking: 'low',
185
- temperature: 0.2,
186
- topP: 0.9,
187
- tools: ['read', 'bash'],
188
- systemPrompt: 'do the thing',
189
- });
190
- expect(path).toBe(join(userAgents, 'written.md'));
191
- const text = fs.readFileSync(path, 'utf8');
192
- expect(text).toContain('name: "written"');
193
- expect(text).toContain('mode: "primary"');
194
- expect(text).toContain('thinking-level: "low"');
195
- expect(text).toContain('temperature: 0.2');
196
- expect(text).toContain('top_p: 0.9');
197
- expect(text).toContain('tools: "read", "bash"');
198
- expect(text).toContain('has \\"quotes\\" and \\\\ slashes');
199
- expect(text.endsWith('\n')).toBe(true);
200
-
201
- expect(await deleteAgentDefinition('written')).toBe(true);
202
- expect(await deleteAgentDefinition('written')).toBe(false);
203
- await expect(deleteAgentDefinition('bad/name')).rejects.toThrow(/Invalid agent file name/);
204
- });
205
- });
206
-
207
111
  describe('instruction files', () => {
208
112
  test('narrows the kind and resolves the two omp basenames', () => {
209
113
  expect(isInstructionFileKind('agents')).toBe(true);
@@ -12,7 +12,7 @@
12
12
  import { join } from 'path';
13
13
  import { getAgentDir, pathExists } from '@/server/lib/omp/core/paths';
14
14
  import { getOmpConfigPath } from '@/server/lib/omp/config/yaml';
15
- import { withOmpYamlDocument } from '@/server/lib/omp/config/document';
15
+ import { seqAt, valueAt, withOmpYamlDocument } from '@/server/lib/omp/config/document';
16
16
  import { isRecord } from '@/shared/lib/util/guards';
17
17
 
18
18
  export interface DiscoveredExtension {
@@ -75,17 +75,26 @@ export async function readDisabledExtensions(): Promise<Set<string>> {
75
75
  }
76
76
  }
77
77
 
78
- /** Toggle one extension id in config.yml disabledExtensions atomically. */
78
+ /**
79
+ * Toggle one extension id in config.yml `disabledExtensions` atomically.
80
+ *
81
+ * The list is read through `valueAt`, which unwraps the YAML node: `doc.get()`
82
+ * returns a SEQ node, and `Array.isArray` on a node is `false` — so the whole
83
+ * list read as empty. Disabling then wrote a one-item list over the user's
84
+ * others, and ENABLING found the id absent from its own empty view, answered
85
+ * "nothing to do", and left the extension disabled forever.
86
+ */
79
87
  export async function setExtensionDisabled(id: string, disabled: boolean): Promise<boolean> {
80
88
  if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(id)) throw new Error('Invalid extension id');
81
89
  const path = getOmpConfigPath();
82
90
  return withOmpYamlDocument(path, (doc) => {
83
- const current = doc.get('disabledExtensions');
84
- const list = Array.isArray(current)
85
- ? current.filter((item): item is string => typeof item === 'string')
86
- : [];
91
+ const raw = valueAt(doc, ['disabledExtensions']);
92
+ const list = Array.isArray(raw) ? raw.filter((item): item is string => typeof item === 'string') : [];
87
93
  if (disabled === list.includes(id)) return { result: false, changed: false };
88
- doc.set('disabledExtensions', disabled ? [...list, id] : list.filter((item) => item !== id));
94
+ const next = disabled ? [...list, id] : list.filter((item) => item !== id);
95
+ const seq = seqAt(doc, ['disabledExtensions']);
96
+ if (seq) seq.items = next;
97
+ else doc.set('disabledExtensions', next);
89
98
  return { result: true, changed: true };
90
99
  });
91
100
  }
@@ -248,6 +248,33 @@ describe('extensions', () => {
248
248
  expect(await setExtensionDisabled('skill:a', false)).toBe(false);
249
249
  expect(await fs.promises.readFile(configPath, 'utf8')).toBe('theme: dark\n');
250
250
  });
251
+
252
+ /**
253
+ * The list was read with `doc.get()`, which returns a YAML SEQ node —
254
+ * `Array.isArray` on that is `false`, so the panel saw an empty list. Turning
255
+ * an extension back ON then found its id "absent" and answered "nothing to
256
+ * do", leaving it disabled forever; turning one OFF overwrote every other
257
+ * disabled id. Both directions are pinned here.
258
+ */
259
+ test('disabling keeps the ids already in the list', async () => {
260
+ const agent = await freshAgentDir();
261
+ const configPath = join(agent, 'config.yml');
262
+ await Bun.write(configPath, 'disabledExtensions:\n - skill:a\n - skill:b\n');
263
+ expect(await setExtensionDisabled('extension-module:c', true)).toBe(true);
264
+ expect(Bun.YAML.parse(await fs.promises.readFile(configPath, 'utf8'))).toEqual({
265
+ disabledExtensions: ['skill:a', 'skill:b', 'extension-module:c'],
266
+ });
267
+ });
268
+
269
+ test('enabling removes only its own id and reports the change', async () => {
270
+ const agent = await freshAgentDir();
271
+ const configPath = join(agent, 'config.yml');
272
+ await Bun.write(configPath, 'disabledExtensions:\n - skill:a\n - skill:b\n');
273
+ expect(await setExtensionDisabled('skill:a', false)).toBe(true);
274
+ expect(Bun.YAML.parse(await fs.promises.readFile(configPath, 'utf8'))).toEqual({
275
+ disabledExtensions: ['skill:b'],
276
+ });
277
+ });
251
278
  });
252
279
 
253
280
  describe('behavior rules', () => {
@@ -30,6 +30,7 @@ import {
30
30
  GET_STATE_TIMEOUT_MS,
31
31
  IDLE_REAP_MS,
32
32
  IMAGE_BEARING_COMMANDS,
33
+ IMAGE_PROMPT_ACK_TIMEOUT_MS,
33
34
  MAX_AGGREGATE_IMAGE_BYTES,
34
35
  MAX_ATTACHED_IMAGE_BYTES,
35
36
  MAX_ATTACHED_IMAGES,
@@ -43,6 +44,7 @@ import {
43
44
  SESSION_BUSY_MESSAGE,
44
45
  SUBAGENT_STALE_MS,
45
46
  buildSessionSpawnArgs,
47
+ promptAckTimeoutMs,
46
48
  resolveSpawnCwd,
47
49
  toImageContents,
48
50
  validateAgentImages,
@@ -71,11 +73,20 @@ describe('timeout windows and messages', () => {
71
73
  expect(READY_TIMEOUT_MS).toBe(120_000);
72
74
  expect(GET_STATE_TIMEOUT_MS).toBe(5_000);
73
75
  expect(PROMPT_ACK_TIMEOUT_MS).toBe(30_000);
76
+ expect(IMAGE_PROMPT_ACK_TIMEOUT_MS).toBe(120_000);
74
77
  expect(RELOAD_PLUGINS_TIMEOUT_MS).toBe(10_000);
75
78
  expect(NON_TERMINAL_CONTINUATION_GRACE_MS).toBe(2_000);
76
79
  expect(AWAITING_AGENT_START_TIMEOUT_MS).toBe(10_000);
77
80
  });
78
81
 
82
+ test('an image prompt gets the longer ack budget; a text prompt keeps the short one', () => {
83
+ // omp describes the image before it acks, which measured 21-26 s — past the
84
+ // text budget, and overrunning it RESETS the child and loses the turn.
85
+ expect(promptAckTimeoutMs([{ type: 'image', data: 'AAAA', mimeType: 'image/png' }])).toBe(IMAGE_PROMPT_ACK_TIMEOUT_MS);
86
+ expect(promptAckTimeoutMs(undefined)).toBe(PROMPT_ACK_TIMEOUT_MS);
87
+ expect(promptAckTimeoutMs([])).toBe(PROMPT_ACK_TIMEOUT_MS);
88
+ });
89
+
79
90
  test('user-facing messages are verbatim', () => {
80
91
  expect(RESTARTING_MESSAGE).toBe('This session is restarting — retry in a moment.');
81
92
  expect(SESSION_BUSY_MESSAGE).toBe('The OMP session is busy with the running turn; retry once it settles.');
@@ -88,6 +88,14 @@ export const SUBAGENT_STALE_MS = 30 * 60 * 1000;
88
88
  export const READY_TIMEOUT_MS = 120_000;
89
89
  export const GET_STATE_TIMEOUT_MS = 5_000;
90
90
  export const PROMPT_ACK_TIMEOUT_MS = 30_000;
91
+ // An image-bearing prompt is NOT ack'd at dispatch time: omp stores the bytes,
92
+ // downscales them and asks the vision model for a description FIRST. Measured
93
+ // on 18.16.0: a plain prompt acks in ~0 ms, while a 1 MB PNG took 21 s and a
94
+ // 30 MB one 26 s — a size-independent cost dominated by that model call, which
95
+ // left 4 s of headroom under the text budget. Overrunning the ack cap does not
96
+ // merely report late: `settleCommandTimeout` RESETS the child, destroying the
97
+ // turn the operator just sent.
98
+ export const IMAGE_PROMPT_ACK_TIMEOUT_MS = 120_000;
91
99
  // A `/reload-plugins` re-read of the skill/command roots. omp answers it in
92
100
  // ~16-40 ms even mid-turn (measured on 18.4.3), so a short cap only bounds a
93
101
  // child that stopped answering at all — the caller's retry is the recovery.
@@ -253,6 +261,13 @@ export function toImageContents(value: unknown): Array<{ type: 'image'; data: st
253
261
  return images?.length ? images : undefined;
254
262
  }
255
263
 
264
+ /** How long a prompt dispatch may wait for its ack, given what it carries.
265
+ * One function because both dispatch paths (the session command router and the
266
+ * BTW side question) must give an image prompt the same window. */
267
+ export function promptAckTimeoutMs(images: unknown): number {
268
+ return toImageContents(images) ? IMAGE_PROMPT_ACK_TIMEOUT_MS : PROMPT_ACK_TIMEOUT_MS;
269
+ }
270
+
256
271
  /** Pick a spawn cwd that actually exists. A session records the directory it
257
272
  * was created in, but that directory may have been deleted since: spawn()
258
273
  * would fail with ENOENT and `omp --cwd <missing>` throws in setProjectDir. */