feat(cli): add deepcode login command to save API key#225
Open
dongowu wants to merge 1 commit into
Open
Conversation
Add an interactive `deepcode login` sub-command that prompts for the DeepSeek API key and writes a ready-to-use default config to ~/.deepcode/settings.json (model=deepseek-v4-pro, base URL=api.deepseek.com, thinking enabled, reasoning effort=max). Existing custom fields are preserved when updating an existing settings file; only `env.API_KEY` is overwritten and missing defaults are filled in. Supported invocations: - `deepcode login` hidden input (Backspace/Ctrl+U/Ctrl+C aware) - `deepcode login --show` echo the key while typing - `deepcode login --api-key sk-...` / `-k` non-interactive (CI/scripts) - `echo sk-... | deepcode login` piped stdin (non-TTY fallback) `login` is dispatched in `main()` before the TUI starts and before the interactive-terminal check, so it works without a TTY. It is parsed by a dedicated `parseLoginArgs` that short-circuits ahead of yargs, keeping the existing strict TUI parser untouched — normal usage (`deepcode`, `-p`, `-r`, positional query) is unaffected (covered by regression tests). core: export `buildLoginSettings()` to merge existing settings with the default template + new API key. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
deepcode loginsub-command that interactively saves the DeepSeek API key to~/.deepcode/settings.json, writing a ready-to-use default config so a fresh login works out of the box:{ "env": { "MODEL": "deepseek-v4-pro", "BASE_URL": "https://api.deepseek.com", "API_KEY": "sk-..." }, "thinkingEnabled": true, "reasoningEffort": "max" }When updating an existing settings file, custom fields (model, base URL, thinking, permissions, …) are preserved — only
env.API_KEYis overwritten and missing defaults are filled in.Usage
Design
main(),loginis handled after--version/--helpbut before the interactive-terminal check and Windows shell config, so it runs without a TTY (keys can be piped) and never starts Ink.parseLoginArgs()short-circuits ahead of yargs whenargv[0] === "login". The strict TUI parser is untouched, so normal usage (deepcode,-p,-r, positional query) is unaffected — covered by regression tests.buildLoginSettings()to merge existing settings with the default template + new API key (reusesDEFAULT_MODEL/DEFAULT_BASE_URL).Files
settings.tsbuildLoginSettings()index.tsbuildLoginSettingscommands/login.tsrunLogin, hidden-input reader, helpcli-args.tscommand/loginfields,parseLoginArgs,Commands:epilogcli.tsxmain()dispatchesloginbefore TUIsettings-and-notify.test.tsbuildLoginSettingstestscli-args.test.tslogin.test.tsrunLoginwrite/preserve testsVerification
npm run typecheck— pass (core + cli + vscode)npm run lint— 0 new issuesnpm test— core 250 pass (+3 new), cli 264 pass (+14 new)--help,--api-keywrite, preserve-existing-fields merge, piped stdin, error exit on missing--api-keyvalue, and thatdeepcode/-p/-rstill behave as before.🤖 Generated with Claude Code