@monoes/monomindcli 2.16.1 → 2.16.2

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 (214) hide show
  1. package/.claude/helpers/handlers/edit-handler.cjs +14 -12
  2. package/.claude/helpers/handlers/route-handler.cjs +6 -0
  3. package/.claude/helpers/monograph-freshen.cjs +31 -113
  4. package/.claude/helpers/utils/monograph-resolve.cjs +497 -0
  5. package/.claude/helpers/utils/monograph.cjs +8 -51
  6. package/README.md +1 -1
  7. package/dist/src/commands/doctor-hook-monograph-checks.d.ts +8 -0
  8. package/dist/src/commands/doctor-hook-monograph-checks.d.ts.map +1 -0
  9. package/dist/src/commands/doctor-hook-monograph-checks.js +79 -0
  10. package/dist/src/commands/doctor-hook-monograph-checks.js.map +1 -0
  11. package/dist/src/commands/doctor.d.ts.map +1 -1
  12. package/dist/src/commands/doctor.js +4 -1
  13. package/dist/src/commands/doctor.js.map +1 -1
  14. package/dist/src/commands/monograph.d.ts.map +1 -1
  15. package/dist/src/commands/monograph.js +16 -1
  16. package/dist/src/commands/monograph.js.map +1 -1
  17. package/dist/src/orgrt/bash-timeout.d.ts +14 -0
  18. package/dist/src/orgrt/bash-timeout.d.ts.map +1 -0
  19. package/dist/src/orgrt/bash-timeout.js +18 -0
  20. package/dist/src/orgrt/bash-timeout.js.map +1 -0
  21. package/dist/src/orgrt/block-recheck.d.ts +30 -0
  22. package/dist/src/orgrt/block-recheck.d.ts.map +1 -0
  23. package/dist/src/orgrt/block-recheck.js +81 -0
  24. package/dist/src/orgrt/block-recheck.js.map +1 -0
  25. package/dist/src/orgrt/completion-gate.d.ts +4 -0
  26. package/dist/src/orgrt/completion-gate.d.ts.map +1 -1
  27. package/dist/src/orgrt/completion-gate.js +22 -2
  28. package/dist/src/orgrt/completion-gate.js.map +1 -1
  29. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  30. package/dist/src/orgrt/daemon.js +6 -4
  31. package/dist/src/orgrt/daemon.js.map +1 -1
  32. package/dist/src/orgrt/decisions.d.ts +1 -1
  33. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  34. package/dist/src/orgrt/decisions.js +14 -6
  35. package/dist/src/orgrt/decisions.js.map +1 -1
  36. package/dist/src/orgrt/mailbox.d.ts +14 -0
  37. package/dist/src/orgrt/mailbox.d.ts.map +1 -1
  38. package/dist/src/orgrt/mailbox.js +31 -1
  39. package/dist/src/orgrt/mailbox.js.map +1 -1
  40. package/dist/src/orgrt/sandbox-fault.d.ts +16 -6
  41. package/dist/src/orgrt/sandbox-fault.d.ts.map +1 -1
  42. package/dist/src/orgrt/sandbox-fault.js +78 -33
  43. package/dist/src/orgrt/sandbox-fault.js.map +1 -1
  44. package/dist/src/orgrt/session.d.ts +4 -3
  45. package/dist/src/orgrt/session.d.ts.map +1 -1
  46. package/dist/src/orgrt/session.js +24 -13
  47. package/dist/src/orgrt/session.js.map +1 -1
  48. package/dist/src/orgrt/task-dag.d.ts +8 -2
  49. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  50. package/dist/src/orgrt/task-dag.js +10 -4
  51. package/dist/src/orgrt/task-dag.js.map +1 -1
  52. package/dist/src/orgrt/types.d.ts +11 -0
  53. package/dist/src/orgrt/types.d.ts.map +1 -1
  54. package/dist/src/orgrt/types.js +18 -0
  55. package/dist/src/orgrt/types.js.map +1 -1
  56. package/dist/src/utils/resource-governor.d.ts.map +1 -1
  57. package/dist/src/utils/resource-governor.js +35 -2
  58. package/dist/src/utils/resource-governor.js.map +1 -1
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +6 -6
  61. package/.claude/skills/monodesign/SKILL.md +0 -257
  62. package/.claude/skills/monodesign/adapt.md +0 -53
  63. package/.claude/skills/monodesign/agents/monodesign-asset-producer.md +0 -100
  64. package/.claude/skills/monodesign/agents/monodesign-manual-edit-applier.md +0 -103
  65. package/.claude/skills/monodesign/animate.md +0 -65
  66. package/.claude/skills/monodesign/audit.md +0 -89
  67. package/.claude/skills/monodesign/bolder.md +0 -50
  68. package/.claude/skills/monodesign/clarify.md +0 -64
  69. package/.claude/skills/monodesign/colorize.md +0 -68
  70. package/.claude/skills/monodesign/craft.md +0 -51
  71. package/.claude/skills/monodesign/critique.md +0 -66
  72. package/.claude/skills/monodesign/delight.md +0 -47
  73. package/.claude/skills/monodesign/distill.md +0 -56
  74. package/.claude/skills/monodesign/document.md +0 -83
  75. package/.claude/skills/monodesign/extract.md +0 -74
  76. package/.claude/skills/monodesign/harden.md +0 -65
  77. package/.claude/skills/monodesign/init.md +0 -30
  78. package/.claude/skills/monodesign/layout.md +0 -36
  79. package/.claude/skills/monodesign/live.md +0 -34
  80. package/.claude/skills/monodesign/onboard.md +0 -50
  81. package/.claude/skills/monodesign/optimize.md +0 -64
  82. package/.claude/skills/monodesign/overdrive.md +0 -56
  83. package/.claude/skills/monodesign/polish.md +0 -68
  84. package/.claude/skills/monodesign/quieter.md +0 -57
  85. package/.claude/skills/monodesign/reference/adapt.md +0 -312
  86. package/.claude/skills/monodesign/reference/adapt.native.md +0 -58
  87. package/.claude/skills/monodesign/reference/android.md +0 -40
  88. package/.claude/skills/monodesign/reference/animate.md +0 -203
  89. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -410
  90. package/.claude/skills/monodesign/reference/audit.md +0 -135
  91. package/.claude/skills/monodesign/reference/audit.native.md +0 -139
  92. package/.claude/skills/monodesign/reference/bolder.md +0 -120
  93. package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
  94. package/.claude/skills/monodesign/reference/brand.md +0 -108
  95. package/.claude/skills/monodesign/reference/clarify.md +0 -288
  96. package/.claude/skills/monodesign/reference/codex.md +0 -105
  97. package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
  98. package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
  99. package/.claude/skills/monodesign/reference/colorize.md +0 -257
  100. package/.claude/skills/monodesign/reference/component-specs.md +0 -260
  101. package/.claude/skills/monodesign/reference/component-states.md +0 -274
  102. package/.claude/skills/monodesign/reference/component-system.md +0 -358
  103. package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
  104. package/.claude/skills/monodesign/reference/craft.md +0 -123
  105. package/.claude/skills/monodesign/reference/critique.md +0 -780
  106. package/.claude/skills/monodesign/reference/delight.md +0 -302
  107. package/.claude/skills/monodesign/reference/design-principles.md +0 -246
  108. package/.claude/skills/monodesign/reference/distill.md +0 -111
  109. package/.claude/skills/monodesign/reference/document.md +0 -429
  110. package/.claude/skills/monodesign/reference/extract.md +0 -69
  111. package/.claude/skills/monodesign/reference/harden.md +0 -347
  112. package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
  113. package/.claude/skills/monodesign/reference/hooks.md +0 -92
  114. package/.claude/skills/monodesign/reference/image-prompts.md +0 -130
  115. package/.claude/skills/monodesign/reference/init.md +0 -221
  116. package/.claude/skills/monodesign/reference/interaction-design.md +0 -189
  117. package/.claude/skills/monodesign/reference/ios.md +0 -45
  118. package/.claude/skills/monodesign/reference/layout.md +0 -185
  119. package/.claude/skills/monodesign/reference/live.md +0 -710
  120. package/.claude/skills/monodesign/reference/motion-design.md +0 -109
  121. package/.claude/skills/monodesign/reference/onboard.md +0 -234
  122. package/.claude/skills/monodesign/reference/optimize.md +0 -258
  123. package/.claude/skills/monodesign/reference/overdrive.md +0 -130
  124. package/.claude/skills/monodesign/reference/personas.md +0 -179
  125. package/.claude/skills/monodesign/reference/polish.md +0 -241
  126. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
  127. package/.claude/skills/monodesign/reference/product.md +0 -60
  128. package/.claude/skills/monodesign/reference/quieter.md +0 -99
  129. package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
  130. package/.claude/skills/monodesign/reference/shape.md +0 -165
  131. package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
  132. package/.claude/skills/monodesign/reference/teach.md +0 -10
  133. package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
  134. package/.claude/skills/monodesign/reference/typeset.md +0 -301
  135. package/.claude/skills/monodesign/reference/typography.md +0 -159
  136. package/.claude/skills/monodesign/reference/ux-research.md +0 -143
  137. package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
  138. package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
  139. package/.claude/skills/monodesign/scripts/command-metadata.json +0 -94
  140. package/.claude/skills/monodesign/scripts/context-signals.mjs +0 -260
  141. package/.claude/skills/monodesign/scripts/context.mjs +0 -1065
  142. package/.claude/skills/monodesign/scripts/critique-storage.mjs +0 -416
  143. package/.claude/skills/monodesign/scripts/detect-csp.mjs +0 -193
  144. package/.claude/skills/monodesign/scripts/detect.mjs +0 -33
  145. package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +0 -1960
  146. package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +0 -321
  147. package/.claude/skills/monodesign/scripts/detector/design-system.mjs +0 -814
  148. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +0 -5628
  149. package/.claude/skills/monodesign/scripts/detector/detect-antipatterns.mjs +0 -50
  150. package/.claude/skills/monodesign/scripts/detector/engines/browser/detect-url.mjs +0 -259
  151. package/.claude/skills/monodesign/scripts/detector/engines/browser/drivers.mjs +0 -339
  152. package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +0 -636
  153. package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +0 -1016
  154. package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +0 -253
  155. package/.claude/skills/monodesign/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -198
  156. package/.claude/skills/monodesign/scripts/detector/findings.mjs +0 -12
  157. package/.claude/skills/monodesign/scripts/detector/fix/css-regions.mjs +0 -181
  158. package/.claude/skills/monodesign/scripts/detector/fix/fixers.mjs +0 -373
  159. package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +0 -426
  160. package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +0 -198
  161. package/.claude/skills/monodesign/scripts/detector/profile/profiler.mjs +0 -166
  162. package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +0 -563
  163. package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +0 -3024
  164. package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +0 -124
  165. package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +0 -101
  166. package/.claude/skills/monodesign/scripts/detector/shared/fonts.mjs +0 -30
  167. package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +0 -148
  168. package/.claude/skills/monodesign/scripts/detector/shared/page.mjs +0 -7
  169. package/.claude/skills/monodesign/scripts/hook-admin.mjs +0 -694
  170. package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +0 -516
  171. package/.claude/skills/monodesign/scripts/hook-lib.mjs +0 -1785
  172. package/.claude/skills/monodesign/scripts/hook.mjs +0 -61
  173. package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +0 -809
  174. package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +0 -69
  175. package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +0 -640
  176. package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +0 -129
  177. package/.claude/skills/monodesign/scripts/lib/provider.mjs +0 -4
  178. package/.claude/skills/monodesign/scripts/lib/target-args.mjs +0 -42
  179. package/.claude/skills/monodesign/scripts/live/browser-script-parts.mjs +0 -50
  180. package/.claude/skills/monodesign/scripts/live/completion.mjs +0 -19
  181. package/.claude/skills/monodesign/scripts/live/event-validation.mjs +0 -137
  182. package/.claude/skills/monodesign/scripts/live/insert-ui.mjs +0 -458
  183. package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +0 -939
  184. package/.claude/skills/monodesign/scripts/live/manual-edit-routes.mjs +0 -357
  185. package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +0 -152
  186. package/.claude/skills/monodesign/scripts/live/session-store.mjs +0 -293
  187. package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +0 -826
  188. package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +0 -279
  189. package/.claude/skills/monodesign/scripts/live/ui-core.mjs +0 -180
  190. package/.claude/skills/monodesign/scripts/live/vocabulary.mjs +0 -36
  191. package/.claude/skills/monodesign/scripts/live-accept.mjs +0 -812
  192. package/.claude/skills/monodesign/scripts/live-browser-dom.js +0 -147
  193. package/.claude/skills/monodesign/scripts/live-browser-session.js +0 -124
  194. package/.claude/skills/monodesign/scripts/live-browser.js +0 -11213
  195. package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +0 -1241
  196. package/.claude/skills/monodesign/scripts/live-complete.mjs +0 -75
  197. package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +0 -683
  198. package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +0 -51
  199. package/.claude/skills/monodesign/scripts/live-inject.mjs +0 -596
  200. package/.claude/skills/monodesign/scripts/live-insert.mjs +0 -272
  201. package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +0 -363
  202. package/.claude/skills/monodesign/scripts/live-poll.mjs +0 -384
  203. package/.claude/skills/monodesign/scripts/live-resume.mjs +0 -94
  204. package/.claude/skills/monodesign/scripts/live-server.mjs +0 -1210
  205. package/.claude/skills/monodesign/scripts/live-status.mjs +0 -61
  206. package/.claude/skills/monodesign/scripts/live-target.mjs +0 -30
  207. package/.claude/skills/monodesign/scripts/live-wrap.mjs +0 -884
  208. package/.claude/skills/monodesign/scripts/live.mjs +0 -297
  209. package/.claude/skills/monodesign/scripts/modern-screenshot.umd.js +0 -14
  210. package/.claude/skills/monodesign/scripts/palette.mjs +0 -635
  211. package/.claude/skills/monodesign/scripts/pin.mjs +0 -221
  212. package/.claude/skills/monodesign/shape.md +0 -71
  213. package/.claude/skills/monodesign/teach.md +0 -18
  214. package/.claude/skills/monodesign/typeset.md +0 -59
