@phren/cli 0.3.36 → 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.
Files changed (103) hide show
  1. package/dist/bridge/account-choice.d.ts +82 -0
  2. package/dist/bridge/account-choice.js +173 -0
  3. package/dist/bridge/account-failover.d.ts +61 -0
  4. package/dist/bridge/account-failover.js +189 -0
  5. package/dist/bridge/account-usage.d.ts +7 -2
  6. package/dist/bridge/account-usage.js +53 -8
  7. package/dist/bridge/agent-hooks.js +2 -0
  8. package/dist/bridge/changes.d.ts +5 -0
  9. package/dist/bridge/changes.js +4 -0
  10. package/dist/bridge/claude-accounts.d.ts +15 -4
  11. package/dist/bridge/claude-accounts.js +31 -16
  12. package/dist/bridge/claude-credits.d.ts +43 -0
  13. package/dist/bridge/claude-credits.js +236 -0
  14. package/dist/bridge/claude-question-dialog.js +6 -2
  15. package/dist/bridge/command.js +64 -3
  16. package/dist/bridge/device-enroll.d.ts +34 -0
  17. package/dist/bridge/device-enroll.js +57 -0
  18. package/dist/bridge/dispatch-command.d.ts +2 -0
  19. package/dist/bridge/dispatch-command.js +25 -1
  20. package/dist/bridge/dispatch-returns.d.ts +19 -0
  21. package/dist/bridge/dispatch-returns.js +93 -12
  22. package/dist/bridge/dispatch.d.ts +83 -3
  23. package/dist/bridge/dispatch.js +82 -10
  24. package/dist/bridge/file-range.d.ts +3 -0
  25. package/dist/bridge/file-range.js +5 -4
  26. package/dist/bridge/file-search.d.ts +37 -0
  27. package/dist/bridge/file-search.js +87 -0
  28. package/dist/bridge/file-write.d.ts +6 -0
  29. package/dist/bridge/file-write.js +120 -0
  30. package/dist/bridge/git-host-auth.d.ts +31 -0
  31. package/dist/bridge/git-host-auth.js +110 -0
  32. package/dist/bridge/git-host-gitboy.d.ts +46 -0
  33. package/dist/bridge/git-host-gitboy.js +296 -0
  34. package/dist/bridge/git-host-gitlab.d.ts +25 -0
  35. package/dist/bridge/git-host-gitlab.js +229 -0
  36. package/dist/bridge/git-host-http.d.ts +33 -0
  37. package/dist/bridge/git-host-http.js +70 -0
  38. package/dist/bridge/git-hosts.d.ts +92 -0
  39. package/dist/bridge/git-hosts.js +244 -0
  40. package/dist/bridge/git-publish.d.ts +15 -5
  41. package/dist/bridge/git-publish.js +69 -21
  42. package/dist/bridge/git-review.d.ts +23 -0
  43. package/dist/bridge/git-review.js +170 -0
  44. package/dist/bridge/git-sync.d.ts +14 -0
  45. package/dist/bridge/git-sync.js +143 -0
  46. package/dist/bridge/git.d.ts +20 -7
  47. package/dist/bridge/git.js +87 -68
  48. package/dist/bridge/gitboy-contract.d.ts +32 -0
  49. package/dist/bridge/gitboy-contract.js +46 -0
  50. package/dist/bridge/hand-off.d.ts +75 -3
  51. package/dist/bridge/hand-off.js +113 -27
  52. package/dist/bridge/health.d.ts +1 -1
  53. package/dist/bridge/health.js +5 -3
  54. package/dist/bridge/install.d.ts +14 -0
  55. package/dist/bridge/install.js +40 -1
  56. package/dist/bridge/launch-brief.d.ts +3 -0
  57. package/dist/bridge/launch-brief.js +16 -0
  58. package/dist/bridge/memory-store.d.ts +8 -0
  59. package/dist/bridge/memory-store.js +80 -2
  60. package/dist/bridge/pair.d.ts +6 -1
  61. package/dist/bridge/pair.js +74 -2
  62. package/dist/bridge/peers.js +4 -2
  63. package/dist/bridge/project-memory.d.ts +94 -0
  64. package/dist/bridge/project-memory.js +235 -0
  65. package/dist/bridge/push.d.ts +15 -0
  66. package/dist/bridge/push.js +39 -0
  67. package/dist/bridge/schedule-launch.js +5 -1
  68. package/dist/bridge/schedule-watch.d.ts +3 -0
  69. package/dist/bridge/schedule-watch.js +27 -1
  70. package/dist/bridge/scoped-gateway.d.ts +29 -0
  71. package/dist/bridge/scoped-gateway.js +239 -0
  72. package/dist/bridge/server-launch.d.ts +12 -0
  73. package/dist/bridge/server-launch.js +23 -12
  74. package/dist/bridge/server-pane-routes.js +54 -3
  75. package/dist/bridge/server-routes.d.ts +12 -0
  76. package/dist/bridge/server-routes.js +64 -5
  77. package/dist/bridge/server.js +50 -5
  78. package/dist/bridge/session-move.d.ts +288 -0
  79. package/dist/bridge/session-move.js +600 -0
  80. package/dist/bridge/subscription.d.ts +15 -0
  81. package/dist/bridge/subscription.js +23 -0
  82. package/dist/bridge/transport.js +21 -1
  83. package/dist/bridge/usage.d.ts +23 -4
  84. package/dist/bridge/usage.js +63 -11
  85. package/dist/bridge-hook.mjs +23280 -13252
  86. package/dist/cli/config.js +28 -2
  87. package/dist/cli-registry.js +10 -4
  88. package/dist/computers/command.js +3 -1
  89. package/dist/computers/read.d.ts +3 -0
  90. package/dist/computers/read.js +6 -0
  91. package/dist/content/summarize.d.ts +21 -0
  92. package/dist/content/summarize.js +56 -18
  93. package/dist/init/preferences.d.ts +6 -0
  94. package/dist/modules/registry.js +13 -13
  95. package/dist/project-config.d.ts +12 -0
  96. package/dist/project-config.js +29 -0
  97. package/dist/shared/retrieval.d.ts +1 -0
  98. package/dist/shared/retrieval.js +1 -1
  99. package/dist/sync/conflict-resolve.js +5 -6
  100. package/dist/tools/dispatch.js +20 -3
  101. package/dist/tools/finding.d.ts +25 -0
  102. package/dist/tools/finding.js +2 -1
  103. package/package.json +57 -1
