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:
@@ -14,6 +14,14 @@ import {
|
|||||||
import type { ContextCollector } from "../../features/context-injector"
|
import type { ContextCollector } from "../../features/context-injector"
|
||||||
|
|
||||||
export function createKeywordDetectorHook(ctx: PluginInput, _collector?: ContextCollector) {
|
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 {
|
return {
|
||||||
"chat.message": async (
|
"chat.message": async (
|
||||||
input: {
|
input: {
|
||||||
@@ -21,6 +29,7 @@ export function createKeywordDetectorHook(ctx: PluginInput, _collector?: Context
|
|||||||
agent?: string
|
agent?: string
|
||||||
model?: { providerID: string; modelID: string }
|
model?: { providerID: string; modelID: string }
|
||||||
messageID?: string
|
messageID?: string
|
||||||
|
variant?: string
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
message: Record<string, unknown>
|
message: Record<string, unknown>
|
||||||
@@ -72,15 +81,21 @@ export function createKeywordDetectorHook(ctx: PluginInput, _collector?: Context
|
|||||||
|
|
||||||
const hasUltrawork = detectedKeywords.some((k) => k.type === "ultrawork")
|
const hasUltrawork = detectedKeywords.some((k) => k.type === "ultrawork")
|
||||||
if (hasUltrawork) {
|
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
|
ctx.client.tui
|
||||||
.showToast({
|
.showToast({
|
||||||
body: {
|
body: {
|
||||||
title: "Ultrawork Mode Activated",
|
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,
|
variant: "success" as const,
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -169,8 +169,8 @@ describe("keyword-detector session filtering", () => {
|
|||||||
output
|
output
|
||||||
)
|
)
|
||||||
|
|
||||||
// then - ultrawork should still work (variant set to max)
|
// then - ultrawork should still work without forcing a new variant
|
||||||
expect(output.message.variant).toBe("max")
|
expect(output.message.variant).toBeUndefined()
|
||||||
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -214,12 +214,12 @@ describe("keyword-detector session filtering", () => {
|
|||||||
output
|
output
|
||||||
)
|
)
|
||||||
|
|
||||||
// then - all keywords should work
|
// then - all keywords should work without forcing a new variant
|
||||||
expect(output.message.variant).toBe("max")
|
expect(output.message.variant).toBeUndefined()
|
||||||
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
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
|
// given - main session set with pre-existing variant from TUI
|
||||||
setMainSession("main-123")
|
setMainSession("main-123")
|
||||||
|
|
||||||
@@ -236,8 +236,8 @@ describe("keyword-detector session filtering", () => {
|
|||||||
output
|
output
|
||||||
)
|
)
|
||||||
|
|
||||||
// then - ultrawork should override TUI variant to max
|
// then - ultrawork should preserve the already resolved runtime variant
|
||||||
expect(output.message.variant).toBe("max")
|
expect(output.message.variant).toBe("low")
|
||||||
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -311,8 +311,8 @@ describe("keyword-detector word boundary", () => {
|
|||||||
output
|
output
|
||||||
)
|
)
|
||||||
|
|
||||||
// then - ultrawork should be triggered
|
// then - ultrawork should be triggered without forcing max
|
||||||
expect(output.message.variant).toBe("max")
|
expect(output.message.variant).toBeUndefined()
|
||||||
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
expect(toastCalls).toContain("Ultrawork Mode Activated")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user