fix(session): preserve custom agent after switching (#1017)
Use setSessionAgent (first-write wins) instead of updateSessionAgent in chat.message handler. This prevents the default agent from overwriting a custom agent that was set via UI switch. Fixes #893 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: justsisyphus <justsisyphus@users.noreply.github.com> Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
39d2d44e22
commit
f8155e7d45
@ -123,4 +123,40 @@ describe("claude-code-session-state", () => {
|
|||||||
expect(getSessionAgent(sessionID)).toBeUndefined()
|
expect(getSessionAgent(sessionID)).toBeUndefined()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("issue #893: custom agent switch reset", () => {
|
||||||
|
test("should preserve custom agent when default agent is sent on subsequent messages", () => {
|
||||||
|
// #given - user switches to custom agent "MyCustomAgent"
|
||||||
|
const sessionID = "test-session-custom"
|
||||||
|
const customAgent = "MyCustomAgent"
|
||||||
|
const defaultAgent = "Sisyphus"
|
||||||
|
|
||||||
|
// User switches to custom agent (via UI)
|
||||||
|
setSessionAgent(sessionID, customAgent)
|
||||||
|
expect(getSessionAgent(sessionID)).toBe(customAgent)
|
||||||
|
|
||||||
|
// #when - first message after switch sends default agent
|
||||||
|
// This simulates the bug: input.agent = "Sisyphus" on first message
|
||||||
|
// Using setSessionAgent (first-write wins) should preserve custom agent
|
||||||
|
setSessionAgent(sessionID, defaultAgent)
|
||||||
|
|
||||||
|
// #then - custom agent should be preserved, NOT overwritten
|
||||||
|
expect(getSessionAgent(sessionID)).toBe(customAgent)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should allow explicit agent update via updateSessionAgent", () => {
|
||||||
|
// #given - custom agent is set
|
||||||
|
const sessionID = "test-session-explicit"
|
||||||
|
const customAgent = "MyCustomAgent"
|
||||||
|
const newAgent = "AnotherAgent"
|
||||||
|
|
||||||
|
setSessionAgent(sessionID, customAgent)
|
||||||
|
|
||||||
|
// #when - explicit update (user intentionally switches)
|
||||||
|
updateSessionAgent(sessionID, newAgent)
|
||||||
|
|
||||||
|
// #then - should be updated
|
||||||
|
expect(getSessionAgent(sessionID)).toBe(newAgent)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -314,7 +314,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
|
|
||||||
"chat.message": async (input, output) => {
|
"chat.message": async (input, output) => {
|
||||||
if (input.agent) {
|
if (input.agent) {
|
||||||
updateSessionAgent(input.sessionID, input.agent);
|
setSessionAgent(input.sessionID, input.agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = (output as { message: { variant?: string } }).message
|
const message = (output as { message: { variant?: string } }).message
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user