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,198 @@
1
+ // web's /config contribution: 16 rows over a `web.`-prefixed key set, masked
2
+ // secrets, save that writes only changed fields to the global settings.json.
3
+
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import fs from "node:fs";
7
+ import os from "node:os";
8
+ import path from "node:path";
9
+
10
+ import { buildWebGroups, diffWebPatch, readWebRowValues, webConfig } from "../configPanel";
11
+ import { writeWebSection } from "../lib/settings";
12
+
13
+ function tmpAgentDir(): string {
14
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "web-panel-"));
15
+ process.env.PI_CODING_AGENT_DIR = dir;
16
+ return dir;
17
+ }
18
+
19
+ function withEnv(key: string, value: string | undefined, fn: () => void): void {
20
+ const old = process.env[key];
21
+ if (value === undefined) delete process.env[key];
22
+ else process.env[key] = value;
23
+ try {
24
+ fn();
25
+ } finally {
26
+ if (old === undefined) delete process.env[key];
27
+ else process.env[key] = old;
28
+ }
29
+ }
30
+
31
+ describe("web configPanel", () => {
32
+ it("16 rows, all keys web.-prefixed, secrets masked", () => {
33
+ const groups = buildWebGroups({});
34
+ assert.equal(groups.length, 1);
35
+ assert.equal(groups[0]!.label, "Web");
36
+ assert.equal(groups[0]!.tab, "Tools");
37
+ assert.equal(groups[0]!.icon, "🌍");
38
+ const rows = groups[0]!.rows;
39
+ assert.equal(rows.length, 16);
40
+ for (const r of rows) assert.ok(r.key.startsWith("web."), r.key);
41
+ const masked = rows.filter((r) => r.mask);
42
+ assert.equal(masked.length, 7);
43
+ for (const r of masked) assert.ok(/key|token|cookie/i.test(r.label), `secret row: ${r.label}`);
44
+ });
45
+
46
+ it("readWebRowValues: env wins, settings fallback, empty default", () => {
47
+ const dir = tmpAgentDir();
48
+ try {
49
+ withEnv("BRAVE_API_KEY", "env-key", () => {
50
+ writeWebSection({ "brave.apiKey": "settings-key", "chat.apiKey": "chat-key" }, path.join(dir, "settings.json"));
51
+ const values = readWebRowValues("/nonexistent-project", false);
52
+ assert.deepEqual(values["brave.apiKey"], { value: "env-key", source: "env" });
53
+ assert.deepEqual(values["chat.apiKey"], { value: "chat-key", source: "global settings" });
54
+ assert.deepEqual(values["gemini.proxy"], { value: "", source: "default" });
55
+ });
56
+ } finally {
57
+ fs.rmSync(dir, { recursive: true, force: true });
58
+ delete process.env.PI_CODING_AGENT_DIR;
59
+ }
60
+ });
61
+
62
+ it("timeout rows are a CLOSED SET so an invalid value can't brick a tool", () => {
63
+ // Live-found regression: a free-text 30 (ms) makes load*Config throw
64
+ // ("must be an integer >= 1000"), disabling every Firecrawl/Crawl4AI tool.
65
+ const groups = buildWebGroups({});
66
+ for (const key of ["web.firecrawl.timeoutMs", "web.crawl4ai.timeoutMs"]) {
67
+ const row = groups[0]!.rows.find((r) => r.key === key)!;
68
+ const opts = row.menu?.() ?? [];
69
+ assert.ok(opts.length >= 4, `${key} offers timed options`);
70
+ for (const o of opts) assert.ok(Number(o.value) >= 1000, `${key} option ${o.value} >= 1000ms`);
71
+ assert.ok(opts.some((o) => o.value === "60000"), `${key} includes the 60s default`);
72
+ }
73
+ });
74
+
75
+ it("rows mutate the working copy; set() accepts numbers for number rows", () => {
76
+ const groups = buildWebGroups({ "firecrawl.timeoutMs": "60000" });
77
+ const row = groups[0]!.rows.find((r) => r.key === "web.firecrawl.timeoutMs")!;
78
+ assert.equal(row.kind, "number");
79
+ row.set(30000);
80
+ assert.equal(row.value, 30000);
81
+ const secret = groups[0]!.rows.find((r) => r.key === "web.brave.apiKey")!;
82
+ secret.set("typed");
83
+ assert.equal(secret.value, "typed");
84
+ });
85
+
86
+ it("save no-ops unless a web.* key was edited", async () => {
87
+ const dir = tmpAgentDir();
88
+ try {
89
+ const cfg = webConfig();
90
+ const notifications: string[] = [];
91
+ const ctx = { cwd: "/nonexistent", ui: { notify: (m: string) => notifications.push(m) }, isProjectTrusted: () => false } as never;
92
+ await cfg.save(new Set(["munin.apiKey"]), ctx);
93
+ assert.equal(notifications.length, 0);
94
+ assert.ok(!fs.existsSync(path.join(dir, "settings.json")));
95
+ } finally {
96
+ fs.rmSync(dir, { recursive: true, force: true });
97
+ delete process.env.PI_CODING_AGENT_DIR;
98
+ }
99
+ });
100
+
101
+ it("save writes ONLY changed fields and discloses env overrides", async () => {
102
+ const dir = tmpAgentDir();
103
+ const old = process.env.BRAVE_API_KEY;
104
+ process.env.BRAVE_API_KEY = "still-from-env";
105
+ try {
106
+ // Working copy built from effective values: env value shown for brave.
107
+ const cfg = webConfig();
108
+ const groups = cfg.groups();
109
+ const brave = groups[0]!.rows.find((r) => r.key === "web.brave.apiKey")!;
110
+ assert.equal(brave.value, "still-from-env");
111
+ // User changes two rows (one env-backed, one plain).
112
+ brave.set("panel-key");
113
+ const timeout = groups[0]!.rows.find((r) => r.key === "web.crawl4ai.timeoutMs")!;
114
+ timeout.set(45000);
115
+ const notifications: string[] = [];
116
+ const ctx = { cwd: "/nonexistent", ui: { notify: (m: string) => notifications.push(m) }, isProjectTrusted: () => false } as never;
117
+ await cfg.save(new Set(["web.brave.apiKey", "web.crawl4ai.timeoutMs"]), ctx);
118
+ const raw = JSON.parse(fs.readFileSync(path.join(dir, "settings.json"), "utf8"));
119
+ assert.equal(raw.web["brave.apiKey"], "panel-key");
120
+ assert.equal(raw.web["crawl4ai.timeoutMs"], 45000);
121
+ assert.equal(Object.keys(raw.web).length, 2, "only changed keys written");
122
+ const note = notifications.join(" ");
123
+ assert.ok(note.includes("settings.json"), note);
124
+ assert.ok(note.includes("BRAVE_API_KEY"), "env override disclosed");
125
+ } finally {
126
+ if (old === undefined) delete process.env.BRAVE_API_KEY;
127
+ else process.env.BRAVE_API_KEY = old;
128
+ fs.rmSync(dir, { recursive: true, force: true });
129
+ delete process.env.PI_CODING_AGENT_DIR;
130
+ }
131
+ });
132
+
133
+ it("diffWebPatch: free-text garbage on a number row leaves the key untouched", () => {
134
+ // Live-found regression: parseInt('abc') || 0 wrote a 0 cap to disk, which
135
+ // the consumer then clamped — silently clobbering the user's real value.
136
+ const before = { "image.dailyCap": "20", "crawl4ai.timeoutMs": "60000", "brave.apiKey": "old" };
137
+ assert.deepEqual(diffWebPatch({ ...before, "image.dailyCap": "abc" }, before), {}, "garbage number row skipped, never 0");
138
+ // A real number still persists as a number; empty string still clears.
139
+ assert.deepEqual(diffWebPatch({ ...before, "crawl4ai.timeoutMs": "45000" }, before), { "crawl4ai.timeoutMs": 45000 });
140
+ assert.deepEqual(diffWebPatch({ ...before, "image.dailyCap": "" }, before), { "image.dailyCap": "" });
141
+ });
142
+
143
+ it("save keeps the stored cap when the panel edit is garbage ('abc' → no write)", async () => {
144
+ const dir = tmpAgentDir();
145
+ try {
146
+ writeWebSection({ "image.dailyCap": 20 }, path.join(dir, "settings.json"));
147
+ const cfg = webConfig();
148
+ cfg.groups()[0]!.rows.find((r) => r.key === "web.image.dailyCap")!.set("abc");
149
+ const ctx = { cwd: "/nonexistent", ui: { notify: () => {} }, isProjectTrusted: () => false } as never;
150
+ await cfg.save(new Set(["web.image.dailyCap"]), ctx);
151
+ const raw = JSON.parse(fs.readFileSync(path.join(dir, "settings.json"), "utf8"));
152
+ assert.equal(raw.web["image.dailyCap"], 20, "stored cap survives a garbage edit");
153
+ } finally {
154
+ fs.rmSync(dir, { recursive: true, force: true });
155
+ delete process.env.PI_CODING_AGENT_DIR;
156
+ }
157
+ });
158
+
159
+ it("discloses a NESTED project web entry that shadows the save", async () => {
160
+ const dir = tmpAgentDir();
161
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "web-nested-"));
162
+ try {
163
+ // Hand-written nested shape: the flat panel key is NOT a top-level key.
164
+ fs.mkdirSync(path.join(cwd, ".pi"), { recursive: true });
165
+ fs.writeFileSync(path.join(cwd, ".pi", "settings.json"), JSON.stringify({ web: { brave: { apiKey: "nested-project-key" } } }));
166
+ const cfg = webConfig();
167
+ cfg.groups()[0]!.rows.find((r) => r.key === "web.brave.apiKey")!.set("panel-key");
168
+ const notifications: string[] = [];
169
+ const ctx = { cwd, ui: { notify: (m: string) => notifications.push(m) }, isProjectTrusted: () => true } as never;
170
+ await cfg.save(new Set(["web.brave.apiKey"]), ctx);
171
+ const note = notifications.join(" ");
172
+ assert.match(note, /shadows: brave\.apiKey/, note);
173
+ } finally {
174
+ fs.rmSync(dir, { recursive: true, force: true });
175
+ fs.rmSync(cwd, { recursive: true, force: true });
176
+ delete process.env.PI_CODING_AGENT_DIR;
177
+ }
178
+ });
179
+
180
+ it("trusted save with no project web section reports no phantom shadow", async () => {
181
+ const dir = tmpAgentDir();
182
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "web-noproj-"));
183
+ try {
184
+ const cfg = webConfig();
185
+ cfg.groups()[0]!.rows.find((r) => r.key === "web.brave.apiKey")!.set("panel-key");
186
+ const notifications: string[] = [];
187
+ const ctx = { cwd, ui: { notify: (m: string) => notifications.push(m) }, isProjectTrusted: () => true } as never;
188
+ await cfg.save(new Set(["web.brave.apiKey"]), ctx);
189
+ // Disclosure reads the PROJECT layer alone: a merged read would see the
190
+ // key just written to global and call it a shadow.
191
+ assert.doesNotMatch(notifications.join(" "), /shadows:/);
192
+ } finally {
193
+ fs.rmSync(dir, { recursive: true, force: true });
194
+ fs.rmSync(cwd, { recursive: true, force: true });
195
+ delete process.env.PI_CODING_AGENT_DIR;
196
+ }
197
+ });
198
+ });
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Unit tests for web_crawl light-mode poll loop deadline handling.
3
+ *
4
+ * The loop must honor timeout_ms (stop polling + report incomplete state)
5
+ * instead of always running its full 60×2s iteration cap.
6
+ */
7
+
8
+ import { describe, it, beforeEach, afterEach } from "node:test";
9
+ import assert from "node:assert/strict";
10
+ import piWebExtension from "../index";
11
+
12
+ // The web settings layer reads the agent-dir settings.json — isolate the
13
+ // agent dir so a host `web` section never leaks into these tests.
14
+ process.env.PI_CODING_AGENT_DIR = "/nonexistent-pi-agent-dir-for-web-tests";
15
+
16
+ // chai-compat helpers (assert-based)
17
+ function includes(haystack: unknown, needle: unknown): boolean {
18
+ if (typeof haystack === "string") return haystack.includes(String(needle));
19
+ if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
20
+ if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
21
+ if (v === needle) return true;
22
+ // chai's to.include on an array does DEEP membership for objects.
23
+ if (v && needle && typeof v === "object" && typeof needle === "object") {
24
+ try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
25
+ }
26
+ return false;
27
+ });
28
+ // chai's to.include on an OBJECT target: needle's properties are a subset.
29
+ if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
30
+ return deepIncludes(haystack, needle as Record<string, unknown>);
31
+ }
32
+ return false;
33
+ }
34
+ function lengthOf(v: unknown): number {
35
+ if (Array.isArray(v)) return v.length;
36
+ if (typeof v === "string") return v.length;
37
+ if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
38
+ if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
39
+ throw new Error("lengthOf: value has no length/size");
40
+ }
41
+ /** Deep "includes" — every own key of `part` must exist on `obj` with a
42
+ * deep-equal value (chai's to.deep.include for object subjects). */
43
+ function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
44
+ if (Array.isArray(obj)) return includes(obj, part); // deep membership
45
+ if (typeof obj !== "object" || obj === null) return false;
46
+ return Object.entries(part).every(([k, v]) => {
47
+ try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
48
+ });
49
+ }
50
+
51
+ function harness(): Record<string, any> {
52
+ const tools: Record<string, any> = {};
53
+ const pi: any = {
54
+ registerTool(tool: any) { tools[tool.name] = tool; },
55
+ on() {},
56
+ };
57
+ piWebExtension(pi);
58
+ return tools;
59
+ }
60
+
61
+ function jsonResponse(body: unknown, status = 200): Response {
62
+ return new Response(JSON.stringify(body), {
63
+ status,
64
+ headers: { "content-type": "application/json" },
65
+ });
66
+ }
67
+
68
+ describe("web_crawl light-mode poll loop", () => {
69
+ const ORIGINAL_FETCH = globalThis.fetch;
70
+ const SAVED_URL = process.env.FIRECRAWL_API_URL;
71
+ const SAVED_KEY = process.env.FIRECRAWL_API_KEY;
72
+
73
+ beforeEach(() => {
74
+ process.env.FIRECRAWL_API_URL = "http://firecrawl.test/v2";
75
+ process.env.FIRECRAWL_API_KEY = "test-key";
76
+ });
77
+
78
+ afterEach(() => {
79
+ globalThis.fetch = ORIGINAL_FETCH;
80
+ if (SAVED_URL === undefined) delete process.env.FIRECRAWL_API_URL;
81
+ else process.env.FIRECRAWL_API_URL = SAVED_URL;
82
+ if (SAVED_KEY === undefined) delete process.env.FIRECRAWL_API_KEY;
83
+ else process.env.FIRECRAWL_API_KEY = SAVED_KEY;
84
+ });
85
+
86
+ it("stops polling at timeout_ms and returns an honest incomplete-state note", async () => {
87
+ let getCalls = 0;
88
+ globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
89
+ const url = String(input);
90
+ if (init?.method === "POST" && url.endsWith("/crawl")) return jsonResponse({ id: "c1" });
91
+ if (url.endsWith("/crawl/c1")) {
92
+ getCalls += 1;
93
+ return jsonResponse({ status: "scraping" });
94
+ }
95
+ throw new Error(`unexpected fetch ${url}`);
96
+ }) as typeof fetch;
97
+
98
+ const tools = harness();
99
+ const res = await tools.web_crawl.execute(
100
+ "t1",
101
+ { url: "https://example.com", mode: "light", poll: true, timeout_ms: 1000 },
102
+ new AbortController().signal,
103
+ undefined,
104
+ {},
105
+ );
106
+ // Exited on the deadline after one poll, not the 60-iteration cap.
107
+ assert.equal(getCalls, 1);
108
+ assert.ok(includes(res.content[0].text, "timeout_ms"));
109
+ assert.ok(includes(res.content[0].text, "scraping"));
110
+ assert.ok(includes(res.content[0].text, "incomplete"));
111
+ });
112
+
113
+ it("still returns immediately when the crawl is already completed (no timeout_ms)", async () => {
114
+ globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
115
+ const url = String(input);
116
+ if (init?.method === "POST" && url.endsWith("/crawl")) return jsonResponse({ id: "c2" });
117
+ if (url.endsWith("/crawl/c2")) {
118
+ return jsonResponse({ status: "completed", data: [{ markdown: "# Page", url: "https://example.com" }] });
119
+ }
120
+ throw new Error(`unexpected fetch ${url}`);
121
+ }) as typeof fetch;
122
+
123
+ const tools = harness();
124
+ const res = await tools.web_crawl.execute(
125
+ "t2",
126
+ { url: "https://example.com", mode: "light", poll: true },
127
+ new AbortController().signal,
128
+ undefined,
129
+ {},
130
+ );
131
+ assert.ok(!includes(res.content[0].text, "incomplete"));
132
+ assert.ok(includes(res.content[0].text, "Page"));
133
+ });
134
+ });
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Unit tests for pi-web Crawl4AI client.
3
+ */
4
+
5
+ import { describe, it, beforeEach, afterEach } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { HttpError } from "../lib/retry";
8
+
9
+ describe("HttpError", () => {
10
+ it("formats error message with status and text", () => {
11
+ const err = new HttpError(401, "Unauthorized", '{"detail":"bad token"}');
12
+ assert.equal(err.status, 401);
13
+ assert.ok(includes(err.message, "HTTP 401: Unauthorized"));
14
+ assert.ok(includes(err.message, '{"detail":"bad token"}'));
15
+ });
16
+
17
+ it("handles empty response text", () => {
18
+ const err = new HttpError(500, "Internal Server Error", "");
19
+ assert.equal(err.status, 500);
20
+ assert.equal(err.message, "HTTP 500: Internal Server Error");
21
+ });
22
+
23
+ it("is instance of Error", () => {
24
+ const err = new HttpError(403, "Forbidden", "rate limit");
25
+ assert.ok(err instanceof Error);
26
+ });
27
+ });
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Config + format integration: verify imported functions exist with correct sigs
31
+ // ---------------------------------------------------------------------------
32
+
33
+ import type { Crawl4aiConfig } from "../lib/config";
34
+
35
+ describe("Crawl4aiConfig interface", () => {
36
+ it("has expected shape", () => {
37
+ const config: Crawl4aiConfig = {
38
+ baseUrl: "http://localhost:11235",
39
+ apiToken: "token123",
40
+ timeoutMs: 30000,
41
+ };
42
+ assert.equal(config.baseUrl, "http://localhost:11235");
43
+ assert.equal(config.apiToken, "token123");
44
+ assert.equal(config.timeoutMs, 30000);
45
+ });
46
+ });
47
+
48
+ // ---------------------------------------------------------------------------
49
+ // Verify client exports exist
50
+ // ---------------------------------------------------------------------------
51
+
52
+ import {
53
+ fetchCrawl4aiMarkdown,
54
+ fetchCrawl4aiCrawl,
55
+ fetchCrawl4aiScreenshot,
56
+ fetchCrawl4aiPdf,
57
+ fetchCrawl4aiHealth,
58
+ crawl4aiRequest,
59
+ } from "../lib/crawl4ai";
60
+
61
+ // chai-compat helpers (assert-based)
62
+ function includes(haystack: unknown, needle: unknown): boolean {
63
+ if (typeof haystack === "string") return haystack.includes(String(needle));
64
+ if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
65
+ if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
66
+ if (v === needle) return true;
67
+ // chai's to.include on an array does DEEP membership for objects.
68
+ if (v && needle && typeof v === "object" && typeof needle === "object") {
69
+ try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
70
+ }
71
+ return false;
72
+ });
73
+ // chai's to.include on an OBJECT target: needle's properties are a subset.
74
+ if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
75
+ return deepIncludes(haystack, needle as Record<string, unknown>);
76
+ }
77
+ return false;
78
+ }
79
+ function lengthOf(v: unknown): number {
80
+ if (Array.isArray(v)) return v.length;
81
+ if (typeof v === "string") return v.length;
82
+ if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
83
+ if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
84
+ throw new Error("lengthOf: value has no length/size");
85
+ }
86
+ /** Deep "includes" — every own key of `part` must exist on `obj` with a
87
+ * deep-equal value (chai's to.deep.include for object subjects). */
88
+ function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
89
+ if (Array.isArray(obj)) return includes(obj, part); // deep membership
90
+ if (typeof obj !== "object" || obj === null) return false;
91
+ return Object.entries(part).every(([k, v]) => {
92
+ try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
93
+ });
94
+ }
95
+
96
+ describe("Crawl4AI client exports", () => {
97
+ it("exports all expected functions", () => {
98
+ assert.equal(typeof fetchCrawl4aiMarkdown, 'function');
99
+ assert.equal(typeof fetchCrawl4aiCrawl, 'function');
100
+ assert.equal(typeof fetchCrawl4aiScreenshot, 'function');
101
+ assert.equal(typeof fetchCrawl4aiPdf, 'function');
102
+ assert.equal(typeof fetchCrawl4aiHealth, 'function');
103
+ assert.equal(typeof crawl4aiRequest, 'function');
104
+ });
105
+ });
@@ -0,0 +1,118 @@
1
+ // ceulen integration contract: per-tool kill-switch (ceulen.disabledTools →
2
+ // defaultActive:false), skill contributed via resources_discover, and the
3
+ // before_agent_start guidance hook gated on active web_* tools.
4
+
5
+ import { describe, it, beforeEach, afterEach } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import fs from "node:fs";
8
+ import os from "node:os";
9
+ import path from "node:path";
10
+
11
+ import webExtension from "../index";
12
+
13
+ const ALL_TOOLS = [
14
+ "web_search", "web_extract", "web_map", "web_crawl", "web_screenshot", "web_pdf",
15
+ "web_interact", "web_research", "web_image", "web_chat", "web_status",
16
+ ];
17
+
18
+ function harness(opts: { disabledTools?: string[]; activeTools?: string[] } = {}) {
19
+ const tools: Record<string, { name: string; defaultActive?: boolean }> = {};
20
+ const handlers: Record<string, Function[]> = {};
21
+ const discoverResults: { skillPaths: string[] }[] = [];
22
+ const pi: any = {
23
+ registerTool(tool: any) { tools[tool.name] = tool; },
24
+ on(name: string, handler: Function) {
25
+ (handlers[name] ??= []).push(handler);
26
+ },
27
+ getActiveTools: () => opts.activeTools ?? [],
28
+ };
29
+ // Intercept resources_discover results (munin harness pattern).
30
+ const realOn = pi.on.bind(pi);
31
+ pi.on = (name: string, handler: Function) => {
32
+ if (name === "resources_discover") {
33
+ return realOn(name, (...args: unknown[]) => {
34
+ const r = (handler as (...a: unknown[]) => { skillPaths: string[] })(...args);
35
+ discoverResults.push(r);
36
+ return r;
37
+ });
38
+ }
39
+ return realOn(name, handler);
40
+ };
41
+ const oldDisabled = process.env.CEULEN_TEST_DISABLED_TOOLS;
42
+ // readDisabledTools reads the settings file — shield via PI_CODING_AGENT_DIR
43
+ // + a settings file carrying the disabled list.
44
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "web-ext-"));
45
+ process.env.PI_CODING_AGENT_DIR = dir;
46
+ if (opts.disabledTools?.length) {
47
+ fs.writeFileSync(path.join(dir, "settings.json"), JSON.stringify({ ceulen: { disabledTools: opts.disabledTools } }));
48
+ }
49
+ try {
50
+ webExtension(pi);
51
+ } finally {
52
+ if (oldDisabled === undefined) delete process.env.PI_CODING_AGENT_DIR;
53
+ else process.env.PI_CODING_AGENT_DIR = oldDisabled;
54
+ fs.rmSync(dir, { recursive: true, force: true });
55
+ }
56
+ return { tools, handlers, discoverResults };
57
+ }
58
+
59
+ async function callGuidance(handlers: Record<string, Function[]>, selectedTools?: string[]) {
60
+ return await handlers.before_agent_start[0]({ systemPrompt: "BASE", systemPromptOptions: { selectedTools } });
61
+ }
62
+
63
+ describe("web module ceulen contract", () => {
64
+ let oldAgentDir: string | undefined;
65
+
66
+ beforeEach(() => {
67
+ oldAgentDir = process.env.PI_CODING_AGENT_DIR;
68
+ });
69
+ afterEach(() => {
70
+ if (oldAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
71
+ else process.env.PI_CODING_AGENT_DIR = oldAgentDir;
72
+ });
73
+
74
+ it("registers exactly the eleven web_* tools", () => {
75
+ const { tools } = harness();
76
+ assert.deepEqual(Object.keys(tools).sort(), [...ALL_TOOLS].sort());
77
+ });
78
+
79
+ it("ceulen.disabledTools → defaultActive:false (inactive at registration)", () => {
80
+ const { tools } = harness({ disabledTools: ["web_search", "web_image"] });
81
+ assert.equal(tools.web_search!.defaultActive, false);
82
+ assert.equal(tools.web_image!.defaultActive, false);
83
+ assert.equal(tools.web_extract!.defaultActive, true);
84
+ assert.equal(tools.web_status!.defaultActive, true);
85
+ });
86
+
87
+ it("all tools default-active when the kill-switch list is empty", () => {
88
+ const { tools } = harness();
89
+ for (const name of ALL_TOOLS) assert.equal(tools[name]!.defaultActive, true, name);
90
+ });
91
+
92
+ it("contributes exactly one skill: skills/web (kill-switch gated by factory load)", () => {
93
+ const { handlers } = harness();
94
+ // resources_discover is a subscription — invoke the handler as pi would.
95
+ const discoverResults = [handlers.resources_discover![0]!()];
96
+ assert.equal(discoverResults.length, 1);
97
+ assert.equal(discoverResults[0]!.skillPaths.length, 1);
98
+ assert.ok(discoverResults[0]!.skillPaths[0]!.endsWith(path.join("skills", "web")));
99
+ assert.ok(fs.existsSync(path.join(discoverResults[0]!.skillPaths[0]!, "SKILL.md")));
100
+ });
101
+
102
+ it("guidance injects only when a web_* tool is active (selectedTools)", async () => {
103
+ const { handlers } = harness();
104
+ const hit = await callGuidance(handlers, ["read", "web_search"]);
105
+ assert.ok(String(hit?.systemPrompt).includes("BASE"));
106
+ assert.ok(String(hit?.systemPrompt).includes("Web Tool Routing"));
107
+ const miss = await callGuidance(handlers, ["read", "bash", "grep"]);
108
+ assert.equal(miss, undefined);
109
+ });
110
+
111
+ it("guidance falls back to pi.getActiveTools() when selectedTools is undefined", async () => {
112
+ const { handlers } = harness({ activeTools: ["read", "web_extract"] });
113
+ const hit = await callGuidance(handlers);
114
+ assert.ok(String(hit?.systemPrompt).includes("Web Tool Routing"));
115
+ const quiet = harness({ activeTools: ["read", "bash"] });
116
+ assert.equal(await callGuidance(quiet.handlers), undefined);
117
+ });
118
+ });