@balababa/codex-mesh 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,158 +1,343 @@
1
1
  # Codex Mesh
2
2
 
3
- Codex Mesh 提供三个入口:
3
+ **让分散在不同机器上的原生 Codex 会话互相发现、通信与协作。**
4
4
 
5
- | 组件 | 入口 | 用途 |
6
- | --- | --- | --- |
7
- | Mesh 服务端 | `codex-mesh hub` | 部署在公网服务器,提供认证、成员登记和消息路由 |
8
- | 普通 Codex 接入 | Mesh MCP + `$codex-mesh` Skill | 普通 `codex` 加入集群、查询、收发消息和自动唤醒 |
9
- | 集群管理工具 | `codex-mesh agents`,可选 `codex-mesh tui` | 查看全网明确登记的 Agent 和状态 |
5
+ Codex Mesh 不是一种新的 Agent,而是给原本独立的 Codex Agent 加上网络能力:
6
+ 你继续用普通的 `codex`,只是它现在能看见并调用其他机器上的同伴。
7
+
8
+ ![Codex Mesh 架构总览](docs/assets/architecture.svg)
10
9
 
11
- 日常工作继续用普通 `codex`。每台机器的后台 Node 连接自己的 native daemon;
12
- Hub 不参与推理或任务调度。Agent 使用原生 Thread ID,只有显式加入的会话才会
13
- 对外展示。当前公网服务器通过认证 SSH 隧道提供远程服务,Hub 监听 loopback。
10
+ ## 这是什么
14
11
 
15
- 从 [三个入口的部署与使用说明](docs/PRODUCTS.md) 开始。
12
+ | 组件 | 入口 | 作用 |
13
+ | --- | --- | --- |
14
+ | **Mesh Hub**(服务端) | `codex-mesh hub` | 认证、成员登记、消息路由、持久收件箱。**不做推理、不调度任务** |
15
+ | **Mesh Node**(每台机器) | 后台常驻进程 | 连接本机 Codex daemon,向 Hub 发起出站连接 |
16
+ | **Mesh MCP + Skill** | `$codex-mesh` | 让普通 `codex` 会话加入集群、发现同伴、收发消息 |
17
+ | **集群管理** | `codex-mesh agents` / 网页面板 | 查看全网已登记的 Agent 与状态 |
16
18
 
17
- The core MVP has run on three machines: ali hosts the Hub, and ascend and gpuplct
18
- host Nodes. Real Codex models exchanged an attributed request and result, created
19
- a remote Agent with an idempotency key, and renamed a remote native thread. The
20
- native command center displayed both hosts and opened a live remote conversation.
21
- An existing thread kept its ID, history, permissions, and original tools while
22
- gaining Mesh tools on an opted-in shared App Server.
19
+ ### 三条设计原则
23
20
 
24
- See the [measured test report](docs/TEST_REPORT.md), [requirements audit](docs/REQUIREMENTS_AUDIT.md),
25
- and [progress log](docs/PROGRESS.md) for what was verified and what remains. The
26
- MVP does not yet cover generalized file transfer or all combinations of native
27
- commands and recovery behavior. Stock MCP queue/steer has separate opt-in
28
- semantics and measured coverage described in docs/STOCK_CODEX.md. Small
29
- operator-published artifacts can be downloaded through an opt-in bounded reader;
30
- see [artifact exports](docs/ARTIFACTS.md).
21
+ - **无主(Masterless)**:所有 Agent 地位平等,Hub 只是认证过的基础设施。
22
+ - **会话原生(Session-native)**:Codex 原生 Thread ID 就是 Agent 的唯一身份。重命名不改变它,Fork 后的新会话有独立身份。
23
+ - **本地优先(Local-first)**:Mesh 是可选能力。Hub 不可用时,本地 Codex 照常工作。
31
24
 
32
- ## npm 安装与普通用户接入
25
+ ### 边界(重要)
33
26
 
34
- 当前源码版本为 **0.4.0**,新增浏览器授权机器接入。Rust Hub/Node/MCP/管理命令、
35
- 启动器和 Skill 使用同一版本。普通用户不需要 Rust、源码仓库或本地编译。
36
- 支持 Linux x86_64、glibc >=2.35,Node.js >=24.19.0。
27
+ - **只有显式加入的会话才会对外展示。** 安装、setup、doctor、打开网页都不会登记任何会话,也不会读取私有历史。
28
+ - **各机器使用自己的 Codex 认证、模型、沙箱与审批策略。** Codex 登录凭据从不上传到 Hub。
29
+ - **Hub 强制只监听 loopback。** 公网访问必须经 SSH 隧道或已验证的 HTTPS 反向代理。
37
30
 
38
- 包名为 **`@balababa/codex-mesh`**。npm 已发布版本为 **0.3.0**;0.4.0 本轮
39
- 不发布,请使用匹配的本地产物,并先升级 Hub:
31
+ ## 快速开始
40
32
 
41
33
  ```sh
42
- npm install -g /absolute/path/balababa-codex-mesh-0.4.0.tgz
34
+ # 服务端(详见下文"部署服务端")
35
+ docker compose up -d --build
36
+
37
+ # 客户端:每台已装 Codex 的机器
38
+ npm install -g @balababa/codex-mesh@0.5.1
43
39
  codex-mesh setup
44
40
  codex-mesh doctor
45
41
  codex
46
42
  ```
47
43
 
48
- 首次 setup 填写 Hub 地址后显示授权链接和确认码。在浏览器打开链接,核对机器信息,
49
- 输入现有管理 Token 并批准,终端自动保存本机独立节点凭据、继续安装 Node、MCP 和 Skill。
50
- 管理 Token 不会交给接入机器。Hub 管理员须先显式给管理凭据开启节点接入授权权限;
51
- 已有节点凭据直接复用,脚本仍可使用 `--node-token-file`。
44
+ ---
45
+
46
+ ## 客户端:安装与使用
47
+
48
+ ![客户端接入流程](docs/assets/client-onboarding.svg)
49
+
50
+ ### 前提
52
51
 
