vibecode-anything 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +239 -67
  2. package/dist/cli.js +2140 -73
  3. package/dist/core/adapters.d.ts +26 -3
  4. package/dist/core/adapters.js +411 -25
  5. package/dist/core/agent-adapter.d.ts +67 -0
  6. package/dist/core/agent-adapter.js +312 -0
  7. package/dist/core/anti-cheat.d.ts +6 -0
  8. package/dist/core/anti-cheat.js +372 -0
  9. package/dist/core/badge.d.ts +18 -0
  10. package/dist/core/badge.js +360 -0
  11. package/dist/core/cache.d.ts +47 -0
  12. package/dist/core/cache.js +403 -0
  13. package/dist/core/ci-export.d.ts +35 -0
  14. package/dist/core/ci-export.js +796 -0
  15. package/dist/core/ci-formats.d.ts +21 -0
  16. package/dist/core/ci-formats.js +388 -0
  17. package/dist/core/client-codegen.d.ts +36 -0
  18. package/dist/core/client-codegen.js +2538 -0
  19. package/dist/core/compose.d.ts +71 -0
  20. package/dist/core/compose.js +1088 -0
  21. package/dist/core/docs-export.d.ts +37 -0
  22. package/dist/core/docs-export.js +2706 -0
  23. package/dist/core/doctor.d.ts +21 -1
  24. package/dist/core/doctor.js +234 -21
  25. package/dist/core/exec.d.ts +26 -2
  26. package/dist/core/exec.js +235 -8
  27. package/dist/core/fixtures.d.ts +153 -0
  28. package/dist/core/fixtures.js +2245 -0
  29. package/dist/core/format.d.ts +77 -0
  30. package/dist/core/format.js +632 -0
  31. package/dist/core/fs-snapshot.d.ts +37 -0
  32. package/dist/core/fs-snapshot.js +216 -0
  33. package/dist/core/graphql-export.d.ts +34 -0
  34. package/dist/core/graphql-export.js +2482 -0
  35. package/dist/core/har-export.d.ts +29 -0
  36. package/dist/core/har-export.js +988 -0
  37. package/dist/core/html-report.d.ts +27 -0
  38. package/dist/core/html-report.js +1535 -0
  39. package/dist/core/http-export.d.ts +31 -0
  40. package/dist/core/http-export.js +726 -0
  41. package/dist/core/impact.d.ts +80 -0
  42. package/dist/core/impact.js +1412 -0
  43. package/dist/core/lint.d.ts +38 -0
  44. package/dist/core/lint.js +1111 -0
  45. package/dist/core/load-export.d.ts +37 -0
  46. package/dist/core/load-export.js +1813 -0
  47. package/dist/core/mcp-export.d.ts +35 -0
  48. package/dist/core/mcp-export.js +1736 -0
  49. package/dist/core/mock-server.d.ts +47 -0
  50. package/dist/core/mock-server.js +1722 -0
  51. package/dist/core/openapi-export.d.ts +44 -0
  52. package/dist/core/openapi-export.js +1074 -0
  53. package/dist/core/parity.d.ts +6 -1
  54. package/dist/core/parity.js +36 -1
  55. package/dist/core/playwright-exporter.d.ts +23 -0
  56. package/dist/core/playwright-exporter.js +1343 -0
  57. package/dist/core/png.js +45 -9
  58. package/dist/core/regression.d.ts +54 -0
  59. package/dist/core/regression.js +529 -0
  60. package/dist/core/responsive.d.ts +86 -0
  61. package/dist/core/responsive.js +606 -0
  62. package/dist/core/run.d.ts +74 -0
  63. package/dist/core/run.js +696 -0
  64. package/dist/core/scheduler.d.ts +24 -0
  65. package/dist/core/scheduler.js +162 -0
  66. package/dist/core/schema-export.d.ts +29 -0
  67. package/dist/core/schema-export.js +2215 -0
  68. package/dist/core/schema.d.ts +3 -2
  69. package/dist/core/schema.js +460 -17
  70. package/dist/core/security.d.ts +233 -0
  71. package/dist/core/security.js +1839 -0
  72. package/dist/core/server-export.d.ts +38 -0
  73. package/dist/core/server-export.js +3198 -0
  74. package/dist/core/spec-writer.d.ts +9 -0
  75. package/dist/core/spec-writer.js +1202 -0
  76. package/dist/core/store.d.ts +11 -2
  77. package/dist/core/store.js +128 -8
  78. package/dist/core/target-map.d.ts +34 -0
  79. package/dist/core/target-map.js +262 -0
  80. package/dist/core/test-exporter.d.ts +25 -0
  81. package/dist/core/test-exporter.js +1918 -0
  82. package/dist/core/types.d.ts +182 -14
  83. package/dist/core/visual-semantic.d.ts +67 -0
  84. package/dist/core/visual-semantic.js +673 -0
  85. package/dist/core/visual.js +65 -16
  86. package/dist/core/watch.d.ts +28 -3
  87. package/dist/core/watch.js +222 -12
  88. package/dist/core/yaml.d.ts +5 -0
  89. package/dist/core/yaml.js +1009 -0
  90. package/dist/diagnostics/diagnose.d.ts +53 -0
  91. package/dist/diagnostics/diagnose.js +1083 -0
  92. package/dist/diagnostics/flake.d.ts +71 -0
  93. package/dist/diagnostics/flake.js +608 -0
  94. package/dist/diagnostics/mutation-audit.d.ts +69 -0
  95. package/dist/diagnostics/mutation-audit.js +769 -0
  96. package/dist/diagnostics/spatial.d.ts +42 -0
  97. package/dist/diagnostics/spatial.js +346 -0
  98. package/dist/diagnostics/trends.d.ts +122 -0
  99. package/dist/diagnostics/trends.js +1190 -0
  100. package/dist/discovery/discover.d.ts +111 -0
  101. package/dist/discovery/discover.js +2017 -0
  102. package/dist/discovery/lock.d.ts +116 -0
  103. package/dist/discovery/lock.js +1505 -0
  104. package/dist/discovery/routes.d.ts +36 -0
  105. package/dist/discovery/routes.js +1494 -0
  106. package/dist/discovery/test-importer.d.ts +92 -0
  107. package/dist/discovery/test-importer.js +4952 -0
  108. package/dist/index.d.ts +123 -0
  109. package/dist/index.js +99 -0
  110. package/dist/ingestors/api-collections.d.ts +28 -0
  111. package/dist/ingestors/api-collections.js +2335 -0
  112. package/dist/ingestors/api-repo.d.ts +2 -1
  113. package/dist/ingestors/api-repo.js +483 -85
  114. package/dist/ingestors/asyncapi.d.ts +26 -0
  115. package/dist/ingestors/asyncapi.js +2105 -0
  116. package/dist/ingestors/bridges.d.ts +2 -0
  117. package/dist/ingestors/bridges.js +702 -0
  118. package/dist/ingestors/cli.d.ts +2 -1
  119. package/dist/ingestors/cli.js +234 -46
  120. package/dist/ingestors/curl.d.ts +14 -0
  121. package/dist/ingestors/curl.js +1024 -0
  122. package/dist/ingestors/graphql.d.ts +56 -0
  123. package/dist/ingestors/graphql.js +1852 -0
  124. package/dist/ingestors/http-file.d.ts +20 -0
  125. package/dist/ingestors/http-file.js +923 -0
  126. package/dist/ingestors/index.js +486 -6
  127. package/dist/ingestors/openrpc.d.ts +29 -0
  128. package/dist/ingestors/openrpc.js +1807 -0
  129. package/dist/ingestors/proto.d.ts +47 -0
  130. package/dist/ingestors/proto.js +2690 -0
  131. package/dist/ingestors/trace.d.ts +10 -0
  132. package/dist/ingestors/trace.js +599 -0
  133. package/dist/ingestors/video.d.ts +4 -1
  134. package/dist/ingestors/video.js +86 -36
  135. package/dist/ingestors/web.d.ts +16 -1
  136. package/dist/ingestors/web.js +474 -32
  137. package/dist/mcp/server.js +3532 -67
  138. package/dist/oracles/api-repo.js +102 -30
  139. package/dist/oracles/cli.js +65 -17
  140. package/dist/oracles/http-workflow.d.ts +68 -0
  141. package/dist/oracles/http-workflow.js +828 -0
  142. package/dist/oracles/image.js +178 -28
  143. package/dist/oracles/index.d.ts +3 -1
  144. package/dist/oracles/index.js +243 -14
  145. package/dist/oracles/perf-budget.d.ts +90 -0
  146. package/dist/oracles/perf-budget.js +1329 -0
  147. package/dist/oracles/stream.d.ts +94 -0
  148. package/dist/oracles/stream.js +1268 -0
  149. package/dist/oracles/ui-states.d.ts +49 -0
  150. package/dist/oracles/ui-states.js +894 -0
  151. package/dist/oracles/video.d.ts +1 -1
  152. package/dist/oracles/video.js +232 -16
  153. package/dist/oracles/web.js +464 -73
  154. package/dist/plugins/builtins.d.ts +12 -0
  155. package/dist/plugins/builtins.js +1052 -0
  156. package/dist/plugins/registry.d.ts +86 -0
  157. package/dist/plugins/registry.js +554 -0
  158. package/dist/setup/index.js +145 -33
  159. package/package.json +56 -47
  160. package/skills/vibecode-anything/SKILL.md +75 -52
