huaweicloud-devkit 2.0.0-next.3 → 2.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +3 -1
  2. package/package.json +3 -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 +55 -1
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  9. package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
  10. package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
  11. package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
  12. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +141 -86
  13. package/plugins/huaweicloud-core/dist/agents/opencode.js +106 -39
  14. package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
  15. package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
  16. package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
  17. package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
  18. package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
  19. package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
  20. package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
  21. package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
  22. package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
  23. package/plugins/huaweicloud-core/dist/hcloud-plan.js +68 -62
  24. package/plugins/huaweicloud-core/dist/lib/approval-mode.js +7 -5
  25. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
  26. package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
  27. package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
  28. package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
  29. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
  30. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +371 -32
  31. package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
  32. package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +224 -78
  33. package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
  34. package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
  35. package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
  36. package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
  37. package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
  38. package/plugins/huaweicloud-core/dist/mcp-protocol.js +68 -16
  39. package/plugins/huaweicloud-core/dist/mcp-server.js +6933 -1186
  40. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  41. package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
  42. package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
  43. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
  44. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +85 -130
  45. package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
  46. package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
  47. package/plugins/huaweicloud-core/dist/packs/registry.js +20 -1
  48. package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
  49. package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
  50. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +180 -23
  51. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
  52. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
  53. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
  54. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +29 -3
  55. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +93 -9
  56. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +37 -10
  57. package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
  58. package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
  59. package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
  60. package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
  61. package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
  62. package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
  63. package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
  64. package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
  65. package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
  66. package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
  67. package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
  68. package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
  69. package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
  70. package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
  71. package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
  72. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
  73. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
  74. package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
  75. package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
  76. package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
  77. package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
  78. package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
  79. package/plugins/huaweicloud-core/dist/setup-cli.js +36 -1
  80. package/plugins/huaweicloud-core/dist/tool-definitions.js +13 -1
  81. package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
  82. package/plugins/huaweicloud-core/dist/tools.js +76 -9
  83. package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
  84. package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
  85. package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
  86. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
  87. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +67 -4
  88. package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
  89. package/plugins/huaweicloud-core/safety/policy.json +18 -11
  90. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +115 -11
  91. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +198 -143
  92. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
  93. package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
  94. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +2 -2
  95. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +11 -7
  96. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +74 -29
  97. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
  98. package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
  99. package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
  100. package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
  101. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +176 -88
  102. package/plugins/huaweicloud-core/src/agents/opencode.ts +125 -54
  103. package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
  104. package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
  105. package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
  106. package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
  107. package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
  108. package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
  109. package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
  110. package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
  111. package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
  112. package/plugins/huaweicloud-core/src/hcloud-plan.ts +74 -71
  113. package/plugins/huaweicloud-core/src/lib/approval-mode.ts +7 -5
  114. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
  115. package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
  116. package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
  117. package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
  118. package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
  119. package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +408 -30
  120. package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
  121. package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +302 -83
  122. package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
  123. package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
  124. package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
  125. package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
  126. package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
  127. package/plugins/huaweicloud-core/src/mcp-protocol.ts +81 -17
  128. package/plugins/huaweicloud-core/src/mcp-server.ts +7 -7
  129. package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
  130. package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
  131. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
  132. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +99 -137
  133. package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
  134. package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
  135. package/plugins/huaweicloud-core/src/packs/registry.ts +43 -1
  136. package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
  137. package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
  138. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +195 -23
  139. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
  140. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
  141. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
  142. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -14
  143. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +120 -8
  144. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +42 -9
  145. package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
  146. package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
  147. package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
  148. package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
  149. package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
  150. package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
  151. package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
  152. package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
  153. package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
  154. package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
  155. package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
  156. package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
  157. package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
  158. package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
  159. package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +511 -0
  160. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
  161. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
  162. package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
  163. package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
  164. package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
  165. package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
  166. package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
  167. package/plugins/huaweicloud-core/src/setup-cli.ts +39 -1
  168. package/plugins/huaweicloud-core/src/tool-definitions.ts +13 -1
  169. package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
  170. package/plugins/huaweicloud-core/src/tools.ts +124 -10
  171. package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
  172. package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
  173. package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
