ceulen 0.5.0 → 0.7.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 (358) hide show
  1. package/CHANGELOG.md +317 -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.ts +93 -7
  7. package/extensions/lib/tools.ts +47 -0
  8. package/extensions/lib/usage-store.ts +33 -0
  9. package/extensions/modules/advisor/commands/advisor.ts +244 -0
  10. package/extensions/modules/advisor/configPanel.ts +194 -0
  11. package/extensions/modules/advisor/index.ts +217 -0
  12. package/extensions/modules/advisor/lib/config.ts +248 -0
  13. package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
  14. package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
  15. package/extensions/modules/advisor/lib/model-picker.ts +47 -0
  16. package/extensions/modules/advisor/lib/watcher.ts +286 -0
  17. package/extensions/modules/advisor/test/compliance.test.ts +125 -0
  18. package/extensions/modules/advisor/test/config.test.ts +202 -0
  19. package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
  20. package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
  21. package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
  22. package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
  23. package/extensions/modules/advisor/test/module.test.ts +586 -0
  24. package/extensions/modules/advisor/test/watcher.test.ts +478 -0
  25. package/extensions/modules/classifier/configPanel.ts +104 -0
  26. package/extensions/modules/classifier/index.ts +297 -0
  27. package/extensions/modules/classifier/lib/settings.ts +95 -0
  28. package/extensions/modules/classifier/test/classifier.test.ts +475 -0
  29. package/extensions/modules/composer/index.ts +152 -3
  30. package/extensions/modules/composer/lib/footer.ts +119 -0
  31. package/extensions/modules/composer/lib/shapes.ts +265 -26
  32. package/extensions/modules/composer/test/editor.test.ts +1 -1
  33. package/extensions/modules/composer/test/footer.test.ts +96 -0
  34. package/extensions/modules/composer/test/module.test.ts +113 -11
  35. package/extensions/modules/composer/test/screen.test.ts +29 -1
  36. package/extensions/modules/composer/test/shapes.test.ts +224 -8
  37. package/extensions/modules/config/defaultTools.ts +96 -0
  38. package/extensions/modules/config/index.ts +147 -7
  39. package/extensions/modules/config/piSettings.ts +254 -69
  40. package/extensions/modules/config/test/defaultTools.test.ts +122 -0
  41. package/extensions/modules/config/test/menu.test.ts +64 -0
  42. package/extensions/modules/config/test/panel.test.ts +38 -23
  43. package/extensions/modules/config/test/piSettings.test.ts +130 -3
  44. package/extensions/modules/config/test/renderTools.test.ts +71 -0
  45. package/extensions/modules/config/test/tools.test.ts +146 -0
  46. package/extensions/modules/fff/index.ts +2094 -0
  47. package/extensions/modules/fff/lib/query.ts +129 -0
  48. package/extensions/modules/fff/test/index.test.ts +607 -0
  49. package/extensions/modules/fff/test/query.test.ts +71 -0
  50. package/extensions/modules/munin/configPanel.ts +105 -0
  51. package/extensions/modules/munin/index.ts +641 -0
  52. package/extensions/modules/munin/lib/helpers.ts +471 -0
  53. package/extensions/modules/munin/lib/retry.ts +20 -0
  54. package/extensions/modules/munin/lib/sdk.ts +218 -0
  55. package/extensions/modules/munin/test/config.test.ts +168 -0
  56. package/extensions/modules/munin/test/configPanel.test.ts +161 -0
  57. package/extensions/modules/munin/test/extension.test.ts +224 -0
  58. package/extensions/modules/munin/test/helpers.test.ts +523 -0
  59. package/extensions/modules/munin/test/retry.test.ts +145 -0
  60. package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
  61. package/extensions/modules/plan/configPanel.ts +152 -0
  62. package/extensions/modules/plan/index.ts +917 -0
  63. package/extensions/modules/plan/lib/plan-tools.ts +72 -0
  64. package/extensions/modules/plan/lib/prompt.ts +65 -0
  65. package/extensions/modules/plan/lib/settings.ts +166 -0
  66. package/extensions/modules/plan/lib/shell-gate.ts +200 -0
  67. package/extensions/modules/plan/test/configPanel.test.ts +96 -0
  68. package/extensions/modules/plan/test/harness.ts +133 -0
  69. package/extensions/modules/plan/test/module.test.ts +305 -0
  70. package/extensions/modules/plan/test/settings.test.ts +114 -0
  71. package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
  72. package/extensions/modules/ponytail/index.ts +23 -73
  73. package/extensions/modules/ponytail/lib/config.ts +1 -6
  74. package/extensions/modules/ponytail/test/extension.test.ts +1 -85
  75. package/extensions/modules/repair/configPanel.ts +96 -0
  76. package/extensions/modules/repair/index.ts +414 -0
  77. package/extensions/modules/repair/lib/auto-bg.ts +333 -0
  78. package/extensions/modules/repair/lib/edit-repair.ts +155 -0
  79. package/extensions/modules/repair/lib/editor.ts +251 -0
  80. package/extensions/modules/repair/lib/guards.ts +34 -0
  81. package/extensions/modules/repair/lib/input-repair.ts +324 -0
  82. package/extensions/modules/repair/lib/patch.ts +481 -0
  83. package/extensions/modules/repair/lib/settings.ts +114 -0
  84. package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
  85. package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
  86. package/extensions/modules/repair/test/editor.test.ts +141 -0
  87. package/extensions/modules/repair/test/guards.test.ts +64 -0
  88. package/extensions/modules/repair/test/input-repair.test.ts +231 -0
  89. package/extensions/modules/repair/test/patch.test.ts +563 -0
  90. package/extensions/modules/repair/test/settings.test.ts +167 -0
  91. package/extensions/modules/repair/test/wrapper.test.ts +210 -0
  92. package/extensions/modules/router/commands/commands.ts +4 -0
  93. package/extensions/modules/router/lib/client.ts +61 -0
  94. package/extensions/modules/router/lib/provider.ts +34 -13
  95. package/extensions/modules/router/lib/systemone.ts +152 -0
  96. package/extensions/modules/router/test/unit.test.ts +179 -0
  97. package/extensions/modules/rtk/findFallback.js +68 -0
  98. package/extensions/modules/rtk/index.ts +248 -0
  99. package/extensions/modules/rtk/safe-rewrite.js +74 -0
  100. package/extensions/modules/rtk/test/findFallback.test.js +66 -0
  101. package/extensions/modules/rtk/test/index.test.js +131 -0
  102. package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
  103. package/extensions/modules/rtk/version-gate.js +34 -0
  104. package/extensions/modules/serena/index.ts +629 -0
  105. package/extensions/modules/serena/lib/detect.ts +73 -0
  106. package/extensions/modules/serena/lib/env.ts +76 -0
  107. package/extensions/modules/serena/lib/guidance.ts +26 -0
  108. package/extensions/modules/serena/lib/normalize.ts +27 -0
  109. package/extensions/modules/serena/lib/symbol-key.ts +20 -0
  110. package/extensions/modules/serena/lib/truncate.ts +20 -0
  111. package/extensions/modules/serena/test/env.test.ts +122 -0
  112. package/extensions/modules/serena/test/index.test.ts +347 -0
  113. package/extensions/modules/serena/test/worker.test.ts +562 -0
  114. package/extensions/modules/serena/worker.ts +858 -0
  115. package/extensions/modules/steering/configPanel.ts +122 -0
  116. package/extensions/modules/steering/index.ts +616 -0
  117. package/extensions/modules/steering/lib/anchor.ts +175 -0
  118. package/extensions/modules/steering/lib/errors.ts +253 -0
  119. package/extensions/modules/steering/lib/family.ts +33 -0
  120. package/extensions/modules/steering/lib/guidance.ts +172 -0
  121. package/extensions/modules/steering/lib/history.ts +170 -0
  122. package/extensions/modules/steering/lib/settings.ts +127 -0
  123. package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
  124. package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
  125. package/extensions/modules/steering/test/anchor.test.ts +160 -0
  126. package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
  127. package/extensions/modules/steering/test/errors.test.ts +309 -0
  128. package/extensions/modules/steering/test/family.test.ts +43 -0
  129. package/extensions/modules/steering/test/guidance.test.ts +357 -0
  130. package/extensions/modules/steering/test/harness.ts +93 -0
  131. package/extensions/modules/steering/test/history.test.ts +118 -0
  132. package/extensions/modules/steering/test/settings.test.ts +182 -0
  133. package/extensions/modules/steering/test/status.test.ts +71 -0
  134. package/extensions/modules/steering/test/toolCall.test.ts +99 -0
  135. package/extensions/modules/subagent/agents/planner.md +14 -0
  136. package/extensions/modules/subagent/agents/reviewer.md +42 -0
  137. package/extensions/modules/subagent/agents/scout.md +47 -0
  138. package/extensions/modules/subagent/agents/tester.md +12 -0
  139. package/extensions/modules/subagent/agents/worker.md +18 -0
  140. package/extensions/modules/subagent/configPanel.ts +219 -0
  141. package/extensions/modules/subagent/index.ts +2451 -0
  142. package/extensions/modules/subagent/lib/agents.ts +408 -0
  143. package/extensions/modules/subagent/lib/background.ts +383 -0
  144. package/extensions/modules/subagent/lib/herdr.ts +1019 -0
  145. package/extensions/modules/subagent/lib/history.ts +126 -0
  146. package/extensions/modules/subagent/lib/model.ts +156 -0
  147. package/extensions/modules/subagent/lib/render.ts +335 -0
  148. package/extensions/modules/subagent/lib/result.ts +110 -0
  149. package/extensions/modules/subagent/lib/roles.ts +296 -0
  150. package/extensions/modules/subagent/lib/routing.ts +223 -0
  151. package/extensions/modules/subagent/lib/runner.ts +559 -0
  152. package/extensions/modules/subagent/lib/schema.ts +21 -0
  153. package/extensions/modules/subagent/lib/security.ts +752 -0
  154. package/extensions/modules/subagent/lib/settings.ts +159 -0
  155. package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
  156. package/extensions/modules/subagent/lib/threads.ts +135 -0
  157. package/extensions/modules/subagent/lib/types.ts +18 -0
  158. package/extensions/modules/subagent/lib/widget.ts +475 -0
  159. package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
  160. package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
  161. package/extensions/modules/subagent/test/routing.test.ts +350 -0
  162. package/extensions/modules/subagent/test/widget.test.ts +208 -0
  163. package/extensions/modules/usage/index.ts +59 -16
  164. package/extensions/modules/usage/test/genrate.test.ts +70 -0
  165. package/extensions/modules/usage/test/parsers.test.ts +13 -0
  166. package/extensions/modules/ux/UPSTREAM +24 -0
  167. package/extensions/modules/ux/index.ts +393 -0
  168. package/extensions/modules/ux/lib/audit.ts +562 -0
  169. package/extensions/modules/ux/lib/config.ts +136 -0
  170. package/extensions/modules/ux/lib/instructions.ts +77 -0
  171. package/extensions/modules/ux/test/audit.test.ts +756 -0
  172. package/extensions/modules/ux/test/extension.test.ts +394 -0
  173. package/extensions/modules/ux/test/instructions.test.ts +19 -0
  174. package/extensions/modules/web/configPanel.ts +193 -0
  175. package/extensions/modules/web/index.ts +978 -0
  176. package/extensions/modules/web/lib/agy.ts +209 -0
  177. package/extensions/modules/web/lib/brave.ts +42 -0
  178. package/extensions/modules/web/lib/cdp.ts +686 -0
  179. package/extensions/modules/web/lib/chatapi.ts +101 -0
  180. package/extensions/modules/web/lib/chatgpt.ts +796 -0
  181. package/extensions/modules/web/lib/chrome.ts +328 -0
  182. package/extensions/modules/web/lib/config.ts +136 -0
  183. package/extensions/modules/web/lib/content.ts +99 -0
  184. package/extensions/modules/web/lib/crawl4ai.ts +172 -0
  185. package/extensions/modules/web/lib/extract.ts +235 -0
  186. package/extensions/modules/web/lib/firecrawl.ts +56 -0
  187. package/extensions/modules/web/lib/format.ts +197 -0
  188. package/extensions/modules/web/lib/gemini-auth.ts +286 -0
  189. package/extensions/modules/web/lib/gemini-dr.ts +338 -0
  190. package/extensions/modules/web/lib/gemini.ts +551 -0
  191. package/extensions/modules/web/lib/imageapi.ts +559 -0
  192. package/extensions/modules/web/lib/retry.ts +71 -0
  193. package/extensions/modules/web/lib/search.ts +237 -0
  194. package/extensions/modules/web/lib/searxng.ts +69 -0
  195. package/extensions/modules/web/lib/settings.ts +148 -0
  196. package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
  197. package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
  198. package/extensions/modules/web/test/agy.test.ts +383 -0
  199. package/extensions/modules/web/test/cdp.test.ts +717 -0
  200. package/extensions/modules/web/test/chat.test.ts +171 -0
  201. package/extensions/modules/web/test/chatgpt.test.ts +633 -0
  202. package/extensions/modules/web/test/chrome.test.ts +282 -0
  203. package/extensions/modules/web/test/config.test.ts +218 -0
  204. package/extensions/modules/web/test/configPanel.test.ts +132 -0
  205. package/extensions/modules/web/test/crawl.test.ts +134 -0
  206. package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
  207. package/extensions/modules/web/test/extension.test.ts +118 -0
  208. package/extensions/modules/web/test/extract.test.ts +436 -0
  209. package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
  210. package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
  211. package/extensions/modules/web/test/fixtures/interaction.html +31 -0
  212. package/extensions/modules/web/test/format.test.ts +230 -0
  213. package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
  214. package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
  215. package/extensions/modules/web/test/gemini.test.ts +472 -0
  216. package/extensions/modules/web/test/hook.test.ts +101 -0
  217. package/extensions/modules/web/test/image.test.ts +1089 -0
  218. package/extensions/modules/web/test/retry.test.ts +119 -0
  219. package/extensions/modules/web/test/screenshot.test.ts +109 -0
  220. package/extensions/modules/web/test/search.test.ts +210 -0
  221. package/extensions/modules/web/test/settings.test.ts +165 -0
  222. package/extensions/modules/web/test/skill.test.ts +72 -0
  223. package/extensions/modules/web/types.d.ts +3 -0
  224. package/extensions/modules/web/vendor/package.json +1 -0
  225. package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
  226. package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
  227. package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
  228. package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
  229. package/extensions/modules/web/vendor/readability/index.js +9 -0
  230. package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
  231. package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
  232. package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
  233. package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
  234. package/extensions/modules/zai/configPanel.ts +151 -0
  235. package/extensions/modules/zai/index.ts +186 -0
  236. package/extensions/modules/zai/lib/anthropic.ts +159 -0
  237. package/extensions/modules/zai/lib/settings.ts +198 -0
  238. package/extensions/modules/zai/lib/signing.ts +718 -0
  239. package/extensions/modules/zai/lib/throttle.ts +198 -0
  240. package/extensions/modules/zai/test/anthropic.test.ts +132 -0
  241. package/extensions/modules/zai/test/configPanel.test.ts +207 -0
  242. package/extensions/modules/zai/test/extension.test.ts +249 -0
  243. package/extensions/modules/zai/test/settings.test.ts +183 -0
  244. package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
  245. package/extensions/modules/zai/test/signing.test.ts +345 -0
  246. package/extensions/modules/zai/test/throttle.test.ts +329 -0
  247. package/package.json +19 -4
  248. package/scripts/validate-themes.mjs +75 -0
  249. package/skills/munin/SKILL.md +117 -0
  250. package/skills/ux-capture/SKILL.md +202 -0
  251. package/skills/ux-design/SKILL.md +279 -0
  252. package/skills/ux-presets/SKILL.md +484 -0
  253. package/skills/ux-routing/SKILL.md +46 -0
  254. package/skills/web/SKILL.md +153 -0
  255. package/themes/alabaster.json +93 -0
  256. package/themes/amethyst.json +96 -0
  257. package/themes/anthracite.json +93 -0
  258. package/themes/basalt.json +91 -0
  259. package/themes/birch.json +95 -0
  260. package/themes/catppuccin-mocha.json +91 -0
  261. package/themes/dark-abyss.json +91 -0
  262. package/themes/dark-arctic.json +104 -0
  263. package/themes/dark-aurora.json +95 -0
  264. package/themes/dark-catppuccin.json +107 -0
  265. package/themes/dark-cavern.json +91 -0
  266. package/themes/dark-celestial.json +106 -0
  267. package/themes/dark-copper.json +95 -0
  268. package/themes/dark-cosmos.json +90 -0
  269. package/themes/dark-cyberpunk.json +102 -0
  270. package/themes/dark-dracula.json +98 -0
  271. package/themes/dark-eclipse.json +91 -0
  272. package/themes/dark-ember.json +95 -0
  273. package/themes/dark-equinox.json +90 -0
  274. package/themes/dark-forest.json +96 -0
  275. package/themes/dark-github.json +105 -0
  276. package/themes/dark-gruvbox.json +112 -0
  277. package/themes/dark-lavender.json +95 -0
  278. package/themes/dark-lunar.json +89 -0
  279. package/themes/dark-midnight.json +95 -0
  280. package/themes/dark-monochrome.json +94 -0
  281. package/themes/dark-monokai.json +98 -0
  282. package/themes/dark-nebula.json +90 -0
  283. package/themes/dark-neon-noir.json +100 -0
  284. package/themes/dark-nord.json +98 -0
  285. package/themes/dark-ocean.json +101 -0
  286. package/themes/dark-one.json +100 -0
  287. package/themes/dark-poimandres.json +115 -0
  288. package/themes/dark-rainforest.json +91 -0
  289. package/themes/dark-reef.json +91 -0
  290. package/themes/dark-retro.json +92 -0
  291. package/themes/dark-rose-pine.json +96 -0
  292. package/themes/dark-sakura.json +95 -0
  293. package/themes/dark-slate.json +95 -0
  294. package/themes/dark-solarized.json +97 -0
  295. package/themes/dark-solstice.json +90 -0
  296. package/themes/dark-starfall.json +91 -0
  297. package/themes/dark-sunset.json +99 -0
  298. package/themes/dark-swamp.json +90 -0
  299. package/themes/dark-synthwave.json +103 -0
  300. package/themes/dark-taiga.json +91 -0
  301. package/themes/dark-terminal.json +95 -0
  302. package/themes/dark-tokyo-night.json +101 -0
  303. package/themes/dark-tundra.json +91 -0
  304. package/themes/dark-twilight.json +91 -0
  305. package/themes/dark-volcanic.json +91 -0
  306. package/themes/dark.json +80 -0
  307. package/themes/graphite.json +92 -0
  308. package/themes/light-arctic.json +107 -0
  309. package/themes/light-aurora-day.json +91 -0
  310. package/themes/light-canyon.json +91 -0
  311. package/themes/light-catppuccin.json +106 -0
  312. package/themes/light-cirrus.json +90 -0
  313. package/themes/light-coral.json +95 -0
  314. package/themes/light-cyberpunk.json +96 -0
  315. package/themes/light-dawn.json +90 -0
  316. package/themes/light-dunes.json +91 -0
  317. package/themes/light-eucalyptus.json +95 -0
  318. package/themes/light-forest.json +100 -0
  319. package/themes/light-frost.json +95 -0
  320. package/themes/light-github.json +115 -0
  321. package/themes/light-glacier.json +91 -0
  322. package/themes/light-gruvbox.json +108 -0
  323. package/themes/light-haze.json +90 -0
  324. package/themes/light-honeycomb.json +95 -0
  325. package/themes/light-lagoon.json +91 -0
  326. package/themes/light-lavender.json +95 -0
  327. package/themes/light-meadow.json +91 -0
  328. package/themes/light-mint.json +95 -0
  329. package/themes/light-monochrome.json +101 -0
  330. package/themes/light-ocean.json +99 -0
  331. package/themes/light-one.json +99 -0
  332. package/themes/light-opal.json +91 -0
  333. package/themes/light-orchard.json +91 -0
  334. package/themes/light-paper.json +95 -0
  335. package/themes/light-poimandres.json +115 -0
  336. package/themes/light-prism.json +90 -0
  337. package/themes/light-retro.json +98 -0
  338. package/themes/light-sand.json +95 -0
  339. package/themes/light-savanna.json +91 -0
  340. package/themes/light-solarized.json +102 -0
  341. package/themes/light-soleil.json +90 -0
  342. package/themes/light-sunset.json +99 -0
  343. package/themes/light-synthwave.json +98 -0
  344. package/themes/light-tokyo-night.json +111 -0
  345. package/themes/light-wetland.json +91 -0
  346. package/themes/light-zenith.json +89 -0
  347. package/themes/light.json +80 -0
  348. package/themes/limestone.json +94 -0
  349. package/themes/mahogany.json +97 -0
  350. package/themes/marble.json +93 -0
  351. package/themes/mirage.json +79 -0
  352. package/themes/obsidian.json +91 -0
  353. package/themes/onyx.json +91 -0
  354. package/themes/pearl.json +93 -0
  355. package/themes/porcelain.json +91 -0
  356. package/themes/quartz.json +96 -0
  357. package/themes/sandstone.json +95 -0
  358. package/themes/titanium.json +90 -0
