@polka-codes/cli 0.9.43 → 0.9.44

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 +187 -55
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -57704,7 +57704,7 @@ var {
57704
57704
  Help
57705
57705
  } = import__.default;
57706
57706
  // package.json
57707
- var version = "0.9.43";
57707
+ var version = "0.9.44";
57708
57708
 
57709
57709
  // src/commands/chat.ts
57710
57710
  import { readFile as readFile3 } from "node:fs/promises";
@@ -104051,8 +104051,9 @@ var runChat = async (opts, command) => {
104051
104051
 
104052
104052
  // src/runWorkflow.ts
104053
104053
  import { spawnSync as spawnSync2 } from "node:child_process";
104054
- import fs2 from "node:fs/promises";
104054
+ import fs2, { mkdir as mkdir2 } from "node:fs/promises";
104055
104055
  import os4 from "node:os";
104056
+ import { dirname as dirname2 } from "node:path";
104056
104057
 
104057
104058
  // ../workflow/src/helpers.ts
104058
104059
  var makeStepFn = (fns) => {
@@ -107314,11 +107315,29 @@ Unstaged files:`);
107314
107315
  throw new UserCancelledError;
107315
107316
  }
107316
107317
  }
107318
+ case "select": {
107319
+ const { message, choices } = toolCall.input;
107320
+ context.spinner.stop();
107321
+ await new Promise((resolve4) => setTimeout(resolve4, 50));
107322
+ try {
107323
+ const result = await esm_default5({ message, choices });
107324
+ context.spinner.start();
107325
+ return result;
107326
+ } catch (_e) {
107327
+ throw new UserCancelledError;
107328
+ }
107329
+ }
107317
107330
  case "writeToFile": {
107318
107331
  const { path, content } = toolCall.input;
107332
+ await mkdir2(dirname2(path), { recursive: true });
107319
107333
  await fs2.writeFile(path, content);
107320
107334
  return {};
107321
107335
  }
107336
+ case "executeCommand": {
107337
+ const { command } = toolCall.input;
107338
+ const result = spawnSync2(command, { shell: true, stdio: "pipe", encoding: "utf-8" });
107339
+ return { exitCode: result.status ?? -1, stdout: result.stdout, stderr: result.stderr };
107340
+ }
107322
107341
  default:
107323
107342
  throw new Error(`Unknown tool: ${String(toolCall.tool)}`);
107324
107343
  }
@@ -107495,7 +107514,7 @@ ${commitMessage}`);
107495
107514
  };
107496
107515
  // src/workflows/init.workflow.ts
107497
107516
  import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
107498
- import { dirname as dirname2 } from "node:path";
107517
+ import { dirname as dirname3 } from "node:path";
107499
107518
  var import_lodash7 = __toESM(require_lodash(), 1);
107500
107519
 
107501
107520
  // ../../node_modules/yaml/dist/index.js
@@ -107665,7 +107684,7 @@ var initWorkflow = {
107665
107684
  const globalConfigPath = getGlobalConfigPath();
107666
107685
  const globalConfig2 = loadConfigAtPath(globalConfigPath) ?? {};
107667
107686
  import_lodash7.set(globalConfig2, ["providers", provider3, "apiKey"], providerConfig.apiKey);
107668
- mkdirSync(dirname2(globalConfigPath), { recursive: true });
107687
+ mkdirSync(dirname3(globalConfigPath), { recursive: true });
107669
107688
  writeFileSync(globalConfigPath, $stringify2(globalConfig2));
107670
107689
  console.log(`API key saved to global config file: ${globalConfigPath}`);
107671
107690
  providerConfig.apiKey = undefined;
@@ -107718,7 +107737,7 @@ ${provider3.toUpperCase()}_API_KEY=${providerConfig.apiKey}`;
107718
107737
  import_lodash7.set(finalConfig, ["providers", providerConfig.provider, "apiKey"], providerConfig.apiKey);
107719
107738
  }
107720
107739
  }
107721
- mkdirSync(dirname2(configPath), { recursive: true });
107740
+ mkdirSync(dirname3(configPath), { recursive: true });
107722
107741
  writeFileSync(configPath, $stringify2(finalConfig));
107723
107742
  console.log(`Configuration saved to ${configPath}`);
107724
107743
  return {};
@@ -107726,12 +107745,7 @@ ${provider3.toUpperCase()}_API_KEY=${providerConfig.apiKey}`;
107726
107745
  return { configPath };
107727
107746
  }