@@ -0,0 +1,245 @@
1
+ import { asText } from "../../lib/as-text.js";
2
+ import { hashArgs } from "../../lib/approval-tokens.js";
3
+ import { classifyTextCommand, redactSecrets } from "../../safety-policy.js";
4
+ import { evaluateCommandRisk, loadRiskRules } from "../../risk-rule-engine.js";
5
+ import { redactWithSupplementalKeys } from "../../lib/supplemental-redaction.js";
6
+ import { isSecretRef } from "../../lib/secret-vault/refs.js";
7
+ // The sandbox pack's approval spec table. Nine tools join the gate: the two
8
+ // exec faces are CLASSIFIED (content decides — a benign command runs with no
9
+ // confirmation surface at all, a write-classified one confirms on every
10
+ // call), the seven mutating lifecycle faces are ALWAYS (a human present per
11
+ // call, no content rule ever exempts them). The strict classification runs
12
+ // on the exec faces' `command` argument through the SAME engines the Bash
13
+ // face uses — classifyTextCommand plus the cloud-risk-rules catalog — so a
14
+ // destructive command is a disabled guard at the gate face (never a minted
15
+ // token the run then denies, ApprovalCoreMint's NoDoomedToken) and the deny
16
+ // survives every confirmation channel.
17
+ //
18
+ // The binding value is the call's own arguments with the approval carriers
19
+ // (approvalToken, approvedByUser, vendorConfirmed) stripped: the hash the
20
+ // token binds and the ledger records is the CONTENT the user confirms, so a
21
+ // retry that only drifts on a carrier rides the same consent key.
22
+ // Approval-chain carrier fields: never part of the content the user
23
+ // confirms. `command` stays IN the binding — on the exec faces it is the
24
+ // content itself, not a display anchor (the commandAnchor machinery is the
25
+ // hcloud pair's; these tools declare none).
26
+ const APPROVAL_CARRIER_KEYS = new Set(['approvalToken', 'approvedByUser', 'vendorConfirmed']);
27
+ export function bindingArgs(args) {
28
+ const out = {};
29
+ for (const [key, value] of Object.entries(args ?? {})) {
30
+ if (APPROVAL_CARRIER_KEYS.has(key))
31
+ continue;
32
+ out[key] = value;
33
+ }
34
+ return out;
35
+ }
36
+ // The pin view: the binding value through the product's redaction pipeline
37
+ // plus the supplemental key vocabulary the trace face shares (api_key and
38
+ // the value channel — sandbox_credentials' long-lived DevBridge key rides
39
+ // api_key; no sandbox tool uses `value`, so the entry is collision-free).
40
+ function pinViewOf(bindingValue) {
41
+ return redactWithSupplementalKeys(redactSecrets(bindingValue));
42
+ }
43
+ const rulingMemo = new WeakMap();
44
+ function computeRuling(command) {
45
+ // The catalog is file-backed; read it once per process (classify stays a
46
+ // pure function of its input — same command, same ruling).
47
+ const catalog = loadRiskRules();
48
+ const rulesDeny = evaluateCommandRisk(command, { catalog }).findings.find((finding) => finding.severity === 'deny');
49
+ if (rulesDeny) {
50
+ return {
51
+ verdict: 'none',
52
+ denyReason: `rule ${rulesDeny.ruleId}: ${rulesDeny.message} Remediation: ${rulesDeny.remediation}`,
53
+ };
54
+ }
55
+ const text = classifyTextCommand(command);
56
+ if (text.decision === 'deny' && (text.risk === 'write' || text.risk === 'execution')) {
57
+ return { verdict: 'required' };
58
+ }
59
+ if (text.decision === 'deny') {
60
+ return { verdict: 'none', denyReason: text.reason ?? 'the command is blocked by strict classification.' };
61
+ }
62
+ return { verdict: 'none' };
63
+ }
64
+ function rulingForBinding(bindingValue) {
65
+ if (bindingValue && typeof bindingValue === 'object' && !Array.isArray(bindingValue)) {
66
+ const cached = rulingMemo.get(bindingValue);
67
+ if (cached)
68
+ return cached;
69
+ const ruling = computeRuling(asText(bindingValue.command ?? ''));
70
+ rulingMemo.set(bindingValue, ruling);
71
+ return ruling;
72
+ }
73
+ return computeRuling(asText(bindingValue));
74
+ }
75
+ // The execution floor: a strict deny refuses in BOTH modes, before any mint,
76
+ // consent record, or token consume — destructive content is never
77
+ // unlockable, so the refusal names the rule and nothing burns.
78
+ function assertCommandAllowed(bindingValue) {
79
+ const ruling = rulingForBinding(bindingValue);
80
+ if (ruling.denyReason === undefined)
81
+ return;
82
+ throw new Error('Sandbox command denied by strict classification (no confirmation unlocks it). ' + `${ruling.denyReason}`);
83
+ }
84
+ // One summarized view per tool family. Every string the view carries is
85
+ // built from the REDACTED pin view — the summarize contract forbids the raw
86
+ // argument stream in any popup surface.
87
+ function asRecordView(bindingValue) {
88
+ return bindingValue && typeof bindingValue === 'object' && !Array.isArray(bindingValue)
89
+ ? bindingValue
90
+ : {};
91
+ }
92
+ function viewOf(bindingValue, summary) {
93
+ const record = asRecordView(bindingValue);
94
+ return {
95
+ summary: summary(record),
96
+ argsHash: hashArgs(bindingValue),
97
+ pinView: pinViewOf(bindingValue),
98
+ };
99
+ }
100
+ // A short redacted field echo for the summary line: "port 8080" style, never
101
+ // the whole JSON blob.
102
+ function fieldEcho(view, keys) {
103
+ const parts = [];
104
+ for (const key of keys) {
105
+ const value = view[key];
106
+ if (value === undefined || value === null || value === '')
107
+ continue;
108
+ const text = asText(pinViewOf(value));
109
+ parts.push(`${key} ${text}`);
110
+ }
111
+ return parts.join(', ');
112
+ }
113
+ function execView(toolShortName, bindingValue) {
114
+ const record = asRecordView(bindingValue);
115
+ const command = typeof record.command === 'string' ? asText(pinViewOf(record.command)) : '';
116
+ const where = fieldEcho(record, ['workspace_id', 'username']);
117
+ const summary = `huaweicloud_sandbox_${toolShortName}${where !== '' ? ` (${where})` : ''}: ` +
118
+ (command !== '' ? command : '(no command)');
119
+ return {
120
+ summary,
121
+ argsHash: hashArgs(bindingValue),
122
+ pinView: pinViewOf(bindingValue),
123
+ ...(command !== '' ? { command } : {}),
124
+ };
125
+ }
126
+ // One shared spec line for every sandbox registration: the binding value is
127
+ // the call's own arguments with the approval carriers stripped (see
128
+ // bindingArgs). Without this the carriers ride into the hash — a retry
129
+ // carrying the token would bind differently from the mint, and every
130
+ // confirmation would be single-use-by-construction.
131
+ function sandboxBinding() {
132
+ return { domain: 'sandbox', tokenSource: 'gate', normalizeArgs: (args) => bindingArgs(args) };
133
+ }
134
+ function execSpec(toolShortName) {
135
+ return {
136
+ ...sandboxBinding(),
137
+ flavor: 'classified',
138
+ classify: (bindingValue) => rulingForBinding(bindingValue).verdict,
139
+ assertArgsExecutable: (bindingValue) => assertCommandAllowed(bindingValue),
140
+ // The command IS the content, and the confirmation surfaces display it,
141
+ // so it anchors itself: provided must equal the binding's own command
142
+ // (it always does when the call is honest — the binding derives from
143
+ // the args). The anchor exists so the no-anchor refusal shape (a
144
+ // stuffed command on a tool that declares no displayable line) never
145
+ // kills the exec faces after the serial landing (the anchor-collision
146
+ // decision): the exec calls are anchored, the seven lifecycle faces are
147
+ // not and refuse a stuffed command.
148
+ commandAnchor: (bindingValue) => {
149
+ const command = bindingValue.command;
150
+ return typeof command === 'string' && command !== '' ? [command] : [];
151
+ },
152
+ summarize: (bindingValue) => execView(toolShortName, bindingValue),
153
+ };
154
+ }
155
+ const connectSpec = {
156
+ ...sandboxBinding(),
157
+ flavor: 'always',
158
+ summarize: (bindingValue) => viewOf(bindingValue, (view) => {
159
+ const target = fieldEcho(view, ['pool_type']);
160
+ return `huaweicloud_sandbox_connect: connect a sandbox${target !== '' ? ` (${target})` : ''}`;
161
+ }),
162
+ };
163
+ const exposeTunnelSpec = {
164
+ ...sandboxBinding(),
165
+ flavor: 'always',
166
+ summarize: (bindingValue) => viewOf(bindingValue, (view) => {
167
+ const target = fieldEcho(view, ['port', 'expiry_hours']);
168
+ return `huaweicloud_sandbox_expose_tunnel: expose a public tunnel URL${target !== '' ? ` (${target})` : ''}`;
169
+ }),
170
+ };
171
+ const renewTunnelSpec = {
172
+ ...sandboxBinding(),
173
+ flavor: 'always',
174
+ summarize: (bindingValue) => viewOf(bindingValue, (view) => {
175
+ const target = fieldEcho(view, ['tunnel_id', 'expiry_hours']);
176
+ return `huaweicloud_sandbox_renew_tunnel: renew a tunnel's lifetime${target !== '' ? ` (${target})` : ''}`;
177
+ }),
178
+ };
179
+ const keepaliveWatchdogSpec = {
180
+ ...sandboxBinding(),
181
+ flavor: 'always',
182
+ summarize: (bindingValue) => viewOf(bindingValue, (view) => {
183
+ const count = Array.isArray(view.tunnels) ? view.tunnels.length : 0;
184
+ const ids = Array.isArray(view.tunnels)
185
+ ? view.tunnels
186
+ .map((tunnel) => tunnel && typeof tunnel === 'object' ? asText(tunnel.tunnel_id ?? '') : '')
187
+ .filter((id) => id !== '')
188
+ : [];
189
+ return `huaweicloud_sandbox_keepalive_watchdog: install/replace the keepalive watchdog over ${count} tunnel(s)${ids.length > 0 ? ` (${ids.join(', ')})` : ''}`;
190
+ }),
191
+ };
192
+ const signAgreementSpec = {
193
+ ...sandboxBinding(),
194
+ flavor: 'always',
195
+ summarize: (bindingValue) => viewOf(bindingValue, () => 'huaweicloud_sandbox_sign_agreement: sign all unsigned or outdated Huawei Cloud developer service agreements for the current user'),
196
+ };
197
+ const credentialsSpec = {
198
+ ...sandboxBinding(),
199
+ flavor: 'always',
200
+ summarize: (bindingValue) => {
201
+ // Name the api_key channel the HANDLER will actually use, never the
202
+ // value (interrogate F1 round 3, F2): handlers-credentials resolves
203
+ // env-first (process.env.HW_API_KEY || args.api_key), so the view
204
+ // mirrors that precedence — an env tier set makes the parameter or ref
205
+ // beside it a dead letter the confirmation must not claim. A vault ref
206
+ // is itself conversation-safe (that is the ref doctrine), and the
207
+ // parameter channel is named with the value redacted by the pin-view
208
+ // pass.
209
+ const rawApiKey = asText(asRecordView(bindingValue).api_key ?? '');
210
+ const channel = process.env.HW_API_KEY
211
+ ? 'api_key via environment (value redacted)'
212
+ : rawApiKey !== ''
213
+ ? isSecretRef(rawApiKey)
214
+ ? `api_key via vault ref ${rawApiKey}`
215
+ : 'api_key via parameter (value redacted)'
216
+ : '';
217
+ return viewOf(bindingValue, (view) => {
218
+ const target = fieldEcho(view, ['session_id', 'dev_stage_id', 'enable_sts']);
219
+ const scope = target !== '' ? ` (${target})` : '';
220
+ return (`huaweicloud_sandbox_credentials: validate and inject temporary credentials into the sandbox${scope}` +
221
+ (channel !== '' ? `; ${channel}` : ''));
222
+ });
223
+ },
224
+ };
225
+ // 关机(port-pr6):不可逆生命周期面,always。确认视图点名目标 id 与
226
+ // close-not-delete 事实——确认面显示的是开发者要关哪台沙箱,不是参数流。
227
+ const shutdownSpec = {
228
+ ...sandboxBinding(),
229
+ flavor: 'always',
230
+ summarize: (bindingValue) => viewOf(bindingValue, (view) => {
231
+ const target = fieldEcho(view, ['session_id', 'dev_stage_id', 'workspace_id']);
232
+ return `huaweicloud_sandbox_shutdown: shut down the sandbox (close only — instance retained, reconnect wakes it)${target !== '' ? ` (${target})` : ''}`;
233
+ }),
234
+ };
235
+ export const SANDBOX_APPROVAL_SPECS = {
236
+ huaweicloud_sandbox_connect: connectSpec,
237
+ huaweicloud_sandbox_exec_with_session: execSpec('exec_with_session'),
238
+ huaweicloud_sandbox_exec_one_shot: execSpec('exec_one_shot'),
239
+ huaweicloud_sandbox_expose_tunnel: exposeTunnelSpec,
240
+ huaweicloud_sandbox_renew_tunnel: renewTunnelSpec,
241
+ huaweicloud_sandbox_keepalive_watchdog: keepaliveWatchdogSpec,
242
+ huaweicloud_sandbox_sign_agreement: signAgreementSpec,
243
+ huaweicloud_sandbox_credentials: credentialsSpec,
244
+ huaweicloud_sandbox_shutdown: shutdownSpec,
245
+ };
@@ -0,0 +1,71 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ // The async expose-task registry (AX N-SB.1). An expose chain can outlive
3
+ // the host's MCP request timeout (auth gate + selective cleanups + up to
4
+ // four ~63s expose execs + the persistence re-verify + keepalive enrollment)
5
+ // while the server completes it — the synchronous tool then loses the
6
+ // publicUrl. An async start returns immediately and the poll tool delivers
7
+ // the finished result in-band.
8
+ //
9
+ // The registry is process-scoped (the stdio MCP server owns one). A restart
10
+ // loses the receipt while the tunnel may already live; the unknown hint
11
+ // therefore teaches recovery (re-expose / deploy_check) and never fabricates
12
+ // a URL. Entries are swept after the TTL so a long session cannot grow the
13
+ // map unbounded.
14
+ export const EXPOSE_TASK_ID_PATTERN = /^exp-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
15
+ const EXPOSE_TASK_TTL_MS = 30 * 60_000;
16
+ const tasks = new Map();
17
+ function sweep(now) {
18
+ for (const [taskId, task] of tasks) {
19
+ if (now - task.startedAt > EXPOSE_TASK_TTL_MS)
20
+ tasks.delete(taskId);
21
+ }
22
+ }
23
+ export function startExposeTask(workspaceId, port, run) {
24
+ const now = Date.now();
25
+ sweep(now);
26
+ const taskId = `exp-${randomUUID()}`;
27
+ const snapshot = { startedAt: now, workspaceId, port };
28
+ tasks.set(taskId, { ...snapshot, state: 'running' });
29
+ // The chain runs detached from the tool call: the client may time out or
30
+ // cancel the start request, but the server-side work (and the tunnel it
31
+ // creates) must continue. Both settle paths are recorded, so the promise
32
+ // is never an unhandled rejection.
33
+ void run().then((result) => {
34
+ tasks.set(taskId, { ...snapshot, state: 'done', result });
35
+ }, (error) => {
36
+ tasks.set(taskId, {
37
+ ...snapshot,
38
+ state: 'failed',
39
+ error: error instanceof Error ? error.message : String(error),
40
+ });
41
+ });
42
+ return { taskId, startedAt: now };
43
+ }
44
+ export function pollExposeTask(taskId) {
45
+ const now = Date.now();
46
+ sweep(now);
47
+ const task = tasks.get(taskId);
48
+ if (!task) {
49
+ return {
50
+ state: 'unknown',
51
+ hint: 'No task with this id is known to this MCP server process (it never started here, the session restarted, or the ' +
52
+ '30-minute receipt expired). The tunnel may already exist: run huaweicloud_sandbox_deploy_check to read it, or ' +
53
+ 're-run huaweicloud_sandbox_expose_tunnel (same port) — do not assume success without a URL.',
54
+ };
55
+ }
56
+ if (task.state === 'running') {
57
+ return {
58
+ state: 'running',
59
+ elapsedMs: now - task.startedAt,
60
+ hint: 'The expose chain is running in the background (auth, cleanup, host start, health check, keepalive). Call again.',
61
+ };
62
+ }
63
+ if (task.state === 'done') {
64
+ return { state: 'done', result: task.result };
65
+ }
66
+ return { state: 'failed', error: task.error };
67
+ }
68
+ // Test seam: isolate a process-global registry between cases.
69
+ export function _resetExposeTasksForTests() {
70
+ tasks.clear();
71
+ }
@@ -1,17 +1,39 @@
1
- import { execOneShot, execWithSession, setWorkspaceId } from "../../sandbox/session-manager.js";
2
- import { hdkitCheckUser, hdkitSignAgreement, hdkitConnect } from "../../lib/hdkit/hdkitservice-api.js";
1
+ import { execWithSession, closeSession, getCurrentWorkspaceId, setWorkspaceId } from "../../sandbox/session-manager.js";
2
+ import { cleanupDevbridgeTunnels } from "../../sandbox/devbridge-tunnel.js";
3
+ import { hdkitCheckUser, hdkitSignAgreement, hdkitConnectWithRetry, hdkitShutdown, } from "../../lib/hdkit/hdkitservice-api.js";
4
+ import { MANUFACTURED_FAMILY, manufacturedPrefixPattern, canonCode, chainDataValue, cleanMessage, ownDataValue, safeMessageText, safeReadField, serializableRemediation, transientExhaustionResult, versionGateResult, } from "../../lib/hdkit/hdkit-gate.js";
5
+ import { asString } from "../../lib/as-text.js";
3
6
  import { validatePoolType, rememberWorkspacePool, shouldAnnounceConnect, enrichConnectResult, } from "../../lib/hdkit/sandbox-pool.js";
