code-intelligence 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +154 -2
- package/THIRD_PARTY.md +17 -0
- package/dist/cli.js +7 -0
- package/dist/commands/doctor.js +80 -0
- package/dist/commands/impact.js +148 -0
- package/dist/commands/init.js +27 -0
- package/dist/commands/mutate.js +319 -0
- package/dist/commands/scan.js +118 -0
- package/dist/core/baseline.js +54 -0
- package/dist/core/cache.js +148 -0
- package/dist/core/config.js +317 -0
- package/dist/core/errors.js +18 -0
- package/dist/core/exec.js +154 -0
- package/dist/core/glob.js +306 -0
- package/dist/core/hashing.js +44 -0
- package/dist/core/logger.js +29 -0
- package/dist/core/normalize.js +133 -0
- package/dist/core/planner.js +106 -0
- package/dist/core/runner.js +126 -0
- package/dist/core/safefs.js +87 -0
- package/dist/core/suppressions.js +27 -0
- package/dist/core/targets.js +286 -0
- package/dist/engines/ast-grep.js +71 -0
- package/dist/engines/engine.js +25 -0
- package/dist/engines/gitleaks.js +135 -0
- package/dist/engines/osv-scanner.js +100 -0
- package/dist/engines/registry.js +7 -0
- package/dist/engines/semgrep.js +139 -0
- package/dist/engines/trivy.js +71 -0
- package/dist/engines/util.js +129 -0
- package/dist/main.js +301 -0
- package/dist/report/json.js +1 -0
- package/dist/report/sarif.js +73 -0
- package/dist/report/text.js +86 -0
- package/dist/types.js +9 -0
- package/dist/version.js +12 -0
- package/package.json +56 -4
- package/schema/config.schema.json +86 -0
- package/schema/report.schema.json +126 -0
package/dist/main.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { renderDoctor, runDoctor } from "./commands/doctor.js";
|
|
3
|
+
import { renderImpact, runImpact } from "./commands/impact.js";
|
|
4
|
+
import { runInit } from "./commands/init.js";
|
|
5
|
+
import { renderMutation, runMutate } from "./commands/mutate.js";
|
|
6
|
+
import { runScan } from "./commands/scan.js";
|
|
7
|
+
import { saveBaseline } from "./core/baseline.js";
|
|
8
|
+
import { UsageError } from "./core/errors.js";
|
|
9
|
+
import { createLogger, isLogLevel } from "./core/logger.js";
|
|
10
|
+
import { renderJson } from "./report/json.js";
|
|
11
|
+
import { renderSarif } from "./report/sarif.js";
|
|
12
|
+
import { renderText } from "./report/text.js";
|
|
13
|
+
import { isSeverity, PROFILES } from "./types.js";
|
|
14
|
+
import { VERSION } from "./version.js";
|
|
15
|
+
const HELP = `code-intel ${VERSION}: run security and quality scanners on what changed, normalize the findings.
|
|
16
|
+
|
|
17
|
+
Usage: code-intel <command> [options]
|
|
18
|
+
|
|
19
|
+
Commands:
|
|
20
|
+
scan Run engines on changed files (or the whole repo) and report findings
|
|
21
|
+
baseline Record current findings so later scans can report only new ones
|
|
22
|
+
mutate Mutation-test changed code (StrykerJS) to find gaps in your tests
|
|
23
|
+
impact List the tests affected by your changes (uses codegraph when indexed)
|
|
24
|
+
doctor Check which engines are installed and whether the config is valid
|
|
25
|
+
init Create .code-intel.json in the current repository
|
|
26
|
+
|
|
27
|
+
Global options:
|
|
28
|
+
-h, --help Show help (also: code-intel <command> --help)
|
|
29
|
+
-v, --version Print the version
|
|
30
|
+
--log-level <level> silent | error | warn (default) | info | debug (logs go to stderr)
|
|
31
|
+
--log-format <format> text (default) | json
|
|
32
|
+
|
|
33
|
+
Exit codes: 0 ok, 1 findings at/above --fail-on, 2 usage or config error, 3 incomplete scan.
|
|
34
|
+
Docs: https://github.com/micio86dev/code-intelligence#readme
|
|
35
|
+
`;
|
|
36
|
+
const SCAN_HELP = `Usage: code-intel scan [options]
|
|
37
|
+
|
|
38
|
+
Scope (default: --changed inside a git repo, --all otherwise):
|
|
39
|
+
--changed Uncommitted changes versus HEAD, plus untracked files
|
|
40
|
+
--staged Only what is staged for commit
|
|
41
|
+
--since <ref> Working tree versus a git ref (e.g. main, HEAD~3)
|
|
42
|
+
--all Every tracked and untracked, non-ignored file
|
|
43
|
+
|
|
44
|
+
Options:
|
|
45
|
+
-p, --profile <name> quick (default): secrets, SAST, dependencies. deep: adds architecture, longer timeouts
|
|
46
|
+
-e, --engines <list> Comma-separated engines or categories (secrets, sast, deps, architecture)
|
|
47
|
+
-f, --format <format> text (default) | json | sarif
|
|
48
|
+
--new-only Hide findings recorded in the baseline (see: code-intel baseline)
|
|
49
|
+
--fail-on <severity> info | low | medium | high (default) | critical
|
|
50
|
+
--timeout <ms> Per-engine time limit (default depends on profile)
|
|
51
|
+
--allow-missing Do not treat a missing engine as an incomplete scan
|
|
52
|
+
--no-cache Do not read or write cached engine results
|
|
53
|
+
--ignore-repo-config Ignore the repository's own configuration (.code-intel.json, .gitleaks.toml,
|
|
54
|
+
.gitleaksignore, baseline). Use it when scanning code you do not trust:
|
|
55
|
+
a hostile repository can configure a scan to find nothing
|
|
56
|
+
`;
|
|
57
|
+
const IMPACT_HELP = `Usage: code-intel impact [--changed | --staged | --since <ref>] [--json]
|
|
58
|
+
|
|
59
|
+
Lists the test files affected by your changes. With a codegraph index (run \`codegraph init\` once)
|
|
60
|
+
the answer follows the import graph transitively. Without one it falls back to a labelled
|
|
61
|
+
heuristic (direct importers and name matches only). The index is synced before every query.
|
|
62
|
+
`;
|
|
63
|
+
const MUTATE_HELP = `Usage: code-intel mutate [files...] [--changed | --staged | --since <ref>] [options]
|
|
64
|
+
|
|
65
|
+
Mutation-tests changed JavaScript/TypeScript code with StrykerJS: it makes small behavior changes
|
|
66
|
+
("mutants") and runs your tests. A mutant your tests do not catch is a gap in the tests.
|
|
67
|
+
Without file arguments it mutates only the lines you changed. This is slow by design; use it
|
|
68
|
+
before merging or when asked about test quality, not after every edit.
|
|
69
|
+
|
|
70
|
+
Requires StrykerJS in the project: npm install --save-dev @stryker-mutator/core
|
|
71
|
+
Uses the project's stryker.config.* when present, otherwise runs its \`npm test\` script.
|
|
72
|
+
|
|
73
|
+
Options:
|
|
74
|
+
--min-score <0-100> Exit 1 when the mutation score is lower
|
|
75
|
+
--timeout <ms> Time limit for the whole run (default 600000)
|
|
76
|
+
--json Machine-readable output
|
|
77
|
+
`;
|
|
78
|
+
const SHARED = {
|
|
79
|
+
help: { type: "boolean", short: "h" },
|
|
80
|
+
version: { type: "boolean", short: "v" },
|
|
81
|
+
"log-level": { type: "string" },
|
|
82
|
+
"log-format": { type: "string" },
|
|
83
|
+
};
|
|
84
|
+
function render(format, r) {
|
|
85
|
+
return format === "json" ? renderJson(r) : format === "sarif" ? renderSarif(r) : renderText(r);
|
|
86
|
+
}
|
|
87
|
+
function parse(rest) {
|
|
88
|
+
return parseArgs({
|
|
89
|
+
args: rest,
|
|
90
|
+
strict: true,
|
|
91
|
+
allowPositionals: true,
|
|
92
|
+
options: {
|
|
93
|
+
...SHARED,
|
|
94
|
+
profile: { type: "string", short: "p" },
|
|
95
|
+
engines: { type: "string", short: "e" },
|
|
96
|
+
format: { type: "string", short: "f" },
|
|
97
|
+
changed: { type: "boolean" },
|
|
98
|
+
staged: { type: "boolean" },
|
|
99
|
+
all: { type: "boolean" },
|
|
100
|
+
since: { type: "string" },
|
|
101
|
+
"new-only": { type: "boolean" },
|
|
102
|
+
"fail-on": { type: "string" },
|
|
103
|
+
timeout: { type: "string" },
|
|
104
|
+
"allow-missing": { type: "boolean" },
|
|
105
|
+
"no-cache": { type: "boolean" },
|
|
106
|
+
"ignore-repo-config": { type: "boolean" },
|
|
107
|
+
json: { type: "boolean" },
|
|
108
|
+
"min-score": { type: "string" },
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
export async function main(argv, io) {
|
|
113
|
+
try {
|
|
114
|
+
const first = argv[0];
|
|
115
|
+
if (first === undefined || first === "-h" || first === "--help" || first === "help") {
|
|
116
|
+
io.stdout(HELP);
|
|
117
|
+
return first === undefined ? 2 : 0;
|
|
118
|
+
}
|
|
119
|
+
if (first === "-v" || first === "--version") {
|
|
120
|
+
io.stdout(`${VERSION}\n`);
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
const command = first;
|
|
124
|
+
const rest = argv.slice(1);
|
|
125
|
+
let parsed;
|
|
126
|
+
try {
|
|
127
|
+
parsed = parse(rest);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
throw new UsageError(e.message, [`Run: code-intel ${command} --help`]);
|
|
131
|
+
}
|
|
132
|
+
const v = parsed.values;
|
|
133
|
+
if (parsed.positionals.length > 0 && command !== "mutate") {
|
|
134
|
+
throw new UsageError(`Unexpected argument '${parsed.positionals[0]}'`, [
|
|
135
|
+
`Run: code-intel ${command} --help`,
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
if (v.help) {
|
|
139
|
+
io.stdout(command === "scan" || command === "baseline"
|
|
140
|
+
? SCAN_HELP
|
|
141
|
+
: command === "impact"
|
|
142
|
+
? IMPACT_HELP
|
|
143
|
+
: HELP);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
if (v.version) {
|
|
147
|
+
io.stdout(`${VERSION}\n`);
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
const level = (v["log-level"] ?? "warn");
|
|
151
|
+
if (!isLogLevel(level))
|
|
152
|
+
throw new UsageError(`--log-level must be one of silent, error, warn, info, debug (got '${level}')`);
|
|
153
|
+
const lfmt = (v["log-format"] ?? "text");
|
|
154
|
+
if (lfmt !== "text" && lfmt !== "json")
|
|
155
|
+
throw new UsageError(`--log-format must be text or json (got '${lfmt}')`);
|
|
156
|
+
const log = createLogger(level, lfmt, io.stderr);
|
|
157
|
+
switch (command) {
|
|
158
|
+
case "doctor": {
|
|
159
|
+
const r = await runDoctor(io.cwd);
|
|
160
|
+
io.stdout(v.json ? `${JSON.stringify(r, null, 2)}\n` : renderDoctor(r));
|
|
161
|
+
return r.config.valid ? 0 : 2;
|
|
162
|
+
}
|
|
163
|
+
case "impact": {
|
|
164
|
+
const modes = [];
|
|
165
|
+
if (v.changed)
|
|
166
|
+
modes.push("changed");
|
|
167
|
+
if (v.staged)
|
|
168
|
+
modes.push("staged");
|
|
169
|
+
if (v.since !== undefined)
|
|
170
|
+
modes.push("since");
|
|
171
|
+
if (v.all)
|
|
172
|
+
throw new UsageError("impact does not support --all; use --changed, --staged or --since <ref>");
|
|
173
|
+
if (modes.length > 1)
|
|
174
|
+
throw new UsageError("Use only one of --changed, --staged, --since");
|
|
175
|
+
const r = await runImpact({
|
|
176
|
+
cwd: io.cwd,
|
|
177
|
+
mode: modes[0] ?? null,
|
|
178
|
+
ref: v.since ?? null,
|
|
179
|
+
log,
|
|
180
|
+
});
|
|
181
|
+
io.stdout(v.json || v.format === "json" ? `${JSON.stringify(r, null, 2)}\n` : renderImpact(r));
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
case "mutate": {
|
|
185
|
+
const modes = [];
|
|
186
|
+
if (v.changed)
|
|
187
|
+
modes.push("changed");
|
|
188
|
+
if (v.staged)
|
|
189
|
+
modes.push("staged");
|
|
190
|
+
if (v.since !== undefined)
|
|
191
|
+
modes.push("since");
|
|
192
|
+
if (v.all)
|
|
193
|
+
throw new UsageError("mutate does not support --all (too slow to be useful); pass files or use --changed, --staged, --since <ref>");
|
|
194
|
+
if (modes.length > 1)
|
|
195
|
+
throw new UsageError("Use only one of --changed, --staged, --since");
|
|
196
|
+
if (modes.length > 0 && parsed.positionals.length > 0)
|
|
197
|
+
throw new UsageError("Pass either files or a scope flag, not both");
|
|
198
|
+
let minScore = null;
|
|
199
|
+
if (v["min-score"] !== undefined) {
|
|
200
|
+
minScore = Number(v["min-score"]);
|
|
201
|
+
if (!Number.isFinite(minScore) || minScore < 0 || minScore > 100)
|
|
202
|
+
throw new UsageError("--min-score must be a number between 0 and 100");
|
|
203
|
+
}
|
|
204
|
+
let timeoutMs = 600_000;
|
|
205
|
+
if (v.timeout !== undefined) {
|
|
206
|
+
timeoutMs = Number(v.timeout);
|
|
207
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1000)
|
|
208
|
+
throw new UsageError("--timeout must be an integer number of milliseconds (>= 1000)");
|
|
209
|
+
}
|
|
210
|
+
const r = await runMutate({
|
|
211
|
+
cwd: io.cwd,
|
|
212
|
+
mode: modes[0] ?? null,
|
|
213
|
+
ref: v.since ?? null,
|
|
214
|
+
files: parsed.positionals,
|
|
215
|
+
timeoutMs,
|
|
216
|
+
minScore,
|
|
217
|
+
log,
|
|
218
|
+
});
|
|
219
|
+
io.stdout(v.json || v.format === "json" ? `${JSON.stringify(r, null, 2)}\n` : renderMutation(r));
|
|
220
|
+
return r.exitCode;
|
|
221
|
+
}
|
|
222
|
+
case "init": {
|
|
223
|
+
const { created } = await runInit(io.cwd);
|
|
224
|
+
io.stdout(`Created: ${created.join(", ")}\n`);
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
case "scan":
|
|
228
|
+
case "baseline": {
|
|
229
|
+
const modes = [];
|
|
230
|
+
if (v.changed)
|
|
231
|
+
modes.push("changed");
|
|
232
|
+
if (v.staged)
|
|
233
|
+
modes.push("staged");
|
|
234
|
+
if (v.since !== undefined)
|
|
235
|
+
modes.push("since");
|
|
236
|
+
if (v.all)
|
|
237
|
+
modes.push("all");
|
|
238
|
+
if (modes.length > 1)
|
|
239
|
+
throw new UsageError("Use only one of --changed, --staged, --since, --all");
|
|
240
|
+
const profile = (v.profile ?? "quick");
|
|
241
|
+
if (!PROFILES.includes(profile))
|
|
242
|
+
throw new UsageError(`--profile must be quick or deep (got '${profile}')`);
|
|
243
|
+
const format = (v.format ?? "text");
|
|
244
|
+
if (!["text", "json", "sarif"].includes(format))
|
|
245
|
+
throw new UsageError(`--format must be text, json or sarif (got '${format}')`);
|
|
246
|
+
if (v["fail-on"] !== undefined && !isSeverity(v["fail-on"]))
|
|
247
|
+
throw new UsageError(`--fail-on must be one of info, low, medium, high, critical (got '${v["fail-on"]}')`);
|
|
248
|
+
let timeoutMs = null;
|
|
249
|
+
if (v.timeout !== undefined) {
|
|
250
|
+
timeoutMs = Number(v.timeout);
|
|
251
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1000)
|
|
252
|
+
throw new UsageError("--timeout must be an integer number of milliseconds (>= 1000)");
|
|
253
|
+
}
|
|
254
|
+
const isBaseline = command === "baseline";
|
|
255
|
+
const { report, root, config } = await runScan({
|
|
256
|
+
cwd: io.cwd,
|
|
257
|
+
profile: profile,
|
|
258
|
+
mode: isBaseline ? "all" : (modes[0] ?? null),
|
|
259
|
+
ref: v.since ?? null,
|
|
260
|
+
engines: v.engines
|
|
261
|
+
? v.engines
|
|
262
|
+
.split(",")
|
|
263
|
+
.map((s) => s.trim())
|
|
264
|
+
.filter(Boolean)
|
|
265
|
+
: null,
|
|
266
|
+
failOn: isBaseline ? null : (v["fail-on"] ?? null),
|
|
267
|
+
timeoutMs,
|
|
268
|
+
cache: !v["no-cache"],
|
|
269
|
+
newOnly: isBaseline ? false : Boolean(v["new-only"]),
|
|
270
|
+
ignoreRepoConfig: Boolean(v["ignore-repo-config"]),
|
|
271
|
+
allowMissing: Boolean(v["allow-missing"]),
|
|
272
|
+
log,
|
|
273
|
+
});
|
|
274
|
+
if (isBaseline) {
|
|
275
|
+
if (!report.complete) {
|
|
276
|
+
io.stdout(renderText(report));
|
|
277
|
+
io.stderr("Baseline not written: the scan was incomplete. Fix the engines above and retry.");
|
|
278
|
+
return 3;
|
|
279
|
+
}
|
|
280
|
+
const n = saveBaseline(root, config.baseline, report.findings);
|
|
281
|
+
io.stdout(`Baseline written: ${n} finding(s) recorded in ${config.baseline}\n`);
|
|
282
|
+
return 0;
|
|
283
|
+
}
|
|
284
|
+
io.stdout(render(format, report));
|
|
285
|
+
return report.exitCode;
|
|
286
|
+
}
|
|
287
|
+
default:
|
|
288
|
+
throw new UsageError(`Unknown command '${command}'`, ["Run: code-intel --help"]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (e) {
|
|
292
|
+
if (e instanceof UsageError) {
|
|
293
|
+
io.stderr(`error: ${e.message}`);
|
|
294
|
+
for (const d of e.details)
|
|
295
|
+
io.stderr(` ${d}`);
|
|
296
|
+
return 2;
|
|
297
|
+
}
|
|
298
|
+
io.stderr(`internal error: ${e instanceof Error ? e.message : String(e)}`);
|
|
299
|
+
return 70;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const renderJson = (r) => `${JSON.stringify(r, null, 2)}\n`;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const LEVEL = {
|
|
2
|
+
critical: "error",
|
|
3
|
+
high: "error",
|
|
4
|
+
medium: "warning",
|
|
5
|
+
low: "note",
|
|
6
|
+
info: "note",
|
|
7
|
+
};
|
|
8
|
+
/** SARIF 2.1.0, consumable by GitHub code scanning and most IDEs. */
|
|
9
|
+
export function renderSarif(r) {
|
|
10
|
+
const rules = new Map();
|
|
11
|
+
for (const f of r.findings) {
|
|
12
|
+
if (rules.has(f.ruleId))
|
|
13
|
+
continue;
|
|
14
|
+
const rule = {
|
|
15
|
+
id: f.ruleId,
|
|
16
|
+
name: f.ruleId.split(".").slice(-1)[0] ?? f.ruleId,
|
|
17
|
+
properties: { tags: [f.category, f.engine] },
|
|
18
|
+
};
|
|
19
|
+
if (f.references[0])
|
|
20
|
+
rule.helpUri = f.references[0];
|
|
21
|
+
rules.set(f.ruleId, rule);
|
|
22
|
+
}
|
|
23
|
+
const sarif = {
|
|
24
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
25
|
+
version: "2.1.0",
|
|
26
|
+
runs: [
|
|
27
|
+
{
|
|
28
|
+
tool: {
|
|
29
|
+
driver: {
|
|
30
|
+
name: r.tool.name,
|
|
31
|
+
version: r.tool.version,
|
|
32
|
+
informationUri: "https://github.com/micio86dev/code-intelligence",
|
|
33
|
+
rules: [...rules.values()],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
invocations: [
|
|
37
|
+
{
|
|
38
|
+
executionSuccessful: r.complete,
|
|
39
|
+
properties: {
|
|
40
|
+
repoConfigIgnored: r.config.ignored,
|
|
41
|
+
repoConfigInEffect: r.config.inEffect,
|
|
42
|
+
},
|
|
43
|
+
toolExecutionNotifications: r.engines
|
|
44
|
+
.filter((e) => e.status === "timeout" || e.status === "error" || e.status === "unavailable")
|
|
45
|
+
.map((e) => ({
|
|
46
|
+
level: "error",
|
|
47
|
+
message: { text: e.reason ?? `${e.engine}: ${e.status}` },
|
|
48
|
+
properties: { engine: e.engine },
|
|
49
|
+
})),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
results: r.findings.map((f) => ({
|
|
53
|
+
ruleId: f.ruleId,
|
|
54
|
+
level: LEVEL[f.severity],
|
|
55
|
+
message: { text: f.remediation ? `${f.message} ${f.remediation}` : f.message },
|
|
56
|
+
locations: [
|
|
57
|
+
{
|
|
58
|
+
physicalLocation: {
|
|
59
|
+
artifactLocation: { uri: f.file, uriBaseId: "%SRCROOT%" },
|
|
60
|
+
...(f.line !== null
|
|
61
|
+
? { region: { startLine: f.line, endLine: f.endLine ?? f.line } }
|
|
62
|
+
: {}),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
partialFingerprints: { "codeIntel/v1": f.fingerprint },
|
|
67
|
+
properties: { engine: f.engine, category: f.category, severity: f.severity },
|
|
68
|
+
})),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
return `${JSON.stringify(sarif, null, 2)}\n`;
|
|
73
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { SEVERITIES } from "../types.js";
|
|
2
|
+
const TAG = {
|
|
3
|
+
ok: "ok",
|
|
4
|
+
findings: "FOUND",
|
|
5
|
+
skipped: "skip",
|
|
6
|
+
unavailable: "MISSING",
|
|
7
|
+
timeout: "TIMEOUT",
|
|
8
|
+
error: "ERROR",
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Escape control and invisible characters: file names and messages come from the scanned repository and could
|
|
12
|
+
* forge report lines, move the cursor, or visually reorder/hide text (bidirectional overrides, zero-width
|
|
13
|
+
* and other format characters).
|
|
14
|
+
*/
|
|
15
|
+
const UNSAFE = /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff\ufff9-\ufffb]/g;
|
|
16
|
+
export function clean(s) {
|
|
17
|
+
return s.replace(UNSAFE, (c) => {
|
|
18
|
+
if (c === "\n")
|
|
19
|
+
return "\\n";
|
|
20
|
+
if (c === "\t")
|
|
21
|
+
return "\\t";
|
|
22
|
+
if (c === "\r")
|
|
23
|
+
return "\\r";
|
|
24
|
+
const code = c.charCodeAt(0);
|
|
25
|
+
return code <= 0xff
|
|
26
|
+
? `\\x${code.toString(16).padStart(2, "0")}`
|
|
27
|
+
: `\\u${code.toString(16).padStart(4, "0")}`;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const secs = (ms) => `${(ms / 1000).toFixed(2)}s`;
|
|
31
|
+
export function renderText(r) {
|
|
32
|
+
const L = [];
|
|
33
|
+
const t = r.target;
|
|
34
|
+
const scope = t.mode === "since" ? `since ${clean(t.ref ?? "")}` : t.mode;
|
|
35
|
+
L.push(`${r.tool.name} ${r.tool.version} | profile ${r.profile} | ${scope} | ${t.fileCount} file(s), ${t.excludedCount} excluded | ${secs(r.durationMs)}`);
|
|
36
|
+
L.push("");
|
|
37
|
+
L.push("Engines");
|
|
38
|
+
for (const e of r.engines) {
|
|
39
|
+
const ver = e.version ? ` ${e.version}` : "";
|
|
40
|
+
const detail = e.status === "ok" || e.status === "findings"
|
|
41
|
+
? `${e.findingCount} finding(s)${e.cached ? ", cached" : ""}, ${secs(e.durationMs)}`
|
|
42
|
+
: clean(e.reason ?? "");
|
|
43
|
+
L.push(` [${TAG[e.status].padEnd(7)}] ${(e.engine + ver).padEnd(22)} ${detail}`);
|
|
44
|
+
for (const w of e.warnings)
|
|
45
|
+
L.push(` warning: ${clean(w)}`);
|
|
46
|
+
}
|
|
47
|
+
L.push("");
|
|
48
|
+
if (r.findings.length === 0) {
|
|
49
|
+
L.push("No findings.");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
L.push(`Findings (${r.summary.total})`);
|
|
53
|
+
for (const f of r.findings) {
|
|
54
|
+
const loc = clean(f.line === null ? f.file : `${f.file}:${f.line}`);
|
|
55
|
+
L.push(` ${f.severity.toUpperCase().padEnd(8)} ${loc} [${f.engine}${f.alsoReportedBy.length ? ` +${f.alsoReportedBy.join(",")}` : ""}] ${clean(f.ruleId)}`);
|
|
56
|
+
L.push(` ${clean(f.message)}`);
|
|
57
|
+
if (f.remediation)
|
|
58
|
+
L.push(` fix: ${clean(f.remediation)}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
L.push("");
|
|
62
|
+
const counts = SEVERITIES.slice()
|
|
63
|
+
.reverse()
|
|
64
|
+
.filter((s) => r.summary.bySeverity[s] > 0)
|
|
65
|
+
.map((s) => `${r.summary.bySeverity[s]} ${s}`);
|
|
66
|
+
L.push(`Summary: ${counts.length ? counts.join(", ") : "clean"}`);
|
|
67
|
+
const sup = r.summary.suppressed;
|
|
68
|
+
if (sup.outsideChangedLines > 0) {
|
|
69
|
+
L.push(`Note: ${sup.outsideChangedLines} SAST finding(s) on unchanged lines were hidden (use --all or set "lineFilter": false to see them).`);
|
|
70
|
+
}
|
|
71
|
+
if (r.config.ignored) {
|
|
72
|
+
L.push("Note: the repository's own configuration was ignored (--ignore-repo-config).");
|
|
73
|
+
}
|
|
74
|
+
else if (r.config.inEffect.length > 0) {
|
|
75
|
+
L.push(`Note: repository-supplied configuration is in effect: ${r.config.inEffect.map(clean).join("; ")}. A repository can configure a scan to find less; use --ignore-repo-config for code you do not trust.`);
|
|
76
|
+
}
|
|
77
|
+
if (sup.baseline > 0)
|
|
78
|
+
L.push(`Note: ${sup.baseline} finding(s) matched the baseline and were hidden.`);
|
|
79
|
+
if (r.exitCode === 1)
|
|
80
|
+
L.push(`Result: FAIL (exit 1): findings at or above '${r.summary.failOn}'.`);
|
|
81
|
+
else if (r.exitCode === 3)
|
|
82
|
+
L.push("Result: INCOMPLETE (exit 3): no blocking findings, but some checks did not complete. Do not treat this as a pass.");
|
|
83
|
+
else
|
|
84
|
+
L.push("Result: PASS (exit 0)");
|
|
85
|
+
return `${L.join("\n")}\n`;
|
|
86
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const SEVERITIES = ["info", "low", "medium", "high", "critical"];
|
|
2
|
+
export const CATEGORIES = ["secrets", "sast", "deps", "architecture"];
|
|
3
|
+
export const PROFILES = ["quick", "deep"];
|
|
4
|
+
export function severityRank(s) {
|
|
5
|
+
return SEVERITIES.indexOf(s);
|
|
6
|
+
}
|
|
7
|
+
export function isSeverity(v) {
|
|
8
|
+
return typeof v === "string" && SEVERITIES.includes(v);
|
|
9
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
/** Read from package.json at runtime; works from both src/ (tests) and dist/ (installed). */
|
|
3
|
+
export const VERSION = (() => {
|
|
4
|
+
try {
|
|
5
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
6
|
+
return pkg.version;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return "0.0.0-unknown";
|
|
10
|
+
}
|
|
11
|
+
})();
|
|
12
|
+
export const TOOL_NAME = "code-intelligence";
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-intelligence",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Agent-agnostic CLI that runs mature security and quality scanners on what changed, normalizes the findings, and reports only what matters.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "micio86dev",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"code-intel": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"schema",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"THIRD_PARTY.md",
|
|
17
|
+
"CHANGELOG.md"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/micio86dev/code-intelligence.git"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/micio86dev/code-intelligence#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/micio86dev/code-intelligence/issues"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"security",
|
|
32
|
+
"sast",
|
|
33
|
+
"secrets",
|
|
34
|
+
"sarif",
|
|
35
|
+
"static-analysis",
|
|
36
|
+
"mutation-testing",
|
|
37
|
+
"ai-agents",
|
|
38
|
+
"cli"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node scripts/clean.mjs && tsc -p tsconfig.build.json",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "biome check .",
|
|
44
|
+
"format": "biome check --write .",
|
|
45
|
+
"test": "node --test \"test/unit/**/*.test.ts\"",
|
|
46
|
+
"test:integration": "node --test --test-concurrency=1 \"test/integration/**/*.test.ts\"",
|
|
47
|
+
"test:e2e": "node --test --test-concurrency=1 \"test/e2e/**/*.test.ts\"",
|
|
48
|
+
"test:all": "node --test --test-concurrency=1 \"test/**/*.test.ts\"",
|
|
49
|
+
"prepare": "node scripts/prepare.mjs",
|
|
50
|
+
"prepack": "npm run build",
|
|
51
|
+
"test:install": "node --test --test-concurrency=1 \"test/install/**/*.test.ts\""
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@biomejs/biome": "^2.6.8",
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"typescript": "^7.0.2"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/micio86dev/code-intelligence/main/schema/config.schema.json",
|
|
4
|
+
"title": "code-intelligence configuration (.code-intel.json)",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": { "type": "string" },
|
|
9
|
+
"failOn": {
|
|
10
|
+
"description": "Lowest severity that makes `scan` exit 1.",
|
|
11
|
+
"enum": ["info", "low", "medium", "high", "critical"],
|
|
12
|
+
"default": "high"
|
|
13
|
+
},
|
|
14
|
+
"exclude": {
|
|
15
|
+
"description": "Extra globs to skip, added to the built-in defaults (.git, node_modules, vendor, dist, build, coverage, .code-intel, *.min.js, *.map). Relative, no '..', max 200 chars, at most 3 '**'.",
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": { "type": "string", "maxLength": 200 }
|
|
18
|
+
},
|
|
19
|
+
"allowMissingEngines": {
|
|
20
|
+
"description": "Treat a missing engine as a warning instead of an incomplete scan (exit 3).",
|
|
21
|
+
"type": "boolean",
|
|
22
|
+
"default": false
|
|
23
|
+
},
|
|
24
|
+
"baseline": {
|
|
25
|
+
"description": "Repo-relative path of the baseline file written by `code-intel baseline`.",
|
|
26
|
+
"type": "string",
|
|
27
|
+
"default": ".code-intel/baseline.json"
|
|
28
|
+
},
|
|
29
|
+
"lineFilter": {
|
|
30
|
+
"description": "In changed-file scans, hide SAST findings on lines the change did not touch.",
|
|
31
|
+
"type": "boolean",
|
|
32
|
+
"default": true
|
|
33
|
+
},
|
|
34
|
+
"profiles": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"additionalProperties": false,
|
|
37
|
+
"properties": {
|
|
38
|
+
"quick": { "$ref": "#/definitions/profile" },
|
|
39
|
+
"deep": { "$ref": "#/definitions/profile" }
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"additionalProperties": false,
|
|
45
|
+
"properties": {
|
|
46
|
+
"gitleaks": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"additionalProperties": false,
|
|
49
|
+
"properties": {
|
|
50
|
+
"configPath": {
|
|
51
|
+
"description": "Repo-relative path of a gitleaks TOML config.",
|
|
52
|
+
"type": "string"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"semgrep": {
|
|
57
|
+
"type": "object",
|
|
58
|
+
"additionalProperties": false,
|
|
59
|
+
"properties": {
|
|
60
|
+
"configs": {
|
|
61
|
+
"description": "Registry ids like 'p/default' or repo-relative rule files/directories. URLs are not accepted.",
|
|
62
|
+
"type": "array",
|
|
63
|
+
"minItems": 1,
|
|
64
|
+
"items": { "type": "string" },
|
|
65
|
+
"default": ["p/default"]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"definitions": {
|
|
73
|
+
"profile": {
|
|
74
|
+
"type": "object",
|
|
75
|
+
"additionalProperties": false,
|
|
76
|
+
"properties": {
|
|
77
|
+
"engines": {
|
|
78
|
+
"description": "Categories (secrets, sast, deps, architecture) or engine names (gitleaks, semgrep, osv-scanner, trivy, ast-grep).",
|
|
79
|
+
"type": "array",
|
|
80
|
+
"items": { "type": "string" }
|
|
81
|
+
},
|
|
82
|
+
"timeoutMs": { "type": "integer", "minimum": 1000, "maximum": 3600000 }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|