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
@@ -1,7 +1,11 @@
1
+ import crypto from "node:crypto";
1
2
  import { VibecodeError, errorMessage } from "../core/errors.js";
2
- import { loadPlaywright } from "../core/adapters.js";
3
+ import { loadPlaywright, launchBrowser } from "../core/adapters.js";
4
+ import { isRecordSafe, redactSensitiveText, resolveSafeTargetUrl } from "../core/security.js";
3
5
  import { compareRegionsIoU } from "../core/visual.js";
4
- import { extractTitle, extractAllLandmarks } from "../ingestors/web.js";
6
+ import { auditResponsiveViewports, extractResponsiveSnapshotFromHtml } from "../core/responsive.js";
7
+ import { extractTitle, extractAllLandmarks, stripTags, openBrowserPage, gotoWithSpaFallback, extractInteractiveLandmarks } from "../ingestors/web.js";
8
+ import { filterRuntimeHeaders, mergeHeaders } from "../ingestors/trace.js";
5
9
  const PLAYWRIGHT_INSTALL_HINT = "npm install -D playwright && npx playwright install chromium";
6
10
  function resolvePlaywright(candidate) {
7
11
  if (!candidate || typeof candidate !== "object")
@@ -15,35 +19,67 @@ function resolvePlaywright(candidate) {
15
19
  }
16
20
  return null;
17
21
  }
