From ffe50650e1bc6e5540afdaa7e53fadcc9cb2bc8a Mon Sep 17 00:00:00 2001 From: maatheusgois-dd Date: Wed, 22 Jul 2026 02:36:38 -0300 Subject: [PATCH] Propagate workspace roots into subagent sessions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subagents (task tool) now inherit the parent session's additionalDirectories via ToolSession → ExecutorOptions → CreateAgentSessionOptions, so delegated agents see the same block and can read/grep/glob added roots. Co-authored-by: oh-my-pi --- packages/coding-agent/src/sdk.ts | 3 +++ packages/coding-agent/src/task/executor.ts | 3 +++ packages/coding-agent/src/task/structured-subagent.ts | 1 + packages/coding-agent/src/tools/index.ts | 2 ++ 4 files changed, 9 insertions(+) diff --git a/packages/coding-agent/src/sdk.ts b/packages/coding-agent/src/sdk.ts index bafa23800..f1e1eee94 100644 --- a/packages/coding-agent/src/sdk.ts +++ b/packages/coding-agent/src/sdk.ts @@ -1665,6 +1665,9 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {} isToolActive: name => activeToolNames.has(name), setActiveToolNames, hasUI: options.hasUI ?? false, + get additionalDirectories() { + return sessionManager.getAdditionalDirectories(); + }, enableLsp, enableIrc: restrictToolNames ? false : options.enableIrc, restrictToolNames, diff --git a/packages/coding-agent/src/task/executor.ts b/packages/coding-agent/src/task/executor.ts index 220bd1f51..20e3f9ed3 100644 --- a/packages/coding-agent/src/task/executor.ts +++ b/packages/coding-agent/src/task/executor.ts @@ -287,6 +287,8 @@ function isRecord(value: unknown): value is Record { /** Options for subagent execution */ export interface ExecutorOptions { cwd: string; + /** Additional workspace directories to seed on the subagent session (multi-root). */ + additionalDirectories?: string[]; worktree?: string; agent: AgentDefinition; task: string; @@ -2539,6 +2541,7 @@ export async function runSubprocess(options: ExecutorOptions): Promise ({ cwd: worktree ?? cwd, + additionalDirectories: options.additionalDirectories, authStorage, modelRegistry, settings: subagentSettings, diff --git a/packages/coding-agent/src/task/structured-subagent.ts b/packages/coding-agent/src/task/structured-subagent.ts index e8a18ea05..9cf7448df 100644 --- a/packages/coding-agent/src/task/structured-subagent.ts +++ b/packages/coding-agent/src/task/structured-subagent.ts @@ -371,6 +371,7 @@ function buildExecutorOptions( const enableMCP = !policy.planMode && (session.enableMCP ?? true); return { cwd: session.cwd, + additionalDirectories: session.additionalDirectories, agent: policy.effectiveAgent, task: renderSubagentPrompt(request.assignment), assignment: request.assignment.trim(), diff --git a/packages/coding-agent/src/tools/index.ts b/packages/coding-agent/src/tools/index.ts index 1ca56486a..90a75a80c 100644 --- a/packages/coding-agent/src/tools/index.ts +++ b/packages/coding-agent/src/tools/index.ts @@ -143,6 +143,8 @@ export interface DeferredDiagnosticsEntry { export interface ToolSession { /** Current working directory */ cwd: string; + /** Additional workspace directories beyond cwd (multi-root), forwarded to subagents. */ + additionalDirectories?: string[]; /** Whether UI is available */ hasUI: boolean; /**