johns-harness 2026.10.21 โ†’ 2026.10.23

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 (73) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +3 -0
  3. package/dist/anthropic-auth-runtime.js +62 -0
  4. package/dist/auth-profiles-5CHn7vq1.js +9 -4
  5. package/dist/compact-B247y5Qt.js +41 -74
  6. package/dist/config-koj5M_EO.js +4 -2
  7. package/dist/daemon-cli.js +4 -2
  8. package/dist/model-selection-BGlGpPgM.js +9 -4
  9. package/dist/model-selection-BU6wl1le.js +9 -4
  10. package/dist/model-selection-L7RMwsG-.js +9 -4
  11. package/dist/pi-embedded-C6ITuRXf.js +42 -89
  12. package/dist/pi-embedded-DoQsYfIY.js +42 -89
  13. package/dist/plugin-sdk/bluebubbles.js +2 -1
  14. package/dist/plugin-sdk/config/types.models.d.ts +1 -0
  15. package/dist/plugin-sdk/config/zod-schema.core.d.ts +3 -0
  16. package/dist/plugin-sdk/config/zod-schema.d.ts +1 -0
  17. package/dist/plugin-sdk/config-4Fgm-yEH.js +9 -4
  18. package/dist/plugin-sdk/config-Di-lyCdh.js +9 -4
  19. package/dist/plugin-sdk/discord.js +4 -2
  20. package/dist/plugin-sdk/dispatch-BP0viZiL.js +42 -89
  21. package/dist/plugin-sdk/dispatch-CQsjmw7g.js +42 -89
  22. package/dist/plugin-sdk/dispatch-Cerq29sy.js +42 -89
  23. package/dist/plugin-sdk/dispatch-Cndjtt0g.js +42 -89
  24. package/dist/plugin-sdk/dispatch-UogiJYul.js +42 -89
  25. package/dist/plugin-sdk/feishu.js +2 -1
  26. package/dist/plugin-sdk/googlechat.js +2 -1
  27. package/dist/plugin-sdk/imessage.js +2 -1
  28. package/dist/plugin-sdk/model-auth-CX9cPHdC.js +9 -4
  29. package/dist/plugin-sdk/model-auth-Ciehz0x5.js +9 -4
  30. package/dist/plugin-sdk/model-auth-DVyo6JSX.js +9 -4
  31. package/dist/plugin-sdk/model-auth-kiHYHGrs.js +9 -4
  32. package/dist/plugin-sdk/model-selection-Dbj4jDYM.js +8 -3
  33. package/dist/plugin-sdk/nostr.js +2 -1
  34. package/dist/plugin-sdk/reply-DbZnH8-h.js +42 -89
  35. package/dist/plugin-sdk/signal.js +2 -1
  36. package/dist/plugin-sdk/slack.js +2 -1
  37. package/dist/plugin-sdk/telegram.js +2 -1
  38. package/dist/plugin-sdk/tlon.js +2 -1
  39. package/dist/plugin-sdk/twitch.js +2 -1
  40. package/dist/plugin-sdk/utils/usage-format.d.ts +1 -0
  41. package/dist/plugin-sdk/voice-call.js +2 -1
  42. package/dist/plugin-sdk/zalo.js +2 -1
  43. package/dist/plugin-sdk/zalouser.js +2 -1
  44. package/dist/reply-C5LKjXcC.js +41 -74
  45. package/dist/session-cost-usage-5CCZbVhO.js +4 -19
  46. package/dist/session-cost-usage-CkCo2kVx.js +4 -19
  47. package/dist/usage-billing.js +88 -0
  48. package/dist/usage-format-CNGi1eHQ.js +6 -11
  49. package/dist/usage-format-CvaU1ntA.js +6 -11
  50. package/docs/PATCHES.md +54 -1
  51. package/docs/providers/anthropic.md +23 -2
  52. package/docs/reference/token-use.md +11 -1
  53. package/models/models.json +33 -33
  54. package/node_modules/@mariozechner/pi-ai/dist/models.d.ts +1 -0
  55. package/node_modules/@mariozechner/pi-ai/dist/models.generated.js +32 -32
  56. package/node_modules/@mariozechner/pi-ai/dist/models.js +16 -5
  57. package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +15 -0
  58. package/node_modules/@mariozechner/pi-ai/dist/providers/google-vertex.js +1 -1
  59. package/node_modules/@mariozechner/pi-ai/dist/providers/google.js +1 -1
  60. package/node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js +5 -5
  61. package/node_modules/@mariozechner/pi-ai/dist/types.d.ts +3 -0
  62. package/node_modules/@mariozechner/pi-coding-agent/dist/core/model-registry.js +3 -0
  63. package/package.json +1 -1
  64. package/scripts/models-sync.mjs +1 -0
  65. package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.d.ts +25 -0
  66. package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.generated.js +32 -32
  67. package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.js +16 -5
  68. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/anthropic.js +15 -0
  69. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/google-vertex.js +371 -0
  70. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/google.js +1 -1
  71. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/openai-completions.js +5 -5
  72. package/vendor/patched-deps/@mariozechner/pi-ai/dist/types.d.ts +282 -0
  73. package/vendor/patched-deps/@mariozechner/pi-coding-agent/dist/core/model-registry.js +3 -0
@@ -1,3 +1,4 @@
1
+ import { readCurrentAnthropicAuth } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
1
2
  import { claudeSubscriptionOrder } from "../subscription-login.js"; // JOHNNESS_PATCH_SUBSCRIPTION_LOGIN_86
2
3
  // JOHNNESS_PATCH_CATALOG_REFRESH_65
3
4
  import { mergeShippedCatalog65 } from "../catalog-refresh.js";
@@ -2156,8 +2157,10 @@ function codexOwnershipContext(agentDir) {
2156
2157
  log: (event) => log$8.info("Codex OAuth ownership", event)
2157
2158
  };
2158
2159
  }
