@polka-codes/cli 0.8.22 → 0.8.23

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 +168 -66
  2. package/package.json +3 -3
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.22";
38450
+ var version = "0.8.23";
38451
38451
 
38452
38452
  // ../core/src/AiService/AiServiceBase.ts
38453
38453
  class AiServiceBase {
@@ -47752,6 +47752,7 @@ __export(exports_allTools, {
47752
47752
  readFile: () => readFile_default,
47753
47753
  listFiles: () => listFiles_default,
47754
47754
  handOver: () => handOver_default,
47755
+ fetchUrl: () => fetchUrl_default,
47755
47756
  executeCommand: () => executeCommand_default,
47756
47757
  delegate: () => delegate_default,
47757
47758
  attemptCompletion: () => attemptCompletion_default,
@@ -48210,8 +48211,89 @@ var executeCommand_default = {
48210
48211
  handler: handler4,
48211
48212
  isAvailable: isAvailable4
48212
48213
  };
48213
- // ../core/src/tools/listFiles.ts
48214
+ // ../core/src/tools/fetchUrl.ts
48214
48215
  var toolInfo5 = {
48216
+ name: "fetch_url",
48217
+ description: "Fetch the content located at one or more HTTP(S) URLs and return it in Markdown format. This works for standard web pages as well as raw files (e.g. README.md, source code) hosted on platforms like GitHub.",
48218
+ parameters: [
48219
+ {
48220
+ name: "url",
48221
+ description: "One or more URLs to fetch, separated by commas if multiple.",
48222
+ required: true
48223
+ }
48224
+ ],
48225
+ examples: [
48226
+ {
48227
+ description: "Fetch a single webpage",
48228
+ parameters: [
48229
+ {
48230
+ name: "url",
48231
+ value: "https://example.com"
48232
+ }
48233
+ ]
48234
+ },
48235
+ {
48236
+ description: "Fetch multiple webpages",
48237
+ parameters: [
48238
+ {
48239
+ name: "url",
48240
+ value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
48241
+ }
48242
+ ]
48243
+ },
48244
+ {
48245
+ description: "Fetch a raw file from GitHub",
48246
+ parameters: [
48247
+ {
48248
+ name: "url",
48249
+ value: "https://raw.githubusercontent.com/user/repo/main/README.md"
48250
+ }
48251
+ ]
48252
+ }
48253
+ ],
48254
+ permissionLevel: 1 /* Read */
48255
+ };
48256
+ var handler5 = async (provider, args) => {
48257
+ if (!provider.fetchUrl) {
48258
+ return {
48259
+ type: "Error" /* Error */,
48260
+ message: "Not possible to fetch url. Abort."
48261
+ };
48262
+ }
48263
+ const urls = getStringArray(args, "url");
48264
+ if (urls.length === 0) {
48265
+ return {
48266
+ type: "Error" /* Error */,
48267
+ message: "No URLs provided. Please provide at least one URL to fetch."
48268
+ };
48269
+ }
48270
+ const results = [];
48271
+ for (const url of urls) {
48272
+ try {
48273
+ const content = provider.fetchUrl(url).then((res) => `<fetch_url_content url="${url}">${res}</fetch_url_content>`);
48274
+ results.push(content);
48275
+ } catch (error) {
48276
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
48277
+ results.push(Promise.resolve(`<fetch_url_error url="${url}">${errorMessage}</fetch_url_error>`));
48278
+ }
48279
+ }
48280
+ const resolvedResults = await Promise.all(results);
48281
+ return {
48282
+ type: "Reply" /* Reply */,
48283
+ message: resolvedResults.join(`
48284
+ `)
48285
+ };
48286
+ };
48287
+ var isAvailable5 = (provider) => {
48288
+ return typeof provider.fetchUrl === "function";
48289
+ };
48290
+ var fetchUrl_default = {
48291
+ ...toolInfo5,
48292
+ handler: handler5,
48293
+ isAvailable: isAvailable5
48294
+ };
48295
+ // ../core/src/tools/listFiles.ts
48296
+ var toolInfo6 = {
48215
48297
  name: "list_files",
48216
48298
  description: "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
48217
48299
  parameters: [
@@ -48251,7 +48333,7 @@ var toolInfo5 = {
48251
48333
  ],
48252
48334
  permissionLevel: 1 /* Read */
48253
48335
  };
48254
- var handler5 = async (provider, args) => {
48336
+ var handler6 = async (provider, args) => {
48255
48337
  if (!provider.listFiles) {
48256
48338
  return {
48257
48339
  type: "Error" /* Error */,
@@ -48272,16 +48354,16 @@ ${files.join(`
48272
48354
  <list_files_truncated>${limitReached}</list_files_truncated>`
48273
48355
  };
48274
48356
  };
48275
- var isAvailable5 = (provider) => {
48357
+ var isAvailable6 = (provider) => {
48276
48358
  return !!provider.listFiles;
48277
48359
  };
48278
48360
  var listFiles_default = {
48279
- ...toolInfo5,
48280
- handler: handler5,
48281
- isAvailable: isAvailable5
48361
+ ...toolInfo6,
48362
+ handler: handler6,
48363
+ isAvailable: isAvailable6
48282
48364
  };
48283
48365
  // ../core/src/tools/readFile.ts
48284
- var toolInfo6 = {
48366
+ var toolInfo7 = {
48285
48367
  name: "read_file",
48286
48368
  description: "Request to read the contents of one or multiple files at the specified paths. Use comma separated paths to read multiple files. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. May not be suitable for other types of binary files, as it returns the raw content as a string. Try to list all the potential files are relevent to the task, and then use this tool to read all the relevant files.",
48287
48369
  parameters: [
@@ -48314,7 +48396,7 @@ var toolInfo6 = {
48314
48396
  ],
48315
48397
  permissionLevel: 1 /* Read */
48316
48398
  };
48317
- var handler6 = async (provider, args) => {
48399
+ var handler7 = async (provider, args) => {
48318
48400
  if (!provider.readFile) {
48319
48401
  return {
48320
48402
  type: "Error" /* Error */,
@@ -48342,16 +48424,16 @@ var handler6 = async (provider, args) => {
48342
48424
  `)
48343
48425
  };
48344
48426
  };
48345
- var isAvailable6 = (provider) => {
48427
+ var isAvailable7 = (provider) => {
48346
48428
  return !!provider.readFile;
48347
48429
  };
48348
48430
  var readFile_default = {
48349
- ...toolInfo6,
48350
- handler: handler6,
48351
- isAvailable: isAvailable6
48431
+ ...toolInfo7,
48432
+ handler: handler7,
48433
+ isAvailable: isAvailable7
48352
48434
  };
48353
48435
  // ../core/src/tools/replaceInFile.ts
48354
- var toolInfo7 = {
48436
+ var toolInfo8 = {
48355
48437
  name: "replace_in_file",
48356
48438
  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.",
48357
48439
  parameters: [
@@ -48503,7 +48585,7 @@ function oldFeature() {
48503
48585
  ],
48504
48586
  permissionLevel: 2 /* Write */
48505
48587
  };
48506
- var handler7 = async (provider, args) => {
48588
+ var handler8 = async (provider, args) => {
48507
48589
  if (!provider.readFile || !provider.writeFile) {
48508
48590
  return {
48509
48591
  type: "Error" /* Error */,
@@ -48526,16 +48608,16 @@ var handler7 = async (provider, args) => {
48526
48608
  message: `<replace_in_file_path>${path}</replace_in_file_path>`
48527
48609
  };
48528
48610
  };
48529
- var isAvailable7 = (provider) => {
48611
+ var isAvailable8 = (provider) => {
48530
48612
  return !!provider.readFile && !!provider.writeFile;
48531
48613
  };
48532
48614
  var replaceInFile_default = {
48533
- ...toolInfo7,
48534
- handler: handler7,
48535
- isAvailable: isAvailable7
48615
+ ...toolInfo8,
48616
+ handler: handler8,
48617
+ isAvailable: isAvailable8
48536
48618
  };
48537
48619
  // ../core/src/tools/searchFiles.ts
48538
- var toolInfo8 = {
48620
+ var toolInfo9 = {
48539
48621
  name: "search_files",
48540
48622
  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.",
48541
48623
  parameters: [
@@ -48579,7 +48661,7 @@ var toolInfo8 = {
48579
48661
  ],
48580
48662
  permissionLevel: 1 /* Read */
48581
48663
  };
48582
- var handler8 = async (provider, args) => {
48664
+ var handler9 = async (provider, args) => {
48583
48665
  if (!provider.searchFiles) {
48584
48666
  return {
48585
48667
  type: "Error" /* Error */,
@@ -48602,13 +48684,13 @@ ${files.join(`
48602
48684
  `
48603
48685
  };
48604
48686
  };
48605
- var isAvailable8 = (provider) => {
48687
+ var isAvailable9 = (provider) => {
48606
48688
  return !!provider.searchFiles;
48607
48689
  };
48608
48690
  var searchFiles_default = {
48609
- ...toolInfo8,
48610
- handler: handler8,
48611
- isAvailable: isAvailable8
48691
+ ...toolInfo9,
48692
+ handler: handler9,
48693
+ isAvailable: isAvailable9
48612
48694
  };
48613
48695
  // ../core/src/tools/updateKnowledge.ts
48614
48696
  var import_yaml = __toESM(require_dist(), 1);
@@ -48670,7 +48752,7 @@ function join(...parts) {
48670
48752
  }
48671
48753
 
48672
48754
  // ../core/src/tools/updateKnowledge.ts
48673
- var toolInfo9 = {
48755
+ var toolInfo10 = {
48674
48756
  name: "update_knowledge",
48675
48757
  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.",
48676
48758
  parameters: [
@@ -48847,7 +48929,7 @@ function deepMerge(target, source) {
48847
48929
  }
48848
48930
  return output;
48849
48931
  }
48850
- var handler9 = async (provider, args) => {
48932
+ var handler10 = async (provider, args) => {
48851
48933
  if (!provider.readFile || !provider.writeFile) {
48852
48934
  return {
48853
48935
  type: "Error" /* Error */,
@@ -48919,16 +49001,16 @@ var handler9 = async (provider, args) => {
48919
49001
  };
48920
49002
  }
48921
49003
  };
48922
- var isAvailable9 = (provider) => {
49004
+ var isAvailable10 = (provider) => {
48923
49005
  return !!provider.readFile && !!provider.writeFile;
48924
49006
  };
48925
49007
  var updateKnowledge_default = {
48926
- ...toolInfo9,
48927
- handler: handler9,
48928
- isAvailable: isAvailable9
49008
+ ...toolInfo10,
49009
+ handler: handler10,
49010
+ isAvailable: isAvailable10
48929
49011
  };
48930
49012
  // ../core/src/tools/writeToFile.ts
48931
- var toolInfo10 = {
49013
+ var toolInfo11 = {
48932
49014
  name: "write_to_file",
48933
49015
  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;`.",
48934
49016
  parameters: [
@@ -48973,7 +49055,7 @@ export default App;
48973
49055
  ],
48974
49056
  permissionLevel: 2 /* Write */
48975
49057
  };
48976
- var handler10 = async (provider, args) => {
49058
+ var handler11 = async (provider, args) => {
48977
49059
  if (!provider.writeFile) {
48978
49060
  return {
48979
49061
  type: "Error" /* Error */,
@@ -48988,16 +49070,16 @@ var handler10 = async (provider, args) => {
48988
49070
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
48989
49071
  };
48990
49072
  };
48991
- var isAvailable10 = (provider) => {
49073
+ var isAvailable11 = (provider) => {
48992
49074
  return !!provider.writeFile;
48993
49075
  };
48994
49076
  var writeToFile_default = {
48995
- ...toolInfo10,
48996
- handler: handler10,
48997
- isAvailable: isAvailable10
49077
+ ...toolInfo11,
49078
+ handler: handler11,
49079
+ isAvailable: isAvailable11
48998
49080
  };
48999
49081
  // ../core/src/tools/handOver.ts
49000
- var toolInfo11 = {
49082
+ var toolInfo12 = {
49001
49083
  name: "hand_over",
49002
49084
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
49003
49085
  parameters: [
@@ -49051,7 +49133,7 @@ var toolInfo11 = {
49051
49133
  ],
49052
49134
  permissionLevel: 0 /* None */
49053
49135
  };
49054
- var handler11 = async (_provider, args) => {
49136
+ var handler12 = async (_provider, args) => {
49055
49137
  const agentName = getString(args, "agent_name");
49056
49138
  const task = getString(args, "task");
49057
49139
  const context = getString(args, "context", undefined);
@@ -49064,16 +49146,16 @@ var handler11 = async (_provider, args) => {
49064
49146
  files
49065
49147
  };
49066
49148
  };
49067
- var isAvailable11 = (_provider) => {
49149
+ var isAvailable12 = (_provider) => {
49068
49150
  return true;
49069
49151
  };
49070
49152
  var handOver_default = {
49071
- ...toolInfo11,
49072
- handler: handler11,
49073
- isAvailable: isAvailable11
49153
+ ...toolInfo12,
49154
+ handler: handler12,
49155
+ isAvailable: isAvailable12
49074
49156
  };
49075
49157
  // ../core/src/tools/removeFile.ts
49076
- var toolInfo12 = {
49158
+ var toolInfo13 = {
49077
49159
  name: "remove_file",
49078
49160
  description: "Request to remove a file at the specified path.",
49079
49161
  parameters: [
@@ -49097,7 +49179,7 @@ var toolInfo12 = {
49097
49179
  ],
49098
49180
  permissionLevel: 2 /* Write */
49099
49181
  };
49100
- var handler12 = async (provider, args) => {
49182
+ var handler13 = async (provider, args) => {
49101
49183
  if (!provider.removeFile) {
49102
49184
  return {
49103
49185
  type: "Error" /* Error */,
@@ -49111,16 +49193,16 @@ var handler12 = async (provider, args) => {
49111
49193
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
49112
49194
  };
49113
49195
  };
49114
- var isAvailable12 = (provider) => {
49196
+ var isAvailable13 = (provider) => {
49115
49197
  return !!provider.removeFile;
49116
49198
  };
49117
49199
  var removeFile_default = {
49118
- ...toolInfo12,
49119
- handler: handler12,
49120
- isAvailable: isAvailable12
49200
+ ...toolInfo13,
49201
+ handler: handler13,
49202
+ isAvailable: isAvailable13
49121
49203
  };
49122
49204
  // ../core/src/tools/renameFile.ts
49123
- var toolInfo13 = {
49205
+ var toolInfo14 = {
49124
49206
  name: "rename_file",
49125
49207
  description: "Request to rename a file from source path to target path.",
49126
49208
  parameters: [
@@ -49154,7 +49236,7 @@ var toolInfo13 = {
49154
49236
  ],
49155
49237
  permissionLevel: 2 /* Write */
49156
49238
  };
49157
- var handler13 = async (provider, args) => {
49239
+ var handler14 = async (provider, args) => {
49158
49240
  if (!provider.renameFile) {
49159
49241
  return {
49160
49242
  type: "Error" /* Error */,
@@ -49169,13 +49251,13 @@ var handler13 = async (provider, args) => {
49169
49251
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
49170
49252
  };
49171
49253
  };
49172
- var isAvailable13 = (provider) => {
49254
+ var isAvailable14 = (provider) => {
49173
49255
  return !!provider.renameFile;
49174
49256
  };
49175
49257
  var renameFile_default = {
49176
- ...toolInfo13,
49177
- handler: handler13,
49178
- isAvailable: isAvailable13
49258
+ ...toolInfo14,
49259
+ handler: handler14,
49260
+ isAvailable: isAvailable14
49179
49261
  };
49180
49262
  // ../core/src/getAvailableTools.ts
49181
49263
  var getAvailableTools = ({
@@ -49533,7 +49615,13 @@ ${joined}`;
49533
49615
  };
49534
49616
  var responsePrompts = {
49535
49617
  errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
49536
- requireUseTool: "Error: You MUST use a tool before proceeding using XCM tags. e.g. <tool_tool_name>tool_name</tool_tool_name>",
49618
+ requireUseTool: `Error: No tool use detected. You MUST use a tool before proceeding.
49619
+ e.g. <tool_tool_name>tool_name</tool_tool_name>
49620
+
49621
+ Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
49622
+ Avoid unnecessary text or symbols before or after the tool use.
49623
+ Avoid unnecessary escape characters or special characters.
49624
+ `,
49537
49625
  toolResults: (tool, result) => `<tool_response>
49538
49626
  <tool_name>${tool}</tool_name>
49539
49627
  <tool_result>
@@ -49776,8 +49864,8 @@ ${instance.prompt}`;
49776
49864
  }
49777
49865
  async#invokeTool(name, args) {
49778
49866
  try {
49779
- const handler14 = this.handlers[name]?.handler;
49780
- if (!handler14) {
49867
+ const handler15 = this.handlers[name]?.handler;
49868
+ if (!handler15) {
49781
49869
  return {
49782
49870
  type: "Error" /* Error */,
49783
49871
  message: responsePrompts.errorInvokeTool(name, "Tool not found"),
@@ -49796,7 +49884,7 @@ ${instance.prompt}`;
49796
49884
  if (resp) {
49797
49885
  return resp;
49798
49886
  }
49799
- return await handler14(this.config.provider, args);
49887
+ return await handler15(this.config.provider, args);
49800
49888
  } catch (error) {
49801
49889
  return {
49802
49890
  type: "Error" /* Error */,
@@ -59697,15 +59785,15 @@ function useKeypress(userHandler) {
59697
59785
  signal.current = userHandler;
59698
59786
  useEffect((rl) => {
59699
59787
  let ignore = false;
59700
- const handler14 = withUpdates((_input, event) => {
59788
+ const handler15 = withUpdates((_input, event) => {
59701
59789
  if (ignore)
59702
59790
  return;
59703
59791
  signal.current(event, rl);
59704
59792
  });
59705
- rl.input.on("keypress", handler14);
59793
+ rl.input.on("keypress", handler15);
59706
59794
  return () => {
59707
59795
  ignore = true;
59708
- rl.input.removeListener("keypress", handler14);
59796
+ rl.input.removeListener("keypress", handler15);
59709
59797
  };
59710
59798
  }, []);
59711
59799
  }
@@ -59887,16 +59975,16 @@ class Emitter {
59887
59975
 
59888
59976
  class SignalExitBase {
59889
59977
  }
59890
- var signalExitWrap = (handler14) => {
59978
+ var signalExitWrap = (handler15) => {
59891
59979
  return {
59892
59980
  onExit(cb, opts) {
59893
- return handler14.onExit(cb, opts);
59981
+ return handler15.onExit(cb, opts);
59894
59982
  },
59895
59983
  load() {
59896
- return handler14.load();
59984
+ return handler15.load();
59897
59985
  },
59898
59986
  unload() {
59899
- return handler14.unload();
59987
+ return handler15.unload();
59900
59988
  }
59901
59989
  };
59902
59990
  };
@@ -60754,6 +60842,20 @@ var getProvider = (agentName, config2, options = {}) => {
60754
60842
  },
60755
60843
  attemptCompletion: async (result) => {
60756
60844
  return;
60845
+ },
60846
+ fetchUrl: async (url) => {
60847
+ const isRaw = url.startsWith("https://raw.githubusercontent.com/");
60848
+ const urlToFetch = isRaw ? url : `https://r.jina.ai/${url}`;
60849
+ try {
60850
+ const response = await fetch(urlToFetch);
60851
+ if (!response.ok) {
60852
+ throw new Error(`HTTP error! status: ${response.status}`);
60853
+ }
60854
+ return await response.text();
60855
+ } catch (error) {
60856
+ console.error("Error fetching URL:", error);
60857
+ throw error;
60858
+ }
60757
60859
  }
60758
60860
  };
60759
60861
  if (checkRipgrep()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.8.22",
3
+ "version": "0.8.23",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@inquirer/prompts": "^7.2.3",
21
- "@polka-codes/core": "0.8.10",
22
- "@polka-codes/cli-shared": "0.8.10",
21
+ "@polka-codes/core": "0.8.22",
22
+ "@polka-codes/cli-shared": "0.8.22",
23
23
  "commander": "^13.0.0",
24
24
  "dotenv": "^16.4.7",
25
25
  "lodash": "^4.17.21",