feat: plan mode sys prompt

This commit is contained in:
Nate 2025-08-23 12:19:52 -07:00
parent b6cfc7d83d
commit d0b708ae47
3 changed files with 75 additions and 2 deletions

View file

@ -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",

View file

@ -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");
});
});

View file

@ -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<string[]> {
/**
* 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<string> {
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<context name="userRules">';