@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,69 +0,0 @@
1
- /**
2
- * Decide whether a given file is "generated" (regenerated by a build step,
3
- * unsafe to write variants into) or "source" (safe to edit, changes persist).
4
- *
5
- * Why this matters: when the user picks an element on a page whose underlying
6
- * file is regenerated by a build step (e.g. `scripts/build-sub-pages.js`
7
- * rewriting `public/docs/*.html`), writing variants or accepted changes into
8
- * that file is silent data loss — the next build wipes them.
9
- *
10
- * Signals, in order of reliability:
11
- * 1. Git check-ignore: gitignored files are assumed generated.
12
- * 2. File-header markers ("GENERATED", "DO NOT EDIT", "AUTO-GENERATED")
13
- * within the first ~300 characters — catches non-git projects.
14
- */
15
-
16
- import { execSync } from 'node:child_process';
17
- import fs from 'node:fs';
18
- import path from 'node:path';
19
-
20
- const HEADER_SCAN_BYTES = 300;
21
- const HEADER_MARKERS = [
22
- /@generated\b/i,
23
- /\bGENERATED\s+FILE\b/,
24
- /\bAUTO-?GENERATED\b/i,
25
- /\bDO\s+NOT\s+EDIT\b/i,
26
- ];
27
-
28
- /**
29
- * @param {string} filePath - absolute or cwd-relative path
30
- * @param {object} [options]
31
- * @param {string} [options.cwd] - project root (defaults to process.cwd())
32
- */
33
- export function isGeneratedFile(filePath, options = {}) {
34
- const cwd = options.cwd || process.cwd();
35
- const absPath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
36
-
37
- if (isGitIgnored(absPath, cwd)) return true;
38
- if (hasGeneratedHeader(absPath)) return true;
39
- return false;
40
- }
41
-
42
- function isGitIgnored(absPath, cwd) {
43
- try {
44
- execSync(`git check-ignore --quiet ${JSON.stringify(absPath)}`, {
45
- cwd,
46
- stdio: 'ignore',
47
- });
48
- return true; // exit 0 = ignored
49
- } catch {
50
- // Exit code 1 = not ignored. Exit code 128 = not a git repo or other error.
51
- // In both cases, treat as "not known to be ignored."
52
- return false;
53
- }
54
- }
55
-
56
- function hasGeneratedHeader(absPath) {
57
- let fd;
58
- try {
59
- fd = fs.openSync(absPath, 'r');
60
- const buf = Buffer.alloc(HEADER_SCAN_BYTES);
61
- const bytesRead = fs.readSync(fd, buf, 0, HEADER_SCAN_BYTES, 0);
62
- const head = buf.slice(0, bytesRead).toString('utf-8');
63
- return HEADER_MARKERS.some((re) => re.test(head));
64
- } catch {
65
- return false;
66
- } finally {
67
- if (fd !== undefined) { try { fs.closeSync(fd); } catch {} }
68
- }
69
- }
@@ -1,640 +0,0 @@
1
- /**
2
- * CLI-side reader/writer for the unified `.monodesign` config.
3
- *
4
- * The CLI (published to npm) and the skill scripts (bundled into the install)
5
- * live in separate trees and cannot share runtime code, so this duplicates a
6
- * small slice of skill/scripts/hook-lib.mjs — the config-path layout, detector
7
- * ignore semantics, and the `.git/info/exclude` handling. Keep the schema,
8
- * ignore filtering, and exclude marker in sync if either side changes.
9
- *
10
- * Schema (config.json shared / config.local.json gitignored, per-developer):
11
- * {
12
- * "detector": { "ignoreRules": [], "ignoreFiles": [], "ignoreValues": [], "designSystem": { "enabled": true } },
13
- * "hook": { "consent": "accepted" | "declined", ... },
14
- * "updateCheck": bool
15
- * }
16
- */
17
-
18
- import { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
19
- import { join, dirname, isAbsolute, relative, resolve, sep } from 'node:path';
20
-
21
- export function getConfigPath(root) {
22
- return join(root, '.monodesign', 'config.json');
23
- }
24
-
25
- export function getLocalConfigPath(root) {
26
- return join(root, '.monodesign', 'config.local.json');
27
- }
28
-
29
- function safeReadJson(filePath) {
30
- try {
31
- const raw = JSON.parse(readFileSync(filePath, 'utf-8'));
32
- return raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : null;
33
- } catch {
34
- return null;
35
- }
36
- }
37
-
38
- function hookSection(raw) {
39
- return raw?.hook && typeof raw.hook === 'object' && !Array.isArray(raw.hook) ? raw.hook : null;
40
- }
41
-
42
- function detectorSection(raw) {
43
- return raw?.detector && typeof raw.detector === 'object' && !Array.isArray(raw.detector) ? raw.detector : null;
44
- }
45
-
46
- const DETECTOR_CONFIG_KEYS = new Set(['ignoreRules', 'ignoreFiles', 'ignoreValues', 'designSystem']);
47
-
48
- const DEFAULT_DETECTION_CONFIG = Object.freeze({
49
- ignoreRules: [],
50
- ignoreFiles: [],
51
- ignoreValues: [],
52
- designSystem: { enabled: true },
53
- });
54
-
55
- function cloneDetectionConfig() {
56
- return {
57
- ignoreRules: [],
58
- ignoreFiles: [],
59
- ignoreValues: [],
60
- designSystem: { ...DEFAULT_DETECTION_CONFIG.designSystem },
61
- };
62
- }
63
-
64
- function cloneRawDetectionConfig() {
65
- return {
66
- ignoreRules: [],
67
- ignoreFiles: [],
68
- ignoreValues: [],
69
- };
70
- }
71
-
72
- function applyDetectionConfigSource(config, raw) {
73
- if (!raw || typeof raw !== 'object') return config;
74
- if (raw.designSystem && typeof raw.designSystem === 'object' && !Array.isArray(raw.designSystem)) {
75
- config.designSystem = {
76
- ...config.designSystem,
77
- enabled: raw.designSystem.enabled !== false,
78
- };
79
- }
80
- if (Array.isArray(raw.ignoreRules)) {
81
- config.ignoreRules = uniqueStrings([...config.ignoreRules, ...raw.ignoreRules]);
82
- }
83
- if (Array.isArray(raw.ignoreFiles)) {
84
- config.ignoreFiles = uniqueStrings([...config.ignoreFiles, ...raw.ignoreFiles]);
85
- }
86
- if (Array.isArray(raw.ignoreValues)) {
87
- config.ignoreValues = mergeIgnoreValues(config.ignoreValues, raw.ignoreValues);
88
- }
89
- return config;
90
- }
91
-
92
- function uniqueStrings(values) {
93
- return Array.from(new Set(values.map(String)));
94
- }
95
-
96
- /**
97
- * Detector filters shared by `monomind design detect` and the design hook.
98
- * `hook.enabled` remains hook lifecycle state; manual CLI scans still run when
99
- * the hook is disabled, but they honor the same ignore rules and design-system
100
- * toggle.
101
- */
102
- export function readDetectionConfig(root) {
103
- const config = cloneDetectionConfig();
104
- for (const filePath of [getConfigPath(root), getLocalConfigPath(root)]) {
105
- const raw = safeReadJson(filePath);
106
- // Back-compat: old builds stored detector filters under hook.*.
107
- applyDetectionConfigSource(config, hookSection(raw));
108
- applyDetectionConfigSource(config, detectorSection(raw));
109
- }
110
- return config;
111
- }
112
-
113
- export function readRawDetectionConfig(root, opts = {}) {
114
- const raw = safeReadJson(opts.local ? getLocalConfigPath(root) : getConfigPath(root));
115
- const config = cloneRawDetectionConfig();
116
- applyDetectionConfigSource(config, hookSection(raw));
117
- applyDetectionConfigSource(config, detectorSection(raw));
118
- return config;
119
- }
120
-
121
- export function writeDetectionConfig(root, detectorConfig, opts = {}) {
122
- const filePath = opts.local ? getLocalConfigPath(root) : getConfigPath(root);
123
- if (opts.local) ensureConfigGitExclude(root);
124
- const existing = safeReadJson(filePath) || {};
125
- const existingHook = hookSection(existing);
126
- const nextHook = stripDetectorKeys(existingHook);
127
- const nextDetector = {
128
- ...(detectorSection(existing) || {}),
129
- ...normalizeDetectionConfigForWrite(detectorConfig),
130
- };
131
- const next = {
132
- ...existing,
133
- detector: nextDetector,
134
- };
135
- if (nextHook && Object.keys(nextHook).length > 0) {
136
- next.hook = nextHook;
137
- } else {
138
- delete next.hook;
139
- }
140
- mkdirSync(dirname(filePath), { recursive: true });
141
- writeFileSync(filePath, `${JSON.stringify(next, null, 2)}\n`);
142
- return filePath;
143
- }
144
-
145
- function normalizeDetectionConfigForWrite(config) {
146
- const out = {};
147
- if (Array.isArray(config?.ignoreRules)) {
148
- out.ignoreRules = uniqueStrings(config.ignoreRules.map((rule) => normalizeIgnoreRule(rule)).filter(Boolean));
149
- }
150
- if (Array.isArray(config?.ignoreFiles)) {
151
- out.ignoreFiles = uniqueStrings(config.ignoreFiles.filter(v => typeof v === 'string' && v.trim()).map(v => v.trim()));
152
- }
153
- out.ignoreValues = normalizeIgnoreValueEntries(config?.ignoreValues || []);
154
- if (config?.designSystem && typeof config.designSystem === 'object' && !Array.isArray(config.designSystem)) {
155
- out.designSystem = {
156
- enabled: config.designSystem.enabled !== false,
157
- };
158
- }
159
- return out;
160
- }
161
-
162
- function stripDetectorKeys(raw) {
163
- if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
164
- const out = {};
165
- for (const [key, value] of Object.entries(raw)) {
166
- if (!DETECTOR_CONFIG_KEYS.has(key)) out[key] = value;
167
- }
168
- return out;
169
- }
170
-
171
- export function normalizeIgnoreValue(value) {
172
- return String(value || '')
173
- .trim()
174
- .replace(/^["']|["']$/g, '')
175
- .replace(/\+/g, ' ')
176
- .replace(/\s+/g, ' ')
177
- .toLowerCase();
178
- }
179
-
180
- function normalizeIgnoreRule(rule) {
181
- return String(rule || '').trim().toLowerCase();
182
- }
183
-
184
- function colorIgnoreKey(value) {
185
- const color = parseIgnoreColor(value);
186
- if (!color) return '';
187
- return `${color.r},${color.g},${color.b},${Math.round(color.a * 255)}`;
188
- }
189
-
190
- function parseIgnoreColor(value) {
191
- const text = String(value || '').trim().toLowerCase();
192
- if (!text) return null;
193
-
194
- const hex = text.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);
195
- if (hex) return parseHexIgnoreColor(hex[1]);
196
-
197
- const rgb = text.match(/^rgba?\((.*)\)$/i);
198
- if (rgb) {
199
- const parts = splitColorArgs(rgb[1]);
200
- if (parts.length < 3 || parts.length > 4) return null;
201
- const r = parseRgbChannel(parts[0]);
202
- const g = parseRgbChannel(parts[1]);
203
- const b = parseRgbChannel(parts[2]);
204
- const a = parts[3] === undefined ? 1 : parseAlphaChannel(parts[3]);
205
- if ([r, g, b, a].some((v) => v === null)) return null;
206
- return { r, g, b, a };
207
- }
208
-
209
- const hsl = text.match(/^hsla?\((.*)\)$/i);
210
- if (hsl) {
211
- const parts = splitColorArgs(hsl[1]);
212
- if (parts.length < 3 || parts.length > 4) return null;
213
- const h = parseHueChannel(parts[0]);
214
- const s = parsePercentChannel(parts[1]);
215
- const l = parsePercentChannel(parts[2]);
216
- const a = parts[3] === undefined ? 1 : parseAlphaChannel(parts[3]);
217
- if ([h, s, l, a].some((v) => v === null)) return null;
218
- return hslToRgb(h, s, l, a);
219
- }
220
-
221
- return null;
222
- }
223
-
224
- function parseHexIgnoreColor(hex) {
225
- if (hex.length === 3 || hex.length === 4) {
226
- const r = parseInt(hex[0] + hex[0], 16);
227
- const g = parseInt(hex[1] + hex[1], 16);
228
- const b = parseInt(hex[2] + hex[2], 16);
229
- const a = hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1;
230
- return { r, g, b, a };
231
- }
232
- const r = parseInt(hex.slice(0, 2), 16);
233
- const g = parseInt(hex.slice(2, 4), 16);
234
- const b = parseInt(hex.slice(4, 6), 16);
235
- const a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
236
- return { r, g, b, a };
237
- }
238
-
239
- function splitColorArgs(body) {
240
- const text = String(body || '').trim();
241
- if (!text) return [];
242
- if (text.includes(',')) {
243
- const parts = text.split(',').map((part) => part.trim()).filter(Boolean);
244
- const last = parts[parts.length - 1];
245
- if (last?.includes('/')) {
246
- const split = last.split('/').map((part) => part.trim()).filter(Boolean);
247
- return [...parts.slice(0, -1), ...split];
248
- }
249
- return parts;
250
- }
251
- return text.replace(/\s*\/\s*/g, ' / ').split(/\s+/).filter((part) => part && part !== '/');
252
- }
253
-
254
- function parseRgbChannel(raw) {
255
- const text = String(raw || '').trim();
256
- const match = text.match(/^(-?\d*\.?\d+)(%)?$/);
257
- if (!match) return null;
258
- const value = Number.parseFloat(match[1]);
259
- if (!Number.isFinite(value)) return null;
260
- const scaled = match[2] ? value * 2.55 : value;
261
- if (scaled < 0 || scaled > 255) return null;
262
- return Math.round(scaled);
263
- }
264
-
265
- function parseAlphaChannel(raw) {
266
- const text = String(raw || '').trim();
267
- const match = text.match(/^(-?\d*\.?\d+)(%)?$/);
268
- if (!match) return null;
269
- const value = Number.parseFloat(match[1]);
270
- if (!Number.isFinite(value)) return null;
271
- const alpha = match[2] ? value / 100 : value;
272
- return alpha >= 0 && alpha <= 1 ? alpha : null;
273
- }
274
-
275
- function parseHueChannel(raw) {
276
- const text = String(raw || '').trim();
277
- const match = text.match(/^(-?\d*\.?\d+)(deg|rad|turn|grad)?$/);
278
- if (!match) return null;
279
- const value = Number.parseFloat(match[1]);
280
- if (!Number.isFinite(value)) return null;
281
- const unit = match[2] || 'deg';
282
- if (unit === 'turn') return value * 360;
283
- if (unit === 'rad') return value * (180 / Math.PI);
284
- if (unit === 'grad') return value * 0.9;
285
- return value;
286
- }
287
-
288
- function parsePercentChannel(raw) {
289
- const text = String(raw || '').trim();
290
- const match = text.match(/^(-?\d*\.?\d+)%$/);
291
- if (!match) return null;
292
- const value = Number.parseFloat(match[1]);
293
- if (!Number.isFinite(value)) return null;
294
- return value >= 0 && value <= 100 ? value / 100 : null;
295
- }
296
-
297
- function hslToRgb(hue, saturation, lightness, alpha) {
298
- const h = (((hue % 360) + 360) % 360) / 360;
299
- if (saturation === 0) {
300
- const gray = clampByte(Math.round(lightness * 255));
301
- return { r: gray, g: gray, b: gray, a: alpha };
302
- }
303
- const q = lightness < 0.5
304
- ? lightness * (1 + saturation)
305
- : lightness + saturation - lightness * saturation;
306
- const p = 2 * lightness - q;
307
- const toRgb = (t) => {
308
- let channel = t;
309
- if (channel < 0) channel += 1;
310
- if (channel > 1) channel -= 1;
311
- if (channel < 1 / 6) return p + (q - p) * 6 * channel;
312
- if (channel < 1 / 2) return q;
313
- if (channel < 2 / 3) return p + (q - p) * (2 / 3 - channel) * 6;
314
- return p;
315
- };
316
- return {
317
- r: clampByte(Math.round(toRgb(h + 1 / 3) * 255)),
318
- g: clampByte(Math.round(toRgb(h) * 255)),
319
- b: clampByte(Math.round(toRgb(h - 1 / 3) * 255)),
320
- a: alpha,
321
- };
322
- }
323
-
324
- function clampByte(value) {
325
- return Math.min(255, Math.max(0, value));
326
- }
327
-
328
- function ignoreValueMatches(rule, entryValue, findingValue) {
329
- if (entryValue === findingValue) return true;
330
- if (rule !== 'design-system-color') return false;
331
- const entryColor = colorIgnoreKey(entryValue);
332
- return Boolean(entryColor && entryColor === colorIgnoreKey(findingValue));
333
- }
334
-
335
- export function normalizeIgnoreValueEntries(entries) {
336
- if (!Array.isArray(entries)) return [];
337
- const out = [];
338
- for (const entry of entries) {
339
- if (!entry || typeof entry !== 'object') continue;
340
- const rule = normalizeIgnoreRule(entry.rule);
341
- const value = normalizeIgnoreValue(entry.value);
342
- if (!rule || !value) continue;
343
- const normalized = { rule, value };
344
- const files = uniqueStrings([
345
- ...(typeof entry.file === 'string' && entry.file.trim() ? [entry.file.trim()] : []),
346
- ...(Array.isArray(entry.files) ? entry.files.filter(v => typeof v === 'string' && v.trim()).map(v => v.trim()) : []),
347
- ]);
348
- if (files.length > 0) normalized.files = files;
349
- if (typeof entry.reason === 'string' && entry.reason.trim()) {
350
- normalized.reason = entry.reason.trim();
351
- }
352
- if (typeof entry.createdAt === 'string' && entry.createdAt.trim()) {
353
- normalized.createdAt = entry.createdAt.trim();
354
- }
355
- out.push(normalized);
356
- }
357
- return out;
358
- }
359
-
360
- function mergeIgnoreValues(existing, incoming) {
361
- const map = new Map();
362
- for (const entry of normalizeIgnoreValueEntries(existing)) {
363
- map.set(`${entry.rule}\0${entry.value}\0${ignoreValueFilesKey(entry.files)}`, entry);
364
- }
365
- for (const entry of normalizeIgnoreValueEntries(incoming)) {
366
- map.set(`${entry.rule}\0${entry.value}\0${ignoreValueFilesKey(entry.files)}`, entry);
367
- }
368
- return Array.from(map.values());
369
- }
370
-
371
- function ignoreValueFilesKey(files) {
372
- return Array.isArray(files) && files.length > 0 ? files.join('\x1f') : '';
373
- }
374
-
375
- // Glob -> RegExp. Supports `**`, `*`, `?`, and `{a,b}` alternation.
376
- function globToRegex(glob) {
377
- let re = '^';
378
- let i = 0;
379
- while (i < glob.length) {
380
- const c = glob[i];
381
- if (c === '*') {
382
- if (glob[i + 1] === '*') {
383
- re += '.*';
384
- i += 2;
385
- if (glob[i] === '/') i += 1;
386
- } else {
387
- re += '[^/]*';
388
- i += 1;
389
- }
390
- } else if (c === '?') {
391
- re += '[^/]';
392
- i += 1;
393
- } else if (c === '{') {
394
- const end = glob.indexOf('}', i);
395
- if (end === -1) { re += '\\{'; i += 1; continue; }
396
- const parts = glob.slice(i + 1, end).split(',').map((p) => p.replace(/[.+^$()|[\]\\]/g, '\\$&'));
397
- re += `(?:${parts.join('|')})`;
398
- i = end + 1;
399
- } else if (/[.+^$()|[\]\\]/.test(c)) {
400
- re += `\\${c}`;
401
- i += 1;
402
- } else {
403
- re += c;
404
- i += 1;
405
- }
406
- }
407
- re += '$';
408
- return new RegExp(re);
409
- }
410
-
411
- export function matchesAnyGlob(filePath, globs) {
412
- if (!Array.isArray(globs) || globs.length === 0) return false;
413
- const normalized = String(filePath || '').split(sep).join('/');
414
- for (const glob of globs) {
415
- try {
416
- const re = globToRegex(String(glob));
417
- if (re.test(normalized)) return true;
418
- const base = normalized.split('/').pop();
419
- if (re.test(base)) return true;
420
- } catch {
421
- /* malformed glob, skip */
422
- }
423
- }
424
- return false;
425
- }
426
-
427
- export function shouldIgnoreDetectionFile(filePath, root, config) {
428
- const globs = config?.ignoreFiles || [];
429
- if (!Array.isArray(globs) || globs.length === 0) return false;
430
- const raw = String(filePath || '').trim();
431
- if (!raw) return false;
432
- if (matchesAnyGlob(raw, globs)) return true;
433
-
434
- try {
435
- const abs = isAbsolute(raw) ? raw : resolve(root, raw);
436
- if (matchesAnyGlob(abs, globs)) return true;
437
- const rel = relative(root, abs);
438
- if (rel && !rel.startsWith('..') && !isAbsolute(rel)) {
439
- return matchesAnyGlob(rel, globs);
440
- }
441
- } catch {
442
- /* ignore */
443
- }
444
- return false;
445
- }
446
-
447
- export function filterDetectionFindings(findings, config) {
448
- if (!Array.isArray(findings) || findings.length === 0) return [];
449
- const ignoreRules = new Set((config?.ignoreRules || []).map((rule) => normalizeIgnoreRule(rule)));
450
- const ignoreValues = normalizeIgnoreValueEntries(config?.ignoreValues || []);
451
- return findings.filter((finding) => {
452
- if (!finding || typeof finding !== 'object') return false;
453
- if (ignoreRules.has(normalizeIgnoreRule(finding.antipattern))) return false;
454
- if (isIgnoredFindingValue(finding, ignoreValues)) return false;
455
- return true;
456
- });
457
- }
458
-
459
- function isIgnoredFindingValue(finding, ignoreValues) {
460
- if (!Array.isArray(ignoreValues) || ignoreValues.length === 0) return false;
461
- const rule = normalizeIgnoreRule(finding.antipattern);
462
- if (!rule) return false;
463
- // File-scoped wildcards suppress rules with no extractable value, such as side-tab.
464
- const value = extractFindingIgnoreValue(finding);
465
- return ignoreValues.some((entry) => {
466
- if (entry.rule !== rule) return false;
467
- const wildcardValue = entry.value === '*';
468
- if (!wildcardValue && (!value || !ignoreValueMatches(rule, entry.value, value))) return false;
469
- if (!Array.isArray(entry.files) || entry.files.length === 0) return !wildcardValue;
470
- return findingMatchesScopedIgnoreFile(finding, entry.files);
471
- });
472
- }
473
-
474
- function findingMatchesScopedIgnoreFile(finding, globs) {
475
- const filePath = String(finding?.file || '').trim();
476
- if (!filePath) return false;
477
- if (matchesAnyGlob(filePath, globs)) return true;
478
-
479
- const normalized = filePath.split(sep).join('/');
480
- const parts = normalized.split('/').filter(Boolean);
481
- for (let i = 0; i < parts.length; i++) {
482
- const suffix = parts.slice(i).join('/');
483
- if (matchesAnyGlob(suffix, globs)) return true;
484
- }
485
- return false;
486
- }
487
-
488
- export function extractFindingIgnoreValue(finding) {
489
- if (!finding || typeof finding !== 'object') return '';
490
- const rule = normalizeIgnoreRule(finding.antipattern);
491
- const directValueRules = new Set([
492
- 'overused-font',
493
- 'bounce-easing',
494
- 'design-system-font',
495
- 'design-system-color',
496
- 'design-system-radius',
497
- ]);
498
- if (!directValueRules.has(rule)) return '';
499
- return normalizeIgnoreValue(extractFindingIgnoreValueRaw(finding, rule));
500
- }
501
-
502
- function extractFindingIgnoreValueRaw(finding, rule = normalizeIgnoreRule(finding?.antipattern)) {
503
- const direct = cleanIgnoreValueDisplay(finding.ignoreValue || finding.value || '');
504
- if (direct) return direct;
505
-
506
- const candidates = [finding.detail, finding.snippet].filter((v) => typeof v === 'string' && v);
507
- for (const text of candidates) {
508
- if (rule === 'bounce-easing') {
509
- const motion = extractMotionIgnoreValue(text);
510
- if (motion) return motion;
511
- continue;
512
- }
513
-
514
- const primary = text.match(/Primary font:\s*([^()\n;]+)/i);
515
- if (primary) return cleanIgnoreValueDisplay(primary[1]);
516
-
517
- const family = text.match(/font-family\s*:\s*["']?([^'",;\n]+)/i);
518
- if (family) return cleanIgnoreValueDisplay(family[1]);
519
-
520
- const google = text.match(/[?&]family=([^&:;\n]+)/i);
521
- if (google) {
522
- try {
523
- return cleanIgnoreValueDisplay(decodeURIComponent(google[1]));
524
- } catch {
525
- return cleanIgnoreValueDisplay(google[1]);
526
- }
527
- }
528
- }
529
-
530
- return '';
531
- }
532
-
533
- function extractMotionIgnoreValue(text) {
534
- const tailwind = text.match(/\banimate-bounce\b/i);
535
- if (tailwind) return cleanIgnoreValueDisplay(tailwind[0]);
536
-
537
- const bezier = text.match(/cubic-bezier\([^)]+\)/i);
538
- if (bezier) return cleanIgnoreValueDisplay(bezier[0]);
539
-
540
- const animation = text.match(/animation(?:-name)?\s*:\s*([^;\n]+)/i);
541
- if (animation) {
542
- const token = animation[1]
543
- .split(/[,\s]+/)
544
- .find((part) => /bounce|elastic|wobble|jiggle|spring/i.test(part));
545
- if (token) return cleanIgnoreValueDisplay(token);
546
- }
547
-
548
- return '';
549
- }
550
-
551
- function cleanIgnoreValueDisplay(value) {
552
- return String(value || '')
553
- .trim()
554
- .replace(/^["']|["']$/g, '')
555
- .replace(/\+/g, ' ')
556
- .replace(/\s+/g, ' ');
557
- }
558
-
559
- /**
560
- * The recorded design-hook decision: 'accepted' | 'declined' | undefined.
561
- * config.local.json (per-developer) overrides config.json.
562
- */
563
- export function getHookConsent(root) {
564
- let consent;
565
- for (const filePath of [getConfigPath(root), getLocalConfigPath(root)]) {
566
- const hook = hookSection(safeReadJson(filePath));
567
- if (hook && (hook.consent === 'accepted' || hook.consent === 'declined')) consent = hook.consent;
568
- }
569
- return consent;
570
- }
571
-
572
- /**
573
- * Persist the per-developer decision to config.local.json, preserving any
574
- * sibling keys, and ensure the file is gitignored.
575
- */
576
- export function setHookConsent(root, value) {
577
- const filePath = getLocalConfigPath(root);
578
- const existing = safeReadJson(filePath) || {};
579
- const hook = hookSection(existing) || {};
580
- const next = { ...existing, hook: { ...hook, consent: value } };
581
- mkdirSync(dirname(filePath), { recursive: true });
582
- writeFileSync(filePath, `${JSON.stringify(next, null, 2)}\n`);
583
- ensureConfigGitExclude(root);
584
- return filePath;
585
- }
586
-
587
- const EXCLUDE_OPEN = '# monodesign-config-ignore-start';
588
- const EXCLUDE_CLOSE = '# monodesign-config-ignore-end';
589
- const EXCLUDE_PATTERNS = ['.monodesign/config.local.json'];
590
-
591
- /**
592
- * Add config.local.json to `.git/info/exclude` so a developer's decision is
593
- * never committed. Idempotent via marker comments. Best-effort; returns false
594
- * when there is no resolvable git dir.
595
- */
596
- export function ensureConfigGitExclude(root) {
597
- try {
598
- const gitDir = resolveGitDir(root);
599
- if (!gitDir) return false;
600
- const target = join(gitDir, 'info', 'exclude');
601
- const existing = existsSync(target) ? readFileSync(target, 'utf-8') : '';
602
- const block = [EXCLUDE_OPEN, ...EXCLUDE_PATTERNS, EXCLUDE_CLOSE].join('\n');
603
- const markerRe = new RegExp(`${escapeRegExp(EXCLUDE_OPEN)}[\\s\\S]*?${escapeRegExp(EXCLUDE_CLOSE)}`);
604
- let updated;
605
- if (markerRe.test(existing)) {
606
- updated = existing.replace(markerRe, block);
607
- } else {
608
- const prefix = existing.length === 0 ? '' : existing.endsWith('\n') ? existing : `${existing}\n`;
609
- updated = `${prefix}${block}\n`;
610
- }
611
- if (updated !== existing) {
612
- mkdirSync(dirname(target), { recursive: true });
613
- writeFileSync(target, updated);
614
- }
615
- return true;
616
- } catch {
617
- return false;
618
- }
619
- }
620
-
621
- function resolveGitDir(root) {
622
- const dotGit = join(root, '.git');
623
- if (!existsSync(dotGit)) return null;
624
- try {
625
- if (statSync(dotGit).isDirectory()) return dotGit;
626
- // A `.git` file (worktree/submodule) points elsewhere: "gitdir: <path>".
627
- const match = readFileSync(dotGit, 'utf-8').match(/gitdir:\s*(.+)/);
628
- if (match) {
629
- const resolved = match[1].trim();
630
- return isAbsolute(resolved) ? resolved : join(root, resolved);
631
- }
632
- } catch {
633
- /* fall through */
634
- }
635
- return null;
636
- }
637
-
638
- function escapeRegExp(value) {
639
- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
640
- }