@polka-codes/cli 0.9.11 → 0.9.13

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 +114 -111
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39790,7 +39790,7 @@ var {
39790
39790
  Help
39791
39791
  } = import__.default;
39792
39792
  // package.json
39793
- var version = "0.9.11";
39793
+ var version = "0.9.13";
39794
39794
 
39795
39795
  // ../../node_modules/@inquirer/core/dist/esm/lib/key.js
39796
39796
  var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
@@ -78241,7 +78241,7 @@ var handler14 = async (provider2, args) => {
78241
78241
  };
78242
78242
  }
78243
78243
  const { staged, file: file3, commitRange } = toolInfo14.parameters.parse(args);
78244
- const commandParts = ["git", "diff", "--no-color"];
78244
+ const commandParts = ["git", "diff", "--no-color", "-U50"];
78245
78245
  if (staged) {
78246
78246
  commandParts.push("--staged");
78247
78247
  }
@@ -84995,6 +84995,7 @@ function createOpenAI(options = {}) {
84995
84995
  return provider2;
84996
84996
  }
84997
84997
  var openai = createOpenAI();
84998
+
84998
84999
  // ../../node_modules/@openrouter/ai-sdk-provider/dist/index.mjs
84999
85000
  var __defProp3 = Object.defineProperty;
85000
85001
  var __defProps = Object.defineProperties;
@@ -96902,7 +96903,7 @@ function toJSONSchema3(input, _params) {
96902
96903
  gen2.process(schema);
96903
96904
  }
96904
96905
  const schemas5 = {};