53
- 在新的普通 Codex 会话中输入 `$codex-mesh 加入 Mesh`。安装、网页授权和 doctor
54
- 不登记任何 Codex 会话。管理端保存配置后,直接 `codex-mesh agents`。
52
+ - Linux x86_64,glibc ≥ 2.35,Node.js ≥ 24.19.0
53
+ - 机器已安装 Codex 并正常登录,**Codex daemon 正在运行**(daemon 版本 0.173.x / 0.174.x 为已验证范围)
54
+ - 不需要 Rust、编译器或本仓库源码
55
55
 
56
- 同一个本地 tarball 可用于 npx 按需启动 MCP:
56
+ ### 1. 安装
57
57
 
58
58
  ```sh
59
- npx --yes --package=/absolute/path/balababa-codex-mesh-0.4.0.tgz \
60
- codex-mesh mcp --socket /absolute/private/mesh/mcp.sock
59
+ npm install -g @balababa/codex-mesh@0.5.1
61
60
  ```
62
61
 
63
- 完整安装、管理授权开关、非交互配置、doctor 与升级说明见
64
- [INSTALL.md](docs/INSTALL.md)。默认使用 systemd user 服务;容器可显式使用
65
- `--service process`。升级 npm 本身不会重启 Node 或用户 daemon,改变配置/版本时
66
- 需要在会话退出 Mesh 后重新 setup。
62
+ 包内含预编译 Rust 二进制、启动器和 Skill。npm 包名是 `@balababa/codex-mesh`,命令是 `codex-mesh`。
67
63
 
68
- ## Build
64
+ > 无关的同名未限定包 `codex-mesh` 不是本项目。Hub 与客户端版本必须一致。
65
+
66
+ ### 2. 运行 setup,浏览器授权本机
69
67
 
70
68
  ```sh
71
- cargo build --locked
72
- cargo test --workspace --locked
73
- cargo run -- --help
69
+ codex-mesh setup
74
70
  ```
75
71
 
76
- Mesh services require Rust 1.95 or newer. Building the separate native TUI patch
77
- uses the upstream pinned Rust 1.99.1 toolchain without changing your default:
72
+ 交互式 setup 会依次:
73
+
74
+ 1. 询问 Hub 地址和本机显示名称(默认主机名)
75
+ 2. 打印一个短时效授权链接和确认码
76
+ 3. 你在**任意设备**的浏览器打开链接,核对机器信息与确认码,输入管理 Token 并批准
77
+ 4. 终端自动保存本机独立节点凭据,继续安装后台 Node、MCP 和 Skill
78
+
79
+ 管理 Token **不会**保存到本机,浏览器授权只是签发本机自己的节点凭据。授权链接 10 分钟有效;中断后重跑 setup 可续接。
80
+
81
+ 如果已有节点 Token 被当前 Hub 返回 401,setup 会询问是否重新授权;输入 `y` 或 `yes` 才继续,直接回车会保留旧 Token。显式指定 Token 文件、非交互模式、网络错误和版本不匹配不会触发该提示。
82
+
83
+ ### 3. 自检
78
84
 
79
85
  ```sh
80
- ./scripts/prepare-upstream.sh
81
- ./scripts/build-native.sh
86
+ codex-mesh doctor
87
+ ```
88
+
89
+ 检查版本、凭据、Hub 连通、Codex daemon、Node 服务、MCP 注册与 Skill。**不登记会话、不触发推理。**
90
+
91
+ ### 4. 在普通 codex 里显式加入
92
+
93
+ 在允许的项目目录打开普通 `codex`,输入:
94
+
95
+ ```text
96
+ $codex-mesh 加入 Mesh
97
+ ```
98
+
99
+ 只有这一步才会登记当前会话。日常对话仍然是原生 Codex 体验。
100
+
101
+ ### 5. 使用
102
+
103
+ ```text
104
+ $codex-mesh 列出在线机器和 Agent。
105
+ 给 <名字或原生 session_id> 发消息:帮我检查这个问题……
106
+ 查看 Mesh 收件箱。
107
+ 退出 Mesh。
82
108
  ```
83
109
 
84
- Mesh uses an independent `codex-mesh` executable and never replaces installed
85
- `codex`. A Node needs its machine's normally authenticated Codex CLI; the Hub does
86
- not. The pinned official source is described in docs/UPSTREAM_BASELINE.json.
87
- Upstream Apache-2.0 LICENSE and NOTICE are retained.
110
+ 底层是 8 个 Mesh MCP 工具:
111
+
112
+ | 工具 | 用途 |
113
+ | --- | --- |
114
+ | `mesh_join` / `mesh_leave` | 显式加入 / 退出(退出保留原生会话) |
115
+ | `mesh_whoami` | 读取本会话的原生身份 |
116
+ | `mesh_list_nodes` / `mesh_list_agents` / `mesh_get_status` | 发现机器、同伴与集群状态 |
117
+ | `mesh_send_message` | 发消息给同伴 |
118
+ | `mesh_get_messages` | 读取本会话的持久收件箱 |
88
119
 
89
- ## Development safety
120
+ 消息投递语义:
90
121
 
91
- Use independent runtime directories, allowlisted test workspaces and per-Node
92
- credentials. The initial Hub binds to loopback and must be reached via an SSH
93
- tunnel or certificate-verified TLS. Codex login credentials are never uploaded to
94
- the Hub. Do not enable unrestricted execution for tests or enroll private threads.
122
+ - `request` + `enqueue`(默认):空闲同伴会被唤醒,忙的排队等当前轮次结束
123
+ - `request` + `steer`:立即补充到正在进行的轮次(需要接收方已选择加入)
124
+ - `notify`:只进收件箱,不唤醒
125
+ - 回复用 `reply` / `result` + `notify`,避免自动回信循环
95
126
 
96
- The authorized test-fleet deployment and status commands are:
127
+ ### 脚本化与非交互安装
97
128
 
