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,1111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency contract security & quality auditor for `vibecode-anything lint`.
|
|
3
|
+
*
|
|
4
|
+
* Audits `.vibecode/contract.json` for schema validity, secret/vault leaks,
|
|
5
|
+
* inline holdouts, duplicate IDs/probes, weak assertions, soft-only gates,
|
|
6
|
+
* and slice graph integrity without ever echoing raw secret literals.
|
|
7
|
+
*/
|
|
8
|
+
import { validateContract } from "./schema.js";
|
|
9
|
+
import { validateContractFixtures } from "./fixtures.js";
|
|
10
|
+
import { ANSI, isRecordSafe, isSensitiveHeaderName, isSensitiveKeyName, isSensitiveQueryParamName, redactSensitiveText, styleAnsi } from "./security.js";
|
|
11
|
+
const MAX_WALK_DEPTH = 32;
|
|
12
|
+
const SAFE_PLACEHOLDER_RE = /^\[REDACTED[^\]]*\]$/i;
|
|
13
|
+
const SAFE_TEMPLATE_RE = /^\{\{[^{}]+\}\}$/;
|
|
14
|
+
const SAFE_AUTH_SCHEME_PLACEHOLDER_RE = /^(?:Bearer|Basic|Token|ApiKey|Digest)\s+(?:\[REDACTED[^\]]*\]|\{\{[^{}]+\}\})$/i;
|
|
15
|
+
const URL_BASIC_AUTH_RE = /\b[a-z][a-z0-9+.-]*:\/\/([^:@\s"'`<>\/]+):([^@\s"'`<>\/]+)@/gi;
|
|
16
|
+
const QUERY_PARAM_RE = /(?:[?&])([A-Za-z0-9_.-]+)=([^&#\s"'`<>]+)/g;
|
|
17
|
+
const BEARER_TOKEN_RE = /\bBearer\s+([A-Za-z0-9._~+/=-]{6,})/gi;
|
|
18
|
+
const COOKIE_STRING_RE = /(?:^|[\s"'`{,;(\[])["']?\b(?:set-cookie|cookie)\b["']?\s*[:=]\s*["']?([^\r\n"'`}]+)/gi;
|
|
19
|
+
const INLINE_SENSITIVE_HEADER_LINE_RE = /^\s*(authorization|proxy-authorization|cookie|set-cookie|x-api-key|x-auth-token|x-csrf-token|x-xsrf-token)\s*:\s*(.+)$/i;
|
|
20
|
+
const VAULT_DIR_RE = /\.vibecode-vault\b/i;
|
|
21
|
+
const HOLDOUTS_FILE_RE = /\bholdouts\.json\b/i;
|
|
22
|
+
const HOLDOUT_SHARD_RE = /\bholdout-[A-Za-z0-9._-]+\.json\b/i;
|
|
23
|
+
// Defense-in-depth sanitizer for messages originating from schema validation or external callers.
|
|
24
|
+
const SANITIZE_VAULT_DIR_RE = /[^\s"'`<>()[\]{}]*\.vibecode-vault[^\s"'`<>()[\]{}]*/gi;
|
|
25
|
+
const SANITIZE_VAULT_FILE_RE = /[^\s"'`<>()[\]{}]*holdouts?(?:-[A-Za-z0-9._-]+)?\.json/gi;
|
|
26
|
+
const SANITIZE_URL_AUTH_RE = /([a-z][a-z0-9+.-]*:\/\/)([^:@\s"'`<>\/]+:[^@\s"'`<>\/]+)(@)/gi;
|
|
27
|
+
const SANITIZE_BEARER_RE = /(\bBearer\s+)([A-Za-z0-9._~+/=-]{6,})/gi;
|
|
28
|
+
const SANITIZE_COOKIE_RE = /(["']?\b(?:set-cookie|cookie)\b["']?\s*[:=]\s*["']?)([^\r\n"'`}]+)/gi;
|
|
29
|
+
const SENSITIVE_ENV_KEY_RE = /(?:^|_)(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|APIKEY|PRIVATE_KEY|AUTH_HEADER|AUTHORIZATION|COOKIE)(?:$|_)/i;
|
|
30
|
+
// eslint-disable-next-line no-control-regex
|
|
31
|
+
const ANSI_OSC_RE = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;
|
|
32
|
+
// eslint-disable-next-line no-control-regex
|
|
33
|
+
const ANSI_CSI_RE = /\x1b\[[0-?]*[ -/]*[@-~]/g;
|
|
34
|
+
// eslint-disable-next-line no-control-regex
|
|
35
|
+
const CONTROL_CHARS_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
|
|
36
|
+
function isObject(value) {
|
|
37
|
+
return isRecordSafe(value);
|
|
38
|
+
}
|
|
39
|
+
function isNonEmptyString(value) {
|
|
40
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
41
|
+
}
|
|
42
|
+
function isNonEmptyArray(value) {
|
|
43
|
+
return Array.isArray(value) && value.length > 0;
|
|
44
|
+
}
|
|
45
|
+
function isNonEmptyObject(value) {
|
|
46
|
+
return isObject(value) && Object.keys(value).length > 0;
|
|
47
|
+
}
|
|
48
|
+
function formatPropPath(base, key) {
|
|
49
|
+
return /^[A-Za-z0-9_$-]+$/.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
|
|
50
|
+
}
|
|
51
|
+
function safeDecodeURIComponent(value) {
|
|
52
|
+
try {
|
|
53
|
+
return decodeURIComponent(value);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function isSafePlaceholder(raw) {
|
|
60
|
+
const trimmed = raw.trim();
|
|
61
|
+
if (trimmed.length === 0)
|
|
62
|
+
return true;
|
|
63
|
+
if (SAFE_PLACEHOLDER_RE.test(trimmed))
|
|
64
|
+
return true;
|
|
65
|
+
if (SAFE_TEMPLATE_RE.test(trimmed))
|
|
66
|
+
return true;
|
|
67
|
+
if (SAFE_AUTH_SCHEME_PLACEHOLDER_RE.test(trimmed))
|
|
68
|
+
return true;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
function isSafeCookieValue(raw) {
|
|
72
|
+
const trimmed = raw.trim();
|
|
73
|
+
return isSafePlaceholder(trimmed) || trimmed.toUpperCase().startsWith("[REDACTED");
|
|
74
|
+
}
|
|
75
|
+
function sanitizeText(text) {
|
|
76
|
+
return text
|
|
77
|
+
.replace(ANSI_OSC_RE, "")
|
|
78
|
+
.replace(ANSI_CSI_RE, "")
|
|
79
|
+
.replace(CONTROL_CHARS_RE, " ")
|
|
80
|
+
.replace(SANITIZE_VAULT_DIR_RE, "[REDACTED_VAULT]")
|
|
81
|
+
.replace(SANITIZE_VAULT_FILE_RE, "[REDACTED_VAULT]")
|
|
82
|
+
.replace(SANITIZE_URL_AUTH_RE, "$1[REDACTED]$3")
|
|
83
|
+
.replace(QUERY_PARAM_RE, (match, key, rawVal) => {
|
|
84
|
+
if (!isSensitiveQueryParamName(key))
|
|
85
|
+
return match;
|
|
86
|
+
const decoded = safeDecodeURIComponent(rawVal);
|
|
87
|
+
if (isSafePlaceholder(rawVal) || isSafePlaceholder(decoded))
|
|
88
|
+
return match;
|
|
89
|
+
return `${match[0]}${key}=[REDACTED]`;
|
|
90
|
+
})
|
|
91
|
+
.replace(SANITIZE_COOKIE_RE, (match, prefix, rawVal) => {
|
|
92
|
+
if (isSafeCookieValue(rawVal))
|
|
93
|
+
return match;
|
|
94
|
+
return `${prefix}[REDACTED]`;
|
|
95
|
+
})
|
|
96
|
+
.replace(SANITIZE_BEARER_RE, "$1[REDACTED]");
|
|
97
|
+
}
|
|
98
|
+
function sanitizeLine(text) {
|
|
99
|
+
return sanitizeText(text).replace(/[\r\n\u2028\u2029]+/g, " ").trim();
|
|
100
|
+
}
|
|
101
|
+
function canonicalJson(value, seen = new WeakSet()) {
|
|
102
|
+
if (value === null)
|
|
103
|
+
return "null";
|
|
104
|
+
if (typeof value === "boolean" || typeof value === "string")
|
|
105
|
+
return JSON.stringify(value);
|
|
106
|
+
if (typeof value === "number")
|
|
107
|
+
return Number.isFinite(value) ? JSON.stringify(value) : String(value);
|
|
108
|
+
if (typeof value === "undefined")
|
|
109
|
+
return "undefined";
|
|
110
|
+
if (Array.isArray(value)) {
|
|
111
|
+
if (seen.has(value))
|
|
112
|
+
return '"[Circular]"';
|
|
113
|
+
seen.add(value);
|
|
114
|
+
const parts = value.map((item) => (item === undefined ? "null" : canonicalJson(item, seen)));
|
|
115
|
+
seen.delete(value);
|
|
116
|
+
return `[${parts.join(",")}]`;
|
|
117
|
+
}
|
|
118
|
+
if (typeof value === "object") {
|
|
119
|
+
if (seen.has(value))
|
|
120
|
+
return '"[Circular]"';
|
|
121
|
+
seen.add(value);
|
|
122
|
+
const obj = value;
|
|
123
|
+
const keys = Object.keys(obj).sort();
|
|
124
|
+
const parts = [];
|
|
125
|
+
for (const key of keys) {
|
|
126
|
+
if (obj[key] === undefined)
|
|
127
|
+
continue;
|
|
128
|
+
parts.push(`${JSON.stringify(key)}:${canonicalJson(obj[key], seen)}`);
|
|
129
|
+
}
|
|
130
|
+
seen.delete(value);
|
|
131
|
+
return `{${parts.join(",")}}`;
|
|
132
|
+
}
|
|
133
|
+
return JSON.stringify(String(value));
|
|
134
|
+
}
|
|
135
|
+
function scanStringForSecrets(value, path, issues, options = {}) {
|
|
136
|
+
if (!value)
|
|
137
|
+
return;
|
|
138
|
+
// 1. Exposed vault / holdout paths
|
|
139
|
+
if (VAULT_DIR_RE.test(value) || HOLDOUTS_FILE_RE.test(value) || HOLDOUT_SHARD_RE.test(value)) {
|
|
140
|
+
issues.push({
|
|
141
|
+
code: "SECRET_EXPOSED",
|
|
142
|
+
severity: "error",
|
|
143
|
+
path,
|
|
144
|
+
message: "Exposed holdout vault path reference detected in contract.",
|
|
145
|
+
suggestion: "Remove holdout vault file paths from the visible contract so agents cannot locate holdouts."
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// 2. URL basic-auth credentials (e.g. https://user:pass@host)
|
|
149
|
+
URL_BASIC_AUTH_RE.lastIndex = 0;
|
|
150
|
+
let urlMatch;
|
|
151
|
+
let reportedBasicAuth = false;
|
|
152
|
+
while ((urlMatch = URL_BASIC_AUTH_RE.exec(value)) !== null) {
|
|
153
|
+
const rawPass = urlMatch[2] ?? "";
|
|
154
|
+
const decodedPass = safeDecodeURIComponent(rawPass);
|
|
155
|
+
if (!isSafePlaceholder(rawPass) && !isSafePlaceholder(decodedPass)) {
|
|
156
|
+
if (!reportedBasicAuth) {
|
|
157
|
+
reportedBasicAuth = true;
|
|
158
|
+
issues.push({
|
|
159
|
+
code: "SECRET_EXPOSED",
|
|
160
|
+
severity: "error",
|
|
161
|
+
path,
|
|
162
|
+
message: "URL contains embedded basic-auth credentials.",
|
|
163
|
+
suggestion: "Strip credentials from URLs and inject auth at runtime via environment variables."
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// 3. Sensitive query parameters in URLs/paths
|
|
169
|
+
QUERY_PARAM_RE.lastIndex = 0;
|
|
170
|
+
let queryMatch;
|
|
171
|
+
const reportedQueryKeys = new Set();
|
|
172
|
+
while ((queryMatch = QUERY_PARAM_RE.exec(value)) !== null) {
|
|
173
|
+
const paramKey = queryMatch[1] ?? "";
|
|
174
|
+
const rawVal = queryMatch[2] ?? "";
|
|
175
|
+
if (!paramKey || !isSensitiveQueryParamName(paramKey))
|
|
176
|
+
continue;
|
|
177
|
+
const decodedVal = safeDecodeURIComponent(rawVal);
|
|
178
|
+
if (isSafePlaceholder(rawVal) || isSafePlaceholder(decodedVal))
|
|
179
|
+
continue;
|
|
180
|
+
const normKey = paramKey.toLowerCase();
|
|
181
|
+
if (reportedQueryKeys.has(normKey))
|
|
182
|
+
continue;
|
|
183
|
+
reportedQueryKeys.add(normKey);
|
|
184
|
+
issues.push({
|
|
185
|
+
code: "SECRET_EXPOSED",
|
|
186
|
+
severity: "error",
|
|
187
|
+
path,
|
|
188
|
+
message: `Sensitive query parameter "${paramKey}" contains an unredacted value.`,
|
|
189
|
+
suggestion: `Remove "${paramKey}" or replace its value with "[REDACTED]" or a "{{...}}" placeholder.`
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (options.skipRawBearerAndCookie)
|
|
193
|
+
return;
|
|
194
|
+
// 4. Optional single-line header argument (e.g. CLI `-H "X-Api-Key: secret"`)
|
|
195
|
+
if (options.allowInlineHeaderLine) {
|
|
196
|
+
const headerLineMatch = INLINE_SENSITIVE_HEADER_LINE_RE.exec(value);
|
|
197
|
+
if (headerLineMatch) {
|
|
198
|
+
const headerName = headerLineMatch[1];
|
|
199
|
+
const headerVal = headerLineMatch[2];
|
|
200
|
+
if (!isSafePlaceholder(headerVal)) {
|
|
201
|
+
issues.push({
|
|
202
|
+
code: "SECRET_EXPOSED",
|
|
203
|
+
severity: "error",
|
|
204
|
+
path,
|
|
205
|
+
message: `Sensitive HTTP header "${headerName}" contains an unredacted value.`,
|
|
206
|
+
suggestion: `Replace the "${headerName}" value with "[REDACTED]" or a "{{...}}" template placeholder.`
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// 5. Raw Bearer tokens
|
|
214
|
+
BEARER_TOKEN_RE.lastIndex = 0;
|
|
215
|
+
let bearerMatch;
|
|
216
|
+
let reportedBearer = false;
|
|
217
|
+
while ((bearerMatch = BEARER_TOKEN_RE.exec(value)) !== null) {
|
|
218
|
+
const token = bearerMatch[1] ?? "";
|
|
219
|
+
if (isSafePlaceholder(token))
|
|
220
|
+
continue;
|
|
221
|
+
if (!reportedBearer) {
|
|
222
|
+
reportedBearer = true;
|
|
223
|
+
issues.push({
|
|
224
|
+
code: "SECRET_EXPOSED",
|
|
225
|
+
severity: "error",
|
|
226
|
+
path,
|
|
227
|
+
message: "Unredacted Bearer token detected in contract string.",
|
|
228
|
+
suggestion: 'Replace the token with "Bearer [REDACTED]" or a "{{...}}" template placeholder.'
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// 6. Raw Cookie / Set-Cookie strings
|
|
233
|
+
COOKIE_STRING_RE.lastIndex = 0;
|
|
234
|
+
let cookieMatch;
|
|
235
|
+
let reportedCookie = false;
|
|
236
|
+
while ((cookieMatch = COOKIE_STRING_RE.exec(value)) !== null) {
|
|
237
|
+
const cookieVal = (cookieMatch[1] ?? "").trim();
|
|
238
|
+
if (isSafeCookieValue(cookieVal))
|
|
239
|
+
continue;
|
|
240
|
+
if (!reportedCookie) {
|
|
241
|
+
reportedCookie = true;
|
|
242
|
+
issues.push({
|
|
243
|
+
code: "SECRET_EXPOSED",
|
|
244
|
+
severity: "error",
|
|
245
|
+
path,
|
|
246
|
+
message: "Unredacted Cookie value detected in contract string.",
|
|
247
|
+
suggestion: 'Replace the cookie value with "[REDACTED]" or a "{{...}}" template placeholder.'
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function scanValueForSecrets(value, path, issues, seen, depth = 0, context = {}) {
|
|
253
|
+
if (depth > MAX_WALK_DEPTH || value === null || value === undefined)
|
|
254
|
+
return;
|
|
255
|
+
if (typeof value === "string") {
|
|
256
|
+
scanStringForSecrets(value, path, issues, { allowInlineHeaderLine: context.inArgs === true });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (typeof value !== "object")
|
|
260
|
+
return;
|
|
261
|
+
if (seen.has(value))
|
|
262
|
+
return;
|
|
263
|
+
seen.add(value);
|
|
264
|
+
if (Array.isArray(value)) {
|
|
265
|
+
for (let i = 0; i < value.length; i++) {
|
|
266
|
+
scanValueForSecrets(value[i], `${path}[${i}]`, issues, seen, depth + 1, {
|
|
267
|
+
inArgs: context.inArgs
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
seen.delete(value);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const obj = value;
|
|
274
|
+
for (const [key, entry] of Object.entries(obj)) {
|
|
275
|
+
const childPath = formatPropPath(path, key);
|
|
276
|
+
if (context.inHeaders && isSensitiveHeaderName(key)) {
|
|
277
|
+
if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") {
|
|
278
|
+
const strVal = String(entry);
|
|
279
|
+
if (strVal.trim().length > 0 && !isSafePlaceholder(strVal)) {
|
|
280
|
+
issues.push({
|
|
281
|
+
code: "SECRET_EXPOSED",
|
|
282
|
+
severity: "error",
|
|
283
|
+
path: childPath,
|
|
284
|
+
message: `Sensitive HTTP header "${key}" contains an unredacted value.`,
|
|
285
|
+
suggestion: `Remove header "${key}" or replace its value with "[REDACTED]" or a "{{...}}" placeholder.`
|
|
286
|
+
});
|
|
287
|
+
// Still check for vault path leaks in this string without double-reporting Bearer/Cookie.
|
|
288
|
+
if (typeof entry === "string") {
|
|
289
|
+
scanStringForSecrets(entry, childPath, issues, { skipRawBearerAndCookie: true });
|
|
290
|
+
}
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (context.inQuery && isSensitiveQueryParamName(key)) {
|
|
296
|
+
if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") {
|
|
297
|
+
const strVal = String(entry);
|
|
298
|
+
if (strVal.trim().length > 0 && !isSafePlaceholder(strVal)) {
|
|
299
|
+
issues.push({
|
|
300
|
+
code: "SECRET_EXPOSED",
|
|
301
|
+
severity: "error",
|
|
302
|
+
path: childPath,
|
|
303
|
+
message: `Sensitive query parameter "${key}" contains an unredacted value.`,
|
|
304
|
+
suggestion: `Remove query parameter "${key}" or replace its value with "[REDACTED]" or a "{{...}}" placeholder.`
|
|
305
|
+
});
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (context.inEnv && (SENSITIVE_ENV_KEY_RE.test(key) || isSensitiveHeaderName(key) || isSensitiveQueryParamName(key))) {
|
|
311
|
+
if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") {
|
|
312
|
+
const strVal = String(entry);
|
|
313
|
+
if (strVal.trim().length > 0 && !isSafePlaceholder(strVal)) {
|
|
314
|
+
issues.push({
|
|
315
|
+
code: "SECRET_EXPOSED",
|
|
316
|
+
severity: "error",
|
|
317
|
+
path: childPath,
|
|
318
|
+
message: `Sensitive environment variable "${sanitizeLine(key)}" contains an unredacted value.`,
|
|
319
|
+
suggestion: `Remove "${sanitizeLine(key)}" from input.env or replace its value with "[REDACTED]" or a "{{...}}" placeholder.`
|
|
320
|
+
});
|
|
321
|
+
if (typeof entry === "string") {
|
|
322
|
+
scanStringForSecrets(entry, childPath, issues, { skipRawBearerAndCookie: true });
|
|
323
|
+
}
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (context.inVars &&
|
|
329
|
+
(isSensitiveKeyName(key) ||
|
|
330
|
+
SENSITIVE_ENV_KEY_RE.test(key) ||
|
|
331
|
+
isSensitiveHeaderName(key) ||
|
|
332
|
+
isSensitiveQueryParamName(key))) {
|
|
333
|
+
if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") {
|
|
334
|
+
const strVal = String(entry);
|
|
335
|
+
if (strVal.trim().length > 0 && !isSafePlaceholder(strVal)) {
|
|
336
|
+
issues.push({
|
|
337
|
+
code: "SECRET_EXPOSED",
|
|
338
|
+
severity: "error",
|
|
339
|
+
path: childPath,
|
|
340
|
+
message: `Sensitive workflow variable "${sanitizeLine(key)}" contains an unredacted value.`,
|
|
341
|
+
suggestion: `Remove "${sanitizeLine(key)}" from input.vars or replace its value with "[REDACTED]" or a "{{...}}" placeholder.`
|
|
342
|
+
});
|
|
343
|
+
if (typeof entry === "string") {
|
|
344
|
+
scanStringForSecrets(entry, childPath, issues, { skipRawBearerAndCookie: true });
|
|
345
|
+
}
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const lowerKey = key.toLowerCase();
|
|
351
|
+
scanValueForSecrets(entry, childPath, issues, seen, depth + 1, {
|
|
352
|
+
inHeaders: lowerKey === "headers",
|
|
353
|
+
inQuery: lowerKey === "query",
|
|
354
|
+
inArgs: lowerKey === "args",
|
|
355
|
+
inEnv: lowerKey === "env",
|
|
356
|
+
inVars: lowerKey === "vars"
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
seen.delete(value);
|
|
360
|
+
}
|
|
361
|
+
function hasHttpExpectation(expected) {
|
|
362
|
+
return (typeof expected.status === "number" ||
|
|
363
|
+
isNonEmptyArray(expected.status) ||
|
|
364
|
+
isNonEmptyObject(expected.jsonSchema) ||
|
|
365
|
+
expected.jsonSubset !== undefined ||
|
|
366
|
+
isNonEmptyArray(expected.jsonPaths) ||
|
|
367
|
+
isNonEmptyString(expected.bodyContains) ||
|
|
368
|
+
isNonEmptyArray(expected.bodyContains) ||
|
|
369
|
+
typeof expected.bodyExact === "string" ||
|
|
370
|
+
isNonEmptyObject(expected.headers) ||
|
|
371
|
+
typeof expected.maxLatencyMs === "number");
|
|
372
|
+
}
|
|
373
|
+
function hasStreamEventExpectation(rule) {
|
|
374
|
+
if (!isObject(rule))
|
|
375
|
+
return false;
|
|
376
|
+
return (isNonEmptyString(rule.event) ||
|
|
377
|
+
typeof rule.dataExact === "string" ||
|
|
378
|
+
isNonEmptyString(rule.dataContains) ||
|
|
379
|
+
isNonEmptyObject(rule.jsonSchema) ||
|
|
380
|
+
rule.jsonSubset !== undefined ||
|
|
381
|
+
isNonEmptyArray(rule.jsonPaths));
|
|
382
|
+
}
|
|
383
|
+
function hasMeaningfulAssertion(type, expected, input) {
|
|
384
|
+
switch (type) {
|
|
385
|
+
case "command":
|
|
386
|
+
return (typeof expected.exitCode === "number" ||
|
|
387
|
+
isNonEmptyArray(expected.exitCode) ||
|
|
388
|
+
typeof expected.stdoutExact === "string" ||
|
|
389
|
+
isNonEmptyArray(expected.stdoutContains) ||
|
|
390
|
+
isNonEmptyArray(expected.stdoutNotContains) ||
|
|
391
|
+
isNonEmptyArray(expected.stdoutRegex) ||
|
|
392
|
+
isNonEmptyString(expected.goldenStdout) ||
|
|
393
|
+
typeof expected.stderrExact === "string" ||
|
|
394
|
+
isNonEmptyArray(expected.stderrContains) ||
|
|
395
|
+
isNonEmptyObject(expected.jsonSchema) ||
|
|
396
|
+
expected.jsonSubset !== undefined ||
|
|
397
|
+
isNonEmptyArray(expected.jsonPaths) ||
|
|
398
|
+
Array.isArray(expected.fsEffects));
|
|
399
|
+
case "http":
|
|
400
|
+
return hasHttpExpectation(expected);
|
|
401
|
+
case "http_workflow": {
|
|
402
|
+
if (!isNonEmptyArray(input.steps))
|
|
403
|
+
return false;
|
|
404
|
+
const allSteps = [
|
|
405
|
+
...input.steps,
|
|
406
|
+
...(Array.isArray(input.finallySteps) ? input.finallySteps : [])
|
|
407
|
+
];
|
|
408
|
+
return allSteps.some((step) => isObject(step) && isObject(step.expected) && hasHttpExpectation(step.expected));
|
|
409
|
+
}
|
|
410
|
+
case "http_stream":
|
|
411
|
+
return (typeof expected.status === "number" ||
|
|
412
|
+
isNonEmptyArray(expected.status) ||
|
|
413
|
+
isNonEmptyObject(expected.headers) ||
|
|
414
|
+
(typeof expected.minEvents === "number" && Number.isFinite(expected.minEvents) && expected.minEvents > 0) ||
|
|
415
|
+
(typeof expected.maxEvents === "number" && Number.isFinite(expected.maxEvents) && expected.maxEvents >= 0) ||
|
|
416
|
+
(typeof expected.maxDurationMs === "number" && Number.isFinite(expected.maxDurationMs) && expected.maxDurationMs > 0) ||
|
|
417
|
+
expected.forbidMalformedEvents === true ||
|
|
418
|
+
hasStreamEventExpectation(expected.terminalEvent) ||
|
|
419
|
+
(Array.isArray(expected.orderedEvents) && expected.orderedEvents.some((ev) => hasStreamEventExpectation(ev))));
|
|
420
|
+
case "ws_protocol": {
|
|
421
|
+
const hasExpectStep = Array.isArray(input.steps) &&
|
|
422
|
+
input.steps.some((step) => isObject(step) && step.action === "expect");
|
|
423
|
+
return (hasExpectStep ||
|
|
424
|
+
(typeof expected.closeCode === "number" && Number.isFinite(expected.closeCode)) ||
|
|
425
|
+
(typeof expected.maxDurationMs === "number" && Number.isFinite(expected.maxDurationMs) && expected.maxDurationMs > 0));
|
|
426
|
+
}
|
|
427
|
+
case "perf_budget":
|
|
428
|
+
return ((typeof expected.maxP50Ms === "number" && Number.isFinite(expected.maxP50Ms) && expected.maxP50Ms >= 0) ||
|
|
429
|
+
(typeof expected.maxP95Ms === "number" && Number.isFinite(expected.maxP95Ms) && expected.maxP95Ms >= 0) ||
|
|
430
|
+
(typeof expected.maxP99Ms === "number" && Number.isFinite(expected.maxP99Ms) && expected.maxP99Ms >= 0) ||
|
|
431
|
+
(typeof expected.maxMeanMs === "number" && Number.isFinite(expected.maxMeanMs) && expected.maxMeanMs >= 0) ||
|
|
432
|
+
(typeof expected.maxDurationMs === "number" && Number.isFinite(expected.maxDurationMs) && expected.maxDurationMs >= 0) ||
|
|
433
|
+
(typeof expected.maxBytes === "number" && Number.isFinite(expected.maxBytes) && expected.maxBytes >= 0) ||
|
|
434
|
+
(typeof expected.minBytes === "number" && Number.isFinite(expected.minBytes) && expected.minBytes >= 0) ||
|
|
435
|
+
typeof expected.status === "number" ||
|
|
436
|
+
isNonEmptyArray(expected.status) ||
|
|
437
|
+
typeof expected.exitCode === "number" ||
|
|
438
|
+
isNonEmptyArray(expected.exitCode));
|
|
439
|
+
case "web_route":
|
|
440
|
+
return (typeof expected.status === "number" ||
|
|
441
|
+
isNonEmptyArray(expected.status) ||
|
|
442
|
+
isNonEmptyString(expected.titleContains) ||
|
|
443
|
+
isNonEmptyArray(expected.landmarks) ||
|
|
444
|
+
isNonEmptyArray(expected.interactiveLandmarks) ||
|
|
445
|
+
isNonEmptyString(expected.textContains) ||
|
|
446
|
+
isNonEmptyArray(expected.textContains) ||
|
|
447
|
+
isNonEmptyArray(expected.visibleText) ||
|
|
448
|
+
isNonEmptyArray(expected.hiddenText) ||
|
|
449
|
+
isNonEmptyArray(expected.domAssertions) ||
|
|
450
|
+
isNonEmptyArray(expected.boundingBoxes) ||
|
|
451
|
+
isNonEmptyString(expected.finalUrlIncludes) ||
|
|
452
|
+
typeof expected.maxConsoleErrors === "number" ||
|
|
453
|
+
typeof expected.maxPageErrors === "number" ||
|
|
454
|
+
expected.noConsoleErrors === true ||
|
|
455
|
+
expected.noPageErrors === true ||
|
|
456
|
+
expected.noServerErrors === true ||
|
|
457
|
+
expected.noUncaughtExceptions === true);
|
|
458
|
+
case "web_flow":
|
|
459
|
+
return (isNonEmptyString(expected.finalUrlIncludes) ||
|
|
460
|
+
isNonEmptyString(expected.titleContains) ||
|
|
461
|
+
isNonEmptyString(expected.textContains) ||
|
|
462
|
+
isNonEmptyArray(expected.textContains) ||
|
|
463
|
+
isNonEmptyArray(expected.visibleText) ||
|
|
464
|
+
isNonEmptyArray(expected.hiddenText) ||
|
|
465
|
+
isNonEmptyArray(expected.domAssertions) ||
|
|
466
|
+
isNonEmptyArray(expected.landmarks) ||
|
|
467
|
+
isNonEmptyArray(expected.interactiveLandmarks) ||
|
|
468
|
+
isNonEmptyArray(expected.networkCalls) ||
|
|
469
|
+
isNonEmptyArray(expected.assertions) ||
|
|
470
|
+
typeof expected.maxConsoleErrors === "number" ||
|
|
471
|
+
typeof expected.maxPageErrors === "number" ||
|
|
472
|
+
expected.noConsoleErrors === true ||
|
|
473
|
+
expected.noPageErrors === true ||
|
|
474
|
+
expected.noUncaughtExceptions === true);
|
|
475
|
+
case "web_network":
|
|
476
|
+
return (isNonEmptyArray(expected.networkCalls) ||
|
|
477
|
+
typeof expected.status === "number" ||
|
|
478
|
+
isNonEmptyArray(expected.status) ||
|
|
479
|
+
isNonEmptyObject(expected.jsonSchema) ||
|
|
480
|
+
expected.jsonSubset !== undefined ||
|
|
481
|
+
isNonEmptyArray(expected.jsonPaths) ||
|
|
482
|
+
expected.noServerErrors === true);
|
|
483
|
+
case "repo_exports":
|
|
484
|
+
return (isNonEmptyArray(expected.exports) ||
|
|
485
|
+
typeof expected.exportCount === "number" ||
|
|
486
|
+
isNonEmptyArray(expected.filesPresent) ||
|
|
487
|
+
isNonEmptyArray(expected.assertions));
|
|
488
|
+
case "image_layout":
|
|
489
|
+
return (isNonEmptyObject(expected.dimensions) ||
|
|
490
|
+
expected.nonBlank === true ||
|
|
491
|
+
isNonEmptyArray(expected.palette) ||
|
|
492
|
+
isNonEmptyArray(expected.regions) ||
|
|
493
|
+
isNonEmptyArray(expected.typographyHierarchy));
|
|
494
|
+
case "image_perceptual":
|
|
495
|
+
return (isNonEmptyString(expected.referenceHash) ||
|
|
496
|
+
isNonEmptyString(input.referenceArtifact) ||
|
|
497
|
+
isNonEmptyObject(expected.dimensions) ||
|
|
498
|
+
expected.nonBlank === true ||
|
|
499
|
+
isNonEmptyArray(expected.palette) ||
|
|
500
|
+
isNonEmptyArray(expected.regions));
|
|
501
|
+
case "video_timeline":
|
|
502
|
+
return (isNonEmptyArray(expected.states) ||
|
|
503
|
+
isNonEmptyArray(expected.transitions) ||
|
|
504
|
+
typeof expected.durationMs === "number");
|
|
505
|
+
case "plugin_svg_a11y":
|
|
506
|
+
case "plugin_state_file":
|
|
507
|
+
return isNonEmptyObject(expected) || isNonEmptyObject(input);
|
|
508
|
+
default:
|
|
509
|
+
if (type.startsWith("plugin_")) {
|
|
510
|
+
return isNonEmptyObject(expected) || isNonEmptyObject(input);
|
|
511
|
+
}
|
|
512
|
+
return Object.keys(expected).length > 0;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const SENSITIVE_UI_FIELD_RE = /password|passwd|secret|token|otp|one-time|pin\b|cvv|cvc|card|ssn|api[_-]?key|credential/i;
|
|
516
|
+
const SENSITIVE_STORAGE_KEY_RE = /token|auth|secret|session|password|passwd|cookie|jwt|key|credential|bearer|private/i;
|
|
517
|
+
/** Audit web_ui_states checks: empty checks, and literal secrets in trigger.value / storage expectations. */
|
|
518
|
+
function auditUiStatesChecks(input, inputPath, invId, issues) {
|
|
519
|
+
const checks = input.checks;
|
|
520
|
+
// Empty/missing checks are already reported as SCHEMA_INVALID ("web_ui_states requires a non-empty checks array").
|
|
521
|
+
if (!isNonEmptyArray(checks))
|
|
522
|
+
return;
|
|
523
|
+
const alreadyFlagged = (path) => issues.some((i) => i.code === "SECRET_EXPOSED" && i.path === path);
|
|
524
|
+
const flagLiteral = (value, path, sensitiveContext, what) => {
|
|
525
|
+
if (typeof value !== "string" || value.trim().length === 0 || isSafePlaceholder(value))
|
|
526
|
+
return;
|
|
527
|
+
if (!sensitiveContext && redactSensitiveText(value) === value)
|
|
528
|
+
return;
|
|
529
|
+
if (alreadyFlagged(path))
|
|
530
|
+
return;
|
|
531
|
+
issues.push({
|
|
532
|
+
code: "SECRET_EXPOSED",
|
|
533
|
+
severity: "error",
|
|
534
|
+
path,
|
|
535
|
+
message: `web_ui_states ${what} in "${sanitizeLine(invId)}" contains a literal secret value.`,
|
|
536
|
+
suggestion: 'Replace the literal with a "{{vars.NAME}}" placeholder and supply it at runtime via --var NAME=... or VIBECODE_VAR_NAME.'
|
|
537
|
+
});
|
|
538
|
+
};
|
|
539
|
+
checks.forEach((check, i) => {
|
|
540
|
+
if (!isObject(check))
|
|
541
|
+
return;
|
|
542
|
+
const cp = `${inputPath}.checks[${i}]`;
|
|
543
|
+
if (isObject(check.trigger)) {
|
|
544
|
+
const sel = typeof check.trigger.selector === "string" ? check.trigger.selector : "";
|
|
545
|
+
flagLiteral(check.trigger.value, `${cp}.trigger.value`, SENSITIVE_UI_FIELD_RE.test(sel), "trigger.value");
|
|
546
|
+
}
|
|
547
|
+
const sensitiveKey = check.kind === "storage" && typeof check.key === "string" && SENSITIVE_STORAGE_KEY_RE.test(check.key);
|
|
548
|
+
flagLiteral(check.expectEquals, `${cp}.expectEquals`, sensitiveKey, "expectEquals");
|
|
549
|
+
flagLiteral(check.expectContains, `${cp}.expectContains`, sensitiveKey, "expectContains");
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
/** Audit perf_budget headers/env/query for embedded secret tokens even under non-standard key names. */
|
|
553
|
+
function auditPerfBudgetSecrets(input, inputPath, invId, issues) {
|
|
554
|
+
const alreadyFlagged = (p) => issues.some((i) => i.code === "SECRET_EXPOSED" && i.path === p);
|
|
555
|
+
for (const section of ["headers", "env", "query"]) {
|
|
556
|
+
const rec = input[section];
|
|
557
|
+
if (!isObject(rec))
|
|
558
|
+
continue;
|
|
559
|
+
const sectionPath = `${inputPath}.${section}`;
|
|
560
|
+
for (const [key, entry] of Object.entries(rec)) {
|
|
561
|
+
if (typeof entry !== "string" && typeof entry !== "number" && typeof entry !== "boolean")
|
|
562
|
+
continue;
|
|
563
|
+
const strVal = String(entry);
|
|
564
|
+
if (strVal.trim().length === 0 || isSafePlaceholder(strVal))
|
|
565
|
+
continue;
|
|
566
|
+
const childPath = formatPropPath(sectionPath, key);
|
|
567
|
+
if (alreadyFlagged(childPath))
|
|
568
|
+
continue;
|
|
569
|
+
if (redactSensitiveText(strVal) !== strVal) {
|
|
570
|
+
issues.push({
|
|
571
|
+
code: "SECRET_EXPOSED",
|
|
572
|
+
severity: "error",
|
|
573
|
+
path: childPath,
|
|
574
|
+
message: `perf_budget input.${section} entry "${sanitizeLine(key)}" in "${sanitizeLine(invId)}" contains a literal secret value.`,
|
|
575
|
+
suggestion: 'Replace the literal with a "{{vars.NAME}}" placeholder and supply it at runtime via --var NAME=... or VIBECODE_VAR_NAME.'
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
function auditFixtureStringSecret(value, path, label, issues, alreadyFlagged) {
|
|
582
|
+
if (typeof value !== "string" || value.trim().length === 0 || isSafePlaceholder(value))
|
|
583
|
+
return;
|
|
584
|
+
if (alreadyFlagged(path))
|
|
585
|
+
return;
|
|
586
|
+
if (redactSensitiveText(value) !== value) {
|
|
587
|
+
issues.push({
|
|
588
|
+
code: "SECRET_EXPOSED",
|
|
589
|
+
severity: "error",
|
|
590
|
+
path,
|
|
591
|
+
message: `${label} contains an unredacted secret value.`,
|
|
592
|
+
suggestion: 'Replace literal secrets with "{{vars.NAME}}" placeholders and supply them at runtime via --var NAME=... or VIBECODE_VAR_NAME.'
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function walkFixtureBodySecrets(value, path, issues, alreadyFlagged, seen, depth = 0) {
|
|
597
|
+
if (depth > MAX_WALK_DEPTH || value === null || value === undefined)
|
|
598
|
+
return;
|
|
599
|
+
if (typeof value === "string") {
|
|
600
|
+
auditFixtureStringSecret(value, path, "Fixture HTTP body field", issues, alreadyFlagged);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (typeof value !== "object")
|
|
604
|
+
return;
|
|
605
|
+
if (seen.has(value))
|
|
606
|
+
return;
|
|
607
|
+
seen.add(value);
|
|
608
|
+
try {
|
|
609
|
+
if (Array.isArray(value)) {
|
|
610
|
+
for (let i = 0; i < value.length; i++) {
|
|
611
|
+
walkFixtureBodySecrets(value[i], `${path}[${i}]`, issues, alreadyFlagged, seen, depth + 1);
|
|
612
|
+
}
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
for (const [k, v] of Object.entries(value)) {
|
|
616
|
+
walkFixtureBodySecrets(v, formatPropPath(path, k), issues, alreadyFlagged, seen, depth + 1);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
finally {
|
|
620
|
+
seen.delete(value);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function auditFixtures(rawFixtures, issues, secretSeen) {
|
|
624
|
+
const validation = validateContractFixtures(rawFixtures);
|
|
625
|
+
if (!validation.valid) {
|
|
626
|
+
for (const rawErr of validation.errors) {
|
|
627
|
+
const match = rawErr.match(/^(fixtures(?:\.[A-Za-z0-9_]+|\[\d+\]|\[[^\]]+\])*):\s*(.*)$/);
|
|
628
|
+
const errPath = match ? `$.${match[1]}` : "$.fixtures";
|
|
629
|
+
const errMsg = match && match[2] ? match[2] : rawErr;
|
|
630
|
+
issues.push({
|
|
631
|
+
code: "FIXTURE_INVALID",
|
|
632
|
+
severity: "error",
|
|
633
|
+
path: errPath,
|
|
634
|
+
message: sanitizeLine(errMsg),
|
|
635
|
+
suggestion: "Fix contract.fixtures so all paths stay inside the workspace, HTTP hooks use relative origin paths, and hook limits are satisfied."
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (!isObject(rawFixtures))
|
|
640
|
+
return;
|
|
641
|
+
// Generic secret & vault path sweep (headers, query, args, env, Bearer, Cookie, vault paths)
|
|
642
|
+
try {
|
|
643
|
+
scanValueForSecrets(rawFixtures, "$.fixtures", issues, secretSeen);
|
|
644
|
+
}
|
|
645
|
+
catch {
|
|
646
|
+
// Ignore hostile accessor traps already reported by validateContractFixtures.
|
|
647
|
+
}
|
|
648
|
+
const alreadyFlagged = (p) => issues.some((i) => i.code === "SECRET_EXPOSED" && i.path === p);
|
|
649
|
+
const bodySeen = new WeakSet();
|
|
650
|
+
try {
|
|
651
|
+
for (const section of ["httpSetup", "httpTeardown"]) {
|
|
652
|
+
const hooks = rawFixtures[section];
|
|
653
|
+
if (!Array.isArray(hooks))
|
|
654
|
+
continue;
|
|
655
|
+
hooks.forEach((hook, i) => {
|
|
656
|
+
if (!isObject(hook))
|
|
657
|
+
return;
|
|
658
|
+
const hp = `$.fixtures.${section}[${i}]`;
|
|
659
|
+
auditFixtureStringSecret(hook.path, `${hp}.path`, `fixtures.${section} path`, issues, alreadyFlagged);
|
|
660
|
+
if (isObject(hook.headers)) {
|
|
661
|
+
for (const [k, v] of Object.entries(hook.headers)) {
|
|
662
|
+
if (typeof v !== "string" && typeof v !== "number" && typeof v !== "boolean")
|
|
663
|
+
continue;
|
|
664
|
+
const strVal = String(v);
|
|
665
|
+
if (strVal.trim().length === 0 || isSafePlaceholder(strVal))
|
|
666
|
+
continue;
|
|
667
|
+
const childPath = formatPropPath(`${hp}.headers`, k);
|
|
668
|
+
if (alreadyFlagged(childPath))
|
|
669
|
+
continue;
|
|
670
|
+
if (isSensitiveHeaderName(k) || redactSensitiveText(strVal) !== strVal) {
|
|
671
|
+
issues.push({
|
|
672
|
+
code: "SECRET_EXPOSED",
|
|
673
|
+
severity: "error",
|
|
674
|
+
path: childPath,
|
|
675
|
+
message: `Sensitive fixture HTTP header "${sanitizeLine(k)}" contains an unredacted value.`,
|
|
676
|
+
suggestion: 'Replace literal header secrets with "{{vars.NAME}}" and pass values at runtime via --var NAME=... or VIBECODE_VAR_NAME.'
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (hook.body !== undefined) {
|
|
682
|
+
walkFixtureBodySecrets(hook.body, `${hp}.body`, issues, alreadyFlagged, bodySeen);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
if (Array.isArray(rawFixtures.seedFiles)) {
|
|
687
|
+
rawFixtures.seedFiles.forEach((seed, i) => {
|
|
688
|
+
if (!isObject(seed) || typeof seed.content !== "string")
|
|
689
|
+
return;
|
|
690
|
+
const cp = `$.fixtures.seedFiles[${i}].content`;
|
|
691
|
+
auditFixtureStringSecret(seed.content, cp, "fixtures.seedFiles content", issues, alreadyFlagged);
|
|
692
|
+
if (seed.encoding === "base64" && !alreadyFlagged(cp)) {
|
|
693
|
+
const compact = seed.content.replace(/\s+/g, "");
|
|
694
|
+
if (compact.length > 0 && compact.length <= 350_000) {
|
|
695
|
+
try {
|
|
696
|
+
const decoded = Buffer.from(compact, "base64").toString("utf8");
|
|
697
|
+
scanStringForSecrets(decoded, cp, issues);
|
|
698
|
+
auditFixtureStringSecret(decoded, cp, "fixtures.seedFiles base64 content", issues, alreadyFlagged);
|
|
699
|
+
}
|
|
700
|
+
catch {
|
|
701
|
+
// Invalid base64 is already reported by FIXTURE_INVALID.
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
for (const section of ["commandSetup", "commandTeardown"]) {
|
|
708
|
+
const hooks = rawFixtures[section];
|
|
709
|
+
if (!Array.isArray(hooks))
|
|
710
|
+
continue;
|
|
711
|
+
hooks.forEach((hook, i) => {
|
|
712
|
+
if (!isObject(hook))
|
|
713
|
+
return;
|
|
714
|
+
const hp = `$.fixtures.${section}[${i}]`;
|
|
715
|
+
if (Array.isArray(hook.args)) {
|
|
716
|
+
hook.args.forEach((arg, j) => {
|
|
717
|
+
auditFixtureStringSecret(arg, `${hp}.args[${j}]`, `fixtures.${section} arg`, issues, alreadyFlagged);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
if (isObject(hook.env)) {
|
|
721
|
+
for (const [k, v] of Object.entries(hook.env)) {
|
|
722
|
+
if (typeof v !== "string" && typeof v !== "number" && typeof v !== "boolean")
|
|
723
|
+
continue;
|
|
724
|
+
const strVal = String(v);
|
|
725
|
+
if (strVal.trim().length === 0 || isSafePlaceholder(strVal))
|
|
726
|
+
continue;
|
|
727
|
+
const childPath = formatPropPath(`${hp}.env`, k);
|
|
728
|
+
if (alreadyFlagged(childPath))
|
|
729
|
+
continue;
|
|
730
|
+
if (isSensitiveHeaderName(k) || isSensitiveKeyName(k) || redactSensitiveText(strVal) !== strVal) {
|
|
731
|
+
issues.push({
|
|
732
|
+
code: "SECRET_EXPOSED",
|
|
733
|
+
severity: "error",
|
|
734
|
+
path: childPath,
|
|
735
|
+
message: `Sensitive fixture command env "${sanitizeLine(k)}" contains an unredacted value.`,
|
|
736
|
+
suggestion: 'Replace literal env secrets with "{{vars.NAME}}" and pass values at runtime via --var NAME=... or VIBECODE_VAR_NAME.'
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
if (isNonEmptyArray(rawFixtures.httpSetup) && !isNonEmptyArray(rawFixtures.httpTeardown)) {
|
|
744
|
+
issues.push({
|
|
745
|
+
code: "FIXTURE_NO_TEARDOWN",
|
|
746
|
+
severity: "warn",
|
|
747
|
+
path: "$.fixtures.httpSetup",
|
|
748
|
+
message: "fixtures.httpSetup is defined without fixtures.httpTeardown.",
|
|
749
|
+
suggestion: "Add fixtures.httpTeardown hooks so external HTTP state is cleaned up after verification."
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
if (isNonEmptyArray(rawFixtures.commandSetup) && !isNonEmptyArray(rawFixtures.commandTeardown)) {
|
|
753
|
+
issues.push({
|
|
754
|
+
code: "FIXTURE_NO_TEARDOWN",
|
|
755
|
+
severity: "warn",
|
|
756
|
+
path: "$.fixtures.commandSetup",
|
|
757
|
+
message: "fixtures.commandSetup is defined without fixtures.commandTeardown.",
|
|
758
|
+
suggestion: "Add fixtures.commandTeardown hooks so setup side effects are rolled back after verification."
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
catch {
|
|
763
|
+
// Ignore hostile accessor traps already reported by validateContractFixtures.
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
function isHandledByDedicatedRule(path, message) {
|
|
767
|
+
if (path === "$.fixtures" || path.startsWith("$.fixtures.")) {
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
if (/^\$\.invariants\[\d+\]\.id$/.test(path) && message.startsWith("Duplicate invariant id:")) {
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
if (/^\$\.slices\[\d+\]\.invariantIds\[\d+\]$/.test(path) && message.startsWith("Unknown invariant id:")) {
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
if (/^\$\.slices\[\d+\]\.dependsOn$/.test(path) && message.startsWith("Dependency cycle detected:")) {
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
/** Audit a raw or normalized contract object for schema, security, and quality issues. */
|
|
782
|
+
export function lintContract(contract, options = {}) {
|
|
783
|
+
const strict = options.strict === true;
|
|
784
|
+
const issues = [];
|
|
785
|
+
// a. Schema validation (gracefully handles non-object / malformed inputs without throwing)
|
|
786
|
+
const validation = validateContract(contract);
|
|
787
|
+
if (!validation.ok) {
|
|
788
|
+
for (const err of validation.errors) {
|
|
789
|
+
if (isHandledByDedicatedRule(err.path, err.message))
|
|
790
|
+
continue;
|
|
791
|
+
issues.push({
|
|
792
|
+
code: "SCHEMA_INVALID",
|
|
793
|
+
severity: "error",
|
|
794
|
+
path: err.path,
|
|
795
|
+
message: sanitizeLine(err.message),
|
|
796
|
+
suggestion: "Fix the contract structure to match the vibecode-anything v0.2 schema."
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (!isObject(contract)) {
|
|
801
|
+
const errors = issues.filter((i) => i.severity === "error").length;
|
|
802
|
+
const warnings = issues.filter((i) => i.severity === "warn").length;
|
|
803
|
+
const exitCode = errors > 0 || (strict && warnings > 0) ? 1 : 0;
|
|
804
|
+
return {
|
|
805
|
+
ok: exitCode === 0,
|
|
806
|
+
strict,
|
|
807
|
+
exitCode,
|
|
808
|
+
summary: { invariants: 0, hard: 0, soft: 0, errors, warnings },
|
|
809
|
+
issues
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
const secretSeen = new WeakSet();
|
|
813
|
+
// b. Secret & vault path scanning across target.sources and artifacts
|
|
814
|
+
if (isObject(contract.target) && contract.target.sources !== undefined) {
|
|
815
|
+
scanValueForSecrets(contract.target.sources, "$.target.sources", issues, secretSeen);
|
|
816
|
+
}
|
|
817
|
+
if (contract.artifacts !== undefined) {
|
|
818
|
+
scanValueForSecrets(contract.artifacts, "$.artifacts", issues, secretSeen);
|
|
819
|
+
}
|
|
820
|
+
if (contract.fixtures !== undefined) {
|
|
821
|
+
auditFixtures(contract.fixtures, issues, secretSeen);
|
|
822
|
+
}
|
|
823
|
+
const rawInvariants = Array.isArray(contract.invariants) ? contract.invariants : null;
|
|
824
|
+
let invariantCount = 0;
|
|
825
|
+
let hardCount = 0;
|
|
826
|
+
let softCount = 0;
|
|
827
|
+
const knownInvariantIds = new Set();
|
|
828
|
+
const seenIds = new Map();
|
|
829
|
+
const seenProbes = new Map();
|
|
830
|
+
if (rawInvariants) {
|
|
831
|
+
invariantCount = rawInvariants.length;
|
|
832
|
+
for (let i = 0; i < rawInvariants.length; i++) {
|
|
833
|
+
const inv = rawInvariants[i];
|
|
834
|
+
const basePath = `$.invariants[${i}]`;
|
|
835
|
+
if (!isObject(inv))
|
|
836
|
+
continue;
|
|
837
|
+
const invId = typeof inv.id === "string" && inv.id.length > 0 ? inv.id : `#${i}`;
|
|
838
|
+
if (inv.severity === "hard")
|
|
839
|
+
hardCount++;
|
|
840
|
+
else if (inv.severity === "soft")
|
|
841
|
+
softCount++;
|
|
842
|
+
// d. DUPLICATE_ID
|
|
843
|
+
if (typeof inv.id === "string" && inv.id.length > 0) {
|
|
844
|
+
knownInvariantIds.add(inv.id);
|
|
845
|
+
const firstIdx = seenIds.get(inv.id);
|
|
846
|
+
if (firstIdx !== undefined) {
|
|
847
|
+
issues.push({
|
|
848
|
+
code: "DUPLICATE_ID",
|
|
849
|
+
severity: "error",
|
|
850
|
+
path: `${basePath}.id`,
|
|
851
|
+
message: `Duplicate invariant id "${sanitizeLine(inv.id)}" (already defined at $.invariants[${firstIdx}]).`,
|
|
852
|
+
suggestion: "Assign a unique id to every invariant."
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
seenIds.set(inv.id, i);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// c. INLINE_HOLDOUT
|
|
860
|
+
if (inv.holdout === true) {
|
|
861
|
+
issues.push({
|
|
862
|
+
code: "INLINE_HOLDOUT",
|
|
863
|
+
severity: "warn",
|
|
864
|
+
path: `${basePath}.holdout`,
|
|
865
|
+
message: `Invariant "${sanitizeLine(invId)}" has holdout: true inline inside contract.json instead of the isolated holdout vault.`,
|
|
866
|
+
suggestion: "Move holdout invariants out of .vibecode/contract.json into the isolated ~/.vibecode-vault/ store."
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
// b. Secret scanning across invariant input, expected, description (and holdoutHint)
|
|
870
|
+
if (inv.description !== undefined) {
|
|
871
|
+
scanValueForSecrets(inv.description, `${basePath}.description`, issues, secretSeen);
|
|
872
|
+
}
|
|
873
|
+
if (inv.holdoutHint !== undefined) {
|
|
874
|
+
scanValueForSecrets(inv.holdoutHint, `${basePath}.holdoutHint`, issues, secretSeen);
|
|
875
|
+
}
|
|
876
|
+
if (inv.input !== undefined) {
|
|
877
|
+
scanValueForSecrets(inv.input, `${basePath}.input`, issues, secretSeen);
|
|
878
|
+
}
|
|
879
|
+
if (inv.expected !== undefined) {
|
|
880
|
+
scanValueForSecrets(inv.expected, `${basePath}.expected`, issues, secretSeen);
|
|
881
|
+
}
|
|
882
|
+
if (inv.tolerance !== undefined) {
|
|
883
|
+
scanValueForSecrets(inv.tolerance, `${basePath}.tolerance`, issues, secretSeen);
|
|
884
|
+
}
|
|
885
|
+
if (inv.type === "web_ui_states" && isObject(inv.input)) {
|
|
886
|
+
auditUiStatesChecks(inv.input, `${basePath}.input`, invId, issues);
|
|
887
|
+
}
|
|
888
|
+
if (inv.type === "perf_budget" && isObject(inv.input)) {
|
|
889
|
+
auditPerfBudgetSecrets(inv.input, `${basePath}.input`, invId, issues);
|
|
890
|
+
}
|
|
891
|
+
// e. DUPLICATE_PROBE
|
|
892
|
+
if (typeof inv.domain === "string" && typeof inv.type === "string" && isObject(inv.input)) {
|
|
893
|
+
const probeKey = `${inv.domain}\0${inv.type}\0${canonicalJson(inv.input)}`;
|
|
894
|
+
const prior = seenProbes.get(probeKey);
|
|
895
|
+
if (prior) {
|
|
896
|
+
issues.push({
|
|
897
|
+
code: "DUPLICATE_PROBE",
|
|
898
|
+
severity: "warn",
|
|
899
|
+
path: `${basePath}.input`,
|
|
900
|
+
message: `Invariant "${sanitizeLine(invId)}" duplicates the ${inv.domain}/${inv.type} probe of "${sanitizeLine(prior.id)}" ($.invariants[${prior.index}]).`,
|
|
901
|
+
suggestion: "Merge assertions into a single invariant or differentiate the input probe."
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
seenProbes.set(probeKey, { index: i, id: invId });
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
// f. WEAK_INVARIANT
|
|
909
|
+
// web_ui_states assertions live in input.checks and are audited by auditUiStatesChecks.
|
|
910
|
+
if (typeof inv.type === "string" && inv.type !== "web_ui_states" && isObject(inv.expected)) {
|
|
911
|
+
const inputObj = isObject(inv.input) ? inv.input : {};
|
|
912
|
+
if (!hasMeaningfulAssertion(inv.type, inv.expected, inputObj)) {
|
|
913
|
+
issues.push({
|
|
914
|
+
code: "WEAK_INVARIANT",
|
|
915
|
+
severity: "warn",
|
|
916
|
+
path: `${basePath}.expected`,
|
|
917
|
+
message: `Invariant "${sanitizeLine(invId)}" (${inv.type}) has no meaningful expected assertions.`,
|
|
918
|
+
suggestion: `Add concrete expected assertions for "${inv.type}" so parity verification actually checks behavior.`
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
// g. NO_HARD_INVARIANTS
|
|
924
|
+
if (hardCount === 0) {
|
|
925
|
+
issues.push({
|
|
926
|
+
code: "NO_HARD_INVARIANTS",
|
|
927
|
+
severity: "warn",
|
|
928
|
+
path: "$.invariants",
|
|
929
|
+
message: invariantCount === 0
|
|
930
|
+
? "Contract contains 0 invariants (0 hard invariants); parity gate cannot verify behavior."
|
|
931
|
+
: `Contract has 0 hard invariants (${softCount} soft only); soft-only contracts never fail default parity gates.`,
|
|
932
|
+
suggestion: 'Add at least one hard invariant (severity: "hard") to enforce behavioral parity.'
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
// b + h. Slices secret scan and slice graph validation
|
|
937
|
+
if (Array.isArray(contract.slices)) {
|
|
938
|
+
scanValueForSecrets(contract.slices, "$.slices", issues, secretSeen);
|
|
939
|
+
if (contract.slices.length > 0) {
|
|
940
|
+
const slices = contract.slices;
|
|
941
|
+
const coveredInvariantIds = new Set();
|
|
942
|
+
const sliceIndexById = new Map();
|
|
943
|
+
const dependencyLists = [];
|
|
944
|
+
for (let i = 0; i < slices.length; i++) {
|
|
945
|
+
const entry = slices[i];
|
|
946
|
+
const deps = [];
|
|
947
|
+
dependencyLists.push(deps);
|
|
948
|
+
if (!isObject(entry))
|
|
949
|
+
continue;
|
|
950
|
+
const sliceId = typeof entry.id === "string" && entry.id.length > 0 ? entry.id : `#${i}`;
|
|
951
|
+
if (typeof entry.id === "string" && entry.id.length > 0 && !sliceIndexById.has(entry.id)) {
|
|
952
|
+
sliceIndexById.set(entry.id, i);
|
|
953
|
+
}
|
|
954
|
+
if (Array.isArray(entry.invariantIds)) {
|
|
955
|
+
for (let j = 0; j < entry.invariantIds.length; j++) {
|
|
956
|
+
const id = entry.invariantIds[j];
|
|
957
|
+
if (typeof id !== "string" || id.length === 0)
|
|
958
|
+
continue;
|
|
959
|
+
if (rawInvariants && !knownInvariantIds.has(id)) {
|
|
960
|
+
issues.push({
|
|
961
|
+
code: "SLICE_UNKNOWN_INVARIANT",
|
|
962
|
+
severity: "error",
|
|
963
|
+
path: `$.slices[${i}].invariantIds[${j}]`,
|
|
964
|
+
message: `Slice "${sanitizeLine(sliceId)}" references unknown invariant id "${sanitizeLine(id)}".`,
|
|
965
|
+
suggestion: `Remove "${sanitizeLine(id)}" from slice.invariantIds or define a matching invariant.`
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
coveredInvariantIds.add(id);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (Array.isArray(entry.dependsOn)) {
|
|
974
|
+
for (const dep of entry.dependsOn) {
|
|
975
|
+
if (typeof dep === "string" && dep.length > 0)
|
|
976
|
+
deps.push(dep);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
// Cycle detection over slice dependsOn graph
|
|
981
|
+
const visiting = new Map();
|
|
982
|
+
const stack = [];
|
|
983
|
+
const reportedCycles = new Set();
|
|
984
|
+
const visit = (id) => {
|
|
985
|
+
visiting.set(id, 1);
|
|
986
|
+
stack.push(id);
|
|
987
|
+
const index = sliceIndexById.get(id);
|
|
988
|
+
const deps = index === undefined ? [] : (dependencyLists[index] ?? []);
|
|
989
|
+
for (const dep of deps) {
|
|
990
|
+
if (!sliceIndexById.has(dep))
|
|
991
|
+
continue;
|
|
992
|
+
const state = visiting.get(dep) ?? 0;
|
|
993
|
+
if (state === 0) {
|
|
994
|
+
visit(dep);
|
|
995
|
+
}
|
|
996
|
+
else if (state === 1) {
|
|
997
|
+
const start = stack.indexOf(dep);
|
|
998
|
+
const cycle = start >= 0 ? [...stack.slice(start), dep] : [dep, dep];
|
|
999
|
+
const key = [...new Set(cycle)].sort().join("|");
|
|
1000
|
+
if (!reportedCycles.has(key)) {
|
|
1001
|
+
reportedCycles.add(key);
|
|
1002
|
+
const at = sliceIndexById.get(id) ?? 0;
|
|
1003
|
+
issues.push({
|
|
1004
|
+
code: "SLICE_CYCLE",
|
|
1005
|
+
severity: "error",
|
|
1006
|
+
path: `$.slices[${at}].dependsOn`,
|
|
1007
|
+
message: `Slice dependency cycle detected: ${cycle.map(sanitizeLine).join(" -> ")}.`,
|
|
1008
|
+
suggestion: "Remove one of the circular dependsOn edges so slices form an acyclic graph."
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
stack.pop();
|
|
1014
|
+
visiting.set(id, 2);
|
|
1015
|
+
};
|
|
1016
|
+
for (const id of sliceIndexById.keys()) {
|
|
1017
|
+
if ((visiting.get(id) ?? 0) === 0)
|
|
1018
|
+
visit(id);
|
|
1019
|
+
}
|
|
1020
|
+
// Orphan visible invariants (not covered by any slice)
|
|
1021
|
+
if (rawInvariants) {
|
|
1022
|
+
const checkedOrphans = new Set();
|
|
1023
|
+
for (let i = 0; i < rawInvariants.length; i++) {
|
|
1024
|
+
const inv = rawInvariants[i];
|
|
1025
|
+
if (!isObject(inv) || typeof inv.id !== "string" || inv.id.length === 0)
|
|
1026
|
+
continue;
|
|
1027
|
+
if (inv.holdout === true)
|
|
1028
|
+
continue;
|
|
1029
|
+
if (checkedOrphans.has(inv.id))
|
|
1030
|
+
continue;
|
|
1031
|
+
checkedOrphans.add(inv.id);
|
|
1032
|
+
if (!coveredInvariantIds.has(inv.id)) {
|
|
1033
|
+
issues.push({
|
|
1034
|
+
code: "SLICE_ORPHAN_INVARIANT",
|
|
1035
|
+
severity: "warn",
|
|
1036
|
+
path: `$.invariants[${i}]`,
|
|
1037
|
+
message: `Visible invariant "${sanitizeLine(inv.id)}" is not covered by any slice.`,
|
|
1038
|
+
suggestion: `Add "${sanitizeLine(inv.id)}" to a slice's invariantIds or create a slice for it.`
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
const errors = issues.filter((issue) => issue.severity === "error").length;
|
|
1046
|
+
const warnings = issues.filter((issue) => issue.severity === "warn").length;
|
|
1047
|
+
const exitCode = errors > 0 || (strict && warnings > 0) ? 1 : 0;
|
|
1048
|
+
const ok = exitCode === 0;
|
|
1049
|
+
return {
|
|
1050
|
+
ok,
|
|
1051
|
+
strict,
|
|
1052
|
+
exitCode,
|
|
1053
|
+
summary: {
|
|
1054
|
+
invariants: invariantCount,
|
|
1055
|
+
hard: hardCount,
|
|
1056
|
+
soft: softCount,
|
|
1057
|
+
errors,
|
|
1058
|
+
warnings
|
|
1059
|
+
},
|
|
1060
|
+
issues
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
/** Render a human-friendly terminal summary for `vibecode-anything lint --pretty`. */
|
|
1064
|
+
export function formatPrettyLint(report, options = {}) {
|
|
1065
|
+
const useColor = options.color === true;
|
|
1066
|
+
const lines = [];
|
|
1067
|
+
const statusBadge = !report.ok || report.summary.errors > 0
|
|
1068
|
+
? { label: "[FAIL]", color: `${ANSI.bold}${ANSI.red}` }
|
|
1069
|
+
: report.summary.warnings > 0
|
|
1070
|
+
? { label: "[WARN]", color: `${ANSI.bold}${ANSI.yellow}` }
|
|
1071
|
+
: { label: "[PASS]", color: `${ANSI.bold}${ANSI.green}` };
|
|
1072
|
+
lines.push(`${styleAnsi("vibecode-anything lint", `${ANSI.bold}${ANSI.cyan}`, useColor)} ${styleAnsi(statusBadge.label, statusBadge.color, useColor)}`);
|
|
1073
|
+
lines.push(`Invariants: ${report.summary.invariants} total (${report.summary.hard} hard, ${report.summary.soft} soft) | Strict: ${report.strict ? "on" : "off"}`);
|
|
1074
|
+
const errPart = styleAnsi(`${report.summary.errors} ${report.summary.errors === 1 ? "error" : "errors"}`, report.summary.errors > 0 ? ANSI.red : ANSI.green, useColor);
|
|
1075
|
+
const warnPart = styleAnsi(`${report.summary.warnings} ${report.summary.warnings === 1 ? "warning" : "warnings"}`, report.summary.warnings > 0 ? ANSI.yellow : ANSI.dim, useColor);
|
|
1076
|
+
lines.push(`Summary: ${errPart}, ${warnPart} (exit ${report.exitCode})`);
|
|
1077
|
+
const errorIssues = report.issues.filter((issue) => issue.severity === "error");
|
|
1078
|
+
const warnIssues = report.issues.filter((issue) => issue.severity === "warn");
|
|
1079
|
+
if (errorIssues.length === 0 && warnIssues.length === 0) {
|
|
1080
|
+
lines.push("");
|
|
1081
|
+
lines.push(styleAnsi("No contract issues detected.", ANSI.green, useColor));
|
|
1082
|
+
return lines.join("\n");
|
|
1083
|
+
}
|
|
1084
|
+
if (errorIssues.length > 0) {
|
|
1085
|
+
lines.push("");
|
|
1086
|
+
lines.push(styleAnsi(`Errors (${errorIssues.length}):`, `${ANSI.bold}${ANSI.red}`, useColor));
|
|
1087
|
+
for (const issue of errorIssues) {
|
|
1088
|
+
const badge = styleAnsi("[ERROR]", `${ANSI.bold}${ANSI.red}`, useColor);
|
|
1089
|
+
const code = styleAnsi(issue.code, ANSI.bold, useColor);
|
|
1090
|
+
const issuePath = styleAnsi(sanitizeLine(issue.path), ANSI.dim, useColor);
|
|
1091
|
+
lines.push(` ${badge} ${code} ${issuePath} - ${sanitizeLine(issue.message)}`);
|
|
1092
|
+
if (issue.suggestion) {
|
|
1093
|
+
lines.push(` ${styleAnsi("suggestion:", ANSI.dim, useColor)} ${sanitizeLine(issue.suggestion)}`);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (warnIssues.length > 0) {
|
|
1098
|
+
lines.push("");
|
|
1099
|
+
lines.push(styleAnsi(`Warnings (${warnIssues.length}):`, `${ANSI.bold}${ANSI.yellow}`, useColor));
|
|
1100
|
+
for (const issue of warnIssues) {
|
|
1101
|
+
const badge = styleAnsi("[WARN]", `${ANSI.bold}${ANSI.yellow}`, useColor);
|
|
1102
|
+
const code = styleAnsi(issue.code, ANSI.bold, useColor);
|
|
1103
|
+
const issuePath = styleAnsi(sanitizeLine(issue.path), ANSI.dim, useColor);
|
|
1104
|
+
lines.push(` ${badge} ${code} ${issuePath} - ${sanitizeLine(issue.message)}`);
|
|
1105
|
+
if (issue.suggestion) {
|
|
1106
|
+
lines.push(` ${styleAnsi("suggestion:", ANSI.dim, useColor)} ${sanitizeLine(issue.suggestion)}`);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return lines.join("\n");
|
|
1111
|
+
}
|