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
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](https://github.com/huaweicloud/huaweicloud-devkit/actions/workflows/ci.yml)
|
|
6
6
|
[](https://www.npmjs.com/package/huaweicloud-devkit)
|
|
7
|
-
[](https://github.com/huaweicloud/huaweicloud-devkit)
|
|
8
8
|
|
|
9
9
|
**[中文](README.zh-CN.md) | English**
|
|
10
10
|
|
|
@@ -332,6 +332,18 @@ npx --yes huaweicloud-devkit@latest update --target all
|
|
|
332
332
|
config. Always keep `@latest` so npm fetches the newest version instead of a
|
|
333
333
|
locally cached older one.
|
|
334
334
|
|
|
335
|
+
### Automatic upgrades
|
|
336
|
+
|
|
337
|
+
The plugin upgrades itself in the background; there is no confirmation prompt:
|
|
338
|
+
|
|
339
|
+
- At session start it fetches `HDKITSERVICE_ENDPOINT/upgrade/policy`; when the server enforces a minimum version and the client is below it, the upgrade runs immediately (bypassing the cooldown).
|
|
340
|
+
- An ordinary new version is installed at a later session start only after it has been on npm for 24 hours.
|
|
341
|
+
- Any `409 HDKIT_VERSION_TOO_OLD` from a hdkitservice endpoint triggers the same immediate upgrade.
|
|
342
|
+
- Auto-upgrade only applies when the plugin runs from a directory the `update` command rewrites (per-agent plugin dirs such as `~/.config/opencode/huaweicloud-plugins`). Marketplace/cache installs (Claude Code, Codex CLI plugin cache) and unpacked tarballs get a manual-upgrade hint instead — the 409 response carries it.
|
|
343
|
+
- Restart the session after installation; the current session keeps running the old code and remains blocked by the version gate.
|
|
344
|
+
- Before an upgrade the running dir's `src/`, `package.json`, and the plugin version manifests are backed up; if verification against the backup fails, everything is restored.
|
|
345
|
+
- Internal guards: `HUAWEICLOUD_DEVKIT_SKIP_UPDATE=1`, CI environments, and git checkouts skip automatic upgrades.
|
|
346
|
+
|
|
335
347
|
### Configure Proxy
|
|
336
348
|
|
|
337
349
|
```bash
|
package/README.zh-CN.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](https://github.com/huaweicloud/huaweicloud-devkit/actions/workflows/ci.yml)
|
|
6
6
|
[](https://www.npmjs.com/package/huaweicloud-devkit)
|
|
7
|
-
[](https://github.com/huaweicloud/huaweicloud-devkit)
|
|
8
8
|
|
|
9
9
|
**中文 | [English](README.md)**
|
|
10
10
|
|
|
@@ -326,6 +326,18 @@ npx --yes huaweicloud-devkit@latest update --target all
|
|
|
326
326
|
|
|
327
327
|
`update` 是增量更新——只刷新已安装的文件,不动配置文件。请务必保留 `@latest`,确保 npm 获取最新版本而非本地缓存的旧版本。
|
|
328
328
|
|
|
329
|
+
### 自动升级
|
|
330
|
+
|
|
331
|
+
插件默认在后台自动安装升级,不弹确认框:
|
|
332
|
+
|
|
333
|
+
- 会话启动时拉取 `HDKITSERVICE_ENDPOINT/upgrade/policy`;若服务端启用最低版本且当前版本低于该值,立即升级(跳过冷却)。
|
|
334
|
+
- 普通新版本需在 npm 发布满 24 小时,才会在之后的会话启动时自动安装。
|
|
335
|
+
- 任意 hdkitservice 接口返回 `409 HDKIT_VERSION_TOO_OLD` 时立即触发升级。
|
|
336
|
+
- 自动升级只作用于 `update` 命令会重写的目录(各 Agent 插件目录,如 `~/.config/opencode/huaweicloud-plugins`)。插件市场/缓存类安装(Claude Code、Codex CLI 插件缓存)与解包目录不在范围内,409 响应会直接给出对应的手动升级指引。
|
|
337
|
+
- 安装完成后必须重启会话;当前会话仍运行旧代码,并继续被版本门禁拦截。
|
|
338
|
+
- 升级前备份运行目录的 `src/`、`package.json` 与全部版本 manifest;校验失败自动整体恢复。
|
|
339
|
+
- 内部保护:`HUAWEICLOUD_DEVKIT_SKIP_UPDATE=1`、CI 环境、git 仓库开发态会自动跳过。
|
|
340
|
+
|
|
329
341
|
### 配置代理
|
|
330
342
|
|
|
331
343
|
```bash
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"mcpName": "io.github.huaweicloud/huaweicloud-devkit",
|
|
4
|
-
"version": "1.1.14-next.
|
|
4
|
+
"version": "1.1.14-next.2",
|
|
5
5
|
"kooCliVersion": "7.3.12",
|
|
6
6
|
"description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
|
|
7
7
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"mcpServers": "./.mcp.json",
|
|
18
18
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
19
19
|
"skills": "./skills/",
|
|
20
|
-
"version": "1.1.14-next.
|
|
20
|
+
"version": "1.1.14-next.2",
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "HuaweiCloud Mate",
|
|
23
23
|
"url": "https://github.com/huaweicloud"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"mcpServers": "./.mcp.json",
|
|
21
21
|
"description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
|
|
22
22
|
"skills": "./skills/",
|
|
23
|
-
"version": "1.1.14-next.
|
|
23
|
+
"version": "1.1.14-next.2",
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "HuaweiCloud Mate",
|
|
26
26
|
"url": "https://github.com/huaweicloud"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"mcpServers": "./.mcp.json",
|
|
18
18
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
19
19
|
"skills": "./skills/",
|
|
20
|
-
"version": "1.1.14-next.
|
|
20
|
+
"version": "1.1.14-next.2",
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "HuaweiCloud Mate",
|
|
23
23
|
"url": "https://github.com/huaweicloud"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
|
-
"version": "1.1.14-next.
|
|
3
|
+
"version": "1.1.14-next.2",
|
|
4
4
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HuaweiCloud Mate",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
|
-
"version": "1.1.14-next.
|
|
3
|
+
"version": "1.1.14-next.2",
|
|
4
4
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HuaweiCloud Mate",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"id": "huaweicloud-devkit",
|
|
4
4
|
"displayName": "HuaweiCloud DevKit",
|
|
5
|
-
"version": "1.1.14-next.
|
|
5
|
+
"version": "1.1.14-next.2",
|
|
6
6
|
"family": "bundle-plugin",
|
|
7
7
|
"bundleFormat": "codex",
|
|
8
8
|
"description": "Guide coding agents to use Huawei Cloud safely — KooCLI, APIs, SDKs, 28 MCP tools, skills, and safety guardrails.",
|
|
@@ -429,12 +429,6 @@
|
|
|
429
429
|
"field": "text",
|
|
430
430
|
"regex": "\\bfdisk\\b"
|
|
431
431
|
}
|
|
432
|
-
],
|
|
433
|
-
"none": [
|
|
434
|
-
{
|
|
435
|
-
"field": "text",
|
|
436
|
-
"regex": "\\bhcloud\\b"
|
|
437
|
-
}
|
|
438
432
|
]
|
|
439
433
|
},
|
|
440
434
|
"message": "The sandbox terminal command is destructively dangerous and could destroy the workspace.",
|
|
@@ -51,7 +51,7 @@ Domain expertise for Huawei Cloud Sandbox (DevStation) instances and workspace t
|
|
|
51
51
|
|
|
52
52
|
> 口径基调:一切以实测为准,口头支持不作数(下表生命周期为实测/平台侧现状;数值为服务端配置下发的默认口径,平台调参以服务端回显为准)。
|
|
53
53
|
|
|
54
|
-
`huaweicloud_sandbox_connect` 用 `pool_type` 选择资源池(服务端权威映射模板;**没有 persist_mode
|
|
54
|
+
`huaweicloud_sandbox_connect` 用 `pool_type` 选择资源池(服务端权威映射模板;**没有 persist_mode 参数**;客户端不再支持传 template_id/自定义模板):
|
|
55
55
|
|
|
56
56
|
| pool_type | 语义 | 生命周期(平台策略) | 适用 |
|
|
57
57
|
| ------------------- | ------------------ | ------------------------------------------------------------ | --------------------------- |
|
|
@@ -74,7 +74,7 @@ Selection rules(agent 按意图自动选池,开发者可覆盖;意图不
|
|
|
74
74
|
- **TTL 播报**:仅 connect(会话首次连接 / 复用被唤醒 `started=true`)与 expose_tunnel(交付地址时)返回生命周期提示;其余执行类工具不逐次播报。**ephemeral 池部署的公网地址会随沙箱闲置关机失效**,向开发者交付 URL 时必须转述 `urlLifetimeHint` / `warnings` 中的存活期提示(隧道有效期 ≠ 沙箱存活期)。数值以服务端回显为准,缺失时用默认口径兜底
|
|
75
75
|
- **烧核播报口径**:沙箱运行消耗核时,播报用「平台赠送 + 活动赚取」口径(非直接计费);账号核时耗尽(`HD.97520422`)时工具返回值给出友好引导
|
|
76
76
|
- **删除纪律**:不向开发者暴露生命周期删除 API(回收走平台闲置策略 G1);开发者主动删除时必须二次确认(确认要删除?数据不可恢复);绝不做延后代删
|
|
77
|
-
-
|
|
77
|
+
- 不支持传 `template_id`;自定义模板已下线,客户端只传 `pool_type`
|
|
78
78
|
- 完整口径、容量规划与 G 清单:[references/resource-pool.md](references/resource-pool.md)
|
|
79
79
|
|
|
80
80
|
## Activation
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
## 机制
|
|
8
8
|
|
|
9
9
|
- **池 = 平台预置模板**:非持久 `9a108ab1bc354bc4979b949b36e3c8c1` / 持久 `05860f507ee94930844907a3a136d1a7` / flavor 3U6G `23ebdfe3b2d34cc4b34a1aaf03d27c54`(服务端 `POOL_TEMPLATE_*` 环境变量维护)
|
|
10
|
-
-
|
|
11
|
-
- **无 persist_mode
|
|
12
|
-
- 实例名前缀即池归属:`hcdke*`(非持久)/ `hcdkp*`(持久);同池才复用。遗留 `hcdk*`
|
|
10
|
+
- 客户端只传 `pool_type`(ephemeral/persistent),**服务端权威映射** template_id;template_id/自定义模板已下线
|
|
11
|
+
- **无 persist_mode 请求参数**;闲置语义由平台按模板配置;上游参数面有 template_id,但客户端不再传入
|
|
12
|
+
- 实例名前缀即池归属:`hcdke*`(非持久)/ `hcdkp*`(持久);同池才复用。遗留 `hcdk*` 老实例不参与池复用、不阻挡池实例创建,由平台闲置策略回收
|
|
13
13
|
|
|
14
14
|
## 两类沙箱
|
|
15
15
|
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
- 生命周期提示只在两个时机播报:connect(会话首次连接,或复用实例被唤醒 `started=true`)与 `expose_tunnel`(交付地址时,返回 `urlLifetimeHint` + `warnings`);其余 exec/upload/deploy 工具不逐次播报
|
|
64
64
|
- connect 返回值富化 `pool` 块(数值取服务端回显,缺失时用默认口径);生命周期口径按 workspace 缓存到 `~/.config/huaweicloud/sandbox-pools.json`(0600,7 天过期),进程重启后仍可播报
|
|
65
65
|
- 429:配额满给 `remediation` 引导;容量不足只透传服务端最终文案 + `retryAfter`
|
|
66
|
-
-
|
|
66
|
+
- 模板 ID 仅由服务端 `POOL_TEMPLATE_*` 权威维护;客户端不再支持 `HW_POOL_TEMPLATE_*` 钉扎或显式 template_id
|
|
67
67
|
|
|
68
68
|
## 平台侧关键依赖(G 清单,非 devkit 交付)
|
|
69
69
|
|
|
@@ -14,6 +14,8 @@ Huawei Cloud comprises 200+ services. This skill is the entry point for ANY acti
|
|
|
14
14
|
|
|
15
15
|
首次操作前先调用 `huaweicloud_check_update` 检查插件版本;若未先行检查,插件会在使用中收到服务端升级提示。
|
|
16
16
|
|
|
17
|
+
插件默认在后台自动安装升级:会话启动时拉取服务端升级策略,若当前版本低于最低版本则立即升级;普通新版本需在 npm 发布满 24h 后升级;服务端 409 `HDKIT_VERSION_TOO_OLD` 会触发同一自动升级。升级完成后必须重启会话(当前会话仍运行旧代码)。插件市场/缓存类安装(Claude Code、Codex CLI)不在自动升级范围内:409 响应会带 `autoUpgrade.status=unsupported_install` 与手动升级指引(如 Claude Code 走 `/plugin`),按指引手动升级后重启即可。
|
|
18
|
+
|
|
17
19
|
1. 如果 `updateAvailable == true` 且 `dismissed == false`,先询问用户是否升级
|
|
18
20
|
2. 用户同意 → 调用 `huaweicloud_upgrade`,完成后提示重启会话
|
|
19
21
|
3. 用户拒绝 → 调用 `huaweicloud_check_update` 传 `dismiss: true`
|
|
@@ -112,16 +112,7 @@ export async function checkAccountType({ region } = {}) {
|
|
|
112
112
|
}
|
|
113
113
|
const identity = parseCallerIdentity(identityResult.stdout);
|
|
114
114
|
if (!identity.ok) {
|
|
115
|
-
|
|
116
|
-
// problem surfacing as free-text error output, not a parser bug.
|
|
117
|
-
const snippet = String(identityResult.stdout || '')
|
|
118
|
-
.slice(0, 200)
|
|
119
|
-
.replace(/\s+/g, ' ');
|
|
120
|
-
return {
|
|
121
|
-
ok: false,
|
|
122
|
-
error: identity.error + (snippet ? ` (raw: ${snippet})` : ''),
|
|
123
|
-
hint: 'GetCallerIdentity 未返回 JSON,通常是凭据未就绪:请确认已运行 auth init、或平台已注入可用 STS(先用 huaweicloud_auth_status 查看 usableCredentials/credentialPanel)。',
|
|
124
|
-
};
|
|
115
|
+
return { ok: false, error: identity.error };
|
|
125
116
|
}
|
|
126
117
|
|
|
127
118
|
const domainsResult = await runHcloud(['IAM', 'KeystoneListAuthDomains'], {
|
|
@@ -31,7 +31,7 @@ function opencodeConfigFile() {
|
|
|
31
31
|
function readJsonSafe(path) {
|
|
32
32
|
if (!existsSync(path)) return null;
|
|
33
33
|
try {
|
|
34
|
-
return JSON.parse(readFileSync(path, 'utf8')
|
|
34
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
35
35
|
} catch {
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
@@ -50,18 +50,11 @@ export function obsConfigPath() {
|
|
|
50
50
|
return process.env.HCLOUD_OBS_CONFIG_PATH || join(homedir(), '.obsutilconfig');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// Read a JSON file, stripping a leading UTF-8 BOM (U+FEFF) if present. CodeArts
|
|
54
|
-
// writes mcp_settings.json with a BOM on Windows; plain JSON.parse would throw.
|
|
55
|
-
export function readJsonFile(path) {
|
|
56
|
-
const text = readFileSync(path, 'utf8');
|
|
57
|
-
return JSON.parse(text.replace(/^\uFEFF/, ''));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
53
|
export function readGlobalCredentials() {
|
|
61
54
|
const path = globalCredentialsPath();
|
|
62
55
|
if (!existsSync(path)) return null;
|
|
63
56
|
try {
|
|
64
|
-
return
|
|
57
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
65
58
|
} catch {
|
|
66
59
|
return null;
|
|
67
60
|
}
|
|
@@ -332,7 +325,7 @@ export function readCodeArtsCredentials() {
|
|
|
332
325
|
const path = join(dir, '.codeartsdoer', 'mcp', 'mcp_settings.json');
|
|
333
326
|
try {
|
|
334
327
|
if (!existsSync(path)) continue;
|
|
335
|
-
const config =
|
|
328
|
+
const config = JSON.parse(readFileSync(path, 'utf8'));
|
|
336
329
|
const server = pickDevkitMcpServer(config?.mcpServers);
|
|
337
330
|
if (!server?.env) continue;
|
|
338
331
|
|
|
@@ -362,7 +355,7 @@ export function readCodeArtsCredentials() {
|
|
|
362
355
|
for (const path of workPaths) {
|
|
363
356
|
try {
|
|
364
357
|
if (!existsSync(path)) continue;
|
|
365
|
-
const config =
|
|
358
|
+
const config = JSON.parse(readFileSync(path, 'utf8'));
|
|
366
359
|
const entry = readWorkEnvironmentEntry(config);
|
|
367
360
|
if (entry) return entry;
|
|
368
361
|
} catch {
|
|
@@ -400,87 +393,6 @@ export function resolveCredentialsWithRuntime(options = {}) {
|
|
|
400
393
|
return resolveCredentials(options);
|
|
401
394
|
}
|
|
402
395
|
|
|
403
|
-
export function resolveXAuthToken() {
|
|
404
|
-
const envToken = process.env.HW_X_AUTH_TOKEN;
|
|
405
|
-
if (present(envToken)) return envToken;
|
|
406
|
-
|
|
407
|
-
const parentCwd = getParentCwd();
|
|
408
|
-
const searchDirs = [process.env.CODEARTS_PROJECT_DIR, parentCwd, process.cwd(), homedir()];
|
|
409
|
-
for (const dir of searchDirs) {
|
|
410
|
-
if (!dir) continue;
|
|
411
|
-
const path = join(dir, '.codeartsdoer', 'mcp', 'mcp_settings.json');
|
|
412
|
-
try {
|
|
413
|
-
if (!existsSync(path)) continue;
|
|
414
|
-
const config = readJsonFile(path);
|
|
415
|
-
const server = pickDevkitMcpServer(config?.mcpServers);
|
|
416
|
-
const token = server?.env?.HW_X_AUTH_TOKEN;
|
|
417
|
-
if (present(token)) return token;
|
|
418
|
-
} catch {}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const workPaths = [
|
|
422
|
-
join(homedir(), '.codearts', 'mcp', 'mcp_settings.json'),
|
|
423
|
-
join(homedir(), '.codeartswork', 'mcp', 'mcp_settings.json'),
|
|
424
|
-
];
|
|
425
|
-
for (const path of workPaths) {
|
|
426
|
-
try {
|
|
427
|
-
if (!existsSync(path)) continue;
|
|
428
|
-
const config = readJsonFile(path);
|
|
429
|
-
const server = pickDevkitMcpServer(config?.mcp);
|
|
430
|
-
const token = server?.environment?.HW_X_AUTH_TOKEN;
|
|
431
|
-
if (present(token)) return token;
|
|
432
|
-
} catch {}
|
|
433
|
-
}
|
|
434
|
-
return null;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
export function resolveXAuthTokenExpiry() {
|
|
438
|
-
const v = process.env.HW_X_AUTH_TOKEN_EXPIRES_AT;
|
|
439
|
-
if (v && typeof v === 'string' && v.trim()) {
|
|
440
|
-
const asNum = Number(v.trim());
|
|
441
|
-
if (Number.isFinite(asNum) && asNum > 0) return asNum > 1e12 ? asNum : asNum * 1000;
|
|
442
|
-
const t = Date.parse(v.trim());
|
|
443
|
-
if (Number.isFinite(t)) return t;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Fallback: 未注入 HW_X_AUTH_TOKEN_EXPIRES_AT 时,从 token 字符串自解析过期时间。
|
|
447
|
-
// X-Auth-Token 是 CMS/PKCS#7 SignedData(base64 DER),其 eContent 内嵌明文 JSON
|
|
448
|
-
// (含 token.expires_at);base64 解码 + 提取 {"token" JSON 即可读出,无需依赖注入方显式给过期时间。
|
|
449
|
-
const token = resolveXAuthToken();
|
|
450
|
-
if (!token) return null;
|
|
451
|
-
return parseXAuthTokenExpiry(token);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
function parseXAuthTokenExpiry(token) {
|
|
455
|
-
try {
|
|
456
|
-
const pad = token + '='.repeat((4 - (token.length % 4)) % 4);
|
|
457
|
-
const text = Buffer.from(pad.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8');
|
|
458
|
-
const idx = text.indexOf('{"token"');
|
|
459
|
-
if (idx < 0) return null;
|
|
460
|
-
const tail = text.slice(idx);
|
|
461
|
-
let depth = 0;
|
|
462
|
-
let end = -1;
|
|
463
|
-
for (let i = 0; i < tail.length; i += 1) {
|
|
464
|
-
if (tail[i] === '{') depth += 1;
|
|
465
|
-
else if (tail[i] === '}') {
|
|
466
|
-
depth -= 1;
|
|
467
|
-
if (depth === 0) {
|
|
468
|
-
end = i + 1;
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
if (end < 0) return null;
|
|
474
|
-
const obj = JSON.parse(tail.slice(0, end));
|
|
475
|
-
const expiresAt = obj?.token?.expires_at;
|
|
476
|
-
if (!expiresAt || typeof expiresAt !== 'string') return null;
|
|
477
|
-
const t = Date.parse(expiresAt);
|
|
478
|
-
return Number.isFinite(t) ? t : null;
|
|
479
|
-
} catch {
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
396
|
export function lastSyncPath() {
|
|
485
397
|
return join(baseHome(), '.config', 'huaweicloud', '.last_sync');
|
|
486
398
|
}
|
|
@@ -489,7 +401,7 @@ export function readLastSync() {
|
|
|
489
401
|
const path = lastSyncPath();
|
|
490
402
|
if (!existsSync(path)) return null;
|
|
491
403
|
try {
|
|
492
|
-
return
|
|
404
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
493
405
|
} catch {
|
|
494
406
|
return null;
|
|
495
407
|
}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
readCodeArtsCredentials,
|
|
12
12
|
readGlobalCredentials,
|
|
13
13
|
resolveCredentialsWithRuntime,
|
|
14
|
-
resolveXAuthToken,
|
|
15
14
|
writeLastSync,
|
|
16
15
|
writeObsConfig,
|
|
17
16
|
} from './credentials.mjs';
|
|
@@ -80,15 +79,6 @@ export function computeOnboarding({ credentials, reconciled } = {}) {
|
|
|
80
79
|
message = '已从码道 MCP settings 读取到临时凭证,MCP 工具可直接使用。';
|
|
81
80
|
return { needsSetup: false, scenario, reason, message, steps: [], accountHint };
|
|
82
81
|
}
|
|
83
|
-
if (resolveXAuthToken() && !s1Has && !envHasCreds) {
|
|
84
|
-
// X-Auth-Token authentication: no AK/SK injected but a token is present —
|
|
85
|
-
// devkit exchanges it for temporary AK/SK on demand, so no manual setup.
|
|
86
|
-
scenario = 0;
|
|
87
|
-
reason = 'token-auth';
|
|
88
|
-
message =
|
|
89
|
-
'已使用 X-Auth-Token 认证。管理面与数据面(沙箱部署/exec)都会在需要时用 token 自动换取临时 AK/SK;请确保可访问 IAM 端点。';
|
|
90
|
-
return { needsSetup: false, scenario, reason, message, steps: [], accountHint };
|
|
91
|
-
}
|
|
92
82
|
if (s1Has && !envHasCreds) {
|
|
93
83
|
scenario = 1;
|
|
94
84
|
reason = 's1-only';
|
|
@@ -177,7 +167,6 @@ export function getAuthStatus(target = 'all') {
|
|
|
177
167
|
const s4Creds = readCodeArtsCredentials();
|
|
178
168
|
const onboarding = computeOnboarding({ credentials, reconciled });
|
|
179
169
|
const stsExpiry = computeStsExpiry();
|
|
180
|
-
const tokenAuth = resolveXAuthToken();
|
|
181
170
|
const credentialPanel = {
|
|
182
171
|
sts: stsExpiry, // 临时 STS(MCP==沙箱同源)
|
|
183
172
|
s1: {
|
|
@@ -185,23 +174,11 @@ export function getAuthStatus(target = 'all') {
|
|
|
185
174
|
fingerprint: credentials?.ak ? fingerprint(credentials.ak, credentials.sk) : null,
|
|
186
175
|
persistent: true, // 永久,无过期
|
|
187
176
|
},
|
|
188
|
-
|
|
189
|
-
activeSource: stsExpiry ? 'temporary-sts' : credentials?.ak ? 's1-persistent' : tokenAuth ? 'x-auth-token' : 'none',
|
|
177
|
+
activeSource: stsExpiry ? 'temporary-sts' : credentials?.ak ? 's1-persistent' : 'none',
|
|
190
178
|
};
|
|
191
179
|
return {
|
|
192
180
|
target,
|
|
193
|
-
|
|
194
|
-
// actually work right now (S1, CodeArts settings, platform STS triplet,
|
|
195
|
-
// X-Auth-Token, or runtime creds) — supersedes the misleading
|
|
196
|
-
// credentialsConfigured/onboarding split (#P4).
|
|
197
|
-
usableCredentials: Boolean(
|
|
198
|
-
(credentials?.ak && credentials?.sk) ||
|
|
199
|
-
(s4Creds?.ak && s4Creds?.sk) ||
|
|
200
|
-
envHasRealTriplet() ||
|
|
201
|
-
tokenAuth ||
|
|
202
|
-
hasRuntimeCredentials(),
|
|
203
|
-
),
|
|
204
|
-
credentialsConfigured: Boolean(credentials?.ak && credentials?.sk) || Boolean(tokenAuth),
|
|
181
|
+
credentialsConfigured: Boolean(credentials?.ak && credentials?.sk),
|
|
205
182
|
credentialsPath: globalCredentialsPath(),
|
|
206
183
|
mcpSettingsConfigured: Boolean(s4Creds?.ak && s4Creds?.sk),
|
|
207
184
|
mcpSettingsSource: s4Creds ? 'codearts' : null,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { autoUpgradePaths, runAutoUpgrade, writeAutoUpgradeState } from './update-auto.mjs';
|
|
5
|
+
|
|
6
|
+
function arg(name, fallback = '') {
|
|
7
|
+
const idx = process.argv.indexOf(name);
|
|
8
|
+
return idx > -1 && process.argv[idx + 1] !== undefined ? process.argv[idx + 1] : fallback;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function track(key, value) {
|
|
12
|
+
try {
|
|
13
|
+
const { enqueueEvent, flushEvents } = await import('./telemetry/telemetry.mjs');
|
|
14
|
+
enqueueEvent({ key, value });
|
|
15
|
+
await flushEvents();
|
|
16
|
+
} catch {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const trigger = arg('--trigger', 'startup_normal');
|
|
20
|
+
const minVersion = arg('--min-version', '');
|
|
21
|
+
const currentVersion = arg('--current-version', '');
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await track('upgrade:auto_started', trigger);
|
|
25
|
+
const state = await runAutoUpgrade({
|
|
26
|
+
trigger,
|
|
27
|
+
minVersion,
|
|
28
|
+
...(currentVersion ? { currentVersion } : {}),
|
|
29
|
+
});
|
|
30
|
+
process.exitCode = state?.lastResult === 'failed' ? 1 : 0;
|
|
31
|
+
if (state?.lastResult === 'succeeded') {
|
|
32
|
+
await track('upgrade:auto_succeeded', state.targetVersion || trigger);
|
|
33
|
+
} else if (state?.lastResult === 'failed') {
|
|
34
|
+
await track('upgrade:auto_failed', state.error || state.targetVersion || trigger);
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const paths = autoUpgradePaths();
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(dirname(paths.log), { recursive: true, mode: 0o700 });
|
|
40
|
+
appendFileSync(paths.log, `[${new Date().toISOString()}] fatal ${error?.message || String(error)}\n`, {
|
|
41
|
+
mode: 0o600,
|
|
42
|
+
});
|
|
43
|
+
} catch {}
|
|
44
|
+
try {
|
|
45
|
+
writeAutoUpgradeState(
|
|
46
|
+
{
|
|
47
|
+
lastResult: 'failed',
|
|
48
|
+
trigger,
|
|
49
|
+
fromVersion: currentVersion || null,
|
|
50
|
+
error: error?.message || String(error),
|
|
51
|
+
finishedAt: new Date().toISOString(),
|
|
52
|
+
},
|
|
53
|
+
{ statePath: paths.state },
|
|
54
|
+
);
|
|
55
|
+
} catch {}
|
|
56
|
+
await track('upgrade:auto_failed', error?.message || String(error));
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
}
|
|
@@ -7,13 +7,7 @@ import { dirname, join } from 'node:path';
|
|
|
7
7
|
import { classifyHcloudArgs, redactSecrets, assertAllowed } from './safety-policy.mjs';
|
|
8
8
|
import { getProxySettings } from './proxy/proxy-config.mjs';
|
|
9
9
|
import { resolveHcloudCommand } from './hcloud-probe.mjs';
|
|
10
|
-
import {
|
|
11
|
-
parseStsExpiry,
|
|
12
|
-
resolveCredentialsWithRuntime,
|
|
13
|
-
resolveXAuthToken,
|
|
14
|
-
resolveXAuthTokenExpiry,
|
|
15
|
-
} from './auth/credentials.mjs';
|
|
16
|
-
import { getTokenCredentials } from './auth/token-exchange.mjs';
|
|
10
|
+
import { parseStsExpiry, resolveCredentialsWithRuntime } from './auth/credentials.mjs';
|
|
17
11
|
|
|
18
12
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
19
13
|
const DEFAULT_FORCE_KILL_AFTER_MS = 2_000;
|
|
@@ -303,7 +297,7 @@ export function redactArgsWithObs(rawArgs) {
|
|
|
303
297
|
return redactSecrets(out);
|
|
304
298
|
}
|
|
305
299
|
|
|
306
|
-
export
|
|
300
|
+
export function resolveStsInjectArgs(rawArgs) {
|
|
307
301
|
const normalized = Array.isArray(rawArgs) ? rawArgs.map(String) : [];
|
|
308
302
|
if (normalized.length === 0) return [];
|
|
309
303
|
const flat = normalized.map(String);
|
|
@@ -356,25 +350,7 @@ export async function resolveStsInjectArgs(rawArgs) {
|
|
|
356
350
|
} catch {
|
|
357
351
|
return [];
|
|
358
352
|
}
|
|
359
|
-
if (!creds || !creds.ak || !creds.sk)
|
|
360
|
-
const token = resolveXAuthToken();
|
|
361
|
-
if (token) {
|
|
362
|
-
const expiry = resolveXAuthTokenExpiry();
|
|
363
|
-
if (expiry !== null && expiry - 60000 <= Date.now()) {
|
|
364
|
-
const err = new Error('X-Auth-Token 已过期,请重启进程重新注入凭证。');
|
|
365
|
-
err.code = 'TOKEN_EXPIRED';
|
|
366
|
-
throw err;
|
|
367
|
-
}
|
|
368
|
-
const temp = await getTokenCredentials(token);
|
|
369
|
-
return [
|
|
370
|
-
'--cli-access-key=' + temp.ak,
|
|
371
|
-
'--cli-secret-key=' + temp.sk,
|
|
372
|
-
'--cli-security-token=' + temp.securityToken,
|
|
373
|
-
];
|
|
374
|
-
}
|
|
375
|
-
return [];
|
|
376
|
-
}
|
|
377
|
-
if (!creds.securityToken) return [];
|
|
353
|
+
if (!creds || !creds.ak || !creds.sk || !creds.securityToken) return [];
|
|
378
354
|
|
|
379
355
|
// R3: if we can derive an expiry and the token is already at/within 60s of
|
|
380
356
|
// expiring, skip injection — using a dead token would make a doomed IAM round
|
|
@@ -492,22 +468,7 @@ export async function runHcloud(args, options = {}) {
|
|
|
492
468
|
// and R3 forbids writing them to disk). Inject per-command so hcloud actually
|
|
493
469
|
// authenticates with the platform-provided STS. Injection args are appended to
|
|
494
470
|
// the EXECUTED args only; classification/approval used the original args.
|
|
495
|
-
|
|
496
|
-
try {
|
|
497
|
-
stsInject = await resolveStsInjectArgs(normalizedArgs);
|
|
498
|
-
} catch (error) {
|
|
499
|
-
if (error?.code === 'TOKEN_INVALID' || error?.code === 'TOKEN_EXCHANGE_FAILED' || error?.code === 'TOKEN_EXPIRED') {
|
|
500
|
-
return {
|
|
501
|
-
ok: false,
|
|
502
|
-
code: error.code,
|
|
503
|
-
error: error.message,
|
|
504
|
-
stderr: '',
|
|
505
|
-
stdout: '',
|
|
506
|
-
plan,
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
throw error;
|
|
510
|
-
}
|
|
471
|
+
const stsInject = resolveStsInjectArgs(normalizedArgs);
|
|
511
472
|
if (stsInject.length > 0) {
|
|
512
473
|
plan.rawArgs = [...plan.rawArgs, ...stsInject];
|
|
513
474
|
}
|
|
@@ -111,18 +111,6 @@ export function classifyHcloudProbe(result, requiredVersion = getKooCliVersion()
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
// Probe timed out / was signal-killed: we can't tell whether hcloud is truly
|
|
115
|
-
// broken or just slow on this box — report unknown instead of unavailable so
|
|
116
|
-
// the caller doesn't falsely conclude "CLI not installed" (#P0-2).
|
|
117
|
-
if (result.signal || result.status === null || result.error?.code === 'ETIMEDOUT') {
|
|
118
|
-
return {
|
|
119
|
-
status: 'unknown',
|
|
120
|
-
installed: false,
|
|
121
|
-
ok: false,
|
|
122
|
-
errorCode: 'HCLOUD_UNKNOWN',
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
114
|
return {
|
|
127
115
|
status: 'unavailable',
|
|
128
116
|
installed: false,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Program-owned fields (the node executable + mcp-server.mjs path, required env
|
|
4
4
|
// keys) are corrected by the installer; everything else belongs to the user.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function isPlainObject(value) {
|
|
7
7
|
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TOOL_DEFINITIONS, callTool } from './tools.mjs';
|
|
2
|
-
import { peekCachedUpdateInfo, applyUpdateHint,
|
|
2
|
+
import { peekCachedUpdateInfo, applyUpdateHint, getRuntimeVersion } from './update-check.mjs';
|
|
3
|
+
import { getAutoUpgradeNotice } from './update-auto.mjs';
|
|
3
4
|
import { initTelemetry, flushEvents } from './telemetry/telemetry.mjs';
|
|
4
5
|
import { detectAgent } from './telemetry/agent-detect.mjs';
|
|
5
6
|
|
|
@@ -7,7 +8,7 @@ import { detectAgent } from './telemetry/agent-detect.mjs';
|
|
|
7
8
|
// 防止进程提前退出导致领券遥测丢失。
|
|
8
9
|
const P0_SYNC_FLUSH_TOOLS = new Set(['huaweicloud_voucher_claim', 'huaweicloud_competition_voucher_claim']);
|
|
9
10
|
|
|
10
|
-
const pkgVersion =
|
|
11
|
+
const pkgVersion = getRuntimeVersion();
|
|
11
12
|
|
|
12
13
|
// 会话内首个非 check/upgrade 工具调用附加 _updateInfo,只消费一次。
|
|
13
14
|
// 按会话隔离:同进程内不同会话(A/B)各自首次提示;stdio 用固定 'stdin'。
|
|
@@ -16,8 +17,16 @@ export function _decorateResult(sessionId, name, result) {
|
|
|
16
17
|
if (consumedBySession.get(sessionId)) return result;
|
|
17
18
|
try {
|
|
18
19
|
const hint = peekCachedUpdateInfo();
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const notice =
|
|
21
|
+
name === 'huaweicloud_check_update' || name === 'huaweicloud_upgrade' ? null : getAutoUpgradeNotice();
|
|
22
|
+
if (!hint && !notice) return result;
|
|
23
|
+
let decorated = hint ? applyUpdateHint(result, name, hint) : result;
|
|
24
|
+
if (notice && decorated && typeof decorated === 'object' && !Array.isArray(decorated)) {
|
|
25
|
+
decorated = {
|
|
26
|
+
...decorated,
|
|
27
|
+
_updateInfo: { ...(decorated._updateInfo || {}), autoUpgrade: notice },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
21
30
|
if (decorated !== result) consumedBySession.set(sessionId, true);
|
|
22
31
|
return decorated;
|
|
23
32
|
} catch {
|