Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/prompts/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,6 @@ export {
getRunSlashCommandDescription,
getGenerateImageDescription,
}

// Export native tool definitions (JSON schema format for OpenAI-compatible APIs)
export { nativeTools } from "./native-tools"
93 changes: 93 additions & 0 deletions src/core/prompts/tools/native-tools/apply_diff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import type OpenAI from "openai"

export const apply_diff_single_file = {
type: "function",
function: {
name: "apply_diff",
description: `
Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for.
`,
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "The path of the file to modify, relative to the current workspace directory.",
},
diff: {
type: "string",
description: `
A string containing one or more search/replace blocks defining the changes. The ':start_line:' is required and indicates the starting line number of the original content. You must not add a start line for the replacement content. Each block must follow this format:
<<<<<<< SEARCH
:start_line:[line_number]
-------
[exact content to find]
=======
[new content to replace with]
>>>>>>> REPLACE
`,
},
},
required: ["path", "diff"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool

//@ts-ignore Preparing for when we enable multi-file diffs
export const apply_diff_multi_file = {
type: "function",
function: {
name: "apply_diff",
description:
"Apply precise, targeted modifications to one or more files by searching for specific sections of content and replacing them. This tool is for surgical edits only and supports making changes across multiple files in a single request. The 'SEARCH' block must exactly match the existing content, including whitespace and indentation. You must use this tool to edit multiple files in a single operation whenever possible.",
parameters: {
type: "object",
properties: {
files: {
type: "array",
description: "A list of file modification operations to perform.",
items: {
type: "object",
properties: {
path: {
type: "string",
description:
"The path of the file to modify, relative to the current workspace directory.",
},
diffs: {
type: "array",
description:
"A list of diffs to apply to the file. Each diff is a distinct search/replace operation.",
items: {
type: "object",
properties: {
content: {
type: "string",
description: `
The search/replace block defining the changes. The SEARCH block must exactly match the content to be replaced. Format:
'<<<<<<< SEARCH
[content_to_find]
=======
[content_to_replace_with]
>>>>>>> REPLACE
`,
},
start_line: {
type: "integer",
description:
"The line number in the original file where the SEARCH block begins.",
},
},
required: ["content", "start_line"],
},
},
},
required: ["path", "diffs"],
},
},
},
required: ["files"],
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
45 changes: 45 additions & 0 deletions src/core/prompts/tools/native-tools/ask_followup_question.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "ask_followup_question",
description:
"Ask the user a question to gather additional information needed to complete the task. Use when clarification or more detail is required before proceeding.",
strict: true,
parameters: {
type: "object",
properties: {
question: {
type: "string",
description: "Clear, specific question that captures the missing information you need",
},
follow_up: {
type: "array",
description:
"Required list of 2-4 suggested responses; each suggestion must be a complete, actionable answer and may include a mode switch",
items: {
type: "object",
properties: {
text: {
type: "string",
description: "Suggested answer the user can pick",
},
mode: {
type: ["string", "null"],
description:
"Optional mode slug to switch to if this suggestion is chosen (e.g., code, architect)",
},
},
required: ["text", "mode"],
additionalProperties: false,
},
minItems: 2,
maxItems: 4,
},
},
required: ["question", "follow_up"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
22 changes: 22 additions & 0 deletions src/core/prompts/tools/native-tools/attempt_completion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "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. 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 confirm that you've received successful results from the user for any previous tool uses. If not, then DO NOT use this tool.",
strict: true,
parameters: {
type: "object",
properties: {
result: {
type: "string",
description: "Final result message to deliver to the user once the task is complete",
},
},
required: ["result"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
64 changes: 64 additions & 0 deletions src/core/prompts/tools/native-tools/browser_action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "browser_action",
description:
"Interact with a Puppeteer-controlled browser session. Always start by launching at a URL and always finish by closing the browser. While the browser is active, do not call any other tools. Use coordinates within the viewport to hover or click, provide text for typing, and ensure actions are grounded in the latest screenshot and console logs.",
strict: true,
parameters: {
type: "object",
properties: {
action: {
type: "string",
description: "Browser action to perform",
enum: ["launch", "hover", "click", "type", "resize", "scroll_down", "scroll_up", "close"],
},
url: {
type: ["string", "null"],
description: "URL to open when performing the launch action; must include protocol",
},
coordinate: {
type: ["object", "null"],
description:
"Screen coordinate for hover or click actions; target the center of the desired element",
properties: {
x: {
type: "number",
description: "Horizontal pixel position within the current viewport",
},
y: {
type: "number",
description: "Vertical pixel position within the current viewport",
},
},
required: ["x", "y"],
additionalProperties: false,
},
size: {
type: ["object", "null"],
description: "Viewport dimensions to apply when performing the resize action",
properties: {
width: {
type: "number",
description: "Viewport width in pixels",
},
height: {
type: "number",
description: "Viewport height in pixels",
},
},
required: ["width", "height"],
additionalProperties: false,
},
text: {
type: ["string", "null"],
description: "Text to type when performing the type action",
},
},
required: ["action", "url", "coordinate", "size", "text"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
26 changes: 26 additions & 0 deletions src/core/prompts/tools/native-tools/codebase_search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "codebase_search",
description:
"Run a semantic search across the workspace to find files relevant to a natural-language query. Reuse the user's wording where possible and keep queries in English.",
strict: true,
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "Meaning-based search query describing the information you need",
},
path: {
type: ["string", "null"],
description: "Optional subdirectory (relative to the workspace) to limit the search scope",
},
},
required: ["query", "path"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
31 changes: 31 additions & 0 deletions src/core/prompts/tools/native-tools/edit_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "edit_file",
description:
"Use this tool to make an edit to a file. A less intelligent apply model will read your request, so be clear about the change while minimizing unchanged code. Specify each edit sequentially and replace omitted sections with // ... existing code ... placeholders. Provide enough surrounding context to avoid ambiguity, always use the placeholder when skipping existing content, show before-and-after context when deleting, and gather all edits for the file in a single request.",
strict: true,
parameters: {
type: "object",
properties: {
target_file: {
type: "string",
description: "Full path of the file to modify",
},
instructions: {
type: "string",
description: "Single first-person sentence summarizing the edit to guide the apply model",
},
code_edit: {
type: "string",
description:
"Only the edited lines using // ... existing code ... wherever unchanged content is omitted",
},
},
required: ["target_file", "instructions", "code_edit"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
26 changes: 26 additions & 0 deletions src/core/prompts/tools/native-tools/execute_command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "execute_command",
description:
"Run a CLI command on the user's system. Tailor the command to the environment, explain what it does, and prefer relative paths or shell-appropriate chaining. Use the cwd parameter only when directed to run in a different directory.",
strict: true,
parameters: {
type: "object",
properties: {
command: {
type: "string",
description: "Shell command to execute",
},
cwd: {
type: ["string", "null"],
description: "Optional working directory for the command, relative or absolute",
},
},
required: ["command", "cwd"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
23 changes: 23 additions & 0 deletions src/core/prompts/tools/native-tools/fetch_instructions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "fetch_instructions",
description:
"Retrieve detailed instructions for performing a predefined task, such as creating an MCP server or creating a mode.",
strict: true,
parameters: {
type: "object",
properties: {
task: {
type: "string",
description: "Task identifier to fetch instructions for",
enum: ["create_mcp_server", "create_mode"],
},
},
required: ["task"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
32 changes: 32 additions & 0 deletions src/core/prompts/tools/native-tools/generate_image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type OpenAI from "openai"

export default {
type: "function",
function: {
name: "generate_image",
description:
"Create a new image or edit an existing one using OpenRouter image models. Provide a prompt describing the desired output, choose where to save the image in the current workspace, and optionally supply an input image to transform.",
strict: true,
parameters: {
type: "object",
properties: {
prompt: {
type: "string",
description: "Text description of the image to generate or the edits to apply",
},
path: {
type: "string",
description:
"Filesystem path (relative to the workspace) where the resulting image should be saved",
},
image: {
type: ["string", "null"],
description:
"Optional path (relative to the workspace) to an existing image to edit; supports PNG, JPG, JPEG, GIF, and WEBP",
},
},
required: ["prompt", "path", "image"],
additionalProperties: false,
},
},
} satisfies OpenAI.Chat.ChatCompletionTool
Loading