ktx/docs-site/content/docs/cli-reference/ktx.mdx
Andrey Avtomonov 2c9a58bb56
feat(cli): smart defaults and flatter command surface for ktx (#177)
Bare invocations now do the obvious thing instead of erroring out, and mode-as-subcommand patterns collapse into flags on the parent. No new top-level commands.

- `ktx ingest` (bare) ingests every configured connection. The `text` subcommand is gone; capture inline notes with `ktx ingest --text "..."` and files with `ktx ingest --file path` (use `-` for stdin). `--text`/`--file` reject a positional connection id; pass `--connection-id` to tag captured notes.
- `ktx connection` (bare) lists; `ktx connection test` (bare) tests every configured connection.
- `ktx wiki` and `ktx sl` flatten `list`/`search`: bare lists, with a `[query...]` positional searches (multi-word joined with spaces). `sl validate` and `sl query` stay as distinct verbs and now read `--connection-id` from the parent.
- `ktx mcp` (bare) prints daemon status.

Adds a shared `resolveConnectionSelection` helper consumed by ingest and connection test. Updates README, docs-site cli-reference and guides, next-steps strings, agent SKILL templates, and all affected tests. Per-package type-check, unit tests (605), smoke tests, and dead-code checks all pass.
2026-05-20 01:52:37 +02:00

105 lines
2.2 KiB
Text

---
title: "ktx"
description: "Root command map, global options, and project resolution for the KTX CLI."
---
The `ktx` CLI sets up local projects, builds agent-ready context, checks
connections, queries semantic-layer sources, searches wiki pages, runs the MCP
server, and manages the bundled Python runtime.
## Command signature
```bash
ktx [global-options] <command>
```
When you run bare `ktx` in an interactive terminal outside any KTX project, the
CLI starts the same guided setup flow as `ktx setup`. Inside an existing
project, use command-specific help:
```bash
ktx --help
ktx setup --help
ktx ingest --help
```
## Command map
```text
ktx
setup
connection
list
test [connectionId]
ingest [connectionId]
text [files...]
wiki
list
search <query>
sl
list
search <query>
validate <sourceName>
query
sql
status
mcp
start
stop
status
logs
admin
init [directory]
schema
runtime
install
start
stop
status
reindex
```
The public context-build entrypoint is `ktx ingest [connectionId]` or
`ktx ingest --all`.
## Global options
| Flag | Description |
|------|-------------|
| `--project-dir <path>` | KTX project directory. Defaults to `KTX_PROJECT_DIR`, then the nearest `ktx.yaml`, then the current working directory. |
| `--debug` | Print diagnostic dispatch and project-resolution details to stderr. |
| `-v`, `--version` | Show the CLI package name and version. |
| `-h`, `--help` | Show help for the current command. |
## Project resolution
Most commands are project-aware. Pass `--project-dir <path>` when scripting or
when you are outside the project directory. If you omit it, KTX checks
`KTX_PROJECT_DIR`, then walks upward for the nearest `ktx.yaml`, then falls back
to the current directory.
## Common workflows
```bash
# Start or resume setup
ktx setup
# Check readiness
ktx status
# Build one configured connection
ktx ingest warehouse
# Build every configured connection
ktx ingest
# Search semantic-layer sources and wiki pages
ktx sl "revenue"
ktx wiki "revenue recognition"
# Execute read-only SQL
ktx sql --connection warehouse "select count(*) from public.orders"
# Start the local MCP server for agent clients
ktx mcp start
```