@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.
Files changed (60) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +21 -0
  3. package/README.md +58 -0
  4. package/client/category-visibility.test.ts +26 -0
  5. package/client/design-tokens.test.ts +39 -0
  6. package/client/design-tokens.ts +104 -0
  7. package/client/dropdown.tsx +139 -0
  8. package/client/entries.test.ts +50 -0
  9. package/client/entries.ts +47 -0
  10. package/client/entry-row.tsx +89 -0
  11. package/client/mechanism-card.tsx +75 -0
  12. package/client/preview-pane.tsx +101 -0
  13. package/client/provider-options.test.ts +31 -0
  14. package/client/provider-options.ts +37 -0
  15. package/client/query-policy.test.ts +57 -0
  16. package/client/query-policy.ts +20 -0
  17. package/client/route.ts +29 -0
  18. package/client/selection-settings.test.ts +16 -0
  19. package/client/slash-command.test.ts +94 -0
  20. package/client/slash-command.ts +36 -0
  21. package/client/surface.tsx +332 -0
  22. package/client/ui.tsx +265 -0
  23. package/client/use-app-language.ts +28 -0
  24. package/client/web.ts +111 -0
  25. package/index.client.tsx +57 -0
  26. package/index.server.ts +13 -0
  27. package/package.json +37 -0
  28. package/paseo-plugin.json +6 -0
  29. package/server/agent-plugins.ts +41 -0
  30. package/server/compatibility.test.ts +104 -0
  31. package/server/compatibility.ts +46 -0
  32. package/server/frontmatter.ts +49 -0
  33. package/server/glob.ts +46 -0
  34. package/server/handlers.ts +193 -0
  35. package/server/jsonc.ts +40 -0
  36. package/server/mcp.ts +87 -0
  37. package/server/parsers.test.ts +92 -0
  38. package/server/providers/acp.ts +186 -0
  39. package/server/providers/claude.ts +284 -0
  40. package/server/providers/codex.ts +219 -0
  41. package/server/providers/copilot.ts +116 -0
  42. package/server/providers/cursor.ts +194 -0
  43. package/server/providers/omp.ts +263 -0
  44. package/server/providers/opencode.ts +215 -0
  45. package/server/providers/pi.ts +102 -0
  46. package/server/providers.test.ts +306 -0
  47. package/server/scan-kit.ts +368 -0
  48. package/server/scan-snapshot.test.ts +56 -0
  49. package/server/scan-snapshot.ts +58 -0
  50. package/server/skill-aliases.ts +60 -0
  51. package/server/toml.ts +240 -0
  52. package/server/yaml-lite.ts +172 -0
  53. package/shared/acp-configs.ts +107 -0
  54. package/shared/category-visibility.ts +26 -0
  55. package/shared/compatibility.ts +6 -0
  56. package/shared/contracts.ts +116 -0
  57. package/shared/i18n.ts +293 -0
  58. package/shared/mechanisms.ts +380 -0
  59. package/shared/providers.ts +27 -0
  60. package/shared/selection-settings.ts +14 -0
