huaweicloud-devkit 1.1.13 → 2.0.0-next.0

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 (697) hide show
  1. package/README.md +16 -5
  2. package/README.zh-CN.md +16 -5
  3. package/bin/dsh-postinstall.cjs +171 -31
  4. package/bin/setup.cjs +1 -1
  5. package/cordis.patch.yml +1 -1
  6. package/integrations/atomcode/hooks/huaweicloud-telemetry.js +29 -33
  7. package/integrations/dsh/hook-plugin.d.mts +19 -0
  8. package/integrations/dsh/hook-plugin.mjs +23 -22
  9. package/integrations/hermes/hooks/huaweicloud-telemetry.py +26 -43
  10. package/integrations/hermes/manifest.yaml +35 -10
  11. package/integrations/opencode/commands/huaweicloud-doctor.md +3 -2
  12. package/integrations/opencode/hooks/skill-tracker.js +70 -89
  13. package/integrations/opencode/opencode.json +5 -6
  14. package/integrations/workbuddy/hooks/telemetry-tracker.py +27 -45
  15. package/package.json +32 -11
  16. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -2
  17. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -2
  18. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -2
  19. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -2
  20. package/plugins/huaweicloud-core/.mcp.json +1 -1
  21. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -2
  22. package/plugins/huaweicloud-core/dist/agents/atomcode.js +118 -0
  23. package/plugins/huaweicloud-core/dist/agents/codearts-work.js +121 -0
  24. package/plugins/huaweicloud-core/dist/agents/codearts.js +69 -0
  25. package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +193 -0
  26. package/plugins/huaweicloud-core/dist/agents/codex.js +205 -0
  27. package/plugins/huaweicloud-core/dist/agents/dsh-patch.js +172 -0
  28. package/plugins/huaweicloud-core/dist/agents/dsh.js +129 -0
  29. package/plugins/huaweicloud-core/dist/agents/hermes-config.js +976 -0
  30. package/plugins/huaweicloud-core/dist/agents/hermes-hook-plugin.js +90 -0
  31. package/plugins/huaweicloud-core/dist/agents/hermes-hooks.js +166 -0
  32. package/plugins/huaweicloud-core/dist/agents/hermes-sdk.js +58 -0
  33. package/plugins/huaweicloud-core/dist/agents/hermes.js +150 -0
  34. package/plugins/huaweicloud-core/dist/agents/officeace-registry.js +179 -0
  35. package/plugins/huaweicloud-core/dist/agents/officeace-sqlite.js +132 -0
  36. package/plugins/huaweicloud-core/dist/agents/officeace.js +173 -0
  37. package/plugins/huaweicloud-core/dist/agents/openclaw.js +54 -0
  38. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +188 -0
  39. package/plugins/huaweicloud-core/dist/agents/opencode.js +112 -0
  40. package/plugins/huaweicloud-core/dist/agents/workbuddy.js +194 -0
  41. package/plugins/huaweicloud-core/dist/auth/account-type.js +136 -0
  42. package/plugins/huaweicloud-core/dist/auth/agent-registration.js +243 -0
  43. package/plugins/huaweicloud-core/dist/auth/cli.js +114 -0
  44. package/plugins/huaweicloud-core/dist/auth/codearts-context.js +131 -0
  45. package/plugins/huaweicloud-core/dist/auth/credential-placeholder.js +41 -0
  46. package/plugins/huaweicloud-core/dist/auth/credential-resolver.js +74 -0
  47. package/plugins/huaweicloud-core/dist/auth/credential-validator.js +139 -0
  48. package/plugins/huaweicloud-core/dist/auth/credentials.js +20 -0
  49. package/plugins/huaweicloud-core/dist/auth/error-table.js +123 -0
  50. package/plugins/huaweicloud-core/dist/auth/hcloud-profile.js +89 -0
  51. package/plugins/huaweicloud-core/dist/auth/init-cli.js +139 -0
  52. package/plugins/huaweicloud-core/dist/auth/missing-credential-error.js +33 -0
  53. package/plugins/huaweicloud-core/dist/auth/obs-config.js +31 -0
  54. package/plugins/huaweicloud-core/dist/auth/project-id.js +90 -0
  55. package/plugins/huaweicloud-core/dist/auth/reconcile.js +256 -0
  56. package/plugins/huaweicloud-core/dist/auth/runtime-credentials.js +32 -0
  57. package/plugins/huaweicloud-core/dist/auth/s1-store.js +171 -0
  58. package/plugins/huaweicloud-core/dist/auth/service.js +397 -0
  59. package/plugins/huaweicloud-core/dist/auth/sts-expiry.js +58 -0
  60. package/plugins/huaweicloud-core/dist/capability-catalog.js +494 -0
  61. package/plugins/huaweicloud-core/dist/codearts-sandbox.js +32 -0
  62. package/plugins/huaweicloud-core/dist/codex-probe.js +77 -0
  63. package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +3517 -0
  64. package/plugins/huaweicloud-core/dist/dep/installers/gateway.js +186 -0
  65. package/plugins/huaweicloud-core/dist/dep/installers/hcloud.js +370 -0
  66. package/plugins/huaweicloud-core/dist/dep/installers/table.js +28 -0
  67. package/plugins/huaweicloud-core/dist/dep/provision.js +247 -0
  68. package/plugins/huaweicloud-core/dist/dep/receipts.js +385 -0
  69. package/plugins/huaweicloud-core/dist/detect-framework-match.js +111 -0
  70. package/plugins/huaweicloud-core/dist/detect-framework-pkg.js +85 -0
  71. package/plugins/huaweicloud-core/dist/detect-framework-scan.js +93 -0
  72. package/plugins/huaweicloud-core/dist/detect-framework-table.js +153 -0
  73. package/plugins/huaweicloud-core/dist/detect-framework.js +7 -0
  74. package/plugins/huaweicloud-core/dist/doctor-native.js +167 -0
  75. package/plugins/huaweicloud-core/dist/doctor-payload.js +34 -0
  76. package/plugins/huaweicloud-core/dist/doctor-report.js +8 -0
  77. package/plugins/huaweicloud-core/dist/explain-error.js +209 -0
  78. package/plugins/huaweicloud-core/dist/hcloud-api-error.js +64 -0
  79. package/plugins/huaweicloud-core/dist/hcloud-catalog.js +91 -0
  80. package/plugins/huaweicloud-core/dist/hcloud-cli.js +24 -0
  81. package/plugins/huaweicloud-core/dist/hcloud-obs-redact.js +68 -0
  82. package/plugins/huaweicloud-core/dist/hcloud-plan.js +298 -0
  83. package/plugins/huaweicloud-core/dist/hcloud-probe.js +153 -0
  84. package/plugins/huaweicloud-core/dist/hcloud-run-once.js +245 -0
  85. package/plugins/huaweicloud-core/dist/hcloud-run.js +107 -0
  86. package/plugins/huaweicloud-core/dist/hcloud-sg-preflight.js +104 -0
  87. package/plugins/huaweicloud-core/dist/hcloud-sts.js +113 -0
  88. package/plugins/huaweicloud-core/dist/hcloud-triage.js +71 -0
  89. package/plugins/huaweicloud-core/dist/icon-library.js +216 -0
  90. package/plugins/huaweicloud-core/dist/install-payload.js +35 -0
  91. package/plugins/huaweicloud-core/dist/install-plan.js +85 -0
  92. package/plugins/huaweicloud-core/dist/install-prompts.js +119 -0
  93. package/plugins/huaweicloud-core/dist/koocli-version.js +83 -0
  94. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +234 -0
  95. package/plugins/huaweicloud-core/dist/lib/as-record.js +10 -0
  96. package/plugins/huaweicloud-core/dist/lib/as-text.js +15 -0
  97. package/plugins/huaweicloud-core/dist/lib/banner.js +10 -0
  98. package/plugins/huaweicloud-core/dist/lib/call-trace.js +128 -0
  99. package/plugins/huaweicloud-core/dist/lib/cli-io.js +72 -0
  100. package/plugins/huaweicloud-core/dist/lib/credentials.js +173 -0
  101. package/plugins/huaweicloud-core/dist/lib/dep-resolve.js +64 -0
  102. package/plugins/huaweicloud-core/dist/lib/dependency-model.js +152 -0
  103. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +217 -0
  104. package/plugins/huaweicloud-core/dist/lib/hdkit/hwlink-api.js +163 -0
  105. package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +303 -0
  106. package/plugins/huaweicloud-core/dist/lib/hw-request-signing.js +57 -0
  107. package/plugins/huaweicloud-core/dist/lib/koocli-paths.js +18 -0
  108. package/plugins/huaweicloud-core/dist/lib/native-receipt.js +110 -0
  109. package/plugins/huaweicloud-core/dist/lib/opencode-permission-seam.js +132 -0
  110. package/plugins/huaweicloud-core/dist/lib/pack-state.js +179 -0
  111. package/plugins/huaweicloud-core/dist/lib/pack-types.js +21 -0
  112. package/plugins/huaweicloud-core/dist/lib/secret-vault/cli.js +273 -0
  113. package/plugins/huaweicloud-core/dist/lib/secret-vault/custody.js +396 -0
  114. package/plugins/huaweicloud-core/dist/lib/secret-vault/refs.js +63 -0
  115. package/plugins/huaweicloud-core/dist/lib/secret-vault/store.js +236 -0
  116. package/plugins/huaweicloud-core/dist/lib/skill-frontmatter.js +158 -0
  117. package/plugins/huaweicloud-core/dist/lib/skill-manifest.js +55 -0
  118. package/plugins/huaweicloud-core/dist/lib/skill-tree.js +44 -0
  119. package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +66 -0
  120. package/plugins/huaweicloud-core/dist/mcp-agent-config.js +80 -0
  121. package/plugins/huaweicloud-core/dist/mcp-config-backup.js +74 -0
  122. package/plugins/huaweicloud-core/dist/mcp-config-io.js +195 -0
  123. package/plugins/huaweicloud-core/dist/mcp-config-merge.js +188 -0
  124. package/plugins/huaweicloud-core/dist/mcp-protocol.js +320 -0
  125. package/plugins/huaweicloud-core/dist/mcp-server.js +62136 -0
  126. package/plugins/huaweicloud-core/dist/mcp-server.js.map +7 -0
  127. package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +206 -0
  128. package/plugins/huaweicloud-core/dist/officeace-paths.js +142 -0
  129. package/plugins/huaweicloud-core/dist/packs/auth/pack.js +11 -0
  130. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +276 -0
  131. package/plugins/huaweicloud-core/dist/packs/discovery/pack.js +11 -0
  132. package/plugins/huaweicloud-core/dist/packs/discovery/tools.js +78 -0
  133. package/plugins/huaweicloud-core/dist/packs/enable.js +81 -0
  134. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/pack.js +39 -0
  135. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +435 -0
  136. package/plugins/huaweicloud-core/dist/packs/huaweicloud-open-mcp/approval.js +222 -0
  137. package/plugins/huaweicloud-core/dist/packs/huaweicloud-open-mcp/pack.js +17 -0
  138. package/plugins/huaweicloud-core/dist/packs/huaweicloud-open-mcp/sidecar.js +486 -0
  139. package/plugins/huaweicloud-core/dist/packs/huaweicloud-open-mcp/tools.js +134 -0
  140. package/plugins/huaweicloud-core/dist/packs/obs/pack.js +11 -0
  141. package/plugins/huaweicloud-core/dist/packs/obs/tools.js +425 -0
  142. package/plugins/huaweicloud-core/dist/packs/registry.js +143 -0
  143. package/plugins/huaweicloud-core/dist/packs/sandbox/git-transfer.js +79 -0
  144. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +80 -0
  145. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +138 -0
  146. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-deploy.js +45 -0
  147. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +48 -0
  148. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +59 -0
  149. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-upload.js +34 -0
  150. package/plugins/huaweicloud-core/dist/packs/sandbox/pack.js +14 -0
  151. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +191 -0
  152. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +146 -0
  153. package/plugins/huaweicloud-core/dist/packs/secrets/pack.js +8 -0
  154. package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +126 -0
  155. package/plugins/huaweicloud-core/dist/packs/update/pack.js +11 -0
  156. package/plugins/huaweicloud-core/dist/packs/update/tools.js +82 -0
  157. package/plugins/huaweicloud-core/dist/packs/voucher/pack.js +11 -0
  158. package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +91 -0
  159. package/plugins/huaweicloud-core/dist/packs-cli/commands.js +108 -0
  160. package/plugins/huaweicloud-core/dist/packs-cli/doctor.js +81 -0
  161. package/plugins/huaweicloud-core/dist/packs-cli/report.js +133 -0
  162. package/plugins/huaweicloud-core/dist/packs-cli/slots.js +104 -0
  163. package/plugins/huaweicloud-core/dist/packs-cli/write-command.js +108 -0
  164. package/plugins/huaweicloud-core/dist/packs-cli/writers.js +115 -0
  165. package/plugins/huaweicloud-core/dist/packs-configure.js +81 -0
  166. package/plugins/huaweicloud-core/dist/packs-policy.js +149 -0
  167. package/plugins/huaweicloud-core/dist/payload-files.js +78 -0
  168. package/plugins/huaweicloud-core/dist/payload-native-clean.js +142 -0
  169. package/plugins/huaweicloud-core/dist/payload-native-sync.js +89 -0
  170. package/plugins/huaweicloud-core/dist/payload-placement.js +94 -0
  171. package/plugins/huaweicloud-core/dist/payload-roster.js +80 -0
  172. package/plugins/huaweicloud-core/dist/payload-runtime-deps.js +67 -0
  173. package/plugins/huaweicloud-core/dist/payload-status.js +43 -0
  174. package/plugins/huaweicloud-core/dist/payload-utils.js +42 -0
  175. package/plugins/huaweicloud-core/dist/preflight.js +232 -0
  176. package/plugins/huaweicloud-core/dist/proxy/cli.js +83 -0
  177. package/plugins/huaweicloud-core/dist/proxy/proxy-agent.js +92 -0
  178. package/plugins/huaweicloud-core/dist/proxy/proxy-bypass.js +83 -0
  179. package/plugins/huaweicloud-core/dist/proxy/proxy-cidr.js +105 -0
  180. package/plugins/huaweicloud-core/dist/proxy/proxy-config-io.js +61 -0
  181. package/plugins/huaweicloud-core/dist/proxy/proxy-config.js +10 -0
  182. package/plugins/huaweicloud-core/dist/risk-rule-engine.js +229 -0
  183. package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +191 -0
  184. package/plugins/huaweicloud-core/dist/safety/classify-text.js +1032 -0
  185. package/plugins/huaweicloud-core/dist/safety/command-operation.js +25 -0
  186. package/plugins/huaweicloud-core/dist/safety/credential-path.js +23 -0
  187. package/plugins/huaweicloud-core/dist/safety/default-policy.js +28 -0
  188. package/plugins/huaweicloud-core/dist/safety/feeder.js +119 -0
  189. package/plugins/huaweicloud-core/dist/safety/heredoc.js +95 -0
  190. package/plugins/huaweicloud-core/dist/safety/policy.js +75 -0
  191. package/plugins/huaweicloud-core/dist/safety/redact.js +42 -0
  192. package/plugins/huaweicloud-core/dist/safety/risk-merge.js +22 -0
  193. package/plugins/huaweicloud-core/dist/safety/script-stream.js +90 -0
  194. package/plugins/huaweicloud-core/dist/safety/secret-exec.js +44 -0
  195. package/plugins/huaweicloud-core/dist/safety/segments.js +138 -0
  196. package/plugins/huaweicloud-core/dist/safety/shell-text.js +414 -0
  197. package/plugins/huaweicloud-core/dist/safety/skill-quality-cli.js +152 -0
  198. package/plugins/huaweicloud-core/dist/safety/tokens.js +297 -0
  199. package/plugins/huaweicloud-core/dist/safety/unwrap.js +148 -0
  200. package/plugins/huaweicloud-core/dist/safety/vocabulary.js +37 -0
  201. package/plugins/huaweicloud-core/dist/safety/windows-rebase.js +56 -0
  202. package/plugins/huaweicloud-core/dist/safety/windows.js +137 -0
  203. package/plugins/huaweicloud-core/dist/safety/xargs-argv.js +64 -0
  204. package/plugins/huaweicloud-core/dist/safety-policy.js +14 -0
  205. package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +246 -0
  206. package/plugins/huaweicloud-core/dist/sandbox/deploy-nginx-verify.js +76 -0
  207. package/plugins/huaweicloud-core/dist/sandbox/deploy-nginx.js +215 -0
  208. package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +246 -0
  209. package/plugins/huaweicloud-core/dist/sandbox/devbridge-exec.js +10 -0
  210. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +225 -0
  211. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +214 -0
  212. package/plugins/huaweicloud-core/dist/sandbox/devbridge-gateway.js +34 -0
  213. package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +212 -0
  214. package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +175 -0
  215. package/plugins/huaweicloud-core/dist/sandbox/devbridge-renew.js +69 -0
  216. package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +48 -0
  217. package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +79 -0
  218. package/plugins/huaweicloud-core/dist/sandbox/devbridge-verify.js +101 -0
  219. package/plugins/huaweicloud-core/dist/sandbox/hwlink-connection.js +145 -0
  220. package/plugins/huaweicloud-core/dist/sandbox/sandbox-file-server.py +45 -0
  221. package/plugins/huaweicloud-core/dist/sandbox/sandbox-output.js +45 -0
  222. package/plugins/huaweicloud-core/dist/sandbox/session-manager.js +55 -0
  223. package/plugins/huaweicloud-core/dist/sandbox/tunnel-http.js +137 -0
  224. package/plugins/huaweicloud-core/dist/sandbox/uninstall-cleanup.js +45 -0
  225. package/plugins/huaweicloud-core/dist/sandbox/upload-diagnostics.js +45 -0
  226. package/plugins/huaweicloud-core/dist/sandbox/upload-file.js +119 -0
  227. package/plugins/huaweicloud-core/dist/sandbox/upload-project.js +171 -0
  228. package/plugins/huaweicloud-core/dist/sandbox/upload-transport.js +96 -0
  229. package/plugins/huaweicloud-core/dist/sandbox/ws-exec-loader.js +43 -0
  230. package/plugins/huaweicloud-core/dist/search-docs.js +64 -0
  231. package/plugins/huaweicloud-core/dist/search-market.js +277 -0
  232. package/plugins/huaweicloud-core/dist/services/availability.js +51 -0
  233. package/plugins/huaweicloud-core/dist/services/regions.js +110 -0
  234. package/plugins/huaweicloud-core/dist/setup-cli.js +1343 -0
  235. package/plugins/huaweicloud-core/dist/skill-disclosure.js +231 -0
  236. package/plugins/huaweicloud-core/dist/targets.js +139 -0
  237. package/plugins/huaweicloud-core/dist/telemetry/agent-detect.js +44 -0
  238. package/plugins/huaweicloud-core/dist/telemetry/agent-registry.js +196 -0
  239. package/plugins/huaweicloud-core/dist/telemetry/agent-versions-desktop.js +143 -0
  240. package/plugins/huaweicloud-core/dist/telemetry/agent-versions.js +78 -0
  241. package/plugins/huaweicloud-core/dist/telemetry/event-pipeline.js +206 -0
  242. package/plugins/huaweicloud-core/dist/telemetry/hook-ingest.js +81 -0
  243. package/plugins/huaweicloud-core/dist/telemetry/identity-stamps.js +104 -0
  244. package/plugins/huaweicloud-core/dist/telemetry/invoke-value.js +47 -0
  245. package/plugins/huaweicloud-core/dist/telemetry/telemetry-fs.js +42 -0
  246. package/plugins/huaweicloud-core/dist/telemetry/telemetry-types.js +14 -0
  247. package/plugins/huaweicloud-core/dist/telemetry/telemetry-values.js +121 -0
  248. package/plugins/huaweicloud-core/dist/telemetry/telemetry.js +262 -0
  249. package/plugins/huaweicloud-core/dist/tool-definitions.js +276 -0
  250. package/plugins/huaweicloud-core/dist/tool-schemas.js +156 -0
  251. package/plugins/huaweicloud-core/dist/tools.js +269 -0
  252. package/plugins/huaweicloud-core/dist/update-cache.js +79 -0
  253. package/plugins/huaweicloud-core/dist/update-check.js +23 -0
  254. package/plugins/huaweicloud-core/dist/update-hint.js +45 -0
  255. package/plugins/huaweicloud-core/dist/update-installed.js +53 -0
  256. package/plugins/huaweicloud-core/dist/update-registry.js +141 -0
  257. package/plugins/huaweicloud-core/dist/update-semver.js +76 -0
  258. package/plugins/huaweicloud-core/dist/update-skip.js +81 -0
  259. package/plugins/huaweicloud-core/dist/update-upgrade.js +94 -0
  260. package/plugins/huaweicloud-core/dist/vendor-gate.js +89 -0
  261. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-exec-client.js +10 -0
  262. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-exec-pending.js +71 -0
  263. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-exec-session.js +235 -0
  264. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-fair-queue.js +139 -0
  265. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-interactive-terminal.js +106 -0
  266. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-multiplexer.js +229 -0
  267. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-normalize.js +53 -0
  268. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-packet.js +148 -0
  269. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-terminal-channel.js +155 -0
  270. package/plugins/huaweicloud-core/dist/ws-exec/hwlink-tunnel-channel.js +254 -0
  271. package/plugins/huaweicloud-core/dist/ws-exec/index.js +20 -0
  272. package/plugins/huaweicloud-core/dist/ws-exec/ws-exec-client.js +76 -0
  273. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +62 -3
  274. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +2500 -33
  275. package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
  276. package/plugins/huaweicloud-core/safety/policy.json +45 -4
  277. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +47 -9
  278. package/plugins/huaweicloud-core/skills/.manifest.json +67 -0
  279. package/plugins/huaweicloud-core/skills/huawei-billing/SKILL.md +2 -0
  280. package/plugins/huaweicloud-core/skills/huawei-cbr/SKILL.md +2 -0
  281. package/plugins/huaweicloud-core/skills/huawei-cce/SKILL.md +3 -1
  282. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/SKILL.md +27 -51
  283. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/references/acceptance-criteria.md +10 -12
  284. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/references/cli-installation-guide.md +23 -27
  285. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/references/dataflow-diagram.md +2 -0
  286. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/references/iam-policies.md +2 -0
  287. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/references/verification-method.md +8 -16
  288. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/scripts/cli/cli_entry.py +71 -461
  289. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/scripts/ensure_cli.sh +28 -68
  290. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/SKILL.md +56 -144
  291. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/references/acceptance-criteria.md +14 -12
  292. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/references/cli-installation-guide.md +72 -39
  293. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/references/dataflow-diagram.md +3 -1
  294. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/references/iam-policies.md +2 -0
  295. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/references/verification-method.md +12 -0
  296. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/scripts/cli/cli_entry.py +67 -307
  297. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/scripts/ensure_cli.sh +28 -68
  298. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/templates/test-defaults.json +1 -1
  299. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/templates/test-vars.json +9 -9
  300. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/SKILL.md +82 -160
  301. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/references/acceptance-criteria.md +9 -8
  302. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/references/cli-installation-guide.md +73 -40
  303. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/references/dataflow-diagram.md +4 -2
  304. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/references/iam-policies.md +2 -0
  305. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/references/related-commands.md +16 -14
  306. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/references/verification-method.md +7 -20
  307. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/scripts/cli/cli_entry.py +67 -307
  308. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/scripts/ensure_cli.sh +28 -68
  309. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/SKILL.md +92 -95
  310. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/acceptance-criteria.md +11 -10
  311. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/cli-installation-guide.md +86 -67
  312. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/dataflow-diagram.md +4 -2
  313. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/iam-policies.md +2 -0
  314. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/test-data-guide.md +29 -25
  315. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/verification-method.md +13 -11
  316. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/scripts/cli/cli_entry.py +67 -307
  317. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/scripts/ensure_cli.sh +28 -68
  318. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/SKILL.md +107 -127
  319. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/acceptance-criteria.md +26 -25
  320. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/cli-installation-guide.md +66 -51
  321. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/csms-usage.md +23 -19
  322. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/dataflow-diagram.md +4 -2
  323. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/iam-policies.md +25 -30
  324. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/kms-usage.md +13 -11
  325. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/references/verification-method.md +13 -7
  326. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/scripts/cli/cli_entry.py +67 -354
  327. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/scripts/ensure_cli.sh +28 -69
  328. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/templates/test-vars.json +11 -11
  329. package/plugins/huaweicloud-core/skills/huawei-cloud-eye/SKILL.md +2 -0
  330. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/SKILL.md +28 -109
  331. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/references/acceptance-criteria.md +27 -31
  332. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/references/cli-installation-guide.md +49 -24
  333. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/references/dataflow-diagram.md +2 -5
  334. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/references/iam-policies.md +2 -0
  335. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/references/verification-method.md +8 -25
  336. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/scripts/cli/cli_entry.py +67 -307
  337. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/scripts/ensure_cli.sh +28 -68
  338. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/SKILL.md +60 -135
  339. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/acceptance-criteria.md +9 -11
  340. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/cli-installation-guide.md +16 -12
  341. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/dataflow-diagram.md +2 -0
  342. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/engine-operation-reference.md +15 -13
  343. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/iam-policies.md +9 -7
  344. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/security-audit-guide.md +9 -5
  345. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/references/verification-method.md +16 -37
  346. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/scripts/cli/cli_entry.py +101 -0
  347. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/scripts/ensure_cli.sh +27 -184
  348. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/SKILL.md +71 -103
  349. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/references/acceptance-criteria.md +4 -2
  350. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/references/cli-installation-guide.md +72 -84
  351. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/references/dataflow-diagram.md +3 -3
  352. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/references/iam-policies.md +2 -0
  353. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/references/related-commands.md +7 -5
  354. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/references/verification-method.md +11 -9
  355. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/scripts/cli/cli_entry.py +101 -0
  356. package/plugins/huaweicloud-core/skills/huawei-cloud-waf-aad-rule-management/scripts/ensure_cli.sh +27 -42
  357. package/plugins/huaweicloud-core/skills/huawei-ecs/SKILL.md +2 -0
  358. package/plugins/huaweicloud-core/skills/huawei-ecs/references/create-instance.md +24 -13
  359. package/plugins/huaweicloud-core/skills/huawei-ecs/references/evs.md +2 -0
  360. package/plugins/huaweicloud-core/skills/huawei-ecs/references/flavors.md +2 -0
  361. package/plugins/huaweicloud-core/skills/huawei-ecs/references/hc-activity.md +2 -0
  362. package/plugins/huaweicloud-core/skills/huawei-ecs/references/troubleshooting.md +25 -21
  363. package/plugins/huaweicloud-core/skills/huawei-ecs/references/windows-ssh.md +7 -5
  364. package/plugins/huaweicloud-core/skills/huawei-functiongraph/SKILL.md +2 -0
  365. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/apig-event-format.md +2 -0
  366. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/create-function.md +2 -0
  367. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/deploy-workflow.md +2 -0
  368. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/triggers.md +2 -0
  369. package/plugins/huaweicloud-core/skills/huawei-getting-started/SKILL.md +2 -0
  370. package/plugins/huaweicloud-core/skills/huawei-iac/SKILL.md +40 -38
  371. package/plugins/huaweicloud-core/skills/huawei-iac/references/architectures.md +2 -0
  372. package/plugins/huaweicloud-core/skills/huawei-iac/references/resource-catalog.md +14 -12
  373. package/plugins/huaweicloud-core/skills/huawei-iac/references/state-file.md +2 -0
  374. package/plugins/huaweicloud-core/skills/huawei-iam/SKILL.md +3 -1
  375. package/plugins/huaweicloud-core/skills/huawei-iam/references/policy-examples.md +2 -0
  376. package/plugins/huaweicloud-core/skills/huawei-iam/references/quick-ref.md +4 -1
  377. package/plugins/huaweicloud-core/skills/huawei-modelarts/SKILL.md +2 -0
  378. package/plugins/huaweicloud-core/skills/huawei-obs/SKILL.md +32 -29
  379. package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-create.md +2 -0
  380. package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-lifecycle.md +4 -2
  381. package/plugins/huaweicloud-core/skills/huawei-obs/references/common-pitfalls.md +17 -15
  382. package/plugins/huaweicloud-core/skills/huawei-obs/references/single-file-share.md +2 -0
  383. package/plugins/huaweicloud-core/skills/huawei-obs/references/static-website.md +10 -6
  384. package/plugins/huaweicloud-core/skills/huawei-openapi/SKILL.md +50 -0
  385. package/plugins/huaweicloud-core/skills/huawei-rds/SKILL.md +15 -13
  386. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +98 -91
  387. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/framework-commands.md +2 -0
  388. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/fullstack-postgrest.md +33 -27
  389. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/nginx-templates.md +2 -0
  390. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +3 -1
  391. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/tunnel-persistence.md +9 -2
  392. package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +5 -3
  393. package/plugins/huaweicloud-core/skills/huawei-vpc/SKILL.md +3 -0
  394. package/plugins/huaweicloud-core/skills/huawei-vpc/references/network.md +16 -0
  395. package/plugins/huaweicloud-core/skills/huawei-vpc/references/security-group.md +2 -0
  396. package/plugins/huaweicloud-core/skills/huawei-vpc/references/subnet.md +2 -0
  397. package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/SKILL.md +3 -0
  398. package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/SKILL.md +16 -13
  399. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +6 -11
  400. package/plugins/huaweicloud-core/skills/huaweicloud-core/SKILL.md +38 -35
  401. package/plugins/huaweicloud-core/skills/huaweicloud-core/references/report-issue.md +2 -0
  402. package/plugins/huaweicloud-core/skills/huaweicloud-core/references/select.md +2 -0
  403. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +3 -0
  404. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/secrets.md +32 -0
  405. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +2 -0
  406. package/plugins/huaweicloud-core/src/agents/atomcode.ts +138 -0
  407. package/plugins/huaweicloud-core/src/agents/codearts-work.ts +136 -0
  408. package/plugins/huaweicloud-core/src/agents/codearts.ts +92 -0
  409. package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +219 -0
  410. package/plugins/huaweicloud-core/src/agents/codex.ts +230 -0
  411. package/plugins/huaweicloud-core/src/agents/dsh-patch.ts +195 -0
  412. package/plugins/huaweicloud-core/src/agents/dsh.ts +153 -0
  413. package/plugins/huaweicloud-core/src/agents/hermes-config.ts +974 -0
  414. package/plugins/huaweicloud-core/src/agents/hermes-hook-plugin.ts +99 -0
  415. package/plugins/huaweicloud-core/src/agents/hermes-hooks.ts +187 -0
  416. package/plugins/huaweicloud-core/src/agents/hermes-sdk.ts +63 -0
  417. package/plugins/huaweicloud-core/src/agents/hermes.ts +192 -0
  418. package/plugins/huaweicloud-core/src/agents/officeace-registry.ts +188 -0
  419. package/plugins/huaweicloud-core/src/agents/officeace-sqlite.ts +153 -0
  420. package/plugins/huaweicloud-core/src/agents/officeace.ts +202 -0
  421. package/plugins/huaweicloud-core/src/agents/openclaw.ts +73 -0
  422. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +193 -0
  423. package/plugins/huaweicloud-core/src/agents/opencode.ts +148 -0
  424. package/plugins/huaweicloud-core/src/agents/workbuddy.ts +216 -0
  425. package/plugins/huaweicloud-core/src/auth/account-type.ts +191 -0
  426. package/plugins/huaweicloud-core/src/auth/agent-registration.ts +267 -0
  427. package/plugins/huaweicloud-core/src/auth/cli.ts +133 -0
  428. package/plugins/huaweicloud-core/src/auth/codearts-context.ts +139 -0
  429. package/plugins/huaweicloud-core/src/auth/credential-placeholder.ts +36 -0
  430. package/plugins/huaweicloud-core/src/auth/credential-resolver.ts +81 -0
  431. package/plugins/huaweicloud-core/src/auth/credential-validator.ts +176 -0
  432. package/plugins/huaweicloud-core/src/auth/credentials.ts +52 -0
  433. package/plugins/huaweicloud-core/src/auth/{guidance.mjs → error-table.ts} +58 -12
  434. package/plugins/huaweicloud-core/src/auth/hcloud-profile.ts +119 -0
  435. package/plugins/huaweicloud-core/src/auth/init-cli.ts +155 -0
  436. package/plugins/huaweicloud-core/src/auth/missing-credential-error.ts +44 -0
  437. package/plugins/huaweicloud-core/src/auth/obs-config.ts +42 -0
  438. package/plugins/huaweicloud-core/src/auth/project-id.ts +104 -0
  439. package/plugins/huaweicloud-core/src/auth/reconcile.ts +345 -0
  440. package/plugins/huaweicloud-core/src/auth/runtime-credentials.ts +38 -0
  441. package/plugins/huaweicloud-core/src/auth/s1-store.ts +214 -0
  442. package/plugins/huaweicloud-core/src/auth/{service.mjs → service.ts} +210 -36
  443. package/plugins/huaweicloud-core/src/auth/sts-expiry.ts +58 -0
  444. package/plugins/huaweicloud-core/src/capability-catalog.ts +519 -0
  445. package/plugins/huaweicloud-core/src/codearts-sandbox.ts +32 -0
  446. package/plugins/huaweicloud-core/src/codex-probe.ts +86 -0
  447. package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +5 -23
  448. package/plugins/huaweicloud-core/src/dep/installers/gateway.ts +213 -0
  449. package/plugins/huaweicloud-core/src/dep/installers/hcloud.ts +407 -0
  450. package/plugins/huaweicloud-core/src/dep/installers/table.ts +123 -0
  451. package/plugins/huaweicloud-core/src/dep/provision.ts +335 -0
  452. package/plugins/huaweicloud-core/src/dep/receipts.ts +464 -0
  453. package/plugins/huaweicloud-core/src/detect-framework-match.ts +143 -0
  454. package/plugins/huaweicloud-core/src/detect-framework-pkg.ts +79 -0
  455. package/plugins/huaweicloud-core/src/detect-framework-scan.ts +117 -0
  456. package/plugins/huaweicloud-core/src/detect-framework-table.ts +166 -0
  457. package/plugins/huaweicloud-core/src/detect-framework.ts +8 -0
  458. package/plugins/huaweicloud-core/src/doctor-native.ts +189 -0
  459. package/plugins/huaweicloud-core/src/doctor-payload.ts +77 -0
  460. package/plugins/huaweicloud-core/src/doctor-report.ts +30 -0
  461. package/plugins/huaweicloud-core/src/explain-error.ts +246 -0
  462. package/plugins/huaweicloud-core/src/hcloud-api-error.ts +69 -0
  463. package/plugins/huaweicloud-core/src/hcloud-catalog.ts +115 -0
  464. package/plugins/huaweicloud-core/src/hcloud-cli.ts +41 -0
  465. package/plugins/huaweicloud-core/src/hcloud-obs-redact.ts +65 -0
  466. package/plugins/huaweicloud-core/src/hcloud-plan.ts +344 -0
  467. package/plugins/huaweicloud-core/src/{hcloud-probe.mjs → hcloud-probe.ts} +87 -60
  468. package/plugins/huaweicloud-core/src/hcloud-run-once.ts +251 -0
  469. package/plugins/huaweicloud-core/src/hcloud-run.ts +151 -0
  470. package/plugins/huaweicloud-core/src/hcloud-sg-preflight.ts +111 -0
  471. package/plugins/huaweicloud-core/src/hcloud-sts.ts +123 -0
  472. package/plugins/huaweicloud-core/src/hcloud-triage.ts +80 -0
  473. package/plugins/huaweicloud-core/src/{icon-library.mjs → icon-library.ts} +115 -23
  474. package/plugins/huaweicloud-core/src/install-payload.ts +63 -0
  475. package/plugins/huaweicloud-core/src/install-plan.ts +85 -0
  476. package/plugins/huaweicloud-core/src/install-prompts.ts +134 -0
  477. package/plugins/huaweicloud-core/src/koocli-version.ts +87 -0
  478. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +315 -0
  479. package/plugins/huaweicloud-core/src/lib/as-record.ts +10 -0
  480. package/plugins/huaweicloud-core/src/lib/as-text.ts +16 -0
  481. package/plugins/huaweicloud-core/src/lib/banner.ts +12 -0
  482. package/plugins/huaweicloud-core/src/lib/call-trace.ts +153 -0
  483. package/plugins/huaweicloud-core/src/lib/cli-io.ts +81 -0
  484. package/plugins/huaweicloud-core/src/lib/credentials.ts +202 -0
  485. package/plugins/huaweicloud-core/src/lib/dep-resolve.ts +107 -0
  486. package/plugins/huaweicloud-core/src/lib/dependency-model.ts +236 -0
  487. package/plugins/huaweicloud-core/src/{sandbox/hdkitservice-api.mjs → lib/hdkit/hdkitservice-api.ts} +99 -118
  488. package/plugins/huaweicloud-core/src/lib/hdkit/hwlink-api.ts +245 -0
  489. package/plugins/huaweicloud-core/src/{sandbox/sandbox-pool.mjs → lib/hdkit/sandbox-pool.ts} +115 -47
  490. package/plugins/huaweicloud-core/src/lib/hw-request-signing.ts +101 -0
  491. package/plugins/huaweicloud-core/src/lib/koocli-paths.ts +21 -0
  492. package/plugins/huaweicloud-core/src/lib/native-receipt.ts +131 -0
  493. package/plugins/huaweicloud-core/src/lib/opencode-permission-seam.ts +145 -0
  494. package/plugins/huaweicloud-core/src/lib/pack-state.ts +192 -0
  495. package/plugins/huaweicloud-core/src/lib/pack-types.ts +74 -0
  496. package/plugins/huaweicloud-core/src/lib/secret-vault/cli.ts +270 -0
  497. package/plugins/huaweicloud-core/src/lib/secret-vault/custody.ts +468 -0
  498. package/plugins/huaweicloud-core/src/lib/secret-vault/refs.ts +75 -0
  499. package/plugins/huaweicloud-core/src/lib/secret-vault/store.ts +357 -0
  500. package/plugins/huaweicloud-core/src/lib/skill-frontmatter.ts +164 -0
  501. package/plugins/huaweicloud-core/src/lib/skill-manifest.ts +55 -0
  502. package/plugins/huaweicloud-core/src/lib/skill-tree.ts +45 -0
  503. package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +80 -0
  504. package/plugins/huaweicloud-core/src/mcp-agent-config.ts +90 -0
  505. package/plugins/huaweicloud-core/src/{mcp-config-backup.mjs → mcp-config-backup.ts} +14 -10
  506. package/plugins/huaweicloud-core/src/mcp-config-io.ts +215 -0
  507. package/plugins/huaweicloud-core/src/mcp-config-merge.ts +205 -0
  508. package/plugins/huaweicloud-core/src/mcp-protocol.ts +385 -0
  509. package/plugins/huaweicloud-core/src/mcp-server-remote.ts +178 -0
  510. package/plugins/huaweicloud-core/src/mcp-server.ts +87 -0
  511. package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +245 -0
  512. package/plugins/huaweicloud-core/src/officeace-paths.ts +146 -0
  513. package/plugins/huaweicloud-core/src/packs/auth/pack.ts +14 -0
  514. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +327 -0
  515. package/plugins/huaweicloud-core/src/packs/discovery/pack.ts +14 -0
  516. package/plugins/huaweicloud-core/src/packs/discovery/tools.ts +97 -0
  517. package/plugins/huaweicloud-core/src/packs/enable.ts +90 -0
  518. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/pack.ts +42 -0
  519. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +493 -0
  520. package/plugins/huaweicloud-core/src/packs/huaweicloud-open-mcp/approval.ts +250 -0
  521. package/plugins/huaweicloud-core/src/packs/huaweicloud-open-mcp/pack.ts +19 -0
  522. package/plugins/huaweicloud-core/src/packs/huaweicloud-open-mcp/sidecar.ts +603 -0
  523. package/plugins/huaweicloud-core/src/packs/huaweicloud-open-mcp/tools.ts +155 -0
  524. package/plugins/huaweicloud-core/src/packs/obs/pack.ts +13 -0
  525. package/plugins/huaweicloud-core/src/packs/obs/tools.ts +487 -0
  526. package/plugins/huaweicloud-core/src/packs/registry.ts +162 -0
  527. package/plugins/huaweicloud-core/src/packs/sandbox/git-transfer.ts +93 -0
  528. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +93 -0
  529. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +144 -0
  530. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-deploy.ts +63 -0
  531. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +59 -0
  532. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +101 -0
  533. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-upload.ts +46 -0
  534. package/plugins/huaweicloud-core/src/packs/sandbox/pack.ts +16 -0
  535. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +249 -0
  536. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +183 -0
  537. package/plugins/huaweicloud-core/src/packs/secrets/pack.ts +11 -0
  538. package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +146 -0
  539. package/plugins/huaweicloud-core/src/packs/update/pack.ts +13 -0
  540. package/plugins/huaweicloud-core/src/packs/update/tools.ts +107 -0
  541. package/plugins/huaweicloud-core/src/packs/voucher/pack.ts +13 -0
  542. package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +112 -0
  543. package/plugins/huaweicloud-core/src/packs-cli/commands.ts +121 -0
  544. package/plugins/huaweicloud-core/src/packs-cli/doctor.ts +85 -0
  545. package/plugins/huaweicloud-core/src/packs-cli/report.ts +171 -0
  546. package/plugins/huaweicloud-core/src/packs-cli/slots.ts +139 -0
  547. package/plugins/huaweicloud-core/src/packs-cli/write-command.ts +114 -0
  548. package/plugins/huaweicloud-core/src/packs-cli/writers.ts +125 -0
  549. package/plugins/huaweicloud-core/src/packs-configure.ts +104 -0
  550. package/plugins/huaweicloud-core/src/packs-policy.ts +203 -0
  551. package/plugins/huaweicloud-core/src/payload-files.ts +78 -0
  552. package/plugins/huaweicloud-core/src/payload-native-clean.ts +154 -0
  553. package/plugins/huaweicloud-core/src/payload-native-sync.ts +110 -0
  554. package/plugins/huaweicloud-core/src/payload-placement.ts +107 -0
  555. package/plugins/huaweicloud-core/src/payload-roster.ts +85 -0
  556. package/plugins/huaweicloud-core/src/payload-runtime-deps.ts +68 -0
  557. package/plugins/huaweicloud-core/src/payload-status.ts +53 -0
  558. package/plugins/huaweicloud-core/src/payload-utils.ts +51 -0
  559. package/plugins/huaweicloud-core/src/preflight.ts +250 -0
  560. package/plugins/huaweicloud-core/src/proxy/cli.ts +103 -0
  561. package/plugins/huaweicloud-core/src/proxy/{proxy-agent.mjs → proxy-agent.ts} +25 -16
  562. package/plugins/huaweicloud-core/src/proxy/proxy-bypass.ts +90 -0
  563. package/plugins/huaweicloud-core/src/proxy/proxy-cidr.ts +98 -0
  564. package/plugins/huaweicloud-core/src/proxy/proxy-config-io.ts +73 -0
  565. package/plugins/huaweicloud-core/src/proxy/proxy-config.ts +18 -0
  566. package/plugins/huaweicloud-core/src/risk-rule-engine.ts +325 -0
  567. package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +246 -0
  568. package/plugins/huaweicloud-core/src/safety/classify-text.ts +1099 -0
  569. package/plugins/huaweicloud-core/src/safety/command-operation.ts +28 -0
  570. package/plugins/huaweicloud-core/src/safety/credential-path.ts +25 -0
  571. package/plugins/huaweicloud-core/src/safety/default-policy.ts +34 -0
  572. package/plugins/huaweicloud-core/src/safety/feeder.ts +140 -0
  573. package/plugins/huaweicloud-core/src/safety/heredoc.ts +100 -0
  574. package/plugins/huaweicloud-core/src/safety/policy.ts +109 -0
  575. package/plugins/huaweicloud-core/src/safety/redact.ts +63 -0
  576. package/plugins/huaweicloud-core/src/safety/risk-merge.ts +31 -0
  577. package/plugins/huaweicloud-core/src/safety/script-stream.ts +95 -0
  578. package/plugins/huaweicloud-core/src/safety/secret-exec.ts +42 -0
  579. package/plugins/huaweicloud-core/src/safety/segments.ts +153 -0
  580. package/plugins/huaweicloud-core/src/safety/shell-text.ts +415 -0
  581. package/plugins/huaweicloud-core/src/safety/skill-quality-cli.ts +141 -0
  582. package/plugins/huaweicloud-core/src/safety/tokens.ts +322 -0
  583. package/plugins/huaweicloud-core/src/safety/unwrap.ts +162 -0
  584. package/plugins/huaweicloud-core/src/safety/vocabulary.ts +38 -0
  585. package/plugins/huaweicloud-core/src/safety/windows-rebase.ts +56 -0
  586. package/plugins/huaweicloud-core/src/safety/windows.ts +133 -0
  587. package/plugins/huaweicloud-core/src/safety/xargs-argv.ts +79 -0
  588. package/plugins/huaweicloud-core/src/safety-policy.ts +16 -0
  589. package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +307 -0
  590. package/plugins/huaweicloud-core/src/sandbox/deploy-nginx-verify.ts +96 -0
  591. package/plugins/huaweicloud-core/src/sandbox/deploy-nginx.ts +300 -0
  592. package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +291 -0
  593. package/plugins/huaweicloud-core/src/sandbox/devbridge-exec.ts +28 -0
  594. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +289 -0
  595. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +310 -0
  596. package/plugins/huaweicloud-core/src/sandbox/devbridge-gateway.ts +36 -0
  597. package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +254 -0
  598. package/plugins/huaweicloud-core/src/sandbox/{devbridge-key.mjs → devbridge-key.ts} +48 -32
  599. package/plugins/huaweicloud-core/src/sandbox/devbridge-renew.ts +87 -0
  600. package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +79 -0
  601. package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +100 -0
  602. package/plugins/huaweicloud-core/src/sandbox/devbridge-verify.ts +120 -0
  603. package/plugins/huaweicloud-core/src/sandbox/hwlink-connection.ts +188 -0
  604. package/plugins/huaweicloud-core/src/sandbox/sandbox-output.ts +46 -0
  605. package/plugins/huaweicloud-core/src/sandbox/session-manager.ts +89 -0
  606. package/plugins/huaweicloud-core/src/sandbox/tunnel-http.ts +155 -0
  607. package/plugins/huaweicloud-core/src/sandbox/{uninstall-cleanup.mjs → uninstall-cleanup.ts} +4 -4
  608. package/plugins/huaweicloud-core/src/sandbox/upload-diagnostics.ts +46 -0
  609. package/plugins/huaweicloud-core/src/sandbox/upload-file.ts +161 -0
  610. package/plugins/huaweicloud-core/src/sandbox/upload-project.ts +218 -0
  611. package/plugins/huaweicloud-core/src/sandbox/upload-transport.ts +150 -0
  612. package/plugins/huaweicloud-core/src/sandbox/ws-exec-loader.ts +104 -0
  613. package/plugins/huaweicloud-core/src/search-docs.ts +64 -0
  614. package/plugins/huaweicloud-core/src/{search-market.mjs → search-market.ts} +96 -28
  615. package/plugins/huaweicloud-core/src/services/availability.ts +53 -0
  616. package/plugins/huaweicloud-core/src/services/regions.ts +110 -0
  617. package/plugins/huaweicloud-core/src/setup-cli.ts +1563 -0
  618. package/plugins/huaweicloud-core/src/skill-disclosure.ts +242 -0
  619. package/plugins/huaweicloud-core/src/targets.ts +156 -0
  620. package/plugins/huaweicloud-core/src/telemetry/{agent-detect.mjs → agent-detect.ts} +16 -5
  621. package/plugins/huaweicloud-core/src/telemetry/agent-registry.ts +210 -0
  622. package/plugins/huaweicloud-core/src/telemetry/agent-versions-desktop.ts +138 -0
  623. package/plugins/huaweicloud-core/src/telemetry/agent-versions.ts +84 -0
  624. package/plugins/huaweicloud-core/src/telemetry/event-pipeline.ts +214 -0
  625. package/plugins/huaweicloud-core/src/telemetry/hook-ingest.ts +82 -0
  626. package/plugins/huaweicloud-core/src/telemetry/identity-stamps.ts +108 -0
  627. package/plugins/huaweicloud-core/src/telemetry/invoke-value.ts +47 -0
  628. package/plugins/huaweicloud-core/src/telemetry/telemetry-fs.ts +47 -0
  629. package/plugins/huaweicloud-core/src/telemetry/telemetry-types.ts +97 -0
  630. package/plugins/huaweicloud-core/src/telemetry/telemetry-values.ts +116 -0
  631. package/plugins/huaweicloud-core/src/telemetry/telemetry.ts +299 -0
  632. package/plugins/huaweicloud-core/src/tool-definitions.ts +294 -0
  633. package/plugins/huaweicloud-core/src/tool-schemas.ts +180 -0
  634. package/plugins/huaweicloud-core/src/tools.ts +417 -0
  635. package/plugins/huaweicloud-core/src/update-cache.ts +95 -0
  636. package/plugins/huaweicloud-core/src/update-check.ts +51 -0
  637. package/plugins/huaweicloud-core/src/update-hint.ts +82 -0
  638. package/plugins/huaweicloud-core/src/update-installed.ts +53 -0
  639. package/plugins/huaweicloud-core/src/update-registry.ts +146 -0
  640. package/plugins/huaweicloud-core/src/update-semver.ts +80 -0
  641. package/plugins/huaweicloud-core/src/update-skip.ts +94 -0
  642. package/plugins/huaweicloud-core/src/update-upgrade.ts +123 -0
  643. package/plugins/huaweicloud-core/src/vendor-gate.ts +103 -0
  644. package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-client.ts +15 -0
  645. package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-pending.ts +113 -0
  646. package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-session.ts +334 -0
  647. package/plugins/huaweicloud-core/src/ws-exec/{hwlink-fair-queue.js → hwlink-fair-queue.ts} +46 -15
  648. package/plugins/huaweicloud-core/src/ws-exec/hwlink-interactive-terminal.ts +158 -0
  649. package/plugins/huaweicloud-core/src/ws-exec/{hwlink-multiplexer.js → hwlink-multiplexer.ts} +108 -30
  650. package/plugins/huaweicloud-core/src/ws-exec/hwlink-normalize.ts +60 -0
  651. package/plugins/huaweicloud-core/src/ws-exec/{hwlink-packet.js → hwlink-packet.ts} +40 -16
  652. package/plugins/huaweicloud-core/src/ws-exec/{hwlink-terminal-channel.js → hwlink-terminal-channel.ts} +30 -18
  653. package/plugins/huaweicloud-core/src/ws-exec/{hwlink-tunnel-channel.mjs → hwlink-tunnel-channel.ts} +75 -27
  654. package/plugins/huaweicloud-core/src/ws-exec/{index.js → index.ts} +11 -11
  655. package/plugins/huaweicloud-core/src/ws-exec/ws-exec-client.ts +102 -0
  656. package/plugins/huaweicloud-core/tsconfig.json +21 -0
  657. package/rules/huawei-agent-rules.mdc +2 -2
  658. package/integrations/hermes/skills-snapshot.json +0 -175
  659. package/integrations/opencode/skills/huaweicloud-core/SKILL.md +0 -32
  660. package/plugins/huaweicloud-core/skills/huawei-cloud-apig-instance-management/scripts/cli/cli_reporting.py +0 -589
  661. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/references/test-report.md +0 -35
  662. package/plugins/huaweicloud-core/skills/huawei-cloud-cts-trace-management/scripts/cli/cli_reporting.py +0 -928
  663. package/plugins/huaweicloud-core/skills/huawei-cloud-dds-dcs-instance-management/scripts/cli/cli_reporting.py +0 -928
  664. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/references/test-report.md +0 -52
  665. package/plugins/huaweicloud-core/skills/huawei-cloud-deployment-task-management/scripts/cli/cli_reporting.py +0 -928
  666. package/plugins/huaweicloud-core/skills/huawei-cloud-dew-key-management/scripts/cli/cli_reporting.py +0 -577
  667. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/scripts/cli/cli_reporting.py +0 -928
  668. package/plugins/huaweicloud-core/skills/huawei-cloud-gaussdb-instance-management/scripts/gaussdb_cli.sh +0 -138
  669. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/scripts/install_cli.sh +0 -94
  670. package/plugins/huaweicloud-core/skills/huawei-cloud-smn-dms-message/scripts/smn_dms_skill.py +0 -444
  671. package/plugins/huaweicloud-core/src/account-type.mjs +0 -135
  672. package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +0 -243
  673. package/plugins/huaweicloud-core/src/auth/credential-validator.mjs +0 -198
  674. package/plugins/huaweicloud-core/src/auth/credentials.mjs +0 -446
  675. package/plugins/huaweicloud-core/src/auth/project-id.mjs +0 -68
  676. package/plugins/huaweicloud-core/src/auth/reconcile.mjs +0 -257
  677. package/plugins/huaweicloud-core/src/detect-framework.mjs +0 -402
  678. package/plugins/huaweicloud-core/src/hcloud-cli.mjs +0 -825
  679. package/plugins/huaweicloud-core/src/koocli-version.mjs +0 -47
  680. package/plugins/huaweicloud-core/src/mcp-config-merge.mjs +0 -219
  681. package/plugins/huaweicloud-core/src/mcp-protocol.mjs +0 -109
  682. package/plugins/huaweicloud-core/src/mcp-server-remote.mjs +0 -108
  683. package/plugins/huaweicloud-core/src/mcp-server.mjs +0 -221
  684. package/plugins/huaweicloud-core/src/officeace-paths.mjs +0 -51
  685. package/plugins/huaweicloud-core/src/preflight.mjs +0 -125
  686. package/plugins/huaweicloud-core/src/proxy/proxy-config.mjs +0 -187
  687. package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +0 -182
  688. package/plugins/huaweicloud-core/src/safety-policy.mjs +0 -625
  689. package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +0 -224
  690. package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +0 -2594
  691. package/plugins/huaweicloud-core/src/setup-cli.mjs +0 -5379
  692. package/plugins/huaweicloud-core/src/telemetry/agent-registry.mjs +0 -341
  693. package/plugins/huaweicloud-core/src/telemetry/telemetry.mjs +0 -492
  694. package/plugins/huaweicloud-core/src/tools.mjs +0 -3190
  695. package/plugins/huaweicloud-core/src/update-check.mjs +0 -476
  696. package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-client.js +0 -461
  697. package/plugins/huaweicloud-core/src/ws-exec/ws-exec-client.js +0 -365
