|
| 1 | + |
| 2 | +import { publisher } from '../constants' |
| 3 | + |
| 4 | +import type { AgentDefinition } from '../types/agent-definition' |
| 5 | + |
| 6 | +export const createCodeEditor = (options: { |
| 7 | + model: 'gpt-5' | 'opus' | 'minimax' |
| 8 | +}): Omit<AgentDefinition, 'id'> => { |
| 9 | + const { model } = options |
| 10 | + return { |
| 11 | + publisher, |
| 12 | + model: |
| 13 | + options.model === 'gpt-5' |
| 14 | + ? 'openai/gpt-5.4' |
| 15 | + : options.model === 'minimax' |
| 16 | + ? 'minimax/minimax-m2.5' |
| 17 | + : 'anthropic/claude-opus-4.6', |
| 18 | + ...(options.model === 'opus' && { |
| 19 | + providerOptions: { |
| 20 | + only: ['amazon-bedrock'], |
| 21 | + }, |
| 22 | + }), |
| 23 | + displayName: 'Editor', |
| 24 | + spawnerPrompt: |
| 25 | + "Expert code editor that implements code changes based on the user's request. Do not specify an input prompt for this agent; it inherits the context of the entire conversation with the user. Make sure to gather as much context as possible and read any related files (be extremely comprehensive!) before spawning this agent as it cannot read files on its own.", |
| 26 | + outputMode: 'structured_output', |
| 27 | + toolNames: [ |
| 28 | + // 'read_files', |
| 29 | + // 'read_subtree', |
| 30 | + // 'skill', |
| 31 | + // 'set_output', |
| 32 | + // 'code_search', |
| 33 | + // 'list_directory', |
| 34 | + // 'glob', |
| 35 | + 'write_file', |
| 36 | + 'str_replace', |
| 37 | + 'patch_file' |
| 38 | + ], |
| 39 | + spawnableAgents: [ |
| 40 | + // 'file-picker', |
| 41 | + // 'researcher-web', |
| 42 | + // 'researcher-docs', |
| 43 | + // 'basher', |
| 44 | + // 'tmux-cli', |
| 45 | + // 'browser-use', |
| 46 | + // 'context-pruner', |
| 47 | + ], |
| 48 | + includeMessageHistory: true, |
| 49 | + systemPrompt: `You are a code editor called upon solely to modify files without using other tools. After you finish, another agent will complete the overall task, including running the type checker, running tests, etc. Your job is only to do one pass on the file editing.`, |
| 50 | + instructionsPrompt: `You are an expert code editor with deep understanding of software engineering principles. You were spawned to generate an implementation for the user's request. Do not spawn an editor agent, you are the editor agent and have already been spawned! |
| 51 | + |
| 52 | +Your task is to write out ALL the code changes needed to complete the user's request in a single comprehensive response. |
| 53 | +
|
| 54 | +Important: You DO NOT have access to tools other than patch_file, write_file, or str_replace file editing tools. You cannot read more files, search the codebase, use glob patterns, run terminal commands (e.g. running the type checker), or use any other tools. You must implement the changes with the context you have already gathered. The rest of the task will be finished by another agent. |
| 55 | +
|
| 56 | +${model === 'opus' |
| 57 | + ? `Before you start writing your implementation, you should use <think> tags to think about the best way to implement the changes. |
| 58 | +
|
| 59 | +You can also use <think> tags interspersed between tool calls to think about the best way to implement the changes. |
| 60 | +
|
| 61 | +<example> |
| 62 | +
|
| 63 | +<think> |
| 64 | +[ Long think about the best way to implement the changes ] |
| 65 | +</think> |
| 66 | +
|
| 67 | +[ First tool call to implement the feature ] |
| 68 | +
|
| 69 | +[ Second tool call to implement the feature ] |
| 70 | +
|
| 71 | +<think> |
| 72 | +[ Thoughts about a tricky part of the implementation ] |
| 73 | +</think> |
| 74 | +
|
| 75 | +[ Third tool call to implement the feature ] |
| 76 | +
|
| 77 | +... |
| 78 | +
|
| 79 | +[ Last tool call to implement the feature ] |
| 80 | +</example>` : ''} |
| 81 | +
|
| 82 | +Your implementation should: |
| 83 | +- Be complete and comprehensive |
| 84 | +- Include all necessary changes to fulfill the user's request |
| 85 | +- Follow the project's conventions and patterns |
| 86 | +- Be as simple and maintainable as possible |
| 87 | +- Reuse existing code wherever possible |
| 88 | +- Be well-structured and organized |
| 89 | +
|
| 90 | +More style notes: |
| 91 | +- Try/catch blocks clutter the code -- use them sparingly. |
| 92 | +- Optional arguments are code smell -- better to use required arguments. |
| 93 | +- New components often should be added to a new file, not added to an existing file. |
| 94 | +
|
| 95 | +Write out your complete implementation now. Your job is only to make these specific changes and not to do anything else (e.g. do not use terminal commands, do not review the code, do not write any final summary). You must stop abruptly as soon as you have made the last edit.`, |
| 96 | + |
| 97 | + handleSteps: function* ({ agentState: initialAgentState, logger }) { |
| 98 | + const initialMessageHistoryLength = |
| 99 | + initialAgentState.messageHistory.length |
| 100 | + const { agentState } = yield 'STEP_ALL' |
| 101 | + const { messageHistory } = agentState |
| 102 | + |
| 103 | + const newMessages = messageHistory.slice(initialMessageHistoryLength) |
| 104 | + |
| 105 | + yield { |
| 106 | + toolName: 'set_output', |
| 107 | + input: { |
| 108 | + output: { |
| 109 | + messages: newMessages, |
| 110 | + }, |
| 111 | + }, |
| 112 | + includeToolCall: false, |
| 113 | + } |
| 114 | + }, |
| 115 | + } satisfies Omit<AgentDefinition, 'id'> |
| 116 | +} |
| 117 | + |
| 118 | +const definition = { |
| 119 | + ...createCodeEditor({ model: 'gpt-5' }), |
| 120 | + id: 'editor-gpt', |
| 121 | +} |
| 122 | +export default definition |
0 commit comments