huaweicloud-devkit 1.1.2-next.0 → 1.1.2-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +18 -18
- package/README.md +182 -38
- package/README.zh-CN.md +180 -36
- package/bin/dsh-postinstall.cjs +77 -0
- package/bin/setup.cjs +7 -4
- package/cordis.patch.yml +13 -0
- package/integrations/atomcode/hooks/huaweicloud-telemetry.js +181 -0
- package/integrations/atomcode/hooks.json +9 -0
- package/integrations/dsh/hook-plugin.mjs +148 -0
- package/integrations/hermes/hooks/huaweicloud-telemetry.py +238 -0
- package/integrations/hermes/manifest.yaml +43 -0
- package/integrations/opencode/hooks/skill-tracker.js +115 -0
- package/integrations/opencode/opencode.json +1 -4
- package/integrations/workbuddy/hooks/telemetry-tracker.py +226 -0
- package/package.json +74 -43
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +4 -17
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +23 -33
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +4 -17
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +30 -0
- package/plugins/huaweicloud-core/.mcp.json +2 -5
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +4 -18
- package/plugins/huaweicloud-core/assets/icon.png +0 -0
- package/plugins/huaweicloud-core/assets/logo-dark.png +0 -0
- package/plugins/huaweicloud-core/assets/logo.png +0 -0
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +104 -28
- package/plugins/huaweicloud-core/openclaw.plugin.json +20 -0
- package/plugins/huaweicloud-core/safety/policy.json +75 -99
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +196 -35
- package/plugins/huaweicloud-core/skills/huawei-apig/SKILL.md +38 -34
- package/plugins/huaweicloud-core/skills/huawei-billing/SKILL.md +21 -20
- package/plugins/huaweicloud-core/skills/huawei-cbr/SKILL.md +19 -19
- package/plugins/huaweicloud-core/skills/huawei-cce/SKILL.md +38 -32
- package/plugins/huaweicloud-core/skills/huawei-cloud-eye/SKILL.md +30 -30
- package/plugins/huaweicloud-core/skills/huawei-cts/SKILL.md +20 -20
- package/plugins/huaweicloud-core/skills/huawei-dds-dcs/SKILL.md +31 -31
- package/plugins/huaweicloud-core/skills/huawei-deployment/SKILL.md +21 -20
- package/plugins/huaweicloud-core/skills/huawei-dew/SKILL.md +40 -31
- package/plugins/huaweicloud-core/skills/huawei-dew/references/csms-usage.md +8 -1
- package/plugins/huaweicloud-core/skills/huawei-dew/references/kms-usage.md +6 -0
- package/plugins/huaweicloud-core/skills/huawei-ecs/SKILL.md +45 -37
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/create-instance.md +57 -6
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/flavors.md +11 -9
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/hc-activity.md +27 -0
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/troubleshooting.md +13 -13
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/SKILL.md +44 -39
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/apig-event-format.md +12 -10
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/create-function.md +21 -20
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/triggers.md +19 -19
- package/plugins/huaweicloud-core/skills/huawei-gaussdb/SKILL.md +20 -20
- package/plugins/huaweicloud-core/skills/huawei-getting-started/SKILL.md +27 -23
- package/plugins/huaweicloud-core/skills/huawei-iac/SKILL.md +93 -0
- package/plugins/huaweicloud-core/skills/huawei-iac/references/architectures.md +83 -0
- package/plugins/huaweicloud-core/skills/huawei-iac/references/resource-catalog.md +107 -0
- package/plugins/huaweicloud-core/skills/huawei-iac/references/state-file.md +104 -0
- package/plugins/huaweicloud-core/skills/huawei-iam/SKILL.md +30 -30
- package/plugins/huaweicloud-core/skills/huawei-iam/references/policy-examples.md +65 -39
- package/plugins/huaweicloud-core/skills/huawei-iam/references/quick-ref.md +9 -9
- package/plugins/huaweicloud-core/skills/huawei-modelarts/SKILL.md +33 -25
- package/plugins/huaweicloud-core/skills/huawei-obs/SKILL.md +46 -45
- package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-create.md +19 -19
- package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-lifecycle.md +12 -7
- package/plugins/huaweicloud-core/skills/huawei-obs/references/common-pitfalls.md +13 -12
- package/plugins/huaweicloud-core/skills/huawei-obs/references/single-file-share.md +4 -4
- package/plugins/huaweicloud-core/skills/huawei-rds/SKILL.md +71 -61
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +776 -44
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/framework-commands.md +84 -0
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/nginx-templates.md +100 -0
- package/plugins/huaweicloud-core/skills/huawei-smn-dms/SKILL.md +36 -29
- package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +57 -0
- package/plugins/huaweicloud-core/skills/huawei-vpc/SKILL.md +39 -39
- package/plugins/huaweicloud-core/skills/huawei-vpc/references/network.md +22 -15
- package/plugins/huaweicloud-core/skills/huawei-vpc/references/security-group.md +20 -19
- package/plugins/huaweicloud-core/skills/huawei-vpc/references/subnet.md +15 -15
- package/plugins/huaweicloud-core/skills/huawei-waf-aad/SKILL.md +23 -20
- package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/SKILL.md +13 -13
- package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/agents/openai.yaml +3 -3
- package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/SKILL.md +21 -2
- package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/agents/openai.yaml +3 -3
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +30 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/agents/openai.yaml +3 -3
- package/plugins/huaweicloud-core/skills/huaweicloud-core/SKILL.md +68 -54
- package/plugins/huaweicloud-core/skills/huaweicloud-core/agents/openai.yaml +3 -3
- package/plugins/huaweicloud-core/skills/huaweicloud-core/references/report-issue.md +6 -6
- package/plugins/huaweicloud-core/skills/huaweicloud-core/references/select.md +15 -1
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +0 -1
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/agents/openai.yaml +3 -3
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +36 -34
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/agents/openai.yaml +3 -3
- package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +142 -5
- package/plugins/huaweicloud-core/src/auth/credentials.mjs +217 -5
- package/plugins/huaweicloud-core/src/auth/reconcile.mjs +174 -0
- package/plugins/huaweicloud-core/src/auth/service.mjs +57 -2
- package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +3517 -0
- package/plugins/huaweicloud-core/src/detect-framework.mjs +366 -0
- package/plugins/huaweicloud-core/src/hcloud-cli.mjs +203 -16
- package/plugins/huaweicloud-core/src/icon-library.mjs +176 -0
- package/plugins/huaweicloud-core/src/mcp-protocol.mjs +88 -0
- package/plugins/huaweicloud-core/src/mcp-server-remote.mjs +107 -0
- package/plugins/huaweicloud-core/src/mcp-server.mjs +154 -99
- package/plugins/huaweicloud-core/src/proxy/proxy-agent.mjs +20 -102
- package/plugins/huaweicloud-core/src/proxy/proxy-config.mjs +11 -4
- package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +4 -1
- package/plugins/huaweicloud-core/src/safety-policy.mjs +123 -68
- package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +48 -12
- package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +25 -26
- package/plugins/huaweicloud-core/src/sandbox/sandbox-file-server.py +45 -0
- package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +943 -10
- package/plugins/huaweicloud-core/src/sandbox/uninstall-cleanup.mjs +50 -0
- package/plugins/huaweicloud-core/src/search-market.mjs +49 -14
- package/plugins/huaweicloud-core/src/setup-cli.mjs +3091 -498
- package/plugins/huaweicloud-core/src/telemetry/agent-detect.mjs +40 -0
- package/plugins/huaweicloud-core/src/telemetry/agent-registry.mjs +328 -0
- package/plugins/huaweicloud-core/src/telemetry/telemetry.mjs +378 -0
- package/plugins/huaweicloud-core/src/tools.mjs +1272 -146
- package/plugins/huaweicloud-core/src/update-check.mjs +383 -0
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-client.js +72 -38
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-fair-queue.js +10 -5
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-multiplexer.js +13 -16
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-packet.js +12 -16
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-terminal-channel.js +46 -31
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-tunnel-channel.mjs +268 -0
- package/plugins/huaweicloud-core/src/ws-exec/index.js +3 -0
- package/plugins/huaweicloud-core/src/ws-exec/ws-exec-client.js +40 -13
- package/plugins/huaweicloud-core/skills/huawei-cloud-find-skills/SKILL.md +0 -190
- package/plugins/huaweicloud-core/skills/huawei-cloud-find-skills/scripts/search-skills.mjs +0 -124
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: huawei-sandbox
|
|
3
|
-
description:
|
|
3
|
+
description: 'Use when creating, connecting, or managing Huawei Cloud Sandbox instances and workspace terminals, or when a task needs a temporary runtime to deploy, run, or preview a web application. Covers sandbox lifecycle (check-user, sign-agreement, connect, release), session-based terminal execution, and credential injection. Triggers on: sandbox, workspace, terminal, web app deployment, deploy web app, preview app, deploy github, github repo, deploy repo, website, static site, web application, hwlink, devstation, hdkitservice, remote exec. NOT for: ECS instances (use huawei-ecs), CCE clusters (use huawei-cce).'
|
|
4
4
|
version: 1
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -26,24 +26,63 @@ Domain expertise for Huawei Cloud Sandbox (DevStation) instances and workspace t
|
|
|
26
26
|
|
|
27
27
|
### User Verification (Prerequisites)
|
|
28
28
|
|
|
29
|
-
| Tool
|
|
30
|
-
|
|
31
|
-
| `huaweicloud_sandbox_check_user`
|
|
29
|
+
| Tool | Purpose |
|
|
30
|
+
| ------------------------------------ | ----------------------------------------------------------- |
|
|
31
|
+
| `huaweicloud_sandbox_check_user` | Check real-name verification and agreement signing status |
|
|
32
32
|
| `huaweicloud_sandbox_sign_agreement` | Sign unsigned/outdated agreements (required before connect) |
|
|
33
33
|
|
|
34
|
+
### Local Detection
|
|
35
|
+
|
|
36
|
+
| Tool | Purpose |
|
|
37
|
+
| ------------------------------ | ---------------------------------------------------------- |
|
|
38
|
+
| `huaweicloud_detect_framework` | Scan local project, return framework type + build commands |
|
|
39
|
+
|
|
34
40
|
### Sandbox Lifecycle
|
|
35
41
|
|
|
36
|
-
| Tool
|
|
37
|
-
|
|
38
|
-
| `huaweicloud_sandbox_connect`
|
|
39
|
-
| `huaweicloud_sandbox_credentials` | Inject temporary AK/SK into a running sandbox
|
|
42
|
+
| Tool | Purpose |
|
|
43
|
+
| --------------------------------- | ------------------------------------------------------------------------ |
|
|
44
|
+
| `huaweicloud_sandbox_connect` | Connect to sandbox (one user one instance, reuses existing if available) |
|
|
45
|
+
| `huaweicloud_sandbox_credentials` | Inject temporary AK/SK into a running sandbox |
|
|
40
46
|
|
|
41
47
|
### Terminal Execution
|
|
42
48
|
|
|
43
|
-
| Tool
|
|
44
|
-
|
|
45
|
-
| `huaweicloud_sandbox_exec_with_session` | Session-based execution (state persists)
|
|
46
|
-
| `
|
|
49
|
+
| Tool | Purpose |
|
|
50
|
+
| --------------------------------------- | --------------------------------------------------------------------------- |
|
|
51
|
+
| `huaweicloud_sandbox_exec_with_session` | Session-based execution (state persists; best for interactive work) |
|
|
52
|
+
| `huaweicloud_sandbox_exec_one_shot` | One-shot execution (fresh connection; best for long/heavy commands) |
|
|
53
|
+
| `huaweicloud_sandbox_upload_file` | Upload a local file into the sandbox (chunked base64 write + md5 verify) |
|
|
54
|
+
| `huaweicloud_sandbox_upload_project` | Upload a local project directory to sandbox (HTTP tunnel, tar.gz + extract) |
|
|
55
|
+
| `huaweicloud_sandbox_deploy_nginx` | Deploy nginx config with permissions fix and reload in one call |
|
|
56
|
+
| `huaweicloud_sandbox_deploy_check` | Run deployment completeness check (nginx, DevBridge, URL, QR if needed) |
|
|
57
|
+
| `huaweicloud_sandbox_close_session` | Close a persistent terminal session |
|
|
58
|
+
|
|
59
|
+
### Tool Selection Guide
|
|
60
|
+
|
|
61
|
+
| Scenario | Use | Why |
|
|
62
|
+
| ---------------------------------- | ---------------------------------- | ------------------------------------------------------------ |
|
|
63
|
+
| `cd`, env setup, command chains | `exec_with_session` | Needs shared shell state across calls |
|
|
64
|
+
| `npm install`, `apt-get`, builds | `exec_one_shot` | Long-running (>30s), no state needed, more stable |
|
|
65
|
+
| `curl`, health checks, quick tests | Either — `exec_one_shot` preferred | Stateless, fast |
|
|
66
|
+
| Server startup (background) | `exec_with_session` | Need to `nohup ... &` then check output in same session |
|
|
67
|
+
| Deployment scripts | `exec_one_shot+shot` | Long script, fresh connection avoids session timeouts |
|
|
68
|
+
| nginx configuration | `deploy_nginx` | Auto-generates correct template + permissions + reload |
|
|
69
|
+
| Deployment completeness check | `deploy_check` | Verifies nginx, DevBridge, URL, QR before reporting success |
|
|
70
|
+
| Single file upload (<1MB) | `upload_file` | Base64 chunked, reliable for small files |
|
|
71
|
+
| Project directory upload (>1MB) | `upload_project` | HTTP tunnel, much faster than base64 for multi-file projects |
|
|
72
|
+
|
|
73
|
+
**Timeout tuning**: default is 120s. For commands expected to run longer (e.g. large builds), pass `timeout_ms` explicitly:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{ "timeout_ms": 300000 }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Session recovery**: if `exec_with_session` returns `session is not ready`, the WebSocket connection has dropped. Do NOT retry the same session — fall back to `exec_one_shot` for that command instead. To recover state (cd, env vars), reconstruct them explicitly in the one-shot command.
|
|
80
|
+
|
|
81
|
+
**Timeout recovery**: if `exec_one_shot` returns a timeout error, check whether partial output is available before declaring failure:
|
|
82
|
+
|
|
83
|
+
- For build commands: check `tail -30 /tmp/build.log` — the build may have completed but the tee pipe didn't flush before timeout
|
|
84
|
+
- For long scripts: split into independent `exec_one_shot` calls (max 5 sub-commands per call, 15s timeout per call)
|
|
85
|
+
- Do NOT retry the same composite command — split and retry individual steps
|
|
47
86
|
|
|
48
87
|
## Workflow
|
|
49
88
|
|
|
@@ -56,10 +95,100 @@ Setup is a **plugin-side preflight** — the developer should be asked a questio
|
|
|
56
95
|
2. **Real-name verification only** (`HDKIT_NOT_REALNAME`): tell the developer once, "Huawei Cloud requires real-name verification before using the sandbox — please complete it in the Huawei Cloud console (实名认证)." and stop — do not retry `connect` in a loop
|
|
57
96
|
3. **Sign agreement only** (`HDKIT_NOT_AGREEMENT`): **STOP and do NOT sign on your own.** Ask the developer: "Huawei Cloud sandbox requires signing the latest developer service agreement. May I sign it for you?" Then **wait for the developer to explicitly agree** (e.g. "签署" / "确认" / "sign it"). Only after explicit consent call `huaweicloud_sandbox_sign_agreement` and return its result (`signed`/`signedCount`) to the developer. **Never sign a legal agreement on the developer's behalf without their explicit, unambiguous consent.** Do not expose the underlying sandbox/DevBridge service as a separate entity the developer must understand or sign up for
|
|
58
97
|
4. **Both missing** (`HDKIT_NOT_REALNAME_AND_AGREEMENT`): present **both** requirements together in one message — the real-name verification steps (console, step 2) **and** the agreement-signing request (step 3, wait for explicit consent) — so the developer can complete both at once
|
|
59
|
-
5. **Connect**: `huaweicloud_sandbox_connect` — returns `session_id`, `dev_stage_id`, `connection_id`, `connection_address`
|
|
60
|
-
6. **
|
|
61
|
-
|
|
62
|
-
|
|
98
|
+
5. **Connect**: `huaweicloud_sandbox_connect` — returns `session_id`, `dev_stage_id`, `connection_id`, `connection_address`. The `source` parameter identifies the calling agent (valid values: `CLI`, `WEB`, `VSCODE`, `WEBVNC`, `WEBPTY`, `WEBIDE`, `CURSOR`, etc. — case-sensitive, all uppercase). When the `git` parameter is provided (with `repo_url`, `target_path`, optional `repo_branch`), code is automatically transferred to the sandbox: local `git clone` followed by `uploadProject` (falls back to direct sandbox clone when local git is unavailable). Check `_repoStatus` in the response: `uploaded_from_local`, `cloned_in_sandbox`, or `already_exists` (reconnect).
|
|
99
|
+
6. **Cleanup previous deployments** (after first connect to a sandbox): nginx configs, DevBridge tunnels, and stale web processes from previous deployments can cause port conflicts and quota errors. Run cleanup immediately after connect:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Kill stale Node.js web processes from previous deployments
|
|
103
|
+
pkill -9 -f "next-server" 2>/dev/null || true
|
|
104
|
+
pkill -9 -f "next start" 2>/dev/null || true
|
|
105
|
+
pkill -9 -f "nuxt" 2>/dev/null || true
|
|
106
|
+
sleep 1
|
|
107
|
+
# Remove stale nginx configs from previous deployments
|
|
108
|
+
sudo rm -f /etc/nginx/conf.d/*.conf /etc/nginx/conf.d/*.conf.bak 2>/dev/null
|
|
109
|
+
# Remove stale DevBridge tunnels
|
|
110
|
+
devbridge delete-all 2>/dev/null || true
|
|
111
|
+
# Reload nginx to apply
|
|
112
|
+
sudo nginx -s reload 2>/dev/null || true
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
7. **Inject credentials** (optional): `huaweicloud_sandbox_credentials` — enables cloud API access from sandbox. After injection, credentials are also written to `/tmp/hw_creds.sh` for shell access:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Source credentials in any sandbox shell before using hcloud/devbridge:
|
|
119
|
+
source /tmp/hw_creds.sh 2>/dev/null && echo "Credentials loaded"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
If `source /tmp/hw_creds.sh` returns empty, the credentials injection may not have completed — re-run `huaweicloud_sandbox_credentials`.
|
|
123
|
+
|
|
124
|
+
8. **Execute commands**: use `huaweicloud_sandbox_exec_with_session` for interactive work (cd, env setup), or `huaweicloud_sandbox_exec_one_shot` for long-running builds/installs. See [Tool Selection Guide](#tool-selection-guide).
|
|
125
|
+
9. **Upload project** (if deploying local code): `huaweicloud_sandbox_upload_project` to transfer a local project directory into `/workspace/<name>` — uses HTTP tunnel, much faster than base64 for multi-file projects. Use `huaweicloud_sandbox_upload_file` for single files.
|
|
126
|
+
10. **Expose the deployed app and return the public URL**: set up a public access link for the app port and give the URL to the developer as the final result (see "Expose the deployed app (public URL)") — this step uses an internal tunnel mechanism that must never be mentioned to the developer
|
|
127
|
+
|
|
128
|
+
## File Transfer (local → sandbox)
|
|
129
|
+
|
|
130
|
+
### upload_project (preferred for directories)
|
|
131
|
+
|
|
132
|
+
`huaweicloud_sandbox_upload_project` packages a local directory as tar.gz, uploads it to the sandbox via HTTP tunnel, and extracts it. This is the fastest way to transfer multi-file projects.
|
|
133
|
+
|
|
134
|
+
**Prerequisites**: sandbox must already be connected (`sandbox_connect` called first). The tool handles everything internally — no manual setup needed.
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"local_dir": "/path/to/local/project",
|
|
139
|
+
"remote_dir": "/workspace",
|
|
140
|
+
"extract": true,
|
|
141
|
+
"exclude": [
|
|
142
|
+
"**/node_modules",
|
|
143
|
+
".git",
|
|
144
|
+
"__pycache__",
|
|
145
|
+
".next",
|
|
146
|
+
".nuxt",
|
|
147
|
+
".output",
|
|
148
|
+
".turbo",
|
|
149
|
+
".cache",
|
|
150
|
+
".swc",
|
|
151
|
+
"dist",
|
|
152
|
+
"coverage",
|
|
153
|
+
"*.pyc"
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- `local_dir` (required): local project directory
|
|
159
|
+
- `remote_dir` (optional, default `/workspace`): parent directory on sandbox
|
|
160
|
+
- `extract` (optional, default `true`): extract tar.gz after upload
|
|
161
|
+
- `exclude` (optional): patterns to exclude from archive. **For web apps, always exclude dependency directories** (`node_modules`, `.next`, `.nuxt`, `.output`, `.turbo`, `.cache`) — these will be re-installed/built in the sandbox.
|
|
162
|
+
- Result includes `md5` and `md5Verified` for integrity check
|
|
163
|
+
|
|
164
|
+
### upload_file (for single files)
|
|
165
|
+
|
|
166
|
+
`huaweicloud_sandbox_upload_file` (local_path → remote_path) uploads a local file by base64-encoding it and writing it in small chunks through the terminal session, then decoding and verifying the md5 checksum. Use it for individual files, especially small ones (<1MB).
|
|
167
|
+
|
|
168
|
+
### Exec channel size limit
|
|
169
|
+
|
|
170
|
+
`huaweicloud_sandbox_exec_with_session` and `huaweicloud_sandbox_exec_one_shot` are fragile for long commands and large inline content. Do NOT paste a file's base64 directly into a single command:
|
|
171
|
+
|
|
172
|
+
| Payload | Result |
|
|
173
|
+
| --------------------------- | -------------------------------------- |
|
|
174
|
+
| ~30KB base64 in one command | exec timeout |
|
|
175
|
+
| ~12KB base64 in one command | session crash (`session is not ready`) |
|
|
176
|
+
| ~4–5KB normal command | OK |
|
|
177
|
+
|
|
178
|
+
Keep individual exec commands small (≤ ~4KB). For larger content, use `huaweicloud_sandbox_upload_file` instead.
|
|
179
|
+
|
|
180
|
+
### OBS transfer fallback
|
|
181
|
+
|
|
182
|
+
When the upload tool is unavailable, transfer through OBS: upload to a public-read object locally, then pull it into the sandbox.
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Local: upload to OBS (public read)
|
|
186
|
+
hcloud OBS cp <local-file> obs://<bucket>/<key> -f -acl=public-read
|
|
187
|
+
# Sandbox: pull it down
|
|
188
|
+
curl -s -o /workspace/<repo>/<file> https://<bucket>.obs.<region>.myhuaweicloud.com/<key>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
> Requires OBS credentials (`huaweicloud_setup_obs_config`). Bucket ACL does not cascade to objects — set object-level `-acl=public-read` for anonymous reads.
|
|
63
192
|
|
|
64
193
|
## Expose the deployed app (public URL)
|
|
65
194
|
|
|
@@ -70,49 +199,652 @@ Expose a deployed web app to a public URL and return that URL to the developer.
|
|
|
70
199
|
**Install** (internal tooling; skip if `devbridge version` already works):
|
|
71
200
|
|
|
72
201
|
```bash
|
|
73
|
-
|
|
202
|
+
if command -v devbridge >/dev/null 2>&1; then
|
|
203
|
+
echo "devbridge already installed"
|
|
204
|
+
else
|
|
205
|
+
curl -fsSL https://res-hd.hc-cdn.cn/sharedata/hdspace/devbridge/install.sh | bash
|
|
206
|
+
fi
|
|
74
207
|
export PATH=$PATH:$HOME/.huawei/bin # installer only writes ~/.bashrc; session shells do not re-source it
|
|
75
208
|
```
|
|
76
209
|
|
|
77
|
-
**Login** (non-interactive
|
|
210
|
+
**Login** (non-interactive; credentials from `huaweicloud_sandbox_credentials` are available via `/tmp/hw_creds.sh`). If `source /tmp/hw_creds.sh` returns empty, the credentials injection has expired (sandbox session reconnection resets them) — re-run `huaweicloud_sandbox_credentials` first:
|
|
78
211
|
|
|
79
212
|
```bash
|
|
80
|
-
|
|
213
|
+
source /tmp/hw_creds.sh 2>/dev/null
|
|
214
|
+
devbridge auth login --huaweicloud --access-key "$HW_ACCESS_KEY" --secret-key "$HW_SECRET_KEY"
|
|
81
215
|
```
|
|
82
216
|
|
|
83
217
|
- The `--huaweicloud` flag is required for AK/SK login; without it the CLI tries an interactive browser login, which fails in the sandbox.
|
|
84
|
-
-
|
|
218
|
+
- Credentials are stored in `/tmp/hw_creds.sh` (chmod 600) — source it before login, never echo the values.
|
|
219
|
+
- Verify with `devbridge auth status`. If `$HW_ACCESS_KEY` is empty, ensure `huaweicloud_sandbox_credentials` was called first.
|
|
85
220
|
|
|
86
221
|
**Expose** (run the web server and the tunnel in the background, then read the URL from the log; the app lives in the workspace mount, e.g. `/workspace/<repo-name>`):
|
|
87
222
|
|
|
88
223
|
```bash
|
|
89
|
-
|
|
90
|
-
|
|
224
|
+
# 0. Pre-cleanup: kill old processes and stale tunnels
|
|
225
|
+
pkill -f "devbridge host" 2>/dev/null || true
|
|
226
|
+
sleep 2
|
|
227
|
+
devbridge delete-all 2>/dev/null || true
|
|
228
|
+
|
|
229
|
+
# 1. Start tunnel
|
|
230
|
+
nohup devbridge host -p <port> -e 8 > /tmp/host.log 2>&1 &
|
|
91
231
|
sleep 10 && cat /tmp/host.log
|
|
232
|
+
|
|
233
|
+
# 2. Extract tunnel URL and health-check before returning
|
|
234
|
+
TUNNEL_URL=$(grep -oP 'Tunnel URL: \K.*' /tmp/host.log)
|
|
235
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$TUNNEL_URL" 2>/dev/null || echo "000")
|
|
236
|
+
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "304" ]; then
|
|
237
|
+
echo "Tunnel verified: $TUNNEL_URL (HTTP $HTTP_CODE)"
|
|
238
|
+
else
|
|
239
|
+
echo "WARN: Tunnel URL unreachable (HTTP $HTTP_CODE). Rebuilding tunnel..."
|
|
240
|
+
pkill -f "devbridge host" && sleep 2
|
|
241
|
+
devbridge delete-all 2>/dev/null || true
|
|
242
|
+
nohup devbridge host -p <port> -e 8 > /tmp/host.log 2>&1 &
|
|
243
|
+
sleep 10
|
|
244
|
+
TUNNEL_URL=$(grep -oP 'Tunnel URL: \K.*' /tmp/host.log)
|
|
245
|
+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$TUNNEL_URL" 2>/dev/null || echo "000")
|
|
246
|
+
echo "Retry tunnel: $TUNNEL_URL (HTTP $HTTP_CODE)"
|
|
247
|
+
fi
|
|
92
248
|
```
|
|
93
249
|
|
|
250
|
+
**Never return a tunnel URL without verifying it first** — a stale URL (from a killed tunnel process) will silently fail. Always curl-check before giving the URL to the developer.
|
|
251
|
+
|
|
252
|
+
**Quota recovery**: if the tunnel creation fails with `10006: quota exceeded`:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Step A: List all tunnels (both active and stale)
|
|
256
|
+
devbridge list -j
|
|
257
|
+
# Step B: Remove all stale tunnels
|
|
258
|
+
devbridge delete-all
|
|
259
|
+
# Step C: Retry tunnel creation
|
|
260
|
+
nohup devbridge host -p <port> -e 8 > /tmp/host.log 2>&1 &
|
|
261
|
+
sleep 10 && cat /tmp/host.log
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
This eliminates the most common deployment failure — historical tunnels from previous sessions accumulating past the max=10 quota.
|
|
265
|
+
|
|
94
266
|
- The public URL has the form `https://<id>-<port>.cn-north-4-bridge.myhuaweicloud.com` (from the `Tunnel URL:` line).
|
|
95
267
|
- **Return this URL to the developer as the deployment result link.** Keep the host process running (do not close the session before handing over the URL).
|
|
268
|
+
- Tunnel `description` (`-d`) accepts only Chinese characters, letters, and digits (0-64). Symbols such as `-`/`_`/spaces are rejected (`Invalid tunnel description`).
|
|
96
269
|
- Internal docs: https://huaweicloud.github.io/devspace-devbridge/
|
|
97
270
|
|
|
98
271
|
**No local downgrade**: if the tunnel tooling cannot be installed in the sandbox, STOP and report a generic error ("无法生成访问地址") without technical detail. Never install it on the developer's local machine — a local install would defeat the purpose of sandbox deployment.
|
|
99
272
|
|
|
273
|
+
## Web Application Deployment
|
|
274
|
+
|
|
275
|
+
When deploying a web application to the sandbox, build the app inside the sandbox before exposing it. Source code is uploaded, dependencies installed, and the framework built in the sandbox environment.
|
|
276
|
+
|
|
277
|
+
### Step 1: Detect Framework Locally
|
|
278
|
+
|
|
279
|
+
**Always call `huaweicloud_detect_framework` first** before connecting to the sandbox. It scans the local project and returns:
|
|
280
|
+
|
|
281
|
+
- `type`: `spa` | `ssr` | `ssg` | `cross-platform` | `monorepo` | `static`
|
|
282
|
+
- `framework`: framework name
|
|
283
|
+
- `packageManager`: `npm` | `yarn` | `pnpm`
|
|
284
|
+
- `installCmd` / `buildCmd` / `outputDir` / `port`
|
|
285
|
+
- For SSR: also `serveCmd` and `checkUrl`
|
|
286
|
+
- For nginx: `nginxType` (`spa` | `proxy` | `static`)
|
|
287
|
+
- For Monorepo: `subApps` list with individual framework detection
|
|
288
|
+
|
|
289
|
+
If detection returns `null`, the project is not a recognized web app. Stop and tell the developer.
|
|
290
|
+
|
|
291
|
+
If detection returns `type: "monorepo"`, show the `subApps` list to the developer and ask which sub-app to deploy. Then re-detect that sub-app's framework.
|
|
292
|
+
|
|
293
|
+
### Step 2: Connect and Upload
|
|
294
|
+
|
|
295
|
+
Follow the standard [Workflow](#workflow) steps 1-6 to connect to the sandbox, then:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"local_dir": "<projectPath>",
|
|
300
|
+
"remote_dir": "/workspace",
|
|
301
|
+
"exclude": [
|
|
302
|
+
"**/node_modules",
|
|
303
|
+
".git",
|
|
304
|
+
"__pycache__",
|
|
305
|
+
".next",
|
|
306
|
+
".nuxt",
|
|
307
|
+
".output",
|
|
308
|
+
".turbo",
|
|
309
|
+
".cache",
|
|
310
|
+
".swc",
|
|
311
|
+
"dist",
|
|
312
|
+
"coverage",
|
|
313
|
+
"*.pyc"
|
|
314
|
+
]
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Always exclude build artifacts and dependency directories** — they will be re-installed/built inside the sandbox:
|
|
319
|
+
|
|
320
|
+
| Pattern | Why excluded |
|
|
321
|
+
| ----------------- | ---------------------------------------------- |
|
|
322
|
+
| `**/node_modules` | Dependencies — reinstall in sandbox |
|
|
323
|
+
| `.git` | Version control — not needed for deployment |
|
|
324
|
+
| `__pycache__` | Python bytecode cache |
|
|
325
|
+
| `.next` | Next.js build output — rebuild in sandbox |
|
|
326
|
+
| `.nuxt` | Nuxt build cache — rebuild in sandbox |
|
|
327
|
+
| `.output` | Nuxt production output — rebuild in sandbox |
|
|
328
|
+
| `.turbo` | Turborepo cache — re-run in sandbox |
|
|
329
|
+
| `.cache` | Generic tool cache (Parcel, Storybook, etc.) |
|
|
330
|
+
| `.swc` | Taro/Webpack SWC cache — regenerate in sandbox |
|
|
331
|
+
| `dist` | Build output — rebuild in sandbox |
|
|
332
|
+
| `coverage` | Test coverage reports — not needed for deploy |
|
|
333
|
+
| `*.pyc` | Python compiled files |
|
|
334
|
+
|
|
335
|
+
**Post-upload permission fix**: after `upload_project` extracts the project, fix file permissions lost during transfer (native binaries from other platforms, .bin symlinks):
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
# Fix executable permissions on node_modules/.bin (lost during cross-platform transfer)
|
|
339
|
+
chmod -R +x /workspace/<dirname>/node_modules/.bin 2>/dev/null || true
|
|
340
|
+
# Fix world-read on all files (sandbox default umask may restrict)
|
|
341
|
+
chmod -R o+rX /workspace/<dirname> 2>/dev/null || true
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Step 3: Sandbox Environment Readiness
|
|
345
|
+
|
|
346
|
+
Install OS-level dependencies **before** uploading the project (independent of project code, can run in parallel if desired).
|
|
347
|
+
|
|
348
|
+
#### 3a: Detect OS and package manager
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
source /etc/os-release 2>/dev/null
|
|
352
|
+
echo "OS_DETECTED=${ID:-unknown}|${ID_LIKE:-}"
|
|
353
|
+
if command -v apt-get >/dev/null 2>&1; then echo "PKG_MGR=apt"; elif command -v yum >/dev/null 2>&1; then echo "PKG_MGR=yum"; elif command -v dnf >/dev/null 2>&1; then echo "PKG_MGR=dnf"; elif command -v apk >/dev/null 2>&1; then echo "PKG_MGR=apk"; else echo "PKG_MGR=unknown"; fi
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Use the detected `PKG_MGR` for all package installations below.
|
|
357
|
+
|
|
358
|
+
**Architecture awareness**: the sandbox runs Linux aarch64 (ARM64). Native binaries built on x64 (Windows/macOS Intel) will not execute. Always install dependencies and build inside the sandbox. For projects with native addons (Taro `@swc/core`, Prisma, `esbuild`, `node-gyp`), local x64 pre-build + upload of `dist/` output is a viable alternative when sandbox builds fail.
|
|
359
|
+
|
|
360
|
+
**GitCode SSL**: if `git clone` from GitCode fails with SSL certificate errors, use a one-shot override (do NOT set it globally — that would disable cert verification for every repo):
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
git -c http.sslVerify=false clone <repo-url>
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Then retry the clone. This bypasses SSL verification only for this single clone.
|
|
367
|
+
|
|
368
|
+
#### 3b: Install nginx (before project upload)
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
# Use the detected PKG_MGR from step 3a
|
|
372
|
+
case "$PKG_MGR" in
|
|
373
|
+
apt) sudo apt-get update -qq && sudo apt-get install -y -qq nginx ;;
|
|
374
|
+
yum) sudo yum install -y nginx ;;
|
|
375
|
+
dnf) sudo dnf install -y nginx ;;
|
|
376
|
+
esac
|
|
377
|
+
sudo nginx -t && echo "nginx: ready"
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
If nginx cannot be installed, skip to Python HTTP server fallback (see `references/nginx-templates.md`).
|
|
381
|
+
|
|
382
|
+
#### 3c: Verify remaining tools
|
|
383
|
+
|
|
384
|
+
Before installing project dependencies, verify the sandbox has the required runtime tools. **Run each check as a separate `exec_one_shot` call with 15s timeout** — do not bundle all checks into one command. A single hung subcommand (e.g., `make --version` or `hugo version`) will timeout the entire check, blocking deployment:
|
|
385
|
+
|
|
386
|
+
```
|
|
387
|
+
Check 1: node --version (timeout: 15s)
|
|
388
|
+
Check 2: npm --version (timeout: 15s)
|
|
389
|
+
Check 3: nginx -v 2>&1 (timeout: 15s)
|
|
390
|
+
Check 4: git --version (timeout: 15s)
|
|
391
|
+
Check 5: python3 --version (timeout: 15s)
|
|
392
|
+
Check 6: curl --version | head -1 (timeout: 15s)
|
|
393
|
+
Check 7: wget --version | head -1 (timeout: 15s)
|
|
394
|
+
Check 8: make --version | head -1 (timeout: 15s)
|
|
395
|
+
Check 9: pnpm --version (timeout: 15s)
|
|
396
|
+
Check 10: yarn --version (timeout: 15s)
|
|
397
|
+
Check 11: hugo version (timeout: 15s)
|
|
398
|
+
Check 12: devbridge version (timeout: 15s)
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
For each check, parse the output: if stdout contains `MISSING:` or the tool wasn't found, install it. **Skip framework-specific tools not needed for the current project** (e.g., skip Hugo for React apps).
|
|
402
|
+
|
|
403
|
+
**Install only missing tools** — parse the pre-flight output and install only tools reported as `MISSING`. Use OS-aware commands:
|
|
404
|
+
|
|
405
|
+
| Missing Tool | Install Command (apt) | Install Command (yum/dnf) |
|
|
406
|
+
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
|
|
407
|
+
| Node.js | Follow [Node.js in the sandbox](#nodejs-in-the-sandbox) | Same |
|
|
408
|
+
| nginx | `sudo apt-get update -qq && sudo apt-get install -y -qq nginx` | `sudo yum install -y nginx` |
|
|
409
|
+
| curl | `sudo apt-get update -qq && sudo apt-get install -y -qq curl` | `sudo yum install -y curl` |
|
|
410
|
+
| wget | `sudo apt-get update -qq && sudo apt-get install -y -qq wget` | `sudo yum install -y wget` |
|
|
411
|
+
| make | `sudo apt-get update -qq && sudo apt-get install -y -qq make` | `sudo yum install -y make` |
|
|
412
|
+
| pnpm | `npm i -g pnpm` | Same |
|
|
413
|
+
| yarn | `npm i -g yarn` | Same |
|
|
414
|
+
| Hugo | `curl -fsSL https://github.com/gohugoio/hugo/releases/download/v0.140.0/hugo_extended_0.140.0_linux-amd64.tar.gz -o /tmp/hugo.tar.gz && sudo tar -xzf /tmp/hugo.tar.gz -C /usr/local/bin hugo && rm /tmp/hugo.tar.gz` | Same |
|
|
415
|
+
| DevBridge | `curl -fsSL https://res-hd.hc-cdn.cn/sharedata/hdspace/devbridge/install.sh \| bash && export PATH=$PATH:$HOME/.huawei/bin` | Same |
|
|
416
|
+
|
|
417
|
+
**If Node.js is missing**, install it first — all build workflows depend on it. Stop and report to the developer if Node.js installation fails.
|
|
418
|
+
|
|
419
|
+
### Step 4: Install and Build
|
|
420
|
+
|
|
421
|
+
#### 4a: Inject Environment Variables
|
|
422
|
+
|
|
423
|
+
Before any project commands, parse `.env*` files and inject them into the shell environment. Prisma, Drizzle, and other ORM/database tools do NOT auto-read framework-level env files:
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
cd /workspace/<dirname>
|
|
427
|
+
# Load env files if present (most specific first)
|
|
428
|
+
for f in .env.local .env.development.local .env.development .env; do
|
|
429
|
+
if [ -f "$f" ]; then
|
|
430
|
+
set -a && source "$f" 2>/dev/null; set +a
|
|
431
|
+
echo "Loaded env: $f"
|
|
432
|
+
fi
|
|
433
|
+
done
|
|
434
|
+
# Verify key variables for common tools
|
|
435
|
+
echo "DATABASE_URL=${DATABASE_URL:-<NOT SET>}"
|
|
436
|
+
echo "NODE_ENV=${NODE_ENV:-development}"
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
This must run via `exec_with_session` so the exported variables persist for subsequent build commands in the same session.
|
|
440
|
+
|
|
441
|
+
**Prisma / ORM compatibility**: Prisma CLI (`prisma generate`, `prisma db push`, `prisma migrate`) only reads `.env` by default, NOT `.env.local` or `.env.development`. If the project uses `.env.local` for `DATABASE_URL`, link it before any Prisma command:
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Prisma requires .env (not .env.local) — symlink if needed
|
|
445
|
+
if [ -f .env.local ] && [ ! -f .env ]; then ln -sf .env.local .env 2>/dev/null || cp .env.local .env; fi
|
|
446
|
+
# Then re-source
|
|
447
|
+
set -a && source .env 2>/dev/null; set +a
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### 4b: Install Dependencies
|
|
451
|
+
|
|
452
|
+
Use `exec_one_shot` for install (no shared state needed). Skip if `node_modules` already exists:
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
cd /workspace/<dirname> && [ -d node_modules ] && echo "SKIP: node_modules exists" || <installCmd>
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Wait for install to complete. For large projects on aarch64 sandboxes (1000+ packages), set `timeout_ms` to 180000 (3 min).
|
|
459
|
+
|
|
460
|
+
**Node version compatibility**: if `npm install` fails with native module errors (e.g., `rollup 4`, `@esbuild`, `node-gyp`), check the Node version:
|
|
461
|
+
|
|
462
|
+
```bash
|
|
463
|
+
node -v
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Node v24+ uses musl-based binaries on some sandbox images, which may break native addons built for glibc. If native modules fail:
|
|
467
|
+
|
|
468
|
+
- Try `npm install --force` or `npm install --legacy-peer-deps`
|
|
469
|
+
- For rollup 4 projects, consider `npm install rollup@3` as fallback
|
|
470
|
+
- If webpack/rollup native addon errors persist, add `--ignore-scripts` then manually rebuild: `npm rebuild`
|
|
471
|
+
|
|
472
|
+
**Prisma / database initialization**: if `prisma/schema.prisma` exists in the project, initialize the database after install and before build. Prisma Client generation (`prisma generate`) is usually handled by `postinstall`, but `prisma db push` (SQLite) or `prisma migrate deploy` (PostgreSQL/MySQL) must be run manually:
|
|
473
|
+
|
|
474
|
+
```bash
|
|
475
|
+
cd /workspace/<dirname>
|
|
476
|
+
if [ -f prisma/schema.prisma ]; then
|
|
477
|
+
echo "Prisma schema detected — initializing database..."
|
|
478
|
+
npx prisma db push --skip-generate 2>/dev/null || npx prisma migrate deploy 2>/dev/null || echo "WARN: skip db init"
|
|
479
|
+
fi
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
> `--skip-generate` avoids redundant generation when `postinstall` already ran `prisma generate`. For SQLite, `DATABASE_URL="file:./dev.db"` must be set in `.env`/`.env.local` before this step.
|
|
483
|
+
|
|
484
|
+
#### 4c: Build
|
|
485
|
+
|
|
486
|
+
**Timeout strategy by framework type:**
|
|
487
|
+
|
|
488
|
+
| Type | timeout_ms | Rationale |
|
|
489
|
+
| ------------------------------ | --------------- | ------------------------------------- |
|
|
490
|
+
| SPA / SSG | 300000 (5 min) | Vite/Webpack builds typically < 3 min |
|
|
491
|
+
| Cross-platform (Taro, uni-app) | 900000 (15 min) | Webpack5 H5 slow on aarch64, 7-8 min |
|
|
492
|
+
| SSR (Next.js, Nuxt) | 600000 (10 min) | Full-stack compilation + SSG pages |
|
|
493
|
+
| Monorepo | 600000 (10 min) | Multiple apps, shared packages |
|
|
494
|
+
| `null` (no build) | N/A | Skip |
|
|
495
|
+
|
|
496
|
+
**Build with `exec_one_shot`:**
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
cd /workspace/<dirname> && [ -d <outputDir> ] && echo "SKIP: <outputDir> exists" || (umask 022 && <buildCmd> 2>&1 | tee /tmp/build.log)
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
Always pipe build output through `tee /tmp/build.log` — captures stderr+stdout so diagnostics are available even if the command times out.
|
|
503
|
+
|
|
504
|
+
**OutDir verification**: before building for the first time, check the project's actual output directory (not just the default from framework detection). Projects can override outDir in config (e.g., VitePress `outDir: '../dist'`):
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
# Check for custom outDir in common config files
|
|
508
|
+
grep -r "outDir\|outputDir\|dest\|distDir" /workspace/<dirname>/.vitepress/config.* 2>/dev/null || true
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
If a custom outDir is found, use that instead of the framework-detected default for all subsequent checks.
|
|
512
|
+
|
|
513
|
+
**Post-build output verification**: after a successful build, verify the actual `index.html` location. Framework-returned `outputDir` may be inaccurate — either a subdirectory (e.g., uni-app v3: `dist` → `dist/build/h5`) or a completely different top-level path (e.g., Vite `build.outDir` pointing to `portal/public`). Search the whole project (skipping `node_modules`), not just `<outputDir>`:
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
# Find the real index.html after build (search whole project, not just the default outputDir)
|
|
517
|
+
REAL_INDEX=$(find /workspace/<dirname> -path '*/node_modules' -prune -o -name index.html -type f -print 2>/dev/null | head -1)
|
|
518
|
+
if [ -n "$REAL_INDEX" ] && [ -f "$REAL_INDEX" ]; then
|
|
519
|
+
REAL_OUTDIR=$(dirname "$REAL_INDEX")
|
|
520
|
+
echo "Actual output dir: $REAL_OUTDIR"
|
|
521
|
+
# Use REAL_OUTDIR for nginx config instead of framework-reported outputDir
|
|
522
|
+
fi
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
If `REAL_OUTDIR` differs from `<outputDir>`, use `REAL_OUTDIR` for all subsequent steps (nginx config, port check, etc.).
|
|
526
|
+
|
|
527
|
+
**Post-timeout recovery**: if `exec_one_shot` returns a timeout error (Request timed out), do NOT fail immediately. First dump any captured build log, then check the output directory:
|
|
528
|
+
|
|
529
|
+
```bash
|
|
530
|
+
# If timeout occurred, show captured output and verify build
|
|
531
|
+
if timeout_error; then
|
|
532
|
+
echo "=== Build log (tail) ==="
|
|
533
|
+
tail -30 /tmp/build.log 2>/dev/null
|
|
534
|
+
echo "=== Checking output ==="
|
|
535
|
+
if [ -d <outputDir> ] && [ "$(ls -A <outputDir> 2>/dev/null)" ]; then
|
|
536
|
+
# Verify at least one key output file exists (not just empty dir from broken build)
|
|
537
|
+
if [ -f <outputDir>/index.html ] || [ -f <outputDir>/server.js ] || [ -f <outputDir>/app.js ]; then
|
|
538
|
+
echo "Build output detected despite timeout — continuing with deployment"
|
|
539
|
+
else
|
|
540
|
+
echo "ERROR: Output directory exists but missing expected files (index.html/server.js). Build may have failed silently."
|
|
541
|
+
echo "Full log: /tmp/build.log"
|
|
542
|
+
exit 1
|
|
543
|
+
fi
|
|
544
|
+
else
|
|
545
|
+
echo "ERROR: Build did not complete. Output directory empty or missing."
|
|
546
|
+
echo "Full log: /tmp/build.log"
|
|
547
|
+
exit 1
|
|
548
|
+
fi
|
|
549
|
+
fi
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
For SSR frameworks, also verify the server entry point exists: `test -f <outputDir>/server.js || test -f node_modules/next/dist/server/next-server.js`.
|
|
553
|
+
|
|
554
|
+
**Build progress visibility**: for very large builds, touch a marker file before starting and use `exec_with_session` to poll intermediate logs:
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
# Before build:
|
|
558
|
+
touch /tmp/build-start && echo "Build started at $(date)"
|
|
559
|
+
|
|
560
|
+
# During build via exec_with_session (separate call for polling):
|
|
561
|
+
cat .next/trace 2>/dev/null | tail -5 # Next.js build trace
|
|
562
|
+
# or
|
|
563
|
+
tail -5 /tmp/build.log 2>/dev/null
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
- `cd /workspace/<dirname>/<subAppPath>` for Monorepo sub-apps.
|
|
567
|
+
- For `pnpm` projects, `node_modules` may be at the workspace root. Check both the sub-app dir and the workspace root.
|
|
568
|
+
- For Hugo/static sites where `installCmd` is `null`, skip install entirely.
|
|
569
|
+
- For static sites where `buildCmd` is `null`, skip build entirely.
|
|
570
|
+
|
|
571
|
+
#### 4c-aux: Build Failure Response
|
|
572
|
+
|
|
573
|
+
Build failures fall into two categories. Handle them differently:
|
|
574
|
+
|
|
575
|
+
| Failure Type | Behavior |
|
|
576
|
+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
577
|
+
| **Timeout** (timed out) | Check `/tmp/build.log` tail and output directory — build may have completed but `tee` pipe didn't flush. See Post-timeout recovery above. |
|
|
578
|
+
| **Non-zero exit code** | **STOP immediately.** The build engine explicitly rejected the output. Do NOT retry, modify source, or tweak env vars. Follow the procedure below. |
|
|
579
|
+
|
|
580
|
+
**When a build exits with non-zero exit code:**
|
|
581
|
+
|
|
582
|
+
1. **STOP** — do NOT retry, do NOT modify source code, do NOT change environment variables
|
|
583
|
+
2. **Extract the error** from `/tmp/build.log`:
|
|
584
|
+
```bash
|
|
585
|
+
tail -30 /tmp/build.log
|
|
586
|
+
```
|
|
587
|
+
3. **Present the failure to the developer** with:
|
|
588
|
+
- The app name and build command that failed
|
|
589
|
+
- The key error message (last meaningful lines from the build log)
|
|
590
|
+
- A brief diagnosis of the likely cause
|
|
591
|
+
4. **Offer fix options** (1-3 choices) and **wait for the developer to choose** before applying any fix:
|
|
592
|
+
- Never modify project source files (configs, scripts, etc.) without explicit approval
|
|
593
|
+
- If the fix requires editing source code, tell the developer what to change and where
|
|
594
|
+
5. **After the developer selects a fix**, apply it, then restart only the failed build — do NOT rebuild already-succeeded apps
|
|
595
|
+
|
|
596
|
+
| Rule | Rationale |
|
|
597
|
+
| ---------------------- | -------------------------------------------------------------- |
|
|
598
|
+
| No blind retry | Retrying without diagnosis wastes time and obscures real error |
|
|
599
|
+
| No silent source edits | Modifying project files without consent destroys trust |
|
|
600
|
+
| Developer decides fix | Different projects have different fix preferences |
|
|
601
|
+
| Only rebuild failed | Avoid redundant work in monorepo deployments |
|
|
602
|
+
|
|
603
|
+
**Monorepo-specific**: if one sub-app build fails while others succeed, report the failure immediately — do NOT delay until all builds complete. Continue other builds in parallel if possible, but notify the developer as soon as a failure is detected.
|
|
604
|
+
|
|
605
|
+
#### 4d: Fix Build Output Permissions
|
|
606
|
+
|
|
607
|
+
After a successful build, fix directory traverse permissions on the build output. Build tools (webpack, vite, uni-app) may create directories with restrictive permissions that block nginx from traversing to `index.html`. **Always resolve symlinks first** — `chmod` does not follow symlinks on Linux:
|
|
608
|
+
|
|
609
|
+
```bash
|
|
610
|
+
# Fix directory execute permissions for nginx traverse
|
|
611
|
+
REAL_OUTDIR="<outputDir>" # use actual output dir from post-build verification
|
|
612
|
+
PROJECT_ROOT="/workspace/<dirname>"
|
|
613
|
+
|
|
614
|
+
# Resolve symlinks — monorepo sub-apps may be symlinked
|
|
615
|
+
REAL_ROOT=$(readlink -f "$PROJECT_ROOT" 2>/dev/null || echo "$PROJECT_ROOT")
|
|
616
|
+
REL_OUTDIR=$(echo "$REAL_OUTDIR" | sed "s|$PROJECT_ROOT/||")
|
|
617
|
+
REAL_OUTDIR="${REAL_ROOT}/${REL_OUTDIR}"
|
|
618
|
+
|
|
619
|
+
# Fix permissions on resolved real paths
|
|
620
|
+
find "$REAL_ROOT" -path "*/${REAL_OUTDIR}" -prune -o -type d -exec chmod o+x {} \; 2>/dev/null || true
|
|
621
|
+
chmod -R o+rX "$REAL_ROOT" 2>/dev/null || true
|
|
622
|
+
chmod -R +x "$REAL_ROOT/node_modules/.bin" 2>/dev/null || true
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
This prevents the most common deployment failure: nginx 500 with `stat() ... Permission denied` caused by missing `o+x` on intermediate directories.
|
|
626
|
+
|
|
627
|
+
#### 4e: Write Deployment Fingerprint
|
|
628
|
+
|
|
629
|
+
After a successful build, write a deployment fingerprint into the output directory. This enables `deploy_check` to verify the nginx-served content belongs to the current deployment (not a stale process from an earlier session):
|
|
630
|
+
|
|
631
|
+
```bash
|
|
632
|
+
echo "deployed-$(date +%s)-<dirname>" > /workspace/<dirname>/<outputDir>/.deploy_fingerprint
|
|
633
|
+
chmod o+r /workspace/<dirname>/<outputDir>/.deploy_fingerprint 2>/dev/null || true
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
> For SSR proxy type, nginx does not serve static files from `.next` — the fingerprint check will gracefully SKIP in `deploy_check`. The fingerprint is still written as a deployment marker for debugging.
|
|
637
|
+
|
|
638
|
+
### Step 5: Port Availability Check
|
|
639
|
+
|
|
640
|
+
**Before configuring nginx or starting the app**, verify the target ports are free. Port conflicts from previous deployments cause silent failures:
|
|
641
|
+
|
|
642
|
+
```bash
|
|
643
|
+
# Check ports from framework detection
|
|
644
|
+
check_port() {
|
|
645
|
+
PORT=$1
|
|
646
|
+
# Prefer lsof (most portable), fallback to netstat, then ss
|
|
647
|
+
if command -v lsof >/dev/null 2>&1; then
|
|
648
|
+
PID=$(lsof -ti :$PORT 2>/dev/null)
|
|
649
|
+
if [ -n "$PID" ]; then
|
|
650
|
+
echo "PORT_IN_USE:$PORT (PID=$PID)"
|
|
651
|
+
kill -9 $PID 2>/dev/null && echo "Killed PID $PID on port $PORT"
|
|
652
|
+
else
|
|
653
|
+
echo "PORT_FREE:$PORT"
|
|
654
|
+
fi
|
|
655
|
+
elif command -v netstat >/dev/null 2>&1; then
|
|
656
|
+
PID=$(netstat -tlnp 2>/dev/null | grep ":$PORT " | awk '{print $NF}' | sed 's|/.*||')
|
|
657
|
+
if [ -n "$PID" ] && [ "$PID" != "-" ]; then
|
|
658
|
+
echo "PORT_IN_USE:$PORT (PID=$PID)"
|
|
659
|
+
kill -9 $PID 2>/dev/null && echo "Killed PID $PID on port $PORT"
|
|
660
|
+
else
|
|
661
|
+
echo "PORT_FREE:$PORT"
|
|
662
|
+
fi
|
|
663
|
+
else
|
|
664
|
+
# Last resort: ss (iproute2)
|
|
665
|
+
PID=$(ss -tlnp 2>/dev/null | grep ":$PORT " | sed -n 's/.*pid=\([0-9]*\).*/\1/p' | head -1)
|
|
666
|
+
if [ -n "$PID" ]; then
|
|
667
|
+
echo "PORT_IN_USE:$PORT (PID=$PID)"
|
|
668
|
+
kill -9 $PID 2>/dev/null && echo "Killed PID $PID on port $PORT"
|
|
669
|
+
else
|
|
670
|
+
echo "PORT_FREE:$PORT"
|
|
671
|
+
fi
|
|
672
|
+
fi
|
|
673
|
+
}
|
|
674
|
+
check_port <port>
|
|
675
|
+
# For SSR, also check the Node port
|
|
676
|
+
check_port <nodePort>
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
| Scenario | Port | Action if occupied |
|
|
680
|
+
| ---------------------- | ------------------------------------ | -------------------------------------- |
|
|
681
|
+
| SPA/SSG/Cross-platform | nginx port (from `framework.detect`) | Kill old process, then configure nginx |
|
|
682
|
+
| SSR | nginx public port + Node app port | Kill old processes on both ports |
|
|
683
|
+
|
|
684
|
+
If the port cannot be freed (different user/process), increment to the next available port: `<port>+1`, update all subsequent nginx config and DevBridge references accordingly.
|
|
685
|
+
|
|
686
|
+
#### Configure Nginx
|
|
687
|
+
|
|
688
|
+
Use `huaweicloud_sandbox_deploy_nginx` to write the correct template, fix directory permissions, and reload nginx — all in one call:
|
|
689
|
+
|
|
690
|
+
```json
|
|
691
|
+
{
|
|
692
|
+
"nginx_type": "<nginxType>",
|
|
693
|
+
"port": <port>,
|
|
694
|
+
"project": "<dirname>",
|
|
695
|
+
"output_dir": "<outputDir>",
|
|
696
|
+
"node_port": <nodePort>,
|
|
697
|
+
"public_port": <publicPort>
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
- `nginx_type` — `spa` (SPA/SSG/cross-platform), `proxy` (SSR), or `static` (Hugo/Hexo) from `detect_framework`
|
|
702
|
+
- `port` — listen port from framework detection
|
|
703
|
+
- `project` — project dir name under `/workspace`
|
|
704
|
+
- `output_dir` — build output dir relative to `/workspace/<project>`
|
|
705
|
+
- `node_port` — Node.js app port for SSR proxy. Defaults to `<port> + 1` if omitted, and the result includes `nodePort` so you know which port to bind the Node process to.
|
|
706
|
+
- `public_port` — public listen port for SSR proxy (optional, defaults to `port`)
|
|
707
|
+
|
|
708
|
+
The tool automatically handles:
|
|
709
|
+
|
|
710
|
+
- Writing the correct nginx template (SPA try_files, SSR reverse proxy, or static)
|
|
711
|
+
- Fixing `o+x` directory traverse permissions on the project path
|
|
712
|
+
- Reloading nginx
|
|
713
|
+
|
|
714
|
+
If the tool returns `ok: false`, nginx may not be installed — fall back to Python HTTP server (see `references/nginx-templates.md`).
|
|
715
|
+
|
|
716
|
+
**Verify nginx is serving** — curl-check the app before proceeding to DevBridge:
|
|
717
|
+
|
|
718
|
+
```bash
|
|
719
|
+
curl -s -o /dev/null -w "nginx status: %{http_code}\n" http://localhost:<port>
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
If the status code is not 2xx/3xx:
|
|
723
|
+
|
|
724
|
+
- **403** — run `chmod -R o+rX /workspace/<project>/<outputDir>` and re-test
|
|
725
|
+
- **000 (connection refused)** — nginx not listening: check `sudo nginx -t` for config errors
|
|
726
|
+
- **Other** — check nginx error log: `sudo tail -20 /var/log/nginx/error.log`
|
|
727
|
+
|
|
728
|
+
> If `curl` is unavailable, check port via `lsof -i :<port>` or `netstat -tlnp | grep :<port>`
|
|
729
|
+
|
|
730
|
+
### Step 6: Start the App [REQUIRED]
|
|
731
|
+
|
|
732
|
+
- **Static (SPA/SSG/cross-platform)**: nginx is already serving. Skip.
|
|
733
|
+
- **SSR**: `PORT=<nodePort>` prefix is REQUIRED before `<serveCmd>`. nginx `proxy_pass` targets `<nodePort>`, not `<port>` — the two must differ. `deployNginx` returns `nodePort` in its result (defaults to `<port> + 1` for proxy type).
|
|
734
|
+
|
|
735
|
+
**Runtime environment variables**: SSR apps often need `DATABASE_URL`, `NEXTAUTH_URL`, `NEXTAUTH_SECRET`, etc. at runtime. Before starting, verify env vars from Step 4a are still loaded, and re-source `.env` if the shell session was reset:
|
|
736
|
+
|
|
737
|
+
```bash
|
|
738
|
+
cd /workspace/<dirname>
|
|
739
|
+
# Re-load env vars (SSR apps need them at runtime, not just build time)
|
|
740
|
+
if [ -f .env ]; then set -a && source .env 2>/dev/null; set +a; echo "Loaded .env"; fi
|
|
741
|
+
if [ -f .env.local ]; then set -a && source .env.local 2>/dev/null; set +a; echo "Loaded .env.local"; fi
|
|
742
|
+
# Verify critical vars
|
|
743
|
+
echo "DATABASE_URL=${DATABASE_URL:-<NOT SET>}"
|
|
744
|
+
echo "NEXTAUTH_URL=${NEXTAUTH_URL:-<NOT SET>}"
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
Then start with `PORT=<nodePort> <serveCmd>` via `exec_with_session` to run the Node process in background.
|
|
748
|
+
|
|
749
|
+
### Step 7: Expose via DevBridge [REQUIRED — deployment incomplete without this]
|
|
750
|
+
|
|
751
|
+
Follow the standard [Expose the deployed app](#expose-the-deployed-app-public-url) procedure. The app is already running on the detected port — only DevBridge tunnel setup is needed.
|
|
752
|
+
|
|
753
|
+
Use `exec_with_session` to background DevBridge. For SSR, DevBridge tunnels the nginx public port (not the Node port directly).
|
|
754
|
+
|
|
755
|
+
**Pre-flight**: always run `devbridge delete-all` before creating a new tunnel to prevent `10006: quota exceeded` from accumulated stale tunnels. If you still get quota error, list tunnels with `devbridge list -j`, delete stale ones, and retry.
|
|
756
|
+
|
|
757
|
+
Extract the tunnel URL from DevBridge output. The public URL has the form `https://<id>-<port>.cn-north-4-bridge.myhuaweicloud.com`. **Return this URL to the developer as the deployment result.**
|
|
758
|
+
|
|
759
|
+
#### Cross-platform H5 QR code
|
|
760
|
+
|
|
761
|
+
**If `detect_framework` returned `type: "cross-platform"` (Taro, uni-app)**, after exposing the tunnel, generate a QR code for mobile scanning:
|
|
762
|
+
|
|
763
|
+
```bash
|
|
764
|
+
TUNNEL_URL="<extracted-tunnel-url>"
|
|
765
|
+
|
|
766
|
+
# Generate QR inside nginx-served output directory so it is accessible via the tunnel URL
|
|
767
|
+
curl -s "https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$TUNNEL_URL")" -o /workspace/<dirname>/<outputDir>/qr.png
|
|
768
|
+
chmod o+r /workspace/<dirname>/<outputDir>/qr.png
|
|
769
|
+
echo "QR code URL: ${TUNNEL_URL}/qr.png"
|
|
770
|
+
echo "Desktop URL: $TUNNEL_URL"
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
**Do NOT use `qrencode -t ANSI256`** — terminal ANSI/ASCII QR codes have low precision and phone cameras cannot scan them. Also, never save the QR image outside the nginx root (e.g., `/workspace/qr.png`) — it must be inside the output directory so it is served by nginx alongside the app.
|
|
774
|
+
|
|
775
|
+
**After generating the QR code**, return both URLs to the developer:
|
|
776
|
+
|
|
777
|
+
```
|
|
778
|
+
桌面访问: <tunnel-url>
|
|
779
|
+
手机扫码: <tunnel-url>/qr.png
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
#### Deployment Completion Check [REQUIRED]
|
|
783
|
+
|
|
784
|
+
**Before reporting success, call `huaweicloud_sandbox_deploy_check`** to verify the deployment is complete:
|
|
785
|
+
|
|
786
|
+
```json
|
|
787
|
+
{
|
|
788
|
+
"port": <port>,
|
|
789
|
+
"project": "<dirname>",
|
|
790
|
+
"output_dir": "<outputDir>",
|
|
791
|
+
"framework_type": "<type>"
|
|
792
|
+
}
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
The tool checks:
|
|
796
|
+
|
|
797
|
+
- **nginx_serving** — nginx responds with 2xx/3xx on the app port
|
|
798
|
+
- **output_dir** — build output directory exists and is non-empty
|
|
799
|
+
- **devbridge_tunnel** — DevBridge tunnel is active
|
|
800
|
+
- **tunnel_url_accessible** — tunnel URL returns 200/304
|
|
801
|
+
- **qr_code** (cross-platform only) — QR image exists in output dir
|
|
802
|
+
|
|
803
|
+
Returns `complete: true/false`, `score`, and `nextStep` to fix missing items.
|
|
804
|
+
|
|
805
|
+
**If `complete` is false, follow `nextStep` to resolve before reporting success.** Do not return a deployment URL until `complete: true`.
|
|
806
|
+
|
|
807
|
+
| Framework Type | Must Return |
|
|
808
|
+
| --------------------------- | ------------------------- |
|
|
809
|
+
| `cross-platform` | Desktop URL + QR code URL |
|
|
810
|
+
| `spa` / `ssg` / `static` | Desktop URL |
|
|
811
|
+
| `ssr` | Desktop URL |
|
|
812
|
+
| `monorepo` (cross-platform) | Desktop URL + QR code URL |
|
|
813
|
+
|
|
814
|
+
**If the framework is cross-platform and the QR code was not generated, the deployment is incomplete — go back and generate it before reporting success.**
|
|
815
|
+
|
|
816
|
+
## References
|
|
817
|
+
|
|
818
|
+
- [Framework Commands](references/framework-commands.md) — command mapping for all supported frameworks
|
|
819
|
+
- [Nginx Templates](references/nginx-templates.md) — nginx configuration templates and fallback
|
|
820
|
+
|
|
100
821
|
## Critical Warnings
|
|
101
822
|
|
|
102
|
-
| Trap
|
|
103
|
-
|
|
104
|
-
| Agreement required first
|
|
105
|
-
| Real-name required
|
|
106
|
-
| Never expose tunnel details
|
|
107
|
-
| Login needs `--huaweicloud`
|
|
108
|
-
| CLI PATH
|
|
109
|
-
| 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
|
|
110
|
-
| Return the deployment URL
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
| Node
|
|
823
|
+
| Trap | Why |
|
|
824
|
+
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
825
|
+
| 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 |
|
|
826
|
+
| Real-name required | `sandbox_connect` fails if `realnameVerified=false`; tell the developer once and stop, don't loop on connect |
|
|
827
|
+
| Never expose tunnel details | Do not mention "DevBridge"/"tunnel"/"devbridge" to the developer — say "正在生成访问地址..." and hand over only the URL |
|
|
828
|
+
| Login needs `--huaweicloud` | `devbridge auth login --access-key/--secret-key` without `--huaweicloud` falls back to interactive browser login, which fails in the sandbox |
|
|
829
|
+
| CLI PATH | The installer only writes `~/.bashrc`; run `export PATH=$PATH:$HOME/.huawei/bin` in the session before using `devbridge` |
|
|
830
|
+
| 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 |
|
|
831
|
+
| Return the deployment URL | Always hand the public URL from the host log to the developer as the final result |
|
|
832
|
+
| 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. |
|
|
833
|
+
| 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. |
|
|
834
|
+
| Session state persists | `exec_with_session` preserves `cd`, env vars, aliases between calls |
|
|
835
|
+
| 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). |
|
|
836
|
+
| 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. |
|
|
837
|
+
| 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. |
|
|
838
|
+
| Destructive commands blocked | `rm -rf /`, `mkfs`, `dd if=`, fork bombs are denied by safety policy |
|
|
839
|
+
| Workspace ID = dev_stage_id | Use `dev_stage_id` from `sandbox_connect` as `workspace_id` for terminal exec |
|
|
840
|
+
| 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 |
|
|
841
|
+
| 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 |
|
|
842
|
+
| Upload file for single files | Use `sandbox_upload_file` for individual files — base64 chunked, reliable for small files (<1MB) |
|
|
843
|
+
| 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") |
|
|
844
|
+
| 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. |
|
|
845
|
+
| 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. |
|
|
846
|
+
| 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. |
|
|
847
|
+
| 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. |
|
|
116
848
|
|
|
117
849
|
## Node.js in the sandbox
|
|
118
850
|
|
|
@@ -129,11 +861,11 @@ node --version
|
|
|
129
861
|
|
|
130
862
|
## Environment Variables
|
|
131
863
|
|
|
132
|
-
| Variable
|
|
133
|
-
|
|
134
|
-
| `HW_ACCESS_KEY`
|
|
135
|
-
| `HW_SECRET_KEY`
|
|
136
|
-
| `HW_SECURITY_TOKEN`
|
|
137
|
-
| `HW_WORKSPACE_ID`
|
|
138
|
-
| `HDKITSERVICE_ENDPOINT` | No
|
|
139
|
-
| `HWLINK_ENDPOINT`
|
|
864
|
+
| Variable | Required | Description |
|
|
865
|
+
| ----------------------- | -------- | --------------------------------------------------------------- |
|
|
866
|
+
| `HW_ACCESS_KEY` | Yes | Huawei Cloud AK |
|
|
867
|
+
| `HW_SECRET_KEY` | Yes | Huawei Cloud SK |
|
|
868
|
+
| `HW_SECURITY_TOKEN` | No | STS security token |
|
|
869
|
+
| `HW_WORKSPACE_ID` | No | Default workspace ID |
|
|
870
|
+
| `HDKITSERVICE_ENDPOINT` | No | hdkitservice API endpoint (default: devkit.huaweicloud.com) |
|
|
871
|
+
| `HWLINK_ENDPOINT` | No | DevStation API endpoint (default: devstation.myhuaweicloud.com) |
|