huaweicloud-devkit 1.1.10-next.4 → 1.1.11
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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +1 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +1 -7
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/troubleshooting.md +18 -17
- package/plugins/huaweicloud-core/skills/huawei-obs/SKILL.md +17 -16
- package/plugins/huaweicloud-core/skills/huawei-obs/references/common-pitfalls.md +168 -1
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +75 -13
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/fullstack-postgrest.md +149 -0
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/tunnel-persistence.md +121 -0
- package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +13 -9
- package/plugins/huaweicloud-core/src/account-type.mjs +1 -10
- package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +1 -1
- package/plugins/huaweicloud-core/src/auth/credentials.mjs +4 -92
- package/plugins/huaweicloud-core/src/auth/service.mjs +2 -24
- package/plugins/huaweicloud-core/src/hcloud-cli.mjs +4 -43
- package/plugins/huaweicloud-core/src/mcp-config-merge.mjs +1 -1
- package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +1 -1
- package/plugins/huaweicloud-core/src/safety-policy.mjs +7 -3
- package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +6 -28
- package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +75 -12
- package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +396 -9
- package/plugins/huaweicloud-core/src/setup-cli.mjs +9 -91
- package/plugins/huaweicloud-core/src/tools.mjs +260 -5
- package/integrations/opencode/package-lock.json +0 -24
- package/integrations/opencode/package.json +0 -10
- package/integrations/opencode/plugins/huaweicloud-devkit.js +0 -194
- package/plugins/huaweicloud-core/src/auth/token-exchange.mjs +0 -100
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// huaweicloud-devkit OpenCode native plugin
|
|
2
|
-
//
|
|
3
|
-
// Bridges all 42 MCP tools into OpenCode in-process custom tools via the shared
|
|
4
|
-
// callTool() business layer, plus:
|
|
5
|
-
// - tool.execute.before safety gate (classifyHcloudArgs / classifyTextCommand)
|
|
6
|
-
// - skill-tracker telemetry (superset of the legacy skill-tracker.js plugin)
|
|
7
|
-
// - STS command-level injection is inherited from callTool -> runHcloud chain
|
|
8
|
-
//
|
|
9
|
-
// Install: npm i -g huaweicloud-devkit && npx huaweicloud-devkit install --target opencode
|
|
10
|
-
// (this file is copied to ~/.config/opencode/plugins/huaweicloud-devkit.js and
|
|
11
|
-
// auto-loaded by OpenCode at startup — local plugins need no config entry)
|
|
12
|
-
//
|
|
13
|
-
// Compatibility contract (unchanged from MCP mode):
|
|
14
|
-
// - tool names stay `huaweicloud_*` (skills/hook matchers keep working)
|
|
15
|
-
// - approval gate: run_approved_command still requires args+approvalToken+approvedByUser
|
|
16
|
-
// - credentials: resolveCredentials reads env (HW_*) then S1 — same priority as MCP
|
|
17
|
-
|
|
18
|
-
import { appendFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
19
|
-
import { join, dirname } from 'node:path';
|
|
20
|
-
import { fileURLToPath } from 'node:url';
|
|
21
|
-
import { createRequire } from 'node:module';
|
|
22
|
-
|
|
23
|
-
const require = createRequire(import.meta.url);
|
|
24
|
-
const z = require('zod');
|
|
25
|
-
|
|
26
|
-
// devkit core — resolved from the installed plugin tree next to this file
|
|
27
|
-
const selfDir = dirname(fileURLToPath(import.meta.url));
|
|
28
|
-
const DEVKIT_SRC = join(selfDir, '..', 'huaweicloud-plugins', 'src');
|
|
29
|
-
|
|
30
|
-
let devkit = null;
|
|
31
|
-
let loadError = null;
|
|
32
|
-
try {
|
|
33
|
-
devkit = await import(`file://${join(DEVKIT_SRC, 'tools.mjs')}`);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
loadError = error;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ── telemetry (superset of legacy skill-tracker.js) ─────────────────────────
|
|
39
|
-
|
|
40
|
-
const TELEMETRY_DIR = join(DEVKIT_SRC, '..', 'telemetry');
|
|
41
|
-
function writeEvent(key, value, extra = {}) {
|
|
42
|
-
try {
|
|
43
|
-
if (!existsSync(TELEMETRY_DIR)) mkdirSync(TELEMETRY_DIR, { recursive: true });
|
|
44
|
-
appendFileSync(join(TELEMETRY_DIR, 'hook-events.jsonl'), JSON.stringify({ key, value, ...extra }) + '\n');
|
|
45
|
-
} catch {
|
|
46
|
-
/* telemetry must never break the host */
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function isHuaweiCloudSkill(name) {
|
|
51
|
-
return typeof name === 'string' && /^huawei/i.test(name);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// ── JSON Schema -> Zod converter (covers the devkit inputSchema subset) ─────
|
|
55
|
-
|
|
56
|
-
function jsonSchemaToZod(schema) {
|
|
57
|
-
// schema is { type:'object', properties:{...}, required:[...] }
|
|
58
|
-
const shape = {};
|
|
59
|
-
const required = new Set(schema?.required || []);
|
|
60
|
-
for (const [name, prop] of Object.entries(schema?.properties || {})) {
|
|
61
|
-
let node;
|
|
62
|
-
switch (prop?.type) {
|
|
63
|
-
case 'string':
|
|
64
|
-
node = z.string();
|
|
65
|
-
if (prop.enum) {
|
|
66
|
-
const vals = prop.enum.filter((v) => typeof v === 'string');
|
|
67
|
-
if (vals.length > 0) node = z.enum(vals);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
case 'number':
|
|
71
|
-
case 'integer':
|
|
72
|
-
node = z.number();
|
|
73
|
-
break;
|
|
74
|
-
case 'boolean':
|
|
75
|
-
node = z.boolean();
|
|
76
|
-
break;
|
|
77
|
-
case 'array':
|
|
78
|
-
node = z.array(z.any());
|
|
79
|
-
break;
|
|
80
|
-
case 'object':
|
|
81
|
-
default:
|
|
82
|
-
node = z.any(); // nested objects (e.g. git{repo_url}) stay permissive
|
|
83
|
-
}
|
|
84
|
-
if (prop?.description) node = node.describe(prop.description);
|
|
85
|
-
shape[name] = required.has(name) ? node : node.optional();
|
|
86
|
-
}
|
|
87
|
-
return shape;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ── safety gate (mirrors the MCP/hook deny semantics) ──────────────────────
|
|
91
|
-
|
|
92
|
-
const DENY_TOOLS = new Set([
|
|
93
|
-
'huaweicloud_run_approved_command', // has its own in-tool approval gate (token check)
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
async function safetyGate(toolName, args) {
|
|
97
|
-
if (!devkit) return; // devkit failed to load -> tools absent, nothing to gate
|
|
98
|
-
// read-only and planning tools pass through: callTool re-runs the full policy
|
|
99
|
-
// layer anyway (classifyHcloudArgs inside plan/read paths). The gate below is
|
|
100
|
-
// a fast pre-check for the raw hcloud-ish tools only.
|
|
101
|
-
if (DENY_TOOLS.has(toolName)) return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// ── tool bridging ───────────────────────────────────────────────────────────
|
|
105
|
-
|
|
106
|
-
function buildBridgedTools() {
|
|
107
|
-
if (!devkit) return {};
|
|
108
|
-
const tools = {};
|
|
109
|
-
const definitions = devkit.TOOL_DEFINITIONS || [];
|
|
110
|
-
for (const def of definitions) {
|
|
111
|
-
tools[def.name] = {
|
|
112
|
-
description: def.description,
|
|
113
|
-
args: jsonSchemaToZod(def.inputSchema || { type: 'object', properties: {} }),
|
|
114
|
-
async execute(args, context) {
|
|
115
|
-
const started = Date.now();
|
|
116
|
-
try {
|
|
117
|
-
await safetyGate(def.name, args);
|
|
118
|
-
const result = await devkit.callTool(def.name, args, { cwd: context?.directory });
|
|
119
|
-
writeEvent('tool:invoke', def.name, { durationMs: Date.now() - started });
|
|
120
|
-
return typeof result === 'string' ? result : { output: JSON.stringify(result, null, 2) };
|
|
121
|
-
} catch (error) {
|
|
122
|
-
// crash containment: never take the host down with a tool error
|
|
123
|
-
const payload = {
|
|
124
|
-
error: error?.message || String(error),
|
|
125
|
-
code: error?.code,
|
|
126
|
-
action: error?.action || error?.nextStep,
|
|
127
|
-
};
|
|
128
|
-
writeEvent('tool:error', def.name, { message: payload.error });
|
|
129
|
-
return { output: JSON.stringify(payload, null, 2) };
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
return tools;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// ── plugin export (v1 Hooks contract, IDE + CLI dual form) ─────────────────
|
|
138
|
-
|
|
139
|
-
function getHooks() {
|
|
140
|
-
return {
|
|
141
|
-
'tool.execute.before': function (input, output) {
|
|
142
|
-
try {
|
|
143
|
-
if (input?.tool === 'skill') {
|
|
144
|
-
const name = output?.args?.name;
|
|
145
|
-
if (isHuaweiCloudSkill(name)) writeEvent('skill:retrieve', name);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (input?.tool === 'bash') {
|
|
149
|
-
const cmd = output?.args?.command || '';
|
|
150
|
-
if (!cmd) return;
|
|
151
|
-
// CLI read/write classification (legacy skill-tracker behavior)
|
|
152
|
-
const isHcloud = /(?:^|[;&|]\s*)hcloud(?:\.exe)?\s+/i.test(cmd);
|
|
153
|
-
if (isHcloud) {
|
|
154
|
-
const isRead = /\b(List|Show|Get|Describe|NovaList|NovaShow)\w*/i.test(cmd);
|
|
155
|
-
writeEvent(isRead ? 'cli:read' : 'cli:write', cmd.slice(0, 120), { capability: 'cli' });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} catch {
|
|
159
|
-
/* hooks must never throw */
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
event: function ({ event }) {
|
|
163
|
-
try {
|
|
164
|
-
if (event?.type === 'message.part.updated') {
|
|
165
|
-
const text = event?.properties?.part?.text;
|
|
166
|
-
if (typeof text === 'string') {
|
|
167
|
-
const m = text.match(/Base directory for this skill:\s*.*?skills[/\\]([a-z0-9-]+)/i);
|
|
168
|
-
if (m && isHuaweiCloudSkill(m[1])) writeEvent('skill:retrieve', m[1]);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
} catch {
|
|
172
|
-
/* ignore */
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function plugin() {
|
|
179
|
-
const hooks = getHooks();
|
|
180
|
-
if (loadError) {
|
|
181
|
-
// Surface a single actionable line instead of breaking startup
|
|
182
|
-
console.error(`[huaweicloud-devkit] core failed to load: ${loadError.message}`);
|
|
183
|
-
console.error(`[huaweicloud-devkit] expected devkit src at ${DEVKIT_SRC}`);
|
|
184
|
-
console.error(`[huaweicloud-devkit] run: npx huaweicloud-devkit install --target opencode`);
|
|
185
|
-
return hooks; // telemetry still works; tools absent until install is re-run
|
|
186
|
-
}
|
|
187
|
-
hooks.tool = buildBridgedTools();
|
|
188
|
-
return hooks;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
plugin.id = 'huaweicloud-devkit';
|
|
192
|
-
plugin.server = async () => plugin();
|
|
193
|
-
|
|
194
|
-
export default plugin;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { fetchWithProxy } from '../proxy/proxy-agent.mjs';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_DURATION_SECONDS = 900;
|
|
4
|
-
const DEFAULT_IAM_ENDPOINT = 'https://iam.myhuaweicloud.com';
|
|
5
|
-
|
|
6
|
-
export async function exchangeTokenForCredentials(token, options = {}) {
|
|
7
|
-
const durationSeconds = options.durationSeconds ?? DEFAULT_DURATION_SECONDS;
|
|
8
|
-
const iamEndpoint = options.iamEndpoint || process.env.HW_TOKEN_IAM_ENDPOINT || DEFAULT_IAM_ENDPOINT;
|
|
9
|
-
const fetchImpl = options.fetchImpl;
|
|
10
|
-
|
|
11
|
-
const body = {
|
|
12
|
-
auth: {
|
|
13
|
-
identity: {
|
|
14
|
-
methods: ['token'],
|
|
15
|
-
token: { id: token, duration_seconds: durationSeconds },
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const fetchOpts = {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: { 'Content-Type': 'application/json;charset=utf8' },
|
|
23
|
-
body: JSON.stringify(body),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const url = `${iamEndpoint}/v3.0/OS-CREDENTIAL/securitytokens`;
|
|
27
|
-
|
|
28
|
-
let resp;
|
|
29
|
-
try {
|
|
30
|
-
resp = fetchImpl ? await fetchImpl(url, fetchOpts) : await fetchWithProxy(url, fetchOpts);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
const err = new Error(`Token exchange request failed: ${error.message}`);
|
|
33
|
-
err.code = 'TOKEN_EXCHANGE_FAILED';
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (resp.status === 401 || resp.status === 403) {
|
|
38
|
-
const err = new Error('X-Auth-Token is invalid or expired.');
|
|
39
|
-
err.code = 'TOKEN_INVALID';
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
if (resp.status !== 201) {
|
|
43
|
-
const err = new Error(`Token exchange returned unexpected status ${resp.status}.`);
|
|
44
|
-
err.code = 'TOKEN_EXCHANGE_FAILED';
|
|
45
|
-
throw err;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let data;
|
|
49
|
-
try {
|
|
50
|
-
data = await resp.json();
|
|
51
|
-
} catch (error) {
|
|
52
|
-
const err = new Error(`Token exchange returned malformed JSON: ${error.message}`);
|
|
53
|
-
err.code = 'TOKEN_EXCHANGE_FAILED';
|
|
54
|
-
throw err;
|
|
55
|
-
}
|
|
56
|
-
const cred = data?.credential;
|
|
57
|
-
if (!cred?.access || !cred?.secret || !cred?.securitytoken) {
|
|
58
|
-
const err = new Error('Token exchange response missing credential fields.');
|
|
59
|
-
err.code = 'TOKEN_EXCHANGE_FAILED';
|
|
60
|
-
throw err;
|
|
61
|
-
}
|
|
62
|
-
// IAM always returns expires_at; if it is absent (or unparseable) we store
|
|
63
|
-
// expiresAt:null, which never satisfies the `cached.expiresAt && …` guard in
|
|
64
|
-
// getTokenCredentials — so the cache is always a miss and we deliberately
|
|
65
|
-
// re-exchange on every call rather than risk caching credentials forever.
|
|
66
|
-
const expiresAt = cred.expires_at ? Date.parse(cred.expires_at) : NaN;
|
|
67
|
-
return {
|
|
68
|
-
ak: cred.access,
|
|
69
|
-
sk: cred.secret,
|
|
70
|
-
securityToken: cred.securitytoken,
|
|
71
|
-
expiresAt: Number.isFinite(expiresAt) ? expiresAt : null,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const GRACE_MS = 60 * 1000;
|
|
76
|
-
|
|
77
|
-
let cached = null; // { ak, sk, securityToken, expiresAt }
|
|
78
|
-
let inflight = null; // Promise 单飞
|
|
79
|
-
|
|
80
|
-
export function __resetTokenCache() {
|
|
81
|
-
cached = null;
|
|
82
|
-
inflight = null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export async function getTokenCredentials(token, options = {}) {
|
|
86
|
-
const now = Date.now();
|
|
87
|
-
if (cached && cached.expiresAt && cached.expiresAt - GRACE_MS > now) {
|
|
88
|
-
return cached;
|
|
89
|
-
}
|
|
90
|
-
if (inflight) return inflight;
|
|
91
|
-
inflight = (async () => {
|
|
92
|
-
try {
|
|
93
|
-
cached = await exchangeTokenForCredentials(token, options);
|
|
94
|
-
return cached;
|
|
95
|
-
} finally {
|
|
96
|
-
inflight = null;
|
|
97
|
-
}
|
|
98
|
-
})();
|
|
99
|
-
return inflight;
|
|
100
|
-
}
|