feat(task): add directory parameter for monorepo subagent dispatch#32351
Open
trin4ik wants to merge 2 commits into
Open
feat(task): add directory parameter for monorepo subagent dispatch#32351trin4ik wants to merge 2 commits into
trin4ik wants to merge 2 commits into
Conversation
Add an optional `directory` parameter to the task tool so a subagent can be dispatched into a specific (sub)project. When set, the agent registry, child session, prompt loop, AGENTS.md walk-up and skill discovery all resolve from that directory's instance instead of inheriting the parent session's directory. Omitting it preserves today's behavior. Implements anomalyco#29271. To keep cross-directory subagents observable, route their events by session lineage instead of by the child's own directory: - server: a directory subscription now receives events from every session whose tree is rooted in that directory (parent + descendant subagents), matched via parentID lineage with a per-connection root-directory cache. Global/instance events without an owning session keep exact-directory scoping. Gated by OPENCODE_EVENT_SUBTREE (default on). - app: when a directory-scoped event has no registered store (a child anchored in a subproject the UI never opened), fall back to routing session-scoped events to any store that already holds that session/message, so the child view stays live instead of freezing until it is re-entered. Also wires InstanceStore/InstanceLayer into the tool registry so the task tool can resolve target-directory instances.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #29271. Also partially helps #26304 and #29175 (subagent sessions and their permission/question prompts not updating live in the UI).
Type of change
What does this PR do?
Adds an optional
directoryargument to thetasktool so a subagent can run in a specific directory instead of always inheriting the parent session's. The point is monorepos: a subagent dispatched into, say,backend/apinow picks up that subproject'sAGENTS.md, agents and skills instead of the repo root's. Leavedirectoryout and behavior is unchanged.The second part is about events. The SSE stream is filtered by directory, so as soon as a subagent runs in a different directory its live events stop reaching the parent's subscription and the child view freezes in the TUI/web/desktop until you re-open it. I switched the server-side filter to match by session lineage (the directory of the session's root ancestor) instead of the child's own directory, and added a fallback in the app sync layer that routes session-scoped events to whichever store already holds that session. With that, subagent sessions render in realtime again.
Filtering events by directory feels like the wrong key now that people lean on worktrees and monorepos — one session tree can legitimately span several directories. Matching by the tree is more robust. I left it behind
OPENCODE_EVENT_SUBTREE(on by default, set to0for the old strict matching) in case maintainers want to gate or revert it.How did you verify your code works?
bun typecheckpasses forpackages/opencodeandpackages/app.serve+attach --dir <monorepo>, dispatched a subagent withdirectoryinto a subproject, and confirmed it resolved that subproject'sAGENTS.md/skills and that its output plus permission/question prompts showed up live in the subagent view.Checklist