diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index c51faf2a1..f67eba333 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -51,6 +51,7 @@ export default withMermaid(defineConfig({ { text: 'Model Context Protocol', link: '/zh/customization/mcp' }, { text: 'Agent Skills', link: '/zh/customization/skills' }, { text: 'Agent 与子 Agent', link: '/zh/customization/agents' }, + { text: 'AGENTS.md 项目指南', link: '/zh/customization/agents-md' }, { text: 'Print 模式', link: '/zh/customization/print-mode' }, { text: 'Wire 模式', link: '/zh/customization/wire-mode' }, ], @@ -132,6 +133,7 @@ export default withMermaid(defineConfig({ { text: 'Model Context Protocol', link: '/en/customization/mcp' }, { text: 'Agent Skills', link: '/en/customization/skills' }, { text: 'Agents and Subagents', link: '/en/customization/agents' }, + { text: 'AGENTS.md Project Guide', link: '/en/customization/agents-md' }, { text: 'Print Mode', link: '/en/customization/print-mode' }, { text: 'Wire Mode', link: '/en/customization/wire-mode' }, ], diff --git a/docs/en/customization/agents-md.md b/docs/en/customization/agents-md.md new file mode 100644 index 000000000..8fef7b4ab --- /dev/null +++ b/docs/en/customization/agents-md.md @@ -0,0 +1,95 @@ +# AGENTS.md project guide + +`AGENTS.md` is a Markdown file placed in the project root, written specifically for AI coding agents. Kimi Code CLI automatically reads it when starting a session and injects its content into the system prompt, so the agent understands the project's background, conventions, and constraints from the very first turn. + +## How it differs from README.md + +`README.md` is for human readers — it describes the project's purpose, installation steps, and usage examples. `AGENTS.md` is for AI agents — it tells the agent how to work correctly within the project. The two serve different purposes: + +| | `README.md` | `AGENTS.md` | +|---|---|---| +| Audience | Human developers and users | AI coding agents | +| Purpose | Introduce the project, guide onboarding | Provide project context and working constraints | +| Typical content | Feature overview, install steps, screenshots | Build commands, code style, directory layout, test instructions | + +A project can have both files without conflict. + +## Why you need AGENTS.md + +When an AI agent enters an unfamiliar project, it knows nothing about the project structure, tech stack, or team conventions. Without `AGENTS.md`, the agent either spends many turns exploring on its own or makes assumptions that don't match the project's norms. A good `AGENTS.md` can: + +- Reduce exploration overhead so the agent gets productive faster +- Prevent the agent from violating team code style or directory conventions +- Make common commands for building, testing, and linting immediately clear +- Inform the agent about special project restrictions (e.g., "do not modify the `generated/` directory") + +## How Kimi Code CLI loads AGENTS.md + +When creating a session, Kimi Code CLI looks for the following files in the current working directory, in order: + +1. `AGENTS.md` (uppercase) +2. `agents.md` (lowercase) + +It reads the first file found and injects the full content into the agent's system prompt via the `${KIMI_AGENTS_MD}` variable. If neither file exists, the variable is an empty string — the agent starts normally but without project context. + +::: warning Note +Kimi Code CLI only looks for `AGENTS.md` in the working directory. It does not traverse parent directories or load from the user's home directory. If your project has nested subdirectories, make sure the file is in the directory where you launch `kimi`. +::: + +## Generating AGENTS.md with /init + +Run the `/init` slash command in a Kimi Code CLI session, and the agent will automatically explore the current project directory, analyze the project structure, tech stack, build configuration, and code organization, then write the results to an `AGENTS.md` file in the working directory. + +How `/init` works: + +1. Creates a temporary isolated context to avoid polluting the current session +2. Lets the agent explore the project and generate `AGENTS.md` in that temporary context +3. Loads the generated file content back into the current session + +If an `AGENTS.md` already exists in the working directory, `/init` will reference its existing content when overwriting. After generation, you should review the file and make corrections or additions as needed. + +## Recommended content + +A practical `AGENTS.md` typically includes the following (include what's relevant — you don't need to cover everything): + +**Project overview** — One or two paragraphs explaining what the project is, what tech stack it uses, and what scenarios it targets. Assume the reader knows nothing about the project. + +**Build and test commands** — List the most common commands for daily development, for example: + +```sh +# Install dependencies +npm install + +# Run tests +npm test + +# Build the project +npm run build + +# Lint check +npm run lint +``` + +**Code style** — Describe the coding conventions the project follows, such as indentation style, naming conventions, import ordering rules, and whether specific linter configurations are used. + +**Directory layout** — Briefly describe the purpose of main directories, such as `src/` for source code, `tests/` for tests, `docs/` for documentation, etc. For large projects, helping the agent quickly locate where code lives is valuable. + +**Common workflows** — Describe the team's development habits, such as branching strategy, commit message format, and PR process. + +**Constraints and restrictions** — Explicitly tell the agent what it should not do, for example: + +- Do not modify auto-generated files +- Do not commit directly to the `main` branch +- Tests must run in a specific environment + +## When to update AGENTS.md + +`AGENTS.md` is not a write-once-and-forget file. Consider updating it when: + +- The project's tech stack or build system changes +- Important directories or modules are added +- Code conventions are adjusted (e.g., switching linter tools or style configurations) +- Team conventions change (e.g., branching strategy, commit format) +- You notice the agent repeatedly making a specific mistake — document the correct approach + +You can rerun `/init` at any time to let the agent regenerate the content, or edit the file manually. Keeping `AGENTS.md` in sync with the actual project state is key to the agent working effectively over time. diff --git a/docs/en/customization/agents.md b/docs/en/customization/agents.md index 61b891302..ed8c3924c 100644 --- a/docs/en/customization/agents.md +++ b/docs/en/customization/agents.md @@ -2,6 +2,8 @@ An agent defines the AI's behavior, including system prompts, available tools, and subagents. You can use built-in agents or create custom agents. +To learn how to provide project context to the agent via an `AGENTS.md` file, see [AGENTS.md project guide](./agents-md.md). + ## Built-in agents Kimi Code CLI provides two built-in agents. You can select one at startup with the `--agent` flag: diff --git a/docs/en/guides/interaction.md b/docs/en/guides/interaction.md index 3f0e96de2..0451f54ad 100644 --- a/docs/en/guides/interaction.md +++ b/docs/en/guides/interaction.md @@ -162,3 +162,46 @@ When YOLO mode is enabled, a yellow YOLO badge appears in the status bar at the ::: warning Note YOLO mode skips all confirmations. Make sure you understand the potential risks. It's recommended to only use this in controlled environments. ::: + +## Security boundaries + +Kimi Code CLI runs directly in your terminal with no sandbox isolation. Shell commands, file operations, and MCP tool calls executed by the agent take effect in your real operating system environment — no different from running commands manually in your terminal. Understanding these boundaries helps you use Kimi Code CLI safely. + +### Workspace scope + +The agent's file operations are centered around the working directory. Read-only tools like `ReadFile`, `Glob`, and `Grep` can access files within the working directory using relative paths, or read files outside it using absolute paths. `WriteFile` and `StrReplaceFile` work the same way, but all write and edit operations require user approval. + +Using the `--add-dir` startup flag or the `/add-dir` command during a session, you can add extra directories to the workspace. Once added, these directories have equal standing with the main working directory — the agent can freely read and write files in them (writes still require approval). Information about additional directories is passed to the system prompt via the `${KIMI_ADDITIONAL_DIRS_INFO}` variable. + +### What operations require approval + +In the default mode, the following operations request your confirmation before each execution: + +| Operation | Approval granularity | +|-----------|---------------------| +| `Shell` command execution | Each command | +| `WriteFile` file writes | Each write | +| `StrReplaceFile` file edits | Each edit | +| MCP tool calls | Each call | + +Read-only tools (`ReadFile`, `ReadMediaFile`, `Glob`, `Grep`, `SearchWeb`, `FetchURL`) do not require approval. + +You can select "Allow for this session" to automatically approve similar operations for the current session. This decision is persisted with the session state and automatically restored when resuming. + +### Risks of YOLO mode + +When YOLO mode is enabled (`kimi --yolo` or `/yolo`), all approval requests are automatically granted. The agent can execute arbitrary shell commands and file modifications without confirmation. This means: + +- The agent can delete files, overwrite code, and perform destructive git operations +- If the agent misunderstands the task, it may make irreversible changes +- If the project has MCP tools configured, those tools are also automatically approved + +Use YOLO mode only when: the project has solid version control, you are running in a recoverable environment such as a container or VM, or you are performing a well-defined low-risk task. + +### MCP tool risk boundaries + +MCP tools are provided by external MCP servers, and their behavior is not controlled by Kimi Code CLI. Each MCP tool call requires user approval by default, but is automatically approved in YOLO mode. When using MCP tools, keep in mind: + +- MCP servers may access the network, databases, or other external resources +- MCP tool inputs and outputs pass through the agent, which may take further actions based on the results +- Make sure you trust the MCP servers you have configured and understand the scope of their tools diff --git a/docs/en/index.md b/docs/en/index.md index af98035da..3b2a8f558 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -12,3 +12,17 @@ hero: text: GitHub link: https://github.com/MoonshotAI/kimi-cli --- + +