@polka-codes/cli 0.4.5 → 0.4.7

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 +258 -46
  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.7";
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) => {
@@ -35047,9 +35149,9 @@ async function searchFiles(path2, regex, filePattern, cwd, excludeFiles) {
35047
35149
  }
35048
35150
 
35049
35151
  // src/provider.ts
35050
- var getProvider = (options) => {
35152
+ var getProvider = (agentName, config, options) => {
35051
35153
  const ig = import_ignore2.default().add(options.excludeFiles ?? []);
35052
- return {
35154
+ const provider2 = {
35053
35155
  readFile: async (path2) => {
35054
35156
  if (ig.ignores(path2)) {
35055
35157
  throw new Error(`Not allow to access file ${path2}`);
@@ -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
  },
@@ -35101,8 +35215,31 @@ var getProvider = (options) => {
35101
35215
  reject(err);
35102
35216
  });
35103
35217
  });
35218
+ },
35219
+ attemptCompletion: async (result) => {
35220
+ const cmd = (config.hooks?.agents?.[agentName]?.beforeCompletion ?? config.hooks?.agents?.default?.beforeCompletion)?.trim();
35221
+ if (cmd) {
35222
+ try {
35223
+ const { exitCode, stdout, stderr } = await provider2.executeCommand(cmd, false);
35224
+ if (exitCode !== 0) {
35225
+ return `
35226
+ <command>${cmd}</command>
35227
+ <command_exit_code>${exitCode}</command_exit_code>
35228
+ <command_stdout>
35229
+ ${stdout}
35230
+ </command_stdout>
35231
+ <command_stderr>
35232
+ ${stderr}
35233
+ </command_stderr>`;
35234
+ }
35235
+ } catch (error) {
35236
+ console.warn(`Failed to execute hook: ${error}`);
35237
+ }
35238
+ }
35239
+ return;
35104
35240
  }
35105
35241
  };
35242
+ return provider2;
35106
35243
  };
35107
35244
 
35108
35245
  // src/Runner.ts
