Skip to content

fix(skill): provide directory context in system prompt and slash-command paths#33787

Closed
shyuan wants to merge 1 commit into
anomalyco:devfrom
shyuan:fix/skill-directory-context
Closed

fix(skill): provide directory context in system prompt and slash-command paths#33787
shyuan wants to merge 1 commit into
anomalyco:devfrom
shyuan:fix/skill-directory-context

Conversation

@shyuan

@shyuan shyuan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #33786

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The skill's base directory was missing or URL-encoded in two code paths, preventing the agent from resolving bundled resources (references/, scripts/) relative to the skill install directory.

1. System prompt <available_skills> URL-encoded <location>

Skill.fmt() in packages/opencode/src/skill/index.ts used pathToFileURL(skill.location).href for the <location> field. This is the same bug #33580 fixed in the skill tool's base directory, but this second occurrence in the system prompt was missed. When a skill lives in a git-tagged plugin cache dir (e.g. ...git#v1.3.0), the agent sees ...git%23v1.3.0 and cannot use the path. Changed to emit skill.location directly.

2. Slash-command skills had no directory context

When a user types /skill-name, the skill is registered as a command (packages/opencode/src/command/index.ts) whose template returned only item.content — the raw SKILL.md body. Unlike the skill tool, there was no Base directory hint, so the agent had no way to locate bundled files. Added the base directory + relative-path hint to the template, matching the skill tool's output format.

How did you verify your code works?

  • bun test test/skill/skill.test.ts — 16 tests pass
  • bun test test/tool/skill.test.ts — 2 tests pass
  • Confirmed both code paths by reading the source: Skill.fmt() now emits a plain path, and skill-as-command templates now include the base directory line

Screenshots / recordings

N/A — no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

These appear to be complementary fixes for different aspects of skill context handling rather than direct duplicates.

No other duplicate PRs found addressing the same specific issues of URL-encoded <location> in Skill.fmt() or the missing base directory hint in slash-command templates.

@shyuan

shyuan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Re: the bot's note about #29429

Worth clarifying since the bot framed them as "complementary" — for bug 2 (slash-command skills lacking directory context), #29429 and this PR actually overlap on the same lines in command/index.ts, so they're alternative solutions rather than complementary:

  • fix(opencode): load full skill context for slash skills #29429 sets the slash template to "" and routes source === "skill" commands through skill.execute(...) in session/prompt.ts, producing the full skill context (including the ripgrep-sampled <skill_files> listing).
  • This PR keeps it lightweight: it just appends the Base directory hint to the template, matching the skill tool's wording but without the file listing.

I went with the lightweight approach because it resolves the reported symptom (agent can't locate bundled references//scripts/) with a minimal, self-contained change and no new execution path. If the maintainers prefer the richer file-listing behavior from #29429, bug 2 here can be dropped to avoid the conflict — but bug 1 (the pathToFileURL URL-encoding of <location> in Skill.fmt()) is independent and not touched by #29429, so that part stands on its own regardless.

@shyuan shyuan force-pushed the fix/skill-directory-context branch from 1602dcb to 26508f0 Compare June 26, 2026 04:04
The skill's base directory was missing or URL-encoded in two code
paths, preventing the agent from resolving bundled resources
(references/, scripts/) relative to the skill install directory.

1. System prompt <available_skills> <location> used pathToFileURL,
   URL-encoding characters like # from git-tagged plugin cache dirs.
   Emit the plain filesystem path instead — same fix as anomalyco#33580 but
   for the second occurrence in skill/index.ts fmt().

2. Skills invoked as slash commands (/skill-name) injected only the
   raw SKILL.md content into the prompt with no directory context at
   all. The agent had no way to locate bundled files. Inject the base
   directory hint, matching the skill tool's output format.
@shyuan shyuan force-pushed the fix/skill-directory-context branch from 26508f0 to 3aab7ef Compare June 26, 2026 04:39
@shyuan

shyuan commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #34052 (fix(opencode): preserve skill resource paths), which already landed on dev and fixes the same two code paths this PR targeted:

The only remaining unique change here was a doc-string typo (reference/references/) in tool/skill.ts, which has no functional impact. Closing in favor of #34052; the typo can be picked up in an unrelated change if needed.

@shyuan shyuan closed this Jun 28, 2026
@shyuan shyuan deleted the fix/skill-directory-context branch June 28, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(skill): skill directory context missing or URL-encoded in system prompt and slash-command paths

1 participant