vibecode-anything 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +407 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2519 -0
- package/dist/core/adapters.d.ts +31 -0
- package/dist/core/adapters.js +478 -0
- package/dist/core/agent-adapter.d.ts +67 -0
- package/dist/core/agent-adapter.js +312 -0
- package/dist/core/anti-cheat.d.ts +6 -0
- package/dist/core/anti-cheat.js +372 -0
- package/dist/core/badge.d.ts +18 -0
- package/dist/core/badge.js +360 -0
- package/dist/core/cache.d.ts +47 -0
- package/dist/core/cache.js +403 -0
- package/dist/core/ci-export.d.ts +35 -0
- package/dist/core/ci-export.js +796 -0
- package/dist/core/ci-formats.d.ts +21 -0
- package/dist/core/ci-formats.js +388 -0
- package/dist/core/client-codegen.d.ts +36 -0
- package/dist/core/client-codegen.js +2538 -0
- package/dist/core/compose.d.ts +71 -0
- package/dist/core/compose.js +1088 -0
- package/dist/core/diff.d.ts +10 -0
- package/dist/core/diff.js +207 -0
- package/dist/core/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +70 -0
- package/dist/core/doctor.js +525 -0
- package/dist/core/errors.d.ts +32 -0
- package/dist/core/errors.js +81 -0
- package/dist/core/exec.d.ts +38 -0
- package/dist/core/exec.js +336 -0
- package/dist/core/fixtures.d.ts +153 -0
- package/dist/core/fixtures.js +2245 -0
- package/dist/core/format.d.ts +77 -0
- package/dist/core/format.js +632 -0
- package/dist/core/fs-snapshot.d.ts +37 -0
- package/dist/core/fs-snapshot.js +216 -0
- package/dist/core/graphql-export.d.ts +34 -0
- package/dist/core/graphql-export.js +2482 -0
- package/dist/core/har-export.d.ts +29 -0
- package/dist/core/har-export.js +988 -0
- package/dist/core/html-report.d.ts +27 -0
- package/dist/core/html-report.js +1535 -0
- package/dist/core/http-export.d.ts +31 -0
- package/dist/core/http-export.js +726 -0
- package/dist/core/impact.d.ts +80 -0
- package/dist/core/impact.js +1412 -0
- package/dist/core/lint.d.ts +38 -0
- package/dist/core/lint.js +1111 -0
- package/dist/core/load-export.d.ts +37 -0
- package/dist/core/load-export.js +1813 -0
- package/dist/core/mcp-export.d.ts +35 -0
- package/dist/core/mcp-export.js +1736 -0
- package/dist/core/mock-server.d.ts +47 -0
- package/dist/core/mock-server.js +1722 -0
- package/dist/core/openapi-export.d.ts +44 -0
- package/dist/core/openapi-export.js +1074 -0
- package/dist/core/parity.d.ts +14 -0
- package/dist/core/parity.js +173 -0
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.d.ts +7 -0
- package/dist/core/png.js +339 -0
- package/dist/core/regression.d.ts +54 -0
- package/dist/core/regression.js +529 -0
- package/dist/core/responsive.d.ts +86 -0
- package/dist/core/responsive.js +606 -0
- package/dist/core/run.d.ts +74 -0
- package/dist/core/run.js +696 -0
- package/dist/core/scheduler.d.ts +24 -0
- package/dist/core/scheduler.js +162 -0
- package/dist/core/schema-export.d.ts +29 -0
- package/dist/core/schema-export.js +2215 -0
- package/dist/core/schema.d.ts +18 -0
- package/dist/core/schema.js +1057 -0
- package/dist/core/security.d.ts +233 -0
- package/dist/core/security.js +1839 -0
- package/dist/core/server-export.d.ts +38 -0
- package/dist/core/server-export.js +3198 -0
- package/dist/core/slices.d.ts +24 -0
- package/dist/core/slices.js +294 -0
- package/dist/core/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +26 -0
- package/dist/core/store.js +217 -0
- package/dist/core/target-map.d.ts +34 -0
- package/dist/core/target-map.js +262 -0
- package/dist/core/test-exporter.d.ts +25 -0
- package/dist/core/test-exporter.js +1918 -0
- package/dist/core/types.d.ts +919 -0
- package/dist/core/types.js +4 -0
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.d.ts +34 -0
- package/dist/core/visual.js +508 -0
- package/dist/core/watch.d.ts +78 -0
- package/dist/core/watch.js +495 -0
- package/dist/core/yaml.d.ts +5 -0
- package/dist/core/yaml.js +1009 -0
- package/dist/diagnostics/diagnose.d.ts +53 -0
- package/dist/diagnostics/diagnose.js +1083 -0
- package/dist/diagnostics/flake.d.ts +71 -0
- package/dist/diagnostics/flake.js +608 -0
- package/dist/diagnostics/mutation-audit.d.ts +69 -0
- package/dist/diagnostics/mutation-audit.js +769 -0
- package/dist/diagnostics/spatial.d.ts +42 -0
- package/dist/diagnostics/spatial.js +346 -0
- package/dist/diagnostics/trends.d.ts +122 -0
- package/dist/diagnostics/trends.js +1190 -0
- package/dist/discovery/discover.d.ts +111 -0
- package/dist/discovery/discover.js +2017 -0
- package/dist/discovery/lock.d.ts +116 -0
- package/dist/discovery/lock.js +1505 -0
- package/dist/discovery/routes.d.ts +36 -0
- package/dist/discovery/routes.js +1494 -0
- package/dist/discovery/test-importer.d.ts +92 -0
- package/dist/discovery/test-importer.js +4952 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +99 -0
- package/dist/ingestors/api-collections.d.ts +28 -0
- package/dist/ingestors/api-collections.js +2335 -0
- package/dist/ingestors/api-repo.d.ts +6 -0
- package/dist/ingestors/api-repo.js +1120 -0
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +5 -0
- package/dist/ingestors/bridges.js +1264 -0
- package/dist/ingestors/cli.d.ts +10 -0
- package/dist/ingestors/cli.js +454 -0
- package/dist/ingestors/curl.d.ts +14 -0
- package/dist/ingestors/curl.js +1024 -0
- package/dist/ingestors/graphql.d.ts +56 -0
- package/dist/ingestors/graphql.js +1852 -0
- package/dist/ingestors/http-file.d.ts +20 -0
- package/dist/ingestors/http-file.js +923 -0
- package/dist/ingestors/image.d.ts +2 -0
- package/dist/ingestors/image.js +147 -0
- package/dist/ingestors/index.d.ts +5 -0
- package/dist/ingestors/index.js +577 -0
- package/dist/ingestors/openrpc.d.ts +29 -0
- package/dist/ingestors/openrpc.js +1807 -0
- package/dist/ingestors/proto.d.ts +47 -0
- package/dist/ingestors/proto.js +2690 -0
- package/dist/ingestors/trace.d.ts +10 -0
- package/dist/ingestors/trace.js +599 -0
- package/dist/ingestors/video.d.ts +50 -0
- package/dist/ingestors/video.js +655 -0
- package/dist/ingestors/web.d.ts +40 -0
- package/dist/ingestors/web.js +839 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +3969 -0
- package/dist/oracles/api-repo.d.ts +2 -0
- package/dist/oracles/api-repo.js +286 -0
- package/dist/oracles/cli.d.ts +2 -0
- package/dist/oracles/cli.js +205 -0
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.d.ts +2 -0
- package/dist/oracles/image.js +429 -0
- package/dist/oracles/index.d.ts +6 -0
- package/dist/oracles/index.js +320 -0
- package/dist/oracles/perf-budget.d.ts +90 -0
- package/dist/oracles/perf-budget.js +1329 -0
- package/dist/oracles/stream.d.ts +94 -0
- package/dist/oracles/stream.js +1268 -0
- package/dist/oracles/ui-states.d.ts +49 -0
- package/dist/oracles/ui-states.js +894 -0
- package/dist/oracles/video.d.ts +21 -0
- package/dist/oracles/video.js +627 -0
- package/dist/oracles/web.d.ts +2 -0
- package/dist/oracles/web.js +871 -0
- package/dist/plugins/builtins.d.ts +12 -0
- package/dist/plugins/builtins.js +1052 -0
- package/dist/plugins/registry.d.ts +86 -0
- package/dist/plugins/registry.js +554 -0
- package/dist/setup/index.d.ts +7 -0
- package/dist/setup/index.js +298 -0
- package/package.json +54 -4
- package/skills/vibecode-anything/SKILL.md +75 -0
|
@@ -0,0 +1,1120 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { VibecodeError, errorMessage } from "../core/errors.js";
|
|
4
|
+
import { parseYaml } from "../core/yaml.js";
|
|
5
|
+
import { mergeHeaders, redactHeaders } from "./trace.js";
|
|
6
|
+
function isObject(v) {
|
|
7
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
8
|
+
}
|
|
9
|
+
function asArray(v) {
|
|
10
|
+
return Array.isArray(v) ? v : [];
|
|
11
|
+
}
|
|
12
|
+
function synthesizeSchema(value) {
|
|
13
|
+
if (value === null)
|
|
14
|
+
return { type: "null" };
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return { type: "array", items: value.length ? synthesizeSchema(value[0]) : {} };
|
|
17
|
+
if (isObject(value)) {
|
|
18
|
+
const properties = {};
|
|
19
|
+
for (const [k, v] of Object.entries(value))
|
|
20
|
+
properties[k] = synthesizeSchema(v);
|
|
21
|
+
return { type: "object", required: Object.keys(value), properties };
|
|
22
|
+
}
|
|
23
|
+
if (Number.isInteger(value))
|
|
24
|
+
return { type: "integer" };
|
|
25
|
+
return { type: typeof value };
|
|
26
|
+
}
|
|
27
|
+
async function fetchJson(url, { method = "GET", headers = {}, body, timeoutMs = 10000 } = {}) {
|
|
28
|
+
const ctrl = new AbortController();
|
|
29
|
+
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
30
|
+
try {
|
|
31
|
+
const res = await fetch(url, {
|
|
32
|
+
method,
|
|
33
|
+
headers,
|
|
34
|
+
body: body === undefined || body === null ? undefined : (typeof body === "string" ? body : JSON.stringify(body)),
|
|
35
|
+
signal: ctrl.signal
|
|
36
|
+
});
|
|
37
|
+
const text = await res.text();
|
|
38
|
+
let json = null;
|
|
39
|
+
try {
|
|
40
|
+
json = text ? JSON.parse(text) : null;
|
|
41
|
+
}
|
|
42
|
+
catch { /* ignore */ }
|
|
43
|
+
const headersObj = {};
|
|
44
|
+
for (const [k, v] of res.headers.entries())
|
|
45
|
+
headersObj[k.toLowerCase()] = v;
|
|
46
|
+
return { status: res.status, headers: headersObj, text, json };
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
clearTimeout(t);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function normalizeEndpoint(ep) {
|
|
53
|
+
if (typeof ep === "string")
|
|
54
|
+
return { method: "GET", path: ep, headers: {}, body: null, explicit: true };
|
|
55
|
+
if (!ep || typeof ep !== "object" || Array.isArray(ep))
|
|
56
|
+
return null;
|
|
57
|
+
const method = String(ep.method || "GET").toUpperCase();
|
|
58
|
+
const p = String(ep.path || ep.url || "/");
|
|
59
|
+
const pathOnly = /^https?:\/\//i.test(p) ? new URL(p).pathname + new URL(p).search : p;
|
|
60
|
+
const headers = {};
|
|
61
|
+
if (isObject(ep.headers)) {
|
|
62
|
+
for (const [k, v] of Object.entries(ep.headers))
|
|
63
|
+
headers[k] = String(v);
|
|
64
|
+
}
|
|
65
|
+
const query = isObject(ep.query) ? ep.query : undefined;
|
|
66
|
+
return {
|
|
67
|
+
id: typeof ep.id === "string" ? ep.id : undefined,
|
|
68
|
+
method,
|
|
69
|
+
path: pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`,
|
|
70
|
+
headers,
|
|
71
|
+
query,
|
|
72
|
+
body: ep.body ?? null,
|
|
73
|
+
expectedStatus: ep.expectedStatus,
|
|
74
|
+
jsonSchema: isObject(ep.jsonSchema) ? ep.jsonSchema : undefined,
|
|
75
|
+
jsonPaths: Array.isArray(ep.jsonPaths) ? ep.jsonPaths : undefined,
|
|
76
|
+
explicit: true
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function buildApiUrl(base, p, query) {
|
|
80
|
+
const baseUrl = /^https?:\/\//i.test(base) ? base : `http://${base}`;
|
|
81
|
+
const baseObj = new URL(baseUrl);
|
|
82
|
+
let url;
|
|
83
|
+
if (/^https?:\/\//i.test(p)) {
|
|
84
|
+
url = new URL(p);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const pathPart = String(p || "/");
|
|
88
|
+
if (pathPart.startsWith("/")) {
|
|
89
|
+
const basePath = baseObj.pathname.replace(/\/$/, "");
|
|
90
|
+
const merged = `${basePath}${pathPart}` || "/";
|
|
91
|
+
url = new URL(baseObj.origin);
|
|
92
|
+
url.pathname = merged.startsWith("/") ? merged : `/${merged}`;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
url = new URL(pathPart, baseObj);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (isObject(query)) {
|
|
99
|
+
for (const [k, v] of Object.entries(query)) {
|
|
100
|
+
if (v !== undefined && v !== null)
|
|
101
|
+
url.searchParams.set(k, String(v));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return url.toString();
|
|
105
|
+
}
|
|
106
|
+
function slugify(text, fallback = "root") {
|
|
107
|
+
const s = String(text || "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
108
|
+
return s || fallback;
|
|
109
|
+
}
|
|
110
|
+
function uniqueId(base, used) {
|
|
111
|
+
let id = base.startsWith("inv-") ? base : `inv-${base}`;
|
|
112
|
+
id = slugify(id.replace(/^inv-/, ""), "api");
|
|
113
|
+
id = `inv-${id}`;
|
|
114
|
+
if (!used.has(id)) {
|
|
115
|
+
used.add(id);
|
|
116
|
+
return id;
|
|
117
|
+
}
|
|
118
|
+
let n = 2;
|
|
119
|
+
while (used.has(`${id}-${n}`))
|
|
120
|
+
n++;
|
|
121
|
+
const out = `${id}-${n}`;
|
|
122
|
+
used.add(out);
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
function decodeJsonPointerSegment(seg) {
|
|
126
|
+
return seg.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
127
|
+
}
|
|
128
|
+
function resolveJsonPointer(doc, ref) {
|
|
129
|
+
if (typeof ref !== "string" || !ref.startsWith("#/"))
|
|
130
|
+
return undefined;
|
|
131
|
+
const parts = ref.slice(2).split("/").map(decodeJsonPointerSegment);
|
|
132
|
+
let cur = doc;
|
|
133
|
+
for (const p of parts) {
|
|
134
|
+
if (cur === null || cur === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
if (Array.isArray(cur)) {
|
|
137
|
+
const idx = Number(p);
|
|
138
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= cur.length)
|
|
139
|
+
return undefined;
|
|
140
|
+
cur = cur[idx];
|
|
141
|
+
}
|
|
142
|
+
else if (isObject(cur)) {
|
|
143
|
+
if (!(p in cur))
|
|
144
|
+
return undefined;
|
|
145
|
+
cur = cur[p];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return cur;
|
|
152
|
+
}
|
|
153
|
+
function mergeSchemas(base, extra) {
|
|
154
|
+
if (!isObject(base))
|
|
155
|
+
return isObject(extra) ? extra : {};
|
|
156
|
+
if (!isObject(extra))
|
|
157
|
+
return base;
|
|
158
|
+
const out = { ...base, ...extra };
|
|
159
|
+
// merge required
|
|
160
|
+
const req = [...new Set([...(Array.isArray(base.required) ? base.required.map(String) : []), ...(Array.isArray(extra.required) ? extra.required.map(String) : [])])];
|
|
161
|
+
if (req.length)
|
|
162
|
+
out.required = req;
|
|
163
|
+
// merge properties
|
|
164
|
+
if (isObject(base.properties) || isObject(extra.properties)) {
|
|
165
|
+
out.properties = { ...(isObject(base.properties) ? base.properties : {}), ...(isObject(extra.properties) ? extra.properties : {}) };
|
|
166
|
+
}
|
|
167
|
+
// merge items shallowly if both objects
|
|
168
|
+
if (isObject(base.items) && isObject(extra.items))
|
|
169
|
+
out.items = mergeSchemas(base.items, extra.items);
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
function resolveSchema(schema, doc, stack = [], memo = new Map()) {
|
|
173
|
+
if (!isObject(schema) && !Array.isArray(schema))
|
|
174
|
+
return schema;
|
|
175
|
+
if (Array.isArray(schema))
|
|
176
|
+
return schema.map((v) => resolveSchema(v, doc, stack, memo));
|
|
177
|
+
if (typeof schema.$ref === "string") {
|
|
178
|
+
const ref = schema.$ref;
|
|
179
|
+
if (stack.includes(ref))
|
|
180
|
+
return { $ref: ref };
|
|
181
|
+
if (memo.has(ref)) {
|
|
182
|
+
// cycle-safe: return memoized shallow result; if not ready, return ref marker
|
|
183
|
+
return memo.get(ref) || { $ref: ref };
|
|
184
|
+
}
|
|
185
|
+
const target = resolveJsonPointer(doc, ref);
|
|
186
|
+
if (target === undefined)
|
|
187
|
+
return { $ref: ref };
|
|
188
|
+
memo.set(ref, null);
|
|
189
|
+
const resolvedTarget = resolveSchema(target, doc, [...stack, ref], memo);
|
|
190
|
+
const sibling = { ...schema };
|
|
191
|
+
delete sibling.$ref;
|
|
192
|
+
const merged = Object.keys(sibling).length
|
|
193
|
+
? mergeSchemas(resolvedTarget, resolveSchema(sibling, doc, stack, memo))
|
|
194
|
+
: (isObject(resolvedTarget) ? resolvedTarget : { value: resolvedTarget });
|
|
195
|
+
memo.set(ref, merged);
|
|
196
|
+
return merged;
|
|
197
|
+
}
|
|
198
|
+
if (Array.isArray(schema.allOf)) {
|
|
199
|
+
let merged = {};
|
|
200
|
+
for (const part of schema.allOf) {
|
|
201
|
+
merged = mergeSchemas(merged, resolveSchema(part, doc, stack, memo));
|
|
202
|
+
}
|
|
203
|
+
const rest = { ...schema };
|
|
204
|
+
delete rest.allOf;
|
|
205
|
+
const resolvedRest = resolveSchema(rest, doc, stack, memo);
|
|
206
|
+
return mergeSchemas(merged, isObject(resolvedRest) ? resolvedRest : {});
|
|
207
|
+
}
|
|
208
|
+
const out = {};
|
|
209
|
+
for (const [k, v] of Object.entries(schema)) {
|
|
210
|
+
if (k === "properties" && isObject(v)) {
|
|
211
|
+
const props = {};
|
|
212
|
+
for (const [pk, pv] of Object.entries(v))
|
|
213
|
+
props[pk] = resolveSchema(pv, doc, stack, memo);
|
|
214
|
+
out[k] = props;
|
|
215
|
+
}
|
|
216
|
+
else if (k === "items") {
|
|
217
|
+
out[k] = resolveSchema(v, doc, stack, memo);
|
|
218
|
+
}
|
|
219
|
+
else if (k === "additionalProperties" && isObject(v)) {
|
|
220
|
+
out[k] = resolveSchema(v, doc, stack, memo);
|
|
221
|
+
}
|
|
222
|
+
else if (k === "not" && isObject(v)) {
|
|
223
|
+
out[k] = resolveSchema(v, doc, stack, memo);
|
|
224
|
+
}
|
|
225
|
+
else if ((k === "anyOf" || k === "oneOf") && Array.isArray(v)) {
|
|
226
|
+
out[k] = v.map((x) => resolveSchema(x, doc, stack, memo));
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
out[k] = v;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
function resolveSchemaObject(schema, doc) {
|
|
235
|
+
const resolved = resolveSchema(schema, doc);
|
|
236
|
+
return isObject(resolved) ? resolved : undefined;
|
|
237
|
+
}
|
|
238
|
+
function pickParamValue(param) {
|
|
239
|
+
if (!isObject(param))
|
|
240
|
+
return undefined;
|
|
241
|
+
if (param.example !== undefined)
|
|
242
|
+
return param.example;
|
|
243
|
+
if (isObject(param.examples)) {
|
|
244
|
+
for (const ex of Object.values(param.examples)) {
|
|
245
|
+
if (isObject(ex) && ex.value !== undefined)
|
|
246
|
+
return ex.value;
|
|
247
|
+
if (ex !== undefined)
|
|
248
|
+
return ex;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const schema = isObject(param.schema) ? param.schema : param;
|
|
252
|
+
if (schema.example !== undefined)
|
|
253
|
+
return schema.example;
|
|
254
|
+
if (schema.default !== undefined)
|
|
255
|
+
return schema.default;
|
|
256
|
+
if (Array.isArray(schema.enum) && schema.enum.length)
|
|
257
|
+
return schema.enum[0];
|
|
258
|
+
const t = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
259
|
+
if (t === "integer" || t === "number")
|
|
260
|
+
return 1;
|
|
261
|
+
if (t === "boolean")
|
|
262
|
+
return true;
|
|
263
|
+
return "sample";
|
|
264
|
+
}
|
|
265
|
+
function substitutePathParams(p, params) {
|
|
266
|
+
return String(p).replace(/\{([^}]+)\}/g, (_, name) => {
|
|
267
|
+
const param = params.find((pr) => pr.in === "path" && pr.name === name);
|
|
268
|
+
const val = pickParamValue(param);
|
|
269
|
+
return encodeURIComponent(String(val ?? "sample"));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function collectParams(pathItem, op) {
|
|
273
|
+
const all = [...asArray(pathItem?.parameters), ...asArray(op?.parameters)].filter(isObject);
|
|
274
|
+
// op overrides path-level by name+in
|
|
275
|
+
const map = new Map();
|
|
276
|
+
for (const p of all) {
|
|
277
|
+
const key = `${String(p.in)}:${String(p.name)}`;
|
|
278
|
+
map.set(key, p);
|
|
279
|
+
}
|
|
280
|
+
return [...map.values()];
|
|
281
|
+
}
|
|
282
|
+
function getResponseSpec(op, doc) {
|
|
283
|
+
const responses = isObject(op?.responses) ? op.responses : {};
|
|
284
|
+
const codes = Object.keys(responses);
|
|
285
|
+
const preferred = ["200", "201", "204", "default", ...codes].find((c) => c in responses);
|
|
286
|
+
if (!preferred)
|
|
287
|
+
return { status: 200 };
|
|
288
|
+
const rawResp = responses[preferred];
|
|
289
|
+
const resp = isObject(rawResp) ? rawResp : {};
|
|
290
|
+
const status = preferred === "default" ? 200 : Number(preferred);
|
|
291
|
+
let schema;
|
|
292
|
+
let contentType;
|
|
293
|
+
if (isObject(resp.content)) {
|
|
294
|
+
const jsonKey = Object.keys(resp.content).find((k) => k.toLowerCase().includes("json")) || Object.keys(resp.content)[0];
|
|
295
|
+
if (jsonKey) {
|
|
296
|
+
contentType = jsonKey;
|
|
297
|
+
const media = resp.content[jsonKey];
|
|
298
|
+
if (isObject(media) && isObject(media.schema))
|
|
299
|
+
schema = resolveSchemaObject(media.schema, doc);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else if (isObject(resp.schema)) { // swagger 2.0
|
|
303
|
+
schema = resolveSchemaObject(resp.schema, doc);
|
|
304
|
+
contentType = "application/json";
|
|
305
|
+
}
|
|
306
|
+
return { status: Number.isFinite(status) ? status : 200, schema, contentType };
|
|
307
|
+
}
|
|
308
|
+
function endpointsFromOpenApiDoc(doc, options = {}) {
|
|
309
|
+
const eps = [];
|
|
310
|
+
const paths = isObject(doc?.paths) ? doc.paths : {};
|
|
311
|
+
const includeMutating = options.includeMutating === true;
|
|
312
|
+
const globalConsumes = asArray(doc.consumes);
|
|
313
|
+
const basePath = typeof doc?.basePath === "string" ? doc.basePath.replace(/\/$/, "") : "";
|
|
314
|
+
for (const [rawPath, pathItem] of Object.entries(paths)) {
|
|
315
|
+
if (!isObject(pathItem))
|
|
316
|
+
continue;
|
|
317
|
+
for (const [m, op] of Object.entries(pathItem)) {
|
|
318
|
+
const method = m.toUpperCase();
|
|
319
|
+
const allowed = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
|
|
320
|
+
if (!allowed.includes(method))
|
|
321
|
+
continue;
|
|
322
|
+
const isMutating = ["POST", "PUT", "PATCH", "DELETE"].includes(method);
|
|
323
|
+
if (isMutating && !includeMutating)
|
|
324
|
+
continue;
|
|
325
|
+
if (!isObject(op))
|
|
326
|
+
continue;
|
|
327
|
+
const params = collectParams(pathItem, op).map((p) => {
|
|
328
|
+
if (p.schema)
|
|
329
|
+
return { ...p, schema: resolveSchema(p.schema, doc) };
|
|
330
|
+
return p;
|
|
331
|
+
});
|
|
332
|
+
const substituted = substitutePathParams(rawPath, params);
|
|
333
|
+
const resolvedPath = `${basePath}${substituted.startsWith("/") ? substituted : `/${substituted}`}` || substituted;
|
|
334
|
+
const query = {};
|
|
335
|
+
const headers = {};
|
|
336
|
+
for (const p of params) {
|
|
337
|
+
const paramName = typeof p.name === "string" ? p.name : "";
|
|
338
|
+
if (!paramName)
|
|
339
|
+
continue;
|
|
340
|
+
if (p.in === "query") {
|
|
341
|
+
const val = pickParamValue(p);
|
|
342
|
+
if (val !== undefined)
|
|
343
|
+
query[paramName] = val;
|
|
344
|
+
}
|
|
345
|
+
else if (p.in === "header") {
|
|
346
|
+
const val = pickParamValue(p);
|
|
347
|
+
if (val !== undefined)
|
|
348
|
+
headers[paramName] = String(val);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
let body = null;
|
|
352
|
+
if (isObject(op.requestBody)) {
|
|
353
|
+
const content = isObject(op.requestBody.content) ? op.requestBody.content : {};
|
|
354
|
+
const jsonKey = Object.keys(content).find((k) => k.toLowerCase().includes("json")) || Object.keys(content)[0];
|
|
355
|
+
if (jsonKey && isObject(content[jsonKey])) {
|
|
356
|
+
const media = content[jsonKey];
|
|
357
|
+
if (media.example !== undefined)
|
|
358
|
+
body = media.example;
|
|
359
|
+
else if (isObject(media.schema))
|
|
360
|
+
body = exampleFromSchema(resolveSchema(media.schema, doc));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
const bodyParam = params.find((p) => p.in === "body");
|
|
365
|
+
if (bodyParam) {
|
|
366
|
+
if (bodyParam.example !== undefined)
|
|
367
|
+
body = bodyParam.example;
|
|
368
|
+
else if (isObject(bodyParam.schema))
|
|
369
|
+
body = exampleFromSchema(resolveSchema(bodyParam.schema, doc));
|
|
370
|
+
else
|
|
371
|
+
body = exampleFromSchema(bodyParam);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const resp = getResponseSpec(op, doc);
|
|
375
|
+
if (resp.contentType && !headers.accept)
|
|
376
|
+
headers.accept = resp.contentType;
|
|
377
|
+
if (body !== null && !headers["content-type"]) {
|
|
378
|
+
const opConsumes = asArray(op.consumes);
|
|
379
|
+
const ct = opConsumes[0] || globalConsumes[0] || "application/json";
|
|
380
|
+
headers["content-type"] = String(ct);
|
|
381
|
+
}
|
|
382
|
+
eps.push({
|
|
383
|
+
id: `openapi-${method.toLowerCase()}-${slugify(rawPath)}`,
|
|
384
|
+
method,
|
|
385
|
+
path: resolvedPath.startsWith("/") ? resolvedPath : `/${resolvedPath}`,
|
|
386
|
+
query: Object.keys(query).length ? query : undefined,
|
|
387
|
+
headers,
|
|
388
|
+
body,
|
|
389
|
+
expectedStatus: resp.status,
|
|
390
|
+
jsonSchema: resp.schema,
|
|
391
|
+
expectedContentType: resp.contentType,
|
|
392
|
+
fromSpec: true
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return eps;
|
|
397
|
+
}
|
|
398
|
+
function exampleFromSchema(schema, depth = 0) {
|
|
399
|
+
if (!isObject(schema) || depth > 8)
|
|
400
|
+
return undefined;
|
|
401
|
+
if (schema.example !== undefined)
|
|
402
|
+
return schema.example;
|
|
403
|
+
if (schema.default !== undefined)
|
|
404
|
+
return schema.default;
|
|
405
|
+
if (Array.isArray(schema.enum) && schema.enum.length)
|
|
406
|
+
return schema.enum[0];
|
|
407
|
+
if (Array.isArray(schema.allOf)) {
|
|
408
|
+
let merged = {};
|
|
409
|
+
for (const p of schema.allOf)
|
|
410
|
+
merged = mergeSchemas(merged, p);
|
|
411
|
+
return exampleFromSchema(merged, depth + 1);
|
|
412
|
+
}
|
|
413
|
+
const t = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
414
|
+
if (t === "object" || isObject(schema.properties)) {
|
|
415
|
+
const out = {};
|
|
416
|
+
for (const [k, v] of Object.entries(isObject(schema.properties) ? schema.properties : {})) {
|
|
417
|
+
const ex = exampleFromSchema(v, depth + 1);
|
|
418
|
+
if (ex !== undefined)
|
|
419
|
+
out[k] = ex;
|
|
420
|
+
else if (Array.isArray(schema.required) && schema.required.includes(k))
|
|
421
|
+
out[k] = "sample";
|
|
422
|
+
}
|
|
423
|
+
return out;
|
|
424
|
+
}
|
|
425
|
+
if (t === "array") {
|
|
426
|
+
const itemEx = exampleFromSchema(schema.items || {}, depth + 1);
|
|
427
|
+
return itemEx === undefined ? [] : [itemEx];
|
|
428
|
+
}
|
|
429
|
+
if (t === "integer" || t === "number")
|
|
430
|
+
return 1;
|
|
431
|
+
if (t === "boolean")
|
|
432
|
+
return true;
|
|
433
|
+
if (t === "null")
|
|
434
|
+
return null;
|
|
435
|
+
return "sample";
|
|
436
|
+
}
|
|
437
|
+
function pickBaseUrlFromSpec(doc, options) {
|
|
438
|
+
if (typeof options.baseUrl === "string" && options.baseUrl)
|
|
439
|
+
return options.baseUrl;
|
|
440
|
+
if (Array.isArray(doc?.servers) && doc.servers.length && isObject(doc.servers[0]) && typeof doc.servers[0].url === "string") {
|
|
441
|
+
return doc.servers[0].url;
|
|
442
|
+
}
|
|
443
|
+
if (typeof doc?.host === "string") {
|
|
444
|
+
const scheme = asArray(doc.schemes)[0] || "http";
|
|
445
|
+
const basePath = typeof doc.basePath === "string" ? doc.basePath : "";
|
|
446
|
+
return `${String(scheme)}://${doc.host}${basePath}`;
|
|
447
|
+
}
|
|
448
|
+
return "http://localhost";
|
|
449
|
+
}
|
|
450
|
+
function isOpenApiDoc(doc) {
|
|
451
|
+
return isObject(doc) && Boolean(doc.openapi || doc.swagger) && isObject(doc.paths);
|
|
452
|
+
}
|
|
453
|
+
const EXPORT_CONDITION_PRIORITY = ["import", "default", "node", "require", "module", "main"];
|
|
454
|
+
const FALLBACK_ENTRY_CANDIDATES = [
|
|
455
|
+
"src/index.ts",
|
|
456
|
+
"src/index.mts",
|
|
457
|
+
"src/index.mjs",
|
|
458
|
+
"src/index.js",
|
|
459
|
+
"index.ts",
|
|
460
|
+
"index.mjs",
|
|
461
|
+
"index.js"
|
|
462
|
+
];
|
|
463
|
+
const MODULE_RESOLVE_EXTENSIONS = [".ts", ".mts", ".cts", ".tsx", ".mjs", ".js", ".cjs"];
|
|
464
|
+
const MAX_EXTRA_SUBPATH_INVARIANTS = 5;
|
|
465
|
+
const DEFAULT_SCAN_MAX_DEPTH = 4;
|
|
466
|
+
function isDeclarationFile(filePath) {
|
|
467
|
+
return /\.d\.[cm]?ts$/i.test(filePath);
|
|
468
|
+
}
|
|
469
|
+
function isIgnoredExportTarget(filePath) {
|
|
470
|
+
const trimmed = filePath.trim();
|
|
471
|
+
return !trimmed || trimmed.includes("*") || isDeclarationFile(trimmed) || /\.json$/i.test(trimmed);
|
|
472
|
+
}
|
|
473
|
+
function isExistingFile(absPath) {
|
|
474
|
+
try {
|
|
475
|
+
return fs.existsSync(absPath) && fs.statSync(absPath).isFile();
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function canonicalizePath(absPath) {
|
|
482
|
+
let resolved;
|
|
483
|
+
try {
|
|
484
|
+
resolved = typeof fs.realpathSync.native === "function" ? fs.realpathSync.native(absPath) : fs.realpathSync(absPath);
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
resolved = path.resolve(absPath);
|
|
488
|
+
}
|
|
489
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
490
|
+
}
|
|
491
|
+
function detectModuleLanguage(filePath) {
|
|
492
|
+
return /\.(?:[cm]?ts|tsx)$/i.test(filePath) ? "ts" : "js";
|
|
493
|
+
}
|
|
494
|
+
function slugifySubpath(subpath) {
|
|
495
|
+
const cleaned = subpath
|
|
496
|
+
.replace(/^\.+\//, "")
|
|
497
|
+
.toLowerCase()
|
|
498
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
499
|
+
.replace(/^-+|-+$/g, "");
|
|
500
|
+
return cleaned || "subpath";
|
|
501
|
+
}
|
|
502
|
+
function collectExportConditionCandidates(value, depth = 0) {
|
|
503
|
+
if (depth > 8 || value === null || value === undefined)
|
|
504
|
+
return [];
|
|
505
|
+
if (typeof value === "string") {
|
|
506
|
+
return isIgnoredExportTarget(value) ? [] : [value];
|
|
507
|
+
}
|
|
508
|
+
const out = [];
|
|
509
|
+
const add = (items) => {
|
|
510
|
+
for (const item of items) {
|
|
511
|
+
if (!out.includes(item))
|
|
512
|
+
out.push(item);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
if (Array.isArray(value)) {
|
|
516
|
+
for (const item of value)
|
|
517
|
+
add(collectExportConditionCandidates(item, depth + 1));
|
|
518
|
+
return out;
|
|
519
|
+
}
|
|
520
|
+
if (isObject(value)) {
|
|
521
|
+
for (const cond of EXPORT_CONDITION_PRIORITY) {
|
|
522
|
+
if (Object.prototype.hasOwnProperty.call(value, cond)) {
|
|
523
|
+
add(collectExportConditionCandidates(value[cond], depth + 1));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
for (const [key, val] of Object.entries(value)) {
|
|
527
|
+
if (key === "types" || EXPORT_CONDITION_PRIORITY.includes(key))
|
|
528
|
+
continue;
|
|
529
|
+
add(collectExportConditionCandidates(val, depth + 1));
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return out;
|
|
533
|
+
}
|
|
534
|
+
function resolveRepoEntryCandidate(repoDir, relCandidate) {
|
|
535
|
+
if (isIgnoredExportTarget(relCandidate))
|
|
536
|
+
return null;
|
|
537
|
+
const norm = relCandidate.trim().replace(/^\.\//, "").replace(/\\/g, "/");
|
|
538
|
+
if (!norm || isIgnoredExportTarget(norm))
|
|
539
|
+
return null;
|
|
540
|
+
const absPath = path.resolve(repoDir, norm);
|
|
541
|
+
if (!isExistingFile(absPath))
|
|
542
|
+
return null;
|
|
543
|
+
return { file: norm, absPath };
|
|
544
|
+
}
|
|
545
|
+
function resolveRelativeModulePath(fromFileAbs, specifier) {
|
|
546
|
+
if (!(specifier.startsWith("./") || specifier.startsWith("../") || specifier === "." || specifier === "..")) {
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
const base = path.resolve(path.dirname(fromFileAbs), specifier);
|
|
550
|
+
if (!isDeclarationFile(base) && isExistingFile(base))
|
|
551
|
+
return base;
|
|
552
|
+
const lower = base.toLowerCase();
|
|
553
|
+
const extOrder = lower.endsWith(".mjs")
|
|
554
|
+
? [".mts", ".ts", ".mjs", ".js", ".cts", ".cjs", ".tsx"]
|
|
555
|
+
: lower.endsWith(".cjs")
|
|
556
|
+
? [".cts", ".ts", ".cjs", ".js", ".mts", ".mjs", ".tsx"]
|
|
557
|
+
: MODULE_RESOLVE_EXTENSIONS;
|
|
558
|
+
const stem = base.replace(/\.(?:[cm]?js|jsx)$/i, "");
|
|
559
|
+
if (stem !== base) {
|
|
560
|
+
for (const ext of extOrder) {
|
|
561
|
+
const candidate = `${stem}${ext}`;
|
|
562
|
+
if (!isDeclarationFile(candidate) && isExistingFile(candidate))
|
|
563
|
+
return candidate;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
for (const ext of extOrder) {
|
|
567
|
+
const candidate = `${base}${ext}`;
|
|
568
|
+
if (!isDeclarationFile(candidate) && isExistingFile(candidate))
|
|
569
|
+
return candidate;
|
|
570
|
+
}
|
|
571
|
+
for (const ext of extOrder) {
|
|
572
|
+
const indexCandidate = path.join(base, `index${ext}`);
|
|
573
|
+
if (!isDeclarationFile(indexCandidate) && isExistingFile(indexCandidate))
|
|
574
|
+
return indexCandidate;
|
|
575
|
+
}
|
|
576
|
+
if (stem !== base) {
|
|
577
|
+
for (const ext of extOrder) {
|
|
578
|
+
const indexCandidate = path.join(stem, `index${ext}`);
|
|
579
|
+
if (!isDeclarationFile(indexCandidate) && isExistingFile(indexCandidate))
|
|
580
|
+
return indexCandidate;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
function parseNamedExportSpecifiers(specListRaw) {
|
|
586
|
+
const cleaned = specListRaw.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/\/\/[^\r\n]*/g, " ");
|
|
587
|
+
const out = [];
|
|
588
|
+
for (const rawPart of cleaned.split(",")) {
|
|
589
|
+
const trimmed = rawPart.trim();
|
|
590
|
+
if (!trimmed)
|
|
591
|
+
continue;
|
|
592
|
+
// Skip TypeScript inline type specifiers: `export { type Foo, type Bar as Baz }`
|
|
593
|
+
if (/^type\s+(?!as(?:\s|$))(?:[A-Za-z_$]|['"])/.test(trimmed))
|
|
594
|
+
continue;
|
|
595
|
+
const asMatch = trimmed.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
596
|
+
if (asMatch) {
|
|
597
|
+
out.push({ localName: asMatch[1], exportedName: asMatch[2] });
|
|
598
|
+
}
|
|
599
|
+
else if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(trimmed)) {
|
|
600
|
+
out.push({ localName: trimmed, exportedName: trimmed });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return out;
|
|
604
|
+
}
|
|
605
|
+
function parseExportsFromText(text) {
|
|
606
|
+
const direct = [];
|
|
607
|
+
const starReExports = [];
|
|
608
|
+
const namedReExports = [];
|
|
609
|
+
const pushDirect = (name, kind) => {
|
|
610
|
+
if (!name)
|
|
611
|
+
return;
|
|
612
|
+
const existing = direct.find((e) => e.name === name);
|
|
613
|
+
if (!existing)
|
|
614
|
+
direct.push({ name, kind });
|
|
615
|
+
else if (existing.kind === "unknown" && kind !== "unknown")
|
|
616
|
+
existing.kind = kind;
|
|
617
|
+
};
|
|
618
|
+
// export [async] function [*] foo
|
|
619
|
+
for (const m of text.matchAll(/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t]+(?:async[ \t]+)?function(?:\s*\*\s*|\s+)([A-Za-z_$][A-Za-z0-9_$]*)/g)) {
|
|
620
|
+
pushDirect(m[1], "function");
|
|
621
|
+
}
|
|
622
|
+
// export [abstract] class Foo
|
|
623
|
+
for (const m of text.matchAll(/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t]+(?:abstract[ \t]+)?class[ \t]+([A-Za-z_$][A-Za-z0-9_$]*)/g)) {
|
|
624
|
+
pushDirect(m[1], "class");
|
|
625
|
+
}
|
|
626
|
+
// export const/let/var foo
|
|
627
|
+
for (const m of text.matchAll(/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t]+(?:const|let|var)[ \t]+([A-Za-z_$][A-Za-z0-9_$]*)/g)) {
|
|
628
|
+
pushDirect(m[1], "const");
|
|
629
|
+
}
|
|
630
|
+
// export * as ns from "./sub.js" (excludes `export type * as ...`)
|
|
631
|
+
for (const m of text.matchAll(/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t]+\*[ \t]+as[ \t]+([A-Za-z_$][A-Za-z0-9_$]*)[ \t]+from[ \t]*(['"])([^'"]+)\2/g)) {
|
|
632
|
+
pushDirect(m[1], "unknown");
|
|
633
|
+
}
|
|
634
|
+
// export * from "./sub.js" (excludes `export type * from ...` and `export * as ...`)
|
|
635
|
+
for (const m of text.matchAll(/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t]+\*[ \t]+from[ \t]*(['"])([^'"]+)\1/g)) {
|
|
636
|
+
if (m[2] && !starReExports.includes(m[2]))
|
|
637
|
+
starReExports.push(m[2]);
|
|
638
|
+
}
|
|
639
|
+
// export { a, b as c } [from "./sub.js"] (excludes `export type { ... }`)
|
|
640
|
+
for (const m of text.matchAll(/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t\r\n]*\{([^}]+)\}(?:[ \t\r\n]*from[ \t\r\n]*(['"])([^'"]+)\2)?/g)) {
|
|
641
|
+
const specifiers = parseNamedExportSpecifiers(m[1]);
|
|
642
|
+
if (specifiers.length === 0)
|
|
643
|
+
continue;
|
|
644
|
+
if (m[3]) {
|
|
645
|
+
namedReExports.push({ specifier: m[3], specifiers });
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
for (const spec of specifiers) {
|
|
649
|
+
pushDirect(spec.exportedName, spec.exportedName === "default" ? "default" : "unknown");
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
// export default (excludes `export default interface`)
|
|
654
|
+
if (/(?:^|[;}\r\n]|\*\/)[ \t]*export[ \t]+default(?!\s+interface\b)\b/.test(text)) {
|
|
655
|
+
pushDirect("default", "default");
|
|
656
|
+
}
|
|
657
|
+
// CJS module.exports = { a, b }
|
|
658
|
+
const modObj = text.match(/\bmodule\.exports\s*=\s*\{([\s\S]*?)\}/m);
|
|
659
|
+
if (modObj) {
|
|
660
|
+
for (const part of modObj[1].split(",")) {
|
|
661
|
+
const kv = part.trim().split(":")[0].trim();
|
|
662
|
+
const name = kv.split(/\s+/)[0];
|
|
663
|
+
if (name && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name))
|
|
664
|
+
pushDirect(name, "unknown");
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
for (const m of text.matchAll(/\bexports\.([A-Za-z_$][A-Za-z0-9_$]*)\s*=/g))
|
|
668
|
+
pushDirect(m[1], "unknown");
|
|
669
|
+
return { direct, starReExports, namedReExports };
|
|
670
|
+
}
|
|
671
|
+
function scanExportsFromText(text) {
|
|
672
|
+
const parsed = parseExportsFromText(text);
|
|
673
|
+
const exports = [];
|
|
674
|
+
const push = (name, kind) => {
|
|
675
|
+
const existing = exports.find((e) => e.name === name);
|
|
676
|
+
if (!existing)
|
|
677
|
+
exports.push({ name, kind });
|
|
678
|
+
else if (existing.kind === "unknown" && kind !== "unknown")
|
|
679
|
+
existing.kind = kind;
|
|
680
|
+
};
|
|
681
|
+
for (const entry of parsed.direct)
|
|
682
|
+
push(entry.name, entry.kind);
|
|
683
|
+
for (const re of parsed.namedReExports) {
|
|
684
|
+
for (const spec of re.specifiers) {
|
|
685
|
+
push(spec.exportedName, spec.exportedName === "default" ? "default" : "unknown");
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return exports;
|
|
689
|
+
}
|
|
690
|
+
function scanExportsFromFileInternal(absPath, depth, maxDepth, visitedStack, memo) {
|
|
691
|
+
if (depth > maxDepth)
|
|
692
|
+
return { entries: [], truncatedByCycle: false };
|
|
693
|
+
const canonical = canonicalizePath(absPath);
|
|
694
|
+
if (visitedStack.has(canonical))
|
|
695
|
+
return { entries: [], truncatedByCycle: true };
|
|
696
|
+
if (!isExistingFile(absPath) || isDeclarationFile(absPath))
|
|
697
|
+
return { entries: [], truncatedByCycle: false };
|
|
698
|
+
const memoKey = `${canonical}::${maxDepth - depth}`;
|
|
699
|
+
const cached = memo.get(memoKey);
|
|
700
|
+
if (cached)
|
|
701
|
+
return { entries: cached, truncatedByCycle: false };
|
|
702
|
+
const text = fs.readFileSync(absPath, "utf8");
|
|
703
|
+
const parsed = parseExportsFromText(text);
|
|
704
|
+
const entries = [];
|
|
705
|
+
const byName = new Map();
|
|
706
|
+
const push = (entry) => {
|
|
707
|
+
const existing = byName.get(entry.name);
|
|
708
|
+
if (!existing) {
|
|
709
|
+
const copy = { name: entry.name, kind: entry.kind };
|
|
710
|
+
byName.set(copy.name, copy);
|
|
711
|
+
entries.push(copy);
|
|
712
|
+
}
|
|
713
|
+
else if (existing.kind === "unknown" && entry.kind !== "unknown") {
|
|
714
|
+
existing.kind = entry.kind;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
for (const entry of parsed.direct)
|
|
718
|
+
push(entry);
|
|
719
|
+
let truncatedByCycle = false;
|
|
720
|
+
visitedStack.add(canonical);
|
|
721
|
+
try {
|
|
722
|
+
// Named re-exports: `export { a, b as c, default as Foo } from "./sub.js"`
|
|
723
|
+
for (const re of parsed.namedReExports) {
|
|
724
|
+
let targetExports = null;
|
|
725
|
+
if (depth < maxDepth) {
|
|
726
|
+
const targetAbs = resolveRelativeModulePath(absPath, re.specifier);
|
|
727
|
+
if (targetAbs) {
|
|
728
|
+
const sub = scanExportsFromFileInternal(targetAbs, depth + 1, maxDepth, visitedStack, memo);
|
|
729
|
+
if (sub.truncatedByCycle)
|
|
730
|
+
truncatedByCycle = true;
|
|
731
|
+
targetExports = sub.entries;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
for (const spec of re.specifiers) {
|
|
735
|
+
const found = targetExports?.find((e) => e.name === spec.localName);
|
|
736
|
+
let kind;
|
|
737
|
+
if (spec.exportedName === "default") {
|
|
738
|
+
kind = "default";
|
|
739
|
+
}
|
|
740
|
+
else if (found && found.kind !== "default") {
|
|
741
|
+
kind = found.kind;
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
kind = "unknown";
|
|
745
|
+
}
|
|
746
|
+
push({ name: spec.exportedName, kind });
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
// Star re-exports: `export * from "./sub.js"` (excludes `default` per ESM spec)
|
|
750
|
+
if (depth < maxDepth) {
|
|
751
|
+
for (const specifier of parsed.starReExports) {
|
|
752
|
+
const targetAbs = resolveRelativeModulePath(absPath, specifier);
|
|
753
|
+
if (!targetAbs)
|
|
754
|
+
continue;
|
|
755
|
+
const sub = scanExportsFromFileInternal(targetAbs, depth + 1, maxDepth, visitedStack, memo);
|
|
756
|
+
if (sub.truncatedByCycle)
|
|
757
|
+
truncatedByCycle = true;
|
|
758
|
+
for (const entry of sub.entries) {
|
|
759
|
+
if (entry.name === "default")
|
|
760
|
+
continue;
|
|
761
|
+
push(entry);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
finally {
|
|
767
|
+
visitedStack.delete(canonical);
|
|
768
|
+
}
|
|
769
|
+
if (!truncatedByCycle) {
|
|
770
|
+
memo.set(memoKey, entries);
|
|
771
|
+
}
|
|
772
|
+
return { entries, truncatedByCycle };
|
|
773
|
+
}
|
|
774
|
+
function scanExportsFromFile(absPath, maxDepth = DEFAULT_SCAN_MAX_DEPTH) {
|
|
775
|
+
return scanExportsFromFileInternal(absPath, 0, maxDepth, new Set(), new Map()).entries;
|
|
776
|
+
}
|
|
777
|
+
export async function ingestRepo(options = {}, _deps = {}) {
|
|
778
|
+
const source = options.source;
|
|
779
|
+
if (!source || typeof source !== "string") {
|
|
780
|
+
throw new VibecodeError("TARGET_MISSING", "Repo ingestor requires --source <repo-dir>");
|
|
781
|
+
}
|
|
782
|
+
const repoDir = path.resolve(options.cwd || process.cwd(), source);
|
|
783
|
+
if (!fs.existsSync(repoDir) || !fs.statSync(repoDir).isDirectory()) {
|
|
784
|
+
throw new VibecodeError("TARGET_MISSING", `Repo source not found: ${source}`);
|
|
785
|
+
}
|
|
786
|
+
const warnings = [];
|
|
787
|
+
const pkgPath = path.join(repoDir, "package.json");
|
|
788
|
+
let pkg = null;
|
|
789
|
+
if (fs.existsSync(pkgPath)) {
|
|
790
|
+
try {
|
|
791
|
+
const parsed = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
792
|
+
if (isObject(parsed))
|
|
793
|
+
pkg = parsed;
|
|
794
|
+
}
|
|
795
|
+
catch {
|
|
796
|
+
warnings.push({ code: "PARSE_WARNING", message: "Could not parse package.json" });
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
// 1. Collect prioritized primary (".") runtime candidates and extra subpath candidate lists
|
|
800
|
+
const primaryCandidates = [];
|
|
801
|
+
const subpathCandidates = [];
|
|
802
|
+
const pushPrimary = (candidates) => {
|
|
803
|
+
for (const c of candidates) {
|
|
804
|
+
if (!primaryCandidates.includes(c))
|
|
805
|
+
primaryCandidates.push(c);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
if (pkg?.exports !== undefined && pkg?.exports !== null) {
|
|
809
|
+
if (typeof pkg.exports === "string") {
|
|
810
|
+
pushPrimary(collectExportConditionCandidates(pkg.exports));
|
|
811
|
+
}
|
|
812
|
+
else if (isObject(pkg.exports)) {
|
|
813
|
+
const exportEntries = Object.entries(pkg.exports);
|
|
814
|
+
const isSubpathMap = exportEntries.some(([k]) => k.startsWith("."));
|
|
815
|
+
if (isSubpathMap) {
|
|
816
|
+
if (Object.prototype.hasOwnProperty.call(pkg.exports, ".")) {
|
|
817
|
+
pushPrimary(collectExportConditionCandidates(pkg.exports["."]));
|
|
818
|
+
}
|
|
819
|
+
for (const [subpath, value] of exportEntries) {
|
|
820
|
+
if (subpath === "." || !subpath.startsWith(".") || subpath.includes("*") || /\.json$/i.test(subpath)) {
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
const cands = collectExportConditionCandidates(value);
|
|
824
|
+
if (cands.length > 0)
|
|
825
|
+
subpathCandidates.push({ subpath, candidates: cands });
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
pushPrimary(collectExportConditionCandidates(pkg.exports));
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (typeof pkg?.module === "string")
|
|
834
|
+
pushPrimary(collectExportConditionCandidates(pkg.module));
|
|
835
|
+
if (typeof pkg?.main === "string")
|
|
836
|
+
pushPrimary(collectExportConditionCandidates(pkg.main));
|
|
837
|
+
for (const fallback of FALLBACK_ENTRY_CANDIDATES)
|
|
838
|
+
pushPrimary([fallback]);
|
|
839
|
+
// 2. Resolve existing runtime files on disk (primary + additional subpaths)
|
|
840
|
+
const seenFiles = new Set();
|
|
841
|
+
let primaryEntry = null;
|
|
842
|
+
for (const cand of primaryCandidates) {
|
|
843
|
+
const resolved = resolveRepoEntryCandidate(repoDir, cand);
|
|
844
|
+
if (!resolved)
|
|
845
|
+
continue;
|
|
846
|
+
primaryEntry = { subpath: ".", ...resolved };
|
|
847
|
+
seenFiles.add(resolved.file);
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
const extraEntries = [];
|
|
851
|
+
for (const sub of subpathCandidates) {
|
|
852
|
+
for (const cand of sub.candidates) {
|
|
853
|
+
const resolved = resolveRepoEntryCandidate(repoDir, cand);
|
|
854
|
+
if (!resolved)
|
|
855
|
+
continue;
|
|
856
|
+
if (seenFiles.has(resolved.file))
|
|
857
|
+
break;
|
|
858
|
+
seenFiles.add(resolved.file);
|
|
859
|
+
if (!primaryEntry) {
|
|
860
|
+
primaryEntry = { subpath: sub.subpath, ...resolved };
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
extraEntries.push({ subpath: sub.subpath, ...resolved });
|
|
864
|
+
}
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
const filesPresent = [];
|
|
869
|
+
if (primaryEntry)
|
|
870
|
+
filesPresent.push(primaryEntry.file);
|
|
871
|
+
for (const extra of extraEntries)
|
|
872
|
+
filesPresent.push(extra.file);
|
|
873
|
+
// 3. Scan ONLY primaryEntry for `inv-repo-exports` (no cross-entrypoint symbol contamination)
|
|
874
|
+
let primaryExports = [];
|
|
875
|
+
if (primaryEntry) {
|
|
876
|
+
try {
|
|
877
|
+
primaryExports = scanExportsFromFile(primaryEntry.absPath);
|
|
878
|
+
}
|
|
879
|
+
catch (err) {
|
|
880
|
+
warnings.push({ code: "READ_WARNING", message: `Failed to scan ${primaryEntry.file}: ${errorMessage(err)}` });
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
const invariants = [
|
|
884
|
+
{
|
|
885
|
+
id: "inv-repo-exports",
|
|
886
|
+
domain: "repo",
|
|
887
|
+
type: "repo_exports",
|
|
888
|
+
severity: "hard",
|
|
889
|
+
description: "Public entrypoint preserves exported symbol contract",
|
|
890
|
+
tags: ["repo", "exports"],
|
|
891
|
+
sourceId: "src-1",
|
|
892
|
+
input: {
|
|
893
|
+
modulePath: primaryEntry ? primaryEntry.file : "src/index.mjs",
|
|
894
|
+
language: primaryEntry ? detectModuleLanguage(primaryEntry.file) : "js"
|
|
895
|
+
},
|
|
896
|
+
expected: {
|
|
897
|
+
filesPresent: filesPresent.length
|
|
898
|
+
? filesPresent
|
|
899
|
+
: ["package.json"].filter((f) => fs.existsSync(path.join(repoDir, f))),
|
|
900
|
+
exports: primaryExports
|
|
901
|
+
},
|
|
902
|
+
tolerance: {}
|
|
903
|
+
}
|
|
904
|
+
];
|
|
905
|
+
// 4. Emit separate `repo_exports` invariants for up to 5 extra subpath entrypoints that export symbols
|
|
906
|
+
const usedIds = new Set(["inv-repo-exports"]);
|
|
907
|
+
let extraEmitted = 0;
|
|
908
|
+
for (const extra of extraEntries) {
|
|
909
|
+
if (extraEmitted >= MAX_EXTRA_SUBPATH_INVARIANTS)
|
|
910
|
+
break;
|
|
911
|
+
let extraExports = [];
|
|
912
|
+
try {
|
|
913
|
+
extraExports = scanExportsFromFile(extra.absPath);
|
|
914
|
+
}
|
|
915
|
+
catch (err) {
|
|
916
|
+
warnings.push({ code: "READ_WARNING", message: `Failed to scan ${extra.file}: ${errorMessage(err)}` });
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
if (extraExports.length === 0)
|
|
920
|
+
continue;
|
|
921
|
+
const slug = slugifySubpath(extra.subpath);
|
|
922
|
+
let invId = `inv-repo-exports-${slug}`;
|
|
923
|
+
let suffix = 2;
|
|
924
|
+
while (usedIds.has(invId)) {
|
|
925
|
+
invId = `inv-repo-exports-${slug}-${suffix++}`;
|
|
926
|
+
}
|
|
927
|
+
usedIds.add(invId);
|
|
928
|
+
invariants.push({
|
|
929
|
+
id: invId,
|
|
930
|
+
domain: "repo",
|
|
931
|
+
type: "repo_exports",
|
|
932
|
+
severity: "hard",
|
|
933
|
+
description: `Subpath entrypoint ${extra.subpath} preserves exported symbol contract`,
|
|
934
|
+
tags: ["repo", "exports", slug],
|
|
935
|
+
sourceId: "src-1",
|
|
936
|
+
input: {
|
|
937
|
+
modulePath: extra.file,
|
|
938
|
+
language: detectModuleLanguage(extra.file)
|
|
939
|
+
},
|
|
940
|
+
expected: {
|
|
941
|
+
filesPresent: [extra.file],
|
|
942
|
+
exports: extraExports
|
|
943
|
+
},
|
|
944
|
+
tolerance: {}
|
|
945
|
+
});
|
|
946
|
+
extraEmitted++;
|
|
947
|
+
}
|
|
948
|
+
if (primaryExports.length === 0 && extraEmitted === 0) {
|
|
949
|
+
warnings.push({ code: "ADAPTER_DEGRADED", message: "No exports detected; emitting filesPresent-only invariant." });
|
|
950
|
+
}
|
|
951
|
+
return {
|
|
952
|
+
domain: "repo",
|
|
953
|
+
sources: [{ id: "src-1", kind: "repo", ref: source, meta: { repoDir } }],
|
|
954
|
+
artifacts: { root: ".vibecode/artifacts", files: {} },
|
|
955
|
+
invariants,
|
|
956
|
+
warnings
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
export { scanExportsFromText, scanExportsFromFile };
|
|
960
|
+
export async function ingestApi(options = {}, deps = {}) {
|
|
961
|
+
const source = options.source;
|
|
962
|
+
if (!source || typeof source !== "string") {
|
|
963
|
+
throw new VibecodeError("TARGET_MISSING", "API ingestor requires --source <base-url-or-openapi.json>");
|
|
964
|
+
}
|
|
965
|
+
const warnings = [];
|
|
966
|
+
let baseUrl = source;
|
|
967
|
+
let endpoints = [];
|
|
968
|
+
let specDoc = null;
|
|
969
|
+
let specMode = false;
|
|
970
|
+
if (Array.isArray(options.endpoints) && options.endpoints.length) {
|
|
971
|
+
endpoints = options.endpoints.map((e) => normalizeEndpoint(e)).filter((e) => e !== null);
|
|
972
|
+
}
|
|
973
|
+
else if (typeof options.endpointsFile === "string") {
|
|
974
|
+
const raw = JSON.parse(fs.readFileSync(path.resolve(options.cwd || process.cwd(), options.endpointsFile), "utf8"));
|
|
975
|
+
const arr = Array.isArray(raw) ? raw : (isObject(raw) && Array.isArray(raw.endpoints) ? raw.endpoints : []);
|
|
976
|
+
endpoints = arr
|
|
977
|
+
.map((e) => normalizeEndpoint(e))
|
|
978
|
+
.filter((e) => e !== null);
|
|
979
|
+
}
|
|
980
|
+
const isUrl = /^https?:\/\//i.test(source);
|
|
981
|
+
if (!isUrl) {
|
|
982
|
+
const abs = path.resolve(options.cwd || process.cwd(), source);
|
|
983
|
+
const lowerAbs = abs.toLowerCase();
|
|
984
|
+
const isJsonSpec = lowerAbs.endsWith(".json");
|
|
985
|
+
const isYamlSpec = lowerAbs.endsWith(".yaml") || lowerAbs.endsWith(".yml");
|
|
986
|
+
if (fs.existsSync(abs) && (isJsonSpec || isYamlSpec)) {
|
|
987
|
+
try {
|
|
988
|
+
const rawText = fs.readFileSync(abs, "utf8");
|
|
989
|
+
const doc = isYamlSpec ? parseYaml(rawText) : JSON.parse(rawText);
|
|
990
|
+
if (isOpenApiDoc(doc)) {
|
|
991
|
+
specDoc = doc;
|
|
992
|
+
baseUrl = pickBaseUrlFromSpec(doc, options);
|
|
993
|
+
if (endpoints.length === 0) {
|
|
994
|
+
endpoints = endpointsFromOpenApiDoc(doc, { includeMutating: options.includeMutating === true });
|
|
995
|
+
specMode = true;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
catch (err) {
|
|
1000
|
+
warnings.push({ code: "BRIDGE_FORMAT_WARNING", message: `Failed to parse OpenAPI source: ${errorMessage(err)}` });
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (!specDoc && typeof options.baseUrl === "string" && options.baseUrl)
|
|
1005
|
+
baseUrl = options.baseUrl;
|
|
1006
|
+
if (endpoints.length === 0) {
|
|
1007
|
+
if (isUrl && !specDoc && !(typeof options.baseUrl === "string" && options.baseUrl)) {
|
|
1008
|
+
try {
|
|
1009
|
+
const parsed = new URL(source);
|
|
1010
|
+
if ((parsed.pathname && parsed.pathname !== "/") || parsed.search) {
|
|
1011
|
+
baseUrl = parsed.origin;
|
|
1012
|
+
const queryObj = parsed.search ? Object.fromEntries(parsed.searchParams.entries()) : undefined;
|
|
1013
|
+
endpoints = [{ method: "GET", path: parsed.pathname || "/", query: queryObj, headers: {}, body: null }];
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
catch {
|
|
1017
|
+
// fall through to default probes
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
if (endpoints.length === 0) {
|
|
1021
|
+
endpoints = [
|
|
1022
|
+
{ method: "GET", path: "/health", headers: {}, body: null },
|
|
1023
|
+
{ method: "GET", path: "/", headers: {}, body: null }
|
|
1024
|
+
];
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
const globalHeaders = isObject(options.headers) ? options.headers : undefined;
|
|
1028
|
+
const usedIds = new Set();
|
|
1029
|
+
const invariants = [];
|
|
1030
|
+
for (const ep of endpoints.slice(0, 25)) {
|
|
1031
|
+
const method = String(ep.method || "GET").toUpperCase();
|
|
1032
|
+
const probeHeaders = mergeHeaders(ep.headers, globalHeaders);
|
|
1033
|
+
const url = buildApiUrl(baseUrl, ep.path, ep.query);
|
|
1034
|
+
let observed = null;
|
|
1035
|
+
let probeFailed = null;
|
|
1036
|
+
const shouldProbe = !(options.offline === true && specMode);
|
|
1037
|
+
if (shouldProbe) {
|
|
1038
|
+
try {
|
|
1039
|
+
observed = await (deps.fetchJson || fetchJson)(url, {
|
|
1040
|
+
method,
|
|
1041
|
+
headers: probeHeaders,
|
|
1042
|
+
body: ep.body ?? null,
|
|
1043
|
+
timeoutMs: ep.timeoutMs || 10000
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
catch (err) {
|
|
1047
|
+
probeFailed = err;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
const canUseSpecFallback = specMode && (options.offline === true || Boolean(probeFailed));
|
|
1051
|
+
if (!observed && !canUseSpecFallback) {
|
|
1052
|
+
if (probeFailed)
|
|
1053
|
+
warnings.push({ code: "EXEC_ERROR", message: `Failed to probe ${method} ${ep.path}: ${errorMessage(probeFailed)}` });
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
if (!observed && canUseSpecFallback) {
|
|
1057
|
+
const msg = options.offline === true
|
|
1058
|
+
? `Offline spec-only mode: emitted ${method} ${ep.path} from OpenAPI spec`
|
|
1059
|
+
: `Live probe failed for ${method} ${ep.path}; fell back to OpenAPI spec: ${probeFailed ? errorMessage(probeFailed) : "unknown error"}`;
|
|
1060
|
+
warnings.push({ code: options.offline === true ? "ADAPTER_DEGRADED" : "EXEC_ERROR", message: msg });
|
|
1061
|
+
}
|
|
1062
|
+
const expected = {};
|
|
1063
|
+
if (observed) {
|
|
1064
|
+
expected.status = ep.expectedStatus ?? observed.status;
|
|
1065
|
+
if (ep.jsonSchema)
|
|
1066
|
+
expected.jsonSchema = ep.jsonSchema;
|
|
1067
|
+
else if (observed.json !== null && isObject(observed.json))
|
|
1068
|
+
expected.jsonSchema = synthesizeSchema(observed.json);
|
|
1069
|
+
else if (Array.isArray(observed.json))
|
|
1070
|
+
expected.jsonSchema = synthesizeSchema(observed.json);
|
|
1071
|
+
if (observed.json !== null && isObject(observed.json))
|
|
1072
|
+
expected.jsonSubset = observed.json;
|
|
1073
|
+
if (ep.jsonPaths)
|
|
1074
|
+
expected.jsonPaths = ep.jsonPaths;
|
|
1075
|
+
if (specMode && ep.fromSpec && ep.jsonSchema)
|
|
1076
|
+
expected.jsonSchema = ep.jsonSchema;
|
|
1077
|
+
if (specMode && ep.fromSpec && ep.expectedContentType) {
|
|
1078
|
+
expected.headers = redactHeaders({ ...(isObject(expected.headers) ? expected.headers : {}), "content-type": ep.expectedContentType }, "strip");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
expected.status = ep.expectedStatus ?? 200;
|
|
1083
|
+
if (ep.jsonSchema)
|
|
1084
|
+
expected.jsonSchema = ep.jsonSchema;
|
|
1085
|
+
if (ep.jsonPaths)
|
|
1086
|
+
expected.jsonPaths = ep.jsonPaths;
|
|
1087
|
+
if (ep.expectedContentType)
|
|
1088
|
+
expected.headers = redactHeaders({ "content-type": ep.expectedContentType }, "strip");
|
|
1089
|
+
}
|
|
1090
|
+
const baseId = ep.id || `inv-api-${method.toLowerCase()}-${slugify(ep.path)}`;
|
|
1091
|
+
const id = uniqueId(baseId, usedIds);
|
|
1092
|
+
const tags = ["api", "http", ep.fromSpec ? "openapi" : "auto-probe", observed ? "observed" : "spec-only"];
|
|
1093
|
+
invariants.push({
|
|
1094
|
+
id,
|
|
1095
|
+
domain: "api",
|
|
1096
|
+
type: "http",
|
|
1097
|
+
severity: "hard",
|
|
1098
|
+
description: `${method} ${ep.path} matches ${observed ? "observed" : "OpenAPI"} contract`,
|
|
1099
|
+
tags,
|
|
1100
|
+
sourceId: "src-1",
|
|
1101
|
+
input: {
|
|
1102
|
+
method,
|
|
1103
|
+
path: ep.path,
|
|
1104
|
+
headers: redactHeaders(probeHeaders, "strip"),
|
|
1105
|
+
...(ep.query ? { query: ep.query } : {}),
|
|
1106
|
+
body: ep.body ?? null,
|
|
1107
|
+
timeoutMs: ep.timeoutMs || 10000
|
|
1108
|
+
},
|
|
1109
|
+
expected,
|
|
1110
|
+
tolerance: {}
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
return {
|
|
1114
|
+
domain: "api",
|
|
1115
|
+
sources: [{ id: "src-1", kind: specDoc ? "openapi" : "api", ref: source, meta: { baseUrl, spec: Boolean(specDoc) } }],
|
|
1116
|
+
artifacts: { root: ".vibecode/artifacts", files: {} },
|
|
1117
|
+
invariants,
|
|
1118
|
+
warnings
|
|
1119
|
+
};
|
|
1120
|
+
}
|