@polka-codes/cli-shared 0.9.47 → 0.9.49

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 +503 -162
  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,6 +30919,38 @@ var handler4 = async (provider, args) => {
30943
30919
  };
30944
30920
  };
30945
30921
  var fetchUrl_default = {
30922
+ ...toolInfo3,
30923
+ handler: handler3
30924
+ };
30925
+ // ../core/src/tools/getTodoItem.ts
30926
+ var toolInfo4 = {
30927
+ name: "getTodoItem",
30928
+ description: "Get a to-do item by its ID.",
30929
+ parameters: exports_external.object({
30930
+ id: exports_external.string().describe("The ID of the to-do item.")
30931
+ })
30932
+ };
30933
+ var handler4 = async (provider, args) => {
30934
+ if (!provider.getTodoItem) {
30935
+ return {
30936
+ type: "Error" /* Error */,
30937
+ message: {
30938
+ type: "error-text",
30939
+ value: "Not possible to get a to-do item."
30940
+ }
30941
+ };
30942
+ }
30943
+ const { id } = toolInfo4.parameters.parse(args);
30944
+ const item = await provider.getTodoItem(id);
30945
+ return {
30946
+ type: "Reply" /* Reply */,
30947
+ message: {
30948
+ type: "json",
30949
+ value: item ?? null
30950
+ }
30951
+ };
30952
+ };
30953
+ var getTodoItem_default = {
30946
30954
  ...toolInfo4,
30947
30955
  handler: handler4
30948
30956
  };
