@polka-codes/cli 0.9.56 → 0.9.58
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/index.js +127 -113
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35579,7 +35579,7 @@ var {
|
|
|
35579
35579
|
Help
|
|
35580
35580
|
} = import__.default;
|
|
35581
35581
|
// package.json
|
|
35582
|
-
var version = "0.9.
|
|
35582
|
+
var version = "0.9.58";
|
|
35583
35583
|
|
|
35584
35584
|
// src/commands/code.ts
|
|
35585
35585
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
@@ -77966,7 +77966,7 @@ var toolInfo18 = {
|
|
|
77966
77966
|
return true;
|
|
77967
77967
|
}
|
|
77968
77968
|
return val;
|
|
77969
|
-
}, exports_external.boolean().optional().default(
|
|
77969
|
+
}, exports_external.boolean().optional().default(true)).describe("Annotate the diff with line numbers for additions and deletions.")
|
|
77970
77970
|
})
|
|
77971
77971
|
};
|
|
77972
77972
|
var handler18 = async (provider3, args) => {
|
|
@@ -78530,7 +78530,7 @@ async function generateText(input2, context) {
|
|
|
78530
78530
|
const messages = applyCacheControl(input2.messages.map(fromJsonModelMessage), model.provider, model.modelId);
|
|
78531
78531
|
for (let i = 0;i < retryCount; i++) {
|
|
78532
78532
|
const abortController = new AbortController;
|
|
78533
|
-
|
|
78533
|
+
let timeout = setTimeout(() => abortController.abort(), requestTimeoutSeconds * 1000);
|
|
78534
78534
|
const usageMeterOnFinishHandler = context.parameters.usageMeter.onFinishHandler(model);
|
|
78535
78535
|
try {
|
|
78536
78536
|
const stream = streamText({
|
|
@@ -78539,6 +78539,8 @@ async function generateText(input2, context) {
|
|
|
78539
78539
|
messages,
|
|
78540
78540
|
tools: input2.tools,
|
|
78541
78541
|
async onChunk({ chunk }) {
|
|
78542
|
+
clearTimeout(timeout);
|
|
78543
|
+
timeout = setTimeout(() => abortController.abort(), requestTimeoutSeconds * 1000);
|
|
78542
78544
|
switch (chunk.type) {
|
|
78543
78545
|
case "text-delta":
|
|
78544
78546
|
agentCallback?.({
|
|
@@ -79259,13 +79261,18 @@ ${createJsonResponseInstruction({
|
|
|
79259
79261
|
bailReason: "Unable to identify the root cause of the error. The error message is ambiguous and requires human investigation."
|
|
79260
79262
|
})}
|
|
79261
79263
|
`;
|
|
79262
|
-
function getFixUserPrompt(command, exitCode, stdout, stderr, task) {
|
|
79264
|
+
function getFixUserPrompt(command, exitCode, stdout, stderr, task, context) {
|
|
79263
79265
|
const taskContext = task ? `
|
|
79264
79266
|
## Original Task
|
|
79265
79267
|
|
|
79266
79268
|
${task}
|
|
79267
79269
|
` : "";
|
|
79268
|
-
|
|
79270
|
+
const contextSection = context ? `
|
|
79271
|
+
## User Context
|
|
79272
|
+
|
|
79273
|
+
${context}
|
|
79274
|
+
` : "";
|
|
79275
|
+
return `## Context${taskContext}${contextSection}
|
|
79269
79276
|
|
|
79270
79277
|
The following command failed with exit code ${exitCode}:
|
|
79271
79278
|
\`${command}\`
|
|
@@ -79563,119 +79570,123 @@ ${createJsonResponseInstruction({
|
|
|
79563
79570
|
`;
|
|
79564
79571
|
// src/workflows/prompts/review.ts
|
|
79565
79572
|
var CODE_REVIEW_SYSTEM_PROMPT = `Role: Senior software engineer.
|
|
79566
|
-
Goal: Review code changes and provide
|
|
79573
|
+
Goal: Review code changes and provide comprehensive, actionable feedback on issues found.
|
|
79567
79574
|
|
|
79568
79575
|
${TOOL_USAGE_INSTRUCTION}
|
|
79569
79576
|
|
|
79570
|
-
|
|
79571
|
-
|
|
79572
|
-
|
|
79573
|
-
|
|
79574
|
-
|
|
79575
|
-
-
|
|
79576
|
-
|
|
79577
|
-
|
|
79578
|
-
|
|
79579
|
-
##
|
|
79580
|
-
|
|
79581
|
-
|
|
79582
|
-
|
|
79583
|
-
-
|
|
79584
|
-
-
|
|
79585
|
-
-
|
|
79586
|
-
|
|
79587
|
-
|
|
79588
|
-
-
|
|
79589
|
-
-
|
|
79590
|
-
-
|
|
79591
|
-
|
|
79592
|
-
|
|
79593
|
-
|
|
79594
|
-
|
|
79595
|
-
-
|
|
79596
|
-
|
|
79597
|
-
|
|
79598
|
-
- The diff will include line number annotations: [Line N] for additions and [Line N removed] for deletions.
|
|
79599
|
-
- You may receive:
|
|
79600
|
-
- <pr_title>
|
|
79601
|
-
- <pr_description>
|
|
79602
|
-
- <commit_messages>
|
|
79603
|
-
- A <review_instructions> tag tells you the focus of the review.
|
|
79604
|
-
- Use <file_status> to understand which files were modified, added, deleted, or renamed and to apply the inclusion/exclusion rules above.
|
|
79605
|
-
|
|
79606
|
-
|
|
79607
|
-
## Line Number Reporting
|
|
79608
|
-
- Use the line numbers from the annotations in the diff output.
|
|
79609
|
-
- For additions: use the number from the [Line N] annotation after the + line.
|
|
79610
|
-
- For deletions: use the number from the [Line N removed] annotation after the - line.
|
|
79611
|
-
- For modifications: report the line number of the new/current code (from [Line N]).
|
|
79612
|
-
- Report single lines as "N" and ranges as "N-M".
|
|
79613
|
-
|
|
79614
|
-
|
|
79615
|
-
## Review Guidelines
|
|
79616
|
-
Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
|
|
79617
|
-
- **Specific issues:** Point to exact problems in the changed code with accurate line references from the annotations.
|
|
79618
|
-
- **Actionable fixes:** Provide concrete solutions, not vague suggestions.
|
|
79619
|
-
- **Clear reasoning:** Explain why each issue matters and how to fix it.
|
|
79620
|
-
- **Avoid generic advice** unless directly tied to a specific problem visible in the diff.
|
|
79621
|
-
|
|
79622
|
-
## What NOT to review
|
|
79623
|
-
- Files excluded by the "File Selection for gitDiff" rules (do not diff or comment on them).
|
|
79624
|
-
- Existing unchanged code.
|
|
79625
|
-
- Overall project structure/architecture unless directly impacted by the changes.
|
|
79626
|
-
- Missing features or functionality not part of this diff.
|
|
79577
|
+
## Review Process
|
|
79578
|
+
|
|
79579
|
+
1. **Identify Reviewable Files**: Use the \`<file_status>\` list to determine which files have been modified.
|
|
79580
|
+
2. **Select Files for Diff**: From the modified files, select only the reviewable source and configuration files.
|
|
79581
|
+
- **Include**: Source code, config files, and template files.
|
|
79582
|
+
- **Exclude**: Lockfiles, build artifacts, test snapshots, binary/media files, data and fixtures and other generated files.
|
|
79583
|
+
3. **Inspect Changes**: Use the \`gitDiff\` tool on one file at a time to see the exact changes. When reviewing pull requests, use the \`commitRange\` parameter provided in the review instructions.
|
|
79584
|
+
4. **Analyze and Review**: Analyze only the modified lines (additions/deletions) for issues. Provide specific, actionable feedback with accurate line numbers.
|
|
79585
|
+
|
|
79586
|
+
## Critical Rules
|
|
79587
|
+
|
|
79588
|
+
- **Focus on Changes**: ONLY review the actual changes shown in the diff. Do not comment on existing, unmodified code.
|
|
79589
|
+
- **Focus Scope**: Do not comment on overall project structure or architecture unless directly impacted by the changes in the diff.
|
|
79590
|
+
- **No Feature Requests**: Do not comment on missing features or functionality that are not part of this diff.
|
|
79591
|
+
- **One File at a Time**: Review files individually using \`gitDiff\` with the specific file path.
|
|
79592
|
+
- **No Empty Diffs**: MUST NOT call \`gitDiff\` with an empty or omitted file parameter.
|
|
79593
|
+
- **Accurate Line Numbers**: Use the line numbers from the diff annotations (\`[Line N]\` for additions, \`[Line N removed]\` for deletions).
|
|
79594
|
+
- **No Praise**: Provide only reviews for actual issues found. Do not include praise or positive feedback.
|
|
79595
|
+
- **Clear Reasoning**: For each issue, provide clear reasoning explaining why it's a problem and what the impact could be.
|
|
79596
|
+
- **Specific Advice**: Avoid generic advice. Provide concrete, actionable suggestions specific to the code being reviewed.
|
|
79597
|
+
- **Assumptions**: Assume all changes have passed linter, type-checking, and unit tests. Do not check for compile errors.
|
|
79598
|
+
|
|
79599
|
+
You may receive the following context:
|
|
79600
|
+
- \`<pr_title>\` and \`<pr_description>\`: PR context
|
|
79601
|
+
- \`<commit_messages>\`: Commits in the change
|
|
79602
|
+
- \`<user_context>\`: Specific review focus from the user
|
|
79603
|
+
- \`<file_status>\`: List of modified files with their status
|
|
79604
|
+
- \`<review_instructions>\`: Specific instructions for this review
|
|
79627
79605
|
|
|
79628
79606
|
## Output Format
|
|
79629
|
-
Do not include praise or positive feedback.
|
|
79630
|
-
Only include reviews for actual issues found in the changed code.
|
|
79631
79607
|
|
|
79632
79608
|
${createJsonResponseInstruction({
|
|
79633
|
-
overview: "Summary of
|
|
79609
|
+
overview: "Summary of issues found, 'No issues found', or 'No reviewable changes' if all files were excluded.",
|
|
79634
79610
|
specificReviews: [
|
|
79635
79611
|
{
|
|
79636
|
-
file: "path/
|
|
79637
|
-
lines: "
|
|
79638
|
-
review: "Specific issue
|
|
79612
|
+
file: "path/to/file.ts",
|
|
79613
|
+
lines: "42 or 15-20",
|
|
79614
|
+
review: "Specific issue description and actionable fix."
|
|
79639
79615
|
}
|
|
79640
79616
|
]
|
|
79641
79617
|
})}
|
|
79618
|
+
|
|
79619
|
+
### Examples
|
|
79620
|
+
|
|
79621
|
+
**Example 1: Issues found**
|
|
79622
|
+
\`\`\`json
|
|
79623
|
+
{
|
|
79624
|
+
"overview": "Found 2 security and 1 logic issue in the authentication changes.",
|
|
79625
|
+
"specificReviews": [
|
|
79626
|
+
{
|
|
79627
|
+
"file": "src/auth/login.ts",
|
|
79628
|
+
"lines": "23",
|
|
79629
|
+
"review": "Password is logged in plaintext. Remove the console.log statement or hash the password before logging."
|
|
79630
|
+
},
|
|
79631
|
+
{
|
|
79632
|
+
"file": "src/auth/login.ts",
|
|
79633
|
+
"lines": "45-48",
|
|
79634
|
+
"review": "Missing input validation for email field. Add email format validation before processing the login request."
|
|
79635
|
+
},
|
|
79636
|
+
{
|
|
79637
|
+
"file": "src/utils/token.ts",
|
|
79638
|
+
"lines": "12",
|
|
79639
|
+
"review": "Token expiration is set to 365 days which is too long for security. Reduce to 24 hours or use refresh tokens."
|
|
79640
|
+
}
|
|
79641
|
+
]
|
|
79642
|
+
}
|
|
79643
|
+
\`\`\`
|
|
79644
|
+
|
|
79645
|
+
**Example 2: No issues**
|
|
79646
|
+
\`\`\`json
|
|
79647
|
+
{
|
|
79648
|
+
"overview": "No issues found.",
|
|
79649
|
+
"specificReviews": []
|
|
79650
|
+
}
|
|
79651
|
+
\`\`\`
|
|
79652
|
+
|
|
79653
|
+
**Example 3: No reviewable changes**
|
|
79654
|
+
\`\`\`json
|
|
79655
|
+
{
|
|
79656
|
+
"overview": "No reviewable changes. All modified files are lockfiles or generated artifacts.",
|
|
79657
|
+
"specificReviews": []
|
|
79658
|
+
}
|
|
79659
|
+
\`\`\`
|
|
79642
79660
|
`;
|
|
79643
|
-
function
|
|
79644
|
-
|
|
79645
|
-
|
|
79646
|
-
parts.push(`<pr_title>
|
|
79647
|
-
${params.pullRequestTitle}
|
|
79648
|
-
</pr_title>`);
|
|
79649
|
-
}
|
|
79650
|
-
if (params.pullRequestDescription) {
|
|
79651
|
-
parts.push(`<pr_description>
|
|
79652
|
-
${params.pullRequestDescription}
|
|
79653
|
-
</pr_description>`);
|
|
79654
|
-
}
|
|
79655
|
-
if (params.commitMessages) {
|
|
79656
|
-
parts.push(`<commit_messages>
|
|
79657
|
-
${params.commitMessages}
|
|
79658
|
-
</commit_messages>`);
|
|
79659
|
-
}
|
|
79660
|
-
if (params.changedFiles && params.changedFiles.length > 0) {
|
|
79661
|
-
const fileList = params.changedFiles.map((file2) => `${file2.status}: ${file2.path}`).join(`
|
|
79662
|
-
`);
|
|
79663
|
-
parts.push(`<file_status>
|
|
79664
|
-
${fileList}
|
|
79665
|
-
</file_status>`);
|
|
79661
|
+
function formatContext(tag, value) {
|
|
79662
|
+
if (!value) {
|
|
79663
|
+
return;
|
|
79666
79664
|
}
|
|
79667
|
-
|
|
79665
|
+
return `<${tag}>
|
|
79666
|
+
${value}
|
|
79667
|
+
</${tag}>`;
|
|
79668
|
+
}
|
|
79669
|
+
function getReviewInstructions(params) {
|
|
79668
79670
|
if (params.commitRange) {
|
|
79669
|
-
|
|
79670
|
-
} else if (params.staged) {
|
|
79671
|
-
instructions = "Review the staged changes. Use the gitDiff 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.";
|
|
79672
|
-
} else {
|
|
79673
|
-
instructions = "Review the unstaged changes. Use the gitDiff 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.";
|
|
79671
|
+
return `Review the pull request. Use the gitDiff tool with commit range '${params.commitRange}' to inspect the actual code changes.`;
|
|
79674
79672
|
}
|
|
79675
|
-
|
|
79676
|
-
|
|
79677
|
-
|
|
79678
|
-
return
|
|
79673
|
+
if (params.staged) {
|
|
79674
|
+
return "Review the staged changes. Use the gitDiff tool with staged: true to inspect the actual code changes.";
|
|
79675
|
+
}
|
|
79676
|
+
return "Review the unstaged changes. Use the gitDiff tool to inspect the actual code changes.";
|
|
79677
|
+
}
|
|
79678
|
+
function formatReviewToolInput(params) {
|
|
79679
|
+
const fileList = params.changedFiles && params.changedFiles.length > 0 ? params.changedFiles.map((file2) => `${file2.status}: ${file2.path}`).join(`
|
|
79680
|
+
`) : undefined;
|
|
79681
|
+
const parts = [
|
|
79682
|
+
formatContext("pr_title", params.pullRequestTitle),
|
|
79683
|
+
formatContext("pr_description", params.pullRequestDescription),
|
|
79684
|
+
formatContext("commit_messages", params.commitMessages),
|
|
79685
|
+
formatContext("user_context", params.context),
|
|
79686
|
+
formatContext("file_status", fileList),
|
|
79687
|
+
formatContext("review_instructions", getReviewInstructions(params))
|
|
79688
|
+
];
|
|
79689
|
+
return parts.filter(Boolean).join(`
|
|
79679
79690
|
`);
|
|
79680
79691
|
}
|
|
79681
79692
|
// src/workflows/fix.workflow.ts
|
|
@@ -79687,7 +79698,7 @@ var FixIterationSummarySchema = exports_external.object({
|
|
|
79687
79698
|
});
|
|
79688
79699
|
var fixWorkflow = async (input2, context) => {
|
|
79689
79700
|
const { tools: tools2, logger, step } = context;
|
|
79690
|
-
const { command: inputCommand, task, interactive = true } = input2;
|
|
79701
|
+
const { command: inputCommand, task, context: userContext, interactive = true } = input2;
|
|
79691
79702
|
let command = inputCommand;
|
|
79692
79703
|
const summaries = [];
|
|
79693
79704
|
let formatCommand;
|
|
@@ -79755,7 +79766,7 @@ var fixWorkflow = async (input2, context) => {
|
|
|
79755
79766
|
const result = await step(`fix-${i}`, async () => {
|
|
79756
79767
|
const defaultContext = await getDefaultContext();
|
|
79757
79768
|
const memoryContext = await tools2.getMemoryContext();
|
|
79758
|
-
const userPrompt = getFixUserPrompt(command, exitCode, stdout, stderr, task);
|
|
79769
|
+
const userPrompt = getFixUserPrompt(command, exitCode, stdout, stderr, task, userContext);
|
|
79759
79770
|
return await agentWorkflow({
|
|
79760
79771
|
systemPrompt: FIX_SYSTEM_PROMPT,
|
|
79761
79772
|
userMessage: [
|
|
@@ -81336,7 +81347,7 @@ var prWorkflow = async (input2, context) => {
|
|
|
81336
81347
|
// src/workflows/review.workflow.ts
|
|
81337
81348
|
var reviewWorkflow = async (input2, context) => {
|
|
81338
81349
|
const { step, tools: tools2, logger } = context;
|
|
81339
|
-
const { pr: pr2 } = input2;
|
|
81350
|
+
const { pr: pr2, context: userContext } = input2;
|
|
81340
81351
|
let changeInfo;
|
|
81341
81352
|
if (pr2) {
|
|
81342
81353
|
const prNumberMatch = pr2.match(/\d+$/);
|
|
@@ -81385,7 +81396,8 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
81385
81396
|
pullRequestTitle: prDetails.title,
|
|
81386
81397
|
pullRequestDescription: prDetails.body,
|
|
81387
81398
|
commitMessages,
|
|
81388
|
-
changedFiles
|
|
81399
|
+
changedFiles,
|
|
81400
|
+
context: userContext
|
|
81389
81401
|
};
|
|
81390
81402
|
} else {
|
|
81391
81403
|
const statusResult = await tools2.executeCommand({ command: "git", args: ["status", "--porcelain=v1"] });
|
|
@@ -81399,7 +81411,8 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
81399
81411
|
printChangedFiles(logger, changedFiles);
|
|
81400
81412
|
changeInfo = {
|
|
81401
81413
|
staged: hasStagedChanges,
|
|
81402
|
-
changedFiles
|
|
81414
|
+
changedFiles,
|
|
81415
|
+
context: userContext
|
|
81403
81416
|
};
|
|
81404
81417
|
} else {
|
|
81405
81418
|
await step("No local changes detected. Falling back to branch diff...", async () => {});
|
|
@@ -81436,7 +81449,8 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
81436
81449
|
printChangedFiles(logger, branchChangedFiles);
|
|
81437
81450
|
changeInfo = {
|
|
81438
81451
|
commitRange: `${defaultBranch}...${currentBranch}`,
|
|
81439
|
-
changedFiles: branchChangedFiles
|
|
81452
|
+
changedFiles: branchChangedFiles,
|
|
81453
|
+
context: userContext
|
|
81440
81454
|
};
|
|
81441
81455
|
}
|
|
81442
81456
|
}
|
|
@@ -81620,8 +81634,8 @@ async function runEpic(task2, _options, command) {
|
|
|
81620
81634
|
var epicCommand = new Command("epic").description("Orchestrates a large feature or epic, breaking it down into smaller tasks.").argument("[task]", "The epic to plan and implement.").action(runEpic);
|
|
81621
81635
|
|
|
81622
81636
|
// src/commands/fix.ts
|
|
81623
|
-
var fixCommand = new Command("fix").description("Fix issues by running a command and letting an agent fix it.").argument("[command]", "The command to run").option("-t, --task <task>", "The task to perform, providing specific instructions to the agent.").action(async (command, options, cmd) => {
|
|
81624
|
-
const workflowInput = { command, task: options.task };
|
|
81637
|
+
var fixCommand = new Command("fix").description("Fix issues by running a command and letting an agent fix it.").argument("[command]", "The command to run").argument("[context]", "Additional context for the fix").option("-t, --task <task>", "The task to perform, providing specific instructions to the agent.").action(async (command, context, options, cmd) => {
|
|
81638
|
+
const workflowInput = { command, task: options.task, context };
|
|
81625
81639
|
const globalOpts = (cmd.parent ?? cmd).opts();
|
|
81626
81640
|
const { verbose } = globalOpts;
|
|
81627
81641
|
const logger = createLogger({
|
|
@@ -81735,7 +81749,7 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
81735
81749
|
});
|
|
81736
81750
|
|
|
81737
81751
|
// src/commands/review.ts
|
|
81738
|
-
var reviewCommand = new Command("review").description("Review a GitHub pull request or local changes").option("--pr <pr>", "The pull request number or URL to review").option("--json", "Output the review in JSON format", false).option("-y, --yes", "Automatically apply review feedback", false).option("--loop [count]", "Re-review after changes are applied.", (value) => {
|
|
81752
|
+
var reviewCommand = new Command("review").description("Review a GitHub pull request or local changes").argument("[context]", "Additional context for the review").option("--pr <pr>", "The pull request number or URL to review").option("--json", "Output the review in JSON format", false).option("-y, --yes", "Automatically apply review feedback", false).option("--loop [count]", "Re-review after changes are applied.", (value) => {
|
|
81739
81753
|
if (value === undefined || value === null) {
|
|
81740
81754
|
return 1;
|
|
81741
81755
|
}
|
|
@@ -81744,7 +81758,7 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
|
|
|
81744
81758
|
throw new InvalidOptionArgumentError("Must be a positive number.");
|
|
81745
81759
|
}
|
|
81746
81760
|
return parsedValue;
|
|
81747
|
-
}, 1).action(async (options, command) => {
|
|
81761
|
+
}, 1).action(async (context, options, command) => {
|
|
81748
81762
|
const { json: json2, pr: pr3, loop: maxIterations, yes: yesOption } = options;
|
|
81749
81763
|
const yes = maxIterations > 1 || yesOption;
|
|
81750
81764
|
let changesAppliedInThisIteration = false;
|
|
@@ -81755,7 +81769,7 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
|
|
|
81755
81769
|
});
|
|
81756
81770
|
for (let i = 0;i < maxIterations; i++) {
|
|
81757
81771
|
changesAppliedInThisIteration = false;
|
|
81758
|
-
const input2 = { pr: pr3 };
|
|
81772
|
+
const input2 = { pr: pr3, context };
|
|
81759
81773
|
if (i > 0) {
|
|
81760
81774
|
logger.debug(`Re-running review (iteration ${i + 1} of ${maxIterations})...`);
|
|
81761
81775
|
}
|