huaweicloud-devkit 1.0.2-dev.9 → 1.0.2-next.10

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 (99) hide show
  1. package/.agents/plugins/marketplace.json +20 -20
  2. package/LICENSE +201 -201
  3. package/README.md +178 -138
  4. package/README.zh-CN.md +176 -138
  5. package/bin/setup.cjs +10 -8
  6. package/integrations/opencode/commands/huaweicloud-doctor.md +14 -14
  7. package/integrations/opencode/opencode.json +11 -14
  8. package/integrations/opencode/skills/huaweicloud-core/SKILL.md +32 -32
  9. package/package.json +60 -44
  10. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +31 -44
  11. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +30 -43
  12. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +31 -44
  13. package/plugins/huaweicloud-core/.mcp.json +13 -15
  14. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +31 -44
  15. package/plugins/huaweicloud-core/hooks/hooks.json +26 -26
  16. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +136 -136
  17. package/plugins/huaweicloud-core/safety/policy.json +76 -100
  18. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +227 -199
  19. package/plugins/huaweicloud-core/skills/huawei-apig/SKILL.md +164 -164
  20. package/plugins/huaweicloud-core/skills/huawei-billing/SKILL.md +48 -48
  21. package/plugins/huaweicloud-core/skills/huawei-cbr/SKILL.md +50 -50
  22. package/plugins/huaweicloud-core/skills/huawei-cce/SKILL.md +103 -101
  23. package/plugins/huaweicloud-core/skills/huawei-cloud-eye/SKILL.md +90 -90
  24. package/plugins/huaweicloud-core/skills/huawei-cloud-find-skills/SKILL.md +191 -190
  25. package/plugins/huaweicloud-core/skills/huawei-cloud-find-skills/scripts/search-skills.mjs +171 -124
  26. package/plugins/huaweicloud-core/skills/huawei-cts/SKILL.md +55 -55
  27. package/plugins/huaweicloud-core/skills/huawei-dds-dcs/SKILL.md +70 -70
  28. package/plugins/huaweicloud-core/skills/huawei-deployment/SKILL.md +57 -56
  29. package/plugins/huaweicloud-core/skills/huawei-dew/SKILL.md +106 -97
  30. package/plugins/huaweicloud-core/skills/huawei-dew/references/csms-usage.md +36 -29
  31. package/plugins/huaweicloud-core/skills/huawei-dew/references/kms-usage.md +29 -23
  32. package/plugins/huaweicloud-core/skills/huawei-ecs/SKILL.md +188 -185
  33. package/plugins/huaweicloud-core/skills/huawei-ecs/references/create-instance.md +144 -133
  34. package/plugins/huaweicloud-core/skills/huawei-ecs/references/evs.md +31 -31
  35. package/plugins/huaweicloud-core/skills/huawei-ecs/references/flavors.md +57 -55
  36. package/plugins/huaweicloud-core/skills/huawei-ecs/references/troubleshooting.md +52 -52
  37. package/plugins/huaweicloud-core/skills/huawei-functiongraph/SKILL.md +132 -131
  38. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/apig-event-format.md +60 -58
  39. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/create-function.md +72 -71
  40. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/deploy-workflow.md +119 -119
  41. package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/triggers.md +142 -142
  42. package/plugins/huaweicloud-core/skills/huawei-gaussdb/SKILL.md +56 -56
  43. package/plugins/huaweicloud-core/skills/huawei-getting-started/SKILL.md +69 -65
  44. package/plugins/huaweicloud-core/skills/huawei-iam/SKILL.md +111 -111
  45. package/plugins/huaweicloud-core/skills/huawei-iam/references/policy-examples.md +148 -122
  46. package/plugins/huaweicloud-core/skills/huawei-iam/references/quick-ref.md +56 -56
  47. package/plugins/huaweicloud-core/skills/huawei-modelarts/SKILL.md +65 -65
  48. package/plugins/huaweicloud-core/skills/huawei-obs/SKILL.md +134 -127
  49. package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-create.md +49 -49
  50. package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-lifecycle.md +31 -26
  51. package/plugins/huaweicloud-core/skills/huawei-obs/references/common-pitfalls.md +101 -100
  52. package/plugins/huaweicloud-core/skills/huawei-obs/references/single-file-share.md +40 -40
  53. package/plugins/huaweicloud-core/skills/huawei-obs/references/static-website.md +56 -56
  54. package/plugins/huaweicloud-core/skills/huawei-rds/SKILL.md +229 -224
  55. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +173 -134
  56. package/plugins/huaweicloud-core/skills/huawei-smn-dms/SKILL.md +69 -69
  57. package/plugins/huaweicloud-core/skills/huawei-vpc/SKILL.md +84 -84
  58. package/plugins/huaweicloud-core/skills/huawei-vpc/references/network.md +77 -76
  59. package/plugins/huaweicloud-core/skills/huawei-vpc/references/security-group.md +60 -59
  60. package/plugins/huaweicloud-core/skills/huawei-vpc/references/subnet.md +50 -50
  61. package/plugins/huaweicloud-core/skills/huawei-waf-aad/SKILL.md +63 -63
  62. package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/SKILL.md +56 -56
  63. package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/agents/openai.yaml +4 -4
  64. package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/SKILL.md +56 -47
  65. package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/agents/openai.yaml +4 -4
  66. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +138 -128
  67. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/agents/openai.yaml +4 -4
  68. package/plugins/huaweicloud-core/skills/huaweicloud-core/SKILL.md +111 -96
  69. package/plugins/huaweicloud-core/skills/huaweicloud-core/agents/openai.yaml +4 -4
  70. package/plugins/huaweicloud-core/skills/huaweicloud-core/references/report-issue.md +20 -20
  71. package/plugins/huaweicloud-core/skills/huaweicloud-core/references/select.md +30 -28
  72. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +59 -60
  73. package/plugins/huaweicloud-core/skills/huaweicloud-safety/agents/openai.yaml +4 -4
  74. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +83 -83
  75. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/agents/openai.yaml +4 -4
  76. package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +54 -1
  77. package/plugins/huaweicloud-core/src/auth/credentials.mjs +103 -95
  78. package/plugins/huaweicloud-core/src/auth/service.mjs +63 -63
  79. package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +3517 -0
  80. package/plugins/huaweicloud-core/src/hcloud-cli.mjs +283 -265
  81. package/plugins/huaweicloud-core/src/icon-library.mjs +171 -0
  82. package/plugins/huaweicloud-core/src/mcp-server.mjs +130 -129
  83. package/plugins/huaweicloud-core/src/proxy/proxy-agent.mjs +68 -0
  84. package/plugins/huaweicloud-core/src/proxy/proxy-config.mjs +94 -0
  85. package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +140 -137
  86. package/plugins/huaweicloud-core/src/safety-policy.mjs +356 -302
  87. package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +86 -87
  88. package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +150 -153
  89. package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +196 -105
  90. package/plugins/huaweicloud-core/src/search-market.mjs +208 -169
  91. package/plugins/huaweicloud-core/src/setup-cli.mjs +2622 -1594
  92. package/plugins/huaweicloud-core/src/tools.mjs +463 -111
  93. package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-client.js +447 -427
  94. package/plugins/huaweicloud-core/src/ws-exec/hwlink-fair-queue.js +128 -132
  95. package/plugins/huaweicloud-core/src/ws-exec/hwlink-multiplexer.js +215 -227
  96. package/plugins/huaweicloud-core/src/ws-exec/hwlink-packet.js +189 -202
  97. package/plugins/huaweicloud-core/src/ws-exec/hwlink-terminal-channel.js +164 -158
  98. package/plugins/huaweicloud-core/src/ws-exec/index.js +19 -19
  99. package/plugins/huaweicloud-core/src/ws-exec/ws-exec-client.js +338 -338