@@ -31017,7 +31025,7 @@ var listFiles_default = {
31017
31025
  // ../core/src/tools/listMemoryTopics.ts
31018
31026
  var toolInfo6 = {
31019
31027
  name: "listMemoryTopics",
31020
- description: "Lists all topics in memory.",
31028
+ description: "Lists all topics in memory. Use this to see what information has been stored and which topics are available to read from.",
31021
31029
  parameters: exports_external.object({})
31022
31030
  };
31023
31031
  var handler6 = async (provider, _args) => {
@@ -31039,15 +31047,88 @@ var listMemoryTopics_default = {
31039
31047
  ...toolInfo6,
31040
31048
  handler: handler6
31041
31049
  };
31042
- // ../core/src/tools/readBinaryFile.ts
31050
+ // ../core/src/tools/todo.ts
31051
+ var TodoStatus = exports_external.enum(["open", "completed", "closed"]);
31052
+ var TodoItemSchema = exports_external.object({
31053
+ id: exports_external.string(),
31054
+ title: exports_external.string(),
31055
+ description: exports_external.string(),
31056
+ relevantFileList: exports_external.array(exports_external.string()),
31057
+ status: TodoStatus
31058
+ });
31059
+ var UpdateTodoItemInputSchema = exports_external.object({
31060
+ operation: exports_external.enum(["add", "update"]),
31061
+ id: exports_external.string().nullish(),
31062
+ parentId: exports_external.string().nullish(),
31063
+ title: exports_external.string().nullish(),
31064
+ description: exports_external.string().nullish(),
31065
+ relevantFileList: exports_external.array(exports_external.string()).nullish(),
31066
+ status: TodoStatus.nullish()
31067
+ }).superRefine((data, ctx) => {
31068
+ if (data.operation === "add") {
31069
+ if (!data.title) {
31070
+ ctx.addIssue({
31071
+ code: "custom",
31072
+ message: 'Title is required for "add" operation',
31073
+ path: ["title"]
31074
+ });
31075
+ }
31076
+ } else if (data.operation === "update") {
31077
+ if (!data.id) {
31078
+ ctx.addIssue({
31079
+ code: "custom",
31080
+ message: 'ID is required for "update" operation',
31081
+ path: ["id"]
31082
+ });
31083
+ }
31084
+ }
31085
+ });
31086
+ var UpdateTodoItemOutputSchema = exports_external.object({
31087
+ id: exports_external.string()
31088
+ });
31089
+
31090
+ // ../core/src/tools/listTodoItems.ts
31043
31091
  var toolInfo7 = {
31092
+ name: "listTodoItems",
31093
+ description: "List all to-do items, sorted by id. If an id is provided, it lists all sub-items for that id. Can be filtered by status.",
31094
+ parameters: exports_external.object({
31095
+ id: exports_external.string().nullish(),
31096
+ status: TodoStatus.nullish()
31097
+ })
31098
+ };
31099
+ var handler7 = async (provider, args) => {
31100
+ if (!provider.listTodoItems) {
31101
+ return {
31102
+ type: "Error" /* Error */,
31103
+ message: {
31104
+ type: "error-text",
31105
+ value: "Not possible to list to-do items."
31106
+ }
31107
+ };
31108
+ }
31109
+ const { id, status } = toolInfo7.parameters.parse(args);
31110
+ const items = await provider.listTodoItems(id, status);
31111
+ return {
31112
+ type: "Reply" /* Reply */,
31113
+ message: {
31114
+ type: "json",
31115
+ value: items
31116
+ }
31117
+ };
31118
+ };
31119
+ var listTodoItems_default = {
31120
+ ...toolInfo7,
31121
+ handler: handler7
31122
+ };
31123
+ // ../core/src/tools/readBinaryFile.ts
31124
+ var toolInfo8 = {
31044
31125
  name: "readBinaryFile",
31045
31126
  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
31127
  parameters: exports_external.object({
31047
31128
  url: exports_external.string().describe("The URL or local path of the file to read.")
31048
31129
  })
31049
31130
  };
31050
- var handler7 = async (provider, args) => {
31131
+ var handler8 = async (provider, args) => {
31051
31132
  if (!provider.readBinaryFile) {
31052
31133
  return {
31053
31134
  type: "Error" /* Error */,
@@ -31057,7 +31138,7 @@ var handler7 = async (provider, args) => {
31057
31138
  }
31058
31139
  };
31059
31140
  }
31060
- const { url: url2 } = toolInfo7.parameters.parse(args);
31141
+ const { url: url2 } = toolInfo8.parameters.parse(args);
31061
31142
  try {
31062
31143
  const filePart = await provider.readBinaryFile(url2);
31063
31144
  return {
@@ -31086,11 +31167,11 @@ var handler7 = async (provider, args) => {
31086
31167
  }
31087
31168
  };
31088
31169
  var readBinaryFile_default = {
31089
- ...toolInfo7,
31090
- handler: handler7
31170
+ ...toolInfo8,
31171
+ handler: handler8
31091
31172
  };
31092
31173
  // ../core/src/tools/readFile.ts
31093
- var toolInfo8 = {
31174
+ var toolInfo9 = {
31094
31175
  name: "readFile",
31095
31176
  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
31177
  parameters: exports_external.object({
@@ -31127,7 +31208,7 @@ var toolInfo8 = {
31127
31208
  ]
31128
31209
  })
31129
31210
  };
31130
- var handler8 = async (provider, args) => {
31211
+ var handler9 = async (provider, args) => {
31131
31212
  if (!provider.readFile) {
31132
31213
  return {
31133
31214
  type: "Error" /* Error */,
@@ -31137,7 +31218,7 @@ var handler8 = async (provider, args) => {
31137
31218
  }
31138
31219
  };
31139
31220
  }
31140
- const { path: paths, includeIgnored } = toolInfo8.parameters.parse(args);
31221
+ const { path: paths, includeIgnored } = toolInfo9.parameters.parse(args);
31141
31222
  const resp = [];
31142
31223
  for (const path of paths) {
31143
31224
  const fileContent = await provider.readFile(path, includeIgnored);
@@ -31162,19 +31243,19 @@ var handler8 = async (provider, args) => {
31162
31243
  };
31163
31244
  };
31164
31245
  var readFile_default = {
31165
- ...toolInfo8,
31166
- handler: handler8
31246
+ ...toolInfo9,
31247
+ handler: handler9
31167
31248
  };
31168
31249
  // ../core/src/tools/readMemory.ts
31169
- var toolInfo9 = {
31250
+ var toolInfo10 = {
31170
31251
  name: "readMemory",
31171
- description: "Reads content from a memory topic.",
31252
+ description: "Reads content from a memory topic. Use this to retrieve information stored in previous steps. If no topic is specified, reads from the default topic.",
31172
31253
  parameters: exports_external.object({
31173
31254
  topic: exports_external.string().optional().describe('The topic to read from memory. Defaults to ":default:".')
31174
31255
  })
31175
31256
  };
31176
- var handler9 = async (provider, args) => {
31177
- const { topic } = toolInfo9.parameters.parse(args);
31257
+ var handler10 = async (provider, args) => {
31258
+ const { topic } = toolInfo10.parameters.parse(args);
31178
31259
  const content = await provider.readMemory(topic);
31179
31260
  if (content) {
31180
31261
  return {
@@ -31196,11 +31277,11 @@ ${content}
31196
31277
  };
31197
31278
  };
31198
31279
  var readMemory_default = {
31199
- ...toolInfo9,
31200
- handler: handler9
31280
+ ...toolInfo10,
31281
+ handler: handler10
31201
31282
  };
31202
31283
  // ../core/src/tools/removeFile.ts
31203
- var toolInfo10 = {
31284
+ var toolInfo11 = {
31204
31285
  name: "removeFile",
31205
31286
  description: "Request to remove a file at the specified path.",
31206
31287
  parameters: exports_external.object({
@@ -31216,7 +31297,7 @@ var toolInfo10 = {
31216
31297
  ]
31217
31298
  })
31218
31299
  };
31219
- var handler10 = async (provider, args) => {
31300
+ var handler11 = async (provider, args) => {
31220
31301
  if (!provider.removeFile) {
31221
31302
  return {
31222
31303
  type: "Error" /* Error */,
@@ -31226,7 +31307,7 @@ var handler10 = async (provider, args) => {
31226
31307
  }
31227
31308
  };
31228
31309
  }
31229
- const parsed = toolInfo10.parameters.safeParse(args);
31310
+ const parsed = toolInfo11.parameters.safeParse(args);
31230
31311
  if (!parsed.success) {
31231
31312
  return {
31232
31313
  type: "Error" /* Error */,
@@ -31247,29 +31328,6 @@ var handler10 = async (provider, args) => {
31247
31328
  };
31248
31329
  };
31249
31330
  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
31331
  ...toolInfo11,
31274
31332
  handler: handler11
31275
31333
  };
@@ -31318,7 +31376,7 @@ var renameFile_default = {
31318
31376
  };
31319
31377
  // ../core/src/tools/utils/replaceInFile.ts
31320
31378
  var replaceInFile = (fileContent, diff) => {
31321
- const blockPattern = /<<<<<+ SEARCH>?\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+ REPLACE/g;
31379
+ const blockPattern = /^\s*<<<<<+\s*SEARCH>?\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+\s*REPLACE\s*$/gm;
31322
31380
  const blocks = [];
31323
31381
  for (let match = blockPattern.exec(diff);match !== null; match = blockPattern.exec(diff)) {
31324
31382
  blocks.push({ search: match[1], replace: match[2] });
@@ -31578,32 +31636,8 @@ var replaceInFile_default = {
31578
31636
  ...toolInfo13,
31579
31637
  handler: handler13
31580
31638
  };
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
31604
- };
31605
31639
  // ../core/src/tools/searchFiles.ts
31606
- var toolInfo15 = {
31640
+ var toolInfo14 = {
31607
31641
  name: "searchFiles",
31608
31642
  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
31643
  parameters: exports_external.object({
@@ -31627,7 +31661,7 @@ var toolInfo15 = {
31627
31661
  ]
31628
31662
  })
31629
31663
  };
31630
- var handler15 = async (provider, args) => {
31664
+ var handler14 = async (provider, args) => {
31631
31665
  if (!provider.searchFiles) {
31632
31666
  return {
31633
31667
  type: "Error" /* Error */,
@@ -31637,7 +31671,7 @@ var handler15 = async (provider, args) => {
31637
31671
  }
31638
31672
  };
31639
31673
  }
31640
- const parsed = toolInfo15.parameters.safeParse(args);
31674
+ const parsed = toolInfo14.parameters.safeParse(args);
31641
31675
  if (!parsed.success) {
31642
31676
  return {
31643
31677
  type: "Error" /* Error */,
@@ -31675,11 +31709,112 @@ ${files.join(`
31675
31709
  }
31676
31710
  };
31677
31711
  var searchFiles_default = {
31712
+ ...toolInfo14,
31713
+ handler: handler14
31714
+ };
31715
+ // ../core/src/tools/updateMemory.ts
31716
+ var toolInfo15 = {
31717
+ name: "updateMemory",
31718
+ description: 'Appends, replaces, or removes content from a memory topic. Use "append" to add to existing content, "replace" to overwrite entirely, or "remove" to delete a topic. Memory persists across tool calls within a workflow.',
31719
+ parameters: exports_external.object({
31720
+ operation: exports_external.enum(["append", "replace", "remove"]).describe("The operation to perform."),
31721
+ topic: exports_external.string().nullish().describe('The topic to update in memory. Defaults to ":default:".'),
31722
+ content: exports_external.string().optional().describe("The content for append or replace operations. Must be omitted for remove operation.")
31723
+ }).superRefine((data, ctx) => {
31724
+ if (data.operation === "append" || data.operation === "replace") {
31725
+ if (data.content === undefined) {
31726
+ ctx.addIssue({
31727
+ code: "custom",
31728
+ message: 'Content is required for "append" and "replace" operations.',
31729
+ path: ["content"]
31730
+ });
31731
+ }
31732
+ } else if (data.operation === "remove") {
31733
+ if (data.content !== undefined) {
31734
+ ctx.addIssue({
31735
+ code: "custom",
31736
+ message: 'Content must not be provided for "remove" operation.',
31737
+ path: ["content"]
31738
+ });
31739
+ }
31740
+ }
31741
+ })
31742
+ };
31743
+ var handler15 = async (provider, args) => {
31744
+ if (!provider.updateMemory) {
31745
+ return {
31746
+ type: "Error" /* Error */,
31747
+ message: {
31748
+ type: "error-text",
31749
+ value: "Memory operations are not supported by the current provider."
31750
+ }
31751
+ };
31752
+ }
31753
+ const params = toolInfo15.parameters.parse(args);
31754
+ await provider.updateMemory(params.operation, params.topic ?? undefined, "content" in params ? params.content : undefined);
31755
+ switch (params.operation) {
31756
+ case "append":
31757
+ return {
31758
+ type: "Reply" /* Reply */,
31759
+ message: {
31760
+ type: "text",
31761
+ value: `Content appended to memory topic '${params.topic || ":default:"}'.`
31762
+ }
31763
+ };
31764
+ case "replace":
31765
+ return {
31766
+ type: "Reply" /* Reply */,
31767
+ message: {
31768
+ type: "text",
31769
+ value: `Memory topic '${params.topic || ":default:"}' replaced.`
31770
+ }
31771
+ };
31772
+ case "remove":
31773
+ return {
31774
+ type: "Reply" /* Reply */,
31775
+ message: {
31776
+ type: "text",
31777
+ value: `Memory topic '${params.topic || ":default:"}' removed.`
31778
+ }
31779
+ };
31780
+ }
31781
+ };
31782
+ var updateMemory_default = {
31678
31783
  ...toolInfo15,
31679
31784
  handler: handler15
31680
31785
  };
31681
- // ../core/src/tools/writeToFile.ts
31786
+ // ../core/src/tools/updateTodoItem.ts
31682
31787
  var toolInfo16 = {
31788
+ name: "updateTodoItem",
31789
+ description: "Add or update a to-do item.",
31790
+ parameters: UpdateTodoItemInputSchema
31791
+ };
31792
+ var handler16 = async (provider, args) => {
31793
+ if (!provider.updateTodoItem) {
31794
+ return {
31795
+ type: "Error" /* Error */,
31796
+ message: {
31797
+ type: "error-text",
31798
+ value: "Not possible to update a to-do item."
31799
+ }
31800
+ };
31801
+ }
31802
+ const input = toolInfo16.parameters.parse(args);
31803
+ const result = await provider.updateTodoItem(input);
31804
+ return {
31805
+ type: "Reply" /* Reply */,
31806
+ message: {
31807
+ type: "json",
31808
+ value: result
31809
+ }
31810
+ };
31811
+ };
31812
+ var updateTodoItem_default = {
31813
+ ...toolInfo16,
31814
+ handler: handler16
31815
+ };
31816
+ // ../core/src/tools/writeToFile.ts
31817
+ var toolInfo17 = {
31683
31818
  name: "writeToFile",
31684
31819
  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
31820
  parameters: exports_external.object({
@@ -31708,7 +31843,7 @@ export default App;
31708
31843
  ]
31709
31844
  })
31710
31845
  };
31711
- var handler16 = async (provider, args) => {
31846
+ var handler17 = async (provider, args) => {
31712
31847
  if (!provider.writeFile) {
31713
31848
  return {
31714
31849
  type: "Error" /* Error */,
@@ -31718,7 +31853,7 @@ var handler16 = async (provider, args) => {
31718
31853
  }
31719
31854
  };
31720
31855
  }
31721
- const parsed = toolInfo16.parameters.safeParse(args);
31856
+ const parsed = toolInfo17.parameters.safeParse(args);
31722
31857
  if (!parsed.success) {
31723
31858
  return {
31724
31859
  type: "Error" /* Error */,
@@ -31742,8 +31877,8 @@ var handler16 = async (provider, args) => {
31742
31877
  };
31743
31878
  };
31744
31879
  var writeToFile_default = {
31745
- ...toolInfo16,
31746
- handler: handler16
31880
+ ...toolInfo17,
31881
+ handler: handler17
31747
31882
  };
31748
31883
  // ../core/src/UsageMeter.ts
31749
31884
  class UsageMeter {
@@ -33633,15 +33768,15 @@ function useKeypress(userHandler) {
33633
33768
  signal.current = userHandler;
33634
33769
  useEffect((rl) => {
33635
33770
  let ignore = false;
33636
- const handler17 = withUpdates((_input, event) => {
33771
+ const handler18 = withUpdates((_input, event) => {
33637
33772
  if (ignore)
33638
33773
  return;
33639
33774
  signal.current(event, rl);
33640
33775
  });
33641
- rl.input.on("keypress", handler17);
33776
+ rl.input.on("keypress", handler18);
33642
33777
  return () => {
33643
33778
  ignore = true;
33644
- rl.input.removeListener("keypress", handler17);
33779
+ rl.input.removeListener("keypress", handler18);
33645
33780
  };
33646
33781
  }, []);
33647
33782
  }
@@ -33800,16 +33935,16 @@ class Emitter {
33800
33935
 
33801
33936
  class SignalExitBase {
33802
33937
  }
33803
- var signalExitWrap = (handler17) => {
33938
+ var signalExitWrap = (handler18) => {
33804
33939
  return {
33805
33940
  onExit(cb, opts) {
33806
- return handler17.onExit(cb, opts);
33941
+ return handler18.onExit(cb, opts);
33807
33942
  },
33808
33943
  load() {
33809
- return handler17.load();
33944
+ return handler18.load();
33810
33945
  },
33811
33946
  unload() {
33812
- return handler17.unload();
33947
+ return handler18.unload();
33813
33948
  }
33814
33949
  };
33815
33950
  };
@@ -34610,27 +34745,122 @@ async function searchFiles(path, regex, filePattern, cwd, excludeFiles) {
34610
34745
  var getProvider = (options = {}) => {
34611
34746
  const ig = import_ignore2.default().add(options.excludeFiles ?? []);
34612
34747
  const memoryStore = {};
34748
+ const todoItems = [];
34613
34749
  const defaultMemoryTopic = ":default:";
34614
34750
  const provider2 = {
34751
+ listTodoItems: async (id, status) => {
34752
+ let items;
34753
+ if (!id) {
34754
+ items = todoItems.filter((i) => !i.id.includes("."));
34755
+ } else {
34756
+ const parent = todoItems.find((i) => i.id === id);
34757
+ if (!parent) {
34758
+ throw new Error(`To-do item with id ${id} not found`);
34759
+ }
34760
+ items = todoItems.filter((i) => i.id.startsWith(`${id}.`) && i.id.split(".").length === id.split(".").length + 1);
34761
+ }
34762
+ if (status) {
34763
+ items = items.filter((item) => item.status === status);
34764
+ }
34765
+ items.sort((a, b) => {
34766
+ const aParts = a.id.split(".");
34767
+ const bParts = b.id.split(".");
34768
+ const len = Math.min(aParts.length, bParts.length);
34769
+ for (let i = 0;i < len; i++) {
34770
+ const comparison = aParts[i].localeCompare(bParts[i], undefined, { numeric: true });
34771
+ if (comparison !== 0) {
34772
+ return comparison;
34773
+ }
34774
+ }
34775
+ return aParts.length - bParts.length;
34776
+ });
34777
+ return items;
34778
+ },
34779
+ getTodoItem: async (id) => {
34780
+ const item = todoItems.find((i) => i.id === id);
34781
+ if (!item) {
34782
+ throw new Error(`To-do item with id ${id} not found`);
34783
+ }
34784
+ const subItems = todoItems.filter((i) => i.id.startsWith(`${id}.`) && i.id.split(".").length === id.split(".").length + 1).map(({ id: id2, title }) => ({ id: id2, title }));
34785
+ return { ...item, subItems };
34786
+ },
34787
+ updateTodoItem: async (input) => {
34788
+ if (input.operation === "add") {
34789
+ const { parentId, title, description, relevantFileList } = input;
34790
+ if (!title) {
34791
+ throw new Error("Title is required for add operation");
34792
+ }
34793
+ let newId;
34794
+ if (parentId) {
34795
+ const parent = todoItems.find((i) => i.id === parentId);
34796
+ if (!parent) {
34797
+ throw new Error(`Parent to-do item with id ${parentId} not found`);
34798
+ }
34799
+ const childItems = todoItems.filter((i) => i.id.startsWith(`${parentId}.`) && i.id.split(".").length === parentId.split(".").length + 1);
34800
+ newId = `${parentId}.${childItems.length + 1}`;
34801
+ } else {
34802
+ const rootItems = todoItems.filter((i) => !i.id.includes("."));
34803
+ newId = `${rootItems.length + 1}`;
34804
+ }
34805
+ const newItem = {
34806
+ id: newId,
34807
+ title,
34808
+ description: description ?? "",
34809
+ relevantFileList: relevantFileList ?? [],
34810
+ status: "open"
34811
+ };
34812
+ todoItems.push(newItem);
34813
+ return { id: newId };
34814
+ } else {
34815
+ const { id } = input;
34816
+ if (!id) {
34817
+ throw new Error("ID is required for update operation");
34818
+ }
34819
+ const item = todoItems.find((i) => i.id === id);
34820
+ if (!item) {
34821
+ throw new Error(`To-do item with id ${id} not found`);
34822
+ }
34823
+ if (input.title != null) {
34824
+ item.title = input.title;
34825
+ }
34826
+ if (input.description != null) {
34827
+ item.description = input.description ?? "";
34828
+ }
34829
+ if (input.relevantFileList != null) {
34830
+ item.relevantFileList = input.relevantFileList;
34831
+ }
34832
+ if (input.status != null) {
34833
+ item.status = input.status;
34834
+ }
34835
+ return { id };
34836
+ }
34837
+ },
34615
34838
  listMemoryTopics: async () => {
34616
34839
  return Object.keys(memoryStore);
34617
34840
  },
34618
34841
  readMemory: async (topic = defaultMemoryTopic) => {
34619
34842
  return memoryStore[topic];
34620
34843
  },
34621
- appendMemory: async (topic = defaultMemoryTopic, content) => {
34622
- if (memoryStore[topic]) {
34623
- memoryStore[topic] += content;
34624
- } else {
34625
- memoryStore[topic] = content;
34844
+ updateMemory: async (operation, topic, content) => {
34845
+ const memoryTopic = topic ?? defaultMemoryTopic;
34846
+ switch (operation) {
34847
+ case "append":
34848
+ if (content === undefined) {
34849
+ throw new Error("Content is required for append operation.");
34850
+ }
34851
+ memoryStore[memoryTopic] = (memoryStore[memoryTopic] || "") + content;
34852
+ break;
34853
+ case "replace":
34854
+ if (content === undefined) {
34855
+ throw new Error("Content is required for replace operation.");
34856
+ }
34857
+ memoryStore[memoryTopic] = content;
34858
+ break;
34859
+ case "remove":
34860
+ delete memoryStore[memoryTopic];
34861
+ break;
34626
34862
  }
34627
34863
  },
34628
- replaceMemory: async (topic = defaultMemoryTopic, content) => {
34629
- memoryStore[topic] = content;
34630
- },
34631
- removeMemory: async (topic = defaultMemoryTopic) => {
34632
- delete memoryStore[topic];
34633
- },
34634
34864
  readFile: async (path, includeIgnored) => {
34635
34865
  if (!includeIgnored && ig.ignores(path)) {
34636
34866
  throw new Error(`Not allow to access file ${path}`);
@@ -35268,19 +35498,110 @@ var chalk = createChalk();
35268
35498
  var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
35269
35499
  var source_default = chalk;
35270
35500
 
35501
+ // src/utils/parameterSimplifier.ts
35502
+ function replaceInFileSimplifier(params) {
35503
+ return { path: params.path };
35504
+ }
35505
+ function writeToFileSimplifier(params) {
35506
+ return { path: params.path };
35507
+ }
35508
+ function readFileSimplifier(params) {
35509
+ return { path: params.path, includeIgnored: params.includeIgnored };
35510
+ }
35511
+ function listFilesSimplifier(params) {
35512
+ const maxCount = params.maxCount;
35513
+ return {
35514
+ path: params.path,
35515
+ recursive: params.recursive,
35516
+ ...maxCount !== 2000 && { maxCount }
35517
+ };
35518
+ }
35519
+ function searchFilesSimplifier(params) {
35520
+ return { ...params };
35521
+ }
35522
+ function executeCommandSimplifier(params) {
35523
+ return { command: params.command, requiresApproval: params.requiresApproval };
35524
+ }
35525
+ function updateMemorySimplifier(params) {
35526
+ return { operation: params.operation, topic: params.topic };
35527
+ }
35528
+ var SIMPLIFIERS = {
35529
+ replaceInFile: replaceInFileSimplifier,
35530
+ writeToFile: writeToFileSimplifier,
35531
+ readFile: readFileSimplifier,
35532
+ listFiles: listFilesSimplifier,
35533
+ searchFiles: searchFilesSimplifier,
35534
+ executeCommand: executeCommandSimplifier,
35535
+ updateMemory: updateMemorySimplifier
35536
+ };
35537
+ function simplifyToolParameters(toolName, params) {
35538
+ if (params === undefined || params === null) {
35539
+ return {};
35540
+ }
35541
+ const simplifier = SIMPLIFIERS[toolName];
35542
+ if (simplifier) {
35543
+ return simplifier(params);
35544
+ }
35545
+ return { ...params };
35546
+ }
35547
+
35271
35548
  // src/utils/eventHandler.ts
35272
- var toolCallStats = new Map;
35549
+ var taskToolCallStats = new Map;
35550
+ var globalToolCallStats = new Map;
35551
+ function logToolCallStats(stream, statsMap, title) {
35552
+ const customConsole = new Console(stream, stream);
35553
+ customConsole.log(`
35554
+
35555
+ ======== ${title} ========`);
35556
+ if (statsMap.size > 0) {
35557
+ const tableData = [...statsMap.entries()].map(([tool2, stats]) => {
35558
+ const successRate = stats.calls > 0 ? stats.success / stats.calls * 100 : 0;
35559
+ return {
35560
+ "Tool Name": tool2,
35561
+ Calls: stats.calls,
35562
+ Success: stats.success,
35563
+ Errors: stats.errors,
35564
+ "Success Rate": `${successRate.toFixed(2)}%`
35565
+ };
35566
+ });
35567
+ customConsole.table(tableData);
35568
+ } else {
35569
+ customConsole.log("No tools were called.");
35570
+ }
35571
+ }
35572
+ var mergeToolCallStats = (a, b) => {
35573
+ const merged = new Map;
35574
+ for (const [tool2, stat] of a) {
35575
+ merged.set(tool2, { ...stat });
35576
+ }
35577
+ for (const [tool2, stat] of b) {
35578
+ const existing = merged.get(tool2);
35579
+ if (existing) {
35580
+ existing.calls += stat.calls;
35581
+ existing.success += stat.success;
35582
+ existing.errors += stat.errors;
35583
+ } else {
35584
+ merged.set(tool2, { ...stat });
35585
+ }
35586
+ }
35587
+ return merged;
35588
+ };
35589
+ function logGlobalToolCallStats(stream) {
35590
+ const merged = mergeToolCallStats(globalToolCallStats, taskToolCallStats);
35591
+ logToolCallStats(stream, merged, "Global Tool Call Stats");
35592
+ }
35273
35593
  var printEvent = (verbose, usageMeter, stream = process.stdout) => {
35274
35594
  if (verbose < 0) {
35275
35595
  return () => {};
35276
35596
  }
35277
35597
  const customConsole = new Console(stream, stream);
35278
35598
  let hadReasoning = false;
35599
+ let hasText = false;
35279
35600
  const write = stream.write.bind(stream);
35280
35601
  return (event) => {
35281
35602
  switch (event.kind) {
35282
35603
  case "StartTask" /* StartTask */:
35283
- toolCallStats.clear();
35604
+ taskToolCallStats.clear();
35284
35605
  if (verbose > 2) {
35285
35606
  customConsole.log(`
35286
35607
  ====== System Prompt ======
@@ -35292,10 +35613,13 @@ ${event.systemPrompt}`);
35292
35613
  }
35293
35614
  break;
35294
35615
  case "StartRequest" /* StartRequest */:
35295
- customConsole.log(`
35616
+ hasText = false;
35617
+ if (verbose > 0) {
35618
+ customConsole.log(`
35296
35619
 
35297
35620
  ======== New Request ========
35298
35621
  `);
35622
+ }
35299
35623
  if (verbose > 1) {
35300
35624
  for (const message of event.userMessage) {
35301
35625
  const userMessage = message.content;
@@ -35339,10 +35663,17 @@ ${event.systemPrompt}`);
35339
35663
  }
35340
35664
  break;
35341
35665
  case "EndRequest" /* EndRequest */:
35342
- customConsole.log(`
35666
+ if (verbose > 0) {
35667
+ customConsole.log(`
35343
35668
 
35344
35669
  ======== Request Ended ========
35345
35670
  `);
35671
+ }
35672
+ if (verbose === 0 && hasText) {
35673
+ write(`
35674
+
35675
+ `);
35676
+ }
35346
35677
  if (verbose > 1) {
35347
35678
  customConsole.log(usageMeter.getUsageText());
35348
35679
  }
@@ -35354,27 +35685,34 @@ ${event.systemPrompt}`);
35354
35685
  `);
35355
35686
  hadReasoning = false;
35356
35687
  }
35688
+ if (event.newText.trim().length > 0) {
35689
+ hasText = true;
35690
+ }
35357
35691
  write(event.newText);
35358
35692
  break;
35359
35693
  }
35360
35694
  case "Reasoning" /* Reasoning */: {
35361
- write(source_default.dim(event.newText));
35362
- hadReasoning = true;
35695
+ if (verbose > 0) {
35696
+ write(source_default.dim(event.newText));
35697
+ hadReasoning = true;
35698
+ }
35363
35699
  break;
35364
35700
  }
35365
35701
  case "ToolUse" /* ToolUse */: {
35366
- customConsole.log(source_default.yellow(`
35702
+ if (verbose > 0) {
35703
+ customConsole.log(source_default.yellow(`
35367
35704
 
35368
- Tool use:`, event.tool), event.params);
35369
- const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35705
+ Tool use:`, event.tool), simplifyToolParameters(event.tool, event.params));
35706
+ }
35707
+ const stats = taskToolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35370
35708
  stats.calls++;
35371
- toolCallStats.set(event.tool, stats);
35709
+ taskToolCallStats.set(event.tool, stats);
35372
35710
  break;
35373
35711
  }
35374
35712
  case "ToolReply" /* ToolReply */: {
35375
- const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35713
+ const stats = taskToolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35376
35714
  stats.success++;
35377
- toolCallStats.set(event.tool, stats);
35715
+ taskToolCallStats.set(event.tool, stats);
35378
35716
  break;
35379
35717
  }
35380
35718
  case "ToolError" /* ToolError */: {
@@ -35382,9 +35720,9 @@ Tool use:`, event.tool), event.params);
35382
35720
 
35383
35721
  Tool error:`, event.tool));
35384
35722
  customConsole.error(event.error);
35385
- const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35723
+ const stats = taskToolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
35386
35724
  stats.errors++;
35387
- toolCallStats.set(event.tool, stats);
35725
+ taskToolCallStats.set(event.tool, stats);
35388
35726
  break;
35389
35727
  }
35390
35728
  case "UsageExceeded" /* UsageExceeded */:
@@ -35400,27 +35738,27 @@ Tool error:`, event.tool));
35400
35738
  `);
35401
35739
  customConsole.log("Reason:", event.exitReason.type);
35402
35740
  switch (event.exitReason.type) {
35741
+ case "Error": {
35742
+ const { error: error46 } = event.exitReason;
35743
+ customConsole.error(source_default.red(`Workflow failed: ${error46.message}`));
35744
+ if (verbose > 0 && error46.stack) {
35745
+ customConsole.error(source_default.red(error46.stack));
35746
+ }
35747
+ break;
35748
+ }
35403
35749
  case "Exit" /* Exit */:
35404
35750
  customConsole.log("Exit Message:", event.exitReason.message);
35405
35751
  break;
35406
35752
  }
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.");
35753
+ for (const [tool2, taskStats] of taskToolCallStats.entries()) {
35754
+ const globalStats = globalToolCallStats.get(tool2) ?? { calls: 0, success: 0, errors: 0 };
35755
+ globalStats.calls += taskStats.calls;
35756
+ globalStats.success += taskStats.success;
35757
+ globalStats.errors += taskStats.errors;
35758
+ globalToolCallStats.set(tool2, globalStats);
35759
+ }
35760
+ if (verbose > 0) {
35761
+ logToolCallStats(stream, taskToolCallStats, "Task Tool Call Stats");
35424
35762
  }
35425
35763
  break;
35426
35764
  }
@@ -35447,12 +35785,15 @@ function readMultiline(prompt = "Enter text (Ctrl+D to finish):") {
35447
35785
  });
35448
35786
  }
35449
35787
  export {
35788
+ simplifyToolParameters,
35450
35789
  searchFiles,
35451
35790
  readMultiline,
35452
35791
  readLocalConfig,
35453
35792
  readConfig,
35454
35793
  printEvent,
35455
35794
  mergeConfigs,
35795
+ logToolCallStats,
35796
+ logGlobalToolCallStats,
35456
35797
  localConfigFileName,
35457
35798
  loadConfigAtPath,
35458
35799
  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.49",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",