96905
- const external4 = {
96906
+ const external3 = {
96906
96907
  registry: input,
96907
96908
  uri: _params?.uri,
96908
96909
  defs
@@ -96911,7 +96912,7 @@ function toJSONSchema3(input, _params) {
96911
96912
  const [key2, schema] = entry;
96912
96913
  schemas5[key2] = gen2.emit(schema, {
96913
96914
  ..._params,
96914
- external: external4
96915
+ external: external3
96915
96916
  });
96916
96917
  }
96917
96918
  if (Object.keys(defs).length > 0) {
@@ -110351,7 +110352,6 @@ function ora(options) {
110351
110352
 
110352
110353
  // src/commands/commit.ts
110353
110354
  var commitCommand = new Command("commit").description("Create a commit with AI-generated message").option("-a, --all", "Stage all files before committing").argument("[message]", "Optional context for the commit message generation").action(async (message, localOptions, command) => {
110354
- const spinner = ora("Gathering information...").start();
110355
110355
  const options = command.parent?.opts() ?? {};
110356
110356
  const { providerConfig, config: config6 } = parseOptions(options);
110357
110357
  const commandConfig = providerConfig.getConfigForCommand("commit");
@@ -110361,6 +110361,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
110361
110361
  }
110362
110362
  console.log("Provider:", commandConfig.provider);
110363
110363
  console.log("Model:", commandConfig.model);
110364
+ const spinner = ora("Gathering information...").start();
110364
110365
  const usage = new UsageMeter(import_lodash6.merge(prices_default, config6.prices ?? {}));
110365
110366
  try {
110366
110367
  const status = execSync("git status --porcelain").toString();
@@ -110387,10 +110388,6 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
110387
110388
  const diff = execSync("git diff --cached -U50").toString();
110388
110389
  spinner.text = "Generating commit message...";
110389
110390
  const llm = getModel(commandConfig);
110390
- const _schema = exports_external2.object({
110391
- reasoning: exports_external2.string().describe("Reasoning if any"),
110392
- message: exports_external2.string().describe("The generated commit message")
110393
- });
110394
110391
  const commitMessage = await generateGitCommitMessage(llm, { diff, context: message }, usage);
110395
110392
  usage.printUsage();
110396
110393
  spinner.succeed("Commit message generated");
@@ -110751,6 +110748,89 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
110751
110748
  import { execSync as execSync3 } from "node:child_process";
110752
110749
  import { Console } from "node:console";
110753
110750
  var import_lodash9 = __toESM(require_lodash(), 1);
110751
+
110752
+ // src/commands/task.ts
110753
+ var readStdin = async (timeoutMs = 30000) => {
110754
+ if (process.stdin.isTTY) {
110755
+ return "";
110756
+ }
110757
+ return new Promise((resolve3, reject) => {
110758
+ let input = "";
110759
+ const cleanup = () => {
110760
+ if (timeoutId)
110761
+ clearTimeout(timeoutId);
110762
+ process.stdin.removeAllListeners();
110763
+ process.stdin.resume();
110764
+ };
110765
+ const timeoutId = setTimeout(() => {
110766
+ cleanup();
110767
+ reject(new Error("Stdin read timeout"));
110768
+ }, timeoutMs);
110769
+ process.stdin.on("data", (chunk) => {
110770
+ input += chunk.toString();
110771
+ });
110772
+ process.stdin.on("end", () => {
110773
+ cleanup();
110774
+ if (!input) {
110775
+ reject(new Error("Empty stdin input"));
110776
+ return;
110777
+ }
110778
+ resolve3(input);
110779
+ });
110780
+ process.stdin.on("error", (err) => {
110781
+ cleanup();
110782
+ reject(err);
110783
+ });
110784
+ });
110785
+ };
110786
+ async function runTask(taskArg, _options, command) {
110787
+ let task = taskArg;
110788
+ if (!task) {
110789
+ try {
110790
+ const stdinInput = await readStdin();
110791
+ if (stdinInput) {
110792
+ task = stdinInput;
110793
+ } else {
110794
+ runChat(command.opts());
110795
+ return;
110796
+ }
110797
+ } catch (error120) {
110798
+ console.error("Error reading stdin:", error120);
110799
+ process.exit(1);
110800
+ }
110801
+ }
110802
+ const { config: config6, providerConfig, verbose, maxMessageCount, budget, agent } = parseOptions(command.opts());
110803
+ const { provider: provider3, model, parameters } = providerConfig.getConfigForAgent(agent) ?? {};
110804
+ if (!provider3 || !model) {
110805
+ console.error("Provider and model must be configured");
110806
+ process.exit(1);
110807
+ }
110808
+ console.log("Provider:", provider3);
110809
+ console.log("Model:", model);
110810
+ for (const [key2, value] of Object.entries(parameters ?? {})) {
110811
+ console.log(`${key2}:`, value);
110812
+ }
110813
+ const runner = new Runner({
110814
+ providerConfig,
110815
+ config: config6,
110816
+ maxMessageCount,
110817
+ budget,
110818
+ interactive: process.stdin.isTTY,
110819
+ verbose
110820
+ });
110821
+ const sigintHandler = () => {
110822
+ runner.abort();
110823
+ console.log();
110824
+ runner.printUsage();
110825
+ process.exit(0);
110826
+ };
110827
+ process.on("SIGINT", sigintHandler);
110828
+ await runner.startTask(task, agent);
110829
+ process.off("SIGINT", sigintHandler);
110830
+ runner.printUsage();
110831
+ }
110832
+
110833
+ // src/commands/review.ts
110754
110834
  function parseGitStatus(statusOutput) {
110755
110835
  const statusLines = statusOutput.split(`
110756
110836
  `).filter((line) => line);
@@ -110871,9 +110951,9 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
110871
110951
  };
110872
110952
  try {
110873
110953
  if (options.pr) {
110874
- await reviewPR(options.pr, spinner, sharedAiOptions, options.json);
110954
+ await reviewPR(options.pr, spinner, sharedAiOptions, options.json, command);
110875
110955
  } else {
110876
- await reviewLocal(spinner, sharedAiOptions, options.json);
110956
+ await reviewLocal(spinner, sharedAiOptions, options.json, command);
110877
110957
  }
110878
110958
  } catch (error120) {
110879
110959
  spinner.fail(`Error reviewing: ${error120 instanceof Error ? error120.message : String(error120)}`);
@@ -110884,7 +110964,7 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
110884
110964
  usage.printUsage();
110885
110965
  }
110886
110966
  });
110887
- async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput) {
110967
+ async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput, command) {
110888
110968
  const prNumberMatch = prIdentifier.match(/\d+$/);
110889
110969
  if (!prNumberMatch) {
110890
110970
  spinner.fail("Invalid PR number or URL.");
@@ -110931,13 +111011,9 @@ async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput) {
110931
111011
  changedFiles
110932
111012
  });
110933
111013
  spinner.succeed("Review generated successfully");
110934
- if (isJsonOutput) {
110935
- console.log(JSON.stringify(result, null, 2));
110936
- } else {
110937
- console.log(formatReviewForConsole(result));
110938
- }
111014
+ await handleReviewResult(result, isJsonOutput, command);
110939
111015
  }
110940
- async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
111016
+ async function reviewLocal(spinner, sharedAiOptions, isJsonOutput, command) {
110941
111017
  const gitStatus = execSync3("git status --porcelain=v1", { encoding: "utf-8" });
110942
111018
  const statusLines = gitStatus.split(`
110943
111019
  `).filter((line) => line);
@@ -110953,11 +111029,7 @@ async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
110953
111029
  changedFiles: stagedFiles
110954
111030
  });
110955
111031
  spinner.succeed("Review generated successfully");
110956
- if (isJsonOutput) {
110957
- console.log(JSON.stringify(result2, null, 2));
110958
- } else {
110959
- console.log(formatReviewForConsole(result2));
110960
- }
111032
+ await handleReviewResult(result2, isJsonOutput, command);
110961
111033
  return;
110962
111034
  }
110963
111035
  if (hasUnstagedChanges) {
@@ -110969,11 +111041,7 @@ async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
110969
111041
  changedFiles: unstagedFiles
110970
111042
  });
