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.
- package/CHANGELOG.md +15 -0
- package/README.md +3 -0
- package/dist/anthropic-auth-runtime.js +62 -0
- package/dist/auth-profiles-5CHn7vq1.js +9 -4
- package/dist/compact-B247y5Qt.js +41 -74
- package/dist/config-koj5M_EO.js +4 -2
- package/dist/daemon-cli.js +4 -2
- package/dist/model-selection-BGlGpPgM.js +9 -4
- package/dist/model-selection-BU6wl1le.js +9 -4
- package/dist/model-selection-L7RMwsG-.js +9 -4
- package/dist/pi-embedded-C6ITuRXf.js +42 -89
- package/dist/pi-embedded-DoQsYfIY.js +42 -89
- package/dist/plugin-sdk/bluebubbles.js +2 -1
- package/dist/plugin-sdk/config/types.models.d.ts +1 -0
- package/dist/plugin-sdk/config/zod-schema.core.d.ts +3 -0
- package/dist/plugin-sdk/config/zod-schema.d.ts +1 -0
- package/dist/plugin-sdk/config-4Fgm-yEH.js +9 -4
- package/dist/plugin-sdk/config-Di-lyCdh.js +9 -4
- package/dist/plugin-sdk/discord.js +4 -2
- package/dist/plugin-sdk/dispatch-BP0viZiL.js +42 -89
- package/dist/plugin-sdk/dispatch-CQsjmw7g.js +42 -89
- package/dist/plugin-sdk/dispatch-Cerq29sy.js +42 -89
- package/dist/plugin-sdk/dispatch-Cndjtt0g.js +42 -89
- package/dist/plugin-sdk/dispatch-UogiJYul.js +42 -89
- package/dist/plugin-sdk/feishu.js +2 -1
- package/dist/plugin-sdk/googlechat.js +2 -1
- package/dist/plugin-sdk/imessage.js +2 -1
- package/dist/plugin-sdk/model-auth-CX9cPHdC.js +9 -4
- package/dist/plugin-sdk/model-auth-Ciehz0x5.js +9 -4
- package/dist/plugin-sdk/model-auth-DVyo6JSX.js +9 -4
- package/dist/plugin-sdk/model-auth-kiHYHGrs.js +9 -4
- package/dist/plugin-sdk/model-selection-Dbj4jDYM.js +8 -3
- package/dist/plugin-sdk/nostr.js +2 -1
- package/dist/plugin-sdk/reply-DbZnH8-h.js +42 -89
- package/dist/plugin-sdk/signal.js +2 -1
- package/dist/plugin-sdk/slack.js +2 -1
- package/dist/plugin-sdk/telegram.js +2 -1
- package/dist/plugin-sdk/tlon.js +2 -1
- package/dist/plugin-sdk/twitch.js +2 -1
- package/dist/plugin-sdk/utils/usage-format.d.ts +1 -0
- package/dist/plugin-sdk/voice-call.js +2 -1
- package/dist/plugin-sdk/zalo.js +2 -1
- package/dist/plugin-sdk/zalouser.js +2 -1
- package/dist/reply-C5LKjXcC.js +41 -74
- package/dist/session-cost-usage-5CCZbVhO.js +4 -19
- package/dist/session-cost-usage-CkCo2kVx.js +4 -19
- package/dist/usage-billing.js +88 -0
- package/dist/usage-format-CNGi1eHQ.js +6 -11
- package/dist/usage-format-CvaU1ntA.js +6 -11
- package/docs/PATCHES.md +54 -1
- package/docs/providers/anthropic.md +23 -2
- package/docs/reference/token-use.md +11 -1
- package/models/models.json +33 -33
- package/node_modules/@mariozechner/pi-ai/dist/models.d.ts +1 -0
- package/node_modules/@mariozechner/pi-ai/dist/models.generated.js +32 -32
- package/node_modules/@mariozechner/pi-ai/dist/models.js +16 -5
- package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +15 -0
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-vertex.js +1 -1
- package/node_modules/@mariozechner/pi-ai/dist/providers/google.js +1 -1
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js +5 -5
- package/node_modules/@mariozechner/pi-ai/dist/types.d.ts +3 -0
- package/node_modules/@mariozechner/pi-coding-agent/dist/core/model-registry.js +3 -0
- package/package.json +1 -1
- package/scripts/models-sync.mjs +1 -0
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.d.ts +25 -0
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.generated.js +32 -32
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.js +16 -5
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/anthropic.js +15 -0
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/google-vertex.js +371 -0
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/google.js +1 -1
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/openai-completions.js +5 -5
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/types.d.ts +282 -0
- package/vendor/patched-deps/@mariozechner/pi-coding-agent/dist/core/model-registry.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026.10.23
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Claude subscription credentials stay current after OAuth token rotation. A long-running gateway no longer retries a spent token from its startup snapshot and silently serves the request with the paid API key. Existing sessions use the current subscription credential without a reload or a new session.
|
|
7
|
+
- `/status` and `session_status` explain subscription-to-API fallback, including model unavailable, token refresh failure, authentication, quota and cooldown. The actual served profile stays visible, and the fallback annotation clears after subscription recovery. Explicit API-key selections remain explicit.
|
|
8
|
+
- Anthropic credential refresh rereads the auth store under its lock. Local-agent account precedence, resolved API SecretRefs, Codex ownership, subscription-zero accounting and the existing fallback policy are preserved.
|
|
9
|
+
|
|
10
|
+
## 2026.10.22
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- `/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.
|
|
14
|
+
- 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.
|
|
15
|
+
- 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.
|
|
16
|
+
- 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.
|
|
17
|
+
|
|
3
18
|
## 2026.10.21
|
|
4
19
|
|
|
5
20
|
- **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.
|
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 |
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
2
|
+
// OAuth generations rotate independently of SecretRef activation. Never log credential material.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { readAuthStore } from './auth-store-transactions.js';
|
|
5
|
+
|
|
6
|
+
const isClaudeOAuth = c => c?.provider === 'anthropic' && c.type === 'oauth';
|
|
7
|
+
export function readCurrentAnthropicAuth({ store, mainAgentDir, agentDir }) {
|
|
8
|
+
const ids = Object.keys(store.profiles ?? {}).filter(id => isClaudeOAuth(store.profiles[id]));
|
|
9
|
+
if (!ids.length) return store;
|
|
10
|
+
const mainPath = path.join(mainAgentDir, 'auth-profiles.json');
|
|
11
|
+
const localPath = path.join(agentDir ?? mainAgentDir, 'auth-profiles.json');
|
|
12
|
+
const main = readAuthStore(mainPath);
|
|
13
|
+
const local = localPath === mainPath ? main : readAuthStore(localPath);
|
|
14
|
+
for (const id of ids) {
|
|
15
|
+
// Local accounts stay local. Deletion, logout or a type change must not resurrect a snapshot.
|
|
16
|
+
const owner = Object.hasOwn(local.profiles, id) ? local : main;
|
|
17
|
+
const current = owner.profiles[id];
|
|
18
|
+
if (isClaudeOAuth(current)) store.profiles[id] = structuredClone(current);
|
|
19
|
+
else delete store.profiles[id];
|
|
20
|
+
store.usageStats ??= {};
|
|
21
|
+
if (owner.usageStats?.[id]) store.usageStats[id] = structuredClone(owner.usageStats[id]);
|
|
22
|
+
else delete store.usageStats[id];
|
|
23
|
+
}
|
|
24
|
+
// New logins still activate through Family 89. API SecretRefs and Codex ownership are untouched.
|
|
25
|
+
return store;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const REASONS = Object.freeze({
|
|
29
|
+
auth: 'subscription authentication rejected',
|
|
30
|
+
billing: 'subscription quota or billing rejected',
|
|
31
|
+
rate_limit: 'subscription rate limited',
|
|
32
|
+
overloaded: 'subscription endpoint overloaded',
|
|
33
|
+
timeout: 'subscription request timed out',
|
|
34
|
+
model_not_found: 'model unavailable on subscription',
|
|
35
|
+
cooldown: 'subscription in cooldown',
|
|
36
|
+
credential_unavailable: 'subscription credential unavailable',
|
|
37
|
+
oauth_refresh_failed: 'subscription token refresh failed',
|
|
38
|
+
unknown: 'subscription request failed'
|
|
39
|
+
});
|
|
40
|
+
export function createSubscriptionAuthTracker({ provider, model, store, preferredProfileId, lockedProfileId }) {
|
|
41
|
+
const requested = isClaudeOAuth(store.profiles?.[preferredProfileId]) ? preferredProfileId : 'anthropic:subscription';
|
|
42
|
+
const enabled = provider === 'anthropic' && isClaudeOAuth(store.profiles?.[requested]) && (!lockedProfileId || lockedProfileId === requested);
|
|
43
|
+
let reason;
|
|
44
|
+
return {
|
|
45
|
+
failed(profileId, value) {
|
|
46
|
+
if (!enabled || profileId !== requested) return;
|
|
47
|
+
// Whitelisted categories only: endpoint bodies can contain secrets or untrusted text.
|
|
48
|
+
reason = Object.hasOwn(REASONS, value) ? value : 'unknown';
|
|
49
|
+
},
|
|
50
|
+
result(profileId) {
|
|
51
|
+
if (!enabled || profileId === requested || store.profiles?.[profileId]?.type !== 'api_key') return null;
|
|
52
|
+
const stats = store.usageStats?.[requested];
|
|
53
|
+
const cooled = Math.max(stats?.cooldownUntil ?? 0, stats?.disabledUntil ?? 0) > Date.now();
|
|
54
|
+
return { fromProfileId: requested, toProfileId: profileId, model, reason: reason ?? (cooled ? 'cooldown' : 'credential_unavailable') };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function formatAuthProfileFallback(entry, profileId) {
|
|
59
|
+
const fallback = entry?.authProfileFallback;
|
|
60
|
+
if (!fallback || fallback.toProfileId !== profileId || !Object.hasOwn(REASONS, fallback.reason)) return '';
|
|
61
|
+
return ` [API fallback: ${REASONS[fallback.reason]}]`;
|
|
62
|
+
}
|
|
@@ -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";
|
|
@@ -4235,8 +4236,10 @@ function codexOwnershipContext(agentDir) {
|
|
|
4235
4236
|
log: (event) => log$8.info("Codex OAuth ownership", event)
|
|
4236
4237
|
};
|
|
4237
4238
|
}
|
|
4239
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
4238
4240
|
function readCodexOwnedAuthStore(agentDir, store) {
|
|
4239
|
-
|
|
4241
|
+
const context = codexOwnershipContext(agentDir);
|
|
4242
|
+
return readCurrentAnthropicAuth({ ...context, store: readManagedCodexStore({ ...context, store }) });
|
|
4240
4243
|
}
|
|
4241
4244
|
function sanitizeAuthProfileCredential(credential) {
|
|
4242
4245
|
const sanitized = { ...credential };
|
|
@@ -5181,7 +5184,8 @@ function resolveModelCost(raw) {
|
|
|
5181
5184
|
input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
|
|
5182
5185
|
output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
|
|
5183
5186
|
cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
|
|
5184
|
-
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
|
|
5187
|
+
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
|
|
5188
|
+
...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
5185
5189
|
};
|
|
5186
5190
|
}
|
|
5187
5191
|
function resolveAnthropicDefaultAuthMode(cfg) {
|
|
@@ -10084,7 +10088,8 @@ const ModelDefinitionSchema = z.object({
|
|
|
10084
10088
|
input: z.number().optional(),
|
|
10085
10089
|
output: z.number().optional(),
|
|
10086
10090
|
cacheRead: z.number().optional(),
|
|
10087
|
-
cacheWrite: z.number().optional()
|
|
10091
|
+
cacheWrite: z.number().optional(),
|
|
10092
|
+
cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
10088
10093
|
}).strict().optional(),
|
|
10089
10094
|
contextWindow: z.number().positive().optional(),
|
|
10090
10095
|
maxTokens: z.number().positive().optional(),
|
|
@@ -16460,7 +16465,7 @@ async function refreshUnmanagedOAuthTokenWithLock(params) {
|
|
|
16460
16465
|
const authPath = resolveAuthStorePath(params.agentDir);
|
|
16461
16466
|
fs.mkdirSync(path.dirname(authPath), { recursive: true, mode: 448 });
|
|
16462
16467
|
return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
|
|
16463
|
-
const store =
|
|
16468
|
+
const store = loadAuthProfileStoreForRuntime(params.agentDir, { allowKeychainPrompt: false }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92: reread under lock
|
|
16464
16469
|
const cred = store.profiles[params.profileId];
|
|
16465
16470
|
if (cred?.provider === "openai-codex") throw new Error("Auth profile changed to Codex; resolve again through its owner");
|
|
16466
16471
|
if (!cred || cred.type !== "oauth") return null;
|
package/dist/compact-B247y5Qt.js
CHANGED
|
@@ -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/compact-B247y5Qt.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";
|
|
@@ -8500,6 +8502,8 @@ function normalizeAssistantUsageSnapshot(usage) {
|
|
|
8500
8502
|
cacheRead,
|
|
8501
8503
|
cacheWrite,
|
|
8502
8504
|
totalTokens,
|
|
8505
|
+
...normalized.cacheWrite5m !== undefined ? { cacheWrite5m: normalized.cacheWrite5m } : {},
|
|
8506
|
+
...normalized.cacheWrite1h !== undefined ? { cacheWrite1h: normalized.cacheWrite1h } : {},
|
|
8503
8507
|
...cost ? { cost } : {}
|
|
8504
8508
|
};
|
|
8505
8509
|
}
|
|
@@ -18431,6 +18435,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
18431
18435
|
});
|
|
18432
18436
|
if (lockedProfileId && !profileOrder.includes(lockedProfileId)) throw new Error(`Auth profile "${lockedProfileId}" is not configured for ${provider}.`);
|
|
18433
18437
|
const profileCandidates = lockedProfileId ? [lockedProfileId] : profileOrder.length > 0 ? profileOrder : [void 0];
|
|
18438
|
+
const subscriptionAuth = createSubscriptionAuthTracker({ provider, model: modelId, store: authStore, preferredProfileId, lockedProfileId }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
18434
18439
|
let profileIndex = 0;
|
|
18435
18440
|
const initialThinkLevel = params.thinkLevel ?? "off";
|
|
18436
18441
|
let thinkLevel = initialThinkLevel;
|
|
@@ -18562,7 +18567,8 @@ async function runEmbeddedPiAgent(params) {
|
|
|
18562
18567
|
} else authStorage.setRuntimeApiKey(model.provider, apiKeyInfo.apiKey);
|
|
18563
18568
|
lastProfileId = apiKeyInfo.profileId;
|
|
18564
18569
|
};
|
|
18565
|
-
const advanceAuthProfile = async () => {
|
|
18570
|
+
const advanceAuthProfile = async (reason) => {
|
|
18571
|
+
subscriptionAuth.failed(profileCandidates[profileIndex], reason);
|
|
18566
18572
|
if (lockedProfileId) return false;
|
|
18567
18573
|
let nextIndex = profileIndex + 1;
|
|
18568
18574
|
while (nextIndex < profileCandidates.length) {
|
|
@@ -18612,7 +18618,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
18612
18618
|
allInCooldown: false,
|
|
18613
18619
|
error: err
|
|
18614
18620
|
});
|
|
18615
|
-
if (!await advanceAuthProfile()) throwAuthProfileFailover({
|
|
18621
|
+
if (!await advanceAuthProfile(/refresh/i.test(String(err)) ? "oauth_refresh_failed" : "credential_unavailable")) throwAuthProfileFailover({
|
|
18616
18622
|
allInCooldown: false,
|
|
18617
18623
|
error: err
|
|
18618
18624
|
});
|
|
@@ -18984,7 +18990,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
18984
18990
|
reason: promptProfileFailureReason
|
|
18985
18991
|
});
|
|
18986
18992
|
const promptFailoverFailure = isFailoverErrorMessage(errorText);
|
|
18987
|
-
if (promptFailoverFailure && promptFailoverReason !== "timeout" && await advanceAuthProfile()) {
|
|
18993
|
+
if (promptFailoverFailure && promptFailoverReason !== "timeout" && await advanceAuthProfile(promptFailoverReason)) {
|
|
18988
18994
|
await maybeBackoffBeforeOverloadFailover(promptFailoverReason);
|
|
18989
18995
|
continue;
|
|
18990
18996
|
}
|
|
@@ -19047,7 +19053,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
19047
19053
|
if (timedOut && !isProbeSession) log$16.warn(`Profile ${lastProfileId} timed out. Trying next account...`);
|
|
19048
19054
|
if (cloudCodeAssistFormatError) log$16.warn(`Profile ${lastProfileId} hit Cloud Code Assist format error. Tool calls will be sanitized on retry.`);
|
|
19049
19055
|
}
|
|
19050
|
-
if (await advanceAuthProfile()) {
|
|
19056
|
+
if (await advanceAuthProfile(timedOut ? "timeout" : assistantFailoverReason)) {
|
|
19051
19057
|
await maybeBackoffBeforeOverloadFailover(assistantFailoverReason);
|
|
19052
19058
|
continue;
|
|
19053
19059
|
}
|
|
@@ -19081,6 +19087,7 @@ async function runEmbeddedPiAgent(params) {
|
|
|
19081
19087
|
lastCallUsage: lastCallUsage ?? void 0,
|
|
19082
19088
|
promptTokens,
|
|
19083
19089
|
compactionCount: autoCompactionCount > 0 ? autoCompactionCount : void 0,
|
|
19090
|
+
authProfileFallback: subscriptionAuth.result(lastProfileId), // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
19084
19091
|
authProfileId: lastProfileId // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89: profile that served this turn
|
|
19085
19092
|
};
|
|
19086
19093
|
const payloads = buildEmbeddedRunPayloads({
|
|
@@ -34240,62 +34247,19 @@ const readUsageFromSessionLog = (sessionId, sessionEntry, agentId, sessionKey, s
|
|
|
34240
34247
|
} catch {
|
|
34241
34248
|
return;
|
|
34242
34249
|
}
|
|
34243
|
-
|
|
34244
|
-
try {
|
|
34245
|
-
const TAIL_BYTES = 8192;
|
|
34246
|
-
const stat = fs.statSync(logPath);
|
|
34247
|
-
const offset = Math.max(0, stat.size - TAIL_BYTES);
|
|
34248
|
-
const buf = Buffer.alloc(Math.min(TAIL_BYTES, stat.size));
|
|
34249
|
-
const fd = fs.openSync(logPath, "r");
|
|
34250
|
-
try {
|
|
34251
|
-
fs.readSync(fd, buf, 0, buf.length, offset);
|
|
34252
|
-
} finally {
|
|
34253
|
-
fs.closeSync(fd);
|
|
34254
|
-
}
|
|
34255
|
-
const tail = buf.toString("utf-8");
|
|
34256
|
-
const lines = (offset > 0 ? tail.slice(tail.indexOf("\n") + 1) : tail).split(/\n+/);
|
|
34257
|
-
let input = 0;
|
|
34258
|
-
let output = 0;
|
|
34259
|
-
let promptTokens = 0;
|
|
34260
|
-
let model;
|
|
34261
|
-
let lastUsage;
|
|
34262
|
-
for (const line of lines) {
|
|
34263
|
-
if (!line.trim()) continue;
|
|
34264
|
-
try {
|
|
34265
|
-
const parsed = JSON.parse(line);
|
|
34266
|
-
const usage = normalizeUsage(parsed.message?.usage ?? parsed.usage);
|
|
34267
|
-
if (usage) lastUsage = usage;
|
|
34268
|
-
model = parsed.message?.model ?? parsed.model ?? model;
|
|
34269
|
-
} catch {}
|
|
34270
|
-
}
|
|
34271
|
-
if (!lastUsage) return;
|
|
34272
|
-
input = lastUsage.input ?? 0;
|
|
34273
|
-
output = lastUsage.output ?? 0;
|
|
34274
|
-
promptTokens = derivePromptTokens(lastUsage) ?? lastUsage.total ?? input + output;
|
|
34275
|
-
const total = lastUsage.total ?? promptTokens + output;
|
|
34276
|
-
if (promptTokens === 0 && total === 0) return;
|
|
34277
|
-
return {
|
|
34278
|
-
input,
|
|
34279
|
-
output,
|
|
34280
|
-
promptTokens,
|
|
34281
|
-
total,
|
|
34282
|
-
model
|
|
34283
|
-
};
|
|
34284
|
-
} catch {
|
|
34285
|
-
return;
|
|
34286
|
-
}
|
|
34250
|
+
return readLatestBillingUsage(logPath);
|
|
34287
34251
|
};
|
|
34288
|
-
const formatUsagePair = (input, output) => {
|
|
34289
|
-
if (input == null && output == null) return null;
|
|
34290
|
-
|
|
34252
|
+
const formatUsagePair = (input, output, cacheRead, cacheWrite) => {
|
|
34253
|
+
if (input == null && output == null && cacheRead == null && cacheWrite == null) return null;
|
|
34254
|
+
const count = value => typeof value === "number" ? value.toLocaleString("en-US") : "?";
|
|
34255
|
+
return `🧮 Tokens: ${count((input ?? 0) + (cacheWrite ?? 0))} new in / ${count(cacheRead ?? 0)} cached / ${count(output)} out (last API call)`;
|
|
34291
34256
|
};
|
|
34292
|
-
const formatCacheLine = (input, cacheRead, cacheWrite) => {
|
|
34257
|
+
const formatCacheLine = (input, cacheRead, cacheWrite, usage) => {
|
|
34293
34258
|
if (!cacheRead && !cacheWrite) return null;
|
|
34294
|
-
|
|
34295
|
-
const
|
|
34296
|
-
const
|
|
34297
|
-
|
|
34298
|
-
return `🗄️ Cache: ${totalInput > 0 && typeof cacheRead === "number" ? Math.round(cacheRead / totalInput * 100) : 0}% hit · ${cachedLabel} cached, ${newLabel} new`;
|
|
34259
|
+
const total = (input ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0);
|
|
34260
|
+
const count = value => (value ?? 0).toLocaleString("en-US");
|
|
34261
|
+
const ttl = usage?.cacheWrite5m !== undefined || usage?.cacheWrite1h !== undefined ? ` (${count(usage.cacheWrite5m)} 5m / ${count(usage.cacheWrite1h)} 1h)` : "";
|
|
34262
|
+
return `🗄️ Cache: ${total > 0 ? Math.round((cacheRead ?? 0) / total * 100) : 0}% hit · ${count(input)} uncached + ${count(cacheWrite)} written${ttl}`;
|
|
34299
34263
|
};
|
|
34300
34264
|
const formatMediaUnderstandingLine = (decisions) => {
|
|
34301
34265
|
if (!decisions || decisions.length === 0) return null;
|
|
@@ -34374,10 +34338,14 @@ function buildStatusMessage(args) {
|
|
|
34374
34338
|
let outputTokens = entry?.outputTokens;
|
|
34375
34339
|
let cacheRead = entry?.cacheRead;
|
|
34376
34340
|
let cacheWrite = entry?.cacheWrite;
|
|
34341
|
+
let billingUsage;
|
|
34377
34342
|
let totalTokens = entry?.totalTokens ?? (entry?.inputTokens ?? 0) + (entry?.outputTokens ?? 0);
|
|
34378
|
-
if (
|
|
34343
|
+
if (entry?.sessionId) { // Always use a coherent latest API call on both status paths.
|
|
34379
34344
|
const logUsage = readUsageFromSessionLog(entry?.sessionId, entry, args.agentId, args.sessionKey, args.sessionStorePath);
|
|
34380
34345
|
if (logUsage) {
|
|
34346
|
+
billingUsage = logUsage;
|
|
34347
|
+
cacheRead = logUsage.cacheRead ?? 0;
|
|
34348
|
+
cacheWrite = logUsage.cacheWrite ?? 0;
|
|
34381
34349
|
const candidate = logUsage.promptTokens || logUsage.total;
|
|
34382
34350
|
if (!totalTokens || totalTokens === 0 || candidate > totalTokens) totalTokens = candidate;
|
|
34383
34351
|
if (!entry?.model && logUsage.model) {
|
|
@@ -34396,8 +34364,10 @@ function buildStatusMessage(args) {
|
|
|
34396
34364
|
model: logUsage.model,
|
|
34397
34365
|
fallbackContextTokens: contextTokens ?? void 0
|
|
34398
34366
|
}) ?? contextTokens;
|
|
34399
|
-
|
|
34400
|
-
|
|
34367
|
+
inputTokens = logUsage.input ?? 0;
|
|
34368
|
+
outputTokens = logUsage.output ?? 0;
|
|
34369
|
+
if (logUsage.provider) activeProvider = logUsage.provider;
|
|
34370
|
+
if (logUsage.model) activeModel = logUsage.model;
|
|
34401
34371
|
}
|
|
34402
34372
|
}
|
|
34403
34373
|
const thinkLevel = args.resolvedThink ?? args.sessionEntry?.thinkingLevel ?? args.agent?.thinkingDefault ?? "off";
|
|
@@ -34433,21 +34403,14 @@ function buildStatusMessage(args) {
|
|
|
34433
34403
|
state: entry
|
|
34434
34404
|
});
|
|
34435
34405
|
const effectiveCostAuthMode = fallbackState.active ? activeAuthMode : selectedAuthMode ?? activeAuthMode;
|
|
34436
|
-
const showCost = effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
|
|
34406
|
+
const showCost = billingUsage?.cost?.total > 0 || effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
|
|
34437
34407
|
const costConfig = showCost ? resolveModelCostConfig({
|
|
34438
34408
|
provider: activeProvider,
|
|
34439
34409
|
model: activeModel,
|
|
34440
34410
|
config: args.config
|
|
34441
34411
|
}) : void 0;
|
|
34442
|
-
const hasUsage =
|
|
34443
|
-
|
|
34444
|
-
usage: {
|
|
34445
|
-
input: inputTokens ?? void 0,
|
|
34446
|
-
output: outputTokens ?? void 0
|
|
34447
|
-
},
|
|
34448
|
-
cost: costConfig
|
|
34449
|
-
}) : void 0;
|
|
34450
|
-
const costLabel = showCost && hasUsage ? formatUsd(cost) : void 0;
|
|
34412
|
+
const hasUsage = [inputTokens, outputTokens, cacheRead, cacheWrite].some(value => typeof value === "number");
|
|
34413
|
+
billingUsage ??= { input: inputTokens, output: outputTokens, cacheRead, cacheWrite };
|
|
34451
34414
|
const selectedAuthLabel = selectedAuthLabelValue ? ` · 🔑 ${selectedAuthLabelValue}` : "";
|
|
34452
34415
|
const channelModelNote = (() => {
|
|
34453
34416
|
if (!args.config || !entry) return;
|
|
@@ -34479,9 +34442,9 @@ function buildStatusMessage(args) {
|
|
|
34479
34442
|
const fallbackLine = fallbackState.active ? `↪️ Fallback: ${activeModelLabel}${showFallbackAuth ? ` · 🔑 ${activeAuthLabelValue}` : ""} (${fallbackState.reason ?? "selected model unavailable"})` : null;
|
|
34480
34443
|
const commit = resolveCommitHash();
|
|
34481
34444
|
const versionLine = `🦞 Johnness ${VERSION}${commit ? ` (${commit})` : ""}`;
|
|
34482
|
-
const usagePair = formatUsagePair(inputTokens, outputTokens);
|
|
34483
|
-
const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite);
|
|
34484
|
-
const costLine =
|
|
34445
|
+
const usagePair = formatUsagePair(inputTokens, outputTokens, cacheRead, cacheWrite);
|
|
34446
|
+
const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite, billingUsage);
|
|
34447
|
+
const costLine = showCost && hasUsage ? formatBillingCost(billingUsage, costConfig) : null;
|
|
34485
34448
|
const usageCostLine = usagePair && costLine ? `${usagePair} · ${costLine}` : usagePair ?? costLine;
|
|
34486
34449
|
const mediaLine = formatMediaUnderstandingLine(args.mediaDecisions);
|
|
34487
34450
|
const voiceLine = formatVoiceModeLine(args.config, args.sessionEntry);
|
|
@@ -35916,7 +35879,7 @@ function resolveModelAuthLabel(params) {
|
|
|
35916
35879
|
});
|
|
35917
35880
|
if (profile.type === "oauth") return `oauth${label ? ` (${label})` : ""}`;
|
|
35918
35881
|
if (profile.type === "token") return `token${label ? ` (${label})` : ""}`;
|
|
35919
|
-
return `api-key${label ? ` (${label})` : ""}`;
|
|
35882
|
+
return `api-key${label ? ` (${label})` : ""}${formatAuthProfileFallback(params.sessionEntry, profileId)}`;
|
|
35920
35883
|
}
|
|
35921
35884
|
const envKey = resolveEnvApiKey(providerKey);
|
|
35922
35885
|
if (envKey?.apiKey) {
|
|
@@ -58651,6 +58614,7 @@ async function persistSessionUsageUpdate(params) {
|
|
|
58651
58614
|
modelProvider: params.providerUsed ?? entry.modelProvider,
|
|
58652
58615
|
model: params.modelUsed ?? entry.model,
|
|
58653
58616
|
authProfileServed: params.authProfileServed ?? entry.authProfileServed, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
|
|
58617
|
+
authProfileFallback: params.authProfileFallback ?? null, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
58654
58618
|
contextTokens: resolvedContextTokens,
|
|
58655
58619
|
systemPromptReport: params.systemPromptReport ?? entry.systemPromptReport,
|
|
58656
58620
|
updatedAt: Date.now()
|
|
@@ -58931,6 +58895,7 @@ function createFollowupRunner(params) {
|
|
|
58931
58895
|
modelUsed,
|
|
58932
58896
|
providerUsed: fallbackProvider,
|
|
58933
58897
|
authProfileServed: runResult.meta?.agentMeta?.authProfileId, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
|
|
58898
|
+
authProfileFallback: runResult.meta?.agentMeta?.authProfileFallback, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
58934
58899
|
contextTokensUsed,
|
|
58935
58900
|
systemPromptReport: runResult.meta?.systemPromptReport,
|
|
58936
58901
|
logLabel: "followup"
|
|
@@ -59269,6 +59234,7 @@ async function runReplyAgent(params) {
|
|
|
59269
59234
|
modelUsed,
|
|
59270
59235
|
providerUsed,
|
|
59271
59236
|
authProfileServed: runResult.meta?.agentMeta?.authProfileId, // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
|
|
59237
|
+
authProfileFallback: runResult.meta?.agentMeta?.authProfileFallback, // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
59272
59238
|
contextTokensUsed,
|
|
59273
59239
|
systemPromptReport: runResult.meta?.systemPromptReport,
|
|
59274
59240
|
cliSessionId
|
|
@@ -72263,6 +72229,7 @@ async function updateSessionStoreAfterAgentRun(params) {
|
|
|
72263
72229
|
model: modelUsed
|
|
72264
72230
|
});
|
|
72265
72231
|
if (result.meta.agentMeta?.authProfileId) next.authProfileServed = result.meta.agentMeta.authProfileId; // JOHNNESS_PATCH_SUBSCRIPTION_ACTIVATE_89
|
|
72232
|
+
next.authProfileFallback = result.meta.agentMeta?.authProfileFallback ?? null; // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
72266
72233
|
if (isCliProvider(providerUsed, cfg)) {
|
|
72267
72234
|
const cliSessionId = result.meta.agentMeta?.sessionId?.trim();
|
|
72268
72235
|
if (cliSessionId) setCliSessionId(next, providerUsed, cliSessionId);
|
package/dist/config-koj5M_EO.js
CHANGED
|
@@ -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) {
|
|
@@ -5967,7 +5968,8 @@ const ModelDefinitionSchema = z.object({
|
|
|
5967
5968
|
input: z.number().optional(),
|
|
5968
5969
|
output: z.number().optional(),
|
|
5969
5970
|
cacheRead: z.number().optional(),
|
|
5970
|
-
cacheWrite: z.number().optional()
|
|
5971
|
+
cacheWrite: z.number().optional(),
|
|
5972
|
+
cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
5971
5973
|
}).strict().optional(),
|
|
5972
5974
|
contextWindow: z.number().positive().optional(),
|
|
5973
5975
|
maxTokens: z.number().positive().optional(),
|
package/dist/daemon-cli.js
CHANGED
|
@@ -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) {
|
|
@@ -8900,7 +8901,8 @@ const ModelDefinitionSchema = z.object({
|
|
|
8900
8901
|
input: z.number().optional(),
|
|
8901
8902
|
output: z.number().optional(),
|
|
8902
8903
|
cacheRead: z.number().optional(),
|
|
8903
|
-
cacheWrite: z.number().optional()
|
|
8904
|
+
cacheWrite: z.number().optional(),
|
|
8905
|
+
cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
8904
8906
|
}).strict().optional(),
|
|
8905
8907
|
contextWindow: z.number().positive().optional(),
|
|
8906
8908
|
maxTokens: z.number().positive().optional(),
|
|
@@ -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";
|
|
@@ -563,8 +564,10 @@ function codexOwnershipContext(agentDir) {
|
|
|
563
564
|
log: (event) => log$10.info("Codex OAuth ownership", event)
|
|
564
565
|
};
|
|
565
566
|
}
|
|
567
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
566
568
|
function readCodexOwnedAuthStore(agentDir, store) {
|
|
567
|
-
|
|
569
|
+
const context = codexOwnershipContext(agentDir);
|
|
570
|
+
return readCurrentAnthropicAuth({ ...context, store: readManagedCodexStore({ ...context, store }) });
|
|
568
571
|
}
|
|
569
572
|
function sanitizeAuthProfileCredential(credential) {
|
|
570
573
|
const sanitized = { ...credential };
|
|
@@ -1733,7 +1736,8 @@ function resolveModelCost(raw) {
|
|
|
1733
1736
|
input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
|
|
1734
1737
|
output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
|
|
1735
1738
|
cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
|
|
1736
|
-
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
|
|
1739
|
+
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
|
|
1740
|
+
...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
1737
1741
|
};
|
|
1738
1742
|
}
|
|
1739
1743
|
function resolveAnthropicDefaultAuthMode(cfg) {
|
|
@@ -8512,7 +8516,8 @@ const ModelDefinitionSchema = z.object({
|
|
|
8512
8516
|
input: z.number().optional(),
|
|
8513
8517
|
output: z.number().optional(),
|
|
8514
8518
|
cacheRead: z.number().optional(),
|
|
8515
|
-
cacheWrite: z.number().optional()
|
|
8519
|
+
cacheWrite: z.number().optional(),
|
|
8520
|
+
cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
8516
8521
|
}).strict().optional(),
|
|
8517
8522
|
contextWindow: z.number().positive().optional(),
|
|
8518
8523
|
maxTokens: z.number().positive().optional(),
|
|
@@ -14675,7 +14680,7 @@ async function refreshUnmanagedOAuthTokenWithLock(params) {
|
|
|
14675
14680
|
const authPath = resolveAuthStorePath(params.agentDir);
|
|
14676
14681
|
syncFs.mkdirSync(path.dirname(authPath), { recursive: true, mode: 448 });
|
|
14677
14682
|
return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
|
|
14678
|
-
const store =
|
|
14683
|
+
const store = loadAuthProfileStoreForRuntime(params.agentDir, { allowKeychainPrompt: false }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92: reread under lock
|
|
14679
14684
|
const cred = store.profiles[params.profileId];
|
|
14680
14685
|
if (cred?.provider === "openai-codex") throw new Error("Auth profile changed to Codex; resolve again through its owner");
|
|
14681
14686
|
if (!cred || cred.type !== "oauth") return null;
|
|
@@ -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";
|
|
@@ -566,8 +567,10 @@ function codexOwnershipContext(agentDir) {
|
|
|
566
567
|
log: (event) => log$9.info("Codex OAuth ownership", event)
|
|
567
568
|
};
|
|
568
569
|
}
|
|
570
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
569
571
|
function readCodexOwnedAuthStore(agentDir, store) {
|
|
570
|
-
|
|
572
|
+
const context = codexOwnershipContext(agentDir);
|
|
573
|
+
return readCurrentAnthropicAuth({ ...context, store: readManagedCodexStore({ ...context, store }) });
|
|
571
574
|
}
|
|
572
575
|
function sanitizeAuthProfileCredential(credential) {
|
|
573
576
|
const sanitized = { ...credential };
|
|
@@ -1708,7 +1711,8 @@ function resolveModelCost(raw) {
|
|
|
1708
1711
|
input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
|
|
1709
1712
|
output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
|
|
1710
1713
|
cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
|
|
1711
|
-
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
|
|
1714
|
+
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
|
|
1715
|
+
...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
1712
1716
|
};
|
|
1713
1717
|
}
|
|
1714
1718
|
function resolveAnthropicDefaultAuthMode(cfg) {
|
|
@@ -8401,7 +8405,8 @@ const ModelDefinitionSchema = z.object({
|
|
|
8401
8405
|
input: z.number().optional(),
|
|
8402
8406
|
output: z.number().optional(),
|
|
8403
8407
|
cacheRead: z.number().optional(),
|
|
8404
|
-
cacheWrite: z.number().optional()
|
|
8408
|
+
cacheWrite: z.number().optional(),
|
|
8409
|
+
cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
8405
8410
|
}).strict().optional(),
|
|
8406
8411
|
contextWindow: z.number().positive().optional(),
|
|
8407
8412
|
maxTokens: z.number().positive().optional(),
|
|
@@ -14564,7 +14569,7 @@ async function refreshUnmanagedOAuthTokenWithLock(params) {
|
|
|
14564
14569
|
const authPath = resolveAuthStorePath(params.agentDir);
|
|
14565
14570
|
fs$1.mkdirSync(path.dirname(authPath), { recursive: true, mode: 448 });
|
|
14566
14571
|
return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
|
|
14567
|
-
const store =
|
|
14572
|
+
const store = loadAuthProfileStoreForRuntime(params.agentDir, { allowKeychainPrompt: false }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92: reread under lock
|
|
14568
14573
|
const cred = store.profiles[params.profileId];
|
|
14569
14574
|
if (cred?.provider === "openai-codex") throw new Error("Auth profile changed to Codex; resolve again through its owner");
|
|
14570
14575
|
if (!cred || cred.type !== "oauth") return null;
|
|
@@ -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";
|
|
@@ -457,8 +458,10 @@ function codexOwnershipContext(agentDir) {
|
|
|
457
458
|
log: (event) => log$8.info("Codex OAuth ownership", event)
|
|
458
459
|
};
|
|
459
460
|
}
|
|
461
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92
|
|
460
462
|
function readCodexOwnedAuthStore(agentDir, store) {
|
|
461
|
-
|
|
463
|
+
const context = codexOwnershipContext(agentDir);
|
|
464
|
+
return readCurrentAnthropicAuth({ ...context, store: readManagedCodexStore({ ...context, store }) });
|
|
462
465
|
}
|
|
463
466
|
function sanitizeAuthProfileCredential(credential) {
|
|
464
467
|
const sanitized = { ...credential };
|
|
@@ -1639,7 +1642,8 @@ function resolveModelCost(raw) {
|
|
|
1639
1642
|
input: typeof raw?.input === "number" ? raw.input : DEFAULT_MODEL_COST.input,
|
|
1640
1643
|
output: typeof raw?.output === "number" ? raw.output : DEFAULT_MODEL_COST.output,
|
|
1641
1644
|
cacheRead: typeof raw?.cacheRead === "number" ? raw.cacheRead : DEFAULT_MODEL_COST.cacheRead,
|
|
1642
|
-
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite
|
|
1645
|
+
cacheWrite: typeof raw?.cacheWrite === "number" ? raw.cacheWrite : DEFAULT_MODEL_COST.cacheWrite,
|
|
1646
|
+
...typeof raw?.cacheWrite1h === "number" ? { cacheWrite1h: raw.cacheWrite1h } : {} // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
1643
1647
|
};
|
|
1644
1648
|
}
|
|
1645
1649
|
function resolveAnthropicDefaultAuthMode(cfg) {
|
|
@@ -6561,7 +6565,8 @@ const ModelDefinitionSchema = z.object({
|
|
|
6561
6565
|
input: z.number().optional(),
|
|
6562
6566
|
output: z.number().optional(),
|
|
6563
6567
|
cacheRead: z.number().optional(),
|
|
6564
|
-
cacheWrite: z.number().optional()
|
|
6568
|
+
cacheWrite: z.number().optional(),
|
|
6569
|
+
cacheWrite1h: z.number().nonnegative().optional() // JOHNNESS_PATCH_USAGE_BILLING_91
|
|
6565
6570
|
}).strict().optional(),
|
|
6566
6571
|
contextWindow: z.number().positive().optional(),
|
|
6567
6572
|
maxTokens: z.number().positive().optional(),
|
|
@@ -12937,7 +12942,7 @@ async function refreshUnmanagedOAuthTokenWithLock(params) {
|
|
|
12937
12942
|
const authPath = resolveAuthStorePath(params.agentDir);
|
|
12938
12943
|
fs.mkdirSync(path.dirname(authPath), { recursive: true, mode: 448 });
|
|
12939
12944
|
return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
|
|
12940
|
-
const store =
|
|
12945
|
+
const store = loadAuthProfileStoreForRuntime(params.agentDir, { allowKeychainPrompt: false }); // JOHNNESS_PATCH_SUBSCRIPTION_RUNTIME_92: reread under lock
|
|
12941
12946
|
const cred = store.profiles[params.profileId];
|
|
12942
12947
|
if (cred?.provider === "openai-codex") throw new Error("Auth profile changed to Codex; resolve again through its owner");
|
|
12943
12948
|
if (!cred || cred.type !== "oauth") return null;
|