Skip to content

feat(task): add directory parameter for monorepo subagent dispatch#32351

Open
trin4ik wants to merge 2 commits into
anomalyco:devfrom
trin4ik:subagent-directory-events
Open

feat(task): add directory parameter for monorepo subagent dispatch#32351
trin4ik wants to merge 2 commits into
anomalyco:devfrom
trin4ik:subagent-directory-events

Conversation

@trin4ik

@trin4ik trin4ik commented Jun 14, 2026

Copy link
Copy Markdown

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

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an optional directory argument to the task tool 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/api now picks up that subproject's AGENTS.md, agents and skills instead of the repo root's. Leave directory out 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 to 0 for the old strict matching) in case maintainers want to gate or revert it.

How did you verify your code works?

  • bun typecheck passes for packages/opencode and packages/app.
  • Ran serve + attach --dir <monorepo>, dispatched a subagent with directory into a subproject, and confirmed it resolved that subproject's AGENTS.md/skills and that its output plus permission/question prompts showed up live in the subagent view.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
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.

[FEATURE]: add directory parameter to task tool for monorepo subagent dispatch

1 participant