@misconfig/cli 1.0.1 → 1.3.0

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/lib/print.js CHANGED
@@ -1,102 +1,259 @@
1
- // Terminal output.
1
+ // Terminal output, in misconfig.ai's visual language: quiet text, bold where
2
+ // it matters, and color in two places only, the grade's square and the
3
+ // severity marks.
4
+
5
+ import { SCOPES } from "../engine/explain.js";
6
+ import { INSTALLED_BY } from "../engine/index.js";
2
7
 
3
8
  const env = process.env;
4
- const color = Boolean(env.FORCE_COLOR) || (process.stdout.isTTY && !env.NO_COLOR && env.TERM !== "dumb");
5
- const paint = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : String(s));
6
- export const bold = paint("1");
7
- export const dim = paint("2");
8
- const SEV = {
9
- critical: { label: "Critical", paint: paint("1;31") },
10
- high: { label: "High", paint: paint("1;38;5;208") },
11
- medium: { label: "Medium", paint: paint("1;33") },
12
- low: { label: "Low", paint: paint("1;34") },
13
- info: { label: "Info", paint: paint("2") },
9
+
10
+ // --- Color -------------------------------------------------------------------
11
+
12
+ // Color depth in bits: 24, 8, 4, or 1 for none. FORCE_COLOR and NO_COLOR
13
+ // work as in Node, and output that isn't a terminal is plain unless forced.
14
+ function colorDepth(stream) {
15
+ if ("FORCE_COLOR" in env) {
16
+ if (/^(0|false)$/i.test(env.FORCE_COLOR)) return 1;
17
+ if (stream.isTTY && stream.getColorDepth) return Math.max(stream.getColorDepth(), 4);
18
+ return env.FORCE_COLOR === "3" ? 24 : env.FORCE_COLOR === "2" ? 8 : 4;
19
+ }
20
+ if (!stream.isTTY || env.NO_COLOR || env.TERM === "dumb") return 1;
21
+ return stream.getColorDepth?.() ?? 4;
22
+ }
23
+ const depth = colorDepth(process.stdout);
24
+
25
+ // The site's colors, with the nearest of 256 and of 16 for older terminals.
26
+ const COLORS = {
27
+ signal: { rgb: [0xea, 0xff, 0x57], ansi: 93 },
28
+ ink: { rgb: [0x00, 0x00, 0x00], ansi: 30 },
29
+ critical: { rgb: [0xd7, 0x26, 0x3d], ansi: 31 },
30
+ high: { rgb: [0xe8, 0x63, 0x0a], ansi: 91 },
31
+ medium: { rgb: [0xb9, 0x89, 0x00], ansi: 33 },
32
+ low: { rgb: [0x25, 0x63, 0xeb], ansi: 34 },
33
+ info: { rgb: [0x8a, 0x90, 0x9c], ansi: 90 },
14
34
  };
15
- const MARK = process.platform === "win32" && !env.WT_SESSION ? "*" : "■";
35
+ const LEVELS = [0, 95, 135, 175, 215, 255];
36
+ const nearest = (c) => LEVELS.reduce((best, v, i) => (Math.abs(v - c) < Math.abs(LEVELS[best] - c) ? i : best), 0);
37
+ const cube = ([r, g, b]) => 16 + 36 * nearest(r) + 6 * nearest(g) + nearest(b);
38
+ function code(name, layer) {
39
+ const { rgb, ansi } = COLORS[name];
40
+ const base = layer === "bg" ? 48 : 38;
41
+ if (depth >= 24) return `${base};2;${rgb.join(";")}`;
42
+ if (depth >= 8) return `${base};5;${cube(rgb)}`;
43
+ return String(layer === "bg" ? ansi + 10 : ansi);
44
+ }
45
+ const on = depth > 1;
46
+ const style = (open, close) => (s) => (on ? `\x1b[${open}m${s}\x1b[${close}m` : String(s));
47
+ export const bold = style("1", "22");
48
+ export const dim = style("2", "22");
49
+ const color = (name) => (s) => (on ? `\x1b[${code(name, "fg")}m${s}\x1b[39m` : String(s));
16
50
 
17
- const width = () => Math.min(Math.max(process.stdout.columns || 100, 60), 110);
51
+ // --- Text --------------------------------------------------------------------
18
52
 
19
- function wrap(text, indent) {
53
+ // Text from the files being checked can hold terminal control codes that
54
+ // would rewrite the screen, or bidirectional marks that reorder it. They're
55
+ // shown as the replacement character (U+FFFD) instead.
56
+ const safe = (s) => String(s ?? "").replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, "\ufffd");
57
+ // For text printed on one line, such as a title or a path: line breaks in it
58
+ // would start a new line that looks like part of the report.
59
+ export const oneLine = (s) => safe(s).replace(/[\t\n]/g, " ");
60
+
61
+ const width = () => Math.min(Math.max(process.stdout.columns || Number(env.COLUMNS) || 100, 60), 100);
62
+
63
+ // Words wrapped to the width, each line indented. `first` replaces the
64
+ // indent on the first line, for a bullet or a label.
65
+ function wrap(text, indent, first = null) {
20
66
  const max = width() - indent;
21
- const words = String(text).split(/\s+/);
22
67
  const lines = [];
23
68
  let line = "";
24
- for (const w of words) {
69
+ for (const w of safe(text).split(/\s+/).filter(Boolean)) {
25
70
  if (line && line.length + 1 + w.length > max) {
26
71
  lines.push(line);
27
72
  line = w;
28
73
  } else line = line ? `${line} ${w}` : w;
29
74
  }
30
75
  if (line) lines.push(line);
31
- return lines.map((l) => " ".repeat(indent) + l).join("\n");
76
+ return lines.map((l, i) => (i === 0 && first !== null ? first : " ".repeat(indent)) + l);
77
+ }
78
+
79
+ // A path that fits the line: long ones keep their start and as much of the
80
+ // end as fits, so the file name and the folders just above it stay visible.
81
+ function fitPath(p, max) {
82
+ const s = oneLine(p);
83
+ if (s.length <= max) return s;
84
+ const parts = s.split("/");
85
+ const head = parts.slice(0, parts[0] === "~" ? 2 : 1).join("/");
86
+ let tail = parts[parts.length - 1];
87
+ for (let i = parts.length - 2; i >= 1 && `${head}/…/${parts[i]}/${tail}`.length <= max; i--) tail = `${parts[i]}/${tail}`;
88
+ const out = `${head}/…/${tail}`;
89
+ return out.length <= max ? out : `…${s.slice(-(max - 1))}`;
32
90
  }
33
91
 
34
- const listText = (items) => (items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`);
92
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
93
+ const npx = process.platform === "win32" ? "npx.cmd" : "npx";
94
+
95
+ // --- Report ------------------------------------------------------------------
96
+
97
+ const SEVERITY = { critical: "Critical", high: "High", medium: "Medium", low: "Low", info: "Info" };
98
+ const MARK = "■";
35
99
 
36
- export function printReport(result, { version, scanned }) {
100
+ export function printReport(result, { version, scanned, explain = false, open = false, lookedUp = false }) {
37
101
  const out = [];
102
+ // One blank line between blocks, never two.
103
+ const gap = () => out.length && out[out.length - 1] !== "" && out.push("");
38
104
  const where = scanned.projectSkipped ? "your home folder" : scanned.project;
105
+ const sent = lookedUp ? "Everything ran here. Only package names and versions went to OSV.dev, to look them up." : "Everything ran here; nothing was uploaded.";
39
106
  out.push(`${bold("misconfig")} ${dim(version)}`);
40
- out.push(
41
- wrap(
42
- `Checked ${where}${scanned.user ? " and the agent settings on this computer" : ""}. Everything ran here; nothing was uploaded.`,
43
- 0,
44
- ),
45
- );
107
+ out.push(...wrap(`Checked ${where}${scanned.user ? " and the agent settings on this computer" : ""}. ${sent}`, 0).map(dim));
46
108
  out.push("");
47
109
 
48
- // The grade, printed on the brand's chartreuse square.
49
- const badge = color ? `\x1b[1;38;5;16;48;5;191m ${result.grade} \x1b[0m` : `[${result.grade}]`;
50
- const score = typeof result.score === "number" ? `${result.score} out of 100` : "no agent setup files found";
51
- out.push(` ${badge} ${bold(score)}`);
52
- const counts = ["critical", "high", "medium", "low"].filter((s) => result.counts[s]).map((s) => SEV[s].paint(`${result.counts[s]} ${s}`));
53
- out.push(` ${counts.length ? counts.join(dim(", ")) : "No issues found"}`);
54
- out.push("");
110
+ // Every file that directs an agent, where it applies, and what it tells the
111
+ // agent. Worked out on this computer, and sent only in an --open report,
112
+ // encrypted here.
113
+ const map = result.controlMap;
114
+ if (map.length) {
115
+ out.push(`${bold("What controls your agents")} ${dim(plural(map.length, "file"))}`);
116
+ for (const scope of ["admin", "computer", "project", "loose"]) {
117
+ const files = map.filter((f) => (f.scope ?? "project") === scope);
118
+ if (!files.length) continue;
119
+ out.push("", ` ${dim(SCOPES[scope])}`);
120
+ for (const f of files) {
121
+ const agents = f.tools.filter((t) => t !== "Any agent started there").join(", ");
122
+ const room = width() - 4 - (agents ? agents.length + 2 : 0);
123
+ if (explain) out.push("");
124
+ out.push(` ${bold(fitPath(f.path, Math.max(room, 30)))}${agents ? ` ${dim(oneLine(agents))}` : ""}`);
125
+ if (f.summary) out.push(...wrap(f.summary, 6));
126
+ if (explain) for (const d of f.details ?? []) out.push(...wrap(d, 8, ` ${dim("·")} `));
127
+ }
128
+ }
129
+ }
55
130
 
56
- // Which files control which agent.
57
- if (result.controlMap.length) {
58
- out.push(bold("Files that control your agents"));
59
- // One file per line under each agent. Loose instruction files aren't tied to
60
- // one agent: they steer any agent started in their folder.
61
- const byAgent = new Map();
62
- for (const f of result.controlMap) for (const t of f.tools) {
63
- const name = t === "Any agent started there" ? "Loose files" : t;
64
- byAgent.set(name, [...(byAgent.get(name) ?? []), f.path]);
131
+ // What's installed: agents and editor extensions, with --explain.
132
+ const installed = result.installed ?? { agents: [], editors: [] };
133
+ if (explain && (installed.agents.length || installed.editors.length)) {
134
+ gap();
135
+ out.push(bold("What's installed"));
136
+ if (installed.agents.length) {
137
+ out.push("", ` ${dim("AI agents")}`);
138
+ for (const a of installed.agents) out.push(` ${bold(oneLine(`${a.tool} ${a.version}`))} ${dim(oneLine(`${INSTALLED_BY[a.via] ?? a.via}, ${fitPath(a.path, width() - 30)}`))}`);
65
139
  }
66
- const pad = Math.max(...[...byAgent.keys()].map((k) => k.length)) + 2;
67
- for (const [agent, paths] of byAgent) {
68
- const shown = paths.slice(0, 8);
69
- shown.forEach((p, i) => out.push(` ${(i ? "" : agent).padEnd(pad)}${p}`));
70
- if (paths.length > shown.length) out.push(` ${"".padEnd(pad)}${dim(`and ${paths.length - shown.length} more`)}`);
140
+ for (const e of installed.editors) {
141
+ out.push("", ` ${dim(oneLine(`${e.editor} extensions, ${e.dir}`))}`);
142
+ const agents = e.agents.map((x) => `${x.name} ${x.version}`.trim());
143
+ const named = agents.length <= 1 ? agents.join("") : `${agents.slice(0, -1).join(", ")} and ${agents.at(-1)}`;
144
+ out.push(...wrap(`${plural(e.count, "extension")}${agents.length ? `, including ${named}` : ""}.`, 4));
71
145
  }
72
- out.push("");
73
146
  }
74
147
 
75
- for (const sev of ["critical", "high", "medium", "low", "info"]) {
76
- const group = result.findings.filter((f) => f.severity === sev);
77
- if (!group.length) continue;
78
- out.push(SEV[sev].paint(`${SEV[sev].label} (${group.length})`));
79
- for (const f of group) {
80
- out.push(` ${SEV[sev].paint(MARK)} ${bold(f.title)}`);
81
- if (f.file) out.push(` ${dim(f.file + (f.line ? `:${f.line}` : ""))}`);
82
- if (sev === "critical" || sev === "high") out.push(wrap(f.why, 4));
83
- out.push(wrap(`Fix: ${f.fix}`, 4));
84
- out.push("");
148
+ // What to fix, worst first.
149
+ const findings = result.findings;
150
+ if (findings.length) {
151
+ gap();
152
+ out.push(`${bold("Findings")} ${dim(String(findings.length))}`);
153
+ for (const sev of Object.keys(SEVERITY)) {
154
+ const group = findings.filter((f) => f.severity === sev);
155
+ if (!group.length) continue;
156
+ const paint = color(sev);
157
+ out.push("", ` ${paint(bold(SEVERITY[sev]))} ${dim(String(group.length))}`);
158
+ for (const [n, f] of group.entries()) {
159
+ if (n) out.push("");
160
+ out.push(...wrap(f.title, 6).map((l, i) => `${i === 0 ? ` ${paint(MARK)} ` : " "}${bold(l.slice(6))}`));
161
+ // Where it is, then the rule, which misconfig.ai/rules explains.
162
+ const at = f.file ? fitPath(f.file, width() - 16 - f.id.length) + (f.line ? `:${f.line}` : "") : "";
163
+ out.push(` ${dim(at ? `${at} ${f.id}` : f.id)}`);
164
+ if (sev === "critical" || sev === "high" || sev === "medium") out.push(...wrap(f.why, 6));
165
+ out.push(...wrap(f.fix, 11, ` ${dim("Fix")} `));
166
+ }
85
167
  }
86
168
  }
87
169
 
88
- if (!result.findings.length) out.push(result.controlMap.length ? "No issues found in these files." : "No files that control AI agents were found.", "");
89
- out.push(dim("Share this project's report: npx @misconfig/cli --share"));
90
- out.push(dim("Full details as JSON: npx @misconfig/cli --json"));
170
+ gap();
171
+ const stopped = () => wrap(`The check stopped after ${result.stats.entriesScanned.toLocaleString("en-US")} files and folders, so agent files deeper in this folder may have been missed. Run it in a smaller folder to check everything.`, 0);
172
+ if (!map.length && !findings.length) {
173
+ out.push(...wrap("No files that control AI agents were found here. Run the check in the folder you open your agent in, usually the project root.", 0));
174
+ if (result.stats.truncated) out.push("", ...stopped());
175
+ process.stdout.write(out.join("\n") + "\n");
176
+ return;
177
+ }
178
+ // The verdict, last, where it's on screen when the check finishes.
179
+ out.push(...verdict(result), "");
180
+ if (result.stats.truncated) out.push(...stopped(), "");
181
+ const next = [];
182
+ if (!explain && map.some((f) => f.details?.length)) next.push(["Everything each file says", `${npx} @misconfig/cli --explain`]);
183
+ if (!open) next.push(["Full report in your browser", `${npx} @misconfig/cli --open`]);
184
+ if (!scanned.projectSkipped) next.push(["Share this project's report", `${npx} @misconfig/cli --share`]);
185
+ if (!lookedUp && result.packages?.length) next.push(["Look up installs on OSV.dev", `${npx} @misconfig/cli --lookup`]);
186
+ if (findings.length) next.push(["Every rule explained", "https://misconfig.ai/rules"]);
187
+ next.push(["Full details as JSON", `${npx} @misconfig/cli --json`]);
188
+ const pad = Math.max(...next.map(([label]) => label.length)) + 3;
189
+ for (const [label, command] of next) out.push(`${dim(label.padEnd(pad))}${command}`);
91
190
  process.stdout.write(out.join("\n") + "\n");
92
191
  }
93
192
 
193
+ // The grade on its square, beside the score, the counts and what was checked.
194
+ // Without color it's plain lines that read the same in a log.
195
+ function verdict(result) {
196
+ const counts = ["critical", "high", "medium", "low"].filter((s) => result.counts[s]);
197
+ const score = `${result.score} out of 100`;
198
+ const s = result.stats;
199
+ const parts = [plural(s.filesChecked, "agent file"), s.mcpServers ? plural(s.mcpServers, "MCP server") : null, s.agentInstalls ? plural(s.agentInstalls, "agent install") : null, s.extensions ? plural(s.extensions, "editor extension") : null].filter(Boolean);
200
+ const checked = `Checked ${parts.length > 1 ? `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}` : parts[0]}.`;
201
+ if (!on) {
202
+ return [`Grade ${result.grade}, ${score}`, counts.length ? counts.map((s) => `${result.counts[s]} ${s}`).join(", ") : "No issues found", checked];
203
+ }
204
+ const tile = (s) => `\x1b[${code("signal", "bg")};${code("ink", "fg")}m${s}\x1b[0m`;
205
+ const tally = counts.length ? counts.map((s) => `${color(s)(MARK)} ${result.counts[s]} ${s}`).join(" ") : "No issues found";
206
+ return [
207
+ ` ${tile(" ")} ${bold(score)}`,
208
+ ` ${tile(` \x1b[1m${result.grade}\x1b[22m `)} ${tally}`,
209
+ ` ${tile(" ")} ${dim(checked)}`,
210
+ ];
211
+ }
212
+
213
+
214
+ // --- Looking up installs ---------------------------------------------------------
215
+
216
+ // Everything --lookup sends, listed before anything is sent.
217
+ export function printLookupPreview(out, queries) {
218
+ const lines = ["", bold("Look up what's installed on OSV.dev")];
219
+ if (!queries.length) {
220
+ lines.push(...wrap("There's nothing to look up: no MCP packages, agent installs or editor extensions were found.", 2), "");
221
+ out.write(lines.join("\n") + "\n");
222
+ return;
223
+ }
224
+ lines.push(
225
+ ...wrap(
226
+ `This sends ${plural(queries.length, "package name")} and their versions to OSV.dev, the open source vulnerability database. Nothing else is sent: no paths, file contents, server names or settings. The names come from your setup, so if one is private to your company, answer no.`,
227
+ 2,
228
+ ),
229
+ "",
230
+ );
231
+ const shown = queries.slice(0, 40);
232
+ for (const q of shown) lines.push(oneLine(` ${q.ecosystem.padEnd(7)} ${q.name}${q.version ? ` ${q.version}` : ""}`) + (q.version ? "" : dim(" (any version)")));
233
+ if (queries.length > shown.length) lines.push(dim(` and ${queries.length - shown.length} more`));
234
+ out.write(lines.join("\n") + "\n");
235
+ }
236
+
237
+ export function printLookupResult(out, { asked, failed, found }) {
238
+ const parts =
239
+ failed >= asked
240
+ ? ["OSV.dev didn't answer, so nothing was looked up. Try again later."]
241
+ : [
242
+ `Looked up ${plural(asked - failed, "package")} on OSV.dev.`,
243
+ found ? `${plural(found, "finding")} added to the report.` : "Nothing new turned up.",
244
+ failed ? `${plural(failed, "package")} couldn't be looked up; try again later.` : "",
245
+ ];
246
+ out.write(["", ...wrap(parts.filter(Boolean).join(" "), 2), ""].join("\n") + "\n");
247
+ }
248
+
249
+ // --- Sharing -----------------------------------------------------------------
250
+
94
251
  // Everything a share sends, listed before anything is sent.
95
252
  export function printSharePreview(out, payload, project, { includesUser }) {
96
253
  const lines = ["", bold("Share this project's report")];
97
254
  const score = typeof project.score === "number" ? `grade ${project.grade}, ${project.score} out of 100` : "no grade";
98
255
  lines.push(
99
- wrap(
256
+ ...wrap(
100
257
  includesUser
101
258
  ? `The link covers this project only (${score}). The settings on this computer aren't included.`
102
259
  : `The link shows ${score}.`,
@@ -109,30 +266,59 @@ export function printSharePreview(out, payload, project, { includesUser }) {
109
266
  for (const f of payload.findings) {
110
267
  const where = f.file ? `${f.file}${f.line ? `:${f.line}` : ""}` : "";
111
268
  const vars = Object.entries(f.vars).map(([k, v]) => `${k}=${v}`).join(", ");
112
- lines.push(` ${f.id}${where ? ` ${where}` : ""}${vars ? dim(` ${vars}`) : ""}`);
269
+ lines.push(oneLine(` ${f.id}${where ? ` ${where}` : ""}`) + (vars ? dim(` ${oneLine(vars)}`) : ""));
113
270
  }
114
271
  lines.push(
115
- ` File names: ${payload.controlMap.length ? payload.controlMap.join(", ") : "none"}`,
116
- ` Totals: ${payload.stats.filesChecked} files checked, ${payload.stats.mcpServers} MCP servers`,
272
+ oneLine(` File names: ${payload.controlMap.length ? payload.controlMap.join(", ") : "none"}`),
273
+ ` Totals: ${plural(payload.stats.filesChecked, "agent file")} checked, ${plural(payload.stats.mcpServers, "MCP server")}`,
117
274
  "",
118
- wrap(dim("Not sent: file contents, quoted lines, this folder's name and anything outside it."), 2),
275
+ ...wrap("Not sent: file contents, quoted lines, this folder's name and anything outside it.", 2).map(dim),
119
276
  "",
120
277
  );
121
278
  out.write(lines.join("\n") + "\n");
122
279
  }
123
280
 
124
- export function printShareResult(out, data) {
281
+ // What --open will do, before anything is sent.
282
+ export function printOpenPreview(out, { includesUser = true } = {}) {
283
+ out.write(
284
+ [
285
+ "",
286
+ bold("Open the full report in your browser"),
287
+ ...wrap(
288
+ `Everything above, including ${includesUser ? "the settings on this computer and " : ""}what each file says, is encrypted here before it's sent. misconfig.ai keeps only the encrypted copy, for 7 days, and can't read it. The key is part of the link, so anyone you give the link to can read the report.`,
289
+ 2,
290
+ ),
291
+ ].join("\n") + "\n",
292
+ );
293
+ }
294
+
295
+ export function printOpenResult(out, { link, deleteLink, expiresAt, opening }) {
296
+ const expires = expiresAt ? new Date(expiresAt).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }) : "In 7 days";
297
+ out.write(
298
+ [
299
+ "",
300
+ bold("Private report ready"),
301
+ ` Link ${link}`,
302
+ ` Delete link ${deleteLink}`,
303
+ ` Expires ${expires}`,
304
+ "",
305
+ ...wrap(`${opening ? "Opening it in your browser. " : ""}Keep both links private. Without them the report can't be opened, and misconfig.ai can't recover them.`, 2).map(dim),
306
+ "",
307
+ ].join("\n") + "\n",
308
+ );
309
+ }
310
+
311
+ export function printShareResult(out, { url, deleteToken }) {
125
312
  out.write(
126
313
  [
127
314
  "",
128
315
  bold("Share link created"),
129
- ` Link: ${data.url}`,
130
- ` README badge: [![AI setup](${data.badgeUrl})](${data.url})`,
131
- ` Delete link: ${data.url}#delete=${data.deleteToken}`,
132
- dim(" Save the delete link now. It isn't shown again. The report expires in 30 days."),
316
+ ` Link ${url}`,
317
+ ` README badge [![AI setup](${url}/badge.svg)](${url})`,
318
+ ` Delete link ${url}#delete=${deleteToken}`,
319
+ "",
320
+ ...wrap("Save the delete link now. It isn't shown again. The report expires in 30 days.", 2).map(dim),
133
321
  "",
134
322
  ].join("\n"),
135
323
  );
136
324
  }
137
-
138
- export { listText };
package/lib/private.js ADDED
@@ -0,0 +1,47 @@
1
+ // Private reports: the whole report, encrypted on this computer before it's
2
+ // sent. misconfig.ai keeps the encrypted bytes for 7 days and never gets the
3
+ // key, which only travels in the link after "#", the part of a link browsers
4
+ // don't send to servers.
5
+
6
+ import { gzipSync } from "node:zlib";
7
+ import { webcrypto } from "node:crypto";
8
+ import { spawn } from "node:child_process";
9
+
10
+ // Format 1: [1][12-byte nonce][AES-256-GCM ciphertext of the gzipped JSON,
11
+ // with its 16-byte tag]. The page at misconfig.ai/p/ reads the same format.
12
+ const FORMAT = 1;
13
+ const AAD = new TextEncoder().encode("misconfig private report v1");
14
+ export const MAX_BYTES = 512 * 1024;
15
+ // The page won't unpack a report larger than this, so one that is isn't sent.
16
+ export const MAX_PLAIN_BYTES = 16 * 1024 * 1024;
17
+
18
+ export async function seal(report) {
19
+ const json = Buffer.from(JSON.stringify(report), "utf8");
20
+ if (json.length > MAX_PLAIN_BYTES) return { body: null, key: null };
21
+ const plain = gzipSync(json);
22
+ const raw = webcrypto.getRandomValues(new Uint8Array(32));
23
+ const iv = webcrypto.getRandomValues(new Uint8Array(12));
24
+ const key = await webcrypto.subtle.importKey("raw", raw, "AES-GCM", false, ["encrypt"]);
25
+ const sealed = new Uint8Array(await webcrypto.subtle.encrypt({ name: "AES-GCM", iv, additionalData: AAD }, key, plain));
26
+ const body = new Uint8Array(1 + iv.length + sealed.length);
27
+ body[0] = FORMAT;
28
+ body.set(iv, 1);
29
+ body.set(sealed, 1 + iv.length);
30
+ return { body, key: Buffer.from(raw).toString("base64url") };
31
+ }
32
+
33
+ // Opens a link in the default browser. If that doesn't work, nothing is
34
+ // lost: the link is printed too.
35
+ export function openInBrowser(link) {
36
+ const [command, args] =
37
+ process.platform === "win32"
38
+ ? ["rundll32", ["url.dll,FileProtocolHandler", link]]
39
+ : process.platform === "darwin"
40
+ ? ["open", [link]]
41
+ : ["xdg-open", [link]];
42
+ try {
43
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
44
+ child.on("error", () => {});
45
+ child.unref();
46
+ } catch {}
47
+ }
package/package.json CHANGED
@@ -1,23 +1,7 @@
1
1
  {
2
2
  "name": "@misconfig/cli",
3
- "version": "1.0.1",
4
- "description": "Finds every file that controls your AI coding agents and checks it for risky settings. Runs on your computer; nothing is uploaded unless you add --share.",
5
- "type": "module",
6
- "bin": {
7
- "misconfig": "bin/misconfig.js"
8
- },
9
- "files": [
10
- "bin",
11
- "lib",
12
- "engine",
13
- "README.md"
14
- ],
15
- "scripts": {
16
- "prepublishOnly": "node ../scripts/build-cli.mjs"
17
- },
18
- "engines": {
19
- "node": ">=18"
20
- },
3
+ "version": "1.3.0",
4
+ "description": "See every file that controls your AI coding agents, what each one tells them to do, which settings put your machine at risk, and whether anything they run is known malware. Runs on your computer.",
21
5
  "keywords": [
22
6
  "claude-code",
23
7
  "codex",
@@ -27,11 +11,28 @@
27
11
  "mcp",
28
12
  "ai-agents",
29
13
  "security",
30
- "misconfiguration"
14
+ "misconfiguration",
15
+ "malware",
16
+ "supply-chain"
31
17
  ],
32
18
  "homepage": "https://misconfig.ai",
33
- "author": "GK Data LLC",
34
19
  "license": "UNLICENSED",
20
+ "author": "GK Data LLC",
21
+ "type": "module",
22
+ "bin": {
23
+ "misconfig": "bin/misconfig.js"
24
+ },
25
+ "files": [
26
+ "bin",
27
+ "lib",
28
+ "engine",
29
+ "README.md",
30
+ "CHANGELOG.md",
31
+ "LICENSE"
32
+ ],
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
35
36
  "publishConfig": {
36
37
  "access": "public"
37
38
  }