im-code-agent 0.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -0
- package/config.env.example +11 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +33 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +2 -0
- package/dist/src-CcW-Vja8.mjs +3452 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# IM Code Agent
|
|
2
|
+
|
|
3
|
+
通过飞书机器人控制本地电脑上的 `codex` 执行开发任务。执行链路保持本地化,由本地 Bridge 服务驱动本地 ACP adapter / agent 进程,并将流式输出和审批请求同步到飞书。
|
|
4
|
+
|
|
5
|
+
## 当前状态
|
|
6
|
+
|
|
7
|
+
当前仓库仍处于方案落地阶段,已确定的 MVP 方向包括:
|
|
8
|
+
|
|
9
|
+
- Bridge 主动连出 WebSocket,不暴露生产入站控制面
|
|
10
|
+
- Agent 会话走 ACP,`acpx` 仅作为调试和接入参考,不作为当前架构里的固定运行时组件
|
|
11
|
+
- `codex` 方向优先接入 `@zed-industries/codex-acp`
|
|
12
|
+
- 已确认 `codex-acp` 使用 newline-delimited JSON 消息,不使用 `Content-Length` framing
|
|
13
|
+
- 敏感操作通过审批流控制
|
|
14
|
+
- 每个任务独立执行,任务结束即销毁
|
|
15
|
+
|
|
16
|
+
详细方案见 [docs/architecture.md](./docs/architecture.md)。
|
|
17
|
+
|
|
18
|
+
## 启动路径
|
|
19
|
+
|
|
20
|
+
当前仅保留一条入口路径:
|
|
21
|
+
|
|
22
|
+
- 飞书直连:通过飞书消息事件触发任务。
|
|
23
|
+
|
|
24
|
+
不再提供本地 debug HTTP 入口。
|
|
25
|
+
|
|
26
|
+
## 飞书直连
|
|
27
|
+
|
|
28
|
+
当前已集成飞书官方 Node SDK(`@larksuiteoapi/node-sdk`)的 WebSocket 事件接收。
|
|
29
|
+
|
|
30
|
+
推荐使用运行时配置文件 `~/.im-code-agent/config.env`(`.env` 风格,支持注释):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Bridge 基础配置
|
|
34
|
+
|
|
35
|
+
# 飞书应用凭据
|
|
36
|
+
FEISHU_APP_ID=
|
|
37
|
+
FEISHU_APP_SECRET=
|
|
38
|
+
|
|
39
|
+
# 可选:true 时默认 Full Access
|
|
40
|
+
YOLO_MODE=false
|
|
41
|
+
|
|
42
|
+
# 可选:默认工作目录,不填则使用 bridge 启动目录
|
|
43
|
+
WORKSPACE_DEFAULT_CWD=
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
也支持环境变量覆盖(优先级高于配置文件):
|
|
47
|
+
|
|
48
|
+
默认读取 `~/.im-code-agent/config.env`(首次启动自动创建),也可用 `BRIDGE_ENV_PATH` 指定文件。兼容读取当前目录的 `bridge.env` / `.env`。
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export FEISHU_APP_ID=cli_xxx
|
|
52
|
+
export FEISHU_APP_SECRET=xxx
|
|
53
|
+
export YOLO_MODE=false
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
如果启动时未检测到有效的 `FEISHU_APP_ID` / `FEISHU_APP_SECRET`:
|
|
57
|
+
|
|
58
|
+
- 交互终端下会提示并引导输入,输入后自动写回配置文件
|
|
59
|
+
- 非交互环境下会直接报错退出,避免以不可用状态启动
|
|
60
|
+
|
|
61
|
+
启动:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
vp run dev
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
指定配置文件路径启动:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
vp exec tsx src/cli.ts --config /absolute/path/to/config.env
|
|
71
|
+
# 或
|
|
72
|
+
vp exec tsx src/cli.ts -c /absolute/path/to/config.env
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
运行后,机器人收到文本消息会触发:
|
|
76
|
+
|
|
77
|
+
1. 飞书消息事件 `im.message.receive_v1`
|
|
78
|
+
2. 本地 `taskRunner.startConversationTask(...)`
|
|
79
|
+
3. `codex-acp` 执行
|
|
80
|
+
4. 飞书消息卡片流式更新执行输出
|
|
81
|
+
|
|
82
|
+
会话命令:
|
|
83
|
+
|
|
84
|
+
- `/help`:展示支持指令
|
|
85
|
+
- `/new`:重置当前聊天会话(保留当前工作目录)
|
|
86
|
+
- `/new <path>`:重置会话并切换工作目录(支持绝对路径,或相对当前目录)
|
|
87
|
+
- `/model`:查看当前模型并通过交互卡片切换
|
|
88
|
+
- `/model <name>`:直接切换到指定模型
|
|
89
|
+
- `/status`:查看当前会话状态
|
|
90
|
+
- `/stop` 或 `/interrupt`:立即打断当前执行中的任务
|
|
91
|
+
- `/perm`:查看并通过交互卡片切换权限模式
|
|
92
|
+
|
|
93
|
+
### 权限与配置清单
|
|
94
|
+
|
|
95
|
+
当前代码使用「消息卡片 + `im.v1.message.patch` 增量更新」实现流式体验,先开这批:
|
|
96
|
+
|
|
97
|
+
1. 机器人能力(Bot)
|
|
98
|
+
2. 事件订阅:
|
|
99
|
+
|
|
100
|
+
- `im.message.receive_v1`(接收消息 v2.0)
|
|
101
|
+
|
|
102
|
+
3. 消息接口权限:
|
|
103
|
+
|
|
104
|
+
- 发送消息(`im.v1.message.create`)
|
|
105
|
+
- 更新应用发送的消息(`im.v1.message.patch`)
|
|
106
|
+
|
|
107
|
+
4. 若要在群里收消息,还需要开群消息可见相关权限(例如“获取群组中所有消息”或“获取用户在群组中@机器人的消息”按你的策略选)
|
|
108
|
+
|
|
109
|
+
如果你后续要升级到 CardKit 原生文本流式接口(`cardkit.v1.cardElement.content`),再额外开:
|
|
110
|
+
|
|
111
|
+
1. 创建与更新卡片(`cardkit:card:write`)
|
|
112
|
+
2. 按 CardKit 实体流程创建卡片实体并维护 `card_id / element_id / sequence`
|
|
113
|
+
|
|
114
|
+
## 开发
|
|
115
|
+
|
|
116
|
+
安装依赖:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
vp install
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
校验代码:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
vp check
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
运行测试:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
vp test
|
|
132
|
+
```
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as startBridge } from "./src-CcW-Vja8.mjs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
//#region src/config/cli-args.ts
|
|
5
|
+
function parseCliArgs(argv) {
|
|
6
|
+
let configPath;
|
|
7
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
8
|
+
const arg = argv[index];
|
|
9
|
+
if (arg === "--config" || arg === "-c") {
|
|
10
|
+
const value = argv[index + 1];
|
|
11
|
+
if (!value || value.startsWith("-")) throw new Error(`${arg} 需要一个配置文件路径参数`);
|
|
12
|
+
configPath = resolve(value);
|
|
13
|
+
index += 1;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (arg.startsWith("-")) throw new Error(`未知参数: ${arg}`);
|
|
17
|
+
}
|
|
18
|
+
return { configPath };
|
|
19
|
+
}
|
|
20
|
+
function applyCliArgs(argv, env = process.env) {
|
|
21
|
+
const { configPath } = parseCliArgs(argv);
|
|
22
|
+
if (configPath) env.BRIDGE_ENV_PATH = configPath;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/cli.ts
|
|
26
|
+
applyCliArgs(process.argv.slice(2));
|
|
27
|
+
startBridge().catch((error) => {
|
|
28
|
+
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
29
|
+
console.error(message);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
33
|
+
export {};
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED