@phren/cli 0.3.37 → 0.3.39
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/dist/bridge/account-failover.d.ts +4 -0
- package/dist/bridge/account-failover.js +12 -4
- package/dist/bridge/account-usage.d.ts +5 -2
- package/dist/bridge/account-usage.js +36 -6
- package/dist/bridge/agent-hooks.js +2 -0
- package/dist/bridge/changes.d.ts +5 -0
- package/dist/bridge/changes.js +4 -0
- package/dist/bridge/claude-accounts.d.ts +15 -4
- package/dist/bridge/claude-accounts.js +31 -16
- package/dist/bridge/claude-credits.d.ts +43 -0
- package/dist/bridge/claude-credits.js +236 -0
- package/dist/bridge/claude-question-dialog.js +6 -2
- package/dist/bridge/command.js +64 -3
- package/dist/bridge/device-enroll.d.ts +34 -0
- package/dist/bridge/device-enroll.js +57 -0
- package/dist/bridge/dispatch-command.d.ts +2 -0
- package/dist/bridge/dispatch-command.js +25 -1
- package/dist/bridge/dispatch-returns.d.ts +7 -0
- package/dist/bridge/dispatch-returns.js +56 -6
- package/dist/bridge/dispatch.d.ts +52 -0
- package/dist/bridge/dispatch.js +14 -0
- package/dist/bridge/file-range.d.ts +3 -0
- package/dist/bridge/file-range.js +5 -4
- package/dist/bridge/file-search.d.ts +37 -0
- package/dist/bridge/file-search.js +87 -0
- package/dist/bridge/file-write.d.ts +6 -0
- package/dist/bridge/file-write.js +120 -0
- package/dist/bridge/git-host-auth.d.ts +31 -0
- package/dist/bridge/git-host-auth.js +110 -0
- package/dist/bridge/git-host-gitboy.d.ts +46 -0
- package/dist/bridge/git-host-gitboy.js +296 -0
- package/dist/bridge/git-host-gitlab.d.ts +25 -0
- package/dist/bridge/git-host-gitlab.js +229 -0
- package/dist/bridge/git-host-http.d.ts +33 -0
- package/dist/bridge/git-host-http.js +70 -0
- package/dist/bridge/git-hosts.d.ts +92 -0
- package/dist/bridge/git-hosts.js +244 -0
- package/dist/bridge/git-publish.d.ts +15 -5
- package/dist/bridge/git-publish.js +69 -21
- package/dist/bridge/git-review.d.ts +23 -0
- package/dist/bridge/git-review.js +170 -0
- package/dist/bridge/git-sync.d.ts +14 -0
- package/dist/bridge/git-sync.js +143 -0
- package/dist/bridge/git.d.ts +20 -7
- package/dist/bridge/git.js +87 -68
- package/dist/bridge/gitboy-contract.d.ts +32 -0
- package/dist/bridge/gitboy-contract.js +46 -0
- package/dist/bridge/hand-off.d.ts +52 -2
- package/dist/bridge/hand-off.js +77 -24
- package/dist/bridge/health.d.ts +1 -1
- package/dist/bridge/health.js +5 -3
- package/dist/bridge/install.d.ts +14 -0
- package/dist/bridge/install.js +40 -1
- package/dist/bridge/memory-store.d.ts +8 -0
- package/dist/bridge/memory-store.js +80 -2
- package/dist/bridge/pair.d.ts +6 -1
- package/dist/bridge/pair.js +74 -2
- package/dist/bridge/project-memory.d.ts +94 -0
- package/dist/bridge/project-memory.js +235 -0
- package/dist/bridge/push.d.ts +15 -0
- package/dist/bridge/push.js +39 -0
- package/dist/bridge/scoped-gateway.d.ts +29 -0
- package/dist/bridge/scoped-gateway.js +239 -0
- package/dist/bridge/server-launch.d.ts +12 -0
- package/dist/bridge/server-launch.js +17 -10
- package/dist/bridge/server-pane-routes.js +54 -3
- package/dist/bridge/server-routes.d.ts +12 -0
- package/dist/bridge/server-routes.js +59 -4
- package/dist/bridge/server.js +44 -5
- package/dist/bridge/session-move.d.ts +288 -0
- package/dist/bridge/session-move.js +600 -0
- package/dist/bridge/subscription.d.ts +15 -0
- package/dist/bridge/subscription.js +23 -0
- package/dist/bridge/transport.js +21 -1
- package/dist/bridge/usage.d.ts +20 -3
- package/dist/bridge/usage.js +61 -11
- package/dist/bridge-hook.mjs +12751 -3207
- package/dist/cli-registry.js +10 -4
- package/dist/computers/command.js +3 -1
- package/dist/computers/read.d.ts +3 -0
- package/dist/computers/read.js +6 -0
- package/dist/content/summarize.d.ts +21 -0
- package/dist/content/summarize.js +56 -18
- package/dist/modules/registry.js +12 -12
- package/dist/project-config.d.ts +12 -0
- package/dist/project-config.js +29 -0
- package/dist/shared/retrieval.d.ts +1 -0
- package/dist/shared/retrieval.js +1 -1
- package/dist/sync/conflict-resolve.js +5 -6
- package/dist/tools/dispatch.js +18 -1
- package/dist/tools/finding.d.ts +25 -0
- package/dist/tools/finding.js +2 -1
- package/package.json +57 -1
package/dist/bridge/transport.js
CHANGED
|
@@ -122,9 +122,29 @@ export async function dispatch(command) {
|
|
|
122
122
|
await attach(file, args, { cwd, env: shellEnvironment() }, shell[2] === "phren" ? "phren agent exited." : shell[2] ? `${shell[2]} exited.` : "The shell exited.");
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
+
// One agent pane's own terminal (the desktop's console view): Herdr streams a
|
|
126
|
+
// single terminal by its id, which the Hook resolves from the pane so the
|
|
127
|
+
// client never names a terminal it was not shown.
|
|
128
|
+
const pane = /^phren-hook v1 pane ([A-Za-z0-9_.-]{1,100}) ([A-Za-z0-9_:%.-]{1,100})$/.exec(command);
|
|
129
|
+
if (pane && pane[0] === command) {
|
|
130
|
+
requireHook();
|
|
131
|
+
const server = serverName.parse(pane[1]);
|
|
132
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
133
|
+
throw new Error("Request an SSH terminal first.");
|
|
134
|
+
if (terminalKind(server) !== "herdr")
|
|
135
|
+
throw new BridgeError(501, "A single pane's console needs Herdr; open the whole tmux terminal instead.");
|
|
136
|
+
const snapshot = object(await terminalProvider().snapshot(server));
|
|
137
|
+
const panes = Array.isArray(snapshot.panes) ? snapshot.panes : [];
|
|
138
|
+
const found = panes.map(entry => object(entry)).find(entry => entry.pane_id === pane[2]);
|
|
139
|
+
const terminalID = typeof found?.terminal_id === "string" && /^[A-Za-z0-9_-]{1,100}$/.test(found.terminal_id) ? found.terminal_id : undefined;
|
|
140
|
+
if (!terminalID)
|
|
141
|
+
throw new BridgeError(404, "That pane is not open anymore.");
|
|
142
|
+
await attach("herdr", ["--session", server, "terminal", "attach", terminalID], { env: shellEnvironment() }, "The pane's terminal disconnected.");
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
125
145
|
const terminal = /^phren-hook v1 terminal ([A-Za-z0-9_.-]{1,100})$/.exec(command);
|
|
126
146
|
if (!terminal || terminal[0] !== command)
|
|
127
|
-
throw new BridgeError(403, "This SSH key only permits Phren Hook, loopback web previews, project shells, and existing Herdr or tmux terminals.");
|
|
147
|
+
throw new BridgeError(403, "This SSH key only permits Phren Hook, loopback web previews, project shells, and existing Herdr or tmux terminals and panes.");
|
|
128
148
|
requireHook();
|
|
129
149
|
const server = serverName.parse(terminal[1]);
|
|
130
150
|
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
package/dist/bridge/usage.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { accountWindows } from "./account-choice.js";
|
|
3
|
-
import { type AccountRef, type ClaudeHome } from "./claude-accounts.js";
|
|
3
|
+
import { type AccountRef, type AuthStatus, type ClaudeHome } from "./claude-accounts.js";
|
|
4
4
|
import { type Subscription } from "./subscription.js";
|
|
5
5
|
export type { Subscription } from "./subscription.js";
|
|
6
6
|
export interface UsageWindow {
|
|
@@ -22,6 +22,19 @@ export interface UsageWindow {
|
|
|
22
22
|
/** The window's reset time passed after its report: no percent is known, so none is sent. */
|
|
23
23
|
reset?: boolean;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Codex credits: a purchased balance on top of the plan's limits, from the
|
|
27
|
+
* `credits` Codex reports beside its windows. `balance` is in Codex's own
|
|
28
|
+
* credit unit, not dollars. `inUse` is derived: credits are enabled and a plan
|
|
29
|
+
* window is spent (at 100%, or Codex says the rate limit is reached), so
|
|
30
|
+
* further work draws on the balance.
|
|
31
|
+
*/
|
|
32
|
+
export interface UsageCredits {
|
|
33
|
+
hasCredits: boolean;
|
|
34
|
+
unlimited?: true;
|
|
35
|
+
balance?: number;
|
|
36
|
+
inUse?: true;
|
|
37
|
+
}
|
|
25
38
|
export interface UsageSpend {
|
|
26
39
|
amountUSD: number;
|
|
27
40
|
period: "rolling_7_days" | "rolling_30_days" | "calendar_week";
|
|
@@ -33,6 +46,8 @@ export interface AccountUsage {
|
|
|
33
46
|
message?: string;
|
|
34
47
|
spend?: UsageSpend;
|
|
35
48
|
subscription?: Subscription;
|
|
49
|
+
/** Codex's credit balance, when Codex reports one. */
|
|
50
|
+
credits?: UsageCredits;
|
|
36
51
|
/** Opaque key identity used only to avoid counting one OpenRouter key twice. */
|
|
37
52
|
accountId?: string;
|
|
38
53
|
/** Which Claude report fed this account: the status-line rate_limits payload
|
|
@@ -139,7 +154,8 @@ export declare function windowExhausted(window: UsageWindow, now: number): boole
|
|
|
139
154
|
export declare function windowLeft(window: UsageWindow, now: number): number | undefined;
|
|
140
155
|
/** What a capacity probe says about room: each Codex and Claude account's least room left, and whether it has none
|
|
141
156
|
* (`exhausted`, with `until` the last reset that frees it). Claude rows add their 5-hour and weekly rooms, which
|
|
142
|
-
* launch and failover rank accounts by (account-choice.ts).
|
|
157
|
+
* launch and failover rank accounts by (account-choice.ts). API credits are pooled: separate grants that fund one
|
|
158
|
+
* balance, so the account is out only when every live credit is, and a credit's expiry is never a reset. */
|
|
143
159
|
export declare function capacityRoom(accounts: readonly AccountUsage[], now: number): Array<{
|
|
144
160
|
source: string;
|
|
145
161
|
account?: string;
|
|
@@ -169,6 +185,7 @@ export declare class AccountUsageReader {
|
|
|
169
185
|
private readCopilot;
|
|
170
186
|
private platform;
|
|
171
187
|
private readElevenLabs;
|
|
188
|
+
private readAuth;
|
|
172
189
|
private cached?;
|
|
173
190
|
private pending?;
|
|
174
191
|
private claudeCached;
|
|
@@ -177,7 +194,7 @@ export declare class AccountUsageReader {
|
|
|
177
194
|
private spendingPending;
|
|
178
195
|
private openCodeCached?;
|
|
179
196
|
private openCodePending?;
|
|
180
|
-
constructor(readCodex?: typeof readCodexLimits, now?: () => number, readClaudeLive?: (now: Date, home: ClaudeHome) => Promise<AccountUsage | undefined>, readOpenCode?: (now: Date) => Promise<AccountUsage>, readOpenRouter?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCodeGo?: (now: Date) => Promise<AccountUsage>, readCopilot?: (now: Date) => Promise<AccountUsage>, platform?: NodeJS.Platform, readElevenLabs?: (now: Date) => Promise<AccountUsage | undefined>);
|
|
197
|
+
constructor(readCodex?: typeof readCodexLimits, now?: () => number, readClaudeLive?: (now: Date, home: ClaudeHome) => Promise<AccountUsage | undefined>, readOpenCode?: (now: Date) => Promise<AccountUsage>, readOpenRouter?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCodeGo?: (now: Date) => Promise<AccountUsage>, readCopilot?: (now: Date) => Promise<AccountUsage>, platform?: NodeJS.Platform, readElevenLabs?: (now: Date) => Promise<AccountUsage | undefined>, readAuth?: (home: ClaudeHome) => Promise<AuthStatus>);
|
|
181
198
|
/** `allAccounts`: one Claude row per home. Otherwise only the default home's, as
|
|
182
199
|
* before accounts existed, since older phones refuse two rows of one source. */
|
|
183
200
|
read(sources?: Set<string>, allAccounts?: boolean): Promise<{
|
package/dist/bridge/usage.js
CHANGED
|
@@ -12,8 +12,9 @@ import { codexExecutable } from "./codex-binary.js";
|
|
|
12
12
|
import { readSpeechKey } from "./speech-key.js";
|
|
13
13
|
import { resolveSpeechRegion, SPEECH_REGIONS } from "./speech-voice.js";
|
|
14
14
|
import { accountWindows } from "./account-choice.js";
|
|
15
|
-
import { CODEX_ACCOUNT, claudeAccountSubscription, claudeAccountEmail, claudeAccountRef, claudeHomeOfEnv, claudeHomes } from "./claude-accounts.js";
|
|
16
|
-
import {
|
|
15
|
+
import { CODEX_ACCOUNT, claudeAccountSubscription, claudeAccountEmail, claudeAccountRef, claudeAuthStatus, claudeHomeOfEnv, claudeHomes, claudePlanUnknown } from "./claude-accounts.js";
|
|
16
|
+
import { claudeCredits, creditWindows, homeSessionCosts, recordSessionCost } from "./claude-credits.js";
|
|
17
|
+
import { claudePlan, planName, subscriptionDate } from "./subscription.js";
|
|
17
18
|
const exec = promisify(execFile);
|
|
18
19
|
/** The status-line snapshot: `usage/claude.json` for the default home, `usage/claude-<id>.json` for others. */
|
|
19
20
|
const claudeFile = (home) => path.join(bridgeRoot(), "usage", home && !home.isDefault ? `claude-${home.id}.json` : "claude.json");
|
|
@@ -35,12 +36,13 @@ export function codexUsage(value, now = new Date()) {
|
|
|
35
36
|
const buckets = Object.keys(multiple).length
|
|
36
37
|
? Object.entries(multiple).sort(([a], [b]) => a === "codex" ? -1 : b === "codex" ? 1 : a.localeCompare(b)).slice(0, 16)
|
|
37
38
|
: [["codex", result.rateLimits]];
|
|
38
|
-
const windows = [];
|
|
39
|
+
const windows = [], kept = [];
|
|
39
40
|
for (const [key, raw] of buckets) {
|
|
40
41
|
const bucket = object(raw), name = safeText(bucket.limitName);
|
|
41
42
|
// Spark is a separate, lightweight lane nobody budgets by; leave it out.
|
|
42
43
|
if (/spark/i.test(String(key)) || /spark/i.test(name ?? ""))
|
|
43
44
|
continue;
|
|
45
|
+
kept.push(bucket);
|
|
44
46
|
for (const field of ["primary", "secondary"]) {
|
|
45
47
|
const item = object(bucket[field]);
|
|
46
48
|
const label = duration(item.windowDurationMins, field === "primary" ? "Primary limit" : "Secondary limit");
|
|
@@ -49,9 +51,22 @@ export function codexUsage(value, now = new Date()) {
|
|
|
49
51
|
windows.push(entry);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
const credits = codexCredits(kept, windows);
|
|
55
|
+
return { source: "codex", windows, updatedAt: now.toISOString(), ...(credits ? { credits } : {}),
|
|
53
56
|
...(!windows.length ? { message: "Codex has not reported account limits. Sign in with your ChatGPT account in Codex on this computer." } : {}) };
|
|
54
57
|
}
|
|
58
|
+
/** The account's credits from the first bucket that reports them; Codex sends the same balance on each. */
|
|
59
|
+
function codexCredits(buckets, windows) {
|
|
60
|
+
const bucket = buckets.find(item => typeof object(item.credits).hasCredits === "boolean");
|
|
61
|
+
if (!bucket)
|
|
62
|
+
return undefined;
|
|
63
|
+
const raw = object(bucket.credits), hasCredits = raw.hasCredits === true;
|
|
64
|
+
const amount = typeof raw.balance === "string" && /^\d{1,12}(?:\.\d{1,12})?$/.test(raw.balance.trim()) ? Number(raw.balance.trim()) : undefined;
|
|
65
|
+
const spent = windows.some(w => (w.usedPercent ?? 0) >= 100) || buckets.some(item => item.rateLimitReachedType === "rate_limit_reached");
|
|
66
|
+
return { hasCredits, ...(raw.unlimited === true ? { unlimited: true } : {}),
|
|
67
|
+
...(amount !== undefined ? { balance: Math.round(amount * 100) / 100 } : {}),
|
|
68
|
+
...(hasCredits && spent ? { inUse: true } : {}) };
|
|
69
|
+
}
|
|
55
70
|
/** Display metadata from the ID token's claims only, never an authentication decision. */
|
|
56
71
|
export function codexSubscription(idToken, now = new Date()) {
|
|
57
72
|
if (typeof idToken !== "string" || idToken.length > 65_536)
|
|
@@ -691,16 +706,40 @@ export function windowLeft(window, now) {
|
|
|
691
706
|
return 0;
|
|
692
707
|
return typeof window.usedPercent === "number" ? Math.max(0, Math.min(100, Math.round(100 - window.usedPercent))) : undefined;
|
|
693
708
|
}
|
|
709
|
+
/** An API credit window (one grant of one Claude account). */
|
|
710
|
+
const isCreditWindow = (window) => window.id.startsWith("credit:");
|
|
711
|
+
/** The room in one account's API credits: the grants fund one balance together, so their limits and spend sum.
|
|
712
|
+
* A credit that expired is not live so it cannot exhaust the pool, and an exhausted pool has no reset to name. */
|
|
713
|
+
function creditPoolRoom(windows, now) {
|
|
714
|
+
const live = windows.filter(window => isCreditWindow(window) && windowLeft(window, now) !== undefined);
|
|
715
|
+
if (!live.length)
|
|
716
|
+
return { exhausted: false };
|
|
717
|
+
const exhausted = live.every(window => windowExhausted(window, now));
|
|
718
|
+
const numbered = live.filter((window) => typeof window.usedUSD === "number" && Number.isFinite(window.usedUSD) && typeof window.limitUSD === "number" && Number.isFinite(window.limitUSD));
|
|
719
|
+
if (numbered.length === live.length) {
|
|
720
|
+
const limit = numbered.reduce((sum, window) => sum + window.limitUSD, 0);
|
|
721
|
+
const used = numbered.reduce((sum, window) => sum + window.usedUSD, 0);
|
|
722
|
+
return { left: limit > 0 ? Math.max(0, Math.min(100, Math.round((limit - used) / limit * 100))) : 0, exhausted };
|
|
723
|
+
}
|
|
724
|
+
const lefts = live.map(window => windowLeft(window, now)).filter((value) => value !== undefined);
|
|
725
|
+
return { ...(lefts.length ? { left: Math.max(...lefts) } : {}), exhausted };
|
|
726
|
+
}
|
|
694
727
|
/** What a capacity probe says about room: each Codex and Claude account's least room left, and whether it has none
|
|
695
728
|
* (`exhausted`, with `until` the last reset that frees it). Claude rows add their 5-hour and weekly rooms, which
|
|
696
|
-
* launch and failover rank accounts by (account-choice.ts).
|
|
729
|
+
* launch and failover rank accounts by (account-choice.ts). API credits are pooled: separate grants that fund one
|
|
730
|
+
* balance, so the account is out only when every live credit is, and a credit's expiry is never a reset. */
|
|
697
731
|
export function capacityRoom(accounts, now) {
|
|
698
732
|
return accounts.map(usage => {
|
|
699
|
-
const
|
|
700
|
-
const
|
|
733
|
+
const pool = creditPoolRoom(usage.windows, now);
|
|
734
|
+
const direct = usage.windows.filter(window => !isCreditWindow(window));
|
|
735
|
+
const left = direct.map(window => windowLeft(window, now)).filter((value) => value !== undefined);
|
|
736
|
+
if (pool.left !== undefined)
|
|
737
|
+
left.push(pool.left);
|
|
738
|
+
const out = direct.filter(window => windowExhausted(window, now));
|
|
701
739
|
const until = out.map(window => window.resetsAt).filter((value) => Boolean(value)).sort().at(-1);
|
|
740
|
+
const exhausted = out.length > 0 || pool.exhausted;
|
|
702
741
|
return { source: usage.source, ...(usage.account?.id ? { account: usage.account.id } : {}), ...(left.length ? { leftPercent: Math.min(...left) } : {}),
|
|
703
|
-
...(
|
|
742
|
+
...(exhausted ? { exhausted: true, ...(until ? { until } : {}) } : {}), ...(usage.source === "claude" ? accountWindows(usage, now) : {}) };
|
|
704
743
|
});
|
|
705
744
|
}
|
|
706
745
|
/** A Claude report older than this says nothing about the account now. */
|
|
@@ -742,6 +781,7 @@ export class AccountUsageReader {
|
|
|
742
781
|
readCopilot;
|
|
743
782
|
platform;
|
|
744
783
|
readElevenLabs;
|
|
784
|
+
readAuth;
|
|
745
785
|
cached;
|
|
746
786
|
pending;
|
|
747
787
|
claudeCached = new Map();
|
|
@@ -750,7 +790,7 @@ export class AccountUsageReader {
|
|
|
750
790
|
spendingPending = new Map();
|
|
751
791
|
openCodeCached;
|
|
752
792
|
openCodePending;
|
|
753
|
-
constructor(readCodex = readCodexLimits, now = Date.now, readClaudeLive = liveClaudeUsage, readOpenCode = now => readOpenCodeUsage("opencode", now), readOpenRouter = liveOpenRouterUsage, readOpenCodeGo = readOpenCodeGoUsage, readCopilot = readCopilotUsage, platform = process.platform, readElevenLabs = liveElevenLabsUsage) {
|
|
793
|
+
constructor(readCodex = readCodexLimits, now = Date.now, readClaudeLive = liveClaudeUsage, readOpenCode = now => readOpenCodeUsage("opencode", now), readOpenRouter = liveOpenRouterUsage, readOpenCodeGo = readOpenCodeGoUsage, readCopilot = readCopilotUsage, platform = process.platform, readElevenLabs = liveElevenLabsUsage, readAuth = home => claudeAuthStatus(home)) {
|
|
754
794
|
this.readCodex = readCodex;
|
|
755
795
|
this.now = now;
|
|
756
796
|
this.readClaudeLive = readClaudeLive;
|
|
@@ -760,6 +800,7 @@ export class AccountUsageReader {
|
|
|
760
800
|
this.readCopilot = readCopilot;
|
|
761
801
|
this.platform = platform;
|
|
762
802
|
this.readElevenLabs = readElevenLabs;
|
|
803
|
+
this.readAuth = readAuth;
|
|
763
804
|
}
|
|
764
805
|
/** `allAccounts`: one Claude row per home. Otherwise only the default home's, as
|
|
765
806
|
* before accounts existed, since older phones refuse two rows of one source. */
|
|
@@ -777,9 +818,17 @@ export class AccountUsageReader {
|
|
|
777
818
|
// Every home, default first; the labels and keys are read once per poll.
|
|
778
819
|
const homes = allAccounts ? claudeHomes() : claudeHomes().slice(0, 1);
|
|
779
820
|
const claudeRow = async (home) => {
|
|
821
|
+
const now = new Date(this.now());
|
|
780
822
|
const email = claudeAccountEmail(home);
|
|
781
|
-
const
|
|
782
|
-
|
|
823
|
+
const credits = claudeCredits(home.id);
|
|
824
|
+
// Claude Code's own answer only when the profile can't name the plan, or a credit asks whether this is a Console login.
|
|
825
|
+
const auth = credits.length || claudePlanUnknown(home) ? await this.readAuth(home).catch(() => undefined) : undefined;
|
|
826
|
+
const fallback = auth?.console ? "Console" : auth?.plan ? claudePlan({ subscriptionType: auth.plan }) : undefined;
|
|
827
|
+
const subscription = claudeAccountSubscription(home, now, fallback);
|
|
828
|
+
const usage = settleClaudeUsage(await this.claude(home), this.now());
|
|
829
|
+
const credit = credits.length ? creditWindows(credits, homeSessionCosts(home), now) : [];
|
|
830
|
+
const withCredit = credit.length ? { ...usage, windows: [...usage.windows, ...credit], message: undefined, updatedAt: usage.updatedAt ?? now.toISOString() } : usage;
|
|
831
|
+
return { ...withCredit, ...(subscription ? { subscription } : {}), account: { ...claudeAccountRef(home), ...(email ? { email } : {}) } };
|
|
783
832
|
};
|
|
784
833
|
const [codexValue, claude, subscription] = await Promise.all([codex, Promise.all(homes.map(claudeRow)), readCodexSubscription(undefined, new Date(this.now()))]);
|
|
785
834
|
return [{ ...codexValue, ...(subscription ? { subscription } : {}), account: CODEX_ACCOUNT }, ...claude];
|
|
@@ -914,6 +963,7 @@ export async function captureClaudeUsage(original) {
|
|
|
914
963
|
used_percentage: w.usedPercent, resets_at: w.resetsAt ? Date.parse(w.resetsAt) / 1000 : undefined,
|
|
915
964
|
}]));
|
|
916
965
|
await atomicInPrivateDir(claudeFile(home), JSON.stringify({ rate_limits, updatedAt: snapshot.updatedAt }));
|
|
966
|
+
await recordSessionCost(home, JSON.parse(input)).catch(() => undefined);
|
|
917
967
|
}
|
|
918
968
|
catch { /* Status line rendering must survive unavailable usage storage. */ }
|
|
919
969
|
const previous = object(JSON.parse(Buffer.from(original, "base64").toString()));
|