huaweicloud-devkit 2.0.1-next.2 → 2.0.1-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 +26 -3
- package/README.zh-CN.md +24 -1
- package/package.json +1 -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 +3 -0
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/approval-roster.js +2 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +7 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +30 -1
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +21 -0
- package/plugins/huaweicloud-core/dist/mcp-server.js +4227 -3049
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/registry.js +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +13 -2
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +198 -10
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +11 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +22 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +46 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-upload.js +11 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +20 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +26 -18
- package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +97 -0
- package/plugins/huaweicloud-core/dist/sandbox/deploy-nginx.js +30 -14
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-backend.js +37 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-connections.js +84 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-client.js +229 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-protocol.js +151 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-transport.js +121 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-service-api.js +80 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-upload.js +106 -0
- package/plugins/huaweicloud-core/dist/sandbox/hwlink-connection.js +12 -0
- package/plugins/huaweicloud-core/dist/sandbox/upload-project.js +5 -2
- package/plugins/huaweicloud-core/dist/server-install.js +363 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +16 -0
- package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
- package/plugins/huaweicloud-core/dist/tools.js +1 -0
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/policy.json +2 -1
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +67 -16
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/devbox-backend.md +78 -0
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +14 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +2 -1
- package/plugins/huaweicloud-core/src/approval-roster.ts +2 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +7 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +30 -1
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +22 -0
- package/plugins/huaweicloud-core/src/mcp-server-remote.ts +68 -5
- package/plugins/huaweicloud-core/src/mcp-server.ts +4 -1
- package/plugins/huaweicloud-core/src/packs/registry.ts +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +15 -2
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +206 -11
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +12 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +23 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +49 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-upload.ts +11 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +23 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +27 -17
- package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +105 -0
- package/plugins/huaweicloud-core/src/sandbox/deploy-nginx.ts +36 -18
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-backend.ts +44 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-connections.ts +115 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-client.ts +281 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-protocol.ts +180 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-transport.ts +142 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-service-api.ts +102 -0
- package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-upload.ts +167 -0
- package/plugins/huaweicloud-core/src/sandbox/hwlink-connection.ts +12 -0
- package/plugins/huaweicloud-core/src/sandbox/upload-project.ts +5 -2
- package/plugins/huaweicloud-core/src/server-install.ts +442 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +16 -0
- package/plugins/huaweicloud-core/src/tool-definitions.ts +4 -0
- package/plugins/huaweicloud-core/src/tools.ts +3 -0
|
@@ -77,6 +77,7 @@ export const PACK_OF = {
|
|
|
77
77
|
huaweicloud_sandbox_connect: 'sandbox',
|
|
78
78
|
huaweicloud_sandbox_credentials: 'sandbox',
|
|
79
79
|
huaweicloud_sandbox_shutdown: 'sandbox',
|
|
80
|
+
huaweicloud_sandbox_kill: 'sandbox',
|
|
80
81
|
huaweicloud_voucher_status: 'voucher',
|
|
81
82
|
huaweicloud_voucher_claim: 'voucher',
|
|
82
83
|
huaweicloud_competition_voucher_claim: 'voucher',
|
|
@@ -4,10 +4,10 @@ import { classifyTextCommand, redactSecrets } from "../../safety-policy.js";
|
|
|
4
4
|
import { evaluateCommandRisk, loadRiskRules } from "../../risk-rule-engine.js";
|
|
5
5
|
import { redactWithSupplementalKeys } from "../../lib/supplemental-redaction.js";
|
|
6
6
|
import { isSecretRef } from "../../lib/secret-vault/refs.js";
|
|
7
|
-
// The sandbox pack's approval spec table.
|
|
7
|
+
// The sandbox pack's approval spec table. Ten tools join the gate: the two
|
|
8
8
|
// exec faces are CLASSIFIED (content decides — a benign command runs with no
|
|
9
9
|
// confirmation surface at all, a write-classified one confirms on every
|
|
10
|
-
// call), the
|
|
10
|
+
// call), the eight mutating lifecycle faces are ALWAYS (a human present per
|
|
11
11
|
// call, no content rule ever exempts them). The strict classification runs
|
|
12
12
|
// on the exec faces' `command` argument through the SAME engines the Bash
|
|
13
13
|
// face uses — classifyTextCommand plus the cloud-risk-rules catalog — so a
|
|
@@ -232,6 +232,16 @@ const shutdownSpec = {
|
|
|
232
232
|
return `huaweicloud_sandbox_shutdown: shut down the sandbox (close only — instance retained, reconnect wakes it)${target !== '' ? ` (${target})` : ''}`;
|
|
233
233
|
}),
|
|
234
234
|
};
|
|
235
|
+
// kill = devbox-only DELETE (irreversible). The confirmation view must say
|
|
236
|
+
// delete, not close: shutdown keeps the instance, kill does not.
|
|
237
|
+
const killSpec = {
|
|
238
|
+
...sandboxBinding(),
|
|
239
|
+
flavor: 'always',
|
|
240
|
+
summarize: (bindingValue) => viewOf(bindingValue, (view) => {
|
|
241
|
+
const target = fieldEcho(view, ['session_id', 'dev_stage_id', 'workspace_id']);
|
|
242
|
+
return `huaweicloud_sandbox_kill: DELETE the devbox sandbox permanently (irreversible — use shutdown to keep the instance)${target !== '' ? ` (${target})` : ''}`;
|
|
243
|
+
}),
|
|
244
|
+
};
|
|
235
245
|
export const SANDBOX_APPROVAL_SPECS = {
|
|
236
246
|
huaweicloud_sandbox_connect: connectSpec,
|
|
237
247
|
huaweicloud_sandbox_exec_with_session: execSpec('exec_with_session'),
|
|
@@ -242,4 +252,5 @@ export const SANDBOX_APPROVAL_SPECS = {
|
|
|
242
252
|
huaweicloud_sandbox_sign_agreement: signAgreementSpec,
|
|
243
253
|
huaweicloud_sandbox_credentials: credentialsSpec,
|
|
244
254
|
huaweicloud_sandbox_shutdown: shutdownSpec,
|
|
255
|
+
huaweicloud_sandbox_kill: killSpec,
|
|
245
256
|
};
|
|
@@ -4,6 +4,9 @@ import { hdkitCheckUser, hdkitSignAgreement, hdkitConnectWithRetry, hdkitShutdow
|
|
|
4
4
|
import { MANUFACTURED_FAMILY, manufacturedPrefixPattern, canonCode, chainDataValue, cleanMessage, ownDataValue, safeMessageText, safeReadField, serializableRemediation, transientExhaustionResult, versionGateResult, } from "../../lib/hdkit/hdkit-gate.js";
|
|
5
5
|
import { asString } from "../../lib/as-text.js";
|
|
6
6
|
import { validatePoolType, rememberWorkspacePool, shouldAnnounceConnect, enrichConnectResult, } from "../../lib/hdkit/sandbox-pool.js";
|
|
7
|
+
import { backendForWorkspace, isDevboxBackend, rememberWorkspaceBackend, sandboxBackend, forgetWorkspaceBackend, } from "../../sandbox/devbox/devbox-backend.js";
|
|
8
|
+
import { clearDevboxConnection, getDevboxConnection, setDevboxConnectionFromResponse, } from "../../sandbox/devbox/devbox-connections.js";
|
|
9
|
+
import { devboxConnect, devboxKill, devboxShutdown } from "../../sandbox/devbox/devbox-service-api.js";
|
|
7
10
|
import { transferGitRepo } from "./git-transfer.js";
|
|
8
11
|
// Account/session-gate handlers (check_user, sign_agreement, connect,
|
|
9
12
|
// shutdown) for the sandbox pack, extracted verbatim from tools.ts in the
|
|
@@ -12,6 +15,17 @@ import { transferGitRepo } from "./git-transfer.js";
|
|
|
12
15
|
// chain invocation (git-transfer.ts); handleShutdown owns the DevStation
|
|
13
16
|
// close face (dev 5d89c880 + 3bfc1f53 tip state).
|
|
14
17
|
export async function handleCheckUser(_args = {}, _opts = {}) {
|
|
18
|
+
if (isDevboxBackend()) {
|
|
19
|
+
return {
|
|
20
|
+
ok: true,
|
|
21
|
+
backend: 'devbox',
|
|
22
|
+
skipped: true,
|
|
23
|
+
checked: false,
|
|
24
|
+
realnameVerified: null,
|
|
25
|
+
agreementSigned: null,
|
|
26
|
+
hint: 'devbox 后端不经过 DevStation 的实名/协议门禁,本次未做任何实名校验。',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
15
29
|
try {
|
|
16
30
|
return await hdkitCheckUser();
|
|
17
31
|
}
|
|
@@ -25,6 +39,16 @@ export async function handleCheckUser(_args = {}, _opts = {}) {
|
|
|
25
39
|
}
|
|
26
40
|
}
|
|
27
41
|
export async function handleSignAgreement(_args = {}, _opts = {}) {
|
|
42
|
+
if (isDevboxBackend()) {
|
|
43
|
+
return {
|
|
44
|
+
ok: true,
|
|
45
|
+
backend: 'devbox',
|
|
46
|
+
skipped: true,
|
|
47
|
+
signed: false,
|
|
48
|
+
signedCount: 0,
|
|
49
|
+
hint: 'devbox 后端不经过 DevStation 的协议门禁;无需签署,也没有代签。',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
28
52
|
try {
|
|
29
53
|
return await hdkitSignAgreement();
|
|
30
54
|
}
|
|
@@ -35,7 +59,120 @@ export async function handleSignAgreement(_args = {}, _opts = {}) {
|
|
|
35
59
|
throw error;
|
|
36
60
|
}
|
|
37
61
|
}
|
|
62
|
+
// Devbox control-plane failures: the MCP error envelope only carries code +
|
|
63
|
+
// message, so remediation/retry fields must be returned structurally.
|
|
64
|
+
function devboxErrorResult(error) {
|
|
65
|
+
const gate = versionGateResult(error);
|
|
66
|
+
if (gate)
|
|
67
|
+
return gate;
|
|
68
|
+
const exhausted = transientExhaustionResult(error);
|
|
69
|
+
if (exhausted)
|
|
70
|
+
return exhausted;
|
|
71
|
+
const rawCode = safeReadField(error, 'code');
|
|
72
|
+
const code = typeof rawCode === 'string' && rawCode !== '' ? rawCode : undefined;
|
|
73
|
+
if (!code)
|
|
74
|
+
return undefined;
|
|
75
|
+
const message = cleanMessage(safeMessageText(error)) || 'hdkitservice error';
|
|
76
|
+
const rawRetryAfter = ownDataValue(error, 'retryAfter');
|
|
77
|
+
const retryAfter = typeof rawRetryAfter === 'string' ? rawRetryAfter : undefined;
|
|
78
|
+
const remediation = serializableRemediation(ownDataValue(error, 'remediation'));
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
code,
|
|
82
|
+
message,
|
|
83
|
+
...(retryAfter ? { retryAfter } : {}),
|
|
84
|
+
...(remediation ? { remediation } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Strip the single-sandbox EnvD data-plane credentials from anything that can
|
|
88
|
+
// reach a tool result. They live only in the process-memory connection cache.
|
|
89
|
+
function sanitizeDevboxConnectResult(result) {
|
|
90
|
+
const safe = {};
|
|
91
|
+
for (const key of [
|
|
92
|
+
'backend',
|
|
93
|
+
'session_id',
|
|
94
|
+
'dev_stage_id',
|
|
95
|
+
'sandbox_id',
|
|
96
|
+
'state',
|
|
97
|
+
'template_id',
|
|
98
|
+
'end_at',
|
|
99
|
+
'token_expiration',
|
|
100
|
+
'envd_version',
|
|
101
|
+
'pool_type',
|
|
102
|
+
'started',
|
|
103
|
+
'pause_retention_hours',
|
|
104
|
+
]) {
|
|
105
|
+
if (result[key] !== undefined)
|
|
106
|
+
safe[key] = result[key];
|
|
107
|
+
}
|
|
108
|
+
safe.backend = 'devbox';
|
|
109
|
+
safe.pool_type = 'ephemeral';
|
|
110
|
+
return safe;
|
|
111
|
+
}
|
|
112
|
+
async function handleDevboxConnect(args) {
|
|
113
|
+
const rawPool = args.pool_type;
|
|
114
|
+
if (rawPool !== undefined && rawPool !== null && rawPool !== '') {
|
|
115
|
+
let poolType;
|
|
116
|
+
try {
|
|
117
|
+
poolType = validatePoolType(rawPool);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return { ok: false, code: 'HDKIT_INVALID_POOL_TYPE', message: error.message };
|
|
121
|
+
}
|
|
122
|
+
if (poolType !== 'ephemeral') {
|
|
123
|
+
return {
|
|
124
|
+
ok: false,
|
|
125
|
+
code: 'HDKIT_BACKEND_UNSUPPORTED',
|
|
126
|
+
message: 'devbox 后端暂不支持 pool_type=persistent,仅支持 ephemeral。',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const envVars = args.env && typeof args.env === 'object' && !Array.isArray(args.env)
|
|
131
|
+
? Object.fromEntries(Object.entries(args.env).map(([k, v]) => [k, String(v)]))
|
|
132
|
+
: undefined;
|
|
133
|
+
let result;
|
|
134
|
+
try {
|
|
135
|
+
result = await devboxConnect({
|
|
136
|
+
timeoutSeconds: typeof args.timeout_seconds === 'number' ? args.timeout_seconds : undefined,
|
|
137
|
+
source: typeof args.source === 'string' ? args.source : undefined,
|
|
138
|
+
envVars,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
const folded = devboxErrorResult(error);
|
|
143
|
+
if (folded)
|
|
144
|
+
return folded;
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
const sandboxId = (typeof result.sandbox_id === 'string' && result.sandbox_id) ||
|
|
148
|
+
(typeof result.session_id === 'string' && result.session_id) ||
|
|
149
|
+
(typeof result.dev_stage_id === 'string' && result.dev_stage_id) ||
|
|
150
|
+
'';
|
|
151
|
+
if (!sandboxId) {
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
code: 'HDKIT_DEVBOX_CREATE_FAILED',
|
|
155
|
+
message: 'hdkitservice devbox connect response did not include a sandbox id.',
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const firstConnection = !getDevboxConnection(sandboxId);
|
|
159
|
+
const connection = setDevboxConnectionFromResponse(sandboxId, result);
|
|
160
|
+
setWorkspaceId(sandboxId);
|
|
161
|
+
rememberWorkspaceBackend(sandboxId, 'devbox');
|
|
162
|
+
const safe = sanitizeDevboxConnectResult(result);
|
|
163
|
+
if (args.git !== undefined && args.git !== null) {
|
|
164
|
+
safe.warning =
|
|
165
|
+
'devbox v1 create 不接受 git:本次没有自动 clone。请在 connect 后用 exec_one_shot 自行 clone,或使用 upload_project。';
|
|
166
|
+
}
|
|
167
|
+
if (connection.started)
|
|
168
|
+
safe.started = true;
|
|
169
|
+
const announce = firstConnection || connection.started === true;
|
|
170
|
+
return enrichConnectResult(safe, { announce });
|
|
171
|
+
}
|
|
38
172
|
export async function handleConnect(args = {}, _opts = {}) {
|
|
173
|
+
if (sandboxBackend() === 'devbox') {
|
|
174
|
+
return await handleDevboxConnect(args);
|
|
175
|
+
}
|
|
39
176
|
// 两池:客户端校验 pool_type(非法值在本地即报错,不发无效请求);未传交由服务端默认 ephemeral
|
|
40
177
|
const connectArgs = { ...args };
|
|
41
178
|
let poolType;
|
|
@@ -201,20 +338,44 @@ function shutdownErrorResult(error) {
|
|
|
201
338
|
...(err.remediation ? { remediation: err.remediation } : {}),
|
|
202
339
|
};
|
|
203
340
|
}
|
|
204
|
-
|
|
341
|
+
// Shared by the lifecycle faces that need a sandbox id (shutdown/kill).
|
|
342
|
+
function missingSandboxIdResult() {
|
|
343
|
+
return {
|
|
344
|
+
ok: false,
|
|
345
|
+
code: 'HDKIT_INVALID_REQUEST',
|
|
346
|
+
message: 'session_id or dev_stage_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, or pass workspace_id.',
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
// Shared id resolution for shutdown/kill (3bfc1f53): workspaceId and devStageId
|
|
350
|
+
// are separate aliases; a session_id-only call leaves devStageId empty so the
|
|
351
|
+
// legacy terminal session is closed with the server-returned devStageId.
|
|
352
|
+
function lifecycleIds(args) {
|
|
205
353
|
const sessionId = args.session_id;
|
|
206
|
-
// 3bfc1f53:workspaceId 与 devStageId 分开解析。仅 session_id 时 devStageId
|
|
207
|
-
// 留空(不把 session_id 字符串当 workspace 用),终端会话以服务端回传的
|
|
208
|
-
// devStageId 为准关闭。
|
|
209
354
|
const workspaceId = args.dev_stage_id || args.workspace_id || getCurrentWorkspaceId();
|
|
210
355
|
const devStageId = args.dev_stage_id || args.workspace_id || (sessionId ? undefined : workspaceId);
|
|
211
|
-
|
|
356
|
+
return { sessionId, workspaceId, devStageId, id: sessionId || devStageId };
|
|
357
|
+
}
|
|
358
|
+
export async function handleShutdown(args = {}, _opts = {}) {
|
|
359
|
+
const { sessionId, workspaceId, devStageId, id } = lifecycleIds(args);
|
|
212
360
|
if (!id) {
|
|
213
|
-
return
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
361
|
+
return missingSandboxIdResult();
|
|
362
|
+
}
|
|
363
|
+
const backend = backendForWorkspace(typeof id === 'string' ? id : undefined);
|
|
364
|
+
if (backend === 'devbox') {
|
|
365
|
+
const sandboxId = typeof id === 'string' ? id : '';
|
|
366
|
+
try {
|
|
367
|
+
const shutdown = await devboxShutdown(sandboxId);
|
|
368
|
+
// Paused sandboxes need a fresh connect before any further exec; drop the
|
|
369
|
+
// stale in-memory EnvD tokens (the backend pin stays for kill/status).
|
|
370
|
+
clearDevboxConnection(sandboxId);
|
|
371
|
+
return { ok: true, backend: 'devbox', ...shutdown };
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
const folded = devboxErrorResult(error);
|
|
375
|
+
if (folded)
|
|
376
|
+
return folded;
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
218
379
|
}
|
|
219
380
|
try {
|
|
220
381
|
const shutdown = await hdkitShutdown(sessionId, devStageId);
|
|
@@ -235,3 +396,30 @@ export async function handleShutdown(args = {}, _opts = {}) {
|
|
|
235
396
|
return shutdownErrorResult(error);
|
|
236
397
|
}
|
|
237
398
|
}
|
|
399
|
+
/** kill = devbox-only delete; legacy returns HDKIT_BACKEND_UNSUPPORTED (2A). */
|
|
400
|
+
export async function handleKill(args = {}, _opts = {}) {
|
|
401
|
+
const { id } = lifecycleIds(args);
|
|
402
|
+
if (!id || typeof id !== 'string') {
|
|
403
|
+
return missingSandboxIdResult();
|
|
404
|
+
}
|
|
405
|
+
if (backendForWorkspace(id) !== 'devbox') {
|
|
406
|
+
return {
|
|
407
|
+
ok: false,
|
|
408
|
+
code: 'HDKIT_BACKEND_UNSUPPORTED',
|
|
409
|
+
message: 'kill is devbox-only. On the legacy DevStation backend use huaweicloud_sandbox_shutdown (pause) instead; ' +
|
|
410
|
+
'the legacy backend does not expose delete.',
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
const killed = await devboxKill(id);
|
|
415
|
+
clearDevboxConnection(id);
|
|
416
|
+
forgetWorkspaceBackend(id);
|
|
417
|
+
return { ok: true, backend: 'devbox', ...killed };
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
const folded = devboxErrorResult(error);
|
|
421
|
+
if (folded)
|
|
422
|
+
return folded;
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
import { execOneShot, execWithSession, getCurrentWorkspaceId } from "../../sandbox/session-manager.js";
|
|
3
|
+
import { backendForWorkspace } from "../../sandbox/devbox/devbox-backend.js";
|
|
3
4
|
import { hdkitCredentials } from "../../lib/hdkit/hdkitservice-api.js";
|
|
4
5
|
import { versionGateResult } from "../../lib/hdkit/hdkit-gate.js";
|
|
5
6
|
import { getCredentials } from "../../lib/hdkit/hwlink-api.js";
|
|
@@ -21,6 +22,16 @@ function shellSingleQuote(value) {
|
|
|
21
22
|
}
|
|
22
23
|
export async function handleCredentials(args = {}, _opts = {}) {
|
|
23
24
|
const devStageId = args.dev_stage_id || getCurrentWorkspaceId();
|
|
25
|
+
if (backendForWorkspace(typeof devStageId === 'string' ? devStageId : undefined) === 'devbox') {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
backend: 'devbox',
|
|
29
|
+
code: 'HDKIT_BACKEND_UNSUPPORTED',
|
|
30
|
+
message: 'credentials (DevStation auto-config / DevBridge key injection) is not supported on the devbox backend.',
|
|
31
|
+
hint: 'Use connect envVars for environment variables, or write /tmp files with exec_one_shot. ' +
|
|
32
|
+
'devbox preview does not use DevBridge tunnels or API keys.',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
24
35
|
let resolved;
|
|
25
36
|
let resolveError;
|
|
26
37
|
try {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execWithSession, execOneShot, closeSession, getCurrentWorkspaceId } from "../../sandbox/session-manager.js";
|
|
2
|
+
import { backendForWorkspace } from "../../sandbox/devbox/devbox-backend.js";
|
|
2
3
|
import { forgetWorkspacePool } from "../../lib/hdkit/sandbox-pool.js";
|
|
3
4
|
import { SANDBOX_TIMEOUT_MS } from "./schemas.js";
|
|
4
5
|
import { startHwexecTask } from "./handlers-hwexec.js";
|
|
@@ -16,6 +17,17 @@ export async function handleExecWithSession(args = {}, _opts = {}) {
|
|
|
16
17
|
const sandboxUser2 = args.username || 'root';
|
|
17
18
|
const sandboxTimeout2 = args.timeout_ms || SANDBOX_TIMEOUT_MS.exec_with_session;
|
|
18
19
|
const sandboxResult2 = await execWithSession(sandboxWsId2, args.command || '', sandboxUser2, sandboxTimeout2);
|
|
20
|
+
if (backendForWorkspace(sandboxWsId2) === 'devbox') {
|
|
21
|
+
return {
|
|
22
|
+
stdout: sandboxResult2.stdout,
|
|
23
|
+
exitCode: sandboxResult2.exitCode,
|
|
24
|
+
backend: 'devbox',
|
|
25
|
+
degraded: true,
|
|
26
|
+
statePersisted: false,
|
|
27
|
+
hint: 'devbox 后端不保留 shell 状态:本次只是 one-shot 执行,cd/env/变量不会跨调用。' +
|
|
28
|
+
'命令必须自包含(cd ... && ...、source ...; ...),需要跨调用状态请使用 legacy 后端。',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
19
31
|
return {
|
|
20
32
|
stdout: sandboxResult2.stdout,
|
|
21
33
|
exitCode: sandboxResult2.exitCode,
|
|
@@ -48,6 +60,16 @@ export async function handleCloseSession(args = {}, _opts = {}) {
|
|
|
48
60
|
throw new Error('workspace_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, ' +
|
|
49
61
|
'or set HW_WORKSPACE_ID environment variable before starting the agent.');
|
|
50
62
|
}
|
|
63
|
+
if (backendForWorkspace(sandboxWsId4) === 'devbox') {
|
|
64
|
+
// Devbox v1 has no terminal session to close; the sandbox itself is NOT
|
|
65
|
+
// deleted (use shutdown/kill for lifecycle control).
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
backend: 'devbox',
|
|
69
|
+
not_applicable: true,
|
|
70
|
+
message: 'close_session is not applicable on devbox (no terminal session exists); the sandbox is left untouched.',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
51
73
|
const sandboxUser4 = args.username || 'root';
|
|
52
74
|
const closed = await closeSession(sandboxWsId4, sandboxUser4);
|
|
53
75
|
if (closed) {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { exposeTunnel, renewTunnel, installKeepaliveWatchdog, validateTunnelId, } from "../../sandbox/devbridge-tunnel.js";
|
|
2
2
|
import { getCurrentWorkspaceId } from "../../sandbox/session-manager.js";
|
|
3
|
+
import { backendForWorkspace } from "../../sandbox/devbox/devbox-backend.js";
|
|
4
|
+
import { requireDevboxConnection } from "../../sandbox/devbox/devbox-connections.js";
|
|
5
|
+
import { devboxAppPortUrl, probeDevboxAppUrl } from "../../sandbox/devbox/devbox-envd-client.js";
|
|
3
6
|
import { validateTunnelPort } from "../../sandbox/devbridge-validation.js";
|
|
4
7
|
import { poolContextFor } from "../../lib/hdkit/sandbox-pool.js";
|
|
5
8
|
import { startExposeTask, pollExposeTask } from "./expose-task.js";
|
|
@@ -19,6 +22,30 @@ export async function handleExposeTunnel(args = {}, _opts = {}) {
|
|
|
19
22
|
}
|
|
20
23
|
const sandboxUser9 = args.username || 'root';
|
|
21
24
|
const sandboxTimeout9 = args.timeout_ms || SANDBOX_TIMEOUT_MS.expose_tunnel;
|
|
25
|
+
if (backendForWorkspace(sandboxWsId9) === 'devbox') {
|
|
26
|
+
// devbox preview: the platform app-port URL is returned directly. No
|
|
27
|
+
// DevBridge tunnel, no keepalive, no DevBridge API key.
|
|
28
|
+
const connection = requireDevboxConnection(sandboxWsId9);
|
|
29
|
+
const port = validateTunnelPort(args.port);
|
|
30
|
+
const publicUrl = devboxAppPortUrl(connection.envdUrl, port);
|
|
31
|
+
const probe = await probeDevboxAppUrl(connection.envdUrl, port, 10000);
|
|
32
|
+
return {
|
|
33
|
+
ok: true,
|
|
34
|
+
backend: 'devbox',
|
|
35
|
+
port,
|
|
36
|
+
publicUrl,
|
|
37
|
+
url: publicUrl,
|
|
38
|
+
accessible: probe.ok,
|
|
39
|
+
...(probe.ok
|
|
40
|
+
? {}
|
|
41
|
+
: {
|
|
42
|
+
warning: `The app-port URL was returned but the client probe got HTTP ${probe.status || 'unreachable'}. ` +
|
|
43
|
+
'Verify the app is running and bound to 0.0.0.0 (not 127.0.0.1), then probe again.',
|
|
44
|
+
}),
|
|
45
|
+
hint: 'devbox preview is a single public port: expose one app port per sandbox and bind the app to 0.0.0.0. ' +
|
|
46
|
+
'No tunnel renewal/keepalive is needed on devbox.',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
22
49
|
const exposePoolContext = poolContextFor(sandboxWsId9);
|
|
23
50
|
const exposeArgs = {
|
|
24
51
|
port: validateTunnelPort(args.port),
|
|
@@ -47,7 +74,20 @@ export async function handleExposeTunnel(args = {}, _opts = {}) {
|
|
|
47
74
|
}
|
|
48
75
|
return await exposeTunnel(sandboxWsId9, exposeArgs, sandboxUser9, sandboxTimeout9);
|
|
49
76
|
}
|
|
77
|
+
function devboxTunnelNotApplicable() {
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
backend: 'devbox',
|
|
81
|
+
code: 'HDKIT_BACKEND_UNSUPPORTED',
|
|
82
|
+
reason: 'not_applicable',
|
|
83
|
+
message: 'This operation is not applicable on the devbox backend.',
|
|
84
|
+
hint: 'devbox expose_tunnel returns the app-port URL synchronously; there is no DevBridge tunnel to poll, renew, or keep alive.',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
50
87
|
export async function handleExposePoll(args = {}, _opts = {}) {
|
|
88
|
+
if (backendForWorkspace(args.workspace_id || getCurrentWorkspaceId()) === 'devbox') {
|
|
89
|
+
return devboxTunnelNotApplicable();
|
|
90
|
+
}
|
|
51
91
|
const taskId = args.task_id;
|
|
52
92
|
if (typeof taskId !== 'string' || taskId === '') {
|
|
53
93
|
throw new Error('task_id is required — pass the taskId returned by huaweicloud_sandbox_expose_tunnel mode:"async".');
|
|
@@ -55,6 +95,9 @@ export async function handleExposePoll(args = {}, _opts = {}) {
|
|
|
55
95
|
return pollExposeTask(taskId);
|
|
56
96
|
}
|
|
57
97
|
export async function handleRenewTunnel(args = {}, _opts = {}) {
|
|
98
|
+
if (backendForWorkspace(args.workspace_id || getCurrentWorkspaceId()) === 'devbox') {
|
|
99
|
+
return devboxTunnelNotApplicable();
|
|
100
|
+
}
|
|
58
101
|
if (!args.tunnel_id) {
|
|
59
102
|
throw new Error('tunnel_id is required. Get it from huaweicloud_sandbox_expose_tunnel or extract it from the public URL (https://<tunnel_id>-<port>.devbridge-s2.hwtunnel.com).');
|
|
60
103
|
}
|
|
@@ -69,6 +112,9 @@ export async function handleRenewTunnel(args = {}, _opts = {}) {
|
|
|
69
112
|
return await renewTunnel(wsId, { tunnelId: args.tunnel_id, expiryHours: typeof args.expiry_hours === 'number' ? args.expiry_hours : undefined }, args.username || 'root', args.timeout_ms || SANDBOX_TIMEOUT_MS.renew_tunnel);
|
|
70
113
|
}
|
|
71
114
|
export async function handleKeepaliveWatchdog(args = {}, _opts = {}) {
|
|
115
|
+
if (backendForWorkspace(args.workspace_id || getCurrentWorkspaceId()) === 'devbox') {
|
|
116
|
+
return devboxTunnelNotApplicable();
|
|
117
|
+
}
|
|
72
118
|
if (!Array.isArray(args.tunnels) || args.tunnels.length === 0) {
|
|
73
119
|
throw new Error('tunnels is required — a non-empty array of {tunnel_id, url} from huaweicloud_sandbox_expose_tunnel results.');
|
|
74
120
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { uploadFileWithSession, uploadProjectWithSession, getCurrentWorkspaceId, } from "../../sandbox/session-manager.js";
|
|
2
|
+
import { backendForWorkspace } from "../../sandbox/devbox/devbox-backend.js";
|
|
3
|
+
import { uploadFileDevbox, uploadProjectDevbox } from "../../sandbox/devbox/devbox-upload.js";
|
|
2
4
|
import { SANDBOX_TIMEOUT_MS } from "./schemas.js";
|
|
3
5
|
// Upload handlers for the sandbox pack, extracted verbatim from tools.ts in
|
|
4
6
|
// the within-pack split for the jscpd complex-file bar; the tools.ts face
|
|
@@ -14,6 +16,9 @@ export async function handleUploadFile(args = {}, _opts = {}) {
|
|
|
14
16
|
}
|
|
15
17
|
const sandboxUser5 = args.username || 'root';
|
|
16
18
|
const sandboxTimeout5 = args.timeout_ms || SANDBOX_TIMEOUT_MS.upload_file;
|
|
19
|
+
if (backendForWorkspace(sandboxWsId5) === 'devbox') {
|
|
20
|
+
return await uploadFileDevbox(sandboxWsId5, args.local_path, args.remote_path, sandboxTimeout5);
|
|
21
|
+
}
|
|
17
22
|
return await uploadFileWithSession(sandboxWsId5, args.local_path, args.remote_path, sandboxUser5, sandboxTimeout5);
|
|
18
23
|
}
|
|
19
24
|
export async function handleUploadProject(args = {}, _opts = {}) {
|
|
@@ -27,6 +32,12 @@ export async function handleUploadProject(args = {}, _opts = {}) {
|
|
|
27
32
|
}
|
|
28
33
|
const sandboxUser6 = args.username || 'root';
|
|
29
34
|
const sandboxTimeout6 = args.timeout_ms || SANDBOX_TIMEOUT_MS.upload_project;
|
|
35
|
+
if (backendForWorkspace(sandboxWsId6) === 'devbox') {
|
|
36
|
+
return await uploadProjectDevbox(sandboxWsId6, args.local_dir, args.remote_dir, sandboxTimeout6, {
|
|
37
|
+
exclude: args.exclude,
|
|
38
|
+
extract: args.extract,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
30
41
|
return await uploadProjectWithSession(sandboxWsId6, args.local_dir, args.remote_dir, sandboxUser6, sandboxTimeout6, {
|
|
31
42
|
exclude: args.exclude,
|
|
32
43
|
extract: args.extract,
|
|
@@ -241,6 +241,14 @@ export const connectSchema = z.looseObject({
|
|
|
241
241
|
flavor_id: z.string().optional().describe('Flavor ID; overrides server default (only for new sandbox)'),
|
|
242
242
|
env: looseObject.optional().describe('Environment variables to set in the sandbox (only for new sandbox)'),
|
|
243
243
|
git: gitConfig.optional().describe('Git repo config (only for new sandbox)'),
|
|
244
|
+
timeout_seconds: z
|
|
245
|
+
.number()
|
|
246
|
+
.int()
|
|
247
|
+
.min(10)
|
|
248
|
+
.max(86400)
|
|
249
|
+
.optional()
|
|
250
|
+
.describe('Sandbox TTL in seconds (10-86400, default 1800). Only honored by the devbox backend; the legacy DevStation backend ignores it. ' +
|
|
251
|
+
'On devbox, connect/refresh extends the TTL of the same sandbox.'),
|
|
244
252
|
approvalToken: approvalTokenArg,
|
|
245
253
|
approvedByUser: approvedByUserArg,
|
|
246
254
|
});
|
|
@@ -273,3 +281,15 @@ export const shutdownSchema = z.looseObject({
|
|
|
273
281
|
approvalToken: approvalTokenArg,
|
|
274
282
|
approvedByUser: approvedByUserArg,
|
|
275
283
|
});
|
|
284
|
+
// kill(devbox-only delete):不可逆,独立工具 + always 审批。
|
|
285
|
+
export const killSchema = z.looseObject({
|
|
286
|
+
session_id: z.string().optional().describe('Sandbox ID from huaweicloud_sandbox_connect (optional)'),
|
|
287
|
+
dev_stage_id: z.string().optional().describe('DevBox sandbox ID (alternative to session_id)'),
|
|
288
|
+
workspace_id: z
|
|
289
|
+
.string()
|
|
290
|
+
.optional()
|
|
291
|
+
.describe('Workspace ID; defaults to the current workspace (an alternative to session_id/dev_stage_id)'),
|
|
292
|
+
username,
|
|
293
|
+
approvalToken: approvalTokenArg,
|
|
294
|
+
approvedByUser: approvedByUserArg,
|
|
295
|
+
});
|