@autohq/cli 0.1.230 → 0.1.231

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.
@@ -23340,7 +23340,7 @@ Object.assign(lookup, {
23340
23340
  // package.json
23341
23341
  var package_default = {
23342
23342
  name: "@autohq/cli",
23343
- version: "0.1.230",
23343
+ version: "0.1.231",
23344
23344
  license: "SEE LICENSE IN README.md",
23345
23345
  publishConfig: {
23346
23346
  access: "public"
@@ -24885,6 +24885,21 @@ var CodexTurnEnvelopeSchema = external_exports.object({
24885
24885
  error: external_exports.object({ message: external_exports.string() }).passthrough().nullish()
24886
24886
  }).passthrough()
24887
24887
  }).passthrough();
24888
+ var CodexTokenUsageSchema = external_exports.object({
24889
+ totalTokens: external_exports.number().int().nonnegative(),
24890
+ inputTokens: external_exports.number().int().nonnegative(),
24891
+ cachedInputTokens: external_exports.number().int().nonnegative(),
24892
+ outputTokens: external_exports.number().int().nonnegative(),
24893
+ reasoningOutputTokens: external_exports.number().int().nonnegative()
24894
+ }).passthrough();
24895
+ var CodexTokenUsageEnvelopeSchema = external_exports.object({
24896
+ threadId: external_exports.string(),
24897
+ turnId: external_exports.string(),
24898
+ tokenUsage: external_exports.object({
24899
+ total: CodexTokenUsageSchema,
24900
+ last: CodexTokenUsageSchema
24901
+ }).passthrough()
24902
+ }).passthrough();
24888
24903
  var CodexFrameSchema = external_exports.object({
24889
24904
  id: CodexRequestIdSchema.optional(),
24890
24905
  method: external_exports.string().optional(),
@@ -25024,6 +25039,16 @@ function parseNotification(method, params) {
25024
25039
  item: parsed.data.item
25025
25040
  };
25026
25041
  }
25042
+ case "thread/tokenUsage/updated": {
25043
+ const parsed = CodexTokenUsageEnvelopeSchema.safeParse(params);
25044
+ return parsed.success ? {
25045
+ type: "tokenUsage",
25046
+ threadId: parsed.data.threadId,
25047
+ turnId: parsed.data.turnId,
25048
+ total: parsed.data.tokenUsage.total,
25049
+ last: parsed.data.tokenUsage.last
25050
+ } : null;
25051
+ }
25027
25052
  case "item/agentMessage/delta": {
25028
25053
  const parsed = external_exports.object({ itemId: external_exports.string(), delta: external_exports.string() }).passthrough().safeParse(params);
25029
25054
  return parsed.success ? {
@@ -49588,6 +49613,40 @@ function errorMessage2(error51) {
49588
49613
  return error51 instanceof Error ? error51.message : String(error51);
49589
49614
  }
49590
49615
 
49616
+ // src/commands/agent-bridge/harness/codex/usage.ts
49617
+ function addCodexUsage(accumulated, next) {
49618
+ if (!accumulated) {
49619
+ return next;
49620
+ }
49621
+ return {
49622
+ totalTokens: accumulated.totalTokens + next.totalTokens,
49623
+ inputTokens: accumulated.inputTokens + next.inputTokens,
49624
+ cachedInputTokens: accumulated.cachedInputTokens + next.cachedInputTokens,
49625
+ outputTokens: accumulated.outputTokens + next.outputTokens,
49626
+ reasoningOutputTokens: accumulated.reasoningOutputTokens + next.reasoningOutputTokens
49627
+ };
49628
+ }
49629
+ function codexTurnUsage(usage) {
49630
+ if (usage.totalTokens === 0) {
49631
+ return void 0;
49632
+ }
49633
+ const cacheReadTokens = usage.cachedInputTokens;
49634
+ const inputTokens = Math.max(0, usage.inputTokens - cacheReadTokens);
49635
+ return {
49636
+ harness: "codex",
49637
+ models: [
49638
+ {
49639
+ model: CODEX_DEFAULT_MODEL,
49640
+ inputTokens,
49641
+ outputTokens: usage.outputTokens,
49642
+ cacheCreationTokens: 0,
49643
+ cacheReadTokens,
49644
+ providerCostUsd: null
49645
+ }
49646
+ ]
49647
+ };
49648
+ }
49649
+
49591
49650
  // src/commands/agent-bridge/harness/codex/index.ts
49592
49651
  function createCodexCommandHandler(input) {
49593
49652
  return new CodexCommandHandler({
@@ -49609,6 +49668,11 @@ var CodexCommandHandler = class {
49609
49668
  pendingApprovals = /* @__PURE__ */ new Map();
49610
49669
  outputBuffer;
49611
49670
  projector = new CodexProjector();
49671
+ // The active turn's running usage sum. codex emits one
49672
+ // `thread/tokenUsage/updated` per model request; their `last` breakdowns are
49673
+ // summed here and ride the turn-completion entry. Reset at each turn boundary
49674
+ // so usage never leaks across turns.
49675
+ turnTokenUsage = null;
49612
49676
  // ---------------------------------------------------------------------------
49613
49677
  // Lifecycle (public API)
49614
49678
  // ---------------------------------------------------------------------------
@@ -49625,6 +49689,7 @@ var CodexCommandHandler = class {
49625
49689
  this.session?.close();
49626
49690
  this.session = null;
49627
49691
  this.pendingApprovals.clear();
49692
+ this.turnTokenUsage = null;
49628
49693
  }
49629
49694
  async handleCommand(rawDelivery) {
49630
49695
  const delivery = RuntimeBridgeCommandDeliverySchema.parse(rawDelivery);
@@ -49750,8 +49815,25 @@ var CodexCommandHandler = class {
49750
49815
  if (!activeContext) {
49751
49816
  return;
49752
49817
  }
49818
+ if (notification.type === "tokenUsage") {
49819
+ this.turnTokenUsage = addCodexUsage(
49820
+ this.turnTokenUsage,
49821
+ notification.last
49822
+ );
49823
+ return;
49824
+ }
49825
+ if (notification.type === "turnStarted") {
49826
+ this.turnTokenUsage = null;
49827
+ }
49828
+ const turnUsage = notification.type === "turnCompleted" && this.turnTokenUsage ? codexTurnUsage(this.turnTokenUsage) : void 0;
49753
49829
  for (const projection of this.projector.project(notification)) {
49754
- await this.emit(activeContext, projection);
49830
+ await this.emit(
49831
+ activeContext,
49832
+ attachTurnUsage(notification, projection, turnUsage)
49833
+ );
49834
+ }
49835
+ if (notification.type === "turnCompleted") {
49836
+ this.turnTokenUsage = null;
49755
49837
  }
49756
49838
  }
49757
49839
  async handleServerRequest(request) {
@@ -49869,6 +49951,15 @@ function deliveryMode2(delivery) {
49869
49951
  function errorMessage3(error51) {
49870
49952
  return error51 instanceof Error ? error51.message : String(error51);
49871
49953
  }
49954
+ function attachTurnUsage(notification, projection, turnUsage) {
49955
+ if (notification.type !== "turnCompleted" || projection.type !== "entry" || !turnUsage) {
49956
+ return projection;
49957
+ }
49958
+ return {
49959
+ type: "entry",
49960
+ entry: { ...projection.entry, usage: turnUsage }
49961
+ };
49962
+ }
49872
49963
 
49873
49964
  // src/commands/agent-bridge/harness/index.ts
49874
49965
  async function runAgentBridgeHarness(options) {
package/dist/index.js CHANGED
@@ -16385,6 +16385,16 @@ function parseNotification(method, params) {
16385
16385
  item: parsed.data.item
16386
16386
  };
16387
16387
  }
16388
+ case "thread/tokenUsage/updated": {
16389
+ const parsed = CodexTokenUsageEnvelopeSchema.safeParse(params);
16390
+ return parsed.success ? {
16391
+ type: "tokenUsage",
16392
+ threadId: parsed.data.threadId,
16393
+ turnId: parsed.data.turnId,
16394
+ total: parsed.data.tokenUsage.total,
16395
+ last: parsed.data.tokenUsage.last
16396
+ } : null;
16397
+ }
16388
16398
  case "item/agentMessage/delta": {
16389
16399
  const parsed = external_exports.object({ itemId: external_exports.string(), delta: external_exports.string() }).passthrough().safeParse(params);
16390
16400
  return parsed.success ? {
@@ -16497,7 +16507,7 @@ function textContent2(text) {
16497
16507
  function isFailedStatus(status) {
16498
16508
  return status === "failed" || status === "declined";
16499
16509
  }
16500
- var CodexRequestIdSchema, CodexTurnStatusSchema, CodexUserMessageItemSchema, CodexAgentMessageItemSchema, CodexReasoningItemSchema, CodexCommandExecutionItemSchema, CodexFileChangeItemSchema, CodexMcpToolCallItemSchema, CodexItemSchema, OptionalCodexItemSchema, CodexItemEnvelopeSchema, CodexTurnEnvelopeSchema, CodexFrameSchema, APPROVE_OPTION_LABEL, DECLINE_OPTION_LABEL;
16510
+ var CodexRequestIdSchema, CodexTurnStatusSchema, CodexUserMessageItemSchema, CodexAgentMessageItemSchema, CodexReasoningItemSchema, CodexCommandExecutionItemSchema, CodexFileChangeItemSchema, CodexMcpToolCallItemSchema, CodexItemSchema, OptionalCodexItemSchema, CodexItemEnvelopeSchema, CodexTurnEnvelopeSchema, CodexTokenUsageSchema, CodexTokenUsageEnvelopeSchema, CodexFrameSchema, APPROVE_OPTION_LABEL, DECLINE_OPTION_LABEL;
16501
16511
  var init_codex = __esm({
16502
16512
  "../../packages/schemas/src/codex.ts"() {
16503
16513
  "use strict";
@@ -16571,6 +16581,21 @@ var init_codex = __esm({
16571
16581
  error: external_exports.object({ message: external_exports.string() }).passthrough().nullish()
16572
16582
  }).passthrough()
16573
16583
  }).passthrough();
16584
+ CodexTokenUsageSchema = external_exports.object({
16585
+ totalTokens: external_exports.number().int().nonnegative(),
16586
+ inputTokens: external_exports.number().int().nonnegative(),
16587
+ cachedInputTokens: external_exports.number().int().nonnegative(),
16588
+ outputTokens: external_exports.number().int().nonnegative(),
16589
+ reasoningOutputTokens: external_exports.number().int().nonnegative()
16590
+ }).passthrough();
16591
+ CodexTokenUsageEnvelopeSchema = external_exports.object({
16592
+ threadId: external_exports.string(),
16593
+ turnId: external_exports.string(),
16594
+ tokenUsage: external_exports.object({
16595
+ total: CodexTokenUsageSchema,
16596
+ last: CodexTokenUsageSchema
16597
+ }).passthrough()
16598
+ }).passthrough();
16574
16599
  CodexFrameSchema = external_exports.object({
16575
16600
  id: CodexRequestIdSchema.optional(),
16576
16601
  method: external_exports.string().optional(),
@@ -22296,7 +22321,7 @@ var init_package = __esm({
22296
22321
  "package.json"() {
22297
22322
  package_default = {
22298
22323
  name: "@autohq/cli",
22299
- version: "0.1.230",
22324
+ version: "0.1.231",
22300
22325
  license: "SEE LICENSE IN README.md",
22301
22326
  publishConfig: {
22302
22327
  access: "public"
@@ -34741,6 +34766,40 @@ function errorMessage2(error51) {
34741
34766
  return error51 instanceof Error ? error51.message : String(error51);
34742
34767
  }
34743
34768
 
34769
+ // src/commands/agent-bridge/harness/codex/usage.ts
34770
+ function addCodexUsage(accumulated, next) {
34771
+ if (!accumulated) {
34772
+ return next;
34773
+ }
34774
+ return {
34775
+ totalTokens: accumulated.totalTokens + next.totalTokens,
34776
+ inputTokens: accumulated.inputTokens + next.inputTokens,
34777
+ cachedInputTokens: accumulated.cachedInputTokens + next.cachedInputTokens,
34778
+ outputTokens: accumulated.outputTokens + next.outputTokens,
34779
+ reasoningOutputTokens: accumulated.reasoningOutputTokens + next.reasoningOutputTokens
34780
+ };
34781
+ }
34782
+ function codexTurnUsage(usage) {
34783
+ if (usage.totalTokens === 0) {
34784
+ return void 0;
34785
+ }
34786
+ const cacheReadTokens = usage.cachedInputTokens;
34787
+ const inputTokens = Math.max(0, usage.inputTokens - cacheReadTokens);
34788
+ return {
34789
+ harness: "codex",
34790
+ models: [
34791
+ {
34792
+ model: CODEX_DEFAULT_MODEL,
34793
+ inputTokens,
34794
+ outputTokens: usage.outputTokens,
34795
+ cacheCreationTokens: 0,
34796
+ cacheReadTokens,
34797
+ providerCostUsd: null
34798
+ }
34799
+ ]
34800
+ };
34801
+ }
34802
+
34744
34803
  // src/commands/agent-bridge/harness/codex/index.ts
34745
34804
  function createCodexCommandHandler(input) {
34746
34805
  return new CodexCommandHandler({
@@ -34762,6 +34821,11 @@ var CodexCommandHandler = class {
34762
34821
  pendingApprovals = /* @__PURE__ */ new Map();
34763
34822
  outputBuffer;
34764
34823
  projector = new CodexProjector();
34824
+ // The active turn's running usage sum. codex emits one
34825
+ // `thread/tokenUsage/updated` per model request; their `last` breakdowns are
34826
+ // summed here and ride the turn-completion entry. Reset at each turn boundary
34827
+ // so usage never leaks across turns.
34828
+ turnTokenUsage = null;
34765
34829
  // ---------------------------------------------------------------------------
34766
34830
  // Lifecycle (public API)
34767
34831
  // ---------------------------------------------------------------------------
@@ -34778,6 +34842,7 @@ var CodexCommandHandler = class {
34778
34842
  this.session?.close();
34779
34843
  this.session = null;
34780
34844
  this.pendingApprovals.clear();
34845
+ this.turnTokenUsage = null;
34781
34846
  }
34782
34847
  async handleCommand(rawDelivery) {
34783
34848
  const delivery = RuntimeBridgeCommandDeliverySchema.parse(rawDelivery);
@@ -34903,8 +34968,25 @@ var CodexCommandHandler = class {
34903
34968
  if (!activeContext) {
34904
34969
  return;
34905
34970
  }
34971
+ if (notification.type === "tokenUsage") {
34972
+ this.turnTokenUsage = addCodexUsage(
34973
+ this.turnTokenUsage,
34974
+ notification.last
34975
+ );
34976
+ return;
34977
+ }
34978
+ if (notification.type === "turnStarted") {
34979
+ this.turnTokenUsage = null;
34980
+ }
34981
+ const turnUsage = notification.type === "turnCompleted" && this.turnTokenUsage ? codexTurnUsage(this.turnTokenUsage) : void 0;
34906
34982
  for (const projection of this.projector.project(notification)) {
34907
- await this.emit(activeContext, projection);
34983
+ await this.emit(
34984
+ activeContext,
34985
+ attachTurnUsage(notification, projection, turnUsage)
34986
+ );
34987
+ }
34988
+ if (notification.type === "turnCompleted") {
34989
+ this.turnTokenUsage = null;
34908
34990
  }
34909
34991
  }
34910
34992
  async handleServerRequest(request) {
@@ -35022,6 +35104,15 @@ function deliveryMode2(delivery) {
35022
35104
  function errorMessage3(error51) {
35023
35105
  return error51 instanceof Error ? error51.message : String(error51);
35024
35106
  }
35107
+ function attachTurnUsage(notification, projection, turnUsage) {
35108
+ if (notification.type !== "turnCompleted" || projection.type !== "entry" || !turnUsage) {
35109
+ return projection;
35110
+ }
35111
+ return {
35112
+ type: "entry",
35113
+ entry: { ...projection.entry, usage: turnUsage }
35114
+ };
35115
+ }
35025
35116
 
35026
35117
  // src/commands/agent-bridge/harness/index.ts
35027
35118
  async function runAgentBridgeHarness(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autohq/cli",
3
- "version": "0.1.230",
3
+ "version": "0.1.231",
4
4
  "license": "SEE LICENSE IN README.md",
5
5
  "publishConfig": {
6
6
  "access": "public"