@polka-codes/cli-shared 0.9.5 → 0.9.6

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 +220 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -27293,7 +27293,7 @@ var handler8 = async (provider, args) => {
27293
27293
  if (isEmpty) {
27294
27294
  resp.push(`<read_file_file_content path="${path}" is_empty="true" />`);
27295
27295
  } else {
27296
- resp.push(`<read_file_file_conten path="${path}">${fileContent}</read_file_file_content>`);
27296
+ resp.push(`<read_file_file_content path="${path}">${fileContent}</read_file_file_content>`);
27297
27297
  }
27298
27298
  }
27299
27299
  }
@@ -27593,8 +27593,15 @@ var handler11 = async (provider, args) => {
27593
27593
  message: "Not possible to replace in file. Abort."
27594
27594
  };
27595
27595
  }
27596
+ const parsed = toolInfo11.parameters.safeParse(args);
27597
+ if (!parsed.success) {
27598
+ return {
27599
+ type: "Invalid" /* Invalid */,
27600
+ message: `Invalid arguments for replace_in_file: ${parsed.error.message}`
27601
+ };
27602
+ }
27603
+ const { path, diff } = parsed.data;
27596
27604
  try {
27597
- const { path, diff } = toolInfo11.parameters.parse(args);
27598
27605
  const fileContent = await provider.readFile(path, false);
27599
27606
  if (fileContent == null) {
27600
27607
  return {
@@ -27672,8 +27679,15 @@ var handler12 = async (provider, args) => {
27672
27679
  message: "Not possible to search files. Abort."
27673
27680
  };
27674
27681
  }
27682
+ const parsed = toolInfo12.parameters.safeParse(args);
27683
+ if (!parsed.success) {
27684
+ return {
27685
+ type: "Invalid" /* Invalid */,
27686
+ message: `Invalid arguments for search_files: ${parsed.error.message}`
27687
+ };
27688
+ }
27689
+ const { path, regex, filePattern } = parsed.data;
27675
27690
  try {
27676
- const { path, regex, filePattern } = toolInfo12.parameters.parse(args);
27677
27691
  const files = await provider.searchFiles(path, regex, filePattern ?? "*");
27678
27692
  return {
27679
27693
  type: "Reply" /* Reply */,
@@ -27688,8 +27702,8 @@ ${files.join(`
27688
27702
  };
27689
27703
  } catch (error40) {
27690
27704
  return {
27691
- type: "Invalid" /* Invalid */,
27692
- message: `Invalid arguments for search_files: ${error40}`
27705
+ type: "Error" /* Error */,
27706
+ message: `Error searching files: ${error40}`
27693
27707
  };
27694
27708
  }
27695
27709
  };
@@ -51549,6 +51563,196 @@ var codeFixerAgentInfo = {
51549
51563
  "Tracking and reporting unfixed issues"
51550
51564
  ]
51551
51565
  };
51566
+
51567
+ // ../core/src/Agent/CoderAgent/prompts.ts
51568
+ var basePrompt2 = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
51569
+ var editingFilesPrompt = (toolNamePrefix) => `
51570
+ ====
51571
+
51572
+ EDITING FILES
51573
+
51574
+ You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full overwrite) and **${toolNamePrefix}replace_in_file** (targeted anchor-based edits). Choose the smallest safe operation for every change.
51575
+
51576
+ # ${toolNamePrefix}write_to_file
51577
+
51578
+ ## Purpose
51579
+
51580
+ - Create a new file, or overwrite the entire contents of an existing file.
51581
+
51582
+ ## When to Use
51583
+
51584
+ - Initial file creation, such as when scaffolding a new project.
51585
+ - Overwriting large boilerplate files where you want to replace the entire content at once.
51586
+ - When the complexity or number of changes would make ${toolNamePrefix}replace_in_file unwieldy or error-prone.
51587
+ - When you need to completely restructure a file's content or change its fundamental organization.
51588
+
51589
+ ## Important Considerations
51590
+
51591
+ - Using ${toolNamePrefix}write_to_file requires providing the file's complete final content.
51592
+ - If you only need to make small changes to an existing file, consider using ${toolNamePrefix}replace_in_file instead to avoid unnecessarily rewriting the entire file.
51593
+ - While ${toolNamePrefix}write_to_file should not be your default choice, don't hesitate to use it when the situation truly calls for it.
51594
+
51595
+ # ${toolNamePrefix}replace_in_file
51596
+
51597
+ ## Purpose
51598
+
51599
+ - Make targeted edits to specific parts of an existing file without overwriting the entire file.
51600
+
51601
+ ## When to Use
51602
+
51603
+ - Small, localized changes like updating a few lines, function implementations, changing variable names, modifying a section of text, etc.
51604
+ - Targeted improvements where only specific portions of the file's content needs to be altered.
51605
+ - Especially useful for long files where much of the file will remain unchanged.
51606
+
51607
+ ## Advantages
51608
+
51609
+ - More efficient for minor edits, since you don't need to supply the entire file content.
51610
+ - Reduces the chance of errors that can occur when overwriting large files.
51611
+
51612
+ # Choosing the Appropriate Tool
51613
+
51614
+ - **Default to ${toolNamePrefix}replace_in_file** for most changes. It keeps diffs small and reduces risk.
51615
+ - **Use ${toolNamePrefix}write_to_file** when:
51616
+ - Creating new files
51617
+ - The changes are so extensive that using ${toolNamePrefix}replace_in_file would be more complex or risky
51618
+ - You need to completely reorganize or restructure a file
51619
+ - The file is relatively small and the changes affect most of its content
51620
+ - You're generating boilerplate or template files
51621
+
51622
+ # Workflow Tips
51623
+
51624
+ 1. Before editing, assess the scope of your changes and decide which tool to use.
51625
+ 2. For targeted edits, apply ${toolNamePrefix}replace_in_file with carefully crafted before/after text anchors. If you need multiple changes, you can stack multiple operations within a single ${toolNamePrefix}replace_in_file call.
51626
+ 3. For major overhauls or initial file creation, rely on ${toolNamePrefix}write_to_file.
51627
+ 4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}replace_in_file, the system will provide you with the final state of the modified file. Use this updated content as the reference point for any subsequent operations, since it reflects any auto-formatting or user-applied changes.
51628
+
51629
+ Picking the right tool keeps edits minimal, safe, and easy to review.
51630
+ `;
51631
+ var rules = (toolNamePrefix) => `
51632
+ ====
51633
+
51634
+ RULES
51635
+
51636
+ - Work only with relative paths; you may \`cd\` into child directories but never use \`cd ..\`, root, or absolute paths.
51637
+ - When generating code, tests, or other comment-capable files, prepend a comment describing the file's purpose plus “generated by polka.codes”.
51638
+ For text files (e.g. README.md), append a footer with the same notice.
51639
+ - Never describe what changed inside code comments; comments must focus on purpose or usage only.
51640
+ - Before using ${toolNamePrefix}execute_command, consider SYSTEM INFORMATION to ensure commands suit the user's OS. If a command must run in a subdirectory, prepend a single \`cd childDir &&\` segment.
51641
+ - Use ${toolNamePrefix}search_files for broad analysis, then ${toolNamePrefix}read_file to inspect context, and finally ${toolNamePrefix}replace_in_file or ${toolNamePrefix}write_to_file to modify.
51642
+ - Prefer ${toolNamePrefix}replace_in_file for focused edits; choose ${toolNamePrefix}write_to_file for new files or complete rewrites.
51643
+ - When creating a new file, look for existing files with similar content or patterns; if found, read them and use their structure or conventions as a reference.
51644
+ - Use before/after text anchors in ${toolNamePrefix}replace_in_file to target changes. If multiple operations are needed, list them in file order.
51645
+ - Do not guess unseen content. Read existing files first unless creating new ones.
51646
+ - Follow existing style, lint, and naming conventions. Ensure all changes compile and pass tests where applicable.
51647
+ - ALWAYS wait for the user's confirmation after each tool call before starting the next step.
51648
+ - The agent must never invoke more than 5 tools in a single response.
51649
+ - Do not end ${toolNamePrefix}attempt_completion output with questions or conversational prompts.
51650
+ - Avoid filler words like “Great”, “Certainly”, “Okay”, “Sure” at the start of responses; be direct and technical.
51651
+ - Keep inline documentation current as you edit.
51652
+ `;
51653
+ var objectives = (toolNamePrefix) => `
51654
+ ====
51655
+
51656
+ OBJECTIVE
51657
+
51658
+ You solve the user's task by working in small, verifiable steps.
51659
+
51660
+ 1. **Plan** - Parse the task, list clear goals, and order them logically.
51661
+ 2. **Think** - Wrap private reasoning in <thinking></thinking>.
51662
+ • Review project context.
51663
+ • Select the single best tool for the next goal.
51664
+ • Ensure every required parameter is available or can be inferred.
51665
+ 3. **Act** - Invoke one tool per step. Wait for the system's response (and user confirmation where required) before continuing.
51666
+ 4. **Iterate** - Repeat Plan → Think → Act until all goals are complete.
51667
+ 5. **Complete** - Use ${toolNamePrefix}attempt_completion to deliver the final result. Do not invite further discussion unless the user explicitly requests changes.
51668
+ `;
51669
+ var fullSystemPrompt4 = (info, tools, toolNamePrefix, instructions, scripts, useNativeTool) => `
51670
+ ${basePrompt2}
51671
+ ${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
51672
+ ${editingFilesPrompt(toolNamePrefix)}
51673
+ ${capabilities(toolNamePrefix)}
51674
+ ${rules(toolNamePrefix)}
51675
+ ${objectives(toolNamePrefix)}
51676
+ ${systemInformation(info)}
51677
+ ${customInstructions(instructions)}
51678
+ ${customScripts(scripts)}
51679
+ `;
51680
+
51681
+ // ../core/src/Agent/CoderAgent/index.ts
51682
+ class CoderAgent extends AgentBase {
51683
+ constructor(options) {
51684
+ const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
51685
+ const tools = getAvailableTools({
51686
+ provider: options.provider,
51687
+ allTools: combinedTools,
51688
+ hasAgent: (options.agents?.length ?? 0) > 0,
51689
+ permissionLevel: 3 /* Arbitrary */,
51690
+ interactive: true
51691
+ });
51692
+ const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
51693
+ const systemPrompt = fullSystemPrompt4({
51694
+ os: options.os
51695
+ }, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
51696
+ super(coderAgentInfo.name, options.ai, {
51697
+ systemPrompt,
51698
+ tools,
51699
+ toolNamePrefix,
51700
+ provider: options.provider,
51701
+ interactive: options.interactive,
51702
+ agents: options.agents,
51703
+ scripts: options.scripts,
51704
+ callback: options.callback,
51705
+ policies: options.policies,
51706
+ toolFormat: options.toolFormat,
51707
+ parameters: options.parameters ?? {},
51708
+ usageMeter: options.usageMeter ?? new UsageMeter
51709
+ });
51710
+ }
51711
+ async#runScript(scriptName, shouldReplyWithError) {
51712
+ const executeCommand = this.config.provider.executeCommand;
51713
+ if (!executeCommand) {
51714
+ return;
51715
+ }
51716
+ const script = this.config.scripts?.[scriptName];
51717
+ const command = typeof script === "string" ? script : script?.command;
51718
+ if (command) {
51719
+ try {
51720
+ const { exitCode, stdout, stderr } = await executeCommand(command, false);
51721
+ if (exitCode !== 0 && shouldReplyWithError) {
51722
+ return {
51723
+ type: "Reply" /* Reply */,
51724
+ message: responsePrompts.commandResult(command, exitCode, stdout, stderr)
51725
+ };
51726
+ }
51727
+ } catch (error81) {
51728
+ console.warn(`Failed to run ${scriptName} using command: ${command}`, error81);
51729
+ }
51730
+ }
51731
+ }
51732
+ async onBeforeInvokeTool(name17, _args) {
51733
+ if (name17 !== attemptCompletion_default.name) {
51734
+ return;
51735
+ }
51736
+ await this.#runScript("format", false);
51737
+ const checkResult = await this.#runScript("check", true);
51738
+ if (checkResult) {
51739
+ return checkResult;
51740
+ }
51741
+ const testResult = await this.#runScript("test", true);
51742
+ if (testResult) {
51743
+ return testResult;
51744
+ }
51745
+ }
51746
+ }
51747
+ var coderAgentInfo = {
51748
+ name: "coder",
51749
+ responsibilities: [
51750
+ "Editing and refactoring existing code.",
51751
+ "Creating new features or modules.",
51752
+ "Running tests and analyzing test results.",
51753
+ "Maintaining coding standards, lint rules, and general code quality."
51754
+ ]
51755
+ };
51552
51756
  // ../core/src/Agent/MultiAgent.ts
51553
51757
  class MultiAgent {
51554
51758
  #config;
@@ -51894,10 +52098,18 @@ Example Output:
51894
52098
  <tool_output>
51895
52099
  <tool_output_pr_title>Refactor Order Validation and Remove Debug Logs</tool_output_pr_title>
51896
52100
  <tool_output_pr_description>
51897
- closes #123
52101
+ Closes #123
52102
+
52103
+ **Context**:
52104
+ - Implementing changes for issue #123 - Focus on clean code and maintainability
51898
52105
 
51899
- This PR removes unnecessary debug print statements and updates order validation
51900
- to use the new validate_and_process method for improved maintainability.
52106
+ **Summary of Changes**:
52107
+ - Refactored order validation logic to use a new \`validate_and_process\` method.
52108
+ - Removed debug print statements from \`user_service.py\`.
52109
+
52110
+ **Highlights of Changed Code**:
52111
+ - \`order_service.py\`: Replaced direct call to \`process_order\` with \`validate_and_process\`.
52112
+ - \`user_service.py\`: Removed \`print("Debug info")\`.
51901
52113
  </tool_output_pr_description>
51902
52114
  </tool_output>
51903
52115
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",