huaweicloud-devkit 2.0.1-next.3 → 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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
  4. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
  5. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
  6. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
  7. package/plugins/huaweicloud-core/.mcp.json +3 -0
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  9. package/plugins/huaweicloud-core/dist/approval-roster.js +2 -0
  10. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +7 -0
  11. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +30 -1
  12. package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +21 -0
  13. package/plugins/huaweicloud-core/dist/mcp-server.js +5019 -3879
  14. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  15. package/plugins/huaweicloud-core/dist/packs/registry.js +1 -0
  16. package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +13 -2
  17. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +198 -10
  18. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +11 -0
  19. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +22 -0
  20. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +46 -0
  21. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-upload.js +11 -0
  22. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +20 -0
  23. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +26 -18
  24. package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +97 -0
  25. package/plugins/huaweicloud-core/dist/sandbox/deploy-nginx.js +30 -14
  26. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-backend.js +37 -0
  27. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-connections.js +84 -0
  28. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-client.js +229 -0
  29. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-protocol.js +151 -0
  30. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-envd-transport.js +121 -0
  31. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-service-api.js +80 -0
  32. package/plugins/huaweicloud-core/dist/sandbox/devbox/devbox-upload.js +106 -0
  33. package/plugins/huaweicloud-core/dist/sandbox/hwlink-connection.js +12 -0
  34. package/plugins/huaweicloud-core/dist/sandbox/upload-project.js +5 -2
  35. package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
  36. package/plugins/huaweicloud-core/dist/tools.js +1 -0
  37. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  38. package/plugins/huaweicloud-core/safety/policy.json +2 -1
  39. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +67 -16
  40. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/devbox-backend.md +78 -0
  41. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +14 -0
  42. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +2 -1
  43. package/plugins/huaweicloud-core/src/approval-roster.ts +2 -0
  44. package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +7 -0
  45. package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +30 -1
  46. package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +22 -0
  47. package/plugins/huaweicloud-core/src/packs/registry.ts +1 -0
  48. package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +15 -2
  49. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +206 -11
  50. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +12 -0
  51. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +23 -0
  52. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +49 -0
  53. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-upload.ts +11 -0
  54. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +23 -0
  55. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +27 -17
  56. package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +105 -0
  57. package/plugins/huaweicloud-core/src/sandbox/deploy-nginx.ts +36 -18
  58. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-backend.ts +44 -0
  59. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-connections.ts +115 -0
  60. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-client.ts +281 -0
  61. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-protocol.ts +180 -0
  62. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-envd-transport.ts +142 -0
  63. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-service-api.ts +102 -0
  64. package/plugins/huaweicloud-core/src/sandbox/devbox/devbox-upload.ts +167 -0
  65. package/plugins/huaweicloud-core/src/sandbox/hwlink-connection.ts +12 -0
  66. package/plugins/huaweicloud-core/src/sandbox/upload-project.ts +5 -2
  67. package/plugins/huaweicloud-core/src/tool-definitions.ts +4 -0
  68. package/plugins/huaweicloud-core/src/tools.ts +3 -0
