@polka-codes/cli 0.4.5 → 0.4.6

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 +221 -36
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -24629,7 +24629,7 @@ var {
24629
24629
  Help
24630
24630
  } = import__.default;
24631
24631
  // package.json
24632
- var version = "0.4.5";
24632
+ var version = "0.4.6";
24633
24633
 
24634
24634
  // ../../node_modules/@anthropic-ai/sdk/version.mjs
24635
24635
  var VERSION = "0.36.2";
@@ -33240,12 +33240,8 @@ var capabilities = (toolNamePrefix) => `
33240
33240
 
33241
33241
  CAPABILITIES
33242
33242
 
33243
- - You have access to a range of tools to aid you in your work. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
33244
- - When the user initially gives you a task, a recursive list of all filepaths in the current working directory will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further.
33245
- - You can use ${toolNamePrefix}search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
33246
- - You can use the ${toolNamePrefix}list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
33247
- \t- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use ${toolNamePrefix}list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then ${toolNamePrefix}read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the ${toolNamePrefix}replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use ${toolNamePrefix}search_files to ensure you update other files as needed.
33248
- - You can use the ${toolNamePrefix}execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.`;
33243
+ - You have access to a range of tools to aid you in your work. These tools help you effectively accomplish a wide range of tasks.
33244
+ - When the user initially gives you a task, a recursive list of all filepaths in the current working directory will be included in context. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further.`;
33249
33245
  var systemInformation = (info) => `
33250
33246
  ====
33251
33247
 
@@ -33310,7 +33306,7 @@ ${joined}`;
33310
33306
  };
33311
33307
  var responsePrompts = {
33312
33308
  errorInvokeTool: (tool, error) => `An error occurred while invoking the tool "${tool}": ${error}`,
33313
- requireUseTool: "Error: You must use a tool before proceeding",
33309
+ requireUseTool: "Error: You must use a tool before proceeding. Making sure the tool is invoked using xml tags.",
33314
33310
  toolResults: (tool, result) => `<tool_response>
33315
33311
  <tool_name>${tool}</tool_name>
33316
33312
  <tool_result>
@@ -33364,6 +33360,7 @@ ${agents}`;
33364
33360
  text += `
