huaweicloud-devkit 2.0.0-next.3 → 2.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/package.json +3 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
- package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
- package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +141 -86
- package/plugins/huaweicloud-core/dist/agents/opencode.js +106 -39
- package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
- package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
- package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
- package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
- package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
- package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
- package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
- package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +68 -62
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +7 -5
- package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
- package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
- package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
- package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +371 -32
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +224 -78
- package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
- package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
- package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
- package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
- package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
- package/plugins/huaweicloud-core/dist/mcp-protocol.js +68 -16
- package/plugins/huaweicloud-core/dist/mcp-server.js +6933 -1186
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
- package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +85 -130
- package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
- package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
- package/plugins/huaweicloud-core/dist/packs/registry.js +20 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +180 -23
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +29 -3
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +93 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +37 -10
- package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
- package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
- package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
- package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
- package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
- package/plugins/huaweicloud-core/dist/packs-configure.js +74 -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 +36 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +2 -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/sandbox/deploy-check.js +1 -1
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
- package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +36 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +13 -1
- package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
- package/plugins/huaweicloud-core/dist/tools.js +76 -9
- package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
- package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
- package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +67 -4
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +115 -11
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +198 -143
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
- package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +2 -2
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +11 -7
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +74 -29
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
- package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
- package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
- package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +176 -88
- package/plugins/huaweicloud-core/src/agents/opencode.ts +125 -54
- package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
- package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
- package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
- package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
- package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
- package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
- package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
- package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +74 -71
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +7 -5
- package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
- package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
- package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
- package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +408 -30
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +302 -83
- package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
- package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
- package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
- package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
- package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
- package/plugins/huaweicloud-core/src/mcp-protocol.ts +81 -17
- package/plugins/huaweicloud-core/src/mcp-server.ts +7 -7
- package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
- package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
- package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +99 -137
- package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
- package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
- package/plugins/huaweicloud-core/src/packs/registry.ts +43 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +195 -23
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -14
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +120 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +42 -9
- package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
- package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
- package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
- package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
- package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
- package/plugins/huaweicloud-core/src/packs-configure.ts +75 -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 +40 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +7 -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/sandbox/deploy-check.ts +1 -1
- package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +511 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
- package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
- package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
- package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
- package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +39 -1
- package/plugins/huaweicloud-core/src/tool-definitions.ts +13 -1
- package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
- package/plugins/huaweicloud-core/src/tools.ts +124 -10
- package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
- package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
- package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
execWithSessionSchema,
|
|
3
3
|
execOneShotSchema,
|
|
4
|
+
execPollSchema,
|
|
4
5
|
closeSessionSchema,
|
|
5
6
|
uploadFileSchema,
|
|
6
7
|
uploadProjectSchema,
|
|
@@ -8,17 +9,20 @@ import {
|
|
|
8
9
|
deployCheckSchema,
|
|
9
10
|
checkUserSchema,
|
|
10
11
|
exposeTunnelSchema,
|
|
12
|
+
exposePollSchema,
|
|
11
13
|
renewTunnelSchema,
|
|
12
14
|
keepaliveWatchdogSchema,
|
|
13
15
|
signAgreementSchema,
|
|
14
16
|
connectSchema,
|
|
15
17
|
credentialsSchema,
|
|
18
|
+
shutdownSchema,
|
|
16
19
|
} from './schemas.ts';
|
|
17
20
|
import { handleExecWithSession, handleExecOneShot, handleCloseSession } from './handlers-session.ts';
|
|
21
|
+
import { handleHwexecPoll } from './handlers-hwexec.ts';
|
|
18
22
|
import { handleUploadFile, handleUploadProject } from './handlers-upload.ts';
|
|
19
23
|
import { handleDeployNginx, handleDeployCheck } from './handlers-deploy.ts';
|
|
20
|
-
import { handleExposeTunnel, handleRenewTunnel, handleKeepaliveWatchdog } from './handlers-tunnel.ts';
|
|
21
|
-
import { handleCheckUser, handleSignAgreement, handleConnect } from './handlers-account.ts';
|
|
24
|
+
import { handleExposeTunnel, handleExposePoll, handleRenewTunnel, handleKeepaliveWatchdog } from './handlers-tunnel.ts';
|
|
25
|
+
import { handleCheckUser, handleSignAgreement, handleConnect, handleShutdown } from './handlers-account.ts';
|
|
22
26
|
import { handleCredentials } from './handlers-credentials.ts';
|
|
23
27
|
import type { PackToolDefinition, LooseToolSchema } from '../../lib/pack-types.ts';
|
|
24
28
|
|
|
@@ -32,10 +36,12 @@ import type { PackToolDefinition, LooseToolSchema } from '../../lib/pack-types.t
|
|
|
32
36
|
// here. The family behind it (all siblings inside src/packs/sandbox/,
|
|
33
37
|
// joining the pack-boundaries walk automatically): schemas.ts (the zod
|
|
34
38
|
// schema block + the timeout table), git-transfer.ts (the repo transfer
|
|
35
|
-
// trio), handlers-session.ts / handlers-
|
|
36
|
-
// handlers-
|
|
37
|
-
// tool handlers, migrated verbatim from
|
|
38
|
-
// program
|
|
39
|
+
// trio), handlers-session.ts / handlers-hwexec.ts / handlers-upload.ts /
|
|
40
|
+
// handlers-deploy.ts / handlers-tunnel.ts / handlers-account.ts /
|
|
41
|
+
// handlers-credentials.ts (the tool handlers, migrated verbatim from
|
|
42
|
+
// src/tools.ts with the P2 pack program; handlers-hwexec.ts carries the
|
|
43
|
+
// async-exec claim protocol — the exec_one_shot async branch and the
|
|
44
|
+
// exec_poll tool).
|
|
39
45
|
|
|
40
46
|
export { SANDBOX_TIMEOUT_MS } from './schemas.ts';
|
|
41
47
|
|
|
@@ -50,10 +56,17 @@ export const SANDBOX_TOOLS = [
|
|
|
50
56
|
{
|
|
51
57
|
name: 'huaweicloud_sandbox_exec_one_shot',
|
|
52
58
|
description:
|
|
53
|
-
'Execute a command on a workspace terminal with a fresh connection per call (no session state carries over). Each invocation opens a new WebSocket connection, executes one command, then disconnects. Use for long-running build/deploy/install commands (>30s) that do not need shell state persistence between calls. More stable than session-based execution for heavy workloads.',
|
|
59
|
+
'Execute a command on a workspace terminal with a fresh connection per call (no session state carries over). Each invocation opens a new WebSocket connection, executes one command, then disconnects. Use for long-running build/deploy/install commands (>30s) that do not need shell state persistence between calls. More stable than session-based execution for heavy workloads. Commands that can outlive the sync timeout (default 120s) must run in mode: "async" instead: the tool claims a per-task directory with an atomic O_EXCL claim, spawns the command detached (setsid/nohup/disown — it survives the exec session), and returns immediately with {started, taskId, taskDir}; poll the verdict with huaweicloud_sandbox_exec_poll — that async + poll pair is the >30s long-command doctrine, and the same-task_id retry after started:"uncertain" is structurally double-spawn-safe. started:"dup" + verdict "never" → start over with a NEW task_id.',
|
|
54
60
|
schema: execOneShotSchema,
|
|
55
61
|
handler: handleExecOneShot,
|
|
56
62
|
},
|
|
63
|
+
{
|
|
64
|
+
name: 'huaweicloud_sandbox_exec_poll',
|
|
65
|
+
description:
|
|
66
|
+
'Poll an async sandbox task started by huaweicloud_sandbox_exec_one_shot with mode: "async". One call runs a bounded server-side wait (wait_ms 0-60000: sleep-2 intervals checking the task\'s status file; the exec timeout auto-folds to wait_ms + 15s so the wait always fits), then returns the task\'s verdict as a discriminated union — done (exitCode + logTail: the command finished), running (logTail: keep polling), lost (the wrapper died without an exit status, or the task directory vanished — a sandbox reboot — while this process remembered the task; restart with a new task_id if needed), never (the task was claimed but never launched — the start exec died between claim and spawn; start a NEW task_id, a same-id retry can never spawn), unknown (no task directory and no memory of the task_id — it never started here, or both the sandbox and this agent restarted). logTail is the last tail_bytes (default 4096) of the task\'s captured stdout+stderr. The retry ladder: started:"uncertain" → retry the SAME task_id (the claim file blocks a second copy); started:"dup" + verdict "never" → new task_id.',
|
|
67
|
+
schema: execPollSchema,
|
|
68
|
+
handler: handleHwexecPoll,
|
|
69
|
+
},
|
|
57
70
|
{
|
|
58
71
|
name: 'huaweicloud_sandbox_close_session',
|
|
59
72
|
description:
|
|
@@ -92,10 +105,17 @@ export const SANDBOX_TOOLS = [
|
|
|
92
105
|
{
|
|
93
106
|
name: 'huaweicloud_sandbox_expose_tunnel',
|
|
94
107
|
description:
|
|
95
|
-
'Expose a port on the sandbox to a public DevBridge tunnel URL (devbridge 0.2.x). Authenticates automatically (DevBridge auth is fixed to API Key — AK/SK login removed: the waterfall reads the sandbox keyring, then the /tmp/hw_api_key file channel; when both are empty it auto-creates the per-account × per-pool key (devkit-ephemeral/devkit-persistent) via the DevStation relay API and injects it, reporting authMode API_KEY_AUTO),
|
|
108
|
+
'Expose a port on the sandbox to a public DevBridge tunnel URL (devbridge 0.2.x). Authenticates automatically (DevBridge auth is fixed to API Key — AK/SK login removed: the waterfall reads the sandbox keyring, then the /tmp/hw_api_key file channel; when both are empty it auto-creates the per-account × per-pool key (devkit-ephemeral/devkit-persistent) via the DevStation relay API and injects it, reporting authMode API_KEY_AUTO), selectively cleans only same-port/orphan tunnels before exposing (cleanup_mode=stale default — other ports, other sessions and keepalive-protected tunnels are preserved, except a tunnel bound to THIS port, which is always replaced; on 10006 quota it removes orphans first, then the oldest non-keepalive tunnel one at a time), starts the host detached from the exec session (setsid/nohup/disown so it survives session teardown), extracts the public URL (https://<id>-<port>.devbridge-s2.hwtunnel.com), and health-checks it before returning. Use the ACTUAL port reported by huaweicloud_sandbox_deploy_nginx (its "port" field auto-increments on conflict) — never the originally requested port. This automates the manual "Expose the deployed app" flow (huawei-sandbox skill). Returns ok, publicUrl, port, tunnelId, authMode, expiresAt (expiry_hours lifetime, default 72h; 1-720), keepalive.enrolled/tunnelCount/watchdogPid, warnings, sandboxLifetime and urlLifetimeHint. The urlLifetimeHint MUST be relayed to the developer together with the URL: the tunnel expiry is NOT the sandbox lifetime — an idle sandbox shuts down (ephemeral also auto-deletes), which kills the URL. AUTO-ENROLLS the tunnel into the keepalive watchdog (unattended renewal + host re-attach + health check; pass keepalive:false to opt out). The URL is re-verified from a second independent exec session: persistent/verifyHttpCode distinguish a session-surviving URL from one that dies with the deploying session, and a non-persistent URL carries a 请勿分享 warning. Gateway-level tunnel errors (404 "tunnel not found" / "port not configured", 502 "bad gateway") are classified by exact body — an app\'s own 404/502 page is never mistaken for them. When no usable URL is reachable after retries it returns ok:false instead of a dead URL; when the tunnel quota (10006) stays full after the selective cleanup it returns ok:false with error_code devbridge_tunnel_quota_exceeded (keepalive-protected tunnels are preserved — remove unused tunnels or retry with cleanup_mode=all for a full reset). When auto-creation hits the 20-key quota it returns ok:false with error_code HDKIT_DEVBRIDGE_KEY_QUOTA_EXCEEDED, the currentKeys list, and the console cleanup URL; a failed key invalidation self-heals by clearing the cache and recreating before the next probe. The auto-create relay goes through hdkitservice and inherits its 409 HDKIT_VERSION_TOO_OLD version gate: an outdated plugin fails auto-create the same way it fails connect, and the expose failure carries error_code HDKIT_VERSION_TOO_OLD with the upgrade remediation under gateRemediation, and clientVersion and minVersion when the service sends them — upgrade the plugin instead of creating a key by hand.',
|
|
96
109
|
schema: exposeTunnelSchema,
|
|
97
110
|
handler: handleExposeTunnel,
|
|
98
111
|
},
|
|
112
|
+
{
|
|
113
|
+
name: 'huaweicloud_sandbox_expose_poll',
|
|
114
|
+
description:
|
|
115
|
+
'Poll an async expose task started by huaweicloud_sandbox_expose_tunnel with mode: "async". Returns state: running (the chain is still working — call again), done (result carries the full expose envelope: ok, publicUrl, port, tunnelId, expiresAt, urlLifetimeHint, keepalive, warnings), failed (an unexpected throw escaped the chain, with error), or unknown (no receipt in this MCP server process — it never started here, the session restarted, or the 30-minute receipt expired; the tunnel may already exist, so check huaweicloud_sandbox_deploy_check or re-expose — never assume success without a URL). The urlLifetimeHint MUST be relayed with the URL: the tunnel expiry is not the sandbox lifetime.',
|
|
116
|
+
schema: exposePollSchema,
|
|
117
|
+
handler: handleExposePoll,
|
|
118
|
+
},
|
|
99
119
|
{
|
|
100
120
|
name: 'huaweicloud_sandbox_renew_tunnel',
|
|
101
121
|
description:
|
|
@@ -127,7 +147,7 @@ export const SANDBOX_TOOLS = [
|
|
|
127
147
|
{
|
|
128
148
|
name: 'huaweicloud_sandbox_connect',
|
|
129
149
|
description:
|
|
130
|
-
'Connect to a sandbox via hdkitservice. One instance per user per pool — reuses the same-pool sandbox if available, otherwise creates a new one. Quota: 1 instance per pool type (a user may hold 1 ephemeral AND 1 persistent simultaneously; same-type requests reuse the existing instance). On quota exhaustion the API returns HTTP 429 with
|
|
150
|
+
'Connect to a sandbox via hdkitservice. One instance per user per pool — reuses the same-pool sandbox if available, otherwise creates a new one. Quota: 1 instance per pool type (a user may hold 1 ephemeral AND 1 persistent simultaneously; same-type requests reuse the existing instance). On quota exhaustion the API returns HTTP 429 with one of three codes: HDKIT_QUOTA_EXCEEDED (retry useless — release or reuse the existing instance; 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). 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 this tool with the SAME parameters after retryAfter and a created instance is reused. An outdated plugin version is rejected by the 409 HDKIT_VERSION_TOO_OLD version gate, surfaced by the sandbox tools (connect/check_user/sign_agreement/credentials) as ok:false and by the voucher trio as claimed:false, always carrying code, message, and remediation naming the upgrade act (npx --yes huaweicloud-devkit@latest update --target <agent>, restart the agent session, or huaweicloud_upgrade), with clientVersion and minVersion present when the service sends them. Returns session_id, dev_stage_id, connection_id, connection_address, expiresAt (STS credential expiry), pool_type/resolved template_id echo, server-configured lifecycle numbers (pool_idle_shutdown_minutes / pool_idle_delete_minutes / pool_reclaim_minutes) and started (true when a reused instance was woken from shutdown). Lifecycle hints are announced only on the first connect of a session or when started=true. Ephemeral pool (default): idle auto-shutdown after 30min, auto-delete after 1h — do not keep important data there. Persistent pool: data disk retained (EVS 32G), idle shutdown after 1h, idle reclaim capped at 7 days. Numbers are configured by hdkitservice; the text follows the server echo and falls back to these defaults. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
131
151
|
schema: connectSchema,
|
|
132
152
|
handler: handleConnect,
|
|
133
153
|
},
|
|
@@ -138,6 +158,13 @@ export const SANDBOX_TOOLS = [
|
|
|
138
158
|
schema: credentialsSchema,
|
|
139
159
|
handler: handleCredentials,
|
|
140
160
|
},
|
|
161
|
+
{
|
|
162
|
+
name: 'huaweicloud_sandbox_shutdown',
|
|
163
|
+
description:
|
|
164
|
+
'Shut down a running sandbox via hdkitservice to stop core-hour consumption. This calls DevStation close, NOT delete: the instance is retained; for persistent sandboxes the EVS data disk is also retained. A later huaweicloud_sandbox_connect wakes it. Works for both ephemeral and persistent sandboxes. Only call when the developer explicitly asks to shut down; never auto-shutdown. Returns devStageId, status (stopped/shutting_down/already_stopped/close_requested) and message.',
|
|
165
|
+
schema: shutdownSchema,
|
|
166
|
+
handler: handleShutdown,
|
|
167
|
+
},
|
|
141
168
|
] as const satisfies readonly PackToolDefinition[];
|
|
142
169
|
|
|
143
170
|
export type SandboxToolName = (typeof SANDBOX_TOOLS)[number]['name'];
|
|
@@ -148,18 +175,21 @@ export type SandboxToolName = (typeof SANDBOX_TOOLS)[number]['name'];
|
|
|
148
175
|
export const SANDBOX_TOOL_SCHEMAS: Readonly<Record<SandboxToolName, LooseToolSchema>> = {
|
|
149
176
|
huaweicloud_sandbox_exec_with_session: execWithSessionSchema,
|
|
150
177
|
huaweicloud_sandbox_exec_one_shot: execOneShotSchema,
|
|
178
|
+
huaweicloud_sandbox_exec_poll: execPollSchema,
|
|
151
179
|
huaweicloud_sandbox_close_session: closeSessionSchema,
|
|
152
180
|
huaweicloud_sandbox_upload_file: uploadFileSchema,
|
|
153
181
|
huaweicloud_sandbox_upload_project: uploadProjectSchema,
|
|
154
182
|
huaweicloud_sandbox_deploy_nginx: deployNginxSchema,
|
|
155
183
|
huaweicloud_sandbox_deploy_check: deployCheckSchema,
|
|
156
184
|
huaweicloud_sandbox_expose_tunnel: exposeTunnelSchema,
|
|
185
|
+
huaweicloud_sandbox_expose_poll: exposePollSchema,
|
|
157
186
|
huaweicloud_sandbox_renew_tunnel: renewTunnelSchema,
|
|
158
187
|
huaweicloud_sandbox_keepalive_watchdog: keepaliveWatchdogSchema,
|
|
159
188
|
huaweicloud_sandbox_check_user: checkUserSchema,
|
|
160
189
|
huaweicloud_sandbox_sign_agreement: signAgreementSchema,
|
|
161
190
|
huaweicloud_sandbox_connect: connectSchema,
|
|
162
191
|
huaweicloud_sandbox_credentials: credentialsSchema,
|
|
192
|
+
huaweicloud_sandbox_shutdown: shutdownSchema,
|
|
163
193
|
};
|
|
164
194
|
|
|
165
195
|
// Dispatch map merged into PACK_TOOL_HANDLERS in packs/registry.ts. Typed over
|
|
@@ -168,16 +198,19 @@ export const SANDBOX_TOOL_SCHEMAS: Readonly<Record<SandboxToolName, LooseToolSch
|
|
|
168
198
|
export const SANDBOX_TOOL_HANDLERS: Readonly<Record<SandboxToolName, PackToolDefinition['handler']>> = {
|
|
169
199
|
huaweicloud_sandbox_exec_with_session: handleExecWithSession,
|
|
170
200
|
huaweicloud_sandbox_exec_one_shot: handleExecOneShot,
|
|
201
|
+
huaweicloud_sandbox_exec_poll: handleHwexecPoll,
|
|
171
202
|
huaweicloud_sandbox_close_session: handleCloseSession,
|
|
172
203
|
huaweicloud_sandbox_upload_file: handleUploadFile,
|
|
173
204
|
huaweicloud_sandbox_upload_project: handleUploadProject,
|
|
174
205
|
huaweicloud_sandbox_deploy_nginx: handleDeployNginx,
|
|
175
206
|
huaweicloud_sandbox_deploy_check: handleDeployCheck,
|
|
176
207
|
huaweicloud_sandbox_expose_tunnel: handleExposeTunnel,
|
|
208
|
+
huaweicloud_sandbox_expose_poll: handleExposePoll,
|
|
177
209
|
huaweicloud_sandbox_renew_tunnel: handleRenewTunnel,
|
|
178
210
|
huaweicloud_sandbox_keepalive_watchdog: handleKeepaliveWatchdog,
|
|
179
211
|
huaweicloud_sandbox_check_user: handleCheckUser,
|
|
180
212
|
huaweicloud_sandbox_sign_agreement: handleSignAgreement,
|
|
181
213
|
huaweicloud_sandbox_connect: handleConnect,
|
|
182
214
|
huaweicloud_sandbox_credentials: handleCredentials,
|
|
215
|
+
huaweicloud_sandbox_shutdown: handleShutdown,
|
|
183
216
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { hashArgs } from '../../lib/approval-tokens.ts';
|
|
2
|
+
import { redactSecrets } from '../../safety-policy.ts';
|
|
3
|
+
import { parseSecretRef } from '../../lib/secret-vault/refs.ts';
|
|
4
|
+
import type { ApprovalSpec } from '../../approval-types.ts';
|
|
5
|
+
import type { ToolArgs } from '../../tools.ts';
|
|
6
|
+
|
|
7
|
+
// The secrets pack's approval registration (PR-3c): secret_delete is
|
|
8
|
+
// ALWAYS gated — it destroys the stored ciphertext with no version
|
|
9
|
+
// history, so a deleted ref is gone until its owner re-stores it. The
|
|
10
|
+
// binding and the confirmation view name the ref, because the ref is the
|
|
11
|
+
// entire consequence of the call. secret_set stays UNREGISTERED: the
|
|
12
|
+
// plaintext arrives from the user (channel=value is the user pasting it,
|
|
13
|
+
// file/envVar are user-designated sources), so the human is present by
|
|
14
|
+
// construction and a second confirmation would confirm nothing new.
|
|
15
|
+
// secret_list is the read-only inventory and stays ungated the same way.
|
|
16
|
+
function deleteBinding(args: ToolArgs): Record<string, unknown> {
|
|
17
|
+
return { ref: args.ref };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const SECRETS_APPROVAL_SPECS: Readonly<Record<'huaweicloud_secret_delete', ApprovalSpec>> = {
|
|
21
|
+
huaweicloud_secret_delete: {
|
|
22
|
+
domain: 'secrets',
|
|
23
|
+
flavor: 'always',
|
|
24
|
+
tokenSource: 'gate',
|
|
25
|
+
normalizeArgs: deleteBinding,
|
|
26
|
+
// NoDoomedToken (interrogate round 2, fix-in-pass i): vaultDelete
|
|
27
|
+
// refuses an unparseable ref outright, so an approval minted for one is
|
|
28
|
+
// doomed — the retry would hit the same refusal forever. The ref must
|
|
29
|
+
// parse before any mint; the message mirrors vaultDelete's own
|
|
30
|
+
// VAULT_BAD_REF text so the two layers teach identically.
|
|
31
|
+
assertArgsExecutable: (value: unknown): void => {
|
|
32
|
+
const ref = (value as { ref?: unknown }).ref;
|
|
33
|
+
const parsed = typeof ref === 'string' ? parseSecretRef(ref) : null;
|
|
34
|
+
if (parsed === null) {
|
|
35
|
+
throw new Error(`"${String(ref)}" is not a valid secret ref (secret://<scope>/<name>, segments [a-z0-9-]).`);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
// The view folds through the shared redaction vocabulary before any
|
|
39
|
+
// field reaches the summary or pin view (the ApprovalSpec contract);
|
|
40
|
+
// the hash binds the raw content.
|
|
41
|
+
summarize: (value) => {
|
|
42
|
+
const safe = redactSecrets(value) as { ref?: unknown };
|
|
43
|
+
return {
|
|
44
|
+
summary: `huaweicloud_secret_delete: delete secret ${String(safe.ref)} from the local vault (no version history)`,
|
|
45
|
+
argsHash: hashArgs(value),
|
|
46
|
+
pinView: safe,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -6,6 +6,7 @@ import { isCredentialEnvVarName, SECRET_REF_PATTERN } from '../../lib/secret-vau
|
|
|
6
6
|
import { isCredentialFilePath } from '../../safety-policy.ts';
|
|
7
7
|
import type { PackToolDefinition, LooseToolSchema } from '../../lib/pack-types.ts';
|
|
8
8
|
import type { CallToolOptions, ToolArgs } from '../../tools.ts';
|
|
9
|
+
import { approvalTokenArg, approvedByUserArg } from '../../lib/tool-schema-parts.ts';
|
|
9
10
|
|
|
10
11
|
// The secrets pack: vault writes and inventory through MCP. There is
|
|
11
12
|
// deliberately NO value-retrieval tool — plaintext never crosses the MCP
|
|
@@ -105,6 +106,8 @@ const secretListSchema = z.looseObject({
|
|
|
105
106
|
|
|
106
107
|
const secretDeleteSchema = z.looseObject({
|
|
107
108
|
ref: secretRefField.describe('Vault ref to delete.'),
|
|
109
|
+
approvalToken: approvalTokenArg,
|
|
110
|
+
approvedByUser: approvedByUserArg,
|
|
108
111
|
});
|
|
109
112
|
|
|
110
113
|
export const SECRETS_TOOLS = [
|
|
@@ -125,7 +128,7 @@ export const SECRETS_TOOLS = [
|
|
|
125
128
|
{
|
|
126
129
|
name: 'huaweicloud_secret_delete',
|
|
127
130
|
description:
|
|
128
|
-
'Delete one secret from the local vault by ref. Idempotent: removed=1 when a secret was deleted, removed=0 when the ref was not stored (usually a typo in the ref — check with huaweicloud_secret_list).',
|
|
131
|
+
'Delete one secret from the local vault by ref. Destructive with no version history, so the approval gate mediates every call: in the default token mode a no-token call returns USER_CONFIRMATION_REQUIRED with the approve command line for the user\u2019s own terminal, and under DEVKIT_APPROVAL_MODE=ask the server raises the confirmation itself (form, or an ASK_CONFIRMATION_REQUIRED chat round-trip). Deleting a ref that S1 credentials.json points at breaks those credential reads until the operator re-stores it (the strict vault seam fails closed on the unresolvable ref). Idempotent: removed=1 when a secret was deleted, removed=0 when the ref was not stored (usually a typo in the ref — check with huaweicloud_secret_list).',
|
|
129
132
|
schema: secretDeleteSchema,
|
|
130
133
|
handler: handleSecretDelete,
|
|
131
134
|
},
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { hashArgs } from '../../lib/approval-tokens.ts';
|
|
2
|
+
import { redactSecrets } from '../../safety-policy.ts';
|
|
3
|
+
import { asString } from '../../lib/as-text.ts';
|
|
4
|
+
import { SUPPORTED_AGENT_TARGETS } from '../../auth/agent-registration.ts';
|
|
5
|
+
import type { ApprovalSpec } from '../../approval-types.ts';
|
|
6
|
+
import type { ToolArgs } from '../../tools.ts';
|
|
7
|
+
|
|
8
|
+
// The update pack's approval registration (PR-3c): huaweicloud_upgrade is
|
|
9
|
+
// ALWAYS gated — it replaces the package on disk for every installed
|
|
10
|
+
// target, which redirects every later tool call onto code the operator
|
|
11
|
+
// never reviewed, so the trunk's description-level consent line
|
|
12
|
+
// ("执行前必须先征得用户同意") becomes a mechanical gate. The binding is
|
|
13
|
+
// the {target, version} projection (never the gate fields), so the
|
|
14
|
+
// confirmation pins exactly what will be upgraded. check_update stays
|
|
15
|
+
// unregistered: it is the read-only face of the pair.
|
|
16
|
+
//
|
|
17
|
+
// Interrogate round 2, finding 2 — display/binding integrity:
|
|
18
|
+
// (a) An ABSENT version normalizes to the literal 'latest' INSIDE the
|
|
19
|
+
// binding, so the value the popup displays is the value the token
|
|
20
|
+
// binds: the natural retry with version:'latest' (what the user read)
|
|
21
|
+
// hashes identically to the unversioned mint and executes, instead
|
|
22
|
+
// of mismatch-burning the token.
|
|
23
|
+
// (b) assertArgsExecutable refuses every version shape the handler's own
|
|
24
|
+
// chain refuses (upgradePackage accepts 'latest' only): a concrete
|
|
25
|
+
// version and an empty string never mint a doomed approval.
|
|
26
|
+
// (c) 'latest' names the CHANNEL, not an artifact: the handler elects
|
|
27
|
+
// the actual tag after consent (a stable current → @latest, a
|
|
28
|
+
// prerelease current → @next). The summarize view says so. Residual,
|
|
29
|
+
// recorded: the tag can move between consent and execution (a
|
|
30
|
+
// registry publish lands mid-cycle); the consent pins the channel
|
|
31
|
+
// and the target, never the resolved artifact.
|
|
32
|
+
//
|
|
33
|
+
// Interrogate round 3, finding — the target half of the same doctrine:
|
|
34
|
+
// (a) An absent AND an empty target normalize to the literal 'all'
|
|
35
|
+
// (the handler's own default for both), so the displayed '(target
|
|
36
|
+
// all)' is the bound value and the natural retry with target:'all'
|
|
37
|
+
// consumes instead of mismatch-burning the confirmed token.
|
|
38
|
+
// (b) assertArgsExecutable also refuses targets outside the handler's
|
|
39
|
+
// SUPPORTED_AGENT_TARGETS allowlist (upgradePackage answers
|
|
40
|
+
// '不支持的升级目标' after the gate, review #717's shell-interpolation
|
|
41
|
+
// guard), so a bogus or case-variant target never mints a doomed
|
|
42
|
+
// approval.
|
|
43
|
+
function upgradeBinding(args: ToolArgs): Record<string, unknown> {
|
|
44
|
+
return {
|
|
45
|
+
target: args.target === undefined || args.target === '' ? 'all' : args.target,
|
|
46
|
+
version: args.version === undefined ? 'latest' : args.version,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function assertUpgradeExecutable(value: unknown): void {
|
|
51
|
+
const { target, version } = value as { target?: unknown; version?: unknown };
|
|
52
|
+
if (version !== 'latest') {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`version must be "latest" (got ${JSON.stringify(version)}): the handler elects the actual dist tag from the channel. Send version: "latest" or omit it.`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const targetStr = String(target);
|
|
58
|
+
if (targetStr !== 'all' && !SUPPORTED_AGENT_TARGETS.includes(targetStr)) {
|
|
59
|
+
throw new Error(`不支持的升级目标:${targetStr}(有效目标:all,或 ${SUPPORTED_AGENT_TARGETS.join(', ')} 之一)`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const UPDATE_APPROVAL_SPECS: Readonly<Record<'huaweicloud_upgrade', ApprovalSpec>> = {
|
|
64
|
+
huaweicloud_upgrade: {
|
|
65
|
+
domain: 'update',
|
|
66
|
+
flavor: 'always',
|
|
67
|
+
tokenSource: 'gate',
|
|
68
|
+
normalizeArgs: upgradeBinding,
|
|
69
|
+
assertArgsExecutable: assertUpgradeExecutable,
|
|
70
|
+
// The view folds through the shared redaction vocabulary before any
|
|
71
|
+
// field reaches the summary or pin view (the ApprovalSpec contract:
|
|
72
|
+
// never the raw argument stream); the hash binds the raw content —
|
|
73
|
+
// here the normalized content, so the displayed value IS the bound
|
|
74
|
+
// value.
|
|
75
|
+
summarize: (value) => {
|
|
76
|
+
const safe = redactSecrets(value) as { target?: unknown; version?: unknown };
|
|
77
|
+
return {
|
|
78
|
+
summary:
|
|
79
|
+
`huaweicloud_upgrade: upgrade huaweicloud-devkit to version ${asString(safe.version) ?? 'latest'} ` +
|
|
80
|
+
`(target ${asString(safe.target) ?? 'all'}) — "latest" names the channel: the handler elects the stable ` +
|
|
81
|
+
'or prerelease dist tag (a stable current upgrades to @latest, a prerelease current to @next) after consent',
|
|
82
|
+
argsHash: hashArgs(value),
|
|
83
|
+
pinView: safe,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '../../update-check.ts';
|
|
14
14
|
import type { PackToolDefinition, LooseToolSchema } from '../../lib/pack-types.ts';
|
|
15
15
|
import type { CallToolOptions, ToolArgs } from '../../tools.ts';
|
|
16
|
+
import { approvalTokenArg, approvedByUserArg } from '../../lib/tool-schema-parts.ts';
|
|
16
17
|
|
|
17
18
|
// Handlers migrated verbatim from src/tools.ts; the doQuery injection seam on
|
|
18
19
|
// CallToolOptions is passed through unchanged (test/upgrade-session.test.ts
|
|
@@ -69,6 +70,8 @@ const upgradeSchema = z.looseObject({
|
|
|
69
70
|
.string()
|
|
70
71
|
.optional()
|
|
71
72
|
.describe('agent 目标(opencode/codex/codearts/.../all)。缺省时用 all(仅更新已安装的)。'),
|
|
73
|
+
approvalToken: approvalTokenArg,
|
|
74
|
+
approvedByUser: approvedByUserArg,
|
|
72
75
|
});
|
|
73
76
|
|
|
74
77
|
export const UPDATE_TOOLS = [
|
|
@@ -81,8 +84,12 @@ export const UPDATE_TOOLS = [
|
|
|
81
84
|
},
|
|
82
85
|
{
|
|
83
86
|
name: 'huaweicloud_upgrade',
|
|
87
|
+
// The mechanical approval gate enforces the consent this line used to
|
|
88
|
+
// only ask for (PR-3c): token mode runs the approve command from the
|
|
89
|
+
// gate's rejection envelope in the user's own terminal, ask mode lets
|
|
90
|
+
// the server raise the confirmation itself.
|
|
84
91
|
description:
|
|
85
|
-
'升级 huaweicloud-devkit
|
|
92
|
+
'升级 huaweicloud-devkit 到最新版本。升级会改写磁盘上的插件本体,因此由审批门机械把关:默认 token 模式下,无 token 调用会返回 USER_CONFIRMATION_REQUIRED 与 approve 命令行,用户在自己的终端确认后才可重试;DEVKIT_APPROVAL_MODE=ask 时由服务器在调用内弹出确认(表单或聊天往返)。version 仅支持 "latest"。完成后需重启会话生效。',
|
|
86
93
|
schema: upgradeSchema,
|
|
87
94
|
handler: handleUpgrade,
|
|
88
95
|
},
|
|
@@ -71,7 +71,7 @@ export const VOUCHER_TOOLS = [
|
|
|
71
71
|
{
|
|
72
72
|
name: 'huaweicloud_voucher_status',
|
|
73
73
|
description:
|
|
74
|
-
'查询代金券领取状态。当会话已处于华为云任务上下文(用户已指明华为云,或先前轮次已确认)且用户首次使用或询问插件能力时,主动调用本工具检查:未领取(claimed=false)则主动提示可领取一张代金券;已领取(claimed=true
|
|
74
|
+
'查询代金券领取状态。当会话已处于华为云任务上下文(用户已指明华为云,或先前轮次已确认)且用户首次使用或询问插件能力时,主动调用本工具检查:未领取(claimed=false)则主动提示可领取一张代金券;已领取(claimed=true)则不提示、不打扰;claimed=false 且 code=HDKIT_VERSION_TOO_OLD 表示客户端版本过旧——转述 remediation 升级引导,绝不提示领券。厂商未定(用户未指明、上下文无法推断)时不要调用——先问用户用的是哪家云。',
|
|
75
75
|
schema: voucherStatusSchema,
|
|
76
76
|
handler: handleVoucherStatus,
|
|
77
77
|
},
|
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
} from './packs/enable.ts';
|
|
23
23
|
import { PACK_IDS, type PackId } from './lib/pack-types.ts';
|
|
24
24
|
import { closePackEnablement } from './lib/dependency-model.ts';
|
|
25
|
+
import { hashArgs } from './lib/approval-tokens.ts';
|
|
26
|
+
import { redactSecrets } from './safety-policy.ts';
|
|
27
|
+
import { asString } from './lib/as-text.ts';
|
|
28
|
+
import type { ApprovalSpec } from './approval-types.ts';
|
|
25
29
|
|
|
26
30
|
export function configurePacks(args: ToolArgs, opts: CallToolOptions): unknown {
|
|
27
31
|
const enable = (args.enable ?? []).map((id) => String(id));
|
|
@@ -102,3 +106,74 @@ export function configurePacks(args: ToolArgs, opts: CallToolOptions): unknown {
|
|
|
102
106
|
: 'The requested surface already applies.',
|
|
103
107
|
};
|
|
104
108
|
}
|
|
109
|
+
|
|
110
|
+
// The packs_configure approval registration (PR-3c). ALWAYS gated, because
|
|
111
|
+
// widening the session's disclosure face is the actual consequence — an
|
|
112
|
+
// enabled pack materializes its tools and skills for every later call — and
|
|
113
|
+
// the summarize view names the exact ids so the confirmation surface shows
|
|
114
|
+
// the consequence itself. requiresSessionSeam mirrors this handler's own
|
|
115
|
+
// stdio-only refusal: the gate checks opts.onPacksChanged BEFORE engaging
|
|
116
|
+
// (the refusal lives here, downstream of any dispatch-layer gate), so a
|
|
117
|
+
// no-seam call refuses with no token minted and no ledger entry — the
|
|
118
|
+
// ordering the gate's precheck exists to enforce. The binding is the
|
|
119
|
+
// {enable, disable, reset} projection, never the gate fields.
|
|
120
|
+
export const PACKS_CONFIGURE_APPROVAL_SPEC: Readonly<ApprovalSpec> = {
|
|
121
|
+
domain: 'packs',
|
|
122
|
+
flavor: 'always',
|
|
123
|
+
tokenSource: 'gate',
|
|
124
|
+
requiresSessionSeam: true,
|
|
125
|
+
normalizeArgs: (args: ToolArgs): Record<string, unknown> => ({
|
|
126
|
+
enable: args.enable,
|
|
127
|
+
disable: args.disable,
|
|
128
|
+
reset: args.reset,
|
|
129
|
+
}),
|
|
130
|
+
summarize: (value) => {
|
|
131
|
+
// The view folds through the shared redaction vocabulary before any
|
|
132
|
+
// field reaches the summary or pin view (the ApprovalSpec contract);
|
|
133
|
+
// the hash binds the raw content.
|
|
134
|
+
const safe = redactSecrets(value) as { enable?: unknown; disable?: unknown; reset?: unknown };
|
|
135
|
+
const list = (ids: unknown): string =>
|
|
136
|
+
Array.isArray(ids) ? ids.map((id) => String(id)).join(', ') : (asString(ids) ?? '');
|
|
137
|
+
const parts: string[] = [];
|
|
138
|
+
if (Array.isArray(safe.enable) && safe.enable.length > 0) parts.push(`enable pack(s) ${list(safe.enable)}`);
|
|
139
|
+
if (Array.isArray(safe.disable) && safe.disable.length > 0) parts.push(`disable pack(s) ${list(safe.disable)}`);
|
|
140
|
+
if (safe.reset === true) parts.push('reset the session override (restore the operator DEVKIT_PACKS posture)');
|
|
141
|
+
if (parts.length === 0) parts.push('no-op: provide enable, disable, or reset');
|
|
142
|
+
return {
|
|
143
|
+
summary: `huaweicloud_packs_configure: ${parts.join('; ')}`,
|
|
144
|
+
argsHash: hashArgs(value),
|
|
145
|
+
pinView: safe,
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
// NoDoomedToken (interrogate round 2, fix-in-pass i): the handler's own
|
|
149
|
+
// five pure validations, hoisted BEFORE the mint — a shape the handler
|
|
150
|
+
// refuses would burn the user's approval on a guaranteed refusal, so it
|
|
151
|
+
// never mints. Message texts mirror the handler's exactly, so the two
|
|
152
|
+
// layers can never drift into different teachings; the handler keeps its
|
|
153
|
+
// own copies as the belt behind this floor.
|
|
154
|
+
assertArgsExecutable: (value: unknown): void => {
|
|
155
|
+
const { enable, disable, reset } = value as { enable?: unknown; disable?: unknown; reset?: unknown };
|
|
156
|
+
const enableIds = Array.isArray(enable) ? enable.map((id) => String(id)) : [];
|
|
157
|
+
const disableIds = Array.isArray(disable) ? disable.map((id) => String(id)) : [];
|
|
158
|
+
const resetIs = reset === true;
|
|
159
|
+
if (!resetIs && enableIds.length === 0 && disableIds.length === 0) {
|
|
160
|
+
throw new Error('Provide at least one of enable, disable, or reset.');
|
|
161
|
+
}
|
|
162
|
+
const bogus = [...enableIds, ...disableIds].filter((id) => !(PACK_IDS as readonly string[]).includes(id));
|
|
163
|
+
if (bogus.length > 0) {
|
|
164
|
+
throw new Error('Unknown pack id(s): ' + bogus.join(', ') + '. Valid pack ids: ' + PACK_IDS.join(', ') + '.');
|
|
165
|
+
}
|
|
166
|
+
if (disableIds.includes('core')) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
'core is always enabled (the pack meta, safety, and discovery surface is force-included) and cannot be disabled.',
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const overlap = enableIds.filter((id) => disableIds.includes(id));
|
|
172
|
+
if (overlap.length > 0) {
|
|
173
|
+
throw new Error('Pack id(s) cannot be both enabled and disabled in one call: ' + overlap.join(', ') + '.');
|
|
174
|
+
}
|
|
175
|
+
if (resetIs && (enableIds.length > 0 || disableIds.length > 0)) {
|
|
176
|
+
throw new Error('reset drops the whole session override and cannot be combined with enable or disable.');
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
};
|
|
@@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
|
|
5
5
|
import { asText } from './lib/as-text.ts';
|
|
6
6
|
import { asRecord } from './lib/as-record.ts';
|
|
7
|
+
import { redactEvidenceText } from './safety/redact.ts';
|
|
7
8
|
|
|
8
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
10
|
const defaultRulesPath = join(__dirname, '..', 'safety', 'rules', 'cloud-risk-rules.json');
|
|
@@ -134,12 +135,7 @@ export function loadRiskRules(options: RiskRuleOptions = {}): RiskCatalog {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
function redactEvidence(text: unknown): string {
|
|
137
|
-
return
|
|
138
|
-
.replace(
|
|
139
|
-
/((?:access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|secret(?!:\/)|security[_-]?token|x[_-]?auth[_-]?token|token|authorization|password|passwd|admin[_-]?pass|credential)\\*["']?\s*[:=]\s*[\\"'\\]*\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi,
|
|
140
|
-
'$1<redacted>',
|
|
141
|
-
)
|
|
142
|
-
.replace(/\b(AK|SK)\\*["']?\s*[:=]\s*("[^"]*"|'[^']*'|[^\s,;]+)/gi, '$1=<redacted>');
|
|
138
|
+
return redactEvidenceText(text);
|
|
143
139
|
}
|
|
144
140
|
|
|
145
141
|
function normalizeText(value: unknown): string {
|
|
@@ -174,10 +170,27 @@ function evaluationContext(stage: string, input: unknown): EvaluationContext {
|
|
|
174
170
|
return { text: normalizeText(input) };
|
|
175
171
|
}
|
|
176
172
|
|
|
173
|
+
// Shell-transcribed commands and nested JSON artifacts arrive with escaped
|
|
174
|
+
// quotes (`\"Action\":` / `{\"privileged\":true}`) — the spelling a shell or
|
|
175
|
+
// an embedded JSON string actually produces. The catalog's JSON-shaped rules
|
|
176
|
+
// were authored against the unescaped spelling, so a backslash between the
|
|
177
|
+
// key and the quote made deny-severity rules (IAM administrator grants, OBS
|
|
178
|
+
// anonymous writes, privileged containers) silently miss. Matching therefore
|
|
179
|
+
// tests the raw value AND a quote-unescaped shadow; evidence/display keep the
|
|
180
|
+
// raw text. Only quote-adjacent backslashes are folded, so Windows paths are
|
|
181
|
+
// untouched.
|
|
182
|
+
function normalizeRuleText(text: string): string {
|
|
183
|
+
return text.replace(/\\+(["'])/g, '$1');
|
|
184
|
+
}
|
|
185
|
+
|
|
177
186
|
function conditionMatches(condition: RiskRuleCondition, context: EvaluationContext): boolean {
|
|
178
187
|
const field = condition.field || 'text';
|
|
179
188
|
const value = Object.hasOwn(context, field) ? context[field] : context.text;
|
|
180
|
-
|
|
189
|
+
const raw = String(value || '');
|
|
190
|
+
const regex = new RegExp(condition.regex, 'ims');
|
|
191
|
+
if (regex.test(raw)) return true;
|
|
192
|
+
const normalized = normalizeRuleText(raw);
|
|
193
|
+
return normalized !== raw && regex.test(normalized);
|
|
181
194
|
}
|
|
182
195
|
|
|
183
196
|
function ruleMatches(rule: RiskRule, context: EvaluationContext): boolean {
|
|
@@ -129,20 +129,28 @@ export function classifyHcloudArgs(args: unknown, options: ClassifyOptions = {})
|
|
|
129
129
|
const isWrite = !readOnly && hasWritePrefix(operation, policy);
|
|
130
130
|
|
|
131
131
|
if (isExecution && !options.allowWrites) {
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
return applyCommandRiskRules(
|
|
133
|
+
{
|
|
134
|
+
decision: 'deny',
|
|
135
|
+
risk: 'execution',
|
|
136
|
+
reason: 'Huawei Cloud execution/trigger operation blocked until approved.',
|
|
137
|
+
},
|
|
138
|
+
normalizedArgs,
|
|
139
|
+
options,
|
|
140
|
+
);
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
if (isWrite && !options.allowWrites) {
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
return applyCommandRiskRules(
|
|
145
|
+
{
|
|
146
|
+
decision: 'deny',
|
|
147
|
+
risk: 'write',
|
|
148
|
+
reason:
|
|
149
|
+
'Huawei Cloud write operation blocked until the agent presents a plan and receives explicit user approval.',
|
|
150
|
+
},
|
|
151
|
+
normalizedArgs,
|
|
152
|
+
options,
|
|
153
|
+
);
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
const obsutilWrites = OBSUTIL_WRITES;
|
|
@@ -154,11 +162,15 @@ export function classifyHcloudArgs(args: unknown, options: ClassifyOptions = {})
|
|
|
154
162
|
const isObsWrite = isObs && obsutilWrites.has(operation.toLowerCase());
|
|
155
163
|
const isObsRead = isObs && obsutilReads.includes(operation.toLowerCase());
|
|
156
164
|
if (isObsWrite && !options.allowWrites) {
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
165
|
+
return applyCommandRiskRules(
|
|
166
|
+
{
|
|
167
|
+
decision: 'deny',
|
|
168
|
+
risk: 'write',
|
|
169
|
+
reason: 'OBS write operation blocked until the agent presents a plan and receives explicit user approval.',
|
|
170
|
+
},
|
|
171
|
+
normalizedArgs,
|
|
172
|
+
options,
|
|
173
|
+
);
|
|
162
174
|
}
|
|
163
175
|
if (isObsRead) {
|
|
164
176
|
return applyCommandRiskRules(
|
|
@@ -858,6 +858,46 @@ export function classifyTextCommand(command: unknown, options: ClassifyOptions =
|
|
|
858
858
|
};
|
|
859
859
|
}
|
|
860
860
|
|
|
861
|
+
// The account-switch CLI verbs (interrogate round 1, finding 1): `auth
|
|
862
|
+
// init`/`auth sync` write S1, the OBS config, and the KooCLI profile —
|
|
863
|
+
// the same account switch the MCP tools gate behind a human present
|
|
864
|
+
// (PR-3b). The hook blocks raw `hcloud configure set`, but the devkit's
|
|
865
|
+
// own wrapper was an open bypass: an agent that shells out to
|
|
866
|
+
// `npx huaweicloud-devkit auth init` switches every downstream approved
|
|
867
|
+
// write's account with no confirmation at all. Same anchoring doctrine
|
|
868
|
+
// as approve/pin: the patterns require a devkit binary spelling, so an
|
|
869
|
+
// hcloud operation or a plain file named auth-init never trips, and the
|
|
870
|
+
// read-only `auth status` stays allowed for the agent.
|
|
871
|
+
if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedAccountSwitchCliPatterns))) {
|
|
872
|
+
return {
|
|
873
|
+
decision: 'deny',
|
|
874
|
+
risk: 'approval',
|
|
875
|
+
reason:
|
|
876
|
+
"Running the account-switch CLI from the agent Bash face is blocked: switching the Huawei Cloud account is approval-gated, and the devkit's own confirmation must come from the user's own interactive terminal. Ask the user to run the auth init / auth sync command themselves, or use the gated MCP tools (huaweicloud_auth_init / huaweicloud_auth_switch), which confirm the target account with the user before switching.",
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// The devkit's gated-mutation CLI twins (interrogate round 1, finding 1):
|
|
881
|
+
// `update`/`upgrade` rewrite the installed package, `secret rm` deletes a
|
|
882
|
+
// vault entry, and `packs enable|disable|all` rewrites the operator
|
|
883
|
+
// DEVKIT_PACKS posture — the exact mutations the MCP approval gate
|
|
884
|
+
// mediates on huaweicloud_upgrade, huaweicloud_secret_delete, and
|
|
885
|
+
// huaweicloud_packs_configure. The CLI path carries no gate at all, so an
|
|
886
|
+
// agent shelling to it performs the mutation with zero confirmation —
|
|
887
|
+
// the same bypass class the auth verbs established. The row shape mirrors
|
|
888
|
+
// the approve/pin family (a devkit bin spelling must be present, so a
|
|
889
|
+
// Huawei Cloud operation or a benign sentence containing the verb never
|
|
890
|
+
// trips), matched against the same two shadows. A human at their own
|
|
891
|
+
// terminal is unaffected: this is the agent Bash face.
|
|
892
|
+
if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedGatedCliPatterns))) {
|
|
893
|
+
return {
|
|
894
|
+
decision: 'deny',
|
|
895
|
+
risk: 'approval',
|
|
896
|
+
reason:
|
|
897
|
+
'Running the devkit update/upgrade, secret rm, and packs enable/disable CLI verbs from the agent Bash face is blocked: they perform the same mutations the MCP approval gate mediates (huaweicloud_upgrade, huaweicloud_secret_delete, huaweicloud_packs_configure), with no confirmation on this path. Call the MCP tool instead — its gate raises the confirmation (token, form, or chat round-trip) — or let the user run the CLI command in their own terminal.',
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
|
|
861
901
|
// Order-independent reveal pair: `echo secret get <ref> --stdout | xargs
|
|
862
902
|
// npx huaweicloud-devkit` reorders the argv through xargs while every word
|
|
863
903
|
// is literal in the text — the patterns above assume bin-before-
|