feat(providers): expose agent cwd to provider processes (#2563)
This commit is contained in:
@@ -35,6 +35,7 @@ import type {
|
|||||||
AgentStreamEvent,
|
AgentStreamEvent,
|
||||||
AgentTimelineItem,
|
AgentTimelineItem,
|
||||||
ImportProviderSessionInput,
|
ImportProviderSessionInput,
|
||||||
|
ImportProviderSessionContext,
|
||||||
ResolveAgentDefaultModeInput,
|
ResolveAgentDefaultModeInput,
|
||||||
} from "./agent-sdk-types.js";
|
} from "./agent-sdk-types.js";
|
||||||
import type { PaseoToolCatalog } from "./tools/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,
|
agentId: snapshot.id,
|
||||||
env: {
|
env: {
|
||||||
PASEO_AGENT_ID: snapshot.id,
|
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,
|
agentId: resumed.id,
|
||||||
env: {
|
env: {
|
||||||
PASEO_AGENT_ID: resumed.id,
|
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 {
|
class ImportClient extends TestAgentClient {
|
||||||
listCalls = 0;
|
listCalls = 0;
|
||||||
importInput: unknown = null;
|
importInput: unknown = null;
|
||||||
|
importLaunchContext: AgentLaunchContext | undefined;
|
||||||
|
|
||||||
async listImportableSessions() {
|
async listImportableSessions() {
|
||||||
this.listCalls += 1;
|
this.listCalls += 1;
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async importSession(input: ImportProviderSessionInput) {
|
async importSession(input: ImportProviderSessionInput, context: ImportProviderSessionContext) {
|
||||||
this.importInput = input;
|
this.importInput = input;
|
||||||
|
this.importLaunchContext = context.launchContext;
|
||||||
return {
|
return {
|
||||||
session,
|
session,
|
||||||
config: { provider: "codex" as const, cwd: workdir },
|
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.listCalls).toBe(0);
|
||||||
expect(client.importInput).toEqual({ providerHandleId: "thread-selected", cwd: workdir });
|
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.lifecycle).toBe("idle");
|
||||||
expect(imported.historyPrimed).toBe(true);
|
expect(imported.historyPrimed).toBe(true);
|
||||||
expect(manager.getTimeline(imported.id)).toEqual([
|
expect(manager.getTimeline(imported.id)).toEqual([
|
||||||
@@ -2712,6 +2724,7 @@ test("reloadAgentSession passes daemon launch env through the provider launch co
|
|||||||
agentId: snapshot.id,
|
agentId: snapshot.id,
|
||||||
env: {
|
env: {
|
||||||
PASEO_AGENT_ID: snapshot.id,
|
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,
|
agentId: snapshot.id,
|
||||||
env: {
|
env: {
|
||||||
PASEO_AGENT_ID: snapshot.id,
|
PASEO_AGENT_ID: snapshot.id,
|
||||||
|
PASEO_AGENT_CWD: workdir,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1023,7 +1023,12 @@ export class AgentManager {
|
|||||||
const client = await this.requireAvailableClient({
|
const client = await this.requireAvailableClient({
|
||||||
provider: storedConfig.provider,
|
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 providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||||
const createOptions = this.buildCreateSessionOptions(options);
|
const createOptions = this.buildCreateSessionOptions(options);
|
||||||
const session = await client.createSession(providerLaunchConfig, launchContext, createOptions);
|
const session = await client.createSession(providerLaunchConfig, launchContext, createOptions);
|
||||||
@@ -1101,7 +1106,7 @@ export class AgentManager {
|
|||||||
`Provider '${handle.provider}' is not available. Please ensure the CLI is installed.`,
|
`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 providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||||
const session = await client.resumeSession(
|
const session = await client.resumeSession(
|
||||||
handle,
|
handle,
|
||||||
@@ -1148,7 +1153,7 @@ export class AgentManager {
|
|||||||
},
|
},
|
||||||
resolvedAgentId,
|
resolvedAgentId,
|
||||||
);
|
);
|
||||||
const launchContext = await this.buildLaunchContext(resolvedAgentId, client);
|
const launchContext = await this.buildLaunchContext(resolvedAgentId, client, storedConfig.cwd);
|
||||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||||
const imported = await client.importSession(
|
const imported = await client.importSession(
|
||||||
{
|
{
|
||||||
@@ -1229,7 +1234,7 @@ export class AgentManager {
|
|||||||
provider,
|
provider,
|
||||||
} as AgentSessionConfig;
|
} as AgentSessionConfig;
|
||||||
const { storedConfig, launchConfig } = await this.prepareSessionConfig(refreshConfig, agentId);
|
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 providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||||
|
|
||||||
const session = handle
|
const session = handle
|
||||||
@@ -4174,6 +4179,7 @@ export class AgentManager {
|
|||||||
private async buildLaunchContext(
|
private async buildLaunchContext(
|
||||||
agentId: string,
|
agentId: string,
|
||||||
client: AgentClient,
|
client: AgentClient,
|
||||||
|
cwd: string,
|
||||||
env?: Record<string, string>,
|
env?: Record<string, string>,
|
||||||
): Promise<AgentLaunchContext> {
|
): Promise<AgentLaunchContext> {
|
||||||
const context: AgentLaunchContext = {
|
const context: AgentLaunchContext = {
|
||||||
@@ -4181,6 +4187,7 @@ export class AgentManager {
|
|||||||
env: {
|
env: {
|
||||||
...env,
|
...env,
|
||||||
PASEO_AGENT_ID: agentId,
|
PASEO_AGENT_ID: agentId,
|
||||||
|
PASEO_AGENT_CWD: cwd,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user