@polka-codes/cli 0.9.65 → 0.9.67
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 +167 -32
- 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.67";
|
|
35583
35583
|
|
|
35584
35584
|
// src/commands/code.ts
|
|
35585
35585
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
@@ -61728,11 +61728,7 @@ var agentWorkflow = async (input, { step, tools, logger }) => {
|
|
|
61728
61728
|
if (msg.content) {
|
|
61729
61729
|
for (const part of msg.content) {
|
|
61730
61730
|
if (part.type === "tool-call") {
|
|
61731
|
-
|
|
61732
|
-
toolCalls.push(part);
|
|
61733
|
-
} else {
|
|
61734
|
-
logger.warn("Tool not found. Skipping.", part);
|
|
61735
|
-
}
|
|
61731
|
+
toolCalls.push(part);
|
|
61736
61732
|
}
|
|
61737
61733
|
}
|
|
61738
61734
|
}
|
|
@@ -61777,6 +61773,23 @@ var agentWorkflow = async (input, { step, tools, logger }) => {
|
|
|
61777
61773
|
}
|
|
61778
61774
|
const toolResults = [];
|
|
61779
61775
|
for (const toolCall of toolCalls) {
|
|
61776
|
+
if (!toolSet[toolCall.toolName]) {
|
|
61777
|
+
logger.warn("Tool not found.", toolCall);
|
|
61778
|
+
await event(`event-tool-error-${toolCall.toolName}-${toolCall.toolCallId}`, {
|
|
61779
|
+
kind: "ToolError" /* ToolError */,
|
|
61780
|
+
tool: toolCall.toolName,
|
|
61781
|
+
error: {
|
|
61782
|
+
type: "error-text",
|
|
61783
|
+
value: `Tool '${toolCall.toolName}' not found.`
|
|
61784
|
+
}
|
|
61785
|
+
});
|
|
61786
|
+
toolResults.push({
|
|
61787
|
+
toolCallId: toolCall.toolCallId,
|
|
61788
|
+
toolName: toolCall.toolName,
|
|
61789
|
+
output: `Error: Tool '${toolCall.toolName}' not found.`
|
|
61790
|
+
});
|
|
61791
|
+
continue;
|
|
61792
|
+
}
|
|
61780
61793
|
await event(`event-tool-use-${toolCall.toolName}-${toolCall.toolCallId}`, {
|
|
61781
61794
|
kind: "ToolUse" /* ToolUse */,
|
|
61782
61795
|
tool: toolCall.toolName,
|
|
@@ -67422,6 +67435,7 @@ Tool error:`, event.tool));
|
|
|
67422
67435
|
if (verbose > 0) {
|
|
67423
67436
|
logToolCallStats(stream, taskToolCallStats, "Task Tool Call Stats");
|
|
67424
67437
|
}
|
|
67438
|
+
taskToolCallStats.clear();
|
|
67425
67439
|
break;
|
|
67426
67440
|
}
|
|
67427
67441
|
};
|
|
@@ -100383,15 +100397,36 @@ function printChangedFiles(logger, changedFiles) {
|
|
|
100383
100397
|
}
|
|
100384
100398
|
logger.info("Changed Files:");
|
|
100385
100399
|
for (const file3 of changedFiles) {
|
|
100386
|
-
|
|
100400
|
+
let statString = "";
|
|
100401
|
+
if (file3.insertions !== undefined || file3.deletions !== undefined) {
|
|
100402
|
+
const ins = file3.insertions ?? 0;
|
|
100403
|
+
const del = file3.deletions ?? 0;
|
|
100404
|
+
statString = ` (+${ins}/-${del})`;
|
|
100405
|
+
}
|
|
100406
|
+
logger.info(`- ${file3.status}: ${file3.path}${statString}`);
|
|
100407
|
+
}
|
|
100408
|
+
}
|
|
100409
|
+
function parseGitDiffNumStat(output) {
|
|
100410
|
+
const stats = {};
|
|
100411
|
+
const lines = output.split(`
|
|
100412
|
+
`).filter((line) => line.trim());
|
|
100413
|
+
for (const line of lines) {
|
|
100414
|
+
const parts = line.split("\t");
|
|
100415
|
+
if (parts.length >= 3) {
|
|
100416
|
+
const insertions = parts[0] === "-" ? 0 : Number.parseInt(parts[0], 10);
|
|
100417
|
+
const deletions = parts[1] === "-" ? 0 : Number.parseInt(parts[1], 10);
|
|
100418
|
+
const path = unquotePath(parts.slice(2).join("\t"));
|
|
100419
|
+
stats[path] = { insertions, deletions };
|
|
100420
|
+
}
|
|
100387
100421
|
}
|
|
100422
|
+
return stats;
|
|
100388
100423
|
}
|
|
100389
100424
|
var unquotePath = (path) => {
|
|
100390
100425
|
if (path.startsWith('"') && path.endsWith('"')) {
|
|
100391
100426
|
try {
|
|
100392
100427
|
return JSON.parse(path);
|
|
100393
100428
|
} catch {
|
|
100394
|
-
return path
|
|
100429
|
+
return path;
|
|
100395
100430
|
}
|
|
100396
100431
|
}
|
|
100397
100432
|
return path;
|
|
@@ -100452,15 +100487,49 @@ function getLocalChanges() {
|
|
|
100452
100487
|
encoding: "utf-8"
|
|
100453
100488
|
});
|
|
100454
100489
|
const allFiles = parseGitStatus(statusOutput);
|
|
100490
|
+
let stagedStats = {};
|
|
100491
|
+
try {
|
|
100492
|
+
const stagedDiffOutput = execSync("git diff --staged --numstat --no-color", { encoding: "utf-8" });
|
|
100493
|
+
stagedStats = parseGitDiffNumStat(stagedDiffOutput);
|
|
100494
|
+
} catch {}
|
|
100495
|
+
let unstagedStats = {};
|
|
100496
|
+
try {
|
|
100497
|
+
const unstagedDiffOutput = execSync("git diff --numstat --no-color", { encoding: "utf-8" });
|
|
100498
|
+
unstagedStats = parseGitDiffNumStat(unstagedDiffOutput);
|
|
100499
|
+
} catch {}
|
|
100455
100500
|
const stagedFiles = [];
|
|
100456
100501
|
const unstagedFiles = [];
|
|
100457
100502
|
for (const file3 of allFiles) {
|
|
100503
|
+
let totalInsertions = 0;
|
|
100504
|
+
let totalDeletions = 0;
|
|
100458
100505
|
if (file3.status.includes("(staged)")) {
|
|
100459
|
-
|
|
100460
|
-
|
|
100461
|
-
|
|
100506
|
+
const stats = stagedStats[file3.path];
|
|
100507
|
+
const stagedFile = { ...file3 };
|
|
100508
|
+
if (stats) {
|
|
100509
|
+
stagedFile.insertions = stats.insertions;
|
|
100510
|
+
stagedFile.deletions = stats.deletions;
|
|
100511
|
+
totalInsertions += stats.insertions;
|
|
100512
|
+
totalDeletions += stats.deletions;
|
|
100513
|
+
}
|
|
100514
|
+
stagedFiles.push(stagedFile);
|
|
100515
|
+
}
|
|
100516
|
+
if (file3.status.includes("(unstaged)")) {
|
|
100517
|
+
const stats = unstagedStats[file3.path];
|
|
100518
|
+
const unstagedFile = { ...file3 };
|
|
100519
|
+
if (stats) {
|
|
100520
|
+
unstagedFile.insertions = stats.insertions;
|
|
100521
|
+
unstagedFile.deletions = stats.deletions;
|
|
100522
|
+
totalInsertions += stats.insertions;
|
|
100523
|
+
totalDeletions += stats.deletions;
|
|
100524
|
+
}
|
|
100525
|
+
unstagedFiles.push(unstagedFile);
|
|
100526
|
+
} else if (file3.status.includes("Untracked")) {
|
|
100462
100527
|
unstagedFiles.push(file3);
|
|
100463
100528
|
}
|
|
100529
|
+
if (totalInsertions > 0 || totalDeletions > 0) {
|
|
100530
|
+
file3.insertions = totalInsertions;
|
|
100531
|
+
file3.deletions = totalDeletions;
|
|
100532
|
+
}
|
|
100464
100533
|
}
|
|
100465
100534
|
return { stagedFiles, unstagedFiles, allFiles };
|
|
100466
100535
|
}
|
|
@@ -101949,7 +102018,15 @@ function getReviewInstructions(params) {
|
|
|
101949
102018
|
return "Review the unstaged changes. Use the gitDiff tool to inspect the actual code changes.";
|
|
101950
102019
|
}
|
|
101951
102020
|
function formatReviewToolInput(params) {
|
|
101952
|
-
const fileList = params.changedFiles && params.changedFiles.length > 0 ? params.changedFiles.map((file3) =>
|
|
102021
|
+
const fileList = params.changedFiles && params.changedFiles.length > 0 ? params.changedFiles.map((file3) => {
|
|
102022
|
+
let statString = "";
|
|
102023
|
+
if (file3.insertions !== undefined || file3.deletions !== undefined) {
|
|
102024
|
+
const ins = file3.insertions ?? 0;
|
|
102025
|
+
const del = file3.deletions ?? 0;
|
|
102026
|
+
statString = ` (+${ins}/-${del})`;
|
|
102027
|
+
}
|
|
102028
|
+
return `${file3.status}: ${file3.path}${statString}`;
|
|
102029
|
+
}).join(`
|
|
101953
102030
|
`) : undefined;
|
|
101954
102031
|
const parts = [
|
|
101955
102032
|
formatContext("pr_title", params.pullRequestTitle),
|
|
@@ -103718,7 +103795,21 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103718
103795
|
logger.warn("Warning: Could not retrieve file changes list");
|
|
103719
103796
|
return [];
|
|
103720
103797
|
}
|
|
103721
|
-
|
|
103798
|
+
const files = parseGitDiffNameStatus(diffResult.stdout);
|
|
103799
|
+
const statResult = await tools2.executeCommand({
|
|
103800
|
+
command: "git",
|
|
103801
|
+
args: ["--no-pager", "diff", "--numstat", "--no-color", `${prDetails.baseRefOid}...HEAD`]
|
|
103802
|
+
});
|
|
103803
|
+
if (statResult.exitCode === 0) {
|
|
103804
|
+
const stats = parseGitDiffNumStat(statResult.stdout);
|
|
103805
|
+
for (const file3 of files) {
|
|
103806
|
+
if (stats[file3.path]) {
|
|
103807
|
+
file3.insertions = stats[file3.path].insertions;
|
|
103808
|
+
file3.deletions = stats[file3.path].deletions;
|
|
103809
|
+
}
|
|
103810
|
+
}
|
|
103811
|
+
}
|
|
103812
|
+
return files;
|
|
103722
103813
|
});
|
|
103723
103814
|
printChangedFiles(logger, changedFiles);
|
|
103724
103815
|
changeInfo = {
|
|
@@ -103738,6 +103829,24 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103738
103829
|
if (hasLocalChanges) {
|
|
103739
103830
|
const hasStagedChanges = statusLines.some((line) => line[0] !== " " && line[0] !== "?");
|
|
103740
103831
|
const changedFiles = parseGitStatus(gitStatus);
|
|
103832
|
+
const unstagedStatResult = await tools2.executeCommand({
|
|
103833
|
+
command: "git",
|
|
103834
|
+
args: ["diff", "--numstat", "--no-color"]
|
|
103835
|
+
});
|
|
103836
|
+
const unstagedStats = unstagedStatResult.exitCode === 0 ? parseGitDiffNumStat(unstagedStatResult.stdout) : {};
|
|
103837
|
+
const stagedStatResult = await tools2.executeCommand({
|
|
103838
|
+
command: "git",
|
|
103839
|
+
args: ["diff", "--numstat", "--cached", "--no-color"]
|
|
103840
|
+
});
|
|
103841
|
+
const stagedStats = stagedStatResult.exitCode === 0 ? parseGitDiffNumStat(stagedStatResult.stdout) : {};
|
|
103842
|
+
for (const file3 of changedFiles) {
|
|
103843
|
+
const unstaged = unstagedStats[file3.path] || { insertions: 0, deletions: 0 };
|
|
103844
|
+
const staged = stagedStats[file3.path] || { insertions: 0, deletions: 0 };
|
|
103845
|
+
if (unstaged.insertions > 0 || unstaged.deletions > 0 || staged.insertions > 0 || staged.deletions > 0) {
|
|
103846
|
+
file3.insertions = unstaged.insertions + staged.insertions;
|
|
103847
|
+
file3.deletions = unstaged.deletions + staged.deletions;
|
|
103848
|
+
}
|
|
103849
|
+
}
|
|
103741
103850
|
printChangedFiles(logger, changedFiles);
|
|
103742
103851
|
changeInfo = {
|
|
103743
103852
|
staged: hasStagedChanges,
|
|
@@ -103774,7 +103883,21 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103774
103883
|
logger.warn("Warning: Could not retrieve file changes list");
|
|
103775
103884
|
return [];
|
|
103776
103885
|
}
|
|
103777
|
-
|
|
103886
|
+
const files = parseGitDiffNameStatus(diffResult.stdout);
|
|
103887
|
+
const statResult = await tools2.executeCommand({
|
|
103888
|
+
command: "git",
|
|
103889
|
+
args: ["--no-pager", "diff", "--numstat", "--no-color", `${defaultBranch}...${currentBranch}`]
|
|
103890
|
+
});
|
|
103891
|
+
if (statResult.exitCode === 0) {
|
|
103892
|
+
const stats = parseGitDiffNumStat(statResult.stdout);
|
|
103893
|
+
for (const file3 of files) {
|
|
103894
|
+
if (stats[file3.path]) {
|
|
103895
|
+
file3.insertions = stats[file3.path].insertions;
|
|
103896
|
+
file3.deletions = stats[file3.path].deletions;
|
|
103897
|
+
}
|
|
103898
|
+
}
|
|
103899
|
+
}
|
|
103900
|
+
return files;
|
|
103778
103901
|
});
|
|
103779
103902
|
printChangedFiles(logger, branchChangedFiles);
|
|
103780
103903
|
changeInfo = {
|
|
@@ -103788,12 +103911,19 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103788
103911
|
return { overview: "No changes to review.", specificReviews: [] };
|
|
103789
103912
|
}
|
|
103790
103913
|
const result = await step("review", async () => {
|
|
103914
|
+
const defaultContext = await getDefaultContext();
|
|
103915
|
+
const memoryContext = await tools2.getMemoryContext();
|
|
103916
|
+
const reviewInput = formatReviewToolInput(changeInfo);
|
|
103917
|
+
const fullContent = `${reviewInput}
|
|
103918
|
+
|
|
103919
|
+
${defaultContext}
|
|
103920
|
+
${memoryContext}`;
|
|
103791
103921
|
return await agentWorkflow({
|
|
103792
103922
|
systemPrompt: CODE_REVIEW_SYSTEM_PROMPT,
|
|
103793
103923
|
userMessage: [
|
|
103794
103924
|
{
|
|
103795
103925
|
role: "user",
|
|
103796
|
-
content:
|
|
103926
|
+
content: fullContent
|
|
103797
103927
|
}
|
|
103798
103928
|
],
|
|
103799
103929
|
tools: [readFile_default, readBinaryFile_default, searchFiles_default, listFiles_default, gitDiff_default],
|
|
@@ -103931,25 +104061,30 @@ async function runEpic(task2, _options, command) {
|
|
|
103931
104061
|
epicContext.task = taskInput;
|
|
103932
104062
|
}
|
|
103933
104063
|
let usageMeter;
|
|
103934
|
-
const saveUsageSnapshot = async () => {
|
|
103935
|
-
if (usageMeter) {
|
|
103936
|
-
const currentUsage = usageMeter.usage;
|
|
103937
|
-
if (!epicContext.usages) {
|
|
103938
|
-
epicContext.usages = [];
|
|
103939
|
-
}
|
|
103940
|
-
epicContext.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
103941
|
-
}
|
|
103942
|
-
};
|
|
103943
104064
|
const workflowInput = {
|
|
103944
104065
|
...epicContext,
|
|
103945
|
-
|
|
103946
|
-
|
|
103947
|
-
|
|
103948
|
-
|
|
103949
|
-
|
|
103950
|
-
|
|
103951
|
-
|
|
103952
|
-
|
|
104066
|
+
interactive: !yes,
|
|
104067
|
+
saveEpicContext: async (context) => {
|
|
104068
|
+
if (context.task)
|
|
104069
|
+
workflowInput.task = context.task;
|
|
104070
|
+
if (context.plan)
|
|
104071
|
+
workflowInput.plan = context.plan;
|
|
104072
|
+
if (context.branchName)
|
|
104073
|
+
workflowInput.branchName = context.branchName;
|
|
104074
|
+
if (context.baseBranch)
|
|
104075
|
+
workflowInput.baseBranch = context.baseBranch;
|
|
104076
|
+
await saveEpicContext(workflowInput);
|
|
104077
|
+
},
|
|
104078
|
+
saveUsageSnapshot: async () => {
|
|
104079
|
+
if (usageMeter) {
|
|
104080
|
+
const currentUsage = usageMeter.usage;
|
|
104081
|
+
if (!workflowInput.usages) {
|
|
104082
|
+
workflowInput.usages = [];
|
|
104083
|
+
}
|
|
104084
|
+
workflowInput.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
104085
|
+
await saveEpicContext(workflowInput);
|
|
104086
|
+
}
|
|
104087
|
+
}
|
|
103953
104088
|
};
|
|
103954
104089
|
await runWorkflow(epicWorkflow, workflowInput, {
|
|
103955
104090
|
commandName: "epic",
|