From d0b708ae47c72632b0cb0aede0d6d9715cb97bf6 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 23 Aug 2025 12:19:52 -0700 Subject: [PATCH] feat: plan mode sys prompt --- extensions/cli/package.json | 2 +- extensions/cli/src/systemMessage.test.ts | 60 ++++++++++++++++++++++++ extensions/cli/src/systemMessage.ts | 15 +++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/extensions/cli/package.json b/extensions/cli/package.json index 2256d5b2f..469009fee 100644 --- a/extensions/cli/package.json +++ b/extensions/cli/package.json @@ -15,7 +15,7 @@ "test:e2e": "vitest run --config vitest.e2e.config.ts", "test:smoke": "node smoke-test.mjs", "build:tsc": "tsc -p tsconfig.build.json", - "build:local-deps": "cd ../../packages/config-types && npm run build && cd ../config-yaml && npm run build && cd ../openai-adapters && npm run build", + "build:local-deps": "cd ../../packages/config-types && npm i && npm run build && cd ../config-yaml && npm i && npm run build && cd ../fetch && npm i && npm run build && cd ../openai-adapters && npm i && npm run build", "build:validate": "node validate-aliases.mjs", "build:bundle": "node build.mjs", "build": "npm run build:local-deps && npm run build:validate && npm run build:bundle", diff --git a/extensions/cli/src/systemMessage.test.ts b/extensions/cli/src/systemMessage.test.ts index b76f4fb61..2610a50f1 100644 --- a/extensions/cli/src/systemMessage.test.ts +++ b/extensions/cli/src/systemMessage.test.ts @@ -146,4 +146,64 @@ Rule 3: Third rule`; expect(result).not.toContain("IMPORTANT: You are running in headless mode"); expect(result).not.toContain("Provide ONLY your final answer"); }); + + it("should add JSON format instructions when format is json", async () => { + const result = await constructSystemMessage(undefined, "json"); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).toContain("IMPORTANT: You are operating in JSON output mode"); + expect(result).toContain("Your final response MUST be valid JSON"); + expect(result).toContain("JSON.parse()"); + }); + + it("should add plan mode instructions when mode is plan", async () => { + const result = await constructSystemMessage(undefined, undefined, false, "plan"); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).toContain("PLAN MODE: You are operating in plan mode"); + expect(result).toContain("which means that your goal is to help the user investigate their ideas"); + expect(result).toContain("develop a plan before taking action"); + expect(result).toContain("read-only tools"); + expect(result).toContain("should not attempt to circumvent them to write / delete / create files"); + }); + + it("should not add plan mode instructions when mode is not plan", async () => { + const result = await constructSystemMessage(undefined, undefined, false, "normal"); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).not.toContain("PLAN MODE: You are operating in plan mode"); + expect(result).not.toContain("which means that your goal is to help the user investigate their ideas"); + }); + + it("should not add plan mode instructions when mode is undefined", async () => { + const result = await constructSystemMessage(); + + expect(result).toContain("You are an agent in the Continue CLI"); + expect(result).not.toContain("PLAN MODE: You are operating in plan mode"); + expect(result).not.toContain("which means that your goal is to help the user investigate their ideas"); + }); + + it("should include basic plan mode description", async () => { + const result = await constructSystemMessage(undefined, undefined, false, "plan"); + + expect(result).toContain("PLAN MODE: You are operating in plan mode"); + expect(result).toContain("read-only tools"); + expect(result).toContain("write / delete / create files"); + }); + + it("should combine plan mode with headless mode instructions", async () => { + const result = await constructSystemMessage(undefined, undefined, true, "plan"); + + expect(result).toContain("IMPORTANT: You are running in headless mode"); + expect(result).toContain("PLAN MODE: You are operating in plan mode"); + expect(result).toContain("which means that your goal is to help the user investigate their ideas"); + }); + + it("should combine plan mode with JSON format instructions", async () => { + const result = await constructSystemMessage(undefined, "json", false, "plan"); + + expect(result).toContain("IMPORTANT: You are operating in JSON output mode"); + expect(result).toContain("PLAN MODE: You are operating in plan mode"); + expect(result).toContain("which means that your goal is to help the user investigate their ideas"); + }); }); diff --git a/extensions/cli/src/systemMessage.ts b/extensions/cli/src/systemMessage.ts index 1f09ff5c6..03c43cf84 100644 --- a/extensions/cli/src/systemMessage.ts +++ b/extensions/cli/src/systemMessage.ts @@ -6,6 +6,8 @@ import pkg from "ignore-walk"; import { Minimatch } from "minimatch"; import { processRule } from "./args.js"; +import { PermissionMode } from "./permissions/types.js"; +import { modeService } from "./services/ModeService.js"; import { serviceContainer } from "./services/ServiceContainer.js"; import { ConfigServiceState, SERVICE_NAMES } from "./services/types.js"; const { WalkerSync } = pkg; @@ -116,16 +118,17 @@ async function getConfigYamlRules(): Promise { /** * Load and construct a comprehensive system message with base message and rules section - * @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 + * @param mode - Current permission mode * @returns The comprehensive system message with base message and rules section */ export async function constructSystemMessage( additionalRules?: string[], format?: "json", headless?: boolean, + mode?: PermissionMode, ): Promise { const agentFiles = ["AGENTS.md", "AGENT.md", "CLAUDE.md", "CODEX.md"]; @@ -163,6 +166,9 @@ export async function constructSystemMessage( const configYamlRules = await getConfigYamlRules(); processedRules.push(...configYamlRules); + // Get current mode if not provided + const currentMode = mode ?? modeService.getCurrentMode(); + // Construct the comprehensive system message let systemMessage = baseSystemMessage; @@ -185,6 +191,13 @@ Example response format: }`; } + // Add plan mode specific instructions if in plan mode + if (currentMode === "plan") { + systemMessage += ` + +PLAN MODE: You are operating in plan mode, which means that your goal is to help the user investigate their ideas and develop a plan before taking action. You only have access to read-only tools and should not attempt to circumvent them to write / delete / create files.`; +} + // Add rules section if we have any rules or agent content if (agentContent || processedRules.length > 0) { systemMessage += '\n\n';