@@ -1,105 +1,196 @@
1
- import { spawn } from 'node:child_process';
2
- import { join, dirname } from 'node:path';
3
- import { fileURLToPath, pathToFileURL } from 'node:url';
4
- import { createConnection, getCredentials } from './hwlink-api.mjs';
5
-
6
- const __dirname = dirname(fileURLToPath(import.meta.url));
7
- export const WS_EXEC_INDEX_URL = pathToFileURL(join(__dirname, '..', 'ws-exec', 'index.js')).href;
8
-
9
- const DEFAULT_WORKSPACE_ID = process.env.HW_WORKSPACE_ID || '0107bd9997aa4287bd2b4890b49af07d';
10
-
11
- function resolveEnv() {
12
- const env = { ...process.env };
13
- env.PATH = `${env.HOME || '/root'}/.huawei/bin:${env.PATH || ''}`;
14
- return env;
15
- }
16
-
17
- async function runNodeExec(args, timeoutMs = 30000) {
18
- const env = resolveEnv();
19
- return new Promise((resolve) => {
20
- const proc = spawn('node', args, { env, stdio: ['pipe', 'pipe', 'pipe'] });
21
- let stdout = '';
22
- let stderr = '';
23
- proc.stdout.on('data', (d) => { stdout += d.toString(); });
24
- proc.stderr.on('data', (d) => { stderr += d.toString(); });
25
-
26
- const timer = setTimeout(() => {
27
- proc.kill();
28
- resolve({ error: 'timed out', exitCode: 124 });
29
- }, timeoutMs);
30
-
31
- proc.on('close', (code) => {
32
- clearTimeout(timer);
33
- const out = stdout.trim();
34
- if (out) {
35
- try {
36
- resolve({ ...JSON.parse(out), exitCode: code || 0 });
37
- return;
38
- } catch {}
39
- }
40
- if (code && code !== 0 && !out) {
41
- resolve({ error: stderr.trim() || `exit code ${code}`, exitCode: code });
42
- return;
43
- }
44
- resolve({ data: out, exitCode: code || 0 });
45
- });
46
- });
47
- }
48
-
49
- const sessions = new Map();
50
-
51
- async function getSession(workspaceId, username, timeoutMs) {
52
- const key = `${workspaceId}:${username}`;
53
- if (sessions.has(key)) return sessions.get(key);
54
-
55
- const { ak, sk, securitytoken } = getCredentials();
56
- const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
57
-
58
- const { connectHwlinkTerminalSession } = await import(WS_EXEC_INDEX_URL);
59
- const session = await connectHwlinkTerminalSession({
60
- url: wsUrl,
61
- source,
62
- username,
63
- timeoutMs,
64
- });
65
-
66
- sessions.set(key, session);
67
- return session;
68
- }
69
-
70
- export async function execOneShot(workspaceId, command, username, timeoutMs) {
71
- const { ak, sk, securitytoken } = getCredentials();
72
- const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
73
-
74
- const { executeHwlinkCommand } = await import(WS_EXEC_INDEX_URL);
75
- return await executeHwlinkCommand({
76
- url: wsUrl,
77
- source,
78
- username,
79
- command,
80
- timeoutMs,
81
- });
82
- }
83
-
84
- export async function execWithSession(workspaceId, command, username, timeoutMs) {
85
- const session = await getSession(workspaceId, username, timeoutMs);
86
- return await session.exec(command, { timeoutMs });
87
- }
88
-
89
- export async function closeSession(workspaceId, username) {
90
- const key = `${workspaceId}:${username}`;
91
- const session = sessions.get(key);
92
- if (!session) return false;
93
- sessions.delete(key);
94
- try { session.close(); } catch {}
95
- return true;
96
- }
97
-
98
- export async function closeAllSessions() {
99
- for (const [key, session] of sessions) {
100
- sessions.delete(key);
101
- try { session.close(); } catch {}
102
- }
103
- }
104
-
105
- export { DEFAULT_WORKSPACE_ID, runNodeExec };
1
+ import { spawn } from 'node:child_process';
2
+ import { existsSync, readFileSync, statSync } from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
+ import { join, dirname } from 'node:path';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import { createConnection, getCredentials } from './hwlink-api.mjs';
7
+ import { getWebSocketImpl } from '../proxy/proxy-agent.mjs';
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ export const WS_EXEC_INDEX_URL = pathToFileURL(join(__dirname, '..', 'ws-exec', 'index.js')).href;
11
+
12
+ const DEFAULT_WORKSPACE_ID = process.env.HW_WORKSPACE_ID || '0107bd9997aa4287bd2b4890b49af07d';
13
+
14
+ function resolveEnv() {
15
+ const env = { ...process.env };
16
+ env.PATH = `${env.HOME || '/root'}/.huawei/bin:${env.PATH || ''}`;
17
+ return env;
18
+ }
19
+
20
+ async function runNodeExec(args, timeoutMs = 30000) {
21
+ const env = resolveEnv();
22
+ return new Promise((resolve) => {
23
+ const proc = spawn('node', args, { env, stdio: ['pipe', 'pipe', 'pipe'] });
24
+ let stdout = '';
25
+ let stderr = '';
26
+ proc.stdout.on('data', (d) => {
27
+ stdout += d.toString();
28
+ });
29
+ proc.stderr.on('data', (d) => {
30
+ stderr += d.toString();
31
+ });
32
+
33
+ const timer = setTimeout(() => {
34
+ proc.kill();
35
+ resolve({ error: 'timed out', exitCode: 124 });
36
+ }, timeoutMs);
37
+
38
+ proc.on('close', (code) => {
39
+ clearTimeout(timer);
40
+ const out = stdout.trim();
41
+ if (out) {
42
+ try {
43
+ resolve({ ...JSON.parse(out), exitCode: code || 0 });
44
+ return;
45
+ } catch {}
46
+ }
47
+ if (code && code !== 0 && !out) {
48
+ resolve({ error: stderr.trim() || `exit code ${code}`, exitCode: code });
49
+ return;
50
+ }
51
+ resolve({ data: out, exitCode: code || 0 });
52
+ });
53
+ });
54
+ }
55
+
56
+ const sessions = new Map();
57
+
58
+ async function getSession(workspaceId, username, timeoutMs) {
59
+ const key = `${workspaceId}:${username}`;
60
+ if (sessions.has(key)) return sessions.get(key);
61
+
62
+ const { ak, sk, securitytoken } = getCredentials();
63
+ const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
64
+
65
+ const WebSocketImpl = await getWebSocketImpl(wsUrl);
66
+
67
+ const { connectHwlinkTerminalSession } = await import(WS_EXEC_INDEX_URL);
68
+ const session = await connectHwlinkTerminalSession({
69
+ url: wsUrl,
70
+ source,
71
+ username,
72
+ timeoutMs,
73
+ WebSocketImpl,
74
+ });
75
+
76
+ sessions.set(key, session);
77
+ return session;
78
+ }
79
+
80
+ export async function execOneShot(workspaceId, command, username, timeoutMs) {
81
+ const { ak, sk, securitytoken } = getCredentials();
82
+ const { wsUrl, source } = await createConnection(workspaceId, ak, sk, securitytoken);
83
+
84
+ const WebSocketImpl = await getWebSocketImpl(wsUrl);
85
+
86
+ const { executeHwlinkCommand } = await import(WS_EXEC_INDEX_URL);
87
+ return await executeHwlinkCommand({
88
+ url: wsUrl,
89
+ source,
90
+ username,
91
+ command,
92
+ timeoutMs,
93
+ WebSocketImpl,
94
+ });
95
+ }
96
+
97
+ export async function execWithSession(workspaceId, command, username, timeoutMs) {
98
+ const session = await getSession(workspaceId, username, timeoutMs);
99
+ return await session.exec(command, { timeoutMs });
100
+ }
101
+
102
+ export const UPLOAD_CHUNK_SIZE = 3072;
103
+
104
+ export function splitBase64Chunks(base64, chunkSize = UPLOAD_CHUNK_SIZE) {
105
+ const chunks = [];
106
+ for (let offset = 0; offset < base64.length; offset += chunkSize) {
107
+ chunks.push(base64.slice(offset, offset + chunkSize));
108
+ }
109
+ return chunks;
110
+ }
111
+
112
+ export async function uploadFileWithSession(workspaceId, localPath, remotePath, username = 'root', timeoutMs = 30000) {
113
+ if (!existsSync(localPath)) {
114
+ throw new Error(`sandbox upload: local file not found: ${localPath}`);
115
+ }
116
+ if (!statSync(localPath).isFile()) {
117
+ throw new Error(`sandbox upload: path is not a regular file: ${localPath}`);
118
+ }
119
+ const content = readFileSync(localPath);
120
+ const base64 = content.toString('base64');
121
+ const expectedMd5 = createHash('md5').update(content).digest('hex');
122
+ const chunks = splitBase64Chunks(base64);
123
+ const tmp = `${remotePath}.b64tmp`;
124
+
125
+ const reset = await execWithSession(workspaceId, `rm -f "${tmp}"`, username, timeoutMs);
126
+ if (reset.exitCode !== 0) {
127
+ throw new Error(`sandbox upload: failed to reset temp file: ${reset.stdout || reset.error || reset.exitCode}`);
128
+ }
129
+
130
+ for (const [i, chunk] of chunks.entries()) {
131
+ const res = await execWithSession(workspaceId, `printf '%s' '${chunk}' >> "${tmp}"`, username, timeoutMs);
132
+ if (res.exitCode !== 0) {
133
+ throw new Error(
134
+ `sandbox upload: failed writing chunk ${i + 1}/${chunks.length}: ${res.stdout || res.error || res.exitCode}`,
135
+ );
136
+ }
137
+ }
138
+
139
+ const decode = await execWithSession(
140
+ workspaceId,
141
+ `base64 -d "${tmp}" > "${remotePath}" && rm -f "${tmp}"`,
142
+ username,
143
+ timeoutMs,
144
+ );
145
+ if (decode.exitCode !== 0) {
146
+ throw new Error(
147
+ `sandbox upload: failed decoding to ${remotePath}: ${decode.stdout || decode.error || decode.exitCode}`,
148
+ );
149
+ }
150
+
151
+ const verify = await execWithSession(workspaceId, `md5sum "${remotePath}"`, username, timeoutMs);
152
+ let md5Verified = false;
153
+ if (verify.exitCode === 0) {
154
+ const remoteMd5 = String(verify.stdout || '')
155
+ .trim()
156
+ .split(/\s+/)[0];
157
+ md5Verified = remoteMd5 === expectedMd5;
158
+ if (!md5Verified) {
159
+ throw new Error(
160
+ `sandbox upload: md5 mismatch for ${remotePath} (expected ${expectedMd5}, got ${remoteMd5 || 'none'})`,
161
+ );
162
+ }
163
+ }
164
+
165
+ return {
166
+ ok: true,
167
+ localPath,
168
+ remotePath,
169
+ bytes: content.length,
170
+ chunks: chunks.length,
171
+ md5: expectedMd5,
172
+ md5Verified,
173
+ };
174
+ }
175
+
176
+ export async function closeSession(workspaceId, username) {
177
+ const key = `${workspaceId}:${username}`;
178
+ const session = sessions.get(key);
179
+ if (!session) return false;
180
+ sessions.delete(key);
181
+ try {
182
+ session.close();
183
+ } catch {}
184
+ return true;
185
+ }
186
+
187
+ export async function closeAllSessions() {
188
+ for (const [key, session] of sessions) {
189
+ sessions.delete(key);
190
+ try {
191
+ session.close();
192
+ } catch {}
193
+ }
194
+ }
195
+
196
+ export { DEFAULT_WORKSPACE_ID, runNodeExec };