4
7
  import { transferGitRepo } from "./git-transfer.js";
5
- // Account/session-gate handlers (check_user, sign_agreement, connect) for
6
- // the sandbox pack, extracted verbatim from tools.ts in the within-pack
7
- // split for the jscpd complex-file bar; the tools.ts face imports them for
8
- // SANDBOX_TOOL_HANDLERS. handleConnect owns the git repo transfer chain
9
- // invocation (git-transfer.ts).
8
+ // Account/session-gate handlers (check_user, sign_agreement, connect,
9
+ // shutdown) for the sandbox pack, extracted verbatim from tools.ts in the
10
+ // within-pack split for the jscpd complex-file bar; the tools.ts face imports
11
+ // them for SANDBOX_TOOL_HANDLERS. handleConnect owns the git repo transfer
12
+ // chain invocation (git-transfer.ts); handleShutdown owns the DevStation
13
+ // close face (dev 5d89c880 + 3bfc1f53 tip state).
10
14
  export async function handleCheckUser(_args = {}, _opts = {}) {
11
- return await hdkitCheckUser();
15
+ try {
16
+ return await hdkitCheckUser();
17
+ }
18
+ catch (error) {
19
+ // 409 版本门禁按出口折叠(dev e1255a4b):MCP 错误信封只携带 code+message,
20
+ // clientVersion/minVersion/remediation 必须展开为结构化返回才能穿透
21
+ const gate = versionGateResult(error);
22
+ if (gate)
23
+ return gate;
24
+ throw error;
25
+ }
12
26
  }
