mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
feat: pursue a goal autonomously (#270)
This commit is contained in:
parent
191059d400
commit
ac37d74484
86 changed files with 6875 additions and 138 deletions
|
|
@ -118,6 +118,21 @@ export KIMI_DISABLE_TELEMETRY="1"
|
|||
```
|
||||
|
||||
`KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT` has higher priority than `config.toml`. For example, running `KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT=0 kimi -p "..."` temporarily requests stopping background tasks before this process exits, even if the config file sets `keep_alive_on_exit = true`.
|
||||
|
||||
## Experimental feature flags
|
||||
|
||||
Experimental features are gated behind `KIMI_CODE_EXPERIMENTAL_*` environment variables and are **off by default**. Each flag accepts truthy values (`1`, `true`, `yes`, `on`); the master switch `KIMI_CODE_EXPERIMENTAL_FLAG` forces every experimental feature on. These flags are not read from `config.toml`.
|
||||
|
||||
| Environment variable | Purpose | Default |
|
||||
| --- | --- | --- |
|
||||
| `KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND` | Enable the `/goal` command and autonomous goal mode. Kimi Code works toward a stated objective across automatic continuation turns until the goal completes, pauses, or becomes blocked. Stop conditions should be written in the objective, for example "stop after 20 turns if still blocked". See [Slash commands: autonomous goals](../reference/slash-commands.md#autonomous-goals). | `false` (off) |
|
||||
| `KIMI_CODE_EXPERIMENTAL_FLAG` | Master switch: force every experimental flag on | `false` (off) |
|
||||
|
||||
```sh
|
||||
# Try goal mode for a single launch
|
||||
KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1 kimi
|
||||
```
|
||||
|
||||
## Diagnostic logging
|
||||
|
||||
The variables below control `kimi`'s diagnostic logs. Logs are written to two locations: the global diagnostic log at `$KIMI_CODE_HOME/logs/kimi-code.log`, and each session's own diagnostic log at `<sessionDir>/logs/kimi-code.log` (see [Data locations](./data-locations.md#logs-and-update-state) for path details). All of these variables are read only once at process startup.
|
||||
|
|
|
|||
|
|
@ -43,11 +43,66 @@ Some commands are only available in the idle state. Running them while the sessi
|
|||
| `/auto [on\|off]` | — | Toggle auto permission mode. Without arguments, flip the current state; pass `on`/`off` explicitly to force the corresponding state. When enabled, tool approvals are handled automatically and the agent will not ask questions. | Yes |
|
||||
| `/plan [on\|off]` | — | Toggle Plan mode. Without arguments, flip the current state; pass `on`/`off` explicitly to force the corresponding state. Toggling alone does not create an empty plan file. | Yes |
|
||||
| `/plan clear` | — | Clear the current plan. | No |
|
||||
| `/goal [status\|pause\|resume\|cancel\|replace <objective>\|<objective>]` | — | Start or manage an autonomous goal. This command is experimental. Enable it with `KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1`. | See below |
|
||||
|
||||
::: warning Note
|
||||
`/yolo` skips approval confirmation for ordinary tool calls. Make sure you understand the potential risks before enabling it. It does not skip the approval required to leave Plan mode; in Plan mode, `Bash` follows the same ordinary allow rules as `/yolo`.
|
||||
:::
|
||||
|
||||
## Autonomous goals
|
||||
|
||||
`/goal` is an experimental command for tasks where you want Kimi Code to keep working through automatic continuation turns. Enable it when starting `kimi`:
|
||||
|
||||
```sh
|
||||
KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1 kimi
|
||||
```
|
||||
|
||||
Experimental flags are read from environment variables. `config.toml` does not currently have an `experimental` option for `/goal`.
|
||||
|
||||
Start a goal by writing the objective after the command:
|
||||
|
||||
```sh
|
||||
/goal Update the checkout docs, run the docs build, and stop after 20 turns if this is still blocked
|
||||
```
|
||||
|
||||
Kimi Code saves the objective, sends it as the next user message, and keeps running turns until the goal stops. A goal can stop in three ways:
|
||||
|
||||
- `complete`: the objective is done. Kimi Code posts a completion message and clears the goal.
|
||||
- `paused`: you paused it, interrupted it, or resumed a session that had an active goal. You can resume it later.
|
||||
- `blocked`: Kimi Code stopped because it needs input, cannot complete the objective as written, hit a configured turn, token, or time budget, or ran into a runtime failure. You can resume it later.
|
||||
|
||||
Write stop conditions in the objective itself. `/goal` does not have separate flags for stop limits.
|
||||
|
||||
In the TUI, starting or replacing a goal in `manual` permission mode opens a confirmation prompt first. You can switch to `auto`, switch to `yolo`, or start in `manual`. You can also return to the input box with your `/goal` command still there.
|
||||
|
||||
`manual` mode is not suitable for unattended goal work. Kimi Code may stop and wait for your approval.
|
||||
|
||||
Use these forms to manage the current goal:
|
||||
|
||||
| Command | What it does | Availability |
|
||||
| --- | --- | --- |
|
||||
| `/goal` or `/goal status` | Show the current goal, status, elapsed time, turn count, token count, and any configured turn, token, or time budget. | Always available |
|
||||
| `/goal pause` | Pause the active goal and keep it saved. If a response is streaming, the current turn is interrupted. | Always available |
|
||||
| `/goal resume` | Resume a paused or blocked goal and start a new turn. | Idle only |
|
||||
| `/goal cancel` | Remove the current goal. If a response is streaming, the current turn is interrupted. | Always available |
|
||||
| `/goal replace <objective>` | Replace the saved goal with a new objective. | Idle only |
|
||||
|
||||
Only one goal can be saved in a session. If you already have one, start a different one with `/goal replace <objective>`.
|
||||
|
||||
The words `status`, `pause`, `resume`, `cancel`, and `replace` act as subcommands only when they are the first word after `/goal`. If your objective needs to start with one of those words, put `--` before it:
|
||||
|
||||
```sh
|
||||
/goal -- cancel the old rollout note after the new docs are published
|
||||
```
|
||||
|
||||
In non-interactive prompt mode, only the create forms start goal mode:
|
||||
|
||||
```sh
|
||||
KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1 kimi -p "/goal Fix the failing checkout test"
|
||||
```
|
||||
|
||||
Prompt mode exits with code `0` when the goal completes, `3` when it blocks, and `6` when it pauses. Other `/goal` subcommands are TUI controls and are not handled by `kimi -p`.
|
||||
|
||||
## Information and status
|
||||
|
||||
| Command | Alias | Description | Always available |
|
||||
|
|
|
|||
|
|
@ -119,6 +119,20 @@ export KIMI_DISABLE_TELEMETRY="1"
|
|||
|
||||
`KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT` 的优先级高于 `config.toml`。例如临时运行 `KIMI_CODE_BACKGROUND_KEEP_ALIVE_ON_EXIT=0 kimi -p "..."` 时,即使配置文件里写了 `keep_alive_on_exit = true`,本次进程退出前也会请求停止后台任务。
|
||||
|
||||
## 实验功能 flag
|
||||
|
||||
实验功能通过 `KIMI_CODE_EXPERIMENTAL_*` 环境变量控制,并且**默认关闭**。每个 flag 都接受真值(`1`、`true`、`yes`、`on`);主开关 `KIMI_CODE_EXPERIMENTAL_FLAG` 会强制启用所有实验功能。这些 flag 不会从 `config.toml` 读取。
|
||||
|
||||
| 环境变量 | 用途 | 默认值 |
|
||||
| --- | --- | --- |
|
||||
| `KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND` | 启用 `/goal` 命令和自主 goal 模式。Kimi Code 会围绕指定目标自动续跑多个轮次,直到目标完成、暂停或进入 blocked 状态。停止条件应写在目标本身里,例如「如果仍被阻塞,20 轮后停止」。详见 [斜杠命令:自主 goal](../reference/slash-commands.md#自主-goal)。 | `false`(关闭) |
|
||||
| `KIMI_CODE_EXPERIMENTAL_FLAG` | 主开关:强制启用所有实验功能 | `false`(关闭) |
|
||||
|
||||
```sh
|
||||
# 单次启动时试用 goal 模式
|
||||
KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1 kimi
|
||||
```
|
||||
|
||||
## 诊断日志
|
||||
|
||||
下列变量控制 `kimi` 的诊断日志。日志会写入两个位置:全局诊断日志在 `$KIMI_CODE_HOME/logs/kimi-code.log`,每个会话自身的诊断日志在 `<sessionDir>/logs/kimi-code.log`(路径细节见 [数据路径](./data-locations.md#日志与更新状态))。所有变量都只在进程启动时读取一次。
|
||||
|
|
|
|||
|
|
@ -43,11 +43,66 @@
|
|||
| `/auto [on\|off]` | — | 切换 auto 权限模式。不带参数时按当前状态翻转;显式传 `on`/`off` 时强制设为对应状态。开启后工具审批自动处理,Agent 不会向用户提问。 | 是 |
|
||||
| `/plan [on\|off]` | — | 切换 Plan 模式。不带参数时按当前状态翻转;显式传 `on`/`off` 时强制设为对应状态。单纯切换不会创建空计划文件。 | 是 |
|
||||
| `/plan clear` | — | 清除当前 plan 方案。 | 否 |
|
||||
| `/goal [status\|pause\|resume\|cancel\|replace <objective>\|<objective>]` | — | 开始或管理一个自主 goal。该命令仍是实验功能,通过 `KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1` 启用。 | 见下文 |
|
||||
|
||||
::: warning 注意
|
||||
`/yolo` 会跳过普通工具调用的审批确认,使用前请确保了解可能的风险。Plan 模式的退出审批不会被 `/yolo` 跳过;Plan 模式下的 `Bash` 也按 `/yolo` 的普通放行规则处理。
|
||||
:::
|
||||
|
||||
## 自主 goal
|
||||
|
||||
`/goal` 是实验命令,适用于你希望 Kimi Code 通过自动续跑的轮次持续处理的任务。启动 `kimi` 时先启用它:
|
||||
|
||||
```sh
|
||||
KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1 kimi
|
||||
```
|
||||
|
||||
实验功能 flag 目前从环境变量读取。`config.toml` 暂时没有用于启用 `/goal` 的 `experimental` 配置项。
|
||||
|
||||
在命令后写目标即可开始一个 goal:
|
||||
|
||||
```sh
|
||||
/goal 更新 checkout 文档,运行 docs build,如果 20 轮后仍被阻塞就停止
|
||||
```
|
||||
|
||||
Kimi Code 会保存该目标,把它作为下一条 User 消息发送,然后持续运行后续轮次,直到 goal 停止。goal 有三种停止状态:
|
||||
|
||||
- `complete`:目标已完成。Kimi Code 会发送完成消息,并清除该 goal。
|
||||
- `paused`:你暂停了 goal、中断了当前轮次,或恢复了一个原本有 active goal 的会话。之后可以继续恢复。
|
||||
- `blocked`:Kimi Code 因需要输入、无法按当前目标完成、达到已配置的轮次、token 或时间预算,或遇到运行时失败而停止。之后可以继续恢复。
|
||||
|
||||
停止条件需要写在目标本身里。`/goal` 没有单独的停止限制 flag。
|
||||
|
||||
在 TUI 中,如果当前权限模式是 `manual`,开始或替换 goal 前会先出现确认提示。你可以切换到 `auto`、切换到 `yolo`,或继续用 `manual`。你也可以回到输入框,且 `/goal` 命令仍会保留在那里。
|
||||
|
||||
`manual` 模式不适合无人值守的 goal 工作。Kimi Code 可能会停下来等你审批。
|
||||
|
||||
使用下列形式管理当前 goal:
|
||||
|
||||
| 命令 | 作用 | 可用性 |
|
||||
| --- | --- | --- |
|
||||
| `/goal` 或 `/goal status` | 显示当前 goal、状态、已用时间、轮次数、token 数,以及已配置的轮次、token 或时间预算。 | 随时可用 |
|
||||
| `/goal pause` | 暂停 active goal 并保留它。若当前正在流式输出,会中断当前轮次。 | 随时可用 |
|
||||
| `/goal resume` | 恢复 paused 或 blocked goal,并开始新的轮次。 | 仅空闲时 |
|
||||
| `/goal cancel` | 移除当前 goal。若当前正在流式输出,会中断当前轮次。 | 随时可用 |
|
||||
| `/goal replace <objective>` | 用新目标替换已保存的 goal。 | 仅空闲时 |
|
||||
|
||||
一个会话中只能保存一个 goal。如果已有 goal,需要用 `/goal replace <objective>` 开始另一个目标。
|
||||
|
||||
`status`、`pause`、`resume`、`cancel` 和 `replace` 只有作为 `/goal` 后的第一个词时才是子命令。如果你的目标需要以这些词开头,请在目标前加 `--`:
|
||||
|
||||
```sh
|
||||
/goal -- cancel 函数需要在订单失败时返回可重试错误,并补充测试
|
||||
```
|
||||
|
||||
在非交互式 prompt 模式中,只有创建形式会启动 goal 模式:
|
||||
|
||||
```sh
|
||||
KIMI_CODE_EXPERIMENTAL_GOAL_COMMAND=1 kimi -p "/goal 修复 checkout 测试失败"
|
||||
```
|
||||
|
||||
Prompt 模式在 goal 完成时以退出码 `0` 退出,在 blocked 时以 `3` 退出,在 paused 时以 `6` 退出。其它 `/goal` 子命令是 TUI 控制命令,不由 `kimi -p` 处理。
|
||||
|
||||
## 信息与状态
|
||||
|
||||
| 命令 | 别名 | 说明 | 随时可用 |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue