CodeDocs Vault

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:

  1. Overview - Understand what Kimi CLI is and its tech stack
  2. Entry Points - Learn how the CLI starts and runs
  3. Core Logic - Dive into the agent loop
  4. Key Abstractions - Understand the main classes
  5. 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:

  1. Update relevant documentation files
  2. Keep diagrams in sync with code changes
  3. Verify line number references are accurate