@polka-codes/core 0.9.3 → 0.9.4

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.
@@ -738,7 +738,7 @@ export declare const default_alias_3: {
738
738
  export declare const default_alias_4: {
739
739
  readonly name: "reviewDiff";
740
740
  readonly description: "Reviews a git diff";
741
- readonly prompt: "\n# Code Review Prompt\n\nYou are a senior software engineer reviewing code changes.\n\n## Viewing Changes\n- Use **git_diff** to inspect code.\n - **Pull request**: use the provided commit range.\n - **Local changes**: diff staged or unstaged files.\n- If a pull request is present you may receive:\n - <pr_title>\n - <pr_description>\n - <commit_messages>\n- A <review_instructions> tag tells you the focus of the review.\n\n## Focus Areas\n- Readability and maintainability\n- Correctness, edge cases, potential bugs\n- Performance implications\n- Clarity of intent\n- Best-practice adherence\n\n## Output Format\nDo **not** include praise or positive feedback. Ignore generated files such as lock files.\n\nReturn your review as a JSON object inside a ```json block, wrapped like:\n<tool_attempt_completion>\n<tool_parameter_result>\n```json\n{\n \"overview\": \"Summary of overall concerns.\",\n \"specificReviews\": [\n {\n \"file\": \"path/filename.ext\",\n \"lines\": \"N or N-M\",\n \"review\": \"Describe the issue and actionable fix or improvement.\"\n }\n ]\n}\n```\n</tool_parameter_result>\n</tool_attempt_completion>\n";
741
+ readonly prompt: "\n# Code Review Prompt\n\nYou are a senior software engineer reviewing code changes.\n\n## Critical Instructions\n**ONLY review the actual changes shown in the diff.** Do not comment on existing code that wasn't modified.\n\n## Viewing Changes\n- **Use git_diff** to inspect the actual code changes for each relevant file.\n - **Pull request**: use the provided commit range for the git_diff tool.\n - **Local changes**: diff staged or unstaged files using the git_diff tool.\n- If a pull request is present you may receive:\n - <pr_title>\n - <pr_description>\n - <commit_messages>\n- A <review_instructions> tag tells you the focus of the review.\n- File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.\n\n## Review Guidelines\nFocus exclusively on the changed lines (+ additions, - deletions, modified lines):\n- **Specific issues**: Point to exact problems in the changed code with line references\n- **Actionable fixes**: Provide concrete solutions, not vague suggestions\n- **Clear reasoning**: Explain why each issue matters and how to fix it\n- **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\n\n## What NOT to review\n- Existing unchanged code\n- Overall project structure or architecture (unless directly impacted by changes)\n- Generic best practices unrelated to the specific changes\n- Missing features or functionality not part of this diff\n\n## Output Format\nDo **not** include praise or positive feedback. Ignore generated files such as lock files.\nOnly include reviews for actual issues found in the changed code.\n\nReturn your review as a JSON object inside a ```json block, wrapped like:\n<tool_attempt_completion>\n<tool_parameter_result>\n```json\n{\n \"overview\": \"Summary of specific issues found in the diff changes, or 'No issues found' if the changes look good.\",\n \"specificReviews\": [\n {\n \"file\": \"path/filename.ext\",\n \"lines\": \"N or N-M\",\n \"review\": \"Specific issue with the changed code and exact actionable fix.\"\n }\n ]\n}\n```\n</tool_parameter_result>\n</tool_attempt_completion>\n";
742
742
  readonly formatInput: (params: Input_2) => string;
743
743
  readonly parseOutput: (output: string) => Output_2;
744
744
  readonly agent: (options: SharedAgentOptions) => AnalyzerAgent;
@@ -963,6 +963,10 @@ declare type Input_2 = {
963
963
  commitMessages?: string;
964
964
  commitRange?: string;
965
965
  staged?: boolean;
966
+ changedFiles?: Array<{
967
+ path: string;
968
+ status: string;
969
+ }>;
966
970
  };
967
971
 
968
972
  declare type InteractionProvider = {
@@ -1197,6 +1201,10 @@ declare const reviewDiff: (options: SharedAgentOptions, params: {
1197
1201
  commitMessages?: string;
1198
1202
  commitRange?: string;
1199
1203
  staged?: boolean;
1204
+ changedFiles?: Array<{
1205
+ path: string;
1206
+ status: string;
1207
+ }>;
1200
1208
  }) => Promise<{
1201
1209
  overview: string;
1202
1210
  specificReviews: {
package/dist/index.js CHANGED
@@ -1811,21 +1811,29 @@ ${instance.prompt}`;
1811
1811
  const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 90;
1812
1812
  let respMessages = [];
1813
1813
  for (let i = 0; i < retryCount; i++) {
1814
+ if (this.#aborted) {
1815
+ break;
1816
+ }
1814
1817
  respMessages = [];
1815
1818
  let timeout;
1819
+ let requestAbortController;
1820
+ requestAbortController = new AbortController();
1821
+ this.#abortController = requestAbortController;
1816
1822
  const resetTimeout = () => {
1817
1823
  if (timeout) {
1818
1824
  clearTimeout(timeout);
1819
1825
  }
1820
- if (requestTimeoutSeconds > 0) {
1826
+ if (requestTimeoutSeconds > 0 && requestAbortController) {
1821
1827
  timeout = setTimeout(() => {
1822
- console.debug(`No data received for ${requestTimeoutSeconds} seconds. Aborting request.`);
1823
- this.abort();
1828
+ console.debug(
1829
+ `Request timeout after ${requestTimeoutSeconds} seconds. Canceling current request attempt ${i + 1}/${retryCount}.`
1830
+ );
1831
+ requestAbortController?.abort();
1824
1832
  }, requestTimeoutSeconds * 1e3);
1825
1833
  }
1826
1834
  };
1827
- this.#abortController = new AbortController();
1828
1835
  try {
1836
+ resetTimeout();
1829
1837
  const streamTextOptions = {
1830
1838
  model: this.ai,
1831
1839
  messages,
@@ -1847,7 +1855,7 @@ ${instance.prompt}`;
1847
1855
  onError: async (error) => {
1848
1856
  console.error("Error in stream:", error);
1849
1857
  },
1850
- abortSignal: this.#abortController.signal
1858
+ abortSignal: requestAbortController.signal
1851
1859
  };
1852
1860
  if (this.config.toolFormat === "native") {
1853
1861
  streamTextOptions.tools = this.#toolSet;
@@ -1860,11 +1868,19 @@ ${instance.prompt}`;
1860
1868
  });
1861
1869
  const resp = await stream.response;
1862
1870
  respMessages = resp.messages;
1871
+ if (timeout) {
1872
+ clearTimeout(timeout);
1873
+ timeout = void 0;
1874
+ }
1863
1875
  } catch (error) {
1864
1876
  if (error instanceof Error && error.name === "AbortError") {
1865
- break;
1877
+ if (this.#aborted) {
1878
+ break;
1879
+ }
1880
+ console.debug(`Request attempt ${i + 1} timed out, will retry`);
1881
+ } else {
1882
+ console.error("Error in stream:", error);
1866
1883
  }
1867
- console.error("Error in stream:", error);
1868
1884
  } finally {
1869
1885
  if (timeout) {
1870
1886
  clearTimeout(timeout);
@@ -1876,13 +1892,15 @@ ${instance.prompt}`;
1876
1892
  if (this.#aborted) {
1877
1893
  break;
1878
1894
  }
1879
- console.debug(`Retrying request ${i + 1} of ${retryCount}`);
1895
+ if (i < retryCount - 1) {
1896
+ console.debug(`Retrying request ${i + 2} of ${retryCount}`);
1897
+ }
1880
1898
  }
1881
1899
  if (respMessages.length === 0) {
1882
1900
  if (this.#aborted) {
1883
1901
  return [];
1884
1902
  }
1885
- throw new Error("No assistant message received");
1903
+ throw new Error("No assistant message received after all retry attempts");
1886
1904
  }
1887
1905
  this.#messages.push(...respMessages);
1888
1906
  if (this.config.toolFormat === "native") {
@@ -1893,7 +1911,7 @@ ${instance.prompt}`;
1893
1911
  return [{ type: "text", content }];
1894
1912
  }
1895
1913
  return content.flatMap((part) => {
1896
- if (part.type === "text") {
1914
+ if (part.type === "text" || part.type === "reasoning") {
1897
1915
  return [{ type: "text", content: part.text }];
1898
1916
  }
1899
1917
  if (part.type === "tool-call") {
@@ -3360,37 +3378,48 @@ var prompt5 = `
3360
3378
 
3361
3379
  You are a senior software engineer reviewing code changes.
3362
3380
 
3381
+ ## Critical Instructions
3382
+ **ONLY review the actual changes shown in the diff.** Do not comment on existing code that wasn't modified.
3383
+
3363
3384
  ## Viewing Changes
3364
- - Use **git_diff** to inspect code.
3365
- - **Pull request**: use the provided commit range.
3366
- - **Local changes**: diff staged or unstaged files.
3385
+ - **Use git_diff** to inspect the actual code changes for each relevant file.
3386
+ - **Pull request**: use the provided commit range for the git_diff tool.
3387
+ - **Local changes**: diff staged or unstaged files using the git_diff tool.
3367
3388
  - If a pull request is present you may receive:
3368
3389
  - <pr_title>
3369
3390
  - <pr_description>
3370
3391
  - <commit_messages>
3371
3392
  - A <review_instructions> tag tells you the focus of the review.
3393
+ - File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
3394
+
3395
+ ## Review Guidelines
3396
+ Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
3397
+ - **Specific issues**: Point to exact problems in the changed code with line references
3398
+ - **Actionable fixes**: Provide concrete solutions, not vague suggestions
3399
+ - **Clear reasoning**: Explain why each issue matters and how to fix it
3400
+ - **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
3372
3401
 
3373
- ## Focus Areas
3374
- - Readability and maintainability
3375
- - Correctness, edge cases, potential bugs
3376
- - Performance implications
3377
- - Clarity of intent
3378
- - Best-practice adherence
3402
+ ## What NOT to review
3403
+ - Existing unchanged code
3404
+ - Overall project structure or architecture (unless directly impacted by changes)
3405
+ - Generic best practices unrelated to the specific changes
3406
+ - Missing features or functionality not part of this diff
3379
3407
 
3380
3408
  ## Output Format
3381
3409
  Do **not** include praise or positive feedback. Ignore generated files such as lock files.
3410
+ Only include reviews for actual issues found in the changed code.
3382
3411
 
3383
3412
  Return your review as a JSON object inside a \`\`\`json block, wrapped like:
3384
3413
  <tool_attempt_completion>
3385
3414
  <tool_parameter_result>
3386
3415
  \`\`\`json
3387
3416
  {
3388
- "overview": "Summary of overall concerns.",
3417
+ "overview": "Summary of specific issues found in the diff changes, or 'No issues found' if the changes look good.",
3389
3418
  "specificReviews": [
3390
3419
  {
3391
3420
  "file": "path/filename.ext",
3392
3421
  "lines": "N or N-M",
3393
- "review": "Describe the issue and actionable fix or improvement."
3422
+ "review": "Specific issue with the changed code and exact actionable fix."
3394
3423
  }
3395
3424
  ]
3396
3425
  }
@@ -3418,14 +3447,20 @@ ${params.pullRequestDescription}
3418
3447
  parts.push(`<commit_messages>
3419
3448
  ${params.commitMessages}
3420
3449
  </commit_messages>`);
3450
+ }
3451
+ if (params.changedFiles && params.changedFiles.length > 0) {
3452
+ const fileList = params.changedFiles.map((file) => `${file.status}: ${file.path}`).join("\n");
3453
+ parts.push(`<file_status>
3454
+ ${fileList}
3455
+ </file_status>`);
3421
3456
  }
3422
3457
  let instructions = "";
3423
3458
  if (params.commitRange) {
3424
- instructions = `Review the pull request. Get the diff using the git_diff tool with the commit range '${params.commitRange}'.`;
3459
+ 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.`;
3425
3460
  } else if (params.staged) {
3426
- instructions = "Review the staged changes. Get the diff using the git_diff tool with staged: true.";
3461
+ 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.";
3427
3462
  } else {
3428
- instructions = "Review the unstaged changes. Get the diff using the git_diff tool.";
3463
+ instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
3429
3464
  }
3430
3465
  parts.push(`<review_instructions>
3431
3466
  ${instructions}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",