@misconfig/cli 0.0.0-stage → 1.0.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/README.md +65 -2
- package/bin/misconfig.js +12 -0
- package/engine/catalog.js +412 -0
- package/engine/index.js +1049 -0
- package/engine/locations.js +134 -0
- package/engine/mask.js +119 -0
- package/engine/parse.js +222 -0
- package/engine/paths.js +86 -0
- package/lib/discover.js +237 -0
- package/lib/main.js +112 -0
- package/lib/print.js +138 -0
- package/package.json +37 -5
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Where each agent keeps the files that control it. The command line tool
|
|
2
|
+
// reads these paths; the website shows them so people know where to look.
|
|
3
|
+
//
|
|
4
|
+
// Tokens: "~" is the home folder. "{config}" is the per-user app settings
|
|
5
|
+
// folder: ~/Library/Application Support on macOS, %APPDATA% on Windows and
|
|
6
|
+
// ~/.config on Linux. A path ending in "/" is a folder of files.
|
|
7
|
+
|
|
8
|
+
export const OSES = { mac: "macOS", windows: "Windows", linux: "Linux" };
|
|
9
|
+
|
|
10
|
+
export const LOCATIONS = [
|
|
11
|
+
{
|
|
12
|
+
agent: "Claude Code",
|
|
13
|
+
controls: "Permissions, hooks, MCP servers, and every folder it has been started in",
|
|
14
|
+
user: ["~/.claude/settings.json", "~/.claude/settings.local.json", "~/.claude.json", "~/.claude/CLAUDE.md", "~/.claude/agents/", "~/.claude/commands/", "~/.claude/skills/", "~/.claude/hooks/"],
|
|
15
|
+
system: {
|
|
16
|
+
mac: ["/Library/Application Support/ClaudeCode/managed-settings.json"],
|
|
17
|
+
windows: ["C:/ProgramData/ClaudeCode/managed-settings.json"],
|
|
18
|
+
linux: ["/etc/claude-code/managed-settings.json"],
|
|
19
|
+
},
|
|
20
|
+
project: ["CLAUDE.md", ".claude/settings.json", ".claude/settings.local.json", ".mcp.json", ".claude/agents/", ".claude/commands/"],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
agent: "Claude Desktop",
|
|
24
|
+
controls: "MCP servers for the desktop app",
|
|
25
|
+
user: ["{config}/Claude/claude_desktop_config.json"],
|
|
26
|
+
project: [],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
agent: "Codex",
|
|
30
|
+
controls: "Sandbox, approvals, MCP servers and trusted folders",
|
|
31
|
+
user: ["~/.codex/config.toml", "~/.codex/AGENTS.md"],
|
|
32
|
+
project: ["AGENTS.md", ".codex/config.toml"],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
agent: "Cursor",
|
|
36
|
+
controls: "Rules, MCP servers and editor settings",
|
|
37
|
+
user: ["~/.cursor/mcp.json", "{config}/Cursor/User/settings.json"],
|
|
38
|
+
project: [".cursor/rules/", ".cursor/mcp.json", ".cursorrules", "AGENTS.md"],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
agent: "GitHub Copilot in VS Code",
|
|
42
|
+
controls: "Instructions, auto-approval and MCP servers",
|
|
43
|
+
user: ["{config}/Code/User/settings.json", "{config}/Code/User/mcp.json"],
|
|
44
|
+
project: [".github/copilot-instructions.md", ".github/instructions/", ".github/prompts/", ".vscode/settings.json", ".vscode/mcp.json"],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
agent: "Gemini CLI",
|
|
48
|
+
controls: "YOLO and auto-accept, MCP servers and instructions",
|
|
49
|
+
user: ["~/.gemini/settings.json", "~/.gemini/GEMINI.md"],
|
|
50
|
+
project: ["GEMINI.md", ".gemini/settings.json"],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
agent: "Your shell",
|
|
54
|
+
controls: "Aliases that start an agent with approvals off",
|
|
55
|
+
user: {
|
|
56
|
+
mac: ["~/.zshrc", "~/.zprofile", "~/.bash_profile", "~/.bashrc"],
|
|
57
|
+
linux: ["~/.bashrc", "~/.zshrc", "~/.profile", "~/.config/fish/config.fish"],
|
|
58
|
+
windows: ["~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1", "~/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1"],
|
|
59
|
+
},
|
|
60
|
+
project: [],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
agent: "OpenCode",
|
|
64
|
+
controls: "Permissions, session sharing and MCP servers",
|
|
65
|
+
user: ["~/.config/opencode/opencode.json", "~/.config/opencode/AGENTS.md"],
|
|
66
|
+
project: ["opencode.json", ".opencode/", "AGENTS.md"],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
agent: "Grok CLI",
|
|
70
|
+
controls: "API key, model and MCP servers",
|
|
71
|
+
user: ["~/.grok/settings.json", "~/.grok/user-settings.json"],
|
|
72
|
+
project: [".grok/settings.json", ".grok/GROK.md"],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
agent: "Windsurf",
|
|
76
|
+
controls: "Rules and MCP servers",
|
|
77
|
+
user: ["~/.codeium/windsurf/mcp_config.json", "{config}/Windsurf/User/settings.json"],
|
|
78
|
+
project: [".windsurf/rules/", ".windsurfrules"],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
agent: "Cline",
|
|
82
|
+
controls: "MCP servers and auto-approved tools",
|
|
83
|
+
user: ["{config}/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json"],
|
|
84
|
+
project: [".clinerules"],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
agent: "Roo Code",
|
|
88
|
+
controls: "MCP servers, modes and rules",
|
|
89
|
+
user: ["{config}/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json"],
|
|
90
|
+
project: [".roo/", ".roomodes"],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
agent: "Zed",
|
|
94
|
+
controls: "Agent tool approvals and context servers",
|
|
95
|
+
user: { mac: ["~/.config/zed/settings.json"], linux: ["~/.config/zed/settings.json"], windows: ["{config}/Zed/settings.json"] },
|
|
96
|
+
project: [".zed/settings.json"],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
agent: "Kiro",
|
|
100
|
+
controls: "Steering files and MCP servers",
|
|
101
|
+
user: ["~/.kiro/settings/mcp.json", "~/.kiro/steering/"],
|
|
102
|
+
project: [".kiro/steering/", ".kiro/settings/mcp.json"],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
agent: "Amazon Q",
|
|
106
|
+
controls: "Rules and MCP servers",
|
|
107
|
+
user: ["~/.aws/amazonq/mcp.json"],
|
|
108
|
+
project: [".amazonq/rules/", ".amazonq/mcp.json"],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
agent: "Aider",
|
|
112
|
+
controls: "Auto-confirm and model settings",
|
|
113
|
+
user: ["~/.aider.conf.yml"],
|
|
114
|
+
project: [".aider.conf.yml"],
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const CONFIG_DIR = { mac: "~/Library/Application Support", windows: "~/AppData/Roaming", linux: "~/.config" };
|
|
119
|
+
|
|
120
|
+
// Paths for one OS, with "{config}" expanded and "~" kept.
|
|
121
|
+
export function userPaths(entry, os) {
|
|
122
|
+
const list = Array.isArray(entry.user) ? entry.user : entry.user?.[os] ?? [];
|
|
123
|
+
const system = entry.system?.[os] ?? [];
|
|
124
|
+
return [...list, ...system].map((p) => p.replace("{config}", CONFIG_DIR[os]));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// How to write a path so people recognise it on their system.
|
|
128
|
+
export function displayPath(path, os) {
|
|
129
|
+
if (os !== "windows") return path;
|
|
130
|
+
return path
|
|
131
|
+
.replace(/^~\/AppData\/Roaming/, "%APPDATA%")
|
|
132
|
+
.replace(/^~\//, "%USERPROFILE%/")
|
|
133
|
+
.replace(/\//g, "\\");
|
|
134
|
+
}
|
package/engine/mask.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Secret masking, shared by the browser and the Worker.
|
|
2
|
+
//
|
|
3
|
+
// Likely secrets are replaced with «masked:<kind>:<length>» before a file
|
|
4
|
+
// leaves the browser. Line breaks are kept, so line numbers still match the
|
|
5
|
+
// original file. The Worker runs the same masking again as a backstop.
|
|
6
|
+
|
|
7
|
+
const MARK_OPEN = "«masked:";
|
|
8
|
+
|
|
9
|
+
const TOKEN_PATTERNS = [
|
|
10
|
+
["private-key", /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g],
|
|
11
|
+
["anthropic-key", /\bsk-ant-[A-Za-z0-9_-]{20,}/g],
|
|
12
|
+
["openai-key", /\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{20,}/g],
|
|
13
|
+
["github-token", /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})/g],
|
|
14
|
+
["aws-key-id", /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g],
|
|
15
|
+
["slack-token", /\bxox[abprs]-[A-Za-z0-9-]{10,}/g],
|
|
16
|
+
["google-key", /\bAIza[0-9A-Za-z_-]{35}/g],
|
|
17
|
+
["stripe-key", /\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}/g],
|
|
18
|
+
["xai-key", /\bxai-[A-Za-z0-9]{20,}/g],
|
|
19
|
+
["groq-key", /\bgsk_[A-Za-z0-9]{20,}/g],
|
|
20
|
+
["huggingface-token", /\bhf_[A-Za-z0-9]{30,}/g],
|
|
21
|
+
["npm-token", /\bnpm_[A-Za-z0-9]{36}\b/g],
|
|
22
|
+
["jwt", /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g],
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
// key = value, "key": "value", KEY=value, --api-key value ...
|
|
26
|
+
const ASSIGNMENT =
|
|
27
|
+
/((?:api[_-]?key|apikey|access[_-]?key|secret[_-]?key|access[_-]?token|auth[_-]?token|refresh[_-]?token|client[_-]?secret|token|secret|password|passwd|pwd|private[_-]?key)["']?\s*(?:[:=]|\s)\s*["']?)([^\s"'`,;{}()<>[\]«]{12,})/gi;
|
|
28
|
+
const BEARER = /(\bBearer\s+)([A-Za-z0-9._~+/=-]{16,})/g;
|
|
29
|
+
const URL_PASSWORD = /(\b[a-z][a-z0-9+.-]*:\/\/[^\s/:@"']{1,64}:)([^\s/@"']{6,})(?=@)/gi;
|
|
30
|
+
const URL_TOKEN = /([?&](?:token|key|api[_-]?key|apikey|access[_-]?token|auth|secret|sig|signature|password)=)([^&#\s"']{8,})/gi;
|
|
31
|
+
|
|
32
|
+
const PLACEHOLDER =
|
|
33
|
+
/^(?:\$|%|<|\{|\[)|\$\{|\{\{|your[_-]?|example|placeholder|changeme|change[_-]?me|redacted|dummy|sample|test[_-]?key|x{4,}|\*{3,}|\.{3}|^(?:true|false|null|none|undefined)$|^process\.env|^env[.:]/i;
|
|
34
|
+
|
|
35
|
+
export function isMasked(value) {
|
|
36
|
+
return typeof value === "string" && value.includes(MARK_OPEN);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function marker(kind, length) {
|
|
40
|
+
return `«masked:${kind}:${length}»`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function entropy(value) {
|
|
44
|
+
const counts = new Map();
|
|
45
|
+
for (const ch of value) counts.set(ch, (counts.get(ch) || 0) + 1);
|
|
46
|
+
let bits = 0;
|
|
47
|
+
for (const n of counts.values()) {
|
|
48
|
+
const p = n / value.length;
|
|
49
|
+
bits -= p * Math.log2(p);
|
|
50
|
+
}
|
|
51
|
+
return bits;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// True when a value looks like a real credential rather than a reference
|
|
55
|
+
// such as ${GITHUB_TOKEN}, {env:KEY} or "your-key-here".
|
|
56
|
+
export function looksLikeSecret(value) {
|
|
57
|
+
if (typeof value !== "string") return false;
|
|
58
|
+
const v = value.trim();
|
|
59
|
+
if (isMasked(v)) return true;
|
|
60
|
+
if (v.length < 12 || PLACEHOLDER.test(v)) return false;
|
|
61
|
+
for (const [, re] of TOKEN_PATTERNS) {
|
|
62
|
+
re.lastIndex = 0;
|
|
63
|
+
if (re.test(v)) return true;
|
|
64
|
+
}
|
|
65
|
+
const classes = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/].filter((re) => re.test(v)).length;
|
|
66
|
+
return v.length >= 16 && classes >= 2 && entropy(v) >= 3.3 && !/\s/.test(v);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Stricter, for strings with no key name to go on, such as command arguments.
|
|
70
|
+
// Random tokens mix letters and digits; names like GITHUB_TOKEN, flags like
|
|
71
|
+
// --dangerously-skip-permissions and package names are made of words and
|
|
72
|
+
// version numbers.
|
|
73
|
+
const WORDY = /^(?:[A-Za-z]+[0-9]{0,2}|[0-9]{1,4})$/;
|
|
74
|
+
export function looksLikeToken(value) {
|
|
75
|
+
if (typeof value !== "string") return false;
|
|
76
|
+
const v = value.trim();
|
|
77
|
+
if (isMasked(v)) return true;
|
|
78
|
+
for (const [, re] of TOKEN_PATTERNS) {
|
|
79
|
+
re.lastIndex = 0;
|
|
80
|
+
if (re.test(v)) return true;
|
|
81
|
+
}
|
|
82
|
+
if (!/[0-9]/.test(v) || !/[A-Za-z]/.test(v)) return false;
|
|
83
|
+
if (v.split(/[-_.:@+]/).every((part) => !part || WORDY.test(part))) return false;
|
|
84
|
+
return looksLikeSecret(v);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function maskSecrets(text) {
|
|
88
|
+
let count = 0;
|
|
89
|
+
const kinds = {};
|
|
90
|
+
const note = (kind) => {
|
|
91
|
+
count++;
|
|
92
|
+
kinds[kind] = (kinds[kind] || 0) + 1;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
let out = text;
|
|
96
|
+
for (const [kind, re] of TOKEN_PATTERNS) {
|
|
97
|
+
out = out.replace(re, (match) => {
|
|
98
|
+
note(kind);
|
|
99
|
+
const newlines = (match.match(/\n/g) || []).length;
|
|
100
|
+
return marker(kind, match.length) + "\n".repeat(newlines);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const keepPrefix = (kind) => (match, prefix, value) => {
|
|
104
|
+
if (isMasked(value) || PLACEHOLDER.test(value)) return match;
|
|
105
|
+
if (kind === "assigned-secret" && !looksLikeSecret(value)) return match;
|
|
106
|
+
note(kind);
|
|
107
|
+
return prefix + marker(kind, value.length);
|
|
108
|
+
};
|
|
109
|
+
out = out.replace(URL_PASSWORD, keepPrefix("url-password"));
|
|
110
|
+
out = out.replace(URL_TOKEN, keepPrefix("url-token"));
|
|
111
|
+
out = out.replace(BEARER, keepPrefix("bearer-token"));
|
|
112
|
+
out = out.replace(ASSIGNMENT, keepPrefix("assigned-secret"));
|
|
113
|
+
return { text: out, count, kinds };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// "«masked:openai-key:51»" -> "•••• (openai key, 51 chars)"
|
|
117
|
+
export function describeMasks(text) {
|
|
118
|
+
return String(text).replace(/«masked:([a-z0-9-]+):(\d+)»/g, (_, kind, len) => `•••• (${kind.replace(/-/g, " ")}, ${len} chars)`);
|
|
119
|
+
}
|
package/engine/parse.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Small tolerant parsers for agent config files. They never throw: a file
|
|
2
|
+
// that can't be parsed returns undefined and is checked as plain text.
|
|
3
|
+
|
|
4
|
+
// JSON with comments and trailing commas (VS Code, OpenCode, Zed settings).
|
|
5
|
+
export function parseJSONC(text) {
|
|
6
|
+
const s = String(text).replace(/^/, "");
|
|
7
|
+
let out = "";
|
|
8
|
+
let inString = false;
|
|
9
|
+
for (let i = 0; i < s.length; i++) {
|
|
10
|
+
const c = s[i];
|
|
11
|
+
const n = s[i + 1];
|
|
12
|
+
if (inString) {
|
|
13
|
+
out += c;
|
|
14
|
+
if (c === "\\") {
|
|
15
|
+
out += n ?? "";
|
|
16
|
+
i++;
|
|
17
|
+
} else if (c === '"') inString = false;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (c === '"') {
|
|
21
|
+
inString = true;
|
|
22
|
+
out += c;
|
|
23
|
+
} else if (c === "/" && n === "/") {
|
|
24
|
+
while (i < s.length && s[i] !== "\n") i++;
|
|
25
|
+
out += "\n";
|
|
26
|
+
} else if (c === "/" && n === "*") {
|
|
27
|
+
i += 2;
|
|
28
|
+
while (i < s.length && !(s[i] === "*" && s[i + 1] === "/")) {
|
|
29
|
+
if (s[i] === "\n") out += "\n";
|
|
30
|
+
i++;
|
|
31
|
+
}
|
|
32
|
+
i++;
|
|
33
|
+
} else if (c === ",") {
|
|
34
|
+
let j = i + 1;
|
|
35
|
+
while (j < s.length && /\s/.test(s[j])) j++;
|
|
36
|
+
if (s[j] !== "}" && s[j] !== "]") out += c;
|
|
37
|
+
} else out += c;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(out);
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Enough TOML for Codex config.toml: tables, dotted and quoted keys,
|
|
47
|
+
// strings, numbers, booleans, arrays and inline tables.
|
|
48
|
+
export function parseTOML(text) {
|
|
49
|
+
const root = {};
|
|
50
|
+
let table = root;
|
|
51
|
+
const lines = String(text).replace(/^/, "").split(/\r?\n/);
|
|
52
|
+
try {
|
|
53
|
+
for (let i = 0; i < lines.length; i++) {
|
|
54
|
+
const line = stripComment(lines[i]).trim();
|
|
55
|
+
if (!line) continue;
|
|
56
|
+
let m = line.match(/^\[\[\s*(.+?)\s*\]\]$/);
|
|
57
|
+
if (m) {
|
|
58
|
+
const keys = splitKey(m[1]);
|
|
59
|
+
const parent = ensure(root, keys.slice(0, -1));
|
|
60
|
+
const last = keys[keys.length - 1];
|
|
61
|
+
if (!Array.isArray(parent[last])) parent[last] = [];
|
|
62
|
+
table = {};
|
|
63
|
+
parent[last].push(table);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
m = line.match(/^\[\s*(.+?)\s*\]$/);
|
|
67
|
+
if (m) {
|
|
68
|
+
table = ensure(root, splitKey(m[1]));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const eq = findTopLevel(line, "=");
|
|
72
|
+
if (eq < 0) continue;
|
|
73
|
+
const keys = splitKey(line.slice(0, eq).trim());
|
|
74
|
+
let raw = line.slice(eq + 1).trim();
|
|
75
|
+
while (!isComplete(raw) && i + 1 < lines.length) {
|
|
76
|
+
i++;
|
|
77
|
+
raw += "\n" + stripComment(lines[i]);
|
|
78
|
+
}
|
|
79
|
+
const parent = ensure(table, keys.slice(0, -1));
|
|
80
|
+
parent[keys[keys.length - 1]] = parseValue(raw.trim());
|
|
81
|
+
}
|
|
82
|
+
return root;
|
|
83
|
+
} catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ensure(obj, keys) {
|
|
89
|
+
let cur = obj;
|
|
90
|
+
for (const k of keys) {
|
|
91
|
+
if (cur[k] === undefined || typeof cur[k] !== "object" || cur[k] === null) cur[k] = {};
|
|
92
|
+
cur = Array.isArray(cur[k]) ? cur[k][cur[k].length - 1] ?? (cur[k][0] = {}) : cur[k];
|
|
93
|
+
}
|
|
94
|
+
return cur;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function splitKey(raw) {
|
|
98
|
+
const keys = [];
|
|
99
|
+
let i = 0;
|
|
100
|
+
const s = raw.trim();
|
|
101
|
+
while (i < s.length) {
|
|
102
|
+
while (s[i] === " " || s[i] === "\t") i++;
|
|
103
|
+
if (s[i] === '"' || s[i] === "'") {
|
|
104
|
+
const q = s[i];
|
|
105
|
+
let j = i + 1;
|
|
106
|
+
let key = "";
|
|
107
|
+
while (j < s.length && s[j] !== q) {
|
|
108
|
+
if (q === '"' && s[j] === "\\") {
|
|
109
|
+
key += s[j + 1] ?? "";
|
|
110
|
+
j += 2;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
key += s[j++];
|
|
114
|
+
}
|
|
115
|
+
keys.push(key);
|
|
116
|
+
i = j + 1;
|
|
117
|
+
} else {
|
|
118
|
+
let j = i;
|
|
119
|
+
while (j < s.length && s[j] !== ".") j++;
|
|
120
|
+
keys.push(s.slice(i, j).trim());
|
|
121
|
+
i = j;
|
|
122
|
+
}
|
|
123
|
+
while (s[i] === " " || s[i] === "\t") i++;
|
|
124
|
+
if (s[i] === ".") i++;
|
|
125
|
+
}
|
|
126
|
+
return keys.filter((k) => k !== "");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function stripComment(line) {
|
|
130
|
+
let quote = null;
|
|
131
|
+
for (let i = 0; i < line.length; i++) {
|
|
132
|
+
const c = line[i];
|
|
133
|
+
if (quote) {
|
|
134
|
+
if (c === "\\" && quote === '"') i++;
|
|
135
|
+
else if (c === quote) quote = null;
|
|
136
|
+
} else if (c === '"' || c === "'") quote = c;
|
|
137
|
+
else if (c === "#") return line.slice(0, i);
|
|
138
|
+
}
|
|
139
|
+
return line;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function findTopLevel(s, ch) {
|
|
143
|
+
let quote = null;
|
|
144
|
+
for (let i = 0; i < s.length; i++) {
|
|
145
|
+
const c = s[i];
|
|
146
|
+
if (quote) {
|
|
147
|
+
if (c === "\\" && quote === '"') i++;
|
|
148
|
+
else if (c === quote) quote = null;
|
|
149
|
+
} else if (c === '"' || c === "'") quote = c;
|
|
150
|
+
else if (c === ch) return i;
|
|
151
|
+
}
|
|
152
|
+
return -1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isComplete(raw) {
|
|
156
|
+
if ((raw.match(/"""/g) || []).length % 2 === 1) return false;
|
|
157
|
+
if ((raw.match(/'''/g) || []).length % 2 === 1) return false;
|
|
158
|
+
let depth = 0;
|
|
159
|
+
let quote = null;
|
|
160
|
+
for (let i = 0; i < raw.length; i++) {
|
|
161
|
+
const c = raw[i];
|
|
162
|
+
if (quote) {
|
|
163
|
+
if (c === "\\" && quote === '"') i++;
|
|
164
|
+
else if (c === quote) quote = null;
|
|
165
|
+
} else if (c === '"' || c === "'") quote = c;
|
|
166
|
+
else if (c === "[" || c === "{") depth++;
|
|
167
|
+
else if (c === "]" || c === "}") depth--;
|
|
168
|
+
}
|
|
169
|
+
return depth <= 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function splitTopLevel(inner) {
|
|
173
|
+
const parts = [];
|
|
174
|
+
let depth = 0;
|
|
175
|
+
let quote = null;
|
|
176
|
+
let start = 0;
|
|
177
|
+
for (let i = 0; i < inner.length; i++) {
|
|
178
|
+
const c = inner[i];
|
|
179
|
+
if (quote) {
|
|
180
|
+
if (c === "\\" && quote === '"') i++;
|
|
181
|
+
else if (c === quote) quote = null;
|
|
182
|
+
} else if (c === '"' || c === "'") quote = c;
|
|
183
|
+
else if (c === "[" || c === "{") depth++;
|
|
184
|
+
else if (c === "]" || c === "}") depth--;
|
|
185
|
+
else if (c === "," && depth === 0) {
|
|
186
|
+
parts.push(inner.slice(start, i));
|
|
187
|
+
start = i + 1;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
parts.push(inner.slice(start));
|
|
191
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function parseValue(raw) {
|
|
195
|
+
if (raw.startsWith('"""')) return raw.slice(3, raw.lastIndexOf('"""')).replace(/^\n/, "");
|
|
196
|
+
if (raw.startsWith("'''")) return raw.slice(3, raw.lastIndexOf("'''")).replace(/^\n/, "");
|
|
197
|
+
if (raw.startsWith('"')) {
|
|
198
|
+
try {
|
|
199
|
+
return JSON.parse(raw.slice(0, raw.lastIndexOf('"') + 1));
|
|
200
|
+
} catch {
|
|
201
|
+
return raw.slice(1, raw.lastIndexOf('"'));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (raw.startsWith("'")) return raw.slice(1, raw.lastIndexOf("'"));
|
|
205
|
+
if (raw === "true") return true;
|
|
206
|
+
if (raw === "false") return false;
|
|
207
|
+
if (/^[+-]?\d[\d_]*(\.\d+)?$/.test(raw)) return Number(raw.replace(/_/g, ""));
|
|
208
|
+
if (raw.startsWith("[")) {
|
|
209
|
+
return splitTopLevel(raw.slice(1, raw.lastIndexOf("]")).replace(/\n/g, " ")).map(parseValue);
|
|
210
|
+
}
|
|
211
|
+
if (raw.startsWith("{")) {
|
|
212
|
+
const obj = {};
|
|
213
|
+
for (const part of splitTopLevel(raw.slice(1, raw.lastIndexOf("}")))) {
|
|
214
|
+
const eq = findTopLevel(part, "=");
|
|
215
|
+
if (eq < 0) continue;
|
|
216
|
+
const keys = splitKey(part.slice(0, eq));
|
|
217
|
+
ensure(obj, keys.slice(0, -1))[keys[keys.length - 1]] = parseValue(part.slice(eq + 1).trim());
|
|
218
|
+
}
|
|
219
|
+
return obj;
|
|
220
|
+
}
|
|
221
|
+
return raw;
|
|
222
|
+
}
|
package/engine/paths.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Which files steer AI agents. Shared by the browser walker, the command
|
|
2
|
+
// line tool and the rule engine, so all three agree on what gets read.
|
|
3
|
+
|
|
4
|
+
export const SKIP_DIRS = new Set([
|
|
5
|
+
"node_modules", ".git", ".hg", ".svn", "dist", "build", "out", ".next", ".nuxt", ".svelte-kit",
|
|
6
|
+
".turbo", ".cache", ".parcel-cache", "coverage", "vendor", "target", ".venv", "venv",
|
|
7
|
+
"__pycache__", ".gradle", ".idea", ".vs", "bin", "obj", "Pods", "DerivedData", ".terraform",
|
|
8
|
+
".pnpm-store", ".yarn", "AppData", "Library", "Application Data", "$RECYCLE.BIN",
|
|
9
|
+
"System Volume Information", ".Trash", ".npm", ".cargo", ".rustup", ".m2", ".nuget",
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export const HOME_MARKERS = new Set([
|
|
13
|
+
".ssh", "AppData", "Library", "NTUSER.DAT", ".bashrc", ".zshrc", ".profile", "Downloads",
|
|
14
|
+
"Documents", "Desktop", ".config", ".local", "Pictures", "Music", "Videos",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
// Agent control files: read, masked, then sent.
|
|
18
|
+
export const CONTENT = [
|
|
19
|
+
/(^|\/)(claude|claude\.local|agents|agents\.override|gemini|grok)\.md$/i,
|
|
20
|
+
/(^|\/)\.claude\/(settings(\.local)?\.json|(commands|agents|skills|output-styles)\/.+\.md|hooks\/.+)$/i,
|
|
21
|
+
/(^|\/)\.mcp\.json$/i,
|
|
22
|
+
/(^|\/)\.claude\.json$/i,
|
|
23
|
+
/(^|\/)\.codex\/(config\.toml|.+\.md)$/i,
|
|
24
|
+
/(^|\/)\.cursor\/(rules\/.+\.mdc?|mcp\.json|.+\.md)$/i,
|
|
25
|
+
/(^|\/)\.cursorrules$/i,
|
|
26
|
+
/(^|\/)\.github\/(copilot-instructions\.md|(instructions|prompts|chatmodes|agents)\/.+\.md)$/i,
|
|
27
|
+
/(^|\/)\.vscode\/(mcp|settings)\.json$/i,
|
|
28
|
+
/(^|\/)\.gemini\/(settings\.json|.+\.md)$/i,
|
|
29
|
+
/(^|\/)opencode\.jsonc?$/i,
|
|
30
|
+
/(^|\/)\.opencode\/.+\.(md|json|jsonc)$/i,
|
|
31
|
+
/(^|\/)\.grok\/(settings\.json|.+\.md)$/i,
|
|
32
|
+
/(^|\/)\.windsurfrules$/i,
|
|
33
|
+
/(^|\/)\.windsurf\/(rules\/.+|mcp_config\.json)$/i,
|
|
34
|
+
/(^|\/)\.clinerules(\/.+)?$/i,
|
|
35
|
+
/(^|\/)\.roomodes$/i,
|
|
36
|
+
/(^|\/)\.roo\/.+\.(md|json)$/i,
|
|
37
|
+
/(^|\/)\.kiro\/(steering\/.+\.md|settings\/mcp\.json)$/i,
|
|
38
|
+
/(^|\/)\.amazonq\/(rules\/.+\.md|mcp\.json)$/i,
|
|
39
|
+
/(^|\/)\.continue\/.+\.(json|ya?ml|md)$/i,
|
|
40
|
+
/(^|\/)\.zed\/settings\.json$/i,
|
|
41
|
+
/(^|\/)\.junie\/guidelines\.md$/i,
|
|
42
|
+
/(^|\/)\.aider\.conf\.ya?ml$/i,
|
|
43
|
+
/^\.gitignore$/i,
|
|
44
|
+
/^package\.json$/i,
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
// Credential files: name and size only.
|
|
48
|
+
export const SENSITIVE = [
|
|
49
|
+
/(^|\/)\.env(\.[\w.-]+)?$/i,
|
|
50
|
+
/(^|\/)[^/]+\.(pem|key|p12|pfx|jks|keystore|ppk)$/i,
|
|
51
|
+
/(^|\/)id_(rsa|dsa|ecdsa|ed25519)$/i,
|
|
52
|
+
/(^|\/)\.(npmrc|pypirc|netrc|git-credentials)$/i,
|
|
53
|
+
/(^|\/)\.aws\/credentials$/i,
|
|
54
|
+
/(^|\/)\.docker\/config\.json$/i,
|
|
55
|
+
/(^|\/)\.kube\/config$/i,
|
|
56
|
+
/(^|\/)\.codex\/auth\.json$/i,
|
|
57
|
+
/(^|\/)\.claude\/\.credentials\.json$/i,
|
|
58
|
+
/(^|\/)\.grok\/user-settings\.json$/i,
|
|
59
|
+
/(^|\/)(credentials|secrets?|service[-_]?account[^/]*)\.json$/i,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export const DOWNLOADS_LIKE = /^(downloads?|desktop|temp|tmp)$/i;
|
|
63
|
+
|
|
64
|
+
// Dropping a tool folder itself (for example ~/.claude) keeps its name in
|
|
65
|
+
// the paths, so ".claude/settings.json" is still recognised.
|
|
66
|
+
export const TOOL_ROOT = /^\.(claude|codex|gemini|cursor|grok|opencode|windsurf|roo|kiro|amazonq|continue|zed|junie|github|vscode)$/i;
|
|
67
|
+
export const withToolRoot = (root, relPath) => (root && TOOL_ROOT.test(root) ? `${root}/${relPath}` : relPath);
|
|
68
|
+
|
|
69
|
+
export const LIMITS = {
|
|
70
|
+
maxEntries: 60000,
|
|
71
|
+
maxFiles: 300,
|
|
72
|
+
maxFileBytes: 400 * 1024,
|
|
73
|
+
maxTotalBytes: 4 * 1024 * 1024,
|
|
74
|
+
maxLooseMarkdown: 25,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function classifyPath(relPath, { looseMarkdown = false } = {}) {
|
|
78
|
+
if (SENSITIVE.some((re) => re.test(relPath))) return "sensitive";
|
|
79
|
+
if (CONTENT.some((re) => re.test(relPath))) return "content";
|
|
80
|
+
if (looseMarkdown && !relPath.includes("/") && /\.(md|mdc|txt)$/i.test(relPath)) return "loose";
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function isSkippedDir(name) {
|
|
85
|
+
return SKIP_DIRS.has(name);
|
|
86
|
+
}
|