fix(hooks): apply Sisyphus GPT-5.5 variant
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
|||||||
resolveRegisteredAgentName,
|
resolveRegisteredAgentName,
|
||||||
updateSessionAgent,
|
updateSessionAgent,
|
||||||
} from "../../features/claude-code-session-state"
|
} from "../../features/claude-code-session-state"
|
||||||
import { log } from "../../shared"
|
import { AGENT_MODEL_REQUIREMENTS, log } from "../../shared"
|
||||||
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
||||||
|
|
||||||
const TOAST_TITLE = "NEVER Use Sisyphus with GPT"
|
const TOAST_TITLE = "NEVER Use Sisyphus with GPT"
|
||||||
@@ -30,6 +30,18 @@ function showToast(ctx: PluginInput, sessionID: string): void {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNativeSisyphusGptVariant(model: { providerID: string; modelID: string }): string | undefined {
|
||||||
|
const chain = AGENT_MODEL_REQUIREMENTS["sisyphus"]?.fallbackChain ?? []
|
||||||
|
const exactMatch = chain.find((entry) =>
|
||||||
|
entry.providers.includes(model.providerID) && entry.model === model.modelID
|
||||||
|
)
|
||||||
|
if (exactMatch?.variant !== undefined) {
|
||||||
|
return exactMatch.variant
|
||||||
|
}
|
||||||
|
|
||||||
|
return chain.find((entry) => entry.model === model.modelID)?.variant
|
||||||
|
}
|
||||||
|
|
||||||
export function createNoSisyphusGptHook(ctx: PluginInput) {
|
export function createNoSisyphusGptHook(ctx: PluginInput) {
|
||||||
return {
|
return {
|
||||||
"chat.message": async (input: {
|
"chat.message": async (input: {
|
||||||
@@ -43,6 +55,20 @@ export function createNoSisyphusGptHook(ctx: PluginInput) {
|
|||||||
const agentKey = getAgentConfigKey(rawAgent)
|
const agentKey = getAgentConfigKey(rawAgent)
|
||||||
const modelID = input.model?.modelID
|
const modelID = input.model?.modelID
|
||||||
|
|
||||||
|
if (
|
||||||
|
agentKey === "sisyphus"
|
||||||
|
&& input.model
|
||||||
|
&& modelID
|
||||||
|
&& isGptNativeSisyphusModel(modelID)
|
||||||
|
&& output?.message
|
||||||
|
&& output.message.variant === undefined
|
||||||
|
) {
|
||||||
|
const variant = getNativeSisyphusGptVariant(input.model)
|
||||||
|
if (variant !== undefined) {
|
||||||
|
output.message.variant = variant
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (agentKey === "sisyphus" && modelID && isGptModel(modelID) && !isGptNativeSisyphusModel(modelID)) {
|
if (agentKey === "sisyphus" && modelID && isGptModel(modelID) && !isGptNativeSisyphusModel(modelID)) {
|
||||||
showToast(ctx, input.sessionID)
|
showToast(ctx, input.sessionID)
|
||||||
input.agent = resolveRegisteredAgentName("hephaestus") ?? "hephaestus"
|
input.agent = resolveRegisteredAgentName("hephaestus") ?? "hephaestus"
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
/// <reference types="bun-types" />
|
||||||
|
|
||||||
import { describe, expect, spyOn, test } from "bun:test"
|
import { describe, expect, spyOn, test } from "bun:test"
|
||||||
|
import type { PluginInput } from "@opencode-ai/plugin"
|
||||||
import { _resetForTesting, updateSessionAgent } from "../../features/claude-code-session-state"
|
import { _resetForTesting, updateSessionAgent } from "../../features/claude-code-session-state"
|
||||||
import { getAgentDisplayName } from "../../shared/agent-display-names"
|
import { getAgentDisplayName } from "../../shared/agent-display-names"
|
||||||
import { createNoSisyphusGptHook } from "./index"
|
import { createNoSisyphusGptHook } from "./index"
|
||||||
@@ -6,20 +9,29 @@ import { createNoSisyphusGptHook } from "./index"
|
|||||||
const SISYPHUS_DISPLAY = getAgentDisplayName("sisyphus")
|
const SISYPHUS_DISPLAY = getAgentDisplayName("sisyphus")
|
||||||
const HEPHAESTUS_DISPLAY = getAgentDisplayName("hephaestus")
|
const HEPHAESTUS_DISPLAY = getAgentDisplayName("hephaestus")
|
||||||
|
|
||||||
function createOutput() {
|
type HookOutput = {
|
||||||
|
message: { agent?: string; variant?: string; [key: string]: unknown }
|
||||||
|
parts: unknown[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function createOutput(): HookOutput {
|
||||||
return {
|
return {
|
||||||
message: {},
|
message: {},
|
||||||
parts: [],
|
parts: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createHookContext(showToast: (input: unknown) => Promise<unknown>): PluginInput {
|
||||||
|
return {
|
||||||
|
client: { tui: { showToast } },
|
||||||
|
} as unknown as PluginInput
|
||||||
|
}
|
||||||
|
|
||||||
describe("no-sisyphus-gpt hook", () => {
|
describe("no-sisyphus-gpt hook", () => {
|
||||||
test("shows toast on every chat.message when sisyphus uses gpt model", async () => {
|
test("shows toast on every chat.message when sisyphus uses gpt model", async () => {
|
||||||
// given - sisyphus (display name) with gpt model
|
// given - sisyphus (display name) with gpt model
|
||||||
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
const hook = createNoSisyphusGptHook({
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
client: { tui: { showToast } },
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
const output1 = createOutput()
|
const output1 = createOutput()
|
||||||
const output2 = createOutput()
|
const output2 = createOutput()
|
||||||
@@ -40,7 +52,8 @@ describe("no-sisyphus-gpt hook", () => {
|
|||||||
expect(showToast).toHaveBeenCalledTimes(2)
|
expect(showToast).toHaveBeenCalledTimes(2)
|
||||||
expect(output1.message.agent).toBe("hephaestus")
|
expect(output1.message.agent).toBe("hephaestus")
|
||||||
expect(output2.message.agent).toBe("hephaestus")
|
expect(output2.message.agent).toBe("hephaestus")
|
||||||
expect(showToast.mock.calls[0]?.[0]).toMatchObject({
|
const firstToastCall = (showToast.mock.calls as Array<Array<unknown>>)[0]?.[0]
|
||||||
|
expect(firstToastCall).toMatchObject({
|
||||||
body: {
|
body: {
|
||||||
title: "NEVER Use Sisyphus with GPT",
|
title: "NEVER Use Sisyphus with GPT",
|
||||||
message: expect.stringContaining("For other GPT models, always use Hephaestus."),
|
message: expect.stringContaining("For other GPT models, always use Hephaestus."),
|
||||||
@@ -52,9 +65,7 @@ describe("no-sisyphus-gpt hook", () => {
|
|||||||
test("does not show toast for gpt-5.4 model (Sisyphus has specialized support)", async () => {
|
test("does not show toast for gpt-5.4 model (Sisyphus has specialized support)", async () => {
|
||||||
// given - sisyphus with gpt-5.4 model (should be allowed)
|
// given - sisyphus with gpt-5.4 model (should be allowed)
|
||||||
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
const hook = createNoSisyphusGptHook({
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
client: { tui: { showToast } },
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
const output = createOutput()
|
const output = createOutput()
|
||||||
|
|
||||||
@@ -73,9 +84,7 @@ describe("no-sisyphus-gpt hook", () => {
|
|||||||
test("does not show toast for gpt-5.5 model (native Sisyphus support)", async () => {
|
test("does not show toast for gpt-5.5 model (native Sisyphus support)", async () => {
|
||||||
// given - sisyphus with gpt-5.5 model (should be allowed)
|
// given - sisyphus with gpt-5.5 model (should be allowed)
|
||||||
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
const hook = createNoSisyphusGptHook({
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
client: { tui: { showToast } },
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
const output = createOutput()
|
const output = createOutput()
|
||||||
|
|
||||||
@@ -91,12 +100,50 @@ describe("no-sisyphus-gpt hook", () => {
|
|||||||
expect(output.message.agent).toBeUndefined()
|
expect(output.message.agent).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("sets medium variant for gpt-5.5 model when native Sisyphus support is used", async () => {
|
||||||
|
// given - sisyphus with gpt-5.5 model and no selected variant
|
||||||
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
|
|
||||||
|
const output = createOutput()
|
||||||
|
|
||||||
|
// when - chat.message runs with gpt-5.5
|
||||||
|
await hook["chat.message"]?.({
|
||||||
|
sessionID: "ses_gpt55_medium",
|
||||||
|
agent: SISYPHUS_DISPLAY,
|
||||||
|
model: { providerID: "openai", modelID: "gpt-5.5" },
|
||||||
|
}, output)
|
||||||
|
|
||||||
|
// then - Sisyphus stays active and receives its configured GPT-5.5 variant
|
||||||
|
expect(showToast).toHaveBeenCalledTimes(0)
|
||||||
|
expect(output.message.agent).toBeUndefined()
|
||||||
|
expect(output.message.variant).toBe("medium")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("preserves selected variant for gpt-5.5 model when native Sisyphus support is used", async () => {
|
||||||
|
// given - sisyphus with gpt-5.5 model and a selected variant
|
||||||
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
|
|
||||||
|
const output: HookOutput = { message: { variant: "high" }, parts: [] }
|
||||||
|
|
||||||
|
// when - chat.message runs with gpt-5.5
|
||||||
|
await hook["chat.message"]?.({
|
||||||
|
sessionID: "ses_gpt55_high",
|
||||||
|
agent: SISYPHUS_DISPLAY,
|
||||||
|
model: { providerID: "openai", modelID: "gpt-5.5" },
|
||||||
|
}, output)
|
||||||
|
|
||||||
|
// then - user-selected variant is not overwritten
|
||||||
|
expect(showToast).toHaveBeenCalledTimes(0)
|
||||||
|
expect(output.message.agent).toBeUndefined()
|
||||||
|
expect(output.message.variant).toBe("high")
|
||||||
|
})
|
||||||
|
|
||||||
test("does not show toast for non-gpt model", async () => {
|
test("does not show toast for non-gpt model", async () => {
|
||||||
// given - sisyphus with claude model
|
// given - sisyphus with claude model
|
||||||
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
const hook = createNoSisyphusGptHook({
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
client: { tui: { showToast } },
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
const output = createOutput()
|
const output = createOutput()
|
||||||
|
|
||||||
@@ -115,9 +162,7 @@ describe("no-sisyphus-gpt hook", () => {
|
|||||||
test("does not show toast for non-sisyphus agent", async () => {
|
test("does not show toast for non-sisyphus agent", async () => {
|
||||||
// given - hephaestus with gpt model
|
// given - hephaestus with gpt model
|
||||||
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
const hook = createNoSisyphusGptHook({
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
client: { tui: { showToast } },
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
const output = createOutput()
|
const output = createOutput()
|
||||||
|
|
||||||
@@ -138,9 +183,7 @@ describe("no-sisyphus-gpt hook", () => {
|
|||||||
_resetForTesting()
|
_resetForTesting()
|
||||||
updateSessionAgent("ses_4", SISYPHUS_DISPLAY)
|
updateSessionAgent("ses_4", SISYPHUS_DISPLAY)
|
||||||
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
const showToast = spyOn({ fn: async () => ({}) }, "fn")
|
||||||
const hook = createNoSisyphusGptHook({
|
const hook = createNoSisyphusGptHook(createHookContext(showToast))
|
||||||
client: { tui: { showToast } },
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
const output = createOutput()
|
const output = createOutput()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user