vibecode-anything 0.0.0-stage → 0.3.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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -2
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +452 -0
  5. package/dist/core/adapters.d.ts +8 -0
  6. package/dist/core/adapters.js +92 -0
  7. package/dist/core/diff.d.ts +10 -0
  8. package/dist/core/diff.js +207 -0
  9. package/dist/core/doctor.d.ts +50 -0
  10. package/dist/core/doctor.js +312 -0
  11. package/dist/core/errors.d.ts +32 -0
  12. package/dist/core/errors.js +81 -0
  13. package/dist/core/exec.d.ts +14 -0
  14. package/dist/core/exec.js +109 -0
  15. package/dist/core/parity.d.ts +9 -0
  16. package/dist/core/parity.js +138 -0
  17. package/dist/core/png.d.ts +7 -0
  18. package/dist/core/png.js +303 -0
  19. package/dist/core/schema.d.ts +17 -0
  20. package/dist/core/schema.js +614 -0
  21. package/dist/core/slices.d.ts +24 -0
  22. package/dist/core/slices.js +294 -0
  23. package/dist/core/store.d.ts +17 -0
  24. package/dist/core/store.js +97 -0
  25. package/dist/core/types.d.ts +751 -0
  26. package/dist/core/types.js +4 -0
  27. package/dist/core/visual.d.ts +34 -0
  28. package/dist/core/visual.js +459 -0
  29. package/dist/core/watch.d.ts +53 -0
  30. package/dist/core/watch.js +285 -0
  31. package/dist/ingestors/api-repo.d.ts +5 -0
  32. package/dist/ingestors/api-repo.js +722 -0
  33. package/dist/ingestors/bridges.d.ts +3 -0
  34. package/dist/ingestors/bridges.js +562 -0
  35. package/dist/ingestors/cli.d.ts +9 -0
  36. package/dist/ingestors/cli.js +266 -0
  37. package/dist/ingestors/image.d.ts +2 -0
  38. package/dist/ingestors/image.js +147 -0
  39. package/dist/ingestors/index.d.ts +5 -0
  40. package/dist/ingestors/index.js +97 -0
  41. package/dist/ingestors/video.d.ts +47 -0
  42. package/dist/ingestors/video.js +605 -0
  43. package/dist/ingestors/web.d.ts +25 -0
  44. package/dist/ingestors/web.js +397 -0
  45. package/dist/mcp/server.d.ts +2 -0
  46. package/dist/mcp/server.js +504 -0
  47. package/dist/oracles/api-repo.d.ts +2 -0
  48. package/dist/oracles/api-repo.js +214 -0
  49. package/dist/oracles/cli.d.ts +2 -0
  50. package/dist/oracles/cli.js +157 -0
  51. package/dist/oracles/image.d.ts +2 -0
  52. package/dist/oracles/image.js +279 -0
  53. package/dist/oracles/index.d.ts +4 -0
  54. package/dist/oracles/index.js +91 -0
  55. package/dist/oracles/video.d.ts +21 -0
  56. package/dist/oracles/video.js +411 -0
  57. package/dist/oracles/web.d.ts +2 -0
  58. package/dist/oracles/web.js +480 -0
  59. package/dist/setup/index.d.ts +7 -0
  60. package/dist/setup/index.js +186 -0
  61. package/package.json +47 -6
  62. package/skills/vibecode-anything/SKILL.md +52 -0
