huaweicloud-devkit 2.0.0-next.5 → 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 (40) 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 +1 -1
  6. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
  7. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
  8. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
  9. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  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/lib/opencode-permission-seam.js +51 -20
  15. package/plugins/huaweicloud-core/dist/mcp-server.js +85 -8
  16. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  17. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +5 -1
  18. package/plugins/huaweicloud-core/dist/payload-placement.js +8 -0
  19. package/plugins/huaweicloud-core/dist/safety/classify-text.js +10 -0
  20. package/plugins/huaweicloud-core/dist/safety/policy.js +12 -0
  21. package/plugins/huaweicloud-core/dist/safety/protected-payload.js +93 -0
  22. package/plugins/huaweicloud-core/dist/safety-integrity.js +122 -0
  23. package/plugins/huaweicloud-core/dist/setup-cli.js +8 -1
  24. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +44 -1
  25. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +61 -1
  26. package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
  27. package/plugins/huaweicloud-core/safety/policy.json +5 -0
  28. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +1 -1
  29. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +33 -3
  30. package/plugins/huaweicloud-core/src/agents/opencode.ts +66 -15
  31. package/plugins/huaweicloud-core/src/approval-gate.ts +29 -4
  32. package/plugins/huaweicloud-core/src/doctor-payload.ts +40 -2
  33. package/plugins/huaweicloud-core/src/lib/opencode-permission-seam.ts +60 -19
  34. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +7 -1
  35. package/plugins/huaweicloud-core/src/payload-placement.ts +8 -0
  36. package/plugins/huaweicloud-core/src/safety/classify-text.ts +10 -0
  37. package/plugins/huaweicloud-core/src/safety/policy.ts +13 -0
  38. package/plugins/huaweicloud-core/src/safety/protected-payload.ts +97 -0
  39. package/plugins/huaweicloud-core/src/safety-integrity.ts +132 -0
  40. package/plugins/huaweicloud-core/src/setup-cli.ts +8 -0
@@ -13,6 +13,17 @@
13
13
  // Mitigations: the tree is regenerated by every install/update
14
14
  // (copyServerPayload), and the PreToolUse hook still denies hcloud writes.
15
15
  //
16
+ // The payload root is the seam's EDIT-ONLY class (the interrogate round's
17
+ // classifier-rewrite finding): the deployed dist/safety-policy.js is what
18
+ // the in-process evaluate gate imports at runtime, so an edit-tool rewrite
19
+ // disarms the gate mid-session. The edit deny closes that tool vector; the
20
+ // external_directory allow is deliberately NOT extended to the payload —
21
+ // an allowed external directory inherits workspace defaults where bash is
22
+ // allowed, and the payload must not become a no-prompt bash write target.
23
+ // The bash-face residual is disclosed in the approvals reference and the
24
+ // changelog (the architectural fix direction is install-time integrity
25
+ // verification, out of scope here).
26
+ //
16
27
  // Ownership rules (no receipt, by judgment recorded in the changelog): two
17
28
  // keys over devkit-only globs — any rule on these globs is devkit-domain by
18
29
  // construction, so add-only-if-absent (a pre-existing rule with ANY value is
@@ -46,12 +57,39 @@ export function skillTreePermissionGlobs(pluginSkillsDir, nativeSkillsDir, coreS
46
57
  }
47
58
  return globs;
48
59
  }
60
+ // The edit-only class: the payload root (dist/, safety/, node_modules —
61
+ // everything the deployed gate imports or executes). Edit/write/patch tools
62
+ // deny there, but the external_directory allow is deliberately NOT
63
+ // extended: the payload must not become a no-prompt bash write target.
64
+ export function payloadEditDenyGlobs(pluginDir) {
65
+ return [`${pluginDir.replace(/\\/g, '/')}/**`];
66
+ }
67
+ // The per-section resolver shared by apply and remove: the section record
68
+ // (fresh when absent, so the caller's writes land and are assigned back),
69
+ // or null when the user owns a scalar shape there — one ownership check in
70
+ // one place for both directions of the seam.
71
+ function sectionFor(permission, key) {
72
+ if (permission[key] !== undefined && !isRecord(permission[key]))
73
+ return null;
74
+ return asRecord(permission[key]);
75
+ }
76
+ // The two-class section table shared by apply and remove: the external
77
+ // allow covers the skills globs only, the edit deny covers them plus the
78
+ // edit-only payload class.
79
+ function seamSections(globs, editOnlyGlobs) {
80
+ return [
81
+ ['external_directory', 'allow', globs],
82
+ ['edit', 'deny', [...globs, ...editOnlyGlobs]],
83
+ ];
84
+ }
49
85
  // Mutates config in place. Add-only-if-absent per section: a glob already
50
86
  // present with ANY value keeps the user's rule; only missing globs get the
51
87
  // devkit value. Appended keys win under OpenCode's last-matching-rule-wins
52
88
  // evaluation — deliberate, so the devkit's specific allow beats an earlier
