feat(reasoning): add CODEGRAPH_OFFLOAD_DISABLE kill-switch and per-call usage log

`CODEGRAPH_OFFLOAD_DISABLE=1` immediately disables the offload for the current
process without touching the persisted config or stored login — useful for A/B
arms or sessions where raw source is preferred.

`CODEGRAPH_OFFLOAD_USAGE_LOG=` appends one JSONL entry per call with token
counts, charged credits, and derived cost (`creditsCharged / 100_000`) so a
harness can attribute CodeGraph AI spend to a single run independently of the
server's cumulative totals. Both features are best-effort and never disrupt the
degradable offload path.

Also fixes the `login` credit display to check `unlimited` before the numeric
balance, so comped/internal accounts don't incorrectly show "0 remaining".
This commit is contained in:
Colby McHenry
2026-06-18 21:10:10 -05:00
parent c9e207a0f2
commit 6d5cb6b25c
4 changed files with 122 additions and 4 deletions
+8 -2
View File
@@ -1382,8 +1382,14 @@ program
success('Signed in to CodeGraph AI — managed reasoning is on.');
try {
const usage = await fetchUsage();
if (usage && typeof usage.remaining === 'number') {
info(` credits: ${usage.remaining.toLocaleString()} remaining`);
if (usage) {
// Mirror `codegraph usage`'s precedence: a comped/internal account is
// flagged `unlimited` (often with remaining:0 when no allowance is set),
// so check that before the numeric balance or it reads "0 remaining".
if (usage.banned) warn(' Account suspended — contact support.');
else if (usage.unlimited) info(' credits: unlimited');
else if (typeof usage.remaining === 'number')
info(` credits: ${usage.remaining.toLocaleString()} remaining`);
}
} catch {
/* balance is best-effort */