@polka-codes/cli 0.9.64 → 0.9.66
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 +163 -34
- 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.66";
|
|
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,
|
|
@@ -100383,15 +100396,36 @@ function printChangedFiles(logger, changedFiles) {
|
|
|
100383
100396
|
}
|
|
100384
100397
|
logger.info("Changed Files:");
|
|
100385
100398
|
for (const file3 of changedFiles) {
|
|
100386
|
-
|
|
100399
|
+
let statString = "";
|
|
100400
|
+
if (file3.insertions !== undefined || file3.deletions !== undefined) {
|
|
100401
|
+
const ins = file3.insertions ?? 0;
|
|
100402
|
+
const del = file3.deletions ?? 0;
|
|
100403
|
+
statString = ` (+${ins}/-${del})`;
|
|
100404
|
+
}
|
|
100405
|
+
logger.info(`- ${file3.status}: ${file3.path}${statString}`);
|
|
100406
|
+
}
|
|
100407
|
+
}
|
|
100408
|
+
function parseGitDiffNumStat(output) {
|
|
100409
|
+
const stats = {};
|
|
100410
|
+
const lines = output.split(`
|
|
100411
|
+
`).filter((line) => line.trim());
|
|
100412
|
+
for (const line of lines) {
|
|
100413
|
+
const parts = line.split("\t");
|
|
100414
|
+
if (parts.length >= 3) {
|
|
100415
|
+
const insertions = parts[0] === "-" ? 0 : Number.parseInt(parts[0], 10);
|
|
100416
|
+
const deletions = parts[1] === "-" ? 0 : Number.parseInt(parts[1], 10);
|
|
100417
|
+
const path = unquotePath(parts.slice(2).join("\t"));
|
|
100418
|
+
stats[path] = { insertions, deletions };
|
|
100419
|
+
}
|
|
100387
100420
|
}
|
|
100421
|
+
return stats;
|
|
100388
100422
|
}
|
|
100389
100423
|
var unquotePath = (path) => {
|
|
100390
100424
|
if (path.startsWith('"') && path.endsWith('"')) {
|
|
100391
100425
|
try {
|
|
100392
100426
|
return JSON.parse(path);
|
|
100393
100427
|
} catch {
|
|
100394
|
-
return path
|
|
100428
|
+
return path;
|
|
100395
100429
|
}
|
|
100396
100430
|
}
|
|
100397
100431
|
return path;
|
|
@@ -100452,15 +100486,49 @@ function getLocalChanges() {
|
|
|
100452
100486
|
encoding: "utf-8"
|
|
100453
100487
|
});
|
|
100454
100488
|
const allFiles = parseGitStatus(statusOutput);
|
|
100489
|
+
let stagedStats = {};
|
|
100490
|
+
try {
|
|
100491
|
+
const stagedDiffOutput = execSync("git diff --staged --numstat --no-color", { encoding: "utf-8" });
|
|
100492
|
+
stagedStats = parseGitDiffNumStat(stagedDiffOutput);
|
|
100493
|
+
} catch {}
|
|
100494
|
+
let unstagedStats = {};
|
|
100495
|
+
try {
|
|
100496
|
+
const unstagedDiffOutput = execSync("git diff --numstat --no-color", { encoding: "utf-8" });
|
|
100497
|
+
unstagedStats = parseGitDiffNumStat(unstagedDiffOutput);
|
|
100498
|
+
} catch {}
|
|
100455
100499
|
const stagedFiles = [];
|
|
100456
100500
|
const unstagedFiles = [];
|
|
100457
100501
|
for (const file3 of allFiles) {
|
|
100502
|
+
let totalInsertions = 0;
|
|
100503
|
+
let totalDeletions = 0;
|
|
100458
100504
|
if (file3.status.includes("(staged)")) {
|
|
100459
|
-
|
|
100460
|
-
|
|
100461
|
-
|
|
100505
|
+
const stats = stagedStats[file3.path];
|
|
100506
|
+
const stagedFile = { ...file3 };
|
|
100507
|
+
if (stats) {
|
|
100508
|
+
stagedFile.insertions = stats.insertions;
|
|
100509
|
+
stagedFile.deletions = stats.deletions;
|
|
100510
|
+
totalInsertions += stats.insertions;
|
|
100511
|
+
totalDeletions += stats.deletions;
|
|
100512
|
+
}
|
|
100513
|
+
stagedFiles.push(stagedFile);
|
|
100514
|
+
}
|
|
100515
|
+
if (file3.status.includes("(unstaged)")) {
|
|
100516
|
+
const stats = unstagedStats[file3.path];
|
|
100517
|
+
const unstagedFile = { ...file3 };
|
|
100518
|
+
if (stats) {
|
|
100519
|
+
unstagedFile.insertions = stats.insertions;
|
|
100520
|
+
unstagedFile.deletions = stats.deletions;
|
|
100521
|
+
totalInsertions += stats.insertions;
|
|
100522
|
+
totalDeletions += stats.deletions;
|
|
100523
|
+
}
|
|
100524
|
+
unstagedFiles.push(unstagedFile);
|
|
100525
|
+
} else if (file3.status.includes("Untracked")) {
|
|
100462
100526
|
unstagedFiles.push(file3);
|
|
100463
100527
|
}
|
|
100528
|
+
if (totalInsertions > 0 || totalDeletions > 0) {
|
|
100529
|
+
file3.insertions = totalInsertions;
|
|
100530
|
+
file3.deletions = totalDeletions;
|
|
100531
|
+
}
|
|
100464
100532
|
}
|
|
100465
100533
|
return { stagedFiles, unstagedFiles, allFiles };
|
|
100466
100534
|
}
|
|
@@ -100548,10 +100616,12 @@ async function getDefaultContext() {
|
|
|
100548
100616
|
const [files, truncated] = await listFiles(cwd, true, 2000, cwd, config5?.excludeFiles ?? []);
|
|
100549
100617
|
const fileList = files.join(`
|
|
100550
100618
|
`);
|
|
100551
|
-
const contextParts = [
|
|
100552
|
-
|
|
100619
|
+
const contextParts = [
|
|
100620
|
+
`<file_list truncated="${truncated}">
|
|
100553
100621
|
${fileList}
|
|
100554
|
-
</file_list
|
|
100622
|
+
</file_list>`,
|
|
100623
|
+
`<now_date>${new Date().toISOString()}</now_date>`
|
|
100624
|
+
];
|
|
100555
100625
|
if (config5?.rules) {
|
|
100556
100626
|
contextParts.push(`<rules>
|
|
100557
100627
|
${config5.rules}
|
|
@@ -101947,7 +102017,15 @@ function getReviewInstructions(params) {
|
|
|
101947
102017
|
return "Review the unstaged changes. Use the gitDiff tool to inspect the actual code changes.";
|
|
101948
102018
|
}
|
|
101949
102019
|
function formatReviewToolInput(params) {
|
|
101950
|
-
const fileList = params.changedFiles && params.changedFiles.length > 0 ? params.changedFiles.map((file3) =>
|
|
102020
|
+
const fileList = params.changedFiles && params.changedFiles.length > 0 ? params.changedFiles.map((file3) => {
|
|
102021
|
+
let statString = "";
|
|
102022
|
+
if (file3.insertions !== undefined || file3.deletions !== undefined) {
|
|
102023
|
+
const ins = file3.insertions ?? 0;
|
|
102024
|
+
const del = file3.deletions ?? 0;
|
|
102025
|
+
statString = ` (+${ins}/-${del})`;
|
|
102026
|
+
}
|
|
102027
|
+
return `${file3.status}: ${file3.path}${statString}`;
|
|
102028
|
+
}).join(`
|
|
101951
102029
|
`) : undefined;
|
|
101952
102030
|
const parts = [
|
|
101953
102031
|
formatContext("pr_title", params.pullRequestTitle),
|
|
@@ -103716,7 +103794,21 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103716
103794
|
logger.warn("Warning: Could not retrieve file changes list");
|
|
103717
103795
|
return [];
|
|
103718
103796
|
}
|
|
103719
|
-
|
|
103797
|
+
const files = parseGitDiffNameStatus(diffResult.stdout);
|
|
103798
|
+
const statResult = await tools2.executeCommand({
|
|
103799
|
+
command: "git",
|
|
103800
|
+
args: ["--no-pager", "diff", "--numstat", "--no-color", `${prDetails.baseRefOid}...HEAD`]
|
|
103801
|
+
});
|
|
103802
|
+
if (statResult.exitCode === 0) {
|
|
103803
|
+
const stats = parseGitDiffNumStat(statResult.stdout);
|
|
103804
|
+
for (const file3 of files) {
|
|
103805
|
+
if (stats[file3.path]) {
|
|
103806
|
+
file3.insertions = stats[file3.path].insertions;
|
|
103807
|
+
file3.deletions = stats[file3.path].deletions;
|
|
103808
|
+
}
|
|
103809
|
+
}
|
|
103810
|
+
}
|
|
103811
|
+
return files;
|
|
103720
103812
|
});
|
|
103721
103813
|
printChangedFiles(logger, changedFiles);
|
|
103722
103814
|
changeInfo = {
|
|
@@ -103736,6 +103828,24 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103736
103828
|
if (hasLocalChanges) {
|
|
103737
103829
|
const hasStagedChanges = statusLines.some((line) => line[0] !== " " && line[0] !== "?");
|
|
103738
103830
|
const changedFiles = parseGitStatus(gitStatus);
|
|
103831
|
+
const unstagedStatResult = await tools2.executeCommand({
|
|
103832
|
+
command: "git",
|
|
103833
|
+
args: ["diff", "--numstat", "--no-color"]
|
|
103834
|
+
});
|
|
103835
|
+
const unstagedStats = unstagedStatResult.exitCode === 0 ? parseGitDiffNumStat(unstagedStatResult.stdout) : {};
|
|
103836
|
+
const stagedStatResult = await tools2.executeCommand({
|
|
103837
|
+
command: "git",
|
|
103838
|
+
args: ["diff", "--numstat", "--cached", "--no-color"]
|
|
103839
|
+
});
|
|
103840
|
+
const stagedStats = stagedStatResult.exitCode === 0 ? parseGitDiffNumStat(stagedStatResult.stdout) : {};
|
|
103841
|
+
for (const file3 of changedFiles) {
|
|
103842
|
+
const unstaged = unstagedStats[file3.path] || { insertions: 0, deletions: 0 };
|
|
103843
|
+
const staged = stagedStats[file3.path] || { insertions: 0, deletions: 0 };
|
|
103844
|
+
if (unstaged.insertions > 0 || unstaged.deletions > 0 || staged.insertions > 0 || staged.deletions > 0) {
|
|
103845
|
+
file3.insertions = unstaged.insertions + staged.insertions;
|
|
103846
|
+
file3.deletions = unstaged.deletions + staged.deletions;
|
|
103847
|
+
}
|
|
103848
|
+
}
|
|
103739
103849
|
printChangedFiles(logger, changedFiles);
|
|
103740
103850
|
changeInfo = {
|
|
103741
103851
|
staged: hasStagedChanges,
|
|
@@ -103772,7 +103882,21 @@ var reviewWorkflow = async (input2, context) => {
|
|
|
103772
103882
|
logger.warn("Warning: Could not retrieve file changes list");
|
|
103773
103883
|
return [];
|
|
103774
103884
|
}
|
|
103775
|
-
|
|
103885
|
+
const files = parseGitDiffNameStatus(diffResult.stdout);
|
|
103886
|
+
const statResult = await tools2.executeCommand({
|
|
103887
|
+
command: "git",
|
|
103888
|
+
args: ["--no-pager", "diff", "--numstat", "--no-color", `${defaultBranch}...${currentBranch}`]
|
|
103889
|
+
});
|
|
103890
|
+
if (statResult.exitCode === 0) {
|
|
103891
|
+
const stats = parseGitDiffNumStat(statResult.stdout);
|
|
103892
|
+
for (const file3 of files) {
|
|
103893
|
+
if (stats[file3.path]) {
|
|
103894
|
+
file3.insertions = stats[file3.path].insertions;
|
|
103895
|
+
file3.deletions = stats[file3.path].deletions;
|
|
103896
|
+
}
|
|
103897
|
+
}
|
|
103898
|
+
}
|
|
103899
|
+
return files;
|
|
103776
103900
|
});
|
|
103777
103901
|
printChangedFiles(logger, branchChangedFiles);
|
|
103778
103902
|
changeInfo = {
|
|
@@ -103929,25 +104053,30 @@ async function runEpic(task2, _options, command) {
|
|
|
103929
104053
|
epicContext.task = taskInput;
|
|
103930
104054
|
}
|
|
103931
104055
|
let usageMeter;
|
|
103932
|
-
const saveUsageSnapshot = async () => {
|
|
103933
|
-
if (usageMeter) {
|
|
103934
|
-
const currentUsage = usageMeter.usage;
|
|
103935
|
-
if (!epicContext.usages) {
|
|
103936
|
-
epicContext.usages = [];
|
|
103937
|
-
}
|
|
103938
|
-
epicContext.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
103939
|
-
}
|
|
103940
|
-
};
|
|
103941
104056
|
const workflowInput = {
|
|
103942
104057
|
...epicContext,
|
|
103943
|
-
|
|
103944
|
-
|
|
103945
|
-
|
|
103946
|
-
|
|
103947
|
-
|
|
103948
|
-
|
|
103949
|
-
|
|
103950
|
-
|
|
104058
|
+
interactive: !yes,
|
|
104059
|
+
saveEpicContext: async (context) => {
|
|
104060
|
+
if (context.task)
|
|
104061
|
+
workflowInput.task = context.task;
|
|
104062
|
+
if (context.plan)
|
|
104063
|
+
workflowInput.plan = context.plan;
|
|
104064
|
+
if (context.branchName)
|
|
104065
|
+
workflowInput.branchName = context.branchName;
|
|
104066
|
+
if (context.baseBranch)
|
|
104067
|
+
workflowInput.baseBranch = context.baseBranch;
|
|
104068
|
+
await saveEpicContext(workflowInput);
|
|
104069
|
+
},
|
|
104070
|
+
saveUsageSnapshot: async () => {
|
|
104071
|
+
if (usageMeter) {
|
|
104072
|
+
const currentUsage = usageMeter.usage;
|
|
104073
|
+
if (!workflowInput.usages) {
|
|
104074
|
+
workflowInput.usages = [];
|
|
104075
|
+
}
|
|
104076
|
+
workflowInput.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
104077
|
+
await saveEpicContext(workflowInput);
|
|
104078
|
+
}
|
|
104079
|
+
}
|
|
103951
104080
|
};
|
|
103952
104081
|
await runWorkflow(epicWorkflow, workflowInput, {
|
|
103953
104082
|
commandName: "epic",
|