13
27
  export async function handleSignAgreement(_args = {}, _opts = {}) {
14
- return await hdkitSignAgreement();
28
+ try {
29
+ return await hdkitSignAgreement();
30
+ }
31
+ catch (error) {
32
+ const gate = versionGateResult(error);
33
+ if (gate)
34
+ return gate;
35
+ throw error;
36
+ }
15
37
  }
16
38
  export async function handleConnect(args = {}, _opts = {}) {
17
39
  // 两池:客户端校验 pool_type(非法值在本地即报错,不发无效请求);未传交由服务端默认 ephemeral
@@ -28,27 +50,108 @@ export async function handleConnect(args = {}, _opts = {}) {
28
50
  }
29
51
  let connectResult;
30
52
  try {
31
- connectResult = await hdkitConnect(connectArgs);
53
+ // AX N-SB.2: the MCP tool answers inside the host's request budget — a
54
+ // transient gateway timeout returns a pending receipt instead of sleeping
55
+ // through the 30s/45s table (the next call re-attempts and reuses any
56
+ // instance the server already created). Short backoffs (tests/operators)
57
+ // keep the inline ladder.
58
+ connectResult = await hdkitConnectWithRetry(connectArgs, { maxInlineDelayMs: 1000 });
32
59
  }
33
60
  catch (error) {
34
- // 业务预期失败(429 双码 / 烧核 / 凭证失效)转结构化返回,remediation 才能穿透 MCP 边界;
35
- // 其余错误维持抛出(MCP 层透传 code+message)
61
+ // 业务预期失败(429 三码 / 烧核 / 凭证失效)转结构化返回,remediation 才能穿透 MCP 边界;
62
+ // 其余错误维持抛出(MCP 层透传 code+message)。
63
+ // 409 版本门禁(dev e1255a4b)与网关 502/504 重试耗尽(v2 扩展)同样在此折叠。
36
64
  const err = error;
37
- if (err.code === 'HDKIT_QUOTA_EXCEEDED' ||
38
- err.code === 'HDKIT_CAPACITY_INSUFFICIENT' ||
39
- err.code === 'HDKIT_CRED_INVALID' ||
40
- err.coreHoursExhausted) {
65
+ const gate = versionGateResult(err);
66
+ if (gate)
67
+ return gate;
68
+ const exhausted = transientExhaustionResult(err);
69
+ if (exhausted)
70
+ return exhausted;
71
+ // 业务折叠的字段读全过安全卫队与窄化(round 15 建、round 16 深验、
72
+ // round 17 嵌套上下文+快照往返、round 18 快照形态窄化):抛出型 getter/
73
+ // 撤销代理按缺失——缺失的码不进业务分支,原错误原样抛出;remediation 经
74
+ // serializableRemediation 深验——非对象、嵌套 BigInt、循环引用、判别器、
75
+ // 有状态换值、非对象 JSON 视图一并不骑信封
76
+ // 判等口径 vs 渲染口径(round 26/MUST 3):canonCode 只作判等——织入/垫
77
+ // 码的业务码仍按 round-12 教义识别(传输噪声下的真服务码);渲染对齐
78
+ // voucher 谓词——服务端亲署码不含空白渲染字符,原始拼写带空白渲染字
79
+ // 符即非亲署,渲染其清洗形会把伪造码洗成亲署拼写的字节等价物(
80
+ // HDKIT_QUOTA\u200b_EXCEEDED 洗成签名 HDKIT_QUOTA_EXCEEDED——真实 wire
81
+ // 路径可经网关/代理注入织入拼写)——一律省略(码字段与前缀同判);
82
+ // 空白码同样省略(never-blank-code 教义——此前渲染 code:'')
83
+ const rawBusinessCode = safeReadField(error, 'code');
84
+ const businessCode = canonCode(rawBusinessCode);
85
+ // 伪造码不渲染(round 30/MUST 3,round 8 教义在业务折叠落地):
86
+ // 无码烧核 502/504 经请求层制造了 HTTP_502/504——分发追踪靠标记
87
+ // (r29),信封的码字段与前缀不得渲染客户端制造拼写
88
+ const renderCode = typeof rawBusinessCode === 'string' &&
89
+ businessCode !== '' &&
90
+ businessCode === rawBusinessCode &&
91
+ !MANUFACTURED_FAMILY.test(businessCode)
92
+ ? rawBusinessCode
93
+ : undefined;
94
+ // 伪造码的消息前缀一并剥除(round 30/MUST 3,与耗尽装饰同法:
95
+ // 请求层把 "HTTP_x: " 合进了消息——客户端制造拼写不得以任何表面(码字段或
96
+ // 可见消息)渲染上信封;循环剥除(页面消息可翻倍),剥后为空则走设计兜底
97
+ let businessMessage = cleanMessage(safeMessageText(error)) || '';
98
+ if (businessCode !== '' && MANUFACTURED_FAMILY.test(businessCode)) {
99
+ const stripPattern = manufacturedPrefixPattern(businessCode);
100
+ while (stripPattern) {
101
+ const hit = stripPattern.exec(businessMessage);
102
+ if (!hit)
103
+ break;
104
+ businessMessage = businessMessage.slice(hit[0].length);
105
+ }
106
+ businessMessage = cleanMessage(businessMessage);
107
+ }
108
+ // 转向字段改自有数据描述符读(round 26/MUST 3):[[Get]] 读让立着访问
109
+ // 器注入任意文案(pay-here URL);与门禁/耗尽折叠的 ownDataValue 同标
110
+ // 准(round 25 漏掉了本折叠)
111
+ const coreHoursExhausted = chainDataValue(error, 'coreHoursExhausted');
112
+ if (businessCode === 'HDKIT_QUOTA_EXCEEDED' ||
113
+ businessCode === 'HDKIT_TEMPLATE_QUOTA_EXCEEDED' ||
114
+ businessCode === 'HDKIT_CAPACITY_INSUFFICIENT' ||
115
+ businessCode === 'HDKIT_CRED_INVALID' ||
116
+ coreHoursExhausted) {
117
+ // retryAfter 窄到字符串、remediation 深验(round 16):BigInt 等敌意值
118
+ // 不骑信封(MCP 序列化边界,与门禁/耗尽折叠同口径)
119
+ const rawRetryAfter = ownDataValue(error, 'retryAfter');
120
+ const retryAfter = typeof rawRetryAfter === 'string' ? rawRetryAfter : undefined;
121
+ const remediation = serializableRemediation(ownDataValue(error, 'remediation'));
122
+ // 空白/缺失消息走构建口同款代码前缀兜底(round 20):其余折叠口从不
123
+ // 渲染空 message,此处对齐——纯不可见消息按缺失
124
+ const fallbackMessage = renderCode ? `${renderCode}: hdkitservice error` : 'hdkitservice error';
41
125
  return {
42
126
  ok: false,
43
- code: err.code,
44
- message: err.message,
45
- ...(err.retryAfter !== undefined ? { retryAfter: err.retryAfter } : {}),
46
- ...(err.coreHoursExhausted ? { coreHoursExhausted: true } : {}),
47
- ...(err.remediation ? { remediation: err.remediation } : {}),
127
+ ...(renderCode ? { code: renderCode } : {}),
128
+ message: businessMessage || fallbackMessage,
129
+ ...(retryAfter ? { retryAfter } : {}),
130
+ ...(coreHoursExhausted ? { coreHoursExhausted: true } : {}),
131
+ ...(remediation ? { remediation } : {}),
48
132
  };
49
133
  }
50
134
  throw error;
51
135
  }
136
+ if (connectResult?.pending === true) {
137
+ const retryAfterMs = typeof connectResult.retryAfterMs === 'number' && Number.isFinite(connectResult.retryAfterMs)
138
+ ? connectResult.retryAfterMs
139
+ : 30000;
140
+ const retryAfter = `${Math.max(1, Math.ceil(retryAfterMs / 1000))}s`;
141
+ return {
142
+ ok: false,
143
+ pending: true,
144
+ retryAfter,
145
+ retryAfterMs,
146
+ ...(typeof connectResult.code === 'string' ? { code: connectResult.code } : {}),
147
+ message: typeof connectResult.message === 'string' && connectResult.message
148
+ ? connectResult.message
149
+ : 'the hdkitservice gateway timed out during orchestration.',
150
+ hint: `The sandbox instance may already exist on the server. Re-call huaweicloud_sandbox_connect with the SAME ` +
151
+ `parameters after ~${retryAfter} — a created instance is reused. Do not start a second sandbox and do not ` +
152
+ `debug this as a credential failure.`,
153
+ };
154
+ }
52
155
  const rawDevStageId = connectResult?.dev_stage_id || connectResult?.devStageId;
53
156
  const devStageId = typeof rawDevStageId === 'string' ? rawDevStageId : undefined;
54
157
  let announceConnect = true;
@@ -59,11 +162,14 @@ export async function handleConnect(args = {}, _opts = {}) {
59
162
  // 池归属 + 生命周期口径缓存(服务端回显优先,缺失时客户端默认兜底)。
60
163
  // 双读兜底与 devStageId 同型(防服务端 wire 命名漂移,QA #1082 配对复审教训)
61
164
  rememberWorkspacePool(devStageId, connectResult?.pool_type || connectResult?.poolType, connectResult || {});
165
+ // 连接后的选择性隧道清理(dev 97c4bc8a):只清孤儿记录/宿主;保留其他
166
+ // 端口、其他会话与 keepalive 名单内的隧道。best-effort —— 清理失败不得
167
+ // 阻断 connect 本身。
62
168
  try {
63
- await execOneShot(devStageId, 'devbridge delete-all 2>/dev/null || true', 'root', 15000);
169
+ await cleanupDevbridgeTunnels(devStageId, { mode: 'stale' });
64
170
  }
65
171
  catch {
66
- // best-effort: a fresh sandbox may have no tunnels (or no devbridge) to delete
172
+ // best-effort: a fresh sandbox may have no tunnels (or no devbridge) to clean
67
173
  }
68
174
  try {
69
175
  // #999: /workspace/.local/bin first — the data-disk install survives
@@ -78,3 +184,54 @@ export async function handleConnect(args = {}, _opts = {}) {
78
184
  // 生命周期提示:仅首次连接 / 关机唤醒时播报(服务端回显 pool_type 才生成)
79
185
  return enrichConnectResult(connectResult, { announce: announceConnect });
80
186
  }
187
+ // 关机错误的结构化折叠(dev 5d89c880 的 toVersionGateResult 面,去掉 v2 未
188
+ // 移植的 autoUpgrade 字段):MCP 错误信封只携带 code+message,指引与版本字段
189
+ // 必须展开为结构化返回才能穿透边界——404 HDKIT_SANDBOX_NOT_FOUND、烧核、
190
+ // 版本门禁与传输层失败一律 ok:false 返回,不再裸抛。
191
+ function shutdownErrorResult(error) {
192
+ const err = error;
193
+ return {
194
+ ok: false,
195
+ code: err.code,
196
+ message: err instanceof Error ? err.message : String(error),
197
+ ...(err.retryAfter !== undefined ? { retryAfter: err.retryAfter } : {}),
198
+ ...(err.coreHoursExhausted ? { coreHoursExhausted: true } : {}),
199
+ ...(err.clientVersion ? { clientVersion: err.clientVersion } : {}),
200
+ ...(err.minVersion ? { minVersion: err.minVersion } : {}),
201
+ ...(err.remediation ? { remediation: err.remediation } : {}),
202
+ };
203
+ }
204
+ export async function handleShutdown(args = {}, _opts = {}) {
205
+ const sessionId = args.session_id;
206
+ // 3bfc1f53:workspaceId 与 devStageId 分开解析。仅 session_id 时 devStageId
207
+ // 留空(不把 session_id 字符串当 workspace 用),终端会话以服务端回传的
208
+ // devStageId 为准关闭。
209
+ const workspaceId = args.dev_stage_id || args.workspace_id || getCurrentWorkspaceId();
210
+ const devStageId = args.dev_stage_id || args.workspace_id || (sessionId ? undefined : workspaceId);
211
+ const id = sessionId || devStageId;
212
+ if (!id) {
213
+ return {
214
+ ok: false,
215
+ code: 'HDKIT_INVALID_REQUEST',
216
+ message: 'session_id or dev_stage_id is required. No sandbox connected — call huaweicloud_sandbox_connect first, or pass workspace_id.',
217
+ };
218
+ }
219
+ try {
220
+ const shutdown = await hdkitShutdown(sessionId, devStageId);
221
+ try {
222
+ // 3bfc1f53 终态:仅 session_id 时以服务端回传的 devStageId 关终端会话。
223
+ // 与 dev 同形的 || 穿透(dev 3bfc1f53):空串回显不截停链——asString 只
224
+ // 收窄类型,真值判定仍按 ||(id 检查已保证链上有真值,'' 尾仅为类型
225
+ // 完备)。
226
+ const wsForClose = asString(shutdown.devStageId) || asString(workspaceId) || asString(sessionId) || '';
227
+ await closeSession(wsForClose, args.username || 'root');
228
+ }
229
+ catch {
230
+ // best-effort: 关机已受理,终端会话随沙箱停止一并消亡
231
+ }
232
+ return { ok: true, ...shutdown };
233
+ }
234
+ catch (error) {
235
+ return shutdownErrorResult(error);
236
+ }
237
+ }
@@ -1,6 +1,7 @@
1
1
  import { randomBytes } from 'node:crypto';
2
2
  import { execOneShot, execWithSession, getCurrentWorkspaceId } from "../../sandbox/session-manager.js";
3
3
  import { hdkitCredentials } from "../../lib/hdkit/hdkitservice-api.js";
4
+ import { versionGateResult } from "../../lib/hdkit/hdkit-gate.js";
4
5
  import { getCredentials } from "../../lib/hdkit/hwlink-api.js";
5
6
  import { validateIamCredentials } from "../../auth/credential-validator.js";
6
7
  import { resolveCredentialsWithRuntime } from "../../auth/credentials.js";
@@ -58,7 +59,18 @@ export async function handleCredentials(args = {}, _opts = {}) {
58
59
  hint: 'Credentials were NOT injected into the sandbox. Fix AK/SK first: run "npx huaweicloud-devkit auth init" or correct HW_ACCESS_KEY/HW_SECRET_KEY, then retry.',
59
60
  };
60
61
  }
61
- const credResult = await hdkitCredentials(args.session_id, devStageId, args.enable_sts !== false);
62
+ // 409 版本门禁同样拦截 credentials 出口:结构化折叠(dev e1255a4b),
63
+ // clientVersion/minVersion/remediation 才能穿透 MCP 边界
64
+ let credResult;
65
+ try {
66
+ credResult = await hdkitCredentials(args.session_id, devStageId, args.enable_sts !== false);
67
+ }
68
+ catch (error) {
69
+ const gate = versionGateResult(error);
70
+ if (gate)
71
+ return gate;
72
+ throw error;
73
+ }
62
74
  const sandboxWsIdCred = args.dev_stage_id || getCurrentWorkspaceId();
63
75
  // The DevBridge API Key is a LONG-LIVED account-level credential (no expiry, manual
64
76
  // revocation only) — unlike the temporary STS AK/SK. It is stored in its own file