huaweicloud-devkit 1.1.14-next.1 → 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.
Files changed (40) hide show
  1. package/README.md +13 -1
  2. package/README.zh-CN.md +13 -1
  3. package/package.json +1 -1
  4. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +3 -16
  5. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +3 -16
  6. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +3 -16
  7. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +3 -16
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +3 -16
  9. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  10. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +0 -6
  11. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +2 -2
  12. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +4 -4
  13. package/plugins/huaweicloud-core/skills/huaweicloud-core/SKILL.md +2 -0
  14. package/plugins/huaweicloud-core/src/account-type.mjs +1 -10
  15. package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +1 -1
  16. package/plugins/huaweicloud-core/src/auth/credentials.mjs +4 -118
  17. package/plugins/huaweicloud-core/src/auth/service.mjs +2 -25
  18. package/plugins/huaweicloud-core/src/auto-upgrade-runner.mjs +58 -0
  19. package/plugins/huaweicloud-core/src/hcloud-cli.mjs +4 -49
  20. package/plugins/huaweicloud-core/src/hcloud-probe.mjs +0 -12
  21. package/plugins/huaweicloud-core/src/mcp-config-merge.mjs +1 -1
  22. package/plugins/huaweicloud-core/src/mcp-protocol.mjs +13 -4
  23. package/plugins/huaweicloud-core/src/mcp-server.mjs +20 -8
  24. package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +1 -1
  25. package/plugins/huaweicloud-core/src/safety-policy.mjs +1 -1
  26. package/plugins/huaweicloud-core/src/sandbox/devbridge-key.mjs +0 -6
  27. package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +55 -58
  28. package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +1 -36
  29. package/plugins/huaweicloud-core/src/sandbox/sandbox-pool.mjs +1 -12
  30. package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +4 -4
  31. package/plugins/huaweicloud-core/src/setup-cli.mjs +9 -91
  32. package/plugins/huaweicloud-core/src/tools.mjs +50 -83
  33. package/plugins/huaweicloud-core/src/update-auto.mjs +669 -0
  34. package/plugins/huaweicloud-core/src/update-check.mjs +141 -10
  35. package/plugins/huaweicloud-core/src/update-policy.mjs +82 -0
  36. package/integrations/opencode/package-lock.json +0 -24
  37. package/integrations/opencode/package.json +0 -10
  38. package/integrations/opencode/plugins/huaweicloud-devkit.js +0 -194
  39. package/plugins/huaweicloud-core/src/auth/token-exchange.mjs +0 -100
  40. package/plugins/huaweicloud-core/src/koocli-install.mjs +0 -57
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
5
5
  [![CI](https://github.com/huaweicloud/huaweicloud-devkit/actions/workflows/ci.yml/badge.svg)](https://github.com/huaweicloud/huaweicloud-devkit/actions/workflows/ci.yml)
6
6
  [![npm version](https://img.shields.io/npm/v/huaweicloud-devkit)](https://www.npmjs.com/package/huaweicloud-devkit)
7
- [![Beta](https://img.shields.io/badge/beta-v1.1.13-orange)](https://github.com/huaweicloud/huaweicloud-devkit)
7
+ [![Beta](https://img.shields.io/badge/beta-v1.1.14-orange)](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](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
5
5
  [![CI](https://github.com/huaweicloud/huaweicloud-devkit/actions/workflows/ci.yml/badge.svg)](https://github.com/huaweicloud/huaweicloud-devkit/actions/workflows/ci.yml)
6
6
  [![npm version](https://img.shields.io/npm/v/huaweicloud-devkit)](https://www.npmjs.com/package/huaweicloud-devkit)
7
- [![Beta](https://img.shields.io/badge/beta-v1.1.13-orange)](https://github.com/huaweicloud/huaweicloud-devkit)
7
+ [![Beta](https://img.shields.io/badge/beta-v1.1.14-orange)](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.1",
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",
@@ -5,10 +5,7 @@
5
5
  "longDescription": "HuaweiCloud DevKit helps coding agents choose and use Huawei Cloud Skills, KooCLI, APIs, SDKs, and MCP tools with less context, safer command execution, and more accurate cloud implementation decisions.",
6
6
  "developerName": "HuaweiCloud Mate",
7
7
  "category": "Cloud",
8
- "capabilities": [
9
- "Read",
10
- "Interactive"
11
- ],
8
+ "capabilities": ["Read", "Interactive"],
12
9
  "websiteURL": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
13
10
  "brandColor": "#C7000B",
14
11
  "defaultPrompt": [
@@ -20,7 +17,7 @@
20
17
  "mcpServers": "./.mcp.json",
21
18
  "description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
22
19
  "skills": "./skills/",
23
- "version": "1.1.14-next.1",
20
+ "version": "1.1.14-next.2",
24
21
  "author": {
25
22
  "name": "HuaweiCloud Mate",
26
23
  "url": "https://github.com/huaweicloud"
@@ -30,15 +27,5 @@
30
27
  "homepage": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
31
28
  "repository": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
32
29
  "license": "Apache-2.0",
33
- "keywords": [
34
- "huaweicloud",
35
- "huawei-cloud",
36
- "koocli",
37
- "hcloud",
38
- "agent",
39
- "mcp",
40
- "api",
41
- "sdk",
42
- "skills"
43
- ]
30
+ "keywords": ["huaweicloud", "huawei-cloud", "koocli", "hcloud", "agent", "mcp", "api", "sdk", "skills"]
44
31
  }
@@ -2,10 +2,7 @@
2
2
  "interface": {
3
3
  "shortDescription": "HuaweiCloud DevKit - Huawei Cloud guidance, CLI/API/SDK routing, MCP tools, and safety for coding agents.",
4
4
  "developerName": "HuaweiCloud Mate",
5
- "capabilities": [
6
- "Read",
7
- "Interactive"
8
- ],
5
+ "capabilities": ["Read", "Interactive"],
9
6
  "brandColor": "#C7000B",
10
7
  "composerIcon": "./assets/icon.png",
11
8
  "logo": "./assets/logo.png",
@@ -23,7 +20,7 @@
23
20
  "mcpServers": "./.mcp.json",
24
21
  "description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
25
22
  "skills": "./skills/",
26
- "version": "1.1.14-next.1",
23
+ "version": "1.1.14-next.2",
27
24
  "author": {
28
25
  "name": "HuaweiCloud Mate",
29
26
  "url": "https://github.com/huaweicloud"
@@ -32,15 +29,5 @@
32
29
  "homepage": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
33
30
  "repository": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
34
31
  "license": "Apache-2.0",
35
- "keywords": [
36
- "huaweicloud",
37
- "huawei-cloud",
38
- "koocli",
39
- "hcloud",
40
- "agent",
41
- "mcp",
42
- "api",
43
- "sdk",
44
- "skills"
45
- ]
32
+ "keywords": ["huaweicloud", "huawei-cloud", "koocli", "hcloud", "agent", "mcp", "api", "sdk", "skills"]
46
33
  }
@@ -5,10 +5,7 @@
5
5
  "longDescription": "HuaweiCloud DevKit helps coding agents choose and use Huawei Cloud Skills, KooCLI, APIs, SDKs, and MCP tools with less context, safer command execution, and more accurate cloud implementation decisions.",
6
6
  "developerName": "HuaweiCloud Mate",
7
7
  "category": "Cloud",
8
- "capabilities": [
9
- "Read",
10
- "Interactive"
11
- ],
8
+ "capabilities": ["Read", "Interactive"],
12
9
  "websiteURL": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
13
10
  "brandColor": "#C7000B",
14
11
  "defaultPrompt": [
@@ -20,7 +17,7 @@
20
17
  "mcpServers": "./.mcp.json",
21
18
  "description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
22
19
  "skills": "./skills/",
23
- "version": "1.1.14-next.1",
20
+ "version": "1.1.14-next.2",
24
21
  "author": {
25
22
  "name": "HuaweiCloud Mate",
26
23
  "url": "https://github.com/huaweicloud"
@@ -30,15 +27,5 @@
30
27
  "homepage": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
31
28
  "repository": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
32
29
  "license": "Apache-2.0",
33
- "keywords": [
34
- "huaweicloud",
35
- "huawei-cloud",
36
- "koocli",
37
- "hcloud",
38
- "agent",
39
- "mcp",
40
- "api",
41
- "sdk",
42
- "skills"
43
- ]
30
+ "keywords": ["huaweicloud", "huawei-cloud", "koocli", "hcloud", "agent", "mcp", "api", "sdk", "skills"]
44
31
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huaweicloud-devkit",
3
- "version": "1.1.14-next.1",
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",
@@ -9,17 +9,7 @@
9
9
  "homepage": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
10
10
  "repository": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
11
11
  "license": "Apache-2.0",
12
- "keywords": [
13
- "huaweicloud",
14
- "huawei-cloud",
15
- "koocli",
16
- "hcloud",
17
- "agent",
18
- "mcp",
19
- "api",
20
- "sdk",
21
- "skills"
22
- ],
12
+ "keywords": ["huaweicloud", "huawei-cloud", "koocli", "hcloud", "agent", "mcp", "api", "sdk", "skills"],
23
13
  "skills": "./skills/",
24
14
  "mcpServers": "./.mcp.json",
25
15
  "interface": {
@@ -28,10 +18,7 @@
28
18
  "longDescription": "HuaweiCloud DevKit helps coding agents choose and use Huawei Cloud Skills, KooCLI, APIs, SDKs, and MCP tools with less context, safer command execution, and more accurate cloud implementation decisions.",
29
19
  "developerName": "HuaweiCloud Mate",
30
20
  "category": "Cloud",
31
- "capabilities": [
32
- "Read",
33
- "Interactive"
34
- ],
21
+ "capabilities": ["Read", "Interactive"],
35
22
  "websiteURL": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
36
23
  "brandColor": "#C7000B",
37
24
  "defaultPrompt": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huaweicloud-devkit",
3
- "version": "1.1.14-next.1",
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",
@@ -9,17 +9,7 @@
9
9
  "homepage": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
10
10
  "repository": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
11
11
  "license": "Apache-2.0",
12
- "keywords": [
13
- "huaweicloud",
14
- "huawei-cloud",
15
- "koocli",
16
- "hcloud",
17
- "agent",
18
- "mcp",
19
- "api",
20
- "sdk",
21
- "skills"
22
- ],
12
+ "keywords": ["huaweicloud", "huawei-cloud", "koocli", "hcloud", "agent", "mcp", "api", "sdk", "skills"],
23
13
  "skills": "./skills/",
24
14
  "mcpServers": "./.mcp.json",
25
15
  "interface": {
@@ -28,10 +18,7 @@
28
18
  "longDescription": "HuaweiCloud DevKit helps coding agents choose and use Huawei Cloud Skills, KooCLI, APIs, SDKs, and MCP tools with less context, safer command execution, and more accurate cloud implementation decisions.",
29
19
  "developerName": "HuaweiCloud Mate",
30
20
  "category": "Cloud",
31
- "capabilities": [
32
- "Read",
33
- "Interactive"
34
- ],
21
+ "capabilities": ["Read", "Interactive"],
35
22
  "websiteURL": "https://github.com/huaweicloud/HuaweiCloud-Devkit",
36
23
  "brandColor": "#C7000B",
37
24
  "defaultPrompt": [
@@ -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.1",
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 参数**——上游参数面仅 template_id/flavor_id):
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
- - 显式 `template_id` 优先于 `pool_type`(自定义模板场景)
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
- - 客户端传 `pool_type`(ephemeral/persistent),**服务端权威映射** template_id;显式 `template_id` 优先(自定义模板)
11
- - **无 persist_mode 请求参数**(需求方两次纠正);闲置语义由平台按模板配置,上游参数面仅 name/template_id/flavor_id/source/env/git
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
- - 钉扎(可选,运维场景):`HW_POOL_TEMPLATE_EPHEMERAL`/`HW_POOL_TEMPLATE_PERSISTENT` 环境变量——设置后客户端附带映射 template_id 上送;日常部署无需配置(模板 ID 由服务端权威维护)
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
- // hcloud ran but stdout was not the expected JSON — usually a credentials
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').replace(/^\uFEFF/, ''));
34
+ return JSON.parse(readFileSync(path, 'utf8'));
35
35
  } catch {
36
36
  return null;
37
37
  }
@@ -12,7 +12,6 @@ import { dirname, join } from 'node:path';
12
12
  import { homedir } from 'node:os';
13
13
 
14
14
  import { buildOnboardingSteps, makeError } from './guidance.mjs';
15
- import { getTokenCredentials } from './token-exchange.mjs';
16
15
 
17
16
  // Verify a credential file ended up with 0600. On Windows-mounted drives inside WSL
18
17
  // (drvfs/9p) chmod is silently ignored, so the file can be world-readable (0777).
@@ -51,18 +50,11 @@ export function obsConfigPath() {
51
50
  return process.env.HCLOUD_OBS_CONFIG_PATH || join(homedir(), '.obsutilconfig');
52
51
  }
53
52
 
54
- // Read a JSON file, stripping a leading UTF-8 BOM (U+FEFF) if present. CodeArts
55
- // writes mcp_settings.json with a BOM on Windows; plain JSON.parse would throw.
56
- export function readJsonFile(path) {
57
- const text = readFileSync(path, 'utf8');
58
- return JSON.parse(text.replace(/^\uFEFF/, ''));
59
- }
60
-
61
53
  export function readGlobalCredentials() {
62
54
  const path = globalCredentialsPath();
63
55
  if (!existsSync(path)) return null;
64
56
  try {
65
- return readJsonFile(path);
57
+ return JSON.parse(readFileSync(path, 'utf8'));
66
58
  } catch {
67
59
  return null;
68
60
  }
@@ -333,7 +325,7 @@ export function readCodeArtsCredentials() {
333
325
  const path = join(dir, '.codeartsdoer', 'mcp', 'mcp_settings.json');
334
326
  try {
335
327
  if (!existsSync(path)) continue;
336
- const config = readJsonFile(path);
328
+ const config = JSON.parse(readFileSync(path, 'utf8'));
337
329
  const server = pickDevkitMcpServer(config?.mcpServers);
338
330
  if (!server?.env) continue;
339
331
 
@@ -363,7 +355,7 @@ export function readCodeArtsCredentials() {
363
355
  for (const path of workPaths) {
364
356
  try {
365
357
  if (!existsSync(path)) continue;
366
- const config = readJsonFile(path);
358
+ const config = JSON.parse(readFileSync(path, 'utf8'));
367
359
  const entry = readWorkEnvironmentEntry(config);
368
360
  if (entry) return entry;
369
361
  } catch {
@@ -401,112 +393,6 @@ export function resolveCredentialsWithRuntime(options = {}) {
401
393
  return resolveCredentials(options);
402
394
  }
403
395
 
404
- // Token warm-up (#token-fullchain): when NO AK/SK is resolvable but an
405
- // X-Auth-Token exists (env / mcp_settings), exchange it for temporary AK/SK
406
- // via IAM securitytokens and cache the result as runtime credentials
407
- // (priority 1). This makes every SYNC consumer downstream (hcloud STS
408
- // injection, devbridge-key getCredentials, OBS signing) work for token-only
409
- // users without any per-callsite async migration. Never throws; failures are
410
- // swallowed so downstream error handling reports the real cause.
411
- export async function warmTokenCredentials() {
412
- try {
413
- const creds = resolveCredentialsWithRuntime({ allowMissing: true });
414
- if (creds && creds.ak && creds.sk) return false; // AK/SK already available — no-op
415
- const token = resolveXAuthToken();
416
- if (!token) return false; // nothing to warm from
417
- const sts = await getTokenCredentials(token);
418
- if (sts && sts.ak && sts.sk) {
419
- setRuntimeCredentials(sts.ak, sts.sk, sts.securityToken || '', sts.region || '');
420
- return true;
421
- }
422
- } catch {
423
- // exchange failure (invalid/expired token, network) — leave state as-is;
424
- // downstream HDKIT_CRED_MISSING / TOKEN_EXCHANGE_FAILED carries the detail.
425
- }
426
- return false;
427
- }
428
-
429
- export function resolveXAuthToken() {
430
- const envToken = process.env.HW_X_AUTH_TOKEN;
431
- if (present(envToken)) return envToken;
432
-
433
- const parentCwd = getParentCwd();
434
- const searchDirs = [process.env.CODEARTS_PROJECT_DIR, parentCwd, process.cwd(), homedir()];
435
- for (const dir of searchDirs) {
436
- if (!dir) continue;
437
- const path = join(dir, '.codeartsdoer', 'mcp', 'mcp_settings.json');
438
- try {
439
- if (!existsSync(path)) continue;
440
- const config = readJsonFile(path);
441
- const server = pickDevkitMcpServer(config?.mcpServers);
442
- const token = server?.env?.HW_X_AUTH_TOKEN;
443
- if (present(token)) return token;
444
- } catch {}
445
- }
446
-
447
- const workPaths = [
448
- join(homedir(), '.codearts', 'mcp', 'mcp_settings.json'),
449
- join(homedir(), '.codeartswork', 'mcp', 'mcp_settings.json'),
450
- ];
451
- for (const path of workPaths) {
452
- try {
453
- if (!existsSync(path)) continue;
454
- const config = readJsonFile(path);
455
- const server = pickDevkitMcpServer(config?.mcp);
456
- const token = server?.environment?.HW_X_AUTH_TOKEN;
457
- if (present(token)) return token;
458
- } catch {}
459
- }
460
- return null;
461
- }
462
-
463
- export function resolveXAuthTokenExpiry() {
464
- const v = process.env.HW_X_AUTH_TOKEN_EXPIRES_AT;
465
- if (v && typeof v === 'string' && v.trim()) {
466
- const asNum = Number(v.trim());
467
- if (Number.isFinite(asNum) && asNum > 0) return asNum > 1e12 ? asNum : asNum * 1000;
468
- const t = Date.parse(v.trim());
469
- if (Number.isFinite(t)) return t;
470
- }
471
-
472
- // Fallback: 未注入 HW_X_AUTH_TOKEN_EXPIRES_AT 时,从 token 字符串自解析过期时间。
473
- // X-Auth-Token 是 CMS/PKCS#7 SignedData(base64 DER),其 eContent 内嵌明文 JSON
474
- // (含 token.expires_at);base64 解码 + 提取 {"token" JSON 即可读出,无需依赖注入方显式给过期时间。
475
- const token = resolveXAuthToken();
476
- if (!token) return null;
477
- return parseXAuthTokenExpiry(token);
478
- }
479
-
480
- function parseXAuthTokenExpiry(token) {
481
- try {
482
- const pad = token + '='.repeat((4 - (token.length % 4)) % 4);
483
- const text = Buffer.from(pad.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8');
484
- const idx = text.indexOf('{"token"');
485
- if (idx < 0) return null;
486
- const tail = text.slice(idx);
487
- let depth = 0;
488
- let end = -1;
489
- for (let i = 0; i < tail.length; i += 1) {
490
- if (tail[i] === '{') depth += 1;
491
- else if (tail[i] === '}') {
492
- depth -= 1;
493
- if (depth === 0) {
494
- end = i + 1;
495
- break;
496
- }
497
- }
498
- }
499
- if (end < 0) return null;
500
- const obj = JSON.parse(tail.slice(0, end));
501
- const expiresAt = obj?.token?.expires_at;
502
- if (!expiresAt || typeof expiresAt !== 'string') return null;
503
- const t = Date.parse(expiresAt);
504
- return Number.isFinite(t) ? t : null;
505
- } catch {
506
- return null;
507
- }
508
- }
509
-
510
396
  export function lastSyncPath() {
511
397
  return join(baseHome(), '.config', 'huaweicloud', '.last_sync');
512
398
  }
@@ -515,7 +401,7 @@ export function readLastSync() {
515
401
  const path = lastSyncPath();
516
402
  if (!existsSync(path)) return null;
517
403
  try {
518
- return readJsonFile(path);
404
+ return JSON.parse(readFileSync(path, 'utf8'));
519
405
  } catch {
520
406
  return null;
521
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
- token: tokenAuth ? { active: true } : { active: false },
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
- // usableCredentials: any credential source that makes the MCP/backend path
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
+ }