@misconfig/cli 1.1.0 → 1.3.1
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/CHANGELOG.md +187 -0
- package/LICENSE +1 -0
- package/README.md +110 -30
- package/bin/misconfig.js +29 -1
- package/engine/catalog.js +504 -99
- package/engine/decode.js +41 -0
- package/engine/explain.js +792 -79
- package/engine/flags.js +121 -0
- package/engine/glob.js +178 -0
- package/engine/index.js +2108 -376
- package/engine/known.js +587 -0
- package/engine/locations.js +96 -49
- package/engine/mask.js +74 -21
- package/engine/named.js +91 -0
- package/engine/parse.js +442 -42
- package/engine/paths.js +83 -20
- package/lib/discover.js +675 -97
- package/lib/findings.js +109 -0
- package/lib/html.js +201 -0
- package/lib/lookup.js +209 -0
- package/lib/main.js +135 -39
- package/lib/print.js +223 -93
- package/package.json +22 -20
- package/report/fonts/OFL.txt +93 -0
- package/report/fonts/recursive-mono.woff2 +0 -0
- package/report/fonts/recursive-sans.woff2 +0 -0
- package/report/mark-black.svg +1 -0
- package/report/mark.svg +1 -0
- package/report/styles.css +2656 -0
package/engine/flags.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Command-line options that turn off an agent's approval prompts or sandbox,
|
|
2
|
+
// and which agent each one belongs to. Used for shell aliases, scripts, hooks
|
|
3
|
+
// and instruction files.
|
|
4
|
+
|
|
5
|
+
// How each agent's command looks on a command line, after any folder,
|
|
6
|
+
// extension or version is taken off.
|
|
7
|
+
const AGENT_COMMANDS = [
|
|
8
|
+
["Claude Code", /^(?:claude|@anthropic-ai\/claude-code)$/],
|
|
9
|
+
["Codex", /^(?:codex|@openai\/codex)$/],
|
|
10
|
+
["Gemini CLI", /^(?:gemini|@google\/gemini-cli)$/],
|
|
11
|
+
["Qwen Code", /^(?:qwen|@qwen-code\/qwen-code)$/],
|
|
12
|
+
["GitHub Copilot", /^(?:copilot|@github\/copilot)$/],
|
|
13
|
+
["Cursor", /^cursor-agent$/],
|
|
14
|
+
["Aider", /^(?:aider|aider-chat)$/],
|
|
15
|
+
["Amp", /^(?:amp|@sourcegraph\/amp)$/],
|
|
16
|
+
["Grok", /^(?:grok|@vibe-kit\/grok-cli)$/],
|
|
17
|
+
["Kiro", /^kiro-cli$/],
|
|
18
|
+
["OpenCode", /^(?:opencode|opencode-ai)$/],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// Each option by the name reports show. A `shared` option also exists in
|
|
22
|
+
// other programs (npx -y, rm -f, bash -c), so it counts only after that
|
|
23
|
+
// agent's own command name. `value` is the option's value, in lower case.
|
|
24
|
+
const DANGER_FLAGS = [
|
|
25
|
+
{ flag: "--dangerously-skip-permissions", agents: ["Claude Code"] },
|
|
26
|
+
{ flag: "--allow-dangerously-skip-permissions", agents: ["Claude Code"] },
|
|
27
|
+
{ flag: "--permission-mode bypassPermissions", agents: ["Claude Code"], names: ["--permission-mode"], value: "bypasspermissions" },
|
|
28
|
+
{ flag: "--dangerously-bypass-approvals-and-sandbox", agents: ["Codex"] },
|
|
29
|
+
{ flag: "--sandbox danger-full-access", agents: ["Codex"], names: ["--sandbox", "-s"], value: "danger-full-access" },
|
|
30
|
+
{ flag: "-c sandbox_mode=danger-full-access", agents: ["Codex"], names: ["-c", "--config"], value: "sandbox_mode=danger-full-access", shared: true },
|
|
31
|
+
{ flag: "--ask-for-approval never", agents: ["Codex"], names: ["--ask-for-approval", "-a"], value: "never", shared: true },
|
|
32
|
+
{ flag: "-c approval_policy=never", agents: ["Codex"], names: ["-c", "--config"], value: "approval_policy=never", shared: true },
|
|
33
|
+
{ flag: "--yolo", agents: ["Codex", "Gemini CLI", "Qwen Code", "GitHub Copilot", "Cursor"], shared: true },
|
|
34
|
+
{ flag: "--approval-mode yolo", agents: ["Gemini CLI", "Qwen Code"], names: ["--approval-mode"], value: "yolo" },
|
|
35
|
+
{ flag: "-y", agents: ["Gemini CLI", "Qwen Code"], shared: true },
|
|
36
|
+
{ flag: "--allow-all-tools", agents: ["GitHub Copilot"] },
|
|
37
|
+
{ flag: "--allow-all", agents: ["GitHub Copilot"], shared: true },
|
|
38
|
+
{ flag: "--force", agents: ["Cursor"], names: ["--force", "-f"], shared: true },
|
|
39
|
+
{ flag: "--yes-always", agents: ["Aider"] },
|
|
40
|
+
{ flag: "--dangerously-allow-all", agents: ["Amp"] },
|
|
41
|
+
{ flag: "--always-approve", agents: ["Grok"], shared: true },
|
|
42
|
+
{ flag: "--trust-all-tools", agents: ["Kiro"] },
|
|
43
|
+
];
|
|
44
|
+
const QUICK_FLAGS = /--(?:dangerously|allow-dangerously|permission-mode|sandbox|ask-for-approval|yolo|approval-mode|allow-all|force|yes-always|always-approve|trust-all|config)|\s-[ysafc]\b/i;
|
|
45
|
+
|
|
46
|
+
// A program by its name alone, wherever it's installed: C:\\Windows\\...\\powershell.exe
|
|
47
|
+
// is powershell.
|
|
48
|
+
export const programName = (word) => String(word).split(/[\\/]/).pop().replace(/\.(?:exe|cmd|bat|com|ps1)$/i, "");
|
|
49
|
+
|
|
50
|
+
// A command line ends at && || ; | or a new line, and in Markdown at a
|
|
51
|
+
// backtick, so an option is only credited to the command it belongs to.
|
|
52
|
+
export const COMMAND_BREAK = /&&|\|\||[;|`\n]|\$\(/g;
|
|
53
|
+
// After the agent's name, its own options end at "--" or at another program.
|
|
54
|
+
const PROGRAMS = /^(?:npx|npm|pnpm|pnpx|yarn|bunx|bun|uvx|uv|pipx|node|deno|python[0-9.]*|docker|podman|bash|sh|zsh|fish|cmd|pwsh|powershell|sudo|env)$/;
|
|
55
|
+
|
|
56
|
+
// Strips quotes, brackets and punctuation from the ends of a word, with a
|
|
57
|
+
// loop rather than a pattern, so a long run of them can't slow it down.
|
|
58
|
+
export function trimWord(word, lead = "\"'({[", trail = "\"',;:)}].") {
|
|
59
|
+
let a = 0;
|
|
60
|
+
let b = word.length;
|
|
61
|
+
while (a < b && lead.includes(word[a])) a++;
|
|
62
|
+
while (b > a && trail.includes(word[b - 1])) b--;
|
|
63
|
+
return word.slice(a, b);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function commandWord(token) {
|
|
67
|
+
const eq = token.indexOf("=");
|
|
68
|
+
// FOO=1 claude, or alias cc='claude
|
|
69
|
+
let t = trimWord(/^[\w.-]*=/.test(token) ? token.slice(eq + 1) : token).toLowerCase();
|
|
70
|
+
if (!t.startsWith("@")) t = t.split(/[\\/]/).pop();
|
|
71
|
+
return t.replace(/\.(?:exe|cmd|bat|ps1)$/, "").replace(/(.)@[^/@]*$/, "$1");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The first option in `text` that turns approvals off, as { flag, agent, index }.
|
|
75
|
+
// `skip(index)` can reject a match, for example one in a "never use" sentence.
|
|
76
|
+
export function findDangerFlag(text, skip = () => false) {
|
|
77
|
+
const s = String(text);
|
|
78
|
+
if (!QUICK_FLAGS.test(s)) return null;
|
|
79
|
+
let start = 0;
|
|
80
|
+
const breaks = [...s.matchAll(COMMAND_BREAK)].map((m) => m.index).concat(s.length);
|
|
81
|
+
for (const end of breaks) {
|
|
82
|
+
const hit = flagInCommand(s, start, end, skip);
|
|
83
|
+
if (hit) return hit;
|
|
84
|
+
start = end + 1;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function flagInCommand(s, from, to, skip) {
|
|
90
|
+
const tokens = [...s.slice(from, to).matchAll(/\S+/g)].map((m) => ({ raw: m[0], at: from + m.index }));
|
|
91
|
+
if (!tokens.length) return null;
|
|
92
|
+
// Which agent's options each token falls under.
|
|
93
|
+
const owner = new Array(tokens.length).fill(null);
|
|
94
|
+
let current = null;
|
|
95
|
+
for (const [i, t] of tokens.entries()) {
|
|
96
|
+
const word = commandWord(t.raw);
|
|
97
|
+
const agent = AGENT_COMMANDS.find(([, re]) => re.test(word))?.[0];
|
|
98
|
+
if (agent) current = agent;
|
|
99
|
+
else if (word === "--" || PROGRAMS.test(word)) current = null;
|
|
100
|
+
else owner[i] = current;
|
|
101
|
+
}
|
|
102
|
+
for (const [i, t] of tokens.entries()) {
|
|
103
|
+
const raw = trimWord(t.raw);
|
|
104
|
+
if (!raw.startsWith("-")) continue;
|
|
105
|
+
const eq = raw.indexOf("=");
|
|
106
|
+
const name = eq > 0 && raw.startsWith("--") ? raw.slice(0, eq) : raw;
|
|
107
|
+
const inline = eq > 0 && raw.startsWith("--") ? raw.slice(eq + 1) : undefined;
|
|
108
|
+
const value = trimWord(inline ?? tokens[i + 1]?.raw ?? "", "\"'", "\"',;:)}].")
|
|
109
|
+
.toLowerCase()
|
|
110
|
+
.replace(/["']/g, "");
|
|
111
|
+
for (const spec of DANGER_FLAGS) {
|
|
112
|
+
const names = spec.names ?? [spec.flag];
|
|
113
|
+
if (!names.includes(name)) continue;
|
|
114
|
+
if (spec.value && value !== spec.value) continue;
|
|
115
|
+
if (spec.shared && !spec.agents.includes(owner[i])) continue;
|
|
116
|
+
if (skip(t.at)) continue;
|
|
117
|
+
return { flag: spec.flag, agent: owner[i] && spec.agents.includes(owner[i]) ? owner[i] : spec.agents[0], index: t.at };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
package/engine/glob.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Glob and .gitignore matching for paths in a project. The patterns come from
|
|
2
|
+
// the files being checked, so they're matched by stepping through the path
|
|
3
|
+
// once, never by building a regular expression a crafted pattern could stall.
|
|
4
|
+
|
|
5
|
+
// Tokens: a literal character, "?" (one character in a name), "*" (any run in
|
|
6
|
+
// a name), "**" as a whole name (any run, across folders), "**/" (any number
|
|
7
|
+
// of whole folders) and character classes such as [abc] or [!0-9]. As in git,
|
|
8
|
+
// "**" next to other characters, as in a**b, is an ordinary "*".
|
|
9
|
+
function tokenize(glob) {
|
|
10
|
+
const tokens = [];
|
|
11
|
+
for (let i = 0; i < glob.length; i++) {
|
|
12
|
+
const c = glob[i];
|
|
13
|
+
if (c === "\\" && i + 1 < glob.length) {
|
|
14
|
+
tokens.push({ lit: glob[++i].toLowerCase() });
|
|
15
|
+
} else if (c === "*") {
|
|
16
|
+
let j = i;
|
|
17
|
+
while (glob[j + 1] === "*") j++;
|
|
18
|
+
const wholeName = j > i && (i === 0 || glob[i - 1] === "/");
|
|
19
|
+
if (wholeName && glob[j + 1] === "/") {
|
|
20
|
+
tokens.push({ folders: true });
|
|
21
|
+
j++;
|
|
22
|
+
} else if (wholeName && j + 1 === glob.length) tokens.push({ any: true });
|
|
23
|
+
else tokens.push({ star: true });
|
|
24
|
+
i = j;
|
|
25
|
+
} else if (c === "?") {
|
|
26
|
+
tokens.push({ one: true });
|
|
27
|
+
} else if (c === "[") {
|
|
28
|
+
const end = glob.indexOf("]", i + 2);
|
|
29
|
+
if (end < 0) {
|
|
30
|
+
tokens.push({ lit: c });
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
let body = glob.slice(i + 1, end).toLowerCase();
|
|
34
|
+
const negate = body[0] === "!" || body[0] === "^";
|
|
35
|
+
if (negate) body = body.slice(1);
|
|
36
|
+
tokens.push({ set: body, negate });
|
|
37
|
+
i = end;
|
|
38
|
+
} else {
|
|
39
|
+
tokens.push({ lit: c.toLowerCase() });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return tokens;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function inSet(token, c) {
|
|
46
|
+
const s = token.set;
|
|
47
|
+
let hit = false;
|
|
48
|
+
for (let i = 0; i < s.length && !hit; i++) {
|
|
49
|
+
if (s[i + 1] === "-" && i + 2 < s.length) {
|
|
50
|
+
hit = c >= s[i] && c <= s[i + 2];
|
|
51
|
+
i += 2;
|
|
52
|
+
} else hit = c === s[i];
|
|
53
|
+
}
|
|
54
|
+
return hit !== token.negate;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Whether `path` matches the whole glob, case-insensitively like git on
|
|
58
|
+
// Windows and macOS. Takes time proportional to path length × pattern length.
|
|
59
|
+
export function globMatch(glob, path) {
|
|
60
|
+
const tokens = typeof glob === "string" ? tokenize(glob) : glob;
|
|
61
|
+
const n = tokens.length;
|
|
62
|
+
// at[i]: matched up to token i. inside[i]: part way through the folders
|
|
63
|
+
// of a "**/" token.
|
|
64
|
+
let at = new Uint8Array(n + 1);
|
|
65
|
+
let inside = new Uint8Array(n + 1);
|
|
66
|
+
let nextAt = new Uint8Array(n + 1);
|
|
67
|
+
let nextInside = new Uint8Array(n + 1);
|
|
68
|
+
const reach = (set, i) => {
|
|
69
|
+
while (i <= n && !set[i]) {
|
|
70
|
+
set[i] = 1;
|
|
71
|
+
const t = tokens[i];
|
|
72
|
+
if (!t || !(t.star || t.any || t.folders)) break;
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
reach(at, 0);
|
|
77
|
+
for (const c of path.toLowerCase()) {
|
|
78
|
+
nextAt.fill(0);
|
|
79
|
+
nextInside.fill(0);
|
|
80
|
+
let alive = false;
|
|
81
|
+
for (let i = 0; i < n; i++) {
|
|
82
|
+
const t = tokens[i];
|
|
83
|
+
if (t.folders) {
|
|
84
|
+
if (!at[i] && !inside[i]) continue;
|
|
85
|
+
nextInside[i] = 1;
|
|
86
|
+
alive = true;
|
|
87
|
+
if (c === "/") reach(nextAt, i + 1);
|
|
88
|
+
} else if (!at[i]) {
|
|
89
|
+
continue;
|
|
90
|
+
} else if (t.star) {
|
|
91
|
+
if (c !== "/") reach(nextAt, i);
|
|
92
|
+
} else if (t.any) {
|
|
93
|
+
reach(nextAt, i);
|
|
94
|
+
} else if (t.one) {
|
|
95
|
+
if (c !== "/") reach(nextAt, i + 1);
|
|
96
|
+
} else if (t.set) {
|
|
97
|
+
if (c !== "/" && inSet(t, c)) reach(nextAt, i + 1);
|
|
98
|
+
} else if (t.lit === c) {
|
|
99
|
+
reach(nextAt, i + 1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
[at, nextAt] = [nextAt, at];
|
|
103
|
+
[inside, nextInside] = [nextInside, inside];
|
|
104
|
+
if (!alive && !at.includes(1)) return false;
|
|
105
|
+
}
|
|
106
|
+
return at[n] === 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// One line of an ignore file. `base` is the folder the file applies to,
|
|
110
|
+
// relative to the project, or "" for the whole project.
|
|
111
|
+
function compileRule(line, base) {
|
|
112
|
+
let p = line.replace(/\r$/, "");
|
|
113
|
+
if (!p || p.startsWith("#")) return null;
|
|
114
|
+
// Trailing spaces don't count unless escaped with a backslash.
|
|
115
|
+
let end = p.length;
|
|
116
|
+
while (end > 0 && p[end - 1] === " " && p[end - 2] !== "\\") end--;
|
|
117
|
+
p = p.slice(0, end);
|
|
118
|
+
if (!p) return null;
|
|
119
|
+
let negate = false;
|
|
120
|
+
if (p.startsWith("!")) {
|
|
121
|
+
negate = true;
|
|
122
|
+
p = p.slice(1);
|
|
123
|
+
} else if (p.startsWith("\\!") || p.startsWith("\\#")) {
|
|
124
|
+
p = p.slice(1);
|
|
125
|
+
}
|
|
126
|
+
let dirOnly = false;
|
|
127
|
+
if (p.endsWith("/")) {
|
|
128
|
+
dirOnly = true;
|
|
129
|
+
p = p.replace(/\/+$/, "");
|
|
130
|
+
}
|
|
131
|
+
if (!p) return null;
|
|
132
|
+
// A slash at the start or in the middle ties the pattern to the folder the
|
|
133
|
+
// file is in. Without one, it matches a name at any depth.
|
|
134
|
+
const anchored = p.includes("/");
|
|
135
|
+
p = p.replace(/^\/+/, "");
|
|
136
|
+
return { tokens: tokenize(anchored ? p : `**/${p}`), negate, dirOnly, base };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function ignoreRules(content, base = "") {
|
|
140
|
+
return String(content)
|
|
141
|
+
.split("\n")
|
|
142
|
+
.slice(0, 2000)
|
|
143
|
+
.map((line) => compileRule(line.slice(0, 300), base))
|
|
144
|
+
.filter(Boolean);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Pattern work allowed for one question, unless the caller shares a budget
|
|
148
|
+
// across many. Rules built to be slow are treated as ignoring everything
|
|
149
|
+
// rather than holding up the check.
|
|
150
|
+
const BUDGET = 4_000_000;
|
|
151
|
+
|
|
152
|
+
function decide(rules, path, isDir, budget) {
|
|
153
|
+
let ignored = false;
|
|
154
|
+
for (const r of rules) {
|
|
155
|
+
if (r.dirOnly && !isDir) continue;
|
|
156
|
+
let rel = path;
|
|
157
|
+
if (r.base) {
|
|
158
|
+
if (!path.startsWith(`${r.base}/`)) continue;
|
|
159
|
+
rel = path.slice(r.base.length + 1);
|
|
160
|
+
}
|
|
161
|
+
budget.left -= rel.length * (r.tokens.length + 1);
|
|
162
|
+
if (budget.left < 0) return true;
|
|
163
|
+
if (globMatch(r.tokens, rel)) ignored = !r.negate;
|
|
164
|
+
}
|
|
165
|
+
return ignored;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Whether git ignores a file, by git's rules. `rules` run from lowest
|
|
169
|
+
// precedence to highest, the last one that matches wins, "!" brings a file
|
|
170
|
+
// back, and a file inside an ignored folder stays ignored.
|
|
171
|
+
export function isIgnored(rules, path, budget = { left: BUDGET }) {
|
|
172
|
+
if (!rules.length) return false;
|
|
173
|
+
const parts = path.split("/");
|
|
174
|
+
for (let i = 1; i < parts.length; i++) {
|
|
175
|
+
if (decide(rules, parts.slice(0, i).join("/"), true, budget)) return true;
|
|
176
|
+
}
|
|
177
|
+
return decide(rules, path, false, budget);
|
|
178
|
+
}
|