Skip to content

Commit 13fc1fc

Browse files
fix(opencode): ignore node_modules during config and skill discovery
Closes anomalyco#30337 Config and skill discovery use glob scans rooted at .opencode/ with recursive patterns (**/*.md, **/SKILL.md) and follow every directory — including node_modules/ installed by @opencode-ai/plugin. Add ignore: ["**/node_modules/**"] to all .opencode/ glob scans and thread the ignore option through Glob.scan's Options interface.
1 parent 1754480 commit 13fc1fc

8 files changed

Lines changed: 105 additions & 0 deletions

File tree

‎packages/core/src/util/glob.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export namespace Glob {
88
include?: "file" | "all"
99
dot?: boolean
1010
symlink?: boolean
11+
ignore?: string | string[]
1112
}
1213

1314
function toGlobOptions(options: Options): GlobOptions {
@@ -17,6 +18,7 @@ export namespace Glob {
1718
dot: options.dot,
1819
follow: options.symlink ?? false,
1920
nodir: options.include !== "all",
21+
ignore: options.ignore,
2022
}
2123
}
2224

‎packages/opencode/src/config/agent.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export async function load(dir: string) {
1515
absolute: true,
1616
dot: true,
1717
symlink: true,
18+
ignore: ["**/node_modules/**"],
1819
})) {
1920
const md = await ConfigMarkdown.parse(item).catch(() => undefined)
2021
if (!md) continue
@@ -38,6 +39,7 @@ export async function loadMode(dir: string) {
3839
absolute: true,
3940
dot: true,
4041
symlink: true,
42+
ignore: ["**/node_modules/**"],
4143
})) {
4244
const md = await ConfigMarkdown.parse(item).catch(() => undefined)
4345
if (!md) continue

‎packages/opencode/src/config/command.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function load(dir: string) {
1717
absolute: true,
1818
dot: true,
1919
symlink: true,
20+
ignore: ["**/node_modules/**"],
2021
})) {
2122
const md = await ConfigMarkdown.parse(item).catch(() => undefined)
2223
if (!md) continue

‎packages/opencode/src/config/plugin.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function load(dir: string) {
2323
absolute: true,
2424
dot: true,
2525
symlink: true,
26+
ignore: ["**/node_modules/**"],
2627
})) {
2728
plugins.push(pathToFileURL(item).href)
2829
}

‎packages/opencode/src/skill/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const scan = Effect.fnUntraced(function* (
153153
include: "file",
154154
symlink: true,
155155
dot: opts?.dot,
156+
ignore: ["**/node_modules/**"],
156157
}),
157158
catch: (error) => error,
158159
}).pipe(

‎packages/opencode/test/config/config.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,3 +2050,52 @@ test("parseManagedPlist handles empty config", async () => {
20502050
)
20512051
expect(config.$schema).toBe("https://opencode.ai/config.json")
20522052
})
2053+
2054+
it.instance("ignores markdown files under .opencode/node_modules during config discovery", () =>
2055+
Effect.gen(function* () {
2056+
const test = yield* TestInstance
2057+
yield* FSUtil.use.writeWithDirs(
2058+
path.join(test.directory, ".opencode", "node_modules", "pkg", "agents", "ignored.md"),
2059+
`---
2060+
model: test/model
2061+
---
2062+
Ignored agent prompt`,
2063+
)
2064+
yield* FSUtil.use.writeWithDirs(
2065+
path.join(test.directory, ".opencode", "agents", "loaded.md"),
2066+
`---
2067+
model: test/model
2068+
---
2069+
Loaded agent prompt`,
2070+
)
2071+
yield* FSUtil.use.writeWithDirs(
2072+
path.join(test.directory, ".opencode", "node_modules", "pkg", "commands", "ignored.md"),
2073+
`---
2074+
description: ignored
2075+
---
2076+
Ignored command template`,
2077+
)
2078+
yield* FSUtil.use.writeWithDirs(
2079+
path.join(test.directory, ".opencode", "commands", "loaded.md"),
2080+
`---
2081+
description: loaded
2082+
---
2083+
Loaded command template`,
2084+
)
2085+
2086+
const config = yield* Config.use.get()
2087+
2088+
expect(config.agent?.["loaded"]).toMatchObject({
2089+
name: "loaded",
2090+
model: "test/model",
2091+
prompt: "Loaded agent prompt",
2092+
})
2093+
expect(config.agent?.["pkg/agents/ignored"]).toBeUndefined()
2094+
2095+
expect(config.command?.["loaded"]).toEqual({
2096+
description: "loaded",
2097+
template: "Loaded command template",
2098+
})
2099+
expect(config.command?.["pkg/commands/ignored"]).toBeUndefined()
2100+
}),
2101+
)

‎packages/opencode/test/skill/skill.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,44 @@ Just some content without YAML frontmatter.
211211
),
212212
)
213213

214+
it.live("ignores skills under .opencode/node_modules", () =>
215+
provideTmpdirInstance(
216+
(dir) =>
217+
Effect.gen(function* () {
218+
yield* Effect.promise(() =>
219+
Bun.write(
220+
path.join(dir, ".opencode", "skill", "kept-skill", "SKILL.md"),
221+
`---
222+
name: kept-skill
223+
description: Should be discovered.
224+
---
225+
226+
# Kept Skill
227+
`,
228+
),
229+
)
230+
yield* Effect.promise(() =>
231+
Bun.write(
232+
path.join(dir, ".opencode", "node_modules", "pkg", "skill", "ignored-skill", "SKILL.md"),
233+
`---
234+
name: ignored-skill
235+
description: Should be ignored.
236+
---
237+
238+
# Ignored Skill
239+
`,
240+
),
241+
)
242+
243+
const skill = yield* Skill.Service
244+
const list = (yield* skill.all()).filter((s) => s.location !== "<built-in>")
245+
expect(list.find((x) => x.name === "kept-skill")).toBeDefined()
246+
expect(list.find((x) => x.name === "ignored-skill")).toBeUndefined()
247+
}),
248+
{ git: true },
249+
),
250+
)
251+
214252
it.live("discovers skills without descriptions", () =>
215253
provideTmpdirInstance(
216254
(dir) =>

‎packages/opencode/test/util/glob.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ describe("Glob", () => {
115115

116116
expect(results).toEqual(["visible"])
117117
})
118+
119+
test("supports ignore patterns", async () => {
120+
await using tmp = await tmpdir()
121+
await fs.mkdir(path.join(tmp.path, "node_modules", "pkg"), { recursive: true })
122+
await fs.writeFile(path.join(tmp.path, "node_modules", "pkg", "blocked.md"), "", "utf-8")
123+
await fs.writeFile(path.join(tmp.path, "allowed.md"), "", "utf-8")
124+
125+
const results = await Glob.scan("**/*.md", { cwd: tmp.path, ignore: ["**/node_modules/**"] })
126+
127+
expect(results).toEqual(["allowed.md"])
128+
})
118129
})
119130

120131
describe("scanSync()", () => {

0 commit comments

Comments
 (0)