@@ -0,0 +1,72 @@
1
+ // ponytail: vendored from @bacnh85/pi-plan 0.16.6 (extensions/lib/plan-tools.ts),
2
+ // trimmed to ceulen's tool surface (subagent/webfetch-era tools and the
3
+ // flow-review tooling are gone). Keep in sync when a ceulen module adds a
4
+ // mutating tool — a new mutator MUST land in BLOCKED_TOOLS, not the confirm tier.
5
+
6
+ /** Known read-only/research tools auto-allowed in plan mode. Tools not in this
7
+ * set require confirmation (or a hard block when they are mutators). */
8
+ export const READ_ONLY_TOOLS = new Set([
9
+ // Built-in reads
10
+ "read", "grep", "find", "ls",
11
+ // Plan tools (path-constrained to the plans dir, safe in plan mode)
12
+ "write_plan", "ask_user_question",
13
+ // FFF tools
14
+ "ffgrep", "fffind", "fff_multi_grep", "resolve_file", "related_files",
15
+ // Serena read-only
16
+ "serena_status", "serena_list_tools", "serena_get_current_config",
17
+ "serena_check_onboarding_performed", "serena_get_symbols_overview", "serena_find_symbol",
18
+ "serena_find_declaration", "serena_find_implementations", "serena_find_referencing_symbols",
19
+ "serena_search_for_pattern", "serena_get_diagnostics_for_file",
20
+ // Munin read-only
21
+ "munin_search", "munin_get", "munin_list", "munin_recent", "munin_capabilities",
22
+ // Advisor returns guidance only; it has no filesystem tools.
23
+ "advisor",
24
+ // ux_audit is pure computation over a CSS string — no fs/network side effects.
25
+ "ux_audit",
26
+ // Decision model: typed questions about caller-supplied state, no side effects.
27
+ "classify",
28
+ // NOTE: herdr is deliberately NOT here — its prompt action can drive a
29
+ // write-capable child, so every herdr call takes the confirm tier.
30
+ ]);
31
+
32
+ /** Tools that are never available in plan mode — direct source/system mutators. */
33
+ export const BLOCKED_TOOLS = new Set([
34
+ // File mutation
35
+ "edit", "write",
36
+ // Diff-style file mutation — same treatment as edit/write.
37
+ "apply_patch",
38
+ // File editor (create/str_replace/insert) — a direct source mutator like edit/write.
39
+ "str_replace_editor",
40
+ // Serena file mutation (restart/onboarding tools are state-changing but no
41
+ // source mutation — they stay at the confirm tier by omission from READ_ONLY)
42
+ "serena_replace_symbol_body", "serena_insert_before_symbol",
43
+ "serena_insert_after_symbol", "serena_rename_symbol",
44
+ "serena_safe_delete_symbol", "serena_replace_content",
45
+ // Munin mutation
46
+ "munin_store", "munin_delete", "munin_share",
47
+ ]);
48
+
49
+ /** First-token set: interpreters/wrappers run arbitrary payloads, so their
50
+ * session-scoped allow key must be the FULL command, not the first token. */
51
+ export const INTERPRETER_TOKENS = new Set([
52
+ "node", "npx", "python", "python3", "bash", "sh", "zsh", "deno", "bun",
53
+ "make", "cargo", "go", "ruby", "perl", "awk", "eval",
54
+ ]);
55
+
56
+ /** Tools whose mutations are gated by another extension's own parameter
57
+ * (subagent): plan mode allows the call only when EVERY named agent resolves
58
+ * read-only, else it takes the confirm tier. */
59
+ export function extractSubagentNames(input: unknown): string[] {
60
+ if (!input || typeof input !== "object") return [];
61
+ const obj = input as Record<string, unknown>;
62
+ const names: string[] = [];
63
+ if (typeof obj.agent === "string") names.push(obj.agent);
64
+ if (Array.isArray(obj.tasks)) for (const t of obj.tasks) if (t && typeof t === "object" && typeof (t as { agent?: unknown }).agent === "string") names.push((t as { agent: string }).agent);
65
+ if (Array.isArray(obj.chain)) for (const c of obj.chain) if (c && typeof c === "object" && typeof (c as { agent?: unknown }).agent === "string") names.push((c as { agent: string }).agent);
66
+ return [...new Set(names)];
67
+ }
68
+
69
+ /** Guidance appended to the plan-mode system prompt (Serena/FFF-first research
70
+ * and what auto-runs vs. prompts). */
71
+ export const PLAN_MODE_RESEARCH_GUIDANCE =
72
+ "Tool selection for code research: for source files, symbols, functions, classes, declarations, references, implementations, and refactors, use Serena before raw reads/searches. Use serena_get_symbols_overview for source-file outlines; serena_find_symbol for named functions/classes/methods/variables; serena_find_referencing_symbols before behavior changes or renames; and serena_find_declaration / serena_find_implementations for definitions, interfaces, and implementations. Use read for docs/config/non-code files, exact line ranges, or after Serena identifies the relevant code region. Prefer the dedicated ls/ffgrep/fffind tools over shell commands; fall back to grep/find when the fff tools are unavailable. Strict single read-only shell commands run automatically; test, build, and package scripts require confirmation because they may modify files. Pipelines and chains of read-only commands (ls, grep, find, cat, head, tail, jq, print-only sed, xargs over read tools, tar -t/-xO, read-only git subcommands) plus cd && chains and VAR=value prefixes run without prompting; $(), backticks, file redirects, heredocs, interpreters like python3 -c / node -e, and test/build/package scripts prompt or hard-block — keep research to the auto-run forms.";
@@ -0,0 +1,65 @@
1
+ // Plan-mode system prompt. The content spec is adapted from OMP's
2
+ // plan-mode-active.md (decision-complete plans, no decision-free sections);
3
+ // the tool rules are ceulen's (write_plan + ask_user_question + the research
4
+ // guidance). Kept as a pure function so tests can assert the contract.
5
+ import { PLAN_MODE_RESEARCH_GUIDANCE } from "./plan-tools.js";
6
+
7
+ export interface PlanPromptInput {
8
+ /** Expanded plans dir (prompt-visible), e.g. `.pi/plans`. */
9
+ plansDir: string;
10
+ /** Next/current plan path relative to cwd, or the would-be pattern. */
11
+ relativePlan: string;
12
+ /** true when the plan file is written to disk only at approval. */
13
+ deferredSave: boolean;
14
+ /** true when plans are never persisted. */
15
+ noSave: boolean;
16
+ /** Autonomous approval is armed — execution starts without a keypress. */
17
+ autoApprove: boolean;
18
+ }
19
+
20
+ const PLAN_TOOL = "write_plan";
21
+ const ASK_TOOL = "ask_user_question";
22
+
23
+ export function buildPlanModePrompt(input: PlanPromptInput): string {
24
+ const saveLine = input.noSave
25
+ ? `Plans are not persisted to disk in this setup — write_plan returns the plan inline and the transcript is the only copy.`
26
+ : input.deferredSave
27
+ ? `The plan file is written to ${input.plansDir}/ only when the plan is approved — until then the plan text returned by write_plan is the reviewable copy.`
28
+ : `The plan file is written to ${input.plansDir}/. Current/next plan path: ${input.relativePlan}`;
29
+ const autoLine = input.autoApprove
30
+ ? `\n- Autonomous approval is ARMED: after ${PLAN_TOOL} writes the plan, execution starts in this session without user input. Do not tell the user to press Enter or run /plan-approve; state that execution starts automatically.`
31
+ : `\n- Do not use ${ASK_TOOL} to offer approve / execute / implement options. Execution is initiated only by /plan-approve (prefilled after the plan is written); ${ASK_TOOL} is for unresolved clarifying questions only.`;
32
+
33
+ return `
34
+
35
+ ## Plan Mode
36
+
37
+ You are in read-only planning mode. Research the codebase and produce a reviewable, decision-complete implementation plan before making changes.
38
+
39
+ Rules:
40
+ - Do not edit source files, configs, lockfiles, or git state.
41
+ - You may read files, search, inspect git state, and use dedicated read/research tools.
42
+ - Bash commands that write to files (redirect, heredoc, sed -i, tee, cp/mv/rm, etc.) or contain command substitution are hard-blocked. Read-only bash commands (ls, grep, find, git status) run automatically — including pipelines/chains whose every segment is read-only (e.g. \`grep foo src | head\`). Test/build/package scripts and other unknown executables require confirmation.
43
+ - ${PLAN_MODE_RESEARCH_GUIDANCE}
44
+ - Ask concise clarifying questions if requirements are ambiguous. Use ${ASK_TOOL} for consequential open decisions with 2-4 clear options, a recommended default, and an Other/user-opinion path.
45
+ - Do not ask about details you can discover from repository evidence. If the user already gave an opinion, incorporate it instead of asking again.
46
+ - Before calling ${PLAN_TOOL}, if any consequential, user-answerable decision remains, call ${ASK_TOOL} and wait for the answer. Do not place blocking user decisions in the final plan as open questions.${autoLine}
47
+ - When the plan is ready, call ${PLAN_TOOL} with a complete Markdown plan.
48
+ - ${saveLine}
49
+ - Goal: honor active system/project/skill constraints. Choose the smallest complete implementation — reuse existing code, stdlib, and native features before adding abstractions.
50
+
51
+ ## What a plan is
52
+
53
+ A plan is an execution spec, not a design doc. Approval may hand it to a fresh session with none of this conversation; a competent implementer unfamiliar with the discussion MUST be able to execute it top-to-bottom with ZERO design decisions. Every choice is made in the file. Decision-completeness beats brevity.
54
+
55
+ Ground every claim: resolve discoverable facts (paths, symbols, signatures, configs) by reading the repository now. Mark anything you could not confirm inline as \`unverified — confirm first\`; never state guesses as settled.
56
+
57
+ Plan content:
58
+ 1. **Context** — the literal ask, the need, the intended end state (2-4 sentences). Every requested outcome maps to a step; add nothing beyond the ask.
59
+ 2. **Approach** — load-bearing ordered steps, grouped by behavior, never by file. Each step names a concrete edit (verb, exact target, new behavior), existing functions/utilities to reuse with paths, exact signatures/call sites/literals for new or changed symbols, and error/empty/conflict handling for every new path — or say why none is needed. Order so the tree builds and existing tests pass after each step.
60
+ 3. **Critical files & anchors** — at most 5 files that disambiguate non-obvious work: path, symbol/region, one-line reason.
61
+ 4. **Verification** — end-to-end proof with at least one new-behavior check: concrete input → expected observable output (not just a build or the existing suite). Exact commands and prerequisites.
62
+ 5. **Assumptions & contingencies** — only user-overridable decisions, each with a pre-decided fallback (\`if reality is X, do Y instead\`) so the implementer never stalls.
63
+
64
+ Do not include these decision-free sections: Non-Goals, Out of Scope, Alternatives Considered, Risks/Mitigations, Future Work. A material scope boundary is one inline line at the temptation point. Do not plan mechanical cleanup tails (changelog/release notes, doc updates, formatter runs).`;
65
+ }
@@ -0,0 +1,166 @@
1
+ // plan settings — the `plan` section of the agent-dir settings.json, overlaid
2
+ // by a TRUSTED project `.pi/settings.json` `plan` section.
3
+ //
4
+ // Read per event (before_agent_start / tool_call) so a /config save needs no
5
+ // /reload; the trusted project file is only eligible when the repo is trusted.
6
+ //
7
+ // "plan": {
8
+ // "plansDir": ".pi/plans", // default; {yyyymm} expands to the UTC month
9
+ // "savePlans": "all", // all | approved | none — which plans hit disk
10
+ // "planModel": "", // provider/id applied only in plan mode
11
+ // "planThinking": "", // thinking level applied only in plan mode
12
+ // "autoApprove": false // approve a written plan and execute without a keypress
13
+ // }
14
+
15
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
16
+ import os from "node:os";
17
+ import path from "node:path";
18
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
19
+
20
+ /** Which plans are written to disk. `all`: every write_plan persists;
21
+ * `approved`: drafts stay in memory, the file is written at approval;
22
+ * `none`: plans never touch disk. */
23
+ export type SavePlans = "all" | "approved" | "none";
24
+
25
+ export const SAVE_PLANS_VALUES: readonly SavePlans[] = ["all", "approved", "none"];
26
+
27
+ /** Thinking levels accepted for `plan.planThinking` (pi's level set). */
28
+ export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
29
+ export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
30
+
31
+ export function isThinkingLevel(value: string): value is ThinkingLevel {
32
+ return (THINKING_LEVELS as readonly string[]).includes(value);
33
+ }
34
+
35
+ export interface PlanSettings {
36
+ plansDir: string;
37
+ savePlans: SavePlans;
38
+ planModel: string;
39
+ planThinking: string;
40
+ autoApprove: boolean;
41
+ }
42
+
43
+ export const DEFAULT_PLANS_DIR = ".pi/plans";
44
+
45
+ export const DEFAULT_PLAN_SETTINGS: PlanSettings = {
46
+ plansDir: DEFAULT_PLANS_DIR,
47
+ savePlans: "all",
48
+ planModel: "",
49
+ planThinking: "",
50
+ autoApprove: false,
51
+ };
52
+
53
+ /** Expanded plans dir (relative to the repo cwd). `{yyyymm}` is UTC-month. */
54
+ export function expandPlansDir(dir: string, d: Date = new Date()): string {
55
+ return dir.replace("{yyyymm}", d.toISOString().slice(0, 7).replace("-", ""));
56
+ }
57
+
58
+ export function isSavePlans(value: unknown): value is SavePlans {
59
+ return typeof value === "string" && (SAVE_PLANS_VALUES as readonly string[]).includes(value);
60
+ }
61
+
62
+ function agentDir(): string {
63
+ return process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), ".pi", "agent");
64
+ }
65
+
66
+ function globalSettingsPath(): string {
67
+ return path.join(agentDir(), "settings.json");
68
+ }
69
+
70
+ /** <cwd>/.pi/settings.json — the trusted project overlay. */
71
+ export function projectSettingsPath(cwd: string): string {
72
+ return path.join(cwd, ".pi", "settings.json");
73
+ }
74
+
75
+ function readJson(file: string): Record<string, unknown> | null {
76
+ try {
77
+ if (!existsSync(file)) return null;
78
+ return JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>;
79
+ } catch {
80
+ return null; // unreadable/corrupt → this layer contributes nothing
81
+ }
82
+ }
83
+
84
+ function section(json: Record<string, unknown> | null): Record<string, unknown> {
85
+ const raw = json?.plan;
86
+ return raw && typeof raw === "object" && !Array.isArray(raw) ? (raw as Record<string, unknown>) : {};
87
+ }
88
+
89
+ /** Merge one settings layer's `plan` keys into out. */
90
+ function mergeLayer(out: PlanSettings, json: Record<string, unknown> | null): void {
91
+ const s = section(json);
92
+ if (typeof s.plansDir === "string" && s.plansDir.trim()) out.plansDir = s.plansDir.trim();
93
+ if (isSavePlans(s.savePlans)) out.savePlans = s.savePlans;
94
+ if (typeof s.planModel === "string") out.planModel = s.planModel.trim();
95
+ if (typeof s.planThinking === "string") out.planThinking = s.planThinking.trim();
96
+ if (typeof s.autoApprove === "boolean") out.autoApprove = s.autoApprove;
97
+ }
98
+
99
+ /** Effective plan settings: defaults ← global ← trusted project overlay. */
100
+ export function readPlanSettings(ctx?: Pick<ExtensionContext, "cwd" | "isProjectTrusted">): PlanSettings {
101
+ const out: PlanSettings = { ...DEFAULT_PLAN_SETTINGS };
102
+ mergeLayer(out, readJson(globalSettingsPath()));
103
+ try {
104
+ if (ctx?.cwd && ctx.isProjectTrusted?.()) mergeLayer(out, readJson(projectSettingsPath(ctx.cwd)));
105
+ } catch {
106
+ /* untrusted or no ctx — global only */
107
+ }
108
+ return out;
109
+ }
110
+
111
+ /** Read-modify-write `plan` fields into the GLOBAL settings.json (merge, never
112
+ * clobber; atomic tmp+rename; a corrupt file refuses to clobber). Returns the
113
+ * written path. Exported for tests. */
114
+ export function writePlanSection(patch: Partial<PlanSettings>): string {
115
+ const file = globalSettingsPath();
116
+ let settings: Record<string, unknown>;
117
+ try {
118
+ settings = existsSync(file) ? (JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>) : {};
119
+ } catch {
120
+ // Corrupt ≠ missing: writing here would replace the whole file with ONLY
121
+ // the plan section — bail instead.
122
+ throw new Error(`${file} is not valid JSON — fix or remove it before saving.`);
123
+ }
124
+ const s = (settings.plan ?? {}) as Record<string, unknown>;
125
+ for (const [key, value] of Object.entries(patch)) {
126
+ if (value === undefined) continue;
127
+ s[key] = typeof value === "string" ? value.trim() : value;
128
+ }
129
+ settings.plan = s;
130
+ mkdirSync(path.dirname(file), { recursive: true });
131
+ const tmp = file + ".tmp";
132
+ writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
133
+ renameSync(tmp, file);
134
+ return file;
135
+ }
136
+
137
+ /** True when a trusted project file carries its own `plan` section (the panel
138
+ * then discloses that those values override the global save). */
139
+ export function projectOverridesPlan(cwd: string, trusted: boolean): boolean {
140
+ if (!trusted) return false;
141
+ return Object.keys(section(readJson(projectSettingsPath(cwd)))).length > 0;
142
+ }
143
+
144
+ /** Resolved plan file path for a title under the configured dir. */
145
+ export function planPath(cwd: string, title: string, plansDir: string = DEFAULT_PLANS_DIR): string {
146
+ const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "plan";
147
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
148
+ return path.join(cwd, expandPlansDir(plansDir), `${stamp}-${slug}.md`);
149
+ }
150
+
151
+ /** True when `resolved` is a file inside the configured plans dir; `{yyyymm}`
152
+ * matches any single path segment so monthly subfolders stay inside. */
153
+ export function isInsidePlansDir(resolved: string, plansDir: string, cwd: string): boolean {
154
+ const pattern = path.resolve(cwd, plansDir).split(/[\\/]/).filter(Boolean);
155
+ const actual = path.resolve(cwd, resolved).split(/[\\/]/).filter(Boolean);
156
+ const wildcard = pattern.indexOf("{yyyymm}");
157
+ const root = wildcard === -1 ? pattern : pattern.filter((seg) => seg !== "{yyyymm}");
158
+ if (actual.length <= root.length) return false;
159
+ if (wildcard !== -1) actual.splice(wildcard, 1);
160
+ return root.every((seg, i) => actual[i] === seg);
161
+ }
162
+
163
+ /** Relative path with forward slashes (prompt text). */
164
+ export function relativeToCwd(cwd: string, absolutePath: string): string {
165
+ return path.relative(cwd, absolutePath).split(path.sep).join("/");
166
+ }
@@ -0,0 +1,200 @@
1
+ // ponytail: vendored from @bacnh85/pi-plan 0.16.6 (extensions/index.ts, command
2
+ // classification) — hardened against ~14 days of live false-block analysis, so
3
+ // keep the rules byte-faithful. Local changes: exported standalone functions,
4
+ // no plan/file state.
5
+ //
6
+ // Classifies one shell command for plan mode WITHOUT attempting to interpret
7
+ // arbitrary executables:
8
+ // read — provably no filesystem writes → auto-run
9
+ // write — provably mutates → hard-block
10
+ // confirm — unknown executable → approval prompt
11
+ import { execFile } from "node:child_process";
12
+
13
+ export type CommandDisposition = "read" | "write" | "confirm";
14
+
15
+ /** Split a shell command on separators (; & | and raw line breaks) that are OUTSIDE quotes. */
16
+ export function splitShellSegments(cmd: string): string[] {
17
+ const segments: string[] = [];
18
+ let cur = "";
19
+ let quote: "'" | '"' | null = null;
20
+ for (let i = 0; i < cmd.length; i++) {
21
+ const ch = cmd[i];
22
+ if (quote) {
23
+ cur += ch;
24
+ if (ch === quote) quote = null;
25
+ } else if (ch === "'" || ch === '"') {
26
+ quote = ch;
27
+ cur += ch;
28
+ } else if (/[;&|\r\n]/.test(ch)) {
29
+ if (cur.trim()) segments.push(cur.trim());
30
+ cur = "";
31
+ } else {
32
+ cur += ch;
33
+ }
34
+ }
35
+ if (cur.trim()) segments.push(cur.trim());
36
+ return segments;
37
+ }
38
+
39
+ // Read-only git subcommands auto-allowed in plan mode. Anything not matched here
40
+ // falls through to "write" (hard-blocked) — the conservative default.
41
+ const GIT_PREFIX = "^git\\s+(?:-C\\s+(?:\"[^\"]*\"|'[^']*'|\\S+)\\s+|-c\\s+\\S+=(?:\"[^\"]*\"|\\S+)\\s+|--no-pager\\s+)*";
42
+ const GIT_READ_ONLY = new RegExp(`${GIT_PREFIX}(?:status|rev-parse|diff|show|log|ls-files|ls-tree|ls-remote|cat-file|rev-list|shortlog|describe|for-each-ref|show-ref|symbolic-ref|name-rev|blame|annotate)\\b`, "i");
43
+ const GIT_BRANCH_READ_ONLY = new RegExp(`${GIT_PREFIX}branch\\s+(?:-[va]+|--(?:list|all|remote|merged|no-merged|contains|show-current))\\b`, "i");
44
+ const GIT_TAG_READ_ONLY = new RegExp(`${GIT_PREFIX}tag\\s+(?:--list\\b|-\\w*l\\b)`, "i");
45
+ const GIT_REMOTE_READ_ONLY = new RegExp(`${GIT_PREFIX}remote(?:\\s+(?:-[va]+|show\\b|get-url\\b)[^\\n]*)?$`, "i");
46
+ const GIT_CONFIG_READ_ONLY = new RegExp(`${GIT_PREFIX}config\\s+(?:--(?:get|get-regexp|get-all|list)|-l)\\b`, "i");
47
+ const GIT_REFLOG_READ_ONLY = new RegExp(`${GIT_PREFIX}reflog(?:\\s+show\\b.*)?$`, "i");
48
+ const GIT_EXTERNAL_DRIVER = /(?:\s--(?!no-)(?:ext-diff|textconv)\b)|(?:\s-c\s+["']?diff\.)/i;
49
+
50
+ // Patch-rendering subcommands run configured diff drivers (textconv is
51
+ // default-on for diff/show/log -p/blame when a repo .gitattributes names a
52
+ // driver the user's gitconfig defines). GIT_EXTERNAL_DRIVER catches only the
53
+ // flag-invited forms; when a driver is actually configured in this repo, these
54
+ // subcommands drop to the confirm tier unless the run explicitly disables the
55
+ // drivers. Probed once per session; empty in most repos → zero behavior change.
56
+ const GIT_PATCH_SUBCOMMANDS = /^(?:git\s+(?:-C\s+\S+\s+|-c\s+\S+=\S+\s+|--no-pager\s+)*)(?:diff|show|log|blame|annotate)\b/i;
57
+ const GIT_DRIVERS_DISABLED = /--(?:no-ext-diff|no-textconv)\b/i;
58
+ let repoHasDiffDriver = false;
59
+
60
+ export async function probeDiffDrivers(cwd: string): Promise<void> {
61
+ repoHasDiffDriver = false;
62
+ try {
63
+ const stdout = await new Promise<string>((resolve, reject) => {
64
+ execFile("git", ["config", "--get-regexp", "\\.(textconv|driver)$"], { cwd }, (err, out) => (err ? reject(err) : resolve(String(out))));
65
+ });
66
+ repoHasDiffDriver = stdout.trim().length > 0;
67
+ } catch { /* no driver configured (exit 1) or git unavailable */ }
68
+ }
69
+
70
+ function isGitReadOnly(inspection: string): boolean {
71
+ // External diff/textconv drivers execute arbitrary commands (from user
72
+ // gitconfig or injected via `-c diff.*=`); never auto-allow them as read.
73
+ if (GIT_EXTERNAL_DRIVER.test(inspection)) return false;
74
+ return GIT_READ_ONLY.test(inspection)
75
+ || GIT_BRANCH_READ_ONLY.test(inspection)
76
+ || GIT_TAG_READ_ONLY.test(inspection)
77
+ || GIT_REMOTE_READ_ONLY.test(inspection)
78
+ || GIT_CONFIG_READ_ONLY.test(inspection)
79
+ || GIT_REFLOG_READ_ONLY.test(inspection);
80
+ }
81
+
82
+ function classifyGitSegment(inspection: string, gitEnvArmed: boolean): CommandDisposition {
83
+ // GIT_* env assignments on a git command can arm GIT_EXTERNAL_DIFF, which
84
+ // executes with NO flag. Other env prefixes stay read.
85
+ if (gitEnvArmed) return "confirm";
86
+ if (!GIT_DRIVERS_DISABLED.test(inspection) && repoHasDiffDriver && GIT_PATCH_SUBCOMMANDS.test(inspection)) {
87
+ return "confirm";
88
+ }
89
+ return isGitReadOnly(inspection) ? "read" : "write";
90
+ }
91
+
92
+ // Env-assignment prefixes (`S=<file>; jq …`, `FOO=a BAR=b cmd`) set shell/env
93
+ // variables and write nothing — strip them and classify the real command.
94
+ const ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|[^\s;&|])*(?:\s+|$)/;
95
+
96
+ // Pure flow-control keywords carry no side effects; loop bodies still classify.
97
+ const FLOW_KEYWORD = /^(?:while|until|do|done)(?:\s+|$)/;
98
+
99
+ // sed read-only gate: `w` (file write), `e` (executes pattern space), -f
100
+ // (script file, uninspectable), -i (in-place) are the writers. Everything else
101
+ // is stdout-only.
102
+ const S_COMMAND_FLAGS = /s([^\w\s])(?:\\.|(?!\1)[\s\S])*?\1(?:\\.|(?!\1)[\s\S])*?\1([a-z0-9]*)/gi;
103
+
104
+ function isSedReadOnly(inspection: string): boolean {
105
+ if (/(?:^|\s)-[a-zA-Z]*[if][a-zA-Z]*\b|--in-place\b|--file\b/i.test(inspection)) return false;
106
+ if (/(?<![A-Za-z])w|w(?![A-Za-z])/i.test(inspection)) return false;
107
+ if (/(?:^|[^A-Za-z-])e(?:[\s;}]|$|['"])/i.test(inspection)) return false;
108
+ for (const m of inspection.matchAll(S_COMMAND_FLAGS)) {
109
+ if (/[ew]/i.test(m[2])) return false;
110
+ }
111
+ return true;
112
+ }
113
+
114
+ /** Strip xargs's own flags so the payload command can be classified.
115
+ * Deviation from upstream (pi-plan 0.16.6): only the long options that
116
+ * actually TAKE a value are stripped as `--opt value`; a valueless long
117
+ * option (`--null`) is stripped alone, so `xargs --null rm` yields `rm`
118
+ * (upstream ate the payload and classified the whole call as a read —
119
+ * silently auto-allowing a writer). */
120
+ const XARGS_LONG_VALUE = /^--(?:arg-file|delimiter|eof|max-args|max-chars|max-lines|max-procs|process-slot-var|replace)\s+(?:"[^"]*"|'[^']*'|\S+)\s*/i;
121
+
122
+ export function xargsPayload(inspection: string): string {
123
+ let rest = inspection.replace(/^xargs\b/i, "").trim();
124
+ for (;;) {
125
+ const next = rest
126
+ .replace(/^-[ILnPsaE]\s+(?:"[^"]*"|'[^']*'|\S+)\s*/i, "")
127
+ .replace(XARGS_LONG_VALUE, "")
128
+ .replace(/^--?[0-9A-Za-z?{}=]+\s*/, "")
129
+ .replace(/^--[a-z-]+(?:=\S*)?\s*/i, "");
130
+ if (next === rest) break;
131
+ rest = next;
132
+ }
133
+ return rest.trim();
134
+ }
135
+
136
+ export function classifySegment(seg: string): CommandDisposition {
137
+ let inspection = seg;
138
+ let gitEnvArmed = false;
139
+ for (;;) {
140
+ const stripped = inspection.replace(ENV_ASSIGNMENT, "").replace(FLOW_KEYWORD, "");
141
+ if (stripped === inspection) break;
142
+ if (/^\s*GIT_[A-Z_]*=/.test(inspection)) gitEnvArmed = true;
143
+ inspection = stripped;
144
+ }
145
+ inspection = inspection.replace(/^\S*\/(?=[^/\s]+(?:\s|$))/, "").trim();
146
+ if (!inspection) return "read"; // bare env assignment — sets a variable, writes nothing
147
+ if (/^git\s+/i.test(inspection)) {
148
+ return classifyGitSegment(inspection, gitEnvArmed);
149
+ }
150
+ // xargs executes a payload command — classify the payload, not xargs itself.
151
+ if (/^xargs\b/i.test(inspection)) {
152
+ const payload = xargsPayload(inspection);
153
+ if (!payload) return "read";
154
+ return classifySegment(payload);
155
+ }
156
+ // command/type/which: only pure executable lookups are reads. POSIX `command NAME`
157
+ // EXECUTES NAME, so bare `command` stays a writer wrapper; only `command -v/-V` is a lookup.
158
+ if (/^(?:type|which)\b/i.test(inspection) || /^command\s+-[vV]\b/i.test(inspection)) return "read";
159
+ if (/^(?:(?:rm|rmdir|mv|cp|mkdir|touch|chmod|chown|ln|install|truncate|dd|mktemp|command)|sudo|env|nohup|time)\b/i.test(inspection)) return "write";
160
+ if (/^sed\b/i.test(inspection)) {
161
+ if (/\s(?:-i\S*|--in-place(?:=\S*)?)(?:\s|$)/i.test(inspection) || /\b(?:\d+)?w\s+/i.test(inspection) || /\/w\s/i.test(inspection) || /(?:^|[^A-Za-z-])\d+w[a-zA-Z0-9.]/i.test(inspection)) return "write";
162
+ return isSedReadOnly(inspection) ? "read" : "confirm";
163
+ }
164
+ if (/^tee\b/i.test(inspection)) return "write";
165
+ // perl/ruby in-place edits are the `sed -i` equivalent.
166
+ if (/^(?:\S+\/)?(?:perl|ruby)\b/i.test(inspection) && /(?:^|\s)-[a-zA-Z]*i[a-zA-Z]*(?:[.\w]+)?(?:\s|$)/i.test(inspection)) return "write";
167
+ // tar: list (-t) and stdout-extract (-x…O) only read. Bare -x extracts to
168
+ // the filesystem → confirm; writers (-c) → confirm.
169
+ if (/^tar\b/i.test(inspection)) {
170
+ if (/--to-command\b/i.test(inspection) || /--use-compress-program\b/i.test(inspection) || /(?:^|\s)-\S*I/i.test(inspection)) return "confirm";
171
+ const letters = inspection.match(/^tar\s+(?:--\S+\s+)*-?([a-zA-Z]+)/i)?.[1]?.toLowerCase() ?? "";
172
+ const toStdout = /(?:^|\s)-(?:o\b|--to-stdout\b)/i.test(inspection);
173
+ if (letters.includes("t") || /--list\b/i.test(inspection) || (letters.includes("x") && (letters.includes("o") || toStdout))) return "read";
174
+ return "confirm";
175
+ }
176
+ if (/^find\b/i.test(inspection) && /-(?:delete|exec|execdir|ok|okdir|fprint|fprint0|fprintf|fls)\b/i.test(inspection)) return "write";
177
+ // Catch sort -o in any short-option form: standalone -o, combined -no/-on, and --output=.
178
+ if (/^sort\b/i.test(inspection) && (/(?:^|\s)-[a-zA-Z]*o[a-zA-Z]*(?:\s|=|$)/i.test(inspection) || /--output(?:=|\s)/i.test(inspection))) return "write";
179
+ // awk is a Turing-complete interpreter (system(), | getline, print>redirect) — never auto-allow.
180
+ return /^(?:rg|grep|find|fd|ls|pwd|cat|head|tail|wc|sort|uniq|cut|echo|printf|jq|strings|stat|file|du|tree|lsof|basename|dirname|realpath|cd|read|diff|cmp)\b/i.test(inspection) ? "read" : "confirm";
181
+ }
182
+
183
+ /** Classify a full (possibly compound) command. Any known writer wins; the
184
+ * whole command is read only when every segment is read. */
185
+ export function classifyCommand(cmd: string): CommandDisposition {
186
+ const c = cmd.trim();
187
+ if (!c) return "confirm";
188
+ // Redirections (stdout/stderr to files, here-docs) can create/modify files.
189
+ // Discarding forms are read-safe: n>/dev/null, n>>/dev/null and fd dups
190
+ // (2>&1, 2>&-). Command substitution and heredocs are always writes.
191
+ const cNoDiscard = c.replace(/\d*>+\s*\/dev\/null(?![\w.\/-])|\d*>&[\d-]/g, "");
192
+ if (/[<>]/.test(cNoDiscard) || /\$\(|`/.test(c) || /--output(?:=|\s)/i.test(c)) return "write";
193
+ const segments = splitShellSegments(cNoDiscard);
194
+ if (segments.length > 1) {
195
+ if (segments.some((seg) => classifySegment(seg) === "write")) return "write";
196
+ if (segments.every((seg) => classifySegment(seg) === "read")) return "read";
197
+ return "confirm";
198
+ }
199
+ return classifySegment(c);
200
+ }
@@ -0,0 +1,96 @@
1
+ // plan's /config contribution: row keys, closed-set save menu, save routing
2
+ // (only plan.* edits persist), and the project-shadow disclosure.
3
+ import assert from "node:assert/strict";
4
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { after, beforeEach, describe, it } from "node:test";
8
+ import { applyRows } from "../../../lib/panel.js";
9
+ import { buildPlanGroups, planConfig, setPlanBridge } from "../configPanel.js";
10
+ import { DEFAULT_PLAN_SETTINGS, readPlanSettings } from "../lib/settings.js";
11
+
12
+ const realAgentDir = process.env.PI_CODING_AGENT_DIR;
13
+ let AGENT: string;
14
+ let REPO: string;
15
+
16
+ beforeEach(() => {
17
+ AGENT = mkdtempSync(join(tmpdir(), "ceulen-plan-cfg-"));
18
+ REPO = mkdtempSync(join(tmpdir(), "ceulen-plan-cfg-repo-"));
19
+ process.env.PI_CODING_AGENT_DIR = AGENT;
20
+ setPlanBridge(undefined);
21
+ });
22
+
23
+ after(() => {
24
+ setPlanBridge(undefined);
25
+ if (realAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
26
+ else process.env.PI_CODING_AGENT_DIR = realAgentDir;
27
+ });
28
+
29
+ const fakeCtx = (notified: string[] = []): any => ({
30
+ cwd: REPO,
31
+ isProjectTrusted: () => false,
32
+ ui: { notify: (message: string) => { notified.push(message); } },
33
+ });
34
+
35
+ describe("plan config panel", () => {
36
+ it("rows: savePlans, plansDir, planModel, planThinking, autoApprove on the Tasks tab", () => {
37
+ const groups = buildPlanGroups({ ...DEFAULT_PLAN_SETTINGS });
38
+ assert.equal(groups.length, 1);
39
+ const group = groups[0];
40
+ assert.equal(group.tab, "Tasks");
41
+ assert.equal(group.label, "Plan mode");
42
+ assert.deepEqual(
43
+ group.rows.map((r) => r.key),
44
+ ["plan.savePlans", "plan.plansDir", "plan.planModel", "plan.planThinking", "plan.autoApprove"],
45
+ );
46
+ assert.equal(group.rows[0].values, undefined, "menu-driven row");
47
+ assert.equal(group.rows[4].kind, "toggle");
48
+ });
49
+
50
+ it("applyRows round-trips a working copy (Save plans + dir + auto-approve)", () => {
51
+ const cfg = { ...DEFAULT_PLAN_SETTINGS };
52
+ const groups = buildPlanGroups(cfg);
53
+ const byKey = new Map(groups[0].rows.map((r) => [r.key, r]));
54
+ byKey.get("plan.savePlans")!.set("approved");
55
+ byKey.get("plan.plansDir")!.set(".agents/plans/{yyyymm}");
56
+ byKey.get("plan.autoApprove")!.set(true);
57
+ applyRows(cfg, groups);
58
+ assert.equal(cfg.savePlans, "approved");
59
+ assert.equal(cfg.plansDir, ".agents/plans/{yyyymm}");
60
+ assert.equal(cfg.autoApprove, true);
61
+ });
62
+
63
+ it("rejects an off-set savePlans value", () => {
64
+ const cfg = { ...DEFAULT_PLAN_SETTINGS };
65
+ const row = buildPlanGroups(cfg)[0].rows[0];
66
+ row.set("sometimes");
67
+ assert.equal(cfg.savePlans, "all", "off-set value ignored");
68
+ });
69
+
70
+ it("save() no-ops unless an owned key was edited", async () => {
71
+ const notified: string[] = [];
72
+ const config = planConfig();
73
+ await config.save(new Set(["advisor.model"]), fakeCtx(notified));
74
+ assert.deepEqual(notified, []);
75
+ assert.equal(readPlanSettings().plansDir, DEFAULT_PLAN_SETTINGS.plansDir);
76
+ });
77
+
78
+ it("save() writes the global plan section", async () => {
79
+ setPlanBridge({ read: () => ({ ...DEFAULT_PLAN_SETTINGS, savePlans: "none" }), apply: () => {} });
80
+ const config = planConfig();
81
+ config.groups(); // open the panel (captures the working copy)
82
+ await config.save(new Set(["plan.savePlans"]), fakeCtx());
83
+ const body = JSON.parse(readFileSync(join(AGENT, "settings.json"), "utf8"));
84
+ assert.equal(body.plan.savePlans, "none");
85
+ });
86
+
87
+ it("save() discloses a shadowing project section", async () => {
88
+ mkdirSync(join(REPO, ".pi"), { recursive: true });
89
+ writeFileSync(join(REPO, ".pi", "settings.json"), JSON.stringify({ plan: { plansDir: "project" } }));
90
+ const notified: string[] = [];
91
+ const config = planConfig();
92
+ config.groups();
93
+ await config.save(new Set(["plan.plansDir"]), { ...fakeCtx(notified), isProjectTrusted: () => true });
94
+ assert.ok(notified.some((n) => n.includes("overrides this save")), notified.join(" | "));
95
+ });
96
+ });