33365
33361
  <context>${context}</context>`;
33366
33362
  }
33363
+ callback({ kind: "StartTask" /* StartTask */, info: taskInfo, systemPrompt: this.config.systemPrompt });
33367
33364
  return await this.#processLoop(text, taskInfo, callback);
33368
33365
  }
33369
33366
  async#processLoop(userMessage, taskInfo, callback) {
@@ -33507,6 +33504,8 @@ __export(exports_allTools, {
33507
33504
  writeToFile: () => writeToFile_default,
33508
33505
  searchFiles: () => searchFiles_default,
33509
33506
  replaceInFile: () => replaceInFile_default,
33507
+ renameFile: () => renameFile_default,
33508
+ removeFile: () => removeFile_default,
33510
33509
  readFile: () => readFile_default,
33511
33510
  listFiles: () => listFiles_default,
33512
33511
  listCodeDefinitionNames: () => listCodeDefinitionNames_default,
@@ -33590,7 +33589,7 @@ var getStringArray = (args, name, defaultValue) => {
33590
33589
  if (ret === "") {
33591
33590
  return [];
33592
33591
  }
33593
- return ret.split(",");
33592
+ return ret.split(",").map((s2) => s2.trim());
33594
33593
  };
33595
33594
  var getBoolean = (args, name, defaultValue) => {
33596
33595
  const ret = args[name];
@@ -34222,7 +34221,7 @@ var handler9 = async (provider, args) => {
34222
34221
  await provider.writeFile(path, content);
34223
34222
  return {
34224
34223
  type: "Reply" /* Reply */,
34225
- message: `<write_file_path>${path}</write_file_path><status>Success</status>`
34224
+ message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
34226
34225
  };
34227
34226
  };
34228
34227
  var isAvailable9 = (provider) => {
@@ -34259,7 +34258,7 @@ var toolInfo10 = {
34259
34258
  {
34260
34259
  name: "files",
34261
34260
  description: "The files relevant to the task",
34262
- required: true,
34261
+ required: false,
34263
34262
  usageValue: "Relevant files"
34264
34263
  }
34265
34264
  ],
@@ -34308,6 +34307,109 @@ var handOver_default = {
34308
34307
  handler: handler10,
34309
34308
  isAvailable: isAvailable10
34310
34309
  };
34310
+ // ../core/src/tools/removeFile.ts
34311
+ var toolInfo11 = {
34312
+ name: "remove_file",
34313
+ description: "Request to remove a file at the specified path.",
34314
+ parameters: [
34315
+ {
34316
+ name: "path",
34317
+ description: "The path of the file to remove",
34318
+ required: true,
34319
+ usageValue: "File path here"
34320
+ }
34321
+ ],
34322
+ examples: [
34323
+ {
34324
+ description: "Request to remove a file",
34325
+ parameters: [
34326
+ {
34327
+ name: "path",
34328
+ value: "src/main.js"
34329
+ }
34330
+ ]
34331
+ }
34332
+ ]
34333
+ };
34334
+ var handler11 = async (provider, args) => {
34335
+ if (!provider.removeFile) {
34336
+ return {
34337
+ type: "Error" /* Error */,
34338
+ message: "Not possible to remove file. Abort."
34339
+ };
34340
+ }
34341
+ const path = getString(args, "path");
34342
+ await provider.removeFile(path);
34343
+ return {
34344
+ type: "Reply" /* Reply */,
34345
+ message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
34346
+ };
34347
+ };
34348
+ var isAvailable11 = (provider) => {
34349
+ return !!provider.removeFile;
34350
+ };
34351
+ var removeFile_default = {
34352
+ ...toolInfo11,
34353
+ handler: handler11,
34354
+ isAvailable: isAvailable11
34355
+ };
34356
+ // ../core/src/tools/renameFile.ts
34357
+ var toolInfo12 = {
34358
+ name: "rename_file",
34359
+ description: "Request to rename a file from source path to target path.",
34360
+ parameters: [
34361
+ {
34362
+ name: "sourcePath",
34363
+ description: "The current path of the file",
34364
+ required: true,
34365
+ usageValue: "Source file path here"
34366
+ },
34367
+ {
34368
+ name: "targetPath",
34369
+ description: "The new path for the file",
34370
+ required: true,
34371
+ usageValue: "Target file path here"
34372
+ }
34373
+ ],
34374
+ examples: [
34375
+ {
34376
+ description: "Request to rename a file",
34377
+ parameters: [
34378
+ {
34379
+ name: "sourcePath",
34380
+ value: "src/old-name.js"
34381
+ },
34382
+ {
34383
+ name: "targetPath",
34384
+ value: "src/new-name.js"
34385
+ }
34386
+ ]
34387
+ }
34388
+ ]
34389
+ };
34390
+ var handler12 = async (provider, args) => {
34391
+ if (!provider.renameFile) {
34392
+ return {
34393
+ type: "Error" /* Error */,
34394
+ message: "Not possible to rename file. Abort."
34395
+ };
34396
+ }
34397
+ const sourcePath = getString(args, "sourcePath");
34398
+ const targetPath = getString(args, "targetPath");
34399
+ await provider.renameFile(sourcePath, targetPath);
34400
+ return {
34401
+ type: "Reply" /* Reply */,
34402
+ message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
34403
+ };
34404
+ };
34405
+ var isAvailable12 = (provider) => {
34406
+ return !!provider.renameFile;
34407
+ };
34408
+ var renameFile_default = {
34409
+ ...toolInfo12,
34410
+ handler: handler12,
34411
+ isAvailable: isAvailable12
34412
+ };
34311
34413
  // ../core/src/Agent/CoderAgent/prompts.ts
34312
34414
  var basePrompt = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
34313
34415
  var editingFilesPrompt = (toolNamePrefix) => `
@@ -34917,7 +35019,7 @@ import os from "node:os";
34917
35019
  // src/provider.ts