110971
111043
  spinner.succeed("Review generated successfully");
110972
- if (isJsonOutput) {
110973
- console.log(JSON.stringify(result2, null, 2));
110974
- } else {
110975
- console.log(formatReviewForConsole(result2));
110976
- }
111044
+ await handleReviewResult(result2, isJsonOutput, command);
110977
111045
  return;
110978
111046
  }
110979
111047
  spinner.text = "No local changes detected. Falling back to branch diff...";
@@ -111007,10 +111075,26 @@ async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
111007
111075
  changedFiles: branchChangedFiles
111008
111076
  });
111009
111077
  spinner.succeed("Review generated successfully");
111078
+ await handleReviewResult(result, isJsonOutput, command);
111079
+ }
111080
+ async function handleReviewResult(result, isJsonOutput, command) {
111010
111081
  if (isJsonOutput) {
111011
111082
  console.log(JSON.stringify(result, null, 2));
111012
- } else {
111013
- console.log(formatReviewForConsole(result));
111083
+ return;
111084
+ }
111085
+ const formatted = formatReviewForConsole(result);
111086
+ console.log(formatted);
111087
+ if (process.stdin.isTTY && result.specificReviews.length > 0) {
111088
+ const shouldRunTask = await esm_default2({
111089
+ message: "Do you wish polka-codes to address the review results?",
111090
+ default: false
111091
+ });
111092
+ if (shouldRunTask) {
111093
+ const taskInstruction = `please address the review result:
111094
+
111095
+ ${formatted}`;
111096
+ await runTask(taskInstruction, {}, command);
111097
+ }
111014
111098
  }
111015
111099
  }
111016
111100
  function formatReviewForConsole(output) {
@@ -111047,87 +111131,6 @@ function printChangedFiles(changedFiles, spinner, isJsonOutput) {
111047
111131
  spinner.start();
111048
111132
  }
111049
111133
 
111050
- // src/commands/task.ts
111051
- var readStdin = async (timeoutMs = 30000) => {
111052
- if (process.stdin.isTTY) {
111053
- return "";
111054
- }
111055
- return new Promise((resolve3, reject) => {
111056
- let input = "";
111057
- const cleanup = () => {
111058
- if (timeoutId)
111059
- clearTimeout(timeoutId);
111060
- process.stdin.removeAllListeners();
111061
- process.stdin.resume();
111062
- };
111063
- const timeoutId = setTimeout(() => {
111064
- cleanup();
111065
- reject(new Error("Stdin read timeout"));
111066
- }, timeoutMs);
111067
- process.stdin.on("data", (chunk) => {
111068
- input += chunk.toString();
111069
- });
111070
- process.stdin.on("end", () => {
111071
- cleanup();
111072
- if (!input) {
111073
- reject(new Error("Empty stdin input"));
111074
- return;
111075
- }
111076
- resolve3(input);
111077
- });
111078
- process.stdin.on("error", (err) => {
111079
- cleanup();
111080
- reject(err);
111081
- });
111082
- });
111083
- };
111084
- async function runTask(taskArg, _options, command) {
111085
- let task = taskArg;
111086
- if (!task) {
111087
- try {
111088
- const stdinInput = await readStdin();
111089
- if (stdinInput) {
111090
- task = stdinInput;
111091
- } else {
111092
- runChat(command.opts());
111093
- return;
111094
- }
111095
- } catch (error120) {
111096
- console.error("Error reading stdin:", error120);
111097
- process.exit(1);
111098
- }
111099
- }
111100
- const { config: config6, providerConfig, verbose, maxMessageCount, budget, agent } = parseOptions(command.opts());
111101
- const { provider: provider3, model, parameters } = providerConfig.getConfigForAgent(agent) ?? {};
111102
- if (!provider3 || !model) {
111103
- console.error("Provider and model must be configured");
111104
- process.exit(1);
111105
- }
111106
- console.log("Provider:", provider3);
111107
- console.log("Model:", model);
111108
- for (const [key2, value] of Object.entries(parameters ?? {})) {
111109
- console.log(`${key2}:`, value);
111110
- }
111111
- const runner = new Runner({
111112
- providerConfig,
111113
- config: config6,
111114
- maxMessageCount,
111115
- budget,
111116
- interactive: process.stdin.isTTY,
111117
- verbose
111118
- });
111119
- const sigintHandler = () => {
111120
- runner.abort();
111121
- console.log();
111122
- runner.printUsage();
111123
- process.exit(0);
111124
- };
111125
- process.on("SIGINT", sigintHandler);
111126
- await runner.startTask(task, agent);
111127
- process.off("SIGINT", sigintHandler);
111128
- runner.printUsage();
111129
- }
111130
-
111131
111134
  // src/index.ts
111132
111135
  var program2 = new Command;
111133
111136
  program2.name("polka").description("Polka Codes CLI").version(version);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",