-
Notifications
You must be signed in to change notification settings - Fork 518
Expand file tree
/
Copy patheditor.ts
More file actions
139 lines (112 loc) · 4.29 KB
/
editor.ts
File metadata and controls
139 lines (112 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { publisher } from '../constants'
import type { AgentDefinition } from '../types/agent-definition'
export const createCodeEditor = (options: {
model: 'gpt-5' | 'opus' | 'glm'
}): Omit<AgentDefinition, 'id'> => {
const { model } = options
return {
publisher,
model:
options.model === 'gpt-5'
? 'openai/gpt-5.1'
: options.model === 'glm'
? 'z-ai/glm-5.1'
: 'anthropic/claude-opus-4.6',
...(options.model === 'opus' && {
providerOptions: {
only: ['amazon-bedrock'],
},
}),
displayName: 'Code Editor',
spawnerPrompt:
"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 read any files intended to be edited before spawning this agent as it cannot read files on its own.",
outputMode: 'structured_output',
toolNames: ['write_file', 'str_replace', 'set_output'],
includeMessageHistory: true,
inheritParentSystemPrompt: true,
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.
Your task is to write out ALL the code changes needed to complete the user's request in a single comprehensive response.
Important: You can not make any other tool calls besides editing files. You cannot read more files, write todos, spawn agents, or set output. set_output in particular should not be used. Do not call any of these tools!
Write out what changes you would make using the tool call format below. Use this exact format for each file change:
<codebuff_tool_call>
{
"cb_tool_name": "str_replace",
"path": "path/to/file",
"replacements": [
{
"old": "exact old code",
"new": "exact new code"
},
{
"old": "exact old code 2",
"new": "exact new code 2"
},
]
}
</codebuff_tool_call>
OR for new files or major rewrites:
<codebuff_tool_call>
{
"cb_tool_name": "write_file",
"path": "path/to/file",
"instructions": "What the change does",
"content": "Complete file content"
}
</codebuff_tool_call>
${model === 'gpt-5' || model === 'glm'
? ''
: `Before you start writing your implementation, you should use <think> tags to think about the best way to implement the changes.
You can also use <think> tags interspersed between tool calls to think about the best way to implement the changes.
<example>
<think>
[ Long think about the best way to implement the changes ]
</think>
<codebuff_tool_call>
[ First tool call to implement the feature ]
</codebuff_tool_call>
<codebuff_tool_call>
[ Second tool call to implement the feature ]
</codebuff_tool_call>
<think>
[ Thoughts about a tricky part of the implementation ]
</think>
<codebuff_tool_call>
[ Third tool call to implement the feature ]
</codebuff_tool_call>
</example>`
}
Your implementation should:
- Be complete and comprehensive
- Include all necessary changes to fulfill the user's request
- Follow the project's conventions and patterns
- Be as simple and maintainable as possible
- Reuse existing code wherever possible
- Be well-structured and organized
More style notes:
- Extra try/catch blocks clutter the code -- use them sparingly.
- Optional arguments are code smell and worse than required arguments.
- New components often should be added to a new file, not added to an existing file.
Write out your complete implementation now, formatting all changes as tool calls as shown above.`,
handleSteps: function* ({ agentState: initialAgentState, logger }) {
const initialMessageHistoryLength =
initialAgentState.messageHistory.length
const { agentState } = yield 'STEP'
const { messageHistory } = agentState
const newMessages = messageHistory.slice(initialMessageHistoryLength)
yield {
toolName: 'set_output',
input: {
output: {
messages: newMessages,
},
},
includeToolCall: false,
}
},
} satisfies Omit<AgentDefinition, 'id'>
}
const definition = {
...createCodeEditor({ model: 'opus' }),
id: 'editor',
}
export default definition