huaweicloud-devkit 2.0.1-next.1 → 2.0.1-next.3
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 +24 -1
- 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/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +5 -0
- package/plugins/huaweicloud-core/dist/mcp-server.js +68 -11
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +3 -3
- package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +55 -0
- package/plugins/huaweicloud-core/dist/server-install.js +363 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +16 -0
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/create-instance.md +2 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +3 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +4 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +6 -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/safety/classify-hcloud.ts +64 -0
- package/plugins/huaweicloud-core/src/server-install.ts +442 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +16 -0
|
@@ -7,6 +7,17 @@ import { findHcloudCommandSegments } from "./segments.js";
|
|
|
7
7
|
import { OBSUTIL_WRITES } from "./tokens.js";
|
|
8
8
|
import { stripExecutable } from "./unwrap.js";
|
|
9
9
|
import { SECRET_ARGS_RE } from "./vocabulary.js";
|
|
10
|
+
// The dry-run preflight vocabulary (see the carve-out comment in
|
|
11
|
+
// classifyHcloudArgs). The global `--dryrun` flag is KooCLI's own
|
|
12
|
+
// "print the request, do not execute" (hcloud --help, service-agnostic);
|
|
13
|
+
// the body param `--dry_run=true` is the service-side preflight, pinned to
|
|
14
|
+
// the `${service} ${operation}` pairs (lowercased) whose operation-level
|
|
15
|
+
// --help documents it. Verified against `hcloud <op> --help` on
|
|
16
|
+
// 2026-11-27 for both entries; a future operation joins the set only with
|
|
17
|
+
// the same --help evidence.
|
|
18
|
+
const DRYRUN_GLOBAL_TOKEN = '--dryrun';
|
|
19
|
+
const DRY_RUN_PREFLIGHT_OPERATIONS = new Set(['ecs createservers', 'ecs createpostpaidservers']);
|
|
20
|
+
const DRY_RUN_EXACT_TOKEN = '--dry_run=true';
|
|
10
21
|
export function classifyHcloudArgs(args, options = {}) {
|
|
11
22
|
const policy = options.policy || DEFAULT_POLICY;
|
|
12
23
|
const unwrappedTokens = stripExecutable(Array.isArray(args) ? args.map((arg) => String(arg)) : []);
|
|
@@ -96,6 +107,50 @@ export function classifyHcloudArgs(args, options = {}) {
|
|
|
96
107
|
reason: 'The command appears to retrieve a secret value. Use a runtime secret reference pattern instead.',
|
|
97
108
|
};
|
|
98
109
|
}
|
|
110
|
+
// The dry-run preflight carve-out (the argv tool faces only — never the
|
|
111
|
+
// text/hook faces, see the rawCommand guard): a command whose child
|
|
112
|
+
// provably creates nothing is not a write, so plans/runs need no
|
|
113
|
+
// confirmation. Two documented zero-side-effect channels:
|
|
114
|
+
// (a) the KooCLI GLOBAL flag `--dryrun` — "Print the request message
|
|
115
|
+
// after verification, without execution" (hcloud --help): no
|
|
116
|
+
// request ever leaves the CLI, for ANY service/operation.
|
|
117
|
+
// (b) the ECS body param `--dry_run=true` — the service-side preflight
|
|
118
|
+
// ("true: indicates that only the request is sent, but the ECS
|
|
119
|
+
// will not be created. Check items include mandatory parameters
|
|
120
|
+
// and request format", per `hcloud ECS CreateServers --help`),
|
|
121
|
+
// allowlisted to the operations whose --help documents it
|
|
122
|
+
// (ECS CreateServers / CreatePostPaidServers, verified 2026-11-27).
|
|
123
|
+
// Fences keep the carve-out narrower than the facts it rests on:
|
|
124
|
+
// - EXACT TOKENS — only `--dryrun` and `--dry_run=true`. Case
|
|
125
|
+
// variants, `=True`, `=1`, `--dry-run`, or a bare `--dry_run` keep
|
|
126
|
+
// the write verdict, so a misspelled preflight still asks the user
|
|
127
|
+
// (fail-closed).
|
|
128
|
+
// - The body-param arm refuses `--cli-jsonInput`: a JSON body could
|
|
129
|
+
// carry a conflicting dry_run value under a precedence the CLI owns
|
|
130
|
+
// and the classifier cannot see.
|
|
131
|
+
// - The rawCommand === undefined guard is the face boundary: every
|
|
132
|
+
// hook entry point (the .mjs PreToolUse twin, the opencode
|
|
133
|
+
// in-process gate, and every nested walk inside classifyTextCommand)
|
|
134
|
+
// classifies TEXT with rawCommand set, so raw Bash keeps its deny
|
|
135
|
+
// and the py twin's verdicts stay parity-true. The argv faces —
|
|
136
|
+
// plan/run tool calls — carry no rawCommand and take the carve-out.
|
|
137
|
+
// A compound argv (a value containing `;`/`&&`/…) fragments in the
|
|
138
|
+
// segment pass and lands here WITHOUT its preflight token in the
|
|
139
|
+
// fragment, so the severity merge denies fail-closed.
|
|
140
|
+
if (options.rawCommand === undefined &&
|
|
141
|
+
(normalizedArgs.includes(DRYRUN_GLOBAL_TOKEN) ||
|
|
142
|
+
(DRY_RUN_PREFLIGHT_OPERATIONS.has(`${service.toLowerCase()} ${operation.toLowerCase()}`) &&
|
|
143
|
+
normalizedArgs.includes(DRY_RUN_EXACT_TOKEN) &&
|
|
144
|
+
!normalizedArgs.some((arg) => arg.startsWith('--cli-jsonInput'))))) {
|
|
145
|
+
return applyCommandRiskRules({
|
|
146
|
+
decision: 'allow',
|
|
147
|
+
risk: 'preflight',
|
|
148
|
+
reason: 'Documented dry-run preflight: the CLI prints the request without executing, or the service validates it and creates nothing, so no confirmation is required.',
|
|
149
|
+
service,
|
|
150
|
+
operation,
|
|
151
|
+
args: normalizedArgs,
|
|
152
|
+
}, normalizedArgs, options);
|
|
153
|
+
}
|
|
99
154
|
const readOnly = hasReadPrefix(operation, policy);
|
|
100
155
|
const executionOps = /(^|\.)(Invoke|SyncInvoke|AsyncInvoke|Send|Trigger|Execute|Start|Reboot|Restart|Stop|Publish|Deploy)/i;
|
|
101
156
|
const isExecution = executionOps.test(operation) && !readOnly;
|
|
@@ -0,0 +1,363 @@
|
|
|
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
|
+
// Deterministic defaults (contest/ops alignment: fixed service names, fixed
|
|
8
|
+
// user, fixed port pair so graders and scripts can discover them). These
|
|
9
|
+
// mirror the v1 installer's values one-for-one so one grading script covers
|
|
10
|
+
// both release lines.
|
|
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
|
+
// The running module may be an individually compiled dist file (setup-cli
|
|
21
|
+
// loads it as dist/server-install.js) or inlined inside the bundled server
|
|
22
|
+
// entry. Walking up to the nearest package.json *named like this package*
|
|
23
|
+
// is robust against both layouts; the v1 installer's fixed three-levels-up
|
|
24
|
+
// resolve shipped a one-level-off copy bug before it was patched, so the
|
|
25
|
+
// walk is also the validation.
|
|
26
|
+
function resolvePackageRoot(startDir) {
|
|
27
|
+
let current = startDir;
|
|
28
|
+
for (let depth = 0; depth < 8; depth++) {
|
|
29
|
+
const manifest = join(current, 'package.json');
|
|
30
|
+
if (existsSync(manifest)) {
|
|
31
|
+
let name;
|
|
32
|
+
try {
|
|
33
|
+
({ name } = JSON.parse(readFileSync(manifest, 'utf8')));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error(`unreadable package manifest while locating the install root: ${manifest}`);
|
|
37
|
+
}
|
|
38
|
+
if (name === 'huaweicloud-devkit')
|
|
39
|
+
return current;
|
|
40
|
+
}
|
|
41
|
+
const parent = dirname(current);
|
|
42
|
+
if (parent === current)
|
|
43
|
+
break;
|
|
44
|
+
current = parent;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`could not locate the huaweicloud-devkit package root above ${startDir}`);
|
|
47
|
+
}
|
|
48
|
+
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
49
|
+
const PACKAGE_ROOT = resolvePackageRoot(MODULE_DIR);
|
|
50
|
+
export function parseServerInstallArgs(argv = []) {
|
|
51
|
+
const opts = {
|
|
52
|
+
installPath: DEFAULT_SERVER_INSTALL_PATH,
|
|
53
|
+
port: DEFAULT_BUSINESS_PORT,
|
|
54
|
+
toolPort: DEFAULT_TOOL_PORT,
|
|
55
|
+
user: DEFAULT_SERVER_USER,
|
|
56
|
+
rotatePassword: false,
|
|
57
|
+
removeUser: false,
|
|
58
|
+
};
|
|
59
|
+
for (let i = 0; i < argv.length; i++) {
|
|
60
|
+
const arg = argv[i];
|
|
61
|
+
if (arg === undefined)
|
|
62
|
+
break;
|
|
63
|
+
const value = () => {
|
|
64
|
+
const next = argv[i + 1];
|
|
65
|
+
if (!next || next.startsWith('--')) {
|
|
66
|
+
throw new Error(`Missing value for ${arg}`);
|
|
67
|
+
}
|
|
68
|
+
i += 1;
|
|
69
|
+
return next;
|
|
70
|
+
};
|
|
71
|
+
if (arg === '--install-path')
|
|
72
|
+
opts.installPath = value();
|
|
73
|
+
else if (arg === '--port')
|
|
74
|
+
opts.port = Number(value());
|
|
75
|
+
else if (arg === '--tool-port')
|
|
76
|
+
opts.toolPort = Number(value());
|
|
77
|
+
else if (arg === '--user')
|
|
78
|
+
opts.user = value();
|
|
79
|
+
else if (arg === '--rotate-password')
|
|
80
|
+
opts.rotatePassword = true;
|
|
81
|
+
else if (arg === '--remove-user')
|
|
82
|
+
opts.removeUser = true;
|
|
83
|
+
else
|
|
84
|
+
throw new Error(`Unknown option for install-server: ${arg}`);
|
|
85
|
+
}
|
|
86
|
+
if (!Number.isSafeInteger(opts.port) || opts.port < 1024 || opts.port > 65535) {
|
|
87
|
+
throw new Error(`Invalid --port: ${opts.port}`);
|
|
88
|
+
}
|
|
89
|
+
if (!Number.isSafeInteger(opts.toolPort) || opts.toolPort < 1024 || opts.toolPort > 65535) {
|
|
90
|
+
throw new Error(`Invalid --tool-port: ${opts.toolPort}`);
|
|
91
|
+
}
|
|
92
|
+
if (opts.port === opts.toolPort) {
|
|
93
|
+
throw new Error('--port and --tool-port must differ');
|
|
94
|
+
}
|
|
95
|
+
if (!/^[a-z_][a-z0-9_-]{0,31}$/.test(opts.user)) {
|
|
96
|
+
throw new Error(`Invalid --user: ${opts.user}`);
|
|
97
|
+
}
|
|
98
|
+
return opts;
|
|
99
|
+
}
|
|
100
|
+
// Deconfusable alphabet (no 0/O/1/I/l): the password is transcribed by
|
|
101
|
+
// humans from a headless server terminal exactly once, at install time.
|
|
102
|
+
// randomInt samples each character uniformly — a modulo of randomBytes
|
|
103
|
+
// would bias the first two alphabet entries (256 % 56 != 0).
|
|
104
|
+
export function randomPassword(length = 24) {
|
|
105
|
+
const alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
|
|
106
|
+
let out = '';
|
|
107
|
+
for (let i = 0; i < length; i++)
|
|
108
|
+
out += alphabet[randomInt(0, alphabet.length)];
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
export function renderSystemdUnit({ serviceName, description, nodePath, appEntry, port, user, authPasswordFile, unitDir = '/etc/systemd/system', }) {
|
|
112
|
+
const unit = [
|
|
113
|
+
'[Unit]',
|
|
114
|
+
`Description=${description}`,
|
|
115
|
+
'After=network.target',
|
|
116
|
+
'',
|
|
117
|
+
'[Service]',
|
|
118
|
+
'Type=simple',
|
|
119
|
+
`ExecStart=${nodePath} ${appEntry} --transport remote --port ${port} --host 0.0.0.0 --auth-password-file ${authPasswordFile}`,
|
|
120
|
+
'Restart=on-failure',
|
|
121
|
+
'RestartSec=3',
|
|
122
|
+
`User=${user}`,
|
|
123
|
+
'',
|
|
124
|
+
'[Install]',
|
|
125
|
+
'WantedBy=multi-user.target',
|
|
126
|
+
'',
|
|
127
|
+
].join('\n');
|
|
128
|
+
return {
|
|
129
|
+
unitDir: unitDir.endsWith('/') ? unitDir : `${unitDir}/`,
|
|
130
|
+
unitPath: `${unitDir}/${serviceName}`,
|
|
131
|
+
unit,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export function nodeArchiveUrl(version, arch = process.arch) {
|
|
135
|
+
const flat = arch === 'arm64' || arch === 'aarch64' ? 'arm64' : 'x64';
|
|
136
|
+
return `${NODE_MIRROR}/v${version}/node-v${version}-linux-${flat}.tar.xz`;
|
|
137
|
+
}
|
|
138
|
+
export function isSupportedPlatform(platform = process.platform) {
|
|
139
|
+
return platform === 'linux';
|
|
140
|
+
}
|
|
141
|
+
function run(cmd, args) {
|
|
142
|
+
const res = spawnSync(cmd, args, { encoding: 'utf8' });
|
|
143
|
+
const out = (res.stdout ?? '').trim();
|
|
144
|
+
const err = (res.stderr ?? '').trim();
|
|
145
|
+
return { code: res.status, out, err, ok: res.status === 0 };
|
|
146
|
+
}
|
|
147
|
+
function runOrDie(cmd, args, what) {
|
|
148
|
+
const res = run(cmd, args);
|
|
149
|
+
if (!res.ok) {
|
|
150
|
+
throw new Error(`${what} failed: ${cmd} ${args.join(' ')}\n${res.err || res.out}`);
|
|
151
|
+
}
|
|
152
|
+
return res;
|
|
153
|
+
}
|
|
154
|
+
function writeFileOwner(path, content, owner, mode = 0o644) {
|
|
155
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
156
|
+
const fd = openSync(path, 'w', mode);
|
|
157
|
+
writeSync(fd, content);
|
|
158
|
+
closeSync(fd);
|
|
159
|
+
chmodSync(path, mode);
|
|
160
|
+
if (owner)
|
|
161
|
+
runOrDie('chown', [owner, path], `chown ${path}`);
|
|
162
|
+
}
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Steps
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
function ensureRoot() {
|
|
167
|
+
if (typeof process.getuid === 'function' && process.getuid() !== 0) {
|
|
168
|
+
throw new Error('install-server must run as root (needs user/group creation and systemd)');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function ensureLinux() {
|
|
172
|
+
if (!isSupportedPlatform()) {
|
|
173
|
+
throw new Error('install-server is Linux-only today (systemd required). Use `install` to configure coding agents.');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function ensureUser(user) {
|
|
177
|
+
const check = run('id', ['-u', user]);
|
|
178
|
+
if (check.ok)
|
|
179
|
+
return;
|
|
180
|
+
const nologin = ['/usr/sbin/nologin', '/sbin/nologin'].find((p) => existsSync(p)) || '/bin/false';
|
|
181
|
+
runOrDie('useradd', ['--system', '--no-create-home', '--shell', nologin, user], `create system user ${user}`);
|
|
182
|
+
}
|
|
183
|
+
function resolveSystemNode() {
|
|
184
|
+
const res = run('node', ['-v']);
|
|
185
|
+
if (res.ok) {
|
|
186
|
+
const major = Number.parseInt(res.out.replace(/^v/, ''), 10);
|
|
187
|
+
if (Number.isSafeInteger(major) && major >= 22) {
|
|
188
|
+
const where = run('bash', ['-c', 'command -v node']);
|
|
189
|
+
// An npx-shim node dies with the cache; the service must not pin it.
|
|
190
|
+
if (where.ok && where.out && !where.out.includes('_npx'))
|
|
191
|
+
return where.out.trim();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
function provisionNode(installPath) {
|
|
197
|
+
const target = join(installPath, 'node');
|
|
198
|
+
const bin = join(target, 'bin', 'node');
|
|
199
|
+
if (existsSync(bin))
|
|
200
|
+
return bin;
|
|
201
|
+
const url = nodeArchiveUrl(NODE_VERSION);
|
|
202
|
+
mkdirSync(installPath, { recursive: true });
|
|
203
|
+
console.log(` downloading Node.js v${NODE_VERSION} from ${url}`);
|
|
204
|
+
runOrDie('curl', ['-sL', '--retry', '3', '-o', join(installPath, 'node.tar.xz'), url], 'download Node.js');
|
|
205
|
+
runOrDie('mkdir', ['-p', target], 'mkdir node dir');
|
|
206
|
+
runOrDie('tar', ['-xJf', join(installPath, 'node.tar.xz'), '-C', target, '--strip-components', '1'], 'extract Node.js');
|
|
207
|
+
rmSync(join(installPath, 'node.tar.xz'), { force: true });
|
|
208
|
+
return bin;
|
|
209
|
+
}
|
|
210
|
+
function installAppDir(installPath, user) {
|
|
211
|
+
const app = join(installPath, 'devkit', 'app');
|
|
212
|
+
rmSync(app, { recursive: true, force: true });
|
|
213
|
+
mkdirSync(app, { recursive: true });
|
|
214
|
+
// Copy the running package (bin/ + plugins/ + package.json + node_modules
|
|
215
|
+
// when present) so the service is self-contained. Direct argv, no shell:
|
|
216
|
+
// every path component stays a literal argument.
|
|
217
|
+
const res = run('cp', ['-a', `${PACKAGE_ROOT}/.`, `${app}/`]);
|
|
218
|
+
if (!res.ok) {
|
|
219
|
+
throw new Error(`copy package to ${app} failed: ${res.err || res.out}`);
|
|
220
|
+
}
|
|
221
|
+
rmSync(join(app, '.git'), { recursive: true, force: true });
|
|
222
|
+
runOrDie('chown', ['-R', `${user}:${user}`, join(installPath, 'devkit')], 'chown app dir');
|
|
223
|
+
chmodSync(app, 0o750);
|
|
224
|
+
return app;
|
|
225
|
+
}
|
|
226
|
+
function writePasswordFile(installPath, user, rotate) {
|
|
227
|
+
const pwFile = join(installPath, 'devkit', 'server', '.auth-password');
|
|
228
|
+
if (existsSync(pwFile) && !rotate) {
|
|
229
|
+
return pwFile;
|
|
230
|
+
}
|
|
231
|
+
const password = randomPassword(24);
|
|
232
|
+
writeFileOwner(pwFile, `${password}\n`, user, 0o600);
|
|
233
|
+
return pwFile;
|
|
234
|
+
}
|
|
235
|
+
function writeUnits(installPath, params) {
|
|
236
|
+
// The dist bundle, not the TypeScript sources: the remote transport ships
|
|
237
|
+
// only inside the bundled entry (the individual mcp-server-remote.js is
|
|
238
|
+
// removed from dist by the build), so this is the one runnable path — the
|
|
239
|
+
// same file the `huaweicloud-devkit-mcp` bin resolves to.
|
|
240
|
+
const entry = join(params.app, 'plugins', 'huaweicloud-core', 'dist', 'mcp-server.js');
|
|
241
|
+
const business = renderSystemdUnit({
|
|
242
|
+
serviceName: BUSINESS_SERVICE_NAME,
|
|
243
|
+
description: 'HuaweiCloud DevKit MCP server (business port)',
|
|
244
|
+
nodePath: params.nodePath,
|
|
245
|
+
appEntry: entry,
|
|
246
|
+
port: params.port,
|
|
247
|
+
user: params.user,
|
|
248
|
+
authPasswordFile: params.pwFile,
|
|
249
|
+
});
|
|
250
|
+
const tool = renderSystemdUnit({
|
|
251
|
+
serviceName: TOOL_SERVICE_NAME,
|
|
252
|
+
description: 'HuaweiCloud DevKit MCP server (tool port)',
|
|
253
|
+
nodePath: params.nodePath,
|
|
254
|
+
appEntry: entry,
|
|
255
|
+
port: params.toolPort,
|
|
256
|
+
user: params.user,
|
|
257
|
+
authPasswordFile: params.pwFile,
|
|
258
|
+
});
|
|
259
|
+
writeFileOwner(business.unitPath, business.unit, 'root', 0o644);
|
|
260
|
+
writeFileOwner(tool.unitPath, tool.unit, 'root', 0o644);
|
|
261
|
+
runOrDie('systemctl', ['daemon-reload'], 'systemd daemon-reload');
|
|
262
|
+
}
|
|
263
|
+
export function planServiceCommands() {
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
cmd: 'systemctl',
|
|
267
|
+
args: ['enable', BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME],
|
|
268
|
+
label: 'enable services',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
cmd: 'systemctl',
|
|
272
|
+
args: ['restart', BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME],
|
|
273
|
+
label: 'restart services',
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
// One joint restart call removes the serial-restart failure window (the
|
|
278
|
+
// first restart succeeding and the second erroring, leaving one unit
|
|
279
|
+
// restarted and the other untouched). It is not a transaction: systemd
|
|
280
|
+
// enqueues the two units' jobs independently, so a mid-call failure can
|
|
281
|
+
// still land between them — but any failure aborts the install at
|
|
282
|
+
// runOrDie before "install complete" is ever printed.
|
|
283
|
+
function startServices() {
|
|
284
|
+
for (const { cmd, args, label } of planServiceCommands()) {
|
|
285
|
+
runOrDie(cmd, args, label);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function waitHealthy(port, timeoutMs = 15000) {
|
|
289
|
+
const deadline = Date.now() + timeoutMs;
|
|
290
|
+
while (Date.now() < deadline) {
|
|
291
|
+
const res = run('curl', ['-fsS', `http://127.0.0.1:${port}/health`]);
|
|
292
|
+
if (res.ok && res.out.includes('"ok"'))
|
|
293
|
+
return true;
|
|
294
|
+
const sleep = run('sleep', ['1']);
|
|
295
|
+
if (!sleep.ok)
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
// The installer never mutates firewall state — punching network holes is a
|
|
301
|
+
// security decision the operator makes knowingly. When firewalld is active
|
|
302
|
+
// we print the exact commands so the step is copy-paste instead of research.
|
|
303
|
+
function printFirewallHint(port, toolPort) {
|
|
304
|
+
const state = run('firewall-cmd', ['--state']);
|
|
305
|
+
if (state.ok && state.out === 'running') {
|
|
306
|
+
console.log('\nFirewalld is active on this host; the installer did not change firewall rules.');
|
|
307
|
+
console.log('Open the service ports yourself if external access is intended:');
|
|
308
|
+
console.log(` firewall-cmd --permanent --add-port=${port}/tcp`);
|
|
309
|
+
console.log(` firewall-cmd --permanent --add-port=${toolPort}/tcp`);
|
|
310
|
+
console.log(' firewall-cmd --reload');
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
console.log('\nNote: firewall rules were not changed. If external clients will connect, open the service ports per your distro (firewalld/ufw/iptables).');
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
// CLI entry points
|
|
318
|
+
// ---------------------------------------------------------------------------
|
|
319
|
+
export async function installServerCli(argv = []) {
|
|
320
|
+
ensureLinux();
|
|
321
|
+
ensureRoot();
|
|
322
|
+
const opts = parseServerInstallArgs(argv);
|
|
323
|
+
const installPath = resolve(opts.installPath);
|
|
324
|
+
console.log(`Installing HuaweiCloud DevKit server under ${installPath}`);
|
|
325
|
+
console.log(` business port: ${opts.port} tool port: ${opts.toolPort} service user: ${opts.user}`);
|
|
326
|
+
ensureUser(opts.user);
|
|
327
|
+
const nodePath = resolveSystemNode() || provisionNode(installPath);
|
|
328
|
+
const app = installAppDir(installPath, opts.user);
|
|
329
|
+
const pwFile = writePasswordFile(installPath, opts.user, opts.rotatePassword);
|
|
330
|
+
writeUnits(installPath, { nodePath, app, port: opts.port, toolPort: opts.toolPort, user: opts.user, pwFile });
|
|
331
|
+
startServices();
|
|
332
|
+
const okBusiness = waitHealthy(opts.port);
|
|
333
|
+
const okTool = waitHealthy(opts.toolPort);
|
|
334
|
+
if (!okBusiness || !okTool) {
|
|
335
|
+
const failed = !okBusiness ? BUSINESS_SERVICE_NAME : TOOL_SERVICE_NAME;
|
|
336
|
+
console.log(` warning: ${failed} did not report healthy yet; inspect with: journalctl -u ${failed} -n 50`);
|
|
337
|
+
}
|
|
338
|
+
console.log('\nServer install complete:');
|
|
339
|
+
console.log(` install path : ${installPath}/devkit/app`);
|
|
340
|
+
console.log(` service user : ${opts.user}`);
|
|
341
|
+
console.log(` business svc : ${BUSINESS_SERVICE_NAME} -> 0.0.0.0:${opts.port}`);
|
|
342
|
+
console.log(` tool svc : ${TOOL_SERVICE_NAME} -> 0.0.0.0:${opts.toolPort}`);
|
|
343
|
+
console.log(` auth password: ${pwFile} (0600; header: Authorization: Bearer <password> or x-devkit-password)`);
|
|
344
|
+
console.log(' health check : GET http://127.0.0.1:<port>/health');
|
|
345
|
+
printFirewallHint(opts.port, opts.toolPort);
|
|
346
|
+
}
|
|
347
|
+
export async function uninstallServerCli(argv = []) {
|
|
348
|
+
ensureLinux();
|
|
349
|
+
ensureRoot();
|
|
350
|
+
const opts = parseServerInstallArgs(argv);
|
|
351
|
+
run('systemctl', ['disable', '--now', BUSINESS_SERVICE_NAME]);
|
|
352
|
+
run('systemctl', ['disable', '--now', TOOL_SERVICE_NAME]);
|
|
353
|
+
for (const unit of [BUSINESS_SERVICE_NAME, TOOL_SERVICE_NAME]) {
|
|
354
|
+
rmSync(`/etc/systemd/system/${unit}`, { force: true });
|
|
355
|
+
}
|
|
356
|
+
run('systemctl', ['daemon-reload']);
|
|
357
|
+
rmSync(join(opts.installPath, 'devkit'), { recursive: true, force: true });
|
|
358
|
+
if (opts.removeUser) {
|
|
359
|
+
run('userdel', [opts.user]);
|
|
360
|
+
console.log(`removed service user: ${opts.user}`);
|
|
361
|
+
}
|
|
362
|
+
console.log('HuaweiCloud DevKit server uninstalled.');
|
|
363
|
+
}
|
|
@@ -15,6 +15,7 @@ import { removeKooCli, removeObsConfig } from "./sandbox/uninstall-cleanup.js";
|
|
|
15
15
|
import { readReceipt, removeReceipt } from "./dep/receipts.js";
|
|
16
16
|
import { runSecretCommand } from "./lib/secret-vault/cli.js";
|
|
17
17
|
import { createProcessApproveIo, runApproveCommand, runPinCommand } from "./approvals-cli.js";
|
|
18
|
+
import { installServerCli, uninstallServerCli } from "./server-install.js";
|
|
18
19
|
import { readConsentEvents } from "./approval-ledger.js";
|
|
19
20
|
import { custodyReport } from "./lib/secret-vault/custody.js";
|
|
20
21
|
import { vaultList } from "./lib/secret-vault/store.js";
|
|
@@ -1323,6 +1324,12 @@ async function main() {
|
|
|
1323
1324
|
case 'install-hcloud':
|
|
1324
1325
|
await cmdInstallHcloud();
|
|
1325
1326
|
break;
|
|
1327
|
+
case 'install-server':
|
|
1328
|
+
await installServerCli(process.argv.slice(3));
|
|
1329
|
+
break;
|
|
1330
|
+
case 'uninstall-server':
|
|
1331
|
+
await uninstallServerCli(process.argv.slice(3));
|
|
1332
|
+
break;
|
|
1326
1333
|
case 'dep':
|
|
1327
1334
|
await cmdDep();
|
|
1328
1335
|
break;
|
|
@@ -1364,6 +1371,8 @@ async function main() {
|
|
|
1364
1371
|
console.log(' status Show installation status');
|
|
1365
1372
|
console.log(' doctor Self-check: hcloud, MCP, skills, auth');
|
|
1366
1373
|
console.log(' install-hcloud Show KooCLI install commands for your OS');
|
|
1374
|
+
console.log(' install-server Server mode: systemd services + dedicated user + auth password (Linux root)');
|
|
1375
|
+
console.log(' uninstall-server Remove server-mode services and files');
|
|
1367
1376
|
console.log(' dep Dependency tooling: status | install <id> | uninstall <id>');
|
|
1368
1377
|
console.log(' packs Post-install pack surface: status | enable <ids> | disable <ids> | all');
|
|
1369
1378
|
console.log(' auth Manage unified auth: init | sync | status | reconcile');
|
|
@@ -1380,6 +1389,13 @@ async function main() {
|
|
|
1380
1389
|
console.log(' --clean-obs (with: uninstall --target all) also remove OBS config');
|
|
1381
1390
|
console.log(' --clean-gateway (with: uninstall --target all) also remove the devkit-installed open-mcp-gateway');
|
|
1382
1391
|
console.log(' --clean-global (with: uninstall --target all) also remove KooCLI + OBS config + open-mcp-gateway');
|
|
1392
|
+
console.log('\ninstall-server options:');
|
|
1393
|
+
console.log(' --install-path <dir> Base install path (default /opt/kunpeng)');
|
|
1394
|
+
console.log(' --port <n> Business port (default 8088)');
|
|
1395
|
+
console.log(' --tool-port <n> Tool port (default 7088)');
|
|
1396
|
+
console.log(' --user <name> Dedicated service user (default devkit)');
|
|
1397
|
+
console.log(' --rotate-password Regenerate the server auth password');
|
|
1398
|
+
console.log(' --remove-user (with: uninstall-server) also delete the service user');
|
|
1383
1399
|
console.log('\nExamples:');
|
|
1384
1400
|
console.log(' npx huaweicloud-devkit install');
|
|
1385
1401
|
console.log(' npx huaweicloud-devkit install --target codex');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"id": "huaweicloud-devkit",
|
|
4
4
|
"displayName": "HuaweiCloud DevKit",
|
|
5
|
-
"version": "2.0.1-next.
|
|
5
|
+
"version": "2.0.1-next.3",
|
|
6
6
|
"family": "bundle-plugin",
|
|
7
7
|
"bundleFormat": "codex",
|
|
8
8
|
"description": "Guide coding agents to use Huawei Cloud safely �?KooCLI, APIs, SDKs, 40 MCP tools, skills, and safety guardrails.",
|
|
@@ -159,6 +159,8 @@ hcloud ECS CreateServers --cli-region=<region> --cli-jsonInput=./<file>.json --d
|
|
|
159
159
|
|
|
160
160
|
`--cli-jsonInput` / `--skeleton` / `--dryrun` are **global flags — they are NOT listed in operation-level `--help` output** (only in `hcloud --help`), so agents routinely miss them.
|
|
161
161
|
|
|
162
|
+
**Through the MCP tools, pre-flight is confirmation-free**: plan with `--dryrun` appended (or `--dry_run=true` — the service-side check, documented on both create operations) and the plan returns `classification.risk: "preflight"` with `userConfirmation.needed: false`; run it with `huaweicloud_run_readonly_command` and fix parameter errors without any user confirmation round-trip. Iterate freely, then plan the real create WITHOUT the dry-run flag and follow the plan → confirm → run contract. Note: a `--cli-jsonInput` body keeps the confirmation requirement even with `--dry_run=true` — for the JSON-file path, prepend `--dryrun` instead.
|
|
163
|
+
|
|
162
164
|
> **Anti-pattern (observed in the wild, #964)**: when the base64 blob exceeded the tool parameter limit, the agent dropped the MCP tools entirely and ran `hcloud` directly in a shell — which also silently bypassed the plan → approve → run approval layer. The JSON-file path above keeps oversized parameters on the approved channel. Never abandon the MCP wrapper just because one parameter is too long.
|
|
163
165
|
>
|
|
164
166
|
> **Skeleton side effect**: `--skeleton` writes its JSON file to the current working directory and prints the path to stdout (the skeleton content itself goes to the file). Clean it up or keep it as the record of what was created.
|
|
@@ -24,6 +24,7 @@ Use this skill before any Huawei Cloud action that may expose secrets, change re
|
|
|
24
24
|
- cost/payment
|
|
25
25
|
- public exposure
|
|
26
26
|
5. For any non-read-only operation, follow the plan, confirm, run contract: plan with `huaweicloud_plan_cli_command`, show the user the command, then run with `huaweicloud_run_approved_command`. The confirm step follows the plan's `userConfirmation`: by default (`userConfirmation.mode` is `ask`) call the run tool and let the SERVER ask the user — a capable client raises a form during the call, and any other client answers with `ASK_CONFIRMATION_REQUIRED` so you can show the command in chat and retry with `approvedByUser: true`; in token mode (opt-in, `DEVKIT_APPROVAL_MODE=token`) show the terminal confirmation line and wait for the user to run it in their own terminal. See `references/approvals.md`. The same gate covers the registered non-CLI mutators (`huaweicloud_obs_set_website_config`, `huaweicloud_obs_set_cors`, `huaweicloud_upgrade`, `huaweicloud_secret_delete`, `huaweicloud_packs_configure`): call the tool and let the gate confirm — obs `action=get` runs unconfirmed as a signed read; the shell CLI twins (`update`/`upgrade`, `secret rm`, `packs enable/disable`) are hook-denied on the Bash face.
|
|
27
|
+
Preflight exception: a plan whose `classification.risk` is `preflight` (the KooCLI global `--dryrun` flag, or `--dry_run=true` on the ECS create operations that document it) validates without creating anything, so `userConfirmation.needed` is false — run it directly with `huaweicloud_run_readonly_command`, iterate parameters freely, and reserve the plan → confirm → run contract for the real create. Raw Bash never gets this: hooks still deny it.
|
|
27
28
|
6. Redact secrets from command output, errors, JSON, logs, and generated reports.
|
|
28
29
|
7. If a command contains `adminPass`, `password`, token, or any secret-like field, warn that plaintext can remain in shell history. Prefer local-only input, runtime injection, or user-side execution.
|
|
29
30
|
|
|
@@ -35,6 +36,8 @@ Use this skill before any Huawei Cloud action that may expose secrets, change re
|
|
|
35
36
|
|
|
36
37
|
## Write Execution Boundary
|
|
37
38
|
|
|
39
|
+
0. Preflight first (no confirmation): when a create call has a documented zero-side-effect form, validate it BEFORE asking the user to approve the real one. Plan with the KooCLI global `--dryrun` flag (any operation — the CLI prints the request without executing) or `--dry_run=true` (ECS CreateServers / CreatePostPaidServers — the service checks mandatory parameters and request format but creates nothing). The plan returns `classification.risk: "preflight"` and `userConfirmation.needed: false`; run it with `huaweicloud_run_readonly_command` and fix parameter errors freely — each retry is free. Then plan the REAL command (no dry-run flag) and continue below.
|
|
40
|
+
|
|
38
41
|
1. Plan: call `huaweicloud_plan_cli_command`. The result echoes the exact command and carries `userConfirmation: { needed, mode: "ask", note }` by default, or `userConfirmation: { needed, command }` when the plan ran under `DEVKIT_APPROVAL_MODE=token` (opt-in).
|
|
39
42
|
2. Confirm (ask mode, the default): when `userConfirmation.mode` is `ask`, there is no terminal line and no token. The FIRST unattested call to `huaweicloud_run_approved_command` (same args, no `approvedByUser`; the `command` display field is recommended but optional) makes the server ask: an elicitation-capable client renders a form, and any other client returns `ASK_CONFIRMATION_REQUIRED`, whose envelope carries the command — show it to the user in chat, then retry that same call with `approvedByUser: true`. That retry is model-relayed posture trust, labeled as such, and its envelope stays live for the session's TTL, so further identical retries of the SAME command execute without re-asking. Different args get their own envelope first.
|
|
40
43
|
3. Confirm (token mode, opt-in): when `needed` is true, show the user the plan echo and the `userConfirmation.command` line (`npx huaweicloud-devkit approve <approvalToken>`), then wait. The USER runs that line in their own terminal, where a TTY check and a PIN gate the confirmation. First use: the user runs `npx huaweicloud-devkit pin` once in their own terminal to enroll the PIN.
|
|
@@ -46,6 +46,10 @@ The same gate covers every tool on the approval roster, not only the hcloud plan
|
|
|
46
46
|
|
|
47
47
|
The account-switch pair is registered (PR-3b): `huaweicloud_auth_init` and `huaweicloud_auth_switch` confirm on every call, and their confirmation views name the target account fingerprint and the credential source, because the account switch is the step that can redirect every later approved write to a different account. The confirmation binds the resolved snapshot — the account, region, and session token of the switch — so the account the user confirmed is the account that switches; a changed file or a changed region re-asks instead of executing. The devkit CLI verbs (`npx huaweicloud-devkit auth init`, `auth sync`) are the operator's own terminal surface: the hook denies them on the agent Bash face, so an agent cannot use the CLI to bypass the gate the MCP tools carry. `auth_confirm` (the persist-conflict reconciliation) and the read faces (`auth_status`, `check_account_type`, `auth_sync` on the MCP surface) stay ungated by this chain.
|
|
48
48
|
|
|
49
|
+
## The dry-run preflight (no confirmation)
|
|
50
|
+
|
|
51
|
+
A command that provably creates nothing is not a write, so it skips the confirmation contract entirely. The classifier recognizes two zero-side-effect channels on the plan/run tool faces: the KooCLI global flag `--dryrun` ("Print the request message after verification, without execution" — no request ever leaves the CLI, any operation) and the ECS body param `--dry_run=true` (the service checks mandatory parameters and request format but creates nothing — documented on `ECS CreateServers` / `ECS CreatePostPaidServers`; a `--cli-jsonInput` body keeps the write verdict because its dry_run value could conflict). Only the exact tokens match: case variants, bare `--dry_run`, `--dry-run`, or `=1` keep the write verdict, so a misspelled preflight still asks the user. The plan returns `classification.risk: "preflight"` with `userConfirmation.needed: false` — run it with `huaweicloud_run_readonly_command` and iterate parameters freely, then plan the real command (no dry-run flag) and follow the plan → confirm → run contract below. Raw Bash never gets this carve-out: the hook faces still deny a dry-run write, so preflights go through the MCP tools.
|
|
52
|
+
|
|
49
53
|
## Ask mode (the default): the server-run confirmation
|
|
50
54
|
|
|
51
55
|
The confirmation happens on the server, in one of two tiers.
|
|
@@ -133,6 +133,10 @@ function planningWarnings(args: string[]): string[] {
|
|
|
133
133
|
|
|
134
134
|
const REQUIRED_PARAMS: Record<string, string[]> = {
|
|
135
135
|
'ECS CreateServers': ['server.flavorRef', 'server.imageRef', 'server.nics.1.subnet_id'],
|
|
136
|
+
// KooCLI rejects a CreatePostPaidServers call that omits server.vpcid
|
|
137
|
+
// with "The following parameters are required: server.vpcid" (live
|
|
138
|
+
// evidence 2026-11-27), so the plan warns before the child ever runs.
|
|
139
|
+
'ECS CreatePostPaidServers': ['server.flavorRef', 'server.imageRef', 'server.nics.1.subnet_id', 'server.vpcid'],
|
|
136
140
|
'VPC CreateVpc': ['vpc.cidr'],
|
|
137
141
|
'VPC CreateSubnet': ['subnet.vpc_id', 'subnet.cidr'],
|
|
138
142
|
'VPC CreateSecurityGroupRule': [
|
|
@@ -152,6 +156,8 @@ const PARAM_VALUE_HINTS: Record<string, string> = {
|
|
|
152
156
|
'server.flavorRef': 'Run `hcloud ECS ListFlavors --cli-region=<r>` to find valid flavors',
|
|
153
157
|
'server.imageRef': 'Run `hcloud IMS ListImages --cli-region=<r> --__imagetype=gold` to find image IDs',
|
|
154
158
|
'server.nics.1.subnet_id': 'Run `hcloud VPC ListSubnets --cli-region=<r>` to find subnet IDs',
|
|
159
|
+
'server.vpcid':
|
|
160
|
+
'Run `hcloud VPC ListVpcs --cli-region=<r>` to find VPC IDs (KooCLI rejects CreatePostPaidServers without it)',
|
|
155
161
|
'subnet.vpc_id': 'Run `hcloud VPC ListVpcs --cli-region=<r>` to find VPC IDs',
|
|
156
162
|
func_name: 'Function name must be unique within project',
|
|
157
163
|
runtime: 'Run `hcloud FunctionGraph ListRuntimes` to see available runtimes',
|