MCPcopy
hub / github.com/nowork-studio/NotFair / readHarnessUsage

Function readHarnessUsage

notfair-cmo/src/server/harness-usage.ts:75–90  ·  view source on GitHub ↗
(
  adapter: "claude-code-local" | "codex-local",
)

Source from the content-addressed store, hash-verified

73const CACHE_TTL_MS = 60_000;
74
75export async function readHarnessUsage(
76 adapter: "claude-code-local" | "codex-local",
77): Promise<HarnessUsage> {
78 const hit = cache.get(adapter);
79 if (hit && hit.until > Date.now()) return hit.value;
80 let value: HarnessUsage;
81 try {
82 if (adapter === "codex-local") value = await readCodexUsage();
83 else if (adapter === "claude-code-local") value = readClaudeUsage();
84 else value = { kind: "unknown" };
85 } catch {
86 value = { kind: "unknown" };
87 }
88 cache.set(adapter, { until: Date.now() + CACHE_TTL_MS, value });
89 return value;
90}
91
92async function readCodexUsage(): Promise<HarnessUsage> {
93 const authFile = path.join(os.homedir(), ".codex", "auth.json");

Callers 1

AppSidebarFunction · 0.90

Calls 2

readCodexUsageFunction · 0.85
readClaudeUsageFunction · 0.85

Tested by

no test coverage detected