@polka-codes/cli 0.8.25 → 0.8.27

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 +88 -57
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38447,7 +38447,7 @@ var {
38447
38447
  Help
38448
38448
  } = import__.default;
38449
38449
  // package.json
38450
- var version = "0.8.25";
38450
+ var version = "0.8.27";
38451
38451
 
38452
38452
  // ../core/src/AiService/AiServiceBase.ts
38453
38453
  class AiServiceBase {
@@ -48629,14 +48629,18 @@ var handler8 = async (provider, args) => {
48629
48629
  if (result.status === "no_diff_applied") {
48630
48630
  return {
48631
48631
  type: "Error" /* Error */,
48632
- message: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes" />`
48632
+ message: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes">
48633
+ <file_content path="${path}">${fileContent}</file_content>
48634
+ </replace_in_file_result>`
48633
48635
  };
48634
48636
  }
48635
48637
  await provider.writeFile(path, result.content);
48636
48638
  if (result.status === "some_diff_applied") {
48637
48639
  return {
48638
48640
  type: "Reply" /* Reply */,
48639
- message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}" />`
48641
+ message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}">
48642
+ <file_content path="${path}">${result.content}</file_content>
48643
+ </replace_in_file_result>`
48640
48644
  };
48641
48645
  }
48642
48646
  return {
@@ -49800,12 +49804,27 @@ ${instance.prompt}`;
49800
49804
  }
49801
49805
  }
49802
49806
  let currentAssistantMessage = "";
49803
- const retryCount = 5;
49807
+ const retryCount = this.config.retryCount ?? 5;
49808
+ const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 10;
49804
49809
  for (let i2 = 0;i2 < retryCount; i2++) {
49805
49810
  currentAssistantMessage = "";
49811
+ let timeout;
49812
+ const resetTimeout = () => {
49813
+ if (timeout) {
49814
+ clearTimeout(timeout);
49815
+ }
49816
+ if (requestTimeoutSeconds > 0) {
49817
+ timeout = setTimeout(() => {
49818
+ console.debug(`No data received for ${requestTimeoutSeconds} seconds. Aborting request.`);
49819
+ this.ai.abort();
49820
+ }, requestTimeoutSeconds * 1000);
49821
+ }
49822
+ };
49806
49823
  const stream = this.ai.send(this.config.systemPrompt, this.#messages);
49807
49824
  try {
49825
+ resetTimeout();
49808
49826
  for await (const chunk of stream) {
49827
+ resetTimeout();
49809
49828
  switch (chunk.type) {
49810
49829
  case "usage":
49811
49830
  await this.#callback({ kind: "Usage" /* Usage */, agent: this });
@@ -49824,6 +49843,10 @@ ${instance.prompt}`;
49824
49843
  break;
49825
49844
  }
49826
49845
  console.error("Error in stream:", error);
49846
+ } finally {
49847
+ if (timeout) {
49848
+ clearTimeout(timeout);
49849
+ }
49827
49850
  }
49828
49851
  if (currentAssistantMessage) {
49829
49852
  break;
@@ -54575,7 +54598,9 @@ var agentSchema = providerModelSchema.extend({
54575
54598
  initialContext: z2.object({
54576
54599
  maxFileCount: z2.number().int().positive().optional(),
54577
54600
  excludes: z2.array(z2.string()).optional()
54578
- }).optional()
54601
+ }).optional(),
54602
+ retryCount: z2.number().int().min(0).optional(),
54603
+ requestTimeoutSeconds: z2.number().int().positive().optional()
54579
54604
  });
54580
54605
  var configSchema = z2.object({
54581
54606
  agent: z2.string().optional(),
@@ -54595,6 +54620,8 @@ var configSchema = z2.object({
54595
54620
  defaultParameters: z2.record(z2.string(), z2.any()).optional(),
54596
54621
  maxMessageCount: z2.number().int().positive().optional(),
54597
54622
  budget: z2.number().positive().optional(),
54623
+ retryCount: z2.number().int().min(0).optional(),
54624
+ requestTimeoutSeconds: z2.number().int().positive().optional(),
54598
54625
  scripts: z2.record(z2.string(), z2.string().or(z2.object({
54599
54626
  command: z2.string(),
54600
54627
  description: z2.string()
@@ -55076,64 +55103,49 @@ ${output}`);
55076
55103
  };
55077
55104
 
55078
55105
  // ../core/src/AiTool/generateProjectConfig.ts
55079
- var prompt5 = `You are an analyzer agent responsible for examining project files and generating appropriate polkacodes configuration. Your task is to:
55080
-
55081
- 1. Read and analyze the provided files using tool_read_file to understand:
55082
- - Build tools and package manager (e.g., bun, npm)
55083
- - Testing frameworks and patterns
55084
- - Code style tools and rules
55085
- - Project structure and conventions
55086
- - Common development workflows
55087
-
55088
- 2. Generate a YAML configuration that captures:
55089
- - scripts section based on package.json scripts and CI workflows. If applicable, generate following scripts:
55090
- - format: Format the code using a code formatter tool
55091
- - check: Check the code for errors using a linter tool
55092
- - test: Run tests using a test runner tool
55093
- - include other relevant scripts based on project conventions, tools, and patterns
55094
- - rules section based on project conventions, tools, and patterns
55095
- - excludeFiles section for sensitive files
55096
-
55097
- 3. Use tool_attempt_completion to return the final configuration in this format:
55106
+ var prompt5 = `
55107
+ Role: Analyzer agent
55108
+ Goal: Produce a valid polkacodes YAML configuration for the project.
55098
55109
 
55099
- <tool_attempt_completion>
55100
- <tool_parameter_result>
55101
- scripts:
55102
- test:
55103
- command: "bun test"
55104
- description: "Run tests with bun:test"
55105
- lint:
55106
- command: "biome check ."
55107
- description: "Check code style with Biome"
55110
+ Workflow
55111
+ 1. Scan project files with tool_read_file and identify:
55112
+ - Package/build tool (npm, bun, pnpm, etc.)
55113
+ - Test framework and patterns (snapshot tests, coverage, etc.)
55114
+ - Formatter / linter and their rules
55115
+ - Folder structure and naming conventions
55116
+ - CI / development workflows
55108
55117
 
55109
- rules:
55110
- - "Use \`bun\` as package manager"
55111
- - "Write tests using bun:test with snapshots"
55112
- - "Follow Biome code style"
55118
+ 2. Build a YAML config with three root keys:
55113
55119
 
55114
- excludeFiles:
55115
- # Sensitive files
55120
+ \`\`\`yaml
55121
+ scripts: # derive from package.json and CI
55122
+ format: # code formatter
55123
+ command: "<formatter cmd>"
55124
+ description: "Format code"
55125
+ check: # linter / type checker
55126
+ command: "<linter cmd>"
55127
+ description: "Static checks"
55128
+ test: # test runner
55129
+ command: "<test cmd>"
55130
+ description: "Run tests"
55131
+ # add any other meaningful project scripts
55132
+
55133
+ rules: # bullet list of key conventions/tools
55134
+
55135
+ excludeFiles: # only files likely to hold secrets
55116
55136
  - ".env"
55117
55137
  - ".env.*"
55118
55138
  - ".npmrc"
55139
+ # do NOT list build artifacts, lockfiles, or paths already in .gitignore
55140
+ \`\`\`
55141
+
55142
+ 3. Return the YAML exactly once, wrapped like:
55143
+
55144
+ <tool_attempt_completion>
55145
+ <tool_parameter_result>
55146
+ # YAML (2-space indents, double-quoted commands)
55119
55147
  </tool_parameter_result>
55120
55148
  </tool_attempt_completion>
55121
-
55122
- Focus on:
55123
- - Package manager and dependency management
55124
- - Testing frameworks and patterns
55125
- - Code style and linting rules
55126
- - File organization and naming conventions
55127
- - Build and development workflows
55128
- - Sensitive files that should not be committed:
55129
- - Environment files (.env*)
55130
- - Configuration files with potential secrets
55131
- - Generated files to exclude:
55132
- - Lock files from package managers
55133
- - Build artifacts and outputs
55134
- - Generated file that are not ignored by .gitignore
55135
-
55136
- The configuration should accurately reflect the project's structure, tools, and conventions.
55137
55149
  `;
55138
55150
  var generateProjectConfig_default = {
55139
55151
  name: "generateProjectConfig",
@@ -61682,6 +61694,9 @@ class Runner {
61682
61694
  this.multiAgent = new MultiAgent({
61683
61695
  createAgent: async (name) => {
61684
61696
  const agentName = name.trim().toLowerCase();
61697
+ const agentConfig = this.#options.config.agents?.[name] ?? this.#options.config.agents?.default ?? {};
61698
+ const retryCount = agentConfig.retryCount ?? this.#options.config.retryCount;
61699
+ const requestTimeoutSeconds = agentConfig.requestTimeoutSeconds ?? this.#options.config.requestTimeoutSeconds;
61685
61700
  const args = {
61686
61701
  ai: getOrCreateService(agentName),
61687
61702
  os: platform,
@@ -61690,7 +61705,9 @@ class Runner {
61690
61705
  interactive: options.interactive,
61691
61706
  agents: this.#options.availableAgents ?? allAgents,
61692
61707
  callback,
61693
- policies: policies2
61708
+ policies: policies2,
61709
+ retryCount,
61710
+ requestTimeoutSeconds
61694
61711
  };
61695
61712
  switch (agentName) {
61696
61713
  case coderAgentInfo.name:
@@ -61933,7 +61950,7 @@ function getEnv(override) {
61933
61950
 
61934
61951
  // src/options.ts
61935
61952
  function addSharedOptions(command) {
61936
- 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("-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)");
61953
+ 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)");
61937
61954
  }
61938
61955
  function parseOptions(options, cwdArg, home = os3.homedir(), env2 = getEnv()) {
61939
61956
  let cwd = cwdArg;
@@ -61945,6 +61962,12 @@ function parseOptions(options, cwdArg, home = os3.homedir(), env2 = getEnv()) {
61945
61962
  cwd = process.cwd();
61946
61963
  }
61947
61964
  const config3 = loadConfig(options.config, cwd, home) ?? {};
61965
+ if (options.retryCount !== undefined) {
61966
+ config3.retryCount = options.retryCount;
61967
+ }
61968
+ if (options.requestTimeoutSeconds !== undefined) {
61969
+ config3.requestTimeoutSeconds = options.requestTimeoutSeconds;
61970
+ }
61948
61971
  const defaultProvider = options.apiProvider || env2.POLKA_API_PROVIDER || config3.defaultProvider;
61949
61972
  const defaultModel = options.model || env2.POLKA_MODEL || config3.defaultModel;
61950
61973
  if (defaultProvider && defaultModel) {
@@ -66964,7 +66987,15 @@ async function runTask(taskArg, _options, command) {
66964
66987
  verbose,
66965
66988
  enableCache: true
66966
66989
  });
66990
+ const sigintHandler = () => {
66991
+ runner.abort();
66992
+ console.log();
66993
+ runner.printUsage();
66994
+ process.exit(0);
66995
+ };
66996
+ process.on("SIGINT", sigintHandler);
66967
66997
  await runner.startTask(task, agent);
66998
+ process.off("SIGINT", sigintHandler);
66968
66999
  runner.printUsage();
66969
67000
  }
66970
67001
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.8.25",
3
+ "version": "0.8.27",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",