@polka-codes/cli-shared 0.9.47 → 0.9.48

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 +217 -183
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -30660,36 +30660,12 @@ var configSchema = exports_external.object({
30660
30660
  rules: exports_external.array(exports_external.string()).optional().or(exports_external.string()).optional(),
30661
30661
  excludeFiles: exports_external.array(exports_external.string()).optional()
30662
30662
  }).strict();
30663
- // ../core/src/tools/appendMemory.ts
30664
- var toolInfo = {
30665
- name: "appendMemory",
30666
- description: "Appends content to a memory topic.",
30667
- parameters: exports_external.object({
30668
- topic: exports_external.string().nullish().describe('The topic to append to in memory. Defaults to ":default:".'),
30669
- content: exports_external.string().describe("The content to append.")
30670
- })
30671
- };
30672
- var handler = async (provider, args) => {
30673
- const { topic, content } = toolInfo.parameters.parse(args);
30674
- await provider.appendMemory(topic ?? undefined, content);
30675
- return {
30676
- type: "Reply" /* Reply */,
30677
- message: {
30678
- type: "text",
30679
- value: `Content appended to memory topic '${topic || ""}'.`
30680
- }
30681
- };
30682
- };
30683
- var appendMemory_default = {
30684
- ...toolInfo,
30685
- handler
30686
- };
30687
30663
  // ../core/src/tools/askFollowupQuestion.ts
30688
30664
  var questionObject = exports_external.object({
30689
30665
  prompt: exports_external.string().describe("The text of the question.").meta({ usageValue: "question text here" }),
30690
30666
  options: exports_external.array(exports_external.string()).default([]).describe("Ordered list of suggested answers (omit if none).").meta({ usageValue: "suggested answer here" })
30691
30667
  });
