lintsure 0.3.7 → 0.3.9

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.
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
+ /** Changed line numbers per file from `git diff -U0` output. Pure. */
3
+ export declare function parseDiff(text: string): Record<string, number[]>;
2
4
  /** Splits --flag=value into two tokens and checks every flag, so a CI gate can't silently fail open
3
5
  * because of a typo or a bad value (improvement review, P25). Returns an error message or the parsed args. Pure. */
4
6
  export declare function parseArgs(argv: string[]): {
package/dist/src/index.js CHANGED
@@ -1,15 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  // npx lintsure scan [path] [options] npx lintsure baseline [path]
3
3
  // Writes reports into the current folder. Never sends anything over the network.
4
- import { mkdir, writeFile } from "node:fs/promises";
4
+ import { execFileSync } from "node:child_process";
5
+ import { access, mkdir, writeFile } from "node:fs/promises";
5
6
  import { basename, dirname, join, resolve } from "node:path";
6
- import { ALL_FRAMEWORKS, BASELINE_FILE, DISCLAIMER, RULES_VERSION, isOpen, nextSteps, readConfig, scan, toAssessmentHtml, toBaseline, toMarkdown, toSarif } from "@lintsure/core";
7
+ import { createInterface } from "node:readline/promises";
8
+ import { ALL_FRAMEWORKS, BASELINE_FILE, DISCLAIMER, RULES_VERSION, classify, isOpen, nextSteps, readConfig, scan, toAssessmentHtml, toBaseline, toMarkdown, toSarif } from "@lintsure/core";
7
9
  const HELP = `lintsure scan [path] [options]
8
10
  lintsure baseline [path]
11
+ lintsure init [path] Three questions, saved to lintsure.config.yaml
12
+ lintsure info [path] Show the settings a scan would use, and where each comes from
9
13
 
10
14
  scan options:
11
15
  --framework <ids> Comma list: ${ALL_FRAMEWORKS.join(", ")}
12
16
  (default: lintsure.config.yaml if present, else all)
17
+ --all Also list medium-confidence findings (held back by default)
18
+ --diff <base> Only list findings on lines changed since <base>, e.g. origin/main
13
19
  --json Also write lintsure-report.json
14
20
  --sarif Also write lintsure.sarif (for GitHub code scanning and editors)
15
21
  --report Also write lintsure-assessment.html, a multi-page report
@@ -32,8 +38,94 @@ fingerprint from lintsure-report.json, your reason, your name and the date.
32
38
 
33
39
  ${DISCLAIMER}
34
40
  Lintsure never sends your code anywhere.`;
35
- const VALUE_FLAGS = ["--framework", "--fail-on", "--project"];
36
- const BOOL_FLAGS = ["--json", "--sarif", "--report", "--new-only", "--github", "--save-record"];
41
+ const VALUE_FLAGS = ["--framework", "--fail-on", "--project", "--diff"];
42
+ const BOOL_FLAGS = ["--json", "--sarif", "--report", "--new-only", "--github", "--save-record", "--all"];
43
+ /** Changed line numbers per file from `git diff -U0` output. Pure. */
44
+ export function parseDiff(text) {
45
+ const out = {};
46
+ let file = null;
47
+ for (const l of text.split(/\r?\n/)) {
48
+ if (l.startsWith("+++ ")) {
49
+ file = l === "+++ /dev/null" ? null : l.slice(4).replace(/^b\//, "");
50
+ continue;
51
+ }
52
+ const h = file && l.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/);
53
+ if (h) {
54
+ const start = +h[1], n = h[2] === undefined ? 1 : +h[2];
55
+ for (let i = 0; i < n; i++)
56
+ (out[file] ??= []).push(start + i);
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+ const FRAMEWORK_NAMES = { "owasp-top10": "OWASP Top 10", "cwe-top25": "CWE Top 25", gdpr: "GDPR", "eu-ai-act": "EU AI Act", "owasp-llm": "OWASP Top 10 for LLM apps", cra: "EU Cyber Resilience Act" };
62
+ /** First-run setup: three questions, saved once, never asked in CI. */
63
+ async function init(path) {
64
+ const file = join(path, "lintsure.config.yaml");
65
+ if (await access(file).then(() => true, () => false)) {
66
+ console.error("lintsure.config.yaml already exists. Edit it, or delete it and run init again.");
67
+ return 2;
68
+ }
69
+ if (!process.stdin.isTTY || process.env.CI) {
70
+ console.error("init asks questions, so it needs a terminal. In CI, commit a lintsure.config.yaml instead.");
71
+ return 2;
72
+ }
73
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
74
+ const pick = async (q, options) => {
75
+ console.log(`\n${q}`);
76
+ options.forEach((o, i) => console.log(` ${i + 1}. ${o}`));
77
+ for (;;) {
78
+ const a = Number((await rl.question("> ")).trim() || "1");
79
+ if (a >= 1 && a <= options.length)
80
+ return a;
81
+ console.log(`Type a number from 1 to ${options.length}.`);
82
+ }
83
+ };
84
+ console.log("Lintsure setup: 3 questions. Press Enter for the first answer.");
85
+ const what = await pick("1. What should Lintsure check?", ["Security only (OWASP Top 10, CWE Top 25)", "Security and privacy (adds GDPR)", "Everything (all six frameworks)", "Let me pick"]);
86
+ let chosen = what === 1 ? ["owasp-top10", "cwe-top25"] : what === 2 ? ["owasp-top10", "cwe-top25", "gdpr"] : [...ALL_FRAMEWORKS];
87
+ if (what === 4) {
88
+ console.log("\nType the numbers you want, separated by commas, or press Enter for all:");
89
+ ALL_FRAMEWORKS.forEach((f, i) => console.log(` ${i + 1}. ${FRAMEWORK_NAMES[f] ?? f}`));
90
+ const a = (await rl.question("> ")).trim();
91
+ chosen = a ? a.split(",").map((x) => ALL_FRAMEWORKS[Number(x.trim()) - 1]).filter(Boolean) : [...ALL_FRAMEWORKS];
92
+ }
93
+ const why = [];
94
+ if (what !== 3 && what !== 4) {
95
+ const ai = (await pick("2. Does your app use AI (chat, generated text or images)?", ["Yes", "No"])) === 1;
96
+ const eu = (await pick("3. Do you have, or plan to have, users in the EU?", ["Yes", "No or not sure"])) === 1;
97
+ for (const c of classify({ usesAI: ai, generativeAI: ai, interactsWithPeople: ai, euUsers: eu, personalData: eu }))
98
+ if (!chosen.includes(c.framework)) {
99
+ chosen.push(c.framework);
100
+ why.push(`${FRAMEWORK_NAMES[c.framework] ?? c.framework}: ${c.reason}`);
101
+ }
102
+ }
103
+ rl.close();
104
+ if (!chosen.length)
105
+ chosen = [...ALL_FRAMEWORKS];
106
+ await writeFile(file, `# Written by lintsure init. Edit freely; run "lintsure info" to check it.\nframeworks:\n${chosen.map((f) => ` - ${f}`).join("\n")}\n`);
107
+ console.log(`\nSaved lintsure.config.yaml with: ${chosen.map((f) => FRAMEWORK_NAMES[f] ?? f).join(", ")}.`);
108
+ why.forEach((w) => console.log(` Added ${w}`));
109
+ console.log("CI and your teammates will use this file and never see the questions. Run init again after deleting it to change your answers.");
110
+ return 0;
111
+ }
112
+ async function info(path) {
113
+ const c = await readConfig(path);
114
+ const from = await access(join(path, "lintsure.config.yaml")).then(() => "lintsure.config.yaml", () => "default (no lintsure.config.yaml)");
115
+ console.log(`Settings for ${path}`);
116
+ console.log(` frameworks ${(c.frameworks ?? ALL_FRAMEWORKS).join(", ")} (${c.frameworks ? from : "default: all"})`);
117
+ if (c.skipped.length)
118
+ console.log(` not checked yet ${c.skipped.join(", ")}`);
119
+ console.log(` ignore ${c.ignore.join(", ") || "-"}`);
120
+ console.log(` rules ${Object.entries(c.rules).map(([k, v]) => `${k}: ${v}`).join(", ") || "-"}`);
121
+ console.log(` show ${c.show === "all" ? "all findings" : "high confidence only (use --all or show: all for the rest)"}`);
122
+ if (c.problems.length) {
123
+ console.error("Problems in lintsure.config.yaml:");
124
+ c.problems.forEach((p) => console.error(` ${p}`));
125
+ return 2;
126
+ }
127
+ return 0;
128
+ }
37
129
  const FAIL_ON = ["gap", "partial"];
38
130
  /** Splits --flag=value into two tokens and checks every flag, so a CI gate can't silently fail open
39
131
  * because of a typo or a bad value (improvement review, P25). Returns an error message or the parsed args. Pure. */
@@ -62,6 +154,8 @@ export function parseArgs(argv) {
62
154
  }
63
155
  async function main(argv) {
64
156
  const [cmd, ...raw] = argv;
157
+ if (cmd === "init" || cmd === "info")
158
+ return (cmd === "init" ? init : info)(resolve(raw.find((a) => !a.startsWith("--")) ?? "."));
65
159
  if (cmd !== "scan" && cmd !== "baseline") {
66
160
  console.log(HELP);
67
161
  return cmd ? 2 : 0;
@@ -80,12 +174,28 @@ async function main(argv) {
80
174
  console.error(`Unknown framework: ${bad.join(", ")}`);
81
175
  return 2;
82
176
  }
83
- const config = wanted ? null : await readConfig(path);
84
- if (config?.skipped.length)
177
+ const config = await readConfig(path);
178
+ if (config.problems.length) {
179
+ console.error("Problems in lintsure.config.yaml (fix them so the scan checks what you meant):");
180
+ config.problems.forEach((p) => console.error(` ${p}`));
181
+ return 2;
182
+ }
183
+ if (!wanted && config.skipped.length)
85
184
  console.log(`Skipping, not checked yet: ${config.skipped.join(", ")}`);
86
- const why = wanted ? "Chosen with --framework on the command line." : config?.frameworks ? "Listed in lintsure.config.yaml." : undefined;
185
+ const why = wanted ? "Chosen with --framework on the command line." : config.frameworks ? "Listed in lintsure.config.yaml." : undefined;
87
186
  const source = process.env.GITHUB_ACTIONS || process.env.CI ? "ci" : "cli";
88
- const report = await scan(path, wanted ?? config?.frameworks ?? ALL_FRAMEWORKS, { why, source });
187
+ const base = flag("--diff");
188
+ let changed;
189
+ if (base) {
190
+ try {
191
+ changed = { base, lines: parseDiff(execFileSync("git", ["diff", "-U0", "--no-color", "--no-ext-diff", "--relative", base, "--"], { cwd: path, encoding: "utf8", maxBuffer: 64 << 20 })) };
192
+ }
193
+ catch {
194
+ console.error(`--diff: git could not compare with "${base}". Fetch it first (for example git fetch origin main).`);
195
+ return 2;
196
+ }
197
+ }
198
+ const report = await scan(path, wanted ?? config.frameworks ?? ALL_FRAMEWORKS, { why, source, all: rest.includes("--all") || undefined, changed });
89
199
  const date = new Date().toISOString().slice(0, 10);
90
200
  if (cmd === "baseline") {
91
201
  const file = join(path, BASELINE_FILE);
@@ -116,6 +226,10 @@ async function main(argv) {
116
226
  console.log(`Record ${report.record.id} · ${report.record.createdAt.replace("T", " ").slice(0, 16)} UTC · ${report.record.counts.checkPoints} check points`);
117
227
  // A check mark only when nothing is open: "✓ 3 gaps" read as a pass.
118
228
  console.log(`${open.length ? "!" : "✓"} ${open.length} open findings · ${n("gap")} gap · ${n("partial")} partial${accepted ? ` · ${accepted} accepted` : ""} · ${report.met.length} rules met · ${report.outside.length} outside code`);
229
+ if (report.diffBase)
230
+ console.log(` Only lines changed since ${report.diffBase}`);
231
+ if (report.held)
232
+ console.log(` ${report.held} more at medium confidence: run with --all to see ${report.held === 1 ? "it" : "them"}`);
119
233
  if (report.baseline)
120
234
  console.log(` Since the baseline of ${report.baseline.created}: ${report.baseline.newCount} new, ${report.baseline.fixed.length} fixed, ${report.baseline.unchangedCount} unchanged`);
121
235
  for (const f of report.findings)
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "lintsure",
3
- "version": "0.3.7",
4
- "description": "Readiness checks for the code your AI writes: EU AI Act, GDPR, OWASP, CWE Top 25, EU Cyber Resilience Act. Runs locally. Not an audit or legal advice.",
5
- "license": "Apache-2.0",
6
- "type": "module",
7
- "bin": {
8
- "lintsure": "dist/src/index.js"
9
- },
10
- "files": [
11
- "dist/src",
12
- "README.md",
13
- "LICENSE"
14
- ],
15
- "dependencies": {
16
- "@lintsure/core": "0.3.7"
17
- },
18
- "author": "Lintsure <hello@lintsure.com>",
19
- "homepage": "https://lintsure.com/docs",
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/lintsure/lintsure.git"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/lintsure/lintsure/issues",
26
- "email": "support@lintsure.com"
27
- },
28
- "engines": {
29
- "node": ">=22"
30
- },
31
- "publishConfig": {
32
- "access": "public"
33
- },
34
- "keywords": [
35
- "compliance",
36
- "gdpr",
37
- "eu-ai-act",
38
- "mcp",
39
- "static-analysis",
40
- "readiness"
41
- ],
42
- "scripts": {
43
- "prepublishOnly": "cd ../.. && npm test"
44
- }
45
- }
1
+ {
2
+ "name": "lintsure",
3
+ "version": "0.3.9",
4
+ "description": "Readiness checks for the code your AI writes: EU AI Act, GDPR, OWASP, CWE Top 25, EU Cyber Resilience Act. Runs locally. Not an audit or legal advice.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "bin": {
8
+ "lintsure": "dist/src/index.js"
9
+ },
10
+ "files": [
11
+ "dist/src",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "dependencies": {
16
+ "@lintsure/core": "0.3.9"
17
+ },
18
+ "author": "Lintsure <hello@lintsure.com>",
19
+ "homepage": "https://lintsure.com/docs",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/lintsure/lintsure.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/lintsure/lintsure/issues",
26
+ "email": "support@lintsure.com"
27
+ },
28
+ "engines": {
29
+ "node": ">=22"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "keywords": [
35
+ "compliance",
36
+ "gdpr",
37
+ "eu-ai-act",
38
+ "mcp",
39
+ "static-analysis",
40
+ "readiness"
41
+ ],
42
+ "scripts": {
43
+ "prepublishOnly": "cd ../.. && npm test"
44
+ }
45
+ }