huaweicloud-devkit 2.0.0-next.0 → 2.0.0-next.1

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 (42) hide show
  1. package/package.json +1 -1
  2. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
  3. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
  4. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
  5. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
  6. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  7. package/plugins/huaweicloud-core/dist/agents/officeace-sqlite.js +14 -4
  8. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +5 -1
  9. package/plugins/huaweicloud-core/dist/approvals-cli.js +159 -0
  10. package/plugins/huaweicloud-core/dist/hcloud-plan.js +26 -4
  11. package/plugins/huaweicloud-core/dist/hcloud-run.js +4 -1
  12. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +132 -13
  13. package/plugins/huaweicloud-core/dist/lib/approvals-pin.js +128 -0
  14. package/plugins/huaweicloud-core/dist/mcp-server.js +114 -28
  15. package/plugins/huaweicloud-core/dist/mcp-server.js.map +3 -3
  16. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +27 -9
  17. package/plugins/huaweicloud-core/dist/payload-runtime-deps.js +11 -3
  18. package/plugins/huaweicloud-core/dist/safety/classify-text.js +13 -0
  19. package/plugins/huaweicloud-core/dist/safety/policy.js +1 -0
  20. package/plugins/huaweicloud-core/dist/setup-cli.js +7 -0
  21. package/plugins/huaweicloud-core/dist/update-registry.js +8 -2
  22. package/plugins/huaweicloud-core/dist/update-upgrade.js +8 -1
  23. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +20 -1
  24. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  25. package/plugins/huaweicloud-core/safety/policy.json +8 -0
  26. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +4 -1
  27. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -6
  28. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +47 -0
  29. package/plugins/huaweicloud-core/src/agents/officeace-sqlite.ts +14 -4
  30. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +5 -1
  31. package/plugins/huaweicloud-core/src/approvals-cli.ts +187 -0
  32. package/plugins/huaweicloud-core/src/hcloud-plan.ts +44 -5
  33. package/plugins/huaweicloud-core/src/hcloud-run.ts +4 -1
  34. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +194 -13
  35. package/plugins/huaweicloud-core/src/lib/approvals-pin.ts +153 -0
  36. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +29 -9
  37. package/plugins/huaweicloud-core/src/payload-runtime-deps.ts +11 -3
  38. package/plugins/huaweicloud-core/src/safety/classify-text.ts +15 -0
  39. package/plugins/huaweicloud-core/src/safety/policy.ts +2 -0
  40. package/plugins/huaweicloud-core/src/setup-cli.ts +7 -0
  41. package/plugins/huaweicloud-core/src/update-registry.ts +8 -2
  42. package/plugins/huaweicloud-core/src/update-upgrade.ts +8 -1
@@ -44107,6 +44107,7 @@ function loadPolicy(path) {
44107
44107
  blockedConfigureSubcommands: toStringArray(raw.blockedConfigureSubcommands, "blockedConfigureSubcommands"),
44108
44108
  blockedSecretOperations: toStringArray(raw.blockedSecretOperations, "blockedSecretOperations"),
44109
44109
  blockedSecretCliPatterns: toStringArray(raw.blockedSecretCliPatterns, "blockedSecretCliPatterns"),
44110
+ blockedApprovalCliPatterns: toStringArray(raw.blockedApprovalCliPatterns, "blockedApprovalCliPatterns"),
44110
44111
  writeOperationPrefixes,
44111
44112
  readOperationPrefixes: toStringArray(raw.readOperationPrefixes, "readOperationPrefixes"),
44112
44113
  readOperationExceptions: toStringArray(raw.readOperationExceptions, "readOperationExceptions")
@@ -45804,6 +45805,13 @@ function classifyTextCommand(command, options = {}) {
45804
45805
  reason: "Printing vault secrets into the agent context is blocked. Run the value consumer instead: npx huaweicloud-devkit secret exec --env NAME=secret://<scope>/<name> -- <command> \u2014 a child you trust not to print its own environment, since its stdout is this conversation. Or use secret get --file from your own terminal."
45805
45806
  };
45806
45807
  }