@@ -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)
@@ -1,5 +1,6 @@
1
1
  import { execFile } from "node:child_process";
2
- import { type AccountRef, type ClaudeHome } from "./claude-accounts.js";
2
+ import { accountWindows } from "./account-choice.js";
3
+ import { type AccountRef, type AuthStatus, type ClaudeHome } from "./claude-accounts.js";
3
4
  import { type Subscription } from "./subscription.js";
4
5
  export type { Subscription } from "./subscription.js";
5
6
  export interface UsageWindow {
@@ -21,6 +22,19 @@ export interface UsageWindow {
21
22
  /** The window's reset time passed after its report: no percent is known, so none is sent. */
22
23
  reset?: boolean;
23
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
+ }
24
38
  export interface UsageSpend {
25
39
  amountUSD: number;
26
40
  period: "rolling_7_days" | "rolling_30_days" | "calendar_week";
@@ -32,6 +46,8 @@ export interface AccountUsage {
32
46
  message?: string;
33
47
  spend?: UsageSpend;
34
48
  subscription?: Subscription;
49
+ /** Codex's credit balance, when Codex reports one. */
50
+ credits?: UsageCredits;
35
51
  /** Opaque key identity used only to avoid counting one OpenRouter key twice. */
36
52
  accountId?: string;
37
53
  /** Which Claude report fed this account: the status-line rate_limits payload
@@ -137,14 +153,16 @@ export declare function windowExhausted(window: UsageWindow, now: number): boole
137
153
  /** Percent left on a window at `now`: none once its reset passed or with no percent, 0 while the service refuses requests. */
138
154
  export declare function windowLeft(window: UsageWindow, now: number): number | undefined;
139
155
  /** What a capacity probe says about room: each Codex and Claude account's least room left, and whether it has none
140
- * (`exhausted`, with `until` the last reset that frees it). */
156
+ * (`exhausted`, with `until` the last reset that frees it). Claude rows add their 5-hour and weekly rooms, which
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. */
141
159
  export declare function capacityRoom(accounts: readonly AccountUsage[], now: number): Array<{
142
160
  source: string;
143
161
  account?: string;
144
162
  leftPercent?: number;
145
163
  exhausted?: true;
146
164
  until?: string;
147
- }>;
165
+ } & ReturnType<typeof accountWindows>>;
148
166
  /** A Claude report older than this says nothing about the account now. */
149
167
  export declare const CLAUDE_REPORT_MAX_AGE_MS: number;
150
168
  /**
@@ -167,6 +185,7 @@ export declare class AccountUsageReader {
167
185
  private readCopilot;
168
186
  private platform;
169
187
  private readElevenLabs;
188
+ private readAuth;
170
189
  private cached?;
171
190
  private pending?;
172
191
  private claudeCached;
@@ -175,7 +194,7 @@ export declare class AccountUsageReader {
175
194
  private spendingPending;
176
195
  private openCodeCached?;
177
196
  private openCodePending?;
178
- 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>);
179
198
  /** `allAccounts`: one Claude row per home. Otherwise only the default home's, as
180
199
  * before accounts existed, since older phones refuse two rows of one source. */
181
200
  read(sources?: Set<string>, allAccounts?: boolean): Promise<{
@@ -11,8 +11,10 @@ import { stripTerminal } from "../terminal-text.js";
11
11
  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
- import { CODEX_ACCOUNT, claudeAccountSubscription, claudeAccountEmail, claudeAccountRef, claudeHomeOfEnv, claudeHomes } from "./claude-accounts.js";
15
- import { planName, subscriptionDate } from "./subscription.js";
14
+ import { accountWindows } from "./account-choice.js";
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";
16
18
  const exec = promisify(execFile);
17
19
  /** The status-line snapshot: `usage/claude.json` for the default home, `usage/claude-<id>.json` for others. */
18
20
  const claudeFile = (home) => path.join(bridgeRoot(), "usage", home && !home.isDefault ? `claude-${home.id}.json` : "claude.json");
@@ -34,12 +36,13 @@ export function codexUsage(value, now = new Date()) {
34
36
  const buckets = Object.keys(multiple).length
35
37
  ? Object.entries(multiple).sort(([a], [b]) => a === "codex" ? -1 : b === "codex" ? 1 : a.localeCompare(b)).slice(0, 16)
36
38
  : [["codex", result.rateLimits]];
37
- const windows = [];
39
+ const windows = [], kept = [];
38
40
  for (const [key, raw] of buckets) {
39
41
  const bucket = object(raw), name = safeText(bucket.limitName);
40
42
  // Spark is a separate, lightweight lane nobody budgets by; leave it out.
41
43
  if (/spark/i.test(String(key)) || /spark/i.test(name ?? ""))
42
44
  continue;
45
+ kept.push(bucket);
43
46
  for (const field of ["primary", "secondary"]) {
44
47
  const item = object(bucket[field]);
45
48
  const label = duration(item.windowDurationMins, field === "primary" ? "Primary limit" : "Secondary limit");
@@ -48,9 +51,22 @@ export function codexUsage(value, now = new Date()) {
48
51
  windows.push(entry);
49
52
  }
50
53
  }
51
- return { source: "codex", windows, updatedAt: now.toISOString(),
54
+ const credits = codexCredits(kept, windows);
55
+ return { source: "codex", windows, updatedAt: now.toISOString(), ...(credits ? { credits } : {}),
52
56
  ...(!windows.length ? { message: "Codex has not reported account limits. Sign in with your ChatGPT account in Codex on this computer." } : {}) };
53
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
+ }
54
70
  /** Display metadata from the ID token's claims only, never an authentication decision. */
55
71
  export function codexSubscription(idToken, now = new Date()) {
56
72
  if (typeof idToken !== "string" || idToken.length > 65_536)
@@ -690,15 +706,40 @@ export function windowLeft(window, now) {
690
706
  return 0;
691
707
  return typeof window.usedPercent === "number" ? Math.max(0, Math.min(100, Math.round(100 - window.usedPercent))) : undefined;
692
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
+ }
693
727
  /** What a capacity probe says about room: each Codex and Claude account's least room left, and whether it has none
694
- * (`exhausted`, with `until` the last reset that frees it). */
728
+ * (`exhausted`, with `until` the last reset that frees it). Claude rows add their 5-hour and weekly rooms, which
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. */
695
731
  export function capacityRoom(accounts, now) {
696
732
  return accounts.map(usage => {
697
- const left = usage.windows.map(window => windowLeft(window, now)).filter((value) => value !== undefined);
698
- const out = usage.windows.filter(window => windowExhausted(window, now));
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));
699
739
  const until = out.map(window => window.resetsAt).filter((value) => Boolean(value)).sort().at(-1);
740
+ const exhausted = out.length > 0 || pool.exhausted;
700
741
  return { source: usage.source, ...(usage.account?.id ? { account: usage.account.id } : {}), ...(left.length ? { leftPercent: Math.min(...left) } : {}),
701
- ...(out.length ? { exhausted: true, ...(until ? { until } : {}) } : {}) };
742
+ ...(exhausted ? { exhausted: true, ...(until ? { until } : {}) } : {}), ...(usage.source === "claude" ? accountWindows(usage, now) : {}) };
702
743
  });
703
744
  }
704
745
  /** A Claude report older than this says nothing about the account now. */
@@ -740,6 +781,7 @@ export class AccountUsageReader {
740
781
  readCopilot;
741
782
  platform;
742
783
  readElevenLabs;
784
+ readAuth;
743
785
  cached;
744
786
  pending;
745
787
  claudeCached = new Map();
@@ -748,7 +790,7 @@ export class AccountUsageReader {
748
790
  spendingPending = new Map();
749
791
  openCodeCached;
750
792
  openCodePending;
751
- 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)) {
752
794
  this.readCodex = readCodex;
753
795
  this.now = now;
754
796
  this.readClaudeLive = readClaudeLive;
@@ -758,6 +800,7 @@ export class AccountUsageReader {
758
800
  this.readCopilot = readCopilot;
759
801
  this.platform = platform;
760
802
  this.readElevenLabs = readElevenLabs;
803
+ this.readAuth = readAuth;
761
804
  }
762
805
  /** `allAccounts`: one Claude row per home. Otherwise only the default home's, as
763
806
  * before accounts existed, since older phones refuse two rows of one source. */
@@ -775,9 +818,17 @@ export class AccountUsageReader {
775
818
  // Every home, default first; the labels and keys are read once per poll.
776
819
  const homes = allAccounts ? claudeHomes() : claudeHomes().slice(0, 1);
777
820
  const claudeRow = async (home) => {
821
+ const now = new Date(this.now());
778
822
  const email = claudeAccountEmail(home);
779
- const subscription = claudeAccountSubscription(home, new Date(this.now()));
780
- return { ...settleClaudeUsage(await this.claude(home), this.now()), ...(subscription ? { subscription } : {}), account: { ...claudeAccountRef(home), ...(email ? { email } : {}) } };
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 } : {}) } };
781
832
  };
782
833
  const [codexValue, claude, subscription] = await Promise.all([codex, Promise.all(homes.map(claudeRow)), readCodexSubscription(undefined, new Date(this.now()))]);
783
834
  return [{ ...codexValue, ...(subscription ? { subscription } : {}), account: CODEX_ACCOUNT }, ...claude];
@@ -912,6 +963,7 @@ export async function captureClaudeUsage(original) {
912
963
  used_percentage: w.usedPercent, resets_at: w.resetsAt ? Date.parse(w.resetsAt) / 1000 : undefined,
913
964
  }]));
914
965
  await atomicInPrivateDir(claudeFile(home), JSON.stringify({ rate_limits, updatedAt: snapshot.updatedAt }));
966
+ await recordSessionCost(home, JSON.parse(input)).catch(() => undefined);
915
967
  }
916
968
  catch { /* Status line rendering must survive unavailable usage storage. */ }
917
969
  const previous = object(JSON.parse(Buffer.from(original, "base64").toString()));