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,3 @@
1
+ import type { IngestOptions, IngestResult } from "../core/types.js";
2
+ export declare function importRea(filePath: string, options?: IngestOptions): Promise<IngestResult>;
3
+ export declare function importCliAnything(filePath: string, options?: IngestOptions): Promise<IngestResult>;
@@ -0,0 +1,562 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { VibecodeError, errorMessage } from "../core/errors.js";
4
+ import { validateContract } from "../core/schema.js";
5
+ function isObject(v) {
6
+ return v !== null && typeof v === "object" && !Array.isArray(v);
7
+ }
8
+ function asArray(v) {
9
+ return Array.isArray(v) ? v : [];
10
+ }
11
+ function str(v, fallback = "") {
12
+ return typeof v === "string" && v.trim() ? v : fallback;
13
+ }
14
+ function loadJson(filePath) {
15
+ let raw;
16
+ try {
17
+ raw = fs.readFileSync(filePath, "utf8");
18
+ }
19
+ catch (err) {
20
+ throw new VibecodeError("TARGET_MISSING", `Bridge file not found: ${filePath}`, { details: errorMessage(err) });
21
+ }
22
+ try {
23
+ return JSON.parse(raw);
24
+ }
25
+ catch (err) {
26
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", `Invalid JSON in bridge file: ${errorMessage(err)}`);
27
+ }
28
+ }
29
+ function slugify(text, fallback = "item") {
30
+ const s = String(text || "")
31
+ .toLowerCase()
32
+ .replace(/[^a-z0-9]+/g, "-")
33
+ .replace(/^-+|-+$/g, "")
34
+ .slice(0, 64);
35
+ return s || fallback;
36
+ }
37
+ function uniqueId(base, used) {
38
+ let id = slugify(base, "inv");
39
+ if (!id.startsWith("inv-"))
40
+ id = `inv-${id}`;
41
+ if (!used.has(id)) {
42
+ used.add(id);
43
+ return id;
44
+ }
45
+ let n = 2;
46
+ while (used.has(`${id}-${n}`))
47
+ n++;
48
+ const out = `${id}-${n}`;
49
+ used.add(out);
50
+ return out;
51
+ }
52
+ function normalizeSeverity(v) {
53
+ return v === "soft" ? "soft" : "hard";
54
+ }
55
+ function normalizeTags(tags, extra = []) {
56
+ const out = [];
57
+ for (const t of [...extra, ...(Array.isArray(tags) ? tags : [])]) {
58
+ if (typeof t === "string" && t.trim() && !out.includes(t))
59
+ out.push(t.trim());
60
+ }
61
+ return out.length ? out : extra.length ? extra : ["bridge"];
62
+ }
63
+ function pushWarning(warnings, code, message, details) {
64
+ warnings.push({ code, message, ...(details !== undefined ? { details } : {}) });
65
+ }
66
+ function finalizeInvariant(raw, { kind, fallbackDomain, index, usedIds }) {
67
+ if (!isObject(raw)) {
68
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge invariant at index ${index} must be an object`);
69
+ }
70
+ const domain = str(raw.domain, fallbackDomain || "cli");
71
+ const type = str(raw.type, domain === "cli" ? "command" : domain === "api" ? "http" : domain === "web" ? "web_route" : "command");
72
+ const idBase = str(raw.id) || `inv-${kind}-${type}-${index + 1}`;
73
+ const inv = {
74
+ id: uniqueId(idBase, usedIds),
75
+ domain: domain,
76
+ type: type,
77
+ severity: normalizeSeverity(raw.severity),
78
+ description: str(raw.description, `Imported ${kind} ${type} invariant ${index + 1}`),
79
+ tags: normalizeTags(raw.tags, ["bridge", kind]),
80
+ sourceId: str(raw.sourceId, "src-1"),
81
+ input: isObject(raw.input) ? raw.input : {},
82
+ expected: isObject(raw.expected) ? raw.expected : {},
83
+ tolerance: isObject(raw.tolerance) ? raw.tolerance : {}
84
+ };
85
+ return inv;
86
+ }
87
+ function validateInvariantsOrThrow(invariants, kind) {
88
+ const contract = {
89
+ schemaVersion: "0.2.0",
90
+ target: { name: kind, domains: ["cli"], sources: [{ id: "src-1", kind, ref: kind }] },
91
+ artifacts: { root: ".vibecode/artifacts", files: {} },
92
+ thresholds: { hardBehavioralParity: 1, softPerceptualParity: 0.85, softGateMode: "warn", defaults: {} },
93
+ invariants
94
+ };
95
+ const res = validateContract(contract);
96
+ if (!res.ok) {
97
+ const err = res.errors[0];
98
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge produced invalid invariant: ${err.path} ${err.message}`, { details: res.errors });
99
+ }
100
+ }
101
+ function extractArtifactFiles(doc) {
102
+ const files = {};
103
+ if (isObject(doc.artifacts) && isObject(doc.artifacts.files)) {
104
+ for (const [k, v] of Object.entries(doc.artifacts.files)) {
105
+ if (typeof v === "string")
106
+ files[k] = v;
107
+ }
108
+ }
109
+ return files;
110
+ }
111
+ function normalizePassThroughContract(doc, kind, warnings) {
112
+ const contractDoc = isObject(doc.contract) ? doc.contract : doc;
113
+ const rawInvs = asArray(contractDoc.invariants);
114
+ if (rawInvs.length === 0) {
115
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge file contains no invariants`);
116
+ }
117
+ const usedIds = new Set();
118
+ const invariants = rawInvs.map((inv, i) => finalizeInvariant(inv, {
119
+ kind,
120
+ fallbackDomain: (isObject(inv) && typeof inv.domain === "string" ? inv.domain : "") || "cli",
121
+ index: i,
122
+ usedIds,
123
+ warnings
124
+ }));
125
+ validateInvariantsOrThrow(invariants, kind);
126
+ return {
127
+ domain: invariants[0]?.domain || "cli",
128
+ sources: [{ id: "src-1", kind, ref: "inline", meta: { bridge: kind } }],
129
+ artifacts: { root: ".vibecode/artifacts", files: extractArtifactFiles(contractDoc) },
130
+ invariants,
131
+ warnings
132
+ };
133
+ }
134
+ function looksLikeContractDoc(doc) {
135
+ return isObject(doc) && (Array.isArray(doc.invariants) || isObject(doc.contract));
136
+ }
137
+ function firstObject(doc, keys) {
138
+ for (const k of keys) {
139
+ if (isObject(doc[k]))
140
+ return doc[k];
141
+ if (Array.isArray(doc[k]))
142
+ return { [k]: doc[k] };
143
+ }
144
+ return null;
145
+ }
146
+ function getReaPayload(doc) {
147
+ if (!isObject(doc))
148
+ return null;
149
+ const nested = firstObject(doc, ["analysis", "spec", "manifest", "report", "rea", "output"]);
150
+ const base = nested ? { ...nested, ...doc, ...nested } : doc;
151
+ return base;
152
+ }
153
+ function getCliAnythingPayload(doc) {
154
+ if (!isObject(doc))
155
+ return null;
156
+ const nested = firstObject(doc, ["cli_anything", "cliAnything", "harness", "spec", "manifest", "report", "analysis"]);
157
+ const base = nested ? { ...nested, ...doc, ...nested } : doc;
158
+ return base;
159
+ }
160
+ function coerceStringArray(v) {
161
+ if (Array.isArray(v))
162
+ return v.map((x) => String(x));
163
+ if (typeof v === "string" && v.trim())
164
+ return [v];
165
+ return [];
166
+ }
167
+ function convertReaRoutes(items, usedIds, warnings) {
168
+ const out = [];
169
+ items.forEach((item, i) => {
170
+ if (!isObject(item)) {
171
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.routes[${i}] is not an object; skipped`);
172
+ return;
173
+ }
174
+ const p = str(item.path, str(item.url, str(item.route, "")));
175
+ if (!p) {
176
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.routes[${i}] missing path; skipped`);
177
+ return;
178
+ }
179
+ const pathVal = p.startsWith("/") ? p : `/${p}`;
180
+ const expected = isObject(item.expected) ? { ...item.expected } : {};
181
+ if (item.status !== undefined && expected.status === undefined)
182
+ expected.status = item.status;
183
+ if (item.title !== undefined && expected.titleContains === undefined)
184
+ expected.titleContains = String(item.title);
185
+ if (item.titleContains !== undefined && expected.titleContains === undefined)
186
+ expected.titleContains = String(item.titleContains);
187
+ if (Array.isArray(item.landmarks) && expected.landmarks === undefined)
188
+ expected.landmarks = item.landmarks;
189
+ if (Array.isArray(item.boundingBoxes) && expected.boundingBoxes === undefined)
190
+ expected.boundingBoxes = item.boundingBoxes;
191
+ if (expected.status === undefined)
192
+ expected.status = 200;
193
+ const inv = {
194
+ id: uniqueId(str(item.id, `inv-rea-route-${slugify(pathVal)}`), usedIds),
195
+ domain: "web",
196
+ type: "web_route",
197
+ severity: normalizeSeverity(item.severity),
198
+ description: str(item.description, `REA route ${pathVal}`),
199
+ tags: normalizeTags(item.tags, ["bridge", "rea", "web", "route"]),
200
+ sourceId: str(item.sourceId, "src-1"),
201
+ input: { path: pathVal, ...(isObject(item.input) ? item.input : {}) },
202
+ expected,
203
+ tolerance: isObject(item.tolerance) ? item.tolerance : {}
204
+ };
205
+ out.push(inv);
206
+ });
207
+ return out;
208
+ }
209
+ function convertReaFlows(items, usedIds, warnings) {
210
+ const out = [];
211
+ items.forEach((item, i) => {
212
+ if (!isObject(item)) {
213
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.flows[${i}] is not an object; skipped`);
214
+ return;
215
+ }
216
+ const startPath = str(item.startPath, str(item.start_path, str(item.path, "/")));
217
+ const steps = Array.isArray(item.steps) ? item.steps : [];
218
+ const expected = isObject(item.expected) ? { ...item.expected } : {};
219
+ if (Array.isArray(item.assertions) && expected.assertions === undefined)
220
+ expected.assertions = item.assertions;
221
+ if (Array.isArray(item.networkCalls) && expected.networkCalls === undefined)
222
+ expected.networkCalls = item.networkCalls;
223
+ if (Array.isArray(item.network_calls) && expected.networkCalls === undefined)
224
+ expected.networkCalls = item.network_calls;
225
+ const inv = {
226
+ id: uniqueId(str(item.id, `inv-rea-flow-${slugify(item.name || startPath)}`), usedIds),
227
+ domain: "web",
228
+ type: "web_flow",
229
+ severity: normalizeSeverity(item.severity),
230
+ description: str(item.description, `REA flow ${str(item.name, startPath)}`),
231
+ tags: normalizeTags(item.tags, ["bridge", "rea", "web", "flow"]),
232
+ sourceId: str(item.sourceId, "src-1"),
233
+ input: {
234
+ startPath: startPath.startsWith("/") ? startPath : `/${startPath}`,
235
+ steps,
236
+ ...(isObject(item.input) ? item.input : {})
237
+ },
238
+ expected,
239
+ tolerance: isObject(item.tolerance) ? item.tolerance : {}
240
+ };
241
+ out.push(inv);
242
+ });
243
+ return out;
244
+ }
245
+ function convertReaEndpoints(items, usedIds, warnings) {
246
+ const out = [];
247
+ items.forEach((item, i) => {
248
+ if (!isObject(item)) {
249
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.endpoints[${i}] is not an object; skipped`);
250
+ return;
251
+ }
252
+ const method = str(item.method, "GET").toUpperCase();
253
+ const p = str(item.path, str(item.url, ""));
254
+ if (!p) {
255
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.endpoints[${i}] missing path; skipped`);
256
+ return;
257
+ }
258
+ const pathVal = p.startsWith("/") ? p : `/${p}`;
259
+ const expected = isObject(item.expected) ? { ...item.expected } : {};
260
+ if (item.status !== undefined && expected.status === undefined)
261
+ expected.status = item.status;
262
+ if (item.jsonSchema !== undefined && expected.jsonSchema === undefined)
263
+ expected.jsonSchema = item.jsonSchema;
264
+ if (item.jsonSubset !== undefined && expected.jsonSubset === undefined)
265
+ expected.jsonSubset = item.jsonSubset;
266
+ if (item.jsonPaths !== undefined && expected.jsonPaths === undefined)
267
+ expected.jsonPaths = item.jsonPaths;
268
+ if (expected.status === undefined)
269
+ expected.status = 200;
270
+ const inv = {
271
+ id: uniqueId(str(item.id, `inv-rea-http-${method.toLowerCase()}-${slugify(pathVal)}`), usedIds),
272
+ domain: "api",
273
+ type: "http",
274
+ severity: normalizeSeverity(item.severity),
275
+ description: str(item.description, `REA endpoint ${method} ${pathVal}`),
276
+ tags: normalizeTags(item.tags, ["bridge", "rea", "api", "http"]),
277
+ sourceId: str(item.sourceId, "src-1"),
278
+ input: {
279
+ method,
280
+ path: pathVal,
281
+ ...(isObject(item.headers) ? { headers: item.headers } : {}),
282
+ ...(isObject(item.query) ? { query: item.query } : {}),
283
+ ...(item.body !== undefined ? { body: item.body } : {}),
284
+ ...(isObject(item.input) ? item.input : {})
285
+ },
286
+ expected,
287
+ tolerance: isObject(item.tolerance) ? item.tolerance : {}
288
+ };
289
+ out.push(inv);
290
+ });
291
+ return out;
292
+ }
293
+ function copyExpectedAliases(source, expected, mapping) {
294
+ const target = expected;
295
+ for (const [from, to] of mapping) {
296
+ if (source[from] !== undefined && target[to] === undefined) {
297
+ target[to] = source[from];
298
+ }
299
+ }
300
+ }
301
+ function convertReaCommands(items, usedIds, warnings) {
302
+ const out = [];
303
+ items.forEach((item, i) => {
304
+ if (!isObject(item)) {
305
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.commands[${i}] is not an object; skipped`);
306
+ return;
307
+ }
308
+ const args = coerceStringArray(item.args ?? item.argv ?? item.command);
309
+ const expected = isObject(item.expected) ? { ...item.expected } : {};
310
+ copyExpectedAliases(item, expected, [
311
+ ["exitCode", "exitCode"], ["exit_code", "exitCode"],
312
+ ["stdoutContains", "stdoutContains"], ["stdout_contains", "stdoutContains"],
313
+ ["stderrContains", "stderrContains"], ["stderr_contains", "stderrContains"],
314
+ ["goldenStdout", "goldenStdout"], ["golden_stdout", "goldenStdout"],
315
+ ["jsonSchema", "jsonSchema"], ["json_schema", "jsonSchema"],
316
+ ["jsonPaths", "jsonPaths"], ["json_paths", "jsonPaths"]
317
+ ]);
318
+ const inv = {
319
+ id: uniqueId(str(item.id, `inv-rea-cli-${slugify(args.join("-") || item.name || i + 1)}`), usedIds),
320
+ domain: "cli",
321
+ type: "command",
322
+ severity: normalizeSeverity(item.severity),
323
+ description: str(item.description, `REA command ${args.join(" ") || "(no args)"}`),
324
+ tags: normalizeTags(item.tags, ["bridge", "rea", "cli", "command"]),
325
+ sourceId: str(item.sourceId, "src-1"),
326
+ input: {
327
+ args,
328
+ ...(item.stdin !== undefined ? { stdin: item.stdin } : {}),
329
+ ...(isObject(item.env) ? { env: item.env } : {}),
330
+ ...(isObject(item.input) ? item.input : {})
331
+ },
332
+ expected,
333
+ tolerance: isObject(item.tolerance) ? item.tolerance : {}
334
+ };
335
+ out.push(inv);
336
+ });
337
+ return out;
338
+ }
339
+ function convertReaScreens(items, usedIds, warnings) {
340
+ const out = [];
341
+ items.forEach((item, i) => {
342
+ if (!isObject(item)) {
343
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.screens[${i}] is not an object; skipped`);
344
+ return;
345
+ }
346
+ const ref = str(item.referenceArtifact, str(item.reference_artifact, str(item.reference, "")));
347
+ const dims = item.dimensions || item.size;
348
+ const hasDims = isObject(dims) && Number.isFinite(Number(dims.width)) && Number.isFinite(Number(dims.height));
349
+ if (!ref || !hasDims) {
350
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `rea.screens[${i}] missing referenceArtifact/dimensions; skipped`, { id: item.id, referenceArtifact: ref || null });
351
+ return;
352
+ }
353
+ const expected = isObject(item.expected) ? { ...item.expected } : {};
354
+ const inv = {
355
+ id: uniqueId(str(item.id, `inv-rea-screen-${slugify(item.name || i + 1)}`), usedIds),
356
+ domain: "image",
357
+ type: str(item.type, "image_layout"),
358
+ severity: normalizeSeverity(item.severity),
359
+ description: str(item.description, `REA screen ${str(item.name, String(i + 1))}`),
360
+ tags: normalizeTags(item.tags, ["bridge", "rea", "image"]),
361
+ sourceId: str(item.sourceId, "src-1"),
362
+ input: {
363
+ referenceArtifact: ref,
364
+ dimensions: { width: Number(dims.width), height: Number(dims.height) },
365
+ ...(isObject(item.input) ? item.input : {})
366
+ },
367
+ expected,
368
+ tolerance: isObject(item.tolerance) ? item.tolerance : {}
369
+ };
370
+ out.push(inv);
371
+ });
372
+ return out;
373
+ }
374
+ function convertReaManifest(doc, kind, warnings) {
375
+ const payload = getReaPayload(doc) || doc;
376
+ const routes = asArray(payload.routes || payload.pages);
377
+ const flows = asArray(payload.flows || payload.interactions);
378
+ const endpoints = asArray(payload.endpoints || payload.api || payload.apis);
379
+ const commands = asArray(payload.commands || payload.cli || payload.cliCommands);
380
+ const screens = asArray(payload.screens || payload.images);
381
+ const usedIds = new Set();
382
+ const invariants = [
383
+ ...convertReaRoutes(routes, usedIds, warnings),
384
+ ...convertReaFlows(flows, usedIds, warnings),
385
+ ...convertReaEndpoints(endpoints, usedIds, warnings),
386
+ ...convertReaCommands(commands, usedIds, warnings),
387
+ ...convertReaScreens(screens, usedIds, warnings)
388
+ ];
389
+ if (invariants.length === 0) {
390
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", "rea bridge file contains no convertible invariants", {
391
+ details: { keys: isObject(payload) ? Object.keys(payload) : [] }
392
+ });
393
+ }
394
+ validateInvariantsOrThrow(invariants, kind);
395
+ return {
396
+ domain: invariants[0]?.domain || "cli",
397
+ sources: [{ id: "src-1", kind, ref: "inline", meta: { bridge: kind, format: "rea-manifest" } }],
398
+ artifacts: { root: ".vibecode/artifacts", files: extractArtifactFiles(payload) },
399
+ invariants,
400
+ warnings
401
+ };
402
+ }
403
+ function extractCliAnythingCommands(payload) {
404
+ if (Array.isArray(payload?.commands))
405
+ return payload.commands;
406
+ if (Array.isArray(payload?.subcommands))
407
+ return payload.subcommands;
408
+ if (isObject(payload?.cli) && Array.isArray(payload.cli.commands))
409
+ return payload.cli.commands;
410
+ if (isObject(payload?.cli) && Array.isArray(payload.cli.subcommands))
411
+ return payload.cli.subcommands;
412
+ if (Array.isArray(payload?.commandTree))
413
+ return payload.commandTree;
414
+ return [];
415
+ }
416
+ function convertCliAnythingTestCases(testCases, { baseArgs, usedIds, warnings, commandName }) {
417
+ const out = [];
418
+ testCases.forEach((tc, i) => {
419
+ if (!isObject(tc)) {
420
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `cli-anything test case ${commandName}[${i}] not an object; skipped`);
421
+ return;
422
+ }
423
+ const tcArgs = coerceStringArray(tc.args ?? tc.argv ?? tc.command);
424
+ const args = [...baseArgs, ...tcArgs];
425
+ const expected = isObject(tc.expected) ? { ...tc.expected } : {};
426
+ copyExpectedAliases(tc, expected, [
427
+ ["exit_code", "exitCode"], ["exitCode", "exitCode"],
428
+ ["stdout_contains", "stdoutContains"], ["stdoutContains", "stdoutContains"],
429
+ ["stderr_contains", "stderrContains"], ["stderrContains", "stderrContains"],
430
+ ["golden_stdout", "goldenStdout"], ["goldenStdout", "goldenStdout"],
431
+ ["json_schema", "jsonSchema"], ["jsonSchema", "jsonSchema"],
432
+ ["json_paths", "jsonPaths"], ["jsonPaths", "jsonPaths"],
433
+ ["stdout_regex", "stdoutRegex"], ["stdoutRegex", "stdoutRegex"]
434
+ ]);
435
+ const inv = {
436
+ id: uniqueId(str(tc.id, `inv-cli-anything-${slugify([...baseArgs, tc.name || i + 1].join("-"))}`), usedIds),
437
+ domain: "cli",
438
+ type: "command",
439
+ severity: normalizeSeverity(tc.severity),
440
+ description: str(tc.description, `CLI-Anything ${commandName} ${args.join(" ") || "(no args)"}`),
441
+ tags: normalizeTags(tc.tags, ["bridge", "cli-anything", "cli", "command"]),
442
+ sourceId: str(tc.sourceId, "src-1"),
443
+ input: {
444
+ args,
445
+ ...(tc.stdin !== undefined ? { stdin: tc.stdin } : {}),
446
+ ...(isObject(tc.env) ? { env: tc.env } : {}),
447
+ ...(isObject(tc.input) ? { input: tc.input } : {})
448
+ },
449
+ expected,
450
+ tolerance: isObject(tc.tolerance) ? tc.tolerance : {}
451
+ };
452
+ out.push(inv);
453
+ });
454
+ return out;
455
+ }
456
+ function walkCliAnythingCommands(commands, prefixArgs, usedIds, warnings, out, parentName = "root") {
457
+ commands.forEach((cmd, i) => {
458
+ if (!isObject(cmd)) {
459
+ pushWarning(warnings, "BRIDGE_FORMAT_WARNING", `cli-anything command ${parentName}[${i}] not an object; skipped`);
460
+ return;
461
+ }
462
+ const name = str(cmd.name, str(cmd.command, ""));
463
+ const cmdArgs = coerceStringArray(cmd.args ?? cmd.argv);
464
+ const ownArgs = name ? [...prefixArgs, name, ...cmdArgs] : [...prefixArgs, ...cmdArgs];
465
+ const commandLabel = ownArgs.join(" ") || name || `command-${i + 1}`;
466
+ const tests = asArray(cmd.test_cases || cmd.tests || cmd.probes || cmd.examples || cmd.cases);
467
+ if (tests.length > 0) {
468
+ out.push(...convertCliAnythingTestCases(tests, { baseArgs: ownArgs, usedIds, warnings, commandName: commandLabel }));
469
+ }
470
+ else if (name || cmdArgs.length || cmd.expected || cmd.exit_code !== undefined || cmd.exitCode !== undefined) {
471
+ // Treat command itself as a probe if it carries expectation-ish fields
472
+ const hasExpectation = cmd.expected !== undefined || cmd.exit_code !== undefined || cmd.exitCode !== undefined || cmd.stdout_contains !== undefined || cmd.stdoutContains !== undefined;
473
+ if (hasExpectation) {
474
+ out.push(...convertCliAnythingTestCases([{ ...cmd, args: cmdArgs }], { baseArgs: prefixArgs.concat(name ? [name] : []), usedIds, warnings, commandName: commandLabel }));
475
+ }
476
+ }
477
+ const children = asArray(cmd.subcommands || cmd.commands || cmd.children);
478
+ if (children.length > 0)
479
+ walkCliAnythingCommands(children, ownArgs, usedIds, warnings, out, commandLabel);
480
+ });
481
+ }
482
+ function convertCliAnythingManifest(doc, kind, warnings) {
483
+ const payload = getCliAnythingPayload(doc) || doc;
484
+ const commands = extractCliAnythingCommands(payload);
485
+ const rootTests = asArray(payload.test_cases || payload.tests || payload.probes || payload.examples);
486
+ const usedIds = new Set();
487
+ const invariants = [];
488
+ // Root-level tests (apply to base command, no subcommand prefix beyond optional cli entrypoint)
489
+ const entryObj = isObject(payload.entrypoint) ? payload.entrypoint : undefined;
490
+ const cliObj = isObject(payload.cli) ? payload.cli : undefined;
491
+ const binaryObj = isObject(payload.binary) ? payload.binary : undefined;
492
+ const entryArgs = coerceStringArray(entryObj?.args || cliObj?.args || binaryObj?.args);
493
+ const baseName = str(entryObj?.name, str(cliObj?.name, str(binaryObj?.name, str(payload.name, ""))));
494
+ const basePrefix = baseName ? [baseName, ...entryArgs] : [...entryArgs];
495
+ if (rootTests.length > 0) {
496
+ invariants.push(...convertCliAnythingTestCases(rootTests, { baseArgs: basePrefix, usedIds, warnings, commandName: baseName || "root" }));
497
+ }
498
+ if (commands.length > 0) {
499
+ walkCliAnythingCommands(commands, basePrefix, usedIds, warnings, invariants, baseName || "root");
500
+ }
501
+ // Fallback: some formats put command-like objects at top-level "cases"
502
+ if (invariants.length === 0 && Array.isArray(payload.cases)) {
503
+ invariants.push(...convertCliAnythingTestCases(payload.cases, { baseArgs: basePrefix, usedIds, warnings, commandName: baseName || "root" }));
504
+ }
505
+ if (invariants.length === 0) {
506
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", "cli-anything bridge file contains no convertible invariants", {
507
+ details: { keys: isObject(payload) ? Object.keys(payload) : [] }
508
+ });
509
+ }
510
+ validateInvariantsOrThrow(invariants, kind);
511
+ return {
512
+ domain: "cli",
513
+ sources: [{ id: "src-1", kind, ref: "inline", meta: { bridge: kind, format: "cli-anything-manifest" } }],
514
+ artifacts: { root: ".vibecode/artifacts", files: extractArtifactFiles(payload) },
515
+ invariants,
516
+ warnings
517
+ };
518
+ }
519
+ async function importBridge(kind, filePath, options = {}) {
520
+ if (!filePath || typeof filePath !== "string") {
521
+ throw new VibecodeError("TARGET_MISSING", `${kind} bridge requires --source <file.json>`);
522
+ }
523
+ const abs = path.resolve(options.cwd || process.cwd(), filePath);
524
+ const doc = loadJson(abs);
525
+ if (!isObject(doc)) {
526
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge file must contain a JSON object`);
527
+ }
528
+ const warnings = [];
529
+ let result;
530
+ if (looksLikeContractDoc(doc) && !options.forceManifest) {
531
+ try {
532
+ result = normalizePassThroughContract(doc, kind, warnings);
533
+ }
534
+ catch (err) {
535
+ // If it's contract-shaped but invalid as pass-through, try manifest conversion for rea/cli-anything
536
+ if (kind === "rea")
537
+ result = convertReaManifest(doc, kind, warnings);
538
+ else if (kind === "cli-anything")
539
+ result = convertCliAnythingManifest(doc, kind, warnings);
540
+ else
541
+ throw err;
542
+ }
543
+ }
544
+ else if (kind === "rea") {
545
+ result = convertReaManifest(doc, kind, warnings);
546
+ }
547
+ else if (kind === "cli-anything") {
548
+ result = convertCliAnythingManifest(doc, kind, warnings);
549
+ }
550
+ else {
551
+ throw new VibecodeError("BRIDGE_FORMAT_ERROR", `${kind} bridge file must contain invariants or contract.invariants`);
552
+ }
553
+ result.sources[0].ref = filePath;
554
+ result.warnings = warnings;
555
+ return result;
556
+ }
557
+ export async function importRea(filePath, options = {}) {
558
+ return importBridge("rea", filePath, options);
559
+ }
560
+ export async function importCliAnything(filePath, options = {}) {
561
+ return importBridge("cli-anything", filePath, options);
562
+ }
@@ -0,0 +1,9 @@
1
+ import type { IngestDeps, IngestOptions, IngestResult, JsonSchema } from "../core/types.js";
2
+ declare function parseHelpSubcommands(stdout: unknown): string[];
3
+ declare function synthesizeSchema(value: unknown): JsonSchema;
4
+ /**
5
+ * Safe sandboxed CLI auto-prober.
6
+ * Runs every probe inside a temporary directory — never the user's workspace.
7
+ */
8
+ export declare function ingest(options?: IngestOptions, deps?: IngestDeps): Promise<IngestResult>;
9
+ export { parseHelpSubcommands, synthesizeSchema };