2026-05-19 15:50:02 +02:00
|
|
|
import type { DefaultModeConfig } from "../config/schema/default-mode"
|
|
|
|
|
|
|
|
|
|
const ULTRAWORK_MODE_TAG = "<ultrawork-mode>"
|
|
|
|
|
|
|
|
|
|
export function createSystemTransformHandler(
|
|
|
|
|
defaultMode?: DefaultModeConfig,
|
|
|
|
|
getUltraworkMessage?: (agentName?: string, modelID?: string) => string,
|
|
|
|
|
): (
|
2026-03-05 11:18:12 +09:00
|
|
|
input: { sessionID?: string; model: { id: string; providerID: string; [key: string]: unknown } },
|
2026-02-22 01:57:22 +09:00
|
|
|
output: { system: string[] },
|
|
|
|
|
) => Promise<void> {
|
2026-05-19 15:50:02 +02:00
|
|
|
return async (input, output): Promise<void> => {
|
|
|
|
|
if (!defaultMode?.ultrawork || !getUltraworkMessage) return
|
|
|
|
|
|
2026-05-19 18:53:24 +02:00
|
|
|
// When ralph_loop is also enabled, skip system prompt injection: the loop's
|
|
|
|
|
// own continuation mechanism handles ultrawork re-injection on each iteration.
|
|
|
|
|
// Injecting both would be redundant — the continuation prompt prepends
|
|
|
|
|
// "ultrawork" and re-triggers keyword detection, defeating invisibility.
|
|
|
|
|
// The `ultrawork` flag still controls loop behavior (500 iters + Oracle gate).
|
|
|
|
|
if (defaultMode?.ralph_loop) return
|
|
|
|
|
|
2026-05-19 15:50:02 +02:00
|
|
|
// Avoid re-injecting if the ultrawork prompt is already in the system prompt
|
|
|
|
|
// (e.g. after compaction the system prompt is rebuilt and this hook fires again)
|
|
|
|
|
if (output.system.some((part) => part.includes(ULTRAWORK_MODE_TAG))) return
|
|
|
|
|
|
|
|
|
|
const modelID = input.model?.id
|
|
|
|
|
const ultraworkMessage = getUltraworkMessage("sisyphus", modelID)
|
|
|
|
|
if (!ultraworkMessage) return
|
|
|
|
|
|
|
|
|
|
output.system.push(ultraworkMessage)
|
|
|
|
|
}
|
2026-02-19 04:41:00 +02:00
|
|
|
}
|