tines 0.0.180 → 0.0.182

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 +145 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3529,10 +3529,21 @@ function runDurationLabel(run, now = Date.now()) {
3529
3529
  function runCostLabel(run) {
3530
3530
  const usage = run.usage;
3531
3531
  if (!usage) return null;
3532
- if (usage.cost_usd !== void 0) return `$${usage.cost_usd.toFixed(2)}`;
3533
- if (usage.cost_source === "none") return "unreported";
3532
+ if (usage.cost_usd !== void 0) {
3533
+ const dollars = usage.cost_usd === 0 ? "$0" : usage.cost_usd < 0.01 ? "<$0.01" : `$${usage.cost_usd.toFixed(2)}`;
3534
+ const source = usage.cost_source === "provider" ? "Reported" : usage.cost_source === "priced" ? "Estimated" : "Recorded";
3535
+ return `${dollars} ${source}`;
3536
+ }
3537
+ if (usage.pricing?.status === "unpriced") return "Unpriced";
3538
+ if (usage.cost_source === "none") return "Unreported";
3539
+ const measured = [
3540
+ usage.input_tokens,
3541
+ usage.output_tokens,
3542
+ usage.cache_read_tokens,
3543
+ usage.cache_write_tokens
3544
+ ].some((value) => value !== void 0);
3534
3545
  const tokens = (usage.input_tokens ?? 0) + (usage.output_tokens ?? 0) + (usage.cache_read_tokens ?? 0) + (usage.cache_write_tokens ?? 0);
3535
- return tokens > 0 ? `${tokens.toLocaleString()} tok` : null;
3546
+ return tokens > 0 ? `${tokens.toLocaleString()} tok` : measured ? "Unpriced" : null;
3536
3547
  }
3537
3548
  function utilizationLabel(quota, activeRuns, stateName = (id2) => id2) {
3538
3549
  if (quota.type === "global_cap") {
@@ -7599,7 +7610,16 @@ function validProviderSessionId(value) {
7599
7610
  return typeof value === "string" && value.length >= 1 && value.length <= 255 && Boolean(value.trim()) && !/[\x00-\x1f\x7f]/.test(value);
7600
7611
  }
7601
7612
  function copySummary(value) {
7602
- return { ...value, ...value.usage ? { usage: { ...value.usage } } : {} };
7613
+ return {
7614
+ ...value,
7615
+ ...value.usage ? { usage: { ...value.usage } } : {},
7616
+ ...value.pricingEvidence ? {
7617
+ pricingEvidence: {
7618
+ ...value.pricingEvidence,
7619
+ ...value.pricingEvidence.raw_usage ? { raw_usage: { ...value.pricingEvidence.raw_usage } } : {}
7620
+ }
7621
+ } : {}
7622
+ };
7603
7623
  }
7604
7624
 
7605
7625
  // src/daemon/claude-stream.ts
@@ -7800,8 +7820,24 @@ var CodexStreamRenderer = class {
7800
7820
  }
7801
7821
  emit;
7802
7822
  pending = "";
7803
- collected = {};
7823
+ collected = {
7824
+ pricingEvidence: {
7825
+ version: 1,
7826
+ harness: "codex",
7827
+ model: null,
7828
+ identity_source: "launch_argument",
7829
+ usage_scope: "thread_total",
7830
+ session_mode: "cold",
7831
+ normalization: "codex-jsonl-v1",
7832
+ model_rerouted: false,
7833
+ measurement_status: "missing",
7834
+ terminal_snapshots: 0
7835
+ }
7836
+ };
7804
7837
  finished = false;
7838
+ threadId;
7839
+ stickyStatus;
7840
+ awaitingTerminal = false;
7805
7841
  write(chunk) {
7806
7842
  this.pending += chunk;
7807
7843
  let nl = this.pending.indexOf("\n");
@@ -7839,24 +7875,75 @@ var CodexStreamRenderer = class {
7839
7875
  `);
7840
7876
  }
7841
7877
  collect(event) {
7842
- if (event.type === "thread.started" && !this.collected.providerSessionId && validProviderSessionId(event.thread_id)) {
7843
- this.collected.providerSessionId = event.thread_id;
7878
+ if (event.type === "thread.started" && validProviderSessionId(event.thread_id)) {
7879
+ if (this.threadId && this.threadId !== event.thread_id)
7880
+ this.stickyStatus = "multiple_threads";
7881
+ this.threadId ??= event.thread_id;
7882
+ this.collected.providerSessionId ??= event.thread_id;
7883
+ }
7884
+ if (event.type === "turn.started") {
7885
+ this.awaitingTerminal = true;
7886
+ this.updateEvidence("incomplete_attempt");
7887
+ return;
7888
+ }
7889
+ if (event.type === "item.completed") {
7890
+ const item = object2(event.item);
7891
+ if (item?.type === "error" && /^model rerouted:/.test(text3(item.message) ?? "")) {
7892
+ this.updateEvidence(void 0, true);
7893
+ }
7894
+ return;
7844
7895
  }
7845
7896
  if (event.type !== "turn.completed") return;
7897
+ this.awaitingTerminal = false;
7846
7898
  const raw = object2(event.usage);
7847
- if (!raw) return;
7848
- const totalInput = validMetric(raw.input_tokens) ? raw.input_tokens : void 0;
7849
- const rawCached = validMetric(raw.cached_input_tokens) ? raw.cached_input_tokens : void 0;
7850
- const output = validMetric(raw.output_tokens) ? raw.output_tokens : void 0;
7851
- if (totalInput === void 0 && rawCached === void 0 && output === void 0) return;
7899
+ const previous = this.collected.pricingEvidence?.raw_usage;
7900
+ const metric = (value) => Number.isSafeInteger(value) && value >= 0 ? value : void 0;
7901
+ const totalInput = metric(raw?.input_tokens);
7902
+ const rawCached = metric(raw?.cached_input_tokens);
7903
+ const rawWrite = metric(raw?.cache_write_input_tokens);
7904
+ const output = metric(raw?.output_tokens);
7905
+ const rawUsage = {
7906
+ ...totalInput !== void 0 ? { input_tokens: totalInput } : {},
7907
+ ...rawCached !== void 0 ? { cached_input_tokens: rawCached } : {},
7908
+ ...rawWrite !== void 0 ? { cache_write_input_tokens: rawWrite } : {},
7909
+ ...output !== void 0 ? { output_tokens: output } : {}
7910
+ };
7911
+ const supplied = raw ? ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens"].filter(
7912
+ (key) => raw[key] !== void 0
7913
+ ).length : 0;
7914
+ const complete = supplied === 4 && Object.keys(rawUsage).length === 4 && rawCached + rawWrite <= totalInput;
7915
+ const previousInput = previous ? metric(previous.input_tokens) !== void 0 && metric(previous.cached_input_tokens) !== void 0 && metric(previous.cache_write_input_tokens) !== void 0 ? previous.input_tokens - previous.cached_input_tokens - previous.cache_write_input_tokens : void 0 : void 0;
7916
+ const input = complete ? totalInput - rawCached - rawWrite : void 0;
7917
+ let status = complete ? "complete" : supplied < 4 ? "missing" : "invalid";
7918
+ if (complete && previous && ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens"].some(
7919
+ (key) => rawUsage[key] < previous[key]
7920
+ ) || input !== void 0 && previousInput !== void 0 && input < previousInput) {
7921
+ this.stickyStatus = "nonmonotonic";
7922
+ }
7923
+ status = this.stickyStatus ?? status;
7852
7924
  const usage = {};
7853
- if (totalInput !== void 0) {
7854
- const cached = rawCached === void 0 ? void 0 : Math.min(rawCached, totalInput);
7855
- usage.input_tokens = totalInput - (cached ?? 0);
7856
- if (cached !== void 0) usage.cache_read_tokens = cached;
7857
- } else if (rawCached !== void 0) usage.cache_read_tokens = rawCached;
7925
+ if (complete) usage.input_tokens = input;
7926
+ if (rawCached !== void 0) usage.cache_read_tokens = rawCached;
7927
+ if (rawWrite !== void 0) usage.cache_write_tokens = rawWrite;
7858
7928
  if (output !== void 0) usage.output_tokens = output;
7859
7929
  this.collected.usage = usage;
7930
+ this.updateEvidence(status, void 0, rawUsage);
7931
+ }
7932
+ updateEvidence(status, rerouted, rawUsage) {
7933
+ const old = this.collected.pricingEvidence;
7934
+ this.collected.pricingEvidence = {
7935
+ version: 1,
7936
+ harness: "codex",
7937
+ model: null,
7938
+ identity_source: "launch_argument",
7939
+ usage_scope: "thread_total",
7940
+ session_mode: "cold",
7941
+ normalization: "codex-jsonl-v1",
7942
+ ...rawUsage ? { raw_usage: rawUsage } : old?.raw_usage ? { raw_usage: old.raw_usage } : {},
7943
+ model_rerouted: rerouted || old?.model_rerouted || false,
7944
+ measurement_status: this.stickyStatus ?? status ?? old?.measurement_status ?? (this.awaitingTerminal ? "incomplete_attempt" : "missing"),
7945
+ terminal_snapshots: (old?.terminal_snapshots ?? 0) + (rawUsage ? 1 : 0)
7946
+ };
7860
7947
  }
7861
7948
  };
7862
7949
 
@@ -8739,6 +8826,14 @@ async function runDaemon(opts) {
8739
8826
  ...error ? { error } : {},
8740
8827
  ...judgment,
8741
8828
  usage: summary?.usage ?? { cost_source: "none" },
8829
+ ...summary?.pricingEvidence ? {
8830
+ pricing_evidence: {
8831
+ ...summary.pricingEvidence,
8832
+ model: run.pricingModel ?? null,
8833
+ session_mode: run.pricingSessionMode ?? "cold",
8834
+ daemon_version: DAEMON_VERSION
8835
+ }
8836
+ } : {},
8742
8837
  ...summary?.providerSessionId ? { provider_session_id: summary.providerSessionId } : {},
8743
8838
  ...summary?.numTurns !== void 0 ? { turn_count: summary.numTurns } : {},
8744
8839
  // The whole conversation's turns, which for a resumed run is
@@ -8916,6 +9011,10 @@ async function runDaemon(opts) {
8916
9011
  { harness: opts.harness, command: opts.command },
8917
9012
  harnessInput
8918
9013
  );
9014
+ if (opts.harness === "codex") {
9015
+ run.pricingModel = harnessInput.model;
9016
+ run.pricingSessionMode = resume ? "resumed" : "cold";
9017
+ }
8919
9018
  run.batcher.append(
8920
9019
  formatLaunchBanner(invocation, harnessInput, {
8921
9020
  harness: opts.harness,
@@ -9584,16 +9683,37 @@ function register8(program3) {
9584
9683
  );
9585
9684
  if (run.usage) {
9586
9685
  const u = run.usage;
9587
- const parts = [];
9588
- if (u.input_tokens !== void 0 || u.output_tokens !== void 0) {
9589
- parts.push(
9590
- `${(u.input_tokens ?? 0).toLocaleString()} in / ${(u.output_tokens ?? 0).toLocaleString()} out tokens`
9686
+ const costLabel = runCostLabel(run);
9687
+ const metric = (value) => value === void 0 ? "unknown" : value.toLocaleString();
9688
+ console.log(
9689
+ `usage: input ${metric(u.input_tokens)} cache-read ${metric(u.cache_read_tokens)} cache-write ${metric(u.cache_write_tokens)} output ${metric(u.output_tokens)}`
9690
+ );
9691
+ if (u.cost_usd !== void 0)
9692
+ console.log(
9693
+ `cost: ${runCostLabel(run)}${u.cost_source === void 0 ? " \xB7 source unavailable" : ""}`
9694
+ );
9695
+ const pricing = u.pricing;
9696
+ if (pricing?.status === "provider_authoritative")
9697
+ console.log("cost provenance: provider-reported amount is authoritative");
9698
+ if (pricing?.status === "unpriced") console.log(`cost: Unpriced (${pricing.reason})`);
9699
+ else if (u.cost_usd === void 0 && costLabel === "Unpriced")
9700
+ console.log("cost: Unpriced");
9701
+ if (pricing?.status === "calculated") {
9702
+ const b = pricing.basis;
9703
+ console.log(`cost provenance: Estimated standard API list-price equivalent`);
9704
+ console.log(` model: ${b.model} (${b.model_identity})`);
9705
+ console.log(
9706
+ ` rate: ${b.rate_id} v${b.rate_version}; adopted ${new Date(b.rate_adopted_at).toISOString()}`
9707
+ );
9708
+ console.log(
9709
+ ` source: ${b.source_url} (checked ${b.source_checked_at}${b.source_effective_at ? `; effective ${b.source_effective_at}` : ""})`
9710
+ );
9711
+ console.log(
9712
+ ` rates USD/1M: input ${b.rates.input_tokens} cache-read ${b.rates.cache_read_tokens} cache-write ${b.rates.cache_write_tokens ?? "unpublished"} output ${b.rates.output_tokens}`
9591
9713
  );
9714
+ console.log(` exact estimated USD: ${b.cost_usd_exact}`);
9715
+ console.log(" Standard API list-price estimate; not an invoice or subscription usage.");
9592
9716
  }
9593
- if (u.cost_usd !== void 0) parts.push(`$${u.cost_usd.toFixed(2)}`);
9594
- if (u.cost_source)
9595
- parts.push(`(${u.cost_source === "provider" ? "provider-reported" : u.cost_source})`);
9596
- if (parts.length > 0) console.log(`usage: ${parts.join(" ")}`);
9597
9717
  }
9598
9718
  if (run.provider_session_id) console.log(`provider session: ${run.provider_session_id}`);
9599
9719
  if (run.provider_url) console.log(`provider console: ${run.provider_url}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tines",
3
- "version": "0.0.180",
3
+ "version": "0.0.182",
4
4
  "description": "CLI for Tines, an orchestration layer for AI agents",
5
5
  "repository": {
6
6
  "type": "git",