98
129
  ```sh
99
- cargo build --release --locked
100
- python3 scripts/deploy-test-cluster.py --apply --native-package artifacts/native/package
101
- python3 scripts/deploy-test-cluster.py --status
102
- target/release/codex-mesh rpc --hub http://127.0.0.1:19010 \
103
- --token-file .mesh/cluster/client.token mesh.list_nodes
130
+ codex-mesh setup --non-interactive \
131
+ --hub https://mesh.example.com \
132
+ --node-token-file /private/received/laptop.token \
133
+ --node-name laptop \
134
+ --allow-dir /absolute/project/one --allow-dir /absolute/project/two
104
135
  ```
105
136
 
106
- The script provisions only project-owned user services, credentials and allowlisted
107
- test workspaces on `ali`, `gpuplct`, and the local machine. Read
108
- [deployment instructions](docs/DEPLOYMENT.md) before running it on another setup.
109
- The native UI launcher is:
137
+ Token 走私有文件,**不要**把 Token 值作为命令行参数。首次 setup 的允许目录默认是用户主目录;用 `--allow-dir` 收窄范围。
138
+
139
+ ### 容器或无 systemd 环境
110
140
 
111
141
  ```sh
112
- target/release/codex-mesh tui --hub http://127.0.0.1:19010 \
113
- --token-file .mesh/cluster/client.token --node ascend \
114
- --codex artifacts/native/package/bin/codex-mesh-native -- agents
142
+ codex-mesh setup --service process
115
143
  ```
116
144
 
117
- Press F6 to switch between the global and local roster. Select a session and
118
- press Enter to use its ordinary Codex conversation. Within a connected session,
119
- `/mesh nodes`, `/mesh agents`, `/mesh inbox` and `/status` show cluster state.
120
- `/send <session-id-or-name> <message>` sends an ordinary message;
121
- `/spawn <node> <absolute-directory> <name> [initial task]` creates a real native
122
- Agent in an allowed destination directory. Quote names or directories with spaces.
123
- Existing sessions are published only after explicit enrollment; the
124
- [protocol guide](docs/PROTOCOL.md)
125
- explains shared App Server attachment and the opt-in for attaching model tools.
126
- `codex-mesh local` launches ordinary local Codex without contacting the Hub.
127
- Read [AGENTS.md](AGENTS.md) before contributing.
145
+ 默认使用 systemd user 服务。`--service process` 是显式的脱离进程后端,重启后需要重新 setup。
128
146
 
129
- ## Ordinary Codex through MCP
147
+ ### 集群管理(不需要 Codex)
130
148
 
131
- An additional opt-in path lets an unmodified Codex session use Mesh through a
132
- private local MCP adapter while its Node attaches to the same native daemon.
133
- Explicit joins preserve the native thread ID; request messages can wake the
134
- original thread through the native queue, with generated source headers.
135
- Use `codex-mesh setup` to install the included
136
- [codex-mesh Skill](skills/codex-mesh/SKILL.md), provision the local Node connection
137
- and register MCP. The older `scripts/install-stock-skill.py` remains a source-tree
138
- operator helper, not the npm user flow. In a new ordinary `codex` session, ask:
149
+ 只做管理、不跑 Agent 的机器:
139
150
 
