@polka-codes/cli-shared 0.8.21 → 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 +211 -68
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -36777,6 +36777,7 @@ __export(exports_allTools, {
36777
36777
  readFile: () => readFile_default,
36778
36778
  listFiles: () => listFiles_default,
36779
36779
  handOver: () => handOver_default,
36780
+ fetchUrl: () => fetchUrl_default,
36780
36781
  executeCommand: () => executeCommand_default,
36781
36782
  delegate: () => delegate_default,
36782
36783
  attemptCompletion: () => attemptCompletion_default,
@@ -37235,8 +37236,89 @@ var executeCommand_default = {
37235
37236
  handler: handler4,
37236
37237
  isAvailable: isAvailable4
37237
37238
  };
37238
- // ../core/src/tools/listFiles.ts
37239
+ // ../core/src/tools/fetchUrl.ts
37239
37240
  var toolInfo5 = {
37241
+ name: "fetch_url",
37242
+ 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.",
37243
+ parameters: [
37244
+ {
37245
+ name: "url",
37246
+ description: "One or more URLs to fetch, separated by commas if multiple.",
37247
+ required: true
37248
+ }
37249
+ ],
37250
+ examples: [
37251
+ {
37252
+ description: "Fetch a single webpage",
37253
+ parameters: [
37254
+ {
37255
+ name: "url",
37256
+ value: "https://example.com"
37257
+ }
37258
+ ]
37259
+ },
37260
+ {
37261
+ description: "Fetch multiple webpages",
37262
+ parameters: [
37263
+ {
37264
+ name: "url",
37265
+ value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
37266
+ }
37267
+ ]
37268
+ },
37269
+ {
37270
+ description: "Fetch a raw file from GitHub",
37271
+ parameters: [
37272
+ {
37273
+ name: "url",
37274
+ value: "https://raw.githubusercontent.com/user/repo/main/README.md"
37275
+ }
37276
+ ]
37277
+ }
37278
+ ],
37279
+ permissionLevel: 1 /* Read */
37280
+ };
37281
+ var handler5 = async (provider, args) => {
37282
+ if (!provider.fetchUrl) {
37283
+ return {
37284
+ type: "Error" /* Error */,
37285
+ message: "Not possible to fetch url. Abort."
37286
+ };
37287
+ }
37288
+ const urls = getStringArray(args, "url");
37289
+ if (urls.length === 0) {
37290
+ return {
37291
+ type: "Error" /* Error */,
37292
+ message: "No URLs provided. Please provide at least one URL to fetch."
37293
+ };
37294
+ }
37295
+ const results = [];
37296
+ for (const url of urls) {
37297
+ try {
37298
+ const content = provider.fetchUrl(url).then((res) => `<fetch_url_content url="${url}">${res}</fetch_url_content>`);
37299
+ results.push(content);
37300
+ } catch (error) {
37301
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
37302
+ results.push(Promise.resolve(`<fetch_url_error url="${url}">${errorMessage}</fetch_url_error>`));
37303
+ }
37304
+ }
37305
+ const resolvedResults = await Promise.all(results);
37306
+ return {
37307
+ type: "Reply" /* Reply */,
37308
+ message: resolvedResults.join(`
37309
+ `)
37310
+ };
37311
+ };
37312
+ var isAvailable5 = (provider) => {
37313
+ return typeof provider.fetchUrl === "function";
37314
+ };
37315
+ var fetchUrl_default = {
37316
+ ...toolInfo5,
37317
+ handler: handler5,
37318
+ isAvailable: isAvailable5
37319
+ };
37320
+ // ../core/src/tools/listFiles.ts
37321
+ var toolInfo6 = {
37240
37322
  name: "list_files",
37241
37323
  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.",
37242
37324
  parameters: [
@@ -37276,7 +37358,7 @@ var toolInfo5 = {
37276
37358
  ],
37277
37359
  permissionLevel: 1 /* Read */
37278
37360
  };
37279
- var handler5 = async (provider, args) => {
37361
+ var handler6 = async (provider, args) => {
37280
37362
  if (!provider.listFiles) {
37281
37363
  return {
37282
37364
  type: "Error" /* Error */,
@@ -37297,16 +37379,16 @@ ${files.join(`
37297
37379
  <list_files_truncated>${limitReached}</list_files_truncated>`
37298
37380
  };
37299
37381
  };
37300
- var isAvailable5 = (provider) => {
37382
+ var isAvailable6 = (provider) => {
37301
37383
  return !!provider.listFiles;
37302
37384
  };
37303
37385
  var listFiles_default = {
37304
- ...toolInfo5,
37305
- handler: handler5,
37306
- isAvailable: isAvailable5
37386
+ ...toolInfo6,
37387
+ handler: handler6,
37388
+ isAvailable: isAvailable6
37307
37389
  };
37308
37390
  // ../core/src/tools/readFile.ts
37309
- var toolInfo6 = {
37391
+ var toolInfo7 = {
37310
37392
  name: "read_file",
37311
37393
  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.",
37312
37394
  parameters: [
@@ -37339,7 +37421,7 @@ var toolInfo6 = {
37339
37421
  ],
37340
37422
  permissionLevel: 1 /* Read */
37341
37423
  };
37342
- var handler6 = async (provider, args) => {
37424
+ var handler7 = async (provider, args) => {
37343
37425
  if (!provider.readFile) {
37344
37426
  return {
37345
37427
  type: "Error" /* Error */,
@@ -37367,16 +37449,16 @@ var handler6 = async (provider, args) => {
37367
37449
  `)
37368
37450
  };
37369
37451
  };
37370
- var isAvailable6 = (provider) => {
37452
+ var isAvailable7 = (provider) => {
37371
37453
  return !!provider.readFile;
37372
37454
  };
37373
37455
  var readFile_default = {
37374
- ...toolInfo6,
37375
- handler: handler6,
37376
- isAvailable: isAvailable6
37456
+ ...toolInfo7,
37457
+ handler: handler7,
37458
+ isAvailable: isAvailable7
37377
37459
  };
37378
37460
  // ../core/src/tools/replaceInFile.ts
37379
- var toolInfo7 = {
37461
+ var toolInfo8 = {
37380
37462
  name: "replace_in_file",
37381
37463
  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.",
37382
37464
  parameters: [
@@ -37528,7 +37610,7 @@ function oldFeature() {
37528
37610
  ],
37529
37611
  permissionLevel: 2 /* Write */
37530
37612
  };
37531
- var handler7 = async (provider, args) => {
37613
+ var handler8 = async (provider, args) => {
37532
37614
  if (!provider.readFile || !provider.writeFile) {
37533
37615
  return {
37534
37616
  type: "Error" /* Error */,
@@ -37551,16 +37633,16 @@ var handler7 = async (provider, args) => {
37551
37633
  message: `<replace_in_file_path>${path}</replace_in_file_path>`
37552
37634
  };
37553
37635
  };
37554
- var isAvailable7 = (provider) => {
37636
+ var isAvailable8 = (provider) => {
37555
37637
  return !!provider.readFile && !!provider.writeFile;
37556
37638
  };
37557
37639
  var replaceInFile_default = {
37558
- ...toolInfo7,
37559
- handler: handler7,
37560
- isAvailable: isAvailable7
37640
+ ...toolInfo8,
37641
+ handler: handler8,
37642
+ isAvailable: isAvailable8
37561
37643
  };
37562
37644
  // ../core/src/tools/searchFiles.ts
37563
- var toolInfo8 = {
37645
+ var toolInfo9 = {
37564
37646
  name: "search_files",
37565
37647
  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.",
37566
37648
  parameters: [
@@ -37604,7 +37686,7 @@ var toolInfo8 = {
37604
37686
  ],
37605
37687
  permissionLevel: 1 /* Read */
37606
37688
  };
37607
- var handler8 = async (provider, args) => {
37689
+ var handler9 = async (provider, args) => {
37608
37690
  if (!provider.searchFiles) {
37609
37691
  return {
37610
37692
  type: "Error" /* Error */,
@@ -37627,18 +37709,59 @@ ${files.join(`
37627
37709
  `
37628
37710
  };
37629
37711
  };
37630
- var isAvailable8 = (provider) => {
37712
+ var isAvailable9 = (provider) => {
37631
37713
  return !!provider.searchFiles;
37632
37714
  };
37633
37715
  var searchFiles_default = {
37634
- ...toolInfo8,
37635
- handler: handler8,
37636
- isAvailable: isAvailable8
37716
+ ...toolInfo9,
37717
+ handler: handler9,
37718
+ isAvailable: isAvailable9
37637
37719
  };
37638
37720
  // ../core/src/tools/updateKnowledge.ts
37639
37721
  var import_yaml = __toESM(require_dist(), 1);
37640
- import { join } from "node:path";
37641
- var toolInfo9 = {
37722
+
37723
+ // ../core/src/path.ts
37724
+ function normalize(path) {
37725
+ const isAbsolute = path.startsWith("/");
37726
+ const segments = path.split("/").filter(Boolean);
37727
+ const stack = [];
37728
+ for (const seg of segments) {
37729
+ if (seg === ".")
37730
+ continue;
37731
+ if (seg === "..") {
37732
+ if (stack.length && stack[stack.length - 1] !== "..") {
37733
+ stack.pop();
37734
+ } else if (!isAbsolute) {
37735
+ stack.push("..");
37736
+ }
37737
+ } else {
37738
+ stack.push(seg);
37739
+ }
37740
+ }
37741
+ let result = stack.join("/");
37742
+ if (!result && !isAbsolute)
37743
+ return ".";
37744
+ if (result && path.endsWith("/"))
37745
+ result += "/";
37746
+ return (isAbsolute ? "/" : "") + result;
37747
+ }
37748
+ function join(...parts) {
37749
+ if (parts.length === 0)
37750
+ return ".";
37751
+ let combined = "";
37752
+ for (const p2 of parts) {
37753
+ if (typeof p2 !== "string") {
37754
+ throw new TypeError("Arguments to join must be strings");
37755
+ }
37756
+ if (p2) {
37757
+ combined = combined ? `${combined}/${p2}` : p2;
37758
+ }
37759
+ }
37760
+ return normalize(combined);
37761
+ }
37762
+
37763
+ // ../core/src/tools/updateKnowledge.ts
37764
+ var toolInfo10 = {
37642
37765
  name: "update_knowledge",
37643
37766
  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.",
37644
37767
  parameters: [
@@ -37815,7 +37938,7 @@ function deepMerge(target, source) {
37815
37938
  }
37816
37939
  return output;
37817
37940
  }
37818
- var handler9 = async (provider, args) => {
37941
+ var handler10 = async (provider, args) => {
37819
37942
  if (!provider.readFile || !provider.writeFile) {
37820
37943
  return {
37821
37944
  type: "Error" /* Error */,
@@ -37887,16 +38010,16 @@ var handler9 = async (provider, args) => {
37887
38010
  };
37888
38011
  }
37889
38012
  };
37890
- var isAvailable9 = (provider) => {
38013
+ var isAvailable10 = (provider) => {
37891
38014
  return !!provider.readFile && !!provider.writeFile;
37892
38015
  };
37893
38016
  var updateKnowledge_default = {
37894
- ...toolInfo9,
37895
- handler: handler9,
37896
- isAvailable: isAvailable9
38017
+ ...toolInfo10,
38018
+ handler: handler10,
38019
+ isAvailable: isAvailable10
37897
38020
  };
37898
38021
  // ../core/src/tools/writeToFile.ts
37899
- var toolInfo10 = {
38022
+ var toolInfo11 = {
37900
38023
  name: "write_to_file",
37901
38024
  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;`.",
37902
38025
  parameters: [
@@ -37941,7 +38064,7 @@ export default App;
37941
38064
  ],
37942
38065
  permissionLevel: 2 /* Write */
37943
38066
  };
37944
- var handler10 = async (provider, args) => {
38067
+ var handler11 = async (provider, args) => {
37945
38068
  if (!provider.writeFile) {
37946
38069
  return {
37947
38070
  type: "Error" /* Error */,
@@ -37956,16 +38079,16 @@ var handler10 = async (provider, args) => {
37956
38079
  message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
37957
38080
  };
37958
38081
  };
37959
- var isAvailable10 = (provider) => {
38082
+ var isAvailable11 = (provider) => {
37960
38083
  return !!provider.writeFile;
37961
38084
  };
37962
38085
  var writeToFile_default = {
37963
- ...toolInfo10,
37964
- handler: handler10,
37965
- isAvailable: isAvailable10
38086
+ ...toolInfo11,
38087
+ handler: handler11,
38088
+ isAvailable: isAvailable11
37966
38089
  };
37967
38090
  // ../core/src/tools/handOver.ts
37968
- var toolInfo11 = {
38091
+ var toolInfo12 = {
37969
38092
  name: "hand_over",
37970
38093
  description: "Hand over the current task to another agent to complete. This tool MUST NOT to be used with any other tool.",
37971
38094
  parameters: [
@@ -38019,7 +38142,7 @@ var toolInfo11 = {
38019
38142
  ],
38020
38143
  permissionLevel: 0 /* None */
38021
38144
  };
38022
- var handler11 = async (_provider, args) => {
38145
+ var handler12 = async (_provider, args) => {
38023
38146
  const agentName = getString(args, "agent_name");
38024
38147
  const task = getString(args, "task");
38025
38148
  const context = getString(args, "context", undefined);
@@ -38032,16 +38155,16 @@ var handler11 = async (_provider, args) => {
38032
38155
  files
38033
38156
  };
38034
38157
  };
38035
- var isAvailable11 = (_provider) => {
38158
+ var isAvailable12 = (_provider) => {
38036
38159
  return true;
38037
38160
  };
38038
38161
  var handOver_default = {
38039
- ...toolInfo11,
38040
- handler: handler11,
38041
- isAvailable: isAvailable11
38162
+ ...toolInfo12,
38163
+ handler: handler12,
38164
+ isAvailable: isAvailable12
38042
38165
  };
38043
38166
  // ../core/src/tools/removeFile.ts
38044
- var toolInfo12 = {
38167
+ var toolInfo13 = {
38045
38168
  name: "remove_file",
38046
38169
  description: "Request to remove a file at the specified path.",
38047
38170
  parameters: [
@@ -38065,7 +38188,7 @@ var toolInfo12 = {
38065
38188
  ],
38066
38189
  permissionLevel: 2 /* Write */
38067
38190
  };
38068
- var handler12 = async (provider, args) => {
38191
+ var handler13 = async (provider, args) => {
38069
38192
  if (!provider.removeFile) {
38070
38193
  return {
38071
38194
  type: "Error" /* Error */,
@@ -38079,16 +38202,16 @@ var handler12 = async (provider, args) => {
38079
38202
  message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
38080
38203
  };
38081
38204
  };
38082
- var isAvailable12 = (provider) => {
38205
+ var isAvailable13 = (provider) => {
38083
38206
  return !!provider.removeFile;
38084
38207
  };
38085
38208
  var removeFile_default = {
38086
- ...toolInfo12,
38087
- handler: handler12,
38088
- isAvailable: isAvailable12
38209
+ ...toolInfo13,
38210
+ handler: handler13,
38211
+ isAvailable: isAvailable13
38089
38212
  };
38090
38213
  // ../core/src/tools/renameFile.ts
38091
- var toolInfo13 = {
38214
+ var toolInfo14 = {
38092
38215
  name: "rename_file",
38093
38216
  description: "Request to rename a file from source path to target path.",
38094
38217
  parameters: [
@@ -38122,7 +38245,7 @@ var toolInfo13 = {
38122
38245
  ],
38123
38246
  permissionLevel: 2 /* Write */
38124
38247
  };
38125
- var handler13 = async (provider, args) => {
38248
+ var handler14 = async (provider, args) => {
38126
38249
  if (!provider.renameFile) {
38127
38250
  return {
38128
38251
  type: "Error" /* Error */,
@@ -38137,13 +38260,13 @@ var handler13 = async (provider, args) => {
38137
38260
  message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
38138
38261
  };
38139
38262
  };
38140
- var isAvailable13 = (provider) => {
38263
+ var isAvailable14 = (provider) => {
38141
38264
  return !!provider.renameFile;
38142
38265
  };
38143
38266
  var renameFile_default = {
38144
- ...toolInfo13,
38145
- handler: handler13,
38146
- isAvailable: isAvailable13
38267
+ ...toolInfo14,
38268
+ handler: handler14,
38269
+ isAvailable: isAvailable14
38147
38270
  };
38148
38271
  // ../core/src/getAvailableTools.ts
38149
38272
  var getAvailableTools = ({
@@ -38501,7 +38624,13 @@ ${joined}`;
38501
38624
  };
38502
38625
  var responsePrompts = {
38503
38626
  errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
38504
- requireUseTool: "Error: You MUST use a tool before proceeding using XCM tags. e.g. <tool_tool_name>tool_name</tool_tool_name>",
38627
+ requireUseTool: `Error: No tool use detected. You MUST use a tool before proceeding.
38628
+ e.g. <tool_tool_name>tool_name</tool_tool_name>
38629
+
38630
+ Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
38631
+ Avoid unnecessary text or symbols before or after the tool use.
38632
+ Avoid unnecessary escape characters or special characters.
38633
+ `,
38505
38634
  toolResults: (tool, result) => `<tool_response>
38506
38635
  <tool_name>${tool}</tool_name>
38507
38636
  <tool_result>
@@ -38744,8 +38873,8 @@ ${instance.prompt}`;
38744
38873
  }
38745
38874
  async#invokeTool(name, args) {
38746
38875
  try {
38747
- const handler14 = this.handlers[name]?.handler;
38748
- if (!handler14) {
38876
+ const handler15 = this.handlers[name]?.handler;
38877
+ if (!handler15) {
38749
38878
  return {
38750
38879
  type: "Error" /* Error */,
38751
38880
  message: responsePrompts.errorInvokeTool(name, "Tool not found"),
@@ -38764,7 +38893,7 @@ ${instance.prompt}`;
38764
38893
  if (resp) {
38765
38894
  return resp;
38766
38895
  }
38767
- return await handler14(this.config.provider, args);
38896
+ return await handler15(this.config.provider, args);
38768
38897
  } catch (error) {
38769
38898
  return {
38770
38899
  type: "Error" /* Error */,
@@ -47411,7 +47540,7 @@ var readLocalConfig = (path) => {
47411
47540
  var import_ignore2 = __toESM(require_ignore(), 1);
47412
47541
  import { spawn as spawn2 } from "node:child_process";
47413
47542
  import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
47414
- import { dirname } from "node:path";
47543
+ import { dirname as dirname2 } from "node:path";
47415
47544
 
47416
47545
  // ../../node_modules/@inquirer/core/dist/esm/lib/key.js
47417
47546
  var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
@@ -47973,15 +48102,15 @@ function useKeypress(userHandler) {
47973
48102
  signal.current = userHandler;
47974
48103
  useEffect((rl) => {
47975
48104
  let ignore = false;
47976
- const handler14 = withUpdates((_input, event) => {
48105
+ const handler15 = withUpdates((_input, event) => {
47977
48106
  if (ignore)
47978
48107
  return;
47979
48108
  signal.current(event, rl);
47980
48109
  });
47981
- rl.input.on("keypress", handler14);
48110
+ rl.input.on("keypress", handler15);
47982
48111
  return () => {
47983
48112
  ignore = true;
47984
- rl.input.removeListener("keypress", handler14);
48113
+ rl.input.removeListener("keypress", handler15);
47985
48114
  };
47986
48115
  }, []);
47987
48116
  }
@@ -48163,16 +48292,16 @@ class Emitter {
48163
48292
 
48164
48293
  class SignalExitBase {
48165
48294
  }
48166
- var signalExitWrap = (handler14) => {
48295
+ var signalExitWrap = (handler15) => {
48167
48296
  return {
48168
48297
  onExit(cb, opts) {
48169
- return handler14.onExit(cb, opts);
48298
+ return handler15.onExit(cb, opts);
48170
48299
  },
48171
48300
  load() {
48172
- return handler14.load();
48301
+ return handler15.load();
48173
48302
  },
48174
48303
  unload() {
48175
- return handler14.unload();
48304
+ return handler15.unload();
48176
48305
  }
48177
48306
  };
48178
48307
  };
@@ -48867,7 +48996,7 @@ var getProvider = (agentName, config2, options = {}) => {
48867
48996
  if (ig.ignores(path)) {
48868
48997
  throw new Error(`Not allow to access file ${path}`);
48869
48998
  }
48870
- await mkdir(dirname(path), { recursive: true });
48999
+ await mkdir(dirname2(path), { recursive: true });
48871
49000
  return await writeFile(path, content, "utf8");
48872
49001
  },
48873
49002
  removeFile: async (path) => {
@@ -48938,6 +49067,20 @@ var getProvider = (agentName, config2, options = {}) => {
48938
49067
  },
48939
49068
  attemptCompletion: async (result) => {
48940
49069
  return;
49070
+ },
49071
+ fetchUrl: async (url) => {
49072
+ const isRaw = url.startsWith("https://raw.githubusercontent.com/");
49073
+ const urlToFetch = isRaw ? url : `https://r.jina.ai/${url}`;
49074
+ try {
49075
+ const response = await fetch(urlToFetch);
49076
+ if (!response.ok) {
49077
+ throw new Error(`HTTP error! status: ${response.status}`);
49078
+ }
49079
+ return await response.text();
49080
+ } catch (error) {
49081
+ console.error("Error fetching URL:", error);
49082
+ throw error;
49083
+ }
48941
49084
  }
48942
49085
  };
48943
49086
  if (checkRipgrep()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.8.21",
3
+ "version": "0.8.23",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "build": "bun build src/index.ts --outdir dist --target node"
16
16
  },
17
17
  "dependencies": {
18
- "@polka-codes/core": "0.8.10",
18
+ "@polka-codes/core": "0.8.22",
19
19
  "ignore": "^7.0.3",
20
20
  "lodash": "^4.17.21",
21
21
  "yaml": "^2.7.0",