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
+11
View File
@@ -102,6 +102,17 @@ const trimmed = (v: string | undefined): string | undefined => {
/** Merge the persisted config with `CODEGRAPH_OFFLOAD_*` env overrides (env wins). */
export function resolveOffload(env: NodeJS.ProcessEnv = process.env): ResolvedOffload {
// Hard kill-switch: disable the offload for this process/session without touching
// the persisted config or the stored login — e.g. one A/B arm, or a user who wants
// codegraph_explore to return raw source for a session. Env-only by design.
if (env.CODEGRAPH_OFFLOAD_DISABLE === '1') {
return {
enabled: false, managed: false, url: undefined, model: MANAGED_DEFAULT_MODEL,
apiKey: undefined, keySource: undefined, effort: 'low', style: 'plain',
timeoutMs: 20000, maxTokens: 12000, strip: false,
debug: env.CODEGRAPH_OFFLOAD_DEBUG === '1', origin: 'none',
};
}
const c = readOffloadConfig();
const managed = !!c.managed;
const envUrl = trimmed(env.CODEGRAPH_OFFLOAD_URL);