18
- async function getPlaywright(deps) {
22
+ async function getPlaywright(deps, cwd) {
19
23
  const explicit = Object.prototype.hasOwnProperty.call(deps, "playwright") ? deps.playwright : undefined;
20
24
  if (explicit === null)
21
25
  return null;
22
- const loaded = explicit !== undefined ? explicit : await loadPlaywright(deps);
26
+ const loaded = explicit !== undefined ? explicit : await loadPlaywright(cwd ? { ...deps, cwd } : deps);
23
27
  return resolvePlaywright(loaded);
24
28
  }
25
- async function launchBrowser(pw, featureName) {
26
- try {
27
- return await pw.chromium.launch({ headless: true });
28
- }
29
- catch (err) {
30
- throw new VibecodeError("ADAPTER_MISSING", `${featureName} requires Playwright Chromium (${errorMessage(err)})`, {
31
- adapter: "playwright",
32
- installHint: PLAYWRIGHT_INSTALL_HINT
29
+ const isObject = isRecordSafe;
30
+ function expectsStatusGe500(expectedStatus) {
31
+ if (typeof expectedStatus === "number")
32
+ return expectedStatus >= 500;
33
+ if (Array.isArray(expectedStatus))
34
+ return expectedStatus.some((s) => typeof s === "number" && s >= 500);
35
+ return false;
36
+ }
37
+ function computeCandidateOutputHash(title, bodyText) {
38
+ const normalized = `${title}\n${bodyText}`.replace(/\s+/g, " ").trim();
39
+ if (!normalized)
40
+ return undefined;
41
+ return crypto.createHash("sha256").update(normalized, "utf8").digest("hex");
42
+ }
43
+ function checkInteractiveLandmarks(expected, actual) {
44
+ const failures = [];
45
+ const list = actual || [];
46
+ for (const exp of expected || []) {
47
+ if (!exp || (!exp.role && !exp.tag))
48
+ continue;
49
+ const expRole = exp.role ? String(exp.role).toLowerCase() : "";
50
+ const expTag = exp.tag ? String(exp.tag).toLowerCase() : "";
51
+ const expName = exp.name ? String(exp.name).trim().toLowerCase() : "";
52
+ const matched = list.some((act) => {
53
+ const actRole = String(act.role || "").toLowerCase();
54
+ const actTag = String(act.tag || "").toLowerCase();
55
+ const actName = String(act.name || "").trim().toLowerCase();
56
+ if (expRole && actRole !== expRole)
57
+ return false;
58
+ if (expTag && actTag !== expTag)
59
+ return false;
60
+ if (expName && !actName.includes(expName))
61
+ return false;
62
+ return true;
33
63
  });
64
+ if (!matched) {
65
+ failures.push(`missing interactive landmark ${exp.role || "*"} <${exp.tag || "*"}>${exp.name ? ` (${JSON.stringify(exp.name)})` : ""}`);
66
+ }
34
67
  }
68
+ return failures;
35
69
  }
36
70
  function buildUrl(base, routePath) {
37
- if (/^https?:\/\//i.test(routePath))
38
- return routePath;
39
- const baseUrl = /^https?:\/\//i.test(base) ? base : `http://${base}`;
40
- return new URL(routePath, baseUrl).toString();
71
+ return resolveSafeTargetUrl(routePath || "/", base).toString();
41
72
  }
42
- async function fetchRoute(url, timeoutMs = 15000) {
73
+ async function fetchRoute(url, timeoutMs = 15000, headers) {
43
74
  const ctrl = new AbortController();
44
75
  const t = setTimeout(() => ctrl.abort(), timeoutMs);
76
+ const cleanHeaders = filterRuntimeHeaders(headers);
45
77
  try {
46
- const res = await fetch(url, { signal: ctrl.signal, redirect: "follow" });
78
+ const res = await fetch(url, {
79
+ signal: ctrl.signal,
80
+ redirect: "follow",
81
+ ...(Object.keys(cleanHeaders).length > 0 ? { headers: cleanHeaders } : {})
82
+ });
47
83
  const html = await res.text();
48
84
  return { status: res.status, title: extractTitle(html), landmarks: extractAllLandmarks(html), html };
49
85
  }
@@ -82,35 +118,263 @@ function checkStatus(expectedStatus, actualStatus) {
82
118
  }
83
119
  return null;
84
120
  }
121
+ function normalizeResponsiveViewports(raw) {
122
+ if (!Array.isArray(raw))
123
+ return [];
124
+ const out = [];
125
+ for (const vp of raw) {
126
+ if (vp &&
127
+ typeof vp === "object" &&
128
+ typeof vp.name === "string" &&
129
+ vp.name.trim().length > 0 &&
130
+ typeof vp.width === "number" &&
131
+ Number.isFinite(vp.width) &&
132
+ vp.width > 0 &&
133
+ typeof vp.height === "number" &&
134
+ Number.isFinite(vp.height) &&
135
+ vp.height > 0) {
136
+ out.push({ name: vp.name.trim(), width: vp.width, height: vp.height });
137
+ }
138
+ }
139
+ return out;
140
+ }
141
+ function applyResponsiveReport(responsive, failures, metrics, diff) {
142
+ metrics.responsive = {
143
+ passed: responsive.passed,
144
+ score: responsive.score,
145
+ viewportsChecked: responsive.viewportsChecked,
146
+ failedViewports: responsive.failedViewports,
147
+ totalErrors: responsive.totalErrors,
148
+ totalWarnings: responsive.totalWarnings,
149
+ viewports: responsive.viewports.map((v) => ({
150
+ name: v.viewport.name,
151
+ width: v.viewport.width,
152
+ height: v.viewport.height,
153
+ passed: v.passed,
154
+ errorCount: v.errorCount,
155
+ warningCount: v.warningCount,
156
+ scrollWidth: v.scrollWidth
157
+ }))
158
+ };
159
+ if (!responsive.passed) {
160
+ const errorIssues = responsive.issues.filter((i) => i.severity === "error");
161
+ const toReport = errorIssues.length > 0 ? errorIssues : responsive.issues;
162
+ for (const issue of toReport.slice(0, 15)) {
163
+ failures.push(`responsive [${issue.viewport}] ${issue.kind}: ${issue.message}`);
164
+ }
165
+ if (toReport.length > 15) {
166
+ failures.push(`responsive: ${toReport.length - 15} more responsive layout issues`);
167
+ }
168
+ diff.responsiveIssues = responsive.issues;
169
+ }
170
+ }
171
+ async function readPageHtmlFallback(page) {
172
+ if (typeof page.content === "function") {
173
+ try {
174
+ const html = await page.content();
175
+ if (typeof html === "string")
176
+ return html;
177
+ }
178
+ catch {
179
+ // fall through
180
+ }
181
+ }
182
+ try {
183
+ const html = await page.evaluate(() => {
184
+ if (typeof document === "undefined")
185
+ return "";
186
+ if (document.documentElement && typeof document.documentElement.outerHTML === "string") {
187
+ return document.documentElement.outerHTML;
188
+ }
189
+ if (document.body && typeof document.body.innerHTML === "string") {
190
+ return document.body.innerHTML;
191
+ }
192
+ return "";
193
+ });
194
+ return typeof html === "string" ? html : "";
195
+ }
196
+ catch {
197
+ return "";
198
+ }
199
+ }
200
+ async function capturePlaywrightResponsiveSnapshots(page, viewports, originalViewport) {
201
+ let cachedFallbackHtml = null;
202
+ const getFallbackHtml = async () => {
203
+ if (cachedFallbackHtml === null)
204
+ cachedFallbackHtml = await readPageHtmlFallback(page);
205
+ return cachedFallbackHtml;
206
+ };
207
+ if (typeof page.setViewportSize !== "function") {
208
+ const html = await getFallbackHtml();
209
+ return viewports.map((vp) => extractResponsiveSnapshotFromHtml(html, vp));
210
+ }
211
+ const snapshots = [];
212
+ try {
213
+ for (const vp of viewports) {
214
+ await page.setViewportSize({ width: vp.width, height: vp.height });
215
+ let evaluated = null;
216
+ try {
217
+ evaluated = await page.evaluate(() => {
218
+ if (typeof document === "undefined" || !document.documentElement)
219
+ return null;
220
+ const docEl = document.documentElement;
221
+ const body = document.body;
222
+ const scrollWidth = Math.max(Number(docEl.scrollWidth || 0), Number(body?.scrollWidth || 0));
223
+ const scrollHeight = Math.max(Number(docEl.scrollHeight || 0), Number(body?.scrollHeight || 0));
224
+ let hasViewportMeta;
225
+ if (typeof document.querySelectorAll === "function") {
226
+ const metas = document.querySelectorAll("meta");
227
+ hasViewportMeta = false;
228
+ for (let m = 0; m < metas.length; m++) {
229
+ const nameAttr = metas[m]?.getAttribute?.("name");
230
+ if (typeof nameAttr === "string" && nameAttr.trim().toLowerCase() === "viewport") {
231
+ hasViewportMeta = true;
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ const elements = [];
237
+ if (typeof document.querySelectorAll === "function") {
238
+ const nodes = document.querySelectorAll("header,nav,main,footer,section,article,aside,form,table,h1,h2,h3,p,a,button,input,select,textarea,[role='button'],[role='link'],[data-testid]");
239
+ const interactiveSet = new Set(["a", "button", "input", "select", "textarea"]);
240
+ const limit = Math.min(nodes.length, 500);
241
+ for (let i = 0; i < limit; i++) {
242
+ const el = nodes[i];
243
+ if (!el || typeof el.getBoundingClientRect !== "function")
244
+ continue;
245
+ if (typeof window !== "undefined" && typeof window.getComputedStyle === "function") {
246
+ const cs = window.getComputedStyle(el);
247
+ if (cs && (cs.display === "none" || cs.visibility === "hidden" || cs.opacity === "0"))
248
+ continue;
249
+ }
250
+ const r = el.getBoundingClientRect();
251
+ const tag = String(el.tagName || "").toLowerCase();
252
+ const role = typeof el.getAttribute === "function" ? (el.getAttribute("role") || undefined) : undefined;
253
+ const interactive = interactiveSet.has(tag) || role === "button" || role === "link";
254
+ const idAttr = typeof el.getAttribute === "function" ? el.getAttribute("id") : el.id;
255
+ const testId = typeof el.getAttribute === "function" ? el.getAttribute("data-testid") : null;
256
+ const id = (idAttr && idAttr.trim()) || (testId && testId.trim()) || `${tag || "el"}-${i + 1}`;
257
+ elements.push({
258
+ id,
259
+ ...(tag ? { tag } : {}),
260
+ ...(role ? { role } : {}),
261
+ interactive,
262
+ visible: true,
263
+ bbox: { x: r.x, y: r.y, w: r.width, h: r.height }
264
+ });
265
+ }
266
+ }
267
+ return { scrollWidth, scrollHeight, hasViewportMeta, elements };
268
+ });
269
+ }
270
+ catch {
271
+ evaluated = null;
272
+ }
273
+ if (evaluated &&
274
+ typeof evaluated === "object" &&
275
+ typeof evaluated.scrollWidth === "number" &&
276
+ Number.isFinite(evaluated.scrollWidth) &&
277
+ Array.isArray(evaluated.elements)) {
278
+ snapshots.push({
279
+ viewport: vp,
280
+ scrollWidth: evaluated.scrollWidth,
281
+ scrollHeight: typeof evaluated.scrollHeight === "number" && Number.isFinite(evaluated.scrollHeight)
282
+ ? evaluated.scrollHeight
283
+ : vp.height,
284
+ elements: evaluated.elements,
285
+ ...(typeof evaluated.hasViewportMeta === "boolean" ? { hasViewportMeta: evaluated.hasViewportMeta } : {})
286
+ });
287
+ }
288
+ else {
289
+ const html = await getFallbackHtml();
290
+ snapshots.push(extractResponsiveSnapshotFromHtml(html, vp));
291
+ }
292
+ }
293
+ }
294
+ finally {
295
+ try {
296
+ await page.setViewportSize(originalViewport);
297
+ }
298
+ catch {
299
+ // ignore viewport restore errors
300
+ }
301
+ }
302
+ return snapshots;
303
+ }
85
304
  async function verifyRouteWithFetch(invariant, ctx, deps) {
86
305
  const input = invariant.input || {};
87
306
  const expected = invariant.expected || {};
88
- const url = buildUrl(ctx.target, input.path || "/");
307
+ let url;
308
+ try {
309
+ url = buildUrl(ctx.target, input.path || "/");
310
+ }
311
+ catch (err) {
312
+ return {
313
+ status: "fail",
314
+ score: 0,
315
+ failures: [redactSensitiveText(`invalid URL: ${errorMessage(err)}`)],
316
+ metrics: { backend: "fetch", url: redactSensitiveText(String(input.path || ctx.target)) }
317
+ };
318
+ }
319
+ const safeUrl = redactSensitiveText(url);
320
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
89
321
  let obs;
90
322
  try {
91
- obs = await (deps.fetchRoute || fetchRoute)(url, input.timeoutMs || 15000);
323
+ const timeout = input.timeoutMs || 15000;
324
+ obs =
325
+ Object.keys(mergedHeaders).length > 0
326
+ ? await (deps.fetchRoute || fetchRoute)(url, timeout, mergedHeaders)
327
+ : await (deps.fetchRoute || fetchRoute)(url, timeout);
92
328
  }
93
329
  catch (err) {
94
330
  return {
95
331
  status: "fail",
96
332
  score: 0,
97
- failures: [`request failed: ${errorMessage(err)}`],
98
- metrics: { backend: "fetch", url }
333
+ failures: [redactSensitiveText(`request failed: ${errorMessage(err)}`)],
334
+ metrics: { backend: "fetch", url: safeUrl }
99
335
  };
100
336
  }
101
337
  const failures = [];
102
338
  const statusErr = checkStatus(expected.status, obs.status);
103
339
  if (statusErr)
104
340
  failures.push(statusErr);
341
+ const enforceNoServerErrors = !expectsStatusGe500(expected.status) &&
342
+ (expected.noServerErrors === true || (expected.noServerErrors !== false && invariant.severity === "hard"));
343
+ if (obs.status >= 500 && enforceNoServerErrors) {
344
+ failures.push(`server error response: HTTP ${obs.status}`);
345
+ }
105
346
  if (expected.titleContains && !String(obs.title).includes(expected.titleContains)) {
106
347
  failures.push(`title missing ${JSON.stringify(expected.titleContains)} (got ${JSON.stringify(obs.title)})`);
107
348
  }
108
349
  failures.push(...checkLandmarks(expected.landmarks, obs.landmarks));
350
+ const candidateOutputHash = computeCandidateOutputHash(obs.title || "", stripTags(obs.html || ""));
351
+ const metrics = {
352
+ backend: "fetch",
353
+ status: obs.status,
354
+ title: obs.title,
355
+ landmarkCount: obs.landmarks.length,
356
+ ...(candidateOutputHash ? { candidateOutputHash } : {})
357
+ };
358
+ const diff = {};
359
+ const responsiveViewports = normalizeResponsiveViewports(expected.responsiveViewports);
360
+ let responsiveReport = null;
361
+ if (responsiveViewports.length > 0) {
362
+ const snapshots = responsiveViewports.map((vp) => extractResponsiveSnapshotFromHtml(obs.html || "", vp));
363
+ responsiveReport = auditResponsiveViewports(snapshots);
364
+ applyResponsiveReport(responsiveReport, failures, metrics, diff);
365
+ }
366
+ const hasDiff = Object.keys(diff).length > 0;
367
+ const score = failures.length === 0
368
+ ? 1
369
+ : invariant.severity === "soft" && responsiveReport
370
+ ? responsiveReport.score
371
+ : 0;
109
372
  return {
110
373
  status: failures.length ? "fail" : "pass",
111
- score: failures.length ? 0 : 1,
374
+ score,
112
375
  failures,
113
- metrics: { backend: "fetch", status: obs.status, title: obs.title, landmarkCount: obs.landmarks.length }
376
+ metrics,
377
+ ...(hasDiff ? { diff } : {})
114
378
  };
115
379
  }
116
380
  function dedupeBoxes(boxes) {
@@ -128,18 +392,33 @@ function dedupeBoxes(boxes) {
128
392
  async function verifyRouteWithPlaywright(invariant, ctx, _deps, pw) {
129
393
  const input = invariant.input || {};
130
394
  const expected = invariant.expected || {};
131
- const url = buildUrl(ctx.target, input.path || "/");
395
+ let url;
396
+ try {
397
+ url = buildUrl(ctx.target, input.path || "/");
398
+ }
399
+ catch (err) {
400
+ return {
401
+ status: "fail",
402
+ score: 0,
403
+ failures: [redactSensitiveText(`invalid URL: ${errorMessage(err)}`)],
404
+ metrics: { backend: "playwright" }
405
+ };
406
+ }
132
407
  const viewport = input.viewport || { width: 1280, height: 720 };
133
- const browser = await launchBrowser(pw, "web_route verification");
408
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
409
+ const storageState = ctx.storageState || input.storageState;
410
+ const browser = await launchBrowser(pw, { headless: true, featureName: "web_route verification" });
134
411
  try {
135
- const page = await browser.newPage({ viewport });
412
+ const pageHandle = await openBrowserPage(browser, { viewport, headers: mergedHeaders, storageState });
413
+ const { page } = pageHandle;
136
414
  try {
415
+ const telemetry = await attachTelemetry(page);
137
416
  let response = null;
138
417
  try {
139
- response = await page.goto(url, { waitUntil: input.waitUntil || "networkidle", timeout: input.timeoutMs || 15000 });
418
+ response = await gotoWithSpaFallback(page, url, input.waitUntil || "networkidle", input.timeoutMs || 15000);
140
419
  }
141
420
  catch (err) {
142
- return { status: "fail", score: 0, failures: [`navigation failed: ${errorMessage(err)}`], metrics: { backend: "playwright" } };
421
+ return { status: "fail", score: 0, failures: [redactSensitiveText(`navigation failed: ${errorMessage(err)}`)], metrics: { backend: "playwright" } };
143
422
  }
144
423
  const failures = [];
145
424
  const status = response?.status?.() ?? 200;
@@ -150,9 +429,19 @@ async function verifyRouteWithPlaywright(invariant, ctx, _deps, pw) {
150
429
  if (expected.titleContains && !String(title).includes(expected.titleContains)) {
151
430
  failures.push(`title missing ${JSON.stringify(expected.titleContains)} (got ${JSON.stringify(title)})`);
152
431
  }
153
- const found = await page.$$eval("header,nav,main,footer,h1,h2,form,table,ul", (nodes) => nodes.map((n) => ({ tag: n.tagName.toLowerCase(), text: (n.textContent || "").trim().slice(0, 120) }))).catch(() => []);
432
+ const wantsParagraph = (expected.landmarks || []).some((l) => String(l.tag).toLowerCase() === "p");
433
+ const selector = wantsParagraph
434
+ ? "header,nav,main,footer,h1,h2,form,table,ul,p"
435
+ : "header,nav,main,footer,h1,h2,form,table,ul";
436
+ const found = await page.$$eval(selector, (nodes) => nodes.map((n) => ({ tag: n.tagName.toLowerCase(), text: (n.textContent || "").trim().slice(0, 120) }))).catch(() => []);
154
437
  failures.push(...checkLandmarks(expected.landmarks, found));
155
438
  const metrics = { backend: "playwright", status, title, landmarkCount: found.length };
439
+ const diff = {};
440
+ if (Array.isArray(expected.interactiveLandmarks) && expected.interactiveLandmarks.length > 0) {
441
+ const foundInteractive = await extractInteractiveLandmarks(page);
442
+ metrics.interactiveLandmarkCount = foundInteractive.length;
443
+ failures.push(...checkInteractiveLandmarks(expected.interactiveLandmarks, foundInteractive));
444
+ }
156
445
  if (Array.isArray(expected.boundingBoxes) && expected.boundingBoxes.length) {
157
446
  const actualBoxes = [];
158
447
  for (const item of expected.boundingBoxes) {
@@ -179,16 +468,57 @@ async function verifyRouteWithPlaywright(invariant, ctx, _deps, pw) {
179
468
  if (cmp.meanIoU < minIoU)
180
469
  failures.push(`layoutIoU ${cmp.meanIoU.toFixed(3)} < ${minIoU}`);
181
470
  }
182
- const score = invariant.severity === "soft" && typeof metrics.layoutIoU === "number"
183
- ? metrics.layoutIoU
184
- : (failures.length ? 0 : 1);
185
- return { status: failures.length ? "fail" : "pass", score, failures, metrics };
186
- }
187
- finally {
471
+ const responsiveViewports = normalizeResponsiveViewports(expected.responsiveViewports);
472
+ let responsiveReport = null;
473
+ if (responsiveViewports.length > 0) {
474
+ const snapshots = await capturePlaywrightResponsiveSnapshots(page, responsiveViewports, viewport);
475
+ responsiveReport = auditResponsiveViewports(snapshots);
476
+ applyResponsiveReport(responsiveReport, failures, metrics, diff);
477
+ }
478
+ const telemetryNow = telemetry.collect();
479
+ const enforceNoPageErrors = expected.noPageErrors === true || (expected.noPageErrors !== false && invariant.severity === "hard");
480
+ if (enforceNoPageErrors) {
481
+ for (const err of telemetryNow.pageErrors) {
482
+ failures.push(`uncaught page error: ${err}`);
483
+ }
484
+ }
485
+ const serverErrorResponses = telemetryNow.network.filter((c) => c.status >= 500);
486
+ if (status >= 500 && !serverErrorResponses.some((c) => c.status === status)) {
487
+ let reqPath = "/";
488
+ try {
489
+ reqPath = new URL(url).pathname;
490
+ }
491
+ catch { /* keep "/" */ }
492
+ serverErrorResponses.push({ method: "GET", pathPattern: reqPath, status });
493
+ }
494
+ const enforceNoServerErrors = !expectsStatusGe500(expected.status) &&
495
+ (expected.noServerErrors === true || (expected.noServerErrors !== false && invariant.severity === "hard"));
496
+ if (enforceNoServerErrors) {
497
+ for (const errRes of serverErrorResponses) {
498
+ failures.push(`server error response: ${errRes.method} ${errRes.pathPattern} returned HTTP ${errRes.status}`);
499
+ }
500
+ }
501
+ let bodyText = "";
188
502
  try {
189
- await page.close?.();
503
+ bodyText = await page.evaluate(() => typeof document !== "undefined" && document.body ? (document.body.innerText || document.body.textContent || "") : "");
190
504
  }
191
505
  catch { /* ignore */ }
506
+ const candidateOutputHash = computeCandidateOutputHash(title || "", bodyText || "");
507
+ if (candidateOutputHash) {
508
+ metrics.candidateOutputHash = candidateOutputHash;
509
+ }
510
+ metrics.pageErrors = telemetryNow.pageErrors.length;
511
+ metrics.serverErrors = serverErrorResponses.length;
512
+ const hasDiff = Object.keys(diff).length > 0;
513
+ const score = invariant.severity === "soft" && typeof metrics.layoutIoU === "number"
514
+ ? (responsiveReport ? Math.min(metrics.layoutIoU, responsiveReport.score) : metrics.layoutIoU)
515
+ : invariant.severity === "soft" && responsiveReport
516
+ ? (failures.length ? responsiveReport.score : 1)
517
+ : (failures.length ? 0 : 1);
518
+ return { status: failures.length ? "fail" : "pass", score, failures, metrics, ...(hasDiff ? { diff } : {}) };
519
+ }
520
+ finally {
521
+ await pageHandle.close();
192
522
  }
193
523
  }
194
524
  finally {
@@ -201,7 +531,7 @@ async function verifyRouteWithPlaywright(invariant, ctx, _deps, pw) {
201
531
  async function verifyRoute(invariant, ctx, deps) {
202
532
  if (!ctx.target)
203
533
  throw new VibecodeError("TARGET_MISSING", "Missing --target <url> for web verification.");
204
- const pw = await getPlaywright(deps);
534
+ const pw = await getPlaywright(deps, ctx.cwd);
205
535
  if (pw) {
206
536
  try {
207
537
  return await verifyRouteWithPlaywright(invariant, ctx, deps, pw);
@@ -231,8 +561,16 @@ async function attachTelemetry(page) {
231
561
  if (typeof page.on === "function") {
232
562
  page.on("response", (res) => {
233
563
  try {
234
- const parsed = new URL(res.url());
235
- network.push({ method: res.request().method(), pathPattern: parsed.pathname, status: res.status(), contentType: res.headers()?.["content-type"] });
564
+ const resRec = res;
565
+ const rawUrl = typeof resRec.url === "function" ? resRec.url() : String(resRec.url ?? "");
566
+ const parsed = new URL(rawUrl);
567
+ const reqObj = typeof resRec.request === "function" ? resRec.request() : undefined;
568
+ const method = reqObj && typeof reqObj.method === "function"
569
+ ? reqObj.method()
570
+ : String(reqObj?.method ?? "GET");
571
+ const status = typeof resRec.status === "function" ? resRec.status() : Number(resRec.status ?? 200);
572
+ const headersObj = typeof resRec.headers === "function" ? resRec.headers() : resRec.headers;
573
+ network.push({ method, pathPattern: parsed.pathname, status, contentType: headersObj?.["content-type"] });
236
574
  }
237
575
  catch { /* ignore */ }
238
576
  });
@@ -243,9 +581,9 @@ async function attachTelemetry(page) {
243
581
  return {
244
582
  collect() {
245
583
  return {
246
- network: Array.isArray(page.__networkCalls) ? page.__networkCalls : network,
247
- consoleErrors: Array.isArray(page.__consoleErrors) ? page.__consoleErrors : consoleErrors,
248
- pageErrors: Array.isArray(page.__pageErrors) ? page.__pageErrors : pageErrors
584
+ network: network.length > 0 ? network : (Array.isArray(page.__networkCalls) ? page.__networkCalls : network),
585
+ consoleErrors: consoleErrors.length > 0 ? consoleErrors : (Array.isArray(page.__consoleErrors) ? page.__consoleErrors : consoleErrors),
586
+ pageErrors: pageErrors.length > 0 ? pageErrors : (Array.isArray(page.__pageErrors) ? page.__pageErrors : pageErrors)
249
587
  };
250
588
  }
251
589
  };
@@ -253,7 +591,7 @@ async function attachTelemetry(page) {
253
591
  async function verifyFlow(invariant, ctx, deps) {
254
592
  if (!ctx.target)
255
593
  throw new VibecodeError("TARGET_MISSING", "Missing --target <url> for web flow verification.");
256
- const pw = await getPlaywright(deps);
594
+ const pw = await getPlaywright(deps, ctx.cwd);
257
595
  if (!pw) {
258
596
  throw new VibecodeError("ADAPTER_MISSING", "web_flow verification requires Playwright", {
259
597
  adapter: "playwright",
@@ -262,24 +600,38 @@ async function verifyFlow(invariant, ctx, deps) {
262
600
  }
263
601
  const input = invariant.input || {};
264
602
  const expected = invariant.expected || {};
265
- const startUrl = buildUrl(ctx.target, input.startPath || "/");
603
+ let startUrl;
604
+ try {
605
+ startUrl = buildUrl(ctx.target, input.startPath || "/");
606
+ }
607
+ catch (err) {
608
+ return {
609
+ status: "fail",
610
+ score: 0,
611
+ failures: [redactSensitiveText(`invalid startPath URL: ${errorMessage(err)}`)],
612
+ metrics: { backend: "playwright" }
613
+ };
614
+ }
266
615
  const viewport = input.viewport || { width: 1280, height: 720 };
267
- const browser = await launchBrowser(pw, "web_flow verification");
616
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
617
+ const storageState = ctx.storageState || input.storageState;
618
+ const browser = await launchBrowser(pw, { headless: true, featureName: "web_flow verification" });
268
619
  try {
269
- const page = await browser.newPage({ viewport });
620
+ const pageHandle = await openBrowserPage(browser, { viewport, headers: mergedHeaders, storageState });
621
+ const { page } = pageHandle;
270
622
  try {
271
623
  const actionPage = page;
272
624
  const telemetry = await attachTelemetry(page);
273
625
  const failures = [];
274
626
  const navTimeoutMs = input.timeoutMs || 15000;
275
627
  try {
276
- await page.goto(startUrl, { waitUntil: input.waitUntil || "networkidle", timeout: navTimeoutMs });
628
+ await gotoWithSpaFallback(page, startUrl, input.waitUntil || "networkidle", navTimeoutMs);
277
629
  }
278
630
  catch (err) {
279
631
  return {
280
632
  status: "fail",
281
633
  score: 0,
282
- failures: [`navigation failed: ${errorMessage(err)}`],
634
+ failures: [redactSensitiveText(`navigation failed: ${errorMessage(err)}`)],
283
635
  metrics: { backend: "playwright" }
284
636
  };
285
637
  }
@@ -294,10 +646,7 @@ async function verifyFlow(invariant, ctx, deps) {
294
646
  else if (step.action === "press")
295
647
  await actionPage.press(selector, step.key || "Enter", { timeout: stepTimeoutMs });
296
648
  else if (step.action === "goto") {
297
- await page.goto(buildUrl(ctx.target, step.url || step.path || "/"), {
298
- waitUntil: step.waitUntil || "networkidle",
299
- timeout: step.timeoutMs || input.timeoutMs || 15000
300
- });
649
+ await gotoWithSpaFallback(page, buildUrl(ctx.target, step.url || step.path || "/"), step.waitUntil || "networkidle", step.timeoutMs || input.timeoutMs || 15000);
301
650
  }
302
651
  else if (step.action === "select") {
303
652
  await actionPage.selectOption(selector, String(step.value ?? ""), { timeout: stepTimeoutMs });
@@ -319,16 +668,17 @@ async function verifyFlow(invariant, ctx, deps) {
319
668
  }
320
669
  }
321
670
  catch (err) {
322
- failures.push(`step ${step.action} failed: ${errorMessage(err)}`);
671
+ failures.push(redactSensitiveText(`step ${step.action} failed: ${errorMessage(err)}`));
323
672
  }
324
673
  }
325
- const finalUrl = typeof page.url === "function" ? page.url() : startUrl;
326
- if (expected.finalUrlIncludes && !String(finalUrl).includes(expected.finalUrlIncludes)) {
674
+ const rawFinalUrl = typeof page.url === "function" ? page.url() : startUrl;
675
+ const finalUrl = redactSensitiveText(String(rawFinalUrl));
676
+ if (expected.finalUrlIncludes && !String(rawFinalUrl).includes(expected.finalUrlIncludes)) {
327
677
  failures.push(`finalUrl ${finalUrl} does not include ${expected.finalUrlIncludes}`);
328
678
  }
329
679
  let bodyText = "";
330
680
  try {
331
- bodyText = await page.evaluate(() => document.body ? document.body.innerText : "");
681
+ bodyText = await page.evaluate(() => typeof document !== "undefined" && document.body ? (document.body.innerText || document.body.textContent || "") : "");
332
682
  }
333
683
  catch { /* ignore */ }
334
684
  for (const text of expected.visibleText || []) {
@@ -372,10 +722,38 @@ async function verifyFlow(invariant, ctx, deps) {
372
722
  for (const err of telemetryNow.consoleErrors)
373
723
  failures.push(`console error: ${err}`);
374
724
  }
375
- if (expected.noUncaughtExceptions) {
725
+ const enforceNoPageErrors = Boolean(expected.noUncaughtExceptions) ||
726
+ expected.noPageErrors === true ||
727
+ (expected.noPageErrors !== false && invariant.severity === "hard");
728
+ if (enforceNoPageErrors) {
376
729
  for (const err of telemetryNow.pageErrors)
377
730
  failures.push(`uncaught exception: ${err}`);
378
731
  }
732
+ const expected500Matchers = (expected.networkCalls || []).filter((c) => typeof c.status === "number" && c.status >= 500);
733
+ const serverErrorResponses = networkCalls.filter((c) => {
734
+ if (c.status < 500)
735
+ return false;
736
+ return !expected500Matchers.some((exp) => {
737
+ const methodOk = !exp.method || String(exp.method).toUpperCase() === String(c.method).toUpperCase();
738
+ if (!methodOk || exp.status !== c.status)
739
+ return false;
740
+ if (!exp.pathPattern)
741
+ return true;
742
+ try {
743
+ return new RegExp(exp.pathPattern).test(c.pathPattern);
744
+ }
745
+ catch {
746
+ return false;
747
+ }
748
+ });
749
+ });
750
+ const enforceNoServerErrors = !expectsStatusGe500(expected.status) &&
751
+ (expected.noServerErrors === true || (expected.noServerErrors !== false && invariant.severity === "hard"));
752
+ if (enforceNoServerErrors) {
753
+ for (const errRes of serverErrorResponses) {
754
+ failures.push(`server error response: ${errRes.method} ${errRes.pathPattern} returned HTTP ${errRes.status}`);
755
+ }
756
+ }
379
757
  const metrics = {
380
758
  backend: "playwright",
381
759
  finalUrl,
@@ -383,15 +761,13 @@ async function verifyFlow(invariant, ctx, deps) {
383
761
  domCounts,
384
762
  networkCalls: networkCalls.length,
385
763
  consoleErrors: telemetryNow.consoleErrors.length,
386
- pageErrors: telemetryNow.pageErrors.length
764
+ pageErrors: telemetryNow.pageErrors.length,
765
+ serverErrors: serverErrorResponses.length
387
766
  };
388
767
  return { status: failures.length ? "fail" : "pass", score: failures.length ? 0 : 1, failures, metrics };
389
768
  }
390
769
  finally {
391
- try {
392
- await page.close?.();
393
- }
394
- catch { /* ignore */ }
770
+ await pageHandle.close();
395
771
  }
396
772
  }
397
773
  finally {
@@ -404,7 +780,7 @@ async function verifyFlow(invariant, ctx, deps) {
404
780
  async function verifyNetwork(invariant, ctx, deps) {
405
781
  if (!ctx.target)
406
782
  throw new VibecodeError("TARGET_MISSING", "Missing --target <url> for web network verification.");
407
- const pw = await getPlaywright(deps);
783
+ const pw = await getPlaywright(deps, ctx.cwd);
408
784
  if (!pw) {
409
785
  throw new VibecodeError("ADAPTER_MISSING", "web_network verification requires Playwright", {
410
786
  adapter: "playwright",
@@ -413,20 +789,38 @@ async function verifyNetwork(invariant, ctx, deps) {
413
789
  }
414
790
  const input = invariant.input || {};
415
791
  const expected = invariant.expected || {};
416
- const url = buildUrl(ctx.target, input.triggerPath || input.path || "/");
417
- const browser = await launchBrowser(pw, "web_network verification");
792
+ let url;
418
793
  try {
419
- const page = await browser.newPage({ viewport: input.viewport || { width: 1280, height: 720 } });
794
+ url = buildUrl(ctx.target, input.triggerPath || input.path || "/");
795
+ }
796
+ catch (err) {
797
+ return {
798
+ status: "fail",
799
+ score: 0,
800
+ failures: [redactSensitiveText(`invalid URL: ${errorMessage(err)}`)],
801
+ metrics: { backend: "playwright" }
802
+ };
803
+ }
804
+ const mergedHeaders = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
805
+ const storageState = ctx.storageState || input.storageState;
806
+ const browser = await launchBrowser(pw, { headless: true, featureName: "web_network verification" });
807
+ try {
808
+ const pageHandle = await openBrowserPage(browser, {
809
+ viewport: input.viewport || { width: 1280, height: 720 },
810
+ headers: mergedHeaders,
811
+ storageState
812
+ });
813
+ const { page } = pageHandle;
420
814
  try {
421
815
  const telemetry = await attachTelemetry(page);
422
816
  try {
423
- await page.goto(url, { waitUntil: input.waitUntil || "networkidle", timeout: input.timeoutMs || 15000 });
817
+ await gotoWithSpaFallback(page, url, input.waitUntil || "networkidle", input.timeoutMs || 15000);
424
818
  }
425
819
  catch (err) {
426
820
  return {
427
821
  status: "fail",
428
822
  score: 0,
429
- failures: [`navigation failed: ${errorMessage(err)}`],
823
+ failures: [redactSensitiveText(`navigation failed: ${errorMessage(err)}`)],
430
824
  metrics: { backend: "playwright" }
431
825
  };
432
826
  }
@@ -456,10 +850,7 @@ async function verifyNetwork(invariant, ctx, deps) {
456
850
  };
457
851
  }
458
852
  finally {
459
- try {
460
- await page.close?.();
461
- }
462
- catch { /* ignore */ }
853
+ await pageHandle.close();
463
854
  }
464
855
  }
465
856
  finally {