@@ -0,0 +1,266 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { splitCommand, runCommand } from "../core/exec.js";
5
+ import { VibecodeError, errorMessage } from "../core/errors.js";
6
+ const DEFAULT_TIMEOUT = 5000;
7
+ const MAX_SUBCOMMANDS = 12;
8
+ function parseHelpSubcommands(stdout) {
9
+ const lines = String(stdout || "").split(/\r?\n/);
10
+ const cmds = new Set();
11
+ let inCommands = false;
12
+ for (const line of lines) {
13
+ if (/^\s*(commands?|available commands?)\s*:?\s*$/i.test(line)) {
14
+ inCommands = true;
15
+ continue;
16
+ }
17
+ if (inCommands && /^\S/.test(line))
18
+ break;
19
+ const m = line.match(/^\s{1,12}([a-z][a-z0-9_-]*)(?:\s{2,}|\t|\s+[-–—]|\s+<).*$/i);
20
+ if (m && !m[1].startsWith("-") && !["usage", "options", "commands", "flags", "examples"].includes(m[1].toLowerCase())) {
21
+ cmds.add(m[1]);
22
+ }
23
+ }
24
+ // Fallback: generic " cmd description" lines
25
+ if (cmds.size === 0) {
26
+ for (const line of lines) {
27
+ const m = line.match(/^\s{2,}([a-z][a-z0-9_-]*)\s{2,}[^\s]/i);
28
+ if (m)
29
+ cmds.add(m[1]);
30
+ }
31
+ }
32
+ return [...cmds].slice(0, MAX_SUBCOMMANDS);
33
+ }
34
+ function synthesizeSchema(value) {
35
+ if (value === null)
36
+ return { type: "null" };
37
+ if (Array.isArray(value))
38
+ return { type: "array", items: value.length ? synthesizeSchema(value[0]) : {} };
39
+ if (typeof value === "object") {
40
+ const obj = value;
41
+ const properties = {};
42
+ for (const [k, v] of Object.entries(obj))
43
+ properties[k] = synthesizeSchema(v);
44
+ return { type: "object", required: Object.keys(obj), properties };
45
+ }
46
+ return { type: typeof value };
47
+ }
48
+ function slug(args) {
49
+ if (!args || args.length === 0)
50
+ return "noargs";
51
+ return args
52
+ .join("-")
53
+ .replace(/[^A-Za-z0-9]+/g, "-")
54
+ .replace(/^-+|-+$/g, "")
55
+ .slice(0, 80) || "probe";
56
+ }
57
+ function probeKey(args, stdin, env) {
58
+ return JSON.stringify({ args, stdin: stdin ?? null, env: env ?? null });
59
+ }
60
+ function resolveCommandTokens(tokens, workspaceCwd) {
61
+ const baseCwd = workspaceCwd || process.cwd();
62
+ return tokens.map((tok, idx) => {
63
+ if (!tok)
64
+ return tok;
65
+ if (idx === 0) {
66
+ if ((tok.startsWith(".") || tok.includes("/") || tok.includes("\\")) && fs.existsSync(path.resolve(baseCwd, tok))) {
67
+ return path.resolve(baseCwd, tok);
68
+ }
69
+ return tok;
70
+ }
71
+ if (!tok.startsWith("-") && fs.existsSync(path.resolve(baseCwd, tok))) {
72
+ return path.resolve(baseCwd, tok);
73
+ }
74
+ return tok;
75
+ });
76
+ }
77
+ /** Build expected assertions from observed probe output. */
78
+ function buildExpected({ args, run, subcommands, explicit = false }) {
79
+ const expected = {
80
+ ...(run.exitCode !== null ? { exitCode: run.exitCode } : {})
81
+ };
82
+ const stdout = run.stdout || "";
83
+ const stderr = run.stderr || "";
84
+ const trimmed = stdout.trim();
85
+ let parsed = null;
86
+ if (trimmed && (/^[{[]/.test(trimmed))) {
87
+ try {
88
+ parsed = JSON.parse(trimmed);
89
+ }
90
+ catch { /* ignore */ }
91
+ }
92
+ if (parsed !== null) {
93
+ expected.jsonSchema = synthesizeSchema(parsed);
94
+ expected.goldenStdout = stdout;
95
+ expected.normalize = ["crlf", "ansi"];
96
+ }
97
+ else if (explicit) {
98
+ if (stdout.length > 0) {
99
+ expected.goldenStdout = stdout;
100
+ expected.normalize = ["crlf", "ansi"];
101
+ }
102
+ if (run.exitCode !== 0 && stderr.trim().length > 0) {
103
+ const firstLine = stderr.trim().split(/\r?\n/).find((l) => l.trim())?.trim().slice(0, 80);
104
+ if (firstLine)
105
+ expected.stderrContains = [firstLine];
106
+ }
107
+ }
108
+ else {
109
+ // Pick stable landmark text tokens
110
+ const common = ["Usage", "Commands", "Options", "Available", "help"];
111
+ const tokens = common.filter((t) => stdout.includes(t));
112
+ if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
113
+ const extra = subcommands.filter((s) => stdout.includes(s)).slice(0, 4);
114
+ const all = [...new Set([...tokens, ...extra])];
115
+ if (all.length)
116
+ expected.stdoutContains = all;
117
+ }
118
+ else if (subcommands.length > 0 && args.length >= 1) {
119
+ const all = [...new Set(tokens)];
120
+ if (all.length)
121
+ expected.stdoutContains = all;
122
+ }
123
+ else if (tokens.length > 0) {
124
+ expected.stdoutContains = tokens;
125
+ }
126
+ const version = stdout.match(/\b\d+\.\d+(?:\.\d+)?\b/);
127
+ if (version)
128
+ expected.stdoutRegex = [String(version[0]).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")];
129
+ }
130
+ return expected;
131
+ }
132
+ /**
133
+ * Safe sandboxed CLI auto-prober.
134
+ * Runs every probe inside a temporary directory — never the user's workspace.
135
+ */
136
+ export async function ingest(options = {}, deps = {}) {
137
+ const source = options.source;
138
+ if (!source || typeof source !== "string") {
139
+ throw new VibecodeError("TARGET_MISSING", "CLI ingestor requires --source <command>");
140
+ }
141
+ const tokens = splitCommand(source);
142
+ if (tokens.length === 0)
143
+ throw new VibecodeError("TARGET_MISSING", "CLI source command is empty");
144
+ const resolvedTokens = resolveCommandTokens(tokens, options.cwd);
145
+ const [target, ...baseArgs] = resolvedTokens;
146
+ const sandbox = deps.tmpDir || fs.mkdtempSync(path.join(os.tmpdir(), "vibecode-probe-"));
147
+ const ownsSandbox = !deps.tmpDir;
148
+ const warnings = [];
149
+ const seen = new Set();
150
+ const probes = [];
151
+ const addProbe = (args, meta = {}) => {
152
+ const key = probeKey(args, meta.stdin, meta.env);
153
+ if (seen.has(key))
154
+ return;
155
+ seen.add(key);
156
+ probes.push({ args, ...meta });
157
+ };
158
+ addProbe(["--help"], { name: "help" });
159
+ addProbe(["-h"], { name: "help-short" });
160
+ addProbe(["--version"], { name: "version" });
161
+ addProbe(["--__vibecode_unknown_flag__"], { name: "unknown-flag" });
162
+ addProbe([], { name: "no-args" });
163
+ // Explicit probes
164
+ const explicit = options.probes || [];
165
+ const probeList = Array.isArray(explicit) ? explicit : [explicit];
166
+ for (const p of probeList) {
167
+ if (typeof p === "string")
168
+ addProbe(splitCommand(p), { name: "custom", explicit: true });
169
+ else if (p && Array.isArray(p.args)) {
170
+ addProbe(p.args, { name: p.name || "custom", stdin: p.stdin, env: p.env, expected: p.expected, explicit: true });
171
+ }
172
+ }
173
+ let subcommands = [];
174
+ let helpStderr = "";
175
+ try {
176
+ const helpRun = runCommand(target, [...baseArgs, "--help"], {
177
+ stdin: "",
178
+ cwd: sandbox,
179
+ timeoutMs: deps.timeoutMs || DEFAULT_TIMEOUT,
180
+ env: { NO_COLOR: "1" }
181
+ });
182
+ helpStderr = helpRun.stderr || "";
183
+ subcommands = parseHelpSubcommands(helpRun.stdout);
184
+ if (subcommands.length === 0)
185
+ subcommands = parseHelpSubcommands(helpRun.stderr);
186
+ for (const cmd of subcommands)
187
+ addProbe([cmd, "--help"], { name: `cmd-${cmd}`, subcommand: true });
188
+ }
189
+ catch (err) {
190
+ warnings.push({ code: "EXEC_ERROR", message: `Help probe failed: ${errorMessage(err)}` });
191
+ }
192
+ const invariants = [];
193
+ const usedIds = new Set();
194
+ try {
195
+ for (const probe of probes) {
196
+ const run = runCommand(target, [...baseArgs, ...probe.args], {
197
+ stdin: probe.stdin !== undefined ? probe.stdin : "",
198
+ cwd: sandbox,
199
+ timeoutMs: deps.timeoutMs || DEFAULT_TIMEOUT,
200
+ env: { NO_COLOR: "1", ...(probe.env || {}) }
201
+ });
202
+ if (run.timedOut) {
203
+ warnings.push({ code: "EXEC_TIMEOUT", message: `Probe ${probe.args.join(" ")} timed out; skipped` });
204
+ continue;
205
+ }
206
+ if (run.error && run.exitCode === null) {
207
+ warnings.push({ code: "EXEC_ERROR", message: `Probe ${probe.args.join(" ")} failed: ${run.error.message}` });
208
+ continue;
209
+ }
210
+ const expected = probe.expected
211
+ ? { ...probe.expected }
212
+ : buildExpected({ args: probe.args, run, subcommands, explicit: Boolean(probe.explicit) });
213
+ let id = `inv-cli-${slug(probe.args)}`;
214
+ if (usedIds.has(id)) {
215
+ const named = probe.name ? `inv-cli-${slug([slug(probe.args), probe.name])}` : "";
216
+ if (named && !usedIds.has(named))
217
+ id = named;
218
+ else {
219
+ let n = 2;
220
+ while (usedIds.has(`${id}-${n}`))
221
+ n++;
222
+ id = `${id}-${n}`;
223
+ }
224
+ }
225
+ usedIds.add(id);
226
+ invariants.push({
227
+ id,
228
+ domain: "cli",
229
+ type: "command",
230
+ severity: "hard",
231
+ description: `CLI probe: ${probe.args.join(" ") || "(no args)"}${probe.name && probe.explicit ? ` (${probe.name})` : ""}`,
232
+ tags: ["cli", "auto-probe", ...(probe.explicit ? ["explicit"] : [])],
233
+ sourceId: "src-1",
234
+ input: {
235
+ args: probe.args,
236
+ stdin: probe.stdin !== undefined ? probe.stdin : null,
237
+ env: { NO_COLOR: "1", ...(probe.env || {}) },
238
+ cwd: ".",
239
+ timeoutMs: deps.timeoutMs || DEFAULT_TIMEOUT
240
+ },
241
+ expected,
242
+ tolerance: {}
243
+ });
244
+ }
245
+ }
246
+ finally {
247
+ if (ownsSandbox)
248
+ fs.rmSync(sandbox, { recursive: true, force: true });
249
+ }
250
+ if (invariants.length > 0 && invariants.every((i) => i.expected.exitCode !== 0) && /Cannot find module|MODULE_NOT_FOUND|No such file/i.test(helpStderr)) {
251
+ warnings.push({ code: "EXEC_ERROR", message: `Every probe exited non-zero (${helpStderr.trim().split(/\r?\n/)[0]}). Check --source path.` });
252
+ }
253
+ if (invariants.length === 0) {
254
+ warnings.push({ code: "ADAPTER_DEGRADED", message: "No CLI probes succeeded; contract has no invariants." });
255
+ }
256
+ return {
257
+ domain: "cli",
258
+ sources: [
259
+ { id: "src-1", kind: "cli", ref: source, meta: { command: source } }
260
+ ],
261
+ artifacts: { root: ".vibecode/artifacts", files: {} },
262
+ invariants,
263
+ warnings
264
+ };
265
+ }
266
+ export { parseHelpSubcommands, synthesizeSchema };
@@ -0,0 +1,2 @@
1
+ import type { IngestDeps, IngestOptions, IngestResult } from "../core/types.js";
2
+ export declare function ingest(options?: IngestOptions, deps?: IngestDeps): Promise<IngestResult>;
@@ -0,0 +1,147 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { VibecodeError, toDiagnostic } from "../core/errors.js";
4
+ import { readImageDimensions } from "../core/png.js";
5
+ import { decodeImage, extractPalette, extractLayoutRegions, estimateTypographyBands, computeDHash } from "../core/visual.js";
6
+ import { saveArtifact, ensureDir, resolveWorkspace } from "../core/store.js";
7
+ function isNonBlank(img) {
8
+ const data = img.data;
9
+ if (!data || data.length < 4)
10
+ return false;
11
+ const r0 = data[0], g0 = data[1], b0 = data[2], a0 = data[3];
12
+ for (let i = 4; i < data.length; i += 4) {
13
+ if (data[i] !== r0 || data[i + 1] !== g0 || data[i + 2] !== b0 || data[i + 3] !== a0)
14
+ return true;
15
+ }
16
+ return false;
17
+ }
18
+ function artifactRelForSource(source) {
19
+ const base = path.basename(source).replace(/[^A-Za-z0-9._-]+/g, "-") || "reference.png";
20
+ const ext = path.extname(base);
21
+ return ext ? base : `${base}.png`;
22
+ }
23
+ export async function ingest(options = {}, deps = {}) {
24
+ const source = options.source;
25
+ if (!source || typeof source !== "string") {
26
+ throw new VibecodeError("TARGET_MISSING", "Image ingestor requires --source <image-path>");
27
+ }
28
+ const absSource = path.resolve(options.cwd || process.cwd(), source);
29
+ if (!fs.existsSync(absSource)) {
30
+ throw new VibecodeError("TARGET_MISSING", `Image source not found: ${source}`);
31
+ }
32
+ const cwd = options.cwd || process.cwd();
33
+ const { artifactsDir } = resolveWorkspace(cwd);
34
+ ensureDir(artifactsDir);
35
+ const warnings = [];
36
+ const buf = fs.readFileSync(absSource);
37
+ const headerDims = readImageDimensions(buf);
38
+ let img = null;
39
+ let decodeDiagnostic = null;
40
+ try {
41
+ img = await decodeImage(absSource, deps);
42
+ }
43
+ catch (err) {
44
+ const diag = toDiagnostic(err);
45
+ if (diag.code === "ADAPTER_MISSING") {
46
+ decodeDiagnostic = diag;
47
+ warnings.push(diag);
48
+ }
49
+ else {
50
+ throw err;
51
+ }
52
+ }
53
+ // Copy reference artifact. If we decoded (or it's a PNG), save original bytes as-is.
54
+ const refKey = "ref-image";
55
+ const relName = artifactRelForSource(absSource);
56
+ const savedRel = saveArtifact(buf, relName, cwd);
57
+ const dims = img
58
+ ? { width: img.width, height: img.height }
59
+ : headerDims
60
+ ? { width: headerDims.width, height: headerDims.height }
61
+ : null;
62
+ if (!dims) {
63
+ throw new VibecodeError("UNSUPPORTED_FORMAT", "Unable to read image dimensions");
64
+ }
65
+ const nonBlank = img ? isNonBlank(img) : null;
66
+ const palette = img ? extractPalette(img, 6) : [];
67
+ const regions = img ? extractLayoutRegions(img, { maxDepth: 3 }) : [];
68
+ const typography = img ? estimateTypographyBands(img) : [];
69
+ const dHash = img ? computeDHash(img) : null;
70
+ const invariants = [];
71
+ invariants.push({
72
+ id: "inv-img-dimensions",
73
+ domain: "image",
74
+ type: "image_layout",
75
+ severity: "hard",
76
+ description: "Image dimensions and non-blank content match reference",
77
+ tags: ["image", "layout", "hard"],
78
+ sourceId: "src-1",
79
+ input: { referenceArtifact: refKey },
80
+ expected: {
81
+ dimensions: { width: dims.width, height: dims.height, aspectRatioTolerance: 0.01 },
82
+ ...(nonBlank === true ? { nonBlank: true } : {})
83
+ },
84
+ tolerance: {}
85
+ });
86
+ if (img) {
87
+ invariants.push({
88
+ id: "inv-img-layout",
89
+ domain: "image",
90
+ type: "image_layout",
91
+ severity: "soft",
92
+ description: "Layout regions and palette similarity match reference",
93
+ tags: ["image", "layout", "soft"],
94
+ sourceId: "src-1",
95
+ input: { referenceArtifact: refKey },
96
+ expected: {
97
+ palette,
98
+ regions,
99
+ ...(typography.length ? { typographyHierarchy: typography } : {})
100
+ },
101
+ tolerance: { minLayoutIoU: 0.75, minPaletteSimilarity: 0.8 }
102
+ });
103
+ invariants.push({
104
+ id: "inv-img-perceptual",
105
+ domain: "image",
106
+ type: "image_perceptual",
107
+ severity: "soft",
108
+ description: "Perceptual similarity (SSIM/pixel-diff/dHash) matches reference",
109
+ tags: ["image", "perceptual", "soft"],
110
+ sourceId: "src-1",
111
+ input: { referenceArtifact: refKey },
112
+ expected: {
113
+ referenceHash: dHash,
114
+ dimensions: { width: dims.width, height: dims.height }
115
+ },
116
+ tolerance: { minSSIM: 0.85, maxPixelDiffRatio: 0.1, colorDelta: 0.1 }
117
+ });
118
+ }
119
+ else if (decodeDiagnostic) {
120
+ // For non-decodable formats without sharp, keep a soft perceptual placeholder as skipped info? No:
121
+ // spec says "catch ADAPTER_MISSING for non-PNG and still emit dimension invariant with warning".
122
+ // We emit only the hard dimension invariant and surface warning.
123
+ }
124
+ return {
125
+ domain: "image",
126
+ sources: [
127
+ {
128
+ id: "src-1",
129
+ kind: "image",
130
+ ref: source,
131
+ meta: {
132
+ width: dims.width,
133
+ height: dims.height,
134
+ format: headerDims?.format || img?.format || "unknown",
135
+ decoded: Boolean(img),
136
+ ...(typography.length ? { typographyHierarchy: typography } : {})
137
+ }
138
+ }
139
+ ],
140
+ artifacts: {
141
+ root: ".vibecode/artifacts",
142
+ files: { [refKey]: savedRel }
143
+ },
144
+ invariants,
145
+ warnings
146
+ };
147
+ }
@@ -0,0 +1,5 @@
1
+ import type { Domain, IngestDeps, IngestOptions, IngestResult, IngestorFn } from "../core/types.js";
2
+ export declare function listDomains(): string[];
3
+ export declare function detectDomain(source: unknown): Domain;
4
+ export declare function getIngestor(domain: string): Promise<IngestorFn>;
5
+ export declare function ingest(options?: IngestOptions, deps?: IngestDeps): Promise<IngestResult>;
@@ -0,0 +1,97 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ import { VibecodeError } from "../core/errors.js";
4
+ import { ingest as ingestCli } from "./cli.js";
5
+ const INGESTORS = {
6
+ cli: ingestCli,
7
+ script: ingestCli
8
+ };
9
+ const IMAGE_EXTS_EXT = new Set([".png", ".jpg", ".jpeg", ".webp"]);
10
+ const VIDEO_EXTS_EXT = new Set([".mp4", ".mov", ".webm", ".mkv", ".gif", ".avi", ".m4v"]);
11
+ // Sidecar files that legitimately accompany an ordered keyframe directory.
12
+ const FRAMES_SIDECAR_EXTS = new Set([".srt", ".vtt"]);
13
+ // Lazy-loaded registries for milestone modules (M2-M4/M3 bridges).
14
+ const LAZY = {
15
+ image: async () => (await import("./image.js")).ingest,
16
+ web: async () => (await import("./web.js")).ingest,
17
+ url: async () => (await import("./web.js")).ingest,
18
+ api: async () => (await import("./api-repo.js")).ingestApi,
19
+ repo: async () => (await import("./api-repo.js")).ingestRepo,
20
+ video: async () => (await import("./video.js")).ingest,
21
+ rea: async () => {
22
+ const mod = await import("./bridges.js");
23
+ return (options = {}) => mod.importRea(options.source || "", options);
24
+ },
25
+ "cli-anything": async () => {
26
+ const mod = await import("./bridges.js");
27
+ return (options = {}) => mod.importCliAnything(options.source || "", options);
28
+ }
29
+ };
30
+ export function listDomains() {
31
+ return [...new Set([...Object.keys(INGESTORS), ...Object.keys(LAZY)])];
32
+ }
33
+ export function detectDomain(source) {
34
+ if (typeof source !== "string")
35
+ return "cli";
36
+ const s = source.trim();
37
+ if (/^https?:\/\//i.test(s))
38
+ return "web";
39
+ if (fs.existsSync(s)) {
40
+ const st = fs.statSync(s);
41
+ if (st.isDirectory()) {
42
+ // A directory of ordered keyframes (plus optional .srt/.vtt sidecars) is a video
43
+ // reference; anything else is a repo.
44
+ try {
45
+ const entries = fs
46
+ .readdirSync(s)
47
+ .filter((f) => !f.startsWith(".") && !FRAMES_SIDECAR_EXTS.has(path.extname(f).toLowerCase()));
48
+ const images = entries.filter((f) => IMAGE_EXTS_EXT.has(path.extname(f).toLowerCase()));
49
+ if (images.length > 0 && images.length === entries.length)
50
+ return "video";
51
+ }
52
+ catch {
53
+ // fall through to repo
54
+ }
55
+ return "repo";
56
+ }
57
+ const ext = path.extname(s).toLowerCase();
58
+ if ([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp"].includes(ext))
59
+ return "image";
60
+ if (VIDEO_EXTS_EXT.has(ext))
61
+ return "video";
62
+ if (ext === ".json") {
63
+ try {
64
+ const doc = JSON.parse(fs.readFileSync(s, "utf8"));
65
+ if (doc && typeof doc === "object" && !Array.isArray(doc)) {
66
+ const rec = doc;
67
+ if ((rec.openapi || rec.swagger) && rec.paths)
68
+ return "api";
69
+ }
70
+ }
71
+ catch {
72
+ // fall through
73
+ }
74
+ }
75
+ }
76
+ return "cli";
77
+ }
78
+ export async function getIngestor(domain) {
79
+ if (INGESTORS[domain])
80
+ return INGESTORS[domain];
81
+ if (LAZY[domain]) {
82
+ return LAZY[domain]();
83
+ }
84
+ throw new VibecodeError("UNSUPPORTED_FORMAT", `Unknown ingest domain: ${domain}`);
85
+ }
86
+ export async function ingest(options = {}, deps = {}) {
87
+ const domain = options.domain || detectDomain(options.source);
88
+ const fn = await getIngestor(domain);
89
+ const result = await fn(options, deps);
90
+ return {
91
+ domain: result.domain || domain,
92
+ sources: result.sources || [],
93
+ artifacts: result.artifacts || { root: ".vibecode/artifacts", files: {} },
94
+ invariants: result.invariants || [],
95
+ warnings: result.warnings || []
96
+ };
97
+ }
@@ -0,0 +1,47 @@
1
+ import { VibecodeError } from "../core/errors.js";
2
+ import type { BBox, ExtractedVideoState, FfmpegAdapter, FfmpegFrame, IngestDeps, IngestOptions, IngestResult, RgbaImage, SubtitleCue, VerifyDeps, VideoTransition } from "../core/types.js";
3
+ export declare const VIDEO_EXTS: Set<string>;
4
+ export declare const IMAGE_EXTS: Set<string>;
5
+ export declare function parseCues(text: unknown): SubtitleCue[];
6
+ export declare const parseSrt: typeof parseCues;
7
+ export declare const parseVtt: typeof parseCues;
8
+ export declare function readSubtitles(filePath: string | null | undefined): SubtitleCue[];
9
+ export declare function cueAt(cues: readonly SubtitleCue[], timestampMs: number): string | null;
10
+ /** Parse `showinfo` scene timestamps from ffmpeg stderr/stdout. */
11
+ export declare function parseSceneTimestamps(logText: unknown): number[];
12
+ export declare function parseFfprobeDurationMs(stdout: unknown): number | null;
13
+ /**
14
+ * Resolve the ffmpeg adapter.
15
+ * - `deps.ffmpegAdapter` explicitly set (object or `null`) wins — `null` models "absent" in tests.
16
+ * - Otherwise probe the real binaries.
17
+ */
18
+ export declare function resolveFfmpegAdapter(deps?: IngestDeps | VerifyDeps): FfmpegAdapter | null;
19
+ export declare function ffmpegMissingError(): VibecodeError;
20
+ /** Extract ordered keyframe files + duration from a video file via the adapter. */
21
+ export declare function extractVideoFrames(absSource: string, { cwd, sceneThreshold, maxFrames, cacheKey }: {
22
+ cwd?: string;
23
+ sceneThreshold?: number;
24
+ maxFrames?: number;
25
+ cacheKey?: string;
26
+ }, adapter: FfmpegAdapter | null): {
27
+ frames: FfmpegFrame[];
28
+ durationMs: number;
29
+ };
30
+ export declare function listFrameFiles(dir: string): string[];
31
+ export declare function bboxFromDiffMask(diffMask: RgbaImage): BBox;
32
+ export declare function changedRegionBetween(imgA: RgbaImage, imgB: RgbaImage, { colorDelta }?: {
33
+ colorDelta?: number;
34
+ }): {
35
+ changedRegion: BBox;
36
+ diffRatio: number;
37
+ };
38
+ /** Decode + dedupe frames (SSIM > 0.985) into an ordered state timeline. */
39
+ export declare function extractStates(frames: readonly FfmpegFrame[], { cues, deps, colorDelta }?: {
40
+ cues?: readonly SubtitleCue[];
41
+ deps?: IngestDeps | VerifyDeps;
42
+ colorDelta?: number;
43
+ }): Promise<{
44
+ states: ExtractedVideoState[];
45
+ transitions: VideoTransition[];
46
+ }>;
47
+ export declare function ingest(options?: IngestOptions, deps?: IngestDeps): Promise<IngestResult>;