lintsure 0.3.10 → 0.3.11

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
@@ -8,9 +8,11 @@ Readiness checks for the code your AI writes: EU AI Act, GDPR, OWASP Top 10, OWA
8
8
  npx lintsure scan
9
9
  npx lintsure scan ./my-app --framework gdpr,owasp-top10 --json --fail-on gap
10
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
11
13
  ```
12
14
 
13
- Every finding shows the file and line, the rules it may affect across all four frameworks, a suggested fix and a plain note on why it matters.
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.
14
16
 
15
17
  - Docs: https://lintsure.com/docs/cli
16
18
  - Source: https://github.com/lintsure/lintsure
@@ -0,0 +1,40 @@
1
+ export interface Agent {
2
+ id: string;
3
+ name: string;
4
+ file: string;
5
+ key: "mcpServers" | "servers";
6
+ marker: string;
7
+ }
8
+ /** Project-level MCP config files. `marker` is the folder that shows the project uses that agent. */
9
+ export declare const AGENTS: Agent[];
10
+ export declare const serverEntry: (a: Agent) => {
11
+ command: string;
12
+ args: string[];
13
+ type?: string | undefined;
14
+ };
15
+ /** What setup would write for one agent: the new file text, or why it skips. Pure apart from reading the file. */
16
+ export declare function plan(root: string, a: Agent): Promise<{
17
+ agent: Agent;
18
+ path: string;
19
+ text?: string;
20
+ skip?: string;
21
+ existed: boolean;
22
+ }>;
23
+ /** JSON in the same style as the file it replaces: its indent (tabs or N spaces) and a leading byte-order mark. Pure. */
24
+ export declare function writeJson(original: string, value: unknown): string;
25
+ /** Agents to set up: the ones named, or the ones whose folder exists, with Claude Code as the default. */
26
+ export declare function pick(root: string, names?: string[]): Promise<Agent[] | string>;
27
+ export declare function setup(root: string, agents: Agent[], apply: boolean): Promise<number>;
28
+ /** Readiness check. Never prints secret values. Exit 2 only when the config has problems a scan would refuse. */
29
+ export declare function status(root: string): Promise<number>;
30
+ /** Takes Lintsure's own entry back out, leaving everything else in the file as it is now (later edits included).
31
+ * A file Lintsure created that is now empty is removed. The original backup is kept. */
32
+ export declare function undo(root: string, agents: Agent[]): Promise<number>;
33
+ /** Starts the locally installed Lintsure MCP server and talks to it the way an agent would: initialize (version must
34
+ * match these rules), tools/list, and one read-only call. Never downloads: when @lintsure/mcp isn't installed next
35
+ * to this CLI, it says so. Returns problems found, or null when the server isn't installed here. */
36
+ export declare function mcpRoundTrip(timeoutMs?: number): Promise<{
37
+ problems: string[];
38
+ tools: number;
39
+ version: string;
40
+ } | null>;
@@ -0,0 +1,216 @@
1
+ // lintsure setup and lintsure status: register the Lintsure MCP server with the coding agents a project uses,
2
+ // and check that a project is ready. Only project files are written, each shown first and backed up. Nothing is
3
+ // downloaded or sent; the agent itself starts the server later with npx.
4
+ import { access, chmod, copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
+ import { constants } from "node:fs";
6
+ import { dirname, join } from "node:path";
7
+ import { RULES_VERSION, readConfig } from "@lintsure/core";
8
+ /** Project-level MCP config files. `marker` is the folder that shows the project uses that agent. */
9
+ export const AGENTS = [
10
+ { id: "claude", name: "Claude Code", file: ".mcp.json", key: "mcpServers", marker: ".claude" },
11
+ { id: "cursor", name: "Cursor", file: ".cursor/mcp.json", key: "mcpServers", marker: ".cursor" },
12
+ { id: "vscode", name: "VS Code (Copilot)", file: ".vscode/mcp.json", key: "servers", marker: ".vscode" },
13
+ { id: "gemini", name: "Gemini CLI", file: ".gemini/settings.json", key: "mcpServers", marker: ".gemini" },
14
+ ];
15
+ // Pinned to this version on purpose: a moving "latest" in an agent config is what agent.config-runs-remote-code warns about.
16
+ export const serverEntry = (a) => ({ ...(a.key === "servers" ? { type: "stdio" } : {}), command: "npx", args: ["-y", `@lintsure/mcp@${RULES_VERSION}`] });
17
+ const exists = (p) => access(p).then(() => true, () => false);
18
+ /** What setup would write for one agent: the new file text, or why it skips. Pure apart from reading the file. */
19
+ export async function plan(root, a) {
20
+ const path = join(root, a.file);
21
+ const existed = await exists(path);
22
+ let json = {}, raw = "";
23
+ if (existed) {
24
+ raw = await readFile(path, "utf8");
25
+ try {
26
+ json = JSON.parse(raw.replace(/^/, ""));
27
+ }
28
+ catch {
29
+ return { agent: a, path, existed, skip: `${a.file} isn't plain JSON (comments?), so it's left alone. Add the entry yourself.` };
30
+ }
31
+ }
32
+ const servers = (json[a.key] ?? {});
33
+ if (JSON.stringify(servers.lintsure) === JSON.stringify(serverEntry(a)))
34
+ return { agent: a, path, existed, skip: "already set up" };
35
+ return { agent: a, path, existed, text: writeJson(raw, { ...json, [a.key]: { ...servers, lintsure: serverEntry(a) } }) };
36
+ }
37
+ /** JSON in the same style as the file it replaces: its indent (tabs or N spaces) and a leading byte-order mark. Pure. */
38
+ export function writeJson(original, value) {
39
+ const indent = /^\t/m.test(original) ? "\t" : (original.match(/^( +)"/m)?.[1].length ?? 2);
40
+ return (original.startsWith("") ? "" : "") + JSON.stringify(value, null, indent) + "\n";
41
+ }
42
+ /** Agents to set up: the ones named, or the ones whose folder exists, with Claude Code as the default. */
43
+ export async function pick(root, names) {
44
+ if (names) {
45
+ const bad = names.filter((n) => !AGENTS.some((a) => a.id === n));
46
+ return bad.length ? `Unknown agent: ${bad.join(", ")}. Use ${AGENTS.map((a) => a.id).join(", ")}.` : AGENTS.filter((a) => names.includes(a.id));
47
+ }
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);
52
+ return found.length ? found : [AGENTS[0]];
53
+ }
54
+ export async function setup(root, agents, apply) {
55
+ const plans = await Promise.all(agents.map((a) => plan(root, a)));
56
+ for (const p of plans) {
57
+ if (p.skip) {
58
+ console.log(`- ${p.agent.name}: ${p.skip}`);
59
+ continue;
60
+ }
61
+ console.log(`- ${p.agent.name}: ${p.existed ? "add to" : "create"} ${p.agent.file}\n "lintsure": ${JSON.stringify(serverEntry(p.agent))}`);
62
+ }
63
+ const todo = plans.filter((p) => p.text);
64
+ if (!todo.length)
65
+ return 0;
66
+ if (!apply) {
67
+ console.log("\nNothing written. Run again with --yes to apply. Existing files are backed up first (<file>.lintsure-backup).");
68
+ return 0;
69
+ }
70
+ for (const p of todo) {
71
+ await mkdir(dirname(p.path), { recursive: true });
72
+ // The first backup is the user's original: never overwrite it on a later run. Owner-only, it may hold tokens.
73
+ if (p.existed) {
74
+ try {
75
+ await copyFile(p.path, p.path + ".lintsure-backup", constants.COPYFILE_EXCL);
76
+ await chmod(p.path + ".lintsure-backup", 0o600).catch(() => { });
77
+ }
78
+ catch (e) {
79
+ if (e.code !== "EEXIST") {
80
+ console.error(`Couldn't back up ${p.agent.file}, so it was left alone.`);
81
+ continue;
82
+ }
83
+ }
84
+ }
85
+ await writeFile(p.path, p.text);
86
+ }
87
+ console.log("Undo any time with: lintsure setup --undo");
88
+ 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");
90
+ return 0;
91
+ }
92
+ /** Readiness check. Never prints secret values. Exit 2 only when the config has problems a scan would refuse. */
93
+ export async function status(root) {
94
+ const line = (ok, what, next) => console.log(`${ok === null ? "info" : ok ? "ok " : "todo"} ${what}${!ok && next ? `\n ${next}` : ""}`);
95
+ const major = Number(process.versions.node.split(".")[0]);
96
+ line(major >= 20, `Node.js ${process.versions.node}`, "Lintsure needs Node.js 20 or newer.");
97
+ line(true, `Lintsure rules ${RULES_VERSION}`);
98
+ const config = await readConfig(root);
99
+ const hasConfig = await exists(join(root, "lintsure.config.yaml"));
100
+ line(hasConfig ? !config.problems.length : null, hasConfig ? `lintsure.config.yaml${config.problems.length ? `: ${config.problems.join("; ")}` : " reads cleanly"}` : "No lintsure.config.yaml: scans use all frameworks", hasConfig ? "Fix the lines above." : undefined);
101
+ if (config.packsMissing?.length)
102
+ line(false, `Rule packs not installed: ${config.packsMissing.join(", ")}`, "Install them next to Lintsure, or remove them from packs:.");
103
+ const rulesFile = await exists(join(root, ".lintsure", "rules.yml"));
104
+ line(rulesFile ? true : null, rulesFile ? ".lintsure/rules.yml found (Drift Guard rules)" : "No .lintsure/rules.yml: the Drift Guard only uses its built-in checks");
105
+ for (const a of AGENTS) {
106
+ const used = await exists(join(root, a.marker)) || await exists(join(root, a.file));
107
+ if (!used)
108
+ continue;
109
+ const p = await plan(root, a);
110
+ 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}`);
111
+ }
112
+ const mcp = await mcpRoundTrip();
113
+ if (!mcp)
114
+ line(null, "MCP server not installed next to this CLI: agents start it with npx, which downloads it on first use");
115
+ else
116
+ line(!mcp.problems.length, mcp.problems.length ? `MCP server: ${mcp.problems.join("; ")}` : `MCP server ${mcp.version} answers: ${mcp.tools} tools, test call ok`);
117
+ 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");
118
+ return hasConfig && config.problems.length ? 2 : 0;
119
+ }
120
+ /** Takes Lintsure's own entry back out, leaving everything else in the file as it is now (later edits included).
121
+ * A file Lintsure created that is now empty is removed. The original backup is kept. */
122
+ export async function undo(root, agents) {
123
+ for (const a of agents) {
124
+ const path = join(root, a.file);
125
+ let json, raw;
126
+ try {
127
+ raw = await readFile(path, "utf8");
128
+ json = JSON.parse(raw.replace(/^/, ""));
129
+ }
130
+ catch {
131
+ continue;
132
+ }
133
+ const servers = (json[a.key] ?? {});
134
+ if (!("lintsure" in servers))
135
+ continue;
136
+ delete servers.lintsure;
137
+ const empty = !Object.keys(servers).length && Object.keys(json).length === 1;
138
+ const backup = await exists(path + ".lintsure-backup");
139
+ if (empty && !backup) {
140
+ await rm(path);
141
+ console.log(`- ${a.name}: removed ${a.file} (Lintsure had created it)`);
142
+ }
143
+ else {
144
+ await writeFile(path, writeJson(raw, json));
145
+ console.log(`- ${a.name}: removed the Lintsure entry from ${a.file}${backup ? ` (your original is still in ${a.file}.lintsure-backup)` : ""}`);
146
+ }
147
+ }
148
+ return 0;
149
+ }
150
+ /** Starts the locally installed Lintsure MCP server and talks to it the way an agent would: initialize (version must
151
+ * match these rules), tools/list, and one read-only call. Never downloads: when @lintsure/mcp isn't installed next
152
+ * to this CLI, it says so. Returns problems found, or null when the server isn't installed here. */
153
+ export async function mcpRoundTrip(timeoutMs = 15000) {
154
+ const { createRequire } = await import("node:module");
155
+ const { spawn } = await import("node:child_process");
156
+ let entry;
157
+ try {
158
+ const req = createRequire(import.meta.url), pkgPath = req.resolve("@lintsure/mcp/package.json");
159
+ const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
160
+ entry = join(dirname(pkgPath), typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.["lintsure-mcp"] ?? "dist/src/index.js");
161
+ }
162
+ catch {
163
+ return null;
164
+ }
165
+ const p = spawn(process.execPath, [entry], { stdio: ["pipe", "pipe", "ignore"] });
166
+ let buf = "";
167
+ const waiting = new Map();
168
+ p.stdout.on("data", (d) => { buf += d; let i; while ((i = buf.indexOf("\n")) >= 0) {
169
+ try {
170
+ const m = JSON.parse(buf.slice(0, i));
171
+ waiting.get(m.id)?.(m);
172
+ }
173
+ catch { /* not ours */ }
174
+ buf = buf.slice(i + 1);
175
+ } });
176
+ // A server that fails to start or exits early is reported as a problem, never a crash of the CLI (EPIPE).
177
+ let gone = null;
178
+ const fail = new Set();
179
+ const stop = (why) => { gone ??= why; for (const f of fail)
180
+ f(new Error(gone)); };
181
+ p.on("error", (e) => stop(`MCP server didn't start (${e.message})`));
182
+ p.on("exit", (code) => stop(`MCP server exited${code == null ? "" : ` with code ${code}`} before answering`));
183
+ p.stdin.on("error", () => stop("MCP server closed its input"));
184
+ let id = 0;
185
+ const call = (method, params) => new Promise((res, rej) => {
186
+ if (gone)
187
+ return rej(new Error(gone));
188
+ const n = ++id, t = setTimeout(() => rej(new Error(`${method} took longer than ${timeoutMs / 1000}s`)), timeoutMs);
189
+ const onFail = (e) => { clearTimeout(t); rej(e); };
190
+ fail.add(onFail);
191
+ waiting.set(n, (m) => { clearTimeout(t); fail.delete(onFail); res(m); });
192
+ p.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: n, method, params }) + "\n");
193
+ });
194
+ const problems = [];
195
+ let tools = 0, version = "";
196
+ try {
197
+ const init = await call("initialize", { protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "lintsure-status", version: RULES_VERSION } });
198
+ version = init.result?.serverInfo?.version ?? "";
199
+ if (version !== RULES_VERSION)
200
+ problems.push(`MCP server is ${version || "unknown"}, the CLI is ${RULES_VERSION}: update both to the same version`);
201
+ p.stdin.write(JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) + "\n");
202
+ tools = (await call("tools/list", {})).result?.tools?.length ?? 0;
203
+ if (!tools)
204
+ problems.push("MCP server listed no tools");
205
+ const r = await call("tools/call", { name: "explain_rule", arguments: { ruleId: "pii.logged" } });
206
+ if (r.error || r.result?.isError || !r.result?.content?.length)
207
+ problems.push("MCP server didn't answer a test call");
208
+ }
209
+ catch (e) {
210
+ problems.push(e instanceof Error ? e.message : String(e));
211
+ }
212
+ finally {
213
+ p.kill();
214
+ }
215
+ return { problems, tools, version };
216
+ }
package/dist/src/index.js CHANGED
@@ -2,14 +2,22 @@
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
4
  import { execFileSync } from "node:child_process";
