huaweicloud-devkit 2.0.1-next.2 → 2.0.1-next.4
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 +26 -3
- package/README.zh-CN.md +24 -1
- 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/.mcp.json +3 -0
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/approval-roster.js +2 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +7 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +30 -1
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +21 -0
- package/plugins/huaweicloud-core/dist/mcp-server.js +4227 -3049
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/registry.js +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +13 -2
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +198 -10
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +11 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +22 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +46 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-upload.js +11 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +20 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +26 -18
- package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +97 -0
- package/plugins/huaweicloud-core/dist/sandbox/deploy-nginx.js +30 -14
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-backend.js +37 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-connections.js +84 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-client.js +229 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-protocol.js +151 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-transport.js +121 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-service-api.js +80 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-upload.js +106 -0
- package/plugins/huaweicloud-core/dist/sandbox/hwlink-connection.js +12 -0
- package/plugins/huaweicloud-core/dist/sandbox/upload-project.js +5 -2
- package/plugins/huaweicloud-core/dist/server-install.js +363 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +16 -0
- package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
- package/plugins/huaweicloud-core/dist/tools.js +1 -0
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/policy.json +2 -1
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +67 -16
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/devbox-backend.md +78 -0
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +14 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +2 -1
- package/plugins/huaweicloud-core/src/approval-roster.ts +2 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +7 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +30 -1
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +22 -0
- package/plugins/huaweicloud-core/src/mcp-server-remote.ts +68 -5
- package/plugins/huaweicloud-core/src/mcp-server.ts +4 -1
- package/plugins/huaweicloud-core/src/packs/registry.ts +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +15 -2
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +206 -11
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +12 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +23 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +49 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-upload.ts +11 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +23 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +27 -17
- package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +105 -0
- package/plugins/huaweicloud-core/src/sandbox/deploy-nginx.ts +36 -18
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-backend.ts +44 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-connections.ts +115 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-client.ts +281 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-protocol.ts +180 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-transport.ts +142 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-service-api.ts +102 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-upload.ts +167 -0
- package/plugins/huaweicloud-core/src/sandbox/hwlink-connection.ts +12 -0
- package/plugins/huaweicloud-core/src/sandbox/upload-project.ts +5 -2
- package/plugins/huaweicloud-core/src/server-install.ts +442 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +16 -0
- package/plugins/huaweicloud-core/src/tool-definitions.ts +4 -0
- package/plugins/huaweicloud-core/src/tools.ts +3 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeSync } from 'node:fs';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { randomInt } from 'node:crypto';
|
|
4
|
+
import { dirname, join, resolve } 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). These
|
|
10
|
+
// mirror the v1 installer's values one-for-one so one grading script covers
|
|
11
|
+
// both release lines.
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_SERVER_INSTALL_PATH = '/opt/kunpeng';
|
|
15
|
+
export const DEFAULT_BUSINESS_PORT = 8088;
|
|
16
|
+
export const DEFAULT_TOOL_PORT = 7088;
|
|
17
|
+
export const DEFAULT_SERVER_USER = 'devkit';
|
|
18
|
+
export const BUSINESS_SERVICE_NAME = 'huaweicloud-devkit.service';
|
|
19
|
+
export const TOOL_SERVICE_NAME = 'huaweicloud-devkit-tool.service';
|
|
20
|
+
export const NODE_VERSION = '22.19.0';
|
|
21
|
+
const NODE_MIRROR = 'https://mirrors.huaweicloud.com/nodejs';
|
|
22
|
+
|
|
23
|
+
// The running module may be an individually compiled dist file (setup-cli
|
|
24
|
+
// loads it as dist/server-install.js) or inlined inside the bundled server
|
|
25
|
+
// entry. Walking up to the nearest package.json *named like this package*
|
|
26
|
+
// is robust against both layouts; the v1 installer's fixed three-levels-up
|
|
27
|
+
// resolve shipped a one-level-off copy bug before it was patched, so the
|
|
28
|
+
// walk is also the validation.
|
|
29
|
+
function resolvePackageRoot(startDir: string): string {
|
|
30
|
+
let current = startDir;
|
|
31
|
+
for (let depth = 0; depth < 8; depth++) {
|
|
32
|
+
const manifest = join(current, 'package.json');
|
|
33
|
+
if (existsSync(manifest)) {
|
|
34
|
+
let name: unknown;
|
|
35
|
+
try {
|
|
36
|
+
({ name } = JSON.parse(readFileSync(manifest, 'utf8')) as { name?: unknown });
|
|
37
|
+
} catch {
|
|
38
|
+
throw new Error(`unreadable package manifest while locating the install root: ${manifest}`);
|
|
39
|
+
}
|
|
40
|
+
if (name === 'huaweicloud-devkit') return current;
|
|
41
|
+
}
|
|
42
|
+
const parent = dirname(current);
|
|
43
|
+
if (parent === current) break;
|
|
44
|
+
current = parent;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`could not locate the huaweicloud-devkit package root above ${startDir}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
50
|
+
const PACKAGE_ROOT = resolvePackageRoot(MODULE_DIR);
|
|
51
|
+
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Pure helpers (unit-testable on any OS)
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
export interface ServerInstallOptions {
|
|
57
|
+
installPath: string;
|
|
58
|
+
port: number;
|
|
59
|
+
toolPort: number;
|
|
60
|
+
user: string;
|
|
61
|
+
rotatePassword: boolean;
|
|
62
|
+
removeUser: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function parseServerInstallArgs(argv: readonly string[] = []): ServerInstallOptions {
|
|
66
|
+
const opts: ServerInstallOptions = {
|
|
67
|
+
installPath: DEFAULT_SERVER_INSTALL_PATH,
|
|
68
|
+
port: DEFAULT_BUSINESS_PORT,
|
|
69
|
+
toolPort: DEFAULT_TOOL_PORT,
|
|
70
|
+
user: DEFAULT_SERVER_USER,
|
|
71
|
+
rotatePassword: false,
|
|
72
|
+
removeUser: false,
|
|
73
|
+
};
|
|
74
|
+
for (let i = 0; i < argv.length; i++) {
|
|
75
|
+
const arg = argv[i];
|
|
76
|
+
if (arg === undefined) break;
|
|
77
|
+
const value = (): string => {
|
|
78
|
+
const next = argv[i + 1];
|
|
79
|
+
if (!next || next.startsWith('--')) {
|
|
80
|
+
throw new Error(`Missing value for ${arg}`);
|
|
81
|
+
}
|
|
82
|
+
i += 1;
|
|
83
|
+
return next;
|
|
84
|
+
};
|
|
85
|
+
if (arg === '--install-path') opts.installPath = value();
|
|
86
|
+
else if (arg === '--port') opts.port = Number(value());
|
|
87
|
+
else if (arg === '--tool-port') opts.toolPort = Number(value());
|
|
88
|
+
else if (arg === '--user') opts.user = value();
|
|
89
|
+
else if (arg === '--rotate-password') opts.rotatePassword = true;
|
|
90
|
+
else if (arg === '--remove-user') opts.removeUser = true;
|
|
91
|
+
else throw new Error(`Unknown option for install-server: ${arg}`);
|
|
92
|
+
}
|
|
93
|
+
if (!Number.isSafeInteger(opts.port) || opts.port < 1024 || opts.port > 65535) {
|
|
94
|
+
throw new Error(`Invalid --port: ${opts.port}`);
|
|
95
|
+
}
|
|
96
|
+
if (!Number.isSafeInteger(opts.toolPort) || opts.toolPort < 1024 || opts.toolPort > 65535) {
|
|
97
|
+
throw new Error(`Invalid --tool-port: ${opts.toolPort}`);
|
|
98
|
+
}
|
|
99
|
+
if (opts.port === opts.toolPort) {
|
|
100
|
+
throw new Error('--port and --tool-port must differ');
|
|
101
|
+
}
|
|
102
|
+
if (!/^[a-z_][a-z0-9_-]{0,31}$/.test(opts.user)) {
|
|
103
|
+
throw new Error(`Invalid --user: ${opts.user}`);
|
|
104
|
+
}
|
|
105
|
+
return opts;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Deconfusable alphabet (no 0/O/1/I/l): the password is transcribed by
|
|
109
|
+
// humans from a headless server terminal exactly once, at install time.
|
|
110
|
+
// randomInt samples each character uniformly — a modulo of randomBytes
|
|
111
|
+
// would bias the first two alphabet entries (256 % 56 != 0).
|
|
112
|
+
export function randomPassword(length = 24): string {
|
|
113
|
+
const alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
|
|
114
|
+
let out = '';
|
|
115
|
+
for (let i = 0; i < length; i++) out += alphabet[randomInt(0, alphabet.length)];
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SystemdUnitRender {
|
|
120
|
+
unitDir: string;
|
|
121
|
+
unitPath: string;
|
|
122
|
+
unit: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function renderSystemdUnit({
|
|
126
|
+
serviceName,
|
|
127
|
+
description,
|
|
128
|
+
nodePath,
|
|
129
|
+
appEntry,
|
|
130
|
+
port,
|
|
131
|
+
user,
|
|
132
|
+
authPasswordFile,
|
|
133
|
+
unitDir = '/etc/systemd/system',
|
|
134
|
+
}: {
|
|
135
|
+
serviceName: string;
|
|
136
|
+
description: string;
|
|
137
|
+
nodePath: string;
|
|
138
|
+
appEntry: string;
|
|
139
|
+
port: number;
|
|
140
|
+
user: string;
|
|
141
|
+
authPasswordFile: string;
|
|
142
|
+
unitDir?: string;
|
|
143
|
+
}): SystemdUnitRender {
|
|
144
|
+
const unit = [
|
|
145
|
+
'[Unit]',
|
|
146
|
+
`Description=${description}`,
|
|
147
|
+
'After=network.target',
|
|
148
|
+
'',
|
|
149
|
+
'[Service]',
|
|
150
|
+
'Type=simple',
|
|
151
|
+
`ExecStart=${nodePath} ${appEntry} --transport remote --port ${port} --host 0.0.0.0 --auth-password-file ${authPasswordFile}`,
|
|
152
|
+
'Restart=on-failure',
|
|
153
|
+
'RestartSec=3',
|
|
154
|
+
`User=${user}`,
|
|
155
|
+
'',
|
|
156
|
+
'[Install]',
|
|
157
|
+
'WantedBy=multi-user.target',
|
|
158
|
+
'',
|
|
159
|
+
].join('\n');
|
|
160
|
+
return {
|
|
161
|
+
unitDir: unitDir.endsWith('/') ? unitDir : `${unitDir}/`,
|
|
162
|
+
unitPath: `${unitDir}/${serviceName}`,
|
|
163
|
+
unit,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function nodeArchiveUrl(version: string, arch: string = process.arch): string {
|
|
168
|
+
const flat = arch === 'arm64' || arch === 'aarch64' ? 'arm64' : 'x64';
|
|
169
|
+
return `${NODE_MIRROR}/v${version}/node-v${version}-linux-${flat}.tar.xz`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function isSupportedPlatform(platform: string = process.platform): boolean {
|
|
173
|
+
return platform === 'linux';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
// Shell helpers
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
|
|
180
|
+
interface ShellResult {
|
|
181
|
+
code: number | null;
|
|
182
|
+
out: string;
|
|
183
|
+
err: string;
|
|
184
|
+
ok: boolean;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function run(cmd: string, args: string[]): ShellResult {
|
|
188
|
+
const res = spawnSync(cmd, args, { encoding: 'utf8' });
|
|
189
|
+
const out = (res.stdout ?? '').trim();
|
|
190
|
+
const err = (res.stderr ?? '').trim();
|
|
191
|
+
return { code: res.status, out, err, ok: res.status === 0 };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function runOrDie(cmd: string, args: string[], what: string): ShellResult {
|
|
195
|
+
const res = run(cmd, args);
|
|
196
|
+
if (!res.ok) {
|
|
197
|
+
throw new Error(`${what} failed: ${cmd} ${args.join(' ')}\n${res.err || res.out}`);
|
|
198
|
+
}
|
|
199
|
+
return res;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function writeFileOwner(path: string, content: string, owner: string | null, mode = 0o644): void {
|
|
203
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
204
|
+
const fd = openSync(path, 'w', mode);
|
|
205
|
+
writeSync(fd, content);
|
|
206
|
+
closeSync(fd);
|
|
207
|
+
chmodSync(path, mode);
|
|
208
|
+
if (owner) runOrDie('chown', [owner, path], `chown ${path}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ---------------------------------------------------------------------------
|
|
212
|
+
// Steps
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
|
|
215
|
+
function ensureRoot(): void {
|
|
216
|
+
if (typeof process.getuid === 'function' && process.getuid() !== 0) {
|
|
217
|
+
throw new Error('install-server must run as root (needs user/group creation and systemd)');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function ensureLinux(): void {
|
|
222
|
+
if (!isSupportedPlatform()) {
|
|
223
|
+
throw new Error('install-server is Linux-only today (systemd required). Use `install` to configure coding agents.');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function ensureUser(user: string): void {
|
|
228
|
+
const check = run('id', ['-u', user]);
|
|
229
|
+
if (check.ok) return;
|
|
230
|
+
const nologin = ['/usr/sbin/nologin', '/sbin/nologin'].find((p) => existsSync(p)) || '/bin/false';
|
|
231
|
+
runOrDie('useradd', ['--system', '--no-create-home', '--shell', nologin, user], `create system user ${user}`);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function resolveSystemNode(): string | null {
|
|
235
|
+
const res = run('node', ['-v']);
|
|
236
|
+
if (res.ok) {
|
|
237
|
+
const major = Number.parseInt(res.out.replace(/^v/, ''), 10);
|
|
238
|
+
if (Number.isSafeInteger(major) && major >= 22) {
|
|
239
|
+
const where = run('bash', ['-c', 'command -v node']);
|
|
240
|
+
// An npx-shim node dies with the cache; the service must not pin it.
|
|
241
|
+
if (where.ok && where.out && !where.out.includes('_npx')) return where.out.trim();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function provisionNode(installPath: string): string {
|
|
248
|
+
const target = join(installPath, 'node');
|
|
249
|
+
const bin = join(target, 'bin', 'node');
|
|
250
|
+
if (existsSync(bin)) return bin;
|
|
251
|
+
const url = nodeArchiveUrl(NODE_VERSION);
|
|
252
|
+
mkdirSync(installPath, { recursive: true });
|
|
253
|
+
console.log(` downloading Node.js v${NODE_VERSION} from ${url}`);
|
|
254
|
+
runOrDie('curl', ['-sL', '--retry', '3', '-o', join(installPath, 'node.tar.xz'), url], 'download Node.js');
|
|
255
|
+
runOrDie('mkdir', ['-p', target], 'mkdir node dir');
|
|
256
|
+
runOrDie(
|
|
257
|
+
'tar',
|
|
258
|
+
['-xJf', join(installPath, 'node.tar.xz'), '-C', target, '--strip-components', '1'],
|
|
259
|
+
'extract Node.js',
|
|
260
|
+
);
|
|
261
|
+
rmSync(join(installPath, 'node.tar.xz'), { force: true });
|
|
262
|
+
return bin;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function installAppDir(installPath: string, user: string): string {
|
|
266
|
+
const app = join(installPath, 'devkit', 'app');
|
|
267
|
+
rmSync(app, { recursive: true, force: true });
|
|
268
|
+
mkdirSync(app, { recursive: true });
|
|
269
|
+
// Copy the running package (bin/ + plugins/ + package.json + node_modules
|
|
270
|
+
// when present) so the service is self-contained. Direct argv, no shell:
|
|
271
|
+
// every path component stays a literal argument.
|
|
272
|
+
const res = run('cp', ['-a', `${PACKAGE_ROOT}/.`, `${app}/`]);
|
|
273
|
+
if (!res.ok) {
|
|
274
|
+
throw new Error(`copy package to ${app} failed: ${res.err || res.out}`);
|
|
275
|
+
}
|
|
276
|
+
rmSync(join(app, '.git'), { recursive: true, force: true });
|
|
277
|
+
runOrDie('chown', ['-R', `${user}:${user}`, join(installPath, 'devkit')], 'chown app dir');
|
|
278
|
+
chmodSync(app, 0o750);
|
|
279
|
+
return app;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function writePasswordFile(installPath: string, user: string, rotate: boolean): string {
|
|
283
|
+
const pwFile = join(installPath, 'devkit', 'server', '.auth-password');
|
|
284
|
+
if (existsSync(pwFile) && !rotate) {
|
|
285
|
+
return pwFile;
|
|
286
|
+
}
|
|
287
|
+
const password = randomPassword(24);
|
|
288
|
+
writeFileOwner(pwFile, `${password}\n`, user, 0o600);
|
|
289
|
+
return pwFile;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function writeUnits(
|
|
293
|
+
installPath: string,
|
|
294
|
+
params: { nodePath: string; app: string; port: number; toolPort: number; user: string; pwFile: string },
|
|
295
|
+
): void {
|
|
296
|
+
// The dist bundle, not the TypeScript sources: the remote transport ships
|
|
297
|
+
// only inside the bundled entry (the individual mcp-server-remote.js is
|
|
298
|
+
// removed from dist by the build), so this is the one runnable path — the
|
|
299
|
+
// same file the `huaweicloud-devkit-mcp` bin resolves to.
|
|
300
|
+
const entry = join(params.app, 'plugins', 'huaweicloud-core', 'dist', 'mcp-server.js');
|
|
301
|
+
const business = renderSystemdUnit({
|
|
302
|
+
serviceName: BUSINESS_SERVICE_NAME,
|
|
303
|
+
description: 'HuaweiCloud DevKit MCP server (business port)',
|
|
304
|
+
nodePath: params.nodePath,
|
|
305
|
+
appEntry: entry,
|
|
306
|
+
port: params.port,
|
|
307
|
+
user: params.user,
|
|
308
|
+
authPasswordFile: params.pwFile,
|
|
309
|
+
});
|
|
310
|
+
const tool = renderSystemdUnit({
|
|
311
|
+
serviceName: TOOL_SERVICE_NAME,
|
|
312
|
+
description: 'HuaweiCloud DevKit MCP server (tool port)',
|
|
313
|
+
nodePath: params.nodePath,
|
|
314
|
+
appEntry: entry,
|
|
315
|
+
port: params.toolPort,
|
|
316
|
+
user: params.user,
|
|
317
|
+
authPasswordFile: params.pwFile,
|
|
318
|
+
});
|
|
319
|
+
writeFileOwner(business.unitPath, business.unit, 'root', 0o644);
|
|
320
|
+
writeFileOwner(tool.unitPath, tool.unit, 'root', 0o644);
|
|
321
|
+
runOrDie('systemctl', ['daemon-reload'], 'systemd daemon-reload');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Pure command plan so the service lifecycle stays unit-testable:
|
|
325
|
+
// `enable` marks the units for boot without starting them; a single
|
|
326
|
+
// joint `restart` then starts fresh installs AND picks up rewritten files
|
|
327
|
+
// (e.g. a rotated auth password) on re-runs in one systemd call.
|
|
328
|
+
export interface ServiceCommand {
|
|
329
|
+
cmd: string;
|
|
330
|
+
args: string[];
|
|
331
|
+
label: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function planServiceCommands(): ServiceCommand[] {
|
|
335
|
+
return [
|
|
336
|
+
{
|
|
337
|
+
cmd: 'systemctl',
|
|
338
|
+
args: ['enable', BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME],
|
|
339
|
+
label: 'enable services',
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
cmd: 'systemctl',
|
|
343
|
+
args: ['restart', BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME],
|
|
344
|
+
label: 'restart services',
|
|
345
|
+
},
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// One joint restart call removes the serial-restart failure window (the
|
|
350
|
+
// first restart succeeding and the second erroring, leaving one unit
|
|
351
|
+
// restarted and the other untouched). It is not a transaction: systemd
|
|
352
|
+
// enqueues the two units' jobs independently, so a mid-call failure can
|
|
353
|
+
// still land between them — but any failure aborts the install at
|
|
354
|
+
// runOrDie before "install complete" is ever printed.
|
|
355
|
+
function startServices(): void {
|
|
356
|
+
for (const { cmd, args, label } of planServiceCommands()) {
|
|
357
|
+
runOrDie(cmd, args, label);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function waitHealthy(port: number, timeoutMs = 15000): boolean {
|
|
362
|
+
const deadline = Date.now() + timeoutMs;
|
|
363
|
+
while (Date.now() < deadline) {
|
|
364
|
+
const res = run('curl', ['-fsS', `http://127.0.0.1:${port}/health`]);
|
|
365
|
+
if (res.ok && res.out.includes('"ok"')) return true;
|
|
366
|
+
const sleep = run('sleep', ['1']);
|
|
367
|
+
if (!sleep.ok) break;
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// The installer never mutates firewall state — punching network holes is a
|
|
373
|
+
// security decision the operator makes knowingly. When firewalld is active
|
|
374
|
+
// we print the exact commands so the step is copy-paste instead of research.
|
|
375
|
+
function printFirewallHint(port: number, toolPort: number): void {
|
|
376
|
+
const state = run('firewall-cmd', ['--state']);
|
|
377
|
+
if (state.ok && state.out === 'running') {
|
|
378
|
+
console.log('\nFirewalld is active on this host; the installer did not change firewall rules.');
|
|
379
|
+
console.log('Open the service ports yourself if external access is intended:');
|
|
380
|
+
console.log(` firewall-cmd --permanent --add-port=${port}/tcp`);
|
|
381
|
+
console.log(` firewall-cmd --permanent --add-port=${toolPort}/tcp`);
|
|
382
|
+
console.log(' firewall-cmd --reload');
|
|
383
|
+
} else {
|
|
384
|
+
console.log(
|
|
385
|
+
'\nNote: firewall rules were not changed. If external clients will connect, open the service ports per your distro (firewalld/ufw/iptables).',
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ---------------------------------------------------------------------------
|
|
391
|
+
// CLI entry points
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
export async function installServerCli(argv: readonly string[] = []): Promise<void> {
|
|
395
|
+
ensureLinux();
|
|
396
|
+
ensureRoot();
|
|
397
|
+
const opts = parseServerInstallArgs(argv);
|
|
398
|
+
const installPath = resolve(opts.installPath);
|
|
399
|
+
console.log(`Installing HuaweiCloud DevKit server under ${installPath}`);
|
|
400
|
+
console.log(` business port: ${opts.port} tool port: ${opts.toolPort} service user: ${opts.user}`);
|
|
401
|
+
|
|
402
|
+
ensureUser(opts.user);
|
|
403
|
+
const nodePath = resolveSystemNode() || provisionNode(installPath);
|
|
404
|
+
const app = installAppDir(installPath, opts.user);
|
|
405
|
+
const pwFile = writePasswordFile(installPath, opts.user, opts.rotatePassword);
|
|
406
|
+
writeUnits(installPath, { nodePath, app, port: opts.port, toolPort: opts.toolPort, user: opts.user, pwFile });
|
|
407
|
+
startServices();
|
|
408
|
+
|
|
409
|
+
const okBusiness = waitHealthy(opts.port);
|
|
410
|
+
const okTool = waitHealthy(opts.toolPort);
|
|
411
|
+
if (!okBusiness || !okTool) {
|
|
412
|
+
const failed = !okBusiness ? BUSINESS_SERVICE_NAME : TOOL_SERVICE_NAME;
|
|
413
|
+
console.log(` warning: ${failed} did not report healthy yet; inspect with: journalctl -u ${failed} -n 50`);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
console.log('\nServer install complete:');
|
|
417
|
+
console.log(` install path : ${installPath}/devkit/app`);
|
|
418
|
+
console.log(` service user : ${opts.user}`);
|
|
419
|
+
console.log(` business svc : ${BUSINESS_SERVICE_NAME} -> 0.0.0.0:${opts.port}`);
|
|
420
|
+
console.log(` tool svc : ${TOOL_SERVICE_NAME} -> 0.0.0.0:${opts.toolPort}`);
|
|
421
|
+
console.log(` auth password: ${pwFile} (0600; header: Authorization: Bearer <password> or x-devkit-password)`);
|
|
422
|
+
console.log(' health check : GET http://127.0.0.1:<port>/health');
|
|
423
|
+
printFirewallHint(opts.port, opts.toolPort);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export async function uninstallServerCli(argv: readonly string[] = []): Promise<void> {
|
|
427
|
+
ensureLinux();
|
|
428
|
+
ensureRoot();
|
|
429
|
+
const opts = parseServerInstallArgs(argv);
|
|
430
|
+
run('systemctl', ['disable', '--now', BUSINESS_SERVICE_NAME]);
|
|
431
|
+
run('systemctl', ['disable', '--now', TOOL_SERVICE_NAME]);
|
|
432
|
+
for (const unit of [BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME]) {
|
|
433
|
+
rmSync(`/etc/systemd/system/${unit}`, { force: true });
|
|
434
|
+
}
|
|
435
|
+
run('systemctl', ['daemon-reload']);
|
|
436
|
+
rmSync(join(opts.installPath, 'devkit'), { recursive: true, force: true });
|
|
437
|
+
if (opts.removeUser) {
|
|
438
|
+
run('userdel', [opts.user]);
|
|
439
|
+
console.log(`removed service user: ${opts.user}`);
|
|
440
|
+
}
|
|
441
|
+
console.log('HuaweiCloud DevKit server uninstalled.');
|
|
442
|
+
}
|
|
@@ -36,6 +36,7 @@ import { removeKooCli, removeObsConfig } from './sandbox/uninstall-cleanup.ts';
|
|
|
36
36
|
import { readReceipt, removeReceipt } from './dep/receipts.ts';
|
|
37
37
|
import { runSecretCommand } from './lib/secret-vault/cli.ts';
|
|
38
38
|
import { createProcessApproveIo, runApproveCommand, runPinCommand } from './approvals-cli.ts';
|
|
39
|
+
import { installServerCli, uninstallServerCli } from './server-install.ts';
|
|
39
40
|
import { readConsentEvents } from './approval-ledger.ts';
|
|
40
41
|
import { custodyReport } from './lib/secret-vault/custody.ts';
|
|
41
42
|
import { vaultList } from './lib/secret-vault/store.ts';
|
|
@@ -1542,6 +1543,12 @@ async function main(): Promise<void> {
|
|
|
1542
1543
|
case 'install-hcloud':
|
|
1543
1544
|
await cmdInstallHcloud();
|
|
1544
1545
|
break;
|
|
1546
|
+
case 'install-server':
|
|
1547
|
+
await installServerCli(process.argv.slice(3));
|
|
1548
|
+
break;
|
|
1549
|
+
case 'uninstall-server':
|
|
1550
|
+
await uninstallServerCli(process.argv.slice(3));
|
|
1551
|
+
break;
|
|
1545
1552
|
case 'dep':
|
|
1546
1553
|
await cmdDep();
|
|
1547
1554
|
break;
|
|
@@ -1585,6 +1592,8 @@ async function main(): Promise<void> {
|
|
|
1585
1592
|
console.log(' status Show installation status');
|
|
1586
1593
|
console.log(' doctor Self-check: hcloud, MCP, skills, auth');
|
|
1587
1594
|
console.log(' install-hcloud Show KooCLI install commands for your OS');
|
|
1595
|
+
console.log(' install-server Server mode: systemd services + dedicated user + auth password (Linux root)');
|
|
1596
|
+
console.log(' uninstall-server Remove server-mode services and files');
|
|
1588
1597
|
console.log(' dep Dependency tooling: status | install <id> | uninstall <id>');
|
|
1589
1598
|
console.log(' packs Post-install pack surface: status | enable <ids> | disable <ids> | all');
|
|
1590
1599
|
console.log(' auth Manage unified auth: init | sync | status | reconcile');
|
|
@@ -1609,6 +1618,13 @@ async function main(): Promise<void> {
|
|
|
1609
1618
|
console.log(
|
|
1610
1619
|
' --clean-global (with: uninstall --target all) also remove KooCLI + OBS config + open-mcp-gateway',
|
|
1611
1620
|
);
|
|
1621
|
+
console.log('\ninstall-server options:');
|
|
1622
|
+
console.log(' --install-path <dir> Base install path (default /opt/kunpeng)');
|
|
1623
|
+
console.log(' --port <n> Business port (default 8088)');
|
|
1624
|
+
console.log(' --tool-port <n> Tool port (default 7088)');
|
|
1625
|
+
console.log(' --user <name> Dedicated service user (default devkit)');
|
|
1626
|
+
console.log(' --rotate-password Regenerate the server auth password');
|
|
1627
|
+
console.log(' --remove-user (with: uninstall-server) also delete the service user');
|
|
1612
1628
|
console.log('\nExamples:');
|
|
1613
1629
|
console.log(' npx huaweicloud-devkit install');
|
|
1614
1630
|
console.log(' npx huaweicloud-devkit install --target codex');
|
|
@@ -210,6 +210,10 @@ export const TOOL_DEFINITIONS_LITERALS = [
|
|
|
210
210
|
name: 'huaweicloud_sandbox_shutdown',
|
|
211
211
|
description: packDescription('huaweicloud_sandbox_shutdown'),
|
|
212
212
|
},
|
|
213
|
+
{
|
|
214
|
+
name: 'huaweicloud_sandbox_kill',
|
|
215
|
+
description: packDescription('huaweicloud_sandbox_kill'),
|
|
216
|
+
},
|
|
213
217
|
{
|
|
214
218
|
name: 'huaweicloud_voucher_status',
|
|
215
219
|
description: packDescription('huaweicloud_voucher_status'),
|
|
@@ -146,6 +146,8 @@ export type ToolArgs = {
|
|
|
146
146
|
workspace_id?: string;
|
|
147
147
|
username?: string;
|
|
148
148
|
timeout_ms?: number;
|
|
149
|
+
/** Devbox sandbox TTL in seconds (connect/refresh). */
|
|
150
|
+
timeout_seconds?: number;
|
|
149
151
|
// The async-exec claim protocol (huaweicloud_sandbox_exec_one_shot mode:
|
|
150
152
|
// "async" + huaweicloud_sandbox_exec_poll).
|
|
151
153
|
task_id?: string;
|
|
@@ -246,6 +248,7 @@ const NUMERIC_ARG_KEYS = [
|
|
|
246
248
|
'node_port',
|
|
247
249
|
'public_port',
|
|
248
250
|
'expiry_hours',
|
|
251
|
+
'timeout_seconds',
|
|
249
252
|
] as const;
|
|
250
253
|
|
|
251
254
|
function normalizeNumericArgs(args: ToolArgs): ToolArgs {
|