fix(keyword-detector): narrow ULW auto-start to leading keyword position only

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-04-08 17:17:14 +09:00
parent 06b825dd74
commit 917ae4dfc3
2 changed files with 53 additions and 0 deletions
@@ -86,6 +86,44 @@ describe("keyword-detector ralph-loop activation", () => {
expect(startLoopCalls[0].options.ultrawork).toBe(true)
})
test("#given ulw mentioned mid-sentence #when chat.message fires #then ralph-loop startLoop is not invoked", async () => {
// given
setMainSession("main-session")
const startLoopCalls: StartLoopCall[] = []
const ralphLoop = createMockRalphLoop(startLoopCalls)
const hook = createKeywordDetectorHook(createMockPluginInput(), undefined, ralphLoop)
const output = {
message: {} as Record<string, unknown>,
parts: [{ type: "text", text: "I think ulw is cool" }],
}
// when
await hook["chat.message"]({ sessionID: "main-session", agent: "sisyphus" }, output)
// then
expect(startLoopCalls).toHaveLength(0)
expect(output.parts[0]?.text).toBe("I think ulw is cool")
})
test("#given question about ultrawork #when chat.message fires #then ralph-loop startLoop is not invoked", async () => {
// given
setMainSession("main-session")
const startLoopCalls: StartLoopCall[] = []
const ralphLoop = createMockRalphLoop(startLoopCalls)
const hook = createKeywordDetectorHook(createMockPluginInput(), undefined, ralphLoop)
const output = {
message: {} as Record<string, unknown>,
parts: [{ type: "text", text: "what is ultrawork?" }],
}
// when
await hook["chat.message"]({ sessionID: "main-session", agent: "sisyphus" }, output)
// then
expect(startLoopCalls).toHaveLength(0)
expect(output.parts[0]?.text).toBe("what is ultrawork?")
})
test("#given non-ulw message #when chat.message fires #then ralph-loop startLoop is not invoked", async () => {
// given
setMainSession("main-session")
+15
View File
@@ -16,11 +16,16 @@ import type { RalphLoopHook } from "../ralph-loop"
import { parseRalphLoopArguments } from "../ralph-loop/command-arguments"
const ULTRAWORK_KEYWORD_PATTERN = /\b(ultrawork|ulw)\b/i
const LEADING_ULTRAWORK_PATTERN = /^\s*(ultrawork|ulw)\b/i
function extractUltraworkTask(cleanText: string): string {
return cleanText.replace(ULTRAWORK_KEYWORD_PATTERN, "").trim()
}
function hasLeadingUltraworkKeyword(cleanText: string): boolean {
return LEADING_ULTRAWORK_PATTERN.test(cleanText)
}
export function createKeywordDetectorHook(
ctx: PluginInput,
_collector?: ContextCollector,
@@ -76,6 +81,16 @@ export function createKeywordDetectorHook(
}
}
if (!hasLeadingUltraworkKeyword(cleanText)) {
const preFilterCount = detectedKeywords.length
detectedKeywords = detectedKeywords.filter((k) => k.type !== "ultrawork")
if (preFilterCount > detectedKeywords.length) {
log(`[keyword-detector] Filtered non-leading ultrawork keyword`, {
sessionID: input.sessionID,
})
}
}
if (detectedKeywords.length === 0) {
return
}