@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,284 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fmList } from "../frontmatter.ts";
|
|
3
|
+
import { matchGlob } from "../glob.ts";
|
|
4
|
+
import { mcpEntry, serversOf } from "../mcp.ts";
|
|
5
|
+
import {
|
|
6
|
+
EntrySink,
|
|
7
|
+
findSkills,
|
|
8
|
+
isDir,
|
|
9
|
+
isFile,
|
|
10
|
+
isRecord,
|
|
11
|
+
listFiles,
|
|
12
|
+
nestedWith,
|
|
13
|
+
parentDirs,
|
|
14
|
+
readJson,
|
|
15
|
+
readMarkdown,
|
|
16
|
+
skillEntry,
|
|
17
|
+
skillInvocation,
|
|
18
|
+
type ScanContext,
|
|
19
|
+
} from "../scan-kit.ts";
|
|
20
|
+
import type { Entry, Scope } from "../../shared/contracts.ts";
|
|
21
|
+
|
|
22
|
+
function managedDir(ctx: ScanContext): string {
|
|
23
|
+
if (ctx.platform === "darwin") return "/Library/Application Support/ClaudeCode";
|
|
24
|
+
if (ctx.platform === "win32") return "C:\\Program Files\\ClaudeCode";
|
|
25
|
+
return "/etc/claude-code";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ClaudeSettings {
|
|
29
|
+
claudeMdExcludes: string[];
|
|
30
|
+
skillOverrides: Record<string, string>;
|
|
31
|
+
enabledMcpjsonServers: string[];
|
|
32
|
+
disabledMcpjsonServers: string[];
|
|
33
|
+
enableAllProjectMcpServers: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function strings(value: unknown): string[] {
|
|
37
|
+
return Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** User → project → local settings merged (arrays concatenate, later scalars win). */
|
|
41
|
+
function readSettings(ctx: ScanContext, claudeJsonProject: Record<string, unknown> | undefined): ClaudeSettings {
|
|
42
|
+
const files = [path.join(ctx.home, ".claude", "settings.json")];
|
|
43
|
+
if (ctx.projectRoot) {
|
|
44
|
+
files.push(path.join(ctx.projectRoot, ".claude", "settings.json"), path.join(ctx.projectRoot, ".claude", "settings.local.json"));
|
|
45
|
+
}
|
|
46
|
+
files.push(path.join(managedDir(ctx), "managed-settings.json"));
|
|
47
|
+
const out: ClaudeSettings = {
|
|
48
|
+
claudeMdExcludes: [],
|
|
49
|
+
skillOverrides: {},
|
|
50
|
+
enabledMcpjsonServers: [],
|
|
51
|
+
disabledMcpjsonServers: [],
|
|
52
|
+
enableAllProjectMcpServers: false,
|
|
53
|
+
};
|
|
54
|
+
const layers = files.map(readJson).filter(isRecord);
|
|
55
|
+
if (claudeJsonProject) layers.unshift(claudeJsonProject);
|
|
56
|
+
for (const layer of layers) {
|
|
57
|
+
out.claudeMdExcludes.push(...strings(layer.claudeMdExcludes));
|
|
58
|
+
out.enabledMcpjsonServers.push(...strings(layer.enabledMcpjsonServers));
|
|
59
|
+
out.disabledMcpjsonServers.push(...strings(layer.disabledMcpjsonServers));
|
|
60
|
+
if (layer.enableAllProjectMcpServers === true) out.enableAllProjectMcpServers = true;
|
|
61
|
+
if (isRecord(layer.skillOverrides)) {
|
|
62
|
+
for (const [name, state] of Object.entries(layer.skillOverrides)) if (typeof state === "string") out.skillOverrides[name] = state;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function excluded(settings: ClaudeSettings, file: string): string | undefined {
|
|
69
|
+
return settings.claudeMdExcludes.find((pattern) => matchGlob(pattern, file));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function scanClaude(ctx: ScanContext): Entry[] {
|
|
73
|
+
const sink = new EntrySink(ctx);
|
|
74
|
+
const claudeJsonPath = path.join(ctx.home, ".claude.json");
|
|
75
|
+
const claudeJson = readJson(claudeJsonPath);
|
|
76
|
+
const projects = isRecord(claudeJson) && isRecord(claudeJson.projects) ? claudeJson.projects : {};
|
|
77
|
+
const projectState = ctx.projectRoot && isRecord(projects[ctx.projectRoot]) ? (projects[ctx.projectRoot] as Record<string, unknown>) : undefined;
|
|
78
|
+
const settings = readSettings(ctx, projectState);
|
|
79
|
+
const userDir = path.join(ctx.home, ".claude");
|
|
80
|
+
|
|
81
|
+
// Instructions ------------------------------------------------------------
|
|
82
|
+
const instruction = (file: string, scope: Scope, tags: Entry["tags"] = [], nestedDir?: string) => {
|
|
83
|
+
if (!isFile(file)) return false;
|
|
84
|
+
const doc = readMarkdown(file);
|
|
85
|
+
const skip = excluded(settings, file);
|
|
86
|
+
sink.add({
|
|
87
|
+
category: "instructions",
|
|
88
|
+
scope,
|
|
89
|
+
name: path.basename(file),
|
|
90
|
+
path: file,
|
|
91
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
92
|
+
status: skip ? "disabled" : nestedDir ? "conditional" : "auto",
|
|
93
|
+
...(skip
|
|
94
|
+
? { reason: { code: "config" as const, value: `claudeMdExcludes: ${skip}` } }
|
|
95
|
+
: nestedDir
|
|
96
|
+
? { reason: { code: "onDemand" as const, value: nestedDir } }
|
|
97
|
+
: {}),
|
|
98
|
+
tags,
|
|
99
|
+
});
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
instruction(path.join(managedDir(ctx), "CLAUDE.md"), "user", ["managed"]);
|
|
103
|
+
instruction(path.join(userDir, "CLAUDE.md"), "user");
|
|
104
|
+
|
|
105
|
+
let hasClaudeMd = false;
|
|
106
|
+
if (ctx.projectRoot) {
|
|
107
|
+
const chain = [ctx.projectRoot, ...parentDirs(ctx.projectRoot)];
|
|
108
|
+
for (const dir of chain) {
|
|
109
|
+
const tags: Entry["tags"] = dir === ctx.projectRoot ? [] : ["parent"];
|
|
110
|
+
for (const name of ["CLAUDE.md", path.join(".claude", "CLAUDE.md")]) {
|
|
111
|
+
if (instruction(path.join(dir, name), "project", tags)) hasClaudeMd = true;
|
|
112
|
+
}
|
|
113
|
+
if (instruction(path.join(dir, "CLAUDE.local.md"), "project", [...tags, "local"])) hasClaudeMd = true;
|
|
114
|
+
}
|
|
115
|
+
for (const dir of chain) {
|
|
116
|
+
const agents = path.join(dir, "AGENTS.md");
|
|
117
|
+
if (!isFile(agents)) continue;
|
|
118
|
+
const doc = readMarkdown(agents);
|
|
119
|
+
sink.add({
|
|
120
|
+
category: "instructions",
|
|
121
|
+
scope: "project",
|
|
122
|
+
name: "AGENTS.md",
|
|
123
|
+
path: agents,
|
|
124
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
125
|
+
status: hasClaudeMd ? "inactive" : "auto",
|
|
126
|
+
...(hasClaudeMd ? { reason: { code: "shadowedBy" as const, value: "CLAUDE.md" } } : {}),
|
|
127
|
+
tags: dir === ctx.projectRoot ? [] : ["parent"],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
for (const dir of nestedWith(ctx, "CLAUDE.md")) instruction(path.join(dir, "CLAUDE.md"), "project", ["nested"], path.relative(ctx.projectRoot, dir));
|
|
131
|
+
for (const dir of nestedWith(ctx, "CLAUDE.local.md")) {
|
|
132
|
+
instruction(path.join(dir, "CLAUDE.local.md"), "project", ["nested", "local"], path.relative(ctx.projectRoot, dir));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Rules -------------------------------------------------------------------
|
|
137
|
+
const rules = (root: string, scope: Scope, nestedDir?: string) => {
|
|
138
|
+
for (const file of listFiles(root, [".md"], true)) {
|
|
139
|
+
const doc = readMarkdown(file);
|
|
140
|
+
const paths = doc ? fmList(doc.data, "paths") : undefined;
|
|
141
|
+
sink.add({
|
|
142
|
+
category: "rules",
|
|
143
|
+
scope,
|
|
144
|
+
name: path.relative(root, file),
|
|
145
|
+
path: file,
|
|
146
|
+
root,
|
|
147
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
148
|
+
status: paths || nestedDir ? "conditional" : "auto",
|
|
149
|
+
reason: paths ? { code: "globs", value: `paths: ${paths}` } : nestedDir ? { code: "onDemand", value: nestedDir } : { code: "always" },
|
|
150
|
+
tags: nestedDir ? ["nested"] : [],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
rules(path.join(userDir, "rules"), "user");
|
|
155
|
+
if (ctx.projectRoot) {
|
|
156
|
+
rules(path.join(ctx.projectRoot, ".claude", "rules"), "project");
|
|
157
|
+
for (const dir of nestedWith(ctx, ".claude")) {
|
|
158
|
+
if (isDir(path.join(dir, ".claude", "rules"))) rules(path.join(dir, ".claude", "rules"), "project", path.relative(ctx.projectRoot, dir));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Skills ------------------------------------------------------------------
|
|
163
|
+
const skills = (root: string, scope: Scope, nestedDir?: string) => {
|
|
164
|
+
for (const skill of findSkills(root, { recursive: false, skip: [".trash"] })) {
|
|
165
|
+
const base = skillEntry(skill, root, scope);
|
|
166
|
+
const invocation = skillInvocation(skill.doc);
|
|
167
|
+
const override = settings.skillOverrides[skill.name];
|
|
168
|
+
const tags = [...(base.tags ?? []), ...invocation.tags];
|
|
169
|
+
if (skill.dir.includes(`${path.sep}skills${path.sep}synced${path.sep}`)) tags.push("synced");
|
|
170
|
+
if (nestedDir) tags.push("nested");
|
|
171
|
+
if (override === "off") {
|
|
172
|
+
sink.add({ ...base, tags, status: "disabled", reason: { code: "config", value: `skillOverrides: "off"` } });
|
|
173
|
+
} else if (override === "user-invocable-only") {
|
|
174
|
+
sink.add({ ...base, tags, status: "manual", reason: { code: "config", value: `skillOverrides: "user-invocable-only"` } });
|
|
175
|
+
} else if (invocation.status === "manual") {
|
|
176
|
+
sink.add({ ...base, tags, status: "manual", ...(invocation.reason ? { reason: invocation.reason } : {}) });
|
|
177
|
+
} else if (nestedDir) {
|
|
178
|
+
sink.add({ ...base, tags, status: "conditional", reason: { code: "onDemand", value: nestedDir } });
|
|
179
|
+
} else {
|
|
180
|
+
if (override === "name-only") tags.push("nameOnly");
|
|
181
|
+
sink.add({ ...base, tags, status: "auto" });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// `synced/` holds claude.ai skills one level deeper.
|
|
185
|
+
if (!nestedDir && scope === "user" && isDir(path.join(root, "synced"))) {
|
|
186
|
+
for (const skill of findSkills(path.join(root, "synced"), { recursive: false })) {
|
|
187
|
+
const invocation = skillInvocation(skill.doc);
|
|
188
|
+
sink.add({ ...skillEntry(skill, root, scope), status: invocation.status, ...(invocation.reason ? { reason: invocation.reason } : {}), tags: ["synced", ...invocation.tags] });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const commands = (root: string, scope: Scope) => {
|
|
193
|
+
for (const file of listFiles(root, [".md"], true)) {
|
|
194
|
+
const doc = readMarkdown(file);
|
|
195
|
+
const manual = doc?.data["disable-model-invocation"] === true;
|
|
196
|
+
sink.add({
|
|
197
|
+
category: "skills",
|
|
198
|
+
scope,
|
|
199
|
+
name: `/${path.relative(root, file).replace(/\.md$/i, "").split(path.sep).join(":")}`,
|
|
200
|
+
path: file,
|
|
201
|
+
root,
|
|
202
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
203
|
+
status: manual ? "manual" : "auto",
|
|
204
|
+
...(manual ? { reason: { code: "frontmatter" as const, value: "disable-model-invocation: true" } } : {}),
|
|
205
|
+
tags: ["command"],
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
skills(path.join(managedDir(ctx), ".claude", "skills"), "user");
|
|
210
|
+
skills(path.join(userDir, "skills"), "user");
|
|
211
|
+
commands(path.join(userDir, "commands"), "user");
|
|
212
|
+
if (ctx.projectRoot) {
|
|
213
|
+
skills(path.join(ctx.projectRoot, ".claude", "skills"), "project");
|
|
214
|
+
commands(path.join(ctx.projectRoot, ".claude", "commands"), "project");
|
|
215
|
+
for (const dir of nestedWith(ctx, ".claude")) {
|
|
216
|
+
const root = path.join(dir, ".claude", "skills");
|
|
217
|
+
if (isDir(root)) skills(root, "project", path.relative(ctx.projectRoot, dir));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// MCP ---------------------------------------------------------------------
|
|
222
|
+
const disabledHere = new Set(projectState ? strings(projectState.disabledMcpServers) : []);
|
|
223
|
+
for (const [name, config] of serversOf(claudeJson)) {
|
|
224
|
+
const off = disabledHere.has(name);
|
|
225
|
+
sink.add(
|
|
226
|
+
mcpEntry({
|
|
227
|
+
name,
|
|
228
|
+
config,
|
|
229
|
+
file: claudeJsonPath,
|
|
230
|
+
source: "~/.claude.json → mcpServers",
|
|
231
|
+
scope: "user",
|
|
232
|
+
status: off ? "disabled" : "auto",
|
|
233
|
+
...(off ? { reason: { code: "config", value: "disabledMcpServers" } } : {}),
|
|
234
|
+
}),
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
if (projectState) {
|
|
238
|
+
for (const [name, config] of serversOf(projectState)) {
|
|
239
|
+
const off = disabledHere.has(name);
|
|
240
|
+
sink.add(
|
|
241
|
+
mcpEntry({
|
|
242
|
+
name,
|
|
243
|
+
config,
|
|
244
|
+
file: claudeJsonPath,
|
|
245
|
+
source: "~/.claude.json → projects (local)",
|
|
246
|
+
scope: "project",
|
|
247
|
+
status: off ? "disabled" : "auto",
|
|
248
|
+
...(off ? { reason: { code: "config", value: "disabledMcpServers" } } : {}),
|
|
249
|
+
tags: ["local"],
|
|
250
|
+
}),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (ctx.projectRoot) {
|
|
255
|
+
const file = path.join(ctx.projectRoot, ".mcp.json");
|
|
256
|
+
for (const [name, config] of serversOf(readJson(file))) {
|
|
257
|
+
const rejected = settings.disabledMcpjsonServers.includes(name);
|
|
258
|
+
const approved = settings.enableAllProjectMcpServers || settings.enabledMcpjsonServers.includes(name);
|
|
259
|
+
sink.add(
|
|
260
|
+
mcpEntry({
|
|
261
|
+
name,
|
|
262
|
+
config,
|
|
263
|
+
file,
|
|
264
|
+
source: ".mcp.json",
|
|
265
|
+
scope: "project",
|
|
266
|
+
status: rejected ? "disabled" : disabledHere.has(name) ? "disabled" : approved ? "auto" : "pending",
|
|
267
|
+
reason: rejected
|
|
268
|
+
? { code: "config", value: "disabledMcpjsonServers" }
|
|
269
|
+
: disabledHere.has(name)
|
|
270
|
+
? { code: "config", value: "disabledMcpServers" }
|
|
271
|
+
: approved
|
|
272
|
+
? { code: "config", value: settings.enableAllProjectMcpServers ? "enableAllProjectMcpServers" : "enabledMcpjsonServers" }
|
|
273
|
+
: { code: "needsApproval" },
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const managedMcp = path.join(managedDir(ctx), "managed-mcp.json");
|
|
279
|
+
for (const [name, config] of serversOf(readJson(managedMcp))) {
|
|
280
|
+
sink.add(mcpEntry({ name, config, file: managedMcp, source: "managed-mcp.json", scope: "user", status: "auto", tags: ["managed"] }));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return sink.entries;
|
|
284
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { mcpEntry } from "../mcp.ts";
|
|
3
|
+
import { agentPluginManifest } from "../agent-plugins.ts";
|
|
4
|
+
import {
|
|
5
|
+
EntrySink,
|
|
6
|
+
ancestors,
|
|
7
|
+
fileSize,
|
|
8
|
+
findSkills,
|
|
9
|
+
isDir,
|
|
10
|
+
isFile,
|
|
11
|
+
isRecord,
|
|
12
|
+
listFiles,
|
|
13
|
+
listNames,
|
|
14
|
+
nestedWith,
|
|
15
|
+
readMarkdown,
|
|
16
|
+
readText,
|
|
17
|
+
skillEntry,
|
|
18
|
+
type ScanContext,
|
|
19
|
+
} from "../scan-kit.ts";
|
|
20
|
+
import { parseToml } from "../toml.ts";
|
|
21
|
+
import type { Entry, Scope } from "../../shared/contracts.ts";
|
|
22
|
+
|
|
23
|
+
const DEFAULT_DOC_MAX_BYTES = 32 * 1024;
|
|
24
|
+
|
|
25
|
+
function readToml(file: string): Record<string, unknown> {
|
|
26
|
+
const text = readText(file);
|
|
27
|
+
if (text == null) return {};
|
|
28
|
+
try {
|
|
29
|
+
return parseToml(text);
|
|
30
|
+
} catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function codexHome(ctx: ScanContext): string {
|
|
36
|
+
return ctx.env.CODEX_HOME?.trim() || path.join(ctx.home, ".codex");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isTrusted(config: Record<string, unknown>, projectRoot: string): boolean {
|
|
40
|
+
const projects = isRecord(config.projects) ? config.projects : {};
|
|
41
|
+
return ancestors(projectRoot).some((dir) => {
|
|
42
|
+
const entry = projects[dir];
|
|
43
|
+
return isRecord(entry) && entry.trust_level === "trusted";
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** `agents/openai.yaml` → `policy.allow_implicit_invocation: false`. */
|
|
48
|
+
function implicitInvocationOff(skillDir: string): boolean {
|
|
49
|
+
const text = readText(path.join(skillDir, "agents", "openai.yaml"), 16 * 1024);
|
|
50
|
+
if (!text) return false;
|
|
51
|
+
return /^\s*allow_implicit_invocation\s*:\s*false\b/m.test(text);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function scanCodex(ctx: ScanContext): Entry[] {
|
|
55
|
+
const sink = new EntrySink(ctx);
|
|
56
|
+
const home = codexHome(ctx);
|
|
57
|
+
const userConfigPath = path.join(home, "config.toml");
|
|
58
|
+
const userConfig = readToml(userConfigPath);
|
|
59
|
+
const projectConfigPath = ctx.projectRoot ? path.join(ctx.projectRoot, ".codex", "config.toml") : null;
|
|
60
|
+
const trusted = ctx.projectRoot ? isTrusted(userConfig, ctx.projectRoot) : false;
|
|
61
|
+
const projectConfig = projectConfigPath && trusted ? readToml(projectConfigPath) : {};
|
|
62
|
+
const merged = { ...userConfig, ...projectConfig };
|
|
63
|
+
const fallbacks = Array.isArray(merged.project_doc_fallback_filenames)
|
|
64
|
+
? merged.project_doc_fallback_filenames.filter((name): name is string => typeof name === "string")
|
|
65
|
+
: [];
|
|
66
|
+
const maxBytes = typeof merged.project_doc_max_bytes === "number" ? merged.project_doc_max_bytes : DEFAULT_DOC_MAX_BYTES;
|
|
67
|
+
|
|
68
|
+
const disabledSkills = new Set<string>();
|
|
69
|
+
const skillsTable = isRecord(userConfig.skills) ? userConfig.skills : {};
|
|
70
|
+
if (Array.isArray(skillsTable.config)) {
|
|
71
|
+
for (const item of skillsTable.config) {
|
|
72
|
+
if (isRecord(item) && typeof item.path === "string" && item.enabled === false) disabledSkills.add(path.resolve(item.path));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Instructions ------------------------------------------------------------
|
|
77
|
+
const pickDoc = (dir: string, names: readonly string[]) => names.map((name) => path.join(dir, name)).filter((file) => isFile(file) && fileSize(file) > 0);
|
|
78
|
+
const addDocs = (dir: string, scope: Scope, names: readonly string[], extra: Partial<Pick<Entry, "status" | "reason" | "tags">> = {}) => {
|
|
79
|
+
const found = pickDoc(dir, names);
|
|
80
|
+
found.forEach((file, index) => {
|
|
81
|
+
const doc = readMarkdown(file);
|
|
82
|
+
const oversize = fileSize(file) > maxBytes;
|
|
83
|
+
const shadowed = index > 0;
|
|
84
|
+
sink.add({
|
|
85
|
+
category: "instructions",
|
|
86
|
+
scope,
|
|
87
|
+
name: path.basename(file),
|
|
88
|
+
path: file,
|
|
89
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
90
|
+
status: shadowed ? "inactive" : extra.status ?? "auto",
|
|
91
|
+
...(shadowed
|
|
92
|
+
? { reason: { code: "shadowedBy" as const, value: path.basename(found[0]!) } }
|
|
93
|
+
: oversize
|
|
94
|
+
? { reason: { code: "oversize" as const, value: `project_doc_max_bytes = ${maxBytes}` } }
|
|
95
|
+
: extra.reason
|
|
96
|
+
? { reason: extra.reason }
|
|
97
|
+
: {}),
|
|
98
|
+
tags: extra.tags ?? [],
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
addDocs(home, "user", ["AGENTS.override.md", "AGENTS.md"]);
|
|
103
|
+
if (ctx.projectRoot) {
|
|
104
|
+
const docNames = ["AGENTS.override.md", "AGENTS.md", ...fallbacks];
|
|
105
|
+
addDocs(ctx.projectRoot, "project", docNames);
|
|
106
|
+
const nestedDirs = new Set(docNames.flatMap((name) => nestedWith(ctx, name)));
|
|
107
|
+
for (const dir of [...nestedDirs].sort()) {
|
|
108
|
+
addDocs(dir, "project", docNames, {
|
|
109
|
+
status: "conditional",
|
|
110
|
+
reason: { code: "nestedDir", value: path.relative(ctx.projectRoot, dir) },
|
|
111
|
+
tags: ["nested"],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Rules -------------------------------------------------------------------
|
|
117
|
+
const rules = (root: string, scope: Scope, active: boolean) => {
|
|
118
|
+
for (const file of listFiles(root, [".rules"], false)) {
|
|
119
|
+
const text = readText(file, 256 * 1024) ?? "";
|
|
120
|
+
const count = (text.match(/\bprefix_rule\s*\(/g) ?? []).length;
|
|
121
|
+
sink.add({
|
|
122
|
+
category: "rules",
|
|
123
|
+
scope,
|
|
124
|
+
name: path.basename(file),
|
|
125
|
+
path: file,
|
|
126
|
+
root,
|
|
127
|
+
description: `${count} prefix_rule`,
|
|
128
|
+
status: active ? "auto" : "inactive",
|
|
129
|
+
...(active ? {} : { reason: { code: "untrusted" as const } }),
|
|
130
|
+
tags: scope === "project" ? ["trust"] : [],
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
rules(path.join(home, "rules"), "user", true);
|
|
135
|
+
if (ctx.projectRoot) rules(path.join(ctx.projectRoot, ".codex", "rules"), "project", trusted);
|
|
136
|
+
|
|
137
|
+
// Skills ------------------------------------------------------------------
|
|
138
|
+
const skills = (root: string, scope: Scope, tags: Entry["tags"] = [], gate?: Pick<Entry, "status" | "reason">) => {
|
|
139
|
+
for (const skill of findSkills(root, { recursive: true, maxDepth: 6 })) {
|
|
140
|
+
const base = skillEntry(skill, root, scope);
|
|
141
|
+
const allTags = [...(base.tags ?? []), ...tags];
|
|
142
|
+
if (disabledSkills.has(path.resolve(skill.file))) {
|
|
143
|
+
sink.add({ ...base, tags: allTags, status: "disabled", reason: { code: "config", value: "[[skills.config]] enabled = false" } });
|
|
144
|
+
} else if (gate) {
|
|
145
|
+
sink.add({ ...base, tags: allTags, status: gate.status, ...(gate.reason ? { reason: gate.reason } : {}) });
|
|
146
|
+
} else if (implicitInvocationOff(skill.dir)) {
|
|
147
|
+
sink.add({ ...base, tags: allTags, status: "manual", reason: { code: "config", value: "agents/openai.yaml allow_implicit_invocation: false" } });
|
|
148
|
+
} else {
|
|
149
|
+
sink.add({ ...base, tags: allTags, status: "auto" });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
if (ctx.projectRoot) {
|
|
154
|
+
skills(path.join(ctx.projectRoot, ".agents", "skills"), "project");
|
|
155
|
+
skills(path.join(ctx.projectRoot, ".codex", "skills"), "project", ["trust"], trusted ? undefined : { status: "inactive", reason: { code: "untrusted" } });
|
|
156
|
+
for (const dir of nestedWith(ctx, ".agents")) {
|
|
157
|
+
const root = path.join(dir, ".agents", "skills");
|
|
158
|
+
if (isDir(root)) {
|
|
159
|
+
skills(root, "project", ["nested"], { status: "conditional", reason: { code: "nestedDir", value: path.relative(ctx.projectRoot, dir) } });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
skills(path.join(ctx.home, ".agents", "skills"), "user");
|
|
164
|
+
skills(path.join(home, "skills"), "user", ["deprecated"]);
|
|
165
|
+
skills(path.join(home, "skills", ".system"), "user", ["system"]);
|
|
166
|
+
skills("/etc/codex/skills", "user", ["managed"]);
|
|
167
|
+
|
|
168
|
+
// MCP ---------------------------------------------------------------------
|
|
169
|
+
const servers = (config: Record<string, unknown>, file: string, scope: Scope, active: boolean) => {
|
|
170
|
+
const map = isRecord(config.mcp_servers) ? config.mcp_servers : {};
|
|
171
|
+
for (const [name, server] of Object.entries(map)) {
|
|
172
|
+
const off = isRecord(server) && server.enabled === false;
|
|
173
|
+
sink.add(
|
|
174
|
+
mcpEntry({
|
|
175
|
+
name,
|
|
176
|
+
config: server,
|
|
177
|
+
file,
|
|
178
|
+
source: `${scope === "user" ? "$CODEX_HOME" : ".codex"}/config.toml → mcp_servers`,
|
|
179
|
+
scope,
|
|
180
|
+
status: !active ? "inactive" : off ? "disabled" : "auto",
|
|
181
|
+
...(!active ? { reason: { code: "untrusted" } } : off ? { reason: { code: "config", value: "enabled = false" } } : {}),
|
|
182
|
+
tags: scope === "project" ? ["trust"] : [],
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
servers(userConfig, userConfigPath, "user", true);
|
|
188
|
+
if (projectConfigPath && isFile(projectConfigPath)) servers(readToml(projectConfigPath), projectConfigPath, "project", trusted);
|
|
189
|
+
|
|
190
|
+
// Plugins ---------------------------------------------------------------
|
|
191
|
+
const addPlugin = (root: string, scope: Scope, source?: string, name = path.basename(root)) => {
|
|
192
|
+
const manifest = path.join(root, "plugin.json");
|
|
193
|
+
const fallback = path.join(root, ".codex-plugin", "plugin.json");
|
|
194
|
+
const file = isFile(manifest) ? manifest : fallback;
|
|
195
|
+
if (!isFile(file)) return;
|
|
196
|
+
sink.add({ category: "plugins", scope, name, path: file, ...(source ? { root: source } : {}), status: "conditional", reason: { code: "config", value: "Activation is not verified" }, agentPlugin: agentPluginManifest(manifest) ?? undefined });
|
|
197
|
+
};
|
|
198
|
+
if (ctx.projectRoot) addPlugin(ctx.projectRoot, "project");
|
|
199
|
+
const pluginsRoot = path.join(home, "plugins");
|
|
200
|
+
for (const name of listNames(pluginsRoot)) {
|
|
201
|
+
const dir = path.join(pluginsRoot, name);
|
|
202
|
+
if (isDir(dir)) addPlugin(dir, "user", pluginsRoot);
|
|
203
|
+
}
|
|
204
|
+
const cacheRoot = path.join(pluginsRoot, "cache");
|
|
205
|
+
for (const source of listNames(cacheRoot)) {
|
|
206
|
+
const sourceDir = path.join(cacheRoot, source);
|
|
207
|
+
if (!isDir(sourceDir)) continue;
|
|
208
|
+
for (const name of listNames(sourceDir)) {
|
|
209
|
+
const pluginDir = path.join(sourceDir, name);
|
|
210
|
+
if (!isDir(pluginDir)) continue;
|
|
211
|
+
for (const version of listNames(pluginDir)) {
|
|
212
|
+
const versionDir = path.join(pluginDir, version);
|
|
213
|
+
if (isDir(versionDir)) addPlugin(versionDir, "user", sourceDir, name);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return sink.entries;
|
|
219
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fmList } from "../frontmatter.ts";
|
|
3
|
+
import { mcpEntry, serversOf } from "../mcp.ts";
|
|
4
|
+
import {
|
|
5
|
+
EntrySink,
|
|
6
|
+
findSkills,
|
|
7
|
+
isFile,
|
|
8
|
+
listFiles,
|
|
9
|
+
parentDirs,
|
|
10
|
+
readJson,
|
|
11
|
+
readMarkdown,
|
|
12
|
+
skillEntry,
|
|
13
|
+
skillInvocation,
|
|
14
|
+
type ScanContext,
|
|
15
|
+
} from "../scan-kit.ts";
|
|
16
|
+
import type { Entry, Scope } from "../../shared/contracts.ts";
|
|
17
|
+
|
|
18
|
+
export function scanCopilot(ctx: ScanContext): Entry[] {
|
|
19
|
+
const sink = new EntrySink(ctx);
|
|
20
|
+
const home = ctx.env.COPILOT_HOME?.trim() || path.join(ctx.home, ".copilot");
|
|
21
|
+
|
|
22
|
+
// Instructions ------------------------------------------------------------
|
|
23
|
+
const instruction = (file: string, scope: Scope) => {
|
|
24
|
+
if (!isFile(file)) return;
|
|
25
|
+
const doc = readMarkdown(file);
|
|
26
|
+
sink.add({
|
|
27
|
+
category: "instructions",
|
|
28
|
+
scope,
|
|
29
|
+
name: path.relative(scope === "project" && ctx.projectRoot ? ctx.projectRoot : home, file),
|
|
30
|
+
path: file,
|
|
31
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
32
|
+
status: "auto",
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
if (ctx.projectRoot) {
|
|
36
|
+
for (const name of ["AGENTS.md", "CLAUDE.md", "GEMINI.md", path.join(".github", "copilot-instructions.md")]) {
|
|
37
|
+
instruction(path.join(ctx.projectRoot, name), "project");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
instruction(path.join(home, "copilot-instructions.md"), "user");
|
|
41
|
+
|
|
42
|
+
// Rules -------------------------------------------------------------------
|
|
43
|
+
const rules = (root: string, scope: Scope) => {
|
|
44
|
+
for (const file of listFiles(root, [".instructions.md"], true)) {
|
|
45
|
+
const doc = readMarkdown(file);
|
|
46
|
+
const applyTo = doc ? fmList(doc.data, "applyTo") : undefined;
|
|
47
|
+
sink.add({
|
|
48
|
+
category: "rules",
|
|
49
|
+
scope,
|
|
50
|
+
name: path.relative(root, file),
|
|
51
|
+
path: file,
|
|
52
|
+
root,
|
|
53
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
54
|
+
status: applyTo && applyTo !== "**" ? "conditional" : "auto",
|
|
55
|
+
reason: applyTo ? { code: "globs", value: `applyTo: ${applyTo}` } : { code: "always" },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
if (ctx.projectRoot) rules(path.join(ctx.projectRoot, ".github", "instructions"), "project");
|
|
60
|
+
rules(path.join(home, "instructions"), "user");
|
|
61
|
+
|
|
62
|
+
// Skills ------------------------------------------------------------------
|
|
63
|
+
const skills = (root: string, scope: Scope, tags: Entry["tags"] = []) => {
|
|
64
|
+
for (const skill of findSkills(root, { recursive: false })) {
|
|
65
|
+
const base = skillEntry(skill, root, scope);
|
|
66
|
+
const invocation = skillInvocation(skill.doc);
|
|
67
|
+
sink.add({
|
|
68
|
+
...base,
|
|
69
|
+
tags: [...(base.tags ?? []), ...invocation.tags, ...tags],
|
|
70
|
+
status: invocation.status,
|
|
71
|
+
...(invocation.reason ? { reason: invocation.reason } : {}),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
if (ctx.projectRoot) {
|
|
76
|
+
skills(path.join(ctx.projectRoot, ".github", "skills"), "project");
|
|
77
|
+
skills(path.join(ctx.projectRoot, ".agents", "skills"), "project");
|
|
78
|
+
skills(path.join(ctx.projectRoot, ".claude", "skills"), "project", ["legacy"]);
|
|
79
|
+
for (const dir of parentDirs(ctx.projectRoot)) skills(path.join(dir, ".github", "skills"), "project", ["parent"]);
|
|
80
|
+
for (const file of listFiles(path.join(ctx.projectRoot, ".claude", "commands"), [".md"], false)) {
|
|
81
|
+
const doc = readMarkdown(file);
|
|
82
|
+
const manual = doc?.data["disable-model-invocation"] === true;
|
|
83
|
+
sink.add({
|
|
84
|
+
category: "skills",
|
|
85
|
+
scope: "project",
|
|
86
|
+
name: `/${path.basename(file, ".md")}`,
|
|
87
|
+
path: file,
|
|
88
|
+
...(doc?.description ? { description: doc.description } : {}),
|
|
89
|
+
status: manual ? "manual" : "auto",
|
|
90
|
+
...(manual ? { reason: { code: "frontmatter" as const, value: "disable-model-invocation: true" } } : {}),
|
|
91
|
+
tags: ["command"],
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
skills(path.join(home, "skills"), "user");
|
|
96
|
+
skills(path.join(ctx.home, ".agents", "skills"), "user");
|
|
97
|
+
for (const dir of (ctx.env.COPILOT_SKILLS_DIRS ?? "").split(",").map((item) => item.trim()).filter(Boolean)) {
|
|
98
|
+
skills(path.resolve(dir), "user");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// MCP ---------------------------------------------------------------------
|
|
102
|
+
if (ctx.projectRoot) {
|
|
103
|
+
for (const rel of [".mcp.json", path.join(".github", "mcp.json")]) {
|
|
104
|
+
const file = path.join(ctx.projectRoot, rel);
|
|
105
|
+
for (const [name, config] of serversOf(readJson(file))) {
|
|
106
|
+
sink.add(mcpEntry({ name, config, file, source: rel, scope: "project", status: "auto", tags: ["trust"] }));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const userMcp = path.join(home, "mcp-config.json");
|
|
111
|
+
for (const [name, config] of serversOf(readJson(userMcp))) {
|
|
112
|
+
sink.add(mcpEntry({ name, config, file: userMcp, source: "~/.copilot/mcp-config.json", scope: "user", status: "auto" }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return sink.entries;
|
|
116
|
+
}
|