fix(kiro): honor thinking effort budgets

Resolve the Kiro thinking budget from client intent (OpenAI reasoning_effort,
OpenAI Responses reasoning.effort, Claude output_config.effort, and Claude
thinking.budget_tokens) by reusing the shared thinkingUnified extractThinking
parser, then inject the resolved budget into the Kiro thinking system prefix.
Explicit none/off/disabled stops the prefix injection; synthetic -thinking
aliases keep the default budget.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
EdisonPVE
2026-06-18 15:14:42 +07:00
committed by decolua
co-authored by Cursor
parent 3f9382dee4
commit 2ff11246ae
5 changed files with 147 additions and 61 deletions
@@ -64,6 +64,17 @@ describe("Claude → Kiro (direct route)", () => {
"<thinking_mode>enabled</thinking_mode>"
);
});
it("maps output_config.effort high to Kiro max_thinking_length 24576", () => {
const out = C2K({
output_config: { effort: "high" },
messages: [{ role: "user", content: "think with adaptive effort" }],
});
expect(out.conversationState.currentMessage.userInputMessage.content).toContain(
"<max_thinking_length>24576</max_thinking_length>"
);
});
});
describe("Kiro → Claude (direct route, OpenAI-shaped chunks from executor)", () => {
+82
View File
@@ -9,6 +9,9 @@
import { describe, it, expect } from "vitest";
import { openaiToKiroRequest } from "../../open-sse/translator/request/openai-to-kiro.js";
const contentOf = (result) =>
result.conversationState.currentMessage.userInputMessage.content;
describe("openaiToKiroRequest", () => {
describe("basic message conversion", () => {
it("should convert a simple text message", () => {
@@ -280,4 +283,83 @@ describe("openaiToKiroRequest", () => {
expect(allJson).toContain("[Tool result: important orphaned output]");
});
});
describe("thinking budget", () => {
it("maps reasoning_effort low to max_thinking_length 1024", () => {
const body = {
reasoning_effort: "low",
messages: [{ role: "user", content: "Think lightly" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6", body, true, {});
expect(contentOf(result)).toContain("<max_thinking_length>1024</max_thinking_length>");
});
it("maps reasoning_effort high to max_thinking_length 24576", () => {
const body = {
reasoning_effort: "high",
messages: [{ role: "user", content: "Think deeply" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6", body, true, {});
expect(contentOf(result)).toContain("<max_thinking_length>24576</max_thinking_length>");
});
it("clamps reasoning_effort max to Kiro max_thinking_length 32000", () => {
const body = {
reasoning_effort: "max",
messages: [{ role: "user", content: "Think as much as possible" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6", body, true, {});
expect(contentOf(result)).toContain("<max_thinking_length>32000</max_thinking_length>");
});
it("clamps OpenAI Responses reasoning.effort xhigh to max_thinking_length 32000", () => {
const body = {
reasoning: { effort: "xhigh" },
messages: [{ role: "user", content: "Think extra deeply" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6", body, true, {});
expect(contentOf(result)).toContain("<max_thinking_length>32000</max_thinking_length>");
});
it("uses Claude thinking.budget_tokens as max_thinking_length", () => {
const body = {
thinking: { type: "enabled", budget_tokens: 4096 },
messages: [{ role: "user", content: "Use a fixed budget" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6", body, true, {});
expect(contentOf(result)).toContain("<max_thinking_length>4096</max_thinking_length>");
});
it("uses the default budget for synthetic -thinking models with no explicit config", () => {
const body = {
messages: [{ role: "user", content: "Think by model suffix" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6-thinking", body, true, {});
expect(contentOf(result)).toContain("<max_thinking_length>16000</max_thinking_length>");
});
it("does not inject thinking prefix for reasoning_effort none", () => {
const body = {
reasoning_effort: "none",
messages: [{ role: "user", content: "Do not think" }]
};
const result = openaiToKiroRequest("claude-sonnet-4.6", body, true, {});
expect(contentOf(result)).not.toContain("<thinking_mode>enabled</thinking_mode>");
expect(contentOf(result)).not.toContain("<max_thinking_length>");
});
});
});