codex-supervisor-mcp 0.6.1 → 0.7.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.en.md +75 -8
- package/README.md +75 -8
- package/package.json +5 -1
- package/skills/codex-supervisor/SKILL.md +20 -3
- package/src/auto-update-worker.js +186 -0
- package/src/auto-update.js +144 -0
- package/src/event-parser.js +21 -2
- package/src/landing.js +144 -0
- package/src/mcp-server.js +148 -7
- package/src/setup.js +6 -47
- package/src/side-chat.js +147 -6
- package/src/skill-sync.js +93 -0
- package/src/task-store.js +17 -5
- package/src/update-check.js +53 -13
- package/src/worktree.js +110 -2
package/README.en.md
CHANGED
|
@@ -8,7 +8,7 @@ English | [中文](README.md)
|
|
|
8
8
|
[](https://github.com/zriyox/codex-supervisor-mcp/actions/workflows/ci.yml)
|
|
9
9
|
[](package.json)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
**codex-supervisor-mcp** is a Codex MCP server: let one main thread (Claude Code, Codex, or any MCP client) run several Codex CLI workers at once. One Git worktree per worker, every state change on disk, and a web board to watch the batch.
|
|
12
12
|
|
|
13
13
|

|
|
14
14
|
|
|
@@ -86,6 +86,56 @@ Which store it opens: `SUPERVISOR_HOME` from the environment if set; otherwise t
|
|
|
86
86
|
|
|
87
87
|
`SUPERVISOR_WEB_PORT` changes the port. A taken port (usually a board that is already running) is reported in one line and the process exits. The board does not dispatch or cancel; the ask tab starts a read-only Codex side session, described below.
|
|
88
88
|
|
|
89
|
+
## How I use it
|
|
90
|
+
|
|
91
|
+
The boundary first: this MCP does not care who the main thread is. Claude Code, Codex itself, Cursor, anything that speaks MCP can dispatch. Workers run `codex exec`, so any model you have configured as a Codex provider works, DeepSeek on one worker and GPT on the next. You can describe the batch in plain words and let the skill make the calls, or call the tools yourself. What follows is my way, not the only way.
|
|
92
|
+
|
|
93
|
+
I run two Claude Code sessions. One writes documents, the other dispatches. A session that writes the design and watches the workers fills its context in two hours, and mixes the judgement that goes into code with the judgement that goes into dispatch.
|
|
94
|
+
|
|
95
|
+
| Who | Where | Does what |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| Me | | Decide what to build, make the calls, read the reports |
|
|
98
|
+
| Planning session | The requirements and docs repository | Talk through the requirement, write the design, write one brief per block of work with a paragraph for the main brain at the end |
|
|
99
|
+
| Main-brain session | A worktree of the code repository | Read the brief, dispatch Codex workers, check every worker's diff, write results back into the brief, report to me. Writes no business code |
|
|
100
|
+
| Codex workers | Their own worktrees | One worker per step, one commit per step, build and verify on a remote machine. No push, no merge |
|
|
101
|
+
|
|
102
|
+
Only one block of text passes between the two sessions. The planning session writes it, I paste it into the main-brain session and hand it over with `/goal`. Its shape is always the same:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
[Role] You are the main brain: read docs and code, dispatch workers, check results, update docs, report to me. You write no business code.
|
|
106
|
+
Dispatch and track with the codex-supervisor skill; load it before starting.
|
|
107
|
+
[Background] Why this block exists, what the previous one left behind
|
|
108
|
+
[Read first] Which sections of which documents. Which one wins when they disagree
|
|
109
|
+
[Repos] Where the worktrees are, which commit each branch is on, which branches are read-only
|
|
110
|
+
[Do] Follow the table in section N of the brief. One commit per step; verify a step before starting the next. Nothing outside the table
|
|
111
|
+
[Dispatch] search_works first, do not dispatch twice
|
|
112
|
+
One session_id for the whole batch
|
|
113
|
+
Serial when steps touch the same files, parallel only when ownedPaths do not overlap
|
|
114
|
+
One worker per step. Write the task in full: background, where in the docs, files to change, verify command, output format
|
|
115
|
+
Read the diff when a worker returns. Its word is not enough; what you see is
|
|
116
|
+
[Build/test] Everything on the remote machine, nothing locally
|
|
117
|
+
[Red lines] What not to change, push or read
|
|
118
|
+
[Stop and ask me when]
|
|
119
|
+
[Report] Tables first, these items, then stop and wait for me
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
What the main brain calls in one round:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
search_works has this batch been dispatched before
|
|
126
|
+
create_codex_worker one worker per step, same session_id, ownedPaths disjoint
|
|
127
|
+
wait_codex_workers two minutes a round, compact: true, call again until done
|
|
128
|
+
get_worker_result what it says it did
|
|
129
|
+
get_worker_diff what it actually did
|
|
130
|
+
ask_codex_worker when the two differ, ask why; read-only, its thread untouched
|
|
131
|
+
resume_codex_worker when it must change something, one follow-up, amended into the same commit
|
|
132
|
+
land_codex_worker checked, then landed on the integration branch
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The last block was 25 steps. The main-brain session ran it end to end with nothing in its context but the brief and each worker's report. The tokens the workers burn are not on the main brain's bill.
|
|
136
|
+
|
|
137
|
+
"One worker per step, one commit per step, checked before the next" came from trying it the other way. A worker returns, the main brain reads the diff and finds step 5 wrong: it sends one `resume_codex_worker` saying what is wrong and asking for `git commit --amend` into the same commit. Same Codex thread, full context, checked again before landing. A worker that did three steps cannot be fixed this way: when step 5 is wrong, the commits for steps 6 and 7 are already on top.
|
|
138
|
+
|
|
89
139
|
## What the board shows
|
|
90
140
|
|
|
91
141
|
| Where | What |
|
|
@@ -100,16 +150,19 @@ Lists load lazily: 20 sessions per page in the rail, 40 workers per page in the
|
|
|
100
150
|
|
|
101
151
|
## Tools
|
|
102
152
|
|
|
103
|
-
|
|
153
|
+
Nineteen.
|
|
104
154
|
|
|
105
155
|
| Tool | Arguments | What it does |
|
|
106
156
|
|---|---|---|
|
|
107
157
|
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Start a worker. `session_title` / `session_note` say what the batch is for; `baseRef` picks the commit the worktree is cut from (default: the repository's `HEAD`), pass another worker's `codex/<id>` branch to build on work not yet on the main line |
|
|
108
158
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, plus the above | A new session seeded with the old worker's prompt, status and recent events |
|
|
109
159
|
| `resume_codex_worker` | `task_id`, `prompt` | Continue the same Codex conversation; `thread_id` stays |
|
|
110
|
-
| `wait_codex_workers` | `task_ids`, `mode` (any/all), `timeoutMinutes`, `timeoutMs`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for terminal states. Two minutes by default, then a snapshot; `still_running: true` means call again with the same ids. Events off by default |
|
|
160
|
+
| `wait_codex_workers` | `task_ids`, `mode` (any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for terminal states. Two minutes by default, then a snapshot; `still_running: true` means call again with the same ids. Events off by default; `compact` returns one line per worker |
|
|
111
161
|
| `get_orchestration_overview` | `status`, `limit` | Every worker in one table, capped at 7000 bytes. Carries `version` and `update` |
|
|
112
162
|
| `get_worker_result` | `task_id`, `limit`, `maxChars` | The worker's own full report plus `status` / `exit_code` / `changed_files`. The door for conclusions |
|
|
163
|
+
| `get_worker_diff` | `task_id`, `maxChars`, `paths` | What the worker actually changed: patches from the worktree's starting commit to its working tree, committed or not, untracked files included. `maxChars` bounds the whole answer; files past it are listed without a patch |
|
|
164
|
+
| `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | Ask the worker on the side. Its thread is forked into a read-only session with no network and no MCP tools; the worker itself is untouched. A resumed worker gets a new fork by itself, `fresh` forces one, `end` deletes it |
|
|
165
|
+
| `land_codex_worker` | `task_id`, `onto`, `commitMessage` | Cherry-pick the worker's commits from `codex/<id>` onto the current branch of the directory it was dispatched from. The target must be clean, `onto` is a check and never a switch, and a conflict rolls back and lists the files. `commitMessage` first commits the worker's uncommitted edits as one commit |
|
|
113
166
|
| `get_worker_summary` | `task_id` | One paragraph: goal, status, changes, last command and message |
|
|
114
167
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | One worker in detail; the prompt is clipped to 300 characters unless asked for |
|
|
115
168
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | The raw event stream |
|
|
@@ -135,6 +188,8 @@ Sixteen.
|
|
|
135
188
|
| One worker's conclusion | `get_worker_result` | The full report, tens of thousands of characters for a big job |
|
|
136
189
|
| Alive or finished | `get_worker_summary` | A paragraph |
|
|
137
190
|
| What it did | `get_codex_worker_events` | Filter with `kinds`, bound with `limit`, clip with `maxChars` |
|
|
191
|
+
| What it actually changed | `get_worker_diff` | Capped by `maxChars`; the file list is always complete |
|
|
192
|
+
| Why it did that | `ask_codex_worker` | One answer; the fork carries the worker's whole context |
|
|
138
193
|
|
|
139
194
|
The dispatch receipt is small and does not echo the task text. `wait_codex_workers` clips `last_message` to 400 characters and `current_action` to 300; the full text is behind `get_worker_result` and `get_codex_worker_events`. That clipping is what takes a five-worker wait from tens of KB to a few KB, which matters when a client backgrounds a timed-out call and replays the result as a notification.
|
|
140
195
|
|
|
@@ -209,6 +264,9 @@ Cached an hour, re-checked every six while running. An unreachable registry is n
|
|
|
209
264
|
| `CODEX_SUPERVISOR_REGISTRY` | `https://registry.npmjs.org` | Registry for the update check |
|
|
210
265
|
| `CODEX_SUPERVISOR_UPDATE_TIMEOUT_MS` | `4000` | How long to wait for the registry |
|
|
211
266
|
| `CODEX_SUPERVISOR_SKIP_SETUP` | unset | `1` skips the `postinstall` setup |
|
|
267
|
+
| `CODEX_SUPERVISOR_NO_AUTO_UPDATE` | unset | `1` turns the background auto-update off (notify only) |
|
|
268
|
+
| `CODEX_SUPERVISOR_SKIP_SKILL_SYNC` | unset | `1` turns the skill sync at server start off |
|
|
269
|
+
| `CODEX_SUPERVISOR_NPM` | unset | npm for the auto-update (path to `npm-cli.js` or an executable); default is the one shipped with the running node |
|
|
212
270
|
|
|
213
271
|
A process started by a GUI client often has no `codex` on `PATH`; set `CODEX_BIN` in the config:
|
|
214
272
|
|
|
@@ -250,16 +308,23 @@ An existing skill with different content is backed up to `SKILL.md.bak-<timestam
|
|
|
250
308
|
|
|
251
309
|
### Upgrading
|
|
252
310
|
|
|
311
|
+
Nothing to do by hand. Every server start asks the registry in the background (then every six hours); when a newer version is published it starts a detached process that runs `npm i -g codex-supervisor-mcp@<that version>` into the same global path. **The running session is untouched; the next session starts on the new version.** Progress lands in `~/.codex-supervisor/data/auto-update.json` and `auto-update.log`, and tool results carry it as `update.auto_update` (`started / running / done / failed`).
|
|
312
|
+
|
|
313
|
+
Only a copy that `npm i -g` installed is touched, and the updater checks the path against `npm root -g` first. A git checkout, an `npm link`, a project-local dependency and an `npx`-started copy are left alone. Each published version is attempted once, and several sessions starting together share one updater. `CODEX_SUPERVISOR_NO_AUTO_UPDATE=1` turns it off; CI is skipped automatically.
|
|
314
|
+
|
|
315
|
+
On a machine where the global directory needs sudo the install fails, the `update` field says why, and the manual way still works:
|
|
316
|
+
|
|
253
317
|
```bash
|
|
254
318
|
npm install -g codex-supervisor-mcp@latest
|
|
255
|
-
npm ls -g --depth=0 | grep codex-supervisor
|
|
256
319
|
```
|
|
257
320
|
|
|
258
|
-
|
|
321
|
+
Versions up to 0.6.1 only notify and never install. Coming from one of those, upgrade by hand once; after that it is automatic. No re-registration needed.
|
|
322
|
+
|
|
323
|
+
Manual-update pitfalls:
|
|
259
324
|
|
|
260
325
|
- The registry takes a few minutes to move `latest` after a publish. If the version did not change, wait, or pin the version.
|
|
261
|
-
- `npm link` installs a symlink: `src/` changes apply at once, the skill does not sync by itself; run `codex-supervisor-setup`.
|
|
262
326
|
- Switching Node versions breaks the registered absolute path. Run `claude mcp remove -s user codex-supervisor` and `codex mcp remove codex-supervisor` first, then install.
|
|
327
|
+
- The skill takes care of itself: every server start copies the bundled skill into whichever of `~/.claude/skills/`, `~/.agents/skills/` and `~/.codex/skills/` already exist, backing up a differing file as `SKILL.md.bak-<timestamp>`. A session that already loaded the skill sees the new text only after loading it again. `CODEX_SUPERVISOR_SKIP_SKILL_SYNC=1` turns the sync off.
|
|
263
328
|
|
|
264
329
|
### Uninstall
|
|
265
330
|
|
|
@@ -292,7 +357,8 @@ rm -rf ~/.codex-supervisor
|
|
|
292
357
|
|
|
293
358
|
## Known limitations
|
|
294
359
|
|
|
295
|
-
- A worker
|
|
360
|
+
- A worker is a child of the MCP process. Kill the MCP and the worker goes with it, settled as `lost` on the next read. Its worktree and `thread_id` survive: `resume_codex_worker` continues the same thread. Keeping it alive across that takes a resident daemon; see the Roadmap.
|
|
361
|
+
- In the default `workspace-write` sandbox a worker cannot commit: Codex keeps `.git` read-only. Either let it edit only and pass `commitMessage` to `land_codex_worker`, or dispatch with `danger-full-access`.
|
|
296
362
|
- The worktree is cut from a commit, so uncommitted work in your checkout is not in it. Give the task absolute paths, or commit first.
|
|
297
363
|
- Only the working directory is isolated. Temp directories, databases and ports are shared; workers that would hit the same dev server need to be kept apart in the task.
|
|
298
364
|
- `ownedPaths` is checked at dispatch only; it does not stop a worker from creating a file it never listed. Review the diff.
|
|
@@ -314,7 +380,8 @@ rm -rf ~/.codex-supervisor
|
|
|
314
380
|
9. ~~Windows~~ ✅
|
|
315
381
|
10. ~~Web board~~ ✅
|
|
316
382
|
11. ~~Session titles, update check, `baseRef`, committed changes visible~~ ✅
|
|
317
|
-
12.
|
|
383
|
+
12. ~~Collecting work: `get_worker_diff` / `ask_codex_worker` / `land_codex_worker`; background auto-update~~ ✅
|
|
384
|
+
13. Resident daemon: move dispatch and process lifetime out of the MCP process
|
|
318
385
|
|
|
319
386
|
Not planned: vector search (substring matching is faster at this scale and costs nothing to maintain), `usage_count` ordering (2 of 80 real works were ever referenced again), a layered memory index (not enough data to need one).
|
|
320
387
|
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://github.com/zriyox/codex-supervisor-mcp/actions/workflows/ci.yml)
|
|
9
9
|
[](package.json)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
**codex-supervisor-mcp** 是一个 Codex MCP server:让一个主线程(Claude Code、Codex,或任何 MCP 客户端)同时指挥多个 Codex CLI worker 干活。一个 worker 一个 Git worktree,状态全部落盘,附一个网页看板盯进度。
|
|
12
12
|
|
|
13
13
|

|
|
14
14
|
|
|
@@ -86,6 +86,56 @@ npx -p codex-supervisor-mcp codex-supervisor-web
|
|
|
86
86
|
|
|
87
87
|
端口用 `SUPERVISOR_WEB_PORT` 改。端口被占(多半是已经有一个看板在跑)会直接说明并退出。看板不派单也不取消;「旁问」会起一个只读的 Codex 旁路会话,见下面。
|
|
88
88
|
|
|
89
|
+
## 我自己怎么用
|
|
90
|
+
|
|
91
|
+
先说边界:这个 MCP 不挑主线程。Claude Code、Codex 自己、Cursor,能连 MCP 的都能派活。worker 跑的是 `codex exec`,你给 Codex 配了哪个 provider 它就能用哪个模型,一路 DeepSeek 一路 GPT 都行。派活可以说人话让 skill 去调,也可以自己一个个调工具。下面是我的用法,不是唯一用法。
|
|
92
|
+
|
|
93
|
+
我开两个 Claude Code 会话。一个只管文档,一个只管派活。一个会话又写详设又盯 worker,上下文两小时就满,写代码的判断和派活的判断也混在一起。
|
|
94
|
+
|
|
95
|
+
| 谁 | 开在哪 | 管什么 |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| 我 | | 定需求,拍板,看汇报 |
|
|
98
|
+
| 规划会话 | 需求和文档仓 | 聊需求,写详设,每一块活写一份任务书,末尾附一段发给主脑的话 |
|
|
99
|
+
| 主脑会话 | 代码仓的一个 worktree | 读任务书,派 Codex worker,核每路的 diff,把结果填回任务书,向我汇报。不写业务代码 |
|
|
100
|
+
| Codex worker | 各自的 worktree | 一个 worker 做一步,一个提交,在远端机器上编译和验证。不 push,不合并 |
|
|
101
|
+
|
|
102
|
+
两个会话之间只传一段文字。规划会话写好,我复制,粘进主脑会话,用 `/goal` 接上。这段文字的结构是固定的:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
【角色】 你是主脑:读文档和代码,派 worker,核结果,更新文档,向我汇报。不写业务代码。
|
|
106
|
+
派活和盯进度用 codex-supervisor 这个 skill,开工前先加载它。
|
|
107
|
+
【背景】 这一块为什么做,上一块留下了什么
|
|
108
|
+
【先读】 哪几份文档的哪几节。几份说法不一样时以哪份为准
|
|
109
|
+
【仓和分支】工作目录在哪,各分支现在在哪个提交,哪些分支只读
|
|
110
|
+
【做什么】 照任务书第几节那张表做。一步一个提交,这步验证过了才做下一步。表里没有的不做
|
|
111
|
+
【派活】 先 search_works 看有没有派过,别重复
|
|
112
|
+
整批用同一个 session_id
|
|
113
|
+
改同一批文件就串行,文件完全不重叠才并行,每路 ownedPaths 写清
|
|
114
|
+
一个 worker 只做一步。task 写全:背景、文档出处、要改的文件、验证命令、输出格式
|
|
115
|
+
worker 交回来先看 diff。它说过了不算,你看到才算
|
|
116
|
+
【构建和测试】全走远端机器,本机不跑
|
|
117
|
+
【红线】 不改什么,不推什么,不读什么
|
|
118
|
+
【必须停下来问我】
|
|
119
|
+
【汇报】 中文,表格优先,报哪几项,然后停下来等我
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
主脑这边一轮下来调的工具就这几个:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
search_works 查这批活派过没有
|
|
126
|
+
create_codex_worker 一步一个 worker,同一个 session_id,ownedPaths 不重叠
|
|
127
|
+
wait_codex_workers 2 分钟一轮,compact: true,没完接着调
|
|
128
|
+
get_worker_result 它说自己做了什么
|
|
129
|
+
get_worker_diff 它实际做了什么
|
|
130
|
+
ask_codex_worker 对不上就问它为什么,只读,不动它的线程
|
|
131
|
+
resume_codex_worker 要改就追一条,让它 amend 进原来那个提交
|
|
132
|
+
land_codex_worker 核过了,落进集成分支
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
上一块活 25 步,主脑会话从头跑到尾,上下文里只有任务书和每路的汇报。worker 那边烧的 token 不进主脑的账。
|
|
136
|
+
|
|
137
|
+
「一个 worker 一步、一步一个提交、核过才进下一步」这条是试出来的。worker 交回来,主脑看 diff 发现某一步不对,就 `resume_codex_worker` 追一条:问题在哪,改完 `git commit --amend` 并进原来那个提交。worker 还是同一个 Codex 会话,上下文都在,改完主脑再核一次,过了才落。一个 worker 做三步就没法这么修:第 5 步错了,第 6、7 步的提交已经叠在上面。
|
|
138
|
+
|
|
89
139
|
## 看板里有什么
|
|
90
140
|
|
|
91
141
|
| 位置 | 内容 |
|
|
@@ -100,16 +150,19 @@ npx -p codex-supervisor-mcp codex-supervisor-web
|
|
|
100
150
|
|
|
101
151
|
## 工具
|
|
102
152
|
|
|
103
|
-
|
|
153
|
+
19 个。
|
|
104
154
|
|
|
105
155
|
| 工具 | 入参 | 作用 |
|
|
106
156
|
|---|---|---|
|
|
107
157
|
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | 起一个 worker。`session_title` / `session_note` 记这批活是干什么的;`baseRef` 指定 worktree 从哪个提交切,默认仓库 `HEAD`,要接着另一路没合进主线的 `codex/<id>` 分支干就填它 |
|
|
108
158
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, 其余同上 | 开一个新会话,把老 worker 的 prompt、状态、近期事件拼进去 |
|
|
109
159
|
| `resume_codex_worker` | `task_id`, `prompt` | 接同一个 Codex 会话继续跑,`thread_id` 不变 |
|
|
110
|
-
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 2 分钟,到点带快照返回,worker 照跑;`still_running: true` 时拿同一批 id
|
|
160
|
+
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 2 分钟,到点带快照返回,worker 照跑;`still_running: true` 时拿同一批 id 接着调。默认不带事件;`compact` 每路只回一行 |
|
|
111
161
|
| `get_orchestration_overview` | `status`, `limit` | 全部 worker 的状态表,封顶 7000 字节。带 `version` 和 `update` |
|
|
112
162
|
| `get_worker_result` | `task_id`, `limit`, `maxChars` | worker 自己的完整汇报,外加 `status` / `exit_code` / `changed_files`。收结论用这个 |
|
|
163
|
+
| `get_worker_diff` | `task_id`, `maxChars`, `paths` | worker 实际改了什么:从 worktree 起点到工作区的 patch,提交没提交都算,未跟踪的文件也在。`maxChars` 管总量,超了的文件只列名不给 patch |
|
|
164
|
+
| `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | 旁路问 worker 一句。线程 fork 成只读侧会话,没网络、没 MCP 工具,worker 本身不动。worker 被 resume 过会自动换新 fork,`fresh` 强制换,`end` 删 |
|
|
165
|
+
| `land_codex_worker` | `task_id`, `onto`, `commitMessage` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标必须干净,`onto` 只核对不切换,冲突就回滚并列出文件。`commitMessage` 先替它把未提交的改动提交成一笔 |
|
|
113
166
|
| `get_worker_summary` | `task_id` | 一段话:goal、状态、改动、最后一条命令和消息 |
|
|
114
167
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | 单个 worker 的状态细节,prompt 默认截到 300 字 |
|
|
115
168
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | 原始事件流 |
|
|
@@ -135,6 +188,8 @@ npx -p codex-supervisor-mcp codex-supervisor-web
|
|
|
135
188
|
| 收一路的结论 | `get_worker_result` | 汇报全文,大活上万字 |
|
|
136
189
|
| 只看活着还是完了 | `get_worker_summary` | 一段话 |
|
|
137
190
|
| 看过程 | `get_codex_worker_events` | 用 `kinds` 先滤、`limit` 限条数、`maxChars` 截长串 |
|
|
191
|
+
| 看它实际改了什么 | `get_worker_diff` | `maxChars` 封顶,文件清单永远全 |
|
|
192
|
+
| 问它为什么 | `ask_codex_worker` | 一段回答,fork 带着它的全部上下文 |
|
|
138
193
|
|
|
139
194
|
派单回执是精简的,不回传任务原文。`wait_codex_workers` 的 `last_message` 截到 400 字,`current_action` 截到 300 字,要全文走 `get_worker_result` 和 `get_codex_worker_events`。这些裁剪是为了一次 wait 五路从几十 KB 降到几 KB;客户端把超时的调用挪到后台再把结果当通知回灌时,这个差别很大。
|
|
140
195
|
|
|
@@ -209,6 +264,9 @@ MCP 启动时问一次 npm registry:`latest` 是哪个版本,tarball integri
|
|
|
209
264
|
| `CODEX_SUPERVISOR_REGISTRY` | `https://registry.npmjs.org` | 更新检查用的 registry |
|
|
210
265
|
| `CODEX_SUPERVISOR_UPDATE_TIMEOUT_MS` | `4000` | 等 registry 的上限 |
|
|
211
266
|
| `CODEX_SUPERVISOR_SKIP_SETUP` | 未设 | `1` 跳过 `postinstall` 的自动安装 |
|
|
267
|
+
| `CODEX_SUPERVISOR_NO_AUTO_UPDATE` | 未设 | `1` 关闭后台自动更新(只提醒) |
|
|
268
|
+
| `CODEX_SUPERVISOR_SKIP_SKILL_SYNC` | 未设 | `1` 关闭 server 启动时的 skill 同步 |
|
|
269
|
+
| `CODEX_SUPERVISOR_NPM` | 未设 | 自动更新用的 npm(`npm-cli.js` 路径或可执行文件),默认用当前 node 自带的那个 |
|
|
212
270
|
|
|
213
271
|
GUI 客户端起的进程 `PATH` 里常常没有 `codex`,在配置里显式给 `CODEX_BIN`:
|
|
214
272
|
|
|
@@ -250,16 +308,23 @@ skill 已存在且内容不同时先备份成 `SKILL.md.bak-<时间戳>` 再覆
|
|
|
250
308
|
|
|
251
309
|
### 更新
|
|
252
310
|
|
|
311
|
+
不用手动更。server 每次启动在后台问一次 registry(之后每 6 小时一次),发现新版就起一个独立进程跑 `npm i -g codex-supervisor-mcp@<新版本>`,装到同一个全局路径。**正在跑的会话不受影响,下一个新会话就是新版。** 过程记在 `~/.codex-supervisor/data/auto-update.json` 和 `auto-update.log`;工具返回的 `update.auto_update` 里也能看到 `started / running / done / failed`。
|
|
312
|
+
|
|
313
|
+
只对 `npm i -g` 装的那份生效,更新前会用 `npm root -g` 核对路径。git 源码、`npm link`、项目内依赖、`npx` 起的都不碰。同一个版本只试一次,几个会话同时启动也只有一个进程在装。`CODEX_SUPERVISOR_NO_AUTO_UPDATE=1` 关掉;CI 里自动跳过。
|
|
314
|
+
|
|
315
|
+
全局目录要 sudo 才能写的机器上会装失败,`update` 字段里会带上原因,这时还是手动:
|
|
316
|
+
|
|
253
317
|
```bash
|
|
254
318
|
npm install -g codex-supervisor-mcp@latest
|
|
255
|
-
npm ls -g --depth=0 | grep codex-supervisor
|
|
256
319
|
```
|
|
257
320
|
|
|
258
|
-
|
|
321
|
+
0.6.1 及以前的版本只提醒、不自己装。从那些版本上来,手动升一次,之后就自动了。注册不用重做。
|
|
322
|
+
|
|
323
|
+
手动更的坑:
|
|
259
324
|
|
|
260
325
|
- 刚发布的版本 registry 要几分钟才切 `latest`,装完版本没变就等一会,或者写死版本号。
|
|
261
|
-
- `npm link` 装出来的是软链,改 `src/` 立即生效,但 skill 不会自动同步,手动跑 `codex-supervisor-setup`。
|
|
262
326
|
- 换了 Node 版本,注册的绝对路径就失效了。先 `claude mcp remove -s user codex-supervisor` 和 `codex mcp remove codex-supervisor`,再装。
|
|
327
|
+
- skill 不用单独管:server 每次启动会把自带的 skill 刷到 `~/.claude/skills/`、`~/.agents/skills/`、`~/.codex/skills/` 里已经存在的那几个目录,内容不同先备份成 `SKILL.md.bak-<时间戳>`。已经加载了 skill 的会话要重新加载才看到新文本。`CODEX_SUPERVISOR_SKIP_SKILL_SYNC=1` 关掉。
|
|
263
328
|
|
|
264
329
|
### 卸载
|
|
265
330
|
|
|
@@ -292,7 +357,8 @@ rm -rf ~/.codex-supervisor
|
|
|
292
357
|
|
|
293
358
|
## 已知限制
|
|
294
359
|
|
|
295
|
-
- worker
|
|
360
|
+
- worker 是 MCP 进程的子进程。MCP 被 kill,worker 跟着没了,下次读状态结算成 `lost`。worktree 里的改动和 `thread_id` 都在,`resume_codex_worker` 接回同一个线程继续;让它不跟着死,要常驻 daemon,在 Roadmap 里。
|
|
361
|
+
- 默认的 `workspace-write` 沙箱里 worker 提交不了:Codex 把 `.git` 设成只读。要么让它只改文件,收活时 `land_codex_worker` 带 `commitMessage` 替它提交;要么派单用 `danger-full-access`。
|
|
296
362
|
- worktree 从一个提交切,你工作区里没 commit 的东西不在里面。要让 worker 读到,给绝对路径或先 commit。
|
|
297
363
|
- 只隔离工作目录。临时目录、数据库、端口是共用的,多路 worker 要连同一个 dev server 得自己错开。
|
|
298
364
|
- `ownedPaths` 只在派单时查,拦不住 worker 在自己 worktree 里新建清单外的文件。收活看 diff。
|
|
@@ -314,7 +380,8 @@ rm -rf ~/.codex-supervisor
|
|
|
314
380
|
9. ~~Windows~~ ✅
|
|
315
381
|
10. ~~网页看板~~ ✅
|
|
316
382
|
11. ~~session 标题、更新检查、`baseRef`、已 commit 的改动可见~~ ✅
|
|
317
|
-
12.
|
|
383
|
+
12. ~~收活三件套:`get_worker_diff` / `ask_codex_worker` / `land_codex_worker`;后台自动更新~~ ✅
|
|
384
|
+
13. 常驻 daemon:派单和进程生命周期从 MCP 进程里拿出来
|
|
318
385
|
|
|
319
386
|
不做的:向量检索(子串匹配在这个规模更快、零维护)、`usage_count` 排序(实测 80 个 work 里只有 2 个被回头引用过)、三层记忆索引(数据量撑不起)。
|
|
320
387
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server that dispatches and supervises parallel Codex CLI workers, one isolated Git worktree each, with a persisted work state machine.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
"src/mcp-server.js",
|
|
32
32
|
"src/bin-resolver.js",
|
|
33
33
|
"src/setup.js",
|
|
34
|
+
"src/skill-sync.js",
|
|
34
35
|
"src/codex-runner.js",
|
|
35
36
|
"src/task-store.js",
|
|
36
37
|
"src/goal-store.js",
|
|
37
38
|
"src/event-parser.js",
|
|
38
39
|
"src/worktree.js",
|
|
40
|
+
"src/landing.js",
|
|
39
41
|
"src/truncate.js",
|
|
40
42
|
"src/status.js",
|
|
41
43
|
"src/paths.js",
|
|
@@ -46,6 +48,8 @@
|
|
|
46
48
|
"src/web-app.js",
|
|
47
49
|
"src/side-chat.js",
|
|
48
50
|
"src/update-check.js",
|
|
51
|
+
"src/auto-update-worker.js",
|
|
52
|
+
"src/auto-update.js",
|
|
49
53
|
"web/dist/",
|
|
50
54
|
"skills/",
|
|
51
55
|
"README.md",
|
|
@@ -29,7 +29,7 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
29
29
|
|
|
30
30
|
## 长任务怎么等
|
|
31
31
|
|
|
32
|
-
一路活要跑二十分钟、一小时,正确的等法只有一种:**反复调 `wait_codex_workers`**,每次默认 2 分钟,回来看一眼 `still_running
|
|
32
|
+
一路活要跑二十分钟、一小时,正确的等法只有一种:**反复调 `wait_codex_workers`**,每次默认 2 分钟,回来看一眼 `still_running`,没完就再调。只想知道完没完,带 `compact: true`,每路一行。中间想省一点上下文就改调 `get_orchestration_overview`。
|
|
33
33
|
|
|
34
34
|
**不要自己写 shell 循环去 `grep` / `tail` `data/runs/<taskId>.jsonl`**,哪怕看起来更省事。原因:
|
|
35
35
|
|
|
@@ -59,7 +59,7 @@ wait_codex_workers (task_ids: [...], mode: "all")
|
|
|
59
59
|
|
|
60
60
|
## 看到 `update` 字段就转告用户
|
|
61
61
|
|
|
62
|
-
`get_orchestration_overview`、派单回执、`wait_codex_workers` 的返回里出现 `update` 且 `update_available: true`(或 `integrity_matches: false
|
|
62
|
+
`get_orchestration_overview`、派单回执、`wait_codex_workers` 的返回里出现 `update` 且 `update_available: true`(或 `integrity_matches: false`)时,当轮回复里告诉用户一句,内容照 `notice` 说。`auto_update.state` 是 `started`、`running` 或 `done` 时,新版已经在后台装或装好了,用户只需要重开会话;`install_command` 有值才让用户自己跑它再重启 Claude Code / Codex。只说一次,不要每轮重复。用户让你查时调 `check_for_update`。
|
|
63
63
|
|
|
64
64
|
## 读结果别把上下文撑爆
|
|
65
65
|
|
|
@@ -82,6 +82,22 @@ wait_codex_workers (task_ids: [...], mode: "all")
|
|
|
82
82
|
|
|
83
83
|
**别做**:一次 `limit: 200` 拉全量事件。那是几万 token。
|
|
84
84
|
|
|
85
|
+
## 收活:先看证据,再问,再改,再落
|
|
86
|
+
|
|
87
|
+
worker 回来以后按这个顺序,别跳:
|
|
88
|
+
|
|
89
|
+
1. `get_worker_result`:它说自己做了什么。
|
|
90
|
+
2. `get_worker_diff`:它实际做了什么。从 worktree 起点到工作区的全部改动,提交没提交都算,按文件给 patch;`maxChars` 管总量,`paths` 缩范围。它说过了不算,diff 对得上才算。
|
|
91
|
+
3. 对不上、看不懂为什么这么改:`ask_codex_worker` 带 `question` 问它。走的是 fork 出来的只读旁路,worker 自己的线程不动;fork 带着它的全部上下文,一句话能答。fork 没网络、没 MCP 工具,它自己知道,所以别问它"远端跑通了没"这类要联网才能答的事,问"你改了什么、为什么、在哪"。超过 `timeoutMs` 回 `running`,之后只带 `task_id` 再调一次拿答案。worker 被 `resume` 过以后,下一问自动换一个新 fork(返回 `refreshed: "worker_resumed"`);想强制换就 `fresh: true`。问完 `end: true` 删 fork。
|
|
92
|
+
4. 要它改:`resume_codex_worker`,提示词里写清问题在哪,让它改完 `git commit --amend --no-edit` 并进原来那个提交,保持一步一个提交。旁路只读,改东西永远走 resume。
|
|
93
|
+
5. 过了:`land_codex_worker` 把 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标脏了、分支不对、冲突,都会拒绝并原样退回,不留半截。
|
|
94
|
+
|
|
95
|
+
**worker 在默认的 `workspace-write` 沙箱里提交不了**:Codex 把 `.git` 设成只读,`git add` 就会报 `index.lock: Operation not permitted`。两条路,派单时定一条:
|
|
96
|
+
- 让它只改文件不提交,收活时 `land_codex_worker` 带 `commitMessage`,由 supervisor 在它的分支上替它提交一笔再落。一步一个提交照样成立。
|
|
97
|
+
- 要它自己提交(比如要 `--amend`),派单 `sandbox: "danger-full-access"`。
|
|
98
|
+
|
|
99
|
+
串行做活(第 N+1 步建立在第 N 步上)两种走法:落完第 N 步再派第 N+1 步;或者第 N+1 步派单时 `baseRef: "codex/<第 N 步的 task_id>"`,直接从它的分支开,最后只落最后一路。
|
|
100
|
+
|
|
85
101
|
## 中断了怎么接
|
|
86
102
|
|
|
87
103
|
先分清是哪种断:
|
|
@@ -91,6 +107,7 @@ wait_codex_workers (task_ids: [...], mode: "all")
|
|
|
91
107
|
| 想接着**同一个** Codex 会话干 | `resume_codex_worker` | 上下文不丢,`thread_id` 不变 |
|
|
92
108
|
| 想开**新会话**,带着老活的摘要干 | `create_codex_followup_worker` | 新线程,靠文本重述 |
|
|
93
109
|
| 主线程自己挂了,要找回那批活 | `get_session_works` | 按 `session_id` 列全部 |
|
|
110
|
+
| worker 变 `lost`(MCP 进程没了把它带走了) | `resume_codex_worker` | 同一线程接着干,worktree 里的改动都在 |
|
|
94
111
|
|
|
95
112
|
主线程重启后第一件事:`get_session_works({ session_id })`。一次拿到那批活的清单和状态,不用凭记忆猜。
|
|
96
113
|
|
|
@@ -111,7 +128,7 @@ wait_codex_workers (task_ids: [...], mode: "all")
|
|
|
111
128
|
**`failed` 和 `lost` 不是一回事**:
|
|
112
129
|
|
|
113
130
|
- `failed`:跑完了但没成。去看日志和 `error`。
|
|
114
|
-
- `lost`:进程被外部信号杀了,或者 MCP
|
|
131
|
+
- `lost`:进程被外部信号杀了,或者 MCP 进程自己没了(worker 是它的子进程)。worktree 里的改动都还在,`thread_id` 也在库里。**用 `resume_codex_worker` 接回同一个线程**,提示词里说"接着上次的做,先看工作区现状";它被杀时正在做的那一步可能要重做。只有没记到 `thread_id` 的老行才走 `create_codex_followup_worker` 重派。
|
|
115
132
|
|
|
116
133
|
`paused` 和 `blocked` 的 goal 不是结束,是等人管。`get_orchestration_overview` 会把它们列进 `needs_attention`。
|
|
117
134
|
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The detached half of auto-update.js. Runs outside the MCP process so a
|
|
3
|
+
// session that ends mid-install does not leave npm half way through.
|
|
4
|
+
//
|
|
5
|
+
// node auto-update-worker.js --version 0.7.0 --package-root <dir> [--registry <url>]
|
|
6
|
+
//
|
|
7
|
+
// Writes data/auto-update.json at every step so the server (and a human)
|
|
8
|
+
// can see what happened without a terminal: running -> done | failed | skipped.
|
|
9
|
+
import { execFile } from "node:child_process";
|
|
10
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
11
|
+
import { mkdir, open, readFile, rm, writeFile } from "node:fs/promises";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { promisify } from "node:util";
|
|
14
|
+
import { dataDir } from "./paths.js";
|
|
15
|
+
import { resolveCommand } from "./bin-resolver.js";
|
|
16
|
+
|
|
17
|
+
const run = promisify(execFile);
|
|
18
|
+
const PACKAGE_NAME = "codex-supervisor-mcp";
|
|
19
|
+
const statePath = join(dataDir, "auto-update.json");
|
|
20
|
+
const lockPath = join(dataDir, "auto-update.lock");
|
|
21
|
+
const LOCK_STALE_MS = 10 * 60 * 1000;
|
|
22
|
+
const NPM_TIMEOUT_MS = 10 * 60 * 1000;
|
|
23
|
+
|
|
24
|
+
function parseArgs(argv) {
|
|
25
|
+
const options = { version: null, packageRoot: null, registry: null };
|
|
26
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
27
|
+
const arg = argv[index];
|
|
28
|
+
if (arg === "--version") options.version = argv[++index];
|
|
29
|
+
else if (arg === "--package-root") options.packageRoot = argv[++index];
|
|
30
|
+
else if (arg === "--registry") options.registry = argv[++index];
|
|
31
|
+
else throw new Error(`Unknown argument: ${arg}`);
|
|
32
|
+
}
|
|
33
|
+
if (!options.version || !options.packageRoot) throw new Error("--version and --package-root are required");
|
|
34
|
+
return options;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function writeState(patch) {
|
|
38
|
+
await mkdir(dataDir, { recursive: true });
|
|
39
|
+
let current = {};
|
|
40
|
+
try {
|
|
41
|
+
current = JSON.parse(await readFile(statePath, "utf8"));
|
|
42
|
+
} catch {
|
|
43
|
+
// first write
|
|
44
|
+
}
|
|
45
|
+
const next = { ...current, ...patch, updated_at: new Date().toISOString() };
|
|
46
|
+
await writeFile(statePath, JSON.stringify(next, null, 2));
|
|
47
|
+
return next;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function alive(pid) {
|
|
51
|
+
try {
|
|
52
|
+
process.kill(pid, 0);
|
|
53
|
+
return true;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return error.code === "EPERM";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// One updater at a time. A lock whose process is gone, or that is older
|
|
60
|
+
// than LOCK_STALE_MS, is taken over.
|
|
61
|
+
async function acquireLock() {
|
|
62
|
+
await mkdir(dataDir, { recursive: true });
|
|
63
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
64
|
+
try {
|
|
65
|
+
const handle = await open(lockPath, "wx");
|
|
66
|
+
await handle.writeFile(JSON.stringify({ pid: process.pid, at: Date.now() }));
|
|
67
|
+
await handle.close();
|
|
68
|
+
return true;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code !== "EEXIST") throw error;
|
|
71
|
+
let holder = null;
|
|
72
|
+
try {
|
|
73
|
+
holder = JSON.parse(await readFile(lockPath, "utf8"));
|
|
74
|
+
} catch {
|
|
75
|
+
// unreadable lock counts as stale
|
|
76
|
+
}
|
|
77
|
+
const stale = !holder || !alive(holder.pid) || Date.now() - (holder.at ?? 0) > LOCK_STALE_MS;
|
|
78
|
+
if (!stale) return false;
|
|
79
|
+
await rm(lockPath, { force: true });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// npm as `node npm-cli.js`: steps over the npm.cmd shim on Windows and uses
|
|
86
|
+
// the npm that belongs to the node running this server. CODEX_SUPERVISOR_NPM
|
|
87
|
+
// points at another npm-cli.js (or any executable) when that is wrong.
|
|
88
|
+
function npmCommand() {
|
|
89
|
+
const override = process.env.CODEX_SUPERVISOR_NPM?.trim();
|
|
90
|
+
if (override) {
|
|
91
|
+
const target = resolveCommand(override);
|
|
92
|
+
return [target.cmd, ...target.prefixArgs];
|
|
93
|
+
}
|
|
94
|
+
const nodeDir = dirname(process.execPath);
|
|
95
|
+
const candidates = [
|
|
96
|
+
join(nodeDir, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js"),
|
|
97
|
+
join(nodeDir, "node_modules", "npm", "bin", "npm-cli.js")
|
|
98
|
+
];
|
|
99
|
+
const found = candidates.find((candidate) => existsSync(candidate));
|
|
100
|
+
if (found) return [process.execPath, found];
|
|
101
|
+
const target = resolveCommand("npm", { npmEntry: { pkg: "npm", bin: "bin/npm-cli.js" } });
|
|
102
|
+
return [target.cmd, ...target.prefixArgs];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function npm(args, { registry, timeout = NPM_TIMEOUT_MS } = {}) {
|
|
106
|
+
const [cmd, ...prefix] = npmCommand();
|
|
107
|
+
const full = [...prefix, ...args, "--no-fund", "--no-audit", "--loglevel=error"];
|
|
108
|
+
if (registry) full.push(`--registry=${registry}`);
|
|
109
|
+
const env = { ...process.env, CODEX_SUPERVISOR_NO_AUTO_UPDATE: "1" };
|
|
110
|
+
return run(cmd, full, { timeout, env, maxBuffer: 4 * 1024 * 1024, windowsHide: true });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function samePath(a, b) {
|
|
114
|
+
try {
|
|
115
|
+
return realpathSync(a) === realpathSync(b);
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function main() {
|
|
122
|
+
const options = parseArgs(process.argv.slice(2));
|
|
123
|
+
const stamp = { version: options.version, pid: process.pid, started_at: new Date().toISOString() };
|
|
124
|
+
|
|
125
|
+
if (!(await acquireLock())) {
|
|
126
|
+
console.log(`auto-update: another updater holds ${lockPath}; leaving it to that one`);
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
await writeState({ ...stamp, state: "running", reason: null, installed_path: null, exit_code: null, log: null });
|
|
131
|
+
|
|
132
|
+
const { stdout: rootOut } = await npm(["root", "-g"], { registry: options.registry, timeout: 60_000 });
|
|
133
|
+
const globalRoot = rootOut.trim();
|
|
134
|
+
const expected = join(globalRoot, PACKAGE_NAME);
|
|
135
|
+
if (!samePath(expected, options.packageRoot)) {
|
|
136
|
+
await writeState({
|
|
137
|
+
state: "skipped",
|
|
138
|
+
reason: `the running copy (${options.packageRoot}) is not npm's global install (${expected}); nothing was changed`
|
|
139
|
+
});
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let output = "";
|
|
144
|
+
try {
|
|
145
|
+
const result = await npm(["install", "-g", `${PACKAGE_NAME}@${options.version}`], { registry: options.registry });
|
|
146
|
+
output = `${result.stdout}${result.stderr}`;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
const tail = `${error.stdout ?? ""}${error.stderr ?? ""}`.trim().split("\n").slice(-12).join("\n");
|
|
149
|
+
await writeState({ state: "failed", reason: `npm install exited ${error.code ?? "?"}`, exit_code: error.code ?? null, log: tail });
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let installed = null;
|
|
154
|
+
try {
|
|
155
|
+
installed = JSON.parse(readFileSync(join(expected, "package.json"), "utf8")).version;
|
|
156
|
+
} catch {
|
|
157
|
+
// verified below
|
|
158
|
+
}
|
|
159
|
+
if (installed !== options.version) {
|
|
160
|
+
await writeState({
|
|
161
|
+
state: "failed",
|
|
162
|
+
reason: `npm reported success but ${expected} holds ${installed ?? "nothing"}, not ${options.version}`,
|
|
163
|
+
exit_code: 0,
|
|
164
|
+
log: output.trim().split("\n").slice(-12).join("\n")
|
|
165
|
+
});
|
|
166
|
+
return 1;
|
|
167
|
+
}
|
|
168
|
+
await writeState({ state: "done", reason: null, installed_path: expected, exit_code: 0, finished_at: new Date().toISOString() });
|
|
169
|
+
console.log(`auto-update: installed ${PACKAGE_NAME}@${options.version} at ${expected}`);
|
|
170
|
+
return 0;
|
|
171
|
+
} finally {
|
|
172
|
+
await rm(lockPath, { force: true });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
process.exitCode = await main();
|
|
178
|
+
} catch (error) {
|
|
179
|
+
try {
|
|
180
|
+
await writeState({ state: "failed", reason: error.message });
|
|
181
|
+
} catch {
|
|
182
|
+
// nothing left to record to
|
|
183
|
+
}
|
|
184
|
+
console.error(`auto-update: ${error.message}`);
|
|
185
|
+
process.exitCode = 1;
|
|
186
|
+
}
|