@polka-codes/cli 0.9.58 → 0.9.59
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 +60 -23
- 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.59";
|
|
35583
35583
|
|
|
35584
35584
|
// src/commands/code.ts
|
|
35585
35585
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
@@ -78531,6 +78531,8 @@ async function generateText(input2, context) {
|
|
|
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
|
+
const lastOutputs = [];
|
|
78535
|
+
let repetitionDetected = false;
|
|
78534
78536
|
const usageMeterOnFinishHandler = context.parameters.usageMeter.onFinishHandler(model);
|
|
78535
78537
|
try {
|
|
78536
78538
|
const stream = streamText({
|
|
@@ -78543,6 +78545,20 @@ async function generateText(input2, context) {
|
|
|
78543
78545
|
timeout = setTimeout(() => abortController.abort(), requestTimeoutSeconds * 1000);
|
|
78544
78546
|
switch (chunk.type) {
|
|
78545
78547
|
case "text-delta":
|
|
78548
|
+
lastOutputs.push(chunk.text);
|
|
78549
|
+
if (lastOutputs.length > 20) {
|
|
78550
|
+
lastOutputs.shift();
|
|
78551
|
+
}
|
|
78552
|
+
if (lastOutputs.length === 20) {
|
|
78553
|
+
const firstHalf = lastOutputs.slice(0, 10).join("");
|
|
78554
|
+
const secondHalf = lastOutputs.slice(10).join("");
|
|
78555
|
+
if (firstHalf === secondHalf) {
|
|
78556
|
+
if (firstHalf.length > 20) {
|
|
78557
|
+
repetitionDetected = true;
|
|
78558
|
+
abortController.abort();
|
|
78559
|
+
}
|
|
78560
|
+
}
|
|
78561
|
+
}
|
|
78546
78562
|
agentCallback?.({
|
|
78547
78563
|
kind: "Text" /* Text */,
|
|
78548
78564
|
newText: chunk.text
|
|
@@ -78571,6 +78587,11 @@ async function generateText(input2, context) {
|
|
|
78571
78587
|
return resp.messages;
|
|
78572
78588
|
} catch (error46) {
|
|
78573
78589
|
if (error46.name === "AbortError") {
|
|
78590
|
+
if (repetitionDetected) {
|
|
78591
|
+
console.warn("Repetition detected, retrying...");
|
|
78592
|
+
continue;
|
|
78593
|
+
}
|
|
78594
|
+
console.warn(`Request timed out after ${requestTimeoutSeconds} seconds, retrying...`);
|
|
78574
78595
|
continue;
|
|
78575
78596
|
}
|
|
78576
78597
|
if ("response" in error46) {
|
|
@@ -80653,7 +80674,7 @@ ${defaultContext}`;
|
|
|
80653
80674
|
outputSchema: EpicPlanSchema
|
|
80654
80675
|
}, context);
|
|
80655
80676
|
}
|
|
80656
|
-
async function createAndApprovePlan(task, context) {
|
|
80677
|
+
async function createAndApprovePlan(task, context, saveUsageSnapshot) {
|
|
80657
80678
|
const { logger, step, tools: tools2 } = context;
|
|
80658
80679
|
logger.info(`Phase 2: Creating high-level plan...
|
|
80659
80680
|
`);
|
|
@@ -80683,6 +80704,7 @@ ${result.plan}`);
|
|
|
80683
80704
|
if (feedback.trim() === "") {
|
|
80684
80705
|
logger.info(`High-level plan approved.
|
|
80685
80706
|
`);
|
|
80707
|
+
await saveUsageSnapshot();
|
|
80686
80708
|
return { plan: result.plan, branchName: result.branchName };
|
|
80687
80709
|
}
|
|
80688
80710
|
break;
|
|
@@ -80914,7 +80936,7 @@ async function findNextTask(tools2) {
|
|
|
80914
80936
|
currentTask = subTasks[0];
|
|
80915
80937
|
}
|
|
80916
80938
|
}
|
|
80917
|
-
async function runImplementationLoop(context, highLevelPlan) {
|
|
80939
|
+
async function runImplementationLoop(context, highLevelPlan, saveUsageSnapshot) {
|
|
80918
80940
|
const { logger, step, tools: tools2 } = context;
|
|
80919
80941
|
const commitMessages = [];
|
|
80920
80942
|
logger.info(`Phase 5: Iterative Implementation Loop...
|
|
@@ -80980,6 +81002,7 @@ Focus only on this item, but use the plan for context.`;
|
|
|
80980
81002
|
}
|
|
80981
81003
|
logger.info(`
|
|
80982
81004
|
Progress: ${progressMessage}`);
|
|
81005
|
+
await saveUsageSnapshot();
|
|
80983
81006
|
if (!nextTaskItem) {
|
|
80984
81007
|
logger.info(`All tasks complete!
|
|
80985
81008
|
`);
|
|
@@ -81091,7 +81114,7 @@ Max retries (${MAX_REVIEW_RETRIES}) reached for final review. Issues might remai
|
|
|
81091
81114
|
}
|
|
81092
81115
|
var epicWorkflow = async (input2, context) => {
|
|
81093
81116
|
const { logger, tools: tools2 } = context;
|
|
81094
|
-
const { task, saveEpicContext } = input2;
|
|
81117
|
+
const { task, saveEpicContext, saveUsageSnapshot } = input2;
|
|
81095
81118
|
const workflowStartTime = Date.now();
|
|
81096
81119
|
if (!task || task.trim() === "") {
|
|
81097
81120
|
logger.error("Error: Task cannot be empty. Please provide a valid task description.");
|
|
@@ -81110,7 +81133,7 @@ var epicWorkflow = async (input2, context) => {
|
|
|
81110
81133
|
logger.error("Error: Task is missing in epic context. Exiting.");
|
|
81111
81134
|
return;
|
|
81112
81135
|
}
|
|
81113
|
-
const planResult = await createAndApprovePlan(input2.task, context);
|
|
81136
|
+
const planResult = await createAndApprovePlan(input2.task, context, saveUsageSnapshot);
|
|
81114
81137
|
if (!planResult)
|
|
81115
81138
|
return;
|
|
81116
81139
|
input2.plan = planResult.plan;
|
|
@@ -81136,8 +81159,9 @@ var epicWorkflow = async (input2, context) => {
|
|
|
81136
81159
|
if (todos.length === 0) {
|
|
81137
81160
|
await addTodoItemsFromPlan(input2.plan, context);
|
|
81138
81161
|
}
|
|
81139
|
-
const commitMessages = await runImplementationLoop(context, input2.plan);
|
|
81162
|
+
const commitMessages = await runImplementationLoop(context, input2.plan, saveUsageSnapshot);
|
|
81140
81163
|
await performFinalReviewAndFix(context, input2.plan, input2.baseBranch ?? undefined);
|
|
81164
|
+
await saveUsageSnapshot();
|
|
81141
81165
|
await tools2.executeCommand({ command: "git", args: ["rm", "-f", ".epic.yml"] });
|
|
81142
81166
|
const statusResult = await tools2.executeCommand({
|
|
81143
81167
|
command: "git",
|
|
@@ -81596,26 +81620,23 @@ async function runEpic(task2, _options, command) {
|
|
|
81596
81620
|
}
|
|
81597
81621
|
epicContext.task = taskInput;
|
|
81598
81622
|
}
|
|
81599
|
-
let
|
|
81623
|
+
let usageMeter;
|
|
81624
|
+
const saveUsageSnapshot = async () => {
|
|
81625
|
+
if (usageMeter) {
|
|
81626
|
+
const currentUsage = usageMeter.usage;
|
|
81627
|
+
if (!epicContext.usages) {
|
|
81628
|
+
epicContext.usages = [];
|
|
81629
|
+
}
|
|
81630
|
+
epicContext.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
81631
|
+
}
|
|
81632
|
+
};
|
|
81600
81633
|
const workflowInput = {
|
|
81601
81634
|
...epicContext,
|
|
81602
81635
|
async saveEpicContext(context) {
|
|
81603
|
-
if (usageMeter) {
|
|
81604
|
-
const currentUsage = usageMeter.usage;
|
|
81605
|
-
if (!context.usages) {
|
|
81606
|
-
context.usages = [];
|
|
81607
|
-
}
|
|
81608
|
-
if (!usageAppended) {
|
|
81609
|
-
context.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
81610
|
-
usageAppended = true;
|
|
81611
|
-
} else {
|
|
81612
|
-
context.usages[context.usages.length - 1] = { ...currentUsage, timestamp: Date.now() };
|
|
81613
|
-
}
|
|
81614
|
-
}
|
|
81615
81636
|
await saveEpicContext(context);
|
|
81616
|
-
}
|
|
81637
|
+
},
|
|
81638
|
+
saveUsageSnapshot
|
|
81617
81639
|
};
|
|
81618
|
-
let usageMeter;
|
|
81619
81640
|
await runWorkflow(epicWorkflow, workflowInput, {
|
|
81620
81641
|
commandName: "epic",
|
|
81621
81642
|
command,
|
|
@@ -81688,9 +81709,22 @@ async function runMeta(task2, command) {
|
|
|
81688
81709
|
}
|
|
81689
81710
|
epicContext.task = taskInput;
|
|
81690
81711
|
}
|
|
81712
|
+
let usageMeter;
|
|
81713
|
+
const saveUsageSnapshot = async () => {
|
|
81714
|
+
if (usageMeter) {
|
|
81715
|
+
const currentUsage = usageMeter.usage;
|
|
81716
|
+
if (!epicContext.usages) {
|
|
81717
|
+
epicContext.usages = [];
|
|
81718
|
+
}
|
|
81719
|
+
epicContext.usages.push({ ...currentUsage, timestamp: Date.now() });
|
|
81720
|
+
}
|
|
81721
|
+
};
|
|
81691
81722
|
const workflowInput = {
|
|
81692
81723
|
...epicContext,
|
|
81693
|
-
saveEpicContext
|
|
81724
|
+
async saveEpicContext(context) {
|
|
81725
|
+
await saveEpicContext(context);
|
|
81726
|
+
},
|
|
81727
|
+
saveUsageSnapshot
|
|
81694
81728
|
};
|
|
81695
81729
|
await runWorkflow(metaWorkflow, workflowInput, {
|
|
81696
81730
|
commandName: "meta",
|
|
@@ -81701,7 +81735,10 @@ async function runMeta(task2, command) {
|
|
|
81701
81735
|
...opt,
|
|
81702
81736
|
todoItemStore: new EpicTodoItemStore(workflowInput),
|
|
81703
81737
|
memoryStore: new EpicMemoryStore(workflowInput)
|
|
81704
|
-
})
|
|
81738
|
+
}),
|
|
81739
|
+
onUsageMeterCreated: (meter) => {
|
|
81740
|
+
usageMeter = meter;
|
|
81741
|
+
}
|
|
81705
81742
|
});
|
|
81706
81743
|
}
|
|
81707
81744
|
|