@polka-codes/cli 0.9.9 → 0.9.10

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 +186 -97
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -677,7 +677,11 @@ var require_help = __commonJS((exports) => {
677
677
  extraInfo.push(`env: ${option.envVar}`);
678
678
  }
679
679
  if (extraInfo.length > 0) {
680
- return `${option.description} (${extraInfo.join(", ")})`;
680
+ const extraDescription = `(${extraInfo.join(", ")})`;
681
+ if (option.description) {
682
+ return `${option.description} ${extraDescription}`;
683
+ }
684
+ return extraDescription;
681
685
  }
682
686
  return option.description;
683
687
  }
@@ -698,6 +702,27 @@ var require_help = __commonJS((exports) => {
698
702
  }
699
703
  return argument.description;
700
704
  }
705
+ formatItemList(heading, items, helper) {
706
+ if (items.length === 0)
707
+ return [];
708
+ return [helper.styleTitle(heading), ...items, ""];
709
+ }
710
+ groupItems(unsortedItems, visibleItems, getGroup) {
711
+ const result = new Map;
712
+ unsortedItems.forEach((item) => {
713
+ const group = getGroup(item);
714
+ if (!result.has(group))
715
+ result.set(group, []);
716
+ });
717
+ visibleItems.forEach((item) => {
718
+ const group = getGroup(item);
719
+ if (!result.has(group)) {
720
+ result.set(group, []);
721
+ }
722
+ result.get(group).push(item);
723
+ });
724
+ return result;
725
+ }
701
726
  formatHelp(cmd, helper) {
702
727
  const termWidth = helper.padWidth(cmd, helper);
703
728
  const helpWidth = helper.helpWidth ?? 80;
@@ -718,45 +743,27 @@ var require_help = __commonJS((exports) => {
718
743
  const argumentList = helper.visibleArguments(cmd).map((argument) => {
719
744
  return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
720
745
  });
721
- if (argumentList.length > 0) {
722
- output = output.concat([
723
- helper.styleTitle("Arguments:"),
724
- ...argumentList,
725
- ""
726
- ]);
727
- }
728
- const optionList = helper.visibleOptions(cmd).map((option) => {
729
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
746
+ output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
747
+ const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
748
+ optionGroups.forEach((options, group) => {
749
+ const optionList = options.map((option) => {
750
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
751
+ });
752
+ output = output.concat(this.formatItemList(group, optionList, helper));
730
753
  });
731
- if (optionList.length > 0) {
732
- output = output.concat([
733
- helper.styleTitle("Options:"),
734
- ...optionList,
735
- ""
736
- ]);
737
- }
738
754
  if (helper.showGlobalOptions) {
739
755
  const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
740
756
  return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
741
757
  });
742
- if (globalOptionList.length > 0) {
743
- output = output.concat([
744
- helper.styleTitle("Global Options:"),
745
- ...globalOptionList,
746
- ""
747
- ]);
748
- }
758
+ output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
749
759
  }
750
- const commandList = helper.visibleCommands(cmd).map((cmd2) => {
751
- return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(cmd2)), helper.styleSubcommandDescription(helper.subcommandDescription(cmd2)));
760
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
761
+ commandGroups.forEach((commands, group) => {
762
+ const commandList = commands.map((sub) => {
763
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
764
+ });
765
+ output = output.concat(this.formatItemList(group, commandList, helper));
752
766
  });
753
- if (commandList.length > 0) {
754
- output = output.concat([
755
- helper.styleTitle("Commands:"),
756
- ...commandList,
757
- ""
758
- ]);
759
- }
760
767
  return output.join(`
761
768
  `);
762
769
  }
@@ -913,6 +920,7 @@ var require_option = __commonJS((exports) => {
913
920
  this.argChoices = undefined;
914
921
  this.conflictsWith = [];
915
922
  this.implied = undefined;
923
+ this.helpGroupHeading = undefined;
916
924
  }
917
925
  default(value, description) {
918
926
  this.defaultValue = value;
@@ -982,6 +990,10 @@ var require_option = __commonJS((exports) => {
982
990
  }
983
991
  return camelcase(this.name());
984
992
  }
993
+ helpGroup(heading) {
994
+ this.helpGroupHeading = heading;
995
+ return this;
996
+ }
985
997
  is(arg) {
986
998
  return this.short === arg || this.long === arg;
987
999
  }
@@ -1199,6 +1211,9 @@ var require_command = __commonJS((exports) => {
1199
1211
  this._addImplicitHelpCommand = undefined;
1200
1212
  this._helpCommand = undefined;
1201
1213
  this._helpConfiguration = {};
1214
+ this._helpGroupHeading = undefined;
1215
+ this._defaultCommandGroup = undefined;
1216
+ this._defaultOptionGroup = undefined;
1202
1217
  }
1203
1218
  copyInheritedSettings(sourceCommand) {
1204
1219
  this._outputConfiguration = sourceCommand._outputConfiguration;
@@ -1263,7 +1278,7 @@ var require_command = __commonJS((exports) => {
1263
1278
  configureOutput(configuration) {
1264
1279
  if (configuration === undefined)
1265
1280
  return this._outputConfiguration;
1266
- Object.assign(this._outputConfiguration, configuration);
1281
+ this._outputConfiguration = Object.assign({}, this._outputConfiguration, configuration);
1267
1282
  return this;
1268
1283
  }
1269
1284
  showHelpAfterError(displayHelp = true) {
@@ -1294,12 +1309,12 @@ var require_command = __commonJS((exports) => {
1294
1309
  createArgument(name, description) {
1295
1310
  return new Argument(name, description);
1296
1311
  }
1297
- argument(name, description, fn, defaultValue) {
1312
+ argument(name, description, parseArg, defaultValue) {
1298
1313
  const argument = this.createArgument(name, description);
1299
- if (typeof fn === "function") {
1300
- argument.default(defaultValue).argParser(fn);
1314
+ if (typeof parseArg === "function") {
1315
+ argument.default(defaultValue).argParser(parseArg);
1301
1316
  } else {
1302
- argument.default(fn);
1317
+ argument.default(parseArg);
1303
1318
  }
1304
1319
  this.addArgument(argument);
1305
1320
  return this;
@@ -1324,10 +1339,13 @@ var require_command = __commonJS((exports) => {
1324
1339
  helpCommand(enableOrNameAndArgs, description) {
1325
1340
  if (typeof enableOrNameAndArgs === "boolean") {
1326
1341
  this._addImplicitHelpCommand = enableOrNameAndArgs;
1342
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
1343
+ this._initCommandGroup(this._getHelpCommand());
1344
+ }
1327
1345
  return this;
1328
1346
  }
1329
- enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
1330
- const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
1347
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
1348
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
1331
1349
  const helpDescription = description ?? "display help for command";
1332
1350
  const helpCommand = this.createCommand(helpName);
1333
1351
  helpCommand.helpOption(false);
@@ -1337,6 +1355,8 @@ var require_command = __commonJS((exports) => {
1337
1355
  helpCommand.description(helpDescription);
1338
1356
  this._addImplicitHelpCommand = true;
1339
1357
  this._helpCommand = helpCommand;
1358
+ if (enableOrNameAndArgs || description)
1359
+ this._initCommandGroup(helpCommand);
1340
1360
  return this;
1341
1361
  }
1342
1362
  addHelpCommand(helpCommand, deprecatedDescription) {
@@ -1346,6 +1366,7 @@ var require_command = __commonJS((exports) => {
1346
1366
  }
1347
1367
  this._addImplicitHelpCommand = true;
1348
1368
  this._helpCommand = helpCommand;
1369
+ this._initCommandGroup(helpCommand);
1349
1370
  return this;
1350
1371
  }
1351
1372
  _getHelpCommand() {
@@ -1425,6 +1446,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1425
1446
  throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1426
1447
  - already used by option '${matchingOption.flags}'`);
1427
1448
  }
1449
+ this._initOptionGroup(option);
1428
1450
  this.options.push(option);
1429
1451
  }
1430
1452
  _registerCommand(command) {
@@ -1437,6 +1459,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1437
1459
  const newCmd = knownBy(command).join("|");
1438
1460
  throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
1439
1461
  }
1462
+ this._initCommandGroup(command);
1440
1463
  this.commands.push(command);
1441
1464
  }
1442
1465
  addOption(option) {
@@ -1981,6 +2004,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
1981
2004
  function maybeOption(arg) {
1982
2005
  return arg.length > 1 && arg[0] === "-";
1983
2006
  }
2007
+ const negativeNumberArg = (arg) => {
2008
+ if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg))
2009
+ return false;
2010
+ return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
2011
+ };
1984
2012
  let activeVariadicOption = null;
1985
2013
  while (args.length) {
1986
2014
  const arg = args.shift();
@@ -1990,7 +2018,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1990
2018
  dest.push(...args);
1991
2019
  break;
1992
2020
  }
1993
- if (activeVariadicOption && !maybeOption(arg)) {
2021
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
1994
2022
  this.emit(`option:${activeVariadicOption.name()}`, arg);
1995
2023
  continue;
1996
2024
  }
@@ -2005,7 +2033,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2005
2033
  this.emit(`option:${option.name()}`, value);
2006
2034
  } else if (option.optional) {
2007
2035
  let value = null;
2008
- if (args.length > 0 && !maybeOption(args[0])) {
2036
+ if (args.length > 0 && (!maybeOption(args[0]) || negativeNumberArg(args[0]))) {
2009
2037
  value = args.shift();
2010
2038
  }
2011
2039
  this.emit(`option:${option.name()}`, value);
@@ -2036,7 +2064,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2036
2064
  continue;
2037
2065
  }
2038
2066
  }
2039
- if (maybeOption(arg)) {
2067
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
2040
2068
  dest = unknown;
2041
2069
  }
2042
2070
  if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
@@ -2271,6 +2299,32 @@ Expecting one of '${allowedValues.join("', '")}'`);
2271
2299
  this._name = str;
2272
2300
  return this;
2273
2301
  }
2302
+ helpGroup(heading) {
2303
+ if (heading === undefined)
2304
+ return this._helpGroupHeading ?? "";
2305
+ this._helpGroupHeading = heading;
2306
+ return this;
2307
+ }
2308
+ commandsGroup(heading) {
2309
+ if (heading === undefined)
2310
+ return this._defaultCommandGroup ?? "";
2311
+ this._defaultCommandGroup = heading;
2312
+ return this;
2313
+ }
2314
+ optionsGroup(heading) {
2315
+ if (heading === undefined)
2316
+ return this._defaultOptionGroup ?? "";
2317
+ this._defaultOptionGroup = heading;
2318
+ return this;
2319
+ }
2320
+ _initOptionGroup(option) {
2321
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
2322
+ option.helpGroup(this._defaultOptionGroup);
2323
+ }
2324
+ _initCommandGroup(cmd) {
2325
+ if (this._defaultCommandGroup && !cmd.helpGroup())
2326
+ cmd.helpGroup(this._defaultCommandGroup);
2327
+ }
2274
2328
  nameFromFilename(filename) {
2275
2329
  this._name = path.basename(filename, path.extname(filename));
2276
2330
  return this;
@@ -2347,15 +2401,19 @@ Expecting one of '${allowedValues.join("', '")}'`);
2347
2401
  helpOption(flags, description) {
2348
2402
  if (typeof flags === "boolean") {
2349
2403
  if (flags) {
2350
- this._helpOption = this._helpOption ?? undefined;
2404
+ if (this._helpOption === null)
2405
+ this._helpOption = undefined;
2406
+ if (this._defaultOptionGroup) {
2407
+ this._initOptionGroup(this._getHelpOption());
2408
+ }
2351
2409
  } else {
2352
2410
  this._helpOption = null;
2353
2411
  }
2354
2412
  return this;
2355
2413
  }
2356
- flags = flags ?? "-h, --help";
2357
- description = description ?? "display help for command";
2358
- this._helpOption = this.createOption(flags, description);
2414
+ this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
2415
+ if (flags || description)
2416
+ this._initOptionGroup(this._helpOption);
2359
2417
  return this;
2360
2418
  }
2361
2419
  _getHelpOption() {
@@ -2366,6 +2424,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2366
2424
  }
2367
2425
  addHelpOption(option) {
2368
2426
  this._helpOption = option;
2427
+ this._initOptionGroup(option);
2369
2428
  return this;
2370
2429
  }
2371
2430
  help(contextOptions) {
@@ -39731,7 +39790,7 @@ var {
39731
39790
  Help
39732
39791
  } = import__.default;
39733
39792
  // package.json
39734
- var version = "0.9.9";
39793
+ var version = "0.9.10";
39735
39794
 
39736
39795
  // ../../node_modules/@inquirer/core/dist/esm/lib/key.js
39737
39796
  var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
@@ -76369,7 +76428,17 @@ ${Object.entries(example.input).map(([name17, value]) => renderParameterValue(na
76369
76428
  `)}
76370
76429
  </${toolNamePrefix}${tool2.name}>
76371
76430
  `;
76372
- var toolUsePrompt = (tools, toolNamePrefix) => {
76431
+ var toolUsePrompt = (useNativeTool, tools, toolNamePrefix) => {
76432
+ if (useNativeTool) {
76433
+ return `
76434
+ ====
76435
+
76436
+ TOOL USE
76437
+
76438
+ - You MUST use a tool.
76439
+ - Batch tool use when feasible; avoid redundant calls.
76440
+ `;
76441
+ }
76373
76442
  if (tools.length === 0) {
76374
76443
  return "";
76375
76444
  }
@@ -76720,7 +76789,8 @@ ${instance.prompt}`;
76720
76789
  }
76721
76790
  if (requestTimeoutSeconds > 0 && requestAbortController) {
76722
76791
  timeout = setTimeout(() => {
76723
- console.debug(`Request timeout after ${requestTimeoutSeconds} seconds. Canceling current request attempt ${i + 1}/${retryCount}.`);
76792
+ console.debug(`
76793
+ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current request attempt ${i + 1}/${retryCount}.`);
76724
76794
  requestAbortController?.abort();
76725
76795
  }, requestTimeoutSeconds * 1000);
76726
76796
  }
@@ -76781,7 +76851,15 @@ ${instance.prompt}`;
76781
76851
  }
76782
76852
  }
76783
76853
  if (this.config.toolFormat === "native") {
76784
- if (respMessages.some((m) => m.role === "tool")) {
76854
+ if (respMessages.some((m) => {
76855
+ if (m.role === "tool") {
76856
+ return true;
76857
+ }
76858
+ if (typeof m.content === "string") {
76859
+ return true;
76860
+ }
76861
+ return m.content.some((part) => part.type === "tool-call" || part.type === "tool-result" || part.type === "text");
76862
+ })) {
76785
76863
  break;
76786
76864
  }
76787
76865
  } else {
@@ -76793,7 +76871,8 @@ ${instance.prompt}`;
76793
76871
  break;
76794
76872
  }
76795
76873
  if (i < retryCount - 1) {
76796
- console.debug(`Retrying request ${i + 2} of ${retryCount}`);
76874
+ console.debug(`
76875
+ Retrying request ${i + 2} of ${retryCount}`);
76797
76876
  }
76798
76877
  }
76799
76878
  if (respMessages.length === 0) {
@@ -77031,7 +77110,7 @@ You are the **Analyzer** agent, responsible for:
77031
77110
  5. **Documentation Assessment**: Review documentation quality and completeness.
77032
77111
  6. **Non-Modification**: Never modify code or files - focus solely on analysis.
77033
77112
 
77034
- ${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
77113
+ ${toolUsePrompt(useNativeTool, tools, toolNamePrefix)}
77035
77114
  ${capabilities(toolNamePrefix)}
77036
77115
  ${systemInformation(info)}
77037
77116
  ${customInstructions(instructions)}
@@ -77121,7 +77200,7 @@ You are the **Architect** agent, responsible for:
77121
77200
  - If multiple steps are required, break them into numbered tasks to delegate to the **Coder** agent.
77122
77201
  - Provide all necessary context, implementation plan, file references, and clarifications for successful execution.
77123
77202
 
77124
- ${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
77203
+ ${toolUsePrompt(useNativeTool, tools, toolNamePrefix)}
77125
77204
  ${capabilities(toolNamePrefix)}
77126
77205
  ${systemInformation(info)}
77127
77206
  ${customInstructions(instructions)}
@@ -77241,7 +77320,7 @@ RETRY GUIDELINES
77241
77320
  - Report any partial improvements`;
77242
77321
  var fullSystemPrompt3 = (info, tools, toolNamePrefix, instructions, scripts, _interactive, useNativeTool) => `
77243
77322
  ${basePrompt}
77244
- ${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
77323
+ ${toolUsePrompt(useNativeTool, tools, toolNamePrefix)}
77245
77324
  ${codeFixingStrategies}
77246
77325
  ${retryGuidelines}
77247
77326
  ${capabilities(toolNamePrefix)}
@@ -77440,7 +77519,7 @@ You solve the user's task by working in small, verifiable steps.
77440
77519
  `;
77441
77520
  var fullSystemPrompt4 = (info, tools, toolNamePrefix, instructions, scripts, useNativeTool) => `
77442
77521
  ${basePrompt2}
77443
- ${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
77522
+ ${toolUsePrompt(useNativeTool, tools, toolNamePrefix)}
77444
77523
  ${editingFilesPrompt(toolNamePrefix)}
77445
77524
  ${capabilities(toolNamePrefix)}
77446
77525
  ${rules(toolNamePrefix)}
@@ -109082,54 +109161,54 @@ var source_default = chalk;
109082
109161
 
109083
109162
  // ../cli-shared/src/utils/eventHandler.ts
109084
109163
  var toolCallStats = new Map;
109085
- var printEvent = (verbose, usageMeter) => {
109164
+ var printEvent = (verbose, usageMeter, customConsole = console) => {
109086
109165
  let hadReasoning = false;
109087
109166
  return (event) => {
109088
109167
  switch (event.kind) {
109089
109168
  case "StartTask" /* StartTask */:
109090
109169
  toolCallStats.clear();
109091
109170
  if (verbose > 1) {
109092
- console.log(`
109171
+ customConsole.log(`
109093
109172
  ====== System Prompt ======
109094
109173
  ${event.systemPrompt}`);
109095
- console.log(`
109174
+ customConsole.log(`
109096
109175
 
109097
109176
  ================
109098
109177
  `);
109099
109178
  }
109100
109179
  break;
109101
109180
  case "StartRequest" /* StartRequest */:
109102
- console.log(`
109181
+ customConsole.log(`
109103
109182
 
109104
109183
  ======== New Request ========
109105
109184
  `);
109106
109185
  if (verbose) {
109107
109186
  const userMessage = event.userMessage.content;
109108
109187
  if (typeof userMessage === "string") {
109109
- console.log(userMessage);
109188
+ customConsole.log(userMessage);
109110
109189
  } else {
109111
109190
  for (const content of userMessage) {
109112
109191
  switch (content.type) {
109113
109192
  case "text":
109114
- console.log(content.text);
109193
+ customConsole.log(content.text);
109115
109194
  break;
109116
109195
  case "image":
109117
109196
  if (content.image instanceof URL) {
109118
- console.log(source_default.yellow(`[Image content from URL: ${content.image}]`));
109197
+ customConsole.log(source_default.yellow(`[Image content from URL: ${content.image}]`));
109119
109198
  } else {
109120
- console.log(source_default.yellow(`[Image content: ${content.mediaType}]`));
109199
+ customConsole.log(source_default.yellow(`[Image content: ${content.mediaType}]`));
109121
109200
  }
109122
109201
  break;
109123
109202
  case "file":
109124
- console.log(source_default.yellow(`[File name: ${content.filename}, type: ${content.mediaType}]`));
109203
+ customConsole.log(source_default.yellow(`[File name: ${content.filename}, type: ${content.mediaType}]`));
109125
109204
  break;
109126
109205
  case "tool-call":
109127
- console.log(source_default.yellow(`[Tool call: ${content.toolName}]`));
109206
+ customConsole.log(source_default.yellow(`[Tool call: ${content.toolName}]`));
109128
109207
  break;
109129
109208
  case "tool-result":
109130
- console.log(source_default.yellow(`[Tool result: ${content.toolName}]`));
109209
+ customConsole.log(source_default.yellow(`[Tool result: ${content.toolName}]`));
109131
109210
  if (verbose > 0) {
109132
- console.log(content.output);
109211
+ customConsole.log(content.output);
109133
109212
  }
109134
109213
  break;
109135
109214
  case "reasoning":
@@ -109137,14 +109216,14 @@ ${event.systemPrompt}`);
109137
109216
  }
109138
109217
  }
109139
109218
  }
109140
- console.log(`
109219
+ customConsole.log(`
109141
109220
 
109142
109221
  ======== Request Message Ended ========
109143
109222
  `);
109144
109223
  }
109145
109224
  break;
109146
109225
  case "EndRequest" /* EndRequest */:
109147
- console.log(`
109226
+ customConsole.log(`
109148
109227
 
109149
109228
  ======== Request Ended ========
109150
109229
  `);
@@ -109155,6 +109234,9 @@ ${event.systemPrompt}`);
109155
109234
  case "Usage" /* Usage */:
109156
109235
  break;
109157
109236
  case "Text" /* Text */:
109237
+ if (customConsole !== console) {
109238
+ break;
109239
+ }
109158
109240
  if (hadReasoning) {
109159
109241
  process.stdout.write(`
109160
109242
 
@@ -109164,11 +109246,14 @@ ${event.systemPrompt}`);
109164
109246
  process.stdout.write(event.newText);
109165
109247
  break;
109166
109248
  case "Reasoning" /* Reasoning */:
109249
+ if (customConsole !== console) {
109250
+ break;
109251
+ }
109167
109252
  process.stdout.write(source_default.dim(event.newText));
109168
109253
  hadReasoning = true;
109169
109254
  break;
109170
109255
  case "ToolUse" /* ToolUse */: {
109171
- console.log(source_default.yellow(`
109256
+ customConsole.log(source_default.yellow(`
109172
109257
 
109173
109258
  Tool use:`, event.tool), event.content);
109174
109259
  const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
@@ -109185,10 +109270,10 @@ Tool use:`, event.tool), event.content);
109185
109270
  case "ToolInvalid" /* ToolInvalid */:
109186
109271
  break;
109187
109272
  case "ToolError" /* ToolError */: {
109188
- console.error(source_default.red(`
109273
+ customConsole.error(source_default.red(`
109189
109274
 
109190
109275
  Tool error:`, event.tool));
109191
- console.error(source_default.red(event.content));
109276
+ customConsole.error(source_default.red(event.content));
109192
109277
  const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
109193
109278
  stats.errors++;
109194
109279
  toolCallStats.set(event.tool, stats);
@@ -109197,48 +109282,48 @@ Tool error:`, event.tool));
109197
109282
  case "ToolInterrupted" /* ToolInterrupted */:
109198
109283
  break;
109199
109284
  case "ToolHandOver" /* ToolHandOver */:
109200
- console.log(`
109285
+ customConsole.log(`
109201
109286
 
109202
109287
  ======== Task Handed Over ========
109203
109288
  `);
109204
- console.log("Agent:", event.agentName);
109205
- console.log("Task:", event.task);
109206
- console.log("Context:", event.context);
109207
- console.log("Files:", event.files);
109208
- console.log();
109289
+ customConsole.log("Agent:", event.agentName);
109290
+ customConsole.log("Task:", event.task);
109291
+ customConsole.log("Context:", event.context);
109292
+ customConsole.log("Files:", event.files);
109293
+ customConsole.log();
109209
109294
  break;
109210
109295
  case "ToolDelegate" /* ToolDelegate */:
109211
- console.log(`
109296
+ customConsole.log(`
109212
109297
 
109213
109298
  ======== Task Delegated ========
109214
109299
  `);
109215
- console.log("Agent:", event.agentName);
109216
- console.log("Task:", event.task);
109217
- console.log("Context:", event.context);
109218
- console.log("Files:", event.files);
109219
- console.log();
109300
+ customConsole.log("Agent:", event.agentName);
109301
+ customConsole.log("Task:", event.task);
109302
+ customConsole.log("Context:", event.context);
109303
+ customConsole.log("Files:", event.files);
109304
+ customConsole.log();
109220
109305
  break;
109221
109306
  case "UsageExceeded" /* UsageExceeded */:
109222
- console.log(`
109307
+ customConsole.log(`
109223
109308
 
109224
109309
  ======= Usage Exceeded ========
109225
109310
  `);
109226
109311
  break;
109227
109312
  case "EndTask" /* EndTask */:
109228
- console.log(`
109313
+ customConsole.log(`
109229
109314
 
109230
109315
  ======== Task Ended ========
109231
109316
  `);
109232
- console.log("Reason:", event.exitReason.type);
109317
+ customConsole.log("Reason:", event.exitReason.type);
109233
109318
  switch (event.exitReason.type) {
109234
109319
  case "Exit" /* Exit */:
109235
- console.log("Exit Message:", event.exitReason.message);
109320
+ customConsole.log("Exit Message:", event.exitReason.message);
109236
109321
  break;
109237
109322
  case "Interrupted" /* Interrupted */:
109238
- console.log("Interrupted Message:", event.exitReason.message);
109323
+ customConsole.log("Interrupted Message:", event.exitReason.message);
109239
109324
  break;
109240
109325
  }
109241
- console.log(`
109326
+ customConsole.log(`
109242
109327
 
109243
109328
  ======== Tool Call Stats ========`);
109244
109329
  if (toolCallStats.size > 0) {
@@ -109252,9 +109337,9 @@ Tool error:`, event.tool));
109252
109337
  "Success Rate": `${successRate.toFixed(2)}%`
109253
109338
  };
109254
109339
  });
109255
- console.table(tableData);
109340
+ customConsole.table(tableData);
109256
109341
  } else {
109257
- console.log("No tools were called.");
109342
+ customConsole.log("No tools were called.");
109258
109343
  }
109259
109344
  break;
109260
109345
  }
@@ -109263,7 +109348,7 @@ Tool error:`, event.tool));
109263
109348
  // src/options.ts
109264
109349
  var import_lodash3 = __toESM(require_lodash(), 1);
109265
109350
  function addSharedOptions(command) {
109266
- return command.option("-c --config <paths>", "Path to config file(s)", (value, prev) => prev.concat(value), []).option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-messages <iterations>", "Maximum number of messages to send. Default to 50", Number.parseInt, 50).option("--budget <budget>", "Budget for the AI service. Default to $10", Number.parseFloat).option("--retry-count <count>", "Number of retries for failed requests. Default to 5", Number.parseInt, 5).option("--request-timeout-seconds <seconds>", "Request timeout in seconds. Default to 10", Number.parseInt, 10).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (_value, prev) => prev + 1, 0).option("-d --base-dir <path>", "Base directory to run commands in").option("--agent <agent>", "Initial agent to use (default: architect)");
109351
+ return command.option("-c --config <paths>", "Path to config file(s)", (value, prev) => prev.concat(value), []).option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-messages <iterations>", "Maximum number of messages to send.", Number.parseInt).option("--budget <budget>", "Budget for the AI service.", Number.parseFloat).option("--retry-count <count>", "Number of retries for failed requests.", Number.parseInt).option("--request-timeout-seconds <seconds>", "Request timeout in seconds.", Number.parseInt).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (_value, prev) => prev + 1, 0).option("-d --base-dir <path>", "Base directory to run commands in").option("--agent <agent>", "Initial agent to use (default: architect)");
109267
109352
  }
109268
109353
  function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
109269
109354
  let cwd = cwdArg;
@@ -110661,6 +110746,7 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
110661
110746
 
110662
110747
  // src/commands/review.ts
110663
110748
  import { execSync as execSync3 } from "node:child_process";
110749
+ import { Console } from "node:console";
110664
110750
  var import_lodash9 = __toESM(require_lodash(), 1);
110665
110751
  function parseGitStatus(statusOutput) {
110666
110752
  const statusLines = statusOutput.split(`
@@ -110759,9 +110845,11 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
110759
110845
  }
110760
110846
  const spinner = ora({
110761
110847
  text: "Gathering information...",
110762
- stream: options.json ? process.stderr : process.stdout
110848
+ stream: process.stderr
110763
110849
  }).start();
110764
110850
  const usage = new UsageMeter(import_lodash9.merge(prices_default, config6.prices ?? {}));
110851
+ const customConsole = options.json ? new Console(process.stderr, process.stderr) : console;
110852
+ const onEvent = printEvent(parentOptions.verbose, usage, customConsole);
110765
110853
  const ai = getModel(commandConfig);
110766
110854
  const toolProviderOptions = {
110767
110855
  excludeFiles: parentOptions.config.excludeFiles,
@@ -110775,7 +110863,8 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
110775
110863
  provider: toolProvider,
110776
110864
  interactive: false,
110777
110865
  policies: [],
110778
- toolFormat: commandConfig.toolFormat
110866
+ toolFormat: commandConfig.toolFormat,
110867
+ callback: parentOptions.verbose > 0 ? onEvent : undefined
110779
110868
  };
110780
110869
  try {
110781
110870
  if (options.pr) {
@@ -110846,7 +110935,7 @@ async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput) {
110846
110935
  }
110847
110936
  }
110848
110937
  async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
110849
- const gitStatus = execSync3("git status --porcelain=v1", { encoding: "utf-8" }).trim();
110938
+ const gitStatus = execSync3("git status --porcelain=v1", { encoding: "utf-8" });
110850
110939
  const statusLines = gitStatus.split(`
110851
110940
  `).filter((line) => line);
110852
110941
  const hasStagedChanges = statusLines.some((line) => "MARC".includes(line[0]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",