From c09caac71a238f43cc1fa058a3c5f758292595c6 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 2 Feb 2026 02:11:57 -0800 Subject: [PATCH] Fix empty chat history in cn check workers The worker built a local chatHistory array, but streamChatResponse replaced it with the ChatHistoryService's empty history via refreshChatHistoryFromService(). Use ChatHistoryService.addUserMessage() so the messages are available when streamChatResponse reads them. Co-Authored-By: Claude Opus 4.5 --- .../cli/src/commands/check/checkWorker.ts | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/extensions/cli/src/commands/check/checkWorker.ts b/extensions/cli/src/commands/check/checkWorker.ts index 4038246a0..4b5bb1ed2 100644 --- a/extensions/cli/src/commands/check/checkWorker.ts +++ b/extensions/cli/src/commands/check/checkWorker.ts @@ -8,16 +8,14 @@ import * as fs from "fs"; -import type { ChatHistoryItem } from "core/index.js"; - import { initializeServices, getService, + services, SERVICE_NAMES, } from "../../services/index.js"; import type { ModelServiceState } from "../../services/types.js"; import { streamChatResponse } from "../../stream/streamChatResponse.js"; -import { constructSystemMessage } from "../../systemMessage.js"; import type { DiffContext } from "./diffContext.js"; import { captureWorktreeDiff } from "./worktree.js"; @@ -133,14 +131,6 @@ export async function runCheckWorker(): Promise { throw new Error("Failed to initialize model service"); } - // Build system message - const systemMessage = await constructSystemMessage( - "auto", - config.options.rule, - undefined, - true, // headless - ); - // Build the check prompt const checkPrompt = buildCheckPrompt(config.diffContext); @@ -153,30 +143,20 @@ export async function runCheckWorker(): Promise { agentInstructions = loadLocalAgentInstructions(config.agentSource); } - // Construct initial chat history - const chatHistory: ChatHistoryItem[] = []; - - if (systemMessage) { - chatHistory.push({ - message: { role: "user", content: systemMessage }, - contextItems: [], - }); - } + // Build the user prompt parts and add to ChatHistoryService + // so streamChatResponse picks them up via refreshChatHistoryFromService + const chatHistorySvc = services.chatHistory; + const promptParts: string[] = []; if (agentInstructions) { - chatHistory.push({ - message: { - role: "user", - content: `## Agent Instructions\n\n${agentInstructions}`, - }, - contextItems: [], - }); + promptParts.push(`## Agent Instructions\n\n${agentInstructions}`); } + promptParts.push(checkPrompt); - chatHistory.push({ - message: { role: "user", content: checkPrompt }, - contextItems: [], - }); + const userMessage = promptParts.join("\n\n"); + chatHistorySvc.addUserMessage(userMessage); + + const chatHistory = chatHistorySvc.getHistory(); // Collect agent text output let agentOutput = "";