Preserve ultrawork runtime variants

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-11 15:59:14 +09:00
parent a3fe161158
commit cbceb3cd0d
3 changed files with 84 additions and 12 deletions

View File

@@ -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, unknown>): 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<string, unknown>
@@ -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,
},

View File

@@ -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")
})

View File

@@ -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<string, unknown>,
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<string, unknown>,
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()
})
})