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
@@ -11,6 +11,8 @@ export interface Policy {
11
11
  blockedSecretOperations: string[];
12
12
  blockedSecretCliPatterns: string[];
13
13
  blockedApprovalCliPatterns: string[];
14
+ blockedAccountSwitchCliPatterns: string[];
15
+ blockedGatedCliPatterns: string[];
14
16
  writeOperationPrefixes: string[];
15
17
  readOperationPrefixes: string[];
16
18
  readOperationExceptions: string[];
@@ -64,6 +66,11 @@ export function loadPolicy(path: string): Policy {
64
66
  blockedSecretOperations: toStringArray(raw.blockedSecretOperations, 'blockedSecretOperations'),
65
67
  blockedSecretCliPatterns: toStringArray(raw.blockedSecretCliPatterns, 'blockedSecretCliPatterns'),
66
68
  blockedApprovalCliPatterns: toStringArray(raw.blockedApprovalCliPatterns, 'blockedApprovalCliPatterns'),
69
+ blockedAccountSwitchCliPatterns: toStringArray(
70
+ raw.blockedAccountSwitchCliPatterns,
71
+ 'blockedAccountSwitchCliPatterns',
72
+ ),
73
+ blockedGatedCliPatterns: toStringArray(raw.blockedGatedCliPatterns, 'blockedGatedCliPatterns'),
67
74
  writeOperationPrefixes,
68
75
  readOperationPrefixes: toStringArray(raw.readOperationPrefixes, 'readOperationPrefixes'),
69
76
  readOperationExceptions: toStringArray(raw.readOperationExceptions, 'readOperationExceptions'),
@@ -6,7 +6,7 @@ function isSecretKeyName(key: unknown, policy: Policy = DEFAULT_POLICY): boolean
6
6
  .toLowerCase()
7
7
  .replace(/[^a-z0-9]/g, '');
8
8
  if (
9
- /access.*key|secret.*key|security.*token|xauth.*token|authorization|password|passwd|adminpass|credential|private.*key|userdata|metadata|inputvalue/.test(
9
+ /access.*key|secret.*key|secret.*string|secret.*binary|secret.*text|api.*key|security.*token|xauth.*token|authorization|password|passwd|adminpass|credential|private.*key|userdata|metadata|inputvalue/.test(
10
10
  normalized,
11
11
  )
12
12
  ) {
@@ -15,6 +15,15 @@ function isSecretKeyName(key: unknown, policy: Policy = DEFAULT_POLICY): boolean
15
15
  return policy.secretKeyNamePatterns.some((pattern) => regexFrom(`^(${pattern})$`).test(String(key)));
16
16
  }
17
17
 
18
+ // The key vocabulary is shared by every evidence/command redaction face.
19
+ // Backslashes around the key/value are tolerated because shell-transcribed
20
+ // commands and nested JSON carry `\"password\":\"…\"` spellings; `secret://`
21
+ // refs are exempt (the ref is conversation-safe by doctrine). `secret_text`
22
+ // and `api_key` joined the family with the AX N-R4.1 fix — DEW's plaintext
23
+ // secret and the DevBridge key were crossing every evidence surface.
24
+ const SECRET_KEY_VALUE_RE =
25
+ /((?:access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|secret[_-]?text|api[_-]?key|secret(?!:\/)|security[_-]?token|x[_-]?auth[_-]?token|token|authorization|password|passwd|admin[_-]?pass|credential|input[_-]?value)\\*["']?\s*[:=]\s*[\\"']*\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi;
26
+
18
27
  function redactString(text: unknown): string {
19
28
  return (
20
29
  String(text)
@@ -32,14 +41,23 @@ function redactString(text: unknown): string {
32
41
  /(["']?(?:user[_-]?data|metadata|private[_-]?key|authorization|x[_-]?auth[_-]?token)["']?\s*[:=]\s*).*/gi,
33
42
  '$1<redacted>',
34
43
  )
35
- .replace(
36
- /(["']?(?:access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|security[_-]?token|token|password|passwd|admin[_-]?pass|credential|input[_-]?value)["']?\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi,
37
- '$1<redacted>',
38
- )
39
- .replace(/\b(["']?(?:AK|SK)["']?\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi, '$1<redacted>')
44
+ .replace(SECRET_KEY_VALUE_RE, '$1<redacted>')
45
+ // XML settings shapes (`<password>value</password>`, the settings.xml
46
+ // deploy idiom) carry no `:`/`=` separator, so the key-value family
47
+ // never saw them — the artifact evidence echoed the password verbatim
48
+ // (AX N-R4.1). The tag name is backreferenced so a mismatched close
49
+ // tag is not half-redacted.
50
+ .replace(/<(password|passwd|pwd)>[^<]*<\/\1>/gi, '<$1><redacted></$1>')
51
+ .replace(/\b(["']?(?:AK|SK)\\*["']?\s*[:=]\s*[\\"']*\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi, '$1<redacted>')
40
52
  );
41
53
  }
42
54
 
55
+ // The string-level evidence redaction entry (risk-rule-engine's excerpt and
56
+ // any future evidence face): one vocabulary, no second drift-prone copy.
57
+ export function redactEvidenceText(text: unknown): string {
58
+ return redactString(text);
59
+ }
60
+
43
61
  // Overload parameter names are documentation only; the implementation below
44
62
  // carries the real, used parameters.
45
63
  export function redactSecrets(value: string, policy?: Policy): string;
@@ -1,4 +1,4 @@
1
- import { evaluateCommandRisk, mergeRiskDecision, type RiskDecision } from '../risk-rule-engine.ts';
1
+ import { evaluateCommandRisk, mergeRiskDecision, type RiskDecision, type RiskEvaluation } from '../risk-rule-engine.ts';
2
2
  import type { ClassifyOptions } from './policy.ts';
3
3
 
4
4
  // The risk-rule merge seam for both classifiers: a non-deny base decision
@@ -10,22 +10,43 @@ function commandRiskText(normalizedArgs: string[], options: ClassifyOptions): st
10
10
  return options.rawCommand || ['hcloud', ...normalizedArgs].join(' ');
11
11
  }
12
12
 
13
+ // A deny-severity base (the generic write/execution gate) still carries the
14
+ // catalog's specialized findings: the approval decision the developer reads
15
+ // must show WHY the command is risky (broad administrator grant, anonymous
16
+ // write, high-cost shape), not only the generic "write must be approved".
17
+ // Only findings/warnings are attached — decision, risk, and reason stay the
18
+ // base's, so the PreToolUse hook's risk-shaped exemption logic does not
19
+ // drift.
20
+ function attachRiskFindings(base: RiskDecision, risk: RiskEvaluation): RiskDecision {
21
+ if (!risk.findings || risk.findings.length === 0) return base;
22
+ const warnFindings = risk.findings.filter((finding) => finding.severity !== 'deny');
23
+ return {
24
+ ...base,
25
+ findings: [...(base.findings || []), ...risk.findings],
26
+ ...(warnFindings.length > 0 ? { warnings: [...(base.warnings || []), ...warnFindings] } : {}),
27
+ };
28
+ }
29
+
30
+ function mergeRisk(base: RiskDecision, risk: RiskEvaluation): RiskDecision {
31
+ return base.decision === 'deny' ? attachRiskFindings(base, risk) : mergeRiskDecision(base, risk);
32
+ }
33
+
13
34
  export function applyCommandRiskRules(
14
35
  base: RiskDecision,
15
36
  normalizedArgs: string[],
16
37
  options: ClassifyOptions,
17
38
  ): RiskDecision {
18
- if (base.decision === 'deny' || options.skipRiskRules === true) {
39
+ if (options.skipRiskRules === true) {
19
40
  return base;
20
41
  }
21
42
  const risk = evaluateCommandRisk(commandRiskText(normalizedArgs, options));
22
- return mergeRiskDecision(base, risk);
43
+ return mergeRisk(base, risk);
23
44
  }
24
45
 
25
46
  export function applyRawCommandRiskRules(base: RiskDecision, command: string, options: ClassifyOptions): RiskDecision {
26
- if (base.decision === 'deny' || options.skipRiskRules === true) {
47
+ if (options.skipRiskRules === true) {
27
48
  return base;
28
49
  }
29
50
  const risk = evaluateCommandRisk(command);
30
- return mergeRiskDecision(base, risk);
51
+ return mergeRisk(base, risk);
31
52
  }
@@ -45,7 +45,7 @@ interface DeployCheckResult {
45
45
  export const TUNNEL_URL_PATTERN = /TUNNEL_URL:(https:\/\/[A-Za-z0-9_-]+-\d+\.devbridge-s2\.hwtunnel\.com)/;
46
46
 
47
47
  export function buildExposeRemediation(port: number): string {
48
- return `In the sandbox: source /tmp/hw_api_key 2>/dev/null; devbridge delete-all; devbridge create <name>; devbridge port create <tunnelId> -p ${port} --protocol http -a; if command -v setsid >/dev/null 2>&1; then setsid nohup devbridge host <tunnelId> -p ${port} -e 72 > /tmp/host.log 2>&1 < /dev/null & else nohup devbridge host <tunnelId> -p ${port} -e 72 > /tmp/host.log 2>&1 < /dev/null & fi; disown 2>/dev/null || true; If deploy_nginx reported a different (auto-incremented) port in its "port" field, use THAT port instead of the one shown here. Full procedure in huawei-sandbox skill, Step 7 (Expose via DevBridge).`;
48
+ return `In the sandbox: source /tmp/hw_api_key 2>/dev/null; for T in $(devbridge list 2>/dev/null | awk '{gsub(/\\033\\]133;C\\007/, ""); if ($1 !~ /^Tunnel/ && $1 !~ /^No$/) print $1}'); do devbridge port list "$T" 2>/dev/null | awk -v P=${port} '{gsub(/\\033\\]133;C\\007/, ""); if ($1 == P) f=1} END {exit f ? 0 : 1}' && devbridge delete "$T" 2>/dev/null || true; done; devbridge create <name>; devbridge port create <tunnelId> -p ${port} --protocol http -a; if command -v setsid >/dev/null 2>&1; then setsid nohup devbridge host <tunnelId> -p ${port} -e 72 > /tmp/host.log 2>&1 < /dev/null & else nohup devbridge host <tunnelId> -p ${port} -e 72 > /tmp/host.log 2>&1 < /dev/null & fi; disown 2>/dev/null || true; the loop deletes ONLY the tunnels whose port list contains ${port} (any tunnel name — query each tunnel's ports with devbridge port list; a name-based match would miss the custom-named tunnels this flow itself creates), INCLUDING a keepalive-protected tunnel bound to THIS port — a port cannot have two tunnels, so the same-port tunnel is always replaced; all OTHER ports, other sessions and keepalive-protected tunnels on other ports are preserved (never wipe every tunnel here — a global delete kills every session's tunnels). The gsub strips OSC 133 shell-integration markers that wrap every output line on integration-enabled terminals — without it the CLI receives glued tunnel IDs it rejects and the delete silently no-ops. If deploy_nginx reported a different (auto-incremented) port in its "port" field, use THAT port instead of the one shown here. Full procedure in huawei-sandbox skill, Step 7 (Expose via DevBridge).`;
49
49
  }
50
50
 
51
51
  // The deploy-check stdout contract as one exported pure function — the
@@ -3,6 +3,40 @@ import { runOneShot } from './devbridge-exec.ts';
3
3
  import { evaluateDevbridgeVersion } from './devbridge-validation.ts';
4
4
  import type { ExposeTunnelResult } from './devbridge-expose.ts';
5
5
  import type { DevbridgeKeyResult, DevbridgeQuotaKeyHint } from './devbridge-key.ts';
6
+ import {
7
+ canonCode,
8
+ cleanMessage,
9
+ gateFoldPayload,
10
+ isVersionGateError,
11
+ safeMessageText,
12
+ safeReadField,
13
+ } from '../lib/hdkit/hdkit-gate.ts';
14
+
15
+ // 409 门禁在 relay 出口的统一折叠(v2 扩展,台账记录):三个 catch 位共用——
16
+ // 自动创建、自愈重建、配额清单读取。authMode/attempts 保留(探测到的真实状态,
17
+ // 与配额失败信封同款,台账记录该取舍)。
18
+ function versionGateFailure(
19
+ error: unknown,
20
+ port: number,
21
+ authMode: string,
22
+ attempts: Record<string, string>,
23
+ ): { ok: false; failure: ExposeTunnelResult } {
24
+ const fold = gateFoldPayload(error);
25
+ return {
26
+ ok: false,
27
+ failure: {
28
+ ok: false,
29
+ port,
30
+ error: fold.message,
31
+ error_code: fold.code,
32
+ ...(fold.clientVersion ? { clientVersion: fold.clientVersion } : {}),
33
+ ...(fold.minVersion ? { minVersion: fold.minVersion } : {}),
34
+ gateRemediation: fold.remediation,
35
+ authMode: authMode || 'UNKNOWN',
36
+ attempts,
37
+ },
38
+ };
39
+ }
6
40
 
7
41
  // The DevBridge auth waterfall, extracted from devbridge-tunnel so the auth
8
42
  // probe script, its stdout parser, and (with the devbridge-tunnel
@@ -20,8 +54,12 @@ import type { DevbridgeKeyResult, DevbridgeQuotaKeyHint } from './devbridge-key.
20
54
  // fallback (devbridge-key.ts) when keyring injection is unavailable.
21
55
  // AK/SK login (--access-key/--secret-key) was REMOVED: devbridge authentication is
22
56
  // now fixed to API Key only (定稿决策,2026-11-04).
23
- // Every tier performs a real `devbridge auth login --api-key` and verifies with
24
- // `auth status` (must print "Logged in"); on failure the waterfall falls through.
57
+ // Every tier performs a real `devbridge auth login --api-key` (exit code checked),
58
+ // then verifies with `auth status` AND a real authenticated API call
59
+ // (`devbridge list`); on failure the waterfall falls through. The list check is
60
+ // required because a stale key can leave a "Logged in" local token while
61
+ // server-side calls return 40100 — without it the probe reports a usable auth
62
+ // and the auto-create self-heal never triggers.
25
63
  // DB_ATTEMPT_* lines are non-sensitive diagnostics for support escalation.
26
64
  // The HOST orchestrates an auto-create fallback between probe rounds: when the
27
65
  // first probe returns NO_CREDENTIAL, the host calls ensureDevbridgeKey() and
@@ -41,7 +79,13 @@ export function buildDevbridgeAuthProbe(): string {
41
79
  `DB_VERSION=$(devbridge version 2>/dev/null | head -1)`,
42
80
  `echo "DB_VERSION=\${DB_VERSION}"`,
43
81
  `DB_OK=0`,
44
- `db_login_ok() { devbridge auth status 2>/dev/null | grep -q "Logged in"; }`,
82
+ `db_login_ok() {`,
83
+ // 本地 token 可能仍显示 Logged in,但 API key 已在服务端失效(实测
84
+ // list/renew 返回 40100)。因此额外做一次真实鉴权 API 调用,确保探针
85
+ // 结果可用(否则 auto-create 自愈不会触发)。
86
+ ` devbridge auth status 2>/dev/null | grep -q "Logged in" || return 1`,
87
+ ` devbridge list >/dev/null 2>&1`,
88
+ `}`,
45
89
  `db_diag() { echo "DB_ATTEMPT_$1=$2"; }`,
46
90
  ``,
47
91
  `# ---- Tier 1: API Key from the sandbox keyring (platform auto-injection) ----`,
@@ -71,8 +115,7 @@ export function buildDevbridgeAuthProbe(): string {
71
115
  ` db_diag KEYRING "hwcloud-not-installed"`,
72
116
  `fi`,
73
117
  `if [ -n "$HW_DB_KEY" ]; then`,
74
- ` devbridge auth login --api-key "$HW_DB_KEY" >/tmp/db_auth.log 2>&1`,
75
- ` if db_login_ok; then`,
118
+ ` if devbridge auth login --api-key "$HW_DB_KEY" >/tmp/db_auth.log 2>&1 && db_login_ok; then`,
76
119
  ` echo "DB_AUTH_MODE=API_KEY_KEYRING"`,
77
120
  ` DB_OK=1`,
78
121
  ` else`,
@@ -86,8 +129,7 @@ export function buildDevbridgeAuthProbe(): string {
86
129
  `if [ "$DB_OK" -eq 0 ]; then`,
87
130
  ` source /tmp/hw_api_key 2>/dev/null`,
88
131
  ` if [ -n "$HW_API_KEY" ]; then`,
89
- ` devbridge auth login --api-key "$HW_API_KEY" >/tmp/db_auth.log 2>&1`,
90
- ` if db_login_ok; then`,
132
+ ` if devbridge auth login --api-key "$HW_API_KEY" >/tmp/db_auth.log 2>&1 && db_login_ok; then`,
91
133
  ` echo "DB_AUTH_MODE=API_KEY_FILE"`,
92
134
  ` DB_OK=1`,
93
135
  ` else`,
@@ -232,8 +274,10 @@ export async function gateExposeAuth(
232
274
  if (isUsableAuthMode(healParsed.authMode)) {
233
275
  effectiveAuthMode = 'API_KEY_AUTO';
234
276
  }
235
- } catch {
236
- // 自愈失败 → 走泛化降级
277
+ } catch (error) {
278
+ // 409 门禁即时折叠:自愈 catch 原样吞掉会多跑一轮泛化 relay 调用才折
279
+ // 叠(round 3);其余自愈失败仍走泛化降级
280
+ if (isVersionGateError(error)) return versionGateFailure(error, port, authMode, attempts);
237
281
  }
238
282
  }
239
283
  // keyring/文件均无 key → host 调 relay API 自动创建 → 注入沙箱 → 重跑 probe
@@ -247,15 +291,30 @@ export async function gateExposeAuth(
247
291
  effectiveAuthMode = 'API_KEY_AUTO';
248
292
  }
249
293
  } catch (error) {
250
- // 自动创建失败(含配额满 13002)→ 结构化降级
251
- if ((error as { code?: string }).code === 'HDKIT_DEVBRIDGE_KEY_QUOTA_EXCEEDED') {
252
- const keysHint = await keyUpgrade.listKeysForQuotaHint();
294
+ // 门禁先裁(round 25/MUST 4):配额比较此前先求值且自选分支——登记
295
+ // 过的载体 code 视图谎报配额码即被误路由进清 key 信封(配额 hint、空
296
+ // currentKeys、gateRemediation 丢失)。isVersionGateError 对登记载体零
297
+ // 读返回种类裁决(round 24),谎报视图无从介入;未登记载体照旧先经安
298
+ // 全读判配额——canonCode 读过卫队(round 14),抛出型 getter 按缺失
299
+ if (isVersionGateError(error)) return versionGateFailure(error, port, authMode, attempts);
300
+ if (canonCode(safeReadField(error, 'code')) === 'HDKIT_DEVBRIDGE_KEY_QUOTA_EXCEEDED') {
301
+ // 配额清单读取本身遭遇 409:门禁优先(清 key 引导拿不出 currentKeys);
302
+ // 其余读取失败仍降级为空清单
303
+ let keysHint: Awaited<ReturnType<typeof keyUpgrade.listKeysForQuotaHint>> = [];
304
+ try {
305
+ keysHint = await keyUpgrade.listKeysForQuotaHint();
306
+ } catch (listError) {
307
+ if (isVersionGateError(listError)) return versionGateFailure(listError, port, authMode, attempts);
308
+ }
309
+ // 消息读同样过卫队与清洗口(round 14):拒读/空白按缺失——字段缺省,
310
+ // 信封的 error_code/hint/currentKeys 不受影响
311
+ const quotaMessage = cleanMessage(safeMessageText(error));
253
312
  return {
254
313
  ok: false,
255
314
  failure: {
256
315
  ok: false,
257
316
  port,
258
- error: (error as Error).message,
317
+ ...(quotaMessage ? { error: quotaMessage } : {}),
259
318
  error_code: 'HDKIT_DEVBRIDGE_KEY_QUOTA_EXCEEDED',
260
319
  authMode: authMode || 'UNKNOWN',
261
320
  attempts,
@@ -264,7 +323,8 @@ export async function gateExposeAuth(
264
323
  },
265
324
  };
266
325
  }
267
- // 其他自动创建失败 → 继续走原有降级路径(可能 keyring/file 后续可用)
326
+ // 其他自动创建失败 → 继续走原有降级路径(可能 keyring/file 后续可用);
327
+ // 门禁折叠已在本 catch 顶部先裁(round 25/MUST 4)
268
328
  }
269
329
  }
270
330
  }