
























@@ -127,6 +127,7 @@ export type SpawnSubagentParams = {
127127model?: string;
128128taskName?: string;
129129thinking?: string;
130+cwd?: string;
130131runTimeoutSeconds?: number;
131132thread?: boolean;
132133mode?: SpawnSubagentMode;
@@ -809,6 +810,7 @@ export async function spawnSubagentDirect(
809810};
810811}
811812const targetAgentId = requestedAgentId ? normalizeAgentId(requestedAgentId) : requesterAgentId;
813+const explicitWorkspaceDir = normalizeOptionalString(params.cwd);
812814const requesterOrigin = normalizeDeliveryContext({
813815channel: ctx.agentChannel,
814816accountId: ctx.agentAccountId,
@@ -1035,9 +1037,24 @@ export async function spawnSubagentDirect(
10351037| undefined;
10361038let attachmentAbsDir: string | undefined;
10371039let attachmentRootDir: string | undefined;
1040+const toolSpawnMetadata = mapToolContextToSpawnedRunMetadata({
1041+agentGroupId: ctx.agentGroupId,
1042+agentGroupChannel: ctx.agentGroupChannel,
1043+agentGroupSpace: ctx.agentGroupSpace,
1044+workspaceDir: ctx.workspaceDir,
1045+});
1046+const inheritedWorkspaceDir =
1047+targetAgentId !== requesterAgentId ? undefined : toolSpawnMetadata.workspaceDir;
1048+const spawnedWorkspaceDir = resolveSpawnedWorkspaceInheritance({
1049+config: cfg,
1050+ targetAgentId,
1051+explicitWorkspaceDir: explicitWorkspaceDir ?? inheritedWorkspaceDir,
1052+});
1053+10381054const materializedAttachments = await materializeSubagentAttachments({
10391055config: cfg,
10401056 targetAgentId,
1057+workspaceDir: spawnedWorkspaceDir,
10411058attachments: params.attachments,
10421059 mountPathHint,
10431060});
@@ -1070,23 +1087,10 @@ export async function spawnSubagentDirect(
10701087 task,
10711088});
107210891073-const toolSpawnMetadata = mapToolContextToSpawnedRunMetadata({
1074-agentGroupId: ctx.agentGroupId,
1075-agentGroupChannel: ctx.agentGroupChannel,
1076-agentGroupSpace: ctx.agentGroupSpace,
1077-workspaceDir: ctx.workspaceDir,
1078-});
10791090const spawnedMetadata = normalizeSpawnedRunMetadata({
10801091spawnedBy: spawnedByKey,
10811092 ...toolSpawnMetadata,
1082-workspaceDir: resolveSpawnedWorkspaceInheritance({
1083-config: cfg,
1084- targetAgentId,
1085-// For cross-agent spawns, ignore the caller's inherited workspace;
1086-// let targetAgentId resolve the correct workspace instead.
1087-explicitWorkspaceDir:
1088-targetAgentId !== requesterAgentId ? undefined : toolSpawnMetadata.workspaceDir,
1089-}),
1093+workspaceDir: spawnedWorkspaceDir,
10901094});
10911095const spawnLineagePatchError = await patchChildSession({
10921096spawnedBy: spawnedByKey,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。