johns-harness 2026.10.20 → 2026.10.22

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 +16 -0
  2. package/README.md +3 -0
  3. package/dist/auth-profiles-5CHn7vq1.js +11 -7
  4. package/dist/compact-B247y5Qt.js +33 -72
  5. package/dist/config-koj5M_EO.js +11 -7
  6. package/dist/daemon-cli.js +11 -7
  7. package/dist/model-selection-BGlGpPgM.js +11 -7
  8. package/dist/model-selection-BU6wl1le.js +11 -7
  9. package/dist/model-selection-L7RMwsG-.js +11 -7
  10. package/dist/pi-embedded-C6ITuRXf.js +34 -87
  11. package/dist/pi-embedded-DoQsYfIY.js +34 -87
  12. package/dist/plugin-sdk/bluebubbles.js +2 -1
  13. package/dist/plugin-sdk/config/types.models.d.ts +1 -0
  14. package/dist/plugin-sdk/config/zod-schema.core.d.ts +3 -0
  15. package/dist/plugin-sdk/config/zod-schema.d.ts +1 -0
  16. package/dist/plugin-sdk/config-4Fgm-yEH.js +11 -7
  17. package/dist/plugin-sdk/config-Di-lyCdh.js +11 -7
  18. package/dist/plugin-sdk/discord.js +11 -7
  19. package/dist/plugin-sdk/dispatch-BP0viZiL.js +34 -87
  20. package/dist/plugin-sdk/dispatch-CQsjmw7g.js +34 -87
  21. package/dist/plugin-sdk/dispatch-Cerq29sy.js +34 -87
  22. package/dist/plugin-sdk/dispatch-Cndjtt0g.js +34 -87
  23. package/dist/plugin-sdk/dispatch-UogiJYul.js +34 -87
  24. package/dist/plugin-sdk/feishu.js +2 -1
  25. package/dist/plugin-sdk/googlechat.js +2 -1
  26. package/dist/plugin-sdk/imessage.js +2 -1
  27. package/dist/plugin-sdk/model-auth-CX9cPHdC.js +11 -7
  28. package/dist/plugin-sdk/model-auth-Ciehz0x5.js +11 -7
  29. package/dist/plugin-sdk/model-auth-DVyo6JSX.js +11 -7
  30. package/dist/plugin-sdk/model-auth-kiHYHGrs.js +11 -7
  31. package/dist/plugin-sdk/model-selection-Dbj4jDYM.js +11 -7
  32. package/dist/plugin-sdk/nostr.js +2 -1
  33. package/dist/plugin-sdk/reply-DbZnH8-h.js +34 -87
  34. package/dist/plugin-sdk/signal.js +2 -1
  35. package/dist/plugin-sdk/slack.js +2 -1
  36. package/dist/plugin-sdk/telegram.js +2 -1
  37. package/dist/plugin-sdk/tlon.js +2 -1
  38. package/dist/plugin-sdk/twitch.js +2 -1
  39. package/dist/plugin-sdk/utils/usage-format.d.ts +1 -0
  40. package/dist/plugin-sdk/voice-call.js +2 -1
  41. package/dist/plugin-sdk/zalo.js +2 -1
  42. package/dist/plugin-sdk/zalouser.js +2 -1
  43. package/dist/reply-C5LKjXcC.js +33 -72
  44. package/dist/session-cost-usage-5CCZbVhO.js +4 -19
  45. package/dist/session-cost-usage-CkCo2kVx.js +4 -19
  46. package/dist/usage-billing.js +88 -0
  47. package/dist/usage-format-CNGi1eHQ.js +6 -11
  48. package/dist/usage-format-CvaU1ntA.js +6 -11
  49. package/docs/PATCHES.md +59 -1
  50. package/docs/concepts/session-pruning.md +1 -1
  51. package/docs/providers/anthropic.md +15 -6
  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 +39 -12
  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 +39 -12
  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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 2026.10.22
4
+
5
+ ### Fixed
6
+ - `/status` and `session_status` include all billable input, cache reads, cache writes and output from one coherent latest API response. New-input counts include cache creation. Costs show every component without rounding away small charges, with a separate total for multi-call turns.
7
+ - Anthropic preserves native five-minute/one-hour cache creation buckets and uses the duration-specific price. Subscription-zero accounting remains zero; session cumulative totals sum the same corrected provider costs.
8
+ - OpenAI Chat Completions no longer counts reasoning twice. DeepSeek cache-hit fields are recognized, and Google native/Vertex subtract cached prompt tokens before pricing ordinary input. OpenAI Responses service-tier adjustments remain intact.
9
+ - Missing recorded costs are explicitly estimated using configured or shipped model prices. The backward transcript reader handles large assistant/tool records instead of silently missing usage outside an 8 KiB tail.
10
+
11
+ ## 2026.10.21
12
+
13
+ - **One-hour prompt caching is the Anthropic default**, for both API keys and Claude subscriptions, including models with no params configured. This avoids rewriting a large cached prompt after gaps longer than five minutes. Explicit `none`, `short`, `long` and legacy `cacheControlTtl` settings still win; Bedrock behavior is unchanged.
14
+ - **The wire request matches the policy:** the adapter sends `cache_control: { type: "ephemeral", ttl: "1h" }` on the existing Anthropic cache breakpoints and adds the extended-cache beta on both auth paths, even with custom beta headers. Stable system content stays cached, changing memory stays outside that breakpoint, and subscription attribution and plan-limit routing are preserved.
15
+ - **Live proof, after gaps over six minutes:** API cache read/write went from 0/31,332 to 31,332/61; subscription from 0/31,407 to 31,407/61. Both subscription responses returned `anthropic-ratelimit-unified-5h-status: allowed`, with Extra usage still disabled. All cache writes were one-hour writes.
16
+ - **Validation:** 36 new Family 90 tests cover all ten runtime and fourteen config copies, actual adapter SSE requests for both auth modes, explicit/legacy settings, empty params, header merging and replay safety. Verifier 564/564; full suite 1,249 pass and 5 existing skips. Clean 2026.10.20 replay matches all 25 changed runtime/adapter files byte for byte.
17
+ - **Rollback:** `npm i -g johns-harness@2026.10.20`.
18
+
3
19
  ## 2026.10.20
4
20
 
5
21
  - **A subscription login takes effect on the very next turn.** After `/login claude` or `/login chatgpt` (chat or CLI), the matching subscription serves the next turn of every existing session with no `johnness secrets reload`, no `/new` and no restart. Root cause: the gateway serves turns from an in-memory auth snapshot taken at start, and a login wrote `auth-profiles.json` without replacing it, so the picker never saw the new profile until a reload. The login now refreshes that snapshot: in process when the login runs inside the gateway, over the `secrets.reload` RPC when it runs from the CLI; no gateway running is fine.
package/README.md CHANGED
@@ -34,6 +34,9 @@ The package is `johns-harness`; the command it installs is `johnness`.
34
34
 
35
35
  The wizard sets up credentials, workspace, gateway, and channels. It asks for your MemoryRouter API key and links to [signup](https://app.memoryrouter.ai/signup), free to start. If you skip memory in the wizard, the third line stores the key later.
36
36
 
37
+ ### API spend at a glance
38
+ `/status` shows the last API call's complete new-input, cached-read and output counts, with separate input/read/write/output costs. Anthropic one-hour and five-minute cache writes are priced separately. Tool-heavy turns also show a total across their API calls; `/usage cost` shows the cumulative session total. See [token use and costs](docs/reference/token-use.md).
39
+
37
40
  ### First run
38
41
 
39
42
  | Step | Command | What happens |
@@ -5181,7 +5181,8 @@ function resolveModelCost(raw) {
5181
5181
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
5182
5182
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
5183
5183
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
5184
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
5184
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
5185
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
5185
5186
  };
5186
5187
  }
