2
0
Эх сурвалжийг харах

Include the original task in the power steering content

Matt Rubens 10 сар өмнө
parent
commit
86896a8865

+ 5 - 0
.changeset/weak-swans-study.md

@@ -0,0 +1,5 @@
+---
+"roo-cline": patch
+---
+
+Include the original task in the power steering content

+ 19 - 5
src/core/Cline.ts

@@ -3243,6 +3243,9 @@ export class Cline {
 			customInstructions: globalCustomInstructions,
 			customInstructions: globalCustomInstructions,
 			preferredLanguage,
 			preferredLanguage,
 		} = (await this.providerRef.deref()?.getState()) ?? {}
 		} = (await this.providerRef.deref()?.getState()) ?? {}
+
+		const powerSteering = Experiments.isEnabled(experiments ?? {}, EXPERIMENT_IDS.POWER_STEERING)
+
 		const currentMode = mode ?? defaultModeSlug
 		const currentMode = mode ?? defaultModeSlug
 		const modeDetails = await getFullModeDetails(currentMode, customModes, customModePrompts, {
 		const modeDetails = await getFullModeDetails(currentMode, customModes, customModePrompts, {
 			cwd,
 			cwd,
@@ -3252,11 +3255,8 @@ export class Cline {
 		details += `\n\n# Current Mode\n`
 		details += `\n\n# Current Mode\n`
 		details += `<slug>${currentMode}</slug>\n`
 		details += `<slug>${currentMode}</slug>\n`
 		details += `<name>${modeDetails.name}</name>\n`
 		details += `<name>${modeDetails.name}</name>\n`
-		if (Experiments.isEnabled(experiments ?? {}, EXPERIMENT_IDS.POWER_STEERING)) {
+		if (powerSteering) {
 			details += `<role>${modeDetails.roleDefinition}</role>\n`
 			details += `<role>${modeDetails.roleDefinition}</role>\n`
-			if (modeDetails.customInstructions) {
-				details += `<custom_instructions>${modeDetails.customInstructions}</custom_instructions>\n`
-			}
 		}
 		}
 
 
 		// Add warning if not in code mode
 		// Add warning if not in code mode
@@ -3268,7 +3268,21 @@ export class Cline {
 		) {
 		) {
 			const currentModeName = getModeBySlug(currentMode, customModes)?.name ?? currentMode
 			const currentModeName = getModeBySlug(currentMode, customModes)?.name ?? currentMode
 			const defaultModeName = getModeBySlug(defaultModeSlug, customModes)?.name ?? defaultModeSlug
 			const defaultModeName = getModeBySlug(defaultModeSlug, customModes)?.name ?? defaultModeSlug
-			details += `\n\nNOTE: You are currently in '${currentModeName}' mode which only allows read-only operations. To write files or execute commands, the user will need to switch to '${defaultModeName}' mode. Note that only the user can switch modes.`
+			details += `\n\nNOTE: You are currently in '${currentModeName}' mode which only allows read-only operations. To write files or execute commands, the user will need to switch to '${defaultModeName}' mode or another mode with these capabilities. Note that only the user can switch modes.`
+		}
+
+		if (powerSteering) {
+			if (modeDetails.customInstructions) {
+				details += `\n\n# Custom Instructions\n`
+				details += `<custom_instructions>${modeDetails.customInstructions}</custom_instructions>\n`
+			}
+
+			const taskMessage = this.clineMessages[0]?.text ?? ""
+
+			if (taskMessage) {
+				details += `\n\n# Current Task\n\n`
+				details += `<task>${taskMessage}</task>\n`
+			}
 		}
 		}
 
 
 		if (includeFileDetails) {
 		if (includeFileDetails) {

+ 84 - 0
src/core/__tests__/Cline.test.ts

@@ -466,6 +466,90 @@ describe("Cline", () => {
 			expect(details).toMatch(/1\/1\/2024.*5:00:00 AM.*\(America\/Los_Angeles, UTC-7:00\)/) // Full time string format
 			expect(details).toMatch(/1\/1\/2024.*5:00:00 AM.*\(America\/Los_Angeles, UTC-7:00\)/) // Full time string format
 		})
 		})
 
 
+		it("should maintain correct section order with context size before file listing", async () => {
+			const cline = new Cline(mockProvider, mockApiConfig, undefined, false, false, undefined, "test task")
+
+			const details = await cline["getEnvironmentDetails"](true)
+
+			const contextSizeIndex = details.indexOf("# Current Context Size")
+			const fileListingIndex = details.indexOf("# Current Working Directory")
+
+			expect(contextSizeIndex).toBeGreaterThan(-1)
+			expect(fileListingIndex).toBeGreaterThan(-1)
+			expect(contextSizeIndex).toBeLessThan(fileListingIndex)
+		})
+
+		it("should include power steering content when experiment is enabled", async () => {
+			// Mock provider state
+			mockProvider.getState = jest.fn().mockResolvedValue({
+				customInstructions: "test instructions",
+				mode: "code",
+				customModes: [],
+				customModePrompts: {},
+				preferredLanguage: "en",
+			})
+
+			const cline = new Cline(
+				mockProvider,
+				mockApiConfig,
+				"test instructions",
+				false,
+				false,
+				undefined,
+				"test task",
+			)
+
+			// Mock experiments module
+			const { experiments, EXPERIMENT_IDS } = require("../../shared/experiments")
+			jest.spyOn(experiments, "isEnabled").mockImplementation((config, id) => {
+				return id === EXPERIMENT_IDS.POWER_STEERING ? true : false
+			})
+
+			const details = await cline["getEnvironmentDetails"](false)
+
+			// Verify sections are present
+			expect(details).toContain("# Custom Instructions")
+			expect(details).toContain("# Current Task")
+
+			// Verify task content
+			expect(details).toContain("<task>test task</task>")
+		})
+
+		it("should exclude power steering content when experiment is disabled", async () => {
+			// Mock provider state
+			mockProvider.getState = jest.fn().mockResolvedValue({
+				customInstructions: "test instructions",
+				mode: "code",
+				customModes: [],
+				customModePrompts: {},
+				preferredLanguage: "en",
+			})
+
+			const cline = new Cline(
+				mockProvider,
+				mockApiConfig,
+				"test instructions",
+				false,
+				false,
+				undefined,
+				"test task",
+			)
+
+			// Mock experiments module
+			const { experiments, EXPERIMENT_IDS } = require("../../shared/experiments")
+			jest.spyOn(experiments, "isEnabled").mockImplementation((config, id) => {
+				return id === EXPERIMENT_IDS.POWER_STEERING ? false : true
+			})
+
+			const details = await cline["getEnvironmentDetails"](false)
+
+			// Verify sections are not present
+			expect(details).not.toContain("# Custom Instructions")
+			expect(details).not.toContain("<custom_instructions>")
+			expect(details).not.toContain("# Current Task")
+			expect(details).not.toContain("<task>")
+		})
+
 		describe("API conversation handling", () => {
 		describe("API conversation handling", () => {
 			it("should clean conversation history before sending to API", async () => {
 			it("should clean conversation history before sending to API", async () => {
 				const cline = new Cline(mockProvider, mockApiConfig, undefined, false, false, undefined, "test task")
 				const cline = new Cline(mockProvider, mockApiConfig, undefined, false, false, undefined, "test task")

+ 1 - 1
src/shared/__tests__/experiments.test.ts

@@ -7,7 +7,7 @@ describe("experiments", () => {
 			expect(experimentConfigsMap.POWER_STEERING).toMatchObject({
 			expect(experimentConfigsMap.POWER_STEERING).toMatchObject({
 				name: 'Use experimental "power steering" mode',
 				name: 'Use experimental "power steering" mode',
 				description:
 				description:
-					"When enabled, Roo will remind the model about the details of its current mode definition more frequently. This will lead to stronger adherence to role definitions and custom instructions, but will use more tokens per message.",
+					"When enabled, Roo will remind the model about the details of the original task and its current mode definition more frequently. This will lead to stronger adherence to its instructions, but will use more tokens per message.",
 				enabled: false,
 				enabled: false,
 			})
 			})
 		})
 		})

+ 1 - 1
src/shared/experiments.ts

@@ -39,7 +39,7 @@ export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
 	POWER_STEERING: {
 	POWER_STEERING: {
 		name: 'Use experimental "power steering" mode',
 		name: 'Use experimental "power steering" mode',
 		description:
 		description:
-			"When enabled, Roo will remind the model about the details of its current mode definition more frequently. This will lead to stronger adherence to role definitions and custom instructions, but will use more tokens per message.",
+			"When enabled, Roo will remind the model about the details of the original task and its current mode definition more frequently. This will lead to stronger adherence to its instructions, but will use more tokens per message.",
 		enabled: false,
 		enabled: false,
 	},
 	},
 }
 }