140
- ```text
141
- $codex-mesh 加入 Mesh,列出在线机器和 Agent。
151
+ ```sh
152
+ codex-mesh setup --manager --non-interactive \
153
+ --hub https://mesh.example.com --admin-token-file /private/manager.token
154
+ codex-mesh agents
155
+ codex-mesh agents --json
142
156
  ```
143
157
 
144
- See [ordinary Codex setup and delivery semantics](docs/STOCK_CODEX.md).
145
- Building alone does not install the Skill, register MCP or switch a deployment.
158
+ ---
159
+
160
+ ## 部署服务端(Hub)
161
+
162
+ ![服务端容器部署](docs/assets/server-docker.svg)
163
+
164
+ Hub 是**纯基础设施**:不需要安装 Codex、不需要登录模型、不做推理。
165
+
166
+ ### 方式一:Docker Compose(推荐)
167
+
168
+ Docker 配置随 GitHub 源码 Release 分发,不包含在 npm 运行包内。先下载或克隆与客户端相同的 `v0.5.1` 源码标签,再执行以下命令。
169
+
170
+ Hub 强制只监听 loopback。容器方案让 Hub 监听容器内 `127.0.0.1:9010`,由共享网络命名空间的 Caddy 终止 TLS 并对外提供 80/443。**Hub 的 9010 端口不发布到宿主机。**
171
+
172
+ ```sh
173
+ cd deploy/docker
174
+ cp .env.example .env
175
+ # 编辑 .env:填入真实域名和 ACME 邮箱
176
+ ```
177
+
178
+ ```sh
179
+ docker compose up -d --build
180
+ docker compose ps
181
+ ```
182
+
183
+ 首次启动时 entrypoint 会自动签发一个管理凭据(名为 `web-manager`),并开启它的节点接入授权权限。取出这个私有 Token 文件:
184
+
185
+ ```sh
186
+ docker compose exec hub cat /var/lib/codex-mesh/manager.token > manager.token
187
+ chmod 600 manager.token
188
+ ```
189
+
190
+ 用它登录 `https://你的域名/` 的网页管理面板,或在浏览器授权新机器时输入。
191
+
192
+ 域名与网络前置条件:
193
+
194
+ - 域名 A 记录指向本服务器公网 IP
195
+ - 云安全组与主机防火墙放行 TCP 80 / 443
196
+ - **保持 9010 端口私有**
197
+
198
+ ### 已有宿主机反向代理(多网站服务器)
199
+
200
+ 如果宿主机 Caddy 已经占用 80/443 并托管其他网站,不要停止或替换它。让现有 Mesh 站点继续 `reverse_proxy 127.0.0.1:9010`,然后只容器化 Hub:
201
+
202
+ ```sh
203
+ cd deploy/docker
204
+ cp .env.example .env
205
+ # 在 .env 中设置 MESH_PUBLIC_URL=https://你的域名
206
+
207
+ docker compose -f docker-compose.host-caddy.yml up -d --build
208
+ docker compose -f docker-compose.host-caddy.yml exec hub \
209
+ cat /var/lib/codex-mesh/manager.token > manager.token
210
+ chmod 600 manager.token
211
+ ```
212
+
213
+ `docker-compose.host-caddy.yml` 不启动容器 Caddy,也不发布任何端口;Hub 通过 `network_mode: host` 与宿主机共享回环地址。它保留非 root 用户、文件系统隔离和数据卷,但网络命名空间隔离弱于默认方案。宿主机反代配置可参考 `deploy/public/Caddyfile.example`,其他站点无需修改或重载。
214
+
215
+ ### 签发更多凭据
216
+
217
+ ```sh
218
+ # 管理凭据(网页面板 / 集群管理用)
219
+ docker compose exec hub codex-mesh credentials issue \
220
+ --credentials /var/lib/codex-mesh/credentials.json \
221
+ --token-file /var/lib/codex-mesh/another-manager.token \
222
+ --name another-manager --role client
223
+
224
+ # 节点凭据(脚本化接入用;浏览器授权流程不需要)
225
+ docker compose exec hub codex-mesh credentials issue \
226
+ --credentials /var/lib/codex-mesh/credentials.json \
227
+ --token-file /var/lib/codex-mesh/laptop.token \
228
+ --name laptop --role node
229
+ ```
230
+
231
+ Hub 每次认证都重新读取凭据文件,**新增授权无需重启**。Token 通过私有通道传到目标机器。
232
+
233
+ ### 升级与备份
234
+
235
+ ```sh
236
+ # 使用宿主机反代模式时,以下 docker compose 命令都要加上
237
+ # -f docker-compose.host-caddy.yml。
238
+ backup="$HOME/.local/share/codex-mesh-backups/$(date +%Y%m%d-%H%M%S)"
239
+ install -d -m 700 "$backup"
240
+
241
+ # SQLite 使用 WAL;停止 Hub 后再复制,不能依赖运行中直接 tar 数据目录。
242
+ docker compose stop hub
243
+ docker compose cp hub:/var/lib/codex-mesh/. "$backup/"
244
+ docker compose up -d --build
245
+ ```
246
+
247
+ SQLite 与凭据都在 `hub-state` 卷里,重建镜像不会丢失,**升级不要运行 `down -v`**。重启 Hub 前确认没有进行中的任务;Node 会自动重连,网页内存会话需要重新登录。保留备份和旧镜像以便回滚。
248
+
249
+ ### 方式二:裸机部署
250
+
251
+ ```sh
252
+ codex-mesh hub --bind 127.0.0.1:9010 \
253
+ --public-url https://mesh.example.com \
254
+ --database /private/mesh-hub/hub.sqlite \
255
+ --credentials /private/mesh-hub/credentials.json
256
+ ```
257
+
258
+ `--public-url` 是浏览器授权链接使用的可信来源,必须是已验证的 HTTPS 源(本地可用 loopback HTTP)。私有目录 0700、凭据文件 0600。
259
+
260
+ 全新 Hub 先签发管理凭据:
261
+
262
+ ```sh
263
+ codex-mesh credentials issue --credentials /private/mesh-hub/credentials.json \
264
+ --token-file /private/mesh-hub/manager.token --name web-manager --role client
265
+ codex-mesh credentials allow-node-enrollment \
266
+ --credentials /private/mesh-hub/credentials.json --name web-manager
267
+ ```
268
+
269
+ ### 方式三:SSH 隧道(无公网 TLS 时)
270
+
271
+ ```sh
272
+ ssh -N -o ExitOnForwardFailure=yes \
273
+ -L 127.0.0.1:19010:127.0.0.1:9010 your-hub-host
274
+ ```
275
+
276
+ 客户端 `setup` 时 Hub 地址填 `http://127.0.0.1:19010`。此方式下浏览器授权不可用,需用 `--node-token-file`。
277
+
278
+ ### 验证
279
+
280
+ ```sh
281
+ # 应返回 Hub 健康信息
282
+ curl --fail --show-error https://mesh.example.com/health
283
+ # 应返回 401
284
+ curl -s -o /dev/null -w '%{http_code}\n' https://mesh.example.com/v1/node/check
285
+ ```
286
+
287
+ 不要用 `curl -k` 当作验收。健康检查通过不代表 WebSocket 路由或唤醒机制可用,完整验收见 [PUBLIC_HUB.md](docs/PUBLIC_HUB.md)。
288
+
289
+ ---
290
+
291
+ ## 网页管理面板
292
+
293
+ Hub 根路径 `/` 内置管理面板:
294
+
295
+ - 使用**管理凭据**登录(不是节点凭据),成功后设置 7 天 HttpOnly 会话 Cookie
296
+ - 节点与 Agent 按所属关系分组,可展开、搜索
297
+ - 删除 Agent 只是让它退出 Mesh;删除 Node 会撤销服务端凭据并断开连接
298
+ - **两者都不删除原生 Codex 会话与历史**
299
+ - 网页不启动推理、不读取私有会话历史
300
+
301
+ ---
302
+
303
+ ## 已验证状态与限制
304
+
305
+ 核心 MVP 已在三台机器上真实运行:ali 部署 Hub,ascend 与 gpuplct 运行 Node。真实 Codex 模型完成过带来源标注的请求与结果交换、带幂等键的远程 Agent 创建、远程原生线程重命名。已有线程在加入后保留原有 ID、历史、权限与工具。
306
+
307
+ **尚未覆盖**:通用文件传输、原生命令与恢复行为的全部组合。Stock MCP 的 queue/steer 是独立的可选语义,覆盖范围见 [STOCK_CODEX.md](docs/STOCK_CODEX.md)。小型操作者发布产物可通过可选的受限读取器下载,见 [ARTIFACTS.md](docs/ARTIFACTS.md)。
308
+
309
+ 容器部署方案(`deploy/docker/`)已实测:镜像构建、首启自动签发凭据、Hub 仅回环监听、Caddy TLS 反代、未认证请求返回 401、宿主机无法直连 9010、Node 经 TLS 的 WebSocket 握手。**尚未实测**:真实公网域名上的 ACME 证书签发、多日运行、生产流量。
310
+
311
+ 详见 [测试报告](docs/TEST_REPORT.md)、[需求审计](docs/REQUIREMENTS_AUDIT.md)、[进度日志](docs/PROGRESS.md)。
312
+
313
+ ## 从源码构建
314
+
315
+ ```sh
316
+ cargo build --locked
317
+ cargo test --workspace --locked
318
+ cargo run -- --help
319
+ ```
320
+
321
+ 需要 Rust 1.95 或更新版本。保留的原生 App Server 补丁及其可复现构建见 [upstream analysis](docs/UPSTREAM_ANALYSIS.md)。
322
+
323
+ `codex-mesh` 是独立可执行文件,**从不替换已安装的 `codex`**。Node 需要本机正常认证的 Codex CLI;Hub 不需要。上游基线见 [UPSTREAM_BASELINE.json](docs/UPSTREAM_BASELINE.json),Apache-2.0 LICENSE 与 NOTICE 已保留。
324
+
325
+ ## 文档索引
326
+
327
+ | 文档 | 内容 |
328
+ | --- | --- |
329
+ | [INSTALL.md](docs/INSTALL.md) | npm 安装完整选项、doctor、升级与排错 |
330
+ | [PRODUCTS.md](docs/PRODUCTS.md) | 三个入口的底层命令与配置结构 |
331
+ | [PUBLIC_HUB.md](docs/PUBLIC_HUB.md) | 公网域名、Caddy、浏览器授权与验收 |
332
+ | [DEPLOYMENT.md](docs/DEPLOYMENT.md) | 已授权的三机测试集群部署脚本 |
333
+ | [ARCHITECTURE.md](docs/ARCHITECTURE.md) | 系统架构与安全边界 |
334
+ | [PROTOCOL.md](docs/PROTOCOL.md) | 网络与消息协议 |
335
+ | [SECURITY.md](docs/SECURITY.md) | 安全模型 |
336
+ | [STOCK_CODEX.md](docs/STOCK_CODEX.md) | 普通 Codex MCP 接入与投递语义 |
337
+ | [TEST_REPORT.md](docs/TEST_REPORT.md) | 真实测试结果与未覆盖范围 |
146
338
 
