@polka-codes/cli 0.9.55 → 0.9.56

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.
Files changed (2) hide show
  1. package/dist/index.js +83 -8
  2. 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.55";
35582
+ var version = "0.9.56";
35583
35583
 
35584
35584
  // src/commands/code.ts
35585
35585
  import { readFile as readFile3 } from "node:fs/promises";
@@ -78705,6 +78705,7 @@ async function runWorkflow(workflow2, workflowInput, options) {
78705
78705
  maxMessages: config4.maxMessageCount,
78706
78706
  maxCost: config4.budget
78707
78707
  });
78708
+ options.onUsageMeterCreated?.(usage);
78708
78709
  const onEvent = printEvent(verbose, usage, process.stderr);
78709
78710
  const excludeFiles = [".epic.yml", ...config4.excludeFiles ?? []];
78710
78711
  const toolProvider = (options.getProvider ?? getProvider)({ excludeFiles });
@@ -78966,7 +78967,7 @@ When planning an epic:
78966
78967
  Your plan must have two parts: task description and implementation plan.
78967
78968
 
78968
78969
  ### 1. Task Description
78969
- Include the verbatim user request to provide context for the implementation plan.
78970
+ Start by providing a detailed description of the task and its expected outcome. This description should be a comprehensive summary based on the user's request, setting the stage for the detailed implementation plan that follows. It should clearly articulate the "what" and "why" of the epic before breaking it down into "how".
78970
78971
 
78971
78972
  ### 2. Implementation Plan
78972
78973
 
@@ -78997,7 +78998,14 @@ For epic-scale work, **use markdown checkboxes** to track progress through multi
78997
78998
  \`\`\`
78998
78999
  ### 1. Task Description
78999
79000
 
79000
- Implement user authentication with JWT tokens.
79001
+ This epic is to implement a complete user authentication system using JSON Web Tokens (JWT). The primary goal is to allow users to register for a new account and log in to receive a token that can be used to access protected resources. The system should handle password hashing for security and provide a way to manage user sessions on the frontend.
79002
+
79003
+ **Expected Outcome:**
79004
+ - A backend with registration and login endpoints.
79005
+ - Secure password storage using bcrypt.
79006
+ - JWT generation upon successful login.
79007
+ - Middleware to protect specific routes.
79008
+ - A frontend with a login form, registration form, and context for managing authentication state.
79001
79009
 
79002
79010
  ### 2. Implementation Plan
79003
79011
 
@@ -80580,6 +80588,7 @@ var MAX_REVIEW_RETRIES = 5;
80580
80588
  var TODO_HANDLING_INSTRUCTIONS = `If you discover that a task is larger than you thought, or that a new task is required, you can add a // TODO comment in the code and create a todo item for it. This will allow you to continue with the current task and address the larger issue later.`;
80581
80589
  async function createPlan2(input2, context) {
80582
80590
  const { task, plan: plan2, files, feedback, messages } = input2;
80591
+ const { tools: tools2 } = context;
80583
80592
  const agentTools = [
80584
80593
  askFollowupQuestion_default,
80585
80594
  fetchUrl_default,
@@ -80600,7 +80609,13 @@ async function createPlan2(input2, context) {
80600
80609
  outputSchema: EpicPlanSchema
80601
80610
  }, context);
80602
80611
  }
