ceulen 0.5.1 → 0.8.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 (367) hide show
  1. package/CHANGELOG.md +365 -12
  2. package/README.md +87 -91
  3. package/extensions/lib/advisor-marker.ts +33 -0
  4. package/extensions/lib/panel.ts +25 -2
  5. package/extensions/lib/rate.ts +24 -0
  6. package/extensions/lib/registry.test.ts +67 -0
  7. package/extensions/lib/registry.ts +104 -8
  8. package/extensions/lib/tools.ts +47 -0
  9. package/extensions/lib/usage-store.ts +33 -0
  10. package/extensions/modules/advisor/commands/advisor.ts +244 -0
  11. package/extensions/modules/advisor/configPanel.ts +194 -0
  12. package/extensions/modules/advisor/index.ts +235 -0
  13. package/extensions/modules/advisor/lib/config.ts +248 -0
  14. package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
  15. package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
  16. package/extensions/modules/advisor/lib/model-picker.ts +47 -0
  17. package/extensions/modules/advisor/lib/watcher.ts +288 -0
  18. package/extensions/modules/advisor/test/compliance.test.ts +125 -0
  19. package/extensions/modules/advisor/test/config.test.ts +202 -0
  20. package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
  21. package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
  22. package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
  23. package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
  24. package/extensions/modules/advisor/test/module.test.ts +649 -0
  25. package/extensions/modules/advisor/test/watcher.test.ts +478 -0
  26. package/extensions/modules/classifier/configPanel.ts +104 -0
  27. package/extensions/modules/classifier/index.ts +297 -0
  28. package/extensions/modules/classifier/lib/settings.ts +95 -0
  29. package/extensions/modules/classifier/test/classifier.test.ts +475 -0
  30. package/extensions/modules/composer/index.ts +152 -3
  31. package/extensions/modules/composer/lib/footer.ts +119 -0
  32. package/extensions/modules/composer/lib/shapes.ts +265 -26
  33. package/extensions/modules/composer/test/editor.test.ts +1 -1
  34. package/extensions/modules/composer/test/footer.test.ts +96 -0
  35. package/extensions/modules/composer/test/module.test.ts +113 -11
  36. package/extensions/modules/composer/test/screen.test.ts +29 -1
  37. package/extensions/modules/composer/test/shapes.test.ts +224 -8
  38. package/extensions/modules/config/defaultTools.ts +96 -0
  39. package/extensions/modules/config/index.ts +147 -7
  40. package/extensions/modules/config/piSettings.ts +254 -69
  41. package/extensions/modules/config/test/defaultTools.test.ts +122 -0
  42. package/extensions/modules/config/test/menu.test.ts +64 -0
  43. package/extensions/modules/config/test/panel.test.ts +38 -23
  44. package/extensions/modules/config/test/piSettings.test.ts +130 -3
  45. package/extensions/modules/config/test/renderTools.test.ts +71 -0
  46. package/extensions/modules/config/test/tools.test.ts +146 -0
  47. package/extensions/modules/fff/index.ts +2094 -0
  48. package/extensions/modules/fff/lib/query.ts +129 -0
  49. package/extensions/modules/fff/test/index.test.ts +607 -0
  50. package/extensions/modules/fff/test/query.test.ts +71 -0
  51. package/extensions/modules/munin/configPanel.ts +108 -0
  52. package/extensions/modules/munin/index.ts +641 -0
  53. package/extensions/modules/munin/lib/helpers.ts +471 -0
  54. package/extensions/modules/munin/lib/retry.ts +20 -0
  55. package/extensions/modules/munin/lib/sdk.ts +218 -0
  56. package/extensions/modules/munin/test/config.test.ts +168 -0
  57. package/extensions/modules/munin/test/configPanel.test.ts +186 -0
  58. package/extensions/modules/munin/test/extension.test.ts +224 -0
  59. package/extensions/modules/munin/test/helpers.test.ts +523 -0
  60. package/extensions/modules/munin/test/retry.test.ts +145 -0
  61. package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
  62. package/extensions/modules/plan/configPanel.ts +152 -0
  63. package/extensions/modules/plan/index.ts +917 -0
  64. package/extensions/modules/plan/lib/plan-tools.ts +72 -0
  65. package/extensions/modules/plan/lib/prompt.ts +65 -0
  66. package/extensions/modules/plan/lib/settings.ts +166 -0
  67. package/extensions/modules/plan/lib/shell-gate.ts +200 -0
  68. package/extensions/modules/plan/test/configPanel.test.ts +96 -0
  69. package/extensions/modules/plan/test/harness.ts +133 -0
  70. package/extensions/modules/plan/test/module.test.ts +305 -0
  71. package/extensions/modules/plan/test/settings.test.ts +114 -0
  72. package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
  73. package/extensions/modules/ponytail/index.ts +23 -73
  74. package/extensions/modules/ponytail/lib/config.ts +1 -6
  75. package/extensions/modules/ponytail/test/extension.test.ts +1 -85
  76. package/extensions/modules/repair/configPanel.ts +96 -0
  77. package/extensions/modules/repair/index.ts +414 -0
  78. package/extensions/modules/repair/lib/auto-bg.ts +333 -0
  79. package/extensions/modules/repair/lib/edit-repair.ts +155 -0
  80. package/extensions/modules/repair/lib/editor.ts +251 -0
  81. package/extensions/modules/repair/lib/guards.ts +34 -0
  82. package/extensions/modules/repair/lib/input-repair.ts +324 -0
  83. package/extensions/modules/repair/lib/patch.ts +481 -0
  84. package/extensions/modules/repair/lib/settings.ts +114 -0
  85. package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
  86. package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
  87. package/extensions/modules/repair/test/editor.test.ts +141 -0
  88. package/extensions/modules/repair/test/guards.test.ts +64 -0
  89. package/extensions/modules/repair/test/input-repair.test.ts +231 -0
  90. package/extensions/modules/repair/test/patch.test.ts +563 -0
  91. package/extensions/modules/repair/test/settings.test.ts +167 -0
  92. package/extensions/modules/repair/test/wrapper.test.ts +210 -0
  93. package/extensions/modules/router/commands/commands.ts +4 -0
  94. package/extensions/modules/router/configPanel.ts +24 -10
  95. package/extensions/modules/router/lib/client.ts +63 -0
  96. package/extensions/modules/router/lib/provider.ts +34 -13
  97. package/extensions/modules/router/lib/systemone.ts +152 -0
  98. package/extensions/modules/router/test/unit.test.ts +260 -0
  99. package/extensions/modules/rtk/findFallback.js +68 -0
  100. package/extensions/modules/rtk/index.ts +248 -0
  101. package/extensions/modules/rtk/safe-rewrite.js +74 -0
  102. package/extensions/modules/rtk/test/findFallback.test.js +66 -0
  103. package/extensions/modules/rtk/test/index.test.js +131 -0
  104. package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
  105. package/extensions/modules/rtk/version-gate.js +34 -0
  106. package/extensions/modules/rules/index.ts +120 -0
  107. package/extensions/modules/rules/lib/rules.ts +348 -0
  108. package/extensions/modules/rules/test/lib.test.ts +263 -0
  109. package/extensions/modules/rules/test/module.test.ts +222 -0
  110. package/extensions/modules/serena/index.ts +629 -0
  111. package/extensions/modules/serena/lib/detect.ts +73 -0
  112. package/extensions/modules/serena/lib/env.ts +76 -0
  113. package/extensions/modules/serena/lib/guidance.ts +26 -0
  114. package/extensions/modules/serena/lib/normalize.ts +27 -0
  115. package/extensions/modules/serena/lib/symbol-key.ts +20 -0
  116. package/extensions/modules/serena/lib/truncate.ts +20 -0
  117. package/extensions/modules/serena/test/env.test.ts +122 -0
  118. package/extensions/modules/serena/test/index.test.ts +347 -0
  119. package/extensions/modules/serena/test/worker.test.ts +562 -0
  120. package/extensions/modules/serena/worker.ts +858 -0
  121. package/extensions/modules/steering/configPanel.ts +122 -0
  122. package/extensions/modules/steering/index.ts +616 -0
  123. package/extensions/modules/steering/lib/anchor.ts +175 -0
  124. package/extensions/modules/steering/lib/errors.ts +253 -0
  125. package/extensions/modules/steering/lib/family.ts +33 -0
  126. package/extensions/modules/steering/lib/guidance.ts +172 -0
  127. package/extensions/modules/steering/lib/history.ts +170 -0
  128. package/extensions/modules/steering/lib/settings.ts +127 -0
  129. package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
  130. package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
  131. package/extensions/modules/steering/test/anchor.test.ts +160 -0
  132. package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
  133. package/extensions/modules/steering/test/errors.test.ts +309 -0
  134. package/extensions/modules/steering/test/family.test.ts +43 -0
  135. package/extensions/modules/steering/test/guidance.test.ts +357 -0
  136. package/extensions/modules/steering/test/harness.ts +93 -0
  137. package/extensions/modules/steering/test/history.test.ts +118 -0
  138. package/extensions/modules/steering/test/settings.test.ts +182 -0
  139. package/extensions/modules/steering/test/status.test.ts +71 -0
  140. package/extensions/modules/steering/test/toolCall.test.ts +99 -0
  141. package/extensions/modules/subagent/agents/planner.md +14 -0
  142. package/extensions/modules/subagent/agents/reviewer.md +42 -0
  143. package/extensions/modules/subagent/agents/scout.md +47 -0
  144. package/extensions/modules/subagent/agents/tester.md +12 -0
  145. package/extensions/modules/subagent/agents/worker.md +18 -0
  146. package/extensions/modules/subagent/configPanel.ts +219 -0
  147. package/extensions/modules/subagent/index.ts +2464 -0
  148. package/extensions/modules/subagent/lib/agents.ts +408 -0
  149. package/extensions/modules/subagent/lib/background.ts +383 -0
  150. package/extensions/modules/subagent/lib/herdr.ts +1019 -0
  151. package/extensions/modules/subagent/lib/history.ts +126 -0
  152. package/extensions/modules/subagent/lib/model.ts +156 -0
  153. package/extensions/modules/subagent/lib/render.ts +335 -0
  154. package/extensions/modules/subagent/lib/result.ts +110 -0
  155. package/extensions/modules/subagent/lib/roles.ts +296 -0
  156. package/extensions/modules/subagent/lib/routing.ts +228 -0
  157. package/extensions/modules/subagent/lib/runner.ts +559 -0
  158. package/extensions/modules/subagent/lib/schema.ts +21 -0
  159. package/extensions/modules/subagent/lib/security.ts +763 -0
  160. package/extensions/modules/subagent/lib/settings.ts +159 -0
  161. package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
  162. package/extensions/modules/subagent/lib/threads.ts +135 -0
  163. package/extensions/modules/subagent/lib/types.ts +18 -0
  164. package/extensions/modules/subagent/lib/widget.ts +475 -0
  165. package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
  166. package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
  167. package/extensions/modules/subagent/test/routing.test.ts +524 -0
  168. package/extensions/modules/subagent/test/widget.test.ts +208 -0
  169. package/extensions/modules/todo/index.ts +478 -0
  170. package/extensions/modules/todo/test/todo.test.ts +252 -0
  171. package/extensions/modules/usage/index.ts +70 -16
  172. package/extensions/modules/usage/test/genrate.test.ts +70 -0
  173. package/extensions/modules/usage/test/parsers.test.ts +13 -0
  174. package/extensions/modules/usage/test/session-accumulators.test.ts +85 -0
  175. package/extensions/modules/ux/UPSTREAM +24 -0
  176. package/extensions/modules/ux/index.ts +393 -0
  177. package/extensions/modules/ux/lib/audit.ts +562 -0
  178. package/extensions/modules/ux/lib/config.ts +136 -0
  179. package/extensions/modules/ux/lib/instructions.ts +77 -0
  180. package/extensions/modules/ux/test/audit.test.ts +756 -0
  181. package/extensions/modules/ux/test/extension.test.ts +394 -0
  182. package/extensions/modules/ux/test/instructions.test.ts +19 -0
  183. package/extensions/modules/web/configPanel.ts +218 -0
  184. package/extensions/modules/web/index.ts +978 -0
  185. package/extensions/modules/web/lib/agy.ts +209 -0
  186. package/extensions/modules/web/lib/brave.ts +42 -0
  187. package/extensions/modules/web/lib/cdp.ts +686 -0
  188. package/extensions/modules/web/lib/chatapi.ts +101 -0
  189. package/extensions/modules/web/lib/chatgpt.ts +796 -0
  190. package/extensions/modules/web/lib/chrome.ts +328 -0
  191. package/extensions/modules/web/lib/config.ts +136 -0
  192. package/extensions/modules/web/lib/content.ts +99 -0
  193. package/extensions/modules/web/lib/crawl4ai.ts +172 -0
  194. package/extensions/modules/web/lib/extract.ts +235 -0
  195. package/extensions/modules/web/lib/firecrawl.ts +56 -0
  196. package/extensions/modules/web/lib/format.ts +197 -0
  197. package/extensions/modules/web/lib/gemini-auth.ts +286 -0
  198. package/extensions/modules/web/lib/gemini-dr.ts +338 -0
  199. package/extensions/modules/web/lib/gemini.ts +551 -0
  200. package/extensions/modules/web/lib/imageapi.ts +559 -0
  201. package/extensions/modules/web/lib/retry.ts +71 -0
  202. package/extensions/modules/web/lib/search.ts +237 -0
  203. package/extensions/modules/web/lib/searxng.ts +69 -0
  204. package/extensions/modules/web/lib/settings.ts +157 -0
  205. package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
  206. package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
  207. package/extensions/modules/web/test/agy.test.ts +383 -0
  208. package/extensions/modules/web/test/cdp.test.ts +717 -0
  209. package/extensions/modules/web/test/chat.test.ts +171 -0
  210. package/extensions/modules/web/test/chatgpt.test.ts +633 -0
  211. package/extensions/modules/web/test/chrome.test.ts +282 -0
  212. package/extensions/modules/web/test/config.test.ts +218 -0
  213. package/extensions/modules/web/test/configPanel.test.ts +198 -0
  214. package/extensions/modules/web/test/crawl.test.ts +134 -0
  215. package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
  216. package/extensions/modules/web/test/extension.test.ts +118 -0
  217. package/extensions/modules/web/test/extract.test.ts +436 -0
  218. package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
  219. package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
  220. package/extensions/modules/web/test/fixtures/interaction.html +31 -0
  221. package/extensions/modules/web/test/format.test.ts +230 -0
  222. package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
  223. package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
  224. package/extensions/modules/web/test/gemini.test.ts +472 -0
  225. package/extensions/modules/web/test/hook.test.ts +101 -0
  226. package/extensions/modules/web/test/image.test.ts +1089 -0
  227. package/extensions/modules/web/test/retry.test.ts +119 -0
  228. package/extensions/modules/web/test/screenshot.test.ts +109 -0
  229. package/extensions/modules/web/test/search.test.ts +210 -0
  230. package/extensions/modules/web/test/settings.test.ts +165 -0
  231. package/extensions/modules/web/test/skill.test.ts +72 -0
  232. package/extensions/modules/web/types.d.ts +3 -0
  233. package/extensions/modules/web/vendor/package.json +1 -0
  234. package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
  235. package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
  236. package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
  237. package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
  238. package/extensions/modules/web/vendor/readability/index.js +9 -0
  239. package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
  240. package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
  241. package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
  242. package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
  243. package/extensions/modules/zai/configPanel.ts +154 -0
  244. package/extensions/modules/zai/index.ts +186 -0
  245. package/extensions/modules/zai/lib/anthropic.ts +159 -0
  246. package/extensions/modules/zai/lib/settings.ts +198 -0
  247. package/extensions/modules/zai/lib/signing.ts +721 -0
  248. package/extensions/modules/zai/lib/throttle.ts +198 -0
  249. package/extensions/modules/zai/test/anthropic.test.ts +132 -0
  250. package/extensions/modules/zai/test/configPanel.test.ts +230 -0
  251. package/extensions/modules/zai/test/extension.test.ts +249 -0
  252. package/extensions/modules/zai/test/settings.test.ts +183 -0
  253. package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
  254. package/extensions/modules/zai/test/signing.test.ts +364 -0
  255. package/extensions/modules/zai/test/throttle.test.ts +329 -0
  256. package/package.json +19 -4
  257. package/scripts/validate-themes.mjs +75 -0
  258. package/skills/munin/SKILL.md +117 -0
  259. package/skills/ux-capture/SKILL.md +202 -0
  260. package/skills/ux-design/SKILL.md +279 -0
  261. package/skills/ux-presets/SKILL.md +484 -0
  262. package/skills/ux-routing/SKILL.md +46 -0
  263. package/skills/web/SKILL.md +153 -0
  264. package/themes/alabaster.json +93 -0
  265. package/themes/amethyst.json +96 -0
  266. package/themes/anthracite.json +93 -0
  267. package/themes/basalt.json +91 -0
  268. package/themes/birch.json +95 -0
  269. package/themes/catppuccin-mocha.json +91 -0
  270. package/themes/dark-abyss.json +91 -0
  271. package/themes/dark-arctic.json +104 -0
  272. package/themes/dark-aurora.json +95 -0
  273. package/themes/dark-catppuccin.json +107 -0
  274. package/themes/dark-cavern.json +91 -0
  275. package/themes/dark-celestial.json +106 -0
  276. package/themes/dark-copper.json +95 -0
  277. package/themes/dark-cosmos.json +90 -0
  278. package/themes/dark-cyberpunk.json +102 -0
  279. package/themes/dark-dracula.json +98 -0
  280. package/themes/dark-eclipse.json +91 -0
  281. package/themes/dark-ember.json +95 -0
  282. package/themes/dark-equinox.json +90 -0
  283. package/themes/dark-forest.json +96 -0
  284. package/themes/dark-github.json +105 -0
  285. package/themes/dark-gruvbox.json +112 -0
  286. package/themes/dark-lavender.json +95 -0
  287. package/themes/dark-lunar.json +89 -0
  288. package/themes/dark-midnight.json +95 -0
  289. package/themes/dark-monochrome.json +94 -0
  290. package/themes/dark-monokai.json +98 -0
  291. package/themes/dark-nebula.json +90 -0
  292. package/themes/dark-neon-noir.json +100 -0
  293. package/themes/dark-nord.json +98 -0
  294. package/themes/dark-ocean.json +101 -0
  295. package/themes/dark-one.json +100 -0
  296. package/themes/dark-poimandres.json +115 -0
  297. package/themes/dark-rainforest.json +91 -0
  298. package/themes/dark-reef.json +91 -0
  299. package/themes/dark-retro.json +92 -0
  300. package/themes/dark-rose-pine.json +96 -0
  301. package/themes/dark-sakura.json +95 -0
  302. package/themes/dark-slate.json +95 -0
  303. package/themes/dark-solarized.json +97 -0
  304. package/themes/dark-solstice.json +90 -0
  305. package/themes/dark-starfall.json +91 -0
  306. package/themes/dark-sunset.json +99 -0
  307. package/themes/dark-swamp.json +90 -0
  308. package/themes/dark-synthwave.json +103 -0
  309. package/themes/dark-taiga.json +91 -0
  310. package/themes/dark-terminal.json +95 -0
  311. package/themes/dark-tokyo-night.json +101 -0
  312. package/themes/dark-tundra.json +91 -0
  313. package/themes/dark-twilight.json +91 -0
  314. package/themes/dark-volcanic.json +91 -0
  315. package/themes/dark.json +80 -0
  316. package/themes/graphite.json +92 -0
  317. package/themes/light-arctic.json +107 -0
  318. package/themes/light-aurora-day.json +91 -0
  319. package/themes/light-canyon.json +91 -0
  320. package/themes/light-catppuccin.json +106 -0
  321. package/themes/light-cirrus.json +90 -0
  322. package/themes/light-coral.json +95 -0
  323. package/themes/light-cyberpunk.json +96 -0
  324. package/themes/light-dawn.json +90 -0
  325. package/themes/light-dunes.json +91 -0
  326. package/themes/light-eucalyptus.json +95 -0
  327. package/themes/light-forest.json +100 -0
  328. package/themes/light-frost.json +95 -0
  329. package/themes/light-github.json +115 -0
  330. package/themes/light-glacier.json +91 -0
  331. package/themes/light-gruvbox.json +108 -0
  332. package/themes/light-haze.json +90 -0
  333. package/themes/light-honeycomb.json +95 -0
  334. package/themes/light-lagoon.json +91 -0
  335. package/themes/light-lavender.json +95 -0
  336. package/themes/light-meadow.json +91 -0
  337. package/themes/light-mint.json +95 -0
  338. package/themes/light-monochrome.json +101 -0
  339. package/themes/light-ocean.json +99 -0
  340. package/themes/light-one.json +99 -0
  341. package/themes/light-opal.json +91 -0
  342. package/themes/light-orchard.json +91 -0
  343. package/themes/light-paper.json +95 -0
  344. package/themes/light-poimandres.json +115 -0
  345. package/themes/light-prism.json +90 -0
  346. package/themes/light-retro.json +98 -0
  347. package/themes/light-sand.json +95 -0
  348. package/themes/light-savanna.json +91 -0
  349. package/themes/light-solarized.json +102 -0
  350. package/themes/light-soleil.json +90 -0
  351. package/themes/light-sunset.json +99 -0
  352. package/themes/light-synthwave.json +98 -0
  353. package/themes/light-tokyo-night.json +111 -0
  354. package/themes/light-wetland.json +91 -0
  355. package/themes/light-zenith.json +89 -0
  356. package/themes/light.json +80 -0
  357. package/themes/limestone.json +94 -0
  358. package/themes/mahogany.json +97 -0
  359. package/themes/marble.json +93 -0
  360. package/themes/mirage.json +79 -0
  361. package/themes/obsidian.json +91 -0
  362. package/themes/onyx.json +91 -0
  363. package/themes/pearl.json +93 -0
  364. package/themes/porcelain.json +91 -0
  365. package/themes/quartz.json +96 -0
  366. package/themes/sandstone.json +95 -0
  367. package/themes/titanium.json +90 -0