@@ -284,6 +284,28 @@ export function enrichConnectResult<T>(result: T, options: { announce?: boolean
284
284
  const rec = result as Record<string, unknown>;
285
285
  const poolType = asString(rec.pool_type || rec.poolType);
286
286
  const announce = options.announce !== false;
287
+ // Devbox lifecycle is server-authoritative (end_at / token_expiration /
288
+ // pause_retention_hours), NOT the DevStation idle policy numbers. Never fall
289
+ // through to the legacy idle shutdown/delete broadcast on this backend.
290
+ if (asString(rec.backend) === 'devbox') {
291
+ if (!announce) {
292
+ delete rec.pool;
293
+ return result;
294
+ }
295
+ const endAt = asString(rec.end_at || rec.endAt);
296
+ const tokenExpiration = asString(rec.token_expiration || rec.tokenExpiration);
297
+ const retentionRaw = rec.pause_retention_hours ?? rec.pauseRetentionHours;
298
+ const retention = typeof retentionRaw === 'number' && retentionRaw > 0 ? retentionRaw : 168;
299
+ rec.pool = {
300
+ pool_type: 'ephemeral',
301
+ lifecycle: `devbox ephemeral sandbox${endAt ? `; TTL ends ${endAt}` : ''}; pause retention ${retention}h`,
302
+ ttl_hint:
303
+ `DevBox 沙箱${endAt ? `到期时间 ${endAt}` : '按平台 TTL 到期'};` +
304
+ `shutdown 暂停后保留 ${retention} 小时,超期由平台回收。重要数据请及时保存或迁出。` +
305
+ (tokenExpiration ? ` EnvD 数据面 token 到期时间 ${tokenExpiration},devkit 会自动刷新一次。` : ''),
306
+ } satisfies ConnectPoolBroadcast;
307
+ return result;
308
+ }
287
309
  if (!announce || !poolType || !isPoolType(poolType)) {
288
310
  delete rec.pool;
289
311
  return result;
@@ -82,6 +82,7 @@ export const PACK_OF = {
82
82
  huaweicloud_sandbox_connect: 'sandbox',
83
83
  huaweicloud_sandbox_credentials: 'sandbox',
84
84
  huaweicloud_sandbox_shutdown: 'sandbox',
85
+ huaweicloud_sandbox_kill: 'sandbox',
85
86
  huaweicloud_voucher_status: 'voucher',
86
87
  huaweicloud_voucher_claim: 'voucher',
87
88
  huaweicloud_competition_voucher_claim: 'voucher',
@@ -7,10 +7,10 @@ import { isSecretRef } from '../../lib/secret-vault/refs.ts';
7
7
  import type { ApprovalSpec } from '../../approval-types.ts';
8
8
  import type { ToolArgs } from '../../tools.ts';
9
9
 
10
- // The sandbox pack's approval spec table. Nine tools join the gate: the two
10
+ // The sandbox pack's approval spec table. Ten tools join the gate: the two
11
11
  // exec faces are CLASSIFIED (content decides — a benign command runs with no
12
12
  // confirmation surface at all, a write-classified one confirms on every
13
- // call), the seven mutating lifecycle faces are ALWAYS (a human present per
13
+ // call), the eight mutating lifecycle faces are ALWAYS (a human present per
14
14
  // call, no content rule ever exempts them). The strict classification runs
15
15
  // on the exec faces' `command` argument through the SAME engines the Bash
16
16
  // face uses — classifyTextCommand plus the cloud-risk-rules catalog — so a
@@ -283,6 +283,18 @@ const shutdownSpec: ApprovalSpec = {
283
283
  }),
284
284
  };
285
285
 
286
+ // kill = devbox-only DELETE (irreversible). The confirmation view must say
287
+ // delete, not close: shutdown keeps the instance, kill does not.
288
+ const killSpec: ApprovalSpec = {
289
+ ...sandboxBinding(),
290
+ flavor: 'always',
291
+ summarize: (bindingValue) =>
292
+ viewOf(bindingValue, (view) => {
293
+ const target = fieldEcho(view, ['session_id', 'dev_stage_id', 'workspace_id']);
294
+ return `huaweicloud_sandbox_kill: DELETE the devbox sandbox permanently (irreversible — use shutdown to keep the instance)${target !== '' ? ` (${target})` : ''}`;
295
+ }),
296
+ };
297
+
286
298
  export const SANDBOX_APPROVAL_SPECS = {
287
299
  huaweicloud_sandbox_connect: connectSpec,
288
300
  huaweicloud_sandbox_exec_with_session: execSpec('exec_with_session'),
@@ -293,4 +305,5 @@ export const SANDBOX_APPROVAL_SPECS = {
293
305
  huaweicloud_sandbox_sign_agreement: signAgreementSpec,
294
306
  huaweicloud_sandbox_credentials: credentialsSpec,
295
307
  huaweicloud_sandbox_shutdown: shutdownSpec,
308
+ huaweicloud_sandbox_kill: killSpec,
296
309
  } as const satisfies Record<string, ApprovalSpec>;
@@ -27,6 +27,19 @@ import {
27
27
  shouldAnnounceConnect,
28
28
  enrichConnectResult,
29
29
  } from '../../lib/hdkit/sandbox-pool.ts';
30
+ import {
31
+ backendForWorkspace,
32
+ isDevboxBackend,
33
+ rememberWorkspaceBackend,
34
+ sandboxBackend,
35
+ forgetWorkspaceBackend,
36
+ } from '../../sandbox/devbox/devbox-backend.ts';
37
+ import {
38
+ clearDevboxConnection,
39
+ getDevboxConnection,
40
+ setDevboxConnectionFromResponse,
41
+ } from '../../sandbox/devbox/devbox-connections.ts';
42
+ import { devboxConnect, devboxKill, devboxShutdown } from '../../sandbox/devbox/devbox-service-api.ts';
30
43
  import type { CallToolOptions, ToolArgs } from '../../tools.ts';
31
44
  import { transferGitRepo } from './git-transfer.ts';
32
45
 
@@ -38,6 +51,17 @@ import { transferGitRepo } from './git-transfer.ts';
38
51
  // close face (dev 5d89c880 + 3bfc1f53 tip state).
39
52
 
40
53
  export async function handleCheckUser(_args: ToolArgs = {}, _opts: CallToolOptions = {}) {
54
+ if (isDevboxBackend()) {
55
+ return {
56
+ ok: true,
57
+ backend: 'devbox',
58
+ skipped: true,
59
+ checked: false,
60
+ realnameVerified: null,
61
+ agreementSigned: null,
62
+ hint: 'devbox 后端不经过 DevStation 的实名/协议门禁,本次未做任何实名校验。',
63
+ };
64
+ }
41
65
  try {
42
66
  return await hdkitCheckUser();
43
67
  } catch (error) {
@@ -50,6 +74,16 @@ export async function handleCheckUser(_args: ToolArgs = {}, _opts: CallToolOptio
50
74
  }
51
75
 
52
76
  export async function handleSignAgreement(_args: ToolArgs = {}, _opts: CallToolOptions = {}) {
77
+ if (isDevboxBackend()) {
78
+ return {
79
+ ok: true,
80
+ backend: 'devbox',
81
+ skipped: true,
82
+ signed: false,
83
+ signedCount: 0,
84
+ hint: 'devbox 后端不经过 DevStation 的协议门禁;无需签署,也没有代签。',
85
+ };
86
+ }
53
87
  try {
54
88
  return await hdkitSignAgreement();
55
89
  } catch (error) {
@@ -59,7 +93,117 @@ export async function handleSignAgreement(_args: ToolArgs = {}, _opts: CallToolO
59
93
  }
60
94
  }
61
95
 
96
+ // Devbox control-plane failures: the MCP error envelope only carries code +
97
+ // message, so remediation/retry fields must be returned structurally.
98
+ function devboxErrorResult(error: unknown): Record<string, unknown> | undefined {
99
+ const gate = versionGateResult(error);
100
+ if (gate) return gate;
101
+ const exhausted = transientExhaustionResult(error);
102
+ if (exhausted) return exhausted;
103
+ const rawCode = safeReadField(error, 'code');
104
+ const code = typeof rawCode === 'string' && rawCode !== '' ? rawCode : undefined;
105
+ if (!code) return undefined;
106
+ const message = cleanMessage(safeMessageText(error)) || 'hdkitservice error';
107
+ const rawRetryAfter = ownDataValue(error, 'retryAfter');
108
+ const retryAfter = typeof rawRetryAfter === 'string' ? rawRetryAfter : undefined;
109
+ const remediation = serializableRemediation(ownDataValue(error, 'remediation'));
110
+ return {
111
+ ok: false,
112
+ code,
113
+ message,
114
+ ...(retryAfter ? { retryAfter } : {}),
115
+ ...(remediation ? { remediation } : {}),
116
+ };
117
+ }
118
+
119
+ // Strip the single-sandbox EnvD data-plane credentials from anything that can
120
+ // reach a tool result. They live only in the process-memory connection cache.
121
+ function sanitizeDevboxConnectResult(result: Record<string, unknown>): Record<string, unknown> {
122
+ const safe: Record<string, unknown> = {};
123
+ for (const key of [
124
+ 'backend',
125
+ 'session_id',
126
+ 'dev_stage_id',
127
+ 'sandbox_id',
128
+ 'state',
129
+ 'template_id',
130
+ 'end_at',
131
+ 'token_expiration',
132
+ 'envd_version',
133
+ 'pool_type',
134
+ 'started',
135
+ 'pause_retention_hours',
136
+ ]) {
137
+ if (result[key] !== undefined) safe[key] = result[key];
138
+ }
139
+ safe.backend = 'devbox';
140
+ safe.pool_type = 'ephemeral';
141
+ return safe;
142
+ }
143
+
144
+ async function handleDevboxConnect(args: ToolArgs): Promise<Record<string, unknown>> {
145
+ const rawPool = args.pool_type;
146
+ if (rawPool !== undefined && rawPool !== null && rawPool !== '') {
147
+ let poolType: ReturnType<typeof validatePoolType>;
148
+ try {
149
+ poolType = validatePoolType(rawPool);
150
+ } catch (error) {
151
+ return { ok: false, code: 'HDKIT_INVALID_POOL_TYPE', message: (error as Error).message };
152
+ }
153
+ if (poolType !== 'ephemeral') {
154
+ return {
155
+ ok: false,
156
+ code: 'HDKIT_BACKEND_UNSUPPORTED',
157
+ message: 'devbox 后端暂不支持 pool_type=persistent,仅支持 ephemeral。',
158
+ };
159
+ }
160
+ }
161
+ const envVars =
162
+ args.env && typeof args.env === 'object' && !Array.isArray(args.env)
163
+ ? Object.fromEntries(Object.entries(args.env).map(([k, v]) => [k, String(v)]))
164
+ : undefined;
165
+ let result: Record<string, unknown>;
166
+ try {
167
+ result = await devboxConnect({
168
+ timeoutSeconds: typeof args.timeout_seconds === 'number' ? args.timeout_seconds : undefined,
169
+ source: typeof args.source === 'string' ? args.source : undefined,
170
+ envVars,
171
+ });
172
+ } catch (error) {
173
+ const folded = devboxErrorResult(error);
174
+ if (folded) return folded;
175
+ throw error;
176
+ }
177
+ const sandboxId =
178
+ (typeof result.sandbox_id === 'string' && result.sandbox_id) ||
179
+ (typeof result.session_id === 'string' && result.session_id) ||
180
+ (typeof result.dev_stage_id === 'string' && result.dev_stage_id) ||
181
+ '';
182
+ if (!sandboxId) {
183
+ return {
184
+ ok: false,
185
+ code: 'HDKIT_DEVBOX_CREATE_FAILED',
186
+ message: 'hdkitservice devbox connect response did not include a sandbox id.',
187
+ };
188
+ }
189
+ const firstConnection = !getDevboxConnection(sandboxId);
190
+ const connection = setDevboxConnectionFromResponse(sandboxId, result);
191
+ setWorkspaceId(sandboxId);
192
+ rememberWorkspaceBackend(sandboxId, 'devbox');
193
+ const safe = sanitizeDevboxConnectResult(result);
194
+ if (args.git !== undefined && args.git !== null) {
195
+ safe.warning =
196
+ 'devbox v1 create 不接受 git:本次没有自动 clone。请在 connect 后用 exec_one_shot 自行 clone,或使用 upload_project。';
197
+ }
198
+ if (connection.started) safe.started = true;
199
+ const announce = firstConnection || connection.started === true;
200
+ return enrichConnectResult(safe, { announce });
201
+ }
202
+
62
203
  export async function handleConnect(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
204
+ if (sandboxBackend() === 'devbox') {
205
+ return await handleDevboxConnect(args);
206
+ }
63
207
  // 两池:客户端校验 pool_type(非法值在本地即报错,不发无效请求);未传交由服务端默认 ephemeral
64
208
  const connectArgs = { ...args };
65
209
  let poolType: ReturnType<typeof validatePoolType>;
@@ -230,21 +374,45 @@ function shutdownErrorResult(error: unknown): Record<string, unknown> {
230
374
  };
231
375
  }
232
376
 
233
- export async function handleShutdown(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
377
+ // Shared by the lifecycle faces that need a sandbox id (shutdown/kill).
378
+ function missingSandboxIdResult(): Record<string, unknown> {
379
+ return {
380
+ ok: false,
381
+ code: 'HDKIT_INVALID_REQUEST',
382
+ message:
383
+ 'session_id or dev_stage_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, or pass workspace_id.',
384
+ };
385
+ }
386
+
387
+ // Shared id resolution for shutdown/kill (3bfc1f53): workspaceId and devStageId
388
+ // are separate aliases; a session_id-only call leaves devStageId empty so the
389
+ // legacy terminal session is closed with the server-returned devStageId.
390
+ function lifecycleIds(args: ToolArgs) {
234
391
  const sessionId = args.session_id;
235
- // 3bfc1f53:workspaceId 与 devStageId 分开解析。仅 session_id 时 devStageId
236
- // 留空(不把 session_id 字符串当 workspace 用),终端会话以服务端回传的
237
- // devStageId 为准关闭。
238
392
  const workspaceId = args.dev_stage_id || args.workspace_id || getCurrentWorkspaceId();
239
393
  const devStageId = args.dev_stage_id || args.workspace_id || (sessionId ? undefined : workspaceId);
240
- const id = sessionId || devStageId;
394
+ return { sessionId, workspaceId, devStageId, id: sessionId || devStageId };
395
+ }
396
+
397
+ export async function handleShutdown(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
398
+ const { sessionId, workspaceId, devStageId, id } = lifecycleIds(args);
241
399
  if (!id) {
242
- return {
243
- ok: false,
244
- code: 'HDKIT_INVALID_REQUEST',
245
- message:
246
- 'session_id or dev_stage_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, or pass workspace_id.',
247
- };
400
+ return missingSandboxIdResult();
401
+ }
402
+ const backend = backendForWorkspace(typeof id === 'string' ? id : undefined);
403
+ if (backend === 'devbox') {
404
+ const sandboxId = typeof id === 'string' ? id : '';
405
+ try {
406
+ const shutdown = await devboxShutdown(sandboxId);
407
+ // Paused sandboxes need a fresh connect before any further exec; drop the
408
+ // stale in-memory EnvD tokens (the backend pin stays for kill/status).
409
+ clearDevboxConnection(sandboxId);
410
+ return { ok: true, backend: 'devbox', ...shutdown };
411
+ } catch (error) {
412
+ const folded = devboxErrorResult(error);
413
+ if (folded) return folded;
414
+ throw error;
415
+ }
248
416
  }
249
417
  try {
250
418
  const shutdown = await hdkitShutdown(sessionId, devStageId);
@@ -263,3 +431,30 @@ export async function handleShutdown(args: ToolArgs = {}, _opts: CallToolOptions
263
431
  return shutdownErrorResult(error);
264
432
  }
265
433
  }
434
+
435
+ /** kill = devbox-only delete; legacy returns HDKIT_BACKEND_UNSUPPORTED (2A). */
436
+ export async function handleKill(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
437
+ const { id } = lifecycleIds(args);
438
+ if (!id || typeof id !== 'string') {
439
+ return missingSandboxIdResult();
440
+ }
441
+ if (backendForWorkspace(id) !== 'devbox') {
442
+ return {
443
+ ok: false,
444
+ code: 'HDKIT_BACKEND_UNSUPPORTED',
445
+ message:
446
+ 'kill is devbox-only. On the legacy DevStation backend use huaweicloud_sandbox_shutdown (pause) instead; ' +
447
+ 'the legacy backend does not expose delete.',
448
+ };
449
+ }
450
+ try {
451
+ const killed = await devboxKill(id);
452
+ clearDevboxConnection(id);
453
+ forgetWorkspaceBackend(id);
454
+ return { ok: true, backend: 'devbox', ...killed };
455
+ } catch (error) {
456
+ const folded = devboxErrorResult(error);
457
+ if (folded) return folded;
458
+ throw error;
459
+ }
460
+ }
@@ -1,6 +1,7 @@
1
1
  import { randomBytes } from 'node:crypto';
2
2
 
3
3
  import { execOneShot, execWithSession, getCurrentWorkspaceId } from '../../sandbox/session-manager.ts';
4
+ import { backendForWorkspace } from '../../sandbox/devbox/devbox-backend.ts';
4
5
  import { hdkitCredentials } from '../../lib/hdkit/hdkitservice-api.ts';
5
6
  import { versionGateResult } from '../../lib/hdkit/hdkit-gate.ts';
6
7
  import { getCredentials } from '../../lib/hdkit/hwlink-api.ts';
@@ -26,6 +27,17 @@ function shellSingleQuote(value: string): string {
26
27
 
27
28
  export async function handleCredentials(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
28
29
  const devStageId = args.dev_stage_id || getCurrentWorkspaceId();
30
+ if (backendForWorkspace(typeof devStageId === 'string' ? devStageId : undefined) === 'devbox') {
31
+ return {
32
+ ok: false,
33
+ backend: 'devbox',
34
+ code: 'HDKIT_BACKEND_UNSUPPORTED',
35
+ message: 'credentials (DevStation auto-config / DevBridge key injection) is not supported on the devbox backend.',
36
+ hint:
37
+ 'Use connect envVars for environment variables, or write /tmp files with exec_one_shot. ' +
38
+ 'devbox preview does not use DevBridge tunnels or API keys.',
39
+ };
40
+ }
29
41
  let resolved: CredentialLike | null;
30
42
  let resolveError: unknown;
31
43
  try {
@@ -1,4 +1,5 @@
1
1
  import { execWithSession, execOneShot, closeSession, getCurrentWorkspaceId } from '../../sandbox/session-manager.ts';
2
+ import { backendForWorkspace } from '../../sandbox/devbox/devbox-backend.ts';
2
3
  import { forgetWorkspacePool } from '../../lib/hdkit/sandbox-pool.ts';
3
4
  import type { CallToolOptions, ToolArgs } from '../../tools.ts';
4
5
  import { SANDBOX_TIMEOUT_MS } from './schemas.ts';
@@ -21,6 +22,18 @@ export async function handleExecWithSession(args: ToolArgs = {}, _opts: CallTool
21
22
  const sandboxUser2 = args.username || 'root';
22
23
  const sandboxTimeout2 = args.timeout_ms || SANDBOX_TIMEOUT_MS.exec_with_session;
23
24
  const sandboxResult2 = await execWithSession(sandboxWsId2, args.command || '', sandboxUser2, sandboxTimeout2);
25
+ if (backendForWorkspace(sandboxWsId2) === 'devbox') {
26
+ return {
27
+ stdout: sandboxResult2.stdout,
28
+ exitCode: sandboxResult2.exitCode,
29
+ backend: 'devbox',
30
+ degraded: true,
31
+ statePersisted: false,
32
+ hint:
33
+ 'devbox 后端不保留 shell 状态:本次只是 one-shot 执行,cd/env/变量不会跨调用。' +
34
+ '命令必须自包含(cd ... && ...、source ...; ...),需要跨调用状态请使用 legacy 后端。',
35
+ };
36
+ }
24
37
  return {
25
38
  stdout: sandboxResult2.stdout,
26
39
  exitCode: sandboxResult2.exitCode,
@@ -59,6 +72,16 @@ export async function handleCloseSession(args: ToolArgs = {}, _opts: CallToolOpt
59
72
  'or set HW_WORKSPACE_ID environment variable before starting the agent.',
60
73
  );
61
74
  }
75
+ if (backendForWorkspace(sandboxWsId4) === 'devbox') {
76
+ // Devbox v1 has no terminal session to close; the sandbox itself is NOT
77
+ // deleted (use shutdown/kill for lifecycle control).
78
+ return {
79
+ ok: true,
80
+ backend: 'devbox',
81
+ not_applicable: true,
82
+ message: 'close_session is not applicable on devbox (no terminal session exists); the sandbox is left untouched.',
83
+ };
84
+ }
62
85
  const sandboxUser4 = args.username || 'root';
63
86
  const closed = await closeSession(sandboxWsId4, sandboxUser4);
64
87
  if (closed) {
@@ -5,6 +5,9 @@ import {
5
5
  validateTunnelId,
6
6
  } from '../../sandbox/devbridge-tunnel.ts';
7
7
  import { getCurrentWorkspaceId } from '../../sandbox/session-manager.ts';
8
+ import { backendForWorkspace } from '../../sandbox/devbox/devbox-backend.ts';
9
+ import { requireDevboxConnection } from '../../sandbox/devbox/devbox-connections.ts';
10
+ import { devboxAppPortUrl, probeDevboxAppUrl } from '../../sandbox/devbox/devbox-envd-client.ts';
8
11
  import { validateTunnelPort } from '../../sandbox/devbridge-validation.ts';
9
12
  import { poolContextFor } from '../../lib/hdkit/sandbox-pool.ts';
10
13
  import { startExposeTask, pollExposeTask } from './expose-task.ts';
@@ -36,6 +39,32 @@ export async function handleExposeTunnel(args: ToolArgs = {}, _opts: CallToolOpt
36
39
  }
37
40
  const sandboxUser9 = args.username || 'root';
38
41
  const sandboxTimeout9 = args.timeout_ms || SANDBOX_TIMEOUT_MS.expose_tunnel;
42
+ if (backendForWorkspace(sandboxWsId9) === 'devbox') {
43
+ // devbox preview: the platform app-port URL is returned directly. No
44
+ // DevBridge tunnel, no keepalive, no DevBridge API key.
45
+ const connection = requireDevboxConnection(sandboxWsId9);
46
+ const port = validateTunnelPort(args.port);
47
+ const publicUrl = devboxAppPortUrl(connection.envdUrl, port);
48
+ const probe = await probeDevboxAppUrl(connection.envdUrl, port, 10000);
49
+ return {
50
+ ok: true,
51
+ backend: 'devbox',
52
+ port,
53
+ publicUrl,
54
+ url: publicUrl,
55
+ accessible: probe.ok,
56
+ ...(probe.ok
57
+ ? {}
58
+ : {
59
+ warning:
60
+ `The app-port URL was returned but the client probe got HTTP ${probe.status || 'unreachable'}. ` +
61
+ 'Verify the app is running and bound to 0.0.0.0 (not 127.0.0.1), then probe again.',
62
+ }),
63
+ hint:
64
+ 'devbox preview is a single public port: expose one app port per sandbox and bind the app to 0.0.0.0. ' +
65
+ 'No tunnel renewal/keepalive is needed on devbox.',
66
+ };
67
+ }
39
68
  const exposePoolContext = poolContextFor(sandboxWsId9);
40
69
  const exposeArgs = {
41
70
  port: validateTunnelPort(args.port),
@@ -68,7 +97,21 @@ export async function handleExposeTunnel(args: ToolArgs = {}, _opts: CallToolOpt
68
97
  return await exposeTunnel(sandboxWsId9, exposeArgs, sandboxUser9, sandboxTimeout9);
69
98
  }
70
99
 
100
+ function devboxTunnelNotApplicable() {
101
+ return {
102
+ ok: false,
103
+ backend: 'devbox',
104
+ code: 'HDKIT_BACKEND_UNSUPPORTED',
105
+ reason: 'not_applicable',
106
+ message: 'This operation is not applicable on the devbox backend.',
107
+ hint: 'devbox expose_tunnel returns the app-port URL synchronously; there is no DevBridge tunnel to poll, renew, or keep alive.',
108
+ };
109
+ }
110
+
71
111
  export async function handleExposePoll(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
112
+ if (backendForWorkspace(args.workspace_id || getCurrentWorkspaceId()) === 'devbox') {
113
+ return devboxTunnelNotApplicable();
114
+ }
72
115
  const taskId = args.task_id;
73
116
  if (typeof taskId !== 'string' || taskId === '') {
74
117
  throw new Error(
@@ -79,6 +122,9 @@ export async function handleExposePoll(args: ToolArgs = {}, _opts: CallToolOptio
79
122
  }
80
123
 
81
124
  export async function handleRenewTunnel(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
125
+ if (backendForWorkspace(args.workspace_id || getCurrentWorkspaceId()) === 'devbox') {
126
+ return devboxTunnelNotApplicable();
127
+ }
82
128
  if (!args.tunnel_id) {
83
129
  throw new Error(
84
130
  '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).',
@@ -103,6 +149,9 @@ export async function handleRenewTunnel(args: ToolArgs = {}, _opts: CallToolOpti
103
149
  }
104
150
 
105
151
  export async function handleKeepaliveWatchdog(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
152
+ if (backendForWorkspace(args.workspace_id || getCurrentWorkspaceId()) === 'devbox') {
153
+ return devboxTunnelNotApplicable();
154
+ }
106
155
  if (!Array.isArray(args.tunnels) || args.tunnels.length === 0) {
107
156
  throw new Error(
108
157
  'tunnels is required — a non-empty array of {tunnel_id, url} from huaweicloud_sandbox_expose_tunnel results.',
@@ -3,6 +3,8 @@ import {
3
3
  uploadProjectWithSession,
4
4
  getCurrentWorkspaceId,
5
5
  } from '../../sandbox/session-manager.ts';
6
+ import { backendForWorkspace } from '../../sandbox/devbox/devbox-backend.ts';
7
+ import { uploadFileDevbox, uploadProjectDevbox } from '../../sandbox/devbox/devbox-upload.ts';
6
8
  import type { CallToolOptions, ToolArgs } from '../../tools.ts';
7
9
  import { SANDBOX_TIMEOUT_MS } from './schemas.ts';
8
10
 
@@ -23,6 +25,9 @@ export async function handleUploadFile(args: ToolArgs = {}, _opts: CallToolOptio
23
25
  }
24
26
  const sandboxUser5 = args.username || 'root';
25
27
  const sandboxTimeout5 = args.timeout_ms || SANDBOX_TIMEOUT_MS.upload_file;
28
+ if (backendForWorkspace(sandboxWsId5) === 'devbox') {
29
+ return await uploadFileDevbox(sandboxWsId5, args.local_path, args.remote_path, sandboxTimeout5);
30
+ }
26
31
  return await uploadFileWithSession(sandboxWsId5, args.local_path, args.remote_path, sandboxUser5, sandboxTimeout5);
27
32
  }
28
33
 
@@ -39,6 +44,12 @@ export async function handleUploadProject(args: ToolArgs = {}, _opts: CallToolOp
39
44
  }
40
45
  const sandboxUser6 = args.username || 'root';
41
46
  const sandboxTimeout6 = args.timeout_ms || SANDBOX_TIMEOUT_MS.upload_project;
47
+ if (backendForWorkspace(sandboxWsId6) === 'devbox') {
48
+ return await uploadProjectDevbox(sandboxWsId6, args.local_dir, args.remote_dir, sandboxTimeout6, {
49
+ exclude: args.exclude,
50
+ extract: args.extract,
51
+ });
52
+ }
42
53
  return await uploadProjectWithSession(sandboxWsId6, args.local_dir, args.remote_dir, sandboxUser6, sandboxTimeout6, {
43
54
  exclude: args.exclude,
44
55
  extract: args.extract,
@@ -321,6 +321,16 @@ export const connectSchema = z.looseObject({
321
321
  flavor_id: z.string().optional().describe('Flavor ID; overrides server default (only for new sandbox)'),
322
322
  env: looseObject.optional().describe('Environment variables to set in the sandbox (only for new sandbox)'),
323
323
  git: gitConfig.optional().describe('Git repo config (only for new sandbox)'),
324
+ timeout_seconds: z
325
+ .number()
326
+ .int()
327
+ .min(10)
328
+ .max(86400)
329
+ .optional()
330
+ .describe(
331
+ 'Sandbox TTL in seconds (10-86400, default 1800). Only honored by the devbox backend; the legacy DevStation backend ignores it. ' +
332
+ 'On devbox, connect/refresh extends the TTL of the same sandbox.',
333
+ ),
324
334
  approvalToken: approvalTokenArg,
325
335
  approvedByUser: approvedByUserArg,
326
336
  });
@@ -359,3 +369,16 @@ export const shutdownSchema = z.looseObject({
359
369
  approvalToken: approvalTokenArg,
360
370
  approvedByUser: approvedByUserArg,
361
371
  });
372
+
373
+ // kill(devbox-only delete):不可逆,独立工具 + always 审批。
374
+ export const killSchema = z.looseObject({
375
+ session_id: z.string().optional().describe('Sandbox ID from huaweicloud_sandbox_connect (optional)'),
376
+ dev_stage_id: z.string().optional().describe('DevBox sandbox ID (alternative to session_id)'),
377
+ workspace_id: z
378
+ .string()
379
+ .optional()
380
+ .describe('Workspace ID; defaults to the current workspace (an alternative to session_id/dev_stage_id)'),
381
+ username,
382
+ approvalToken: approvalTokenArg,
383
+ approvedByUser: approvedByUserArg,
384
+ });