@monoes/monomindcli 2.15.5 → 2.15.7

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 (226) hide show
  1. package/dist/src/commands/cleanup-plan.d.ts +57 -0
  2. package/dist/src/commands/cleanup-plan.d.ts.map +1 -0
  3. package/dist/src/commands/cleanup-plan.js +379 -0
  4. package/dist/src/commands/cleanup-plan.js.map +1 -0
  5. package/dist/src/commands/cleanup.d.ts.map +1 -1
  6. package/dist/src/commands/cleanup.js +87 -160
  7. package/dist/src/commands/cleanup.js.map +1 -1
  8. package/dist/src/commands/search-universal.d.ts +8 -0
  9. package/dist/src/commands/search-universal.d.ts.map +1 -1
  10. package/dist/src/commands/search-universal.js +14 -0
  11. package/dist/src/commands/search-universal.js.map +1 -1
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +11 -2
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/orgrt/completion-gate.d.ts +40 -0
  16. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  17. package/dist/src/orgrt/completion-gate.js +90 -9
  18. package/dist/src/orgrt/completion-gate.js.map +1 -1
  19. package/dist/src/orgrt/daemon.d.ts +4 -0
  20. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  21. package/dist/src/orgrt/daemon.js +15 -2
  22. package/dist/src/orgrt/daemon.js.map +1 -1
  23. package/dist/src/orgrt/decisions.d.ts +24 -1
  24. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  25. package/dist/src/orgrt/decisions.js +171 -11
  26. package/dist/src/orgrt/decisions.js.map +1 -1
  27. package/dist/src/orgrt/idle-deadline.d.ts +10 -0
  28. package/dist/src/orgrt/idle-deadline.d.ts.map +1 -1
  29. package/dist/src/orgrt/idle-deadline.js +8 -0
  30. package/dist/src/orgrt/idle-deadline.js.map +1 -1
  31. package/dist/src/orgrt/mailbox.d.ts +7 -0
  32. package/dist/src/orgrt/mailbox.d.ts.map +1 -1
  33. package/dist/src/orgrt/mailbox.js +14 -0
  34. package/dist/src/orgrt/mailbox.js.map +1 -1
  35. package/dist/src/orgrt/review-packet.d.ts +1 -1
  36. package/dist/src/orgrt/review-packet.d.ts.map +1 -1
  37. package/dist/src/orgrt/review-packet.js +2 -1
  38. package/dist/src/orgrt/review-packet.js.map +1 -1
  39. package/dist/src/orgrt/role-sandbox.d.ts +1 -0
  40. package/dist/src/orgrt/role-sandbox.d.ts.map +1 -1
  41. package/dist/src/orgrt/role-sandbox.js +6 -1
  42. package/dist/src/orgrt/role-sandbox.js.map +1 -1
  43. package/dist/src/orgrt/session.d.ts +3 -0
  44. package/dist/src/orgrt/session.d.ts.map +1 -1
  45. package/dist/src/orgrt/session.js +8 -1
  46. package/dist/src/orgrt/session.js.map +1 -1
  47. package/dist/src/orgrt/task-dag.d.ts +3 -0
  48. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  49. package/dist/src/orgrt/task-dag.js +7 -0
  50. package/dist/src/orgrt/task-dag.js.map +1 -1
  51. package/dist/src/orgrt/types.d.ts +3 -0
  52. package/dist/src/orgrt/types.d.ts.map +1 -1
  53. package/dist/src/orgrt/types.js +6 -2
  54. package/dist/src/orgrt/types.js.map +1 -1
  55. package/dist/src/update/checker.d.ts +3 -1
  56. package/dist/src/update/checker.d.ts.map +1 -1
  57. package/dist/src/update/checker.js +7 -3
  58. package/dist/src/update/checker.js.map +1 -1
  59. package/dist/src/update/index.d.ts +16 -0
  60. package/dist/src/update/index.d.ts.map +1 -1
  61. package/dist/src/update/index.js +37 -1
  62. package/dist/src/update/index.js.map +1 -1
  63. package/dist/src/update/refresh-worker.d.ts +9 -0
  64. package/dist/src/update/refresh-worker.d.ts.map +1 -0
  65. package/dist/src/update/refresh-worker.js +17 -0
  66. package/dist/src/update/refresh-worker.js.map +1 -0
  67. package/dist/src/utils/resource-governor.d.ts +44 -2
  68. package/dist/src/utils/resource-governor.d.ts.map +1 -1
  69. package/dist/src/utils/resource-governor.js +157 -40
  70. package/dist/src/utils/resource-governor.js.map +1 -1
  71. package/dist/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +4 -4
  73. package/.claude/skills/monodesign/SKILL.md +0 -257
  74. package/.claude/skills/monodesign/adapt.md +0 -53
  75. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  76. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  77. package/.claude/skills/monodesign/animate.md +0 -65
  78. package/.claude/skills/monodesign/audit.md +0 -89
  79. package/.claude/skills/monodesign/bolder.md +0 -50
  80. package/.claude/skills/monodesign/clarify.md +0 -64
  81. package/.claude/skills/monodesign/colorize.md +0 -68
  82. package/.claude/skills/monodesign/craft.md +0 -51
  83. package/.claude/skills/monodesign/critique.md +0 -66
  84. package/.claude/skills/monodesign/delight.md +0 -47
  85. package/.claude/skills/monodesign/distill.md +0 -56
  86. package/.claude/skills/monodesign/document.md +0 -83
  87. package/.claude/skills/monodesign/extract.md +0 -74
  88. package/.claude/skills/monodesign/harden.md +0 -65
  89. package/.claude/skills/monodesign/init.md +0 -30
  90. package/.claude/skills/monodesign/layout.md +0 -36
  91. package/.claude/skills/monodesign/live.md +0 -34
  92. package/.claude/skills/monodesign/onboard.md +0 -50
  93. package/.claude/skills/monodesign/optimize.md +0 -64
  94. package/.claude/skills/monodesign/overdrive.md +0 -56
  95. package/.claude/skills/monodesign/polish.md +0 -68
  96. package/.claude/skills/monodesign/quieter.md +0 -57
  97. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  98. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  99. package/.claude/skills/monodesign/reference/android.md +0 -40
  100. package/.claude/skills/monodesign/reference/animate.md +0 -203
  101. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  102. package/.claude/skills/monodesign/reference/audit.md +0 -135
  103. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  104. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  105. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  106. package/.claude/skills/monodesign/reference/brand.md +0 -108
  107. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  108. package/.claude/skills/monodesign/reference/codex.md +0 -105
  109. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  110. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  111. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  112. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  113. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  114. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  115. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  116. package/.claude/skills/monodesign/reference/craft.md +0 -123
  117. package/.claude/skills/monodesign/reference/critique.md +0 -780
  118. package/.claude/skills/monodesign/reference/delight.md +0 -302
  119. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  120. package/.claude/skills/monodesign/reference/distill.md +0 -111
  121. package/.claude/skills/monodesign/reference/document.md +0 -429
  122. package/.claude/skills/monodesign/reference/extract.md +0 -69
  123. package/.claude/skills/monodesign/reference/harden.md +0 -347
  124. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  125. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  126. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  127. package/.claude/skills/monodesign/reference/init.md +0 -221
  128. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  129. package/.claude/skills/monodesign/reference/ios.md +0 -45
  130. package/.claude/skills/monodesign/reference/layout.md +0 -185
  131. package/.claude/skills/monodesign/reference/live.md +0 -710
  132. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  133. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  134. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  135. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  136. package/.claude/skills/monodesign/reference/personas.md +0 -179
  137. package/.claude/skills/monodesign/reference/polish.md +0 -241
  138. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  139. package/.claude/skills/monodesign/reference/product.md +0 -60
  140. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  141. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  142. package/.claude/skills/monodesign/reference/shape.md +0 -165
  143. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  144. package/.claude/skills/monodesign/reference/teach.md +0 -10
  145. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  146. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  147. package/.claude/skills/monodesign/reference/typography.md +0 -159
  148. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  149. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  150. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  151. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  152. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  153. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  154. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  155. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  156. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  157. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  158. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  159. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  160. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  161. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  162. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  163. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -349
  164. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  165. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  166. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  167. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  168. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  169. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  170. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  171. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  172. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  173. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  174. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  175. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  176. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  177. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  178. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  179. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  180. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  181. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  182. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  183. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  184. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  185. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  186. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  187. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  188. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  189. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  190. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  191. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  192. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  193. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  194. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  195. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  196. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  197. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  198. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  199. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  200. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  201. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  202. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  203. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  204. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  205. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  206. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  207. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  208. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  209. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  210. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  211. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  212. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  213. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  214. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  215. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  216. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  217. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  218. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  219. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  220. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  221. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  222. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  223. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  224. package/.claude/skills/monodesign/shape.md +0 -71
  225. package/.claude/skills/monodesign/teach.md +0 -18
  226. 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
- }