fix(continuation): mark resumes synthetic

This commit is contained in:
YeonGyu-Kim
2026-05-13 13:09:12 +09:00
parent 3f92264311
commit 38b1433ff5
6 changed files with 90 additions and 10 deletions
@@ -61,15 +61,33 @@ describe("ralph-loop continuation prompt injector", () => {
test("#given inherited message agent has ZWSP prefix #when injecting continuation prompt #then promptAsync receives normalized agent", async () => {
// given
let promptBody: { agent?: string } | undefined
let promptBody: { agent?: string; noReply?: boolean } | undefined
let promptPart:
| {
text: string
synthetic?: boolean
metadata?: Record<string, unknown>
}
| undefined
const ctx = {
client: {
session: {
messages: async () => ({
data: [{ info: { agent: "\u200bSisyphus - Ultraworker" } }],
}),
promptAsync: async (input: { body: { agent?: string } }) => {
promptAsync: async (input: {
body: {
agent?: string
noReply?: boolean
parts?: Array<{
text: string
synthetic?: boolean
metadata?: Record<string, unknown>
}>
}
}) => {
promptBody = input.body
promptPart = input.body.parts?.[0]
return {}
},
},
@@ -87,6 +105,9 @@ describe("ralph-loop continuation prompt injector", () => {
// then
expect(promptBody?.agent).toBe("sisyphus")
expect(promptBody?.agent).not.toContain("\u200b")
expect(promptBody?.noReply).toBeUndefined()
expect(promptPart?.synthetic).toBe(true)
expect(promptPart?.metadata?.compaction_continue).toBe(true)
})
test("#given inherited message agent has no ZWSP prefix #when injecting continuation prompt #then promptAsync receives normalized agent", async () => {
@@ -4,7 +4,7 @@ import { findNearestMessageWithFields } from "../../features/hook-message-inject
import { getMessageDir } from "./message-storage-directory"
import { withTimeout } from "./with-timeout"
import {
createInternalAgentTextPart,
createInternalAgentContinuationTextPart,
isRecord,
normalizeSDKResponse,
resolveInheritedPromptTools,
@@ -126,7 +126,7 @@ export async function injectContinuationPrompt(
...(launchModel ? { model: launchModel } : {}),
...(launchVariant ? { variant: launchVariant } : {}),
...(inheritedTools ? { tools: inheritedTools } : {}),
parts: [createInternalAgentTextPart(options.prompt)],
parts: [createInternalAgentContinuationTextPart(options.prompt)],
},
query: { directory: options.directory },
})
@@ -46,7 +46,14 @@ describe("injectContinuation", () => {
test("inherits tools from resolved message info when reinjecting", async () => {
// given
let capturedTools: Record<string, boolean> | undefined
let capturedText: string | undefined
let capturedPart:
| {
text: string
synthetic?: boolean
metadata?: Record<string, unknown>
}
| undefined
let capturedNoReply: boolean | undefined
const ctx = {
directory: "/tmp/test",
client: {
@@ -55,11 +62,18 @@ describe("injectContinuation", () => {
promptAsync: async (input: {
body: {
tools?: Record<string, boolean>
parts?: Array<{ type: string; text: string }>
noReply?: boolean
parts?: Array<{
type: string
text: string
synthetic?: boolean
metadata?: Record<string, unknown>
}>
}
}) => {
capturedTools = input.body.tools
capturedText = input.body.parts?.[0]?.text
capturedNoReply = input.body.noReply
capturedPart = input.body.parts?.[0]
return {}
},
},
@@ -83,7 +97,10 @@ describe("injectContinuation", () => {
// then
expect(capturedTools).toEqual({ question: false, bash: true })
expect(capturedText).toContain(OMO_INTERNAL_INITIATOR_MARKER)
expect(capturedNoReply).toBeUndefined()
expect(capturedPart?.text).toContain(OMO_INTERNAL_INITIATOR_MARKER)
expect(capturedPart?.synthetic).toBe(true)
expect(capturedPart?.metadata?.compaction_continue).toBe(true)
})
test("skips injection when agent is plan (prevents Plan Mode infinite loop)", async () => {
@@ -6,7 +6,7 @@ import {
resolveRegisteredAgentName,
} from "../../features/claude-code-session-state"
import {
createInternalAgentTextPart,
createInternalAgentContinuationTextPart,
normalizeSDKResponse,
resolveInheritedPromptTools,
} from "../../shared"
@@ -191,7 +191,7 @@ ${todoList}`
...(launchModel ? { model: launchModel } : {}),
...(launchVariant ? { variant: launchVariant } : {}),
...(inheritedTools ? { tools: inheritedTools } : {}),
parts: [createInternalAgentTextPart(prompt)],
parts: [createInternalAgentContinuationTextPart(prompt)],
},
query: { directory: ctx.directory },
})