@trans-ai/trans-code 0.0.0-stage → 0.1.0
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 +203 -2
- package/bin/transcode.ts +4 -0
- package/docs/ACP.md +231 -0
- package/package.json +42 -4
- package/src/acp/protocol.ts +115 -0
- package/src/acp/server.ts +202 -0
- package/src/acp/session.ts +269 -0
- package/src/acp/transport.ts +216 -0
- package/src/agent/loop.ts +334 -0
- package/src/agent/system-prompt.ts +86 -0
- package/src/agent/tools.ts +483 -0
- package/src/cli.ts +53 -0
- package/src/commands.ts +61 -0
- package/src/main.tsx +62 -0
- package/src/provider/provider.ts +373 -0
- package/src/screens/REPL.tsx +282 -0
- package/src/tui/cli.tsx +2 -0
- package/src/tui/keyed-stdin.ts +83 -0
- package/src/version.ts +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,204 @@
|
|
|
1
|
-
#
|
|
1
|
+
# transcode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
多模型 AI 编码 Agent CLI。当前 MVP 的目标是:**作为本地 Agent 被 multica 通过 ACP 调用**。
|
|
4
|
+
|
|
5
|
+
- 终端侧:Ink REPL(保留原有命令:`help` / `models` / `clear` / `exit`)
|
|
6
|
+
- Agent 侧:`transcode acp` 启动 ACP v1 stdio 服务,供 multica daemon 等客户端调用
|
|
7
|
+
- 模型侧:Anthropic / OpenAI 及任意 OpenAI 兼容网关(DeepSeek、GLM、MiniMax、Kimi、自建网关等)
|
|
8
|
+
- 工具侧:`read_file` / `write_file` / `edit_file` / `glob` / `grep` / `bash`
|
|
9
|
+
|
|
10
|
+
## 环境要求
|
|
11
|
+
|
|
12
|
+
- Bun >= 1.3
|
|
13
|
+
- 至少一个模型提供商的 API Key
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
也可以全局安装(需要本机有 Bun,因为入口是 `#!/usr/bin/env bun`):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i -g @trans-ai/trans-code
|
|
23
|
+
# 或在本仓库内
|
|
24
|
+
bun link
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 配置模型
|
|
28
|
+
|
|
29
|
+
通过环境变量配置,模型可以是注册表 id,也可以是 `provider:model`:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 注册表 id: opus | gpt | deepseek | glm | minimax | kimi
|
|
33
|
+
export ANTHROPIC_API_KEY=...
|
|
34
|
+
export DEEPSEEK_API_KEY=...
|
|
35
|
+
export TRANSCODE_MODEL=deepseek
|
|
36
|
+
|
|
37
|
+
# 或者显式指定 provider:model
|
|
38
|
+
export OPENAI_API_KEY=...
|
|
39
|
+
export TRANSCODE_MODEL=openai:gpt-4o
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 复用 Claude Code 的 Anthropic 兼容配置
|
|
43
|
+
|
|
44
|
+
如果你已经有一个 Anthropic 兼容网关(例如 DeepSeek 的 `/anthropic` 端点),可以直接沿用 Claude Code 的环境变量,不需要改 `TRANSCODE_MODEL`:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
export ANTHROPIC_AUTH_TOKEN=sk-...
|
|
48
|
+
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
|
|
49
|
+
export ANTHROPIC_DEFAULT_FABLE_MODEL='deepseek-v4-pro[1M]'
|
|
50
|
+
export ANTHROPIC_DEFAULT_FABLE_MODEL_NAME=deepseek-v4-pro
|
|
51
|
+
|
|
52
|
+
transcode acp
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
transcode 会:
|
|
56
|
+
|
|
57
|
+
- 优先使用 `ANTHROPIC_DEFAULT_FABLE_MODEL_NAME`(去掉 `[1M]` 这类上下文后缀),其次 `ANTHROPIC_DEFAULT_FABLE_MODEL`,再其次 `ANTHROPIC_MODEL`
|
|
58
|
+
- 用 `ANTHROPIC_BASE_URL` 作为 Anthropic base URL
|
|
59
|
+
- 用 `ANTHROPIC_AUTH_TOKEN` 作为 bearer token(当 `ANTHROPIC_API_KEY` 未设置时)
|
|
60
|
+
- 自动丢弃 `top_k` / `top_p` 默认值,避免严格网关返回 `top_p` 越界错误
|
|
61
|
+
|
|
62
|
+
验证:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
bun run model:check # 直接问模型一句话
|
|
66
|
+
bun run test:acp:real # 完整 ACP + 工具调用(会创建临时 workspace)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
常用变量:
|
|
70
|
+
|
|
71
|
+
| 变量 | 说明 |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `TRANSCODE_MODEL` | 默认模型。注册表 id、`provider:model`,或裸模型名 |
|
|
74
|
+
| `TRANSCODE_DEFAULT_PROVIDER` | 裸模型名走哪个 provider,默认 `openai` |
|
|
75
|
+
| `TRANSCODE_PERMISSION_MODE` | `ask`(默认) / `auto` / `readonly` |
|
|
76
|
+
| `TRANSCODE_ALLOW_OUTSIDE_CWD` | 设为 `1` 才允许读写工作区之外的路径 |
|
|
77
|
+
| `TRANSCODE_BASE_URL` | 覆盖当前模型的 base URL(所有 provider) |
|
|
78
|
+
| `TRANSCODE_MAX_TOKENS` | 单次回复的 `max_tokens`,默认 `8192` |
|
|
79
|
+
| `TRANSCODE_MOCK` | 设为 `1` 使用本地 mock 模型(仅用于协议测试) |
|
|
80
|
+
|
|
81
|
+
`provider:model` 支持的前缀:`openai`、`anthropic`、`deepseek`、`glm`、`minimax`、`kimi`、`moonshot`。
|
|
82
|
+
裸模型名会使用 `TRANSCODE_DEFAULT_PROVIDER`;`openai` 前缀和裸模型名可以用 `OPENAI_BASE_URL` 指向兼容网关,`TRANSCODE_BASE_URL` 则可以覆盖任意 provider。
|
|
83
|
+
|
|
84
|
+
## 本地运行
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# ACP 服务(给 multica 用)
|
|
88
|
+
bun bin/transcode.ts acp
|
|
89
|
+
|
|
90
|
+
# 交互式 REPL
|
|
91
|
+
bun run start
|
|
92
|
+
|
|
93
|
+
# 检查
|
|
94
|
+
bun run typecheck
|
|
95
|
+
bun run test:acp # ACP 协议 + 工具事件(mock 模型)
|
|
96
|
+
bun run test:acp:openai # 真实 LangChain 流式 + 工具循环(本地假 OpenAI 服务)
|
|
97
|
+
bun run test:acp:real # 真实模型 + 真实工具调用(无 key 时自动跳过)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 接入 multica
|
|
101
|
+
|
|
102
|
+
multica daemon 支持“自定义 runtime profile”:选择一个已支持的协议家族,但用你自己的可执行文件启动。transcode 实现的是 **ACP** 协议,因此用 `hermes` 家族接入。multica 会用 `<command> acp` 启动它。
|
|
103
|
+
|
|
104
|
+
### 1. 让 `transcode` 出现在 PATH
|
|
105
|
+
|
|
106
|
+
二选一:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# 方式 A:bun link(会把当前包链接到全局 bin)
|
|
110
|
+
cd /Users/lindaw/Documents/transcode
|
|
111
|
+
bun link
|
|
112
|
+
|
|
113
|
+
# 方式 B:直接使用绝对路径,后面用 runtime profile set-path 指定
|
|
114
|
+
chmod +x bin/transcode.ts
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
确认:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
transcode --version
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 2. 创建 runtime profile
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
multica runtime profile create \
|
|
127
|
+
--runtime-type hermes \
|
|
128
|
+
--command-name transcode \
|
|
129
|
+
--display-name "Transcode"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
如果 `transcode` 不在 daemon 的 PATH 上,给它固定一个绝对路径:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
multica runtime profile list
|
|
136
|
+
multica runtime profile set-path <profile-id> --path /Users/lindaw/Documents/transcode/bin/transcode.ts
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 3. 重启 daemon 并确认注册
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
multica daemon restart
|
|
143
|
+
multica daemon logs -n 200 | grep -i transcode
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
然后在 multica 里为 Agent 选择 `Transcode` runtime,并开始任务。
|
|
147
|
+
|
|
148
|
+
### 4. 模型与权限
|
|
149
|
+
|
|
150
|
+
multica 任务会通过 `session/new` / `session/set_model` 传模型名;环境变量作为默认值:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
export TRANSCODE_MODEL=deepseek
|
|
154
|
+
export DEEPSEEK_API_KEY=...
|
|
155
|
+
multica daemon restart
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
ACP 默认权限模式是 `ask`:写文件、改文件、执行命令前会向客户端发 `session/request_permission`。multica 会自动选择 `allow_once`。如果你在别的 headless 客户端里使用,可以设 `TRANSCODE_PERMISSION_MODE=auto`;设为 `readonly` 则只允许读/搜索。
|
|
159
|
+
|
|
160
|
+
## 工具
|
|
161
|
+
|
|
162
|
+
| 工具 | 说明 | 是否需要授权 |
|
|
163
|
+
| --- | --- | --- |
|
|
164
|
+
| `read_file` | 读取文本文件,带行号,支持 offset/limit | 否 |
|
|
165
|
+
| `glob` | 按 glob 查文件 | 否 |
|
|
166
|
+
| `grep` | 正则搜索文件内容 | 否 |
|
|
167
|
+
| `write_file` | 创建/覆盖文件 | 是 |
|
|
168
|
+
| `edit_file` | 精确字符串替换 | 是 |
|
|
169
|
+
| `bash` | 在 workspace 内执行 bash 命令 | 是 |
|
|
170
|
+
|
|
171
|
+
所有路径默认限制在任务 workspace(`cwd`)内;`..` 越界会被拒绝,除非显式设置 `TRANSCODE_ALLOW_OUTSIDE_CWD=1`。
|
|
172
|
+
|
|
173
|
+
## 上下文
|
|
174
|
+
|
|
175
|
+
每次 turn 会加载 workspace 下的 `AGENTS.md`、`CLAUDE.md`、`TRANSCODE.md`、`.transcode/AGENTS.md`(存在时)并注入系统提示,因此 multica 写入的任务说明、仓库约定都能被 Agent 看到。
|
|
176
|
+
|
|
177
|
+
## ACP 协议
|
|
178
|
+
|
|
179
|
+
支持的方法、事件格式、权限流程和调试方式见 [docs/ACP.md](docs/ACP.md)。
|
|
180
|
+
|
|
181
|
+
## MVP 限制
|
|
182
|
+
|
|
183
|
+
- 不支持 MCP(会忽略 `mcpServers` 并在 stderr 提示)
|
|
184
|
+
- 不支持 ACP session 持久化:`loadSession: false`,进程内 session 在进程退出后丢失
|
|
185
|
+
- 只处理文本 prompt;图片/音频/嵌入式资源暂不支持
|
|
186
|
+
- 没有 Web 搜索、子 Agent、hooks、自动压缩
|
|
187
|
+
- 工具输出有长度上限,避免单次上下文爆炸
|
|
188
|
+
- `TRANSCODE_MOCK=1` 仅用于协议 smoke test,不会调用真实模型
|
|
189
|
+
|
|
190
|
+
## 目录
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
src/
|
|
194
|
+
acp/ ACP JSON-RPC 传输、server、session
|
|
195
|
+
agent/ Agent 循环、工具实现、系统提示
|
|
196
|
+
provider/ 多模型注册与 LangChain 适配
|
|
197
|
+
screens/ Ink REPL
|
|
198
|
+
commands.ts REPL 命令
|
|
199
|
+
cli.ts 命令行入口分发
|
|
200
|
+
main.tsx REPL 入口
|
|
201
|
+
bin/transcode.ts 可执行入口
|
|
202
|
+
scripts/acp-smoke.ts
|
|
203
|
+
docs/ACP.md
|
|
204
|
+
```
|
package/bin/transcode.ts
ADDED
package/docs/ACP.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# transcode ACP 协议说明
|
|
2
|
+
|
|
3
|
+
transcode 实现了 [Agent Client Protocol (ACP) v1](https://agentclientprotocol.com/) 的最小子集,通过 stdin/stdout 上的换行分隔 JSON-RPC 2.0 通信。multica daemon 可以把 transcode 当作一个本地 ACP runtime 启动。
|
|
4
|
+
|
|
5
|
+
## 启动
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
transcode acp
|
|
9
|
+
# 或
|
|
10
|
+
bun bin/transcode.ts acp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
约束:
|
|
14
|
+
|
|
15
|
+
- stdout **只**输出 JSON-RPC 帧,一行一个。
|
|
16
|
+
- 日志、警告、第三方库的 `console.log` 全部重定向到 stderr。
|
|
17
|
+
- 进程在 stdin 关闭或收到 SIGINT/SIGTERM 时退出。
|
|
18
|
+
|
|
19
|
+
## 方法
|
|
20
|
+
|
|
21
|
+
### 客户端 → Agent
|
|
22
|
+
|
|
23
|
+
| 方法 | 说明 |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `initialize` | 握手,返回协议版本和能力 |
|
|
26
|
+
| `authenticate` | MVP 恒返回 `null`(不要求认证) |
|
|
27
|
+
| `session/new` | 创建进程内 session,返回 `sessionId` 和模型列表 |
|
|
28
|
+
| `session/prompt` | 执行一个 turn,流式发送 `session/update`,最后返回 `stopReason` |
|
|
29
|
+
| `session/set_model` | 切换后续 turn 使用的模型 |
|
|
30
|
+
| `session/cancel` | 取消当前 turn(也支持作为 notification) |
|
|
31
|
+
| `session/load` / `session/resume` | 进程内 session 存在时返回同一 session;否则 `-32002` |
|
|
32
|
+
| `session/set_config_option` | MVP 接受但忽略 |
|
|
33
|
+
| `session/request_permission` | **Agent → 客户端** 的请求,见下文 |
|
|
34
|
+
|
|
35
|
+
`initialize` 返回:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"protocolVersion": 1,
|
|
40
|
+
"agentInfo": { "name": "transcode", "version": "0.1.0" },
|
|
41
|
+
"agentCapabilities": {
|
|
42
|
+
"loadSession": false,
|
|
43
|
+
"promptCapabilities": { "image": false, "audio": false, "embeddedContext": false },
|
|
44
|
+
"mcpCapabilities": { "http": false, "sse": false }
|
|
45
|
+
},
|
|
46
|
+
"authMethods": []
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`session/new` 参数:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"cwd": "/absolute/task/workspace",
|
|
55
|
+
"mcpServers": [],
|
|
56
|
+
"model": "deepseek"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`model` 可省略,省略时使用 `TRANSCODE_MODEL` 或默认 `opus`。`mcpServers` 在 MVP 中会被忽略(stderr 提示)。
|
|
61
|
+
|
|
62
|
+
返回:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"sessionId": "ses_...",
|
|
67
|
+
"models": {
|
|
68
|
+
"availableModels": [
|
|
69
|
+
{ "modelId": "opus", "name": "Claude Opus" },
|
|
70
|
+
{ "modelId": "gpt", "name": "GPT-4o" }
|
|
71
|
+
],
|
|
72
|
+
"currentModelId": "deepseek"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `session/prompt`
|
|
78
|
+
|
|
79
|
+
请求:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"sessionId": "ses_...",
|
|
84
|
+
"prompt": [{ "type": "text", "text": "修复这个测试失败" }]
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
响应:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{ "stopReason": "end_turn" }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`stopReason` 取值:`end_turn`、`max_turn_requests`、`refusal`、`cancelled`。
|
|
95
|
+
|
|
96
|
+
同一个 session 同时只处理一个 prompt;并发调用返回 `-32000`。
|
|
97
|
+
|
|
98
|
+
## 流式事件
|
|
99
|
+
|
|
100
|
+
所有事件都是 `session/update` notification:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"jsonrpc": "2.0",
|
|
105
|
+
"method": "session/update",
|
|
106
|
+
"params": {
|
|
107
|
+
"sessionId": "ses_...",
|
|
108
|
+
"update": { "sessionUpdate": "agent_message_chunk", "content": { "type": "text", "text": "..." } }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
支持的事件:
|
|
114
|
+
|
|
115
|
+
| `sessionUpdate` | 说明 |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `agent_message_chunk` | 助手文本增量 |
|
|
118
|
+
| `agent_thought_chunk` | 思考增量(MVP 模型暂不产生) |
|
|
119
|
+
| `tool_call` | 工具开始:`toolCallId`、`name`、`title`、`kind`、`status: "pending"`、`rawInput` |
|
|
120
|
+
| `tool_call_update` | 工具结束:`toolCallId`、`status: "completed" \| "failed"`、`content` |
|
|
121
|
+
|
|
122
|
+
工具标题使用 ACP 常见前缀,便于 multica 映射:
|
|
123
|
+
|
|
124
|
+
- `terminal: <command>`
|
|
125
|
+
- `read: <path>`
|
|
126
|
+
- `write: <path>`
|
|
127
|
+
- `patch: <path>`
|
|
128
|
+
- `search: <pattern>`
|
|
129
|
+
|
|
130
|
+
工具结果示例:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"sessionUpdate": "tool_call_update",
|
|
135
|
+
"toolCallId": "call_1",
|
|
136
|
+
"status": "completed",
|
|
137
|
+
"name": "bash",
|
|
138
|
+
"content": [
|
|
139
|
+
{ "type": "content", "content": { "type": "text", "text": "hello\n\n[exit] code=0" } }
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 权限流程
|
|
145
|
+
|
|
146
|
+
写文件、改文件、执行 bash 在默认 `ask` 模式下会触发:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"jsonrpc": "2.0",
|
|
151
|
+
"id": 7,
|
|
152
|
+
"method": "session/request_permission",
|
|
153
|
+
"params": {
|
|
154
|
+
"sessionId": "ses_...",
|
|
155
|
+
"toolCall": {
|
|
156
|
+
"toolCallId": "call_1",
|
|
157
|
+
"title": "terminal: rm -rf build",
|
|
158
|
+
"kind": "execute",
|
|
159
|
+
"status": "pending",
|
|
160
|
+
"rawInput": { "command": "rm -rf build" }
|
|
161
|
+
},
|
|
162
|
+
"options": [
|
|
163
|
+
{ "optionId": "allow_once", "name": "Allow once", "kind": "allow_once" },
|
|
164
|
+
{ "optionId": "reject_once", "name": "Reject", "kind": "reject_once" }
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
客户端选择允许:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{ "jsonrpc": "2.0", "id": 7, "result": { "outcome": { "outcome": "selected", "optionId": "allow_once" } } }
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
选择拒绝或 `{"outcome":{"outcome":"cancelled"}}` 都会让工具返回失败,但不会中断整个 turn。
|
|
177
|
+
|
|
178
|
+
超时 60 秒或客户端不支持该方法时,按拒绝处理。
|
|
179
|
+
|
|
180
|
+
权限模式:
|
|
181
|
+
|
|
182
|
+
| `TRANSCODE_PERMISSION_MODE` | 行为 |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `ask`(默认) | 变更类工具向客户端请求授权 |
|
|
185
|
+
| `auto` | 全部自动允许 |
|
|
186
|
+
| `readonly` | 只允许读/搜索;写和 bash 直接拒绝 |
|
|
187
|
+
|
|
188
|
+
## 模型解析
|
|
189
|
+
|
|
190
|
+
`session/new` / `session/set_model` / `TRANSCODE_MODEL` 使用同一套解析:
|
|
191
|
+
|
|
192
|
+
1. 注册表 id:`opus`、`gpt`、`deepseek`、`glm`、`minimax`、`kimi`
|
|
193
|
+
2. `provider:model`:`openai:gpt-4o`、`anthropic:claude-sonnet-4-20250514`、`deepseek:deepseek-chat`、`kimi:moonshot-v1-128k` 等
|
|
194
|
+
3. 裸模型名:按名字推断 provider(`claude*` / `deepseek*` / `glm*` / `kimi*` / `minimax*`),否则走 `TRANSCODE_DEFAULT_PROVIDER`(默认 `openai`)
|
|
195
|
+
4. 空值:`TRANSCODE_MODEL` → `ANTHROPIC_DEFAULT_FABLE_MODEL_NAME` / `ANTHROPIC_DEFAULT_FABLE_MODEL` / `ANTHROPIC_MODEL`(当配置了 `ANTHROPIC_AUTH_TOKEN` 或 `ANTHROPIC_BASE_URL`)→ `opus`
|
|
196
|
+
|
|
197
|
+
Anthropic 适配器会:
|
|
198
|
+
|
|
199
|
+
- 用 `ANTHROPIC_BASE_URL` 作为 `anthropicApiUrl`
|
|
200
|
+
- 在 `ANTHROPIC_API_KEY` 缺失时用 `ANTHROPIC_AUTH_TOKEN` 作为 key 和 bearer token
|
|
201
|
+
- 去掉 LangChain 默认的 `top_k = -1` / `top_p = -1`,否则部分兼容网关会直接返回 400
|
|
202
|
+
|
|
203
|
+
OpenAI 兼容网关可以用 `OPENAI_BASE_URL` 覆盖 base URL;`TRANSCODE_BASE_URL` 覆盖所有 provider。API Key 优先取 provider 对应变量,其次 `TRANSCODE_API_KEY`。
|
|
204
|
+
|
|
205
|
+
## 与 multica 的兼容点
|
|
206
|
+
|
|
207
|
+
- multica 的 `hermes` 协议家族会用 `<command> acp` 启动本地 runtime,因此 transcode 提供 `acp` 子命令。
|
|
208
|
+
- multica 通过 `initialize` → `session/new` → `session/prompt` 驱动一个 turn。
|
|
209
|
+
- 任务 brief 通常出现在 prompt 文本和/或 workspace 的 `AGENTS.md` 中;transcode 两者都会读取。
|
|
210
|
+
- multica 对 `session/request_permission` 会自动选择 `allow_once`。
|
|
211
|
+
- transcode 不广告 `loadSession`,因此每个任务默认新 session;如果同一进程内复用 session,会保留内存中的对话历史。
|
|
212
|
+
- 不使用 MCP 时 multica 传来的 `mcpServers` 为空;有值会被忽略。
|
|
213
|
+
|
|
214
|
+
## 调试
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# 协议 smoke test(不需要 API Key)
|
|
218
|
+
bun run test:acp
|
|
219
|
+
|
|
220
|
+
# 手动观察协议帧
|
|
221
|
+
TRANSCODE_MOCK=1 bun bin/transcode.ts acp
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
手工发送一帧:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientInfo":{"name":"manual","version":"0"},"clientCapabilities":{}}}' \
|
|
228
|
+
| TRANSCODE_MOCK=1 bun bin/transcode.ts acp
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
stderr 上会看到 `[transcode] ACP server ready`、session 创建、权限拒绝等诊断信息;stdout 只应出现 JSON。
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trans-ai/trans-code",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI-powered multi-model coding CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/wang20110277/transcode.git"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"src",
|
|
14
|
+
"docs",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"bin": {
|
|
18
|
+
"transcode": "./bin/transcode.ts"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build:repl": "bun build src/main.tsx --target=node --packages=external --outdir=dist",
|
|
22
|
+
"start": "bun run build:repl && node dist/main.js",
|
|
23
|
+
"dev": "bun run build:repl && node dist/main.js",
|
|
24
|
+
"acp": "bun bin/transcode.ts acp",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"test:acp": "bun scripts/acp-smoke.ts",
|
|
27
|
+
"test:acp:openai": "bun scripts/acp-openai-smoke.ts",
|
|
28
|
+
"test:acp:real": "bun scripts/acp-real-smoke.ts",
|
|
29
|
+
"model:check": "bun scripts/model-check.ts"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"ink": "^5.1.0",
|
|
33
|
+
"react": "^18.3.1",
|
|
34
|
+
"@langchain/core": "^0.3.0",
|
|
35
|
+
"@langchain/openai": "^0.4.0",
|
|
36
|
+
"@langchain/anthropic": "^0.3.0",
|
|
37
|
+
"zod": "^3.25.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.0.0",
|
|
41
|
+
"@types/react": "^18.3.0",
|
|
42
|
+
"typescript": "^5.7.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Agent Client Protocol (ACP) v1 types used by transcode.
|
|
3
|
+
* Only the surface needed for a local coding agent is modelled here.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type JsonRpcId = number | string;
|
|
7
|
+
|
|
8
|
+
export interface JsonRpcRequest {
|
|
9
|
+
jsonrpc: '2.0';
|
|
10
|
+
id: JsonRpcId;
|
|
11
|
+
method: string;
|
|
12
|
+
params?: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface JsonRpcNotification {
|
|
16
|
+
jsonrpc: '2.0';
|
|
17
|
+
method: string;
|
|
18
|
+
params?: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface JsonRpcResponse {
|
|
22
|
+
jsonrpc: '2.0';
|
|
23
|
+
id: JsonRpcId;
|
|
24
|
+
result?: unknown;
|
|
25
|
+
error?: { code: number; message: string; data?: unknown };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface AcpContentBlock {
|
|
29
|
+
type: string;
|
|
30
|
+
text?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AcpPromptBlock {
|
|
35
|
+
type: string;
|
|
36
|
+
text?: string;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AcpSessionNewParams {
|
|
41
|
+
cwd?: string;
|
|
42
|
+
mcpServers?: unknown[];
|
|
43
|
+
model?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AcpPromptParams {
|
|
47
|
+
sessionId: string;
|
|
48
|
+
prompt: AcpPromptBlock[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AcpSetModelParams {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
modelId: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface AcpCancelParams {
|
|
57
|
+
sessionId: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type AcpStopReason =
|
|
61
|
+
| 'end_turn'
|
|
62
|
+
| 'max_tokens'
|
|
63
|
+
| 'max_turn_requests'
|
|
64
|
+
| 'refusal'
|
|
65
|
+
| 'cancelled';
|
|
66
|
+
|
|
67
|
+
export interface AcpModelInfo {
|
|
68
|
+
modelId: string;
|
|
69
|
+
name: string;
|
|
70
|
+
description?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface AcpSessionModelState {
|
|
74
|
+
availableModels: AcpModelInfo[];
|
|
75
|
+
currentModelId: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface AcpSessionNewResult {
|
|
79
|
+
sessionId: string;
|
|
80
|
+
models?: AcpSessionModelState;
|
|
81
|
+
configOptions?: unknown[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface AcpPromptResult {
|
|
85
|
+
stopReason: AcpStopReason;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface AcpPermissionOption {
|
|
89
|
+
optionId: string;
|
|
90
|
+
name: string;
|
|
91
|
+
kind: 'allow_once' | 'allow_always' | 'reject_once' | 'reject_always';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface AcpPermissionRequest {
|
|
95
|
+
sessionId: string;
|
|
96
|
+
toolCall: {
|
|
97
|
+
toolCallId: string;
|
|
98
|
+
title: string;
|
|
99
|
+
kind: string;
|
|
100
|
+
status: 'pending';
|
|
101
|
+
rawInput: Record<string, unknown>;
|
|
102
|
+
};
|
|
103
|
+
options: AcpPermissionOption[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface AcpPermissionResponse {
|
|
107
|
+
outcome:
|
|
108
|
+
| { outcome: 'selected'; optionId: string }
|
|
109
|
+
| { outcome: 'cancelled' };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface AcpSessionUpdate {
|
|
113
|
+
sessionUpdate: string;
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}
|