147
- ## 域名和网页管理
339
+ ## 开发安全
148
340
 
149
- 0.3.0 Hub 内置网页版只读集群概览,入口为 `/`。网页使用独立管理凭据,
150
- 列出所有明确登记的 Agent 和节点,不启动推理、不读取私有会话历史。
151
- 凭据仅保留在页面内存中;支持搜索、分页和刷新。Hub 仍监听回环地址,
152
- 公网域名由 HTTPS 反向代理承接。配置模板与验收步骤见
153
- [PUBLIC_HUB.md](docs/PUBLIC_HUB.md)。真实域名、TLS 和公网连通性需分别验证。
341
+ 使用独立运行目录、白名单测试工作区和每节点独立凭据。Hub 绑定 loopback,经 SSH 隧道或证书验证的 TLS 访问。Codex 登录凭据从不上传。不要为测试开启无限制执行,也不要登记私有线程。
154
342
 
155
- For an explicitly chosen daemon outside the default verified version range, use
156
- `codex-mesh setup --skip-daemon-version-check`. The choice persists for setup and
157
- doctor; `setup --check-daemon-version` restores checking. Socket security and
158
- runtime checks remain enabled. See [installation options](docs/INSTALL.md).
343
+ 贡献前请阅读 [AGENTS.md](AGENTS.md)。
package/docs/INSTALL.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # npm installation and ordinary Codex setup
2
2
 
3
- Source release version: **0.4.0** (npm, Rust binary and Skill metadata).
3
+ Source release version: **0.5.1** (npm, Rust binary and Skill metadata).
4
4
 
5
5
  The npm package name is **`@balababa/codex-mesh`**, using the maintainer's
6
6
  personal scope. The operator selected this name after the prior organization
7
7
  scope failed publication with `Scope not found`. The command remains `codex-mesh`.
8
- Version 0.3.0 is published (registry metadata checked on 2026-12-05).
9
- Source 0.4.0 adds browser-authorized node onboarding and is not published in this
10
- change. Use its matching local tarball and upgrade the Hub deliberately first.
8
+ Version 0.5.1 is published to npm and the matching Linux x86_64 GNU Hub binary
9
+ is attached to GitHub Release v0.5.1 (verified on 2026-12-06). Upgrade the Hub
10
+ deliberately before connecting 0.5.1 nodes.
11
11
  The unrelated unscoped `codex-mesh` package is not this implementation.
12
12
 
13
13
  ## Supported runtime
@@ -20,17 +20,16 @@ libgcc); consumers need no Rust/compiler/source tree. Ordinary Codex daemon
20
20
  0.173.x/0.174.x is the checked compatibility range; 0.174.0 is the real npm
21
21
  acceptance target. The daemon must already be running and normally authenticated.
22
22
 
23
- For this 0.4.0 build, install the matching local artifact:
23
+ Install the published release:
24
24
 
25
25
  ```sh
26
- npm install -g /absolute/path/balababa-codex-mesh-0.4.0.tgz
26
+ npm install -g @balababa/codex-mesh@0.5.1
27
27
  codex-mesh setup
28
28
  codex-mesh doctor
29
29
  ```
30
30
 
31
- After an explicitly authorized publication, the equivalent registry command is
32
- `npm install -g @balababa/codex-mesh@0.4.0`. This document does not assert that
33
- version is published.
31
+ The x86_64 Hub binary is available from GitHub Release `v0.5.1`; verify it with
32
+ the attached `.sha256` file before installing it on the server.
34
33
 
35
34
  Installation itself has no lifecycle hook, never joins a session and never
