Skip to content

feat(cli): add --model flag and gate prompt on TTY for openkb init#56

Open
SeungwookHan wants to merge 1 commit into
VectifyAI:mainfrom
SeungwookHan:feat/init-model-flag
Open

feat(cli): add --model flag and gate prompt on TTY for openkb init#56
SeungwookHan wants to merge 1 commit into
VectifyAI:mainfrom
SeungwookHan:feat/init-model-flag

Conversation

@SeungwookHan
Copy link
Copy Markdown
Contributor

Summary

  • Add --model/-m MODEL flag to openkb init so the LLM can be set non-interactively (e.g. openkb init --model anthropic/claude-sonnet-4-6).
  • Gate the existing model click.prompt on sys.stdin.isatty() so piped/redirected callers (CI, automation) fall back to the configured default instead of
    failing on EOF — same pattern as the --language prompt from feat(cli): add --language flag and prompt to openkb init #48.
  • Add _coerce_model validation (max 100 chars, no control characters) mirroring _coerce_language, so embedded newlines can't corrupt logged output or
    config.yaml.

Why

Follow-up to #48, which left this open in review:

A parallel --model flag would also close the asymmetry where init is partially non-interactive.

After #48, openkb init could set --language non-interactively but the model still always required a prompt, so scripts / CI pipelines had to pipe newlines
or hand-edit .openkb/config.yaml afterwards. This PR closes that asymmetry — LLM_API_KEY=... openkb init -m anthropic/claude-sonnet-4-6 -l ko is now
fully non-interactive. The API-key prompt deliberately stays interactive: exposing it as a flag would leak the secret into shell history.

Test plan

  • tests/test_cli.py — 20/20 pass, including 6 new model tests:
    • test_init_defaults_model_to_default — no flag under non-TTY, model prompt is skipped and the default is kept.
    • test_init_model_flag_sets_config / test_init_model_short_flag--model / -m skip the prompt and write the value.
    • test_init_empty_model_flag_falls_back_to_default — blank flag value strips to default instead of writing an empty model.
    • test_init_rejects_model_with_control_chars — embedded newline is rejected before any KB files are written.
    • test_init_model_prompt_accepts_input — interactive path (forced TTY) still consumes typed input.
  • Full suite (pytest) — 335 passed.
  • Manual: openkb init --model anthropic/claude-sonnet-4-6 --language ko in a temp dir → .openkb/config.yaml shows both values; openkb init --help
    exposes the new flag.

Mirrors the --language pattern from VectifyAI#48 to close the remaining
asymmetry where `openkb init` was only partially non-interactive.

- Add `--model/-m MODEL` flag that skips the interactive model prompt
  when set, persisting the LiteLLM "provider/model" string straight
  to .openkb/config.yaml.
- Gate the model `click.prompt` on `_stdin_is_tty()` so piped/redirected
  callers fall back to the default model without a click prompt failure
  on EOF.
- Add `_coerce_model` validation (max 100 chars, no control chars),
  matching `_coerce_language` so embedded newlines can't corrupt
  logged output or config.yaml.

Now `LLM_API_KEY=... openkb init -m anthropic/claude-sonnet-4-6 -l ko`
is fully non-interactive (api_key prompt remains for security).
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