@polka-codes/cli 0.8.12 → 0.8.13

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 +70 -9
  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.12";
38450
+ var version = "0.8.13";
38451
38451
 
38452
38452
  // ../core/src/AiService/AiServiceBase.ts
38453
38453
  class AiServiceBase {
@@ -48240,11 +48240,11 @@ var delegate_default = {
48240
48240
  // ../core/src/tools/executeCommand.ts
48241
48241
  var toolInfo4 = {
48242
48242
  name: "execute_command",
48243
- description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call, no other tool calls are allowed in the same assistant response.",
48243
+ description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. **IMPORTANT**: After an `execute_command` call, you MUST stop and NOT allowed to make further tool calls in the same message.",
48244
48244
  parameters: [
48245
48245
  {
48246
48246
  name: "command",
48247
- description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.",
48247
+ description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.",
48248
48248
  required: true,
48249
48249
  usageValue: "your-command-here"
48250
48250
  },
@@ -49520,7 +49520,7 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
49520
49520
 
49521
49521
  TOOL USE
49522
49522
 
49523
- You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
49523
+ You have access to a set of tools that are executed upon the user's approval. You can use up to 5 tool calls per message, and will receive the results of those tool uses in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
49524
49524
 
49525
49525
  # Tool Use Formatting
49526
49526
 
@@ -49586,18 +49586,16 @@ ${tools.map((tool) => {
49586
49586
 
49587
49587
  1. **Outline Your Thought Process**
49588
49588
  - Before using a tool, wrap your reasoning inside \`<thinking>\` tags. Be concise—just enough to clarify your plan and the rationale behind selecting a specific tool.
49589
-
49590
49589
  2. **Wait for Feedback**
49591
49590
  - After using a tool, wait for the user's response indicating success/failure or any output logs. Do not assume the result of a tool without explicit confirmation.
49592
-
49593
49591
  3. **Error Handling**
49594
49592
  - If a tool fails or produces an unexpected result, analyze the error, decide on an alternative approach or tool, and proceed carefully.
49595
-
49596
49593
  4. **Avoid Repetition**
49597
49594
  - Do not quote or repeat previous commands or prompts verbatim. Move the conversation forward by focusing on the latest required action.
49598
-
49599
49595
  5. **No Unnecessary Re-invocations**
49600
- - Only invoke the same tool again if a genuine need arises (e.g., different parameters or updated context).`;
49596
+ - Only invoke the same tool again if a genuine need arises (e.g., different parameters or updated context).
49597
+ 6. **Tool Call Limit**
49598
+ - Do not make more than 5 tool calls in a single message.`;
49601
49599
  };
49602
49600
  var agentsPrompt = (agents, name) => `
49603
49601
  ====
@@ -54728,6 +54726,65 @@ var KnowledgeManagementPolicy = (tools) => {
54728
54726
  }
54729
54727
  };
54730
54728
  };
54729
+ // ../core/src/Agent/policies/TruncateContext.ts
54730
+ var DEFAULT_MAX_TOKENS_ESTIMATE = 8000;
54731
+ function getMaxTokens(agent) {
54732
+ const params = agent.parameters || {};
54733
+ if (params.maxTokens && typeof params.maxTokens === "number" && params.maxTokens > 0) {
54734
+ return params.maxTokens;
54735
+ }
54736
+ return DEFAULT_MAX_TOKENS_ESTIMATE;
54737
+ }
54738
+ function estimateTokens(text) {
54739
+ return Math.ceil(text.length / 4);
54740
+ }
54741
+ var TruncateContextPolicy = (tools) => {
54742
+ return {
54743
+ name: "truncatecontext" /* TruncateContext */,
54744
+ async onBeforeRequest(agent) {
54745
+ const messages = agent.messages;
54746
+ if (messages.length < 3) {
54747
+ return;
54748
+ }
54749
+ let totalTokens = 0;
54750
+ for (const msg of messages) {
54751
+ if (typeof msg.content === "string") {
54752
+ totalTokens += estimateTokens(msg.content);
54753
+ } else if (Array.isArray(msg.content)) {
54754
+ for (const block of msg.content) {
54755
+ if (typeof block === "object" && "text" in block && typeof block.text === "string") {
54756
+ totalTokens += estimateTokens(block.text);
54757
+ }
54758
+ }
54759
+ }
54760
+ }
54761
+ const maxTokens = getMaxTokens(agent);
54762
+ if (totalTokens <= maxTokens) {
54763
+ return;
54764
+ }
54765
+ const totalMessages = messages.length;
54766
+ const messagesToKeep = Math.ceil(totalMessages / 2);
54767
+ const minKeep = Math.max(2, messagesToKeep);
54768
+ if (minKeep >= totalMessages) {
54769
+ return;
54770
+ }
54771
+ const keepFromStart = Math.floor(minKeep / 2);
54772
+ const keepFromEnd = minKeep - keepFromStart;
54773
+ const startMessages = messages.slice(0, keepFromStart);
54774
+ const endMessages = messages.slice(-keepFromEnd);
54775
+ const truncatedCount = totalMessages - minKeep;
54776
+ const truncatedMessages = [
54777
+ ...startMessages,
54778
+ {
54779
+ role: "user",
54780
+ content: `Note: ${truncatedCount} messages were truncated from the middle to prevent context overflow.`
54781
+ },
54782
+ ...endMessages
54783
+ ];
54784
+ agent.setMessages(truncatedMessages);
54785
+ }
54786
+ };
54787
+ };
54731
54788
  // ../core/src/Agent/index.ts
54732
54789
  var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo, codeFixerAgentInfo];
54733
54790
  // ../core/src/AiTool/createNewProject.ts
@@ -61503,6 +61560,10 @@ class Runner {
61503
61560
  this.#hasKnowledgeManagementPolicy = true;
61504
61561
  console.log("KnowledgeManagementPolicy enabled");
61505
61562
  break;
61563
+ case "truncatecontext" /* TruncateContext */:
61564
+ policies2.push(TruncateContextPolicy);
61565
+ console.log("TruncateContextPolicy enabled");
61566
+ break;
61506
61567
  default:
61507
61568
  console.log("Unknown policy:", policy);
61508
61569
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.8.12",
3
+ "version": "0.8.13",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",