@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,272 +0,0 @@
1
- /**
2
- * CLI helper: find an anchor element in source and splice an insert-variant
3
- * wrapper before or after it (no original variant — net-new content).
4
- *
5
- * Usage:
6
- * node live-insert.mjs --id SESSION_ID --count N --position after \
7
- * --classes "hero" --tag section [--file path]
8
- */
9
-
10
- import fs from 'node:fs';
11
- import path from 'node:path';
12
- import { isGeneratedFile } from './lib/is-generated.mjs';
13
- import {
14
- buildSearchQueries,
15
- findElement,
16
- findAllElements,
17
- filterByText,
18
- findFileWithQuery,
19
- detectCommentSyntax,
20
- detectStyleMode,
21
- buildCssAuthoring,
22
- buildCssSelectorPrefixExamples,
23
- } from './live-wrap.mjs';
24
- import {
25
- buildSvelteComponentCssAuthoring,
26
- scaffoldSvelteComponentInsertSession,
27
- shouldUseSvelteComponentInjection,
28
- } from './live/svelte-component.mjs';
29
-
30
- const INSERT_POSITIONS = new Set(['before', 'after']);
31
-
32
- export function isInsertPosition(value) {
33
- return INSERT_POSITIONS.has(value);
34
- }
35
-
36
- export function computeInsertLine(startLine, endLine, position) {
37
- return position === 'before' ? startLine : endLine + 1;
38
- }
39
-
40
- export function buildInsertWrapperLines({ id, count, indent, commentSyntax, isJsx }) {
41
- const styleContents = isJsx ? 'style={{ display: "contents" }}' : 'style="display: contents"';
42
- const attrs =
43
- 'data-monodesign-variants="' + id + '" ' +
44
- 'data-monodesign-mode="insert" ' +
45
- 'data-monodesign-variant-count="' + count + '" ' +
46
- styleContents;
47
-
48
- if (isJsx) {
49
- return [
50
- `${indent}<div ${attrs}>`,
51
- `${indent} ${commentSyntax.open} monodesign-variants-start ${id} ${commentSyntax.close}`,
52
- `${indent} ${commentSyntax.open} Variants: insert below this line ${commentSyntax.close}`,
53
- `${indent} ${commentSyntax.open} monodesign-variants-end ${id} ${commentSyntax.close}`,
54
- `${indent}</div>`,
55
- ];
56
- }
57
-
58
- return [
59
- `${indent + commentSyntax.open} monodesign-variants-start ${id} ${commentSyntax.close}`,
60
- `${indent}<div ${attrs}>`,
61
- `${indent} ${commentSyntax.open} Variants: insert below this line ${commentSyntax.close}`,
62
- `${indent}</div>`,
63
- `${indent + commentSyntax.open} monodesign-variants-end ${id} ${commentSyntax.close}`,
64
- ];
65
- }
66
-
67
- function argVal(args, flag) {
68
- const idx = args.indexOf(flag);
69
- return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : null;
70
- }
71
-
72
- function resolveElementMatch({ lines, queries, tag, text }) {
73
- if (text) {
74
- const candidates = [];
75
- for (const q of queries) {
76
- const all = findAllElements(lines, q, tag);
77
- for (const c of all) {
78
- if (!candidates.some((x) => x.startLine === c.startLine)) candidates.push(c);
79
- }
80
- if (candidates.length === 1) break;
81
- }
82
- if (candidates.length === 0) return { error: 'element_not_found' };
83
- if (candidates.length === 1) return { match: candidates[0] };
84
- const filtered = filterByText(candidates, lines, text);
85
- if (filtered.length === 1) return { match: filtered[0] };
86
- if (filtered.length === 0) return { match: candidates[0] };
87
- return { error: 'element_ambiguous', candidates: filtered };
88
- }
89
-
90
- for (const q of queries) {
91
- const match = findElement(lines, q, tag);
92
- if (match) return { match };
93
- }
94
- return { error: 'element_not_found' };
95
- }
96
-
97
- export async function insertCli() {
98
- const args = process.argv.slice(2);
99
-
100
- if (args.includes('--help') || args.includes('-h')) {
101
- console.log(`Usage: node live-insert.mjs [options]
102
-
103
- Find an anchor element in source and splice an insert-variant wrapper.
104
-
105
- Required:
106
- --id ID Session ID for the variant wrapper
107
- --count N Number of expected variants (1-8)
108
- --position POS before | after (relative to the anchor element)
109
-
110
- Element identification (at least one required):
111
- --element-id ID HTML id attribute of the anchor element
112
- --classes A,B,C Comma-separated CSS class names
113
- --tag TAG Tag name (div, section, etc.)
114
- --query TEXT Fallback: raw text to search for
115
-
116
- Optional:
117
- --file PATH Source file to search in (skips auto-detection)
118
- --text TEXT Anchor textContent for disambiguation (~80 chars)
119
-
120
- Output (JSON):
121
- { mode: "insert", file, position, insertLine, commentSyntax, styleMode, styleTag, cssAuthoring }`);
122
- process.exit(0);
123
- }
124
-
125
- const id = argVal(args, '--id');
126
- const count = parseInt(argVal(args, '--count') || '3', 10);
127
- const position = argVal(args, '--position');
128
- const elementId = argVal(args, '--element-id');
129
- const classes = argVal(args, '--classes');
130
- const tag = argVal(args, '--tag');
131
- const query = argVal(args, '--query');
132
- const filePath = argVal(args, '--file');
133
- const text = argVal(args, '--text');
134
-
135
- if (!id) { console.error('Missing --id'); process.exit(1); }
136
- if (!position) { console.error('Missing --position (before | after)'); process.exit(1); }
137
- if (!isInsertPosition(position)) { console.error(`Invalid --position: ${position}`); process.exit(1); }
138
- if (!elementId && !classes && !query) {
139
- console.error('Need at least one of: --element-id, --classes, --query');
140
- process.exit(1);
141
- }
142
-
143
- const queries = buildSearchQueries(elementId, classes, tag, query);
144
- const genOpts = { cwd: process.cwd() };
145
-
146
- let targetFile = filePath;
147
- if (!targetFile) {
148
- for (const q of queries) {
149
- targetFile = findFileWithQuery(q, process.cwd(), genOpts);
150
- if (targetFile) break;
151
- }
152
- if (!targetFile) {
153
- let generatedHit = null;
154
- for (const q of queries) {
155
- generatedHit = findFileWithQuery(q, process.cwd(), { ...genOpts, includeGenerated: true });
156
- if (generatedHit) break;
157
- }
158
- console.error(JSON.stringify({
159
- error: generatedHit ? 'element_not_in_source' : 'element_not_found',
160
- fallback: 'agent-driven',
161
- hint: 'See "Handle fallback" in live.md.',
162
- }));
163
- process.exit(1);
164
- }
165
- } else if (isGeneratedFile(targetFile, genOpts)) {
166
- console.error(JSON.stringify({
167
- error: 'file_is_generated',
168
- fallback: 'agent-driven',
169
- file: path.relative(process.cwd(), path.resolve(process.cwd(), targetFile)).split(path.sep).join('/'),
170
- }));
171
- process.exit(1);
172
- }
173
-
174
- const content = fs.readFileSync(targetFile, 'utf-8');
175
- const lines = content.split('\n');
176
- const resolved = resolveElementMatch({ lines, queries, tag, text });
177
-
178
- if (resolved.error === 'element_ambiguous') {
179
- console.error(JSON.stringify({
180
- error: 'element_ambiguous',
181
- fallback: 'agent-driven',
182
- file: path.relative(process.cwd(), targetFile).split(path.sep).join('/'),
183
- candidates: resolved.candidates.map((c) => ({
184
- startLine: c.startLine + 1,
185
- endLine: c.endLine + 1,
186
- })),
187
- }));
188
- process.exit(1);
189
- }
190
- if (!resolved.match) {
191
- console.error(JSON.stringify({ error: 'element_not_found', fallback: 'agent-driven' }));
192
- process.exit(1);
193
- }
194
-
195
- const { startLine, endLine } = resolved.match;
196
- const commentSyntax = detectCommentSyntax(targetFile);
197
- const styleMode = detectStyleMode(targetFile);
198
- const isJsx = commentSyntax.open === '{/*';
199
- const spliceIndex = computeInsertLine(startLine, endLine, position);
200
- const relTargetFile = path.relative(process.cwd(), targetFile).split(path.sep).join('/');
201
-
202
- if (shouldUseSvelteComponentInjection(targetFile)) {
203
- const session = scaffoldSvelteComponentInsertSession({
204
- id,
205
- count,
206
- sourceFile: relTargetFile,
207
- insertLine: spliceIndex + 1,
208
- position,
209
- anchorStartLine: startLine + 1,
210
- anchorEndLine: endLine + 1,
211
- anchorLines: lines.slice(startLine, endLine + 1),
212
- cwd: process.cwd(),
213
- });
214
- console.log(JSON.stringify({
215
- mode: 'insert',
216
- position,
217
- file: session.manifestFile,
218
- sourceFile: relTargetFile,
219
- previewMode: 'svelte-component',
220
- componentDir: session.componentDir,
221
- propContract: session.propContract,
222
- insertLine: 1,
223
- sourceInsertLine: spliceIndex + 1,
224
- anchorStartLine: startLine + 1,
225
- anchorEndLine: endLine + 1,
226
- commentSyntax,
227
- styleMode: 'svelte-component',
228
- styleTag: null,
229
- cssSelectorPrefixExamples: [],
230
- cssAuthoring: buildSvelteComponentCssAuthoring(count),
231
- }));
232
- return;
233
- }
234
-
235
- const indent = lines[spliceIndex]?.match(/^(\s*)/)?.[1]
236
- ?? lines[startLine]?.match(/^(\s*)/)?.[1]
237
- ?? '';
238
-
239
- const wrapperLines = buildInsertWrapperLines({
240
- id,
241
- count,
242
- indent,
243
- commentSyntax,
244
- isJsx,
245
- });
246
-
247
- const newLines = [
248
- ...lines.slice(0, spliceIndex),
249
- ...wrapperLines,
250
- ...lines.slice(spliceIndex),
251
- ];
252
- fs.writeFileSync(targetFile, newLines.join('\n'), 'utf-8');
253
-
254
- const insertLine = spliceIndex + 3;
255
-
256
- console.log(JSON.stringify({
257
- mode: 'insert',
258
- position,
259
- file: relTargetFile,
260
- insertLine: insertLine + 1,
261
- commentSyntax,
262
- styleMode: styleMode.mode,
263
- styleTag: styleMode.styleTag,
264
- cssSelectorPrefixExamples: buildCssSelectorPrefixExamples(styleMode.mode, count),
265
- cssAuthoring: buildCssAuthoring(styleMode, count),
266
- }));
267
- }
268
-
269
- const _running = process.argv[1];
270
- if (_running?.endsWith('live-insert.mjs') || _running?.endsWith('live-insert.mjs/')) {
271
- insertCli();
272
- }
@@ -1,363 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Collect evidence for pending live copy edits.
4
- *
5
- * This module intentionally does not edit source files and does not choose a
6
- * winner. It gathers staged browser edits, rendered context, framework source
7
- * hints, and likely source candidates so the AI copy-edit batch runner can make
8
- * source changes with full repo context.
9
- */
10
-
11
- import fs from 'node:fs';
12
- import path from 'node:path';
13
- import { isGeneratedFile } from './lib/is-generated.mjs';
14
- import { readBuffer, getBufferPath } from './live/manual-edits-buffer.mjs';
15
-
16
- const EVIDENCE_VERSION = 1;
17
- const TEXT_EXTENSIONS = new Set(['.html', '.jsx', '.tsx', '.vue', '.svelte', '.astro', '.js', '.mjs', '.ts']);
18
- const SEARCH_DIRS = ['src', 'app', 'pages', 'components', 'public', 'views', 'templates', 'site', 'lib', 'data'];
19
- const STRONG_LITERAL_MATCH_LIMIT = 8;
20
- const WEAK_LITERAL_MATCH_LIMIT = 4;
21
- const OBJECT_KEY_MATCH_LIMIT = 8;
22
- const LOCATOR_MATCH_LIMIT = 4;
23
- const CONTEXT_MATCH_LIMIT = 8;
24
- const CONTEXT_MATCH_PER_HINT = 2;
25
- const SKIP_DIRS = new Set([
26
- 'node_modules',
27
- '.git',
28
- '.monodesign',
29
- '.astro',
30
- '.next',
31
- '.nuxt',
32
- '.svelte-kit',
33
- 'dist',
34
- 'build',
35
- 'out',
36
- 'coverage',
37
- ]);
38
-
39
- export function buildManualEditEvidence({ cwd = process.cwd(), pageUrl = null } = {}) {
40
- const buffer = readBuffer(cwd);
41
- const entries = pageUrl
42
- ? buffer.entries.filter((entry) => entry.pageUrl === pageUrl)
43
- : buffer.entries;
44
- const opCount = countOps(entries);
45
-
46
- if (opCount === 0) {
47
- return {
48
- pageUrl,
49
- count: 0,
50
- entries: [],
51
- ops: [],
52
- candidates: [],
53
- };
54
- }
55
-
56
- const searchFiles = collectSearchFiles(cwd);
57
- const ops = flattenOps(entries);
58
- const candidates = ops.map((op) => buildCandidatesForOp(op, cwd, searchFiles));
59
- return {
60
- version: EVIDENCE_VERSION,
61
- pageUrl: pageUrl || null,
62
- count: opCount,
63
- entries,
64
- ops,
65
- context: {
66
- cwd,
67
- bufferPath: path.relative(cwd, getBufferPath(cwd)).split(path.sep).join('/'),
68
- totalEntries: entries.length,
69
- totalOps: opCount,
70
- },
71
- candidates,
72
- };
73
- }
74
-
75
- function countOps(entries) {
76
- let count = 0;
77
- for (const entry of entries) count += Array.isArray(entry.ops) ? entry.ops.length : 0;
78
- return count;
79
- }
80
-
81
- function flattenOps(entries) {
82
- const out = [];
83
- for (const entry of entries) {
84
- const contextHintsByRef = buildContextHintsByRef(entry);
85
- for (const op of entry.ops || []) {
86
- out.push({
87
- entryId: entry.id,
88
- pageUrl: entry.pageUrl,
89
- ref: op.ref,
90
- contextRef: op.contextRef || null,
91
- tag: op.tag,
92
- elementId: op.elementId || null,
93
- classes: Array.isArray(op.classes) ? op.classes : [],
94
- originalText: op.originalText,
95
- newText: op.newText,
96
- deleted: op.deleted === true,
97
- sourceHint: op.sourceHint || null,
98
- leaf: op.leaf || null,
99
- nearbyEditableTexts: Array.isArray(op.nearbyEditableTexts) ? op.nearbyEditableTexts : [],
100
- container: op.container || null,
101
- contextHints: contextHintsByRef.get(op.ref) || [],
102
- });
103
- }
104
- }
105
- return out;
106
- }
107
-
108
- function buildContextHintsByRef(entry) {
109
- const map = new Map();
110
- for (const op of entry.ops || []) {
111
- const hints = new Set();
112
- const add = (value) => {
113
- const text = normalizeText(decodeBasicHtml(String(value || '')));
114
- if (text.length < 3 || text.length > 160) return;
115
- if (text === normalizeText(op.originalText) || text === normalizeText(op.newText)) return;
116
- hints.add(text);
117
- };
118
-
119
- for (const item of op.nearbyEditableTexts || []) {
120
- add(typeof item === 'string' ? item : item?.text);
121
- }
122
- const outer = typeof entry.element?.outerHTML === 'string' ? entry.element.outerHTML : '';
123
- for (const match of outer.matchAll(/data-monodesign-original-text="([^"]*)"/g)) add(match[1]);
124
- if (typeof entry.element?.textContent === 'string') {
125
- for (const chunk of entry.element.textContent.split(/\s{2,}|\n|\t/)) add(chunk);
126
- }
127
- map.set(op.ref, [...hints].slice(0, 16));
128
- }
129
- return map;
130
- }
131
-
132
- function buildCandidatesForOp(op, cwd, searchFiles) {
133
- const originalText = String(op.originalText || '');
134
- const contextNeedles = op.contextHints || [];
135
- return {
136
- entryId: op.entryId,
137
- ref: op.ref,
138
- originalText,
139
- sourceHint: analyzeSourceHint(op, cwd),
140
- textMatches: originalText ? findLiteralMatches(searchFiles, originalText, { max: literalMatchLimit(originalText) }) : [],
141
- objectKeyMatches: originalText ? findObjectKeyMatches(searchFiles, originalText, { max: OBJECT_KEY_MATCH_LIMIT }) : [],
142
- locatorMatches: findLocatorMatches(searchFiles, op, { max: LOCATOR_MATCH_LIMIT }),
143
- contextTextMatches: findContextMatches(searchFiles, contextNeedles, { maxPerHint: CONTEXT_MATCH_PER_HINT, max: CONTEXT_MATCH_LIMIT }),
144
- };
145
- }
146
-
147
- function literalMatchLimit(text) {
148
- return isWeakSourceNeedle(text) ? WEAK_LITERAL_MATCH_LIMIT : STRONG_LITERAL_MATCH_LIMIT;
149
- }
150
-
151
- function isWeakSourceNeedle(text) {
152
- const normalized = normalizeText(text);
153
- return normalized.length < 4 || /^[\d.,+\-%\s]+$/.test(normalized);
154
- }
155
-
156
- function analyzeSourceHint(op, cwd) {
157
- const hint = normalizeSourceHint(op.sourceHint);
158
- if (!hint.file) return null;
159
- const file = path.resolve(cwd, hint.file);
160
- const relativeFile = path.relative(cwd, file).split(path.sep).join('/');
161
- if (!isPathInsideOrEqual(cwd, file)) {
162
- return { ...hint, status: 'outside_cwd', relativeFile: hint.file };
163
- }
164
- if (!fs.existsSync(file)) {
165
- return { ...hint, status: 'file_missing', relativeFile };
166
- }
167
- if (isGeneratedFile(file, { cwd })) {
168
- return { ...hint, status: 'generated', relativeFile };
169
- }
170
-
171
- const content = fs.readFileSync(file, 'utf-8');
172
- const lines = content.split('\n');
173
- const line = hint.line || 1;
174
- const start = Math.max(0, line - 4);
175
- const end = Math.min(lines.length, line + 3);
176
- const windowText = lines.slice(start, end).join('\n');
177
- const containsOriginalText = typeof op.originalText === 'string' && windowText.includes(op.originalText);
178
- return {
179
- ...hint,
180
- status: containsOriginalText ? 'ok' : 'text_not_found_near_hint',
181
- relativeFile,
182
- excerpt: lines.slice(start, end).map((text, index) => ({
183
- line: start + index + 1,
184
- text: text.slice(0, 240),
185
- })),
186
- };
187
- }
188
-
189
- function normalizeSourceHint(hint) {
190
- if (!hint || typeof hint !== 'object') return {};
191
- let line = Number.isFinite(Number(hint.line)) ? Number(hint.line) : null;
192
- let column = Number.isFinite(Number(hint.column)) ? Number(hint.column) : null;
193
- if ((!line || !column) && typeof hint.loc === 'string') {
194
- const match = hint.loc.match(/^(\d+)(?::(\d+))?/);
195
- if (match) {
196
- line = Number(match[1]);
197
- if (match[2]) column = Number(match[2]);
198
- }
199
- }
200
- return {
201
- file: typeof hint.file === 'string' ? hint.file : '',
202
- loc: typeof hint.loc === 'string' ? hint.loc : '',
203
- line,
204
- column,
205
- };
206
- }
207
-
208
- function collectSearchFiles(cwd) {
209
- const out = [];
210
- const seenDirs = new Set();
211
- const seenFiles = new Set();
212
- for (const dir of SEARCH_DIRS) {
213
- scanDir(path.join(cwd, dir), cwd, seenDirs, seenFiles, out, 0);
214
- }
215
- scanRootFiles(cwd, seenFiles, out);
216
- return out;
217
- }
218
-
219
- function scanDir(dir, cwd, seenDirs, seenFiles, out, depth) {
220
- if (depth > 7 || !fs.existsSync(dir)) return;
221
- let realDir;
222
- try { realDir = fs.realpathSync(dir); } catch { return; }
223
- if (seenDirs.has(realDir)) return;
224
- seenDirs.add(realDir);
225
-
226
- let entries;
227
- try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
228
- for (const entry of entries) {
229
- const fullPath = path.join(dir, entry.name);
230
- if (entry.isDirectory()) {
231
- if (SKIP_DIRS.has(entry.name)) continue;
232
- scanDir(fullPath, cwd, seenDirs, seenFiles, out, depth + 1);
233
- continue;
234
- }
235
- if (!entry.isFile() || !TEXT_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) continue;
236
- maybeAddSearchFile(fullPath, cwd, seenFiles, out);
237
- }
238
- }
239
-
240
- function scanRootFiles(cwd, seenFiles, out) {
241
- let entries;
242
- try { entries = fs.readdirSync(cwd, { withFileTypes: true }); } catch { return; }
243
- for (const entry of entries) {
244
- if (!entry.isFile() || !TEXT_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) continue;
245
- maybeAddSearchFile(path.join(cwd, entry.name), cwd, seenFiles, out);
246
- }
247
- }
248
-
249
- function maybeAddSearchFile(file, cwd, seenFiles, out) {
250
- let realFile;
251
- try { realFile = fs.realpathSync(file); } catch { return; }
252
- if (seenFiles.has(realFile)) return;
253
- seenFiles.add(realFile);
254
- if (isGeneratedFile(file, { cwd })) return;
255
- let content;
256
- try { content = fs.readFileSync(file, 'utf-8'); } catch { return; }
257
- out.push({ file, relativeFile: path.relative(cwd, file).split(path.sep).join('/'), content, lines: content.split('\n') });
258
- }
259
-
260
- function findLiteralMatches(searchFiles, needle, { max }) {
261
- return findMatches(searchFiles, needle, { kind: 'text', max });
262
- }
263
-
264
- function findObjectKeyMatches(searchFiles, text, { max }) {
265
- const re = new RegExp(`(["\\'\`])${escapeRegExp(text)}\\1(?=\\s*:)`, 'g');
266
- const out = [];
267
- for (const file of searchFiles) {
268
- for (const match of file.content.matchAll(re)) {
269
- out.push(matchForIndex(file, match.index, 'object_key', text));
270
- if (out.length >= max) return out;
271
- }
272
- }
273
- return out;
274
- }
275
-
276
- function findLocatorMatches(searchFiles, op, { max }) {
277
- const needles = [];
278
- if (op.elementId) needles.push({ kind: 'id', needle: op.elementId });
279
- for (const cls of op.classes || []) {
280
- if (cls) needles.push({ kind: 'class', needle: cls });
281
- }
282
- if (op.tag) needles.push({ kind: 'tag', needle: `<${op.tag}` });
283
-
284
- const out = [];
285
- const seen = new Set();
286
- for (const { kind, needle } of needles) {
287
- for (const match of findMatches(searchFiles, needle, { kind, max })) {
288
- const key = `${match.file}:${match.line}:${kind}:${needle}`;
289
- if (seen.has(key)) continue;
290
- seen.add(key);
291
- out.push({ ...match, needle });
292
- if (out.length >= max) return out;
293
- }
294
- }
295
- return out;
296
- }
297
-
298
- function findContextMatches(searchFiles, hints, { maxPerHint, max }) {
299
- const out = [];
300
- const seen = new Set();
301
- for (const hint of hints || []) {
302
- for (const match of findMatches(searchFiles, hint, { kind: 'context', max: maxPerHint })) {
303
- const key = `${match.file}:${match.line}:${hint}`;
304
- if (seen.has(key)) continue;
305
- seen.add(key);
306
- out.push({ ...match, needle: hint });
307
- if (out.length >= max) return out;
308
- }
309
- }
310
- return out;
311
- }
312
-
313
- function findMatches(searchFiles, needle, { kind, max }) {
314
- const text = String(needle || '');
315
- if (!text) return [];
316
- const out = [];
317
- for (const file of searchFiles) {
318
- let index = 0;
319
- while (out.length < max) {
320
- index = file.content.indexOf(text, index);
321
- if (index === -1) break;
322
- out.push(matchForIndex(file, index, kind, text));
323
- index += Math.max(1, text.length);
324
- }
325
- if (out.length >= max) break;
326
- }
327
- return out;
328
- }
329
-
330
- function matchForIndex(file, index, kind, needle) {
331
- const line = file.content.slice(0, index).split('\n').length;
332
- const lineText = file.lines[line - 1] || '';
333
- return {
334
- kind,
335
- file: file.relativeFile,
336
- line,
337
- needle,
338
- excerpt: lineText.trim().slice(0, 240),
339
- };
340
- }
341
-
342
- function isPathInsideOrEqual(cwd, file) {
343
- const rel = path.relative(path.resolve(cwd), path.resolve(file)).split(path.sep).join('/');
344
- return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
345
- }
346
-
347
- function normalizeText(value) {
348
- return String(value || '').replace(/\s+/g, ' ').trim();
349
- }
350
-
351
- function decodeBasicHtml(value) {
352
- return value
353
- .replace(/&quot;/g, '"')
354
- .replace(/&#39;/g, "'")
355
- .replace(/&apos;/g, "'")
356
- .replace(/&amp;/g, '&')
357
- .replace(/&lt;/g, '<')
358
- .replace(/&gt;/g, '>');
359
- }
360
-
361
- function escapeRegExp(value) {
362
- return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
363
- }