@lintsure/core 0.1.0 → 0.1.3

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.
@@ -7,7 +7,7 @@ const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">
7
7
  const NAME = { "eu-ai-act": "EU AI Act", gdpr: "GDPR", soc2: "SOC 2", "iso-27001": "ISO/IEC 27001" };
8
8
  const STATUS = { gap: "Gap", partial: "Partial", met: "Met", outside: "Outside code" };
9
9
  const SEV = ["high", "medium", "low"];
10
- const SKIPPED = "node_modules, .git, dist, build, .next, venv, .venv, __pycache__, coverage";
10
+ const SKIPPED = "node_modules, .git, dist, build, out, .output, .next, .nuxt, .svelte-kit, .astro, .vercel, .netlify, .wrangler, .turbo, .cache, venv, .venv, __pycache__, coverage";
11
11
  function page(title, body, n, total, project) {
12
12
  return `<section class="page"><header><span>Lintsure readiness assessment · ${esc(project)}</span><span>Draft until reviewed by a person</span></header>
13
13
  <h2>${esc(title)}</h2>${body}<footer><span>Not an audit, a certification or legal advice.</span><span>Section ${n} of ${total}</span></footer></section>`;
@@ -51,7 +51,7 @@ export function toAssessmentHtml(r, opts) {
51
51
  ${fws.map((f) => `<tr><td>${NAME[f]}</td><td>${r.findings.filter((x) => x.status === "gap" && x.controls.some((c) => c.framework === f)).length}</td><td>${r.findings.filter((x) => x.status === "partial" && x.controls.some((c) => c.framework === f)).length}</td><td>${r.met.filter((m) => m.controls.some((c) => c.framework === f)).length}</td><td>${r.outside.filter((o) => o.framework === f).length}</td></tr>`).join("")}</table>
52
52
  <div class="callout"><b>What this summary does not mean.</b> ${esc(NOT_A_VERDICT)}</div>`;
53
53
  const method = `<h3>What was checked</h3>
54
- <p>Lintsure read ${r.filesChecked} files in the project folder on the computer or CI runner where it ran. Nothing was uploaded. It skipped these folders: ${SKIPPED}, and any file over 1 MB or binary.</p>
54
+ <p>Lintsure read ${r.filesChecked} files in the project folder on the computer or CI runner where it ran. Nothing was uploaded. It skipped these folders: ${SKIPPED}, any paths listed under ignore in lintsure.config.yaml, minified files, and any file over 1 MB or binary.</p>
55
55
  <h3>How results are produced</h3>
56
56
  <ul><li>A fixed set of rules (version ${esc(r.rulesVersion)}) looks for known patterns, line by line or file by file. It does not use a language model to decide results, so the same code gives the same findings.</li>
57
57
  <li><b>Gap</b>: a rule found code that may break a control. <b>Partial</b>: a likely problem that depends on context only you can confirm. <b>Met</b>: the rule ran and found nothing in the files it read. <b>Outside code</b>: work that code cannot show.</li>
@@ -1,3 +1,15 @@
1
- export declare const AGENT_GUIDANCE = "You are using Lintsure, a readiness tool that checks code against compliance frameworks.\n\nWhen you report Lintsure results:\n- Never say or imply the user is compliant, certified, approved, audit-ready, \"good to go\", or that they passed. Lintsure cannot decide that.\n- Never make a decision for the user. Present findings and options; the user chooses what to do.\n- Always ask for confirmation before changing any file, and before treating a framework as applicable.\n- Say that results cover code only, against Lintsure's reading of the publicly available text of each framework.\n- Always mention the items outside code (policies, training, contracts, evidence) that still need to be done before a full review.\n- Recommend that a qualified person review the results before any audit, certification or business decision.\n- A control marked Met only means Lintsure's rules found no problem in the files they read. Say so if you mention Met.";
1
+ import type { Control, Proposal } from "./types.js";
2
+ /** The approval rule every agent must follow before doing anything. Part of AGENT_GUIDANCE and every scan reply. */
3
+ export declare const APPROVAL_RULES = "Before you do anything (edit, create or delete a file, run a command, install a package, or treat a framework as applying), stop and present a proposal with all four parts:\n1. What you plan to do.\n2. Why: the problem and the rule or control it relates to.\n3. Where, exactly: the file and line, or the document and section.\n4. The benefit to the user if they approve it.\nThen ask the user to approve that one proposal and wait. Only a clear yes is approval. Silence, \"maybe\" or a question is not. Do only what was approved, then show what changed. One proposal at a time.";
4
+ /** Lays a finding out as a proposal a person can approve or decline. */
5
+ export declare function proposalFor(f: {
6
+ file: string;
7
+ line: number;
8
+ title: string;
9
+ fix: string;
10
+ note: string;
11
+ controls: Control[];
12
+ }): Proposal;
13
+ export declare const AGENT_GUIDANCE = "You are using Lintsure, a readiness tool that checks code against compliance frameworks.\n\nBefore you do anything (edit, create or delete a file, run a command, install a package, or treat a framework as applying), stop and present a proposal with all four parts:\n1. What you plan to do.\n2. Why: the problem and the rule or control it relates to.\n3. Where, exactly: the file and line, or the document and section.\n4. The benefit to the user if they approve it.\nThen ask the user to approve that one proposal and wait. Only a clear yes is approval. Silence, \"maybe\" or a question is not. Do only what was approved, then show what changed. One proposal at a time.\n\nWhen you report Lintsure results:\n- Never say or imply the user is compliant, certified, approved, audit-ready, \"good to go\", or that they passed. Lintsure cannot decide that.\n- Never make a decision for the user. Present findings and options; the user chooses what to do.\n- Every finding comes with a proposal (where, what, why, benefit). Show it as a proposal, never as something you have already done.\n- Say that results cover code only, against Lintsure's reading of the publicly available text of each framework.\n- Always mention the items outside code (policies, training, contracts, evidence) that still need to be done before a full review.\n- Recommend that a qualified person review the results before any audit, certification or business decision.\n- A control marked Met only means Lintsure's rules found no problem in the files they read. Say so if you mention Met.";
2
14
  /** Phrases that read as a verdict. Lintsure's own output must never claim these. */
3
15
  export declare const FORBIDDEN_CLAIMS: RegExp[];
@@ -1,11 +1,30 @@
1
- // How any agent should talk about Lintsure results. Sent to MCP clients as server instructions
2
- // and tested: the report text must never contain the phrases in FORBIDDEN_CLAIMS.
1
+ /** The approval rule every agent must follow before doing anything. Part of AGENT_GUIDANCE and every scan reply. */
2
+ export const APPROVAL_RULES = `Before you do anything (edit, create or delete a file, run a command, install a package, or treat a framework as applying), stop and present a proposal with all four parts:
3
+ 1. What you plan to do.
4
+ 2. Why: the problem and the rule or control it relates to.
5
+ 3. Where, exactly: the file and line, or the document and section.
6
+ 4. The benefit to the user if they approve it.
7
+ Then ask the user to approve that one proposal and wait. Only a clear yes is approval. Silence, "maybe" or a question is not. Do only what was approved, then show what changed. One proposal at a time.`;
8
+ const NAMES = { "eu-ai-act": "EU AI Act", gdpr: "GDPR", soc2: "SOC 2", "iso-27001": "ISO 27001" };
9
+ const refs = (cs) => cs.map((c) => `${NAMES[c.framework]} ${c.id}`).join(", ");
10
+ /** Lays a finding out as a proposal a person can approve or decline. */
11
+ export function proposalFor(f) {
12
+ return {
13
+ where: `${f.file}:${f.line}`,
14
+ what: f.fix,
15
+ why: `${f.title}. ${f.note} Relates to ${refs(f.controls)}.`,
16
+ benefit: `Removes this finding from the code side of ${refs(f.controls)}, so it no longer shows up when this file is reviewed. Work outside code may still be needed.`,
17
+ needsApproval: true,
18
+ };
19
+ }
3
20
  export const AGENT_GUIDANCE = `You are using Lintsure, a readiness tool that checks code against compliance frameworks.
4
21
 
22
+ ${APPROVAL_RULES}
23
+
5
24
  When you report Lintsure results:
6
25
  - Never say or imply the user is compliant, certified, approved, audit-ready, "good to go", or that they passed. Lintsure cannot decide that.
7
26
  - Never make a decision for the user. Present findings and options; the user chooses what to do.
8
- - Always ask for confirmation before changing any file, and before treating a framework as applicable.
27
+ - Every finding comes with a proposal (where, what, why, benefit). Show it as a proposal, never as something you have already done.
9
28
  - Say that results cover code only, against Lintsure's reading of the publicly available text of each framework.
10
29
  - Always mention the items outside code (policies, training, contracts, evidence) that still need to be done before a full review.
11
30
  - Recommend that a qualified person review the results before any audit, certification or business decision.
@@ -1,11 +1,13 @@
1
1
  import { rules } from "./rules/index.js";
2
2
  import type { FrameworkId, Report } from "./types.js";
3
+ /** Heading above every proposed change, in every report. Tests check it is there for each finding. */
4
+ export declare const PROPOSAL_HEADING = "Proposed change. Nothing changes until you approve it.";
3
5
  export * from "./types.js";
4
6
  export { rules };
5
7
  export * from "./guidance.js";
6
8
  export { toAssessmentHtml } from "./assessment.js";
7
9
  export * from "./knowledge/index.js";
8
- export declare const RULES_VERSION = "0.1.0";
10
+ export declare const RULES_VERSION = "0.1.3";
9
11
  /** Shown with every result, in every interface. Lintsure prepares; people decide. */
10
12
  export declare const DISCLAIMER: string;
11
13
  /** What a report must never be read as. Used in the report and by the MCP server. */
@@ -17,12 +19,15 @@ export declare const ALL_FRAMEWORKS: FrameworkId[];
17
19
  * Only the simple list form is supported:
18
20
  * frameworks:
19
21
  * - gdpr
20
- * Ids Lintsure doesn't check yet (for example "hipaa") are returned in `skipped`. */
22
+ * Ids Lintsure doesn't check yet (for example "hipaa") are returned in `skipped`.
23
+ * An `ignore:` list of paths (relative to the root, for example tests/ or fixtures/) is skipped by scan(). */
21
24
  export declare function readConfig(root: string): Promise<{
22
25
  frameworks: FrameworkId[] | null;
23
26
  skipped: string[];
27
+ ignore: string[];
24
28
  }>;
29
+ export declare const SKIP_DIRS: string[];
25
30
  /** Scout: list files to check, sorted so output order never depends on the file system. */
26
- export declare function listFiles(root: string): Promise<string[]>;
31
+ export declare function listFiles(root: string, ignore?: string[]): Promise<string[]>;
27
32
  export declare function scan(root: string, frameworks?: FrameworkId[]): Promise<Report>;
28
33
  export declare function toMarkdown(r: Report): string;
package/dist/src/index.js CHANGED
@@ -4,12 +4,15 @@ import { readdir, readFile } from "node:fs/promises";
4
4
  import { extname, join, relative, sep } from "node:path";
5
5
  import { outsideFor } from "./knowledge/index.js";
6
6
  import { rules } from "./rules/index.js";
7
+ import { proposalFor } from "./guidance.js";
8
+ /** Heading above every proposed change, in every report. Tests check it is there for each finding. */
9
+ export const PROPOSAL_HEADING = "Proposed change. Nothing changes until you approve it.";
7
10
  export * from "./types.js";
8
11
  export { rules };
9
12
  export * from "./guidance.js";
10
13
  export { toAssessmentHtml } from "./assessment.js";
11
14
  export * from "./knowledge/index.js";
12
- export const RULES_VERSION = "0.1.0";
15
+ export const RULES_VERSION = "0.1.3";
13
16
  /** Shown with every result, in every interface. Lintsure prepares; people decide. */
14
17
  export const DISCLAIMER = "Lintsure is a readiness tool, not an audit, a certification or legal advice. " +
15
18
  "Its rules reflect our reading of the publicly available text of each framework, and they check code only. " +
@@ -34,46 +37,64 @@ export const ALL_FRAMEWORKS = ["gdpr", "soc2", "iso-27001", "eu-ai-act"];
34
37
  * Only the simple list form is supported:
35
38
  * frameworks:
36
39
  * - gdpr
37
- * Ids Lintsure doesn't check yet (for example "hipaa") are returned in `skipped`. */
40
+ * Ids Lintsure doesn't check yet (for example "hipaa") are returned in `skipped`.
41
+ * An `ignore:` list of paths (relative to the root, for example tests/ or fixtures/) is skipped by scan(). */
38
42
  export async function readConfig(root) {
39
43
  let text;
40
44
  try {
41
45
  text = await readFile(join(root, "lintsure.config.yaml"), "utf8");
42
46
  }
43
47
  catch {
44
- return { frameworks: null, skipped: [] };
48
+ return { frameworks: null, skipped: [], ignore: [] };
45
49
  }
46
- const ids = [];
47
- let inList = false;
50
+ const lists = { frameworks: [], ignore: [] };
51
+ let key = "";
52
+ let emptyFw = false;
48
53
  for (const raw of text.split(/\r?\n/)) {
49
54
  const line = raw.replace(/#.*$/, "").trimEnd();
50
- if (/^frameworks\s*:\s*\[\s*\]\s*$/.test(line))
51
- return { frameworks: [], skipped: [] };
52
- if (/^frameworks\s*:\s*$/.test(line)) {
53
- inList = true;
55
+ if (/^frameworks\s*:\s*\[\s*\]\s*$/.test(line)) {
56
+ emptyFw = true;
57
+ key = "";
54
58
  continue;
55
59
  }
56
- if (inList) {
57
- const m = line.match(/^\s+-\s*([\w-]+)\s*$/);
60
+ const head = line.match(/^(frameworks|ignore)\s*:\s*$/);
61
+ if (head) {
62
+ key = head[1];
63
+ continue;
64
+ }
65
+ if (key) {
66
+ const m = line.match(/^\s+-\s*["']?([^"'\s]+)["']?\s*$/);
58
67
  if (m)
59
- ids.push(m[1]);
68
+ lists[key].push(m[1]);
60
69
  else if (line.trim())
61
- inList = false;
70
+ key = "";
62
71
  }
63
72
  }
73
+ const ignore = lists.ignore.map((p) => p.replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+$/, ""));
74
+ if (emptyFw)
75
+ return { frameworks: [], skipped: [], ignore };
76
+ const ids = lists.frameworks;
77
+ if (!ids.length)
78
+ return { frameworks: null, skipped: [], ignore };
64
79
  const known = ids.filter((i) => ALL_FRAMEWORKS.includes(i));
65
- return { frameworks: known, skipped: ids.filter((i) => !known.includes(i)) };
80
+ return { frameworks: known, skipped: ids.filter((i) => !known.includes(i)), ignore };
66
81
  }
67
- const SKIP = new Set(["node_modules", ".git", "dist", "build", ".next", "venv", ".venv", "__pycache__", "coverage"]);
82
+ // Dependencies, build output and caches: generated code, not code you wrote.
83
+ export const SKIP_DIRS = ["node_modules", ".git", "dist", "build", "out", ".output", ".next", ".nuxt", ".svelte-kit", ".astro", ".vercel", ".netlify", ".wrangler", ".turbo", ".cache", "venv", ".venv", "__pycache__", "coverage"];
84
+ const SKIP = new Set(SKIP_DIRS);
85
+ const MAX_LINE = 1000; // a line this long means minified or generated code
68
86
  const MAX_BYTES = 1_000_000;
69
87
  /** Scout: list files to check, sorted so output order never depends on the file system. */
70
- export async function listFiles(root) {
88
+ export async function listFiles(root, ignore = []) {
71
89
  const out = [];
90
+ const ignored = (p) => { const r = relative(root, p).split(sep).join("/"); return ignore.some((i) => r === i || r.startsWith(i + "/")); };
72
91
  async function walk(dir) {
73
92
  for (const e of await readdir(dir, { withFileTypes: true })) {
74
- if (SKIP.has(e.name))
93
+ if (SKIP.has(e.name) || /\.min\.(js|css)$/.test(e.name))
75
94
  continue;
76
95
  const p = join(dir, e.name);
96
+ if (ignored(p))
97
+ continue;
77
98
  if (e.isDirectory())
78
99
  await walk(p);
79
100
  else if (e.isFile())
@@ -87,7 +108,7 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS) {
87
108
  const active = rules.filter((r) => r.controls.some((c) => frameworks.includes(c.framework)));
88
109
  const findings = [];
89
110
  let filesChecked = 0;
90
- for (const abs of await listFiles(root)) {
111
+ for (const abs of await listFiles(root, (await readConfig(root)).ignore)) {
91
112
  const ext = extname(abs) || (abs.endsWith(".env") ? ".env" : "");
92
113
  const relevant = active.filter((r) => r.extensions.includes(ext));
93
114
  if (!relevant.length)
@@ -95,13 +116,18 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS) {
95
116
  const buf = await readFile(abs);
96
117
  if (buf.length > MAX_BYTES || buf.includes(0))
97
118
  continue; // skip big or binary files
98
- filesChecked++;
99
119
  const file = relative(root, abs).split(sep).join("/");
100
120
  const lines = buf.toString("utf8").split(/\r?\n/);
101
- const add = (r, line) => findings.push({
102
- ruleId: r.id, file, line, status: r.status, severity: r.severity, title: r.title,
103
- controls: r.controls.filter((c) => frameworks.includes(c.framework)), fix: r.fix, note: r.note,
104
- });
121
+ if (lines.some((l) => l.length > MAX_LINE))
122
+ continue; // minified or generated
123
+ filesChecked++;
124
+ const add = (r, line) => {
125
+ const controls = r.controls.filter((c) => frameworks.includes(c.framework));
126
+ findings.push({
127
+ ruleId: r.id, file, line, status: r.status, severity: r.severity, title: r.title, controls, fix: r.fix, note: r.note,
128
+ proposal: proposalFor({ file, line, title: r.title, fix: r.fix, note: r.note, controls }),
129
+ });
130
+ };
105
131
  for (const r of relevant) {
106
132
  if (r.test)
107
133
  lines.forEach((text, i) => { if (r.test(text))
@@ -139,7 +165,7 @@ export function toMarkdown(r) {
139
165
  if (!r.findings.length)
140
166
  lines.push("No issues found by the current rules.", "");
141
167
  for (const f of r.findings)
142
- lines.push(`### ${LABEL[f.status]} · \`${f.file}:${f.line}\``, `**${f.title}** (${f.severity})`, "", `- Rules: ${ctl(f.controls)}`, `- Fix: ${f.fix}`, `- Auditor note: ${f.note}`, "");
168
+ lines.push(`### ${LABEL[f.status]} · \`${f.file}:${f.line}\``, `**${f.title}** (${f.severity})`, "", `- Rules: ${ctl(f.controls)}`, `- Auditor note: ${f.note}`, "", `**${PROPOSAL_HEADING}**`, "", `- Where: \`${f.proposal.where}\``, `- What: ${f.proposal.what}`, `- Why: ${f.proposal.why}`, `- Benefit: ${f.proposal.benefit}`, "");
143
169
  lines.push(`## Met (${r.met.length})`, "", ...r.met.map((m) => `- ${m.title} · ${ctl(m.controls)}`), "");
144
170
  lines.push(`## Outside code (${r.outside.length})`, "", "Code can't prove these. They still need to be done before a full review.", "", ...r.outside.map((o) => `- ${o.framework.toUpperCase()} ${o.control} · ${o.title}: ${o.evidence}`), "");
145
171
  lines.push("## What to do next", "", ...nextSteps(r).map((s, i) => `${i + 1}. ${s}`), "");
@@ -2,6 +2,8 @@ const CODE = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py"];
2
2
  // Beta: mapped by us, awaiting review by a qualified compliance professional.
3
3
  const DRAFT = { mappedBy: "beta", reviewedAt: "pending" };
4
4
  const LOG_CALL = /\b(console\.(log|info|warn|error|debug)|logger\.\w+|log\.(info|warn|error|debug)|logging\.\w+|print)\s*\(/;
5
+ // Drops the text of string literals but keeps interpolations, so "email error" is ignored and `${user.email}` or f"{user.email}" is not.
6
+ const codeOnly = (l) => l.replace(/(["'`])(?:\\.|(?!\1).)*\1/g, (s) => (s.match(/\{[^}]*\}/g) ?? []).join(" "));
5
7
  const PII = /\b(e-?mail|phone|ssn|social_?security|passport|date_?of_?birth|dob|password|passwd|credit_?card|card_?number|iban)\b/i;
6
8
  export const rules = [
7
9
  {
@@ -16,7 +18,7 @@ export const rules = [
16
18
  fix: "Mask or remove the personal field before logging, for example mask(user.email).",
17
19
  note: "Logs are copied to many places and kept for a long time. Personal data in them is hard to find and delete.",
18
20
  extensions: CODE,
19
- test: (l) => LOG_CALL.test(l) && PII.test(l),
21
+ test: (l) => LOG_CALL.test(l) && PII.test(codeOnly(l)),
20
22
  ...DRAFT,
21
23
  },
22
24
  {
@@ -107,7 +109,7 @@ export const rules = [
107
109
  fix: "Remove the override and trust a proper certificate. For self-signed certs in tests, scope it to the test only.",
108
110
  note: "With checks off, anyone on the network path can read or change the traffic.",
109
111
  extensions: [...CODE, ".env"],
110
- test: (l) => /rejectUnauthorized\s*:\s*false|NODE_TLS_REJECT_UNAUTHORIZED\s*[=:]\s*["']?0|verify\s*=\s*False|InsecureSkipVerify\s*:\s*true|CERT_NONE/.test(l),
112
+ test: (l) => /rejectUnauthorized\s*:\s*false|NODE_TLS_REJECT_UNAUTHORIZED\s*[=:]\s*["']?0|\b(requests|httpx|session|client|Client|AsyncClient|urlopen)\b.*\bverify\s*=\s*False|InsecureSkipVerify\s*:\s*true|CERT_NONE/.test(l),
111
113
  ...DRAFT,
112
114
  },
113
115
  {
@@ -25,6 +25,19 @@ export interface Rule {
25
25
  mappedBy: string;
26
26
  reviewedAt: string;
27
27
  }
28
+ /** A change Lintsure suggests. It is only ever a proposal: a person must approve it first. */
29
+ export interface Proposal {
30
+ /** Exactly where: "file:line". */
31
+ where: string;
32
+ /** What would change. */
33
+ what: string;
34
+ /** Why: the problem and the controls it relates to. */
35
+ why: string;
36
+ /** What the person gains if they approve it. */
37
+ benefit: string;
38
+ /** Always true. Nothing changes without an explicit yes. */
39
+ needsApproval: true;
40
+ }
28
41
  export interface Finding {
29
42
  ruleId: string;
30
43
  file: string;
@@ -35,6 +48,8 @@ export interface Finding {
35
48
  controls: Control[];
36
49
  fix: string;
37
50
  note: string;
51
+ /** The suggested change, laid out for a person to approve or decline. */
52
+ proposal: Proposal;
38
53
  }
39
54
  export interface OutsideItem {
40
55
  framework: FrameworkId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lintsure/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Lintsure engine: rules, framework knowledge and reports for readiness checks of AI-written code. Not an audit or legal advice.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",