@koinzhang/paseo-plugin-customize 0.1.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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/client/category-visibility.test.ts +26 -0
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +104 -0
- package/client/dropdown.tsx +139 -0
- package/client/entries.test.ts +50 -0
- package/client/entries.ts +47 -0
- package/client/entry-row.tsx +89 -0
- package/client/mechanism-card.tsx +75 -0
- package/client/preview-pane.tsx +101 -0
- package/client/provider-options.test.ts +31 -0
- package/client/provider-options.ts +37 -0
- package/client/query-policy.test.ts +57 -0
- package/client/query-policy.ts +20 -0
- package/client/route.ts +29 -0
- package/client/selection-settings.test.ts +16 -0
- package/client/slash-command.test.ts +94 -0
- package/client/slash-command.ts +36 -0
- package/client/surface.tsx +332 -0
- package/client/ui.tsx +265 -0
- package/client/use-app-language.ts +28 -0
- package/client/web.ts +111 -0
- package/index.client.tsx +57 -0
- package/index.server.ts +13 -0
- package/package.json +37 -0
- package/paseo-plugin.json +6 -0
- package/server/agent-plugins.ts +41 -0
- package/server/compatibility.test.ts +104 -0
- package/server/compatibility.ts +46 -0
- package/server/frontmatter.ts +49 -0
- package/server/glob.ts +46 -0
- package/server/handlers.ts +193 -0
- package/server/jsonc.ts +40 -0
- package/server/mcp.ts +87 -0
- package/server/parsers.test.ts +92 -0
- package/server/providers/acp.ts +186 -0
- package/server/providers/claude.ts +284 -0
- package/server/providers/codex.ts +219 -0
- package/server/providers/copilot.ts +116 -0
- package/server/providers/cursor.ts +194 -0
- package/server/providers/omp.ts +263 -0
- package/server/providers/opencode.ts +215 -0
- package/server/providers/pi.ts +102 -0
- package/server/providers.test.ts +306 -0
- package/server/scan-kit.ts +368 -0
- package/server/scan-snapshot.test.ts +56 -0
- package/server/scan-snapshot.ts +58 -0
- package/server/skill-aliases.ts +60 -0
- package/server/toml.ts +240 -0
- package/server/yaml-lite.ts +172 -0
- package/shared/acp-configs.ts +107 -0
- package/shared/category-visibility.ts +26 -0
- package/shared/compatibility.ts +6 -0
- package/shared/contracts.ts +116 -0
- package/shared/i18n.ts +293 -0
- package/shared/mechanisms.ts +380 -0
- package/shared/providers.ts +27 -0
- package/shared/selection-settings.ts +14 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
6
|
+
import type { Entry } from "../shared/contracts.ts";
|
|
7
|
+
import { cachedScanRpc, openRpc, previewRpc, scanRpc } from "../shared/contracts.ts";
|
|
8
|
+
import type { ProviderId } from "../shared/providers.ts";
|
|
9
|
+
import { parseJsonc } from "./jsonc.ts";
|
|
10
|
+
import { redactServer } from "./mcp.ts";
|
|
11
|
+
import { scanClaude } from "./providers/claude.ts";
|
|
12
|
+
import { scanCodex } from "./providers/codex.ts";
|
|
13
|
+
import { scanCopilot } from "./providers/copilot.ts";
|
|
14
|
+
import { scanCursor } from "./providers/cursor.ts";
|
|
15
|
+
import { scanOmp } from "./providers/omp.ts";
|
|
16
|
+
import { scanOpencode } from "./providers/opencode.ts";
|
|
17
|
+
import { scanPi } from "./providers/pi.ts";
|
|
18
|
+
import { scanAcp } from "./providers/acp.ts";
|
|
19
|
+
import { buildNestedIndex, fileSize, isDir, isFile, isRecord, readText, type NestedIndex, type ScanContext } from "./scan-kit.ts";
|
|
20
|
+
import { readSnapshot, writeSnapshot } from "./scan-snapshot.ts";
|
|
21
|
+
import { compatibilityFor } from "./compatibility.ts";
|
|
22
|
+
import { mergeSkillAliases } from "./skill-aliases.ts";
|
|
23
|
+
import { parseToml } from "./toml.ts";
|
|
24
|
+
import { parseYaml } from "./yaml-lite.ts";
|
|
25
|
+
|
|
26
|
+
const execFileAsync = promisify(execFile);
|
|
27
|
+
|
|
28
|
+
const SCANNERS: Record<ProviderId, (ctx: ScanContext) => Entry[]> = {
|
|
29
|
+
claude: scanClaude,
|
|
30
|
+
codex: scanCodex,
|
|
31
|
+
cursor: scanCursor,
|
|
32
|
+
copilot: scanCopilot,
|
|
33
|
+
opencode: scanOpencode,
|
|
34
|
+
pi: scanPi,
|
|
35
|
+
omp: scanOmp,
|
|
36
|
+
cline: (ctx) => scanAcp("cline", ctx),
|
|
37
|
+
"codebuddy-code": (ctx) => scanAcp("codebuddy-code", ctx),
|
|
38
|
+
gemini: (ctx) => scanAcp("gemini", ctx),
|
|
39
|
+
goose: (ctx) => scanAcp("goose", ctx),
|
|
40
|
+
grok: (ctx) => scanAcp("grok", ctx),
|
|
41
|
+
kilo: (ctx) => scanAcp("kilo", ctx),
|
|
42
|
+
kiro: (ctx) => scanAcp("kiro", ctx),
|
|
43
|
+
kimi: (ctx) => scanAcp("kimi", ctx),
|
|
44
|
+
"qwen-code": (ctx) => scanAcp("qwen-code", ctx),
|
|
45
|
+
traecli: (ctx) => scanAcp("traecli", ctx),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const PREVIEW_MAX_BYTES = 64 * 1024;
|
|
49
|
+
export const PREVIEW_MAX_LINES = 400;
|
|
50
|
+
const NESTED_TTL_MS = 15_000;
|
|
51
|
+
|
|
52
|
+
const nestedCache = new Map<string, { at: number; index: NestedIndex }>();
|
|
53
|
+
/** Paths returned by scans; preview / open only accept these. */
|
|
54
|
+
const allowed = new Set<string>();
|
|
55
|
+
const snapshotCandidates = new Map<string, Array<{ provider: ProviderId; projectRoot: string | null }>>();
|
|
56
|
+
|
|
57
|
+
function nestedIndex(root: string): NestedIndex {
|
|
58
|
+
const cached = nestedCache.get(root);
|
|
59
|
+
if (cached && Date.now() - cached.at < NESTED_TTL_MS) return cached.index;
|
|
60
|
+
const index = buildNestedIndex(root);
|
|
61
|
+
nestedCache.set(root, { at: Date.now(), index });
|
|
62
|
+
return index;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function scanProvider(provider: ProviderId, projectRoot: string | null, env: Pick<ScanContext, "home" | "env" | "platform">): Entry[] {
|
|
66
|
+
const root = projectRoot && isDir(projectRoot) ? path.resolve(projectRoot) : null;
|
|
67
|
+
const ctx: ScanContext = { ...env, projectRoot: root, nested: root ? nestedIndex(root) : null };
|
|
68
|
+
return mergeSkillAliases(provider, SCANNERS[provider](ctx));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function handleScan(input: RpcInput<typeof scanRpc>): Promise<RpcOutput<typeof scanRpc>> {
|
|
72
|
+
const home = homedir();
|
|
73
|
+
const entries = scanProvider(input.provider, input.projectRoot, { home, env: process.env, platform: process.platform });
|
|
74
|
+
const ctx: ScanContext = { home, env: process.env, platform: process.platform, projectRoot: input.projectRoot, nested: null };
|
|
75
|
+
for (const entry of entries) allowed.add(entry.path);
|
|
76
|
+
const result = {
|
|
77
|
+
provider: input.provider,
|
|
78
|
+
projectRoot: input.projectRoot,
|
|
79
|
+
home,
|
|
80
|
+
entries,
|
|
81
|
+
compatibility: compatibilityFor(input.provider, ctx),
|
|
82
|
+
scannedAt: new Date().toISOString(),
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
writeSnapshot(result);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error("Customize could not persist scan snapshot", error);
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function handleCachedScan(input: RpcInput<typeof cachedScanRpc>): RpcOutput<typeof cachedScanRpc> {
|
|
93
|
+
const cached = readSnapshot(input.provider, input.projectRoot);
|
|
94
|
+
const currentCompatibility = compatibilityFor(input.provider, {
|
|
95
|
+
home: homedir(), env: process.env, platform: process.platform, projectRoot: input.projectRoot, nested: null,
|
|
96
|
+
});
|
|
97
|
+
if (cached.snapshot) {
|
|
98
|
+
for (const entry of cached.snapshot.entries) {
|
|
99
|
+
const candidates = snapshotCandidates.get(entry.path) ?? [];
|
|
100
|
+
if (!candidates.some((candidate) => candidate.provider === input.provider && candidate.projectRoot === input.projectRoot)) {
|
|
101
|
+
candidates.push({ provider: input.provider, projectRoot: input.projectRoot });
|
|
102
|
+
}
|
|
103
|
+
snapshotCandidates.set(entry.path, candidates);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { ...cached, stale: cached.stale || cached.snapshot?.compatibility?.enabled !== currentCompatibility?.enabled };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function assertAllowed(p: string) {
|
|
110
|
+
if (allowed.has(p)) return;
|
|
111
|
+
for (const candidate of snapshotCandidates.get(p) ?? []) {
|
|
112
|
+
const entries = scanProvider(candidate.provider, candidate.projectRoot, { home: homedir(), env: process.env, platform: process.platform });
|
|
113
|
+
if (entries.some((entry) => entry.path === p)) {
|
|
114
|
+
for (const entry of entries) allowed.add(entry.path);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw new Error("Path is not part of a Customize scan");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** One MCP server's config, redacted, from a JSON / JSONC / TOML config file. */
|
|
122
|
+
export function mcpPreview(file: string, name: string): string | null {
|
|
123
|
+
const text = readText(file);
|
|
124
|
+
if (text == null) return null;
|
|
125
|
+
let data: unknown;
|
|
126
|
+
try {
|
|
127
|
+
data = file.endsWith(".toml") ? parseToml(text) : file.endsWith(".yaml") ? parseYaml(text) : parseJsonc(text);
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const candidates: unknown[] = [];
|
|
132
|
+
const pick = (value: unknown, key: string) => (isRecord(value) && isRecord(value[key]) ? value[key] : undefined);
|
|
133
|
+
if (isRecord(data)) {
|
|
134
|
+
for (const key of ["mcpServers", "mcp_servers", "mcp", "servers", "extensions"]) candidates.push(pick(pick(data, key), name));
|
|
135
|
+
if (Array.isArray(data.mcp_servers)) candidates.push(data.mcp_servers.find((entry) => isRecord(entry) && entry.name === name));
|
|
136
|
+
if (isRecord(data.projects)) for (const project of Object.values(data.projects)) candidates.push(pick(pick(project, "mcpServers"), name));
|
|
137
|
+
}
|
|
138
|
+
const config = candidates.find((candidate) => candidate !== undefined);
|
|
139
|
+
if (config === undefined) return null;
|
|
140
|
+
return JSON.stringify({ [name]: redactServer(config) }, null, 2);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function handlePreview(input: RpcInput<typeof previewRpc>): Promise<RpcOutput<typeof previewRpc>> {
|
|
144
|
+
assertAllowed(input.path);
|
|
145
|
+
const bytes = fileSize(input.path);
|
|
146
|
+
if (input.mcpName) {
|
|
147
|
+
const content = mcpPreview(input.path, input.mcpName);
|
|
148
|
+
return { path: input.path, kind: content == null ? "missing" : "mcp", content: content ?? "", truncated: false, bytes };
|
|
149
|
+
}
|
|
150
|
+
if (isDir(input.path)) return { path: input.path, kind: "directory", content: "", truncated: false, bytes: 0 };
|
|
151
|
+
if (!isFile(input.path)) return { path: input.path, kind: "missing", content: "", truncated: false, bytes: 0 };
|
|
152
|
+
if (input.path.endsWith(path.join("goose", "config.yaml"))) {
|
|
153
|
+
const data = parseYaml(readText(input.path, PREVIEW_MAX_BYTES) ?? "");
|
|
154
|
+
const content = JSON.stringify({
|
|
155
|
+
extensions: isRecord(data.extensions) ? Object.fromEntries(Object.entries(data.extensions).map(([name, config]) => [name, redactServer(config)])) : {},
|
|
156
|
+
slash_commands: Array.isArray(data.slash_commands) ? data.slash_commands : [],
|
|
157
|
+
}, null, 2);
|
|
158
|
+
return { path: input.path, kind: "text", content, truncated: bytes > PREVIEW_MAX_BYTES, bytes };
|
|
159
|
+
}
|
|
160
|
+
const raw = readText(input.path, PREVIEW_MAX_BYTES) ?? "";
|
|
161
|
+
const lines = raw.split("\n");
|
|
162
|
+
const truncated = bytes > PREVIEW_MAX_BYTES || lines.length > PREVIEW_MAX_LINES;
|
|
163
|
+
return { path: input.path, kind: "text", content: lines.slice(0, PREVIEW_MAX_LINES).join("\n"), truncated, bytes };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function which(command: string): Promise<boolean> {
|
|
167
|
+
try {
|
|
168
|
+
await execFileAsync(process.platform === "win32" ? "where" : "which", [command], { timeout: 3000 });
|
|
169
|
+
return true;
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export async function handleOpen(input: RpcInput<typeof openRpc>): Promise<RpcOutput<typeof openRpc>> {
|
|
176
|
+
assertAllowed(input.path);
|
|
177
|
+
const target = input.path;
|
|
178
|
+
if (process.platform === "darwin") {
|
|
179
|
+
await execFileAsync("open", input.reveal ? ["-R", target] : [target], { timeout: 10_000 }).catch(async (error: unknown) => {
|
|
180
|
+
// No app registered for the extension (e.g. `.mdc`, `.rules`): fall back to the default text editor.
|
|
181
|
+
if (input.reveal) throw error;
|
|
182
|
+
await execFileAsync("open", ["-t", target], { timeout: 10_000 });
|
|
183
|
+
});
|
|
184
|
+
} else if (process.platform === "win32") {
|
|
185
|
+
await execFileAsync("explorer.exe", input.reveal ? [`/select,${target}`] : [target], { timeout: 10_000 }).catch(() => {});
|
|
186
|
+
} else {
|
|
187
|
+
const opener = (await which("xdg-open")) ? "xdg-open" : "gio";
|
|
188
|
+
await execFileAsync(opener, opener === "gio" ? ["open", input.reveal ? path.dirname(target) : target] : [input.reveal ? path.dirname(target) : target], {
|
|
189
|
+
timeout: 10_000,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return { ok: true };
|
|
193
|
+
}
|
package/server/jsonc.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** JSON with comments and trailing commas (opencode.jsonc, VS Code-style configs). */
|
|
2
|
+
export function parseJsonc(source: string): unknown {
|
|
3
|
+
let out = "";
|
|
4
|
+
let i = 0;
|
|
5
|
+
let inString = false;
|
|
6
|
+
while (i < source.length) {
|
|
7
|
+
const ch = source[i]!;
|
|
8
|
+
const next = source[i + 1];
|
|
9
|
+
if (inString) {
|
|
10
|
+
out += ch;
|
|
11
|
+
if (ch === "\\") {
|
|
12
|
+
out += next ?? "";
|
|
13
|
+
i += 2;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (ch === '"') inString = false;
|
|
17
|
+
i++;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (ch === '"') {
|
|
21
|
+
inString = true;
|
|
22
|
+
out += ch;
|
|
23
|
+
i++;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (ch === "/" && next === "/") {
|
|
27
|
+
while (i < source.length && source[i] !== "\n") i++;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (ch === "/" && next === "*") {
|
|
31
|
+
i += 2;
|
|
32
|
+
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) i++;
|
|
33
|
+
i += 2;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
out += ch;
|
|
37
|
+
i++;
|
|
38
|
+
}
|
|
39
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
40
|
+
}
|
package/server/mcp.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Entry, Scope, Status } from "../shared/contracts.ts";
|
|
2
|
+
import { isRecord, type EntryInput } from "./scan-kit.ts";
|
|
3
|
+
|
|
4
|
+
const SECRET_KEY = /(token|secret|password|passwd|api[-_]?key|auth|bearer|credential|cookie|session)/i;
|
|
5
|
+
const MASK = "••••••";
|
|
6
|
+
|
|
7
|
+
function redactArg(arg: string, previous: string | undefined): string {
|
|
8
|
+
if (previous && /^--?[\w-]+$/.test(previous) && SECRET_KEY.test(previous)) return MASK;
|
|
9
|
+
const eq = /^(--?[\w-]+)=(.+)$/.exec(arg);
|
|
10
|
+
if (eq && SECRET_KEY.test(eq[1]!)) return `${eq[1]}=${MASK}`;
|
|
11
|
+
if (/^(sk|ghp|gho|xox[abp]|glpat|tai_pat)[-_][A-Za-z0-9_\-.]{8,}/.test(arg)) return MASK;
|
|
12
|
+
return arg.replace(/([?&](?:token|key|secret|access_token|api_key)=)[^&]+/gi, `$1${MASK}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function redactArgs(args: unknown): unknown {
|
|
16
|
+
if (!Array.isArray(args)) return args;
|
|
17
|
+
return args.map((arg, index) => (typeof arg === "string" ? redactArg(arg, args[index - 1] as string | undefined) : arg));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function maskValues(value: unknown): unknown {
|
|
21
|
+
if (!isRecord(value)) return value;
|
|
22
|
+
return Object.fromEntries(Object.keys(value).map((key) => [key, MASK]));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Server config safe to show: env / headers values masked, secret-looking args and URL params masked. */
|
|
26
|
+
export function redactServer(config: unknown): unknown {
|
|
27
|
+
if (!isRecord(config)) return config;
|
|
28
|
+
const out: Record<string, unknown> = {};
|
|
29
|
+
for (const [key, value] of Object.entries(config)) {
|
|
30
|
+
if (/^(env|envs|headers|http_headers|env_http_headers|environment)$/i.test(key)) out[key] = maskValues(value);
|
|
31
|
+
else if (key === "args") out[key] = redactArgs(value);
|
|
32
|
+
else if (key === "command" && Array.isArray(value)) out[key] = redactArgs(value);
|
|
33
|
+
else if ((key === "url" || key === "uri") && typeof value === "string") out[key] = redactArg(value, undefined);
|
|
34
|
+
else if (SECRET_KEY.test(key) && typeof value === "string") out[key] = MASK;
|
|
35
|
+
else out[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `{ transport, target }` for the list meta line. */
|
|
41
|
+
export function describeServer(config: unknown): { transport: string; target: string } {
|
|
42
|
+
if (!isRecord(config)) return { transport: "?", target: "" };
|
|
43
|
+
const url = typeof config.url === "string" ? config.url : typeof config.uri === "string" ? config.uri : typeof config.serverUrl === "string" ? config.serverUrl : undefined;
|
|
44
|
+
const type = typeof config.type === "string" ? config.type : typeof config.transport === "string" ? config.transport : undefined;
|
|
45
|
+
if (url) {
|
|
46
|
+
const safe = redactArg(url, undefined);
|
|
47
|
+
const transport = type && type !== "remote" ? type : "http";
|
|
48
|
+
return { transport, target: safe };
|
|
49
|
+
}
|
|
50
|
+
const rawCommand = config.command ?? config.cmd;
|
|
51
|
+
const command = Array.isArray(rawCommand) ? (rawCommand as unknown[]) : typeof rawCommand === "string" ? [rawCommand] : [];
|
|
52
|
+
const args = Array.isArray(config.args) ? (config.args as unknown[]) : [];
|
|
53
|
+
const parts = (redactArgs([...command, ...args]) as unknown[]).filter((part): part is string => typeof part === "string");
|
|
54
|
+
return { transport: type && type !== "local" ? type : "stdio", target: parts.join(" ") };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function mcpEntry(input: {
|
|
58
|
+
name: string;
|
|
59
|
+
config: unknown;
|
|
60
|
+
file: string;
|
|
61
|
+
source: string;
|
|
62
|
+
scope: Scope;
|
|
63
|
+
status: Status;
|
|
64
|
+
reason?: EntryInput["reason"];
|
|
65
|
+
tags?: Entry["tags"];
|
|
66
|
+
}): EntryInput {
|
|
67
|
+
const { transport, target } = describeServer(input.config);
|
|
68
|
+
return {
|
|
69
|
+
category: "mcp",
|
|
70
|
+
scope: input.scope,
|
|
71
|
+
name: input.name,
|
|
72
|
+
path: input.file,
|
|
73
|
+
source: input.source,
|
|
74
|
+
description: target,
|
|
75
|
+
status: input.status,
|
|
76
|
+
...(input.reason ? { reason: input.reason } : {}),
|
|
77
|
+
tags: input.tags ?? [],
|
|
78
|
+
mcp: { name: input.name, transport, target },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** `{ mcpServers: { … } }`-style map (Claude / Cursor / Copilot / OMP). */
|
|
83
|
+
export function serversOf(value: unknown, key = "mcpServers"): Array<[string, unknown]> {
|
|
84
|
+
if (!isRecord(value)) return [];
|
|
85
|
+
const map = value[key];
|
|
86
|
+
return isRecord(map) ? Object.entries(map) : [];
|
|
87
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { fmList, parseFrontmatter } from "./frontmatter.ts";
|
|
4
|
+
import { matchGlob } from "./glob.ts";
|
|
5
|
+
import { parseJsonc } from "./jsonc.ts";
|
|
6
|
+
import { describeServer, redactServer } from "./mcp.ts";
|
|
7
|
+
import { parseToml } from "./toml.ts";
|
|
8
|
+
import { parseYaml } from "./yaml-lite.ts";
|
|
9
|
+
|
|
10
|
+
test("toml: tables, dotted / quoted keys, arrays of tables, inline tables", () => {
|
|
11
|
+
const doc = parseToml(`
|
|
12
|
+
model = "gpt" # comment
|
|
13
|
+
[projects."/Users/me/repo"]
|
|
14
|
+
trust_level = "trusted"
|
|
15
|
+
|
|
16
|
+
[mcp_servers.github]
|
|
17
|
+
command = "npx"
|
|
18
|
+
args = ["-y", "server", 'x']
|
|
19
|
+
env = { TOKEN = "secret" }
|
|
20
|
+
enabled = false
|
|
21
|
+
|
|
22
|
+
[[skills.config]]
|
|
23
|
+
path = "/a/SKILL.md"
|
|
24
|
+
enabled = false
|
|
25
|
+
[[skills.config]]
|
|
26
|
+
path = "/b/SKILL.md"
|
|
27
|
+
`);
|
|
28
|
+
assert.equal(doc.model, "gpt");
|
|
29
|
+
assert.deepEqual(doc.projects, { "/Users/me/repo": { trust_level: "trusted" } });
|
|
30
|
+
const github = (doc.mcp_servers as Record<string, Record<string, unknown>>).github;
|
|
31
|
+
assert.deepEqual(github.args, ["-y", "server", "x"]);
|
|
32
|
+
assert.deepEqual(github.env, { TOKEN: "secret" });
|
|
33
|
+
assert.equal(github.enabled, false);
|
|
34
|
+
const config = (doc.skills as { config: Array<Record<string, unknown>> }).config;
|
|
35
|
+
assert.equal(config.length, 2);
|
|
36
|
+
assert.equal(config[0]?.enabled, false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("yaml-lite: maps, lists, inline lists, block scalars", () => {
|
|
40
|
+
const doc = parseYaml(`
|
|
41
|
+
name: demo
|
|
42
|
+
description: >
|
|
43
|
+
folded
|
|
44
|
+
text
|
|
45
|
+
globs: ["*.ts", "*.tsx"]
|
|
46
|
+
skills:
|
|
47
|
+
enableClaudeUser: true
|
|
48
|
+
ignoredSkills:
|
|
49
|
+
- foo
|
|
50
|
+
- "bar"
|
|
51
|
+
`);
|
|
52
|
+
assert.equal(doc.name, "demo");
|
|
53
|
+
assert.equal(doc.description, "folded text");
|
|
54
|
+
assert.deepEqual(doc.globs, ["*.ts", "*.tsx"]);
|
|
55
|
+
assert.deepEqual(doc.skills, { enableClaudeUser: true, ignoredSkills: ["foo", "bar"] });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("frontmatter: data, body, list joining", () => {
|
|
59
|
+
const { data, body } = parseFrontmatter("---\nname: x\npaths:\n - src/**\n - lib/**\n---\n# Title\n");
|
|
60
|
+
assert.equal(data.name, "x");
|
|
61
|
+
assert.equal(fmList(data, "paths"), "src/**, lib/**");
|
|
62
|
+
assert.equal(body.trim(), "# Title");
|
|
63
|
+
assert.deepEqual(parseFrontmatter("no frontmatter").data, {});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("jsonc: comments and trailing commas", () => {
|
|
67
|
+
assert.deepEqual(parseJsonc(`{ // c\n "a": [1, 2,], /* b */ "u": "http://x" }`), { a: [1, 2], u: "http://x" });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("glob: ** / * / ?", () => {
|
|
71
|
+
assert.ok(matchGlob("**/node_modules/**", "/a/node_modules/b/CLAUDE.md"));
|
|
72
|
+
assert.ok(matchGlob("src/*.ts", "src/a.ts"));
|
|
73
|
+
assert.ok(!matchGlob("src/*.ts", "src/a/b.ts"));
|
|
74
|
+
assert.ok(matchGlob("a?.md", "ab.md"));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("mcp redaction masks env / headers / secret args and URL params", () => {
|
|
78
|
+
const redacted = JSON.stringify(
|
|
79
|
+
redactServer({
|
|
80
|
+
command: "npx",
|
|
81
|
+
args: ["server", "--token", "abc123", "--api-key=xyz", "plain"],
|
|
82
|
+
env: { GITHUB_TOKEN: "ghp_real" },
|
|
83
|
+
headers: { Authorization: "Bearer real" },
|
|
84
|
+
url: "https://x.dev/mcp?key=real&mode=a",
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
for (const secret of ["abc123", "xyz", "ghp_real", "Bearer real", "key=real"]) assert.ok(!redacted.includes(secret), secret);
|
|
88
|
+
assert.ok(redacted.includes("plain"));
|
|
89
|
+
assert.ok(redacted.includes("GITHUB_TOKEN"));
|
|
90
|
+
assert.deepEqual(describeServer({ url: "https://x.dev/mcp" }).transport.length > 0, true);
|
|
91
|
+
assert.equal(describeServer({ command: "npx", args: ["-y", "srv"] }).transport, "stdio");
|
|
92
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ACP_CONFIGS, type AcpConfig, type AcpProviderId } from "../../shared/acp-configs.ts";
|
|
3
|
+
import { CATEGORIES, type Category, type Entry, type Scope } from "../../shared/contracts.ts";
|
|
4
|
+
import { fmList } from "../frontmatter.ts";
|
|
5
|
+
import { agentPluginManifest } from "../agent-plugins.ts";
|
|
6
|
+
import { mcpEntry, serversOf } from "../mcp.ts";
|
|
7
|
+
import { parseJsonc } from "../jsonc.ts";
|
|
8
|
+
import { parseToml } from "../toml.ts";
|
|
9
|
+
import { parseYaml } from "../yaml-lite.ts";
|
|
10
|
+
import {
|
|
11
|
+
EntrySink, findSkills, isDir, isFile, isRecord, listFiles, listNames, nestedWith, readMarkdown, readText, skillEntry, skillInvocation,
|
|
12
|
+
type ScanContext,
|
|
13
|
+
} from "../scan-kit.ts";
|
|
14
|
+
|
|
15
|
+
function configValue(file: string): unknown {
|
|
16
|
+
const text = readText(file);
|
|
17
|
+
if (!text) return undefined;
|
|
18
|
+
try { return file.endsWith(".toml") ? parseToml(text) : file.endsWith(".yaml") ? parseYaml(text) : parseJsonc(text); } catch { return undefined; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function mcpServers(value: unknown, provider: AcpProviderId): Array<[string, unknown]> {
|
|
22
|
+
if (provider === "grok") return serversOf(value, "mcp_servers");
|
|
23
|
+
if (provider === "kilo") return serversOf(value, "mcp");
|
|
24
|
+
if (provider === "goose") return serversOf(value, "extensions").filter(([, server]) => isRecord(server) && ["stdio", "streamable_http"].includes(String(server.type)));
|
|
25
|
+
if (provider === "traecli" && isRecord(value) && Array.isArray(value.mcp_servers)) {
|
|
26
|
+
return value.mcp_servers.filter((entry): entry is Record<string, unknown> => isRecord(entry) && typeof entry.name === "string").map((entry) => [entry.name as string, entry]);
|
|
27
|
+
}
|
|
28
|
+
return serversOf(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function rootFor(ctx: ScanContext, provider: AcpProviderId, scope: Scope): string | null {
|
|
32
|
+
if (scope === "project") return ctx.projectRoot;
|
|
33
|
+
if (provider === "kimi" && ctx.env.KIMI_CODE_HOME?.trim()) return ctx.env.KIMI_CODE_HOME.trim();
|
|
34
|
+
return ctx.home;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function resolveLocation(ctx: ScanContext, provider: AcpProviderId, scope: Scope, relative: string): string | null {
|
|
38
|
+
const root = rootFor(ctx, provider, scope);
|
|
39
|
+
if (!root) return null;
|
|
40
|
+
if (provider === "kimi" && scope === "user" && relative.startsWith(".kimi-code/") && ctx.env.KIMI_CODE_HOME?.trim()) {
|
|
41
|
+
return path.join(root, relative.slice(".kimi-code/".length));
|
|
42
|
+
}
|
|
43
|
+
if (provider === "kimi" && scope === "user" && relative.startsWith(".agents/")) return path.join(ctx.home, relative);
|
|
44
|
+
if (provider === "traecli" && scope === "user" && relative.endsWith("trae_cli.yaml")) {
|
|
45
|
+
if (ctx.platform === "win32") return path.join(ctx.home, "AppData", "Roaming", "trae_cli", "trae_cli.yaml");
|
|
46
|
+
if (ctx.platform === "linux") return path.join(ctx.env.XDG_CONFIG_HOME?.trim() || path.join(ctx.home, ".config"), "trae_cli", "trae_cli.yaml");
|
|
47
|
+
}
|
|
48
|
+
return path.join(root, relative);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** File-system evidence only; runtime selection, trust, and plugin enablement may differ. */
|
|
52
|
+
export function scanAcp(provider: AcpProviderId, ctx: ScanContext): Entry[] {
|
|
53
|
+
const config: AcpConfig = ACP_CONFIGS[provider];
|
|
54
|
+
const sink = new EntrySink(ctx);
|
|
55
|
+
if (provider === "gemini" && ctx.projectRoot) {
|
|
56
|
+
const manifest = path.join(ctx.projectRoot, "plugin.json");
|
|
57
|
+
const agentPlugin = agentPluginManifest(manifest);
|
|
58
|
+
if (agentPlugin) sink.add({ category: "plugins", scope: "project", name: path.basename(ctx.projectRoot), path: manifest, status: "conditional", reason: { code: "config", value: "Activation is not verified" }, agentPlugin });
|
|
59
|
+
}
|
|
60
|
+
for (const category of CATEGORIES) {
|
|
61
|
+
for (const scope of ["project", "user"] as const) {
|
|
62
|
+
const locations = config[category][scope] ?? [];
|
|
63
|
+
for (const relative of locations) {
|
|
64
|
+
const location = resolveLocation(ctx, provider, scope, relative);
|
|
65
|
+
if (!location) continue;
|
|
66
|
+
if (provider === "kimi" && category === "commands") continue; // Plugin manifests declare command roots.
|
|
67
|
+
if (category === "instructions") {
|
|
68
|
+
if (!isFile(location)) continue;
|
|
69
|
+
const doc = readMarkdown(location);
|
|
70
|
+
sink.add({ category, scope, name: path.basename(location), path: location, status: "auto", tags: [], ...(doc?.description ? { description: doc.description } : {}) });
|
|
71
|
+
} else if (category === "mcp") {
|
|
72
|
+
const value = configValue(location);
|
|
73
|
+
for (const [name, server] of mcpServers(value, provider)) {
|
|
74
|
+
const off = isRecord(server) && server.enabled === false;
|
|
75
|
+
sink.add(mcpEntry({ name, config: server, file: location, source: relative, scope, status: off ? "disabled" : "auto" }));
|
|
76
|
+
}
|
|
77
|
+
} else if (provider === "goose" && (category === "commands" || category === "plugins") && isFile(location)) {
|
|
78
|
+
const value = configValue(location);
|
|
79
|
+
if (isRecord(value)) {
|
|
80
|
+
const items = category === "commands" ? (Array.isArray(value.slash_commands) ? value.slash_commands : []) : Object.entries(isRecord(value.extensions) ? value.extensions : {}).map(([name, settings]) => ({ name, settings }));
|
|
81
|
+
for (const item of items) {
|
|
82
|
+
if (!isRecord(item)) continue;
|
|
83
|
+
const name = category === "commands" ? item.command : item.name;
|
|
84
|
+
if (typeof name !== "string") continue;
|
|
85
|
+
sink.add({ category, scope, name, path: location, source: relative, status: category === "plugins" && isRecord(item.settings) && item.settings.enabled === false ? "disabled" : "auto", tags: [] });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} else if (category === "skills") {
|
|
89
|
+
for (const skill of findSkills(location, { recursive: provider === "gemini" || provider === "grok" || provider === "qwen-code", maxDepth: 6, looseMarkdown: provider === "kimi" })) {
|
|
90
|
+
const invocation = skillInvocation(skill.doc);
|
|
91
|
+
sink.add({ ...skillEntry(skill, location, scope), status: invocation.status, ...(invocation.reason ? { reason: invocation.reason } : {}), tags: [...(skill.symlink ? ["symlink" as const] : []), ...invocation.tags] });
|
|
92
|
+
}
|
|
93
|
+
} else if (category === "plugins") {
|
|
94
|
+
if (isFile(location)) {
|
|
95
|
+
sink.add({ category, scope, name: path.basename(location), path: location, status: "conditional", reason: { code: "config", value: "Check installed and enabled state" }, tags: [] });
|
|
96
|
+
} else if (isDir(location)) {
|
|
97
|
+
if (provider === "codebuddy-code") {
|
|
98
|
+
let visited = 0;
|
|
99
|
+
const walk = (dir: string, depth: number) => {
|
|
100
|
+
if (depth > 4 || visited++ > 500) return;
|
|
101
|
+
const manifest = config.pluginManifests?.map((candidate) => path.join(dir, candidate)).find(isFile);
|
|
102
|
+
if (manifest) {
|
|
103
|
+
sink.add({ category, scope, name: path.basename(path.dirname(dir)), path: manifest, root: location, status: "conditional", reason: { code: "config", value: "Check enabledPlugins in settings" }, tags: [] });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
for (const child of listNames(dir)) if (isDir(path.join(dir, child))) walk(path.join(dir, child), depth + 1);
|
|
107
|
+
};
|
|
108
|
+
walk(location, 0);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
for (const name of listNames(location)) {
|
|
112
|
+
const dir = path.join(location, name);
|
|
113
|
+
if (provider === "cline" && isFile(dir) && /\.[cm]?[jt]s$/.test(name)) {
|
|
114
|
+
sink.add({ category, scope, name, path: dir, root: location, status: "conditional", reason: { code: "config", value: "Activation is not verified" }, tags: [] });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!isDir(dir)) continue;
|
|
118
|
+
const standardManifest = path.join(dir, "plugin.json");
|
|
119
|
+
const agentPlugin = provider === "gemini" ? agentPluginManifest(standardManifest) : null;
|
|
120
|
+
const manifest = agentPlugin ? standardManifest : config.pluginManifests?.map((candidate) => path.join(dir, candidate)).find(isFile);
|
|
121
|
+
if (!manifest && provider !== "kiro") continue;
|
|
122
|
+
const target = manifest ?? dir;
|
|
123
|
+
sink.add({ category, scope, name, path: target, root: location, status: "conditional", reason: { code: "config", value: "Activation is not verified" }, ...(agentPlugin ? { agentPlugin } : {}) });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
const extensions = category === "subagents" && (provider === "kiro" || provider === "qwen-code") ? [".md", ".json", ".yaml"] : category === "commands" && provider === "gemini" ? [".toml"] : category === "commands" && provider === "qwen-code" ? [".md", ".toml"] : [".md", ".mdc"];
|
|
128
|
+
const files = isFile(location) ? [location] : listFiles(location, extensions, true);
|
|
129
|
+
for (const file of files) {
|
|
130
|
+
if (category === "rules" && provider === "kiro" && path.basename(file) === "AGENTS.md") continue;
|
|
131
|
+
const doc = readMarkdown(file);
|
|
132
|
+
const paths = category === "rules" && doc ? fmList(doc.data, "paths") : null;
|
|
133
|
+
sink.add({ category: category as Category, scope, name: path.relative(location, file) || path.basename(file), path: file, root: location, status: paths ? "conditional" : "auto", ...(paths ? { reason: { code: "globs" as const, value: `paths: ${paths}` } } : {}), tags: [], ...(doc?.description ? { description: doc.description } : {}) });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (ctx.projectRoot) {
|
|
140
|
+
const nestedInstructions = provider === "gemini" ? ["GEMINI.md"]
|
|
141
|
+
: provider === "codebuddy-code" ? ["CODEBUDDY.md"]
|
|
142
|
+
: provider === "qwen-code" ? ["QWEN.md"]
|
|
143
|
+
: provider === "goose" ? ["AGENTS.md", ".goosehints"]
|
|
144
|
+
: ["grok", "kilo", "kiro", "kimi", "traecli"].includes(provider) ? ["AGENTS.md"] : [];
|
|
145
|
+
for (const name of nestedInstructions) for (const dir of nestedWith(ctx, name)) {
|
|
146
|
+
const file = path.join(dir, name);
|
|
147
|
+
if (isFile(file)) sink.add({ category: "instructions", scope: "project", name: path.relative(ctx.projectRoot, file), path: file, status: "conditional", reason: { code: "nestedDir", value: path.relative(ctx.projectRoot, dir) }, tags: ["nested"] });
|
|
148
|
+
}
|
|
149
|
+
if (provider === "gemini") {
|
|
150
|
+
const settings = [path.join(ctx.projectRoot, ".gemini", "settings.json"), path.join(ctx.home, ".gemini", "settings.json")].map(configValue);
|
|
151
|
+
const names = settings.flatMap((value) => {
|
|
152
|
+
const context = isRecord(value) && isRecord(value.context) ? value.context : null;
|
|
153
|
+
const filenames = context?.fileName;
|
|
154
|
+
return typeof filenames === "string" ? [filenames] : Array.isArray(filenames) ? filenames.filter((name): name is string => typeof name === "string") : [];
|
|
155
|
+
});
|
|
156
|
+
if (names.includes("AGENTS.md")) {
|
|
157
|
+
const file = path.join(ctx.projectRoot, "AGENTS.md");
|
|
158
|
+
if (isFile(file)) sink.add({ category: "instructions", scope: "project", name: "AGENTS.md", path: file, status: "auto", reason: { code: "config", value: "context.fileName" }, tags: [] });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (provider === "kimi") {
|
|
163
|
+
const managed = resolveLocation(ctx, provider, "user", ".kimi-code/plugins/managed");
|
|
164
|
+
if (managed) for (const name of listNames(managed)) {
|
|
165
|
+
const root = path.join(managed, name);
|
|
166
|
+
const manifest = configValue(path.join(root, "kimi.plugin.json"));
|
|
167
|
+
if (!isRecord(manifest)) continue;
|
|
168
|
+
for (const [category, key, fallback] of [["commands", "commands", null], ["subagents", "agents", "agents"], ["skills", "skills", "skills"]] as const) {
|
|
169
|
+
const declared = manifest[key];
|
|
170
|
+
const paths = typeof declared === "string" ? [declared] : Array.isArray(declared) ? declared.filter((item): item is string => typeof item === "string") : fallback ? [fallback] : [];
|
|
171
|
+
for (const relative of paths) {
|
|
172
|
+
const target = path.resolve(root, relative);
|
|
173
|
+
if (target !== root && !target.startsWith(`${root}${path.sep}`)) continue;
|
|
174
|
+
if (category === "skills") {
|
|
175
|
+
for (const skill of findSkills(target, { recursive: true })) sink.add({ ...skillEntry(skill, target, "user"), status: "conditional", reason: { code: "config", value: "Plugin activation" }, tags: [] });
|
|
176
|
+
} else {
|
|
177
|
+
for (const file of isFile(target) ? [target] : listFiles(target, [".md"], true)) {
|
|
178
|
+
sink.add({ category, scope: "user", name: `${name}:${path.basename(file, ".md")}`, path: file, root: target, status: "conditional", reason: { code: "config", value: "Plugin activation" }, tags: [] });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return sink.entries;
|
|
186
|
+
}
|