aislop 0.9.4 → 0.9.6
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 +50 -3
- package/dist/cli.js +1046 -62
- package/dist/{version-C45P3Q1N.js → engine-info-DCvIfZ0f.js} +1 -5
- package/dist/index.d.ts +6 -0
- package/dist/index.js +770 -51
- package/dist/{json-CXiEvR_M.js → json-CxiErSgX.js} +2 -1
- package/dist/mcp.js +665 -39
- package/dist/sarif-CLVijBAO.js +60 -0
- package/dist/sarif-CZVuavf_.js +61 -0
- package/dist/version-CPpO6jbj.js +5 -0
- package/package.json +3 -2
- package/scripts/gen-config-schema.mjs +35 -0
- /package/dist/{expo-doctor-Bz0LZhQ6.js → expo-doctor-BcIkOte5.js} +0 -0
- /package/dist/{generic-BrcWMW7E.js → generic-D_T4cUaC.js} +0 -0
- /package/dist/{typecheck-XJMuCczG.js → typecheck-DQSzG8fX.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as getEngineLabel, t as ENGINE_INFO } from "./engine-info-DCvIfZ0f.js";
|
|
2
2
|
import { n as runSubprocess, t as isToolInstalled } from "./subprocess-CQUJDGgn.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { t as APP_VERSION } from "./version-CPpO6jbj.js";
|
|
4
|
+
import { r as runGenericLinter, t as fixRubyLint } from "./generic-D_T4cUaC.js";
|
|
5
|
+
import { n as runExpoDoctor } from "./expo-doctor-BcIkOte5.js";
|
|
5
6
|
import { createRequire, isBuiltin } from "node:module";
|
|
6
7
|
import fs from "node:fs";
|
|
7
8
|
import path from "node:path";
|
|
@@ -13,8 +14,8 @@ import { spawnSync } from "node:child_process";
|
|
|
13
14
|
import micromatch from "micromatch";
|
|
14
15
|
import { fileURLToPath } from "node:url";
|
|
15
16
|
import { performance } from "node:perf_hooks";
|
|
16
|
-
import os from "node:os";
|
|
17
17
|
import ts from "typescript";
|
|
18
|
+
import os from "node:os";
|
|
18
19
|
import { randomUUID } from "node:crypto";
|
|
19
20
|
import { isCancel, multiselect, select, text } from "@clack/prompts";
|
|
20
21
|
|
|
@@ -67,7 +68,8 @@ const DEFAULT_CONFIG = {
|
|
|
67
68
|
failBelow: 70,
|
|
68
69
|
format: "json"
|
|
69
70
|
},
|
|
70
|
-
telemetry: { enabled: true }
|
|
71
|
+
telemetry: { enabled: true },
|
|
72
|
+
rules: {}
|
|
71
73
|
};
|
|
72
74
|
const GITHUB_WORKFLOW_DIR = ".github/workflows";
|
|
73
75
|
const GITHUB_WORKFLOW_FILE = "aislop.yml";
|
|
@@ -194,6 +196,12 @@ const CiSchema = z.object({
|
|
|
194
196
|
format: z.enum(["json"]).default("json")
|
|
195
197
|
});
|
|
196
198
|
const TelemetrySchema = z.object({ enabled: z.boolean().default(true) });
|
|
199
|
+
const RuleSeverityOverride = z.enum([
|
|
200
|
+
"error",
|
|
201
|
+
"warning",
|
|
202
|
+
"off"
|
|
203
|
+
]);
|
|
204
|
+
const RulesSchema = z.record(z.string(), RuleSeverityOverride).default(() => ({}));
|
|
197
205
|
const AislopConfigSchema = z.object({
|
|
198
206
|
version: z.number().default(1),
|
|
199
207
|
engines: EnginesSchema.default(() => ({
|
|
@@ -228,6 +236,7 @@ const AislopConfigSchema = z.object({
|
|
|
228
236
|
format: "json"
|
|
229
237
|
})),
|
|
230
238
|
telemetry: TelemetrySchema.default(() => ({ enabled: true })),
|
|
239
|
+
rules: RulesSchema,
|
|
231
240
|
exclude: z.array(z.string()).default(() => [
|
|
232
241
|
"node_modules",
|
|
233
242
|
".git",
|
|
@@ -544,7 +553,7 @@ const padStart = (s, target, fill = " ") => {
|
|
|
544
553
|
//#endregion
|
|
545
554
|
//#region src/utils/source-files.ts
|
|
546
555
|
const MAX_BUFFER$1 = 50 * 1024 * 1024;
|
|
547
|
-
const SOURCE_EXTENSIONS = new Set([
|
|
556
|
+
const SOURCE_EXTENSIONS$1 = new Set([
|
|
548
557
|
".ts",
|
|
549
558
|
".tsx",
|
|
550
559
|
".js",
|
|
@@ -652,7 +661,7 @@ const toProjectPath = (rootDirectory, filePath) => {
|
|
|
652
661
|
const isWithinProject = (relativePath) => relativePath.length > 0 && !relativePath.startsWith("..");
|
|
653
662
|
const hasAllowedExtension = (filePath, extraExtensions) => {
|
|
654
663
|
const extension = path.extname(filePath);
|
|
655
|
-
return SOURCE_EXTENSIONS.has(extension) || extraExtensions.has(extension);
|
|
664
|
+
return SOURCE_EXTENSIONS$1.has(extension) || extraExtensions.has(extension);
|
|
656
665
|
};
|
|
657
666
|
const isExcludedPath = (filePath) => EXCLUDED_DIRS.some((dir) => filePath === dir || filePath.startsWith(`${dir}/`) || filePath.includes(`/${dir}/`));
|
|
658
667
|
const isExcludedFromScan = (relativePath) => isExcludedPath(relativePath) || isBuildCacheFile(relativePath);
|
|
@@ -1246,7 +1255,7 @@ const doctorCommand = async (directory, options = {}) => {
|
|
|
1246
1255
|
|
|
1247
1256
|
//#endregion
|
|
1248
1257
|
//#region src/engines/ai-slop/abstractions.ts
|
|
1249
|
-
const JS_EXTS$
|
|
1258
|
+
const JS_EXTS$2 = new Set([
|
|
1250
1259
|
".ts",
|
|
1251
1260
|
".tsx",
|
|
1252
1261
|
".js",
|
|
@@ -1257,11 +1266,11 @@ const JS_EXTS$1 = new Set([
|
|
|
1257
1266
|
const THIN_WRAPPER_PATTERNS = [
|
|
1258
1267
|
{
|
|
1259
1268
|
pattern: /(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\([^)]*\)\s*(?::\s*\w[^{]*)?\{\s*\n?\s*return\s+\w+\([^)]*\);\s*\n?\s*\}/g,
|
|
1260
|
-
extensions: JS_EXTS$
|
|
1269
|
+
extensions: JS_EXTS$2
|
|
1261
1270
|
},
|
|
1262
1271
|
{
|
|
1263
1272
|
pattern: /(?:export\s+)?const\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*(?::\s*\w[^=]*)?\s*=>\s*\w+\([^)]*\);/g,
|
|
1264
|
-
extensions: JS_EXTS$
|
|
1273
|
+
extensions: JS_EXTS$2
|
|
1265
1274
|
},
|
|
1266
1275
|
{
|
|
1267
1276
|
pattern: /def\s+(\w+)\s*\([^)]*\)(?:\s*->[^:]*)?:\s*\n\s+return\s+\w+\([^)]*\)\s*$/gm,
|
|
@@ -1494,6 +1503,12 @@ const COMMENTED_CODE_CHARS = /[({=;}\]>]/;
|
|
|
1494
1503
|
const MAX_TRIVIAL_COMMENT_LENGTH = 60;
|
|
1495
1504
|
const isJsComment = (trimmed) => trimmed.startsWith("//") && !trimmed.startsWith("///") && !trimmed.startsWith("//!");
|
|
1496
1505
|
const isPythonComment = (trimmed) => trimmed.startsWith("#") && !trimmed.startsWith("#!");
|
|
1506
|
+
const isLineComment = (trimmed) => isJsComment(trimmed) || isPythonComment(trimmed);
|
|
1507
|
+
const isInMultiLineCommentRun = (lines, index) => {
|
|
1508
|
+
const prev = index > 0 ? lines[index - 1].trim() : "";
|
|
1509
|
+
const next = index + 1 < lines.length ? lines[index + 1].trim() : "";
|
|
1510
|
+
return isLineComment(prev) || isLineComment(next);
|
|
1511
|
+
};
|
|
1497
1512
|
/**
|
|
1498
1513
|
* Extract just the comment text after the comment marker.
|
|
1499
1514
|
*/
|
|
@@ -1546,6 +1561,7 @@ const scanFileForTrivialComments = (content, relativePath, ext) => {
|
|
|
1546
1561
|
const lines = content.split("\n");
|
|
1547
1562
|
for (let i = 0; i < lines.length; i++) {
|
|
1548
1563
|
if (!isTrivialComment(lines[i].trim(), i + 1 < lines.length ? lines[i + 1] : void 0)) continue;
|
|
1564
|
+
if (isInMultiLineCommentRun(lines, i)) continue;
|
|
1549
1565
|
if (isDocCommentForDeclaration(lines, i, ext)) continue;
|
|
1550
1566
|
diagnostics.push({
|
|
1551
1567
|
filePath: relativePath,
|
|
@@ -1707,6 +1723,177 @@ const detectDeadPatterns = async (context) => {
|
|
|
1707
1723
|
return diagnostics;
|
|
1708
1724
|
};
|
|
1709
1725
|
|
|
1726
|
+
//#endregion
|
|
1727
|
+
//#region src/engines/ai-slop/defensive-patterns.ts
|
|
1728
|
+
const JS_TS_EXTENSIONS = new Set([
|
|
1729
|
+
".ts",
|
|
1730
|
+
".tsx",
|
|
1731
|
+
".js",
|
|
1732
|
+
".jsx",
|
|
1733
|
+
".mjs",
|
|
1734
|
+
".cjs"
|
|
1735
|
+
]);
|
|
1736
|
+
const TS_EXTENSIONS = new Set([".ts", ".tsx"]);
|
|
1737
|
+
const COERCION_CTORS = {
|
|
1738
|
+
string: "String",
|
|
1739
|
+
number: "Number",
|
|
1740
|
+
boolean: "Boolean"
|
|
1741
|
+
};
|
|
1742
|
+
const scriptKindFor = (ext) => {
|
|
1743
|
+
switch (ext) {
|
|
1744
|
+
case ".tsx": return ts.ScriptKind.TSX;
|
|
1745
|
+
case ".jsx": return ts.ScriptKind.JSX;
|
|
1746
|
+
case ".js":
|
|
1747
|
+
case ".mjs":
|
|
1748
|
+
case ".cjs": return ts.ScriptKind.JS;
|
|
1749
|
+
default: return ts.ScriptKind.TS;
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
const lineFor = (sourceFile, node) => sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
1753
|
+
const makeDiagnostic = (filePath, line, rule, message, help) => ({
|
|
1754
|
+
filePath,
|
|
1755
|
+
engine: "ai-slop",
|
|
1756
|
+
rule,
|
|
1757
|
+
severity: "warning",
|
|
1758
|
+
message,
|
|
1759
|
+
help,
|
|
1760
|
+
line,
|
|
1761
|
+
column: 0,
|
|
1762
|
+
category: "AI Slop",
|
|
1763
|
+
fixable: false
|
|
1764
|
+
});
|
|
1765
|
+
const isFunctionNode = (node) => ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node);
|
|
1766
|
+
const primitiveKindOf = (node) => {
|
|
1767
|
+
if (!node) return null;
|
|
1768
|
+
switch (node.kind) {
|
|
1769
|
+
case ts.SyntaxKind.StringKeyword: return "string";
|
|
1770
|
+
case ts.SyntaxKind.NumberKeyword: return "number";
|
|
1771
|
+
case ts.SyntaxKind.BooleanKeyword: return "boolean";
|
|
1772
|
+
default: return null;
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
const hasExportModifier = (node) => node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
1776
|
+
const primitiveParamsOf = (node) => {
|
|
1777
|
+
const params = /* @__PURE__ */ new Map();
|
|
1778
|
+
for (const param of node.parameters) {
|
|
1779
|
+
if (!ts.isIdentifier(param.name)) continue;
|
|
1780
|
+
const kind = primitiveKindOf(param.type);
|
|
1781
|
+
if (!kind) continue;
|
|
1782
|
+
params.set(param.name.text, kind);
|
|
1783
|
+
}
|
|
1784
|
+
return params;
|
|
1785
|
+
};
|
|
1786
|
+
const isRethrowStatement = (statement, errorName) => ts.isThrowStatement(statement) && statement.expression !== void 0 && ts.isIdentifier(statement.expression) && statement.expression.text === errorName;
|
|
1787
|
+
const isPromiseRejectRethrow = (statement, errorName) => {
|
|
1788
|
+
if (!ts.isReturnStatement(statement) || !statement.expression) return false;
|
|
1789
|
+
const expression = statement.expression;
|
|
1790
|
+
if (!ts.isCallExpression(expression) || expression.arguments.length !== 1) return false;
|
|
1791
|
+
const [arg] = expression.arguments;
|
|
1792
|
+
if (!ts.isIdentifier(arg) || arg.text !== errorName) return false;
|
|
1793
|
+
if (!ts.isPropertyAccessExpression(expression.expression)) return false;
|
|
1794
|
+
const target = expression.expression;
|
|
1795
|
+
return ts.isIdentifier(target.expression) && target.expression.text === "Promise" && target.name.text === "reject";
|
|
1796
|
+
};
|
|
1797
|
+
const detectRedundantTryCatch = (sourceFile, relativePath) => {
|
|
1798
|
+
const diagnostics = [];
|
|
1799
|
+
const visit = (node) => {
|
|
1800
|
+
if (ts.isTryStatement(node) && node.catchClause && !node.finallyBlock) {
|
|
1801
|
+
const catchNameNode = node.catchClause.variableDeclaration?.name;
|
|
1802
|
+
const [onlyStatement] = node.catchClause.block.statements;
|
|
1803
|
+
if (catchNameNode && ts.isIdentifier(catchNameNode) && node.catchClause.block.statements.length === 1 && onlyStatement && (isRethrowStatement(onlyStatement, catchNameNode.text) || isPromiseRejectRethrow(onlyStatement, catchNameNode.text))) diagnostics.push(makeDiagnostic(relativePath, lineFor(sourceFile, node.catchClause), "ai-slop/redundant-try-catch", "Catch block only rethrows the same error", "Remove the try/catch or add useful context, cleanup, or recovery. Rethrowing unchanged errors is usually defensive agent noise."));
|
|
1804
|
+
}
|
|
1805
|
+
ts.forEachChild(node, visit);
|
|
1806
|
+
};
|
|
1807
|
+
visit(sourceFile);
|
|
1808
|
+
return diagnostics;
|
|
1809
|
+
};
|
|
1810
|
+
const detectPrimitiveCoercions = (sourceFile, relativePath) => {
|
|
1811
|
+
const diagnostics = [];
|
|
1812
|
+
const scanFunctionBody = (node, params) => {
|
|
1813
|
+
const body = node.body;
|
|
1814
|
+
if (!body || params.size === 0) return;
|
|
1815
|
+
const visitBody = (child) => {
|
|
1816
|
+
if (child !== body && isFunctionNode(child)) return;
|
|
1817
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression)) {
|
|
1818
|
+
const [arg] = child.arguments;
|
|
1819
|
+
if (arg && ts.isIdentifier(arg)) {
|
|
1820
|
+
const primitive = params.get(arg.text);
|
|
1821
|
+
if (primitive && child.expression.text === COERCION_CTORS[primitive]) diagnostics.push(makeDiagnostic(relativePath, lineFor(sourceFile, child), "ai-slop/redundant-type-coercion", `Parameter '${arg.text}' is already typed as ${primitive} but is coerced again`, "Trust the typed boundary or validate unknown input before this function. Re-coercing already typed parameters is usually defensive agent noise."));
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
ts.forEachChild(child, visitBody);
|
|
1825
|
+
};
|
|
1826
|
+
visitBody(body);
|
|
1827
|
+
};
|
|
1828
|
+
const visit = (node) => {
|
|
1829
|
+
if (isFunctionNode(node)) scanFunctionBody(node, primitiveParamsOf(node));
|
|
1830
|
+
ts.forEachChild(node, visit);
|
|
1831
|
+
};
|
|
1832
|
+
visit(sourceFile);
|
|
1833
|
+
return diagnostics;
|
|
1834
|
+
};
|
|
1835
|
+
const normalizedTypeDeclaration = (sourceFile, node) => sourceFile.text.slice(node.getStart(sourceFile), node.getEnd()).replace(/\bexport\b/g, "").replace(/\bdeclare\b/g, "").replace(/\s+/g, " ").trim();
|
|
1836
|
+
const exportedTypesOf = (parsed) => {
|
|
1837
|
+
const declarations = [];
|
|
1838
|
+
const visit = (node) => {
|
|
1839
|
+
if ((ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) && hasExportModifier(node)) declarations.push({
|
|
1840
|
+
name: node.name.text,
|
|
1841
|
+
signature: normalizedTypeDeclaration(parsed.sourceFile, node),
|
|
1842
|
+
filePath: parsed.relativePath,
|
|
1843
|
+
line: lineFor(parsed.sourceFile, node)
|
|
1844
|
+
});
|
|
1845
|
+
ts.forEachChild(node, visit);
|
|
1846
|
+
};
|
|
1847
|
+
visit(parsed.sourceFile);
|
|
1848
|
+
return declarations;
|
|
1849
|
+
};
|
|
1850
|
+
const duplicateTypeKeyOf = (declaration) => `${declaration.name}\0${declaration.signature}`;
|
|
1851
|
+
const detectDuplicateExportedTypes = (parsedSources) => {
|
|
1852
|
+
const diagnostics = [];
|
|
1853
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1854
|
+
for (const parsed of parsedSources) {
|
|
1855
|
+
if (!TS_EXTENSIONS.has(parsed.ext)) continue;
|
|
1856
|
+
for (const declaration of exportedTypesOf(parsed)) {
|
|
1857
|
+
const key = duplicateTypeKeyOf(declaration);
|
|
1858
|
+
const previous = seen.get(key);
|
|
1859
|
+
if (!previous) {
|
|
1860
|
+
seen.set(key, declaration);
|
|
1861
|
+
continue;
|
|
1862
|
+
}
|
|
1863
|
+
if (previous.filePath === declaration.filePath) continue;
|
|
1864
|
+
diagnostics.push(makeDiagnostic(declaration.filePath, declaration.line, "ai-slop/duplicate-type-declaration", `Exported type '${declaration.name}' duplicates an existing declaration`, `Reuse or import the existing type from ${previous.filePath} instead of re-declaring the same shape in another file.`));
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
return diagnostics;
|
|
1868
|
+
};
|
|
1869
|
+
const detectDefensivePatterns = async (context) => {
|
|
1870
|
+
const diagnostics = [];
|
|
1871
|
+
const parsedSources = [];
|
|
1872
|
+
for (const filePath of getSourceFiles(context)) {
|
|
1873
|
+
if (isAutoGenerated(filePath)) continue;
|
|
1874
|
+
let content;
|
|
1875
|
+
try {
|
|
1876
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
1877
|
+
} catch {
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
const relativePath = path.relative(context.rootDirectory, filePath);
|
|
1881
|
+
if (isNonProductionPath(relativePath)) continue;
|
|
1882
|
+
const ext = path.extname(filePath);
|
|
1883
|
+
if (!JS_TS_EXTENSIONS.has(ext)) continue;
|
|
1884
|
+
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, scriptKindFor(ext));
|
|
1885
|
+
parsedSources.push({
|
|
1886
|
+
sourceFile,
|
|
1887
|
+
relativePath,
|
|
1888
|
+
ext
|
|
1889
|
+
});
|
|
1890
|
+
diagnostics.push(...detectRedundantTryCatch(sourceFile, relativePath));
|
|
1891
|
+
if (TS_EXTENSIONS.has(ext)) diagnostics.push(...detectPrimitiveCoercions(sourceFile, relativePath));
|
|
1892
|
+
}
|
|
1893
|
+
diagnostics.push(...detectDuplicateExportedTypes(parsedSources));
|
|
1894
|
+
return diagnostics;
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1710
1897
|
//#endregion
|
|
1711
1898
|
//#region src/engines/ai-slop/duplicate-imports.ts
|
|
1712
1899
|
const JS_EXTENSIONS$3 = new Set([
|
|
@@ -1717,7 +1904,16 @@ const JS_EXTENSIONS$3 = new Set([
|
|
|
1717
1904
|
".mjs",
|
|
1718
1905
|
".cjs"
|
|
1719
1906
|
]);
|
|
1720
|
-
const IMPORT_FROM_RE$1 = /^\s*import\s+[^;]*?from\s+["']([^"']+)["']/;
|
|
1907
|
+
const IMPORT_FROM_RE$1 = /^\s*import\s+([^;]*?)\s+from\s+["']([^"']+)["']/;
|
|
1908
|
+
const TYPE_ONLY_RE = /^\s*type\b/;
|
|
1909
|
+
const VALUE_BINDING_RE = /\{([^}]*)\}/;
|
|
1910
|
+
const isTypeOnly = (clause) => {
|
|
1911
|
+
if (TYPE_ONLY_RE.test(clause)) return true;
|
|
1912
|
+
const braces = VALUE_BINDING_RE.exec(clause);
|
|
1913
|
+
if (!braces) return false;
|
|
1914
|
+
const members = braces[1].split(",").map((member) => member.trim()).filter((member) => member.length > 0);
|
|
1915
|
+
return members.length > 0 && members.every((member) => /^type\b/.test(member));
|
|
1916
|
+
};
|
|
1721
1917
|
const extractImportLines = (content) => {
|
|
1722
1918
|
const lines = content.split("\n");
|
|
1723
1919
|
const results = [];
|
|
@@ -1726,8 +1922,9 @@ const extractImportLines = (content) => {
|
|
|
1726
1922
|
const match = IMPORT_FROM_RE$1.exec(line);
|
|
1727
1923
|
if (!match) continue;
|
|
1728
1924
|
results.push({
|
|
1729
|
-
spec: match[
|
|
1730
|
-
line: i + 1
|
|
1925
|
+
spec: match[2],
|
|
1926
|
+
line: i + 1,
|
|
1927
|
+
typeOnly: isTypeOnly(match[1])
|
|
1731
1928
|
});
|
|
1732
1929
|
}
|
|
1733
1930
|
return results;
|
|
@@ -1746,14 +1943,16 @@ const detectDuplicateImports = async (context) => {
|
|
|
1746
1943
|
}
|
|
1747
1944
|
const imports = extractImportLines(content);
|
|
1748
1945
|
if (imports.length < 2) continue;
|
|
1749
|
-
const
|
|
1946
|
+
const byBucket = /* @__PURE__ */ new Map();
|
|
1750
1947
|
for (const imp of imports) {
|
|
1751
|
-
const
|
|
1948
|
+
const key = `${imp.typeOnly ? "type" : "value"}\0${imp.spec}`;
|
|
1949
|
+
const list = byBucket.get(key) ?? [];
|
|
1752
1950
|
list.push(imp);
|
|
1753
|
-
|
|
1951
|
+
byBucket.set(key, list);
|
|
1754
1952
|
}
|
|
1755
1953
|
const relPath = path.relative(context.rootDirectory, filePath);
|
|
1756
|
-
for (const
|
|
1954
|
+
for (const occurrences of byBucket.values()) {
|
|
1955
|
+
const { spec } = occurrences[0];
|
|
1757
1956
|
if (occurrences.length < 2) continue;
|
|
1758
1957
|
for (const dup of occurrences.slice(1)) {
|
|
1759
1958
|
const firstLine = occurrences[0].line;
|
|
@@ -1958,6 +2157,141 @@ const detectGoPatterns = async (context) => {
|
|
|
1958
2157
|
return diagnostics;
|
|
1959
2158
|
};
|
|
1960
2159
|
|
|
2160
|
+
//#endregion
|
|
2161
|
+
//#region src/engines/ai-slop/hardcoded-config.ts
|
|
2162
|
+
const SOURCE_EXTENSIONS = new Set([
|
|
2163
|
+
".ts",
|
|
2164
|
+
".tsx",
|
|
2165
|
+
".js",
|
|
2166
|
+
".jsx",
|
|
2167
|
+
".mjs",
|
|
2168
|
+
".cjs",
|
|
2169
|
+
".py",
|
|
2170
|
+
".go",
|
|
2171
|
+
".rs",
|
|
2172
|
+
".rb",
|
|
2173
|
+
".java",
|
|
2174
|
+
".php"
|
|
2175
|
+
]);
|
|
2176
|
+
const URL_LITERAL_RE = /(["'`])(https?:\/\/[^"'`\s<>]+)\1/g;
|
|
2177
|
+
const ID_LITERAL_RE = /(["'])([A-Za-z][A-Za-z0-9_-]{15,})\1/g;
|
|
2178
|
+
const ENV_REFERENCE_RE = /\b(?:process\.env|import\.meta\.env|Deno\.env|os\.environ|getenv|env\()\b/i;
|
|
2179
|
+
const DOC_URL_CONTEXT_RE = /\b(?:docs?|documentation|homepage|repository|bugs|license|readme|source|svgUrl|pageUrl|href|link|install)\b/i;
|
|
2180
|
+
const URL_CONFIG_CONTEXT_RE = /\b(?:api|base[_-]?url|baseUrl|endpoint|host|origin|webhook|callback|redirect|server|service|domain|url)\b/i;
|
|
2181
|
+
const ENVIRONMENT_HOST_RE = /(?:^|[.-])(?:api|app|admin|auth|staging|stage|prod|dev|sandbox|webhook|internal)(?:[.-]|$)|^(?:localhost|127\.0\.0\.1|0\.0\.0\.0)$/i;
|
|
2182
|
+
const ID_CONTEXT_RE = /(?:^|[^A-Za-z0-9])(?:api[_-]?key|client[_-]?id|project[_-]?id|org(?:anization)?[_-]?id|workspace[_-]?id|tenant[_-]?id|price[_-]?id|product[_-]?id|customer[_-]?id|subscription[_-]?id|account[_-]?id|app[_-]?id|key|token|secret)(?:$|[^A-Za-z0-9])/i;
|
|
2183
|
+
const MIGRATION_PATH_RE$1 = /(?:^|[\\/])(?:migrations?|db[\\/]migrate)[\\/]/i;
|
|
2184
|
+
const PLACEHOLDER_HOSTS = new Set([
|
|
2185
|
+
"example.com",
|
|
2186
|
+
"example.org",
|
|
2187
|
+
"example.net"
|
|
2188
|
+
]);
|
|
2189
|
+
const LOOPBACK_HOSTS = new Set([
|
|
2190
|
+
"localhost",
|
|
2191
|
+
"127.0.0.1",
|
|
2192
|
+
"0.0.0.0",
|
|
2193
|
+
"::1"
|
|
2194
|
+
]);
|
|
2195
|
+
const PLACEHOLDER_ID_RE = /^(?:changeme|replace[_-]?me|your[_-]|example|placeholder|todo)/i;
|
|
2196
|
+
const HARDCODED_URL_FINDING = {
|
|
2197
|
+
rule: "ai-slop/hardcoded-url",
|
|
2198
|
+
message: "Hardcoded environment URL in production code",
|
|
2199
|
+
help: "Move deployment-specific URLs to environment variables or a typed config module. Keep only stable documentation/public links inline."
|
|
2200
|
+
};
|
|
2201
|
+
const HARDCODED_ID_FINDING = {
|
|
2202
|
+
rule: "ai-slop/hardcoded-id",
|
|
2203
|
+
message: "Hardcoded provider/project ID in production code",
|
|
2204
|
+
help: "Move provider IDs, tenant IDs, price IDs, and similar deployment-specific identifiers to env/config so agents do not bake one environment into source."
|
|
2205
|
+
};
|
|
2206
|
+
const makeFinding = (filePath, line, spec) => ({
|
|
2207
|
+
filePath,
|
|
2208
|
+
engine: "ai-slop",
|
|
2209
|
+
rule: spec.rule,
|
|
2210
|
+
severity: "warning",
|
|
2211
|
+
message: spec.message,
|
|
2212
|
+
help: spec.help,
|
|
2213
|
+
line,
|
|
2214
|
+
column: 0,
|
|
2215
|
+
category: "AI Slop",
|
|
2216
|
+
fixable: false
|
|
2217
|
+
});
|
|
2218
|
+
const isCommentOnlyLine = (trimmed) => trimmed.startsWith("//") || trimmed.startsWith("#") || trimmed.startsWith("*") || trimmed.startsWith("/*");
|
|
2219
|
+
const commentStartsBefore = (line, index, ext) => {
|
|
2220
|
+
const prefix = line.slice(0, index);
|
|
2221
|
+
if (ext === ".py" || ext === ".rb") return prefix.includes("#");
|
|
2222
|
+
if (ext === ".php") return prefix.includes("//") || prefix.includes("#");
|
|
2223
|
+
return prefix.includes("//") || prefix.includes("/*");
|
|
2224
|
+
};
|
|
2225
|
+
const safeUrlHost = (urlText) => {
|
|
2226
|
+
try {
|
|
2227
|
+
return new URL(urlText).hostname.toLowerCase();
|
|
2228
|
+
} catch {
|
|
2229
|
+
return null;
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
const isEnvBackedLine = (line) => ENV_REFERENCE_RE.test(line);
|
|
2233
|
+
const shouldFlagUrlLiteral = (line, urlText) => {
|
|
2234
|
+
if (isEnvBackedLine(line)) return false;
|
|
2235
|
+
const host = safeUrlHost(urlText);
|
|
2236
|
+
if (!host) return false;
|
|
2237
|
+
if (PLACEHOLDER_HOSTS.has(host)) return false;
|
|
2238
|
+
if (LOOPBACK_HOSTS.has(host)) return false;
|
|
2239
|
+
if (DOC_URL_CONTEXT_RE.test(line) && !ENVIRONMENT_HOST_RE.test(host)) return false;
|
|
2240
|
+
return URL_CONFIG_CONTEXT_RE.test(line) || ENVIRONMENT_HOST_RE.test(host);
|
|
2241
|
+
};
|
|
2242
|
+
const ENV_VAR_NAME_RE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/;
|
|
2243
|
+
const hasUsefulIdShape = (value) => {
|
|
2244
|
+
if (PLACEHOLDER_ID_RE.test(value)) return false;
|
|
2245
|
+
if (ENV_VAR_NAME_RE.test(value)) return false;
|
|
2246
|
+
if (/^https?:\/\//i.test(value)) return false;
|
|
2247
|
+
if (/^[A-Za-z]+$/.test(value)) return false;
|
|
2248
|
+
return /[0-9]/.test(value);
|
|
2249
|
+
};
|
|
2250
|
+
const scanLineForConfigLiterals = (line, relativePath, ext, lineNumber) => {
|
|
2251
|
+
const diagnostics = [];
|
|
2252
|
+
if (isCommentOnlyLine(line.trim())) return diagnostics;
|
|
2253
|
+
URL_LITERAL_RE.lastIndex = 0;
|
|
2254
|
+
let urlMatch;
|
|
2255
|
+
while ((urlMatch = URL_LITERAL_RE.exec(line)) !== null) {
|
|
2256
|
+
const urlText = urlMatch[2];
|
|
2257
|
+
if (commentStartsBefore(line, urlMatch.index, ext)) continue;
|
|
2258
|
+
if (!shouldFlagUrlLiteral(line, urlText)) continue;
|
|
2259
|
+
diagnostics.push(makeFinding(relativePath, lineNumber, HARDCODED_URL_FINDING));
|
|
2260
|
+
}
|
|
2261
|
+
if (!ID_CONTEXT_RE.test(line) || isEnvBackedLine(line) || DOC_URL_CONTEXT_RE.test(line)) return diagnostics;
|
|
2262
|
+
ID_LITERAL_RE.lastIndex = 0;
|
|
2263
|
+
let idMatch;
|
|
2264
|
+
while ((idMatch = ID_LITERAL_RE.exec(line)) !== null) {
|
|
2265
|
+
const value = idMatch[2];
|
|
2266
|
+
if (commentStartsBefore(line, idMatch.index, ext)) continue;
|
|
2267
|
+
if (!hasUsefulIdShape(value)) continue;
|
|
2268
|
+
diagnostics.push(makeFinding(relativePath, lineNumber, HARDCODED_ID_FINDING));
|
|
2269
|
+
}
|
|
2270
|
+
return diagnostics;
|
|
2271
|
+
};
|
|
2272
|
+
const scanFileForConfigLiterals = (content, relativePath, ext) => {
|
|
2273
|
+
if (!SOURCE_EXTENSIONS.has(ext)) return [];
|
|
2274
|
+
if (isNonProductionPath(relativePath)) return [];
|
|
2275
|
+
if (MIGRATION_PATH_RE$1.test(relativePath)) return [];
|
|
2276
|
+
return content.split("\n").flatMap((line, index) => scanLineForConfigLiterals(line, relativePath, ext, index + 1));
|
|
2277
|
+
};
|
|
2278
|
+
const detectHardcodedConfigLiterals = async (context) => {
|
|
2279
|
+
const diagnostics = [];
|
|
2280
|
+
for (const filePath of getSourceFiles(context)) {
|
|
2281
|
+
if (isAutoGenerated(filePath)) continue;
|
|
2282
|
+
let content;
|
|
2283
|
+
try {
|
|
2284
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
2285
|
+
} catch {
|
|
2286
|
+
continue;
|
|
2287
|
+
}
|
|
2288
|
+
const relativePath = path.relative(context.rootDirectory, filePath);
|
|
2289
|
+
const ext = path.extname(filePath);
|
|
2290
|
+
diagnostics.push(...scanFileForConfigLiterals(content, relativePath, ext));
|
|
2291
|
+
}
|
|
2292
|
+
return diagnostics;
|
|
2293
|
+
};
|
|
2294
|
+
|
|
1961
2295
|
//#endregion
|
|
1962
2296
|
//#region src/engines/ai-slop/js-import-aliases.ts
|
|
1963
2297
|
const TS_CONFIG_FILES = ["tsconfig.json", "jsconfig.json"];
|
|
@@ -2225,23 +2559,88 @@ const PYTHON_STDLIB = new Set([
|
|
|
2225
2559
|
"zoneinfo"
|
|
2226
2560
|
]);
|
|
2227
2561
|
const PYTHON_IMPORT_TO_PIP = {
|
|
2228
|
-
yaml: "pyyaml",
|
|
2229
|
-
PIL: "pillow",
|
|
2230
|
-
dateutil: "python-dateutil",
|
|
2231
|
-
cv2:
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2562
|
+
yaml: ["pyyaml"],
|
|
2563
|
+
PIL: ["pillow"],
|
|
2564
|
+
dateutil: ["python-dateutil"],
|
|
2565
|
+
cv2: [
|
|
2566
|
+
"opencv-python",
|
|
2567
|
+
"opencv-python-headless",
|
|
2568
|
+
"opencv-contrib-python"
|
|
2569
|
+
],
|
|
2570
|
+
sklearn: ["scikit-learn"],
|
|
2571
|
+
bs4: ["beautifulsoup4"],
|
|
2572
|
+
typing_extensions: ["typing-extensions"],
|
|
2573
|
+
dotenv: ["python-dotenv"],
|
|
2574
|
+
genai: ["google-genai"],
|
|
2575
|
+
google: [
|
|
2576
|
+
"google-genai",
|
|
2577
|
+
"google-generativeai",
|
|
2578
|
+
"google-api-python-client",
|
|
2579
|
+
"google-cloud-storage",
|
|
2580
|
+
"google-cloud-aiplatform",
|
|
2581
|
+
"google-auth",
|
|
2582
|
+
"protobuf"
|
|
2583
|
+
],
|
|
2584
|
+
jose: ["python-jose"],
|
|
2585
|
+
jwt: ["pyjwt"],
|
|
2586
|
+
OpenSSL: ["pyopenssl"],
|
|
2587
|
+
Crypto: ["pycryptodome", "pycryptodomex"],
|
|
2588
|
+
Cryptodome: ["pycryptodomex", "pycryptodome"],
|
|
2589
|
+
magic: ["python-magic"],
|
|
2590
|
+
docx: ["python-docx"],
|
|
2591
|
+
pptx: ["python-pptx"],
|
|
2592
|
+
git: ["gitpython"],
|
|
2593
|
+
socks: ["pysocks"],
|
|
2594
|
+
psycopg2: ["psycopg2-binary", "psycopg2"],
|
|
2595
|
+
redis: ["redis"],
|
|
2596
|
+
cairo: ["pycairo"],
|
|
2597
|
+
serial: ["pyserial"],
|
|
2598
|
+
usb: ["pyusb"],
|
|
2599
|
+
gi: ["pygobject"],
|
|
2600
|
+
Xlib: ["python-xlib"],
|
|
2601
|
+
ldap: ["python-ldap"],
|
|
2602
|
+
slugify: ["python-slugify"],
|
|
2603
|
+
memcache: ["python-memcached"],
|
|
2604
|
+
dns: ["dnspython"],
|
|
2605
|
+
attr: ["attrs"],
|
|
2606
|
+
attrs: ["attrs"],
|
|
2607
|
+
zoneinfo_data: ["tzdata"],
|
|
2608
|
+
pkg_resources: ["setuptools"],
|
|
2609
|
+
setuptools: ["setuptools"],
|
|
2610
|
+
wx: ["wxpython"],
|
|
2611
|
+
skimage: ["scikit-image"],
|
|
2612
|
+
OpenGL: ["pyopengl"],
|
|
2613
|
+
win32api: ["pywin32"],
|
|
2614
|
+
win32con: ["pywin32"],
|
|
2615
|
+
win32com: ["pywin32"],
|
|
2616
|
+
pythoncom: ["pywin32"],
|
|
2617
|
+
pywintypes: ["pywin32"],
|
|
2618
|
+
rest_framework: ["djangorestframework"],
|
|
2619
|
+
allauth: ["django-allauth"],
|
|
2620
|
+
corsheaders: ["django-cors-headers"],
|
|
2621
|
+
debug_toolbar: ["django-debug-toolbar"],
|
|
2622
|
+
environ: ["django-environ"],
|
|
2623
|
+
flask_cors: ["flask-cors"],
|
|
2624
|
+
flask_sqlalchemy: ["flask-sqlalchemy"],
|
|
2625
|
+
flask_migrate: ["flask-migrate"],
|
|
2626
|
+
flask_login: ["flask-login"],
|
|
2627
|
+
jwt_extended: ["flask-jwt-extended"],
|
|
2628
|
+
dateparser: ["dateparser"],
|
|
2629
|
+
yaml_include: ["pyyaml-include"],
|
|
2630
|
+
lxml_html_clean: ["lxml-html-clean"],
|
|
2631
|
+
grpc: ["grpcio"],
|
|
2632
|
+
grpc_status: ["grpcio-status"],
|
|
2633
|
+
google_crc32c: ["google-crc32c"],
|
|
2634
|
+
pkg_about: ["pkg-about"],
|
|
2635
|
+
mpl_toolkits: ["matplotlib"],
|
|
2636
|
+
dotmap: ["dotmap"],
|
|
2637
|
+
pydantic_settings: ["pydantic-settings"],
|
|
2638
|
+
telegram: ["python-telegram-bot"],
|
|
2639
|
+
discord: ["discord-py"],
|
|
2640
|
+
nacl: ["pynacl"],
|
|
2641
|
+
jwcrypto: ["jwcrypto"],
|
|
2642
|
+
humanfriendly: ["humanfriendly"],
|
|
2643
|
+
multipart: ["python-multipart"]
|
|
2245
2644
|
};
|
|
2246
2645
|
|
|
2247
2646
|
//#endregion
|
|
@@ -2280,6 +2679,8 @@ const collectFromPyproject = (rootDir, pyDeps) => {
|
|
|
2280
2679
|
const m = line.match(/["']\s*([a-zA-Z0-9_\-.]+)/);
|
|
2281
2680
|
if (m) addPyDep(pyDeps, m[1]);
|
|
2282
2681
|
}
|
|
2682
|
+
const extras = content.match(/\[project\.optional-dependencies\]([\s\S]*?)(?=\n\[|$)/);
|
|
2683
|
+
if (extras) for (const m of extras[1].matchAll(/["']\s*([a-zA-Z][a-zA-Z0-9_\-.]+)/g)) addPyDep(pyDeps, m[1]);
|
|
2283
2684
|
const poetryRe = /\[tool\.poetry(?:\.group\.[a-z]+)?\.dependencies\]([\s\S]*?)(?=\n\[|$)/g;
|
|
2284
2685
|
let match = poetryRe.exec(content);
|
|
2285
2686
|
while (match !== null) {
|
|
@@ -2478,6 +2879,11 @@ const packageNameFromImport = (spec) => {
|
|
|
2478
2879
|
}
|
|
2479
2880
|
return spec.split("/")[0];
|
|
2480
2881
|
};
|
|
2882
|
+
const typesPackageName = (pkg) => {
|
|
2883
|
+
if (pkg.startsWith("@types/")) return pkg;
|
|
2884
|
+
if (pkg.startsWith("@")) return `@types/${pkg.slice(1).replace("/", "__")}`;
|
|
2885
|
+
return `@types/${pkg}`;
|
|
2886
|
+
};
|
|
2481
2887
|
const STATIC_IMPORT_RE = /^\s*import\s+(?:[\w*{},\s]+\s+from\s+)?["']([^"']+)["']/;
|
|
2482
2888
|
const DYNAMIC_IMPORT_RE = /(?:import|require)\s*\(\s*["']([^"']+)["']/g;
|
|
2483
2889
|
const extractJsImports = (content) => {
|
|
@@ -2542,15 +2948,16 @@ const checkJsImport = (rawSpec, manifest, tsAliasMatchers) => {
|
|
|
2542
2948
|
const realPkg = pkg.slice(7);
|
|
2543
2949
|
if (manifest.jsDeps.has(realPkg)) return null;
|
|
2544
2950
|
}
|
|
2951
|
+
if (manifest.jsDeps.has(typesPackageName(pkg))) return null;
|
|
2545
2952
|
return pkg;
|
|
2546
2953
|
};
|
|
2954
|
+
const normalizePyName = (name) => name.toLowerCase().replace(/_/g, "-");
|
|
2547
2955
|
const checkPyImport = (spec, manifest) => {
|
|
2548
2956
|
const root = spec.split(".")[0];
|
|
2549
2957
|
if (PYTHON_STDLIB.has(root)) return null;
|
|
2550
|
-
const normalized = root
|
|
2958
|
+
const normalized = normalizePyName(root);
|
|
2551
2959
|
if (manifest.pyDeps.has(normalized)) return null;
|
|
2552
|
-
|
|
2553
|
-
if (pipName && manifest.pyDeps.has(pipName)) return null;
|
|
2960
|
+
if ((PYTHON_IMPORT_TO_PIP[root] ?? PYTHON_IMPORT_TO_PIP[normalized])?.some((dist) => manifest.pyDeps.has(normalizePyName(dist)))) return null;
|
|
2554
2961
|
return root;
|
|
2555
2962
|
};
|
|
2556
2963
|
const detectHallucinatedImports = async (context) => {
|
|
@@ -2700,6 +3107,85 @@ const collectBlocks = (sourceLines, syntax) => {
|
|
|
2700
3107
|
return blocks;
|
|
2701
3108
|
};
|
|
2702
3109
|
|
|
3110
|
+
//#endregion
|
|
3111
|
+
//#region src/engines/ai-slop/meta-comment.ts
|
|
3112
|
+
const PLAN_REFERENCE_RES = [
|
|
3113
|
+
/\b(?:stage|step|phase)\s+\d+\b(?!\s*[:.]?\s*(?:bytes|ms|seconds|of\s+\d))/i,
|
|
3114
|
+
/\bstep\s+\d+\s+of\s+the\s+plan\b/i,
|
|
3115
|
+
/\bas\s+(?:per|requested)\s+(?:the\s+)?(?:requirements?|spec|task|ticket|prompt|instructions?)\b/i,
|
|
3116
|
+
/\bper\s+the\s+(?:spec|requirements?|task|ticket|plan|prompt|instructions?)\b/i,
|
|
3117
|
+
/\bfrom\s+the\s+(?:task|todo|plan|spec|ticket|prompt|requirements?)\b/i,
|
|
3118
|
+
/\bimplement(?:ing|s|ed)?\s+use\s*case\s+\d*/i,
|
|
3119
|
+
/\b(?:requirements?\s+doc|requirement\s+\d+)\b/i,
|
|
3120
|
+
/\bas\s+(?:instructed|specified|outlined)\s+(?:above|below|in\s+the)\b/i
|
|
3121
|
+
];
|
|
3122
|
+
const BEFORE_AFTER_RES = [
|
|
3123
|
+
/\bpreviously[,:]?\s+(?:this|we|it|the)\b/i,
|
|
3124
|
+
/\bused\s+to\s+(?:be|use|call|return|do|have|rely)\b/i,
|
|
3125
|
+
/\bchanged\s+(?:\w+\s+){0,3}from\s+.+\bto\b/i,
|
|
3126
|
+
/\bno\s+longer\s+(?:needed|used|required|necessary|calls?|returns?|does)\b/i,
|
|
3127
|
+
/\bthis\s+was\s+.+\bbut\s+now\b/i,
|
|
3128
|
+
/\bwe\s+(?:now|used\s+to)\s+(?:no\s+longer\s+)?(?:use|call|return|do|have)\b/i,
|
|
3129
|
+
/\breplaced\s+the\s+(?:old|previous|former)\b/i,
|
|
3130
|
+
/\b(?:was|were)\s+(?:renamed|moved|removed|refactored|extracted)\s+(?:from|to|out\s+of)\b/i
|
|
3131
|
+
];
|
|
3132
|
+
const WHY_OR_TODO_RE = /\b(?:because|since|otherwise|todo|fixme|hack|note:|reason:|workaround|see\s+(?:issue|#))\b/i;
|
|
3133
|
+
const looksLikeLicenseHeader$1 = (block) => {
|
|
3134
|
+
if (block.startLine !== 1) return false;
|
|
3135
|
+
const text = block.rawLines.join(" ").toLowerCase();
|
|
3136
|
+
return text.includes("copyright") || text.includes("license") || text.includes("spdx-license-identifier");
|
|
3137
|
+
};
|
|
3138
|
+
const looksLikeSuppressDirective$1 = (block) => block.rawLines.some((line) => /\b(?:biome-ignore|eslint-disable|ts-ignore|ts-expect-error|@ts-\w+|noqa|pylint:\s*disable|rubocop:disable|noinspection|phpcs:disable)\b/.test(line));
|
|
3139
|
+
const matchMetaSignal = (block) => {
|
|
3140
|
+
if (looksLikeLicenseHeader$1(block)) return null;
|
|
3141
|
+
if (looksLikeSuppressDirective$1(block)) return null;
|
|
3142
|
+
if (block.kind === "jsdoc" && block.hasMeaningfulJsdocTag) return null;
|
|
3143
|
+
if (block.isRustDoc) return null;
|
|
3144
|
+
const joined = block.prose.join(" ");
|
|
3145
|
+
if (joined.trim().length === 0) return null;
|
|
3146
|
+
if (WHY_OR_TODO_RE.test(joined)) return null;
|
|
3147
|
+
if (PLAN_REFERENCE_RES.some((re) => re.test(joined))) return "plan/process reference";
|
|
3148
|
+
if (BEFORE_AFTER_RES.some((re) => re.test(joined))) return "before/after state narration";
|
|
3149
|
+
return null;
|
|
3150
|
+
};
|
|
3151
|
+
const detectMetaComments = async (context) => {
|
|
3152
|
+
const files = getSourceFiles(context);
|
|
3153
|
+
const diagnostics = [];
|
|
3154
|
+
for (const filePath of files) {
|
|
3155
|
+
const ext = path.extname(filePath);
|
|
3156
|
+
if (!SUPPORTED_EXTS.has(ext)) continue;
|
|
3157
|
+
if (isAutoGenerated(filePath)) continue;
|
|
3158
|
+
const syntax = getCommentSyntax(ext);
|
|
3159
|
+
if (!syntax) continue;
|
|
3160
|
+
const relativePath = path.relative(context.rootDirectory, filePath);
|
|
3161
|
+
if (isNonProductionPath(relativePath)) continue;
|
|
3162
|
+
let content;
|
|
3163
|
+
try {
|
|
3164
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
3165
|
+
} catch {
|
|
3166
|
+
continue;
|
|
3167
|
+
}
|
|
3168
|
+
const blocks = collectBlocks(content.split("\n"), syntax);
|
|
3169
|
+
for (const block of blocks) {
|
|
3170
|
+
const reason = matchMetaSignal(block);
|
|
3171
|
+
if (!reason) continue;
|
|
3172
|
+
diagnostics.push({
|
|
3173
|
+
filePath: relativePath,
|
|
3174
|
+
engine: "ai-slop",
|
|
3175
|
+
rule: "ai-slop/meta-comment",
|
|
3176
|
+
severity: "warning",
|
|
3177
|
+
message: `Meta/plan comment (${reason})`,
|
|
3178
|
+
help: "Remove — references to the build plan or before/after code state belong in PR descriptions and commit messages, not source.",
|
|
3179
|
+
line: block.startLine,
|
|
3180
|
+
column: 0,
|
|
3181
|
+
category: "Comments",
|
|
3182
|
+
fixable: false
|
|
3183
|
+
});
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
return diagnostics;
|
|
3187
|
+
};
|
|
3188
|
+
|
|
2703
3189
|
//#endregion
|
|
2704
3190
|
//#region src/engines/ai-slop/narrative-comments.ts
|
|
2705
3191
|
const looksLikeDeclarationPreamble = (nextLine, ext) => {
|
|
@@ -3308,6 +3794,143 @@ const detectRustPatterns = async (context) => {
|
|
|
3308
3794
|
return diagnostics;
|
|
3309
3795
|
};
|
|
3310
3796
|
|
|
3797
|
+
//#endregion
|
|
3798
|
+
//#region src/engines/ai-slop/silent-recovery.ts
|
|
3799
|
+
const JS_EXTS$1 = new Set([
|
|
3800
|
+
".ts",
|
|
3801
|
+
".tsx",
|
|
3802
|
+
".js",
|
|
3803
|
+
".jsx",
|
|
3804
|
+
".mjs",
|
|
3805
|
+
".cjs"
|
|
3806
|
+
]);
|
|
3807
|
+
const CATCH_HEAD_RE = /\bcatch\s*(?:\([^)]*\))?\s*\{/g;
|
|
3808
|
+
const LOG_STATEMENT_RE = /^(?:console|[\w$]+(?:\.[\w$]+)*)\.(?:log|info|warn|warning|error|debug|trace)\s*\(/;
|
|
3809
|
+
const HANDLING_TOKEN_RE = /\b(?:throw|return|reject|next|process\.exit|continue|break)\b/;
|
|
3810
|
+
const stripBlockComments = (text) => text.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
3811
|
+
const extractCatchBody = (content, openBraceIndex) => {
|
|
3812
|
+
let depth = 0;
|
|
3813
|
+
let inString = null;
|
|
3814
|
+
for (let i = openBraceIndex; i < content.length; i += 1) {
|
|
3815
|
+
const ch = content[i];
|
|
3816
|
+
const prev = content[i - 1];
|
|
3817
|
+
if (inString) {
|
|
3818
|
+
if (ch === inString && prev !== "\\") inString = null;
|
|
3819
|
+
continue;
|
|
3820
|
+
}
|
|
3821
|
+
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
3822
|
+
inString = ch;
|
|
3823
|
+
continue;
|
|
3824
|
+
}
|
|
3825
|
+
if (ch === "{") depth += 1;
|
|
3826
|
+
else if (ch === "}") {
|
|
3827
|
+
depth -= 1;
|
|
3828
|
+
if (depth === 0) return content.slice(openBraceIndex + 1, i);
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
return null;
|
|
3832
|
+
};
|
|
3833
|
+
const isLogOnlyBody = (body) => {
|
|
3834
|
+
const statements = stripBlockComments(body).split("\n").map((line) => line.replace(/\/\/.*$/, "").trim()).filter((line) => line.length > 0 && line !== ";");
|
|
3835
|
+
if (statements.length === 0) return false;
|
|
3836
|
+
if (statements.some((line) => HANDLING_TOKEN_RE.test(line))) return false;
|
|
3837
|
+
let sawLog = false;
|
|
3838
|
+
for (const statement of statements) {
|
|
3839
|
+
const normalized = statement.replace(/;+$/, "");
|
|
3840
|
+
if (LOG_STATEMENT_RE.test(normalized)) {
|
|
3841
|
+
sawLog = true;
|
|
3842
|
+
continue;
|
|
3843
|
+
}
|
|
3844
|
+
if (/^[\w$"'`{[(),.\s+:-]+$/.test(normalized) && !/[=(]\s*(?:async\s+)?\(/.test(normalized)) continue;
|
|
3845
|
+
return false;
|
|
3846
|
+
}
|
|
3847
|
+
return sawLog;
|
|
3848
|
+
};
|
|
3849
|
+
const detectJsSilentRecovery = (content, relPath) => {
|
|
3850
|
+
const out = [];
|
|
3851
|
+
CATCH_HEAD_RE.lastIndex = 0;
|
|
3852
|
+
let match;
|
|
3853
|
+
while ((match = CATCH_HEAD_RE.exec(content)) !== null) {
|
|
3854
|
+
const body = extractCatchBody(content, match.index + match[0].length - 1);
|
|
3855
|
+
if (body === null) continue;
|
|
3856
|
+
if (!isLogOnlyBody(body)) continue;
|
|
3857
|
+
const line = content.slice(0, match.index).split("\n").length;
|
|
3858
|
+
out.push({
|
|
3859
|
+
filePath: relPath,
|
|
3860
|
+
engine: "ai-slop",
|
|
3861
|
+
rule: "ai-slop/silent-recovery",
|
|
3862
|
+
severity: "warning",
|
|
3863
|
+
message: "Catch only logs then continues, leaving execution in a possibly broken state",
|
|
3864
|
+
help: "Handle the error: rethrow, return an error value, or recover explicitly. Logging alone lets the program proceed as if nothing failed.",
|
|
3865
|
+
line,
|
|
3866
|
+
column: 0,
|
|
3867
|
+
category: "AI Slop",
|
|
3868
|
+
fixable: false
|
|
3869
|
+
});
|
|
3870
|
+
}
|
|
3871
|
+
return out;
|
|
3872
|
+
};
|
|
3873
|
+
const PY_EXCEPT_RE = /^(\s*)except\b[^\n]*:\s*(?:#.*)?$/;
|
|
3874
|
+
const PY_LOG_STATEMENT_RE = /^(?:logging|logger|log|self\.log|self\.logger|print)(?:\.(?:debug|info|warning|warn|error|exception|critical))?\s*\(/;
|
|
3875
|
+
const PY_HANDLING_TOKEN_RE = /^(?:raise\b|return\b|continue\b|break\b|self\.|[\w.]+\s*=)/;
|
|
3876
|
+
const detectPySilentRecovery = (content, relPath) => {
|
|
3877
|
+
const out = [];
|
|
3878
|
+
const lines = content.split("\n");
|
|
3879
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
3880
|
+
const exceptMatch = PY_EXCEPT_RE.exec(lines[i]);
|
|
3881
|
+
if (!exceptMatch) continue;
|
|
3882
|
+
const indent = exceptMatch[1].length;
|
|
3883
|
+
const bodyLines = [];
|
|
3884
|
+
let j = i + 1;
|
|
3885
|
+
for (; j < lines.length; j += 1) {
|
|
3886
|
+
const raw = lines[j];
|
|
3887
|
+
if (raw.trim() === "") continue;
|
|
3888
|
+
if (raw.length - raw.trimStart().length <= indent) break;
|
|
3889
|
+
bodyLines.push(raw.trim());
|
|
3890
|
+
}
|
|
3891
|
+
if (bodyLines.length === 0) continue;
|
|
3892
|
+
if (bodyLines.some((line) => PY_HANDLING_TOKEN_RE.test(line))) continue;
|
|
3893
|
+
if (bodyLines.some((line) => line === "pass")) continue;
|
|
3894
|
+
const allLogs = bodyLines.every((line) => PY_LOG_STATEMENT_RE.test(line) || /^[\w"'(),.\s+:%{}[\]-]+$/.test(line));
|
|
3895
|
+
const sawLog = bodyLines.some((line) => PY_LOG_STATEMENT_RE.test(line));
|
|
3896
|
+
if (!allLogs || !sawLog) continue;
|
|
3897
|
+
out.push({
|
|
3898
|
+
filePath: relPath,
|
|
3899
|
+
engine: "ai-slop",
|
|
3900
|
+
rule: "ai-slop/silent-recovery",
|
|
3901
|
+
severity: "warning",
|
|
3902
|
+
message: "except only logs then continues, leaving execution in a possibly broken state",
|
|
3903
|
+
help: "Handle the error: re-raise, return an error value, or recover explicitly. Logging alone lets the program proceed as if nothing failed.",
|
|
3904
|
+
line: i + 1,
|
|
3905
|
+
column: 0,
|
|
3906
|
+
category: "AI Slop",
|
|
3907
|
+
fixable: false
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
return out;
|
|
3911
|
+
};
|
|
3912
|
+
const detectSilentRecovery = async (context) => {
|
|
3913
|
+
const files = getSourceFiles(context);
|
|
3914
|
+
const diagnostics = [];
|
|
3915
|
+
for (const filePath of files) {
|
|
3916
|
+
if (isAutoGenerated(filePath)) continue;
|
|
3917
|
+
const ext = path.extname(filePath);
|
|
3918
|
+
const isJs = JS_EXTS$1.has(ext);
|
|
3919
|
+
if (!isJs && !(ext === ".py")) continue;
|
|
3920
|
+
const relPath = path.relative(context.rootDirectory, filePath);
|
|
3921
|
+
if (isNonProductionPath(relPath)) continue;
|
|
3922
|
+
let content;
|
|
3923
|
+
try {
|
|
3924
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
3925
|
+
} catch {
|
|
3926
|
+
continue;
|
|
3927
|
+
}
|
|
3928
|
+
if (isJs) diagnostics.push(...detectJsSilentRecovery(content, relPath));
|
|
3929
|
+
else diagnostics.push(...detectPySilentRecovery(content, relPath));
|
|
3930
|
+
}
|
|
3931
|
+
return diagnostics;
|
|
3932
|
+
};
|
|
3933
|
+
|
|
3311
3934
|
//#endregion
|
|
3312
3935
|
//#region src/engines/ai-slop/unused-imports.ts
|
|
3313
3936
|
const JS_EXTENSIONS$1 = new Set([
|
|
@@ -3497,15 +4120,19 @@ const aiSlopEngine = {
|
|
|
3497
4120
|
const results = await Promise.allSettled([
|
|
3498
4121
|
detectTrivialComments(context),
|
|
3499
4122
|
detectSwallowedExceptions(context),
|
|
4123
|
+
detectDefensivePatterns(context),
|
|
3500
4124
|
detectOverAbstraction(context),
|
|
3501
4125
|
detectDeadPatterns(context),
|
|
3502
4126
|
detectUnusedImports(context),
|
|
3503
4127
|
detectNarrativeComments(context),
|
|
3504
4128
|
detectDuplicateImports(context),
|
|
4129
|
+
detectHardcodedConfigLiterals(context),
|
|
3505
4130
|
detectPythonPatterns(context),
|
|
3506
4131
|
detectGoPatterns(context),
|
|
3507
4132
|
detectRustPatterns(context),
|
|
3508
|
-
detectHallucinatedImports(context)
|
|
4133
|
+
detectHallucinatedImports(context),
|
|
4134
|
+
detectSilentRecovery(context),
|
|
4135
|
+
detectMetaComments(context)
|
|
3509
4136
|
]);
|
|
3510
4137
|
for (const result of results) if (result.status === "fulfilled") diagnostics.push(...result.value);
|
|
3511
4138
|
return {
|
|
@@ -5641,9 +6268,9 @@ const lintEngine = {
|
|
|
5641
6268
|
const promises = [];
|
|
5642
6269
|
if (languages.includes("typescript") || languages.includes("javascript")) {
|
|
5643
6270
|
promises.push(runOxlint(context));
|
|
5644
|
-
if (context.config.lint.typecheck) promises.push(import("./typecheck-
|
|
6271
|
+
if (context.config.lint.typecheck) promises.push(import("./typecheck-DQSzG8fX.js").then((mod) => mod.runTypecheck(context)));
|
|
5645
6272
|
}
|
|
5646
|
-
if (context.frameworks.includes("expo")) promises.push(import("./expo-doctor-
|
|
6273
|
+
if (context.frameworks.includes("expo")) promises.push(import("./expo-doctor-BcIkOte5.js").then((n) => n.t).then((mod) => mod.runExpoDoctor(context)));
|
|
5647
6274
|
if (languages.includes("python") && installedTools["ruff"]) promises.push(runRuffLint(context));
|
|
5648
6275
|
if (languages.includes("go") && installedTools["golangci-lint"]) promises.push(runGolangciLint(context));
|
|
5649
6276
|
if (languages.includes("rust") && installedTools["cargo"]) promises.push(runGenericLinter(context, "rust"));
|
|
@@ -6194,7 +6821,7 @@ const RISKY_PATTERNS = [
|
|
|
6194
6821
|
help: "Use JSON, MessagePack, or other safe serialization formats for untrusted data"
|
|
6195
6822
|
},
|
|
6196
6823
|
{
|
|
6197
|
-
pattern: new RegExp(
|
|
6824
|
+
pattern: new RegExp(`(?<![\\w.>:\\\\])\\bexec\\s*\\(`, "g"),
|
|
6198
6825
|
extensions: [".py"],
|
|
6199
6826
|
name: "python-exec",
|
|
6200
6827
|
message: "Use of exec() can execute arbitrary code",
|
|
@@ -6762,8 +7389,8 @@ const redactProperties = (props) => {
|
|
|
6762
7389
|
|
|
6763
7390
|
//#endregion
|
|
6764
7391
|
//#region src/telemetry/client.ts
|
|
6765
|
-
const POSTHOG_HOST = "https://eu.i.posthog.com";
|
|
6766
|
-
const POSTHOG_KEY = "phc_eY2cOMFva9q24GrWeOuvuVIOhCIdjOALxeAR3ItrqbJ";
|
|
7392
|
+
const POSTHOG_HOST = process.env.AISLOP_POSTHOG_HOST ?? "https://eu.i.posthog.com";
|
|
7393
|
+
const POSTHOG_KEY = process.env.AISLOP_POSTHOG_KEY ?? "phc_eY2cOMFva9q24GrWeOuvuVIOhCIdjOALxeAR3ItrqbJ";
|
|
6767
7394
|
const SCHEMA_VERSION = "v2";
|
|
6768
7395
|
const REQUEST_TIMEOUT_MS = 3e3;
|
|
6769
7396
|
const isTelemetryDisabled = (config) => {
|
|
@@ -7102,6 +7729,30 @@ const printEngineStatus = (result) => {
|
|
|
7102
7729
|
}
|
|
7103
7730
|
};
|
|
7104
7731
|
|
|
7732
|
+
//#endregion
|
|
7733
|
+
//#region src/scoring/rule-severity.ts
|
|
7734
|
+
/**
|
|
7735
|
+
* Apply per-rule severity overrides from config: "off" drops the diagnostic,
|
|
7736
|
+
* "error"/"warning" rewrite its severity before scoring and rendering.
|
|
7737
|
+
*/
|
|
7738
|
+
const applyRuleSeverities = (diagnostics, overrides) => {
|
|
7739
|
+
if (Object.keys(overrides).length === 0) return diagnostics;
|
|
7740
|
+
const result = [];
|
|
7741
|
+
for (const diagnostic of diagnostics) {
|
|
7742
|
+
const override = overrides[diagnostic.rule];
|
|
7743
|
+
if (!override) {
|
|
7744
|
+
result.push(diagnostic);
|
|
7745
|
+
continue;
|
|
7746
|
+
}
|
|
7747
|
+
if (override === "off") continue;
|
|
7748
|
+
result.push(override === diagnostic.severity ? diagnostic : {
|
|
7749
|
+
...diagnostic,
|
|
7750
|
+
severity: override
|
|
7751
|
+
});
|
|
7752
|
+
}
|
|
7753
|
+
return result;
|
|
7754
|
+
};
|
|
7755
|
+
|
|
7105
7756
|
//#endregion
|
|
7106
7757
|
//#region src/ui/live-grid.ts
|
|
7107
7758
|
const SPINNER = [
|
|
@@ -7238,6 +7889,11 @@ const RULE_LABELS = {
|
|
|
7238
7889
|
"knip/types": "Unused type",
|
|
7239
7890
|
"ai-slop/trivial-comment": "Trivial restating comment",
|
|
7240
7891
|
"ai-slop/swallowed-exception": "Empty catch (swallowed error)",
|
|
7892
|
+
"ai-slop/silent-recovery": "Catch logs then continues",
|
|
7893
|
+
"ai-slop/meta-comment": "Meta/plan comment",
|
|
7894
|
+
"ai-slop/redundant-try-catch": "Redundant try/catch",
|
|
7895
|
+
"ai-slop/redundant-type-coercion": "Redundant type coercion",
|
|
7896
|
+
"ai-slop/duplicate-type-declaration": "Duplicate exported type",
|
|
7241
7897
|
"ai-slop/thin-wrapper": "Thin function wrapper",
|
|
7242
7898
|
"ai-slop/generic-naming": "Generic/vague identifier name",
|
|
7243
7899
|
"ai-slop/unused-import": "Unused import",
|
|
@@ -7251,6 +7907,8 @@ const RULE_LABELS = {
|
|
|
7251
7907
|
"ai-slop/ts-directive": "@ts-ignore / @ts-expect-error",
|
|
7252
7908
|
"ai-slop/narrative-comment": "Narrative comment block",
|
|
7253
7909
|
"ai-slop/duplicate-import": "Duplicate import statement",
|
|
7910
|
+
"ai-slop/hardcoded-url": "Hardcoded URL",
|
|
7911
|
+
"ai-slop/hardcoded-id": "Hardcoded provider ID",
|
|
7254
7912
|
"ai-slop/python-bare-except": "Bare except",
|
|
7255
7913
|
"ai-slop/python-broad-except": "Broad except",
|
|
7256
7914
|
"ai-slop/python-mutable-default": "Mutable default argument",
|
|
@@ -7423,8 +8081,35 @@ const getStagedFiles = (cwd) => {
|
|
|
7423
8081
|
return result.stdout.split("\n").filter((f) => f.length > 0).map((f) => path.resolve(cwd, f));
|
|
7424
8082
|
};
|
|
7425
8083
|
|
|
8084
|
+
//#endregion
|
|
8085
|
+
//#region src/utils/history.ts
|
|
8086
|
+
const HISTORY_FILE = "history.jsonl";
|
|
8087
|
+
const isHistoryDisabled = (env = process.env) => env.AISLOP_NO_HISTORY === "1";
|
|
8088
|
+
const historyPath = (directory) => path.join(path.resolve(directory), CONFIG_DIR, HISTORY_FILE);
|
|
8089
|
+
/**
|
|
8090
|
+
* Append a compact scan record to .aislop/history.jsonl. Best-effort: never
|
|
8091
|
+
* throws, so a read-only checkout or missing config dir can't break a scan.
|
|
8092
|
+
*/
|
|
8093
|
+
const appendHistory = (input) => {
|
|
8094
|
+
if (isHistoryDisabled()) return;
|
|
8095
|
+
const configDir = path.join(path.resolve(input.directory), CONFIG_DIR);
|
|
8096
|
+
if (!fs.existsSync(configDir)) return;
|
|
8097
|
+
const record = {
|
|
8098
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8099
|
+
score: input.score,
|
|
8100
|
+
errors: input.errors,
|
|
8101
|
+
warnings: input.warnings,
|
|
8102
|
+
files: input.files,
|
|
8103
|
+
cliVersion: APP_VERSION
|
|
8104
|
+
};
|
|
8105
|
+
try {
|
|
8106
|
+
fs.appendFileSync(historyPath(input.directory), `${JSON.stringify(record)}\n`);
|
|
8107
|
+
} catch {}
|
|
8108
|
+
};
|
|
8109
|
+
|
|
7426
8110
|
//#endregion
|
|
7427
8111
|
//#region src/commands/scan.ts
|
|
8112
|
+
const isMachineOutput = (options) => Boolean(options.json) || Boolean(options.sarif);
|
|
7428
8113
|
const shouldUseSpinner = () => Boolean(process.stderr.isTTY) && process.env.CI !== "true" && process.env.CI !== "1";
|
|
7429
8114
|
const ALL_ENGINE_NAMES = Object.keys(ENGINE_INFO);
|
|
7430
8115
|
const BREAKDOWN_TOP_N = 10;
|
|
@@ -7539,17 +8224,18 @@ const scanCommand = async (directory, config, options) => {
|
|
|
7539
8224
|
const runScanBody = async (resolvedDir, config, options, projectInfo) => {
|
|
7540
8225
|
const startTime = performance.now();
|
|
7541
8226
|
const showHeader = options.showHeader !== false;
|
|
7542
|
-
const
|
|
8227
|
+
const machineOutput = isMachineOutput(options);
|
|
8228
|
+
const useLiveProgress = !machineOutput && shouldUseSpinner();
|
|
7543
8229
|
let files;
|
|
7544
8230
|
if (options.staged) {
|
|
7545
8231
|
files = filterProjectFiles(resolvedDir, getStagedFiles(resolvedDir), [], config.exclude);
|
|
7546
|
-
if (!
|
|
8232
|
+
if (!machineOutput) log.muted(`Scope: ${files.length} staged file(s)`);
|
|
7547
8233
|
} else if (options.changes) {
|
|
7548
8234
|
files = filterProjectFiles(resolvedDir, getChangedFiles(resolvedDir), [], config.exclude);
|
|
7549
|
-
if (!
|
|
8235
|
+
if (!machineOutput) log.muted(`Scope: ${files.length} changed file(s)`);
|
|
7550
8236
|
} else {
|
|
7551
8237
|
files = filterProjectFiles(resolvedDir, listProjectFiles(resolvedDir), [], config.exclude);
|
|
7552
|
-
if (!
|
|
8238
|
+
if (!machineOutput) log.muted(`Scope: ${files.length} file(s) after exclusions`);
|
|
7553
8239
|
}
|
|
7554
8240
|
const configDir = findConfigDir(resolvedDir);
|
|
7555
8241
|
const rulesPath = configDir ? path.join(configDir, RULES_FILE) : void 0;
|
|
@@ -7566,7 +8252,7 @@ const runScanBody = async (resolvedDir, config, options, projectInfo) => {
|
|
|
7566
8252
|
}));
|
|
7567
8253
|
const progressRenderer = useLiveProgress ? new LiveGrid(gridRows) : null;
|
|
7568
8254
|
progressRenderer?.start();
|
|
7569
|
-
const
|
|
8255
|
+
const rawResults = await runEngines({
|
|
7570
8256
|
rootDirectory: resolvedDir,
|
|
7571
8257
|
languages: projectInfo.languages,
|
|
7572
8258
|
frameworks: projectInfo.frameworks,
|
|
@@ -7599,9 +8285,13 @@ const runScanBody = async (resolvedDir, config, options, projectInfo) => {
|
|
|
7599
8285
|
elapsedMs: result.elapsed
|
|
7600
8286
|
});
|
|
7601
8287
|
}
|
|
7602
|
-
if (!
|
|
8288
|
+
if (!machineOutput && !progressRenderer) printEngineStatus(result);
|
|
7603
8289
|
});
|
|
7604
8290
|
progressRenderer?.stop();
|
|
8291
|
+
const results = rawResults.map((result) => ({
|
|
8292
|
+
...result,
|
|
8293
|
+
diagnostics: applyRuleSeverities(result.diagnostics, config.rules)
|
|
8294
|
+
}));
|
|
7605
8295
|
const allDiagnostics = results.flatMap((r) => r.diagnostics);
|
|
7606
8296
|
const elapsedMs = performance.now() - startTime;
|
|
7607
8297
|
const scoreResult = calculateScore(allDiagnostics, config.scoring.weights, config.scoring.thresholds, projectInfo.sourceFileCount, config.scoring.smoothing);
|
|
@@ -7622,12 +8312,24 @@ const runScanBody = async (resolvedDir, config, options, projectInfo) => {
|
|
|
7622
8312
|
engineIssues,
|
|
7623
8313
|
engineTimings
|
|
7624
8314
|
};
|
|
8315
|
+
if (options.sarif) {
|
|
8316
|
+
const { buildSarifLog } = await import("./sarif-CLVijBAO.js");
|
|
8317
|
+
console.log(JSON.stringify(buildSarifLog(results), null, 2));
|
|
8318
|
+
return completion;
|
|
8319
|
+
}
|
|
7625
8320
|
if (options.json) {
|
|
7626
|
-
const { buildJsonOutput } = await import("./json-
|
|
8321
|
+
const { buildJsonOutput } = await import("./json-CxiErSgX.js");
|
|
7627
8322
|
const jsonOut = buildJsonOutput(results, scoreResult, projectInfo.sourceFileCount, elapsedMs);
|
|
7628
8323
|
console.log(JSON.stringify(jsonOut, null, 2));
|
|
7629
8324
|
return completion;
|
|
7630
8325
|
}
|
|
8326
|
+
if (!options.staged && !options.changes && options.command !== "ci" && !isCiEnv()) appendHistory({
|
|
8327
|
+
directory: resolvedDir,
|
|
8328
|
+
score: scoreResult.score,
|
|
8329
|
+
errors: completion.errorCount,
|
|
8330
|
+
warnings: completion.warningCount,
|
|
8331
|
+
files: projectInfo.sourceFileCount
|
|
8332
|
+
});
|
|
7631
8333
|
const projectName = projectInfo.projectName ?? "project";
|
|
7632
8334
|
const language = projectInfo.languages[0] ?? "unknown";
|
|
7633
8335
|
process.stdout.write(buildScanRender({
|
|
@@ -7707,6 +8409,16 @@ const AGENT_CONFIGS = {
|
|
|
7707
8409
|
bin: "goose",
|
|
7708
8410
|
args: (p) => ["run", p]
|
|
7709
8411
|
},
|
|
8412
|
+
pi: {
|
|
8413
|
+
type: "cli",
|
|
8414
|
+
bin: "pi",
|
|
8415
|
+
args: (p) => ["-p", p]
|
|
8416
|
+
},
|
|
8417
|
+
crush: {
|
|
8418
|
+
type: "cli",
|
|
8419
|
+
bin: "crush",
|
|
8420
|
+
args: (p) => ["run", p]
|
|
8421
|
+
},
|
|
7710
8422
|
cursor: {
|
|
7711
8423
|
type: "editor",
|
|
7712
8424
|
bin: "cursor"
|
|
@@ -8905,7 +9617,7 @@ const runLintSteps = async (deps) => {
|
|
|
8905
9617
|
if (hasJsOrTs(deps.projectInfo)) await deps.runStep("Lint fixes (js/ts)", () => runOxlint(deps.context), () => fixOxlint(deps.context, { force: deps.force }));
|
|
8906
9618
|
if (deps.projectInfo.languages.includes("python") && deps.projectInfo.installedTools.ruff) await deps.runStep("Lint fixes (python)", () => runRuffLint(deps.context), () => deps.force ? fixRuffLintForce(deps.resolvedDir) : fixRuffLint(deps.resolvedDir));
|
|
8907
9619
|
else if (deps.projectInfo.languages.includes("python")) log.warn("Python detected but ruff is not installed; skipping Python lint fixes.");
|
|
8908
|
-
if (deps.projectInfo.languages.includes("ruby") && deps.projectInfo.installedTools.rubocop) await deps.runStep("Lint fixes (ruby)", () => import("./generic-
|
|
9620
|
+
if (deps.projectInfo.languages.includes("ruby") && deps.projectInfo.installedTools.rubocop) await deps.runStep("Lint fixes (ruby)", () => import("./generic-D_T4cUaC.js").then((n) => n.n).then((mod) => mod.runGenericLinter(deps.context, "ruby")), () => fixRubyLint(deps.resolvedDir));
|
|
8909
9621
|
else if (deps.projectInfo.languages.includes("ruby")) log.warn("Ruby detected but rubocop is not installed; skipping Ruby lint fixes.");
|
|
8910
9622
|
};
|
|
8911
9623
|
const runDependencyStep = async (deps) => {
|
|
@@ -9431,6 +10143,11 @@ const BUILTIN_RULES = [
|
|
|
9431
10143
|
rules: [
|
|
9432
10144
|
"ai-slop/trivial-comment",
|
|
9433
10145
|
"ai-slop/swallowed-exception",
|
|
10146
|
+
"ai-slop/silent-recovery",
|
|
10147
|
+
"ai-slop/meta-comment",
|
|
10148
|
+
"ai-slop/redundant-try-catch",
|
|
10149
|
+
"ai-slop/redundant-type-coercion",
|
|
10150
|
+
"ai-slop/duplicate-type-declaration",
|
|
9434
10151
|
"ai-slop/thin-wrapper",
|
|
9435
10152
|
"ai-slop/generic-naming",
|
|
9436
10153
|
"ai-slop/unused-import",
|
|
@@ -9444,6 +10161,8 @@ const BUILTIN_RULES = [
|
|
|
9444
10161
|
"ai-slop/ts-directive",
|
|
9445
10162
|
"ai-slop/narrative-comment",
|
|
9446
10163
|
"ai-slop/duplicate-import",
|
|
10164
|
+
"ai-slop/hardcoded-url",
|
|
10165
|
+
"ai-slop/hardcoded-id",
|
|
9447
10166
|
"ai-slop/python-bare-except",
|
|
9448
10167
|
"ai-slop/python-broad-except",
|
|
9449
10168
|
"ai-slop/python-mutable-default",
|