介绍
---
**重要:** 你需要安装并配置好 Kilo CLI,以便 OpenClaw 可以顺利使用它。
```sh npm install -g @kilocode/cli ```
如果你想自动向 Github 提交 Pull Request,则还需要在你的项目中认证 Github CLI:https://github.com/cli/cli#installation
# Coding Agent (background-first)
对于非交互式编码工作,请使用 **bash 后台模式**。对于交互式编码会话,请使用 **tmux** 技能(除非是非常简单的单次提示,否则请始终使用)。
## 模式:工作目录 + 后台
```bash # Create temp space for chats/scratch work SCRATCH=$(mktemp -d)
# Start agent in target directory ("little box" - only sees relevant files) bash workdir:$SCRATCH background:true command:"<agent command>" # Or for project work: bash workdir:~/project/folder background:true command:"<agent command>" # Returns sessionId for tracking
# Monitor progress process action:log sessionId:XXX
# Check if done process action:poll sessionId:XXX
# Send input (if agent asks a question) process action:write sessionId:XXX data:"y"
# Kill if needed process action:kill sessionId:XXX ```
**为什么工作目录很重要:** 代理在一个专注的目录中启动,不会四处游荡去读取不相关的文件(比如你的 soul.md 😅)。
---
## Kilo CLI
### 构建/创建(使用自动模式)
```bash bash workdir:~/project background:true command:"kilo run --auto \"Build a snake game with dark theme\"" ```
### 审查 PR(原生命令,无参数)
**⚠️ 关键:切勿在 OpenClaw 自身的项目文件夹中审查 PR!** - 要么使用提交 PR 的项目(如果它不是 ~/Projects/openclaw) - 要么先克隆到一个临时文件夹
```bash # Option 1: Review in the actual project (if NOT OpenClaw) bash workdir:~/Projects/some-other-repo background:true command:"kilo run \"Review current branch against main branch\""
# Option 2: Clone to temp folder for safe review (REQUIRED for OpenClaw PRs!) REVIEW_DIR=$(mktemp -d) git clone https://github.com/openclaw/openclaw.git $REVIEW_DIR cd $REVIEW_DIR && gh pr checkout 130 bash workdir:$REVIEW_DIR background:true command:"kilo run \"Review current branch against main branch\"" # Clean up after: rm -rf $REVIEW_DIR
# Option 3: Use git worktree (keeps main intact) git worktree add /tmp/pr-130-review pr-130-branch bash workdir:/tmp/pr-130-review background:true command:"kilo run \"Review current branch against main branch\"" ```
**为什么?** 在正在运行的 OpenClaw 仓库中检出分支可能会破坏正在运行的实例!
### 批量 PR 审查(并行军团!) ```bash # Fetch all PR refs first git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'
# Deploy the army - one Kilo CLI per PR! bash workdir:~/project background:true command:"kilo run \"Review PR #86. git diff origin/main...origin/pr/86\"" bash workdir:~/project background:true command:"kilo run \"Review PR #87. git diff origin/main...origin/pr/87\"" bash workdir:~/project background:true command:"kilo run \"Review PR #95. git diff origin/main...origin/pr/95\"" # ... repeat for all PRs
# Monitor all process action:list
# Get results and post to GitHub process action:log sessionId:XXX gh pr comment <PR#> --body "<review content>" ```
### PR 审查提示 - **先获取引用:** `git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'` - **使用 git diff:** 告诉 Kilo CLI 使用 `git diff origin/main...origin/pr/XX` - **不要检出:** 多个并行审查 = 不要让它们切换分支 - **发布结果:** 使用 `gh pr comment` 将审查结果发布到 GitHub
---
## tmux(交互式会话)
对于交互式编码会话,请使用 tmux 技能(除非是非常简单的单次提示,否则请始终使用)。对于非交互式运行,请优先使用 bash 后台模式。
---
## 使用 git worktrees + tmux 并行修复问题
若要并行修复多个问题,请使用 git worktrees(隔离分支)+ tmux 会话:
```bash # 1. Clone repo to temp location cd /tmp && git clone [email protected]:user/repo.git repo-worktrees cd repo-worktrees
# 2. Create worktrees for each issue (isolated branches!) git worktree add -b fix/issue-78 /tmp/issue-78 main git worktree add -b fix/issue-99 /tmp/issue-99 main
# 3. Set up tmux sessions SOCKET="${TMPDIR:-/tmp}/kilo-fixes.sock" tmux -S "$SOCKET" new-session -d -s fix-78 tmux -S "$SOCKET" new-session -d -s fix-99
# 4. Launch Kilo CLI in each (after npm install!) tmux -S "$SOCKET" send-keys -t fix-78 "cd /tmp/issue-78 && npm install && kilo run 'Fix issue #78: <description>. Commit and push.'" Enter tmux -S "$SOCKET" send-keys -t fix-99 "cd /tmp/issue-99 && npm install && kilo run 'Fix issue #99: <description>. Commit and push.'" Enter
# 5. Monitor progress tmux -S "$SOCKET" capture-pane -p -t fix-78 -S -30 tmux -S "$SOCKET" capture-pane -p -t fix-99 -S -30
# 6. Check if done (prompt returned) tmux -S "$SOCKET" capture-pane -p -t fix-78 -S -3 | grep -q "❯" && echo "Done!"
# 7. Create PRs after fixes cd /tmp/issue-78 && git push -u origin fix/issue-78 gh pr create --repo user/repo --head fix/issue-78 --title "fix: ..." --body "..."
# 8. Cleanup tmux -S "$SOCKET" kill-server git worktree remove /tmp/issue-78 git worktree remove /tmp/issue-99 ```
**为什么用 worktrees?** 每个 Kilo CLI 在隔离的分支中工作,不会产生冲突。可以运行 5+ 个并行修复!
**为什么用 tmux 而不是 bash 后台?** Kilo CLI 是交互式的 —— 需要正确的 TTY 输出。tmux 提供持久会话并捕获完整的历史记录。
---
## ⚠️ 规则
1. **尊重工具选择** —— 如果用户要求使用 Kilo CLI,就使用 Kilo CLI。绝不要主动提出自己去构建! 2. **保持耐心** —— 不要因为会话“慢”就终止它们 3. **使用 process:log 进行监控** —— 检查进度但不进行干扰 4. **构建时使用 --full-auto** —— 自动批准更改 5. **审查时使用 vanilla** —— 不需要特殊参数 6. **并行是可以的** —— 批量处理时可以同时运行许多 Kilo CLI 进程 7. **切勿在 ~/openclaw/ 中启动 Kilo CLI/** —— 它会读取你的灵魂文档并对组织结构图产生奇怪的想法!请使用目标项目目录或 /tmp 进行空白板式的对话 8. **切勿在 ~/Projects/openclaw/ 中检出分支/** —— 那是正在运行的 OpenClaw 实例!请克隆到 /tmp 或使用 git worktree 进行 PR 审查
---
## PR 模板(The Razor 标准)
向外部仓库提交 PR 时,请使用此格式以确保质量并方便维护者:
````markdown ## Original Prompt [Exact request/problem statement]
## What this does [High-level description]
**Features:** - [Key feature 1] - [Key feature 2]
**Example usage:** ```bash # 示例 command example ```
## Feature intent (maintainer-friendly) [Why useful, how it fits, workflows it enables]
## Prompt history (timestamped) - YYYY-MM-DD HH:MM UTC: [Step 1] - YYYY-MM-DD HH:MM UTC: [Step 2]
## How I tested **Manual verification:** 1. [Test step] - Output: `[result]` 2. [Test step] - Result: [result]
**Files tested:** - [Detail] - [Edge cases]
## Session logs (implementation) - [What was researched] - [What was discovered] - [Time spent]
## Implementation details **New files:** - `path/file.ts` - [description]
**Modified files:** - `path/file.ts` - [change]
**Technical notes:** - [Detail 1] - [Detail 2]
--- ````
**关键原则:** 1. 人工编写的描述(不要 AI 灌水) 2. 给维护者的功能意图说明 3. 带时间戳的提示历史记录 4. 如果使用 Kilo CLI 代理,需包含会话日志