@monoes/monomindcli 2.15.6 → 2.16.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 (304) hide show
  1. package/.claude/helpers/build-skill-registry.cjs +23 -2
  2. package/.claude/helpers/handlers/route-handler.cjs +89 -3
  3. package/.claude/helpers/handlers/session-restore-handler.cjs +1 -1
  4. package/.claude/helpers/jev-picker.cjs +499 -0
  5. package/.claude/helpers/redact-secrets.cjs +69 -0
  6. package/.claude/skills/mastermind-agent-select/SKILL.md +28 -0
  7. package/dist/src/catalog/blueprints.d.ts +39 -0
  8. package/dist/src/catalog/blueprints.d.ts.map +1 -0
  9. package/dist/src/catalog/blueprints.js +78 -0
  10. package/dist/src/catalog/blueprints.js.map +1 -0
  11. package/dist/src/catalog/digest.d.ts +16 -0
  12. package/dist/src/catalog/digest.d.ts.map +1 -0
  13. package/dist/src/catalog/digest.js +62 -0
  14. package/dist/src/catalog/digest.js.map +1 -0
  15. package/dist/src/catalog/frontmatter.d.ts +23 -0
  16. package/dist/src/catalog/frontmatter.d.ts.map +1 -0
  17. package/dist/src/catalog/frontmatter.js +80 -0
  18. package/dist/src/catalog/frontmatter.js.map +1 -0
  19. package/dist/src/catalog/lifecycle.d.ts +31 -0
  20. package/dist/src/catalog/lifecycle.d.ts.map +1 -0
  21. package/dist/src/catalog/lifecycle.js +78 -0
  22. package/dist/src/catalog/lifecycle.js.map +1 -0
  23. package/dist/src/catalog/projection.d.ts +57 -0
  24. package/dist/src/catalog/projection.d.ts.map +1 -0
  25. package/dist/src/catalog/projection.js +272 -0
  26. package/dist/src/catalog/projection.js.map +1 -0
  27. package/dist/src/catalog/scan.d.ts +37 -0
  28. package/dist/src/catalog/scan.d.ts.map +1 -0
  29. package/dist/src/catalog/scan.js +214 -0
  30. package/dist/src/catalog/scan.js.map +1 -0
  31. package/dist/src/catalog/snapshot.d.ts +62 -0
  32. package/dist/src/catalog/snapshot.d.ts.map +1 -0
  33. package/dist/src/catalog/snapshot.js +183 -0
  34. package/dist/src/catalog/snapshot.js.map +1 -0
  35. package/dist/src/catalog/stage.d.ts +26 -0
  36. package/dist/src/catalog/stage.d.ts.map +1 -0
  37. package/dist/src/catalog/stage.js +316 -0
  38. package/dist/src/catalog/stage.js.map +1 -0
  39. package/dist/src/catalog/state.d.ts +23 -0
  40. package/dist/src/catalog/state.d.ts.map +1 -0
  41. package/dist/src/catalog/state.js +102 -0
  42. package/dist/src/catalog/state.js.map +1 -0
  43. package/dist/src/catalog/types.d.ts +289 -0
  44. package/dist/src/catalog/types.d.ts.map +1 -0
  45. package/dist/src/catalog/types.js +118 -0
  46. package/dist/src/catalog/types.js.map +1 -0
  47. package/dist/src/commands/catalog.d.ts +14 -0
  48. package/dist/src/commands/catalog.d.ts.map +1 -0
  49. package/dist/src/commands/catalog.js +392 -0
  50. package/dist/src/commands/catalog.js.map +1 -0
  51. package/dist/src/commands/doctor-catalog-checks.d.ts +3 -0
  52. package/dist/src/commands/doctor-catalog-checks.d.ts.map +1 -0
  53. package/dist/src/commands/doctor-catalog-checks.js +69 -0
  54. package/dist/src/commands/doctor-catalog-checks.js.map +1 -0
  55. package/dist/src/commands/doctor-decision-checks.d.ts +10 -0
  56. package/dist/src/commands/doctor-decision-checks.d.ts.map +1 -0
  57. package/dist/src/commands/doctor-decision-checks.js +82 -0
  58. package/dist/src/commands/doctor-decision-checks.js.map +1 -0
  59. package/dist/src/commands/doctor.d.ts.map +1 -1
  60. package/dist/src/commands/doctor.js +9 -1
  61. package/dist/src/commands/doctor.js.map +1 -1
  62. package/dist/src/commands/index.d.ts +2 -2
  63. package/dist/src/commands/index.d.ts.map +1 -1
  64. package/dist/src/commands/index.js +4 -1
  65. package/dist/src/commands/index.js.map +1 -1
  66. package/dist/src/commands/org-observe.d.ts.map +1 -1
  67. package/dist/src/commands/org-observe.js +7 -1
  68. package/dist/src/commands/org-observe.js.map +1 -1
  69. package/dist/src/commands/org-skills.d.ts.map +1 -1
  70. package/dist/src/commands/org-skills.js +14 -4
  71. package/dist/src/commands/org-skills.js.map +1 -1
  72. package/dist/src/commands/org.d.ts.map +1 -1
  73. package/dist/src/commands/org.js +8 -1
  74. package/dist/src/commands/org.js.map +1 -1
  75. package/dist/src/commands/pick.d.ts +4 -0
  76. package/dist/src/commands/pick.d.ts.map +1 -0
  77. package/dist/src/commands/pick.js +77 -0
  78. package/dist/src/commands/pick.js.map +1 -0
  79. package/dist/src/commands/route.js +1 -1
  80. package/dist/src/commands/route.js.map +1 -1
  81. package/dist/src/decision/catalogs.d.ts +20 -0
  82. package/dist/src/decision/catalogs.d.ts.map +1 -0
  83. package/dist/src/decision/catalogs.js +64 -0
  84. package/dist/src/decision/catalogs.js.map +1 -0
  85. package/dist/src/decision/jev.d.ts +85 -0
  86. package/dist/src/decision/jev.d.ts.map +1 -0
  87. package/dist/src/decision/jev.js +72 -0
  88. package/dist/src/decision/jev.js.map +1 -0
  89. package/dist/src/decision/picks.d.ts +50 -0
  90. package/dist/src/decision/picks.d.ts.map +1 -0
  91. package/dist/src/decision/picks.js +100 -0
  92. package/dist/src/decision/picks.js.map +1 -0
  93. package/dist/src/init/helpers-generator.d.ts.map +1 -1
  94. package/dist/src/init/helpers-generator.js +7 -0
  95. package/dist/src/init/helpers-generator.js.map +1 -1
  96. package/dist/src/orgrt/checkpoint-ops.d.ts.map +1 -1
  97. package/dist/src/orgrt/checkpoint-ops.js +6 -1
  98. package/dist/src/orgrt/checkpoint-ops.js.map +1 -1
  99. package/dist/src/orgrt/completion-gate.d.ts +15 -0
  100. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  101. package/dist/src/orgrt/completion-gate.js +59 -3
  102. package/dist/src/orgrt/completion-gate.js.map +1 -1
  103. package/dist/src/orgrt/daemon.d.ts +18 -1
  104. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  105. package/dist/src/orgrt/daemon.js +33 -3
  106. package/dist/src/orgrt/daemon.js.map +1 -1
  107. package/dist/src/orgrt/decisions.d.ts +24 -0
  108. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  109. package/dist/src/orgrt/decisions.js +164 -18
  110. package/dist/src/orgrt/decisions.js.map +1 -1
  111. package/dist/src/orgrt/review-packet.d.ts +1 -1
  112. package/dist/src/orgrt/review-packet.d.ts.map +1 -1
  113. package/dist/src/orgrt/review-packet.js +2 -2
  114. package/dist/src/orgrt/review-packet.js.map +1 -1
  115. package/dist/src/orgrt/session.d.ts +9 -0
  116. package/dist/src/orgrt/session.d.ts.map +1 -1
  117. package/dist/src/orgrt/session.js +24 -2
  118. package/dist/src/orgrt/session.js.map +1 -1
  119. package/dist/src/orgrt/skill-library.d.ts +10 -1
  120. package/dist/src/orgrt/skill-library.d.ts.map +1 -1
  121. package/dist/src/orgrt/skill-library.js +53 -4
  122. package/dist/src/orgrt/skill-library.js.map +1 -1
  123. package/dist/src/orgrt/task-dag.d.ts +3 -0
  124. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  125. package/dist/src/orgrt/task-dag.js +6 -0
  126. package/dist/src/orgrt/task-dag.js.map +1 -1
  127. package/dist/src/orgrt/types.d.ts +2 -0
  128. package/dist/src/orgrt/types.d.ts.map +1 -1
  129. package/dist/src/orgrt/types.js +4 -0
  130. package/dist/src/orgrt/types.js.map +1 -1
  131. package/dist/src/platform-adapters/mutation.d.ts +34 -0
  132. package/dist/src/platform-adapters/mutation.d.ts.map +1 -0
  133. package/dist/src/platform-adapters/mutation.js +188 -0
  134. package/dist/src/platform-adapters/mutation.js.map +1 -0
  135. package/dist/src/platform-adapters/operations.d.ts +7 -1
  136. package/dist/src/platform-adapters/operations.d.ts.map +1 -1
  137. package/dist/src/platform-adapters/operations.js +18 -76
  138. package/dist/src/platform-adapters/operations.js.map +1 -1
  139. package/dist/src/routing/jev-step.d.ts +17 -0
  140. package/dist/src/routing/jev-step.d.ts.map +1 -0
  141. package/dist/src/routing/jev-step.js +27 -0
  142. package/dist/src/routing/jev-step.js.map +1 -0
  143. package/dist/src/routing/route-layer-factory.d.ts.map +1 -1
  144. package/dist/src/routing/route-layer-factory.js +16 -1
  145. package/dist/src/routing/route-layer-factory.js.map +1 -1
  146. package/dist/src/utils/redaction.d.ts.map +1 -1
  147. package/dist/src/utils/redaction.js +19 -4
  148. package/dist/src/utils/redaction.js.map +1 -1
  149. package/dist/tsconfig.tsbuildinfo +1 -1
  150. package/package.json +4 -4
  151. package/.claude/skills/monodesign/SKILL.md +0 -257
  152. package/.claude/skills/monodesign/adapt.md +0 -53
  153. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  154. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  155. package/.claude/skills/monodesign/animate.md +0 -65
  156. package/.claude/skills/monodesign/audit.md +0 -89
  157. package/.claude/skills/monodesign/bolder.md +0 -50
  158. package/.claude/skills/monodesign/clarify.md +0 -64
  159. package/.claude/skills/monodesign/colorize.md +0 -68
  160. package/.claude/skills/monodesign/craft.md +0 -51
  161. package/.claude/skills/monodesign/critique.md +0 -66
  162. package/.claude/skills/monodesign/delight.md +0 -47
  163. package/.claude/skills/monodesign/distill.md +0 -56
  164. package/.claude/skills/monodesign/document.md +0 -83
  165. package/.claude/skills/monodesign/extract.md +0 -74
  166. package/.claude/skills/monodesign/harden.md +0 -65
  167. package/.claude/skills/monodesign/init.md +0 -30
  168. package/.claude/skills/monodesign/layout.md +0 -36
  169. package/.claude/skills/monodesign/live.md +0 -34
  170. package/.claude/skills/monodesign/onboard.md +0 -50
  171. package/.claude/skills/monodesign/optimize.md +0 -64
  172. package/.claude/skills/monodesign/overdrive.md +0 -56
  173. package/.claude/skills/monodesign/polish.md +0 -68
  174. package/.claude/skills/monodesign/quieter.md +0 -57
  175. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  176. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  177. package/.claude/skills/monodesign/reference/android.md +0 -40
  178. package/.claude/skills/monodesign/reference/animate.md +0 -203
  179. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  180. package/.claude/skills/monodesign/reference/audit.md +0 -135
  181. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  182. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  183. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  184. package/.claude/skills/monodesign/reference/brand.md +0 -108
  185. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  186. package/.claude/skills/monodesign/reference/codex.md +0 -105
  187. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  188. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  189. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  190. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  191. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  192. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  193. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  194. package/.claude/skills/monodesign/reference/craft.md +0 -123
  195. package/.claude/skills/monodesign/reference/critique.md +0 -780
  196. package/.claude/skills/monodesign/reference/delight.md +0 -302
  197. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  198. package/.claude/skills/monodesign/reference/distill.md +0 -111
  199. package/.claude/skills/monodesign/reference/document.md +0 -429
  200. package/.claude/skills/monodesign/reference/extract.md +0 -69
  201. package/.claude/skills/monodesign/reference/harden.md +0 -347
  202. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  203. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  204. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  205. package/.claude/skills/monodesign/reference/init.md +0 -221
  206. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  207. package/.claude/skills/monodesign/reference/ios.md +0 -45
  208. package/.claude/skills/monodesign/reference/layout.md +0 -185
  209. package/.claude/skills/monodesign/reference/live.md +0 -710
  210. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  211. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  212. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  213. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  214. package/.claude/skills/monodesign/reference/personas.md +0 -179
  215. package/.claude/skills/monodesign/reference/polish.md +0 -241
  216. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  217. package/.claude/skills/monodesign/reference/product.md +0 -60
  218. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  219. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  220. package/.claude/skills/monodesign/reference/shape.md +0 -165
  221. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  222. package/.claude/skills/monodesign/reference/teach.md +0 -10
  223. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  224. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  225. package/.claude/skills/monodesign/reference/typography.md +0 -159
  226. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  227. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  228. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  229. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  230. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  231. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  232. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  233. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  234. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  235. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  236. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  237. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  238. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  239. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  240. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  241. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -339
  242. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  243. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  244. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  245. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  246. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  247. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  248. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  249. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  250. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  251. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  252. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  253. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  254. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  255. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  256. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  257. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  258. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  259. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  260. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  261. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  262. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  263. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  264. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  265. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  266. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  267. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  268. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  269. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  270. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  271. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  272. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  273. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  274. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  275. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  276. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  277. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  278. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  279. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  280. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  281. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  282. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  283. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  284. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  285. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  286. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  287. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  288. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  289. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  290. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  291. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  292. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  293. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  294. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  295. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  296. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  297. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  298. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  299. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  300. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  301. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  302. package/.claude/skills/monodesign/shape.md +0 -71
  303. package/.claude/skills/monodesign/teach.md +0 -18
  304. package/.claude/skills/monodesign/typeset.md +0 -59