@@ -0,0 +1,310 @@
1
+ import {
2
+ DEVBRIDGE_BAD_GATEWAY_MARKER,
3
+ DEVBRIDGE_MIGRATION_MARKER,
4
+ DEVBRIDGE_PORT_NOT_CONFIGURED_MARKER,
5
+ DEVBRIDGE_TUNNEL_DOMAIN,
6
+ DEVBRIDGE_TUNNEL_NOT_FOUND_MARKER,
7
+ escapeTunnelDomainForRegExp,
8
+ } from './devbridge-gateway.ts';
9
+ import { DEVBRIDGE_HOST_EXPIRY_HOURS, evaluateDevbridgeVersion } from './devbridge-validation.ts';
10
+ import { stripTerminalEscapes } from './sandbox-output.ts';
11
+ import { runOneShot, type OneShotResult } from './devbridge-exec.ts';
12
+ import type { DevbridgeQuotaKeyHint } from './devbridge-key.ts';
13
+
14
+ // The expose attempt contract, extracted from devbridge-tunnel: the script that
15
+ // starts the host and probes reachability, the DB_* stdout grammar (readDbField
16
+ // + the expose/probe parsers), the reachability warning, and the tool's result
17
+ // interface. readDbField is the grammar's canonical home — the renew and
18
+ // keepalive parsers import it from here.
19
+
20
+ export interface ExposeTunnelResult {
21
+ ok: boolean;
22
+ publicUrl?: string;
23
+ port: number;
24
+ tunnelId?: string;
25
+ authMode: string;
26
+ httpCode?: string;
27
+ verifyHttpCode?: string;
28
+ verifyNotFound?: boolean;
29
+ persistent?: boolean;
30
+ expiresAt?: string;
31
+ expiresInHours?: number;
32
+ sandboxLifetime?: {
33
+ poolType: string;
34
+ idleShutdownMinutes: number;
35
+ idleDeleteMinutes?: number;
36
+ reclaimMinutes?: number;
37
+ };
38
+ urlLifetimeHint?: string;
39
+ warnings?: string;
40
+ hostLog?: string;
41
+ error?: string;
42
+ error_code?: string;
43
+ version?: string;
44
+ remediation?: string;
45
+ keepalive?: {
46
+ enrolled: boolean;
47
+ tunnelCount: number | undefined;
48
+ watchdogPid: string | undefined;
49
+ logPath: string | undefined;
50
+ error: string | undefined;
51
+ };
52
+ attempts?: Record<string, string>;
53
+ hint?: string;
54
+ loginOutput?: string;
55
+ // The quota-degradation key list (the HDKIT_DEVBRIDGE_KEY_QUOTA_EXCEEDED
56
+ // failure only): masked keys with last_used_at so the caller can pick what
57
+ // to clean up in the console.
58
+ currentKeys?: DevbridgeQuotaKeyHint[];
59
+ }
60
+
61
+ // Start (or replace) a devbridge host bound to a single port, extract the public
62
+ // URL, and health-check it. Mirrors the huaweicloud-sandbox skill's Expose flow:
63
+ // pre-clean stale tunnels (quota 10006), start host in background, read the
64
+ // port-anchored "Tunnel URL: ..." from /tmp/host.log, curl-check, retry once on
65
+ // unreachable.
66
+ // The host MUST survive the exec session that started it (#919): setsid detaches
67
+ // it from the session's process group, `< /dev/null` drops the controlling tty
68
+ // stdin, and `disown` removes it from the shell's job table — without all three
69
+ // the host is reaped when the one-shot session ends and the tunnel dies
70
+ // immediately after a green in-session health check (the "假成功" bug).
71
+ export function buildDevbridgeExposeScript(port: number, expiryHours: number = DEVBRIDGE_HOST_EXPIRY_HOURS): string {
72
+ const hostLog = '/tmp/host.log';
73
+ // Port-anchored URL extraction: a multi-port host prints one "Tunnel URL:" line per
74
+ // port, so a port-blind `sed | tail -1` can pick another port's URL. The pattern is
75
+ // derived from the shared domain constant, never hardcoded.
76
+ const domainLiteral = escapeTunnelDomainForRegExp(DEVBRIDGE_TUNNEL_DOMAIN);
77
+ return [
78
+ // #999: the export rides the same first line as the pkill so the fake's
79
+ // first-line recognizer (and any reader) sees one stable anchor — the
80
+ // one-shot exec shell does NOT inherit the auth probe's PATH, and after
81
+ // the Layer-3 install + dedup (or a reboot) the only surviving binary
82
+ // lives at /workspace/.local/bin.
83
+ `export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"; pkill -f "devbridge host" 2>/dev/null || true`,
84
+ `sleep 2`,
85
+ `devbridge delete-all > /dev/null 2>&1 || true`,
86
+ // #922 (S8): setsid is unavailable on some sandbox images — fall back to a
87
+ // bare nohup launch so the host still starts; persistence is then judged by
88
+ // the independent re-verify in exposeTunnel, which emits the 请勿分享 warning
89
+ // in the non-persistent case. disown is guarded: shells without the builtin
90
+ // must not abort the script.
91
+ `if command -v setsid > /dev/null 2>&1; then setsid nohup devbridge host -p ${port} -e ${expiryHours} > ${hostLog} 2>&1 < /dev/null & else nohup devbridge host -p ${port} -e ${expiryHours} > ${hostLog} 2>&1 < /dev/null & fi`,
92
+ `disown 2>/dev/null || true`,
93
+ // A2 (#935), v2-hardened: bounded URL-extraction retry instead of a flat
94
+ // settle sleep — the host logs "Tunnel URL:" at its own pace (v2's old
95
+ // 12s flat window existed for slow host logs), so re-grep up to 4 times
96
+ // with 3s gaps (0/3/6/9s, early exit) before concluding the host never
97
+ // logged a URL. Main's A2 uses a flat sleep 6 + single grep, which halves
98
+ // the window v2 tuned for slow hosts — deliberate divergence, recorded.
99
+ `TUNNEL_URL=""`,
100
+ `for i in 1 2 3 4; do`,
101
+ ` TUNNEL_URL=$(grep -oE "https://[A-Za-z0-9_-]+-${port}\\.${domainLiteral}" ${hostLog} | head -1)`,
102
+ ` [ -n "$TUNNEL_URL" ] && break`,
103
+ ` sleep 3`,
104
+ `done`,
105
+ // A2 (#935): probe with retries + backoff — 502/000 before the gateway is
106
+ // ready is not a failure; the LAST probe decides reachability. Every probe
107
+ // that receives an HTTP response rewrites the body file; a transport-failed
108
+ // final probe leaves the previous body (inert — body verdicts are
109
+ // status-gated on 404/502, never 000).
110
+ // No `|| echo "000"`: curl's -w already prints 000 on transport-level
111
+ // failure (DNS/refused/timeout) and exits non-zero, so `|| echo` appends a
112
+ // second 000 to the captured output — a value no '000' sentinel check ever
113
+ // equals. Early curl exits leave the field '' or '000' — both are handled
114
+ // as unreachable.
115
+ `HTTP_CODE="000"`,
116
+ `if [ -n "$TUNNEL_URL" ]; then`,
117
+ ` for i in 1 2 3 4; do`,
118
+ // #1000: --noproxy — the sandbox injects an HTTP proxy that does NOT route
119
+ // the tunnel domain; without it the probe returns 502/404 fakes and a
120
+ // working tunnel is judged dead.
121
+ ` HTTP_CODE=$(curl -s --noproxy '*' -o /tmp/.db_probe_body -w "%{http_code}" --max-time 10 "$TUNNEL_URL" 2>/dev/null)`,
122
+ ` echo "DB_PROBE_$i=$HTTP_CODE"`,
123
+ ` if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "304" ]; then break; fi`,
124
+ ` if [ "$i" != "4" ]; then sleep 5; fi`,
125
+ ` done`,
126
+ `fi`,
127
+ `echo "DB_HOST_LOG="`,
128
+ `tail -n 5 ${hostLog}`,
129
+ `echo "DB_TUNNEL_URL=$TUNNEL_URL"`,
130
+ `echo "DB_HTTP_CODE=$HTTP_CODE"`,
131
+ `echo "DB_EXPIRY_HOURS=${expiryHours}"`,
132
+ // First 64 bytes of the probe body (non-sensitive, newlines stripped so an
133
+ // app body can never line-inject later DB_ verdict fields) — feeds the
134
+ // exact gateway-error body matching.
135
+ `echo "DB_TUNNEL_BODY=$(head -c 64 /tmp/.db_probe_body 2>/dev/null | tr -d '\\r\\n')"`,
136
+ `rm -f /tmp/.db_probe_body`,
137
+ // grep -c prints its 0 count itself on no-match (exit 1); `|| true` keeps
138
+ // that stdout. A missing log leaves '' → parsed as no quota error. (The old
139
+ // `|| echo 0` doubled the output: a stray second 0 line.)
140
+ `echo "DB_QUOTA_ERROR=$(grep -c '10006' ${hostLog} 2>/dev/null || true)"`,
141
+ // Migration-marker scan scoped to the HOST LOG ONLY (devbridge's own
142
+ // output): the probe body is now echoed (DB_TUNNEL_BODY) for the
143
+ // gateway-error classification, and an app page legitimately containing
144
+ // the marker in its first bytes must not be misdiagnosed as a retired
145
+ // pre-migration gateway placeholder.
146
+ `echo "DB_MIGRATION=$(grep -c '${DEVBRIDGE_MIGRATION_MARKER}' ${hostLog} 2>/dev/null || true)"`,
147
+ ].join('\n');
148
+ }
149
+
150
+ export interface DevbridgeProbe {
151
+ attempt: number;
152
+ httpCode: string;
153
+ }
154
+
155
+ // A2 (#935): parse the probe sequence emitted by buildDevbridgeExposeScript.
156
+ // Each probe echo is `DB_PROBE_<n>=<code>`; reachability is decided by the
157
+ // LAST probe — intermediate 502/000 probes are gateway-not-ready noise, not
158
+ // failures, so they must not leak into the tool's verdict. NB: in production
159
+ // the verdict rides the DB_HTTP_CODE field (the loop variable's final value,
160
+ // emitted by the script) — finalHttpCode here is a diagnostic/test derivation
161
+ // for sequences parsed standalone.
162
+ export function parseDevbridgeProbeSequence(stdout: unknown): { probes: DevbridgeProbe[]; finalHttpCode: string } {
163
+ const text = stripTerminalEscapes(stdout);
164
+ const probes: DevbridgeProbe[] = [];
165
+ for (const m of text.matchAll(/^DB_PROBE_(\d+)=(\S*)$/gm)) {
166
+ probes.push({ attempt: Number(m[1]), httpCode: m[2] ?? '' });
167
+ }
168
+ const finalHttpCode = probes.length > 0 ? probes[probes.length - 1]!.httpCode : '';
169
+ return { probes, finalHttpCode };
170
+ }
171
+
172
+ // A2 (#935): the reachability warning must come from the LAST probe's HTTP
173
+ // status, not from a single early curl — the old single-shot check warned
174
+ // "Tunnel reachable check returned HTTP (expected 200/304)" while the same
175
+ // log showed DB_HTTP_CODE=200. 200/304 = no warning; anything else surfaces
176
+ // as-is.
177
+ export function formatTunnelReachabilityWarning(httpCode: string): string | undefined {
178
+ if (httpCode === '200' || httpCode === '304') return undefined;
179
+ return `Tunnel reachable check returned HTTP ${httpCode || '000'} (expected 200/304). The URL may not be serving yet — the final probe decides.`;
180
+ }
181
+
182
+ export interface DevbridgeExpose {
183
+ tunnelUrl: string;
184
+ httpCode: string;
185
+ quotaError: boolean;
186
+ tunnelId: string;
187
+ expiryHours: number | undefined;
188
+ gatewayTunnelError: boolean;
189
+ badGateway: boolean;
190
+ migration: boolean;
191
+ probes: DevbridgeProbe[];
192
+ }
193
+
194
+ // Anchored `^KEY=value` field reader over stripped multi-line text — the DB_*
195
+ // output grammar's single lookup rule, shared by the expose and verify parsers
196
+ // (and, through this canonical home, the renew and keepalive parsers).
197
+ export function readDbField(text: string, key: string): string {
198
+ const m = text.match(new RegExp(`^${key}=(.*)$`, 'm'));
199
+ return m ? (m[1] ?? '').trim() : '';
200
+ }
201
+
202
+ // Parse the raw stdout of buildDevbridgeExposeScript into structured fields.
203
+ // `gatewayTunnelError` marks a URL the s2 gateway itself reports as dead
204
+ // (404 "tunnel not found" / "port not configured") — it can never serve content
205
+ // regardless of the app. `badGateway` (502 "bad gateway") means the tunnel is
206
+ // alive but the local service on the exposed port is not serving.
207
+ export function parseDevbridgeExposeOutput(stdout: unknown): DevbridgeExpose {
208
+ // #946: strip OSC/CSI escapes + \r BEFORE the anchored ^DB_ lookups — otherwise
209
+ // every field is lost on integration-enabled shells and a perfectly good tunnel
210
+ // comes back as ok:true with publicUrl missing (and pointlessly re-built once).
211
+ const text = stripTerminalEscapes(stdout);
212
+ const tunnelUrl = readDbField(text, 'DB_TUNNEL_URL') || (text.match(/TUNNEL_URL:(https:\/\/[^\s]+)/) ?? [])[1] || '';
213
+ const httpCode = readDbField(text, 'DB_HTTP_CODE');
214
+ const body = readDbField(text, 'DB_TUNNEL_BODY');
215
+ // Field-scoped verdicts (never scan the echoed probe body): quota and
216
+ // migration are host-log facts, computed script-side by grepping the log.
217
+ // Count-robust (`> 0`, not `=== '1'`): grep -c prints a LINE count, and a
218
+ // retrying host can log the marker on several lines.
219
+ const quotaError = Number(readDbField(text, 'DB_QUOTA_ERROR')) > 0;
220
+ const migration = Number(readDbField(text, 'DB_MIGRATION')) > 0;
221
+ const domainPattern = escapeTunnelDomainForRegExp(DEVBRIDGE_TUNNEL_DOMAIN);
222
+ const tunnelId =
223
+ (tunnelUrl.match(new RegExp(`^https:\\/\\/([A-Za-z0-9_-]+)-\\d+\\.${domainPattern}`)) ?? [])[1] ?? '';
224
+ const expiryHours = Number(readDbField(text, 'DB_EXPIRY_HOURS')) || undefined;
225
+ // Exact-body match gated on the status code: an app's own 404/502 page is never misjudged.
226
+ const gatewayTunnelError =
227
+ httpCode === '404' && (body === DEVBRIDGE_TUNNEL_NOT_FOUND_MARKER || body === DEVBRIDGE_PORT_NOT_CONFIGURED_MARKER);
228
+ const badGateway = httpCode === '502' && body === DEVBRIDGE_BAD_GATEWAY_MARKER;
229
+ const { probes } = parseDevbridgeProbeSequence(text);
230
+ return { tunnelUrl, httpCode, quotaError, tunnelId, expiryHours, gatewayTunnelError, badGateway, migration, probes };
231
+ }
232
+
233
+ // The no-usable-URL failure verdict of exposeTunnel (the Q2 ruling path):
234
+ // build the #998 taxonomy return — too_old (with the deferred version
235
+ // read-back) / no_tunnel_url / tunnel_unreachable. The failure shape is the
236
+ // flow's verbatim return (moved here, not reworded); the caller passes the
237
+ // accumulated warnings array and this phase appends its own before joining.
238
+ export async function reportUnusableExpose(args: {
239
+ workspaceId: string;
240
+ username: string;
241
+ port: number;
242
+ authMode: string;
243
+ authVersion: string;
244
+ parsed: DevbridgeExpose;
245
+ exposeFailed: boolean;
246
+ warnings: string[];
247
+ result: OneShotResult;
248
+ }): Promise<ExposeTunnelResult> {
249
+ const { workspaceId, username, port, authMode, authVersion, parsed, exposeFailed, warnings, result } = args;
250
+ // #998 read-back: a no-URL failure after retries needs the version in the
251
+ // return body — the gate above catches 0.1.x upfront, but a binary that
252
+ // changed mid-flow (or an empty probe version) lands here, and in the
253
+ // measured incident a single version field would have saved the whole
254
+ // credentials/network/port misdiagnosis. The command reuses the DB_VERSION
255
+ // field grammar (echo + anchored parse through stripTerminalEscapes — the
256
+ // #946 doctrine; a raw stdout read would be OSC-blind on exactly the
257
+ // shells that lose the probe line in the first place).
258
+ let noUrlVersion = authVersion;
259
+ if (parsed.tunnelUrl === '') {
260
+ try {
261
+ const versionResult = await runOneShot(
262
+ workspaceId,
263
+ `export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"; echo "DB_VERSION=$(devbridge version 2>/dev/null | head -1)"`,
264
+ username,
265
+ 15000,
266
+ );
267
+ const readBack =
268
+ stripTerminalEscapes(versionResult.stdout)
269
+ .match(/^DB_VERSION=(.*)$/m)?.[1]
270
+ ?.trim() ?? '';
271
+ noUrlVersion = readBack || authVersion;
272
+ } catch {
273
+ // best-effort: the auth probe's version stands
274
+ }
275
+ }
276
+ const noUrlCheck = evaluateDevbridgeVersion(noUrlVersion);
277
+ if (noUrlCheck.blocked) {
278
+ warnings.push(
279
+ `devbridge version is ${noUrlVersion} — too old to serve tunnels; upgrade per Step 0 before retrying.`,
280
+ );
281
+ }
282
+ // #998 taxonomy: too_old (blocked) / no_tunnel_url (no URL observed —
283
+ // host did not start, or the exec timed out before the log was read) /
284
+ // tunnel_unreachable (URL present, probes exhausted). The timeout-fold
285
+ // case gets its own hedged wording — a timeout lost the observation, it
286
+ // did not prove the host never started.
287
+ const timedOut = exposeFailed && parsed.tunnelUrl === '';
288
+ return {
289
+ ok: false,
290
+ port,
291
+ error: noUrlCheck.blocked
292
+ ? noUrlCheck.error
293
+ : timedOut
294
+ ? 'Failed to expose a working DevBridge tunnel: the expose exec timed out or died before a Tunnel URL could be extracted — host state unknown (see warnings). Retry, or raise timeout_ms.'
295
+ : parsed.tunnelUrl === ''
296
+ ? 'Failed to expose a working DevBridge tunnel: the host log contains no Tunnel URL — the host did not start. Check the hostLog below for the real cause.'
297
+ : 'Failed to expose a working DevBridge tunnel: no reachable public URL after retries.',
298
+ error_code: noUrlCheck.blocked
299
+ ? 'devbridge_too_old'
300
+ : parsed.tunnelUrl === ''
301
+ ? 'no_tunnel_url'
302
+ : 'tunnel_unreachable',
303
+ version: noUrlVersion || undefined,
304
+ authMode,
305
+ httpCode: parsed.httpCode,
306
+ warnings: warnings.length > 0 ? warnings.join(' ') : undefined,
307
+ remediation: noUrlCheck.blocked ? noUrlCheck.remediation : undefined,
308
+ hostLog: String(result.stdout ?? '').slice(0, 400),
309
+ };
310
+ }
@@ -0,0 +1,36 @@
1
+ // The DevBridge s2 gateway's wire contract, extracted from session-manager so
2
+ // the tunnel-domain and gateway-error vocabulary has one canonical home in the
3
+ // sandbox family: deploy-check.ts splices these into its probe script, and the
4
+ // devbridge-tunnel family (devbridge-expose.ts / devbridge-verify.ts) consumes
5
+ // them directly (same exported names, same import path).
6
+
7
+ // Public tunnel URL domain for the DevBridge s2 gateway. The pre-migration Huawei Cloud
8
+ // bridge domain was retired in Sep 2026 and now serves a 「服务已迁移」 placeholder page with
9
+ // HTTP 200 — never construct tunnel URLs from it. Exported for the devbridge-tunnel
10
+ // family (the DevBridge-owned modules keep the single copy).
11
+ export const DEVBRIDGE_TUNNEL_DOMAIN = 'devbridge-s2.hwtunnel.com';
12
+ // Migration placeholder page marker — a tunnel URL returning this body must be treated as unreachable.
13
+ export const DEVBRIDGE_MIGRATION_MARKER = '服务已迁移';
14
+ // Gateway-level tunnel error bodies. "tunnel not found" was verified live
15
+ // against the s2 gateway (Oct 2026: 404, text/plain, body "tunnel not found\n");
16
+ // the other two are the gateway's documented contract:
17
+ // 404 "tunnel not found" — no live host session on the gateway (host process dead or
18
+ // tunnel deleted); the tunnel RECORD may still exist in `list`
19
+ // 404 "port not configured" — the URL's port is not registered on the tunnel
20
+ // 502 "bad gateway" — host session alive, but the registered port has no local service
21
+ // A bare status check cannot distinguish these from app-generated 404/502 responses, so the
22
+ // checks below match the exact body AND gate on the HTTP status code.
23
+ export const DEVBRIDGE_TUNNEL_NOT_FOUND_MARKER = 'tunnel not found';
24
+ export const DEVBRIDGE_PORT_NOT_CONFIGURED_MARKER = 'port not configured';
25
+ export const DEVBRIDGE_BAD_GATEWAY_MARKER = 'bad gateway';
26
+
27
+ // Complete regex-metacharacter escape for the domain when it is interpolated
28
+ // into a pattern — the dot-only escape the family used before was incomplete
29
+ // (CodeQL js/incomplete-sanitization: a backslash in the input would eat the
30
+ // next character's escape). Both regex consumers — the expose script's
31
+ // port-anchored grep -oE matcher and the tunnelId parser's RegExp — go
32
+ // through this one seam; the escaped form is valid for ERE and JS RegExp
33
+ // alike (over-escaping is inert in both).
34
+ export function escapeTunnelDomainForRegExp(domain: string): string {
35
+ return domain.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
36
+ }
@@ -0,0 +1,254 @@
1
+ import { asText } from '../lib/as-text.ts';
2
+ import { DEVBRIDGE_RENEW_HOURS, validateTunnelId } from './devbridge-validation.ts';
3
+ import { runOneShot } from './devbridge-exec.ts';
4
+ import { stripTerminalEscapes } from './sandbox-output.ts';
5
+ import { readDbField } from './devbridge-expose.ts';
6
+
7
+ // The keepalive watchdog family, extracted from devbridge-tunnel: the
8
+ // three-layer watchdog script (host re-attach + daily renewal + health check),
9
+ // the installed-watchdog tunnel read, its parser, the merge, and the install
10
+ // flow. Validators and the renewal horizon come from devbridge-validation.ts;
11
+ // the DB_* field reader from the expose stdout grammar's canonical home.
12
+
13
+ export interface KeepaliveTunnel {
14
+ tunnelId: string;
15
+ url: string;
16
+ }
17
+
18
+ // Build the keepalive watchdog script for a set of known tunnels (the
19
+ // three-layer pattern proven in the 2026-10 tunnel-persistence test):
20
+ // 1. host watchdog — re-attach with `devbridge host <id>` when the host
21
+ // process dies; the URL is bound to the tunnel ID, so it never changes
22
+ // 2. daily renewal — `devbridge update <id> -e 720` (29-day failure tolerance)
23
+ // 3. health check — curl each URL every 5 minutes, log on non-200/304
24
+ // URLs are HARDCODED per tunnel (tunnel IDs never change), NOT derived from
25
+ // `devbridge port list` — that table's lines are wrapped in OSC escapes on
26
+ // integration-enabled shells, so anchored greps silently fail and the
27
+ // constructed health URL 404s (measured 2026-10).
28
+ // v2 divergences from main's script (recorded): the PATH export is
29
+ // data-disk-first (#999); the health-check curl carries --noproxy '*'
30
+ // (#1000 — main's own keepalive missed it; without it the watchdog logs WARN
31
+ // 502/404 fakes for healthy tunnels) and drops main's `|| echo "000"` (the
32
+ // file's documented sentinel-doubling doctrine — an empty HC still WARNs);
33
+ // and the layer-1 probe matches BOTH host launch forms (main's single-form
34
+ // pgrep cannot see the -p-form host expose_tunnel itself launched and
35
+ // spuriously "restarts" it on the first tick).
36
+ export function buildDevbridgeKeepaliveScript(tunnels: unknown): string {
37
+ if (!Array.isArray(tunnels) || tunnels.length === 0) {
38
+ throw new Error('sandbox keepalive: tunnels must be a non-empty array of {tunnelId, url}.');
39
+ }
40
+ const entries = (tunnels as Array<Record<string, unknown>>)
41
+ .map((t) => {
42
+ const id = validateTunnelId(t?.tunnelId);
43
+ const url = asText(t?.url ?? '');
44
+ if (!/^https:\/\/[A-Za-z0-9:._/-]+$/.test(url)) {
45
+ throw new Error(
46
+ `sandbox keepalive: invalid tunnel URL ${JSON.stringify(url.slice(0, 80))} for the keepalive health check. Expected an https:// URL with URL-safe characters (from huaweicloud_sandbox_expose_tunnel's publicUrl).`,
47
+ );
48
+ }
49
+ // The URL embeds the port (https://<id>-<port>.domain) — the layer-1
50
+ // liveness probe needs BOTH host launch forms: expose_tunnel starts
51
+ // `devbridge host -p <port>` (the ID does not exist at launch), the
52
+ // re-attach form is `devbridge host <id>`. A single-form pgrep misses
53
+ // the live -p-form host and spuriously "restarts" it on the first tick
54
+ // (v2 fix — main's watchdog carries the single-form miss).
55
+ const port = url.match(/-(\d+)\.[^.]+\.[^.]+\.[^.]+\/?$/)?.[1] ?? '';
56
+ return port ? `${id}:${url}:${port}` : `${id}:${url}:`;
57
+ })
58
+ .join(' ');
59
+ // Heredoc is single-quoted ('DB_KEEPALIVE_EOF') so the writer shell expands
60
+ // nothing; all ${...} expansion happens inside the watchdog at runtime.
61
+ const body = [
62
+ `#!/bin/bash`,
63
+ `export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"`,
64
+ `# entries: tunnelId:url (URLs are stable — tunnel IDs never change)`,
65
+ `TUNNELS="${entries}"`,
66
+ `declare -A LAST_RENEW`,
67
+ `while true; do`,
68
+ ` NOW=$(date -u +%s)`,
69
+ ` TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)`,
70
+ ` for entry in $TUNNELS; do`,
71
+ ` ID="\${entry%%:*}"; REST="\${entry#*:}"; URL="\${REST%:*}"; PORT="\${REST##*:}"`,
72
+ ` if ! pgrep -f "devbridge host $ID" > /dev/null 2>&1 && ! pgrep -f "devbridge host -p $PORT" > /dev/null 2>&1; then`,
73
+ ` if command -v setsid > /dev/null 2>&1; then setsid nohup devbridge host "$ID" > "/tmp/host-$ID.log" 2>&1 < /dev/null & else nohup devbridge host "$ID" > "/tmp/host-$ID.log" 2>&1 < /dev/null & fi`,
74
+ ` echo "$TS host $ID restarted (same tunnel, URL unchanged)" >> /tmp/tunnel-keepalive.log`,
75
+ ` sleep 8`,
76
+ ` fi`,
77
+ ` if [ $((\${LAST_RENEW[$ID]:-0})) -eq 0 ] || [ $((NOW - \${LAST_RENEW[$ID]})) -ge 86400 ]; then`,
78
+ ` if devbridge update "$ID" -e ${DEVBRIDGE_RENEW_HOURS} > /tmp/keepalive-last-update.log 2>&1; then`,
79
+ ` echo "$TS renew $ID ok (${DEVBRIDGE_RENEW_HOURS}h)" >> /tmp/tunnel-keepalive.log`,
80
+ ` else`,
81
+ ` echo "$TS renew $ID FAILED: $(head -1 /tmp/keepalive-last-update.log)" >> /tmp/tunnel-keepalive.log`,
82
+ ` fi`,
83
+ ` LAST_RENEW[$ID]=$NOW`,
84
+ ` fi`,
85
+ ` HC=$(curl -s --noproxy '*' -o /dev/null -w "%{http_code}" --max-time 10 "$URL/" 2>/dev/null)`,
86
+ ` if [ "$HC" != "200" ] && [ "$HC" != "304" ]; then`,
87
+ ` echo "$TS health $ID WARN http=$HC" >> /tmp/tunnel-keepalive.log`,
88
+ ` fi`,
89
+ ` done`,
90
+ ` sleep 300`,
91
+ `done`,
92
+ ].join('\n');
93
+ return [
94
+ // #999 anchor doctrine: the export rides the same first line as the pkill
95
+ // so first-line readers (the e2e fake, any diagnostics consumer) see one
96
+ // stable anchor — a standalone export first line is byte-identical to the
97
+ // auth probe's opening line and cannot be told apart by first-line
98
+ // recognition (measured on the e2e legs: the install one-shot was
99
+ // misread as an auth probe, its DB_ fields lost, and the resulting
100
+ // enrollment-failure warning taught the model to retry).
101
+ `export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"; pkill -f "tunnel-keepalive.sh" 2>/dev/null || true`,
102
+ `sleep 1`,
103
+ `cat > /tmp/tunnel-keepalive.sh << 'DB_KEEPALIVE_EOF'`,
104
+ body,
105
+ `DB_KEEPALIVE_EOF`,
106
+ `chmod +x /tmp/tunnel-keepalive.sh`,
107
+ `bash -n /tmp/tunnel-keepalive.sh > /dev/null 2>&1`,
108
+ `echo "DB_KEEPALIVE_SYNTAX=$?"`,
109
+ `if command -v setsid > /dev/null 2>&1; then setsid nohup /tmp/tunnel-keepalive.sh > /dev/null 2>&1 < /dev/null & else nohup /tmp/tunnel-keepalive.sh > /dev/null 2>&1 < /dev/null & fi`,
110
+ `disown 2>/dev/null || true`,
111
+ `sleep 3`,
112
+ `echo "DB_KEEPALIVE_PID=$(pgrep -f 'tunnel-keepalive.sh' | head -1)"`,
113
+ `echo "DB_KEEPALIVE_LOG=/tmp/tunnel-keepalive.log"`,
114
+ ].join('\n');
115
+ }
116
+
117
+ // Read the tunnel list of the INSTALLED watchdog (if any). The TUNNELS line in
118
+ // /tmp/tunnel-keepalive.sh is the single source of truth for what is currently
119
+ // protected; expose_tunnel reads it before installing so the new tunnel is
120
+ // MERGED into the existing protection instead of replacing it.
121
+ export function buildKeepaliveTunnelsReadScript(): string {
122
+ return [
123
+ `LINE=$(grep -m1 '^TUNNELS=' /tmp/tunnel-keepalive.sh 2>/dev/null | sed 's/^TUNNELS=//; s/^"//; s/"$//')`,
124
+ `echo "DB_KEEPALIVE_TUNNELS=$LINE"`,
125
+ ].join('\n');
126
+ }
127
+
128
+ // Parse the raw stdout of buildKeepaliveTunnelsReadScript. Empty output (no
129
+ // watchdog installed yet) yields [].
130
+ export function parseKeepaliveTunnelsOutput(stdout: unknown): KeepaliveTunnel[] {
131
+ const text = stripTerminalEscapes(stdout);
132
+ const m = text.match(/^DB_KEEPALIVE_TUNNELS=(.*)$/m);
133
+ const line = m ? (m[1] ?? '').trim() : '';
134
+ if (!line) return [];
135
+ return line
136
+ .split(/\s+/)
137
+ .map((entry) => {
138
+ const i = entry.indexOf(':');
139
+ return i > 0 ? { tunnelId: entry.slice(0, i), url: entry.slice(i + 1) } : null;
140
+ })
141
+ .filter((t): t is KeepaliveTunnel => t !== null);
142
+ }
143
+
144
+ // Merge the current watchdog tunnels with the incoming ones: dedupe by
145
+ // tunnelId, incoming wins (same tunnel re-exposed refreshes its URL), existing
146
+ // order preserved, new tunnels appended. Known limit: the read and the install
147
+ // are two execs — two CONCURRENT expose_tunnel calls on the same sandbox can
148
+ // interleave them and last-writer-wins drops the other's tunnel (documented;
149
+ // single-sandbox concurrency is not a supported posture).
150
+ export function mergeKeepaliveTunnels(existing: unknown, incoming: unknown): KeepaliveTunnel[] {
151
+ const byId = new Map<string, KeepaliveTunnel>();
152
+ for (const t of (Array.isArray(existing) ? existing : []) as Array<Record<string, unknown>>) {
153
+ if (t?.tunnelId && t?.url) byId.set(asText(t.tunnelId), { tunnelId: asText(t.tunnelId), url: asText(t.url) });
154
+ }
155
+ for (const t of (Array.isArray(incoming) ? incoming : []) as Array<Record<string, unknown>>) {
156
+ if (t?.tunnelId && t?.url) byId.set(asText(t.tunnelId), { tunnelId: asText(t.tunnelId), url: asText(t.url) });
157
+ }
158
+ return [...byId.values()];
159
+ }
160
+
161
+ export interface KeepaliveWatchdogResult {
162
+ ok: boolean;
163
+ scriptPath?: string;
164
+ logPath?: string;
165
+ watchdogPid?: string;
166
+ tunnels?: KeepaliveTunnel[];
167
+ error?: string;
168
+ }
169
+
170
+ // Install the keepalive watchdog in the sandbox. Validates every tunnel ID and
171
+ // URL before splicing, aborts on a bash syntax error (DB_KEEPALIVE_SYNTAX != 0),
172
+ // and reports the watchdog PID. Replacing the watchdog (re-running the tool)
173
+ // kills the old loop first so two loops never double-renew.
174
+ export async function installKeepaliveWatchdog(
175
+ workspaceId: string,
176
+ { tunnels }: { tunnels: unknown },
177
+ username = 'root',
178
+ timeoutMs = 60000,
179
+ ): Promise<KeepaliveWatchdogResult> {
180
+ if (!workspaceId) {
181
+ throw new Error('sandbox keepalive: workspace_id is required.');
182
+ }
183
+ const script = buildDevbridgeKeepaliveScript(tunnels);
184
+ const result = await runOneShot(workspaceId, script, username, timeoutMs);
185
+ const text = stripTerminalEscapes(result.stdout);
186
+ const syntax = readDbField(text, 'DB_KEEPALIVE_SYNTAX');
187
+ if (syntax !== '0') {
188
+ return {
189
+ ok: false,
190
+ error: `keepalive watchdog script failed the bash -n syntax check (exit ${syntax || 'unknown'}).`,
191
+ };
192
+ }
193
+ // The syntax gate alone is a weak success: the launch is unconditional, so a
194
+ // watchdog that dies inside the 3-second window (noexec /tmp, spawn failure)
195
+ // would report ok with no PID — a silent non-existence for a subsystem whose
196
+ // whole point is unattended liveness. An empty PID is an honest failure.
197
+ const pid = readDbField(text, 'DB_KEEPALIVE_PID');
198
+ if (!pid) {
199
+ return {
200
+ ok: false,
201
+ error:
202
+ 'keepalive watchdog passed the syntax check but no running PID was found after launch — the script may have died immediately (noexec /tmp? missing bash?). Inspect /tmp/tunnel-keepalive.log.',
203
+ };
204
+ }
205
+ return {
206
+ ok: true,
207
+ scriptPath: '/tmp/tunnel-keepalive.sh',
208
+ logPath: readDbField(text, 'DB_KEEPALIVE_LOG') || '/tmp/tunnel-keepalive.log',
209
+ watchdogPid: pid,
210
+ tunnels: ((Array.isArray(tunnels) ? tunnels : []) as Array<Record<string, unknown>>).map((t) => ({
211
+ tunnelId: asText(t.tunnelId),
212
+ url: asText(t.url),
213
+ })),
214
+ };
215
+ }
216
+
217
+ // The AUTO-ENROLL phase of exposeTunnel (see the flow's return-shape comment):
218
+ // read the installed watchdog's tunnel list and merge the new tunnel into it —
219
+ // MERGED, never replacing other tunnels' coverage. keepalive:false opts out.
220
+ // Non-fatal: an enrollment failure is surfaced as a warning (appended to the
221
+ // caller's array), never as a failed expose — the tunnel itself is working.
222
+ // The warning texts are the flow's verbatim lines.
223
+ export async function enrollKeepalive(
224
+ workspaceId: string,
225
+ tunnel: { tunnelId: string; url: string },
226
+ keepalive: boolean | undefined,
227
+ warnings: string[],
228
+ username: string,
229
+ ): Promise<KeepaliveWatchdogResult | undefined> {
230
+ if (keepalive !== false && tunnel.url && !tunnel.tunnelId) {
231
+ warnings.push(
232
+ 'Keepalive enrollment skipped: the tunnel ID could not be derived from the exposed URL — the tunnel works but will NOT be auto-renewed.',
233
+ );
234
+ }
235
+ if (keepalive !== false && tunnel.url && tunnel.tunnelId) {
236
+ try {
237
+ const readResult = await runOneShot(workspaceId, buildKeepaliveTunnelsReadScript(), username, 20000);
238
+ const existing = parseKeepaliveTunnelsOutput(readResult.stdout);
239
+ const merged = mergeKeepaliveTunnels(existing, [{ tunnelId: tunnel.tunnelId, url: tunnel.url }]);
240
+ const enrollment = await installKeepaliveWatchdog(workspaceId, { tunnels: merged }, username, 30000);
241
+ if (!enrollment.ok) {
242
+ warnings.push(
243
+ `Keepalive watchdog enrollment failed: ${enrollment.error || 'unknown error'} — the tunnel works but will NOT be auto-renewed. Retry with huaweicloud_sandbox_keepalive_watchdog.`,
244
+ );
245
+ }
246
+ return enrollment;
247
+ } catch (error) {
248
+ warnings.push(
249
+ `Keepalive watchdog enrollment failed (${error instanceof Error ? error.message : 'unknown error'}) — the tunnel works but will NOT be auto-renewed. Retry with huaweicloud_sandbox_keepalive_watchdog.`,
250
+ );
251
+ }
252
+ }
253
+ return undefined;
254
+ }