@@ -31,7 +31,11 @@ type PatchTool struct {
31
31
Callback PatchCallback // may be nil
32
32
// Pwd is the working directory for resolving relative paths
33
33
Pwd string
34
+ // Simplified indicates whether to use the simplified input schema.
35
+ // Helpful for weaker models.
36
+ Simplified bool
34
37
// ClipboardEnabled controls whether clipboard functionality is enabled.
38
+ // Ignored if Simplified is true.
35
39
// NB: The actual implementation of the patch tool is unchanged,
36
40
// this flag merely extends the description and input schema to include the clipboard operations.
37
41
ClipboardEnabled bool
@@ -43,7 +47,10 @@ type PatchTool struct {
43
47
func (p * PatchTool ) Tool () * llm.Tool {
44
48
description := PatchBaseDescription + PatchUsageNotes
45
49
schema := PatchStandardInputSchema
46
- if p .ClipboardEnabled {
50
+ switch {
51
+ case p .Simplified :
52
+ schema = PatchStandardSimplifiedSchema
53
+ case p .ClipboardEnabled :
47
54
description = PatchBaseDescription + PatchClipboardDescription + PatchUsageNotes
48
55
schema = PatchClipboardInputSchema
49
56
}
@@ -130,6 +137,36 @@ Usage notes:
130
137
}
131
138
`
132
139
140
+ PatchStandardSimplifiedSchema = `{
141
+ "type": "object",
142
+ "required": ["path", "patch"],
143
+ "properties": {
144
+ "path": {
145
+ "type": "string",
146
+ "description": "Path to the file to patch"
147
+ },
148
+ "patch": {
149
+ "type": "object",
150
+ "required": ["operation", "newText"],
151
+ "properties": {
152
+ "operation": {
153
+ "type": "string",
154
+ "enum": ["replace", "append_eof", "prepend_bof", "overwrite"],
155
+ "description": "Type of operation to perform"
156
+ },
157
+ "oldText": {
158
+ "type": "string",
159
+ "description": "Text to locate for the operation (must be unique in file, required for replace)"
160
+ },
161
+ "newText": {
162
+ "type": "string",
163
+ "description": "The new text to use (empty for deletions)"
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }`
169
+
133
170
PatchClipboardInputSchema = `
134
171
{
135
172
"type": "object",
@@ -199,8 +236,14 @@ type PatchInput struct {
199
236
200
237
// PatchInputOne is a simplified version of PatchInput for single patch operations.
201
238
type PatchInputOne struct {
202
- Path string `json:"path"`
203
- Patches PatchRequest `json:"patches"`
239
+ Path string `json:"path"`
240
+ Patches * PatchRequest `json:"patches"`
241
+ }
242
+
243
+ // PatchInputOneSingular is PatchInputOne with a better name for the singular case.
244
+ type PatchInputOneSingular struct {
245
+ Path string `json:"path"`
246
+ Patch * PatchRequest `json:"patch"`
204
247
}
205
248
206
249
type PatchInputOneString struct {
@@ -253,17 +296,21 @@ func (p *PatchTool) Run(ctx context.Context, m json.RawMessage) llm.ToolOut {
253
296
func (p * PatchTool ) patchParse (m json.RawMessage ) (PatchInput , error ) {
254
297
var input PatchInput
255
298
originalErr := json .Unmarshal (m , & input )
256
- if originalErr == nil {
299
+ if originalErr == nil && len ( input . Patches ) > 0 {
257
300
return input , nil
258
301
}
259
302
var inputOne PatchInputOne
260
- if err := json .Unmarshal (m , & inputOne ); err == nil {
261
- return PatchInput {Path : inputOne .Path , Patches : []PatchRequest {inputOne .Patches }}, nil
303
+ if err := json .Unmarshal (m , & inputOne ); err == nil && inputOne .Patches != nil {
304
+ return PatchInput {Path : inputOne .Path , Patches : []PatchRequest {* inputOne .Patches }}, nil
305
+ }
306
+ var inputOneSingular PatchInputOneSingular
307
+ if err := json .Unmarshal (m , & inputOneSingular ); err == nil && inputOneSingular .Patch != nil {
308
+ return PatchInput {Path : inputOneSingular .Path , Patches : []PatchRequest {* inputOneSingular .Patch }}, nil
262
309
}
263
310
var inputOneString PatchInputOneString
264
311
if err := json .Unmarshal (m , & inputOneString ); err == nil {
265
312
var onePatch PatchRequest
266
- if err := json .Unmarshal ([]byte (inputOneString .Patches ), & onePatch ); err == nil {
313
+ if err := json .Unmarshal ([]byte (inputOneString .Patches ), & onePatch ); err == nil && onePatch . Operation != "" {
267
314
return PatchInput {Path : inputOneString .Path , Patches : []PatchRequest {onePatch }}, nil
268
315
}
269
316
var patches []PatchRequest
0 commit comments