Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
571c3e6
feat(agent-core-v2): let plugins contribute system prompt instruction…
7Sageer Jul 28, 2026
5e4f572
feat(agent-core-v2): add systemPromptPath to load plugin system promp…
7Sageer Jul 28, 2026
f63de0c
docs: explain plugin system prompt templates
7Sageer Jul 28, 2026
6118dc6
fix(agent-core-v2): refresh plugin system prompts after changes
7Sageer Jul 28, 2026
b1a0613
Merge remote-tracking branch 'origin/main' into feat/plugin-system-pr…
7Sageer Jul 28, 2026
774664d
fix(agent-core-v2): freeze restored profile bindings and converge plu…
7Sageer Jul 28, 2026
a26976d
fix(agent-core-v2): register the new session domain and dedupe the mi…
7Sageer Jul 28, 2026
e96d94f
fix(agent-core-v2): dedupe the plugin budget warning and surface sect…
7Sageer Jul 28, 2026
16f8b6f
fix(agent-core-v2): serialize session convergence and restore onDidRe…
7Sageer Jul 28, 2026
db3ff25
docs(agent-core-v2): align convergence wording with the serialized se…
7Sageer Jul 28, 2026
d0eae88
fix(agent-core-v2): keep empty plugin sections byte-neutral in the pr…
7Sageer Jul 29, 2026
2a16fce
fix(agent-core-v2): pin a fork's profile so refresh triggers never re…
7Sageer Jul 29, 2026
3d2573d
fix(agent-core-v2): join in-flight convergence during agent bootstrap
7Sageer Jul 29, 2026
06c2f82
fix(agent-core-v2): bound the bootstrap convergence join by the timeout
7Sageer Jul 29, 2026
1262bd1
fix(agent-core-v2): close the convergence race against in-progress re…
7Sageer Jul 29, 2026
4d472b9
fix(agent-core-v2): bound each convergence so a wedged participant ca…
7Sageer Jul 29, 2026
75441b4
fix(agent-core-v2): bound the skill reload, preserve user-tool overla…
7Sageer Jul 29, 2026
b3b5e28
feat(agent-core-v2): converge cold plugin changes on resume through a…
7Sageer Jul 29, 2026
fd183f0
fix(agent-core-v2): bound the restored-prompt gate and land the secti…
7Sageer Jul 29, 2026
4aa2b44
Update plugin system-prompt instructions in changeset
7Sageer Jul 29, 2026
7abda21
refactor(agent-core-v2): keep plugin skill reload user-driven
7Sageer Jul 29, 2026
d66d94f
refactor(agent-core-v2): apply plugin system-prompt changes only on e…
7Sageer Jul 29, 2026
c0daf92
feat(agent-core): let plugins contribute system prompt instructions v…
7Sageer Jul 29, 2026
c093b56
chore(agent-core-v2): remove inline implementation comment
7Sageer Jul 29, 2026
11c475e
docs: clarify plugin prompt refresh semantics
7Sageer Jul 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plugin-system-prompt-section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": minor
---

Allow enabled plugins to contribute agent system-prompt instructions through `systemPrompt` or `systemPromptPath` in `kimi.plugin.json`, effective on both agent engines (the TUI, `kimi -p`, and `kimi web`).
9 changes: 6 additions & 3 deletions docs/en/customization/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ You are a strict code reviewer. Read the diff, then report findings grouped by s

Built-in and user tools match by exact, case-sensitive name; entries starting with `mcp__` match MCP tools as globs. Three entry shapes never match anything and are reported with a warning when the profile takes effect: a wildcard outside an `mcp__` pattern (a bare `*` in `disallowedTools` disables nothing), an `mcp__` literal that is not a full `mcp__<server>__<tool>` name (`mcp__github` matches nothing — use `mcp__github__*` for the whole server), and a name no registered or built-in tool has (usually a typo, such as `read` instead of `Read`).

The body is the agent's system prompt, and it is rendered as a template each time the prompt is built: `${var}` placeholders substitute live context values — unknown variables stay verbatim, a bare `$` is never special, and a variable with no context value renders as an empty string. `${base_prompt}` embeds the effective default system prompt (the built-in default, or your `SYSTEM.md` override when present), so a file can wrap the default behavior instead of replacing it. The available variables are listed in the SYSTEM.md section below.
The body is the agent's system prompt, and it is rendered as a template each time the prompt is built: `${var}` placeholders substitute live context values — unknown variables stay verbatim, a bare `$` is never special, and a variable with no context value renders as an empty string. `${base_prompt}` embeds the effective default system prompt (the built-in default, or your `SYSTEM.md` override when present), so a file can wrap the default behavior instead of replacing it. If the file replaces the default prompt but should still honor instructions contributed by enabled plugins, place `${plugin_sections}` where those instructions should appear. The available variables are listed in the SYSTEM.md section below.

