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,1202 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ensureDir, resolveWorkspace } from "./store.js";
|
|
4
|
+
import { defineOwnProp, isForbiddenObjectKey, isSensitiveHeaderName, isSensitiveKeyName, isSensitiveQueryParamName, redactDeepValue, redactSensitiveText } from "./security.js";
|
|
5
|
+
export const MAX_GOLDEN_CHARS = 4096;
|
|
6
|
+
function normalizeNewlines(text) {
|
|
7
|
+
return text.replace(/\r\n?/g, "\n");
|
|
8
|
+
}
|
|
9
|
+
function truncateText(text, maxChars = MAX_GOLDEN_CHARS) {
|
|
10
|
+
const normalized = normalizeNewlines(text);
|
|
11
|
+
if (normalized.length <= maxChars) {
|
|
12
|
+
return normalized;
|
|
13
|
+
}
|
|
14
|
+
return `${normalized.slice(0, maxChars)}\n... [truncated]`;
|
|
15
|
+
}
|
|
16
|
+
function escapeFence(text) {
|
|
17
|
+
// Space out runs of 3+ backticks so neither ``` nor longer runs (e.g. `````) leave an unescaped closing fence.
|
|
18
|
+
return text.replace(/`{3,}/g, (match) => match.split("").join(" "));
|
|
19
|
+
}
|
|
20
|
+
function escapeTableCell(text) {
|
|
21
|
+
return escapeFence(normalizeNewlines(text)).replace(/\n/g, " ").replace(/\|/g, "\\|");
|
|
22
|
+
}
|
|
23
|
+
function inlineCode(text) {
|
|
24
|
+
const safe = escapeFence(normalizeNewlines(text))
|
|
25
|
+
.replace(/\n/g, "\\n")
|
|
26
|
+
.replace(/`{2,}/g, (match) => match.split("").join(" "));
|
|
27
|
+
if (!safe.includes("`")) {
|
|
28
|
+
return `\`${safe}\``;
|
|
29
|
+
}
|
|
30
|
+
return safe.startsWith("`") || safe.endsWith("`") ? `\`\` ${safe} \`\`` : `\`\`${safe}\`\``;
|
|
31
|
+
}
|
|
32
|
+
function sortKeysDeep(value) {
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
return value.map((item) => sortKeysDeep(item));
|
|
35
|
+
}
|
|
36
|
+
if (value !== null && typeof value === "object") {
|
|
37
|
+
const record = value;
|
|
38
|
+
const sorted = {};
|
|
39
|
+
for (const key of Object.keys(record).sort()) {
|
|
40
|
+
if (isForbiddenObjectKey(key))
|
|
41
|
+
continue;
|
|
42
|
+
const desc = Object.getOwnPropertyDescriptor(record, key);
|
|
43
|
+
if (!desc || !("value" in desc) || desc.value === undefined)
|
|
44
|
+
continue;
|
|
45
|
+
defineOwnProp(sorted, key, sortKeysDeep(desc.value));
|
|
46
|
+
}
|
|
47
|
+
return sorted;
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function stableJson(value, space = 2) {
|
|
52
|
+
return JSON.stringify(sortKeysDeep(value), null, space) ?? "null";
|
|
53
|
+
}
|
|
54
|
+
function renderCodeBlock(text, lang = "text", maxChars = MAX_GOLDEN_CHARS) {
|
|
55
|
+
const body = escapeFence(truncateText(text, maxChars));
|
|
56
|
+
return `\`\`\`${lang}\n${body}\n\`\`\``;
|
|
57
|
+
}
|
|
58
|
+
function renderJsonBlock(value, truncate = false) {
|
|
59
|
+
const raw = stableJson(value, 2);
|
|
60
|
+
const content = truncate ? truncateText(raw, MAX_GOLDEN_CHARS) : normalizeNewlines(raw);
|
|
61
|
+
return `\`\`\`json\n${escapeFence(content)}\n\`\`\``;
|
|
62
|
+
}
|
|
63
|
+
function formatNumberOrArray(value) {
|
|
64
|
+
return Array.isArray(value) ? value.map((item) => `\`${item}\``).join(" or ") : `\`${value}\``;
|
|
65
|
+
}
|
|
66
|
+
function formatBBox(bbox) {
|
|
67
|
+
return `{ x: ${bbox.x}, y: ${bbox.y}, w: ${bbox.w}, h: ${bbox.h} }`;
|
|
68
|
+
}
|
|
69
|
+
function hasNonEmptyRecord(record) {
|
|
70
|
+
if (!record || typeof record !== "object") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return Object.keys(record).some((key) => record[key] !== undefined);
|
|
74
|
+
}
|
|
75
|
+
const MAX_PLUGIN_SPEC_DEPTH = 16;
|
|
76
|
+
const UI_VARS_TEMPLATE_RE = /^\{\{\s*vars\.[A-Za-z0-9_.-]+\s*\}\}$/;
|
|
77
|
+
const SPLIT_SECRET_CLI_FLAGS = new Set([
|
|
78
|
+
"--token",
|
|
79
|
+
"--api-key",
|
|
80
|
+
"--apikey",
|
|
81
|
+
"--secret",
|
|
82
|
+
"--client-secret",
|
|
83
|
+
"--password",
|
|
84
|
+
"--passwd",
|
|
85
|
+
"--passphrase",
|
|
86
|
+
"--auth-token",
|
|
87
|
+
"--access-token",
|
|
88
|
+
"--refresh-token",
|
|
89
|
+
"--id-token",
|
|
90
|
+
"--session-token",
|
|
91
|
+
"--csrf-token",
|
|
92
|
+
"--xsrf-token",
|
|
93
|
+
"--private-key",
|
|
94
|
+
"--signing-key",
|
|
95
|
+
"--bearer",
|
|
96
|
+
"--cookie",
|
|
97
|
+
"--user",
|
|
98
|
+
"--auth",
|
|
99
|
+
"--jwt",
|
|
100
|
+
"--credential"
|
|
101
|
+
]);
|
|
102
|
+
/** Mask literal values (typed input, storage values) unless they are `{{vars.NAME}}` templates. */
|
|
103
|
+
function maskUiStateValue(value) {
|
|
104
|
+
return typeof value === "string" && UI_VARS_TEMPLATE_RE.test(value.trim()) ? value.trim() : "[REDACTED]";
|
|
105
|
+
}
|
|
106
|
+
function redactCliHeaderArg(rawVal) {
|
|
107
|
+
const colon = rawVal.indexOf(":");
|
|
108
|
+
if (colon > 0) {
|
|
109
|
+
const hdrName = rawVal.slice(0, colon).trim();
|
|
110
|
+
const hdrVal = rawVal.slice(colon + 1).trim();
|
|
111
|
+
if (isSensitiveHeaderName(hdrName) || isSensitiveKeyName(hdrName)) {
|
|
112
|
+
return `${redactSensitiveText(hdrName)}: ${UI_VARS_TEMPLATE_RE.test(hdrVal) ? hdrVal : "[REDACTED]"}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return redactSensitiveText(rawVal);
|
|
116
|
+
}
|
|
117
|
+
function redactCommandArgsForSpec(args) {
|
|
118
|
+
if (args.length === 0)
|
|
119
|
+
return "`(none)`";
|
|
120
|
+
const rendered = [];
|
|
121
|
+
for (let i = 0; i < args.length; i++) {
|
|
122
|
+
const raw = String(args[i]);
|
|
123
|
+
const trimmed = raw.trim();
|
|
124
|
+
const lower = trimmed.toLowerCase();
|
|
125
|
+
if ((trimmed === "-H" || lower === "--header") && i + 1 < args.length) {
|
|
126
|
+
rendered.push(inlineCode(redactSensitiveText(raw)));
|
|
127
|
+
rendered.push(inlineCode(redactCliHeaderArg(String(args[i + 1]))));
|
|
128
|
+
i++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if ((SPLIT_SECRET_CLI_FLAGS.has(lower) || trimmed === "-u") && i + 1 < args.length) {
|
|
132
|
+
rendered.push(inlineCode(redactSensitiveText(raw)));
|
|
133
|
+
const nextVal = String(args[i + 1]);
|
|
134
|
+
rendered.push(inlineCode(UI_VARS_TEMPLATE_RE.test(nextVal.trim()) ? nextVal.trim() : "[REDACTED]"));
|
|
135
|
+
i++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const eqMatch = /^(--?[a-z0-9-]+)=([\s\S]+)$/i.exec(trimmed);
|
|
139
|
+
if (eqMatch) {
|
|
140
|
+
const flag = eqMatch[1];
|
|
141
|
+
const flagLower = flag.toLowerCase();
|
|
142
|
+
const val = eqMatch[2];
|
|
143
|
+
if (flag === "-H" || flagLower === "--header") {
|
|
144
|
+
rendered.push(inlineCode(`${redactSensitiveText(flag)}=${redactCliHeaderArg(val)}`));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (SPLIT_SECRET_CLI_FLAGS.has(flagLower) || flag === "-u") {
|
|
148
|
+
rendered.push(inlineCode(`${redactSensitiveText(flag)}=${UI_VARS_TEMPLATE_RE.test(val.trim()) ? val.trim() : "[REDACTED]"}`));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (trimmed.startsWith("-u") && trimmed.length > 2 && !trimmed.startsWith("-u=")) {
|
|
153
|
+
const rest = trimmed.slice(2);
|
|
154
|
+
rendered.push(inlineCode(`-u${UI_VARS_TEMPLATE_RE.test(rest) ? rest : "[REDACTED]"}`));
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
rendered.push(inlineCode(redactSensitiveText(raw)));
|
|
158
|
+
}
|
|
159
|
+
return rendered.join(" ");
|
|
160
|
+
}
|
|
161
|
+
function redactPluginSpecValue(value) {
|
|
162
|
+
return redactDeepValue(value, {
|
|
163
|
+
maxDepth: MAX_PLUGIN_SPEC_DEPTH,
|
|
164
|
+
sensitiveKeyMode: "value",
|
|
165
|
+
sanitizeNonFiniteNumbers: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function redactSpecHeaders(headers) {
|
|
169
|
+
if (!headers || typeof headers !== "object" || Array.isArray(headers))
|
|
170
|
+
return {};
|
|
171
|
+
const out = {};
|
|
172
|
+
for (const [rawKey, rawVal] of Object.entries(headers)) {
|
|
173
|
+
const key = rawKey.trim();
|
|
174
|
+
if (!key || isForbiddenObjectKey(key) || rawVal === undefined || rawVal === null)
|
|
175
|
+
continue;
|
|
176
|
+
const safeKey = redactSensitiveText(key);
|
|
177
|
+
if (isForbiddenObjectKey(safeKey))
|
|
178
|
+
continue;
|
|
179
|
+
defineOwnProp(out, safeKey, isSensitiveHeaderName(key) ? "[REDACTED]" : redactSensitiveText(String(rawVal)));
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
function redactSpecVars(vars) {
|
|
184
|
+
const out = {};
|
|
185
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
186
|
+
if (isForbiddenObjectKey(k) || v === undefined)
|
|
187
|
+
continue;
|
|
188
|
+
const safeKey = redactSensitiveText(k);
|
|
189
|
+
if (isForbiddenObjectKey(safeKey))
|
|
190
|
+
continue;
|
|
191
|
+
defineOwnProp(out, safeKey, isSensitiveKeyName(k) ? "[REDACTED]" : redactSensitiveText(String(v)));
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
function redactSpecQuery(query) {
|
|
196
|
+
const out = {};
|
|
197
|
+
for (const [k, v] of Object.entries(query)) {
|
|
198
|
+
if (isForbiddenObjectKey(k) || v === undefined)
|
|
199
|
+
continue;
|
|
200
|
+
const safeKey = redactSensitiveText(k);
|
|
201
|
+
if (isForbiddenObjectKey(safeKey))
|
|
202
|
+
continue;
|
|
203
|
+
if (isSensitiveQueryParamName(k) || isSensitiveKeyName(k)) {
|
|
204
|
+
defineOwnProp(out, safeKey, "[REDACTED]");
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
defineOwnProp(out, safeKey, redactPluginSpecValue(v));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
function redactWebFlowStepsForSpec(steps) {
|
|
213
|
+
return steps.map((step) => {
|
|
214
|
+
if (!step || typeof step !== "object" || Array.isArray(step)) {
|
|
215
|
+
return typeof step === "string" ? redactSensitiveText(step) : step;
|
|
216
|
+
}
|
|
217
|
+
const clean = redactPluginSpecValue(step);
|
|
218
|
+
if (clean && typeof clean === "object" && !Array.isArray(clean)) {
|
|
219
|
+
const rec = clean;
|
|
220
|
+
if (rec.action === "fill" && Object.prototype.hasOwnProperty.call(rec, "value") && rec.value !== undefined) {
|
|
221
|
+
defineOwnProp(rec, "value", maskUiStateValue(rec.value));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return clean;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function redactWorkflowStepsForSpec(steps) {
|
|
228
|
+
return steps.map((step) => {
|
|
229
|
+
if (!step || typeof step !== "object" || Array.isArray(step))
|
|
230
|
+
return step;
|
|
231
|
+
const rec = { ...step };
|
|
232
|
+
if (typeof rec.path === "string") {
|
|
233
|
+
rec.path = redactSensitiveText(rec.path);
|
|
234
|
+
}
|
|
235
|
+
if (typeof rec.url === "string") {
|
|
236
|
+
rec.url = redactSensitiveText(rec.url);
|
|
237
|
+
}
|
|
238
|
+
if (rec.query && typeof rec.query === "object" && !Array.isArray(rec.query)) {
|
|
239
|
+
rec.query = redactSpecQuery(rec.query);
|
|
240
|
+
}
|
|
241
|
+
if (rec.headers && typeof rec.headers === "object" && !Array.isArray(rec.headers)) {
|
|
242
|
+
rec.headers = redactSpecHeaders(rec.headers);
|
|
243
|
+
}
|
|
244
|
+
if (rec.body !== undefined) {
|
|
245
|
+
rec.body = typeof rec.body === "string" ? redactSensitiveText(rec.body) : redactPluginSpecValue(rec.body);
|
|
246
|
+
}
|
|
247
|
+
if (rec.expected && typeof rec.expected === "object" && !Array.isArray(rec.expected)) {
|
|
248
|
+
const exp = { ...rec.expected };
|
|
249
|
+
if (exp.headers && typeof exp.headers === "object" && !Array.isArray(exp.headers)) {
|
|
250
|
+
exp.headers = redactSpecHeaders(exp.headers);
|
|
251
|
+
}
|
|
252
|
+
rec.expected = exp;
|
|
253
|
+
}
|
|
254
|
+
return rec;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function pushTextAssertionBlock(lines, label, value) {
|
|
258
|
+
if (value.length === 0) {
|
|
259
|
+
lines.push(`- **${label}:** \`(empty)\``);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
lines.push(`- **${label}:**`);
|
|
263
|
+
lines.push(renderCodeBlock(value, "text"));
|
|
264
|
+
}
|
|
265
|
+
function isSensitiveJsonPath(rawPath) {
|
|
266
|
+
const normalized = String(rawPath ?? "").replace(/\[['"]?([^\]]*?)['"]?\]/g, ".$1");
|
|
267
|
+
const segments = normalized
|
|
268
|
+
.split(".")
|
|
269
|
+
.map((s) => s.trim())
|
|
270
|
+
.filter((s) => Boolean(s) && s !== "$" && !/^\d+$/.test(s));
|
|
271
|
+
for (const seg of segments) {
|
|
272
|
+
if (isSensitiveKeyName(seg) || isSensitiveHeaderName(seg) || isSensitiveQueryParamName(seg)) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
function renderJsonPaths(lines, jsonPaths) {
|
|
279
|
+
lines.push("- **JSON Paths:**");
|
|
280
|
+
for (const jp of jsonPaths) {
|
|
281
|
+
const sensitivePath = isSensitiveJsonPath(jp.path);
|
|
282
|
+
const parts = [` - ${inlineCode(redactSensitiveText(jp.path))}`];
|
|
283
|
+
if (jp.equals !== undefined) {
|
|
284
|
+
const safeEquals = sensitivePath
|
|
285
|
+
? typeof jp.equals === "string" && UI_VARS_TEMPLATE_RE.test(jp.equals.trim())
|
|
286
|
+
? jp.equals.trim()
|
|
287
|
+
: "[REDACTED]"
|
|
288
|
+
: redactPluginSpecValue(jp.equals);
|
|
289
|
+
parts.push(`equals ${inlineCode(stableJson(safeEquals, 0))}`);
|
|
290
|
+
}
|
|
291
|
+
if (typeof jp.matches === "string") {
|
|
292
|
+
const safeMatches = sensitivePath
|
|
293
|
+
? UI_VARS_TEMPLATE_RE.test(jp.matches.trim())
|
|
294
|
+
? jp.matches.trim()
|
|
295
|
+
: "[REDACTED]"
|
|
296
|
+
: redactSensitiveText(jp.matches);
|
|
297
|
+
parts.push(`matches ${inlineCode(safeMatches)}`);
|
|
298
|
+
}
|
|
299
|
+
lines.push(parts.join(" "));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function renderCommandInvariant(lines, inv) {
|
|
303
|
+
const { input, expected } = inv;
|
|
304
|
+
if (Array.isArray(input.args)) {
|
|
305
|
+
lines.push(`- **Args:** ${redactCommandArgsForSpec(input.args)}`);
|
|
306
|
+
}
|
|
307
|
+
if (typeof input.stdin === "string") {
|
|
308
|
+
pushTextAssertionBlock(lines, "Stdin", redactSensitiveText(input.stdin));
|
|
309
|
+
}
|
|
310
|
+
if (hasNonEmptyRecord(input.env)) {
|
|
311
|
+
lines.push("- **Env:**");
|
|
312
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(input.env)));
|
|
313
|
+
}
|
|
314
|
+
if (typeof input.cwd === "string" && input.cwd.length > 0) {
|
|
315
|
+
lines.push(`- **Working Directory:** ${inlineCode(redactSensitiveText(input.cwd))}`);
|
|
316
|
+
}
|
|
317
|
+
if (typeof input.timeoutMs === "number") {
|
|
318
|
+
lines.push(`- **Timeout (ms):** \`${input.timeoutMs}\``);
|
|
319
|
+
}
|
|
320
|
+
if (expected.exitCode !== undefined) {
|
|
321
|
+
lines.push(`- **Expected Exit Code:** ${formatNumberOrArray(expected.exitCode)}`);
|
|
322
|
+
}
|
|
323
|
+
if (Array.isArray(expected.normalize) && expected.normalize.length > 0) {
|
|
324
|
+
lines.push(`- **Normalizers:** ${expected.normalize.map(inlineCode).join(", ")}`);
|
|
325
|
+
}
|
|
326
|
+
if (typeof expected.stdoutExact === "string") {
|
|
327
|
+
pushTextAssertionBlock(lines, "Stdout Exact", redactSensitiveText(expected.stdoutExact));
|
|
328
|
+
}
|
|
329
|
+
if (Array.isArray(expected.stdoutContains) && expected.stdoutContains.length > 0) {
|
|
330
|
+
lines.push(`- **Stdout Contains:** ${expected.stdoutContains.map((s) => inlineCode(redactSensitiveText(s))).join(", ")}`);
|
|
331
|
+
}
|
|
332
|
+
if (Array.isArray(expected.stdoutNotContains) && expected.stdoutNotContains.length > 0) {
|
|
333
|
+
lines.push(`- **Stdout Not Contains:** ${expected.stdoutNotContains.map((s) => inlineCode(redactSensitiveText(s))).join(", ")}`);
|
|
334
|
+
}
|
|
335
|
+
if (Array.isArray(expected.stdoutRegex) && expected.stdoutRegex.length > 0) {
|
|
336
|
+
lines.push(`- **Stdout Regex:** ${expected.stdoutRegex.map((s) => inlineCode(redactSensitiveText(s))).join(", ")}`);
|
|
337
|
+
}
|
|
338
|
+
if (typeof expected.stderrExact === "string") {
|
|
339
|
+
pushTextAssertionBlock(lines, "Stderr Exact", redactSensitiveText(expected.stderrExact));
|
|
340
|
+
}
|
|
341
|
+
if (Array.isArray(expected.stderrContains) && expected.stderrContains.length > 0) {
|
|
342
|
+
lines.push(`- **Stderr Contains:** ${expected.stderrContains.map((s) => inlineCode(redactSensitiveText(s))).join(", ")}`);
|
|
343
|
+
}
|
|
344
|
+
if (expected.jsonSchema !== undefined) {
|
|
345
|
+
lines.push("- **JSON Schema:**");
|
|
346
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.jsonSchema)));
|
|
347
|
+
}
|
|
348
|
+
if (Array.isArray(expected.jsonPaths) && expected.jsonPaths.length > 0) {
|
|
349
|
+
renderJsonPaths(lines, expected.jsonPaths);
|
|
350
|
+
}
|
|
351
|
+
if (typeof expected.goldenStdout === "string") {
|
|
352
|
+
pushTextAssertionBlock(lines, "Golden Stdout", redactSensitiveText(expected.goldenStdout));
|
|
353
|
+
}
|
|
354
|
+
if (Array.isArray(expected.fsEffects) && expected.fsEffects.length > 0) {
|
|
355
|
+
lines.push("- **Filesystem Effects:**");
|
|
356
|
+
for (const effect of expected.fsEffects) {
|
|
357
|
+
const meta = [];
|
|
358
|
+
if (typeof effect.size === "number") {
|
|
359
|
+
meta.push(`size=${effect.size}`);
|
|
360
|
+
}
|
|
361
|
+
if (typeof effect.sha256 === "string" && effect.sha256.length > 0) {
|
|
362
|
+
meta.push(`sha256=${inlineCode(redactSensitiveText(effect.sha256))}`);
|
|
363
|
+
}
|
|
364
|
+
const suffix = meta.length > 0 ? ` (${meta.join(", ")})` : "";
|
|
365
|
+
lines.push(` - ${inlineCode(effect.status)} ${inlineCode(redactSensitiveText(effect.path))}${suffix}`);
|
|
366
|
+
if (typeof effect.preview === "string" && effect.preview.length > 0) {
|
|
367
|
+
lines.push(renderCodeBlock(redactSensitiveText(effect.preview), "text"));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function formatInteractiveLandmark(landmark) {
|
|
373
|
+
const namePart = typeof landmark.name === "string" && landmark.name.length > 0
|
|
374
|
+
? ` (name=${inlineCode(redactSensitiveText(landmark.name))})`
|
|
375
|
+
: "";
|
|
376
|
+
return `${inlineCode(landmark.role)} ${inlineCode(`<${landmark.tag}>`)}${namePart}`;
|
|
377
|
+
}
|
|
378
|
+
function formatLandmark(landmark) {
|
|
379
|
+
const attrs = [];
|
|
380
|
+
if (landmark.required !== undefined) {
|
|
381
|
+
attrs.push(`required=${landmark.required}`);
|
|
382
|
+
}
|
|
383
|
+
if (typeof landmark.textContains === "string") {
|
|
384
|
+
attrs.push(`textContains=${inlineCode(redactSensitiveText(landmark.textContains))}`);
|
|
385
|
+
}
|
|
386
|
+
const suffix = attrs.length > 0 ? ` (${attrs.join(", ")})` : "";
|
|
387
|
+
return `${inlineCode(`<${landmark.tag}>`)}${suffix}`;
|
|
388
|
+
}
|
|
389
|
+
function formatBoundingBox(entry) {
|
|
390
|
+
const label = entry.selector ?? entry.id ?? "(element)";
|
|
391
|
+
return `${inlineCode(redactSensitiveText(label))} -> \`${formatBBox(entry.bbox)}\``;
|
|
392
|
+
}
|
|
393
|
+
function formatDomAssertion(assertion) {
|
|
394
|
+
const checks = [];
|
|
395
|
+
if (typeof assertion.count === "number") {
|
|
396
|
+
checks.push(`count=${assertion.count}`);
|
|
397
|
+
}
|
|
398
|
+
if (typeof assertion.minCount === "number") {
|
|
399
|
+
checks.push(`minCount=${assertion.minCount}`);
|
|
400
|
+
}
|
|
401
|
+
const suffix = checks.length > 0 ? ` (${checks.join(", ")})` : "";
|
|
402
|
+
return `${inlineCode(redactSensitiveText(assertion.selector))}${suffix}`;
|
|
403
|
+
}
|
|
404
|
+
function renderWebNetworkExpectation(lines, call) {
|
|
405
|
+
const details = [];
|
|
406
|
+
if (typeof call.method === "string") {
|
|
407
|
+
details.push(`method=${inlineCode(call.method)}`);
|
|
408
|
+
}
|
|
409
|
+
if (typeof call.pathPattern === "string") {
|
|
410
|
+
details.push(`pathPattern=${inlineCode(redactSensitiveText(call.pathPattern))}`);
|
|
411
|
+
}
|
|
412
|
+
if (typeof call.path === "string") {
|
|
413
|
+
details.push(`path=${inlineCode(redactSensitiveText(call.path))}`);
|
|
414
|
+
}
|
|
415
|
+
if (typeof call.status === "number") {
|
|
416
|
+
details.push(`status=\`${call.status}\``);
|
|
417
|
+
}
|
|
418
|
+
if (typeof call.contentType === "string") {
|
|
419
|
+
details.push(`contentType=${inlineCode(redactSensitiveText(call.contentType))}`);
|
|
420
|
+
}
|
|
421
|
+
lines.push(` - ${details.length > 0 ? details.join(", ") : "(any request)"}`);
|
|
422
|
+
if (call.jsonSchema !== undefined) {
|
|
423
|
+
lines.push(" - **Network JSON Schema:**");
|
|
424
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(call.jsonSchema)));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function renderWebInvariant(lines, inv) {
|
|
428
|
+
const { input, expected, tolerance } = inv;
|
|
429
|
+
if (typeof input.path === "string") {
|
|
430
|
+
lines.push(`- **Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
431
|
+
}
|
|
432
|
+
if (typeof input.startPath === "string") {
|
|
433
|
+
lines.push(`- **Start Path:** ${inlineCode(redactSensitiveText(input.startPath))}`);
|
|
434
|
+
}
|
|
435
|
+
if (typeof input.triggerPath === "string") {
|
|
436
|
+
lines.push(`- **Trigger Path:** ${inlineCode(redactSensitiveText(input.triggerPath))}`);
|
|
437
|
+
}
|
|
438
|
+
if (input.viewport) {
|
|
439
|
+
lines.push(`- **Viewport:** \`${input.viewport.width}x${input.viewport.height}\``);
|
|
440
|
+
}
|
|
441
|
+
if (typeof input.waitUntil === "string") {
|
|
442
|
+
lines.push(`- **Wait Until:** ${inlineCode(input.waitUntil)}`);
|
|
443
|
+
}
|
|
444
|
+
if (hasNonEmptyRecord(input.headers)) {
|
|
445
|
+
const safeHeaders = redactSpecHeaders(input.headers);
|
|
446
|
+
if (hasNonEmptyRecord(safeHeaders)) {
|
|
447
|
+
lines.push("- **Request Headers:**");
|
|
448
|
+
lines.push(renderJsonBlock(safeHeaders));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (Array.isArray(input.steps) && input.steps.length > 0) {
|
|
452
|
+
lines.push("- **Flow Steps:**");
|
|
453
|
+
lines.push(renderJsonBlock(redactWebFlowStepsForSpec(input.steps)));
|
|
454
|
+
}
|
|
455
|
+
if (expected.status !== undefined) {
|
|
456
|
+
lines.push(`- **Expected Status:** ${formatNumberOrArray(expected.status)}`);
|
|
457
|
+
}
|
|
458
|
+
if (hasNonEmptyRecord(expected.headers)) {
|
|
459
|
+
const safeHeaders = redactSpecHeaders(expected.headers);
|
|
460
|
+
if (hasNonEmptyRecord(safeHeaders)) {
|
|
461
|
+
lines.push("- **Expected Headers:**");
|
|
462
|
+
lines.push(renderJsonBlock(safeHeaders));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (typeof expected.titleContains === "string") {
|
|
466
|
+
lines.push(`- **Title Contains:** ${inlineCode(redactSensitiveText(expected.titleContains))}`);
|
|
467
|
+
}
|
|
468
|
+
if (typeof expected.finalUrlIncludes === "string") {
|
|
469
|
+
lines.push(`- **Final URL Includes:** ${inlineCode(redactSensitiveText(expected.finalUrlIncludes))}`);
|
|
470
|
+
}
|
|
471
|
+
if (Array.isArray(expected.landmarks) && expected.landmarks.length > 0) {
|
|
472
|
+
lines.push("- **Landmarks:**");
|
|
473
|
+
for (const landmark of expected.landmarks) {
|
|
474
|
+
lines.push(` - ${formatLandmark(landmark)}`);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (Array.isArray(expected.interactiveLandmarks) && expected.interactiveLandmarks.length > 0) {
|
|
478
|
+
lines.push("- **Interactive Landmarks:**");
|
|
479
|
+
for (const landmark of expected.interactiveLandmarks) {
|
|
480
|
+
lines.push(` - ${formatInteractiveLandmark(landmark)}`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (Array.isArray(expected.boundingBoxes) && expected.boundingBoxes.length > 0) {
|
|
484
|
+
lines.push("- **Bounding Boxes:**");
|
|
485
|
+
for (const entry of expected.boundingBoxes) {
|
|
486
|
+
lines.push(` - ${formatBoundingBox(entry)}`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (Array.isArray(expected.visibleText) && expected.visibleText.length > 0) {
|
|
490
|
+
lines.push(`- **Visible Text:** ${expected.visibleText.map((t) => inlineCode(redactSensitiveText(t))).join(", ")}`);
|
|
491
|
+
}
|
|
492
|
+
if (Array.isArray(expected.hiddenText) && expected.hiddenText.length > 0) {
|
|
493
|
+
lines.push(`- **Hidden Text:** ${expected.hiddenText.map((t) => inlineCode(redactSensitiveText(t))).join(", ")}`);
|
|
494
|
+
}
|
|
495
|
+
if (Array.isArray(expected.domAssertions) && expected.domAssertions.length > 0) {
|
|
496
|
+
lines.push("- **DOM Assertions:**");
|
|
497
|
+
for (const assertion of expected.domAssertions) {
|
|
498
|
+
lines.push(` - ${formatDomAssertion(assertion)}`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (Array.isArray(expected.networkCalls) && expected.networkCalls.length > 0) {
|
|
502
|
+
lines.push("- **Network Calls:**");
|
|
503
|
+
for (const call of expected.networkCalls) {
|
|
504
|
+
renderWebNetworkExpectation(lines, call);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (expected.noConsoleErrors !== undefined) {
|
|
508
|
+
lines.push(`- **No Console Errors:** \`${String(expected.noConsoleErrors)}\``);
|
|
509
|
+
}
|
|
510
|
+
if (expected.noUncaughtExceptions !== undefined) {
|
|
511
|
+
lines.push(`- **No Uncaught Exceptions:** \`${String(expected.noUncaughtExceptions)}\``);
|
|
512
|
+
}
|
|
513
|
+
if (expected.noPageErrors !== undefined) {
|
|
514
|
+
lines.push(`- **No Page Errors:** \`${String(expected.noPageErrors)}\``);
|
|
515
|
+
}
|
|
516
|
+
if (expected.noServerErrors !== undefined) {
|
|
517
|
+
lines.push(`- **No Server Errors:** \`${String(expected.noServerErrors)}\``);
|
|
518
|
+
}
|
|
519
|
+
if (typeof tolerance.minLayoutIoU === "number") {
|
|
520
|
+
lines.push(`- **Min Layout IoU:** \`${tolerance.minLayoutIoU}\``);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function renderHttpInvariant(lines, inv) {
|
|
524
|
+
const { input, expected } = inv;
|
|
525
|
+
if (typeof input.method === "string") {
|
|
526
|
+
lines.push(`- **Method:** ${inlineCode(input.method)}`);
|
|
527
|
+
}
|
|
528
|
+
if (typeof input.path === "string") {
|
|
529
|
+
lines.push(`- **Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
530
|
+
}
|
|
531
|
+
if (hasNonEmptyRecord(input.query)) {
|
|
532
|
+
lines.push("- **Query:**");
|
|
533
|
+
lines.push(renderJsonBlock(redactSpecQuery(input.query)));
|
|
534
|
+
}
|
|
535
|
+
if (hasNonEmptyRecord(input.headers)) {
|
|
536
|
+
const safeHeaders = redactSpecHeaders(input.headers);
|
|
537
|
+
if (hasNonEmptyRecord(safeHeaders)) {
|
|
538
|
+
lines.push("- **Request Headers:**");
|
|
539
|
+
lines.push(renderJsonBlock(safeHeaders));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (input.body !== undefined) {
|
|
543
|
+
if (typeof input.body === "string") {
|
|
544
|
+
pushTextAssertionBlock(lines, "Request Body", redactSensitiveText(input.body));
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
lines.push("- **Request Body:**");
|
|
548
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(input.body), true));
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (expected.status !== undefined) {
|
|
552
|
+
lines.push(`- **Expected Status:** ${formatNumberOrArray(expected.status)}`);
|
|
553
|
+
}
|
|
554
|
+
if (hasNonEmptyRecord(expected.headers)) {
|
|
555
|
+
const safeHeaders = redactSpecHeaders(expected.headers);
|
|
556
|
+
if (hasNonEmptyRecord(safeHeaders)) {
|
|
557
|
+
lines.push("- **Expected Headers:**");
|
|
558
|
+
lines.push(renderJsonBlock(safeHeaders));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (typeof expected.maxLatencyMs === "number") {
|
|
562
|
+
lines.push(`- **Max Latency (ms):** \`${expected.maxLatencyMs}\``);
|
|
563
|
+
}
|
|
564
|
+
if (expected.jsonSubset !== undefined) {
|
|
565
|
+
lines.push("- **JSON Subset:**");
|
|
566
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.jsonSubset)));
|
|
567
|
+
}
|
|
568
|
+
if (expected.jsonSchema !== undefined) {
|
|
569
|
+
lines.push("- **JSON Schema:**");
|
|
570
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.jsonSchema)));
|
|
571
|
+
}
|
|
572
|
+
if (Array.isArray(expected.jsonPaths) && expected.jsonPaths.length > 0) {
|
|
573
|
+
renderJsonPaths(lines, expected.jsonPaths);
|
|
574
|
+
}
|
|
575
|
+
if (expected.bodyContains !== undefined) {
|
|
576
|
+
const items = typeof expected.bodyContains === "string"
|
|
577
|
+
? [expected.bodyContains]
|
|
578
|
+
: Array.isArray(expected.bodyContains)
|
|
579
|
+
? expected.bodyContains
|
|
580
|
+
: [];
|
|
581
|
+
if (items.length > 0) {
|
|
582
|
+
lines.push(`- **Body Contains:** ${items.map((item) => inlineCode(redactSensitiveText(String(item)))).join(", ")}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (typeof expected.bodyExact === "string") {
|
|
586
|
+
pushTextAssertionBlock(lines, "Body Exact", redactSensitiveText(expected.bodyExact));
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function renderHttpWorkflowInvariant(lines, inv) {
|
|
590
|
+
const { input } = inv;
|
|
591
|
+
if (typeof input.cookieJar === "boolean") {
|
|
592
|
+
lines.push(`- **Cookie Jar:** \`${String(input.cookieJar)}\``);
|
|
593
|
+
}
|
|
594
|
+
if (hasNonEmptyRecord(input.vars)) {
|
|
595
|
+
lines.push("- **Variables:**");
|
|
596
|
+
lines.push(renderJsonBlock(redactSpecVars(input.vars)));
|
|
597
|
+
}
|
|
598
|
+
if (Array.isArray(input.steps) && input.steps.length > 0) {
|
|
599
|
+
lines.push("- **Workflow Steps:**");
|
|
600
|
+
lines.push(renderJsonBlock(redactWorkflowStepsForSpec(input.steps), true));
|
|
601
|
+
}
|
|
602
|
+
if (Array.isArray(input.finallySteps) && input.finallySteps.length > 0) {
|
|
603
|
+
lines.push("- **Finally Steps:**");
|
|
604
|
+
lines.push(renderJsonBlock(redactWorkflowStepsForSpec(input.finallySteps), true));
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function renderHttpStreamInvariant(lines, inv) {
|
|
608
|
+
const { input, expected } = inv;
|
|
609
|
+
if (typeof input.format === "string") {
|
|
610
|
+
lines.push(`- **Stream Format:** ${inlineCode(input.format)}`);
|
|
611
|
+
}
|
|
612
|
+
renderHttpInvariant(lines, inv);
|
|
613
|
+
if (typeof input.maxBytes === "number") {
|
|
614
|
+
lines.push(`- **Max Bytes:** \`${input.maxBytes}\``);
|
|
615
|
+
}
|
|
616
|
+
if (typeof input.maxEvents === "number") {
|
|
617
|
+
lines.push(`- **Input Max Events:** \`${input.maxEvents}\``);
|
|
618
|
+
}
|
|
619
|
+
if (typeof expected.minEvents === "number") {
|
|
620
|
+
lines.push(`- **Min Events:** \`${expected.minEvents}\``);
|
|
621
|
+
}
|
|
622
|
+
if (typeof expected.maxEvents === "number") {
|
|
623
|
+
lines.push(`- **Max Events:** \`${expected.maxEvents}\``);
|
|
624
|
+
}
|
|
625
|
+
if (typeof expected.maxDurationMs === "number") {
|
|
626
|
+
lines.push(`- **Max Duration (ms):** \`${expected.maxDurationMs}\``);
|
|
627
|
+
}
|
|
628
|
+
if (typeof expected.forbidMalformedEvents === "boolean") {
|
|
629
|
+
lines.push(`- **Forbid Malformed Events:** \`${String(expected.forbidMalformedEvents)}\``);
|
|
630
|
+
}
|
|
631
|
+
if (Array.isArray(expected.orderedEvents) && expected.orderedEvents.length > 0) {
|
|
632
|
+
lines.push("- **Ordered Events:**");
|
|
633
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.orderedEvents), true));
|
|
634
|
+
}
|
|
635
|
+
if (expected.terminalEvent !== undefined) {
|
|
636
|
+
lines.push("- **Terminal Event:**");
|
|
637
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.terminalEvent)));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function renderWsProtocolInvariant(lines, inv) {
|
|
641
|
+
const { input, expected } = inv;
|
|
642
|
+
if (typeof input.path === "string") {
|
|
643
|
+
lines.push(`- **Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
644
|
+
}
|
|
645
|
+
if (hasNonEmptyRecord(input.query)) {
|
|
646
|
+
lines.push("- **Query:**");
|
|
647
|
+
lines.push(renderJsonBlock(redactSpecQuery(input.query)));
|
|
648
|
+
}
|
|
649
|
+
if (hasNonEmptyRecord(input.headers)) {
|
|
650
|
+
const safeHeaders = redactSpecHeaders(input.headers);
|
|
651
|
+
if (hasNonEmptyRecord(safeHeaders)) {
|
|
652
|
+
lines.push("- **Request Headers:**");
|
|
653
|
+
lines.push(renderJsonBlock(safeHeaders));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (typeof input.maxMessageBytes === "number") {
|
|
657
|
+
lines.push(`- **Max Message Bytes:** \`${input.maxMessageBytes}\``);
|
|
658
|
+
}
|
|
659
|
+
if (Array.isArray(input.steps) && input.steps.length > 0) {
|
|
660
|
+
lines.push("- **Protocol Steps:**");
|
|
661
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(input.steps), true));
|
|
662
|
+
}
|
|
663
|
+
if (typeof expected.closeCode === "number") {
|
|
664
|
+
lines.push(`- **Expected Close Code:** \`${expected.closeCode}\``);
|
|
665
|
+
}
|
|
666
|
+
if (typeof expected.maxDurationMs === "number") {
|
|
667
|
+
lines.push(`- **Max Duration (ms):** \`${expected.maxDurationMs}\``);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
function formatImageDimensions(dims) {
|
|
671
|
+
const parts = [];
|
|
672
|
+
if (typeof dims.width === "number" || typeof dims.height === "number") {
|
|
673
|
+
const w = typeof dims.width === "number" ? String(dims.width) : "?";
|
|
674
|
+
const h = typeof dims.height === "number" ? String(dims.height) : "?";
|
|
675
|
+
parts.push(`${w}x${h}`);
|
|
676
|
+
}
|
|
677
|
+
if (typeof dims.aspectRatio === "number") {
|
|
678
|
+
parts.push(`aspectRatio=${dims.aspectRatio}`);
|
|
679
|
+
}
|
|
680
|
+
if (typeof dims.aspectRatioTolerance === "number") {
|
|
681
|
+
parts.push(`aspectRatioTolerance=${dims.aspectRatioTolerance}`);
|
|
682
|
+
}
|
|
683
|
+
return parts.length > 0 ? `\`${parts.join(", ")}\`` : "`(unspecified)`";
|
|
684
|
+
}
|
|
685
|
+
function renderImageInvariant(lines, inv) {
|
|
686
|
+
const { input, expected, tolerance } = inv;
|
|
687
|
+
if (typeof input.referenceArtifact === "string") {
|
|
688
|
+
lines.push(`- **Reference Artifact:** ${inlineCode(redactSensitiveText(input.referenceArtifact))}`);
|
|
689
|
+
}
|
|
690
|
+
if (typeof input.urlPath === "string") {
|
|
691
|
+
lines.push(`- **URL Path:** ${inlineCode(redactSensitiveText(input.urlPath))}`);
|
|
692
|
+
}
|
|
693
|
+
if (expected.dimensions) {
|
|
694
|
+
lines.push(`- **Dimensions:** ${formatImageDimensions(expected.dimensions)}`);
|
|
695
|
+
}
|
|
696
|
+
if (expected.nonBlank !== undefined) {
|
|
697
|
+
lines.push(`- **Non-Blank:** \`${String(expected.nonBlank)}\``);
|
|
698
|
+
}
|
|
699
|
+
if (Array.isArray(expected.palette) && expected.palette.length > 0) {
|
|
700
|
+
const paletteText = expected.palette.map((entry) => `${inlineCode(entry.hex)} (${entry.weight})`).join(", ");
|
|
701
|
+
lines.push(`- **Palette:** ${paletteText}`);
|
|
702
|
+
}
|
|
703
|
+
if (Array.isArray(expected.regions) && expected.regions.length > 0) {
|
|
704
|
+
lines.push("- **Layout Regions:**");
|
|
705
|
+
for (const region of expected.regions) {
|
|
706
|
+
lines.push(` - ${inlineCode(region.id)}: \`${formatBBox(region.bbox)}\``);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (Array.isArray(expected.typographyHierarchy) && expected.typographyHierarchy.length > 0) {
|
|
710
|
+
const bands = expected.typographyHierarchy.map((band) => `\`${band.level}\` (height~${band.estimatedHeightPx}px, bands=${band.bandCount})`);
|
|
711
|
+
lines.push(`- **Typography Hierarchy:** ${bands.join(", ")}`);
|
|
712
|
+
}
|
|
713
|
+
if (typeof tolerance.minSSIM === "number") {
|
|
714
|
+
lines.push(`- **Min SSIM:** \`${tolerance.minSSIM}\``);
|
|
715
|
+
}
|
|
716
|
+
if (typeof tolerance.maxPixelDiffRatio === "number") {
|
|
717
|
+
lines.push(`- **Max Pixel Diff Ratio:** \`${tolerance.maxPixelDiffRatio}\``);
|
|
718
|
+
}
|
|
719
|
+
if (typeof tolerance.minLayoutIoU === "number") {
|
|
720
|
+
lines.push(`- **Min Layout IoU:** \`${tolerance.minLayoutIoU}\``);
|
|
721
|
+
}
|
|
722
|
+
if (typeof tolerance.minPaletteSimilarity === "number") {
|
|
723
|
+
lines.push(`- **Min Palette Similarity:** \`${tolerance.minPaletteSimilarity}\``);
|
|
724
|
+
}
|
|
725
|
+
if (typeof tolerance.colorDelta === "number") {
|
|
726
|
+
lines.push(`- **Color Delta:** \`${tolerance.colorDelta}\``);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function renderVideoTimelineInvariant(lines, inv) {
|
|
730
|
+
const { expected, tolerance } = inv;
|
|
731
|
+
if (typeof expected.durationMs === "number") {
|
|
732
|
+
lines.push(`- **Duration (ms):** \`${expected.durationMs}\``);
|
|
733
|
+
}
|
|
734
|
+
if (Array.isArray(expected.states) && expected.states.length > 0) {
|
|
735
|
+
lines.push("- **States:**");
|
|
736
|
+
for (const state of expected.states) {
|
|
737
|
+
const details = [`keyframe=${inlineCode(state.keyframeArtifact)}`];
|
|
738
|
+
if (typeof state.timestampMs === "number") {
|
|
739
|
+
details.push(`t=${state.timestampMs}ms`);
|
|
740
|
+
}
|
|
741
|
+
if (typeof state.dHash === "string") {
|
|
742
|
+
details.push(`dHash=${inlineCode(state.dHash)}`);
|
|
743
|
+
}
|
|
744
|
+
if (typeof state.subtitleCue === "string" && state.subtitleCue.length > 0) {
|
|
745
|
+
details.push(`subtitle=${inlineCode(state.subtitleCue)}`);
|
|
746
|
+
}
|
|
747
|
+
if (state.required !== undefined) {
|
|
748
|
+
details.push(`required=${state.required}`);
|
|
749
|
+
}
|
|
750
|
+
lines.push(` - ${inlineCode(state.id)}: ${details.join(", ")}`);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (Array.isArray(expected.transitions) && expected.transitions.length > 0) {
|
|
754
|
+
lines.push("- **Transitions:**");
|
|
755
|
+
for (const tr of expected.transitions) {
|
|
756
|
+
const details = [];
|
|
757
|
+
if (typeof tr.eventHint === "string" && tr.eventHint.length > 0) {
|
|
758
|
+
details.push(`eventHint=${inlineCode(tr.eventHint)}`);
|
|
759
|
+
}
|
|
760
|
+
if (typeof tr.subtitleCue === "string" && tr.subtitleCue.length > 0) {
|
|
761
|
+
details.push(`subtitle=${inlineCode(tr.subtitleCue)}`);
|
|
762
|
+
}
|
|
763
|
+
if (typeof tr.minDeltaSSIM === "number") {
|
|
764
|
+
details.push(`minDeltaSSIM=${tr.minDeltaSSIM}`);
|
|
765
|
+
}
|
|
766
|
+
const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
|
|
767
|
+
lines.push(` - ${inlineCode(tr.from)} -> ${inlineCode(tr.to)}${suffix}`);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (typeof tolerance.stateMatchFloor === "number") {
|
|
771
|
+
lines.push(`- **State Match Floor:** \`${tolerance.stateMatchFloor}\``);
|
|
772
|
+
}
|
|
773
|
+
if (typeof tolerance.minKeyframeSSIM === "number") {
|
|
774
|
+
lines.push(`- **Min Keyframe SSIM:** \`${tolerance.minKeyframeSSIM}\``);
|
|
775
|
+
}
|
|
776
|
+
if (typeof tolerance.minMotionRegionIoU === "number") {
|
|
777
|
+
lines.push(`- **Min Motion Region IoU:** \`${tolerance.minMotionRegionIoU}\``);
|
|
778
|
+
}
|
|
779
|
+
if (typeof tolerance.maxHammingDistance === "number") {
|
|
780
|
+
lines.push(`- **Max Hamming Distance:** \`${tolerance.maxHammingDistance}\``);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function renderRepoExportsInvariant(lines, inv) {
|
|
784
|
+
const { input, expected } = inv;
|
|
785
|
+
if (typeof input.modulePath === "string") {
|
|
786
|
+
lines.push(`- **Module Path:** ${inlineCode(input.modulePath)}`);
|
|
787
|
+
}
|
|
788
|
+
if (typeof input.language === "string") {
|
|
789
|
+
lines.push(`- **Language:** ${inlineCode(input.language)}`);
|
|
790
|
+
}
|
|
791
|
+
if (Array.isArray(expected.filesPresent) && expected.filesPresent.length > 0) {
|
|
792
|
+
lines.push(`- **Files Present:** ${expected.filesPresent.map(inlineCode).join(", ")}`);
|
|
793
|
+
}
|
|
794
|
+
if (Array.isArray(expected.exports) && expected.exports.length > 0) {
|
|
795
|
+
lines.push("- **Exports:**");
|
|
796
|
+
for (const entry of expected.exports) {
|
|
797
|
+
lines.push(` - ${inlineCode(entry.name)} (${inlineCode(entry.kind)})`);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function renderPluginSvgA11yInvariant(lines, inv) {
|
|
802
|
+
const { input, expected } = inv;
|
|
803
|
+
if (typeof input.path === "string" && input.path.trim().length > 0) {
|
|
804
|
+
lines.push(`- **SVG Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
805
|
+
}
|
|
806
|
+
if (typeof expected.requireViewBox === "boolean") {
|
|
807
|
+
lines.push(`- **Require ViewBox:** \`${String(expected.requireViewBox)}\``);
|
|
808
|
+
}
|
|
809
|
+
if (typeof expected.requireAccessibleName === "boolean") {
|
|
810
|
+
lines.push(`- **Require Accessible Name:** \`${String(expected.requireAccessibleName)}\``);
|
|
811
|
+
}
|
|
812
|
+
if (typeof expected.minElements === "number" && Number.isFinite(expected.minElements)) {
|
|
813
|
+
lines.push(`- **Min Graphical Elements:** \`${expected.minElements}\``);
|
|
814
|
+
}
|
|
815
|
+
if (Array.isArray(expected.requiredIds) && expected.requiredIds.length > 0) {
|
|
816
|
+
const ids = expected.requiredIds
|
|
817
|
+
.filter((id) => typeof id === "string" && id.length > 0)
|
|
818
|
+
.map((id) => inlineCode(redactSensitiveText(id)));
|
|
819
|
+
if (ids.length > 0) {
|
|
820
|
+
lines.push(`- **Required IDs:** ${ids.join(", ")}`);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function renderPluginStateFileInvariant(lines, inv) {
|
|
825
|
+
const { input, expected } = inv;
|
|
826
|
+
if (typeof input.path === "string" && input.path.trim().length > 0) {
|
|
827
|
+
lines.push(`- **State File Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
828
|
+
}
|
|
829
|
+
if (Array.isArray(input.ignorePaths) && input.ignorePaths.length > 0) {
|
|
830
|
+
const ignored = input.ignorePaths
|
|
831
|
+
.filter((p) => typeof p === "string" && p.length > 0)
|
|
832
|
+
.map((p) => inlineCode(redactSensitiveText(p)));
|
|
833
|
+
if (ignored.length > 0) {
|
|
834
|
+
lines.push(`- **Ignore Paths:** ${ignored.join(", ")}`);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (expected.jsonSchema !== undefined) {
|
|
838
|
+
lines.push("- **JSON Schema:**");
|
|
839
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.jsonSchema), true));
|
|
840
|
+
}
|
|
841
|
+
if (expected.jsonSubset !== undefined) {
|
|
842
|
+
lines.push("- **JSON Subset:**");
|
|
843
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected.jsonSubset), true));
|
|
844
|
+
}
|
|
845
|
+
if (Array.isArray(expected.jsonPaths) && expected.jsonPaths.length > 0) {
|
|
846
|
+
const safePaths = expected.jsonPaths.map((jp) => ({
|
|
847
|
+
path: redactSensitiveText(jp.path),
|
|
848
|
+
...(jp.equals !== undefined ? { equals: redactPluginSpecValue(jp.equals) } : {}),
|
|
849
|
+
...(typeof jp.matches === "string" ? { matches: redactSensitiveText(jp.matches) } : {})
|
|
850
|
+
}));
|
|
851
|
+
renderJsonPaths(lines, safePaths);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function describeUiStateCheck(raw, idx) {
|
|
855
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
856
|
+
return `${inlineCode(`check-${idx + 1}`)}: invalid (not an object)`;
|
|
857
|
+
const c = raw;
|
|
858
|
+
const kind = typeof c.kind === "string" && c.kind ? c.kind : "unknown";
|
|
859
|
+
const id = typeof c.id === "string" && c.id.trim() ? c.id.trim() : `${kind}-${idx + 1}`;
|
|
860
|
+
const safe = (v) => inlineCode(redactSensitiveText(String(v)));
|
|
861
|
+
const parts = [];
|
|
862
|
+
if (typeof c.selector === "string" && c.selector)
|
|
863
|
+
parts.push(`selector ${safe(c.selector)}`);
|
|
864
|
+
if (Array.isArray(c.expectedFocusOrder) && c.expectedFocusOrder.length > 0) {
|
|
865
|
+
parts.push(`focus order ${c.expectedFocusOrder.filter((s) => typeof s === "string").map(safe).join(" → ")}`);
|
|
866
|
+
}
|
|
867
|
+
if (typeof c.count === "number")
|
|
868
|
+
parts.push(`count ${c.count}`);
|
|
869
|
+
if (typeof c.expectVisible === "string")
|
|
870
|
+
parts.push(`expect visible ${safe(c.expectVisible)}`);
|
|
871
|
+
if (typeof c.expectClass === "string")
|
|
872
|
+
parts.push(`expect class ${safe(c.expectClass)}`);
|
|
873
|
+
if (c.expectAttr && typeof c.expectAttr === "object" && !Array.isArray(c.expectAttr)) {
|
|
874
|
+
parts.push(`expect attrs ${inlineCode(stableJson(redactPluginSpecValue(c.expectAttr), 0))}`);
|
|
875
|
+
}
|
|
876
|
+
for (const flag of ["expectFocused", "expectVisibleFocusRing", "expectDisabled", "expectRoleAlert", "expectExists", "expectAbsent"]) {
|
|
877
|
+
if (typeof c[flag] === "boolean")
|
|
878
|
+
parts.push(`${flag}=${String(c[flag])}`);
|
|
879
|
+
}
|
|
880
|
+
if (typeof c.expectAriaInvalid === "string")
|
|
881
|
+
parts.push(`aria-invalid=${safe(c.expectAriaInvalid)}`);
|
|
882
|
+
const texts = typeof c.expectTextContains === "string" ? [c.expectTextContains] : Array.isArray(c.expectTextContains) ? c.expectTextContains : [];
|
|
883
|
+
if (texts.length > 0)
|
|
884
|
+
parts.push(`text contains ${texts.filter((t) => typeof t === "string").map(safe).join(", ")}`);
|
|
885
|
+
if (c.trigger && typeof c.trigger === "object" && !Array.isArray(c.trigger)) {
|
|
886
|
+
const t = c.trigger;
|
|
887
|
+
const action = typeof t.action === "string" ? t.action : "?";
|
|
888
|
+
const target = typeof t.selector === "string" ? ` ${safe(t.selector)}` : "";
|
|
889
|
+
const value = t.value !== undefined ? ` = ${inlineCode(maskUiStateValue(t.value))}` : "";
|
|
890
|
+
const key = typeof t.key === "string" ? ` key ${safe(t.key)}` : "";
|
|
891
|
+
parts.push(`trigger ${action}${target}${value}${key}`);
|
|
892
|
+
}
|
|
893
|
+
if (kind === "storage") {
|
|
894
|
+
const area = c.area === "sessionStorage" ? "sessionStorage" : "localStorage";
|
|
895
|
+
if (typeof c.key === "string")
|
|
896
|
+
parts.push(`${area}[${safe(c.key)}]`);
|
|
897
|
+
if (c.expectEquals !== undefined)
|
|
898
|
+
parts.push(`equals ${inlineCode(maskUiStateValue(c.expectEquals))}`);
|
|
899
|
+
if (c.expectContains !== undefined)
|
|
900
|
+
parts.push(`contains ${inlineCode(maskUiStateValue(c.expectContains))}`);
|
|
901
|
+
}
|
|
902
|
+
return `${inlineCode(redactSensitiveText(id))} (${escapeFence(kind)})${parts.length ? `: ${parts.join("; ")}` : ""}`;
|
|
903
|
+
}
|
|
904
|
+
function renderWebUiStatesInvariant(lines, inv) {
|
|
905
|
+
const { input } = inv;
|
|
906
|
+
if (typeof input.path === "string" && input.path.trim().length > 0) {
|
|
907
|
+
lines.push(`- **Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
908
|
+
}
|
|
909
|
+
if (input.headers && typeof input.headers === "object" && !Array.isArray(input.headers)) {
|
|
910
|
+
lines.push("- **Headers:**");
|
|
911
|
+
lines.push(renderJsonBlock(redactSpecHeaders(input.headers)));
|
|
912
|
+
}
|
|
913
|
+
const checks = Array.isArray(input.checks) ? input.checks : [];
|
|
914
|
+
if (checks.length === 0) {
|
|
915
|
+
lines.push("- **UI State Checks:** none (invalid: `web_ui_states` requires a non-empty `checks` array)");
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
lines.push(`- **UI State Checks (${checks.length}):**`);
|
|
919
|
+
checks.forEach((check, i) => lines.push(` - ${describeUiStateCheck(check, i)}`));
|
|
920
|
+
}
|
|
921
|
+
function renderPerfBudgetInvariant(lines, inv) {
|
|
922
|
+
const { input, expected } = inv;
|
|
923
|
+
const kind = input.kind === "http" || input.kind === "command"
|
|
924
|
+
? input.kind
|
|
925
|
+
: inv.domain === "cli" || (Array.isArray(input.args) && typeof input.path !== "string")
|
|
926
|
+
? "command"
|
|
927
|
+
: "http";
|
|
928
|
+
lines.push(`- **Kind:** ${inlineCode(kind)}`);
|
|
929
|
+
if (kind === "http") {
|
|
930
|
+
if (typeof input.method === "string" && input.method.trim().length > 0) {
|
|
931
|
+
lines.push(`- **Method:** ${inlineCode(redactSensitiveText(input.method.trim().toUpperCase()))}`);
|
|
932
|
+
}
|
|
933
|
+
if (typeof input.path === "string" && input.path.trim().length > 0) {
|
|
934
|
+
lines.push(`- **Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
935
|
+
}
|
|
936
|
+
if (hasNonEmptyRecord(input.query)) {
|
|
937
|
+
lines.push("- **Query:**");
|
|
938
|
+
lines.push(renderJsonBlock(redactSpecQuery(input.query)));
|
|
939
|
+
}
|
|
940
|
+
if (hasNonEmptyRecord(input.headers)) {
|
|
941
|
+
const safeHeaders = redactSpecHeaders(input.headers);
|
|
942
|
+
if (hasNonEmptyRecord(safeHeaders)) {
|
|
943
|
+
lines.push("- **Request Headers:**");
|
|
944
|
+
lines.push(renderJsonBlock(safeHeaders));
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (input.body !== undefined && input.body !== null) {
|
|
948
|
+
if (typeof input.body === "string") {
|
|
949
|
+
pushTextAssertionBlock(lines, "Request Body", redactSensitiveText(input.body));
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
lines.push("- **Request Body:**");
|
|
953
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(input.body), true));
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
if (Array.isArray(input.args)) {
|
|
959
|
+
lines.push(`- **Args:** ${redactCommandArgsForSpec(input.args)}`);
|
|
960
|
+
}
|
|
961
|
+
if (hasNonEmptyRecord(input.env)) {
|
|
962
|
+
lines.push("- **Env:**");
|
|
963
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(input.env)));
|
|
964
|
+
}
|
|
965
|
+
if (typeof input.cwd === "string" && input.cwd.length > 0) {
|
|
966
|
+
lines.push(`- **Working Directory:** ${inlineCode(redactSensitiveText(input.cwd))}`);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (hasNonEmptyRecord(input.vars)) {
|
|
970
|
+
const safeVars = {};
|
|
971
|
+
for (const [k, v] of Object.entries(redactSpecVars(input.vars))) {
|
|
972
|
+
safeVars[k] = redactSensitiveText(v);
|
|
973
|
+
}
|
|
974
|
+
lines.push("- **Variables:**");
|
|
975
|
+
lines.push(renderJsonBlock(safeVars));
|
|
976
|
+
}
|
|
977
|
+
if (typeof input.runs === "number" && Number.isFinite(input.runs)) {
|
|
978
|
+
lines.push(`- **Runs:** \`${input.runs}\``);
|
|
979
|
+
}
|
|
980
|
+
if (typeof input.warmupRuns === "number" && Number.isFinite(input.warmupRuns)) {
|
|
981
|
+
lines.push(`- **Warmup Runs:** \`${input.warmupRuns}\``);
|
|
982
|
+
}
|
|
983
|
+
if (typeof input.timeoutMs === "number" && Number.isFinite(input.timeoutMs)) {
|
|
984
|
+
lines.push(`- **Timeout (ms):** \`${input.timeoutMs}\``);
|
|
985
|
+
}
|
|
986
|
+
if (expected.status !== undefined) {
|
|
987
|
+
lines.push(`- **Expected Status:** ${formatNumberOrArray(expected.status)}`);
|
|
988
|
+
}
|
|
989
|
+
if (expected.exitCode !== undefined) {
|
|
990
|
+
lines.push(`- **Expected Exit Code:** ${formatNumberOrArray(expected.exitCode)}`);
|
|
991
|
+
}
|
|
992
|
+
const budgetLabels = [
|
|
993
|
+
["maxP50Ms", "Max P50 Latency (ms)"],
|
|
994
|
+
["maxP95Ms", "Max P95 Latency (ms)"],
|
|
995
|
+
["maxP99Ms", "Max P99 Latency (ms)"],
|
|
996
|
+
["maxMeanMs", "Max Mean Latency (ms)"],
|
|
997
|
+
["maxDurationMs", "Max Duration (ms)"],
|
|
998
|
+
["minBytes", "Min Payload Bytes"],
|
|
999
|
+
["maxBytes", "Max Payload Bytes"],
|
|
1000
|
+
["maxErrorRate", "Max Error Rate"]
|
|
1001
|
+
];
|
|
1002
|
+
for (const [key, label] of budgetLabels) {
|
|
1003
|
+
const val = expected[key];
|
|
1004
|
+
if (typeof val === "number" && Number.isFinite(val)) {
|
|
1005
|
+
lines.push(`- **${label}:** \`${val}\``);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function renderGenericPluginInvariant(lines, inv) {
|
|
1010
|
+
const { input, expected, tolerance } = inv;
|
|
1011
|
+
if (typeof input.path === "string" && input.path.trim().length > 0) {
|
|
1012
|
+
lines.push(`- **Path:** ${inlineCode(redactSensitiveText(input.path))}`);
|
|
1013
|
+
}
|
|
1014
|
+
if (hasNonEmptyRecord(input)) {
|
|
1015
|
+
lines.push("- **Plugin Input:**");
|
|
1016
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(input), true));
|
|
1017
|
+
}
|
|
1018
|
+
if (hasNonEmptyRecord(expected)) {
|
|
1019
|
+
lines.push("- **Plugin Expected:**");
|
|
1020
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(expected), true));
|
|
1021
|
+
}
|
|
1022
|
+
if (hasNonEmptyRecord(tolerance)) {
|
|
1023
|
+
lines.push("- **Plugin Tolerance:**");
|
|
1024
|
+
lines.push(renderJsonBlock(redactPluginSpecValue(tolerance), true));
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function renderInvariantSection(inv) {
|
|
1028
|
+
const lines = [`### ${escapeFence(normalizeNewlines(redactSensitiveText(inv.id)))} (${inv.type}, ${inv.severity})`];
|
|
1029
|
+
if (typeof inv.description === "string" && inv.description.length > 0) {
|
|
1030
|
+
lines.push(`- **Description:** ${escapeFence(normalizeNewlines(redactSensitiveText(inv.description)))}`);
|
|
1031
|
+
}
|
|
1032
|
+
if (Array.isArray(inv.tags) && inv.tags.length > 0) {
|
|
1033
|
+
lines.push(`- **Tags:** ${inv.tags.map((t) => inlineCode(redactSensitiveText(String(t)))).join(", ")}`);
|
|
1034
|
+
}
|
|
1035
|
+
switch (inv.type) {
|
|
1036
|
+
case "command":
|
|
1037
|
+
renderCommandInvariant(lines, inv);
|
|
1038
|
+
break;
|
|
1039
|
+
case "web_route":
|
|
1040
|
+
case "web_flow":
|
|
1041
|
+
case "web_network":
|
|
1042
|
+
renderWebInvariant(lines, inv);
|
|
1043
|
+
break;
|
|
1044
|
+
case "web_ui_states":
|
|
1045
|
+
renderWebUiStatesInvariant(lines, inv);
|
|
1046
|
+
break;
|
|
1047
|
+
case "http":
|
|
1048
|
+
renderHttpInvariant(lines, inv);
|
|
1049
|
+
break;
|
|
1050
|
+
case "http_workflow":
|
|
1051
|
+
renderHttpWorkflowInvariant(lines, inv);
|
|
1052
|
+
break;
|
|
1053
|
+
case "http_stream":
|
|
1054
|
+
renderHttpStreamInvariant(lines, inv);
|
|
1055
|
+
break;
|
|
1056
|
+
case "ws_protocol":
|
|
1057
|
+
renderWsProtocolInvariant(lines, inv);
|
|
1058
|
+
break;
|
|
1059
|
+
case "perf_budget":
|
|
1060
|
+
renderPerfBudgetInvariant(lines, inv);
|
|
1061
|
+
break;
|
|
1062
|
+
case "image_layout":
|
|
1063
|
+
case "image_perceptual":
|
|
1064
|
+
renderImageInvariant(lines, inv);
|
|
1065
|
+
break;
|
|
1066
|
+
case "video_timeline":
|
|
1067
|
+
renderVideoTimelineInvariant(lines, inv);
|
|
1068
|
+
break;
|
|
1069
|
+
case "repo_exports":
|
|
1070
|
+
renderRepoExportsInvariant(lines, inv);
|
|
1071
|
+
break;
|
|
1072
|
+
case "plugin_svg_a11y":
|
|
1073
|
+
renderPluginSvgA11yInvariant(lines, inv);
|
|
1074
|
+
break;
|
|
1075
|
+
case "plugin_state_file":
|
|
1076
|
+
renderPluginStateFileInvariant(lines, inv);
|
|
1077
|
+
break;
|
|
1078
|
+
default: {
|
|
1079
|
+
renderGenericPluginInvariant(lines, inv);
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return lines.join("\n");
|
|
1084
|
+
}
|
|
1085
|
+
function renderFixturesSection(fixtures) {
|
|
1086
|
+
if (!fixtures || typeof fixtures !== "object" || Array.isArray(fixtures))
|
|
1087
|
+
return null;
|
|
1088
|
+
const seedCount = Array.isArray(fixtures.seedFiles) ? fixtures.seedFiles.length : 0;
|
|
1089
|
+
const snapshotCount = Array.isArray(fixtures.snapshotPaths) ? fixtures.snapshotPaths.length : 0;
|
|
1090
|
+
const httpSetupCount = Array.isArray(fixtures.httpSetup) ? fixtures.httpSetup.length : 0;
|
|
1091
|
+
const httpTeardownCount = Array.isArray(fixtures.httpTeardown) ? fixtures.httpTeardown.length : 0;
|
|
1092
|
+
const cmdSetupCount = Array.isArray(fixtures.commandSetup) ? fixtures.commandSetup.length : 0;
|
|
1093
|
+
const cmdTeardownCount = Array.isArray(fixtures.commandTeardown) ? fixtures.commandTeardown.length : 0;
|
|
1094
|
+
if (seedCount + snapshotCount + httpSetupCount + httpTeardownCount + cmdSetupCount + cmdTeardownCount === 0) {
|
|
1095
|
+
return null;
|
|
1096
|
+
}
|
|
1097
|
+
return [
|
|
1098
|
+
"## Fixtures & Rollback",
|
|
1099
|
+
"Declarative workspace fixtures run before verification and roll back afterward (values, file contents, and sensitive headers are omitted from this spec).",
|
|
1100
|
+
"",
|
|
1101
|
+
"| Phase | Count |",
|
|
1102
|
+
"| :--- | :--- |",
|
|
1103
|
+
`| Seed Files | ${seedCount} |`,
|
|
1104
|
+
`| Snapshot Paths | ${snapshotCount} |`,
|
|
1105
|
+
`| HTTP Setup / Teardown Hooks | ${httpSetupCount} / ${httpTeardownCount} |`,
|
|
1106
|
+
`| Command Setup / Teardown Hooks | ${cmdSetupCount} / ${cmdTeardownCount} |`
|
|
1107
|
+
].join("\n");
|
|
1108
|
+
}
|
|
1109
|
+
function renderSlicesSection(slices, holdoutIds) {
|
|
1110
|
+
const lines = ["## Slices"];
|
|
1111
|
+
if (slices.length === 0) {
|
|
1112
|
+
lines.push("No explicit slices defined (verify evaluates all visible invariants).");
|
|
1113
|
+
return lines.join("\n");
|
|
1114
|
+
}
|
|
1115
|
+
lines.push("| ID | Title | Dependencies | Invariant IDs |");
|
|
1116
|
+
lines.push("| :--- | :--- | :--- | :--- |");
|
|
1117
|
+
for (const slice of slices) {
|
|
1118
|
+
const deps = Array.isArray(slice.dependsOn) && slice.dependsOn.length > 0
|
|
1119
|
+
? slice.dependsOn.map(inlineCode).join(", ")
|
|
1120
|
+
: "(none)";
|
|
1121
|
+
const visibleSliceInvariants = (Array.isArray(slice.invariantIds) ? slice.invariantIds : []).filter((id) => !holdoutIds.has(id));
|
|
1122
|
+
const invIdsText = visibleSliceInvariants.length > 0 ? visibleSliceInvariants.map(inlineCode).join(", ") : "(none)";
|
|
1123
|
+
lines.push(`| ${escapeTableCell(slice.id)} | ${escapeTableCell(slice.title)} | ${deps} | ${invIdsText} |`);
|
|
1124
|
+
}
|
|
1125
|
+
return lines.join("\n");
|
|
1126
|
+
}
|
|
1127
|
+
export function buildSpecMarkdown(contract, holdoutCount) {
|
|
1128
|
+
const allInvariants = Array.isArray(contract.invariants) ? contract.invariants : [];
|
|
1129
|
+
const visible = allInvariants.filter((inv) => inv.holdout !== true);
|
|
1130
|
+
const holdoutIds = new Set(allInvariants.filter((inv) => inv.holdout === true).map((inv) => inv.id));
|
|
1131
|
+
const inlineHoldouts = allInvariants.length - visible.length;
|
|
1132
|
+
const totalHoldouts = typeof holdoutCount === "number" && Number.isFinite(holdoutCount) && holdoutCount > 0
|
|
1133
|
+
? Math.max(Math.floor(holdoutCount), inlineHoldouts)
|
|
1134
|
+
: inlineHoldouts;
|
|
1135
|
+
const domains = Array.isArray(contract.target.domains) && contract.target.domains.length > 0
|
|
1136
|
+
? contract.target.domains.join(", ")
|
|
1137
|
+
: "(none)";
|
|
1138
|
+
const sources = Array.isArray(contract.target.sources) && contract.target.sources.length > 0
|
|
1139
|
+
? escapeTableCell(contract.target.sources.map((s) => `${redactSensitiveText(s.kind)}: ${redactSensitiveText(s.ref)}`).join("; "))
|
|
1140
|
+
: "(none)";
|
|
1141
|
+
const headerLines = [
|
|
1142
|
+
`# ${escapeFence(normalizeNewlines(redactSensitiveText(contract.target.name)))} — Re-Implementation Specification`,
|
|
1143
|
+
"",
|
|
1144
|
+
"| Property | Value |",
|
|
1145
|
+
"| :--- | :--- |",
|
|
1146
|
+
`| Domains | ${escapeTableCell(domains)} |`,
|
|
1147
|
+
`| Sources | ${sources} |`,
|
|
1148
|
+
`| Hard Parity Threshold | ${contract.thresholds.hardBehavioralParity} |`,
|
|
1149
|
+
`| Soft Parity Threshold | ${contract.thresholds.softPerceptualParity} |`,
|
|
1150
|
+
`| Soft Gate Mode | ${escapeTableCell(contract.thresholds.softGateMode)} |`,
|
|
1151
|
+
`| Visible Invariants | ${visible.length} |`
|
|
1152
|
+
];
|
|
1153
|
+
const rulesLines = [
|
|
1154
|
+
"## Zero-Assumption Contract Rules",
|
|
1155
|
+
"- Every parameter default, exit code, stdout/stderr assertion, JSON schema field, route landmark, API expectation, and layout constraint listed below is binding.",
|
|
1156
|
+
"- Do not assume undocumented flags, routes, defaults, or output formats.",
|
|
1157
|
+
"- Internal implementation structure is unconstrained unless explicitly required by a `repo_exports` invariant.",
|
|
1158
|
+
"- Never edit `.vibecode/contract.json` or attempt to locate holdout tests outside the workspace."
|
|
1159
|
+
];
|
|
1160
|
+
const slices = Array.isArray(contract.slices) ? contract.slices : [];
|
|
1161
|
+
const slicesSection = renderSlicesSection(slices, holdoutIds);
|
|
1162
|
+
const fixturesSection = renderFixturesSection(contract.fixtures);
|
|
1163
|
+
const visibleLines = ["## Visible Invariants"];
|
|
1164
|
+
if (visible.length === 0) {
|
|
1165
|
+
visibleLines.push("No visible invariants defined.");
|
|
1166
|
+
}
|
|
1167
|
+
else {
|
|
1168
|
+
for (const inv of visible) {
|
|
1169
|
+
visibleLines.push(renderInvariantSection(inv));
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
const holdoutLines = [
|
|
1173
|
+
"## Holdout Verification",
|
|
1174
|
+
`> ${totalHoldouts} unseen holdout invariants (negative inputs, boundary cases) are stored in an isolated external vault outside this workspace and verified during \`vibecode-anything verify\`.`
|
|
1175
|
+
];
|
|
1176
|
+
const sections = [
|
|
1177
|
+
headerLines.join("\n"),
|
|
1178
|
+
rulesLines.join("\n"),
|
|
1179
|
+
slicesSection,
|
|
1180
|
+
...(fixturesSection ? [fixturesSection] : []),
|
|
1181
|
+
visibleLines.join("\n\n"),
|
|
1182
|
+
holdoutLines.join("\n")
|
|
1183
|
+
];
|
|
1184
|
+
return `${sections.join("\n\n")}\n`;
|
|
1185
|
+
}
|
|
1186
|
+
export function writeSpecFile(workspaceDir, options) {
|
|
1187
|
+
const outPath = options.outPath
|
|
1188
|
+
? path.resolve(workspaceDir, options.outPath)
|
|
1189
|
+
: resolveWorkspace(workspaceDir).specPath;
|
|
1190
|
+
ensureDir(path.dirname(outPath));
|
|
1191
|
+
const md = buildSpecMarkdown(options.contract, options.holdoutCount);
|
|
1192
|
+
const tmp = `${outPath}.tmp`;
|
|
1193
|
+
try {
|
|
1194
|
+
fs.writeFileSync(tmp, md, "utf8");
|
|
1195
|
+
fs.renameSync(tmp, outPath);
|
|
1196
|
+
}
|
|
1197
|
+
catch (err) {
|
|
1198
|
+
fs.rmSync(tmp, { force: true });
|
|
1199
|
+
throw err;
|
|
1200
|
+
}
|
|
1201
|
+
return outPath;
|
|
1202
|
+
}
|