From 8bddfd16293fee5921065be795481f3c8e190f57 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Tue, 28 Jul 2026 22:17:26 +0200 Subject: [PATCH] feat(providers): expose agent cwd to provider processes --- .../src/server/agent/agent-manager.test.ts | 16 +++++++++++++++- .../server/src/server/agent/agent-manager.ts | 15 +++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/server/src/server/agent/agent-manager.test.ts b/packages/server/src/server/agent/agent-manager.test.ts index 10dcea8f9..355c83fb4 100644 --- a/packages/server/src/server/agent/agent-manager.test.ts +++ b/packages/server/src/server/agent/agent-manager.test.ts @@ -35,6 +35,7 @@ import type { AgentStreamEvent, AgentTimelineItem, ImportProviderSessionInput, + ImportProviderSessionContext, ResolveAgentDefaultModeInput, } from "./agent-sdk-types.js"; import type { PaseoToolCatalog } from "./tools/types.js"; @@ -1706,6 +1707,7 @@ test("createAgent passes daemon launch env through the provider launch context", agentId: snapshot.id, env: { PASEO_AGENT_ID: snapshot.id, + PASEO_AGENT_CWD: workdir, }, }); }); @@ -2511,6 +2513,7 @@ test("resumeAgentFromPersistence keeps metadata config, applies overrides, and p agentId: resumed.id, env: { PASEO_AGENT_ID: resumed.id, + PASEO_AGENT_CWD: workdir, }, }); }); @@ -2525,14 +2528,16 @@ test("importProviderSession imports the selected session without listing and pub class ImportClient extends TestAgentClient { listCalls = 0; importInput: unknown = null; + importLaunchContext: AgentLaunchContext | undefined; async listImportableSessions() { this.listCalls += 1; return []; } - async importSession(input: ImportProviderSessionInput) { + async importSession(input: ImportProviderSessionInput, context: ImportProviderSessionContext) { this.importInput = input; + this.importLaunchContext = context.launchContext; return { session, config: { provider: "codex" as const, cwd: workdir }, @@ -2612,6 +2617,13 @@ test("importProviderSession imports the selected session without listing and pub expect(client.listCalls).toBe(0); expect(client.importInput).toEqual({ providerHandleId: "thread-selected", cwd: workdir }); + expect(client.importLaunchContext).toEqual({ + agentId: imported.id, + env: { + PASEO_AGENT_ID: imported.id, + PASEO_AGENT_CWD: workdir, + }, + }); expect(imported.lifecycle).toBe("idle"); expect(imported.historyPrimed).toBe(true); expect(manager.getTimeline(imported.id)).toEqual([ @@ -2712,6 +2724,7 @@ test("reloadAgentSession passes daemon launch env through the provider launch co agentId: snapshot.id, env: { PASEO_AGENT_ID: snapshot.id, + PASEO_AGENT_CWD: workdir, }, }); @@ -2723,6 +2736,7 @@ test("reloadAgentSession passes daemon launch env through the provider launch co agentId: snapshot.id, env: { PASEO_AGENT_ID: snapshot.id, + PASEO_AGENT_CWD: workdir, }, }); }); diff --git a/packages/server/src/server/agent/agent-manager.ts b/packages/server/src/server/agent/agent-manager.ts index dc87d3196..8ee2a23c3 100644 --- a/packages/server/src/server/agent/agent-manager.ts +++ b/packages/server/src/server/agent/agent-manager.ts @@ -1047,7 +1047,12 @@ export class AgentManager { const client = await this.requireAvailableClient({ provider: storedConfig.provider, }); - const launchContext = await this.buildLaunchContext(resolvedAgentId, client, options?.env); + const launchContext = await this.buildLaunchContext( + resolvedAgentId, + client, + storedConfig.cwd, + options?.env, + ); const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext); const createOptions = this.buildCreateSessionOptions(options); const session = await client.createSession(providerLaunchConfig, launchContext, createOptions); @@ -1125,7 +1130,7 @@ export class AgentManager { `Provider '${handle.provider}' is not available. Please ensure the CLI is installed.`, ); } - const launchContext = await this.buildLaunchContext(resolvedAgentId, client); + const launchContext = await this.buildLaunchContext(resolvedAgentId, client, storedConfig.cwd); const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext); const session = await client.resumeSession( handle, @@ -1172,7 +1177,7 @@ export class AgentManager { }, resolvedAgentId, ); - const launchContext = await this.buildLaunchContext(resolvedAgentId, client); + const launchContext = await this.buildLaunchContext(resolvedAgentId, client, storedConfig.cwd); const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext); const imported = await client.importSession( { @@ -1253,7 +1258,7 @@ export class AgentManager { provider, } as AgentSessionConfig; const { storedConfig, launchConfig } = await this.prepareSessionConfig(refreshConfig, agentId); - const launchContext = await this.buildLaunchContext(agentId, client); + const launchContext = await this.buildLaunchContext(agentId, client, storedConfig.cwd); const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext); const session = handle @@ -4253,6 +4258,7 @@ export class AgentManager { private async buildLaunchContext( agentId: string, client: AgentClient, + cwd: string, env?: Record, ): Promise { const context: AgentLaunchContext = { @@ -4260,6 +4266,7 @@ export class AgentManager { env: { ...env, PASEO_AGENT_ID: agentId, + PASEO_AGENT_CWD: cwd, }, }; if (