2160
+ // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
2159
2161
  function readCodexOwnedAuthStore(agentDir, store) {
2160
- return readManagedCodexStore({ ...codexOwnershipContext(agentDir), store });
2162
+ const context = codexOwnershipContext(agentDir);
2163
+ return readCurrentAnthropicAuth({ ...context, store: readManagedCodexStore({ ...context, store }) });
2161
2164
  }
2162
2165
  function sanitizeAuthProfileCredential(credential) {
2163
2166
  const sanitized = { ...credential };
@@ -3756,7 +3759,7 @@ async function refreshUnmanagedOAuthTokenWithLock(params) {
3756
3759
  const authPath = resolveAuthStorePath(params.agentDir);
3757
3760
  fs.mkdirSync(path.dirname(authPath), { recursive: true, mode: 448 });
3758
3761
  return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
3759
- const store = ensureAuthProfileStore(params.agentDir);
3762
+ const store = loadAuthProfileStoreForRuntime(params.agentDir, { allowKeychainPrompt: false }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92: reread under lock
3760
3763
  const cred = store.profiles[params.profileId];
3761
3764
  if (cred?.provider === "openai-codex") throw new Error("Auth profile changed to Codex; resolve again through its owner");
3762
3765
  if (!cred || cred.type !== "oauth") return null;
@@ -8130,7 +8133,8 @@ function resolveModelCost(raw) {
8130
8133
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
8131
8134
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
8132
8135
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
8133
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
8136
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
8137
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
8134
8138
  };
8135
8139
  }
8136
8140
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -13837,7 +13841,8 @@ const ModelDefinitionSchema = z.object({
13837
13841
  input: z.number().optional(),
13838
13842
  output: z.number().optional(),
13839
13843
  cacheRead: z.number().optional(),
13840
- cacheWrite: z.number().optional()
13844
+ cacheWrite: z.number().optional(),
13845
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
13841
13846
  }).strict().optional(),
13842
13847
  contextWindow: z.number().positive().optional(),
13843
13848
  maxTokens: z.number().positive().optional(),
@@ -5255,7 +5255,8 @@ function resolveModelCost(raw) {
5255
5255
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
5256
5256
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
5257
5257
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
5258
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
5258
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
5259
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
5259
5260
  };
5260
5261
  }
5261
5262
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -9153,7 +9154,8 @@ const ModelDefinitionSchema = z.object({
9153
9154
  input: z.number().optional(),
9154
9155
  output: z.number().optional(),
9155
9156
  cacheRead: z.number().optional(),
9156
- cacheWrite: z.number().optional()
9157
+ cacheWrite: z.number().optional(),
9158
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
9157
9159
  }).strict().optional(),
9158
9160
  contextWindow: z.number().positive().optional(),
9159
9161
  maxTokens: z.number().positive().optional(),
@@ -1,3 +1,5 @@
1
+ import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
2
+ import { normalizeBillingUsage, readLatestBillingUsage, formatBillingCost } from "../usage-billing.js"; // JOHNNESS_PATCH_USAGE_BILLING_91 dist/plugin-sdk/dispatch-BP0viZiL.js
1
3
  import { importOptional66 } from "../optional-module.js";
2
4
  const JOHNNESS_PATCH_SLIM_TREE_66 = true;
3
5
  import { createImageGenerateTool } from "../image-generate.js";
@@ -24310,7 +24312,7 @@ function resolveModelAuthLabel(params) {
24310
24312
  });
24311
24313
  if (profile.type === "oauth") return `oauth${label ? ` (${label})` : ""}`;
24312
24314
  if (profile.type === "token") return `token${label ? ` (${label})` : ""}`;
24313
- return `api-key${label ? ` (${label})` : ""}`;
24315
+ return `api-key${label ? ` (${label})` : ""}${formatAuthProfileFallback(params.sessionEntry, profileId)}`;
24314
24316
  }
24315
24317
  const envKey = resolveEnvApiKey(providerKey);
24316
24318
  if (envKey?.apiKey) {
@@ -33961,21 +33963,7 @@ function hasNonzeroUsage(usage) {
33961
33963
  ].some((v) => typeof v === "number" && Number.isFinite(v) && v > 0);
33962
33964
  }
33963
33965
  function normalizeUsage(raw) {
33964
- if (!raw) return;
33965
- const rawInput = asFiniteNumber(raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens);
33966
- const input = rawInput !== void 0 && rawInput < 0 ? 0 : rawInput;
33967
- const output = asFiniteNumber(raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens);
33968
- const cacheRead = asFiniteNumber(raw.cacheRead ?? raw.cache_read ?? raw.cache_read_input_tokens ?? raw.cached_tokens ?? raw.prompt_tokens_details?.cached_tokens);
33969
- const cacheWrite = asFiniteNumber(raw.cacheWrite ?? raw.cache_write ?? raw.cache_creation_input_tokens);
33970
- const total = asFiniteNumber(raw.total ?? raw.totalTokens ?? raw.total_tokens);
33971
- if (input === void 0 && output === void 0 && cacheRead === void 0 && cacheWrite === void 0 && total === void 0) return;
33972
- return {
33973
- input,
33974
- output,
33975
- cacheRead,
33976
- cacheWrite,
33977
- total
33978
- };
33966
+ return normalizeBillingUsage(raw);
33979
33967
  }
33980
33968
  function derivePromptTokens(usage) {
33981
33969
  if (!usage) return;
@@ -34029,6 +34017,7 @@ async function updateSessionStoreAfterAgentRun(params) {
34029
34017
  model: modelUsed
34030
34018
  });
34031
34019
  if (result.meta.agentMeta?.authProfileId) next.authProfileServed = result.meta.agentMeta.authProfileId; // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
