@polka-codes/cli 0.8.2 → 0.8.4

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 +200 -54
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31550,7 +31550,7 @@ var {
31550
31550
  Help
31551
31551
  } = import__.default;
31552
31552
  // package.json
31553
- var version = "0.8.2";
31553
+ var version = "0.8.4";
31554
31554
 
31555
31555
  // ../core/src/AiService/AiServiceBase.ts
31556
31556
  class AiServiceBase {
@@ -40930,10 +40930,16 @@ ${search}`);
40930
40930
  };
40931
40931
  // ../core/src/tools/utils/getArg.ts
40932
40932
  var getString = (args2, name2, defaultValue) => {
40933
+ if (typeof args2 !== "object" || Array.isArray(args2)) {
40934
+ throw new Error(`Invalid argument type: ${name2} ${args2}`);
40935
+ }
40933
40936
  const ret = args2[name2] ?? defaultValue;
40934
40937
  if (ret === undefined) {
40935
40938
  throw new Error(`Missing required argument: ${name2}`);
40936
40939
  }
40940
+ if (typeof ret !== "string") {
40941
+ throw new Error(`Invalid argument type: ${name2} ${ret}`);
40942
+ }
40937
40943
  return ret;
40938
40944
  };
40939
40945
  var getStringArray = (args2, name2, defaultValue) => {
@@ -40947,6 +40953,9 @@ var getStringArray = (args2, name2, defaultValue) => {
40947
40953
  if (ret === "") {
40948
40954
  return [];
40949
40955
  }
40956
+ if (typeof ret !== "string") {
40957
+ throw new Error(`Invalid argument type: ${name2} ${ret}`);
40958
+ }
40950
40959
  return ret.split(",").map((s2) => s2.trim());
40951
40960
  };
40952
40961
  var getBoolean = (args2, name2, defaultValue) => {
@@ -40957,13 +40966,16 @@ var getBoolean = (args2, name2, defaultValue) => {
40957
40966
  }
40958
40967
  return defaultValue;
40959
40968
  }
40969
+ if (typeof ret !== "string") {
40970
+ throw new Error(`Invalid argument type: ${name2} ${ret}`);
40971
+ }
40960
40972
  switch (ret.toLowerCase()) {
40961
40973
  case "true":
40962
40974
  return true;
40963
40975
  case "false":
40964
40976
  return false;
40965
40977
  default:
40966
- throw new Error(`Invalid argument value: ${name2}`);
40978
+ throw new Error(`Invalid argument value: ${name2} ${ret}`);
40967
40979
  }
40968
40980
  };
40969
40981
  var getInt = (args2, name2, defaultValue) => {
@@ -40974,50 +40986,104 @@ var getInt = (args2, name2, defaultValue) => {
40974
40986
  }
40975
40987
  return defaultValue;
40976
40988
  }
40989
+ if (typeof ret !== "string") {
40990
+ throw new Error(`Invalid argument type: ${name2} ${ret}`);
40991
+ }
40977
40992
  const parsed = Number.parseInt(ret);
40978
40993
  if (Number.isNaN(parsed)) {
40979
- throw new Error(`Invalid argument value: ${name2}`);
40994
+ throw new Error(`Invalid argument value: ${name2} ${ret}`);
40980
40995
  }
40981
40996
  return parsed;
40982
40997
  };
40998
+ var getArray = (args2, name2, defaultValue) => {
40999
+ if (typeof args2 !== "object" || Array.isArray(args2)) {
41000
+ throw new Error(`Invalid argument type: ${name2} ${args2}`);
41001
+ }
41002
+ const ret = args2[name2];
41003
+ if (ret === undefined) {
41004
+ if (defaultValue === undefined) {
41005
+ throw new Error(`Missing required argument: ${name2}`);
41006
+ }
41007
+ return defaultValue;
41008
+ }
41009
+ if (Array.isArray(ret)) {
41010
+ return ret;
41011
+ }
41012
+ return [ret];
41013
+ };
40983
41014
  // ../core/src/tools/askFollowupQuestion.ts
40984
41015
  var toolInfo = {
40985
41016
  name: "ask_followup_question",
40986
- description: "Whenever you need extra details or clarification to complete the task, pose a direct question to the user. Use this tool sparingly to avoid excessive back-and-forth. If helpful, offer multiple-choice options or examples to guide the user’s response.",
41017
+ 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.",
40987
41018
  parameters: [
40988
41019
  {
40989
- name: "question",
40990
- description: "The question to ask the user. This should be a clear, specific question that addresses the information you need.",
41020
+ name: "questions",
41021
+ description: "One or more follow-up questions you need answered before you can continue.",
40991
41022
  required: true,
40992
- usageValue: "Your question here"
40993
- },
40994
- {
40995
- name: "options",
40996
- description: "A comma separated list of possible answers to the question. Ordered by preference. If not provided, the user will be prompted to provide an answer.",
40997
- required: false,
40998
- usageValue: "A comma separated list of possible answers (optional)"
41023
+ allowMultiple: true,
41024
+ children: [
41025
+ {
41026
+ name: "prompt",
41027
+ description: "The text of the question.",
41028
+ required: true,
41029
+ usageValue: "question text here"
41030
+ },
41031
+ {
41032
+ name: "options",
41033
+ description: "Ordered list of suggested answers (omit if none).",
41034
+ required: false,
41035
+ allowMultiple: true,
41036
+ usageValue: "suggested answer here"
41037
+ }
41038
+ ]
40999
41039
  }
41000
41040
  ],
41001
41041
  examples: [
41002
41042
  {
41003
- description: "Request to ask a question",
41043
+ description: "Single clarifying question (no options)",
41004
41044
  parameters: [
41005
41045
  {
41006
- name: "question",
41007
- value: "What is the name of the project?"
41046
+ name: "questions",
41047
+ value: { prompt: "What is the target deployment environment?" }
41008
41048
  }
41009
41049
  ]
41010
41050
  },
41011
41051
  {
41012
- description: "Request to ask a question with options",
41052
+ description: "Single question with multiple-choice options",
41013
41053
  parameters: [
41014
41054
  {
41015
- name: "question",
41016
- value: "What framework do you use?"
41017
- },
41055
+ name: "questions",
41056
+ value: {
41057
+ prompt: "Which frontend framework are you using?",
41058
+ options: ["React", "Angular", "Vue", "Svelte"]
41059
+ }
41060
+ }
41061
+ ]
41062
+ },
41063
+ {
41064
+ description: "Two related questions in one call",
41065
+ parameters: [
41018
41066
  {
41019
- name: "options",
41020
- value: "React,Angular,Vue,Svelte"
41067
+ name: "questions",
41068
+ value: [
41069
+ { prompt: "What type of application are you building?" },
41070
+ {
41071
+ prompt: "Preferred programming language?",
41072
+ options: ["JavaScript", "TypeScript", "Python", "Java"]
41073
+ }
41074
+ ]
41075
+ }
41076
+ ]
41077
+ },
41078
+ {
41079
+ description: "Binary (yes/no) confirmation",
41080
+ parameters: [
41081
+ {
41082
+ name: "questions",
41083
+ value: {
41084
+ prompt: "Is it acceptable to refactor existing tests to improve performance?",
41085
+ options: ["Yes", "No"]
41086
+ }
41021
41087
  }
41022
41088
  ]
41023
41089
  }
@@ -41031,13 +41097,26 @@ var handler = async (provider, args2) => {
41031
41097
  message: "Not possible to ask followup question. Abort."
41032
41098
  };
41033
41099
  }
41034
- const question = getString(args2, "question");
41035
- const options = getStringArray(args2, "options", []);
41036
- const answer = await provider.askFollowupQuestion(question, options);
41100
+ const questions = getArray(args2, "questions");
41101
+ if (!questions || questions.length === 0) {
41102
+ return {
41103
+ type: "Error" /* Error */,
41104
+ message: "No questions provided"
41105
+ };
41106
+ }
41107
+ const answers = [];
41108
+ for (const question of questions) {
41109
+ const prompt = getString(question, "prompt");
41110
+ const options = getArray(question, "options", []);
41111
+ const answer = await provider.askFollowupQuestion(prompt, options);
41112
+ answers.push(`<ask_followup_question_answer question="${prompt}">
41113
+ ${answer}
41114
+ </ask_followup_question_answer>`);
41115
+ }
41037
41116
  return {
41038
41117
  type: "Reply" /* Reply */,
41039
- message: `<ask_followup_question_question>${question}</ask_followup_question_question>
41040
- <ask_followup_question_answer>${answer}</ask_followup_question_answer>`
41118
+ message: answers.join(`
41119
+ `)
41041
41120
  };
41042
41121
  };
41043
41122
  var isAvailable = (provider) => {
@@ -41174,33 +41253,27 @@ var delegate_default = {
41174
41253
  // ../core/src/tools/executeCommand.ts
41175
41254
  var toolInfo4 = {
41176
41255
  name: "execute_command",
41177
- description: `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.`,
41256
+ 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. After an `execute_command` call, no other tool calls are allowed in the same assistant response.",
41178
41257
  parameters: [
41179
41258
  {
41180
41259
  name: "command",
41181
- description: "The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.",
41260
+ description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.",
41182
41261
  required: true,
41183
- usageValue: "Your command here"
41262
+ usageValue: "your-command-here"
41184
41263
  },
41185
41264
  {
41186
41265
  name: "requires_approval",
41187
- description: `A boolean indicating whether this command requires explicit user approval before execution in case the user has auto-approve mode enabled. Set to 'true' for potentially impactful operations like installing/uninstalling packages, deleting/overwriting files, system configuration changes, network operations, or any commands that could have unintended side effects. Set to 'false' for safe operations like reading files/directories, running development servers, building projects, and other non-destructive operations.`,
41266
+ description: "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).",
41188
41267
  required: false,
41189
- usageValue: "true or false"
41268
+ usageValue: "true | false"
41190
41269
  }
41191
41270
  ],
41192
41271
  examples: [
41193
41272
  {
41194
- description: "Request to execute a command",
41273
+ description: "Make a build",
41195
41274
  parameters: [
41196
- {
41197
- name: "command",
41198
- value: "npm run dev"
41199
- },
41200
- {
41201
- name: "requires_approval",
41202
- value: "false"
41203
- }
41275
+ { name: "command", value: "npm run build" },
41276
+ { name: "requires_approval", value: "false" }
41204
41277
  ]
41205
41278
  }
41206
41279
  ],
@@ -42162,6 +42235,23 @@ var getAvailableTools = ({
42162
42235
  };
42163
42236
 
42164
42237
  // ../core/src/Agent/parseAssistantMessage.ts
42238
+ function parseNestedParameters(content, parameterPrefix) {
42239
+ const result = {};
42240
+ const nestedParamRegex = new RegExp(`<${parameterPrefix}([^>]+)>([\\s\\S]*?)<\\/${parameterPrefix}\\1>`, "gs");
42241
+ while (true) {
42242
+ const match = nestedParamRegex.exec(content);
42243
+ if (match === null)
42244
+ break;
42245
+ const paramName = match[1];
42246
+ const paramContent = match[2].trim();
42247
+ if (paramContent.includes(`<${parameterPrefix}`)) {
42248
+ result[paramName] = parseNestedParameters(paramContent, parameterPrefix);
42249
+ } else {
42250
+ result[paramName] = paramContent;
42251
+ }
42252
+ }
42253
+ return result;
42254
+ }
42165
42255
  function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
42166
42256
  const parameterPrefix = `${toolNamePrefix}parameter_`;
42167
42257
  const results = [];
@@ -42190,10 +42280,25 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
42190
42280
  for (const param of tool.parameters) {
42191
42281
  const paramName = `${parameterPrefix}${param.name}`;
42192
42282
  const escapedParamName = paramName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
42193
- const paramPattern = `<${escapedParamName}>([\\s\\S]*?)<\\/${escapedParamName}>`;
42194
- const paramMatch = fullTagContent.match(new RegExp(paramPattern, "s"));
42195
- if (paramMatch) {
42196
- params[param.name] = paramMatch[1].trim();
42283
+ const paramRegex = new RegExp(`<${escapedParamName}>([\\s\\S]*?)<\\/${escapedParamName}>`, "gs");
42284
+ const paramMatches = [];
42285
+ while (true) {
42286
+ const paramMatch = paramRegex.exec(fullTagContent);
42287
+ if (paramMatch === null)
42288
+ break;
42289
+ paramMatches.push(paramMatch[1].trim());
42290
+ }
42291
+ if (paramMatches.length > 0) {
42292
+ if (paramMatches.length === 1) {
42293
+ const paramContent = paramMatches[0];
42294
+ if (paramContent.includes(`<${parameterPrefix}`)) {
42295
+ params[param.name] = parseNestedParameters(paramContent, parameterPrefix);
42296
+ } else {
42297
+ params[param.name] = paramContent;
42298
+ }
42299
+ } else {
42300
+ params[param.name] = paramMatches;
42301
+ }
42197
42302
  }
42198
42303
  }
42199
42304
  results.push({
@@ -42225,6 +42330,20 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
42225
42330
  }
42226
42331
 
42227
42332
  // ../core/src/Agent/prompts.ts
42333
+ var renderParameterValue = (key, value, parameterPrefix) => {
42334
+ if (typeof value === "string") {
42335
+ return `<${parameterPrefix}${key}>${value}</${parameterPrefix}${key}>`;
42336
+ }
42337
+ if (Array.isArray(value)) {
42338
+ return value.map((v2) => renderParameterValue(key, v2, parameterPrefix)).join(`
42339
+ `);
42340
+ }
42341
+ const inner = Object.entries(value).map(([key2, v2]) => renderParameterValue(key2, v2, parameterPrefix)).join(`
42342
+ `);
42343
+ return `<${parameterPrefix}${key}>
42344
+ ${inner}
42345
+ </${parameterPrefix}${key}>`;
42346
+ };
42228
42347
  var toolInfoPrompt = (tool, toolNamePrefix, parameterPrefix) => `
42229
42348
  ## ${toolNamePrefix}${tool.name}
42230
42349
 
@@ -42239,11 +42358,11 @@ Usage:
42239
42358
  ${tool.parameters.map((param) => `<${parameterPrefix}${param.name}>${param.usageValue}</${parameterPrefix}${param.name}>`).join(`
42240
42359
  `)}
42241
42360
  </${toolNamePrefix}${tool.name}>`;
42242
- var toolInfoExamplesPrompt = (idx, tool, example, toolNamePrefix, parameterPrefix) => `
42243
- ## Example ${idx + 1}: ${example.description}
42361
+ var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) => `
42362
+ ## Example: ${example.description}
42244
42363
 
42245
42364
  <${toolNamePrefix}${tool.name}>
42246
- ${example.parameters.map((param) => `<${parameterPrefix}${param.name}>${param.value}</${parameterPrefix}${param.name}>`).join(`
42365
+ ${example.parameters.map((param) => `${renderParameterValue(param.name, param.value, parameterPrefix)}`).join(`
42247
42366
  `)}
