@kody-ade/kody-engine 0.4.647 → 0.4.648

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/bin/kody.js +31 -8
  2. package/package.json +1 -1
package/dist/bin/kody.js CHANGED
@@ -15,7 +15,7 @@ var init_package = __esm({
15
15
  "package.json"() {
16
16
  package_default = {
17
17
  name: "@kody-ade/kody-engine",
18
- version: "0.4.647",
18
+ version: "0.4.648",
19
19
  description: "kody \u2014 autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative implementation profiles.",
20
20
  license: "MIT",
21
21
  repository: {
@@ -7397,11 +7397,14 @@ function addTokenBreakdown(left, right) {
7397
7397
  function createRunUsage(tokens, costUsd, details = {}) {
7398
7398
  if (!tokens && costUsd === void 0 && details.turns === void 0) return void 0;
7399
7399
  const normalizedTokens = tokenBreakdown(tokens);
7400
+ const hasBillableUsage = normalizedTokens.total > 0 || safeNumber(costUsd) > 0;
7401
+ const measurement = details.outcome === "failed" && !hasBillableUsage ? "unknown" : "reported";
7400
7402
  const modelUsage = {
7401
7403
  tokens: normalizedTokens,
7402
7404
  costUsd: safeNumber(costUsd),
7403
7405
  agentRuns: 1,
7404
- turns: safeNumber(details.turns)
7406
+ turns: safeNumber(details.turns),
7407
+ measurement
7405
7408
  };
7406
7409
  const reportedModels = Object.entries(details.modelUsage ?? {});
7407
7410
  const byModel = reportedModels.length > 0 ? Object.fromEntries(
@@ -7418,7 +7421,8 @@ function createRunUsage(tokens, costUsd, details = {}) {
7418
7421
  tokens: modelTokens,
7419
7422
  costUsd: safeNumber(usage.costUSD),
7420
7423
  agentRuns: 1,
7421
- turns: reportedModels.length === 1 ? safeNumber(details.turns) : 0
7424
+ turns: reportedModels.length === 1 ? safeNumber(details.turns) : 0,
7425
+ measurement
7422
7426
  }
7423
7427
  ];
7424
7428
  })
@@ -7444,13 +7448,27 @@ function isModelRunUsage(value) {
7444
7448
  usage.turns
7445
7449
  ].every((number) => typeof number === "number" && Number.isFinite(number) && number >= 0);
7446
7450
  }
7451
+ function isUsageMeasurement(value) {
7452
+ return value === "reported" || value === "partial" || value === "unknown";
7453
+ }
7454
+ function mergeMeasurement(left, right) {
7455
+ const normalizedLeft = left ?? "reported";
7456
+ const normalizedRight = right ?? "reported";
7457
+ if (normalizedLeft === normalizedRight) return normalizedLeft;
7458
+ return "partial";
7459
+ }
7447
7460
  function parseRunUsage(value) {
7448
7461
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
7449
7462
  const usage = value;
7450
7463
  if (usage.version !== 1 || !isModelRunUsage(usage)) return void 0;
7451
7464
  if (!usage.byModel || typeof usage.byModel !== "object" || Array.isArray(usage.byModel)) return void 0;
7452
7465
  if (!Object.values(usage.byModel).every(isModelRunUsage)) return void 0;
7453
- return structuredClone(usage);
7466
+ const normalized = structuredClone(usage);
7467
+ normalized.measurement = isUsageMeasurement(usage.measurement) ? usage.measurement : "reported";
7468
+ for (const [model, modelUsage] of Object.entries(normalized.byModel)) {
7469
+ modelUsage.measurement = isUsageMeasurement(usage.byModel[model]?.measurement) ? usage.byModel[model].measurement : "reported";
7470
+ }
7471
+ return normalized;
7454
7472
  }
7455
7473
  function mergeRunUsage(left, right) {
7456
7474
  if (!left) return right ? structuredClone(right) : void 0;
@@ -7468,7 +7486,8 @@ function mergeRunUsage(left, right) {
7468
7486
  tokens: addTokenBreakdown(first.tokens, second.tokens),
7469
7487
  costUsd: first.costUsd + second.costUsd,
7470
7488
  agentRuns: first.agentRuns + second.agentRuns,
7471
- turns: first.turns + second.turns
7489
+ turns: first.turns + second.turns,
7490
+ measurement: mergeMeasurement(first.measurement, second.measurement)
7472
7491
  };
7473
7492
  }
7474
7493
  }
@@ -7478,6 +7497,7 @@ function mergeRunUsage(left, right) {
7478
7497
  costUsd: left.costUsd + right.costUsd,
7479
7498
  agentRuns: left.agentRuns + right.agentRuns,
7480
7499
  turns: left.turns + right.turns,
7500
+ measurement: mergeMeasurement(left.measurement, right.measurement),
7481
7501
  byModel
7482
7502
  };
7483
7503
  }
@@ -7487,12 +7507,14 @@ function formatRunUsageMarker(subject, usage) {
7487
7507
  function appendRunUsageSummary(summaryPath, subject, usage) {
7488
7508
  if (!summaryPath) return;
7489
7509
  const tokens = usage.tokens;
7510
+ const tokenLine = usage.measurement === "unknown" ? "- **Tokens:** usage unknown (provider did not report billable usage)" : `- **${usage.measurement === "partial" ? "Known tokens" : "Tokens"}:** ${tokens.input.toLocaleString()} input / ${tokens.cacheRead.toLocaleString()} cache-read / ${tokens.cacheCreate.toLocaleString()} cache-create / ${tokens.output.toLocaleString()} output / ${tokens.total.toLocaleString()} total${usage.measurement === "partial" ? "; some child usage is unknown" : ""}`;
7511
+ const costLine = usage.measurement === "unknown" ? "- **Provider-reported cost:** unknown" : `- **Provider-reported cost:** $${usage.costUsd.toFixed(4)}${usage.measurement === "partial" ? " known; some child cost is unknown" : ""}`;
7490
7512
  const lines = [
7491
7513
  `### Kody usage - ${subject}`,
7492
7514
  "",
7493
- `- **Tokens:** ${tokens.input.toLocaleString()} input / ${tokens.cacheRead.toLocaleString()} cache-read / ${tokens.cacheCreate.toLocaleString()} cache-create / ${tokens.output.toLocaleString()} output / ${tokens.total.toLocaleString()} total`,
7515
+ tokenLine,
7494
7516
  `- **Agent work:** ${usage.agentRuns.toLocaleString()} runs / ${usage.turns.toLocaleString()} turns`,
7495
- `- **Provider-reported cost:** $${usage.costUsd.toFixed(4)}`,
7517
+ costLine,
7496
7518
  ""
7497
7519
  ];
7498
7520
  try {
@@ -23888,7 +23910,8 @@ async function runImplementation(profileName, input) {
23888
23910
  ctx.output.usage = createRunUsage(agentResult.tokens, agentResult.costUsd, {
23889
23911
  model: `${model.provider}/${model.model}`,
23890
23912
  turns: agentResult.turns,
23891
- modelUsage: agentResult.modelUsage
23913
+ modelUsage: agentResult.modelUsage,
23914
+ outcome: agentResult.outcome
23892
23915
  });
23893
23916
  emitEvent(input.cwd, {
23894
23917
  implementation: profileName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kody-ade/kody-engine",
3
- "version": "0.4.647",
3
+ "version": "0.4.648",
4
4
  "description": "kody — autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative implementation profiles.",
5
5
  "license": "MIT",
6
6
  "repository": {