Kimi Code CLI - Architecture Documentation
kimi-code
Kimi Code CLI - Architecture Documentation
This directory contains architecture documentation for the Kimi Code CLI project, an AI-powered terminal agent built by Moonshot AI.
Documentation Index
| Document | Description |
|---|---|
| 00-overview.md | High-level summary, tech stack, directory structure |
| 01-entry-points.md | Entry points, CLI commands, execution flow |
| 02-core-logic.md | Agent loop, LLM integration, data flow |
| 03-key-abstractions.md | Important classes, design patterns |
| 04-configuration.md | Configuration system, environment variables |
Quick Start
If you're new to the codebase, read the documents in order:
- Overview - Understand what Kimi CLI is and its tech stack
- Entry Points - Learn how the CLI starts and runs
- Core Logic - Dive into the agent loop
- Key Abstractions - Understand the main classes
- Configuration - Configure the application
Architecture at a Glance
┌────────────────────────────────────────────────────────────┐
│ KimiCLI │
│ (app.py) │
└───────────────────────────┬────────────────────────────────┘
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Runtime │ │ Agent │ │ Context │
│ (all deps) │ │ (prompt+tools) │ │ (history) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌──────────────────────────┐
│ KimiSoul │
│ (agent loop) │
└──────────────────────────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ LLM │ │ Tools │ │ Wire │
│ (kosong) │ │ (toolset) │ │ (events) │
└───────────┘ └───────────┘ └───────────┘
Key Components
| Component | Location | Purpose |
|---|---|---|
KimiCLI |
src/kimi_cli/app.py |
Main orchestrator |
KimiSoul |
src/kimi_cli/soul/kimisoul.py |
Agent loop |
Runtime |
src/kimi_cli/soul/agent.py |
Execution context |
Agent |
src/kimi_cli/soul/agent.py |
Prompt + tools |
Context |
src/kimi_cli/soul/context.py |
Message history |
KimiToolset |
src/kimi_cli/soul/toolset.py |
Tool registry |
Approval |
src/kimi_cli/soul/approval.py |
Action gating |
Contributing
When modifying the architecture:
- Update relevant documentation files
- Keep diagrams in sync with code changes
- Verify line number references are accurate