feat(tui): enhance LLM interaction with max_tokens and temperature overrides; add tests for parallel delegation and workflow script parsing

This commit is contained in:
asepharyana
2026-09-03 16:38:21 +07:00
parent 7e2eda3bb4
commit 5c65f8f6ab
13 changed files with 306 additions and 125 deletions
@@ -111,13 +111,16 @@ interface ScriptedStep {
function makeScriptedProvider(script: ScriptedStep[]): {
provider: ProviderService;
seen: Array<ChatMessage[]>;
chatCalls: Array<ChatMessage[]>;
} {
const seen: Array<ChatMessage[]> = [];
const chatCalls: Array<ChatMessage[]> = [];
let step = 0;
const chatResponses: string[] = [];
const provider: ProviderService = {
async chat(_messages, _tools, _maxTokens, _temperature) {
async chat(messages, _tools, _maxTokens, _temperature) {
// Used by compaction and review. For review tests we script below.
chatCalls.push([...messages]);
const text = chatResponses.shift() ?? "";
return { message: { role: "assistant", content: text || null }, usage: [10, 5] };
},
@@ -146,7 +149,7 @@ function makeScriptedProvider(script: ScriptedStep[]): {
(provider as unknown as { setChatReply: (s: string) => void }).setChatReply = (text: string) => {
chatResponses.push(text);
};
return { provider, seen };
return { provider, seen, chatCalls };
}
/** A ToolExecutor that echoes fixed outputs per tool. */
@@ -180,33 +183,13 @@ function buildParams(userText: string): {
return { params, events };
}
/** Extract the `[Flow]` steering system message from a captured batch. */
function flowDirective(batch: ChatMessage[]): string {
const m = batch.find((x) => (x.content ?? "").includes("[Flow]"));
return m?.content ?? "";
}
describe("runTurn complexity steering", () => {
it("injects a complex-request directive for a complex prompt", async () => {
const { provider, seen } = makeScriptedProvider([
{ content: "final answer" },
]);
describe("runTurn", () => {
it("runs a simple one-shot prompt to completion", async () => {
const { provider } = makeScriptedProvider([{ content: "here is the answer" }]);
const svc = new AgentTurnServiceImpl(provider as never, fixedExecutor({}), [] as never);
const { params } = buildParams("Please refactor the architecture across multiple files");
const { params } = buildParams("hello");
await svc.runTurn(params);
// The complexity directive system message must be present before the LLM.
const flow = flowDirective(seen[0] ?? []);
expect(flow).toContain("flagged as complex");
});
it("injects a keep-it-simple directive instead", async () => {
const { provider, seen } = makeScriptedProvider([{ content: "hi" }]);
const svc = new AgentTurnServiceImpl(provider as never, fixedExecutor({}), [] as never);
const { params } = buildParams("what is 2+2");
await svc.runTurn(params);
const flow = flowDirective(seen[0] ?? []);
expect(flow).toContain("looks simple");
expect(flow).not.toContain("complex");
expect(params.in_flight.value).toBe(false);
});
});
@@ -266,6 +249,25 @@ describe("runTurn self-review", () => {
// review_usage emitted.
expect(events.some((e) => e.kind === "review_usage")).toBe(true);
});
it("passes the work-in-progress to the reviewer (not an empty slate)", async () => {
const { provider, chatCalls } = makeScriptedProvider([
{ tools: [{ name: "edit" }] },
{ content: "fixed" },
]);
(provider as unknown as { setChatReply(s: string): void }).setChatReply(
"- [PRIORITY: medium] add a null check",
);
const svc = new AgentTurnServiceImpl(provider as never, fixedExecutor({ edit: "changed" }), [] as never);
const { params } = buildParams("harden the parser");
await svc.runTurn(params);
// The REVIEWER chat call carries the digest in its user message.
const reviewerCall = chatCalls.find((c) =>
c.some((m) => (m.content ?? "").includes("Review the work-in-progress below")),
);
expect(reviewerCall).toBeTruthy();
expect(reviewerCall!.some((m) => (m.content ?? "").includes("harden the parser"))).toBe(true);
});
});
/* ── Compaction: efficient + accurate ─────────────────────────────── */