Avoid stale agentDir in tools sessions

This commit is contained in:
Tak Hoffman
2026-04-10 19:49:20 -05:00
parent 9b95d65ea2
commit 4ba3ea30b0
2 changed files with 27 additions and 2 deletions

View File

@@ -346,4 +346,28 @@ describe("handleToolsCommand", () => {
}),
);
});
it("does not forward a stale ambient agentDir for session-bound /tools", async () => {
const { resolveSessionAgentId } = await import("../../agents/agent-scope.js");
vi.mocked(resolveSessionAgentId).mockReturnValue("target");
const { buildCommandTestParams, handleToolsCommand, resolveToolsMock } =
await loadToolsHarness();
const params = buildCommandTestParams("/tools", buildConfig(), undefined, {
workspaceDir: "/tmp",
});
params.agentId = "main";
params.agentDir = "/tmp/agents/main/agent";
params.sessionKey = "agent:target:whatsapp:direct:12345";
const result = await handleToolsCommand(params, true);
expect(result?.shouldContinue).toBe(false);
expect(resolveToolsMock).toHaveBeenCalledWith(
expect.objectContaining({
agentId: "target",
agentDir: undefined,
sessionKey: "agent:target:whatsapp:direct:12345",
}),
);
});
});

View File

@@ -115,7 +115,8 @@ export const handleToolsCommand: CommandHandler = async (params, allowTextComman
ctx: params.ctx,
command: params.command,
});
const agentId = params.sessionKey
const sessionBound = Boolean(params.sessionKey);
const agentId = sessionBound
? resolveSessionAgentId({ sessionKey: params.sessionKey, config: params.cfg })
: params.agentId;
const threadingContext = buildThreadingToolContext({
@@ -128,7 +129,7 @@ export const handleToolsCommand: CommandHandler = async (params, allowTextComman
agentId,
sessionKey: params.sessionKey,
workspaceDir: params.workspaceDir,
agentDir: params.agentDir,
agentDir: sessionBound ? undefined : params.agentDir,
modelProvider: params.provider,
modelId: params.model,
messageProvider: params.command.channel,