Phase 3 / Ep 14: Coding 权限实战 —— 让 Agent 成为你的编程助手

⏱ 预计阅读 3 分钟 更新于 2026/4/13

🎯 学习目标:配置 coding 权限并让 Agent 完成真实编程任务。

1. 启用 Coding Profile

openclaw config set tools.profile coding
openclaw gateway restart

2. Coding 权限解锁的能力

启用后,Agent 可以:

  • 🔧 执行任意 Shell 命令(npm install, python script.py
  • 📁 创建、编辑、删除文件
  • 🔀 Git 操作(clone, branch, commit, push)
  • 🧪 运行测试套件
  • 📦 安装依赖包

3. 实战:Agent 的一次完整编程任务

通过 Telegram 或 CLI 发送:

"请帮我在 ~/projects/ 下 clone openclaw/example-skill 仓库,创建一个 feat/weather 分支,在 SKILL.md 中添加天气查询的描述,然后跑一下 npm test。"

Agent 的执行流程:

sequenceDiagram
    participant User as 🧑 你
    participant Agent as 🤖 Code Agent
    participant Shell as 💻 Shell
    participant Git as 🔀 Git

    User->>Agent: "clone 仓库 + 创建分支 + 修改文件 + 测试"
    Agent->>Shell: git clone openclaw/example-skill
    Shell->>Agent: ✅ 克隆完成
    Agent->>Git: git checkout -b feat/weather
    Git->>Agent: ✅ 分支已创建
    Agent->>Shell: 编辑 SKILL.md(添加天气描述)
    Shell->>Agent: ✅ 文件已保存
    Agent->>Shell: npm test
    Shell->>Agent: ✅ 3 tests passed
    Agent->>User: "✅ 全部完成!仓库已 clone,分支 feat/weather 已创建,SKILL.md 已更新,测试全部通过。"

4. 安全边界

即使是 coding 权限,以下命令仍会被拒绝:

  • rm -rf /(危险的递归删除)
  • sudo 命令(不允许提权)
  • 修改系统配置文件
  • 访问 ~/.openclaw/ 目录本身

5. 审计日志

每一个 Shell 命令都会被记录在 session 日志中:

# 查看 Agent 执行了哪些命令
openclaw sessions show <id> --filter tools

下节预告: Ep 15,full 权限——最强也最危险。什么时候用?怎么安全地用?