vibecode-anything 0.3.0 → 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/README.md +239 -67
- package/dist/cli.js +2140 -73
- package/dist/core/adapters.d.ts +26 -3
- package/dist/core/adapters.js +411 -25
- 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/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +21 -1
- package/dist/core/doctor.js +234 -21
- package/dist/core/exec.d.ts +26 -2
- package/dist/core/exec.js +235 -8
- 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 +6 -1
- package/dist/core/parity.js +36 -1
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.js +45 -9
- 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 +3 -2
- package/dist/core/schema.js +460 -17
- 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/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +11 -2
- package/dist/core/store.js +128 -8
- 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 +182 -14
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.js +65 -16
- package/dist/core/watch.d.ts +28 -3
- package/dist/core/watch.js +222 -12
- 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 +2 -1
- package/dist/ingestors/api-repo.js +483 -85
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +2 -0
- package/dist/ingestors/bridges.js +702 -0
- package/dist/ingestors/cli.d.ts +2 -1
- package/dist/ingestors/cli.js +234 -46
- 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/index.js +486 -6
- 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 +4 -1
- package/dist/ingestors/video.js +86 -36
- package/dist/ingestors/web.d.ts +16 -1
- package/dist/ingestors/web.js +474 -32
- package/dist/mcp/server.js +3532 -67
- package/dist/oracles/api-repo.js +102 -30
- package/dist/oracles/cli.js +65 -17
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.js +178 -28
- package/dist/oracles/index.d.ts +3 -1
- package/dist/oracles/index.js +243 -14
- 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 +1 -1
- package/dist/oracles/video.js +232 -16
- package/dist/oracles/web.js +464 -73
- 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.js +145 -33
- package/package.json +56 -47
- package/skills/vibecode-anything/SKILL.md +75 -52
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { splitCommand } from "./exec.js";
|
|
5
|
+
import { ensureDir, resolveWorkspace } from "./store.js";
|
|
6
|
+
export const REPLAY_CACHE_SCHEMA_VERSION = "1";
|
|
7
|
+
export const REPLAY_CACHE_FILENAME = "replay.json";
|
|
8
|
+
const IGNORED_DIRS = new Set([".git", "node_modules", ".vibecode", ".vibecode-vault"]);
|
|
9
|
+
const LIVE_URL_RE = /^https?:\/\//i;
|
|
10
|
+
function canonicalSerialize(value, seen) {
|
|
11
|
+
if (value === null)
|
|
12
|
+
return "null";
|
|
13
|
+
if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "bigint") {
|
|
17
|
+
return JSON.stringify(value.toString());
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === "undefined" || typeof value === "function" || typeof value === "symbol") {
|
|
20
|
+
return "null";
|
|
21
|
+
}
|
|
22
|
+
const obj = value;
|
|
23
|
+
if (seen.has(obj)) {
|
|
24
|
+
return JSON.stringify("[Circular]");
|
|
25
|
+
}
|
|
26
|
+
if (obj instanceof Date) {
|
|
27
|
+
return JSON.stringify(obj.toISOString());
|
|
28
|
+
}
|
|
29
|
+
if (obj instanceof RegExp) {
|
|
30
|
+
return JSON.stringify(obj.toString());
|
|
31
|
+
}
|
|
32
|
+
if (Buffer.isBuffer(obj)) {
|
|
33
|
+
return JSON.stringify(`buffer:${obj.toString("hex")}`);
|
|
34
|
+
}
|
|
35
|
+
if (ArrayBuffer.isView(obj)) {
|
|
36
|
+
const view = new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength);
|
|
37
|
+
return JSON.stringify(`bytes:${Buffer.from(view).toString("hex")}`);
|
|
38
|
+
}
|
|
39
|
+
seen.add(obj);
|
|
40
|
+
try {
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
const items = obj.map((item) => canonicalSerialize(item, seen));
|
|
43
|
+
return `[${items.join(",")}]`;
|
|
44
|
+
}
|
|
45
|
+
const record = obj;
|
|
46
|
+
const keys = Object.keys(record).sort();
|
|
47
|
+
const parts = [];
|
|
48
|
+
for (const key of keys) {
|
|
49
|
+
const val = record[key];
|
|
50
|
+
if (val === undefined || typeof val === "function" || typeof val === "symbol") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
parts.push(`${JSON.stringify(key)}:${canonicalSerialize(val, seen)}`);
|
|
54
|
+
}
|
|
55
|
+
return `{${parts.join(",")}}`;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
seen.delete(obj);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deterministic SHA-256 hex digest over canonical key-sorted JSON.
|
|
63
|
+
*/
|
|
64
|
+
export function stableHash(value) {
|
|
65
|
+
const canonical = canonicalSerialize(value, new Set());
|
|
66
|
+
return crypto.createHash("sha256").update(canonical).digest("hex");
|
|
67
|
+
}
|
|
68
|
+
function normalizeRelPath(baseDir, fullPath) {
|
|
69
|
+
const rel = path.relative(baseDir, fullPath);
|
|
70
|
+
return rel.split(path.sep).join("/");
|
|
71
|
+
}
|
|
72
|
+
function hashSingleFile(fullPath, labelPath) {
|
|
73
|
+
try {
|
|
74
|
+
const stat = fs.statSync(fullPath);
|
|
75
|
+
if (!stat.isFile())
|
|
76
|
+
return null;
|
|
77
|
+
const content = fs.readFileSync(fullPath);
|
|
78
|
+
const sha256 = crypto.createHash("sha256").update(content).digest("hex");
|
|
79
|
+
return {
|
|
80
|
+
path: labelPath,
|
|
81
|
+
size: stat.size,
|
|
82
|
+
sha256
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function collectDirectoryFiles(rootDir, baseForLabels, visitedPaths, out) {
|
|
90
|
+
const stack = [rootDir];
|
|
91
|
+
while (stack.length > 0) {
|
|
92
|
+
const current = stack.pop();
|
|
93
|
+
let entries;
|
|
94
|
+
try {
|
|
95
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
101
|
+
for (const entry of entries) {
|
|
102
|
+
const fullPath = path.join(current, entry.name);
|
|
103
|
+
if (entry.isSymbolicLink())
|
|
104
|
+
continue;
|
|
105
|
+
if (entry.isDirectory()) {
|
|
106
|
+
if (IGNORED_DIRS.has(entry.name))
|
|
107
|
+
continue;
|
|
108
|
+
stack.push(fullPath);
|
|
109
|
+
}
|
|
110
|
+
else if (entry.isFile()) {
|
|
111
|
+
const canonicalPath = process.platform === "win32" ? fullPath.toLowerCase() : fullPath;
|
|
112
|
+
if (visitedPaths.has(canonicalPath))
|
|
113
|
+
continue;
|
|
114
|
+
visitedPaths.add(canonicalPath);
|
|
115
|
+
const record = hashSingleFile(fullPath, normalizeRelPath(baseForLabels, fullPath));
|
|
116
|
+
if (record)
|
|
117
|
+
out.push(record);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function collectTargetPath(candidatePath, baseForLabels, visitedPaths, out) {
|
|
123
|
+
let stat;
|
|
124
|
+
try {
|
|
125
|
+
stat = fs.statSync(candidatePath);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (stat.isDirectory()) {
|
|
131
|
+
collectDirectoryFiles(candidatePath, baseForLabels, visitedPaths, out);
|
|
132
|
+
}
|
|
133
|
+
else if (stat.isFile()) {
|
|
134
|
+
const canonicalPath = process.platform === "win32" ? candidatePath.toLowerCase() : candidatePath;
|
|
135
|
+
if (visitedPaths.has(canonicalPath))
|
|
136
|
+
return;
|
|
137
|
+
visitedPaths.add(canonicalPath);
|
|
138
|
+
const record = hashSingleFile(candidatePath, normalizeRelPath(baseForLabels, candidatePath));
|
|
139
|
+
if (record)
|
|
140
|
+
out.push(record);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function fingerprintStorageState(storageState, cwd) {
|
|
144
|
+
if (!storageState)
|
|
145
|
+
return null;
|
|
146
|
+
const resolved = path.resolve(cwd, storageState);
|
|
147
|
+
try {
|
|
148
|
+
const stat = fs.statSync(resolved);
|
|
149
|
+
if (stat.isFile()) {
|
|
150
|
+
const content = fs.readFileSync(resolved);
|
|
151
|
+
const sha256 = crypto.createHash("sha256").update(content).digest("hex");
|
|
152
|
+
return {
|
|
153
|
+
path: storageState,
|
|
154
|
+
exists: true,
|
|
155
|
+
mtimeMs: stat.mtimeMs,
|
|
156
|
+
size: stat.size,
|
|
157
|
+
sha256
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Fall through to missing metadata.
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
path: storageState,
|
|
166
|
+
exists: false
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Computes a deterministic SHA-256 fingerprint for a local target and context.
|
|
171
|
+
* Returns `null` for live HTTP/HTTPS URLs so remote targets are never cached.
|
|
172
|
+
*/
|
|
173
|
+
export function computeTargetFingerprint(target, cwd = process.cwd(), ctx) {
|
|
174
|
+
const trimmed = String(target ?? "").trim();
|
|
175
|
+
if (!trimmed || LIVE_URL_RE.test(trimmed)) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const resolvedCwd = path.resolve(cwd);
|
|
179
|
+
const tokens = splitCommand(trimmed);
|
|
180
|
+
const visitedPaths = new Set();
|
|
181
|
+
const files = [];
|
|
182
|
+
// Check if target is directly a local file or directory path.
|
|
183
|
+
const directPath = path.resolve(resolvedCwd, trimmed);
|
|
184
|
+
let directStat = null;
|
|
185
|
+
try {
|
|
186
|
+
directStat = fs.statSync(directPath);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
directStat = null;
|
|
190
|
+
}
|
|
191
|
+
if (directStat?.isFile()) {
|
|
192
|
+
collectTargetPath(directPath, resolvedCwd, visitedPaths, files);
|
|
193
|
+
}
|
|
194
|
+
else if (directStat?.isDirectory()) {
|
|
195
|
+
collectTargetPath(directPath, directPath, visitedPaths, files);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Local CLI command: hash any path tokens plus workspace files.
|
|
199
|
+
for (const token of tokens) {
|
|
200
|
+
if (!token || LIVE_URL_RE.test(token))
|
|
201
|
+
continue;
|
|
202
|
+
const candidates = [token];
|
|
203
|
+
const eqIdx = token.indexOf("=");
|
|
204
|
+
if (eqIdx > 0 && eqIdx < token.length - 1) {
|
|
205
|
+
candidates.push(token.slice(eqIdx + 1));
|
|
206
|
+
}
|
|
207
|
+
for (const candidate of candidates) {
|
|
208
|
+
const resolved = path.resolve(resolvedCwd, candidate);
|
|
209
|
+
if (fs.existsSync(resolved)) {
|
|
210
|
+
collectTargetPath(resolved, resolvedCwd, visitedPaths, files);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (fs.existsSync(resolvedCwd)) {
|
|
215
|
+
collectTargetPath(resolvedCwd, resolvedCwd, visitedPaths, files);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
219
|
+
return stableHash({
|
|
220
|
+
target: trimmed,
|
|
221
|
+
tokens,
|
|
222
|
+
files,
|
|
223
|
+
headers: ctx?.headers ?? null,
|
|
224
|
+
storageState: fingerprintStorageState(ctx?.storageState, resolvedCwd),
|
|
225
|
+
strict: Boolean(ctx?.strict)
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Computes a deterministic SHA-256 cache key for an invariant + target fingerprint.
|
|
230
|
+
*/
|
|
231
|
+
export function computeInvariantCacheKey(invariant, targetFingerprint, strict) {
|
|
232
|
+
return stableHash({
|
|
233
|
+
formatVersion: REPLAY_CACHE_SCHEMA_VERSION,
|
|
234
|
+
invariant,
|
|
235
|
+
targetFingerprint,
|
|
236
|
+
strict: Boolean(strict)
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function emptyStore() {
|
|
240
|
+
return {
|
|
241
|
+
schemaVersion: REPLAY_CACHE_SCHEMA_VERSION,
|
|
242
|
+
entries: {}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function isPlainRecord(value) {
|
|
246
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
247
|
+
}
|
|
248
|
+
function isValidCacheEntry(value) {
|
|
249
|
+
if (!isPlainRecord(value))
|
|
250
|
+
return false;
|
|
251
|
+
if (typeof value.key !== "string" ||
|
|
252
|
+
typeof value.invariantId !== "string" ||
|
|
253
|
+
typeof value.targetFingerprint !== "string" ||
|
|
254
|
+
typeof value.cachedAt !== "string" ||
|
|
255
|
+
typeof value.lastUsedAt !== "string") {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
if (!isPlainRecord(value.result))
|
|
259
|
+
return false;
|
|
260
|
+
if (typeof value.result.id !== "string" || typeof value.result.status !== "string") {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Loads `.vibecode/cache/replay.json`. Recovers gracefully with an empty store
|
|
267
|
+
* if the file is missing, unreadable, malformed, or has an incompatible schema.
|
|
268
|
+
*/
|
|
269
|
+
export function loadReplayCache(workspaceDir) {
|
|
270
|
+
const { cacheDir } = resolveWorkspace(workspaceDir);
|
|
271
|
+
const filePath = path.join(cacheDir, REPLAY_CACHE_FILENAME);
|
|
272
|
+
if (!fs.existsSync(filePath)) {
|
|
273
|
+
return emptyStore();
|
|
274
|
+
}
|
|
275
|
+
let parsed;
|
|
276
|
+
try {
|
|
277
|
+
parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return emptyStore();
|
|
281
|
+
}
|
|
282
|
+
if (!isPlainRecord(parsed)) {
|
|
283
|
+
return emptyStore();
|
|
284
|
+
}
|
|
285
|
+
if (parsed.schemaVersion !== REPLAY_CACHE_SCHEMA_VERSION) {
|
|
286
|
+
return emptyStore();
|
|
287
|
+
}
|
|
288
|
+
if (!isPlainRecord(parsed.entries)) {
|
|
289
|
+
return emptyStore();
|
|
290
|
+
}
|
|
291
|
+
const entries = {};
|
|
292
|
+
for (const [key, rawEntry] of Object.entries(parsed.entries)) {
|
|
293
|
+
if (isValidCacheEntry(rawEntry) && rawEntry.key === key) {
|
|
294
|
+
entries[key] = rawEntry;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
schemaVersion: REPLAY_CACHE_SCHEMA_VERSION,
|
|
299
|
+
entries
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function parseTimestamp(iso) {
|
|
303
|
+
const ms = Date.parse(iso);
|
|
304
|
+
return Number.isFinite(ms) ? ms : 0;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Evicts oldest `lastUsedAt` entries above `maxEntries` and atomically writes
|
|
308
|
+
* `.vibecode/cache/replay.json` via `.tmp` + rename.
|
|
309
|
+
*/
|
|
310
|
+
export function saveReplayCache(workspaceDir, store, maxEntries = 500) {
|
|
311
|
+
const { cacheDir } = resolveWorkspace(workspaceDir);
|
|
312
|
+
ensureDir(cacheDir);
|
|
313
|
+
const filePath = path.join(cacheDir, REPLAY_CACHE_FILENAME);
|
|
314
|
+
const cap = Math.max(0, Math.floor(maxEntries));
|
|
315
|
+
const keys = Object.keys(store.entries);
|
|
316
|
+
if (keys.length > cap) {
|
|
317
|
+
const sorted = keys
|
|
318
|
+
.map((key) => store.entries[key])
|
|
319
|
+
.sort((a, b) => {
|
|
320
|
+
const usedDiff = parseTimestamp(a.lastUsedAt) - parseTimestamp(b.lastUsedAt);
|
|
321
|
+
if (usedDiff !== 0)
|
|
322
|
+
return usedDiff;
|
|
323
|
+
const createdDiff = parseTimestamp(a.cachedAt) - parseTimestamp(b.cachedAt);
|
|
324
|
+
if (createdDiff !== 0)
|
|
325
|
+
return createdDiff;
|
|
326
|
+
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
327
|
+
});
|
|
328
|
+
const toRemove = sorted.length - cap;
|
|
329
|
+
for (let i = 0; i < toRemove; i++) {
|
|
330
|
+
delete store.entries[sorted[i].key];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const payload = {
|
|
334
|
+
schemaVersion: REPLAY_CACHE_SCHEMA_VERSION,
|
|
335
|
+
entries: store.entries
|
|
336
|
+
};
|
|
337
|
+
const tmpPath = `${filePath}.tmp`;
|
|
338
|
+
fs.writeFileSync(tmpPath, JSON.stringify(payload, null, 2) + "\n", "utf8");
|
|
339
|
+
fs.renameSync(tmpPath, filePath);
|
|
340
|
+
return filePath;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Looks up a cached passing result for `invariant` under `ctx`.
|
|
344
|
+
* Never returns cached hits for holdout invariants, non-passing results, or live URLs.
|
|
345
|
+
*/
|
|
346
|
+
export function lookupCachedResult(store, invariant, ctx) {
|
|
347
|
+
if (invariant.holdout === true) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
const targetFingerprint = computeTargetFingerprint(ctx.target, ctx.cwd ?? process.cwd(), {
|
|
351
|
+
headers: ctx.headers,
|
|
352
|
+
storageState: ctx.storageState,
|
|
353
|
+
strict: ctx.strict
|
|
354
|
+
});
|
|
355
|
+
if (targetFingerprint === null) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
const key = computeInvariantCacheKey(invariant, targetFingerprint, Boolean(ctx.strict));
|
|
359
|
+
const entry = store.entries[key];
|
|
360
|
+
if (!entry || entry.result.status !== "pass") {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
entry.lastUsedAt = new Date().toISOString();
|
|
364
|
+
const cloned = structuredClone(entry.result);
|
|
365
|
+
return {
|
|
366
|
+
...cloned,
|
|
367
|
+
metrics: {
|
|
368
|
+
...(cloned.metrics ?? {}),
|
|
369
|
+
cached: true
|
|
370
|
+
},
|
|
371
|
+
durationMs: 0
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Stores a passing non-holdout result for a cacheable local target.
|
|
376
|
+
*/
|
|
377
|
+
export function storeCachedResult(store, invariant, ctx, result) {
|
|
378
|
+
if (invariant.holdout === true) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
if (result.status !== "pass") {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
const targetFingerprint = computeTargetFingerprint(ctx.target, ctx.cwd ?? process.cwd(), {
|
|
385
|
+
headers: ctx.headers,
|
|
386
|
+
storageState: ctx.storageState,
|
|
387
|
+
strict: ctx.strict
|
|
388
|
+
});
|
|
389
|
+
if (targetFingerprint === null) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
const key = computeInvariantCacheKey(invariant, targetFingerprint, Boolean(ctx.strict));
|
|
393
|
+
const now = new Date().toISOString();
|
|
394
|
+
store.entries[key] = {
|
|
395
|
+
key,
|
|
396
|
+
invariantId: invariant.id,
|
|
397
|
+
targetFingerprint,
|
|
398
|
+
result: structuredClone(result),
|
|
399
|
+
cachedAt: now,
|
|
400
|
+
lastUsedAt: now
|
|
401
|
+
};
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ContractV02 } from "./types.js";
|
|
2
|
+
export type CiExportFormat = "github-actions" | "gitlab-ci" | "makefile";
|
|
3
|
+
export interface ExportCiOptions {
|
|
4
|
+
format?: CiExportFormat;
|
|
5
|
+
title?: string;
|
|
6
|
+
target?: string;
|
|
7
|
+
strict?: boolean;
|
|
8
|
+
cache?: boolean;
|
|
9
|
+
nodeVersion?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ExportCiResult {
|
|
12
|
+
format: CiExportFormat;
|
|
13
|
+
content: string;
|
|
14
|
+
fileExtension: string;
|
|
15
|
+
defaultFileName: string;
|
|
16
|
+
invariantCount: number;
|
|
17
|
+
domainSummary: string[];
|
|
18
|
+
sliceIds: string[];
|
|
19
|
+
warnings: string[];
|
|
20
|
+
outPath?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compile a ContractV02 into a zero-dependency CI/CD parity pipeline
|
|
24
|
+
* (`github-actions`, `gitlab-ci`, or `makefile`) with 100% holdout invisibility
|
|
25
|
+
* and hardened secret/injection sanitization.
|
|
26
|
+
*/
|
|
27
|
+
export declare function exportCiPipeline(contract: ContractV02, options?: ExportCiOptions): ExportCiResult;
|
|
28
|
+
/**
|
|
29
|
+
* Generate and atomically write a CI/CD parity pipeline to disk (temp file + rename).
|
|
30
|
+
*/
|
|
31
|
+
export declare function writeCiPipeline(contract: ContractV02, outPath: string, options?: ExportCiOptions): ExportCiResult;
|
|
32
|
+
/**
|
|
33
|
+
* Format a concise, sanitized terminal summary for a CI pipeline export result.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatPrettyCiExport(result: ExportCiResult, outPath?: string, color?: boolean): string;
|