Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,17 @@ export namespace Config {
})
export type Skills = z.infer<typeof Skills>

export const LegacySkill = z
.object({
name: z.string(),
description: z.string(),
command: z.string(),
})
.catchall(z.unknown())
export const LegacySkills = z.array(LegacySkill)
export type LegacySkill = z.infer<typeof LegacySkill>
export type LegacySkills = z.infer<typeof LegacySkills>

export const Agent = z
.object({
model: ModelId.optional(),
Expand Down Expand Up @@ -916,7 +927,10 @@ export namespace Config {
.record(z.string(), Command)
.optional()
.describe("Command configuration, see https://opencode.ai/docs/commands"),
skills: Skills.optional().describe("Additional skill folder paths"),
skills: z
.union([Skills, LegacySkills])
.optional()
.describe("Additional skill folder paths, remote skill URLs, or legacy inline skills"),
watcher: z
.object({
ignore: z.array(z.string()).optional(),
Expand Down
55 changes: 43 additions & 12 deletions packages/opencode/src/skill/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,56 @@ export namespace Skill {
}

const cfg = yield* config.get()
for (const item of cfg.skills?.paths ?? []) {
const expanded = item.startsWith("~/") ? path.join(os.homedir(), item.slice(2)) : item
const dir = path.isAbsolute(expanded) ? expanded : path.join(directory, expanded)
if (!(yield* fsys.isDir(dir))) {
log.warn("skill path not found", { path: dir })
continue
if (Array.isArray(cfg.skills)) {
for (const item of cfg.skills) {
if (state.skills[item.name]) {
log.warn("duplicate skill name", {
name: item.name,
existing: state.skills[item.name].location,
duplicate: path.join(directory, "opencode.json"),
})
}

state.skills[item.name] = {
name: item.name,
description: item.description,
location: path.join(directory, "opencode.json"),
content: [
"# Legacy Inline Skill",
"",
"This skill was loaded from the legacy `skills` array in `opencode.json`.",
"",
"```bash",
item.command,
"```",
].join("\n"),
}
}

yield* scan(state, bus, dir, SKILL_PATTERN)
}

for (const url of cfg.skills?.urls ?? []) {
const pulledDirs = yield* discovery.pull(url)
for (const dir of pulledDirs) {
state.dirs.add(dir)
if (!Array.isArray(cfg.skills)) {
for (const item of cfg.skills?.paths ?? []) {
const expanded = item.startsWith("~/") ? path.join(os.homedir(), item.slice(2)) : item
const dir = path.isAbsolute(expanded) ? expanded : path.join(directory, expanded)
if (!(yield* fsys.isDir(dir))) {
log.warn("skill path not found", { path: dir })
continue
}

yield* scan(state, bus, dir, SKILL_PATTERN)
}
}

if (!Array.isArray(cfg.skills)) {
for (const url of cfg.skills?.urls ?? []) {
const pulledDirs = yield* discovery.pull(url)
for (const dir of pulledDirs) {
state.dirs.add(dir)
yield* scan(state, bus, dir, SKILL_PATTERN)
}
}
}

log.info("init", { count: Object.keys(state.skills).length })
})

Expand Down
35 changes: 35 additions & 0 deletions packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,41 @@ test("handles command configuration", async () => {
})
})

test("accepts legacy skills array in opencode.json", async () => {
await using tmp = await tmpdir({
init: async (dir) => {
await Filesystem.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
skills: [
{
name: "test",
description: "Test skill",
command: "echo test",
},
],
}),
)
},
})

await Instance.provide({
directory: tmp.path,
fn: async () => {
const config = await Config.get()
expect(Array.isArray(config.skills)).toBe(true)
expect(config.skills).toEqual([
{
name: "test",
description: "Test skill",
command: "echo test",
},
])
},
})
})

test("migrates autoshare to share field", async () => {
await using tmp = await tmpdir({
init: async (dir) => {
Expand Down
33 changes: 33 additions & 0 deletions packages/opencode/test/skill/skill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,39 @@ test("returns empty array when no skills exist", async () => {
})
})

test("loads legacy inline skills from opencode.json", async () => {
await using tmp = await tmpdir({
git: true,
init: async (dir) => {
await Bun.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
skills: [
{
name: "test",
description: "Test skill",
command: "echo test",
},
],
}),
)
},
})

await Instance.provide({
directory: tmp.path,
fn: async () => {
const skills = await Skill.all()
expect(skills.length).toBe(1)
expect(skills[0].name).toBe("test")
expect(skills[0].description).toBe("Test skill")
expect(skills[0].location).toBe(path.join(tmp.path, "opencode.json"))
expect(skills[0].content).toContain("echo test")
},
})
})

test("discovers skills from .agents/skills/ directory", async () => {
await using tmp = await tmpdir({
git: true,
Expand Down
Loading