Unknown fields are ignored, so newer files stay readable by older versions. Fields from other agent tools (such as Claude Code's `model` or OpenCode's `mode`) are ignored the same way, the comma-separated `tools` form keeps Claude Code-style agent files loadable, and a missing `name` falls back to the file name so OpenCode-style files load too — a minimal file with `description` and a body works across tools.

Expand Down Expand Up @@ -134,7 +134,7 @@ KIMI_CODE_EXPERIMENTAL_FLAG=1 kimi -p --agent reviewer "Review the changes on th

The bound agent is the session's identity: it is fixed at the session's first bind and cannot be switched later. Re-selecting the already-bound agent (for example resuming with the same `--agent`) is a no-op; selecting a different one fails with an "already bound" error.

For main-agent customization, reference `${base_prompt}` in the body so the environment, workspace-instruction, and Skill injections from the default prompt stay in effect; a body without `${base_prompt}` owns the entire prompt, which fits self-contained sub-agents.
For main-agent customization, reference `${base_prompt}` in the body so the environment, workspace-instruction, Skill, and plugin injections already present in the effective default prompt stay in effect. When you want to replace the default prompt but keep only plugin-contributed instructions, use `${plugin_sections}` instead. A body without `${base_prompt}` or `${plugin_sections}` owns the entire prompt and excludes plugin instructions, which fits self-contained sub-agents.

### Overriding the main agent's system prompt with SYSTEM.md

Expand All @@ -155,15 +155,18 @@ Like the body of a regular agent file, SYSTEM.md is rendered as a template each
| `${now}` | Current time in ISO format |
| `${additional_dirs_info}` | Additional directories added to the workspace; empty when there are none |
| `${base_prompt}` | The default system prompt. Inside `SYSTEM.md` itself this is the built-in default; inside an agent file it is the effective default — the built-in default, or your `SYSTEM.md` override when present |
| `${plugin_sections}` | A complete Plugin Instructions block contributed by enabled plugins; empty when no enabled plugin contributes instructions |

Unknown variables stay verbatim, a bare `$` is never special, and a variable with no context value renders as an empty string. Three pre-composed blocks — `${windows_notes}`, `${additional_dirs_section}`, and `${skills_section}` — render the matching built-in prompt section, or an empty string when it does not apply. The variables are enough to rebuild the skeleton of the built-in prompt, for example:
Unknown variables stay verbatim, a bare `$` is never special, and a variable with no context value renders as an empty string. Four pre-composed blocks — `${windows_notes}`, `${additional_dirs_section}`, `${skills_section}`, and `${plugin_sections}` — render the matching built-in prompt section, or an empty string when it does not apply. The built-in default prompt already includes `${plugin_sections}`, so do not add it again when `${base_prompt}` already expands to that prompt. The variables are enough to rebuild the skeleton of the built-in prompt, for example:

```markdown
You are Kimi, running at ${cwd} on ${os}.

${agents_md}

${skills}

${plugin_sections}
```

## Instruction Files
Expand Down
25 changes: 23 additions & 2 deletions docs/en/customization/plugins.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plugins

Plugins package reusable Kimi Code CLI capabilities into installable units — they can add [Agent Skills](./skills.md), automatically load a specified Skill at session start, and declare MCP servers to provide real tool capabilities. They are ideal for sharing workflows with a team, connecting to external services, or installing extensions from the official marketplace.
Plugins package reusable Kimi Code CLI capabilities into installable units — they can add [Agent Skills](./skills.md), automatically load a specified Skill at session start, contribute system-prompt instructions, and declare MCP servers to provide real tool capabilities. They are ideal for sharing workflows with a team, connecting to external services, or installing extensions from the official marketplace.

## Installation and Management