107728
107747
  };
107729
- // src/workflows/plan.workflow.ts
107730
- var PlanSchema = exports_external.object({
107731
- plan: exports_external.string().optional(),
107732
- ready: exports_external.boolean(),
107733
- question: exports_external.string().optional()
107734
- });
107748
+ // src/workflows/plan.prompt.ts
107735
107749
  var PLAN_PROMPT = `
107736
107750
  You are an expert planner. Your goal is to create a detailed plan for a given task.
107737
107751
 
@@ -107757,61 +107771,100 @@ Respond with a JSON object that matches the following schema:
107757
107771
  "question": "The clarifying question to ask the user."
107758
107772
  }
107759
107773
  `;
107774
+
107775
+ // src/workflows/plan.workflow.ts
107776
+ var PlanSchema = exports_external.object({
107777
+ plan: exports_external.string().optional(),
107778
+ ready: exports_external.boolean(),
107779
+ question: exports_external.string().optional()
107780
+ });
107760
107781
  var planWorkflow = {
107761
107782
  name: "Plan Task",
107762
107783
  description: "Create or update a plan for a given task.",
107763
107784
  async* fn(input, _step, tools3) {
107764
107785
  const { task, fileContent, filePath } = input;
107765
107786
  let plan = fileContent || "";
107766
- let isPlanReady = false;
107767
107787
  let userFeedback = "";
107768
- while (true) {
107769
- const currentTask = userFeedback ? `${task}
107788
+ let state = "Generating";
107789
+ while (state !== "Done") {
107790
+ switch (state) {
107791
+ case "Generating": {
107792
+ const currentTask = userFeedback ? `${task}
107770
107793
 
107771
107794
  User feedback: ${userFeedback}` : task;
107772
- const prompt3 = PLAN_PROMPT.replace("{task}", currentTask).replace("{fileContent}", plan);
107773
- const {
107774
- plan: newPlan,
107775
- ready,
107776
- question
107777
- } = yield* tools3.invokeAgent({
107778
- agent: "architect",
107779
- messages: [{ type: "user", content: prompt3 }],
107780
- outputSchema: PlanSchema
107781
- });
107782
- if (newPlan !== undefined) {
107783
- plan = newPlan;
107784
- }
107785
- isPlanReady = ready;
107786
- if (!isPlanReady && question) {
107787
- const answer = yield* tools3.input({ message: question });
107788
- userFeedback = `Question: ${question}
107795
+ const prompt3 = PLAN_PROMPT.replace("{task}", currentTask).replace("{fileContent}", plan);
107796
+ const {
107797
+ plan: newPlan,
107798
+ ready,
107799
+ question
107800
+ } = yield* tools3.invokeAgent({
107801
+ agent: "architect",
107802
+ messages: [{ type: "user", content: prompt3 }],
107803
+ outputSchema: PlanSchema
107804
+ });
107805
+ if (newPlan !== undefined) {
107806
+ plan = newPlan;
107807
+ }
107808
+ if (!ready && question) {
107809
+ const answer = yield* tools3.input({ message: question });
107810
+ userFeedback = `Question: ${question}
107789
107811
  Answer: ${answer}`;
107790
- continue;
107791
- }
107792
- console.log(`
107812
+ state = "Generating";
107813
+ } else {
107814
+ userFeedback = "";
107815
+ state = "Reviewing";
107816
+ }
107817
+ break;
107818
+ }
107819
+ case "Reviewing": {
107820
+ console.log(`
107793
107821
  Generated Plan:
107794
107822
  `);
107795
- console.log(plan);
107796
- try {
107797
- userFeedback = yield* tools3.input({
107798
- message: "What changes do you want to make? (leave empty or press Ctrl+C to exit)"
107799
- });
107800
- } catch (_error) {
107801
- userFeedback = "";
107802
- }
107803
- if (!userFeedback) {
107804
- break;
107805
- }
107806
- }
107807
- const savePlan = yield* tools3.confirm({ message: "Do you want to save the plan?", default: false });
107808
- if (savePlan) {
107809
- let savePath = filePath;
107810
- if (!savePath) {
107811
- savePath = yield* tools3.input({ message: "Where do you want to save the plan?", default: "docs/plan.md" });
107823
+ console.log(plan);
107824
+ const choice = yield* tools3.select({
107825
+ message: "What do you want to do?",
107826
+ choices: [
107827
+ { name: "Accept and Save", value: "1" },
107828
+ { name: "Provide Feedback", value: "2" },
107829
+ { name: "Regenerate Plan", value: "3" },
107830
+ { name: "Exit", value: "4" }
107831
+ ]
107832
+ });
107833
+ switch (choice) {
107834
+ case "1": {
107835
+ const defaultPath = `.plans/plan-${new Date().toISOString().replace(/:/g, "-")}.md`;
107836
+ const savePath = filePath || (yield* tools3.input({ message: "Where do you want to save the plan?", default: defaultPath }));
107837
+ yield* tools3.writeToFile({ path: savePath, content: plan });
107838
+ console.log(`Plan saved to ${savePath}`);
107839
+ state = "Done";
107840
+ break;
107841
+ }
107842
+ case "2": {
107843
+ try {
107844
+ userFeedback = yield* tools3.input({
107845
+ message: "What changes do you want to make?"
107846
+ });
107847
+ state = "Generating";
107848
+ } catch (_error) {
107849
+ userFeedback = "";
107850
+ state = "Reviewing";
107851
+ }
107852
+ break;
107853
+ }
107854
+ case "3": {
107855
+ plan = "";
107856
+ userFeedback = "";
107857
+ state = "Generating";
107858
+ break;
107859
+ }
107860
+ case "4": {
107861
+ state = "Done";
107862
+ break;
107863
+ }
107864
+ }
107865
+ break;
107866
+ }
107812
107867
  }
107813
- yield* tools3.writeToFile({ path: savePath, content: plan });
107814
- console.log(`Plan saved to ${savePath}`);
107815
107868
  }
107816
107869
  return {};
107817
107870
  }
@@ -108285,7 +108338,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
108285
108338
 
108286
108339
  // src/commands/create.ts
108287
108340
  import { existsSync as existsSync4 } from "node:fs";
108288
- import { mkdir as mkdir2, stat } from "node:fs/promises";
108341
+ import { mkdir as mkdir3, stat } from "node:fs/promises";
108289
108342
  import { join as join3 } from "node:path";
108290
108343
  var askForPath = async (projectName) => {
108291
108344
  let targetPath = join3(process.cwd(), projectName);
@@ -108334,7 +108387,7 @@ var createCommand2 = new Command("create").description("Create a new project").a
108334
108387
  }
108335
108388
  const targetPath = await askForPath(projectName);
108336
108389
  try {
108337
- await mkdir2(targetPath, { recursive: true });
108390
+ await mkdir3(targetPath, { recursive: true });
108338
108391
  } catch (error47) {
108339
108392
  console.error(`Failed to create directory: ${targetPath}`, error47);
108340
108393
  process.exit(1);
@@ -108352,6 +108405,84 @@ var createCommand2 = new Command("create").description("Create a new project").a
108352
108405
  await createNewProject(runner.multiAgent, projectName);
108353
108406
  });
108354
108407
 
108408
+ // src/workflows/fix.workflow.ts
108409
+ var fixWorkflow = {
108410
+ name: "Fix",
108411
+ description: "Fix an issue by running a command repeatedly.",
108412
+ async* fn(input, _step, tools3) {
108413
+ let command = input.command;
108414
+ if (!command) {
108415
+ const config4 = loadConfig();
108416
+ const check2 = config4?.scripts?.check;
108417
+ const test = config4?.scripts?.test;
108418
+ let checkCommand;
108419
+ if (typeof check2 === "string") {
108420
+ checkCommand = check2;
108421
+ } else if (check2) {
108422
+ checkCommand = check2.command;
108423
+ }
108424
+ let testCommand;
108425
+ if (typeof test === "string") {
108426
+ testCommand = test;
108427
+ } else if (test) {
108428
+ testCommand = test.command;
108429
+ }
108430
+ let defaultCommand;
108431
+ if (checkCommand && testCommand) {
108432
+ defaultCommand = `${checkCommand} && ${testCommand}`;
108433
+ } else if (checkCommand) {
108434
+ defaultCommand = checkCommand;
108435
+ } else if (testCommand) {
108436
+ defaultCommand = testCommand;
108437
+ }
108438
+ command = yield* tools3.input({
108439
+ message: "Please enter the command to run to identify issues:",
108440
+ default: defaultCommand
108441
+ });
108442
+ if (!command) {
108443
+ throw new Error("No command provided. Aborting.");
108444
+ }
108445
+ }
108446
+ for (let i = 0;i < 10; i++) {
108447
+ console.log(`Running command: ${command}`);
108448
+ const { exitCode, stdout, stderr } = yield* tools3.executeCommand({ command });
108449
+ if (stdout) {
108450
+ console.log(`Command stdout:
108451
+ `, stdout);
108452
+ }
108453
+ if (stderr) {
108454
+ console.error(`Command stderr:
108455
+ `, stderr);
108456
+ }
108457
+ if (exitCode === 0) {
108458
+ console.log("Command succeeded!");
108459
+ return { success: true };
108460
+ }
108461
+ console.log(`Command failed with exit code ${exitCode}. Asking agent to fix it...`);
108462
+ const prompt3 = `The command "${command}" failed with exit code ${exitCode}.
108463
+ Please fix the code.
108464
+
108465
+ stdout:
108466
+ ${stdout}
108467
+
108468
+ stderr:
108469
+ ${stderr}
108470
+ `;
108471
+ yield* tools3.invokeAgent({
108472
+ agent: "coder",
108473
+ messages: [{ type: "user", content: prompt3 }]
108474
+ });
108475
+ }
108476
+ throw new Error("Failed to fix the issue after 10 attempts.");
108477
+ }
108478
+ };
108479
+
108480
+ // src/commands/fix.ts
108481
+ var fixCommand = new Command("fix").description("Fix issues by running a command and letting an agent fix it.").argument("[command]", "The command to run").action(async (command, _options, cmd) => {
108482
+ const workflowInput = { command };
108483
+ await runWorkflow("fix", fixWorkflow, cmd, workflowInput);
108484
+ });
108485
+
108355
108486
  // src/commands/init.ts
108356
108487
  var initCommand = new Command("init").description("Initialize polkacodes configuration").option("-g, --global", "Use global config").action(async (options, command) => {
108357
108488
  await runWorkflow("init", initWorkflow, command, {
@@ -108587,6 +108718,7 @@ program2.addCommand(prCommand);
108587
108718
  program2.addCommand(reviewCommand);
108588
108719
  program2.addCommand(createCommand2);
108589
108720
  program2.addCommand(planCommand);
108721
+ program2.addCommand(fixCommand);
108590
108722
  addSharedOptions(program2);
108591
108723
  program2.parse();
108592
108724
  process.on("uncaughtException", (error47) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.43",
3
+ "version": "0.9.44",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",