@bonesofspring/ai-rules 0.2.63 → 0.2.64

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 (288) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +10 -3
  3. package/bin/cli.js +7 -5
  4. package/bin/lib/ai-local-drift.js +7 -6
  5. package/bin/lib/engine-scripts.js +4 -0
  6. package/bin/lib/engine-upgrade.js +10 -2
  7. package/bin/lib/manifest-schema.js +12 -0
  8. package/bin/lib/seed-ai-local-team.js +13 -0
  9. package/bin/mavis-install.js +4 -3
  10. package/bin/opencode-install.js +22 -6
  11. package/bin/zcode-install.js +4 -3
  12. package/docs/MCP-CATALOG.md +1 -1
  13. package/docs/OPENCODE-COMPATIBILITY.md +3 -2
  14. package/docs/OPENCODE.md +22 -2
  15. package/docs/PRESET-CONTRIBUTION.md +2 -2
  16. package/docs/TEAM-DB.md +71 -4
  17. package/docs/openapi/team-db.v1.json +4817 -2795
  18. package/mcp/defectdojo-mcp.mjs +41 -11
  19. package/mcp/lib/defectdojo.mjs +45 -2
  20. package/package.json +8 -2
  21. package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +279 -0
  22. package/presets/_shared/ai-local/scripts/team-db-api.mjs +471 -7
  23. package/presets/_shared/ai-local/scripts/team-db-backlog.mjs +1366 -0
  24. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +573 -7
  25. package/presets/_shared/ai-local/scripts/team-db-project.mjs +288 -4
  26. package/presets/_shared/ai-local/scripts/team-db-scheduler.mjs +82 -10
  27. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +83 -0
  28. package/presets/_shared/ai-local/scripts/team-db.mjs +69 -6
  29. package/presets/_shared/ai-local/scripts/upstream-research.mjs +3 -0
  30. package/presets/_shared/core/agent-team/agent-task-metrics.md +7 -2
  31. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +1 -0
  32. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +225 -0
  33. package/presets/_shared/hooks/run-hook.mjs +2 -1
  34. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +225 -0
  35. package/presets/claude/android-kotlin/hooks/run-hook.mjs +2 -1
  36. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  37. package/presets/claude/go/hooks/chain-team-phases.sh +225 -0
  38. package/presets/claude/go/hooks/run-hook.mjs +2 -1
  39. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  40. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +225 -0
  41. package/presets/claude/ios-swift/hooks/run-hook.mjs +2 -1
  42. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  43. package/presets/claude/java/hooks/chain-team-phases.sh +225 -0
  44. package/presets/claude/java/hooks/run-hook.mjs +2 -1
  45. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  46. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +225 -0
  47. package/presets/claude/mcp-ts/hooks/run-hook.mjs +2 -1
  48. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  49. package/presets/claude/mol/hooks/chain-team-phases.sh +225 -0
  50. package/presets/claude/mol/hooks/run-hook.mjs +2 -1
  51. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  52. package/presets/claude/next/agents/code-reviewer.md +1 -0
  53. package/presets/claude/next/agents/mockup-reviewer.md +2 -1
  54. package/presets/claude/next/agents/task-analyst.md +2 -0
  55. package/presets/claude/next/commands/task.md +7 -1
  56. package/presets/claude/next/commands/technical-retro.md +7 -1
  57. package/presets/claude/next/commands/upstream-research.md +1 -1
  58. package/presets/claude/next/hooks/chain-team-phases.sh +225 -0
  59. package/presets/claude/next/hooks/run-hook.mjs +2 -1
  60. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  61. package/presets/claude/next/skills/figma-fidelity/SKILL.md +4 -1
  62. package/presets/claude/next/skills/mockup-review/SKILL.md +4 -0
  63. package/presets/claude/next/team/README.md +5 -1
  64. package/presets/claude/next/team/upstream/jobs.json +34 -0
  65. package/presets/claude/nuxt/hooks/chain-team-phases.sh +225 -0
  66. package/presets/claude/nuxt/hooks/run-hook.mjs +2 -1
  67. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  68. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +225 -0
  69. package/presets/claude/php-hexagonal/hooks/run-hook.mjs +2 -1
  70. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  71. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +225 -0
  72. package/presets/claude/php-laravel/hooks/run-hook.mjs +2 -1
  73. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  74. package/presets/claude/svelte/hooks/chain-team-phases.sh +225 -0
  75. package/presets/claude/svelte/hooks/run-hook.mjs +2 -1
  76. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
  77. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +225 -0
  78. package/presets/cursor/android-kotlin/hooks/run-hook.mjs +2 -1
  79. package/presets/cursor/go/hooks/chain-team-phases.sh +225 -0
  80. package/presets/cursor/go/hooks/run-hook.mjs +2 -1
  81. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +225 -0
  82. package/presets/cursor/ios-swift/hooks/run-hook.mjs +2 -1
  83. package/presets/cursor/java/hooks/chain-team-phases.sh +225 -0
  84. package/presets/cursor/java/hooks/run-hook.mjs +2 -1
  85. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +225 -0
  86. package/presets/cursor/mcp-ts/hooks/run-hook.mjs +2 -1
  87. package/presets/cursor/mol/hooks/chain-team-phases.sh +225 -0
  88. package/presets/cursor/mol/hooks/run-hook.mjs +2 -1
  89. package/presets/cursor/next/agents/code-reviewer.md +1 -0
  90. package/presets/cursor/next/agents/mockup-reviewer.md +2 -1
  91. package/presets/cursor/next/agents/task-analyst.md +2 -0
  92. package/presets/cursor/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
  93. package/presets/cursor/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  94. package/presets/cursor/next/commands/task.md +7 -1
  95. package/presets/cursor/next/commands/technical-retro.md +7 -1
  96. package/presets/cursor/next/commands/upstream-research.md +1 -1
  97. package/presets/cursor/next/hooks/chain-team-phases.sh +225 -0
  98. package/presets/cursor/next/hooks/run-hook.mjs +2 -1
  99. package/presets/cursor/next/skills/figma-fidelity/SKILL.md +4 -1
  100. package/presets/cursor/next/skills/mockup-review/SKILL.md +4 -0
  101. package/presets/cursor/next/team/README.md +5 -1
  102. package/presets/cursor/next/team/upstream/jobs.json +34 -0
  103. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +225 -0
  104. package/presets/cursor/nuxt/hooks/run-hook.mjs +2 -1
  105. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +225 -0
  106. package/presets/cursor/php-hexagonal/hooks/run-hook.mjs +2 -1
  107. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +225 -0
  108. package/presets/cursor/php-laravel/hooks/run-hook.mjs +2 -1
  109. package/presets/cursor/svelte/hooks/chain-team-phases.sh +225 -0
  110. package/presets/cursor/svelte/hooks/run-hook.mjs +2 -1
  111. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  112. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +225 -0
  113. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +1 -0
  114. package/presets/mavis/go/adapter-map.json +1 -1
  115. package/presets/mavis/go/hooks/chain-team-phases.sh +225 -0
  116. package/presets/mavis/go/rules/agent-team-orchestrator.md +1 -0
  117. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  118. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +225 -0
  119. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +1 -0
  120. package/presets/mavis/java/adapter-map.json +1 -1
  121. package/presets/mavis/java/hooks/chain-team-phases.sh +225 -0
  122. package/presets/mavis/java/rules/agent-team-orchestrator.md +1 -0
  123. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  124. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +225 -0
  125. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +1 -0
  126. package/presets/mavis/mol/adapter-map.json +1 -1
  127. package/presets/mavis/mol/hooks/chain-team-phases.sh +225 -0
  128. package/presets/mavis/mol/rules/agent-team-orchestrator.md +1 -0
  129. package/presets/mavis/next/adapter-map.json +9 -1
  130. package/presets/mavis/next/agents/code-reviewer.md +1 -0
  131. package/presets/mavis/next/agents/mockup-reviewer.md +2 -1
  132. package/presets/mavis/next/agents/task-analyst.md +2 -0
  133. package/presets/mavis/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
  134. package/presets/mavis/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  135. package/presets/mavis/next/commands/task.md +7 -1
  136. package/presets/mavis/next/commands/technical-retro.md +7 -1
  137. package/presets/mavis/next/commands/upstream-research.md +1 -1
  138. package/presets/mavis/next/hooks/chain-team-phases.sh +225 -0
  139. package/presets/mavis/next/rules/agent-team-orchestrator.md +1 -0
  140. package/presets/mavis/next/skills/figma-fidelity/SKILL.md +4 -1
  141. package/presets/mavis/next/skills/mockup-review/SKILL.md +4 -0
  142. package/presets/mavis/next/team/README.md +5 -1
  143. package/presets/mavis/next/team/upstream/jobs.json +34 -0
  144. package/presets/mavis/nuxt/adapter-map.json +1 -1
  145. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +225 -0
  146. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +1 -0
  147. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  148. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +225 -0
  149. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +1 -0
  150. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  151. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +225 -0
  152. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +1 -0
  153. package/presets/mavis/svelte/adapter-map.json +1 -1
  154. package/presets/mavis/svelte/hooks/chain-team-phases.sh +225 -0
  155. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +1 -0
  156. package/presets/opencode/android-kotlin/OPENCODE.md +4 -1
  157. package/presets/opencode/android-kotlin/README.md +1 -0
  158. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  159. package/presets/opencode/android-kotlin/hooks/README.md +4 -2
  160. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +225 -0
  161. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +1 -0
  162. package/presets/opencode/go/OPENCODE.md +4 -1
  163. package/presets/opencode/go/README.md +1 -0
  164. package/presets/opencode/go/adapter-map.json +1 -1
  165. package/presets/opencode/go/hooks/README.md +4 -2
  166. package/presets/opencode/go/hooks/chain-team-phases.sh +225 -0
  167. package/presets/opencode/go/rules/agent-team-orchestrator.md +1 -0
  168. package/presets/opencode/ios-swift/OPENCODE.md +4 -1
  169. package/presets/opencode/ios-swift/README.md +1 -0
  170. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  171. package/presets/opencode/ios-swift/hooks/README.md +4 -2
  172. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +225 -0
  173. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +1 -0
  174. package/presets/opencode/java/OPENCODE.md +4 -1
  175. package/presets/opencode/java/README.md +1 -0
  176. package/presets/opencode/java/adapter-map.json +1 -1
  177. package/presets/opencode/java/hooks/README.md +4 -2
  178. package/presets/opencode/java/hooks/chain-team-phases.sh +225 -0
  179. package/presets/opencode/java/rules/agent-team-orchestrator.md +1 -0
  180. package/presets/opencode/mcp-ts/OPENCODE.md +4 -1
  181. package/presets/opencode/mcp-ts/README.md +1 -0
  182. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  183. package/presets/opencode/mcp-ts/hooks/README.md +4 -2
  184. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +225 -0
  185. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +1 -0
  186. package/presets/opencode/mol/OPENCODE.md +4 -1
  187. package/presets/opencode/mol/README.md +1 -0
  188. package/presets/opencode/mol/adapter-map.json +1 -1
  189. package/presets/opencode/mol/hooks/README.md +4 -2
  190. package/presets/opencode/mol/hooks/chain-team-phases.sh +225 -0
  191. package/presets/opencode/mol/rules/agent-team-orchestrator.md +1 -0
  192. package/presets/opencode/next/OPENCODE.md +4 -1
  193. package/presets/opencode/next/README.md +1 -0
  194. package/presets/opencode/next/adapter-map.json +9 -1
  195. package/presets/opencode/next/agents/code-reviewer.md +1 -0
  196. package/presets/opencode/next/agents/mockup-reviewer.md +2 -1
  197. package/presets/opencode/next/agents/task-analyst.md +2 -0
  198. package/presets/opencode/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
  199. package/presets/opencode/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  200. package/presets/opencode/next/commands/task.md +7 -1
  201. package/presets/opencode/next/commands/technical-retro.md +7 -1
  202. package/presets/opencode/next/commands/upstream-research.md +1 -1
  203. package/presets/opencode/next/hooks/README.md +4 -2
  204. package/presets/opencode/next/hooks/chain-team-phases.sh +225 -0
  205. package/presets/opencode/next/rules/agent-team-orchestrator.md +1 -0
  206. package/presets/opencode/next/skills/figma-fidelity/SKILL.md +4 -1
  207. package/presets/opencode/next/skills/mockup-review/SKILL.md +4 -0
  208. package/presets/opencode/next/team/README.md +5 -1
  209. package/presets/opencode/next/team/upstream/jobs.json +34 -0
  210. package/presets/opencode/nuxt/OPENCODE.md +4 -1
  211. package/presets/opencode/nuxt/README.md +1 -0
  212. package/presets/opencode/nuxt/adapter-map.json +1 -1
  213. package/presets/opencode/nuxt/hooks/README.md +4 -2
  214. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +225 -0
  215. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +1 -0
  216. package/presets/opencode/php-hexagonal/OPENCODE.md +4 -1
  217. package/presets/opencode/php-hexagonal/README.md +1 -0
  218. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  219. package/presets/opencode/php-hexagonal/hooks/README.md +4 -2
  220. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +225 -0
  221. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +1 -0
  222. package/presets/opencode/php-laravel/OPENCODE.md +4 -1
  223. package/presets/opencode/php-laravel/README.md +1 -0
  224. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  225. package/presets/opencode/php-laravel/hooks/README.md +4 -2
  226. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +225 -0
  227. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +1 -0
  228. package/presets/opencode/platform-contract.json +6 -0
  229. package/presets/opencode/plugins/task-status/README.md +92 -0
  230. package/presets/opencode/plugins/task-status/details-data.ts +130 -0
  231. package/presets/opencode/plugins/task-status/details.tsx +84 -0
  232. package/presets/opencode/plugins/task-status/eta.ts +230 -0
  233. package/presets/opencode/plugins/task-status/index.ts +6 -0
  234. package/presets/opencode/plugins/task-status/package.json +10 -0
  235. package/presets/opencode/plugins/task-status/task-view.ts +606 -0
  236. package/presets/opencode/plugins/task-status/tui.tsx +139 -0
  237. package/presets/opencode/svelte/OPENCODE.md +4 -1
  238. package/presets/opencode/svelte/README.md +1 -0
  239. package/presets/opencode/svelte/adapter-map.json +1 -1
  240. package/presets/opencode/svelte/hooks/README.md +4 -2
  241. package/presets/opencode/svelte/hooks/chain-team-phases.sh +225 -0
  242. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +1 -0
  243. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  244. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +225 -0
  245. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +1 -0
  246. package/presets/zcode/go/adapter-map.json +1 -1
  247. package/presets/zcode/go/hooks/chain-team-phases.sh +225 -0
  248. package/presets/zcode/go/rules/agent-team-orchestrator.md +1 -0
  249. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  250. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +225 -0
  251. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +1 -0
  252. package/presets/zcode/java/adapter-map.json +1 -1
  253. package/presets/zcode/java/hooks/chain-team-phases.sh +225 -0
  254. package/presets/zcode/java/rules/agent-team-orchestrator.md +1 -0
  255. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  256. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +225 -0
  257. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +1 -0
  258. package/presets/zcode/mol/adapter-map.json +1 -1
  259. package/presets/zcode/mol/hooks/chain-team-phases.sh +225 -0
  260. package/presets/zcode/mol/rules/agent-team-orchestrator.md +1 -0
  261. package/presets/zcode/next/adapter-map.json +9 -1
  262. package/presets/zcode/next/agents/code-reviewer.md +1 -0
  263. package/presets/zcode/next/agents/mockup-reviewer.md +2 -1
  264. package/presets/zcode/next/agents/task-analyst.md +2 -0
  265. package/presets/zcode/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
  266. package/presets/zcode/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  267. package/presets/zcode/next/commands/task.md +7 -1
  268. package/presets/zcode/next/commands/technical-retro.md +7 -1
  269. package/presets/zcode/next/commands/upstream-research.md +1 -1
  270. package/presets/zcode/next/hooks/chain-team-phases.sh +225 -0
  271. package/presets/zcode/next/rules/agent-team-orchestrator.md +1 -0
  272. package/presets/zcode/next/skills/figma-fidelity/SKILL.md +4 -1
  273. package/presets/zcode/next/skills/mockup-review/SKILL.md +4 -0
  274. package/presets/zcode/next/team/README.md +5 -1
  275. package/presets/zcode/next/team/upstream/jobs.json +34 -0
  276. package/presets/zcode/nuxt/adapter-map.json +1 -1
  277. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +225 -0
  278. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +1 -0
  279. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  280. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +225 -0
  281. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +1 -0
  282. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  283. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +225 -0
  284. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +1 -0
  285. package/presets/zcode/svelte/adapter-map.json +1 -1
  286. package/presets/zcode/svelte/hooks/chain-team-phases.sh +225 -0
  287. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +1 -0
  288. package/scripts/aggregate-agent-task-metrics.mjs +48 -4
