@polka-codes/cli-shared 0.9.23 → 0.9.25

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 +100 -62
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -61403,13 +61403,14 @@ Retrying request ${i + 2} of ${retryCount}`);
61403
61403
  return resp;
61404
61404
  };
61405
61405
  let hasPause = false;
61406
+ const toolUseContents = response.filter((c) => c.type === "tool_use");
61406
61407
  outer:
61407
61408
  for (const content of response) {
61408
61409
  switch (content.type) {
61409
61410
  case "text":
61410
61411
  break;
61411
61412
  case "tool_use": {
61412
- await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, content: content.params });
61413
+ await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, params: content.params });
61413
61414
  const toolResp = await this.#invokeTool(content.name, content.params);
61414
61415
  switch (toolResp.type) {
61415
61416
  case "Reply" /* Reply */: {
@@ -61418,52 +61419,73 @@ Retrying request ${i + 2} of ${retryCount}`);
61418
61419
  break;
61419
61420
  }
61420
61421
  case "Exit" /* Exit */:
61422
+ case "HandOver" /* HandOver */:
61423
+ case "Delegate" /* Delegate */: {
61424
+ if (this.config.toolFormat === "native" && toolUseContents.length > 1) {
61425
+ const message = {
61426
+ type: "Error" /* Error */,
61427
+ message: {
61428
+ type: "error-text",
61429
+ value: `Error: The tool '${content.name}' must be called alone, but it was called with other tools.`
61430
+ },
61431
+ canRetry: false
61432
+ };
61433
+ await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, error: message });
61434
+ toolResponses.push({
61435
+ type: "response",
61436
+ tool: content.name,
61437
+ response: processResponse(message.message),
61438
+ id: content.id
61439
+ });
61440
+ break;
61441
+ }
61421
61442
  if (toolResponses.length > 0) {
61422
61443
  break outer;
61423
61444
  }
61424
- return { type: "exit", reason: toolResp };
61445
+ if (toolResp.type === "Exit" /* Exit */) {
61446
+ return { type: "exit", reason: toolResp };
61447
+ }
61448
+ if (toolResp.type === "HandOver" /* HandOver */) {
61449
+ await this.#callback({
61450
+ kind: "ToolHandOver" /* ToolHandOver */,
61451
+ agent: this,
61452
+ tool: content.name,
61453
+ agentName: toolResp.agentName,
61454
+ task: toolResp.task,
61455
+ context: toolResp.context,
61456
+ files: toolResp.files
61457
+ });
61458
+ return { type: "exit", reason: toolResp };
61459
+ }
61460
+ if (toolResp.type === "Delegate" /* Delegate */) {
61461
+ await this.#callback({
61462
+ kind: "ToolDelegate" /* ToolDelegate */,
61463
+ agent: this,
61464
+ tool: content.name,
61465
+ agentName: toolResp.agentName,
61466
+ task: toolResp.task,
61467
+ context: toolResp.context,
61468
+ files: toolResp.files
61469
+ });
61470
+ return { type: "exit", reason: toolResp };
61471
+ }
61472
+ break;
61473
+ }
61425
61474
  case "Invalid" /* Invalid */: {
61426
61475
  await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
61427
61476
  toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
61428
- break outer;
61429
- }
61430
- case "Error" /* Error */: {
61431
- await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
61432
- toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
61433
- break outer;
61434
- }
61435
- case "Interrupted" /* Interrupted */:
61436
- await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name, content: toolResp.message });
61437
- return { type: "exit", reason: toolResp };
61438
- case "HandOver" /* HandOver */: {
61439
- if (toolResponses.length > 0) {
61477
+ if (this.config.toolFormat !== "native") {
61440
61478
  break outer;
61441
61479
  }
61442
- await this.#callback({
61443
- kind: "ToolHandOver" /* ToolHandOver */,
61444
- agent: this,
61445
- tool: content.name,
61446
- agentName: toolResp.agentName,
61447
- task: toolResp.task,
61448
- context: toolResp.context,
61449
- files: toolResp.files
61450
- });
61451
- return { type: "exit", reason: toolResp };
61480
+ break;
61452
61481
  }
