mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-14 02:29:33 +01:00
Squash of PR #662. The header plan-usage chip gains a Copilot row: the calendar-month premium-request quota, with the request counts and the reset in the tooltip, read every 10 minutes from GitHub's copilot_internal/user endpoint with the Copilot CLI's own sign-in token. It rides showPlanUsageLimits and is on by default while the CLI is installed and signed in; any failure leaves the chip without the row. Merge-time fixes by the maintainer: the gates (setting, then token, then the CLI probe) live in readCopilotPlanUsageIfEnabled() so a host with no Copilot sign-in never runs the login-shell probe each tick, with a test that Plan Usage Limits off means no request; the X-GitHub-Api-Version header the Copilot CLI itself does not send is dropped; and CLAUDE.md, architecture-invariants, README and copilot-integration describe the read. The hooks-config import in server.ts was merged with #666's. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
/**
|
|
* @fileoverview Process-wide last-known plan-usage telemetry (account-global).
|
|
*
|
|
* The Claude status-telemetry route and the host Codex and Copilot polls merge their latest
|
|
* values here. The SSE init snapshot (`getLightState`) replays the combined
|
|
* value so the header "Plan Usage Limits" chip shows immediately on a fresh
|
|
* page load / SSE reconnect — before either source emits another sample, and
|
|
* without relying on per-browser localStorage.
|
|
*
|
|
* Null until the first telemetry of the process; cleared naturally on restart.
|
|
*
|
|
* @module plan-usage-latest
|
|
*/
|
|
|
|
let latest: Record<string, unknown> | null = null;
|
|
|
|
export function setLatestPlanUsage(value: Record<string, unknown>): Record<string, unknown> {
|
|
// The Claude status route replaces the Claude part; the host-polled providers ride along.
|
|
const codex = latest?.codex;
|
|
const copilot = latest?.copilot;
|
|
latest = {
|
|
...value,
|
|
...(codex !== undefined ? { codex } : {}),
|
|
...(copilot !== undefined ? { copilot } : {}),
|
|
};
|
|
return latest;
|
|
}
|
|
|
|
export function setLatestCodexPlanUsage(value: object | null): Record<string, unknown> {
|
|
latest = { ...(latest ?? {}), codex: value };
|
|
return latest;
|
|
}
|
|
|
|
export function setLatestCopilotPlanUsage(value: object | null): Record<string, unknown> {
|
|
latest = { ...(latest ?? {}), copilot: value };
|
|
return latest;
|
|
}
|
|
|
|
export function getLatestPlanUsage(): Record<string, unknown> | null {
|
|
return latest;
|
|
}
|