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.
Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/integrations/opencode/commands/huaweicloud-doctor.md +1 -1
  3. package/integrations/opencode/hooks/safety-gate.js +235 -0
  4. package/package.json +1 -1
  5. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +3 -16
  6. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +3 -16
  7. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +3 -16
  8. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +3 -16
  9. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +3 -16
  10. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +29 -4
  11. package/plugins/huaweicloud-core/dist/agents/opencode.js +55 -14
  12. package/plugins/huaweicloud-core/dist/approval-gate.js +23 -5
  13. package/plugins/huaweicloud-core/dist/doctor-payload.js +29 -0
  14. package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
  15. package/plugins/huaweicloud-core/dist/hcloud-plan.js +6 -1
  16. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +18 -9
  17. package/plugins/huaweicloud-core/dist/lib/opencode-permission-seam.js +51 -20
  18. package/plugins/huaweicloud-core/dist/mcp-server.js +520 -290
  19. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  20. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +5 -1
  21. package/plugins/huaweicloud-core/dist/packs/registry.js +1 -0
  22. package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
  23. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +25 -1
  24. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +28 -3
  25. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +14 -0
  26. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +11 -3
  27. package/plugins/huaweicloud-core/dist/payload-placement.js +8 -0
  28. package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
  29. package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
  30. package/plugins/huaweicloud-core/dist/safety/classify-text.js +10 -0
  31. package/plugins/huaweicloud-core/dist/safety/policy.js +12 -0
  32. package/plugins/huaweicloud-core/dist/safety/protected-payload.js +93 -0
  33. package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
  34. package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
  35. package/plugins/huaweicloud-core/dist/safety-integrity.js +122 -0
  36. package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +1 -1
  37. package/plugins/huaweicloud-core/dist/setup-cli.js +8 -1
  38. package/plugins/huaweicloud-core/dist/tool-definitions.js +4 -0
  39. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +44 -1
  40. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +75 -2
  41. package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
  42. package/plugins/huaweicloud-core/safety/policy.json +5 -0
  43. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +1 -1
  44. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +42 -39
  45. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +1 -1
  46. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +33 -3
  47. package/plugins/huaweicloud-core/src/agents/opencode.ts +66 -15
  48. package/plugins/huaweicloud-core/src/approval-gate.ts +29 -4
  49. package/plugins/huaweicloud-core/src/doctor-payload.ts +40 -2
  50. package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
  51. package/plugins/huaweicloud-core/src/hcloud-plan.ts +6 -1
  52. package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +32 -1
  53. package/plugins/huaweicloud-core/src/lib/opencode-permission-seam.ts +60 -19
  54. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +7 -1
  55. package/plugins/huaweicloud-core/src/packs/registry.ts +1 -0
  56. package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
  57. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +28 -1
  58. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -15
  59. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +20 -0
  60. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +12 -2
  61. package/plugins/huaweicloud-core/src/payload-placement.ts +8 -0
  62. package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
  63. package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
  64. package/plugins/huaweicloud-core/src/safety/classify-text.ts +10 -0
  65. package/plugins/huaweicloud-core/src/safety/policy.ts +13 -0
  66. package/plugins/huaweicloud-core/src/safety/protected-payload.ts +97 -0
  67. package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
  68. package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
  69. package/plugins/huaweicloud-core/src/safety-integrity.ts +132 -0
  70. package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +7 -5
  71. package/plugins/huaweicloud-core/src/setup-cli.ts +8 -0
  72. package/plugins/huaweicloud-core/src/tool-definitions.ts +4 -0
