huaweicloud-devkit 2.0.0-next.4 → 2.0.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/integrations/opencode/commands/huaweicloud-doctor.md +1 -1
- package/integrations/opencode/hooks/safety-gate.js +235 -0
- 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/agents/opencode-config.js +29 -4
- package/plugins/huaweicloud-core/dist/agents/opencode.js +55 -14
- package/plugins/huaweicloud-core/dist/approval-gate.js +23 -5
- package/plugins/huaweicloud-core/dist/doctor-payload.js +29 -0
- 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/lib/opencode-permission-seam.js +51 -20
- package/plugins/huaweicloud-core/dist/mcp-server.js +520 -290
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +5 -1
- 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/payload-placement.js +8 -0
- 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/classify-text.js +10 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +12 -0
- package/plugins/huaweicloud-core/dist/safety/protected-payload.js +93 -0
- 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/safety-integrity.js +122 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +1 -1
- package/plugins/huaweicloud-core/dist/setup-cli.js +8 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +44 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +75 -2
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +5 -0
- 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/skills/huaweicloud-safety/references/approvals.md +1 -1
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +33 -3
- package/plugins/huaweicloud-core/src/agents/opencode.ts +66 -15
- package/plugins/huaweicloud-core/src/approval-gate.ts +29 -4
- package/plugins/huaweicloud-core/src/doctor-payload.ts +40 -2
- 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/lib/opencode-permission-seam.ts +60 -19
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +7 -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/payload-placement.ts +8 -0
- 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/classify-text.ts +10 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +13 -0
- package/plugins/huaweicloud-core/src/safety/protected-payload.ts +97 -0
- 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/safety-integrity.ts +132 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +7 -5
- package/plugins/huaweicloud-core/src/setup-cli.ts +8 -0
- 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
|
|
|
@@ -88,7 +88,7 @@ The PIN record stores only a mac over the vault custody master key, never the pl
|
|
|
88
88
|
|
|
89
89
|
The gate defends: execution needs a user-recorded confirmation — a PIN-checked terminal grant bound to the token and every stored field the run gate trusts (command hash, pin view, redacted form, mint time), or a server-raised form answer the client relayed, or an explicitly-labelled posture attestation whose line was shown first. The terminal grant is a custody-keyed mac, so a same-user edit of the state string or any trusted field does not verify; and a gated call without a valid confirmation never runs.
|
|
90
90
|
|
|
91
|
-
It does NOT defend against: a socially engineered user who approves a command they did not read (the form and terminal print the request, but neither proves comprehension); a same-user process that holds BOTH the custody master key and write access to `~/.config/huaweicloud/`, which can forge a grant for any pending token on the keyfile tier; a harness without the safety hook, where the TTY check is the only barrier and an agent driving a pseudo-terminal looks like a terminal
|
|
91
|
+
It does NOT defend against: a socially engineered user who approves a command they did not read (the form and terminal print the request, but neither proves comprehension); a same-user process that holds BOTH the custody master key and write access to `~/.config/huaweicloud/`, which can forge a grant for any pending token on the keyfile tier; a harness without the safety hook, where the TTY check is the only barrier and an agent driving a pseudo-terminal looks like a terminal (on opencode 2.x the shell face is no longer in this class: the installer-deployed safety-gate adapter classifies each scanner segment in-process and denies classifier-refused compounds before execution, leaving only the gate's own text residuals there — the indirection classes below); the text gates' indirection residuals — variable-indirect verbs (`V=approve; npx huaweicloud-devkit $V`, the same indirection residual the shell shadow documents for the secret gate) and script-file carriers (`bash /tmp/x.sh` runs a script whose content no text gate ever sees), both reaching a gated verb through a shell variable or an indirect file; an agent that rewrites the deployed classifier file itself — the same attack that was once open on every in-process gate is now three layers deep rather than closed: the classifier denies write-shaped bash commands targeting the deployed payload paths (policy.json's `protectedPayloadPathMarkers`), the adapter and the `.mjs` hook refuse an imported module that fails the load-time shape/behavior canaries, and doctor compares the deployed classifier files against the install-time integrity receipt — so the naive vector (echo/tee/cp over `dist/safety-policy.js`) is denied at the command itself, non-adversarial corruption (a stale replacement, a truncated overwrite) denies fail-closed at load, and any drift that lands anyway surfaces in doctor with the reinstall remediation. Against arbitrary user-permission bash NO purely local mechanism fully closes this — with the file system writable by the same user the gate runs under, an escape requires a crafted module that passes the canaries and a bypass of the path gate's own text residuals (quote/variable-indirect path spellings, verbs outside the shape table), which raises the cost to forging multiple artifacts at once; full closure needs out-of-band verification (a read-only install location, a signed payload, or an integrity check from a process the agent cannot write). The integrity receipt is itself local, so a determined attacker can rewrite it too — doctor's drift check is detection, not proof. Also outside the gate: a posture-tier retry, which trusts the model's report of the user's answer by design and is labelled as such on every surface that shows it. This is a consent gate, not an isolation boundary.
|
|
92
92
|
|
|
93
93
|
## The registered non-CLI tools
|
|
94
94
|
|
|
@@ -19,6 +19,7 @@ import { readJsonRecord, writeMcpSettingsFile } from '../mcp-config-io.ts';
|
|
|
19
19
|
import {
|
|
20
20
|
applySkillTreePermissionSeam,
|
|
21
21
|
opencodeSeamVersionSupported,
|
|
22
|
+
payloadEditDenyGlobs,
|
|
22
23
|
removeSkillTreePermissionSeam,
|
|
23
24
|
skillTreePermissionGlobs,
|
|
24
25
|
} from '../lib/opencode-permission-seam.ts';
|
|
@@ -137,6 +138,30 @@ export function openCodeAskGate(): OpenCodeAskGate {
|
|
|
137
138
|
return forced === 'on' ? 'v2-array' : 'off';
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
// The safety gate's floor check: permission.hook("evaluate") is a V2
|
|
142
|
+
// surface (G1 measured the event shape, the "shell" action naming, and the
|
|
143
|
+
// deny semantics on 2.2.7; V1 named the action "bash" and had no evaluate
|
|
144
|
+
// hook), so the floor is the 2.0 major. Unparsable or absent stays
|
|
145
|
+
// unsupported — the caller's polarity is skip, never a guess.
|
|
146
|
+
export function opencodeSafetyGateVersionSupported(version: string | null): boolean {
|
|
147
|
+
if (version === null) return false;
|
|
148
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
|
|
149
|
+
return match !== null && Number(match[1]) >= 2;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// The safety gate's version gate, same doctrine as the seam's:
|
|
153
|
+
// HUAWEICLOUD_OPENCODE_SAFETY_GATE=on|off is the deterministic override for
|
|
154
|
+
// the installer test suite (e2e strips it — the runner's install relies on
|
|
155
|
+
// the natural probe); unset runs the probe against the 2.0 floor. A
|
|
156
|
+
// below-floor, absent, or unparsable opencode gets no adapter file and a
|
|
157
|
+
// doctor SKIP, never a FAIL — 1.x has no evaluate hook to register on, and a
|
|
158
|
+
// later update heals the skip by deploying the file.
|
|
159
|
+
export function openCodeSafetyGate(): 'on' | 'off' {
|
|
160
|
+
const forced = process.env.HUAWEICLOUD_OPENCODE_SAFETY_GATE;
|
|
161
|
+
if (forced === 'on' || forced === 'off') return forced;
|
|
162
|
+
return opencodeSafetyGateVersionSupported(probeOpencodeVersion()) ? 'on' : 'off';
|
|
163
|
+
}
|
|
164
|
+
|
|
140
165
|
// The server half of the ask posture: DEVKIT_APPROVAL_MODE=ask in the mcp
|
|
141
166
|
// entry's environment (the field OpenCode reads — the applyPacksToEntry
|
|
142
167
|
// 'environment' precedent). Ask mode now means the SERVER-RUN gate: the
|
|
@@ -198,7 +223,7 @@ export function updateOpenCodeConfig(pluginDir: string): void {
|
|
|
198
223
|
// lib/opencode-permission-seam.ts), so the single write below carries it.
|
|
199
224
|
let permChanged = false;
|
|
200
225
|
if (openCodeSeamGate() === 'on') {
|
|
201
|
-
const seam = applySkillTreePermissionSeam(config, openCodeSeamGlobs(pluginDir));
|
|
226
|
+
const seam = applySkillTreePermissionSeam(config, openCodeSeamGlobs(pluginDir), payloadEditDenyGlobs(pluginDir));
|
|
202
227
|
permChanged = seam.changed;
|
|
203
228
|
for (const section of seam.skipped) {
|
|
204
229
|
console.log(
|
|
@@ -340,8 +365,13 @@ export function removeOpenCodeConfig(): void {
|
|
|
340
365
|
// hand. Globs derive from the stable XDG paths (the plugin dir may
|
|
341
366
|
// already be gone) and the running package's own manifest;
|
|
342
367
|
// value-exact deletion keeps user-modified rules (the ownership contract
|
|
343
|
-
// lives in lib/opencode-permission-seam.ts).
|
|
344
|
-
|
|
368
|
+
// lives in lib/opencode-permission-seam.ts). The edit-only payload
|
|
369
|
+
// class is removed under the same value-exact rule.
|
|
370
|
+
const permCleaned = removeSkillTreePermissionSeam(
|
|
371
|
+
config,
|
|
372
|
+
openCodeSeamGlobs(opencodePluginsDir()),
|
|
373
|
+
payloadEditDenyGlobs(opencodePluginsDir()),
|
|
374
|
+
);
|
|
345
375
|
// The client-rule cleanup also runs unconditionally of the version gate: an
|
|
346
376
|
// uninstall must remove what any past install wrote — the opencode that
|
|
347
377
|
// gated the write may since have been upgraded, downgraded, or removed from
|
|
@@ -34,9 +34,11 @@ import {
|
|
|
34
34
|
openCodeSeamGate,
|
|
35
35
|
openCodeSeamGlobs,
|
|
36
36
|
openCodeAskGate,
|
|
37
|
+
openCodeSafetyGate,
|
|
37
38
|
} from './opencode-config.ts';
|
|
38
39
|
import { readPermissionRules, readPermissionRulesV1, type RosterRuleState } from '../lib/opencode-ask-rule.ts';
|
|
39
40
|
import { scanSavedAllowRows } from '../lib/opencode-saved-perms.ts';
|
|
41
|
+
import { payloadEditDenyGlobs } from '../lib/opencode-permission-seam.ts';
|
|
40
42
|
import type { DoctorReporter } from '../doctor-report.ts';
|
|
41
43
|
import { asRecord } from '../lib/as-record.ts';
|
|
42
44
|
|
|
@@ -204,23 +206,27 @@ function savedAllowStoreCheck(ctx: DoctorReporter): void {
|
|
|
204
206
|
|
|
205
207
|
// Doctor: the skills-tree permission seam check — OpenCode installs only
|
|
206
208
|
// (the seam is the installer's zero-prompt path for direct skill reads on
|
|
207
|
-
// that harness). Verifies the
|
|
208
|
-
// ownership contract: a user-owned value on a devkit glob is
|
|
209
|
-
// kept, not broken; a below-floor or absent opencode is a SKIP,
|
|
210
|
-
// FAIL.
|
|
209
|
+
// that harness). Verifies the keys and their values over BOTH glob classes,
|
|
210
|
+
// honoring the ownership contract: a user-owned value on a devkit glob is
|
|
211
|
+
// reported as kept, not broken; a below-floor or absent opencode is a SKIP,
|
|
212
|
+
// never a FAIL.
|
|
211
213
|
export function opencodeDoctorSeam(ctx: DoctorReporter): void {
|
|
212
214
|
if (openCodeSeamGate() === 'off') {
|
|
213
215
|
ctx.skip('Skills-tree permission seam (opencode not verifiably at or above the measured permission floor)');
|
|
214
216
|
return;
|
|
215
217
|
}
|
|
216
|
-
// Per-glob evaluation, matching the installer's per-section
|
|
218
|
+
// Per-glob, two-class evaluation, matching the installer's per-section
|
|
217
219
|
// contract exactly: user-owned globs (any non-devkit value) are reported
|
|
218
220
|
// as kept, missing globs as healable — one user-owned glob must never
|
|
219
|
-
// mask a
|
|
221
|
+
// mask a healable gap. The edit-only class (the payload root — the
|
|
222
|
+
// classifier the in-process gate imports) requires just the edit deny:
|
|
223
|
+
// the external allow is deliberately absent there, so requiring it would
|
|
224
|
+
// fail every healthy install. Configs the installer itself refuses to
|
|
220
225
|
// touch (scalar-shaped permission, unparseable file — the parse-fail
|
|
221
226
|
// skip is the install path's ONLY skip) get a SKIP with the manual
|
|
222
227
|
// pointer, never a FAIL whose re-run-install remediation cannot succeed.
|
|
223
228
|
const globs = openCodeSeamGlobs(opencodePluginsDir());
|
|
229
|
+
const editOnlyGlobs = payloadEditDenyGlobs(opencodePluginsDir());
|
|
224
230
|
let cfg: Record<string, unknown> | null;
|
|
225
231
|
try {
|
|
226
232
|
cfg = asRecord(JSON.parse(readFileSync(opencodeConfigFile(), 'utf8')));
|
|
@@ -240,28 +246,52 @@ export function opencodeDoctorSeam(ctx: DoctorReporter): void {
|
|
|
240
246
|
const permRecord = asRecord(permission);
|
|
241
247
|
const ext = asRecord(permRecord.external_directory);
|
|
242
248
|
const editRules = asRecord(permRecord.edit);
|
|
243
|
-
const kept =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
249
|
+
const kept =
|
|
250
|
+
globs.filter((g) => (g in ext && ext[g] !== 'allow') || (g in editRules && editRules[g] !== 'deny')).length +
|
|
251
|
+
editOnlyGlobs.filter((g) => g in editRules && editRules[g] !== 'deny').length;
|
|
252
|
+
const missing =
|
|
253
|
+
globs.filter((g) => ext[g] !== 'allow' || editRules[g] !== 'deny').length +
|
|
254
|
+
editOnlyGlobs.filter((g) => editRules[g] !== 'deny').length;
|
|
255
|
+
const LABEL = 'Skills-tree permission seam (allow + edit deny; payload edit deny)';
|
|
256
|
+
if (missing === 0) {
|
|
257
|
+
ctx.check(LABEL, true, '');
|
|
258
|
+
} else if (kept === 0) {
|
|
248
259
|
ctx.check(
|
|
249
|
-
|
|
260
|
+
LABEL,
|
|
250
261
|
false,
|
|
251
|
-
'Run: npx huaweicloud-devkit install (writes the missing
|
|
262
|
+
'Run: npx huaweicloud-devkit install (writes the missing seam rules; see README, Harness permission notes)',
|
|
252
263
|
);
|
|
253
264
|
} else {
|
|
254
265
|
ctx.check(
|
|
255
|
-
|
|
266
|
+
LABEL,
|
|
256
267
|
false,
|
|
257
|
-
`${missing
|
|
268
|
+
`${missing} rule(s) missing (re-run: npx huaweicloud-devkit install); ${kept} user-owned glob(s) kept as-is (see README, Harness permission notes)`,
|
|
258
269
|
);
|
|
259
270
|
}
|
|
260
271
|
}
|
|
261
272
|
|
|
273
|
+
// Doctor: the shell safety gate — OpenCode installs only (the evaluate-hook
|
|
274
|
+
// adapter is the opencode ≥ 2.0 in-process deny face for shell commands).
|
|
275
|
+
// A below-floor, absent, or unparsable opencode is a SKIP, never a FAIL
|
|
276
|
+
// (the adapter has no surface to register on there); a verifiably ≥ 2.0
|
|
277
|
+
// opencode with a missing adapter file is the FAIL install heals.
|
|
278
|
+
export function opencodeDoctorSafetyGate(ctx: DoctorReporter): void {
|
|
279
|
+
if (openCodeSafetyGate() === 'off') {
|
|
280
|
+
ctx.skip('Shell safety gate (opencode not verifiably at or above 2.0.0)');
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const gateFile = join(configRoot('opencode'), 'plugins', 'safety-gate.js');
|
|
284
|
+
ctx.check(
|
|
285
|
+
'Shell safety gate (evaluate-hook adapter)',
|
|
286
|
+
existsSync(gateFile),
|
|
287
|
+
'Run: npx huaweicloud-devkit install --target opencode',
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
262
291
|
export async function deployOpenCode(mode: DeployMode): Promise<void> {
|
|
263
292
|
const commandsSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'commands');
|
|
264
293
|
const pluginSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'hooks', 'skill-tracker.js');
|
|
294
|
+
const gateSrc = join(PACKAGE_ROOT, 'integrations', 'opencode', 'hooks', 'safety-gate.js');
|
|
265
295
|
const pluginDest = opencodePluginsDir();
|
|
266
296
|
|
|
267
297
|
copyDir(commandsSrc, opencodeCommandsDir());
|
|
@@ -274,6 +304,19 @@ export async function deployOpenCode(mode: DeployMode): Promise<void> {
|
|
|
274
304
|
mkdirSync(opcPlugins, { recursive: true });
|
|
275
305
|
copyFileSync(pluginSrc, join(opcPlugins, 'skill-tracker.js'));
|
|
276
306
|
console.log(` Plugin${deployWord(mode)} -> ${opcPlugins}`);
|
|
307
|
+
const gateFile = join(opcPlugins, 'safety-gate.js');
|
|
308
|
+
if (openCodeSafetyGate() === 'on') {
|
|
309
|
+
copyFileSync(gateSrc, gateFile);
|
|
310
|
+
console.log(` Safety gate${deployWord(mode)} -> ${opcPlugins}`);
|
|
311
|
+
} else {
|
|
312
|
+
// Drift heal, same doctrine as the ask-rule migration: an opencode that
|
|
313
|
+
// downgraded or vanished since the last install must not keep the file
|
|
314
|
+
// (a below-floor host has no evaluate hook to run it on).
|
|
315
|
+
removeIfExists(gateFile);
|
|
316
|
+
console.log(
|
|
317
|
+
' \x1b[33m[INFO]\x1b[0m opencode not verifiably at or above 2.0.0 — skipping the shell safety-gate plugin; a below-floor host has no evaluate hook to gate the Bash face on.',
|
|
318
|
+
);
|
|
319
|
+
}
|
|
277
320
|
updateOpenCodeConfig(pluginDest);
|
|
278
321
|
|
|
279
322
|
installRuntimeDeps(pluginDest);
|
|
@@ -292,6 +335,12 @@ export function uninstallOpenCode(removeOwnedSkills: (dir: string) => number): v
|
|
|
292
335
|
console.log(' Removed plugin');
|
|
293
336
|
}
|
|
294
337
|
|
|
338
|
+
const gateFile = join(configRoot('opencode'), 'plugins', 'safety-gate.js');
|
|
339
|
+
if (existsSync(gateFile)) {
|
|
340
|
+
removeIfExists(gateFile);
|
|
341
|
+
console.log(' Removed safety-gate plugin');
|
|
342
|
+
}
|
|
343
|
+
|
|
295
344
|
if (removeIfExists(opencodePluginsDir())) {
|
|
296
345
|
console.log(' Removed MCP server and safety policy');
|
|
297
346
|
}
|
|
@@ -300,5 +349,7 @@ export function uninstallOpenCode(removeOwnedSkills: (dir: string) => number): v
|
|
|
300
349
|
|
|
301
350
|
export function opencodeStatus(): void {
|
|
302
351
|
payloadStatusLines(opencodePluginsDir());
|
|
352
|
+
const gateInstalled = existsSync(join(configRoot('opencode'), 'plugins', 'safety-gate.js'));
|
|
353
|
+
console.log(` Shell safety gate: ${gateInstalled ? '\x1b[32mInstalled\x1b[0m' : '\x1b[31mNot installed\x1b[0m'}`);
|
|
303
354
|
printMcpConfigStatus(opencodeConfigFile(), 'mcp');
|
|
304
355
|
}
|
|
@@ -86,6 +86,21 @@ export const NO_SESSION_SEAM_ERROR =
|
|
|
86
86
|
const GRANT_REQUIRED_NEXT_STEP =
|
|
87
87
|
'Ask the user to run "npx huaweicloud-devkit approve <this approvalToken>" in their own terminal, then retry this exact call.';
|
|
88
88
|
|
|
89
|
+
// F-APV-1: every CONFIRM_TOKEN_* rejection spells its way out — the ask
|
|
90
|
+
// envelope and the mint envelope already carry nextStep, and these close the
|
|
91
|
+
// gap so the model never has to reverse-engineer the approval flow from
|
|
92
|
+
// tool descriptions. Splitting NOT_FOUND into MISSING vs INVALID is a
|
|
93
|
+
// contract change held for its own pass; this keeps the pinned codes and
|
|
94
|
+
// only adds the guidance. Exported for the tests that pin the envelopes.
|
|
95
|
+
export const PLAN_FACE_TOKEN_MISSING_NEXT_STEP =
|
|
96
|
+
'This run call requires an approvalToken minted by the plan face. Call huaweicloud_plan_cli_command with the same args first — its USER_CONFIRMATION_REQUIRED envelope carries the fresh approvalToken; retry this call with it.';
|
|
97
|
+
|
|
98
|
+
export const CONFIRM_TOKEN_UNKNOWN_NEXT_STEP =
|
|
99
|
+
'This approvalToken was never minted in this process — malformed, or dropped by a server restart (tokens are process-scoped and never persisted). Re-run the plan call to mint a fresh approvalToken, then retry this call with it.';
|
|
100
|
+
|
|
101
|
+
export const CONFIRM_TOKEN_EXPIRED_NEXT_STEP =
|
|
102
|
+
'This approvalToken passed its 5-minute TTL. Re-run the plan call to mint a fresh approvalToken and have the user approve it promptly, then retry this call with it.';
|
|
103
|
+
|
|
89
104
|
// The command-forward anchor (the operator-approved display field): a call
|
|
90
105
|
// that carries the tool's `command` string must spell the exact line its args
|
|
91
106
|
// execute, so the harness popup's first line is the command the user is
|
|
@@ -951,7 +966,9 @@ export async function runApprovalGate(
|
|
|
951
966
|
// classified nothing on a tokenless call, and the plan face's own hook
|
|
952
967
|
// deny already covers the credential class at plan time.
|
|
953
968
|
if (spec.tokenSource === 'plan-face') {
|
|
954
|
-
return {
|
|
969
|
+
return {
|
|
970
|
+
envelope: { status: 'rejected', code: 'CONFIRM_TOKEN_NOT_FOUND', nextStep: PLAN_FACE_TOKEN_MISSING_NEXT_STEP },
|
|
971
|
+
};
|
|
955
972
|
}
|
|
956
973
|
// Gate-source mint face (PR-3 registrations; ApprovalCoreMint's
|
|
957
974
|
// classify-before-mint). BOTH floors sit before the mint for the same
|
|
@@ -991,13 +1008,17 @@ export async function runApprovalGate(
|
|
|
991
1008
|
return { envelope: { status: 'ok', outcome: 'already_processed' } };
|
|
992
1009
|
}
|
|
993
1010
|
if (inspection.state === 'expired') {
|
|
994
|
-
return {
|
|
1011
|
+
return {
|
|
1012
|
+
envelope: { status: 'rejected', code: 'CONFIRM_TOKEN_EXPIRED', nextStep: CONFIRM_TOKEN_EXPIRED_NEXT_STEP },
|
|
1013
|
+
};
|
|
995
1014
|
}
|
|
996
1015
|
if (inspection.state === 'not_found') {
|
|
997
1016
|
// A token that was never created (typo / unknown / pruned beyond the
|
|
998
1017
|
// tombstone window) is still a rejection, but carries no expired or
|
|
999
1018
|
// already semantics — a distinct code so clients can tell them apart.
|
|
1000
|
-
return {
|
|
1019
|
+
return {
|
|
1020
|
+
envelope: { status: 'rejected', code: 'CONFIRM_TOKEN_NOT_FOUND', nextStep: CONFIRM_TOKEN_UNKNOWN_NEXT_STEP },
|
|
1021
|
+
};
|
|
1001
1022
|
}
|
|
1002
1023
|
|
|
1003
1024
|
// Credential floor before the consume, so the refusal burns nothing and
|
|
@@ -1019,7 +1040,11 @@ export async function runApprovalGate(
|
|
|
1019
1040
|
// two reads. Classify via re-inspect, never a misleading success and
|
|
1020
1041
|
// never a false not_found.
|
|
1021
1042
|
const recheck = inspectApprovalToken(token);
|
|
1022
|
-
if (recheck.state === 'expired')
|
|
1043
|
+
if (recheck.state === 'expired') {
|
|
1044
|
+
return {
|
|
1045
|
+
envelope: { status: 'rejected', code: 'CONFIRM_TOKEN_EXPIRED', nextStep: CONFIRM_TOKEN_EXPIRED_NEXT_STEP },
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1023
1048
|
return { envelope: { status: 'ok', outcome: 'already_processed' } };
|
|
1024
1049
|
}
|
|
1025
1050
|
|