5187
5188
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -5520,16 +5521,18 @@ function applyContextPruningDefaults(cfg) {
5520
5521
  const nextModels = defaults.models ? { ...defaults.models } : {};
5521
5522
  let modelsMutated = false;
5522
5523
  const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
5524
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
5523
5525
  for (const [key, entry] of Object.entries(nextModels)) {
5524
- if (!isAnthropicCacheRetentionTarget(parseModelRef(key, "anthropic"))) continue;
5526
+ const parsed = parseModelRef(key, "anthropic");
5527
+ if (!isAnthropicCacheRetentionTarget(parsed)) continue;
5525
5528
  const current = entry ?? {};
5526
5529
  const params = current.params ?? {};
5527
- if (typeof params.cacheRetention === "string") continue;
5530
+ if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
5528
5531
  nextModels[key] = {
5529
5532
  ...current,
5530
5533
  params: {
5531
5534
  ...params,
5532
- cacheRetention: "short"
5535
+ cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
5533
5536
  }
5534
5537
  };
5535
5538
  modelsMutated = true;
@@ -5541,12 +5544,12 @@ function applyContextPruningDefaults(cfg) {
5541
5544
  const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
5542
5545
  const current = nextModels[key] ?? {};
5543
5546
  const params = current.params ?? {};
5544
- if (typeof params.cacheRetention !== "string") {
5547
+ if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
5545
5548
  nextModels[key] = {
5546
5549
  ...current,
5547
5550
  params: {
5548
5551
  ...params,
5549
- cacheRetention: "short"
5552
+ cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
5550
5553
  }
5551
5554
  };
5552
5555
  modelsMutated = true;
@@ -10082,7 +10085,8 @@ const ModelDefinitionSchema = z.object({
10082
10085
  input: z.number().optional(),
10083
10086
  output: z.number().optional(),
10084
10087
  cacheRead: z.number().optional(),
10085
- cacheWrite: z.number().optional()
10088
+ cacheWrite: z.number().optional(),
10089
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
10086
10090
  }).strict().optional(),
10087
10091
  contextWindow: z.number().positive().optional(),
10088
10092
  maxTokens: z.number().positive().optional(),
@@ -1,3 +1,4 @@
1
+ import { normalizeBillingUsage, readLatestBillingUsage, formatBillingCost } from "./usage-billing.js"; // JOHNNESS_PATCH_USAGE_BILLING_91 dist/compact-B247y5Qt.js
1
2
  import { importOptional66 } from "./optional-module.js";
2
3
  const JOHNNESS_PATCH_SLIM_TREE_66 = true;
3
4
  import { createImageGenerateTool } from "./image-generate.js";
@@ -6430,7 +6431,7 @@ function resolveExtraParams(params) {
6430
6431
  * OpenRouter uses openai-completions API with hardcoded cache_control instead
6431
6432
  * of the cacheRetention stream option.
6432
6433
  *
6433
- * Defaults to "short" for direct Anthropic when not explicitly configured.
6434
+ * JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
6434
6435
  */
6435
6436
  function resolveCacheRetention(extraParams, provider) {
6436
6437
  const isAnthropicDirect = provider === "anthropic";
@@ -6442,10 +6443,12 @@ function resolveCacheRetention(extraParams, provider) {
6442
6443
  if (legacy === "5m") return "short";
6443
6444
  if (legacy === "1h") return "long";
6444
6445
  if (!isAnthropicDirect) return;
6445
- return "short";
6446
+ return "long";
6446
6447
  }
6447
6448
  function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
6448
- if (!extraParams || Object.keys(extraParams).length === 0) return;
6449
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
6450
+ if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
6451
+ extraParams ??= {};
6449
6452
  const streamParams = {};
6450
6453
  if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
6451
6454
  if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
@@ -8498,6 +8501,8 @@ function normalizeAssistantUsageSnapshot(usage) {
8498
8501
  cacheRead,
8499
8502
  cacheWrite,
8500
8503
  totalTokens,
8504
+ ...normalized.cacheWrite5m !== undefined ? { cacheWrite5m: normalized.cacheWrite5m } : {},
8505
+ ...normalized.cacheWrite1h !== undefined ? { cacheWrite1h: normalized.cacheWrite1h } : {},
8501
8506
  ...cost ? { cost } : {}
8502
8507
  };
8503
8508
  }
@@ -34238,62 +34243,19 @@ const readUsageFromSessionLog = (sessionId, sessionEntry, agentId, sessionKey, s
34238
34243
  } catch {
34239
34244
  return;
34240
34245
  }
34241
- if (!fs.existsSync(logPath)) return;
34242
- try {
34243
- const TAIL_BYTES = 8192;
34244
- const stat = fs.statSync(logPath);
34245
- const offset = Math.max(0, stat.size - TAIL_BYTES);
34246
- const buf = Buffer.alloc(Math.min(TAIL_BYTES, stat.size));
34247
- const fd = fs.openSync(logPath, "r");
34248
- try {
34249
- fs.readSync(fd, buf, 0, buf.length, offset);
34250
- } finally {
34251
- fs.closeSync(fd);
34252
- }
34253
- const tail = buf.toString("utf-8");
34254
- const lines = (offset > 0 ? tail.slice(tail.indexOf("\n") + 1) : tail).split(/\n+/);
34255
- let input = 0;
34256
- let output = 0;
34257
- let promptTokens = 0;
34258
- let model;
34259
- let lastUsage;
34260
- for (const line of lines) {
34261
- if (!line.trim()) continue;
34262
- try {
34263
- const parsed = JSON.parse(line);
34264
- const usage = normalizeUsage(parsed.message?.usage ?? parsed.usage);
34265
- if (usage) lastUsage = usage;
34266
- model = parsed.message?.model ?? parsed.model ?? model;
34267
- } catch {}
34268
- }
34269
- if (!lastUsage) return;
34270
- input = lastUsage.input ?? 0;
34271
- output = lastUsage.output ?? 0;
34272
- promptTokens = derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
34273
- const total = lastUsage.total ?? promptTokens + output;
34274
- if (promptTokens === 0 && total === 0) return;
34275
- return {
34276
- input,
34277
- output,
34278
- promptTokens,
34279
- total,
34280
- model
34281
- };
34282
- } catch {
34283
- return;
34284
- }
34246
+ return readLatestBillingUsage(logPath);
34285
34247
  };
34286
- const formatUsagePair = (input, output) => {
34287
- if (input == null && output == null) return null;
34288
- return `🧮 Tokens: ${typeof input === "number" ? formatTokenCount(input) : "?"} in / ${typeof output === "number" ? formatTokenCount(output) : "?"} out`;
34248
+ const formatUsagePair = (input, output, cacheRead, cacheWrite) => {
34249
+ if (input == null && output == null && cacheRead == null && cacheWrite == null) return null;
34250
+ const count = value => typeof value === "number" ? value.toLocaleString("en-US") : "?";
34251
+ return `🧮 Tokens: ${count((input ?? 0) + (cacheWrite ?? 0))} new in / ${count(cacheRead ?? 0)} cached / ${count(output)} out (last API call)`;
34289
34252
  };
34290
- const formatCacheLine = (input, cacheRead, cacheWrite) => {
34253
+ const formatCacheLine = (input, cacheRead, cacheWrite, usage) => {
34291
34254
  if (!cacheRead && !cacheWrite) return null;
34292
- if ((typeof cacheRead !== "number" || cacheRead <= 0) && (typeof cacheWrite !== "number" || cacheWrite <= 0)) return null;
34293
- const cachedLabel = typeof cacheRead === "number" ? formatTokenCount(cacheRead) : "0";
34294
- const newLabel = typeof cacheWrite === "number" ? formatTokenCount(cacheWrite) : "0";
34295
- const totalInput = (typeof cacheRead === "number" ? cacheRead : 0) + (typeof cacheWrite === "number" ? cacheWrite : 0) + (typeof input === "number" ? input : 0);
34296
- return `🗄️ Cache: ${totalInput > 0 && typeof cacheRead === "number" ? Math.round(cacheRead / totalInput * 100) : 0}% hit · ${cachedLabel} cached, ${newLabel} new`;
34255
+ const total = (input ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0);
34256
+ const count = value => (value ?? 0).toLocaleString("en-US");
34257
+ const ttl = usage?.cacheWrite5m !== undefined || usage?.cacheWrite1h !== undefined ? ` (${count(usage.cacheWrite5m)} 5m / ${count(usage.cacheWrite1h)} 1h)` : "";
34258
+ return `🗄️ Cache: ${total > 0 ? Math.round((cacheRead ?? 0) / total * 100) : 0}% hit · ${count(input)} uncached + ${count(cacheWrite)} written${ttl}`;
34297
34259
  };
34298
34260
  const formatMediaUnderstandingLine = (decisions) => {
34299
34261
  if (!decisions || decisions.length === 0) return null;
@@ -34372,10 +34334,14 @@ function buildStatusMessage(args) {
34372
34334
  let outputTokens = entry?.outputTokens;
34373
34335
  let cacheRead = entry?.cacheRead;
34374
34336
  let cacheWrite = entry?.cacheWrite;
34337
+ let billingUsage;
34375
34338
  let totalTokens = entry?.totalTokens ?? (entry?.inputTokens ?? 0) + (entry?.outputTokens ?? 0);
34376
- if (args.includeTranscriptUsage) {
34339
+ if (entry?.sessionId) { // Always use a coherent latest API call on both status paths.
34377
34340
  const logUsage = readUsageFromSessionLog(entry?.sessionId, entry, args.agentId, args.sessionKey, args.sessionStorePath);
34378
34341
  if (logUsage) {
34342
+ billingUsage = logUsage;
34343
+ cacheRead = logUsage.cacheRead ?? 0;
34344
+ cacheWrite = logUsage.cacheWrite ?? 0;
34379
34345
  const candidate = logUsage.promptTokens || logUsage.total;
34380
34346
  if (!totalTokens || totalTokens === 0 || candidate > totalTokens) totalTokens = candidate;
34381
34347
  if (!entry?.model && logUsage.model) {
@@ -34394,8 +34360,10 @@ function buildStatusMessage(args) {
34394
34360
  model: logUsage.model,
34395
34361
  fallbackContextTokens: contextTokens ?? void 0
34396
34362
  }) ?? contextTokens;
34397
- if (!inputTokens || inputTokens === 0) inputTokens = logUsage.input;
34398
- if (!outputTokens || outputTokens === 0) outputTokens = logUsage.output;
34363
+ inputTokens = logUsage.input ?? 0;
34364
+ outputTokens = logUsage.output ?? 0;
34365
+ if (logUsage.provider) activeProvider = logUsage.provider;
34366
+ if (logUsage.model) activeModel = logUsage.model;
34399
34367
  }
34400
34368
  }
34401
34369
  const thinkLevel = args.resolvedThink ?? args.sessionEntry?.thinkingLevel ?? args.agent?.thinkingDefault ?? "off";
@@ -34431,21 +34399,14 @@ function buildStatusMessage(args) {
34431
34399
  state: entry
34432
34400
  });
34433
34401
  const effectiveCostAuthMode = fallbackState.active ? activeAuthMode : selectedAuthMode ?? activeAuthMode;
34434
- const showCost = effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
34402
+ const showCost = billingUsage?.cost?.total > 0 || effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
34435
34403
  const costConfig = showCost ? resolveModelCostConfig({
34436
34404
  provider: activeProvider,
34437
34405
  model: activeModel,
34438
34406
  config: args.config
34439
34407
  }) : void 0;
34440
- const hasUsage = typeof inputTokens === "number" || typeof outputTokens === "number";
34441
- const cost = showCost && hasUsage ? estimateUsageCost({
34442
- usage: {
34443
- input: inputTokens ?? void 0,
34444
- output: outputTokens ?? void 0
34445
- },
34446
- cost: costConfig
34447
- }) : void 0;
34448
- const costLabel = showCost && hasUsage ? formatUsd(cost) : void 0;
34408
+ const hasUsage = [inputTokens, outputTokens, cacheRead, cacheWrite].some(value => typeof value === "number");
34409
+ billingUsage ??= { input: inputTokens, output: outputTokens, cacheRead, cacheWrite };
34449
34410
  const selectedAuthLabel = selectedAuthLabelValue ? ` · 🔑 ${selectedAuthLabelValue}` : "";
34450
34411
  const channelModelNote = (() => {
34451
34412
  if (!args.config || !entry) return;
@@ -34477,9 +34438,9 @@ function buildStatusMessage(args) {
34477
34438
  const fallbackLine = fallbackState.active ? `↪️ Fallback: ${activeModelLabel}${showFallbackAuth ? ` · 🔑 ${activeAuthLabelValue}` : ""} (${fallbackState.reason ?? "selected model unavailable"})` : null;
34478
34439
  const commit = resolveCommitHash();
34479
34440
  const versionLine = `🦞 Johnness ${VERSION}${commit ? ` (${commit})` : ""}`;
34480
- const usagePair = formatUsagePair(inputTokens, outputTokens);
34481
- const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite);
34482
- const costLine = costLabel ? `💵 Cost: ${costLabel}` : null;
34441
+ const usagePair = formatUsagePair(inputTokens, outputTokens, cacheRead, cacheWrite);
34442
+ const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite, billingUsage);
34443
+ const costLine = showCost && hasUsage ? formatBillingCost(billingUsage, costConfig) : null;
34483
34444
  const usageCostLine = usagePair && costLine ? `${usagePair} · ${costLine}` : usagePair ?? costLine;
34484
34445
  const mediaLine = formatMediaUnderstandingLine(args.mediaDecisions);
34485
34446
  const voiceLine = formatVoiceModeLine(args.config, args.sessionEntry);
@@ -1875,7 +1875,8 @@ function resolveModelCost(raw) {
1875
1875
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
1876
1876
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
1877
1877
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
1878
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
1878
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
1879
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
1879
1880
  };
1880
1881
  }
1881
1882
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -2214,16 +2215,18 @@ function applyContextPruningDefaults(cfg) {
2214
2215
  const nextModels = defaults.models ? { ...defaults.models } : {};
2215
2216
  let modelsMutated = false;
2216
2217
  const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
2218
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
2217
2219
  for (const [key, entry] of Object.entries(nextModels)) {
2218
- if (!isAnthropicCacheRetentionTarget(parseModelRef(key, "anthropic"))) continue;
2220
+ const parsed = parseModelRef(key, "anthropic");
2221
+ if (!isAnthropicCacheRetentionTarget(parsed)) continue;
2219
2222
  const current = entry ?? {};
2220
2223
  const params = current.params ?? {};
2221
- if (typeof params.cacheRetention === "string") continue;
2224
+ if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
2222
2225
  nextModels[key] = {
2223
2226
  ...current,
2224
2227
  params: {
2225
2228
  ...params,
2226
- cacheRetention: "short"
2229
+ cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
2227
2230
  }
2228
2231
  };
2229
2232
  modelsMutated = true;
@@ -2235,12 +2238,12 @@ function applyContextPruningDefaults(cfg) {
2235
2238
  const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
2236
2239
  const current = nextModels[key] ?? {};
2237
2240
  const params = current.params ?? {};
2238
- if (typeof params.cacheRetention !== "string") {
2241
+ if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
2239
2242
  nextModels[key] = {
2240
2243
  ...current,
2241
2244
  params: {
2242
2245
  ...params,
2243
- cacheRetention: "short"
2246
+ cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
2244
2247
  }
2245
2248
  };
2246
2249
  modelsMutated = true;
@@ -5965,7 +5968,8 @@ const ModelDefinitionSchema = z.object({
5965
5968
  input: z.number().optional(),
5966
5969
  output: z.number().optional(),
5967
5970
  cacheRead: z.number().optional(),
5968
- cacheWrite: z.number().optional()
5971
+ cacheWrite: z.number().optional(),
5972
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
5969
5973
  }).strict().optional(),
5970
5974
  contextWindow: z.number().positive().optional(),
5971
5975
  maxTokens: z.number().positive().optional(),
@@ -5027,7 +5027,8 @@ function resolveModelCost(raw) {
5027
5027
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
5028
5028
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
5029
5029
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
5030
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
5030
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
5031
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
5031
5032
  };
5032
5033
  }
5033
5034
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -5366,16 +5367,18 @@ function applyContextPruningDefaults(cfg) {
5366
5367
  const nextModels = defaults.models ? { ...defaults.models } : {};
5367
5368
  let modelsMutated = false;
5368
5369
  const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
5370
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
5369
5371
  for (const [key, entry] of Object.entries(nextModels)) {
5370
- if (!isAnthropicCacheRetentionTarget(parseModelRef(key, "anthropic"))) continue;
5372
+ const parsed = parseModelRef(key, "anthropic");
5373
+ if (!isAnthropicCacheRetentionTarget(parsed)) continue;
5371
5374
  const current = entry ?? {};
5372
5375
  const params = current.params ?? {};
5373
- if (typeof params.cacheRetention === "string") continue;
5376
+ if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
5374
5377
  nextModels[key] = {
5375
5378
  ...current,
5376
5379
  params: {
5377
5380
  ...params,
5378
- cacheRetention: "short"
5381
+ cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
5379
5382
  }
5380
5383
  };
5381
5384
  modelsMutated = true;
@@ -5387,12 +5390,12 @@ function applyContextPruningDefaults(cfg) {
5387
5390
  const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
5388
5391
  const current = nextModels[key] ?? {};
5389
5392
  const params = current.params ?? {};
5390
- if (typeof params.cacheRetention !== "string") {
5393
+ if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
5391
5394
  nextModels[key] = {
5392
5395
  ...current,
5393
5396
  params: {
5394
5397
  ...params,
5395
- cacheRetention: "short"
5398
+ cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
5396
5399
  }
5397
5400
  };
5398
5401
  modelsMutated = true;
@@ -8898,7 +8901,8 @@ const ModelDefinitionSchema = z.object({
8898
8901
  input: z.number().optional(),
8899
8902
  output: z.number().optional(),
8900
8903
  cacheRead: z.number().optional(),
8901
- cacheWrite: z.number().optional()
8904
+ cacheWrite: z.number().optional(),
8905
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
8902
8906
  }).strict().optional(),
8903
8907
  contextWindow: z.number().positive().optional(),
8904
8908
  maxTokens: z.number().positive().optional(),
@@ -1733,7 +1733,8 @@ function resolveModelCost(raw) {
1733
1733
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
1734
1734
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
1735
1735
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
1736
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
1736
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
1737
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
1737
1738
  };
1738
1739
  }
1739
1740
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -2091,16 +2092,18 @@ function applyContextPruningDefaults(cfg) {
2091
2092
  const nextModels = defaults.models ? { ...defaults.models } : {};
2092
2093
  let modelsMutated = false;
2093
2094
  const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
2095
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
2094
2096
  for (const [key, entry] of Object.entries(nextModels)) {
2095
- if (!isAnthropicCacheRetentionTarget(parseModelRef(key, "anthropic"))) continue;
2097
+ const parsed = parseModelRef(key, "anthropic");
2098
+ if (!isAnthropicCacheRetentionTarget(parsed)) continue;
2096
2099
  const current = entry ?? {};
2097
2100
  const params = current.params ?? {};
2098
- if (typeof params.cacheRetention === "string") continue;
2101
+ if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
2099
2102
  nextModels[key] = {
2100
2103
  ...current,
2101
2104
  params: {
2102
2105
  ...params,
2103
- cacheRetention: "short"
2106
+ cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
2104
2107
  }
2105
2108
  };
2106
2109
  modelsMutated = true;
@@ -2112,12 +2115,12 @@ function applyContextPruningDefaults(cfg) {
2112
2115
  const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
2113
2116
  const current = nextModels[key] ?? {};
2114
2117
  const params = current.params ?? {};
2115
- if (typeof params.cacheRetention !== "string") {
2118
+ if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
2116
2119
  nextModels[key] = {
2117
2120
  ...current,
2118
2121
  params: {
2119
2122
  ...params,
2120
- cacheRetention: "short"
2123
+ cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
2121
2124
  }
2122
2125
  };
2123
2126
  modelsMutated = true;
@@ -8510,7 +8513,8 @@ const ModelDefinitionSchema = z.object({
8510
8513
  input: z.number().optional(),
8511
8514
  output: z.number().optional(),
8512
8515
  cacheRead: z.number().optional(),
8513
- cacheWrite: z.number().optional()
8516
+ cacheWrite: z.number().optional(),
8517
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
8514
8518
  }).strict().optional(),
8515
8519
  contextWindow: z.number().positive().optional(),
8516
8520
  maxTokens: z.number().positive().optional(),
@@ -1708,7 +1708,8 @@ function resolveModelCost(raw) {
1708
1708
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
1709
1709
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
1710
1710
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
1711
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
1711
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
1712
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
1712
1713
  };
1713
1714
  }
1714
1715
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -2066,16 +2067,18 @@ function applyContextPruningDefaults(cfg) {
2066
2067
  const nextModels = defaults.models ? { ...defaults.models } : {};
2067
2068
  let modelsMutated = false;
2068
2069
  const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
2070
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
2069
2071
  for (const [key, entry] of Object.entries(nextModels)) {
2070
- if (!isAnthropicCacheRetentionTarget(parseModelRef(key, "anthropic"))) continue;
2072
+ const parsed = parseModelRef(key, "anthropic");
2073
+ if (!isAnthropicCacheRetentionTarget(parsed)) continue;
2071
2074
  const current = entry ?? {};
2072
2075
  const params = current.params ?? {};
2073
- if (typeof params.cacheRetention === "string") continue;
2076
+ if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
2074
2077
  nextModels[key] = {
2075
2078
  ...current,
2076
2079
  params: {
2077
2080
  ...params,
2078
- cacheRetention: "short"
2081
+ cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
2079
2082
  }
2080
2083
  };
2081
2084
  modelsMutated = true;
@@ -2087,12 +2090,12 @@ function applyContextPruningDefaults(cfg) {
2087
2090
  const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
2088
2091
  const current = nextModels[key] ?? {};
2089
2092
  const params = current.params ?? {};
2090
- if (typeof params.cacheRetention !== "string") {
2093
+ if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
2091
2094
  nextModels[key] = {
2092
2095
  ...current,
2093
2096
  params: {
2094
2097
  ...params,
2095
- cacheRetention: "short"
2098
+ cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
2096
2099
  }
2097
2100
  };
2098
2101
  modelsMutated = true;
@@ -8399,7 +8402,8 @@ const ModelDefinitionSchema = z.object({
8399
8402
  input: z.number().optional(),
8400
8403
  output: z.number().optional(),
8401
8404
  cacheRead: z.number().optional(),
8402
- cacheWrite: z.number().optional()
8405
+ cacheWrite: z.number().optional(),
8406
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
8403
8407
  }).strict().optional(),
8404
8408
  contextWindow: z.number().positive().optional(),
8405
8409
  maxTokens: z.number().positive().optional(),
@@ -1639,7 +1639,8 @@ function resolveModelCost(raw) {
1639
1639
  input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
1640
1640
  output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
1641
1641
  cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
1642
- cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
1642
+ cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
1643
+ ...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
1643
1644
  };
1644
1645
  }
1645
1646
  function resolveAnthropicDefaultAuthMode(cfg) {
@@ -1997,16 +1998,18 @@ function applyContextPruningDefaults(cfg) {
1997
1998
  const nextModels = defaults.models ? { ...defaults.models } : {};
1998
1999
  let modelsMutated = false;
1999
2000
  const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
2001
+ // JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
2000
2002
  for (const [key, entry] of Object.entries(nextModels)) {
2001
- if (!isAnthropicCacheRetentionTarget(parseModelRef(key, "anthropic"))) continue;
2003
+ const parsed = parseModelRef(key, "anthropic");
2004
+ if (!isAnthropicCacheRetentionTarget(parsed)) continue;
2002
2005
  const current = entry ?? {};
2003
2006
  const params = current.params ?? {};
2004
- if (typeof params.cacheRetention === "string") continue;
2007
+ if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
2005
2008
  nextModels[key] = {
2006
2009
  ...current,
2007
2010
  params: {
2008
2011
  ...params,
2009
- cacheRetention: "short"
2012
+ cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
2010
2013
  }
2011
2014
  };
2012
2015
  modelsMutated = true;
@@ -2018,12 +2021,12 @@ function applyContextPruningDefaults(cfg) {
2018
2021
  const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
2019
2022
  const current = nextModels[key] ?? {};
2020
2023
  const params = current.params ?? {};
2021
- if (typeof params.cacheRetention !== "string") {
2024
+ if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
2022
2025
  nextModels[key] = {
2023
2026
  ...current,
2024
2027
  params: {
2025
2028
  ...params,
2026
- cacheRetention: "short"
2029
+ cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
2027
2030
  }
2028
2031
  };
2029
2032
  modelsMutated = true;
@@ -6559,7 +6562,8 @@ const ModelDefinitionSchema = z.object({
6559
6562
  input: z.number().optional(),
6560
6563
  output: z.number().optional(),
6561
6564
  cacheRead: z.number().optional(),
6562
- cacheWrite: z.number().optional()
6565
+ cacheWrite: z.number().optional(),
6566
+ cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
6563
6567
  }).strict().optional(),
6564
6568
  contextWindow: z.number().positive().optional(),
6565
6569
  maxTokens: z.number().positive().optional(),