@polka-codes/cli 0.8.18 → 0.8.20

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 +164 -168
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38447,7 +38447,7 @@ var {
38447
38447
  Help
38448
38448
  } = import__.default;
38449
38449
  // package.json
38450
- var version = "0.8.18";
38450
+ var version = "0.8.20";
38451
38451
 
38452
38452
  // ../core/src/AiService/AiServiceBase.ts
38453
38453
  class AiServiceBase {
@@ -47746,13 +47746,13 @@ __export(exports_allTools, {
47746
47746
  writeToFile: () => writeToFile_default,
47747
47747
  updateKnowledge: () => updateKnowledge_default,
47748
47748
  searchFiles: () => searchFiles_default,
47749
+ replaceInFile: () => replaceInFile_default,
47749
47750
  renameFile: () => renameFile_default,
47750
47751
  removeFile: () => removeFile_default,
47751
47752
  readFile: () => readFile_default,
47752
47753
  listFiles: () => listFiles_default,
47753
47754
  handOver: () => handOver_default,
47754
47755
  executeCommand: () => executeCommand_default,
47755
- editFile: () => editFile_default,
47756
47756
  delegate: () => delegate_default,
47757
47757
  attemptCompletion: () => attemptCompletion_default,
47758
47758
  askFollowupQuestion: () => askFollowupQuestion_default
@@ -47884,7 +47884,7 @@ var getArray = (args, name, defaultValue) => {
47884
47884
  };
47885
47885
  // ../core/src/tools/utils/replaceInFile.ts
47886
47886
  var replaceInFile = async (fileContent, diff) => {
47887
- const blockPattern = /<<<<<+ SEARCH\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+ REPLACE/g;
47887
+ const blockPattern = /<<<<<+ SEARCH>?\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+ REPLACE/g;
47888
47888
  const blocks = [];
47889
47889
  for (let match = blockPattern.exec(diff);match !== null; match = blockPattern.exec(diff)) {
47890
47890
  blocks.push({ search: match[1], replace: match[2] });
@@ -48383,8 +48383,125 @@ var readFile_default = {
48383
48383
  handler: handler6,
48384
48384
  isAvailable: isAvailable6
48385
48385
  };
48386
- // ../core/src/tools/searchFiles.ts
48386
+ // ../core/src/tools/replaceInFile.ts
48387
48387
  var toolInfo7 = {
48388
+ name: "replace_in_file",
48389
+ 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.",
48390
+ parameters: [
48391
+ {
48392
+ name: "path",
48393
+ description: "The path of the file to modify",
48394
+ required: true,
48395
+ usageValue: "File path here"
48396
+ },
48397
+ {
48398
+ name: "diff",
48399
+ description: `One or more SEARCH/REPLACE blocks following this exact format:
48400
+ \`\`\`
48401
+ <<<<<<< SEARCH
48402
+ [exact content to find]
48403
+ =======
48404
+ [new content to replace with]
48405
+ >>>>>>> REPLACE
48406
+ \`\`\`
48407
+ Critical rules:
48408
+ 1. SEARCH content must match the associated file section to find EXACTLY:
48409
+ * Match character-for-character including whitespace, indentation, line endings
48410
+ * Include all comments, docstrings, etc.
48411
+ 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
48412
+ * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
48413
+ * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
48414
+ * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
48415
+ 3. Keep SEARCH/REPLACE blocks concise:
48416
+ * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
48417
+ * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
48418
+ * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
48419
+ * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
48420
+ 4. Special operations:
48421
+ * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
48422
+ * To delete code: Use empty REPLACE section`,
48423
+ required: true,
48424
+ usageValue: "Search and replace blocks here"
48425
+ }
48426
+ ],
48427
+ examples: [
48428
+ {
48429
+ description: "Request to replace sections of content in a file",
48430
+ parameters: [
48431
+ {
48432
+ name: "path",
48433
+ value: "src/main.js"
48434
+ },
48435
+ {
48436
+ name: "diff",
48437
+ value: `
48438
+ <<<<<<< SEARCH
48439
+ import React from 'react';
48440
+ =======
48441
+ import React, { useState } from 'react';
48442
+ >>>>>>> REPLACE
48443
+
48444
+ <<<<<<< SEARCH
48445
+ function handleSubmit() {
48446
+ saveData();
48447
+ setLoading(false);
48448
+ }
48449
+
48450
+ =======
48451
+ >>>>>>> REPLACE
48452
+
48453
+ <<<<<<< SEARCH
48454
+ return (
48455
+ <div>
48456
+ =======
48457
+ function handleSubmit() {
48458
+ saveData();
48459
+ setLoading(false);
48460
+ }
48461
+
48462
+ return (
48463
+ <div>
48464
+ >>>>>>> REPLACE
48465
+ `
48466
+ }
48467
+ ]
48468
+ }
48469
+ ],
48470
+ permissionLevel: 2 /* Write */
48471
+ };
48472
+ var handler7 = async (provider, args) => {
48473
+ if (!provider.readFile || !provider.writeFile) {
48474
+ return {
48475
+ type: "Error" /* Error */,
48476
+ message: "Not possible to replace in file. Abort."
48477
+ };
48478
+ }
48479
+ const path = getString(args, "path");
48480
+ const diff = getString(args, "diff");
48481
+ const fileContent = await provider.readFile(path);
48482
+ if (fileContent == null) {
48483
+ return {
48484
+ type: "Error" /* Error */,
48485
+ message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
48486
+ };
48487
+ }
48488
+ const result = await replaceInFile(fileContent, diff);
48489
+ await provider.writeFile(path, result);
48490
+ return {
48491
+ type: "Reply" /* Reply */,
48492
+ message: `<replace_in_file_path>${path}</replace_in_file_path>`
48493
+ };
48494
+ };
48495
+ var isAvailable7 = (provider) => {
48496
+ return !!provider.readFile && !!provider.writeFile;
48497
+ };
48498
+ var replaceInFile_default = {
48499
+ ...toolInfo7,
48500
+ handler: handler7,
48501
+ isAvailable: isAvailable7
48502
+ };
48503
+ // ../core/src/tools/searchFiles.ts
48504
+ var toolInfo8 = {
48388
48505
  name: "search_files",
48389
48506
  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.",
48390
48507
  parameters: [
@@ -48428,7 +48545,7 @@ var toolInfo7 = {
48428
48545
  ],
48429
48546
  permissionLevel: 1 /* Read */
48430
48547
  };
48431
- var handler7 = async (provider, args) => {
48548
+ var handler8 = async (provider, args) => {
48432
48549
  if (!provider.searchFiles) {
48433
48550
  return {
48434
48551
  type: "Error" /* Error */,
@@ -48451,18 +48568,18 @@ ${files.join(`
48451
48568
  `
48452
48569
  };
48453
48570
  };
48454
- var isAvailable7 = (provider) => {
48571
+ var isAvailable8 = (provider) => {
48455
48572
  return !!provider.searchFiles;
48456
48573
  };
48457
48574
  var searchFiles_default = {
48458
- ...toolInfo7,
48459
- handler: handler7,
48460
- isAvailable: isAvailable7
48575
+ ...toolInfo8,
48576
+ handler: handler8,
48577
+ isAvailable: isAvailable8
48461
48578
  };
48462
48579
  // ../core/src/tools/updateKnowledge.ts
48463
48580
  var import_yaml = __toESM(require_dist(), 1);
48464
48581
  import { join } from "node:path";
48465
- var toolInfo8 = {
48582
+ var toolInfo9 = {
48466
48583
  name: "update_knowledge",
48467
48584
  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.",
48468
48585
  parameters: [
@@ -48639,7 +48756,7 @@ function deepMerge(target, source) {
48639
48756
  }
48640
48757
  return output;
48641
48758
  }
48642
- var handler8 = async (provider, args) => {
48759
+ var handler9 = async (provider, args) => {
48643
48760
  if (!provider.readFile || !provider.writeFile) {
48644
48761
  return {
48645
48762
  type: "Error" /* Error */,
@@ -48711,16 +48828,16 @@ var handler8 = async (provider, args) => {
48711
48828
  };
48712
48829
  }
48713
48830
  };
48714
- var isAvailable8 = (provider) => {
48831
+ var isAvailable9 = (provider) => {
48715
48832
  return !!provider.readFile && !!provider.writeFile;
48716
48833
  };
48717
48834
  var updateKnowledge_default = {
48718
- ...toolInfo8,
48719
- handler: handler8,
48720
- isAvailable: isAvailable8
48835
+ ...toolInfo9,
48836
+ handler: handler9,
48837
+ isAvailable: isAvailable9
48721
48838
  };
48722
48839
  // ../core/src/tools/writeToFile.ts
48723
- var toolInfo9 = {
48840
+ var toolInfo10 = {
48724
48841
  name: "write_to_file",
48725
48842
  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;`.",
48726
48843
  parameters: [
@@ -48765,7 +48882,7 @@ export default App;
48765
48882
  ],
48766
48883
  permissionLevel: 2 /* Write */
48767
48884
  };
48768
- var handler9 = async (provider, args) => {
48885
+ var handler10 = async (provider, args) => {
48769
48886
  if (!provider.writeFile) {
48770
48887
  return {
48771
48888
  type: "Error" /* Error */,
@@ -48780,16 +48897,16 @@ var handler9 = async (provider, args) => {
48780
48897
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
48781
48898
  };
48782
48899
  };
48783
- var isAvailable9 = (provider) => {
48900
+ var isAvailable10 = (provider) => {
48784
48901
  return !!provider.writeFile;
48785
48902
  };
48786
48903
  var writeToFile_default = {
48787
- ...toolInfo9,
48788
- handler: handler9,
48789
- isAvailable: isAvailable9
48904
+ ...toolInfo10,
48905
+ handler: handler10,
48906
+ isAvailable: isAvailable10
48790
48907
  };
48791
48908
  // ../core/src/tools/handOver.ts
48792
- var toolInfo10 = {
48909
+ var toolInfo11 = {
48793
48910
  name: "hand_over",
48794
48911
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
48795
48912
  parameters: [
@@ -48843,7 +48960,7 @@ var toolInfo10 = {
48843
48960
  ],
48844
48961
  permissionLevel: 0 /* None */
48845
48962
  };
48846
- var handler10 = async (_provider, args) => {
48963
+ var handler11 = async (_provider, args) => {
48847
48964
  const agentName = getString(args, "agent_name");
48848
48965
  const task = getString(args, "task");
48849
48966
  const context = getString(args, "context", undefined);
@@ -48856,16 +48973,16 @@ var handler10 = async (_provider, args) => {
48856
48973
  files
48857
48974
  };
48858
48975
  };
48859
- var isAvailable10 = (_provider) => {
48976
+ var isAvailable11 = (_provider) => {
48860
48977
  return true;
48861
48978
  };
48862
48979
  var handOver_default = {
48863
- ...toolInfo10,
48864
- handler: handler10,
48865
- isAvailable: isAvailable10
48980
+ ...toolInfo11,
48981
+ handler: handler11,
48982
+ isAvailable: isAvailable11
48866
48983
  };
48867
48984
  // ../core/src/tools/removeFile.ts
48868
- var toolInfo11 = {
48985
+ var toolInfo12 = {
48869
48986
  name: "remove_file",
48870
48987
  description: "Request to remove a file at the specified path.",
48871
48988
  parameters: [
@@ -48889,7 +49006,7 @@ var toolInfo11 = {
48889
49006
  ],
48890
49007
  permissionLevel: 2 /* Write */
48891
49008
  };
48892
- var handler11 = async (provider, args) => {
49009
+ var handler12 = async (provider, args) => {
48893
49010
  if (!provider.removeFile) {
48894
49011
  return {
48895
49012
  type: "Error" /* Error */,
@@ -48903,16 +49020,16 @@ var handler11 = async (provider, args) => {
48903
49020
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
48904
49021
  };
48905
49022
  };
48906
- var isAvailable11 = (provider) => {
49023
+ var isAvailable12 = (provider) => {
48907
49024
  return !!provider.removeFile;
48908
49025
  };
48909
49026
  var removeFile_default = {
48910
- ...toolInfo11,
48911
- handler: handler11,
48912
- isAvailable: isAvailable11
49027
+ ...toolInfo12,
49028
+ handler: handler12,
49029
+ isAvailable: isAvailable12
48913
49030
  };
48914
49031
  // ../core/src/tools/renameFile.ts
48915
- var toolInfo12 = {
49032
+ var toolInfo13 = {
48916
49033
  name: "rename_file",
48917
49034
  description: "Request to rename a file from source path to target path.",
48918
49035
  parameters: [
@@ -48946,7 +49063,7 @@ var toolInfo12 = {
48946
49063
  ],
48947
49064
  permissionLevel: 2 /* Write */
48948
49065
  };
48949
- var handler12 = async (provider, args) => {
49066
+ var handler13 = async (provider, args) => {
48950
49067
  if (!provider.renameFile) {
48951
49068
  return {
48952
49069
  type: "Error" /* Error */,
@@ -48961,16 +49078,16 @@ var handler12 = async (provider, args) => {
48961
49078
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
48962
49079
  };
48963
49080
  };
48964
- var isAvailable12 = (provider) => {
49081
+ var isAvailable13 = (provider) => {
48965
49082
  return !!provider.renameFile;
48966
49083
  };
48967
49084
  var renameFile_default = {
48968
- ...toolInfo12,
48969
- handler: handler12,
48970
- isAvailable: isAvailable12
49085
+ ...toolInfo13,
49086
+ handler: handler13,
49087
+ isAvailable: isAvailable13
48971
49088
  };
48972
49089
  // ../core/src/tools/editFile.ts
48973
- var toolInfo13 = {
49090
+ var toolInfo14 = {
48974
49091
  name: "edit_file",
48975
49092
  description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
48976
49093
  parameters: [
@@ -49086,7 +49203,7 @@ var toolInfo13 = {
49086
49203
  ],
49087
49204
  permissionLevel: 2 /* Write */
49088
49205
  };
49089
- var handler13 = async (provider, args) => {
49206
+ var handler14 = async (provider, args) => {
49090
49207
  if (!provider.readFile || !provider.writeFile) {
49091
49208
  return {
49092
49209
  type: "Error" /* Error */,
@@ -49122,127 +49239,10 @@ var handler13 = async (provider, args) => {
49122
49239
  };
49123
49240
  }
49124
49241
  };
49125
- var isAvailable13 = (provider) => {
49126
- return !!provider.readFile && !!provider.writeFile;
49127
- };
49128
- var editFile_default = {
49129
- ...toolInfo13,
49130
- handler: handler13,
49131
- isAvailable: isAvailable13
49132
- };
49133
- // ../core/src/tools/replaceInFile.ts
49134
- var toolInfo14 = {
49135
- name: "replace_in_file",
49136
- 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.",
49137
- parameters: [
49138
- {
49139
- name: "path",
49140
- description: "The path of the file to modify",
49141
- required: true,
49142
- usageValue: "File path here"
49143
- },
49144
- {
49145
- name: "diff",
49146
- description: `One or more SEARCH/REPLACE blocks following this exact format:
49147
- \`\`\`
49148
- <<<<<<< SEARCH
49149
- [exact content to find]
49150
- =======
49151
- [new content to replace with]
49152
- >>>>>>> REPLACE
49153
- \`\`\`
49154
- Critical rules:
49155
- 1. SEARCH content must match the associated file section to find EXACTLY:
49156
- * Match character-for-character including whitespace, indentation, line endings
49157
- * Include all comments, docstrings, etc.
49158
- 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
49159
- * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
49160
- * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
49161
- * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
49162
- 3. Keep SEARCH/REPLACE blocks concise:
49163
- * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
49164
- * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
49165
- * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
49166
- * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
49167
- 4. Special operations:
49168
- * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
49169
- * To delete code: Use empty REPLACE section`,
49170
- required: true,
49171
- usageValue: "Search and replace blocks here"
49172
- }
49173
- ],
49174
- examples: [
49175
- {
49176
- description: "Request to replace sections of content in a file",
49177
- parameters: [
49178
- {
49179
- name: "path",
49180
- value: "src/main.js"
49181
- },
49182
- {
49183
- name: "diff",
49184
- value: `
49185
- <<<<<<< SEARCH
49186
- import React from 'react';
49187
- =======
49188
- import React, { useState } from 'react';
49189
- >>>>>>> REPLACE
49190
-
49191
- <<<<<<< SEARCH
49192
- function handleSubmit() {
49193
- saveData();
49194
- setLoading(false);
49195
- }
49196
-
49197
- =======
49198
- >>>>>>> REPLACE
49199
-
49200
- <<<<<<< SEARCH
49201
- return (
49202
- <div>
49203
- =======
49204
- function handleSubmit() {
49205
- saveData();
49206
- setLoading(false);
49207
- }
49208
-
49209
- return (
49210
- <div>
49211
- >>>>>>> REPLACE
49212
- `
49213
- }
49214
- ]
49215
- }
49216
- ],
49217
- permissionLevel: 2 /* Write */
49218
- };
49219
- var handler14 = async (provider, args) => {
49220
- if (!provider.readFile || !provider.writeFile) {
49221
- return {
49222
- type: "Error" /* Error */,
49223
- message: "Not possible to replace in file. Abort."
49224
- };
49225
- }
49226
- const path = getString(args, "path");
49227
- const diff = getString(args, "diff");
49228
- const fileContent = await provider.readFile(path);
49229
- if (fileContent == null) {
49230
- return {
49231
- type: "Error" /* Error */,
49232
- message: `<error><replace_in_file_path>${path}</replace_in_file_path><error_message>File not found</error_message></error>`
49233
- };
49234
- }
49235
- const result = await replaceInFile(fileContent, diff);
49236
- await provider.writeFile(path, result);
49237
- return {
49238
- type: "Reply" /* Reply */,
49239
- message: `<replace_in_file_path>${path}</replace_in_file_path>`
49240
- };
49241
- };
49242
49242
  var isAvailable14 = (provider) => {
49243
49243
  return !!provider.readFile && !!provider.writeFile;
49244
49244
  };
49245
- var replaceInFile_default = {
49245
+ var editFile_default = {
49246
49246
  ...toolInfo14,
49247
49247
  handler: handler14,
49248
49248
  isAvailable: isAvailable14
@@ -49523,18 +49523,14 @@ ${tools.map((tool) => {
49523
49523
  }).join("")}
49524
49524
  # Tool Use Guidelines
49525
49525
 
49526
- 1. **Outline Your Thought Process**
49527
- - Before using a tool, wrap your reasoning inside \`<thinking>\` tags. Be concise—just enough to clarify your plan and the rationale behind selecting a specific tool.
49528
- 2. **Wait for Feedback**
49526
+ 1. **Wait for Feedback**
49529
49527
  - After using a tool, wait for the user's response indicating success/failure or any output logs. Do not assume the result of a tool without explicit confirmation.
49530
- 3. **Error Handling**
49528
+ 2. **Error Handling**
49531
49529
  - If a tool fails or produces an unexpected result, analyze the error, decide on an alternative approach or tool, and proceed carefully.
49532
- 4. **Avoid Repetition**
49530
+ 3. **Avoid Repetition**
49533
49531
  - Do not quote or repeat previous commands or prompts verbatim. Move the conversation forward by focusing on the latest required action.
49534
- 5. **No Unnecessary Re-invocations**
49535
- - Only invoke the same tool again if a genuine need arises (e.g., different parameters or updated context).
49536
- 6. **Tool Call Limit**
49537
- - Do not make more than 5 tool calls in a single message.`;
49532
+ 4. **Tool Call Limit**
49533
+ - It is **STRIGHTLY FORBIDDEN** to make more than 5 tool calls in a single message.`;
49538
49534
  };
49539
49535
  var agentsPrompt = (agents, name) => `
49540
49536
  ====
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.8.18",
3
+ "version": "0.8.20",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",