@@ -0,0 +1,122 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ // The deployed-payload integrity receipt (the integrity unit's layer 3):
5
+ // install/update records a hash manifest of the CLASSIFIER files the
6
+ // in-process gates import — the same artifacts the layer-1 path gate
7
+ // protects and the layer-2 canaries behavior-check. Doctor compares the
8
+ // current hashes against the receipt: drift (an agent-side rewrite the
9
+ // path gate missed, a half-landed overwrite) FAILs with the reinstall
10
+ // remediation; a payload placed by an older devkit (no receipt yet) WARNs
11
+ // instead — backward compatibility, never a false red.
12
+ //
13
+ // Scope is the classifier chain, not the whole payload: dist/safety-policy.js
14
+ // plus its dist/safety/ import graph (the JS classifier the adapter and the
15
+ // .mjs hook load), safety/policy.json (the vocabulary both faces read), and
16
+ // safety/rules/ (the risk catalog). skills/ and node_modules/ are outside
17
+ // it — they have their own freshness/equality probes, and hashing them
18
+ // would make the receipt churn on every skill edit.
19
+ //
20
+ // A receipt-style marker beside the `.installed` precedent: written by the
21
+ // one shared placement seam (copyServerPayload), owned by the devkit,
22
+ // removed with the plugin dir on uninstall. Unlike `.installed` it
23
+ // persists across server boots (the server deletes the restart marker at
24
+ // boot; the receipt must survive for doctor to read).
25
+ export const INTEGRITY_RECEIPT_FILE = '.safety-integrity.json';
26
+ function sha256Of(file) {
27
+ return createHash('sha256').update(readFileSync(file)).digest('hex');
28
+ }
29
+ function filesUnder(dir) {
30
+ if (!existsSync(dir))
31
+ return [];
32
+ const out = [];
33
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
34
+ const full = join(dir, entry.name);
35
+ if (entry.isDirectory())
36
+ out.push(...filesUnder(full));
37
+ else if (entry.isFile())
38
+ out.push(full);
39
+ }
40
+ return out;
41
+ }
42
+ // The classifier artifacts present under a deployed payload dir, as sorted
43
+ // relative paths. Absent entries (a skipDist payload ships safety/ without
44
+ // dist/) simply stay out of the scope — the receipt records what shipped.
45
+ // The receipt's keys are wire vocabulary (pinned deep-equal in the tests and
46
+ // spelled forward-slash in policy docs), so the platform separator is
47
+ // normalized to posix: join()/readdirSync() produce '\' segments on win32
48
+ // and a raw slice would ship platform-dependent receipt keys.
49
+ export function integrityScopeFiles(dir) {
50
+ const rel = [];
51
+ const push = (path) => {
52
+ if (existsSync(join(dir, path)))
53
+ rel.push(path);
54
+ };
55
+ push('dist/safety-policy.js');
56
+ for (const file of filesUnder(join(dir, 'dist', 'safety'))) {
57
+ rel.push(file.slice(dir.length + 1).replaceAll('\\', '/'));
58
+ }
59
+ push('safety/policy.json');
60
+ for (const file of filesUnder(join(dir, 'safety', 'rules'))) {
61
+ rel.push(file.slice(dir.length + 1).replaceAll('\\', '/'));
62
+ }
63
+ return rel.sort((a, b) => a.localeCompare(b));
64
+ }
65
+ export function integrityReceiptPath(dir) {
66
+ return join(dir, INTEGRITY_RECEIPT_FILE);
67
+ }
68
+ // Written at placement time over what actually landed (the verified-copy
69
+ // seam guarantees the bytes; hashing the DEST is the honest record).
70
+ export function writeIntegrityReceipt(dir) {
71
+ const files = {};
72
+ for (const rel of integrityScopeFiles(dir))
73
+ files[rel] = sha256Of(join(dir, rel));
74
+ const receipt = { version: 1, files };
75
+ writeFileSync(integrityReceiptPath(dir), `${JSON.stringify(receipt, null, 2)}\n`);
76
+ }
77
+ // The doctor-side comparison. A receipt entry whose file changed or vanished
78
+ // drifts; a scope file present on disk but absent from the receipt drifts
79
+ // too — no legit path lands classifier files without rewriting the receipt
80
+ // (every install/update writes it), so an unrecorded classifier file is the
81
+ // dropped-in-later tamper shape.
82
+ export function verifyIntegrity(dir) {
83
+ const receiptFile = integrityReceiptPath(dir);
84
+ const scope = integrityScopeFiles(dir);
85
+ if (scope.length === 0)
86
+ return { status: 'no-payload' };
87
+ if (!existsSync(receiptFile))
88
+ return { status: 'no-receipt' };
89
+ let receipt;
90
+ try {
91
+ receipt = JSON.parse(readFileSync(receiptFile, 'utf8'));
92
+ }
93
+ catch {
94
+ return { status: 'no-receipt' };
95
+ }
96
+ if (receipt === null ||
97
+ typeof receipt !== 'object' ||
98
+ receipt.version !== 1 ||
99
+ receipt.files === null ||
100
+ typeof receipt.files !== 'object') {
101
+ return { status: 'no-receipt' };
102
+ }
103
+ const recorded = new Set(Object.keys(receipt.files));
104
+ const drifted = [];
105
+ const missing = [];
106
+ for (const rel of scope) {
107
+ if (!recorded.has(rel))
108
+ continue; // counted as unrecorded below
109
+ const expected = receipt.files[rel];
110
+ if (typeof expected !== 'string' || sha256Of(join(dir, rel)) !== expected)
111
+ drifted.push(rel);
112
+ }
113
+ for (const rel of Object.keys(receipt.files)) {
114
+ if (!existsSync(join(dir, rel)))
115
+ missing.push(rel);
116
+ }
117
+ const unrecorded = scope.filter((rel) => !recorded.has(rel));
118
+ if (drifted.length > 0 || missing.length > 0 || unrecorded.length > 0) {
119
+ return { status: 'mismatch', drifted, missing, unrecorded };
120
+ }
121
+ return { status: 'match' };
122
+ }
@@ -213,7 +213,7 @@ export function planDevbridgeCleanup({ tunnels = [], hosts = [], keepalive = [],
213
213
  }
214
214
  return { deleteIds: [...deleteSet], killPids: [...killPids] };
215
215
  }
