huaweicloud-devkit 1.1.10-next.4 → 1.1.11

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 (34) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/package.json +1 -1
  4. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
  5. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
  6. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
  7. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  9. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  10. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +1 -7
  11. package/plugins/huaweicloud-core/skills/huawei-ecs/references/troubleshooting.md +18 -17
  12. package/plugins/huaweicloud-core/skills/huawei-obs/SKILL.md +17 -16
  13. package/plugins/huaweicloud-core/skills/huawei-obs/references/common-pitfalls.md +168 -1
  14. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +75 -13
  15. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/fullstack-postgrest.md +149 -0
  16. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/tunnel-persistence.md +121 -0
  17. package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +13 -9
  18. package/plugins/huaweicloud-core/src/account-type.mjs +1 -10
  19. package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +1 -1
  20. package/plugins/huaweicloud-core/src/auth/credentials.mjs +4 -92
  21. package/plugins/huaweicloud-core/src/auth/service.mjs +2 -24
  22. package/plugins/huaweicloud-core/src/hcloud-cli.mjs +4 -43
  23. package/plugins/huaweicloud-core/src/mcp-config-merge.mjs +1 -1
  24. package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +1 -1
  25. package/plugins/huaweicloud-core/src/safety-policy.mjs +7 -3
  26. package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +6 -28
  27. package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +75 -12
  28. package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +396 -9
  29. package/plugins/huaweicloud-core/src/setup-cli.mjs +9 -91
  30. package/plugins/huaweicloud-core/src/tools.mjs +260 -5
  31. package/integrations/opencode/package-lock.json +0 -24
  32. package/integrations/opencode/package.json +0 -10
  33. package/integrations/opencode/plugins/huaweicloud-devkit.js +0 -194
  34. package/plugins/huaweicloud-core/src/auth/token-exchange.mjs +0 -100
@@ -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, '..', '..');
@@ -245,9 +243,6 @@ function officeaceSqlitePath() {
245
243
  }
246
244
 
247
245
  function openOfficeaceDb() {
248
- // Lazy-require node:sqlite (experimental on Node 22.x) so CLI commands that
249
- // don't touch OfficeAce (version/doctor/install) run without the flag.
250
- const { DatabaseSync } = createRequire(import.meta.url)('node:sqlite');
251
246
  return new DatabaseSync(officeaceSqlitePath());
252
247
  }
253
248
 
@@ -708,7 +703,7 @@ function resolveOpenCodeEra() {
708
703
  return (resolvedOpenCodeEra = 'v2');
709
704
  }
710
705
 
