Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(doc): update channel cli

xiaotian077cbea20ca523d
diff --git "a/docs/assets/images/\345\221\275\344\273\244\350\241\214\350\247\243\346\236\220.jpg" "b/docs/assets/images/\345\221\275\344\273\244\350\241\214\350\247\243\346\236\220.jpg"
deleted file mode 100644
index ffa23554d3..0000000000
Binary files "a/docs/assets/images/\345\221\275\344\273\244\350\241\214\350\247\243\346\236\220.jpg" and /dev/null differ
diff --git "a/docs/assets/images/\345\221\275\344\273\244\350\241\214\350\247\243\346\236\220.png" "b/docs/assets/images/\345\221\275\344\273\244\350\241\214\350\247\243\346\236\220.png"
new file mode 100644
index 0000000000..a1c4837798
Binary files /dev/null and "b/docs/assets/images/\345\221\275\344\273\244\350\241\214\350\247\243\346\236\220.png" differ
diff --git a/docs/en/CLI.md b/docs/en/CLI.md
index c2b028ea70..30792891b0 100644
--- a/docs/en/CLI.md
+++ b/docs/en/CLI.md
@@ -1,94 +1,192 @@
-## CLI / channel control commands
+## CLI / Channel Control Commands
-JiuwenSwarm supports **special prefix commands** to control sessions and modes. Common ones:
+JiuwenSwarm supports **special prefix commands** to control sessions and modes. These commands are parsed by the Gateway's `MessageHandler` and **are not sent to the Agent**.
-- `/new_session`: start a new `session_id` for the current channel
-- `/mode plan`, `/mode fast`, `/mode team`, `/mode code`: switch the channel's working mode
+---
+
+### Supported Channels
-These are handled in the Gateway **`MessageHandler`** and **are not** sent to the agent.
+The following IM channels support control commands:
+
+- `feishu`
+- `xiaoyi`
+- `dingtalk`
+- `whatsapp`
+- `wechat`
---
-### 1. `/new_session` — new session id
+### 1. `/new_session` — New Session ID
**Behavior**
-- For supported channels (`feishu` / `xiaoyi` / `dingtalk` / `whatsapp` / `wecom` / `wechat`), generates a new `session_id`, e.g.:
- - `feishu_<ms hex>_<random hex>`
- - `xiaoyi_<ms hex>_<random hex>`
- - `dingtalk_<ms hex>_<random hex>`
- - `whatsapp_<ms hex>_<random hex>`
- - `wecom_<ms hex>_<random hex>`
- - `wechat_<ms hex>_<random hex>`
-- Later messages on that channel use this id, so a new folder appears under `workspace/session/`.
+- Generates a new `session_id` for the current channel, formatted as `{channel_type}_{ms_timestamp_hex}_{random_hex}`
+- All subsequent chat messages from this channel will be forced to use the new `session_id`
**Usage**
Send in a supported channel:
- ```text
- /new_session
- ```
-![](../assets/images/命令行解析.jpg)
+```text
+/new_session
+```
+
+![](../assets/images/命令行解析.png)
The Gateway will:
+1. Intercept this message (not forwarded to the Agent)
+2. Cancel any tasks currently running in the session
+3. Generate a new `session_id` for that `channel_id`
+4. Reply with a system message, e.g.: `[Received CLI command], session_id changed to feishu_17f2b4b32e0_ab12cd`
+
+---
+
+### 2. `/mode` — Switch Channel Mode
+
+**Behavior**
+
+Sets the working mode for the current channel. The Agent uses this when constructing prompts and behavior strategies.
+
+**Primary Modes (mapped to secondary modes):**
+
+| Command | Maps to | Description |
+|---------|---------|-------------|
+| `/mode agent` | `agent.plan` | Agent mode, planning/explanation/decomposition |
+| `/mode code` | `code.normal` | Code mode, Agent interacts via code execution tools |
+| `/mode team` | `team` | Team mode |
+
+**Direct Secondary Modes:**
+
+| Command | Description |
+|---------|-------------|
+| `/mode agent.plan` | Agent mode + planning style (default) |
+| `/mode agent.fast` | Agent mode + auto-execution style |
+| `/mode code.plan` | Code mode + planning style |
+| `/mode code.normal` | Code mode + direct execution style (default) |
+| `/mode code.team` | Code mode + team style |
+
+**Usage**
+
+```text
+/mode agent
+```
+
+or
+
+```text
+/mode code.plan
+```
+
+The Gateway will:
+1. Intercept this message
+2. Cancel tasks in the current session (if mode changes)
+3. Update `ChannelControlState.mode`
+4. Reply with a system message, e.g.: `[Received CLI command], mode changed to code.plan`
+
+---
+
+### 3. `/switch` — Switch Secondary Mode
+
+**Behavior**
+
+Switches secondary style within the current primary mode, more concise than `/mode`.
- 1. Intercept (not forwarded to the agent)
- 2. Generate a new `session_id` for that `channel_id`
- 3. Reply with a system message, e.g.
- `session_id updated to feishu_17f2b4b32e0_ab12cd`
+| Command | When in agent mode | When in code mode |
+|---------|--------------------|--------------------|
+| `/switch plan` | → `agent.plan` | → `code.plan` |
+| `/switch fast` | → `agent.fast` | Not supported |
+| `/switch normal` | Not supported | → `code.normal` |
+| `/switch team` | Not supported | → `code.team` |
-**Notes**
+**Usage**
+
+```text
+/switch plan
+```
+
+---
+
+### 4. `/skills list` — List Available Skills
+
+**Behavior**
-- `/new_session` only changes **future** message binding; the directory is created when the session is actually used (todo, files, etc.).
+Queries the currently available skill list.
+
+**Usage**
+
+```text
+/skills list
+```
+
+The Gateway will call `skills.list` and reply with the skill list as a notification.
---
-### 2. `/mode` — channel mode (`plan` / `fast` / `code` / `team`)
+### 5. `/branch` — Fork Session
**Behavior**
-- Sets a logical **mode** for the channel:
- - `plan`: planning, explanation, decomposition (default)
- - `fast`: more hands-on execution
- - `code`: code generation and execution mode (defaults to `code.normal`; use `/mode code.plan` for code planning)
- - `team`: team mode
-- You can also specify sub-modes directly:
- - `agent.plan` or `plan` → Agent Plan mode
- - `agent.fast` or `fast` → Agent Fast mode
- - `code.plan` → Code Plan mode
- - `code.normal` or `code` → Code Normal mode
- - `team` → Team mode
-- Mode is passed in `params["mode"]` for prompt construction.
+Forks a new session from the current one, preserving the original conversation history. Useful for exploring new directions without affecting the original session.
**Usage**
- ```text
- /mode plan
- ```
+```text
+/branch
+```
- or
+Or with a custom name:
- ```text
- /mode fast
- ```
+```text
+/branch fix login issue
+```
The Gateway will:
+1. Call `session.fork` to create a new session
+2. Switch to the new session
+3. Reply with a message, e.g.: `[Received /branch command] Session "fix login issue" forked, now switched to new session.`
- 1. Treat as control, not forward to the agent
- 2. Update `ChannelControlState.mode`
- 3. Reply e.g. `mode updated to fast`
+---
+
+### 6. `/rewind` — Rewind Conversation
-**Scope**
+**Behavior**
-- Stored **per channel** (`channel_id` → `mode`). All later messages on that channel use the current mode.
-- Initial value can come from `default_mode` in config; `MessageHandler` reads it on startup.
+Rewinds the current session to a specified turn, deleting that turn and all subsequent conversation records.
+
+**Usage**
+
+First send the rewind request:
+
+```text
+/rewind 3
+```
+
+The Gateway will reply with a confirmation prompt:
+
+```
+[Received /rewind 3 command] Confirm rewind to turn 3?
+This operation is irreversible and will delete turn 3 and all subsequent conversations.
+Please reply /rewind confirm 3 to confirm, or /rewind cancel to cancel.
+Note: Rewind does not affect manually edited files or commands executed via bash.
+```
+
+Confirm execution:
+
+```text
+/rewind confirm 3
+```
+
+Cancel operation:
+
+```text
+/rewind cancel
+```
---
-### 3. TUI: `/workspace_dir` — workspace path for outbound requests
+### 7. TUI: `/workspace_dir` — Workspace Path for Outbound Requests
-**Scope:** terminal UI (`jiuwenswarm-tui`) only; parsed locally, not by the Gateway control pipeline.
+**Scope:** Terminal UI (`jiuwenswarm-tui`) only; parsed locally, not by the Gateway control pipeline.
**Behavior**
@@ -107,7 +205,7 @@ The Gateway will:
---
-### 4. `/compact` — context compression
+### 8. `/compact` — Context Compression
**Scope:** TUI only; triggers context compression via AgentServer.
@@ -118,9 +216,9 @@ The Gateway will:
**Usage**
- ```text
- /compact
- ```
+```text
+/compact
+```
**Return Values**
@@ -128,3 +226,10 @@ The Gateway will:
- `compressed`: Compression successful, displays token count before/after compression and savings percentage.
- `noop`: No compression needed, context is already optimized.
+---
+
+### Configuration Notes
+
+- Mode is stored **per channel** (`channel_id` → `mode`). All subsequent messages on that channel will automatically include the current mode.
+- `default_mode` can be set in `config.yaml` as the initial value; `MessageHandler` reads it on startup.
+- `/new_session` and `/mode` changes will automatically cancel tasks currently running in the session.
\ No newline at end of file
diff --git "a/docs/zh/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md" "b/docs/zh/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md"
index 86fe16dd43..ef6b8f8672 100644
--- "a/docs/zh/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md"
+++ "b/docs/zh/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md"
@@ -1,11 +1,18 @@
## 命令行 / 通道控制指令说明
-JiuwenSwarm 支持通过「特殊前缀指令」控制会话和模式,最常用的是:
+JiuwenSwarm 支持通过「特殊前缀指令」控制会话和模式,这些指令由 Gateway 层的 `MessageHandler` 解析,**不会发给 Agent 本身**。
-- `/new_session`:为当前通道切换到一个全新的 `session_id`
-- `/mode`:切换当前通道的工作模式(`plan` / `fast` / `code` / `team`)
+---
+
+### 受控通道
-这些指令由 Gateway 层的 `MessageHandler` 解析,**不会发给 Agent 本身**。
+以下 IM 通道支持控制指令:
+
+- `feishu`(飞书)
+- `xiaoyi`(小艺)
+- `dingtalk`(钉钉)
+- `whatsapp`
+- `wechat`(微信)
---
@@ -13,78 +20,174 @@ JiuwenSwarm 支持通过「特殊前缀指令」控制会话和模式,最常
**作用:**
-- 针对受控通道(当前支持:`feishu` / `xiaoyi` / `dingtalk` / `whatsapp` / `wecom` / `wechat`),为该通道生成一个新的 `session_id`,形如:
- - `feishu_<毫秒时间戳hex>_<随机hex>`
- - `xiaoyi_<毫秒时间戳hex>_<随机hex>`
- - `dingtalk_<毫秒时间戳hex>_<随机hex>`
- - `whatsapp_<毫秒时间戳hex>_<随机hex>`
- - `wecom_<毫秒时间戳hex>_<随机hex>`
- - `wechat_<毫秒时间戳hex>_<随机hex>`
-- 后续从该通道进来的所有普通聊天消息,都会被强制覆盖为这个新的 `session_id`,从而在 `workspace/session/` 下形成一个新的会话目录。
+- 为当前通道生成一个新的 `session_id`,形如 `{通道类型}_{毫秒时间戳hex}_{随机hex}`
+- 后续从该通道进来的所有普通聊天消息,都会被强制覆盖为这个新的 `session_id`
**使用方式:**
-- 在通道(飞书 / 小艺 / 钉钉 / WhatsApp / 企业微信 / 微信)中,直接发送一条消息:
+在受控通道中发送:
+
+```text
+/new_session
+```
+
+![](../assets/images/命令行解析.png)
+
+Gateway 会:
+1. 拦截这条消息(不转发给 Agent)
+2. 取消当前 session 正在执行的任务
+3. 为该 `channel_id` 生成新的 `session_id`
+4. 回复系统提示,例如:`[收到 CLI 指令], session_id 已变更为 feishu_17f2b4b32e0_ab12cd`
+
+---
+
+### 2. `/mode` —— 切换通道模式
+
+**作用:**
- ```text
- /new_session
- ```
-![](../assets/images/命令行解析.jpg)
+为当前通道设置工作模式,Agent 在构造提示词和行为策略时可以使用。
-- Gateway 会:
- 1. 拦截这条消息(不转发给 Agent)
- 2. 为该 `channel_id` 生成新的 `session_id`
- 3. 在当前会话里回复一条系统提示,例如:
- `session_id 已变更为 feishu_17f2b4b32e0_ab12cd`
+**一级模式(默认映射到二级模式):**
-**注意事项:**
+| 命令 | 映射到 | 说明 |
+|------|--------|------|
+| `/mode agent` | `agent.plan` | Agent 模式,偏规划、解释、拆解任务 |
+| `/mode code` | `code.normal` | 代码模式,Agent 通过代码执行工具与环境交互 |
+| `/mode team` | `team` | 组队模式 |
-- `/new_session` 只会修改 **后续消息绑定的 session_id**,不会立刻创建目录;目录在真正用到(如 todo / 文件写入 / 显式创建 session)时按需生成。
+**直达二级模式:**
+
+| 命令 | 说明 |
+|------|------|
+| `/mode agent.plan` | Agent 模式 + 规划风格(默认) |
+| `/mode agent.fast` | Agent 模式 + 自动执行风格 |
+| `/mode code.plan` | 代码模式 + 规划风格 |
+| `/mode code.normal` | 代码模式 + 直接执行风格(默认) |
+| `/mode code.team` | 代码模式 + 组队风格 |
+
+**使用方式:**
+
+```text
+/mode agent
+```
+
+或
+
+```text
+/mode code.plan
+```
+
+Gateway 会:
+1. 拦截这条消息
+2. 取消当前 session 正在执行的任务(如果模式发生变化)
+3. 更新 `ChannelControlState.mode`
+4. 回复系统提示,例如:`[收到 CLI 指令], mode 已变更为 code.plan`
---
-### 2. `/mode` —— 切换通道模式(plan / fast / code / team)
+### 3. `/switch` —— 切换二级模式
**作用:**
-- 为当前通道设置一个逻辑「模式」,用于告诉 Agent 是偏向:
- - `plan`:偏规划、解释、拆解任务(默认,即 `agent.plan`)
- - `fast`:偏自动执行、直接动手(内部与历史 `agent` 模式一致,即 `agent.fast`)
- - `code`:代码模式,Agent 通过代码执行工具与环境交互
- - `code.plan`:代码模式 + 规划风格
- - `code.normal`:代码模式 + 直接执行风格
- - `team`:组队模式
-- 模式信息会写入消息的 `params["mode"]` 中,Agent 在构造提示词和行为策略时可以使用。
+在当前一级模式下切换二级风格,比 `/mode` 更简洁。
+
+| 命令 | 当前 agent 模式时 | 当前 code 模式时 |
+|------|------------------|------------------|
+| `/switch plan` | → `agent.plan` | → `code.plan` |
+| `/switch fast` | → `agent.fast` | 不支持 |
+| `/switch normal` | 不支持 | → `code.normal` |
+| `/switch team` | 不支持 | → `code.team` |
**使用方式:**
-- 在受控通道中发送:
+```text
+/switch plan
+```
- ```text
- /mode plan
- ```
+---
- 或
+### 4. `/skills list` —— 列出可用技能
- ```text
- /mode fast
- ```
+**作用:**
- 或
+查询当前可用的技能列表。
+
+**使用方式:**
+
+```text
+/skills list
+```
+
+Gateway 会调用 `skills.list` 并以通知形式回复技能列表。
+
+---
- ```text
- /mode code
- ```
+### 5. `/branch` —— 分叉会话
-- Gateway 会:
- 1. 识别这条消息为控制指令,不转发给 Agent
- 2. 更新内部 `ChannelControlState.mode`
- 3. 给当前会话回复一条系统提示,例如:
- `mode 已变更为 fast`
+**作用:**
+
+从当前会话分叉出一个新会话,保留原有对话历史,适合在不影响原会话的情况下探索新方向。
+
+**使用方式:**
+
+```text
+/branch
+```
+
+或带自定义名称:
+
+```text
+/branch 修复登录问题
+```
+
+Gateway 会:
+1. 调用 `session.fork` 创建新会话
+2. 切换到新会话
+3. 回复提示,例如:`[收到 /branch 指令] 已分叉会话「修复登录问题」,当前已切换到新会话。`
+
+---
+
+### 6. `/rewind` —— 回退对话
+
+**作用:**
+
+将当前会话回退到指定轮次,删除该轮次及之后的所有对话记录。
+
+**使用方式:**
+
+先发送回退请求:
+
+```text
+/rewind 3
+```
+
+Gateway 会回复确认提示,要求用户确认:
+
+```
+[收到 /rewind 3 指令] 确认要回退到第 3 轮吗?
+此操作不可逆,将删除第 3 轮及之后的所有对话。
+请回复 /rewind confirm 3 确认,或 /rewind cancel 取消。
+注意:回退不影响手动编辑的文件或通过 bash 执行的命令。
+```
+
+确认执行:
+
+```text
+/rewind confirm 3
+```
+
+取消操作:
+
+```text
+/rewind cancel
+```
+
+---
-**生效范围:**
+### 配置说明
-- 模式是 **按通道维度** 存储的(`channel_id` → `mode`),同一通道的所有后续消息,都会自动带上当前模式。
-- 前端 `config.yaml` 中的 `default_mode` 可设初始值,`MessageHandler` 启动时会读取。
+- 模式是 **按通道维度** 存储的(`channel_id` → `mode`),同一通道的所有后续消息都会自动带上当前模式
+- `config.yaml` 中可设置 `default_mode` 作为初始值,`MessageHandler` 启动时会读取
+- `/new_session` 和 `/mode` 变更时会自动取消当前 session 正在执行的任务