53
- // broader user pattern (e.g. "~/.config/opencode/**": "ask").
54
- export function applySkillTreePermissionSeam(config, globs) {
89
+ // broader user pattern (e.g. "~/.config/opencode/**": "ask"). The edit-only
90
+ // class writes the edit section alone; the external allow deliberately
91
+ // never covers it (see the module header).
92
+ export function applySkillTreePermissionSeam(config, globs, editOnlyGlobs = []) {
55
93
  if (config.permission !== undefined && !isRecord(config.permission)) {
56
94
  // The whole-config string form ("permission": "allow") is the user's
57
95
  // global posture; converting it to an object would silently revert
@@ -61,17 +99,13 @@ export function applySkillTreePermissionSeam(config, globs) {
61
99
  const permission = asRecord(config.permission);
62
100
  const skipped = [];
63
101
  let changed = false;
64
- const sections = [
65
- ['external_directory', 'allow'],
66
- ['edit', 'deny'],
67
- ];
68
- for (const [key, value] of sections) {
69
- if (permission[key] !== undefined && !isRecord(permission[key])) {
102
+ for (const [key, value, list] of seamSections(globs, editOnlyGlobs)) {
103
+ const section = sectionFor(permission, key);
104
+ if (section === null) {
70
105
  skipped.push(key);
71
106
  continue;
72
107
  }
73
- const section = asRecord(permission[key]);
74
- const missing = globs.filter((glob) => !Object.hasOwn(section, glob));
108
+ const missing = list.filter((glob) => !Object.hasOwn(section, glob));
75
109
  if (missing.length === 0)
76
110
  continue;
77
111
  for (const glob of missing)
@@ -86,22 +120,19 @@ export function applySkillTreePermissionSeam(config, globs) {
86
120
  // Mutates config in place. Value-exact deletion only — a user-modified value
87
121
  // on a devkit glob survives. Sections emptied by OUR deletions are pruned
88
122
  // (a pre-existing empty section is left untouched), and the permission
89
- // object itself is pruned only when the seam emptied it.
90
- export function removeSkillTreePermissionSeam(config, globs) {
123
+ // object itself is pruned only when the seam emptied it. The edit-only
124
+ // class is removed from the edit section under the same value-exact rule.
125
+ export function removeSkillTreePermissionSeam(config, globs, editOnlyGlobs = []) {
91
126
  if (!isRecord(config.permission))
92
127
  return false;
93
128
  const permission = asRecord(config.permission);
94
129
  let changed = false;
95
- const sections = [
96
- ['external_directory', 'allow'],
97
- ['edit', 'deny'],
98
- ];
99
- for (const [key, value] of sections) {
100
- if (!isRecord(permission[key]))
130
+ for (const [key, value, list] of seamSections(globs, editOnlyGlobs)) {
131
+ const section = sectionFor(permission, key);
132
+ if (section === null)
101
133
  continue;
102
- const section = asRecord(permission[key]);
103
134
  let removedHere = false;
104
- for (const glob of globs) {
135
+ for (const glob of list) {
105
136
  if (section[glob] === value) {
106
137
  delete section[glob];
107
138
  removedHere = true;
@@ -43879,9 +43879,14 @@ function loadPolicy(path) {
43879
43879
  if (raw.writeOperationPrefixes !== void 0 && writeOperationPrefixes.length === 0) {
43880
43880
  throw new TypeError('safety policy field "writeOperationPrefixes" must not be empty');
43881
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
+ }
43882
43886
  return {
43883
43887
  secretKeyNamePatterns: toStringArray(raw.secretKeyNamePatterns, "secretKeyNamePatterns"),
43884
43888
  credentialFilePatterns: toStringArray(raw.credentialFilePatterns, "credentialFilePatterns"),
43889
+ protectedPayloadPathMarkers,
43885
43890
  blockedConfigureSubcommands: toStringArray(raw.blockedConfigureSubcommands, "blockedConfigureSubcommands"),
43886
43891
  blockedSecretOperations: toStringArray(raw.blockedSecretOperations, "blockedSecretOperations"),
43887
43892
  blockedSecretCliPatterns: toStringArray(raw.blockedSecretCliPatterns, "blockedSecretCliPatterns"),
@@ -45356,6 +45361,61 @@ var init_classify_hcloud = __esm({
45356
45361
  }
45357
45362
  });
45358
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
+
45359
45419
  // plugins/huaweicloud-core/dist.new/safety/classify-text.js
45360
45420
  function scriptTextOf(tokens, depth = 0) {
45361
45421
  if (depth >= 18 || tokens.length === 0)
@@ -45827,6 +45887,9 @@ function classifyTextCommand(command, options = {}) {
45827
45887
  reason: "Reading Huawei Cloud credential or profile files is blocked. Use redacted profile inspection tools instead."
45828
45888
  };
45829
45889
  }
45890
+ const payloadWrite = protectedPayloadWriteDenied(text, policy);
45891
+ if (payloadWrite !== null)
45892
+ return payloadWrite;
45830
45893
  if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedSecretCliPatterns))) {
45831
45894
  return {
45832
45895
  decision: "deny",
@@ -45935,6 +45998,7 @@ var init_classify_text = __esm({
45935
45998
  init_credential_path();
45936
45999
  init_default_policy();
45937
46000
  init_policy();
46001
+ init_protected_payload();
45938
46002
  init_risk_merge();
45939
46003
  init_secret_exec();
45940
46004
  init_skill_quality_cli();
@@ -60036,7 +60100,7 @@ async function handleAuthConfirm(args = {}, _opts = {}) {
60036
60100
  if (token && consumedConfirms.has(token)) {
60037
60101
  return { status: "ok", outcome: "already_processed" };
60038
60102
  }
60039
- 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 };
60040
60104
  }
60041
60105
  if (args.decision === "s1") {
60042
60106
  pendingConfirms.delete(token);
@@ -60054,7 +60118,7 @@ async function handleAuthConfirm(args = {}, _opts = {}) {
60054
60118
  async function handleCheckAccountType(args = {}, _opts = {}) {
60055
60119
  return checkAccountType({ region: typeof args.region === "string" ? args.region : void 0 });
60056
60120
  }
60057
- 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;
60058
60122
  var init_tools3 = __esm({
60059
60123
  "plugins/huaweicloud-core/dist.new/packs/auth/tools.js"() {
60060
60124
  "use strict";
@@ -60067,6 +60131,7 @@ var init_tools3 = __esm({
60067
60131
  init_credentials2();
60068
60132
  init_store();
60069
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.";
60070
60135
  authStatusSchema = external_exports.looseObject({
60071
60136
  vendorConfirmed,
60072
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).")
@@ -65448,7 +65513,9 @@ async function runApprovalGate(name, spec, args, opts) {
65448
65513
  }
65449
65514
  if (!token) {
65450
65515
  if (spec.tokenSource === "plan-face") {
65451
- return { envelope: { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND" } };
65516
+ return {
65517
+ envelope: { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND", nextStep: PLAN_FACE_TOKEN_MISSING_NEXT_STEP }
65518
+ };
65452
65519
  }
65453
65520
  assertNoCredentialPath(value, args);
65454
65521
  spec.assertArgsExecutable?.(value, "token");
@@ -65478,10 +65545,14 @@ async function runApprovalGate(name, spec, args, opts) {
65478
65545
  return { envelope: { status: "ok", outcome: "already_processed" } };
65479
65546
  }
65480
65547
  if (inspection.state === "expired") {
65481
- return { envelope: { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED" } };
65548
+ return {
65549
+ envelope: { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED", nextStep: CONFIRM_TOKEN_EXPIRED_NEXT_STEP }
65550
+ };
65482
65551
  }
65483
65552
  if (inspection.state === "not_found") {
65484
- return { envelope: { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND" } };
65553
+ return {
65554
+ envelope: { status: "rejected", code: "CONFIRM_TOKEN_NOT_FOUND", nextStep: CONFIRM_TOKEN_UNKNOWN_NEXT_STEP }
65555
+ };
65485
65556
  }
65486
65557
  assertNoCredentialPath(value, args);
65487
65558
  spec.assertArgsExecutable?.(value, "token");
@@ -65491,8 +65562,11 @@ async function runApprovalGate(name, spec, args, opts) {
65491
65562
  }
65492
65563
  if (consumed.status === "gone") {
65493
65564
  const recheck = inspectApprovalToken(token);
65494
- if (recheck.state === "expired")
65495
- return { envelope: { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED" } };
65565
+ if (recheck.state === "expired") {
65566
+ return {
65567
+ envelope: { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED", nextStep: CONFIRM_TOKEN_EXPIRED_NEXT_STEP }
65568
+ };
65569
+ }
65496
65570
  return { envelope: { status: "ok", outcome: "already_processed" } };
65497
65571
  }
65498
65572
  const stored = consumed.entry;
@@ -65561,7 +65635,7 @@ function handlerResultCarriesFailure(handlerResult) {
65561
65635
  const failure2 = record2.error ?? record2.errorMessage ?? record2.message;
65562
65636
  return failure2 !== void 0 && failure2 !== null && failure2 !== "";
65563
65637
  }
65564
- 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;
65565
65639
  var init_approval_gate = __esm({
65566
65640
  "plugins/huaweicloud-core/dist.new/approval-gate.js"() {
65567
65641
  "use strict";
@@ -65572,6 +65646,9 @@ var init_approval_gate = __esm({
65572
65646
  init_confirm_language();
65573
65647
  NO_SESSION_SEAM_ERROR = "Runtime pack configuration is available in stdio agent sessions only; this surface carries no session state.";
65574
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.";
65575
65652
  COMMAND_ARGS_MISMATCH = "COMMAND_ARGS_MISMATCH";
65576
65653
  COMMAND_REQUIRES_ARGS = "COMMAND_REQUIRES_ARGS";
65577
65654
  OBS_URI_RE = /^obs:\/\//;