@balababa/codex-mesh 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -13
- package/docs/INSTALL.md +74 -39
- package/npm/lib/enrollment.mjs +104 -0
- package/npm/lib/onboarding.mjs +22 -13
- package/package.json +1 -1
- package/platforms/linux-x64-gnu/codex-mesh +0 -0
- package/release.json +2 -2
- package/skills/codex-mesh/SKILL.md +1 -1
- package/skills/codex-mesh/references/setup.md +8 -4
package/README.md
CHANGED
|
@@ -31,36 +31,39 @@ see [artifact exports](docs/ARTIFACTS.md).
|
|
|
31
31
|
|
|
32
32
|
## npm 安装与普通用户接入
|
|
33
33
|
|
|
34
|
-
当前源码版本为 **0.
|
|
34
|
+
当前源码版本为 **0.4.0**,新增浏览器授权机器接入。Rust Hub/Node/MCP/管理命令、
|
|
35
35
|
启动器和 Skill 使用同一版本。普通用户不需要 Rust、源码仓库或本地编译。
|
|
36
36
|
支持 Linux x86_64、glibc >=2.35,Node.js >=24.19.0。
|
|
37
37
|
|
|
38
|
-
包名为 **`@balababa/codex-mesh`**。npm 已发布版本为 **0.
|
|
39
|
-
|
|
38
|
+
包名为 **`@balababa/codex-mesh`**。npm 已发布版本为 **0.3.0**;0.4.0 本轮
|
|
39
|
+
不发布,请使用匹配的本地产物,并先升级 Hub:
|
|
40
40
|
|
|
41
41
|
```sh
|
|
42
|
-
npm install -g /absolute/path/balababa-codex-mesh-0.
|
|
42
|
+
npm install -g /absolute/path/balababa-codex-mesh-0.4.0.tgz
|
|
43
43
|
codex-mesh setup
|
|
44
44
|
codex-mesh doctor
|
|
45
45
|
codex
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
首次 setup 填写 Hub 地址后显示授权链接和确认码。在浏览器打开链接,核对机器信息,
|
|
49
|
+
输入现有管理 Token 并批准,终端自动保存本机独立节点凭据、继续安装 Node、MCP 和 Skill。
|
|
50
|
+
管理 Token 不会交给接入机器。Hub 管理员须先显式给管理凭据开启节点接入授权权限;
|
|
51
|
+
已有节点凭据直接复用,脚本仍可使用 `--node-token-file`。
|
|
52
|
+
|
|
53
|
+
在新的普通 Codex 会话中输入 `$codex-mesh 加入 Mesh`。安装、网页授权和 doctor
|
|
54
|
+
不登记任何 Codex 会话。管理端保存配置后,直接 `codex-mesh agents`。
|
|
53
55
|
|
|
54
56
|
同一个本地 tarball 可用于 npx 按需启动 MCP:
|
|
55
57
|
|
|
56
58
|
```sh
|
|
57
|
-
npx --yes --package=/absolute/path/balababa-codex-mesh-0.
|
|
59
|
+
npx --yes --package=/absolute/path/balababa-codex-mesh-0.4.0.tgz \
|
|
58
60
|
codex-mesh mcp --socket /absolute/private/mesh/mcp.sock
|
|
59
61
|
```
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
[INSTALL.md](docs/INSTALL.md)。默认使用 systemd user
|
|
63
|
-
|
|
63
|
+
完整安装、管理授权开关、非交互配置、doctor 与升级说明见
|
|
64
|
+
[INSTALL.md](docs/INSTALL.md)。默认使用 systemd user 服务;容器可显式使用
|
|
65
|
+
`--service process`。升级 npm 本身不会重启 Node 或用户 daemon,改变配置/版本时
|
|
66
|
+
需要在会话退出 Mesh 后重新 setup。
|
|
64
67
|
|
|
65
68
|
## Build
|
|
66
69
|
|
package/docs/INSTALL.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# npm installation and ordinary Codex setup
|
|
2
2
|
|
|
3
|
-
Source release version: **0.
|
|
3
|
+
Source release version: **0.4.0** (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.
|
|
9
|
-
Source
|
|
10
|
-
matching local tarball
|
|
11
|
-
is not this implementation.
|
|
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.
|
|
11
|
+
The unrelated unscoped `codex-mesh` package is not this implementation.
|
|
12
12
|
|
|
13
13
|
## Supported runtime
|
|
14
14
|
|
|
@@ -20,21 +20,17 @@ 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
|
-
|
|
23
|
+
For this 0.4.0 build, install the matching local artifact:
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
npm install -g
|
|
26
|
+
npm install -g /absolute/path/balababa-codex-mesh-0.4.0.tgz
|
|
27
27
|
codex-mesh setup
|
|
28
28
|
codex-mesh doctor
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
npm install -g /absolute/path/balababa-codex-mesh-0.3.0.tgz
|
|
35
|
-
codex-mesh setup
|
|
36
|
-
codex-mesh doctor
|
|
37
|
-
```
|
|
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.
|
|
38
34
|
|
|
39
35
|
Installation itself has no lifecycle hook, never joins a session and never
|
|
40
36
|
starts/restarts a daemon. The package contains the original Rust executable,
|
|
@@ -42,29 +38,44 @@ stdio launcher, setup/doctor and Skill under one version/checksum manifest.
|
|
|
42
38
|
|
|
43
39
|
## Hub and credential provisioning
|
|
44
40
|
|
|
45
|
-
On the Hub host, install the same tarball/version.
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
On the Hub host, install the same tarball/version. Reuse the existing management
|
|
42
|
+
Token; no second management Token is needed. Enable node-enrollment permission
|
|
43
|
+
explicitly for its credential name (the existing deployment uses `web-manager`):
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
codex-mesh credentials allow-node-enrollment \
|
|
47
|
+
--credentials /home/chh/.local/share/codex-mesh/hub/credentials.json \
|
|
48
|
+
--name web-manager
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This preserves the management Token and unrelated grants. Repeated execution is
|
|
52
|
+
safe, and new authentication reads updates without a Hub restart. Existing
|
|
53
|
+
credentials do not gain enrollment rights merely by upgrading.
|
|
54
|
+
|
|
55
|
+
For a new Hub only, first issue its management credential:
|
|
48
56
|
|
|
49
57
|
```sh
|
|
50
58
|
codex-mesh credentials issue --credentials /private/mesh-hub/credentials.json \
|
|
51
|
-
--token-file /private/mesh-hub/
|
|
52
|
-
codex-mesh credentials
|
|
53
|
-
--
|
|
59
|
+
--token-file /private/mesh-hub/manager.token --name web-manager --role client
|
|
60
|
+
codex-mesh credentials allow-node-enrollment \
|
|
61
|
+
--credentials /private/mesh-hub/credentials.json --name web-manager
|
|
54
62
|
codex-mesh hub --bind 127.0.0.1:9010 \
|
|
63
|
+
--public-url https://codex-mesh.wcisman.cc \
|
|
55
64
|
--database /private/mesh-hub/hub.sqlite \
|
|
56
65
|
--credentials /private/mesh-hub/credentials.json
|
|
57
66
|
```
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
`--public-url` is the trusted origin used for browser authorization links. It must
|
|
69
|
+
be verified HTTPS, or loopback HTTP for local/tunnel use. Behind Caddy use the
|
|
70
|
+
external HTTPS origin while Hub continues listening on loopback. No forwarded
|
|
71
|
+
host header determines authorization links.
|
|
72
|
+
|
|
73
|
+
For automation, the existing `credentials issue --role node` and
|
|
74
|
+
`setup --node-token-file /private/node.token` remain supported. Transfer that
|
|
75
|
+
file only to its intended machine through an authenticated private channel.
|
|
76
|
+
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.
|
|
68
79
|
|
|
69
80
|
Keep Hub on loopback and provide an authenticated SSH tunnel:
|
|
70
81
|
|
|
@@ -78,11 +89,28 @@ existing secure tunnel/service to survive your desired session lifecycle.
|
|
|
78
89
|
|
|
79
90
|
## Node setup
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
the
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
94
|
+
verify the self-reported machine name/hostname and matching code, enter the
|
|
95
|
+
existing authorized management Token, and approve. The CLI automatically saves
|
|
96
|
+
its independent Node Token and resumes configuration. The management Token is
|
|
97
|
+
never saved on the new machine. This works on headless servers and containers;
|
|
98
|
+
a browser is only needed on the device used for approval.
|
|
99
|
+
|
|
100
|
+
A request lasts 10 minutes. The CLI keeps a private pending record so rerunning
|
|
101
|
+
setup can resume after interruption. Approved credentials are retained if a later
|
|
102
|
+
local setup check fails. Timeout, denial or missing permission produces an error,
|
|
103
|
+
not a successful installation. Doctor points to incomplete onboarding. For a hard
|
|
104
|
+
process termination, follow the stale setup-lock instructions below before retry.
|
|
105
|
+
|
|
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.
|
|
110
|
+
|
|
111
|
+
Setup uses the existing ordinary Codex and discovers its owning daemon; it does
|
|
112
|
+
not start, replace or restart Codex. If another independently owned server is
|
|
113
|
+
used, pass `--daemon-socket` explicitly; ownership/mode checks still apply.
|
|
86
114
|
|
|
87
115
|
For scripts:
|
|
88
116
|
|
|
@@ -130,7 +158,7 @@ replies use notify to avoid wake loops.
|
|
|
130
158
|
The same package provides every Rust subcommand, including stdio MCP:
|
|
131
159
|
|
|
132
160
|
```sh
|
|
133
|
-
npx --yes --package=/absolute/path/balababa-codex-mesh-0.
|
|
161
|
+
npx --yes --package=/absolute/path/balababa-codex-mesh-0.4.0.tgz \
|
|
134
162
|
codex-mesh mcp --socket /absolute/private/mesh-runtime/mcp.sock
|
|
135
163
|
```
|
|
136
164
|
|
|
@@ -169,7 +197,10 @@ Upgrade npm to the desired exact version, upgrade Hub deliberately, then rerun
|
|
|
169
197
|
`setup` and `doctor`. No npm install hook restarts running services. If a Node has
|
|
170
198
|
any enrolled sessions, a changed setup is deferred before stopping it. Ask those
|
|
171
199
|
sessions to leave Mesh, then rerun. Unchanged setup is safe to repeat while joined.
|
|
172
|
-
User Codex daemon is never restarted. Keep the existing secure Hub tunnel running.
|
|
200
|
+
User Codex daemon is never restarted. Keep the existing verified TLS endpoint or secure Hub tunnel running.
|
|
201
|
+
The current setup requires exact Hub/package release versions; it does not
|
|
202
|
+
silently relax that gate for older clients. Plan the Hub and node upgrades
|
|
203
|
+
together, and rerun setup to refresh stable services, MCP and Skill.
|
|
173
204
|
|
|
174
205
|
Setup records `pending` before side effects and `ready` only after actual checks.
|
|
175
206
|
Interrupted/pending setup is not reported healthy; fix the reported cause and
|
|
@@ -195,7 +226,7 @@ npx against the same local artifact. See the repository docs/TEST_REPORT.md for
|
|
|
195
226
|
|
|
196
227
|
## Public domain and web management
|
|
197
228
|
|
|
198
|
-
|
|
229
|
+
The Hub serves its read-only dashboard at the Hub root. Use a management/client
|
|
199
230
|
credential, separate from per-node setup credentials. For verified HTTPS domain
|
|
200
231
|
access, Caddy reverse proxy, external checks and current privilege prerequisites,
|
|
201
232
|
see [PUBLIC_HUB.md](PUBLIC_HUB.md). HTTP remains loopback-only.
|
|
@@ -217,5 +248,9 @@ skipped version check explicitly. Re-enable the default with
|
|
|
217
248
|
setup; they are mutually exclusive. Only the version gate is bypassed: running
|
|
218
249
|
daemon discovery, private owned socket checks, actual Node startup/connectivity,
|
|
219
250
|
MCP and all sandbox/approval rules still apply. This does not certify 0.172.0
|
|
220
|
-
native queue/steer compatibility.
|
|
221
|
-
|
|
251
|
+
native queue/steer compatibility.
|
|
252
|
+
|
|
253
|
+
First-time setup defaults the allowed directory to the current user home (`~`),
|
|
254
|
+
in both interactive and non-interactive modes. Saved allowlists remain unchanged
|
|
255
|
+
on repeat setup; explicit `--allow-dir` values override them. This includes home
|
|
256
|
+
subdirectories. Use explicit project directories when a narrower scope is wanted.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Browser approval only provisions a node credential. It never enrolls a Codex thread.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import crypto from 'node:crypto';
|
|
6
|
+
import {spawn} from 'node:child_process';
|
|
7
|
+
|
|
8
|
+
const pendingName='enrollment.json';
|
|
9
|
+
const digest=value=>crypto.createHash('sha256').update(value).digest('hex');
|
|
10
|
+
function checkFile(file) {
|
|
11
|
+
const stat=fs.lstatSync(file);
|
|
12
|
+
if(!stat.isFile()||stat.isSymbolicLink()||stat.uid!==process.getuid()||(stat.mode&0o077))throw new Error(`Private owned regular file required (chmod 600): ${file}`);
|
|
13
|
+
}
|
|
14
|
+
function write(file,value) {
|
|
15
|
+
if(fs.existsSync(file))checkFile(file);
|
|
16
|
+
const temporary=file+'.new-'+crypto.randomUUID();
|
|
17
|
+
const fd=fs.openSync(temporary,'wx',0o600);
|
|
18
|
+
try{fs.writeFileSync(fd,JSON.stringify(value,null,2)+'\n');fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
19
|
+
fs.renameSync(temporary,file);
|
|
20
|
+
}
|
|
21
|
+
export function pendingEnrollment(root) {
|
|
22
|
+
const file=path.join(root,pendingName);
|
|
23
|
+
if(!fs.existsSync(file))return null;
|
|
24
|
+
checkFile(file);
|
|
25
|
+
const state=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
26
|
+
if(typeof state.hub!=='string'||typeof state.token!=='string'||! /^[a-f0-9]{64}$/.test(state.token)||! /^[a-f0-9]{64}$/.test(state.claim))throw new Error('Invalid saved browser authorization; preserve private state and rerun setup with a token file');
|
|
27
|
+
return state;
|
|
28
|
+
}
|
|
29
|
+
function verificationUrl(value,hub,id) {
|
|
30
|
+
const url=new URL(value);
|
|
31
|
+
if(!['https:','http:'].includes(url.protocol)||url.username||url.password||url.search||url.hash||url.origin!==new URL(hub.replace(/^ws:/,'http:').replace(/^wss:/,'https:')).origin||url.pathname!=='/activate/'+id)throw new Error('Hub returned an unsafe authorization URL; check its --public-url configuration.');
|
|
32
|
+
return url.href;
|
|
33
|
+
}
|
|
34
|
+
function browser(url) {
|
|
35
|
+
if(!process.env.DISPLAY&&!process.env.WAYLAND_DISPLAY)return;
|
|
36
|
+
try {
|
|
37
|
+
const child=spawn('xdg-open',[url],{detached:true,stdio:'ignore'});
|
|
38
|
+
child.on('error',()=>{});child.unref();
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
const pause=(ms,signal)=>new Promise((resolve,reject)=>{
|
|
42
|
+
if(signal?.aborted){reject(new Error('Authorization interrupted; rerun setup to resume.'));return;}
|
|
43
|
+
const aborted=()=>{clearTimeout(timer);reject(new Error('Authorization interrupted; rerun setup to resume.'));};
|
|
44
|
+
const timer=setTimeout(()=>{signal?.removeEventListener('abort',aborted);resolve();},ms);
|
|
45
|
+
signal?.addEventListener('abort',aborted,{once:true});
|
|
46
|
+
});
|
|
47
|
+
function terminalState(state) {
|
|
48
|
+
if(['denied','cancelled','expired'].includes(state))throw new Error(`Browser authorization ${state}; rerun setup to request authorization again.`);
|
|
49
|
+
}
|
|
50
|
+
export async function browserEnrollment({root,hub,nodeName,version,request,validateGrant,signal,log=console.log,openBrowser=browser,sleep=pause,now=()=>Date.now()}) {
|
|
51
|
+
const file=path.join(root,pendingName);
|
|
52
|
+
let state=pendingEnrollment(root);
|
|
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) {
|
|
55
|
+
state={hub,version,node_name:nodeName||os.hostname(),hostname:os.hostname(),token:crypto.randomBytes(32).toString('hex'),claim:crypto.randomBytes(32).toString('hex')};
|
|
56
|
+
write(file,state);
|
|
57
|
+
}
|
|
58
|
+
if(!state.request_id) {
|
|
59
|
+
let started;
|
|
60
|
+
try {started=await request(hub,'/v1/enrollment/start',null,{node_name:state.node_name,hostname:state.hostname,token_sha256:digest(state.token),claim_sha256:digest(state.claim)});}
|
|
61
|
+
catch(error) {
|
|
62
|
+
if([404,405].includes(error.status))throw new Error('This Hub does not support browser authorization. Upgrade the Hub to 0.4.0 or use setup --node-token-file FILE.');
|
|
63
|
+
if(error.status===503)throw new Error('Browser authorization is unavailable. Configure the Hub --public-url, or use setup --node-token-file FILE.');
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
const verification=verificationUrl(started.verification_uri,hub,started.request_id);
|
|
67
|
+
if(!/^[0-9a-f-]{36}$/.test(started.request_id)||!/^[0-9a-f-]{36}$/.test(started.node_id)||typeof started.user_code!=='string'||!/^[A-Z0-9-]{4,32}$/.test(started.user_code)||!Number.isFinite(started.expires_at))throw new Error('Hub returned an invalid browser authorization response.');
|
|
68
|
+
state={...state,...{request_id:started.request_id,node_id:started.node_id,user_code:started.user_code,verification_uri:verification,expires_at:started.expires_at,interval:3}};
|
|
69
|
+
write(file,state);
|
|
70
|
+
}
|
|
71
|
+
verificationUrl(state.verification_uri,hub,state.request_id);
|
|
72
|
+
log(`Open this link to authorize this machine:\n${state.verification_uri}\nConfirmation code: ${state.user_code}\nEnter your management token in the browser only. Waiting for authorization…`);
|
|
73
|
+
openBrowser(state.verification_uri);
|
|
74
|
+
const endpoint='/v1/enrollment/'+state.request_id;
|
|
75
|
+
for(;;) {
|
|
76
|
+
if(signal?.aborted)throw new Error('Authorization interrupted; rerun setup to resume.');
|
|
77
|
+
let result;
|
|
78
|
+
try{result=await request(hub,endpoint+'/poll',state.claim,{});}
|
|
79
|
+
catch(error){
|
|
80
|
+
if([401,404,410].includes(error.status)&&state.expires_at*1000<=now()){fs.rmSync(file);throw new Error('Browser authorization expired or unavailable; rerun setup to request a new link.');}
|
|
81
|
+
throw new Error(`Authorization status unavailable; rerun setup to resume. ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
if(['denied','cancelled','expired'].includes(result.status)){fs.rmSync(file);terminalState(result.status);}
|
|
84
|
+
if(['approved','completed'].includes(result.status)) {
|
|
85
|
+
const grant=await request(hub,'/v1/node/check',state.token);
|
|
86
|
+
if(grant.node_id!==state.node_id)throw new Error('Authorized node identity does not match this authorization request.');
|
|
87
|
+
if(validateGrant)validateGrant(grant);
|
|
88
|
+
const tokenFile=path.join(root,'node.token');
|
|
89
|
+
if(fs.existsSync(tokenFile))checkFile(tokenFile);
|
|
90
|
+
const temporary=tokenFile+'.new-'+crypto.randomUUID();
|
|
91
|
+
const fd=fs.openSync(temporary,'wx',0o600);
|
|
92
|
+
try{fs.writeFileSync(fd,state.token+'\n');fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
93
|
+
fs.renameSync(temporary,tokenFile);
|
|
94
|
+
await request(hub,endpoint+'/complete',state.claim,{});
|
|
95
|
+
fs.rmSync(file);
|
|
96
|
+
log('Machine authorized. Node credential saved privately; no Codex session enrolled.');
|
|
97
|
+
return {token:state.token,grant};
|
|
98
|
+
}
|
|
99
|
+
if(result.status!=='pending')throw new Error('Hub returned an invalid authorization status.');
|
|
100
|
+
if(result.expires_at!==undefined&&result.expires_at*1000<=now()){fs.rmSync(file);terminalState('expired');}
|
|
101
|
+
if(state.expires_at*1000<=now()){fs.rmSync(file);terminalState('expired');}
|
|
102
|
+
await sleep(3000,signal);
|
|
103
|
+
}
|
|
104
|
+
}
|
package/npm/lib/onboarding.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import https from 'node:https';
|
|
|
7
7
|
import crypto from 'node:crypto';
|
|
8
8
|
import {spawn, spawnSync, execFileSync} from 'node:child_process';
|
|
9
9
|
import {createInterface} from 'node:readline/promises';
|
|
10
|
+
import {browserEnrollment, pendingEnrollment} from './enrollment.mjs';
|
|
10
11
|
|
|
11
12
|
const marker='Managed by codex-mesh npm setup';
|
|
12
13
|
const home=()=>path.resolve(process.env.CODEX_MESH_HOME || path.join(os.homedir(),'.local/share/codex-mesh/npm'));
|
|
@@ -46,13 +47,13 @@ async function request(hub,endpoint,token,body) {
|
|
|
46
47
|
const response=await new Promise((resolve,reject)=>{
|
|
47
48
|
const transport=url.protocol==='https:'?https:http;
|
|
48
49
|
const directAgent=new transport.Agent({keepAlive:false,proxyEnv:{}});
|
|
49
|
-
const req=transport.request(url,{agent:directAgent,method:body?'POST':'GET',headers:{authorization:'Bearer '+token,...(body?{'content-type':'application/json'}:{})}},res=>{
|
|
50
|
+
const req=transport.request(url,{agent:directAgent,method:body?'POST':'GET',headers:{...(token?{authorization:'Bearer '+token}:{}),...(body?{'content-type':'application/json'}:{})}},res=>{
|
|
50
51
|
let bytes=0,text='';res.setEncoding('utf8');res.on('data',chunk=>{bytes+=Buffer.byteLength(chunk);if(bytes>1024*1024){req.destroy(new Error('Hub response exceeds limit'));return;}text+=chunk;});res.on('end',()=>resolve({status:res.statusCode,text}));res.on('error',reject);
|
|
51
52
|
});
|
|
52
53
|
req.setTimeout(10000,()=>req.destroy(new Error('Hub request timed out')));req.on('error',()=>reject(new Error('Hub connection failed; check URL, tunnel and certificate')));
|
|
53
54
|
req.end(body?JSON.stringify(body):undefined);
|
|
54
55
|
});
|
|
55
|
-
if(response.status<200||response.status>=300)
|
|
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;}
|
|
56
57
|
const result=JSON.parse(response.text);if(result.error) throw new Error('Hub rejected operation; check credential role/grants');return result;
|
|
57
58
|
}
|
|
58
59
|
function command(program,args,options={}) {
|
|
@@ -175,12 +176,6 @@ async function setup(o,context) {
|
|
|
175
176
|
try{
|
|
176
177
|
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';
|
|
177
178
|
if(o.manager)o.adminTokenFile=o.adminTokenFile||await rl.question('Management token FILE path (not the token): ');
|
|
178
|
-
else {
|
|
179
|
-
o.tokenFile=o.tokenFile||await rl.question('Node token FILE path (leave empty to reuse saved credential): ')||undefined;
|
|
180
|
-
o.nodeId=o.nodeId||await rl.question(`Node UUID [${old?.nodeId||'from Hub credential'}]: `)||old?.nodeId;
|
|
181
|
-
const dir=await rl.question(`Allowed project directory [${old?.allowed?.join(', ')||process.cwd()}]: `);
|
|
182
|
-
if(!o.allowDirs.length)o.allowDirs=dir?[dir]:(old?.allowed||[process.cwd()]);
|
|
183
|
-
}
|
|
184
179
|
}finally{rl.close();}
|
|
185
180
|
}
|
|
186
181
|
const hub=hubUrl(o.hub||old?.hub||managerSaved?.hub||'');
|
|
@@ -191,16 +186,26 @@ async function setup(o,context) {
|
|
|
191
186
|
write(path.join(root,'admin.token'),token+'\n');write(path.join(root,'management.json'),{version:context.version,hub,tokenFile:path.join(root,'admin.token')});
|
|
192
187
|
console.log('Management configuration saved. Run codex-mesh agents. No session enrolled.');return;
|
|
193
188
|
}
|
|
194
|
-
const
|
|
195
|
-
const grant
|
|
196
|
-
|
|
189
|
+
const tokenFile=path.resolve(o.tokenFile||path.join(root,'node.token'));
|
|
190
|
+
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
|
+
let token,grant;
|
|
192
|
+
if(!o.tokenFile&&((!o.nonInteractive&&pendingEnrollment(root))||!fs.existsSync(tokenFile))) {
|
|
193
|
+
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
|
+
const controller=new AbortController();const interrupt=()=>controller.abort();process.on('SIGINT',interrupt);
|
|
195
|
+
try {({token,grant}=await browserEnrollment({root,hub,nodeName:o.nodeName,version:context.version,request,validateGrant,signal:controller.signal}));}
|
|
196
|
+
finally {process.removeListener('SIGINT',interrupt);}
|
|
197
|
+
} else {token=readToken(tokenFile);grant=await request(hub,'/v1/node/check',token);validateGrant(grant);}
|
|
198
|
+
if(!o.nonInteractive&&!o.allowDirs.length) {
|
|
199
|
+
const rl=createInterface({input:process.stdin,output:process.stdout});
|
|
200
|
+
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
|
+
}
|
|
197
202
|
const nodeId=o.nodeId||old?.nodeId||grant.node_id;
|
|
198
203
|
if(nodeId!==grant.node_id)throw new Error('Node UUID does not match this node credential (management tokens cannot join)');
|
|
199
204
|
const codex=absoluteProgram(o.codex||old?.codex||'codex');
|
|
200
205
|
const skipDaemonVersionCheck=daemonVersionPolicy(o,old||{});
|
|
201
206
|
const d=daemon(codex,o.daemonSocket,skipDaemonVersionCheck);
|
|
202
207
|
if(skipDaemonVersionCheck)console.error(`Daemon version check skipped by saved/explicit policy (${d.version||"unknown"}); runtime compatibility is not guaranteed.`);
|
|
203
|
-
const allowed=(o.allowDirs.length?o.allowDirs:old?.allowed||[]).map(p=>fs.realpathSync(path.resolve(p)));
|
|
208
|
+
const allowed=(o.allowDirs.length?o.allowDirs:old?.allowed||[os.homedir()]).map(p=>fs.realpathSync(path.resolve(p)));
|
|
204
209
|
if(!allowed.length || allowed.some(p=>!fs.statSync(p).isDirectory()))throw new Error('At least one --allow-dir DIRECTORY is required');
|
|
205
210
|
const service=o.service||old?.service||'systemd';if(!['systemd','process'].includes(service))throw new Error('--service must be systemd or process');
|
|
206
211
|
if(service==='systemd')command('systemctl',['--user','show-environment']);
|
|
@@ -226,6 +231,7 @@ async function setup(o,context) {
|
|
|
226
231
|
if(running&&old.process)state.process=old.process;
|
|
227
232
|
write(file,state); // Pending until actual Node/MCP/Skill checks pass.
|
|
228
233
|
write(path.join(root,'node.token'),token+'\n');write(state.nodeConfig,node);
|
|
234
|
+
if(o.tokenFile||o.nonInteractive)fs.rmSync(path.join(root,'enrollment.json'),{force:true});
|
|
229
235
|
if(!running)await startService(state);
|
|
230
236
|
safeManagedSkill(state,path.join(context.packageRoot,'skills/codex-mesh'));
|
|
231
237
|
command(codex,['mcp','add','mesh','--',state.binary,'mcp','--socket',state.socket]);
|
|
@@ -264,12 +270,15 @@ export function savedAgentArgs(args) {
|
|
|
264
270
|
}
|
|
265
271
|
export async function main(args,context) {
|
|
266
272
|
const [action,...rest]=args;const o=options(rest);
|
|
267
|
-
if(o.help){console.log(`codex-mesh ${action}\nsetup [--non-interactive] --hub URL --token-file FILE [--node-id UUID] --allow-dir DIR
|
|
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;}
|
|
268
274
|
if(action==='setup')return setup(o,context);
|
|
269
275
|
const root=home();const file=path.join(root,'installation.json');let checks;
|
|
270
276
|
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.'}];}}
|
|
271
277
|
else if(fs.existsSync(path.join(root,'management.json'))){
|
|
272
278
|
try{const s=json(path.join(root,'management.json'));if(s.version!==context.version)throw Error();privateDir(root);privateFile(path.join(root,'management.json'));await request(hubUrl(s.hub),'/v1/rpc',readToken(s.tokenFile),{id:'doctor',method:'mesh.list_agents',params:{limit:1}});checks=[{name:'management config/Hub',ok:true}];}catch{checks=[{name:'management config/Hub',ok:false,fix:'Run setup --manager with a private management token and reachable Hub.'}];}
|
|
279
|
+
}else if(fs.existsSync(path.join(root,'enrollment.json'))) {
|
|
280
|
+
try {const enrollment=pendingEnrollment(root);checks=[{name:'browser authorization',ok:false,fix:`Authorization is incomplete${enrollment.expires_at&&enrollment.expires_at*1000<Date.now()?' (approval deadline passed)':''}; rerun interactive codex-mesh setup --hub ${hubUrl(enrollment.hub)} to resume or request approval again.`}];}
|
|
281
|
+
catch {checks=[{name:'browser authorization',ok:false,fix:'Saved authorization is invalid or has unsafe permissions; inspect private enrollment.json and rerun setup.'}];}
|
|
273
282
|
}else checks=[{name:'configuration',ok:false,fix:'Run codex-mesh setup (or setup --manager for management-only use).'}];
|
|
274
283
|
if(o.json)console.log(JSON.stringify({version:context.version,ok:checks.every(c=>c.ok),checks},null,2));
|
|
275
284
|
else for(const c of checks)console.log(`${c.ok?'OK':'FAIL'} ${c.name}${c.fix?' — '+c.fix:''}`);
|
package/package.json
CHANGED
|
Binary file
|
package/release.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.4.0",
|
|
3
3
|
"protocolVersion": 1,
|
|
4
4
|
"platforms": {
|
|
5
5
|
"linux-x64-gnu": {
|
|
6
6
|
"path": "platforms/linux-x64-gnu/codex-mesh",
|
|
7
|
-
"sha256": "
|
|
7
|
+
"sha256": "3cf6a2c17d6aff3824ce2f8ccc9f3fd3837b91ce565b47c2bc1dc35708d38b8a",
|
|
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.
|
|
5
|
+
version: "0.4.0"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Codex Mesh
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Host setup for packaged Mesh 0.
|
|
1
|
+
# Host setup for packaged Mesh 0.4.0
|
|
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
|
|
@@ -6,8 +6,12 @@ loading this Skill does not enroll anything.
|
|
|
6
6
|
|
|
7
7
|
A host operator installs the authorized npm package (or its local release tarball),
|
|
8
8
|
then runs `codex-mesh setup` and `codex-mesh doctor`. Setup needs a running owning
|
|
9
|
-
ordinary Codex daemon, a reachable authenticated Hub,
|
|
10
|
-
|
|
9
|
+
ordinary Codex daemon, a reachable authenticated Hub, browser approval with the existing authorized management Token (or an explicitly
|
|
10
|
+
provided per-node token file for scripts), and allowed project directories.
|
|
11
|
+
The CLI prints a link and confirmation code; the human approves on a trusted
|
|
12
|
+
browser and the CLI saves independent node credentials automatically. Never ask
|
|
13
|
+
for a management Token through model tools or store it in a project.
|
|
14
|
+
Machine authorization does not enroll this Codex session.
|
|
11
15
|
|
|
12
16
|
```sh
|
|
13
17
|
codex-mesh setup --non-interactive --hub http://127.0.0.1:19010 \
|
|
@@ -26,7 +30,7 @@ supported reload or a new session. Do not call mesh_join merely to diagnose an
|
|
|
26
30
|
installation. Doctor checks readiness without inference or enrollment.
|
|
27
31
|
|
|
28
32
|
For an npm/npx MCP entry, first complete host setup, then use the exact authorized
|
|
29
|
-
package version with `npx --yes --package=<package>@0.
|
|
33
|
+
package version with `npx --yes --package=<package>@0.4.0 codex-mesh mcp --socket
|
|
30
34
|
/private/mesh/mcp.sock`. The Node remains in stable managed storage. The package
|
|
31
35
|
name is `@balababa/codex-mesh` under the maintainer personal scope; registry
|
|
32
36
|
installation requires publication of that version. Do not install the unrelated unscoped `codex-mesh` package.
|