Expand Down Expand Up @@ -143,6 +143,7 @@ Example:
"version": "1.0.0",
"description": "Finance data and analysis workflows for Kimi Code CLI",
"skills": "./skills/",
"systemPromptPath": "./SYSTEM.md",
"sessionStart": {
"skill": "using-finance"
},
Expand All @@ -163,12 +164,33 @@ Supported fields:
| `skills` | One or more `./` paths; must be within the plugin root directory. When omitted, the `SKILL.md` in the root directory is treated as a single Skill root |
| `sessionStart.skill` | Loads the specified plugin Skill into the main Agent when a new or resumed session starts |
| `skillInstructions` | Additional instructions appended whenever a Skill from this plugin is loaded |
| `systemPrompt` | Inline instructions contributed to the agent's system prompt while the plugin is enabled |
| `systemPromptPath` | A `./` path to a UTF-8 text file containing system-prompt instructions; combined after `systemPrompt` when both are present |
| `mcpServers` | MCP server declarations; enabled by default, can be disabled from `/plugins` |
| `hooks` | Hook rules run on lifecycle events while the plugin is enabled; see [Hooks in Plugins](#hooks-in-plugins) |
| `commands` | One or more `./` paths pointing to a directory or `.md` file; registers the Markdown files within as slash commands. See [Plugin Slash Commands](#plugin-slash-commands) |

Unsupported runtime fields such as `tools`, `apps`, `inject`, and `configFile` appear as diagnostics and are ignored.

### System-prompt instructions

Use `systemPrompt` for a short inline instruction, or `systemPromptPath` to keep longer instructions in a file inside the plugin root. If both fields are present, the inline text appears first, followed by the file content. The file content is read when the plugin is installed or reloaded, so edits take effect only after `/plugins reload`. For example:

```json
{
"name": "code-review",
"systemPromptPath": "./SYSTEM.md"
}
```

System-prompt contributions take effect on both agent engines: the interactive TUI and `kimi -p` (the v1 engine), `kimi web`, and any CLI surface with `KIMI_CODE_EXPERIMENTAL_FLAG=1` (the v2 engine).

Each field — the inline `systemPrompt` and the `systemPromptPath` file — is limited to 32 KB (UTF-8 bytes): oversized content is ignored and reported in the plugin diagnostics. Across all enabled plugins, one prompt build injects at most 64 KB of instructions; contributions beyond the budget are skipped with a warning, including a single plugin whose inline text and file together exceed that budget.

New sessions and newly created agents read the contributions from the plugins currently enabled. An in-flight request keeps its existing system prompt. `/plugins reload` refreshes the plugin skill list and requests prompt rebuilds for live agents; use it when you need the change to converge deliberately before the next turn. On the v2 engine, installing, enabling, disabling, or removing a plugin updates the catalog immediately and a later prompt rebuild — for example after compaction or a tool-policy change — may pick up the new sections. The legacy engine keeps each live session's plugin snapshot until `/plugins reload` or a new session. A resumed session starts from its persisted prompt, and later rebuilds follow the engine-specific behavior above. Toggling a plugin's MCP server does not change system-prompt sections.

The built-in agent prompt includes instructions from enabled plugins automatically. A custom `SYSTEM.md` or agent file owns its template, so include `${plugin_sections}` where plugin-contributed instructions should appear. If the custom template includes `${base_prompt}` and that effective default already contains the plugin block, do not add `${plugin_sections}` again. See [Custom agents and SYSTEM.md](./agents.md#overriding-the-main-agent-s-system-prompt-with-system-md) for the complete variable table.

## Plugin Slash Commands

Slash commands save a prompt you use often as a `/command`, so you can trigger it by typing the command instead of retyping the whole thing.
Expand Down Expand Up @@ -323,4 +345,3 @@ Plugins have a limited loading scope. The following operations do not occur duri
- All paths must remain within the plugin root directory after symbolic link resolution
- MCP servers of enabled plugins start after `/reload` or in new sessions and can be disabled at any time from `/plugins`
- Broken manifests or unsafe paths appear in `/plugins info <id>` diagnostics and do not affect other sessions

9 changes: 6 additions & 3 deletions docs/zh/customization/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ disallowedTools:

内置工具与用户工具按名称精确匹配(区分大小写);以 `mcp__` 开头的条目按 glob 匹配 MCP 工具。有三种写法永远匹配不到任何工具,在 profile 生效时会给出警告:`mcp__` 模式之外使用通配符(`disallowedTools` 里单独的 `*` 什么也禁不掉);不是完整 `mcp__<服务器>__<工具>` 形式的 `mcp__` 字面量(`mcp__github` 匹配不到任何工具 —— 匹配整个服务器要用 `mcp__github__*`);以及任何已注册或内置工具都没有的名字(通常是笔误,如把 `Read` 写成 `read`)。

正文即 Agent 的系统提示词,每次构建提示词时都会作为模板渲染:`${var}` 占位符替换为实时上下文值——未知变量保持原样,单独的 `$` 没有特殊含义,上下文中缺失的变量渲染为空字符串。`${base_prompt}` 会在你放置它的位置嵌入有效默认系统提示词(内置默认,或存在时为你的 `SYSTEM.md` 覆盖),因此文件可以"包裹"默认行为而不是替换它。可用变量见下文 SYSTEM.md 变量表。
正文即 Agent 的系统提示词,每次构建提示词时都会作为模板渲染:`${var}` 占位符替换为实时上下文值——未知变量保持原样,单独的 `$` 没有特殊含义,上下文中缺失的变量渲染为空字符串。`${base_prompt}` 会在你放置它的位置嵌入有效默认系统提示词(内置默认,或存在时为你的 `SYSTEM.md` 覆盖),因此文件可以"包裹"默认行为而不是替换它。如果文件会替换默认提示词、但仍要保留已启用 plugin 提供的指令,请把 `${plugin_sections}` 放在希望出现这些指令的位置。可用变量见下文 SYSTEM.md 变量表。

未知字段会被忽略,新版本写的文件在旧版本上仍可读取。其他 Agent 工具的字段(如 Claude Code 的 `model`、OpenCode 的 `mode`)同样会被忽略;加上 `tools` 的逗号分隔写法和 `name` 缺省回退到文件名,Claude Code 与 OpenCode 风格的 Agent 文件一般可直接加载 —— 只含 `description` 和正文的最小文件可跨工具通用。

Expand Down Expand Up @@ -134,7 +134,7 @@ KIMI_CODE_EXPERIMENTAL_FLAG=1 kimi -p --agent reviewer "审查这个分支上的

绑定的 Agent 即会话的身份:在会话首次绑定后即固定,之后不可切换。重复选择已绑定的 Agent(例如以相同的 `--agent` 恢复会话)是 no-op;选择不同的 Agent 会报 "already bound" 错误。

定制主 Agent 时,在正文中引用 `${base_prompt}` 可保持默认提示词的环境、工作区指令和 Skill 注入生效;不引用 `${base_prompt}` 的正文则完全拥有自己的提示词,适合自包含的子 Agent。
定制主 Agent 时,在正文中引用 `${base_prompt}` 可保持有效默认提示词中已有的环境、工作区指令、Skill 和 plugin 注入生效。如果要替换默认提示词、但只保留 plugin 提供的指令,请改用 `${plugin_sections}`。正文同时不引用 `${base_prompt}` 和 `${plugin_sections}` 时,会完全拥有自己的提示词并排除 plugin 指令,适合自包含的子 Agent。

### 用 SYSTEM.md 覆盖主 Agent 的系统提示词

Expand All @@ -155,15 +155,18 @@ SYSTEM.md 是纯 Markdown 正文,不需要也不读取 Frontmatter。文件缺
| `${now}` | 当前时间(ISO 格式) |
| `${additional_dirs_info}` | 加入工作区的额外目录信息;没有时为空 |
| `${base_prompt}` | 默认系统提示词。在 `SYSTEM.md` 中指内置默认提示词;在 Agent 文件中指有效默认提示词(内置默认,或存在时为你的 `SYSTEM.md` 覆盖) |
| `${plugin_sections}` | 已启用 plugin 提供的完整 Plugin Instructions 块;没有已启用 plugin 提供指令时为空 |

未知变量原样保留,单独的 `$` 没有特殊含义;上下文中缺失的变量渲染为空字符串。另有三个预组合块——`${windows_notes}`、`${additional_dirs_section}`、`${skills_section}`——渲染对应的内置提示词段落,不适用时为空字符串。利用这些变量可以重建内置提示词的骨架,例如:
未知变量原样保留,单独的 `$` 没有特殊含义;上下文中缺失的变量渲染为空字符串。另有四个预组合块——`${windows_notes}`、`${additional_dirs_section}`、`${skills_section}`、`${plugin_sections}`——渲染对应的内置提示词段落,不适用时为空字符串。内置默认提示词已经包含 `${plugin_sections}`;当 `${base_prompt}` 已展开为该提示词时,不要再重复加入此变量。利用这些变量可以重建内置提示词的骨架,例如:

```markdown
You are Kimi, running at ${cwd} on ${os}.

${agents_md}

${skills}

${plugin_sections}
```

## 指令文件
Expand Down
Loading
Loading