Skip to content

feat(cli): add deepcode login command to save API key#225

Open
dongowu wants to merge 1 commit into
lessweb:mainfrom
dongowu:feat/cli-login
Open

feat(cli): add deepcode login command to save API key#225
dongowu wants to merge 1 commit into
lessweb:mainfrom
dongowu:feat/cli-login

Conversation

@dongowu

@dongowu dongowu commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Adds a deepcode login sub-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_KEY is overwritten and missing defaults are filled in.

Usage

deepcode login                     # hidden input (Backspace/Ctrl+U/Ctrl+C aware)
deepcode login --show              # echo the key while typing
deepcode login --api-key sk-xxx    # non-interactive (CI/scripts); -k alias
echo sk-xxx | deepcode login       # piped stdin (non-TTY fallback)
deepcode login --help              # login help

Design

  • Dispatched before the TUI: in main(), login is handled after --version/--help but before the interactive-terminal check and Windows shell config, so it runs without a TTY (keys can be piped) and never starts Ink.
  • Isolated from the existing yargs parser: a dedicated parseLoginArgs() short-circuits ahead of yargs when argv[0] === "login". The strict TUI parser is untouched, so normal usage (deepcode, -p, -r, positional query) is unaffected — covered by regression tests.
  • core: exports buildLoginSettings() to merge existing settings with the default template + new API key (reuses DEFAULT_MODEL / DEFAULT_BASE_URL).
  • Hidden input uses raw mode on a TTY; falls back to a single-line stdin read when piped (no spurious prompt).

Files

Area File Change
core settings.ts new exported buildLoginSettings()
core index.ts re-export buildLoginSettings
cli commands/login.ts newrunLogin, hidden-input reader, help
cli cli-args.ts command/login fields, parseLoginArgs, Commands: epilog
cli cli.tsx main() dispatches login before TUI
tests settings-and-notify.test.ts 3 buildLoginSettings tests
tests cli-args.test.ts 12 login parse + regression tests
tests login.test.ts newrunLogin write/preserve tests

Verification

  • npm run typecheck — pass (core + cli + vscode)
  • npm run lint — 0 new issues
  • npm test — core 250 pass (+3 new), cli 264 pass (+14 new)
  • Manually verified: --help, --api-key write, preserve-existing-fields merge, piped stdin, error exit on missing --api-key value, and that deepcode/-p/-r still behave as before.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant