feat(cli): add --model flag and gate prompt on TTY for openkb init#56
Open
SeungwookHan wants to merge 1 commit into
Open
feat(cli): add --model flag and gate prompt on TTY for openkb init#56SeungwookHan wants to merge 1 commit into
SeungwookHan wants to merge 1 commit into
Conversation
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).
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
--model/-m MODELflag toopenkb initso the LLM can be set non-interactively (e.g.openkb init --model anthropic/claude-sonnet-4-6).click.promptonsys.stdin.isatty()so piped/redirected callers (CI, automation) fall back to the configured default instead offailing on EOF — same pattern as the
--languageprompt from feat(cli): add --language flag and prompt to openkb init #48._coerce_modelvalidation (max 100 chars, no control characters) mirroring_coerce_language, so embedded newlines can't corrupt logged output orconfig.yaml.Why
Follow-up to #48, which left this open in review:
After #48,
openkb initcould set--languagenon-interactively but the model still always required a prompt, so scripts / CI pipelines had to pipe newlinesor hand-edit
.openkb/config.yamlafterwards. This PR closes that asymmetry —LLM_API_KEY=... openkb init -m anthropic/claude-sonnet-4-6 -l kois nowfully 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/-mskip 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.pytest) — 335 passed.openkb init --model anthropic/claude-sonnet-4-6 --language koin a temp dir →.openkb/config.yamlshows both values;openkb init --helpexposes the new flag.