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,397 @@
1
+ import { VibecodeError, errorMessage } from "../core/errors.js";
2
+ import { loadPlaywright } from "../core/adapters.js";
3
+ import { saveArtifact, ensureDir, resolveWorkspace } from "../core/store.js";
4
+ const LANDMARK_TAGS = ["header", "nav", "main", "footer", "h1", "h2", "form", "table", "ul"];
5
+ const PLAYWRIGHT_INSTALL_HINT = "npm install -D playwright && npx playwright install chromium";
6
+ function isObject(v) {
7
+ return v !== null && typeof v === "object" && !Array.isArray(v);
8
+ }
9
+ function stripTags(html) {
10
+ return String(html)
11
+ .replace(/<script[\s\S]*?<\/script>/gi, " ")
12
+ .replace(/<style[\s\S]*?<\/style>/gi, " ")
13
+ .replace(/<[^>]+>/g, " ")
14
+ .replace(/&nbsp;/g, " ")
15
+ .replace(/&amp;/g, "&")
16
+ .replace(/&lt;/g, "<")
17
+ .replace(/&gt;/g, ">")
18
+ .replace(/\s+/g, " ")
19
+ .trim();
20
+ }
21
+ function extractTitle(html) {
22
+ const m = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
23
+ return m ? stripTags(m[1]) : "";
24
+ }
25
+ function extractAllLandmarks(html) {
26
+ const landmarks = [];
27
+ for (const tag of LANDMARK_TAGS) {
28
+ const re = new RegExp(`<${tag}\\b[^>]*>([\\s\\S]*?)<\\/${tag}>`, "gi");
29
+ let m;
30
+ while ((m = re.exec(html)) !== null) {
31
+ landmarks.push({ tag, text: stripTags(m[1]).slice(0, 120) });
32
+ }
33
+ }
34
+ return landmarks;
35
+ }
36
+ function extractLandmarks(html) {
37
+ const landmarks = [];
38
+ for (const tag of LANDMARK_TAGS) {
39
+ const re = new RegExp(`<${tag}\\b[^>]*>([\\s\\S]*?)<\\/${tag}>`, "i");
40
+ const m = re.exec(html);
41
+ if (!m)
42
+ continue;
43
+ const entry = { tag, required: true };
44
+ const text = stripTags(m[1]).slice(0, 80);
45
+ if (text && (tag === "h1" || tag === "h2" || tag === "main"))
46
+ entry.textContains = text;
47
+ landmarks.push(entry);
48
+ }
49
+ return landmarks;
50
+ }
51
+ function normalizeRoute(route) {
52
+ if (typeof route === "string")
53
+ return { path: route.startsWith("/") ? route : `/${route}`, waitUntil: "networkidle" };
54
+ if (!route || typeof route !== "object" || Array.isArray(route))
55
+ return { path: "/", waitUntil: "networkidle" };
56
+ const vp = route.viewport;
57
+ const timeoutMs = typeof route.timeoutMs === "number" && Number.isFinite(route.timeoutMs) && route.timeoutMs > 0
58
+ ? route.timeoutMs
59
+ : undefined;
60
+ return {
61
+ path: route.path || "/",
62
+ viewport: vp && typeof vp === "object" && typeof vp.width === "number" && typeof vp.height === "number" ? vp : undefined,
63
+ waitUntil: route.waitUntil || "networkidle",
64
+ id: route.id,
65
+ titleContains: route.titleContains,
66
+ ...(timeoutMs !== undefined ? { timeoutMs } : {})
67
+ };
68
+ }
69
+ function buildUrl(base, routePath) {
70
+ if (/^https?:\/\//i.test(routePath))
71
+ return routePath;
72
+ const baseUrl = /^https?:\/\//i.test(base) ? base : `http://${base}`;
73
+ return new URL(routePath, baseUrl).toString();
74
+ }
75
+ async function fetchRoute(url, _viewport, timeoutMs = 15000) {
76
+ const ctrl = new AbortController();
77
+ const t = setTimeout(() => ctrl.abort(), timeoutMs);
78
+ try {
79
+ const res = await fetch(url, { signal: ctrl.signal, redirect: "follow" });
80
+ const html = await res.text();
81
+ return {
82
+ status: res.status,
83
+ title: extractTitle(html),
84
+ landmarks: extractLandmarks(html),
85
+ html,
86
+ headers: Object.fromEntries([...res.headers.entries()].map(([k, v]) => [k.toLowerCase(), v]))
87
+ };
88
+ }
89
+ finally {
90
+ clearTimeout(t);
91
+ }
92
+ }
93
+ function slugify(text) {
94
+ return String(text).replace(/[^A-Za-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80) || "route";
95
+ }
96
+ function resolvePlaywright(candidate) {
97
+ if (!candidate || typeof candidate !== "object")
98
+ return null;
99
+ const mod = candidate;
100
+ if (mod.chromium && typeof mod.chromium.launch === "function") {
101
+ return mod;
102
+ }
103
+ if (mod.default?.chromium && typeof mod.default.chromium.launch === "function") {
104
+ return mod.default;
105
+ }
106
+ return null;
107
+ }
108
+ async function getPlaywright(deps) {
109
+ const explicit = Object.prototype.hasOwnProperty.call(deps, "playwright") ? deps.playwright : undefined;
110
+ if (explicit === null)
111
+ return null;
112
+ const loaded = explicit !== undefined ? explicit : await loadPlaywright(deps);
113
+ return resolvePlaywright(loaded);
114
+ }
115
+ function isValidBBox(box) {
116
+ if (!isObject(box))
117
+ return false;
118
+ const { x, y, w, h } = box;
119
+ return (typeof x === "number" &&
120
+ typeof y === "number" &&
121
+ typeof w === "number" &&
122
+ typeof h === "number" &&
123
+ Number.isFinite(x) &&
124
+ Number.isFinite(y) &&
125
+ Number.isFinite(w) &&
126
+ Number.isFinite(h) &&
127
+ w > 0 &&
128
+ h > 0);
129
+ }
130
+ function normalizeNetworkEntry(entry) {
131
+ const out = {
132
+ method: String(entry.method || "GET").toUpperCase(),
133
+ pathPattern: entry.pathPattern || entry.path || "/",
134
+ status: entry.status
135
+ };
136
+ if (entry.contentType)
137
+ out.contentType = String(entry.contentType).split(";")[0].trim();
138
+ if (isObject(entry.jsonSchema))
139
+ out.jsonSchema = entry.jsonSchema;
140
+ return out;
141
+ }
142
+ export async function ingest(options = {}, deps = {}) {
143
+ const source = options.source;
144
+ if (!source || typeof source !== "string") {
145
+ throw new VibecodeError("TARGET_MISSING", "Web ingestor requires --source <url>");
146
+ }
147
+ const cwd = options.cwd || process.cwd();
148
+ const { artifactsDir } = resolveWorkspace(cwd);
149
+ ensureDir(artifactsDir);
150
+ const defaultTimeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) && options.timeoutMs > 0
151
+ ? options.timeoutMs
152
+ : typeof deps.timeoutMs === "number" && Number.isFinite(deps.timeoutMs) && deps.timeoutMs > 0
153
+ ? deps.timeoutMs
154
+ : 15000;
155
+ const warnings = [];
156
+ let defaultRoute = "/";
157
+ try {
158
+ const parsed = new URL(/^https?:\/\//i.test(source) ? source : `http://${source}`);
159
+ const p = `${parsed.pathname || "/"}${parsed.search || ""}`;
160
+ if (p && p !== "/")
161
+ defaultRoute = p;
162
+ }
163
+ catch { /* keep "/" */ }
164
+ const routes = (Array.isArray(options.routes) && options.routes.length ? options.routes : [defaultRoute]).map(normalizeRoute);
165
+ const pw = await getPlaywright(deps);
166
+ let browser = null;
167
+ let playwrightActive = false;
168
+ let launchFailureMessage = null;
169
+ const invariants = [];
170
+ const artifacts = { root: ".vibecode/artifacts", files: {} };
171
+ try {
172
+ if (pw) {
173
+ try {
174
+ browser = await pw.chromium.launch({ headless: true });
175
+ playwrightActive = true;
176
+ }
177
+ catch (err) {
178
+ browser = null;
179
+ playwrightActive = false;
180
+ launchFailureMessage = errorMessage(err);
181
+ }
182
+ }
183
+ if (browser) {
184
+ for (const route of routes) {
185
+ const url = buildUrl(source, route.path);
186
+ const viewport = route.viewport || { width: 1280, height: 720 };
187
+ const timeoutMs = route.timeoutMs ?? defaultTimeoutMs;
188
+ const page = await browser.newPage({ viewport });
189
+ try {
190
+ const network = [];
191
+ const consoleErrors = [];
192
+ const pageErrors = [];
193
+ const onResponse = (res) => {
194
+ try {
195
+ const parsed = new URL(res.url());
196
+ if (parsed.pathname === "/favicon.ico")
197
+ return;
198
+ network.push({
199
+ method: res.request().method(),
200
+ pathPattern: parsed.pathname,
201
+ status: res.status(),
202
+ contentType: res.headers()?.["content-type"]
203
+ });
204
+ }
205
+ catch { /* ignore */ }
206
+ };
207
+ if (typeof page.on === "function") {
208
+ page.on("response", onResponse);
209
+ page.on("console", (msg) => { if (msg.type() === "error")
210
+ consoleErrors.push(msg.text()); });
211
+ page.on("pageerror", (err) => pageErrors.push(err.message || String(err)));
212
+ }
213
+ let response = null;
214
+ try {
215
+ response = await page.goto(url, { waitUntil: route.waitUntil, timeout: timeoutMs });
216
+ }
217
+ catch (err) {
218
+ warnings.push({ code: "EXEC_ERROR", message: `Navigation failed for ${url}: ${errorMessage(err)}` });
219
+ continue;
220
+ }
221
+ const title = await page.title();
222
+ const landmarks = await page.$$eval(LANDMARK_TAGS.map((t) => t).join(","), (nodes) => nodes.map((n) => ({ tag: n.tagName.toLowerCase(), text: (n.textContent || "").trim().slice(0, 80) }))).catch(() => []);
223
+ const boundingBoxes = [];
224
+ const seenBoxTags = new Set();
225
+ for (const lm of landmarks) {
226
+ if (seenBoxTags.has(lm.tag))
227
+ continue;
228
+ seenBoxTags.add(lm.tag);
229
+ const box = await page.$eval(lm.tag, (el) => {
230
+ const r = el.getBoundingClientRect();
231
+ const vw = window.innerWidth || 1;
232
+ const vh = window.innerHeight || 1;
233
+ return { x: r.x / vw, y: r.y / vh, w: r.width / vw, h: r.height / vh };
234
+ }).catch(() => null);
235
+ if (isValidBBox(box))
236
+ boundingBoxes.push({ selector: lm.tag, bbox: box });
237
+ }
238
+ const slug = slugify(route.path);
239
+ const shotName = `web/${slug}.png`;
240
+ try {
241
+ const buf = await page.screenshot({ fullPage: false });
242
+ if (buf)
243
+ artifacts.files[`web-${slug}`] = saveArtifact(buf, shotName, cwd);
244
+ }
245
+ catch { /* screenshot optional */ }
246
+ const titleVal = route.titleContains || (title ? title : undefined);
247
+ const routeInv = {
248
+ id: route.id || `inv-web-${slug}`,
249
+ domain: "web",
250
+ type: "web_route",
251
+ severity: "hard",
252
+ description: `Route ${route.path} returns expected status and landmarks`,
253
+ tags: ["web", "route", "hard"],
254
+ sourceId: "src-1",
255
+ input: { path: route.path, viewport, waitUntil: route.waitUntil },
256
+ expected: {
257
+ status: response?.status() ?? 200,
258
+ ...(titleVal ? { titleContains: titleVal } : {}),
259
+ landmarks: landmarks.map((lm) => ({
260
+ tag: lm.tag,
261
+ required: true,
262
+ ...(lm.tag === "h1" || lm.tag === "h2" ? { textContains: lm.text } : {})
263
+ }))
264
+ },
265
+ tolerance: {}
266
+ };
267
+ invariants.push(routeInv);
268
+ if (boundingBoxes.length) {
269
+ invariants.push({
270
+ id: `inv-web-${slug}-layout`,
271
+ domain: "web",
272
+ type: "web_route",
273
+ severity: "soft",
274
+ description: `Route ${route.path} preserves landmark layout`,
275
+ tags: ["web", "layout", "soft"],
276
+ sourceId: "src-1",
277
+ input: { path: route.path, viewport, waitUntil: route.waitUntil },
278
+ expected: { status: response?.status() ?? 200, boundingBoxes },
279
+ tolerance: { minLayoutIoU: 0.75 }
280
+ });
281
+ }
282
+ const normalizedNet = (page.__networkCalls || network).map(normalizeNetworkEntry);
283
+ if (normalizedNet.length) {
284
+ invariants.push({
285
+ id: `inv-web-${slug}-network`,
286
+ domain: "web",
287
+ type: "web_network",
288
+ severity: "hard",
289
+ description: `Route ${route.path} issues expected network calls`,
290
+ tags: ["web", "network", "hard"],
291
+ sourceId: "src-1",
292
+ input: { triggerPath: route.path, viewport, waitUntil: route.waitUntil },
293
+ expected: { networkCalls: normalizedNet },
294
+ tolerance: {}
295
+ });
296
+ }
297
+ }
298
+ finally {
299
+ try {
300
+ await page.close?.();
301
+ }
302
+ catch { /* ignore */ }
303
+ }
304
+ }
305
+ }
306
+ else {
307
+ warnings.push({
308
+ code: "ADAPTER_DEGRADED",
309
+ message: launchFailureMessage
310
+ ? `Playwright failed to launch Chromium (${launchFailureMessage}); using native fetch + HTML landmark fallback (web_flow/boundingBoxes unavailable).`
311
+ : "Playwright is not installed; using native fetch + HTML landmark fallback (web_flow/boundingBoxes unavailable).",
312
+ adapter: "playwright",
313
+ installHint: PLAYWRIGHT_INSTALL_HINT
314
+ });
315
+ for (const route of routes) {
316
+ const url = buildUrl(source, route.path);
317
+ let obs;
318
+ try {
319
+ obs = await (deps.fetchRoute || fetchRoute)(url, route.viewport, route.timeoutMs ?? defaultTimeoutMs);
320
+ }
321
+ catch (err) {
322
+ warnings.push({ code: "EXEC_ERROR", message: `Fetch failed for ${url}: ${errorMessage(err)}` });
323
+ continue;
324
+ }
325
+ const slug = slugify(route.path);
326
+ const titleVal = route.titleContains || (obs.title ? obs.title : undefined);
327
+ invariants.push({
328
+ id: route.id || `inv-web-${slug}`,
329
+ domain: "web",
330
+ type: "web_route",
331
+ severity: "hard",
332
+ description: `Route ${route.path} returns expected status and landmarks (fetch fallback)`,
333
+ tags: ["web", "route", "hard", "fetch-fallback"],
334
+ sourceId: "src-1",
335
+ input: { path: route.path, waitUntil: "networkidle" },
336
+ expected: {
337
+ status: obs.status,
338
+ ...(titleVal ? { titleContains: titleVal } : {}),
339
+ landmarks: obs.landmarks
340
+ },
341
+ tolerance: {}
342
+ });
343
+ }
344
+ }
345
+ // web flow from CLI --flow <file.json>
346
+ if (options.flow && typeof options.flow === "object" && !Array.isArray(options.flow)) {
347
+ const flow = options.flow;
348
+ if (!browser) {
349
+ warnings.push({
350
+ code: "ADAPTER_MISSING",
351
+ message: launchFailureMessage
352
+ ? `web_flow verification requires Playwright Chromium (${launchFailureMessage}); flow invariant was not emitted.`
353
+ : "web_flow verification requires Playwright; flow invariant was not emitted.",
354
+ adapter: "playwright",
355
+ installHint: PLAYWRIGHT_INSTALL_HINT
356
+ });
357
+ }
358
+ else {
359
+ invariants.push({
360
+ id: flow.id || "inv-web-flow",
361
+ domain: "web",
362
+ type: "web_flow",
363
+ severity: "hard",
364
+ description: flow.description || "Interactive web flow matches reference",
365
+ tags: ["web", "flow", "hard"],
366
+ sourceId: "src-1",
367
+ input: {
368
+ startPath: flow.startPath || "/",
369
+ viewport: flow.viewport || { width: 1280, height: 720 },
370
+ steps: Array.isArray(flow.steps) ? flow.steps : []
371
+ },
372
+ expected: isObject(flow.expected) ? flow.expected : {},
373
+ tolerance: {}
374
+ });
375
+ }
376
+ }
377
+ }
378
+ finally {
379
+ if (browser) {
380
+ try {
381
+ await browser.close();
382
+ }
383
+ catch { /* ignore */ }
384
+ }
385
+ }
386
+ if (invariants.length === 0) {
387
+ warnings.push({ code: "ADAPTER_DEGRADED", message: "Web ingestor produced no invariants." });
388
+ }
389
+ return {
390
+ domain: "web",
391
+ sources: [{ id: "src-1", kind: "web", ref: source, meta: { routes: routes.map((r) => r.path), playwright: playwrightActive } }],
392
+ artifacts,
393
+ invariants,
394
+ warnings
395
+ };
396
+ }
397
+ export { stripTags, extractTitle, extractLandmarks, extractAllLandmarks, normalizeNetworkEntry };
@@ -0,0 +1,2 @@
1
+ import type { McpServerInstance, McpServerOptions } from "../core/types.js";
2
+ export declare function createMcpServer({ cwd, stdin, stdout, stderr, deps }?: McpServerOptions): McpServerInstance;