Skip to content

fix: include user/project agents in task(subagent_type) resolution#2690

Open
trafgals wants to merge 2 commits intocode-yeongyu:devfrom
trafgals:fix/user-agents-callable
Open

fix: include user/project agents in task(subagent_type) resolution#2690
trafgals wants to merge 2 commits intocode-yeongyu:devfrom
trafgals:fix/user-agents-callable

Conversation

@trafgals
Copy link
Copy Markdown

@trafgals trafgals commented Mar 19, 2026

Summary

Fixes user agents (from ~/.config/opencode/agents/*.md) and project agents (from .claude/agents/) not being callable via task(subagent_type="...").

Root Cause

In resolveSubagentExecution(), only server-registered agents were queried via client.app.agents(). User/project agents were loaded locally via loadUserAgents() / loadProjectAgents() but never merged into the callable agent list.

Changes

  • subagent-resolver.ts: Merge user and project agents into the server agent list. Server agents take precedence on name collisions. Also fixes a bug where isPrimaryAgent was checking callableAgents (which excludes primary) for mode === "primary", always returning empty.

  • subagent-resolver.test.ts: Added 6 tests covering:

    • User agent resolution when server returns empty
    • Project agent resolution when server returns empty
    • Server agent precedence over user agent on name collision
    • Error message for primary-mode user agents
    • User/project agents appearing in available agents error
    • Simultaneous merge of user and project agents

Testing

  • npx tsc --noEmit passes
  • npx bun test src/tools/delegate-task/subagent-resolver.test.ts — 11 tests pass

Summary by cubic

Enables calling user and project agents via task(subagent_type) by merging them with server agents and passing the project directory to client.app.agents() for native resolution. Also fixes primary-agent detection to return the correct error when a primary agent is requested.

  • Bug Fixes
    • Merge user agents from ~/.config/opencode/agents/*.md and project agents from .claude/agents/ into resolveSubagentExecution(); dedupe by name with server agents first.
    • Pass directory to client.app.agents({ query: { directory } }) so server returns project-scoped agents.
    • Detect primary agents using the full merged list and check mode === "primary", fixing false negatives.
    • Include user/project agents in the “available agents” error; add tests for resolution, precedence, primary-mode error, and merged availability.

Written for commit f455f49. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 19, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Previously, user agents loaded from ~/.config/opencode/agents/*.md and
project agents from .claude/agents/ were not callable via task(subagent_type=...).
They were loaded locally but never registered with the OpenCode server.

This commit merges user and project agents into the server agent list in
resolveSubagentExecution(), allowing them to be called via task() just like
built-in agents. Server agents take precedence on name collisions.

Also fixes a bug where the isPrimaryAgent check was filtering callableAgents
(which excludes primary) for mode==='primary', always returning empty.
@trafgals trafgals force-pushed the fix/user-agents-callable branch from 5de1ba8 to 238ba27 Compare March 19, 2026 04:20
@trafgals
Copy link
Copy Markdown
Author

recheck

@trafgals
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Mar 19, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 3/5

  • There is a concrete behavior gap in src/tools/delegate-task/subagent-resolver.ts: not passing directory to client.app.agents({ directory }) can exclude native Opencode project agents from resolution.
  • Given the severity (7/10) and high confidence (10/10), this is a meaningful user-impacting risk for agent discovery rather than a cosmetic issue, so merge risk is moderate.
  • Pay close attention to src/tools/delegate-task/subagent-resolver.ts - ensure the resolver includes the directory parameter so both native Opencode agents and .claude/agents are considered.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tools/delegate-task/subagent-resolver.ts">

<violation number="1" location="src/tools/delegate-task/subagent-resolver.ts:23">
P1: Custom agent: **Opencode Compatibility**

Pass the `directory` parameter to `client.app.agents({ directory })` so that native Opencode project agents are included in the resolution, not just the `.claude/agents` markdown ones.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Resolves cubic's review comment - include native Opencode project
agents in resolution by passing directory as a query param.
@trafgals
Copy link
Copy Markdown
Author

@cubic-dev-ai Fixed! Changed client.app.agents() to client.app.agents({ query: { directory } }) so native Opencode project agents are included in resolution. TypeScript compiles clean and all 11 tests pass.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Auto-approved: The changes correctly implement agent merging with proper precedence and fix a logic bug in primary agent detection. Extensive tests cover all new logic paths.

Copy link
Copy Markdown
Owner

@code-yeongyu code-yeongyu left a comment

Choose a reason for hiding this comment

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

Good fix. User/project agents were being loaded locally but never merged into the agent lookup that task(subagent_type) uses — only server-registered agents were checked. Merging user/project agents after server agents (server takes precedence) is the right priority order. Tests cover the key scenarios including user-only, project-only, server-overrides-user, and server-unavailable fallback. LGTM.

@code-yeongyu
Copy link
Copy Markdown
Owner

This PR has merge conflicts with recent merges on dev (likely #2891 or related changes to subagent-resolver.ts). Could you rebase on the latest dev branch? The fix is approved — merging user/project agents into the server agent list for task(subagent_type) resolution is exactly right. Just needs a rebase. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:bug-fix PR: Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants