agent-supervisor-mcp 2.0.1 → 2.0.3
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 +122 -120
- package/README.ru.md +209 -0
- package/README.zh-CN.md +208 -0
- package/package.json +1 -1
- package/src/app/acceptance.js +2 -2
- package/src/app/start-run.js +89 -2
- package/src/domain/worker-preflight.js +11 -0
- package/src/infra/bin-resolver.js +5 -0
- package/src/infra/process.js +7 -2
- package/src/interface/bin/setup.js +4 -1
- package/src/run-host/entry.js +35 -3
- package/src/run-host/track.js +4 -4
- package/src/runners/codex/adapter.js +16 -2
- package/README.en.md +0 -208
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# agent-supervisor-mcp
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [Русский](README.ru.md) | 中文
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/agent-supervisor-mcp)
|
|
6
|
+
[](https://www.npmjs.com/package/agent-supervisor-mcp)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://github.com/zriyox/agent-supervisor-mcp/actions/workflows/ci.yml)
|
|
9
|
+
[](package.json)
|
|
10
|
+
[](https://glama.ai/mcp/servers/zriyox/agent-supervisor-mcp)
|
|
11
|
+
|
|
12
|
+
官网 [agent-supervisor.zriyo.com](https://agent-supervisor.zriyo.com) · 给模型读的 [llms.txt](https://agent-supervisor.zriyo.com/llms.txt) · [参考手册](docs/reference.md)
|
|
13
|
+
|
|
14
|
+
让几个 agent 同时改一个仓库,结果是互相覆盖,没人说得清谁改了什么,主线程的上下文还被 worker 的输出塞满。
|
|
15
|
+
|
|
16
|
+
agent-supervisor-mcp 是一个 MCP server。主线程(Claude Code、Codex 或任何 MCP 客户端)用它同时指挥多个 Codex CLI worker:一个 worker 一个 Git worktree,状态写进 SQLite,另有一个网页看板。派单和记账都在磁盘上,不占模型上下文。
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
*30 秒真跑:派 3 个 worker,各自 worktree 并行,主线程收 3 份 diff 合成一次 commit。*
|
|
21
|
+
|
|
22
|
+
> **这个包以前叫 codex-supervisor-mcp**。改名是因为 worker 不再只是 Codex。装着旧包的机器会被它的最后一版自动带过来:装上本包、把 MCP 注册和 skill 换成 `agent-supervisor`,状态目录原地不动。命令行工具的前缀从 `codex-supervisor-` 变成 `agent-supervisor-`。
|
|
23
|
+
>
|
|
24
|
+
> **从 0.x 升级到 1.x**:工具从 39 个收成 14 个,名字和参数都换了,旧名不留别名。升级前先把在跑的 worker 收完,升级后重开会话让新 skill 生效。对照表在[参考手册](docs/reference.md),变更说明在 [1.0.0 release](https://github.com/zriyox/agent-supervisor-mcp/releases/tag/v1.0.0)。
|
|
25
|
+
|
|
26
|
+
## 解决什么
|
|
27
|
+
|
|
28
|
+
| 问题 | 做法 |
|
|
29
|
+
|---|---|
|
|
30
|
+
| 几个 worker 互相踩文件 | 一个 worker 一个 worktree,`owned_paths` 在派单前查冲突 |
|
|
31
|
+
| worker 的输出塞爆主线程 | 事件写 JSONL,主线程只读压缩过的概览(全部 worker 不超过 7000 字节) |
|
|
32
|
+
| 重启或换会话后接不上 | 每个 work 一行 SQLite,带 `thread_id`;`resume_worker` 接回同一个 Codex 会话 |
|
|
33
|
+
| 分不清跑失败还是进程没了 | 状态机把 `failed` 和 `lost` 分开,失败带来源和错误码 |
|
|
34
|
+
| worker 说做完了其实没有 | 派单带 `acceptance` 验收命令,supervisor 在 worker 退出后自己跑,不过就拒绝合入 |
|
|
35
|
+
| 改动留在本地没上线 | `land_worker` 合回主分支,`verify_push` 核对远端真有这笔提交 |
|
|
36
|
+
| worktree 越堆越多 | 已合入或没有改动的在轮询时自动清;没合入的留 7 天,删之前先把未提交的改动存进它的分支。分支和证据不删 |
|
|
37
|
+
|
|
38
|
+
worker 默认跑 `codex exec`,`model` 透传。主线程留在 Claude,worker 挂 DeepSeek 或别的 provider,账单分开算。
|
|
39
|
+
|
|
40
|
+
worker 也可以是 Claude Code:`create_worker` 带 `runner: "claude"`。它没有系统级沙箱,所以只能在 git worktree 或只读模式下跑,也不支持旁问(`ask_worker`);其余派单、验收、续跑、合入、清理都一样。想接别的 CLI,看 [docs/runner.md](docs/runner.md)。
|
|
41
|
+
|
|
42
|
+
## 五分钟跑起来
|
|
43
|
+
|
|
44
|
+
要 Node.js 22.13.0 以上,`codex` CLI 在 `PATH` 里。macOS、Linux、Windows 都行。
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install -g agent-supervisor-mcp
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
安装脚本会给检测到的 Claude Code 和 Codex 装 skill、注册 MCP,装完重启它们。没注册上(比如用了 `--ignore-scripts`)就跑一次 `agent-supervisor-setup`,或者手动加:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
claude mcp add -s user agent-supervisor -- npx -y agent-supervisor-mcp
|
|
54
|
+
codex mcp add agent-supervisor -- npx -y agent-supervisor-mcp
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Claude Desktop、Cursor、Windsurf 这类 GUI 客户端要自己改 MCP 配置,写法在[参考手册](docs/reference.md#环境变量)。只要 skill 不要 MCP:`npx skills add zriyox/agent-supervisor-mcp`。
|
|
58
|
+
|
|
59
|
+
然后在 Claude Code 里说人话:
|
|
60
|
+
|
|
61
|
+
> 把这三个模块的单测补齐,用 agent-supervisor 分三路并行跑,session 叫「补单测」。
|
|
62
|
+
|
|
63
|
+
skill 会带着主线程走完这几步:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
preflight_worker 先在同样的环境里跑一遍 probe
|
|
67
|
+
create_worker ×3 每路带 session、owned_paths、goal
|
|
68
|
+
wait_workers 一次最多等 60 秒,没完接着等
|
|
69
|
+
get_worker ×3 每路的汇报,带它真跑过的命令和退出码
|
|
70
|
+
get_worker_diff ×3 它实际改了什么
|
|
71
|
+
land_worker ×3 核过了,代它提交并合入
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
worker 自己不提交。它的改动留在 `worker/<taskId>` 分支,等主线程看过 diff 再合。
|
|
75
|
+
|
|
76
|
+
想看着它们跑,开看板:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
agent-supervisor-web # 或 npx -p agent-supervisor-mcp agent-supervisor-web
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
打开 `http://127.0.0.1:7877`。按 session 看每路 worker 的状态、正在跑的命令、改动和事件,还能旁问:从 worker 的线程 fork 一个只读会话来答,不打断它手上的活。看板只看,不派单也不取消。
|
|
83
|
+
|
|
84
|
+
## 我自己怎么用
|
|
85
|
+
|
|
86
|
+
能连 MCP 的都能当主线程,下面只是我的用法。我开两个 Claude Code 会话,一个只管文档,一个只管派活。合成一个的话,又写详设又盯 worker,上下文两小时就满。
|
|
87
|
+
|
|
88
|
+
| 谁 | 开在哪 | 管什么 |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| 我 | | 定需求,拍板,看汇报 |
|
|
91
|
+
| 规划会话 | 需求和文档仓 | 聊需求,写详设,每块活写一份任务书 |
|
|
92
|
+
| 主脑会话 | 代码仓的一个 worktree | 读任务书,派 worker,核 diff,向我汇报。不写业务代码 |
|
|
93
|
+
| Codex worker | 各自的 worktree | 一个 worker 做一个能独立验收的功能包。不 commit、不 push |
|
|
94
|
+
|
|
95
|
+
两个会话之间只传一段文字,粘进主脑会话用 `/goal` 接上:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
【角色】 你是主脑:派 worker,核结果,更新文档,向我汇报。不写业务代码。先加载 agent-supervisor skill。
|
|
99
|
+
【背景】 这一块为什么做,上一块留下了什么
|
|
100
|
+
【先读】 哪几份文档的哪几节,说法冲突时以哪份为准
|
|
101
|
+
【做什么】照任务书第几节那张表做,表里没有的不做
|
|
102
|
+
【派活】 先 find_works 查重;整批同一个 session.id;
|
|
103
|
+
写入范围不重叠才并行;验证命令同时填 acceptance;
|
|
104
|
+
worker 说过了不算,你看到 diff 才算
|
|
105
|
+
【红线】 不改什么,不推什么,不读什么
|
|
106
|
+
【汇报】 中文,表格优先,报完停下来等我
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 工具
|
|
110
|
+
|
|
111
|
+
默认 14 个。入参和边界见[参考手册](docs/reference.md#工具)。
|
|
112
|
+
|
|
113
|
+
| 阶段 | 工具 | 干什么 |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| 派单前 | `preflight_worker` | 用和目标 worker 相同的环境起一个短 probe,或者先把验收命令真跑一遍 |
|
|
116
|
+
| 派单 | `create_worker` | 派一路。带 `followup_of` 就是接着另一路的成果干 |
|
|
117
|
+
| | `resume_worker` | 同一个会话继续跑,可先 rebase 到主线新头 |
|
|
118
|
+
| | `cancel_worker` | 终止一路 |
|
|
119
|
+
| 盯进度 | `poll_workers` | 不带 cursor 给全表;带 cursor 只给上次之后的变化,顺带恢复死掉的第一轮、清掉可清的 worktree |
|
|
120
|
+
| | `wait_workers` | 等到有结果,单次最多 60 秒 |
|
|
121
|
+
| 收活 | `get_worker` | 读一路:摘要、汇报、状态、事件、goal,要哪块取哪块 |
|
|
122
|
+
| | `get_worker_diff` | 实际改动,按文件和 hunk 分页 |
|
|
123
|
+
| | `ask_worker` | 旁路问它一句,只读,不动它的线程 |
|
|
124
|
+
| 交付 | `land_worker` | 代提交并 cherry-pick 到集成分支,验收没过就拒 |
|
|
125
|
+
| | `verify_push` | 证明合入的提交已经在远端。只验证,不替你 push |
|
|
126
|
+
| | `cleanup` | 看某个 worktree 为什么还在,或立刻清掉。平时是自动清的 |
|
|
127
|
+
| 批次 | `find_works` | 找回一批活,或按关键字搜历史 |
|
|
128
|
+
| | `describe_session` | 给一批活记标题、目标、默认验收和审批状态 |
|
|
129
|
+
|
|
130
|
+
另有 3 个默认不注册,设 `AGENT_SUPERVISOR_TOOLS=all` 才出现:`facts`(已验证事实的台账)、`review`(起一个只读 verifier 独立复核)、`get_artifact`(读留存的证据)。日常派活用不到,不注册能省下每个会话的上下文。
|
|
131
|
+
|
|
132
|
+
## 和 Claude Code 的 subagent 有什么区别
|
|
133
|
+
|
|
134
|
+
subagent 自己也能开 worktree,所以文件隔离不算差别。差别在模型和进程。
|
|
135
|
+
|
|
136
|
+
| | Claude Code subagent | agent-supervisor worker |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| 能跑什么模型 | 只能选 Claude | Codex CLI 配了 provider 的都行 |
|
|
139
|
+
| 干活的是谁 | Claude Code 自己 | 独立的 `codex exec` 进程 |
|
|
140
|
+
| 两路写同一个文件 | 没有路径声明 | 派单前查 `owned_paths` 交集,重叠直接拒 |
|
|
141
|
+
| 主线程挂了 | 收不回来 | worker 和验收照常跑完,新窗口用 `find_works` 找回 |
|
|
142
|
+
| 谁能驱动 | 只有 Claude Code | 任何 MCP 客户端 |
|
|
143
|
+
| 看过程 | 只有它返回的结论 | 原始 JSONL 和网页看板 |
|
|
144
|
+
|
|
145
|
+
## 配置和状态
|
|
146
|
+
|
|
147
|
+
状态都在 `~/.agent-supervisor`(从 codex-supervisor-mcp 升上来、已有 `~/.codex-supervisor` 的机器继续用旧目录):`data/supervisor.sqlite` 是台账,`data/runs/<taskId>.jsonl` 是 Codex 的原始输出,`worktrees/<taskId>/` 是各路的工作区。
|
|
148
|
+
|
|
149
|
+
| 变量 | 默认 | 作用 |
|
|
150
|
+
|---|---|---|
|
|
151
|
+
| `SUPERVISOR_HOME` | `~/.agent-supervisor` | 状态根目录。MCP 和看板要指同一个 |
|
|
152
|
+
| `CODEX_BIN` | `codex` | Codex CLI 路径。GUI 客户端的 `PATH` 里常常没有它 |
|
|
153
|
+
| `SUPERVISOR_WEB_PORT` | `7877` | 看板端口 |
|
|
154
|
+
| `AGENT_SUPERVISOR_NO_AUTO_UPDATE` | 未设 | `1` 关掉后台自动更新,只提醒 |
|
|
155
|
+
|
|
156
|
+
其余变量、worker 的七种状态、沙箱默认放开哪些缓存目录,都在[参考手册](docs/reference.md)。
|
|
157
|
+
|
|
158
|
+
更新不用管。server 启动时后台查一次 registry,有新版就另起进程 `npm i -g`,正在跑的会话不受影响,下一个新会话就是新版。只对全局安装的那份生效。
|
|
159
|
+
|
|
160
|
+
卸载:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm uninstall -g agent-supervisor-mcp
|
|
164
|
+
claude mcp remove -s user agent-supervisor
|
|
165
|
+
codex mcp remove agent-supervisor
|
|
166
|
+
rm -rf ~/.claude/skills/agent-supervisor ~/.agents/skills/agent-supervisor ~/.codex/skills/agent-supervisor ~/.agent-supervisor
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 排查
|
|
170
|
+
|
|
171
|
+
| 症状 | 原因 | 处理 |
|
|
172
|
+
|---|---|---|
|
|
173
|
+
| `claude mcp list` 里没有 | 安装时没跑 `postinstall` | `agent-supervisor-setup` |
|
|
174
|
+
| worker 一起来就 `failed`,`spawn codex ENOENT` | 进程 `PATH` 里没有 codex | 设 `CODEX_BIN` |
|
|
175
|
+
| `codex only resolved to a shell shim` | Windows 只找到 `.cmd`,包入口没了 | 重装 `@openai/codex`,或 `CODEX_BIN` 指到 `codex.js` |
|
|
176
|
+
| `Cannot find module 'node:sqlite'` | Node 低于 22.13.0 | 升 Node |
|
|
177
|
+
| worker `lost` | worker 或它的运行进程被杀了 | 查事件,`resume_worker` 接回 |
|
|
178
|
+
| worker `timed_out` | 时间预算用完被停掉 | 看已有改动;单轮超时 `resume_worker`,总预算用完用 `followup_of` 带新 `limits` 接续 |
|
|
179
|
+
| `git add` 报 `index.lock: Operation not permitted` | 沙箱把 `.git` 设成只读,这是正常边界 | 让 `land_worker` 带 `commit_message` 代提交 |
|
|
180
|
+
| `owned_paths overlap with active worker(s)` | 两路认领了同一片路径 | 改拆法,或取消占着的那路 |
|
|
181
|
+
| 看板是空的 | 看板和 MCP 的 `SUPERVISOR_HOME` 不一样 | 两边指同一个目录 |
|
|
182
|
+
| `port 7877 ... is already in use` | 已经有一个看板在跑 | 直接开它,或换 `SUPERVISOR_WEB_PORT` |
|
|
183
|
+
|
|
184
|
+
## 已知限制
|
|
185
|
+
|
|
186
|
+
- worktree 从一个提交切出来,你工作区里没 commit 的东西不在里面。
|
|
187
|
+
- 只隔离工作目录。临时目录、数据库、端口是共用的。
|
|
188
|
+
- 守卫拦直接写文件,但它不是文件沙箱。你声明放行的脚本可以有清单外的副作用,要靠 land 前的 diff 检查兜住。
|
|
189
|
+
- `acceptance` 里写了什么就查什么,没写的不会替你查。剩下的靠主线程看 diff。
|
|
190
|
+
- 客户端的 MCP 超时是硬墙,一次 `wait_workers` 等不到底,只能反复调。
|
|
191
|
+
- `find_works` 是子串匹配,几百条够用。向量检索不打算做。
|
|
192
|
+
|
|
193
|
+
## 开发
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npm install
|
|
197
|
+
npm test # fake-codex 回放,不到一分钟
|
|
198
|
+
npm run test:real # 真 codex CLI 端到端,要先登录
|
|
199
|
+
npm run web:dev # 看板开发,/api 代理到 7877
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
CI 跑 Ubuntu、macOS、Windows,外加一个 Node 22.13.0 的 job 卡住 `engines` 下界。
|
|
203
|
+
|
|
204
|
+
贡献看 [CONTRIBUTING.md](CONTRIBUTING.md)。安全问题走[私密通道](https://github.com/zriyox/agent-supervisor-mcp/security/advisories/new),见 [SECURITY.md](SECURITY.md)。
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-supervisor-mcp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"mcpName": "io.github.zriyox/agent-supervisor-mcp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "MCP server that runs parallel Codex CLI or Claude Code workers from any MCP client: one Git worktree each, 14 tools to dispatch, track, check, land and clean up, state on disk.",
|
package/src/app/acceptance.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// The commands are shell lines written by the main thread, so they run with
|
|
12
12
|
// the supervisor's own privileges, exactly as if the main thread had run
|
|
13
13
|
// them itself. That is the trust model and it is stated in the tool text.
|
|
14
|
-
import { runSync, spawnProcess } from "../infra/process.js";
|
|
14
|
+
import { hideChildConsole, runSync, spawnProcess } from "../infra/process.js";
|
|
15
15
|
import { existsSync } from "node:fs";
|
|
16
16
|
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
17
17
|
import { randomUUID } from "node:crypto";
|
|
@@ -130,7 +130,7 @@ function spawnAcceptanceShell(cwd, env) {
|
|
|
130
130
|
cwd,
|
|
131
131
|
env: shellEnv,
|
|
132
132
|
stdio: ["pipe", "pipe", "pipe"],
|
|
133
|
-
windowsHide:
|
|
133
|
+
windowsHide: hideChildConsole,
|
|
134
134
|
detached: process.platform !== "win32"
|
|
135
135
|
});
|
|
136
136
|
}
|
package/src/app/start-run.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./compose.js";
|
|
2
|
-
import { spawnProcess } from "../infra/process.js";
|
|
2
|
+
import { runSync, SHARED_CONSOLE_ENV, spawnProcess } from "../infra/process.js";
|
|
3
3
|
import { upsertTask } from "../infra/store/tasks.js";
|
|
4
4
|
import { compileWorkerContext } from "./context-compiler.js";
|
|
5
5
|
import { failedStart, MAX_RUN_HOST_PROMPT_BYTES, RUN_HOST_STARTUP_TIMEOUT_MS } from "./run-state.js";
|
|
6
|
-
import { closeSync, openSync } from "node:fs";
|
|
6
|
+
import { closeSync, existsSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
9
|
// The MCP client may disappear at any point. A detached process owns the
|
|
@@ -32,6 +32,11 @@ export async function startTrackedRun(job) {
|
|
|
32
32
|
const hostLogPath = job.logPath.endsWith(".jsonl")
|
|
33
33
|
? job.logPath.replace(/\.jsonl$/, ".host.log")
|
|
34
34
|
: `${job.logPath}.host.log`;
|
|
35
|
+
if (process.platform === "win32") {
|
|
36
|
+
const started = await startHostInSharedConsole(job, hostLogPath);
|
|
37
|
+
if (!started.ok) await upsertTask(started.record);
|
|
38
|
+
return started;
|
|
39
|
+
}
|
|
35
40
|
let hostLogFd;
|
|
36
41
|
try {
|
|
37
42
|
hostLogFd = openSync(hostLogPath, "a");
|
|
@@ -75,3 +80,85 @@ export async function startTrackedRun(job) {
|
|
|
75
80
|
if (!started.ok) await upsertTask(started.record);
|
|
76
81
|
return started;
|
|
77
82
|
}
|
|
83
|
+
|
|
84
|
+
// On Windows the run host must share this process's hidden console and live
|
|
85
|
+
// outside the job that ends this process's children: `start /b` gives both.
|
|
86
|
+
// That path has no IPC channel, so the job and the startup answer are files.
|
|
87
|
+
async function startHostInSharedConsole(job, hostLogPath) {
|
|
88
|
+
const base = hostLogPath.replace(/\.host\.log$/, "");
|
|
89
|
+
const jobPath = `${base}.job.json`;
|
|
90
|
+
const ackPath = `${base}.ack.json`;
|
|
91
|
+
const entry = fileURLToPath(new URL("../run-host/entry.js", import.meta.url));
|
|
92
|
+
for (const path of [process.execPath, entry, jobPath, ackPath]) {
|
|
93
|
+
if (/[%&^|<>"]/.test(path)) {
|
|
94
|
+
return failedStart(job.record, `run host cannot launch: path contains a cmd.exe special character (% & ^ | < > "): ${path}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
rmSync(ackPath, { force: true });
|
|
98
|
+
writeFileSync(jobPath, JSON.stringify(job));
|
|
99
|
+
const line = `/d /c start "" /b "${process.execPath}" "${entry}" --run-host --job-file "${jobPath}" --ack-file "${ackPath}"`;
|
|
100
|
+
let hostLogFd;
|
|
101
|
+
try {
|
|
102
|
+
hostLogFd = openSync(hostLogPath, "a");
|
|
103
|
+
} catch (error) {
|
|
104
|
+
rmSync(jobPath, { force: true });
|
|
105
|
+
return failedStart(job.record, `cannot open run host log ${hostLogPath}: ${error.message}`);
|
|
106
|
+
}
|
|
107
|
+
let spawnError = null;
|
|
108
|
+
try {
|
|
109
|
+
const launcher = spawnProcess(process.env.ComSpec || "cmd.exe", [line], {
|
|
110
|
+
stdio: ["ignore", hostLogFd, hostLogFd],
|
|
111
|
+
env: { ...process.env, [SHARED_CONSOLE_ENV]: "1" },
|
|
112
|
+
windowsVerbatimArguments: true,
|
|
113
|
+
windowsHide: true
|
|
114
|
+
});
|
|
115
|
+
launcher.on("error", (error) => {
|
|
116
|
+
spawnError = error;
|
|
117
|
+
});
|
|
118
|
+
launcher.unref();
|
|
119
|
+
} finally {
|
|
120
|
+
closeSync(hostLogFd);
|
|
121
|
+
}
|
|
122
|
+
const deadline = Date.now() + RUN_HOST_STARTUP_TIMEOUT_MS;
|
|
123
|
+
while (Date.now() < deadline) {
|
|
124
|
+
if (spawnError) {
|
|
125
|
+
rmSync(jobPath, { force: true });
|
|
126
|
+
return failedStart(job.record, `run host launcher failed: ${spawnError.message}`);
|
|
127
|
+
}
|
|
128
|
+
if (existsSync(ackPath)) {
|
|
129
|
+
let answer;
|
|
130
|
+
try {
|
|
131
|
+
answer = JSON.parse(readFileSync(ackPath, "utf8"));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return failedStart(job.record, `run host answer unreadable (${error.message}); host log: ${hostLogPath}`);
|
|
134
|
+
} finally {
|
|
135
|
+
rmSync(ackPath, { force: true });
|
|
136
|
+
}
|
|
137
|
+
return answer;
|
|
138
|
+
}
|
|
139
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
140
|
+
}
|
|
141
|
+
return failedStart(job.record, `run host startup timed out; ${abandonLateHost(jobPath)}; host log: ${hostLogPath}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// The host claims the job by renaming the job file; whoever renames it first
|
|
145
|
+
// owns the start. A host that claimed it after the deadline is killed.
|
|
146
|
+
function abandonLateHost(jobPath) {
|
|
147
|
+
try {
|
|
148
|
+
renameSync(jobPath, `${jobPath}.abandoned`);
|
|
149
|
+
rmSync(`${jobPath}.abandoned`, { force: true });
|
|
150
|
+
return "the host never claimed the job";
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error.code !== "ENOENT") return `job file could not be withdrawn: ${error.message}`;
|
|
153
|
+
}
|
|
154
|
+
const pidPath = `${jobPath}.pid`;
|
|
155
|
+
if (!existsSync(pidPath)) return "the host claimed the job but left no pid";
|
|
156
|
+
const pid = Number(readFileSync(pidPath, "utf8"));
|
|
157
|
+
rmSync(pidPath, { force: true });
|
|
158
|
+
try {
|
|
159
|
+
runSync("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", timeout: 5000, windowsHide: true });
|
|
160
|
+
return `the late host ${pid} was stopped`;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return `the late host ${pid} could not be stopped: ${error.message}`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -21,8 +21,19 @@ function uniqueSorted(values) {
|
|
|
21
21
|
return [...new Set((values ?? []).map((value) => String(value)))].sort();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
const POWERSHELL_WRAPPED = /^"?(?:[^"\s]*[\\/])?(?:powershell|pwsh)(?:\.exe)?"?(?:\s+-(?:NoProfile|NoLogo|NonInteractive|ExecutionPolicy\s+\S+))*\s+-(?:Command|c)\s+([\s\S]+)$/i;
|
|
25
|
+
|
|
26
|
+
function unwrapPowerShell(body) {
|
|
27
|
+
const text = body.trim();
|
|
28
|
+
if (text.length >= 2 && text[0] === "'" && text.at(-1) === "'") return text.slice(1, -1).replace(/''/g, "'").trim();
|
|
29
|
+
if (text.length >= 2 && text[0] === '"' && text.at(-1) === '"') return text.slice(1, -1).replace(/\\"/g, '"').trim();
|
|
30
|
+
return text;
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
export function normalizeObservedCommand(command) {
|
|
25
34
|
const text = String(command ?? "").trim();
|
|
35
|
+
const powershell = text.match(POWERSHELL_WRAPPED);
|
|
36
|
+
if (powershell) return unwrapPowerShell(powershell[1]);
|
|
26
37
|
const wrapped = text.match(/^(?:[^\s]+\/)?(?:zsh|bash|sh)\s+-l?c\s+([\s\S]+)$/);
|
|
27
38
|
if (!wrapped) return text;
|
|
28
39
|
let body = wrapped[1].trim();
|
|
@@ -70,6 +70,7 @@ const listSeparator = (platform) => (isWindows(platform) ? ";" : ":");
|
|
|
70
70
|
* @typedef {Object} NpmEntryHint
|
|
71
71
|
* @property {string} pkg npm package name, e.g. "@openai/codex"
|
|
72
72
|
* @property {string} bin entry path inside the package, e.g. "bin/codex.js"
|
|
73
|
+
* @property {string[]} [native] native executable paths inside the package, probed before bin
|
|
73
74
|
*/
|
|
74
75
|
|
|
75
76
|
/**
|
|
@@ -276,6 +277,10 @@ function npmBypass(shimPath, npmEntry, exists, nodePath) {
|
|
|
276
277
|
roots.push(path.win32.dirname(path.win32.dirname(dir)));
|
|
277
278
|
}
|
|
278
279
|
for (const root of roots) {
|
|
280
|
+
for (const native of npmEntry.native ?? []) {
|
|
281
|
+
const binary = path.win32.join(root, "node_modules", npmEntry.pkg, native);
|
|
282
|
+
if (exists(binary)) return { cmd: binary, prefixArgs: [], shim: false };
|
|
283
|
+
}
|
|
279
284
|
const entry = path.win32.join(root, "node_modules", npmEntry.pkg, npmEntry.bin);
|
|
280
285
|
if (!exists(entry)) continue;
|
|
281
286
|
if (DIRECT_EXTS.has(path.win32.extname(entry).toLowerCase())) {
|
package/src/infra/process.js
CHANGED
|
@@ -9,10 +9,15 @@ export const runSync = execFileSync;
|
|
|
9
9
|
export const runFile = execFile;
|
|
10
10
|
export const spawnProcess = spawn;
|
|
11
11
|
|
|
12
|
+
// A Windows run host is started inside its parent's hidden console; its children
|
|
13
|
+
// must share that console, because a console of their own shows a window.
|
|
14
|
+
export const SHARED_CONSOLE_ENV = "AGENT_SUPERVISOR_SHARED_CONSOLE";
|
|
15
|
+
export const hideChildConsole = process.env[SHARED_CONSOLE_ENV] !== "1";
|
|
16
|
+
|
|
12
17
|
// Resolves when the command exits 0, rejects otherwise. Output is discarded.
|
|
13
18
|
export function runToExit(command, args, options = {}) {
|
|
14
19
|
return new Promise((resolvePromise, reject) => {
|
|
15
|
-
const child = spawn(command, args, { stdio: "ignore", windowsHide:
|
|
20
|
+
const child = spawn(command, args, { stdio: "ignore", windowsHide: hideChildConsole, ...options });
|
|
16
21
|
child.on("exit", (code) => {
|
|
17
22
|
if (code === 0) resolvePromise();
|
|
18
23
|
else reject(new Error(`${command} ${args.join(" ")} exited with ${code}`));
|
|
@@ -40,7 +45,7 @@ function powershellBin() {
|
|
|
40
45
|
// seconds to print anything. A tight timeout silently degrades to the useless
|
|
41
46
|
// tasklist probe, and the cancel comes back "process_not_found".
|
|
42
47
|
export function describeProcess(pid) {
|
|
43
|
-
const options = { encoding: "utf8", timeout: 15000, windowsHide:
|
|
48
|
+
const options = { encoding: "utf8", timeout: 15000, windowsHide: hideChildConsole };
|
|
44
49
|
try {
|
|
45
50
|
if (process.platform === "win32") {
|
|
46
51
|
try {
|
|
@@ -52,7 +52,10 @@ const CLIENTS = [
|
|
|
52
52
|
...SKILL_ROOTS.codex,
|
|
53
53
|
binary: "codex",
|
|
54
54
|
binEnv: "CODEX_BIN",
|
|
55
|
-
npmEntry: { pkg: "@openai/codex", bin: "bin/codex.js"
|
|
55
|
+
npmEntry: { pkg: "@openai/codex", bin: "bin/codex.js", native: [
|
|
56
|
+
"node_modules/@openai/codex-win32-x64/vendor/x86_64-pc-windows-msvc/bin/codex.exe",
|
|
57
|
+
"node_modules/@openai/codex-win32-arm64/vendor/aarch64-pc-windows-msvc/bin/codex.exe"
|
|
58
|
+
] }
|
|
56
59
|
}
|
|
57
60
|
];
|
|
58
61
|
|
package/src/run-host/entry.js
CHANGED
|
@@ -6,10 +6,11 @@ import { failedStart } from "../app/run-state.js";
|
|
|
6
6
|
import { upsertTask } from "../infra/store/tasks.js";
|
|
7
7
|
import { installCrashGuard } from "../infra/crash-guard.js";
|
|
8
8
|
import { trackRunInHost } from "./track.js";
|
|
9
|
+
import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
9
10
|
|
|
10
11
|
installCrashGuard("run-host", { exitOnRejection: true });
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
async function runJob(job, answer) {
|
|
13
14
|
const keepAlive = setInterval(() => {}, 1000);
|
|
14
15
|
let result;
|
|
15
16
|
try {
|
|
@@ -19,8 +20,39 @@ process.once("message", async (job) => {
|
|
|
19
20
|
result = failedStart(job.record, `run host failed: ${error.message}`);
|
|
20
21
|
await upsertTask(result.record);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
await answer({ ok: result.ok, record: result.record });
|
|
23
24
|
if (result.settled) await result.settled;
|
|
24
25
|
clearInterval(keepAlive);
|
|
25
26
|
if (process.connected) process.disconnect();
|
|
26
|
-
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function argValue(name) {
|
|
30
|
+
const index = process.argv.indexOf(name);
|
|
31
|
+
return index === -1 ? null : process.argv[index + 1];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const jobFile = argValue("--job-file");
|
|
35
|
+
if (jobFile) {
|
|
36
|
+
const ackFile = argValue("--ack-file");
|
|
37
|
+
writeFileSync(`${jobFile}.pid`, String(process.pid));
|
|
38
|
+
const claimed = `${jobFile}.claimed`;
|
|
39
|
+
try {
|
|
40
|
+
renameSync(jobFile, claimed);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
rmSync(`${jobFile}.pid`, { force: true });
|
|
43
|
+
console.error(`[ERROR] job ${jobFile} withdrawn before this host claimed it: ${error.message}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const job = JSON.parse(readFileSync(claimed, "utf8"));
|
|
47
|
+
rmSync(claimed);
|
|
48
|
+
rmSync(`${jobFile}.pid`, { force: true });
|
|
49
|
+
runJob(job, (message) => {
|
|
50
|
+
writeFileSync(`${ackFile}.tmp`, JSON.stringify(message));
|
|
51
|
+
renameSync(`${ackFile}.tmp`, ackFile);
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
process.once("message", (job) => runJob(job, (message) => {
|
|
55
|
+
if (!process.connected) return undefined;
|
|
56
|
+
return new Promise((resolveSent) => process.send(message, resolveSent));
|
|
57
|
+
}));
|
|
58
|
+
}
|
package/src/run-host/track.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import "../app/compose.js";
|
|
5
5
|
import { failedStart, processes } from "../app/run-state.js";
|
|
6
6
|
import { captureExternalOutputs } from "../infra/external-output.js";
|
|
7
|
-
import { spawnProcess } from "../infra/process.js";
|
|
7
|
+
import { hideChildConsole, spawnProcess } from "../infra/process.js";
|
|
8
8
|
import { clearStage } from "../infra/stage-store.js";
|
|
9
9
|
import { appendTaskEvent, ensureRunRecord } from "../infra/store/events.js";
|
|
10
10
|
import { getTask } from "../infra/store/tasks.js";
|
|
@@ -97,9 +97,9 @@ export async function trackRunInHost({ record, args, prompt, logPath, spawnOptio
|
|
|
97
97
|
|
|
98
98
|
const { child, spawnError, earlyOutput } = await spawnAndAwaitStart(target, launch.guardedArgs, {
|
|
99
99
|
stdio: ["pipe", "pipe", "pipe"],
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
...spawnOptions
|
|
100
|
+
windowsHide: hideChildConsole,
|
|
101
|
+
...spawnOptions,
|
|
102
|
+
env: { ...launch.env(), ...spawnOptions.env, ...target.env }
|
|
103
103
|
});
|
|
104
104
|
if (spawnError) return failedStart(record, `failed to spawn ${target.cmd}: ${spawnError.message}`);
|
|
105
105
|
|
|
@@ -9,7 +9,16 @@ import { fileURLToPath } from "node:url";
|
|
|
9
9
|
|
|
10
10
|
const quoteCommand = (path) => process.platform === "win32" ? `"${path.replace(/"/g, '""')}"` : `'${path.replace(/'/g, "'\\''")}'`;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// The native binary is resolved before codex.js: its commands must share the
|
|
13
|
+
// run host's console.
|
|
14
|
+
const CODEX_NPM_ENTRY = {
|
|
15
|
+
pkg: "@openai/codex",
|
|
16
|
+
bin: "bin/codex.js",
|
|
17
|
+
native: [
|
|
18
|
+
"node_modules/@openai/codex-win32-x64/vendor/x86_64-pc-windows-msvc/bin/codex.exe",
|
|
19
|
+
"node_modules/@openai/codex-win32-arm64/vendor/aarch64-pc-windows-msvc/bin/codex.exe"
|
|
20
|
+
]
|
|
21
|
+
};
|
|
13
22
|
|
|
14
23
|
export class CodexRunnerAdapter {
|
|
15
24
|
constructor({ env = process.env } = {}) {
|
|
@@ -72,7 +81,12 @@ export class CodexRunnerAdapter {
|
|
|
72
81
|
const located = configured ? configured : (findBinaryPath("codex", { extraDirs: defaultBinDirs() }) ?? "codex");
|
|
73
82
|
const target = resolveCommand(located, { npmEntry: CODEX_NPM_ENTRY });
|
|
74
83
|
if (target.shim) return { error: shimMessage("codex", target.cmd, "CODEX_BIN") };
|
|
75
|
-
|
|
84
|
+
const normalized = target.cmd.replace(/\\/g, "/");
|
|
85
|
+
const native = CODEX_NPM_ENTRY.native.find((entry) => normalized.toLowerCase().endsWith(`/${entry.toLowerCase()}`));
|
|
86
|
+
const packageRoot = native ? target.cmd.slice(0, -(native.length + 1)) : null;
|
|
87
|
+
return { cmd: target.cmd, prefixArgs: target.prefixArgs, ...(packageRoot ? { env: {
|
|
88
|
+
CODEX_MANAGED_BY_NPM: "1", CODEX_MANAGED_PACKAGE_ROOT: packageRoot
|
|
89
|
+
} } : {}) };
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
capabilityPreflight(target = this.resolveTarget()) {
|