36
35
  starts/restarts a daemon. The package contains the original Rust executable,
@@ -74,8 +73,10 @@ For automation, the existing `credentials issue --role node` and
74
73
  `setup --node-token-file /private/node.token` remain supported. Transfer that
75
74
  file only to its intended machine through an authenticated private channel.
76
75
  Do not pass secret Token values as arguments. Hub remains infrastructure and
77
- never schedules inference. Existing authenticated connections retain their
78
- grant: immediate live revocation is not implemented.
76
+ never schedules inference. Manually removing a grant blocks new authentication,
77
+ but an already authenticated connection retains its grant until disconnected.
78
+ The dashboard's **delete Node** action additionally closes that connection and
79
+ provides immediate revocation.
79
80
 
80
81
  Keep Hub on loopback and provide an authenticated SSH tunnel:
81
82
 
@@ -89,8 +90,9 @@ existing secure tunnel/service to survive your desired session lifecycle.
89
90
 
90
91
  ## Node setup
91
92
 
92
- First-time interactive `codex-mesh setup` asks for the Hub URL, then prints a
93
- short-lived authorization URL and confirmation code. Open it on any device,
93
+ First-time interactive `codex-mesh setup` asks for the Hub URL and a node display
94
+ name (blank uses the machine hostname), then prints a short-lived authorization
95
+ URL and confirmation code. Open it on any device,
94
96
  verify the self-reported machine name/hostname and matching code, enter the
95
97
  existing authorized management Token, and approve. The CLI automatically saves
96
98
  its independent Node Token and resumes configuration. The management Token is
@@ -103,10 +105,19 @@ local setup check fails. Timeout, denial or missing permission produces an error
103
105
  not a successful installation. Doctor points to incomplete onboarding. For a hard
104
106
  process termination, follow the stale setup-lock instructions below before retry.
105
107
 
106
- Existing saved node credentials are reused. Explicit `--node-token-file` uses the
107
- file workflow. Non-interactive setup without saved/file credentials fails with
108
- instructions rather than waiting for browser input. A Hub without browser
109
- authorization support must be upgraded, or use the file workflow.
108
+ Existing saved node credentials are reused and checked against the selected Hub.
109
+ If the default saved credential receives HTTP 401, interactive setup asks before
110
+ starting browser reauthorization (`y`/`yes`; the default is no). Declining keeps
111
+ the old Token unchanged. Explicit token files and non-interactive setup still fail
112
+ without prompting; network errors, unsafe files and Hub/package version mismatches
113
+ do not trigger reauthorization. A replacement Token is written atomically only
114
+ after its authenticated admission succeeds. Its authenticated Node UUID becomes
115
+ the saved identity; an explicit mismatched `--node-id` remains an error.
116
+
117
+ Explicit `--node-token-file` uses the file workflow. Non-interactive setup without
118
+ saved/file credentials fails with instructions rather than waiting for browser
119
+ input. A Hub without browser authorization support must be upgraded, or use the
120
+ file workflow.
110
121
 
111
122
  Setup uses the existing ordinary Codex and discovers its owning daemon; it does
112
123
  not start, replace or restart Codex. If another independently owned server is
@@ -158,7 +169,7 @@ replies use notify to avoid wake loops.
158
169
  The same package provides every Rust subcommand, including stdio MCP:
159
170
 
160
171
  ```sh
161
- npx --yes --package=/absolute/path/balababa-codex-mesh-0.4.0.tgz \
172
+ npx --yes --package=/absolute/path/balababa-codex-mesh-0.5.1.tgz \
162
173
  codex-mesh mcp --socket /absolute/private/mesh-runtime/mcp.sock
163
174
  ```
164
175
 
@@ -226,8 +237,18 @@ npx against the same local artifact. See the repository docs/TEST_REPORT.md for
226
237
 
227
238
  ## Public domain and web management
228
239
 
229
- The Hub serves its read-only dashboard at the Hub root. Use a management/client
230
- credential, separate from per-node setup credentials. For verified HTTPS domain
240
+ The Hub serves its management dashboard at the Hub root. Docker deployment uses
241
+ the Compose files from the matching GitHub source tag; they are not included in
242
+ the npm runtime package. Docker users can choose the default self-contained TLS stack or `docker-compose.host-caddy.yml`, which
243
+ keeps an existing multi-site host Caddy unchanged and containerizes only the
244
+ Hub. Both options preserve state in the Compose `hub-state` volume; never use
245
+ `down -v` during an upgrade. See the README deployment section for commands.
246
+ Use a management/client
247
+ credential, separate from per-node setup credentials. A successful login sets a
248
+ seven-day HttpOnly session cookie; the original Token is not persisted by the
249
+ browser. Agents are grouped under Nodes, with expand/collapse and confirmed
250
+ Agent/Node removal. Agent removal requires an online Node; Node removal revokes
251
+ its credential and Hub records. Neither removes native Codex history. For verified HTTPS domain
231
252
  access, Caddy reverse proxy, external checks and current privilege prerequisites,
232
253
  see [PUBLIC_HUB.md](PUBLIC_HUB.md). HTTP remains loopback-only.
233
254
 
