@polka-codes/cli-shared 0.9.15 → 0.9.17

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 +91 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -52239,6 +52239,64 @@ var generateProjectConfig_default = {
52239
52239
  agent: "analyzer"
52240
52240
  };
52241
52241
 
52242
+ // ../core/src/AiTool/tools/utils/diffLineNumbers.ts
52243
+ function parseHunkHeader(header) {
52244
+ const match = header.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
52245
+ if (!match)
52246
+ return null;
52247
+ return {
52248
+ oldStart: parseInt(match[1], 10),
52249
+ oldCount: match[2] ? parseInt(match[2], 10) : 1,
52250
+ newStart: parseInt(match[3], 10),
52251
+ newCount: match[4] ? parseInt(match[4], 10) : 1,
52252
+ header
52253
+ };
52254
+ }
52255
+ function annotateDiffWithLineNumbers(diff) {
52256
+ const lines = diff.split(`
52257
+ `);
52258
+ const annotatedLines = [];
52259
+ let currentNewLine = 0;
52260
+ let currentOldLine = 0;
52261
+ let inHunk = false;
52262
+ for (const line of lines) {
52263
+ if (line.startsWith("@@")) {
52264
+ const hunk = parseHunkHeader(line);
52265
+ if (hunk) {
52266
+ currentOldLine = hunk.oldStart;
52267
+ currentNewLine = hunk.newStart;
52268
+ inHunk = true;
52269
+ }
52270
+ annotatedLines.push(line);
52271
+ continue;
52272
+ }
52273
+ if (line.startsWith("diff --git") || line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
52274
+ annotatedLines.push(line);
52275
+ inHunk = false;
52276
+ continue;
52277
+ }
52278
+ if (!inHunk) {
52279
+ annotatedLines.push(line);
52280
+ continue;
52281
+ }
52282
+ if (line.startsWith("+") && !line.startsWith("+++")) {
52283
+ annotatedLines.push(`${line} [Line ${currentNewLine}]`);
52284
+ currentNewLine++;
52285
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
52286
+ annotatedLines.push(`${line} [Line ${currentOldLine} removed]`);
52287
+ currentOldLine++;
52288
+ } else if (line.startsWith(" ")) {
52289
+ annotatedLines.push(line);
52290
+ currentOldLine++;
52291
+ currentNewLine++;
52292
+ } else {
52293
+ annotatedLines.push(line);
52294
+ }
52295
+ }
52296
+ return annotatedLines.join(`
52297
+ `);
52298
+ }
52299
+
52242
52300
  // ../core/src/AiTool/tools/gitDiff.ts
52243
52301
  var toolInfo14 = {
52244
52302
  name: "git_diff",
@@ -52255,7 +52313,18 @@ var toolInfo14 = {
52255
52313
  return val;
52256
52314
  }, exports_external.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
52257
52315
  commitRange: exports_external.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
52258
- file: exports_external.string().optional().describe("Get the diff for a specific file.")
52316
+ file: exports_external.string().optional().describe("Get the diff for a specific file."),
52317
+ contextLines: exports_external.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
52318
+ includeLineNumbers: exports_external.preprocess((val) => {
52319
+ if (typeof val === "string") {
52320
+ const lower = val.toLowerCase();
52321
+ if (lower === "false")
52322
+ return false;
52323
+ if (lower === "true")
52324
+ return true;
52325
+ }
52326
+ return val;
52327
+ }, exports_external.boolean().optional().default(false)).describe("Annotate the diff with line numbers for additions and deletions.")
52259
52328
  }),
52260
52329
  permissionLevel: 1 /* Read */
52261
52330
  };
@@ -52266,8 +52335,8 @@ var handler14 = async (provider2, args) => {
52266
52335
  message: "Not possible to execute command. Abort."
52267
52336
  };
52268
52337
  }
52269
- const { staged, file: file3, commitRange } = toolInfo14.parameters.parse(args);
52270
- const commandParts = ["git", "diff", "--no-color", "-U50"];
52338
+ const { staged, file: file3, commitRange, contextLines, includeLineNumbers } = toolInfo14.parameters.parse(args);
52339
+ const commandParts = ["git", "diff", "--no-color", `-U${contextLines}`];
52271
52340
  if (staged) {
52272
52341
  commandParts.push("--staged");
52273
52342
  }
@@ -52287,10 +52356,14 @@ var handler14 = async (provider2, args) => {
52287
52356
  message: "No diff found."
52288
52357
  };
52289
52358
  }
52359
+ let diffOutput = result.stdout;
52360
+ if (includeLineNumbers) {
52361
+ diffOutput = annotateDiffWithLineNumbers(diffOutput);
52362
+ }
52290
52363
  return {
52291
52364
  type: "Reply" /* Reply */,
52292
52365
  message: `<diff file="${file3 ?? "all"}">
52293
- ${result.stdout}
52366
+ ${diffOutput}
52294
52367
  </diff>`
52295
52368
  };
52296
52369
  }
@@ -52326,8 +52399,9 @@ You are a senior software engineer reviewing code changes.
52326
52399
 
52327
52400
  ## Viewing Changes
52328
52401
  - **Use git_diff** to inspect the actual code changes for each relevant file.
52329
- - **Pull request**: use the provided commit range for the git_diff tool.
52330
- - **Local changes**: diff staged or unstaged files using the git_diff tool.
52402
+ - **Pull request**: use the provided commit range for the git_diff tool with contextLines: 5 and includeLineNumbers: true
52403
+ - **Local changes**: diff staged or unstaged files using the git_diff tool with contextLines: 5 and includeLineNumbers: true
52404
+ - The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions
52331
52405
  - If a pull request is present you may receive:
52332
52406
  - <pr_title>
52333
52407
  - <pr_description>
@@ -52335,9 +52409,16 @@ You are a senior software engineer reviewing code changes.
52335
52409
  - A <review_instructions> tag tells you the focus of the review.
52336
52410
  - File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
52337
52411
 
52412
+ ## Line Number Reporting
52413
+ - **IMPORTANT**: Use the line numbers from the annotations in the diff output
52414
+ - For additions: Look for [Line N] annotations after the + lines
52415
+ - For deletions: Look for [Line N removed] annotations after the - lines
52416
+ - For modifications: Report the line number of the new/current code (from [Line N] annotations)
52417
+ - Report single lines as "N" and ranges as "N-M"
52418
+
52338
52419
  ## Review Guidelines
52339
52420
  Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
52340
- - **Specific issues**: Point to exact problems in the changed code with line references
52421
+ - **Specific issues**: Point to exact problems in the changed code with accurate line references from the annotations
52341
52422
  - **Actionable fixes**: Provide concrete solutions, not vague suggestions
52342
52423
  - **Clear reasoning**: Explain why each issue matters and how to fix it
52343
52424
  - **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
@@ -52400,11 +52481,11 @@ ${fileList}
52400
52481
  }
52401
52482
  let instructions = "";
52402
52483
  if (params.commitRange) {
52403
- 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.`;
52484
+ 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.`;
52404
52485
  } else if (params.staged) {
52405
- 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.";
52486
+ 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.";
52406
52487
  } else {
52407
- instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
52488
+ 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.";
52408
52489
  }
52409
52490
  parts.push(`<review_instructions>
52410
52491
  ${instructions}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.15",
3
+ "version": "0.9.17",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",