diff --git a/src/commands/chat.ts b/src/commands/chat.ts index 902d01f15..6a7d3ebe8 100644 --- a/src/commands/chat.ts +++ b/src/commands/chat.ts @@ -72,7 +72,8 @@ export async function initializeChatHistory( const systemMessage = await constructSystemMessage( rulesSystemMessage, options.rule, - options.format + options.format, + options.headless ); if (systemMessage) { chatHistory.push({ role: "system", content: systemMessage }); diff --git a/src/commands/serve.ts b/src/commands/serve.ts index d1d404364..9ebfd9d68 100644 --- a/src/commands/serve.ts +++ b/src/commands/serve.ts @@ -105,7 +105,7 @@ export async function serve(prompt?: string, options: ServeOptions = {}) { // Initialize chat history let chatHistory: ChatCompletionMessageParam[] = []; - const systemMessage = await constructSystemMessage("", options.rule); + const systemMessage = await constructSystemMessage("", options.rule, undefined, true); if (systemMessage) { chatHistory.push({ role: "system", content: systemMessage }); } diff --git a/src/systemMessage.test.ts b/src/systemMessage.test.ts index 6f82681c3..680179e06 100644 --- a/src/systemMessage.test.ts +++ b/src/systemMessage.test.ts @@ -101,4 +101,29 @@ Rule 3: Third rule`; expect(result).toContain("AGENTS.md"); expect(result).toContain(""); }); + + it("should add headless mode instructions when headless is true", async () => { + const result = await constructSystemMessage("", undefined, undefined, true); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).toContain("IMPORTANT: You are running in headless mode"); + expect(result).toContain("Provide ONLY your final answer"); + expect(result).toContain("Do not include explanations, reasoning, or additional commentary"); + }); + + it("should not add headless mode instructions when headless is false", async () => { + const result = await constructSystemMessage("", undefined, undefined, false); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).not.toContain("IMPORTANT: You are running in headless mode"); + expect(result).not.toContain("Provide ONLY your final answer"); + }); + + it("should not add headless mode instructions when headless is undefined", async () => { + const result = await constructSystemMessage(""); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).not.toContain("IMPORTANT: You are running in headless mode"); + expect(result).not.toContain("Provide ONLY your final answer"); + }); }); diff --git a/src/systemMessage.ts b/src/systemMessage.ts index e7136d123..f4e006f2f 100644 --- a/src/systemMessage.ts +++ b/src/systemMessage.ts @@ -98,12 +98,14 @@ ${getGitStatus()} * @param rulesSystemMessage - The rules system message from the assistant * @param additionalRules - Additional rules from --rule flags * @param format - Output format for headless mode + * @param headless - Whether running in headless mode * @returns The comprehensive system message with base message and rules section */ export async function constructSystemMessage( rulesSystemMessage: string, additionalRules?: string[], - format?: "json" + format?: "json", + headless?: boolean ): Promise { const agentFiles = ["AGENTS.md", "AGENT.md", "CLAUDE.md", "CODEX.md"]; @@ -141,6 +143,13 @@ export async function constructSystemMessage( // Construct the comprehensive system message let systemMessage = baseSystemMessage; + // In headless mode, add instructions to be concise and only provide final answers + if (headless) { + systemMessage += ` + +IMPORTANT: You are running in headless mode. Provide ONLY your final answer to the user's question. Do not include explanations, reasoning, or additional commentary unless specifically requested. Be direct and concise.`; + } + // Add JSON formatting instructions if format is json if (format === "json") { systemMessage += `