fix(continuation): mark resumes synthetic
This commit is contained in:
@@ -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 () => {
|
test("#given inherited message agent has ZWSP prefix #when injecting continuation prompt #then promptAsync receives normalized agent", async () => {
|
||||||
// given
|
// 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 = {
|
const ctx = {
|
||||||
client: {
|
client: {
|
||||||
session: {
|
session: {
|
||||||
messages: async () => ({
|
messages: async () => ({
|
||||||
data: [{ info: { agent: "\u200bSisyphus - Ultraworker" } }],
|
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
|
promptBody = input.body
|
||||||
|
promptPart = input.body.parts?.[0]
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -87,6 +105,9 @@ describe("ralph-loop continuation prompt injector", () => {
|
|||||||
// then
|
// then
|
||||||
expect(promptBody?.agent).toBe("sisyphus")
|
expect(promptBody?.agent).toBe("sisyphus")
|
||||||
expect(promptBody?.agent).not.toContain("\u200b")
|
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 () => {
|
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 { getMessageDir } from "./message-storage-directory"
|
||||||
import { withTimeout } from "./with-timeout"
|
import { withTimeout } from "./with-timeout"
|
||||||
import {
|
import {
|
||||||
createInternalAgentTextPart,
|
createInternalAgentContinuationTextPart,
|
||||||
isRecord,
|
isRecord,
|
||||||
normalizeSDKResponse,
|
normalizeSDKResponse,
|
||||||
resolveInheritedPromptTools,
|
resolveInheritedPromptTools,
|
||||||
@@ -126,7 +126,7 @@ export async function injectContinuationPrompt(
|
|||||||
...(launchModel ? { model: launchModel } : {}),
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
...(inheritedTools ? { tools: inheritedTools } : {}),
|
...(inheritedTools ? { tools: inheritedTools } : {}),
|
||||||
parts: [createInternalAgentTextPart(options.prompt)],
|
parts: [createInternalAgentContinuationTextPart(options.prompt)],
|
||||||
},
|
},
|
||||||
query: { directory: options.directory },
|
query: { directory: options.directory },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -46,7 +46,14 @@ describe("injectContinuation", () => {
|
|||||||
test("inherits tools from resolved message info when reinjecting", async () => {
|
test("inherits tools from resolved message info when reinjecting", async () => {
|
||||||
// given
|
// given
|
||||||
let capturedTools: Record<string, boolean> | undefined
|
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 = {
|
const ctx = {
|
||||||
directory: "/tmp/test",
|
directory: "/tmp/test",
|
||||||
client: {
|
client: {
|
||||||
@@ -55,11 +62,18 @@ describe("injectContinuation", () => {
|
|||||||
promptAsync: async (input: {
|
promptAsync: async (input: {
|
||||||
body: {
|
body: {
|
||||||
tools?: Record<string, boolean>
|
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
|
capturedTools = input.body.tools
|
||||||
capturedText = input.body.parts?.[0]?.text
|
capturedNoReply = input.body.noReply
|
||||||
|
capturedPart = input.body.parts?.[0]
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -83,7 +97,10 @@ describe("injectContinuation", () => {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
expect(capturedTools).toEqual({ question: false, bash: true })
|
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 () => {
|
test("skips injection when agent is plan (prevents Plan Mode infinite loop)", async () => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
resolveRegisteredAgentName,
|
resolveRegisteredAgentName,
|
||||||
} from "../../features/claude-code-session-state"
|
} from "../../features/claude-code-session-state"
|
||||||
import {
|
import {
|
||||||
createInternalAgentTextPart,
|
createInternalAgentContinuationTextPart,
|
||||||
normalizeSDKResponse,
|
normalizeSDKResponse,
|
||||||
resolveInheritedPromptTools,
|
resolveInheritedPromptTools,
|
||||||
} from "../../shared"
|
} from "../../shared"
|
||||||
@@ -191,7 +191,7 @@ ${todoList}`
|
|||||||
...(launchModel ? { model: launchModel } : {}),
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
...(inheritedTools ? { tools: inheritedTools } : {}),
|
...(inheritedTools ? { tools: inheritedTools } : {}),
|
||||||
parts: [createInternalAgentTextPart(prompt)],
|
parts: [createInternalAgentContinuationTextPart(prompt)],
|
||||||
},
|
},
|
||||||
query: { directory: ctx.directory },
|
query: { directory: ctx.directory },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import {
|
import {
|
||||||
OMO_INTERNAL_INITIATOR_MARKER,
|
OMO_INTERNAL_INITIATOR_MARKER,
|
||||||
|
createInternalAgentContinuationTextPart,
|
||||||
createInternalAgentTextPart,
|
createInternalAgentTextPart,
|
||||||
stripInternalInitiatorMarkers,
|
stripInternalInitiatorMarkers,
|
||||||
} from "./internal-initiator-marker"
|
} from "./internal-initiator-marker"
|
||||||
@@ -19,6 +20,18 @@ describe("internal-initiator-marker", () => {
|
|||||||
expect(part.text).toBe(`Hello world\n${OMO_INTERNAL_INITIATOR_MARKER}`)
|
expect(part.text).toBe(`Hello world\n${OMO_INTERNAL_INITIATOR_MARKER}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("#given regular internal text #when creating a text part #then leaves it visible as a normal message part", () => {
|
||||||
|
// given
|
||||||
|
const text = "Visible notification"
|
||||||
|
|
||||||
|
// when
|
||||||
|
const part = createInternalAgentTextPart(text)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect("synthetic" in part).toBe(false)
|
||||||
|
expect("metadata" in part).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
test("#given text already ending with the marker #when creating a text part #then does not duplicate the marker", () => {
|
test("#given text already ending with the marker #when creating a text part #then does not duplicate the marker", () => {
|
||||||
// given
|
// given
|
||||||
const text = `Already marked\n${OMO_INTERNAL_INITIATOR_MARKER}`
|
const text = `Already marked\n${OMO_INTERNAL_INITIATOR_MARKER}`
|
||||||
@@ -71,6 +84,22 @@ describe("internal-initiator-marker", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("createInternalAgentContinuationTextPart", () => {
|
||||||
|
test("#given continuation text #when creating a text part #then marks it as an agent continuation", () => {
|
||||||
|
// given
|
||||||
|
const text = "Continue the loop"
|
||||||
|
|
||||||
|
// when
|
||||||
|
const part = createInternalAgentContinuationTextPart(text)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(part.type).toBe("text")
|
||||||
|
expect(part.text).toBe(`Continue the loop\n${OMO_INTERNAL_INITIATOR_MARKER}`)
|
||||||
|
expect(part.synthetic).toBe(true)
|
||||||
|
expect(part.metadata.compaction_continue).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("stripInternalInitiatorMarkers", () => {
|
describe("stripInternalInitiatorMarkers", () => {
|
||||||
test("#given text with no markers #when stripping #then returns text trimmed at the end", () => {
|
test("#given text with no markers #when stripping #then returns text trimmed at the end", () => {
|
||||||
// given
|
// given
|
||||||
|
|||||||
@@ -16,3 +16,16 @@ export function createInternalAgentTextPart(text: string): {
|
|||||||
text: `${cleanText}\n${OMO_INTERNAL_INITIATOR_MARKER}`,
|
text: `${cleanText}\n${OMO_INTERNAL_INITIATOR_MARKER}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createInternalAgentContinuationTextPart(text: string): {
|
||||||
|
type: "text"
|
||||||
|
text: string
|
||||||
|
synthetic: true
|
||||||
|
metadata: { compaction_continue: true }
|
||||||
|
} {
|
||||||
|
return {
|
||||||
|
...createInternalAgentTextPart(text),
|
||||||
|
synthetic: true,
|
||||||
|
metadata: { compaction_continue: true },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user