Skip to content

Conversation

@IgorWarzocha
Copy link
Owner

@IgorWarzocha IgorWarzocha commented Jan 4, 2026

Summary

This PR restructures the Opencode tool system and allows skills to be injected into subagents.

Changes

Skill System Improvements

  • Add skill field to Command, SubtaskPart, and Loop schemas
  • Implement automatic directory permission grants for loaded skills
  • Add proactive skill validation in Task tool
  • Inject explicit skill tool calls into subagent history
  • Move skill loading to system prompt for reliability

@gemini-code-assist

This comment was marked as off-topic.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent pull request that introduces significant improvements to the tool and skill systems. The adoption of RFC 2119 keywords and an XML-based structure for prompts is a fantastic step towards clearer and more maintainable agent instructions. The new skill system is well-designed, with robust features like permission checks and a clever context injection mechanism. The code changes are consistent and well-implemented across the board.

I've identified a few minor areas for improvement in packages/opencode/src/session/prompt.ts related to code clarity and structure. These are not critical but could enhance the long-term maintainability of the new logic. Overall, this is a high-quality contribution.

@IgorWarzocha IgorWarzocha force-pushed the feat/task-tool-skills branch from b91b466 to ff0f1e8 Compare January 4, 2026 00:41
@IgorWarzocha IgorWarzocha changed the title feat: restructure tools with XML/RFC 2119 and enhance skill system feat: enhance task tool with skill system Jan 4, 2026
@IgorWarzocha IgorWarzocha force-pushed the feat/task-tool-skills branch 2 times, most recently from 65cdf6c to ffb6393 Compare January 4, 2026 01:20
@IgorWarzocha IgorWarzocha force-pushed the feat/task-tool-skills branch from ffb6393 to 8202a86 Compare January 4, 2026 01:22
@IgorWarzocha
Copy link
Owner Author

/oc review the code

@opencode-agent
Copy link

opencode-agent bot commented Jan 4, 2026

Code Review

This PR adds a skill system to the task tool, enabling specialized knowledge and permissions to be injected into subagents. The implementation is well-structured and adds important capabilities to the opencode system.

Summary of Changes

  1. Schema Extensions: Added skill field to Command.Info, Command config, and SubtaskPart schemas
  2. Permission System: Skills now automatically grant directory permissions when loaded via input.skill
  3. Skill Validation: Task tool validates skills exist and agent has permission before execution (task.ts:42-59)
  4. Context Injection: Skills are loaded into subagent sessions with explicit tool call messages (prompt.ts:654-722)
  5. Integration: Skill field flows through commands → prompts → subtasks → task tool execution

Issues Identified

1. Minor: Unused local session updates in prompt.ts

Location: packages/opencode/src/session/prompt.ts:175-195

The code updates the local session.permission variable after calling Session.update(), but since loop() re-fetches the session from storage on each iteration, these local updates aren't used:

if (input.skill) {
  const skill = await Skill.get(input.skill)
  if (skill) {
    const dir = path.resolve(path.dirname(skill.location))
    const rules: PermissionNext.Rule[] = [...]
    await Session.update(session.id, (draft) => {
      draft.permission = [...(draft.permission ?? []), ...rules]
    })
  }
}

The Session.update() calls correctly persist the changes. The local session.permission assignments are redundant and could be removed for clarity.

2. Suggestion: Consider extracting injectSkillContext function

Location: packages/opencode/src/session/prompt.ts:654-722

The injectSkillContext function is 68 lines and adds complexity to the loop function. Consider extracting it to a separate module (e.g., src/session/skill-context.ts) to improve maintainability. This is a minor suggestion and not blocking.

Positive Aspects

  1. Clean integration: The skill system integrates naturally with existing permission and command systems
  2. Robust error handling: Clear error messages when skills don't exist or agents lack permissions
  3. Security-conscious: Explicit permission checks ensure agents can only access authorized skills
  4. Backward compatible: Skill field is optional, so existing functionality isn't affected
  5. Well-documented: Parameter descriptions clearly explain the skill option

Recommendation

Approved with minor comments

The code is production-ready. The issues noted are minor and don't affect correctness or security. Consider addressing the redundant session updates for cleaner code, and potentially extracting the skill context injection logic in a follow-up PR for improved maintainability.

New%20session%20-%202026-01-04T01%3A37%3A19.452Z
opencode session  |  github run

@IgorWarzocha
Copy link
Owner Author

/gemini summary

@gemini-code-assist
Copy link

Summary of Changes

This pull request significantly enhances the Opencode tool system by introducing a robust skill management framework. The changes allow for the injection of specialized skills into subagents, improving their capabilities and enabling more precise control over their actions. This refactoring aims to make agent interactions more secure, reliable, and context-aware, ultimately leading to more effective task execution.

Highlights

  • Skill System Integration: Introduced a 'skill' field across Command, SubtaskPart, and Loop schemas to enable the injection of specialized skills into subagents.
  • Automated Permission Grants: Implemented automatic directory permission grants for loaded skills, enhancing security and functionality for subagents.
  • Proactive Skill Validation: Added validation within the Task tool to ensure that specified skills exist and that agents have the necessary permissions before execution.
  • Explicit Skill Context Injection: Skills are now explicitly injected into subagent history as tool calls, improving traceability and providing clear context for agent operations.
  • Skill Loading Refinement: Moved the process of skill loading to the system prompt for increased reliability and consistency in how skills are made available to agents.
Changelog
  • packages/opencode/src/command/index.ts
    • Added an optional 'skill' field to the Command schema.
    • Included the 'skill' field when constructing Command.Info objects.
  • packages/opencode/src/config/config.ts
    • Extended the Config.Command type with an optional 'skill' property.
  • packages/opencode/src/session/llm.ts
    • Imported Skill, ConfigMarkdown, and path for skill-related functionalities.
  • packages/opencode/src/session/message-v2.ts
    • Added an optional 'skill' field to the SubtaskPart schema.
    • Added an optional 'skill' field to the Loop schema.
  • packages/opencode/src/session/prompt.ts
    • Imported Skill for skill management.
    • Added an optional 'skill' field to the SessionPrompt input.
    • Implemented logic to automatically grant directory permissions for loaded skills to the session.
    • Introduced a call to injectSkillContext to add skill information to the subagent's history.
    • Passed the 'skill' field through to the TaskTool input and Command definition.
  • packages/opencode/src/tool/task.ts
    • Added imports for Skill, ConfigMarkdown, path, PermissionNext, ulid, and Instance.
    • Included an optional 'skill' field in the TaskTool parameters.
    • Implemented validation checks to ensure the specified skill exists and the agent has permission to use it.
    • Passed the 'skill' parameter into the TaskTool metadata and the initial message for subagent sessions.
  • packages/opencode/src/tool/task.txt
    • Updated usage notes to inform users about the new optional 'skill' parameter for loading specialized instructions into subagent contexts.
Activity
  • gemini-code-assist[bot] provided an initial summary of changes.
  • IgorWarzocha requested a code review.
  • opencode-agent[bot] performed a detailed code review, highlighting schema extensions, permission system, skill validation, context injection, and overall integration. It also pointed out minor issues regarding redundant local session updates and suggested extracting the injectSkillContext function, ultimately approving the PR with minor comments.
  • gemini-code-assist[bot] also provided specific review comments on redundant local session updates in prompt.ts and suggested extracting the injectSkillContext function for better maintainability.
  • IgorWarzocha requested another summary.

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