42248
42367
  </${toolNamePrefix}${tool.name}>
42249
42368
  `;
@@ -42252,7 +42371,6 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
42252
42371
  return "";
42253
42372
  }
42254
42373
  const parameterPrefix = `${toolNamePrefix}parameter_`;
42255
- let exampleIndex = 0;
42256
42374
  return `
42257
42375
  ====
42258
42376
 
@@ -42270,11 +42388,39 @@ Tool use is formatted using XML-style tags. The tool name is enclosed in opening
42270
42388
  ...
42271
42389
  </${toolNamePrefix}tool_name>
42272
42390
 
42273
- For example:
42391
+ ## Array Parameters
42392
+
42393
+ To create an array of values for a parameter, repeat the parameter tag multiple times:
42394
+
42395
+ <${toolNamePrefix}process_file>
42396
+ <${parameterPrefix}path>test.ts</${parameterPrefix}path>
42397
+ <${parameterPrefix}path>main.ts</${parameterPrefix}path>
42398
+ </${toolNamePrefix}process_file>
42399
+
42400
+ ## Nested Object Parameters
42401
+
42402
+ To create nested objects, nest parameter tags within other parameter tags:
42403
+
42404
+ <${toolNamePrefix}example_tool>
42405
+ <${parameterPrefix}key>
42406
+ <${parameterPrefix}key2>value</${parameterPrefix}key2>
42407
+ <${parameterPrefix}key3>value2</${parameterPrefix}key3>
42408
+ </${parameterPrefix}key>
42409
+ </${toolNamePrefix}example_tool>
42410
+
42411
+ You can also combine array parameters with nested objects:
42274
42412
 
42275
- <${toolNamePrefix}read_file>
42276
- <${parameterPrefix}path>src/main.js</${parameterPrefix}path>
42277
- </${toolNamePrefix}read_file>
42413
+ <${toolNamePrefix}example_tool>
42414
+ <${parameterPrefix}key>
42415
+ <${parameterPrefix}key2>value</${parameterPrefix}key2>
42416
+ <${parameterPrefix}key3>value2</${parameterPrefix}key3>
42417
+ </${parameterPrefix}key>
42418
+ <${parameterPrefix}key>
42419
+ <${parameterPrefix}key2>value3</${parameterPrefix}key2>
42420
+ <${parameterPrefix}key3>value4</${parameterPrefix}key3>
42421
+ <${parameterPrefix}key3>value5</${parameterPrefix}key3>
42422
+ </${parameterPrefix}key>
42423
+ </${toolNamePrefix}example_tool>
42278
42424
 
42279
42425
  Always adhere to this format for the tool use to ensure proper parsing and execution.
42280
42426
 
@@ -42288,7 +42434,7 @@ ${tools.map((tool) => toolInfoPrompt(tool, toolNamePrefix, parameterPrefix)).joi
42288
42434
  ${tools.map((tool) => {
42289
42435
  let promp = "";
42290
42436
  for (const example of tool.examples ?? []) {
42291
- promp += toolInfoExamplesPrompt(exampleIndex++, tool, example, toolNamePrefix, parameterPrefix);
42437
+ promp += toolInfoExamplesPrompt(tool, example, toolNamePrefix, parameterPrefix);
42292
42438
  }
42293
42439
  return promp;
42294
42440
  }).join("")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",