mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-10 01:48:40 +00:00
fix(opencode): preserve skill resource paths (#34052)
This commit is contained in:
parent
753d312c28
commit
ae853561cd
3 changed files with 38 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
||||
import path from "path"
|
||||
import { InstanceState } from "@/effect/instance-state"
|
||||
import { EffectBridge } from "@/effect/bridge"
|
||||
import type { InstanceContext } from "@/project/instance-context"
|
||||
|
|
@ -132,12 +133,19 @@ export const layer = Layer.effect(
|
|||
|
||||
for (const item of yield* skill.all()) {
|
||||
if (commands[item.name]) continue
|
||||
const dir = item.location === "<built-in>" ? undefined : path.dirname(item.location)
|
||||
commands[item.name] = {
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
source: "skill",
|
||||
get template() {
|
||||
return item.content
|
||||
if (!dir) return item.content
|
||||
return [
|
||||
item.content,
|
||||
"",
|
||||
`Base directory for this skill: ${dir}`,
|
||||
"Relative paths in this skill (e.g., scripts/, references/) are relative to this base directory.",
|
||||
].join("\n")
|
||||
},
|
||||
hints: [],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
||||
import path from "path"
|
||||
import { pathToFileURL } from "url"
|
||||
import { Effect, Layer, Context, Schema } from "effect"
|
||||
import { NamedError } from "@opencode-ai/core/util/error"
|
||||
import type { Agent } from "@/agent/agent"
|
||||
|
|
@ -17,6 +16,7 @@ import { RuntimeFlags } from "@/effect/runtime-flags"
|
|||
import { Glob } from "@opencode-ai/core/util/glob"
|
||||
import { Discovery } from "./discovery"
|
||||
import { isRecord } from "@/util/record"
|
||||
import { escapeHtml } from "@/util/html"
|
||||
|
||||
const CLAUDE_EXTERNAL_DIR = ".claude"
|
||||
const AGENTS_EXTERNAL_DIR = ".agents"
|
||||
|
|
@ -339,7 +339,7 @@ export function fmt(list: Info[], opts: { verbose: boolean }) {
|
|||
" <skill>",
|
||||
` <name>${skill.name}</name>`,
|
||||
` <description>${skill.description}</description>`,
|
||||
` <location>${pathToFileURL(skill.location).href}</location>`,
|
||||
` <location>${escapeHtml(skill.location)}</location>`,
|
||||
" </skill>",
|
||||
]),
|
||||
"</available_skills>",
|
||||
|
|
|
|||
|
|
@ -77,6 +77,33 @@ const withHome = <A, E, R>(home: string, self: Effect.Effect<A, E, R>) =>
|
|||
)
|
||||
|
||||
describe("skill", () => {
|
||||
it.effect("formats verbose locations as XML-safe filesystem paths", () =>
|
||||
Effect.sync(() => {
|
||||
const output = Skill.fmt(
|
||||
[
|
||||
{
|
||||
name: "tagged-skill",
|
||||
description: "A tagged skill.",
|
||||
location: "/tmp/plugin.git#v1.3.0/SKILL.md",
|
||||
content: "",
|
||||
},
|
||||
{
|
||||
name: "built-in-skill",
|
||||
description: "A built-in skill.",
|
||||
location: "<built-in>",
|
||||
content: "",
|
||||
},
|
||||
],
|
||||
{ verbose: true },
|
||||
)
|
||||
|
||||
expect(output).toContain("<location>/tmp/plugin.git#v1.3.0/SKILL.md</location>")
|
||||
expect(output).toContain("<location><built-in></location>")
|
||||
expect(output).not.toContain("file://")
|
||||
expect(output).not.toContain("%23")
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("discovers skills from .opencode/skill/ directory", () =>
|
||||
provideTmpdirInstance(
|
||||
(dir) =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue