mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-22 08:38:08 +02:00
fix(cli): clear error when ktx setup has no LLM backend under --no-input (#281)
* fix(cli): fail clearly when ktx setup has no LLM backend under --no-input Non-interactive `ktx setup` silently defaulted the LLM backend to `anthropic` and then failed with `Missing Anthropic API key: pass --anthropic-api-key-env or --anthropic-api-key-file` — confusing for users who selected a different provider (e.g. `--target claude-code`) and never asked for the Anthropic API backend. That silent default could never succeed: it was reached only when no backend, Anthropic key, or Vertex flag was supplied, and in exactly that case the Anthropic credential resolver always failed (no env fallback in disabled mode). Unlike embeddings, the LLM has no credential-free default (anthropic needs a key, vertex needs gcloud ADC, claude-code/codex need a logged-in local CLI), so there is nothing safe to assume. `chooseBackend` now fails clearly in disabled mode with no backend, naming the (hidden) `--llm-backend` flag and its choices and noting each backend's credential needs. `--llm-backend` stays hidden in `--help`, consistent with the rest of the documented automation surface; the error message is the discovery path. - Add a unit test (no backend, disabled -> clear message) and a CLI/integration test (`--target claude-code --no-input` -> exit 1, clear message, not the Anthropic red herring). - Document the no-default behavior and add a Common-errors row in docs-site ktx-setup.mdx. * refactor(cli): single source of truth for setup LLM backends The set of LLM backends a user can pick during `ktx setup` (claude-code, codex, anthropic, vertex) was hand-enumerated in five places: the `--llm-backend` arg parser, the `KtxSetupLlmBackend` union, the interactive prompt's narrowing, the prompt options, and the missing-backend error. Only some had TypeScript coverage, so adding a backend could silently drift (e.g. a valid value rejected by the parser, or routed to anthropic by the prompt's `? : 'anthropic'` fallback). Collapse them onto one `KTX_SETUP_LLM_BACKENDS` list: - `KtxSetupLlmBackend` is derived from it. - `isKtxSetupLlmBackend` is the shared validator; the arg parser and the prompt both route through it instead of re-listing literals. - The prompt options derive from the list, with a `Record<KtxSetupLlmBackend, string>` label map so a new backend fails to compile until it has a label. - The missing-backend error builds its choice list from the same source. Behavior-preserving: identical accepted values and parse error, identical prompt options (asserted by an existing test), and the prompt's unreachable fallback now cancels rather than silently assuming anthropic.
This commit is contained in:
parent
9ff0e86bb8
commit
0425160857
5 changed files with 97 additions and 19 deletions
|
|
@ -67,6 +67,13 @@ of Anthropic API key or Vertex flags. After you choose a backend, `ktx setup`
|
|||
writes that backend's per-role model preset to `ktx.yaml`. To change a model,
|
||||
edit the matching `llm.models.<role>` value in `ktx.yaml`.
|
||||
|
||||
With `--no-input`, `ktx setup` does not assume a default LLM provider, because
|
||||
every backend needs credentials only you can supply. Pass `--llm-backend`
|
||||
explicitly. Note that `--target` selects the agent integration, not the LLM
|
||||
provider: `ktx setup --target claude-code --no-input` still needs
|
||||
`--llm-backend claude-code` to use your Claude subscription for **ktx** LLM
|
||||
calls.
|
||||
|
||||
### Embeddings
|
||||
|
||||
| Flag | Description |
|
||||
|
|
@ -276,6 +283,7 @@ Use `ktx status` for repeatable readiness checks after setup exits.
|
|||
|-------|-------|----------|
|
||||
| Setup resumes an unexpected project | `KTX_PROJECT_DIR` or nearest `ktx.yaml` points to another directory | Pass `--project-dir <path>` explicitly |
|
||||
| Setup cannot run in CI | Required values are missing and `--no-input` disables prompts | Provide the relevant automation flags or create a fixture `ktx.yaml` |
|
||||
| `Missing LLM backend: pass --llm-backend …` | `--no-input` setup ran without an LLM backend; `--target` does not select one | Pass `--llm-backend claude-code`, `codex`, `anthropic`, or `vertex` (with that backend's credential flags) |
|
||||
| Provider health check fails | Provider key, model id, Vertex project, or Vertex location is invalid | Fix the `env:` or `file:` reference and rerun setup |
|
||||
| Python runtime is missing | The selected setup needs runtime-backed agent, query-history, Looker, or local embedding features | Accept the interactive prompt, rerun with `--yes`, or run the suggested `ktx admin runtime install` command |
|
||||
| `--enable-query-history` is rejected | The selected database driver does not support query history | Use Postgres, BigQuery, or Snowflake, or rerun without query-history flags |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue