@polka-codes/core 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.
- package/dist/_tsup-dts-rollup.d.ts +37 -1
- package/dist/index.js +88 -10
- package/package.json +1 -1
|
@@ -176,6 +176,12 @@ export { AnalyzerAgentOptions }
|
|
|
176
176
|
export { AnalyzerAgentOptions as AnalyzerAgentOptions_alias_1 }
|
|
177
177
|
export { AnalyzerAgentOptions as AnalyzerAgentOptions_alias_2 }
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Annotate a diff with line numbers for additions and deletions
|
|
181
|
+
* Adds [Line N] for additions and [Line N removed] for deletions
|
|
182
|
+
*/
|
|
183
|
+
export declare function annotateDiffWithLineNumbers(diff: string): string;
|
|
184
|
+
|
|
179
185
|
declare class ArchitectAgent extends AgentBase {
|
|
180
186
|
constructor(options: ArchitectAgentOptions);
|
|
181
187
|
onBeforeInvokeTool(): Promise<undefined>;
|
|
@@ -743,7 +749,7 @@ export declare const default_alias_3: {
|
|
|
743
749
|
export declare const default_alias_4: {
|
|
744
750
|
readonly name: "reviewDiff";
|
|
745
751
|
readonly description: "Reviews a git diff";
|
|
746
|
-
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
|
|
752
|
+
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 with contextLines: 5 and includeLineNumbers: true\n - **Local changes**: diff staged or unstaged files using the git_diff tool with contextLines: 5 and includeLineNumbers: true\n- The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions\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## Line Number Reporting\n- **IMPORTANT**: Use the line numbers from the annotations in the diff output\n- For additions: Look for [Line N] annotations after the + lines\n- For deletions: Look for [Line N removed] annotations after the - lines\n- For modifications: Report the line number of the new/current code (from [Line N] annotations)\n- Report single lines as \"N\" and ranges as \"N-M\"\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 accurate line references from the annotations\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";
|
|
747
753
|
readonly formatInput: (params: Input_2) => string;
|
|
748
754
|
readonly parseOutput: (output: string) => Output_2;
|
|
749
755
|
readonly agent: (options: SharedAgentOptions) => AnalyzerAgent;
|
|
@@ -757,6 +763,8 @@ export declare const default_alias_5: {
|
|
|
757
763
|
staged: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
758
764
|
commitRange: z.ZodOptional<z.ZodString>;
|
|
759
765
|
file: z.ZodOptional<z.ZodString>;
|
|
766
|
+
contextLines: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
|
|
767
|
+
includeLineNumbers: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
760
768
|
}, z.core.$strip>;
|
|
761
769
|
readonly permissionLevel: PermissionLevel.Read;
|
|
762
770
|
}, CommandProvider>;
|
|
@@ -767,10 +775,20 @@ export declare const default_alias_5: {
|
|
|
767
775
|
staged: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
768
776
|
commitRange: z.ZodOptional<z.ZodString>;
|
|
769
777
|
file: z.ZodOptional<z.ZodString>;
|
|
778
|
+
contextLines: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
|
|
779
|
+
includeLineNumbers: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
770
780
|
}, z.core.$strip>;
|
|
771
781
|
permissionLevel: PermissionLevel.Read;
|
|
772
782
|
};
|
|
773
783
|
|
|
784
|
+
export declare interface DiffHunk {
|
|
785
|
+
oldStart: number;
|
|
786
|
+
oldCount: number;
|
|
787
|
+
newStart: number;
|
|
788
|
+
newCount: number;
|
|
789
|
+
header: string;
|
|
790
|
+
}
|
|
791
|
+
|
|
774
792
|
/**
|
|
775
793
|
* Returns the directory portion of a path string.
|
|
776
794
|
* Strips trailing slashes, then takes everything up to the last slash.
|
|
@@ -811,6 +829,16 @@ export { ExitReason }
|
|
|
811
829
|
export { ExitReason as ExitReason_alias_1 }
|
|
812
830
|
export { ExitReason as ExitReason_alias_2 }
|
|
813
831
|
|
|
832
|
+
/**
|
|
833
|
+
* Extract line ranges from a diff for a specific file
|
|
834
|
+
* Returns an array of line ranges that were modified
|
|
835
|
+
*/
|
|
836
|
+
export declare function extractModifiedLineRanges(diff: string, filePath?: string): Array<{
|
|
837
|
+
start: number;
|
|
838
|
+
end: number;
|
|
839
|
+
type: 'added' | 'removed' | 'modified';
|
|
840
|
+
}>;
|
|
841
|
+
|
|
814
842
|
declare type FilesystemProvider = {
|
|
815
843
|
readFile?: (path: string, includeIgnored: boolean) => Promise<string | undefined>;
|
|
816
844
|
writeFile?: (path: string, content: string) => Promise<void>;
|
|
@@ -1157,6 +1185,12 @@ export { parseAssistantMessage }
|
|
|
1157
1185
|
export { parseAssistantMessage as parseAssistantMessage_alias_1 }
|
|
1158
1186
|
export { parseAssistantMessage as parseAssistantMessage_alias_2 }
|
|
1159
1187
|
|
|
1188
|
+
/**
|
|
1189
|
+
* Parse a unified diff hunk header
|
|
1190
|
+
* Format: @@ -oldStart,oldCount +newStart,newCount @@ optional context
|
|
1191
|
+
*/
|
|
1192
|
+
export declare function parseHunkHeader(header: string): DiffHunk | null;
|
|
1193
|
+
|
|
1160
1194
|
declare enum PermissionLevel {
|
|
1161
1195
|
None = 0,
|
|
1162
1196
|
Read = 1,
|
|
@@ -1460,6 +1494,8 @@ export declare const toolInfo: {
|
|
|
1460
1494
|
staged: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
1461
1495
|
commitRange: z.ZodOptional<z.ZodString>;
|
|
1462
1496
|
file: z.ZodOptional<z.ZodString>;
|
|
1497
|
+
contextLines: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
|
|
1498
|
+
includeLineNumbers: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
1463
1499
|
}, z.core.$strip>;
|
|
1464
1500
|
readonly permissionLevel: PermissionLevel.Read;
|
|
1465
1501
|
};
|
package/dist/index.js
CHANGED
|
@@ -3363,6 +3363,63 @@ var generateProjectConfig_default = {
|
|
|
3363
3363
|
|
|
3364
3364
|
// src/AiTool/tools/gitDiff.ts
|
|
3365
3365
|
import { z as z16 } from "zod";
|
|
3366
|
+
|
|
3367
|
+
// src/AiTool/tools/utils/diffLineNumbers.ts
|
|
3368
|
+
function parseHunkHeader(header) {
|
|
3369
|
+
const match = header.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
3370
|
+
if (!match) return null;
|
|
3371
|
+
return {
|
|
3372
|
+
oldStart: parseInt(match[1], 10),
|
|
3373
|
+
oldCount: match[2] ? parseInt(match[2], 10) : 1,
|
|
3374
|
+
newStart: parseInt(match[3], 10),
|
|
3375
|
+
newCount: match[4] ? parseInt(match[4], 10) : 1,
|
|
3376
|
+
header
|
|
3377
|
+
};
|
|
3378
|
+
}
|
|
3379
|
+
function annotateDiffWithLineNumbers(diff) {
|
|
3380
|
+
const lines = diff.split("\n");
|
|
3381
|
+
const annotatedLines = [];
|
|
3382
|
+
let currentNewLine = 0;
|
|
3383
|
+
let currentOldLine = 0;
|
|
3384
|
+
let inHunk = false;
|
|
3385
|
+
for (const line of lines) {
|
|
3386
|
+
if (line.startsWith("@@")) {
|
|
3387
|
+
const hunk = parseHunkHeader(line);
|
|
3388
|
+
if (hunk) {
|
|
3389
|
+
currentOldLine = hunk.oldStart;
|
|
3390
|
+
currentNewLine = hunk.newStart;
|
|
3391
|
+
inHunk = true;
|
|
3392
|
+
}
|
|
3393
|
+
annotatedLines.push(line);
|
|
3394
|
+
continue;
|
|
3395
|
+
}
|
|
3396
|
+
if (line.startsWith("diff --git") || line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
|
|
3397
|
+
annotatedLines.push(line);
|
|
3398
|
+
inHunk = false;
|
|
3399
|
+
continue;
|
|
3400
|
+
}
|
|
3401
|
+
if (!inHunk) {
|
|
3402
|
+
annotatedLines.push(line);
|
|
3403
|
+
continue;
|
|
3404
|
+
}
|
|
3405
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
3406
|
+
annotatedLines.push(`${line} [Line ${currentNewLine}]`);
|
|
3407
|
+
currentNewLine++;
|
|
3408
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
3409
|
+
annotatedLines.push(`${line} [Line ${currentOldLine} removed]`);
|
|
3410
|
+
currentOldLine++;
|
|
3411
|
+
} else if (line.startsWith(" ")) {
|
|
3412
|
+
annotatedLines.push(line);
|
|
3413
|
+
currentOldLine++;
|
|
3414
|
+
currentNewLine++;
|
|
3415
|
+
} else {
|
|
3416
|
+
annotatedLines.push(line);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
return annotatedLines.join("\n");
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
// src/AiTool/tools/gitDiff.ts
|
|
3366
3423
|
var toolInfo14 = {
|
|
3367
3424
|
name: "git_diff",
|
|
3368
3425
|
description: "Get the git diff for the current repository. Can be used to get staged changes, unstaged changes, or changes between commits. By default, it returns unstaged changes.",
|
|
@@ -3376,7 +3433,16 @@ var toolInfo14 = {
|
|
|
3376
3433
|
return val;
|
|
3377
3434
|
}, z16.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
|
|
3378
3435
|
commitRange: z16.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
|
|
3379
|
-
file: z16.string().optional().describe("Get the diff for a specific file.")
|
|
3436
|
+
file: z16.string().optional().describe("Get the diff for a specific file."),
|
|
3437
|
+
contextLines: z16.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
|
|
3438
|
+
includeLineNumbers: z16.preprocess((val) => {
|
|
3439
|
+
if (typeof val === "string") {
|
|
3440
|
+
const lower = val.toLowerCase();
|
|
3441
|
+
if (lower === "false") return false;
|
|
3442
|
+
if (lower === "true") return true;
|
|
3443
|
+
}
|
|
3444
|
+
return val;
|
|
3445
|
+
}, z16.boolean().optional().default(false)).describe("Annotate the diff with line numbers for additions and deletions.")
|
|
3380
3446
|
}),
|
|
3381
3447
|
permissionLevel: 1 /* Read */
|
|
3382
3448
|
};
|
|
@@ -3387,8 +3453,8 @@ var handler14 = async (provider, args) => {
|
|
|
3387
3453
|
message: "Not possible to execute command. Abort."
|
|
3388
3454
|
};
|
|
3389
3455
|
}
|
|
3390
|
-
const { staged, file, commitRange } = toolInfo14.parameters.parse(args);
|
|
3391
|
-
const commandParts = ["git", "diff", "--no-color",
|
|
3456
|
+
const { staged, file, commitRange, contextLines, includeLineNumbers } = toolInfo14.parameters.parse(args);
|
|
3457
|
+
const commandParts = ["git", "diff", "--no-color", `-U${contextLines}`];
|
|
3392
3458
|
if (staged) {
|
|
3393
3459
|
commandParts.push("--staged");
|
|
3394
3460
|
}
|
|
@@ -3408,10 +3474,14 @@ var handler14 = async (provider, args) => {
|
|
|
3408
3474
|
message: "No diff found."
|
|
3409
3475
|
};
|
|
3410
3476
|
}
|
|
3477
|
+
let diffOutput = result.stdout;
|
|
3478
|
+
if (includeLineNumbers) {
|
|
3479
|
+
diffOutput = annotateDiffWithLineNumbers(diffOutput);
|
|
3480
|
+
}
|
|
3411
3481
|
return {
|
|
3412
3482
|
type: "Reply" /* Reply */,
|
|
3413
3483
|
message: `<diff file="${file ?? "all"}">
|
|
3414
|
-
${
|
|
3484
|
+
${diffOutput}
|
|
3415
3485
|
</diff>`
|
|
3416
3486
|
};
|
|
3417
3487
|
}
|
|
@@ -3447,8 +3517,9 @@ You are a senior software engineer reviewing code changes.
|
|
|
3447
3517
|
|
|
3448
3518
|
## Viewing Changes
|
|
3449
3519
|
- **Use git_diff** to inspect the actual code changes for each relevant file.
|
|
3450
|
-
- **Pull request**: use the provided commit range for the git_diff tool
|
|
3451
|
-
- **Local changes**: diff staged or unstaged files using the git_diff tool
|
|
3520
|
+
- **Pull request**: use the provided commit range for the git_diff tool with contextLines: 5 and includeLineNumbers: true
|
|
3521
|
+
- **Local changes**: diff staged or unstaged files using the git_diff tool with contextLines: 5 and includeLineNumbers: true
|
|
3522
|
+
- The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions
|
|
3452
3523
|
- If a pull request is present you may receive:
|
|
3453
3524
|
- <pr_title>
|
|
3454
3525
|
- <pr_description>
|
|
@@ -3456,9 +3527,16 @@ You are a senior software engineer reviewing code changes.
|
|
|
3456
3527
|
- A <review_instructions> tag tells you the focus of the review.
|
|
3457
3528
|
- File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
|
|
3458
3529
|
|
|
3530
|
+
## Line Number Reporting
|
|
3531
|
+
- **IMPORTANT**: Use the line numbers from the annotations in the diff output
|
|
3532
|
+
- For additions: Look for [Line N] annotations after the + lines
|
|
3533
|
+
- For deletions: Look for [Line N removed] annotations after the - lines
|
|
3534
|
+
- For modifications: Report the line number of the new/current code (from [Line N] annotations)
|
|
3535
|
+
- Report single lines as "N" and ranges as "N-M"
|
|
3536
|
+
|
|
3459
3537
|
## Review Guidelines
|
|
3460
3538
|
Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
|
|
3461
|
-
- **Specific issues**: Point to exact problems in the changed code with line references
|
|
3539
|
+
- **Specific issues**: Point to exact problems in the changed code with accurate line references from the annotations
|
|
3462
3540
|
- **Actionable fixes**: Provide concrete solutions, not vague suggestions
|
|
3463
3541
|
- **Clear reasoning**: Explain why each issue matters and how to fix it
|
|
3464
3542
|
- **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
|
|
@@ -3520,11 +3598,11 @@ ${fileList}
|
|
|
3520
3598
|
}
|
|
3521
3599
|
let instructions = "";
|
|
3522
3600
|
if (params.commitRange) {
|
|
3523
|
-
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.`;
|
|
3601
|
+
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.`;
|
|
3524
3602
|
} else if (params.staged) {
|
|
3525
|
-
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.";
|
|
3603
|
+
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.";
|
|
3526
3604
|
} else {
|
|
3527
|
-
instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
|
|
3605
|
+
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.";
|
|
3528
3606
|
}
|
|
3529
3607
|
parts.push(`<review_instructions>
|
|
3530
3608
|
${instructions}
|