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,329 @@
1
+ // Ported from pi-model-tools extensions/test/unit/zai-throttle.test.ts.
2
+ // Added: defaultThrottlePaths() honors PI_CODING_AGENT_DIR (ceulen resolves the
3
+ // agent dir through lib/registry.ts agentDirs(), not a hardcoded ~/.pi/agent),
4
+ // and throttleZaiDispatch accepts the settings-resolved intervalMs override.
5
+ // Dropped: readFile/none — all assertions preserved.
6
+
7
+ import assert from "node:assert/strict";
8
+ import { existsSync } from "node:fs";
9
+ import { mkdir, mkdtemp, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { after, describe, it } from "node:test";
13
+ import {
14
+ DEFAULT_MIN_INTERVAL_MS,
15
+ MIN_INTERVAL_ENV,
16
+ acquireLock,
17
+ defaultThrottlePaths,
18
+ throttleDispatch,
19
+ throttleZaiDispatch,
20
+ zaiThrottleIntervalMs,
21
+ } from "../lib/throttle.js";
22
+
23
+ interface Ctx {
24
+ dir: string;
25
+ statePath: string;
26
+ lockPath: string;
27
+ }
28
+
29
+ const tmpDirs: string[] = [];
30
+
31
+ after(async () => {
32
+ for (const dir of tmpDirs) await rm(dir, { recursive: true, force: true });
33
+ });
34
+
35
+ async function freshCtx(): Promise<Ctx> {
36
+ const dir = await mkdtemp(join(tmpdir(), "zai-throttle-"));
37
+ tmpDirs.push(dir);
38
+ return {
39
+ dir,
40
+ statePath: join(dir, "zai-anthropic-dispatch.json"),
41
+ lockPath: join(dir, ".zai-anthropic-dispatch.lock"),
42
+ };
43
+ }
44
+
45
+ /** Fake clock: sleep() advances now() so waits resolve instantly but stay observable. */
46
+ function fakeClock(start = 10_000) {
47
+ let t = start;
48
+ const slept: number[] = [];
49
+ return {
50
+ now: () => t,
51
+ slept,
52
+ sleep: async (ms: number) => {
53
+ slept.push(ms);
54
+ t += ms;
55
+ },
56
+ };
57
+ }
58
+
59
+ describe("zai-throttle interval config", () => {
60
+ it("defaults to 1000ms; explicit 0 disables; garbage falls back to default", () => {
61
+ assert.equal(zaiThrottleIntervalMs({}), DEFAULT_MIN_INTERVAL_MS);
62
+ assert.equal(zaiThrottleIntervalMs({ [MIN_INTERVAL_ENV]: "0" }), 0);
63
+ assert.equal(zaiThrottleIntervalMs({ [MIN_INTERVAL_ENV]: "2500" }), 2500);
64
+ assert.equal(zaiThrottleIntervalMs({ [MIN_INTERVAL_ENV]: "bogus" }), DEFAULT_MIN_INTERVAL_MS);
65
+ assert.equal(zaiThrottleIntervalMs({ [MIN_INTERVAL_ENV]: "-5" }), DEFAULT_MIN_INTERVAL_MS);
66
+ });
67
+
68
+ it("defaultThrottlePaths lands both files in the agent dir", () => {
69
+ const paths = defaultThrottlePaths("/agents");
70
+ assert.equal(paths.statePath, join("/agents", "zai-anthropic-dispatch.json"));
71
+ assert.equal(paths.lockPath, join("/agents", ".zai-anthropic-dispatch.lock"));
72
+ });
73
+
74
+ it("defaultThrottlePaths() resolves through agentDirs() — PI_CODING_AGENT_DIR wins", () => {
75
+ const prev = process.env.PI_CODING_AGENT_DIR;
76
+ process.env.PI_CODING_AGENT_DIR = "/tmp/ceulen-zai-agent-dir";
77
+ try {
78
+ const paths = defaultThrottlePaths();
79
+ assert.equal(paths.statePath, join("/tmp/ceulen-zai-agent-dir", "zai-anthropic-dispatch.json"));
80
+ assert.equal(paths.lockPath, join("/tmp/ceulen-zai-agent-dir", ".zai-anthropic-dispatch.lock"));
81
+ } finally {
82
+ if (prev === undefined) delete process.env.PI_CODING_AGENT_DIR;
83
+ else process.env.PI_CODING_AGENT_DIR = prev;
84
+ }
85
+ });
86
+ });
87
+
88
+ describe("throttleDispatch", () => {
89
+ it("interval 0 → no-op, touches no files", async () => {
90
+ const c = await freshCtx();
91
+ const waited = await throttleDispatch({ intervalMs: 0, statePath: c.statePath, lockPath: c.lockPath });
92
+ assert.equal(waited, 0);
93
+ assert.equal(existsSync(c.statePath), false, "no state written");
94
+ assert.equal(existsSync(c.lockPath), false, "no lock left");
95
+ });
96
+
97
+ it("first dispatch claims immediately, records ts, releases the lock before returning", async () => {
98
+ const c = await freshCtx();
99
+ const clock = fakeClock();
100
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
101
+ assert.equal(waited, 0, "no state file yet → no wait");
102
+ assert.deepEqual(clock.slept, [], "slept nothing");
103
+ const state = JSON.parse(await readFile(c.statePath, "utf-8"));
104
+ assert.equal(state.ts, 10_000);
105
+ assert.equal(existsSync(c.lockPath), false, "lock released even though no request ever ran");
106
+ });
107
+
108
+ it("second dispatch inside the interval waits for the slot (claim held during sleep)", async () => {
109
+ const c = await freshCtx();
110
+ await writeFile(c.statePath, JSON.stringify({ ts: 10_000 }));
111
+ const clock = fakeClock(10_500); // 500ms after last slot, interval 1000 → wait 500
112
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
113
+ assert.equal(waited, 500);
114
+ assert.deepEqual(clock.slept, [500]);
115
+ assert.equal(JSON.parse(await readFile(c.statePath, "utf-8")).ts, 11_000, "slot recorded after the wait");
116
+ assert.equal(existsSync(c.lockPath), false);
117
+ });
118
+
119
+ it("dispatch past the interval does not wait", async () => {
120
+ const c = await freshCtx();
121
+ await writeFile(c.statePath, JSON.stringify({ ts: 10_000 }));
122
+ const clock = fakeClock(12_000); // 2s later, interval 1000 → free
123
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
124
+ assert.equal(waited, 0);
125
+ assert.deepEqual(clock.slept, []);
126
+ });
127
+
128
+ it("stale lock (crash mid-claim) is broken after 30s", async () => {
129
+ const c = await freshCtx();
130
+ await writeFile(c.lockPath, "99999");
131
+ const old = new Date(Date.now() - 40_000);
132
+ await utimes(c.lockPath, old, old);
133
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath });
134
+ assert.equal(waited, 0);
135
+ assert.equal(existsSync(c.lockPath), false, "stale lock broken and our claim released");
136
+ assert.ok(existsSync(c.statePath));
137
+ });
138
+
139
+ it("fail-open: unwritable state → returns 0, does not throw, lock still released", async () => {
140
+ const c = await freshCtx();
141
+ await mkdir(c.statePath); // state path is a directory → readFile AND writeFile both fail
142
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath });
143
+ assert.equal(waited, 0);
144
+ assert.equal(existsSync(c.lockPath), false, "no lock leak on fail-open");
145
+ });
146
+
147
+ it("concurrent dispatches space out by the interval (real timers)", async () => {
148
+ const c = await freshCtx();
149
+ const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
150
+ const t0 = Date.now();
151
+ // Queued claimants sleep while holding the mutex, so each waits ~one
152
+ // interval from ITS acquisition; total wall clock spans (N-1)×interval.
153
+ const waits = await Promise.all([
154
+ throttleDispatch({ intervalMs: 120, statePath: c.statePath, lockPath: c.lockPath, sleep }),
155
+ throttleDispatch({ intervalMs: 120, statePath: c.statePath, lockPath: c.lockPath, sleep }),
156
+ throttleDispatch({ intervalMs: 120, statePath: c.statePath, lockPath: c.lockPath, sleep }),
157
+ ]);
158
+ const elapsed = Date.now() - t0;
159
+ waits.sort((a, b) => a - b);
160
+ assert.ok(elapsed >= 230, `three claims at 120ms interval must queue, took ${elapsed}ms`);
161
+ assert.equal(waits[0], 0, "first claimant goes immediately");
162
+ // Slot spacing is the invariant (pinned deterministically by the fake-clock
163
+ // tests above); per-claimant sleeps vary by poll timing (up to one 40ms
164
+ // poll cycle late to the mutex) — just require real queueing happened.
165
+ assert.ok(Math.max(...waits) >= 60, `queued claimants slept real intervals (${waits.join(", ")})`);
166
+ assert.equal(existsSync(c.lockPath), false, "lock released after all claims");
167
+ const ts1 = JSON.parse(await readFile(c.statePath, "utf-8")).ts as number;
168
+ assert.ok(Math.abs(ts1 - Date.now()) < 5_000, "state holds a fresh ts");
169
+ });
170
+ });
171
+
172
+ describe("review hardening: lock protocol defects", () => {
173
+ it("unremovable stale lock → fails fast after deadline (no hot loop), fail-open with onError", async () => {
174
+ const c = await freshCtx();
175
+ // A directory at the lock path: open(…,"wx") → EEXIST, but unlink → EISDIR forever.
176
+ await mkdir(c.lockPath);
177
+ const old = new Date(Date.now() - 40_000);
178
+ await utimes(c.lockPath, old, old);
179
+ const errors: Error[] = [];
180
+ const t0 = Date.now();
181
+ const waited = await throttleDispatch({
182
+ intervalMs: 1000,
183
+ statePath: c.statePath,
184
+ lockPath: c.lockPath,
185
+ pollMs: 5,
186
+ lockDeadlineMs: 150,
187
+ onError: (e) => errors.push(e),
188
+ });
189
+ const elapsed = Date.now() - t0;
190
+ assert.equal(waited, 0, "fail-open");
191
+ assert.ok(elapsed < 5_000, `must hit the deadline fast, took ${elapsed}ms (hot loop would hang)`);
192
+ assert.equal(errors.length, 1, "fail-open reported via onError");
193
+ assert.match(errors[0]!.message, /lock busy/);
194
+ assert.equal(existsSync(c.statePath), false, "nothing claimed");
195
+ });
196
+
197
+ it("future/corrupt ts (clock step-back) is ignored → immediate dispatch, not an hour-long nap", async () => {
198
+ const c = await freshCtx();
199
+ await writeFile(c.statePath, JSON.stringify({ ts: Date.now() + 3_600_000 }));
200
+ const t0 = Date.now();
201
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath });
202
+ assert.ok(Date.now() - t0 < 5_000, "returns within seconds");
203
+ assert.equal(waited, 0);
204
+ const ts = JSON.parse(await readFile(c.statePath, "utf-8")).ts as number;
205
+ assert.ok(Math.abs(ts - Date.now()) < 5_000, "state rewritten with a sane fresh ts");
206
+ });
207
+
208
+ it("long wait naps in bounded holds and re-queues — never holds ≥ stale threshold (fake clock)", async () => {
209
+ const c = await freshCtx();
210
+ await writeFile(c.statePath, JSON.stringify({ ts: 10_000 }));
211
+ const clock = fakeClock(10_500); // wait = 19_500 > MAX_HOLD_MS(15_000) → 2 holds
212
+ const waited = await throttleDispatch({ intervalMs: 20_000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
213
+ assert.equal(waited, 19_500);
214
+ assert.deepEqual(clock.slept, [15_000, 4_500], "first nap capped at MAX_HOLD_MS, remainder re-queued");
215
+ assert.equal(JSON.parse(await readFile(c.statePath, "utf-8")).ts, 30_000);
216
+ assert.equal(existsSync(c.lockPath), false);
217
+ });
218
+
219
+ it("wrong-typed ts (string/object) is corrupt → immediate dispatch, no NaN/hot loop", async () => {
220
+ const c = await freshCtx();
221
+ await writeFile(c.statePath, JSON.stringify({ ts: "12345" }));
222
+ const clock = fakeClock();
223
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
224
+ assert.equal(waited, 0, "string ts → dispatch now");
225
+ assert.deepEqual(clock.slept, []);
226
+ assert.equal(JSON.parse(await readFile(c.statePath, "utf-8")).ts, 10_000, "state rewritten with numeric ts");
227
+
228
+ await writeFile(c.statePath, JSON.stringify({ ts: { nested: true } }));
229
+ const clock2 = fakeClock();
230
+ const waited2 = await throttleDispatch({ intervalMs: 1000, statePath: c.statePath, lockPath: c.lockPath, ...clock2 });
231
+ assert.equal(waited2, 0, "object ts → dispatch now");
232
+ assert.deepEqual(clock2.slept, []);
233
+ });
234
+
235
+ it("fresh agent dir (missing parents) is created before the lock is claimed", async () => {
236
+ const root = await mkdtemp(join(tmpdir(), "zai-throttle-fresh-"));
237
+ const statePath = join(root, "does", "not", "exist", "zai-anthropic-dispatch.json");
238
+ const lockPath = join(root, "does", "not", "exist", ".zai-anthropic-dispatch.lock");
239
+ try {
240
+ const waited = await throttleDispatch({ intervalMs: 1000, statePath, lockPath });
241
+ assert.equal(waited, 0);
242
+ assert.ok(existsSync(statePath), "state written — throttle is not a permanent silent no-op");
243
+ assert.equal(existsSync(lockPath), false);
244
+ } finally {
245
+ await rm(root, { recursive: true, force: true });
246
+ }
247
+ });
248
+
249
+ it("release() deletes only OUR lock, never a stale-breaker's replacement", async () => {
250
+ const c = await freshCtx();
251
+ const lock = await acquireLock(c.lockPath, () => 0, (ms) => new Promise((r) => setTimeout(r, ms)));
252
+ // Simulate a stale-breaker replacing our lock while we "hold" it.
253
+ await writeFile(c.lockPath, "OTHER-PID");
254
+ await lock.release();
255
+ assert.equal(existsSync(c.lockPath), true, "foreign lock preserved");
256
+ await rm(c.lockPath, { force: true });
257
+
258
+ const mine = await acquireLock(c.lockPath, () => 0, (ms) => new Promise((r) => setTimeout(r, ms)));
259
+ assert.equal(existsSync(c.lockPath), true);
260
+ await mine.release();
261
+ assert.equal(existsSync(c.lockPath), false, "our own lock is removed");
262
+ });
263
+
264
+ it("second claim after a big-interval slot waits another full interval — no stale-break cascade (fake clock)", async () => {
265
+ const c = await freshCtx();
266
+ await writeFile(c.statePath, JSON.stringify({ ts: 10_000 }));
267
+ const clock = fakeClock(10_000);
268
+ // Claim 1: wait 20_000 in two capped holds (proves re-looping under MAX_HOLD_MS).
269
+ const first = await throttleDispatch({ intervalMs: 20_000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
270
+ assert.equal(first, 20_000);
271
+ // Claim 2 joins AFTER the big slot: must wait its own full interval
272
+ // (two more capped holds), never inherit/break anything.
273
+ const second = await throttleDispatch({ intervalMs: 20_000, statePath: c.statePath, lockPath: c.lockPath, ...clock });
274
+ assert.equal(second, 20_000);
275
+ assert.deepEqual(clock.slept, [15_000, 5_000, 15_000, 5_000]);
276
+ assert.equal(JSON.parse(await readFile(c.statePath, "utf-8")).ts, 50_000, "slot = previous slot + interval");
277
+ assert.equal(existsSync(c.lockPath), false);
278
+ });
279
+ });
280
+
281
+ describe("throttleZaiDispatch wiring", () => {
282
+ it("non-zai-anthropic provider → no-op even with default interval", async () => {
283
+ const c = await freshCtx();
284
+ const waited = await throttleZaiDispatch("openrouter", {}, { statePath: c.statePath, lockPath: c.lockPath });
285
+ assert.equal(waited, 0);
286
+ assert.equal(existsSync(c.statePath), false);
287
+ });
288
+
289
+ it("undefined provider → no-op", async () => {
290
+ const c = await freshCtx();
291
+ const waited = await throttleZaiDispatch(undefined, {}, { statePath: c.statePath, lockPath: c.lockPath });
292
+ assert.equal(waited, 0);
293
+ });
294
+
295
+ it("zai-anthropic provider claims a slot using env interval", async () => {
296
+ const c = await freshCtx();
297
+ await writeFile(c.statePath, JSON.stringify({ ts: 10_000 }));
298
+ const waited = await throttleZaiDispatch(
299
+ "ZAI-Anthropic", // case-insensitive, matches provider gating elsewhere
300
+ { [MIN_INTERVAL_ENV]: "700" },
301
+ { statePath: c.statePath, lockPath: c.lockPath },
302
+ );
303
+ void waited; // real timers; ts in the past → likely no wait — the assertion is that the gate RAN
304
+ assert.ok(existsSync(c.statePath), "state written for zai-anthropic provider");
305
+ await stat(c.statePath); // readable
306
+ assert.equal(existsSync(c.lockPath), false);
307
+ });
308
+
309
+ it("settings-resolved intervalMs override wins over the env default (0 = gate off)", async () => {
310
+ const c = await freshCtx();
311
+ const waited = await throttleZaiDispatch(
312
+ "zai-anthropic",
313
+ { [MIN_INTERVAL_ENV]: "700" },
314
+ { statePath: c.statePath, lockPath: c.lockPath },
315
+ { intervalMs: 0 },
316
+ );
317
+ assert.equal(waited, 0);
318
+ assert.equal(existsSync(c.statePath), false, "interval 0 → the gate never touches the state file");
319
+
320
+ const waited2 = await throttleZaiDispatch(
321
+ "zai-anthropic",
322
+ { [MIN_INTERVAL_ENV]: "0" },
323
+ { statePath: c.statePath, lockPath: c.lockPath },
324
+ { intervalMs: 1000 },
325
+ );
326
+ assert.equal(waited2, 0);
327
+ assert.ok(existsSync(c.statePath), "explicit 1000 overrides the env's 0");
328
+ });
329
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ceulen",
3
- "version": "0.5.1",
3
+ "version": "0.8.0",
4
4
  "description": "Ceulen — the Pi coding agent, fully dressed: one bundle extension carrying the full toolkit with a single /ceulen config command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,10 +18,21 @@
18
18
  "files": [
19
19
  "extensions",
20
20
  "skills",
21
+ "themes",
22
+ "scripts",
21
23
  "README.md",
22
24
  "LICENSE",
23
25
  "CHANGELOG.md"
24
26
  ],
27
+ "dependencies": {
28
+ "@ff-labs/fff-node": "^0.10.6",
29
+ "axios": "^1.20.0",
30
+ "gemini-reverse": "^2.1.0",
31
+ "jsdom": "^27.0.1"
32
+ },
33
+ "optionalDependencies": {
34
+ "@yuuang/ffi-rs-linux-x64-gnu": "1.3.2"
35
+ },
25
36
  "repository": {
26
37
  "type": "git",
27
38
  "url": "git+https://github.com/ceulen-dev/ceulen.git"
@@ -29,17 +40,21 @@
29
40
  "homepage": "https://github.com/ceulen-dev/ceulen#readme",
30
41
  "bugs": "https://github.com/ceulen-dev/ceulen/issues",
31
42
  "scripts": {
32
- "test": "node --import tsx --test extensions/modules/router/test/unit.test.ts extensions/modules/router/test/guard.test.ts extensions/modules/usage/test/*.test.ts extensions/modules/ponytail/test/*.test.ts extensions/modules/config/test/*.test.ts extensions/modules/composer/test/*.test.ts",
43
+ "test": "node scripts/validate-themes.mjs && node --import tsx --test extensions/lib/registry.test.ts extensions/modules/router/test/unit.test.ts extensions/modules/router/test/guard.test.ts extensions/modules/classifier/test/*.test.ts extensions/modules/advisor/test/*.test.ts extensions/modules/usage/test/*.test.ts extensions/modules/ponytail/test/*.test.ts extensions/modules/ux/test/*.test.ts extensions/modules/config/test/*.test.ts extensions/modules/composer/test/*.test.ts extensions/modules/serena/test/*.test.ts extensions/modules/fff/test/*.test.ts extensions/modules/rtk/test/*.test.js extensions/modules/munin/test/*.test.ts extensions/modules/subagent/test/*.test.ts extensions/modules/zai/test/*.test.ts extensions/modules/repair/test/*.test.ts extensions/modules/steering/test/*.test.ts extensions/modules/plan/test/*.test.ts extensions/modules/todo/test/*.test.ts extensions/modules/web/test/*.test.ts extensions/modules/rules/test/*.test.ts",
33
44
  "typecheck": "tsc --noEmit"
34
45
  },
35
46
  "pi": {
36
47
  "extensions": [
37
48
  "./extensions"
49
+ ],
50
+ "themes": [
51
+ "./themes"
38
52
  ]
39
53
  },
40
54
  "peerDependencies": {
41
- "@earendil-works/pi-coding-agent": ">=0.99.1 <0.101.0",
42
- "@earendil-works/pi-tui": ">=0.99.1 <0.101.0"
55
+ "@earendil-works/pi-coding-agent": ">=0.99.1 <1.1.0",
56
+ "@earendil-works/pi-tui": ">=0.99.1 <1.1.0",
57
+ "typebox": "*"
43
58
  },
44
59
  "devDependencies": {
45
60
  "@types/node": "^20.19.43",
@@ -0,0 +1,75 @@
1
+ // Validates every themes/*.json loads as a pi theme: name present + unique,
2
+ // not colliding with pi's builtin names (dark/light/system are preloaded and
3
+ // win dedupe), full pi-required color token set (from pi's theme-json schema),
4
+ // and every value resolving to a var ref, #RRGGBB, 256-color index, or "".
5
+ // ponytail: adapted from @bacnh85/pi-themes scripts/validate-themes.mjs (MIT).
6
+ // Usage: node scripts/validate-themes.mjs [dir] (dir defaults to ./themes)
7
+ import { readFileSync, readdirSync } from "node:fs";
8
+ import { join, dirname } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ const dir = process.argv[2]
12
+ ?? join(dirname(dirname(fileURLToPath(import.meta.url))), "themes");
13
+ const files = readdirSync(dir).filter((f) => f.endsWith(".json")).sort();
14
+ if (files.length === 0) {
15
+ console.error(`no theme files found in ${dir}`);
16
+ process.exit(1);
17
+ }
18
+
19
+ // pi's required colors token list (dist/modes/interactive/theme/theme-json.js).
20
+ const REQUIRED = [
21
+ "accent", "border", "borderAccent", "borderMuted", "success", "error",
22
+ "warning", "muted", "dim", "text", "thinkingText", "selectedBg",
23
+ "userMessageBg", "userMessageText", "customMessageBg", "customMessageText",
24
+ "customMessageLabel", "toolPendingBg", "toolSuccessBg", "toolErrorBg",
25
+ "toolTitle", "toolOutput", "mdHeading", "mdLink", "mdLinkUrl", "mdCode",
26
+ "mdCodeBlock", "mdCodeBlockBorder", "mdQuote", "mdQuoteBorder", "mdHr",
27
+ "mdListBullet", "toolDiffAdded", "toolDiffRemoved", "toolDiffContext",
28
+ "syntaxComment", "syntaxKeyword", "syntaxFunction", "syntaxVariable",
29
+ "syntaxString", "syntaxNumber", "syntaxType", "syntaxOperator",
30
+ "syntaxPunctuation", "thinkingOff", "thinkingMinimal", "thinkingLow",
31
+ "thinkingMedium", "thinkingHigh", "thinkingXhigh", "bashMode",
32
+ ];
33
+ const BUILTIN = new Set(["dark", "light", "system"]);
34
+
35
+ let failed = false;
36
+ const names = new Set();
37
+ const isColorValue = (v, vars) =>
38
+ (typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 255)
39
+ || v === ""
40
+ || /^#[0-9A-Fa-f]{6}$/.test(v)
41
+ || vars.has(v);
42
+
43
+ for (const file of files) {
44
+ let theme;
45
+ try {
46
+ theme = JSON.parse(readFileSync(join(dir, file), "utf8"));
47
+ } catch (e) {
48
+ console.error(`${file}: not valid JSON: ${e.message}`);
49
+ failed = true;
50
+ continue;
51
+ }
52
+ const fail = (msg) => {
53
+ console.error(`${file}: ${msg}`);
54
+ failed = true;
55
+ };
56
+
57
+ if (!theme.name) fail("missing name");
58
+ else if (BUILTIN.has(theme.name)) fail(`name collides with pi builtin: ${theme.name}`);
59
+ else if (names.has(theme.name)) fail(`duplicate theme name: ${theme.name}`);
60
+ else names.add(theme.name);
61
+
62
+ const colors = theme.colors ?? {};
63
+ const missing = REQUIRED.filter((k) => !(k in colors));
64
+ if (missing.length) fail(`missing required tokens: ${missing.join(", ")}`);
65
+
66
+ const vars = new Set(Object.keys(theme.vars ?? {}));
67
+ const bad = [];
68
+ for (const [k, v] of Object.entries({ ...vars.entries && theme.vars, ...colors })) {
69
+ if (!isColorValue(v, vars)) bad.push(`${k}=${JSON.stringify(v)}`);
70
+ }
71
+ if (bad.length) fail(`unresolvable values: ${bad.join(", ")}`);
72
+ }
73
+
74
+ if (failed) process.exit(1);
75
+ console.log(`themes: ${files.length} files OK`);
@@ -0,0 +1,117 @@
1
+ ---
2
+ name: munin
3
+ description: Use Munin long-term memory before non-trivial repo work, bug fixes with recurring symptoms, architecture/dependency/setup changes, and when storing durable verified knowledge for future sessions. Search, retrieve, verify, list, store, or share project knowledge across sessions. Use munin_search for pre-work context, munin_store for post-work storage. Use when the user mentions memory, recall, remember, past work, previously, store this, document this, or when work could benefit from prior project knowledge.
4
+ ---
5
+
6
+ # Munin
7
+
8
+ Munin is the canonical memory system for Pi. Use it for all memory operations — project-local and cross-project.
9
+
10
+ Use the Munin Pi extension tools to recover and preserve verified project knowledge through native Pi-native tool calls. Memory results are leads, not authority: verify them against the current repository, docs, command output, or user-provided facts before relying on them.
11
+
12
+ ## How It Works
13
+
14
+ 1. The ceulen `munin` module provides native tools: `munin_search`, `munin_get`, `munin_store`, `munin_list`, `munin_recent`, `munin_delete`, `munin_capabilities`, `munin_share`.
15
+ 2. Config lives at PROJECT level: `/config` → Memory → Munin (saved to `<repo>/.pi/settings.json` under a `munin` section). `MUNIN_API_KEY` / `MUNIN_PROJECT` / `MUNIN_BASE_URL` env vars (incl. trusted `.env.local` / `.env`) override it; a per-call `api_key`/`project`/`base_url` param overrides everything.
16
+ 3. Print readable output by default, or raw JSON via tool details.
17
+ 4. Store only durable knowledge that is verified and useful in a future session.
18
+
19
+ ## Quick Start
20
+
21
+ **Pre-work: search context:**
22
+ ```
23
+ munin_search query="auth refresh token timeout" tags="type:bug-fix,domain:auth" topK=5
24
+ ```
25
+
26
+ **Post-work: store knowledge:**
27
+ ```
28
+ munin_store
29
+ key="bug-fix/auth-refresh-timeout"
30
+ title="Auth refresh timeout fix"
31
+ content="Conclusion: The auth refresh timeout was caused by missing timeout fallback...\n\nWhy it matters: Future auth work should avoid this pattern...\n\nEvidence/verification: Verified with test_auth_refresh.py passing...\n\nAnchors: src/auth.ts:42, AuthService.refreshToken"
32
+ tags="type:bug-fix,domain:auth"
33
+ ```
34
+
35
+ **Targeted operations:**
36
+ ```
37
+ munin_search query="cache policy" tags="type:decision" topK=5
38
+ munin_get key="architecture/cache-policy"
39
+ munin_store key="setup/new-db-migration" title="..." content="..." tags="type:fact,domain:infra"
40
+ munin_list limit=20
41
+ munin_recent limit=10
42
+ ```
43
+
44
+ ## Tag Discipline
45
+
46
+ | Category | Examples | Required |
47
+ |----------|----------|----------|
48
+ | `type:` | decision, bug-fix, fact, dependency | Yes, at least one |
49
+ | `domain:` | auth, frontend, backend, infra, memory | Yes, at least one |
50
+ | `status:` | active, deprecated, experimental | Optional |
51
+ | `priority:` | high, medium, low | Optional |
52
+
53
+ ## Search Query Quality
54
+
55
+ Use **4-8 word queries** with **quoted phrases** (`"JWT TTL"`) and **capitalized entity names** (`Stripe`, `Munin`). Quoted phrases get +0.25 score boost; named entities get +0.15. **DO NOT use single-word queries** — they return noise. Example: ✅ `"EAI_AGAIN" MongoDB Atlas connection drop` — ❌ `auth`.
56
+
57
+ ## Tool Selection
58
+
59
+ | Tool | When to Use |
60
+ |------|-------------|
61
+ | `munin_search` | Targeted search with specific filters before work. |
62
+ | `munin_get` | Retrieve full content of a specific memory by key. |
63
+ | `munin_store` | Store verified knowledge with tag validation. |
64
+ | `munin_list` / `munin_recent` | Browse or audit what is stored. |
65
+ | `munin_delete` | Only when user explicitly requests removal. |
66
+ | `munin_capabilities` | Check what server features are available. |
67
+ | `munin_share` | Share memories across projects. |
68
+
69
+
70
+
71
+ ## What to Store
72
+
73
+ Store one verified concept per memory:
74
+
75
+ - Architecture or product decisions and rationale.
76
+ - Recurring bug symptoms, root causes, fixes, and verification.
77
+ - Stable setup facts, conventions, constraints, and dependency choices.
78
+ - Durable user/project preferences when they materially guide work.
79
+ - Cross-reference related memories by mentioning their keys in `content` (e.g., `See also: architecture/cache-policy`). This enables Munin's semantic search to surface related knowledge together.
80
+
81
+ Do not store:
82
+
83
+ - Secrets, credentials, tokens, private keys, or connection strings.
84
+ - Raw logs, transient task progress, temporary TODOs, or unverified guesses.
85
+ - Information already trivial to derive from repository files.
86
+
87
+ ## Workflow
88
+
89
+ **Pre-work**: `munin_search` with 4-8 word query + tags → `munin_get` promising results → verify against repo. **Post-work**: `munin_store` with conclusion + why + evidence + anchors + tags.
90
+
91
+ ## Examples
92
+
93
+ **Pre-work search for a bug:**
94
+ ```
95
+ munin_search query="auth refresh timeout error" tags="type:bug-fix,domain:auth"
96
+ → I found relevant memory: bug-fix/auth-refresh-timeout — Missing fallback caused 500ms timeout. Verified against src/auth.ts before using it.
97
+ ```
98
+
99
+ **Post-work store:**
100
+ ```
101
+ munin_store
102
+ key="architecture/cache-policy"
103
+ title="Cache policy decision"
104
+ content="Conclusion: Use LRU with 1h TTL for API responses, no-cache for auth tokens.\n\nWhy it matters: Prevents stale data and reduces backend load.\n\nEvidence/verification: Benchmarked with k6: 40% reduction in DB queries.\n\nAnchors: src/cache.ts, CachePolicy class"
105
+ tags="type:decision,domain:backend"
106
+ ```
107
+
108
+ ## Troubleshooting
109
+
110
+ - **Missing extension**: Install the ceulen bundle (`pi install npm:ceulen`) and keep the `munin` module enabled (`ceulen.disabled`).
111
+ - **Missing credentials**: Configure via `/config` → Memory → Munin (project-level `.pi/settings.json`), or set `MUNIN_API_KEY` and `MUNIN_PROJECT` in `.env.local` / environment.
112
+ - **"Project not found" errors**: Do **not** pass the `project` parameter to tool calls. It defaults to `$MUNIN_PROJECT`, which is already set correctly. Hardcoding a value like the repo directory name causes this error.
113
+ - **Tag validation failed**: Ensure at least one `type:` and one `domain:` tag. Check spelling.
114
+ - **Single-word search queries return noise**: Use 4-8 word queries with at least one quoted phrase or capitalized entity name. See "Search Query Quality" section above.
115
+ - **No results**: Try broader queries, fewer tags, or `munin_list` to see what exists.
116
+
117
+