@polka-codes/runner 0.9.34 → 0.9.36

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 +44 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -30494,7 +30494,7 @@ var {
30494
30494
  Help
30495
30495
  } = import__.default;
30496
30496
  // package.json
30497
- var version = "0.9.34";
30497
+ var version = "0.9.36";
30498
30498
 
30499
30499
  // src/runner.ts
30500
30500
  import { execSync } from "node:child_process";
@@ -42659,14 +42659,23 @@ var handler4 = async (provider, args) => {
42659
42659
  try {
42660
42660
  console.log("Executing command:", command, "Requires approval:", requiresApproval);
42661
42661
  const result = await provider.executeCommand(command, requiresApproval);
42662
- const message = `<command>${command}</command>
42662
+ let message = `<command>${command}</command>
42663
42663
  <command_exit_code>${result.exitCode}</command_exit_code>
42664
- <command_stdout>
42664
+ `;
42665
+ if (result.summary) {
42666
+ message += `<command_output_summary>
42667
+ ${result.summary}
42668
+ </command_output_summary>
42669
+ `;
42670
+ } else {
42671
+ message += `<command_stdout>
42665
42672
  ${result.stdout}
42666
42673
  </command_stdout>
42667
42674
  <command_stderr>
42668
42675
  ${result.stderr}
42669
- </command_stderr>`;
42676
+ </command_stderr>
42677
+ `;
42678
+ }
42670
42679
  if (result.exitCode === 0) {
42671
42680
  return {
42672
42681
  type: "Reply" /* Reply */,
@@ -43665,10 +43674,10 @@ class UsageMeter {
43665
43674
  };
43666
43675
  const usage = "totalUsage" in resp ? resp.totalUsage : resp.usage;
43667
43676
  const result = this.#calculageUsage(usage, resp.providerMetadata, modelInfo);
43668
- this.#totals.input += result.input;
43669
- this.#totals.output += result.output;
43670
- this.#totals.cachedRead += result.cachedRead;
43671
- this.#totals.cost += result.cost;
43677
+ this.#totals.input += result.input || 0;
43678
+ this.#totals.output += result.output || 0;
43679
+ this.#totals.cachedRead += result.cachedRead || 0;
43680
+ this.#totals.cost += result.cost || 0;
43672
43681
  this.#totals.messageCount += 1;
43673
43682
  }
43674
43683
  setUsage(newUsage) {
@@ -43709,6 +43718,14 @@ class UsageMeter {
43709
43718
  get usage() {
43710
43719
  return { ...this.#totals };
43711
43720
  }
43721
+ merge(other) {
43722
+ const otherUsage = other.usage;
43723
+ this.#totals.input += otherUsage.input;
43724
+ this.#totals.output += otherUsage.output;
43725
+ this.#totals.cachedRead += otherUsage.cachedRead;
43726
+ this.#totals.cost += otherUsage.cost;
43727
+ this.#totals.messageCount += otherUsage.messageCount;
43728
+ }
43712
43729
  printUsage(customConsole = console) {
43713
43730
  const u = this.usage;
43714
43731
  customConsole.log(`Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, ` + `output: ${u.output}, cost: $${u.cost.toFixed(4)}`);
@@ -56441,6 +56458,7 @@ var configSchema = exports_external.object({
56441
56458
  budget: exports_external.number().positive().optional(),
56442
56459
  retryCount: exports_external.number().int().min(0).optional(),
56443
56460
  requestTimeoutSeconds: exports_external.number().int().positive().optional(),
56461
+ summaryThreshold: exports_external.number().int().positive().optional(),
56444
56462
  scripts: exports_external.record(exports_external.string(), exports_external.string().or(exports_external.object({
56445
56463
  command: exports_external.string(),
56446
56464
  description: exports_external.string()
@@ -62234,8 +62252,25 @@ var getProvider = (options = {}) => {
62234
62252
  options.command?.onStderr(dataStr);
62235
62253
  stderrText += dataStr;
62236
62254
  });
62237
- child.on("close", (code) => {
62255
+ child.on("close", async (code) => {
62238
62256
  options.command?.onExit(code ?? 0);
62257
+ const totalLength = stdoutText.length + stderrText.length;
62258
+ if (totalLength > (options.summaryThreshold ?? 5000) && options.summarizeOutput) {
62259
+ try {
62260
+ const summary = await options.summarizeOutput(stdoutText, stderrText);
62261
+ if (summary) {
62262
+ resolve4({
62263
+ summary,
62264
+ stdout: stdoutText,
62265
+ stderr: stderrText,
62266
+ exitCode: code ?? 0
62267
+ });
62268
+ return;
62269
+ }
62270
+ } catch (_e) {
62271
+ console.error("Summarization failed:", _e);
62272
+ }
62273
+ }
62239
62274
  resolve4({
62240
62275
  stdout: stdoutText,
62241
62276
  stderr: stderrText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.9.34",
3
+ "version": "0.9.36",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",