Add /ulw-loop command for ultrawork mode loop (#867)
* feat(ralph-loop): add ultrawork field to RalphLoopState * feat(ralph-loop): persist ultrawork field in storage * feat(ralph-loop): accept ultrawork option in startLoop Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * feat(ralph-loop): prepend ultrawork keyword when mode active Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * feat(ralph-loop): custom toast for ultrawork mode * feat(ralph-loop): add /ulw-loop command for ultrawork mode * fix(ralph-loop): add non-null assertion for type safety * fix(ralph-loop): mirror argument parsing in ulw-loop handler - Parse quoted prompts and strip flags from task text - Support --max-iterations and --completion-promise options - Add default prompt for empty input - Fixes behavior inconsistency with /ralph-loop --------- Co-authored-by: justsisyphus <sisyphus-dev-ai@users.noreply.github.com> Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -92,6 +92,27 @@ describe("ralph-loop", () => {
|
||||
expect(readResult?.session_id).toBe("test-session-123")
|
||||
})
|
||||
|
||||
test("should handle ultrawork field", () => {
|
||||
// #given - a state object with ultrawork enabled
|
||||
const state: RalphLoopState = {
|
||||
active: true,
|
||||
iteration: 1,
|
||||
max_iterations: 50,
|
||||
completion_promise: "DONE",
|
||||
started_at: "2025-12-30T01:00:00Z",
|
||||
prompt: "Build a REST API",
|
||||
session_id: "test-session-123",
|
||||
ultrawork: true,
|
||||
}
|
||||
|
||||
// #when - write and read state
|
||||
writeState(TEST_DIR, state)
|
||||
const readResult = readState(TEST_DIR)
|
||||
|
||||
// #then - ultrawork field should be preserved
|
||||
expect(readResult?.ultrawork).toBe(true)
|
||||
})
|
||||
|
||||
test("should return null for non-existent state", () => {
|
||||
// #given - no state file exists
|
||||
// #when - read state
|
||||
@@ -164,6 +185,30 @@ describe("ralph-loop", () => {
|
||||
expect(state?.session_id).toBe("session-123")
|
||||
})
|
||||
|
||||
test("should accept ultrawork option in startLoop", () => {
|
||||
// #given - hook instance
|
||||
const hook = createRalphLoopHook(createMockPluginInput())
|
||||
|
||||
// #when - start loop with ultrawork
|
||||
hook.startLoop("session-123", "Build something", { ultrawork: true })
|
||||
|
||||
// #then - state should have ultrawork=true
|
||||
const state = hook.getState()
|
||||
expect(state?.ultrawork).toBe(true)
|
||||
})
|
||||
|
||||
test("should handle missing ultrawork option in startLoop", () => {
|
||||
// #given - hook instance
|
||||
const hook = createRalphLoopHook(createMockPluginInput())
|
||||
|
||||
// #when - start loop without ultrawork
|
||||
hook.startLoop("session-123", "Build something")
|
||||
|
||||
// #then - state should have ultrawork=undefined
|
||||
const state = hook.getState()
|
||||
expect(state?.ultrawork).toBeUndefined()
|
||||
})
|
||||
|
||||
test("should inject continuation when loop active and no completion detected", async () => {
|
||||
// #given - active loop state
|
||||
const hook = createRalphLoopHook(createMockPluginInput())
|
||||
@@ -672,7 +717,10 @@ describe("ralph-loop", () => {
|
||||
|
||||
// #when - session goes idle
|
||||
await hook.event({
|
||||
event: { type: "session.idle", properties: { sessionID: "session-123" } },
|
||||
event: {
|
||||
type: "session.idle",
|
||||
properties: { sessionID: "session-123" },
|
||||
},
|
||||
})
|
||||
|
||||
// #then - should complete via transcript (API not called when transcript succeeds)
|
||||
@@ -681,6 +729,70 @@ describe("ralph-loop", () => {
|
||||
// API should NOT be called since transcript found completion
|
||||
expect(messagesCalls.length).toBe(0)
|
||||
})
|
||||
|
||||
test("should show ultrawork completion toast", async () => {
|
||||
// #given - hook with ultrawork mode and completion in transcript
|
||||
const transcriptPath = join(TEST_DIR, "transcript.jsonl")
|
||||
const hook = createRalphLoopHook(createMockPluginInput(), {
|
||||
getTranscriptPath: () => transcriptPath,
|
||||
})
|
||||
writeFileSync(transcriptPath, JSON.stringify({ content: "<promise>DONE</promise>" }))
|
||||
hook.startLoop("test-id", "Build API", { ultrawork: true })
|
||||
|
||||
// #when - idle event triggered
|
||||
await hook.event({ event: { type: "session.idle", properties: { sessionID: "test-id" } } })
|
||||
|
||||
// #then - ultrawork toast shown
|
||||
const completionToast = toastCalls.find(t => t.title === "ULTRAWORK LOOP COMPLETE!")
|
||||
expect(completionToast).toBeDefined()
|
||||
expect(completionToast!.message).toMatch(/JUST ULW ULW!/)
|
||||
})
|
||||
|
||||
test("should show regular completion toast when ultrawork disabled", async () => {
|
||||
// #given - hook without ultrawork
|
||||
const transcriptPath = join(TEST_DIR, "transcript.jsonl")
|
||||
const hook = createRalphLoopHook(createMockPluginInput(), {
|
||||
getTranscriptPath: () => transcriptPath,
|
||||
})
|
||||
writeFileSync(transcriptPath, JSON.stringify({ content: "<promise>DONE</promise>" }))
|
||||
hook.startLoop("test-id", "Build API")
|
||||
|
||||
// #when - idle event triggered
|
||||
await hook.event({ event: { type: "session.idle", properties: { sessionID: "test-id" } } })
|
||||
|
||||
// #then - regular toast shown
|
||||
expect(toastCalls.some(t => t.title === "Ralph Loop Complete!")).toBe(true)
|
||||
})
|
||||
|
||||
test("should prepend ultrawork to continuation prompt when ultrawork=true", async () => {
|
||||
// #given - hook with ultrawork mode enabled
|
||||
const hook = createRalphLoopHook(createMockPluginInput())
|
||||
hook.startLoop("session-123", "Build API", { ultrawork: true })
|
||||
|
||||
// #when - session goes idle (continuation triggered)
|
||||
await hook.event({
|
||||
event: { type: "session.idle", properties: { sessionID: "session-123" } },
|
||||
})
|
||||
|
||||
// #then - prompt should start with "ultrawork "
|
||||
expect(promptCalls.length).toBe(1)
|
||||
expect(promptCalls[0].text).toMatch(/^ultrawork /)
|
||||
})
|
||||
|
||||
test("should NOT prepend ultrawork to continuation prompt when ultrawork=false", async () => {
|
||||
// #given - hook without ultrawork mode
|
||||
const hook = createRalphLoopHook(createMockPluginInput())
|
||||
hook.startLoop("session-123", "Build API")
|
||||
|
||||
// #when - session goes idle (continuation triggered)
|
||||
await hook.event({
|
||||
event: { type: "session.idle", properties: { sessionID: "session-123" } },
|
||||
})
|
||||
|
||||
// #then - prompt should NOT start with "ultrawork "
|
||||
expect(promptCalls.length).toBe(1)
|
||||
expect(promptCalls[0].text).not.toMatch(/^ultrawork /)
|
||||
})
|
||||
})
|
||||
|
||||
describe("API timeout protection", () => {
|
||||
|
||||
Reference in New Issue
Block a user