80603
- const content = [{ type: "text", text: getPlanPrompt(task, plan2) }];
80612
+ const defaultContext = await getDefaultContext();
80613
+ const memoryContext = await tools2.getMemoryContext();
80614
+ const prompt = `${memoryContext}
80615
+ ${getPlanPrompt(task, plan2)}
80616
+
80617
+ ${defaultContext}`;
80618
+ const content = [{ type: "text", text: prompt }];
80604
80619
  if (files) {
80605
80620
  for (const file2 of files) {
80606
80621
  if (file2.type === "file") {
@@ -81136,6 +81151,37 @@ Summary:`);
81136
81151
  for (const [idx, msg] of commitMessages.entries()) {
81137
81152
  logger.info(` ${idx + 1}. ${msg}`);
81138
81153
  }
81154
+ if (input2.usages && input2.usages.length > 0) {
81155
+ const sortedUsages = [...input2.usages].sort((a, b) => a.timestamp - b.timestamp);
81156
+ let lastUsage = {
81157
+ input: 0,
81158
+ output: 0,
81159
+ cachedRead: 0,
81160
+ cost: 0,
81161
+ messageCount: 0
81162
+ };
81163
+ logger.info(`
81164
+ Usage Breakdown:`);
81165
+ sortedUsages.forEach((usage, index) => {
81166
+ const delta = {
81167
+ input: usage.input - lastUsage.input,
81168
+ output: usage.output - lastUsage.output,
81169
+ cachedRead: usage.cachedRead - lastUsage.cachedRead,
81170
+ cost: usage.cost - lastUsage.cost,
81171
+ messageCount: usage.messageCount - lastUsage.messageCount
81172
+ };
81173
+ const tempMeter = new UsageMeter;
81174
+ tempMeter.setUsage(delta);
81175
+ logger.info(` Step ${index + 1}: ${tempMeter.getUsageText()}`);
81176
+ lastUsage = usage;
81177
+ });
81178
+ const last = sortedUsages.at(-1);
81179
+ if (last) {
81180
+ const totalMeter = new UsageMeter;
81181
+ totalMeter.setUsage(last);
81182
+ logger.info(` Total: ${totalMeter.getUsageText()}`);
81183
+ }
81184
+ }
81139
81185
  } catch (error46) {
81140
81186
  logger.error(`
81141
81187
  Epic workflow failed: ${error46 instanceof Error ? error46.message : String(error46)}`);
@@ -81437,13 +81483,22 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
81437
81483
  // src/workflows/epic-context.ts
81438
81484
  import { promises as fs3 } from "node:fs";
81439
81485
  var EPIC_CONTEXT_FILE = ".epic.yml";
81486
+ var EpicUsageSchema = exports_external.object({
81487
+ timestamp: exports_external.number(),
81488
+ input: exports_external.number(),
81489
+ output: exports_external.number(),
81490
+ cachedRead: exports_external.number(),
81491
+ cost: exports_external.number(),
81492
+ messageCount: exports_external.number()
81493
+ });
81440
81494
  var EpicContextSchema = exports_external.object({
81441
81495
  task: exports_external.string().nullish(),
81442
81496
  plan: exports_external.string().nullish(),
81443
81497
  branchName: exports_external.string().nullish(),
81444
81498
  baseBranch: exports_external.string().nullish(),
81445
81499
  todos: exports_external.array(TodoItemSchema).nullish(),
81446
- memory: exports_external.record(exports_external.string(), exports_external.string()).nullish()
81500
+ memory: exports_external.record(exports_external.string(), exports_external.string()).nullish(),
81501
+ usages: exports_external.array(EpicUsageSchema).nullish()
81447
81502
  });
81448
81503
  var saveEpicContext = async (context) => {
81449
81504
  const yamlString = $stringify({
@@ -81452,7 +81507,8 @@ var saveEpicContext = async (context) => {
81452
81507
  branchName: context.branchName,
81453
81508
  baseBranch: context.baseBranch,
81454
81509
  todos: context.todos,
81455
- memory: context.memory
81510
+ memory: context.memory,
81511
+ usages: context.usages
81456
81512
  });
81457
81513
  await fs3.writeFile(EPIC_CONTEXT_FILE, yamlString, "utf-8");
81458
81514
  };
@@ -81526,10 +81582,26 @@ async function runEpic(task2, _options, command) {
81526
81582
  }
81527
81583
  epicContext.task = taskInput;
81528
81584
  }
81585
+ let usageAppended = false;
81529
81586
  const workflowInput = {
81530
81587
  ...epicContext,
81531
- saveEpicContext
81588
+ async saveEpicContext(context) {
81589
+ if (usageMeter) {
81590
+ const currentUsage = usageMeter.usage;
81591
+ if (!context.usages) {
81592
+ context.usages = [];
81593
+ }
81594
+ if (!usageAppended) {
81595
+ context.usages.push({ ...currentUsage, timestamp: Date.now() });
81596
+ usageAppended = true;
81597
+ } else {
81598
+ context.usages[context.usages.length - 1] = { ...currentUsage, timestamp: Date.now() };
81599
+ }
81600
+ }
81601
+ await saveEpicContext(context);
81602
+ }
81532
81603
  };
81604
+ let usageMeter;
81533
81605
  await runWorkflow(epicWorkflow, workflowInput, {
81534
81606
  commandName: "epic",
81535
81607
  command,
@@ -81539,7 +81611,10 @@ async function runEpic(task2, _options, command) {
81539
81611
  ...opt,
81540
81612
  todoItemStore: new EpicTodoItemStore(workflowInput),
81541
81613
  memoryStore: new EpicMemoryStore(workflowInput)
81542
- })
81614
+ }),
81615
+ onUsageMeterCreated: (meter) => {
81616
+ usageMeter = meter;
81617
+ }
81543
81618
  });
81544
81619
  }
81545
81620
  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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.55",
3
+ "version": "0.9.56",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",