@polka-codes/cli 0.9.14 → 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 +103 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39790,7 +39790,7 @@ var {
39790
39790
  Help
39791
39791
  } = import__.default;
39792
39792
  // package.json
39793
- var version = "0.9.14";
39793
+ var version = "0.9.16";
39794
39794
 
39795
39795
  // ../../node_modules/@inquirer/core/dist/esm/lib/key.js
39796
39796
  var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
@@ -78213,6 +78213,64 @@ var generateProjectConfig_default = {
78213
78213
  agent: "analyzer"
78214
78214
  };
78215
78215
 
78216
+ // ../core/src/AiTool/tools/utils/diffLineNumbers.ts
78217
+ function parseHunkHeader(header) {
78218
+ const match = header.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
78219
+ if (!match)
78220
+ return null;
78221
+ return {
78222
+ oldStart: parseInt(match[1], 10),
78223
+ oldCount: match[2] ? parseInt(match[2], 10) : 1,
78224
+ newStart: parseInt(match[3], 10),
78225
+ newCount: match[4] ? parseInt(match[4], 10) : 1,
78226
+ header
78227
+ };
78228
+ }
78229
+ function annotateDiffWithLineNumbers(diff) {
78230
+ const lines = diff.split(`
78231
+ `);
78232
+ const annotatedLines = [];
78233
+ let currentNewLine = 0;
78234
+ let currentOldLine = 0;
78235
+ let inHunk = false;
78236
+ for (const line of lines) {
78237
+ if (line.startsWith("@@")) {
78238
+ const hunk = parseHunkHeader(line);
78239
+ if (hunk) {
78240
+ currentOldLine = hunk.oldStart;
78241
+ currentNewLine = hunk.newStart;
78242
+ inHunk = true;
78243
+ }
78244
+ annotatedLines.push(line);
78245
+ continue;
78246
+ }
78247
+ if (line.startsWith("diff --git") || line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
78248
+ annotatedLines.push(line);
78249
+ inHunk = false;
78250
+ continue;
78251
+ }
78252
+ if (!inHunk) {
78253
+ annotatedLines.push(line);
78254
+ continue;
78255
+ }
78256
+ if (line.startsWith("+") && !line.startsWith("+++")) {
78257
+ annotatedLines.push(`${line} [Line ${currentNewLine}]`);
78258
+ currentNewLine++;
78259
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
78260
+ annotatedLines.push(`${line} [Line ${currentOldLine} removed]`);
78261
+ currentOldLine++;
78262
+ } else if (line.startsWith(" ")) {
78263
+ annotatedLines.push(line);
78264
+ currentOldLine++;
78265
+ currentNewLine++;
78266
+ } else {
78267
+ annotatedLines.push(line);
78268
+ }
78269
+ }
78270
+ return annotatedLines.join(`
78271
+ `);
78272
+ }
78273
+
78216
78274
  // ../core/src/AiTool/tools/gitDiff.ts
78217
78275
  var toolInfo14 = {
78218
78276
  name: "git_diff",
@@ -78229,7 +78287,18 @@ var toolInfo14 = {
78229
78287
  return val;
78230
78288
  }, exports_external.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
78231
78289
  commitRange: exports_external.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
78232
- file: exports_external.string().optional().describe("Get the diff for a specific file.")
78290
+ file: exports_external.string().optional().describe("Get the diff for a specific file."),
78291
+ contextLines: exports_external.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
78292
+ includeLineNumbers: exports_external.preprocess((val) => {
78293
+ if (typeof val === "string") {
78294
+ const lower = val.toLowerCase();
78295
+ if (lower === "false")
78296
+ return false;
78297
+ if (lower === "true")
78298
+ return true;
78299
+ }
78300
+ return val;
78301
+ }, exports_external.boolean().optional().default(false)).describe("Annotate the diff with line numbers for additions and deletions.")
78233
78302
  }),
78234
78303
  permissionLevel: 1 /* Read */
78235
78304
  };
@@ -78240,8 +78309,8 @@ var handler14 = async (provider2, args) => {
78240
78309
  message: "Not possible to execute command. Abort."
78241
78310
  };
78242
78311
  }
78243
- const { staged, file: file3, commitRange } = toolInfo14.parameters.parse(args);
78244
- const commandParts = ["git", "diff", "--no-color", "-U50"];
78312
+ const { staged, file: file3, commitRange, contextLines, includeLineNumbers } = toolInfo14.parameters.parse(args);
78313
+ const commandParts = ["git", "diff", "--no-color", `-U${contextLines}`];
78245
78314
  if (staged) {
78246
78315
  commandParts.push("--staged");
78247
78316
  }
@@ -78261,10 +78330,14 @@ var handler14 = async (provider2, args) => {
78261
78330
  message: "No diff found."
78262
78331
  };
78263
78332
  }
78333
+ let diffOutput = result.stdout;
78334
+ if (includeLineNumbers) {
78335
+ diffOutput = annotateDiffWithLineNumbers(diffOutput);
78336
+ }
78264
78337
  return {
78265
78338
  type: "Reply" /* Reply */,
78266
78339
  message: `<diff file="${file3 ?? "all"}">
78267
- ${result.stdout}
78340
+ ${diffOutput}
78268
78341
  </diff>`
78269
78342
  };
78270
78343
  }
@@ -78300,8 +78373,9 @@ You are a senior software engineer reviewing code changes.
78300
78373
 
78301
78374
  ## Viewing Changes
78302
78375
  - **Use git_diff** to inspect the actual code changes for each relevant file.
78303
- - **Pull request**: use the provided commit range for the git_diff tool.
78304
- - **Local changes**: diff staged or unstaged files using the git_diff tool.
78376
+ - **Pull request**: use the provided commit range for the git_diff tool with contextLines: 5 and includeLineNumbers: true
78377
+ - **Local changes**: diff staged or unstaged files using the git_diff tool with contextLines: 5 and includeLineNumbers: true
78378
+ - The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions
78305
78379
  - If a pull request is present you may receive:
78306
78380
  - <pr_title>
78307
78381
  - <pr_description>
@@ -78309,9 +78383,16 @@ You are a senior software engineer reviewing code changes.
78309
78383
  - A <review_instructions> tag tells you the focus of the review.
78310
78384
  - File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
78311
78385
 
78386
+ ## Line Number Reporting
78387
+ - **IMPORTANT**: Use the line numbers from the annotations in the diff output
78388
+ - For additions: Look for [Line N] annotations after the + lines
78389
+ - For deletions: Look for [Line N removed] annotations after the - lines
78390
+ - For modifications: Report the line number of the new/current code (from [Line N] annotations)
78391
+ - Report single lines as "N" and ranges as "N-M"
78392
+
78312
78393
  ## Review Guidelines
78313
78394
  Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
78314
- - **Specific issues**: Point to exact problems in the changed code with line references
78395
+ - **Specific issues**: Point to exact problems in the changed code with accurate line references from the annotations
78315
78396
  - **Actionable fixes**: Provide concrete solutions, not vague suggestions
78316
78397
  - **Clear reasoning**: Explain why each issue matters and how to fix it
78317
78398
  - **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
@@ -78374,11 +78455,11 @@ ${fileList}
78374
78455
  }
78375
78456
  let instructions = "";
78376
78457
  if (params.commitRange) {
78377
- 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.`;
78458
+ 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.`;
78378
78459
  } else if (params.staged) {
78379
- 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.";
78460
+ 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.";
78380
78461
  } else {
78381
- instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
78462
+ 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.";
78382
78463
  }
78383
78464
  parts.push(`<review_instructions>
78384
78465
  ${instructions}
@@ -104101,12 +104182,11 @@ var getModel = (config5, debugLogging = false) => {
104101
104182
  };
104102
104183
 
104103
104184
  // src/ApiProviderConfig.ts
104104
- var isClaude = (model) => model.includes("claude");
104105
104185
  var getToolFormat = (model, toolFormat) => {
104106
104186
  if (toolFormat) {
104107
104187
  return toolFormat;
104108
104188
  }
104109
- if (isClaude(model)) {
104189
+ if (model.includes("claude") || model.includes("gemini")) {
104110
104190
  return "native";
104111
104191
  }
104112
104192
  return "polka-codes";
@@ -104116,7 +104196,7 @@ var defaultModels = {
104116
104196
  ["ollama" /* Ollama */]: "deepseek-r1:32b",
104117
104197
  ["deepseek" /* DeepSeek */]: "deepseek-chat",
104118
104198
  ["openrouter" /* OpenRouter */]: "google/gemini-2.5-pro",
104119
- ["openai" /* OpenAI */]: "gpt-4.1",
104199
+ ["openai" /* OpenAI */]: "gpt-5-2025-08-07",
104120
104200
  ["google-vertex" /* GoogleVertex */]: "gemini-2.5-pro"
104121
104201
  };
104122
104202
 
@@ -104328,6 +104408,7 @@ Aborting request...`);
104328
104408
  var prices_default = {
104329
104409
  ["anthropic" /* Anthropic */]: {
104330
104410
  "claude-opus-4-20250514": { inputPrice: 15, outputPrice: 75, cacheWritesPrice: 18.75, cacheReadsPrice: 1.5, supportsThinking: true },
104411
+ "claude-opus-4-1-20250805": { inputPrice: 15, outputPrice: 75, cacheWritesPrice: 18.75, cacheReadsPrice: 1.5, supportsThinking: true },
104331
104412
  "claude-sonnet-4-20250514": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: true },
104332
104413
  "claude-3-7-sonnet-20250219": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: true },