711
- function updateOpenCodeConfig(pluginDir, { nativePluginInstalled = false } = {}) {
706
+ function updateOpenCodeConfig(pluginDir) {
712
707
  const configPath = opencodeConfigFile();
713
708
  const mcpPath = join(pluginDir, 'src', 'mcp-server.mjs').replace(/\\/g, '/');
714
709
  const era = resolveOpenCodeEra();
@@ -727,25 +722,6 @@ function updateOpenCodeConfig(pluginDir, { nativePluginInstalled = false } = {})
727
722
 
728
723
  const { config: next, existing, changed } = mergeOpenCodeEntry(config, { mcpPath, era });
729
724
 
730
- // Native-plugin mode: the in-process plugin already bridges all 42 tools with
731
- // the shared callTool layer (names, approval gate, telemetry unchanged). Keep
732
- // the MCP entry for manual fallback but leave it disabled so OpenCode does
733
- // not register 42 duplicate `huaweicloud-devkit_*` copies (#940 follow-up).
734
- let mcpDisabled = false;
735
- if (nativePluginInstalled) {
736
- const key = 'huaweicloud-devkit';
737
- if (era === 'v2') {
738
- const servers = isPlainObject(next.mcp?.servers) ? next.mcp.servers : null;
739
- if (servers && servers[key] && servers[key].disabled !== true) {
740
- servers[key] = { ...servers[key], disabled: true };
741
- mcpDisabled = true;
742
- }
743
- } else if (next.mcp?.[key] && next.mcp[key].enabled !== false) {
744
- next.mcp[key] = { ...next.mcp[key], enabled: false };
745
- mcpDisabled = true;
746
- }
747
- }
748
-
749
725
  // Restore user fields saved by a previous uninstall (issue #615), on fresh install only.
750
726
  if (!existing) {
751
727
  const delta = takeAgentDelta('opencode');
@@ -758,15 +734,12 @@ function updateOpenCodeConfig(pluginDir, { nativePluginInstalled = false } = {})
758
734
  }
759
735
  }
760
736
 
761
- if (existing && !changed && !mcpDisabled) {
737
+ if (existing && !changed) {
762
738
  console.log(` OpenCode MCP config unchanged: ${configPath}`);
763
739
  return;
764
740
  }
765
741
 
766
742
  writeMcpSettingsFile(configPath, next);
767
- if (mcpDisabled) {
768
- console.log(` OpenCode MCP entry disabled (native plugin active — no duplicate tools) -> ${configPath}`);
769
- }
770
743
  console.log(
771
744
  existing
772
745
  ? ` OpenCode MCP config merged (user fields preserved, ${era}): ${configPath}`
@@ -988,24 +961,7 @@ async function installOpenCode() {
988
961
  mkdirSync(opcPlugins, { recursive: true });
989
962
  copyFileSync(pluginSrc, join(opcPlugins, 'skill-tracker.js'));
990
963
  console.log(` Plugin -> ${opcPlugins}`);
991
- // OpenCode native plugin (#905 OpenCode performance): bridges all 42 MCP tools
992
- // into OpenCode in-process custom tools (zod schemas + callTool), plus safety
993
- // gate and telemetry. Local plugins are auto-loaded from this directory.
994
- const nativePluginSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'plugins', 'huaweicloud-devkit.js');
995
- let nativePluginInstalled = false;
996
- if (existsSync(nativePluginSrc)) {
997
- copyFileSync(nativePluginSrc, join(opcPlugins, 'huaweicloud-devkit.js'));
998
- // Deps for the native plugin (zod) live next to the OpenCode config so the
999
- // plugin can require them at load time.
1000
- const nativePkgSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'package.json');
1001
- const nativePkgDst = join(configRoot('opencode'), 'package.json');
1002
- if (existsSync(nativePkgSrc) && !existsSync(nativePkgDst)) {
1003
- copyFileSync(nativePkgSrc, nativePkgDst);
1004
- }
1005
- nativePluginInstalled = true;
1006
- console.log(` Native plugin -> ${join(opcPlugins, 'huaweicloud-devkit.js')}`);
1007
- }
1008
- updateOpenCodeConfig(pluginDest, { nativePluginInstalled });
964
+ updateOpenCodeConfig(pluginDest);
1009
965
  installRuntimeDeps(pluginDest);
1010
966
  }
1011
967
 
@@ -1038,11 +994,6 @@ function uninstallOpenCode() {
1038
994
  removeIfExists(pluginFile);
1039
995
  console.log(' Removed plugin');
1040
996
  }
1041
- const nativePluginFile = join(configRoot('opencode'), 'plugins', 'huaweicloud-devkit.js');
1042
- if (existsSync(nativePluginFile)) {
1043
- removeIfExists(nativePluginFile);
1044
- console.log(' Removed native plugin');
1045
- }
1046
997
 
1047
998
  if (removeIfExists(opencodePluginsDir())) {
1048
999
  console.log(' Removed MCP server and safety policy');
@@ -1090,20 +1041,7 @@ async function updateOpenCode() {
1090
1041
  mkdirSync(opcPlugins, { recursive: true });
1091
1042
  copyFileSync(pluginSrc, join(opcPlugins, 'skill-tracker.js'));
1092
1043
  console.log(` Plugin updated -> ${opcPlugins}`);
1093
- // Native plugin refresh (#905 OpenCode performance) — overwrite in place.
1094
- const nativePluginSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'plugins', 'huaweicloud-devkit.js');
1095
- let nativePluginInstalled = false;
1096
- if (existsSync(nativePluginSrc)) {
1097
- copyFileSync(nativePluginSrc, join(opcPlugins, 'huaweicloud-devkit.js'));
1098
- const nativePkgSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'package.json');
1099
- const nativePkgDst = join(configRoot('opencode'), 'package.json');
1100
- if (existsSync(nativePkgSrc) && !existsSync(nativePkgDst)) {
1101
- copyFileSync(nativePkgSrc, nativePkgDst);
1102
- }
1103
- nativePluginInstalled = true;
1104
- console.log(` Native plugin updated -> ${join(opcPlugins, 'huaweicloud-devkit.js')}`);
1105
- }
1106
- updateOpenCodeConfig(pluginDest, { nativePluginInstalled });
1044
+ updateOpenCodeConfig(pluginDest);
1107
1045
  mkdirSync(pluginDest, { recursive: true });
1108
1046
  writeFileSync(join(pluginDest, '.installed'), new Date().toISOString());
1109
1047
  installRuntimeDeps(pluginDest);
@@ -1588,7 +1526,7 @@ function codeartsStatus() {
1588
1526
  );
1589
1527
  if (existsSync(codeartsMcpSettingsFile())) {
1590
1528
  try {
1591
- const config = readJsonFile(codeartsMcpSettingsFile());
1529
+ const config = JSON.parse(readFileSync(codeartsMcpSettingsFile(), 'utf8'));
1592
1530
  console.log(
1593
1531
  ` MCP config: ${config.mcpServers?.['huaweicloud-devkit'] ? '\x1b[32mConfigured\x1b[0m' : '\x1b[31mNot configured\x1b[0m'}`,
1594
1532
  );
@@ -1749,7 +1687,7 @@ function codeartsWorkStatus() {
1749
1687
  );
1750
1688
  if (existsSync(codeartsWorkMcpSettingsFile())) {
1751
1689
  try {
1752
- const config = readJsonFile(codeartsWorkMcpSettingsFile());
1690
+ const config = JSON.parse(readFileSync(codeartsWorkMcpSettingsFile(), 'utf8'));
1753
1691
  console.log(
1754
1692
  ` MCP config: ${config.mcp?.['huaweicloud-devkit'] ? '\x1b[32mConfigured\x1b[0m' : '\x1b[31mNot configured\x1b[0m'}`,
1755
1693
  );
@@ -4314,27 +4252,7 @@ async function cmdDoctor() {
4314
4252
  timeout: 5000,
4315
4253
  });
4316
4254
  const hasAuth = authCheck.status === 0 && /access.?key/i.test(authCheck.stdout.toString());
4317
- if (hasAuth) {
4318
- check('hcloud credentials configured', true, '');
4319
- } else {
4320
- // In CodeArts, platform-injected STS / X-Auth-Token reach only the MCP
4321
- // server process, not this bash tool process — so `hcloud configure list`
4322
- // shows no profile even though the backend API path is usable. Degrade to
4323
- // a warning instead of a hard fail in that case (#P3 of CodeArts test).
4324
- let platformCredsActive = false;
4325
- try {
4326
- const c = resolveCredentialsWithRuntime({ allowMissing: true });
4327
- platformCredsActive = Boolean((c && c.ak && c.sk && c.securityToken) || resolveXAuthToken());
4328
- } catch {}
4329
- if (platformCredsActive) {
4330
- console.log(
4331
- ` \x1b[33m[WARN]\x1b[0m hcloud credentials configured — KooCLI 无 profile,但检测到平台凭证(MCP 通道可用);仅 KooCLI 直接调用需 auth init`,
4332
- );
4333
- warn++;
4334
- } else {
4335
- check('hcloud credentials configured', false, 'Run: npx huaweicloud-devkit auth init');
4336
- }
4337
- }
4255
+ check('hcloud credentials configured', hasAuth, 'Run: npx huaweicloud-devkit auth init');
4338
4256
  }
4339
4257
 
4340
4258
  // Skills
@@ -22,6 +22,8 @@ import {
22
22
  deployNginx,
23
23
  deployCheck,
24
24
  exposeTunnel,
25
+ renewTunnel,
26
+ installKeepaliveWatchdog,
25
27
  getCurrentWorkspaceId,
26
28
  setWorkspaceId,
27
29
  } from './sandbox/session-manager.mjs';
@@ -764,7 +766,7 @@ export const TOOL_DEFINITIONS = [
764
766
  {
765
767
  name: 'huaweicloud_sandbox_expose_tunnel',
766
768
  description:
767
- 'Expose a port on the sandbox to a public DevBridge tunnel URL (devbridge 0.2.x). Authenticates automatically (probing AK/SK vs API-Key builds, using /tmp/hw_creds.sh and /tmp/hw_api_key as injected by huaweicloud_sandbox_credentials), pre-cleans stale tunnels to avoid quota errors, starts the host, extracts the public URL (https://<id>-<port>.devbridge-s2.hwtunnel.com), and health-checks it before returning. Use the ACTUAL port reported by huaweicloud_sandbox_deploy_nginx (its "port" field auto-increments on conflict) — never the originally requested port. This automates the manual "Expose via DevBridge" 5-step flow. Returns ok, publicUrl, port, tunnelId, and warnings. If the API Key is missing on a release build it returns ok:false with instructions to create one.',
769
+ 'Expose a port on the sandbox to a public DevBridge tunnel URL (devbridge 0.2.x). Authenticates automatically (probing AK/SK vs API-Key builds, using /tmp/hw_creds.sh and /tmp/hw_api_key as injected by huaweicloud_sandbox_credentials), pre-cleans stale tunnels to avoid quota errors, starts the host, extracts the public URL (https://<id>-<port>.devbridge-s2.hwtunnel.com), and health-checks it before returning. AUTO-ENROLLS the tunnel into the keepalive watchdog (host re-attach + daily 720h renewal + health check) by default, merged into existing coverage — pass keepalive:false to opt out. Use the ACTUAL port reported by huaweicloud_sandbox_deploy_nginx (its "port" field auto-increments on conflict) — never the originally requested port. Returns ok, publicUrl, port, tunnelId, keepalive.enrolled, and warnings. If the API Key is missing on a release build it returns ok:false with instructions to create one.',
768
770
  inputSchema: {
769
771
  type: 'object',
770
772
  required: ['port'],
@@ -774,6 +776,16 @@ export const TOOL_DEFINITIONS = [
774
776
  description:
775
777
  'Actual port nginx is listening on — use the "port" value returned by huaweicloud_sandbox_deploy_nginx, not the originally requested port.',
776
778
  },
779
+ expiry_hours: {
780
+ type: 'number',
781
+ description:
782
+ 'Tunnel lifetime in hours via devbridge -e (1-720; 720 = the 30-day maximum, default 72). The expiry is a rolling window — the keepalive watchdog renews daily to keep the URL alive indefinitely.',
783
+ },
784
+ keepalive: {
785
+ type: 'boolean',
786
+ description:
787
+ 'Auto-enroll the tunnel into the keepalive watchdog (default true — every tunnel deployed to the sandbox must be keepalive-protected). Pass false only when the caller explicitly manages keepalive itself.',
788
+ },
777
789
  workspace_id: {
778
790
  type: 'string',
779
791
  description:
@@ -784,6 +796,65 @@ export const TOOL_DEFINITIONS = [
784
796
  },
785
797
  },
786
798
  },
799
+ {
800
+ name: 'huaweicloud_sandbox_renew_tunnel',
801
+ description:
802
+ 'Renew a DevBridge tunnel lifetime via devbridge update <tunnelId> -e <hours> (1-720; 720 = the 30-day maximum). The expiry is a rolling window: renewal sets expiration = now + hours regardless of remaining time, so renewing before expiry keeps the SAME tunnel URL alive indefinitely. A renewal counts as ok only when the update succeeds AND show -v reports the absolute tunnelExpiration — the management plane can lose a tunnel record (10002 "tunnel not found") while the data plane keeps serving. Returns ok, tunnelId, expiresAt (ISO), renewedForHours. Pair with huaweicloud_sandbox_keepalive_watchdog for unattended daily renewal.',
803
+ inputSchema: {
804
+ type: 'object',
805
+ required: ['tunnel_id'],
806
+ properties: {
807
+ tunnel_id: {
808
+ type: 'string',
809
+ description:
810
+ 'Short tunnel ID from huaweicloud_sandbox_expose_tunnel (e.g. nv2dvv6w) — extractable from the public URL as https://<tunnel_id>-<port>.devbridge-s2.hwtunnel.com.',
811
+ },
812
+ expiry_hours: {
813
+ type: 'number',
814
+ description:
815
+ 'Renewal horizon in hours (1-720, default 720). The expiration becomes now + expiry_hours (rolling window).',
816
+ },
817
+ workspace_id: {
818
+ type: 'string',
819
+ description:
820
+ 'Workspace ID from huaweicloud_sandbox_connect return value. Required - must be passed explicitly when HW_WORKSPACE_ID is not set.',
821
+ },
822
+ username: { type: 'string', description: 'Login username (default: root)' },
823
+ timeout_ms: { type: 'number', description: 'Execution timeout in milliseconds (default: 60000)' },
824
+ },
825
+ },
826
+ },
827
+ {
828
+ name: 'huaweicloud_sandbox_keepalive_watchdog',
829
+ description:
830
+ 'Install a keepalive watchdog in the sandbox that keeps DevBridge tunnel URLs alive indefinitely (three-layer pattern, proven in the 2026-10 tunnel-persistence test): (1) re-attaches the host with devbridge host <tunnelId> if the process dies — the URL is bound to the tunnel ID so it never changes; (2) renews every tunnel daily with devbridge update <tunnelId> -e 720 (29-day failure tolerance); (3) health-checks each URL every 5 minutes, logging warnings to /tmp/tunnel-keepalive.log. Installs as a setsid-detached loop at /tmp/tunnel-keepalive.sh; re-running replaces the old loop. URLs are hardcoded per tunnel because devbridge port list output is wrapped in OSC escapes that break anchored greps. Call AFTER huaweicloud_sandbox_expose_tunnel; requires DevBridge credentials (auth) in the sandbox.',
831
+ inputSchema: {
832
+ type: 'object',
833
+ required: ['tunnels'],
834
+ properties: {
835
+ tunnels: {
836
+ type: 'array',
837
+ description:
838
+ 'Tunnels to watch. Get tunnelId + url from huaweicloud_sandbox_expose_tunnel (publicUrl contains the tunnelId as https://<tunnel_id>-<port>.devbridge-s2.hwtunnel.com).',
839
+ items: {
840
+ type: 'object',
841
+ required: ['tunnel_id', 'url'],
842
+ properties: {
843
+ tunnel_id: { type: 'string', description: 'Short tunnel ID (e.g. kag7rozs).' },
844
+ url: { type: 'string', description: 'Full public https URL of the tunnel (used for the health check).' },
845
+ },
846
+ },
847
+ },
848
+ workspace_id: {
849
+ type: 'string',
850
+ description:
851
+ 'Workspace ID from huaweicloud_sandbox_connect return value. Required - must be passed explicitly when HW_WORKSPACE_ID is not set.',
852
+ },
853
+ username: { type: 'string', description: 'Login username (default: root)' },
854
+ timeout_ms: { type: 'number', description: 'Execution timeout in milliseconds (default: 60000)' },
855
+ },
856
+ },
857
+ },
787
858
  {
788
859
  name: 'huaweicloud_sandbox_check_user',
789
860
  description:
@@ -951,6 +1022,47 @@ export const TOOL_DEFINITIONS = [
951
1022
  required: ['action', 'bucket', 'region'],
952
1023
  },
953
1024
  },
1025
+ {
1026
+ name: 'huaweicloud_obs_set_cors',
1027
+ description:
1028
+ '配置 OBS 桶的 CORS 规则(浏览器直传前置条件)。KooCLI OBS 不支持 cors 子命令,此工具内部实现 AWS4 签名调用 OBS REST API(PUT/GET/DELETE /?cors),屏蔽签名细节。支持 set(配置)、get(查询)、delete(删除)三种操作。allowedMethod 必须含 HEAD(BrowserJS SDK 每次操作前发 HEAD ?apiversion 探测,缺 HEAD 时浏览器吞掉探测请求)。配置成功后用返回体中的 verify 命令做 OPTIONS 预检验证(200 + Access-Control-Allow-Origin 才算成功)。',
1029
+ inputSchema: {
1030
+ type: 'object',
1031
+ properties: {
1032
+ action: {
1033
+ type: 'string',
1034
+ enum: ['set', 'get', 'delete'],
1035
+ description: '操作类型:set=配置 CORS 规则,get=查询当前规则,delete=删除规则',
1036
+ },
1037
+ bucket: { type: 'string', description: 'OBS 桶名称' },
1038
+ region: { type: 'string', description: 'OBS 桶所在区域,如 cn-north-4' },
1039
+ rules: {
1040
+ type: 'array',
1041
+ description:
1042
+ 'CORS 规则数组(action=set 时必填)。每条规则:allowedOrigin(如 https://your-app)、allowedMethod 数组(GET/PUT/POST/DELETE/HEAD,必须含 HEAD)、allowedHeader 数组(默认 ["*"])、maxAgeSeconds(默认 3000)',
1043
+ items: {
1044
+ type: 'object',
1045
+ properties: {
1046
+ allowedOrigin: { type: 'string', description: '允许的来源,如 https://your-app.example.com 或 *' },
1047
+ allowedMethod: {
1048
+ type: 'array',
1049
+ items: { type: 'string' },
1050
+ description: '允许的 HTTP 方法,必须包含 HEAD',
1051
+ },
1052
+ allowedHeader: {
1053
+ type: 'array',
1054
+ items: { type: 'string' },
1055
+ description: '允许的请求头,默认 ["*"]',
1056
+ },
1057
+ maxAgeSeconds: { type: 'number', description: '预检结果缓存秒数,默认 3000' },
1058
+ },
1059
+ required: ['allowedOrigin', 'allowedMethod'],
1060
+ },
1061
+ },
1062
+ },
1063
+ required: ['action', 'bucket', 'region'],
1064
+ },
1065
+ },
954
1066
  ];
955
1067
 
956
1068
  function toolInvokeValue(name, args) {
@@ -1512,7 +1624,53 @@ export async function callTool(name, rawArgs = {}, opts = {}) {
1512
1624
  }
1513
1625
  const sandboxUser9 = args.username || 'root';
1514
1626
  const sandboxTimeout9 = args.timeout_ms || 90000;
1515
- return await exposeTunnel(sandboxWsId9, { port: args.port }, sandboxUser9, sandboxTimeout9);
1627
+ return await exposeTunnel(
1628
+ sandboxWsId9,
1629
+ { port: args.port, expiryHours: args.expiry_hours, keepalive: args.keepalive },
1630
+ sandboxUser9,
1631
+ sandboxTimeout9,
1632
+ );
1633
+ }
1634
+ case 'huaweicloud_sandbox_renew_tunnel': {
1635
+ if (!args.tunnel_id) {
1636
+ throw new Error(
1637
+ 'tunnel_id is required. Get it from huaweicloud_sandbox_expose_tunnel or extract it from the public URL (https://<tunnel_id>-<port>.devbridge-s2.hwtunnel.com).',
1638
+ );
1639
+ }
1640
+ const sandboxWsId10 = args.workspace_id || getCurrentWorkspaceId();
1641
+ if (!sandboxWsId10) {
1642
+ throw new Error(
1643
+ 'workspace_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, ' +
1644
+ 'or set HW_WORKSPACE_ID environment variable before starting the agent.',
1645
+ );
1646
+ }
1647
+ return await renewTunnel(
1648
+ sandboxWsId10,
1649
+ { tunnelId: args.tunnel_id, expiryHours: args.expiry_hours },
1650
+ args.username || 'root',
1651
+ args.timeout_ms || 60000,
1652
+ );
1653
+ }
1654
+ case 'huaweicloud_sandbox_keepalive_watchdog': {
1655
+ if (!Array.isArray(args.tunnels) || args.tunnels.length === 0) {
1656
+ throw new Error(
1657
+ 'tunnels is required — a non-empty array of {tunnel_id, url} from huaweicloud_sandbox_expose_tunnel results.',
1658
+ );
1659
+ }
1660
+ const sandboxWsId11 = args.workspace_id || getCurrentWorkspaceId();
1661
+ if (!sandboxWsId11) {
1662
+ throw new Error(
1663
+ 'workspace_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, ' +
1664
+ 'or set HW_WORKSPACE_ID environment variable before starting the agent.',
1665
+ );
1666
+ }
1667
+ const tunnels11 = args.tunnels.map((t) => ({ tunnelId: t.tunnel_id || t.tunnelId, url: t.url }));
1668
+ return await installKeepaliveWatchdog(
1669
+ sandboxWsId11,
1670
+ { tunnels: tunnels11 },
1671
+ args.username || 'root',
1672
+ args.timeout_ms || 60000,
1673
+ );
1516
1674
  }
1517
1675
  case 'huaweicloud_sandbox_check_user':
1518
1676
  return await hdkitCheckUser();
@@ -1527,7 +1685,12 @@ export async function callTool(name, rawArgs = {}, opts = {}) {
1527
1685
  await execOneShot(devStageId, 'devbridge delete-all 2>/dev/null || true', 'root', 15000);
1528
1686
  } catch {}
1529
1687
  try {
1530
- await execWithSession(devStageId, 'export PATH=$HOME/.huawei/bin${PATH:+:$PATH}', 'root', 10000);
1688
+ await execWithSession(
1689
+ devStageId,
1690
+ 'export PATH=/workspace/.local/bin:$HOME/.huawei/bin${PATH:+:$PATH}',
1691
+ 'root',
1692
+ 10000,
1693
+ );
1531
1694
  } catch {}
1532
1695
  await transferGitRepo(args, devStageId, connectResult);
1533
1696
  }
@@ -1632,6 +1795,8 @@ export async function callTool(name, rawArgs = {}, opts = {}) {
1632
1795
  return await handleUpgrade(args, { sessionId: opts?.sessionId });
1633
1796
  case 'huaweicloud_obs_set_website_config':
1634
1797
  return await handleObsWebsiteConfig(args);
1798
+ case 'huaweicloud_obs_set_cors':
1799
+ return await handleObsCorsConfig(args);
1635
1800
  default:
1636
1801
  throw new Error(`Unknown tool: ${name}`);
1637
1802
  }
@@ -2351,6 +2516,8 @@ function explainError({ service = 'unknown', errorCode = '', message = '', reque
2351
2516
  'The flavor has been taken offline (Ecs.0019). Run `hcloud ECS ListFlavors --cli-region=<region>` to query currently on-sale flavors and switch to a replacement flavor (see the huawei-ecs skill references/flavors.md for the cond:operation:status field rules — a flavor marked 卖光/下线 keeps failing until you pick an on-sale one), then recreate.',
2352
2517
  'Ecs.0319':
2353
2518
  'The requested flavor has insufficient capacity in the selected availability zone (Ecs.0319). Fix: retry in a different availability zone, or switch to a replacement flavor (list on-sale flavors with `hcloud ECS ListFlavors --cli-region=<region>`), then recreate.',
2519
+ 'Ecs.0044':
2520
+ 'The requested volume type is sold out in the selected availability zone (Ecs.0044, e.g. "the volumeType [SATA] is sellout in az[cn-north-4a]"). This is the ROOT VOLUME/DISK type being unavailable — a different failure from Ecs.0319 (flavor capacity). Fix: switch `--server.root_volume.volumetype` to an available type (SAS/SSD/GPSSD — query availability first) or retry in a different availability zone (`hcloud ECS NovaListAvailabilityZones --cli-region=<region>`). ListFlavors does NOT pre-warn about volume-type sellouts — you only find out at order time.',
2354
2521
  'Ecs.0067':
2355
2522
  'Order submission rejected for balance reasons (Ecs.0067). Check the cash balance with `hcloud BSS ShowCustomerAccountBalances --cli-region=cn-north-1` and top up if needed — pay-per-use order risk control checks the CASH balance only (代金券/vouchers do NOT participate in order risk control; they only offset the bill at settlement). Also settle any historical arrears, however small, before retrying.',
2356
2523
  },
@@ -2766,7 +2933,95 @@ async function handleObsWebsiteConfig(args) {
2766
2933
  throw new Error(`Unknown action: ${action}. Use set, get, or delete.`);
2767
2934
  }
2768
2935
 
2769
- async function obsSignedRequest(method, endpoint, pathAndQuery, body, creds, region) {
2936
+ // #1003: same-structure extension of handleObsWebsiteConfig — KooCLI OBS does
2937
+ // not expose a cors subcommand and there is no SetBucketCors MCP path, so
2938
+ // agents fell back to installing a Python SDK in the sandbox just to configure
2939
+ // CORS. This reuses obsSignedRequest (AWS4, s3 service) against /?cors.
2940
+ async function handleObsCorsConfig(args = {}) {
2941
+ const { action, bucket, region, rules } = args;
2942
+ if (!bucket || !region) {
2943
+ throw new Error('bucket and region are required');
2944
+ }
2945
+ const creds = resolveCredentialsWithRuntime({});
2946
+ if (!creds?.ak || !creds?.sk) {
2947
+ throw new Error('OBS CORS config requires AK/SK credentials. Run huaweicloud_auth_init first.');
2948
+ }
2949
+
2950
+ const host = `${bucket}.obs.${region}.myhuaweicloud.com`;
2951
+ const endpoint = `https://${host}`;
2952
+ const preflightHint =
2953
+ 'Verify with an OPTIONS preflight before declaring success: ' +
2954
+ `curl -i -X OPTIONS --noproxy '*' 'https://${host}/<object-key>' -H 'Origin: <your-app-origin>' -H 'Access-Control-Request-Method: HEAD' ` +
2955
+ 'must return HTTP 200 with an Access-Control-Allow-Origin header (200 without CORS headers = config not effective; ' +
2956
+ '403 = rule missing the requested method). See the huawei-obs skill common-pitfalls.md p05.';
2957
+
2958
+ if (action === 'get') {
2959
+ const res = await obsSignedRequest('GET', endpoint, '/?cors', '', creds, region, 'cors');
2960
+ return { ok: res.status === 200, status: res.status, rules: res.body, verify: preflightHint };
2961
+ }
2962
+
2963
+ if (action === 'delete') {
2964
+ const res = await obsSignedRequest('DELETE', endpoint, '/?cors', '', creds, region, 'cors');
2965
+ return { ok: res.status === 204, status: res.status };
2966
+ }
2967
+
2968
+ if (action === 'set') {
2969
+ if (!Array.isArray(rules) || rules.length === 0) {
2970
+ throw new Error('rules array is required for action=set (allowedOrigin + allowedMethod, HEAD included)');
2971
+ }
2972
+ for (const rule of rules) {
2973
+ if (!rule?.allowedOrigin || !Array.isArray(rule?.allowedMethod) || rule.allowedMethod.length === 0) {
2974
+ throw new Error('each CORS rule needs allowedOrigin and a non-empty allowedMethod array');
2975
+ }
2976
+ if (!rule.allowedMethod.includes('HEAD')) {
2977
+ // p01: the BrowserJS SDK's HEAD ?apiversion probe gets swallowed by the
2978
+ // browser when HEAD is missing — the exact failure this tool exists to
2979
+ // prevent, so reject it at the input boundary instead of at runtime.
2980
+ throw new Error(
2981
+ "allowedMethod must include 'HEAD' — the BrowserJS SDK sends a HEAD ?apiversion probe before every " +
2982
+ 'operation, and a CORS rule without HEAD makes the browser swallow it as Network Error (p01).',
2983
+ );
2984
+ }
2985
+ }
2986
+ const escapeXml = (s) =>
2987
+ String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
2988
+ const xmlParts = ['<CORSConfiguration>'];
2989
+ for (const rule of rules) {
2990
+ xmlParts.push(' <CORSRule>');
2991
+ xmlParts.push(` <AllowedOrigin>${escapeXml(rule.allowedOrigin)}</AllowedOrigin>`);
2992
+ for (const method of rule.allowedMethod) {
2993
+ xmlParts.push(` <AllowedMethod>${escapeXml(method)}</AllowedMethod>`);
2994
+ }
2995
+ for (const header of rule.allowedHeader || ['*']) {
2996
+ xmlParts.push(` <AllowedHeader>${escapeXml(header)}</AllowedHeader>`);
2997
+ }
2998
+ if (rule.maxAgeSeconds != null) {
2999
+ xmlParts.push(` <MaxAgeSeconds>${Number(rule.maxAgeSeconds)}</MaxAgeSeconds>`);
3000
+ }
3001
+ xmlParts.push(' </CORSRule>');
3002
+ }
3003
+ xmlParts.push('</CORSConfiguration>');
3004
+ const body = xmlParts.join('\n');
3005
+ const res = await obsSignedRequest('PUT', endpoint, '/?cors', body, creds, region, 'cors');
3006
+ return {
3007
+ ok: res.status === 200,
3008
+ status: res.status,
3009
+ message:
3010
+ res.status === 200
3011
+ ? `CORS configured for ${bucket} (${rules.length} rule(s)).`
3012
+ : `Failed to configure CORS: HTTP ${res.status}`,
3013
+ verify: preflightHint,
3014
+ };
3015
+ }
3016
+
3017
+ throw new Error(`Unknown action: ${action}. Use set, get, or delete.`);
3018
+ }
3019
+
3020
+ // Single AWS4-signed OBS REST API caller shared by the website/CORS tools
3021
+ // (#1003): subresource is the bucket subresource being addressed — 'website'
3022
+ // for PUT/GET/DELETE /?website, 'cors' for /?cors. Credential scope uses the
3023
+ // s3 service name (OBS is S3-compatible).
3024
+ async function obsSignedRequest(method, endpoint, pathAndQuery, body, creds, region, subresource = 'website') {
2770
3025
  const now = new Date();
2771
3026
  const dateStamp = now.toISOString().slice(0, 10).replace(/-/g, '');
2772
3027
  const amzDate = dateStamp + 'T' + now.toISOString().slice(11, 19).replace(/:/g, '') + 'Z';
@@ -2774,7 +3029,7 @@ async function obsSignedRequest(method, endpoint, pathAndQuery, body, creds, reg
2774
3029
 
2775
3030
  const url = new URL(endpoint + pathAndQuery);
2776
3031
  const canonicalUri = '/';
2777
- const canonicalQueryString = 'website=';
3032
+ const canonicalQueryString = `${subresource}=`;
2778
3033
  const canonicalHeaders = `host:${url.host}\n` + `x-amz-content-sha256:${payloadHash}\n` + `x-amz-date:${amzDate}\n`;
2779
3034
  const signedHeaders = 'host;x-amz-content-sha256;x-amz-date';
2780
3035
  const canonicalRequest = [
@@ -1,24 +0,0 @@
1
- {
2
- "name": "@huaweicloud-devkit/opencode-integration",
3
- "version": "0.0.0",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "@huaweicloud-devkit/opencode-integration",
9
- "version": "0.0.0",
10
- "dependencies": {
11
- "zod": "^3.11.0"
12
- }
13
- },
14
- "node_modules/zod": {
15
- "version": "3.25.76",
16
- "resolved": "https://repo.huaweicloud.com/repository/npm/zod/-/zod-3.25.76.tgz",
17
- "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
18
- "license": "MIT",
19
- "funding": {
20
- "url": "https://github.com/sponsors/colinhacks"
21
- }
22
- }
23
- }
24
- }
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@huaweicloud-devkit/opencode-integration",
3
- "version": "0.0.0",
4
- "private": true,
5
- "type": "module",
6
- "description": "Local deps for the huaweicloud-devkit OpenCode plugin (zod for tool schema conversion). Installed into ~/.config/opencode by 'npx huaweicloud-devkit install --target opencode'.",
7
- "dependencies": {
8
- "zod": "^3.11.0"
9
- }
10
- }