← Back to Plugins
Tools

Acp Code Mode

daheli By daheli 👁 14 views ▲ 0 votes

OpenClaw ACP code mode plugin

GitHub

Configuration Example

{
  "plugins": {
    "allow": [
      "acp-code-mode-plugin"
    ],
    "entries": {
      "acp-code-mode-plugin": {
        "enabled": true,
        "config": {
          "enabled": true,
          "ttlDays": 30,
          "defaultProfile": "default",
          "profiles": {
            "default": {
              "agentId": "opencode",
              "cwd": "/path/to/project-default/Pods"
            },
            "10.90.1": {
              "agentId": "opencode-10-90-1",
              "cwd": "/path/to/project-10.90.1/Pods"
            },
            "android": {
              "agentId": "opencode-android",
              "cwd": "/path/to/project-android/"
            }
          }
        }
      }
    }
  }
}

README

# acp-code-mode-plugin

一个给 OpenClaw 用的独立插件,用来给聊天会话提供全局 `/code` 模式。

当前目标是:

- 在任意支持文本命令的会话里输入 `/code`
- 将当前会话切到预设的 `opencode` ACP session
- 后续普通消息继续在对应工作目录里执行
- 提供 `/code status`、`/code exit`、profile 切换

目前这份实现是在本地 OpenClaw 环境里开发和验证的,重点先打通企业微信链路。

## 目前如何使用

### 1. 安装 / 启用

插件目录:

`~/.openclaw/extensions/acp-code-mode-plugin`

需要在 `~/.openclaw/openclaw.json` 中启用:

```json
{
  "plugins": {
    "allow": [
      "acp-code-mode-plugin"
    ],
    "entries": {
      "acp-code-mode-plugin": {
        "enabled": true,
        "config": {
          "enabled": true,
          "ttlDays": 30,
          "defaultProfile": "default",
          "profiles": {
            "default": {
              "agentId": "opencode",
              "cwd": "/path/to/project-default/Pods"
            },
            "10.90.1": {
              "agentId": "opencode-10-90-1",
              "cwd": "/path/to/project-10.90.1/Pods"
            },
            "android": {
              "agentId": "opencode-android",
              "cwd": "/path/to/project-android/"
            }
          }
        }
      }
    }
  }
}
```

改完配置后重启:

```bash
openclaw gateway restart
```

### 2. 目前支持的命令

- `/code`
  - 切到默认 profile
- `/code android`
  - 切到 `android` profile
- `/code 10.90.1`
  - 切到 `10.90.1` profile
- `/code status`
  - 查看当前 code mode 状态
- `/code exit`
  - 退出当前 code mode

### 3. 当前验证通过的能力

- `default` profile 能切到:
  - `/path/to/project-default/Pods`
- `android` profile 能切到:
  - `/path/to/project-android/`
- 普通消息会继续在当前 code mode profile 下执行
- `/code status` 会显示:
  - 当前 profile
  - 当前 agent
  - 当前 session key
  - 当前 cwd
  - 过期时间

## 目前进展

### 已完成

- 独立插件骨架
- profile 配置解析
- 本地 state 文件存储
- `/code`、`/code status`、`/code exit`
- 会话进入 code mode 时创建/初始化对应 ACP session
- 企业微信普通消息在 `before_agent_reply` 阶段切到 code mode session
- `default` / `android` profile 的实际工作目录验证
- 真实 ACP 事件的基础可见化
  - 当前至少能看到部分 `status` 与部分工具过程事件

### 已知现状

- 插件当前主要在企业微信场景下验证通过
- 普通消息接管点使用的是 `before_agent_reply`
- 中间态展示已经比“完全无反馈”好,但还不稳定:
  - 有些问题能看到真实工具过程
  - 有些问题只会看到 `status`
  - 并不是每轮都会有 `thinking_delta` / `tool_call`

## 继续的 TODO

### 高优先级

- 把真实 ACP 事件映射整理得更稳定
  - 明确哪些 provider / runtime 会产出 `thinking_delta`
  - 明确哪些场景会产出 `tool_call` / `tool_result`
- 优化企业微信里的过程展示
  - 当前已避免把最终正文拆成很多段
  - 还需要进一步调优过程消息的可读性与去重
- 补齐 `10.90.1` profile 的端到端验证

### 中优先级

- 支持更多 channel 的实测验证
- 补更多自动化测试
  - state
  - profile 切换
  - session 初始化
  - 事件到消息展示的映射
- 把调试日志降噪,只保留必要日志

### 低优先级

- 提炼为更通用的 OpenClaw ACP code mode 插件
- 支持更多 profile 管理方式
- 整理安装脚本 / 发布方式

## 目录说明

- `index.js`
  - 插件入口,命令注册、ACP session 初始化、消息接管
- `commands.js`
  - `/code` 命令逻辑
- `config.js`
  - 插件配置解析
- `state.js`
  - 本地状态存储
- `session-key.js`
  - 会话 key / target session key 生成
- `route-hook.js`
  - 会话接管相关辅助逻辑
- `tests/`
  - 当前已有的基础测试

## 当前注意事项

- 这是一个仍在演进中的本地插件实现,不是正式发布版本
- 部分实现明显依赖当前本机 OpenClaw 版本与内部运行时 API
- 升级 OpenClaw 后,内部 import 路径和运行时行为可能需要重新适配
tools

Comments

Sign in to leave a comment

Loading comments...