@polka-codes/runner 0.9.15 → 0.9.16

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 +92 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -21067,7 +21067,7 @@ var {
21067
21067
  Help
21068
21068
  } = import__.default;
21069
21069
  // package.json
21070
- var version = "0.9.15";
21070
+ var version = "0.9.16";
21071
21071
 
21072
21072
  // src/runner.ts
21073
21073
  import { execSync } from "node:child_process";
@@ -57601,6 +57601,64 @@ var generateProjectConfig_default = {
57601
57601
  agent: "analyzer"
57602
57602
  };
57603
57603
 
57604
+ // ../core/src/AiTool/tools/utils/diffLineNumbers.ts
57605
+ function parseHunkHeader(header) {
57606
+ const match = header.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
57607
+ if (!match)
57608
+ return null;
57609
+ return {
57610
+ oldStart: parseInt(match[1], 10),
57611
+ oldCount: match[2] ? parseInt(match[2], 10) : 1,
57612
+ newStart: parseInt(match[3], 10),
57613
+ newCount: match[4] ? parseInt(match[4], 10) : 1,
57614
+ header
57615
+ };
57616
+ }
57617
+ function annotateDiffWithLineNumbers(diff) {
57618
+ const lines = diff.split(`
57619
+ `);
57620
+ const annotatedLines = [];
57621
+ let currentNewLine = 0;
57622
+ let currentOldLine = 0;
57623
+ let inHunk = false;
57624
+ for (const line of lines) {
57625
+ if (line.startsWith("@@")) {
57626
+ const hunk = parseHunkHeader(line);
57627
+ if (hunk) {
57628
+ currentOldLine = hunk.oldStart;
57629
+ currentNewLine = hunk.newStart;
57630
+ inHunk = true;
57631
+ }
57632
+ annotatedLines.push(line);
57633
+ continue;
57634
+ }
57635
+ if (line.startsWith("diff --git") || line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
57636
+ annotatedLines.push(line);
57637
+ inHunk = false;
57638
+ continue;
57639
+ }
57640
+ if (!inHunk) {
57641
+ annotatedLines.push(line);
57642
+ continue;
57643
+ }
57644
+ if (line.startsWith("+") && !line.startsWith("+++")) {
57645
+ annotatedLines.push(`${line} [Line ${currentNewLine}]`);
57646
+ currentNewLine++;
57647
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
57648
+ annotatedLines.push(`${line} [Line ${currentOldLine} removed]`);
57649
+ currentOldLine++;
57650
+ } else if (line.startsWith(" ")) {
57651
+ annotatedLines.push(line);
57652
+ currentOldLine++;
57653
+ currentNewLine++;
57654
+ } else {
57655
+ annotatedLines.push(line);
57656
+ }
57657
+ }
57658
+ return annotatedLines.join(`
57659
+ `);
57660
+ }
57661
+
57604
57662
  // ../core/src/AiTool/tools/gitDiff.ts
57605
57663
  var toolInfo14 = {
57606
57664
  name: "git_diff",
@@ -57617,7 +57675,18 @@ var toolInfo14 = {
57617
57675
  return val;
57618
57676
  }, exports_external.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
57619
57677
  commitRange: exports_external.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
57620
- file: exports_external.string().optional().describe("Get the diff for a specific file.")
57678
+ file: exports_external.string().optional().describe("Get the diff for a specific file."),
57679
+ contextLines: exports_external.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
57680
+ includeLineNumbers: exports_external.preprocess((val) => {
57681
+ if (typeof val === "string") {
57682
+ const lower = val.toLowerCase();
57683
+ if (lower === "false")
57684
+ return false;
57685
+ if (lower === "true")
57686
+ return true;
57687
+ }
57688
+ return val;
57689
+ }, exports_external.boolean().optional().default(false)).describe("Annotate the diff with line numbers for additions and deletions.")
57621
57690
  }),
57622
57691
  permissionLevel: 1 /* Read */
57623
57692
  };
@@ -57628,8 +57697,8 @@ var handler14 = async (provider2, args) => {
57628
57697
  message: "Not possible to execute command. Abort."
57629
57698
  };
57630
57699
  }
