@polka-codes/cli 0.9.99 → 0.9.100

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 +167 -52
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -112338,7 +112338,7 @@ var {
112338
112338
  Help
112339
112339
  } = import__.default;
112340
112340
  // package.json
112341
- var version = "0.9.99";
112341
+ var version = "0.9.100";
112342
112342
 
112343
112343
  // src/commands/agent.ts
112344
112344
  init_src();
@@ -117712,13 +117712,15 @@ init_prompts2();
117712
117712
 
117713
117713
  // src/workflows/task.workflow.ts
117714
117714
  init_src();
117715
+ init_zod();
117715
117716
  init_workflow_utils();
117716
117717
  var SYSTEM_PROMPT = `You are a generic AI assistant.
117717
117718
  You are able to perform simple tasks including making simple changes, reading code, and answering user questions.
117718
117719
  Use the available tools to perform the task.`;
117720
+ var TaskOutputSchema = exports_external.any().describe("A JSON value with the task result");
117719
117721
  var taskWorkflow = async (input2, context) => {
117720
117722
  const { logger, step } = context;
117721
- const { task, additionalTools } = input2;
117723
+ const { task, additionalTools, jsonMode } = input2;
117722
117724
  logger.info(`
117723
117725
  Running generic agent...
117724
117726
  `);
@@ -117740,33 +117742,44 @@ Running generic agent...
117740
117742
  if (additionalTools?.mcpTools) {
117741
117743
  agentTools.push(...additionalTools.mcpTools);
117742
117744
  }
117743
- await step("agent", async () => {
117745
+ const result = await step("agent", async () => {
117744
117746
  const defaultContext = await getDefaultContext("task");
117745
117747
  const userMessage = `${task}
117746
117748
 
117747
117749
  ${defaultContext}`;
117748
- await agentWorkflow({
117750
+ return await agentWorkflow({
117749
117751
  systemPrompt: SYSTEM_PROMPT,
117750
117752
  userMessage: [{ role: "user", content: userMessage }],
117751
- tools: agentTools
117753
+ tools: agentTools,
117754
+ outputSchema: jsonMode ? TaskOutputSchema : undefined
117752
117755
  }, context);
117753
117756
  });
117754
117757
  logger.info(`
117755
117758
  Agent finished!
117756
117759
  `);
117757
- return { success: true };
117760
+ return result;
117758
117761
  };
117759
117762
 
117760
117763
  // src/workflows/meta.workflow.ts
117761
117764
  var DecisionSchema = exports_external.object({
117762
117765
  workflow: exports_external.enum(["code", "task"])
117763
117766
  });
117767
+ var MetaOutputSchema = exports_external.object({
117768
+ workflow: exports_external.enum(["code", "task"]).describe("The workflow that was executed"),
117769
+ success: exports_external.boolean().describe("Whether the workflow completed successfully"),
117770
+ summary: exports_external.string().optional().describe("Summary of what was done"),
117771
+ error: exports_external.string().optional().describe("Error message if the workflow failed")
117772
+ });
117764
117773
  var metaWorkflow = async (input2, context) => {
117765
117774
  const { task } = input2;
117766
117775
  const { logger } = context;
117767
117776
  if (!task) {
117768
117777
  logger.error("Task is not defined in the input for metaWorkflow.");
117769
- return;
117778
+ return {
117779
+ workflow: "task",
117780
+ success: false,
117781
+ error: "Task is not defined in the input for metaWorkflow."
117782
+ };
117770
117783
  }
117771
117784
  logger.info(`
117772
117785
  Deciding which workflow to use for task...
@@ -117783,27 +117796,67 @@ Deciding which workflow to use for task...
117783
117796
  outputSchema: DecisionSchema
117784
117797
  }, context);
117785
117798
  if (result.type !== "Exit" || !result.object) {
117786
- throw new Error(`Could not decide which workflow to run. Agent exited with reason: ${result.type}`);
117799
+ const errorMsg = `Could not decide which workflow to run. Agent exited with reason: ${result.type}`;
117800
+ logger.error(errorMsg);
117801
+ return {
117802
+ workflow: "task",
117803
+ success: false,
117804
+ error: errorMsg
117805
+ };
117787
117806
  }
117788
117807
  const decision = result.object;
117789
117808
  if (!decision.workflow) {
117790
- throw new Error("Could not decide which workflow to run.");
117809
+ const errorMsg = "Could not decide which workflow to run.";
117810
+ logger.error(errorMsg);
117811
+ return {
117812
+ workflow: "task",
117813
+ success: false,
117814
+ error: errorMsg
117815
+ };
117791
117816
  }
117792
117817
  logger.info(`
117793
117818
  Decision: Using '${decision.workflow}' workflow.`);
117794
117819
  switch (decision.workflow) {
117795
- case "code":
117796
- await codeWorkflow({ task, interactive: input2.interactive, additionalTools: input2.additionalTools }, context);
117797
- break;
117798
- case "task":
117799
- await taskWorkflow({
117820
+ case "code": {
117821
+ const codeResult = await codeWorkflow({ task, interactive: input2.interactive, additionalTools: input2.additionalTools }, context);
117822
+ return {
117823
+ workflow: "code",
117824
+ success: codeResult.success,
117825
+ summary: codeResult.summaries?.join(`
117826
+ `),
117827
+ error: codeResult.success === false ? codeResult.reason : undefined
117828
+ };
117829
+ }
117830
+ case "task": {
117831
+ const taskResult = await taskWorkflow({
117800
117832
  task,
117801
117833
  interactive: input2.interactive,
117802
117834
  additionalTools: input2.additionalTools
117803
117835
  }, context);
117804
- break;
117805
- default:
117806
- throw new Error(`Unknown workflow: ${decision.workflow}`);
117836
+ if (taskResult.type === "Exit") {
117837
+ return {
117838
+ workflow: "task",
117839
+ success: true,
117840
+ summary: taskResult.message
117841
+ };
117842
+ } else if (taskResult.type === "Error") {
117843
+ return {
117844
+ workflow: "task",
117845
+ success: false,
117846
+ error: taskResult.error.message
117847
+ };
117848
+ } else {
117849
+ return {
117850
+ workflow: "task",
117851
+ success: false,
117852
+ error: "Usage limit exceeded"
117853
+ };
117854
+ }
117855
+ }
117856
+ default: {
117857
+ const errorMsg = `Unknown workflow: ${decision.workflow}`;
117858
+ throw new Error(errorMsg);
117859
+ }
117807
117860
  }
117808
117861
  };
117809
117862
 
@@ -117957,12 +118010,28 @@ async function fix3(options = {}) {
117957
118010
  onUsageMeterCreated: onUsage
117958
118011
  });
117959
118012
  }
118013
+ async function task2(options) {
118014
+ const { task: taskInput, jsonMode, interactive, onUsage, ...context } = options;
118015
+ const verbose = context.silent ? -1 : context.verbose ?? 0;
118016
+ const logger = createLogger({ verbose });
118017
+ const workflowInput = {
118018
+ task: taskInput,
118019
+ jsonMode
118020
+ };
118021
+ return runWorkflow(taskWorkflow, workflowInput, {
118022
+ commandName: "task",
118023
+ context,
118024
+ logger,
118025
+ interactive: interactive !== false,
118026
+ onUsageMeterCreated: onUsage
118027
+ });
118028
+ }
117960
118029
  async function plan3(options = {}) {
117961
- const { task: task2, fileContent, planFile, files, mode, interactive, onUsage, ...context } = options;
118030
+ const { task: task3, fileContent, planFile, files, mode, interactive, onUsage, ...context } = options;
117962
118031
  const verbose = context.silent ? -1 : context.verbose ?? 0;
117963
118032
  const logger = createLogger({ verbose });
117964
118033
  const workflowInput = {
117965
- task: task2,
118034
+ task: task3,
117966
118035
  fileContent,
117967
118036
  filePath: planFile,
117968
118037
  files,
@@ -118025,8 +118094,8 @@ var readStdin = async (timeoutMs = COMMAND_CONSTANTS.DEFAULT_STDIN_TIMEOUT_MS) =
118025
118094
  });
118026
118095
  });
118027
118096
  };
118028
- async function runCode(task2, _options, command) {
118029
- let taskInput = task2;
118097
+ async function runCode(task3, _options, command) {
118098
+ let taskInput = task3;
118030
118099
  const stdin = await readStdin();
118031
118100
  if (stdin) {
118032
118101
  taskInput = stdin;
@@ -118113,7 +118182,20 @@ init_lodash();
118113
118182
  init_dist();
118114
118183
 
118115
118184
  // src/builtin-commands.ts
118116
- var BUILT_IN_COMMANDS = ["code", "commit", "pr", "review", "fix", "plan", "workflow", "run", "init", "meta", "skills"];
118185
+ var BUILT_IN_COMMANDS = [
118186
+ "code",
118187
+ "commit",
118188
+ "pr",
118189
+ "review",
118190
+ "fix",
118191
+ "plan",
118192
+ "task",
118193
+ "workflow",
118194
+ "run",
118195
+ "init",
118196
+ "meta",
118197
+ "skills"
118198
+ ];
118117
118199
 
118118
118200
  // src/configPrompt.ts
118119
118201
  init_dist18();
@@ -119444,15 +119526,15 @@ class McpServer {
119444
119526
  const taskExtra = { ...extra, taskStore: extra.taskStore };
119445
119527
  const createTaskResult = args ? await Promise.resolve(handler20.createTask(args, taskExtra)) : await Promise.resolve(handler20.createTask(taskExtra));
119446
119528
  const taskId = createTaskResult.task.taskId;
119447
- let task2 = createTaskResult.task;
119448
- const pollInterval = task2.pollInterval ?? 5000;
119449
- while (task2.status !== "completed" && task2.status !== "failed" && task2.status !== "cancelled") {
119529
+ let task3 = createTaskResult.task;
119530
+ const pollInterval = task3.pollInterval ?? 5000;
119531
+ while (task3.status !== "completed" && task3.status !== "failed" && task3.status !== "cancelled") {
119450
119532
  await new Promise((resolve7) => setTimeout(resolve7, pollInterval));
119451
119533
  const updatedTask = await extra.taskStore.getTask(taskId);
119452
119534
  if (!updatedTask) {
119453
119535
  throw new McpError2(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
119454
119536
  }
119455
- task2 = updatedTask;
119537
+ task3 = updatedTask;
119456
119538
  }
119457
119539
  return await extra.taskStore.getTaskResult(taskId);
119458
119540
  }
@@ -120273,10 +120355,10 @@ Parameters:
120273
120355
  ...providerOverrideSchema.shape
120274
120356
  }),
120275
120357
  handler: async (args, toolContext) => {
120276
- const { task: task2 } = args;
120358
+ const { task: task3 } = args;
120277
120359
  const providerOverride = extractProviderOverride(args);
120278
- logger.info(`MCP: Executing code workflow - task: "${task2}"${providerOverride?.provider ? ` with provider: ${providerOverride.provider}` : ""}`);
120279
- return await executeWorkflow(codeWorkflow, { task: task2 }, "code", logger, providerOverride, toolContext.defaultProvider);
120360
+ logger.info(`MCP: Executing code workflow - task: "${task3}"${providerOverride?.provider ? ` with provider: ${providerOverride.provider}` : ""}`);
120361
+ return await executeWorkflow(codeWorkflow, { task: task3 }, "code", logger, providerOverride, toolContext.defaultProvider);
120280
120362
  }
120281
120363
  },
120282
120364
  {
@@ -120359,9 +120441,9 @@ Parameters:
120359
120441
  ...providerOverrideSchema.shape
120360
120442
  }),
120361
120443
  handler: async (args, toolContext) => {
120362
- const { task: task2 } = args;
120444
+ const { task: task3 } = args;
120363
120445
  const providerOverride = extractProviderOverride(args);
120364
- logger.info(`MCP: Executing plan workflow - task: "${task2}"${providerOverride?.provider ? ` with provider: ${providerOverride.provider}` : ""}`);
120446
+ logger.info(`MCP: Executing plan workflow - task: "${task3}"${providerOverride?.provider ? ` with provider: ${providerOverride.provider}` : ""}`);
120365
120447
  try {
120366
120448
  const context = createExecutionContext(logger);
120367
120449
  const finalProvider = providerOverride?.provider || toolContext.defaultProvider?.provider;
@@ -120377,7 +120459,7 @@ Parameters:
120377
120459
  if (finalApiKey) {
120378
120460
  context.apiKey = finalApiKey;
120379
120461
  }
120380
- const result = await runWorkflow(planWorkflow, { task: task2, interactive: false }, {
120462
+ const result = await runWorkflow(planWorkflow, { task: task3, interactive: false }, {
120381
120463
  commandName: "plan",
120382
120464
  context,
120383
120465
  logger,
@@ -120457,10 +120539,10 @@ Parameters:
120457
120539
  ...providerOverrideSchema.shape
120458
120540
  }),
120459
120541
  handler: async (args, toolContext) => {
120460
- const { task: task2 } = args;
120542
+ const { task: task3 } = args;
120461
120543
  const providerOverride = extractProviderOverride(args);
120462
- logger.info(`MCP: Executing fix workflow - task: "${task2}"${providerOverride?.provider ? ` with provider: ${providerOverride.provider}` : ""}`);
120463
- return await executeWorkflow(fixWorkflow, { task: task2 }, "fix", logger, providerOverride, toolContext.defaultProvider);
120544
+ logger.info(`MCP: Executing fix workflow - task: "${task3}"${providerOverride?.provider ? ` with provider: ${providerOverride.provider}` : ""}`);
120545
+ return await executeWorkflow(fixWorkflow, { task: task3 }, "fix", logger, providerOverride, toolContext.defaultProvider);
120464
120546
  }
120465
120547
  },
120466
120548
  {
@@ -121420,14 +121502,14 @@ async function executeScript(script, name18, logger, args = []) {
121420
121502
  }
121421
121503
 
121422
121504
  // src/commands/meta.ts
121423
- async function runMeta(task2, command) {
121505
+ async function runMeta(task3, command) {
121424
121506
  const workflowOpts = getBaseWorkflowOptions(command);
121425
- const { verbose } = workflowOpts;
121507
+ const { verbose, json: json2 } = workflowOpts;
121426
121508
  const logger = createLogger({
121427
- verbose
121509
+ verbose: json2 ? -1 : verbose
121428
121510
  });
121429
- if (task2) {
121430
- const trimmedTask = task2.trim();
121511
+ if (task3) {
121512
+ const trimmedTask = task3.trim();
121431
121513
  const words2 = trimmedTask.split(/\s+/);
121432
121514
  if (words2.length === 1) {
121433
121515
  const matched = await tryExecuteCommand(words2[0], logger);
@@ -121436,7 +121518,7 @@ async function runMeta(task2, command) {
121436
121518
  }
121437
121519
  logger.error(`Error: Unknown command '${words2[0]}'`);
121438
121520
  logger.info("Available commands:");
121439
- logger.info(" Built-in: code, commit, pr, review, fix, plan, workflow, run");
121521
+ logger.info(" Built-in: code, commit, pr, review, fix, plan, task, workflow, run");
121440
121522
  const config4 = await loadConfig2();
121441
121523
  if (config4?.scripts) {
121442
121524
  const scriptNames = Object.keys(config4.scripts);
@@ -121456,15 +121538,19 @@ async function runMeta(task2, command) {
121456
121538
  return;
121457
121539
  }
121458
121540
  const workflowInput2 = {
121459
- task: task2,
121541
+ task: task3,
121542
+ jsonMode: json2 === true,
121460
121543
  ...workflowOpts
121461
121544
  };
121462
- await runWorkflow(metaWorkflow, workflowInput2, {
121545
+ const result2 = await runWorkflow(metaWorkflow, workflowInput2, {
121463
121546
  commandName: "meta",
121464
121547
  context: workflowOpts,
121465
121548
  logger,
121466
121549
  ...workflowOpts
121467
121550
  });
121551
+ if (json2 && result2) {
121552
+ console.log(JSON.stringify(result2, null, 2));
121553
+ }
121468
121554
  return;
121469
121555
  }
121470
121556
  const input2 = await getUserInput("What do you want to work on?");
@@ -121481,7 +121567,7 @@ async function runMeta(task2, command) {
121481
121567
  }
121482
121568
  logger.error(`Error: Unknown command '${words[0]}'`);
121483
121569
  logger.info("Available commands:");
121484
- logger.info(" Built-in: code, commit, pr, review, fix, plan, workflow, run");
121570
+ logger.info(" Built-in: code, commit, pr, review, fix, plan, task, workflow, run");
121485
121571
  return;
121486
121572
  }
121487
121573
  if (words.length < 2) {
@@ -121492,14 +121578,18 @@ async function runMeta(task2, command) {
121492
121578
  }
121493
121579
  const workflowInput = {
121494
121580
  task: input2,
121581
+ jsonMode: json2 === true,
121495
121582
  ...workflowOpts
121496
121583
  };
121497
- await runWorkflow(metaWorkflow, workflowInput, {
121584
+ const result = await runWorkflow(metaWorkflow, workflowInput, {
121498
121585
  commandName: "meta",
121499
121586
  context: workflowOpts,
121500
121587
  logger,
121501
121588
  ...workflowOpts
121502
121589
  });
121590
+ if (json2 && result) {
121591
+ console.log(JSON.stringify(result, null, 2));
121592
+ }
121503
121593
  }
121504
121594
  async function tryExecuteCommand(commandName, logger) {
121505
121595
  if (BUILT_IN_COMMANDS.includes(commandName)) {
@@ -121527,8 +121617,8 @@ async function tryExecuteCommand(commandName, logger) {
121527
121617
 
121528
121618
  // src/commands/plan.ts
121529
121619
  import { readFileSync as readFileSync3 } from "node:fs";
121530
- var planCommand = new Command("plan").description("Create or update a plan for a task.").argument("[task]", "The task to plan.").option("-p, --plan-file <path>", "The path to the plan file.").action(async (task2, options, command) => {
121531
- let taskInput = task2;
121620
+ var planCommand = new Command("plan").description("Create or update a plan for a task.").argument("[task]", "The task to plan.").option("-p, --plan-file <path>", "The path to the plan file.").action(async (task3, options, command) => {
121621
+ let taskInput = task3;
121532
121622
  let fileContent;
121533
121623
  if (options.planFile) {
121534
121624
  try {
@@ -121899,10 +121989,33 @@ skillsCommand.command("validate").description("Validate a skill's structure and
121899
121989
  }
121900
121990
  });
121901
121991
 
121992
+ // src/commands/task.ts
121993
+ async function runTask(taskInput, options, command) {
121994
+ const workflowOpts = getBaseWorkflowOptions(command);
121995
+ if (options.json) {
121996
+ workflowOpts.silent = true;
121997
+ }
121998
+ const result = await task2({
121999
+ task: taskInput ?? "",
122000
+ jsonMode: options.json === true,
122001
+ ...workflowOpts
122002
+ });
122003
+ if (options.json) {
122004
+ if (result) {
122005
+ if (result.type === "Exit" && result.object) {
122006
+ console.log(JSON.stringify(result.object, null, 2));
122007
+ } else {
122008
+ console.log(JSON.stringify(result, null, 2));
122009
+ }
122010
+ }
122011
+ }
122012
+ }
122013
+ var taskCommand = new Command("task").description("Run a generic task using an AI agent.").argument("[task]", "The task to perform").option("--json", "Output result as JSON").action(runTask);
122014
+
121902
122015
  // src/commands/workflow.ts
121903
122016
  init_src();
121904
122017
  import { readFile as readFile14 } from "node:fs/promises";
121905
- async function runWorkflowCommand(task2, _options, command) {
122018
+ async function runWorkflowCommand(task3, _options, command) {
121906
122019
  const workflowOpts = getBaseWorkflowOptions(command);
121907
122020
  const { verbose } = workflowOpts;
121908
122021
  const logger = createLogger({ verbose });
@@ -121973,10 +122086,10 @@ async function runWorkflowCommand(task2, _options, command) {
121973
122086
  };
121974
122087
  const selectedWorkflow = workflowDef.workflows[workflowId];
121975
122088
  const workflowInput = {};
121976
- if (selectedWorkflow.inputs && selectedWorkflow.inputs.length > 0 && task2) {
122089
+ if (selectedWorkflow.inputs && selectedWorkflow.inputs.length > 0 && task3) {
121977
122090
  const firstInput = selectedWorkflow.inputs[0];
121978
- workflowInput[firstInput.id] = task2;
121979
- logger.info(`Workflow input '${firstInput.id}': ${task2}`);
122091
+ workflowInput[firstInput.id] = task3;
122092
+ logger.info(`Workflow input '${firstInput.id}': ${task3}`);
121980
122093
  } else if (selectedWorkflow.inputs && selectedWorkflow.inputs.length > 0) {
121981
122094
  logger.info(`Workflow expects inputs: ${selectedWorkflow.inputs.map((i2) => i2.id).join(", ")}`);
121982
122095
  } else {
@@ -121996,7 +122109,7 @@ var workflowCommand = new Command("workflow").description("Run custom workflows.
121996
122109
  globalThis.AI_SDK_LOG_WARNINGS = false;
121997
122110
  var program2 = new Command;
121998
122111
  program2.name("polka").description("Polka Codes CLI").version(version);
121999
- program2.argument("[task]", "The task to execute").action((task2, _options, command) => runMeta(task2, command));
122112
+ program2.argument("[task]", "The task to execute").action((task3, _options, command) => runMeta(task3, command));
122000
122113
  program2.addCommand(initCommand);
122001
122114
  program2.addCommand(agentCommand);
122002
122115
  program2.addCommand(commitCommand);
@@ -122005,6 +122118,7 @@ program2.addCommand(reviewCommand);
122005
122118
  program2.addCommand(planCommand);
122006
122119
  program2.addCommand(codeCommand);
122007
122120
  program2.addCommand(fixCommand);
122121
+ program2.addCommand(taskCommand);
122008
122122
  program2.addCommand(runCommand);
122009
122123
  program2.addCommand(skillsCommand);
122010
122124
  program2.addCommand(mcpServerCommand);
@@ -122023,6 +122137,7 @@ process.on("uncaughtException", (error48) => {
122023
122137
  }
122024
122138
  });
122025
122139
  export {
122140
+ task2 as task,
122026
122141
  reviewCode,
122027
122142
  plan3 as plan,
122028
122143
  fix3 as fix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.9.99",
3
+ "version": "0.9.100",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",