lintsure 0.3.14 → 0.3.15

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 CHANGED
@@ -1,21 +1,35 @@
1
- # lintsure
2
-
3
- Readiness checks for the code your AI writes: EU AI Act, GDPR, OWASP Top 10, OWASP LLM Top 10, CWE Top 25 and the EU Cyber Resilience Act. Runs on your machine and never uploads your code.
4
-
5
- > **Lintsure is a readiness tool, not an audit, a certification or legal advice.** It checks code only, against our reading of the publicly available text of each framework. Work outside code still has to be done, and a qualified person should review the results before any audit or decision.
6
-
7
- ```bash
8
- npx lintsure scan
9
- npx lintsure scan ./my-app --framework gdpr,owasp-top10 --json --fail-on gap
10
- npx lintsure scan --report --project "My app" # multi-page assessment to review and sign
11
- npx lintsure setup --yes # add Lintsure to the coding agents this project uses
12
- npx lintsure status # check Node, config, rules and agents
13
- ```
14
-
15
- Every finding shows the file and line, the framework controls it may affect, a suggested fix and a plain note on why it matters.
16
-
17
- - Docs: https://lintsure.com/docs/cli
18
- - Source: https://github.com/lintsure/lintsure
19
- - Disclaimer: https://lintsure.com/disclaimer
20
-
21
- If it helps you, please ⭐ the repo, share it, or [send a review](https://lintsure.com/review). Apache-2.0.
1
+ # lintsure
2
+
3
+ **Keep your AI coding agents on track and in context.** Lintsure checks the code Claude Code, Cursor, Codex and other agents write, and holds them to your project's rules. It finds secrets in source, databases left open, unsafe agent settings, request data reaching a query or a shell, and more, and maps each finding to OWASP, GDPR and the EU AI Act. It runs on your machine and never uploads your code.
4
+
5
+ ```bash
6
+ npx lintsure scan # check the project in this folder
7
+ npx lintsure setup --yes # connect it to the coding agents this project uses
8
+ npx lintsure skills --yes # add the skills that tell the agent when to use it
9
+ npx lintsure scan --fail-on gap # fail a CI job on clear problems
10
+ npx lintsure baseline # then later scans show only what's new
11
+ npx lintsure scan --report --project "My app" # multi-page assessment to review and sign
12
+ npx lintsure status # check Node, config, rules and agents
13
+ ```
14
+
15
+ ```text
16
+ ! 3 open findings · 2 gap · 1 partial · 61 rules met · 30 outside code
17
+ Read 214 files
18
+ partial src/billing.ts:4 Data sent over plain HTTP
19
+ gap src/config.ts:2 Secret or private key committed to source
20
+ gap src/users.ts:5 Personal data written to logs
21
+ ```
22
+
23
+ Every finding shows the file and line, a suggested fix, a plain note on why it matters, and the framework controls it may affect. It also says which files it couldn't read, so "nothing found" never means "checked everything".
24
+
25
+ In Claude Code, the [plugin](https://github.com/lintsure/claude-plugin) adds guards that work while the agent edits: Drift Guard, Danger Guard, Secret Guard and Loop Guard.
26
+
27
+ With Docker: `docker run --rm -v "$PWD:/work" -w /work node:22-slim npx -y lintsure scan`
28
+
29
+ > **Lintsure is a readiness tool, not an audit, a certification or legal advice.** It checks code only, against our reading of the publicly available text of each framework. Work outside code still has to be done, and a qualified person should review the results before any audit or decision.
30
+
31
+ - Docs: https://lintsure.com/docs/cli
32
+ - Source: https://github.com/lintsure/lintsure
33
+ - Disclaimer: https://lintsure.com/disclaimer
34
+
35
+ If it helps you, please star the repo, share it, or [send a review](https://lintsure.com/review). Apache-2.0.
@@ -2,11 +2,14 @@ export interface Agent {
2
2
  id: string;
3
3
  name: string;
4
4
  file: string;
5
- key: "mcpServers" | "servers";
5
+ key: "mcpServers" | "servers" | "mcp_servers";
6
6
  marker: string;
7
7
  }
8
8
  /** Project-level MCP config files. `marker` is the folder that shows the project uses that agent. */
9
9
  export declare const AGENTS: Agent[];
10
+ /** For agents with no config file in the project (they are set up in their own app or account): what to enter there. */
11
+ export declare const MANUAL: () => string;
12
+ export declare const tomlEntry: () => string;
10
13
  export declare const serverEntry: (a: Agent) => {
11
14
  command: string;
12
15
  args: string[];
@@ -22,6 +25,10 @@ export declare function plan(root: string, a: Agent): Promise<{
22
25
  }>;
23
26
  /** JSON in the same style as the file it replaces: its indent (tabs or N spaces) and a leading byte-order mark. Pure. */
24
27
  export declare function writeJson(original: string, value: unknown): string;
28
+ /** The agents this project already uses: the ones whose folder or config file is here. */
29
+ export declare function detected(root: string): Promise<Agent[]>;
30
+ /** What connecting does, in plain words, for the screens that offer it. */
31
+ export declare const CONNECT_NOTE = "Connecting adds one entry to the agent's config file in this project. It tells the agent how to start\nLintsure, so the agent can check code and explain findings itself. Installing the lintsure command does not\ndo this: an agent only knows Lintsure once it is connected.";
25
32
  /** Agents to set up: the ones named, or the ones whose folder exists, with Claude Code as the default. */
26
33
  export declare function pick(root: string, names?: string[]): Promise<Agent[] | string>;
27
34
  export declare function setup(root: string, agents: Agent[], apply: boolean): Promise<number>;
@@ -11,7 +11,14 @@ export const AGENTS = [
11
11
  { id: "cursor", name: "Cursor", file: ".cursor/mcp.json", key: "mcpServers", marker: ".cursor" },
12
12
  { id: "vscode", name: "VS Code (Copilot)", file: ".vscode/mcp.json", key: "servers", marker: ".vscode" },
13
13
  { id: "gemini", name: "Gemini CLI", file: ".gemini/settings.json", key: "mcpServers", marker: ".gemini" },
14
+ // Codex keeps its config as TOML, one table per server. It reads a project's file only for projects marked as trusted.
15
+ { id: "codex", name: "Codex", file: ".codex/config.toml", key: "mcp_servers", marker: ".codex" },
14
16
  ];
17
+ /** For agents with no config file in the project (they are set up in their own app or account): what to enter there. */
18
+ export const MANUAL = () => `Some agents are set up in their own settings, not by a file in the project: Devin, Windsurf, Zed, Cline and\nothers. Add an MCP server there with these values:\n\n name lintsure\n command npx\n args -y @lintsure/mcp@${RULES_VERSION}\n\nThen ask the agent, in its own chat: Check this project with Lintsure.`;
19
+ // Lintsure's own table in a Codex config: from its header to the next table. Only this table is ever written or removed.
20
+ const TOML_TABLE = /^\[mcp_servers\.lintsure\][^\n]*\n?(?:(?!\[)[^\n]*\n?)*/m;
21
+ export const tomlEntry = () => `[mcp_servers.lintsure]\ncommand = "npx"\nargs = ["-y", "@lintsure/mcp@${RULES_VERSION}"]\n`;
15
22
  // Pinned to this version on purpose: a moving "latest" in an agent config is what agent.config-runs-remote-code warns about.
16
23
  export const serverEntry = (a) => ({ ...(a.key === "servers" ? { type: "stdio" } : {}), command: "npx", args: ["-y", `@lintsure/mcp@${RULES_VERSION}`] });
17
24
  const exists = (p) => access(p).then(() => true, () => false);
@@ -19,6 +26,12 @@ const exists = (p) => access(p).then(() => true, () => false);
19
26
  export async function plan(root, a) {
20
27
  const path = join(root, a.file);
21
28
  const existed = await exists(path);
29
+ if (a.key === "mcp_servers") {
30
+ const toml = existed ? await readFile(path, "utf8") : "", now = TOML_TABLE.exec(toml)?.[0];
31
+ if (now?.replace(/\r/g, "").trim() === tomlEntry().trim())
32
+ return { agent: a, path, existed, skip: "already set up" };
33
+ return { agent: a, path, existed, text: now ? toml.replace(TOML_TABLE, () => tomlEntry()) : toml + (toml && !toml.endsWith("\n") ? "\n" : "") + (toml.trim() ? "\n" : "") + tomlEntry() };
34
+ }
22
35
  let json = {}, raw = "";
23
36
  if (existed) {
24
37
  raw = await readFile(path, "utf8");
@@ -39,16 +52,23 @@ export function writeJson(original, value) {
39
52
  const indent = /^\t/m.test(original) ? "\t" : (original.match(/^( +)"/m)?.[1].length ?? 2);
40
53
  return (original.startsWith("") ? "" : "") + JSON.stringify(value, null, indent) + "\n";
41
54
  }
55
+ /** The agents this project already uses: the ones whose folder or config file is here. */
56
+ export async function detected(root) {
57
+ const found = [];
58
+ for (const a of AGENTS)
59
+ if (await exists(join(root, a.marker)) || await exists(join(root, a.file)))
60
+ found.push(a);
61
+ return found;
62
+ }
63
+ /** What connecting does, in plain words, for the screens that offer it. */
64
+ export const CONNECT_NOTE = "Connecting adds one entry to the agent's config file in this project. It tells the agent how to start\nLintsure, so the agent can check code and explain findings itself. Installing the lintsure command does not\ndo this: an agent only knows Lintsure once it is connected.";
42
65
  /** Agents to set up: the ones named, or the ones whose folder exists, with Claude Code as the default. */
43
66
  export async function pick(root, names) {
44
67
  if (names) {
45
68
  const bad = names.filter((n) => !AGENTS.some((a) => a.id === n));
46
69
  return bad.length ? `Unknown agent: ${bad.join(", ")}. Use ${AGENTS.map((a) => a.id).join(", ")}.` : AGENTS.filter((a) => names.includes(a.id));
47
70
  }
48
- const found = [];
49
- for (const a of AGENTS)
50
- if (await exists(join(root, a.marker)) || await exists(join(root, a.file)))
51
- found.push(a);
71
+ const found = await detected(root);
52
72
  return found.length ? found : [AGENTS[0]];
53
73
  }
54
74
  export async function setup(root, agents, apply) {
@@ -58,13 +78,15 @@ export async function setup(root, agents, apply) {
58
78
  console.log(`- ${p.agent.name}: ${p.skip}`);
59
79
  continue;
60
80
  }
61
- console.log(`- ${p.agent.name}: ${p.existed ? "add to" : "create"} ${p.agent.file}\n "lintsure": ${JSON.stringify(serverEntry(p.agent))}`);
81
+ console.log(`- ${p.agent.name}: ${p.existed ? "add to" : "create"} ${p.agent.file}\n ${p.agent.key === "mcp_servers" ? tomlEntry().trim().replace(/\n/g, "\n ") : `"lintsure": ${JSON.stringify(serverEntry(p.agent))}`}`);
62
82
  }
63
83
  const todo = plans.filter((p) => p.text);
64
- if (!todo.length)
84
+ if (!todo.length) {
85
+ console.log("\nNothing to write. Check the connection with: lintsure status");
65
86
  return 0;
87
+ }
66
88
  if (!apply) {
67
- console.log("\nNothing written. Run again with --yes to apply. Existing files are backed up first (<file>.lintsure-backup).");
89
+ console.log("\nNothing written yet. To apply, run: lintsure setup --yes\nExisting files are backed up first (<file>.lintsure-backup).");
68
90
  return 0;
69
91
  }
70
92
  for (const p of todo) {
@@ -86,12 +108,17 @@ export async function setup(root, agents, apply) {
86
108
  }
87
109
  console.log("Undo any time with: lintsure setup --undo");
88
110
  console.log(`\nWritten. Restart the agent so it starts the Lintsure MCP server. Run "lintsure status" to check.`);
89
- console.log("For the guards (Drift Guard, Danger Guard) in Claude Code, also install the plugin: /plugin marketplace add lintsure/claude-plugin");
111
+ console.log("Then ask the agent, in its own chat: Check this project with Lintsure.");
112
+ if (agents.some((a) => a.id === "codex"))
113
+ console.log("Codex reads a project's .codex/config.toml only for projects you have marked as trusted.");
114
+ if (agents.some((a) => a.id === "claude"))
115
+ console.log("For the guards (Drift Guard, Danger Guard) in Claude Code, also install the plugin: /plugin marketplace add lintsure/claude-plugin");
90
116
  return 0;
91
117
  }
92
118
  /** Readiness check. Never prints secret values. Exit 2 only when the config has problems a scan would refuse. */
93
119
  export async function status(root) {
94
- const line = (ok, what, next) => console.log(`${ok === null ? "info" : ok ? "ok " : "todo"} ${what}${!ok && next ? `\n ${next}` : ""}`);
120
+ let todo = 0;
121
+ const line = (ok, what, next) => (ok === false && todo++, console.log(`${ok === null ? "info" : ok ? "ok " : "todo"} ${what}${!ok && next ? `\n ${next}` : ""}`));
95
122
  const major = Number(process.versions.node.split(".")[0]);
96
123
  line(major >= 20, `Node.js ${process.versions.node}`, "Lintsure needs Node.js 20 or newer.");
97
124
  line(true, `Lintsure rules ${RULES_VERSION}`);
@@ -115,6 +142,7 @@ export async function status(root) {
115
142
  else
116
143
  line(!mcp.problems.length, mcp.problems.length ? `MCP server: ${mcp.problems.join("; ")}` : `MCP server ${mcp.version} answers: ${mcp.tools} tools, test call ok`);
117
144
  line(null, process.env.LINTSURE_API_KEY ? "LINTSURE_API_KEY is set: the plugin will use the hosted workspace" : "No LINTSURE_API_KEY: everything stays on this machine");
145
+ console.log(todo ? `\nAlmost there: ${todo} thing${todo === 1 ? "" : "s"} to do, marked todo above.` : "\nReady! Everything Lintsure needs is in place.");
118
146
  return hasConfig && config.problems.length ? 2 : 0;
119
147
  }
120
148
  /** Takes Lintsure's own entry back out, leaving everything else in the file as it is now (later edits included).
@@ -122,6 +150,21 @@ export async function status(root) {
122
150
  export async function undo(root, agents) {
123
151
  for (const a of agents) {
124
152
  const path = join(root, a.file);
153
+ if (a.key === "mcp_servers") {
154
+ const toml = await readFile(path, "utf8").catch(() => "");
155
+ if (!TOML_TABLE.test(toml))
156
+ continue;
157
+ const left = toml.replace(TOML_TABLE, "").replace(/\n{3,}/g, "\n\n"), kept = await exists(path + ".lintsure-backup");
158
+ if (!left.trim() && !kept) {
159
+ await rm(path);
160
+ console.log(`- ${a.name}: removed ${a.file} (Lintsure had created it)`);
161
+ }
162
+ else {
163
+ await writeFile(path, left);
164
+ console.log(`- ${a.name}: removed the Lintsure entry from ${a.file}${kept ? ` (your original is still in ${a.file}.lintsure-backup)` : ""}`);
165
+ }
166
+ continue;
167
+ }
125
168
  let json, raw;
126
169
  try {
127
170
  raw = await readFile(path, "utf8");
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ /** Whether a folder is a software project or sits inside one: a marker file in the folder itself, or a git repository
3
+ * around it. Folders above count only through .git, because a stray package.json in a temp or documents folder is
4
+ * common. The home folder and a drive root never count. */
5
+ export declare const looksLikeProject: (dir: string) => boolean;
2
6
  /** Changed line numbers per file from `git diff -U0` output. Pure. */
3
7
  export declare function parseDiff(text: string): Record<string, number[]>;
4
8
  /** Splits --flag=value into two tokens and checks every flag, so a CI gate can't silently fail open