From cbceb3cd0d739c25fa557ea6bce47ee4d058551c Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 11 Mar 2026 15:59:14 +0900 Subject: [PATCH] Preserve ultrawork runtime variants Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/hooks/keyword-detector/hook.ts | 21 ++++++- src/hooks/keyword-detector/index.test.ts | 18 +++--- .../ultrawork-runtime-variant.test.ts | 57 +++++++++++++++++++ 3 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 src/hooks/keyword-detector/ultrawork-runtime-variant.test.ts diff --git a/src/hooks/keyword-detector/hook.ts b/src/hooks/keyword-detector/hook.ts index d55a73c37..8d7fcb15d 100644 --- a/src/hooks/keyword-detector/hook.ts +++ b/src/hooks/keyword-detector/hook.ts @@ -14,6 +14,14 @@ import { import type { ContextCollector } from "../../features/context-injector" export function createKeywordDetectorHook(ctx: PluginInput, _collector?: ContextCollector) { + function getRuntimeVariant(input: { variant?: string }, message: Record): string | undefined { + if (typeof message["variant"] === "string") { + return message["variant"] + } + + return typeof input.variant === "string" ? input.variant : undefined + } + return { "chat.message": async ( input: { @@ -21,6 +29,7 @@ export function createKeywordDetectorHook(ctx: PluginInput, _collector?: Context agent?: string model?: { providerID: string; modelID: string } messageID?: string + variant?: string }, output: { message: Record @@ -72,15 +81,21 @@ export function createKeywordDetectorHook(ctx: PluginInput, _collector?: Context const hasUltrawork = detectedKeywords.some((k) => k.type === "ultrawork") if (hasUltrawork) { - log(`[keyword-detector] Ultrawork mode activated`, { sessionID: input.sessionID }) + const runtimeVariant = getRuntimeVariant(input, output.message) + const isRuntimeMax = runtimeVariant === "max" - output.message.variant = "max" + log(`[keyword-detector] Ultrawork mode activated`, { + sessionID: input.sessionID, + runtimeVariant, + }) ctx.client.tui .showToast({ body: { title: "Ultrawork Mode Activated", - message: "Maximum precision engaged. All agents at your disposal.", + message: isRuntimeMax + ? "Maximum precision engaged. All agents at your disposal." + : "Runtime variant preserved. All agents at your disposal.", variant: "success" as const, duration: 3000, }, diff --git a/src/hooks/keyword-detector/index.test.ts b/src/hooks/keyword-detector/index.test.ts index 182b6afae..bf162ddeb 100644 --- a/src/hooks/keyword-detector/index.test.ts +++ b/src/hooks/keyword-detector/index.test.ts @@ -169,8 +169,8 @@ describe("keyword-detector session filtering", () => { output ) - // then - ultrawork should still work (variant set to max) - expect(output.message.variant).toBe("max") + // then - ultrawork should still work without forcing a new variant + expect(output.message.variant).toBeUndefined() expect(toastCalls).toContain("Ultrawork Mode Activated") }) @@ -214,12 +214,12 @@ describe("keyword-detector session filtering", () => { output ) - // then - all keywords should work - expect(output.message.variant).toBe("max") + // then - all keywords should work without forcing a new variant + expect(output.message.variant).toBeUndefined() expect(toastCalls).toContain("Ultrawork Mode Activated") }) - test("should override existing variant when ultrawork keyword is used", async () => { + test("should preserve existing runtime variant when ultrawork keyword is used", async () => { // given - main session set with pre-existing variant from TUI setMainSession("main-123") @@ -236,8 +236,8 @@ describe("keyword-detector session filtering", () => { output ) - // then - ultrawork should override TUI variant to max - expect(output.message.variant).toBe("max") + // then - ultrawork should preserve the already resolved runtime variant + expect(output.message.variant).toBe("low") expect(toastCalls).toContain("Ultrawork Mode Activated") }) }) @@ -311,8 +311,8 @@ describe("keyword-detector word boundary", () => { output ) - // then - ultrawork should be triggered - expect(output.message.variant).toBe("max") + // then - ultrawork should be triggered without forcing max + expect(output.message.variant).toBeUndefined() expect(toastCalls).toContain("Ultrawork Mode Activated") }) diff --git a/src/hooks/keyword-detector/ultrawork-runtime-variant.test.ts b/src/hooks/keyword-detector/ultrawork-runtime-variant.test.ts new file mode 100644 index 000000000..13c8c8943 --- /dev/null +++ b/src/hooks/keyword-detector/ultrawork-runtime-variant.test.ts @@ -0,0 +1,57 @@ +import { describe, expect, test } from "bun:test" +import { createKeywordDetectorHook } from "./index" +import { _resetForTesting, setMainSession } from "../../features/claude-code-session-state" + +function createMockPluginInput(toastMessages: string[]) { + return { + client: { + tui: { + showToast: async (opts: { body: { message: string } }) => { + toastMessages.push(opts.body.message) + }, + }, + }, + } as any +} + +describe("keyword-detector ultrawork runtime variant gating", () => { + test("#given runtime max variant #when ultrawork activates #then maximum precision toast is preserved", async () => { + // given + _resetForTesting() + setMainSession("main-session") + const toastMessages: string[] = [] + const hook = createKeywordDetectorHook(createMockPluginInput(toastMessages)) + const output = { + message: { variant: "max" } as Record, + parts: [{ type: "text", text: "ultrawork do it" }], + } + + // when + await hook["chat.message"]({ sessionID: "main-session", variant: "max" }, output) + + // then + expect(output.message.variant).toBe("max") + expect(toastMessages).toEqual(["Maximum precision engaged. All agents at your disposal."]) + _resetForTesting() + }) + + test("#given runtime non-max variant #when ultrawork activates #then variant stays unchanged and toast does not claim max", async () => { + // given + _resetForTesting() + setMainSession("main-session") + const toastMessages: string[] = [] + const hook = createKeywordDetectorHook(createMockPluginInput(toastMessages)) + const output = { + message: { variant: "medium" } as Record, + parts: [{ type: "text", text: "ultrawork do it" }], + } + + // when + await hook["chat.message"]({ sessionID: "main-session", variant: "medium" }, output) + + // then + expect(output.message.variant).toBe("medium") + expect(toastMessages).toEqual(["Runtime variant preserved. All agents at your disposal."]) + _resetForTesting() + }) +})