huaweicloud-devkit 1.1.15 → 1.1.17
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 +18 -0
- package/README.zh-CN.md +18 -0
- package/package.json +1 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/src/mcp-server-remote.mjs +38 -3
- package/plugins/huaweicloud-core/src/mcp-server.mjs +4 -1
- package/plugins/huaweicloud-core/src/server-install.mjs +315 -0
- package/plugins/huaweicloud-core/src/setup-cli.mjs +16 -0
package/README.md
CHANGED
|
@@ -284,6 +284,24 @@ It listens on `127.0.0.1:9528` by default. Then connect with a remote config (op
|
|
|
284
284
|
|
|
285
285
|
> Use `--port <port>` if 9528 is taken and update `url` accordingly; add `--host 0.0.0.0` for LAN access. The remote server has no built-in auth — do not expose it anonymously to the public internet.
|
|
286
286
|
|
|
287
|
+
### Server Mode (systemd, Linux)
|
|
288
|
+
|
|
289
|
+
Runs the MCP server as a pair of hardened systemd services with a dedicated OS user and generated auth password — for unattended/ops environments.
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
sudo npx --yes huaweicloud-devkit install-server # defaults: /opt/kunpeng, business 8088, tool 7088, user devkit
|
|
293
|
+
sudo npx --yes huaweicloud-devkit install-server --install-path /opt/kunpeng --port 8088 --tool-port 7088 --user devkit
|
|
294
|
+
sudo npx --yes huaweicloud-devkit uninstall-server # add --remove-user to delete the service user
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
What it provisions:
|
|
298
|
+
|
|
299
|
+
- Dedicated system user (default `devkit`, nologin shell) that runs both services
|
|
300
|
+
- `huaweicloud-devkit.service` (business port, default 8088) and `huaweicloud-devkit-tool.service` (tool port, default 7088)
|
|
301
|
+
- Generated auth password at `<install-path>/devkit/server/.auth-password` (0600, owned by the service user); every RPC requires `Authorization: Bearer <password>` or `x-devkit-password: <password>` — `GET /health` stays open for probes
|
|
302
|
+
- Self-contained runtime under `<install-path>/devkit/app` (Node.js 22+ is auto-provisioned when missing)
|
|
303
|
+
- Idempotent: re-running refreshes services; add `--rotate-password` to regenerate the password
|
|
304
|
+
|
|
287
305
|
### Install KooCLI
|
|
288
306
|
|
|
289
307
|
```bash
|
package/README.zh-CN.md
CHANGED
|
@@ -280,6 +280,24 @@ npx --yes huaweicloud-devkit-mcp --transport remote
|
|
|
280
280
|
|
|
281
281
|
> 端口被占用时用 `--port <端口>` 换端口,`url` 同步修改;需要局域网访问时加 `--host 0.0.0.0`。remote 服务器不内置鉴权,请勿匿名暴露到公网。
|
|
282
282
|
|
|
283
|
+
### 服务器模式(systemd,Linux)
|
|
284
|
+
|
|
285
|
+
以一对加固的 systemd 服务运行 MCP server:专用 OS 用户 + 自动生成的鉴权密码,适合无人值守/运维环境。
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
sudo npx --yes huaweicloud-devkit install-server # 默认:/opt/kunpeng,业务端口 8088,工具端口 7088,用户 devkit
|
|
289
|
+
sudo npx --yes huaweicloud-devkit install-server --install-path /opt/kunpeng --port 8088 --tool-port 7088 --user devkit
|
|
290
|
+
sudo npx --yes huaweicloud-devkit uninstall-server # 追加 --remove-user 可删除服务用户
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
它会创建:
|
|
294
|
+
|
|
295
|
+
- 专用系统用户(默认 `devkit`,nologin shell),两个服务均以该用户运行
|
|
296
|
+
- `huaweicloud-devkit.service`(业务端口,默认 8088)与 `huaweicloud-devkit-tool.service`(工具端口,默认 7088)
|
|
297
|
+
- 自动生成的鉴权密码 `<install-path>/devkit/server/.auth-password`(0600,属主为服务用户);所有 RPC 需携带 `Authorization: Bearer <密码>` 或 `x-devkit-password: <密码>` —— `GET /health` 保持开放供探活
|
|
298
|
+
- 自包含运行时 `<install-path>/devkit/app`(缺 Node.js 22+ 时自动下载)
|
|
299
|
+
- 幂等可重跑;追加 `--rotate-password` 可重新生成密码
|
|
300
|
+
|
|
283
301
|
### 安装 KooCLI
|
|
284
302
|
|
|
285
303
|
```bash
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"mcpName": "io.github.huaweicloud/huaweicloud-devkit",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.17",
|
|
5
5
|
"kooCliVersion": "7.3.12",
|
|
6
6
|
"description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
|
|
7
7
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"mcpServers": "./.mcp.json",
|
|
18
18
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
19
19
|
"skills": "./skills/",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.17",
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "HuaweiCloud Mate",
|
|
23
23
|
"url": "https://github.com/huaweicloud"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"mcpServers": "./.mcp.json",
|
|
21
21
|
"description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
|
|
22
22
|
"skills": "./skills/",
|
|
23
|
-
"version": "1.1.
|
|
23
|
+
"version": "1.1.17",
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "HuaweiCloud Mate",
|
|
26
26
|
"url": "https://github.com/huaweicloud"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"mcpServers": "./.mcp.json",
|
|
18
18
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
19
19
|
"skills": "./skills/",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.17",
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "HuaweiCloud Mate",
|
|
23
23
|
"url": "https://github.com/huaweicloud"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HuaweiCloud Mate",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HuaweiCloud Mate",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"id": "huaweicloud-devkit",
|
|
4
4
|
"displayName": "HuaweiCloud DevKit",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.17",
|
|
6
6
|
"family": "bundle-plugin",
|
|
7
7
|
"bundleFormat": "codex",
|
|
8
8
|
"description": "Guide coding agents to use Huawei Cloud safely — KooCLI, APIs, SDKs, 28 MCP tools, skills, and safety guardrails.",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
2
3
|
import { resolve } from 'node:path';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { format } from 'node:util';
|
|
@@ -8,13 +9,28 @@ import { dispatch } from './mcp-protocol.mjs';
|
|
|
8
9
|
export const DEFAULT_PORT = 9528;
|
|
9
10
|
export const DEFAULT_HOST = '127.0.0.1';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
// Pure helper: decide whether an HTTP request carries the expected password.
|
|
13
|
+
// Accepted in either the `Authorization: Bearer <pwd>` header or the
|
|
14
|
+
// `x-devkit-password: <pwd>` header. Exported for tests.
|
|
15
|
+
export function verifyAuthPassword(headers, expected) {
|
|
16
|
+
if (!expected) return true;
|
|
17
|
+
const auth = String(headers['authorization'] || '').trim();
|
|
18
|
+
if (auth.startsWith('Bearer ') && auth.slice(7).trim() === expected) return true;
|
|
19
|
+
const direct = String(headers['x-devkit-password'] || '').trim();
|
|
20
|
+
return direct.length > 0 && direct === expected;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function startRemoteServer({ port = DEFAULT_PORT, host = DEFAULT_HOST, authPasswordFile } = {}) {
|
|
24
|
+
let authPassword = '';
|
|
25
|
+
if (authPasswordFile) {
|
|
26
|
+
authPassword = readFileSync(authPasswordFile, 'utf8').trim();
|
|
27
|
+
}
|
|
12
28
|
const server = createServer(async (req, res) => {
|
|
13
29
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
14
30
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
15
31
|
res.setHeader(
|
|
16
32
|
'Access-Control-Allow-Headers',
|
|
17
|
-
'Content-Type, MCP-Protocol-Version, Mcp-Session-Id, Accept, Authorization',
|
|
33
|
+
'Content-Type, MCP-Protocol-Version, Mcp-Session-Id, Accept, Authorization, X-DevKit-Password',
|
|
18
34
|
);
|
|
19
35
|
res.setHeader('Access-Control-Expose-Headers', 'MCP-Protocol-Version, Mcp-Session-Id');
|
|
20
36
|
|
|
@@ -24,6 +40,23 @@ export async function startRemoteServer({ port = DEFAULT_PORT, host = DEFAULT_HO
|
|
|
24
40
|
return;
|
|
25
41
|
}
|
|
26
42
|
|
|
43
|
+
if (req.method === 'GET' && req.url.split('?')[0] === '/health') {
|
|
44
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
45
|
+
res.end(JSON.stringify({ ok: true }));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (authPassword && !verifyAuthPassword(req.headers, authPassword)) {
|
|
50
|
+
res.writeHead(401, {
|
|
51
|
+
'Content-Type': 'application/json',
|
|
52
|
+
'WWW-Authenticate': 'Bearer realm="huaweicloud-devkit-mcp"',
|
|
53
|
+
});
|
|
54
|
+
res.end(
|
|
55
|
+
JSON.stringify({ error: 'Unauthorized', hint: 'send Authorization: Bearer <password> or x-devkit-password' }),
|
|
56
|
+
);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
27
60
|
if (req.method !== 'POST') {
|
|
28
61
|
res.writeHead(405, { Allow: 'POST, OPTIONS' });
|
|
29
62
|
res.end();
|
|
@@ -100,7 +133,9 @@ if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1
|
|
|
100
133
|
const port = portIdx > -1 ? Number(process.argv[portIdx + 1]) : DEFAULT_PORT;
|
|
101
134
|
const hostIdx = process.argv.indexOf('--host');
|
|
102
135
|
const host = hostIdx > -1 && process.argv[hostIdx + 1] ? process.argv[hostIdx + 1] : DEFAULT_HOST;
|
|
103
|
-
|
|
136
|
+
const authIdx = process.argv.indexOf('--auth-password-file');
|
|
137
|
+
const authPasswordFile = authIdx > -1 && process.argv[authIdx + 1] ? resolve(process.argv[authIdx + 1]) : undefined;
|
|
138
|
+
startRemoteServer({ port, host, authPasswordFile }).catch((error) => {
|
|
104
139
|
process.stderr.write(`Failed to start MCP remote server: ${error.message}\n`);
|
|
105
140
|
// eslint-disable-next-line n/no-process-exit -- fatal startup error in standalone CLI mode
|
|
106
141
|
process.exit(1);
|
|
@@ -19,6 +19,9 @@ const portIdx = process.argv.indexOf('--port');
|
|
|
19
19
|
const remotePort = portIdx > -1 ? Number(process.argv[portIdx + 1]) : DEFAULT_PORT;
|
|
20
20
|
const hostIdx = process.argv.indexOf('--host');
|
|
21
21
|
const remoteHost = hostIdx > -1 && process.argv[hostIdx + 1] ? process.argv[hostIdx + 1] : DEFAULT_HOST;
|
|
22
|
+
const authFileIdx = process.argv.indexOf('--auth-password-file');
|
|
23
|
+
const authPasswordFile =
|
|
24
|
+
authFileIdx > -1 && process.argv[authFileIdx + 1] ? resolve(process.argv[authFileIdx + 1]) : undefined;
|
|
22
25
|
|
|
23
26
|
const projectDirIdx = process.argv.indexOf('--codearts-project-dir');
|
|
24
27
|
if (projectDirIdx > -1 && process.argv[projectDirIdx + 1]) {
|
|
@@ -83,7 +86,7 @@ process.nextTick(() => {
|
|
|
83
86
|
|
|
84
87
|
if (transport === 'remote') {
|
|
85
88
|
const { startRemoteServer } = await import('./mcp-server-remote.mjs');
|
|
86
|
-
startRemoteServer({ port: remotePort, host: remoteHost }).catch((error) => {
|
|
89
|
+
startRemoteServer({ port: remotePort, host: remoteHost, authPasswordFile }).catch((error) => {
|
|
87
90
|
process.stderr.write(`Failed to start MCP remote server: ${error.message}\n`);
|
|
88
91
|
// eslint-disable-next-line n/no-process-exit -- fatal startup error; no active session to keep alive
|
|
89
92
|
process.exit(1);
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, openSync, writeSync, closeSync, chmodSync, rmSync } from 'node:fs';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { randomBytes } from 'node:crypto';
|
|
4
|
+
import { join, resolve, dirname } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Deterministic defaults (contest/ops alignment: fixed service names, fixed
|
|
9
|
+
// user, fixed port pair so graders and scripts can discover them).
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_SERVER_INSTALL_PATH = '/opt/kunpeng';
|
|
13
|
+
export const DEFAULT_BUSINESS_PORT = 8088;
|
|
14
|
+
export const DEFAULT_TOOL_PORT = 7088;
|
|
15
|
+
export const DEFAULT_SERVER_USER = 'devkit';
|
|
16
|
+
export const BUSINESS_SERVICE_NAME = 'huaweicloud-devkit.service';
|
|
17
|
+
export const TOOL_SERVICE_NAME = 'huaweicloud-devkit-tool.service';
|
|
18
|
+
export const NODE_VERSION = '22.19.0';
|
|
19
|
+
const NODE_MIRROR = 'https://mirrors.huaweicloud.com/nodejs';
|
|
20
|
+
|
|
21
|
+
// .../plugins/huaweicloud-core/src/server-install.mjs → package root
|
|
22
|
+
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const PACKAGE_ROOT = resolve(MODULE_DIR, '..', '..', '..');
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Pure helpers (unit-testable on any OS)
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
export function parseServerInstallArgs(argv = []) {
|
|
30
|
+
const opts = {
|
|
31
|
+
installPath: DEFAULT_SERVER_INSTALL_PATH,
|
|
32
|
+
port: DEFAULT_BUSINESS_PORT,
|
|
33
|
+
toolPort: DEFAULT_TOOL_PORT,
|
|
34
|
+
user: DEFAULT_SERVER_USER,
|
|
35
|
+
rotatePassword: false,
|
|
36
|
+
removeUser: false,
|
|
37
|
+
};
|
|
38
|
+
for (let i = 0; i < argv.length; i++) {
|
|
39
|
+
const arg = argv[i];
|
|
40
|
+
const value = () => {
|
|
41
|
+
const v = argv[i + 1];
|
|
42
|
+
if (!v || v.startsWith('--')) {
|
|
43
|
+
throw new Error(`Missing value for ${arg}`);
|
|
44
|
+
}
|
|
45
|
+
i += 1;
|
|
46
|
+
return v;
|
|
47
|
+
};
|
|
48
|
+
if (arg === '--install-path') opts.installPath = value();
|
|
49
|
+
else if (arg === '--port') opts.port = Number(value());
|
|
50
|
+
else if (arg === '--tool-port') opts.toolPort = Number(value());
|
|
51
|
+
else if (arg === '--user') opts.user = value();
|
|
52
|
+
else if (arg === '--rotate-password') opts.rotatePassword = true;
|
|
53
|
+
else if (arg === '--remove-user') opts.removeUser = true;
|
|
54
|
+
else throw new Error(`Unknown option for install-server: ${arg}`);
|
|
55
|
+
}
|
|
56
|
+
if (!Number.isSafeInteger(opts.port) || opts.port < 1024 || opts.port > 65535) {
|
|
57
|
+
throw new Error(`Invalid --port: ${opts.port}`);
|
|
58
|
+
}
|
|
59
|
+
if (!Number.isSafeInteger(opts.toolPort) || opts.toolPort < 1024 || opts.toolPort > 65535) {
|
|
60
|
+
throw new Error(`Invalid --tool-port: ${opts.toolPort}`);
|
|
61
|
+
}
|
|
62
|
+
if (opts.port === opts.toolPort) {
|
|
63
|
+
throw new Error('--port and --tool-port must differ');
|
|
64
|
+
}
|
|
65
|
+
if (!/^[a-z_][a-z0-9_-]{0,31}$/.test(opts.user)) {
|
|
66
|
+
throw new Error(`Invalid --user: ${opts.user}`);
|
|
67
|
+
}
|
|
68
|
+
return opts;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function randomPassword(length = 24) {
|
|
72
|
+
const alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
|
|
73
|
+
const bytes = randomBytes(length);
|
|
74
|
+
let out = '';
|
|
75
|
+
for (const b of bytes) out += alphabet[b % alphabet.length];
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function renderSystemdUnit({
|
|
80
|
+
serviceName,
|
|
81
|
+
description,
|
|
82
|
+
nodePath,
|
|
83
|
+
appEntry,
|
|
84
|
+
port,
|
|
85
|
+
user,
|
|
86
|
+
authPasswordFile,
|
|
87
|
+
unitDir = '/etc/systemd/system',
|
|
88
|
+
}) {
|
|
89
|
+
const unit = [
|
|
90
|
+
'[Unit]',
|
|
91
|
+
`Description=${description}`,
|
|
92
|
+
'After=network.target',
|
|
93
|
+
'',
|
|
94
|
+
'[Service]',
|
|
95
|
+
'Type=simple',
|
|
96
|
+
`ExecStart=${nodePath} ${appEntry} --transport remote --port ${port} --host 0.0.0.0 --auth-password-file ${authPasswordFile}`,
|
|
97
|
+
`Restart=on-failure`,
|
|
98
|
+
'RestartSec=3',
|
|
99
|
+
`User=${user}`,
|
|
100
|
+
'',
|
|
101
|
+
'[Install]',
|
|
102
|
+
'WantedBy=multi-user.target',
|
|
103
|
+
'',
|
|
104
|
+
].join('\n');
|
|
105
|
+
return { unitDir: unitDir.endsWith('/') ? unitDir : `${unitDir}/`, unitPath: `${unitDir}/${serviceName}`, unit };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function nodeArchiveUrl(version, arch = process.arch) {
|
|
109
|
+
const flat = arch === 'arm64' || arch === 'aarch64' ? 'arm64' : 'x64';
|
|
110
|
+
return `${NODE_MIRROR}/v${version}/node-v${version}-linux-${flat}.tar.xz`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function isSupportedPlatform(platform = process.platform) {
|
|
114
|
+
return platform === 'linux';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Shell helpers
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
function run(cmd, args) {
|
|
122
|
+
const res = spawnSync(cmd, args, { encoding: 'utf8' });
|
|
123
|
+
const out = (res.stdout || '').trim();
|
|
124
|
+
const err = (res.stderr || '').trim();
|
|
125
|
+
return { code: res.status, out, err, ok: res.status === 0 };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function runOrDie(cmd, args, what) {
|
|
129
|
+
const res = run(cmd, args);
|
|
130
|
+
if (!res.ok) {
|
|
131
|
+
throw new Error(`${what} failed: ${cmd} ${args.join(' ')}\n${res.err || res.out}`);
|
|
132
|
+
}
|
|
133
|
+
return res;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function writeFileOwner(path, content, owner, mode = 0o644) {
|
|
137
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
138
|
+
const fd = openSync(path, 'w', mode);
|
|
139
|
+
writeSync(fd, content);
|
|
140
|
+
closeSync(fd);
|
|
141
|
+
chmodSync(path, mode);
|
|
142
|
+
if (owner) runOrDie('chown', [`${owner}`, path], `chown ${path}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
// Steps
|
|
147
|
+
// ---------------------------------------------------------------------------
|
|
148
|
+
|
|
149
|
+
function ensureRoot() {
|
|
150
|
+
if (process.getuid && process.getuid() !== 0) {
|
|
151
|
+
throw new Error('install-server must run as root (needs user/group creation and systemd)');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function ensureLinux() {
|
|
156
|
+
if (!isSupportedPlatform()) {
|
|
157
|
+
throw new Error('install-server is Linux-only today (systemd required). Use `install` to configure coding agents.');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function ensureUser(user) {
|
|
162
|
+
const check = run('id', ['-u', user]);
|
|
163
|
+
if (check.ok) return;
|
|
164
|
+
const nologin = ['/usr/sbin/nologin', '/sbin/nologin'].find((p) => existsSync(p)) || '/bin/false';
|
|
165
|
+
runOrDie('useradd', ['--system', '--no-create-home', '--shell', nologin, user], `create system user ${user}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function resolveSystemNode() {
|
|
169
|
+
const res = run('node', ['-v']);
|
|
170
|
+
if (res.ok) {
|
|
171
|
+
const major = Number.parseInt(res.out.replace(/^v/, ''), 10);
|
|
172
|
+
if (Number.isSafeInteger(major) && major >= 22) {
|
|
173
|
+
const where = run('bash', ['-c', 'command -v node']);
|
|
174
|
+
if (where.ok && where.out && !where.out.includes('_npx')) return where.out.trim();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function provisionNode(installPath) {
|
|
181
|
+
const target = join(installPath, 'node');
|
|
182
|
+
const bin = join(target, 'bin', 'node');
|
|
183
|
+
if (existsSync(bin)) return bin;
|
|
184
|
+
const url = nodeArchiveUrl(NODE_VERSION);
|
|
185
|
+
mkdirSync(installPath, { recursive: true });
|
|
186
|
+
console.log(` downloading Node.js v${NODE_VERSION} from ${url}`);
|
|
187
|
+
runOrDie('curl', ['-sL', '--retry', '3', '-o', join(installPath, 'node.tar.xz'), url], 'download Node.js');
|
|
188
|
+
runOrDie('mkdir', ['-p', target], 'mkdir node dir');
|
|
189
|
+
runOrDie(
|
|
190
|
+
'tar',
|
|
191
|
+
['-xJf', join(installPath, 'node.tar.xz'), '-C', target, '--strip-components', '1'],
|
|
192
|
+
'extract Node.js',
|
|
193
|
+
);
|
|
194
|
+
rmSync(join(installPath, 'node.tar.xz'), { force: true });
|
|
195
|
+
return bin;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function installAppDir(installPath, user) {
|
|
199
|
+
const app = join(installPath, 'devkit', 'app');
|
|
200
|
+
rmSync(app, { recursive: true, force: true });
|
|
201
|
+
mkdirSync(app, { recursive: true });
|
|
202
|
+
// copy the running package (bin/ + plugins/ + package.json + node_modules when present)
|
|
203
|
+
const res = run('bash', ['-c', `cp -a ${JSON.stringify(PACKAGE_ROOT)}/. ${JSON.stringify(app)}/`]);
|
|
204
|
+
if (!res.ok) {
|
|
205
|
+
throw new Error(`copy package to ${app} failed: ${res.err || res.out}`);
|
|
206
|
+
}
|
|
207
|
+
rmSync(join(app, '.git'), { recursive: true, force: true });
|
|
208
|
+
runOrDie('chown', ['-R', `${user}:${user}`, join(installPath, 'devkit')], 'chown app dir');
|
|
209
|
+
chmodSync(app, 0o750);
|
|
210
|
+
return app;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function writePasswordFile(installPath, user, { rotate }) {
|
|
214
|
+
const pwFile = join(installPath, 'devkit', 'server', '.auth-password');
|
|
215
|
+
if (existsSync(pwFile) && !rotate) {
|
|
216
|
+
return pwFile;
|
|
217
|
+
}
|
|
218
|
+
const password = randomPassword(24);
|
|
219
|
+
writeFileOwner(pwFile, `${password}\n`, user, 0o600);
|
|
220
|
+
return pwFile;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function writeUnits(installPath, { nodePath, app, port, toolPort, user, pwFile }) {
|
|
224
|
+
const entry = join(app, 'plugins', 'huaweicloud-core', 'src', 'mcp-server.mjs');
|
|
225
|
+
const business = renderSystemdUnit({
|
|
226
|
+
serviceName: BUSINESS_SERVICE_NAME,
|
|
227
|
+
description: 'HuaweiCloud DevKit MCP server (business port)',
|
|
228
|
+
nodePath,
|
|
229
|
+
appEntry: entry,
|
|
230
|
+
port,
|
|
231
|
+
user,
|
|
232
|
+
authPasswordFile: pwFile,
|
|
233
|
+
});
|
|
234
|
+
const tool = renderSystemdUnit({
|
|
235
|
+
serviceName: TOOL_SERVICE_NAME,
|
|
236
|
+
description: 'HuaweiCloud DevKit MCP server (tool port)',
|
|
237
|
+
nodePath,
|
|
238
|
+
appEntry: entry,
|
|
239
|
+
port: toolPort,
|
|
240
|
+
user,
|
|
241
|
+
authPasswordFile: pwFile,
|
|
242
|
+
});
|
|
243
|
+
writeFileOwner(business.unitPath, business.unit, 'root', 0o644);
|
|
244
|
+
writeFileOwner(tool.unitPath, tool.unit, 'root', 0o644);
|
|
245
|
+
runOrDie('systemctl', ['daemon-reload'], 'systemd daemon-reload');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function startServices() {
|
|
249
|
+
runOrDie('systemctl', ['enable', '--now', BUSINESS_SERVICE_NAME], 'enable business service');
|
|
250
|
+
runOrDie('systemctl', ['enable', '--now', TOOL_SERVICE_NAME], 'enable tool service');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function waitHealthy(port, timeoutMs = 15000) {
|
|
254
|
+
const deadline = Date.now() + timeoutMs;
|
|
255
|
+
while (Date.now() < deadline) {
|
|
256
|
+
const res = run('curl', ['-fsS', `http://127.0.0.1:${port}/health`]);
|
|
257
|
+
if (res.ok && res.out.includes('"ok"')) return true;
|
|
258
|
+
const sleep = run('sleep', ['1']);
|
|
259
|
+
if (!sleep.ok) break;
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
// CLI entry points
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
|
|
268
|
+
export async function installServerCli(argv = []) {
|
|
269
|
+
ensureLinux();
|
|
270
|
+
ensureRoot();
|
|
271
|
+
const opts = parseServerInstallArgs(argv);
|
|
272
|
+
const installPath = resolve(opts.installPath);
|
|
273
|
+
console.log(`Installing HuaweiCloud DevKit server under ${installPath}`);
|
|
274
|
+
console.log(` business port: ${opts.port} tool port: ${opts.toolPort} service user: ${opts.user}`);
|
|
275
|
+
|
|
276
|
+
ensureUser(opts.user);
|
|
277
|
+
const nodePath = resolveSystemNode() || provisionNode(installPath);
|
|
278
|
+
const app = installAppDir(installPath, opts.user);
|
|
279
|
+
const pwFile = writePasswordFile(installPath, opts.user, { rotate: opts.rotatePassword });
|
|
280
|
+
writeUnits(installPath, { nodePath, app, port: opts.port, toolPort: opts.toolPort, user: opts.user, pwFile });
|
|
281
|
+
startServices();
|
|
282
|
+
|
|
283
|
+
const okBusiness = waitHealthy(opts.port);
|
|
284
|
+
const okTool = waitHealthy(opts.toolPort);
|
|
285
|
+
if (!okBusiness || !okTool) {
|
|
286
|
+
const failed = !okBusiness ? BUSINESS_SERVICE_NAME : TOOL_SERVICE_NAME;
|
|
287
|
+
console.log(` warning: ${failed} did not report healthy yet; inspect with: journalctl -u ${failed} -n 50`);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
console.log('\nServer install complete:');
|
|
291
|
+
console.log(` install path : ${installPath}/devkit/app`);
|
|
292
|
+
console.log(` service user : ${opts.user}`);
|
|
293
|
+
console.log(` business svc : ${BUSINESS_SERVICE_NAME} -> 0.0.0.0:${opts.port}`);
|
|
294
|
+
console.log(` tool svc : ${TOOL_SERVICE_NAME} -> 0.0.0.0:${opts.toolPort}`);
|
|
295
|
+
console.log(` auth password: ${pwFile} (0600; header: Authorization: Bearer <password> or x-devkit-password)`);
|
|
296
|
+
console.log(' health check : GET http://127.0.0.1:<port>/health');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export async function uninstallServerCli(argv = []) {
|
|
300
|
+
ensureLinux();
|
|
301
|
+
ensureRoot();
|
|
302
|
+
const opts = parseServerInstallArgs(argv);
|
|
303
|
+
run('systemctl', ['disable', '--now', BUSINESS_SERVICE_NAME]);
|
|
304
|
+
run('systemctl', ['disable', '--now', TOOL_SERVICE_NAME]);
|
|
305
|
+
for (const unit of [BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME]) {
|
|
306
|
+
rmSync(`/etc/systemd/system/${unit}`, { force: true });
|
|
307
|
+
}
|
|
308
|
+
run('systemctl', ['daemon-reload']);
|
|
309
|
+
rmSync(join(opts.installPath, 'devkit'), { recursive: true, force: true });
|
|
310
|
+
if (opts.removeUser) {
|
|
311
|
+
run('userdel', [opts.user]);
|
|
312
|
+
console.log(`removed service user: ${opts.user}`);
|
|
313
|
+
}
|
|
314
|
+
console.log('HuaweiCloud DevKit server uninstalled.');
|
|
315
|
+
}
|
|
@@ -18,6 +18,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
18
18
|
|
|
19
19
|
import { getAuthStatus, syncAuth } from './auth/service.mjs';
|
|
20
20
|
import { resolveAndApplyProjectId } from './auth/project-id.mjs';
|
|
21
|
+
import { installServerCli, uninstallServerCli } from './server-install.mjs';
|
|
21
22
|
import { SUPPORTED_AGENT_TARGETS } from './auth/agent-registration.mjs';
|
|
22
23
|
import { fingerprint, readKooCliProfiles, resolveManagedProfile } from './auth/reconcile.mjs';
|
|
23
24
|
import { redactSecrets } from './safety-policy.mjs';
|
|
@@ -5324,6 +5325,12 @@ async function main() {
|
|
|
5324
5325
|
case 'install-hcloud':
|
|
5325
5326
|
await cmdInstallHcloud();
|
|
5326
5327
|
break;
|
|
5328
|
+
case 'install-server':
|
|
5329
|
+
await installServerCli(process.argv.slice(3));
|
|
5330
|
+
break;
|
|
5331
|
+
case 'uninstall-server':
|
|
5332
|
+
await uninstallServerCli(process.argv.slice(3));
|
|
5333
|
+
break;
|
|
5327
5334
|
case 'auth':
|
|
5328
5335
|
await cmdAuth();
|
|
5329
5336
|
break;
|
|
@@ -5352,6 +5359,8 @@ async function main() {
|
|
|
5352
5359
|
console.log(' status Show installation status');
|
|
5353
5360
|
console.log(' doctor Self-check: hcloud, MCP, skills, auth');
|
|
5354
5361
|
console.log(' install-hcloud Show KooCLI install commands for your OS');
|
|
5362
|
+
console.log(' install-server Server mode: systemd services + dedicated user + auth password (Linux root)');
|
|
5363
|
+
console.log(' uninstall-server Remove server-mode services and files');
|
|
5355
5364
|
console.log(' auth Manage unified auth: init | sync | status | reconcile');
|
|
5356
5365
|
console.log(' proxy Manage proxy config: init | show | clear');
|
|
5357
5366
|
console.log(' version Print CLI version and installed plugin version per agent');
|
|
@@ -5367,6 +5376,13 @@ async function main() {
|
|
|
5367
5376
|
console.log(' --clean-kocli (with: uninstall --target all) also remove KooCLI');
|
|
5368
5377
|
console.log(' --clean-obs (with: uninstall --target all) also remove OBS config');
|
|
5369
5378
|
console.log(' --clean-global (with: uninstall --target all) also remove KooCLI + OBS config');
|
|
5379
|
+
console.log('\ninstall-server options:');
|
|
5380
|
+
console.log(' --install-path <dir> Base install path (default /opt/kunpeng)');
|
|
5381
|
+
console.log(' --port <n> Business port (default 8088)');
|
|
5382
|
+
console.log(' --tool-port <n> Tool port (default 7088)');
|
|
5383
|
+
console.log(' --user <name> Dedicated service user (default devkit)');
|
|
5384
|
+
console.log(' --rotate-password Regenerate the server auth password');
|
|
5385
|
+
console.log(' --remove-user (with: uninstall-server) also delete the service user');
|
|
5370
5386
|
console.log('\nExamples:');
|
|
5371
5387
|
console.log(' npx huaweicloud-devkit install');
|
|
5372
5388
|
console.log(' npx huaweicloud-devkit install --target codex');
|