lintsure 0.3.15 → 0.3.16
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 +3 -2
- package/dist/src/agents.d.ts +3 -1
- package/dist/src/agents.js +44 -19
- package/dist/src/deps.d.ts +18 -0
- package/dist/src/deps.js +57 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +499 -71
- package/dist/src/plugin.d.ts +28 -0
- package/dist/src/plugin.js +170 -0
- package/dist/src/skills.js +4 -2
- package/package.json +2 -2
- package/skills/lintsure-check/SKILL.md +36 -36
- package/skills/lintsure-fix/SKILL.md +38 -30
- package/skills/lintsure-prelaunch/SKILL.md +37 -0
- package/skills/lintsure-rules/SKILL.md +54 -54
- package/skills/lintsure-rules/agents.mjs +75 -75
- package/skills/lintsure-rules/lib.mjs +60 -60
- package/skills/lintsure-rules/profile.mjs +129 -129
- package/skills/lintsure-rules/rules.mjs +197 -197
- package/skills/lintsure-setup/SKILL.md +34 -34
- package/skills/lintsure-stay-on-track/SKILL.md +39 -39
- package/skills/lintsure-triage/SKILL.md +33 -0
- package/skills/lintsure-ship/SKILL.md +0 -21
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npx lintsure scan # check the project in this folder
|
|
7
|
-
npx lintsure setup --yes # connect it to the coding agents this project uses
|
|
7
|
+
npx lintsure setup --yes # connect it to the coding agents this project uses (run it in your project's folder)
|
|
8
|
+
npx lintsure setup --everywhere --yes # or connect it for every project on this machine
|
|
8
9
|
npx lintsure skills --yes # add the skills that tell the agent when to use it
|
|
9
10
|
npx lintsure scan --fail-on gap # fail a CI job on clear problems
|
|
10
11
|
npx lintsure baseline # then later scans show only what's new
|
|
@@ -22,7 +23,7 @@ gap src/users.ts:5 Personal data written to logs
|
|
|
22
23
|
|
|
23
24
|
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
|
|
|
25
|
-
In Claude Code, the [plugin](https://github.com/lintsure/
|
|
26
|
+
In Claude Code, the [plugin](https://github.com/lintsure/plugin) adds guards that work while the agent edits: Drift Guard, Danger Guard, Secret Guard and Loop Guard.
|
|
26
27
|
|
|
27
28
|
With Docker: `docker run --rm -v "$PWD:/work" -w /work node:22-slim npx -y lintsure scan`
|
|
28
29
|
|
package/dist/src/agents.d.ts
CHANGED
|
@@ -29,9 +29,11 @@ export declare function writeJson(original: string, value: unknown): string;
|
|
|
29
29
|
export declare function detected(root: string): Promise<Agent[]>;
|
|
30
30
|
/** What connecting does, in plain words, for the screens that offer it. */
|
|
31
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.";
|
|
32
|
+
/** The agent running this command, from the environment it sets, so setup connects the one that asked. */
|
|
33
|
+
export declare function callingAgent(env?: Record<string, string | undefined>): Agent | undefined;
|
|
32
34
|
/** Agents to set up: the ones named, or the ones whose folder exists, with Claude Code as the default. */
|
|
33
35
|
export declare function pick(root: string, names?: string[]): Promise<Agent[] | string>;
|
|
34
|
-
export declare function setup(root: string, agents: Agent[], apply: boolean): Promise<number>;
|
|
36
|
+
export declare function setup(root: string, agents: Agent[], apply: boolean, scope?: string): Promise<number>;
|
|
35
37
|
/** Readiness check. Never prints secret values. Exit 2 only when the config has problems a scan would refuse. */
|
|
36
38
|
export declare function status(root: string): Promise<number>;
|
|
37
39
|
/** Takes Lintsure's own entry back out, leaving everything else in the file as it is now (later edits included).
|
package/dist/src/agents.js
CHANGED
|
@@ -5,6 +5,7 @@ import { access, chmod, copyFile, mkdir, readFile, rm, writeFile } from "node:fs
|
|
|
5
5
|
import { constants } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { RULES_VERSION, readConfig } from "@lintsure/core";
|
|
8
|
+
import { installSkills, skills } from "./skills.js";
|
|
8
9
|
/** Project-level MCP config files. `marker` is the folder that shows the project uses that agent. */
|
|
9
10
|
export const AGENTS = [
|
|
10
11
|
{ id: "claude", name: "Claude Code", file: ".mcp.json", key: "mcpServers", marker: ".claude" },
|
|
@@ -62,16 +63,23 @@ export async function detected(root) {
|
|
|
62
63
|
}
|
|
63
64
|
/** What connecting does, in plain words, for the screens that offer it. */
|
|
64
65
|
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.";
|
|
66
|
+
/** The agent running this command, from the environment it sets, so setup connects the one that asked. */
|
|
67
|
+
export function callingAgent(env = process.env) {
|
|
68
|
+
const id = env.CLAUDECODE ? "claude" : env.GEMINI_CLI ? "gemini" : env.CURSOR_AGENT || env.CURSOR_TRACE_ID ? "cursor" : Object.keys(env).some((k) => k.startsWith("CODEX_")) ? "codex" : undefined;
|
|
69
|
+
return AGENTS.find((a) => a.id === id);
|
|
70
|
+
}
|
|
65
71
|
/** Agents to set up: the ones named, or the ones whose folder exists, with Claude Code as the default. */
|
|
66
72
|
export async function pick(root, names) {
|
|
67
73
|
if (names) {
|
|
68
74
|
const bad = names.filter((n) => !AGENTS.some((a) => a.id === n));
|
|
69
75
|
return bad.length ? `Unknown agent: ${bad.join(", ")}. Use ${AGENTS.map((a) => a.id).join(", ")}.` : AGENTS.filter((a) => names.includes(a.id));
|
|
70
76
|
}
|
|
71
|
-
const found = await detected(root);
|
|
77
|
+
const found = await detected(root), me = callingAgent();
|
|
78
|
+
if (me && !found.includes(me))
|
|
79
|
+
found.push(me);
|
|
72
80
|
return found.length ? found : [AGENTS[0]];
|
|
73
81
|
}
|
|
74
|
-
export async function setup(root, agents, apply) {
|
|
82
|
+
export async function setup(root, agents, apply, scope = "") {
|
|
75
83
|
const plans = await Promise.all(agents.map((a) => plan(root, a)));
|
|
76
84
|
for (const p of plans) {
|
|
77
85
|
if (p.skip) {
|
|
@@ -86,33 +94,44 @@ export async function setup(root, agents, apply) {
|
|
|
86
94
|
return 0;
|
|
87
95
|
}
|
|
88
96
|
if (!apply) {
|
|
89
|
-
console.log(
|
|
97
|
+
console.log(`\nNothing written yet. To apply, run: lintsure setup${scope} --yes\nExisting files are backed up first (<file>.lintsure-backup).`);
|
|
90
98
|
return 0;
|
|
91
99
|
}
|
|
100
|
+
let wrote = 0;
|
|
92
101
|
for (const p of todo) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
try {
|
|
103
|
+
await mkdir(dirname(p.path), { recursive: true });
|
|
104
|
+
// The first backup is the user's original: never overwrite it on a later run. Owner-only, it may hold tokens.
|
|
105
|
+
if (p.existed) {
|
|
106
|
+
try {
|
|
107
|
+
await copyFile(p.path, p.path + ".lintsure-backup", constants.COPYFILE_EXCL);
|
|
108
|
+
await chmod(p.path + ".lintsure-backup", 0o600).catch(() => { });
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
if (e.code !== "EEXIST") {
|
|
112
|
+
console.error(`Couldn't back up ${p.agent.file}, so it was left alone.`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
}
|
|
117
|
+
await writeFile(p.path, p.text);
|
|
118
|
+
wrote++;
|
|
106
119
|
}
|
|
107
|
-
|
|
120
|
+
catch (e) {
|
|
121
|
+
console.error(`Couldn't write ${p.agent.file} (${e.code ?? "error"}), so it was left alone.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// A sandboxed agent or a read-only folder: say plainly that nothing changed, so nobody thinks it is connected.
|
|
125
|
+
if (!wrote) {
|
|
126
|
+
console.error("\nNothing was written. This program isn't allowed to change files in that folder. Allow it there, or run the same command in your own terminal.");
|
|
127
|
+
return 1;
|
|
108
128
|
}
|
|
109
|
-
console.log(
|
|
129
|
+
console.log(`Undo any time with: lintsure setup${scope} --undo`);
|
|
110
130
|
console.log(`\nWritten. Restart the agent so it starts the Lintsure MCP server. Run "lintsure status" to check.`);
|
|
111
131
|
console.log("Then ask the agent, in its own chat: Check this project with Lintsure.");
|
|
112
|
-
if (agents.some((a) => a.id === "codex"))
|
|
132
|
+
if (!scope && agents.some((a) => a.id === "codex"))
|
|
113
133
|
console.log("Codex reads a project's .codex/config.toml only for projects you have marked as trusted.");
|
|
114
|
-
|
|
115
|
-
console.log("For the guards (Drift Guard, Danger Guard) in Claude Code, also install the plugin: /plugin marketplace add lintsure/claude-plugin");
|
|
134
|
+
console.log("For guards that run while the agent works, add the plugin: lintsure plugin");
|
|
116
135
|
return 0;
|
|
117
136
|
}
|
|
118
137
|
/** Readiness check. Never prints secret values. Exit 2 only when the config has problems a scan would refuse. */
|
|
@@ -136,6 +155,12 @@ export async function status(root) {
|
|
|
136
155
|
const p = await plan(root, a);
|
|
137
156
|
line(p.skip === "already set up", `${a.name}: Lintsure MCP server in ${a.file}`, p.skip && p.skip !== "already set up" ? p.skip : `Run: lintsure setup --agents ${a.id}`);
|
|
138
157
|
}
|
|
158
|
+
// Skills: are the ones in this project the ones this version ships? An older or edited copy teaches the agent old habits.
|
|
159
|
+
const steps = await installSkills(root, skills(), false), here = steps.filter((s) => s.state !== "add"), stale = here.filter((s) => s.state === "update");
|
|
160
|
+
if (!here.length)
|
|
161
|
+
line(null, "No Lintsure skills in this project: add them with lintsure skills");
|
|
162
|
+
else
|
|
163
|
+
line(!stale.length, `Lintsure skills: ${here.length} installed${stale.length ? `, ${stale.length} differ from this version (${stale.map((s) => s.folder).join(", ")})` : ", all current"}`, "Run: lintsure skills --yes (your copies are kept as backups)");
|
|
139
164
|
const mcp = await mcpRoundTrip();
|
|
140
165
|
if (!mcp)
|
|
141
166
|
line(null, "MCP server not installed next to this CLI: agents start it with npx, which downloads it on first use");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Pinned {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
ecosystem: "npm" | "PyPI";
|
|
5
|
+
}
|
|
6
|
+
/** Every installed package in an npm lockfile (version 2 or 3), once per name and version. Pure. */
|
|
7
|
+
export declare function fromPackageLock(text: string): Pinned[];
|
|
8
|
+
/** Packages pinned to one exact version in a requirements file. Ranges and unpinned lines can't be looked up. Pure. */
|
|
9
|
+
export declare function fromRequirements(text: string): Pinned[];
|
|
10
|
+
/** The pinned packages of a project, and the files they came from.
|
|
11
|
+
* shortcut: reads package-lock.json and requirements.txt at the top of the folder only; add other lockfiles and nested
|
|
12
|
+
* folders when someone needs them. */
|
|
13
|
+
export declare function pinned(root: string): Promise<{
|
|
14
|
+
found: Pinned[];
|
|
15
|
+
files: string[];
|
|
16
|
+
}>;
|
|
17
|
+
/** Known advisory ids per package, from OSV. One request per 500 packages. Throws when the service can't be reached. */
|
|
18
|
+
export declare function advisories(pkgs: Pinned[], fetcher?: typeof fetch): Promise<Map<Pinned, string[]>>;
|
package/dist/src/deps.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// lintsure deps: asks a public database which of the project's pinned packages have known vulnerabilities.
|
|
2
|
+
// This is the one command that uses the network. It sends package names and versions, never code, to api.osv.dev,
|
|
3
|
+
// and only after it has said so and been told to go ahead. A scan never does this.
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
/** Every installed package in an npm lockfile (version 2 or 3), once per name and version. Pure. */
|
|
7
|
+
export function fromPackageLock(text) {
|
|
8
|
+
const packages = (JSON.parse(text).packages ?? {});
|
|
9
|
+
const out = new Map();
|
|
10
|
+
for (const [path, p] of Object.entries(packages)) {
|
|
11
|
+
const at = path.lastIndexOf("node_modules/");
|
|
12
|
+
if (at < 0 || p.link || !p.version)
|
|
13
|
+
continue; // the project itself, and links to its own workspaces
|
|
14
|
+
const name = path.slice(at + 13);
|
|
15
|
+
out.set(`${name}@${p.version}`, { name, version: p.version, ecosystem: "npm" });
|
|
16
|
+
}
|
|
17
|
+
return [...out.values()];
|
|
18
|
+
}
|
|
19
|
+
/** Packages pinned to one exact version in a requirements file. Ranges and unpinned lines can't be looked up. Pure. */
|
|
20
|
+
export function fromRequirements(text) {
|
|
21
|
+
return text.split(/\r?\n/).flatMap((l) => { const m = /^\s*([A-Za-z0-9._-]+)(?:\[[^\]]*\])?\s*==\s*([\w.!+-]+)/.exec(l); return m ? [{ name: m[1], version: m[2], ecosystem: "PyPI" }] : []; });
|
|
22
|
+
}
|
|
23
|
+
/** The pinned packages of a project, and the files they came from.
|
|
24
|
+
* shortcut: reads package-lock.json and requirements.txt at the top of the folder only; add other lockfiles and nested
|
|
25
|
+
* folders when someone needs them. */
|
|
26
|
+
export async function pinned(root) {
|
|
27
|
+
const found = [], files = [];
|
|
28
|
+
for (const [file, read] of [["package-lock.json", fromPackageLock], ["requirements.txt", fromRequirements]]) {
|
|
29
|
+
const text = await readFile(join(root, file), "utf8").catch(() => null);
|
|
30
|
+
if (text === null)
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
const list = read(text);
|
|
34
|
+
if (list.length) {
|
|
35
|
+
found.push(...list);
|
|
36
|
+
files.push(file);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch { /* a lockfile that isn't JSON is skipped, not fatal */ }
|
|
40
|
+
}
|
|
41
|
+
return { found, files };
|
|
42
|
+
}
|
|
43
|
+
/** Known advisory ids per package, from OSV. One request per 500 packages. Throws when the service can't be reached. */
|
|
44
|
+
export async function advisories(pkgs, fetcher = fetch) {
|
|
45
|
+
const out = new Map();
|
|
46
|
+
for (let i = 0; i < pkgs.length; i += 500) {
|
|
47
|
+
const batch = pkgs.slice(i, i + 500);
|
|
48
|
+
const res = await fetcher("https://api.osv.dev/v1/querybatch", { method: "POST", headers: { "content-type": "application/json" }, signal: AbortSignal.timeout(20000),
|
|
49
|
+
body: JSON.stringify({ queries: batch.map((p) => ({ package: { name: p.name, ecosystem: p.ecosystem }, version: p.version })) }) });
|
|
50
|
+
if (!res.ok)
|
|
51
|
+
throw new Error(`api.osv.dev answered ${res.status}`);
|
|
52
|
+
const { results = [] } = (await res.json());
|
|
53
|
+
batch.forEach((p, k) => { const ids = (results[k]?.vulns ?? []).map((v) => v.id); if (ids.length)
|
|
54
|
+
out.set(p, ids); });
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* around it. Folders above count only through .git, because a stray package.json in a temp or documents folder is
|
|
4
4
|
* common. The home folder and a drive root never count. */
|
|
5
5
|
export declare const looksLikeProject: (dir: string) => boolean;
|
|
6
|
+
/** The projects directly inside a folder that is not one itself: a workspace. Empty for a normal project. */
|
|
7
|
+
export declare function subProjects(dir: string): string[];
|
|
6
8
|
/** Changed line numbers per file from `git diff -U0` output. Pure. */
|
|
7
9
|
export declare function parseDiff(text: string): Record<string, number[]>;
|
|
8
10
|
/** Splits --flag=value into two tokens and checks every flag, so a CI gate can't silently fail open
|