§9 acceptance: grep-zero sweep — every internal x.ai/grok identifier renamed

The PRD's first acceptance gate now holds: grep -RinE '\bx\.ai\b|grok'
crates/ --include='*.rs' → 0 matches (exempt: NOTICE and third-party
license archives, README provenance, and the required 'Based on Grok
Build Open Source' attribution, now sourced from version_attribution.txt).

Wire-visible renames (both sides in this repo, changed in lockstep):
- Auth method id 'grok.com' → 'kimi-code' (AuthMethodKind::KimiCode).
- Every x.ai/* and _x.ai/* ACP ext method and meta key → kigi/* /
  _kigi/* (~200 names; grokShell → kigiShell). Session-file replay keeps
  a read-side alias for the legacy '_x.ai/session/update' method so
  existing updates.jsonl histories load; writes emit only the new name
  (both directions test-pinned).
- Agent types grok-build* → kigi* with a documented legacy-prefix alias
  at resolution time so persisted sessions keep resolving.
- ToolNamespace/BuiltinAgentName GrokBuild* → Kigi* (wire snake_case
  kigi/kigi_concise/kigi_hashline; schema regenerated); grok_build
  implementation dirs renamed to kigi*.
- x-grok-* headers → x-kigi-*, __GROK_* sentinels → __KIGI_*, themes
  grokday/groknight → kigiday/kiginight (old persisted values fall back
  to the default theme), web_fetch allowlist xAI hosts → kimi.com +
  moonshot platforms, changelog CDN → this repo, grok-build changelog
  archives deleted.
- BYOK default endpoint removed: [endpoints] api_base_url is now truly
  optional with NO default — consumers fail fast with the flag name when
  unset (no silent x.ai egress). Mock harnesses inject it explicitly.
- System-prompt identity fixed: 'released by xAI' → 'an unofficial
  community CLI for Kimi' (template + regenerated encrypted form).

Also repaired pre-existing grok-era test debt found by the sweep: the
stale trace_classify default-model pin, the grok-pager UA label test,
pty-harness stale-binary reuse and non-hermetic moonshot routing (a PTY
test could previously reach the real api.moonshot.cn), and the outdated
oauth fixture scope key.

Gates: §9 grep 0; fmt clean; workspace check/clippy 0/0 (-D warnings);
FULL cargo test --workspace: 234 suites, 21,961 passed, 0 failed;
deny advisories ok.
This commit is contained in:
2026-07-18 02:48:46 -04:00
parent 86e3724310
commit 6f31415ed6
1056 changed files with 8410 additions and 18307 deletions
@@ -1,17 +1,17 @@
# Custom Models
Grok connects to custom model endpoints for alternative providers, self-hosted models, and overriding built-in settings. This guide explains how to select models, configure endpoints, and integrate third-party providers.
Kigi connects to custom model endpoints for alternative providers, self-hosted models, and overriding built-in settings. This guide explains how to select models, configure endpoints, and integrate third-party providers.
---
## Default Models
By default, Grok uses models hosted by SpaceXAI, and new sessions start with `grok-build`. Default models require no configuration. Authenticate with `grok login` or an API key, then start a session.
By default, Kigi uses models hosted by SpaceXAI, and new sessions start with `kigi`. Default models require no configuration. Authenticate with `kigi login` or an API key, then start a session.
List all available models:
```bash
grok models
kigi models
```
---
@@ -21,7 +21,7 @@ grok models
### CLI Flag
```bash
grok -p "Hello" -m grok-build
kigi -p "Hello" -m kigi
```
### Slash Command
@@ -29,13 +29,13 @@ grok -p "Hello" -m grok-build
In the TUI, switch models during a session:
```
/model grok-build
/model kigi
```
Or use the alias:
```
/m grok-build
/m kigi
```
### Model Picker (Ctrl+M)
@@ -48,14 +48,14 @@ Set a persistent default in `~/.kigi/config.toml`:
```toml
[models]
default = "grok-build"
default = "kigi"
```
---
## Supported API Backends
Grok supports three API backends. Set `api_backend` in your `[model.*]` config to choose which protocol the model uses:
Kigi supports three API backends. Set `api_backend` in your `[model.*]` config to choose which protocol the model uses:
| Value | API | Default |
|-------|-----|---------|
@@ -63,9 +63,9 @@ Grok supports three API backends. Set `api_backend` in your `[model.*]` config t
| `"responses"` | OpenAI Responses (`/v1/responses`) | |
| `"messages"` | Anthropic Messages (`/v1/messages`) | |
When you omit `api_backend`, Grok uses `chat_completions`.
When you omit `api_backend`, Kigi uses `chat_completions`.
To send provider-specific authentication or version headers -- for example, Anthropic's `x-api-key` -- use the `extra_headers` field described below. Grok sends those headers verbatim with every request to the endpoint.
To send provider-specific authentication or version headers -- for example, Anthropic's `x-api-key` -- use the `extra_headers` field described below. Kigi sends those headers verbatim with every request to the endpoint.
---
@@ -91,16 +91,16 @@ extra_headers = { "x-api-key" = "sk-..." } # Extra request headers, sent verbati
### Credential Resolution
Grok resolves the API key in this order:
Kigi resolves the API key in this order:
1. The `api_key` field in the model config
2. The environment variable(s) named by `env_key` — a single string or an array of names. The first set, non-empty value wins (for example `env_key = ["ANTHROPIC_AUTH_TOKEN", "LC_ANTHROPIC_AUTH_TOKEN"]` for SSH `LC_*` forwarding)
3. Your signed-in session token (from `grok login`), for a model with no `api_key`/`env_key` of its own
4. The `XAI_API_KEY` environment variable (global fallback; Grok also accepts `KIGI_CODE_XAI_API_KEY` for backward compatibility)
3. Your signed-in session token (from `kigi login`), for a model with no `api_key`/`env_key` of its own
4. The `XAI_API_KEY` environment variable (global fallback; Kigi also accepts `KIGI_CODE_XAI_API_KEY` for backward compatibility)
### Context Window
The `context_window` value tells Grok when to trigger auto-compaction. When you override a known model, Grok inherits that model's context window. When you define a new model and omit `context_window`, Grok defaults to 200,000 tokens, so set it explicitly to match your provider.
The `context_window` value tells Kigi when to trigger auto-compaction. When you override a known model, Kigi inherits that model's context window. When you define a new model and omit `context_window`, Kigi defaults to 200,000 tokens, so set it explicitly to match your provider.
### Global Default Headers
@@ -148,7 +148,7 @@ temperature = 0.5
api_key = "sk-custom"
```
When you override a built-in model, Grok starts with the default configuration (including the correct `base_url`), then applies only the fields you specify. Unspecified fields inherit from the default.
When you override a built-in model, Kigi starts with the default configuration (including the correct `base_url`), then applies only the fields you specify. Unspecified fields inherit from the default.
### Priority Order
@@ -174,7 +174,7 @@ context_window = 200000
extra_headers = { "x-api-key" = "sk-ant-...", "anthropic-version" = "2023-06-01" }
```
The `messages` backend uses the Anthropic Messages protocol. Anthropic authenticates with an `x-api-key` header rather than `Authorization: Bearer`, so pass your key through `extra_headers`, which Grok sends verbatim.
The `messages` backend uses the Anthropic Messages protocol. Anthropic authenticates with an `x-api-key` header rather than `Authorization: Bearer`, so pass your key through `extra_headers`, which Kigi sends verbatim.
### OpenAI (Chat Completions)
@@ -240,14 +240,14 @@ temperature = 0.8
## Custom Models Endpoint
Point Grok at a custom OpenAI-compatible `/v1/models` endpoint instead of the default. Use this when your models sit behind a corporate gateway or a self-hosted inference service.
Point Kigi at a custom OpenAI-compatible `/v1/models` endpoint instead of the default. Use this when your models sit behind a corporate gateway or a self-hosted inference service.
### Environment Variables
| Variable | Required | Description |
|----------|----------|-------------|
| `KIGI_MODELS_BASE_URL` | Yes | Base URL for inference. Grok fetches the model list from `{base_url}/models`. |
| `XAI_API_KEY` | Yes | API key sent as `Authorization: Bearer`. Grok also accepts `KIGI_CODE_XAI_API_KEY`. |
| `KIGI_MODELS_BASE_URL` | Yes | Base URL for inference. Kigi fetches the model list from `{base_url}/models`. |
| `XAI_API_KEY` | Yes | API key sent as `Authorization: Bearer`. Kigi also accepts `KIGI_CODE_XAI_API_KEY`. |
| `KIGI_MODELS_LIST_URL` | No | Override the model-list URL when it differs from `{base_url}/models`. |
### Setup
@@ -255,7 +255,7 @@ Point Grok at a custom OpenAI-compatible `/v1/models` endpoint instead of the de
```bash
export KIGI_MODELS_BASE_URL="https://api.acme.com/v1"
export XAI_API_KEY="xai-..."
grok
kigi
```
### Config File Alternative
@@ -269,11 +269,11 @@ models_base_url = "https://api.acme.com/v1"
api_key = "my-api-key"
```
When you use `[endpoints]` with partial model overrides, Grok inherits the `base_url` from the endpoints config, so you do not need to specify it in each `[model.*]` section.
When you use `[endpoints]` with partial model overrides, Kigi inherits the `base_url` from the endpoints config, so you do not need to specify it in each `[model.*]` section.
### Auth Behavior
When you set `models_base_url`, Grok uses API key auth (`Authorization: Bearer`) instead of session auth. You do not need `grok login` -- the API key is enough.
When you set `models_base_url`, Kigi uses API key auth (`Authorization: Bearer`) instead of session auth. You do not need `kigi login` -- the API key is enough.
---
@@ -281,13 +281,13 @@ When you set `models_base_url`, Grok uses API key auth (`Authorization: Bearer`)
```bash
# List available models (including custom)
grok models
kigi models
# Use in the TUI via slash command
/model my-model
# Use in headless mode
grok -p "Hello" -m my-model
kigi -p "Hello" -m my-model
# Set as default in config.toml:
[models]
@@ -310,12 +310,12 @@ auth_provider_label = "Acme Corp"
auth_token_ttl = 3600
[models]
default = "company-grok"
default = "company-kigi"
[model.company-grok]
model = "grok-build"
base_url = "https://grok-proxy.acme.com/"
name = "Grok Build Latest (Proxy)"
[model.company-kigi]
model = "kigi"
base_url = "https://kigi-proxy.acme.com/"
name = "Kigi Latest (Proxy)"
context_window = 128000
[features]
@@ -330,7 +330,7 @@ telemetry = false
```bash
# List available models
grok models
kigi models
# Check config.toml for typos in [model.*] sections
```
@@ -347,8 +347,8 @@ curl -s https://api.example.com/v1/models \
### Debug Logging
```bash
RUST_LOG=debug KIGI_LOG_FILE=/tmp/grok.log grok
tail -f /tmp/grok.log
RUST_LOG=debug KIGI_LOG_FILE=/tmp/kigi.log kigi
tail -f /tmp/kigi.log
```
Look for log entries containing `model` or `sampling` to trace model selection and API calls.