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,207 @@
1
+ /**
2
+ * Output normalizers and diff utilities.
3
+ */
4
+ export function normalizeText(text, modes = []) {
5
+ let out = text == null ? "" : String(text);
6
+ for (const mode of modes) {
7
+ switch (mode) {
8
+ case "crlf":
9
+ out = out.replace(/\r\n/g, "\n");
10
+ break;
11
+ case "ansi":
12
+ // eslint-disable-next-line no-control-regex
13
+ out = out.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, "");
14
+ break;
15
+ case "timestamps":
16
+ // ISO-like timestamps, common log timestamps, unix-ish epoch ms
17
+ out = out.replace(/\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?/g, "<TS>");
18
+ out = out.replace(/\b\d{13}\b/g, "<TS_MS>");
19
+ break;
20
+ case "paths":
21
+ // Normalize Windows paths to POSIX-ish for comparison
22
+ out = out.replace(/[A-Za-z]:\\[^\s"']+/g, (m) => m.replace(/\\/g, "/"));
23
+ break;
24
+ case "trim":
25
+ out = out.trim();
26
+ break;
27
+ default:
28
+ break;
29
+ }
30
+ }
31
+ return out;
32
+ }
33
+ /**
34
+ * Simple LCS-based unified diff.
35
+ */
36
+ export function diffLines(expected, actual, { context = 2, maxLines = 40 } = {}) {
37
+ const exp = String(expected ?? "").replace(/\r\n/g, "\n").split("\n");
38
+ const act = String(actual ?? "").replace(/\r\n/g, "\n").split("\n");
39
+ // Trim trailing empty line caused by final newline for cleaner diffs
40
+ if (exp.length > 1 && exp[exp.length - 1] === "")
41
+ exp.pop();
42
+ if (act.length > 1 && act[act.length - 1] === "")
43
+ act.pop();
44
+ if (exp.length === act.length && exp.every((l, i) => l === act[i])) {
45
+ return { identical: true, added: 0, removed: 0, truncated: false, unified: "" };
46
+ }
47
+ const edits = lcsEdits(exp, act);
48
+ let added = 0;
49
+ let removed = 0;
50
+ for (const e of edits) {
51
+ if (e.type === "add")
52
+ added++;
53
+ if (e.type === "remove")
54
+ removed++;
55
+ }
56
+ // Build hunks with context
57
+ const changeIndices = [];
58
+ for (let i = 0; i < edits.length; i++) {
59
+ if (edits[i].type !== "equal")
60
+ changeIndices.push(i);
61
+ }
62
+ if (changeIndices.length === 0) {
63
+ return { identical: true, added: 0, removed: 0, truncated: false, unified: "" };
64
+ }
65
+ const ranges = [];
66
+ let start = Math.max(0, changeIndices[0] - context);
67
+ let end = Math.min(edits.length - 1, changeIndices[0] + context);
68
+ for (let k = 1; k < changeIndices.length; k++) {
69
+ const idx = changeIndices[k];
70
+ const s = Math.max(0, idx - context);
71
+ const e = Math.min(edits.length - 1, idx + context);
72
+ if (s <= end + 1)
73
+ end = e;
74
+ else {
75
+ ranges.push([start, end]);
76
+ start = s;
77
+ end = e;
78
+ }
79
+ }
80
+ ranges.push([start, end]);
81
+ const lines = ["--- expected", "+++ actual"];
82
+ let emitted = 0;
83
+ let truncated = false;
84
+ outer: for (const [s, e] of ranges) {
85
+ lines.push("@@");
86
+ for (let i = s; i <= e; i++) {
87
+ if (emitted >= maxLines) {
88
+ truncated = true;
89
+ break outer;
90
+ }
91
+ const edit = edits[i];
92
+ if (edit.type === "equal")
93
+ lines.push(" " + edit.line);
94
+ else if (edit.type === "remove")
95
+ lines.push("-" + edit.line);
96
+ else if (edit.type === "add")
97
+ lines.push("+" + edit.line);
98
+ emitted++;
99
+ }
100
+ }
101
+ if (truncated)
102
+ lines.push("... diff truncated ...");
103
+ return { identical: false, added, removed, truncated, unified: lines.join("\n") };
104
+ }
105
+ function lcsEdits(a, b) {
106
+ const n = a.length;
107
+ const m = b.length;
108
+ // Optimize for common case: small inputs; for larger, use Myers-like? N*M is fine for CLI output.
109
+ // Guard against very large outputs to avoid OOM
110
+ const MAX = 4000;
111
+ if (n > MAX || m > MAX) {
112
+ // Fallback: simple prefix/suffix diff
113
+ return simpleEdits(a, b);
114
+ }
115
+ const dp = new Array(n + 1);
116
+ for (let i = 0; i <= n; i++) {
117
+ dp[i] = new Uint16Array(m + 1);
118
+ }
119
+ for (let i = n - 1; i >= 0; i--) {
120
+ for (let j = m - 1; j >= 0; j--) {
121
+ if (a[i] === b[j])
122
+ dp[i][j] = dp[i + 1][j + 1] + 1;
123
+ else
124
+ dp[i][j] = Math.max(dp[i + 1][j], dp[i][j + 1]);
125
+ }
126
+ }
127
+ const edits = [];
128
+ let i = 0, j = 0;
129
+ while (i < n && j < m) {
130
+ if (a[i] === b[j]) {
131
+ edits.push({ type: "equal", line: a[i] });
132
+ i++;
133
+ j++;
134
+ }
135
+ else if (dp[i + 1][j] >= dp[i][j + 1]) {
136
+ edits.push({ type: "remove", line: a[i] });
137
+ i++;
138
+ }
139
+ else {
140
+ edits.push({ type: "add", line: b[j] });
141
+ j++;
142
+ }
143
+ }
144
+ while (i < n) {
145
+ edits.push({ type: "remove", line: a[i++] });
146
+ }
147
+ while (j < m) {
148
+ edits.push({ type: "add", line: b[j++] });
149
+ }
150
+ return edits;
151
+ }
152
+ function simpleEdits(a, b) {
153
+ const edits = [];
154
+ let prefix = 0;
155
+ while (prefix < a.length && prefix < b.length && a[prefix] === b[prefix])
156
+ prefix++;
157
+ let suffix = 0;
158
+ while (suffix < a.length - prefix && suffix < b.length - prefix && a[a.length - 1 - suffix] === b[b.length - 1 - suffix])
159
+ suffix++;
160
+ for (let i = 0; i < prefix; i++)
161
+ edits.push({ type: "equal", line: a[i] });
162
+ for (let i = prefix; i < a.length - suffix; i++)
163
+ edits.push({ type: "remove", line: a[i] });
164
+ for (let j = prefix; j < b.length - suffix; j++)
165
+ edits.push({ type: "add", line: b[j] });
166
+ for (let i = a.length - suffix; i < a.length; i++)
167
+ edits.push({ type: "equal", line: a[i] });
168
+ return edits;
169
+ }
170
+ export function diffJsonSubset(expectedSubset, actual, path = "$") {
171
+ const diffs = [];
172
+ walk(expectedSubset, actual, path, diffs);
173
+ return diffs;
174
+ }
175
+ function walk(exp, act, p, diffs) {
176
+ if (Array.isArray(exp)) {
177
+ if (!Array.isArray(act)) {
178
+ diffs.push({ path: p, expected: exp, actual: act });
179
+ return;
180
+ }
181
+ // subset semantics: each expected element must match by index
182
+ for (let i = 0; i < exp.length; i++) {
183
+ if (i >= act.length)
184
+ diffs.push({ path: `${p}[${i}]`, expected: exp[i], actual: undefined });
185
+ else
186
+ walk(exp[i], act[i], `${p}[${i}]`, diffs);
187
+ }
188
+ return;
189
+ }
190
+ if (exp && typeof exp === "object") {
191
+ if (!act || typeof act !== "object" || Array.isArray(act)) {
192
+ diffs.push({ path: p, expected: exp, actual: act });
193
+ return;
194
+ }
195
+ const expObj = exp;
196
+ const actObj = act;
197
+ for (const k of Object.keys(expObj)) {
198
+ if (!(k in actObj))
199
+ diffs.push({ path: `${p}.${k}`, expected: expObj[k], actual: undefined });
200
+ else
201
+ walk(expObj[k], actObj[k], `${p}.${k}`, diffs);
202
+ }
203
+ return;
204
+ }
205
+ if (exp !== act)
206
+ diffs.push({ path: p, expected: exp, actual: act });
207
+ }
@@ -0,0 +1,50 @@
1
+ import type { AdapterProbeResults, SetupScope } from "./types.js";
2
+ export type DoctorCheckStatus = "ok" | "warn" | "fail";
3
+ export interface DoctorCheck {
4
+ id: "node" | "playwright" | "ffmpeg" | "sharp" | "rea" | "cli-anything" | "mcp";
5
+ name: string;
6
+ required: boolean;
7
+ status: DoctorCheckStatus;
8
+ version?: string;
9
+ path?: string;
10
+ message: string;
11
+ installHint?: string;
12
+ fallbackHint?: string;
13
+ details?: Record<string, unknown>;
14
+ }
15
+ export interface DoctorOptions {
16
+ cwd?: string;
17
+ homeDir?: string;
18
+ scope?: SetupScope | string;
19
+ antigravityDir?: string;
20
+ strict?: boolean;
21
+ }
22
+ export interface BinaryProbeResult {
23
+ available: boolean;
24
+ path?: string;
25
+ version?: string;
26
+ error?: string;
27
+ }
28
+ export interface DoctorDeps {
29
+ nodeVersion?: string;
30
+ tsStrippingSupported?: boolean;
31
+ probeAdapters?: () => Promise<AdapterProbeResults>;
32
+ probeBinary?: (bin: string, args: readonly string[]) => BinaryProbeResult | Promise<BinaryProbeResult>;
33
+ }
34
+ export interface DoctorReport {
35
+ ok: boolean;
36
+ command: "doctor";
37
+ scope: SetupScope;
38
+ strict: boolean;
39
+ exitCode: number;
40
+ summary: {
41
+ total: number;
42
+ ok: number;
43
+ warn: number;
44
+ fail: number;
45
+ requiredFailed: number;
46
+ };
47
+ checks: DoctorCheck[];
48
+ }
49
+ /** Run all seven environment checks and produce a single doctor report. */
50
+ export declare function runDoctor(options?: DoctorOptions, deps?: DoctorDeps): Promise<DoctorReport>;
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Environment diagnostics for vibecode-anything v0.3.
3
+ *
4
+ * Reports required and optional capabilities with install/fallback hints so
5
+ * CLI and MCP callers can decide whether to degrade or stop. Zero runtime
6
+ * dependencies: Node.js built-ins only.
7
+ */
8
+ import { spawnSync } from "node:child_process";
9
+ import fs from "node:fs";
10
+ import os from "node:os";
11
+ import path from "node:path";
12
+ import { probeAdapters } from "./adapters.js";
13
+ import { VibecodeError, errorMessage } from "./errors.js";
14
+ const SERVER_ID = "vibecode-anything";
15
+ const VALID_SCOPES = new Set(["project", "global"]);
16
+ const NODE_INSTALL_HINT = "Install Node.js >= 20.0.0 (Node 24+ recommended for native TypeScript execution).";
17
+ const PLAYWRIGHT_FALLBACK = "Native HTTP fetch fallback still verifies web_route landmarks without Playwright.";
18
+ const FFMPEG_FALLBACK = "Ordered PNG keyframe directory input (with optional .srt/.vtt) still works without ffmpeg/ffprobe.";
19
+ const SHARP_FALLBACK = "Pure-Node built-in PNG decoder/encoder still verifies PNG images without sharp.";
20
+ const REA_INSTALL_HINT = "Install rea CLI on PATH or set VIBECODE_REA_PATH.";
21
+ const REA_FALLBACK = "Offline 'vibecode-anything ingest --domain rea --source <manifest.json>' still works without the rea binary.";
22
+ const CLI_ANYTHING_INSTALL_HINT = "Install cli-anything CLI on PATH or set VIBECODE_CLI_ANYTHING_PATH.";
23
+ const CLI_ANYTHING_FALLBACK = "Offline 'vibecode-anything ingest --domain cli-anything --source <spec.json>' still works without the cli-anything binary.";
24
+ const MCP_FALLBACK = "CLI commands (ingest/verify/watch/status/diff) work directly without MCP registration.";
25
+ function describeType(value) {
26
+ if (value === null)
27
+ return "null";
28
+ if (Array.isArray(value))
29
+ return "array";
30
+ return typeof value;
31
+ }
32
+ function firstNonEmptyLine(stdout, stderr) {
33
+ for (const source of [stdout, stderr]) {
34
+ for (const line of String(source ?? "").split(/\r?\n/)) {
35
+ const trimmed = line.trim();
36
+ if (trimmed)
37
+ return trimmed;
38
+ }
39
+ }
40
+ return undefined;
41
+ }
42
+ /** Probe a binary with --version, falling back to --help when it exits non-zero. */
43
+ function defaultProbeBinary(bin, args) {
44
+ const attempts = args.length > 0 ? [...args] : ["--version"];
45
+ if (!attempts.includes("--help"))
46
+ attempts.push("--help");
47
+ let lastError = "binary probe failed";
48
+ for (const arg of attempts) {
49
+ let res;
50
+ try {
51
+ const useShell = process.platform === "win32" && /\.(cmd|bat)$/i.test(bin);
52
+ res = spawnSync(bin, [arg], { encoding: "utf8", timeout: 5000, shell: useShell });
53
+ }
54
+ catch (err) {
55
+ return { available: false, error: errorMessage(err) };
56
+ }
57
+ if (res.error)
58
+ return { available: false, error: errorMessage(res.error) };
59
+ if (res.status !== 0) {
60
+ lastError = `${bin} ${arg} exited with code ${String(res.status)}`;
61
+ continue;
62
+ }
63
+ const version = firstNonEmptyLine(String(res.stdout ?? ""), String(res.stderr ?? ""));
64
+ return { available: true, path: bin, ...(version ? { version } : {}) };
65
+ }
66
+ return { available: false, error: lastError };
67
+ }
68
+ function parseMajor(version) {
69
+ const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
70
+ return match ? Number(match[1]) : null;
71
+ }
72
+ function nodeCheck(nodeVersion, tsStrippingSupported) {
73
+ const major = parseMajor(nodeVersion);
74
+ const nativeTypeScript = tsStrippingSupported ?? Boolean(process.features?.typescript);
75
+ const details = { version: nodeVersion, major, nativeTypeScript };
76
+ if (major === null || major < 20) {
77
+ return {
78
+ id: "node",
79
+ name: "Node.js",
80
+ required: true,
81
+ status: "fail",
82
+ message: `Node.js ${nodeVersion || "unknown"} does not meet the minimum required version 20.0.0.`,
83
+ installHint: NODE_INSTALL_HINT,
84
+ details
85
+ };
86
+ }
87
+ return {
88
+ id: "node",
89
+ name: "Node.js",
90
+ required: true,
91
+ status: "ok",
92
+ message: `Node.js ${nodeVersion} meets the minimum required version 20.0.0 (native TypeScript: ${nativeTypeScript ? "available" : "unavailable"}).`,
93
+ details
94
+ };
95
+ }
96
+ async function binaryCheck(id, name, envVar, defaultBin, installHint, fallbackHint, probe) {
97
+ const bin = process.env[envVar] || defaultBin;
98
+ let result;
99
+ try {
100
+ result = await probe(bin, ["--version"]);
101
+ }
102
+ catch (err) {
103
+ result = { available: false, error: errorMessage(err) };
104
+ }
105
+ const details = { binary: bin };
106
+ if (result.error)
107
+ details.error = result.error;
108
+ return {
109
+ id,
110
+ name,
111
+ required: false,
112
+ status: result.available ? "ok" : "warn",
113
+ message: result.available
114
+ ? `${name} CLI available at ${result.path || bin}${result.version ? ` (${result.version})` : ""}.`
115
+ : `${name} CLI was not found${result.error ? ` (${result.error})` : ""}.`,
116
+ ...(result.path ? { path: result.path } : result.available ? { path: bin } : {}),
117
+ ...(result.version ? { version: result.version } : {}),
118
+ ...(result.available ? {} : { installHint }),
119
+ fallbackHint,
120
+ details
121
+ };
122
+ }
123
+ /** Mirrors the exact client path layouts used by `vibecode-anything setup`. */
124
+ function clientLayouts(scope, cwd, homeDir, antigravityDir) {
125
+ const base = scope === "global" ? homeDir : cwd;
126
+ return [
127
+ {
128
+ client: "claude-code",
129
+ layout: {
130
+ mcpPath: scope === "global" ? path.join(homeDir, ".claude.json") : path.join(cwd, ".mcp.json"),
131
+ skillPath: path.join(base, ".claude", "skills", SERVER_ID, "SKILL.md")
132
+ }
133
+ },
134
+ {
135
+ client: "cursor",
136
+ layout: {
137
+ mcpPath: path.join(base, ".cursor", "mcp.json"),
138
+ skillPath: path.join(base, ".cursor", "skills", SERVER_ID, "SKILL.md")
139
+ }
140
+ },
141
+ {
142
+ client: "antigravity",
143
+ layout: {
144
+ mcpPath: antigravityDir
145
+ ? path.join(antigravityDir, "mcp_config.json")
146
+ : path.join(homeDir, ".gemini", "antigravity", "mcp_config.json"),
147
+ skillPath: scope === "global"
148
+ ? path.join(homeDir, ".gemini", "antigravity", "skills", SERVER_ID, "SKILL.md")
149
+ : path.join(cwd, ".agents", "skills", SERVER_ID, "SKILL.md")
150
+ }
151
+ }
152
+ ];
153
+ }
154
+ function inspectMcp(scope, cwd, homeDir, antigravityDir) {
155
+ const clients = [];
156
+ const errors = [];
157
+ let registeredCount = 0;
158
+ for (const { client, layout } of clientLayouts(scope, cwd, homeDir, antigravityDir)) {
159
+ const detail = {
160
+ client,
161
+ mcpPath: layout.mcpPath,
162
+ skillPath: layout.skillPath,
163
+ mcpExists: false,
164
+ registered: false,
165
+ skillInstalled: false
166
+ };
167
+ try {
168
+ if (fs.existsSync(layout.mcpPath)) {
169
+ detail.mcpExists = true;
170
+ if (fs.statSync(layout.mcpPath).isDirectory()) {
171
+ detail.error = `${client}: ${layout.mcpPath} is a directory, expected a JSON file.`;
172
+ }
173
+ else {
174
+ const text = fs.readFileSync(layout.mcpPath, "utf8");
175
+ if (text.trim()) {
176
+ let parsed;
177
+ try {
178
+ parsed = JSON.parse(text);
179
+ }
180
+ catch (err) {
181
+ detail.error = `${client}: invalid JSON in ${layout.mcpPath} (${errorMessage(err)}).`;
182
+ }
183
+ if (!detail.error) {
184
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
185
+ detail.error = `${client}: ${layout.mcpPath} must contain a top-level JSON object, found ${describeType(parsed)}.`;
186
+ }
187
+ else {
188
+ const servers = parsed.mcpServers;
189
+ if (servers !== undefined && (!servers || typeof servers !== "object" || Array.isArray(servers))) {
190
+ detail.error = `${client}: "mcpServers" in ${layout.mcpPath} must be a JSON object, found ${describeType(servers)}.`;
191
+ }
192
+ else if (servers && typeof servers === "object") {
193
+ detail.registered = Boolean(servers[SERVER_ID]);
194
+ }
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ catch (err) {
202
+ detail.error = `${client}: could not inspect ${layout.mcpPath} (${errorMessage(err)}).`;
203
+ }
204
+ try {
205
+ detail.skillInstalled = fs.existsSync(layout.skillPath) && fs.statSync(layout.skillPath).isFile();
206
+ }
207
+ catch {
208
+ detail.skillInstalled = false;
209
+ }
210
+ if (detail.registered)
211
+ registeredCount++;
212
+ if (detail.error)
213
+ errors.push(detail.error);
214
+ clients.push(detail);
215
+ }
216
+ const base = { id: "mcp", name: "MCP registration", required: false, details: { clients } };
217
+ if (errors.length > 0) {
218
+ return {
219
+ ...base,
220
+ status: "fail",
221
+ message: `MCP configuration errors: ${errors.join(" ")}`,
222
+ installHint: `Fix the MCP configuration errors or re-run vibecode-anything setup --clients auto --scope ${scope}.`,
223
+ fallbackHint: MCP_FALLBACK
224
+ };
225
+ }
226
+ if (registeredCount > 0) {
227
+ return { ...base, status: "ok", message: `MCP registered for ${registeredCount}/${clients.length} client(s)` };
228
+ }
229
+ return {
230
+ ...base,
231
+ status: "warn",
232
+ message: "MCP is not registered for any supported client.",
233
+ installHint: `vibecode-anything setup --clients auto --scope ${scope}`,
234
+ fallbackHint: MCP_FALLBACK
235
+ };
236
+ }
237
+ /** Run all seven environment checks and produce a single doctor report. */
238
+ export async function runDoctor(options = {}, deps = {}) {
239
+ const scopeInput = options.scope ?? "project";
240
+ if (!VALID_SCOPES.has(scopeInput)) {
241
+ throw new VibecodeError("CONTRACT_INVALID", `scope must be one of ${[...VALID_SCOPES].join(", ")} (got "${scopeInput}"). Pass --scope project or --scope global.`);
242
+ }
243
+ const scope = scopeInput;
244
+ const strict = Boolean(options.strict);
245
+ const cwd = options.cwd ?? process.cwd();
246
+ const homeDir = options.homeDir ?? os.homedir();
247
+ const adapters = deps.probeAdapters ? await deps.probeAdapters() : await probeAdapters();
248
+ const probe = deps.probeBinary ?? defaultProbeBinary;
249
+ const pw = adapters.playwright;
250
+ const ffmpegMissing = [];
251
+ if (!adapters.ffmpeg.available)
252
+ ffmpegMissing.push("ffmpeg");
253
+ if (!adapters.ffprobe.available)
254
+ ffmpegMissing.push("ffprobe");
255
+ const ffmpegHints = [
256
+ !adapters.ffmpeg.available ? adapters.ffmpeg.installHint : "",
257
+ !adapters.ffprobe.available ? adapters.ffprobe.installHint : ""
258
+ ].filter(Boolean);
259
+ const checks = [
260
+ nodeCheck(deps.nodeVersion ?? process.versions.node, deps.tsStrippingSupported),
261
+ {
262
+ id: "playwright",
263
+ name: "Playwright",
264
+ required: false,
265
+ status: pw.available ? "ok" : "warn",
266
+ message: pw.available
267
+ ? `Playwright available${pw.version ? ` (${pw.version})` : ""}.`
268
+ : "Playwright is not available; web_route landmarks fall back to native HTTP fetch.",
269
+ ...(pw.version ? { version: pw.version } : {}),
270
+ ...(pw.path ? { path: pw.path } : {}),
271
+ ...(pw.available ? {} : { installHint: pw.installHint }),
272
+ fallbackHint: PLAYWRIGHT_FALLBACK
273
+ },
274
+ {
275
+ id: "ffmpeg",
276
+ name: "ffmpeg / ffprobe",
277
+ required: false,
278
+ status: ffmpegMissing.length === 0 ? "ok" : "warn",
279
+ message: ffmpegMissing.length === 0
280
+ ? "ffmpeg and ffprobe are available."
281
+ : `Missing video adapter binaries: ${ffmpegMissing.join(", ")}.`,
282
+ ...(ffmpegMissing.length === 0 ? {} : { installHint: ffmpegHints.join(" ") }),
283
+ fallbackHint: FFMPEG_FALLBACK,
284
+ details: { ffmpeg: adapters.ffmpeg, ffprobe: adapters.ffprobe }
285
+ },
286
+ {
287
+ id: "sharp",
288
+ name: "sharp",
289
+ required: false,
290
+ status: adapters.sharp.available ? "ok" : "warn",
291
+ message: adapters.sharp.available
292
+ ? `sharp available${adapters.sharp.version ? ` (${adapters.sharp.version})` : ""}.`
293
+ : "sharp is not available; PNG parsing falls back to the pure-Node decoder.",
294
+ ...(adapters.sharp.version ? { version: adapters.sharp.version } : {}),
295
+ ...(adapters.sharp.path ? { path: adapters.sharp.path } : {}),
296
+ ...(adapters.sharp.available ? {} : { installHint: adapters.sharp.installHint }),
297
+ fallbackHint: SHARP_FALLBACK
298
+ },
299
+ await binaryCheck("rea", "rea", "VIBECODE_REA_PATH", "rea", REA_INSTALL_HINT, REA_FALLBACK, probe),
300
+ await binaryCheck("cli-anything", "cli-anything", "VIBECODE_CLI_ANYTHING_PATH", "cli-anything", CLI_ANYTHING_INSTALL_HINT, CLI_ANYTHING_FALLBACK, probe),
301
+ inspectMcp(scope, cwd, homeDir, options.antigravityDir)
302
+ ];
303
+ const summary = {
304
+ total: checks.length,
305
+ ok: checks.filter((check) => check.status === "ok").length,
306
+ warn: checks.filter((check) => check.status === "warn").length,
307
+ fail: checks.filter((check) => check.status === "fail").length,
308
+ requiredFailed: checks.filter((check) => check.required && check.status === "fail").length
309
+ };
310
+ const exitCode = summary.fail > 0 || summary.requiredFailed > 0 || (strict && summary.warn > 0) ? 1 : 0;
311
+ return { ok: exitCode === 0, command: "doctor", scope, strict, exitCode, summary, checks };
312
+ }
@@ -0,0 +1,32 @@
1
+ import type { Diagnostic, VibecodeErrorOptions } from "./types.js";
2
+ /**
3
+ * Structured error envelope shared by every vibecode-anything module.
4
+ *
5
+ * Every module throws (or returns) diagnostics shaped like:
6
+ * { code, message, adapter?, installHint?, fallbackHint?, details? }
7
+ */
8
+ export declare class VibecodeError extends Error {
9
+ readonly code: string;
10
+ readonly adapter?: string;
11
+ readonly installHint?: string;
12
+ readonly fallbackHint?: string;
13
+ readonly details?: unknown;
14
+ constructor(code: string, message: string, options?: VibecodeErrorOptions);
15
+ toJSON(): Diagnostic;
16
+ }
17
+ export declare const ERROR_CODES: Readonly<{
18
+ readonly CONTRACT_INVALID: "CONTRACT_INVALID";
19
+ readonly CONTRACT_NOT_FOUND: "CONTRACT_NOT_FOUND";
20
+ readonly ADAPTER_MISSING: "ADAPTER_MISSING";
21
+ readonly ADAPTER_DEGRADED: "ADAPTER_DEGRADED";
22
+ readonly TARGET_MISSING: "TARGET_MISSING";
23
+ readonly EXEC_TIMEOUT: "EXEC_TIMEOUT";
24
+ readonly UNSUPPORTED_FORMAT: "UNSUPPORTED_FORMAT";
25
+ readonly BRIDGE_FORMAT_ERROR: "BRIDGE_FORMAT_ERROR";
26
+ }>;
27
+ /** Extract a human-readable message from an unknown thrown value. */
28
+ export declare function errorMessage(error: unknown): string;
29
+ /** Extract an error code property from an unknown thrown value, if present. */
30
+ export declare function errorCode(error: unknown): string | undefined;
31
+ /** Serialize any thrown value into the standard diagnostic envelope. */
32
+ export declare function toDiagnostic(error: unknown): Diagnostic;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Structured error envelope shared by every vibecode-anything module.
3
+ *
4
+ * Every module throws (or returns) diagnostics shaped like:
5
+ * { code, message, adapter?, installHint?, fallbackHint?, details? }
6
+ */
7
+ export class VibecodeError extends Error {
8
+ code;
9
+ adapter;
10
+ installHint;
11
+ fallbackHint;
12
+ details;
13
+ constructor(code, message, options = {}) {
14
+ super(message);
15
+ this.name = "VibecodeError";
16
+ this.code = code;
17
+ if (options.adapter)
18
+ this.adapter = options.adapter;
19
+ if (options.installHint)
20
+ this.installHint = options.installHint;
21
+ if (options.fallbackHint)
22
+ this.fallbackHint = options.fallbackHint;
23
+ if (options.details !== undefined)
24
+ this.details = options.details;
25
+ }
26
+ toJSON() {
27
+ return {
28
+ code: this.code,
29
+ message: this.message,
30
+ ...(this.adapter ? { adapter: this.adapter } : {}),
31
+ ...(this.installHint ? { installHint: this.installHint } : {}),
32
+ ...(this.fallbackHint ? { fallbackHint: this.fallbackHint } : {}),
33
+ ...(this.details !== undefined ? { details: this.details } : {})
34
+ };
35
+ }
36
+ }
37
+ export const ERROR_CODES = Object.freeze({
38
+ CONTRACT_INVALID: "CONTRACT_INVALID",
39
+ CONTRACT_NOT_FOUND: "CONTRACT_NOT_FOUND",
40
+ ADAPTER_MISSING: "ADAPTER_MISSING",
41
+ ADAPTER_DEGRADED: "ADAPTER_DEGRADED",
42
+ TARGET_MISSING: "TARGET_MISSING",
43
+ EXEC_TIMEOUT: "EXEC_TIMEOUT",
44
+ UNSUPPORTED_FORMAT: "UNSUPPORTED_FORMAT",
45
+ BRIDGE_FORMAT_ERROR: "BRIDGE_FORMAT_ERROR"
46
+ });
47
+ /** Extract a human-readable message from an unknown thrown value. */
48
+ export function errorMessage(error) {
49
+ if (error instanceof Error)
50
+ return error.message;
51
+ if (error && typeof error === "object" && "message" in error) {
52
+ const msg = error.message;
53
+ if (typeof msg === "string")
54
+ return msg;
55
+ }
56
+ return String(error);
57
+ }
58
+ /** Extract an error code property from an unknown thrown value, if present. */
59
+ export function errorCode(error) {
60
+ if (error && typeof error === "object" && "code" in error) {
61
+ const code = error.code;
62
+ if (typeof code === "string")
63
+ return code;
64
+ }
65
+ return undefined;
66
+ }
67
+ /** Serialize any thrown value into the standard diagnostic envelope. */
68
+ export function toDiagnostic(error) {
69
+ if (error instanceof VibecodeError)
70
+ return error.toJSON();
71
+ if (error && typeof error === "object" && "message" in error) {
72
+ const rec = error;
73
+ if (typeof rec.message === "string") {
74
+ return {
75
+ code: typeof rec.code === "string" && rec.code ? rec.code : "INTERNAL_ERROR",
76
+ message: rec.message
77
+ };
78
+ }
79
+ }
80
+ return { code: "INTERNAL_ERROR", message: String(error) };
81
+ }