From 193722de45f95ff38f9efc00fe3e7f1125f4db73 Mon Sep 17 00:00:00 2001 From: Colby McHenry Date: Thu, 18 Jun 2026 00:15:40 -0500 Subject: [PATCH] feat(cli): replace `offload` subcommands with browser device-authorization `login` / `logout` The old `offload` command family required users to paste a token manually (`offload login --token `) and exposed bring-your-own-endpoint plumbing (`set-endpoint`, `status`, `disable`) as top-level CLI surface. This replaces it with a standard OAuth device flow (RFC 8628 shape) against the CodeGraph dashboard. `codegraph login` calls `/api/cli/device/start`, opens the browser to the returned URL, polls `/api/cli/device/token` until the user approves, then stores the minted token and enables managed reasoning. `codegraph logout` clears it. BYO-endpoint configuration moves entirely to env vars (`CODEGRAPH_OFFLOAD_URL` / `CODEGRAPH_OFFLOAD_KEY` / `CODEGRAPH_OFFLOAD_MODEL`), keeping the CLI surface minimal. --- src/bin/codegraph.ts | 131 +++++++++++++---------------------------- src/reasoning/login.ts | 89 ++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 89 deletions(-) create mode 100644 src/reasoning/login.ts diff --git a/src/bin/codegraph.ts b/src/bin/codegraph.ts index 000414e..913d39e 100644 --- a/src/bin/codegraph.ts +++ b/src/bin/codegraph.ts @@ -36,8 +36,9 @@ import { installFatalHandlers } from './fatal-handler'; import { relaunchWithWasmRuntimeFlagsIfNeeded } from '../extraction/wasm-runtime-flags'; import { EXTRACTION_VERSION } from '../extraction/extraction-version'; import { getTelemetry, TELEMETRY_DOCS, recordIndexEvent } from '../telemetry'; -import { writeOffloadConfig, resolveOffload } from '../reasoning/config'; +import { writeOffloadConfig } from '../reasoning/config'; import { writeOffloadToken } from '../reasoning/credentials'; +import { startDeviceLogin, pollForToken, openBrowser } from '../reasoning/login'; import { fetchUsage } from '../reasoning/reasoner'; // Lazy-load heavy modules (CodeGraph, runInstaller) to keep CLI startup fast. @@ -1352,103 +1353,55 @@ program }); /** - * codegraph offload — configure the reasoning offload (bring-your-own endpoint). + * codegraph login / logout — managed reasoning (CodeGraph AI). * - * When set, codegraph_explore reasons over its assembled source with a remote - * model and returns the synthesized answer instead of the raw source dump. + * `login` runs a browser device-authorization flow against the CodeGraph dashboard, + * mints the account's metered org token, and stores it (managed offload on). When + * signed in, codegraph_explore reasons over its assembled source via the managed + * gateway instead of returning the raw source dump. `logout` clears it. + * + * Bring-your-own endpoint is configured via the CODEGRAPH_OFFLOAD_URL / + * CODEGRAPH_OFFLOAD_KEY / CODEGRAPH_OFFLOAD_MODEL env vars (see ../reasoning/config). */ -const offloadCmd = program - .command('offload') - .description('Configure the reasoning offload — let codegraph_explore answer via your own reasoning model'); - -offloadCmd - .command('set-endpoint ') - .description('Send explore output to an OpenAI-compatible reasoning endpoint (URL ends in /v1)') - .option('--model ', 'Model id to request', 'gpt-oss-120b') - .option('--key-env ', 'Name of the env var holding the API key (the key is never written to disk)') - .option('--effort ', 'reasoning_effort: low | medium | high') - .option('--style