@polka-codes/core 0.8.4 → 0.8.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 +37 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1010,6 +1010,14 @@ var getStringArray = (args, name, defaultValue) => {
1010
1010
  if (ret === "") {
1011
1011
  return [];
1012
1012
  }
1013
+ if (Array.isArray(ret)) {
1014
+ for (const item of ret) {
1015
+ if (typeof item !== "string") {
1016
+ throw new Error(`Invalid argument type: ${name} ${item}`);
1017
+ }
1018
+ }
1019
+ return ret;
1020
+ }
1013
1021
  if (typeof ret !== "string") {
1014
1022
  throw new Error(`Invalid argument type: ${name} ${ret}`);
1015
1023
  }
@@ -3245,7 +3253,7 @@ You have access to two tools for working with files: **${toolNamePrefix}write_to
3245
3253
 
3246
3254
  ## Important Considerations
3247
3255
 
3248
- - Using ${toolNamePrefix}write_to_file requires providing the file\u2019s complete final content.
3256
+ - Using ${toolNamePrefix}write_to_file requires providing the file's complete final content.
3249
3257
  - 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.
3250
3258
  - While ${toolNamePrefix}write_to_file should not be your default choice, don't hesitate to use it when the situation truly calls for it.
3251
3259
 
@@ -3258,12 +3266,12 @@ You have access to two tools for working with files: **${toolNamePrefix}write_to
3258
3266
  ## When to Use
3259
3267
 
3260
3268
  - Small, localized changes like updating a few lines, function implementations, changing variable names, modifying a section of text, etc.
3261
- - Targeted improvements where only specific portions of the file\u2019s content needs to be altered.
3269
+ - Targeted improvements where only specific portions of the file's content needs to be altered.
3262
3270
  - Especially useful for long files where much of the file will remain unchanged.
3263
3271
 
3264
3272
  ## Advantages
3265
3273
 
3266
- - More efficient for minor edits, since you don\u2019t need to supply the entire file content.
3274
+ - More efficient for minor edits, since you don't need to supply the entire file content.
3267
3275
  - Reduces the chance of errors that can occur when overwriting large files.
3268
3276
 
3269
3277
  # Choosing the Appropriate Tool
@@ -3289,41 +3297,39 @@ var rules = (toolNamePrefix) => `
3289
3297
 
3290
3298
  RULES
3291
3299
 
3292
- - You may use \`cd\` to enter any child directory within the current working directory. For example, \`cd myChildDir\`. But you may never move to a parent directory or any directory outside your current path. For example, do not use \`cd ..\`, \`cd /\`, or any absolute path.
3293
- - Always work with relative path names, and never use absolute paths.
3294
- - When generating code or test or any file that support comments, add a comment on top of the file with a description of the file's purpose and a note that this file is generated by "polka.codes".
3295
- - When generate text file such as README.md, add a footer indicating this file is generated by "polka.codes".
3296
- - Before using the ${toolNamePrefix}execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory, and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command). For example, if you needed to run \`npm install\` in a project that's not in the current working directory, you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`. However, you can only cd into child directory, but never parent directory or root directory or home directory.
3297
- - When using the ${toolNamePrefix}search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the ${toolNamePrefix}search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use ${toolNamePrefix}read_file to examine the full context of interesting matches before using ${toolNamePrefix}replace_in_file to make informed changes.
3298
- - When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when creating files, as the ${toolNamePrefix}write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
3299
- - Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write.
3300
- - When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.
3301
- - **Adhere to any established coding style, linting rules, or naming conventions if they are known or can be inferred from the existing codebase, to maintain consistency.**
3302
- - When you want to modify a file, use the ${toolNamePrefix}replace_in_file or ${toolNamePrefix}write_to_file tool directly with the desired changes. You do not need to display the changes before using the tool.
3303
- - **Do not guess or hallucinate file content that has not been explicitly provided or read. Always read an existing file with \`${toolNamePrefix}read_file\` (or rely on content the user directly provided) before modifying it, unless you are creating a brand-new file.**
3304
- - Do not ask for more information than necessary. Use the tools provided to accomplish the user's request efficiently and effectively. When you've completed your task, you must use the ${toolNamePrefix}attempt_completion tool to present the result to the user.
3305
- - The user may provide a file's contents directly in their message, in which case you shouldn't use the ${toolNamePrefix}read_file tool to get the file contents again since you already have it.
3306
- - Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.
3307
- - NEVER end ${toolNamePrefix}attempt_completion result with a question or request to engage in further conversation! Formulate the end of your result in a way that is final and does not require further input from the user.
3308
- - You are STRICTLY FORBIDDEN from starting your messages with "Great", "Certainly", "Okay", "Sure". You should NOT be conversational in your responses, but rather direct and to the point. For example you should NOT say "Great, I've updated the CSS" but instead something like "I've updated the CSS". It is important you be clear and technical in your messages.
3309
- - When presented with images, utilize your vision capabilities to thoroughly examine them and extract meaningful information. Incorporate these insights into your thought process as you accomplish the user's task.
3310
- - When using the ${toolNamePrefix}replace_in_file tool, you must include complete lines in your SEARCH blocks, not partial lines. The system requires exact line matches and cannot match partial lines. For example, if you want to match a line containing "const x = 5;", your SEARCH block must include the entire line, not just "x = 5" or other fragments.
3311
- - When using the ${toolNamePrefix}replace_in_file tool, if you use multiple SEARCH/REPLACE blocks, list them in the order they appear in the file. For example if you need to make changes to both line 10 and line 50, first include the SEARCH/REPLACE block for line 10, followed by the SEARCH/REPLACE block for line 50.
3312
- - It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc.
3313
- - Keep the inline docs up to date if needed.
3300
+ - Work only with relative paths; you may \`cd\` into child directories but never use \`cd ..\`, root, or absolute paths.
3301
+ - When generating code, tests, or other comment-capable files, prepend a comment describing the file's purpose plus \u201Cgenerated by polka.codes\u201D.
3302
+ For text files (e.g. README.md), append a footer with the same notice.
3303
+ - Never describe what changed inside code comments; comments must focus on purpose or usage only.
3304
+ - 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.
3305
+ - 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.
3306
+ - Prefer ${toolNamePrefix}replace_in_file for focused edits; choose ${toolNamePrefix}write_to_file for new files or complete rewrites.
3307
+ - 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.
3308
+ - SEARCH blocks in ${toolNamePrefix}replace_in_file must match whole lines. If multiple blocks are needed, list them in file order.
3309
+ - Do not guess unseen content. Read existing files first unless creating new ones.
3310
+ - Follow existing style, lint, and naming conventions. Ensure all changes compile and pass tests where applicable.
3311
+ - ALWAYS wait for the user's confirmation after each tool call before starting the next step.
3312
+ - The agent must never invoke more than 5 tools in a single response.
3313
+ - Do not end ${toolNamePrefix}attempt_completion output with questions or conversational prompts.
3314
+ - Avoid filler words like \u201CGreat\u201D, \u201CCertainly\u201D, \u201COkay\u201D, \u201CSure\u201D at the start of responses; be direct and technical.
3315
+ - Keep inline documentation current as you edit.
3314
3316
  `;
3315
3317
  var objectives = (toolNamePrefix) => `
3316
3318
  ====
3317
3319
 
3318
3320
  OBJECTIVE
3319
3321
 
3320
- You accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.
3322
+ You solve the user's task by working in small, verifiable steps.
3321
3323
 
3322
- 1. Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.
3323
- 2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go.
3324
- 3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use.
3325
- 4. Once you've completed the user's task, you must use the ${toolNamePrefix}attempt_completion tool to present the result of the task to the user.
3326
- 5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.`;
3324
+ 1. **Plan** - Parse the task, list clear goals, and order them logically.
3325
+ 2. **Think** - Wrap private reasoning in <thinking></thinking>.
3326
+ \u2022 Review project context.
3327
+ \u2022 Select the single best tool for the next goal.
3328
+ \u2022 Ensure every required parameter is available or can be inferred.
3329
+ 3. **Act** - Invoke one tool per step. Wait for the system's response (and user confirmation where required) before continuing.
3330
+ 4. **Iterate** - Repeat Plan \u2192 Think \u2192 Act until all goals are complete.
3331
+ 5. **Complete** - Use ${toolNamePrefix}attempt_completion to deliver the final result. Do not invite further discussion unless the user explicitly requests changes.
3332
+ `;
3327
3333
  var fullSystemPrompt4 = (info, tools, toolNamePrefix, instructions, scripts) => `
3328
3334
  ${basePrompt2}
3329
3335
  ${toolUsePrompt(tools, toolNamePrefix)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",