fix: include user/project agents in task(subagent_type) resolution#2690
fix: include user/project agents in task(subagent_type) resolution#2690trafgals wants to merge 2 commits intocode-yeongyu:devfrom
Conversation
|
All contributors have signed the CLA. Thank you! ✅ |
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.
5de1ba8 to
238ba27
Compare
|
recheck |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
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 passingdirectorytoclient.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 thedirectoryparameter so both native Opencode agents and.claude/agentsare 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-aiwith guidance or docs links (includingllms.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.
|
@cubic-dev-ai Fixed! Changed |
code-yeongyu
left a comment
There was a problem hiding this comment.
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.
|
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! |
Summary
Fixes user agents (from
~/.config/opencode/agents/*.md) and project agents (from.claude/agents/) not being callable viatask(subagent_type="...").Root Cause
In
resolveSubagentExecution(), only server-registered agents were queried viaclient.app.agents(). User/project agents were loaded locally vialoadUserAgents()/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 whereisPrimaryAgentwas checkingcallableAgents(which excludes primary) formode === "primary", always returning empty.subagent-resolver.test.ts: Added 6 tests covering:Testing
npx tsc --noEmitpassesnpx bun test src/tools/delegate-task/subagent-resolver.test.ts— 11 tests passSummary 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.~/.config/opencode/agents/*.mdand project agents from.claude/agents/intoresolveSubagentExecution(); dedupe by name with server agents first.directorytoclient.app.agents({ query: { directory } })so server returns project-scoped agents.mode === "primary", fixing false negatives.Written for commit f455f49. Summary will update on new commits.