@@ -13,6 +13,7 @@ import { createInterface } from 'node:readline';
13
13
  import {
14
14
  ApiError,
15
15
  ConfigError,
16
+ isAllowedImportPath,
16
17
  isAllowedPath,
17
18
  loadDefectDojoConfig,
18
19
  request,
@@ -141,7 +142,7 @@ const TOOLS = [
141
142
  properties: {
142
143
  engagement: { type: 'integer', minimum: 1 },
143
144
  scan_type: { type: 'string' },
144
- file: { type: 'string', description: 'Repo-relative or absolute path to the report file.' },
145
+ file: { type: 'string', description: 'Repo-relative path to the report file, read inside the project root.' },
145
146
  minimum_severity: { type: 'string', enum: ['Info', 'Low', 'Medium', 'High', 'Critical'] },
146
147
  active: { type: 'boolean' },
147
148
  verified: { type: 'boolean' },
@@ -178,18 +179,42 @@ function jsonResult(payload) {
178
179
  return { content: [{ type: 'text', text: clipped }] };
179
180
  }
180
181
 
182
+ /**
183
+ * Known error classes carry crafted messages without local paths; anything
184
+ * else is sanitized: the client gets a short generic message, the stack (and
185
+ * any local paths in it) goes to stderr for the operator only.
186
+ */
181
187
  function errorResult(error) {
182
- const message = error instanceof ConfigError || error instanceof ApiError
183
- ? error.message
184
- : error instanceof Error
185
- ? error.stack ?? error.message
186
- : String(error);
188
+ if (error instanceof ConfigError || error instanceof ApiError) {
189
+ return { content: [{ type: 'text', text: error.message }], isError: true };
190
+ }
191
+
192
+ const detail = error instanceof Error
193
+ ? error.stack ?? `${error.name}: ${error.message}`
194
+ : String(error);
187
195
 
188
- return { content: [{ type: 'text', text: message }], isError: true };
196
+ process.stderr.write(`defectdojo-mcp: unexpected tool failure\n${detail}\n`);
197
+
198
+ return { content: [{ type: 'text', text: 'unexpected tool failure (details in the server log)' }], isError: true };
189
199
  }
190
200
 
191
- function readFileForImport(root, path) {
192
- const absolute = resolve(root, path);
201
+ /** Declared-integer args are validated at runtime before they reach a path or payload. */
202
+ function requireInteger(value, name) {
203
+ if (!Number.isInteger(value)) {
204
+ throw new ConfigError(`${name} must be an integer`);
205
+ }
206
+
207
+ return value;
208
+ }
209
+
210
+ function readFileForImport(root, file) {
211
+ if (!isAllowedImportPath(root, file)) {
212
+ throw new ConfigError(
213
+ 'file must be a repo-relative path inside the project root; absolute paths, ".." traversal and symlink escapes are refused',
214
+ );
215
+ }
216
+
217
+ const absolute = resolve(root, file);
193
218
 
194
219
  return { buffer: readFileSync(absolute), name: basename(absolute) };
195
220
  }
@@ -205,15 +230,19 @@ async function callTool(name, args) {
205
230
  });
206
231
 
207
232
  case 'dd_finding':
208
- return request(config, { path: `findings/${args.id}/` });
233
+ return request(config, { path: `findings/${requireInteger(args.id, 'id')}/` });
209
234
 
210
235
  case 'dd_products':
211
236
  return request(config, { path: 'products/', query: asQuery(args, ['name', 'prod_type', 'limit', 'offset']) });
212
237
 
213
238
  case 'dd_product':
214
- return request(config, { path: `products/${args.id}/` });
239
+ return request(config, { path: `products/${requireInteger(args.id, 'id')}/` });
215
240
 
216
241
  case 'dd_engagements':
242
+ if (args.product !== undefined && args.product !== null) {
243
+ requireInteger(args.product, 'product');
244
+ }
245
+
217
246
  return request(config, { path: 'engagements/', query: asQuery(args, ['product', 'status', 'limit', 'offset']) });
218
247
 
219
248
  case 'dd_test_types':
@@ -228,6 +257,7 @@ async function callTool(name, args) {
228
257
  }
229
258
 
230
259
  case 'dd_import_scan': {
260
+ requireInteger(args.engagement, 'engagement');
231
261
  const { buffer, name: filename } = readFileForImport(config.root, args.file);
232
262
  const formData = new FormData();
233
263
 
@@ -7,8 +7,8 @@
7
7
  * `.env.defectdojo` file. Unlike GitLab, the token is not validated with a
8
8
  * provider endpoint at setup time only — the same probe powers the doctor.
9
9
  */
10
- import { existsSync } from 'node:fs';
11
- import { join } from 'node:path';
10
+ import { existsSync, realpathSync } from 'node:fs';
11
+ import { isAbsolute, join, resolve, sep } from 'node:path';
12
12
  import run from '../../bin/lib/mcp/run.js';
13
13
  import { ConfigError, readEnvFile } from './envfile.mjs';
14
14
 
@@ -157,6 +157,49 @@ export function isAllowedPath(path, baseUrl) {
157
157
  }
158
158
  }
159
159
 
160
+ /**
161
+ * `dd_import_scan` may read the report file inside the project root only —
162
+ * the local-file twin of {@link isAllowedPath}: a prompt-injected upload must
163
+ * not become a read of arbitrary local files. Absolute paths (POSIX, Windows
164
+ * drive or UNC) and any `..` traversal form — raw, percent-encoded, or
165
+ * backslash — are refused outright, and the resolved file must really exist
166
+ * under the *real* project root: a symlink that leaves the root is an escape,
167
+ * not a read. Deny closed: an unreadable, unresolvable, or malformed-encoding
168
+ * path is a refusal, never a best-effort read.
169
+ */
170
+ export function isAllowedImportPath(root, input) {
171
+ if (typeof root !== 'string' || root === '' || typeof input !== 'string' || input.trim() === '') {
172
+ return false;
173
+ }
174
+
175
+ const trimmed = input.trim();
176
+
177
+ if (isAbsolute(trimmed) || /^[a-zA-Z]:[/\\]/.test(trimmed) || trimmed.startsWith('\\\\')) {
178
+ return false;
179
+ }
180
+
181
+ const forms = [trimmed];
182
+ try {
183
+ forms.push(decodeURIComponent(trimmed));
184
+ } catch {
185
+ return false;
186
+ }
187
+
188
+ for (const form of forms) {
189
+ if (form.split(/[\\/]/).includes('..')) {
190
+ return false;
191
+ }
192
+ }
193
+
194
+ try {
195
+ const realRoot = realpathSync(root);
196
+ const realFile = realpathSync(resolve(root, trimmed));
197
+ return realFile === realRoot || realFile.startsWith(realRoot + sep);
198
+ } catch {
199
+ return false;
200
+ }
201
+ }
202
+
160
203
  export function buildUrl(baseUrl, path, query = {}) {
161
204
  const url = /^https?:\/\//.test(path) ? new URL(path) : new URL(`${baseUrl}/${apiPath(path)}`);
162
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.63",
3
+ "version": "0.2.64",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -87,6 +87,7 @@
87
87
  "test:mcp-pack-tarball": "node scripts/test-mcp-pack-tarball.mjs",
88
88
  "test:chain-coverage": "node scripts/test-chain-team-phases-coverage.mjs",
89
89
  "test:agent-task-metrics-hooks": "node scripts/test-agent-task-metrics-hooks.mjs",
90
+ "test:upstream": "node scripts/test-upstream-research.mjs",
90
91
  "test:team-db:schema": "node scripts/test-team-db-schema.mjs",
91
92
  "test:team-db:project": "node scripts/test-team-db-project.mjs",
92
93
  "test:team-db:migrate-tasks": "node scripts/test-team-db-migrate-tasks.mjs",
@@ -95,9 +96,14 @@
95
96
  "test:team-db:security": "node scripts/test-team-db-security.mjs",
96
97
  "test:team-db:dashboard": "node scripts/test-team-db-dashboard.mjs",
97
98
  "test:team-db:concurrency": "node scripts/test-team-db-concurrency.mjs",
99
+ "test:team-db:backlog": "node scripts/test-team-db-backlog.mjs",
100
+ "test:team-db:backlog-order": "node scripts/test-team-db-backlog-order.mjs",
101
+ "test:team-db:backlog-project": "node scripts/test-team-db-backlog-project.mjs",
102
+ "test:team-db:backlog-queue": "node scripts/test-team-db-backlog-queue.mjs",
103
+ "test:team-db:backlog-import": "node scripts/test-team-db-backlog-import.mjs",
98
104
  "test:team-db:scheduler": "node scripts/test-team-db-scheduler.mjs",
99
105
  "test:team-db:fixtures": "node scripts/test-team-db-fixtures.mjs",
100
- "test:team-db": "node scripts/test-team-db-schema.mjs && node scripts/test-team-db-project.mjs && node scripts/test-team-db-migrate-tasks.mjs && node scripts/test-team-db-dualwrite.mjs && node scripts/check-team-db-contract.mjs && node scripts/test-team-db-api.mjs && node scripts/test-team-db-security.mjs && node scripts/test-team-db-dashboard.mjs && node scripts/test-team-db-concurrency.mjs && node scripts/test-team-db-scheduler.mjs && node scripts/test-team-db-fixtures.mjs",
106
+ "test:team-db": "node scripts/test-team-db-schema.mjs && node scripts/test-team-db-project.mjs && node scripts/test-team-db-migrate-tasks.mjs && node scripts/test-team-db-dualwrite.mjs && node scripts/check-team-db-contract.mjs && node scripts/test-team-db-api.mjs && node scripts/test-team-db-security.mjs && node scripts/test-team-db-dashboard.mjs && node scripts/test-team-db-concurrency.mjs && node scripts/test-team-db-backlog.mjs && node scripts/test-team-db-backlog-order.mjs && node scripts/test-team-db-backlog-project.mjs && node scripts/test-team-db-backlog-queue.mjs && node scripts/test-team-db-backlog-import.mjs && node scripts/test-team-db-scheduler.mjs && node scripts/test-team-db-fixtures.mjs",
101
107
  "check:team-db-contract": "node scripts/check-team-db-contract.mjs",
102
108
  "check:mavis-platform-contract": "node scripts/check-mavis-platform-contract.mjs --self-test",
103
109
  "check:mavis-adapter-map": "node scripts/check-mavis-adapter-map.mjs --self-test",
@@ -0,0 +1,279 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Aggregate `metrics.json` ledgers across `.ai.local/team/tasks/*` and emit a JSON report.
4
+ *
5
+ * Usage:
6
+ * node scripts/aggregate-agent-task-metrics.mjs [--team-root <dir>] [--help]
7
+ *
8
+ * Defaults to `<cwd>/.ai.local/team` when --team-root is omitted.
9
+ */
10
+
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+
14
+ const args = process.argv.slice(2);
15
+
16
+ if (args.includes('-h') || args.includes('--help')) {
17
+ console.log(`Aggregate agent-task metrics ledgers.
18
+
19
+ Usage:
20
+ node scripts/aggregate-agent-task-metrics.mjs [--team-root <dir>] [--slug <slug>]
21
+
22
+ Options:
23
+ --team-root <dir> Directory containing a 'tasks/' subfolder with *.metrics.json ledgers
24
+ (default: <cwd>/.ai.local/team)
25
+ --slug <slug> Only aggregate the named task directory
26
+
27
+ Output: JSON report on stdout (machine-readable).`);
28
+ process.exit(0);
29
+ }
30
+
31
+ const teamRootIndex = args.indexOf('--team-root');
32
+ const teamRoot =
33
+ teamRootIndex >= 0
34
+ ? path.resolve(args[teamRootIndex + 1] ?? '')
35
+ : path.join(process.cwd(), '.ai.local', 'team');
36
+ const slugIndex = args.indexOf('--slug');
37
+ const slugFilter = slugIndex >= 0 ? args[slugIndex + 1] ?? null : null;
38
+ const tasksDir = path.join(teamRoot, 'tasks');
39
+ const incomplete = [];
40
+ const attempts = [];
41
+ const tasks = [];
42
+ const taskReports = [];
43
+ const gateWaits = [];
44
+ const outOfBandDurations = [];
45
+ const attributionConfidenceCounts = new Map();
46
+ let unmatchedAttemptCount = 0;
47
+ let duplicateTerminalAttemptCount = 0;
48
+ let duplicateAttemptIdCount = 0;
49
+ let missingLedgerCount = 0;
50
+ let malformedLedgerCount = 0;
51
+ let invalidLedgerCount = 0;
52
+ let unterminatedAttemptCount = 0;
53
+
54
+ function readMetrics(filePath) {
55
+ if (!fs.existsSync(filePath)) {
56
+ incomplete.push({ file: filePath, category: 'missing_ledger', reason: 'missing ledger' });
57
+ missingLedgerCount += 1;
58
+ return;
59
+ }
60
+ let parsed;
61
+ try {
62
+ parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
63
+ } catch {
64
+ incomplete.push({ file: filePath, category: 'malformed_json', reason: 'malformed JSON' });
65
+ malformedLedgerCount += 1;
66
+ return;
67
+ }
68
+ if (parsed.schemaVersion !== 1 || !parsed.task || !Array.isArray(parsed.events)) {
69
+ incomplete.push({ file: filePath, category: 'unsupported_schema', reason: 'unsupported schema' });
70
+ return;
71
+ }
72
+ try {
73
+ collect(parsed, filePath);
74
+ } catch (error) {
75
+ incomplete.push({
76
+ file: filePath,
77
+ category: 'invalid_ledger',
78
+ reason: error instanceof Error ? error.message : 'invalid ledger structure',
79
+ });
80
+ invalidLedgerCount += 1;
81
+ }
82
+ }
83
+
84
+ function collect(metrics, filePath) {
85
+ const starts = new Map();
86
+ const gateStarts = new Map();
87
+ const terminalAttempts = new Set();
88
+ const attemptDurations = [];
89
+ let taskCompleted = false;
90
+ let ledgerIncomplete = false;
91
+ let taskStartedAt = null;
92
+ let taskCompletedAt = null;
93
+ let taskGateWaitMs = 0;
94
+ let taskOutOfBandMs = 0;
95
+ let taskOutOfBandCount = 0;
96
+
97
+ for (const event of metrics.events) {
98
+ if (event.type === 'task_started') taskStartedAt = event.at;
99
+ if (event.type === 'out_of_band_finished' && Number.isFinite(event.durationMs)) {
100
+ outOfBandDurations.push(event.durationMs);
101
+ taskOutOfBandMs += event.durationMs;
102
+ taskOutOfBandCount += 1;
103
+ }
104
+ if (event.type === 'attempt_started' && event.attemptId) {
105
+ if (starts.has(event.attemptId)) {
106
+ incomplete.push({
107
+ file: filePath,
108
+ category: 'duplicate_attempt_id',
109
+ reason: `duplicate attempt ID ${event.attemptId}`,
110
+ });
111
+ duplicateAttemptIdCount += 1;
112
+ ledgerIncomplete = true;
113
+ continue;
114
+ }
115
+ starts.set(event.attemptId, event);
116
+ }
117
+ if (event.type === 'attempt_finished' && event.attemptId) {
118
+ const start = starts.get(event.attemptId);
119
+ if (!start) {
120
+ incomplete.push({
121
+ file: filePath,
122
+ category: 'unmatched_attempt',
123
+ reason: `unmatched attempt ${event.attemptId}`,
124
+ });
125
+ unmatchedAttemptCount += 1;
126
+ ledgerIncomplete = true;
127
+ continue;
128
+ }
129
+ if (terminalAttempts.has(event.attemptId)) {
130
+ incomplete.push({
131
+ file: filePath,
132
+ category: 'duplicate_terminal_attempt',
133
+ reason: `duplicate terminal attempt ${event.attemptId}`,
134
+ });
135
+ duplicateTerminalAttemptCount += 1;
136
+ ledgerIncomplete = true;
137
+ continue;
138
+ }
139
+ terminalAttempts.add(event.attemptId);
140
+ const attributionConfidence = event.attributionConfidence ?? 'unknown';
141
+ attributionConfidenceCounts.set(
142
+ attributionConfidence,
143
+ (attributionConfidenceCounts.get(attributionConfidence) ?? 0) + 1,
144
+ );
145
+ if (Number.isFinite(event.durationMs)) attemptDurations.push(event.durationMs);
146
+ attempts.push({
147
+ ...metrics.task,
148
+ agent: start.agent ?? 'unknown',
149
+ role: start.role ?? 'unknown',
150
+ durationMs: Number.isFinite(event.durationMs) ? event.durationMs : null,
151
+ outcome: event.outcome ?? 'unknown',
152
+ attributionConfidence,
153
+ });
154
+ }
155
+ if (event.type === 'human_gate_started' && event.eventId) {
156
+ gateStarts.set(event.eventId, event);
157
+ }
158
+ if (event.type === 'human_gate_ended') {
159
+ const start = event.gateStartedEventId ? gateStarts.get(event.gateStartedEventId) : undefined;
160
+ const elapsed = start ? Date.parse(event.at) - Date.parse(start.at) : NaN;
161
+ if (Number.isFinite(elapsed) && elapsed >= 0) {
162
+ gateWaits.push(elapsed);
163
+ taskGateWaitMs += elapsed;
164
+ }
165
+ }
166
+ if (event.type === 'task_completed') {
167
+ taskCompleted = true;
168
+ taskCompletedAt = event.at;
169
+ }
170
+ }
171
+
172
+ for (const attemptId of starts.keys()) {
173
+ if (terminalAttempts.has(attemptId)) continue;
174
+ incomplete.push({
175
+ file: filePath,
176
+ category: 'unterminated_attempt',
177
+ reason: `unterminated attempt ${attemptId}`,
178
+ });
179
+ unterminatedAttemptCount += 1;
180
+ ledgerIncomplete = true;
181
+ }
182
+
183
+ if (taskCompleted && !ledgerIncomplete) tasks.push(metrics.task);
184
+ if (taskStartedAt) {
185
+ taskReports.push({
186
+ ...metrics.task,
187
+ elapsedMs: taskCompletedAt ? Date.parse(taskCompletedAt) - Date.parse(taskStartedAt) : null,
188
+ activeMs: attemptDurations.reduce((sum, value) => sum + value, 0),
189
+ gateWaitMs: taskGateWaitMs,
190
+ outOfBandMs: taskOutOfBandMs,
191
+ outOfBandCount: taskOutOfBandCount,
192
+ attemptCount: terminalAttempts.size,
193
+ completed: taskCompleted,
194
+ incomplete: ledgerIncomplete,
195
+ });
196
+ }
197
+ }
198
+
199
+ function groupBy(items, keyFor) {
200
+ const groups = new Map();
201
+ for (const item of items) {
202
+ const key = keyFor(item);
203
+ groups.set(key, [...(groups.get(key) ?? []), item]);
204
+ }
205
+ return [...groups.values()];
206
+ }
207
+
208
+ if (!fs.existsSync(tasksDir)) {
209
+ console.error(`Task directory does not exist: ${tasksDir}`);
210
+ process.exit(1);
211
+ }
212
+
213
+ for (const entry of fs.readdirSync(tasksDir, { withFileTypes: true })) {
214
+ if (!entry.isDirectory()) continue;
215
+ if (slugFilter && entry.name !== slugFilter) continue;
216
+ readMetrics(path.join(tasksDir, entry.name, 'metrics.json'));
217
+ }
218
+
219
+ const byAgentRole = groupBy(
220
+ attempts,
221
+ (item) => `${item.platform}|${item.stack}|${item.preset}|${item.agent}|${item.role}`,
222
+ ).map((group) => {
223
+ const sample = group[0];
224
+ const durations = group.map((item) => item.durationMs).filter((value) => value !== null);
225
+ const sumDurationMs = durations.reduce((sum, value) => sum + value, 0);
226
+ return {
227
+ platform: sample.platform,
228
+ stack: sample.stack,
229
+ preset: sample.preset,
230
+ agent: sample.agent,
231
+ role: sample.role,
232
+ count: group.length,
233
+ completedCount: group.filter((item) => item.outcome === 'completed').length,
234
+ sumDurationMs,
235
+ avgDurationMs: durations.length ? sumDurationMs / durations.length : null,
236
+ };
237
+ });
238
+
239
+ const taskCountsByRunId = [...new Map(tasks.map((task) => [task.runId, task])).values()].map((task) => ({
240
+ runId: task.runId,
241
+ slug: task.slug,
242
+ platform: task.platform,
243
+ stack: task.stack,
244
+ preset: task.preset,
245
+ intent: task.intent,
246
+ }));
247
+
248
+ process.stdout.write(
249
+ `${JSON.stringify(
250
+ {
251
+ schemaVersion: 1,
252
+ teamRoot,
253
+ agentRole: byAgentRole,
254
+ taskCountsByRunId,
255
+ taskReports,
256
+ humanGateWait: {
257
+ count: gateWaits.length,
258
+ sumDurationMs: gateWaits.reduce((sum, value) => sum + value, 0),
259
+ },
260
+ outOfBand: {
261
+ count: outOfBandDurations.length,
262
+ sumDurationMs: outOfBandDurations.reduce((sum, value) => sum + value, 0),
263
+ },
264
+ attributionConfidence: Object.fromEntries(attributionConfidenceCounts),
265
+ completeness: {
266
+ missingLedgerCount,
267
+ malformedLedgerCount,
268
+ invalidLedgerCount,
269
+ duplicateAttemptIdCount,
270
+ unterminatedAttemptCount,
271
+ unmatchedAttemptCount,
272
+ duplicateTerminalAttemptCount,
273
+ },
274
+ incomplete,
275
+ },
276
+ null,
277
+ 2,
278
+ )}\n`,
279
+ );