57631
- const { staged, file: file3, commitRange } = toolInfo14.parameters.parse(args);
57632
- const commandParts = ["git", "diff", "--no-color", "-U50"];
57700
+ const { staged, file: file3, commitRange, contextLines, includeLineNumbers } = toolInfo14.parameters.parse(args);
57701
+ const commandParts = ["git", "diff", "--no-color", `-U${contextLines}`];
57633
57702
  if (staged) {
57634
57703
  commandParts.push("--staged");
57635
57704
  }
@@ -57649,10 +57718,14 @@ var handler14 = async (provider2, args) => {
57649
57718
  message: "No diff found."
57650
57719
  };
57651
57720
  }
57721
+ let diffOutput = result.stdout;
57722
+ if (includeLineNumbers) {
57723
+ diffOutput = annotateDiffWithLineNumbers(diffOutput);
57724
+ }
57652
57725
  return {
57653
57726
  type: "Reply" /* Reply */,
57654
57727
  message: `<diff file="${file3 ?? "all"}">
57655
- ${result.stdout}
57728
+ ${diffOutput}
57656
57729
  </diff>`
57657
57730
  };
57658
57731
  }
@@ -57688,8 +57761,9 @@ You are a senior software engineer reviewing code changes.
57688
57761
 
57689
57762
  ## Viewing Changes
57690
57763
  - **Use git_diff** to inspect the actual code changes for each relevant file.
57691
- - **Pull request**: use the provided commit range for the git_diff tool.
57692
- - **Local changes**: diff staged or unstaged files using the git_diff tool.
57764
+ - **Pull request**: use the provided commit range for the git_diff tool with contextLines: 5 and includeLineNumbers: true
57765
+ - **Local changes**: diff staged or unstaged files using the git_diff tool with contextLines: 5 and includeLineNumbers: true
57766
+ - The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions
57693
57767
  - If a pull request is present you may receive:
57694
57768
  - <pr_title>
57695
57769
  - <pr_description>
@@ -57697,9 +57771,16 @@ You are a senior software engineer reviewing code changes.
57697
57771
  - A <review_instructions> tag tells you the focus of the review.
57698
57772
  - File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
57699
57773
 
57774
+ ## Line Number Reporting
57775
+ - **IMPORTANT**: Use the line numbers from the annotations in the diff output
57776
+ - For additions: Look for [Line N] annotations after the + lines
57777
+ - For deletions: Look for [Line N removed] annotations after the - lines
57778
+ - For modifications: Report the line number of the new/current code (from [Line N] annotations)
57779
+ - Report single lines as "N" and ranges as "N-M"
57780
+
57700
57781
  ## Review Guidelines
57701
57782
  Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
57702
- - **Specific issues**: Point to exact problems in the changed code with line references
57783
+ - **Specific issues**: Point to exact problems in the changed code with accurate line references from the annotations
57703
57784
  - **Actionable fixes**: Provide concrete solutions, not vague suggestions
57704
57785
  - **Clear reasoning**: Explain why each issue matters and how to fix it
57705
57786
  - **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
@@ -57762,11 +57843,11 @@ ${fileList}
57762
57843
  }
57763
57844
  let instructions = "";
57764
57845
  if (params.commitRange) {
57765
- instructions = `Review the pull request. Use the git_diff tool with commit range '${params.commitRange}' to inspect the actual code changes. File status information is already provided above.`;
57846
+ instructions = `Review the pull request. Use the git_diff tool with commit range '${params.commitRange}', contextLines: 5, and includeLineNumbers: true to inspect the actual code changes. The diff will include line number annotations to help you report accurate line numbers. File status information is already provided above.`;
57766
57847
  } else if (params.staged) {
57767
- instructions = "Review the staged changes. Use the git_diff tool with staged: true to inspect the actual code changes. File status information is already provided above.";
57848
+ instructions = "Review the staged changes. Use the git_diff tool with staged: true, contextLines: 5, and includeLineNumbers: true to inspect the actual code changes. The diff will include line number annotations to help you report accurate line numbers. File status information is already provided above.";
57768
57849
  } else {
57769
- instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
57850
+ instructions = "Review the unstaged changes. Use the git_diff tool with contextLines: 5 and includeLineNumbers: true to inspect the actual code changes. The diff will include line number annotations to help you report accurate line numbers. File status information is already provided above.";
57770
57851
  }
57771
57852
  parts.push(`<review_instructions>
57772
57853
  ${instructions}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.9.15",
3
+ "version": "0.9.16",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",