Skip to content

Conversation

@malhashemi
Copy link
Contributor

@malhashemi malhashemi commented Dec 23, 2025

Summary

Implements per-agent skill filtering in the <available_skills> tool description, completing the feature originally proposed in #5930.

After #5930 was merged, the maintainer simplified it by removing per-agent filtering from the tool description (permissions were only checked at execution time). This PR adds the infrastructure to pass agent context to tool initialization, enabling the skill tool to filter its description based on agent permissions.

Problem

Without this change, agents see ALL skills in <available_skills>, including ones they can't use (permission = deny). This leads to:

  • Wasted tokens listing inaccessible skills
  • Agent confusion when it tries to load a denied skill
  • Poor UX when certain skills should be hidden from certain agents

Solution

Pass agent context through the tool initialization chain so the skill tool can filter <available_skills> by permissions.

Changes

Infrastructure (tool.ts, registry.ts, prompt.ts)

  • Add InitContext interface with optional agent field to Tool namespace
  • Update Tool.Info.init signature to accept (ctx?: InitContext)
  • Update ToolRegistry.tools() to accept optional agent and pass it to each tool's init()
  • Pass agent from SessionPrompt.resolveTools() to ToolRegistry.tools()

Skill Tool (tool/skill.ts)

  • Rewrite using explicit Tool.Info<typeof parameters> typing
  • Filter accessibleSkills by agent permissions in init(ctx)
  • Only skills where Wildcard.all(skill.name, permissions) !== "deny" appear in <available_skills>

Skill Registry (skill/skill.ts)

  • Add duplicate skill name detection with warning log

Behavior

With config:

{
  "permission": {
    "skill": {
      "documents-*": "deny",
      "experimental-*": "ask",
      "*": "allow"
    }
  }
}
Skill In <available_skills>? On Execute
documents-* ❌ Hidden Rejected
experimental-* ✅ Shown Prompts user
Others ✅ Shown Loads immediately

Agent-specific overrides work as expected:

# In agent frontmatter
permission:
  skill:
    "documents-*": "allow"  # This agent CAN see and use documents-* skills

Testing

  • bun run typecheck passes
  • bun test passes (320 pass, 1 skip)
  • ✅ Manually tested with multiple agents and permission patterns
  • Backwards compatible: existing tools without init(ctx) usage are unaffected

Pass agent context through tool initialization chain so the skill tool
can filter available_skills by agent permissions. Skills with 'deny'
permission are hidden from the tool description, preventing agents from
seeing skills they cannot access.

Changes:
- Add InitContext interface with optional agent to Tool namespace
- Update ToolRegistry.tools() to accept and pass agent to init()
- Filter skills in SkillTool.init() based on agent permissions
- Add duplicate skill name warning in Skill.all()

Follow-up to anomalyco#5930 per maintainer feedback.
- Update intro to mention on-demand loading via skill tool
- Add 'Configure permissions' section with pattern examples
- Add 'Override per agent' section for agent-specific permissions
- Add 'Disable the skill tool' section
- Update troubleshooting to include permission checks
@malhashemi malhashemi marked this pull request as ready for review December 23, 2025 00:52
@thdxr thdxr merged commit 3a54ab6 into anomalyco:dev Dec 23, 2025
2 checks passed
malhashemi added a commit to malhashemi/opencode-skills that referenced this pull request Dec 23, 2025
BREAKING CHANGE: This plugin is deprecated. Skills functionality is now built into OpenCode natively.

- Add graduation banner and migration guide
- Document directory change (.opencode/skills/ → skill/)
- Document config migration (tools → permission.skill)
- Add Thank You section acknowledging community support
- Promote opencode-sessions as the next plugin to try
- Move original README to collapsed Historical Documentation section

Native implementation PRs:
- anomalyco/opencode#5930 (v1.0.190)
- anomalyco/opencode#6000 (v1.0.191)
malhashemi added a commit to malhashemi/opencode-skills that referenced this pull request Dec 23, 2025
BREAKING CHANGE: This plugin is deprecated. Skills functionality is now built into OpenCode natively.

- Add graduation banner and migration guide
- Document directory change (.opencode/skills/ → skill/)
- Document config migration (tools → permission.skill)
- Add Thank You section acknowledging community support
- Promote opencode-sessions as the next plugin to try
- Move original README to collapsed Historical Documentation section

Native implementation PRs:
- anomalyco/opencode#5930 (v1.0.190)
- anomalyco/opencode#6000 (v1.0.191)
malhashemi added a commit to malhashemi/opencode-skills that referenced this pull request Dec 23, 2025
BREAKING CHANGE: This plugin is deprecated. Skills functionality is now built into OpenCode natively.

- Add graduation banner and migration guide
- Document directory change (.opencode/skills/ → skill/)
- Document config migration (tools → permission.skill)
- Add Thank You section acknowledging community support
- Promote opencode-sessions as the next plugin to try
- Move original README to collapsed Historical Documentation section

Native implementation PRs:
- anomalyco/opencode#5930 (v1.0.190)
- anomalyco/opencode#6000 (v1.0.191)
iljod pushed a commit to iljod/opencode that referenced this pull request Dec 23, 2025
@malhashemi malhashemi deleted the feat/skill-per-agent-filtering branch December 23, 2025 22:42
anntnzrb pushed a commit to anntnzrb/opencode-1 that referenced this pull request Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants