huaweicloud-devkit 2.0.0-next.4 → 2.0.0-next.6
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/integrations/opencode/commands/huaweicloud-doctor.md +1 -1
- package/integrations/opencode/hooks/safety-gate.js +235 -0
- package/package.json +1 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +3 -16
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +29 -4
- package/plugins/huaweicloud-core/dist/agents/opencode.js +55 -14
- package/plugins/huaweicloud-core/dist/approval-gate.js +23 -5
- package/plugins/huaweicloud-core/dist/doctor-payload.js +29 -0
- package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +6 -1
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +18 -9
- package/plugins/huaweicloud-core/dist/lib/opencode-permission-seam.js +51 -20
- package/plugins/huaweicloud-core/dist/mcp-server.js +520 -290
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +5 -1
- package/plugins/huaweicloud-core/dist/packs/registry.js +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +25 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +28 -3
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +14 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +11 -3
- package/plugins/huaweicloud-core/dist/payload-placement.js +8 -0
- package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
- package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
- package/plugins/huaweicloud-core/dist/safety/classify-text.js +10 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +12 -0
- package/plugins/huaweicloud-core/dist/safety/protected-payload.js +93 -0
- package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
- package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
- package/plugins/huaweicloud-core/dist/safety-integrity.js +122 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +1 -1
- package/plugins/huaweicloud-core/dist/setup-cli.js +8 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +44 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +75 -2
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +5 -0
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +1 -1
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +42 -39
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +1 -1
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +33 -3
- package/plugins/huaweicloud-core/src/agents/opencode.ts +66 -15
- package/plugins/huaweicloud-core/src/approval-gate.ts +29 -4
- package/plugins/huaweicloud-core/src/doctor-payload.ts +40 -2
- package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +6 -1
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +32 -1
- package/plugins/huaweicloud-core/src/lib/opencode-permission-seam.ts +60 -19
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +7 -1
- package/plugins/huaweicloud-core/src/packs/registry.ts +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +28 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -15
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +20 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +12 -2
- package/plugins/huaweicloud-core/src/payload-placement.ts +8 -0
- package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
- package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
- package/plugins/huaweicloud-core/src/safety/classify-text.ts +10 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +13 -0
- package/plugins/huaweicloud-core/src/safety/protected-payload.ts +97 -0
- package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
- package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
- package/plugins/huaweicloud-core/src/safety-integrity.ts +132 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +7 -5
- package/plugins/huaweicloud-core/src/setup-cli.ts +8 -0
- package/plugins/huaweicloud-core/src/tool-definitions.ts +4 -0
|
@@ -27993,9 +27993,9 @@ var init_protocol = __esm({
|
|
|
27993
27993
|
});
|
|
27994
27994
|
this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
|
|
27995
27995
|
try {
|
|
27996
|
-
const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
|
|
27996
|
+
const { tasks: tasks2, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
|
|
27997
27997
|
return {
|
|
27998
|
-
tasks,
|
|
27998
|
+
tasks: tasks2,
|
|
27999
27999
|
nextCursor,
|
|
28000
28000
|
_meta: {}
|
|
28001
28001
|
};
|
|
@@ -43477,228 +43477,6 @@ var init_as_record = __esm({
|
|
|
43477
43477
|
}
|
|
43478
43478
|
});
|
|
43479
43479
|
|
|
43480
|
-
// plugins/huaweicloud-core/dist.new/risk-rule-engine.js
|
|
43481
|
-
import { readFileSync } from "node:fs";
|
|
43482
|
-
import { dirname, join } from "node:path";
|
|
43483
|
-
import { fileURLToPath } from "node:url";
|
|
43484
|
-
function toSeverity(value) {
|
|
43485
|
-
return value === "deny" || value === "warn" || value === "info" ? value : "info";
|
|
43486
|
-
}
|
|
43487
|
-
function toCondition(value) {
|
|
43488
|
-
const raw = asRecord(value);
|
|
43489
|
-
return {
|
|
43490
|
-
field: typeof raw.field === "string" ? raw.field : void 0,
|
|
43491
|
-
regex: typeof raw.regex === "string" ? raw.regex : ""
|
|
43492
|
-
};
|
|
43493
|
-
}
|
|
43494
|
-
function toConditionList(value) {
|
|
43495
|
-
return Array.isArray(value) ? value.map((condition) => toCondition(condition)) : void 0;
|
|
43496
|
-
}
|
|
43497
|
-
function toMatch(value) {
|
|
43498
|
-
const raw = asRecord(value);
|
|
43499
|
-
return {
|
|
43500
|
-
all: toConditionList(raw.all),
|
|
43501
|
-
any: toConditionList(raw.any),
|
|
43502
|
-
none: toConditionList(raw.none)
|
|
43503
|
-
};
|
|
43504
|
-
}
|
|
43505
|
-
function toRule(value) {
|
|
43506
|
-
const raw = asRecord(value);
|
|
43507
|
-
return {
|
|
43508
|
-
id: typeof raw.id === "string" ? raw.id : "",
|
|
43509
|
-
title: typeof raw.title === "string" ? raw.title : "",
|
|
43510
|
-
category: typeof raw.category === "string" ? raw.category : "",
|
|
43511
|
-
severity: toSeverity(raw.severity),
|
|
43512
|
-
stages: Array.isArray(raw.stages) ? raw.stages.filter((stage) => typeof stage === "string") : [],
|
|
43513
|
-
match: toMatch(raw.match),
|
|
43514
|
-
message: typeof raw.message === "string" ? raw.message : "",
|
|
43515
|
-
remediation: typeof raw.remediation === "string" ? raw.remediation : ""
|
|
43516
|
-
};
|
|
43517
|
-
}
|
|
43518
|
-
function toCatalog(value) {
|
|
43519
|
-
const raw = asRecord(value);
|
|
43520
|
-
return {
|
|
43521
|
-
version: typeof raw.version === "string" ? raw.version : void 0,
|
|
43522
|
-
rules: Array.isArray(raw.rules) ? raw.rules.map((rule) => toRule(rule)) : []
|
|
43523
|
-
};
|
|
43524
|
-
}
|
|
43525
|
-
function loadRiskRules(options = {}) {
|
|
43526
|
-
const path = options.path || defaultRulesPath;
|
|
43527
|
-
return toCatalog(JSON.parse(readFileSync(path, "utf8")));
|
|
43528
|
-
}
|
|
43529
|
-
function redactEvidence(text) {
|
|
43530
|
-
return String(text).replace(/((?:access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|secret(?!:\/)|security[_-]?token|x[_-]?auth[_-]?token|token|authorization|password|passwd|admin[_-]?pass|credential)\\*["']?\s*[:=]\s*[\\"'\\]*\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi, "$1<redacted>").replace(/\b(AK|SK)\\*["']?\s*[:=]\s*("[^"]*"|'[^']*'|[^\s,;]+)/gi, "$1=<redacted>");
|
|
43531
|
-
}
|
|
43532
|
-
function normalizeText(value) {
|
|
43533
|
-
if (typeof value === "string")
|
|
43534
|
-
return value;
|
|
43535
|
-
return JSON.stringify(value, null, 2);
|
|
43536
|
-
}
|
|
43537
|
-
function evaluationContext(stage, input2) {
|
|
43538
|
-
const record2 = asRecord(input2);
|
|
43539
|
-
if (stage === "command") {
|
|
43540
|
-
const command = normalizeText(record2.command || record2.text || "");
|
|
43541
|
-
return { text: command, command };
|
|
43542
|
-
}
|
|
43543
|
-
if (stage === "artifact") {
|
|
43544
|
-
const path = asText(record2.path || "");
|
|
43545
|
-
const content = normalizeText(record2.content || "");
|
|
43546
|
-
return { text: `${path}
|
|
43547
|
-
${content}`, path, content };
|
|
43548
|
-
}
|
|
43549
|
-
if (stage === "deploy_plan") {
|
|
43550
|
-
const plan = normalizeText(record2.plan || record2.text || input2);
|
|
43551
|
-
return { text: plan, plan };
|
|
43552
|
-
}
|
|
43553
|
-
return { text: normalizeText(input2) };
|
|
43554
|
-
}
|
|
43555
|
-
function conditionMatches(condition, context) {
|
|
43556
|
-
const field = condition.field || "text";
|
|
43557
|
-
const value = Object.hasOwn(context, field) ? context[field] : context.text;
|
|
43558
|
-
return new RegExp(condition.regex, "ims").test(String(value || ""));
|
|
43559
|
-
}
|
|
43560
|
-
function ruleMatches(rule, context) {
|
|
43561
|
-
const match = rule.match || {};
|
|
43562
|
-
const all = match.all;
|
|
43563
|
-
const any2 = match.any;
|
|
43564
|
-
const none = match.none;
|
|
43565
|
-
if (Array.isArray(all) && !all.every((condition) => conditionMatches(condition, context))) {
|
|
43566
|
-
return false;
|
|
43567
|
-
}
|
|
43568
|
-
if (Array.isArray(any2) && !any2.some((condition) => conditionMatches(condition, context))) {
|
|
43569
|
-
return false;
|
|
43570
|
-
}
|
|
43571
|
-
if (Array.isArray(none) && none.some((condition) => conditionMatches(condition, context))) {
|
|
43572
|
-
return false;
|
|
43573
|
-
}
|
|
43574
|
-
return Array.isArray(all) || Array.isArray(any2);
|
|
43575
|
-
}
|
|
43576
|
-
function excerpt(text) {
|
|
43577
|
-
const compact = redactEvidence(String(text).replace(/\s+/g, " ").trim());
|
|
43578
|
-
if (compact.length <= 240)
|
|
43579
|
-
return compact;
|
|
43580
|
-
return `${compact.slice(0, 237)}...`;
|
|
43581
|
-
}
|
|
43582
|
-
function inputPath(input2) {
|
|
43583
|
-
if (input2 === null || typeof input2 !== "object")
|
|
43584
|
-
return void 0;
|
|
43585
|
-
const path = input2.path;
|
|
43586
|
-
return typeof path === "string" ? path : void 0;
|
|
43587
|
-
}
|
|
43588
|
-
function evaluate(stage, inputs, options = {}) {
|
|
43589
|
-
const catalog = options.catalog || loadRiskRules(options);
|
|
43590
|
-
const items = Array.isArray(inputs) ? inputs : [inputs];
|
|
43591
|
-
const findings = [];
|
|
43592
|
-
for (const input2 of items) {
|
|
43593
|
-
const context = evaluationContext(stage, input2 || {});
|
|
43594
|
-
for (const rule of catalog.rules) {
|
|
43595
|
-
if (!rule.stages.includes(stage))
|
|
43596
|
-
continue;
|
|
43597
|
-
if (!ruleMatches(rule, context))
|
|
43598
|
-
continue;
|
|
43599
|
-
findings.push({
|
|
43600
|
-
ruleId: rule.id,
|
|
43601
|
-
title: rule.title,
|
|
43602
|
-
category: rule.category,
|
|
43603
|
-
severity: rule.severity,
|
|
43604
|
-
message: rule.message,
|
|
43605
|
-
remediation: rule.remediation,
|
|
43606
|
-
source: inputPath(input2) || stage,
|
|
43607
|
-
evidence: excerpt(context.text)
|
|
43608
|
-
});
|
|
43609
|
-
}
|
|
43610
|
-
}
|
|
43611
|
-
findings.sort((a, b) => SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity]);
|
|
43612
|
-
const hasDeny = findings.some((finding) => finding.severity === "deny");
|
|
43613
|
-
const hasWarn = findings.some((finding) => finding.severity === "warn");
|
|
43614
|
-
return {
|
|
43615
|
-
decision: hasDeny ? "deny" : hasWarn ? "warn" : "allow",
|
|
43616
|
-
findings
|
|
43617
|
-
};
|
|
43618
|
-
}
|
|
43619
|
-
function isNonEmptyString(value) {
|
|
43620
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
43621
|
-
}
|
|
43622
|
-
function isNonEmptyContainer(value) {
|
|
43623
|
-
if (Array.isArray(value))
|
|
43624
|
-
return value.length > 0;
|
|
43625
|
-
if (value && typeof value === "object")
|
|
43626
|
-
return Object.keys(value).length > 0;
|
|
43627
|
-
return false;
|
|
43628
|
-
}
|
|
43629
|
-
function invalidRiskResult(stage, reason) {
|
|
43630
|
-
return {
|
|
43631
|
-
decision: "deny",
|
|
43632
|
-
risk: "invalid",
|
|
43633
|
-
findings: [
|
|
43634
|
-
{
|
|
43635
|
-
ruleId: "invalid-input",
|
|
43636
|
-
title: "Invalid input for risk check",
|
|
43637
|
-
category: "invalid",
|
|
43638
|
-
severity: "deny",
|
|
43639
|
-
message: reason,
|
|
43640
|
-
remediation: "Provide a valid, non-empty input before re-running the check.",
|
|
43641
|
-
source: stage,
|
|
43642
|
-
evidence: ""
|
|
43643
|
-
}
|
|
43644
|
-
]
|
|
43645
|
-
};
|
|
43646
|
-
}
|
|
43647
|
-
function evaluateCommandRisk(command, options = {}) {
|
|
43648
|
-
if (!isNonEmptyString(command)) {
|
|
43649
|
-
return invalidRiskResult("command", "command must be a non-empty string.");
|
|
43650
|
-
}
|
|
43651
|
-
return evaluate("command", { command }, options);
|
|
43652
|
-
}
|
|
43653
|
-
function evaluateArtifacts(artifacts, options = {}) {
|
|
43654
|
-
if (!Array.isArray(artifacts) || artifacts.length === 0) {
|
|
43655
|
-
return invalidRiskResult("artifact", "artifacts must be a non-empty array.");
|
|
43656
|
-
}
|
|
43657
|
-
return evaluate("artifact", artifacts, options);
|
|
43658
|
-
}
|
|
43659
|
-
function evaluateDeployPlan(plan, options = {}) {
|
|
43660
|
-
const valid = isNonEmptyString(plan) || plan != null && typeof plan === "object" && isNonEmptyContainer(plan);
|
|
43661
|
-
if (!valid) {
|
|
43662
|
-
return invalidRiskResult("deploy_plan", "plan must be a non-empty object, array, or string.");
|
|
43663
|
-
}
|
|
43664
|
-
return evaluate("deploy_plan", { plan }, options);
|
|
43665
|
-
}
|
|
43666
|
-
function mergeRiskDecision(base, risk) {
|
|
43667
|
-
if (!risk || !risk.findings?.length)
|
|
43668
|
-
return base;
|
|
43669
|
-
if (risk.decision === "deny") {
|
|
43670
|
-
const topFinding = risk.findings[0];
|
|
43671
|
-
const reason = topFinding.remediation ? `${topFinding.message} Remediation: ${topFinding.remediation}` : topFinding.message;
|
|
43672
|
-
return {
|
|
43673
|
-
...base,
|
|
43674
|
-
decision: "deny",
|
|
43675
|
-
risk: topFinding.category,
|
|
43676
|
-
reason,
|
|
43677
|
-
blockedByRiskRule: true,
|
|
43678
|
-
findings: risk.findings
|
|
43679
|
-
};
|
|
43680
|
-
}
|
|
43681
|
-
return {
|
|
43682
|
-
...base,
|
|
43683
|
-
warnings: [...base.warnings || [], ...risk.findings]
|
|
43684
|
-
};
|
|
43685
|
-
}
|
|
43686
|
-
var __dirname, defaultRulesPath, SEVERITY_RANK;
|
|
43687
|
-
var init_risk_rule_engine = __esm({
|
|
43688
|
-
"plugins/huaweicloud-core/dist.new/risk-rule-engine.js"() {
|
|
43689
|
-
"use strict";
|
|
43690
|
-
init_as_text();
|
|
43691
|
-
init_as_record();
|
|
43692
|
-
__dirname = dirname(fileURLToPath(import.meta.url));
|
|
43693
|
-
defaultRulesPath = join(__dirname, "..", "safety", "rules", "cloud-risk-rules.json");
|
|
43694
|
-
SEVERITY_RANK = {
|
|
43695
|
-
deny: 3,
|
|
43696
|
-
warn: 2,
|
|
43697
|
-
info: 1
|
|
43698
|
-
};
|
|
43699
|
-
}
|
|
43700
|
-
});
|
|
43701
|
-
|
|
43702
43480
|
// plugins/huaweicloud-core/dist.new/safety/heredoc.js
|
|
43703
43481
|
function scanHeredocStart(text, i, separators) {
|
|
43704
43482
|
const prev = i === 0 ? "" : text[i - 1];
|
|
@@ -44082,7 +43860,7 @@ var init_shell_text = __esm({
|
|
|
44082
43860
|
});
|
|
44083
43861
|
|
|
44084
43862
|
// plugins/huaweicloud-core/dist.new/safety/policy.js
|
|
44085
|
-
import { readFileSync
|
|
43863
|
+
import { readFileSync } from "node:fs";
|
|
44086
43864
|
function toStringArray(value, field) {
|
|
44087
43865
|
if (value === void 0)
|
|
44088
43866
|
return [];
|
|
@@ -44092,7 +43870,7 @@ function toStringArray(value, field) {
|
|
|
44092
43870
|
return value.filter((item) => typeof item === "string");
|
|
44093
43871
|
}
|
|
44094
43872
|
function loadPolicy(path) {
|
|
44095
|
-
const parsed = JSON.parse(
|
|
43873
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
44096
43874
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
44097
43875
|
throw new TypeError("safety policy must be a JSON object");
|
|
44098
43876
|
}
|
|
@@ -44101,9 +43879,14 @@ function loadPolicy(path) {
|
|
|
44101
43879
|
if (raw.writeOperationPrefixes !== void 0 && writeOperationPrefixes.length === 0) {
|
|
44102
43880
|
throw new TypeError('safety policy field "writeOperationPrefixes" must not be empty');
|
|
44103
43881
|
}
|
|
43882
|
+
const protectedPayloadPathMarkers = toStringArray(raw.protectedPayloadPathMarkers, "protectedPayloadPathMarkers");
|
|
43883
|
+
if (raw.protectedPayloadPathMarkers !== void 0 && protectedPayloadPathMarkers.length === 0) {
|
|
43884
|
+
throw new TypeError('safety policy field "protectedPayloadPathMarkers" must not be empty');
|
|
43885
|
+
}
|
|
44104
43886
|
return {
|
|
44105
43887
|
secretKeyNamePatterns: toStringArray(raw.secretKeyNamePatterns, "secretKeyNamePatterns"),
|
|
44106
43888
|
credentialFilePatterns: toStringArray(raw.credentialFilePatterns, "credentialFilePatterns"),
|
|
43889
|
+
protectedPayloadPathMarkers,
|
|
44107
43890
|
blockedConfigureSubcommands: toStringArray(raw.blockedConfigureSubcommands, "blockedConfigureSubcommands"),
|
|
44108
43891
|
blockedSecretOperations: toStringArray(raw.blockedSecretOperations, "blockedSecretOperations"),
|
|
44109
43892
|
blockedSecretCliPatterns: toStringArray(raw.blockedSecretCliPatterns, "blockedSecretCliPatterns"),
|
|
@@ -44138,17 +43921,17 @@ var init_policy = __esm({
|
|
|
44138
43921
|
|
|
44139
43922
|
// plugins/huaweicloud-core/dist.new/safety/default-policy.js
|
|
44140
43923
|
import { existsSync } from "node:fs";
|
|
44141
|
-
import { dirname
|
|
44142
|
-
import { fileURLToPath
|
|
43924
|
+
import { dirname, join } from "node:path";
|
|
43925
|
+
import { fileURLToPath } from "node:url";
|
|
44143
43926
|
function pluginRootDir(startDir) {
|
|
44144
|
-
for (const candidate of [
|
|
44145
|
-
if (existsSync(
|
|
43927
|
+
for (const candidate of [join(startDir, ".."), join(startDir, "..", "..")]) {
|
|
43928
|
+
if (existsSync(join(candidate, "safety", "policy.json")))
|
|
44146
43929
|
return candidate;
|
|
44147
43930
|
}
|
|
44148
|
-
return
|
|
43931
|
+
return join(startDir, "..", "..");
|
|
44149
43932
|
}
|
|
44150
43933
|
function defaultPolicyPath() {
|
|
44151
|
-
return
|
|
43934
|
+
return join(pluginRootDir(dirname(fileURLToPath(import.meta.url))), "safety", "policy.json");
|
|
44152
43935
|
}
|
|
44153
43936
|
function loadPolicy2(path = defaultPolicyPath()) {
|
|
44154
43937
|
return loadPolicy(path);
|
|
@@ -44162,40 +43945,19 @@ var init_default_policy = __esm({
|
|
|
44162
43945
|
}
|
|
44163
43946
|
});
|
|
44164
43947
|
|
|
44165
|
-
// plugins/huaweicloud-core/dist.new/safety/vocabulary.js
|
|
44166
|
-
function deriveSecretOperationAlternation(ops) {
|
|
44167
|
-
const entries = ops.filter((op) => op !== "");
|
|
44168
|
-
if (entries.length === 0)
|
|
44169
|
-
return "(?!)";
|
|
44170
|
-
return entries.map((op) => {
|
|
44171
|
-
const l = op.toLowerCase();
|
|
44172
|
-
const isStem = entries.some((other) => other !== op && other.toLowerCase().startsWith(l));
|
|
44173
|
-
const escaped = l.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
44174
|
-
return isStem ? `(?<![A-Za-z0-9._/-])${escaped}(?![A-Za-z0-9._/-])` : escaped;
|
|
44175
|
-
}).join("|");
|
|
44176
|
-
}
|
|
44177
|
-
var SECRET_OP_ALTERNATION, SECRET_ARGS_RE, SECRET_TEXT_RE, SECRET_SHADOW_RE;
|
|
44178
|
-
var init_vocabulary = __esm({
|
|
44179
|
-
"plugins/huaweicloud-core/dist.new/safety/vocabulary.js"() {
|
|
44180
|
-
"use strict";
|
|
44181
|
-
init_default_policy();
|
|
44182
|
-
SECRET_OP_ALTERNATION = deriveSecretOperationAlternation(DEFAULT_POLICY.blockedSecretOperations);
|
|
44183
|
-
SECRET_ARGS_RE = new RegExp(`secret[_-]?string|secret[_-]?binary|${SECRET_OP_ALTERNATION}`, "i");
|
|
44184
|
-
SECRET_TEXT_RE = new RegExp(`${SECRET_OP_ALTERNATION}|secret_string|secret_binary`, "i");
|
|
44185
|
-
SECRET_SHADOW_RE = new RegExp(SECRET_OP_ALTERNATION, "i");
|
|
44186
|
-
}
|
|
44187
|
-
});
|
|
44188
|
-
|
|
44189
43948
|
// plugins/huaweicloud-core/dist.new/safety/redact.js
|
|
44190
43949
|
function isSecretKeyName(key, policy = DEFAULT_POLICY) {
|
|
44191
43950
|
const normalized = String(key).toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
44192
|
-
if (/access.*key|secret.*key|security.*token|xauth.*token|authorization|password|passwd|adminpass|credential|private.*key|userdata|metadata|inputvalue/.test(normalized)) {
|
|
43951
|
+
if (/access.*key|secret.*key|secret.*string|secret.*binary|secret.*text|api.*key|security.*token|xauth.*token|authorization|password|passwd|adminpass|credential|private.*key|userdata|metadata|inputvalue/.test(normalized)) {
|
|
44193
43952
|
return true;
|
|
44194
43953
|
}
|
|
44195
43954
|
return policy.secretKeyNamePatterns.some((pattern) => regexFrom(`^(${pattern})$`).test(String(key)));
|
|
44196
43955
|
}
|
|
44197
43956
|
function redactString(text) {
|
|
44198
|
-
return String(text).replace(/(["']?(?:user[_-]?data|metadata|private[_-]?key|authorization|x[_-]?auth[_-]?token)["']?\s*[:=]\s*).*/gi, "$1<redacted>").replace(
|
|
43957
|
+
return String(text).replace(/(["']?(?:user[_-]?data|metadata|private[_-]?key|authorization|x[_-]?auth[_-]?token)["']?\s*[:=]\s*).*/gi, "$1<redacted>").replace(SECRET_KEY_VALUE_RE, "$1<redacted>").replace(/<(password|passwd|pwd)>[^<]*<\/\1>/gi, "<$1><redacted></$1>").replace(/\b(["']?(?:AK|SK)\\*["']?\s*[:=]\s*[\\"']*\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi, "$1<redacted>");
|
|
43958
|
+
}
|
|
43959
|
+
function redactEvidenceText(text) {
|
|
43960
|
+
return redactString(text);
|
|
44199
43961
|
}
|
|
44200
43962
|
function redactSecrets(value, policy = DEFAULT_POLICY) {
|
|
44201
43963
|
if (Array.isArray(value)) {
|
|
@@ -44212,11 +43974,268 @@ function redactSecrets(value, policy = DEFAULT_POLICY) {
|
|
|
44212
43974
|
}
|
|
44213
43975
|
return value;
|
|
44214
43976
|
}
|
|
43977
|
+
var SECRET_KEY_VALUE_RE;
|
|
44215
43978
|
var init_redact = __esm({
|
|
44216
43979
|
"plugins/huaweicloud-core/dist.new/safety/redact.js"() {
|
|
44217
43980
|
"use strict";
|
|
44218
43981
|
init_default_policy();
|
|
44219
43982
|
init_policy();
|
|
43983
|
+
SECRET_KEY_VALUE_RE = /((?:access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|secret[_-]?text|api[_-]?key|secret(?!:\/)|security[_-]?token|x[_-]?auth[_-]?token|token|authorization|password|passwd|admin[_-]?pass|credential|input[_-]?value)\\*["']?\s*[:=]\s*[\\"']*\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi;
|
|
43984
|
+
}
|
|
43985
|
+
});
|
|
43986
|
+
|
|
43987
|
+
// plugins/huaweicloud-core/dist.new/risk-rule-engine.js
|
|
43988
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
43989
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
43990
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
43991
|
+
function toSeverity(value) {
|
|
43992
|
+
return value === "deny" || value === "warn" || value === "info" ? value : "info";
|
|
43993
|
+
}
|
|
43994
|
+
function toCondition(value) {
|
|
43995
|
+
const raw = asRecord(value);
|
|
43996
|
+
return {
|
|
43997
|
+
field: typeof raw.field === "string" ? raw.field : void 0,
|
|
43998
|
+
regex: typeof raw.regex === "string" ? raw.regex : ""
|
|
43999
|
+
};
|
|
44000
|
+
}
|
|
44001
|
+
function toConditionList(value) {
|
|
44002
|
+
return Array.isArray(value) ? value.map((condition) => toCondition(condition)) : void 0;
|
|
44003
|
+
}
|
|
44004
|
+
function toMatch(value) {
|
|
44005
|
+
const raw = asRecord(value);
|
|
44006
|
+
return {
|
|
44007
|
+
all: toConditionList(raw.all),
|
|
44008
|
+
any: toConditionList(raw.any),
|
|
44009
|
+
none: toConditionList(raw.none)
|
|
44010
|
+
};
|
|
44011
|
+
}
|
|
44012
|
+
function toRule(value) {
|
|
44013
|
+
const raw = asRecord(value);
|
|
44014
|
+
return {
|
|
44015
|
+
id: typeof raw.id === "string" ? raw.id : "",
|
|
44016
|
+
title: typeof raw.title === "string" ? raw.title : "",
|
|
44017
|
+
category: typeof raw.category === "string" ? raw.category : "",
|
|
44018
|
+
severity: toSeverity(raw.severity),
|
|
44019
|
+
stages: Array.isArray(raw.stages) ? raw.stages.filter((stage) => typeof stage === "string") : [],
|
|
44020
|
+
match: toMatch(raw.match),
|
|
44021
|
+
message: typeof raw.message === "string" ? raw.message : "",
|
|
44022
|
+
remediation: typeof raw.remediation === "string" ? raw.remediation : ""
|
|
44023
|
+
};
|
|
44024
|
+
}
|
|
44025
|
+
function toCatalog(value) {
|
|
44026
|
+
const raw = asRecord(value);
|
|
44027
|
+
return {
|
|
44028
|
+
version: typeof raw.version === "string" ? raw.version : void 0,
|
|
44029
|
+
rules: Array.isArray(raw.rules) ? raw.rules.map((rule) => toRule(rule)) : []
|
|
44030
|
+
};
|
|
44031
|
+
}
|
|
44032
|
+
function loadRiskRules(options = {}) {
|
|
44033
|
+
const path = options.path || defaultRulesPath;
|
|
44034
|
+
return toCatalog(JSON.parse(readFileSync2(path, "utf8")));
|
|
44035
|
+
}
|
|
44036
|
+
function redactEvidence(text) {
|
|
44037
|
+
return redactEvidenceText(text);
|
|
44038
|
+
}
|
|
44039
|
+
function normalizeText(value) {
|
|
44040
|
+
if (typeof value === "string")
|
|
44041
|
+
return value;
|
|
44042
|
+
return JSON.stringify(value, null, 2);
|
|
44043
|
+
}
|
|
44044
|
+
function evaluationContext(stage, input2) {
|
|
44045
|
+
const record2 = asRecord(input2);
|
|
44046
|
+
if (stage === "command") {
|
|
44047
|
+
const command = normalizeText(record2.command || record2.text || "");
|
|
44048
|
+
return { text: command, command };
|
|
44049
|
+
}
|
|
44050
|
+
if (stage === "artifact") {
|
|
44051
|
+
const path = asText(record2.path || "");
|
|
44052
|
+
const content = normalizeText(record2.content || "");
|
|
44053
|
+
return { text: `${path}
|
|
44054
|
+
${content}`, path, content };
|
|
44055
|
+
}
|
|
44056
|
+
if (stage === "deploy_plan") {
|
|
44057
|
+
const plan = normalizeText(record2.plan || record2.text || input2);
|
|
44058
|
+
return { text: plan, plan };
|
|
44059
|
+
}
|
|
44060
|
+
return { text: normalizeText(input2) };
|
|
44061
|
+
}
|
|
44062
|
+
function normalizeRuleText(text) {
|
|
44063
|
+
return text.replace(/\\+(["'])/g, "$1");
|
|
44064
|
+
}
|
|
44065
|
+
function conditionMatches(condition, context) {
|
|
44066
|
+
const field = condition.field || "text";
|
|
44067
|
+
const value = Object.hasOwn(context, field) ? context[field] : context.text;
|
|
44068
|
+
const raw = String(value || "");
|
|
44069
|
+
const regex = new RegExp(condition.regex, "ims");
|
|
44070
|
+
if (regex.test(raw))
|
|
44071
|
+
return true;
|
|
44072
|
+
const normalized = normalizeRuleText(raw);
|
|
44073
|
+
return normalized !== raw && regex.test(normalized);
|
|
44074
|
+
}
|
|
44075
|
+
function ruleMatches(rule, context) {
|
|
44076
|
+
const match = rule.match || {};
|
|
44077
|
+
const all = match.all;
|
|
44078
|
+
const any2 = match.any;
|
|
44079
|
+
const none = match.none;
|
|
44080
|
+
if (Array.isArray(all) && !all.every((condition) => conditionMatches(condition, context))) {
|
|
44081
|
+
return false;
|
|
44082
|
+
}
|
|
44083
|
+
if (Array.isArray(any2) && !any2.some((condition) => conditionMatches(condition, context))) {
|
|
44084
|
+
return false;
|
|
44085
|
+
}
|
|
44086
|
+
if (Array.isArray(none) && none.some((condition) => conditionMatches(condition, context))) {
|
|
44087
|
+
return false;
|
|
44088
|
+
}
|
|
44089
|
+
return Array.isArray(all) || Array.isArray(any2);
|
|
44090
|
+
}
|
|
44091
|
+
function excerpt(text) {
|
|
44092
|
+
const compact = redactEvidence(String(text).replace(/\s+/g, " ").trim());
|
|
44093
|
+
if (compact.length <= 240)
|
|
44094
|
+
return compact;
|
|
44095
|
+
return `${compact.slice(0, 237)}...`;
|
|
44096
|
+
}
|
|
44097
|
+
function inputPath(input2) {
|
|
44098
|
+
if (input2 === null || typeof input2 !== "object")
|
|
44099
|
+
return void 0;
|
|
44100
|
+
const path = input2.path;
|
|
44101
|
+
return typeof path === "string" ? path : void 0;
|
|
44102
|
+
}
|
|
44103
|
+
function evaluate(stage, inputs, options = {}) {
|
|
44104
|
+
const catalog = options.catalog || loadRiskRules(options);
|
|
44105
|
+
const items = Array.isArray(inputs) ? inputs : [inputs];
|
|
44106
|
+
const findings = [];
|
|
44107
|
+
for (const input2 of items) {
|
|
44108
|
+
const context = evaluationContext(stage, input2 || {});
|
|
44109
|
+
for (const rule of catalog.rules) {
|
|
44110
|
+
if (!rule.stages.includes(stage))
|
|
44111
|
+
continue;
|
|
44112
|
+
if (!ruleMatches(rule, context))
|
|
44113
|
+
continue;
|
|
44114
|
+
findings.push({
|
|
44115
|
+
ruleId: rule.id,
|
|
44116
|
+
title: rule.title,
|
|
44117
|
+
category: rule.category,
|
|
44118
|
+
severity: rule.severity,
|
|
44119
|
+
message: rule.message,
|
|
44120
|
+
remediation: rule.remediation,
|
|
44121
|
+
source: inputPath(input2) || stage,
|
|
44122
|
+
evidence: excerpt(context.text)
|
|
44123
|
+
});
|
|
44124
|
+
}
|
|
44125
|
+
}
|
|
44126
|
+
findings.sort((a, b) => SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity]);
|
|
44127
|
+
const hasDeny = findings.some((finding) => finding.severity === "deny");
|
|
44128
|
+
const hasWarn = findings.some((finding) => finding.severity === "warn");
|
|
44129
|
+
return {
|
|
44130
|
+
decision: hasDeny ? "deny" : hasWarn ? "warn" : "allow",
|
|
44131
|
+
findings
|
|
44132
|
+
};
|
|
44133
|
+
}
|
|
44134
|
+
function isNonEmptyString(value) {
|
|
44135
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
44136
|
+
}
|
|
44137
|
+
function isNonEmptyContainer(value) {
|
|
44138
|
+
if (Array.isArray(value))
|
|
44139
|
+
return value.length > 0;
|
|
44140
|
+
if (value && typeof value === "object")
|
|
44141
|
+
return Object.keys(value).length > 0;
|
|
44142
|
+
return false;
|
|
44143
|
+
}
|
|
44144
|
+
function invalidRiskResult(stage, reason) {
|
|
44145
|
+
return {
|
|
44146
|
+
decision: "deny",
|
|
44147
|
+
risk: "invalid",
|
|
44148
|
+
findings: [
|
|
44149
|
+
{
|
|
44150
|
+
ruleId: "invalid-input",
|
|
44151
|
+
title: "Invalid input for risk check",
|
|
44152
|
+
category: "invalid",
|
|
44153
|
+
severity: "deny",
|
|
44154
|
+
message: reason,
|
|
44155
|
+
remediation: "Provide a valid, non-empty input before re-running the check.",
|
|
44156
|
+
source: stage,
|
|
44157
|
+
evidence: ""
|
|
44158
|
+
}
|
|
44159
|
+
]
|
|
44160
|
+
};
|
|
44161
|
+
}
|
|
44162
|
+
function evaluateCommandRisk(command, options = {}) {
|
|
44163
|
+
if (!isNonEmptyString(command)) {
|
|
44164
|
+
return invalidRiskResult("command", "command must be a non-empty string.");
|
|
44165
|
+
}
|
|
44166
|
+
return evaluate("command", { command }, options);
|
|
44167
|
+
}
|
|
44168
|
+
function evaluateArtifacts(artifacts, options = {}) {
|
|
44169
|
+
if (!Array.isArray(artifacts) || artifacts.length === 0) {
|
|
44170
|
+
return invalidRiskResult("artifact", "artifacts must be a non-empty array.");
|
|
44171
|
+
}
|
|
44172
|
+
return evaluate("artifact", artifacts, options);
|
|
44173
|
+
}
|
|
44174
|
+
function evaluateDeployPlan(plan, options = {}) {
|
|
44175
|
+
const valid = isNonEmptyString(plan) || plan != null && typeof plan === "object" && isNonEmptyContainer(plan);
|
|
44176
|
+
if (!valid) {
|
|
44177
|
+
return invalidRiskResult("deploy_plan", "plan must be a non-empty object, array, or string.");
|
|
44178
|
+
}
|
|
44179
|
+
return evaluate("deploy_plan", { plan }, options);
|
|
44180
|
+
}
|
|
44181
|
+
function mergeRiskDecision(base, risk) {
|
|
44182
|
+
if (!risk || !risk.findings?.length)
|
|
44183
|
+
return base;
|
|
44184
|
+
if (risk.decision === "deny") {
|
|
44185
|
+
const topFinding = risk.findings[0];
|
|
44186
|
+
const reason = topFinding.remediation ? `${topFinding.message} Remediation: ${topFinding.remediation}` : topFinding.message;
|
|
44187
|
+
return {
|
|
44188
|
+
...base,
|
|
44189
|
+
decision: "deny",
|
|
44190
|
+
risk: topFinding.category,
|
|
44191
|
+
reason,
|
|
44192
|
+
blockedByRiskRule: true,
|
|
44193
|
+
findings: risk.findings
|
|
44194
|
+
};
|
|
44195
|
+
}
|
|
44196
|
+
return {
|
|
44197
|
+
...base,
|
|
44198
|
+
warnings: [...base.warnings || [], ...risk.findings]
|
|
44199
|
+
};
|
|
44200
|
+
}
|
|
44201
|
+
var __dirname, defaultRulesPath, SEVERITY_RANK;
|
|
44202
|
+
var init_risk_rule_engine = __esm({
|
|
44203
|
+
"plugins/huaweicloud-core/dist.new/risk-rule-engine.js"() {
|
|
44204
|
+
"use strict";
|
|
44205
|
+
init_as_text();
|
|
44206
|
+
init_as_record();
|
|
44207
|
+
init_redact();
|
|
44208
|
+
__dirname = dirname2(fileURLToPath2(import.meta.url));
|
|
44209
|
+
defaultRulesPath = join2(__dirname, "..", "safety", "rules", "cloud-risk-rules.json");
|
|
44210
|
+
SEVERITY_RANK = {
|
|
44211
|
+
deny: 3,
|
|
44212
|
+
warn: 2,
|
|
44213
|
+
info: 1
|
|
44214
|
+
};
|
|
44215
|
+
}
|
|
44216
|
+
});
|
|
44217
|
+
|
|
44218
|
+
// plugins/huaweicloud-core/dist.new/safety/vocabulary.js
|
|
44219
|
+
function deriveSecretOperationAlternation(ops) {
|
|
44220
|
+
const entries = ops.filter((op) => op !== "");
|
|
44221
|
+
if (entries.length === 0)
|
|
44222
|
+
return "(?!)";
|
|
44223
|
+
return entries.map((op) => {
|
|
44224
|
+
const l = op.toLowerCase();
|
|
44225
|
+
const isStem = entries.some((other) => other !== op && other.toLowerCase().startsWith(l));
|
|
44226
|
+
const escaped = l.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
44227
|
+
return isStem ? `(?<![A-Za-z0-9._/-])${escaped}(?![A-Za-z0-9._/-])` : escaped;
|
|
44228
|
+
}).join("|");
|
|
44229
|
+
}
|
|
44230
|
+
var SECRET_OP_ALTERNATION, SECRET_ARGS_RE, SECRET_TEXT_RE, SECRET_SHADOW_RE;
|
|
44231
|
+
var init_vocabulary = __esm({
|
|
44232
|
+
"plugins/huaweicloud-core/dist.new/safety/vocabulary.js"() {
|
|
44233
|
+
"use strict";
|
|
44234
|
+
init_default_policy();
|
|
44235
|
+
SECRET_OP_ALTERNATION = deriveSecretOperationAlternation(DEFAULT_POLICY.blockedSecretOperations);
|
|
44236
|
+
SECRET_ARGS_RE = new RegExp(`secret[_-]?string|secret[_-]?binary|${SECRET_OP_ALTERNATION}`, "i");
|
|
44237
|
+
SECRET_TEXT_RE = new RegExp(`${SECRET_OP_ALTERNATION}|secret_string|secret_binary`, "i");
|
|
44238
|
+
SECRET_SHADOW_RE = new RegExp(SECRET_OP_ALTERNATION, "i");
|
|
44220
44239
|
}
|
|
44221
44240
|
});
|
|
44222
44241
|
|
|
@@ -44928,19 +44947,32 @@ var init_command_operation = __esm({
|
|
|
44928
44947
|
function commandRiskText(normalizedArgs, options) {
|
|
44929
44948
|
return options.rawCommand || ["hcloud", ...normalizedArgs].join(" ");
|
|
44930
44949
|
}
|
|
44950
|
+
function attachRiskFindings(base, risk) {
|
|
44951
|
+
if (!risk.findings || risk.findings.length === 0)
|
|
44952
|
+
return base;
|
|
44953
|
+
const warnFindings = risk.findings.filter((finding) => finding.severity !== "deny");
|
|
44954
|
+
return {
|
|
44955
|
+
...base,
|
|
44956
|
+
findings: [...base.findings || [], ...risk.findings],
|
|
44957
|
+
...warnFindings.length > 0 ? { warnings: [...base.warnings || [], ...warnFindings] } : {}
|
|
44958
|
+
};
|
|
44959
|
+
}
|
|
44960
|
+
function mergeRisk(base, risk) {
|
|
44961
|
+
return base.decision === "deny" ? attachRiskFindings(base, risk) : mergeRiskDecision(base, risk);
|
|
44962
|
+
}
|
|
44931
44963
|
function applyCommandRiskRules(base, normalizedArgs, options) {
|
|
44932
|
-
if (
|
|
44964
|
+
if (options.skipRiskRules === true) {
|
|
44933
44965
|
return base;
|
|
44934
44966
|
}
|
|
44935
44967
|
const risk = evaluateCommandRisk(commandRiskText(normalizedArgs, options));
|
|
44936
|
-
return
|
|
44968
|
+
return mergeRisk(base, risk);
|
|
44937
44969
|
}
|
|
44938
44970
|
function applyRawCommandRiskRules(base, command, options) {
|
|
44939
|
-
if (
|
|
44971
|
+
if (options.skipRiskRules === true) {
|
|
44940
44972
|
return base;
|
|
44941
44973
|
}
|
|
44942
44974
|
const risk = evaluateCommandRisk(command);
|
|
44943
|
-
return
|
|
44975
|
+
return mergeRisk(base, risk);
|
|
44944
44976
|
}
|
|
44945
44977
|
var init_risk_merge = __esm({
|
|
44946
44978
|
"plugins/huaweicloud-core/dist.new/safety/risk-merge.js"() {
|
|
@@ -45232,18 +45264,18 @@ function classifyHcloudArgs(args, options = {}) {
|
|
|
45232
45264
|
const isExecution = executionOps.test(operation) && !readOnly;
|
|
45233
45265
|
const isWrite = !readOnly && hasWritePrefix(operation, policy);
|
|
45234
45266
|
if (isExecution && !options.allowWrites) {
|
|
45235
|
-
return {
|
|
45267
|
+
return applyCommandRiskRules({
|
|
45236
45268
|
decision: "deny",
|
|
45237
45269
|
risk: "execution",
|
|
45238
45270
|
reason: "Huawei Cloud execution/trigger operation blocked until approved."
|
|
45239
|
-
};
|
|
45271
|
+
}, normalizedArgs, options);
|
|
45240
45272
|
}
|
|
45241
45273
|
if (isWrite && !options.allowWrites) {
|
|
45242
|
-
return {
|
|
45274
|
+
return applyCommandRiskRules({
|
|
45243
45275
|
decision: "deny",
|
|
45244
45276
|
risk: "write",
|
|
45245
45277
|
reason: "Huawei Cloud write operation blocked until the agent presents a plan and receives explicit user approval."
|
|
45246
|
-
};
|
|
45278
|
+
}, normalizedArgs, options);
|
|
45247
45279
|
}
|
|
45248
45280
|
const obsutilWrites = OBSUTIL_WRITES;
|
|
45249
45281
|
const obsutilReads = ["ls", "stat", "cat", "help", "version"];
|
|
@@ -45251,11 +45283,11 @@ function classifyHcloudArgs(args, options = {}) {
|
|
|
45251
45283
|
const isObsWrite = isObs && obsutilWrites.has(operation.toLowerCase());
|
|
45252
45284
|
const isObsRead = isObs && obsutilReads.includes(operation.toLowerCase());
|
|
45253
45285
|
if (isObsWrite && !options.allowWrites) {
|
|
45254
|
-
return {
|
|
45286
|
+
return applyCommandRiskRules({
|
|
45255
45287
|
decision: "deny",
|
|
45256
45288
|
risk: "write",
|
|
45257
45289
|
reason: "OBS write operation blocked until the agent presents a plan and receives explicit user approval."
|
|
45258
|
-
};
|
|
45290
|
+
}, normalizedArgs, options);
|
|
45259
45291
|
}
|
|
45260
45292
|
if (isObsRead) {
|
|
45261
45293
|
return applyCommandRiskRules({
|
|
@@ -45329,6 +45361,61 @@ var init_classify_hcloud = __esm({
|
|
|
45329
45361
|
}
|
|
45330
45362
|
});
|
|
45331
45363
|
|
|
45364
|
+
// plugins/huaweicloud-core/dist.new/safety/protected-payload.js
|
|
45365
|
+
function shapeRegexes(markers) {
|
|
45366
|
+
if (markers.length === 0)
|
|
45367
|
+
return [];
|
|
45368
|
+
const markerAlt = `(?:${markers.join("|")})`;
|
|
45369
|
+
const anchor2 = String.raw`^[ \t]*(?:[A-Za-z_][A-Za-z0-9_]*=\S*[ \t]+)*(?:(?:sudo|env|nice|nohup|command|xargs)[ \t]+)*`;
|
|
45370
|
+
return [
|
|
45371
|
+
// 1. Redirection: the marker sits in the redirect's target region.
|
|
45372
|
+
// Direction is inherent — `cat <marker> > /tmp/out` keeps its marker
|
|
45373
|
+
// BEFORE the operator and never matches.
|
|
45374
|
+
new RegExp(String.raw`>>?[^;&|]*` + markerAlt, "i"),
|
|
45375
|
+
// 2. tee: every operand is a write target.
|
|
45376
|
+
new RegExp(anchor2 + String.raw`tee\b[^;&|]*` + markerAlt, "i"),
|
|
45377
|
+
// 3. The copy family: the destination is the LAST operand, so the
|
|
45378
|
+
// marker must ride the final word — `cp <marker> /tmp/` (a copy-out)
|
|
45379
|
+
// stays allowed.
|
|
45380
|
+
new RegExp(anchor2 + String.raw`(?:cp|mv|rsync|install)\b[^;&|]*[ \t]\S*` + markerAlt + String.raw`\S*[ \t]*$`, "i"),
|
|
45381
|
+
// 4. dd: the of= operand is the output.
|
|
45382
|
+
new RegExp(anchor2 + String.raw`dd\b[^;&|]*\bof[ \t]*=[ \t]*[^;&|]*` + markerAlt, "i"),
|
|
45383
|
+
// 5. sed: a whitespace-preceded -i flag (in-place) anywhere before the
|
|
45384
|
+
// marker; a read-only sed over the payload stays allowed.
|
|
45385
|
+
new RegExp(anchor2 + String.raw`sed\b[^;&|]*[ \t]-i\b[^;&|]*` + markerAlt, "i"),
|
|
45386
|
+
// 6. patch: the operand is the file being patched.
|
|
45387
|
+
new RegExp(anchor2 + String.raw`patch\b[^;&|]*` + markerAlt, "i")
|
|
45388
|
+
];
|
|
45389
|
+
}
|
|
45390
|
+
function protectedPayloadWriteDenied(text, policy) {
|
|
45391
|
+
if (policy.protectedPayloadPathMarkers.length === 0)
|
|
45392
|
+
return null;
|
|
45393
|
+
const shapes = shapeRegexes(policy.protectedPayloadPathMarkers);
|
|
45394
|
+
for (const candidate of credentialFileCandidates(text)) {
|
|
45395
|
+
for (const chunk of candidate.split(/[;&|\n\r]/)) {
|
|
45396
|
+
for (const shape of shapes) {
|
|
45397
|
+
if (shape.test(chunk)) {
|
|
45398
|
+
return {
|
|
45399
|
+
decision: "deny",
|
|
45400
|
+
// risk 'invalid': exempt from NO roster exemption class (the
|
|
45401
|
+
// .mjs/py hooks skip write/execution/destructive for exempt
|
|
45402
|
+
// shapes — a payload-write deny must never be skippable).
|
|
45403
|
+
risk: "invalid",
|
|
45404
|
+
reason: "Writing to the deployed Huawei Cloud DevKit plugin payload is blocked: this command targets the installed safety policy files, and modifying them would disarm the gates that classify agent commands. Reinstall or update via npx huaweicloud-devkit install from your own terminal; see the huaweicloud-safety skill's approvals reference for the integrity model."
|
|
45405
|
+
};
|
|
45406
|
+
}
|
|
45407
|
+
}
|
|
45408
|
+
}
|
|
45409
|
+
}
|
|
45410
|
+
return null;
|
|
45411
|
+
}
|
|
45412
|
+
var init_protected_payload = __esm({
|
|
45413
|
+
"plugins/huaweicloud-core/dist.new/safety/protected-payload.js"() {
|
|
45414
|
+
"use strict";
|
|
45415
|
+
init_credential_path();
|
|
45416
|
+
}
|
|
45417
|
+
});
|
|
45418
|
+
|
|
45332
45419
|
// plugins/huaweicloud-core/dist.new/safety/classify-text.js
|
|
45333
45420
|
function scriptTextOf(tokens, depth = 0) {
|
|
45334
45421
|
if (depth >= 18 || tokens.length === 0)
|
|
@@ -45800,6 +45887,9 @@ function classifyTextCommand(command, options = {}) {
|
|
|
45800
45887
|
reason: "Reading Huawei Cloud credential or profile files is blocked. Use redacted profile inspection tools instead."
|
|
45801
45888
|
};
|
|
45802
45889
|
}
|
|
45890
|
+
const payloadWrite = protectedPayloadWriteDenied(text, policy);
|
|
45891
|
+
if (payloadWrite !== null)
|
|
45892
|
+
return payloadWrite;
|
|
45803
45893
|
if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedSecretCliPatterns))) {
|
|
45804
45894
|
return {
|
|
45805
45895
|
decision: "deny",
|
|
@@ -45908,6 +45998,7 @@ var init_classify_text = __esm({
|
|
|
45908
45998
|
init_credential_path();
|
|
45909
45999
|
init_default_policy();
|
|
45910
46000
|
init_policy();
|
|
46001
|
+
init_protected_payload();
|
|
45911
46002
|
init_risk_merge();
|
|
45912
46003
|
init_secret_exec();
|
|
45913
46004
|
init_skill_quality_cli();
|
|
@@ -49287,8 +49378,10 @@ function explainError({ service = "unknown", errorCode = "", code = "", message
|
|
|
49287
49378
|
const uniqueSuggestions = suggestions.filter((s, i, arr) => {
|
|
49288
49379
|
return !arr.slice(0, i).some((prev) => prev.substring(0, 50).toLowerCase() === s.substring(0, 50).toLowerCase());
|
|
49289
49380
|
});
|
|
49381
|
+
const providedKnown = Boolean(service) && svc !== "unknown";
|
|
49382
|
+
const responseService = !providedKnown || !hwErrorPatterns[patternKey] ? effectiveKey : service;
|
|
49290
49383
|
return {
|
|
49291
|
-
service,
|
|
49384
|
+
service: responseService,
|
|
49292
49385
|
errorCode: resolvedCode,
|
|
49293
49386
|
requestId,
|
|
49294
49387
|
suggestions: uniqueSuggestions
|
|
@@ -52063,14 +52156,72 @@ var init_hwexec_task = __esm({
|
|
|
52063
52156
|
}
|
|
52064
52157
|
});
|
|
52065
52158
|
|
|
52159
|
+
// plugins/huaweicloud-core/dist.new/packs/sandbox/expose-task.js
|
|
52160
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
52161
|
+
function sweep(now) {
|
|
52162
|
+
for (const [taskId, task] of tasks) {
|
|
52163
|
+
if (now - task.startedAt > EXPOSE_TASK_TTL_MS)
|
|
52164
|
+
tasks.delete(taskId);
|
|
52165
|
+
}
|
|
52166
|
+
}
|
|
52167
|
+
function startExposeTask(workspaceId2, port, run) {
|
|
52168
|
+
const now = Date.now();
|
|
52169
|
+
sweep(now);
|
|
52170
|
+
const taskId = `exp-${randomUUID2()}`;
|
|
52171
|
+
const snapshot = { startedAt: now, workspaceId: workspaceId2, port };
|
|
52172
|
+
tasks.set(taskId, { ...snapshot, state: "running" });
|
|
52173
|
+
void run().then((result) => {
|
|
52174
|
+
tasks.set(taskId, { ...snapshot, state: "done", result });
|
|
52175
|
+
}, (error62) => {
|
|
52176
|
+
tasks.set(taskId, {
|
|
52177
|
+
...snapshot,
|
|
52178
|
+
state: "failed",
|
|
52179
|
+
error: error62 instanceof Error ? error62.message : String(error62)
|
|
52180
|
+
});
|
|
52181
|
+
});
|
|
52182
|
+
return { taskId, startedAt: now };
|
|
52183
|
+
}
|
|
52184
|
+
function pollExposeTask(taskId) {
|
|
52185
|
+
const now = Date.now();
|
|
52186
|
+
sweep(now);
|
|
52187
|
+
const task = tasks.get(taskId);
|
|
52188
|
+
if (!task) {
|
|
52189
|
+
return {
|
|
52190
|
+
state: "unknown",
|
|
52191
|
+
hint: "No task with this id is known to this MCP server process (it never started here, the session restarted, or the 30-minute receipt expired). The tunnel may already exist: run huaweicloud_sandbox_deploy_check to read it, or re-run huaweicloud_sandbox_expose_tunnel (same port) \u2014 do not assume success without a URL."
|
|
52192
|
+
};
|
|
52193
|
+
}
|
|
52194
|
+
if (task.state === "running") {
|
|
52195
|
+
return {
|
|
52196
|
+
state: "running",
|
|
52197
|
+
elapsedMs: now - task.startedAt,
|
|
52198
|
+
hint: "The expose chain is running in the background (auth, cleanup, host start, health check, keepalive). Call again."
|
|
52199
|
+
};
|
|
52200
|
+
}
|
|
52201
|
+
if (task.state === "done") {
|
|
52202
|
+
return { state: "done", result: task.result };
|
|
52203
|
+
}
|
|
52204
|
+
return { state: "failed", error: task.error };
|
|
52205
|
+
}
|
|
52206
|
+
var EXPOSE_TASK_ID_PATTERN, EXPOSE_TASK_TTL_MS, tasks;
|
|
52207
|
+
var init_expose_task = __esm({
|
|
52208
|
+
"plugins/huaweicloud-core/dist.new/packs/sandbox/expose-task.js"() {
|
|
52209
|
+
"use strict";
|
|
52210
|
+
EXPOSE_TASK_ID_PATTERN = /^exp-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
52211
|
+
EXPOSE_TASK_TTL_MS = 30 * 6e4;
|
|
52212
|
+
tasks = /* @__PURE__ */ new Map();
|
|
52213
|
+
}
|
|
52214
|
+
});
|
|
52215
|
+
|
|
52066
52216
|
// plugins/huaweicloud-core/dist.new/packs/sandbox/schemas.js
|
|
52067
|
-
var SANDBOX_TIMEOUT_MS, execWithSessionSchema, execOneShotSchema, execPollSchema, closeSessionSchema, uploadFileSchema, uploadProjectSchema, deployNginxSchema, deployCheckSchema, checkUserSchema, exposeTunnelSchema, renewTunnelSchema, keepaliveWatchdogSchema, signAgreementSchema, connectSchema, credentialsSchema, shutdownSchema;
|
|
52217
|
+
var SANDBOX_TIMEOUT_MS, execWithSessionSchema, execOneShotSchema, execPollSchema, closeSessionSchema, uploadFileSchema, uploadProjectSchema, deployNginxSchema, deployCheckSchema, checkUserSchema, exposeTunnelSchema, exposePollSchema, renewTunnelSchema, keepaliveWatchdogSchema, signAgreementSchema, connectSchema, credentialsSchema, shutdownSchema;
|
|
52068
52218
|
var init_schemas4 = __esm({
|
|
52069
52219
|
"plugins/huaweicloud-core/dist.new/packs/sandbox/schemas.js"() {
|
|
52070
52220
|
"use strict";
|
|
52071
52221
|
init_zod();
|
|
52072
52222
|
init_hwexec_task();
|
|
52073
52223
|
init_tool_schema_parts();
|
|
52224
|
+
init_expose_task();
|
|
52074
52225
|
SANDBOX_TIMEOUT_MS = {
|
|
52075
52226
|
exec_with_session: 12e4,
|
|
52076
52227
|
exec_one_shot: 12e4,
|
|
@@ -52174,12 +52325,16 @@ var init_schemas4 = __esm({
|
|
|
52174
52325
|
expiry_hours: numericArg.optional().describe("Tunnel lifetime in hours, 1-720 (default 72). 720 = the devbridge 30-day maximum; the keepalive watchdog renews to 720h daily."),
|
|
52175
52326
|
keepalive: external_exports.boolean().optional().describe("Enroll the tunnel into the keepalive watchdog (default true \u2014 pass false to opt out). Returns keepalive.enrolled/tunnelCount/watchdogPid."),
|
|
52176
52327
|
cleanup_mode: external_exports.enum(["stale", "all", "none"]).optional().describe("Tunnel cleanup before exposing. stale (default): delete same-port tunnels + orphan records/hosts; preserve other ports, other sessions and keepalive-protected tunnels \u2014 except a tunnel bound to THIS port, which is always replaced. all: wipe every tunnel/host (manual full reset only \u2014 a shared sandbox loses every session's tunnels). none: no cleanup (a stale same-port host can then conflict)."),
|
|
52328
|
+
mode: external_exports.enum(["sync", "async"]).optional().describe("sync (default): run the whole expose chain and return its result. async: start the chain in the background and return {started:true, taskId, hint} immediately \u2014 use it on MCP hosts whose per-request timeout is shorter than the expose chain (auth + selective cleanup + up to four ~63s expose attempts + re-verify + keepalive enrollment), then poll huaweicloud_sandbox_expose_poll with taskId. The task receipt lives in this MCP server process (30 min)."),
|
|
52177
52329
|
workspace_id: workspaceId,
|
|
52178
52330
|
username,
|
|
52179
52331
|
timeout_ms: numericArg.optional().describe(`Execution timeout in milliseconds (default: ${SANDBOX_TIMEOUT_MS.expose_tunnel})`),
|
|
52180
52332
|
approvalToken: approvalTokenArg,
|
|
52181
52333
|
approvedByUser: approvedByUserArg
|
|
52182
52334
|
});
|
|
52335
|
+
exposePollSchema = external_exports.looseObject({
|
|
52336
|
+
task_id: external_exports.string().regex(EXPOSE_TASK_ID_PATTERN, 'task_id must be the exp-<uuid> from huaweicloud_sandbox_expose_tunnel mode:"async".').describe('The taskId returned by huaweicloud_sandbox_expose_tunnel with mode:"async".')
|
|
52337
|
+
});
|
|
52183
52338
|
renewTunnelSchema = external_exports.looseObject({
|
|
52184
52339
|
tunnel_id: external_exports.string().describe("DevBridge tunnel ID to renew (from expose_tunnel's tunnelId field, or extract from the URL https://<tunnel_id>-<port>.devbridge-s2.hwtunnel.com)."),
|
|
52185
52340
|
expiry_hours: numericArg.optional().describe("New lifetime in hours, 1-720 (default 720 = the 30-day maximum). Renewal is a rolling window \u2014 the same URL stays alive."),
|
|
@@ -56445,8 +56600,10 @@ async function hdkitConnect(options = {}) {
|
|
|
56445
56600
|
}
|
|
56446
56601
|
return asRecord(await hdkitRequest("POST", "connect", body));
|
|
56447
56602
|
}
|
|
56448
|
-
async function hdkitConnectWithRetry(options = {}) {
|
|
56603
|
+
async function hdkitConnectWithRetry(options = {}, retryOptions = {}) {
|
|
56449
56604
|
const delays = connectRetryDelaysMs();
|
|
56605
|
+
const inlineRetry = retryOptions.inlineRetry !== false;
|
|
56606
|
+
const maxInlineDelayMs = retryOptions.maxInlineDelayMs ?? Number.POSITIVE_INFINITY;
|
|
56450
56607
|
let retries = 0;
|
|
56451
56608
|
for (; ; ) {
|
|
56452
56609
|
try {
|
|
@@ -56465,6 +56622,16 @@ async function hdkitConnectWithRetry(options = {}) {
|
|
|
56465
56622
|
throw decorateExhaustedConnect(error62, retries);
|
|
56466
56623
|
throw error62;
|
|
56467
56624
|
}
|
|
56625
|
+
if (!inlineRetry || (delays[retries] ?? Number.POSITIVE_INFINITY) > maxInlineDelayMs) {
|
|
56626
|
+
const pendingCode = asString(safeReadField(error62, "code"));
|
|
56627
|
+
return {
|
|
56628
|
+
pending: true,
|
|
56629
|
+
connectRetries: retries,
|
|
56630
|
+
retryAfterMs: delays[retries] ?? delays[0] ?? 0,
|
|
56631
|
+
...pendingCode ? { code: pendingCode } : {},
|
|
56632
|
+
message: safeMessageText(error62)
|
|
56633
|
+
};
|
|
56634
|
+
}
|
|
56468
56635
|
await new Promise((resolve11) => setTimeout(resolve11, delays[retries]));
|
|
56469
56636
|
retries += 1;
|
|
56470
56637
|
}
|
|
@@ -56719,8 +56886,8 @@ async function handleExposeTunnel(args = {}, _opts = {}) {
|
|
|
56719
56886
|
const sandboxUser9 = args.username || "root";
|
|
56720
56887
|
const sandboxTimeout9 = args.timeout_ms || SANDBOX_TIMEOUT_MS.expose_tunnel;
|
|
56721
56888
|
const exposePoolContext = poolContextFor(sandboxWsId9);
|
|
56722
|
-
|
|
56723
|
-
port: args.port,
|
|
56889
|
+
const exposeArgs = {
|
|
56890
|
+
port: validateTunnelPort(args.port),
|
|
56724
56891
|
expiryHours: typeof args.expiry_hours === "number" ? args.expiry_hours : void 0,
|
|
56725
56892
|
keepalive: typeof args.keepalive === "boolean" ? args.keepalive : void 0,
|
|
56726
56893
|
cleanupMode: args.cleanup_mode,
|
|
@@ -56728,7 +56895,24 @@ async function handleExposeTunnel(args = {}, _opts = {}) {
|
|
|
56728
56895
|
poolType: exposePoolContext?.poolMode || "ephemeral",
|
|
56729
56896
|
poolContext: exposePoolContext,
|
|
56730
56897
|
keyUpgrade: { ensureDevbridgeKey, recreateDevbridgeKey, buildKeyringInjectScript, listKeysForQuotaHint }
|
|
56731
|
-
}
|
|
56898
|
+
};
|
|
56899
|
+
if (args.mode === "async") {
|
|
56900
|
+
const { taskId } = startExposeTask(sandboxWsId9, exposeArgs.port, () => exposeTunnel(sandboxWsId9, exposeArgs, sandboxUser9, sandboxTimeout9));
|
|
56901
|
+
return {
|
|
56902
|
+
started: true,
|
|
56903
|
+
mode: "async",
|
|
56904
|
+
taskId,
|
|
56905
|
+
hint: "The expose chain is running in the background. Poll huaweicloud_sandbox_expose_poll with this taskId until state is done \u2014 the publicUrl and urlLifetimeHint are delivered there (the task receipt lives 30 minutes in this MCP server process)."
|
|
56906
|
+
};
|
|
56907
|
+
}
|
|
56908
|
+
return await exposeTunnel(sandboxWsId9, exposeArgs, sandboxUser9, sandboxTimeout9);
|
|
56909
|
+
}
|
|
56910
|
+
async function handleExposePoll(args = {}, _opts = {}) {
|
|
56911
|
+
const taskId = args.task_id;
|
|
56912
|
+
if (typeof taskId !== "string" || taskId === "") {
|
|
56913
|
+
throw new Error('task_id is required \u2014 pass the taskId returned by huaweicloud_sandbox_expose_tunnel mode:"async".');
|
|
56914
|
+
}
|
|
56915
|
+
return pollExposeTask(taskId);
|
|
56732
56916
|
}
|
|
56733
56917
|
async function handleRenewTunnel(args = {}, _opts = {}) {
|
|
56734
56918
|
if (!args.tunnel_id) {
|
|
@@ -56760,7 +56944,9 @@ var init_handlers_tunnel = __esm({
|
|
|
56760
56944
|
"use strict";
|
|
56761
56945
|
init_devbridge_tunnel();
|
|
56762
56946
|
init_session_manager();
|
|
56947
|
+
init_devbridge_validation();
|
|
56763
56948
|
init_sandbox_pool();
|
|
56949
|
+
init_expose_task();
|
|
56764
56950
|
init_devbridge_key();
|
|
56765
56951
|
init_schemas4();
|
|
56766
56952
|
}
|
|
@@ -56873,7 +57059,7 @@ async function handleConnect(args = {}, _opts = {}) {
|
|
|
56873
57059
|
}
|
|
56874
57060
|
let connectResult;
|
|
56875
57061
|
try {
|
|
56876
|
-
connectResult = await hdkitConnectWithRetry(connectArgs);
|
|
57062
|
+
connectResult = await hdkitConnectWithRetry(connectArgs, { maxInlineDelayMs: 1e3 });
|
|
56877
57063
|
} catch (error62) {
|
|
56878
57064
|
const err = error62;
|
|
56879
57065
|
const gate = versionGateResult(err);
|
|
@@ -56913,6 +57099,19 @@ async function handleConnect(args = {}, _opts = {}) {
|
|
|
56913
57099
|
}
|
|
56914
57100
|
throw error62;
|
|
56915
57101
|
}
|
|
57102
|
+
if (connectResult?.pending === true) {
|
|
57103
|
+
const retryAfterMs = typeof connectResult.retryAfterMs === "number" && Number.isFinite(connectResult.retryAfterMs) ? connectResult.retryAfterMs : 3e4;
|
|
57104
|
+
const retryAfter = `${Math.max(1, Math.ceil(retryAfterMs / 1e3))}s`;
|
|
57105
|
+
return {
|
|
57106
|
+
ok: false,
|
|
57107
|
+
pending: true,
|
|
57108
|
+
retryAfter,
|
|
57109
|
+
retryAfterMs,
|
|
57110
|
+
...typeof connectResult.code === "string" ? { code: connectResult.code } : {},
|
|
57111
|
+
message: typeof connectResult.message === "string" && connectResult.message ? connectResult.message : "the hdkitservice gateway timed out during orchestration.",
|
|
57112
|
+
hint: `The sandbox instance may already exist on the server. Re-call huaweicloud_sandbox_connect with the SAME parameters after ~${retryAfter} \u2014 a created instance is reused. Do not start a second sandbox and do not debug this as a credential failure.`
|
|
57113
|
+
};
|
|
57114
|
+
}
|
|
56916
57115
|
const rawDevStageId = connectResult?.dev_stage_id || connectResult?.devStageId;
|
|
56917
57116
|
const devStageId = typeof rawDevStageId === "string" ? rawDevStageId : void 0;
|
|
56918
57117
|
let announceConnect = true;
|
|
@@ -57956,6 +58155,12 @@ var init_tools2 = __esm({
|
|
|
57956
58155
|
schema: exposeTunnelSchema,
|
|
57957
58156
|
handler: handleExposeTunnel
|
|
57958
58157
|
},
|
|
58158
|
+
{
|
|
58159
|
+
name: "huaweicloud_sandbox_expose_poll",
|
|
58160
|
+
description: 'Poll an async expose task started by huaweicloud_sandbox_expose_tunnel with mode: "async". Returns state: running (the chain is still working \u2014 call again), done (result carries the full expose envelope: ok, publicUrl, port, tunnelId, expiresAt, urlLifetimeHint, keepalive, warnings), failed (an unexpected throw escaped the chain, with error), or unknown (no receipt in this MCP server process \u2014 it never started here, the session restarted, or the 30-minute receipt expired; the tunnel may already exist, so check huaweicloud_sandbox_deploy_check or re-expose \u2014 never assume success without a URL). The urlLifetimeHint MUST be relayed with the URL: the tunnel expiry is not the sandbox lifetime.',
|
|
58161
|
+
schema: exposePollSchema,
|
|
58162
|
+
handler: handleExposePoll
|
|
58163
|
+
},
|
|
57959
58164
|
{
|
|
57960
58165
|
name: "huaweicloud_sandbox_renew_tunnel",
|
|
57961
58166
|
description: "Renew a DevBridge tunnel's lifetime (devbridge update <id> -e <hours>) \u2014 a ROLLING window: expiration = now + hours regardless of remaining time, so renewing before expiry keeps the SAME public URL alive indefinitely (the URL is bound to the tunnel ID and never changes). Default 720h = the 30-day maximum. Returns ok, tunnelId, expiresAt (absolute ISO timestamp read back via show -v \u2014 a management-plane loss (10002 tunnel not found) is NOT misread as success), renewedForHours. Use the tunnelId from huaweicloud_sandbox_expose_tunnel or extract it from the URL. The keepalive watchdog renews automatically; this tool is the manual/one-off path.",
|
|
@@ -57982,7 +58187,7 @@ var init_tools2 = __esm({
|
|
|
57982
58187
|
},
|
|
57983
58188
|
{
|
|
57984
58189
|
name: "huaweicloud_sandbox_connect",
|
|
57985
|
-
description: "Connect to a sandbox via hdkitservice. One instance per user per pool \u2014 reuses the same-pool sandbox if available, otherwise creates a new one. Quota: 1 instance per pool type (a user may hold 1 ephemeral AND 1 persistent simultaneously; same-type requests reuse the existing instance). On quota exhaustion the API returns HTTP 429 with one of three codes: HDKIT_QUOTA_EXCEEDED (retry useless \u2014 release or reuse the existing instance; Retry-After 60), HDKIT_TEMPLATE_QUOTA_EXCEEDED (the running instances of this account for this sandbox type are at the limit \u2014 shut down or release an instance of the same type and retry; no Retry-After), or HDKIT_CAPACITY_INSUFFICIENT (pool capacity; retry later / off-peak; Retry-After 60). Gateway 502/504 timeouts during orchestration
|
|
58190
|
+
description: "Connect to a sandbox via hdkitservice. One instance per user per pool \u2014 reuses the same-pool sandbox if available, otherwise creates a new one. Quota: 1 instance per pool type (a user may hold 1 ephemeral AND 1 persistent simultaneously; same-type requests reuse the existing instance). On quota exhaustion the API returns HTTP 429 with one of three codes: HDKIT_QUOTA_EXCEEDED (retry useless \u2014 release or reuse the existing instance; Retry-After 60), HDKIT_TEMPLATE_QUOTA_EXCEEDED (the running instances of this account for this sandbox type are at the limit \u2014 shut down or release an instance of the same type and retry; no Retry-After), or HDKIT_CAPACITY_INSUFFICIENT (pool capacity; retry later / off-peak; Retry-After 60). Gateway 502/504 timeouts during orchestration return a pending receipt (ok:false, pending:true, retryAfter, hint) instead of holding the call through the backoff \u2014 the server may already have created the instance; re-call this tool with the SAME parameters after retryAfter and a created instance is reused. An outdated plugin version is rejected by the 409 HDKIT_VERSION_TOO_OLD version gate, surfaced by the sandbox tools (connect/check_user/sign_agreement/credentials) as ok:false and by the voucher trio as claimed:false, always carrying code, message, and remediation naming the upgrade act (npx --yes huaweicloud-devkit@latest update --target <agent>, restart the agent session, or huaweicloud_upgrade), with clientVersion and minVersion present when the service sends them. Returns session_id, dev_stage_id, connection_id, connection_address, expiresAt (STS credential expiry), pool_type/resolved template_id echo, server-configured lifecycle numbers (pool_idle_shutdown_minutes / pool_idle_delete_minutes / pool_reclaim_minutes) and started (true when a reused instance was woken from shutdown). Lifecycle hints are announced only on the first connect of a session or when started=true. Ephemeral pool (default): idle auto-shutdown after 30min, auto-delete after 1h \u2014 do not keep important data there. Persistent pool: data disk retained (EVS 32G), idle shutdown after 1h, idle reclaim capped at 7 days. Numbers are configured by hdkitservice; the text follows the server echo and falls back to these defaults. Vendor-gated (vendorConfirmed): call only when the vendor is established \u2014 see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.",
|
|
57986
58191
|
schema: connectSchema,
|
|
57987
58192
|
handler: handleConnect
|
|
57988
58193
|
},
|
|
@@ -58009,6 +58214,7 @@ var init_tools2 = __esm({
|
|
|
58009
58214
|
huaweicloud_sandbox_deploy_nginx: deployNginxSchema,
|
|
58010
58215
|
huaweicloud_sandbox_deploy_check: deployCheckSchema,
|
|
58011
58216
|
huaweicloud_sandbox_expose_tunnel: exposeTunnelSchema,
|
|
58217
|
+
huaweicloud_sandbox_expose_poll: exposePollSchema,
|
|
58012
58218
|
huaweicloud_sandbox_renew_tunnel: renewTunnelSchema,
|
|
58013
58219
|
huaweicloud_sandbox_keepalive_watchdog: keepaliveWatchdogSchema,
|
|
58014
58220
|
huaweicloud_sandbox_check_user: checkUserSchema,
|
|
@@ -58027,6 +58233,7 @@ var init_tools2 = __esm({
|
|
|
58027
58233
|
huaweicloud_sandbox_deploy_nginx: handleDeployNginx,
|
|
58028
58234
|
huaweicloud_sandbox_deploy_check: handleDeployCheck,
|
|
58029
58235
|
huaweicloud_sandbox_expose_tunnel: handleExposeTunnel,
|
|
58236
|
+
huaweicloud_sandbox_expose_poll: handleExposePoll,
|
|
58030
58237
|
huaweicloud_sandbox_renew_tunnel: handleRenewTunnel,
|
|
58031
58238
|
huaweicloud_sandbox_keepalive_watchdog: handleKeepaliveWatchdog,
|
|
58032
58239
|
huaweicloud_sandbox_check_user: handleCheckUser,
|
|
@@ -58438,7 +58645,7 @@ var init_supplemental_redaction = __esm({
|
|
|
58438
58645
|
});
|
|
58439
58646
|
|
|
58440
58647
|
// plugins/huaweicloud-core/dist.new/lib/approval-tokens.js
|
|
58441
|
-
import { createHash as createHash7, createHmac as createHmac3, randomUUID as
|
|
58648
|
+
import { createHash as createHash7, createHmac as createHmac3, randomUUID as randomUUID3, timingSafeEqual } from "node:crypto";
|
|
58442
58649
|
import { existsSync as existsSync28, mkdirSync as mkdirSync14, readdirSync as readdirSync4, readFileSync as readFileSync28, renameSync as renameSync7, statSync as statSync9, unlinkSync as unlinkSync4, writeFileSync as writeFileSync12 } from "node:fs";
|
|
58443
58650
|
import { dirname as dirname24, join as join35 } from "node:path";
|
|
58444
58651
|
function approvalFilePath() {
|
|
@@ -58568,7 +58775,7 @@ function pruneConsumedMarkers(now = Date.now()) {
|
|
|
58568
58775
|
}
|
|
58569
58776
|
}
|
|
58570
58777
|
function createApprovalToken(rawArgs, opts = {}) {
|
|
58571
|
-
const token =
|
|
58778
|
+
const token = randomUUID3();
|
|
58572
58779
|
const map2 = readApprovals();
|
|
58573
58780
|
map2[token] = {
|
|
58574
58781
|
argsHash: hashArgs(rawArgs),
|
|
@@ -59133,7 +59340,12 @@ function planHcloudCommand(args, options = {}) {
|
|
|
59133
59340
|
needed: true,
|
|
59134
59341
|
...approvalToken !== void 0 ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}
|
|
59135
59342
|
} : { needed: false },
|
|
59136
|
-
|
|
59343
|
+
// "Safe to run NOW": a caller-supplied allowWrites:true only unlocks the
|
|
59344
|
+
// classification — the strict view still demands the user's confirmation
|
|
59345
|
+
// (the approval token/form), so a plan showing decision:"allow" must not
|
|
59346
|
+
// also read as runnable while userConfirmation.needed is true (AX D-02
|
|
59347
|
+
// display-layer alignment).
|
|
59348
|
+
safeToRun: effectiveClassification.decision === "allow" && !needsConfirmation
|
|
59137
59349
|
};
|
|
59138
59350
|
}
|
|
59139
59351
|
var REQUIRED_PARAMS, PARAM_VALUE_HINTS, PLACEHOLDER_SECRET_VALUE_RE;
|
|
@@ -59888,7 +60100,7 @@ async function handleAuthConfirm(args = {}, _opts = {}) {
|
|
|
59888
60100
|
if (token && consumedConfirms.has(token)) {
|
|
59889
60101
|
return { status: "ok", outcome: "already_processed" };
|
|
59890
60102
|
}
|
|
59891
|
-
return { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND" };
|
|
60103
|
+
return { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND", nextStep: AUTH_CONFIRM_TOKEN_NOT_FOUND_NEXT_STEP };
|
|
59892
60104
|
}
|
|
59893
60105
|
if (args.decision === "s1") {
|
|
59894
60106
|
pendingConfirms.delete(token);
|
|
@@ -59906,7 +60118,7 @@ async function handleAuthConfirm(args = {}, _opts = {}) {
|
|
|
59906
60118
|
async function handleCheckAccountType(args = {}, _opts = {}) {
|
|
59907
60119
|
return checkAccountType({ region: typeof args.region === "string" ? args.region : void 0 });
|
|
59908
60120
|
}
|
|
59909
|
-
var authStatusSchema, authSyncSchema, authInitSchema, authSwitchSchema, authConfirmSchema, checkAccountTypeSchema, AUTH_TOOLS, AUTH_TOOL_SCHEMAS, AUTH_TOOL_HANDLERS;
|
|
60121
|
+
var AUTH_CONFIRM_TOKEN_NOT_FOUND_NEXT_STEP, authStatusSchema, authSyncSchema, authInitSchema, authSwitchSchema, authConfirmSchema, checkAccountTypeSchema, AUTH_TOOLS, AUTH_TOOL_SCHEMAS, AUTH_TOOL_HANDLERS;
|
|
59910
60122
|
var init_tools3 = __esm({
|
|
59911
60123
|
"plugins/huaweicloud-core/dist.new/packs/auth/tools.js"() {
|
|
59912
60124
|
"use strict";
|
|
@@ -59919,6 +60131,7 @@ var init_tools3 = __esm({
|
|
|
59919
60131
|
init_credentials2();
|
|
59920
60132
|
init_store();
|
|
59921
60133
|
init_approval();
|
|
60134
|
+
AUTH_CONFIRM_TOKEN_NOT_FOUND_NEXT_STEP = "This confirmation token was never minted in this process \u2014 mistyped, or dropped by a server restart (confirm tokens are process-scoped and never persisted). Re-run the huaweicloud_auth_switch action that returned needs_confirmation to mint a fresh token, then call huaweicloud_auth_confirm with it.";
|
|
59922
60135
|
authStatusSchema = external_exports.looseObject({
|
|
59923
60136
|
vendorConfirmed,
|
|
59924
60137
|
target: external_exports.string().optional().describe("Agent target to check: opencode, codex, codex-desktop, codearts, codearts-work, workbuddy, dsh, officeace, hermes, openclaw, atomcode, or all (default).")
|
|
@@ -63273,6 +63486,7 @@ var init_registry = __esm({
|
|
|
63273
63486
|
huaweicloud_sandbox_deploy_nginx: "sandbox",
|
|
63274
63487
|
huaweicloud_sandbox_deploy_check: "sandbox",
|
|
63275
63488
|
huaweicloud_sandbox_expose_tunnel: "sandbox",
|
|
63489
|
+
huaweicloud_sandbox_expose_poll: "sandbox",
|
|
63276
63490
|
huaweicloud_sandbox_renew_tunnel: "sandbox",
|
|
63277
63491
|
huaweicloud_sandbox_keepalive_watchdog: "sandbox",
|
|
63278
63492
|
huaweicloud_sandbox_check_user: "sandbox",
|
|
@@ -63674,6 +63888,10 @@ var init_tool_definitions = __esm({
|
|
|
63674
63888
|
name: "huaweicloud_sandbox_expose_tunnel",
|
|
63675
63889
|
description: packDescription("huaweicloud_sandbox_expose_tunnel")
|
|
63676
63890
|
},
|
|
63891
|
+
{
|
|
63892
|
+
name: "huaweicloud_sandbox_expose_poll",
|
|
63893
|
+
description: packDescription("huaweicloud_sandbox_expose_poll")
|
|
63894
|
+
},
|
|
63677
63895
|
{
|
|
63678
63896
|
name: "huaweicloud_sandbox_check_user",
|
|
63679
63897
|
description: packDescription("huaweicloud_sandbox_check_user")
|
|
@@ -63969,7 +64187,7 @@ var init_vendor_gate = __esm({
|
|
|
63969
64187
|
|
|
63970
64188
|
// plugins/huaweicloud-core/dist.new/approval-ledger.js
|
|
63971
64189
|
import { closeSync, constants, existsSync as existsSync35, fstatSync, mkdirSync as mkdirSync16, openSync, readFileSync as readFileSync33, readSync, readdirSync as readdirSync7, renameSync as renameSync8, rmSync as rmSync10, statSync as statSync10, writeFileSync as writeFileSync16, writeSync } from "node:fs";
|
|
63972
|
-
import { createHash as createHash9, randomUUID as
|
|
64190
|
+
import { createHash as createHash9, randomUUID as randomUUID4 } from "node:crypto";
|
|
63973
64191
|
import { dirname as dirname26, join as join45 } from "node:path";
|
|
63974
64192
|
function ledgerFilePath() {
|
|
63975
64193
|
return join45(devkitStateBase(), "approval-consents.json");
|
|
@@ -64425,7 +64643,7 @@ function parseSpoolLine(line) {
|
|
|
64425
64643
|
}
|
|
64426
64644
|
}
|
|
64427
64645
|
function quarantineSidecarName(path) {
|
|
64428
|
-
return `${path}.corrupt-${process.pid}-${
|
|
64646
|
+
return `${path}.corrupt-${process.pid}-${randomUUID4()}`;
|
|
64429
64647
|
}
|
|
64430
64648
|
function appendLineAdditively(path, line) {
|
|
64431
64649
|
try {
|
|
@@ -64481,7 +64699,7 @@ function takeSpool() {
|
|
|
64481
64699
|
};
|
|
64482
64700
|
try {
|
|
64483
64701
|
if (existsSync35(spool)) {
|
|
64484
|
-
const takenFile = `${spool}.taken-${process.pid}-${
|
|
64702
|
+
const takenFile = `${spool}.taken-${process.pid}-${randomUUID4()}`;
|
|
64485
64703
|
renameSync8(spool, takenFile);
|
|
64486
64704
|
fold(takenFile);
|
|
64487
64705
|
}
|
|
@@ -65295,7 +65513,9 @@ async function runApprovalGate(name, spec, args, opts) {
|
|
|
65295
65513
|
}
|
|
65296
65514
|
if (!token) {
|
|
65297
65515
|
if (spec.tokenSource === "plan-face") {
|
|
65298
|
-
return {
|
|
65516
|
+
return {
|
|
65517
|
+
envelope: { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND", nextStep: PLAN_FACE_TOKEN_MISSING_NEXT_STEP }
|
|
65518
|
+
};
|
|
65299
65519
|
}
|
|
65300
65520
|
assertNoCredentialPath(value, args);
|
|
65301
65521
|
spec.assertArgsExecutable?.(value, "token");
|
|
@@ -65325,10 +65545,14 @@ async function runApprovalGate(name, spec, args, opts) {
|
|
|
65325
65545
|
return { envelope: { status: "ok", outcome: "already_processed" } };
|
|
65326
65546
|
}
|
|
65327
65547
|
if (inspection.state === "expired") {
|
|
65328
|
-
return {
|
|
65548
|
+
return {
|
|
65549
|
+
envelope: { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED", nextStep: CONFIRM_TOKEN_EXPIRED_NEXT_STEP }
|
|
65550
|
+
};
|
|
65329
65551
|
}
|
|
65330
65552
|
if (inspection.state === "not_found") {
|
|
65331
|
-
return {
|
|
65553
|
+
return {
|
|
65554
|
+
envelope: { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND", nextStep: CONFIRM_TOKEN_UNKNOWN_NEXT_STEP }
|
|
65555
|
+
};
|
|
65332
65556
|
}
|
|
65333
65557
|
assertNoCredentialPath(value, args);
|
|
65334
65558
|
spec.assertArgsExecutable?.(value, "token");
|
|
@@ -65338,8 +65562,11 @@ async function runApprovalGate(name, spec, args, opts) {
|
|
|
65338
65562
|
}
|
|
65339
65563
|
if (consumed.status === "gone") {
|
|
65340
65564
|
const recheck = inspectApprovalToken(token);
|
|
65341
|
-
if (recheck.state === "expired")
|
|
65342
|
-
return {
|
|
65565
|
+
if (recheck.state === "expired") {
|
|
65566
|
+
return {
|
|
65567
|
+
envelope: { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED", nextStep: CONFIRM_TOKEN_EXPIRED_NEXT_STEP }
|
|
65568
|
+
};
|
|
65569
|
+
}
|
|
65343
65570
|
return { envelope: { status: "ok", outcome: "already_processed" } };
|
|
65344
65571
|
}
|
|
65345
65572
|
const stored = consumed.entry;
|
|
@@ -65408,7 +65635,7 @@ function handlerResultCarriesFailure(handlerResult) {
|
|
|
65408
65635
|
const failure2 = record2.error ?? record2.errorMessage ?? record2.message;
|
|
65409
65636
|
return failure2 !== void 0 && failure2 !== null && failure2 !== "";
|
|
65410
65637
|
}
|
|
65411
|
-
var NO_SESSION_SEAM_ERROR, GRANT_REQUIRED_NEXT_STEP, COMMAND_ARGS_MISMATCH, COMMAND_REQUIRES_ARGS, OBS_URI_RE, CREDS_FILE_NAMES, ASK_ENVELOPE_TTL_MS, shownAskEnvelopes, retryMemos, standingGrants, ELICITATION_DECLINED, ELICITATION_CANCELLED, ELICITATION_TIMEOUT, ELICITATION_FAILED, ELICITATION_INVALID_CONTENT, ASK_CONFIRMATION_REQUIRED, ELICITATION_TIMEOUT_MS, ELICITATION_DECISIONS, MESSAGE_FAILURE_MARKERS, BENIGN_ABSENCE_PHRASES;
|
|
65638
|
+
var NO_SESSION_SEAM_ERROR, GRANT_REQUIRED_NEXT_STEP, PLAN_FACE_TOKEN_MISSING_NEXT_STEP, CONFIRM_TOKEN_UNKNOWN_NEXT_STEP, CONFIRM_TOKEN_EXPIRED_NEXT_STEP, COMMAND_ARGS_MISMATCH, COMMAND_REQUIRES_ARGS, OBS_URI_RE, CREDS_FILE_NAMES, ASK_ENVELOPE_TTL_MS, shownAskEnvelopes, retryMemos, standingGrants, ELICITATION_DECLINED, ELICITATION_CANCELLED, ELICITATION_TIMEOUT, ELICITATION_FAILED, ELICITATION_INVALID_CONTENT, ASK_CONFIRMATION_REQUIRED, ELICITATION_TIMEOUT_MS, ELICITATION_DECISIONS, MESSAGE_FAILURE_MARKERS, BENIGN_ABSENCE_PHRASES;
|
|
65412
65639
|
var init_approval_gate = __esm({
|
|
65413
65640
|
"plugins/huaweicloud-core/dist.new/approval-gate.js"() {
|
|
65414
65641
|
"use strict";
|
|
@@ -65419,6 +65646,9 @@ var init_approval_gate = __esm({
|
|
|
65419
65646
|
init_confirm_language();
|
|
65420
65647
|
NO_SESSION_SEAM_ERROR = "Runtime pack configuration is available in stdio agent sessions only; this surface carries no session state.";
|
|
65421
65648
|
GRANT_REQUIRED_NEXT_STEP = 'Ask the user to run "npx huaweicloud-devkit approve <this approvalToken>" in their own terminal, then retry this exact call.';
|
|
65649
|
+
PLAN_FACE_TOKEN_MISSING_NEXT_STEP = "This run call requires an approvalToken minted by the plan face. Call huaweicloud_plan_cli_command with the same args first \u2014 its USER_CONFIRMATION_REQUIRED envelope carries the fresh approvalToken; retry this call with it.";
|
|
65650
|
+
CONFIRM_TOKEN_UNKNOWN_NEXT_STEP = "This approvalToken was never minted in this process \u2014 malformed, or dropped by a server restart (tokens are process-scoped and never persisted). Re-run the plan call to mint a fresh approvalToken, then retry this call with it.";
|
|
65651
|
+
CONFIRM_TOKEN_EXPIRED_NEXT_STEP = "This approvalToken passed its 5-minute TTL. Re-run the plan call to mint a fresh approvalToken and have the user approve it promptly, then retry this call with it.";
|
|
65422
65652
|
COMMAND_ARGS_MISMATCH = "COMMAND_ARGS_MISMATCH";
|
|
65423
65653
|
COMMAND_REQUIRES_ARGS = "COMMAND_REQUIRES_ARGS";
|
|
65424
65654
|
OBS_URI_RE = /^obs:\/\//;
|