Skip to content
3 changes: 2 additions & 1 deletion packages/types/src/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Keys, Equals, AssertEqual } from "./type-fu.js"
* ExperimentId
*/

export const experimentIds = ["powerSteering", "concurrentFileReads"] as const
export const experimentIds = ["powerSteering", "concurrentFileReads", "disableCompletionCommand"] as const

export const experimentIdsSchema = z.enum(experimentIds)

Expand All @@ -19,6 +19,7 @@ export type ExperimentId = z.infer<typeof experimentIdsSchema>
export const experimentsSchema = z.object({
powerSteering: z.boolean(),
concurrentFileReads: z.boolean(),
disableCompletionCommand: z.boolean(),
})

export type Experiments = z.infer<typeof experimentsSchema>
Expand Down
12 changes: 10 additions & 2 deletions src/core/prompts/sections/objective.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EXPERIMENT_IDS, experiments } from "../../../shared/experiments"
import { CodeIndexManager } from "../../../services/code-index/manager"

export function getObjectiveSection(codeIndexManager?: CodeIndexManager): string {
export function getObjectiveSection(codeIndexManager?: CodeIndexManager, experimentsConfig?: Record<string, boolean>): string {
const isCodebaseSearchAvailable = codeIndexManager &&
codeIndexManager.isFeatureEnabled &&
codeIndexManager.isFeatureConfigured &&
Expand All @@ -9,6 +10,13 @@ export function getObjectiveSection(codeIndexManager?: CodeIndexManager): string
const codebaseSearchInstruction = isCodebaseSearchAvailable
? "First, if the task involves understanding existing code or functionality, you MUST use the `codebase_search` tool to search for relevant code based on the task's intent BEFORE using any other search or file exploration tools. Then, "
: "First, "

// Check if command execution is disabled via experiment
const isCommandDisabled = experimentsConfig && experimentsConfig[EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND]

const commandInstruction = !isCommandDisabled
? " You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built."
: ""

return `====

Expand All @@ -19,6 +27,6 @@ You accomplish a given task iteratively, breaking it down into clear steps and w
1. Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.
2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go.
3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. ${codebaseSearchInstruction}analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Next, think about which of the provided tools is the most relevant tool to accomplish the user's task. Go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool. DO NOT ask for more information on optional parameters if it is not provided.
4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built.
4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user.${commandInstruction}
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.`
}
2 changes: 1 addition & 1 deletion src/core/prompts/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ${getRulesSection(cwd, supportsComputerUse, effectiveDiffStrategy, codeIndexMana

${getSystemInfoSection(cwd)}

${getObjectiveSection(codeIndexManager)}
${getObjectiveSection(codeIndexManager, experiments)}

${await addCustomInstructions(baseInstructions, globalCustomInstructions || "", cwd, mode, { language: language ?? formatLanguage(vscode.env.language), rooIgnoreInstructions })}`

Expand Down
129 changes: 129 additions & 0 deletions src/core/prompts/tools/__tests__/attempt-completion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { getAttemptCompletionDescription } from "../attempt-completion"
import { EXPERIMENT_IDS } from "../../../../shared/experiments"

describe("getAttemptCompletionDescription - DISABLE_COMPLETION_COMMAND experiment", () => {
describe("when experiment is disabled (default)", () => {
it("should include command parameter in the description", () => {
const args = {
cwd: "/test/path",
supportsComputerUse: false,
experiments: {
[EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND]: false,
},
}

const description = getAttemptCompletionDescription(args)

// Check that command parameter is included
expect(description).toContain("- command: (optional)")
expect(description).toContain("A CLI command to execute to show a live demo")
expect(description).toContain("<command>Command to demonstrate result (optional)</command>")
expect(description).toContain("<command>open index.html</command>")
})

it("should include command parameter when experiments is undefined", () => {
const args = {
cwd: "/test/path",
supportsComputerUse: false,
}

const description = getAttemptCompletionDescription(args)

// Check that command parameter is included
expect(description).toContain("- command: (optional)")
expect(description).toContain("A CLI command to execute to show a live demo")
expect(description).toContain("<command>Command to demonstrate result (optional)</command>")
expect(description).toContain("<command>open index.html</command>")
})

it("should include command parameter when no args provided", () => {
const description = getAttemptCompletionDescription()

// Check that command parameter is included
expect(description).toContain("- command: (optional)")
expect(description).toContain("A CLI command to execute to show a live demo")
expect(description).toContain("<command>Command to demonstrate result (optional)</command>")
expect(description).toContain("<command>open index.html</command>")
})
})

describe("when experiment is enabled", () => {
it("should NOT include command parameter in the description", () => {
const args = {
cwd: "/test/path",
supportsComputerUse: false,
experiments: {
[EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND]: true,
},
}

const description = getAttemptCompletionDescription(args)

// Check that command parameter is NOT included
expect(description).not.toContain("- command: (optional)")
expect(description).not.toContain("A CLI command to execute to show a live demo")
expect(description).not.toContain("<command>Command to demonstrate result (optional)</command>")
expect(description).not.toContain("<command>open index.html</command>")

// But should still have the basic structure
expect(description).toContain("## attempt_completion")
expect(description).toContain("- result: (required)")
expect(description).toContain("<attempt_completion>")
expect(description).toContain("</attempt_completion>")
})

it("should show example without command", () => {
const args = {
cwd: "/test/path",
supportsComputerUse: false,
experiments: {
[EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND]: true,
},
}

const description = getAttemptCompletionDescription(args)

// Check example format
expect(description).toContain("Example: Requesting to attempt completion with a result")
expect(description).toContain("I've updated the CSS")
expect(description).not.toContain("Example: Requesting to attempt completion with a result and command")
})
})

describe("description content", () => {
it("should maintain core functionality description regardless of experiment", () => {
const argsWithExperimentDisabled = {
cwd: "/test/path",
supportsComputerUse: false,
experiments: {
[EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND]: false,
},
}

const argsWithExperimentEnabled = {
cwd: "/test/path",
supportsComputerUse: false,
experiments: {
[EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND]: true,
},
}

const descriptionDisabled = getAttemptCompletionDescription(argsWithExperimentDisabled)
const descriptionEnabled = getAttemptCompletionDescription(argsWithExperimentEnabled)

// Both should contain core functionality
const coreText = "After each tool use, the user will respond with the result of that tool use"
expect(descriptionDisabled).toContain(coreText)
expect(descriptionEnabled).toContain(coreText)

// Both should contain the important note
const importantNote = "IMPORTANT NOTE: This tool CANNOT be used until you've confirmed"
expect(descriptionDisabled).toContain(importantNote)
expect(descriptionEnabled).toContain(importantNote)

// Both should contain result parameter
expect(descriptionDisabled).toContain("- result: (required)")
expect(descriptionEnabled).toContain("- result: (required)")
})
})
})
39 changes: 31 additions & 8 deletions src/core/prompts/tools/attempt-completion.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
export function getAttemptCompletionDescription(): string {
return `## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. Optionally you may provide a CLI command to showcase the result of your work. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
import { EXPERIMENT_IDS, experiments } from "../../../shared/experiments"
import { ToolArgs } from "./types"

export function getAttemptCompletionDescription(args?: ToolArgs): string {
// Check if command execution is disabled via experiment
const isCommandDisabled = args?.experiments && experiments.isEnabled(
args.experiments,
EXPERIMENT_IDS.DISABLE_COMPLETION_COMMAND
)

const baseDescription = `## attempt_completion
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user.${!isCommandDisabled ? ' Optionally you may provide a CLI command to showcase the result of your work.' : ''} The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Parameters:
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
- command: (optional) A CLI command to execute to show a live demo of the result to the user. For example, use \`open index.html\` to display a created html website, or \`open localhost:3000\` to display a locally running development server. But DO NOT use commands like \`echo\` or \`cat\` that merely print text. This command should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.`

const commandParameter = !isCommandDisabled ? `
- command: (optional) A CLI command to execute to show a live demo of the result to the user. For example, use \`open index.html\` to display a created html website, or \`open localhost:3000\` to display a locally running development server. But DO NOT use commands like \`echo\` or \`cat\` that merely print text. This command should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.` : ''

const usage = `
Usage:
<attempt_completion>
<result>
Your final result description here
</result>
<command>Command to demonstrate result (optional)</command>
</attempt_completion>
</result>${!isCommandDisabled ? '\n<command>Command to demonstrate result (optional)</command>' : ''}
</attempt_completion>`

const example = !isCommandDisabled ? `

Example: Requesting to attempt completion with a result and command
<attempt_completion>
<result>
I've updated the CSS
</result>
<command>open index.html</command>
</attempt_completion>` : `

Example: Requesting to attempt completion with a result
<attempt_completion>
<result>
I've updated the CSS
</result>
</attempt_completion>`

return baseDescription + commandParameter + usage + example
}
3 changes: 2 additions & 1 deletion src/core/prompts/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
list_code_definition_names: (args) => getListCodeDefinitionNamesDescription(args),
browser_action: (args) => getBrowserActionDescription(args),
ask_followup_question: () => getAskFollowupQuestionDescription(),
attempt_completion: () => getAttemptCompletionDescription(),
attempt_completion: (args) => getAttemptCompletionDescription(args),
use_mcp_tool: (args) => getUseMcpToolDescription(args),
access_mcp_resource: (args) => getAccessMcpResourceDescription(args),
codebase_search: () => getCodebaseSearchDescription(),
Expand Down Expand Up @@ -69,6 +69,7 @@ export function getToolDescriptionsForMode(
mcpHub,
partialReadsEnabled,
settings,
experiments,
}

const tools = new Set<string>()
Expand Down
1 change: 1 addition & 0 deletions src/core/prompts/tools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type ToolArgs = {
toolOptions?: any
partialReadsEnabled?: boolean
settings?: Record<string, any>
experiments?: Record<string, boolean>
}
Loading
Loading