30692
- var toolInfo2 = {
30668
+ var toolInfo = {
30693
30669
  name: "askFollowupQuestion",
30694
30670
  description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
30695
30671
  parameters: exports_external.object({
@@ -30739,7 +30715,7 @@ var toolInfo2 = {
30739
30715
  ]
30740
30716
  })
30741
30717
  };
30742
- var handler2 = async (provider, args) => {
30718
+ var handler = async (provider, args) => {
30743
30719
  if (!provider.askFollowupQuestion) {
30744
30720
  return {
30745
30721
  type: "Error" /* Error */,
@@ -30749,7 +30725,7 @@ var handler2 = async (provider, args) => {
30749
30725
  }
30750
30726
  };
30751
30727
  }
30752
- const { questions } = toolInfo2.parameters.parse(args);
30728
+ const { questions } = toolInfo.parameters.parse(args);
30753
30729
  if (questions.length === 0) {
30754
30730
  return {
30755
30731
  type: "Error" /* Error */,
@@ -30777,11 +30753,11 @@ ${answer}
30777
30753
  };
30778
30754
  };
30779
30755
  var askFollowupQuestion_default = {
30780
- ...toolInfo2,
30781
- handler: handler2
30756
+ ...toolInfo,
30757
+ handler
30782
30758
  };
30783
30759
  // ../core/src/tools/executeCommand.ts
30784
- var toolInfo3 = {
30760
+ var toolInfo2 = {
30785
30761
  name: "executeCommand",
30786
30762
  description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. **IMPORTANT**: After an `execute_command` call, you MUST stop and NOT allowed to make further tool calls in the same message.",
30787
30763
  parameters: exports_external.object({
@@ -30808,7 +30784,7 @@ var toolInfo3 = {
30808
30784
  ]
30809
30785
  })
30810
30786
  };
30811
- var handler3 = async (provider, args) => {
30787
+ var handler2 = async (provider, args) => {
30812
30788
  if (!provider.executeCommand) {
30813
30789
  return {
30814
30790
  type: "Error" /* Error */,
@@ -30818,7 +30794,7 @@ var handler3 = async (provider, args) => {
30818
30794
  }
30819
30795
  };
30820
30796
  }
30821
- const { command, requiresApproval } = toolInfo3.parameters.parse(args);
30797
+ const { command, requiresApproval } = toolInfo2.parameters.parse(args);
30822
30798
  try {
30823
30799
  const result = await provider.executeCommand(command, requiresApproval);
30824
30800
  let message = `<command>${command}</command>
@@ -30865,11 +30841,11 @@ ${result.stderr}
30865
30841
  }
30866
30842
  };
30867
30843
  var executeCommand_default = {
30868
- ...toolInfo3,
30869
- handler: handler3
30844
+ ...toolInfo2,
30845
+ handler: handler2
30870
30846
  };
30871
30847
  // ../core/src/tools/fetchUrl.ts
30872
- var toolInfo4 = {
30848
+ var toolInfo3 = {
30873
30849
  name: "fetchUrl",
30874
30850
  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.",
30875
30851
  parameters: exports_external.object({
@@ -30902,7 +30878,7 @@ var toolInfo4 = {
30902
30878
  ]
30903
30879
  })
30904
30880
  };
30905
- var handler4 = async (provider, args) => {
30881
+ var handler3 = async (provider, args) => {
30906
30882
  if (!provider.fetchUrl) {
30907
30883
  return {
30908
30884
  type: "Error" /* Error */,
@@ -30912,7 +30888,7 @@ var handler4 = async (provider, args) => {
30912
30888
  }
30913
30889
  };
30914
30890
  }
30915
- const { url: urls } = toolInfo4.parameters.parse(args);
30891
+ const { url: urls } = toolInfo3.parameters.parse(args);
30916
30892
  if (urls.length === 0) {
30917
30893
  return {
30918
30894
  type: "Error" /* Error */,
@@ -30943,11 +30919,11 @@ var handler4 = async (provider, args) => {
30943
30919
  };
30944
30920
  };
30945
30921
  var fetchUrl_default = {
30946
- ...toolInfo4,
30947
- handler: handler4
30922
+ ...toolInfo3,
30923
+ handler: handler3
30948
30924
  };
30949
30925
  // ../core/src/tools/listFiles.ts
30950
- var toolInfo5 = {
30926
+ var toolInfo4 = {
30951
30927
  name: "listFiles",
30952
30928
  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.",
30953
30929
  parameters: exports_external.object({
@@ -30985,7 +30961,7 @@ var toolInfo5 = {
30985
30961
  ]
30986
30962
  })
30987
30963
  };
30988
- var handler5 = async (provider, args) => {
30964
+ var handler4 = async (provider, args) => {
30989
30965
  if (!provider.listFiles) {
30990
30966
  return {
30991
30967
  type: "Error" /* Error */,
@@ -30995,7 +30971,7 @@ var handler5 = async (provider, args) => {
30995
30971
  }
30996
30972
  };
30997
30973
  }
30998
- const { path, maxCount, recursive, includeIgnored } = toolInfo5.parameters.parse(args);
30974
+ const { path, maxCount, recursive, includeIgnored } = toolInfo4.parameters.parse(args);
30999
30975
  const [files, limitReached] = await provider.listFiles(path, recursive, maxCount, includeIgnored);
31000
30976
  return {
31001
30977
  type: "Reply" /* Reply */,
@@ -31011,16 +30987,16 @@ ${files.join(`
31011
30987
  };
31012
30988
  };
31013
30989
  var listFiles_default = {
31014
- ...toolInfo5,
31015
- handler: handler5
30990
+ ...toolInfo4,
30991
+ handler: handler4
31016
30992
  };
31017
30993
  // ../core/src/tools/listMemoryTopics.ts
31018
- var toolInfo6 = {
30994
+ var toolInfo5 = {
31019
30995
  name: "listMemoryTopics",
31020
30996
  description: "Lists all topics in memory.",
31021
30997
  parameters: exports_external.object({})
31022
30998
  };
31023
- var handler6 = async (provider, _args) => {
30999
+ var handler5 = async (provider, _args) => {
31024
31000
  const topics = await provider.listMemoryTopics();
31025
31001
  if (!topics.length) {
31026
31002
  return { type: "Reply" /* Reply */, message: { type: "text", value: "No topics found." } };
@@ -31036,18 +31012,18 @@ ${topics.join(`
31036
31012
  };
31037
31013
  };
31038
31014
  var listMemoryTopics_default = {
31039
- ...toolInfo6,
31040
- handler: handler6
31015
+ ...toolInfo5,
31016
+ handler: handler5
31041
31017
  };
31042
31018
  // ../core/src/tools/readBinaryFile.ts
31043
- var toolInfo7 = {
31019
+ var toolInfo6 = {
31044
31020
  name: "readBinaryFile",
31045
31021
  description: "Read a binary file from a URL or local path. Use file:// prefix to access local files. This can be used to access non-text files such as PDFs or images.",
31046
31022
  parameters: exports_external.object({
31047
31023
  url: exports_external.string().describe("The URL or local path of the file to read.")
31048
31024
  })
31049
31025
  };
31050
- var handler7 = async (provider, args) => {
31026
+ var handler6 = async (provider, args) => {
31051
31027
  if (!provider.readBinaryFile) {
31052
31028
  return {
31053
31029
  type: "Error" /* Error */,
@@ -31057,7 +31033,7 @@ var handler7 = async (provider, args) => {
31057
31033
  }
31058
31034
  };
31059
31035
  }
31060
- const { url: url2 } = toolInfo7.parameters.parse(args);
31036
+ const { url: url2 } = toolInfo6.parameters.parse(args);
31061
31037
  try {
31062
31038
  const filePart = await provider.readBinaryFile(url2);
31063
31039
  return {
@@ -31086,11 +31062,11 @@ var handler7 = async (provider, args) => {
31086
31062
  }
31087
31063
  };
31088
31064
  var readBinaryFile_default = {
31089
- ...toolInfo7,
31090
- handler: handler7
31065
+ ...toolInfo6,
31066
+ handler: handler6
31091
31067
  };
31092
31068
  // ../core/src/tools/readFile.ts
31093
- var toolInfo8 = {
31069
+ var toolInfo7 = {
31094
31070
  name: "readFile",
31095
31071
  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.",
31096
31072
  parameters: exports_external.object({
@@ -31127,7 +31103,7 @@ var toolInfo8 = {
31127
31103
  ]
31128
31104
  })
31129
31105
  };
31130
- var handler8 = async (provider, args) => {
31106
+ var handler7 = async (provider, args) => {
31131
31107
  if (!provider.readFile) {
31132
31108
  return {
31133
31109
  type: "Error" /* Error */,
@@ -31137,7 +31113,7 @@ var handler8 = async (provider, args) => {
31137
31113
  }
31138
31114
  };
31139
31115
  }
31140
- const { path: paths, includeIgnored } = toolInfo8.parameters.parse(args);
31116
+ const { path: paths, includeIgnored } = toolInfo7.parameters.parse(args);
31141
31117
  const resp = [];
31142
31118
  for (const path of paths) {
31143
31119
  const fileContent = await provider.readFile(path, includeIgnored);
@@ -31162,19 +31138,19 @@ var handler8 = async (provider, args) => {
31162
31138
  };
31163
31139
  };
31164
31140
  var readFile_default = {
31165
- ...toolInfo8,
31166
- handler: handler8
31141
+ ...toolInfo7,
31142
+ handler: handler7
31167
31143
  };
31168
31144
  // ../core/src/tools/readMemory.ts
31169
- var toolInfo9 = {
31145
+ var toolInfo8 = {
31170
31146
  name: "readMemory",
31171
31147
  description: "Reads content from a memory topic.",
31172
31148
  parameters: exports_external.object({
31173
31149
  topic: exports_external.string().optional().describe('The topic to read from memory. Defaults to ":default:".')
31174
31150
  })
31175
31151
  };
31176
- var handler9 = async (provider, args) => {
31177
- const { topic } = toolInfo9.parameters.parse(args);
31152
+ var handler8 = async (provider, args) => {
31153
+ const { topic } = toolInfo8.parameters.parse(args);
31178
31154
  const content = await provider.readMemory(topic);
31179
31155
  if (content) {
31180
31156
  return {
@@ -31196,11 +31172,11 @@ ${content}
31196
31172
  };
31197
31173
  };
31198
31174
  var readMemory_default = {
31199
- ...toolInfo9,
31200
- handler: handler9
31175
+ ...toolInfo8,
31176
+ handler: handler8
31201
31177
  };
31202
31178
  // ../core/src/tools/removeFile.ts
31203
- var toolInfo10 = {
31179
+ var toolInfo9 = {
31204
31180
  name: "removeFile",
31205
31181
  description: "Request to remove a file at the specified path.",
31206
31182
  parameters: exports_external.object({
@@ -31216,7 +31192,7 @@ var toolInfo10 = {
31216
31192
  ]
31217
31193
  })
31218
31194
  };
31219
- var handler10 = async (provider, args) => {
31195
+ var handler9 = async (provider, args) => {
31220
31196
  if (!provider.removeFile) {
31221
31197
  return {
31222
31198
  type: "Error" /* Error */,
@@ -31226,7 +31202,7 @@ var handler10 = async (provider, args) => {
31226
31202
  }
31227
31203
  };
31228
31204
  }
31229
- const parsed = toolInfo10.parameters.safeParse(args);
31205
+ const parsed = toolInfo9.parameters.safeParse(args);
31230
31206
  if (!parsed.success) {
31231
31207
  return {
31232
31208
  type: "Error" /* Error */,
@@ -31247,34 +31223,11 @@ var handler10 = async (provider, args) => {
31247
31223
  };
31248
31224
  };
31249
31225
  var removeFile_default = {
31250
- ...toolInfo10,
31251
- handler: handler10
31252
- };
31253
- // ../core/src/tools/removeMemory.ts
31254
- var toolInfo11 = {
31255
- name: "removeMemory",
31256
- description: "Removes a topic from memory.",
31257
- parameters: exports_external.object({
31258
- topic: exports_external.string().optional().describe('The topic to remove from memory. Defaults to ":default:".')
31259
- })
31260
- };
31261
- var handler11 = async (provider, args) => {
31262
- const { topic } = toolInfo11.parameters.parse(args);
31263
- await provider.removeMemory(topic);
31264
- return {
31265
- type: "Reply" /* Reply */,
31266
- message: {
31267
- type: "text",
31268
- value: `Memory topic '${topic || ""}' removed.`
31269
- }
31270
- };
31271
- };
31272
- var removeMemory_default = {
31273
- ...toolInfo11,
31274
- handler: handler11
31226
+ ...toolInfo9,
31227
+ handler: handler9
31275
31228
  };
31276
31229
  // ../core/src/tools/renameFile.ts
31277
- var toolInfo12 = {
31230
+ var toolInfo10 = {
31278
31231
  name: "renameFile",
31279
31232
  description: "Request to rename a file from source path to target path.",
31280
31233
  parameters: exports_external.object({
@@ -31292,7 +31245,7 @@ var toolInfo12 = {
31292
31245
  ]
31293
31246
  })
31294
31247
  };
31295
- var handler12 = async (provider, args) => {
31248
+ var handler10 = async (provider, args) => {
31296
31249
  if (!provider.renameFile) {
31297
31250
  return {
31298
31251
  type: "Error" /* Error */,
@@ -31302,7 +31255,7 @@ var handler12 = async (provider, args) => {
31302
31255
  }
31303
31256
  };
31304
31257
  }
31305
- const { source_path, target_path } = toolInfo12.parameters.parse(args);
31258
+ const { source_path, target_path } = toolInfo10.parameters.parse(args);
31306
31259
  await provider.renameFile(source_path, target_path);
31307
31260
  return {
31308
31261
  type: "Reply" /* Reply */,
@@ -31313,8 +31266,8 @@ var handler12 = async (provider, args) => {
31313
31266
  };
31314
31267
  };
31315
31268
  var renameFile_default = {
31316
- ...toolInfo12,
31317
- handler: handler12
31269
+ ...toolInfo10,
31270
+ handler: handler10
31318
31271
  };
31319
31272
  // ../core/src/tools/utils/replaceInFile.ts
31320
31273
  var replaceInFile = (fileContent, diff) => {
@@ -31391,7 +31344,7 @@ var replaceInFile = (fileContent, diff) => {
31391
31344
  };
31392
31345
 
31393
31346
  // ../core/src/tools/replaceInFile.ts
31394
- var toolInfo13 = {
31347
+ var toolInfo11 = {
31395
31348
  name: "replaceInFile",
31396
31349
  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.",
31397
31350
  parameters: exports_external.object({
@@ -31501,7 +31454,7 @@ function oldFeature() {
31501
31454
  ]
31502
31455
  })
31503
31456
  };
31504
- var handler13 = async (provider, args) => {
31457
+ var handler11 = async (provider, args) => {
31505
31458
  if (!provider.readFile || !provider.writeFile) {
31506
31459
  return {
31507
31460
  type: "Error" /* Error */,
@@ -31511,7 +31464,7 @@ var handler13 = async (provider, args) => {
31511
31464
  }
31512
31465
  };
31513
31466
  }
31514
- const parsed = toolInfo13.parameters.safeParse(args);
31467
+ const parsed = toolInfo11.parameters.safeParse(args);
31515
31468
  if (!parsed.success) {
31516
31469
  return {
31517
31470
  type: "Error" /* Error */,
@@ -31575,35 +31528,11 @@ var handler13 = async (provider, args) => {
31575
31528
  }
31576
31529
  };
31577
31530
  var replaceInFile_default = {
31578
- ...toolInfo13,
31579
- handler: handler13
31580
- };
31581
- // ../core/src/tools/replaceMemory.ts
31582
- var toolInfo14 = {
31583
- name: "replaceMemory",
31584
- description: "Replaces content of a memory topic.",
31585
- parameters: exports_external.object({
31586
- topic: exports_external.string().optional().describe('The topic to replace in memory. Defaults to ":default:".'),
31587
- content: exports_external.string().describe("The new content.")
31588
- })
31589
- };
31590
- var handler14 = async (provider, args) => {
31591
- const { topic, content } = toolInfo14.parameters.parse(args);
31592
- await provider.replaceMemory(topic, content);
31593
- return {
31594
- type: "Reply" /* Reply */,
31595
- message: {
31596
- type: "text",
31597
- value: `Memory topic '${topic || ""}' replaced.`
31598
- }
31599
- };
31600
- };
31601
- var replaceMemory_default = {
31602
- ...toolInfo14,
31603
- handler: handler14
31531
+ ...toolInfo11,
31532
+ handler: handler11
31604
31533
  };
31605
31534
  // ../core/src/tools/searchFiles.ts
31606
- var toolInfo15 = {
31535
+ var toolInfo12 = {
31607
31536
  name: "searchFiles",
31608
31537
  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.",
31609
31538
  parameters: exports_external.object({
@@ -31627,7 +31556,7 @@ var toolInfo15 = {
31627
31556
  ]
31628
31557
  })
31629
31558
  };
31630
- var handler15 = async (provider, args) => {
31559
+ var handler12 = async (provider, args) => {
31631
31560
  if (!provider.searchFiles) {
31632
31561
  return {
31633
31562
  type: "Error" /* Error */,
@@ -31637,7 +31566,7 @@ var handler15 = async (provider, args) => {
31637
31566
  }
31638
31567
  };
31639
31568
  }
31640
- const parsed = toolInfo15.parameters.safeParse(args);
31569
+ const parsed = toolInfo12.parameters.safeParse(args);
31641
31570
  if (!parsed.success) {
31642
31571
  return {
31643
31572
  type: "Error" /* Error */,
@@ -31675,11 +31604,82 @@ ${files.join(`
31675
31604
  }
31676
31605
  };
31677
31606
  var searchFiles_default = {
31678
- ...toolInfo15,
31679
- handler: handler15
31607
+ ...toolInfo12,
31608
+ handler: handler12
31609
+ };
31610
+ // ../core/src/tools/updateMemory.ts
31611
+ var toolInfo13 = {
31612
+ name: "updateMemory",
31613
+ description: "Appends, replaces, or removes content from a memory topic.",
31614
+ parameters: exports_external.object({
31615
+ operation: exports_external.enum(["append", "replace", "remove"]).describe("The operation to perform."),
31616
+ topic: exports_external.string().nullish().describe('The topic to update in memory. Defaults to ":default:".'),
31617
+ content: exports_external.string().optional().describe("The content for append or replace operations. Must be omitted for remove operation.")
31618
+ }).superRefine((data, ctx) => {
31619
+ if (data.operation === "append" || data.operation === "replace") {
31620
+ if (data.content === undefined) {
31621
+ ctx.addIssue({
31622
+ code: "custom",
31623
+ message: 'Content is required for "append" and "replace" operations.',
31624
+ path: ["content"]
31625
+ });
31626
+ }
31627
+ } else if (data.operation === "remove") {
31628
+ if (data.content !== undefined) {
31629
+ ctx.addIssue({
31630
+ code: "custom",
31631
+ message: 'Content must not be provided for "remove" operation.',
31632
+ path: ["content"]
31633
+ });
31634
+ }
31635
+ }
31636
+ })
31637
+ };
31638
+ var handler13 = async (provider, args) => {
31639
+ if (!provider.updateMemory) {
31640
+ return {
31641
+ type: "Error" /* Error */,
31642
+ message: {
31643
+ type: "error-text",
31644
+ value: "Memory operations are not supported by the current provider."
31645
+ }
31646
+ };
31647
+ }
31648
+ const params = toolInfo13.parameters.parse(args);
31649
+ await provider.updateMemory(params.operation, params.topic ?? undefined, "content" in params ? params.content : undefined);
31650
+ switch (params.operation) {
31651
+ case "append":
31652
+ return {
31653
+ type: "Reply" /* Reply */,
31654
+ message: {
31655
+ type: "text",
31656
+ value: `Content appended to memory topic '${params.topic || ":default:"}'.`
31657
+ }
31658
+ };
31659
+ case "replace":
31660
+ return {
31661
+ type: "Reply" /* Reply */,
31662
+ message: {
31663
+ type: "text",
31664
+ value: `Memory topic '${params.topic || ":default:"}' replaced.`
31665
+ }
31666
+ };
31667
+ case "remove":
31668
+ return {
31669
+ type: "Reply" /* Reply */,
31670
+ message: {
31671
+ type: "text",
31672
+ value: `Memory topic '${params.topic || ":default:"}' removed.`
31673
+ }
31674
+ };
31675
+ }
31676
+ };
31677
+ var updateMemory_default = {
31678
+ ...toolInfo13,
31679
+ handler: handler13
31680
31680
  };
31681
31681
  // ../core/src/tools/writeToFile.ts
31682
- var toolInfo16 = {
31682
+ var toolInfo14 = {
31683
31683
  name: "writeToFile",
31684
31684
  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;`, `&gt;`, or `&amp;`. Also ensure there is no unwanted CDATA tags in the content.",
31685
31685
  parameters: exports_external.object({
@@ -31708,7 +31708,7 @@ export default App;
31708
31708
  ]
31709
31709
  })
31710
31710
  };
31711
- var handler16 = async (provider, args) => {
31711
+ var handler14 = async (provider, args) => {
31712
31712
  if (!provider.writeFile) {
31713
31713
  return {
31714
31714
  type: "Error" /* Error */,
@@ -31718,7 +31718,7 @@ var handler16 = async (provider, args) => {
31718
31718
  }
31719
31719
  };
31720
31720
  }
31721
- const parsed = toolInfo16.parameters.safeParse(args);
31721
+ const parsed = toolInfo14.parameters.safeParse(args);
31722
31722
  if (!parsed.success) {
31723
31723
  return {
31724
31724
  type: "Error" /* Error */,
@@ -31742,8 +31742,8 @@ var handler16 = async (provider, args) => {
31742
31742
  };
31743
31743
  };
31744
31744
  var writeToFile_default = {
31745
- ...toolInfo16,
31746
- handler: handler16
31745
+ ...toolInfo14,
31746
+ handler: handler14
31747
31747
  };
31748
31748
  // ../core/src/UsageMeter.ts
31749
31749
  class UsageMeter {
@@ -33633,15 +33633,15 @@ function useKeypress(userHandler) {
33633
33633
  signal.current = userHandler;
33634
33634
  useEffect((rl) => {
33635
33635
  let ignore = false;
33636
- const handler17 = withUpdates((_input, event) => {
33636
+ const handler15 = withUpdates((_input, event) => {
33637
33637
  if (ignore)
33638
33638
  return;
33639
33639
  signal.current(event, rl);
33640
33640
  });
33641
- rl.input.on("keypress", handler17);
33641
+ rl.input.on("keypress", handler15);
33642
33642
  return () => {
33643
33643
  ignore = true;
33644
- rl.input.removeListener("keypress", handler17);
33644
+ rl.input.removeListener("keypress", handler15);
33645
33645
  };
33646
33646
  }, []);
33647
33647
  }
@@ -33800,16 +33800,16 @@ class Emitter {
33800
33800
 
33801
33801
  class SignalExitBase {
33802
33802
  }
33803
- var signalExitWrap = (handler17) => {
33803
+ var signalExitWrap = (handler15) => {
33804
33804
  return {
33805
33805
  onExit(cb, opts) {
33806
- return handler17.onExit(cb, opts);
33806
+ return handler15.onExit(cb, opts);
33807
33807
  },
33808
33808
  load() {
33809
- return handler17.load();
33809
+ return handler15.load();
33810
33810
  },
33811
33811
  unload() {
33812
- return handler17.unload();
33812
+ return handler15.unload();
33813
33813
  }
33814
33814
  };
33815
33815
  };
@@ -34618,19 +34618,26 @@ var getProvider = (options = {}) => {
34618
34618
  readMemory: async (topic = defaultMemoryTopic) => {
34619
34619
  return memoryStore[topic];
34620
34620
  },
34621
- appendMemory: async (topic = defaultMemoryTopic, content) => {
34622
- if (memoryStore[topic]) {
34623
- memoryStore[topic] += content;
34624
- } else {
34625
- memoryStore[topic] = content;
34621
+ updateMemory: async (operation, topic, content) => {
34622
+ const memoryTopic = topic ?? defaultMemoryTopic;
34623
+ switch (operation) {
34624
+ case "append":
34625
+ if (content === undefined) {
34626
+ throw new Error("Content is required for append operation.");
34627
+ }
34628
+ memoryStore[memoryTopic] = (memoryStore[memoryTopic] || "") + content;
34629
+ break;
34630
+ case "replace":
34631
+ if (content === undefined) {
34632
+ throw new Error("Content is required for replace operation.");
34633
+ }
34634
+ memoryStore[memoryTopic] = content;
34635
+ break;
34636
+ case "remove":
34637
+ delete memoryStore[memoryTopic];
34638
+ break;
34626
34639
  }
34627
34640
  },
34628
- replaceMemory: async (topic = defaultMemoryTopic, content) => {
34629
- memoryStore[topic] = content;
34630
- },
34631
- removeMemory: async (topic = defaultMemoryTopic) => {
34632
- delete memoryStore[topic];
34633
- },
34634
34641
  readFile: async (path, includeIgnored) => {
34635
34642
  if (!includeIgnored && ig.ignores(path)) {
34636
34643
  throw new Error(`Not allow to access file ${path}`);
@@ -35269,7 +35276,32 @@ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
35269
35276
  var source_default = chalk;
35270
35277
 
35271
35278
  // src/utils/eventHandler.ts
35272
- var toolCallStats = new Map;
35279
+ var taskToolCallStats = new Map;
35280
+ var globalToolCallStats = new Map;
35281
+ function logToolCallStats(stream, statsMap, title) {
35282
+ const customConsole = new Console(stream, stream);
35283
+ customConsole.log(`
35284
+
35285
+ ======== ${title} ========`);
35286
+ if (statsMap.size > 0) {
35287
+ const tableData = [...statsMap.entries()].map(([tool2, stats]) => {
35288
+ const successRate = stats.calls > 0 ? stats.success / stats.calls * 100 : 0;
35289
+ return {
35290
+ "Tool Name": tool2,
35291
+ Calls: stats.calls,
35292
+ Success: stats.success,
35293
+ Errors: stats.errors,
35294
+ "Success Rate": `${successRate.toFixed(2)}%`
35295
+ };
35296
+ });
35297
+ customConsole.table(tableData);
35298
+ } else {
35299
+ customConsole.log("No tools were called.");
35300
+ }
35301
+ }
35302
+ function logGlobalToolCallStats(stream) {
35303
+ logToolCallStats(stream, globalToolCallStats, "Global Tool Call Stats");
35304
+ }
35273
35305
  var printEvent = (verbose, usageMeter, stream = process.stdout) => {
35274
35306
  if (verbose < 0) {
35275
35307
  return () => {};
@@ -35280,7 +35312,7 @@ var printEvent = (verbose, usageMeter, stream = process.stdout) => {
35280
35312
  return (event) => {
35281
35313
  switch (event.kind) {
35282
35314
  case "StartTask" /* StartTask */:
35283
- toolCallStats.clear();
35315
+ taskToolCallStats.clear();
35284
35316
  if (verbose > 2) {
35285
35317
  customConsole.log(`
35286
35318
  ====== System Prompt ======
@@ -35292,10 +35324,12 @@ ${event.systemPrompt}`);
35292
35324
  }
35293
35325
  break;
35294
35326
  case "StartRequest" /* StartRequest */:
35295
- customConsole.log(`
35327
+ if (verbose > 0) {
35328
+ customConsole.log(`
35296
35329
 
35297
35330
  ======== New Request ========
35298
35331
  `);
35332
+ }
35299
35333
  if (verbose > 1) {
35300
35334
  for (const message of event.userMessage) {
35301
35335
  const userMessage = message.content;
@@ -35339,10 +35373,12 @@ ${event.systemPrompt}`);
35339
35373
  }
35340
35374
  break;
35341
35375
  case "EndRequest" /* EndRequest */:
35342
- customConsole.log(`
35376
+ if (verbose > 0) {
35377
+ customConsole.log(`
35343
35378
 
35344
35379
  ======== Request Ended ========
35345
35380
  `);
35381
+ }
35346
35382
  if (verbose > 1) {
35347
35383
  customConsole.log(usageMeter.getUsageText());
35348
35384
  }
@@ -35358,23 +35394,27 @@ ${event.systemPrompt}`);
35358
35394
  break;
35359
35395
  }
35360
35396
  case "Reasoning" /* Reasoning */: {
35361
- write(source_default.dim(event.newText));
35362
- hadReasoning = true;
35397
+ if (verbose > 0) {
35398
+ write(source_default.dim(event.newText));
35399
+ hadReasoning = true;
35400
+ }
35363
35401
  break;
35364
35402
  }
35365
35403
  case "ToolUse" /* ToolUse */: {
35366
- customConsole.log(source_default.yellow(`
35404
+ if (verbose > 0) {
35405
+ customConsole.log(source_default.yellow(`
35367
35406
 
35368
35407
  Tool use:`, event.tool), event.params);
35369
- const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35408
+ }
35409
+ const stats = taskToolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35370
35410
  stats.calls++;
35371
- toolCallStats.set(event.tool, stats);
35411
+ taskToolCallStats.set(event.tool, stats);
35372
35412
  break;
35373
35413
  }
35374
35414
  case "ToolReply" /* ToolReply */: {
35375
- const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35415
+ const stats = taskToolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35376
35416
  stats.success++;
35377
- toolCallStats.set(event.tool, stats);
35417
+ taskToolCallStats.set(event.tool, stats);
35378
35418
  break;
35379
35419
  }
35380
35420
  case "ToolError" /* ToolError */: {
@@ -35382,9 +35422,9 @@ Tool use:`, event.tool), event.params);
35382
35422
 
35383
35423
  Tool error:`, event.tool));
35384
35424
  customConsole.error(event.error);
35385
- const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35425
+ const stats = taskToolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35386
35426
  stats.errors++;
35387
- toolCallStats.set(event.tool, stats);
35427
+ taskToolCallStats.set(event.tool, stats);
35388
35428
  break;
35389
35429
  }
35390
35430
  case "UsageExceeded" /* UsageExceeded */:
@@ -35404,23 +35444,15 @@ Tool error:`, event.tool));
35404
35444
  customConsole.log("Exit Message:", event.exitReason.message);
35405
35445
  break;
35406
35446
  }
35407
- customConsole.log(`
35408
-
35409
- ======== Tool Call Stats ========`);
35410
- if (toolCallStats.size > 0) {
35411
- const tableData = [...toolCallStats.entries()].map(([tool2, stats]) => {
35412
- const successRate = stats.calls > 0 ? stats.success / stats.calls * 100 : 0;
35413
- return {
35414
- "Tool Name": tool2,
35415
- Calls: stats.calls,
35416
- Success: stats.success,
35417
- Errors: stats.errors,
35418
- "Success Rate": `${successRate.toFixed(2)}%`
35419
- };
35420
- });
35421
- customConsole.table(tableData);
35422
- } else {
35423
- customConsole.log("No tools were called.");
35447
+ if (verbose > 0) {
35448
+ for (const [tool2, taskStats] of taskToolCallStats.entries()) {
35449
+ const globalStats = globalToolCallStats.get(tool2) ?? { calls: 0, success: 0, errors: 0 };
35450
+ globalStats.calls += taskStats.calls;
35451
+ globalStats.success += taskStats.success;
35452
+ globalStats.errors += taskStats.errors;
35453
+ globalToolCallStats.set(tool2, globalStats);
35454
+ }
35455
+ logToolCallStats(stream, taskToolCallStats, "Task Tool Call Stats");
35424
35456
  }
35425
35457
  break;
35426
35458
  }
@@ -35453,6 +35485,8 @@ export {
35453
35485
  readConfig,
35454
35486
  printEvent,
35455
35487
  mergeConfigs,
35488
+ logToolCallStats,
35489
+ logGlobalToolCallStats,
35456
35490
  localConfigFileName,
35457
35491
  loadConfigAtPath,
35458
35492
  loadConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.47",
3
+ "version": "0.9.48",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",