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,10 @@
1
+ import type { IngestDeps, IngestOptions, IngestResult, Invariant } from "../core/types.js";
2
+ export declare const SENSITIVE_HEADER_NAMES: Set<string>;
3
+ export declare function isSensitiveHeader(name: string): boolean;
4
+ export declare function isSensitiveQueryParam(name: string): boolean;
5
+ export declare function redactHeaders(headers: Record<string, string> | undefined, mode?: "strip" | "mask"): Record<string, string>;
6
+ export declare function filterRuntimeHeaders(headers: Record<string, string> | undefined): Record<string, string>;
7
+ export declare function mergeHeaders(base: Record<string, string> | undefined, override: Record<string, string> | undefined): Record<string, string>;
8
+ export declare function applyHoldoutPartition(invariants: Invariant[], hintPrefix: string): Invariant[];
9
+ export declare function ingestFromCommands(options?: IngestOptions, deps?: IngestDeps): Promise<IngestResult>;
10
+ export declare function ingestFromHar(options?: IngestOptions, _deps?: IngestDeps): Promise<IngestResult>;
@@ -0,0 +1,599 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { VibecodeError, errorMessage } from "../core/errors.js";
4
+ import { splitCommand } from "../core/exec.js";
5
+ import { ingest as ingestCli } from "./cli.js";
6
+ export const SENSITIVE_HEADER_NAMES = new Set([
7
+ "authorization",
8
+ "cookie",
9
+ "set-cookie",
10
+ "x-api-key",
11
+ "proxy-authorization",
12
+ "x-auth-token",
13
+ "x-csrf-token",
14
+ "x-xsrf-token"
15
+ ]);
16
+ const HAR_MAX_ENTRIES = 40;
17
+ const HAR_MAX_BODY_BYTES = 128 * 1024;
18
+ const MAX_JSON_SCHEMA_DEPTH = 16;
19
+ const MAX_JSON_SCHEMA_KEYS = 200;
20
+ const HAR_STATIC_ASSET_RE = /\.(css|js|mjs|map|png|jpg|jpeg|gif|webp|svg|ico|woff|woff2|ttf|eot)$/i;
21
+ const SENSITIVE_QUERY_PARAM_RE = /^(?:access[_-]?token|id[_-]?token|refresh[_-]?token|auth[_-]?token|token|api[_-]?key|apikey|x[-_]api[-_]key|x[-_]auth[-_]token|secret|client[_-]?secret|password|passwd|auth|jwt|session[_-]?id|sig|signature|private[_-]?key)$/i;
22
+ const HTML_LANDMARK_TAGS = ["header", "nav", "main", "footer", "h1", "h2", "form", "table", "ul"];
23
+ const INTERPRETER_NAMES = new Set([
24
+ "node",
25
+ "python",
26
+ "python3",
27
+ "py",
28
+ "tsx",
29
+ "ts-node",
30
+ "npx",
31
+ "deno",
32
+ "bun",
33
+ "ruby",
34
+ "perl",
35
+ "bash",
36
+ "sh",
37
+ "zsh",
38
+ "pwsh",
39
+ "powershell",
40
+ "php",
41
+ "java"
42
+ ]);
43
+ function isObject(v) {
44
+ return v !== null && typeof v === "object" && !Array.isArray(v);
45
+ }
46
+ export function isSensitiveHeader(name) {
47
+ return SENSITIVE_HEADER_NAMES.has(String(name).trim().toLowerCase());
48
+ }
49
+ export function isSensitiveQueryParam(name) {
50
+ return SENSITIVE_QUERY_PARAM_RE.test(String(name).trim());
51
+ }
52
+ function redactUrlSearch(parsedUrl) {
53
+ const safeParams = new URLSearchParams();
54
+ const safeQuery = {};
55
+ for (const [rawKey, rawVal] of parsedUrl.searchParams.entries()) {
56
+ const key = rawKey.trim();
57
+ if (!key || isSensitiveQueryParam(key))
58
+ continue;
59
+ safeParams.append(rawKey, rawVal);
60
+ safeQuery[rawKey] = rawVal;
61
+ }
62
+ const serialized = safeParams.toString();
63
+ return {
64
+ safeSearch: serialized ? `?${serialized}` : "",
65
+ safeQuery
66
+ };
67
+ }
68
+ export function redactHeaders(headers, mode = "strip") {
69
+ if (!isObject(headers))
70
+ return {};
71
+ const out = {};
72
+ for (const [rawKey, rawVal] of Object.entries(headers)) {
73
+ const key = rawKey.trim();
74
+ if (!key || rawVal === undefined || rawVal === null)
75
+ continue;
76
+ if (isSensitiveHeader(key)) {
77
+ if (mode === "mask")
78
+ out[key] = "[REDACTED]";
79
+ continue;
80
+ }
81
+ out[key] = String(rawVal);
82
+ }
83
+ return out;
84
+ }
85
+ export function filterRuntimeHeaders(headers) {
86
+ if (!isObject(headers))
87
+ return {};
88
+ const out = {};
89
+ for (const [rawKey, rawVal] of Object.entries(headers)) {
90
+ const key = rawKey.trim();
91
+ if (!key || rawVal === undefined || rawVal === null)
92
+ continue;
93
+ const val = String(rawVal);
94
+ if (val.trim() === "[REDACTED]")
95
+ continue;
96
+ out[key] = val;
97
+ }
98
+ return out;
99
+ }
100
+ export function mergeHeaders(base, override) {
101
+ const out = {};
102
+ const keyByLower = new Map();
103
+ for (const source of [filterRuntimeHeaders(base), filterRuntimeHeaders(override)]) {
104
+ for (const [key, val] of Object.entries(source)) {
105
+ const lower = key.toLowerCase();
106
+ const prevKey = keyByLower.get(lower);
107
+ if (prevKey && prevKey !== key) {
108
+ delete out[prevKey];
109
+ }
110
+ keyByLower.set(lower, key);
111
+ out[key] = val;
112
+ }
113
+ }
114
+ return out;
115
+ }
116
+ export function applyHoldoutPartition(invariants, hintPrefix) {
117
+ if (invariants.length < 2)
118
+ return invariants.slice();
119
+ const count = Math.max(1, Math.floor(invariants.length * 0.2));
120
+ const existing = invariants.filter((inv) => inv.holdout === true).length;
121
+ const needed = Math.max(0, count - existing);
122
+ if (needed === 0)
123
+ return invariants.slice();
124
+ const chosen = new Set();
125
+ for (let i = invariants.length - 1; i >= 1 && chosen.size < needed; i--) {
126
+ if (invariants[i]?.holdout === true)
127
+ continue;
128
+ chosen.add(i);
129
+ }
130
+ let seq = 0;
131
+ return invariants.map((inv, idx) => {
132
+ if (!chosen.has(idx))
133
+ return inv;
134
+ seq += 1;
135
+ const tags = Array.isArray(inv.tags)
136
+ ? (inv.tags.includes("holdout") ? [...inv.tags] : [...inv.tags, "holdout"])
137
+ : ["holdout"];
138
+ return {
139
+ ...inv,
140
+ holdout: true,
141
+ holdoutHint: `${hintPrefix} probe #${seq}`,
142
+ tags
143
+ };
144
+ });
145
+ }
146
+ function isInterpreterToken(token) {
147
+ if (!token)
148
+ return false;
149
+ const base = path.basename(token).replace(/\.(exe|cmd|bat)$/i, "").toLowerCase();
150
+ return INTERPRETER_NAMES.has(base);
151
+ }
152
+ function quoteToken(token) {
153
+ if (token.length === 0 || /[\s"]/.test(token)) {
154
+ return `"${token.replace(/"/g, '\\"')}"`;
155
+ }
156
+ return token;
157
+ }
158
+ function tokensStartWith(tokens, prefix) {
159
+ if (prefix.length === 0 || tokens.length < prefix.length)
160
+ return false;
161
+ return prefix.every((tok, idx) => tokens[idx] === tok);
162
+ }
163
+ function longestCommonNonFlagPrefix(lines) {
164
+ if (lines.length === 0)
165
+ return [];
166
+ const first = lines[0];
167
+ const prefix = [];
168
+ for (let i = 0; i < first.length; i++) {
169
+ const tok = first[i];
170
+ if (!tok || tok.startsWith("-"))
171
+ break;
172
+ if (lines.every((line) => line[i] === tok)) {
173
+ prefix.push(tok);
174
+ }
175
+ else {
176
+ break;
177
+ }
178
+ }
179
+ return prefix;
180
+ }
181
+ export async function ingestFromCommands(options = {}, deps = {}) {
182
+ if (typeof options.fromCommands !== "string" || !options.fromCommands.trim()) {
183
+ throw new VibecodeError("TARGET_MISSING", "Command trace ingestor requires --from-commands <file>");
184
+ }
185
+ const cwd = options.cwd || process.cwd();
186
+ const filePath = path.resolve(cwd, options.fromCommands.trim());
187
+ if (!fs.existsSync(filePath)) {
188
+ throw new VibecodeError("TARGET_MISSING", `Command trace file not found: ${options.fromCommands}`);
189
+ }
190
+ let rawText;
191
+ try {
192
+ if (!fs.statSync(filePath).isFile()) {
193
+ throw new Error("path is not a file");
194
+ }
195
+ rawText = fs.readFileSync(filePath, "utf8");
196
+ }
197
+ catch (err) {
198
+ throw new VibecodeError("CONTRACT_INVALID", `Failed to read command trace file ${options.fromCommands}: ${errorMessage(err)}`);
199
+ }
200
+ const parsedLines = [];
201
+ for (const rawLine of rawText.split(/\r?\n/)) {
202
+ const trimmed = rawLine.trim();
203
+ if (!trimmed || trimmed.startsWith("#"))
204
+ continue;
205
+ const tokens = splitCommand(trimmed);
206
+ if (tokens.length > 0)
207
+ parsedLines.push(tokens);
208
+ }
209
+ if (parsedLines.length === 0) {
210
+ throw new VibecodeError("CONTRACT_INVALID", `Command trace file contains no valid commands: ${options.fromCommands}`);
211
+ }
212
+ let source;
213
+ let sourceTokens;
214
+ if (typeof options.source === "string" && options.source.trim()) {
215
+ source = options.source.trim();
216
+ sourceTokens = splitCommand(source);
217
+ }
218
+ else {
219
+ const lcp = longestCommonNonFlagPrefix(parsedLines);
220
+ const first = parsedLines[0];
221
+ if (parsedLines.length === 1) {
222
+ sourceTokens = isInterpreterToken(first[0]) && first.length >= 2 && !first[1].startsWith("-")
223
+ ? [first[0], first[1]]
224
+ : [first[0]];
225
+ }
226
+ else if (lcp.length >= 2 && isInterpreterToken(lcp[0]) && !lcp[1].startsWith("-")) {
227
+ sourceTokens = [lcp[0], lcp[1]];
228
+ }
229
+ else if (lcp.length >= 1) {
230
+ sourceTokens = [lcp[0]];
231
+ }
232
+ else {
233
+ sourceTokens = isInterpreterToken(first[0]) && first.length >= 2 && !first[1].startsWith("-")
234
+ ? [first[0], first[1]]
235
+ : [first[0]];
236
+ }
237
+ source = sourceTokens.map(quoteToken).join(" ");
238
+ }
239
+ const probeArgsList = parsedLines.map((tokens) => tokensStartWith(tokens, sourceTokens) ? tokens.slice(sourceTokens.length) : tokens);
240
+ const probes = probeArgsList.map((args, idx) => ({
241
+ name: `trace-${idx + 1}`,
242
+ args,
243
+ ...(options.env ? { env: { ...options.env } } : {})
244
+ }));
245
+ const cliResult = await ingestCli({
246
+ ...options,
247
+ domain: "cli",
248
+ source,
249
+ probes,
250
+ ...(options.env ? { env: options.env } : {}),
251
+ ...(options.fsDiff !== undefined ? { fsDiff: options.fsDiff } : {})
252
+ }, deps);
253
+ const invariants = applyHoldoutPartition(cliResult.invariants, "Holdout CLI trace");
254
+ return {
255
+ domain: "cli",
256
+ sources: [
257
+ {
258
+ id: "src-1",
259
+ kind: "cli",
260
+ ref: source,
261
+ meta: {
262
+ command: source,
263
+ fromCommands: options.fromCommands,
264
+ traceCommandCount: probeArgsList.length
265
+ }
266
+ }
267
+ ],
268
+ artifacts: cliResult.artifacts,
269
+ invariants,
270
+ warnings: cliResult.warnings
271
+ };
272
+ }
273
+ function stripHtmlTags(html) {
274
+ return String(html)
275
+ .replace(/<script[\s\S]*?<\/script>/gi, " ")
276
+ .replace(/<style[\s\S]*?<\/style>/gi, " ")
277
+ .replace(/<[^>]+>/g, " ")
278
+ .replace(/&nbsp;/g, " ")
279
+ .replace(/&amp;/g, "&")
280
+ .replace(/&lt;/g, "<")
281
+ .replace(/&gt;/g, ">")
282
+ .replace(/\s+/g, " ")
283
+ .trim();
284
+ }
285
+ function extractHtmlTitle(html) {
286
+ const m = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
287
+ return m ? stripHtmlTags(m[1]) : "";
288
+ }
289
+ function extractHtmlLandmarks(html) {
290
+ const landmarks = [];
291
+ for (const tag of HTML_LANDMARK_TAGS) {
292
+ const re = new RegExp(`<${tag}\\b[^>]*>([\\s\\S]*?)<\\/${tag}>`, "i");
293
+ const m = re.exec(html);
294
+ if (!m)
295
+ continue;
296
+ const entry = { tag, required: true };
297
+ const text = stripHtmlTags(m[1]).slice(0, 80);
298
+ if (text && (tag === "h1" || tag === "h2" || tag === "main"))
299
+ entry.textContains = text;
300
+ landmarks.push(entry);
301
+ }
302
+ return landmarks;
303
+ }
304
+ function synthesizeJsonSchema(value, depth = 0) {
305
+ if (depth >= MAX_JSON_SCHEMA_DEPTH)
306
+ return {};
307
+ if (value === null)
308
+ return { type: "null" };
309
+ if (Array.isArray(value)) {
310
+ return { type: "array", items: value.length ? synthesizeJsonSchema(value[0], depth + 1) : {} };
311
+ }
312
+ if (isObject(value)) {
313
+ const entries = Object.entries(value).slice(0, MAX_JSON_SCHEMA_KEYS);
314
+ const properties = {};
315
+ const required = [];
316
+ for (const [k, v] of entries) {
317
+ properties[k] = synthesizeJsonSchema(v, depth + 1);
318
+ required.push(k);
319
+ }
320
+ return { type: "object", required, properties };
321
+ }
322
+ if (Number.isInteger(value))
323
+ return { type: "integer" };
324
+ return { type: typeof value };
325
+ }
326
+ function slugifyHar(text) {
327
+ return String(text).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64) || "root";
328
+ }
329
+ function uniqueHarId(baseId, usedIds) {
330
+ if (!usedIds.has(baseId)) {
331
+ usedIds.add(baseId);
332
+ return baseId;
333
+ }
334
+ let n = 2;
335
+ while (usedIds.has(`${baseId}-${n}`))
336
+ n += 1;
337
+ const unique = `${baseId}-${n}`;
338
+ usedIds.add(unique);
339
+ return unique;
340
+ }
341
+ function collectHarHeaders(rawHeaders) {
342
+ const out = {};
343
+ if (Array.isArray(rawHeaders)) {
344
+ for (const item of rawHeaders) {
345
+ if (!isObject(item) || typeof item.name !== "string")
346
+ continue;
347
+ const name = item.name.trim();
348
+ if (!name || name.startsWith(":"))
349
+ continue;
350
+ if (item.value === undefined || item.value === null)
351
+ continue;
352
+ out[name] = String(item.value);
353
+ }
354
+ return out;
355
+ }
356
+ if (isObject(rawHeaders)) {
357
+ for (const [rawKey, rawVal] of Object.entries(rawHeaders)) {
358
+ const name = rawKey.trim();
359
+ if (!name || name.startsWith(":"))
360
+ continue;
361
+ if (rawVal === undefined || rawVal === null)
362
+ continue;
363
+ out[name] = String(rawVal);
364
+ }
365
+ }
366
+ return out;
367
+ }
368
+ function findHeaderIgnoreCase(headers, target) {
369
+ const lower = target.toLowerCase();
370
+ for (const [k, v] of Object.entries(headers)) {
371
+ if (k.toLowerCase() === lower)
372
+ return v;
373
+ }
374
+ return "";
375
+ }
376
+ function decodeHarResponseText(content) {
377
+ if (!content || typeof content.text !== "string")
378
+ return { text: "", truncated: false };
379
+ const isBase64 = String(content.encoding || "").toLowerCase() === "base64";
380
+ const maxRawLen = isBase64 ? Math.ceil((HAR_MAX_BODY_BYTES * 4) / 3) + 4 : HAR_MAX_BODY_BYTES;
381
+ if (content.text.length > maxRawLen) {
382
+ if (isBase64) {
383
+ try {
384
+ const sliced = content.text.slice(0, maxRawLen - (maxRawLen % 4));
385
+ return { text: Buffer.from(sliced, "base64").toString("utf8").slice(0, HAR_MAX_BODY_BYTES), truncated: true };
386
+ }
387
+ catch {
388
+ return { text: content.text.slice(0, HAR_MAX_BODY_BYTES), truncated: true };
389
+ }
390
+ }
391
+ return { text: content.text.slice(0, HAR_MAX_BODY_BYTES), truncated: true };
392
+ }
393
+ if (isBase64) {
394
+ try {
395
+ const decoded = Buffer.from(content.text, "base64").toString("utf8");
396
+ if (decoded.length > HAR_MAX_BODY_BYTES) {
397
+ return { text: decoded.slice(0, HAR_MAX_BODY_BYTES), truncated: true };
398
+ }
399
+ return { text: decoded, truncated: false };
400
+ }
401
+ catch {
402
+ return { text: content.text, truncated: false };
403
+ }
404
+ }
405
+ return { text: content.text, truncated: false };
406
+ }
407
+ export async function ingestFromHar(options = {}, _deps = {}) {
408
+ if (typeof options.fromHar !== "string" || !options.fromHar.trim()) {
409
+ throw new VibecodeError("TARGET_MISSING", "HAR ingestor requires --from-har <file>");
410
+ }
411
+ const cwd = options.cwd || process.cwd();
412
+ const filePath = path.resolve(cwd, options.fromHar.trim());
413
+ if (!fs.existsSync(filePath)) {
414
+ throw new VibecodeError("TARGET_MISSING", `HAR file not found: ${options.fromHar}`);
415
+ }
416
+ let doc;
417
+ try {
418
+ if (!fs.statSync(filePath).isFile()) {
419
+ throw new Error("path is not a file");
420
+ }
421
+ doc = JSON.parse(fs.readFileSync(filePath, "utf8"));
422
+ }
423
+ catch (err) {
424
+ throw new VibecodeError("CONTRACT_INVALID", `Malformed HAR JSON in ${options.fromHar}: ${errorMessage(err)}`);
425
+ }
426
+ if (!isObject(doc) || !isObject(doc.log) || !Array.isArray(doc.log.entries)) {
427
+ throw new VibecodeError("CONTRACT_INVALID", `HAR file ${options.fromHar} must contain log.entries array`);
428
+ }
429
+ const warnings = [];
430
+ const invariants = [];
431
+ const seenRequests = new Set();
432
+ const usedIds = new Set();
433
+ let firstOrigin = "";
434
+ for (const rawEntry of doc.log.entries) {
435
+ if (invariants.length >= HAR_MAX_ENTRIES)
436
+ break;
437
+ if (!isObject(rawEntry) || !isObject(rawEntry.request))
438
+ continue;
439
+ const req = rawEntry.request;
440
+ if (typeof req.url !== "string" || !req.url.trim())
441
+ continue;
442
+ let parsedUrl;
443
+ try {
444
+ parsedUrl = new URL(req.url.trim());
445
+ }
446
+ catch {
447
+ continue;
448
+ }
449
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:")
450
+ continue;
451
+ const pathname = parsedUrl.pathname || "/";
452
+ if (pathname === "/favicon.ico" || HAR_STATIC_ASSET_RE.test(pathname))
453
+ continue;
454
+ if (!firstOrigin)
455
+ firstOrigin = parsedUrl.origin;
456
+ const method = String(req.method || "GET").trim().toUpperCase() || "GET";
457
+ const { safeSearch, safeQuery } = redactUrlSearch(parsedUrl);
458
+ const dedupeKey = `${method} ${pathname}${safeSearch}`;
459
+ if (seenRequests.has(dedupeKey))
460
+ continue;
461
+ seenRequests.add(dedupeKey);
462
+ const rawReqHeaders = collectHarHeaders(req.headers);
463
+ const safeHeaders = redactHeaders(rawReqHeaders, "strip");
464
+ const query = { ...safeQuery };
465
+ if (Object.keys(query).length === 0 && Array.isArray(req.queryString)) {
466
+ for (const item of req.queryString) {
467
+ if (isObject(item) && typeof item.name === "string" && item.name) {
468
+ if (isSensitiveQueryParam(item.name))
469
+ continue;
470
+ query[item.name] = item.value === undefined || item.value === null ? "" : String(item.value);
471
+ }
472
+ }
473
+ }
474
+ let reqBody = undefined;
475
+ if (isObject(req.postData) && typeof req.postData.text === "string" && req.postData.text.length > 0) {
476
+ if (req.postData.text.length <= HAR_MAX_BODY_BYTES) {
477
+ try {
478
+ reqBody = JSON.parse(req.postData.text);
479
+ }
480
+ catch {
481
+ reqBody = req.postData.text;
482
+ }
483
+ }
484
+ else {
485
+ warnings.push({
486
+ code: "ADAPTER_DEGRADED",
487
+ message: `Omitted oversized HAR request body (${req.postData.text.length} bytes) for ${method} ${pathname}.`
488
+ });
489
+ }
490
+ }
491
+ const res = isObject(rawEntry.response) ? rawEntry.response : {};
492
+ const rawStatus = res.status;
493
+ const status = typeof rawStatus === "number" && Number.isFinite(rawStatus) && rawStatus > 0 ? rawStatus : 200;
494
+ const content = isObject(res.content) ? res.content : undefined;
495
+ const rawRespHeaders = collectHarHeaders(res.headers);
496
+ const mimeType = String(content?.mimeType || findHeaderIgnoreCase(rawRespHeaders, "content-type") || "");
497
+ const { text: respText, truncated: respTruncated } = decodeHarResponseText(content);
498
+ if (mimeType.toLowerCase().includes("text/html")) {
499
+ const title = extractHtmlTitle(respText);
500
+ const landmarks = extractHtmlLandmarks(respText);
501
+ const routePath = `${pathname}${safeSearch}`;
502
+ invariants.push({
503
+ id: uniqueHarId(`inv-har-web-${slugifyHar(routePath)}`, usedIds),
504
+ domain: "web",
505
+ type: "web_route",
506
+ severity: "hard",
507
+ description: `HAR route ${routePath} preserves status and HTML landmarks`,
508
+ tags: ["web", "route", "hard", "har"],
509
+ sourceId: "src-1",
510
+ input: {
511
+ path: routePath,
512
+ ...(Object.keys(safeHeaders).length > 0 ? { headers: safeHeaders } : {})
513
+ },
514
+ expected: {
515
+ status,
516
+ ...(title ? { titleContains: title } : {}),
517
+ ...(landmarks.length > 0 ? { landmarks } : {}),
518
+ noPageErrors: true,
519
+ noServerErrors: true
520
+ },
521
+ tolerance: {}
522
+ });
523
+ }
524
+ else {
525
+ let jsonSchema;
526
+ let jsonSubset = undefined;
527
+ const trimmedResp = respText.trim();
528
+ if (!respTruncated && trimmedResp && (mimeType.toLowerCase().includes("json") || /^[{[]/.test(trimmedResp))) {
529
+ try {
530
+ const parsedJson = JSON.parse(trimmedResp);
531
+ if (isObject(parsedJson) || Array.isArray(parsedJson)) {
532
+ jsonSchema = synthesizeJsonSchema(parsedJson);
533
+ }
534
+ if (isObject(parsedJson)) {
535
+ jsonSubset = parsedJson;
536
+ }
537
+ }
538
+ catch {
539
+ // ignore non-JSON body despite MIME hint
540
+ }
541
+ }
542
+ else if (respTruncated) {
543
+ warnings.push({
544
+ code: "ADAPTER_DEGRADED",
545
+ message: `Skipped oversized HAR response body schema extraction for ${method} ${pathname}.`
546
+ });
547
+ }
548
+ invariants.push({
549
+ id: uniqueHarId(`inv-har-${method.toLowerCase()}-${slugifyHar(pathname)}`, usedIds),
550
+ domain: "api",
551
+ type: "http",
552
+ severity: "hard",
553
+ description: `HAR ${method} ${pathname} preserves HTTP response contract`,
554
+ tags: ["api", "http", "hard", "har"],
555
+ sourceId: "src-1",
556
+ input: {
557
+ method,
558
+ path: pathname,
559
+ ...(Object.keys(query).length > 0 ? { query } : {}),
560
+ ...(Object.keys(safeHeaders).length > 0 ? { headers: safeHeaders } : {}),
561
+ ...(reqBody !== undefined ? { body: reqBody } : {})
562
+ },
563
+ expected: {
564
+ status,
565
+ ...(jsonSchema ? { jsonSchema } : {}),
566
+ ...(jsonSubset !== undefined ? { jsonSubset } : {})
567
+ },
568
+ tolerance: {}
569
+ });
570
+ }
571
+ }
572
+ const partitioned = applyHoldoutPartition(invariants, "Holdout trace request");
573
+ if (partitioned.length === 0) {
574
+ warnings.push({ code: "ADAPTER_DEGRADED", message: "HAR trace produced no non-static HTTP(S) invariants." });
575
+ }
576
+ const baseUrl = (typeof options.baseUrl === "string" && options.baseUrl.trim()) ||
577
+ firstOrigin ||
578
+ (typeof options.source === "string" && options.source.trim()) ||
579
+ "http://localhost";
580
+ const domain = partitioned.length > 0 && partitioned.every((inv) => inv.type === "web_route") ? "web" : "api";
581
+ return {
582
+ domain,
583
+ sources: [
584
+ {
585
+ id: "src-1",
586
+ kind: domain,
587
+ ref: baseUrl,
588
+ meta: {
589
+ baseUrl,
590
+ fromHar: options.fromHar,
591
+ entryCount: partitioned.length
592
+ }
593
+ }
594
+ ],
595
+ artifacts: { root: ".vibecode/artifacts", files: {} },
596
+ invariants: partitioned,
597
+ warnings
598
+ };
599
+ }
@@ -10,6 +10,8 @@ export declare function cueAt(cues: readonly SubtitleCue[], timestampMs: number)
10
10
  /** Parse `showinfo` scene timestamps from ffmpeg stderr/stdout. */
11
11
  export declare function parseSceneTimestamps(logText: unknown): number[];
12
12
  export declare function parseFfprobeDurationMs(stdout: unknown): number | null;
13
+ /** Validate and normalize an ffmpeg `w:h:x:y` crop specification. */
14
+ export declare function parseCropFilter(crop: unknown): string | undefined;
13
15
  /**
14
16
  * Resolve the ffmpeg adapter.
15
17
  * - `deps.ffmpegAdapter` explicitly set (object or `null`) wins — `null` models "absent" in tests.
@@ -18,11 +20,12 @@ export declare function parseFfprobeDurationMs(stdout: unknown): number | null;
18
20
  export declare function resolveFfmpegAdapter(deps?: IngestDeps | VerifyDeps): FfmpegAdapter | null;
19
21
  export declare function ffmpegMissingError(): VibecodeError;
20
22
  /** Extract ordered keyframe files + duration from a video file via the adapter. */
21
- export declare function extractVideoFrames(absSource: string, { cwd, sceneThreshold, maxFrames, cacheKey }: {
23
+ export declare function extractVideoFrames(absSource: string, { cwd, sceneThreshold, maxFrames, cacheKey, crop }: {
22
24
  cwd?: string;
23
25
  sceneThreshold?: number;
24
26
  maxFrames?: number;
25
27
  cacheKey?: string;
28
+ crop?: string;
26
29
  }, adapter: FfmpegAdapter | null): {
27
30
  frames: FfmpegFrame[];
28
31
  durationMs: number;