huaweicloud-devkit 2.0.0-next.3 → 2.0.0-next.4
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 +16 -3
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +16 -3
- 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/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +62 -61
- 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 +362 -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 +6506 -912
- 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 +19 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +156 -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 +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +79 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +28 -9
- 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/safety/classify-text.js +36 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
- 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 +9 -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 +53 -3
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +114 -10
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +190 -138
- 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/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +68 -70
- 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 +377 -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 +42 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +168 -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 +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +100 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +31 -8
- 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/safety/classify-text.ts +40 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
- 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 +509 -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 +9 -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
|
@@ -22,6 +22,7 @@ export async function handleExposeTunnel(args = {}, _opts = {}) {
|
|
|
22
22
|
port: args.port,
|
|
23
23
|
expiryHours: typeof args.expiry_hours === 'number' ? args.expiry_hours : undefined,
|
|
24
24
|
keepalive: typeof args.keepalive === 'boolean' ? args.keepalive : undefined,
|
|
25
|
+
cleanupMode: args.cleanup_mode,
|
|
25
26
|
// DevBridge API Key 自动创建兜底(认证固定 apikey,AK/SK 已移除)
|
|
26
27
|
poolType: exposePoolContext?.poolMode || 'ephemeral',
|
|
27
28
|
poolContext: exposePoolContext,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { HWEXEC_POLL_HEADROOM_MS, HWEXEC_TAIL_BYTES_DEFAULT, HWEXEC_TAIL_BYTES_MAX, HWEXEC_TASK_ID_PATTERN, HWEXEC_WAIT_MS_MAX, } from "../../sandbox/hwexec-task.js";
|
|
3
|
+
import { numericArg, looseObject, gitConfig, workspaceId, username, vendorConfirmed, approvalTokenArg, approvedByUserArg, } from "../../lib/tool-schema-parts.js";
|
|
3
4
|
// The sandbox pack's zod schema family, extracted from tools.ts in the
|
|
4
5
|
// within-pack split for the jscpd complex-file bar. tools.ts stays the stable
|
|
5
6
|
// face: it imports every schema here for the SANDBOX_TOOLS /
|
|
@@ -12,6 +13,16 @@ import { numericArg, looseObject, gitConfig, workspaceId, username, vendorConfir
|
|
|
12
13
|
export const SANDBOX_TIMEOUT_MS = {
|
|
13
14
|
exec_with_session: 120000,
|
|
14
15
|
exec_one_shot: 120000,
|
|
16
|
+
// The async start's exec budget: the start script itself is fast (claim +
|
|
17
|
+
// spawn + receipt echo); a timeout here folds into the 'uncertain'
|
|
18
|
+
// receipt — the claim may have landed, and the same-task_id retry is
|
|
19
|
+
// structurally safe, so the short bound is honest, not lossy.
|
|
20
|
+
exec_one_shot_async: 30000,
|
|
21
|
+
// The poll's exec budget floor: the bounded wait loop (wait_ms, capped at
|
|
22
|
+
// 60000) plus the field round-trips must sit inside the timeout — the
|
|
23
|
+
// handler folds wait_ms + 15000 headroom via resolveHwexecPollTimeoutMs
|
|
24
|
+
// (the devbridge-expose-flow A2 doctrine), never below this floor.
|
|
25
|
+
exec_poll: 30000,
|
|
15
26
|
upload_file: 120000,
|
|
16
27
|
upload_project: 120000,
|
|
17
28
|
deploy_nginx: 60000,
|
|
@@ -20,10 +31,11 @@ export const SANDBOX_TIMEOUT_MS = {
|
|
|
20
31
|
// of dying as a ws-exec timeout (the pre-probing 30s default did not).
|
|
21
32
|
deploy_check: 60000,
|
|
22
33
|
// The expose script's A2 (#935) bounded waits can spend ~63s in one exec
|
|
23
|
-
// (
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
34
|
+
// (up to 9s URL-extraction retries + 4 × 10s probes + 3 × 5s backoff) — the
|
|
35
|
+
// headroom exists for the slow-gateway days the probe loop exists for, and
|
|
36
|
+
// a timeout still folds into the structured unreachable envelope (never a
|
|
37
|
+
// raw ws error). The selective pre-clean execs run outside this budget,
|
|
38
|
+
// each with its own bounded one-shot (devbridge-cleanup.ts).
|
|
27
39
|
expose_tunnel: 90000,
|
|
28
40
|
renew_tunnel: 60000,
|
|
29
41
|
keepalive_watchdog: 60000,
|
|
@@ -35,14 +47,42 @@ export const execWithSessionSchema = z.looseObject({
|
|
|
35
47
|
timeout_ms: numericArg
|
|
36
48
|
.optional()
|
|
37
49
|
.describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.exec_with_session})`),
|
|
50
|
+
approvalToken: approvalTokenArg,
|
|
51
|
+
approvedByUser: approvedByUserArg,
|
|
38
52
|
});
|
|
39
53
|
export const execOneShotSchema = z.looseObject({
|
|
40
54
|
command: z.string().describe('The shell command to execute on the remote workspace'),
|
|
55
|
+
mode: z
|
|
56
|
+
.enum(['sync', 'async'])
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('sync (default): this exec waits for the command and returns its output. async: claim a per-task directory and spawn the command detached (it survives the exec session), return {started, taskId, taskDir} immediately, then poll with huaweicloud_sandbox_exec_poll. Use async for build/install-class commands that can outlive the sync timeout. Retry ladder: started:"uncertain" (start exec timed out, the claim may be placed) → retry the SAME task_id — the claim file blocks a second spawn; started:"dup" + verdict "never" → start over with a NEW task_id.'),
|
|
59
|
+
task_id: z
|
|
60
|
+
.string()
|
|
61
|
+
.optional()
|
|
62
|
+
.describe(`async mode: the task id to claim, ${HWEXEC_TASK_ID_PATTERN.source} (path- and pgrep-safe). Defaults to a generated id. Reuse the SAME task_id when retrying an uncertain start — the claim file blocks a second copy.`),
|
|
63
|
+
workspace_id: workspaceId,
|
|
64
|
+
username,
|
|
65
|
+
timeout_ms: numericArg
|
|
66
|
+
.optional()
|
|
67
|
+
.describe(`Execution timeout in milliseconds (sync default: ${SANDBOX_TIMEOUT_MS.exec_one_shot}; async bounds only the start exec, default ${SANDBOX_TIMEOUT_MS.exec_one_shot_async} — the async command itself is unbounded and outlives the exec)`),
|
|
68
|
+
approvalToken: approvalTokenArg,
|
|
69
|
+
approvedByUser: approvedByUserArg,
|
|
70
|
+
});
|
|
71
|
+
export const execPollSchema = z.looseObject({
|
|
72
|
+
task_id: z
|
|
73
|
+
.string()
|
|
74
|
+
.describe(`The task id from huaweicloud_sandbox_exec_one_shot async mode, ${HWEXEC_TASK_ID_PATTERN.source}.`),
|
|
41
75
|
workspace_id: workspaceId,
|
|
42
76
|
username,
|
|
77
|
+
wait_ms: numericArg
|
|
78
|
+
.optional()
|
|
79
|
+
.describe(`Bounded in-poll wait: sleep-2 intervals checking the task status file, 0-${HWEXEC_WAIT_MS_MAX} (default 0 — snapshot only). The exec timeout auto-raises to wait_ms + ${HWEXEC_POLL_HEADROOM_MS} so the wait always fits.`),
|
|
80
|
+
tail_bytes: numericArg
|
|
81
|
+
.optional()
|
|
82
|
+
.describe(`Log tail size in bytes, 1-${HWEXEC_TAIL_BYTES_MAX} (default: ${HWEXEC_TAIL_BYTES_DEFAULT}).`),
|
|
43
83
|
timeout_ms: numericArg
|
|
44
84
|
.optional()
|
|
45
|
-
.describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.
|
|
85
|
+
.describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.exec_poll}; auto-raised to wait_ms + ${HWEXEC_POLL_HEADROOM_MS} headroom, never below the default)`),
|
|
46
86
|
});
|
|
47
87
|
export const closeSessionSchema = z.looseObject({
|
|
48
88
|
workspace_id: workspaceId,
|
|
@@ -125,11 +165,17 @@ export const exposeTunnelSchema = z.looseObject({
|
|
|
125
165
|
.boolean()
|
|
126
166
|
.optional()
|
|
127
167
|
.describe('Enroll the tunnel into the keepalive watchdog (default true — pass false to opt out). Returns keepalive.enrolled/tunnelCount/watchdogPid.'),
|
|
168
|
+
cleanup_mode: z
|
|
169
|
+
.enum(['stale', 'all', 'none'])
|
|
170
|
+
.optional()
|
|
171
|
+
.describe("Tunnel cleanup before exposing. stale (default): delete same-port tunnels + orphan records/hosts; preserve other ports, other sessions and keepalive-protected tunnels — except a tunnel bound to THIS port, which is always replaced. all: wipe every tunnel/host (manual full reset only — a shared sandbox loses every session's tunnels). none: no cleanup (a stale same-port host can then conflict)."),
|
|
128
172
|
workspace_id: workspaceId,
|
|
129
173
|
username,
|
|
130
174
|
timeout_ms: numericArg
|
|
131
175
|
.optional()
|
|
132
176
|
.describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.expose_tunnel})`),
|
|
177
|
+
approvalToken: approvalTokenArg,
|
|
178
|
+
approvedByUser: approvedByUserArg,
|
|
133
179
|
});
|
|
134
180
|
export const renewTunnelSchema = z.looseObject({
|
|
135
181
|
tunnel_id: z
|
|
@@ -143,6 +189,8 @@ export const renewTunnelSchema = z.looseObject({
|
|
|
143
189
|
timeout_ms: numericArg
|
|
144
190
|
.optional()
|
|
145
191
|
.describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.renew_tunnel})`),
|
|
192
|
+
approvalToken: approvalTokenArg,
|
|
193
|
+
approvedByUser: approvedByUserArg,
|
|
146
194
|
});
|
|
147
195
|
export const keepaliveWatchdogSchema = z.looseObject({
|
|
148
196
|
tunnels: z
|
|
@@ -159,8 +207,13 @@ export const keepaliveWatchdogSchema = z.looseObject({
|
|
|
159
207
|
timeout_ms: numericArg
|
|
160
208
|
.optional()
|
|
161
209
|
.describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.keepalive_watchdog})`),
|
|
210
|
+
approvalToken: approvalTokenArg,
|
|
211
|
+
approvedByUser: approvedByUserArg,
|
|
212
|
+
});
|
|
213
|
+
export const signAgreementSchema = z.looseObject({
|
|
214
|
+
approvalToken: approvalTokenArg,
|
|
215
|
+
approvedByUser: approvedByUserArg,
|
|
162
216
|
});
|
|
163
|
-
export const signAgreementSchema = z.looseObject({});
|
|
164
217
|
export const connectSchema = z.looseObject({
|
|
165
218
|
vendorConfirmed,
|
|
166
219
|
source: z
|
|
@@ -170,11 +223,12 @@ export const connectSchema = z.looseObject({
|
|
|
170
223
|
pool_type: z
|
|
171
224
|
.enum(['ephemeral', 'persistent'])
|
|
172
225
|
.optional()
|
|
173
|
-
.describe('Sandbox pool type (default ephemeral). ephemeral = non-persistent: idle auto-shutdown 30min + auto-delete 1h (platform scheduled task, verified) — save important data elsewhere; persistent = data disk retained, idle reclaim within 7 days. Each user may hold one instance per pool type (1+1).
|
|
174
|
-
template_id: z.string().optional().describe('Template ID; overrides server default (only for new sandbox)'),
|
|
226
|
+
.describe('Sandbox pool type (default ephemeral). ephemeral = non-persistent: idle auto-shutdown 30min + auto-delete 1h (platform scheduled task, verified) — save important data elsewhere; persistent = data disk retained, idle reclaim within 7 days. Each user may hold one instance per pool type (1+1); same-type requests reuse the existing instance. Custom templates are no longer supported.'),
|
|
175
227
|
flavor_id: z.string().optional().describe('Flavor ID; overrides server default (only for new sandbox)'),
|
|
176
228
|
env: looseObject.optional().describe('Environment variables to set in the sandbox (only for new sandbox)'),
|
|
177
229
|
git: gitConfig.optional().describe('Git repo config (only for new sandbox)'),
|
|
230
|
+
approvalToken: approvalTokenArg,
|
|
231
|
+
approvedByUser: approvedByUserArg,
|
|
178
232
|
});
|
|
179
233
|
export const credentialsSchema = z.looseObject({
|
|
180
234
|
session_id: z.string().optional().describe('Session ID from huaweicloud_sandbox_connect'),
|
|
@@ -188,4 +242,20 @@ export const credentialsSchema = z.looseObject({
|
|
|
188
242
|
.string()
|
|
189
243
|
.optional()
|
|
190
244
|
.describe('DevBridge API Key (devbridge_...), injected into the sandbox as HW_API_KEY for devbridge 0.2.x auth. Also accepts a vault ref (secret://<scope>/<name>), resolved locally so the key never enters the conversation. The local HW_API_KEY environment variable takes precedence over this param (preferred delivery — keeps the long-lived key out of the conversation). Users create one at https://devstation.connect.huaweicloud.com/space/devbridge/apikey (full value shown once at creation). Required for exposing web apps via devbridge 0.2.x; if missing, guide the user through creating one.'),
|
|
245
|
+
approvalToken: approvalTokenArg,
|
|
246
|
+
approvedByUser: approvedByUserArg,
|
|
247
|
+
});
|
|
248
|
+
// 关机(dev 5d89c880):不可逆写类工具,走审批门(always 面);token 与
|
|
249
|
+
// attestation 与其余门面工具同型——schema 可选,门是执行者,首个无 token
|
|
250
|
+
// 调用必须能到达门以领取 mint 信封。
|
|
251
|
+
export const shutdownSchema = z.looseObject({
|
|
252
|
+
session_id: z.string().optional().describe('Session ID from huaweicloud_sandbox_connect (optional)'),
|
|
253
|
+
dev_stage_id: z.string().optional().describe('DevStation environment ID (alternative to session_id)'),
|
|
254
|
+
workspace_id: z
|
|
255
|
+
.string()
|
|
256
|
+
.optional()
|
|
257
|
+
.describe('Workspace ID; defaults to the current workspace (an alternative to session_id/dev_stage_id)'),
|
|
258
|
+
username,
|
|
259
|
+
approvalToken: approvalTokenArg,
|
|
260
|
+
approvedByUser: approvedByUserArg,
|
|
191
261
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { execWithSessionSchema, execOneShotSchema, closeSessionSchema, uploadFileSchema, uploadProjectSchema, deployNginxSchema, deployCheckSchema, checkUserSchema, exposeTunnelSchema, renewTunnelSchema, keepaliveWatchdogSchema, signAgreementSchema, connectSchema, credentialsSchema, } from "./schemas.js";
|
|
1
|
+
import { execWithSessionSchema, execOneShotSchema, execPollSchema, closeSessionSchema, uploadFileSchema, uploadProjectSchema, deployNginxSchema, deployCheckSchema, checkUserSchema, exposeTunnelSchema, renewTunnelSchema, keepaliveWatchdogSchema, signAgreementSchema, connectSchema, credentialsSchema, shutdownSchema, } from "./schemas.js";
|
|
2
2
|
import { handleExecWithSession, handleExecOneShot, handleCloseSession } from "./handlers-session.js";
|
|
3
|
+
import { handleHwexecPoll } from "./handlers-hwexec.js";
|
|
3
4
|
import { handleUploadFile, handleUploadProject } from "./handlers-upload.js";
|
|
4
5
|
import { handleDeployNginx, handleDeployCheck } from "./handlers-deploy.js";
|
|
5
6
|
import { handleExposeTunnel, handleRenewTunnel, handleKeepaliveWatchdog } from "./handlers-tunnel.js";
|
|
6
|
-
import { handleCheckUser, handleSignAgreement, handleConnect } from "./handlers-account.js";
|
|
7
|
+
import { handleCheckUser, handleSignAgreement, handleConnect, handleShutdown } from "./handlers-account.js";
|
|
7
8
|
import { handleCredentials } from "./handlers-credentials.js";
|
|
8
9
|
// The sandbox pack's stable face (split from the former 879-line monolith
|
|
9
10
|
// for the jscpd complex-file bar, cx < 50 per file; the safety-policy.ts
|
|
@@ -15,10 +16,12 @@ import { handleCredentials } from "./handlers-credentials.js";
|
|
|
15
16
|
// here. The family behind it (all siblings inside src/packs/sandbox/,
|
|
16
17
|
// joining the pack-boundaries walk automatically): schemas.ts (the zod
|
|
17
18
|
// schema block + the timeout table), git-transfer.ts (the repo transfer
|
|
18
|
-
// trio), handlers-session.ts / handlers-
|
|
19
|
-
// handlers-
|
|
20
|
-
// tool handlers, migrated verbatim from
|
|
21
|
-
// program
|
|
19
|
+
// trio), handlers-session.ts / handlers-hwexec.ts / handlers-upload.ts /
|
|
20
|
+
// handlers-deploy.ts / handlers-tunnel.ts / handlers-account.ts /
|
|
21
|
+
// handlers-credentials.ts (the tool handlers, migrated verbatim from
|
|
22
|
+
// src/tools.ts with the P2 pack program; handlers-hwexec.ts carries the
|
|
23
|
+
// async-exec claim protocol — the exec_one_shot async branch and the
|
|
24
|
+
// exec_poll tool).
|
|
22
25
|
export { SANDBOX_TIMEOUT_MS } from "./schemas.js";
|
|
23
26
|
export const SANDBOX_TOOLS = [
|
|
24
27
|
{
|
|
@@ -29,10 +32,16 @@ export const SANDBOX_TOOLS = [
|
|
|
29
32
|
},
|
|
30
33
|
{
|
|
31
34
|
name: 'huaweicloud_sandbox_exec_one_shot',
|
|
32
|
-
description: '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.',
|
|
35
|
+
description: '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.',
|
|
33
36
|
schema: execOneShotSchema,
|
|
34
37
|
handler: handleExecOneShot,
|
|
35
38
|
},
|
|
39
|
+
{
|
|
40
|
+
name: 'huaweicloud_sandbox_exec_poll',
|
|
41
|
+
description: '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.',
|
|
42
|
+
schema: execPollSchema,
|
|
43
|
+
handler: handleHwexecPoll,
|
|
44
|
+
},
|
|
36
45
|
{
|
|
37
46
|
name: 'huaweicloud_sandbox_close_session',
|
|
38
47
|
description: 'Close the persistent terminal session for a workspace. This closes the agent-side terminal session only — it does NOT delete the sandbox instance. Resource-pool sandbox deletion is developer-initiated (always ask for a second confirmation before guiding a delete) or handled by the platform resource-group idle-reclaim policy within the 7-day cap (v3 caliber); devkit never defers or performs deletion on the user behalf.',
|
|
@@ -65,7 +74,7 @@ export const SANDBOX_TOOLS = [
|
|
|
65
74
|
},
|
|
66
75
|
{
|
|
67
76
|
name: 'huaweicloud_sandbox_expose_tunnel',
|
|
68
|
-
description: '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),
|
|
77
|
+
description: '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.',
|
|
69
78
|
schema: exposeTunnelSchema,
|
|
70
79
|
handler: handleExposeTunnel,
|
|
71
80
|
},
|
|
@@ -95,7 +104,7 @@ export const SANDBOX_TOOLS = [
|
|
|
95
104
|
},
|
|
96
105
|
{
|
|
97
106
|
name: 'huaweicloud_sandbox_connect',
|
|
98
|
-
description: '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
|
|
107
|
+
description: '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 are retried automatically (30s/45s backoff) — the server may already have created the instance, so a retry reuses it. 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.',
|
|
99
108
|
schema: connectSchema,
|
|
100
109
|
handler: handleConnect,
|
|
101
110
|
},
|
|
@@ -105,6 +114,12 @@ export const SANDBOX_TOOLS = [
|
|
|
105
114
|
schema: credentialsSchema,
|
|
106
115
|
handler: handleCredentials,
|
|
107
116
|
},
|
|
117
|
+
{
|
|
118
|
+
name: 'huaweicloud_sandbox_shutdown',
|
|
119
|
+
description: '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.',
|
|
120
|
+
schema: shutdownSchema,
|
|
121
|
+
handler: handleShutdown,
|
|
122
|
+
},
|
|
108
123
|
];
|
|
109
124
|
// Schema map keyed by tool name for src/tool-schemas.ts: TOOL_SCHEMAS spreads
|
|
110
125
|
// it in place, keeping the satisfies Record<ToolName, LooseToolSchema>
|
|
@@ -112,6 +127,7 @@ export const SANDBOX_TOOLS = [
|
|
|
112
127
|
export const SANDBOX_TOOL_SCHEMAS = {
|
|
113
128
|
huaweicloud_sandbox_exec_with_session: execWithSessionSchema,
|
|
114
129
|
huaweicloud_sandbox_exec_one_shot: execOneShotSchema,
|
|
130
|
+
huaweicloud_sandbox_exec_poll: execPollSchema,
|
|
115
131
|
huaweicloud_sandbox_close_session: closeSessionSchema,
|
|
116
132
|
huaweicloud_sandbox_upload_file: uploadFileSchema,
|
|
117
133
|
huaweicloud_sandbox_upload_project: uploadProjectSchema,
|
|
@@ -124,6 +140,7 @@ export const SANDBOX_TOOL_SCHEMAS = {
|
|
|
124
140
|
huaweicloud_sandbox_sign_agreement: signAgreementSchema,
|
|
125
141
|
huaweicloud_sandbox_connect: connectSchema,
|
|
126
142
|
huaweicloud_sandbox_credentials: credentialsSchema,
|
|
143
|
+
huaweicloud_sandbox_shutdown: shutdownSchema,
|
|
127
144
|
};
|
|
128
145
|
// Dispatch map merged into PACK_TOOL_HANDLERS in packs/registry.ts. Typed over
|
|
129
146
|
// SandboxToolName, so a tool added to SANDBOX_TOOLS without a handler entry
|
|
@@ -131,6 +148,7 @@ export const SANDBOX_TOOL_SCHEMAS = {
|
|
|
131
148
|
export const SANDBOX_TOOL_HANDLERS = {
|
|
132
149
|
huaweicloud_sandbox_exec_with_session: handleExecWithSession,
|
|
133
150
|
huaweicloud_sandbox_exec_one_shot: handleExecOneShot,
|
|
151
|
+
huaweicloud_sandbox_exec_poll: handleHwexecPoll,
|
|
134
152
|
huaweicloud_sandbox_close_session: handleCloseSession,
|
|
135
153
|
huaweicloud_sandbox_upload_file: handleUploadFile,
|
|
136
154
|
huaweicloud_sandbox_upload_project: handleUploadProject,
|
|
@@ -143,4 +161,5 @@ export const SANDBOX_TOOL_HANDLERS = {
|
|
|
143
161
|
huaweicloud_sandbox_sign_agreement: handleSignAgreement,
|
|
144
162
|
huaweicloud_sandbox_connect: handleConnect,
|
|
145
163
|
huaweicloud_sandbox_credentials: handleCredentials,
|
|
164
|
+
huaweicloud_sandbox_shutdown: handleShutdown,
|
|
146
165
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { hashArgs } from "../../lib/approval-tokens.js";
|
|
2
|
+
import { redactSecrets } from "../../safety-policy.js";
|
|
3
|
+
import { parseSecretRef } from "../../lib/secret-vault/refs.js";
|
|
4
|
+
// The secrets pack's approval registration (PR-3c): secret_delete is
|
|
5
|
+
// ALWAYS gated — it destroys the stored ciphertext with no version
|
|
6
|
+
// history, so a deleted ref is gone until its owner re-stores it. The
|
|
7
|
+
// binding and the confirmation view name the ref, because the ref is the
|
|
8
|
+
// entire consequence of the call. secret_set stays UNREGISTERED: the
|
|
9
|
+
// plaintext arrives from the user (channel=value is the user pasting it,
|
|
10
|
+
// file/envVar are user-designated sources), so the human is present by
|
|
11
|
+
// construction and a second confirmation would confirm nothing new.
|
|
12
|
+
// secret_list is the read-only inventory and stays ungated the same way.
|
|
13
|
+
function deleteBinding(args) {
|
|
14
|
+
return { ref: args.ref };
|
|
15
|
+
}
|
|
16
|
+
export const SECRETS_APPROVAL_SPECS = {
|
|
17
|
+
huaweicloud_secret_delete: {
|
|
18
|
+
domain: 'secrets',
|
|
19
|
+
flavor: 'always',
|
|
20
|
+
tokenSource: 'gate',
|
|
21
|
+
normalizeArgs: deleteBinding,
|
|
22
|
+
// NoDoomedToken (interrogate round 2, fix-in-pass i): vaultDelete
|
|
23
|
+
// refuses an unparseable ref outright, so an approval minted for one is
|
|
24
|
+
// doomed — the retry would hit the same refusal forever. The ref must
|
|
25
|
+
// parse before any mint; the message mirrors vaultDelete's own
|
|
26
|
+
// VAULT_BAD_REF text so the two layers teach identically.
|
|
27
|
+
assertArgsExecutable: (value) => {
|
|
28
|
+
const ref = value.ref;
|
|
29
|
+
const parsed = typeof ref === 'string' ? parseSecretRef(ref) : null;
|
|
30
|
+
if (parsed === null) {
|
|
31
|
+
throw new Error(`"${String(ref)}" is not a valid secret ref (secret://<scope>/<name>, segments [a-z0-9-]).`);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
// The view folds through the shared redaction vocabulary before any
|
|
35
|
+
// field reaches the summary or pin view (the ApprovalSpec contract);
|
|
36
|
+
// the hash binds the raw content.
|
|
37
|
+
summarize: (value) => {
|
|
38
|
+
const safe = redactSecrets(value);
|
|
39
|
+
return {
|
|
40
|
+
summary: `huaweicloud_secret_delete: delete secret ${String(safe.ref)} from the local vault (no version history)`,
|
|
41
|
+
argsHash: hashArgs(value),
|
|
42
|
+
pinView: safe,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { vaultDelete, vaultList, vaultSet } from "../../lib/secret-vault/store.js";
|
|
4
4
|
import { isCredentialEnvVarName, SECRET_REF_PATTERN } from "../../lib/secret-vault/refs.js";
|
|
5
5
|
import { isCredentialFilePath } from "../../safety-policy.js";
|
|
6
|
+
import { approvalTokenArg, approvedByUserArg } from "../../lib/tool-schema-parts.js";
|
|
6
7
|
// The secrets pack: vault writes and inventory through MCP. There is
|
|
7
8
|
// deliberately NO value-retrieval tool — plaintext never crosses the MCP
|
|
8
9
|
// face; the Bash-side `secret exec` (child-process env only) is the
|
|
@@ -93,6 +94,8 @@ const secretListSchema = z.looseObject({
|
|
|
93
94
|
});
|
|
94
95
|
const secretDeleteSchema = z.looseObject({
|
|
95
96
|
ref: secretRefField.describe('Vault ref to delete.'),
|
|
97
|
+
approvalToken: approvalTokenArg,
|
|
98
|
+
approvedByUser: approvedByUserArg,
|
|
96
99
|
});
|
|
97
100
|
export const SECRETS_TOOLS = [
|
|
98
101
|
{
|
|
@@ -109,7 +112,7 @@ export const SECRETS_TOOLS = [
|
|
|
109
112
|
},
|
|
110
113
|
{
|
|
111
114
|
name: 'huaweicloud_secret_delete',
|
|
112
|
-
description: '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).',
|
|
115
|
+
description: '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).',
|
|
113
116
|
schema: secretDeleteSchema,
|
|
114
117
|
handler: handleSecretDelete,
|
|
115
118
|
},
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { hashArgs } from "../../lib/approval-tokens.js";
|
|
2
|
+
import { redactSecrets } from "../../safety-policy.js";
|
|
3
|
+
import { asString } from "../../lib/as-text.js";
|
|
4
|
+
import { SUPPORTED_AGENT_TARGETS } from "../../auth/agent-registration.js";
|
|
5
|
+
// The update pack's approval registration (PR-3c): huaweicloud_upgrade is
|
|
6
|
+
// ALWAYS gated — it replaces the package on disk for every installed
|
|
7
|
+
// target, which redirects every later tool call onto code the operator
|
|
8
|
+
// never reviewed, so the trunk's description-level consent line
|
|
9
|
+
// ("执行前必须先征得用户同意") becomes a mechanical gate. The binding is
|
|
10
|
+
// the {target, version} projection (never the gate fields), so the
|
|
11
|
+
// confirmation pins exactly what will be upgraded. check_update stays
|
|
12
|
+
// unregistered: it is the read-only face of the pair.
|
|
13
|
+
//
|
|
14
|
+
// Interrogate round 2, finding 2 — display/binding integrity:
|
|
15
|
+
// (a) An ABSENT version normalizes to the literal 'latest' INSIDE the
|
|
16
|
+
// binding, so the value the popup displays is the value the token
|
|
17
|
+
// binds: the natural retry with version:'latest' (what the user read)
|
|
18
|
+
// hashes identically to the unversioned mint and executes, instead
|
|
19
|
+
// of mismatch-burning the token.
|
|
20
|
+
// (b) assertArgsExecutable refuses every version shape the handler's own
|
|
21
|
+
// chain refuses (upgradePackage accepts 'latest' only): a concrete
|
|
22
|
+
// version and an empty string never mint a doomed approval.
|
|
23
|
+
// (c) 'latest' names the CHANNEL, not an artifact: the handler elects
|
|
24
|
+
// the actual tag after consent (a stable current → @latest, a
|
|
25
|
+
// prerelease current → @next). The summarize view says so. Residual,
|
|
26
|
+
// recorded: the tag can move between consent and execution (a
|
|
27
|
+
// registry publish lands mid-cycle); the consent pins the channel
|
|
28
|
+
// and the target, never the resolved artifact.
|
|
29
|
+
//
|
|
30
|
+
// Interrogate round 3, finding — the target half of the same doctrine:
|
|
31
|
+
// (a) An absent AND an empty target normalize to the literal 'all'
|
|
32
|
+
// (the handler's own default for both), so the displayed '(target
|
|
33
|
+
// all)' is the bound value and the natural retry with target:'all'
|
|
34
|
+
// consumes instead of mismatch-burning the confirmed token.
|
|
35
|
+
// (b) assertArgsExecutable also refuses targets outside the handler's
|
|
36
|
+
// SUPPORTED_AGENT_TARGETS allowlist (upgradePackage answers
|
|
37
|
+
// '不支持的升级目标' after the gate, review #717's shell-interpolation
|
|
38
|
+
// guard), so a bogus or case-variant target never mints a doomed
|
|
39
|
+
// approval.
|
|
40
|
+
function upgradeBinding(args) {
|
|
41
|
+
return {
|
|
42
|
+
target: args.target === undefined || args.target === '' ? 'all' : args.target,
|
|
43
|
+
version: args.version === undefined ? 'latest' : args.version,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function assertUpgradeExecutable(value) {
|
|
47
|
+
const { target, version } = value;
|
|
48
|
+
if (version !== 'latest') {
|
|
49
|
+
throw new Error(`version must be "latest" (got ${JSON.stringify(version)}): the handler elects the actual dist tag from the channel. Send version: "latest" or omit it.`);
|
|
50
|
+
}
|
|
51
|
+
const targetStr = String(target);
|
|
52
|
+
if (targetStr !== 'all' && !SUPPORTED_AGENT_TARGETS.includes(targetStr)) {
|
|
53
|
+
throw new Error(`不支持的升级目标:${targetStr}(有效目标:all,或 ${SUPPORTED_AGENT_TARGETS.join(', ')} 之一)`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export const UPDATE_APPROVAL_SPECS = {
|
|
57
|
+
huaweicloud_upgrade: {
|
|
58
|
+
domain: 'update',
|
|
59
|
+
flavor: 'always',
|
|
60
|
+
tokenSource: 'gate',
|
|
61
|
+
normalizeArgs: upgradeBinding,
|
|
62
|
+
assertArgsExecutable: assertUpgradeExecutable,
|
|
63
|
+
// The view folds through the shared redaction vocabulary before any
|
|
64
|
+
// field reaches the summary or pin view (the ApprovalSpec contract:
|
|
65
|
+
// never the raw argument stream); the hash binds the raw content —
|
|
66
|
+
// here the normalized content, so the displayed value IS the bound
|
|
67
|
+
// value.
|
|
68
|
+
summarize: (value) => {
|
|
69
|
+
const safe = redactSecrets(value);
|
|
70
|
+
return {
|
|
71
|
+
summary: `huaweicloud_upgrade: upgrade huaweicloud-devkit to version ${asString(safe.version) ?? 'latest'} ` +
|
|
72
|
+
`(target ${asString(safe.target) ?? 'all'}) — "latest" names the channel: the handler elects the stable ` +
|
|
73
|
+
'or prerelease dist tag (a stable current upgrades to @latest, a prerelease current to @next) after consent',
|
|
74
|
+
argsHash: hashArgs(value),
|
|
75
|
+
pinView: safe,
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { getCachedUpdateInfo, getUpdateDistTags, invalidateUpdateCache, judgeUpdate, determineTarget, readInstalledVersion, writeSkipState, resolveSkipFilePath, upgradePackage, } from "../../update-check.js";
|
|
3
|
+
import { approvalTokenArg, approvedByUserArg } from "../../lib/tool-schema-parts.js";
|
|
3
4
|
// Handlers migrated verbatim from src/tools.ts; the doQuery injection seam on
|
|
4
5
|
// CallToolOptions is passed through unchanged (test/upgrade-session.test.ts
|
|
5
6
|
// #607 depends on it reaching getUpdateDistTags/getCachedUpdateInfo).
|
|
@@ -51,6 +52,8 @@ const upgradeSchema = z.looseObject({
|
|
|
51
52
|
.string()
|
|
52
53
|
.optional()
|
|
53
54
|
.describe('agent 目标(opencode/codex/codearts/.../all)。缺省时用 all(仅更新已安装的)。'),
|
|
55
|
+
approvalToken: approvalTokenArg,
|
|
56
|
+
approvedByUser: approvedByUserArg,
|
|
54
57
|
});
|
|
55
58
|
export const UPDATE_TOOLS = [
|
|
56
59
|
{
|
|
@@ -61,7 +64,11 @@ export const UPDATE_TOOLS = [
|
|
|
61
64
|
},
|
|
62
65
|
{
|
|
63
66
|
name: 'huaweicloud_upgrade',
|
|
64
|
-
|
|
67
|
+
// The mechanical approval gate enforces the consent this line used to
|
|
68
|
+
// only ask for (PR-3c): token mode runs the approve command from the
|
|
69
|
+
// gate's rejection envelope in the user's own terminal, ask mode lets
|
|
70
|
+
// the server raise the confirmation itself.
|
|
71
|
+
description: '升级 huaweicloud-devkit 到最新版本。升级会改写磁盘上的插件本体,因此由审批门机械把关:默认 token 模式下,无 token 调用会返回 USER_CONFIRMATION_REQUIRED 与 approve 命令行,用户在自己的终端确认后才可重试;DEVKIT_APPROVAL_MODE=ask 时由服务器在调用内弹出确认(表单或聊天往返)。version 仅支持 "latest"。完成后需重启会话生效。',
|
|
65
72
|
schema: upgradeSchema,
|
|
66
73
|
handler: handleUpgrade,
|
|
67
74
|
},
|
|
@@ -56,7 +56,7 @@ const voucherClaimSchema = z.looseObject({
|
|
|
56
56
|
export const VOUCHER_TOOLS = [
|
|
57
57
|
{
|
|
58
58
|
name: 'huaweicloud_voucher_status',
|
|
59
|
-
description: '查询代金券领取状态。当会话已处于华为云任务上下文(用户已指明华为云,或先前轮次已确认)且用户首次使用或询问插件能力时,主动调用本工具检查:未领取(claimed=false)则主动提示可领取一张代金券;已领取(claimed=true
|
|
59
|
+
description: '查询代金券领取状态。当会话已处于华为云任务上下文(用户已指明华为云,或先前轮次已确认)且用户首次使用或询问插件能力时,主动调用本工具检查:未领取(claimed=false)则主动提示可领取一张代金券;已领取(claimed=true)则不提示、不打扰;claimed=false 且 code=HDKIT_VERSION_TOO_OLD 表示客户端版本过旧——转述 remediation 升级引导,绝不提示领券。厂商未定(用户未指明、上下文无法推断)时不要调用——先问用户用的是哪家云。',
|
|
60
60
|
schema: voucherStatusSchema,
|
|
61
61
|
handler: handleVoucherStatus,
|
|
62
62
|
},
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { resolveEnabledPacks, setRuntimePacksOverride, clearRuntimePacksOverride, runtimePacksOverride, } from "./packs/enable.js";
|
|
2
2
|
import { PACK_IDS } from "./lib/pack-types.js";
|
|
3
3
|
import { closePackEnablement } from "./lib/dependency-model.js";
|
|
4
|
+
import { hashArgs } from "./lib/approval-tokens.js";
|
|
5
|
+
import { redactSecrets } from "./safety-policy.js";
|
|
6
|
+
import { asString } from "./lib/as-text.js";
|
|
4
7
|
export function configurePacks(args, opts) {
|
|
5
8
|
const enable = (args.enable ?? []).map((id) => String(id));
|
|
6
9
|
const disable = (args.disable ?? []).map((id) => String(id));
|
|
@@ -79,3 +82,74 @@ export function configurePacks(args, opts) {
|
|
|
79
82
|
: 'The requested surface already applies.',
|
|
80
83
|
};
|
|
81
84
|
}
|
|
85
|
+
// The packs_configure approval registration (PR-3c). ALWAYS gated, because
|
|
86
|
+
// widening the session's disclosure face is the actual consequence — an
|
|
87
|
+
// enabled pack materializes its tools and skills for every later call — and
|
|
88
|
+
// the summarize view names the exact ids so the confirmation surface shows
|
|
89
|
+
// the consequence itself. requiresSessionSeam mirrors this handler's own
|
|
90
|
+
// stdio-only refusal: the gate checks opts.onPacksChanged BEFORE engaging
|
|
91
|
+
// (the refusal lives here, downstream of any dispatch-layer gate), so a
|
|
92
|
+
// no-seam call refuses with no token minted and no ledger entry — the
|
|
93
|
+
// ordering the gate's precheck exists to enforce. The binding is the
|
|
94
|
+
// {enable, disable, reset} projection, never the gate fields.
|
|
95
|
+
export const PACKS_CONFIGURE_APPROVAL_SPEC = {
|
|
96
|
+
domain: 'packs',
|
|
97
|
+
flavor: 'always',
|
|
98
|
+
tokenSource: 'gate',
|
|
99
|
+
requiresSessionSeam: true,
|
|
100
|
+
normalizeArgs: (args) => ({
|
|
101
|
+
enable: args.enable,
|
|
102
|
+
disable: args.disable,
|
|
103
|
+
reset: args.reset,
|
|
104
|
+
}),
|
|
105
|
+
summarize: (value) => {
|
|
106
|
+
// The view folds through the shared redaction vocabulary before any
|
|
107
|
+
// field reaches the summary or pin view (the ApprovalSpec contract);
|
|
108
|
+
// the hash binds the raw content.
|
|
109
|
+
const safe = redactSecrets(value);
|
|
110
|
+
const list = (ids) => Array.isArray(ids) ? ids.map((id) => String(id)).join(', ') : (asString(ids) ?? '');
|
|
111
|
+
const parts = [];
|
|
112
|
+
if (Array.isArray(safe.enable) && safe.enable.length > 0)
|
|
113
|
+
parts.push(`enable pack(s) ${list(safe.enable)}`);
|
|
114
|
+
if (Array.isArray(safe.disable) && safe.disable.length > 0)
|
|
115
|
+
parts.push(`disable pack(s) ${list(safe.disable)}`);
|
|
116
|
+
if (safe.reset === true)
|
|
117
|
+
parts.push('reset the session override (restore the operator DEVKIT_PACKS posture)');
|
|
118
|
+
if (parts.length === 0)
|
|
119
|
+
parts.push('no-op: provide enable, disable, or reset');
|
|
120
|
+
return {
|
|
121
|
+
summary: `huaweicloud_packs_configure: ${parts.join('; ')}`,
|
|
122
|
+
argsHash: hashArgs(value),
|
|
123
|
+
pinView: safe,
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
// NoDoomedToken (interrogate round 2, fix-in-pass i): the handler's own
|
|
127
|
+
// five pure validations, hoisted BEFORE the mint — a shape the handler
|
|
128
|
+
// refuses would burn the user's approval on a guaranteed refusal, so it
|
|
129
|
+
// never mints. Message texts mirror the handler's exactly, so the two
|
|
130
|
+
// layers can never drift into different teachings; the handler keeps its
|
|
131
|
+
// own copies as the belt behind this floor.
|
|
132
|
+
assertArgsExecutable: (value) => {
|
|
133
|
+
const { enable, disable, reset } = value;
|
|
134
|
+
const enableIds = Array.isArray(enable) ? enable.map((id) => String(id)) : [];
|
|
135
|
+
const disableIds = Array.isArray(disable) ? disable.map((id) => String(id)) : [];
|
|
136
|
+
const resetIs = reset === true;
|
|
137
|
+
if (!resetIs && enableIds.length === 0 && disableIds.length === 0) {
|
|
138
|
+
throw new Error('Provide at least one of enable, disable, or reset.');
|
|
139
|
+
}
|
|
140
|
+
const bogus = [...enableIds, ...disableIds].filter((id) => !PACK_IDS.includes(id));
|
|
141
|
+
if (bogus.length > 0) {
|
|
142
|
+
throw new Error('Unknown pack id(s): ' + bogus.join(', ') + '. Valid pack ids: ' + PACK_IDS.join(', ') + '.');
|
|
143
|
+
}
|
|
144
|
+
if (disableIds.includes('core')) {
|
|
145
|
+
throw new Error('core is always enabled (the pack meta, safety, and discovery surface is force-included) and cannot be disabled.');
|
|
146
|
+
}
|
|
147
|
+
const overlap = enableIds.filter((id) => disableIds.includes(id));
|
|
148
|
+
if (overlap.length > 0) {
|
|
149
|
+
throw new Error('Pack id(s) cannot be both enabled and disabled in one call: ' + overlap.join(', ') + '.');
|
|
150
|
+
}
|
|
151
|
+
if (resetIs && (enableIds.length > 0 || disableIds.length > 0)) {
|
|
152
|
+
throw new Error('reset drops the whole session override and cannot be combined with enable or disable.');
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
@@ -831,6 +831,42 @@ export function classifyTextCommand(command, options = {}) {
|
|
|
831
831
|
reason: "Running the approval CLI from the agent Bash face is blocked: the confirmation must come from the user's own interactive terminal, where the PIN is checked. Ask the user to run the printed npx huaweicloud-devkit approve <token> line themselves (first use: npx huaweicloud-devkit pin, once), then retry the same call.",
|
|
832
832
|
};
|
|
833
833
|
}
|
|
834
|
+
// The account-switch CLI verbs (interrogate round 1, finding 1): `auth
|
|
835
|
+
// init`/`auth sync` write S1, the OBS config, and the KooCLI profile —
|
|
836
|
+
// the same account switch the MCP tools gate behind a human present
|
|
837
|
+
// (PR-3b). The hook blocks raw `hcloud configure set`, but the devkit's
|
|
838
|
+
// own wrapper was an open bypass: an agent that shells out to
|
|
839
|
+
// `npx huaweicloud-devkit auth init` switches every downstream approved
|
|
840
|
+
// write's account with no confirmation at all. Same anchoring doctrine
|
|
841
|
+
// as approve/pin: the patterns require a devkit binary spelling, so an
|
|
842
|
+
// hcloud operation or a plain file named auth-init never trips, and the
|
|
843
|
+
// read-only `auth status` stays allowed for the agent.
|
|
844
|
+
if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedAccountSwitchCliPatterns))) {
|
|
845
|
+
return {
|
|
846
|
+
decision: 'deny',
|
|
847
|
+
risk: 'approval',
|
|
848
|
+
reason: "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.",
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
// The devkit's gated-mutation CLI twins (interrogate round 1, finding 1):
|
|
852
|
+
// `update`/`upgrade` rewrite the installed package, `secret rm` deletes a
|
|
853
|
+
// vault entry, and `packs enable|disable|all` rewrites the operator
|
|
854
|
+
// DEVKIT_PACKS posture — the exact mutations the MCP approval gate
|
|
855
|
+
// mediates on huaweicloud_upgrade, huaweicloud_secret_delete, and
|
|
856
|
+
// huaweicloud_packs_configure. The CLI path carries no gate at all, so an
|
|
857
|
+
// agent shelling to it performs the mutation with zero confirmation —
|
|
858
|
+
// the same bypass class the auth verbs established. The row shape mirrors
|
|
859
|
+
// the approve/pin family (a devkit bin spelling must be present, so a
|
|
860
|
+
// Huawei Cloud operation or a benign sentence containing the verb never
|
|
861
|
+
// trips), matched against the same two shadows. A human at their own
|
|
862
|
+
// terminal is unaffected: this is the agent Bash face.
|
|
863
|
+
if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedGatedCliPatterns))) {
|
|
864
|
+
return {
|
|
865
|
+
decision: 'deny',
|
|
866
|
+
risk: 'approval',
|
|
867
|
+
reason: '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.',
|
|
868
|
+
};
|
|
869
|
+
}
|
|
834
870
|
// Order-independent reveal pair: `echo secret get <ref> --stdout | xargs
|
|
835
871
|
// npx huaweicloud-devkit` reorders the argv through xargs while every word
|
|
836
872
|
// is literal in the text — the patterns above assume bin-before-
|