Skip to content

Commit 55bc8f0

Browse files
committed
refactor(ultrawork-mode): use history injection instead of direct message modification
- Replace direct parts[idx].text modification with injectHookMessage - Context now injected via filesystem (like UserPromptSubmitHook) - Preserves original user message without modification 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
1 parent 0ac4d22 commit 55bc8f0

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/hooks/ultrawork-mode/index.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { detectUltraworkKeyword, extractPromptText } from "./detector"
22
import { ULTRAWORK_CONTEXT } from "./constants"
33
import type { UltraworkModeState } from "./types"
44
import { log } from "../../shared"
5+
import { injectHookMessage } from "../../features/hook-message-injector"
56

67
export * from "./detector"
78
export * from "./constants"
@@ -16,13 +17,13 @@ export function clearUltraworkModeState(sessionID: string): void {
1617
export function createUltraworkModeHook() {
1718
return {
1819
/**
19-
* chat.message hook - detect ultrawork/ulw keywords, inject context
20+
* chat.message hook - detect ultrawork/ulw keywords, inject context via history
2021
*
2122
* Execution timing: AFTER claudeCodeHooks["chat.message"]
2223
* Behavior:
2324
* 1. Extract text from user prompt
2425
* 2. Detect ultrawork/ulw keywords (excluding code blocks)
25-
* 3. If detected, prepend ULTRAWORK_CONTEXT to first text part
26+
* 3. If detected, inject ULTRAWORK_CONTEXT via injectHookMessage (history injection)
2627
*/
2728
"chat.message": async (
2829
input: {
@@ -51,13 +52,25 @@ export function createUltraworkModeHook() {
5152
state.detected = true
5253
log("Ultrawork keyword detected", { sessionID: input.sessionID })
5354

54-
const parts = output.parts as Array<{ type: string; text?: string }>
55-
const idx = parts.findIndex((p) => p.type === "text" && p.text)
55+
const message = output.message as {
56+
agent?: string
57+
model?: { modelID?: string; providerID?: string }
58+
path?: { cwd?: string; root?: string }
59+
tools?: Record<string, boolean>
60+
}
61+
62+
const success = injectHookMessage(input.sessionID, ULTRAWORK_CONTEXT, {
63+
agent: message.agent,
64+
model: message.model,
65+
path: message.path,
66+
tools: message.tools,
67+
})
5668

57-
if (idx >= 0) {
58-
parts[idx].text = `${ULTRAWORK_CONTEXT}${parts[idx].text ?? ""}`
69+
if (success) {
5970
state.injected = true
60-
log("Ultrawork context injected", { sessionID: input.sessionID })
71+
log("Ultrawork context injected via history", { sessionID: input.sessionID })
72+
} else {
73+
log("Ultrawork context injection failed", { sessionID: input.sessionID })
6174
}
6275

6376
ultraworkModeState.set(input.sessionID, state)

0 commit comments

Comments
 (0)