@@ -0,0 +1,606 @@
1
+ /**
2
+ * Zero-dependency multi-viewport responsive overflow, overlap & breakpoint audit engine.
3
+ */
4
+ import { asciiLower, stripTerminalEscapes } from "./security.js";
5
+ export const DEFAULT_RESPONSIVE_VIEWPORTS = Object.freeze([
6
+ Object.freeze({ name: "mobile", width: 390, height: 844 }),
7
+ Object.freeze({ name: "tablet", width: 768, height: 1024 }),
8
+ Object.freeze({ name: "desktop", width: 1440, height: 900 })
9
+ ]);
10
+ const DEFAULTS = {
11
+ overflowTolerancePx: 1,
12
+ minOverlapRatio: 0.15,
13
+ siblingErrorRatio: 0.35,
14
+ containmentRatio: 0.95,
15
+ minTouchTargetPx: 24,
16
+ narrowMaxPx: 768,
17
+ maxElements: 500,
18
+ maxElementsHardCap: 2000,
19
+ maxOverlapIssues: 250,
20
+ maxHtmlBytes: 512 * 1024,
21
+ maxCssNesting: 256,
22
+ maxSyntheticElements: 50,
23
+ maxCssEntries: 100,
24
+ maxPrettyIssues: 30
25
+ };
26
+ const ANSI = { reset: "\x1b[0m", bold: "\x1b[1m", dim: "\x1b[2m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m", cyan: "\x1b[36m" };
27
+ const POSITIVE_PX_RE = /^(\d+(?:\.\d+)?)px$/;
28
+ const INTERACTIVE_TAGS = new Set(["a", "button", "input", "select", "textarea"]);
29
+ const isNum = (v) => typeof v === "number" && Number.isFinite(v);
30
+ const hasBBox = (b) => Boolean(b) && isNum(b.x) && isNum(b.y) && isNum(b.w) && isNum(b.h);
31
+ const isVisible = (el) => Boolean(el) && el.visible !== false;
32
+ const round2 = (n) => (isNum(n) && Number.isFinite(n * 100) ? Math.round(n * 100) / 100 : isNum(n) ? n : 0);
33
+ const round3 = (n) => (isNum(n) && Number.isFinite(n * 1000) ? Math.round(n * 1000) / 1000 : isNum(n) ? n : 0);
34
+ const clean = (s) => (typeof s === "string" ? stripTerminalEscapes(s).replace(/[\r\n]+/g, " ").trim() : "");
35
+ const vpNameOf = (vp) => clean(vp?.name) || "unknown";
36
+ const elIdOf = (el) => (typeof el.id === "string" ? el.id : undefined);
37
+ const elLabel = (el) => clean(el.id) || clean(el.selector) || clean(el.tag) || "element";
38
+ const resolveCap = (n) => isNum(n) ? Math.max(0, Math.min(DEFAULTS.maxElementsHardCap, Math.floor(n))) : DEFAULTS.maxElements;
39
+ function takeVisible(elements, cap) {
40
+ const out = [];
41
+ if (!Array.isArray(elements) || cap <= 0)
42
+ return out;
43
+ for (let i = 0; i < elements.length && out.length < cap; i++) {
44
+ const el = elements[i];
45
+ if (isVisible(el) && hasBBox(el.bbox))
46
+ out.push(el);
47
+ }
48
+ return out;
49
+ }
50
+ /** Detect page-level horizontal scroll overflow and visible elements extending past viewport bounds. */
51
+ export function detectHorizontalOverflow(snapshot, tolerancePx = DEFAULTS.overflowTolerancePx) {
52
+ const vw = snapshot?.viewport?.width;
53
+ if (!isNum(vw) || vw <= 0)
54
+ return [];
55
+ const vpName = vpNameOf(snapshot.viewport);
56
+ const tol = isNum(tolerancePx) && tolerancePx >= 0 ? tolerancePx : DEFAULTS.overflowTolerancePx;
57
+ const issues = [];
58
+ let scrollW = isNum(snapshot.scrollWidth) ? snapshot.scrollWidth : 0;
59
+ if (Array.isArray(snapshot.cssFixedWidthOverflowPx)) {
60
+ for (const px of snapshot.cssFixedWidthOverflowPx)
61
+ if (isNum(px) && px > scrollW)
62
+ scrollW = px;
63
+ }
64
+ if (scrollW > vw + tol) {
65
+ const overflowPx = round2(scrollW - vw);
66
+ issues.push({
67
+ viewport: vpName,
68
+ kind: "HORIZONTAL_OVERFLOW",
69
+ severity: "error",
70
+ message: `Horizontal overflow on ${vpName}: scrollWidth ${round2(scrollW)}px exceeds viewport ${round2(vw)}px by ${overflowPx}px`,
71
+ metrics: { scrollWidth: round2(scrollW), viewportWidth: round2(vw), overflowPx }
72
+ });
73
+ }
74
+ for (const el of Array.isArray(snapshot.elements) ? snapshot.elements : []) {
75
+ if (!isVisible(el) || !hasBBox(el.bbox))
76
+ continue;
77
+ const { x, w } = el.bbox;
78
+ const right = x + Math.max(0, w);
79
+ if (!Number.isFinite(right))
80
+ continue;
81
+ const overLeft = x < -tol;
82
+ const overRight = right > vw + tol;
83
+ if (!overLeft && !overRight)
84
+ continue;
85
+ const overflowPx = round2(Math.max(overLeft ? -x : 0, overRight ? right - vw : 0));
86
+ const side = overLeft && overRight ? "both edges" : overLeft ? "left edge" : "right edge";
87
+ issues.push({
88
+ viewport: vpName,
89
+ kind: "ELEMENT_OVERFLOW",
90
+ severity: "error",
91
+ elementId: elIdOf(el),
92
+ message: `Element "${elLabel(el)}" overflows ${vpName} ${side} by ${overflowPx}px`,
93
+ metrics: { x: round2(x), width: round2(w), right: round2(right), viewportWidth: round2(vw), overflowPx }
94
+ });
95
+ }
96
+ return issues;
97
+ }
98
+ /** Detect colliding visible elements via X-axis sweep-and-prune, ignoring non-interactive parent-child nesting. */
99
+ export function detectElementOverlaps(elements, viewportName, options) {
100
+ const cap = resolveCap(options?.maxElements);
101
+ const minRatio = isNum(options?.minOverlapRatio) && options.minOverlapRatio > 0 && options.minOverlapRatio <= 1 ? options.minOverlapRatio : DEFAULTS.minOverlapRatio;
102
+ const vpName = clean(viewportName) || "unknown";
103
+ const boxes = [];
104
+ for (let i = 0; Array.isArray(elements) && i < elements.length && boxes.length < cap; i++) {
105
+ const el = elements[i];
106
+ if (!isVisible(el) || !hasBBox(el.bbox))
107
+ continue;
108
+ const { x, y, w, h } = el.bbox;
109
+ const x2 = x + w;
110
+ const y2 = y + h;
111
+ const area = w * h;
112
+ if (w > 0 && h > 0 && Number.isFinite(x2) && Number.isFinite(y2) && Number.isFinite(area) && area > 0) {
113
+ boxes.push({ el, idx: i, x1: x, y1: y, x2, y2, area, interactive: el.interactive === true });
114
+ }
115
+ }
116
+ let minX = Infinity;
117
+ let maxX = -Infinity;
118
+ let minY = Infinity;
119
+ let maxY = -Infinity;
120
+ for (const b of boxes) {
121
+ if (b.x1 < minX)
122
+ minX = b.x1;
123
+ if (b.x2 > maxX)
124
+ maxX = b.x2;
125
+ if (b.y1 < minY)
126
+ minY = b.y1;
127
+ if (b.y2 > maxY)
128
+ maxY = b.y2;
129
+ }
130
+ const sweepY = boxes.length > 1 && maxY - minY > maxX - minX;
131
+ if (sweepY) {
132
+ boxes.sort((a, b) => (a.y1 < b.y1 ? -1 : a.y1 > b.y1 ? 1 : a.x1 < b.x1 ? -1 : a.x1 > b.x1 ? 1 : a.idx - b.idx));
133
+ }
134
+ else {
135
+ boxes.sort((a, b) => (a.x1 < b.x1 ? -1 : a.x1 > b.x1 ? 1 : a.y1 < b.y1 ? -1 : a.y1 > b.y1 ? 1 : a.idx - b.idx));
136
+ }
137
+ const issues = [];
138
+ for (let i = 0; i < boxes.length && issues.length < DEFAULTS.maxOverlapIssues; i++) {
139
+ const a = boxes[i];
140
+ for (let j = i + 1; j < boxes.length && issues.length < DEFAULTS.maxOverlapIssues; j++) {
141
+ const b = boxes[j];
142
+ if (sweepY ? b.y1 >= a.y2 : b.x1 >= a.x2)
143
+ break;
144
+ const iy = Math.min(a.y2, b.y2) - Math.max(a.y1, b.y1);
145
+ if (!Number.isFinite(iy) || iy <= 0)
146
+ continue;
147
+ const ix = Math.min(a.x2, b.x2) - Math.max(a.x1, b.x1);
148
+ if (!Number.isFinite(ix) || ix <= 0)
149
+ continue;
150
+ const interArea = ix * iy;
151
+ const minArea = Math.min(a.area, b.area);
152
+ if (!Number.isFinite(interArea) || minArea <= 0)
153
+ continue;
154
+ const ratio = Math.min(1, interArea / minArea);
155
+ const bothInteractive = a.interactive && b.interactive;
156
+ if ((!bothInteractive && ratio >= DEFAULTS.containmentRatio) || ratio < minRatio)
157
+ continue;
158
+ issues.push({
159
+ viewport: vpName,
160
+ kind: "ELEMENT_OVERLAP",
161
+ severity: bothInteractive || ratio >= DEFAULTS.siblingErrorRatio ? "error" : "warn",
162
+ elementId: elIdOf(a.el),
163
+ otherElementId: elIdOf(b.el),
164
+ message: `${bothInteractive ? "Interactive targets" : "Elements"} "${elLabel(a.el)}" and "${elLabel(b.el)}" overlap (${Math.round(ratio * 100)}%)`,
165
+ metrics: { overlapRatio: round3(ratio), intersectionArea: round2(interArea), intersectionWidth: round2(ix), intersectionHeight: round2(iy) }
166
+ });
167
+ }
168
+ }
169
+ return issues;
170
+ }
171
+ /** Detect collapsed/off-canvas elements and undersized interactive touch targets on narrow viewports (<= 768px). */
172
+ export function detectClippedOrTinyTargets(elements, viewport, options) {
173
+ const vw = viewport?.width;
174
+ if (!isNum(vw) || vw <= 0 || !Array.isArray(elements))
175
+ return [];
176
+ const vpName = vpNameOf(viewport);
177
+ const minTouch = isNum(options?.minTouchTargetPx) && options.minTouchTargetPx > 0 ? options.minTouchTargetPx : DEFAULTS.minTouchTargetPx;
178
+ const checkTouch = options?.checkTouchTargets !== false && vw <= DEFAULTS.narrowMaxPx;
179
+ const issues = [];
180
+ for (const el of elements) {
181
+ if (!isVisible(el) || !hasBBox(el.bbox))
182
+ continue;
183
+ const { x, y, w, h } = el.bbox;
184
+ const collapsed = w <= 0 || h <= 0;
185
+ if (collapsed || x + w <= 0 || y + h <= 0 || x >= vw) {
186
+ issues.push({
187
+ viewport: vpName,
188
+ kind: "CLIPPED_OR_COLLAPSED",
189
+ severity: "error",
190
+ elementId: elIdOf(el),
191
+ message: collapsed
192
+ ? `Element "${elLabel(el)}" is collapsed (${round2(w)}x${round2(h)}px) on ${vpName}`
193
+ : `Element "${elLabel(el)}" is off-canvas at (${round2(x)}, ${round2(y)}) on ${vpName}`,
194
+ metrics: { x: round2(x), y: round2(y), width: round2(w), height: round2(h) }
195
+ });
196
+ }
197
+ else if (checkTouch && el.interactive === true && (w < minTouch || h < minTouch)) {
198
+ issues.push({
199
+ viewport: vpName,
200
+ kind: "INTERACTIVE_TARGET_TOO_SMALL",
201
+ severity: "warn",
202
+ elementId: elIdOf(el),
203
+ message: `Interactive target "${elLabel(el)}" is ${round2(w)}x${round2(h)}px on ${vpName} (min ${round2(minTouch)}px)`,
204
+ metrics: { width: round2(w), height: round2(h), minTouchTargetPx: round2(minTouch) }
205
+ });
206
+ }
207
+ }
208
+ return issues;
209
+ }
210
+ /** Audit a single viewport snapshot across all responsive detectors. */
211
+ export function auditResponsiveViewport(snapshot, options) {
212
+ const vw = isNum(snapshot?.viewport?.width) && snapshot.viewport.width > 0 ? snapshot.viewport.width : 0;
213
+ const vh = isNum(snapshot?.viewport?.height) && snapshot.viewport.height > 0 ? snapshot.viewport.height : 0;
214
+ const vp = { name: vpNameOf(snapshot?.viewport), width: vw, height: vh };
215
+ const rawElements = Array.isArray(snapshot?.elements) ? snapshot.elements : [];
216
+ const cap = resolveCap(options?.maxElements);
217
+ const bounded = takeVisible(rawElements, cap);
218
+ const issues = [];
219
+ const checkMeta = options?.requireViewportMeta === true || (options?.requireViewportMeta !== false && vw > 0 && vw <= DEFAULTS.narrowMaxPx);
220
+ if (checkMeta && snapshot?.hasViewportMeta === false) {
221
+ issues.push({ viewport: vp.name, kind: "MISSING_VIEWPORT_META", severity: "error", message: `Missing <meta name="viewport"> tag on ${vp.name} (${round2(vw)}x${round2(vh)})` });
222
+ }
223
+ const safeScrollWidth = isNum(snapshot?.scrollWidth) && snapshot.scrollWidth >= 0 ? snapshot.scrollWidth : vw;
224
+ const safeScrollHeight = isNum(snapshot?.scrollHeight) && snapshot.scrollHeight >= 0 ? snapshot.scrollHeight : vh;
225
+ issues.push(...detectHorizontalOverflow({
226
+ viewport: vp,
227
+ scrollWidth: isNum(snapshot?.scrollWidth) ? snapshot.scrollWidth : 0,
228
+ scrollHeight: safeScrollHeight,
229
+ elements: bounded,
230
+ hasViewportMeta: snapshot?.hasViewportMeta,
231
+ cssFixedWidthOverflowPx: snapshot?.cssFixedWidthOverflowPx
232
+ }, options?.overflowTolerancePx), ...detectElementOverlaps(bounded, vp.name, { minOverlapRatio: options?.minOverlapRatio, maxElements: cap }), ...detectClippedOrTinyTargets(bounded, vp, { minTouchTargetPx: options?.minTouchTargetPx, checkTouchTargets: options?.checkTouchTargets }));
233
+ const errorCount = issues.filter((i) => i.severity === "error").length;
234
+ return {
235
+ viewport: vp,
236
+ passed: errorCount === 0,
237
+ errorCount,
238
+ warningCount: issues.length - errorCount,
239
+ elementCount: rawElements.length,
240
+ scrollWidth: safeScrollWidth,
241
+ issues
242
+ };
243
+ }
244
+ /** Audit multiple viewport snapshots and aggregate pass/fail status and normalized score. */
245
+ export function auditResponsiveViewports(snapshots, options) {
246
+ const viewports = (Array.isArray(snapshots) ? snapshots : []).map((s) => auditResponsiveViewport(s, options));
247
+ const failedViewports = [];
248
+ const issues = [];
249
+ let totalErrors = 0;
250
+ let totalWarnings = 0;
251
+ let scoreSum = 0;
252
+ for (const res of viewports) {
253
+ if (!res.passed)
254
+ failedViewports.push(res.viewport.name);
255
+ totalErrors += res.errorCount;
256
+ totalWarnings += res.warningCount;
257
+ issues.push(...res.issues);
258
+ scoreSum += Math.max(0, 1 - res.errorCount * 0.25 - res.warningCount * 0.05);
259
+ }
260
+ const viewportsChecked = viewports.length;
261
+ return {
262
+ passed: viewportsChecked > 0 && failedViewports.length === 0,
263
+ score: viewportsChecked > 0 ? round3(scoreSum / viewportsChecked) : 0,
264
+ viewportsChecked,
265
+ failedViewports,
266
+ totalErrors,
267
+ totalWarnings,
268
+ viewports,
269
+ issues
270
+ };
271
+ }
272
+ // --- Linear-time O(N), ReDoS-free static HTML/CSS fallback ---
273
+ function parsePositivePx(raw) {
274
+ const m = POSITIVE_PX_RE.exec(raw.trim());
275
+ const n = m ? Number(m[1]) : NaN;
276
+ return Number.isFinite(n) && n > 0 ? n : null;
277
+ }
278
+ function stripCssComments(css) {
279
+ if (!css.includes("/*"))
280
+ return css;
281
+ const parts = [];
282
+ for (let i = 0; i < css.length;) {
283
+ const s = css.indexOf("/*", i);
284
+ if (s === -1) {
285
+ parts.push(css.slice(i));
286
+ break;
287
+ }
288
+ if (s > i)
289
+ parts.push(css.slice(i, s));
290
+ const e = css.indexOf("*/", s + 2);
291
+ if (e === -1)
292
+ break;
293
+ i = e + 2;
294
+ }
295
+ return parts.join("");
296
+ }
297
+ function extractCssDeclarationOverflows(declBlock, vw) {
298
+ const fixed = [];
299
+ const mins = [];
300
+ let hidden = false;
301
+ let constrainedMax = false;
302
+ for (const part of stripCssComments(declBlock).split(";")) {
303
+ const colon = part.indexOf(":");
304
+ if (colon === -1)
305
+ continue;
306
+ const prop = asciiLower(part.slice(0, colon)).trim();
307
+ if (prop !== "width" && prop !== "min-width" && prop !== "max-width" && prop !== "display")
308
+ continue;
309
+ let val = asciiLower(part.slice(colon + 1)).trim();
310
+ if (val.endsWith("!important"))
311
+ val = val.slice(0, -10).trim();
312
+ if (prop === "display" && val === "none")
313
+ hidden = true;
314
+ else if (prop === "width") {
315
+ const px = parsePositivePx(val);
316
+ if (px !== null && px > vw)
317
+ fixed.push(px);
318
+ }
319
+ else if (prop === "min-width") {
320
+ const px = parsePositivePx(val);
321
+ if (px !== null && px > vw)
322
+ mins.push(px);
323
+ }
324
+ else if (prop === "max-width") {
325
+ const px = parsePositivePx(val);
326
+ if (val === "100%" || val === "100vw" || (px !== null && px <= vw))
327
+ constrainedMax = true;
328
+ }
329
+ }
330
+ return hidden ? [] : constrainedMax ? mins : [...mins, ...fixed];
331
+ }
332
+ function matchesMediaPrelude(prelude, vw) {
333
+ const rest = asciiLower(prelude.slice(6)).trim();
334
+ if (!rest)
335
+ return true;
336
+ for (const raw of rest.split(",")) {
337
+ const branch = raw.trim();
338
+ if (!branch || branch === "print" || branch.startsWith("print ") || branch.startsWith("only print"))
339
+ continue;
340
+ let matched = true;
341
+ let lastOpen = -1;
342
+ for (let pos = 0; pos < branch.length; pos++) {
343
+ const ch = branch.charCodeAt(pos);
344
+ if (ch === 40) {
345
+ lastOpen = pos;
346
+ }
347
+ else if (ch === 41 && lastOpen !== -1) {
348
+ const clause = branch.slice(lastOpen + 1, pos);
349
+ lastOpen = -1;
350
+ const colon = clause.indexOf(":");
351
+ if (colon !== -1) {
352
+ const feat = clause.slice(0, colon).trim();
353
+ const px = parsePositivePx(clause.slice(colon + 1));
354
+ if (px !== null && ((feat === "min-width" && vw < px) || (feat === "max-width" && vw > px)))
355
+ matched = false;
356
+ }
357
+ }
358
+ }
359
+ if (branch.startsWith("not ") ? !matched : matched)
360
+ return true;
361
+ }
362
+ return false;
363
+ }
364
+ function scanStyleSheet(css, vw, recordWidth) {
365
+ const cleaned = stripCssComments(css);
366
+ const stack = [];
367
+ let excessDepth = 0;
368
+ let segStart = 0;
369
+ let quote = "";
370
+ for (let i = 0; i < cleaned.length; i++) {
371
+ const ch = cleaned[i];
372
+ if (quote) {
373
+ if (ch === "\\")
374
+ i++;
375
+ else if (ch === quote)
376
+ quote = "";
377
+ continue;
378
+ }
379
+ if (ch === "'" || ch === '"') {
380
+ quote = ch;
381
+ continue;
382
+ }
383
+ if (ch === ";" && excessDepth === 0 && (stack.length === 0 || stack[stack.length - 1].isAtRule)) {
384
+ segStart = i + 1;
385
+ }
386
+ else if (ch === "{") {
387
+ if (excessDepth > 0 || stack.length >= DEFAULTS.maxCssNesting) {
388
+ excessDepth++;
389
+ segStart = i + 1;
390
+ continue;
391
+ }
392
+ const parent = stack.length > 0 ? stack[stack.length - 1] : null;
393
+ if (parent && parent.active && !parent.isAtRule && i > segStart) {
394
+ for (const px of extractCssDeclarationOverflows(cleaned.slice(segStart, i), vw))
395
+ recordWidth(px);
396
+ }
397
+ const prelude = i > segStart ? cleaned.slice(segStart, i).trim() : "";
398
+ const lower = asciiLower(prelude);
399
+ const parentActive = parent === null || parent.active;
400
+ const isKeyframes = lower.startsWith("@keyframes") || lower.startsWith("@-webkit-keyframes");
401
+ const active = lower.startsWith("@media") ? parentActive && matchesMediaPrelude(prelude, vw) : isKeyframes ? false : parentActive;
402
+ stack.push({ active, isAtRule: lower.startsWith("@") });
403
+ segStart = i + 1;
404
+ }
405
+ else if (ch === "}") {
406
+ if (excessDepth > 0) {
407
+ excessDepth--;
408
+ segStart = i + 1;
409
+ continue;
410
+ }
411
+ const frame = stack.pop();
412
+ if (frame && frame.active && !frame.isAtRule && i > segStart) {
413
+ for (const px of extractCssDeclarationOverflows(cleaned.slice(segStart, i), vw))
414
+ recordWidth(px);
415
+ }
416
+ segStart = i + 1;
417
+ }
418
+ }
419
+ }
420
+ const isSpace = (c) => c === 32 || c === 9 || c === 10 || c === 13 || c === 12;
421
+ function findRawCloseTag(lower, needle, from) {
422
+ let pos = from;
423
+ while (pos < lower.length) {
424
+ const idx = lower.indexOf(needle, pos);
425
+ if (idx === -1)
426
+ return -1;
427
+ const after = idx + needle.length;
428
+ if (after >= lower.length)
429
+ return idx;
430
+ const c = lower.charCodeAt(after);
431
+ if (c === 62 || c === 47 || isSpace(c))
432
+ return idx;
433
+ pos = after;
434
+ }
435
+ return -1;
436
+ }
437
+ function scanTagAttrs(src, lower, start, tag) {
438
+ let pos = start;
439
+ let closed = false;
440
+ let metaName = "";
441
+ let styleAttr = "";
442
+ let idAttr = "";
443
+ while (pos < src.length) {
444
+ while (pos < src.length && isSpace(src.charCodeAt(pos)))
445
+ pos++;
446
+ if (pos >= src.length)
447
+ break;
448
+ const ch = src.charCodeAt(pos);
449
+ if (ch === 62) {
450
+ pos++;
451
+ closed = true;
452
+ break;
453
+ }
454
+ if (ch === 47) {
455
+ pos++;
456
+ continue;
457
+ }
458
+ const kStart = pos;
459
+ while (pos < src.length && !isSpace(src.charCodeAt(pos)) && src.charCodeAt(pos) !== 61 && src.charCodeAt(pos) !== 62 && src.charCodeAt(pos) !== 47)
460
+ pos++;
461
+ const key = lower.slice(kStart, pos);
462
+ while (pos < src.length && isSpace(src.charCodeAt(pos)))
463
+ pos++;
464
+ let val = "";
465
+ if (pos < src.length && src.charCodeAt(pos) === 61) {
466
+ pos++;
467
+ while (pos < src.length && isSpace(src.charCodeAt(pos)))
468
+ pos++;
469
+ const q = pos < src.length ? src.charCodeAt(pos) : 0;
470
+ if (q === 34 || q === 39) {
471
+ const close = src.indexOf(src[pos], pos + 1);
472
+ val = close === -1 ? src.slice(pos + 1) : src.slice(pos + 1, close);
473
+ pos = close === -1 ? src.length : close + 1;
474
+ }
475
+ else {
476
+ const vStart = pos;
477
+ while (pos < src.length && !isSpace(src.charCodeAt(pos)) && src.charCodeAt(pos) !== 62)
478
+ pos++;
479
+ val = src.slice(vStart, pos);
480
+ }
481
+ }
482
+ if (tag === "meta" && key === "name")
483
+ metaName = asciiLower(val).trim();
484
+ else if (key === "style")
485
+ styleAttr = val;
486
+ else if (key === "id")
487
+ idAttr = val.trim();
488
+ }
489
+ return { endPos: pos, closed, metaName, styleAttr, idAttr };
490
+ }
491
+ /** Linear-time O(N), ReDoS-free static HTML/CSS fallback synthesizing a viewport snapshot without Playwright. */
492
+ export function extractResponsiveSnapshotFromHtml(html, viewport) {
493
+ const vw = isNum(viewport?.width) && viewport.width > 0 ? viewport.width : 0;
494
+ const vh = isNum(viewport?.height) && viewport.height > 0 ? viewport.height : 0;
495
+ const vp = { name: vpNameOf(viewport), width: vw, height: vh };
496
+ let source = typeof html === "string" ? (html.length > DEFAULTS.maxHtmlBytes ? html.slice(0, DEFAULTS.maxHtmlBytes) : html) : "";
497
+ if (source.charCodeAt(0) === 0xfeff)
498
+ source = source.slice(1);
499
+ const lower = asciiLower(source);
500
+ let hasViewportMeta = false;
501
+ let maxWidth = vw;
502
+ const overflowSet = new Set();
503
+ const elements = [];
504
+ const recordWidth = (px) => {
505
+ if (vw <= 0 || px <= vw)
506
+ return;
507
+ if (px > maxWidth)
508
+ maxWidth = px;
509
+ if (overflowSet.size < DEFAULTS.maxCssEntries)
510
+ overflowSet.add(round2(px));
511
+ };
512
+ for (let i = 0; i < source.length;) {
513
+ const lt = source.indexOf("<", i);
514
+ if (lt === -1)
515
+ break;
516
+ if (source.startsWith("<!--", lt)) {
517
+ const end = source.indexOf("-->", lt + 4);
518
+ if (end === -1)
519
+ break;
520
+ i = end + 3;
521
+ continue;
522
+ }
523
+ const ch1 = lower[lt + 1] ?? "";
524
+ if (ch1 === "!" || ch1 === "?" || ch1 === "/") {
525
+ const gt = source.indexOf(">", lt + 2);
526
+ if (gt === -1)
527
+ break;
528
+ i = gt + 1;
529
+ continue;
530
+ }
531
+ if (ch1 < "a" || ch1 > "z") {
532
+ i = lt + 1;
533
+ continue;
534
+ }
535
+ let nameEnd = lt + 1;
536
+ while (nameEnd < source.length && /[a-z0-9:_-]/.test(lower[nameEnd]))
537
+ nameEnd++;
538
+ const tag = lower.slice(lt + 1, nameEnd);
539
+ const { endPos, closed, metaName, styleAttr, idAttr } = scanTagAttrs(source, lower, nameEnd, tag);
540
+ if (closed && tag === "meta" && metaName === "viewport")
541
+ hasViewportMeta = true;
542
+ if (closed && styleAttr && vw > 0) {
543
+ let maxInline = 0;
544
+ for (const px of extractCssDeclarationOverflows(styleAttr, vw)) {
545
+ recordWidth(px);
546
+ if (px > maxInline)
547
+ maxInline = px;
548
+ }
549
+ if (maxInline > vw && elements.length < DEFAULTS.maxSyntheticElements) {
550
+ const idx = elements.length;
551
+ elements.push({ id: idAttr || `${tag}-inline-${idx + 1}`, tag, visible: true, interactive: INTERACTIVE_TAGS.has(tag), bbox: { x: 0, y: idx * 48, w: round2(maxInline), h: 32 } });
552
+ }
553
+ }
554
+ if (closed && (tag === "script" || tag === "style")) {
555
+ const needle = tag === "script" ? "</script" : "</style";
556
+ const closeIdx = findRawCloseTag(lower, needle, endPos);
557
+ const bodyEnd = closeIdx === -1 ? source.length : closeIdx;
558
+ if (tag === "style" && vw > 0 && bodyEnd > endPos)
559
+ scanStyleSheet(source.slice(endPos, bodyEnd), vw, recordWidth);
560
+ if (closeIdx === -1)
561
+ break;
562
+ const closeGt = source.indexOf(">", closeIdx + needle.length);
563
+ i = closeGt === -1 ? source.length : closeGt + 1;
564
+ continue;
565
+ }
566
+ i = endPos;
567
+ }
568
+ return { viewport: vp, scrollWidth: round2(maxWidth), scrollHeight: round2(vh), elements, hasViewportMeta, cssFixedWidthOverflowPx: Array.from(overflowSet) };
569
+ }
570
+ const style = (text, codes, useColor) => (useColor ? `${codes}${text}${ANSI.reset}` : text);
571
+ const statusBadge = (passed, warns, c) => !passed ? style("[FAIL]", `${ANSI.bold}${ANSI.red}`, c) : warns > 0 ? style("[WARN]", `${ANSI.bold}${ANSI.yellow}`, c) : style("[PASS]", `${ANSI.bold}${ANSI.green}`, c);
572
+ /** Format a responsive audit report for terminal display (plain or ANSI colored). */
573
+ export function formatPrettyResponsive(report, options) {
574
+ const c = options?.color === true;
575
+ const scorePct = `${(Math.max(0, Math.min(1, isNum(report?.score) ? report.score : 0)) * 100).toFixed(1)}%`;
576
+ const failedList = Array.isArray(report?.failedViewports) ? report.failedViewports : [];
577
+ const viewports = Array.isArray(report?.viewports) ? report.viewports : [];
578
+ const issues = Array.isArray(report?.issues) ? report.issues : [];
579
+ const failedNote = failedList.length > 0 ? ` | Failed: ${failedList.map(clean).join(", ")}` : "";
580
+ const lines = [
581
+ `${style("vibecode-anything responsive", `${ANSI.bold}${ANSI.cyan}`, c)} ${statusBadge(Boolean(report?.passed), isNum(report?.totalWarnings) ? report.totalWarnings : 0, c)}`,
582
+ `Score: ${style(scorePct, ANSI.bold, c)} | Viewports: ${isNum(report?.viewportsChecked) ? report.viewportsChecked : 0} checked | Errors: ${isNum(report?.totalErrors) ? report.totalErrors : 0}, Warnings: ${isNum(report?.totalWarnings) ? report.totalWarnings : 0}${failedNote}`
583
+ ];
584
+ if (viewports.length > 0) {
585
+ lines.push("");
586
+ for (const vp of viewports) {
587
+ lines.push(` ${statusBadge(Boolean(vp?.passed), isNum(vp?.warningCount) ? vp.warningCount : 0, c)} ${vpNameOf(vp?.viewport)} (${round2(vp?.viewport?.width)}x${round2(vp?.viewport?.height)}) scrollWidth=${round2(vp?.scrollWidth)}px elements=${isNum(vp?.elementCount) ? vp.elementCount : 0} (${isNum(vp?.errorCount) ? vp.errorCount : 0} errors, ${isNum(vp?.warningCount) ? vp.warningCount : 0} warnings)`);
588
+ }
589
+ }
590
+ if (issues.length === 0) {
591
+ lines.push("", report?.passed ? style("No responsive layout issues detected.", ANSI.green, c) : style("No viewports audited.", ANSI.yellow, c));
592
+ return lines.join("\n");
593
+ }
594
+ lines.push("", style(`Issues (${issues.length}):`, ANSI.bold, c));
595
+ for (const issue of issues.slice(0, DEFAULTS.maxPrettyIssues)) {
596
+ const sev = issue?.severity === "error" ? style("[ERROR]", `${ANSI.bold}${ANSI.red}`, c) : style("[WARN]", `${ANSI.bold}${ANSI.yellow}`, c);
597
+ const elA = clean(issue?.elementId);
598
+ const elB = clean(issue?.otherElementId);
599
+ const target = elA ? (elB ? ` (${elA} <-> ${elB})` : ` (${elA})`) : "";
600
+ lines.push(` ${sev} ${style(clean(issue?.kind) || "ISSUE", ANSI.bold, c)} [${style(clean(issue?.viewport) || "unknown", ANSI.dim, c)}]${target} - ${clean(issue?.message)}`);
601
+ }
602
+ if (issues.length > DEFAULTS.maxPrettyIssues) {
603
+ lines.push(style(` ... and ${issues.length - DEFAULTS.maxPrettyIssues} more issues`, ANSI.dim, c));
604
+ }
605
+ return lines.join("\n");
606
+ }
@@ -0,0 +1,74 @@
1
+ import type { PluginRegistry } from "../plugins/registry.js";
2
+ import { type AgentCommandRunner, type AgentKind } from "./agent-adapter.js";
3
+ import { type TargetMap } from "./target-map.js";
4
+ import type { ContractSlice, Diagnostic, IngestDeps, ParityReport, VerifyDeps, VerifyMode } from "./types.js";
5
+ export interface RunHistoryEntry {
6
+ iteration: number;
7
+ sliceId?: string;
8
+ agent?: string;
9
+ timestamp: string;
10
+ durationMs: number;
11
+ parity: number;
12
+ compositeScore: number;
13
+ hardPassed: number;
14
+ hardTotal: number;
15
+ gateStatus: string;
16
+ failingInvariantIds: string[];
17
+ diffPngPaths?: string[];
18
+ }
19
+ export interface RunLoopOptions {
20
+ target?: string;
21
+ targets?: TargetMap;
22
+ vars?: Record<string, string>;
23
+ mode?: VerifyMode;
24
+ concurrency?: number;
25
+ skipFixtures?: boolean;
26
+ allowFixtureCommands?: boolean;
27
+ pluginRegistry?: PluginRegistry;
28
+ recordTrends?: boolean;
29
+ cwd?: string;
30
+ source?: string;
31
+ domain?: string;
32
+ agent?: string;
33
+ maxIterations?: number;
34
+ maxMinutes?: number;
35
+ plateauLimit?: number;
36
+ timeoutMs?: number;
37
+ sliceIds?: string[];
38
+ strict?: boolean;
39
+ dryRun?: boolean;
40
+ forceIngest?: boolean;
41
+ useCache?: boolean;
42
+ headers?: Record<string, string>;
43
+ storageState?: string;
44
+ }
45
+ export type RunStopReason = "passed" | "dry_run" | "max_iterations" | "max_minutes" | "plateau" | "quota_exceeded" | "contract_tampered" | "adapter_missing" | "agent_error";
46
+ export interface PlannedSliceInfo {
47
+ id: string;
48
+ title: string;
49
+ invariantIds: string[];
50
+ }
51
+ export interface RunLoopResult {
52
+ ok: boolean;
53
+ dryRun: boolean;
54
+ agent: string;
55
+ specPath: string;
56
+ historyPath: string;
57
+ iterations: RunHistoryEntry[];
58
+ plannedSlices: PlannedSliceInfo[];
59
+ finalReport: ParityReport | null;
60
+ stoppedReason: RunStopReason;
61
+ tamperedFiles?: string[];
62
+ diagnostic?: Diagnostic;
63
+ }
64
+ export interface RunLoopDeps {
65
+ verifyDeps?: VerifyDeps;
66
+ ingestDeps?: IngestDeps;
67
+ commandRunner?: AgentCommandRunner;
68
+ detectAgent?: (preferred?: AgentKind) => AgentKind | null;
69
+ }
70
+ export declare function sortSlicesTopologically(slices: readonly ContractSlice[]): ContractSlice[];
71
+ export declare function resolveHistoryPath(workspaceDir: string): string;
72
+ export declare function readRunHistory(workspaceDir: string): RunHistoryEntry[];
73
+ export declare function writeRunHistory(workspaceDir: string, entries: readonly RunHistoryEntry[]): string;
74
+ export declare function runClosedLoop(options: RunLoopOptions, deps?: RunLoopDeps): Promise<RunLoopResult>;