@@ -1,426 +0,0 @@
1
- /**
2
- * Auto-fix engine: detect -> apply safe codemods -> re-detect -> report.
3
- *
4
- * Single-pass by design: every fixer is idempotent and lands values on the
5
- * safe side of its detector threshold, so the re-detect step only verifies —
6
- * it never triggers another round of edits (no oscillation).
7
- *
8
- * Honors the same filter pipeline as `detect`: project config ignores
9
- * (.monodesign/config.json), inline monodesign-disable* directives, and file
10
- * ignores — an ignored finding is never "fixed".
11
- */
12
-
13
- import fs from 'node:fs';
14
- import path from 'node:path';
15
-
16
- import { loadDesignSystemForCwd } from '../design-system.mjs';
17
- import { detectHtml } from '../engines/static-html/detect-html.mjs';
18
- import { detectText } from '../engines/regex/detect-text.mjs';
19
- import {
20
- filterDetectionFindings,
21
- readDetectionConfig,
22
- shouldIgnoreDetectionFile,
23
- } from '../../lib/monodesign-config.mjs';
24
- import { HTML_EXTENSIONS, walkDir } from '../node/file-system.mjs';
25
- import { UNFIXABLE_REASONS, getFixer, fixableRuleIds, FIXERS } from './fixers.mjs';
26
-
27
- // ---------------------------------------------------------------------------
28
- // Edit application
29
- // ---------------------------------------------------------------------------
30
-
31
- /** Apply edits to content. Edits are sorted; overlapping edits are dropped
32
- * (first wins). Returns { content, applied } — applied lists the edits used. */
33
- function applyEdits(content, edits) {
34
- const sorted = [...edits].sort((a, b) => a.start - b.start || a.end - b.end);
35
- const kept = [];
36
- let lastEnd = -1;
37
- for (const edit of sorted) {
38
- if (edit.start < lastEnd) continue; // overlap — first edit wins
39
- kept.push(edit);
40
- lastEnd = Math.max(edit.end, edit.start);
41
- }
42
- let result = content;
43
- for (let i = kept.length - 1; i >= 0; i--) {
44
- const { start, end, replacement } = kept[i];
45
- result = result.slice(0, start) + replacement + result.slice(end);
46
- }
47
- return { content: result, applied: kept };
48
- }
49
-
50
- /** Atomic write: temp file in the same directory, then rename over target. */
51
- function writeFileAtomic(filePath, content) {
52
- const tmp = path.join(
53
- path.dirname(filePath),
54
- `.${path.basename(filePath)}.${process.pid}.monodesign-tmp`,
55
- );
56
- fs.writeFileSync(tmp, content, 'utf-8');
57
- fs.renameSync(tmp, filePath);
58
- }
59
-
60
- // ---------------------------------------------------------------------------
61
- // Unified diff (minimal single-hunk implementation for --dry-run)
62
- // ---------------------------------------------------------------------------
63
-
64
- function unifiedDiff(oldText, newText, label) {
65
- if (oldText === newText) return '';
66
- const a = oldText.split('\n');
67
- const b = newText.split('\n');
68
- let p = 0;
69
- while (p < a.length && p < b.length && a[p] === b[p]) p++;
70
- let s = 0;
71
- while (s < a.length - p && s < b.length - p && a[a.length - 1 - s] === b[b.length - 1 - s]) s++;
72
- const aEnd = a.length - s;
73
- const bEnd = b.length - s;
74
- const ctxStart = Math.max(0, p - 3);
75
- const ctxEnd = Math.min(a.length, aEnd + 3);
76
- const oldLen = ctxEnd - ctxStart;
77
- const newLen = (p - ctxStart) + (bEnd - p) + (ctxEnd - aEnd);
78
- const lines = [`--- a/${label}`, `+++ b/${label}`, `@@ -${ctxStart + 1},${oldLen} +${ctxStart + 1},${newLen} @@`];
79
- for (let i = ctxStart; i < p; i++) lines.push(` ${a[i]}`);
80
- for (let i = p; i < aEnd; i++) lines.push(`-${a[i]}`);
81
- for (let i = p; i < bEnd; i++) lines.push(`+${b[i]}`);
82
- for (let i = aEnd; i < ctxEnd; i++) lines.push(` ${a[i]}`);
83
- return lines.join('\n');
84
- }
85
-
86
- // ---------------------------------------------------------------------------
87
- // Linked stylesheet resolution (HTML findings whose declaration lives in CSS)
88
- // ---------------------------------------------------------------------------
89
-
90
- function extractLinkedStylesheets(html, htmlPath) {
91
- const out = [];
92
- const linkRe = /<link\b[^>]*>/gi;
93
- let m;
94
- while ((m = linkRe.exec(html)) !== null) {
95
- const tag = m[0];
96
- if (!/rel\s*=\s*["']?stylesheet/i.test(tag)) continue;
97
- const href = tag.match(/href\s*=\s*["']([^"']+)["']/i)?.[1];
98
- if (!href || /^(?:https?:)?\/\//i.test(href) || href.startsWith('data:')) continue;
99
- const resolved = path.resolve(path.dirname(htmlPath), href.split(/[?#]/)[0]);
100
- if (fs.existsSync(resolved)) out.push(resolved);
101
- }
102
- return out;
103
- }
104
-
105
- // ---------------------------------------------------------------------------
106
- // Fix run
107
- // ---------------------------------------------------------------------------
108
-
109
- function groupByRule(findings) {
110
- const byRule = new Map();
111
- for (const f of findings) {
112
- if (!byRule.has(f.antipattern)) byRule.set(f.antipattern, []);
113
- byRule.get(f.antipattern).push(f);
114
- }
115
- return byRule;
116
- }
117
-
118
- /**
119
- * Run the fix loop over file/directory targets.
120
- *
121
- * options:
122
- * cwd — project root for config + design-system loading
123
- * dryRun — compute edits and diffs; write nothing
124
- * rules — restrict fixing to these rule ids
125
- * noConfig — skip project config + inline-ignore filtering
126
- *
127
- * Returns a report:
128
- * { dryRun, fixed, remaining, skipped, filesChanged, diffs, warnings }
129
- */
130
- async function runFix(targets, options = {}) {
131
- const cwd = options.cwd || process.cwd();
132
- const dryRun = Boolean(options.dryRun);
133
- const ruleFilter = options.rules?.length ? new Set(options.rules) : null;
134
- const config = options.noConfig
135
- ? { ignoreRules: [], ignoreFiles: [], ignoreValues: [] }
136
- : readDetectionConfig(cwd);
137
- const designSystemEnabled = !options.noConfig && config.designSystem?.enabled !== false;
138
- const designSystem = designSystemEnabled ? loadDesignSystemForCwd(cwd) : null;
139
- const scanOptions = { providers: [], inlineIgnores: !options.noConfig };
140
- if (designSystem) scanOptions.designSystem = designSystem;
141
-
142
- const warnings = [];
143
- const files = [];
144
- for (const target of targets) {
145
- if (/^https?:\/\//i.test(target)) {
146
- warnings.push(`Skipping URL target ${target}: fix operates on local files only.`);
147
- continue;
148
- }
149
- const resolved = path.resolve(cwd, target);
150
- let stat;
151
- try { stat = fs.statSync(resolved); }
152
- catch { warnings.push(`Warning: cannot access ${target}`); continue; }
153
- if (stat.isDirectory()) {
154
- files.push(...walkDir(resolved).filter(f => !shouldIgnoreDetectionFile(f, cwd, config)));
155
- } else if (!shouldIgnoreDetectionFile(resolved, cwd, config)) {
156
- files.push(resolved);
157
- }
158
- }
159
- const uniqueFiles = [...new Set(files)];
160
-
161
- const detectFile = async (file) => {
162
- const ext = path.extname(file).toLowerCase();
163
- const found = HTML_EXTENSIONS.has(ext)
164
- ? await detectHtml(file, scanOptions)
165
- : detectText(fs.readFileSync(file, 'utf-8'), file, scanOptions);
166
- return filterDetectionFindings(found, config);
167
- };
168
-
169
- // 1. Detect
170
- const findingsByFile = new Map();
171
- for (const file of uniqueFiles) {
172
- const found = await detectFile(file);
173
- if (found.length > 0) findingsByFile.set(file, found);
174
- }
175
-
176
- // 2. Plan + apply fixes in memory. Buffers exist only for files that carry
177
- // findings (or are stylesheets linked from such a file) — files with no
178
- // findings are never touched.
179
- const buffers = new Map(); // path -> { original, content, changed, parents:Set }
180
- const loadBuffer = (file) => {
181
- let buf = buffers.get(file);
182
- if (!buf) {
183
- const original = fs.readFileSync(file, 'utf-8');
184
- buf = { original, content: original, changed: false, parents: new Set() };
185
- buffers.set(file, buf);
186
- }
187
- return buf;
188
- };
189
-
190
- const skipped = []; // { file, antipattern, count, reason }
191
- const attempts = []; // { file, antipattern, before, notes, targetFile }
192
-
193
- for (const [file, findings] of findingsByFile) {
194
- const ext = path.extname(file).toLowerCase();
195
- for (const [rule, ruleFindings] of groupByRule(findings)) {
196
- const count = ruleFindings.length;
197
- if (ruleFilter && !ruleFilter.has(rule)) {
198
- skipped.push({ file, antipattern: rule, count, reason: 'excluded by --rule' });
199
- continue;
200
- }
201
- const fixer = getFixer(rule);
202
- if (!fixer) {
203
- skipped.push({
204
- file,
205
- antipattern: rule,
206
- count,
207
- reason: UNFIXABLE_REASONS[rule] || 'no deterministic safe fix exists for this rule',
208
- });
209
- continue;
210
- }
211
- const buf = loadBuffer(file);
212
- let edits = fixer.fix(buf.content, ext);
213
- let targetFile = file;
214
- if (edits.length === 0 && HTML_EXTENSIONS.has(ext)) {
215
- // The offending declaration may live in a linked stylesheet — the
216
- // detector cascades linked CSS into HTML findings.
217
- for (const cssPath of extractLinkedStylesheets(buf.original, file)) {
218
- const cssBuf = loadBuffer(cssPath);
219
- const cssEdits = fixer.fix(cssBuf.content, path.extname(cssPath).toLowerCase());
220
- if (cssEdits.length > 0) {
221
- edits = cssEdits;
222
- targetFile = cssPath;
223
- cssBuf.parents.add(file);
224
- break;
225
- }
226
- }
227
- }
228
- if (edits.length === 0) {
229
- skipped.push({
230
- file,
231
- antipattern: rule,
232
- count,
233
- reason: 'no safely rewritable declaration found in source',
234
- });
235
- continue;
236
- }
237
- const targetBuf = loadBuffer(targetFile);
238
- const { content, applied } = applyEdits(targetBuf.content, edits);
239
- if (content !== targetBuf.content) {
240
- targetBuf.content = content;
241
- targetBuf.changed = true;
242
- }
243
- attempts.push({
244
- file,
245
- antipattern: rule,
246
- before: count,
247
- targetFile,
248
- notes: applied.map(e => e.note).filter(Boolean),
249
- });
250
- }
251
- }
252
-
253
- const changedFiles = [...buffers.entries()].filter(([, b]) => b.changed);
254
- const filesChanged = changedFiles.map(([p]) => p);
255
-
256
- // 3. Write (atomic) or diff (dry-run)
257
- const diffs = [];
258
- if (dryRun) {
259
- for (const [p, b] of changedFiles) {
260
- diffs.push({ file: p, diff: unifiedDiff(b.original, b.content, path.relative(cwd, p).split(path.sep).join('/') || p) });
261
- }
262
- } else {
263
- for (const [p, b] of changedFiles) writeFileAtomic(p, b.content);
264
- }
265
-
266
- // 4. Re-detect touched files to verify (skip in dry-run — nothing changed
267
- // on disk). Linked-CSS edits are verified through their parent HTML.
268
- const remaining = [];
269
- if (!dryRun && changedFiles.length > 0) {
270
- const recheck = new Set();
271
- for (const [p, b] of changedFiles) {
272
- if (findingsByFile.has(p)) recheck.add(p);
273
- for (const parent of b.parents) recheck.add(parent);
274
- }
275
- const after = new Map();
276
- for (const p of recheck) after.set(p, await detectFile(p));
277
- for (const attempt of attempts) {
278
- const afterFindings = after.get(attempt.file) || [];
279
- const stillThere = afterFindings.filter(f => f.antipattern === attempt.antipattern).length;
280
- attempt.after = stillThere;
281
- attempt.fixed = Math.max(0, attempt.before - stillThere);
282
- if (stillThere > 0) {
283
- remaining.push({ file: attempt.file, antipattern: attempt.antipattern, count: stillThere });
284
- }
285
- }
286
- } else {
287
- for (const attempt of attempts) {
288
- attempt.after = dryRun ? null : attempt.before;
289
- attempt.fixed = dryRun ? attempt.before : 0;
290
- }
291
- }
292
-
293
- return {
294
- dryRun,
295
- fixed: attempts.map(a => ({
296
- file: a.file,
297
- antipattern: a.antipattern,
298
- before: a.before,
299
- after: a.after,
300
- fixed: a.fixed,
301
- targetFile: a.targetFile,
302
- notes: a.notes,
303
- })),
304
- remaining,
305
- skipped,
306
- filesChanged,
307
- diffs,
308
- warnings,
309
- };
310
- }
311
-
312
- // ---------------------------------------------------------------------------
313
- // CLI
314
- // ---------------------------------------------------------------------------
315
-
316
- function printFixUsage() {
317
- console.log(`Usage: monodesign fix [options] <file-or-dir...>
318
-
319
- Auto-fix detector findings where a deterministic, safe codemod exists.
320
- Runs detect, applies fixes, re-detects to verify, and reports
321
- fixed / remaining / skipped findings. Files without findings are never touched.
322
-
323
- Options:
324
- --dry-run Print unified diffs of would-be changes; write nothing
325
- --json Output the fix report as JSON
326
- --rule <id,...> Only fix the given rule ids
327
- --no-config Skip project config and inline-ignore filtering
328
- --help Show this help message
329
-
330
- Fixable rules:
331
- ${Object.entries(FIXERS).map(([id, f]) => ` ${id.padEnd(26)} ${f.description}`).join('\n')}
332
-
333
- Everything else is reported as skipped with a reason (e.g. broken-image:
334
- choosing a real image is a content decision, not a codemod).
335
-
336
- Examples:
337
- monodesign fix src/
338
- monodesign fix --dry-run index.html
339
- monodesign fix --rule tight-leading,tiny-text styles.css`);
340
- }
341
-
342
- function formatFixReport(report, jsonMode) {
343
- if (jsonMode) return JSON.stringify(report, null, 2);
344
- const out = [];
345
- if (report.dryRun) {
346
- for (const { diff } of report.diffs) {
347
- if (diff) out.push(diff, '');
348
- }
349
- }
350
- const verb = report.dryRun ? 'would fix' : 'fixed';
351
- for (const item of report.fixed) {
352
- const where = item.targetFile && item.targetFile !== item.file
353
- ? `${item.file} (edited ${item.targetFile})`
354
- : item.file;
355
- out.push(`${verb} [${item.antipattern}] ${item.fixed}/${item.before} in ${where}`);
356
- }
357
- for (const item of report.remaining) {
358
- out.push(`remaining [${item.antipattern}] ${item.count} in ${item.file}`);
359
- }
360
- for (const item of report.skipped) {
361
- out.push(`skipped [${item.antipattern}] ${item.count} in ${item.file} — ${item.reason}`);
362
- }
363
- const fixedTotal = report.fixed.reduce((n, f) => n + (f.fixed || 0), 0);
364
- const remainingTotal = report.remaining.reduce((n, f) => n + f.count, 0);
365
- const skippedTotal = report.skipped.reduce((n, f) => n + f.count, 0);
366
- out.push(`\n${report.dryRun ? 'Would fix' : 'Fixed'} ${fixedTotal}, remaining ${remainingTotal}, skipped ${skippedTotal}. ${report.filesChanged.length} file${report.filesChanged.length === 1 ? '' : 's'} ${report.dryRun ? 'would change' : 'changed'}.`);
367
- return out.join('\n');
368
- }
369
-
370
- async function runFixCli(args) {
371
- const targets = [];
372
- const options = { dryRun: false, rules: null, noConfig: false };
373
- let jsonMode = false;
374
- for (let i = 0; i < args.length; i++) {
375
- const arg = args[i];
376
- if (arg === '--help' || arg === '-h') { printFixUsage(); process.exit(0); }
377
- else if (arg === '--dry-run') options.dryRun = true;
378
- else if (arg === '--json') jsonMode = true;
379
- else if (arg === '--no-config') options.noConfig = true;
380
- else if (arg === '--rule' || arg.startsWith('--rule=')) {
381
- const value = arg.startsWith('--rule=') ? arg.slice('--rule='.length) : args[++i];
382
- if (!value || value.startsWith('--')) {
383
- process.stderr.write('Error: --rule requires a comma-separated list of rule ids.\n');
384
- process.exit(1);
385
- }
386
- options.rules = [...(options.rules || []), ...value.split(',').map(s => s.trim()).filter(Boolean)];
387
- } else if (arg.startsWith('--')) {
388
- process.stderr.write(`Error: unknown option ${arg}\n\nRun: monodesign fix --help\n`);
389
- process.exit(1);
390
- } else {
391
- targets.push(arg);
392
- }
393
- }
394
-
395
- if (options.rules) {
396
- const fixable = new Set(fixableRuleIds());
397
- const unknown = options.rules.filter(r => !fixable.has(r));
398
- if (unknown.length > 0) {
399
- process.stderr.write(`Error: no fixer for rule(s): ${unknown.join(', ')}.\nFixable rules: ${fixableRuleIds().join(', ')}\n`);
400
- process.exit(1);
401
- }
402
- }
403
-
404
- if (targets.length === 0) {
405
- process.stderr.write('Error: fix requires at least one file or directory target.\n\nRun: monodesign fix --help\n');
406
- process.exit(1);
407
- }
408
-
409
- const report = await runFix(targets, options);
410
- for (const warning of report.warnings) process.stderr.write(`${warning}\n`);
411
- const formatted = formatFixReport(report, jsonMode);
412
- if (jsonMode || report.dryRun) process.stdout.write(`${formatted}\n`);
413
- else process.stderr.write(`${formatted}\n`);
414
- process.exit(!report.dryRun && report.remaining.length > 0 ? 2 : 0);
415
- }
416
-
417
- export {
418
- runFix,
419
- runFixCli,
420
- applyEdits,
421
- unifiedDiff,
422
- writeFileAtomic,
423
- extractLinkedStylesheets,
424
- printFixUsage,
425
- formatFixReport,
426
- };
@@ -1,198 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- // ---------------------------------------------------------------------------
5
- // File walker
6
- // ---------------------------------------------------------------------------
7
-
8
- const SKIP_DIRS = new Set([
9
- 'node_modules', '.git', 'dist', 'build', '.next', '.nuxt', '.output',
10
- '.svelte-kit', '__pycache__', '.turbo', '.vercel',
11
- ]);
12
-
13
- const SCANNABLE_EXTENSIONS = new Set([
14
- '.html', '.htm', '.css', '.scss', '.sass', '.less',
15
- '.jsx', '.tsx', '.js', '.ts',
16
- '.vue', '.svelte', '.astro',
17
- ]);
18
-
19
- const HTML_EXTENSIONS = new Set(['.html', '.htm']);
20
-
21
- function walkDir(dir) {
22
- const files = [];
23
- let entries;
24
- try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return files; }
25
- for (const entry of entries) {
26
- if (SKIP_DIRS.has(entry.name)) continue;
27
- const full = path.join(dir, entry.name);
28
- if (entry.isDirectory()) files.push(...walkDir(full));
29
- else if (SCANNABLE_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) files.push(full);
30
- }
31
- return files;
32
- }
33
-
34
-
35
- // ---------------------------------------------------------------------------
36
- // Import graph (multi-file awareness)
37
- // ---------------------------------------------------------------------------
38
-
39
- function resolveImport(specifier, fromDir, fileSet) {
40
- if (!/^[./]/.test(specifier)) return null; // skip bare specifiers
41
- const base = path.resolve(fromDir, specifier);
42
- if (fileSet.has(base)) return base;
43
- for (const ext of SCANNABLE_EXTENSIONS) {
44
- const withExt = base + ext;
45
- if (fileSet.has(withExt)) return withExt;
46
- }
47
- // index file convention
48
- for (const ext of SCANNABLE_EXTENSIONS) {
49
- const indexFile = path.join(base, `index${ext}`);
50
- if (fileSet.has(indexFile)) return indexFile;
51
- }
52
- return null;
53
- }
54
-
55
- function buildImportGraph(files) {
56
- const fileSet = new Set(files);
57
- const graph = new Map();
58
-
59
- for (const file of files) {
60
- const content = fs.readFileSync(file, 'utf-8');
61
- const dir = path.dirname(file);
62
- const imports = new Set();
63
-
64
- // ES imports: import ... from '...' and import '...'
65
- const esRe = /import\s+(?:[\s\S]*?from\s+)?['"]([^'"]+)['"]/g;
66
- let m;
67
- while ((m = esRe.exec(content)) !== null) {
68
- const resolved = resolveImport(m[1], dir, fileSet);
69
- if (resolved) imports.add(resolved);
70
- }
71
-
72
- // CSS @import
73
- const cssRe = /@import\s+(?:url\(\s*)?['"]?([^'");\s]+)['"]?\s*\)?/g;
74
- while ((m = cssRe.exec(content)) !== null) {
75
- const resolved = resolveImport(m[1], dir, fileSet);
76
- if (resolved) imports.add(resolved);
77
- }
78
-
79
- // SCSS @use / @forward
80
- const scssRe = /@(?:use|forward)\s+['"]([^'"]+)['"]/g;
81
- while ((m = scssRe.exec(content)) !== null) {
82
- const resolved = resolveImport(m[1], dir, fileSet);
83
- if (resolved) imports.add(resolved);
84
- }
85
-
86
- graph.set(file, imports);
87
- }
88
- return graph;
89
- }
90
-
91
- // ---------------------------------------------------------------------------
92
- // Framework dev server detection
93
- // ---------------------------------------------------------------------------
94
-
95
- const FRAMEWORK_CONFIGS = [
96
- { name: 'Next.js', files: ['next.config.js', 'next.config.mjs', 'next.config.ts'], defaultPort: 3000,
97
- portRe: /port\s*[:=]\s*(\d+)/,
98
- fingerprint: { header: 'x-powered-by', value: /next/i } },
99
- { name: 'SvelteKit', files: ['svelte.config.js', 'svelte.config.ts'], defaultPort: 5173,
100
- portRe: /port\s*[:=]\s*(\d+)/,
101
- fingerprint: { header: 'x-sveltekit-page', value: null } },
102
- { name: 'Nuxt', files: ['nuxt.config.js', 'nuxt.config.ts'], defaultPort: 3000,
103
- portRe: /port\s*[:=]\s*(\d+)/,
104
- fingerprint: { header: 'x-powered-by', value: /nuxt/i } },
105
- { name: 'Vite', files: ['vite.config.js', 'vite.config.ts', 'vite.config.mjs'], defaultPort: 5173,
106
- portRe: /port\s*[:=]\s*(\d+)/,
107
- fingerprint: { body: /@vite\/client/ } },
108
- { name: 'Astro', files: ['astro.config.js', 'astro.config.ts', 'astro.config.mjs'], defaultPort: 4321,
109
- portRe: /port\s*[:=]\s*(\d+)/,
110
- fingerprint: { body: /astro/i } },
111
- { name: 'Angular', files: ['angular.json'], defaultPort: 4200,
112
- portRe: /"port"\s*:\s*(\d+)/,
113
- fingerprint: { body: /ng-version/i } },
114
- { name: 'Remix', files: ['remix.config.js', 'remix.config.ts'], defaultPort: 3000,
115
- portRe: /port\s*[:=]\s*(\d+)/,
116
- fingerprint: { header: 'x-powered-by', value: /remix/i } },
117
- ];
118
-
119
- function detectFrameworkConfig(dir) {
120
- let entries;
121
- try { entries = fs.readdirSync(dir); } catch { return null; }
122
- const entrySet = new Set(entries);
123
-
124
- for (const cfg of FRAMEWORK_CONFIGS) {
125
- const match = cfg.files.find(f => entrySet.has(f));
126
- if (!match) continue;
127
-
128
- const configPath = path.join(dir, match);
129
- let port = cfg.defaultPort;
130
- try {
131
- const content = fs.readFileSync(configPath, 'utf-8');
132
- const portMatch = content.match(cfg.portRe);
133
- if (portMatch) port = parseInt(portMatch[1], 10);
134
- } catch { /* use default */ }
135
-
136
- return { name: cfg.name, port, configPath, fingerprint: cfg.fingerprint };
137
- }
138
- return null;
139
- }
140
-
141
- /**
142
- * Check if a port is listening and optionally verify it matches the expected framework.
143
- * Returns { listening: true, matched: true/false } or { listening: false }.
144
- */
145
- async function isPortListening(port, fingerprint = null) {
146
- if (!fingerprint) {
147
- // Simple TCP probe fallback
148
- const net = await import('node:net');
149
- return new Promise((resolve) => {
150
- const sock = net.default.createConnection({ port, host: '127.0.0.1' });
151
- sock.setTimeout(500);
152
- sock.on('connect', () => { sock.destroy(); resolve({ listening: true, matched: true }); });
153
- sock.on('error', () => resolve({ listening: false }));
154
- sock.on('timeout', () => { sock.destroy(); resolve({ listening: false }); });
155
- });
156
- }
157
-
158
- // HTTP probe with fingerprint matching
159
- try {
160
- const controller = new AbortController();
161
- const timeout = setTimeout(() => controller.abort(), 2000);
162
- const res = await fetch(`http://localhost:${port}/`, { signal: controller.signal, redirect: 'follow' });
163
- clearTimeout(timeout);
164
-
165
- // Check header fingerprint
166
- if (fingerprint.header) {
167
- const val = res.headers.get(fingerprint.header);
168
- if (val && (!fingerprint.value || fingerprint.value.test(val))) {
169
- return { listening: true, matched: true };
170
- }
171
- }
172
-
173
- // Check body fingerprint
174
- if (fingerprint.body) {
175
- const body = await res.text();
176
- if (fingerprint.body.test(body)) {
177
- return { listening: true, matched: true };
178
- }
179
- }
180
-
181
- // Port is listening but doesn't match the expected framework
182
- return { listening: true, matched: false };
183
- } catch {
184
- return { listening: false };
185
- }
186
- }
187
-
188
- export {
189
- SKIP_DIRS,
190
- SCANNABLE_EXTENSIONS,
191
- HTML_EXTENSIONS,
192
- walkDir,
193
- resolveImport,
194
- buildImportGraph,
195
- FRAMEWORK_CONFIGS,
196
- detectFrameworkConfig,
197
- isPortListening,
198
- };