@polka-codes/core 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -55,35 +55,27 @@ var toolInfo = {
55
55
  description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
56
56
  parameters: z.object({
57
57
  questions: z.array(questionObject).describe("One or more follow-up questions you need answered before you can continue.").meta({ usageValue: "questions here" })
58
- }),
59
- examples: [
60
- {
61
- description: "Single clarifying question (no options)",
62
- parameters: [
63
- {
64
- name: "questions",
65
- value: { prompt: "What is the target deployment environment?" }
58
+ }).meta({
59
+ examples: [
60
+ {
61
+ description: "Single clarifying question (no options)",
62
+ input: {
63
+ questions: { prompt: "What is the target deployment environment?" }
66
64
  }
67
- ]
68
- },
69
- {
70
- description: "Single question with multiple-choice options",
71
- parameters: [
72
- {
73
- name: "questions",
74
- value: {
65
+ },
66
+ {
67
+ description: "Single question with multiple-choice options",
68
+ input: {
69
+ questions: {
75
70
  prompt: "Which frontend framework are you using?",
76
71
  options: ["React", "Angular", "Vue", "Svelte"]
77
72
  }
78
73
  }
79
- ]
80
- },
81
- {
82
- description: "Two related questions in one call",
83
- parameters: [
84
- {
85
- name: "questions",
86
- value: [
74
+ },
75
+ {
76
+ description: "Two related questions in one call",
77
+ input: {
78
+ questions: [
87
79
  { prompt: "What type of application are you building?" },
88
80
  {
89
81
  prompt: "Preferred programming language?",
@@ -91,21 +83,18 @@ var toolInfo = {
91
83
  }
92
84
  ]
93
85
  }
94
- ]
95
- },
96
- {
97
- description: "Binary (yes/no) confirmation",
98
- parameters: [
99
- {
100
- name: "questions",
101
- value: {
86
+ },
87
+ {
88
+ description: "Binary (yes/no) confirmation",
89
+ input: {
90
+ questions: {
102
91
  prompt: "Is it acceptable to refactor existing tests to improve performance?",
103
92
  options: ["Yes", "No"]
104
93
  }
105
94
  }
106
- ]
107
- }
108
- ],
95
+ }
96
+ ]
97
+ }),
109
98
  permissionLevel: 0 /* None */
110
99
  };
111
100
  var handler = async (provider, args) => {
@@ -124,9 +113,9 @@ var handler = async (provider, args) => {
124
113
  }
125
114
  const answers = [];
126
115
  for (const question of questions) {
127
- const { prompt: prompt5, options } = question;
128
- const answer = await provider.askFollowupQuestion(prompt5, options);
129
- answers.push(`<ask_followup_question_answer question="${prompt5}">
116
+ const { prompt: prompt6, options } = question;
117
+ const answer = await provider.askFollowupQuestion(prompt6, options);
118
+ answers.push(`<ask_followup_question_answer question="${prompt6}">
130
119
  ${answer}
131
120
  </ask_followup_question_answer>`);
132
121
  }
@@ -153,18 +142,16 @@ var toolInfo2 = {
153
142
  result: z2.string().describe(
154
143
  "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."
155
144
  ).meta({ usageValue: "Your final result description here" })
156
- }),
157
- examples: [
158
- {
159
- description: "Request to present the result of the task",
160
- parameters: [
161
- {
162
- name: "result",
163
- value: "Your final result description here"
145
+ }).meta({
146
+ examples: [
147
+ {
148
+ description: "Request to present the result of the task",
149
+ input: {
150
+ result: "Your final result description here"
164
151
  }
165
- ]
166
- }
167
- ],
152
+ }
153
+ ]
154
+ }),
168
155
  permissionLevel: 0 /* None */
169
156
  };
170
157
  var handler2 = async (provider, args) => {
@@ -211,30 +198,19 @@ var toolInfo3 = {
211
198
  const values = Array.isArray(val) ? val : [val];
212
199
  return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
213
200
  }, z3.array(z3.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
214
- }),
215
- examples: [
216
- {
217
- description: "Delegate a code analysis task to the analyzer agent",
218
- parameters: [
219
- {
220
- name: "agentName",
221
- value: "analyzer"
222
- },
223
- {
224
- name: "task",
225
- value: "Analyze the authentication implementation"
226
- },
227
- {
228
- name: "context",
229
- value: "Need to understand the security implications of the current auth system"
230
- },
231
- {
232
- name: "files",
233
- value: "src/auth/login.ts,src/auth/types.ts"
201
+ }).meta({
202
+ examples: [
203
+ {
204
+ description: "Delegate a code analysis task to the analyzer agent",
205
+ input: {
206
+ agentName: "analyzer",
207
+ task: "Analyze the authentication implementation",
208
+ context: "Need to understand the security implications of the current auth system",
209
+ files: "src/auth/login.ts,src/auth/types.ts"
234
210
  }
235
- ]
236
- }
237
- ],
211
+ }
212
+ ]
213
+ }),
238
214
  permissionLevel: 0 /* None */
239
215
  };
240
216
  var handler3 = async (_provider, args) => {
@@ -280,16 +256,17 @@ var toolInfo4 = {
280
256
  }, z4.boolean().optional().default(false)).describe(
281
257
  "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests)."
282
258
  ).meta({ usageValue: "true | false" })
259
+ }).meta({
260
+ examples: [
261
+ {
262
+ description: "Make a build",
263
+ input: {
264
+ command: "npm run build",
265
+ requiresApproval: "false"
266
+ }
267
+ }
268
+ ]
283
269
  }),
284
- examples: [
285
- {
286
- description: "Make a build",
287
- parameters: [
288
- { name: "command", value: "npm run build" },
289
- { name: "requiresApproval", value: "false" }
290
- ]
291
- }
292
- ],
293
270
  permissionLevel: 3 /* Arbitrary */
294
271
  };
295
272
  var handler4 = async (provider, args) => {
@@ -348,36 +325,28 @@ var toolInfo5 = {
348
325
  const values = Array.isArray(val) ? val : [val];
349
326
  return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
350
327
  }, z5.array(z5.string())).describe("One or more URLs to fetch, separated by commas if multiple.").meta({ usageValue: "url" })
351
- }),
352
- examples: [
353
- {
354
- description: "Fetch a single webpage",
355
- parameters: [
356
- {
357
- name: "url",
358
- value: "https://example.com"
328
+ }).meta({
329
+ examples: [
330
+ {
331
+ description: "Fetch a single webpage",
332
+ input: {
333
+ url: "https://example.com"
359
334
  }
360
- ]
361
- },
362
- {
363
- description: "Fetch multiple webpages",
364
- parameters: [
365
- {
366
- name: "url",
367
- value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
335
+ },
336
+ {
337
+ description: "Fetch multiple webpages",
338
+ input: {
339
+ url: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
368
340
  }
369
- ]
370
- },
371
- {
372
- description: "Fetch a raw file from GitHub",
373
- parameters: [
374
- {
375
- name: "url",
376
- value: "https://raw.githubusercontent.com/user/repo/main/README.md"
341
+ },
342
+ {
343
+ description: "Fetch a raw file from GitHub",
344
+ input: {
345
+ url: "https://raw.githubusercontent.com/user/repo/main/README.md"
377
346
  }
378
- ]
379
- }
380
- ],
347
+ }
348
+ ]
349
+ }),
381
350
  permissionLevel: 1 /* Read */
382
351
  };
383
352
  var handler5 = async (provider, args) => {
@@ -433,30 +402,19 @@ var toolInfo6 = {
433
402
  const values = Array.isArray(val) ? val : [val];
434
403
  return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
435
404
  }, z6.array(z6.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
436
- }),
437
- examples: [
438
- {
439
- description: "Hand over a coding task to the coder agent",
440
- parameters: [
441
- {
442
- name: "agentName",
443
- value: "coder"
444
- },
445
- {
446
- name: "task",
447
- value: "Implement the login feature"
448
- },
449
- {
450
- name: "context",
451
- value: "We need a secure login system with email and password"
452
- },
453
- {
454
- name: "files",
455
- value: "src/auth/login.ts,src/auth/types.ts"
405
+ }).meta({
406
+ examples: [
407
+ {
408
+ description: "Hand over a coding task to the coder agent",
409
+ input: {
410
+ agentName: "coder",
411
+ task: "Implement the login feature",
412
+ context: "We need a secure login system with email and password",
413
+ files: "src/auth/login.ts,src/auth/types.ts"
456
414
  }
457
- ]
458
- }
459
- ],
415
+ }
416
+ ]
417
+ }),
460
418
  permissionLevel: 0 /* None */
461
419
  };
462
420
  var handler6 = async (_provider, args) => {
@@ -501,22 +459,17 @@ var toolInfo7 = {
501
459
  }
502
460
  return val;
503
461
  }, z7.boolean().optional().default(true)).describe("Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.").meta({ usageValue: "true or false (optional)" })
504
- }),
505
- examples: [
506
- {
507
- description: "Request to list files",
508
- parameters: [
509
- {
510
- name: "path",
511
- value: "src"
512
- },
513
- {
514
- name: "maxCount",
515
- value: "100"
462
+ }).meta({
463
+ examples: [
464
+ {
465
+ description: "Request to list files",
466
+ input: {
467
+ path: "src",
468
+ maxCount: "100"
516
469
  }
517
- ]
518
- }
519
- ],
470
+ }
471
+ ]
472
+ }),
520
473
  permissionLevel: 1 /* Read */
521
474
  };
522
475
  var handler7 = async (provider, args) => {
@@ -557,27 +510,22 @@ var toolInfo8 = {
557
510
  const values = Array.isArray(val) ? val : [val];
558
511
  return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
559
512
  }, z8.array(z8.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" })
560
- }),
561
- examples: [
562
- {
563
- description: "Request to read the contents of a file",
564
- parameters: [
565
- {
566
- name: "path",
567
- value: "src/main.js"
513
+ }).meta({
514
+ examples: [
515
+ {
516
+ description: "Request to read the contents of a file",
517
+ input: {
518
+ path: "src/main.js"
568
519
  }
569
- ]
570
- },
571
- {
572
- description: "Request to read multiple files",
573
- parameters: [
574
- {
575
- name: "path",
576
- value: "src/main.js,src/index.js"
520
+ },
521
+ {
522
+ description: "Request to read multiple files",
523
+ input: {
524
+ path: "src/main.js,src/index.js"
577
525
  }
578
- ]
579
- }
580
- ],
526
+ }
527
+ ]
528
+ }),
581
529
  permissionLevel: 1 /* Read */
582
530
  };
583
531
  var handler8 = async (provider, args) => {
@@ -623,18 +571,16 @@ var toolInfo9 = {
623
571
  description: "Request to remove a file at the specified path.",
624
572
  parameters: z9.object({
625
573
  path: z9.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
626
- }),
627
- examples: [
628
- {
629
- description: "Request to remove a file",
630
- parameters: [
631
- {
632
- name: "path",
633
- value: "src/main.js"
574
+ }).meta({
575
+ examples: [
576
+ {
577
+ description: "Request to remove a file",
578
+ input: {
579
+ path: "src/main.js"
634
580
  }
635
- ]
636
- }
637
- ],
581
+ }
582
+ ]
583
+ }),
638
584
  permissionLevel: 2 /* Write */
639
585
  };
640
586
  var handler9 = async (provider, args) => {
@@ -675,22 +621,17 @@ var toolInfo10 = {
675
621
  parameters: z10.object({
676
622
  source_path: z10.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
677
623
  target_path: z10.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
678
- }),
679
- examples: [
680
- {
681
- description: "Request to rename a file",
682
- parameters: [
683
- {
684
- name: "source_path",
685
- value: "src/old-name.js"
686
- },
687
- {
688
- name: "target_path",
689
- value: "src/new-name.js"
624
+ }).meta({
625
+ examples: [
626
+ {
627
+ description: "Request to rename a file",
628
+ input: {
629
+ source_path: "src/old-name.js",
630
+ target_path: "src/new-name.js"
690
631
  }
691
- ]
692
- }
693
- ],
632
+ }
633
+ ]
634
+ }),
694
635
  permissionLevel: 2 /* Write */
695
636
  };
696
637
  var handler10 = async (provider, args) => {
@@ -825,18 +766,13 @@ Critical rules:
825
766
  * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
826
767
  * To delete code: Use empty REPLACE section`
827
768
  ).meta({ usageValue: "Search and replace blocks here" })
828
- }),
829
- examples: [
830
- {
831
- description: "Request to replace sections of content in a file",
832
- parameters: [
833
- {
834
- name: "path",
835
- value: "src/main.js"
836
- },
837
- {
838
- name: "diff",
839
- value: `<<<<<<< SEARCH
769
+ }).meta({
770
+ examples: [
771
+ {
772
+ description: "Request to replace sections of content in a file",
773
+ input: {
774
+ path: "src/main.js",
775
+ diff: `<<<<<<< SEARCH
840
776
  import React from 'react';
841
777
  =======
842
778
  import React, { useState } from 'react';
@@ -864,35 +800,23 @@ return (
864
800
  <div>
865
801
  >>>>>>> REPLACE`
866
802
  }
867
- ]
868
- },
869
- {
870
- description: "Request to perform a simple, single-line replacement",
871
- parameters: [
872
- {
873
- name: "path",
874
- value: "src/config.js"
875
- },
876
- {
877
- name: "diff",
878
- value: `<<<<<<< SEARCH
803
+ },
804
+ {
805
+ description: "Request to perform a simple, single-line replacement",
806
+ input: {
807
+ path: "src/config.js",
808
+ diff: `<<<<<<< SEARCH
879
809
  const API_URL = 'https://api.example.com';
880
810
  =======
881
811
  const API_URL = 'https://api.staging.example.com';
882
812
  >>>>>>> REPLACE`
883
813
  }
884
- ]
885
- },
886
- {
887
- description: "Request to add a new function to a file",
888
- parameters: [
889
- {
890
- name: "path",
891
- value: "src/utils.js"
892
- },
893
- {
894
- name: "diff",
895
- value: `<<<<<<< SEARCH
814
+ },
815
+ {
816
+ description: "Request to add a new function to a file",
817
+ input: {
818
+ path: "src/utils.js",
819
+ diff: `<<<<<<< SEARCH
896
820
  function helperA() {
897
821
  // ...
898
822
  }
@@ -906,18 +830,12 @@ function newHelper() {
906
830
  }
907
831
  >>>>>>> REPLACE`
908
832
  }
909
- ]
910
- },
911
- {
912
- description: "Request to delete a block of code from a file",
913
- parameters: [
914
- {
915
- name: "path",
916
- value: "src/app.js"
917
- },
918
- {
919
- name: "diff",
920
- value: `<<<<<<< SEARCH
833
+ },
834
+ {
835
+ description: "Request to delete a block of code from a file",
836
+ input: {
837
+ path: "src/app.js",
838
+ diff: `<<<<<<< SEARCH
921
839
  function oldFeature() {
922
840
  // This is no longer needed
923
841
  }
@@ -925,9 +843,9 @@ function oldFeature() {
925
843
  =======
926
844
  >>>>>>> REPLACE`
927
845
  }
928
- ]
929
- }
930
- ],
846
+ }
847
+ ]
848
+ }),
931
849
  permissionLevel: 2 /* Write */
932
850
  };
933
851
  var handler11 = async (provider, args) => {
@@ -1001,26 +919,18 @@ var toolInfo12 = {
1001
919
  ).meta({
1002
920
  usageValue: "file pattern here (optional)"
1003
921
  })
1004
- }),
1005
- examples: [
1006
- {
1007
- description: "Request to perform a regex search across files",
1008
- parameters: [
1009
- {
1010
- name: "path",
1011
- value: "src"
1012
- },
1013
- {
1014
- name: "regex",
1015
- value: "^components/"
1016
- },
1017
- {
1018
- name: "filePattern",
1019
- value: "*.ts,*.tsx"
922
+ }).meta({
923
+ examples: [
924
+ {
925
+ description: "Request to perform a regex search across files",
926
+ input: {
927
+ path: "src",
928
+ regex: "^components/",
929
+ filePattern: "*.ts,*.tsx"
1020
930
  }
1021
- ]
1022
- }
1023
- ],
931
+ }
932
+ ]
933
+ }),
1024
934
  permissionLevel: 1 /* Read */
1025
935
  };
1026
936
  var handler12 = async (provider, args) => {
@@ -1069,18 +979,13 @@ var toolInfo13 = {
1069
979
  content: z13.string().describe(
1070
980
  "The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified."
1071
981
  ).meta({ usageValue: "Your file content here" })
1072
- }),
1073
- examples: [
1074
- {
1075
- description: "Request to write content to a file",
1076
- parameters: [
1077
- {
1078
- name: "path",
1079
- value: "src/main.js"
1080
- },
1081
- {
1082
- name: "content",
1083
- value: `import React from 'react';
982
+ }).meta({
983
+ examples: [
984
+ {
985
+ description: "Request to write content to a file",
986
+ input: {
987
+ path: "src/main.js",
988
+ content: `import React from 'react';
1084
989
 
1085
990
  function App() {
1086
991
  return (
@@ -1093,9 +998,9 @@ function App() {
1093
998
  export default App;
1094
999
  `
1095
1000
  }
1096
- ]
1097
- }
1098
- ],
1001
+ }
1002
+ ]
1003
+ }),
1099
1004
  permissionLevel: 2 /* Write */
1100
1005
  };
1101
1006
  var handler13 = async (provider, args) => {
@@ -1186,46 +1091,6 @@ var getAvailableTools = ({
1186
1091
  return tools;
1187
1092
  };
1188
1093
 
1189
- // src/tool-v1-compat.ts
1190
- import { z as z14 } from "zod";
1191
- function zodSchemaToParameters(schema) {
1192
- const parameters = [];
1193
- const { shape } = schema;
1194
- for (const name in shape) {
1195
- const def = shape[name];
1196
- const isOptional = def.safeParse(void 0).success;
1197
- const description = def.description || "";
1198
- const param = {
1199
- name,
1200
- description,
1201
- required: !isOptional
1202
- };
1203
- const usageValue = def.meta()?.usageValue;
1204
- if (usageValue) {
1205
- param.usageValue = usageValue;
1206
- }
1207
- if (def instanceof z14.ZodObject) {
1208
- param.children = zodSchemaToParameters(def);
1209
- } else if (def instanceof z14.ZodArray) {
1210
- param.allowMultiple = true;
1211
- const element = def.element;
1212
- if (element instanceof z14.ZodObject) {
1213
- param.children = zodSchemaToParameters(element);
1214
- }
1215
- }
1216
- parameters.push(param);
1217
- }
1218
- return parameters;
1219
- }
1220
- function toToolInfoV1(tool) {
1221
- const { parameters: zodSchema, ...rest } = tool;
1222
- const v1Parameters = zodSchemaToParameters(zodSchema);
1223
- return {
1224
- ...rest,
1225
- parameters: v1Parameters
1226
- };
1227
- }
1228
-
1229
1094
  // src/UsageMeter.ts
1230
1095
  var UsageMeter = class {
1231
1096
  #totals = { input: 0, output: 0, cachedRead: 0, cost: 0 };
@@ -1371,7 +1236,54 @@ var UsageMeter = class {
1371
1236
  };
1372
1237
 
1373
1238
  // src/Agent/AgentBase.ts
1374
- import { streamText } from "ai";
1239
+ import { jsonSchema, streamText } from "ai";
1240
+ import { camelCase } from "lodash";
1241
+ import { toJSONSchema } from "zod";
1242
+
1243
+ // src/tool-v1-compat.ts
1244
+ import { z as z14 } from "zod";
1245
+ function zodSchemaToParameters(schema) {
1246
+ const parameters = [];
1247
+ const { shape } = schema;
1248
+ for (const name in shape) {
1249
+ const def = shape[name];
1250
+ const isOptional = def.safeParse(void 0).success;
1251
+ const description = def.description || "";
1252
+ const param = {
1253
+ name,
1254
+ description,
1255
+ required: !isOptional
1256
+ };
1257
+ const usageValue = def.meta()?.usageValue;
1258
+ if (usageValue) {
1259
+ param.usageValue = usageValue;
1260
+ }
1261
+ if (def instanceof z14.ZodObject) {
1262
+ param.children = zodSchemaToParameters(def);
1263
+ } else if (def instanceof z14.ZodArray) {
1264
+ param.allowMultiple = true;
1265
+ const element = def.element;
1266
+ if (element instanceof z14.ZodObject) {
1267
+ param.children = zodSchemaToParameters(element);
1268
+ }
1269
+ }
1270
+ parameters.push(param);
1271
+ }
1272
+ return parameters;
1273
+ }
1274
+ function toToolInfoV1(tool) {
1275
+ const { parameters: zodSchema, ...rest } = tool;
1276
+ const v1Parameters = zodSchemaToParameters(zodSchema);
1277
+ const examples = zodSchema.meta()?.examples;
1278
+ const v1Tool = {
1279
+ ...rest,
1280
+ parameters: v1Parameters
1281
+ };
1282
+ if (examples) {
1283
+ v1Tool.examples = examples;
1284
+ }
1285
+ return v1Tool;
1286
+ }
1375
1287
 
1376
1288
  // src/Agent/parseAssistantMessage.ts
1377
1289
  function parseNestedParameters(content, parameterPrefix, childrenParams) {
@@ -1543,7 +1455,7 @@ var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) =>
1543
1455
  ## Example: ${example.description}
1544
1456
 
1545
1457
  <${toolNamePrefix}${tool.name}>
1546
- ${example.parameters.map((param) => `${renderParameterValue(param.name, param.value, parameterPrefix)}`).join("\n")}
1458
+ ${Object.entries(example.input).map(([name, value]) => renderParameterValue(name, value, parameterPrefix)).join("\n")}
1547
1459
  </${toolNamePrefix}${tool.name}>
1548
1460
  `;
1549
1461
  var toolUsePrompt = (tools, toolNamePrefix) => {
@@ -1551,6 +1463,7 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
1551
1463
  return "";
1552
1464
  }
1553
1465
  const parameterPrefix = `${toolNamePrefix}parameter_`;
1466
+ const v1Tools = tools.map(toToolInfoV1);
1554
1467
  return `
1555
1468
  ====
1556
1469
 
@@ -1609,10 +1522,10 @@ Always adhere to this format, ensuring every opening tag has a matching closing
1609
1522
  NEVER surround tool use with triple backticks (\`\`\`).
1610
1523
 
1611
1524
  # Tools
1612
- ${tools.map((tool) => toolInfoPrompt(tool, toolNamePrefix, parameterPrefix)).join("\n")}
1525
+ ${v1Tools.map((tool) => toolInfoPrompt(tool, toolNamePrefix, parameterPrefix)).join("\n")}
1613
1526
 
1614
1527
  # Tool Use Examples
1615
- ${tools.map((tool) => {
1528
+ ${v1Tools.map((tool) => {
1616
1529
  let promp = "";
1617
1530
  for (const example of tool.examples ?? []) {
1618
1531
  promp += toolInfoExamplesPrompt(tool, example, toolNamePrefix, parameterPrefix);
@@ -1703,6 +1616,8 @@ e.g. <tool_tool_name>tool_name</tool_tool_name>
1703
1616
  Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
1704
1617
  Avoid unnecessary text or symbols before or after the tool use.
1705
1618
  Avoid unnecessary escape characters or special characters.
1619
+ `,
1620
+ requireUseToolNative: `Error: No tool use detected. You MUST use a tool before proceeding.
1706
1621
  `,
1707
1622
  toolResults: (tool, result) => {
1708
1623
  if (typeof result === "string") {
@@ -1760,6 +1675,7 @@ var AgentBase = class {
1760
1675
  config;
1761
1676
  handlers;
1762
1677
  #policies;
1678
+ #toolSet;
1763
1679
  #messages = [];
1764
1680
  #aborted = false;
1765
1681
  #abortController;
@@ -1797,6 +1713,20 @@ ${instance.prompt}`;
1797
1713
  role: "system",
1798
1714
  content: this.config.systemPrompt
1799
1715
  });
1716
+ if (this.config.toolFormat === "native") {
1717
+ const tools = {};
1718
+ for (const tool of Object.values(this.handlers)) {
1719
+ const toolName = camelCase(tool.name);
1720
+ tools[toolName] = {
1721
+ description: tool.description,
1722
+ inputSchema: jsonSchema(toJSONSchema(tool.parameters))
1723
+ };
1724
+ this.handlers[toolName] = tool;
1725
+ }
1726
+ this.#toolSet = tools;
1727
+ } else {
1728
+ this.#toolSet = {};
1729
+ }
1800
1730
  }
1801
1731
  abort() {
1802
1732
  this.#aborted = true;
@@ -1816,21 +1746,27 @@ ${instance.prompt}`;
1816
1746
  async #callback(event) {
1817
1747
  await this.config.callback?.(event);
1818
1748
  }
1819
- async start(prompt5) {
1749
+ async start(prompt6) {
1820
1750
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
1821
- return await this.#processLoop(prompt5);
1751
+ return await this.#processLoop(prompt6);
1822
1752
  }
1823
- async step(prompt5) {
1753
+ async step(prompt6) {
1824
1754
  if (this.#messages.length === 0) {
1825
1755
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
1826
1756
  }
1827
- return await this.#request(prompt5);
1757
+ return await this.#request({
1758
+ role: "user",
1759
+ content: prompt6
1760
+ });
1828
1761
  }
1829
1762
  async handleStepResponse(response) {
1830
1763
  return this.#handleResponse(response);
1831
1764
  }
1832
1765
  async #processLoop(userMessage) {
1833
- let nextRequest = userMessage;
1766
+ let nextRequest = {
1767
+ role: "user",
1768
+ content: userMessage
1769
+ };
1834
1770
  while (true) {
1835
1771
  if (this.#aborted) {
1836
1772
  return { type: "Aborted" };
@@ -1859,10 +1795,7 @@ ${instance.prompt}`;
1859
1795
  throw new Error("userMessage is missing");
1860
1796
  }
1861
1797
  await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
1862
- this.#messages.push({
1863
- role: "user",
1864
- content: userMessage
1865
- });
1798
+ this.#messages.push(userMessage);
1866
1799
  for (const instance of this.#policies) {
1867
1800
  if (instance.onBeforeRequest) {
1868
1801
  await instance.onBeforeRequest(this);
@@ -1874,11 +1807,11 @@ ${instance.prompt}`;
1874
1807
  messages = await instance.prepareMessages(this, messages);
1875
1808
  }
1876
1809
  }
1877
- let currentAssistantMessage = "";
1878
1810
  const retryCount = this.config.retryCount ?? 5;
1879
- const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 10;
1811
+ const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 90;
1812
+ let respMessages = [];
1880
1813
  for (let i = 0; i < retryCount; i++) {
1881
- currentAssistantMessage = "";
1814
+ respMessages = [];
1882
1815
  let timeout;
1883
1816
  const resetTimeout = () => {
1884
1817
  if (timeout) {
@@ -1892,40 +1825,22 @@ ${instance.prompt}`;
1892
1825
  }
1893
1826
  };
1894
1827
  this.#abortController = new AbortController();
1895
- const providerOptions = {};
1896
- const thinkingBudgetTokens = this.config.parameters?.thinkingBudgetTokens;
1897
- const enableThinking = thinkingBudgetTokens > 0;
1898
- if (enableThinking) {
1899
- providerOptions.anthropic = {
1900
- thinking: { type: "enabled", budgetTokens: thinkingBudgetTokens }
1901
- };
1902
- providerOptions.openrouter = {
1903
- reasoning: {
1904
- max_tokens: thinkingBudgetTokens
1905
- }
1906
- };
1907
- providerOptions.google = {
1908
- thinkingConfig: {
1909
- includeThoughts: true,
1910
- thinkingBudget: thinkingBudgetTokens
1911
- }
1912
- };
1913
- }
1914
1828
  try {
1915
- const stream = streamText({
1829
+ const streamTextOptions = {
1916
1830
  model: this.ai,
1917
1831
  messages,
1918
- providerOptions,
1832
+ providerOptions: this.config.parameters?.providerOptions,
1919
1833
  onChunk: async ({ chunk }) => {
1920
1834
  resetTimeout();
1921
1835
  switch (chunk.type) {
1922
1836
  case "text":
1923
- currentAssistantMessage += chunk.text;
1924
1837
  await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
1925
1838
  break;
1926
1839
  case "reasoning":
1927
1840
  await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
1928
1841
  break;
1842
+ case "tool-call":
1843
+ break;
1929
1844
  }
1930
1845
  },
1931
1846
  onFinish: this.config.usageMeter.onFinishHandler(this.ai),
@@ -1933,8 +1848,18 @@ ${instance.prompt}`;
1933
1848
  console.error("Error in stream:", error);
1934
1849
  },
1935
1850
  abortSignal: this.#abortController.signal
1851
+ };
1852
+ if (this.config.toolFormat === "native") {
1853
+ streamTextOptions.tools = this.#toolSet;
1854
+ }
1855
+ const stream = streamText(streamTextOptions);
1856
+ await stream.consumeStream({
1857
+ onError: (error) => {
1858
+ console.error("Error in stream:", error);
1859
+ }
1936
1860
  });
1937
- await stream.consumeStream();
1861
+ const resp = await stream.response;
1862
+ respMessages = resp.messages;
1938
1863
  } catch (error) {
1939
1864
  if (error instanceof Error && error.name === "AbortError") {
1940
1865
  break;
@@ -1945,7 +1870,7 @@ ${instance.prompt}`;
1945
1870
  clearTimeout(timeout);
1946
1871
  }
1947
1872
  }
1948
- if (currentAssistantMessage) {
1873
+ if (respMessages.length > 0) {
1949
1874
  break;
1950
1875
  }
1951
1876
  if (this.#aborted) {
@@ -1953,17 +1878,44 @@ ${instance.prompt}`;
1953
1878
  }
1954
1879
  console.debug(`Retrying request ${i + 1} of ${retryCount}`);
1955
1880
  }
1956
- if (!currentAssistantMessage) {
1881
+ if (respMessages.length === 0) {
1957
1882
  if (this.#aborted) {
1958
1883
  return [];
1959
1884
  }
1960
1885
  throw new Error("No assistant message received");
1961
1886
  }
1962
- console.log("Assistant message:", currentAssistantMessage);
1963
- this.#messages.push({
1964
- role: "assistant",
1965
- content: currentAssistantMessage
1966
- });
1887
+ this.#messages.push(...respMessages);
1888
+ if (this.config.toolFormat === "native") {
1889
+ return respMessages.flatMap((msg) => {
1890
+ if (msg.role === "assistant") {
1891
+ const content = msg.content;
1892
+ if (typeof content === "string") {
1893
+ return [{ type: "text", content }];
1894
+ }
1895
+ return content.flatMap((part) => {
1896
+ if (part.type === "text") {
1897
+ return [{ type: "text", content: part.text }];
1898
+ }
1899
+ if (part.type === "tool-call") {
1900
+ return [{ type: "tool_use", id: part.toolCallId, name: part.toolName, params: part.input }];
1901
+ }
1902
+ return [];
1903
+ });
1904
+ }
1905
+ return [];
1906
+ });
1907
+ }
1908
+ const currentAssistantMessage = respMessages.map((msg) => {
1909
+ if (typeof msg.content === "string") {
1910
+ return msg.content;
1911
+ }
1912
+ return msg.content.map((part) => {
1913
+ if (part.type === "text") {
1914
+ return part.text;
1915
+ }
1916
+ return "";
1917
+ });
1918
+ }).join("\n");
1967
1919
  const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools.map(toToolInfoV1), this.config.toolNamePrefix);
1968
1920
  await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: currentAssistantMessage });
1969
1921
  return ret;
@@ -1976,12 +1928,12 @@ ${instance.prompt}`;
1976
1928
  case "text":
1977
1929
  break;
1978
1930
  case "tool_use": {
1979
- await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
1931
+ await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, content: content.params });
1980
1932
  const toolResp = await this.#invokeTool(content.name, content.params);
1981
1933
  switch (toolResp.type) {
1982
1934
  case "Reply" /* Reply */: {
1983
- await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
1984
- toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
1935
+ await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name, content: toolResp.message });
1936
+ toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
1985
1937
  break;
1986
1938
  }
1987
1939
  case "Exit" /* Exit */:
@@ -1990,17 +1942,17 @@ ${instance.prompt}`;
1990
1942
  }
1991
1943
  return { type: "exit", reason: toolResp };
1992
1944
  case "Invalid" /* Invalid */: {
1993
- await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
1994
- toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
1945
+ await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
1946
+ toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
1995
1947
  break outer;
1996
1948
  }
1997
1949
  case "Error" /* Error */: {
1998
- await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
1999
- toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
1950
+ await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
1951
+ toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
2000
1952
  break outer;
2001
1953
  }
2002
1954
  case "Interrupted" /* Interrupted */:
2003
- await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
1955
+ await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name, content: toolResp.message });
2004
1956
  return { type: "exit", reason: toolResp };
2005
1957
  case "HandOver" /* HandOver */: {
2006
1958
  if (toolResponses.length > 0) {
@@ -2034,7 +1986,7 @@ ${instance.prompt}`;
2034
1986
  }
2035
1987
  case "Pause" /* Pause */: {
2036
1988
  await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
2037
- toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object });
1989
+ toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object, id: content.id });
2038
1990
  hasPause = true;
2039
1991
  }
2040
1992
  }
@@ -2046,15 +1998,56 @@ ${instance.prompt}`;
2046
1998
  return { type: "exit", reason: { type: "Pause", responses: toolResponses } };
2047
1999
  }
2048
2000
  if (toolResponses.length === 0) {
2049
- return { type: "reply", message: responsePrompts.requireUseTool };
2001
+ return {
2002
+ type: "reply",
2003
+ message: {
2004
+ role: "user",
2005
+ content: responsePrompts.requireUseToolNative
2006
+ }
2007
+ };
2008
+ }
2009
+ if (this.config.toolFormat === "native") {
2010
+ const toolResults = toolResponses.filter((resp) => resp.type === "response").map(
2011
+ (resp) => ({
2012
+ type: "tool-result",
2013
+ toolCallId: resp.id,
2014
+ toolName: resp.tool,
2015
+ output: {
2016
+ type: "text",
2017
+ value: resp.response
2018
+ }
2019
+ })
2020
+ );
2021
+ return {
2022
+ type: "reply",
2023
+ message: {
2024
+ role: "tool",
2025
+ content: toolResults
2026
+ }
2027
+ };
2028
+ }
2029
+ if (toolResponses.length === 0) {
2030
+ return {
2031
+ type: "reply",
2032
+ message: {
2033
+ role: "user",
2034
+ content: responsePrompts.requireUseTool
2035
+ }
2036
+ };
2050
2037
  }
2051
2038
  const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2));
2052
- return { type: "reply", message: finalResp };
2039
+ return {
2040
+ type: "reply",
2041
+ message: {
2042
+ role: "user",
2043
+ content: finalResp
2044
+ }
2045
+ };
2053
2046
  }
2054
2047
  async #invokeTool(name, args) {
2055
2048
  try {
2056
- const handler14 = this.handlers[name]?.handler;
2057
- if (!handler14) {
2049
+ const handler15 = this.handlers[name]?.handler;
2050
+ if (!handler15) {
2058
2051
  return {
2059
2052
  type: "Error" /* Error */,
2060
2053
  message: responsePrompts.errorInvokeTool(name, "Tool not found"),
@@ -2073,7 +2066,7 @@ ${instance.prompt}`;
2073
2066
  if (resp) {
2074
2067
  return resp;
2075
2068
  }
2076
- return await handler14(this.config.provider, args);
2069
+ return await handler15(this.config.provider, args);
2077
2070
  } catch (error) {
2078
2071
  return {
2079
2072
  type: "Error" /* Error */,
@@ -2130,12 +2123,12 @@ var AnalyzerAgent = class extends AgentBase {
2130
2123
  permissionLevel: 1 /* Read */,
2131
2124
  interactive: true
2132
2125
  });
2133
- const toolNamePrefix = "tool_";
2126
+ const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
2134
2127
  const systemPrompt = fullSystemPrompt(
2135
2128
  {
2136
2129
  os: options.os
2137
2130
  },
2138
- tools.map(toToolInfoV1),
2131
+ tools,
2139
2132
  toolNamePrefix,
2140
2133
  options.customInstructions ?? [],
2141
2134
  options.scripts ?? {},
@@ -2226,12 +2219,12 @@ var ArchitectAgent = class extends AgentBase {
2226
2219
  permissionLevel: 1 /* Read */,
2227
2220
  interactive: true
2228
2221
  });
2229
- const toolNamePrefix = "tool_";
2222
+ const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
2230
2223
  const systemPrompt = fullSystemPrompt2(
2231
2224
  {
2232
2225
  os: options.os
2233
2226
  },
2234
- tools.map(toToolInfoV1),
2227
+ tools,
2235
2228
  toolNamePrefix,
2236
2229
  options.customInstructions ?? [],
2237
2230
  options.scripts ?? {},
@@ -2355,12 +2348,12 @@ var CodeFixerAgent = class extends AgentBase {
2355
2348
  permissionLevel: 3 /* Arbitrary */,
2356
2349
  interactive: true
2357
2350
  });
2358
- const toolNamePrefix = "tool_";
2351
+ const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
2359
2352
  const systemPrompt = fullSystemPrompt3(
2360
2353
  {
2361
2354
  os: options.os
2362
2355
  },
2363
- tools.map(toToolInfoV1),
2356
+ tools,
2364
2357
  toolNamePrefix,
2365
2358
  options.customInstructions ?? [],
2366
2359
  options.scripts ?? {},
@@ -2561,12 +2554,12 @@ var CoderAgent = class extends AgentBase {
2561
2554
  permissionLevel: 3 /* Arbitrary */,
2562
2555
  interactive: true
2563
2556
  });
2564
- const toolNamePrefix = "tool_";
2557
+ const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
2565
2558
  const systemPrompt = fullSystemPrompt4(
2566
2559
  {
2567
2560
  os: options.os
2568
2561
  },
2569
- tools.map(toToolInfoV1),
2562
+ tools,
2570
2563
  toolNamePrefix,
2571
2564
  options.customInstructions ?? [],
2572
2565
  options.scripts ?? {},
@@ -2658,24 +2651,24 @@ var MultiAgent = class {
2658
2651
  switch (exitReason.type) {
2659
2652
  case "HandOver" /* HandOver */: {
2660
2653
  this.#agents.pop();
2661
- const prompt5 = await this.#config.getPrompt?.(
2654
+ const prompt6 = await this.#config.getPrompt?.(
2662
2655
  exitReason.agentName,
2663
2656
  exitReason.task,
2664
2657
  exitReason.context,
2665
2658
  exitReason.files,
2666
2659
  this.#originalTask
2667
2660
  ) ?? exitReason.task;
2668
- return await this.#startTask(exitReason.agentName, prompt5);
2661
+ return await this.#startTask(exitReason.agentName, prompt6);
2669
2662
  }
2670
2663
  case "Delegate" /* Delegate */: {
2671
- const prompt5 = await this.#config.getPrompt?.(
2664
+ const prompt6 = await this.#config.getPrompt?.(
2672
2665
  exitReason.agentName,
2673
2666
  exitReason.task,
2674
2667
  exitReason.context,
2675
2668
  exitReason.files,
2676
2669
  this.#originalTask
2677
2670
  ) ?? exitReason.task;
2678
- const delegateResult = await this.#startTask(exitReason.agentName, prompt5);
2671
+ const delegateResult = await this.#startTask(exitReason.agentName, prompt6);
2679
2672
  switch (delegateResult.type) {
2680
2673
  case "HandOver" /* HandOver */:
2681
2674
  case "Delegate" /* Delegate */:
@@ -3014,23 +3007,23 @@ var prompt = `You are an AiTool designed to assist users in creating new project
3014
3007
  - Create a .gitattributes file with appropriate configurations:
3015
3008
  - Mark lock files as generated and exclude them from diffs
3016
3009
  - Example for different package managers:
3017
-
3010
+
3018
3011
  # For Bun
3019
3012
  bun.lock linguist-generated=true
3020
3013
  bun.lock -diff
3021
-
3014
+
3022
3015
  # For npm
3023
3016
  package-lock.json linguist-generated=true
3024
3017
  package-lock.json -diff
3025
-
3018
+
3026
3019
  # For Yarn
3027
3020
  yarn.lock linguist-generated=true
3028
3021
  yarn.lock -diff
3029
-
3022
+
3030
3023
  # For pnpm
3031
3024
  pnpm-lock.yaml linguist-generated=true
3032
3025
  pnpm-lock.yaml -diff
3033
-
3026
+
3034
3027
  - Include other common configurations as needed based on project type
3035
3028
 
3036
3029
  6. **Handover to Coder Agent:**
@@ -3286,6 +3279,182 @@ var generateProjectConfig_default = {
3286
3279
  agent: "analyzer"
3287
3280
  };
3288
3281
 
3282
+ // src/AiTool/tools/gitDiff.ts
3283
+ import { z as z16 } from "zod";
3284
+ var toolInfo14 = {
3285
+ name: "git_diff",
3286
+ description: "Get the git diff for the current repository. Can be used to get staged changes, unstaged changes, or changes between commits. By default, it returns unstaged changes.",
3287
+ parameters: z16.object({
3288
+ staged: z16.preprocess((val) => {
3289
+ if (typeof val === "string") {
3290
+ const lower = val.toLowerCase();
3291
+ if (lower === "false") return false;
3292
+ if (lower === "true") return true;
3293
+ }
3294
+ return val;
3295
+ }, z16.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
3296
+ commitRange: z16.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
3297
+ file: z16.string().optional().describe("Get the diff for a specific file.")
3298
+ }),
3299
+ permissionLevel: 1 /* Read */
3300
+ };
3301
+ var handler14 = async (provider, args) => {
3302
+ if (!provider.executeCommand) {
3303
+ return {
3304
+ type: "Error" /* Error */,
3305
+ message: "Not possible to execute command. Abort."
3306
+ };
3307
+ }
3308
+ const { staged, file, commitRange } = toolInfo14.parameters.parse(args);
3309
+ const commandParts = ["git", "diff", "--no-color"];
3310
+ if (staged) {
3311
+ commandParts.push("--staged");
3312
+ }
3313
+ if (commitRange) {
3314
+ commandParts.push(commitRange);
3315
+ }
3316
+ if (file) {
3317
+ commandParts.push("--", file);
3318
+ }
3319
+ const command = commandParts.join(" ");
3320
+ try {
3321
+ const result = await provider.executeCommand(command, false);
3322
+ if (result.exitCode === 0) {
3323
+ if (!result.stdout.trim()) {
3324
+ return {
3325
+ type: "Reply" /* Reply */,
3326
+ message: "No diff found."
3327
+ };
3328
+ }
3329
+ return {
3330
+ type: "Reply" /* Reply */,
3331
+ message: `<diff file="${file ?? "all"}">
3332
+ ${result.stdout}
3333
+ </diff>`
3334
+ };
3335
+ }
3336
+ return {
3337
+ type: "Error" /* Error */,
3338
+ message: `\`${command}\` exited with code ${result.exitCode}:
3339
+ ${result.stderr}`
3340
+ };
3341
+ } catch (error) {
3342
+ return {
3343
+ type: "Error" /* Error */,
3344
+ message: error instanceof Error ? error.message : String(error)
3345
+ };
3346
+ }
3347
+ };
3348
+ var isAvailable14 = (provider) => {
3349
+ return !!provider.executeCommand;
3350
+ };
3351
+ var gitDiff_default = {
3352
+ ...toolInfo14,
3353
+ handler: handler14,
3354
+ isAvailable: isAvailable14
3355
+ };
3356
+
3357
+ // src/AiTool/reviewDiff.ts
3358
+ var prompt5 = `
3359
+ # Code Review Prompt
3360
+
3361
+ You are a senior software engineer reviewing code changes.
3362
+
3363
+ ## Viewing Changes
3364
+ - Use **git_diff** to inspect code.
3365
+ - **Pull request**: use the provided commit range.
3366
+ - **Local changes**: diff staged or unstaged files.
3367
+ - If a pull request is present you may receive:
3368
+ - <pr_title>
3369
+ - <pr_description>
3370
+ - <commit_messages>
3371
+ - A <review_instructions> tag tells you the focus of the review.
3372
+
3373
+ ## Focus Areas
3374
+ - Readability and maintainability
3375
+ - Correctness, edge cases, potential bugs
3376
+ - Performance implications
3377
+ - Clarity of intent
3378
+ - Best-practice adherence
3379
+
3380
+ ## Output Format
3381
+ Do **not** include praise or positive feedback. Ignore generated files such as lock files.
3382
+
3383
+ Return your review as a JSON object inside a \`\`\`json block, wrapped like:
3384
+ <tool_attempt_completion>
3385
+ <tool_parameter_result>
3386
+ \`\`\`json
3387
+ {
3388
+ "overview": "Summary of overall concerns.",
3389
+ "specificReviews": [
3390
+ {
3391
+ "file": "path/filename.ext",
3392
+ "lines": "N or N-M",
3393
+ "review": "Describe the issue and actionable fix or improvement."
3394
+ }
3395
+ ]
3396
+ }
3397
+ \`\`\`
3398
+ </tool_parameter_result>
3399
+ </tool_attempt_completion>
3400
+ `;
3401
+ var reviewDiff_default = {
3402
+ name: "reviewDiff",
3403
+ description: "Reviews a git diff",
3404
+ prompt: prompt5,
3405
+ formatInput: (params) => {
3406
+ const parts = [];
3407
+ if (params.pullRequestTitle) {
3408
+ parts.push(`<pr_title>
3409
+ ${params.pullRequestTitle}
3410
+ </pr_title>`);
3411
+ }
3412
+ if (params.pullRequestDescription) {
3413
+ parts.push(`<pr_description>
3414
+ ${params.pullRequestDescription}
3415
+ </pr_description>`);
3416
+ }
3417
+ if (params.commitMessages) {
3418
+ parts.push(`<commit_messages>
3419
+ ${params.commitMessages}
3420
+ </commit_messages>`);
3421
+ }
3422
+ let instructions = "";
3423
+ if (params.commitRange) {
3424
+ instructions = `Review the pull request. Get the diff using the git_diff tool with the commit range '${params.commitRange}'.`;
3425
+ } else if (params.staged) {
3426
+ instructions = "Review the staged changes. Get the diff using the git_diff tool with staged: true.";
3427
+ } else {
3428
+ instructions = "Review the unstaged changes. Get the diff using the git_diff tool.";
3429
+ }
3430
+ parts.push(`<review_instructions>
3431
+ ${instructions}
3432
+ </review_instructions>`);
3433
+ return parts.join("\n");
3434
+ },
3435
+ parseOutput: (output) => {
3436
+ const jsonBlockRegex = /```json\n([\s\S]*?)\n```/;
3437
+ const match = output.match(jsonBlockRegex);
3438
+ const content = match ? match[1] : output;
3439
+ try {
3440
+ return JSON.parse(content);
3441
+ } catch (error) {
3442
+ console.error("Error parsing JSON output:", error);
3443
+ return {
3444
+ overview: `Could not parse review output. Raw output:
3445
+ ${output}`,
3446
+ specificReviews: []
3447
+ };
3448
+ }
3449
+ },
3450
+ agent: (options) => {
3451
+ return new AnalyzerAgent({
3452
+ ...options,
3453
+ additionalTools: [gitDiff_default]
3454
+ });
3455
+ }
3456
+ };
3457
+
3289
3458
  // src/AiTool/index.ts
3290
3459
  var executeTool = async (definition, ai, params, usageMeter) => {
3291
3460
  const resp = await generateText({
@@ -3301,10 +3470,7 @@ var executeTool = async (definition, ai, params, usageMeter) => {
3301
3470
  usageMeter.addUsage(ai, resp);
3302
3471
  return definition.parseOutput(resp.text);
3303
3472
  };
3304
- var executeAgentTool = async (definition, agent, params) => {
3305
- if (!definition.agent) {
3306
- throw new Error("Agent not specified");
3307
- }
3473
+ var executeMultiAgentTool = async (definition, agent, params) => {
3308
3474
  const exitReason = await agent.startTask({
3309
3475
  agentName: definition.agent,
3310
3476
  task: definition.prompt,
@@ -3315,20 +3481,36 @@ var executeAgentTool = async (definition, agent, params) => {
3315
3481
  }
3316
3482
  throw new Error(`Tool execution failed: ${exitReason.type}`);
3317
3483
  };
3484
+ var executeAgentTool = async (definition, options, params) => {
3485
+ const agent = definition.agent(options);
3486
+ const exitReason = await agent.start(`${definition.prompt}
3487
+
3488
+ ${definition.formatInput(params)}`);
3489
+ if (exitReason.type === "Exit" /* Exit */) {
3490
+ return definition.parseOutput(exitReason.message);
3491
+ }
3492
+ throw new Error(`Tool execution failed: ${exitReason.type}`);
3493
+ };
3318
3494
  var makeTool = (definition) => {
3319
3495
  return async (ai, params, usageMeter) => {
3320
3496
  return executeTool(definition, ai, params, usageMeter);
3321
3497
  };
3322
3498
  };
3323
- var makeAgentTool = (definition) => {
3499
+ var makeMultiAgentTool = (definition) => {
3324
3500
  return async (agent, params) => {
3325
- return executeAgentTool(definition, agent, params);
3501
+ return executeMultiAgentTool(definition, agent, params);
3502
+ };
3503
+ };
3504
+ var makeAgentTool = (definition) => {
3505
+ return async (options, params) => {
3506
+ return executeAgentTool(definition, options, params);
3326
3507
  };
3327
3508
  };
3328
3509
  var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
3329
3510
  var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
3330
- var generateProjectConfig = makeAgentTool(generateProjectConfig_default);
3331
- var createNewProject = makeAgentTool(createNewProject_default);
3511
+ var reviewDiff = makeAgentTool(reviewDiff_default);
3512
+ var generateProjectConfig = makeMultiAgentTool(generateProjectConfig_default);
3513
+ var createNewProject = makeMultiAgentTool(createNewProject_default);
3332
3514
  export {
3333
3515
  AgentBase,
3334
3516
  AnalyzerAgent,
@@ -3361,6 +3543,7 @@ export {
3361
3543
  delegate_default as delegate,
3362
3544
  executeAgentTool,
3363
3545
  executeCommand_default as executeCommand,
3546
+ executeMultiAgentTool,
3364
3547
  executeTool,
3365
3548
  fetchUrl_default as fetchUrl,
3366
3549
  generateGitCommitMessage,
@@ -3370,6 +3553,7 @@ export {
3370
3553
  handOver_default as handOver,
3371
3554
  listFiles_default as listFiles,
3372
3555
  makeAgentTool,
3556
+ makeMultiAgentTool,
3373
3557
  makeTool,
3374
3558
  parseAssistantMessage,
3375
3559
  readFile_default as readFile,
@@ -3378,6 +3562,7 @@ export {
3378
3562
  replaceInFile_default as replaceInFile,
3379
3563
  replaceInFile as replaceInFileHelper,
3380
3564
  responsePrompts,
3565
+ reviewDiff,
3381
3566
  searchFiles_default as searchFiles,
3382
3567
  systemInformation,
3383
3568
  toolUsePrompt,