34020
+ next.authProfileFallback = result.meta.agentMeta?.authProfileFallback ?? null; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
34032
34021
  if (isCliProvider(providerUsed, cfg)) {
34033
34022
  const cliSessionId = result.meta.agentMeta?.sessionId?.trim();
34034
34023
  if (cliSessionId) setCliSessionId(next, providerUsed, cliSessionId);
@@ -48811,62 +48800,19 @@ const readUsageFromSessionLog = (sessionId, sessionEntry, agentId, sessionKey, s
48811
48800
  } catch {
48812
48801
  return;
48813
48802
  }
48814
- if (!fs.existsSync(logPath)) return;
48815
- try {
48816
- const TAIL_BYTES = 8192;
48817
- const stat = fs.statSync(logPath);
48818
- const offset = Math.max(0, stat.size - TAIL_BYTES);
48819
- const buf = Buffer.alloc(Math.min(TAIL_BYTES, stat.size));
48820
- const fd = fs.openSync(logPath, "r");
48821
- try {
48822
- fs.readSync(fd, buf, 0, buf.length, offset);
48823
- } finally {
48824
- fs.closeSync(fd);
48825
- }
48826
- const tail = buf.toString("utf-8");
48827
- const lines = (offset > 0 ? tail.slice(tail.indexOf("\n") + 1) : tail).split(/\n+/);
48828
- let input = 0;
48829
- let output = 0;
48830
- let promptTokens = 0;
48831
- let model;
48832
- let lastUsage;
48833
- for (const line of lines) {
48834
- if (!line.trim()) continue;
48835
- try {
48836
- const parsed = JSON.parse(line);
48837
- const usage = normalizeUsage(parsed.message?.usage ?? parsed.usage);
48838
- if (usage) lastUsage = usage;
48839
- model = parsed.message?.model ?? parsed.model ?? model;
48840
- } catch {}
48841
- }
48842
- if (!lastUsage) return;
48843
- input = lastUsage.input ?? 0;
48844
- output = lastUsage.output ?? 0;
48845
- promptTokens = derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
48846
- const total = lastUsage.total ?? promptTokens + output;
48847
- if (promptTokens === 0 && total === 0) return;
48848
- return {
48849
- input,
48850
- output,
48851
- promptTokens,
48852
- total,
48853
- model
48854
- };
48855
- } catch {
48856
- return;
48857
- }
48803
+ return readLatestBillingUsage(logPath);
48858
48804
  };