@@ -1,416 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Critique persistence helper.
4
- *
5
- * Each critique run writes a per-target snapshot to
6
- * .monodesign/critique/<timestamp>__<slug>.md
7
- * with a small YAML frontmatter carrying the score + P0/P1 counts.
8
- *
9
- * The polish workflow reads the latest matching snapshot at start as its
10
- * fix backlog. No other skill auto-reads critique output.
11
- *
12
- * The slug is derived mechanically from the *resolved* primary artifact
13
- * (file path or URL), never from the user's natural-language phrasing.
14
- * Slug stability across runs is what lets the trend display work.
15
- *
16
- * CLI entry points (called from skill instructions):
17
- * node critique-storage.mjs slug <resolved-target>
18
- * node critique-storage.mjs write <slug> <snapshot-body-file>
19
- * node critique-storage.mjs latest <slug>
20
- * node critique-storage.mjs trend <slug> [limit]
21
- * node critique-storage.mjs recall <slug> [limit]
22
- *
23
- * `write` also best-effort mirrors a compact record of the snapshot into
24
- * monomind's persistent memory (namespace `design-critique`) so design
25
- * health survives across sessions. The mirror is fire-and-forget: if the
26
- * monomind CLI is not installed it is skipped silently, and it can be
27
- * disabled outright with MONODESIGN_NO_MEMORY=1.
28
- *
29
- * Note: there is intentionally no `ignore` subcommand. ignore.md is a plain
30
- * markdown file; the model reads it directly with its file-read tool. This
31
- * helper only exists for operations the model can't trivially do inline
32
- * (normalizing paths, generating filenames, globbing + parsing frontmatter).
33
- */
34
-
35
- import fs from 'node:fs';
36
- import path from 'node:path';
37
- import { spawnSync } from 'node:child_process';
38
- import { fileURLToPath, pathToFileURL } from 'node:url';
39
- import { getCritiqueDir } from './lib/monodesign-paths.mjs';
40
-
41
- const SLUG_MAX = 50;
42
-
43
- /**
44
- * Mechanically derive a slug from a resolved target. Returns null if the
45
- * input doesn't look like a stable identifier (empty, project root, etc).
46
- *
47
- * Accepts file paths and URLs. The model resolves "the homepage" to a
48
- * concrete artifact before calling this — we never slug a natural-language
49
- * phrase.
50
- */
51
- export function slugFromTarget(resolved, { cwd = process.cwd() } = {}) {
52
- if (!resolved || typeof resolved !== 'string') return null;
53
- const trimmed = resolved.trim();
54
- if (!trimmed) return null;
55
-
56
- // URL
57
- if (/^https?:\/\//i.test(trimmed)) {
58
- let url;
59
- try { url = new URL(trimmed); } catch { return null; }
60
- const hostPath = `${url.hostname}${url.pathname}`;
61
- return kebab(hostPath);
62
- }
63
-
64
- // File path. Make it project-relative so two devs critiquing the same
65
- // checkout get the same slug regardless of where their repo is cloned.
66
- const abs = path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
67
- let rel = path.relative(cwd, abs).split(path.sep).join('/');
68
- // If the target is outside cwd, fall back to the basename so we still
69
- // produce a stable slug (vs the absolute path, which would include
70
- // home dirs / usernames).
71
- if (rel.startsWith('..') || path.isAbsolute(rel)) {
72
- rel = path.basename(abs);
73
- }
74
- if (!rel || rel === '.' || rel === '') return null;
75
- return kebab(rel);
76
- }
77
-
78
- function kebab(s) {
79
- const slug = s
80
- .toLowerCase()
81
- .replace(/[/\\.]+/g, '-')
82
- .replace(/[^a-z0-9-]+/g, '-')
83
- .replace(/-+/g, '-')
84
- .replace(/^-|-$/g, '');
85
- if (!slug) return null;
86
- // Cap from the tail — the tail (filename) is more identifying than the
87
- // top-level directory.
88
- return slug.length <= SLUG_MAX ? slug : slug.slice(slug.length - SLUG_MAX).replace(/^-/, '');
89
- }
90
-
91
- /**
92
- * Filename-safe UTC ISO timestamp: hyphens for separators, trailing Z.
93
- * Plain colons aren't allowed on Windows filesystems.
94
- */
95
- export function nowFilenameStamp(date = new Date()) {
96
- const iso = date.toISOString(); // 2026-05-12T18:30:00.123Z
97
- return iso.replace(/[:.]/g, '-').replace(/-\d+Z$/, 'Z');
98
- }
99
-
100
- /**
101
- * Write a snapshot for `slug`. `meta` carries the small structured frontmatter
102
- * keys read back by readTrend(). `body` is the human-readable critique
103
- * report (everything below the frontmatter).
104
- *
105
- * Returns the absolute path written.
106
- */
107
- export function writeSnapshot({ slug, meta, body, cwd = process.cwd(), now = new Date() }) {
108
- if (!slug) throw new Error('writeSnapshot requires a slug');
109
- const dir = getCritiqueDir(cwd);
110
- fs.mkdirSync(dir, { recursive: true });
111
- const timestamp = nowFilenameStamp(now);
112
- const filePath = path.join(dir, `${timestamp}__${slug}.md`);
113
- // Spread `meta` first so internally computed `timestamp` and `slug`
114
- // always win. Otherwise a caller-supplied meta blob (parsed from the
115
- // MONODESIGN_CRITIQUE_META env var) could clobber them, leaving the
116
- // filename in disagreement with its frontmatter and corrupting trends.
117
- const front = serializeFrontmatter({ ...meta, timestamp, slug });
118
- fs.writeFileSync(filePath, `${front}\n${body.trim()}\n`, 'utf-8');
119
- return filePath;
120
- }
121
-
122
- function serializeFrontmatter(obj) {
123
- const lines = ['---'];
124
- for (const [key, value] of Object.entries(obj)) {
125
- if (value === undefined || value === null) continue;
126
- const str = typeof value === 'string' ? value : String(value);
127
- // Quote strings that contain : or # to keep parsing simple.
128
- const needsQuotes = typeof value === 'string' && /[:#]/.test(str);
129
- lines.push(`${key}: ${needsQuotes ? JSON.stringify(str) : str}`);
130
- }
131
- lines.push('---');
132
- return lines.join('\n');
133
- }
134
-
135
- function parseFrontmatter(text) {
136
- const match = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
137
- if (!match) return {};
138
- const out = {};
139
- for (const line of match[1].split(/\r?\n/)) {
140
- const colon = line.indexOf(':');
141
- if (colon < 0) continue;
142
- const key = line.slice(0, colon).trim();
143
- let value = line.slice(colon + 1).trim();
144
- if (/^".*"$/.test(value)) {
145
- try { value = JSON.parse(value); } catch { /* leave as-is */ }
146
- } else if (/^-?\d+$/.test(value)) {
147
- value = Number(value);
148
- }
149
- out[key] = value;
150
- }
151
- return out;
152
- }
153
-
154
- /**
155
- * Return all snapshot files for `slug`, sorted oldest → newest.
156
- */
157
- function listSnapshotsForSlug(slug, cwd) {
158
- const dir = getCritiqueDir(cwd);
159
- if (!fs.existsSync(dir)) return [];
160
- const suffix = `__${slug}.md`;
161
- return fs.readdirSync(dir)
162
- .filter((f) => f.endsWith(suffix))
163
- .sort()
164
- .map((f) => path.join(dir, f));
165
- }
166
-
167
- /**
168
- * Return the most recent snapshot for `slug`, or null. Polish reads this
169
- * to find its fix backlog when the slug matches.
170
- */
171
- export function readLatestSnapshot(slug, { cwd = process.cwd() } = {}) {
172
- const all = listSnapshotsForSlug(slug, cwd);
173
- if (!all.length) return null;
174
- const latest = all[all.length - 1];
175
- const body = fs.readFileSync(latest, 'utf-8');
176
- return { path: latest, body, meta: parseFrontmatter(body) };
177
- }
178
-
179
- /**
180
- * Return the last `limit` snapshots' frontmatter, oldest → newest.
181
- * Critique appends a one-line trend to its output using this.
182
- */
183
- export function readTrend(slug, { limit = 5, cwd = process.cwd() } = {}) {
184
- const all = listSnapshotsForSlug(slug, cwd);
185
- const slice = all.slice(-limit);
186
- return slice.map((file) => parseFrontmatter(fs.readFileSync(file, 'utf-8')));
187
- }
188
-
189
- // ---- Monomind memory mirror --------------------------------------------
190
-
191
- const asFiniteNumber = (v) => {
192
- const n = Number(v);
193
- return Number.isFinite(n) ? n : null;
194
- };
195
-
196
- /**
197
- * Locate a locally installed monomind CLI bin by climbing from `cwd`.
198
- * Returns null when none is installed — the caller then tries
199
- * `npx --no-install`, which also fails fast (and silently) when absent.
200
- */
201
- function resolveMonomindBin(cwd) {
202
- const name = process.platform === 'win32' ? 'monomind.cmd' : 'monomind';
203
- let dir = path.resolve(cwd);
204
- for (;;) {
205
- const bin = path.join(dir, 'node_modules', '.bin', name);
206
- try {
207
- fs.accessSync(bin, fs.constants.X_OK);
208
- return bin;
209
- } catch { /* keep climbing */ }
210
- const parent = path.dirname(dir);
211
- if (parent === dir) return null;
212
- dir = parent;
213
- }
214
- }
215
-
216
- /**
217
- * Best-effort mirror of a snapshot's structured metadata into monomind's
218
- * persistent memory (namespace `design-critique`, key `<project>-<slug>`,
219
- * upserted), so design health is queryable across sessions via
220
- * `monomind memory search`. Never throws and never fails the critique flow:
221
- * if the monomind CLI is unavailable the call is skipped silently.
222
- * Kill-switch: MONODESIGN_NO_MEMORY=1.
223
- */
224
- export function mirrorToMemory({ slug, meta = {}, filePath, cwd = process.cwd(), now = new Date(), env = process.env }) {
225
- if (!slug) return { mirrored: false, reason: 'no-slug' };
226
- if (env.MONODESIGN_NO_MEMORY === '1') return { mirrored: false, reason: 'disabled' };
227
- try {
228
- const record = {
229
- score: asFiniteNumber(meta.total_score ?? meta.score),
230
- p0: asFiniteNumber(meta.p0_count ?? meta.p0),
231
- p1: asFiniteNumber(meta.p1_count ?? meta.p1),
232
- date: now.toISOString(),
233
- slug,
234
- path: filePath ? path.relative(cwd, filePath).split(path.sep).join('/') : null,
235
- };
236
- const project = kebab(path.basename(path.resolve(cwd))) || 'project';
237
- const key = `${project}-${slug}`;
238
- const argv = [
239
- 'memory', 'store',
240
- '--key', key,
241
- '--value', JSON.stringify(record),
242
- '--namespace', 'design-critique',
243
- '--upsert',
244
- ];
245
- const bin = resolveMonomindBin(cwd);
246
- const opts = { cwd, env, stdio: 'ignore', timeout: 15000 };
247
- const run = bin
248
- ? spawnSync(bin, argv, opts)
249
- : spawnSync('npx', ['--no-install', 'monomind', ...argv], { ...opts, shell: process.platform === 'win32' });
250
- if (run.error || run.status !== 0) return { mirrored: false, reason: 'cli-unavailable' };
251
- return { mirrored: true, key };
252
- } catch {
253
- return { mirrored: false, reason: 'error' };
254
- }
255
- }
256
-
257
- // ---- Recall (latest + trend + open items, one compact block) -----------
258
-
259
- /**
260
- * Extract open issue titles tagged [P0] / [P1] from a snapshot body.
261
- * Matches the critique report's "**[P?] What**: ..." lines, but tolerates
262
- * loose formatting: any line containing `[P0]`/`[P1]` counts, with the
263
- * title taken from the text after the tag (markdown emphasis stripped).
264
- */
265
- export function extractIssueLines(body, { max = 8 } = {}) {
266
- const issues = { p0: [], p1: [] };
267
- if (!body || typeof body !== 'string') return issues;
268
- // Drop frontmatter so metadata lines never masquerade as issues.
269
- const text = body.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
270
- for (const line of text.split(/\r?\n/)) {
271
- const m = line.match(/\[(P0|P1)\]\s*(.*)/i);
272
- if (!m) continue;
273
- let title = m[2];
274
- // "**[P0] Title**: explanation" → keep just the title.
275
- const boldColon = title.indexOf('**:');
276
- if (boldColon !== -1) title = title.slice(0, boldColon);
277
- title = title.replace(/\*+/g, '').replace(/^[-–—\s]+/, '').replace(/[:\s]+$/, '').trim();
278
- if (!title) continue;
279
- const bucket = m[1].toUpperCase() === 'P0' ? issues.p0 : issues.p1;
280
- if (bucket.length < max && !bucket.includes(title)) bucket.push(title);
281
- }
282
- return issues;
283
- }
284
-
285
- /**
286
- * Direction of the last (up to) 3 finite scores: improving | declining |
287
- * flat, or null when fewer than 2 scores exist.
288
- */
289
- export function trendDirection(scores) {
290
- const s = (scores || []).map(asFiniteNumber).filter((n) => n !== null).slice(-3);
291
- if (s.length < 2) return null;
292
- if (s[s.length - 1] > s[0]) return 'improving';
293
- if (s[s.length - 1] < s[0]) return 'declining';
294
- return 'flat';
295
- }
296
-
297
- /**
298
- * Combined latest + trend + open-issue view for `slug`, or null when no
299
- * snapshot exists. This backs the `recall` subcommand that polish/critique
300
- * consume instead of separate latest+trend calls.
301
- */
302
- export function readRecall(slug, { limit = 5, cwd = process.cwd() } = {}) {
303
- const latest = readLatestSnapshot(slug, { cwd });
304
- if (!latest) return null;
305
- const trend = readTrend(slug, { limit, cwd });
306
- const scores = trend.map((t) => asFiniteNumber(t.total_score ?? t.score));
307
- return {
308
- slug,
309
- latest,
310
- trend,
311
- scores,
312
- direction: trendDirection(scores),
313
- issues: extractIssueLines(latest.body),
314
- };
315
- }
316
-
317
- /** Render a recall result as a compact markdown block. */
318
- export function formatRecall(recall, { cwd = process.cwd() } = {}) {
319
- const { slug, latest, trend, scores, direction, issues } = recall;
320
- const meta = latest.meta;
321
- const score = asFiniteNumber(meta.total_score ?? meta.score);
322
- const p0 = asFiniteNumber(meta.p0_count ?? meta.p0);
323
- const p1 = asFiniteNumber(meta.p1_count ?? meta.p1);
324
- const lines = [`## Design health: \`${slug}\``];
325
- lines.push(
326
- `- Latest score: ${score !== null ? `${score}/40` : 'n/a'}`
327
- + ` (P0: ${p0 ?? '?'}, P1: ${p1 ?? '?'})`
328
- + (meta.timestamp ? ` — ${meta.timestamp}` : ''),
329
- );
330
- const arrows = scores.map((n) => (n === null ? '?' : n)).join(' → ');
331
- lines.push(`- Trend (last ${trend.length}): ${arrows}${direction ? ` (${direction})` : ''}`);
332
- if (issues.p0.length) {
333
- lines.push('- Open P0:');
334
- for (const t of issues.p0) lines.push(` - ${t}`);
335
- }
336
- if (issues.p1.length) {
337
- lines.push('- Open P1:');
338
- for (const t of issues.p1) lines.push(` - ${t}`);
339
- }
340
- if (!issues.p0.length && !issues.p1.length) {
341
- lines.push('- No open P0/P1 lines found in the latest snapshot.');
342
- }
343
- lines.push(`- Snapshot: ${path.relative(cwd, latest.path).split(path.sep).join('/')}`);
344
- return lines.join('\n');
345
- }
346
-
347
- // ---- CLI ---------------------------------------------------------------
348
-
349
- function main(argv) {
350
- const [cmd, ...args] = argv;
351
- switch (cmd) {
352
- case 'slug': {
353
- const slug = slugFromTarget(args[0]);
354
- if (!slug) { process.stderr.write('no stable slug for input\n'); process.exit(1); }
355
- process.stdout.write(`${slug}\n`);
356
- return;
357
- }
358
- case 'write': {
359
- const [slug, bodyFile] = args;
360
- if (!slug || !bodyFile) { process.stderr.write('usage: write <slug> <body-file>\n'); process.exit(1); }
361
- const raw = fs.readFileSync(bodyFile, 'utf-8');
362
- // The body file may be a full report. The caller passes the meta as
363
- // a JSON object on stdin if it wants structured frontmatter; otherwise
364
- // we write with minimal metadata.
365
- let meta = {};
366
- const metaArg = process.env.MONODESIGN_CRITIQUE_META;
367
- if (metaArg) {
368
- try { meta = JSON.parse(metaArg); } catch { /* ignore */ }
369
- }
370
- const out = writeSnapshot({ slug, meta, body: raw });
371
- // Best-effort cross-session mirror; must never break the critique flow.
372
- mirrorToMemory({ slug, meta, filePath: out });
373
- process.stdout.write(`${out}\n`);
374
- return;
375
- }
376
- case 'latest': {
377
- const latest = readLatestSnapshot(args[0]);
378
- if (!latest) { process.exit(2); }
379
- process.stdout.write(latest.body);
380
- return;
381
- }
382
- case 'trend': {
383
- const rows = readTrend(args[0], { limit: args[1] ? Number(args[1]) : 5 });
384
- process.stdout.write(`${JSON.stringify(rows, null, 2)}\n`);
385
- return;
386
- }
387
- case 'recall': {
388
- const recall = readRecall(args[0], { limit: args[1] ? Number(args[1]) : 5 });
389
- if (!recall) { process.exit(2); }
390
- process.stdout.write(`${formatRecall(recall)}\n`);
391
- return;
392
- }
393
- default:
394
- process.stderr.write('usage: critique-storage.mjs <slug|write|latest|trend|recall> [args]\n');
395
- process.exit(1);
396
- }
397
- }
398
-
399
- function isMainModule() {
400
- if (!process.argv[1]) return false;
401
- try {
402
- return fs.realpathSync(fileURLToPath(import.meta.url)) === fs.realpathSync(process.argv[1]);
403
- } catch {
404
- // pathToFileURL normalizes Windows paths; keep it as a fallback for any
405
- // environment where realpath is unavailable.
406
- return import.meta.url === pathToFileURL(process.argv[1]).href;
407
- }
408
- }
409
-
410
- // Why the realpath check: generated skills are often reached through symlinked
411
- // harness directories (for example a demo repo's `.agents` -> source `.agents`).
412
- // Node resolves import.meta.url to the real file, while process.argv[1] keeps
413
- // the symlink path. Comparing canonical paths prevents a silent exit-0 no-op.
414
- if (isMainModule()) {
415
- main(process.argv.slice(2));
416
- }
@@ -1,193 +0,0 @@
1
- /**
2
- * Scan a project tree for Content-Security-Policy signals and classify the
3
- * shape so the agent knows which patch template to propose.
4
- *
5
- * Used at first-time `live.mjs` setup. Mechanical (grep-based) — no network,
6
- * no dev server, no JS evaluation. The classification drives a user-facing
7
- * consent prompt; the agent does the actual patch writing.
8
- *
9
- * Shapes are named by patch mechanism, not framework origin:
10
- * - "append-arrays": CSP defined as structured directive arrays. Patch
11
- * appends a dev-only localhost entry. Covers:
12
- * - Monorepo helpers with additional*Src options
13
- * (e.g. createBaseNextConfig for Next)
14
- * - SvelteKit kit.csp.directives
15
- * - nuxt-security module's contentSecurityPolicy
16
- * - "append-string": CSP built as a literal value string. Patch splices
17
- * a dev-only token into script-src and connect-src.
18
- * Covers:
19
- * - Inline Next.js headers() with CSP string
20
- * - Nuxt routeRules / nitro.routeRules CSP headers
21
- * - "middleware": CSP set dynamically in middleware.{ts,js}.
22
- * Detected but not auto-patched in v1.
23
- * - "meta-tag": <meta http-equiv="Content-Security-Policy"> in
24
- * layout files. Detected but not auto-patched in v1.
25
- * - null: no CSP signals found; no patch needed.
26
- */
27
-
28
- import fs from 'node:fs';
29
- import path from 'node:path';
30
-
31
- const SKIP_DIRS = new Set([
32
- 'node_modules',
33
- '.git',
34
- '.next',
35
- '.turbo',
36
- '.svelte-kit',
37
- '.nuxt',
38
- '.astro',
39
- 'dist',
40
- 'build',
41
- 'out',
42
- '.vercel',
43
- ]);
44
-
45
- const SCAN_EXTS = new Set(['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts', '.tsx', '.jsx']);
46
- const LAYOUT_EXTS = new Set(['.tsx', '.jsx', '.astro', '.vue', '.svelte', '.html']);
47
- const MAX_DEPTH = 6;
48
- const MAX_READ_BYTES = 64 * 1024;
49
-
50
- // append-arrays signals: CSP expressed as structured directive arrays
51
- const MONOREPO_HELPER_SIGNALS = [
52
- /\bbuildCSPConfig\b/,
53
- /\bbuildSecurityHeaders\b/,
54
- /\badditionalScriptSrc\b/,
55
- /\badditionalConnectSrc\b/,
56
- /\bcreateBaseNextConfig\b/,
57
- ];
58
- const SVELTEKIT_CSP_SIGNALS = [
59
- /\bkit\s*:/,
60
- /\bcsp\s*:/,
61
- /\bdirectives\s*:/,
62
- ];
63
- const NUXT_SECURITY_SIGNALS = [
64
- /['"]nuxt-security['"]/,
65
- /\bcontentSecurityPolicy\b/,
66
- ];
67
-
68
- // append-string signals: CSP written as a literal value string
69
- const INLINE_HEADER_SIGNALS = [
70
- /["']Content-Security-Policy["']/i,
71
- /\bscript-src\b/,
72
- /\bconnect-src\b/,
73
- ];
74
-
75
- const MIDDLEWARE_HINT = /headers\.set\(\s*["']Content-Security-Policy["']/i;
76
- const META_TAG_HINT = /http-equiv\s*=\s*["']Content-Security-Policy["']/i;
77
-
78
- /**
79
- * @param {string} cwd Project root.
80
- * @returns {{ shape: string|null, signals: string[] }}
81
- */
82
- export function detectCsp(cwd = process.cwd()) {
83
- const hits = { appendArrays: [], appendString: [], middleware: [], metaTag: [] };
84
-
85
- walk(cwd, cwd, 0, (absPath, relPath, body) => {
86
- const ext = path.extname(absPath);
87
- const base = path.basename(absPath).toLowerCase();
88
- const isConfig = (name) =>
89
- new RegExp(`(^|/)${name}\\.config\\.`).test(relPath);
90
-
91
- // === append-arrays candidates ===
92
-
93
- // Monorepo CSP helper: packages/*/src/.../(config|security)/*
94
- if (SCAN_EXTS.has(ext) &&
95
- /packages\/[^/]+\/src\/.*(config|next-config|security)/.test(relPath) &&
96
- MONOREPO_HELPER_SIGNALS.some((re) => re.test(body))) {
97
- hits.appendArrays.push(relPath);
98
- return;
99
- }
100
-
101
- // SvelteKit kit.csp.directives
102
- if (SCAN_EXTS.has(ext) && isConfig('svelte') &&
103
- SVELTEKIT_CSP_SIGNALS.every((re) => re.test(body))) {
104
- hits.appendArrays.push(relPath);
105
- return;
106
- }
107
-
108
- // Nuxt nuxt-security module
109
- if (SCAN_EXTS.has(ext) && isConfig('nuxt') &&
110
- NUXT_SECURITY_SIGNALS.every((re) => re.test(body))) {
111
- hits.appendArrays.push(relPath);
112
- return;
113
- }
114
-
115
- // === append-string candidates ===
116
-
117
- // Inline headers in Next/Nuxt/SvelteKit/Astro/Vite config
118
- if (SCAN_EXTS.has(ext) &&
119
- /(^|\/)(next|nuxt|vite|astro|svelte)\.config\./.test(relPath) &&
120
- INLINE_HEADER_SIGNALS.every((re) => re.test(body))) {
121
- // Nuxt routeRules is a sub-shape of append-string; we already covered
122
- // nuxt-security above via return, so any remaining Nuxt CSP match here
123
- // is a route-rules / inline-headers case. Either way, same patch
124
- // mechanism.
125
- hits.appendString.push(relPath);
126
- return;
127
- }
128
-
129
- // === detect-only shapes ===
130
-
131
- if ((base === 'middleware.ts' || base === 'middleware.js' || base === 'middleware.mjs') &&
132
- MIDDLEWARE_HINT.test(body)) {
133
- hits.middleware.push(relPath);
134
- }
135
-
136
- if (LAYOUT_EXTS.has(ext) && META_TAG_HINT.test(body)) {
137
- hits.metaTag.push(relPath);
138
- }
139
- });
140
-
141
- // Priority: append-arrays > append-string > middleware > meta-tag.
142
- // Structured patches are safer than string splices; runtime and HTML
143
- // injection patches are less reliable and v1 doesn't auto-apply them.
144
- if (hits.appendArrays.length > 0) {
145
- return { shape: 'append-arrays', signals: hits.appendArrays };
146
- }
147
- if (hits.appendString.length > 0) {
148
- return { shape: 'append-string', signals: hits.appendString };
149
- }
150
- if (hits.middleware.length > 0) {
151
- return { shape: 'middleware', signals: hits.middleware };
152
- }
153
- if (hits.metaTag.length > 0) {
154
- return { shape: 'meta-tag', signals: hits.metaTag };
155
- }
156
- return { shape: null, signals: [] };
157
- }
158
-
159
- function walk(root, dir, depth, visit) {
160
- if (depth > MAX_DEPTH) return;
161
- let entries;
162
- try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
163
- catch { return; }
164
-
165
- for (const entry of entries) {
166
- const abs = path.join(dir, entry.name);
167
- if (entry.isDirectory()) {
168
- if (SKIP_DIRS.has(entry.name)) continue;
169
- walk(root, abs, depth + 1, visit);
170
- continue;
171
- }
172
- if (!entry.isFile()) continue;
173
- const ext = path.extname(entry.name);
174
- if (!SCAN_EXTS.has(ext) && !LAYOUT_EXTS.has(ext)) continue;
175
- let body;
176
- try {
177
- const fd = fs.openSync(abs, 'r');
178
- try {
179
- const buf = Buffer.alloc(MAX_READ_BYTES);
180
- const n = fs.readSync(fd, buf, 0, MAX_READ_BYTES, 0);
181
- body = buf.slice(0, n).toString('utf-8');
182
- } finally { fs.closeSync(fd); }
183
- } catch { continue; }
184
- visit(abs, path.relative(root, abs).split(path.sep).join('/'), body);
185
- }
186
- }
187
-
188
- // CLI mode
189
- const _running = process.argv[1];
190
- if (_running?.endsWith('detect-csp.mjs') || _running?.endsWith('detect-csp.mjs/')) {
191
- const result = detectCsp(process.cwd());
192
- console.log(JSON.stringify(result, null, 2));
193
- }
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import { createRequire } from 'node:module';
6
- import { pathToFileURL, fileURLToPath } from 'node:url';
7
-
8
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
-
10
- // Packaged fallback: resolve the engine from an installed @monoes/monodesign.
11
- function packagedDetectorPath() {
12
- try {
13
- return createRequire(import.meta.url).resolve('@monoes/monodesign/engine');
14
- } catch {
15
- return null;
16
- }
17
- }
18
-
19
- const candidates = [
20
- path.join(__dirname, 'detector', 'detect-antipatterns.mjs'),
21
- path.join(__dirname, '..', '..', 'cli', 'engine', 'detect-antipatterns.mjs'),
22
- packagedDetectorPath(),
23
- ].filter(Boolean);
24
- const detectorPath = candidates.find(p => fs.existsSync(p));
25
-
26
- if (!detectorPath) {
27
- process.stderr.write('Error: bundled detector not found.\n');
28
- process.exit(1);
29
- }
30
-
31
- const { detectCli } = await import(pathToFileURL(detectorPath));
32
-
33
- await detectCli();