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.
- package/LICENSE +21 -0
- package/README.md +235 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +452 -0
- package/dist/core/adapters.d.ts +8 -0
- package/dist/core/adapters.js +92 -0
- package/dist/core/diff.d.ts +10 -0
- package/dist/core/diff.js +207 -0
- package/dist/core/doctor.d.ts +50 -0
- package/dist/core/doctor.js +312 -0
- package/dist/core/errors.d.ts +32 -0
- package/dist/core/errors.js +81 -0
- package/dist/core/exec.d.ts +14 -0
- package/dist/core/exec.js +109 -0
- package/dist/core/parity.d.ts +9 -0
- package/dist/core/parity.js +138 -0
- package/dist/core/png.d.ts +7 -0
- package/dist/core/png.js +303 -0
- package/dist/core/schema.d.ts +17 -0
- package/dist/core/schema.js +614 -0
- package/dist/core/slices.d.ts +24 -0
- package/dist/core/slices.js +294 -0
- package/dist/core/store.d.ts +17 -0
- package/dist/core/store.js +97 -0
- package/dist/core/types.d.ts +751 -0
- package/dist/core/types.js +4 -0
- package/dist/core/visual.d.ts +34 -0
- package/dist/core/visual.js +459 -0
- package/dist/core/watch.d.ts +53 -0
- package/dist/core/watch.js +285 -0
- package/dist/ingestors/api-repo.d.ts +5 -0
- package/dist/ingestors/api-repo.js +722 -0
- package/dist/ingestors/bridges.d.ts +3 -0
- package/dist/ingestors/bridges.js +562 -0
- package/dist/ingestors/cli.d.ts +9 -0
- package/dist/ingestors/cli.js +266 -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 +97 -0
- package/dist/ingestors/video.d.ts +47 -0
- package/dist/ingestors/video.js +605 -0
- package/dist/ingestors/web.d.ts +25 -0
- package/dist/ingestors/web.js +397 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +504 -0
- package/dist/oracles/api-repo.d.ts +2 -0
- package/dist/oracles/api-repo.js +214 -0
- package/dist/oracles/cli.d.ts +2 -0
- package/dist/oracles/cli.js +157 -0
- package/dist/oracles/image.d.ts +2 -0
- package/dist/oracles/image.js +279 -0
- package/dist/oracles/index.d.ts +4 -0
- package/dist/oracles/index.js +91 -0
- package/dist/oracles/video.d.ts +21 -0
- package/dist/oracles/video.js +411 -0
- package/dist/oracles/web.d.ts +2 -0
- package/dist/oracles/web.js +480 -0
- package/dist/setup/index.d.ts +7 -0
- package/dist/setup/index.js +186 -0
- package/package.json +47 -6
- package/skills/vibecode-anything/SKILL.md +52 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { VibecodeError } from "./errors.js";
|
|
2
|
+
import { assertValidContract } from "./schema.js";
|
|
3
|
+
function clone(value) {
|
|
4
|
+
return JSON.parse(JSON.stringify(value));
|
|
5
|
+
}
|
|
6
|
+
const SLICE_RULES = [
|
|
7
|
+
{
|
|
8
|
+
id: "cli-core",
|
|
9
|
+
title: "CLI Commands & Behavior",
|
|
10
|
+
match: (domain, type) => domain === "cli" && type === "command"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "web-routes",
|
|
14
|
+
title: "Web Routes & Landmarks",
|
|
15
|
+
match: (domain, type) => domain === "web" && type === "web_route"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "web-flows",
|
|
19
|
+
title: "Interactive Web Flows & Network",
|
|
20
|
+
match: (domain, type) => domain === "web" && (type === "web_flow" || type === "web_network"),
|
|
21
|
+
dependsOn: ["web-routes"]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "api-endpoints",
|
|
25
|
+
title: "HTTP API Endpoints",
|
|
26
|
+
match: (domain, type) => domain === "api" && type === "http"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "repo-exports",
|
|
30
|
+
title: "Repository Exports",
|
|
31
|
+
match: (domain, type) => domain === "repo" && type === "repo_exports"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "image-layout",
|
|
35
|
+
title: "Image Dimensions & Layout",
|
|
36
|
+
match: (domain, type) => domain === "image" && type === "image_layout"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "image-perceptual",
|
|
40
|
+
title: "Image Perceptual Similarity",
|
|
41
|
+
match: (domain, type) => domain === "image" && type === "image_perceptual",
|
|
42
|
+
dependsOn: ["image-layout"]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "video-timeline",
|
|
46
|
+
title: "Video State Timeline & Motion",
|
|
47
|
+
match: (domain, type) => domain === "video" && type === "video_timeline"
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
/** Build deterministic slices from the invariant domains/types in a contract. */
|
|
51
|
+
export function deriveDefaultSlices(contract) {
|
|
52
|
+
const severityById = new Map();
|
|
53
|
+
for (const inv of contract.invariants || []) {
|
|
54
|
+
severityById.set(inv.id, inv.severity);
|
|
55
|
+
}
|
|
56
|
+
const hardFirst = (a, b) => {
|
|
57
|
+
const aHard = severityById.get(a) === "hard" ? 0 : 1;
|
|
58
|
+
const bHard = severityById.get(b) === "hard" ? 0 : 1;
|
|
59
|
+
return aHard - bHard;
|
|
60
|
+
};
|
|
61
|
+
const slices = [];
|
|
62
|
+
const byId = new Map();
|
|
63
|
+
for (const rule of SLICE_RULES) {
|
|
64
|
+
const matches = (contract.invariants || [])
|
|
65
|
+
.filter((inv) => rule.match(inv.domain, inv.type))
|
|
66
|
+
.map((inv) => inv.id)
|
|
67
|
+
.sort(hardFirst);
|
|
68
|
+
if (matches.length === 0)
|
|
69
|
+
continue;
|
|
70
|
+
const slice = {
|
|
71
|
+
id: rule.id,
|
|
72
|
+
title: rule.title,
|
|
73
|
+
invariantIds: matches,
|
|
74
|
+
status: "pending"
|
|
75
|
+
};
|
|
76
|
+
const deps = rule.dependsOn;
|
|
77
|
+
if (deps && slices.some((s) => deps.includes(s.id))) {
|
|
78
|
+
slice.dependsOn = [...deps];
|
|
79
|
+
}
|
|
80
|
+
slices.push(slice);
|
|
81
|
+
byId.set(slice.id, slice);
|
|
82
|
+
}
|
|
83
|
+
const usedIds = new Set(slices.flatMap((s) => s.invariantIds));
|
|
84
|
+
for (const inv of contract.invariants || []) {
|
|
85
|
+
if (usedIds.has(inv.id))
|
|
86
|
+
continue;
|
|
87
|
+
const id = `${inv.domain}-${inv.type}`;
|
|
88
|
+
let slice = byId.get(id);
|
|
89
|
+
if (!slice) {
|
|
90
|
+
slice = {
|
|
91
|
+
id,
|
|
92
|
+
title: `${inv.domain} ${inv.type.replace(/_/g, " ")}`,
|
|
93
|
+
invariantIds: [],
|
|
94
|
+
status: "pending"
|
|
95
|
+
};
|
|
96
|
+
slices.push(slice);
|
|
97
|
+
byId.set(id, slice);
|
|
98
|
+
}
|
|
99
|
+
slice.invariantIds.push(inv.id);
|
|
100
|
+
}
|
|
101
|
+
for (const slice of slices) {
|
|
102
|
+
slice.invariantIds.sort(hardFirst);
|
|
103
|
+
}
|
|
104
|
+
return slices;
|
|
105
|
+
}
|
|
106
|
+
/** Return persisted slices when present, otherwise derived defaults. */
|
|
107
|
+
export function getContractSlices(contract) {
|
|
108
|
+
if (Array.isArray(contract.slices) && contract.slices.length > 0) {
|
|
109
|
+
return clone(contract.slices);
|
|
110
|
+
}
|
|
111
|
+
return deriveDefaultSlices(contract);
|
|
112
|
+
}
|
|
113
|
+
function parseSliceIds(sliceIds) {
|
|
114
|
+
const raw = Array.isArray(sliceIds)
|
|
115
|
+
? sliceIds
|
|
116
|
+
: typeof sliceIds === "string"
|
|
117
|
+
? sliceIds.split(",")
|
|
118
|
+
: [];
|
|
119
|
+
const out = [];
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
for (const value of raw) {
|
|
122
|
+
const id = String(value).trim();
|
|
123
|
+
if (id && !seen.has(id)) {
|
|
124
|
+
seen.add(id);
|
|
125
|
+
out.push(id);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/** Resolve slice IDs (single, comma-separated, or array) to slices and invariant IDs. */
|
|
131
|
+
export function resolveSliceInvariants(contract, sliceIds) {
|
|
132
|
+
const requested = parseSliceIds(sliceIds);
|
|
133
|
+
if (requested.length === 0) {
|
|
134
|
+
throw new VibecodeError("TARGET_MISSING", "At least one slice id is required");
|
|
135
|
+
}
|
|
136
|
+
const available = getContractSlices(contract);
|
|
137
|
+
const byId = new Map(available.map((slice) => [slice.id, slice]));
|
|
138
|
+
const unknown = requested.filter((id) => !byId.has(id));
|
|
139
|
+
if (unknown.length > 0) {
|
|
140
|
+
const valid = available.map((slice) => slice.id);
|
|
141
|
+
throw new VibecodeError("NOT_FOUND", `Unknown slice id(s): ${unknown.join(", ")}. Valid slice ids: ${valid.length > 0 ? valid.join(", ") : "(none)"}`, { details: { unknown, valid } });
|
|
142
|
+
}
|
|
143
|
+
const slices = requested.map((id) => clone(byId.get(id)));
|
|
144
|
+
const invariantIds = [];
|
|
145
|
+
const seen = new Set();
|
|
146
|
+
for (const slice of slices) {
|
|
147
|
+
for (const id of slice.invariantIds) {
|
|
148
|
+
if (!seen.has(id)) {
|
|
149
|
+
seen.add(id);
|
|
150
|
+
invariantIds.push(id);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { slices, invariantIds };
|
|
155
|
+
}
|
|
156
|
+
function clampScore(value) {
|
|
157
|
+
const bounded = Math.min(1, Math.max(0, value));
|
|
158
|
+
return Math.round(bounded * 10000) / 10000;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Apply a parity report to slice progress. Untargeted slices are only touched when
|
|
162
|
+
* one of their invariants was actually evaluated in the report.
|
|
163
|
+
*/
|
|
164
|
+
export function updateSliceProgress(contract, report, options = {}) {
|
|
165
|
+
const results = new Map();
|
|
166
|
+
for (const result of report.results || []) {
|
|
167
|
+
results.set(result.id, result);
|
|
168
|
+
}
|
|
169
|
+
const targeted = options.sliceIds && options.sliceIds.length > 0 ? new Set(options.sliceIds) : null;
|
|
170
|
+
const timestamp = options.timestamp ?? report.timestamp ?? new Date().toISOString();
|
|
171
|
+
const updated = getContractSlices(contract);
|
|
172
|
+
const nextSlices = updated.map((slice) => {
|
|
173
|
+
const isTargeted = targeted !== null && targeted.has(slice.id);
|
|
174
|
+
const evaluated = slice.invariantIds
|
|
175
|
+
.map((id) => results.get(id))
|
|
176
|
+
.filter((entry) => entry !== undefined);
|
|
177
|
+
const hasEvaluated = evaluated.length > 0;
|
|
178
|
+
if (!hasEvaluated) {
|
|
179
|
+
if (isTargeted) {
|
|
180
|
+
const next = { ...slice, status: "skipped" };
|
|
181
|
+
delete next.lastScore;
|
|
182
|
+
return next;
|
|
183
|
+
}
|
|
184
|
+
return slice;
|
|
185
|
+
}
|
|
186
|
+
const anyFailure = evaluated.some((result) => result.status === "fail" || result.status === "error");
|
|
187
|
+
const allSkipped = evaluated.every((result) => result.status === "skipped");
|
|
188
|
+
const allEvaluated = evaluated.length === slice.invariantIds.length;
|
|
189
|
+
const nonSkipped = evaluated.filter((result) => result.status !== "skipped");
|
|
190
|
+
const allPassOrWarn = nonSkipped.every((result) => result.status === "pass" || result.status === "warn");
|
|
191
|
+
let status;
|
|
192
|
+
if (allSkipped) {
|
|
193
|
+
status = "skipped";
|
|
194
|
+
}
|
|
195
|
+
else if (anyFailure) {
|
|
196
|
+
status = "failed";
|
|
197
|
+
}
|
|
198
|
+
else if (allEvaluated && allPassOrWarn) {
|
|
199
|
+
status = "passed";
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
status = "in_progress";
|
|
203
|
+
}
|
|
204
|
+
const next = { ...slice, status, lastVerifiedAt: timestamp };
|
|
205
|
+
if (nonSkipped.length === 0) {
|
|
206
|
+
delete next.lastScore;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const scores = nonSkipped.map((result) => (typeof result.score === "number" ? result.score : 0));
|
|
210
|
+
next.lastScore = clampScore(scores.reduce((sum, value) => sum + value, 0) / scores.length);
|
|
211
|
+
}
|
|
212
|
+
return next;
|
|
213
|
+
});
|
|
214
|
+
const nextContract = clone(contract);
|
|
215
|
+
nextContract.slices = nextSlices;
|
|
216
|
+
return nextContract;
|
|
217
|
+
}
|
|
218
|
+
/** Summarize slice progress and identify the next actionable slice. */
|
|
219
|
+
export function summarizeSlices(contract) {
|
|
220
|
+
const slices = getContractSlices(contract);
|
|
221
|
+
const summary = {
|
|
222
|
+
total: slices.length,
|
|
223
|
+
passed: 0,
|
|
224
|
+
failed: 0,
|
|
225
|
+
inProgress: 0,
|
|
226
|
+
pending: 0,
|
|
227
|
+
skipped: 0,
|
|
228
|
+
completionRatio: 0,
|
|
229
|
+
nextSlice: null,
|
|
230
|
+
slices: []
|
|
231
|
+
};
|
|
232
|
+
const items = slices.map((slice) => {
|
|
233
|
+
switch (slice.status) {
|
|
234
|
+
case "passed":
|
|
235
|
+
summary.passed += 1;
|
|
236
|
+
break;
|
|
237
|
+
case "failed":
|
|
238
|
+
summary.failed += 1;
|
|
239
|
+
break;
|
|
240
|
+
case "in_progress":
|
|
241
|
+
summary.inProgress += 1;
|
|
242
|
+
break;
|
|
243
|
+
case "skipped":
|
|
244
|
+
summary.skipped += 1;
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
summary.pending += 1;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
id: slice.id,
|
|
252
|
+
title: slice.title,
|
|
253
|
+
status: slice.status,
|
|
254
|
+
invariantCount: slice.invariantIds.length,
|
|
255
|
+
dependsOn: slice.dependsOn ? [...slice.dependsOn] : [],
|
|
256
|
+
...(slice.lastVerifiedAt ? { lastVerifiedAt: slice.lastVerifiedAt } : {}),
|
|
257
|
+
...(slice.lastScore !== undefined ? { lastScore: slice.lastScore } : {})
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
summary.completionRatio = summary.total > 0 ? summary.passed / summary.total : 0;
|
|
261
|
+
const notPassed = slices.filter((slice) => slice.status !== "passed");
|
|
262
|
+
const byId = new Map(slices.map((candidate) => [candidate.id, candidate]));
|
|
263
|
+
const ready = notPassed.find((slice) => {
|
|
264
|
+
const deps = slice.dependsOn || [];
|
|
265
|
+
return deps.every((dep) => byId.get(dep)?.status === "passed");
|
|
266
|
+
});
|
|
267
|
+
summary.nextSlice = (ready || notPassed[0])?.id ?? null;
|
|
268
|
+
summary.slices = items;
|
|
269
|
+
return summary;
|
|
270
|
+
}
|
|
271
|
+
/** Insert or replace a slice, validating references and dependencies. */
|
|
272
|
+
export function addOrUpdateSlice(contract, slice) {
|
|
273
|
+
const next = clone(contract);
|
|
274
|
+
const slices = getContractSlices(next);
|
|
275
|
+
const incoming = {
|
|
276
|
+
id: slice.id,
|
|
277
|
+
title: slice.title,
|
|
278
|
+
invariantIds: [...slice.invariantIds],
|
|
279
|
+
status: slice.status ?? "pending",
|
|
280
|
+
...(slice.description !== undefined ? { description: slice.description } : {}),
|
|
281
|
+
...(slice.dependsOn !== undefined ? { dependsOn: [...slice.dependsOn] } : {}),
|
|
282
|
+
...(slice.lastVerifiedAt !== undefined ? { lastVerifiedAt: slice.lastVerifiedAt } : {}),
|
|
283
|
+
...(slice.lastScore !== undefined ? { lastScore: slice.lastScore } : {}),
|
|
284
|
+
...(slice.notes !== undefined ? { notes: slice.notes } : {})
|
|
285
|
+
};
|
|
286
|
+
const index = slices.findIndex((entry) => entry.id === incoming.id);
|
|
287
|
+
if (index >= 0)
|
|
288
|
+
slices[index] = incoming;
|
|
289
|
+
else
|
|
290
|
+
slices.push(incoming);
|
|
291
|
+
next.slices = slices;
|
|
292
|
+
assertValidContract(next);
|
|
293
|
+
return next;
|
|
294
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ContractV02, ParityReport, WorkspacePaths } from "./types.js";
|
|
2
|
+
export declare const CONTRACT_DIR = ".vibecode";
|
|
3
|
+
export declare const CONTRACT_FILE: string;
|
|
4
|
+
export declare const LAST_REPORT_FILE: string;
|
|
5
|
+
export declare const ARTIFACTS_DIR: string;
|
|
6
|
+
export declare const CACHE_DIR: string;
|
|
7
|
+
export declare function resolveWorkspace(cwd?: string): WorkspacePaths;
|
|
8
|
+
export declare function ensureDir(dir: string): void;
|
|
9
|
+
export declare function readContract(cwd?: string): ContractV02;
|
|
10
|
+
export declare function readRawContract(cwd?: string): unknown;
|
|
11
|
+
export declare function writeContract(contract: unknown, cwd?: string, { force }?: {
|
|
12
|
+
force?: boolean;
|
|
13
|
+
}): string;
|
|
14
|
+
export declare function saveArtifact(bufferOrPath: Buffer | Uint8Array | string, relName: string, cwd?: string): string;
|
|
15
|
+
export declare function writeLastReport(report: ParityReport, cwd?: string): string;
|
|
16
|
+
export declare function readLastReport(cwd?: string): ParityReport | null;
|
|
17
|
+
export declare function artifactPath(relName: string, cwd?: string): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { VibecodeError, errorMessage } from "./errors.js";
|
|
4
|
+
import { normalizeContract, assertValidContract } from "./schema.js";
|
|
5
|
+
export const CONTRACT_DIR = ".vibecode";
|
|
6
|
+
export const CONTRACT_FILE = path.join(CONTRACT_DIR, "contract.json");
|
|
7
|
+
export const LAST_REPORT_FILE = path.join(CONTRACT_DIR, "last-report.json");
|
|
8
|
+
export const ARTIFACTS_DIR = path.join(CONTRACT_DIR, "artifacts");
|
|
9
|
+
export const CACHE_DIR = path.join(CONTRACT_DIR, "cache");
|
|
10
|
+
export function resolveWorkspace(cwd = process.cwd()) {
|
|
11
|
+
const rootDir = path.resolve(cwd);
|
|
12
|
+
return {
|
|
13
|
+
rootDir,
|
|
14
|
+
contractPath: path.join(rootDir, CONTRACT_FILE),
|
|
15
|
+
reportPath: path.join(rootDir, LAST_REPORT_FILE),
|
|
16
|
+
artifactsDir: path.join(rootDir, ARTIFACTS_DIR),
|
|
17
|
+
cacheDir: path.join(rootDir, CACHE_DIR)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function ensureDir(dir) {
|
|
21
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
export function readContract(cwd = process.cwd()) {
|
|
24
|
+
const { contractPath } = resolveWorkspace(cwd);
|
|
25
|
+
if (!fs.existsSync(contractPath)) {
|
|
26
|
+
throw new VibecodeError("CONTRACT_NOT_FOUND", `Missing ${CONTRACT_FILE}. Run 'vibecode-anything init' first.`);
|
|
27
|
+
}
|
|
28
|
+
let raw;
|
|
29
|
+
try {
|
|
30
|
+
raw = JSON.parse(fs.readFileSync(contractPath, "utf8"));
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw new VibecodeError("CONTRACT_INVALID", `Failed to parse ${CONTRACT_FILE}: ${errorMessage(err)}`, { details: err });
|
|
34
|
+
}
|
|
35
|
+
const normalized = normalizeContract(raw);
|
|
36
|
+
assertValidContract(normalized);
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
export function readRawContract(cwd = process.cwd()) {
|
|
40
|
+
const { contractPath } = resolveWorkspace(cwd);
|
|
41
|
+
if (!fs.existsSync(contractPath)) {
|
|
42
|
+
throw new VibecodeError("CONTRACT_NOT_FOUND", `Missing ${CONTRACT_FILE}. Run 'vibecode-anything init' first.`);
|
|
43
|
+
}
|
|
44
|
+
return JSON.parse(fs.readFileSync(contractPath, "utf8"));
|
|
45
|
+
}
|
|
46
|
+
export function writeContract(contract, cwd = process.cwd(), { force = false } = {}) {
|
|
47
|
+
const { rootDir, contractPath } = resolveWorkspace(cwd);
|
|
48
|
+
const contractDir = path.join(rootDir, CONTRACT_DIR);
|
|
49
|
+
ensureDir(contractDir);
|
|
50
|
+
if (fs.existsSync(contractPath) && !force) {
|
|
51
|
+
throw new VibecodeError("CONTRACT_INVALID", `Contract already exists at ${CONTRACT_FILE}. Use --force to overwrite.`);
|
|
52
|
+
}
|
|
53
|
+
const normalized = normalizeContract(contract);
|
|
54
|
+
assertValidContract(normalized);
|
|
55
|
+
const tmp = contractPath + ".tmp";
|
|
56
|
+
fs.writeFileSync(tmp, JSON.stringify(normalized, null, 2) + "\n", "utf8");
|
|
57
|
+
fs.renameSync(tmp, contractPath);
|
|
58
|
+
return contractPath;
|
|
59
|
+
}
|
|
60
|
+
export function saveArtifact(bufferOrPath, relName, cwd = process.cwd()) {
|
|
61
|
+
const { artifactsDir } = resolveWorkspace(cwd);
|
|
62
|
+
ensureDir(artifactsDir);
|
|
63
|
+
// sanitize relName to prevent path traversal
|
|
64
|
+
const safeRel = relName.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\.\.(\/|$)/g, "");
|
|
65
|
+
const outPath = path.join(artifactsDir, ...safeRel.split("/"));
|
|
66
|
+
ensureDir(path.dirname(outPath));
|
|
67
|
+
if (Buffer.isBuffer(bufferOrPath) || bufferOrPath instanceof Uint8Array) {
|
|
68
|
+
fs.writeFileSync(outPath, bufferOrPath);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
fs.copyFileSync(bufferOrPath, outPath);
|
|
72
|
+
}
|
|
73
|
+
return safeRel;
|
|
74
|
+
}
|
|
75
|
+
export function writeLastReport(report, cwd = process.cwd()) {
|
|
76
|
+
const { reportPath } = resolveWorkspace(cwd);
|
|
77
|
+
ensureDir(path.dirname(reportPath));
|
|
78
|
+
const tmp = reportPath + ".tmp";
|
|
79
|
+
fs.writeFileSync(tmp, JSON.stringify(report, null, 2) + "\n", "utf8");
|
|
80
|
+
fs.renameSync(tmp, reportPath);
|
|
81
|
+
return reportPath;
|
|
82
|
+
}
|
|
83
|
+
export function readLastReport(cwd = process.cwd()) {
|
|
84
|
+
const { reportPath } = resolveWorkspace(cwd);
|
|
85
|
+
if (!fs.existsSync(reportPath))
|
|
86
|
+
return null;
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(fs.readFileSync(reportPath, "utf8"));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function artifactPath(relName, cwd = process.cwd()) {
|
|
95
|
+
const { artifactsDir } = resolveWorkspace(cwd);
|
|
96
|
+
return path.join(artifactsDir, ...relName.replace(/\\/g, "/").split("/"));
|
|
97
|
+
}
|