Merge PR #6973: fix(coding-agent): share parent local:// root with /tan clone (@roboomp)

This commit is contained in:
can1357
2026-07-29 23:08:44 +02:00
6 changed files with 100 additions and 4 deletions
@@ -390,8 +390,9 @@ export class LocalProtocolHandler implements ProtocolHandler {
/**
* Install a process-global override that wins over the AgentRegistry-based
* derivation. Used by SDK consumers that wire `localProtocolOptions` on
* `createAgentSession` and by subagents that share their parent's root.
* derivation. Used by top-level SDK consumers that wire
* `localProtocolOptions` on `createAgentSession`; subagents keep their
* inherited mapping session-bound.
*/
static setOverride(value: LocalProtocolOptions | undefined): void {
LocalProtocolHandler.#override = value;
@@ -80,6 +80,19 @@ export class TanCommandController {
const ownerId = session.getAgentId() ?? MAIN_AGENT_ID;
const mcpManager = this.ctx.mcpManager;
const cwd = this.ctx.sessionManager.getCwd();
const parentArtifactsDir = this.ctx.sessionManager.getArtifactsDir();
// Snapshot the parent session's local:// mapping when dispatching. The
// interactive SessionManager is mutable and may switch transcripts while
// this background tan is still running. Use the session-manager id (not
// `session.sessionId`, which can diverge after `/fresh` or a provider
// session override) so the tan resolves the same local root the parent's
// large-paste writes and `local://` reads use — notably the Windows
// short-root fallback keys `%TEMP%/omp-local/<id>` off this id.
const parentLocalSessionId = this.ctx.sessionManager.getSessionId();
const localProtocolOptions = {
getArtifactsDir: () => parentArtifactsDir,
getSessionId: () => parentLocalSessionId,
};
// Nest the clone inside the parent's artifact directory (like a subagent
// session) rather than as a top-level sibling, so it shares the parent's
// artifacts in place — no copy needed.
@@ -132,6 +145,7 @@ export class TanCommandController {
parentAgentId: ownerId,
agentRegistry,
disableExtensionDiscovery: true,
localProtocolOptions,
});
clone = created.session;
clone.sessionManager?.appendSessionInit?.({
+1 -1
View File
@@ -1773,7 +1773,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
getArtifactsDir,
getSessionId: () => sessionManager.getSessionId?.() ?? null,
};
if (options.localProtocolOptions) {
if (options.localProtocolOptions && !options.parentTaskPrefix) {
LocalProtocolHandler.setOverride(options.localProtocolOptions);
}
toolSession.getArtifactsDir = getArtifactsDir;