216
- export function buildDevbridgeCleanupApplyScript({ deleteIds = [], killPids = [] } = {}) {
216
+ export function buildDevbridgeCleanupApplyScript({ deleteIds = [], killPids = [], } = {}) {
217
217
  for (const id of deleteIds) {
218
218
  if (!DEVBRIDGE_TUNNEL_ID_PATTERN.test(String(id))) {
219
219
  throw new Error(`devbridge cleanup: invalid tunnel id ${JSON.stringify(id)}`);
@@ -67,7 +67,7 @@ import { codexDesktopDoctorMcpConfigured, deployCodexDesktop, uninstallCodexDesk
67
67
  import { codexDoctorApprovalRow } from "./agents/codex-config.js";
68
68
  import { deployDsh, dshStatus, uninstallDsh } from "./agents/dsh.js";
69
69
  import { dshDoctorMcpConfigured, dshPayloadDoctorSection } from "./agents/dsh-patch.js";
70
- import { deployOpenCode, opencodeDoctorAskRule, opencodeDoctorMcpConfigured, opencodeDoctorSeam, opencodeStatus, uninstallOpenCode, } from "./agents/opencode.js";
70
+ import { deployOpenCode, opencodeDoctorAskRule, opencodeDoctorMcpConfigured, opencodeDoctorSafetyGate, opencodeDoctorSeam, opencodeStatus, uninstallOpenCode, } from "./agents/opencode.js";
71
71
  import { deployOpenClaw, openclawDoctorMcpConfigured, openclawStatus, uninstallOpenClaw } from "./agents/openclaw.js";
72
72
  import { codeartsDoctorMcpConfigured, codeartsStatus, deployCodeArts, uninstallCodeArts } from "./agents/codearts.js";
73
73
  import { codeartsWorkDoctorMcpConfigured, codeartsWorkStatus, deployCodeArtsWork, uninstallCodeArtsWork, } from "./agents/codearts-work.js";
@@ -806,6 +806,12 @@ async function cmdDoctor() {
806
806
  check('Runtime deps (undici) installed', undiciOk, 'Run: npx huaweicloud-devkit install');
807
807
  const safetyOk = sections.some((section) => section.triple.safety);
808
808
  check('Safety policy installed', safetyOk, 'Run: npx huaweicloud-devkit install');
809
+ // The integrity unit's layer 3: per-row comparison of the deployed
810
+ // classifier files against the receipt the placement seam wrote. A row
811
+ // with no payload stays silent; a payload without a receipt WARNs (a
812
+ // pre-integrity install); drift FAILs with the reinstall remediation.
813
+ for (const section of sections)
814
+ section.integrity(ctx);
809
815
  // Secret vault — custody tier and inventory only; doctor never decrypts.
810
816
  try {
811
817
  const custody = custodyReport();
@@ -879,6 +885,7 @@ async function cmdDoctor() {
879
885
  if (installedPayload?.id === 'opencode') {
880
886
  opencodeDoctorSeam(ctx);
881
887
  opencodeDoctorAskRule(ctx);
888
+ opencodeDoctorSafetyGate(ctx);
882
889
  }
883
890
  // The codex client yield (PR-5): the per-tool approval_mode blocks the
884
891
  // devkit payload's .mcp.json carries (agents/codex-config.ts records why
@@ -180,6 +180,10 @@ export const TOOL_DEFINITIONS_LITERALS = [
180
180
  name: 'huaweicloud_sandbox_expose_tunnel',
181
181
  description: packDescription('huaweicloud_sandbox_expose_tunnel'),
182
182
  },
183
+ {
184
+ name: 'huaweicloud_sandbox_expose_poll',
185
+ description: packDescription('huaweicloud_sandbox_expose_poll'),
186
+ },
183
187
  {
184
188
  name: 'huaweicloud_sandbox_check_user',
185
189
  description: packDescription('huaweicloud_sandbox_check_user'),
@@ -84,8 +84,9 @@ let classifyTextCommand;
84
84
  // covers the transition.
85
85
  let rosterApprovalTools;
86
86
  let rosterInputShapes;
87
+ let policyModule;
87
88
  try {
88
- const policyModule = existsSync(join(__dirname, '..', 'dist', 'safety-policy.js'))
89
+ policyModule = existsSync(join(__dirname, '..', 'dist', 'safety-policy.js'))
89
90
  ? await import('../dist/safety-policy.js')
90
91
  : await import('../src/safety-policy.ts');
91
92
  ({ classifyTextCommand } = policyModule);
@@ -102,6 +103,48 @@ try {
102
103
  );
103
104
  process.exit(0);
104
105
  }
106
+
107
+ // The load-time behavior self-check (the integrity unit's layer 2, the
108
+ // opencode safety-gate adapter's twin): an import that succeeds is not yet
109
+ // a classifier — a stale replacement, a truncated overwrite, or a bad
110
+ // upgrade can hand over a module that is shaped right and decides wrong.
111
+ // Three canaries run before the module is trusted: the export shape, a
112
+ // canonical write vector (must deny), and a canonical benign read (must
113
+ // allow); any failure denies fail-closed with the self-check reason before
114
+ // main() runs. This runs per hook invocation (a fresh process per Bash
115
+ // call) and catches NON-adversarial corruption; the crafted module that
116
+ // passes the canaries is the documented residual the doctor drift check
117
+ // (layer 3) owns. The reason literal is pinned byte-identical to the
118
+ // adapter's by the safety-gate test.
119
+ const SELF_CHECK_FAILED_REASON =
120
+ 'the deployed safety policy failed its load-time self-check (shape or behavior canary); commands are denied fail-closed. Reinstall the huaweicloud-devkit plugin.';
121
+ const CANARY_WRITE_VECTOR = 'hcloud ECS DeleteServers --server.id=x';
122
+ const CANARY_BENIGN_READ = 'ls /tmp';
123
+
124
+ function policySelfCheckFailed(module) {
125
+ if (typeof module.classifyTextCommand !== 'function') return true;
126
+ try {
127
+ if (module.classifyTextCommand(CANARY_WRITE_VECTOR).decision !== 'deny') return true;
128
+ if (module.classifyTextCommand(CANARY_BENIGN_READ).decision !== 'allow') return true;
129
+ } catch {
130
+ return true;
131
+ }
132
+ return false;
133
+ }
134
+
135
+ if (policySelfCheckFailed(policyModule)) {
136
+ writeSync(
137
+ 1,
138
+ JSON.stringify({
139
+ hookSpecificOutput: {
140
+ hookEventName: 'PreToolUse',
141
+ permissionDecision: 'deny',
142
+ permissionDecisionReason: DENY_PREFIX + SELF_CHECK_FAILED_REASON,
143
+ },
144
+ }) + '\n',
145
+ );
146
+ process.exit(0);
147
+ }
105
148
  try {
106
149
  const rosterModule = existsSync(join(__dirname, '..', 'dist', 'approval-roster.js'))
107
150
  ? await import('../dist/approval-roster.js')
@@ -32,6 +32,19 @@ TELEMETRY_DIR = PLUGIN_DIR / "telemetry"
32
32
  HOOK_EVENTS_PATH = TELEMETRY_DIR / "hook-events.jsonl"
33
33
 
34
34
  CONFIG_FILE_RE = None
35
+ # The payload path-write gate (the integrity unit's layer 1): the compiled
36
+ # write-shape regexes over the policy's protectedPayloadPathMarkers, the py
37
+ # mirror of src/safety/protected-payload.ts. None (field absent, non-list,
38
+ # or empty — the degraded shapes load_policy normalizes) means the gate is
39
+ # unset: additive vocabulary, so an older policy.json without the key
40
+ # disables it on BOTH twins (the TS side's [] / py None agree in verdict).
41
+ PROTECTED_WRITE_RES = None
42
+ PROTECTED_WRITE_REASON = (
43
+ "writing to the deployed Huawei Cloud DevKit plugin payload is blocked: "
44
+ "this command targets the installed safety policy files, and modifying them "
45
+ "would disarm the gates that classify agent commands. Reinstall or update "
46
+ "via npx huaweicloud-devkit install from your own terminal."
47
+ )
35
48
  SECRET_READ_RE = None
36
49
  SECRET_CLI_RE = None
37
50
  APPROVAL_CLI_RE = None
@@ -76,7 +89,7 @@ OBS_MARKER_RE = re.compile(r"\bOBS\b", re.I)
76
89
 
77
90
 
78
91
  def load_policy():
79
- global CONFIG_FILE_RE, SECRET_READ_RE, SECRET_CLI_RE, APPROVAL_CLI_RE, ACCOUNT_SWITCH_CLI_RE, GATED_CLI_RE, WRITE_OPERATION_RE, WRITE_VOCAB_RE, READ_OPERATION_RE, READ_OPERATION_EXCEPTIONS
92
+ global CONFIG_FILE_RE, PROTECTED_WRITE_RES, SECRET_READ_RE, SECRET_CLI_RE, APPROVAL_CLI_RE, ACCOUNT_SWITCH_CLI_RE, GATED_CLI_RE, WRITE_OPERATION_RE, WRITE_VOCAB_RE, READ_OPERATION_RE, READ_OPERATION_EXCEPTIONS
80
93
  try:
81
94
  with POLICY_PATH.open("r", encoding="utf-8") as file_obj:
82
95
  policy = json.load(file_obj)
@@ -165,6 +178,41 @@ def load_policy():
165
178
  cred_patterns = policy.get("credentialFilePatterns", [])
166
179
  if cred_patterns:
167
180
  CONFIG_FILE_RE = re.compile("|".join(cred_patterns), re.I)
181
+ # The payload path-write gate (integrity layer 1): compiled from the
182
+ # policy's protectedPayloadPathMarkers — never a hand-copied marker
183
+ # list — with the SAME write-shape spec as the TS twin
184
+ # (src/safety/protected-payload.ts owns the doctrine comment):
185
+ # candidates split on [;&|\n\r], per-chunk shapes anchored at
186
+ # command position (env assignments + sudo/env/nice/nohup/command/
187
+ # xargs heads), whitespace [ \t] only. Absent/non-list/empty
188
+ # normalizes to an UNSET gate (additive vocabulary — the absent key
189
+ # on an older deployed policy must not fail this face), and a
190
+ # malformed marker pattern degrades ONLY this gate (the isolated
191
+ # per-field doctrine), never the later loads.
192
+ protected_markers = policy.get("protectedPayloadPathMarkers", [])
193
+ if not isinstance(protected_markers, list):
194
+ protected_markers = []
195
+ protected_markers = [m for m in protected_markers if isinstance(m, str) and m]
196
+ if protected_markers:
197
+ try:
198
+ marker_alt = "(?:" + "|".join(protected_markers) + ")"
199
+ anchor = (
200
+ r"^[ \t]*(?:[A-Za-z_][A-Za-z0-9_]*=\S*[ \t]+)*"
201
+ r"(?:(?:sudo|env|nice|nohup|command|xargs)[ \t]+)*"
202
+ )
203
+ PROTECTED_WRITE_RES = [
204
+ re.compile(r">>?[^;&|]*" + marker_alt, re.I),
205
+ re.compile(anchor + r"tee\b[^;&|]*" + marker_alt, re.I),
206
+ re.compile(
207
+ anchor + r"(?:cp|mv|rsync|install)\b[^;&|]*[ \t]\S*" + marker_alt + r"\S*[ \t]*$",
208
+ re.I,
209
+ ),
210
+ re.compile(anchor + r"dd\b[^;&|]*\bof[ \t]*=[ \t]*[^;&|]*" + marker_alt, re.I),
211
+ re.compile(anchor + r"sed\b[^;&|]*[ \t]-i\b[^;&|]*" + marker_alt, re.I),
212
+ re.compile(anchor + r"patch\b[^;&|]*" + marker_alt, re.I),
213
+ ]
214
+ except re.error:
215
+ PROTECTED_WRITE_RES = None
168
216
  blocked_secrets = [op for op in policy.get("blockedSecretOperations", []) if op != ""]
169
217
  if blocked_secrets:
170
218
  # Only entries that are a PREFIX of another entry (ShowSecret is
@@ -478,8 +526,21 @@ def load_cloud_risk_rules():
478
526
  return None
479
527
 
480
528
 
529
+ def normalize_rule_text(text):
530
+ # Twin of risk-rule-engine.normalizeRuleText: shell-transcribed commands
531
+ # and nested JSON carry \"key\": spellings the catalog's JSON-shaped
532
+ # rules were not authored against — a backslash between the key and the
533
+ # quote silently defeated the deny rules. Match the raw text AND its
534
+ # quote-unescaped shadow; the displayed reason keeps the raw command.
535
+ return re.sub(r'\\+(["\'])', r"\1", text)
536
+
537
+
481
538
  def condition_matches(condition, text):
482
- return re.search(condition.get("regex", r"a^"), text, re.I | re.M | re.S) is not None
539
+ regex = re.compile(condition.get("regex", r"a^"), re.I | re.M | re.S)
540
+ if regex.search(text) is not None:
541
+ return True
542
+ normalized = normalize_rule_text(text)
543
+ return normalized != text and regex.search(normalized) is not None
483
544
 
484
545
 
485
546
  def rule_matches(rule, text):
@@ -2653,6 +2714,18 @@ def evaluate(tool_name, tool_input):
2653
2714
  for candidate in (text, unquoted, normalized, normalized_unquoted)
2654
2715
  ):
2655
2716
  return "reading Huawei Cloud credential/profile files can expose AK/SK or tokens. Use redacted toolkit tools."
2717
+ # The payload path-write gate (integrity layer 1, the CONFIG_FILE_RE
2718
+ # gate's sibling): the same four candidates, WRITE-shaped only — the
2719
+ # py mirror of classify-text.ts's protectedPayloadWriteDenied, compiled
2720
+ # in load_policy from the same policy field. Reads of the payload tree
2721
+ # stay allowed (skills reads, direct inspection); only a write-shaped
2722
+ # command targeting a protected payload path denies.
2723
+ if PROTECTED_WRITE_RES:
2724
+ for candidate in (text, unquoted, normalized, normalized_unquoted):
2725
+ for chunk in re.split(r"[;&|\n\r]", candidate):
2726
+ for shape in PROTECTED_WRITE_RES:
2727
+ if shape.search(chunk):
2728
+ return PROTECTED_WRITE_REASON
2656
2729
  if SECRET_CLI_RE and any(SECRET_CLI_RE.search(candidate) for candidate in candidates):
2657
2730
  return "printing vault secrets into the agent context is blocked. Use secret exec so the value reaches only the child process environment."
2658
2731
  if APPROVAL_CLI_RE and any(APPROVAL_CLI_RE.search(candidate) for candidate in candidates):
@@ -2,10 +2,10 @@
2
2
  "name": "huaweicloud-devkit",
3
3
  "id": "huaweicloud-devkit",
4
4
  "displayName": "HuaweiCloud DevKit",
5
- "version": "2.0.0-next.4",
5
+ "version": "2.0.0-next.6",
6
6
  "family": "bundle-plugin",
7
7
  "bundleFormat": "codex",
8
- "description": "Guide coding agents to use Huawei Cloud safely — KooCLI, APIs, SDKs, 40 MCP tools, skills, and safety guardrails.",
8
+ "description": "Guide coding agents to use Huawei Cloud safely �?KooCLI, APIs, SDKs, 40 MCP tools, skills, and safety guardrails.",
9
9
  "author": {
10
10
  "name": "HuaweiCloud Mate",
11
11
  "url": "https://github.com/huaweicloud"
@@ -27,6 +27,11 @@
27
27
  "/proc/(self|[0-9]+)/environ",
28
28
  "huaweicloud\\s*(?:&&|;|/|[\\n\\r])\\s*(?:\\S+\\s+){0,2}(?:credentials|creds-import|config)\\.json"
29
29
  ],
30
+ "protectedPayloadPathMarkers": [
31
+ "huaweicloud-plugins[/\\\\]",
32
+ "huaweicloud-core[/\\\\]dist[/\\\\]",
33
+ "huaweicloud-core[/\\\\]safety[/\\\\]"
34
+ ],
30
35
  "blockedConfigureSubcommands": ["show", "get", "list", "export", "init"],
31
36
  "blockedSecretOperations": [
32
37
  "ShowSecret",
@@ -496,7 +496,7 @@
496
496
  },
497
497
  {
498
498
  "field": "text",
499
- "regex": "--(?:[A-Za-z0-9_.-]*[._-])?(?:admin(?:Pass|[_-]pass)|passwd|password|secret(?:[_-]?key)?|access[_-]?key|token|ak|sk)\\b\\s*[=:]\\s*[^\\s<][^\\s<>\"']"
499
+ "regex": "--(?:[A-Za-z0-9_.-]*[._-])?(?:admin(?:Pass|[_-]pass)|passwd|password|secret[_-]?(?:key|text|string|binary)|secret|api[_-]?key|access[_-]?key|token|ak|sk)\\b\\s*[=:]\\s*[^\\s<][^\\s<>\"']"
500
500
  }
501
501
  ]
502
502
  },