34918
35020
  var import_ignore2 = __toESM(require_ignore(), 1);
34919
35021
  import { spawn as spawn2 } from "node:child_process";
34920
- import { mkdir, readFile, writeFile } from "node:fs/promises";
35022
+ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
34921
35023
  import { dirname } from "node:path";
34922
35024
 
34923
35025
  // src/utils/listFiles.ts
@@ -35030,7 +35132,7 @@ async function searchFiles(path2, regex, filePattern, cwd, excludeFiles) {
35030
35132
  rg.stderr.on("data", (data) => {
35031
35133
  const err = data.toString();
35032
35134
  if (!err.startsWith("WARNING:")) {
35033
- console.error(err);
35135
+ console.warn(err);
35034
35136
  }
35035
35137
  });
35036
35138
  rg.on("error", (error) => {
@@ -35063,6 +35165,18 @@ var getProvider = (options) => {
35063
35165
  await mkdir(dirname(path2), { recursive: true });
35064
35166
  return await writeFile(path2, content, "utf8");
35065
35167
  },
35168
+ removeFile: async (path2) => {
35169
+ if (ig.ignores(path2)) {
35170
+ throw new Error(`Not allow to access file ${path2}`);
35171
+ }
35172
+ return await unlink(path2);
35173
+ },
35174
+ renameFile: async (sourcePath, targetPath) => {
35175
+ if (ig.ignores(sourcePath) || ig.ignores(targetPath)) {
35176
+ throw new Error(`Not allow to access file ${sourcePath} or ${targetPath}`);
35177
+ }
35178
+ return await rename(sourcePath, targetPath);
35179
+ },
35066
35180
  listFiles: async (path2, recursive, maxCount) => {
35067
35181
  return await listFiles(path2, recursive, maxCount, dirname(path2), options.excludeFiles);
35068
35182
  },
@@ -39416,7 +39530,7 @@ var readConfig = (path2) => {
39416
39530
 
39417
39531
  // src/options.ts
39418
39532
  function addSharedOptions(command) {
39419
- return command.option("-c --config <path>", "Path to config file").option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-iterations <iterations>", "Maximum number of iterations to run. Default to 30", Number.parseInt);
39533
+ return command.option("-c --config <path>", "Path to config file").option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-iterations <iterations>", "Maximum number of iterations to run. Default to 30", Number.parseInt).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (value, prev) => prev + 1, 0);
39420
39534
  }
39421
39535
 
39422
39536
  class ApiProviderConfig {
@@ -39485,6 +39599,7 @@ function parseOptions(options, cwd = process.cwd(), home = os2.homedir()) {
39485
39599
  });
39486
39600
  return {
39487
39601
  maxIterations: options.maxIterations ?? 30,
39602
+ verbose: options.verbose ?? 0,
39488
39603
  config,
39489
39604
  providerConfig
39490
39605
  };
@@ -39975,13 +40090,32 @@ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
39975
40090
  var source_default = chalk;
39976
40091
 
39977
40092
  // src/utils/eventHandler.ts
39978
- var printEvent = (event) => {
40093
+ var printEvent = (verbose) => (event) => {
40094
+ let hadReasoning = false;
39979
40095
  switch (event.kind) {
40096
+ case "StartTask" /* StartTask */:
40097
+ if (verbose > 1) {
40098
+ console.log(`
40099
+ ====== System Prompt ======
40100
+ ${event.systemPrompt}`);
40101
+ console.log(`
40102
+
40103
+ ================
40104
+ `);
40105
+ }
40106
+ break;
39980
40107
  case "StartRequest" /* StartRequest */:
39981
40108
  console.log(`
39982
40109
 
39983
40110
  ======== New Request ========
39984
40111
  `);
40112
+ if (verbose) {
40113
+ console.log(event.userMessage);
40114
+ console.log(`
40115
+
40116
+ ======== Request Message Ended ========
40117
+ `);
40118
+ }
39985
40119
  break;
39986
40120
  case "EndRequest" /* EndRequest */:
39987
40121
  console.log(`
@@ -39992,10 +40126,17 @@ var printEvent = (event) => {
39992
40126
  case "Usage" /* Usage */:
39993
40127
  break;
39994
40128
  case "Text" /* Text */:
40129
+ if (hadReasoning) {
40130
+ process.stdout.write(`
40131
+
40132
+ `);
40133
+ hadReasoning = false;
40134
+ }
39995
40135
  process.stdout.write(event.newText);
39996
40136
  break;
39997
40137
  case "Reasoning" /* Reasoning */:
39998
40138
  process.stdout.write(source_default.dim(event.newText));
40139
+ hadReasoning = true;
39999
40140
  break;
40000
40141
  case "ToolUse" /* ToolUse */:
40001
40142
  break;
@@ -40591,15 +40732,15 @@ function useKeypress(userHandler) {
40591
40732
  signal.current = userHandler;
40592
40733
  useEffect((rl) => {
40593
40734
  let ignore3 = false;
40594
- const handler11 = withUpdates((_input, event) => {
40735
+ const handler13 = withUpdates((_input, event) => {
40595
40736
  if (ignore3)
40596
40737
  return;
40597
40738
  signal.current(event, rl);
40598
40739
  });
40599
- rl.input.on("keypress", handler11);
40740
+ rl.input.on("keypress", handler13);
40600
40741
  return () => {
40601
40742
  ignore3 = true;
40602
- rl.input.removeListener("keypress", handler11);
40743
+ rl.input.removeListener("keypress", handler13);
40603
40744
  };
40604
40745
  }, []);
40605
40746
  }
@@ -40781,16 +40922,16 @@ class Emitter {
40781
40922
 
40782
40923
  class SignalExitBase {
40783
40924
  }
40784
- var signalExitWrap = (handler11) => {
40925
+ var signalExitWrap = (handler13) => {
40785
40926
  return {
40786
40927
  onExit(cb, opts) {
40787
- return handler11.onExit(cb, opts);
40928
+ return handler13.onExit(cb, opts);
40788
40929
  },
40789
40930
  load() {
40790
- return handler11.load();
40931
+ return handler13.load();
40791
40932
  },
40792
40933
  unload() {
40793
- return handler11.unload();
40934
+ return handler13.unload();
40794
40935
  }
40795
40936
  };
40796
40937
  };
@@ -41470,7 +41611,7 @@ async function printConfig(configPath) {
41470
41611
  }
41471
41612
  console.log($stringify(config));
41472
41613
  }
41473
- async function configCommand(options) {
41614
+ var configCommand = new Command("config").description("Configure global or local settings").option("-g, --global", "Use global config").option("-p, --print", "Print config").action(async (options) => {
41474
41615
  const globalConfigPath = getGlobalConfigPath();
41475
41616
  let configPath = options.global ? globalConfigPath : localConfigFileName;
41476
41617
  if (options.print) {
@@ -41557,12 +41698,11 @@ ${provider2.toUpperCase()}_API_KEY=${apiKey}`;
41557
41698
  mkdirSync(dirname2(configPath), { recursive: true });
41558
41699
  writeFileSync(configPath, $stringify(newConfig));
41559
41700
  console.log(`Config file saved at: ${configPath}`);
41560
- return;
41561
- }
41701
+ });
41562
41702
 
41563
41703
  // src/commands/chat.ts
41564
41704
  var runChat = async (options) => {
41565
- const { config, providerConfig, maxIterations } = parseOptions(options);
41705
+ const { config, providerConfig, maxIterations, verbose } = parseOptions(options);
41566
41706
  let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent("coder") ?? {};
41567
41707
  if (!provider2) {
41568
41708
  const newConfig = await configPrompt({ provider: provider2, model, apiKey });
@@ -41582,7 +41722,7 @@ var runChat = async (options) => {
41582
41722
  config: config ?? {},
41583
41723
  maxIterations,
41584
41724
  interactive: true,
41585
- eventCallback: printEvent
41725
+ eventCallback: printEvent(verbose)
41586
41726
  });
41587
41727
  let taskInfo;
41588
41728
  const chat2 = new Chat3({
@@ -42351,12 +42491,57 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
42351
42491
  });
42352
42492
 
42353
42493
  // src/commands/task.ts
42494
+ var readStdin = async (timeoutMs = 30000) => {
42495
+ if (process.stdin.isTTY) {
42496
+ return "";
42497
+ }
42498
+ return new Promise((resolve2, reject) => {
42499
+ let input = "";
42500
+ let timeoutId = undefined;
42501
+ const cleanup = () => {
42502
+ if (timeoutId)
42503
+ clearTimeout(timeoutId);
42504
+ process.stdin.removeAllListeners();
42505
+ process.stdin.resume();
42506
+ };
42507
+ timeoutId = setTimeout(() => {
42508
+ cleanup();
42509
+ reject(new Error("Stdin read timeout"));
42510
+ }, timeoutMs);
42511
+ process.stdin.on("data", (chunk) => {
42512
+ input += chunk.toString();
42513
+ });
42514
+ process.stdin.on("end", () => {
42515
+ cleanup();
42516
+ if (!input) {
42517
+ reject(new Error("Empty stdin input"));
42518
+ return;
42519
+ }
42520
+ resolve2(input);
42521
+ });
42522
+ process.stdin.on("error", (err) => {
42523
+ cleanup();
42524
+ reject(err);
42525
+ });
42526
+ });
42527
+ };
42354
42528
  var runTask = async (taskArg, options) => {
42355
- if (!taskArg) {
42356
- runChat(options);
42357
- return;
42529
+ let task = taskArg;
42530
+ if (!task) {
42531
+ try {
42532
+ const stdinInput = await readStdin();
42533
+ if (stdinInput) {
42534
+ task = stdinInput;
42535
+ } else {
42536
+ runChat(options);
42537
+ return;
42538
+ }
42539
+ } catch (error) {
42540
+ console.error("Error reading stdin:", error);
42541
+ process.exit(1);
42542
+ }
42358
42543
  }
42359
- const { providerConfig, config, maxIterations } = parseOptions(options);
42544
+ const { providerConfig, config, maxIterations, verbose } = parseOptions(options);
42360
42545
  let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent("coder") ?? {};
42361
42546
  if (!provider2) {
42362
42547
  const newConfig = await configPrompt({ provider: provider2, model, apiKey });
@@ -42373,18 +42558,18 @@ var runTask = async (taskArg, options) => {
42373
42558
  config: config ?? {},
42374
42559
  maxIterations,
42375
42560
  interactive: false,
42376
- eventCallback: printEvent
42561
+ eventCallback: printEvent(verbose)
42377
42562
  });
42378
- await runner.startTask(taskArg);
42563
+ await runner.startTask(task);
42379
42564
  runner.printUsage();
42380
42565
  };
42381
42566
 
42382
42567
  // src/index.ts
42383
42568
  var program2 = new Command;
42384
- program2.name("polka").description("Polka Codes CLI").version(version);
42385
- program2.command("chat").description("Start an interactive chat session").action(runChat);
42386
- program2.command("config").description("Configure global or local settings").option("-g, --global", "Use global config").option("-p, --print", "Print config").action(configCommand);
42569
+ program2.name("polka-codes").description("Polka Codes CLI").version(version);
42387
42570
  program2.argument("[task]", "The task to execute").action(runTask);
42571
+ program2.command("chat").description("Start an interactive chat session").action(runChat);
42572
+ program2.addCommand(configCommand);
42388
42573
  program2.addCommand(commitCommand);
42389
42574
  program2.addCommand(prCommand);
42390
42575
  addSharedOptions(program2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "license": "AGPL-3.0",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@inquirer/prompts": "^7.2.3",
20
- "@polka-codes/core": "0.4.3",
20
+ "@polka-codes/core": "0.4.5",
21
21
  "@vscode/ripgrep": "^1.15.10",
22
22
  "chalk": "^5.4.1",
23
23
  "commander": "^13.0.0",