diff --git a/packages/devin/index.mjs b/packages/devin/index.mjs index 731d3b5..ae76eff 100644 --- a/packages/devin/index.mjs +++ b/packages/devin/index.mjs @@ -2065,7 +2065,7 @@ function buildMessages(req, uid, key) { if (thought) [p.thinking, thought] = [thought, null] return p } - for (const b of t.blocks) { + for (const [i, b] of t.blocks.entries()) { if (b?.type === "text" && typeof b.text === "string") { if (b.text) own.push(take({ role: ASSISTANT, text: b.text, calls: [], cache: marked(b) })) else if (marked(b) && own.length) own[own.length - 1].cache = true @@ -2073,7 +2073,10 @@ function buildMessages(req, uid, key) { calls.push({ id: inID(b.id), name: b.name, args: JSON.stringify(b.input ?? {}) }) mark ||= marked(b) } else if (b?.type === "thinking" && claude && typeof b.signature === "string" && b.signature) { - // two in a row: the first has a prompt of its own + // Devin rejects a signed thought on an otherwise empty assistant prompt. + // A gateway search can leave adjacent thoughts; keep the last one intact. + const next = t.blocks[i + 1] + if (next?.type === "thinking" && typeof next.signature === "string" && next.signature) continue if (thought) own.push(take({ role: ASSISTANT, text: "", calls: [] })) thought = { text: typeof b.thinking === "string" ? b.thinking : "", signature: b.signature, type: sigTypeOf(b.signature) } } else if (b?.type === "thinking" && !claude && typeof b.thinking === "string" && b.thinking) { diff --git a/packages/devin/package.json b/packages/devin/package.json index d70cfff..801c21e 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.42", + "version": "0.1.43", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/devin/thinking-signature.test.mjs b/packages/devin/thinking-signature.test.mjs index 2a80fc6..67541ec 100644 --- a/packages/devin/thinking-signature.test.mjs +++ b/packages/devin/thinking-signature.test.mjs @@ -134,6 +134,20 @@ test("the next request sends Claude's signed thinking back on the prompt that fo expect(only).toEqual({ role: 2, text: "", calls: ["read_file"], thinking: "t", signature: SIG, type: "anthropic" }) }) +test("a search turn with adjacent signed thoughts replays without a thinking-only assistant prompt", () => { + const messages = [ + { role: "user", content: "Look it up." }, + { role: "assistant", content: [ + { type: "thinking", thinking: "Search first.", signature: "s1" }, + { type: "thinking", thinking: "Use the result.", signature: "s2" }, + { type: "text", text: "Found it." }, + ] }, + { role: "user", content: "Continue." }, + ] + const ps = prompts(buildMessages({ messages }, "claude-opus-5-5", "k")).filter((p) => p.role === 2) + expect(ps).toEqual([{ role: 2, text: "Found it.", calls: [], thinking: "Use the result.", signature: "s2", type: "anthropic" }]) +}) + test("thinking after the text goes on a prompt of its own ahead of the calls", () => { const ps = prompts( buildMessages(