huaweicloud-devkit 1.1.14-next.0 → 1.1.14-next.2
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 +13 -1
- package/README.zh-CN.md +13 -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/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +0 -6
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +2 -2
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-core/SKILL.md +2 -0
- package/plugins/huaweicloud-core/src/account-type.mjs +1 -10
- package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +1 -1
- package/plugins/huaweicloud-core/src/auth/credentials.mjs +4 -92
- package/plugins/huaweicloud-core/src/auth/service.mjs +2 -25
- package/plugins/huaweicloud-core/src/auto-upgrade-runner.mjs +58 -0
- package/plugins/huaweicloud-core/src/hcloud-cli.mjs +4 -43
- package/plugins/huaweicloud-core/src/hcloud-probe.mjs +0 -12
- package/plugins/huaweicloud-core/src/mcp-config-merge.mjs +1 -1
- package/plugins/huaweicloud-core/src/mcp-protocol.mjs +13 -4
- package/plugins/huaweicloud-core/src/mcp-server.mjs +20 -8
- package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +1 -1
- package/plugins/huaweicloud-core/src/safety-policy.mjs +1 -1
- package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +55 -58
- package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +1 -36
- package/plugins/huaweicloud-core/src/sandbox/sandbox-pool.mjs +1 -12
- package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +4 -4
- package/plugins/huaweicloud-core/src/setup-cli.mjs +9 -91
- package/plugins/huaweicloud-core/src/tools.mjs +51 -69
- package/plugins/huaweicloud-core/src/update-auto.mjs +669 -0
- package/plugins/huaweicloud-core/src/update-check.mjs +141 -10
- package/plugins/huaweicloud-core/src/update-policy.mjs +82 -0
- package/integrations/opencode/package-lock.json +0 -24
- package/integrations/opencode/package.json +0 -10
- package/integrations/opencode/plugins/huaweicloud-devkit.js +0 -194
- package/plugins/huaweicloud-core/src/auth/token-exchange.mjs +0 -100
- package/plugins/huaweicloud-core/src/koocli-install.mjs +0 -57
|
@@ -7,7 +7,9 @@ import { fileURLToPath } from 'node:url';
|
|
|
7
7
|
|
|
8
8
|
import { dispatch } from './mcp-protocol.mjs';
|
|
9
9
|
import { DEFAULT_PORT, DEFAULT_HOST } from './mcp-server-remote.mjs';
|
|
10
|
-
import { getCachedUpdateInfo,
|
|
10
|
+
import { getCachedUpdateInfo, getRuntimeVersion, semverCompare } from './update-check.mjs';
|
|
11
|
+
import { getUpgradePolicy } from './update-policy.mjs';
|
|
12
|
+
import { maybeAutoUpgrade } from './update-auto.mjs';
|
|
11
13
|
import { detectAgent } from './telemetry/agent-detect.mjs';
|
|
12
14
|
import { maybePreinstallKooCli } from './preflight.mjs';
|
|
13
15
|
|
|
@@ -62,6 +64,23 @@ try {
|
|
|
62
64
|
maybePreinstallKooCli();
|
|
63
65
|
} catch {}
|
|
64
66
|
|
|
67
|
+
const updatePrewarm = async () => {
|
|
68
|
+
const current = getRuntimeVersion();
|
|
69
|
+
const hintPromise = getCachedUpdateInfo(current).catch(() => null);
|
|
70
|
+
const policy = await getUpgradePolicy().catch(() => null);
|
|
71
|
+
if (policy?.active && policy.minVersion && semverCompare(current, policy.minVersion) < 0) {
|
|
72
|
+
maybeAutoUpgrade({ trigger: 'startup_forced', minVersion: policy.minVersion });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const hint = await hintPromise;
|
|
76
|
+
if (hint?.updateAvailable) maybeAutoUpgrade({ trigger: 'startup_normal' });
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// 版本升级检测预热:异步、非阻塞;失败静默(离线/超时不影响会话)。
|
|
80
|
+
process.nextTick(() => {
|
|
81
|
+
updatePrewarm().catch(() => {});
|
|
82
|
+
});
|
|
83
|
+
|
|
65
84
|
if (transport === 'remote') {
|
|
66
85
|
const { startRemoteServer } = await import('./mcp-server-remote.mjs');
|
|
67
86
|
startRemoteServer({ port: remotePort, host: remoteHost }).catch((error) => {
|
|
@@ -74,10 +93,6 @@ if (transport === 'remote') {
|
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
function runStdioServer() {
|
|
77
|
-
const updatePrewarm = () => {
|
|
78
|
-
getCachedUpdateInfo(readInstalledVersion() || '0.0.0').catch(() => {});
|
|
79
|
-
};
|
|
80
|
-
|
|
81
96
|
let buffer = Buffer.alloc(0);
|
|
82
97
|
let useContentLengthFraming = true;
|
|
83
98
|
|
|
@@ -93,9 +108,6 @@ function runStdioServer() {
|
|
|
93
108
|
const { harness } = detectAgent();
|
|
94
109
|
const NEEDS_KEEPALIVE = harness === 'hermes' && platform() === 'win32';
|
|
95
110
|
|
|
96
|
-
// 版本升级检测预热:异步、非阻塞;失败静默(离线/超时不影响会话)。
|
|
97
|
-
process.nextTick(updatePrewarm);
|
|
98
|
-
|
|
99
111
|
let keepAlive = null;
|
|
100
112
|
function onStdinClose() {
|
|
101
113
|
if (keepAlive) return;
|
|
@@ -19,7 +19,7 @@ export function loadRiskRules(options = {}) {
|
|
|
19
19
|
function redactEvidence(text) {
|
|
20
20
|
return String(text)
|
|
21
21
|
.replace(
|
|
22
|
-
/((?:access[_-]?key|secret[_-]?key|secret|security[_-]?token|x[_-]?auth[_-]?token|
|
|
22
|
+
/((?:access[_-]?key|secret[_-]?key|secret|security[_-]?token|x[_-]?auth[_-]?token|token|authorization|password|passwd|admin[_-]?pass|credential)\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi,
|
|
23
23
|
'$1<redacted>',
|
|
24
24
|
)
|
|
25
25
|
.replace(/(AK|SK)\s*[:=]\s*("[^"]*"|'[^']*'|[^\s,;]+)/g, '$1=<redacted>');
|
|
@@ -39,7 +39,7 @@ function redactString(text) {
|
|
|
39
39
|
// Redact the ENTIRE value of this arg — not just the first whitespace token.
|
|
40
40
|
.replace(/((?:user[_-]?data|metadata|private[_-]?key)\s*[:=]\s*).*/gi, '$1<redacted>')
|
|
41
41
|
.replace(
|
|
42
|
-
/((?:access[_-]?key|secret[_-]?key|security[_-]?token|x[_-]?auth[_-]?token|
|
|
42
|
+
/((?:access[_-]?key|secret[_-]?key|security[_-]?token|x[_-]?auth[_-]?token|token|authorization|password|passwd|admin[_-]?pass|credential)\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi,
|
|
43
43
|
'$1<redacted>',
|
|
44
44
|
)
|
|
45
45
|
.replace(/(AK|SK)\s*[:=]\s*("[^"]*"|'[^']*'|[^\s,;]+)/g, '$1=<redacted>')
|
|
@@ -1,50 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCredentials } from './hwlink-api.mjs';
|
|
2
2
|
import { getProxyDispatcher } from '../proxy/proxy-agent.mjs';
|
|
3
3
|
import { cacheUserHash } from '../telemetry/telemetry.mjs';
|
|
4
4
|
import { detectAgent } from '../telemetry/agent-detect.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { getTokenCredentials } from '../auth/token-exchange.mjs';
|
|
8
|
-
import { makeError } from '../auth/guidance.mjs';
|
|
5
|
+
import { getRuntimeVersion } from '../update-check.mjs';
|
|
6
|
+
import { maybeAutoUpgrade } from '../update-auto.mjs';
|
|
9
7
|
|
|
10
8
|
function getHdkitBaseUrl() {
|
|
11
9
|
return process.env.HDKITSERVICE_ENDPOINT || 'https://devkit.huaweicloud.com/rest/developer/server/hdkitservice/';
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
// Backend (hdkitservice/voucher) credentials: prefer AK/SK, else fall back to
|
|
15
|
-
// X-Auth-Token → temporary AK/SK exchange, so token-auth users are not blocked.
|
|
16
|
-
async function resolveBackendCredentials() {
|
|
17
|
-
try {
|
|
18
|
-
const creds = resolveCredentialsWithRuntime({ allowMissing: true });
|
|
19
|
-
if (creds && creds.ak && creds.sk) return creds;
|
|
20
|
-
} catch {
|
|
21
|
-
// no AK/SK — fall through to token
|
|
22
|
-
}
|
|
23
|
-
const token = resolveXAuthToken();
|
|
24
|
-
if (!token) return null;
|
|
25
|
-
try {
|
|
26
|
-
return await getTokenCredentials(token);
|
|
27
|
-
} catch {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
12
|
async function hdkitRequest(method, path, body, timeoutMs = 300000) {
|
|
33
|
-
const
|
|
34
|
-
const ak = creds?.ak;
|
|
35
|
-
const sk = creds?.sk;
|
|
36
|
-
const securitytoken = creds?.securityToken || '';
|
|
13
|
+
const { ak, sk, securitytoken } = getCredentials();
|
|
37
14
|
|
|
38
15
|
if (!ak || !sk) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
throw new Error(
|
|
17
|
+
'Huawei Cloud credentials are not configured. ' +
|
|
18
|
+
'Run "npx huaweicloud-devkit auth init" or set HW_ACCESS_KEY/HW_SECRET_KEY.',
|
|
19
|
+
);
|
|
42
20
|
}
|
|
43
21
|
const headers = {
|
|
44
22
|
'Content-Type': 'application/json',
|
|
45
23
|
'X-HW-AK': ak,
|
|
46
24
|
'X-HW-SK': sk,
|
|
47
|
-
'X-HW-Client-Version':
|
|
25
|
+
'X-HW-Client-Version': getRuntimeVersion(),
|
|
48
26
|
// #1040: 对外请求统一携带 X-HW-Agent(值=detectAgent 结果 harness)
|
|
49
27
|
'X-HW-Agent': detectAgent().harness,
|
|
50
28
|
};
|
|
@@ -125,13 +103,38 @@ async function hdkitRequest(method, path, body, timeoutMs = 300000) {
|
|
|
125
103
|
err.clientVersion = data.clientVersion || undefined;
|
|
126
104
|
err.minVersion = data.minVersion || undefined;
|
|
127
105
|
err.message = data.message || err.message;
|
|
106
|
+
const autoUpgrade = maybeAutoUpgrade({
|
|
107
|
+
trigger: data.minVersion ? 'version_gate' : 'startup_normal',
|
|
108
|
+
minVersion: data.minVersion || '',
|
|
109
|
+
});
|
|
110
|
+
err.autoUpgrade = autoUpgrade;
|
|
111
|
+
const autoStarted = autoUpgrade.status === 'started' || autoUpgrade.status === 'already_running';
|
|
112
|
+
const autoReady = autoUpgrade.status === 'already_upgraded';
|
|
113
|
+
const autoUnsupported = autoUpgrade.status === 'unsupported_install';
|
|
128
114
|
err.remediation = {
|
|
129
115
|
hint: `插件版本过旧(当前 ${data.clientVersion || '未知'},需升级至正式版 ${data.minVersion || '最新版'} 及以上):`,
|
|
130
|
-
steps:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
steps: autoReady
|
|
117
|
+
? [
|
|
118
|
+
`新版本 ${autoUpgrade.installedVersion || ''} 已安装,重启当前 Agent 会话即可`.trim(),
|
|
119
|
+
'若重启后仍被拦截,可在终端执行:npx --yes huaweicloud-devkit@latest update --target <agent>',
|
|
120
|
+
]
|
|
121
|
+
: autoStarted
|
|
122
|
+
? [
|
|
123
|
+
'升级已在后台开始,完成后重启当前 Agent 会话(MCP 工具需重启才生效)',
|
|
124
|
+
'若长时间未完成,可在终端执行:npx --yes huaweicloud-devkit@latest update --target <agent>',
|
|
125
|
+
'也可直接调用 huaweicloud_upgrade 工具完成升级',
|
|
126
|
+
]
|
|
127
|
+
: autoUnsupported
|
|
128
|
+
? [
|
|
129
|
+
autoUpgrade.manual ||
|
|
130
|
+
'当前安装方式暂不支持自动升级,请在终端执行:npx --yes huaweicloud-devkit@latest update --target <agent>',
|
|
131
|
+
'升级完成后重启当前 Agent 会话(MCP 工具需重启才生效)',
|
|
132
|
+
]
|
|
133
|
+
: [
|
|
134
|
+
'在终端执行:npx --yes huaweicloud-devkit@latest update --target <agent>',
|
|
135
|
+
'升级完成后重启当前 Agent 会话(MCP 工具需重启才生效)',
|
|
136
|
+
'也可直接调用 huaweicloud_upgrade 工具完成升级',
|
|
137
|
+
],
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
140
|
// 烧核播报(缺口#5 代码层):账号核心时长耗尽——上游码 HD.97520422 经
|
|
@@ -175,14 +178,11 @@ export async function hdkitConnect(options = {}) {
|
|
|
175
178
|
if (options.source) body.source = options.source;
|
|
176
179
|
if (options.env) body.env = options.env;
|
|
177
180
|
if (options.git) body.git = options.git;
|
|
178
|
-
if (options.template_id) body.template_id = options.template_id;
|
|
179
181
|
if (options.flavor_id) body.flavor_id = options.flavor_id;
|
|
180
182
|
if (options.pool_type) {
|
|
181
183
|
// 两池:pool_type 由服务端权威映射(不传默认 ephemeral)。
|
|
182
|
-
//
|
|
184
|
+
// 自定义模板/显式 template_id 已下线,客户端不再上送。
|
|
183
185
|
body.pool_type = options.pool_type;
|
|
184
|
-
const pinned = pinnedTemplateFor(options.pool_type);
|
|
185
|
-
if (pinned && !body.template_id) body.template_id = pinned;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
return await hdkitRequest('POST', 'connect', body);
|
|
@@ -253,17 +253,24 @@ export async function hdkitDeleteApiKey(keyId) {
|
|
|
253
253
|
return await hdkitRequest('DELETE', `api-keys/${encodeURIComponent(keyId)}`, undefined, 30000);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
function voucherErrorResult(error, fallbackMessage) {
|
|
257
|
+
return {
|
|
258
|
+
claimed: false,
|
|
259
|
+
message: error?.message || fallbackMessage,
|
|
260
|
+
code: error?.code,
|
|
261
|
+
...(error?.clientVersion ? { clientVersion: error.clientVersion } : {}),
|
|
262
|
+
...(error?.minVersion ? { minVersion: error.minVersion } : {}),
|
|
263
|
+
...(error?.remediation ? { remediation: error.remediation } : {}),
|
|
264
|
+
...(error?.autoUpgrade ? { autoUpgrade: error.autoUpgrade } : {}),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
256
268
|
export async function hdkitVoucherStatus(domainId) {
|
|
257
269
|
try {
|
|
258
270
|
const path = domainId ? `voucher/status?domain_id=${encodeURIComponent(domainId)}` : 'voucher/status';
|
|
259
271
|
return await hdkitRequest('GET', path, undefined, 30000);
|
|
260
272
|
} catch (error) {
|
|
261
|
-
return
|
|
262
|
-
claimed: false,
|
|
263
|
-
message: error?.message || 'Incentive service unavailable, please try again later',
|
|
264
|
-
code: error?.code,
|
|
265
|
-
...(error?.remediation ? { remediation: error.remediation } : {}),
|
|
266
|
-
};
|
|
273
|
+
return voucherErrorResult(error, 'Incentive service unavailable, please try again later');
|
|
267
274
|
}
|
|
268
275
|
}
|
|
269
276
|
|
|
@@ -272,12 +279,7 @@ export async function hdkitVoucherClaim(domainId) {
|
|
|
272
279
|
const body = domainId ? { domain_id: domainId } : {};
|
|
273
280
|
return await hdkitRequest('POST', 'voucher/claim', body);
|
|
274
281
|
} catch (error) {
|
|
275
|
-
return
|
|
276
|
-
claimed: false,
|
|
277
|
-
message: error?.message || 'Incentive service unavailable, please try again later',
|
|
278
|
-
code: error?.code,
|
|
279
|
-
...(error?.remediation ? { remediation: error.remediation } : {}),
|
|
280
|
-
};
|
|
282
|
+
return voucherErrorResult(error, 'Incentive service unavailable, please try again later');
|
|
281
283
|
}
|
|
282
284
|
}
|
|
283
285
|
|
|
@@ -286,11 +288,6 @@ export async function hdkitCompetitionVoucherClaim(domainId) {
|
|
|
286
288
|
const body = domainId ? { domain_id: domainId } : {};
|
|
287
289
|
return await hdkitRequest('POST', 'competition/voucher/claim', body);
|
|
288
290
|
} catch (error) {
|
|
289
|
-
return
|
|
290
|
-
claimed: false,
|
|
291
|
-
message: error?.message || 'Competition voucher service unavailable, please try again later',
|
|
292
|
-
code: error?.code,
|
|
293
|
-
...(error?.remediation ? { remediation: error.remediation } : {}),
|
|
294
|
-
};
|
|
291
|
+
return voucherErrorResult(error, 'Competition voucher service unavailable, please try again later');
|
|
295
292
|
}
|
|
296
293
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
|
|
3
|
-
import { resolveCredentialsWithRuntime
|
|
4
|
-
import { getTokenCredentials } from '../auth/token-exchange.mjs';
|
|
5
|
-
import { makeError } from '../auth/guidance.mjs';
|
|
3
|
+
import { resolveCredentialsWithRuntime } from '../auth/credentials.mjs';
|
|
6
4
|
import { getProxyDispatcher } from '../proxy/proxy-agent.mjs';
|
|
7
5
|
|
|
8
6
|
const BASE_URL = process.env.HWLINK_ENDPOINT || 'https://devstation.myhuaweicloud.com';
|
|
@@ -84,39 +82,6 @@ export function getCredentials() {
|
|
|
84
82
|
return { ak: credentials.ak, sk: credentials.sk, securitytoken: credentials.securityToken };
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
// Data-plane (sandbox exec/upload/tunnel) credentials: prefer AK/SK, else fall
|
|
88
|
-
// back to X-Auth-Token → temporary AK/SK, so token-auth users can drive the data
|
|
89
|
-
// plane without a permanent AK/SK (experience-report #3.3/#3.7 dead-loop fix).
|
|
90
|
-
// NOTE: returns `securitytoken` (lowercase t) — the call sites (session-manager,
|
|
91
|
-
// tools.mjs) destructure that exact spelling; returning `securityToken` here
|
|
92
|
-
// silently drops the STS token from the hwlink signature (APIGW.0301).
|
|
93
|
-
export async function resolveBackendCredentials() {
|
|
94
|
-
try {
|
|
95
|
-
const creds = resolveCredentialsWithRuntime({ allowMissing: true });
|
|
96
|
-
if (creds && creds.ak && creds.sk) {
|
|
97
|
-
return { ak: creds.ak, sk: creds.sk, securitytoken: creds.securityToken || '' };
|
|
98
|
-
}
|
|
99
|
-
} catch {
|
|
100
|
-
// no AK/SK — fall through to token
|
|
101
|
-
}
|
|
102
|
-
const token = resolveXAuthToken();
|
|
103
|
-
if (token) {
|
|
104
|
-
try {
|
|
105
|
-
const temp = await getTokenCredentials(token);
|
|
106
|
-
return { ak: temp.ak, sk: temp.sk, securitytoken: temp.securityToken || '' };
|
|
107
|
-
} catch (error) {
|
|
108
|
-
// Distinguish "token exchange failed" from "no credential at all" (#3.4).
|
|
109
|
-
const err = makeError('HDKIT_CRED_MISSING');
|
|
110
|
-
err.code = error?.code || 'TOKEN_EXCHANGE_FAILED';
|
|
111
|
-
err.messageZh =
|
|
112
|
-
`X-Auth-Token 换取临时 AK/SK 失败(${err.code}):` +
|
|
113
|
-
`${error?.message || '网络异常或 token 无效'},请检查网络连通性与 token 有效性。`;
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
throw makeError('HDKIT_CRED_MISSING');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
85
|
async function apiGet(path, query, ak, sk, securitytoken) {
|
|
121
86
|
query = query || {};
|
|
122
87
|
const qs = sortedQs(query);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 两池沙箱(pool_type)客户端支持。
|
|
2
2
|
// 机制(定稿):池 = 平台预置模板,客户端传 pool_type(ephemeral/persistent),
|
|
3
|
-
// 服务端权威映射 template_id
|
|
3
|
+
// 服务端权威映射 template_id;不支持自定义模板/显式 template_id。
|
|
4
4
|
// - 非持久池(默认):闲置自动关机 + 自动删除(平台策略)
|
|
5
5
|
// - 持久池:EVS 数据盘跨关机保留,闲置回收保留期上限 7 天
|
|
6
6
|
// - 生命周期数值由 hdkitservice 配置回显(仅播报口径,实际策略由平台执行)
|
|
@@ -47,17 +47,6 @@ export function validatePoolType(raw) {
|
|
|
47
47
|
return normalized;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
* 运维钉扎(可选):设置 HW_POOL_TEMPLATE_EPHEMERAL/PERSISTENT 后,客户端把映射出的
|
|
52
|
-
* template_id 与 pool_type 一并上送——服务端(及未升级的老服务端)按显式模板处理。
|
|
53
|
-
* 日常部署无需配置:模板 ID 由服务端 POOL_TEMPLATE_* 环境变量权威维护。
|
|
54
|
-
*/
|
|
55
|
-
export function pinnedTemplateFor(poolType) {
|
|
56
|
-
if (poolType === 'ephemeral') return process.env.HW_POOL_TEMPLATE_EPHEMERAL || '';
|
|
57
|
-
if (poolType === 'persistent') return process.env.HW_POOL_TEMPLATE_PERSISTENT || '';
|
|
58
|
-
return '';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
50
|
function positiveNumber(value) {
|
|
62
51
|
const n = Number(value);
|
|
63
52
|
return Number.isFinite(n) && n > 0 ? n : null;
|
|
@@ -16,7 +16,7 @@ import { join, dirname, basename } from 'node:path';
|
|
|
16
16
|
import { tmpdir } from 'node:os';
|
|
17
17
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
18
18
|
|
|
19
|
-
import { createConnection,
|
|
19
|
+
import { createConnection, getCredentials } from './hwlink-api.mjs';
|
|
20
20
|
import { getWebSocketImpl } from '../proxy/proxy-agent.mjs';
|
|
21
21
|
import { trackSandboxConnect, trackSandboxDisconnect } from '../telemetry/telemetry.mjs';
|
|
22
22
|
import { buildExposeLifetimeNotice } from './sandbox-pool.mjs';
|
|
@@ -108,7 +108,7 @@ async function getSession(workspaceId, username, timeoutMs) {
|
|
|
108
108
|
const key = `${workspaceId}:${username}`;
|
|
109
109
|
if (sessions.has(key)) return sessions.get(key);
|
|
110
110
|
|
|
111
|
-
const { ak, sk, securitytoken } =
|
|
111
|
+
const { ak, sk, securitytoken } = getCredentials();
|
|
112
112
|
const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
|
|
113
113
|
|
|
114
114
|
const WebSocketImpl = await getWebSocketImpl(wsUrl);
|
|
@@ -127,7 +127,7 @@ async function getSession(workspaceId, username, timeoutMs) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
async function createTunnelSession(workspaceId, username, timeoutMs = 30000) {
|
|
130
|
-
const { ak, sk, securitytoken } =
|
|
130
|
+
const { ak, sk, securitytoken } = getCredentials();
|
|
131
131
|
const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
|
|
132
132
|
const WebSocketImpl = await getWebSocketImpl(wsUrl);
|
|
133
133
|
|
|
@@ -166,7 +166,7 @@ async function createTunnelSession(workspaceId, username, timeoutMs = 30000) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
export async function execOneShot(workspaceId, command, username, timeoutMs) {
|
|
169
|
-
const { ak, sk, securitytoken } =
|
|
169
|
+
const { ak, sk, securitytoken } = getCredentials();
|
|
170
170
|
const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
|
|
171
171
|
|
|
172
172
|
const WebSocketImpl = await getWebSocketImpl(wsUrl);
|
|
@@ -25,9 +25,6 @@ import { redactSecrets } from './safety-policy.mjs';
|
|
|
25
25
|
import {
|
|
26
26
|
globalCredentialsPath,
|
|
27
27
|
readGlobalCredentials,
|
|
28
|
-
readJsonFile,
|
|
29
|
-
resolveCredentialsWithRuntime,
|
|
30
|
-
resolveXAuthToken,
|
|
31
28
|
writeGlobalCredentials,
|
|
32
29
|
writeLastSync,
|
|
33
30
|
writeObsConfig,
|
|
@@ -47,7 +44,6 @@ import {
|
|
|
47
44
|
applyUserDelta,
|
|
48
45
|
inheritPeerUserEnv,
|
|
49
46
|
detectOpenCodeEra,
|
|
50
|
-
isPlainObject,
|
|
51
47
|
mergeOpenCodeEntry,
|
|
52
48
|
} from './mcp-config-merge.mjs';
|
|
53
49
|
import { readAgentDelta, saveAgentDelta, takeAgentDelta, purgeBackup } from './mcp-config-backup.mjs';
|
|
@@ -56,6 +52,8 @@ import { queryDistTagsFetch, determineTarget, semverCompare } from './update-che
|
|
|
56
52
|
import { getKooCliVersion, compareVersion, kooCliDownloadBase, KOO_CLI_BASE } from './koocli-version.mjs';
|
|
57
53
|
import { findHcloudBin, hcloudProbeNextStep, probeHcloud } from './hcloud-probe.mjs';
|
|
58
54
|
|
|
55
|
+
const { DatabaseSync } = createRequire(import.meta.url)('node:sqlite');
|
|
56
|
+
|
|
59
57
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
60
58
|
const PLUGIN_ROOT = resolve(__dirname, '..');
|
|
61
59
|
const PACKAGE_ROOT = resolve(PLUGIN_ROOT, '..', '..');
|
|
@@ -252,9 +250,6 @@ function officeaceSqlitePath() {
|
|
|
252
250
|
}
|
|
253
251
|
|
|
254
252
|
function openOfficeaceDb() {
|
|
255
|
-
// Lazy-require node:sqlite (experimental on Node 22.x) so CLI commands that
|
|
256
|
-
// don't touch OfficeAce (version/doctor/install) run without the flag.
|
|
257
|
-
const { DatabaseSync } = createRequire(import.meta.url)('node:sqlite');
|
|
258
253
|
return new DatabaseSync(officeaceSqlitePath());
|
|
259
254
|
}
|
|
260
255
|
|
|
@@ -715,7 +710,7 @@ function resolveOpenCodeEra() {
|
|
|
715
710
|
return (resolvedOpenCodeEra = 'v2');
|
|
716
711
|
}
|
|
717
712
|
|
|
718
|
-
function updateOpenCodeConfig(pluginDir
|
|
713
|
+
function updateOpenCodeConfig(pluginDir) {
|
|
719
714
|
const configPath = opencodeConfigFile();
|
|
720
715
|
const mcpPath = join(pluginDir, 'src', 'mcp-server.mjs').replace(/\\/g, '/');
|
|
721
716
|
const era = resolveOpenCodeEra();
|
|
@@ -734,25 +729,6 @@ function updateOpenCodeConfig(pluginDir, { nativePluginInstalled = false } = {})
|
|
|
734
729
|
|
|
735
730
|
const { config: next, existing, changed } = mergeOpenCodeEntry(config, { mcpPath, era });
|
|
736
731
|
|
|
737
|
-
// Native-plugin mode: the in-process plugin already bridges all 42 tools with
|
|
738
|
-
// the shared callTool layer (names, approval gate, telemetry unchanged). Keep
|
|
739
|
-
// the MCP entry for manual fallback but leave it disabled so OpenCode does
|
|
740
|
-
// not register 42 duplicate `huaweicloud-devkit_*` copies (#940 follow-up).
|
|
741
|
-
let mcpDisabled = false;
|
|
742
|
-
if (nativePluginInstalled) {
|
|
743
|
-
const key = 'huaweicloud-devkit';
|
|
744
|
-
if (era === 'v2') {
|
|
745
|
-
const servers = isPlainObject(next.mcp?.servers) ? next.mcp.servers : null;
|
|
746
|
-
if (servers && servers[key] && servers[key].disabled !== true) {
|
|
747
|
-
servers[key] = { ...servers[key], disabled: true };
|
|
748
|
-
mcpDisabled = true;
|
|
749
|
-
}
|
|
750
|
-
} else if (next.mcp?.[key] && next.mcp[key].enabled !== false) {
|
|
751
|
-
next.mcp[key] = { ...next.mcp[key], enabled: false };
|
|
752
|
-
mcpDisabled = true;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
732
|
// Restore user fields saved by a previous uninstall (issue #615), on fresh install only.
|
|
757
733
|
if (!existing) {
|
|
758
734
|
const delta = takeAgentDelta('opencode');
|
|
@@ -765,15 +741,12 @@ function updateOpenCodeConfig(pluginDir, { nativePluginInstalled = false } = {})
|
|
|
765
741
|
}
|
|
766
742
|
}
|
|
767
743
|
|
|
768
|
-
if (existing && !changed
|
|
744
|
+
if (existing && !changed) {
|
|
769
745
|
console.log(` OpenCode MCP config unchanged: ${configPath}`);
|
|
770
746
|
return;
|
|
771
747
|
}
|
|
772
748
|
|
|
773
749
|
writeMcpSettingsFile(configPath, next);
|
|
774
|
-
if (mcpDisabled) {
|
|
775
|
-
console.log(` OpenCode MCP entry disabled (native plugin active — no duplicate tools) -> ${configPath}`);
|
|
776
|
-
}
|
|
777
750
|
console.log(
|
|
778
751
|
existing
|
|
779
752
|
? ` OpenCode MCP config merged (user fields preserved, ${era}): ${configPath}`
|
|
@@ -995,24 +968,7 @@ async function installOpenCode() {
|
|
|
995
968
|
mkdirSync(opcPlugins, { recursive: true });
|
|
996
969
|
copyFileSync(pluginSrc, join(opcPlugins, 'skill-tracker.js'));
|
|
997
970
|
console.log(` Plugin -> ${opcPlugins}`);
|
|
998
|
-
|
|
999
|
-
// into OpenCode in-process custom tools (zod schemas + callTool), plus safety
|
|
1000
|
-
// gate and telemetry. Local plugins are auto-loaded from this directory.
|
|
1001
|
-
const nativePluginSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'plugins', 'huaweicloud-devkit.js');
|
|
1002
|
-
let nativePluginInstalled = false;
|
|
1003
|
-
if (existsSync(nativePluginSrc)) {
|
|
1004
|
-
copyFileSync(nativePluginSrc, join(opcPlugins, 'huaweicloud-devkit.js'));
|
|
1005
|
-
// Deps for the native plugin (zod) live next to the OpenCode config so the
|
|
1006
|
-
// plugin can require them at load time.
|
|
1007
|
-
const nativePkgSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'package.json');
|
|
1008
|
-
const nativePkgDst = join(configRoot('opencode'), 'package.json');
|
|
1009
|
-
if (existsSync(nativePkgSrc) && !existsSync(nativePkgDst)) {
|
|
1010
|
-
copyFileSync(nativePkgSrc, nativePkgDst);
|
|
1011
|
-
}
|
|
1012
|
-
nativePluginInstalled = true;
|
|
1013
|
-
console.log(` Native plugin -> ${join(opcPlugins, 'huaweicloud-devkit.js')}`);
|
|
1014
|
-
}
|
|
1015
|
-
updateOpenCodeConfig(pluginDest, { nativePluginInstalled });
|
|
971
|
+
updateOpenCodeConfig(pluginDest);
|
|
1016
972
|
installRuntimeDeps(pluginDest);
|
|
1017
973
|
}
|
|
1018
974
|
|
|
@@ -1045,11 +1001,6 @@ function uninstallOpenCode() {
|
|
|
1045
1001
|
removeIfExists(pluginFile);
|
|
1046
1002
|
console.log(' Removed plugin');
|
|
1047
1003
|
}
|
|
1048
|
-
const nativePluginFile = join(configRoot('opencode'), 'plugins', 'huaweicloud-devkit.js');
|
|
1049
|
-
if (existsSync(nativePluginFile)) {
|
|
1050
|
-
removeIfExists(nativePluginFile);
|
|
1051
|
-
console.log(' Removed native plugin');
|
|
1052
|
-
}
|
|
1053
1004
|
|
|
1054
1005
|
if (removeIfExists(opencodePluginsDir())) {
|
|
1055
1006
|
console.log(' Removed MCP server and safety policy');
|
|
@@ -1097,20 +1048,7 @@ async function updateOpenCode() {
|
|
|
1097
1048
|
mkdirSync(opcPlugins, { recursive: true });
|
|
1098
1049
|
copyFileSync(pluginSrc, join(opcPlugins, 'skill-tracker.js'));
|
|
1099
1050
|
console.log(` Plugin updated -> ${opcPlugins}`);
|
|
1100
|
-
|
|
1101
|
-
const nativePluginSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'plugins', 'huaweicloud-devkit.js');
|
|
1102
|
-
let nativePluginInstalled = false;
|
|
1103
|
-
if (existsSync(nativePluginSrc)) {
|
|
1104
|
-
copyFileSync(nativePluginSrc, join(opcPlugins, 'huaweicloud-devkit.js'));
|
|
1105
|
-
const nativePkgSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'package.json');
|
|
1106
|
-
const nativePkgDst = join(configRoot('opencode'), 'package.json');
|
|
1107
|
-
if (existsSync(nativePkgSrc) && !existsSync(nativePkgDst)) {
|
|
1108
|
-
copyFileSync(nativePkgSrc, nativePkgDst);
|
|
1109
|
-
}
|
|
1110
|
-
nativePluginInstalled = true;
|
|
1111
|
-
console.log(` Native plugin updated -> ${join(opcPlugins, 'huaweicloud-devkit.js')}`);
|
|
1112
|
-
}
|
|
1113
|
-
updateOpenCodeConfig(pluginDest, { nativePluginInstalled });
|
|
1051
|
+
updateOpenCodeConfig(pluginDest);
|
|
1114
1052
|
mkdirSync(pluginDest, { recursive: true });
|
|
1115
1053
|
writeFileSync(join(pluginDest, '.installed'), new Date().toISOString());
|
|
1116
1054
|
installRuntimeDeps(pluginDest);
|
|
@@ -1595,7 +1533,7 @@ function codeartsStatus() {
|
|
|
1595
1533
|
);
|
|
1596
1534
|
if (existsSync(codeartsMcpSettingsFile())) {
|
|
1597
1535
|
try {
|
|
1598
|
-
const config =
|
|
1536
|
+
const config = JSON.parse(readFileSync(codeartsMcpSettingsFile(), 'utf8'));
|
|
1599
1537
|
console.log(
|
|
1600
1538
|
` MCP config: ${config.mcpServers?.['huaweicloud-devkit'] ? '\x1b[32mConfigured\x1b[0m' : '\x1b[31mNot configured\x1b[0m'}`,
|
|
1601
1539
|
);
|
|
@@ -1756,7 +1694,7 @@ function codeartsWorkStatus() {
|
|
|
1756
1694
|
);
|
|
1757
1695
|
if (existsSync(codeartsWorkMcpSettingsFile())) {
|
|
1758
1696
|
try {
|
|
1759
|
-
const config =
|
|
1697
|
+
const config = JSON.parse(readFileSync(codeartsWorkMcpSettingsFile(), 'utf8'));
|
|
1760
1698
|
console.log(
|
|
1761
1699
|
` MCP config: ${config.mcp?.['huaweicloud-devkit'] ? '\x1b[32mConfigured\x1b[0m' : '\x1b[31mNot configured\x1b[0m'}`,
|
|
1762
1700
|
);
|
|
@@ -4321,27 +4259,7 @@ async function cmdDoctor() {
|
|
|
4321
4259
|
timeout: 5000,
|
|
4322
4260
|
});
|
|
4323
4261
|
const hasAuth = authCheck.status === 0 && /access.?key/i.test(authCheck.stdout.toString());
|
|
4324
|
-
|
|
4325
|
-
check('hcloud credentials configured', true, '');
|
|
4326
|
-
} else {
|
|
4327
|
-
// In CodeArts, platform-injected STS / X-Auth-Token reach only the MCP
|
|
4328
|
-
// server process, not this bash tool process — so `hcloud configure list`
|
|
4329
|
-
// shows no profile even though the backend API path is usable. Degrade to
|
|
4330
|
-
// a warning instead of a hard fail in that case (#P3 of CodeArts test).
|
|
4331
|
-
let platformCredsActive = false;
|
|
4332
|
-
try {
|
|
4333
|
-
const c = resolveCredentialsWithRuntime({ allowMissing: true });
|
|
4334
|
-
platformCredsActive = Boolean((c && c.ak && c.sk && c.securityToken) || resolveXAuthToken());
|
|
4335
|
-
} catch {}
|
|
4336
|
-
if (platformCredsActive) {
|
|
4337
|
-
console.log(
|
|
4338
|
-
` \x1b[33m[WARN]\x1b[0m hcloud credentials configured — KooCLI 无 profile,但检测到平台凭证(MCP 通道可用);仅 KooCLI 直接调用需 auth init`,
|
|
4339
|
-
);
|
|
4340
|
-
warn++;
|
|
4341
|
-
} else {
|
|
4342
|
-
check('hcloud credentials configured', false, 'Run: npx huaweicloud-devkit auth init');
|
|
4343
|
-
}
|
|
4344
|
-
}
|
|
4262
|
+
check('hcloud credentials configured', hasAuth, 'Run: npx huaweicloud-devkit auth init');
|
|
4345
4263
|
}
|
|
4346
4264
|
|
|
4347
4265
|
// Skills
|