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,495 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { VibecodeError, errorMessage, errorCode } from "./errors.js";
|
|
4
|
+
import { analyzeImpact } from "./impact.js";
|
|
5
|
+
import { scoreReport } from "./parity.js";
|
|
6
|
+
import { sanitizeSingleLine } from "./security.js";
|
|
7
|
+
import { readContract, writeContract, writeLastReport, resolveWorkspace } from "./store.js";
|
|
8
|
+
import { redactRuntimeVars } from "./target-map.js";
|
|
9
|
+
import { verifyContract as defaultVerifyContract } from "../oracles/index.js";
|
|
10
|
+
import { resolveSliceInvariants, updateSliceProgress, summarizeSlices } from "./slices.js";
|
|
11
|
+
const DEFAULT_IGNORE = [".git", ".vibecode", "node_modules"];
|
|
12
|
+
function normalizedSegments(filePath, rootDir) {
|
|
13
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
14
|
+
const rel = path.relative(rootDir, filePath).replace(/\\/g, "/");
|
|
15
|
+
const base = rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? rel : normalized.replace(/^[A-Za-z]:\//, "");
|
|
16
|
+
return base.split("/").filter(Boolean);
|
|
17
|
+
}
|
|
18
|
+
function isIgnored(filePath, ignore, rootDir) {
|
|
19
|
+
const ignored = new Set(ignore.map((entry) => entry.replace(/\\/g, "/").replace(/^\.\//, "")));
|
|
20
|
+
return normalizedSegments(filePath, rootDir).some((segment) => ignored.has(segment));
|
|
21
|
+
}
|
|
22
|
+
function normalizeWatchError(error) {
|
|
23
|
+
if (error instanceof VibecodeError)
|
|
24
|
+
return error;
|
|
25
|
+
return new VibecodeError("INTERNAL_ERROR", errorMessage(error), { details: error });
|
|
26
|
+
}
|
|
27
|
+
/** Start a zero-dependency continuous verification watcher. */
|
|
28
|
+
export async function startWatch(options, deps = {}) {
|
|
29
|
+
const hasTarget = typeof options.target === "string" && options.target.trim().length > 0;
|
|
30
|
+
const hasTargets = Boolean(options.targets &&
|
|
31
|
+
typeof options.targets === "object" &&
|
|
32
|
+
!Array.isArray(options.targets) &&
|
|
33
|
+
Object.keys(options.targets).length > 0);
|
|
34
|
+
if (!hasTarget && !hasTargets) {
|
|
35
|
+
throw new VibecodeError("TARGET_MISSING", "A non-empty verification target (or non-empty targets map) is required");
|
|
36
|
+
}
|
|
37
|
+
const target = typeof options.target === "string" ? options.target : "";
|
|
38
|
+
const rootDir = resolveWorkspace(options.cwd ?? process.cwd()).rootDir;
|
|
39
|
+
const read = deps.readContract ?? readContract;
|
|
40
|
+
const verify = deps.verifyContract ?? defaultVerifyContract;
|
|
41
|
+
const writeLast = deps.writeLastReport ?? writeLastReport;
|
|
42
|
+
const write = deps.writeContract ?? writeContract;
|
|
43
|
+
const watcherFn = deps.fsWatch ??
|
|
44
|
+
((filename, opts, listener) => fs.watch(filename, opts, listener));
|
|
45
|
+
let contract = read(rootDir);
|
|
46
|
+
const sliceIds = options.sliceIds ?? [];
|
|
47
|
+
let sliceInvariantIds = [];
|
|
48
|
+
if (sliceIds.length > 0) {
|
|
49
|
+
sliceInvariantIds = resolveSliceInvariants(contract, sliceIds).invariantIds;
|
|
50
|
+
}
|
|
51
|
+
const evaluationIds = [];
|
|
52
|
+
const seenEvaluationIds = new Set();
|
|
53
|
+
for (const id of [...(options.invariantIds ?? []), ...sliceInvariantIds]) {
|
|
54
|
+
if (!seenEvaluationIds.has(id)) {
|
|
55
|
+
seenEvaluationIds.add(id);
|
|
56
|
+
evaluationIds.push(id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const updateSlices = options.updateSlices ?? Boolean(sliceIds.length > 0 || (contract.slices && contract.slices.length > 0));
|
|
60
|
+
const ignore = options.ignore ?? DEFAULT_IGNORE;
|
|
61
|
+
const debounceMs = options.debounceMs ?? 300;
|
|
62
|
+
const watchPaths = (options.watchPaths && options.watchPaths.length > 0 ? options.watchPaths : [rootDir]).map((entry) => path.resolve(rootDir, entry));
|
|
63
|
+
let doneResolve = () => { };
|
|
64
|
+
const done = new Promise((resolve) => {
|
|
65
|
+
doneResolve = resolve;
|
|
66
|
+
});
|
|
67
|
+
let finished = false;
|
|
68
|
+
const finish = () => {
|
|
69
|
+
if (finished)
|
|
70
|
+
return;
|
|
71
|
+
finished = true;
|
|
72
|
+
doneResolve();
|
|
73
|
+
};
|
|
74
|
+
const watchers = [];
|
|
75
|
+
let timer = null;
|
|
76
|
+
let running = false;
|
|
77
|
+
let pendingRun = false;
|
|
78
|
+
let pendingAllowEmpty = false;
|
|
79
|
+
const pendingFiles = new Set();
|
|
80
|
+
let closed = false;
|
|
81
|
+
let runIndex = 0;
|
|
82
|
+
let activeRun = null;
|
|
83
|
+
let previousStatuses = new Map();
|
|
84
|
+
let lastReport = null;
|
|
85
|
+
let lastResultsById = new Map();
|
|
86
|
+
let lastResultOrder = [];
|
|
87
|
+
const onAbort = () => {
|
|
88
|
+
void close();
|
|
89
|
+
};
|
|
90
|
+
const teardown = () => {
|
|
91
|
+
if (closed)
|
|
92
|
+
return;
|
|
93
|
+
closed = true;
|
|
94
|
+
if (timer) {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
timer = null;
|
|
97
|
+
}
|
|
98
|
+
for (const watcher of watchers) {
|
|
99
|
+
try {
|
|
100
|
+
watcher.close();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// A watcher that is already closed needs no further cleanup.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
watchers.length = 0;
|
|
107
|
+
if (options.signal)
|
|
108
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
109
|
+
};
|
|
110
|
+
const reportError = (error) => {
|
|
111
|
+
options.onError?.(normalizeWatchError(error));
|
|
112
|
+
};
|
|
113
|
+
const close = async () => {
|
|
114
|
+
teardown();
|
|
115
|
+
if (activeRun)
|
|
116
|
+
await activeRun.catch(() => { });
|
|
117
|
+
finish();
|
|
118
|
+
};
|
|
119
|
+
const scheduleRun = (reason, immediate = false) => {
|
|
120
|
+
if (closed)
|
|
121
|
+
return;
|
|
122
|
+
if (timer) {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
timer = null;
|
|
125
|
+
}
|
|
126
|
+
const launch = () => {
|
|
127
|
+
timer = null;
|
|
128
|
+
const changedFiles = [...pendingFiles];
|
|
129
|
+
const allowEmpty = pendingAllowEmpty;
|
|
130
|
+
pendingFiles.clear();
|
|
131
|
+
pendingAllowEmpty = false;
|
|
132
|
+
if (changedFiles.length > 0 || allowEmpty)
|
|
133
|
+
void launchRun(reason, changedFiles);
|
|
134
|
+
};
|
|
135
|
+
if (immediate || debounceMs <= 0) {
|
|
136
|
+
launch();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
timer = setTimeout(launch, debounceMs);
|
|
140
|
+
};
|
|
141
|
+
const executeRun = async (reason, files) => {
|
|
142
|
+
if (closed)
|
|
143
|
+
return;
|
|
144
|
+
const started = Date.now();
|
|
145
|
+
running = true;
|
|
146
|
+
runIndex += 1;
|
|
147
|
+
try {
|
|
148
|
+
let impact;
|
|
149
|
+
let effectiveInvariantIds = evaluationIds;
|
|
150
|
+
let isPartialSmartRun = false;
|
|
151
|
+
let skipVerify = false;
|
|
152
|
+
if (options.smart === true &&
|
|
153
|
+
(reason === "change" || reason === "manual") &&
|
|
154
|
+
files.length > 0 &&
|
|
155
|
+
lastReport !== null &&
|
|
156
|
+
lastResultsById.size > 0) {
|
|
157
|
+
const previousFailedIds = [...previousStatuses.entries()]
|
|
158
|
+
.filter(([, status]) => status === "fail" || status === "error" || status === "warn")
|
|
159
|
+
.map(([id]) => id);
|
|
160
|
+
impact = analyzeImpact(contract, files, {
|
|
161
|
+
cwd: rootDir,
|
|
162
|
+
...(options.impactGraph ? { graph: options.impactGraph } : {}),
|
|
163
|
+
previousFailedIds
|
|
164
|
+
});
|
|
165
|
+
const evalSet = evaluationIds.length > 0 ? new Set(evaluationIds) : null;
|
|
166
|
+
const selectedIds = impact.fallbackToFull
|
|
167
|
+
? evaluationIds
|
|
168
|
+
: evalSet
|
|
169
|
+
? impact.selectedInvariantIds.filter((id) => evalSet.has(id))
|
|
170
|
+
: impact.selectedInvariantIds;
|
|
171
|
+
const fullEvalCount = evaluationIds.length > 0 ? evaluationIds.length : contract.invariants.length;
|
|
172
|
+
if (!impact.fallbackToFull && selectedIds.length === 0) {
|
|
173
|
+
skipVerify = true;
|
|
174
|
+
}
|
|
175
|
+
else if (!impact.fallbackToFull && selectedIds.length > 0 && selectedIds.length < fullEvalCount) {
|
|
176
|
+
isPartialSmartRun = true;
|
|
177
|
+
effectiveInvariantIds = selectedIds;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
effectiveInvariantIds = evaluationIds;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (skipVerify && lastReport !== null) {
|
|
184
|
+
const reusedReport = {
|
|
185
|
+
...lastReport,
|
|
186
|
+
timestamp: new Date().toISOString()
|
|
187
|
+
};
|
|
188
|
+
lastReport = reusedReport;
|
|
189
|
+
writeLast(reusedReport, rootDir);
|
|
190
|
+
const slices = contract.slices && contract.slices.length > 0 ? summarizeSlices(contract) : undefined;
|
|
191
|
+
const event = {
|
|
192
|
+
runIndex,
|
|
193
|
+
reason,
|
|
194
|
+
changedFiles: [...new Set(files)],
|
|
195
|
+
timestamp: reusedReport.timestamp,
|
|
196
|
+
durationMs: Date.now() - started,
|
|
197
|
+
report: reusedReport,
|
|
198
|
+
...(impact ? { impact } : {}),
|
|
199
|
+
...(slices ? { slices } : {}),
|
|
200
|
+
newlyFixed: [],
|
|
201
|
+
newlyBroken: []
|
|
202
|
+
};
|
|
203
|
+
options.onRun?.(event);
|
|
204
|
+
if (options.maxRuns !== undefined && runIndex >= options.maxRuns) {
|
|
205
|
+
teardown();
|
|
206
|
+
finish();
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const ctx = {
|
|
211
|
+
target,
|
|
212
|
+
...(hasTargets ? { targets: options.targets } : {}),
|
|
213
|
+
...(options.vars && Object.keys(options.vars).length > 0 ? { vars: options.vars } : {}),
|
|
214
|
+
cwd: rootDir,
|
|
215
|
+
contract,
|
|
216
|
+
strict: options.strict === true,
|
|
217
|
+
...(options.mode ? { mode: options.mode } : {}),
|
|
218
|
+
...(options.concurrency !== undefined ? { concurrency: options.concurrency } : {}),
|
|
219
|
+
...(options.pluginRegistry ? { pluginRegistry: options.pluginRegistry } : {}),
|
|
220
|
+
...(effectiveInvariantIds.length > 0 ? { invariantIds: effectiveInvariantIds } : {}),
|
|
221
|
+
...(options.useCache ? { useCache: true } : {}),
|
|
222
|
+
...(options.headers ? { headers: options.headers } : {}),
|
|
223
|
+
...(options.storageState ? { storageState: options.storageState } : {}),
|
|
224
|
+
...(options.skipFixtures ? { skipFixtures: true } : {}),
|
|
225
|
+
...(options.allowFixtureCommands ? { allowFixtureCommands: true } : {})
|
|
226
|
+
};
|
|
227
|
+
const rawReport = await verify(contract, ctx, {});
|
|
228
|
+
if (closed)
|
|
229
|
+
return;
|
|
230
|
+
let report;
|
|
231
|
+
if (isPartialSmartRun) {
|
|
232
|
+
for (const res of rawReport.results || []) {
|
|
233
|
+
lastResultsById.set(res.id, res);
|
|
234
|
+
if (!lastResultOrder.includes(res.id))
|
|
235
|
+
lastResultOrder.push(res.id);
|
|
236
|
+
}
|
|
237
|
+
const mergedResults = [];
|
|
238
|
+
const emittedIds = new Set();
|
|
239
|
+
for (const inv of contract.invariants) {
|
|
240
|
+
const res = lastResultsById.get(inv.id);
|
|
241
|
+
if (res && !emittedIds.has(inv.id)) {
|
|
242
|
+
emittedIds.add(inv.id);
|
|
243
|
+
mergedResults.push(res);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const id of lastResultOrder) {
|
|
247
|
+
const res = lastResultsById.get(id);
|
|
248
|
+
if (res && !emittedIds.has(id)) {
|
|
249
|
+
emittedIds.add(id);
|
|
250
|
+
mergedResults.push(res);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
report = scoreReport(contract, mergedResults, {
|
|
254
|
+
strict: options.strict === true,
|
|
255
|
+
...(rawReport.antiCheat?.status === "suspected" ? { antiCheat: rawReport.antiCheat } : {})
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
report = rawReport;
|
|
260
|
+
lastResultsById = new Map();
|
|
261
|
+
lastResultOrder = [];
|
|
262
|
+
for (const res of report.results || []) {
|
|
263
|
+
lastResultsById.set(res.id, res);
|
|
264
|
+
if (!lastResultOrder.includes(res.id))
|
|
265
|
+
lastResultOrder.push(res.id);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
lastReport = report;
|
|
269
|
+
const newlyFixed = [];
|
|
270
|
+
const newlyBroken = [];
|
|
271
|
+
const fixedSet = new Set();
|
|
272
|
+
const brokenSet = new Set();
|
|
273
|
+
const nextStatuses = new Map();
|
|
274
|
+
for (const result of report.results || []) {
|
|
275
|
+
nextStatuses.set(result.id, result.status);
|
|
276
|
+
const previous = previousStatuses.get(result.id);
|
|
277
|
+
if (previous === undefined)
|
|
278
|
+
continue;
|
|
279
|
+
if (previous !== "pass" && result.status === "pass" && !fixedSet.has(result.id)) {
|
|
280
|
+
fixedSet.add(result.id);
|
|
281
|
+
newlyFixed.push(result.id);
|
|
282
|
+
}
|
|
283
|
+
else if (previous === "pass" && result.status !== "pass" && !brokenSet.has(result.id)) {
|
|
284
|
+
brokenSet.add(result.id);
|
|
285
|
+
newlyBroken.push(result.id);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
previousStatuses = nextStatuses;
|
|
289
|
+
writeLast(report, rootDir);
|
|
290
|
+
let slices;
|
|
291
|
+
if (updateSlices) {
|
|
292
|
+
contract = updateSliceProgress(contract, report, { sliceIds, timestamp: report.timestamp });
|
|
293
|
+
write(contract, rootDir, { force: true, preserveHoldouts: true });
|
|
294
|
+
slices = summarizeSlices(contract);
|
|
295
|
+
}
|
|
296
|
+
else if (contract.slices && contract.slices.length > 0) {
|
|
297
|
+
slices = summarizeSlices(contract);
|
|
298
|
+
}
|
|
299
|
+
const event = {
|
|
300
|
+
runIndex,
|
|
301
|
+
reason,
|
|
302
|
+
changedFiles: [...new Set(files)],
|
|
303
|
+
timestamp: report.timestamp || new Date().toISOString(),
|
|
304
|
+
durationMs: Date.now() - started,
|
|
305
|
+
report,
|
|
306
|
+
...(impact ? { impact } : {}),
|
|
307
|
+
...(slices ? { slices } : {}),
|
|
308
|
+
newlyFixed,
|
|
309
|
+
newlyBroken
|
|
310
|
+
};
|
|
311
|
+
options.onRun?.(event);
|
|
312
|
+
if (options.maxRuns !== undefined && runIndex >= options.maxRuns) {
|
|
313
|
+
teardown();
|
|
314
|
+
finish();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
reportError(normalizeWatchError(error));
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
running = false;
|
|
322
|
+
if (!closed && pendingRun) {
|
|
323
|
+
pendingRun = false;
|
|
324
|
+
scheduleRun("change");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const launchRun = (reason, files) => {
|
|
329
|
+
if (closed)
|
|
330
|
+
return;
|
|
331
|
+
const active = executeRun(reason, files);
|
|
332
|
+
activeRun = active;
|
|
333
|
+
void active.finally(() => {
|
|
334
|
+
if (activeRun === active)
|
|
335
|
+
activeRun = null;
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
const enqueue = (files, reason, allowEmpty) => {
|
|
339
|
+
if (closed)
|
|
340
|
+
return;
|
|
341
|
+
for (const file of files) {
|
|
342
|
+
if (!isIgnored(file, ignore, rootDir))
|
|
343
|
+
pendingFiles.add(file);
|
|
344
|
+
}
|
|
345
|
+
if (running) {
|
|
346
|
+
if (allowEmpty)
|
|
347
|
+
pendingAllowEmpty = true;
|
|
348
|
+
pendingRun = true;
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (pendingFiles.size === 0 && !allowEmpty)
|
|
352
|
+
return;
|
|
353
|
+
if (allowEmpty)
|
|
354
|
+
pendingAllowEmpty = true;
|
|
355
|
+
scheduleRun(reason);
|
|
356
|
+
};
|
|
357
|
+
const trigger = (changedFiles = []) => {
|
|
358
|
+
enqueue(changedFiles, "manual", true);
|
|
359
|
+
};
|
|
360
|
+
try {
|
|
361
|
+
for (const watchPath of watchPaths) {
|
|
362
|
+
const listener = (_eventType, filename) => {
|
|
363
|
+
if (filename === null || filename === undefined)
|
|
364
|
+
return;
|
|
365
|
+
const raw = String(filename);
|
|
366
|
+
const absolute = path.isAbsolute(raw) ? raw : path.resolve(watchPath, raw);
|
|
367
|
+
enqueue([absolute], "change", false);
|
|
368
|
+
};
|
|
369
|
+
let watcher;
|
|
370
|
+
try {
|
|
371
|
+
watcher = watcherFn(watchPath, { recursive: true }, listener);
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
const code = errorCode(error);
|
|
375
|
+
if (code !== "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM" && code !== "EINVAL")
|
|
376
|
+
throw error;
|
|
377
|
+
watcher = watcherFn(watchPath, { recursive: false }, listener);
|
|
378
|
+
}
|
|
379
|
+
watchers.push(watcher);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
teardown();
|
|
384
|
+
finish();
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
if (options.signal) {
|
|
388
|
+
if (options.signal.aborted) {
|
|
389
|
+
teardown();
|
|
390
|
+
finish();
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (!closed && options.runOnStart !== false) {
|
|
397
|
+
await executeRun("initial", []);
|
|
398
|
+
}
|
|
399
|
+
return { close, trigger, done, runCount: () => runIndex };
|
|
400
|
+
}
|
|
401
|
+
function formatSmartImpactTag(impact) {
|
|
402
|
+
if (impact.fallbackToFull) {
|
|
403
|
+
return `smart=full(${sanitizeSingleLine(impact.fallbackReason)})`;
|
|
404
|
+
}
|
|
405
|
+
if (impact.docsOnly && impact.selectedInvariantIds.length === 0) {
|
|
406
|
+
return "smart=docs-only";
|
|
407
|
+
}
|
|
408
|
+
const selected = Number.isFinite(impact.summary?.selected)
|
|
409
|
+
? impact.summary.selected
|
|
410
|
+
: impact.selectedInvariantIds.length;
|
|
411
|
+
const total = Number.isFinite(impact.summary?.total)
|
|
412
|
+
? impact.summary.total
|
|
413
|
+
: selected;
|
|
414
|
+
return `smart=${selected}/${total}`;
|
|
415
|
+
}
|
|
416
|
+
/** Concise one-line summary of a watch run, with follow-up details when relevant. */
|
|
417
|
+
export function formatWatchEvent(event, options = {}) {
|
|
418
|
+
const fixed = event.newlyFixed.length > 0 ? event.newlyFixed.map((s) => sanitizeSingleLine(s)).join(", ") : "none";
|
|
419
|
+
const broken = event.newlyBroken.length > 0 ? event.newlyBroken.map((s) => sanitizeSingleLine(s)).join(", ") : "none";
|
|
420
|
+
const next = event.slices?.nextSlice ? sanitizeSingleLine(event.slices.nextSlice) : "none";
|
|
421
|
+
const files = event.changedFiles.length > 0 ? String(event.changedFiles.length) : "0";
|
|
422
|
+
const score = Number.isFinite(event.report.compositeScore) ? event.report.compositeScore.toFixed(3) : "0.000";
|
|
423
|
+
const smartSuffix = event.impact ? ` ${formatSmartImpactTag(event.impact)}` : "";
|
|
424
|
+
const line = `run #${event.runIndex} [${sanitizeSingleLine(String(event.reason))}] gate=${sanitizeSingleLine(String(event.report.gate.status))} score=${score} files=${files} newlyFixed=${fixed} newlyBroken=${broken} nextSlice=${next}${smartSuffix}`;
|
|
425
|
+
return options.vars && Object.keys(options.vars).length > 0 ? redactRuntimeVars(line, options.vars) : line;
|
|
426
|
+
}
|
|
427
|
+
const ANSI = {
|
|
428
|
+
reset: "\x1b[0m",
|
|
429
|
+
bold: "\x1b[1m",
|
|
430
|
+
dim: "\x1b[2m",
|
|
431
|
+
red: "\x1b[31m",
|
|
432
|
+
green: "\x1b[32m",
|
|
433
|
+
yellow: "\x1b[33m",
|
|
434
|
+
cyan: "\x1b[36m"
|
|
435
|
+
};
|
|
436
|
+
function style(text, codes, useColor) {
|
|
437
|
+
return useColor ? `${codes}${text}${ANSI.reset}` : text;
|
|
438
|
+
}
|
|
439
|
+
function clamp01(value) {
|
|
440
|
+
if (!Number.isFinite(value))
|
|
441
|
+
return 0;
|
|
442
|
+
return Math.max(0, Math.min(1, value));
|
|
443
|
+
}
|
|
444
|
+
function formatPercent(ratio) {
|
|
445
|
+
return `${(clamp01(ratio) * 100).toFixed(1)}%`;
|
|
446
|
+
}
|
|
447
|
+
function watchGateBadge(status, useColor) {
|
|
448
|
+
switch (status) {
|
|
449
|
+
case "pass":
|
|
450
|
+
return style("[PASS]", `${ANSI.bold}${ANSI.green}`, useColor);
|
|
451
|
+
case "pass_with_warnings":
|
|
452
|
+
return style("[WARN]", `${ANSI.bold}${ANSI.yellow}`, useColor);
|
|
453
|
+
case "fail":
|
|
454
|
+
return style("[FAIL]", `${ANSI.bold}${ANSI.red}`, useColor);
|
|
455
|
+
case "incomplete":
|
|
456
|
+
return style("[INCOMPLETE]", `${ANSI.bold}${ANSI.yellow}`, useColor);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/** High-signal colorized or plain terminal summary of a watch run. */
|
|
460
|
+
export function formatPrettyWatchEvent(event, options = {}) {
|
|
461
|
+
const useColor = options.color === true;
|
|
462
|
+
const runLabel = style(`#${event.runIndex} [${sanitizeSingleLine(String(event.reason))}]`, `${ANSI.bold}${ANSI.cyan}`, useColor);
|
|
463
|
+
const badge = watchGateBadge(event.report.gate.status, useColor);
|
|
464
|
+
const hardPassed = Number.isFinite(event.report.hard?.passed) ? event.report.hard.passed : 0;
|
|
465
|
+
const hardTotal = Number.isFinite(event.report.hard?.total) ? event.report.hard.total : 0;
|
|
466
|
+
const hardParity = Number.isFinite(event.report.hard?.parity)
|
|
467
|
+
? event.report.hard.parity
|
|
468
|
+
: hardTotal > 0
|
|
469
|
+
? hardPassed / hardTotal
|
|
470
|
+
: 0;
|
|
471
|
+
const composite = Number.isFinite(event.report.compositeScore) ? event.report.compositeScore : 0;
|
|
472
|
+
const fileCount = event.changedFiles.length;
|
|
473
|
+
const filesLabel = `${fileCount} ${fileCount === 1 ? "file" : "files"}`;
|
|
474
|
+
const durationMs = Number.isFinite(event.durationMs) && event.durationMs >= 0 ? Math.round(event.durationMs) : 0;
|
|
475
|
+
const sep = style("|", ANSI.dim, useColor);
|
|
476
|
+
const smartSegment = event.impact
|
|
477
|
+
? ` ${sep} ${style(formatSmartImpactTag(event.impact), event.impact.fallbackToFull ? ANSI.yellow : ANSI.cyan, useColor)}`
|
|
478
|
+
: "";
|
|
479
|
+
const lines = [
|
|
480
|
+
`${runLabel} ${badge} hard ${hardPassed}/${hardTotal} (${formatPercent(hardParity)}) ${sep} score ${formatPercent(composite)} ${sep} ${filesLabel}${smartSegment} ${sep} ${style(`${durationMs}ms`, ANSI.dim, useColor)}`
|
|
481
|
+
];
|
|
482
|
+
if (event.newlyFixed.length > 0) {
|
|
483
|
+
const fixed = event.newlyFixed.map((s) => sanitizeSingleLine(s)).join(", ");
|
|
484
|
+
lines.push(` ${style(`+newlyFixed: ${fixed}`, ANSI.green, useColor)}`);
|
|
485
|
+
}
|
|
486
|
+
if (event.newlyBroken.length > 0) {
|
|
487
|
+
const broken = event.newlyBroken.map((s) => sanitizeSingleLine(s)).join(", ");
|
|
488
|
+
lines.push(` ${style(`-newlyBroken: ${broken}`, ANSI.red, useColor)}`);
|
|
489
|
+
}
|
|
490
|
+
if (event.slices?.nextSlice) {
|
|
491
|
+
lines.push(` ${style("next slice:", ANSI.dim, useColor)} ${style(sanitizeSingleLine(event.slices.nextSlice), ANSI.cyan, useColor)}`);
|
|
492
|
+
}
|
|
493
|
+
const output = lines.join("\n");
|
|
494
|
+
return options.vars && Object.keys(options.vars).length > 0 ? redactRuntimeVars(output, options.vars) : output;
|
|
495
|
+
}
|