@@ -0,0 +1,194 @@
1
+ import path from "node:path";
2
+ import { fmList, fmString, type Frontmatter } from "../frontmatter.ts";
3
+ import { agentPluginManifest } from "../agent-plugins.ts";
4
+ import { mcpEntry, serversOf } from "../mcp.ts";
5
+ import {
6
+ EntrySink,
7
+ findSkills,
8
+ isDir,
9
+ isFile,
10
+ listFiles,
11
+ listNames,
12
+ nestedWith,
13
+ readJson,
14
+ readMarkdown,
15
+ skillEntry,
16
+ skillInvocation,
17
+ type EntryInput,
18
+ type ScanContext,
19
+ } from "../scan-kit.ts";
20
+ import type { Entry, Scope } from "../../shared/contracts.ts";
21
+ import { cursorThirdPartySwitch } from "../compatibility.ts";
22
+
23
+ /** cursor-agent `workspace-paths` slug: non-alphanumerics → `-`, collapsed and trimmed. */
24
+ export function cursorProjectSlug(root: string): string {
25
+ return root.replace(/[^a-zA-Z0-9]/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
26
+ }
27
+
28
+ /** Cursor / OMP `.mdc` rule semantics from `alwaysApply` / `globs` / `description`. */
29
+ export function mdcRuleState(data: Frontmatter): Pick<EntryInput, "status" | "reason"> {
30
+ if (data.alwaysApply === true || data.alwaysApply === "true") return { status: "auto", reason: { code: "always" } };
31
+ const globs = fmList(data, "globs");
32
+ if (globs) return { status: "conditional", reason: { code: "globs", value: `globs: ${globs}` } };
33
+ if (fmString(data, "description")) return { status: "conditional", reason: { code: "agentDecides" } };
34
+ return { status: "manual", reason: { code: "manualMention" } };
35
+ }
36
+
37
+ export function scanCursor(ctx: ScanContext): Entry[] {
38
+ const sink = new EntrySink(ctx);
39
+ const cursorHome = ctx.env.CURSOR_CONFIG_DIR?.trim() || path.join(ctx.home, ".cursor");
40
+ const thirdParty = cursorThirdPartySwitch(ctx);
41
+
42
+ // Instructions ------------------------------------------------------------
43
+ const instruction = (file: string, extra: Partial<EntryInput> = {}) => {
44
+ if (!isFile(file)) return;
45
+ const doc = readMarkdown(file);
46
+ sink.add({
47
+ category: "instructions",
48
+ scope: "project",
49
+ name: path.basename(file),
50
+ path: file,
51
+ ...(doc?.description ? { description: doc.description } : {}),
52
+ status: "auto",
53
+ ...extra,
54
+ });
55
+ };
56
+ if (ctx.projectRoot) {
57
+ for (const name of ["AGENTS.md", "CLAUDE.md", "CLAUDE.local.md"]) instruction(path.join(ctx.projectRoot, name));
58
+ instruction(path.join(ctx.projectRoot, ".cursorrules"), { tags: ["legacy"] });
59
+ for (const dir of nestedWith(ctx, "AGENTS.md")) {
60
+ instruction(path.join(dir, "AGENTS.md"), {
61
+ status: "conditional",
62
+ reason: { code: "nestedDir", value: path.relative(ctx.projectRoot, dir) },
63
+ tags: ["nested"],
64
+ });
65
+ }
66
+ }
67
+
68
+ // Rules -------------------------------------------------------------------
69
+ const rules = (root: string, scope: Scope, nestedDir?: string) => {
70
+ for (const file of listFiles(root, [".mdc", ".md"], true)) {
71
+ const doc = readMarkdown(file);
72
+ const base = {
73
+ category: "rules" as const,
74
+ scope,
75
+ name: path.relative(root, file),
76
+ path: file,
77
+ root,
78
+ ...(doc?.description ? { description: doc.description } : {}),
79
+ tags: nestedDir ? (["nested"] as Entry["tags"]) : [],
80
+ };
81
+ if (!file.toLowerCase().endsWith(".mdc")) {
82
+ sink.add({ ...base, status: "inactive", reason: { code: "ignoredExt", value: ".md" } });
83
+ continue;
84
+ }
85
+ const state = mdcRuleState(doc?.data ?? {});
86
+ if (nestedDir && state.status === "auto") {
87
+ sink.add({ ...base, status: "conditional", reason: { code: "nestedDir", value: nestedDir } });
88
+ } else {
89
+ sink.add({ ...base, ...state });
90
+ }
91
+ }
92
+ };
93
+ if (ctx.projectRoot) {
94
+ rules(path.join(ctx.projectRoot, ".cursor", "rules"), "project");
95
+ for (const dir of nestedWith(ctx, ".cursor")) {
96
+ const root = path.join(dir, ".cursor", "rules");
97
+ if (isDir(root)) rules(root, "project", path.relative(ctx.projectRoot, dir));
98
+ }
99
+ }
100
+
101
+ // Skills ------------------------------------------------------------------
102
+ const skills = (root: string, scope: Scope, tags: Entry["tags"] = [], nestedDir?: string, external = false) => {
103
+ for (const skill of findSkills(root, { recursive: true, maxDepth: 6 })) {
104
+ const base = skillEntry(skill, root, scope);
105
+ const invocation = skillInvocation(skill.doc);
106
+ const allTags = [...(base.tags ?? []), ...invocation.tags, ...tags];
107
+ const paths = fmList(skill.doc.data, "paths") ?? fmList(skill.doc.data, "globs");
108
+ if (external && thirdParty.enabled === false) {
109
+ sink.add({ ...base, tags: allTags, status: "disabled", reason: { code: "config", value: "thirdPartyExtensibilityEnabled: false" } });
110
+ } else if (invocation.status === "manual") {
111
+ sink.add({ ...base, tags: allTags, status: "manual", ...(invocation.reason ? { reason: invocation.reason } : {}) });
112
+ } else if (paths) {
113
+ sink.add({ ...base, tags: allTags, status: "conditional", reason: { code: "globs", value: `paths: ${paths}` } });
114
+ } else if (nestedDir) {
115
+ sink.add({ ...base, tags: allTags, status: "conditional", reason: { code: "nestedDir", value: nestedDir } });
116
+ } else {
117
+ sink.add({ ...base, tags: allTags, status: "auto" });
118
+ }
119
+ }
120
+ };
121
+ const PROJECT_SKILL_DIRS = [".agents", ".cursor", ".claude", ".codex"] as const;
122
+ if (ctx.projectRoot) {
123
+ for (const base of PROJECT_SKILL_DIRS) {
124
+ skills(path.join(ctx.projectRoot, base, "skills"), "project", base === ".claude" || base === ".codex" ? ["legacy"] : [], undefined, base === ".claude" || base === ".codex");
125
+ }
126
+ for (const base of PROJECT_SKILL_DIRS) {
127
+ for (const dir of nestedWith(ctx, base)) {
128
+ const root = path.join(dir, base, "skills");
129
+ if (isDir(root)) skills(root, "project", ["nested"], path.relative(ctx.projectRoot, dir), base === ".claude" || base === ".codex");
130
+ }
131
+ }
132
+ }
133
+ skills(path.join(ctx.home, ".agents", "skills"), "user");
134
+ skills(path.join(cursorHome, "skills"), "user");
135
+ skills(path.join(ctx.home, ".claude", "skills"), "user", ["legacy"], undefined, true);
136
+ skills(path.join(ctx.home, ".codex", "skills"), "user", ["legacy"], undefined, true);
137
+ skills(path.join(cursorHome, "skills-cursor"), "user", ["builtin"]);
138
+
139
+ // MCP ---------------------------------------------------------------------
140
+ const disabledFile = ctx.projectRoot ? path.join(cursorHome, "projects", cursorProjectSlug(ctx.projectRoot), "mcp-disabled.json") : null;
141
+ const disabledRaw = disabledFile ? readJson(disabledFile) : undefined;
142
+ const disabled = new Set(Array.isArray(disabledRaw) ? disabledRaw.filter((name): name is string => typeof name === "string") : []);
143
+ const servers = (file: string, scope: Scope, source: string) => {
144
+ for (const [name, config] of serversOf(readJson(file))) {
145
+ const off = disabled.has(name);
146
+ sink.add(
147
+ mcpEntry({
148
+ name,
149
+ config,
150
+ file,
151
+ source,
152
+ scope,
153
+ status: off ? "disabled" : "auto",
154
+ ...(off ? { reason: { code: "config", value: "mcp-disabled.json" } } : {}),
155
+ }),
156
+ );
157
+ }
158
+ };
159
+ if (ctx.projectRoot) servers(path.join(ctx.projectRoot, ".cursor", "mcp.json"), "project", ".cursor/mcp.json");
160
+ servers(path.join(cursorHome, "mcp.json"), "user", "~/.cursor/mcp.json");
161
+
162
+ const extraFiles = (category: "commands" | "subagents", root: string, scope: Scope, tags: Entry["tags"] = []) => {
163
+ for (const file of listFiles(root, [".md"], true)) {
164
+ const doc = readMarkdown(file);
165
+ const off = category === "subagents" && tags.includes("legacy") && thirdParty.enabled === false;
166
+ sink.add({ category, scope, name: path.relative(root, file), path: file, root, status: off ? "disabled" : "auto", ...(off ? { reason: { code: "config", value: "thirdPartyExtensibilityEnabled: false" } } : {}), tags, ...(doc?.description ? { description: doc.description } : {}) });
167
+ }
168
+ };
169
+ if (ctx.projectRoot) {
170
+ extraFiles("commands", path.join(ctx.projectRoot, ".cursor", "commands"), "project");
171
+ for (const base of [".cursor", ".claude", ".codex"]) extraFiles("subagents", path.join(ctx.projectRoot, base, "agents"), "project", base === ".cursor" ? [] : ["legacy"]);
172
+ const standardManifest = path.join(ctx.projectRoot, "plugin.json");
173
+ const manifest = isFile(standardManifest) ? standardManifest : path.join(ctx.projectRoot, ".cursor-plugin", "plugin.json");
174
+ if (isFile(manifest)) {
175
+ sink.add({ category: "plugins", scope: "project", name: path.basename(ctx.projectRoot), path: manifest, status: "conditional", reason: { code: "config", value: "Activation is not verified" }, agentPlugin: agentPluginManifest(standardManifest) ?? undefined });
176
+ extraFiles("commands", path.join(ctx.projectRoot, "commands"), "project");
177
+ extraFiles("subagents", path.join(ctx.projectRoot, "agents"), "project");
178
+ }
179
+ }
180
+ extraFiles("commands", path.join(cursorHome, "commands"), "user");
181
+ for (const base of [cursorHome, path.join(ctx.home, ".claude"), path.join(ctx.home, ".codex")]) extraFiles("subagents", path.join(base, "agents"), "user", base === cursorHome ? [] : ["legacy"]);
182
+
183
+ const localPlugins = path.join(cursorHome, "plugins", "local");
184
+ for (const name of listNames(localPlugins)) {
185
+ const root = path.join(localPlugins, name);
186
+ if (!isDir(root)) continue;
187
+ const standardManifest = path.join(root, "plugin.json");
188
+ const manifest = isFile(standardManifest) ? standardManifest : path.join(root, ".cursor-plugin", "plugin.json");
189
+ if (!isFile(manifest)) continue;
190
+ sink.add({ category: "plugins", scope: "user", name, path: manifest, root: localPlugins, status: "conditional", reason: { code: "config", value: "Activation is not verified" }, agentPlugin: agentPluginManifest(standardManifest) ?? undefined });
191
+ }
192
+
193
+ return sink.entries;
194
+ }
@@ -0,0 +1,263 @@
1
+ import path from "node:path";
2
+ import { matchGlob } from "../glob.ts";
3
+ import { mcpEntry, serversOf } from "../mcp.ts";
4
+ import {
5
+ EntrySink,
6
+ findSkills,
7
+ isFile,
8
+ isRecord,
9
+ listFiles,
10
+ parentDirs,
11
+ readJson,
12
+ readMarkdown,
13
+ readText,
14
+ skillEntry,
15
+ type EntryInput,
16
+ type ScanContext,
17
+ } from "../scan-kit.ts";
18
+ import { parseToml } from "../toml.ts";
19
+ import { parseYaml } from "../yaml-lite.ts";
20
+ import type { Entry, Scope } from "../../shared/contracts.ts";
21
+ import { mdcRuleState } from "./cursor.ts";
22
+
23
+ interface OmpSettings {
24
+ enableClaudeUser: boolean;
25
+ enableCodexUser: boolean;
26
+ enableClaudeProject: boolean;
27
+ enableAgentsUser: boolean;
28
+ enableAgentsProject: boolean;
29
+ enablePiUser: boolean;
30
+ enablePiProject: boolean;
31
+ ignoredSkills: string[];
32
+ disabledSkills: Set<string>;
33
+ }
34
+
35
+ /** Dotted (`skills.enableClaudeUser`) or nested (`skills:\n enableClaudeUser`) keys. */
36
+ function setting(config: Record<string, unknown>, key: string): unknown {
37
+ if (key in config) return config[key];
38
+ const [head, ...rest] = key.split(".");
39
+ const child = config[head!];
40
+ return rest.length && isRecord(child) ? setting(child, rest.join(".")) : undefined;
41
+ }
42
+
43
+ function readSettings(agentDir: string, projectRoot: string | null): OmpSettings {
44
+ const layers = [path.join(agentDir, "config.yml"), ...(projectRoot ? [path.join(projectRoot, ".omp", "config.yml")] : [])]
45
+ .map((file) => readText(file))
46
+ .filter((text): text is string => text != null)
47
+ .map((text) => {
48
+ try {
49
+ return parseYaml(text);
50
+ } catch {
51
+ return {};
52
+ }
53
+ });
54
+ const bool = (key: string, fallback: boolean) => {
55
+ let value = fallback;
56
+ for (const layer of layers) {
57
+ const raw = setting(layer, key);
58
+ if (typeof raw === "boolean") value = raw;
59
+ }
60
+ return value;
61
+ };
62
+ const list = (key: string) =>
63
+ layers.flatMap((layer) => {
64
+ const raw = setting(layer, key);
65
+ return Array.isArray(raw) ? raw.filter((item): item is string => typeof item === "string") : [];
66
+ });
67
+ return {
68
+ enableClaudeUser: bool("skills.enableClaudeUser", false),
69
+ enableCodexUser: bool("skills.enableCodexUser", false),
70
+ enableClaudeProject: bool("skills.enableClaudeProject", true),
71
+ enableAgentsUser: bool("skills.enableAgentsUser", true),
72
+ enableAgentsProject: bool("skills.enableAgentsProject", true),
73
+ enablePiUser: bool("skills.enablePiUser", true),
74
+ enablePiProject: bool("skills.enablePiProject", true),
75
+ ignoredSkills: list("skills.ignoredSkills"),
76
+ disabledSkills: new Set(list("disabledExtensions").filter((id) => id.startsWith("skill:")).map((id) => id.slice(6))),
77
+ };
78
+ }
79
+
80
+ export function scanOmp(ctx: ScanContext): Entry[] {
81
+ const sink = new EntrySink(ctx);
82
+ const agentDir = path.join(ctx.home, ".omp", "agent");
83
+ const settings = readSettings(agentDir, ctx.projectRoot);
84
+ const chain = ctx.projectRoot ? [ctx.projectRoot, ...parentDirs(ctx.projectRoot)] : [];
85
+ const nearestOmp = chain.find((dir) => dir !== ctx.home && isFile(path.join(dir, ".omp", "AGENTS.md")));
86
+ const nearestRules = chain.find((dir) => dir !== ctx.home && isFile(path.join(dir, ".omp", "RULES.md")));
87
+
88
+ // Instructions ------------------------------------------------------------
89
+ const instruction = (file: string, scope: Scope, tags: Entry["tags"] = []) => {
90
+ if (!isFile(file)) return;
91
+ const doc = readMarkdown(file);
92
+ sink.add({
93
+ category: "instructions",
94
+ scope,
95
+ name: path.basename(file),
96
+ path: file,
97
+ ...(doc?.description ? { description: doc.description } : {}),
98
+ status: "auto",
99
+ tags,
100
+ });
101
+ };
102
+ instruction(path.join(agentDir, "AGENTS.md"), "user");
103
+ instruction(path.join(agentDir, "SYSTEM.md"), "user", ["systemPrompt"]);
104
+ for (const base of [".agents", ".agent"]) instruction(path.join(ctx.home, base, "AGENTS.md"), "user");
105
+ instruction(path.join(ctx.home, ".claude", "CLAUDE.md"), "user", ["legacy"]);
106
+ instruction(path.join(ctx.home, ".codex", "AGENTS.md"), "user", ["legacy"]);
107
+ instruction(path.join(ctx.home, ".config", "opencode", "AGENTS.md"), "user", ["legacy"]);
108
+ if (ctx.projectRoot) {
109
+ if (nearestOmp) instruction(path.join(nearestOmp, ".omp", "AGENTS.md"), "project", nearestOmp === ctx.projectRoot ? [] : ["parent"]);
110
+ instruction(path.join(ctx.projectRoot, ".omp", "SYSTEM.md"), "project", ["systemPrompt"]);
111
+ for (const dir of chain) {
112
+ if (dir === ctx.home) continue;
113
+ const tags: Entry["tags"] = dir === ctx.projectRoot ? [] : ["parent"];
114
+ instruction(path.join(dir, "AGENTS.md"), "project", tags);
115
+ instruction(path.join(dir, "CLAUDE.md"), "project", tags);
116
+ }
117
+ instruction(path.join(ctx.projectRoot, ".github", "copilot-instructions.md"), "project", ["legacy"]);
118
+ }
119
+
120
+ // Rules -------------------------------------------------------------------
121
+ const rules = (root: string, scope: Scope, exts: readonly string[], tags: Entry["tags"] = []) => {
122
+ for (const file of listFiles(root, exts, false)) {
123
+ const doc = readMarkdown(file);
124
+ sink.add({
125
+ category: "rules",
126
+ scope,
127
+ name: path.basename(file),
128
+ path: file,
129
+ root,
130
+ ...(doc?.description ? { description: doc.description } : {}),
131
+ ...mdcRuleState(doc?.data ?? {}),
132
+ tags,
133
+ });
134
+ }
135
+ };
136
+ const sticky = (file: string, scope: Scope) => {
137
+ if (!isFile(file)) return;
138
+ sink.add({ category: "rules", scope, name: "RULES.md", path: file, status: "auto", reason: { code: "always" }, tags: ["sticky"] });
139
+ };
140
+ sticky(path.join(agentDir, "RULES.md"), "user");
141
+ rules(path.join(agentDir, "rules"), "user", [".md", ".mdc"]);
142
+ for (const base of [".agents", ".agent"]) rules(path.join(ctx.home, base, "rules"), "user", [".md", ".mdc"]);
143
+ rules(path.join(ctx.home, ".cursor", "rules"), "user", [".mdc"], ["legacy"]);
144
+ if (ctx.projectRoot) {
145
+ if (nearestRules) sticky(path.join(nearestRules, ".omp", "RULES.md"), "project");
146
+ rules(path.join(ctx.projectRoot, ".omp", "rules"), "project", [".md", ".mdc"]);
147
+ for (const base of [".agents", ".agent"]) rules(path.join(ctx.projectRoot, base, "rules"), "project", [".md", ".mdc"]);
148
+ rules(path.join(ctx.projectRoot, ".cursor", "rules"), "project", [".mdc"], ["legacy"]);
149
+ const instructionsDir = path.join(ctx.projectRoot, ".github", "instructions");
150
+ for (const file of listFiles(instructionsDir, [".instructions.md"], true)) {
151
+ const doc = readMarkdown(file);
152
+ const applyTo = doc?.data.applyTo;
153
+ sink.add({
154
+ category: "rules",
155
+ scope: "project",
156
+ name: path.relative(instructionsDir, file),
157
+ path: file,
158
+ root: instructionsDir,
159
+ ...(doc?.description ? { description: doc.description } : {}),
160
+ ...(typeof applyTo === "string" && applyTo
161
+ ? { status: "conditional" as const, reason: { code: "globs" as const, value: `applyTo: ${applyTo}` } }
162
+ : { status: "auto" as const }),
163
+ tags: ["legacy"],
164
+ });
165
+ }
166
+ }
167
+
168
+ // Skills ------------------------------------------------------------------
169
+ const skills = (root: string, scope: Scope, gate: { enabled: boolean; key?: string }, tags: Entry["tags"] = []) => {
170
+ for (const skill of findSkills(root, { recursive: false })) {
171
+ if (!skill.doc.description) continue;
172
+ const base = skillEntry(skill, root, scope);
173
+ const allTags = [...(base.tags ?? []), ...tags];
174
+ const data = skill.doc.data;
175
+ let state: Pick<EntryInput, "status" | "reason">;
176
+ if (data.enabled === false) state = { status: "disabled", reason: { code: "frontmatter", value: "enabled: false" } };
177
+ else if (!gate.enabled) state = { status: "inactive", reason: { code: "offByDefault", value: gate.key } };
178
+ else if (settings.disabledSkills.has(skill.name)) state = { status: "disabled", reason: { code: "config", value: `disabledExtensions: skill:${skill.name}` } };
179
+ else if (settings.ignoredSkills.some((pattern) => matchGlob(pattern, skill.name))) {
180
+ state = { status: "disabled", reason: { code: "config", value: "skills.ignoredSkills" } };
181
+ } else if (data.hide === true) state = { status: "manual", reason: { code: "frontmatter", value: "hide: true" } };
182
+ else if (data["disable-model-invocation"] === true) state = { status: "manual", reason: { code: "frontmatter", value: "disable-model-invocation: true" } };
183
+ else state = { status: "auto" };
184
+ sink.add({ ...base, tags: allTags, ...state });
185
+ }
186
+ };
187
+ const on = { enabled: true };
188
+ if (ctx.projectRoot) {
189
+ for (const dir of chain.filter((dir) => dir !== ctx.home)) {
190
+ const tags: Entry["tags"] = dir === ctx.projectRoot ? [] : ["parent"];
191
+ skills(path.join(dir, ".omp", "skills"), "project", { enabled: settings.enablePiProject, key: "skills.enablePiProject" }, tags);
192
+ for (const base of [".agents", ".agent"]) {
193
+ skills(path.join(dir, base, "skills"), "project", { enabled: settings.enableAgentsProject, key: "skills.enableAgentsProject" }, tags);
194
+ }
195
+ skills(path.join(dir, ".claude", "skills"), "project", { enabled: settings.enableClaudeProject, key: "skills.enableClaudeProject" }, [...tags, "legacy"]);
196
+ }
197
+ skills(path.join(ctx.projectRoot, ".codex", "skills"), "project", on, ["legacy"]);
198
+ }
199
+ skills(path.join(agentDir, "skills"), "user", { enabled: settings.enablePiUser, key: "skills.enablePiUser" });
200
+ skills(path.join(agentDir, "managed-skills"), "user", on, ["autolearn"]);
201
+ for (const base of [".agents", ".agent"]) {
202
+ skills(path.join(ctx.home, base, "skills"), "user", { enabled: settings.enableAgentsUser, key: "skills.enableAgentsUser" });
203
+ }
204
+ skills(path.join(ctx.home, ".claude", "skills"), "user", { enabled: settings.enableClaudeUser, key: "skills.enableClaudeUser" }, ["legacy"]);
205
+ skills(path.join(ctx.home, ".codex", "skills"), "user", { enabled: settings.enableCodexUser, key: "skills.enableCodexUser" }, ["legacy"]);
206
+
207
+ // MCP ---------------------------------------------------------------------
208
+ const jsonServers = (file: string, scope: Scope, source: string, tags: Entry["tags"] = []) => {
209
+ for (const [name, config] of serversOf(readJson(file))) {
210
+ const off = isRecord(config) && config.enabled === false;
211
+ sink.add(
212
+ mcpEntry({
213
+ name,
214
+ config,
215
+ file,
216
+ source,
217
+ scope,
218
+ status: off ? "disabled" : "auto",
219
+ ...(off ? { reason: { code: "config", value: "enabled: false" } } : {}),
220
+ tags,
221
+ }),
222
+ );
223
+ }
224
+ };
225
+ const tomlServers = (file: string, scope: Scope, source: string) => {
226
+ const text = readText(file);
227
+ if (text == null) return;
228
+ let config: Record<string, unknown> = {};
229
+ try {
230
+ config = parseToml(text);
231
+ } catch {
232
+ return;
233
+ }
234
+ for (const [name, server] of Object.entries(isRecord(config.mcp_servers) ? config.mcp_servers : {})) {
235
+ const off = isRecord(server) && server.enabled === false;
236
+ sink.add(
237
+ mcpEntry({
238
+ name,
239
+ config: server,
240
+ file,
241
+ source,
242
+ scope,
243
+ status: off ? "disabled" : "auto",
244
+ ...(off ? { reason: { code: "config", value: "enabled = false" } } : {}),
245
+ tags: ["legacy"],
246
+ }),
247
+ );
248
+ }
249
+ };
250
+ for (const name of ["mcp.json", ".mcp.json"]) jsonServers(path.join(agentDir, name), "user", `~/.omp/agent/${name}`);
251
+ jsonServers(path.join(ctx.home, ".cursor", "mcp.json"), "user", "~/.cursor/mcp.json", ["legacy"]);
252
+ tomlServers(path.join(ctx.home, ".codex", "config.toml"), "user", "~/.codex/config.toml");
253
+ if (ctx.projectRoot) {
254
+ for (const name of ["mcp.json", ".mcp.json"]) {
255
+ jsonServers(path.join(ctx.projectRoot, ".omp", name), "project", `.omp/${name}`);
256
+ jsonServers(path.join(ctx.projectRoot, name), "project", name);
257
+ }
258
+ jsonServers(path.join(ctx.projectRoot, ".cursor", "mcp.json"), "project", ".cursor/mcp.json", ["legacy"]);
259
+ tomlServers(path.join(ctx.projectRoot, ".codex", "config.toml"), "project", ".codex/config.toml");
260
+ }
261
+
262
+ return sink.entries;
263
+ }
@@ -0,0 +1,215 @@
1
+ import path from "node:path";
2
+ import { matchGlob } from "../glob.ts";
3
+ import { parseJsonc } from "../jsonc.ts";
4
+ import { mcpEntry } from "../mcp.ts";
5
+ import {
6
+ EntrySink,
7
+ findSkills,
8
+ isFile,
9
+ isRecord,
10
+ listFiles,
11
+ nestedWith,
12
+ readMarkdown,
13
+ readText,
14
+ skillEntry,
15
+ type EntryInput,
16
+ type ScanContext,
17
+ } from "../scan-kit.ts";
18
+ import type { Entry, Scope } from "../../shared/contracts.ts";
19
+ import { opencodeExternalSkillSwitch } from "../compatibility.ts";
20
+
21
+ function configDir(ctx: ScanContext): string {
22
+ const xdg = ctx.env.XDG_CONFIG_HOME?.trim();
23
+ return path.join(xdg || path.join(ctx.home, ".config"), "opencode");
24
+ }
25
+
26
+ function readConfig(file: string): Record<string, unknown> | null {
27
+ const text = readText(file);
28
+ if (text == null) return null;
29
+ try {
30
+ const value = parseJsonc(text);
31
+ return isRecord(value) ? value : null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ function configFiles(dir: string): string[] {
38
+ return ["opencode.json", "opencode.jsonc"].map((name) => path.join(dir, name)).filter(isFile);
39
+ }
40
+
41
+ const truthy = (value: string | undefined) => value != null && value !== "" && value !== "0" && value.toLowerCase() !== "false";
42
+
43
+ /** Last matching `permission.skill` pattern wins. */
44
+ function skillPermission(rules: Array<[string, string]>, name: string): string | undefined {
45
+ let result: string | undefined;
46
+ for (const [pattern, action] of rules) if (matchGlob(pattern, name)) result = action;
47
+ return result;
48
+ }
49
+
50
+ export function scanOpencode(ctx: ScanContext): Entry[] {
51
+ const sink = new EntrySink(ctx);
52
+ const globalDir = configDir(ctx);
53
+ const noClaude = truthy(ctx.env.OPENCODE_DISABLE_CLAUDE_CODE);
54
+ const noClaudePrompt = noClaude || truthy(ctx.env.OPENCODE_DISABLE_CLAUDE_CODE_PROMPT);
55
+ const noClaudeSkills = noClaude || truthy(ctx.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS);
56
+ const externalSkills = opencodeExternalSkillSwitch(ctx.env);
57
+
58
+ const configs: Array<{ file: string; scope: Scope; data: Record<string, unknown> }> = [];
59
+ for (const file of configFiles(globalDir)) {
60
+ const data = readConfig(file);
61
+ if (data) configs.push({ file, scope: "user", data });
62
+ }
63
+ if (ctx.projectRoot) {
64
+ for (const file of [...configFiles(ctx.projectRoot), ...configFiles(path.join(ctx.projectRoot, ".opencode"))]) {
65
+ const data = readConfig(file);
66
+ if (data) configs.push({ file, scope: "project", data });
67
+ }
68
+ }
69
+
70
+ // Instructions ------------------------------------------------------------
71
+ const doc = (file: string, scope: Scope, state: Pick<EntryInput, "status" | "reason">, tags: Entry["tags"] = []) => {
72
+ const md = readMarkdown(file);
73
+ sink.add({
74
+ category: "instructions",
75
+ scope,
76
+ name: path.basename(file),
77
+ path: file,
78
+ ...(md?.description ? { description: md.description } : {}),
79
+ ...state,
80
+ tags,
81
+ });
82
+ };
83
+ const firstWins = (candidates: Array<{ file: string; disabledBy?: string }>, scope: Scope, tags: Entry["tags"] = []) => {
84
+ let winner: string | null = null;
85
+ for (const candidate of candidates) {
86
+ if (!isFile(candidate.file)) continue;
87
+ if (candidate.disabledBy) {
88
+ doc(candidate.file, scope, { status: "disabled", reason: { code: "env", value: candidate.disabledBy } }, tags);
89
+ } else if (winner) {
90
+ doc(candidate.file, scope, { status: "inactive", reason: { code: "shadowedBy", value: path.basename(winner) } }, tags);
91
+ } else {
92
+ winner = candidate.file;
93
+ doc(candidate.file, scope, { status: "auto" }, tags);
94
+ }
95
+ }
96
+ };
97
+ if (ctx.projectRoot) {
98
+ firstWins(
99
+ [
100
+ { file: path.join(ctx.projectRoot, "AGENTS.md") },
101
+ { file: path.join(ctx.projectRoot, "CLAUDE.md"), ...(noClaude ? { disabledBy: "OPENCODE_DISABLE_CLAUDE_CODE" } : {}) },
102
+ ],
103
+ "project",
104
+ );
105
+ for (const dir of nestedWith(ctx, "AGENTS.md")) {
106
+ doc(path.join(dir, "AGENTS.md"), "project", { status: "conditional", reason: { code: "nestedDir", value: path.relative(ctx.projectRoot, dir) } }, ["nested"]);
107
+ }
108
+ }
109
+ firstWins(
110
+ [
111
+ { file: path.join(globalDir, "AGENTS.md") },
112
+ {
113
+ file: path.join(ctx.home, ".claude", "CLAUDE.md"),
114
+ ...(noClaudePrompt ? { disabledBy: noClaude ? "OPENCODE_DISABLE_CLAUDE_CODE" : "OPENCODE_DISABLE_CLAUDE_CODE_PROMPT" } : {}),
115
+ },
116
+ ],
117
+ "user",
118
+ );
119
+
120
+ // Rules: `instructions` entries ------------------------------------------
121
+ for (const { file, scope, data } of configs) {
122
+ const list = Array.isArray(data.instructions) ? data.instructions.filter((item): item is string => typeof item === "string") : [];
123
+ const base = scope === "project" && ctx.projectRoot ? ctx.projectRoot : path.dirname(file);
124
+ for (const item of list) {
125
+ if (/^https?:\/\//i.test(item)) {
126
+ sink.add({ category: "rules", scope, name: item, path: item, source: path.basename(file), status: "auto", tags: ["url"] });
127
+ continue;
128
+ }
129
+ const pattern = item.startsWith("~/") ? path.join(ctx.home, item.slice(2)) : path.resolve(base, item);
130
+ const matches = /[*?[{]/.test(pattern) ? expandGlob(pattern) : isFile(pattern) ? [pattern] : [];
131
+ for (const match of matches) {
132
+ const md = readMarkdown(match);
133
+ sink.add({
134
+ category: "rules",
135
+ scope,
136
+ name: path.relative(base, match) || path.basename(match),
137
+ path: match,
138
+ source: `${path.basename(file)} → instructions`,
139
+ ...(md?.description ? { description: md.description } : {}),
140
+ status: "auto",
141
+ reason: { code: "config", value: item },
142
+ });
143
+ }
144
+ }
145
+ }
146
+
147
+ // Skills ------------------------------------------------------------------
148
+ const permissions: Array<[string, string]> = [];
149
+ for (const { data } of configs) {
150
+ const skill = isRecord(data.permission) ? data.permission.skill : undefined;
151
+ if (typeof skill === "string") permissions.push(["*", skill]);
152
+ else if (isRecord(skill)) for (const [pattern, action] of Object.entries(skill)) if (typeof action === "string") permissions.push([pattern, action]);
153
+ }
154
+ const skills = (root: string, scope: Scope, external = false, claude = false) => {
155
+ for (const skill of findSkills(root, { recursive: true, maxDepth: 6 })) {
156
+ const base = skillEntry(skill, root, scope);
157
+ const tags = [...(base.tags ?? []), ...(claude ? (["legacy"] as Entry["tags"]) : [])];
158
+ const permission = skillPermission(permissions, skill.name);
159
+ if (external && !externalSkills.enabled) {
160
+ sink.add({ ...base, tags, status: "disabled", reason: { code: "env", value: externalSkills.disabledBy } });
161
+ } else if (claude && noClaudeSkills) {
162
+ sink.add({ ...base, tags, status: "disabled", reason: { code: "env", value: noClaude ? "OPENCODE_DISABLE_CLAUDE_CODE" : "OPENCODE_DISABLE_CLAUDE_CODE_SKILLS" } });
163
+ } else if (permission === "deny") {
164
+ sink.add({ ...base, tags, status: "disabled", reason: { code: "config", value: `permission.skill: deny` } });
165
+ } else {
166
+ // OpenCode 1.18 advertises discovered skills automatically. Claude/Cursor
167
+ // `disable-model-invocation` does not make one manual-only here.
168
+ sink.add({ ...base, tags: permission === "ask" ? [...tags, "ask"] : tags, status: "auto" });
169
+ }
170
+ }
171
+ };
172
+ if (ctx.projectRoot) {
173
+ skills(path.join(ctx.projectRoot, ".opencode", "skills"), "project");
174
+ skills(path.join(ctx.projectRoot, ".claude", "skills"), "project", true, true);
175
+ skills(path.join(ctx.projectRoot, ".agents", "skills"), "project", true);
176
+ }
177
+ skills(path.join(globalDir, "skills"), "user");
178
+ skills(path.join(ctx.home, ".claude", "skills"), "user", true, true);
179
+ skills(path.join(ctx.home, ".agents", "skills"), "user", true);
180
+
181
+ // MCP ---------------------------------------------------------------------
182
+ for (const { file, scope, data } of configs) {
183
+ const map = isRecord(data.mcp) ? data.mcp : {};
184
+ for (const [name, server] of Object.entries(map)) {
185
+ const off = isRecord(server) && server.enabled === false;
186
+ sink.add(
187
+ mcpEntry({
188
+ name,
189
+ config: server,
190
+ file,
191
+ source: `${scope === "user" ? "~/.config/opencode/" : ""}${path.relative(scope === "project" && ctx.projectRoot ? ctx.projectRoot : path.dirname(file), file) || path.basename(file)} → mcp`,
192
+ scope,
193
+ status: off ? "disabled" : "auto",
194
+ ...(off ? { reason: { code: "config", value: "enabled: false" } } : {}),
195
+ }),
196
+ );
197
+ }
198
+ }
199
+
200
+ return sink.entries;
201
+ }
202
+
203
+ /** Expands `dir/**\/*.md`-style patterns by listing the static prefix. */
204
+ function expandGlob(pattern: string): string[] {
205
+ const parts = pattern.split(path.sep);
206
+ const firstMagic = parts.findIndex((part) => /[*?[{]/.test(part));
207
+ const baseDir = parts.slice(0, firstMagic).join(path.sep) || path.sep;
208
+ const recursive = parts.slice(firstMagic).some((part) => part === "**") || parts.length - firstMagic > 1;
209
+ const regex = pattern;
210
+ return listFiles(baseDir, [""], recursive).filter((file) => matchGlobPath(regex, file));
211
+ }
212
+
213
+ function matchGlobPath(pattern: string, file: string): boolean {
214
+ return matchGlob(pattern.split(path.sep).join("/"), file.split(path.sep).join("/"));
215
+ }