@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/explain.js
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
// What each file that controls an agent actually tells it to do, in plain
|
|
2
|
-
// words. This runs on the user's computer
|
|
3
|
-
//
|
|
2
|
+
// words. This runs on the user's computer, and what it works out is shown
|
|
3
|
+
// only there: in --explain and the page --open saves.
|
|
4
4
|
|
|
5
5
|
import { describeMasks, maskSecrets } from "./mask.js";
|
|
6
|
+
import { findDangerFlag, trimWord, programName } from "./flags.js";
|
|
7
|
+
import { parseCodexRules, parseYAML } from "./parse.js";
|
|
6
8
|
|
|
7
9
|
const isObj = (x) => x !== null && typeof x === "object" && !Array.isArray(x);
|
|
8
10
|
const strs = (x) => (Array.isArray(x) ? x.filter((s) => typeof s === "string" && s.trim()) : []);
|
|
9
11
|
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
10
|
-
|
|
12
|
+
// Drops invisible tag characters, zero-width and direction marks, and control
|
|
13
|
+
// codes, so a summary shows only what can be seen.
|
|
14
|
+
const clean = (s) => describeMasks(String(s)).replace(/[\u{E0000}-\u{E007F}\u200b-\u200d\u2060\ufeff\u202a-\u202e\u2066-\u2069\u0000-\u0008\u000b-\u001f\u007f-\u009f]/gu, "");
|
|
15
|
+
// Shortens text at a word boundary, so a summary never ends mid-word.
|
|
11
16
|
const clip = (s, n = 90) => {
|
|
12
17
|
const t = clean(s).replace(/\s+/g, " ").trim();
|
|
13
|
-
|
|
18
|
+
if (t.length <= n) return t;
|
|
19
|
+
const cut = t.slice(0, n - 1);
|
|
20
|
+
const space = cut.lastIndexOf(" ");
|
|
21
|
+
return `${(space > n * 0.5 ? cut.slice(0, space) : cut).replace(/[\s,;:.(\-]+$/, "")}…`;
|
|
14
22
|
};
|
|
23
|
+
|
|
24
|
+
// Paths as people recognize them: the home folder as ~, forward slashes, and
|
|
25
|
+
// long paths shortened in the middle so the folder or file name stays visible.
|
|
26
|
+
const HOME_PREFIX = /^(?:[a-z]:\/users\/[^/]+|\/users\/[^/]+|\/home\/[^/]+|\/root)(?=\/|$)/i;
|
|
27
|
+
function shortPath(p, n = 60) {
|
|
28
|
+
// Doubled separators, as in a Windows path written C:\\Users\\..., count once.
|
|
29
|
+
const t = clean(p).trim().replace(/\\/g, "/").replace(/(?!^)\/{2,}/g, "/").replace(HOME_PREFIX, "~");
|
|
30
|
+
if (t.length <= n) return t;
|
|
31
|
+
const parts = t.split("/");
|
|
32
|
+
const last = parts.pop();
|
|
33
|
+
const short = `${parts.slice(0, 2).join("/")}/…/${last}`;
|
|
34
|
+
return short.length <= n ? short : `…/${last.length > n - 2 ? `${last.slice(0, n - 3)}…` : last}`;
|
|
35
|
+
}
|
|
36
|
+
const looksLikePath = (s) => /^(?:[a-z]:[\\/]|\/|~[\\/]|\.{1,2}[\\/])/i.test(String(s));
|
|
37
|
+
const commandText = (command, args, n = 80) =>
|
|
38
|
+
clip([command, ...args].filter(Boolean).map((part) => (looksLikePath(part) ? shortPath(part, 50) : part)).join(" "), n);
|
|
39
|
+
const period = (s) => (/[.!?…”"]$/.test(s) ? s : `${s}.`);
|
|
15
40
|
const list = (items, max = 4) => {
|
|
16
41
|
const shown = items.slice(0, max);
|
|
17
42
|
const rest = items.length - shown.length;
|
|
@@ -20,6 +45,129 @@ const list = (items, max = 4) => {
|
|
|
20
45
|
};
|
|
21
46
|
const sentence = (s) => (s ? s.replace(/^./, (c) => c.toUpperCase()).replace(/([^.!?…”"])$/, "$1.") : s);
|
|
22
47
|
|
|
48
|
+
// Unicode tag characters, which no font draws, as runs of { index, length,
|
|
49
|
+
// decoded }. The flags of England, Scotland and Wales are written with a few
|
|
50
|
+
// tag letters after a black flag emoji, so a run like that is a flag, not
|
|
51
|
+
// hidden text.
|
|
52
|
+
const FLAG_TAGS = /^[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,7}\u{E007F}$/u;
|
|
53
|
+
export function hiddenTags(text) {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (const m of text.matchAll(/[\u{E0000}-\u{E007F}]+/gu)) {
|
|
56
|
+
if (text.codePointAt(m.index - 2) === 0x1f3f4 && FLAG_TAGS.test(m[0])) continue;
|
|
57
|
+
const chars = [...m[0]];
|
|
58
|
+
const decoded = chars.map((ch) => String.fromCharCode(ch.codePointAt(0) - 0xe0000)).join("").replace(/[^\x20-\x7e]/g, "");
|
|
59
|
+
out.push({ index: m.index, length: chars.length, decoded });
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Where zero-width characters are in a text, leaving out the ones that are
|
|
65
|
+
// part of the writing: a byte order mark at the start of the text or of a
|
|
66
|
+
// line, the joiner inside an emoji sequence such as the technologist emoji,
|
|
67
|
+
// and the joiners and breaks that scripts such as Persian, Hindi and Thai
|
|
68
|
+
// use between letters. Two or more in a row always count, since nothing
|
|
69
|
+
// written needs that.
|
|
70
|
+
const PICTOGRAPH = /[\p{Extended_Pictographic}\p{Emoji_Modifier}\ufe0f]/u;
|
|
71
|
+
const LETTER = /[\p{L}\p{M}]/u;
|
|
72
|
+
const LATIN = /[\p{Script=Latin}\p{Script=Common}\p{Script=Inherited}]/u;
|
|
73
|
+
const otherScript = (ch) => LETTER.test(ch) && !LATIN.test(ch);
|
|
74
|
+
const charBefore = (text, i) => (i > 0 ? String.fromCodePoint(text.codePointAt(i >= 2 && /[\udc00-\udfff]/.test(text[i - 1]) ? i - 2 : i - 1)) : "");
|
|
75
|
+
const charAfter = (text, i) => (i < text.length ? String.fromCodePoint(text.codePointAt(i)) : "");
|
|
76
|
+
export function hiddenZeroWidth(text) {
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const m of text.matchAll(/[\u0000\u200b-\u200d\u2060\u180e\ufeff]+/g)) {
|
|
79
|
+
let { index } = m;
|
|
80
|
+
let run = m[0];
|
|
81
|
+
if (run[0] === "\ufeff" && (index === 0 || text[index - 1] === "\n")) {
|
|
82
|
+
index++;
|
|
83
|
+
run = run.slice(1);
|
|
84
|
+
if (!run) continue;
|
|
85
|
+
}
|
|
86
|
+
if (run.length === 1) {
|
|
87
|
+
const before = charBefore(text, index);
|
|
88
|
+
const after = charAfter(text, index + 1);
|
|
89
|
+
if (run === "\u200d" && PICTOGRAPH.test(before) && PICTOGRAPH.test(after)) continue;
|
|
90
|
+
if ("\u200b\u200c\u200d\u180e".includes(run) && (otherScript(before) || otherScript(after))) continue;
|
|
91
|
+
}
|
|
92
|
+
for (let i = 0; i < run.length; i++) out.push(index + i);
|
|
93
|
+
if (out.length >= 100_000) break;
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// HTML comments as { index, inner }, found with indexOf: a file full of
|
|
99
|
+
// unclosed "<!--" can't slow anything down.
|
|
100
|
+
export function htmlComments(text, max = 200) {
|
|
101
|
+
const out = [];
|
|
102
|
+
for (let from = 0; out.length < max; ) {
|
|
103
|
+
const start = text.indexOf("<!--", from);
|
|
104
|
+
if (start < 0) break;
|
|
105
|
+
const end = text.indexOf("-->", start + 4);
|
|
106
|
+
if (end < 0) break;
|
|
107
|
+
out.push({ index: start, inner: text.slice(start + 4, end) });
|
|
108
|
+
from = end + 3;
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Fenced code blocks as [start, end) offsets. A file of thousands of fences
|
|
114
|
+
// is still read in one pass.
|
|
115
|
+
export function fencedRanges(text) {
|
|
116
|
+
const ranges = [];
|
|
117
|
+
let open = -1;
|
|
118
|
+
let marker = "";
|
|
119
|
+
for (let start = 0; start < text.length; ) {
|
|
120
|
+
const nl = text.indexOf("\n", start);
|
|
121
|
+
const end = nl < 0 ? text.length : nl;
|
|
122
|
+
const m = /^ {0,3}(`{3,}|~{3,})/.exec(text.slice(start, Math.min(end, start + 16)));
|
|
123
|
+
if (m && open < 0) {
|
|
124
|
+
open = start;
|
|
125
|
+
marker = m[1][0];
|
|
126
|
+
} else if (m && m[1][0] === marker) {
|
|
127
|
+
ranges.push([open, end]);
|
|
128
|
+
open = -1;
|
|
129
|
+
}
|
|
130
|
+
start = end + 1;
|
|
131
|
+
}
|
|
132
|
+
if (open >= 0) ranges.push([open, text.length]);
|
|
133
|
+
return ranges;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// A function that finds the code block an offset is in, if any, by binary
|
|
137
|
+
// search, so many lookups in a file of many blocks stay fast.
|
|
138
|
+
export function fenceAt(text) {
|
|
139
|
+
const fences = fencedRanges(text);
|
|
140
|
+
return (i) => {
|
|
141
|
+
let lo = 0;
|
|
142
|
+
let hi = fences.length - 1;
|
|
143
|
+
while (lo <= hi) {
|
|
144
|
+
const mid = (lo + hi) >> 1;
|
|
145
|
+
if (i < fences[mid][0]) hi = mid - 1;
|
|
146
|
+
else if (i >= fences[mid][1]) lo = mid + 1;
|
|
147
|
+
else return fences[mid];
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// HTML comments that are hidden when the Markdown is displayed. Inside a
|
|
154
|
+
// code block or a `code span` a comment shows as written, so it isn't.
|
|
155
|
+
export function hiddenComments(text, max = 200) {
|
|
156
|
+
const fence = fenceAt(text);
|
|
157
|
+
const inFence = (i) => fence(i) !== null;
|
|
158
|
+
return htmlComments(text, max * 5).filter((c) => !inFence(c.index) && !inCodeSpan(text, c.index)).slice(0, max);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const withoutComments = (line) => {
|
|
162
|
+
let out = "";
|
|
163
|
+
let from = 0;
|
|
164
|
+
for (const c of hiddenComments(line)) {
|
|
165
|
+
out += line.slice(from, c.index);
|
|
166
|
+
from = c.index + c.inner.length + 7;
|
|
167
|
+
}
|
|
168
|
+
return out + line.slice(from);
|
|
169
|
+
};
|
|
170
|
+
|
|
23
171
|
// Where a file's settings apply.
|
|
24
172
|
export function scopeOf(file) {
|
|
25
173
|
const p = file.path;
|
|
@@ -37,19 +185,40 @@ export const SCOPES = {
|
|
|
37
185
|
};
|
|
38
186
|
|
|
39
187
|
// { scope, summary, details } for one file. `json` is the parsed settings
|
|
40
|
-
// file (or null); `servers` are its MCP servers, already
|
|
188
|
+
// file (or null); `servers` are its MCP servers, already normalized.
|
|
41
189
|
export function explainFile(file, { json = null, servers = [] } = {}) {
|
|
42
190
|
const scope = scopeOf(file);
|
|
191
|
+
if (file.listed && file.kind === "Plugin code") return { scope, summary: `Code ${file.tools?.[0] ?? "the agent"} loads when it starts. misconfig lists it by name and doesn't open it.`, details: [] };
|
|
43
192
|
if (!file.content) return { scope, summary: file.tooLarge ? "Too large to read." : "Not read.", details: [] };
|
|
44
193
|
const p = file.path;
|
|
45
194
|
let out;
|
|
46
|
-
if (/(^|\/)(\.claude\/settings(\.local)
|
|
195
|
+
if (/(^|\/)(\.claude\/settings(\.local)?\.json|managed-settings(\.d\/[^/]+)?\.json)$/i.test(p)) out = claudeSettings(json, scope === "project");
|
|
196
|
+
else if (/(^|\/)\.claude\/plugins\/installed_plugins\.json$/i.test(p)) out = claudePlugins(json);
|
|
197
|
+
else if (/(^|\/)\.claude\/plugins\/known_marketplaces\.json$/i.test(p)) out = claudeMarketplaces(json);
|
|
198
|
+
else if (/(^|\/)\.claude\/plugins\/.+\/hooks\/hooks\.json$/i.test(p)) out = { parts: [], details: claudeHooks(json?.hooks) };
|
|
47
199
|
else if (/(^|\/)\.claude\.json$/i.test(p)) out = claudeUserConfig(json);
|
|
48
|
-
else if (/(^|\/)\.codex\/config\.toml$/i.test(p)) out = codexConfig(json);
|
|
49
|
-
else if (/(^|\/)
|
|
200
|
+
else if (/(^|\/)\.codex\/([^/]+\.)?config\.toml$/i.test(p)) out = codexConfig(json);
|
|
201
|
+
else if (/(^|\/)codex\/requirements\.toml$/i.test(p)) out = codexRequirements(json);
|
|
202
|
+
else if (/(^|\/)(\.gemini|gemini-cli|GeminiCli)\/(system-)?settings\.json$/i.test(p)) out = geminiSettings(json);
|
|
203
|
+
else if (/(^|\/)\.gemini\/trustedFolders\.json$/i.test(p)) out = trustedFolders(geminiTrusted(json));
|
|
204
|
+
else if (/(^|\/)\.copilot\/config\.json$/i.test(p)) out = trustedFolders(strs(json?.trusted_folders ?? json?.trustedFolders));
|
|
205
|
+
else if (/(^|\/)(\.github\/hooks\/[^/]+|\.cursor\/hooks|\.codex\/hooks|\.windsurf\/hooks|\.codeium\/windsurf\/hooks|\.devin\/hooks\.v1|\.grok\/hooks\/[^/]+)\.json$/i.test(p)) out = jsonHooks(json);
|
|
206
|
+
else if (/(^|\/)\.kiro\/hooks\/[^/]+\.(json|kiro\.hook)$/i.test(p)) out = jsonHooks(json);
|
|
207
|
+
else if (/(^|\/)(\.kiro\/agents|\.amazonq\/cli-agents|\.aws\/amazonq\/cli-agents)\/[^/]+\.json$/i.test(p)) out = agentConfig(json);
|
|
208
|
+
else if (/(^|\/)\.cursor\/environment\.json$/i.test(p)) out = cursorEnvironment(json);
|
|
209
|
+
else if (/(^|\/)\.vscode\/tasks\.json$/i.test(p)) out = vsCodeTasks(json);
|
|
210
|
+
else if (/(^|\/)\.gemini\/commands\/.+\.toml$/i.test(p)) out = geminiCommand(p, json);
|
|
211
|
+
else if (/(^|\/)\.codex\/rules\/[^/]+\.rules$/i.test(p)) out = codexRules(file);
|
|
212
|
+
else if (/(^|\/)\.cursor\/(cli-config|cli)\.json$/i.test(p)) out = cursorCli(json);
|
|
213
|
+
else if (/(^|\/)\.cursor\/sandbox\.json$/i.test(p)) out = cursorSandbox(json);
|
|
50
214
|
else if (/(^|\/)(\.vscode|(Code|Code - Insiders|VSCodium|Cursor|Windsurf)\/User)\/settings\.json$/i.test(p)) out = editorSettings(json);
|
|
51
215
|
else if (/(^|\/)opencode\.jsonc?$/i.test(p)) out = openCode(json);
|
|
52
216
|
else if (/(^|\/)(\.zed|zed|Zed)\/settings\.json$/i.test(p)) out = zedSettings(json);
|
|
217
|
+
else if (/(^|\/)\.cline\/data\/globalState\.json$/i.test(p)) out = clineState(json);
|
|
218
|
+
else if (/(^|\/)\.grok\/config\.toml$/i.test(p)) out = grokConfig(json);
|
|
219
|
+
else if (/(^|\/)(\.amp|\.config\/amp)\/settings\.json$/i.test(p)) out = ampSettings(json);
|
|
220
|
+
else if (/(^|\/)goose\/config\.ya?ml$/i.test(p)) out = gooseConfig(file);
|
|
221
|
+
else if (/(^|\/)\.continue\/config\.ya?ml$/i.test(p)) out = continueConfig(file);
|
|
53
222
|
else if (/(^|\/)\.aider\.conf\.ya?ml$/i.test(p)) out = aiderConfig(file);
|
|
54
223
|
else if (file.kind === "Shell profile") out = shellProfile(file);
|
|
55
224
|
else if (file.kind === "Hook script") out = hookScript(file);
|
|
@@ -76,44 +245,120 @@ function serverText(s) {
|
|
|
76
245
|
host = clip(s.url, 40);
|
|
77
246
|
}
|
|
78
247
|
what = `connects to ${host}`;
|
|
79
|
-
} else what = `runs ${
|
|
248
|
+
} else what = `runs ${commandText(s.command, s.args)}`;
|
|
80
249
|
const auto = s.alwaysAllow === true ? "; its tools run without asking" : strs(s.alwaysAllow).length ? `; runs ${list(strs(s.alwaysAllow), 3)} without asking` : "";
|
|
81
|
-
const
|
|
82
|
-
|
|
250
|
+
const keys = Object.keys(s.env ?? {});
|
|
251
|
+
const env = keys.length > 3 ? `; sets ${keys.length} environment variables` : keys.length ? `; sets ${list(keys, 3)}` : "";
|
|
252
|
+
return period(`MCP server “${s.name}”${s.disabled ? " (turned off)" : ""}: ${what}${auto}${env}`);
|
|
83
253
|
}
|
|
84
254
|
|
|
85
|
-
// --- Claude Code
|
|
255
|
+
// --- Claude Code -------------------------------------------------------------
|
|
86
256
|
|
|
87
257
|
const CLAUDE_MODES = {
|
|
88
|
-
default: ["Asks before acting", "Asks
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
258
|
+
default: ["Asks before acting", "Asks the first time each tool is used."],
|
|
259
|
+
manual: ["Asks before acting", "Asks the first time each tool is used."],
|
|
260
|
+
acceptEdits: ["Edits files without asking", "Accepts file edits and common file commands in the project without asking, and asks before other commands."],
|
|
261
|
+
plan: ["Plan mode", "Starts in plan mode: it reads and explores but changes nothing until you approve a plan."],
|
|
262
|
+
auto: ["Auto mode", "Auto mode: runs without routine prompts while a classifier checks that each action matches what you asked for."],
|
|
263
|
+
dontAsk: ["Refuses anything not allowed", "Never prompts: anything that isn't already allowed is refused."],
|
|
264
|
+
bypassPermissions: ["Never asks", "Skips permission prompts for everything except a few protected actions."],
|
|
93
265
|
};
|
|
94
266
|
|
|
95
|
-
|
|
267
|
+
// Claude Code hook events, in plain words.
|
|
268
|
+
export const HOOK_EVENTS = {
|
|
269
|
+
SessionStart: "When a session starts",
|
|
270
|
+
Setup: "During setup",
|
|
271
|
+
UserPromptSubmit: "When you send a prompt",
|
|
272
|
+
UserPromptExpansion: "When a prompt is expanded",
|
|
96
273
|
PreToolUse: "Before each tool runs",
|
|
274
|
+
PermissionRequest: "When Claude asks for permission",
|
|
275
|
+
PermissionDenied: "When a permission is denied",
|
|
97
276
|
PostToolUse: "After each tool runs",
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
SessionEnd: "When a session ends",
|
|
101
|
-
Stop: "When Claude finishes a reply",
|
|
102
|
-
SubagentStop: "When a subagent finishes",
|
|
277
|
+
PostToolUseFailure: "After a tool fails",
|
|
278
|
+
PostToolBatch: "After a batch of tools runs",
|
|
103
279
|
Notification: "When Claude sends a notification",
|
|
280
|
+
MessageDisplay: "When a message is shown",
|
|
281
|
+
SubagentStart: "When a subagent starts",
|
|
282
|
+
SubagentStop: "When a subagent finishes",
|
|
283
|
+
TaskCreated: "When a task is created",
|
|
284
|
+
TaskCompleted: "When a task is completed",
|
|
285
|
+
Stop: "When Claude finishes a reply",
|
|
286
|
+
StopFailure: "When a reply ends with an error",
|
|
287
|
+
TeammateIdle: "When a teammate goes idle",
|
|
288
|
+
InstructionsLoaded: "When instruction files are loaded",
|
|
289
|
+
ConfigChange: "When settings change",
|
|
290
|
+
CwdChanged: "When the working folder changes",
|
|
291
|
+
DirectoryAdded: "When a folder is added",
|
|
292
|
+
FileChanged: "When a file changes",
|
|
293
|
+
WorktreeCreate: "When a worktree is created",
|
|
294
|
+
WorktreeRemove: "When a worktree is removed",
|
|
104
295
|
PreCompact: "Before the conversation is compacted",
|
|
296
|
+
PostCompact: "After the conversation is compacted",
|
|
297
|
+
PreModelSwitch: "Before the model changes",
|
|
298
|
+
PostModelSwitch: "After the model changes",
|
|
299
|
+
Elicitation: "When an MCP server asks for input",
|
|
300
|
+
ElicitationResult: "When you answer an MCP server",
|
|
301
|
+
SessionEnd: "When a session ends",
|
|
105
302
|
};
|
|
106
303
|
|
|
107
|
-
|
|
304
|
+
// Settings that make Claude Code run a command, and what each command is for.
|
|
305
|
+
const CLAUDE_COMMANDS = {
|
|
306
|
+
apiKeyHelper: "to get its API key",
|
|
307
|
+
awsAuthRefresh: "to refresh AWS credentials",
|
|
308
|
+
awsCredentialExport: "to get AWS credentials",
|
|
309
|
+
gcpAuthRefresh: "to refresh Google Cloud credentials",
|
|
310
|
+
otelHeadersHelper: "to get telemetry headers",
|
|
311
|
+
statusLine: "to draw the status line",
|
|
312
|
+
subagentStatusLine: "to draw subagent status",
|
|
313
|
+
fileSuggestion: "to suggest files",
|
|
314
|
+
processWrapper: "to start its background processes",
|
|
315
|
+
policyHelper: "to work out managed settings",
|
|
316
|
+
sshHostCommands: "to find SSH hosts",
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const commandsOf = (value, depth = 0) =>
|
|
320
|
+
typeof value === "string"
|
|
321
|
+
? [value]
|
|
322
|
+
: Array.isArray(value) && depth < 4
|
|
323
|
+
? value.flatMap((v) => commandsOf(v, depth + 1))
|
|
324
|
+
: isObj(value)
|
|
325
|
+
? [value.command, value.path].filter((c) => typeof c === "string")
|
|
326
|
+
: [];
|
|
327
|
+
|
|
328
|
+
function hookText(event, matcher, h) {
|
|
329
|
+
const when = `${HOOK_EVENTS[event] ?? event}${matcher}`;
|
|
330
|
+
if (typeof h?.command === "string") return `${when}: runs ${clip(h.command, 80)}.`;
|
|
331
|
+
if (h?.type === "http" && typeof h.url === "string") {
|
|
332
|
+
let host = h.url;
|
|
333
|
+
try {
|
|
334
|
+
host = new URL(h.url).host;
|
|
335
|
+
} catch {}
|
|
336
|
+
return `${when}: sends the event to ${clip(host, 50)}.`;
|
|
337
|
+
}
|
|
338
|
+
if (h?.type === "mcp_tool") return `${when}: calls an MCP tool${typeof h.server === "string" ? ` on “${clip(h.server, 30)}”` : ""}.`;
|
|
339
|
+
if (h?.type === "prompt") return `${when}: asks a model to check it.`;
|
|
340
|
+
if (h?.type === "agent") return `${when}: starts a subagent to check it.`;
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// `shared` is a project's own settings file, where Claude Code ignores the
|
|
345
|
+
// auto and bypassPermissions modes.
|
|
346
|
+
function claudeSettings(json, shared) {
|
|
108
347
|
const parts = [];
|
|
109
348
|
const details = [];
|
|
110
349
|
if (!isObj(json)) return { parts, details, summary: "Couldn't read the settings in this file." };
|
|
111
350
|
const p = isObj(json.permissions) ? json.permissions : {};
|
|
112
351
|
const mode = CLAUDE_MODES[p.defaultMode];
|
|
113
|
-
if (mode) {
|
|
352
|
+
if (mode && shared && (p.defaultMode === "auto" || p.defaultMode === "bypassPermissions")) {
|
|
353
|
+
parts.push(`asks for ${p.defaultMode} mode`);
|
|
354
|
+
details.push(`Asks for ${p.defaultMode} mode. Claude Code ignores that in a project's own settings and starts in the default mode, but versions before 2.1.257 honor bypassPermissions.`);
|
|
355
|
+
} else if (mode) {
|
|
114
356
|
parts.push(mode[0]);
|
|
115
357
|
details.push(mode[1]);
|
|
116
|
-
} else if (typeof p.defaultMode === "string")
|
|
358
|
+
} else if (typeof p.defaultMode === "string") {
|
|
359
|
+
parts.push(`permission mode: ${clip(p.defaultMode, 30)}`);
|
|
360
|
+
details.push(`Permission mode: ${clip(p.defaultMode, 30)}.`);
|
|
361
|
+
}
|
|
117
362
|
const allow = strs(p.allow);
|
|
118
363
|
const ask = strs(p.ask);
|
|
119
364
|
const deny = strs(p.deny);
|
|
@@ -129,20 +374,10 @@ function claudeSettings(json) {
|
|
|
129
374
|
const dirs = strs(p.additionalDirectories);
|
|
130
375
|
if (dirs.length) details.push(`Can also work in: ${list(dirs.map((d) => clip(d, 60)), 4)}.`);
|
|
131
376
|
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const matcher = typeof entry?.matcher === "string" && entry.matcher && entry.matcher !== "*" ? ` (${clip(entry.matcher, 30)})` : "";
|
|
137
|
-
for (const h of Array.isArray(entry?.hooks) ? entry.hooks : [entry]) {
|
|
138
|
-
if (typeof h?.command !== "string") continue;
|
|
139
|
-
hookCount++;
|
|
140
|
-
details.push(`${HOOK_EVENTS[event] ?? event}${matcher}: runs ${clip(h.command, 80)}.`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (hookCount) parts.push(hookCount === 1 ? "runs a command on a hook" : `runs ${hookCount} commands on hooks`);
|
|
377
|
+
const hooks = claudeHooks(json.hooks);
|
|
378
|
+
if (hooks.length) parts.push(hooks.length === 1 ? "has a hook" : `has ${hooks.length} hooks`);
|
|
379
|
+
details.push(...hooks);
|
|
380
|
+
if (json.disableAllHooks === true) details.push("Turns off all hooks.");
|
|
146
381
|
if (isObj(json.env) && Object.keys(json.env).length) {
|
|
147
382
|
const keys = Object.keys(json.env);
|
|
148
383
|
parts.push(`sets ${plural(keys.length, "environment variable")}`);
|
|
@@ -158,12 +393,38 @@ function claudeSettings(json) {
|
|
|
158
393
|
}
|
|
159
394
|
const enabled = strs(json.enabledMcpjsonServers);
|
|
160
395
|
if (enabled.length) details.push(`Turns on these project MCP servers: ${list(enabled, 5)}.`);
|
|
161
|
-
|
|
162
|
-
|
|
396
|
+
for (const [key, purpose] of Object.entries(CLAUDE_COMMANDS)) {
|
|
397
|
+
for (const command of commandsOf(json[key])) details.push(`Runs ${clip(command, 60)} ${purpose}.`);
|
|
398
|
+
}
|
|
399
|
+
if (isObj(json.sandbox) && typeof json.sandbox.enabled === "boolean") details.push(json.sandbox.enabled ? "Runs commands in a sandbox." : "Turns the command sandbox off.");
|
|
400
|
+
const plugins = isObj(json.enabledPlugins) ? Object.keys(json.enabledPlugins).filter((k) => json.enabledPlugins[k]) : [];
|
|
401
|
+
if (plugins.length) {
|
|
402
|
+
parts.push(`turns on ${plural(plugins.length, "plugin")}`);
|
|
403
|
+
details.push(`Turns on ${plural(plugins.length, "plugin")}: ${list(plugins.map((k) => clip(k, 40)), 5)}.`);
|
|
404
|
+
}
|
|
405
|
+
if (isObj(json.extraKnownMarketplaces) && Object.keys(json.extraKnownMarketplaces).length) {
|
|
406
|
+
details.push(`Adds plugin marketplaces: ${list(Object.keys(json.extraKnownMarketplaces).map((k) => clip(k, 40)), 4)}.`);
|
|
407
|
+
}
|
|
163
408
|
if (typeof json.outputStyle === "string") details.push(`Uses the “${json.outputStyle}” output style.`);
|
|
164
409
|
return { parts, details };
|
|
165
410
|
}
|
|
166
411
|
|
|
412
|
+
// One line per hook, in the order they appear.
|
|
413
|
+
function claudeHooks(hooks) {
|
|
414
|
+
const out = [];
|
|
415
|
+
if (!isObj(hooks)) return out;
|
|
416
|
+
for (const [event, entries] of Object.entries(hooks)) {
|
|
417
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
418
|
+
const matcher = typeof entry?.matcher === "string" && entry.matcher && entry.matcher !== "*" ? ` (${clip(entry.matcher, 30)})` : "";
|
|
419
|
+
for (const h of Array.isArray(entry?.hooks) ? entry.hooks : [entry]) {
|
|
420
|
+
const text = hookText(event, matcher, h);
|
|
421
|
+
if (text) out.push(text);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return out;
|
|
426
|
+
}
|
|
427
|
+
|
|
167
428
|
// ~/.claude.json, already reduced to MCP servers and the folders Claude Code
|
|
168
429
|
// has been started in. MCP servers are added by the caller.
|
|
169
430
|
function claudeUserConfig(json) {
|
|
@@ -181,7 +442,7 @@ function claudeUserConfig(json) {
|
|
|
181
442
|
return { parts, details };
|
|
182
443
|
}
|
|
183
444
|
|
|
184
|
-
// --- Codex
|
|
445
|
+
// --- Codex -------------------------------------------------------------------
|
|
185
446
|
|
|
186
447
|
const CODEX_SANDBOX = {
|
|
187
448
|
"read-only": ["Read-only sandbox", "Sandbox: can read files but not change them."],
|
|
@@ -189,8 +450,8 @@ const CODEX_SANDBOX = {
|
|
|
189
450
|
"danger-full-access": ["No sandbox", "No sandbox: commands can change any file and use the network."],
|
|
190
451
|
};
|
|
191
452
|
const CODEX_APPROVAL = {
|
|
192
|
-
untrusted: ["asks before most commands", "Asks before running anything outside a short list of safe commands."],
|
|
193
|
-
"on-failure": ["asks only when a command fails", "Runs commands in the sandbox and asks only when one fails."],
|
|
453
|
+
untrusted: ["asks before most commands", "Asks before running anything outside a short list of safe commands. Newer versions of Codex don't accept this value."],
|
|
454
|
+
"on-failure": ["asks only when a command fails", "Runs commands in the sandbox and asks only when one fails. Codex has deprecated this value."],
|
|
194
455
|
"on-request": ["asks when it decides to", "Asks only when it decides a command needs your approval."],
|
|
195
456
|
never: ["never asks", "Never asks for approval."],
|
|
196
457
|
};
|
|
@@ -209,32 +470,71 @@ function codexConfig(toml) {
|
|
|
209
470
|
parts.push(approval[0]);
|
|
210
471
|
details.push(approval[1]);
|
|
211
472
|
}
|
|
473
|
+
if (isObj(toml.approval_policy)) {
|
|
474
|
+
parts.push("approvals set per kind of action");
|
|
475
|
+
details.push(`Approvals are set per kind of action: ${list(Object.keys(toml.approval_policy), 5)}.`);
|
|
476
|
+
}
|
|
477
|
+
if (typeof toml.approvals_reviewer === "string") details.push(`Approval requests are reviewed by: ${clip(toml.approvals_reviewer, 30)}.`);
|
|
212
478
|
if (toml.sandbox_workspace_write?.network_access === true) details.push("Lets sandboxed commands use the network.");
|
|
213
479
|
if (typeof toml.model === "string") details.push(`Uses the ${toml.model} model.`);
|
|
214
480
|
if (isObj(toml.projects)) {
|
|
215
|
-
const trusted = Object.entries(toml.projects).filter(([, s]) => s?.trust_level === "trusted").map(([d]) => d);
|
|
481
|
+
const trusted = Object.entries(toml.projects).filter(([, s]) => s?.trust_level === "trusted").map(([d]) => shortPath(d, 50));
|
|
482
|
+
const risky = (d) => d === "~" || /^~\/(downloads|desktop)$/i.test(d) || /^[a-z]:\/?$/i.test(d) || d === "/";
|
|
483
|
+
const home = trusted.includes("~");
|
|
216
484
|
if (trusted.length) {
|
|
217
|
-
parts.push(`trusts ${plural(trusted.length, "folder")}`);
|
|
218
|
-
|
|
485
|
+
parts.push(`trusts ${plural(trusted.length, "folder")}${home ? ", including your home folder" : ""}`);
|
|
486
|
+
const ordered = [...trusted.filter(risky), ...trusted.filter((d) => !risky(d))].map((d) => (d === "~" ? "~ (your home folder)" : d));
|
|
487
|
+
details.push(`Trusts ${list(ordered, 4)}.`);
|
|
219
488
|
}
|
|
220
489
|
}
|
|
221
490
|
if (isObj(toml.profiles) && Object.keys(toml.profiles).length) details.push(`Has ${plural(Object.keys(toml.profiles).length, "profile")}: ${list(Object.keys(toml.profiles), 4)}.`);
|
|
222
491
|
const notify = strs(toml.notify);
|
|
223
|
-
if (notify.length) details.push(`Runs ${
|
|
492
|
+
if (notify.length) details.push(`Runs ${commandText(notify[0], notify.slice(1), 60)} to send notifications.`);
|
|
493
|
+
const hooks = hookLines(toml.hooks);
|
|
494
|
+
parts.push(...hookParts(hooks));
|
|
495
|
+
details.push(...hooks);
|
|
496
|
+
namedFiles(parts, details, toml.project_doc_fallback_filenames);
|
|
497
|
+
let helpers = 0;
|
|
498
|
+
for (const [name, provider] of Object.entries(isObj(toml.model_providers) ? toml.model_providers : {}).slice(0, 10)) {
|
|
499
|
+
if (typeof provider?.auth?.command !== "string") continue;
|
|
500
|
+
helpers++;
|
|
501
|
+
details.push(`Runs ${commandText(provider.auth.command, strs(provider.auth.args), 60)} to get a key for the “${clip(name, 30)}” model provider.`);
|
|
502
|
+
}
|
|
503
|
+
for (const [name, server] of Object.entries(isObj(toml.mcp_servers) ? toml.mcp_servers : {}).slice(0, 20)) {
|
|
504
|
+
const helper = server?.http_headers_helper;
|
|
505
|
+
if (typeof helper !== "string" && !strs(helper).length) continue;
|
|
506
|
+
helpers++;
|
|
507
|
+
details.push(`Runs ${clip(Array.isArray(helper) ? strs(helper).join(" ") : helper, 60)} to make the request headers for MCP server “${clip(name, 30)}”.`);
|
|
508
|
+
}
|
|
509
|
+
if (helpers) parts.push(`runs ${plural(helpers, "command")} for keys or headers`);
|
|
510
|
+
const set = isObj(toml.shell_environment_policy?.set) ? Object.keys(toml.shell_environment_policy.set) : [];
|
|
511
|
+
if (set.length) {
|
|
512
|
+
parts.push(`sets ${plural(set.length, "environment variable")}`);
|
|
513
|
+
details.push(`Sets ${plural(set.length, "environment variable")} for the commands it runs: ${list(set.map((k) => clip(k, 30)), 5)}.`);
|
|
514
|
+
}
|
|
224
515
|
return { parts, details };
|
|
225
516
|
}
|
|
226
517
|
|
|
227
|
-
// --- Gemini, editors, OpenCode, Zed, Aider
|
|
518
|
+
// --- Gemini, editors, OpenCode, Zed, Aider -----------------------------------
|
|
228
519
|
|
|
229
520
|
function geminiSettings(json) {
|
|
230
521
|
const parts = [];
|
|
231
522
|
const details = [];
|
|
232
523
|
if (!isObj(json)) return { parts, details };
|
|
233
|
-
const mode = json.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
524
|
+
const mode = [json.general?.defaultApprovalMode, json.defaultApprovalMode, json.approvalMode, json.general?.approvalMode, json.tools?.approvalMode].find((v) => typeof v === "string") ?? "";
|
|
525
|
+
// Gemini CLI turns YOLO mode on only from the command line, so a setting
|
|
526
|
+
// that asks for it changes nothing.
|
|
527
|
+
if (json.yolo === true || /^yolo$/i.test(mode)) {
|
|
528
|
+
parts.push("Asks for YOLO mode, which Gemini CLI ignores in settings");
|
|
529
|
+
details.push("Asks for YOLO mode. Current Gemini CLI turns YOLO on only with --yolo or --approval-mode=yolo, so this setting changes nothing.");
|
|
530
|
+
} else if (/^auto_edit$/i.test(mode)) {
|
|
531
|
+
parts.push("Edits files without asking");
|
|
532
|
+
details.push("Approval mode auto_edit: edits files without asking, and asks before other tools.");
|
|
533
|
+
} else if (/^plan$/i.test(mode)) {
|
|
534
|
+
parts.push("Plan mode");
|
|
535
|
+
details.push("Starts in plan mode: it reads and explores but changes nothing.");
|
|
536
|
+
}
|
|
537
|
+
if (json.autoAccept === true || json.tools?.autoAccept === true) {
|
|
238
538
|
parts.push("Accepts some tool calls without asking");
|
|
239
539
|
details.push("Accepts tool calls it considers safe without asking.");
|
|
240
540
|
}
|
|
@@ -244,6 +544,17 @@ function geminiSettings(json) {
|
|
|
244
544
|
if (allowed.length) details.push(`Tools it may use: ${list(allowed, 6)}.`);
|
|
245
545
|
const excluded = strs(json.excludeTools ?? json.tools?.exclude);
|
|
246
546
|
if (excluded.length) details.push(`Tools it may not use: ${list(excluded, 6)}.`);
|
|
547
|
+
namedFiles(parts, details, json.context?.fileName ?? json.contextFileName, ["GEMINI.md"]);
|
|
548
|
+
const discover = [json.tools?.discoveryCommand, json.toolDiscoveryCommand].find((c) => typeof c === "string" && c.trim());
|
|
549
|
+
if (discover) {
|
|
550
|
+
parts.push("runs its own command to find tools");
|
|
551
|
+
details.push(`Runs ${clip(discover, 60)} to find more tools.`);
|
|
552
|
+
}
|
|
553
|
+
const call = [json.tools?.callCommand, json.toolCallCommand].find((c) => typeof c === "string" && c.trim());
|
|
554
|
+
if (call) details.push(`Runs ${clip(call, 60)} to use them.`);
|
|
555
|
+
const hooks = hookLines(json.hooks);
|
|
556
|
+
parts.push(...hookParts(hooks));
|
|
557
|
+
details.push(...hooks);
|
|
247
558
|
return { parts, details };
|
|
248
559
|
}
|
|
249
560
|
|
|
@@ -251,10 +562,20 @@ function editorSettings(json) {
|
|
|
251
562
|
const parts = [];
|
|
252
563
|
const details = [];
|
|
253
564
|
if (!isObj(json)) return { parts, details };
|
|
254
|
-
if (json["chat.tools.autoApprove"] === true || json["chat.tools.global.autoApprove"] === true) {
|
|
565
|
+
if (json["chat.tools.autoApprove"] === true || json["chat.tools.global.autoApprove"] === true || json["chat.permissions.default"] === "autoApprove") {
|
|
255
566
|
parts.push("Runs agent tools without asking");
|
|
256
567
|
details.push("Agent mode runs tools and terminal commands without asking.");
|
|
257
568
|
}
|
|
569
|
+
if (json["github.copilot.chat.claudeAgent.allowDangerouslySkipPermissions"] === true) {
|
|
570
|
+
parts.push("lets the Claude agent skip every permission prompt");
|
|
571
|
+
details.push("The Claude agent in Copilot Chat can skip every permission prompt.");
|
|
572
|
+
}
|
|
573
|
+
if (json["chat.tools.terminal.ignoreDefaultAutoApproveRules"] === true) details.push("Ignores VS Code's built-in rules for terminal commands.");
|
|
574
|
+
const edits = json["chat.tools.edits.autoApprove"];
|
|
575
|
+
if (isObj(edits)) {
|
|
576
|
+
const on = Object.keys(edits).filter((k) => edits[k] === true);
|
|
577
|
+
if (on.length) details.push(`Edits that don't need approval: ${list(on.map((k) => clip(k, 40)), 5)}.`);
|
|
578
|
+
}
|
|
258
579
|
const terminal = json["chat.tools.terminal.autoApprove"] ?? json["github.copilot.chat.agent.terminal.allowList"];
|
|
259
580
|
if (isObj(terminal)) {
|
|
260
581
|
const on = Object.entries(terminal).filter(([, v]) => v === true || (isObj(v) && v.approve === true)).map(([k]) => k);
|
|
@@ -287,6 +608,7 @@ function openCode(json) {
|
|
|
287
608
|
} else if (typeof json.share === "string") details.push(`Session sharing: ${json.share}.`);
|
|
288
609
|
if (typeof json.model === "string") details.push(`Uses the ${json.model} model.`);
|
|
289
610
|
if (isObj(json.agent) && Object.keys(json.agent).length) details.push(`Defines ${plural(Object.keys(json.agent).length, "agent")}: ${list(Object.keys(json.agent), 4)}.`);
|
|
611
|
+
namedFiles(parts, details, json.instructions);
|
|
290
612
|
return { parts, details };
|
|
291
613
|
}
|
|
292
614
|
|
|
@@ -294,9 +616,15 @@ function zedSettings(json) {
|
|
|
294
616
|
const parts = [];
|
|
295
617
|
const details = [];
|
|
296
618
|
if (!isObj(json)) return { parts, details };
|
|
297
|
-
if (json.agent?.always_allow_tool_actions === true || json.assistant?.always_allow_tool_actions === true) {
|
|
619
|
+
if (json.agent?.always_allow_tool_actions === true || json.assistant?.always_allow_tool_actions === true || json.agent?.tool_permissions?.default === "allow") {
|
|
298
620
|
parts.push("Runs agent tools without asking");
|
|
299
621
|
details.push("The agent runs tool actions without asking.");
|
|
622
|
+
} else if (typeof json.agent?.tool_permissions?.default === "string") {
|
|
623
|
+
details.push(`Tool permissions default to “${clip(json.agent.tool_permissions.default, 20)}”.`);
|
|
624
|
+
}
|
|
625
|
+
if (json.session?.trust_all_worktrees === true) {
|
|
626
|
+
parts.push("trusts every project");
|
|
627
|
+
details.push("Trusts every project you open, so each one's own settings apply.");
|
|
300
628
|
}
|
|
301
629
|
const model = json.agent?.default_model?.model ?? json.assistant?.default_model?.model;
|
|
302
630
|
if (typeof model === "string") details.push(`Uses the ${model} model.`);
|
|
@@ -308,19 +636,349 @@ function aiderConfig(file) {
|
|
|
308
636
|
const parts = [];
|
|
309
637
|
const details = [];
|
|
310
638
|
for (const line of file.lines ?? []) {
|
|
311
|
-
const
|
|
312
|
-
if (
|
|
313
|
-
const
|
|
639
|
+
const colon = line.indexOf(":");
|
|
640
|
+
if (colon < 0) continue;
|
|
641
|
+
const key = line.slice(0, colon).trim();
|
|
642
|
+
const value = line.slice(colon + 1).trim();
|
|
643
|
+
if (!/^[a-z0-9-]+$/i.test(key) || !value) continue;
|
|
314
644
|
if (key === "yes-always" && /^true$/i.test(value)) {
|
|
315
645
|
parts.push("Confirms everything without asking");
|
|
316
646
|
details.push("Answers yes to every confirmation, including running commands.");
|
|
317
647
|
} else if (key === "model") details.push(`Uses the ${clip(value, 40)} model.`);
|
|
318
648
|
else if (key === "auto-commits") details.push(`Commits changes automatically: ${value}.`);
|
|
319
649
|
}
|
|
650
|
+
// The read list, as one value, a [list] or items under the key.
|
|
651
|
+
const read = [];
|
|
652
|
+
let inRead = false;
|
|
653
|
+
for (const line of file.lines ?? []) {
|
|
654
|
+
const top = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/.exec(line);
|
|
655
|
+
if (top) {
|
|
656
|
+
inRead = top[1] === "read";
|
|
657
|
+
if (inRead && top[2].trim()) read.push(...top[2].replace(/^\[|\]$/g, "").split(",").map((x) => x.trim().replace(/^["']|["']$/g, "")));
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
const item = inRead && /^\s+-\s+(.+)$/.exec(line);
|
|
661
|
+
if (item) read.push(item[1].trim().replace(/^["']|["']$/g, ""));
|
|
662
|
+
}
|
|
663
|
+
namedFiles(parts, details, read.filter(Boolean));
|
|
664
|
+
return { parts, details };
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// --- Trusted folders, hooks and other agents' settings -----------------------
|
|
668
|
+
|
|
669
|
+
const RISKY_FOLDER = /^(~|\/|[a-z]:[\\/]?|(~|\/users\/[^/]+|\/home\/[^/]+|[a-z]:\/users\/[^/]+)(\/(downloads|desktop))?)$/i;
|
|
670
|
+
|
|
671
|
+
function trustedFolders(folders) {
|
|
672
|
+
const parts = [];
|
|
673
|
+
const details = [];
|
|
674
|
+
const shown = folders.map((d) => shortPath(d, 50));
|
|
675
|
+
if (!shown.length) return { parts, details, summary: "Trusts no folders." };
|
|
676
|
+
const risky = (d) => RISKY_FOLDER.test(d);
|
|
677
|
+
const home = shown.some((d) => d === "~");
|
|
678
|
+
parts.push(`trusts ${plural(shown.length, "folder")}${home ? ", including your home folder" : ""}`);
|
|
679
|
+
const ordered = [...shown.filter(risky), ...shown.filter((d) => !risky(d))].map((d) => (d === "~" ? "~ (your home folder)" : d));
|
|
680
|
+
details.push(`Trusts ${list(ordered, 5)}.`);
|
|
681
|
+
return { parts, details };
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Gemini CLI trusts a folder itself (TRUST_FOLDER) or the folder it's in (TRUST_PARENT).
|
|
685
|
+
function geminiTrusted(json) {
|
|
686
|
+
if (!isObj(json)) return [];
|
|
687
|
+
const parent = (d) => trimWord(d, "", "/\\").replace(/[\\/][^\\/]*$/, "") || "/";
|
|
688
|
+
return Object.entries(json).flatMap(([d, v]) => (v === "TRUST_FOLDER" ? [d] : v === "TRUST_PARENT" ? [parent(d)] : []));
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Every hook in a hooks setting, in any agent's format: event names mapped
|
|
692
|
+
// to lists of hooks, groups of hooks under a matcher, or a list of hooks
|
|
693
|
+
// that each name what sets them off. One line per hook, such as
|
|
694
|
+
// "PreToolUse: runs ./check.sh."
|
|
695
|
+
function hookLines(value, event = "", depth = 0, out = []) {
|
|
696
|
+
if (depth > 6 || out.length >= 50) return out;
|
|
697
|
+
if (Array.isArray(value)) {
|
|
698
|
+
for (const v of value.slice(0, 50)) hookLines(v, event, depth + 1, out);
|
|
699
|
+
return out;
|
|
700
|
+
}
|
|
701
|
+
if (!isObj(value)) return out;
|
|
702
|
+
const on = event || [value.trigger, value.when?.type, value.event].find((v) => typeof v === "string" && v.trim()) || "";
|
|
703
|
+
const command = [value.command, value.bash, value.powershell, value.action?.command, value.then?.command].find((c) => (typeof c === "string" && c.trim()) || strs(c).length);
|
|
704
|
+
const prompt = [value.prompt, value.action?.prompt, value.then?.prompt].find((c) => typeof c === "string" && c.trim());
|
|
705
|
+
const what = command !== undefined ? `runs ${clip(Array.isArray(command) ? strs(command).join(" ") : command, 80)}` : prompt ? `asks the agent “${clip(prompt, 80)}”` : null;
|
|
706
|
+
if (what) {
|
|
707
|
+
out.push(on ? `${clip(on, 40)}: ${what}.` : sentence(what));
|
|
708
|
+
return out;
|
|
709
|
+
}
|
|
710
|
+
for (const [k, v] of Object.entries(value)) if (k !== "matcher" && k !== "when") hookLines(v, depth === 0 && !event ? k : on, depth + 1, out);
|
|
711
|
+
return out;
|
|
712
|
+
}
|
|
713
|
+
const hookParts = (lines) => (lines.length ? [lines.length === 1 ? "has a hook" : `has ${lines.length} hooks`] : []);
|
|
714
|
+
|
|
715
|
+
function jsonHooks(json) {
|
|
716
|
+
const details = hookLines(isObj(json) && json.hooks !== undefined ? json.hooks : json);
|
|
717
|
+
return { parts: hookParts(details), details };
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// Kiro and Amazon Q agent files: hooks, and tools the agent uses without
|
|
721
|
+
// asking. Their MCP servers are listed with the others.
|
|
722
|
+
function agentConfig(json) {
|
|
723
|
+
if (!isObj(json)) return { parts: [], details: [], summary: "Couldn't read the settings in this file." };
|
|
724
|
+
const details = hookLines(json.hooks);
|
|
725
|
+
const parts = hookParts(details);
|
|
726
|
+
const allowed = strs(json.allowedTools);
|
|
727
|
+
if (allowed.length) {
|
|
728
|
+
parts.push(`uses ${plural(allowed.length, "tool")} without asking`);
|
|
729
|
+
details.push(`Tools it uses without asking: ${list(allowed.map((t) => clip(t, 40)), 6)}.`);
|
|
730
|
+
}
|
|
731
|
+
if (typeof json.name === "string" && json.name.trim()) details.unshift(`Agent “${clip(json.name, 40)}”.`);
|
|
732
|
+
return { parts, details };
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// What a Cursor background agent runs on the machine it works on.
|
|
736
|
+
function cursorEnvironment(json) {
|
|
737
|
+
if (!isObj(json)) return { parts: [], details: [], summary: "Couldn't read the settings in this file." };
|
|
738
|
+
const details = [];
|
|
739
|
+
if (typeof json.install === "string" && json.install.trim()) details.push(`Runs ${clip(json.install, 80)} to set up the machine.`);
|
|
740
|
+
if (typeof json.start === "string" && json.start.trim()) details.push(`Runs ${clip(json.start, 80)} each time an agent starts.`);
|
|
741
|
+
for (const t of (Array.isArray(json.terminals) ? json.terminals : []).filter((t) => isObj(t) && typeof t.command === "string").slice(0, 5)) {
|
|
742
|
+
details.push(`Opens a terminal${typeof t.name === "string" && t.name.trim() ? ` named “${clip(t.name, 30)}”` : ""} that runs ${clip(t.command, 60)}.`);
|
|
743
|
+
}
|
|
744
|
+
return { parts: details.length ? [`runs ${plural(details.length, "command")} for background agents`] : [], details };
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// A Gemini CLI custom command: its name, what it asks the agent, and the
|
|
748
|
+
// shell commands it runs with !{...} before the prompt is sent.
|
|
749
|
+
function geminiCommand(path, toml) {
|
|
750
|
+
if (!isObj(toml)) return { parts: [], details: [], summary: "Couldn't read the settings in this file." };
|
|
751
|
+
const name = `/${path.replace(/^.*?\.gemini\/commands\//i, "").replace(/\.toml$/i, "").split("/").join(":")}`;
|
|
752
|
+
const prompt = typeof toml.prompt === "string" ? toml.prompt : "";
|
|
753
|
+
const shell = [...prompt.matchAll(/!\{([^}]{1,200})\}/g)].map((m) => m[1].trim());
|
|
754
|
+
const parts = [`command ${clip(name, 40)}`];
|
|
755
|
+
if (shell.length) parts.push(`runs ${plural(shell.length, "shell command")} when used`);
|
|
756
|
+
const details = [];
|
|
757
|
+
if (typeof toml.description === "string" && toml.description.trim()) details.push(`Described as: “${clip(toml.description, 80)}”`);
|
|
758
|
+
if (prompt.trim()) details.push(`Says: “${clip(prompt.trim().split("\n")[0], 80)}”`);
|
|
759
|
+
for (const c of shell.slice(0, 5)) details.push(`Runs ${clip(c, 60)} first.`);
|
|
760
|
+
return { parts, details };
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// Files a setting names as instructions, beyond the agent's usual ones.
|
|
764
|
+
function namedFiles(parts, details, names, usual = []) {
|
|
765
|
+
const given = (typeof names === "string" ? [names] : Array.isArray(names) ? names : []).filter((n) => typeof n === "string" && n.trim()).map((n) => clip(n.trim(), 60));
|
|
766
|
+
if (!given.some((n) => !usual.includes(n))) return;
|
|
767
|
+
parts.push(`reads instructions from ${list(given.filter((n) => !usual.includes(n)), 3)}`);
|
|
768
|
+
details.push(`Reads its instructions from ${list(given, 6)}.`);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// VS Code tasks: what each runs, and which run as soon as the folder opens.
|
|
772
|
+
function vsCodeTasks(json) {
|
|
773
|
+
const tasks = (Array.isArray(json?.tasks) ? json.tasks : []).filter(isObj);
|
|
774
|
+
if (!tasks.length) return { parts: [], details: [] };
|
|
775
|
+
const text = (t) => clip([t.command, ...strs(t.args)].filter((w) => typeof w === "string").join(" ").trim(), 70);
|
|
776
|
+
const onOpen = tasks.filter((t) => t.runOptions?.runOn === "folderOpen");
|
|
777
|
+
const parts = [plural(tasks.length, "task")];
|
|
778
|
+
if (onOpen.length) parts.push(`${onOpen.length === 1 ? "1 runs" : `${onOpen.length} run`} when the folder opens`);
|
|
779
|
+
const details = tasks.slice(0, 20).map((t) => {
|
|
780
|
+
const name = typeof t.label === "string" && t.label.trim() ? `Task “${clip(t.label, 40)}”` : "A task";
|
|
781
|
+
const command = text(t);
|
|
782
|
+
return `${name}${command ? ` runs ${command}` : ""}${t.runOptions?.runOn === "folderOpen" ? ", as soon as the folder opens" : ""}.`;
|
|
783
|
+
});
|
|
784
|
+
return { parts, details };
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Codex command rules: which commands run without asking, which ask first
|
|
788
|
+
// and which are blocked.
|
|
789
|
+
const DECISIONS = { allow: (w) => `Lets ${w} run without asking`, prompt: (w) => `Asks before ${w}`, forbidden: (w) => `Blocks ${w}` };
|
|
790
|
+
function codexRules(file) {
|
|
791
|
+
const rules = parseCodexRules(file.content).filter((r) => r.pattern?.length && DECISIONS[r.decision]);
|
|
792
|
+
if (!rules.length) return { parts: [], details: [], summary: "No command rules this check can read." };
|
|
793
|
+
// Programs by name, so C:\Windows\...\powershell.exe -Command reads as
|
|
794
|
+
// powershell -Command.
|
|
795
|
+
const word = (w, i) => (i === 0 ? programName(w) : w);
|
|
796
|
+
const words = (r) => clip(r.pattern.slice(0, 5).map((w, i) => (Array.isArray(w) ? w.map((x) => word(x, i)).join(" or ") : w == null ? "…" : word(w, i))).join(" "), 60);
|
|
797
|
+
// The summary names each pattern by its program and first word.
|
|
798
|
+
const start = (r) => clip(r.pattern.slice(0, 2).map((w, i) => (Array.isArray(w) ? w.map((x) => word(x, i)).join(" or ") : w == null ? "…" : word(w, i))).join(" "), 40);
|
|
799
|
+
const parts = [];
|
|
800
|
+
for (const [decision, verb] of [["allow", "lets"], ["prompt", "asks before"], ["forbidden", "blocks"]]) {
|
|
801
|
+
const matching = rules.filter((r) => r.decision === decision);
|
|
802
|
+
if (!matching.length) continue;
|
|
803
|
+
const starts = [...new Set(matching.map(start))];
|
|
804
|
+
const what = matching.length === 1 ? starts[0] : `${plural(matching.length, "command")} starting with ${list(starts, 3)}`;
|
|
805
|
+
parts.push(decision === "allow" ? `${verb} ${what} run without asking` : `${verb} ${what}`);
|
|
806
|
+
}
|
|
807
|
+
const details = rules.slice(0, 30).map((r) => `${DECISIONS[r.decision](words(r))}${r.justification.trim() ? `: “${clip(r.justification, 60)}”` : ""}.`);
|
|
808
|
+
return { parts, details };
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function cursorCli(json) {
|
|
812
|
+
const parts = [];
|
|
813
|
+
const details = [];
|
|
814
|
+
const allow = strs(json?.permissions?.allow);
|
|
815
|
+
const deny = strs(json?.permissions?.deny);
|
|
816
|
+
if (allow.length) {
|
|
817
|
+
parts.push(`allows ${plural(allow.length, "action")} without asking`);
|
|
818
|
+
details.push(`Allowed without asking: ${list(allow.map((r) => clip(r, 60)), 8)}.`);
|
|
819
|
+
}
|
|
820
|
+
if (deny.length) {
|
|
821
|
+
parts.push(`blocks ${plural(deny.length, "action")}`);
|
|
822
|
+
details.push(`Blocked: ${list(deny.map((r) => clip(r, 60)), 8)}.`);
|
|
823
|
+
}
|
|
824
|
+
return { parts, details };
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function cursorSandbox(json) {
|
|
828
|
+
if (json?.type === "insecure_none") return { parts: ["No sandbox"], details: ["No sandbox: agent commands can change any file and use the network."] };
|
|
829
|
+
const details = [];
|
|
830
|
+
if (typeof json?.type === "string") details.push(`Sandbox type: ${clip(json.type, 30)}.`);
|
|
831
|
+
if (typeof json?.networkPolicy?.default === "string") details.push(`Network access by default: ${clip(json.networkPolicy.default, 20)}.`);
|
|
832
|
+
return { parts: [], details };
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function claudePlugins(json) {
|
|
836
|
+
const names = isObj(json?.plugins) ? Object.keys(json.plugins) : [];
|
|
837
|
+
if (!names.length) return { parts: [], details: [], summary: "No plugins installed." };
|
|
838
|
+
return { parts: [`${plural(names.length, "plugin")} installed`], details: [`Installed plugins: ${list(names.map((n) => clip(n, 50)), 8)}.`] };
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// Where a plugin marketplace's plugins come from, by its source type: a
|
|
842
|
+
// GitHub repository, a git or web address, or a folder.
|
|
843
|
+
function marketplaceKind(m) {
|
|
844
|
+
const src = isObj(m?.source) ? m.source : {};
|
|
845
|
+
const repo = typeof src.repo === "string" ? src.repo : "";
|
|
846
|
+
const url = typeof src.url === "string" ? src.url : "";
|
|
847
|
+
const kind = typeof src.source === "string" ? src.source : repo && !url ? "github" : url && !repo ? "git" : "";
|
|
848
|
+
return { kind, repo, url, path: typeof src.path === "string" ? src.path : "" };
|
|
849
|
+
}
|
|
850
|
+
export function marketplaceSource(m) {
|
|
851
|
+
const { kind, repo, url, path } = marketplaceKind(m);
|
|
852
|
+
return kind === "github" ? repo : kind === "git" || kind === "url" ? url : path || repo || url;
|
|
853
|
+
}
|
|
854
|
+
// True for a marketplace in Anthropic's own GitHub organization, named
|
|
855
|
+
// exactly: the address its source type uses, with no more path after the
|
|
856
|
+
// repository.
|
|
857
|
+
const ANTHROPIC_REPO = /^anthropics\/(?!\.\.?$)[A-Za-z0-9._-]{1,100}$/i;
|
|
858
|
+
const ANTHROPIC_URL = /^(?:https:\/\/github\.com\/|git@github\.com:)anthropics\/(?!\.\.?(?:\.git)?\/?$)[A-Za-z0-9._-]{1,100}\/?$/i;
|
|
859
|
+
export function anthropicMarketplace(m) {
|
|
860
|
+
const { kind, repo, url } = marketplaceKind(m);
|
|
861
|
+
if (kind === "github") return ANTHROPIC_REPO.test(repo);
|
|
862
|
+
if (kind === "git" || kind === "url") return ANTHROPIC_URL.test(url);
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// Where Claude Code can install plugins from, and who runs each place.
|
|
867
|
+
function claudeMarketplaces(json) {
|
|
868
|
+
const entries = isObj(json) ? Object.entries(json).filter(([, m]) => isObj(m)) : [];
|
|
869
|
+
if (!entries.length) return { parts: [], details: [], summary: "No plugin marketplaces added." };
|
|
870
|
+
const others = entries.filter(([, m]) => !anthropicMarketplace(m)).length;
|
|
871
|
+
const who = !others ? "all run by Anthropic" : others < entries.length ? `${others} not run by Anthropic` : entries.length === 1 ? "not run by Anthropic" : "none run by Anthropic";
|
|
872
|
+
return {
|
|
873
|
+
parts: [`${plural(entries.length, "plugin marketplace")}, ${who}`],
|
|
874
|
+
details: entries.slice(0, 50).map(([name, m]) => `Marketplace ${clip(name, 50)}: ${clip(marketplaceSource(m), 100) || "no source given"}${anthropicMarketplace(m) ? ", run by Anthropic" : ""}.`),
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
function codexRequirements(toml) {
|
|
879
|
+
const details = [];
|
|
880
|
+
if (!isObj(toml)) return { parts: [], details };
|
|
881
|
+
for (const [key, value] of Object.entries(toml)) {
|
|
882
|
+
const text = (v) => (typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? String(v) : "");
|
|
883
|
+
if (Array.isArray(value)) details.push(`${key}: ${list(value.map(text).filter(Boolean).map((v) => clip(v, 30)), 6)}.`);
|
|
884
|
+
else if (text(value)) details.push(`${key}: ${clip(text(value), 40)}.`);
|
|
885
|
+
}
|
|
886
|
+
return { parts: details.length ? ["Limits what Codex settings may allow"] : [], details };
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function clineState(json) {
|
|
890
|
+
const parts = [];
|
|
891
|
+
const details = [];
|
|
892
|
+
if (!isObj(json)) return { parts, details };
|
|
893
|
+
if (json.yoloModeToggled === true) {
|
|
894
|
+
parts.push("YOLO mode: approves everything");
|
|
895
|
+
details.push("YOLO mode is on: every action runs without asking.");
|
|
896
|
+
}
|
|
897
|
+
const auto = json.autoApprovalSettings;
|
|
898
|
+
if (isObj(auto) && auto.enabled !== false && isObj(auto.actions)) {
|
|
899
|
+
const on = Object.keys(auto.actions).filter((k) => auto.actions[k] === true);
|
|
900
|
+
if (on.length) {
|
|
901
|
+
if (!parts.length) parts.push(`auto-approves ${plural(on.length, "kind")} of action`);
|
|
902
|
+
details.push(`Approved without asking: ${list(on, 6)}.`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
320
905
|
return { parts, details };
|
|
321
906
|
}
|
|
322
907
|
|
|
323
|
-
|
|
908
|
+
function grokConfig(toml) {
|
|
909
|
+
const parts = [];
|
|
910
|
+
const details = [];
|
|
911
|
+
if (!isObj(toml)) return { parts, details, summary: "Couldn't read the settings in this file." };
|
|
912
|
+
const mode = toml.ui?.permission_mode ?? toml.permission_mode;
|
|
913
|
+
if (mode === "always-approve" || mode === "yolo") {
|
|
914
|
+
parts.push("Never asks");
|
|
915
|
+
details.push(`Permission mode “${mode}”: runs commands and edits without asking.`);
|
|
916
|
+
} else if (typeof mode === "string") details.push(`Permission mode: ${clip(mode, 30)}.`);
|
|
917
|
+
if (isObj(toml.sandbox)) details.push(`Sandbox settings: ${list(Object.keys(toml.sandbox), 5)}.`);
|
|
918
|
+
const status = toml.ui?.status_line?.command;
|
|
919
|
+
if (typeof status === "string" && status.trim()) {
|
|
920
|
+
parts.push("runs a command for its status line");
|
|
921
|
+
details.push(`Runs ${clip(status, 60)} to draw the status line.`);
|
|
922
|
+
}
|
|
923
|
+
return { parts, details };
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function ampSettings(json) {
|
|
927
|
+
const parts = [];
|
|
928
|
+
const details = [];
|
|
929
|
+
if (!isObj(json)) return { parts, details };
|
|
930
|
+
if (json["amp.dangerouslyAllowAll"] === true) {
|
|
931
|
+
parts.push("Runs every tool without asking");
|
|
932
|
+
details.push("Runs every tool, including commands, without asking.");
|
|
933
|
+
}
|
|
934
|
+
const keys = Object.keys(json).filter((k) => k.startsWith("amp.") && k !== "amp.mcpServers" && k !== "amp.dangerouslyAllowAll");
|
|
935
|
+
if (keys.length) details.push(`Changes ${plural(keys.length, "setting")}: ${list(keys, 5)}.`);
|
|
936
|
+
return { parts, details };
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// YAML, read line by line for the few keys that matter.
|
|
940
|
+
function gooseConfig(file) {
|
|
941
|
+
const parts = [];
|
|
942
|
+
const details = [];
|
|
943
|
+
const lines = file.lines ?? [];
|
|
944
|
+
const mode = lines.map((l) => l.match(/^GOOSE_MODE\s*:\s*["']?([\w-]+)/)?.[1]).find(Boolean);
|
|
945
|
+
if (mode === "auto") {
|
|
946
|
+
parts.push("Runs tools without asking");
|
|
947
|
+
details.push("Mode auto: runs tools and commands without asking.");
|
|
948
|
+
} else if (mode) details.push(`Mode: ${mode}.`);
|
|
949
|
+
const start = lines.findIndex((l) => /^extensions\s*:/.test(l));
|
|
950
|
+
if (start >= 0) {
|
|
951
|
+
const names = [];
|
|
952
|
+
for (const l of lines.slice(start + 1)) {
|
|
953
|
+
if (/^\S/.test(l)) break;
|
|
954
|
+
const m = l.match(/^ {2}([\w.-]+)\s*:\s*$/);
|
|
955
|
+
if (m) names.push(m[1]);
|
|
956
|
+
}
|
|
957
|
+
if (names.length) {
|
|
958
|
+
parts.push(`${plural(names.length, "extension")}: ${list(names, 3)}`);
|
|
959
|
+
details.push(`Extensions: ${list(names, 8)}.`);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return { parts, details };
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function continueConfig(file) {
|
|
966
|
+
const parts = [];
|
|
967
|
+
const details = [];
|
|
968
|
+
for (const line of file.lines ?? []) {
|
|
969
|
+
const m = line.match(/^\s*(?:-\s*)?destination\s*:\s*["']?([^\s"'#]+)/i);
|
|
970
|
+
if (!m) continue;
|
|
971
|
+
let where = m[1];
|
|
972
|
+
try {
|
|
973
|
+
where = /^https?:/i.test(m[1]) ? new URL(m[1]).host : shortPath(m[1].replace(/^file:\/\//i, ""), 50);
|
|
974
|
+
} catch {}
|
|
975
|
+
details.push(`Sends session data to ${clip(where, 50)}.`);
|
|
976
|
+
}
|
|
977
|
+
if (details.length) parts.push(`sends session data to ${plural(details.length, "place")}`);
|
|
978
|
+
return { parts, details };
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// --- Shell profiles and hook scripts -----------------------------------------
|
|
324
982
|
|
|
325
983
|
const AGENT_COMMANDS = /\b(claude|codex|gemini|qwen|opencode|cursor-agent|aider|amp|copilot|grok|kiro|q chat)\b/i;
|
|
326
984
|
const AGENT_ENV = /\b(ANTHROPIC|CLAUDE|OPENAI|CODEX|GEMINI|GOOGLE_GENAI|XAI|GROK|OPENROUTER|MISTRAL|DEEPSEEK)_[A-Z0-9_]+/;
|
|
@@ -340,12 +998,12 @@ function shellProfile(file) {
|
|
|
340
998
|
const details = [];
|
|
341
999
|
const lines = agentLines(file);
|
|
342
1000
|
for (const { line, text } of lines) {
|
|
343
|
-
const flag = text
|
|
1001
|
+
const flag = findDangerFlag(text);
|
|
344
1002
|
const agent = text.match(AGENT_COMMANDS)?.[1];
|
|
345
1003
|
const env = text.match(AGENT_ENV)?.[0];
|
|
346
1004
|
if (flag && agent) {
|
|
347
|
-
parts.push(`starts ${agent} with ${flag
|
|
348
|
-
details.push(`Line ${line}: every time you run ${agent}, it adds ${flag
|
|
1005
|
+
parts.push(`starts ${agent} with ${flag.flag}`);
|
|
1006
|
+
details.push(`Line ${line}: every time you run ${agent}, it adds ${flag.flag}.`);
|
|
349
1007
|
} else if (env) details.push(`Line ${line}: sets ${env} for every program you run.`);
|
|
350
1008
|
else details.push(`Line ${line}: ${clip(text, 80)}`);
|
|
351
1009
|
}
|
|
@@ -362,16 +1020,48 @@ function hookScript(file) {
|
|
|
362
1020
|
};
|
|
363
1021
|
}
|
|
364
1022
|
|
|
365
|
-
// --- Instruction files
|
|
1023
|
+
// --- Instruction files -------------------------------------------------------
|
|
1024
|
+
|
|
1025
|
+
// Files where "@path" pulls another file in: Claude Code's CLAUDE.md files
|
|
1026
|
+
// and rules, and Gemini CLI's GEMINI.md. Elsewhere an @ is only text, such as
|
|
1027
|
+
// a package or model name.
|
|
1028
|
+
export const CAN_IMPORT = /(?:^|\/)(?:claude(?:\.local)?|gemini)\.md$|(?:^|\/)\.claude\/rules\//i;
|
|
1029
|
+
const RX_IMPORT = /(?:^|\s)@([~.\w/-][^\s]*\.[A-Za-z][\w-]{0,9})(?=$|[\s),;:.!?])/g;
|
|
1030
|
+
|
|
1031
|
+
// Whether an offset sits inside a `code span` on its line.
|
|
1032
|
+
export function inCodeSpan(text, index) {
|
|
1033
|
+
let ticks = 0;
|
|
1034
|
+
for (let j = text.lastIndexOf("\n", index - 1) + 1; j < index; j++) if (text.charCodeAt(j) === 96) ticks++;
|
|
1035
|
+
return ticks % 2 === 1;
|
|
1036
|
+
}
|
|
366
1037
|
|
|
367
1038
|
const DIRECTIVE =
|
|
368
1039
|
/^(?:always|never|don['’]?t|do not|must|should|use|run|prefer|avoid|make sure|ensure|keep|write|follow|add|remove|only|ignore|install|call|send|read|check|before|after|when|if|you|please|import|create|update|delete|commit|push|test|format|name|put|store|respond|reply|answer|ask|tell|do)\b/i;
|
|
369
1040
|
|
|
1041
|
+
// The front matter of a skill, agent or rule file, read as YAML so that
|
|
1042
|
+
// quoted, folded and multi-line values come out the way they were written.
|
|
1043
|
+
// Values are kept as one line of text; a block YAML can't read falls back to
|
|
1044
|
+
// plain key: value lines.
|
|
370
1045
|
function frontmatter(text) {
|
|
371
1046
|
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
372
1047
|
if (!m) return {};
|
|
1048
|
+
const block = m[1].slice(0, 20_000);
|
|
373
1049
|
const out = {};
|
|
374
|
-
|
|
1050
|
+
let yaml = null;
|
|
1051
|
+
try {
|
|
1052
|
+
yaml = parseYAML(block);
|
|
1053
|
+
} catch {
|
|
1054
|
+
yaml = null;
|
|
1055
|
+
}
|
|
1056
|
+
if (isObj(yaml)) {
|
|
1057
|
+
for (const [key, value] of Object.entries(yaml)) {
|
|
1058
|
+
if (!/^[A-Za-z][\w-]*$/.test(key)) continue;
|
|
1059
|
+
const text = ["string", "number", "boolean"].includes(typeof value) ? String(value) : Array.isArray(value) ? value.filter((v) => typeof v === "string").join(", ") : null;
|
|
1060
|
+
if (text !== null) out[key.toLowerCase()] = text.replace(/\s+/g, " ").trim();
|
|
1061
|
+
}
|
|
1062
|
+
return out;
|
|
1063
|
+
}
|
|
1064
|
+
for (const line of block.split(/\r?\n/)) {
|
|
375
1065
|
const kv = line.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);
|
|
376
1066
|
if (kv) out[kv[1].toLowerCase()] = kv[2].trim().replace(/^["']|["']$/g, "");
|
|
377
1067
|
}
|
|
@@ -384,15 +1074,34 @@ function instructions(file) {
|
|
|
384
1074
|
const body = text.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "");
|
|
385
1075
|
const lines = body.split(/\r?\n/);
|
|
386
1076
|
const nonEmpty = lines.filter((l) => l.trim()).length;
|
|
387
|
-
|
|
388
|
-
|
|
1077
|
+
// Headings and imports outside code blocks: a "# comment" in a shell
|
|
1078
|
+
// example isn't a section, and an @ in code imports nothing.
|
|
1079
|
+
const headings = [];
|
|
1080
|
+
const imports = [];
|
|
1081
|
+
let code = false;
|
|
1082
|
+
for (const line of lines) {
|
|
1083
|
+
if (/^\s*(```|~~~)/.test(line)) code = !code;
|
|
1084
|
+
else if (code) continue;
|
|
1085
|
+
else if (/^#{1,3}\s+\S/.test(line)) headings.push(clip(line.replace(/^#+\s*/, ""), 40));
|
|
1086
|
+
else if (CAN_IMPORT.test(file.path)) {
|
|
1087
|
+
const visible = line.slice(0, 2000).replace(/`[^`]*`/g, " ");
|
|
1088
|
+
for (const m of visible.matchAll(RX_IMPORT)) imports.push(`@${m[1]}`);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
389
1091
|
// What it says, in the order it says it.
|
|
390
1092
|
const said = [];
|
|
391
1093
|
let fence = false;
|
|
392
1094
|
for (const raw of lines) {
|
|
393
1095
|
if (/^\s*(```|~~~)/.test(raw)) fence = !fence;
|
|
394
|
-
|
|
395
|
-
|
|
1096
|
+
// Code, headings and table rows aren't sentences the file says.
|
|
1097
|
+
if (fence || /^\s*(?:#|```|~~~|<!--|-->|-{3,}|\|)/.test(raw)) continue;
|
|
1098
|
+
// Lines are cut before links are tidied, so a line of thousands of
|
|
1099
|
+
// brackets can't slow it down. Only the start of a line is ever shown.
|
|
1100
|
+
const l = withoutComments(clean(raw.slice(0, 1000)))
|
|
1101
|
+
.replace(/^\s*(?:[-*+]|\d+[.)])\s+/, "")
|
|
1102
|
+
.replace(/\*\*/g, "")
|
|
1103
|
+
.replace(/!?\[([^\]\n]{1,200})\]\([^)\s]{0,300}\)/g, "$1")
|
|
1104
|
+
.trim();
|
|
396
1105
|
if (l.length >= 4 && !/^@\S+$/.test(l)) said.push(l);
|
|
397
1106
|
if (said.length >= 40) break;
|
|
398
1107
|
}
|
|
@@ -401,12 +1110,13 @@ function instructions(file) {
|
|
|
401
1110
|
|
|
402
1111
|
// What it says that people can't see: invisible characters and comments.
|
|
403
1112
|
const hidden = [];
|
|
404
|
-
for (const
|
|
405
|
-
const decoded =
|
|
1113
|
+
for (const run of hiddenTags(text)) {
|
|
1114
|
+
const decoded = run.decoded.trim();
|
|
406
1115
|
if (decoded) hidden.push(`Hidden text you can't see when it's displayed: “${clip(maskSecrets(decoded).text, 100)}”`);
|
|
1116
|
+
if (hidden.length >= 4) break;
|
|
407
1117
|
}
|
|
408
|
-
for (const
|
|
409
|
-
const inner =
|
|
1118
|
+
for (const c of hiddenComments(text)) {
|
|
1119
|
+
const inner = c.inner.trim();
|
|
410
1120
|
if (inner.length >= 8 && !/^(prettier-|eslint-|markdownlint|toc|end|start|region|endregion)/i.test(inner)) hidden.push(`Hidden in a comment: “${clip(inner, 100)}”`);
|
|
411
1121
|
if (hidden.length >= 4) break;
|
|
412
1122
|
}
|
|
@@ -415,24 +1125,27 @@ function instructions(file) {
|
|
|
415
1125
|
const name = fm.name ?? p.split("/").slice(-2, -1)[0];
|
|
416
1126
|
const parts = [];
|
|
417
1127
|
const details = [];
|
|
418
|
-
|
|
419
|
-
|
|
1128
|
+
const skill = /(^|\/)skills\/(?:[^/]+\/)+SKILL\.md$/i.test(p);
|
|
1129
|
+
if (skill || /(^|\/)\.claude\/(?:.+\/)?(agents|commands)\/[^/]+\.md$/i.test(p)) {
|
|
1130
|
+
const kind = skill ? "Skill" : /\/agents\/[^/]+$/i.test(p) ? "Subagent" : "Command";
|
|
420
1131
|
const label = kind === "Command" ? `/${p.split("/").pop().replace(/\.md$/i, "")}` : `“${name}”`;
|
|
421
1132
|
parts.push(`${kind} ${label}${fm.description ? `: ${clip(fm.description, 70)}` : ""}`);
|
|
422
1133
|
const tools = fm["allowed-tools"] ?? fm.tools;
|
|
423
1134
|
if (tools) details.push(`Can use: ${clip(tools, 80)}.`);
|
|
424
1135
|
if (fm.model) details.push(`Uses the ${fm.model} model.`);
|
|
425
1136
|
} else {
|
|
426
|
-
|
|
1137
|
+
const what = file.kind === "Memory" ? "saved memory" : "instructions";
|
|
1138
|
+
parts.push(`${plural(nonEmpty, "line")} of ${what}${example ? `, such as “${clip(example, 60)}”` : ""}`);
|
|
427
1139
|
}
|
|
428
1140
|
if (hidden.length) parts.push("also contains text that's hidden when you read it");
|
|
429
1141
|
if (fm.alwaysapply === "true") details.push("Applies to every request.");
|
|
430
1142
|
else if (fm.globs || fm.applyto) details.push(`Applies to files matching ${clip(fm.globs || fm.applyto, 60)}.`);
|
|
431
1143
|
else if (fm.description && !/skills|agents|commands/i.test(p)) details.push(`Applies when relevant to: ${clip(fm.description, 70)}.`);
|
|
432
|
-
if (headings.length) details.push(`Sections: ${list(headings, 6)}
|
|
1144
|
+
if (headings.length) details.push(period(`Sections: ${list(headings, 6)}`));
|
|
433
1145
|
if (imports.length) details.push(`Pulls in ${list([...new Set(imports)].map((i) => clip(i, 50)), 4)}.`);
|
|
434
1146
|
details.push(...hidden);
|
|
435
1147
|
for (const d of said.slice(0, 8)) details.push(`Says: “${clip(d, 90)}”`);
|
|
436
|
-
|
|
1148
|
+
// Only the first 40 lines are collected, so past that the count is a floor.
|
|
1149
|
+
if (said.length > 8) details.push(`And ${said.length >= 40 ? "at least " : ""}${plural(said.length - 8, "more line")}.`);
|
|
437
1150
|
return { parts, details };
|
|
438
1151
|
}
|