codex-supervisor-mcp 1.2.0 → 1.3.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.en.md CHANGED
@@ -18,6 +18,8 @@ codex-supervisor-mcp is an MCP server. A main thread (Claude Code, Codex, or any
18
18
 
19
19
  *30 seconds, recorded live: three workers in their own worktrees in parallel, then the main thread collects three diffs and makes one commit.*
20
20
 
21
+ > **This package is now [agent-supervisor-mcp](https://www.npmjs.com/package/agent-supervisor-mcp).** This is the last release under the old name. A global install needs nothing from you: it installs the new package in the background, replaces the MCP registration and the skill, and the next session starts on the new package with the state directory where it was. Where that does not happen (started through npx, a source checkout), run `npm install -g agent-supervisor-mcp`.
22
+ >
21
23
  > **Upgrading from 0.x to 1.x**: 39 tools became 14, with new names and arguments and no aliases for the old ones. Finish the workers in flight first, then reopen the session after upgrading so the new skill loads. The tool table is in the [reference](docs/reference.en.md); what changed is in the [1.0.0 release](https://github.com/zriyox/codex-supervisor-mcp/releases/tag/v1.0.0).
22
24
 
23
25
  ## What it solves
package/README.md CHANGED
@@ -18,6 +18,8 @@ codex-supervisor-mcp 是一个 MCP server。主线程(Claude Code、Codex 或
18
18
 
19
19
  *30 秒真跑:派 3 个 worker,各自 worktree 并行,主线程收 3 份 diff 合成一次 commit。*
20
20
 
21
+ > **这个包已改名为 [agent-supervisor-mcp](https://www.npmjs.com/package/agent-supervisor-mcp)。** 这是旧名字下的最后一版。全局安装的机器不用动手:它会在后台装好新包、换掉 MCP 注册和 skill,下次开会话就在新包上,状态目录原地不动。没自动换成的(npx 启动、源码检出)手动跑 `npm install -g agent-supervisor-mcp`。
22
+ >
21
23
  > **从 0.x 升级到 1.x**:工具从 39 个收成 14 个,名字和参数都换了,旧名不留别名。升级前先把在跑的 worker 收完,升级后重开会话让新 skill 生效。对照表在[参考手册](docs/reference.md),变更说明在 [1.0.0 release](https://github.com/zriyox/codex-supervisor-mcp/releases/tag/v1.0.0)。
22
24
 
23
25
  ## 解决什么
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-supervisor-mcp",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "mcpName": "io.github.zriyox/codex-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.",
@@ -22,15 +22,16 @@ const LOCK_STALE_MS = 10 * 60 * 1000;
22
22
  const NPM_TIMEOUT_MS = 10 * 60 * 1000;
23
23
 
24
24
  function parseArgs(argv) {
25
- const options = { version: null, packageRoot: null, registry: null };
25
+ const options = { version: null, packageRoot: null, registry: null, successor: null };
26
26
  for (let index = 0; index < argv.length; index += 1) {
27
27
  const arg = argv[index];
28
28
  if (arg === "--version") options.version = argv[++index];
29
29
  else if (arg === "--package-root") options.packageRoot = argv[++index];
30
30
  else if (arg === "--registry") options.registry = argv[++index];
31
+ else if (arg === "--successor") options.successor = argv[++index];
31
32
  else throw new Error(`Unknown argument: ${arg}`);
32
33
  }
33
- if (!options.version || !options.packageRoot) throw new Error("--version and --package-root are required");
34
+ if ((!options.version && !options.successor) || !options.packageRoot) throw new Error("--package-root and one of --version, --successor are required");
34
35
  return options;
35
36
  }
36
37
 
@@ -118,8 +119,49 @@ function samePath(a, b) {
118
119
  }
119
120
  }
120
121
 
122
+ // Installs the package this one was renamed to. Its own install step does the
123
+ // rest: registers it, removes this package's registration, retires its skill.
124
+ async function installSuccessor(options) {
125
+ const handoverPath = join(dataDir, "handover.json");
126
+ const record = async (patch) => {
127
+ await mkdir(dataDir, { recursive: true });
128
+ await writeFile(handoverPath, JSON.stringify({ ...patch, pid: process.pid, updated_at: new Date().toISOString() }, null, 2));
129
+ };
130
+ if (!(await acquireLock())) {
131
+ console.log(`handover: another installer holds ${lockPath}; leaving it to that one`);
132
+ return 0;
133
+ }
134
+ try {
135
+ await record({ state: "running" });
136
+ const { stdout: rootOut } = await npm(["root", "-g"], { registry: options.registry, timeout: 60_000 });
137
+ const globalRoot = rootOut.trim();
138
+ if (!samePath(join(globalRoot, PACKAGE_NAME), options.packageRoot)) {
139
+ await record({ state: "skipped", reason: `the running copy (${options.packageRoot}) is not npm's global install; nothing was changed` });
140
+ return 0;
141
+ }
142
+ try {
143
+ await npm(["install", "-g", `${options.successor}@latest`], { registry: options.registry });
144
+ } catch (error) {
145
+ const tail = `${error.stdout ?? ""}${error.stderr ?? ""}`.trim().split("\n").slice(-12).join("\n");
146
+ await record({ state: "failed", reason: `npm install exited ${error.code ?? "?"}`, log: tail });
147
+ return 1;
148
+ }
149
+ const installedAt = join(globalRoot, options.successor);
150
+ if (!existsSync(join(installedAt, "package.json"))) {
151
+ await record({ state: "failed", reason: `npm reported success but ${installedAt} is not there` });
152
+ return 1;
153
+ }
154
+ await record({ state: "done", installed_path: installedAt });
155
+ console.log(`handover: installed ${options.successor} at ${installedAt}`);
156
+ return 0;
157
+ } finally {
158
+ await rm(lockPath, { force: true });
159
+ }
160
+ }
161
+
121
162
  async function main() {
122
163
  const options = parseArgs(process.argv.slice(2));
164
+ if (options.successor) return installSuccessor(options);
123
165
  const stamp = { version: options.version, pid: process.pid, started_at: new Date().toISOString() };
124
166
 
125
167
  if (!(await acquireLock())) {
@@ -0,0 +1,125 @@
1
+ // This package was renamed to agent-supervisor-mcp. This is its last release
2
+ // under the old name, and its one job beyond working as before is to bring the
3
+ // machine over without anyone typing a command.
4
+ //
5
+ // At start-up, if this copy is a global npm install and the new package is
6
+ // not installed beside it, a detached worker runs
7
+ // `npm install -g agent-supervisor-mcp`. The new package's own install step
8
+ // then registers itself with the clients it finds, removes this package's
9
+ // registration and retires its skill. The session that is running keeps
10
+ // running; the next one starts on the new package. The state directory is
11
+ // not touched: the new package keeps using it.
12
+ //
13
+ // As with auto-update, only a copy npm installed globally is acted on. A
14
+ // checkout, an npx copy or a project dependency only gets the notice.
15
+ import { spawnProcess } from "../process.js";
16
+ import { closeSync, existsSync, openSync } from "node:fs";
17
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
18
+ import { dirname, join } from "node:path";
19
+ import { fileURLToPath } from "node:url";
20
+ import { dataDir } from "../paths.js";
21
+ import { autoUpdateDisabled } from "./auto-update.js";
22
+
23
+ export const SUCCESSOR = "agent-supervisor-mcp";
24
+ export const handoverStatePath = join(dataDir, "handover.json");
25
+ const logPath = join(dataDir, "auto-update.log");
26
+ const workerEntry = join(dirname(fileURLToPath(import.meta.url)), "auto-update-worker.js");
27
+ const RETRY_AFTER_MS = 24 * 60 * 60 * 1000;
28
+ const MANUAL = `npm install -g ${SUCCESSOR}`;
29
+
30
+ // Pure. Why nothing is installed automatically, or null when it should be.
31
+ export function handoverBlocker(update, env = process.env) {
32
+ if (!update) return "no update check result yet";
33
+ if (update.disabled) return "update check is disabled";
34
+ if (autoUpdateDisabled(env)) return "disabled by AGENT_SUPERVISOR_NO_AUTO_UPDATE";
35
+ if (env.CI) return "CI environment";
36
+ const source = update.installed?.source;
37
+ if (source !== "npm") return `installed from ${source ?? "an unknown source"}, not a global npm install`;
38
+ return null;
39
+ }
40
+
41
+ async function readState() {
42
+ try {
43
+ return JSON.parse(await readFile(handoverStatePath, "utf8"));
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+
49
+ function processAlive(pid) {
50
+ if (!pid) return false;
51
+ try {
52
+ process.kill(pid, 0);
53
+ return true;
54
+ } catch (error) {
55
+ return error.code === "EPERM";
56
+ }
57
+ }
58
+
59
+ async function launchWorker({ packageRoot, registry }) {
60
+ await mkdir(dataDir, { recursive: true });
61
+ const args = [workerEntry, "--successor", SUCCESSOR, "--package-root", packageRoot];
62
+ if (registry) args.push("--registry", registry);
63
+ const log = openSync(logPath, "a");
64
+ try {
65
+ const child = spawnProcess(process.execPath, args, {
66
+ detached: true, stdio: ["ignore", log, log], env: { ...process.env, AGENT_SUPERVISOR_NO_AUTO_UPDATE: "1" }, windowsHide: true
67
+ });
68
+ child.unref();
69
+ return child.pid;
70
+ } finally {
71
+ closeSync(log);
72
+ }
73
+ }
74
+
75
+ // Returns the handover record: { state: "done" | "started" | "running" | "failed" | "skipped", reason? }.
76
+ let queue = Promise.resolve();
77
+ export function maybeHandOver(update, options = {}) {
78
+ const next = queue.then(() => decide(update, options));
79
+ queue = next.catch(() => {});
80
+ return next;
81
+ }
82
+
83
+ async function decide(update, { env = process.env, launch = launchWorker, exists = existsSync } = {}) {
84
+ const blocker = handoverBlocker(update, env);
85
+ if (blocker) return { state: "skipped", reason: blocker };
86
+ // npm puts global packages side by side.
87
+ const successorRoot = join(dirname(update.installed.path), SUCCESSOR);
88
+ if (exists(join(successorRoot, "package.json"))) return { state: "done", installed_path: successorRoot };
89
+
90
+ const prior = await readState();
91
+ if (prior && ["started", "running"].includes(prior.state) && processAlive(prior.pid)) return prior;
92
+ const age = prior?.updated_at ? Date.now() - Date.parse(prior.updated_at) : Number.POSITIVE_INFINITY;
93
+ // A failed attempt is not repeated on every start; once a day is enough to get past a registry outage.
94
+ if (prior?.state === "failed" && age < RETRY_AFTER_MS) return prior;
95
+
96
+ let record;
97
+ try {
98
+ const pid = await launch({ packageRoot: update.installed.path, registry: env.AGENT_SUPERVISOR_REGISTRY?.trim() || null });
99
+ record = { state: "started", pid };
100
+ } catch (error) {
101
+ record = { state: "failed", reason: `could not start the installer: ${error.message}` };
102
+ }
103
+ try {
104
+ await mkdir(dataDir, { recursive: true });
105
+ await writeFile(handoverStatePath, JSON.stringify({ ...record, updated_at: new Date().toISOString() }, null, 2));
106
+ } catch {
107
+ // the worker rewrites it anyway
108
+ }
109
+ return record;
110
+ }
111
+
112
+ // What every tool result says about it. This package always has something to say.
113
+ export function handoverNotice(record) {
114
+ const renamed = `codex-supervisor-mcp is now ${SUCCESSOR}`;
115
+ if (record?.state === "done") {
116
+ return { renamed_to: SUCCESSOR, state: "done",
117
+ notice: `${renamed}, and it has been installed and registered. Start a new session (restart the MCP client) to use it; its tools are the same. Afterwards: npm uninstall -g codex-supervisor-mcp` };
118
+ }
119
+ if (record?.state === "started" || record?.state === "running") {
120
+ return { renamed_to: SUCCESSOR, state: record.state, notice: `${renamed}. It is being installed in the background; the next session starts on it once the install finishes.` };
121
+ }
122
+ const why = record?.reason ? ` (not installed automatically: ${record.reason})` : "";
123
+ return { renamed_to: SUCCESSOR, state: record?.state ?? "pending", install_command: MANUAL,
124
+ notice: `${renamed}. This is the last release under the old name. Run \`${MANUAL}\` and restart the MCP client${why}.` };
125
+ }
@@ -1,4 +1,5 @@
1
1
  import { maybeAutoUpdate } from "../../infra/update/auto-update.js";
2
+ import { handoverNotice, maybeHandOver } from "../../infra/update/handover.js";
2
3
  import { checkForUpdate, updateNotice } from "../../infra/update/update-check.js";
3
4
 
4
5
  // Nobody should keep running an old build without hearing about it. The
@@ -10,21 +11,26 @@ export let updateState = null;
10
11
  // The last word from auto-update.js: null until a check found a newer
11
12
  // version, then started | running | done | failed | skipped.
12
13
  export let autoUpdateState = null;
14
+ // The package was renamed; handover.js installs the new one. Null until the first check.
15
+ export let handoverState = null;
13
16
  export async function refreshUpdateState({ force = false } = {}) {
14
17
  try {
15
18
  updateState = await checkForUpdate({ force });
16
19
  autoUpdateState = await maybeAutoUpdate(updateState);
17
- const notice = updateNotice(updateState, autoUpdateState)?.notice;
18
- if (notice) process.stderr.write(`[codex-supervisor] ${notice}\n`);
20
+ handoverState = await maybeHandOver(updateState);
21
+ if (!updateState.disabled) process.stderr.write(`[codex-supervisor] ${handoverNotice(handoverState).notice}\n`);
19
22
  } catch (error) {
20
23
  process.stderr.write(`[codex-supervisor] update check failed: ${error.message}\n`);
21
24
  }
22
25
  return updateState;
23
26
  }
24
27
 
25
- // The short form for tool results: null when the install is current.
28
+ // The short form for tool results. The rename is always said; a newer release
29
+ // of this package is not worth a line beside it.
26
30
  export function updateField() {
27
- return updateNotice(updateState, autoUpdateState);
31
+ // With the update check switched off the server says nothing unasked, the rename included.
32
+ if (!updateState || updateState.disabled) return updateNotice(updateState, autoUpdateState);
33
+ return handoverNotice(handoverState);
28
34
  }
29
35
 
30
36
  // Spread into a result: adds `update` only when there is something to say.