@polka-codes/cli-shared 0.8.17 → 0.8.19

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.
Files changed (2) hide show
  1. package/dist/index.js +230 -287
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -36771,13 +36771,13 @@ __export(exports_allTools, {
36771
36771
  writeToFile: () => writeToFile_default,
36772
36772
  updateKnowledge: () => updateKnowledge_default,
36773
36773
  searchFiles: () => searchFiles_default,
36774
+ replaceInFile: () => replaceInFile_default,
36774
36775
  renameFile: () => renameFile_default,
36775
36776
  removeFile: () => removeFile_default,
36776
36777
  readFile: () => readFile_default,
36777
36778
  listFiles: () => listFiles_default,
36778
36779
  handOver: () => handOver_default,
36779
36780
  executeCommand: () => executeCommand_default,
36780
- editFile: () => editFile_default,
36781
36781
  delegate: () => delegate_default,
36782
36782
  attemptCompletion: () => attemptCompletion_default,
36783
36783
  askFollowupQuestion: () => askFollowupQuestion_default
@@ -36790,78 +36790,31 @@ var editFile = async (fileContent, operations) => {
36790
36790
  if (!operations || operations.length === 0) {
36791
36791
  throw new Error("At least one edit operation is required");
36792
36792
  }
36793
- const originalLines = fileContent.split(`
36794
- `);
36795
36793
  let updatedContent = fileContent;
36796
36794
  for (const operation of operations) {
36797
- updatedContent = await applyEditOperation(updatedContent, operation, originalLines);
36795
+ updatedContent = await applyEditOperation(updatedContent, operation);
36798
36796
  }
36799
36797
  return updatedContent;
36800
36798
  };
36801
- async function applyEditOperation(fileContent, operation, originalLines) {
36802
- const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
36803
- if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
36804
- return new_text;
36805
- }
36806
- if (start_anchor === START_OF_FILE) {
36807
- if (!end_anchor) {
36808
- return new_text + fileContent;
36809
- }
36810
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
36811
- return new_text + fileContent.slice(afterIndex);
36799
+ async function applyEditOperation(fileContent, operation) {
36800
+ const { search, replace } = operation;
36801
+ if (search === START_OF_FILE && replace === END_OF_FILE) {
36802
+ throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
36812
36803
  }
36813
- if (end_anchor === END_OF_FILE) {
36814
- if (!start_anchor) {
36815
- return fileContent + new_text;
36816
- }
36817
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
36818
- const beforeEndIndex = beforeIndex + start_anchor.length;
36819
- return fileContent.slice(0, beforeEndIndex) + new_text;
36820
- }
36821
- if (start_anchor && end_anchor) {
36822
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
36823
- const beforeEndIndex = beforeIndex + start_anchor.length;
36824
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
36825
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
36804
+ if (search === END_OF_FILE && replace === START_OF_FILE) {
36805
+ throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
36826
36806
  }
36827
- if (start_anchor) {
36828
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
36829
- const beforeEndIndex = beforeIndex + start_anchor.length;
36830
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
36807
+ if (search === START_OF_FILE) {
36808
+ return replace + fileContent;
36831
36809
  }
36832
- if (end_anchor) {
36833
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
36834
- return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
36810
+ if (search === END_OF_FILE) {
36811
+ return fileContent + replace;
36835
36812
  }
36836
- throw new Error("Either start_anchor or end_anchor must be specified");
36837
- }
36838
- function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
36839
- if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
36840
- const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
36841
- const searchRadius = 5;
36842
- const windowStart = Math.max(0, hintIndex - searchRadius * 50);
36843
- const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
36844
- const windowContent = content.slice(windowStart, windowEnd);
36845
- const relativeIndex = windowContent.indexOf(searchText);
36846
- if (relativeIndex !== -1) {
36847
- const absoluteIndex = windowStart + relativeIndex;
36848
- if (absoluteIndex >= startIndex) {
36849
- return absoluteIndex;
36850
- }
36851
- }
36852
- }
36853
- const index = content.indexOf(searchText, startIndex);
36813
+ const index = fileContent.indexOf(search);
36854
36814
  if (index === -1) {
36855
- throw new Error(`Could not find text: ${searchText}`);
36856
- }
36857
- return index;
36858
- }
36859
- function getLineStartIndex(lines, lineIndex) {
36860
- let index = 0;
36861
- for (let i2 = 0;i2 < lineIndex && i2 < lines.length; i2++) {
36862
- index += lines[i2].length + 1;
36815
+ throw new Error(`Could not find text: ${search}`);
36863
36816
  }
36864
- return index;
36817
+ return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
36865
36818
  }
36866
36819
  // ../core/src/tools/utils/getArg.ts
36867
36820
  var getString = (args, name, defaultValue) => {
@@ -37455,8 +37408,125 @@ var readFile_default = {
37455
37408
  handler: handler6,
37456
37409
  isAvailable: isAvailable6
37457
37410
  };
37458
- // ../core/src/tools/searchFiles.ts
37411
+ // ../core/src/tools/replaceInFile.ts
37459
37412
  var toolInfo7 = {
37413
+ name: "replace_in_file",
37414
+ description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
37415
+ parameters: [
37416
+ {
37417
+ name: "path",
37418
+ description: "The path of the file to modify",
37419
+ required: true,
37420
+ usageValue: "File path here"
37421
+ },
37422
+ {
37423
+ name: "diff",
37424
+ description: `One or more SEARCH/REPLACE blocks following this exact format:
37425
+ \`\`\`
37426
+ <<<<<<< SEARCH
37427
+ [exact content to find]
37428
+ =======
37429
+ [new content to replace with]
37430
+ >>>>>>> REPLACE
37431
+ \`\`\`
37432
+ Critical rules:
37433
+ 1. SEARCH content must match the associated file section to find EXACTLY:
37434
+ * Match character-for-character including whitespace, indentation, line endings
37435
+ * Include all comments, docstrings, etc.
37436
+ 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
37437
+ * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
37438
+ * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
37439
+ * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
37440
+ 3. Keep SEARCH/REPLACE blocks concise:
37441
+ * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
37442
+ * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
37443
+ * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
37444
+ * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
37445
+ 4. Special operations:
37446
+ * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
37447
+ * To delete code: Use empty REPLACE section`,
37448
+ required: true,
37449
+ usageValue: "Search and replace blocks here"
37450
+ }
37451
+ ],
37452
+ examples: [
37453
+ {
37454
+ description: "Request to replace sections of content in a file",
37455
+ parameters: [
37456
+ {
37457
+ name: "path",
37458
+ value: "src/main.js"
37459
+ },
37460
+ {
37461
+ name: "diff",
37462
+ value: `
37463
+ <<<<<<< SEARCH
37464
+ import React from 'react';
37465
+ =======
37466
+ import React, { useState } from 'react';
37467
+ >>>>>>> REPLACE
37468
+
37469
+ <<<<<<< SEARCH
37470
+ function handleSubmit() {
37471
+ saveData();
37472
+ setLoading(false);
37473
+ }
37474
+
37475
+ =======
37476
+ >>>>>>> REPLACE
37477
+
37478
+ <<<<<<< SEARCH
37479
+ return (
37480
+ <div>
37481
+ =======
37482
+ function handleSubmit() {
37483
+ saveData();
37484
+ setLoading(false);
37485
+ }
37486
+
37487
+ return (
37488
+ <div>
37489
+ >>>>>>> REPLACE
37490
+ `
37491
+ }
37492
+ ]
37493
+ }
37494
+ ],
37495
+ permissionLevel: 2 /* Write */
37496
+ };
37497
+ var handler7 = async (provider, args) => {
37498
+ if (!provider.readFile || !provider.writeFile) {
37499
+ return {
37500
+ type: "Error" /* Error */,
37501
+ message: "Not possible to replace in file. Abort."
37502
+ };
37503
+ }
37504
+ const path = getString(args, "path");
37505
+ const diff = getString(args, "diff");
37506
+ const fileContent = await provider.readFile(path);
37507
+ if (fileContent == null) {
37508
+ return {
37509
+ type: "Error" /* Error */,
37510
+ message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
37511
+ };
37512
+ }
37513
+ const result = await replaceInFile(fileContent, diff);
37514
+ await provider.writeFile(path, result);
37515
+ return {
37516
+ type: "Reply" /* Reply */,
37517
+ message: `<replace_in_file_path>${path}</replace_in_file_path>`
37518
+ };
37519
+ };
37520
+ var isAvailable7 = (provider) => {
37521
+ return !!provider.readFile && !!provider.writeFile;
37522
+ };
37523
+ var replaceInFile_default = {
37524
+ ...toolInfo7,
37525
+ handler: handler7,
37526
+ isAvailable: isAvailable7
37527
+ };
37528
+ // ../core/src/tools/searchFiles.ts
37529
+ var toolInfo8 = {
37460
37530
  name: "search_files",
37461
37531
  description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
37462
37532
  parameters: [
@@ -37500,7 +37570,7 @@ var toolInfo7 = {
37500
37570
  ],
37501
37571
  permissionLevel: 1 /* Read */
37502
37572
  };
37503
- var handler7 = async (provider, args) => {
37573
+ var handler8 = async (provider, args) => {
37504
37574
  if (!provider.searchFiles) {
37505
37575
  return {
37506
37576
  type: "Error" /* Error */,
@@ -37523,18 +37593,18 @@ ${files.join(`
37523
37593
  `
37524
37594
  };
37525
37595
  };
37526
- var isAvailable7 = (provider) => {
37596
+ var isAvailable8 = (provider) => {
37527
37597
  return !!provider.searchFiles;
37528
37598
  };
37529
37599
  var searchFiles_default = {
37530
- ...toolInfo7,
37531
- handler: handler7,
37532
- isAvailable: isAvailable7
37600
+ ...toolInfo8,
37601
+ handler: handler8,
37602
+ isAvailable: isAvailable8
37533
37603
  };
37534
37604
  // ../core/src/tools/updateKnowledge.ts
37535
37605
  var import_yaml = __toESM(require_dist(), 1);
37536
37606
  import { join } from "node:path";
37537
- var toolInfo8 = {
37607
+ var toolInfo9 = {
37538
37608
  name: "update_knowledge",
37539
37609
  description: "Update knowledge in a knowledge.ai.yml file with smart merging capabilities. This tool lets you add, update, or remove information using path-based updates and special directives.",
37540
37610
  parameters: [
@@ -37711,7 +37781,7 @@ function deepMerge(target, source) {
37711
37781
  }
37712
37782
  return output;
37713
37783
  }
37714
- var handler8 = async (provider, args) => {
37784
+ var handler9 = async (provider, args) => {
37715
37785
  if (!provider.readFile || !provider.writeFile) {
37716
37786
  return {
37717
37787
  type: "Error" /* Error */,
@@ -37783,16 +37853,16 @@ var handler8 = async (provider, args) => {
37783
37853
  };
37784
37854
  }
37785
37855
  };
37786
- var isAvailable8 = (provider) => {
37856
+ var isAvailable9 = (provider) => {
37787
37857
  return !!provider.readFile && !!provider.writeFile;
37788
37858
  };
37789
37859
  var updateKnowledge_default = {
37790
- ...toolInfo8,
37791
- handler: handler8,
37792
- isAvailable: isAvailable8
37860
+ ...toolInfo9,
37861
+ handler: handler9,
37862
+ isAvailable: isAvailable9
37793
37863
  };
37794
37864
  // ../core/src/tools/writeToFile.ts
37795
- var toolInfo9 = {
37865
+ var toolInfo10 = {
37796
37866
  name: "write_to_file",
37797
37867
  description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `&lt;` and `&gt;`.",
37798
37868
  parameters: [
@@ -37837,7 +37907,7 @@ export default App;
37837
37907
  ],
37838
37908
  permissionLevel: 2 /* Write */
37839
37909
  };
37840
- var handler9 = async (provider, args) => {
37910
+ var handler10 = async (provider, args) => {
37841
37911
  if (!provider.writeFile) {
37842
37912
  return {
37843
37913
  type: "Error" /* Error */,
@@ -37852,16 +37922,16 @@ var handler9 = async (provider, args) => {
37852
37922
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
37853
37923
  };
37854
37924
  };
37855
- var isAvailable9 = (provider) => {
37925
+ var isAvailable10 = (provider) => {
37856
37926
  return !!provider.writeFile;
37857
37927
  };
37858
37928
  var writeToFile_default = {
37859
- ...toolInfo9,
37860
- handler: handler9,
37861
- isAvailable: isAvailable9
37929
+ ...toolInfo10,
37930
+ handler: handler10,
37931
+ isAvailable: isAvailable10
37862
37932
  };
37863
37933
  // ../core/src/tools/handOver.ts
37864
- var toolInfo10 = {
37934
+ var toolInfo11 = {
37865
37935
  name: "hand_over",
37866
37936
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
37867
37937
  parameters: [
@@ -37915,7 +37985,7 @@ var toolInfo10 = {
37915
37985
  ],
37916
37986
  permissionLevel: 0 /* None */
37917
37987
  };
37918
- var handler10 = async (_provider, args) => {
37988
+ var handler11 = async (_provider, args) => {
37919
37989
  const agentName = getString(args, "agent_name");
37920
37990
  const task = getString(args, "task");
37921
37991
  const context = getString(args, "context", undefined);
@@ -37928,16 +37998,16 @@ var handler10 = async (_provider, args) => {
37928
37998
  files
37929
37999
  };
37930
38000
  };
37931
- var isAvailable10 = (_provider) => {
38001
+ var isAvailable11 = (_provider) => {
37932
38002
  return true;
37933
38003
  };
37934
38004
  var handOver_default = {
37935
- ...toolInfo10,
37936
- handler: handler10,
37937
- isAvailable: isAvailable10
38005
+ ...toolInfo11,
38006
+ handler: handler11,
38007
+ isAvailable: isAvailable11
37938
38008
  };
37939
38009
  // ../core/src/tools/removeFile.ts
37940
- var toolInfo11 = {
38010
+ var toolInfo12 = {
37941
38011
  name: "remove_file",
37942
38012
  description: "Request to remove a file at the specified path.",
37943
38013
  parameters: [
@@ -37961,7 +38031,7 @@ var toolInfo11 = {
37961
38031
  ],
37962
38032
  permissionLevel: 2 /* Write */
37963
38033
  };
37964
- var handler11 = async (provider, args) => {
38034
+ var handler12 = async (provider, args) => {
37965
38035
  if (!provider.removeFile) {
37966
38036
  return {
37967
38037
  type: "Error" /* Error */,
@@ -37975,16 +38045,16 @@ var handler11 = async (provider, args) => {
37975
38045
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
37976
38046
  };
37977
38047
  };
37978
- var isAvailable11 = (provider) => {
38048
+ var isAvailable12 = (provider) => {
37979
38049
  return !!provider.removeFile;
37980
38050
  };
37981
38051
  var removeFile_default = {
37982
- ...toolInfo11,
37983
- handler: handler11,
37984
- isAvailable: isAvailable11
38052
+ ...toolInfo12,
38053
+ handler: handler12,
38054
+ isAvailable: isAvailable12
37985
38055
  };
37986
38056
  // ../core/src/tools/renameFile.ts
37987
- var toolInfo12 = {
38057
+ var toolInfo13 = {
37988
38058
  name: "rename_file",
37989
38059
  description: "Request to rename a file from source path to target path.",
37990
38060
  parameters: [
@@ -38018,7 +38088,7 @@ var toolInfo12 = {
38018
38088
  ],
38019
38089
  permissionLevel: 2 /* Write */
38020
38090
  };
38021
- var handler12 = async (provider, args) => {
38091
+ var handler13 = async (provider, args) => {
38022
38092
  if (!provider.renameFile) {
38023
38093
  return {
38024
38094
  type: "Error" /* Error */,
@@ -38033,18 +38103,18 @@ var handler12 = async (provider, args) => {
38033
38103
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
38034
38104
  };
38035
38105
  };
38036
- var isAvailable12 = (provider) => {
38106
+ var isAvailable13 = (provider) => {
38037
38107
  return !!provider.renameFile;
38038
38108
  };
38039
38109
  var renameFile_default = {
38040
- ...toolInfo12,
38041
- handler: handler12,
38042
- isAvailable: isAvailable12
38110
+ ...toolInfo13,
38111
+ handler: handler13,
38112
+ isAvailable: isAvailable13
38043
38113
  };
38044
38114
  // ../core/src/tools/editFile.ts
38045
- var toolInfo13 = {
38115
+ var toolInfo14 = {
38046
38116
  name: "edit_file",
38047
- description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.",
38117
+ description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
38048
38118
  parameters: [
38049
38119
  {
38050
38120
  name: "path",
@@ -38054,39 +38124,21 @@ var toolInfo13 = {
38054
38124
  },
38055
38125
  {
38056
38126
  name: "operations",
38057
- description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
38127
+ description: "Edit operation with search and replace parameters",
38058
38128
  required: true,
38059
38129
  allowMultiple: true,
38060
38130
  children: [
38061
38131
  {
38062
- name: "start_anchor",
38063
- description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
38064
- required: false,
38065
- usageValue: "Text before the edit location"
38066
- },
38067
- {
38068
- name: "end_anchor",
38069
- description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
38070
- required: false,
38071
- usageValue: "Text after the edit location"
38072
- },
38073
- {
38074
- name: "new_text",
38075
- description: "Text to replace the content between start_anchor and end_anchor",
38132
+ name: "search",
38133
+ description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
38076
38134
  required: true,
38077
- usageValue: "New text content"
38135
+ usageValue: "Text to find and replace"
38078
38136
  },
38079
38137
  {
38080
- name: "start_anchor_line_start",
38081
- description: "Optional line number hint for start_anchor location (1-based)",
38082
- required: false,
38083
- usageValue: "10"
38084
- },
38085
- {
38086
- name: "end_anchor_line_start",
38087
- description: "Optional line number hint for end_anchor location (1-based)",
38088
- required: false,
38089
- usageValue: "20"
38138
+ name: "replace",
38139
+ description: "Text to replace the search text with",
38140
+ required: true,
38141
+ usageValue: "Replacement text"
38090
38142
  }
38091
38143
  ],
38092
38144
  usageValue: "operations here"
@@ -38094,7 +38146,7 @@ var toolInfo13 = {
38094
38146
  ],
38095
38147
  examples: [
38096
38148
  {
38097
- description: "Replace content between two text anchors",
38149
+ description: "Replace specific text",
38098
38150
  parameters: [
38099
38151
  {
38100
38152
  name: "path",
@@ -38103,11 +38155,12 @@ var toolInfo13 = {
38103
38155
  {
38104
38156
  name: "operations",
38105
38157
  value: {
38106
- start_anchor: "function oldFunction() {",
38107
- end_anchor: "}",
38108
- new_text: `
38158
+ search: `function oldFunction() {
38159
+ return 42;
38160
+ }`,
38161
+ replace: `function newFunction() {
38109
38162
  return "new implementation";
38110
- `
38163
+ }`
38111
38164
  }
38112
38165
  }
38113
38166
  ]
@@ -38122,9 +38175,8 @@ var toolInfo13 = {
38122
38175
  {
38123
38176
  name: "operations",
38124
38177
  value: {
38125
- start_anchor: START_OF_FILE,
38126
- end_anchor: "export",
38127
- new_text: `// File header comment
38178
+ search: START_OF_FILE,
38179
+ replace: `// File header comment
38128
38180
  `
38129
38181
  }
38130
38182
  }
@@ -38141,25 +38193,42 @@ var toolInfo13 = {
38141
38193
  name: "operations",
38142
38194
  value: [
38143
38195
  {
38144
- start_anchor: "import React",
38145
- end_anchor: 'from "react"',
38146
- new_text: ", { useState }"
38196
+ search: 'import React from "react"',
38197
+ replace: 'import React, { useState } from "react"'
38147
38198
  },
38148
38199
  {
38149
- start_anchor: "function Component() {",
38150
- end_anchor: "return (",
38151
- new_text: `
38200
+ search: `function Component() {
38201
+ return (`,
38202
+ replace: `function Component() {
38152
38203
  const [state, setState] = useState(false);
38153
- `
38204
+ return (`
38154
38205
  }
38155
38206
  ]
38156
38207
  }
38157
38208
  ]
38209
+ },
38210
+ {
38211
+ description: "Append content at end of file",
38212
+ parameters: [
38213
+ {
38214
+ name: "path",
38215
+ value: "src/footer.ts"
38216
+ },
38217
+ {
38218
+ name: "operations",
38219
+ value: {
38220
+ search: END_OF_FILE,
38221
+ replace: `
38222
+ // End of file appended comment
38223
+ `
38224
+ }
38225
+ }
38226
+ ]
38158
38227
  }
38159
38228
  ],
38160
38229
  permissionLevel: 2 /* Write */
38161
38230
  };
38162
- var handler13 = async (provider, args) => {
38231
+ var handler14 = async (provider, args) => {
38163
38232
  if (!provider.readFile || !provider.writeFile) {
38164
38233
  return {
38165
38234
  type: "Error" /* Error */,
@@ -38195,127 +38264,10 @@ var handler13 = async (provider, args) => {
38195
38264
  };
38196
38265
  }
38197
38266
  };
38198
- var isAvailable13 = (provider) => {
38199
- return !!provider.readFile && !!provider.writeFile;
38200
- };
38201
- var editFile_default = {
38202
- ...toolInfo13,
38203
- handler: handler13,
38204
- isAvailable: isAvailable13
38205
- };
38206
- // ../core/src/tools/replaceInFile.ts
38207
- var toolInfo14 = {
38208
- name: "replace_in_file",
38209
- description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
38210
- parameters: [
38211
- {
38212
- name: "path",
38213
- description: "The path of the file to modify",
38214
- required: true,
38215
- usageValue: "File path here"
38216
- },
38217
- {
38218
- name: "diff",
38219
- description: `One or more SEARCH/REPLACE blocks following this exact format:
38220
- \`\`\`
38221
- <<<<<<< SEARCH
38222
- [exact content to find]
38223
- =======
38224
- [new content to replace with]
38225
- >>>>>>> REPLACE
38226
- \`\`\`
38227
- Critical rules:
38228
- 1. SEARCH content must match the associated file section to find EXACTLY:
38229
- * Match character-for-character including whitespace, indentation, line endings
38230
- * Include all comments, docstrings, etc.
38231
- 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
38232
- * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
38233
- * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
38234
- * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
38235
- 3. Keep SEARCH/REPLACE blocks concise:
38236
- * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
38237
- * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
38238
- * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
38239
- * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
38240
- 4. Special operations:
38241
- * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
38242
- * To delete code: Use empty REPLACE section`,
38243
- required: true,
38244
- usageValue: "Search and replace blocks here"
38245
- }
38246
- ],
38247
- examples: [
38248
- {
38249
- description: "Request to replace sections of content in a file",
38250
- parameters: [
38251
- {
38252
- name: "path",
38253
- value: "src/main.js"
38254
- },
38255
- {
38256
- name: "diff",
38257
- value: `
38258
- <<<<<<< SEARCH
38259
- import React from 'react';
38260
- =======
38261
- import React, { useState } from 'react';
38262
- >>>>>>> REPLACE
38263
-
38264
- <<<<<<< SEARCH
38265
- function handleSubmit() {
38266
- saveData();
38267
- setLoading(false);
38268
- }
38269
-
38270
- =======
38271
- >>>>>>> REPLACE
38272
-
38273
- <<<<<<< SEARCH
38274
- return (
38275
- <div>
38276
- =======
38277
- function handleSubmit() {
38278
- saveData();
38279
- setLoading(false);
38280
- }
38281
-
38282
- return (
38283
- <div>
38284
- >>>>>>> REPLACE
38285
- `
38286
- }
38287
- ]
38288
- }
38289
- ],
38290
- permissionLevel: 2 /* Write */
38291
- };
38292
- var handler14 = async (provider, args) => {
38293
- if (!provider.readFile || !provider.writeFile) {
38294
- return {
38295
- type: "Error" /* Error */,
38296
- message: "Not possible to replace in file. Abort."
38297
- };
38298
- }
38299
- const path = getString(args, "path");
38300
- const diff = getString(args, "diff");
38301
- const fileContent = await provider.readFile(path);
38302
- if (fileContent == null) {
38303
- return {
38304
- type: "Error" /* Error */,
38305
- message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
38306
- };
38307
- }
38308
- const result = await replaceInFile(fileContent, diff);
38309
- await provider.writeFile(path, result);
38310
- return {
38311
- type: "Reply" /* Reply */,
38312
- message: `<replace_in_file_path>${path}</replace_in_file_path>`
38313
- };
38314
- };
38315
38267
  var isAvailable14 = (provider) => {
38316
38268
  return !!provider.readFile && !!provider.writeFile;
38317
38269
  };
38318
- var replaceInFile_default = {
38270
+ var editFile_default = {
38319
38271
  ...toolInfo14,
38320
38272
  handler: handler14,
38321
38273
  isAvailable: isAvailable14
@@ -38701,7 +38653,6 @@ class AgentBase {
38701
38653
  config;
38702
38654
  handlers;
38703
38655
  #messages = [];
38704
- #originalTask;
38705
38656
  #policies;
38706
38657
  constructor(name, ai, config) {
38707
38658
  this.ai = ai;
@@ -38747,7 +38698,6 @@ ${instance.prompt}`;
38747
38698
  await this.config.callback?.(event);
38748
38699
  }
38749
38700
  async start(prompt) {
38750
- this.#originalTask = prompt;
38751
38701
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
38752
38702
  return await this.#processLoop(prompt);
38753
38703
  }
@@ -38874,41 +38824,31 @@ ${instance.prompt}`;
38874
38824
  if (toolResponses.length > 0) {
38875
38825
  break outer;
38876
38826
  }
38877
- const handOverResp = {
38878
- ...toolResp,
38879
- originalTask: this.#originalTask
38880
- };
38881
38827
  await this.#callback({
38882
38828
  kind: "ToolHandOver" /* ToolHandOver */,
38883
38829
  agent: this,
38884
38830
  tool: content.name,
38885
- agentName: handOverResp.agentName,
38886
- task: handOverResp.task,
38887
- context: handOverResp.context,
38888
- files: handOverResp.files,
38889
- originalTask: handOverResp.originalTask
38831
+ agentName: toolResp.agentName,
38832
+ task: toolResp.task,
38833
+ context: toolResp.context,
38834
+ files: toolResp.files
38890
38835
  });
38891
- return { type: "exit", reason: handOverResp };
38836
+ return { type: "exit", reason: toolResp };
38892
38837
  }
38893
38838
  case "Delegate" /* Delegate */: {
38894
38839
  if (toolResponses.length > 0) {
38895
38840
  break outer;
38896
38841
  }
38897
- const delegateResp = {
38898
- ...toolResp,
38899
- originalTask: this.#originalTask
38900
- };
38901
38842
  await this.#callback({
38902
38843
  kind: "ToolDelegate" /* ToolDelegate */,
38903
38844
  agent: this,
38904
38845
  tool: content.name,
38905
- agentName: delegateResp.agentName,
38906
- task: delegateResp.task,
38907
- context: delegateResp.context,
38908
- files: delegateResp.files,
38909
- originalTask: delegateResp.originalTask
38846
+ agentName: toolResp.agentName,
38847
+ task: toolResp.task,
38848
+ context: toolResp.context,
38849
+ files: toolResp.files
38910
38850
  });
38911
- return { type: "exit", reason: delegateResp };
38851
+ return { type: "exit", reason: toolResp };
38912
38852
  }
38913
38853
  case "Pause" /* Pause */: {
38914
38854
  await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
@@ -39132,6 +39072,7 @@ var codeFixerAgentInfo = {
39132
39072
  class MultiAgent {
39133
39073
  #config;
39134
39074
  #agents = [];
39075
+ #originalTask;
39135
39076
  constructor(config) {
39136
39077
  this.#config = config;
39137
39078
  }
@@ -39139,11 +39080,11 @@ class MultiAgent {
39139
39080
  switch (exitReason.type) {
39140
39081
  case "HandOver" /* HandOver */: {
39141
39082
  this.#agents.pop();
39142
- const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, exitReason.originalTask) ?? exitReason.task;
39083
+ const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
39143
39084
  return await this.#startTask(exitReason.agentName, prompt);
39144
39085
  }
39145
39086
  case "Delegate" /* Delegate */: {
39146
- const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, exitReason.originalTask) ?? exitReason.task;
39087
+ const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
39147
39088
  const delegateResult = await this.#startTask(exitReason.agentName, prompt);
39148
39089
  switch (delegateResult.type) {
39149
39090
  case "HandOver" /* HandOver */:
@@ -39175,7 +39116,9 @@ class MultiAgent {
39175
39116
  if (this.#agents.length > 0) {
39176
39117
  throw new Error("An active agent already exists");
39177
39118
  }
39178
- return this.#startTask(options.agentName, options.task);
39119
+ this.#originalTask = options.task;
39120
+ return this.#startTask(options.agentName, `<task>${options.task}</task>
39121
+ <context>${options.context}</context>`);
39179
39122
  }
39180
39123
  async continueTask(userMessage) {
39181
39124
  if (!this.#agents.length) {
@@ -43593,8 +43536,8 @@ var executeAgentTool = async (definition, agent, params) => {
43593
43536
  }
43594
43537
  const exitReason = await agent.startTask({
43595
43538
  agentName: definition.agent,
43596
- task: `<task>${definition.prompt}</task>
43597
- <context>${definition.formatInput(params)}</context>`
43539
+ task: definition.prompt,
43540
+ context: definition.formatInput(params)
43598
43541
  });
43599
43542
  if (exitReason.type === "Exit" /* Exit */) {
43600
43543
  return definition.parseOutput(exitReason.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.8.17",
3
+ "version": "0.8.19",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",