45808
+ if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedApprovalCliPatterns))) {
45809
+ return {
45810
+ decision: "deny",
45811
+ risk: "approval",
45812
+ reason: "Running the approval CLI from the agent Bash face is blocked: the confirmation must come from the user's own interactive terminal, where the PIN is checked. Ask the user to run the printed npx huaweicloud-devkit approve <token> line themselves (first use: npx huaweicloud-devkit pin, once), then retry the same call."
45813
+ };
45814
+ }
45807
45815
  if (shadowCandidates.some((candidate) => /(^|[^a-z0-9.-])(?:huaweicloud-devkit|setup-cli\.(?:js|mjs|ts|cjs)|setup\.cjs)/i.test(candidate)) && shadowCandidates.some((candidate) => /(?:^|\s)secret\s+get\b/i.test(candidate))) {
45808
45816
  return {
45809
45817
  decision: "deny",
@@ -49503,7 +49511,7 @@ function queryDistTags({ timeoutMs = 15e3, cwd } = {}) {
49503
49511
  return new Promise((resolve9) => {
49504
49512
  let child;
49505
49513
  try {
49506
- child = spawn(NPM_BIN, ["view", "huaweicloud-devkit", "dist-tags", "--json"], {
49514
+ child = spawn(`${NPM_BIN} view huaweicloud-devkit dist-tags --json`, {
49507
49515
  windowsHide: true,
49508
49516
  cwd,
49509
49517
  shell: true
@@ -50016,7 +50024,7 @@ var init_agent_registration = __esm({
50016
50024
  // plugins/huaweicloud-core/dist.new/update-upgrade.js
50017
50025
  import { spawnSync as spawnSync6 } from "node:child_process";
50018
50026
  function defaultSpawn(command, args, options) {
50019
- return spawnSync6(command, args, options);
50027
+ return spawnSync6([command, ...args].join(" "), options);
50020
50028
  }
50021
50029
  function restartMessage(target) {
50022
50030
  if (target === "officeace") {
@@ -54954,7 +54962,7 @@ var init_pack_state = __esm({
54954
54962
  });
54955
54963
 
54956
54964
  // plugins/huaweicloud-core/dist.new/lib/approval-tokens.js
54957
- import { createHash as createHash7, randomUUID as randomUUID2 } from "node:crypto";
54965
+ import { createHash as createHash7, createHmac as createHmac3, randomUUID as randomUUID2, timingSafeEqual } from "node:crypto";
54958
54966
  import { existsSync as existsSync26, mkdirSync as mkdirSync13, readdirSync as readdirSync4, readFileSync as readFileSync27, renameSync as renameSync7, statSync as statSync9, unlinkSync as unlinkSync4, writeFileSync as writeFileSync12 } from "node:fs";
54959
54967
  import { dirname as dirname22, join as join33 } from "node:path";
54960
54968
  function approvalFilePath() {
@@ -55018,7 +55026,9 @@ function readApprovals() {
55018
55026
  argsRedacted: entry.argsRedacted,
55019
55027
  createdAt: entry.createdAt,
55020
55028
  ...entry.secretsSubstitutable === true ? { secretsSubstitutable: true } : {},
55021
- ...entry.argsPinView !== void 0 ? { argsPinView: entry.argsPinView } : {}
55029
+ ...entry.argsPinView !== void 0 ? { argsPinView: entry.argsPinView } : {},
55030
+ ...isApprovalEntryState(entry.state) ? { state: entry.state } : {},
55031
+ ...isConfirmGrant(entry.confirmGrant) ? { confirmGrant: { confirmedAt: entry.confirmGrant.confirmedAt, mac: entry.confirmGrant.mac } } : {}
55022
55032
  };
55023
55033
  }
55024
55034
  return result;
@@ -55026,6 +55036,15 @@ function readApprovals() {
55026
55036
  return {};
55027
55037
  }
55028
55038
  }
55039
+ function isApprovalEntryState(value) {
55040
+ return value === "awaiting_user" || value === "user_confirmed";
55041
+ }
55042
+ function isConfirmGrant(value) {
55043
+ if (!value || typeof value !== "object" || Array.isArray(value))
55044
+ return false;
55045
+ const grant = value;
55046
+ return typeof grant.confirmedAt === "number" && typeof grant.mac === "string";
55047
+ }
55029
55048
  function writeApprovals(map2) {
55030
55049
  try {
55031
55050
  const path = approvalFilePath();
@@ -55080,7 +55099,8 @@ function createApprovalToken(rawArgs, opts = {}) {
55080
55099
  argsRedacted: redactSecrets(rawArgs),
55081
55100
  createdAt: Date.now(),
55082
55101
  ...opts.secretsSubstitutable === true ? { secretsSubstitutable: true } : {},
55083
- ...opts.argsPinView !== void 0 ? { argsPinView: opts.argsPinView } : {}
55102
+ ...opts.argsPinView !== void 0 ? { argsPinView: opts.argsPinView } : {},
55103
+ state: "awaiting_user"
55084
55104
  };
55085
55105
  pruneStale(map2);
55086
55106
  pruneConsumedMarkers();
@@ -55103,32 +55123,78 @@ function inspectApprovalToken(token) {
55103
55123
  return { state: "expired" };
55104
55124
  return { state: "valid", entry };
55105
55125
  }
55106
- function consumeApprovalToken(token) {
55126
+ function consumeApprovalToken(token, opts = {}) {
55107
55127
  if (!TOKEN_SHAPE.test(token))
55108
- return null;
55128
+ return { status: "gone" };
55109
55129
  const map2 = readApprovals();
55110
55130
  const entry = map2[token];
55111
55131
  if (!entry || isTombstone(entry))
55112
- return null;
55132
+ return { status: "gone" };
55113
55133
  if (Date.now() - entry.createdAt > APPROVAL_TTL_MS) {
55114
55134
  delete map2[token];
55115
55135
  writeApprovals(map2);
55116
- return null;
55136
+ return { status: "gone" };
55137
+ }
55138
+ if (opts.requireGrant) {
55139
+ const grant = verifyConfirmationGrant(entry, token);
55140
+ if (!grant.ok)
55141
+ return { status: "grant_required", reason: grant.reason };
55117
55142
  }
55118
55143
  if (!claimSingleUse(token))
55119
- return null;
55144
+ return { status: "gone" };
55120
55145
  map2[token] = { consumedAt: Date.now(), createdAt: entry.createdAt };
55121
55146
  writeApprovals(map2);
55122
- return entry;
55147
+ return { status: "consumed", entry };
55148
+ }
55149
+ function grantMac(masterKey, token, entry, confirmedAt) {
55150
+ const shapeDigest = hashArgs({
55151
+ argsHash: entry.argsHash,
55152
+ argsPinView: entry.argsPinView,
55153
+ argsRedacted: entry.argsRedacted,
55154
+ secretsSubstitutable: entry.secretsSubstitutable,
55155
+ createdAt: entry.createdAt
55156
+ });
55157
+ return createHmac3("sha256", masterKey).update(`${GRANT_MAC_DOMAIN}\0${token}\0${shapeDigest}\0${String(confirmedAt)}`).digest("hex");
55123
55158
  }
55124
- var APPROVAL_TTL_MS, TOKEN_SHAPE;
55159
+ function resolveVerificationMasterKey() {
55160
+ try {
55161
+ const master = resolveMasterKey();
55162
+ if (!master)
55163
+ return { failure: "vault master key unavailable" };
55164
+ return { key: master.key };
55165
+ } catch (error62) {
55166
+ const message = error62 instanceof Error ? error62.message : String(error62);
55167
+ return { failure: `vault master key unreadable: ${message}` };
55168
+ }
55169
+ }
55170
+ function verifyConfirmationGrant(entry, token) {
55171
+ if (entry.state !== "user_confirmed") {
55172
+ return { ok: false, reason: "token is awaiting user confirmation" };
55173
+ }
55174
+ const grant = entry.confirmGrant;
55175
+ if (!isConfirmGrant(grant)) {
55176
+ return { ok: false, reason: "confirmation grant is missing or malformed" };
55177
+ }
55178
+ const master = resolveVerificationMasterKey();
55179
+ if ("failure" in master)
55180
+ return { ok: false, reason: master.failure };
55181
+ if (!/^[0-9a-f]{64}$/.test(grant.mac)) {
55182
+ return { ok: false, reason: "confirmation grant mac is malformed" };
55183
+ }
55184
+ const expected = grantMac(master.key, token, entry, grant.confirmedAt);
55185
+ const matches = timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(grant.mac, "hex"));
55186
+ return matches ? { ok: true } : { ok: false, reason: "confirmation grant does not verify" };
55187
+ }
55188
+ var APPROVAL_TTL_MS, TOKEN_SHAPE, GRANT_MAC_DOMAIN;
55125
55189
  var init_approval_tokens = __esm({
55126
55190
  "plugins/huaweicloud-core/dist.new/lib/approval-tokens.js"() {
55127
55191
  "use strict";
55128
55192
  init_safety_policy();
55193
+ init_custody();
55129
55194
  init_pack_state();
55130
55195
  APPROVAL_TTL_MS = 5 * 6e4;
55131
55196
  TOKEN_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
55197
+ GRANT_MAC_DOMAIN = "huaweicloud-approval-grant";
55132
55198
  }
55133
55199
  });
55134
55200
 
@@ -55423,6 +55489,10 @@ var init_hcloud_sg_preflight = __esm({
55423
55489
  });
55424
55490
 
55425
55491
  // plugins/huaweicloud-core/dist.new/hcloud-plan.js
55492
+ function needsUserConfirmation(args, options = {}) {
55493
+ const strict = classifyHcloudArgs(args, { ...options, allowWrites: false });
55494
+ return strict.decision === "deny" && (strict.risk === "write" || strict.risk === "execution");
55495
+ }
55426
55496
  function quoteShellArg(value) {
55427
55497
  const text = String(value);
55428
55498
  if (!text)
@@ -55565,6 +55635,11 @@ function planHcloudCommand(args, options = {}) {
55565
55635
  warnings.push(`${triage.message} ${triage.nextStep}`);
55566
55636
  }
55567
55637
  }
55638
+ const approvalToken = options.mintApprovalToken === false ? void 0 : createApprovalToken(normalizedArgs, {
55639
+ secretsSubstitutable: secretsSubstitutable(normalizedArgs),
55640
+ argsPinView: pinViewArgs(normalizedArgs)
55641
+ });
55642
+ const needsConfirmation = needsUserConfirmation(normalizedArgs, options);
55568
55643
  return {
55569
55644
  executable: "hcloud",
55570
55645
  args: normalizedArgs.map((arg) => redactSecrets(arg)),
@@ -55577,10 +55652,13 @@ function planHcloudCommand(args, options = {}) {
55577
55652
  warnings,
55578
55653
  classification: applyPreflightFindings(effectiveClassification, sgFindings),
55579
55654
  sgFindings,
55580
- approvalToken: createApprovalToken(normalizedArgs, {
55581
- secretsSubstitutable: secretsSubstitutable(normalizedArgs),
55582
- argsPinView: pinViewArgs(normalizedArgs)
55583
- }),
55655
+ ...approvalToken !== void 0 ? { approvalToken } : {},
55656
+ // `command` exists only where a token was minted: a run-path plan stays
55657
+ // silent rather than name a line for a token the run cannot offer.
55658
+ userConfirmation: needsConfirmation ? {
55659
+ needed: true,
55660
+ ...approvalToken !== void 0 ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}
55661
+ } : { needed: false },
55584
55662
  safeToRun: effectiveClassification.decision === "allow"
55585
55663
  };
55586
55664
  }
@@ -55832,7 +55910,7 @@ async function runHcloud2(args, options = {}) {
55832
55910
  const inputArgs = Array.isArray(args) ? args.map(String) : [];
55833
55911
  const { args: normalizedArgs } = stripLeadingHcloudBinArgs(inputArgs);
55834
55912
  const plan = {
55835
- ...planHcloudCommand(normalizedArgs, options),
55913
+ ...planHcloudCommand(normalizedArgs, { ...options, mintApprovalToken: false }),
55836
55914
  rawArgs: normalizedArgs
55837
55915
  };
55838
55916
  assertAllowed(plan.classification);
@@ -56308,7 +56386,7 @@ var init_pack3 = __esm({
56308
56386
  import { existsSync as existsSync27, writeFileSync as writeFileSync14 } from "node:fs";
56309
56387
  import { homedir as homedir23 } from "node:os";
56310
56388
  import { join as join35 } from "node:path";
56311
- import { createHash as createHash8, createHmac as createHmac3 } from "node:crypto";
56389
+ import { createHash as createHash8, createHmac as createHmac4 } from "node:crypto";
56312
56390
  function pickString(...values) {
56313
56391
  for (const value of values) {
56314
56392
  if (typeof value === "string" && value)
@@ -56578,11 +56656,11 @@ x-amz-date:${amzDate}
56578
56656
  credentialScope,
56579
56657
  createHash8("sha256").update(canonicalRequest).digest("hex")
56580
56658
  ].join("\n");
56581
- const kDate = createHmac3("sha256", "AWS4" + creds.sk).update(dateStamp).digest();
56582
- const kRegion = createHmac3("sha256", kDate).update(region).digest();
56583
- const kService = createHmac3("sha256", kRegion).update("s3").digest();
56584
- const kSigning = createHmac3("sha256", kService).update("aws4_request").digest();
56585
- const signature = createHmac3("sha256", kSigning).update(stringToSign).digest("hex");
56659
+ const kDate = createHmac4("sha256", "AWS4" + creds.sk).update(dateStamp).digest();
56660
+ const kRegion = createHmac4("sha256", kDate).update(region).digest();
56661
+ const kService = createHmac4("sha256", kRegion).update("s3").digest();
56662
+ const kSigning = createHmac4("sha256", kService).update("aws4_request").digest();
56663
+ const signature = createHmac4("sha256", kSigning).update(stringToSign).digest("hex");
56586
56664
  const authorization = `AWS4-HMAC-SHA256 Credential=${creds.ak}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
56587
56665
  const headers = {
56588
56666
  Host: url2.host,
@@ -57842,13 +57920,22 @@ async function runApprovedCommand(args = {}) {
57842
57920
  if (placeholderArg) {
57843
57921
  throw new Error(`The argument "${placeholderArg}" still carries a placeholder secret value: replace <redacted> with the actual value the user approved, then re-run with the same approval token.`);
57844
57922
  }
57845
- const stored = consumeApprovalToken(token);
57846
- if (!stored) {
57923
+ const strictPlan = planHcloudCommand(effectiveArgs, { allowWrites: false, mintApprovalToken: false });
57924
+ const consumed = consumeApprovalToken(token, { requireGrant: strictPlan.userConfirmation.needed });
57925
+ if (consumed.status === "grant_required") {
57926
+ return {
57927
+ status: "rejected",
57928
+ code: "USER_CONFIRMATION_REQUIRED",
57929
+ nextStep: 'Ask the user to run "npx huaweicloud-devkit approve <this approvalToken>" in their own terminal, then retry this exact call.'
57930
+ };
57931
+ }
57932
+ if (consumed.status === "gone") {
57847
57933
  const recheck = inspectApprovalToken(token);
57848
57934
  if (recheck.state === "expired")
57849
57935
  return { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED" };
57850
57936
  return { status: "ok", outcome: "already_processed" };
57851
57937
  }
57938
+ const stored = consumed.entry;
57852
57939
  if (hashArgs(effectiveArgs) !== stored.argsHash) {
57853
57940
  const storedView = JSON.stringify(stored.argsPinView ?? stored.argsRedacted);
57854
57941
  const providedView = JSON.stringify(pinViewArgs(effectiveArgs));
@@ -57859,7 +57946,6 @@ async function runApprovedCommand(args = {}) {
57859
57946
  throw new Error("Secret values are pinned to the approved plan: re-run huaweicloud_plan_cli_command with the final values and re-approve.");
57860
57947
  }
57861
57948
  }
57862
- const strictPlan = planHcloudCommand(effectiveArgs, { allowWrites: false });
57863
57949
  const result = await runHcloud2(effectiveArgs, {
57864
57950
  allowWrites: true,
57865
57951
  timeoutMs: args.timeoutMs,
@@ -58036,7 +58122,7 @@ var init_tools7 = __esm({
58036
58122
  },
58037
58123
  {
58038
58124
  name: "huaweicloud_plan_cli_command",
58039
- description: "Classify and plan a Huawei Cloud hcloud command without executing it. 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.",
58125
+ description: "Classify and plan a Huawei Cloud hcloud command without executing it. When the result's userConfirmation.needed is true, the USER must confirm in their own terminal by running the userConfirmation.command line (npx huaweicloud-devkit approve <approvalToken>) before huaweicloud_run_approved_command will accept the command. 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.",
58040
58126
  schema: planCliCommandSchema,
58041
58127
  handler: handlePlanCliCommand
58042
58128
  },
@@ -58054,7 +58140,7 @@ var init_tools7 = __esm({
58054
58140
  },
58055
58141
  {
58056
58142
  name: "huaweicloud_run_approved_command",
58057
- description: "Run a write-capable hcloud command only after the exact command has been shown and explicitly approved by the user. 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.",
58143
+ description: "Run a write-capable hcloud command only after the exact command has been shown and explicitly approved by the user, and after the user confirmed the plan token in their own terminal (npx huaweicloud-devkit approve <token>). A non-read command without that terminal confirmation is rejected with USER_CONFIRMATION_REQUIRED and the token stays usable. 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.",
58058
58144
  schema: runApprovedCommandSchema,
58059
58145
  handler: handleRunApprovedCommand
58060
58146
  },