@polka-codes/cli 0.8.26 → 0.8.28

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 +74 -55
  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.26";
38450
+ var version = "0.8.28";
38451
38451
 
38452
38452
  // ../core/src/AiService/AiServiceBase.ts
38453
38453
  class AiServiceBase {
@@ -49804,12 +49804,27 @@ ${instance.prompt}`;
49804
49804
  }
49805
49805
  }
49806
49806
  let currentAssistantMessage = "";
49807
- const retryCount = 5;
49807
+ const retryCount = this.config.retryCount ?? 5;
49808
+ const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 10;
49808
49809
  for (let i2 = 0;i2 < retryCount; i2++) {
49809
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
+ };
49810
49823
  const stream = this.ai.send(this.config.systemPrompt, this.#messages);
49811
49824
  try {
49825
+ resetTimeout();
49812
49826
  for await (const chunk of stream) {
49827
+ resetTimeout();
49813
49828
  switch (chunk.type) {
49814
49829
  case "usage":
49815
49830
  await this.#callback({ kind: "Usage" /* Usage */, agent: this });
@@ -49828,6 +49843,10 @@ ${instance.prompt}`;
49828
49843
  break;
49829
49844
  }
49830
49845
  console.error("Error in stream:", error);
49846
+ } finally {
49847
+ if (timeout) {
49848
+ clearTimeout(timeout);
49849
+ }
49831
49850
  }
49832
49851
  if (currentAssistantMessage) {
49833
49852
  break;
@@ -54579,7 +54598,9 @@ var agentSchema = providerModelSchema.extend({
54579
54598
  initialContext: z2.object({
54580
54599
  maxFileCount: z2.number().int().positive().optional(),
54581
54600
  excludes: z2.array(z2.string()).optional()
54582
- }).optional()
54601
+ }).optional(),
54602
+ retryCount: z2.number().int().min(0).optional(),
54603
+ requestTimeoutSeconds: z2.number().int().positive().optional()
54583
54604
  });
54584
54605
  var configSchema = z2.object({
54585
54606
  agent: z2.string().optional(),
@@ -54599,6 +54620,8 @@ var configSchema = z2.object({
54599
54620
  defaultParameters: z2.record(z2.string(), z2.any()).optional(),
54600
54621
  maxMessageCount: z2.number().int().positive().optional(),
54601
54622
  budget: z2.number().positive().optional(),
54623
+ retryCount: z2.number().int().min(0).optional(),
54624
+ requestTimeoutSeconds: z2.number().int().positive().optional(),
54602
54625
  scripts: z2.record(z2.string(), z2.string().or(z2.object({
54603
54626
  command: z2.string(),
54604
54627
  description: z2.string()
@@ -55080,64 +55103,49 @@ ${output}`);
55080
55103
  };
55081
55104
 
55082
55105
  // ../core/src/AiTool/generateProjectConfig.ts
55083
- var prompt5 = `You are an analyzer agent responsible for examining project files and generating appropriate polkacodes configuration. Your task is to:
55084
-
55085
- 1. Read and analyze the provided files using tool_read_file to understand:
55086
- - Build tools and package manager (e.g., bun, npm)
55087
- - Testing frameworks and patterns
55088
- - Code style tools and rules
55089
- - Project structure and conventions
55090
- - Common development workflows
55091
-
55092
- 2. Generate a YAML configuration that captures:
55093
- - scripts section based on package.json scripts and CI workflows. If applicable, generate following scripts:
55094
- - format: Format the code using a code formatter tool
55095
- - check: Check the code for errors using a linter tool
55096
- - test: Run tests using a test runner tool
55097
- - include other relevant scripts based on project conventions, tools, and patterns
55098
- - rules section based on project conventions, tools, and patterns
55099
- - excludeFiles section for sensitive files
55100
-
55101
- 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.
55102
55109
 
55103
- <tool_attempt_completion>
55104
- <tool_parameter_result>
55105
- scripts:
55106
- test:
55107
- command: "bun test"
55108
- description: "Run tests with bun:test"
55109
- lint:
55110
- command: "biome check ."
55111
- 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
55112
55117
 
55113
- rules:
55114
- - "Use \`bun\` as package manager"
55115
- - "Write tests using bun:test with snapshots"
55116
- - "Follow Biome code style"
55118
+ 2. Build a YAML config with three root keys:
55117
55119
 
55118
- excludeFiles:
55119
- # 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
55120
55136
  - ".env"
55121
55137
  - ".env.*"
55122
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)
55123
55147
  </tool_parameter_result>
55124
55148
  </tool_attempt_completion>
55125
-
55126
- Focus on:
55127
- - Package manager and dependency management
55128
- - Testing frameworks and patterns
55129
- - Code style and linting rules
55130
- - File organization and naming conventions
55131
- - Build and development workflows
55132
- - Sensitive files that should not be committed:
55133
- - Environment files (.env*)
55134
- - Configuration files with potential secrets
55135
- - Generated files to exclude:
55136
- - Lock files from package managers
55137
- - Build artifacts and outputs
55138
- - Generated file that are not ignored by .gitignore
55139
-
55140
- The configuration should accurately reflect the project's structure, tools, and conventions.
55141
55149
  `;
55142
55150
  var generateProjectConfig_default = {
55143
55151
  name: "generateProjectConfig",
@@ -61686,6 +61694,9 @@ class Runner {
61686
61694
  this.multiAgent = new MultiAgent({
61687
61695
  createAgent: async (name) => {
61688
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;
61689
61700
  const args = {
61690
61701
  ai: getOrCreateService(agentName),
61691
61702
  os: platform,
@@ -61694,7 +61705,9 @@ class Runner {
61694
61705
  interactive: options.interactive,
61695
61706
  agents: this.#options.availableAgents ?? allAgents,
61696
61707
  callback,
61697
- policies: policies2
61708
+ policies: policies2,
61709
+ retryCount,
61710
+ requestTimeoutSeconds
61698
61711
  };
61699
61712
  switch (agentName) {
61700
61713
  case coderAgentInfo.name:
@@ -61937,7 +61950,7 @@ function getEnv(override) {
61937
61950
 
61938
61951
  // src/options.ts
61939
61952
  function addSharedOptions(command) {
61940
- 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)");
61941
61954
  }
61942
61955
  function parseOptions(options, cwdArg, home = os3.homedir(), env2 = getEnv()) {
61943
61956
  let cwd = cwdArg;
@@ -61949,6 +61962,12 @@ function parseOptions(options, cwdArg, home = os3.homedir(), env2 = getEnv()) {
61949
61962
  cwd = process.cwd();
61950
61963
  }
61951
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
+ }
61952
61971
  const defaultProvider = options.apiProvider || env2.POLKA_API_PROVIDER || config3.defaultProvider;
61953
61972
  const defaultModel = options.model || env2.POLKA_MODEL || config3.defaultModel;
61954
61973
  if (defaultProvider && defaultModel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.8.26",
3
+ "version": "0.8.28",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",