@@ -0,0 +1,394 @@
1
+ import assert from "node:assert/strict";
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+
7
+ import uxExtension, {
8
+ buildUxGroups,
9
+ parseUxCommand,
10
+ resolveSessionMode,
11
+ readDefaultMode,
12
+ readQuietStartup,
13
+ uxConfig,
14
+ writeDefaultMode,
15
+ } from "../index.ts";
16
+
17
+ /* Untyped harness stub: only the API surface the module actually touches.
18
+ * (Kept loose on purpose — pi's SDK types require a full context object.) */
19
+ function createPiHarness() {
20
+ const events = new Map();
21
+ const commands = new Map();
22
+ const tools = new Map();
23
+ const appendedEntries = [];
24
+ const discoverResults = [];
25
+
26
+ const pi = {
27
+ on(eventName, handler) {
28
+ if (eventName === "resources_discover") discoverResults.push(handler);
29
+ events.set(eventName, handler);
30
+ },
31
+ registerCommand(name, options) {
32
+ commands.set(name, options);
33
+ },
34
+ registerTool(definition) {
35
+ tools.set(definition.name, definition);
36
+ },
37
+ appendEntry(customType, data) {
38
+ appendedEntries.push({ customType, data });
39
+ },
40
+ sendUserMessage() {},
41
+ };
42
+
43
+ uxExtension(pi);
44
+ return { events, commands, tools, appendedEntries, discoverResults };
45
+ }
46
+
47
+ function createCommandContext(overrides = {}) {
48
+ return {
49
+ isIdle: () => true,
50
+ sessionManager: { getEntries: () => [] },
51
+ ui: { notify() {} },
52
+ ...overrides,
53
+ };
54
+ }
55
+
56
+ function withTempConfig(fn) {
57
+ const tempConfigHome = mkdtempSync(join(tmpdir(), "ux-test-"));
58
+ const previousXdg = process.env.XDG_CONFIG_HOME;
59
+ const previousDefault = process.env.PI_UX_DEFAULT_MODE;
60
+ const previousQuiet = process.env.PI_UX_QUIET_STARTUP;
61
+ process.env.XDG_CONFIG_HOME = tempConfigHome;
62
+ delete process.env.PI_UX_DEFAULT_MODE;
63
+ delete process.env.PI_UX_QUIET_STARTUP;
64
+
65
+ return Promise.resolve()
66
+ .then(fn)
67
+ .finally(() => {
68
+ if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
69
+ else process.env.XDG_CONFIG_HOME = previousXdg;
70
+ if (previousDefault === undefined) delete process.env.PI_UX_DEFAULT_MODE;
71
+ else process.env.PI_UX_DEFAULT_MODE = previousDefault;
72
+ if (previousQuiet === undefined) delete process.env.PI_UX_QUIET_STARTUP;
73
+ else process.env.PI_UX_QUIET_STARTUP = previousQuiet;
74
+ rmSync(tempConfigHome, { recursive: true, force: true });
75
+ });
76
+ }
77
+
78
+ test("extension registers the /ux command and ux_audit tool, and NO status bar", () => {
79
+ const { commands, tools, events } = createPiHarness();
80
+ assert.deepEqual([...commands.keys()], ["ux"]);
81
+ assert.deepEqual([...tools.keys()], ["ux_audit"]);
82
+ // No status bar: no agent_start/agent_end sync handlers exist to draw one.
83
+ assert.equal(events.has("agent_start"), false, "no agent_start handler (status-bar only)");
84
+ assert.equal(events.has("agent_end"), false, "no agent_end handler (status-bar only)");
85
+ });
86
+
87
+ test("ux_audit is registered default-active unless ceulen.disabledTools lists it", () => {
88
+ const active = createPiHarness();
89
+ assert.equal(active.tools.get("ux_audit").defaultActive, true);
90
+ });
91
+
92
+ test("ux_audit parameter schema has the expected shape", () => {
93
+ const { tools } = createPiHarness();
94
+ const params = tools.get("ux_audit").parameters;
95
+ assert.equal(params.type, "object");
96
+ assert.ok(params.properties.css, "missing css property");
97
+ assert.equal(params.properties.css.type, "string");
98
+ assert.ok(params.properties.pairs, "missing pairs property");
99
+ assert.equal(params.properties.pairs.type, "array");
100
+ assert.ok(params.properties.pairs.items?.properties?.fg, "missing pairs.items.properties.fg");
101
+ assert.ok(params.properties.pairs.items?.properties?.bg, "missing pairs.items.properties.bg");
102
+ });
103
+
104
+ test("ux_audit tool reports a clean pass on token-compliant CSS", async () => withTempConfig(async () => {
105
+ const { tools } = createPiHarness();
106
+ const css = `
107
+ :root { --accent: #0066ff; --text: #111; --bg: #fff; --elev: 0 2px 8px rgba(0,0,0,0.08); }
108
+ .card { color: var(--text); background: var(--bg); box-shadow: var(--elev); padding: 8px; }
109
+ button { color: var(--accent); }
110
+ button:focus-visible { outline: 2px solid var(--accent); }
111
+ button:disabled { opacity: 0.5; }
112
+ `;
113
+ const out = await tools.get("ux_audit").execute(
114
+ "id",
115
+ { css, pairs: [{ fg: "#111", bg: "#fff", label: "body", min: 4.5 }] },
116
+ undefined, undefined, { cwd: "." },
117
+ );
118
+ assert.match(out.content[0].text, /UX AUDIT PASSED/);
119
+ assert.equal(out.details.pass, true);
120
+ }));
121
+
122
+ test("ux_audit tool reports a fail on hardcoded hex + missing states", async () => withTempConfig(async () => {
123
+ const { tools } = createPiHarness();
124
+ const css = `:root { --accent: #0066ff; } .card { color: #ff0000; } button { font-weight: bold; }`;
125
+ const out = await tools.get("ux_audit").execute("id", { css, pairs: [] }, undefined, undefined, { cwd: "." });
126
+ assert.match(out.content[0].text, /UX AUDIT FAILED/);
127
+ assert.equal(out.details.pass, false);
128
+ assert.match(out.content[0].text, /hardcoded hex/);
129
+ assert.match(out.content[0].text, /focus-visible/i);
130
+ }));
131
+
132
+ test("ux_audit tool renders 'n/a' for an invalid colour pair", async () => withTempConfig(async () => {
133
+ const { tools } = createPiHarness();
134
+ const out = await tools.get("ux_audit").execute(
135
+ "id",
136
+ { css: "/* pair gate only */ .x { color: #111; }", pairs: [{ fg: "not-a-color", bg: "#fff", label: "bad", min: 4.5 }] },
137
+ undefined, undefined, { cwd: "." },
138
+ );
139
+ assert.match(out.content[0].text, /UX AUDIT FAILED/);
140
+ assert.match(out.content[0].text, /bad: n\/a/);
141
+ }));
142
+
143
+ test("ux_audit tool returns a formatted error for an unreadable path instead of throwing", async () => withTempConfig(async () => {
144
+ const { tools } = createPiHarness();
145
+ const out = await tools.get("ux_audit").execute(
146
+ "id",
147
+ { path: "/nonexistent/definitely-missing.css", pairs: [] },
148
+ undefined, undefined, { cwd: "." },
149
+ );
150
+ assert.equal(out.isError, true);
151
+ assert.match(out.content[0].text, /UX AUDIT ERROR/);
152
+ assert.match(out.content[0].text, /ENOENT/);
153
+ }));
154
+
155
+ test("/ux updates session mode and injects instructions", async () => withTempConfig(async () => {
156
+ const { commands, events, appendedEntries } = createPiHarness();
157
+ const ctx = createCommandContext();
158
+
159
+ await events.get("session_start")({ reason: "startup" }, ctx);
160
+ await commands.get("ux").handler("lite", ctx);
161
+
162
+ assert.deepEqual(appendedEntries.at(-1), {
163
+ customType: "ux-mode",
164
+ data: { mode: "lite" },
165
+ });
166
+
167
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
168
+ assert.ok(result.systemPrompt.includes("UX DISCIPLINE ACTIVE"));
169
+ assert.ok(result.systemPrompt.includes("lite"));
170
+ }));
171
+
172
+ test("before_agent_start guards missing event and missing systemPrompt", async () => withTempConfig(async () => {
173
+ const { events } = createPiHarness();
174
+ const ctx = createCommandContext();
175
+
176
+ await events.get("session_start")({ reason: "startup" }, ctx);
177
+
178
+ for (const bad of [undefined, null]) {
179
+ const r = await events.get("before_agent_start")(bad, ctx);
180
+ assert.ok(r.systemPrompt.includes("UX DISCIPLINE ACTIVE"));
181
+ assert.ok(!r.systemPrompt.includes("undefined"), "must not contain the literal 'undefined'");
182
+ }
183
+
184
+ const empty = await events.get("before_agent_start")({}, ctx);
185
+ assert.ok(empty.systemPrompt.includes("UX DISCIPLINE ACTIVE"));
186
+ assert.ok(!empty.systemPrompt.startsWith("undefined"), "must not start with 'undefined'");
187
+
188
+ const withBase = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
189
+ assert.ok(withBase.systemPrompt.startsWith("BASE\n\n"));
190
+ assert.ok(withBase.systemPrompt.includes("UX DISCIPLINE ACTIVE"));
191
+ }));
192
+
193
+ test("strict banner enforces the audit gate; lite banner recommends it", async () => withTempConfig(async () => {
194
+ const { commands, events } = createPiHarness();
195
+ const ctx = createCommandContext();
196
+
197
+ await events.get("session_start")({ reason: "startup" }, ctx);
198
+
199
+ await commands.get("ux").handler("strict", ctx);
200
+ const strict = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
201
+ assert.match(strict.systemPrompt, /level: strict/);
202
+ assert.match(strict.systemPrompt, /block handoff on fail/i);
203
+
204
+ await commands.get("ux").handler("lite", ctx);
205
+ const lite = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
206
+ assert.match(lite.systemPrompt, /level: lite/);
207
+ assert.match(lite.systemPrompt, /recommended but not blocking/i);
208
+ }));
209
+
210
+ test("session_start restores latest persisted mode", async () => withTempConfig(async () => {
211
+ const { events } = createPiHarness();
212
+ const ctx = createCommandContext({
213
+ sessionManager: {
214
+ getEntries: () => [
215
+ { type: "custom", customType: "ux-mode", data: { mode: "lite" } },
216
+ ],
217
+ },
218
+ });
219
+
220
+ await events.get("session_start")({ reason: "resume" }, ctx);
221
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
222
+ assert.ok(result.systemPrompt.includes("lite"));
223
+ }));
224
+
225
+ test("off mode injects nothing", async () => withTempConfig(async () => {
226
+ const { commands, events } = createPiHarness();
227
+ const ctx = createCommandContext();
228
+
229
+ await events.get("session_start")({ reason: "startup" }, ctx);
230
+ await commands.get("ux").handler("off", ctx);
231
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
232
+ assert.equal(result, undefined);
233
+ }));
234
+
235
+ test("normal mode disables persistent instructions", async () => withTempConfig(async () => {
236
+ const { commands, events } = createPiHarness();
237
+ const ctx = createCommandContext();
238
+
239
+ await events.get("session_start")({ reason: "startup" }, ctx);
240
+ await commands.get("ux").handler("strict", ctx);
241
+ await events.get("input")({ text: "normal mode", source: "interactive" }, ctx);
242
+
243
+ const disabled = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
244
+ assert.equal(disabled, undefined);
245
+ }));
246
+
247
+ test("a request mentioning normal mode stays active", async () => withTempConfig(async () => {
248
+ const { commands, events } = createPiHarness();
249
+ const ctx = createCommandContext();
250
+
251
+ await events.get("session_start")({ reason: "startup" }, ctx);
252
+ await commands.get("ux").handler("strict", ctx);
253
+ await events.get("input")({ text: "add a normal mode toggle next to dark mode", source: "interactive" }, ctx);
254
+
255
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
256
+ assert.match(result.systemPrompt, /UX DISCIPLINE ACTIVE/);
257
+ }));
258
+
259
+ test("resources_discover contributes ONLY the 4 ux skill dirs", () => {
260
+ const { discoverResults } = createPiHarness();
261
+ assert.equal(discoverResults.length, 1);
262
+ const result = discoverResults[0]();
263
+ const names = result.skillPaths.map((p) => p.split("/").filter(Boolean).pop());
264
+ assert.deepEqual(names.sort(), ["ux-capture", "ux-design", "ux-presets", "ux-routing"]);
265
+ for (const p of result.skillPaths) {
266
+ assert.ok(p.includes("/skills/ux-"), "each path is its own skill dir under skills/");
267
+ assert.ok(!p.endsWith("/skills/"), "must not contribute the shared skills/ root");
268
+ assert.ok(existsSync(p), `skill dir exists: ${p}`);
269
+ }
270
+ });
271
+
272
+ // --- /config contribution ---
273
+
274
+ test("config groups carry the ux.* rows over the Appearance tab", () => {
275
+ const groups = buildUxGroups({ defaultMode: "lite", quietStartup: true });
276
+ assert.equal(groups.length, 1);
277
+ assert.equal(groups[0].tab, "Appearance");
278
+ assert.equal(groups[0].label, "UX discipline");
279
+ const keys = groups[0].rows.map((r) => r.key);
280
+ assert.deepEqual(keys, ["ux.defaultMode", "ux.quietStartup"]);
281
+ const mode = groups[0].rows[0];
282
+ assert.deepEqual(mode.values, ["off", "lite", "strict"]);
283
+ assert.equal(mode.defaultValue, "strict");
284
+ const quiet = groups[0].rows[1];
285
+ assert.equal(quiet.defaultValue, false);
286
+ });
287
+
288
+ test("uxConfig save persists defaultMode + quietStartup to the pi-ux config file", async () => withTempConfig(async () => {
289
+ const { ui } = createCommandContext();
290
+ let notified = "";
291
+ const contrib = uxConfig();
292
+ const groups = contrib.groups();
293
+ // Simulate the panel: mutate via the row setters, then save with owned keys.
294
+ groups[0].rows[0].set("off");
295
+ groups[0].rows[1].set(true);
296
+ await contrib.save(new Set(["ux.defaultMode", "ux.quietStartup"]), { ui: { notify: (m) => (notified = m) } });
297
+
298
+ const configPath = join(process.env.XDG_CONFIG_HOME, "pi-ux", "config.json");
299
+ assert.ok(existsSync(configPath));
300
+ assert.deepEqual(JSON.parse(readFileSync(configPath, "utf8")), { defaultMode: "off", quietStartup: true });
301
+ assert.match(notified, /UX config saved/);
302
+ }));
303
+
304
+ test("uxConfig save no-ops without an owned key", async () => withTempConfig(async () => {
305
+ const contrib = uxConfig();
306
+ const configPath = join(process.env.XDG_CONFIG_HOME, "pi-ux", "config.json");
307
+ await contrib.save(new Set(["router.baseUrl"]), { ui: { notify() {} } });
308
+ assert.equal(existsSync(configPath), false, "no config file written");
309
+ }));
310
+
311
+ test("uxConfig save reports an env-shadowed default", async () => withTempConfig(async () => {
312
+ process.env.PI_UX_DEFAULT_MODE = "lite";
313
+ let notified = "";
314
+ const contrib = uxConfig();
315
+ contrib.groups()[0].rows[0].set("strict");
316
+ await contrib.save(new Set(["ux.defaultMode"]), { ui: { notify: (m) => (notified = m) } });
317
+ assert.match(notified, /PI_UX_DEFAULT_MODE env keeps the default at lite/);
318
+ }));
319
+
320
+ // --- helpers ---
321
+
322
+ test("parseUxCommand bare reports status (ponytail #99 precedent, not upstream's reset)", () => {
323
+ assert.deepEqual(parseUxCommand(""), { type: "status" });
324
+ assert.deepEqual(parseUxCommand(" "), { type: "status" });
325
+ });
326
+
327
+ test("parseUxCommand parses modes and status (no default subcommand — /config owns it)", () => {
328
+ assert.deepEqual(parseUxCommand("lite"), { type: "set-mode", mode: "lite" });
329
+ assert.deepEqual(parseUxCommand("STRICT"), { type: "set-mode", mode: "strict" });
330
+ assert.deepEqual(parseUxCommand("status"), { type: "status" });
331
+ assert.deepEqual(parseUxCommand("default lite"), { type: "invalid", reason: "invalid-mode", mode: "default" });
332
+ assert.deepEqual(parseUxCommand("banana"), { type: "invalid", reason: "invalid-mode", mode: "banana" });
333
+ });
334
+
335
+ test("resolveSessionMode prefers latest persisted session mode", () => {
336
+ const entries = [
337
+ { type: "custom", customType: "ux-mode", data: { mode: "lite" } },
338
+ { type: "custom", customType: "ux-mode", data: { mode: "strict" } },
339
+ ];
340
+ assert.equal(resolveSessionMode(entries, "strict"), "strict");
341
+ });
342
+
343
+ test("resolveSessionMode returns fallback when entries is not an array", () => {
344
+ assert.equal(resolveSessionMode(null, "strict"), "strict");
345
+ assert.equal(resolveSessionMode("not an array"), "strict"); // DEFAULT_MODE fallback
346
+ });
347
+
348
+ test("readDefaultMode and writeDefaultMode use XDG config path", () => {
349
+ const tempDir = mkdtempSync(join(tmpdir(), "ux-config-"));
350
+ const previousXdg = process.env.XDG_CONFIG_HOME;
351
+ const previousDefault = process.env.PI_UX_DEFAULT_MODE;
352
+ const configPath = join(tempDir, "pi-ux", "config.json");
353
+ process.env.XDG_CONFIG_HOME = tempDir;
354
+ delete process.env.PI_UX_DEFAULT_MODE;
355
+
356
+ try {
357
+ assert.equal(readDefaultMode(), "strict");
358
+ assert.equal(writeDefaultMode("lite"), "lite");
359
+ assert.equal(readDefaultMode(), "lite");
360
+ assert.ok(existsSync(configPath));
361
+ assert.deepEqual(JSON.parse(readFileSync(configPath, "utf8")), { defaultMode: "lite" });
362
+ } finally {
363
+ if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
364
+ else process.env.XDG_CONFIG_HOME = previousXdg;
365
+ if (previousDefault === undefined) delete process.env.PI_UX_DEFAULT_MODE;
366
+ else process.env.PI_UX_DEFAULT_MODE = previousDefault;
367
+ rmSync(tempDir, { recursive: true, force: true });
368
+ }
369
+ });
370
+
371
+ test("readQuietStartup resolves env var, config file, and default in that order", () => {
372
+ const tempDir = mkdtempSync(join(tmpdir(), "ux-quiet-"));
373
+ const previousXdg = process.env.XDG_CONFIG_HOME;
374
+ const previousEnv = process.env.PI_UX_QUIET_STARTUP;
375
+ const configDir = join(tempDir, "pi-ux");
376
+ const configPath = join(configDir, "config.json");
377
+ process.env.XDG_CONFIG_HOME = tempDir;
378
+ delete process.env.PI_UX_QUIET_STARTUP;
379
+
380
+ try {
381
+ assert.equal(readQuietStartup(), false);
382
+ mkdirSync(configDir, { recursive: true });
383
+ writeFileSync(configPath, JSON.stringify({ quietStartup: true }), "utf8");
384
+ assert.equal(readQuietStartup(), true);
385
+ process.env.PI_UX_QUIET_STARTUP = "0";
386
+ assert.equal(readQuietStartup(), false);
387
+ } finally {
388
+ if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
389
+ else process.env.XDG_CONFIG_HOME = previousXdg;
390
+ if (previousEnv === undefined) delete process.env.PI_UX_QUIET_STARTUP;
391
+ else process.env.PI_UX_QUIET_STARTUP = previousEnv;
392
+ rmSync(tempDir, { recursive: true, force: true });
393
+ }
394
+ });
@@ -0,0 +1,19 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import { getUxInstructions } from "../lib/instructions.js";
5
+
6
+ test("getUxInstructions returns banner + SKILL.md body with frontmatter stripped", () => {
7
+ const out = getUxInstructions("strict");
8
+ assert.ok(out.startsWith("UX DISCIPLINE ACTIVE — level: strict."));
9
+ assert.ok(out.includes("DESIGN.md")); // body content present, not the fallback
10
+ // Frontmatter delimiters are gone (first line is the banner).
11
+ assert.ok(!out.slice(0, out.indexOf("\n", out.indexOf("\n") + 1)).includes("---"));
12
+ });
13
+
14
+ test("getUxInstructions lite banner + stable output across calls (memoized read)", () => {
15
+ const a = getUxInstructions("lite");
16
+ const b = getUxInstructions("lite");
17
+ assert.ok(a.startsWith("UX DISCIPLINE ACTIVE — level: lite."));
18
+ assert.equal(a, b); // unchanged file ⇒ cached body, identical output
19
+ });
@@ -0,0 +1,218 @@
1
+ // web's /config contribution — Tools tab, Web section (icon 🌍).
2
+ //
3
+ // The 16 provider rows over the `web` settings section (global agent-dir
4
+ // settings.json; a trusted project `.pi/settings.json` `web` section shadows
5
+ // per field; env vars win over both — see lib/settings.ts lookupVar). The
6
+ // Enable row + 11 tool toggle rows are prepended/appended by the config
7
+ // module automatically (withEnableRow/withToolRows over the registry entry).
8
+ // Config is read PER TOOL CALL, so a save applies to the live session with
9
+ // no /reload.
10
+
11
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
12
+ import { row, type PanelGroup } from "../../lib/panel.js";
13
+ import type { ModuleConfig } from "../../lib/registry.js";
14
+ import { agentDirs } from "../../lib/registry.js";
15
+ import { findEnvValue } from "./lib/config.js";
16
+ import {
17
+ DEFAULT_SEARXNG_BASE_URL,
18
+ DEFAULT_CRAWL4AI_API_URL,
19
+ HOSTED_FIRECRAWL_BASE_URL,
20
+ } from "./lib/config.js";
21
+ import {
22
+ ENV_TO_SETTINGS_KEY,
23
+ readProjectWebSection,
24
+ sectionValue,
25
+ writeWebSection,
26
+ } from "./lib/settings.js";
27
+
28
+ /** One row's definition: settings key, label, effective value, default. */
29
+ interface WebRowSpec {
30
+ key: string; // after "web."
31
+ label: string;
32
+ envVar: string;
33
+ kind: "string" | "number";
34
+ mask?: boolean;
35
+ defaultValue?: string;
36
+ description: string;
37
+ secret?: boolean;
38
+ /** Closed set (Enter opens the submenu) — used for timeouts so an invalid
39
+ * value can't brick a tool (pi-web's loaders require an integer >= 1000). */
40
+ allow?: readonly string[];
41
+ }
42
+
43
+ // OMP-parity labelled timeout options (providers.webSearchTimeoutSeconds).
44
+ const TIMEOUT_VALUES = ["15000", "30000", "60000", "120000", "300000"] as const;
45
+ const TIMEOUT_DESCRIPTIONS: Record<string, string> = {
46
+ "15000": "15 seconds — snappy, fails fast on slow backends",
47
+ "30000": "30 seconds",
48
+ "60000": "1 minute (default)",
49
+ "120000": "2 minutes",
50
+ "300000": "5 minutes — slow/self-hosted backends",
51
+ };
52
+
53
+ // Lazy: reading lib/config constants at module top level would TDZ on the
54
+ // registry → configPanel → lib/config → settings → registry cycle.
55
+ function webRowSpecs(): WebRowSpec[] {
56
+ return [
57
+ // ── Search ──────────────────────────────────────────────────────────
58
+ { key: "searxng.baseUrl", label: "SearXNG base URL", envVar: "SEARXNG_BASE_URL", kind: "string", defaultValue: DEFAULT_SEARXNG_BASE_URL,
59
+ description: "Self-hosted SearXNG instance for web_search (broad discovery backend). SEARXNG_BASE_URL env overrides." },
60
+ { key: "brave.apiKey", label: "Brave API key", envVar: "BRAVE_API_KEY", kind: "string", mask: true, secret: true,
61
+ description: "Brave Search API key — the precision backend (site:/quotes/docs). BRAVE_API_KEY env overrides." },
62
+ // ── Firecrawl ───────────────────────────────────────────────────────
63
+ { key: "firecrawl.baseUrl", label: "Firecrawl URL", envVar: "FIRECRAWL_API_URL", kind: "string", defaultValue: HOSTED_FIRECRAWL_BASE_URL,
64
+ description: "Self-hosted or hosted Firecrawl API (search/scrape/crawl/map). FIRECRAWL_API_URL env overrides." },
65
+ { key: "firecrawl.apiKey", label: "Firecrawl API key", envVar: "FIRECRAWL_API_KEY", kind: "string", mask: true, secret: true,
66
+ description: "Required for hosted Firecrawl; optional for self-hosted. FIRECRAWL_API_KEY env overrides." },
67
+ { key: "firecrawl.timeoutMs", label: "Firecrawl timeout", envVar: "FIRECRAWL_TIMEOUT_MS", kind: "number", defaultValue: "60000", allow: TIMEOUT_VALUES,
68
+ description: "Firecrawl request timeout (integer ms >= 1000). FIRECRAWL_TIMEOUT_MS env overrides." },
69
+ // ── Crawl4AI ────────────────────────────────────────────────────────
70
+ { key: "crawl4ai.baseUrl", label: "Crawl4AI URL", envVar: "CRAWL4AI_API_URL", kind: "string", defaultValue: DEFAULT_CRAWL4AI_API_URL,
71
+ description: "Crawl4AI Docker API for full extraction, crawl, screenshot, PDF. CRAWL4AI_API_URL env overrides." },
72
+ { key: "crawl4ai.apiToken", label: "Crawl4AI token", envVar: "CRAWL4AI_API_TOKEN", kind: "string", mask: true, secret: true,
73
+ description: "Required if Crawl4AI auth is enabled (v0.9+ default config). CRAWL4AI_API_TOKEN env overrides." },
74
+ { key: "crawl4ai.timeoutMs", label: "Crawl4AI timeout", envVar: "CRAWL4AI_API_TIMEOUT_MS", kind: "number", defaultValue: "60000", allow: TIMEOUT_VALUES,
75
+ description: "Crawl4AI request timeout (integer ms >= 1000). CRAWL4AI_API_TIMEOUT_MS env overrides." },
76
+ // ── Gemini web ──────────────────────────────────────────────────────
77
+ { key: "gemini.cookie", label: "Gemini web cookie", envVar: "GEMINI_WEB_SECURE_1PSID", kind: "string", mask: true, secret: true,
78
+ description: "__Secure-1PSID from a fresh incognito gemini.google.com login — enables authed web_research (Deep Research). GEMINI_WEB_SECURE_1PSID env overrides; keep the source browser session closed." },
79
+ { key: "gemini.proxy", label: "Gemini web proxy", envVar: "GEMINI_WEB_PROXY", kind: "string",
80
+ description: "Proxy URL for Gemini web calls if Google blocks the IP. GEMINI_WEB_PROXY env overrides." },
81
+ // ── Image ───────────────────────────────────────────────────────────
82
+ { key: "image.zaiKey", label: "Z.ai image key", envVar: "ZAI_API_KEY", kind: "string", mask: true, secret: true,
83
+ description: "Z.ai API key for the web_image GLM-Image provider (distinct from the zai module's ZAI_ANTHROPIC_API_KEY). ZAI_API_KEY env overrides." },
84
+ { key: "image.customUrl", label: "Custom image URL", envVar: "WEB_IMAGE_API_BASE_URL", kind: "string",
85
+ description: "web_image custom provider: any OpenAI-compatible /images/generations endpoint. WEB_IMAGE_API_BASE_URL env overrides." },
86
+ { key: "image.customKey", label: "Custom image key", envVar: "WEB_IMAGE_API_KEY", kind: "string", mask: true, secret: true,
87
+ description: "Bearer key for the custom image endpoint. WEB_IMAGE_API_KEY env overrides." },
88
+ { key: "image.dailyCap", label: "Web image daily cap", envVar: "WEB_IMAGE_DAILY_CAP", kind: "number", defaultValue: "20",
89
+ description: "Daily soft cap for the Gemini web tier and ChatGPT web image providers (keyed APIs stay uncapped). WEB_IMAGE_DAILY_CAP env overrides." },
90
+ // ── Chat ────────────────────────────────────────────────────────────
91
+ { key: "chat.baseUrl", label: "Web chat gateway URL", envVar: "WEB_CHAT_API_BASE_URL", kind: "string",
92
+ description: "web_chat gateway: any OpenAI-compatible /chat/completions endpoint. WEB_CHAT_API_BASE_URL env overrides." },
93
+ { key: "chat.apiKey", label: "Web chat gateway key", envVar: "WEB_CHAT_API_KEY", kind: "string", mask: true, secret: true,
94
+ description: "Bearer key for the web_chat gateway. WEB_CHAT_API_KEY env overrides." },
95
+ ];
96
+ }
97
+
98
+ /** Effective row values for the panel's working copy: env wins over settings
99
+ * (what the tools actually resolve), settings shown when env is unset.
100
+ * Exported for tests. */
101
+ export function readWebRowValues(cwd: string, trusted: boolean): Record<string, { value: string; source: string }> {
102
+ const out: Record<string, { value: string; source: string }> = {};
103
+ for (const spec of webRowSpecs()) {
104
+ // findEnvValue == lookupVar: env → settings layers in one call, with the
105
+ // source disclosing which layer served ("env" | "project settings" |
106
+ // "global settings"), so the panel shows exactly what the tools resolve.
107
+ const r = findEnvValue(spec.envVar, cwd, trusted);
108
+ out[spec.key] = r.value ? { value: r.value, source: r.source } : { value: "", source: "default" };
109
+ }
110
+ return out;
111
+ }
112
+
113
+ /** Build the web panel group over a working copy (mutated by row setters).
114
+ * Exported for tests. */
115
+ export function buildWebGroups(working: Record<string, string>): PanelGroup[] {
116
+ return [
117
+ {
118
+ key: "web",
119
+ label: "Web",
120
+ tab: "Tools",
121
+ icon: "🌍",
122
+ rows: webRowSpecs().map((spec) =>
123
+ row(
124
+ `web.${spec.key}`,
125
+ spec.label,
126
+ spec.kind,
127
+ working[spec.key] ?? "",
128
+ (v) => {
129
+ working[spec.key] = v === undefined || v === null ? "" : String(v).trim();
130
+ },
131
+ {
132
+ ...(spec.mask ? { mask: true } : {}),
133
+ ...(spec.defaultValue !== undefined ? { defaultValue: spec.defaultValue } : {}),
134
+ ...(spec.allow ? {
135
+ menu: () => spec.allow!.map((v) => ({ value: v, label: `${Number(v) / 1000} seconds`, description: TIMEOUT_DESCRIPTIONS[v] })),
136
+ } : {}),
137
+ description: spec.description,
138
+ ...(spec.secret
139
+ ? { warning: "Stored in the settings file — prefer the env var on shared machines." }
140
+ : {}),
141
+ },
142
+ ),
143
+ ),
144
+ },
145
+ ];
146
+ }
147
+
148
+ const OWNED_PREFIX = "web.";
149
+
150
+ /** The save patch for the rows edited since the pre-edit snapshot. Number rows
151
+ * persist as numbers (timeoutMs semantics), strings as strings, and an empty
152
+ * string clears the key (writeWebSection semantics). Free text that is not a
153
+ * finite number is SKIPPED — writing 0 would clobber the stored cap with a
154
+ * value the consumer then clamps (or bricks the timeout loaders). Exported
155
+ * for tests. */
156
+ export function diffWebPatch(
157
+ working: Record<string, string>,
158
+ before: Record<string, string>,
159
+ ): Record<string, string | number> {
160
+ const patch: Record<string, string | number> = {};
161
+ for (const spec of webRowSpecs()) {
162
+ if (working[spec.key] === before[spec.key]) continue;
163
+ const raw = working[spec.key] ?? "";
164
+ if (spec.kind === "number" && raw !== "") {
165
+ const n = Number.parseInt(raw, 10);
166
+ if (!Number.isFinite(n)) continue; // garbage → leave the stored value alone
167
+ patch[spec.key] = n;
168
+ } else {
169
+ patch[spec.key] = raw;
170
+ }
171
+ }
172
+ return patch;
173
+ }
174
+
175
+ /** web's ModuleConfig for the central /config panel. cwd/trust come from the
176
+ * save ctx (factories receive none); reads use process.cwd(), matching
177
+ * munin's panel pattern. */
178
+ export function webConfig(): ModuleConfig {
179
+ const read = () => {
180
+ const values = readWebRowValues(process.cwd(), true);
181
+ return Object.fromEntries(Object.entries(values).map(([k, v]) => [k, v.value]));
182
+ };
183
+ const before = read();
184
+ const working = structuredClone(before);
185
+
186
+ return {
187
+ groups: () => buildWebGroups(working),
188
+ save: async (edited, ctx) => {
189
+ if (![...edited].some((k) => k.startsWith(OWNED_PREFIX))) return;
190
+ const target = `${agentDirs()[0]}${"/"}settings.json`;
191
+ // Diff against the pre-edit effective values: only changed keys are
192
+ // written (masked rows start empty — an untouched masked row diffs to
193
+ // no change).
194
+ const patch = diffWebPatch(working, before);
195
+ writeWebSection(patch, target);
196
+ const notes = [`Web config saved to ${target} — effective immediately (read per tool call).`];
197
+ // Disclose env vars that still override saved values, and a trusted
198
+ // project file that shadows a field.
199
+ const envOverrides = webRowSpecs().filter((s) => patch[s.key] !== undefined && process.env[s.envVar]).map((s) => s.envVar);
200
+ if (envOverrides.length) notes.push(`Still overridden by env: ${envOverrides.join(", ")}.`);
201
+ // Resolve through the SAME lookup the runtime uses, so a hand-written
202
+ // NESTED project entry (web.brave.apiKey as {brave:{apiKey}}) is
203
+ // disclosed instead of shadowing the save silently. The PROJECT layer
204
+ // alone — a merged read reports the just-written global key as a shadow.
205
+ const shadowed = ctx.isProjectTrusted?.() === true
206
+ ? Object.keys(patch).filter((k) => {
207
+ const v = sectionValue(readProjectWebSection(ctx.cwd), k);
208
+ return v !== undefined && v !== null && v !== "";
209
+ })
210
+ : [];
211
+ if (shadowed.length) notes.push(`A trusted project .pi/settings.json web section shadows: ${shadowed.join(", ")}.`);
212
+ ctx.ui.notify(notes.join(" "), "info");
213
+ },
214
+ };
215
+ }
216
+
217
+ /** Exposed for tests + the module's own status surfaces. */
218
+ export { ENV_TO_SETTINGS_KEY };