5
- import { access, mkdir, writeFile } from "node:fs/promises";
5
+ import { access, mkdir, readFile, writeFile } from "node:fs/promises";
6
6
  import { basename, dirname, join, resolve } from "node:path";
7
7
  import { createInterface } from "node:readline/promises";
8
+ import { status, pick, setup, undo } from "./agents.js";
9
+ import { parseActivity, toOtlp } from "./otel.js";
8
10
  import { ALL_FRAMEWORKS, BASELINE_FILE, DISCLAIMER, RULES_VERSION, classify, isOpen, nextSteps, readConfig, scan, toAssessmentHtml, toBaseline, toMarkdown, toSarif } from "@lintsure/core";
9
11
  const HELP = `lintsure scan [path] [options]
10
12
  lintsure baseline [path]
11
13
  lintsure init [path] Three questions, saved to lintsure.config.yaml
12
14
  lintsure info [path] Show the settings a scan would use, and where each comes from
15
+ lintsure setup [path] Add the Lintsure MCP server to this project's agent configs
16
+ (shows the change; --yes writes it; --undo takes it out;
17
+ --agents claude,cursor,vscode,gemini)
18
+ lintsure status [path] Check that this project is ready: Node, config, rules, agents
19
+ lintsure export --otlp-json [path] Write .lintsure/activity.jsonl as an OpenTelemetry
20
+ traces file (lintsure.otlp.json) for your own observability tool
13
21
 
14
22
  scan options:
15
23
  --framework <ids> Comma list: ${ALL_FRAMEWORKS.join(", ")}
@@ -45,8 +53,9 @@ export function parseDiff(text) {
45
53
  const out = {};
46
54
  let file = null;
47
55
  for (const l of text.split(/\r?\n/)) {
56
+ // Git ends a path with a space in it with a tab, and quotes paths it escapes; run with core.quotePath=false too.
48
57
  if (l.startsWith("+++ ")) {
49
- file = l === "+++ /dev/null" ? null : l.slice(4).replace(/^b\//, "");
58
+ file = l === "+++ /dev/null" ? null : l.slice(4).replace(/\t$/, "").replace(/^"(.*)"$/, "$1").replace(/^b\//, "");
50
59
  continue;
51
60
  }
52
61
  const h = file && l.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/);
@@ -154,6 +163,38 @@ export function parseArgs(argv) {
154
163
  }
155
164
  async function main(argv) {
156
165
  const [cmd, ...raw] = argv;
166
+ if (cmd === "export") {
167
+ if (!raw.includes("--otlp-json")) {
168
+ console.error("Choose a format: lintsure export --otlp-json [path]");
169
+ return 2;
170
+ }
171
+ const root = resolve(raw.find((a) => !a.startsWith("--")) ?? ".");
172
+ let text = "";
173
+ try {
174
+ text = await readFile(join(root, ".lintsure", "activity.jsonl"), "utf8");
175
+ }
176
+ catch { /* none yet */ }
177
+ const rows = parseActivity(text);
178
+ if (!rows.length) {
179
+ console.error("No activity yet in .lintsure/activity.jsonl. The Lintsure plugin writes it while your agent works.");
180
+ return 2;
181
+ }
182
+ await writeFile("lintsure.otlp.json", JSON.stringify(toOtlp(rows, RULES_VERSION), null, 2));
183
+ console.log(`Wrote lintsure.otlp.json: ${rows.length} events. Nothing was sent; load the file into your collector or tool (OTLP/JSON).`);
184
+ return 0;
185
+ }
186
+ if (cmd === "setup" || cmd === "status") {
187
+ const root = resolve(raw.find((a, i) => !a.startsWith("--") && raw[i - 1] !== "--agents") ?? ".");
188
+ if (cmd === "status")
189
+ return status(root);
190
+ const i = raw.indexOf("--agents");
191
+ const agents = await pick(root, i >= 0 ? raw[i + 1]?.split(",").map((s) => s.trim()) : undefined);
192
+ if (typeof agents === "string") {
193
+ console.error(agents);
194
+ return 2;
195
+ }
196
+ return raw.includes("--undo") ? undo(root, agents) : setup(root, agents, raw.includes("--yes"));
197
+ }
157
198
  if (cmd === "init" || cmd === "info")
158
199
  return (cmd === "init" ? init : info)(resolve(raw.find((a) => !a.startsWith("--")) ?? "."));
159
200
  if (cmd !== "scan" && cmd !== "baseline") {
@@ -169,12 +210,13 @@ async function main(argv) {
169
210
  const flag = (n) => { const i = rest.indexOf(n); return i >= 0 ? rest[i + 1] : undefined; };
170
211
  const path = resolve(rest.find((a, i) => !a.startsWith("--") && !VALUE_FLAGS.includes(rest[i - 1])) ?? ".");
171
212
  const wanted = flag("--framework")?.split(",").map((s) => s.trim());
213
+ const config = await readConfig(path);
214
+ // Checked after the config loads its rule packs, so a pack's framework id is accepted.
172
215
  const bad = wanted?.filter((f) => !ALL_FRAMEWORKS.includes(f));
173
216
  if (bad?.length) {
174
217
  console.error(`Unknown framework: ${bad.join(", ")}`);
175
218
  return 2;
176
219
  }
177
- const config = await readConfig(path);
178
220
  if (config.problems.length) {
179
221
  console.error("Problems in lintsure.config.yaml (fix them so the scan checks what you meant):");
180
222
  config.problems.forEach((p) => console.error(` ${p}`));
@@ -188,14 +230,27 @@ async function main(argv) {
188
230
  let changed;
189
231
  if (base) {
190
232
  try {
191
- changed = { base, lines: parseDiff(execFileSync("git", ["diff", "-U0", "--no-color", "--no-ext-diff", "--relative", base, "--"], { cwd: path, encoding: "utf8", maxBuffer: 64 << 20 })) };
233
+ changed = { base, lines: parseDiff(execFileSync("git", ["-c", "core.quotePath=false", "diff", "-U0", "--no-color", "--no-ext-diff", "--relative", base, "--"], { cwd: path, encoding: "utf8", maxBuffer: 64 << 20 })) };
192
234
  }
193
235
  catch {
194
236
  console.error(`--diff: git could not compare with "${base}". Fetch it first (for example git fetch origin main).`);
195
237
  return 2;
196
238
  }
197
239
  }
198
- const report = await scan(path, wanted ?? config.frameworks ?? ALL_FRAMEWORKS, { why, source, all: rest.includes("--all") || undefined, changed });
240
+ // LINTSURE_WORKSPACE_RULES: path to a JSON file of account rules the caller already has (the plugin writes it).
241
+ // Read only to hash into the policy fingerprint; the CLI never fetches them. A file it can't read is an error, not a silent skip.
242
+ let workspaceRules;
243
+ const wsFile = process.env.LINTSURE_WORKSPACE_RULES;
244
+ if (wsFile) {
245
+ try {
246
+ workspaceRules = JSON.parse(await readFile(wsFile, "utf8"));
247
+ }
248
+ catch {
249
+ console.error(`Couldn't read workspace rules from LINTSURE_WORKSPACE_RULES (${wsFile}).`);
250
+ process.exit(2);
251
+ }
252
+ }
253
+ const report = await scan(path, wanted ?? config.frameworks ?? ALL_FRAMEWORKS, { why, source, all: rest.includes("--all") || undefined, changed, workspaceRules });
199
254
  const date = new Date().toISOString().slice(0, 10);