@@ -35126,7 +35263,7 @@ class Runner {
35126
35263
  if (typeof rules2 === "string") {
35127
35264
  rules2 = [rules2];
35128
35265
  }
35129
- const provider2 = getProvider({
35266
+ const providerOptions = {
35130
35267
  command: {
35131
35268
  onStarted(command) {
35132
35269
  console.log(`$ >>>> $ ${command}`);
@@ -35145,19 +35282,20 @@ class Runner {
35145
35282
  }
35146
35283
  },
35147
35284
  excludeFiles: options.config.excludeFiles
35148
- });
35285
+ };
35149
35286
  const platform = os.platform();
35150
35287
  const agents = [coderAgentInfo, architectAgentInfo];
35151
35288
  this.#multiAgent = new MultiAgent({
35152
35289
  createAgent: async (name) => {
35153
- switch (name.trim().toLowerCase()) {
35290
+ const agentName = name.trim().toLowerCase();
35291
+ switch (agentName) {
35154
35292
  case coderAgentInfo.name.toLowerCase():
35155
35293
  return new CoderAgent({
35156
35294
  ai: service,
35157
35295
  os: platform,
35158
35296
  customInstructions: rules2,
35159
35297
  scripts: options.config.scripts,
35160
- provider: provider2,
35298
+ provider: getProvider("coder", options.config, providerOptions),
35161
35299
  interactive: options.interactive,
35162
35300
  agents
35163
35301
  });
@@ -35167,7 +35305,7 @@ class Runner {
35167
35305
  os: platform,
35168
35306
  customInstructions: rules2,
35169
35307
  scripts: options.config.scripts,
35170
- provider: provider2,
35308
+ provider: getProvider("architect", options.config, providerOptions),
35171
35309
  interactive: options.interactive,
35172
35310
  agents
35173
35311
  });
@@ -39306,6 +39444,8 @@ var z2 = /* @__PURE__ */ Object.freeze({
39306
39444
  });
39307
39445
 
39308
39446
  // src/config.ts
39447
+ var agentNames = z2.enum(["coder", "architect"]);
39448
+ var agentNameOrDefault = z2.union([agentNames, z2.literal("default")]);
39309
39449
  var providerModelSchema = z2.object({
39310
39450
  provider: z2.string().optional(),
39311
39451
  model: z2.string().optional()
@@ -39324,13 +39464,14 @@ var configSchema = z2.object({
39324
39464
  defaultProvider: z2.string().optional(),
39325
39465
  defaultModel: z2.string().optional(),
39326
39466
  maxIterations: z2.number().int().positive().optional(),
39467
+ hooks: z2.object({
39468
+ agents: z2.record(agentNameOrDefault, z2.object({ beforeCompletion: z2.string().optional() })).optional()
39469
+ }).optional(),
39327
39470
  scripts: z2.record(z2.string(), z2.string().or(z2.object({
39328
39471
  command: z2.string(),
39329
39472
  description: z2.string()
39330
39473
  }))).optional(),
39331
- agents: z2.object({
39332
- default: agentSchema.optional()
39333
- }).catchall(agentSchema).optional(),
39474
+ agents: z2.record(agentNameOrDefault, agentSchema).optional(),
39334
39475
  commands: z2.object({
39335
39476
  default: providerModelSchema.optional()
39336
39477
  }).catchall(providerModelSchema).optional(),
@@ -39416,7 +39557,7 @@ var readConfig = (path2) => {
39416
39557
 
39417
39558
  // src/options.ts
39418
39559
  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);
39560
+ 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
39561
  }
39421
39562
 
39422
39563
  class ApiProviderConfig {
@@ -39485,6 +39626,7 @@ function parseOptions(options, cwd = process.cwd(), home = os2.homedir()) {
39485
39626
  });
39486
39627
  return {
39487
39628
  maxIterations: options.maxIterations ?? 30,
39629
+ verbose: options.verbose ?? 0,
39488
39630
  config,
39489
39631
  providerConfig
39490
39632
  };
@@ -39975,13 +40117,32 @@ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
39975
40117
  var source_default = chalk;
39976
40118
 
39977
40119
  // src/utils/eventHandler.ts
39978
- var printEvent = (event) => {
40120
+ var printEvent = (verbose) => (event) => {
40121
+ let hadReasoning = false;
39979
40122
  switch (event.kind) {
40123
+ case "StartTask" /* StartTask */:
40124
+ if (verbose > 1) {
40125
+ console.log(`
40126
+ ====== System Prompt ======
40127
+ ${event.systemPrompt}`);
40128
+ console.log(`
40129
+
40130
+ ================
40131
+ `);
40132
+ }
40133
+ break;
39980
40134
  case "StartRequest" /* StartRequest */:
39981
40135
  console.log(`
39982
40136
 
39983
40137
  ======== New Request ========
39984
40138
  `);
40139
+ if (verbose) {
40140
+ console.log(event.userMessage);
40141
+ console.log(`
40142
+
40143
+ ======== Request Message Ended ========
40144
+ `);
40145
+ }
39985
40146
  break;
39986
40147
  case "EndRequest" /* EndRequest */:
39987
40148
  console.log(`
@@ -39992,10 +40153,17 @@ var printEvent = (event) => {
39992
40153
  case "Usage" /* Usage */:
39993
40154
  break;
39994
40155
  case "Text" /* Text */:
40156
+ if (hadReasoning) {
40157
+ process.stdout.write(`
40158
+
40159
+ `);
40160
+ hadReasoning = false;
40161
+ }
39995
40162
  process.stdout.write(event.newText);
39996
40163
  break;
39997
40164
  case "Reasoning" /* Reasoning */:
39998
40165
  process.stdout.write(source_default.dim(event.newText));
40166
+ hadReasoning = true;
39999
40167
  break;
40000
40168
  case "ToolUse" /* ToolUse */:
40001
40169
  break;
@@ -40591,15 +40759,15 @@ function useKeypress(userHandler) {
40591
40759
  signal.current = userHandler;
40592
40760
  useEffect((rl) => {
40593
40761
  let ignore3 = false;
40594
- const handler11 = withUpdates((_input, event) => {
40762
+ const handler13 = withUpdates((_input, event) => {
40595
40763
  if (ignore3)
40596
40764
  return;
40597
40765
  signal.current(event, rl);
40598
40766
  });
40599
- rl.input.on("keypress", handler11);
40767
+ rl.input.on("keypress", handler13);
40600
40768
  return () => {
40601
40769
  ignore3 = true;
40602
- rl.input.removeListener("keypress", handler11);
40770
+ rl.input.removeListener("keypress", handler13);
40603
40771
  };
40604
40772
  }, []);
40605
40773
  }
@@ -40781,16 +40949,16 @@ class Emitter {
40781
40949
 
40782
40950
  class SignalExitBase {
40783
40951
  }
40784
- var signalExitWrap = (handler11) => {
40952
+ var signalExitWrap = (handler13) => {
40785
40953
  return {
40786
40954
  onExit(cb, opts) {
40787
- return handler11.onExit(cb, opts);
40955
+ return handler13.onExit(cb, opts);
40788
40956
  },
40789
40957
  load() {
40790
- return handler11.load();
40958
+ return handler13.load();
40791
40959
  },
40792
40960
  unload() {
40793
- return handler11.unload();
40961
+ return handler13.unload();
40794
40962
  }
40795
40963
  };
40796
40964
  };
@@ -41470,7 +41638,7 @@ async function printConfig(configPath) {
41470
41638
  }
41471
41639
  console.log($stringify(config));
41472
41640
  }
41473
- async function configCommand(options) {
41641
+ 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
41642
  const globalConfigPath = getGlobalConfigPath();
41475
41643
  let configPath = options.global ? globalConfigPath : localConfigFileName;
41476
41644
  if (options.print) {
@@ -41557,12 +41725,11 @@ ${provider2.toUpperCase()}_API_KEY=${apiKey}`;
41557
41725
  mkdirSync(dirname2(configPath), { recursive: true });
41558
41726
  writeFileSync(configPath, $stringify(newConfig));
41559
41727
  console.log(`Config file saved at: ${configPath}`);
41560
- return;
41561
- }
41728
+ });
41562
41729
 
41563
41730
  // src/commands/chat.ts
41564
41731
  var runChat = async (options) => {
41565
- const { config, providerConfig, maxIterations } = parseOptions(options);
41732
+ const { config, providerConfig, maxIterations, verbose } = parseOptions(options);
41566
41733
  let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent("coder") ?? {};
41567
41734
  if (!provider2) {
41568
41735
  const newConfig = await configPrompt({ provider: provider2, model, apiKey });
@@ -41582,7 +41749,7 @@ var runChat = async (options) => {
41582
41749
  config: config ?? {},
41583
41750
  maxIterations,
41584
41751
  interactive: true,
41585
- eventCallback: printEvent
41752
+ eventCallback: printEvent(verbose)
41586
41753
  });
41587
41754
  let taskInfo;
41588
41755
  const chat2 = new Chat3({
@@ -42351,12 +42518,57 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
42351
42518
  });
42352
42519
 
42353
42520
  // src/commands/task.ts
42521
+ var readStdin = async (timeoutMs = 30000) => {
42522
+ if (process.stdin.isTTY) {
42523
+ return "";
42524
+ }
42525
+ return new Promise((resolve2, reject) => {
42526
+ let input = "";
42527
+ let timeoutId = undefined;
42528
+ const cleanup = () => {
42529
+ if (timeoutId)
42530
+ clearTimeout(timeoutId);
42531
+ process.stdin.removeAllListeners();
42532
+ process.stdin.resume();
42533
+ };
42534
+ timeoutId = setTimeout(() => {
42535
+ cleanup();
42536
+ reject(new Error("Stdin read timeout"));
42537
+ }, timeoutMs);
42538
+ process.stdin.on("data", (chunk) => {
42539
+ input += chunk.toString();
42540
+ });
42541
+ process.stdin.on("end", () => {
42542
+ cleanup();
42543
+ if (!input) {
42544
+ reject(new Error("Empty stdin input"));
42545
+ return;
42546
+ }
42547
+ resolve2(input);
42548
+ });
42549
+ process.stdin.on("error", (err) => {
42550
+ cleanup();
42551
+ reject(err);
42552
+ });
42553
+ });
42554
+ };
42354
42555
  var runTask = async (taskArg, options) => {
42355
- if (!taskArg) {
42356
- runChat(options);
42357
- return;
42556
+ let task = taskArg;
42557
+ if (!task) {
42558
+ try {
42559
+ const stdinInput = await readStdin();
42560
+ if (stdinInput) {
42561
+ task = stdinInput;
42562
+ } else {
42563
+ runChat(options);
42564
+ return;
42565
+ }
42566
+ } catch (error) {
42567
+ console.error("Error reading stdin:", error);
42568
+ process.exit(1);
42569
+ }
42358
42570
  }
42359
- const { providerConfig, config, maxIterations } = parseOptions(options);
42571
+ const { providerConfig, config, maxIterations, verbose } = parseOptions(options);
42360
42572
  let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent("coder") ?? {};
42361
42573
  if (!provider2) {
42362
42574
  const newConfig = await configPrompt({ provider: provider2, model, apiKey });
@@ -42373,18 +42585,18 @@ var runTask = async (taskArg, options) => {
42373
42585
  config: config ?? {},
42374
42586
  maxIterations,
42375
42587
  interactive: false,
42376
- eventCallback: printEvent
42588
+ eventCallback: printEvent(verbose)
42377
42589
  });
42378
- await runner.startTask(taskArg);
42590
+ await runner.startTask(task);
42379
42591
  runner.printUsage();
42380
42592
  };
42381
42593
 
42382
42594
  // src/index.ts
42383
42595
  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);
42596
+ program2.name("polka-codes").description("Polka Codes CLI").version(version);
42387
42597
  program2.argument("[task]", "The task to execute").action(runTask);
42598
+ program2.command("chat").description("Start an interactive chat session").action(runChat);
42599
+ program2.addCommand(configCommand);
42388
42600
  program2.addCommand(commitCommand);
42389
42601
  program2.addCommand(prCommand);
42390
42602
  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.7",
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",