@@ -51,6 +51,7 @@ export async function browserEnrollment({root,hub,nodeName,version,request,valid
51
51
  const file=path.join(root,pendingName);
52
52
  let state=pendingEnrollment(root);
53
53
  if(state&&state.hub!==hub)throw new Error('Pending browser authorization belongs to a different Hub; resume it with that Hub or explicitly use --node-token-file.');
54
+ if(state&&nodeName&&nodeName!==state.node_name)throw new Error(`Pending browser authorization uses node name "${state.node_name}"; resume it with that name.`);
54
55
  if(!state) {
55
56
  state={hub,version,node_name:nodeName||os.hostname(),hostname:os.hostname(),token:crypto.randomBytes(32).toString('hex'),claim:crypto.randomBytes(32).toString('hex')};
56
57
  write(file,state);
@@ -56,6 +56,9 @@ async function request(hub,endpoint,token,body) {
56
56
  if(response.status<200||response.status>=300) {const error=new Error(`Hub authentication/connectivity failed (HTTP ${response.status}); check tunnel, Hub and credential role`);error.status=response.status;throw error;}
57
57
  const result=JSON.parse(response.text);if(result.error) throw new Error('Hub rejected operation; check credential role/grants');return result;
58
58
  }
59
+ export function shouldOfferReauthorization(error,o) {
60
+ return error.status===401&&!o.nonInteractive&&!o.tokenFile;
61
+ }
59
62
  function command(program,args,options={}) {
60
63
  const r=spawnSync(program,args,{encoding:'utf8',timeout:15000,...options});
61
64
  if(r.error || r.status!==0) throw new Error(`Command failed: ${path.basename(program)} ${args.slice(0,2).join(' ')}; check program/service configuration`);
@@ -170,14 +173,18 @@ async function setup(o,context) {
170
173
  try {
171
174
  const file=path.join(root,'installation.json');const old=fs.existsSync(file)?json(file):null;
172
175
  const managerFile=path.join(root,'management.json');const managerSaved=fs.existsSync(managerFile)?json(managerFile):null;
176
+ const pending=o.nonInteractive||o.manager?null:pendingEnrollment(root);
177
+ if(pending&&o.nodeName&&o.nodeName!==pending.node_name)throw new Error(`Saved browser authorization uses node name "${pending.node_name}"; resume it with that name or explicitly use --node-token-file`);
173
178
  if(!o.nonInteractive && !process.stdin.isTTY)throw new Error('No interactive terminal; use setup --non-interactive with explicit options');
174
179
  if(!o.nonInteractive) {
175
180
  const rl=createInterface({input:process.stdin,output:process.stdout});
176
181
  try{
177
182
  o.hub=o.hub||await rl.question(`Hub URL [${old?.hub||'http://127.0.0.1:19010'}]: `)||old?.hub||'http://127.0.0.1:19010';
178
183
  if(o.manager)o.adminTokenFile=o.adminTokenFile||await rl.question('Management token FILE path (not the token): ');
184
+ else if(!o.nodeName){const defaultName=pending?.node_name||old?.nodeName||os.hostname();o.nodeName=await rl.question(`Node display name [${defaultName}]: `)||defaultName;}
179
185
  }finally{rl.close();}
180
186
  }
187
+ if(!o.manager&&(o.nodeName!==undefined)&&(typeof o.nodeName!=='string'||!o.nodeName.length||o.nodeName.length>128||/[\p{Cc}]/u.test(o.nodeName)))throw new Error('Node display name must be 1-128 characters without control characters');
181
188
  const hub=hubUrl(o.hub||old?.hub||managerSaved?.hub||'');
182
189
  if(o.manager) {
183
190
  if(!o.adminTokenFile && !managerSaved?.tokenFile)throw new Error('Manager setup requires --admin-token-file');
@@ -189,17 +196,30 @@ async function setup(o,context) {
189
196
  const tokenFile=path.resolve(o.tokenFile||path.join(root,'node.token'));
190
197
  const validateGrant=grant=>{if(grant.protocol_version!==1 || grant.version!==context.version)throw new Error(`Hub ${grant.version} is not compatible with package ${context.version}; upgrade the Hub deliberately first`);};
191
198
  let token,grant;
192
- if(!o.tokenFile&&((!o.nonInteractive&&pendingEnrollment(root))||!fs.existsSync(tokenFile))) {
199
+ const authorize=async()=>{
193
200
  if(o.nonInteractive)throw new Error('Non-interactive setup requires --node-token-file FILE or a saved credential. Run interactive setup to authorize this machine in a browser.');
194
201
  const controller=new AbortController();const interrupt=()=>controller.abort();process.on('SIGINT',interrupt);
195
202
  try {({token,grant}=await browserEnrollment({root,hub,nodeName:o.nodeName,version:context.version,request,validateGrant,signal:controller.signal}));}
196
203
  finally {process.removeListener('SIGINT',interrupt);}
197
- } else {token=readToken(tokenFile);grant=await request(hub,'/v1/node/check',token);validateGrant(grant);}
204
+ };
205
+ if(!o.tokenFile&&((!o.nonInteractive&&pendingEnrollment(root))||!fs.existsSync(tokenFile))) await authorize();
206
+ else {
207
+ token=readToken(tokenFile);
208
+ try {grant=await request(hub,'/v1/node/check',token);validateGrant(grant);}
209
+ catch(error) {
210
+ if(!shouldOfferReauthorization(error,o))throw error;
211
+ const rl=createInterface({input:process.stdin,output:process.stdout});
212
+ let answer;
213
+ try{answer=await rl.question('Saved node token was rejected by this Hub (HTTP 401). Reauthorize this machine in the browser? [y/N]: ');}finally{rl.close();}
214
+ if(!/^y(es)?$/i.test(answer.trim()))throw new Error('Saved node token was left unchanged; rerun setup and accept browser reauthorization, or explicitly use --node-token-file FILE.');
215
+ await authorize();
216
+ }
217
+ }
198
218
  if(!o.nonInteractive&&!o.allowDirs.length) {
199
219
  const rl=createInterface({input:process.stdin,output:process.stdout});
200
220
  try {const dir=await rl.question(`Allowed project directory [${old?.allowed?.join(', ')||os.homedir()}]: `);o.allowDirs=dir?[dir]:(old?.allowed||[os.homedir()]);}finally{rl.close();}
201
221
  }
202
- const nodeId=o.nodeId||old?.nodeId||grant.node_id;
222
+ const nodeId=o.nodeId||grant.node_id;
203
223
  if(nodeId!==grant.node_id)throw new Error('Node UUID does not match this node credential (management tokens cannot join)');
204
224
  const codex=absoluteProgram(o.codex||old?.codex||'codex');
205
225
  const skipDaemonVersionCheck=daemonVersionPolicy(o,old||{});
@@ -270,7 +290,7 @@ export function savedAgentArgs(args) {
270
290
  }
271
291
  export async function main(args,context) {
272
292
  const [action,...rest]=args;const o=options(rest);
273
- if(o.help){console.log(`codex-mesh ${action}\nsetup [--non-interactive] --hub URL [--node-token-file FILE] [--node-id UUID] [--allow-dir DIR...]\n [--node-name NAME] [--codex PATH] [--daemon-socket PATH] [--service systemd|process]\n [--skills-dir DIR] [--admin-token-file FILE]\n [--skip-daemon-version-check | --check-daemon-version]\nsetup --manager [--non-interactive] --hub URL --admin-token-file FILE\ndoctor [--json]\nFirst interactive setup prints a browser authorization link; use your existing authorized management token in the browser.\nScripted setup requires a saved credential or --node-token-file FILE; never pass token values. CODEX_MESH_HOME isolates Mesh state.\nAllowed directories default to your home directory on first setup; saved directories and explicit --allow-dir take precedence.\nDefault systemd user service survives terminals; process backend is explicitly opt-in and needs setup after reboot.\nDaemon version policy is saved; skip only bypasses version gating, never socket security or runtime checks.\nUpgrade: install new npm version, leave Mesh sessions, rerun setup; no install hooks restart services.`);return;}
293
+ if(o.help){console.log(`codex-mesh ${action}\nsetup [--non-interactive] --hub URL [--node-token-file FILE] [--node-id UUID] [--allow-dir DIR...]\n [--node-name NAME] [--codex PATH] [--daemon-socket PATH] [--service systemd|process]\n [--skills-dir DIR] [--admin-token-file FILE]\n [--skip-daemon-version-check | --check-daemon-version]\nsetup --manager [--non-interactive] --hub URL --admin-token-file FILE\ndoctor [--json]\nFirst interactive setup asks for a node display name (default: hostname), then prints a browser authorization link; use your existing authorized management token in the browser. If the saved node token receives HTTP 401, interactive setup offers browser reauthorization; declining preserves the old token.\nScripted setup requires a saved credential or --node-token-file FILE; --node-name defaults to the hostname; never pass token values. CODEX_MESH_HOME isolates Mesh state.\nAllowed directories default to your home directory on first setup; saved directories and explicit --allow-dir take precedence.\nDefault systemd user service survives terminals; process backend is explicitly opt-in and needs setup after reboot.\nDaemon version policy is saved; skip only bypasses version gating, never socket security or runtime checks.\nUpgrade: install new npm version, leave Mesh sessions, rerun setup; no install hooks restart services.`);return;}
274
294
  if(action==='setup')return setup(o,context);
275
295
  const root=home();const file=path.join(root,'installation.json');let checks;
276
296
  if(fs.existsSync(file)){try{checks=await inspect(json(file),context);}catch{checks=[{name:'configuration',ok:false,fix:'Saved installation configuration is incomplete/invalid; rerun setup with explicit options after preserving its private runtime state.'}];}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balababa/codex-mesh",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Session-native Mesh Hub, ordinary Codex MCP/Skill and Agent management",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
Binary file
package/release.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
- "version": "0.4.0",
2
+ "version": "0.5.1",
3
3
  "protocolVersion": 1,
4
4
  "platforms": {
5
5
  "linux-x64-gnu": {
6
6
  "path": "platforms/linux-x64-gnu/codex-mesh",
7
- "sha256": "3cf6a2c17d6aff3824ce2f8ccc9f3fd3837b91ce565b47c2bc1dc35708d38b8a",
7
+ "sha256": "4cb6a9456342720ef4200a06a20ed2525ee5eeab996797e85de643d7ee01cb28",
8
8
  "nodeMinimum": "24.19.0",
9
9
  "glibcMinimum": "2.35"
10
10
  }
@@ -2,7 +2,7 @@
2
2
  name: codex-mesh
3
3
  description: Connect ordinary Codex to Codex Mesh (集群/机器/Agent 通信). Use when the user wants to join or leave Mesh, discover enrolled agents or machines, send a peer message, or read Mesh replies. Mesh MCP supplies the actions; this skill explains the workflow.
4
4
  metadata:
5
- version: "0.4.0"
5
+ version: "0.5.1"
6
6
  ---
7
7
 
8
8
  # Codex Mesh
@@ -1,4 +1,4 @@
1
- # Host setup for packaged Mesh 0.4.0
1
+ # Host setup for packaged Mesh 0.5.1
2
2
 
3
3
  The Skill supplies instructions; MCP performs actions; a persistent local Node
4
4
  receives messages and wakes explicitly enrolled native sessions. Installing or
@@ -11,7 +11,9 @@ provided per-node token file for scripts), and allowed project directories.
11
11
  The CLI prints a link and confirmation code; the human approves on a trusted
12
12
  browser and the CLI saves independent node credentials automatically. Never ask
13
13
  for a management Token through model tools or store it in a project.
14
- Machine authorization does not enroll this Codex session.
14
+ Machine authorization does not enroll this Codex session. If an existing saved
15
+ Node Token receives HTTP 401, interactive setup asks before browser reauthorization;
16
+ declining preserves it. Explicit/non-interactive credential failures never prompt.
15
17
 
16
18
  ```sh
17
19
  codex-mesh setup --non-interactive --hub http://127.0.0.1:19010 \
@@ -30,7 +32,7 @@ supported reload or a new session. Do not call mesh_join merely to diagnose an
30
32
  installation. Doctor checks readiness without inference or enrollment.
31
33
 
32
34
  For an npm/npx MCP entry, first complete host setup, then use the exact authorized
33
- package version with `npx --yes --package=<package>@0.4.0 codex-mesh mcp --socket
35
+ package version with `npx --yes --package=<package>@0.5.1 codex-mesh mcp --socket
34
36
  /private/mesh/mcp.sock`. The Node remains in stable managed storage. The package
35
37
  name is `@balababa/codex-mesh` under the maintainer personal scope; registry
36
38
  installation requires publication of that version. Do not install the unrelated unscoped `codex-mesh` package.