104333
104414
  "claude-3-5-sonnet-20241022": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: false },
@@ -104340,10 +104421,9 @@ var prices_default = {
104340
104421
  },
104341
104422
  ["openrouter" /* OpenRouter */]: {},
104342
104423
  ["openai" /* OpenAI */]: {
104343
- "gpt-4.1": { inputPrice: 2, outputPrice: 8, cacheWritesPrice: 0.5, cacheReadsPrice: 0.5 },
104344
- "gpt-4.1-mini": { inputPrice: 0.4, outputPrice: 1.6, cacheWritesPrice: 0.1, cacheReadsPrice: 0.1 },
104345
- "gpt-4.1-nano": { inputPrice: 0.1, outputPrice: 0.4, cacheWritesPrice: 0.025, cacheReadsPrice: 0.025 },
104346
- "o4-mini": { inputPrice: 1.1, outputPrice: 4.4, cacheWritesPrice: 0.275, cacheReadsPrice: 0.275 }
104424
+ "gpt-5-2025-08-07": { inputPrice: 1.25, outputPrice: 10, cacheWritesPrice: 0, cacheReadsPrice: 0.125, supportsThinking: false },
104425
+ "gpt-5-mini-2025-08-07": { inputPrice: 0.25, outputPrice: 2, cacheWritesPrice: 0, cacheReadsPrice: 0.025, supportsThinking: false },
104426
+ "gpt-5-nano-2025-08-07": { inputPrice: 0.05, outputPrice: 0.4, cacheWritesPrice: 0, cacheReadsPrice: 0.005, supportsThinking: false }
104347
104427
  },
104348
104428
  ["google-vertex" /* GoogleVertex */]: {
104349
104429
  "gemini-2.5-pro": { inputPrice: 2.5, outputPrice: 10, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: true },
@@ -110986,17 +111066,16 @@ async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput, co
110986
111066
  process.exit(1);
110987
111067
  }
110988
111068
  spinner.text = "Fetching pull request details...";
110989
- const prDetails = JSON.parse(execSync3(`gh pr view ${prNumber} --json title,body,commits`, { encoding: "utf-8" }));
110990
- const defaultBranch = execSync3("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name", {
110991
- encoding: "utf-8"
110992
- }).trim();
111069
+ const prDetails = JSON.parse(execSync3(`gh pr view ${prNumber} --json title,body,commits,baseRefName,baseRefOid`, { encoding: "utf-8" }));
110993
111070
  const commitMessages = prDetails.commits.map((c) => c.messageBody).join(`
110994
111071
  ---
110995
111072
  `);
110996
111073
  spinner.text = "Getting file changes...";
110997
111074
  let changedFiles = [];
110998
111075
  try {
110999
- const diffNameStatus = execSync3(`git diff --name-status --no-color ${defaultBranch}...HEAD`, { encoding: "utf-8" });
111076
+ const diffNameStatus = execSync3(`git diff --name-status --no-color ${prDetails.baseRefOid}...HEAD`, {
111077
+ encoding: "utf-8"
111078
+ });
111000
111079
  changedFiles = parseGitDiffNameStatus(diffNameStatus);
111001
111080
  } catch (_error) {
111002
111081
  console.warn("Warning: Could not retrieve file changes list");
@@ -111004,7 +111083,7 @@ async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput, co
111004
111083
  printChangedFiles(changedFiles, spinner, isJsonOutput);
111005
111084
  spinner.text = "Generating review...";
111006
111085
  const result = await reviewDiff(sharedAiOptions, {
111007
- commitRange: `${defaultBranch}...HEAD`,
111086
+ commitRange: `${prDetails.baseRefOid}...HEAD`,
111008
111087
  pullRequestTitle: prDetails.title,
111009
111088
  pullRequestDescription: prDetails.body,
111010
111089
  commitMessages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.14",
3
+ "version": "0.9.16",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",