fix(ultrawork): use session agent fallback and skip same-model override
This commit is contained in:
parent
5647cf83cd
commit
eb0931ed6d
@ -140,6 +140,6 @@ export function createChatMessageHandler(args: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyUltraworkModelOverrideOnMessage(pluginConfig, input.agent, output, ctx.client.tui)
|
applyUltraworkModelOverrideOnMessage(pluginConfig, input.agent, output, ctx.client.tui, input.sessionID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, test, beforeEach, afterEach, spyOn, mock } from "bun:test"
|
import { describe, expect, test, beforeEach, afterEach, spyOn } from "bun:test"
|
||||||
import {
|
import {
|
||||||
applyUltraworkModelOverrideOnMessage,
|
applyUltraworkModelOverrideOnMessage,
|
||||||
resolveUltraworkOverride,
|
resolveUltraworkOverride,
|
||||||
@ -6,6 +6,7 @@ import {
|
|||||||
} from "./ultrawork-model-override"
|
} from "./ultrawork-model-override"
|
||||||
import * as sharedModule from "../shared"
|
import * as sharedModule from "../shared"
|
||||||
import * as dbOverrideModule from "./ultrawork-db-model-override"
|
import * as dbOverrideModule from "./ultrawork-db-model-override"
|
||||||
|
import * as sessionStateModule from "../features/claude-code-session-state"
|
||||||
|
|
||||||
describe("detectUltrawork", () => {
|
describe("detectUltrawork", () => {
|
||||||
test("should detect ultrawork keyword", () => {
|
test("should detect ultrawork keyword", () => {
|
||||||
@ -197,6 +198,22 @@ describe("resolveUltraworkOverride", () => {
|
|||||||
//#then
|
//#then
|
||||||
expect(result).toEqual({ providerID: "anthropic", modelID: "claude-opus-4-6", variant: undefined })
|
expect(result).toEqual({ providerID: "anthropic", modelID: "claude-opus-4-6", variant: undefined })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should use session agent when input and message agents are undefined", () => {
|
||||||
|
//#given
|
||||||
|
const config = createConfig("sisyphus", { model: "anthropic/claude-opus-4-6", variant: "max" })
|
||||||
|
const output = createOutput("ultrawork do something")
|
||||||
|
const getSessionAgentSpy = spyOn(sessionStateModule, "getSessionAgent").mockReturnValue("sisyphus")
|
||||||
|
|
||||||
|
//#when
|
||||||
|
const result = resolveUltraworkOverride(config, undefined, output, "ses_test")
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(getSessionAgentSpy).toHaveBeenCalledWith("ses_test")
|
||||||
|
expect(result).toEqual({ providerID: "anthropic", modelID: "claude-opus-4-6", variant: "max" })
|
||||||
|
|
||||||
|
getSessionAgentSpy.mockRestore()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("applyUltraworkModelOverrideOnMessage", () => {
|
describe("applyUltraworkModelOverrideOnMessage", () => {
|
||||||
@ -378,4 +395,26 @@ describe("applyUltraworkModelOverrideOnMessage", () => {
|
|||||||
"max",
|
"max",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should skip override trigger when current model already matches ultrawork model", () => {
|
||||||
|
//#given
|
||||||
|
const config = createConfig("sisyphus", { model: "anthropic/claude-opus-4-6", variant: "max" })
|
||||||
|
const output = createOutput("ultrawork do something", {
|
||||||
|
existingModel: { providerID: "anthropic", modelID: "claude-opus-4-6" },
|
||||||
|
messageId: "msg_123",
|
||||||
|
})
|
||||||
|
let toastCalled = false
|
||||||
|
const tui = {
|
||||||
|
showToast: async () => {
|
||||||
|
toastCalled = true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
//#when
|
||||||
|
applyUltraworkModelOverrideOnMessage(config, "sisyphus", output, tui)
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(dbOverrideSpy).not.toHaveBeenCalled()
|
||||||
|
expect(toastCalled).toBe(false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { OhMyOpenCodeConfig } from "../config"
|
import type { OhMyOpenCodeConfig } from "../config"
|
||||||
import type { AgentOverrides } from "../config/schema/agent-overrides"
|
import type { AgentOverrides } from "../config/schema/agent-overrides"
|
||||||
|
import { getSessionAgent } from "../features/claude-code-session-state"
|
||||||
import { log } from "../shared"
|
import { log } from "../shared"
|
||||||
import { getAgentConfigKey } from "../shared/agent-display-names"
|
import { getAgentConfigKey } from "../shared/agent-display-names"
|
||||||
import { scheduleDeferredModelOverride } from "./ultrawork-db-model-override"
|
import { scheduleDeferredModelOverride } from "./ultrawork-db-model-override"
|
||||||
@ -35,6 +36,18 @@ export type UltraworkOverrideResult = {
|
|||||||
variant?: string
|
variant?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSameModel(
|
||||||
|
current: unknown,
|
||||||
|
target: { providerID: string; modelID: string },
|
||||||
|
): boolean {
|
||||||
|
if (typeof current !== "object" || current === null) return false
|
||||||
|
const currentRecord = current as Record<string, unknown>
|
||||||
|
return (
|
||||||
|
currentRecord["providerID"] === target.providerID
|
||||||
|
&& currentRecord["modelID"] === target.modelID
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the ultrawork model override config for the given agent and prompt text.
|
* Resolves the ultrawork model override config for the given agent and prompt text.
|
||||||
* Returns null if no override should be applied.
|
* Returns null if no override should be applied.
|
||||||
@ -46,13 +59,15 @@ export function resolveUltraworkOverride(
|
|||||||
message: Record<string, unknown>
|
message: Record<string, unknown>
|
||||||
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
||||||
},
|
},
|
||||||
|
sessionID?: string,
|
||||||
): UltraworkOverrideResult | null {
|
): UltraworkOverrideResult | null {
|
||||||
const promptText = extractPromptText(output.parts)
|
const promptText = extractPromptText(output.parts)
|
||||||
if (!detectUltrawork(promptText)) return null
|
if (!detectUltrawork(promptText)) return null
|
||||||
|
|
||||||
const messageAgentName =
|
const messageAgentName =
|
||||||
typeof output.message["agent"] === "string" ? (output.message["agent"] as string) : undefined
|
typeof output.message["agent"] === "string" ? (output.message["agent"] as string) : undefined
|
||||||
const rawAgentName = inputAgentName ?? messageAgentName
|
const sessionAgentName = sessionID ? getSessionAgent(sessionID) : undefined
|
||||||
|
const rawAgentName = inputAgentName ?? messageAgentName ?? sessionAgentName
|
||||||
if (!rawAgentName || !pluginConfig.agents) return null
|
if (!rawAgentName || !pluginConfig.agents) return null
|
||||||
|
|
||||||
const agentConfigKey = getAgentConfigKey(rawAgentName)
|
const agentConfigKey = getAgentConfigKey(rawAgentName)
|
||||||
@ -94,8 +109,9 @@ export function applyUltraworkModelOverrideOnMessage(
|
|||||||
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
||||||
},
|
},
|
||||||
tui: unknown,
|
tui: unknown,
|
||||||
|
sessionID?: string,
|
||||||
): void {
|
): void {
|
||||||
const override = resolveUltraworkOverride(pluginConfig, inputAgentName, output)
|
const override = resolveUltraworkOverride(pluginConfig, inputAgentName, output, sessionID)
|
||||||
if (!override) return
|
if (!override) return
|
||||||
|
|
||||||
if (!override.providerID || !override.modelID) {
|
if (!override.providerID || !override.modelID) {
|
||||||
@ -106,10 +122,16 @@ export function applyUltraworkModelOverrideOnMessage(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const targetModel = { providerID: override.providerID, modelID: override.modelID }
|
||||||
|
if (isSameModel(output.message.model, targetModel)) {
|
||||||
|
log(`[ultrawork-model-override] Skip override; target model already active: ${override.modelID}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const messageId = output.message["id"] as string | undefined
|
const messageId = output.message["id"] as string | undefined
|
||||||
if (!messageId) {
|
if (!messageId) {
|
||||||
log("[ultrawork-model-override] No message ID found, falling back to direct mutation")
|
log("[ultrawork-model-override] No message ID found, falling back to direct mutation")
|
||||||
output.message.model = { providerID: override.providerID, modelID: override.modelID }
|
output.message.model = targetModel
|
||||||
if (override.variant) {
|
if (override.variant) {
|
||||||
output.message["variant"] = override.variant
|
output.message["variant"] = override.variant
|
||||||
output.message["thinking"] = override.variant
|
output.message["thinking"] = override.variant
|
||||||
@ -125,7 +147,7 @@ export function applyUltraworkModelOverrideOnMessage(
|
|||||||
|
|
||||||
scheduleDeferredModelOverride(
|
scheduleDeferredModelOverride(
|
||||||
messageId,
|
messageId,
|
||||||
{ providerID: override.providerID, modelID: override.modelID },
|
targetModel,
|
||||||
override.variant,
|
override.variant,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user