huaweicloud-devkit 2.0.0-next.4 → 2.0.0-next.5
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/package.json +1 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +6 -1
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +18 -9
- package/plugins/huaweicloud-core/dist/mcp-server.js +435 -282
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/registry.js +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +25 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +28 -3
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +14 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +11 -3
- package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
- package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
- package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
- package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +1 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +14 -1
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +1 -1
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +42 -39
- package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +6 -1
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +32 -1
- package/plugins/huaweicloud-core/src/packs/registry.ts +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +28 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -15
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +20 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +12 -2
- package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
- package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
- package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
- package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +7 -5
- package/plugins/huaweicloud-core/src/tool-definitions.ts +4 -0
|
@@ -170,11 +170,12 @@ Selection rules(按意图自动选池;具体按 [Pool-Selection Gate](#pool-
|
|
|
170
170
|
|
|
171
171
|
### Tunnel Persistence (public URL lifetime)
|
|
172
172
|
|
|
173
|
-
| Tool | Purpose
|
|
174
|
-
| ---------------------------------------- |
|
|
175
|
-
| `huaweicloud_sandbox_expose_tunnel` | Expose a port → public tunnel URL (auth, pre-clean, health check; `expiry_hours` 1-720, def 72). **AUTO-enrolls into the keepalive watchdog** (`keepalive: false` opts out; the merge preserves the watchdog ROSTER — note each expose pre-cleans all tunnels, so prior tunnels' coverage matters only for hosts surviving outside this flow) |
|
|
176
|
-
| `
|
|
177
|
-
| `
|
|
173
|
+
| Tool | Purpose |
|
|
174
|
+
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
175
|
+
| `huaweicloud_sandbox_expose_tunnel` | Expose a port → public tunnel URL (auth, pre-clean, health check; `expiry_hours` 1-720, def 72). **AUTO-enrolls into the keepalive watchdog** (`keepalive: false` opts out; the merge preserves the watchdog ROSTER — note each expose pre-cleans all tunnels, so prior tunnels' coverage matters only for hosts surviving outside this flow). `mode: "async"` returns `{started, taskId}` immediately when the chain can outlive the host request timeout |
|
|
176
|
+
| `huaweicloud_sandbox_expose_poll` | Poll an async expose task (`state` running/done/failed/unknown; `done` carries the full expose envelope incl. `publicUrl` and `urlLifetimeHint`) |
|
|
177
|
+
| `huaweicloud_sandbox_renew_tunnel` | Renew a tunnel lifetime (`update -e`, rolling window; returns absolute expiresAt) |
|
|
178
|
+
| `huaweicloud_sandbox_keepalive_watchdog` | Install/replace the 3-layer watchdog: host re-attach + daily 720h renewal + 5-min health check |
|
|
178
179
|
|
|
179
180
|
### Terminal Execution
|
|
180
181
|
|
|
@@ -360,6 +361,8 @@ Expose a deployed web app to a public URL and return that URL to the developer.
|
|
|
360
361
|
|
|
361
362
|
**User-facing language rule**: the tunnel mechanism below is an internal implementation detail. Never mention "DevBridge", "tunnel", or the tunnel CLI to the developer. Tell the developer only: "正在生成访问地址..." while exposing, then hand over the final URL.
|
|
362
363
|
|
|
364
|
+
**Long chain / tight host timeout (async mode)**: the expose chain (auth gate, selective cleanup, up to four ~63s expose attempts, the persistence re-verify, keepalive enrollment) can outlive an MCP host's per-request timeout. In that posture call `huaweicloud_sandbox_expose_tunnel` with `mode: "async"`: it returns `{started: true, taskId}` at once and the chain continues in the background. Poll `huaweicloud_sandbox_expose_poll` with the `taskId` until `state: "done"`, then hand over `result.publicUrl` **and** `result.urlLifetimeHint` (the tunnel expiry is NOT the sandbox lifetime). The receipt lives 30 minutes in this MCP server process; `state: "unknown"` means the tunnel may already exist — check `huaweicloud_sandbox_deploy_check` or re-expose, never assume success without a URL.
|
|
365
|
+
|
|
363
366
|
### Step 0: Ensure DevBridge CLI 0.2.x (install or upgrade in place)
|
|
364
367
|
|
|
365
368
|
**Check the version first.** Sandboxes created before Sep 2026 ship devbridge 0.1.13, whose hardcoded gateway (`cn-north-4-bridge.myhuaweicloud.com`) was migrated and now serves a 「服务已迁移」 placeholder page — 0.1.x can no longer connect:
|
|
@@ -1137,40 +1140,40 @@ Returns `complete: true/false`, `score`, and `nextStep` to fix missing items.
|
|
|
1137
1140
|
|
|
1138
1141
|
## Critical Warnings
|
|
1139
1142
|
|
|
1140
|
-
| Trap | Why
|
|
1141
|
-
| --------------------------------------- |
|
|
1142
|
-
| Target not confirmed | "部署到华为云" without a named target is NOT a go signal. You MUST run the Target-Selection Gate and get an explicit choice before calling any sandbox lifecycle tool. Skipping it and defaulting to the sandbox is a violation.
|
|
1143
|
-
| Stack not confirmed (workbench ⇒ SPA) | 工作台/全栈/full-stack/CRUD/数据库/持久化 requests are full-stack workbench deployments (PostgreSQL + PostgREST default) even when no database is mentioned. NEVER infer or default the stack to SPA — run the Stack-Selection Gate (Step 0.5) before uploading or writing ANY application code; an SPA-only deployment that already started with persistence implied must be STOPped and redirected to the full-stack path, not papered over with a bolted-on static backend.
|
|
1144
|
-
| Pool type fixes durability | 预览/试用/即焚 requests belong on the `ephemeral` pool — idle 30min auto-shutdown + 1h auto-delete (平台定时任务,已实测), nothing survives it, data dies with the box; 工作台/需要跨会话保留数据/跨日 requests belong on the `persistent` pool (EVS 32G mounted, survives reboots, idle reclaim within 7 days max). Pick per the [Pool-Selection Gate](#pool-selection-gate-mandatory--do-not-skip) (Step 0.6) BEFORE calling `sandbox_connect`, and never promise durability on an ephemeral sandbox. A rejected connect returns HTTP 429 with one of three codes — the CODE, not the status, separates the failure classes: HDKIT_QUOTA_EXCEEDED (quota — 1 instance per pool type; release or reuse, retry useless; Retry-After 60), HDKIT_TEMPLATE_QUOTA_EXCEEDED (the running instances of this account for this sandbox type are at the limit — shut down or release an instance of the same type and retry; no Retry-After), or HDKIT_CAPACITY_INSUFFICIENT (pool capacity; retry later / off-peak; Retry-After 60).
|
|
1145
|
-
| Gateway 502/504 vs the 409 version gate | A connect answered by gateway 502/504 is a transient orchestration timeout, NOT a failed create: Gateway 502/504 timeouts during orchestration
|
|
1146
|
-
| Agreement required first | `sandbox_connect` fails if the agreement isn't signed; the `sandbox_check_user` preflight detects this, so surface it to the developer only when signing is needed
|
|
1147
|
-
| Real-name required | `sandbox_connect` fails if `realnameVerified=false`; tell the developer once and stop, don't loop on connect
|
|
1148
|
-
| Never expose tunnel details | Do not mention "DevBridge"/"tunnel"/"devbridge" to the developer — say "正在生成访问地址..." and hand over only the URL
|
|
1149
|
-
| devbridge auth: API Key only | DevBridge auth is fixed to API Key (AK/SK login removed, 2026-11-04). The waterfall: keyring (ours + platform legacy) → file → auto-create fallback. Use `devbridge auth login --api-key` only — never `--access-key/--secret-key`.
|
|
1150
|
-
| devbridge 0.1.x is dead | Sandboxes created before Sep 2026 ship 0.1.13, which connects to a migrated gateway serving a 「服务已迁移」 placeholder with HTTP 200. Check `devbridge version` first and upgrade in place (Step 0) — old tunnels never survive the upgrade
|
|
1151
|
-
| CLI PATH | The installer only writes `~/.bashrc`; run `export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"` (prepend, data-disk first) in the session before using `devbridge` — appending lets a stale image binary in `/usr/local/bin` win, and `~/.huawei/bin` alone is wiped on reboot (#999)
|
|
1152
|
-
| Never install tunnel tooling locally | If the sandbox cannot install it, report a generic error and stop — installing on the developer's machine defeats sandbox deployment
|
|
1153
|
-
| Return the deployment URL | Always hand the public URL from the host log to the developer as the final result
|
|
1154
|
-
| Deploy is not just nginx | Configuring nginx does NOT complete the deployment. Steps 7 (DevBridge expose) and deploy_check are REQUIRED — `deploy_nginx` returns `nextStep: expose_via_devbridge` as a reminder. Do not stop after nginx.
|
|
1155
|
-
| Call deploy_check before success | Always call `huaweicloud_sandbox_deploy_check` before reporting deployment success. A green nginx status does not mean the tunnel is accessible — verify end-to-end with the tool.
|
|
1156
|
-
| Session state persists | `exec_with_session` preserves `cd`, env vars, aliases between calls
|
|
1157
|
-
| Long commands prefer one-shot | `exec_one_shot` creates a fresh connection per call — more stable for builds, installs, and scripts >30s. See [Tool Selection Guide](#tool-selection-guide).
|
|
1158
|
-
| SSR nginx/Node ports must differ | nginx `proxy_pass` targets `<nodePort>`, not `<port>`. `deploy_nginx` auto-defaults `nodePort` to `<port>+1` — always start the Node process with `PORT=<nodePort>` to match. Same-port = EADDRINUSE.
|
|
1159
|
-
| HTTP 200 ≠ correct content | A green HTTP check does not guarantee the right project is serving — old processes from a previous session bound to the same port will still return 200. `deploy_check` verifies the deployment fingerprint to catch this.
|
|
1160
|
-
| 404 "tunnel not found" ≠ content issue | The s2 gateway answers 404 with body `tunnel not found` when the host process is dead (the tunnel record may STILL show in `devbridge list`) and `port not configured` for an unregistered URL port — both mean the URL is dead, not that the app returned 404. `expose_tunnel`/`deploy_check` verify the probe body and refuse such URLs; a shared sandbox's second deployment also kills earlier URLs (global pre-clean), so re-expose and hand over the fresh URL.
|
|
1161
|
-
| Destructive commands blocked | `rm -rf /`, `mkfs`, `dd if=`, fork bombs, and shutdown/reboot/init verbs at command position are denied on every host — by the agent Bash hook where installed, and server-side by the sandbox exec approval gate's strict classification (a strict deny survives every confirmation)
|
|
1162
|
-
| Workspace ID = dev_stage_id | Use `dev_stage_id` from `sandbox_connect` as `workspace_id` for terminal exec
|
|
1163
|
-
| Projects live in `/workspace` | Clone/install project code under `/workspace/<repo-name>` (filesystem-root workspace mount, not `$HOME/workspace`), never in `/tmp` — ephemeral locations lose the project when the sandbox session restarts
|
|
1164
|
-
| Upload project for local code | Use `sandbox_upload_project` to transfer local projects — packages as tar.gz, uploads via HTTP tunnel, extracts on sandbox. Much faster than base64 for multi-file projects
|
|
1165
|
-
| Upload file for single files | Use `sandbox_upload_file` for individual files — base64 chunked, reliable for small files (<1MB)
|
|
1166
|
-
| Node.js >= 22 required | Sandbox terminal uses built-in WebSocket (globalThis.WebSocket); if Node.js is missing, install it from the Huawei Cloud mirror (see "Node.js in the sandbox")
|
|
1167
|
-
| Sandbox restart kills processes | After sandbox restarts, all user processes (nginx, Node.js, Python servers) are stopped. Re-run startup commands and verify ports are listening before proceeding.
|
|
1168
|
-
| Cross-platform binaries incompatible | The sandbox runs Linux. Native binaries built on Windows/macOS (e.g., Prisma client, `node_modules/.prisma/`, platform-specific native addons) will not execute. Always install and build dependencies inside the sandbox, not locally.
|
|
1169
|
-
| Cross-platform needs QR code | When `detect_framework` returns `type: "cross-platform"` (Taro, uni-app), generating a QR code image is **mandatory** — the deployment is incomplete without it. Check the Deployment Completion Check table in Step 7.
|
|
1170
|
-
| Build fails do NOT auto-fix | When a build exits with non-zero exit code, STOP and present the error + fix options to the developer. Do not silently retry, modify configs, or change source files without explicit approval. See 4c-aux.
|
|
1171
|
-
| Tunnel description: no spaces/hyphens | `devbridge create <name> -d 'hello world'` fails with `Invalid tunnel description: only Chinese characters, digits, letters, length 0-64`. The message is misleading — the real rule is no spaces/hyphens. Omit `-d` or use bare letters/digits.
|
|
1172
|
-
| Use `host`, never `connect` | `devbridge connect` is the sender side (for on-prem machines dialing out). For public preview it loops `Connection failed, retrying...` forever with no hint. Always use `devbridge host <tunnelId> -p <port>`.
|
|
1173
|
-
| Port drift detaches the tunnel | When deploy_nginx auto-increments to a free port, an existing tunnel stays bound to the old port — re-bind: `devbridge port create <tunnelId> -p <newPort> --protocol http -a` and restart `devbridge host`. deploy_nginx emits a warning when this happens.
|
|
1143
|
+
| Trap | Why |
|
|
1144
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1145
|
+
| Target not confirmed | "部署到华为云" without a named target is NOT a go signal. You MUST run the Target-Selection Gate and get an explicit choice before calling any sandbox lifecycle tool. Skipping it and defaulting to the sandbox is a violation. |
|
|
1146
|
+
| Stack not confirmed (workbench ⇒ SPA) | 工作台/全栈/full-stack/CRUD/数据库/持久化 requests are full-stack workbench deployments (PostgreSQL + PostgREST default) even when no database is mentioned. NEVER infer or default the stack to SPA — run the Stack-Selection Gate (Step 0.5) before uploading or writing ANY application code; an SPA-only deployment that already started with persistence implied must be STOPped and redirected to the full-stack path, not papered over with a bolted-on static backend. |
|
|
1147
|
+
| Pool type fixes durability | 预览/试用/即焚 requests belong on the `ephemeral` pool — idle 30min auto-shutdown + 1h auto-delete (平台定时任务,已实测), nothing survives it, data dies with the box; 工作台/需要跨会话保留数据/跨日 requests belong on the `persistent` pool (EVS 32G mounted, survives reboots, idle reclaim within 7 days max). Pick per the [Pool-Selection Gate](#pool-selection-gate-mandatory--do-not-skip) (Step 0.6) BEFORE calling `sandbox_connect`, and never promise durability on an ephemeral sandbox. A rejected connect returns HTTP 429 with one of three codes — the CODE, not the status, separates the failure classes: HDKIT_QUOTA_EXCEEDED (quota — 1 instance per pool type; release or reuse, retry useless; Retry-After 60), HDKIT_TEMPLATE_QUOTA_EXCEEDED (the running instances of this account for this sandbox type are at the limit — shut down or release an instance of the same type and retry; no Retry-After), or HDKIT_CAPACITY_INSUFFICIENT (pool capacity; retry later / off-peak; Retry-After 60). |
|
|
1148
|
+
| Gateway 502/504 vs the 409 version gate | A connect answered by gateway 502/504 is a transient orchestration timeout, NOT a failed create: Gateway 502/504 timeouts during orchestration return a pending receipt (ok:false, pending:true, retryAfter, hint) instead of holding the call through the backoff — the server may already have created the instance; re-call connect with the SAME parameters after retryAfter and a created instance is reused; on a genuine exhaustion the result is ok:false with the attempt count, and the remediation follows the failing answer — a gateway page carries the transient-class copy, while a business-coded 502 that carries its own remediation keeps it (one without its own copy falls to the transient copy). A 409 `HDKIT_VERSION_TOO_OLD` is the client-version gate — a different failure, not transient: follow the returned remediation (npx --yes huaweicloud-devkit@latest update --target <agent>, restart the agent session, or call `huaweicloud_upgrade`); retrying connect cannot clear it. The same gate fires on the expose relay's auto-create, surfacing error_code HDKIT_VERSION_TOO_OLD with the upgrade remediation instead of a credential failure. Do not debug either as a credential or deployment issue. |
|
|
1149
|
+
| Agreement required first | `sandbox_connect` fails if the agreement isn't signed; the `sandbox_check_user` preflight detects this, so surface it to the developer only when signing is needed |
|
|
1150
|
+
| Real-name required | `sandbox_connect` fails if `realnameVerified=false`; tell the developer once and stop, don't loop on connect |
|
|
1151
|
+
| Never expose tunnel details | Do not mention "DevBridge"/"tunnel"/"devbridge" to the developer — say "正在生成访问地址..." and hand over only the URL |
|
|
1152
|
+
| devbridge auth: API Key only | DevBridge auth is fixed to API Key (AK/SK login removed, 2026-11-04). The waterfall: keyring (ours + platform legacy) → file → auto-create fallback. Use `devbridge auth login --api-key` only — never `--access-key/--secret-key`. |
|
|
1153
|
+
| devbridge 0.1.x is dead | Sandboxes created before Sep 2026 ship 0.1.13, which connects to a migrated gateway serving a 「服务已迁移」 placeholder with HTTP 200. Check `devbridge version` first and upgrade in place (Step 0) — old tunnels never survive the upgrade |
|
|
1154
|
+
| CLI PATH | The installer only writes `~/.bashrc`; run `export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"` (prepend, data-disk first) in the session before using `devbridge` — appending lets a stale image binary in `/usr/local/bin` win, and `~/.huawei/bin` alone is wiped on reboot (#999) |
|
|
1155
|
+
| Never install tunnel tooling locally | If the sandbox cannot install it, report a generic error and stop — installing on the developer's machine defeats sandbox deployment |
|
|
1156
|
+
| Return the deployment URL | Always hand the public URL from the host log to the developer as the final result |
|
|
1157
|
+
| Deploy is not just nginx | Configuring nginx does NOT complete the deployment. Steps 7 (DevBridge expose) and deploy_check are REQUIRED — `deploy_nginx` returns `nextStep: expose_via_devbridge` as a reminder. Do not stop after nginx. |
|
|
1158
|
+
| Call deploy_check before success | Always call `huaweicloud_sandbox_deploy_check` before reporting deployment success. A green nginx status does not mean the tunnel is accessible — verify end-to-end with the tool. |
|
|
1159
|
+
| Session state persists | `exec_with_session` preserves `cd`, env vars, aliases between calls |
|
|
1160
|
+
| Long commands prefer one-shot | `exec_one_shot` creates a fresh connection per call — more stable for builds, installs, and scripts >30s. See [Tool Selection Guide](#tool-selection-guide). |
|
|
1161
|
+
| SSR nginx/Node ports must differ | nginx `proxy_pass` targets `<nodePort>`, not `<port>`. `deploy_nginx` auto-defaults `nodePort` to `<port>+1` — always start the Node process with `PORT=<nodePort>` to match. Same-port = EADDRINUSE. |
|
|
1162
|
+
| HTTP 200 ≠ correct content | A green HTTP check does not guarantee the right project is serving — old processes from a previous session bound to the same port will still return 200. `deploy_check` verifies the deployment fingerprint to catch this. |
|
|
1163
|
+
| 404 "tunnel not found" ≠ content issue | The s2 gateway answers 404 with body `tunnel not found` when the host process is dead (the tunnel record may STILL show in `devbridge list`) and `port not configured` for an unregistered URL port — both mean the URL is dead, not that the app returned 404. `expose_tunnel`/`deploy_check` verify the probe body and refuse such URLs; a shared sandbox's second deployment also kills earlier URLs (global pre-clean), so re-expose and hand over the fresh URL. |
|
|
1164
|
+
| Destructive commands blocked | `rm -rf /`, `mkfs`, `dd if=`, fork bombs, and shutdown/reboot/init verbs at command position are denied on every host — by the agent Bash hook where installed, and server-side by the sandbox exec approval gate's strict classification (a strict deny survives every confirmation) |
|
|
1165
|
+
| Workspace ID = dev_stage_id | Use `dev_stage_id` from `sandbox_connect` as `workspace_id` for terminal exec |
|
|
1166
|
+
| Projects live in `/workspace` | Clone/install project code under `/workspace/<repo-name>` (filesystem-root workspace mount, not `$HOME/workspace`), never in `/tmp` — ephemeral locations lose the project when the sandbox session restarts |
|
|
1167
|
+
| Upload project for local code | Use `sandbox_upload_project` to transfer local projects — packages as tar.gz, uploads via HTTP tunnel, extracts on sandbox. Much faster than base64 for multi-file projects |
|
|
1168
|
+
| Upload file for single files | Use `sandbox_upload_file` for individual files — base64 chunked, reliable for small files (<1MB) |
|
|
1169
|
+
| Node.js >= 22 required | Sandbox terminal uses built-in WebSocket (globalThis.WebSocket); if Node.js is missing, install it from the Huawei Cloud mirror (see "Node.js in the sandbox") |
|
|
1170
|
+
| Sandbox restart kills processes | After sandbox restarts, all user processes (nginx, Node.js, Python servers) are stopped. Re-run startup commands and verify ports are listening before proceeding. |
|
|
1171
|
+
| Cross-platform binaries incompatible | The sandbox runs Linux. Native binaries built on Windows/macOS (e.g., Prisma client, `node_modules/.prisma/`, platform-specific native addons) will not execute. Always install and build dependencies inside the sandbox, not locally. |
|
|
1172
|
+
| Cross-platform needs QR code | When `detect_framework` returns `type: "cross-platform"` (Taro, uni-app), generating a QR code image is **mandatory** — the deployment is incomplete without it. Check the Deployment Completion Check table in Step 7. |
|
|
1173
|
+
| Build fails do NOT auto-fix | When a build exits with non-zero exit code, STOP and present the error + fix options to the developer. Do not silently retry, modify configs, or change source files without explicit approval. See 4c-aux. |
|
|
1174
|
+
| Tunnel description: no spaces/hyphens | `devbridge create <name> -d 'hello world'` fails with `Invalid tunnel description: only Chinese characters, digits, letters, length 0-64`. The message is misleading — the real rule is no spaces/hyphens. Omit `-d` or use bare letters/digits. |
|
|
1175
|
+
| Use `host`, never `connect` | `devbridge connect` is the sender side (for on-prem machines dialing out). For public preview it loops `Connection failed, retrying...` forever with no hint. Always use `devbridge host <tunnelId> -p <port>`. |
|
|
1176
|
+
| Port drift detaches the tunnel | When deploy_nginx auto-increments to a free port, an existing tunnel stays bound to the old port — re-bind: `devbridge port create <tunnelId> -p <newPort> --protocol http -a` and restart `devbridge host`. deploy_nginx emits a warning when this happens. |
|
|
1174
1177
|
|
|
1175
1178
|
## Node.js in the sandbox
|
|
1176
1179
|
|
|
@@ -237,8 +237,16 @@ export function explainError({
|
|
|
237
237
|
return !arr.slice(0, i).some((prev) => prev.substring(0, 50).toLowerCase() === s.substring(0, 50).toLowerCase());
|
|
238
238
|
});
|
|
239
239
|
|
|
240
|
+
// The response names the service the error was RESOLVED to, not a raw
|
|
241
|
+
// `unknown`/wrong pasted name: `code`-only calls and a pasted service whose
|
|
242
|
+
// own pattern table is empty derive their key from the code prefix (the
|
|
243
|
+
// suggestions already walked that table). A valid explicit service keeps
|
|
244
|
+
// its exact spelling — the pre-existing contract and its #935 regression
|
|
245
|
+
// pin (AX report D-05).
|
|
246
|
+
const providedKnown = Boolean(service) && svc !== 'unknown';
|
|
247
|
+
const responseService = !providedKnown || !hwErrorPatterns[patternKey] ? effectiveKey : service;
|
|
240
248
|
return {
|
|
241
|
-
service,
|
|
249
|
+
service: responseService,
|
|
242
250
|
errorCode: resolvedCode,
|
|
243
251
|
requestId,
|
|
244
252
|
suggestions: uniqueSuggestions,
|
|
@@ -408,6 +408,11 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
|
|
|
408
408
|
...(approvalToken !== undefined ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}),
|
|
409
409
|
}
|
|
410
410
|
: { needed: false },
|
|
411
|
-
|
|
411
|
+
// "Safe to run NOW": a caller-supplied allowWrites:true only unlocks the
|
|
412
|
+
// classification — the strict view still demands the user's confirmation
|
|
413
|
+
// (the approval token/form), so a plan showing decision:"allow" must not
|
|
414
|
+
// also read as runnable while userConfirmation.needed is true (AX D-02
|
|
415
|
+
// display-layer alignment).
|
|
416
|
+
safeToRun: effectiveClassification.decision === 'allow' && !needsConfirmation,
|
|
412
417
|
};
|
|
413
418
|
}
|
|
@@ -432,8 +432,24 @@ export async function hdkitConnect(options: Record<string, unknown> = {}): Promi
|
|
|
432
432
|
* 重试表经 HW_SANDBOX_CONNECT_RETRY_DELAYS_MS 针脚可覆写(v2 扩展)。
|
|
433
433
|
* 成功路径回显 connect_retries(v2 扩展;dev 仅在错误路径带尝试次数)。
|
|
434
434
|
*/
|
|
435
|
-
export
|
|
435
|
+
export interface HdkitConnectRetryOptions {
|
|
436
|
+
// MCP tool faces must answer inside the host's request budget. A backoff
|
|
437
|
+
// longer than maxInlineDelayMs returns a `pending` receipt instead of
|
|
438
|
+
// sleeping: the server may already have created the instance, and the
|
|
439
|
+
// agent's next huaweicloud_sandbox_connect call re-attempts the same
|
|
440
|
+
// request and reuses it. inlineRetry:false disables the inline ladder
|
|
441
|
+
// outright (both knobs default to the dev behavior: inline, unbounded).
|
|
442
|
+
inlineRetry?: boolean;
|
|
443
|
+
maxInlineDelayMs?: number;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export async function hdkitConnectWithRetry(
|
|
447
|
+
options: Record<string, unknown> = {},
|
|
448
|
+
retryOptions: HdkitConnectRetryOptions = {},
|
|
449
|
+
): Promise<Record<string, unknown>> {
|
|
436
450
|
const delays = connectRetryDelaysMs();
|
|
451
|
+
const inlineRetry = retryOptions.inlineRetry !== false;
|
|
452
|
+
const maxInlineDelayMs = retryOptions.maxInlineDelayMs ?? Number.POSITIVE_INFINITY;
|
|
437
453
|
let retries = 0;
|
|
438
454
|
for (;;) {
|
|
439
455
|
try {
|
|
@@ -454,6 +470,21 @@ export async function hdkitConnectWithRetry(options: Record<string, unknown> = {
|
|
|
454
470
|
if (transient) throw decorateExhaustedConnect(error, retries);
|
|
455
471
|
throw error;
|
|
456
472
|
}
|
|
473
|
+
if (!inlineRetry || (delays[retries] ?? Number.POSITIVE_INFINITY) > maxInlineDelayMs) {
|
|
474
|
+
// AX N-SB.2: never hold the tool call through a backoff longer than
|
|
475
|
+
// the host's request budget — a host request timeout would abandon
|
|
476
|
+
// the call while the server completed the create. The retry moves to
|
|
477
|
+
// the next tool call (same params). Short test/operator backoffs keep
|
|
478
|
+
// the inline ladder.
|
|
479
|
+
const pendingCode = asString(safeReadField(error, 'code'));
|
|
480
|
+
return {
|
|
481
|
+
pending: true,
|
|
482
|
+
connectRetries: retries,
|
|
483
|
+
retryAfterMs: delays[retries] ?? delays[0] ?? 0,
|
|
484
|
+
...(pendingCode ? { code: pendingCode } : {}),
|
|
485
|
+
message: safeMessageText(error),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
457
488
|
await new Promise((resolve) => setTimeout(resolve, delays[retries]));
|
|
458
489
|
retries += 1;
|
|
459
490
|
}
|
|
@@ -74,6 +74,7 @@ export const PACK_OF = {
|
|
|
74
74
|
huaweicloud_sandbox_deploy_nginx: 'sandbox',
|
|
75
75
|
huaweicloud_sandbox_deploy_check: 'sandbox',
|
|
76
76
|
huaweicloud_sandbox_expose_tunnel: 'sandbox',
|
|
77
|
+
huaweicloud_sandbox_expose_poll: 'sandbox',
|
|
77
78
|
huaweicloud_sandbox_renew_tunnel: 'sandbox',
|
|
78
79
|
huaweicloud_sandbox_keepalive_watchdog: 'sandbox',
|
|
79
80
|
huaweicloud_sandbox_check_user: 'sandbox',
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import type { ExposeTunnelResult } from '../../sandbox/devbridge-expose.ts';
|
|
4
|
+
|
|
5
|
+
// The async expose-task registry (AX N-SB.1). An expose chain can outlive
|
|
6
|
+
// the host's MCP request timeout (auth gate + selective cleanups + up to
|
|
7
|
+
// four ~63s expose execs + the persistence re-verify + keepalive enrollment)
|
|
8
|
+
// while the server completes it — the synchronous tool then loses the
|
|
9
|
+
// publicUrl. An async start returns immediately and the poll tool delivers
|
|
10
|
+
// the finished result in-band.
|
|
11
|
+
//
|
|
12
|
+
// The registry is process-scoped (the stdio MCP server owns one). A restart
|
|
13
|
+
// loses the receipt while the tunnel may already live; the unknown hint
|
|
14
|
+
// therefore teaches recovery (re-expose / deploy_check) and never fabricates
|
|
15
|
+
// a URL. Entries are swept after the TTL so a long session cannot grow the
|
|
16
|
+
// map unbounded.
|
|
17
|
+
|
|
18
|
+
export const EXPOSE_TASK_ID_PATTERN = /^exp-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
19
|
+
|
|
20
|
+
const EXPOSE_TASK_TTL_MS = 30 * 60_000;
|
|
21
|
+
|
|
22
|
+
export interface ExposeTaskSnapshot {
|
|
23
|
+
startedAt: number;
|
|
24
|
+
workspaceId: string;
|
|
25
|
+
port: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ExposeTask =
|
|
29
|
+
| (ExposeTaskSnapshot & { state: 'running' })
|
|
30
|
+
| (ExposeTaskSnapshot & { state: 'done'; result: ExposeTunnelResult })
|
|
31
|
+
| (ExposeTaskSnapshot & { state: 'failed'; error: string });
|
|
32
|
+
|
|
33
|
+
const tasks = new Map<string, ExposeTask>();
|
|
34
|
+
|
|
35
|
+
function sweep(now: number): void {
|
|
36
|
+
for (const [taskId, task] of tasks) {
|
|
37
|
+
if (now - task.startedAt > EXPOSE_TASK_TTL_MS) tasks.delete(taskId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function startExposeTask(
|
|
42
|
+
workspaceId: string,
|
|
43
|
+
port: number,
|
|
44
|
+
run: () => Promise<ExposeTunnelResult>,
|
|
45
|
+
): { taskId: string; startedAt: number } {
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
sweep(now);
|
|
48
|
+
const taskId = `exp-${randomUUID()}`;
|
|
49
|
+
const snapshot: ExposeTaskSnapshot = { startedAt: now, workspaceId, port };
|
|
50
|
+
tasks.set(taskId, { ...snapshot, state: 'running' });
|
|
51
|
+
// The chain runs detached from the tool call: the client may time out or
|
|
52
|
+
// cancel the start request, but the server-side work (and the tunnel it
|
|
53
|
+
// creates) must continue. Both settle paths are recorded, so the promise
|
|
54
|
+
// is never an unhandled rejection.
|
|
55
|
+
void run().then(
|
|
56
|
+
(result) => {
|
|
57
|
+
tasks.set(taskId, { ...snapshot, state: 'done', result });
|
|
58
|
+
},
|
|
59
|
+
(error: unknown) => {
|
|
60
|
+
tasks.set(taskId, {
|
|
61
|
+
...snapshot,
|
|
62
|
+
state: 'failed',
|
|
63
|
+
error: error instanceof Error ? error.message : String(error),
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
return { taskId, startedAt: now };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type ExposePollResult =
|
|
71
|
+
| { state: 'running'; elapsedMs: number; hint: string }
|
|
72
|
+
| { state: 'done'; result: ExposeTunnelResult }
|
|
73
|
+
| { state: 'failed'; error: string }
|
|
74
|
+
| { state: 'unknown'; hint: string };
|
|
75
|
+
|
|
76
|
+
export function pollExposeTask(taskId: string): ExposePollResult {
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
sweep(now);
|
|
79
|
+
const task = tasks.get(taskId);
|
|
80
|
+
if (!task) {
|
|
81
|
+
return {
|
|
82
|
+
state: 'unknown',
|
|
83
|
+
hint:
|
|
84
|
+
'No task with this id is known to this MCP server process (it never started here, the session restarted, or the ' +
|
|
85
|
+
'30-minute receipt expired). The tunnel may already exist: run huaweicloud_sandbox_deploy_check to read it, or ' +
|
|
86
|
+
're-run huaweicloud_sandbox_expose_tunnel (same port) — do not assume success without a URL.',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (task.state === 'running') {
|
|
90
|
+
return {
|
|
91
|
+
state: 'running',
|
|
92
|
+
elapsedMs: now - task.startedAt,
|
|
93
|
+
hint: 'The expose chain is running in the background (auth, cleanup, host start, health check, keepalive). Call again.',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (task.state === 'done') {
|
|
97
|
+
return { state: 'done', result: task.result };
|
|
98
|
+
}
|
|
99
|
+
return { state: 'failed', error: task.error };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Test seam: isolate a process-global registry between cases.
|
|
103
|
+
export function _resetExposeTasksForTests(): void {
|
|
104
|
+
tasks.clear();
|
|
105
|
+
}
|
|
@@ -72,7 +72,12 @@ export async function handleConnect(args: ToolArgs = {}, _opts: CallToolOptions
|
|
|
72
72
|
}
|
|
73
73
|
let connectResult: Record<string, unknown>;
|
|
74
74
|
try {
|
|
75
|
-
|
|
75
|
+
// AX N-SB.2: the MCP tool answers inside the host's request budget — a
|
|
76
|
+
// transient gateway timeout returns a pending receipt instead of sleeping
|
|
77
|
+
// through the 30s/45s table (the next call re-attempts and reuses any
|
|
78
|
+
// instance the server already created). Short backoffs (tests/operators)
|
|
79
|
+
// keep the inline ladder.
|
|
80
|
+
connectResult = await hdkitConnectWithRetry(connectArgs, { maxInlineDelayMs: 1000 });
|
|
76
81
|
} catch (error) {
|
|
77
82
|
// 业务预期失败(429 三码 / 烧核 / 凭证失效)转结构化返回,remediation 才能穿透 MCP 边界;
|
|
78
83
|
// 其余错误维持抛出(MCP 层透传 code+message)。
|
|
@@ -149,6 +154,28 @@ export async function handleConnect(args: ToolArgs = {}, _opts: CallToolOptions
|
|
|
149
154
|
}
|
|
150
155
|
throw error;
|
|
151
156
|
}
|
|
157
|
+
if (connectResult?.pending === true) {
|
|
158
|
+
const retryAfterMs =
|
|
159
|
+
typeof connectResult.retryAfterMs === 'number' && Number.isFinite(connectResult.retryAfterMs)
|
|
160
|
+
? connectResult.retryAfterMs
|
|
161
|
+
: 30000;
|
|
162
|
+
const retryAfter = `${Math.max(1, Math.ceil(retryAfterMs / 1000))}s`;
|
|
163
|
+
return {
|
|
164
|
+
ok: false,
|
|
165
|
+
pending: true,
|
|
166
|
+
retryAfter,
|
|
167
|
+
retryAfterMs,
|
|
168
|
+
...(typeof connectResult.code === 'string' ? { code: connectResult.code } : {}),
|
|
169
|
+
message:
|
|
170
|
+
typeof connectResult.message === 'string' && connectResult.message
|
|
171
|
+
? connectResult.message
|
|
172
|
+
: 'the hdkitservice gateway timed out during orchestration.',
|
|
173
|
+
hint:
|
|
174
|
+
`The sandbox instance may already exist on the server. Re-call huaweicloud_sandbox_connect with the SAME ` +
|
|
175
|
+
`parameters after ~${retryAfter} — a created instance is reused. Do not start a second sandbox and do not ` +
|
|
176
|
+
`debug this as a credential failure.`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
152
179
|
const rawDevStageId = connectResult?.dev_stage_id || connectResult?.devStageId;
|
|
153
180
|
const devStageId = typeof rawDevStageId === 'string' ? rawDevStageId : undefined;
|
|
154
181
|
let announceConnect = true;
|
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
validateTunnelId,
|
|
6
6
|
} from '../../sandbox/devbridge-tunnel.ts';
|
|
7
7
|
import { getCurrentWorkspaceId } from '../../sandbox/session-manager.ts';
|
|
8
|
+
import { validateTunnelPort } from '../../sandbox/devbridge-validation.ts';
|
|
8
9
|
import { poolContextFor } from '../../lib/hdkit/sandbox-pool.ts';
|
|
10
|
+
import { startExposeTask, pollExposeTask } from './expose-task.ts';
|
|
9
11
|
import {
|
|
10
12
|
buildKeyringInjectScript,
|
|
11
13
|
ensureDevbridgeKey,
|
|
@@ -35,21 +37,45 @@ export async function handleExposeTunnel(args: ToolArgs = {}, _opts: CallToolOpt
|
|
|
35
37
|
const sandboxUser9 = args.username || 'root';
|
|
36
38
|
const sandboxTimeout9 = args.timeout_ms || SANDBOX_TIMEOUT_MS.expose_tunnel;
|
|
37
39
|
const exposePoolContext = poolContextFor(sandboxWsId9);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
40
|
+
const exposeArgs = {
|
|
41
|
+
port: validateTunnelPort(args.port),
|
|
42
|
+
expiryHours: typeof args.expiry_hours === 'number' ? args.expiry_hours : undefined,
|
|
43
|
+
keepalive: typeof args.keepalive === 'boolean' ? args.keepalive : undefined,
|
|
44
|
+
cleanupMode: args.cleanup_mode,
|
|
45
|
+
// DevBridge API Key 自动创建兜底(认证固定 apikey,AK/SK 已移除)
|
|
46
|
+
poolType: exposePoolContext?.poolMode || 'ephemeral',
|
|
47
|
+
poolContext: exposePoolContext,
|
|
48
|
+
keyUpgrade: { ensureDevbridgeKey, recreateDevbridgeKey, buildKeyringInjectScript, listKeysForQuotaHint },
|
|
49
|
+
};
|
|
50
|
+
// AX N-SB.1: the chain can outlive the host's request timeout while the
|
|
51
|
+
// server completes it — async starts it detached and the poll tool delivers
|
|
52
|
+
// the URL in-band. The fast parameter checks above stay synchronous, so a
|
|
53
|
+
// bad port is an immediate error, not a deferred task failure.
|
|
54
|
+
if (args.mode === 'async') {
|
|
55
|
+
const { taskId } = startExposeTask(sandboxWsId9, exposeArgs.port, () =>
|
|
56
|
+
exposeTunnel(sandboxWsId9, exposeArgs, sandboxUser9, sandboxTimeout9),
|
|
57
|
+
);
|
|
58
|
+
return {
|
|
59
|
+
started: true,
|
|
60
|
+
mode: 'async',
|
|
61
|
+
taskId,
|
|
62
|
+
hint:
|
|
63
|
+
'The expose chain is running in the background. Poll huaweicloud_sandbox_expose_poll with this taskId until ' +
|
|
64
|
+
'state is done — the publicUrl and urlLifetimeHint are delivered there (the task receipt lives 30 minutes in ' +
|
|
65
|
+
'this MCP server process).',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return await exposeTunnel(sandboxWsId9, exposeArgs, sandboxUser9, sandboxTimeout9);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function handleExposePoll(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
|
|
72
|
+
const taskId = args.task_id;
|
|
73
|
+
if (typeof taskId !== 'string' || taskId === '') {
|
|
74
|
+
throw new Error(
|
|
75
|
+
'task_id is required — pass the taskId returned by huaweicloud_sandbox_expose_tunnel mode:"async".',
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return pollExposeTask(taskId);
|
|
53
79
|
}
|
|
54
80
|
|
|
55
81
|
export async function handleRenewTunnel(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
|