61453
- case "Delegate" /* Delegate */: {
61454
- if (toolResponses.length > 0) {
61482
+ case "Error" /* Error */: {
61483
+ await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, error: toolResp.message });
61484
+ toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
61485
+ if (this.config.toolFormat !== "native") {
61455
61486
  break outer;
61456
61487
  }
61457
- await this.#callback({
61458
- kind: "ToolDelegate" /* ToolDelegate */,
61459
- agent: this,
61460
- tool: content.name,
61461
- agentName: toolResp.agentName,
61462
- task: toolResp.task,
61463
- context: toolResp.context,
61464
- files: toolResp.files
61465
- });
61466
- return { type: "exit", reason: toolResp };
61488
+ break;
61467
61489
  }
61468
61490
  case "Pause" /* Pause */: {
61469
61491
  await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
@@ -62568,7 +62590,7 @@ var toolInfo15 = {
62568
62590
  return val;
62569
62591
  }, exports_external.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
62570
62592
  commitRange: exports_external.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
62571
- file: exports_external.string().optional().describe("Get the diff for a specific file."),
62593
+ file: exports_external.string().describe("Get the diff for a specific file."),
62572
62594
  contextLines: exports_external.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
62573
62595
  includeLineNumbers: exports_external.preprocess((val) => {
62574
62596
  if (typeof val === "string") {
@@ -62602,7 +62624,7 @@ var handler15 = async (provider2, args) => {
62602
62624
  commandParts.push(commitRange);
62603
62625
  }
62604
62626
  if (file3) {
62605
- commandParts.push("--", file3);
62627
+ commandParts.push("--", `'${file3}'`);
62606
62628
  }
62607
62629
  const command = commandParts.join(" ");
62608
62630
  try {
@@ -62665,42 +62687,58 @@ var prompt5 = `
62665
62687
  You are a senior software engineer reviewing code changes.
62666
62688
 
62667
62689
  ## Critical Instructions
62668
- **ONLY review the actual changes shown in the diff.** Do not comment on existing code that wasn't modified.
62690
+ - **ONLY review the actual changes shown in the diff.** Do not comment on existing code that wasn't modified.
62691
+ - **ONLY run git_diff on files that are reviewable source/config files** per the "File Selection for git_diff" rules below. Do not pass excluded files to git_diff.
62692
+
62693
+ ## File Selection for git_diff
62694
+ Use <file_status> to decide which files to diff. Include only files likely to contain human-authored source or meaningful configuration.
62695
+
62696
+ Include (run git_diff):
62697
+ - Application/source code
62698
+ - UI/templates/assets code
62699
+ - Infra/config that affects behavior
62700
+
62701
+ Exclude (do NOT run git_diff; do not review):
62702
+ - Lockfiles
62703
+ - Generated/build artifacts & deps
62704
+ - Test artifacts/snapshots
62705
+ - Data and fixtures
62706
+ - Binary/media/minified/maps
62669
62707
 
62670
62708
  ## Viewing Changes
62671
- - **Use git_diff** to inspect the actual code changes for each relevant file.
62672
- - **Pull request**: use the provided commit range for the git_diff tool with contextLines: 5 and includeLineNumbers: true
62673
- - **Local changes**: diff staged or unstaged files using the git_diff tool with contextLines: 5 and includeLineNumbers: true
62674
- - The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions
62675
- - If a pull request is present you may receive:
62709
+ - For each included file, **use git_diff** to inspect the actual code changes:
62710
+ - **Pull request:** use the provided commit range for the git_diff tool with contextLines: 5 and includeLineNumbers: true, but only surface and review the included files.
62711
+ - **Local changes:** diff staged or unstaged included files using git_diff with contextLines: 5 and includeLineNumbers: true.
62712
+ - The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions.
62713
+ - You may receive:
62676
62714
  - <pr_title>
62677
62715
  - <pr_description>
62678
62716
  - <commit_messages>
62679
62717
  - A <review_instructions> tag tells you the focus of the review.
62680
- - File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
62718
+ - Use <file_status> to understand which files were modified, added, deleted, or renamed and to apply the inclusion/exclusion rules above.
62681
62719
 
62682
62720
  ## Line Number Reporting
62683
- - **IMPORTANT**: Use the line numbers from the annotations in the diff output
62684
- - For additions: Look for [Line N] annotations after the + lines
62685
- - For deletions: Look for [Line N removed] annotations after the - lines
62686
- - For modifications: Report the line number of the new/current code (from [Line N] annotations)
62687
- - Report single lines as "N" and ranges as "N-M"
62721
+ - Use the line numbers from the annotations in the diff output.
62722
+ - For additions: use the number from the [Line N] annotation after the + line.
62723
+ - For deletions: use the number from the [Line N removed] annotation after the - line.
62724
+ - For modifications: report the line number of the new/current code (from [Line N]).
62725
+ - Report single lines as "N" and ranges as "N-M".
62688
62726
 
62689
62727
  ## Review Guidelines
62690
62728
  Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
62691
- - **Specific issues**: Point to exact problems in the changed code with accurate line references from the annotations
62692
- - **Actionable fixes**: Provide concrete solutions, not vague suggestions
62693
- - **Clear reasoning**: Explain why each issue matters and how to fix it
62694
- - **Avoid generic advice**: No generic suggestions like "add more tests", "improve documentation", or "follow best practices" unless directly related to a specific problem in the diff
62729
+ - **Specific issues:** Point to exact problems in the changed code with accurate line references from the annotations.
62730
+ - **Actionable fixes:** Provide concrete solutions, not vague suggestions.
62731
+ - **Clear reasoning:** Explain why each issue matters and how to fix it.
62732
+ - **Avoid generic advice** unless directly tied to a specific problem visible in the diff.
62695
62733
 
62696
62734
  ## What NOT to review
62697
- - Existing unchanged code
62698
- - Overall project structure or architecture (unless directly impacted by changes)
62699
- - Generic best practices unrelated to the specific changes
62700
- - Missing features or functionality not part of this diff
62735
+ - Files excluded by the "File Selection for git_diff" rules (do not diff or comment on them).
62736
+ - Existing unchanged code.
62737
+ - Overall project structure/architecture unless directly impacted by the changes.
62738
+ - Missing features or functionality not part of this diff.
62701
62739
 
62702
62740
  ## Output Format
62703
- Do **not** include praise or positive feedback. Ignore generated files such as lock files.
62741
+ Do not include praise or positive feedback.
62704
62742
  Only include reviews for actual issues found in the changed code.
62705
62743
 
62706
62744
  Return your review as a JSON object inside a \`\`\`json block, wrapped like:
@@ -62708,7 +62746,7 @@ Return your review as a JSON object inside a \`\`\`json block, wrapped like:
62708
62746
  <tool_parameter_result>
62709
62747
  \`\`\`json
62710
62748
  {
62711
- "overview": "Summary of specific issues found in the diff changes, or 'No issues found' if the changes look good.",
62749
+ "overview": "Summary of specific issues found in the diff changes, 'No issues found', or 'No reviewable changes' if all modified files were excluded.",
62712
62750
  "specificReviews": [
62713
62751
  {
62714
62752
  "file": "path/filename.ext",
@@ -69059,7 +69097,7 @@ ${event.systemPrompt}`);
69059
69097
  case "ToolUse" /* ToolUse */: {
69060
69098
  customConsole.log(source_default.yellow(`
69061
69099
 
69062
- Tool use:`, event.tool), event.content);
69100
+ Tool use:`, event.tool), event.params);
69063
69101
  const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
69064
69102
  stats.calls++;
69065
69103
  toolCallStats.set(event.tool, stats);
@@ -69077,7 +69115,7 @@ Tool use:`, event.tool), event.content);
69077
69115
  customConsole.error(source_default.red(`
69078
69116
 
69079
69117
  Tool error:`, event.tool));
69080
- customConsole.error(source_default.red(event.content));
69118
+ customConsole.error(event.error);
69081
69119
  const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
69082
69120
  stats.errors++;
69083
69121
  toolCallStats.set(event.tool, stats);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.23",
3
+ "version": "0.9.25",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",