veristack 0.1.0 → 0.1.1
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 +55 -64
- package/dist/cli.mjs +562 -59
- package/package.json +1 -1
- package/skill/SKILL.md +61 -57
- package/skill/agents/openai.yaml +1 -1
- package/skill/references/02-linter-and-antislop-stack.md +2 -1
- package/skill/references/04-source-patterns-digest.md +1 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/cli.ts
|
|
2
|
-
import
|
|
2
|
+
import fs10 from "node:fs";
|
|
3
3
|
|
|
4
4
|
// src/ci-auditor.ts
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
@@ -16,7 +16,7 @@ var RUST_USE = /^\s*use\s+([A-Za-z_][A-Za-z0-9_]*)::/gm;
|
|
|
16
16
|
var RUST_FRAMEWORK_USE = /^(?:std|core|alloc|proptest|rstest|tokio|serde|serde_json|wiremock|mockito|mockall|stateright)$/;
|
|
17
17
|
var PY_IMPORT = /^\s*(?:from\s+([A-Za-z_][A-Za-z0-9_.]*)\s+import|import\s+([A-Za-z_][A-Za-z0-9_.]*))/gm;
|
|
18
18
|
var PY_FRAMEWORK_IMPORT = /^(?:pytest|unittest|hypothesis|mock|respx|httpx|json|os|sys|re|math|time|datetime|pathlib|collections|dataclasses|typing|random|functools|itertools|tempfile|subprocess|asyncio|inspect)$/;
|
|
19
|
-
var CSHARP_PARENT_NS_TEST = /^\s*namespace\s+[A-Za-z_][A-Za-z0-9_.]*\.(?:Tests?|Specs?)\b/m;
|
|
19
|
+
var CSHARP_PARENT_NS_TEST = /^\s*namespace\s+[A-Za-z_][A-Za-z0-9_.]*\.(?:Unit|Integration|Functional|Component)?(?:Tests?|Specs?)\b/m;
|
|
20
20
|
var CSHARP_FRAMEWORK_TYPE = /^(?:Assert|Fact|Theory|Task|DateTime|DateTimeOffset|TimeSpan|Random|Thread|Environment|JsonSerializer|File|Path|Guid|Console|Math|String|Enumerable|List|Dictionary|HashSet|Array|Object|Exception|InvalidOperationException|ArgumentException|StringComparison|CancellationToken|HttpStatusCode|Stopwatch|Mock|Substitute)$/;
|
|
21
21
|
var VITEST_CONFIG_FILE = /^(?:vitest|vite)\.config\.[cm]?[jt]s$/i;
|
|
22
22
|
var PINS_UTC = /\benv\s*:\s*\{[^}]*\bTZ\s*:\s*["']UTC["']/;
|
|
@@ -204,12 +204,22 @@ function hasNonFrameworkImport(raw, language) {
|
|
|
204
204
|
return true;
|
|
205
205
|
}
|
|
206
206
|
if (CSHARP_PARENT_NS_TEST.test(raw)) {
|
|
207
|
-
const masked =
|
|
207
|
+
const masked = maskCode(raw, "csharp");
|
|
208
208
|
for (const match of masked.matchAll(/\bnew\s+([A-Z][A-Za-z0-9_]*)\s*[<(]/g)) {
|
|
209
209
|
const typeName = match[1] ?? "";
|
|
210
210
|
if (!CSHARP_FRAMEWORK_TYPE.test(typeName))
|
|
211
211
|
return true;
|
|
212
212
|
}
|
|
213
|
+
for (const match of masked.matchAll(/\b([A-Z][A-Za-z0-9_]*)\.[A-Z][A-Za-z0-9_]*\s*[<(]/g)) {
|
|
214
|
+
const typeName = match[1] ?? "";
|
|
215
|
+
if (!CSHARP_FRAMEWORK_TYPE.test(typeName))
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
for (const match of masked.matchAll(/\bclass\s+[A-Za-z0-9_]+\s*:\s*([A-Z][A-Za-z0-9_]*)/g)) {
|
|
219
|
+
const baseName = match[1] ?? "";
|
|
220
|
+
if (!CSHARP_FRAMEWORK_TYPE.test(baseName))
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
213
223
|
}
|
|
214
224
|
return false;
|
|
215
225
|
}
|
|
@@ -2042,7 +2052,7 @@ function shouldReadText(rel) {
|
|
|
2042
2052
|
return true;
|
|
2043
2053
|
if (base === "dockerfile" || base.startsWith("dockerfile."))
|
|
2044
2054
|
return true;
|
|
2045
|
-
return base === "package.json" || base === "tsconfig.json" || base === "pyproject.toml" || base === "cargo.toml" || base === "go.mod" || base === "codeowners" || base === "agents.md" || base === "claude.md" || base === "gemini.md" || base === "skill.md" || base === "review.md" || base === "gates.md" || base === "lefthook.yml" || base === ".oxlintrc.json" || base === ".oxlintrc.jsonc" || base === "oxlint.config.ts" || base === "turbo.json" || base === "directory.build.props" || base === "directory.packages.props" || base === ".editorconfig" || base === "stryker-config.json" || base === "clippy.toml" || base === ".clippy.toml" || base === "rustfmt.toml" || base === ".rustfmt.toml" || base === "mutants.toml" || base === "ruff.toml" || base === ".ruff.toml" || base === "mypy.ini" || base === "pyrightconfig.json" || base === "pytest.ini" || base === "control-plan.json" || base === "escapes.json" || base.endsWith(".csproj") || base.endsWith(".tla") || base.endsWith(".qnt") || base.endsWith(".als") || base.endsWith(".dfy") || base.endsWith(".lean") || base.endsWith(".feature") || /^(?:vitest|vite)\.config\.[cm]?[jt]s$/.test(base);
|
|
2055
|
+
return base === "package.json" || base === "tsconfig.json" || base === "pyproject.toml" || base === "cargo.toml" || base === "go.mod" || base === "codeowners" || base === "agents.md" || base === "claude.md" || base === "gemini.md" || base === ".cursorrules" || base === "copilot-instructions.md" || base === "skill.md" || base === "review.md" || base === "gates.md" || base === "lefthook.yml" || base === ".oxlintrc.json" || base === ".oxlintrc.jsonc" || base === "oxlint.config.ts" || base === "turbo.json" || base === "directory.build.props" || base === "directory.packages.props" || base === ".editorconfig" || base === "stryker-config.json" || base === "clippy.toml" || base === ".clippy.toml" || base === "rustfmt.toml" || base === ".rustfmt.toml" || base === "mutants.toml" || base === "ruff.toml" || base === ".ruff.toml" || base === "mypy.ini" || base === "pyrightconfig.json" || base === "pytest.ini" || base === "control-plan.json" || base === "escapes.json" || base.endsWith(".csproj") || base.endsWith(".tla") || base.endsWith(".qnt") || base.endsWith(".als") || base.endsWith(".dfy") || base.endsWith(".lean") || base.endsWith(".feature") || /^(?:vitest|vite)\.config\.[cm]?[jt]s$/.test(base);
|
|
2046
2056
|
}
|
|
2047
2057
|
function readSafe(abs) {
|
|
2048
2058
|
try {
|
|
@@ -2169,8 +2179,10 @@ function discoverRepo(repoPath) {
|
|
|
2169
2179
|
`);
|
|
2170
2180
|
const configText = files.filter((f) => !f.isTest && (!f.language && !f.rel.toLowerCase().endsWith(".md") || f.rel.includes("config") || f.isWorkflow)).map((f) => f.content).join(`
|
|
2171
2181
|
`);
|
|
2172
|
-
const
|
|
2173
|
-
|
|
2182
|
+
const manifestText = files.filter((f) => !f.isTest && !f.isWorkflow && !f.language && !f.rel.toLowerCase().endsWith(".md")).map((f) => f.content).join(`
|
|
2183
|
+
`);
|
|
2184
|
+
const hasReactOrUi = /(?:["'](?:react|next|vue|svelte|@angular\/core|solid-js)["']|\b(?:react-dom|next\.config)\b)/i.test(manifestText) || lowerPaths.some((p) => p.endsWith(".tsx") || p.endsWith(".jsx") || p.endsWith(".vue") || p.endsWith(".svelte"));
|
|
2185
|
+
const hasBackendService = /\b(?:express|fastify|hono|nestjs|koa|fastapi|django|flask|actix-web|axum|gin-gonic|microsoft\.aspnetcore)\b/i.test(manifestText) || files.some((f) => f.language === "csharp" && !f.isTest && /\bWebApplication\.CreateBuilder\b/.test(f.content)) || lowerPaths.some((p) => p.includes("dockerfile") || p.includes("controllers/") || p.includes("routes/"));
|
|
2174
2186
|
let archetype = "library";
|
|
2175
2187
|
if (hasReactOrUi && hasBackendService)
|
|
2176
2188
|
archetype = "fullstack";
|
|
@@ -2441,12 +2453,14 @@ function scanSingleTestFile(file, repoHasEmulator) {
|
|
|
2441
2453
|
const hasRealBus = REAL_BUS_SIGNAL.test(code);
|
|
2442
2454
|
const hasNetworkMock = NETWORK_MOCK_SIGNAL.test(code);
|
|
2443
2455
|
const isConfigFile = /(?:config|playwright|vitest|jest)\.[cm]?[jt]s$/i.test(file.rel);
|
|
2444
|
-
const addMatches = (target, regex, rule, category, severity, message, fix, limit = 5) => {
|
|
2456
|
+
const addMatches = (target, regex, rule, category, severity, message, fix, limit = 5, skip) => {
|
|
2445
2457
|
let count = 0;
|
|
2446
2458
|
for (const m of target.matchAll(regex)) {
|
|
2447
2459
|
const idx = m.index ?? 0;
|
|
2448
2460
|
if (target === raw && code[idx] === " ")
|
|
2449
2461
|
continue;
|
|
2462
|
+
if (skip?.(m))
|
|
2463
|
+
continue;
|
|
2450
2464
|
count += 1;
|
|
2451
2465
|
if (count <= limit) {
|
|
2452
2466
|
const line = lineOf(target, idx);
|
|
@@ -2513,7 +2527,10 @@ function scanSingleTestFile(file, repoHasEmulator) {
|
|
|
2513
2527
|
addMatches(code, SKIP_OR_ONLY, "test-discipline", "cheat", "error", "Focused (.only) or disabled (.todo/.fixme/Ignore) test committed.", "Restore a deterministic assertion or remove dead tests; never silently skip gating checks.");
|
|
2514
2528
|
addMatches(raw, UNCONDITIONAL_SKIP, "test-discipline", "cheat", "error", "Unconditionally skipped test (.skip) committed.", "Fix, delete, or track in a known-defect ledger; a skipped test proves nothing.");
|
|
2515
2529
|
addMatches(code, MULTI_STATUS_ASSERT, "no-multi-status-assertion", "test-smell", "error", "Assertion accepts multiple HTTP statuses and passes whether the call succeeded or failed.", "Assert the single exact HTTP status promised by the contract.");
|
|
2516
|
-
addMatches(code, TAUTOLOGY, "weak-asserts-tautology", "test-smell", "error", "Tautological assertion cannot fail when behavior breaks.", "Compare a computed SUT output against an independently derived expected value.")
|
|
2530
|
+
addMatches(code, TAUTOLOGY, "weak-asserts-tautology", "test-smell", "error", "Tautological assertion cannot fail when behavior breaks.", "Compare a computed SUT output against an independently derived expected value.", 5, (m) => {
|
|
2531
|
+
const idx = m.index ?? 0;
|
|
2532
|
+
return /^Assert\.Pass\b/.test(m[0]) && /\bAssert\.Fail\s*\(/.test(code.slice(Math.max(0, idx - 300), idx + 300));
|
|
2533
|
+
});
|
|
2517
2534
|
addMatches(code, SAME_CALL_EXPECT, "self-derived-expectation", "test-smell", "error", "Actual and expected values invoke the exact same function call.", "Replace the expected side with a known literal or independent oracle.");
|
|
2518
2535
|
addMatches(code, CONDITIONAL_EXPECT, "no-conditional-expect", "test-smell", "error", "Assertion inside conditional branch silently passes if branch is skipped.", "Split into explicit test cases with unconditional assertions.");
|
|
2519
2536
|
addMatches(code, WALL_CLOCK, "no-elapsed-time-bound", "test-smell", "warn", "Wall-clock elapsed-time assertion flakes on shared CI runners.", "Assert logical ordering or move performance bounds to a dedicated R6 benchmark.");
|
|
@@ -6822,6 +6839,16 @@ var RUST_INSTANT_ARITH = /\bInstant::now\s*\(\s*\)\s*[+-]\s*[A-Za-z0-9_.:]+|\.\s
|
|
|
6822
6839
|
var RUST_POLL_FN = /\bfn\s+poll(?:_next|_read|_write)?\s*\([^)]*\)[^{]*\{/g;
|
|
6823
6840
|
var RUST_HASHMAP_ENVS = /\.\s*envs\s*\(\s*&?\s*[A-Za-z0-9_.]*hash_?map[A-Za-z0-9_]*\s*\)/gi;
|
|
6824
6841
|
var CS_UNORDERED_SKIP = /\.\s*Skip\s*\(\s*[^)\n]+\)/g;
|
|
6842
|
+
var CS_EF_CONTEXT = /\b(?:Microsoft\.EntityFrameworkCore|DbContext|DbSet|IQueryable|AsNoTracking|ToListAsync|FirstOrDefaultAsync|SingleOrDefaultAsync)\b/;
|
|
6843
|
+
function isSymmetricBoundMath(callText) {
|
|
6844
|
+
const open = callText.indexOf("(");
|
|
6845
|
+
const comma = callText.indexOf(",", open + 1);
|
|
6846
|
+
if (open < 0 || comma < 0)
|
|
6847
|
+
return false;
|
|
6848
|
+
const firstArg = callText.slice(open + 1, comma);
|
|
6849
|
+
const isMin = /\bMath\.(?:min|Min)\b/.test(callText.slice(0, open));
|
|
6850
|
+
return isMin ? /(?:min|Min|floor|Floor)/.test(firstArg) : /(?:max|Max|cap|Cap|ceiling|Ceiling)/.test(firstArg);
|
|
6851
|
+
}
|
|
6825
6852
|
var CS_UNDISPOSED_NEW = /^[ \t]*(?!using\b|await\s+using\b|return\b)(?:var|[A-Za-z0-9_.<>]+)\s+[A-Za-z_][A-Za-z0-9_]*\s*=\s*new\s+(?:SqlConnection|NpgsqlConnection|FileStream|StreamReader|StreamWriter|DbCommand|SqlCommand)\s*\(/gm;
|
|
6826
6853
|
var GO_HTTP_CALL = /\b(?:http\.(?:Get|Post|PostForm|Head)|[A-Za-z_][A-Za-z0-9_]*\.Do)\s*\(/g;
|
|
6827
6854
|
function push14(findings, file, line, rule, rung, severity, message, fix) {
|
|
@@ -6966,11 +6993,13 @@ function analyzeOssGuards(file) {
|
|
|
6966
6993
|
return findings;
|
|
6967
6994
|
}
|
|
6968
6995
|
if (file.language === "csharp") {
|
|
6969
|
-
|
|
6970
|
-
const
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6996
|
+
if (CS_EF_CONTEXT.test(masked)) {
|
|
6997
|
+
for (const m of masked.matchAll(CS_UNORDERED_SKIP)) {
|
|
6998
|
+
const idx = m.index ?? 0;
|
|
6999
|
+
if (/\.\s*OrderBy(?:Descending)?\s*\(/.test(masked.slice(Math.max(0, idx - 220), idx)))
|
|
7000
|
+
continue;
|
|
7001
|
+
push14(findings, file.rel, lineOf(raw, idx), "efcore-unordered-skip-or-assert", "R1", "warn", ".Skip() called without a preceding .OrderBy() produces non-deterministic query pagination across DB engines.", "Chain a deterministic .OrderBy(...) (with a unique tie-breaker) before .Skip()/.Take().");
|
|
7002
|
+
}
|
|
6974
7003
|
}
|
|
6975
7004
|
for (const m of masked.matchAll(CS_UNDISPOSED_NEW)) {
|
|
6976
7005
|
const idx = m.index ?? 0;
|
|
@@ -6979,6 +7008,8 @@ function analyzeOssGuards(file) {
|
|
|
6979
7008
|
push14(findings, file.rel, lineOf(raw, idx), "csharp-undisposed-local-idisp", "R1", "warn", "Local IDisposable resource constructed without 'using' risks connection/file-handle leaks.", "Declare with 'using var' or 'await using var' so disposal runs deterministically even on exceptions.");
|
|
6980
7009
|
}
|
|
6981
7010
|
for (const m of masked.matchAll(FLOOR_CEILING_INVERSION)) {
|
|
7011
|
+
if (isSymmetricBoundMath(m[0]))
|
|
7012
|
+
continue;
|
|
6982
7013
|
push14(findings, file.rel, lineOf(raw, m.index ?? 0), "math-floor-ceiling-inversion", "R1", "warn", `Possible floor/ceiling clamp inversion (${m[0].trim()}).`, "Verify Math.Max is used for lower bounds (floors) and Math.Min is used for upper bounds (ceilings).");
|
|
6983
7014
|
}
|
|
6984
7015
|
return findings;
|
|
@@ -7137,6 +7168,8 @@ function analyzeOssGuards(file) {
|
|
|
7137
7168
|
push14(findings, file.rel, lineOf(raw, idx), "require-try-finally-around-teardown", "R1", "warn", "Sequential flush/export before close/dispose lacks try...finally — an export error skips close() and leaks resources.", "Wrap export/flush in try { ... } finally { await close(); } so teardown always executes.");
|
|
7138
7169
|
}
|
|
7139
7170
|
for (const m of masked.matchAll(FLOOR_CEILING_INVERSION)) {
|
|
7171
|
+
if (isSymmetricBoundMath(m[0]))
|
|
7172
|
+
continue;
|
|
7140
7173
|
push14(findings, file.rel, lineOf(raw, m.index ?? 0), "math-floor-ceiling-inversion", "R1", "warn", `Possible floor/ceiling clamp inversion (${m[0].trim()}).`, "Verify Math.max is used for lower bounds (floors) and Math.min is used for upper bounds (ceilings).");
|
|
7141
7174
|
}
|
|
7142
7175
|
for (const m of masked.matchAll(/\.(?:includes)\s*\(/g)) {
|
|
@@ -7969,6 +8002,11 @@ function checkCsharpScatteredMutations(file, masked) {
|
|
|
7969
8002
|
const before = masked.slice(Math.max(0, pos - 40), pos);
|
|
7970
8003
|
if (/\b(?:new\s+[A-Za-z_]|with\s*\{|var\s+|bool\s+|string\s+|int\s+)/.test(before))
|
|
7971
8004
|
continue;
|
|
8005
|
+
const lineEnd = masked.indexOf(`
|
|
8006
|
+
`, pos);
|
|
8007
|
+
const restOfLine = masked.slice(pos, lineEnd < 0 ? pos + 120 : lineEnd);
|
|
8008
|
+
if (/,\s*$/.test(restOfLine) || /\bEntityState\./.test(restOfLine) || /\bAddress\.State\b/.test(restOfLine))
|
|
8009
|
+
continue;
|
|
7972
8010
|
const containing = spans.filter((s) => s.start < pos && pos < s.end).sort((a, b) => a.end - a.start - (b.end - b.start))[0];
|
|
7973
8011
|
if (!containing || CANONICAL_TRANSITION.test(containing.name))
|
|
7974
8012
|
continue;
|
|
@@ -9865,7 +9903,8 @@ function analyzeStructure(repo) {
|
|
|
9865
9903
|
}
|
|
9866
9904
|
}
|
|
9867
9905
|
if (file.language === "csharp" && !file.isTest && !isGenerated) {
|
|
9868
|
-
|
|
9906
|
+
const csharpCode = maskCode(file.content, "csharp");
|
|
9907
|
+
for (const match of csharpCode.matchAll(CSHARP_TEST_ONLY_EXPORT)) {
|
|
9869
9908
|
const line = lineOf5(file.content, match.index ?? 0);
|
|
9870
9909
|
findings.push({
|
|
9871
9910
|
id: `ST:cs-test-seam:${file.rel}:${line}`,
|
|
@@ -9879,7 +9918,7 @@ function analyzeStructure(repo) {
|
|
|
9879
9918
|
fix: "Remove test-only production backdoors and verify behavior through the public contract."
|
|
9880
9919
|
});
|
|
9881
9920
|
}
|
|
9882
|
-
for (const match of
|
|
9921
|
+
for (const match of csharpCode.matchAll(SWALLOWING_CATCH)) {
|
|
9883
9922
|
const line = lineOf5(file.content, match.index ?? 0);
|
|
9884
9923
|
findings.push({
|
|
9885
9924
|
id: `ST:cs-swallow-catch:${file.rel}:${line}`,
|
|
@@ -9893,7 +9932,7 @@ function analyzeStructure(repo) {
|
|
|
9893
9932
|
fix: "Rethrow, return a typed result/error variant, or handle the specific expected exception explicitly."
|
|
9894
9933
|
});
|
|
9895
9934
|
}
|
|
9896
|
-
for (const match of
|
|
9935
|
+
for (const match of csharpCode.matchAll(CSHARP_DYNAMIC)) {
|
|
9897
9936
|
const line = lineOf5(file.content, match.index ?? 0);
|
|
9898
9937
|
findings.push({
|
|
9899
9938
|
id: `AS:cs-dynamic:${file.rel}:${line}`,
|
|
@@ -10152,6 +10191,130 @@ function analyzeStructure(repo) {
|
|
|
10152
10191
|
return findings;
|
|
10153
10192
|
}
|
|
10154
10193
|
|
|
10194
|
+
// src/anti-slop/agent-docs.ts
|
|
10195
|
+
import fs6 from "node:fs";
|
|
10196
|
+
import path15 from "node:path";
|
|
10197
|
+
var AGENT_DOC_BASENAME = /^(?:agents\.md|claude\.md|gemini\.md|review\.md|\.cursorrules|copilot-instructions\.md)$/i;
|
|
10198
|
+
var MAX_AGENT_DOC_LINES = 400;
|
|
10199
|
+
var BACKTICK_TOKEN = /`([^`\r\n]+)`/g;
|
|
10200
|
+
var KNOWN_FILE_EXT = /\.(?:[cm]?[jt]sx?|cs|py|rs|go|jsonc?|ya?ml|toml|sql|sh|bash|md|mdx|bend|csproj|slnx)$/i;
|
|
10201
|
+
var MECHANICAL_PROHIBITION = /\b(?:never|must not|do not|don't|ban|forbid)\s+(?:use|call|import|add|commit|skip|weaken|pipe|disable)\b/i;
|
|
10202
|
+
function isAgentInstructionFile(rel) {
|
|
10203
|
+
const norm = rel.replace(/\\/g, "/");
|
|
10204
|
+
if (/^(?:examples|templates|tests\/fixtures)\//i.test(norm))
|
|
10205
|
+
return false;
|
|
10206
|
+
const base = path15.posix.basename(norm);
|
|
10207
|
+
return AGENT_DOC_BASENAME.test(base);
|
|
10208
|
+
}
|
|
10209
|
+
function collectTopLevelDirs(repoRoot) {
|
|
10210
|
+
const dirs = new Set;
|
|
10211
|
+
try {
|
|
10212
|
+
for (const entry of fs6.readdirSync(repoRoot, { withFileTypes: true })) {
|
|
10213
|
+
if (entry.isDirectory() && entry.name !== ".git" && entry.name !== "node_modules") {
|
|
10214
|
+
dirs.add(entry.name);
|
|
10215
|
+
}
|
|
10216
|
+
}
|
|
10217
|
+
} catch {
|
|
10218
|
+
return dirs;
|
|
10219
|
+
}
|
|
10220
|
+
return dirs;
|
|
10221
|
+
}
|
|
10222
|
+
function auditAgentDocs(repo) {
|
|
10223
|
+
const findings = [];
|
|
10224
|
+
const topDirs = collectTopLevelDirs(repo.root);
|
|
10225
|
+
const hasMechanicalEnforcementRegistry = repo.allRelPaths.some((p) => /^\.verification\/(?:chokepoints|escapes)\.json$/i.test(p));
|
|
10226
|
+
for (const file of repo.files) {
|
|
10227
|
+
if (!isAgentInstructionFile(file.rel))
|
|
10228
|
+
continue;
|
|
10229
|
+
if (file.lines > MAX_AGENT_DOC_LINES) {
|
|
10230
|
+
findings.push({
|
|
10231
|
+
id: `AD:bloat:${file.rel}:1`,
|
|
10232
|
+
rule: "agent-doc-bloat",
|
|
10233
|
+
category: "structure",
|
|
10234
|
+
rung: "R0",
|
|
10235
|
+
severity: "warn",
|
|
10236
|
+
file: file.rel,
|
|
10237
|
+
line: 1,
|
|
10238
|
+
message: `Agent instruction file ${file.rel} has ${file.lines} lines (budget: <= ${MAX_AGENT_DOC_LINES}); oversized instruction files dilute context and compound slop.`,
|
|
10239
|
+
fix: "Trim stale prose, move topic details into progressive-disclosure docs, and promote mechanical rules into R0/R1 linters."
|
|
10240
|
+
});
|
|
10241
|
+
}
|
|
10242
|
+
const lines = file.content.split(/\r?\n/);
|
|
10243
|
+
const seenStale = new Set;
|
|
10244
|
+
let inFence = false;
|
|
10245
|
+
let staleCount = 0;
|
|
10246
|
+
let mechanicalProseCount = 0;
|
|
10247
|
+
for (let idx = 0;idx < lines.length; idx++) {
|
|
10248
|
+
const line = lines[idx] ?? "";
|
|
10249
|
+
if (/^\s*```/.test(line)) {
|
|
10250
|
+
inFence = !inFence;
|
|
10251
|
+
continue;
|
|
10252
|
+
}
|
|
10253
|
+
if (inFence)
|
|
10254
|
+
continue;
|
|
10255
|
+
if (MECHANICAL_PROHIBITION.test(line)) {
|
|
10256
|
+
mechanicalProseCount += 1;
|
|
10257
|
+
}
|
|
10258
|
+
if (staleCount >= 5)
|
|
10259
|
+
continue;
|
|
10260
|
+
for (const m of line.matchAll(BACKTICK_TOKEN)) {
|
|
10261
|
+
const rawToken = (m[1] ?? "").trim();
|
|
10262
|
+
if (!rawToken || /\s|[*?<>:${}()|]|:\/\//.test(rawToken))
|
|
10263
|
+
continue;
|
|
10264
|
+
if (rawToken.startsWith("/") || rawToken.startsWith("~") || rawToken.startsWith("-"))
|
|
10265
|
+
continue;
|
|
10266
|
+
const clean = rawToken.replace(/^\.\//, "").split("#")[0]?.split(":")[0] ?? "";
|
|
10267
|
+
if (!clean || !clean.includes("/") || clean.endsWith("/"))
|
|
10268
|
+
continue;
|
|
10269
|
+
if (!KNOWN_FILE_EXT.test(clean))
|
|
10270
|
+
continue;
|
|
10271
|
+
const firstSegment = clean.split("/")[0] ?? "";
|
|
10272
|
+
if (!topDirs.has(firstSegment))
|
|
10273
|
+
continue;
|
|
10274
|
+
if (seenStale.has(clean))
|
|
10275
|
+
continue;
|
|
10276
|
+
const resolved = path15.resolve(repo.root, clean);
|
|
10277
|
+
if (!resolved.startsWith(`${repo.root}${path15.sep}`))
|
|
10278
|
+
continue;
|
|
10279
|
+
if (fs6.existsSync(resolved))
|
|
10280
|
+
continue;
|
|
10281
|
+
const siblingResolved = path15.resolve(path15.dirname(file.abs), clean);
|
|
10282
|
+
if (siblingResolved.startsWith(`${repo.root}${path15.sep}`) && fs6.existsSync(siblingResolved))
|
|
10283
|
+
continue;
|
|
10284
|
+
seenStale.add(clean);
|
|
10285
|
+
staleCount += 1;
|
|
10286
|
+
findings.push({
|
|
10287
|
+
id: `AD:stale-path:${file.rel}:${idx + 1}:${clean}`,
|
|
10288
|
+
rule: "agent-doc-stale-path",
|
|
10289
|
+
category: "structure",
|
|
10290
|
+
rung: "R0",
|
|
10291
|
+
severity: "warn",
|
|
10292
|
+
file: file.rel,
|
|
10293
|
+
line: idx + 1,
|
|
10294
|
+
message: `Agent instruction file references missing path '${clean}'; stale knowledge-base pointers cause agents to hallucinate or copy obsolete patterns.`,
|
|
10295
|
+
fix: `Update or remove the stale reference to '${clean}' in ${file.rel}.`
|
|
10296
|
+
});
|
|
10297
|
+
if (staleCount >= 5)
|
|
10298
|
+
break;
|
|
10299
|
+
}
|
|
10300
|
+
}
|
|
10301
|
+
if (mechanicalProseCount >= 4 && !hasMechanicalEnforcementRegistry) {
|
|
10302
|
+
findings.push({
|
|
10303
|
+
id: `AD:unpromoted:${file.rel}:1`,
|
|
10304
|
+
rule: "agent-doc-unpromoted-rules",
|
|
10305
|
+
category: "structure",
|
|
10306
|
+
rung: "R1",
|
|
10307
|
+
severity: "info",
|
|
10308
|
+
file: file.rel,
|
|
10309
|
+
line: 1,
|
|
10310
|
+
message: `${file.rel} states ${mechanicalProseCount} mechanical prohibition(s) in prose without a .verification/chokepoints.json or escapes.json enforcement registry.`,
|
|
10311
|
+
fix: "Run 'vstack circuit run instruction-lint-promoter .' and promote repeatable bans into deterministic R0/R1 linters."
|
|
10312
|
+
});
|
|
10313
|
+
}
|
|
10314
|
+
}
|
|
10315
|
+
return findings;
|
|
10316
|
+
}
|
|
10317
|
+
|
|
10155
10318
|
// src/ladder.ts
|
|
10156
10319
|
var E2E_CAP_BY_ARCHETYPE = {
|
|
10157
10320
|
library: { max: 0, label: "0 (not applicable)" },
|
|
@@ -10362,6 +10525,7 @@ function scanRepo(repoPath, options = {}) {
|
|
|
10362
10525
|
}
|
|
10363
10526
|
}
|
|
10364
10527
|
rawFindings.push(...analyzeStructure(repo));
|
|
10528
|
+
rawFindings.push(...auditAgentDocs(repo));
|
|
10365
10529
|
const testResult = analyzeTests(repo);
|
|
10366
10530
|
rawFindings.push(...testResult.findings);
|
|
10367
10531
|
rawFindings.push(...auditCiWorkflows(repo));
|
|
@@ -10413,8 +10577,8 @@ function scanRepo(repoPath, options = {}) {
|
|
|
10413
10577
|
}
|
|
10414
10578
|
|
|
10415
10579
|
// src/ratchet.ts
|
|
10416
|
-
import
|
|
10417
|
-
import
|
|
10580
|
+
import fs7 from "node:fs";
|
|
10581
|
+
import path16 from "node:path";
|
|
10418
10582
|
function buildRatchetBaseline(findings) {
|
|
10419
10583
|
const counts = new Map;
|
|
10420
10584
|
for (const f of findings) {
|
|
@@ -10450,16 +10614,16 @@ function evaluateRatchet(findings, baseline) {
|
|
|
10450
10614
|
};
|
|
10451
10615
|
}
|
|
10452
10616
|
function writeRatchetBaseline(filePath, baseline) {
|
|
10453
|
-
const resolved =
|
|
10454
|
-
|
|
10455
|
-
|
|
10617
|
+
const resolved = path16.resolve(filePath);
|
|
10618
|
+
fs7.mkdirSync(path16.dirname(resolved), { recursive: true });
|
|
10619
|
+
fs7.writeFileSync(resolved, `${JSON.stringify(baseline, null, 2)}
|
|
10456
10620
|
`, "utf8");
|
|
10457
10621
|
}
|
|
10458
10622
|
|
|
10459
10623
|
// src/zero-defect/bench.ts
|
|
10460
|
-
import
|
|
10624
|
+
import fs8 from "node:fs";
|
|
10461
10625
|
import os3 from "node:os";
|
|
10462
|
-
import
|
|
10626
|
+
import path17 from "node:path";
|
|
10463
10627
|
function commentPrefix(lang) {
|
|
10464
10628
|
if (lang === "python" || lang === "shell")
|
|
10465
10629
|
return "# ";
|
|
@@ -10493,16 +10657,16 @@ const Doc = "${escaped}"
|
|
|
10493
10657
|
`;
|
|
10494
10658
|
}
|
|
10495
10659
|
function runInTempDir(files) {
|
|
10496
|
-
const dir =
|
|
10660
|
+
const dir = fs8.mkdtempSync(path17.join(os3.tmpdir(), "vstack-bench-"));
|
|
10497
10661
|
try {
|
|
10498
10662
|
for (const [rel, content] of Object.entries(files)) {
|
|
10499
|
-
const full =
|
|
10500
|
-
|
|
10501
|
-
|
|
10663
|
+
const full = path17.join(dir, rel);
|
|
10664
|
+
fs8.mkdirSync(path17.dirname(full), { recursive: true });
|
|
10665
|
+
fs8.writeFileSync(full, content, "utf8");
|
|
10502
10666
|
}
|
|
10503
10667
|
return scanRepo(dir);
|
|
10504
10668
|
} finally {
|
|
10505
|
-
|
|
10669
|
+
fs8.rmSync(dir, { recursive: true, force: true });
|
|
10506
10670
|
}
|
|
10507
10671
|
}
|
|
10508
10672
|
function countRuleMap(findings) {
|
|
@@ -10516,11 +10680,11 @@ function countRuleMap(findings) {
|
|
|
10516
10680
|
return m;
|
|
10517
10681
|
}
|
|
10518
10682
|
function runHistoricalReplayBench(replayDir) {
|
|
10519
|
-
const manifestPath =
|
|
10520
|
-
const entries = JSON.parse(
|
|
10683
|
+
const manifestPath = path17.join(replayDir, "manifest.json");
|
|
10684
|
+
const entries = JSON.parse(fs8.readFileSync(manifestPath, "utf8"));
|
|
10521
10685
|
const t0 = performance.now();
|
|
10522
|
-
const beforeScan = scanRepo(
|
|
10523
|
-
const afterScan = scanRepo(
|
|
10686
|
+
const beforeScan = scanRepo(path17.join(replayDir, "before"));
|
|
10687
|
+
const afterScan = scanRepo(path17.join(replayDir, "after"));
|
|
10524
10688
|
const scanMs = Number((performance.now() - t0).toFixed(2));
|
|
10525
10689
|
const beforeByFile = new Map;
|
|
10526
10690
|
for (const f of beforeScan.findings) {
|
|
@@ -10558,8 +10722,8 @@ function runHistoricalReplayBench(replayDir) {
|
|
|
10558
10722
|
if (aCnt > (bMap.get(rule) ?? 0))
|
|
10559
10723
|
regressedRules.push(rule);
|
|
10560
10724
|
}
|
|
10561
|
-
const beforeRaw =
|
|
10562
|
-
const afterRaw =
|
|
10725
|
+
const beforeRaw = fs8.readFileSync(path17.join(replayDir, "before", entry.beforeRel), "utf8");
|
|
10726
|
+
const afterRaw = fs8.readFileSync(path17.join(replayDir, "after", entry.afterRel), "utf8");
|
|
10563
10727
|
const revertEvents = buildSyntheticRevertEvents(entry.afterRel, afterRaw, beforeRaw);
|
|
10564
10728
|
const revertFindings = [
|
|
10565
10729
|
...auditDiffInvariantLoss(revertEvents),
|
|
@@ -10626,17 +10790,17 @@ function runHistoricalReplayBench(replayDir) {
|
|
|
10626
10790
|
};
|
|
10627
10791
|
}
|
|
10628
10792
|
function runPrecisionBench(repoRoot, corpusDir, replayDir) {
|
|
10629
|
-
const examplesRoot =
|
|
10793
|
+
const examplesRoot = path17.join(repoRoot, "examples");
|
|
10630
10794
|
const langs = ["typescript", "csharp", "rust", "python", "go", "sql", "shell"];
|
|
10631
10795
|
const languages = [];
|
|
10632
10796
|
for (const lang of langs) {
|
|
10633
|
-
const langDir =
|
|
10634
|
-
const manifestPath =
|
|
10635
|
-
if (!
|
|
10797
|
+
const langDir = path17.join(examplesRoot, lang);
|
|
10798
|
+
const manifestPath = path17.join(langDir, "manifest.json");
|
|
10799
|
+
if (!fs8.existsSync(manifestPath))
|
|
10636
10800
|
continue;
|
|
10637
|
-
const manifest = JSON.parse(
|
|
10638
|
-
const caughtDir =
|
|
10639
|
-
const cleanDir =
|
|
10801
|
+
const manifest = JSON.parse(fs8.readFileSync(manifestPath, "utf8"));
|
|
10802
|
+
const caughtDir = path17.join(langDir, "caught");
|
|
10803
|
+
const cleanDir = path17.join(langDir, "clean");
|
|
10640
10804
|
const t0 = performance.now();
|
|
10641
10805
|
const caughtScan = scanRepo(caughtDir);
|
|
10642
10806
|
const cleanScan = scanRepo(cleanDir);
|
|
@@ -10665,7 +10829,7 @@ function runPrecisionBench(repoRoot, corpusDir, replayDir) {
|
|
|
10665
10829
|
for (const relFile of Object.keys(manifest.caught)) {
|
|
10666
10830
|
if (/test|spec/i.test(relFile))
|
|
10667
10831
|
continue;
|
|
10668
|
-
const content =
|
|
10832
|
+
const content = fs8.readFileSync(path17.join(caughtDir, relFile), "utf8");
|
|
10669
10833
|
commentedFiles[relFile] = wrapInComments(content, lang);
|
|
10670
10834
|
const wrappedStr = wrapInStringLiteral(content, lang);
|
|
10671
10835
|
if (wrappedStr !== null)
|
|
@@ -10689,7 +10853,7 @@ function runPrecisionBench(repoRoot, corpusDir, replayDir) {
|
|
|
10689
10853
|
});
|
|
10690
10854
|
}
|
|
10691
10855
|
let corpusFindingsPer10kLoc;
|
|
10692
|
-
if (corpusDir &&
|
|
10856
|
+
if (corpusDir && fs8.existsSync(corpusDir)) {
|
|
10693
10857
|
const corpusReport = scanRepo(corpusDir);
|
|
10694
10858
|
const loc = Math.max(1, corpusReport.summary.prodLines + corpusReport.summary.testLines);
|
|
10695
10859
|
corpusFindingsPer10kLoc = Number((corpusReport.findings.length / loc * 1e4).toFixed(2));
|
|
@@ -10699,7 +10863,7 @@ function runPrecisionBench(repoRoot, corpusDir, replayDir) {
|
|
|
10699
10863
|
const totalCleanFps = languages.reduce((s, l) => s + l.cleanFalsePositives.length, 0);
|
|
10700
10864
|
const totalAdversarialFps = languages.reduce((s, l) => s + l.commentWrappedFps.length + l.stringWrappedFps.length, 0);
|
|
10701
10865
|
const totalScanMs = Number(languages.reduce((s, l) => s + l.scanMs, 0).toFixed(2));
|
|
10702
|
-
const replay = replayDir &&
|
|
10866
|
+
const replay = replayDir && fs8.existsSync(path17.join(replayDir, "manifest.json")) ? runHistoricalReplayBench(replayDir) : undefined;
|
|
10703
10867
|
return {
|
|
10704
10868
|
passed: totalExpectedRules === totalMatchedRules && totalCleanFps === 0 && totalAdversarialFps === 0,
|
|
10705
10869
|
totalExpectedRules,
|
|
@@ -10835,8 +10999,8 @@ function fitEmpiricalBigO(samples, thresholds = { maxTimeExponent: 1.45 }) {
|
|
|
10835
10999
|
}
|
|
10836
11000
|
|
|
10837
11001
|
// src/zero-defect/daikon-invariants.ts
|
|
10838
|
-
import
|
|
10839
|
-
import
|
|
11002
|
+
import fs9 from "node:fs";
|
|
11003
|
+
import path18 from "node:path";
|
|
10840
11004
|
function runtimeType(val) {
|
|
10841
11005
|
if (val === null)
|
|
10842
11006
|
return "null";
|
|
@@ -10997,9 +11161,9 @@ function compareInvariantSnapshots(baseline, current, baselineFile = ".verificat
|
|
|
10997
11161
|
};
|
|
10998
11162
|
}
|
|
10999
11163
|
function writeInvariantSnapshot(filePath, snapshot) {
|
|
11000
|
-
const resolved =
|
|
11001
|
-
|
|
11002
|
-
|
|
11164
|
+
const resolved = path18.resolve(filePath);
|
|
11165
|
+
fs9.mkdirSync(path18.dirname(resolved), { recursive: true });
|
|
11166
|
+
fs9.writeFileSync(resolved, `${JSON.stringify(snapshot, null, 2)}
|
|
11003
11167
|
`, "utf8");
|
|
11004
11168
|
}
|
|
11005
11169
|
function formatInvariantDiffReport(snapshot, diff) {
|
|
@@ -11025,6 +11189,320 @@ function formatInvariantDiffReport(snapshot, diff) {
|
|
|
11025
11189
|
`);
|
|
11026
11190
|
}
|
|
11027
11191
|
|
|
11192
|
+
// src/anti-slop/review-brief.ts
|
|
11193
|
+
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
11194
|
+
import path19 from "node:path";
|
|
11195
|
+
var LOCK_OR_GENERATED = /(?:^|\/)(?:pnpm-lock\.yaml|package-lock\.json|yarn\.lock|bun\.lockb?|cargo\.lock|uv\.lock|poetry\.lock|go\.sum)$|\.(?:snap|generated\.[a-z]+)$/i;
|
|
11196
|
+
var DOC_FILE = /\.(?:md|mdx|txt|rst)$/i;
|
|
11197
|
+
var CRITICAL_PATH = /(?:^|\/)(?:\.github\/workflows\/|codeowners$|migrations\/|schema|rls|policies\/|auth|security|billing|payment|permission|crypto|token|secret|openapi|contracts|state-machines?\/|tsconfig(?:\.[^/]+)?\.json$|\.?vstack\.json$|\.verification\/|package\.json$|cargo\.toml$|pyproject\.toml$|directory\.build\.props$)/i;
|
|
11198
|
+
var WORKAROUND_MARKER = /\b(?:HACK|WORKAROUND|TEMP(?:ORARY)?|KLUDGE|FIXME)\b/;
|
|
11199
|
+
var FALLBACK_SWALLOW_CATCH = /\bcatch\b[^{]*\{\s*return\s+(?:null|undefined|false|true|\[\s*\]|\{\s*\}|""|''|0)\s*;?\s*\}/;
|
|
11200
|
+
var TIER_ORDER = { critical: 0, core: 1, verify: 2, low: 3 };
|
|
11201
|
+
function validateBaseRef(baseRef) {
|
|
11202
|
+
if (!baseRef || baseRef.startsWith("-")) {
|
|
11203
|
+
throw new Error(`Invalid git baseRef "${baseRef}".`);
|
|
11204
|
+
}
|
|
11205
|
+
}
|
|
11206
|
+
function classifyFileStakes(file, cheatCount, workaroundCount) {
|
|
11207
|
+
if (cheatCount > 0) {
|
|
11208
|
+
return { tier: "critical", reason: `${cheatCount} diff-cheat / invariant-loss finding(s)` };
|
|
11209
|
+
}
|
|
11210
|
+
if (CRITICAL_PATH.test(file)) {
|
|
11211
|
+
return { tier: "critical", reason: "high-stakes boundary (security, schema, CI, contract, or strictness config)" };
|
|
11212
|
+
}
|
|
11213
|
+
if (workaroundCount > 0) {
|
|
11214
|
+
return { tier: "critical", reason: `${workaroundCount} workaround/fallback signal(s) added` };
|
|
11215
|
+
}
|
|
11216
|
+
if (LOCK_OR_GENERATED.test(file)) {
|
|
11217
|
+
return { tier: "low", reason: "lockfile or generated artifact" };
|
|
11218
|
+
}
|
|
11219
|
+
if (DOC_FILE.test(file)) {
|
|
11220
|
+
return { tier: "low", reason: "documentation / prose" };
|
|
11221
|
+
}
|
|
11222
|
+
if (isTestFilePath(file)) {
|
|
11223
|
+
return { tier: "verify", reason: "test oracle / verification suite" };
|
|
11224
|
+
}
|
|
11225
|
+
return { tier: "core", reason: "production logic" };
|
|
11226
|
+
}
|
|
11227
|
+
function collectWorkaroundSignals(repoRoot, baseRef) {
|
|
11228
|
+
const diff = spawnSync7("git", ["-C", repoRoot, "diff", baseRef, "--unified=0", "--no-color"], {
|
|
11229
|
+
encoding: "utf8"
|
|
11230
|
+
});
|
|
11231
|
+
if (diff.status !== 0)
|
|
11232
|
+
return [];
|
|
11233
|
+
const signals = [];
|
|
11234
|
+
let currentFile = "";
|
|
11235
|
+
let currentLine = 1;
|
|
11236
|
+
for (const raw of diff.stdout.split(/\r?\n/)) {
|
|
11237
|
+
if (raw.startsWith("+++ b/")) {
|
|
11238
|
+
currentFile = raw.slice(6);
|
|
11239
|
+
continue;
|
|
11240
|
+
}
|
|
11241
|
+
const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)/.exec(raw);
|
|
11242
|
+
if (hunk) {
|
|
11243
|
+
currentLine = Number(hunk[1]);
|
|
11244
|
+
continue;
|
|
11245
|
+
}
|
|
11246
|
+
if (!raw.startsWith("+") || raw.startsWith("+++"))
|
|
11247
|
+
continue;
|
|
11248
|
+
const added = raw.slice(1);
|
|
11249
|
+
if (!DOC_FILE.test(currentFile) && !LOCK_OR_GENERATED.test(currentFile) && !isTestFilePath(currentFile)) {
|
|
11250
|
+
if (WORKAROUND_MARKER.test(added)) {
|
|
11251
|
+
signals.push({ file: currentFile, line: currentLine, signal: "workaround-marker" });
|
|
11252
|
+
} else if (FALLBACK_SWALLOW_CATCH.test(added)) {
|
|
11253
|
+
signals.push({ file: currentFile, line: currentLine, signal: "fallback-swallow-catch" });
|
|
11254
|
+
}
|
|
11255
|
+
}
|
|
11256
|
+
currentLine += 1;
|
|
11257
|
+
}
|
|
11258
|
+
return signals;
|
|
11259
|
+
}
|
|
11260
|
+
function buildBlindSpots(files, docLinesAdded, additionBias) {
|
|
11261
|
+
const spots = [
|
|
11262
|
+
"Static gates and agent reviews verify mechanics, not whether this change solves the right user problem."
|
|
11263
|
+
];
|
|
11264
|
+
if (files.some((f) => f.tier === "critical")) {
|
|
11265
|
+
spots.push("High-stakes paths changed: verify business intent, threat assumptions, and rollback safety by hand.");
|
|
11266
|
+
}
|
|
11267
|
+
if (additionBias) {
|
|
11268
|
+
spots.push("Diff is heavily additive: check whether existing code could be simplified or deleted instead of layered on.");
|
|
11269
|
+
}
|
|
11270
|
+
if (docLinesAdded > 0) {
|
|
11271
|
+
spots.push("Prose/docs were added: verify every paragraph earns the reader's time and reflects real code.");
|
|
11272
|
+
}
|
|
11273
|
+
if (files.some((f) => f.tier === "verify")) {
|
|
11274
|
+
spots.push("Tests were modified: confirm oracles come from an independent spec and failed before the fix.");
|
|
11275
|
+
}
|
|
11276
|
+
return spots;
|
|
11277
|
+
}
|
|
11278
|
+
function buildReviewBrief(repoPath, options = {}) {
|
|
11279
|
+
const repoRoot = path19.resolve(repoPath);
|
|
11280
|
+
const baseRef = options.baseRef ?? "HEAD";
|
|
11281
|
+
validateBaseRef(baseRef);
|
|
11282
|
+
const maxLines = options.maxLines ?? 600;
|
|
11283
|
+
const maxDirs = options.maxDirs ?? 8;
|
|
11284
|
+
const maxDocLines = options.maxDocLines ?? 250;
|
|
11285
|
+
const numstat = spawnSync7("git", ["-C", repoRoot, "diff", baseRef, "--numstat", "--no-renames"], {
|
|
11286
|
+
encoding: "utf8"
|
|
11287
|
+
});
|
|
11288
|
+
if (numstat.status !== 0) {
|
|
11289
|
+
throw new Error(`git diff failed for base "${baseRef}": ${(numstat.stderr ?? "").trim()}`);
|
|
11290
|
+
}
|
|
11291
|
+
const cheatFindings = scanGitDiffCheats(repoRoot, baseRef);
|
|
11292
|
+
const workaroundSignals = collectWorkaroundSignals(repoRoot, baseRef);
|
|
11293
|
+
const cheatsByFile = new Map;
|
|
11294
|
+
for (const f of cheatFindings) {
|
|
11295
|
+
cheatsByFile.set(f.file, (cheatsByFile.get(f.file) ?? 0) + 1);
|
|
11296
|
+
}
|
|
11297
|
+
const workaroundsByFile = new Map;
|
|
11298
|
+
for (const w of workaroundSignals) {
|
|
11299
|
+
workaroundsByFile.set(w.file, (workaroundsByFile.get(w.file) ?? 0) + 1);
|
|
11300
|
+
}
|
|
11301
|
+
const items = [];
|
|
11302
|
+
const dirs = new Set;
|
|
11303
|
+
let linesAdded = 0;
|
|
11304
|
+
let linesDeleted = 0;
|
|
11305
|
+
let nonLockfileLinesAdded = 0;
|
|
11306
|
+
let docLinesAdded = 0;
|
|
11307
|
+
for (const line of numstat.stdout.split(/\r?\n/)) {
|
|
11308
|
+
if (!line.trim())
|
|
11309
|
+
continue;
|
|
11310
|
+
const [rawAdd, rawDel, ...restPath] = line.split("\t");
|
|
11311
|
+
const file = restPath.join("\t").trim();
|
|
11312
|
+
if (!file)
|
|
11313
|
+
continue;
|
|
11314
|
+
const added = rawAdd === "-" ? 0 : Number(rawAdd) || 0;
|
|
11315
|
+
const deleted = rawDel === "-" ? 0 : Number(rawDel) || 0;
|
|
11316
|
+
linesAdded += added;
|
|
11317
|
+
linesDeleted += deleted;
|
|
11318
|
+
if (!LOCK_OR_GENERATED.test(file)) {
|
|
11319
|
+
nonLockfileLinesAdded += added;
|
|
11320
|
+
const dir = path19.posix.dirname(file);
|
|
11321
|
+
dirs.add(dir === "." ? "<root>" : dir);
|
|
11322
|
+
}
|
|
11323
|
+
if (DOC_FILE.test(file))
|
|
11324
|
+
docLinesAdded += added;
|
|
11325
|
+
const cheatCount = cheatsByFile.get(file) ?? 0;
|
|
11326
|
+
const workaroundCount = workaroundsByFile.get(file) ?? 0;
|
|
11327
|
+
const classified = classifyFileStakes(file, cheatCount, workaroundCount);
|
|
11328
|
+
items.push({
|
|
11329
|
+
file,
|
|
11330
|
+
tier: classified.tier,
|
|
11331
|
+
added,
|
|
11332
|
+
deleted,
|
|
11333
|
+
reason: classified.reason,
|
|
11334
|
+
cheatCount
|
|
11335
|
+
});
|
|
11336
|
+
}
|
|
11337
|
+
items.sort((a, b) => {
|
|
11338
|
+
const tierDiff = TIER_ORDER[a.tier] - TIER_ORDER[b.tier];
|
|
11339
|
+
if (tierDiff !== 0)
|
|
11340
|
+
return tierDiff;
|
|
11341
|
+
return b.added + b.deleted - (a.added + a.deleted);
|
|
11342
|
+
});
|
|
11343
|
+
const totalChurn = linesAdded + linesDeleted;
|
|
11344
|
+
const deletionRatio = totalChurn > 0 ? Number((linesDeleted / totalChurn).toFixed(3)) : 0;
|
|
11345
|
+
const dirsTouched = dirs.size;
|
|
11346
|
+
const additionBias = nonLockfileLinesAdded >= 300 && deletionRatio < 0.05 && items.length >= 5;
|
|
11347
|
+
const budgetBreaches = [];
|
|
11348
|
+
if (cheatFindings.length > 0) {
|
|
11349
|
+
budgetBreaches.push({
|
|
11350
|
+
rule: "review-budget-diff-cheats",
|
|
11351
|
+
actual: cheatFindings.length,
|
|
11352
|
+
limit: 0,
|
|
11353
|
+
message: `${cheatFindings.length} anti-cheat / dropped-invariant violation(s) found in diff.`,
|
|
11354
|
+
fix: "Resolve every diff-cheats finding before requesting human review."
|
|
11355
|
+
});
|
|
11356
|
+
}
|
|
11357
|
+
if (nonLockfileLinesAdded > maxLines) {
|
|
11358
|
+
budgetBreaches.push({
|
|
11359
|
+
rule: "review-budget-diff-size",
|
|
11360
|
+
actual: nonLockfileLinesAdded,
|
|
11361
|
+
limit: maxLines,
|
|
11362
|
+
message: `Diff adds ${nonLockfileLinesAdded} non-lockfile lines (review budget: <= ${maxLines}).`,
|
|
11363
|
+
fix: "Split into stacked, independently reviewable PRs or delete redundant code before asking for review."
|
|
11364
|
+
});
|
|
11365
|
+
}
|
|
11366
|
+
if (dirsTouched > maxDirs) {
|
|
11367
|
+
budgetBreaches.push({
|
|
11368
|
+
rule: "review-budget-shotgun-spread",
|
|
11369
|
+
actual: dirsTouched,
|
|
11370
|
+
limit: maxDirs,
|
|
11371
|
+
message: `Diff scatters changes across ${dirsTouched} directories (budget: <= ${maxDirs}).`,
|
|
11372
|
+
fix: "Isolate unrelated refactors or consolidate leaky abstractions into a deeper module."
|
|
11373
|
+
});
|
|
11374
|
+
}
|
|
11375
|
+
if (docLinesAdded > maxDocLines) {
|
|
11376
|
+
budgetBreaches.push({
|
|
11377
|
+
rule: "review-budget-doc-dump",
|
|
11378
|
+
actual: docLinesAdded,
|
|
11379
|
+
limit: maxDocLines,
|
|
11380
|
+
message: `Diff adds ${docLinesAdded} lines of prose/docs (budget: <= ${maxDocLines}).`,
|
|
11381
|
+
fix: "Trim AI-generated prose so every line respects the reader's time."
|
|
11382
|
+
});
|
|
11383
|
+
}
|
|
11384
|
+
if (additionBias) {
|
|
11385
|
+
budgetBreaches.push({
|
|
11386
|
+
rule: "review-budget-addition-bias",
|
|
11387
|
+
actual: Math.round(deletionRatio * 100),
|
|
11388
|
+
limit: 5,
|
|
11389
|
+
message: `Heavily additive diff (+${nonLockfileLinesAdded}/-${linesDeleted}, ${(deletionRatio * 100).toFixed(1)}% deletions across ${items.length} files).`,
|
|
11390
|
+
fix: "Check for workarounds or parallel wrappers that should replace or delete existing code instead."
|
|
11391
|
+
});
|
|
11392
|
+
}
|
|
11393
|
+
if (workaroundSignals.length > 0) {
|
|
11394
|
+
budgetBreaches.push({
|
|
11395
|
+
rule: "review-budget-workarounds",
|
|
11396
|
+
actual: workaroundSignals.length,
|
|
11397
|
+
limit: 0,
|
|
11398
|
+
message: `Added ${workaroundSignals.length} workaround/fallback-swallow signal(s) in production diff.`,
|
|
11399
|
+
fix: "Fix the root cause instead of layering HACK/WORKAROUND markers or silent fallback catches."
|
|
11400
|
+
});
|
|
11401
|
+
}
|
|
11402
|
+
return {
|
|
11403
|
+
schemaVersion: 1,
|
|
11404
|
+
repo: repoRoot,
|
|
11405
|
+
baseRef,
|
|
11406
|
+
passed: budgetBreaches.length === 0,
|
|
11407
|
+
metrics: {
|
|
11408
|
+
filesChanged: items.length,
|
|
11409
|
+
dirsTouched,
|
|
11410
|
+
linesAdded,
|
|
11411
|
+
linesDeleted,
|
|
11412
|
+
netLines: linesAdded - linesDeleted,
|
|
11413
|
+
nonLockfileLinesAdded,
|
|
11414
|
+
docLinesAdded,
|
|
11415
|
+
deletionRatio
|
|
11416
|
+
},
|
|
11417
|
+
budgets: { maxLines, maxDirs, maxDocLines },
|
|
11418
|
+
budgetBreaches,
|
|
11419
|
+
cheatFindings,
|
|
11420
|
+
workaroundSignals,
|
|
11421
|
+
reviewQueue: {
|
|
11422
|
+
mustReview: items.filter((i) => i.tier === "critical"),
|
|
11423
|
+
coreLogic: items.filter((i) => i.tier === "core"),
|
|
11424
|
+
verifyOracles: items.filter((i) => i.tier === "verify"),
|
|
11425
|
+
lowStakes: items.filter((i) => i.tier === "low")
|
|
11426
|
+
},
|
|
11427
|
+
blindSpots: buildBlindSpots(items, docLinesAdded, additionBias),
|
|
11428
|
+
ownershipChecklist: [
|
|
11429
|
+
"Problem & prior art understood before generation (no unreviewed first-draft pass-through).",
|
|
11430
|
+
"High-stakes slice (Must-Review queue above) verified directly by a human owner.",
|
|
11431
|
+
"Prefer subtraction: confirmed no workaround or parallel layer could be deleted/simplified.",
|
|
11432
|
+
"AI-authored code/docs explicitly disclosed and checked where stakes are highest."
|
|
11433
|
+
]
|
|
11434
|
+
};
|
|
11435
|
+
}
|
|
11436
|
+
function formatReviewBriefTerminal(report) {
|
|
11437
|
+
const m = report.metrics;
|
|
11438
|
+
const out = [];
|
|
11439
|
+
out.push(`Review Brief (${report.baseRef}) — ${report.passed ? "WITHIN BUDGET" : "OVER REVIEW BUDGET"}`);
|
|
11440
|
+
out.push(`Scope: ${m.filesChanged} file(s) across ${m.dirsTouched} dir(s) | +${m.linesAdded} / -${m.linesDeleted} (net ${m.netLines >= 0 ? "+" : ""}${m.netLines}, deletion ratio ${(m.deletionRatio * 100).toFixed(1)}%) | docs +${m.docLinesAdded}`);
|
|
11441
|
+
if (report.budgetBreaches.length > 0) {
|
|
11442
|
+
out.push("");
|
|
11443
|
+
out.push(`SLOP-ASYMMETRY & BUDGET BREACHES (${report.budgetBreaches.length})`);
|
|
11444
|
+
for (const b of report.budgetBreaches) {
|
|
11445
|
+
out.push(` - [${b.rule}] ${b.message}`);
|
|
11446
|
+
out.push(` Fix: ${b.fix}`);
|
|
11447
|
+
}
|
|
11448
|
+
}
|
|
11449
|
+
const emitGroup = (label, items, cap) => {
|
|
11450
|
+
if (items.length === 0)
|
|
11451
|
+
return;
|
|
11452
|
+
out.push("");
|
|
11453
|
+
out.push(`${label} (${items.length})`);
|
|
11454
|
+
for (const item of items.slice(0, cap)) {
|
|
11455
|
+
out.push(` - ${item.file} (+${item.added}/-${item.deleted}) — ${item.reason}`);
|
|
11456
|
+
}
|
|
11457
|
+
if (items.length > cap)
|
|
11458
|
+
out.push(` ... and ${items.length - cap} more`);
|
|
11459
|
+
};
|
|
11460
|
+
emitGroup("MUST REVIEW FIRST (HIGH STAKES)", report.reviewQueue.mustReview, 15);
|
|
11461
|
+
emitGroup("CORE LOGIC", report.reviewQueue.coreLogic, 12);
|
|
11462
|
+
emitGroup("TEST ORACLES", report.reviewQueue.verifyOracles, 8);
|
|
11463
|
+
emitGroup("LOW STAKES / MECHANICAL", report.reviewQueue.lowStakes, 6);
|
|
11464
|
+
out.push("");
|
|
11465
|
+
out.push("WHERE AUTOMATED CHECKS ARE BLIND (HUMAN JUDGMENT REQUIRED)");
|
|
11466
|
+
for (const spot of report.blindSpots)
|
|
11467
|
+
out.push(` - ${spot}`);
|
|
11468
|
+
return out.join(`
|
|
11469
|
+
`);
|
|
11470
|
+
}
|
|
11471
|
+
function formatReviewBriefMarkdown(report) {
|
|
11472
|
+
const m = report.metrics;
|
|
11473
|
+
const out = [];
|
|
11474
|
+
out.push(`## Human Review Brief (\`${report.baseRef}\`) — ${report.passed ? "Within Budget" : "Attention Required"}`);
|
|
11475
|
+
out.push("");
|
|
11476
|
+
out.push(`- **Diff Shape:** ${m.filesChanged} files · ${m.dirsTouched} dirs · \`+${m.linesAdded} / -${m.linesDeleted}\` (deletion ratio \`${(m.deletionRatio * 100).toFixed(1)}%\`) · docs \`+${m.docLinesAdded}\``);
|
|
11477
|
+
if (report.budgetBreaches.length > 0) {
|
|
11478
|
+
out.push("");
|
|
11479
|
+
out.push("### Slop-Asymmetry Warnings");
|
|
11480
|
+
for (const b of report.budgetBreaches) {
|
|
11481
|
+
out.push(`- **\`${b.rule}\`**: ${b.message} *Fix:* ${b.fix}`);
|
|
11482
|
+
}
|
|
11483
|
+
}
|
|
11484
|
+
const topFocus = [...report.reviewQueue.mustReview, ...report.reviewQueue.coreLogic].slice(0, 12);
|
|
11485
|
+
if (topFocus.length > 0) {
|
|
11486
|
+
out.push("");
|
|
11487
|
+
out.push("### Highest-Stakes Files to Read First");
|
|
11488
|
+
out.push("| Priority | File | Churn | Why |");
|
|
11489
|
+
out.push("| :---: | :--- | :---: | :--- |");
|
|
11490
|
+
for (const f of topFocus) {
|
|
11491
|
+
out.push(`| \`${f.tier}\` | \`${f.file}\` | \`+${f.added}/-${f.deleted}\` | ${f.reason} |`);
|
|
11492
|
+
}
|
|
11493
|
+
}
|
|
11494
|
+
out.push("");
|
|
11495
|
+
out.push("### Where Linters & Tests Are Blind");
|
|
11496
|
+
for (const spot of report.blindSpots)
|
|
11497
|
+
out.push(`- ${spot}`);
|
|
11498
|
+
out.push("");
|
|
11499
|
+
out.push("### Human Ownership Checklist");
|
|
11500
|
+
for (const item of report.ownershipChecklist)
|
|
11501
|
+
out.push(`- [ ] ${item}`);
|
|
11502
|
+
return out.join(`
|
|
11503
|
+
`);
|
|
11504
|
+
}
|
|
11505
|
+
|
|
11028
11506
|
// src/cli.ts
|
|
11029
11507
|
var VALID_PROVIDERS = new Set(["laya", "jev", "local", "command", "fixture"]);
|
|
11030
11508
|
var VALID_CIRCUITS = new Set([
|
|
@@ -11042,6 +11520,7 @@ function usage() {
|
|
|
11042
11520
|
" vstack no-comments [dir] [--json] [--fail]",
|
|
11043
11521
|
" vstack state-machines [dir] [--json] [--fail]",
|
|
11044
11522
|
" vstack diff-cheats [dir] [--base <ref>] [--json] [--fail]",
|
|
11523
|
+
" vstack review-brief [dir] [--base <ref>] [--max-lines <n>] [--max-dirs <n>] [--max-doc-lines <n>] [--json | --md] [--fail]",
|
|
11045
11524
|
" vstack formal-sync [dir] [--json] [--fail]",
|
|
11046
11525
|
" vstack laws [dir] [--verify] [--json] [--fail]",
|
|
11047
11526
|
" vstack bench [dir] [--corpus <dir>] [--replay <dir>] [--json] [--fail]",
|
|
@@ -11066,6 +11545,9 @@ function firstPositional(args) {
|
|
|
11066
11545
|
const valueFlags = new Set([
|
|
11067
11546
|
"--base",
|
|
11068
11547
|
"--max",
|
|
11548
|
+
"--max-lines",
|
|
11549
|
+
"--max-dirs",
|
|
11550
|
+
"--max-doc-lines",
|
|
11069
11551
|
"--corroborate",
|
|
11070
11552
|
"--provider",
|
|
11071
11553
|
"--endpoint",
|
|
@@ -11127,12 +11609,12 @@ async function run() {
|
|
|
11127
11609
|
const updateRatchet = rest.includes("--update-ratchet");
|
|
11128
11610
|
let ratchetEval;
|
|
11129
11611
|
if (ratchetPath) {
|
|
11130
|
-
if (updateRatchet || !
|
|
11612
|
+
if (updateRatchet || !fs10.existsSync(ratchetPath)) {
|
|
11131
11613
|
const nextBaseline = buildRatchetBaseline(report.findings);
|
|
11132
11614
|
writeRatchetBaseline(ratchetPath, nextBaseline);
|
|
11133
11615
|
ratchetEval = evaluateRatchet(report.findings, nextBaseline);
|
|
11134
11616
|
} else {
|
|
11135
|
-
const baseline = JSON.parse(
|
|
11617
|
+
const baseline = JSON.parse(fs10.readFileSync(ratchetPath, "utf8"));
|
|
11136
11618
|
ratchetEval = evaluateRatchet(report.findings, baseline);
|
|
11137
11619
|
}
|
|
11138
11620
|
}
|
|
@@ -11213,6 +11695,25 @@ RATCHET (${ratchetPath}): ${ratchetEval.passed ? "PASS" : "FAIL"}`);
|
|
|
11213
11695
|
console.log(formatFindingsList(`diff-cheats (${baseRef})`, findings, asJson));
|
|
11214
11696
|
return rest.includes("--fail") && findings.length > 0 ? 1 : 0;
|
|
11215
11697
|
}
|
|
11698
|
+
if (cmd === "review-brief") {
|
|
11699
|
+
const baseRef = parseFlagValue(rest, "--base") ?? "HEAD";
|
|
11700
|
+
const maxLinesRaw = parseFlagValue(rest, "--max-lines");
|
|
11701
|
+
const maxDirsRaw = parseFlagValue(rest, "--max-dirs");
|
|
11702
|
+
const maxDocRaw = parseFlagValue(rest, "--max-doc-lines");
|
|
11703
|
+
const report = buildReviewBrief(target, {
|
|
11704
|
+
baseRef,
|
|
11705
|
+
maxLines: maxLinesRaw ? Number(maxLinesRaw) : undefined,
|
|
11706
|
+
maxDirs: maxDirsRaw ? Number(maxDirsRaw) : undefined,
|
|
11707
|
+
maxDocLines: maxDocRaw ? Number(maxDocRaw) : undefined
|
|
11708
|
+
});
|
|
11709
|
+
if (asJson)
|
|
11710
|
+
console.log(JSON.stringify(report, null, 2));
|
|
11711
|
+
else if (asMd)
|
|
11712
|
+
console.log(formatReviewBriefMarkdown(report));
|
|
11713
|
+
else
|
|
11714
|
+
console.log(formatReviewBriefTerminal(report));
|
|
11715
|
+
return rest.includes("--fail") && !report.passed ? 1 : 0;
|
|
11716
|
+
}
|
|
11216
11717
|
if (cmd === "classify") {
|
|
11217
11718
|
const maxRaw = parseFlagValue(rest, "--max");
|
|
11218
11719
|
const maxCandidates = maxRaw ? Number(maxRaw) : 30;
|
|
@@ -11229,7 +11730,7 @@ RATCHET (${ratchetPath}): ${ratchetEval.passed ? "PASS" : "FAIL"}`);
|
|
|
11229
11730
|
});
|
|
11230
11731
|
packet = { ...corroborateSystem1Batch(packet, answers), provider };
|
|
11231
11732
|
} else if (corroboratePath) {
|
|
11232
|
-
const answers = JSON.parse(
|
|
11733
|
+
const answers = JSON.parse(fs10.readFileSync(corroboratePath, "utf8"));
|
|
11233
11734
|
packet = corroborateSystem1Batch(packet, answers);
|
|
11234
11735
|
}
|
|
11235
11736
|
if (rest.includes("--emit-requests")) {
|
|
@@ -11320,7 +11821,7 @@ RATCHET (${ratchetPath}): ${ratchetEval.passed ? "PASS" : "FAIL"}`);
|
|
|
11320
11821
|
const metricsPath = rest.find((a) => !a.startsWith("-"));
|
|
11321
11822
|
if (!metricsPath)
|
|
11322
11823
|
throw new Error("vstack spc requires a JSON metrics file ({ metric, upperSpecLimit, values }).");
|
|
11323
|
-
const parsed = JSON.parse(
|
|
11824
|
+
const parsed = JSON.parse(fs10.readFileSync(metricsPath, "utf8"));
|
|
11324
11825
|
const result = evaluateSpcSeries(parsed.metric, parsed.values, parsed.upperSpecLimit);
|
|
11325
11826
|
if (asJson)
|
|
11326
11827
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -11336,7 +11837,7 @@ RATCHET (${ratchetPath}): ${ratchetEval.passed ? "PASS" : "FAIL"}`);
|
|
|
11336
11837
|
if (!samplesPath) {
|
|
11337
11838
|
throw new Error("vstack big-o requires a JSON samples file ({ samples: [{ n, timeMs, memoryBytes? }], maxTimeExponent? }).");
|
|
11338
11839
|
}
|
|
11339
|
-
const parsed = JSON.parse(
|
|
11840
|
+
const parsed = JSON.parse(fs10.readFileSync(samplesPath, "utf8"));
|
|
11340
11841
|
const maxTimeRaw = parseFlagValue(rest, "--max-time-exp");
|
|
11341
11842
|
const maxSpaceRaw = parseFlagValue(rest, "--max-space-exp");
|
|
11342
11843
|
const result = fitEmpiricalBigO(parsed.samples, {
|
|
@@ -11358,18 +11859,18 @@ RATCHET (${ratchetPath}): ${ratchetEval.passed ? "PASS" : "FAIL"}`);
|
|
|
11358
11859
|
if (!tracesPath || tracesPath === ".") {
|
|
11359
11860
|
throw new Error("vstack invariants requires a JSON traces file ({ samples: [{ fn, args?, result?, throws? }] }).");
|
|
11360
11861
|
}
|
|
11361
|
-
const parsed = JSON.parse(
|
|
11862
|
+
const parsed = JSON.parse(fs10.readFileSync(tracesPath, "utf8"));
|
|
11362
11863
|
const samples = Array.isArray(parsed) ? parsed : parsed.samples ?? [];
|
|
11363
11864
|
const current = inferDynamicInvariants(samples);
|
|
11364
11865
|
const baselinePath = parseFlagValue(rest, "--baseline");
|
|
11365
11866
|
const update = rest.includes("--update");
|
|
11366
11867
|
let diff;
|
|
11367
11868
|
if (baselinePath) {
|
|
11368
|
-
if (update || !
|
|
11869
|
+
if (update || !fs10.existsSync(baselinePath)) {
|
|
11369
11870
|
writeInvariantSnapshot(baselinePath, current);
|
|
11370
11871
|
diff = compareInvariantSnapshots(current, current, baselinePath);
|
|
11371
11872
|
} else {
|
|
11372
|
-
const baseline = JSON.parse(
|
|
11873
|
+
const baseline = JSON.parse(fs10.readFileSync(baselinePath, "utf8"));
|
|
11373
11874
|
diff = compareInvariantSnapshots(baseline, current, baselinePath);
|
|
11374
11875
|
}
|
|
11375
11876
|
}
|
|
@@ -11384,8 +11885,10 @@ RATCHET (${ratchetPath}): ${ratchetEval.passed ? "PASS" : "FAIL"}`);
|
|
|
11384
11885
|
console.error(usage());
|
|
11385
11886
|
return 2;
|
|
11386
11887
|
}
|
|
11387
|
-
run().then((code) =>
|
|
11888
|
+
run().then((code) => {
|
|
11889
|
+
process.exitCode = code;
|
|
11890
|
+
}).catch((err) => {
|
|
11388
11891
|
const message = err instanceof Error ? err.message : String(err);
|
|
11389
11892
|
console.error(`vstack error: ${message}`);
|
|
11390
|
-
process.
|
|
11893
|
+
process.exitCode = 1;
|
|
11391
11894
|
});
|