48859
- const formatUsagePair = (input, output) => {
48860
- if (input == null && output == null) return null;
48861
- return `๐Ÿงฎ Tokens: ${typeof input === "number" ? formatTokenCount$1(input) : "?"} in / ${typeof output === "number" ? formatTokenCount$1(output) : "?"} out`;
48805
+ const formatUsagePair = (input, output, cacheRead, cacheWrite) => {
48806
+ if (input == null && output == null && cacheRead == null && cacheWrite == null) return null;
48807
+ const count = value => typeof value === "number" ? value.toLocaleString("en-US") : "?";
48808
+ return `๐Ÿงฎ Tokens: ${count((input ?? 0) + (cacheWrite ?? 0))} new in / ${count(cacheRead ?? 0)} cached / ${count(output)} out (last API call)`;
48862
48809
  };
48863
- const formatCacheLine = (input, cacheRead, cacheWrite) => {
48810
+ const formatCacheLine = (input, cacheRead, cacheWrite, usage) => {
48864
48811
  if (!cacheRead && !cacheWrite) return null;
48865
- if ((typeof cacheRead !== "number" || cacheRead <= 0) && (typeof cacheWrite !== "number" || cacheWrite <= 0)) return null;
48866
- const cachedLabel = typeof cacheRead === "number" ? formatTokenCount$1(cacheRead) : "0";
48867
- const newLabel = typeof cacheWrite === "number" ? formatTokenCount$1(cacheWrite) : "0";
48868
- const totalInput = (typeof cacheRead === "number" ? cacheRead : 0) + (typeof cacheWrite === "number" ? cacheWrite : 0) + (typeof input === "number" ? input : 0);
48869
- return `๐Ÿ—„๏ธ Cache: ${totalInput > 0 && typeof cacheRead === "number" ? Math.round(cacheRead / totalInput * 100) : 0}% hit ยท ${cachedLabel} cached, ${newLabel} new`;
48812
+ const total = (input ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0);
48813
+ const count = value => (value ?? 0).toLocaleString("en-US");
48814
+ const ttl = usage?.cacheWrite5m !== undefined || usage?.cacheWrite1h !== undefined ? ` (${count(usage.cacheWrite5m)} 5m / ${count(usage.cacheWrite1h)} 1h)` : "";
48815
+ return `๐Ÿ—„๏ธ Cache: ${total > 0 ? Math.round((cacheRead ?? 0) / total * 100) : 0}% hit ยท ${count(input)} uncached + ${count(cacheWrite)} written${ttl}`;
48870
48816
  };
48871
48817
  const formatMediaUnderstandingLine = (decisions) => {
48872
48818
  if (!decisions || decisions.length === 0) return null;
@@ -48945,10 +48891,14 @@ function buildStatusMessage(args) {
48945
48891
  let outputTokens = entry?.outputTokens;
48946
48892
  let cacheRead = entry?.cacheRead;
48947
48893
  let cacheWrite = entry?.cacheWrite;
48894
+ let billingUsage;
48948
48895
  let totalTokens = entry?.totalTokens ?? (entry?.inputTokens ?? 0) + (entry?.outputTokens ?? 0);
48949
- if (args.includeTranscriptUsage) {
48896
+ if (entry?.sessionId) { // Always use a coherent latest API call on both status paths.
48950
48897
  const logUsage = readUsageFromSessionLog(entry?.sessionId, entry, args.agentId, args.sessionKey, args.sessionStorePath);
48951
48898
  if (logUsage) {
48899
+ billingUsage = logUsage;
48900
+ cacheRead = logUsage.cacheRead ?? 0;
48901
+ cacheWrite = logUsage.cacheWrite ?? 0;
48952
48902
  const candidate = logUsage.promptTokens || logUsage.total;
48953
48903
  if (!totalTokens || totalTokens === 0 || candidate > totalTokens) totalTokens = candidate;
48954
48904
  if (!entry?.model && logUsage.model) {
@@ -48967,8 +48917,10 @@ function buildStatusMessage(args) {
48967
48917
  model: logUsage.model,
48968
48918
  fallbackContextTokens: contextTokens ?? void 0
48969
48919
  }) ?? contextTokens;
48970
- if (!inputTokens || inputTokens === 0) inputTokens = logUsage.input;
48971
- if (!outputTokens || outputTokens === 0) outputTokens = logUsage.output;
48920
+ inputTokens = logUsage.input ?? 0;
48921
+ outputTokens = logUsage.output ?? 0;
48922
+ if (logUsage.provider) activeProvider = logUsage.provider;
48923
+ if (logUsage.model) activeModel = logUsage.model;
48972
48924
  }
48973
48925
  }
48974
48926
  const thinkLevel = args.resolvedThink ?? args.sessionEntry?.thinkingLevel ?? args.agent?.thinkingDefault ?? "off";
@@ -49004,21 +48956,14 @@ function buildStatusMessage(args) {
49004
48956
  state: entry
49005
48957
  });
49006
48958
  const effectiveCostAuthMode = fallbackState.active ? activeAuthMode : selectedAuthMode ?? activeAuthMode;
49007
- const showCost = effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
48959
+ const showCost = billingUsage?.cost?.total > 0 || effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
49008
48960
  const costConfig = showCost ? resolveModelCostConfig({
49009
48961
  provider: activeProvider,
49010
48962
  model: activeModel,
49011
48963
  config: args.config
49012
48964
  }) : void 0;
49013
- const hasUsage = typeof inputTokens === "number" || typeof outputTokens === "number";
49014
- const cost = showCost && hasUsage ? estimateUsageCost({
49015
- usage: {
49016
- input: inputTokens ?? void 0,
49017
- output: outputTokens ?? void 0
49018
- },
49019
- cost: costConfig
49020
- }) : void 0;
49021
- const costLabel = showCost && hasUsage ? formatUsd(cost) : void 0;
48965
+ const hasUsage = [inputTokens, outputTokens, cacheRead, cacheWrite].some(value => typeof value === "number");
48966
+ billingUsage ??= { input: inputTokens, output: outputTokens, cacheRead, cacheWrite };
49022
48967
  const selectedAuthLabel = selectedAuthLabelValue ? ` ยท ๐Ÿ”‘ ${selectedAuthLabelValue}` : "";
49023
48968
  const channelModelNote = (() => {
49024
48969
  if (!args.config || !entry) return;
@@ -49050,9 +48995,9 @@ function buildStatusMessage(args) {
49050
48995
  const fallbackLine = fallbackState.active ? `โ†ช๏ธ Fallback: ${activeModelLabel}${showFallbackAuth ? ` ยท ๐Ÿ”‘ ${activeAuthLabelValue}` : ""} (${fallbackState.reason ?? "selected model unavailable"})` : null;
49051
48996
  const commit = resolveCommitHash();
49052
48997
  const versionLine = `๐Ÿฆž Johnness ${VERSION}${commit ? ` (${commit})` : ""}`;
49053
- const usagePair = formatUsagePair(inputTokens, outputTokens);
49054
- const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite);
49055
- const costLine = costLabel ? `๐Ÿ’ต Cost: ${costLabel}` : null;
48998
+ const usagePair = formatUsagePair(inputTokens, outputTokens, cacheRead, cacheWrite);
48999
+ const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite, billingUsage);
49000
+ const costLine = showCost && hasUsage ? formatBillingCost(billingUsage, costConfig) : null;
49056
49001
  const usageCostLine = usagePair && costLine ? `${usagePair} ยท ${costLine}` : usagePair ?? costLine;
49057
49002
  const mediaLine = formatMediaUnderstandingLine(args.mediaDecisions);
49058
49003
  const voiceLine = formatVoiceModeLine(args.config, args.sessionEntry);
@@ -81134,6 +81079,8 @@ function normalizeAssistantUsageSnapshot(usage) {
81134
81079
  cacheRead,
81135
81080
  cacheWrite,
81136
81081
  totalTokens,
81082
+ ...normalized.cacheWrite5m !== undefined ? { cacheWrite5m: normalized.cacheWrite5m } : {},
81083
+ ...normalized.cacheWrite1h !== undefined ? { cacheWrite1h: normalized.cacheWrite1h } : {},
81137
81084
  ...cost ? { cost } : {}
81138
81085
  };
81139
81086
  }
@@ -88321,6 +88268,7 @@ async function runEmbeddedPiAgent(params) {
88321
88268
  });
88322
88269
  if (lockedProfileId && !profileOrder.includes(lockedProfileId)) throw new Error(`Auth profile "${lockedProfileId}" is not configured for ${provider}.`);
88323
88270
  const profileCandidates = lockedProfileId ? [lockedProfileId] : profileOrder.length > 0 ? profileOrder : [void 0];
88271
+ const subscriptionAuth = createSubscriptionAuthTracker({ provider, model: modelId, store: authStore, preferredProfileId, lockedProfileId }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
88324
88272
  let profileIndex = 0;
88325
88273
  const initialThinkLevel = params.thinkLevel ?? "off";
88326
88274
  let thinkLevel = initialThinkLevel;
@@ -88452,7 +88400,8 @@ async function runEmbeddedPiAgent(params) {
88452
88400
  } else authStorage.setRuntimeApiKey(model.provider, apiKeyInfo.apiKey);
88453
88401
  lastProfileId = apiKeyInfo.profileId;
88454
88402
  };
88455
- const advanceAuthProfile = async () => {
88403
+ const advanceAuthProfile = async (reason) => {
88404
+ subscriptionAuth.failed(profileCandidates[profileIndex], reason);
88456
88405
  if (lockedProfileId) return false;
88457
88406
  let nextIndex = profileIndex + 1;
88458
88407
  while (nextIndex < profileCandidates.length) {
@@ -88502,7 +88451,7 @@ async function runEmbeddedPiAgent(params) {
88502
88451
  allInCooldown: false,
88503
88452
  error: err
88504
88453
  });
88505
- if (!await advanceAuthProfile()) throwAuthProfileFailover({
88454
+ if (!await advanceAuthProfile(/refresh/i.test(String(err)) ? "oauth_refresh_failed" : "credential_unavailable")) throwAuthProfileFailover({
88506
88455
  allInCooldown: false,
88507
88456
  error: err
88508
88457
  });
@@ -88871,7 +88820,7 @@ async function runEmbeddedPiAgent(params) {
88871
88820
  reason: promptProfileFailureReason
88872
88821
  });
88873
88822
  const promptFailoverFailure = isFailoverErrorMessage(errorText);
88874
- if (promptFailoverFailure && promptFailoverReason !== "timeout" && await advanceAuthProfile()) {
88823
+ if (promptFailoverFailure && promptFailoverReason !== "timeout" && await advanceAuthProfile(promptFailoverReason)) {
88875
88824
  await maybeBackoffBeforeOverloadFailover(promptFailoverReason);
88876
88825
  continue;
88877
88826
  }
@@ -88934,7 +88883,7 @@ async function runEmbeddedPiAgent(params) {
88934
88883
  if (timedOut && !isProbeSession) log$7.warn(`Profile ${lastProfileId} timed out. Trying next account...`);
88935
88884
  if (cloudCodeAssistFormatError) log$7.warn(`Profile ${lastProfileId} hit Cloud Code Assist format error. Tool calls will be sanitized on retry.`);
88936
88885
  }
88937
- if (await advanceAuthProfile()) {
88886
+ if (await advanceAuthProfile(timedOut ? "timeout" : assistantFailoverReason)) {
88938
88887
  await maybeBackoffBeforeOverloadFailover(assistantFailoverReason);
88939
88888
  continue;
88940
88889
  }
@@ -88968,6 +88917,7 @@ async function runEmbeddedPiAgent(params) {
88968
88917
  lastCallUsage: lastCallUsage ?? void 0,
88969
88918
  promptTokens,
88970
88919
  compactionCount: autoCompactionCount > 0 ? autoCompactionCount : void 0,
88920
+ authProfileFallback: subscriptionAuth.result(lastProfileId), // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
88971
88921
  authProfileId: lastProfileId // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89: profile that served this turn
88972
88922
  };
88973
88923
  const payloads = buildEmbeddedRunPayloads({
@@ -100362,6 +100312,7 @@ async function persistSessionUsageUpdate(params) {
100362
100312
  modelProvider: params.providerUsed ?? entry.modelProvider,
100363
100313
  model: params.modelUsed ?? entry.model,
100364
100314
  authProfileServed: params.authProfileServed ?? entry.authProfileServed, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
100315
+ authProfileFallback: params.authProfileFallback ?? null, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
100365
100316
  contextTokens: resolvedContextTokens,
100366
100317
  systemPromptReport: params.systemPromptReport ?? entry.systemPromptReport,
100367
100318
  updatedAt: Date.now()
@@ -100642,6 +100593,7 @@ function createFollowupRunner(params) {
100642
100593
  modelUsed,
100643
100594
  providerUsed: fallbackProvider,
100644
100595
  authProfileServed: runResult.meta?.agentMeta?.authProfileId, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
100596
+ authProfileFallback: runResult.meta?.agentMeta?.authProfileFallback, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
100645
100597
  contextTokensUsed,
100646
100598
  systemPromptReport: runResult.meta?.systemPromptReport,
100647
100599
  logLabel: "followup"
@@ -100980,6 +100932,7 @@ async function runReplyAgent(params) {
100980
100932
  modelUsed,
100981
100933
  providerUsed,
100982
100934
  authProfileServed: runResult.meta?.agentMeta?.authProfileId, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
100935
+ authProfileFallback: runResult.meta?.agentMeta?.authProfileFallback, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
100983
100936
  contextTokensUsed,
100984
100937
  systemPromptReport: runResult.meta?.systemPromptReport,
100985
100938
  cliSessionId
@@ -1,3 +1,5 @@
1
+ import { createSubscriptionAuthTracker, formatAuthProfileFallback } from "../anthropic-auth-runtime.js"; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
2
+ import { normalizeBillingUsage, readLatestBillingUsage, formatBillingCost } from "../usage-billing.js"; // JOHNNESS_PATCH_USAGE_BILLING_91 dist/plugin-sdk/dispatch-CQsjmw7g.js
1
3
  import { importOptional66 } from "../optional-module.js";
2
4
  const JOHNNESS_PATCH_SLIM_TREE_66 = true;
3
5
  import { createImageGenerateTool } from "../image-generate.js";
@@ -24419,7 +24421,7 @@ function resolveModelAuthLabel(params) {
24419
24421
  });
24420
24422
  if (profile.type === "oauth") return `oauth${label ? ` (${label})` : ""}`;
24421
24423
  if (profile.type === "token") return `token${label ? ` (${label})` : ""}`;
24422
- return `api-key${label ? ` (${label})` : ""}`;
24424
+ return `api-key${label ? ` (${label})` : ""}${formatAuthProfileFallback(params.sessionEntry, profileId)}`;
24423
24425
  }
24424
24426
  const envKey = resolveEnvApiKey(providerKey);
24425
24427
  if (envKey?.apiKey) {
@@ -34060,21 +34062,7 @@ function hasNonzeroUsage(usage) {
34060
34062
  ].some((v) => typeof v === "number" && Number.isFinite(v) && v > 0);
34061
34063
  }
34062
34064
  function normalizeUsage(raw) {
34063
- if (!raw) return;
34064
- const rawInput = asFiniteNumber(raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens);
34065
- const input = rawInput !== void 0 && rawInput < 0 ? 0 : rawInput;
34066
- const output = asFiniteNumber(raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens);
34067
- const cacheRead = asFiniteNumber(raw.cacheRead ?? raw.cache_read ?? raw.cache_read_input_tokens ?? raw.cached_tokens ?? raw.prompt_tokens_details?.cached_tokens);
34068
- const cacheWrite = asFiniteNumber(raw.cacheWrite ?? raw.cache_write ?? raw.cache_creation_input_tokens);
34069
- const total = asFiniteNumber(raw.total ?? raw.totalTokens ?? raw.total_tokens);
34070
- if (input === void 0 && output === void 0 && cacheRead === void 0 && cacheWrite === void 0 && total === void 0) return;
34071
- return {
34072
- input,
34073
- output,
34074
- cacheRead,
34075
- cacheWrite,
34076
- total
34077
- };
34065
+ return normalizeBillingUsage(raw);
34078
34066
  }
34079
34067
  function derivePromptTokens(usage) {
34080
34068
  if (!usage) return;
@@ -34128,6 +34116,7 @@ async function updateSessionStoreAfterAgentRun(params) {
34128
34116
  model: modelUsed
34129
34117
  });
34130
34118
  if (result.meta.agentMeta?.authProfileId) next.authProfileServed = result.meta.agentMeta.authProfileId; // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
34119
+ next.authProfileFallback = result.meta.agentMeta?.authProfileFallback ?? null; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
34131
34120
  if (isCliProvider(providerUsed, cfg)) {
34132
34121
  const cliSessionId = result.meta.agentMeta?.sessionId?.trim();
34133
34122
  if (cliSessionId) setCliSessionId(next, providerUsed, cliSessionId);
@@ -48811,62 +48800,19 @@ const readUsageFromSessionLog = (sessionId, sessionEntry, agentId, sessionKey, s
48811
48800
  } catch {
48812
48801
  return;
48813
48802
  }
48814
- if (!fs$1.existsSync(logPath)) return;
48815
- try {
48816
- const TAIL_BYTES = 8192;
48817
- const stat = fs$1.statSync(logPath);
48818
- const offset = Math.max(0, stat.size - TAIL_BYTES);
48819
- const buf = Buffer.alloc(Math.min(TAIL_BYTES, stat.size));
48820
- const fd = fs$1.openSync(logPath, "r");
48821
- try {
48822
- fs$1.readSync(fd, buf, 0, buf.length, offset);
48823
- } finally {
48824
- fs$1.closeSync(fd);
48825
- }
48826
- const tail = buf.toString("utf-8");
48827
- const lines = (offset > 0 ? tail.slice(tail.indexOf("\n") + 1) : tail).split(/\n+/);
48828
- let input = 0;
48829
- let output = 0;
48830
- let promptTokens = 0;
48831
- let model;
48832
- let lastUsage;
48833
- for (const line of lines) {
48834
- if (!line.trim()) continue;
48835
- try {
48836
- const parsed = JSON.parse(line);
48837
- const usage = normalizeUsage(parsed.message?.usage ?? parsed.usage);
48838
- if (usage) lastUsage = usage;
48839
- model = parsed.message?.model ?? parsed.model ?? model;
48840
- } catch {}
48841
- }
48842
- if (!lastUsage) return;
48843
- input = lastUsage.input ?? 0;
48844
- output = lastUsage.output ?? 0;
48845
- promptTokens = derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
48846
- const total = lastUsage.total ?? promptTokens + output;
48847
- if (promptTokens === 0 && total === 0) return;
48848
- return {
48849
- input,
48850
- output,
48851
- promptTokens,
48852
- total,
48853
- model
48854
- };
48855
- } catch {
48856
- return;
48857
- }
48803
+ return readLatestBillingUsage(logPath);
48858
48804
  };
48859
- const formatUsagePair = (input, output) => {
48860
- if (input == null && output == null) return null;
48861
- return `๐Ÿงฎ Tokens: ${typeof input === "number" ? formatTokenCount$1(input) : "?"} in / ${typeof output === "number" ? formatTokenCount$1(output) : "?"} out`;
48805
+ const formatUsagePair = (input, output, cacheRead, cacheWrite) => {
48806
+ if (input == null && output == null && cacheRead == null && cacheWrite == null) return null;
48807
+ const count = value => typeof value === "number" ? value.toLocaleString("en-US") : "?";
48808
+ return `๐Ÿงฎ Tokens: ${count((input ?? 0) + (cacheWrite ?? 0))} new in / ${count(cacheRead ?? 0)} cached / ${count(output)} out (last API call)`;
48862
48809
  };
48863
- const formatCacheLine = (input, cacheRead, cacheWrite) => {
48810
+ const formatCacheLine = (input, cacheRead, cacheWrite, usage) => {
48864
48811
  if (!cacheRead && !cacheWrite) return null;
48865
- if ((typeof cacheRead !== "number" || cacheRead <= 0) && (typeof cacheWrite !== "number" || cacheWrite <= 0)) return null;
48866
- const cachedLabel = typeof cacheRead === "number" ? formatTokenCount$1(cacheRead) : "0";
48867
- const newLabel = typeof cacheWrite === "number" ? formatTokenCount$1(cacheWrite) : "0";
48868
- const totalInput = (typeof cacheRead === "number" ? cacheRead : 0) + (typeof cacheWrite === "number" ? cacheWrite : 0) + (typeof input === "number" ? input : 0);
48869
- return `๐Ÿ—„๏ธ Cache: ${totalInput > 0 && typeof cacheRead === "number" ? Math.round(cacheRead / totalInput * 100) : 0}% hit ยท ${cachedLabel} cached, ${newLabel} new`;
48812
+ const total = (input ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0);
48813
+ const count = value => (value ?? 0).toLocaleString("en-US");
48814
+ const ttl = usage?.cacheWrite5m !== undefined || usage?.cacheWrite1h !== undefined ? ` (${count(usage.cacheWrite5m)} 5m / ${count(usage.cacheWrite1h)} 1h)` : "";
48815
+ return `๐Ÿ—„๏ธ Cache: ${total > 0 ? Math.round((cacheRead ?? 0) / total * 100) : 0}% hit ยท ${count(input)} uncached + ${count(cacheWrite)} written${ttl}`;
48870
48816
  };
48871
48817
  const formatMediaUnderstandingLine = (decisions) => {
48872
48818
  if (!decisions || decisions.length === 0) return null;
@@ -48945,10 +48891,14 @@ function buildStatusMessage(args) {
48945
48891
  let outputTokens = entry?.outputTokens;
48946
48892
  let cacheRead = entry?.cacheRead;
48947
48893
  let cacheWrite = entry?.cacheWrite;
48894
+ let billingUsage;
48948
48895
  let totalTokens = entry?.totalTokens ?? (entry?.inputTokens ?? 0) + (entry?.outputTokens ?? 0);
48949
- if (args.includeTranscriptUsage) {
48896
+ if (entry?.sessionId) { // Always use a coherent latest API call on both status paths.
48950
48897
  const logUsage = readUsageFromSessionLog(entry?.sessionId, entry, args.agentId, args.sessionKey, args.sessionStorePath);
48951
48898
  if (logUsage) {
48899
+ billingUsage = logUsage;
48900
+ cacheRead = logUsage.cacheRead ?? 0;
48901
+ cacheWrite = logUsage.cacheWrite ?? 0;
48952
48902
  const candidate = logUsage.promptTokens || logUsage.total;
48953
48903
  if (!totalTokens || totalTokens === 0 || candidate > totalTokens) totalTokens = candidate;
48954
48904
  if (!entry?.model && logUsage.model) {
@@ -48967,8 +48917,10 @@ function buildStatusMessage(args) {
48967
48917
  model: logUsage.model,
48968
48918
  fallbackContextTokens: contextTokens ?? void 0
48969
48919
  }) ?? contextTokens;
48970
- if (!inputTokens || inputTokens === 0) inputTokens = logUsage.input;
48971
- if (!outputTokens || outputTokens === 0) outputTokens = logUsage.output;
48920
+ inputTokens = logUsage.input ?? 0;
48921
+ outputTokens = logUsage.output ?? 0;
48922
+ if (logUsage.provider) activeProvider = logUsage.provider;
48923
+ if (logUsage.model) activeModel = logUsage.model;
48972
48924
  }
48973
48925
  }
48974
48926
  const thinkLevel = args.resolvedThink ?? args.sessionEntry?.thinkingLevel ?? args.agent?.thinkingDefault ?? "off";
@@ -49004,21 +48956,14 @@ function buildStatusMessage(args) {
49004
48956
  state: entry
49005
48957
  });
49006
48958
  const effectiveCostAuthMode = fallbackState.active ? activeAuthMode : selectedAuthMode ?? activeAuthMode;
49007
- const showCost = effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
48959
+ const showCost = billingUsage?.cost?.total > 0 || effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
49008
48960
  const costConfig = showCost ? resolveModelCostConfig({
49009
48961
  provider: activeProvider,
49010
48962
  model: activeModel,
49011
48963
  config: args.config
49012
48964
  }) : void 0;
49013
- const hasUsage = typeof inputTokens === "number" || typeof outputTokens === "number";
49014
- const cost = showCost && hasUsage ? estimateUsageCost({
49015
- usage: {
49016
- input: inputTokens ?? void 0,
49017
- output: outputTokens ?? void 0
49018
- },
49019
- cost: costConfig
49020
- }) : void 0;
49021
- const costLabel = showCost && hasUsage ? formatUsd(cost) : void 0;
48965
+ const hasUsage = [inputTokens, outputTokens, cacheRead, cacheWrite].some(value => typeof value === "number");
48966
+ billingUsage ??= { input: inputTokens, output: outputTokens, cacheRead, cacheWrite };
49022
48967
  const selectedAuthLabel = selectedAuthLabelValue ? ` ยท ๐Ÿ”‘ ${selectedAuthLabelValue}` : "";
49023
48968
  const channelModelNote = (() => {
49024
48969
  if (!args.config || !entry) return;
@@ -49050,9 +48995,9 @@ function buildStatusMessage(args) {
49050
48995
  const fallbackLine = fallbackState.active ? `โ†ช๏ธ Fallback: ${activeModelLabel}${showFallbackAuth ? ` ยท ๐Ÿ”‘ ${activeAuthLabelValue}` : ""} (${fallbackState.reason ?? "selected model unavailable"})` : null;
49051
48996
  const commit = resolveCommitHash();
49052
48997
  const versionLine = `๐Ÿฆž Johnness ${VERSION}${commit ? ` (${commit})` : ""}`;
49053
- const usagePair = formatUsagePair(inputTokens, outputTokens);
49054
- const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite);
49055
- const costLine = costLabel ? `๐Ÿ’ต Cost: ${costLabel}` : null;
48998
+ const usagePair = formatUsagePair(inputTokens, outputTokens, cacheRead, cacheWrite);
48999
+ const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite, billingUsage);
49000
+ const costLine = showCost && hasUsage ? formatBillingCost(billingUsage, costConfig) : null;
49056
49001
  const usageCostLine = usagePair && costLine ? `${usagePair} ยท ${costLine}` : usagePair ?? costLine;
49057
49002
  const mediaLine = formatMediaUnderstandingLine(args.mediaDecisions);
49058
49003
  const voiceLine = formatVoiceModeLine(args.config, args.sessionEntry);
@@ -81134,6 +81079,8 @@ function normalizeAssistantUsageSnapshot(usage) {
81134
81079
  cacheRead,
81135
81080
  cacheWrite,
81136
81081
  totalTokens,
81082
+ ...normalized.cacheWrite5m !== undefined ? { cacheWrite5m: normalized.cacheWrite5m } : {},
81083
+ ...normalized.cacheWrite1h !== undefined ? { cacheWrite1h: normalized.cacheWrite1h } : {},
81137
81084
  ...cost ? { cost } : {}
81138
81085
  };
81139
81086
  }
@@ -88321,6 +88268,7 @@ async function runEmbeddedPiAgent(params) {
88321
88268
  });
88322
88269
  if (lockedProfileId && !profileOrder.includes(lockedProfileId)) throw new Error(`Auth profile "${lockedProfileId}" is not configured for ${provider}.`);
88323
88270
  const profileCandidates = lockedProfileId ? [lockedProfileId] : profileOrder.length > 0 ? profileOrder : [void 0];
88271
+ const subscriptionAuth = createSubscriptionAuthTracker({ provider, model: modelId, store: authStore, preferredProfileId, lockedProfileId }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
88324
88272
  let profileIndex = 0;
88325
88273
  const initialThinkLevel = params.thinkLevel ?? "off";
88326
88274
  let thinkLevel = initialThinkLevel;
@@ -88452,7 +88400,8 @@ async function runEmbeddedPiAgent(params) {
88452
88400
  } else authStorage.setRuntimeApiKey(model.provider, apiKeyInfo.apiKey);
88453
88401
  lastProfileId = apiKeyInfo.profileId;
88454
88402
  };
88455
- const advanceAuthProfile = async () => {
88403
+ const advanceAuthProfile = async (reason) => {
88404
+ subscriptionAuth.failed(profileCandidates[profileIndex], reason);
88456
88405
  if (lockedProfileId) return false;
88457
88406
  let nextIndex = profileIndex + 1;
88458
88407
  while (nextIndex < profileCandidates.length) {
@@ -88502,7 +88451,7 @@ async function runEmbeddedPiAgent(params) {
88502
88451
  allInCooldown: false,
88503
88452
  error: err
88504
88453
  });
88505
- if (!await advanceAuthProfile()) throwAuthProfileFailover({
88454
+ if (!await advanceAuthProfile(/refresh/i.test(String(err)) ? "oauth_refresh_failed" : "credential_unavailable")) throwAuthProfileFailover({
88506
88455
  allInCooldown: false,
88507
88456
  error: err
88508
88457
  });
@@ -88871,7 +88820,7 @@ async function runEmbeddedPiAgent(params) {
88871
88820
  reason: promptProfileFailureReason
88872
88821
  });
88873
88822
  const promptFailoverFailure = isFailoverErrorMessage(errorText);
88874
- if (promptFailoverFailure && promptFailoverReason !== "timeout" && await advanceAuthProfile()) {
88823
+ if (promptFailoverFailure && promptFailoverReason !== "timeout" && await advanceAuthProfile(promptFailoverReason)) {
88875
88824
  await maybeBackoffBeforeOverloadFailover(promptFailoverReason);
88876
88825
  continue;
88877
88826
  }
@@ -88934,7 +88883,7 @@ async function runEmbeddedPiAgent(params) {
88934
88883
  if (timedOut && !isProbeSession) log$7.warn(`Profile ${lastProfileId} timed out. Trying next account...`);
88935
88884
  if (cloudCodeAssistFormatError) log$7.warn(`Profile ${lastProfileId} hit Cloud Code Assist format error. Tool calls will be sanitized on retry.`);
88936
88885
  }
88937
- if (await advanceAuthProfile()) {
88886
+ if (await advanceAuthProfile(timedOut ? "timeout" : assistantFailoverReason)) {
88938
88887
  await maybeBackoffBeforeOverloadFailover(assistantFailoverReason);
88939
88888
  continue;
88940
88889
  }
@@ -88968,6 +88917,7 @@ async function runEmbeddedPiAgent(params) {
88968
88917
  lastCallUsage: lastCallUsage ?? void 0,
88969
88918
  promptTokens,
88970
88919
  compactionCount: autoCompactionCount > 0 ? autoCompactionCount : void 0,
88920
+ authProfileFallback: subscriptionAuth.result(lastProfileId), // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
88971
88921
  authProfileId: lastProfileId // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89: profile that served this turn
88972
88922
  };
88973
88923
  const payloads = buildEmbeddedRunPayloads({
@@ -100362,6 +100312,7 @@ async function persistSessionUsageUpdate(params) {
100362
100312
  modelProvider: params.providerUsed ?? entry.modelProvider,
100363
100313
  model: params.modelUsed ?? entry.model,
100364
100314
  authProfileServed: params.authProfileServed ?? entry.authProfileServed, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
100315
+ authProfileFallback: params.authProfileFallback ?? null, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
100365
100316
  contextTokens: resolvedContextTokens,
100366
100317
  systemPromptReport: params.systemPromptReport ?? entry.systemPromptReport,
100367
100318
  updatedAt: Date.now()
@@ -100642,6 +100593,7 @@ function createFollowupRunner(params) {
100642
100593
  modelUsed,
100643
100594
  providerUsed: fallbackProvider,
100644
100595
  authProfileServed: runResult.meta?.agentMeta?.authProfileId, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
100596
+ authProfileFallback: runResult.meta?.agentMeta?.authProfileFallback, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
100645
100597
  contextTokensUsed,
100646
100598
  systemPromptReport: runResult.meta?.systemPromptReport,
100647
100599
  logLabel: "followup"
@@ -100980,6 +100932,7 @@ async function runReplyAgent(params) {
100980
100932
  modelUsed,
100981
100933
  providerUsed,
100982
100934
  authProfileServed: runResult.meta?.agentMeta?.authProfileId, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
100935
+ authProfileFallback: runResult.meta?.agentMeta?.authProfileFallback, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
100983
100936
  contextTokensUsed,
100984
100937
  systemPromptReport: runResult.meta?.systemPromptReport,
100985
100938
  cliSessionId