88
99import * as fs from "fs" ;
1010
11- import type { ChatHistoryItem } from "core/index.js" ;
12-
1311import {
1412 initializeServices ,
1513 getService ,
14+ services ,
1615 SERVICE_NAMES ,
1716} from "../../services/index.js" ;
1817import type { ModelServiceState } from "../../services/types.js" ;
1918import { streamChatResponse } from "../../stream/streamChatResponse.js" ;
20- import { constructSystemMessage } from "../../systemMessage.js" ;
2119
2220import type { DiffContext } from "./diffContext.js" ;
2321import { captureWorktreeDiff } from "./worktree.js" ;
@@ -133,14 +131,6 @@ export async function runCheckWorker(): Promise<void> {
133131 throw new Error ( "Failed to initialize model service" ) ;
134132 }
135133
136- // Build system message
137- const systemMessage = await constructSystemMessage (
138- "auto" ,
139- config . options . rule ,
140- undefined ,
141- true , // headless
142- ) ;
143-
144134 // Build the check prompt
145135 const checkPrompt = buildCheckPrompt ( config . diffContext ) ;
146136
@@ -153,30 +143,20 @@ export async function runCheckWorker(): Promise<void> {
153143 agentInstructions = loadLocalAgentInstructions ( config . agentSource ) ;
154144 }
155145
156- // Construct initial chat history
157- const chatHistory : ChatHistoryItem [ ] = [ ] ;
158-
159- if ( systemMessage ) {
160- chatHistory . push ( {
161- message : { role : "user" , content : systemMessage } ,
162- contextItems : [ ] ,
163- } ) ;
164- }
146+ // Build the user prompt parts and add to ChatHistoryService
147+ // so streamChatResponse picks them up via refreshChatHistoryFromService
148+ const chatHistorySvc = services . chatHistory ;
165149
150+ const promptParts : string [ ] = [ ] ;
166151 if ( agentInstructions ) {
167- chatHistory . push ( {
168- message : {
169- role : "user" ,
170- content : `## Agent Instructions\n\n${ agentInstructions } ` ,
171- } ,
172- contextItems : [ ] ,
173- } ) ;
152+ promptParts . push ( `## Agent Instructions\n\n${ agentInstructions } ` ) ;
174153 }
154+ promptParts . push ( checkPrompt ) ;
175155
176- chatHistory . push ( {
177- message : { role : "user" , content : checkPrompt } ,
178- contextItems : [ ] ,
179- } ) ;
156+ const userMessage = promptParts . join ( "\n\n" ) ;
157+ chatHistorySvc . addUserMessage ( userMessage ) ;
158+
159+ const chatHistory = chatHistorySvc . getHistory ( ) ;
180160
181161 // Collect agent text output
182162 let agentOutput = "" ;
0 commit comments