diff --git a/src/auto-reply/reply/directive-handling.model.test.ts b/src/auto-reply/reply/directive-handling.model.test.ts index dd746f12e1c..21fc75efc18 100644 --- a/src/auto-reply/reply/directive-handling.model.test.ts +++ b/src/auto-reply/reply/directive-handling.model.test.ts @@ -25,6 +25,7 @@ import { clearRuntimeAuthProfileStoreSnapshots, replaceRuntimeAuthProfileStoreSnapshots, } from "../../agents/auth-profiles.js"; +import { resolveAgentDir, resolveSessionAgentId } from "../../agents/agent-scope.js"; import type { ModelAliasIndex } from "../../agents/model-selection.js"; import type { OpenClawConfig } from "../../config/config.js"; import type { SessionEntry } from "../../config/sessions.js"; @@ -105,6 +106,8 @@ beforeEach(() => { store: { version: 1, profiles: {} }, }, ]); + vi.mocked(resolveAgentDir).mockReset().mockReturnValue(TEST_AGENT_DIR); + vi.mocked(resolveSessionAgentId).mockReset().mockReturnValue("main"); liveModelSwitchMocks.requestLiveSessionModelSwitch.mockReset().mockReturnValue(false); queueMocks.refreshQueuedFollowupSession.mockReset(); }); @@ -475,6 +478,23 @@ describe("/model chat UX", () => { expect(sessionEntry.authProfileOverride).toBe(OPENAI_DATE_PROFILE_ID); }); + it("resolves agentDir from the target session agent before wrapper agentDir", async () => { + vi.mocked(resolveSessionAgentId).mockReturnValue("target"); + vi.mocked(resolveAgentDir).mockReturnValue("/tmp/target-agent"); + + await persistModelDirectiveForTest({ + command: "/model openai/gpt-4o hello", + allowedModelKeys: ["openai/gpt-4o"], + sessionEntry: createSessionEntry(), + }); + + expect(resolveSessionAgentId).toHaveBeenCalledWith({ + sessionKey: "agent:main:dm:1", + config: expect.any(Object), + }); + expect(resolveAgentDir).toHaveBeenCalledWith(expect.any(Object), "target"); + }); + it("persists explicit auth profiles after @YYYYMMDD version suffixes in mixed-content messages", async () => { const { sessionEntry } = await persistModelDirectiveForTest({ command: `/model custom/vertex-ai_claude-haiku-4-5@${OPENAI_DATE_PROFILE_ID}@work hello`, diff --git a/src/auto-reply/reply/directive-handling.persist.ts b/src/auto-reply/reply/directive-handling.persist.ts index 433798b081a..15c2e6c1f2e 100644 --- a/src/auto-reply/reply/directive-handling.persist.ts +++ b/src/auto-reply/reply/directive-handling.persist.ts @@ -76,7 +76,7 @@ export async function persistInlineDirectives(params: { const activeAgentId = sessionKey ? resolveSessionAgentId({ sessionKey, config: cfg }) : resolveDefaultAgentId(cfg); - const agentDir = params.agentDir ?? resolveAgentDir(cfg, activeAgentId); + const agentDir = resolveAgentDir(cfg, activeAgentId) ?? params.agentDir; if (sessionEntry && sessionStore && sessionKey) { const prevElevatedLevel =