200
255
  if (cmd === "baseline") {
201
256
  const file = join(path, BASELINE_FILE);
@@ -223,7 +278,7 @@ async function main(argv) {
223
278
  const n = (s) => open.filter((f) => f.status === s).length;
224
279
  const accepted = report.findings.length - open.length;
225
280
  if (report.record)
226
- console.log(`Record ${report.record.id} · ${report.record.createdAt.replace("T", " ").slice(0, 16)} UTC · ${report.record.counts.checkPoints} check points`);
281
+ console.log(`Record ${report.record.id} · ${report.record.createdAt.replace("T", " ").slice(0, 16)} UTC · ${report.record.counts.checkPoints} check points${report.policy ? ` · Policy #${report.policy.fingerprint}` : ""}`);
227
282
  // A check mark only when nothing is open: "✓ 3 gaps" read as a pass.
228
283
  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
284
  if (report.diffBase)
@@ -0,0 +1,42 @@
1
+ export interface ActivityRow {
2
+ at: string;
3
+ type: "catch" | "decision" | "scan";
4
+ session?: string | null;
5
+ kind?: string;
6
+ rule?: string;
7
+ file?: string;
8
+ line?: number;
9
+ outcome?: string;
10
+ scope?: string;
11
+ open?: number;
12
+ gap?: number;
13
+ partial?: number;
14
+ policy?: string;
15
+ rules?: string;
16
+ }
17
+ type Attr = {
18
+ key: string;
19
+ value: {
20
+ stringValue: string;
21
+ } | {
22
+ intValue: string;
23
+ };
24
+ };
25
+ /** One trace per session (reads OTEL_SERVICE_NAME for the service name): an invoke_agent span covering it, and one child span per catch, decision or scan. Pure. */
26
+ export declare function toOtlp(rows: ActivityRow[], version: string): {
27
+ resourceSpans: {
28
+ resource: {
29
+ attributes: Attr[];
30
+ };
31
+ scopeSpans: {
32
+ scope: {
33
+ name: string;
34
+ version: string;
35
+ };
36
+ spans: unknown[];
37
+ }[];
38
+ }[];
39
+ };
40
+ /** Reads activity.jsonl lines, skipping any it can't parse. Pure. */
41
+ export declare function parseActivity(text: string): ActivityRow[];
42
+ export {};
@@ -0,0 +1,49 @@
1
+ // lintsure export --otlp-json: turns the local activity log (.lintsure/activity.jsonl, written by the plugin's guards
2
+ // and end-of-task scans) into an OpenTelemetry traces file (OTLP/JSON) a team can load into its own observability
3
+ // tool. Written to a file only; nothing is sent anywhere. Names follow the OpenTelemetry GenAI conventions
4
+ // (gen_ai.operation.name, gen_ai.conversation.id, gen_ai.tool.name) plus Lintsure's own lintsure.* fields.
5
+ // The log holds no code or command text, so the spans can't carry any either.
6
+ import { createHash } from "node:crypto";
7
+ const hex = (s, n) => createHash("sha256").update(s).digest("hex").slice(0, n);
8
+ const nanos = (iso) => `${BigInt(Date.parse(iso) || 0) * 1000000n}`;
9
+ const attrs = (o) => Object.entries(o).filter(([, v]) => v != null && v !== "")
10
+ .map(([key, v]) => ({ key, value: typeof v === "number" ? { intValue: String(v) } : { stringValue: String(v) } }));
11
+ /** One trace per session (reads OTEL_SERVICE_NAME for the service name): an invoke_agent span covering it, and one child span per catch, decision or scan. Pure. */
12
+ export function toOtlp(rows, version) {
13
+ const bySession = new Map();
14
+ for (const r of rows) {
15
+ const k = r.session || "no-session";
16
+ (bySession.get(k) ?? bySession.set(k, []).get(k)).push(r);
17
+ }
18
+ const spans = [];
19
+ for (const [session, list] of bySession) {
20
+ const traceId = hex(`trace:${session}`, 32), rootId = hex(`root:${session}`, 16);
21
+ const times = list.map((r) => r.at).sort();
22
+ spans.push({ traceId, spanId: rootId, name: "invoke_agent", kind: 1, startTimeUnixNano: nanos(times[0]), endTimeUnixNano: nanos(times[times.length - 1]),
23
+ attributes: attrs({ "gen_ai.operation.name": "invoke_agent", "gen_ai.agent.name": "coding agent (guarded by Lintsure)", "gen_ai.conversation.id": session }) });
24
+ list.forEach((r, i) => {
25
+ const base = { traceId, spanId: hex(`span:${session}:${i}:${r.at}`, 16), parentSpanId: rootId, kind: 1, startTimeUnixNano: nanos(r.at), endTimeUnixNano: nanos(r.at) };
26
+ // Current semconv names plus the older ones many tools still read.
27
+ const code = { "code.file.path": r.file, "code.line.number": r.line, "code.filepath": r.file, "code.lineno": r.line };
28
+ if (r.type === "catch")
29
+ spans.push({ ...base, name: `execute_tool lintsure.guard.${r.kind}`, attributes: attrs({ "gen_ai.operation.name": "execute_tool",
30
+ "gen_ai.tool.name": `lintsure.guard.${r.kind}`, "gen_ai.conversation.id": session, "lintsure.rule.id": r.rule, "lintsure.decision": r.outcome, ...code }) });
31
+ else if (r.type === "decision")
32
+ spans.push({ ...base, name: "lintsure.decision", attributes: attrs({ "gen_ai.conversation.id": session, "lintsure.decision": r.scope, "lintsure.rule.id": r.rule, ...code }) });
33
+ else
34
+ spans.push({ ...base, name: "lintsure.scan", attributes: attrs({ "gen_ai.conversation.id": session, "lintsure.policy.fingerprint": r.policy, "lintsure.rules.version": r.rules,
35
+ "lintsure.findings.open": r.open, "lintsure.findings.gap": r.gap, "lintsure.findings.partial": r.partial }) });
36
+ });
37
+ }
38
+ return { resourceSpans: [{ resource: { attributes: attrs({ "service.name": process.env.OTEL_SERVICE_NAME || "lintsure", "service.version": version }) }, scopeSpans: [{ scope: { name: "lintsure", version }, spans }] }] };
39
+ }
40
+ /** Reads activity.jsonl lines, skipping any it can't parse. Pure. */
41
+ export function parseActivity(text) {
42
+ return text.split(/\r?\n/).flatMap((l) => { try {
43
+ const r = JSON.parse(l);
44
+ return r && r.at && r.type ? [r] : [];
45
+ }
46
+ catch {
47
+ return [];
48
+ } });
49
+ }
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "lintsure",
3
- "version": "0.3.10",
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.10"
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.11",
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.11"
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
+ }